Committed for move

This commit is contained in:
Tristan Ancelet 2023-05-15 16:45:18 -05:00
parent 343a01cf61
commit 6194dda84a
8 changed files with 172 additions and 11 deletions

View File

@ -1,5 +1,5 @@
<?php <?php
echo "Total Crontabs:<br>"; echo "Total Crontabs:<br>";
$crontab_counts=shell_exec('./count-crontabs.sh'); $crontab_counts=shell_exec('../../Scripts/count-crontabs.sh');
echo "$crontab_counts"; echo "$crontab_counts";
?> ?>

27
api/crontab_view.php Normal file
View File

@ -0,0 +1,27 @@
<?php
/*
GET Variables
name: Name of crontab
*/
$GLOBALS['db'] = new SQLite3('../../webcron.db');
if (!array_key_exists("name", $_GET)) {
$name = "";
} else {
$name = $_GET["name"];
}
$db = $GLOBALS['db'];
$id = $db->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";
}
?>

View File

@ -5,6 +5,7 @@ This endpoint will get specific tables from the db
Args will be: Args will be:
name: Table Name name: Table Name
limit: number of entries to return (default all) 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) ){ if ( ! array_key_exists("name", $_GET) ){
echo "A tablename was not provided with the request"; echo "A tablename was not provided with the request";
@ -19,6 +20,11 @@ if ( array_key_exists("limit", $_GET)){
$limit=0; $limit=0;
} }
if ( array_key_exists("columns", $_GET)){
echo $_GET["columns"];
$columns = explode(',', $_GET["columns"]);
}
$query_modifier=""; $query_modifier="";
if (filter_var($limit, FILTER_VALIDATE_INT)){ if (filter_var($limit, FILTER_VALIDATE_INT)){
if ($limit > 0){ if ($limit > 0){
@ -35,20 +41,32 @@ if (filter_var($limit, FILTER_VALIDATE_INT)){
echo '<div class="log_table bordered">'; echo '<div class="log_table bordered">';
echo '<div class="table_row">'; echo '<div class="table_row">';
if ( !empty($columns) ) {
foreach($columns as $column_name){
echo "<div class=\"table_header\">{$column_name}</div>";
}
} else {
$counter=0; $counter=0;
for ($i = 0; $i < $res->numColumns(); $i++ ){ for ($i = 0; $i < $res->numColumns(); $i++ ){
echo "<div class=\"table_header\">{$res->columnName($i)}</div>"; echo "<div class=\"table_header\">{$res->columnName($i)}</div>";
$counter++; $counter++;
} }
}
echo '</div>'; echo '</div>';
while ($row = $res->fetchArray()){ while ($row = $res->fetchArray()){
echo "<div class=\"table_row\">"; echo "<div class=\"table_row\">";
if ( !empty($columns) ) {
foreach($columns as $column_name){
echo "<div class=\"table_cell\">{$row[$column_name]}</div>";
}
} else {
for ($i = 0; $i < $counter; $i++){ for ($i = 0; $i < $counter; $i++){
echo "<div class=\"table_cell\">{$row[$i]}</div>"; echo "<div class=\"table_cell\">{$row[$i]}</div>";
} }
}
echo "</div>"; echo "</div>";
} }
echo '</div>'; echo '</div>';

View File

@ -29,6 +29,8 @@
<div class="menu_bar bordered_right cell"> <div class="menu_bar bordered_right cell">
<button class="menu_button" onclick="setCrontabStats()"> View Crontab Statistics </button> <button class="menu_button" onclick="setCrontabStats()"> View Crontab Statistics </button>
<button class="menu_button" onclick="getTable('job_history')">View Script Run History</button> <button class="menu_button" onclick="getTable('job_history')">View Script Run History</button>
<button class="menu_button" onclick="getCrontabs()">View Crontabs</button>
<button class="menu_button" onclick="test()">Test</button>
</div> </div>
<div id="content" class="content cell"> <div id="content" class="content cell">

View File

@ -26,9 +26,7 @@
<div class="content_area bordered rounded_border"> <div class="content_area bordered rounded_border">
<div class="menu_bar bordered_right cell"> <div class="menu_bar bordered_right cell">
<button class="menu_button"> Check Logs </button> <button class="menu_button" onclick="getLogHistory()"> Check Logs </button>
<button class="menu_button"> View Crontab Statistics</button>
<button class="menu_button" onclick="setInfoSection()"> View Database Version</button>
</div> </div>
<div id="content" class="content cell"> <div id="content" class="content cell">

18
main.js
View File

@ -28,3 +28,21 @@ function getTable(name){
response = makeRequest(url); response = makeRequest(url);
setInfoSection(response); 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();});
}

View File

@ -0,0 +1,96 @@
<!Doctype html>
<!--
Color pallet: https://colorhunt.co/palette/b9eddd87cbb9569daa577d86
-->
<html>
<head>
<!-- <script src="https://cdn.tailwindcss.com"></script> -->
<link rel="stylesheet" href="css/main.css">
<script src="main.js"> </script>
<title>Overview</title>
</head>
<body>
<div class="content_area bordered rounded_border">
<div class="menu_bar bordered_right cell">
<button class="menu_button"> Check Logs </button>
<button class="menu_button"> View Crontab Statistics</button>
<button class="menu_button" onclick="setInfoSection()"> View Database Version</button>
</div>
<div id="content" class="content cell">
Test
<br>
<?php
$user=shell_exec("whoami");
echo "User: $user<br>";
$db = new SQLite3('../webcron.db');
$res = $db->querySingle("SELECT COUNT(job_id) FROM job_history;");
echo "Job History Entries: $res<br>";
$res = $db->querySingle("SELECT COUNT(log_id) FROM logs;");
echo "Log Entries: $res<br>";
?>
</div>
<div class="double_width_menu_bar bordered_left cell">
<div class="wrapper bordered center_text">
Log Statistics (This Week)
<div id="log_statistics_table" class="log_table bordered">
<div class="table_row">
<div class="table_header">Level</div>
<div class="table_header"># of occurances</div>
</div>
<?php
$db = new SQLite3('../webcron.db');
$res = $db->query("SELECT * FROM log_statistics_last_7_days;");
while ($row = $res->fetchArray()){
echo "<div class='table_row'>";
echo "<div class='table_cell'>{$row['log_level_name']}</div> <div class='table_cell'>{$row['count']}</div>";
echo "</div>";
}
?>
</div>
</div>
<div class="wrapper bordered center_text">
Script Failures (Last 10)
<div id="script_failures" class="log_table">
<div class="table_row">
<div class="table_header">Date/Time</div> <div class="table_header">Script</div> <div class="table_header">Exit Code</div>
</div>
<?php
$db = new SQLite3('../webcron.db');
$res = $db->query("SELECT * FROM last_ten_failed_jobs;");
while ($row = $res->fetchArray()){
echo "<div class='table_row'>";
echo "<div class='table_cell'>{$row['job_timestamp']}</div> <div class='table_cell'>{$row['job_source']}</div><div class='table_cell'>{$row['job_exit_code']}</div>";
echo "</div>";
}
?>
</div>
</div>
<div class="wrapper bordered center_text">
Jobs Run (Last 10)
<div id="jobs_run_table" class="log_table">
<div class="table_row">
<div class="table_header">Date/Time</div> <div class="table_header">Script</div> <div class="table_header">Exit Code</div> <div class="table_header">Job Result</div>
</div>
<?php
$db = new SQLite3('../webcron.db');
$res = $db->query("SELECT * FROM job_history ORDER BY job_timestamp DESC LIMIT 10;");
while ($row = $res->fetchArray()){
echo "<div class='table_row'>";
echo "<div class='table_cell'>{$row['job_timestamp']}</div> <div class='table_cell'>{$row['job_source']}</div><div class='table_cell'>{$row['job_exit_code']}</div><div class='table_cell'>{$row['job_result']}</div>";
echo "</div>";
}
?>
</div>
</div>
</div>
</div>
</body>
</html>

2
pages/popup.php Normal file
View File

@ -0,0 +1,2 @@
<div class="popup">
</div>