From 9a1139edaeab309f9cf7eaf4b6431c339638be41 Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Sat, 13 May 2023 13:24:58 -0500 Subject: [PATCH] Moved shell files out of web-root directory so they can't be accessed and downloaded by clients. --- count-crontabs.sh | 19 --------------- main.js | 27 +++++++++++++++++---- update-database.sh | 59 ---------------------------------------------- 3 files changed, 22 insertions(+), 83 deletions(-) delete mode 100755 count-crontabs.sh delete mode 100755 update-database.sh diff --git a/count-crontabs.sh b/count-crontabs.sh deleted file mode 100755 index 9ea45d8..0000000 --- a/count-crontabs.sh +++ /dev/null @@ -1,19 +0,0 @@ -total_count=0 -declare -a crontab_dirs=( - /etc/cron.d - /etc/cron.daily - /etc/cron.hourly - /etc/cron.weekly - /var/spool/cron -) - -for dir in ${crontab_dirs[@]}; do - count=0; - for file in $dir/*; do - count=` ls -1 $dir | wc -l ` - done - echo "- $dir: $count
" - total_count=$(( $count + $total_count )) -done - -echo "Total: $total_count" \ No newline at end of file diff --git a/main.js b/main.js index aad8b48..c73df36 100644 --- a/main.js +++ b/main.js @@ -1,13 +1,30 @@ -function request_sqlite_version () { +function setDatabaseVersion() { + url = 'http://localhost:8000/api/database_version.php'; + response = makeRequest(url); + setInfoSection(response); +} + + +function makeRequest(url){ var request = new XMLHttpRequest(); - request.open("GET", 'http://localhost:8000/database_version.php', false); + request.open("GET", url, false); request.send(null); return request.responseText; } -function setInfoSection (string) { - var info_section = document.getElementById("content"); - info_section.innerHTML = request_sqlite_version(); +function setCrontabStats(){ + url = "http://localhost:8000/api/crontab_stats.php"; + response = makeRequest(url); + setInfoSection(response); } +function setInfoSection (string) { + var info_section = document.getElementById("content"); + info_section.innerHTML = string; +} +function getTable(name){ + url = "http://localhost:8000/api/table.php?name=" + name; + response = makeRequest(url); + setInfoSection(response); +} diff --git a/update-database.sh b/update-database.sh deleted file mode 100755 index d58d986..0000000 --- a/update-database.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/bash -set -e - -declare -a crontab_dirs=( - /etc/cron.d - /etc/cron.daily - /etc/cron.hourly - /etc/cron.weekly - /var/spool/cron -) - -declare -a crontabs_in_db - -sqlite_cmd='sqlite3 ../webcron.db' - - -for name in $( $sqlite_cmd <<< "SELECT crontab_path FROM crontabs;"); do - crontabs_in_db+=( "$name" ) -done - -# This will go through and count the number of files in each directory (to determine if they need to be checked) -for dir in ${crontab_dirs[@]}; do - # If the directory has less than 1 crontab (aka empty) it will be skipped - if [[ $( ls -1 $dir | wc -l ) -ge 1 ]]; then - for file in $dir/* ; do - # For each file in the directory it will check to see if the current file - # path is already stored in the DB - # if not it will create one and it will be be indexed in the DB - if [[ -f $file ]] && [[ ! "${crontabs_in_db[@]}" == *$file* ]]; then - $sqlite_cmd <<< " - INSERT INTO crontabs (crontab_path, crontab_data) VALUES - ('$file', - '$(<$file)') - " - fi - done - fi -done - -# This will request all of the information from the db relating to all of the indexed crontab's -IFS='|' -while read crontab_id crontab_path; do - # It will initially request the id and path of the file, and then will load in the actual data of the - # file to be compared to the file content's on disk. - data=`sqlite3 ../webcron.db <<< "SELECT crontab_data FROM crontabs WHERE crontab_id = $crontab_id"` - - # this will check to make sure that the file exists on disk and - # will compare the disk and db versions of the file to make sure if a change is needed to be - # loaded into the db. - if [[ -f $crontab_path ]] && [[ ! "$data" == "$(<$crontab_path)" ]]; then - sqlite3 ../webcron.db <<<" - UPDATE crontabs SET crontab_data = '$(<$crontab_path)' WHERE crontab_id = $crontab_id - " - fi - -done <<< ` sqlite3 ../webcron.db <<< " -SELECT crontab_id crontab_name, crontab_path FROM crontabs; -" ` -unset IFS \ No newline at end of file