Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
//includes files
require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php";
//check permissions
if (permission_exists('device_log_add') || permission_exists('device_log_edit')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;
$text = $language->get();
//connect to the database
$database = new database;
//action add or update
if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"])) {
$action = "update";
$device_log_uuid = $_REQUEST["id"];
$id = $_REQUEST["id"];
}
else {
$action = "add";
}
//get http post variables and set them to php variables
if (is_array($_POST)) {
$device_log_uuid = $_POST["device_log_uuid"] ?? null;
$device_uuid = $_POST["device_uuid"] ?? null;
$timestamp = $_POST["timestamp"] ?? '';
$device_address = $_POST["device_address"] ?? '';
$request_scheme = $_POST["request_scheme"] ?? '';
$http_host = $_POST["http_host"] ?? '';
$server_port = $_POST["server_port"] ?? '';
$server_protocol = $_POST["server_protocol"] ?? '';
$query_string = $_POST["query_string"] ?? '';
$remote_address = $_POST["remote_address"] ?? '';
$http_user_agent = $_POST["http_user_agent"] ?? '';
$http_status = $_POST["http_status"] ?? '';
$http_status_code = $_POST["http_status_code"] ?? '';
$http_content_body = $_POST["http_content_body"] ?? '';
}
//process the user data and save it to the database
if (count($_POST) > 0 && empty($_POST["persistformvar"])) {
//delete the bridge
if (permission_exists('bridge_delete')) {
if ($_POST['action'] == 'delete' && is_uuid($device_log_uuid)) {
//prepare
$array[0]['checked'] = 'true';
$array[0]['uuid'] = $device_log_uuid;
//delete
$obj = new device_logs;
$obj->delete($array);
//redirect
header('Location: device_logs.php');
exit;
}
}
//get the uuid from the POST
if ($action == "update") {
$device_log_uuid = $_POST["device_log_uuid"];
}
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: device_logs.php');
exit;
}
//check for all required data
$msg = '';
//if (strlen($device_uuid) == 0) { $msg .= $text['message-required']." ".$text['label-device_uuid']."
\n"; }
if (strlen($timestamp) == 0) { $msg .= $text['message-required']." ".$text['label-timestamp']."
\n"; }
if (strlen($device_address) == 0) { $msg .= $text['message-required']." ".$text['label-device_address']."
\n"; }
if (strlen($request_scheme) == 0) { $msg .= $text['message-required']." ".$text['label-request_scheme']."
\n"; }
if (strlen($http_host) == 0) { $msg .= $text['message-required']." ".$text['label-http_host']."
\n"; }
if (strlen($server_port) == 0) { $msg .= $text['message-required']." ".$text['label-server_port']."
\n"; }
if (strlen($server_protocol) == 0) { $msg .= $text['message-required']." ".$text['label-server_protocol']."
\n"; }
if (strlen($query_string) == 0) { $msg .= $text['message-required']." ".$text['label-query_string']."
\n"; }
if (strlen($remote_address) == 0) { $msg .= $text['message-required']." ".$text['label-remote_address']."
\n"; }
if (strlen($http_user_agent) == 0) { $msg .= $text['message-required']." ".$text['label-http_user_agent']."
\n"; }
if (strlen($http_status) == 0) { $msg .= $text['message-required']." ".$text['label-http_status']."
\n"; }
if (strlen($http_status_code) == 0) { $msg .= $text['message-required']." ".$text['label-http_status_code']."
\n"; }
//if (strlen($http_content_body) == 0) { $msg .= $text['message-required']." ".$text['label-http_content_body']."
\n"; }
if (strlen($msg) > 0 && empty($_POST["persistformvar"])) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "
\n";
echo $msg." "; echo " |