- This will create a dockwatch label, should be a valid URL (Ex: http://dockwatch or http://10.1.0.1:9999)
+ This will create a dockwatch label, should be a valid URL (Ex: http://dockwatch or http://10.1.0.1:= APP_PORT ?>)
@@ -878,6 +926,8 @@
}
if ($_POST['m'] == 'updateContainerOption') {
- $settingsFile['containers'][$_POST['hash']][$_POST['option']] = $_POST['setting'];
- $saveSettings = setServerFile('settings', $settingsFile);
+ $containersTable = apiRequest('database-getContainers')['result'];
+ $container = apiRequest('database-getContainerGroupFromHash', ['hash' => $_POST['hash']])['result'];
+
+ apiRequest('database-updateContainer', [], ['hash' => $_POST['hash'], $_POST['option'] => $database->prepare($_POST['setting'])]);
}
diff --git a/root/app/www/public/ajax/login.php b/root/app/www/public/ajax/login.php
index 700a380..a4aaaa6 100644
--- a/root/app/www/public/ajax/login.php
+++ b/root/app/www/public/ajax/login.php
@@ -9,6 +9,11 @@
require 'shared.php';
+if ($_POST['m'] == 'resetSession') {
+ session_unset();
+ session_destroy();
+}
+
if ($_POST['m'] == 'login') {
logger(SYSTEM_LOG, 'login ->');
diff --git a/root/app/www/public/ajax/logs.php b/root/app/www/public/ajax/logs.php
index d9bbdd8..f722edd 100644
--- a/root/app/www/public/ajax/logs.php
+++ b/root/app/www/public/ajax/logs.php
@@ -108,10 +108,10 @@
if ($_POST['m'] == 'viewLog') {
logger(SYSTEM_LOG, 'View log: ' . $_POST['name']);
- $apiResponse = apiRequest('viewLog', ['name' => $_POST['name']]);
+ $apiRequest = apiRequest('server-log', ['name' => $_POST['name']]);
- if ($apiResponse['code'] == 200) {
- $result = json_decode($apiResponse['response']['result'], true);
+ if ($apiRequest['code'] == 200) {
+ $result = json_decode($apiRequest['result'], true);
} else {
$error = 'Failed to get log from server ' . ACTIVE_SERVER_NAME;
}
@@ -122,13 +122,13 @@
if ($_POST['m'] == 'purgeLogs') {
logger(SYSTEM_LOG, 'Purge logs: ' . $_POST['group']);
- $apiResponse = apiRequest('purgeLogs', [], ['group' => $_POST['group']]);
- logger(UI_LOG, 'purgeLogs:' . json_encode($apiResponse));
+ $apiRequest = apiRequest('server-purgeLogs', [], ['group' => $_POST['group']]);
+ logger(UI_LOG, 'purgeLogs:' . json_encode($apiRequest));
}
if ($_POST['m'] == 'deleteLog') {
logger(SYSTEM_LOG, 'Delete log: ' . $_POST['log']);
- $apiResponse = apiRequest('deleteLog', [], ['log' => $_POST['log']]);
- logger(UI_LOG, 'deleteLog:' . json_encode($apiResponse));
-}
\ No newline at end of file
+ $apiRequest = apiRequest('server-deleteLog', [], ['log' => $_POST['log']]);
+ logger(UI_LOG, 'deleteLog:' . json_encode($apiRequest));
+}
diff --git a/root/app/www/public/ajax/notification.php b/root/app/www/public/ajax/notification.php
index 642e1e9..3204b03 100644
--- a/root/app/www/public/ajax/notification.php
+++ b/root/app/www/public/ajax/notification.php
@@ -9,179 +9,286 @@
require 'shared.php';
-$triggers = [
- [
- 'name' => 'updated',
- 'label' => 'Updated',
- 'desc' => 'Send a notification when a container has had an update applied',
- 'event' => 'updates'
- ],[
- 'name' => 'updates',
- 'label' => 'Updates',
- 'desc' => 'Send a notification when a container has an update available',
- 'event' => 'updates'
- ],[
- 'name' => 'stateChange',
- 'label' => 'State change',
- 'desc' => 'Send a notification when a container has a state change (running -> down)',
- 'event' => 'state'
- ],[
- 'name' => 'added',
- 'label' => 'Added',
- 'desc' => 'Send a notification when a container is added',
- 'event' => 'state'
- ],[
- 'name' => 'removed',
- 'label' => 'Removed',
- 'desc' => 'Send a notification when a container is removed',
- 'event' => 'state'
- ],[
- 'name' => 'prune',
- 'label' => 'Prune',
- 'desc' => 'Send a notification when an image or volume is pruned',
- 'event' => 'prune'
- ],[
- 'name' => 'cpuHigh',
- 'label' => 'CPU usage',
- 'desc' => 'Send a notification when container CPU usage exceeds threshold (set in Settings)',
- 'event' => 'usage'
- ],[
- 'name' => 'memHigh',
- 'label' => 'Memory usage',
- 'desc' => 'Send a notification when container memory usage exceeds threshold (set in Settings)',
- 'event' => 'usage'
- ],[
- 'name' => 'health',
- 'label' => 'Health change',
- 'desc' => 'Send a notification when container becomes unhealthy',
- 'event' => 'health'
- ]
- ];
-
if ($_POST['m'] == 'init') {
- $notificationPlatforms = $notifications->getPlatforms();
+ $notificationPlatformTable = apiRequest('database-getNotificationPlatforms')['result'];
+ $notificationTriggersTable = apiRequest('database-getNotificationTriggers')['result'];
+ $notificationLinkTable = apiRequest('database-getNotificationLinks')['result'];
+
?>
-
+ Notifications have not been setup yet, click the plus icon above to set them up.
+
+
+
+
-
-
+
+
+
+
+ = $notificationLink['name'] ?>
+
+
+
+
+ You have not configured any triggers for this notificationgetNotificationTriggerNameFromId($triggerId, $notificationTriggersTable);
+ $enabledTriggers[] = $trigger;
+ }
+
+ echo '
The name of this server, also passed in the notification payload
Maintenance IP
-
+
This IP is used to do updates/restarts for Dockwatch. It will create another container dockwatch-maintenance with this IP and after it has updated/restarted Dockwatch it will be removed. This is only required if you do static IP assignment for your containers.
Maintenance port
-
+
This port is used to do updates/restarts for Dockwatch. It will create another container dockwatch-maintenance with this port and after it has updated/restarted Dockwatch it will be removed.
-
Login Failures
+
Login failures
@@ -81,7 +85,7 @@
-
Server list
+
= APP_NAME ?> servers
@@ -93,30 +97,30 @@
-
Sorry, remote management of server access is not allowed. Go to the = ACTIVE_SERVER_NAME ?> server to make those changes.
+
Sorry, remote management of the server list is not allowed. Go to the = ACTIVE_SERVER_NAME ?> server to make those changes.
-
-
-
= $serversFile[0]['apikey'] ?>
+
+
+
= $serversTable[APP_SERVER_ID]['apikey'] ?>
1) {
- foreach ($serversFile as $serverIndex => $serverSettings) {
- if ($serverIndex == 0) {
+ if (count($serversTable) > 1) {
+ foreach ($serversTable as $serverSettings) {
+ if ($serverSettings['id'] == APP_SERVER_ID) {
continue;
}
?>
-
-
-
+
+
+
+
+
Timeout length
+
+
+
+
How long to wait for a remote server to respond, keep in mind 60-90 seconds will throw apache/nginx/cloudflare timeouts
+
-
New Containers
+
New containers
@@ -148,18 +159,18 @@
Updates1
-
-
-
+
+
+
-
+
What settings to use for new containers that are added
-
Auto Prune
+
Auto prune
@@ -173,21 +184,21 @@
Orphan images
- >
+ >
Automatically try to prune all orphan images daily
Orphan volumes
- >
+ >
Automatically try to prune all orphan volumes daily
Orphan networks
- >
+ >
Automatically try to prune all orphan networks daily
If a container usage is above this number, send a notification (if notification is enabled)
CPUs
-
+
Detected count: = $cpus ?>
Memory1
-
+
If a container usage is above this number, send a notification (if notification is enabled)
@@ -258,7 +269,7 @@
Enabled2,3
- >
+ >
SSE will update the container list UI every minute with current status of Updates, State, Health, CPU and Memory
@@ -279,28 +290,28 @@
Crons
-
+
How long to store cron run log files (min 1 day)
Notifications
-
+
How long to store logs generated when notifications are sent (min 1 day)
UI
-
+
How long to store logs generated from using the UI (min 1 day)
API
-
+
How long to store logs generated when api requests are made (min 1 day)
@@ -322,25 +333,25 @@
Environment
-
-
+
+
Location of webroot, requires a container restart after changing. Do not change this without working files externally!
-
Override Blacklist
+
Override blacklist
- >
+ >
Generally not recommended, it's at your own risk.
-
Page Loading3
+
Page loading3
-
-
+
+
Internal: On a full page refresh you will go back to the overview. (state lost) External: On a full page refresh you will stay on this current page. (state saved in URL)
@@ -358,8 +369,8 @@
}
if ($_POST['m'] == 'saveGlobalSettings') {
- $currentSettings = getServerFile('settings');
- $newSettings = [];
+ $activeServer = apiGetActiveServer();
+ $newSettings = [];
foreach ($_POST as $key => $val) {
if ($key == 'm' || str_contains($key, 'serverList')) {
@@ -378,7 +389,7 @@
}
//-- ENVIRONMENT SWITCHING
- if ($currentSettings['global']['environment'] != $_POST['environment']) {
+ if ($settingsTable['environment'] != $_POST['environment']) {
if ($_POST['environment'] == 0) { //-- USE INTERNAL
linkWebroot('internal');
} else { //-- USE EXTERNAL
@@ -386,18 +397,15 @@
}
}
- $settingsFile['global'] = $newSettings;
- $saveSettings = setServerFile('settings', $settingsFile);
-
- if ($saveSettings['code'] != 200) {
- $error = 'Error saving global settings on server ' . ACTIVE_SERVER_NAME;
- }
+ $settingsTable = apiRequest('database-setSettings', [], ['newSettings' => $newSettings])['result'];
//-- ONLY MAKE SERVER CHANGES ON LOCAL
- if ($_SESSION['serverIndex'] == 0) {
+ if ($activeServer['id'] == APP_SERVER_ID) {
+ $serverList = [];
+
//-- ADD SERVER TO LIST
if ($_POST['serverList-name-new'] && $_POST['serverList-url-new'] && $_POST['serverList-apikey-new']) {
- $serversFile[] = ['name' => $_POST['serverList-name-new'], 'url' => rtrim($_POST['serverList-url-new'], '/'), 'apikey' => $_POST['serverList-apikey-new']];
+ $serverList[] = ['name' => $_POST['serverList-name-new'], 'url' => rtrim($_POST['serverList-url-new'], '/'), 'apikey' => $_POST['serverList-apikey-new']];
}
//-- UPDATE SERVER LIST
@@ -406,14 +414,14 @@
continue;
}
- list($name, $field, $index) = explode('-', $key);
+ list($name, $field, $instanceId) = explode('-', $key);
- if (!is_numeric($index)) {
+ if (!is_numeric($instanceId)) {
continue;
}
- if ($_POST['serverList-name-' . $index] && $_POST['serverList-url-' . $index] && $_POST['serverList-apikey-' . $index]) {
- $serversFile[$index] = ['name' => $_POST['serverList-name-' . $index], 'url' => rtrim($_POST['serverList-url-' . $index], '/'), 'apikey' => $_POST['serverList-apikey-' . $index]];
+ if ($_POST['serverList-name-' . $instanceId] && $_POST['serverList-url-' . $instanceId] && $_POST['serverList-apikey-' . $instanceId]) {
+ $serverList[$instanceId] = ['name' => $_POST['serverList-name-' . $instanceId], 'url' => rtrim($_POST['serverList-url-' . $instanceId], '/'), 'apikey' => $_POST['serverList-apikey-' . $instanceId]];
}
}
@@ -423,41 +431,25 @@
continue;
}
- list($name, $field, $index) = explode('-', $key);
+ list($name, $field, $instanceId) = explode('-', $key);
- if (!is_numeric($index)) {
+ if (!is_numeric($instanceId)) {
continue;
}
- if (!$_POST['serverList-name-' . $index] && !$_POST['serverList-url-' . $index] && !$_POST['serverList-apikey-' . $index]) {
- unset($serversFile[$index]);
+ if (!$_POST['serverList-name-' . $instanceId] && !$_POST['serverList-url-' . $instanceId] && !$_POST['serverList-apikey-' . $instanceId]) {
+ $serverList[$instanceId]['remove'] = true;
}
}
- $saveServers = setServerFile('servers', $serversFile);
-
- if ($saveServers['code'] != 200) {
- $error = 'Error saving server list on server ' . ACTIVE_SERVER_NAME;
- }
- } else {
- $serversFile = getFile(SERVERS_FILE);
+ $serversTable = apiRequest('database-setServers', [], ['serverList' => $serverList])['result'];
}
- $serverList = '';
- foreach ($serversFile as $serverIndex => $serverDetails) {
- $ping = curl($serverDetails['url'] . '/api/?request=ping', ['x-api-key: ' . $serverDetails['apikey']]);
- $disabled = '';
- if ($ping['code'] != 200) {
- $disabled = ' [HTTP: ' . $ping['code'] . ']';
- }
- $serverList .= '';
- }
-
- echo json_encode(['error' => $error, 'server' => ACTIVE_SERVER_NAME, 'serverList' => $serverList]);
+ echo json_encode(['error' => $error, 'server' => ACTIVE_SERVER_NAME, 'serverList' => getRemoteServerSelect()]);
}
//-- CALLED FROM THE NAV MENU SELECT
-if ($_POST['m'] == 'updateServerIndex') {
- $_SESSION['serverIndex'] = intval($_POST['index']);
+if ($_POST['m'] == 'updateActiveServer') {
+ apiSetActiveServer(intval($_POST['id']));
$_SESSION['serverList'] = '';
-}
\ No newline at end of file
+}
diff --git a/root/app/www/public/ajax/shared.php b/root/app/www/public/ajax/shared.php
index 24c8e10..124fc6c 100644
--- a/root/app/www/public/ajax/shared.php
+++ b/root/app/www/public/ajax/shared.php
@@ -18,7 +18,9 @@
}
require ABSOLUTE_PATH . 'loader.php';
-if (!$_SESSION['IN_DOCKWATCH']) {
- http_response_code(400);
- exit('Error: You should use the UI, its much prettier.');
+if (!str_contains_any($_SERVER['PHP_SELF'], ['/api/']) && !str_contains($_SERVER['PWD'], 'oneshot')) {
+ if (!$_SESSION['IN_DOCKWATCH']) {
+ http_response_code(400);
+ exit('Error: You should use the UI, its much prettier.');
+ }
}
diff --git a/root/app/www/public/ajax/tasks.php b/root/app/www/public/ajax/tasks.php
index 631febb..a3246b9 100644
--- a/root/app/www/public/ajax/tasks.php
+++ b/root/app/www/public/ajax/tasks.php
@@ -26,43 +26,43 @@