added a foreach loop to print out a crontab line-by-line to crontab_view.php
This commit is contained in:
parent
dbc5587bb6
commit
743ca029cc
@ -13,9 +13,9 @@
|
|||||||
|
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case "list":
|
case "list":
|
||||||
$res = $db->query("SELECT crontab_path FROM crontabs;");
|
$res = $db->query("SELECT crontab_id, crontab_path FROM crontabs;");
|
||||||
while ($row = $res->fetchArray()){
|
while ($row = $res->fetchArray()){
|
||||||
exit;
|
echo "<button onclick=loadCrontab({$row['crontab_id']})>{$row['crontab_path']}</button><br>";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,27 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
GET Variables
|
GET Variables
|
||||||
name: Name of crontab
|
Optional:
|
||||||
|
id: id of the crontab
|
||||||
*/
|
*/
|
||||||
$GLOBALS['db'] = new SQLite3('../../webcron.db');
|
$GLOBALS['db'] = new SQLite3('../../webcron.db');
|
||||||
|
|
||||||
if (!array_key_exists("name", $_GET)) {
|
if (!array_key_exists("id", $_GET)) {
|
||||||
$name = "";
|
$name = "";
|
||||||
} else {
|
} else {
|
||||||
$name = $_GET["name"];
|
$id = $_GET["id"];
|
||||||
}
|
}
|
||||||
|
|
||||||
$db = $GLOBALS['db'];
|
$db = $GLOBALS['db'];
|
||||||
$id = $db->querySingle("select crontab_id from crontabs where crontab_path like '%/$name';");
|
|
||||||
|
|
||||||
if (empty($id)){
|
if (empty($id)){
|
||||||
echo "$name is not a valid crontab";
|
echo "$name is not a valid crontab";
|
||||||
} else {
|
} else {
|
||||||
$data = $db->querySingle("SELECT crontab_data FROM crontabs WHERE crontab_id = $id;");
|
$data = $db->querySingle("SELECT crontab_data FROM crontabs WHERE crontab_id = $id;");
|
||||||
echo "$data";
|
$lines = explode("\n", $data);
|
||||||
|
foreach ($lines as $line){
|
||||||
|
echo "$line<br>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
111
api/table.php
111
api/table.php
@ -3,73 +3,92 @@
|
|||||||
This endpoint will get specific tables from the db
|
This endpoint will get specific tables from the db
|
||||||
|
|
||||||
Args will be:
|
Args will be:
|
||||||
|
action:
|
||||||
|
list: list table names
|
||||||
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)
|
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";
|
$db = new SQLite3("../../webcron.db");
|
||||||
return 1;
|
|
||||||
|
if ( array_key_exists('action', $_GET)){
|
||||||
|
$action=$_GET['action'];
|
||||||
} else {
|
} else {
|
||||||
$name=$_GET['name'];
|
$action="show";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( array_key_exists("limit", $_GET)){
|
if ($action == "show"){
|
||||||
$limit=$_GET['limit'];
|
if ( ! array_key_exists("name", $_GET) ){
|
||||||
} else {
|
echo "A tablename was not provided with the request";
|
||||||
$limit=0;
|
return 1;
|
||||||
}
|
} else {
|
||||||
|
$name=$_GET['name'];
|
||||||
if ( array_key_exists("columns", $_GET)){
|
|
||||||
$columns = explode(',', $_GET["columns"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$query_modifier="";
|
|
||||||
if (filter_var($limit, FILTER_VALIDATE_INT)){
|
|
||||||
if ($limit > 0){
|
|
||||||
$query_modifier="WHERE LIMIT $limit";
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
$query_modifier="";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$db = new SQLite3("../../webcron.db");
|
if ( array_key_exists("limit", $_GET)){
|
||||||
|
$limit=$_GET['limit'];
|
||||||
|
} else {
|
||||||
|
$limit=0;
|
||||||
|
}
|
||||||
|
|
||||||
$res = $db->query("SELECT * FROM $name $query_modifier");
|
if ( array_key_exists("columns", $_GET)){
|
||||||
echo '<div class="wrapper bordered center_text">';
|
$columns = explode(',', $_GET["columns"]);
|
||||||
echo '<div class="log_table bordered">';
|
}
|
||||||
echo '<div class="table_row">';
|
|
||||||
|
|
||||||
if ( !empty($columns) ) {
|
$query_modifier="";
|
||||||
foreach($columns as $column_name){
|
if (filter_var($limit, FILTER_VALIDATE_INT)){
|
||||||
echo "<div class=\"table_header\">{$column_name}</div>";
|
if ($limit > 0){
|
||||||
}
|
$query_modifier="WHERE LIMIT $limit";
|
||||||
} else {
|
}
|
||||||
$counter=0;
|
}else {
|
||||||
for ($i = 0; $i < $res->numColumns(); $i++ ){
|
$query_modifier="";
|
||||||
echo "<div class=\"table_header\">{$res->columnName($i)}</div>";
|
|
||||||
$counter++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$db = new SQLite3("../../webcron.db");
|
||||||
|
|
||||||
echo '</div>';
|
$res = $db->query("SELECT * FROM $name $query_modifier");
|
||||||
while ($row = $res->fetchArray()){
|
echo '<div class="wrapper bordered center_text">';
|
||||||
echo "<div class=\"table_row\">";
|
echo '<div class="log_table bordered">';
|
||||||
|
echo '<div class="table_row">';
|
||||||
|
|
||||||
if ( !empty($columns) ) {
|
if ( !empty($columns) ) {
|
||||||
foreach($columns as $column_name){
|
foreach($columns as $column_name){
|
||||||
echo "<div class=\"table_cell\">{$row[$column_name]}</div>";
|
echo "<div class=\"table_header\">{$column_name}</div>";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for ($i = 0; $i < $counter; $i++){
|
$counter=0;
|
||||||
echo "<div class=\"table_cell\">{$row[$i]}</div>";
|
for ($i = 0; $i < $res->numColumns(); $i++ ){
|
||||||
|
echo "<div class=\"table_header\">{$res->columnName($i)}</div>";
|
||||||
|
$counter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo "</div>";
|
|
||||||
}
|
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
echo '</div>';
|
while ($row = $res->fetchArray()){
|
||||||
|
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++){
|
||||||
|
echo "<div class=\"table_cell\">{$row[$i]}</div>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo "</div>";
|
||||||
|
}
|
||||||
|
echo '</div>';
|
||||||
|
echo '</div>';
|
||||||
|
} else if ($action == "list"){
|
||||||
|
$res = $db->query("SELECT name FROM sqlite_master WHERE type='table';");
|
||||||
|
|
||||||
|
while ($row = $res->fetchArray()){
|
||||||
|
echo "<button onclick='getTable(\"{$row['name']}\")'>{$row['name']}</button><br> ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
20
api/update.php
Normal file
20
api/update.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
UPDATE:
|
||||||
|
target=<string>
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
if (array_key_exists("target", $_GET)){
|
||||||
|
$target=$_GET['target'];
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($target) {
|
||||||
|
case "crontabs":
|
||||||
|
shell_exec("../../Scripts/update-databse.sh");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
?>
|
@ -29,7 +29,7 @@
|
|||||||
<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="listCrontabs()">View Crontabs</button>
|
||||||
<button class="menu_button" onclick="test()">Test</button>
|
<button class="menu_button" onclick="test()">Test</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
<div class="menu_bar bordered_right cell">
|
<div class="menu_bar bordered_right cell">
|
||||||
<button class="menu_button" onclick="setDatabaseVersion()"> View Database Version</button>
|
<button class="menu_button" onclick="setDatabaseVersion()"> View Database Version</button>
|
||||||
<button class="menu_button" onclick="setTableNames()"> View Tables </button>
|
<button class="menu_button" onclick="listTables()"> View Tables </button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="content" class="content cell">
|
<div id="content" class="content cell">
|
||||||
|
42
main.js
42
main.js
@ -1,9 +1,11 @@
|
|||||||
function setDatabaseVersion() {
|
function setAreaByUrl(url){
|
||||||
url = '/api/database_version.php';
|
|
||||||
response = makeRequest(url);
|
response = makeRequest(url);
|
||||||
setInfoSection(response);
|
setInfoSection(response);
|
||||||
}
|
}
|
||||||
|
function setDatabaseVersion() {
|
||||||
|
url = '/api/database_version.php';
|
||||||
|
setAreaByUrl(url);
|
||||||
|
}
|
||||||
|
|
||||||
function makeRequest(url){
|
function makeRequest(url){
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
@ -14,8 +16,7 @@ function makeRequest(url){
|
|||||||
|
|
||||||
function setCrontabStats(){
|
function setCrontabStats(){
|
||||||
url = "/api/crontab_stats.php";
|
url = "/api/crontab_stats.php";
|
||||||
response = makeRequest(url);
|
setAreaByUrl(url);
|
||||||
setInfoSection(response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setInfoSection (string) {
|
function setInfoSection (string) {
|
||||||
@ -24,21 +25,38 @@ function setInfoSection (string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getTable(name){
|
function getTable(name){
|
||||||
url = "/api/table.php?name=" + name;
|
url = "/api/table.php?name="+name;
|
||||||
response = makeRequest(url);
|
setAreaByUrl(url);
|
||||||
setInfoSection(response);
|
}
|
||||||
|
|
||||||
|
function listTables(){
|
||||||
|
url="/api/table.php?action=list";
|
||||||
|
setAreaByUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCrontabs (){
|
function getCrontabs (){
|
||||||
url = "/api/table.php?name='crontabs'&columns=crontab_path,crontab_created_timestamp,crontab_modified_timestamp";
|
url = "/api/table.php?name='crontabs'&columns=crontab_path,crontab_created_timestamp,crontab_modified_timestamp";
|
||||||
response = makeRequest(url);
|
setAreaByUrl(url);
|
||||||
setInfoSection(response);
|
}
|
||||||
|
|
||||||
|
function listCrontabs(){
|
||||||
|
url = "/api/crontab.php?action=list";
|
||||||
|
setAreaByUrl(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadCrontab (id){
|
||||||
|
url = "/api/crontab_view.php?id="+id;
|
||||||
|
setAreaByUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
function test (){
|
function test (){
|
||||||
url = "/api/crontab_view.php?name=0hourly";
|
url = "/api/crontab_view.php?name=0hourly";
|
||||||
response = makeRequest(url);
|
setAreaByUrl(url);
|
||||||
setInfoSection(response);
|
}
|
||||||
|
|
||||||
|
function update_crons () {
|
||||||
|
url = "/api/update.php?target=crontabs";
|
||||||
|
setAreaByUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerPopup(info_to_get){
|
function triggerPopup(info_to_get){
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
<div class="popup">
|
<div class="popup">
|
||||||
|
<dialog>
|
||||||
|
</dialog>
|
||||||
</div>
|
</div>
|
Loading…
Reference in New Issue
Block a user