Implemented table classes for each webpage.
This commit is contained in:
parent
12e1f06897
commit
b8ba9dc5d4
@ -1,8 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
namespace db;
|
||||||
|
|
||||||
class Query {
|
class Query {
|
||||||
private $table_name;
|
private $table_name;
|
||||||
private array $columns_querying = array();
|
private array $columns_querying = array();
|
||||||
private int $limit=0;
|
private int $limit=0;
|
||||||
|
private string $order_by;
|
||||||
|
|
||||||
public function __construct(string $table_name){
|
public function __construct(string $table_name){
|
||||||
$this->table_name = $table_name;
|
$this->table_name = $table_name;
|
||||||
@ -19,6 +22,10 @@ class Query {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function set_order_by_column (string $order_by){
|
||||||
|
$this->order_by = $order_by;
|
||||||
|
}
|
||||||
|
|
||||||
private function get_columns(){
|
private function get_columns(){
|
||||||
$column_string="";
|
$column_string="";
|
||||||
|
|
||||||
@ -39,13 +46,21 @@ class Query {
|
|||||||
return $modifier;
|
return $modifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function get_order_by(){
|
||||||
|
$order_by="";
|
||||||
|
if (!empty($this->order_by)){
|
||||||
|
$order_by=" ORDER BY {$this->order_by}";
|
||||||
|
}
|
||||||
|
return $order_by;
|
||||||
|
}
|
||||||
|
|
||||||
private function get_where() {
|
private function get_where() {
|
||||||
$where = "";
|
$where = "";
|
||||||
return $where;
|
return $where;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_query_string(){
|
public function get_query_string(){
|
||||||
$query = "SELECT {$this->get_columns()} FROM {$this->table_name}{$this->get_where()}{$this->get_limit()};";
|
$query = "SELECT {$this->get_columns()} FROM {$this->table_name}{$this->get_where()}{$this->get_order_by()}{$this->get_limit()};";
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
require("../Libraries/db/query.php");
|
|
||||||
|
namespace table;
|
||||||
|
$root = $_SERVER['DOCUMENT_ROOT'];
|
||||||
|
include("$root/Libraries/db/query.php");
|
||||||
|
use db\Query;
|
||||||
|
|
||||||
class Table_Cell {
|
class Table_Cell {
|
||||||
private $formats = array(
|
private $formats = array(
|
||||||
@ -62,6 +66,7 @@ class Table_Row {
|
|||||||
class Table {
|
class Table {
|
||||||
private Query $query;
|
private Query $query;
|
||||||
private $name;
|
private $name;
|
||||||
|
private $pretty_name;
|
||||||
private $headers;
|
private $headers;
|
||||||
private $rows = array();
|
private $rows = array();
|
||||||
|
|
||||||
@ -84,6 +89,18 @@ class Table {
|
|||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function set_pretty_name(string $pretty_name){
|
||||||
|
$this->pretty_name = $pretty_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_pretty_name(){
|
||||||
|
$output=$this->name;
|
||||||
|
if (!empty($this->pretty_name)){
|
||||||
|
$output=$this->pretty_name;
|
||||||
|
}
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
public function Load($db){
|
public function Load($db){
|
||||||
$res = $db->query($this->query->get_query_string());
|
$res = $db->query($this->query->get_query_string());
|
||||||
|
|
||||||
@ -108,7 +125,7 @@ class Table {
|
|||||||
}
|
}
|
||||||
public function get_html(){
|
public function get_html(){
|
||||||
$output="";
|
$output="";
|
||||||
$output="{$output}<div class=\"wrapper bordered center_text\">";
|
$output="{$output}<div class=\"wrapper bordered center_text\">{$this->get_pretty_name()}";
|
||||||
$output="{$output}<div class=\"log_table bordered\">";
|
$output="{$output}<div class=\"log_table bordered\">";
|
||||||
|
|
||||||
foreach ($this->rows as $row){
|
foreach ($this->rows as $row){
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require("class.php");
|
require("class.php");
|
||||||
|
use table\Table;
|
||||||
function get_main () {
|
function get_main () {
|
||||||
$db = $GLOBALS["db"];
|
$db = $GLOBALS["db"];
|
||||||
/*
|
/*
|
||||||
|
@ -1,9 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
include("../Libraries/table/class.php");
|
echo $_SERVER['DOCUMENT_ROOT'];
|
||||||
$db = new SQLite3("../../webcron.db");
|
|
||||||
$table = new Table("crontabs");
|
|
||||||
|
|
||||||
$table->Load($db, "");
|
|
||||||
|
|
||||||
echo $table->get_html();
|
|
||||||
?>
|
?>
|
||||||
|
34
crontab.php
34
crontab.php
@ -1,4 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
$root = $_SERVER['DOCUMENT_ROOT'];
|
||||||
|
require "$root/Libraries/table/class.php";
|
||||||
|
use table\Table;
|
||||||
|
$db = new SQLite3("../webcron.db");
|
||||||
|
?>
|
||||||
<!Doctype html>
|
<!Doctype html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
@ -37,24 +42,19 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="double_width_menu_bar bordered_left cell">
|
<div class="double_width_menu_bar bordered_left cell">
|
||||||
<div class="wrapper bordered center_text">
|
|
||||||
All Crontabs
|
|
||||||
<div id="log_statistics_table" class="log_table bordered">
|
|
||||||
<div class="table_row">
|
|
||||||
<div class="table_header">Crontab</div> <div class="table_header">Created At</div><div class="table_header">Last Modified</div>
|
|
||||||
</div>
|
|
||||||
<?php
|
<?php
|
||||||
$db = new SQLite3('../webcron.db');
|
$columns = array(
|
||||||
$res = $db->query("SELECT crontab_path, crontab_created_timestamp, crontab_modified_timestamp FROM crontabs;");
|
'crontab_path AS "Crontab Path"',
|
||||||
|
'crontab_created_timestamp AS "Created At"',
|
||||||
while ($row = $res->fetchArray()){
|
'crontab_modified_timestamp AS "Last Modified At"'
|
||||||
echo "<div class=\"table_row\">";
|
);
|
||||||
echo "<div class=\"table_cell\">{$row['crontab_path']}</div> <div class=\"table_cell\">{$row['crontab_created_timestamp']}</div><div class=\"table_cell\">{$row['crontab_modified_timestamp']}</div>";
|
$table = new Table("crontabs");
|
||||||
echo "</div>";
|
$table->set_pretty_name("Crontabs");
|
||||||
}
|
$query = $table->get_query();
|
||||||
|
$query->set_columns($columns);
|
||||||
|
$table->Load($db);
|
||||||
|
echo $table->get_html();
|
||||||
?>
|
?>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
$root = $_SERVER['DOCUMENT_ROOT'];
|
||||||
|
require "$root/Libraries/table/class.php";
|
||||||
|
use table\Table;
|
||||||
|
$db = new SQLite3("../webcron.db");
|
||||||
|
?>
|
||||||
<!Doctype html>
|
<!Doctype html>
|
||||||
<!--
|
<!--
|
||||||
Color pallet: https://colorhunt.co/palette/b9eddd87cbb9569daa577d86
|
Color pallet: https://colorhunt.co/palette/b9eddd87cbb9569daa577d86
|
||||||
@ -37,6 +43,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="double_width_menu_bar bordered_left cell">
|
<div class="double_width_menu_bar bordered_left cell">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
79
index.php
79
index.php
@ -1,3 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
$root = $_SERVER['DOCUMENT_ROOT'];
|
||||||
|
require "$root/Libraries/table/class.php";
|
||||||
|
use table\Table;
|
||||||
|
$db = new SQLite3("../webcron.db");
|
||||||
|
?>
|
||||||
<!Doctype html>
|
<!Doctype html>
|
||||||
<!--
|
<!--
|
||||||
Color pallet: https://colorhunt.co/palette/b9eddd87cbb9569daa577d86
|
Color pallet: https://colorhunt.co/palette/b9eddd87cbb9569daa577d86
|
||||||
@ -35,7 +41,6 @@
|
|||||||
<?php
|
<?php
|
||||||
$user=shell_exec("whoami");
|
$user=shell_exec("whoami");
|
||||||
echo "User: $user<br>";
|
echo "User: $user<br>";
|
||||||
$db = new SQLite3('../webcron.db');
|
|
||||||
$res = $db->querySingle("SELECT COUNT(job_id) FROM job_history;");
|
$res = $db->querySingle("SELECT COUNT(job_id) FROM job_history;");
|
||||||
echo "Job History Entries: $res<br>";
|
echo "Job History Entries: $res<br>";
|
||||||
$res = $db->querySingle("SELECT COUNT(log_id) FROM logs;");
|
$res = $db->querySingle("SELECT COUNT(log_id) FROM logs;");
|
||||||
@ -44,61 +49,31 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="double_width_menu_bar bordered_left cell">
|
<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
|
<?php
|
||||||
$db = new SQLite3('../webcron.db');
|
$table = new Table("log_statistics_last_7_days");
|
||||||
$res = $db->query("SELECT * FROM log_statistics_last_7_days;");
|
$table->set_pretty_name("Log Statistics (Last 7 Days)");
|
||||||
while ($row = $res->fetchArray()){
|
$query = $table->get_query();
|
||||||
echo "<div class='table_row'>";
|
$table->Load($db);
|
||||||
echo "<div class='table_cell'>{$row['log_level_name']}</div> <div class='table_cell'>{$row['count']}</div>";
|
echo $query->get_query_string();
|
||||||
echo "</div>";
|
echo $table->get_html();
|
||||||
}
|
|
||||||
?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="wrapper bordered center_text">
|
$table = new Table("last_ten_failed_jobs");
|
||||||
Script Failures (Last 10)
|
$table->set_pretty_name("Script Failures (Last 10)");
|
||||||
<div id="script_failures" class="log_table">
|
$query = $table->get_query();
|
||||||
<div class="table_row">
|
$table->Load($db);
|
||||||
<div class="table_header">Date/Time</div> <div class="table_header">Script</div> <div class="table_header">Exit Code</div>
|
echo $query->get_query_string();
|
||||||
</div>
|
echo $table->get_html();
|
||||||
<?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>
|
|
||||||
|
|
||||||
|
$table = new Table("job_history");
|
||||||
|
$table->set_pretty_name("Jobs Run (Last 10)");
|
||||||
|
$query = $table->get_query();
|
||||||
|
$query->set_order_by_column("job_timestamp DESC");
|
||||||
|
$query->set_limit(10);
|
||||||
|
$table->Load($db);
|
||||||
|
echo $query->get_query_string();
|
||||||
|
echo $table->get_html();
|
||||||
|
?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
require("Libraries/db/query.php");
|
require("Libraries/db/query.php");
|
||||||
|
use db\Query;
|
||||||
|
|
||||||
$query = new Query("crontabs");
|
$query = new Query("crontabs");
|
||||||
$query->set_limit(-1);
|
$query->set_limit(-1);
|
||||||
|
0
webcron.db
Normal file
0
webcron.db
Normal file
Loading…
Reference in New Issue
Block a user