diff --git a/api/crontab.php b/api/crontab.php index 59020c5..41403b8 100644 --- a/api/crontab.php +++ b/api/crontab.php @@ -13,9 +13,9 @@ switch ($action) { case "list": - $res = $db->query("SELECT crontab_path FROM crontabs;"); + $res = $db->query("SELECT crontab_id, crontab_path FROM crontabs;"); while ($row = $res->fetchArray()){ - exit; + echo "
"; } break; } diff --git a/api/crontab_view.php b/api/crontab_view.php index d19eed5..a5ad9b3 100644 --- a/api/crontab_view.php +++ b/api/crontab_view.php @@ -1,24 +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"; + $lines = explode("\n", $data); + foreach ($lines as $line){ + echo "$line
"; + } } diff --git a/api/table.php b/api/table.php index 085a08b..10560c4 100644 --- a/api/table.php +++ b/api/table.php @@ -3,73 +3,92 @@ This endpoint will get specific tables from the db Args will be: + action: + list: list table names 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"; - return 1; + +$db = new SQLite3("../../webcron.db"); + +if ( array_key_exists('action', $_GET)){ + $action=$_GET['action']; } else { - $name=$_GET['name']; + $action="show"; } -if ( array_key_exists("limit", $_GET)){ - $limit=$_GET['limit']; -} else { - $limit=0; -} - -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=""; +if ($action == "show"){ + if ( ! array_key_exists("name", $_GET) ){ + echo "A tablename was not provided with the request"; + return 1; + } else { + $name=$_GET['name']; } - $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"); - echo '
'; - echo '
'; - echo '
'; + if ( array_key_exists("columns", $_GET)){ + $columns = explode(',', $_GET["columns"]); + } - 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++; - } + $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"); - echo '
'; - while ($row = $res->fetchArray()){ - echo "
"; + $res = $db->query("SELECT * FROM $name $query_modifier"); + echo '
'; + echo '
'; + echo '
'; if ( !empty($columns) ) { foreach($columns as $column_name){ - echo "
{$row[$column_name]}
"; + echo "
{$column_name}
"; } } else { - for ($i = 0; $i < $counter; $i++){ - echo "
{$row[$i]}
"; + $counter=0; + for ($i = 0; $i < $res->numColumns(); $i++ ){ + echo "
{$res->columnName($i)}
"; + $counter++; } } - echo "
"; - } - echo '
'; - echo '
'; + + + echo '
'; + while ($row = $res->fetchArray()){ + echo "
"; + + if ( !empty($columns) ) { + foreach($columns as $column_name){ + echo "
{$row[$column_name]}
"; + } + } else { + for ($i = 0; $i < $counter; $i++){ + echo "
{$row[$i]}
"; + } + } + echo "
"; + } + echo '
'; + echo '
'; +} else if ($action == "list"){ + $res = $db->query("SELECT name FROM sqlite_master WHERE type='table';"); + + while ($row = $res->fetchArray()){ + echo "
"; + } +} ?> \ No newline at end of file diff --git a/api/update.php b/api/update.php new file mode 100644 index 0000000..51bfad9 --- /dev/null +++ b/api/update.php @@ -0,0 +1,20 @@ + +*/ + + +if (array_key_exists("target", $_GET)){ + $target=$_GET['target']; +} + +switch ($target) { + case "crontabs": + shell_exec("../../Scripts/update-databse.sh"); + break; +} + +return 0; + +?> \ No newline at end of file diff --git a/crontab.php b/crontab.php index 0e4c966..0ae4401 100644 --- a/crontab.php +++ b/crontab.php @@ -29,7 +29,7 @@ diff --git a/database.php b/database.php index 3cf28e0..f59ac43 100644 --- a/database.php +++ b/database.php @@ -30,7 +30,7 @@
diff --git a/main.js b/main.js index 6ad4c2b..b8ac23a 100644 --- a/main.js +++ b/main.js @@ -1,9 +1,11 @@ -function setDatabaseVersion() { - url = '/api/database_version.php'; +function setAreaByUrl(url){ response = makeRequest(url); setInfoSection(response); } - +function setDatabaseVersion() { + url = '/api/database_version.php'; + setAreaByUrl(url); +} function makeRequest(url){ var request = new XMLHttpRequest(); @@ -14,8 +16,7 @@ function makeRequest(url){ function setCrontabStats(){ url = "/api/crontab_stats.php"; - response = makeRequest(url); - setInfoSection(response); + setAreaByUrl(url); } function setInfoSection (string) { @@ -24,21 +25,38 @@ function setInfoSection (string) { } function getTable(name){ - url = "/api/table.php?name=" + name; - response = makeRequest(url); - setInfoSection(response); + url = "/api/table.php?name="+name; + setAreaByUrl(url); +} + +function listTables(){ + url="/api/table.php?action=list"; + setAreaByUrl(url); } function getCrontabs (){ url = "/api/table.php?name='crontabs'&columns=crontab_path,crontab_created_timestamp,crontab_modified_timestamp"; - response = makeRequest(url); - setInfoSection(response); + setAreaByUrl(url); +} + +function listCrontabs(){ + url = "/api/crontab.php?action=list"; + setAreaByUrl(url); +} + +function loadCrontab (id){ + url = "/api/crontab_view.php?id="+id; + setAreaByUrl(url); } function test (){ url = "/api/crontab_view.php?name=0hourly"; - response = makeRequest(url); - setInfoSection(response); + setAreaByUrl(url); +} + +function update_crons () { + url = "/api/update.php?target=crontabs"; + setAreaByUrl(url); } function triggerPopup(info_to_get){ diff --git a/pages/popup.php b/pages/popup.php index 800e256..2355cc7 100644 --- a/pages/popup.php +++ b/pages/popup.php @@ -1,2 +1,4 @@ \ No newline at end of file