From 6194dda84a5c7ba3d89a17819fc4c027fe096076 Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Mon, 15 May 2023 16:45:18 -0500 Subject: [PATCH] Committed for move --- api/crontab_stats.php | 2 +- api/crontab_view.php | 27 ++++++++++++ api/table.php | 32 +++++++++++---- crontab.php | 2 + index.php | 4 +- main.js | 18 ++++++++ pages/login.php | 96 +++++++++++++++++++++++++++++++++++++++++++ pages/popup.php | 2 + 8 files changed, 172 insertions(+), 11 deletions(-) create mode 100644 api/crontab_view.php create mode 100644 pages/popup.php diff --git a/api/crontab_stats.php b/api/crontab_stats.php index a1a167b..a0c8a64 100644 --- a/api/crontab_stats.php +++ b/api/crontab_stats.php @@ -1,5 +1,5 @@ "; -$crontab_counts=shell_exec('./count-crontabs.sh'); +$crontab_counts=shell_exec('../../Scripts/count-crontabs.sh'); echo "$crontab_counts"; ?> diff --git a/api/crontab_view.php b/api/crontab_view.php new file mode 100644 index 0000000..d19eed5 --- /dev/null +++ b/api/crontab_view.php @@ -0,0 +1,27 @@ +querySingle("select crontab_id from crontabs where crontab_path like '%/$name';"); + + if (empty($id)){ + echo "$name is not a valid crontab"; + } else { + $data = $db->querySingle("SELECT crontab_data FROM crontabs WHERE crontab_id = $id;"); + echo "$data"; + } + + + + +?> \ No newline at end of file diff --git a/api/table.php b/api/table.php index f3ee86f..24cf66c 100644 --- a/api/table.php +++ b/api/table.php @@ -5,6 +5,7 @@ This endpoint will get specific tables from the db Args will be: name: Table Name limit: number of entries to return (default all) + columns: This will be a comma delimited list of column names (in the order that it needs to be displayed) */ if ( ! array_key_exists("name", $_GET) ){ echo "A tablename was not provided with the request"; @@ -19,6 +20,11 @@ if ( array_key_exists("limit", $_GET)){ $limit=0; } +if ( array_key_exists("columns", $_GET)){ + echo $_GET["columns"]; + $columns = explode(',', $_GET["columns"]); +} + $query_modifier=""; if (filter_var($limit, FILTER_VALIDATE_INT)){ if ($limit > 0){ @@ -35,20 +41,32 @@ if (filter_var($limit, FILTER_VALIDATE_INT)){ echo '
'; echo '
'; - $counter=0; - for ($i = 0; $i < $res->numColumns(); $i++ ){ - echo "
{$res->columnName($i)}
"; - $counter++; + if ( !empty($columns) ) { + foreach($columns as $column_name){ + echo "
{$column_name}
"; + } + } else { + $counter=0; + for ($i = 0; $i < $res->numColumns(); $i++ ){ + echo "
{$res->columnName($i)}
"; + $counter++; + } } + echo '
'; while ($row = $res->fetchArray()){ echo "
"; - for ($i = 0; $i < $counter; $i++){ - echo "
{$row[$i]}
"; + if ( !empty($columns) ) { + foreach($columns as $column_name){ + echo "
{$row[$column_name]}
"; + } + } else { + for ($i = 0; $i < $counter; $i++){ + echo "
{$row[$i]}
"; + } } - echo "
"; } echo '
'; diff --git a/crontab.php b/crontab.php index 38d1de7..0e4c966 100644 --- a/crontab.php +++ b/crontab.php @@ -29,6 +29,8 @@
diff --git a/index.php b/index.php index cab8c23..8038726 100644 --- a/index.php +++ b/index.php @@ -26,9 +26,7 @@
diff --git a/main.js b/main.js index c73df36..828d207 100644 --- a/main.js +++ b/main.js @@ -28,3 +28,21 @@ function getTable(name){ response = makeRequest(url); setInfoSection(response); } + +function getCrontabs (){ + url = "http://localhost:8000/api/table.php?name='crontabs'&columns=crontab_path,crontab_created_timestamp,crontab_modified_timestamp"; + response = makeRequest(url); + setInfoSection(response); +} + +function test (){ + url = "http://localhost:8000/api/crontab_view.php?name=0hourly"; + response = makeRequest(url); + setInfoSection(response); +} + +function triggerPopup(info_to_get){ + const modal = document.querySelector('dialog'); + + document.querySelector("#popup_button").addEventListener("click", () => {modal.showModal();}); +} \ No newline at end of file diff --git a/pages/login.php b/pages/login.php index e69de29..8e99634 100644 --- a/pages/login.php +++ b/pages/login.php @@ -0,0 +1,96 @@ + + + + + + + + + Overview + + +
+ + + +
+ Test +
+ "; + $db = new SQLite3('../webcron.db'); + $res = $db->querySingle("SELECT COUNT(job_id) FROM job_history;"); + echo "Job History Entries: $res
"; + $res = $db->querySingle("SELECT COUNT(log_id) FROM logs;"); + echo "Log Entries: $res
"; + ?> +
+ +
+
+ Log Statistics (This Week) +
+
+
Level
+
# of occurances
+
+ query("SELECT * FROM log_statistics_last_7_days;"); + while ($row = $res->fetchArray()){ + echo "
"; + echo "
{$row['log_level_name']}
{$row['count']}
"; + echo "
"; + } + ?> +
+
+ +
+ Script Failures (Last 10) +
+
+
Date/Time
Script
Exit Code
+
+ query("SELECT * FROM last_ten_failed_jobs;"); + while ($row = $res->fetchArray()){ + echo "
"; + echo "
{$row['job_timestamp']}
{$row['job_source']}
{$row['job_exit_code']}
"; + echo "
"; + } + ?> +
+
+ +
+ Jobs Run (Last 10) +
+
+
Date/Time
Script
Exit Code
Job Result
+
+ query("SELECT * FROM job_history ORDER BY job_timestamp DESC LIMIT 10;"); + while ($row = $res->fetchArray()){ + echo "
"; + echo "
{$row['job_timestamp']}
{$row['job_source']}
{$row['job_exit_code']}
{$row['job_result']}
"; + echo "
"; + } + ?> +
+
+ +
+
+ + + \ No newline at end of file diff --git a/pages/popup.php b/pages/popup.php new file mode 100644 index 0000000..800e256 --- /dev/null +++ b/pages/popup.php @@ -0,0 +1,2 @@ + \ No newline at end of file