diff --git a/css/index.css b/css/index.css index 9019721..87ed970 100644 --- a/css/index.css +++ b/css/index.css @@ -17,3 +17,54 @@ body { .signed { margin-top: 20px; } + +/* +https://bootsnipp.com/snippets/jvP6z +*/ +.mini-led-green, .mini-led-green-blink { + background-color: #80FF00; + box-shadow: #7D7B80 0 -1px 6px 1px, inset #460 0 -1px 8px, #80FF00 0 3px 11px; +} +.mini-led-red, .mini-led-red-blink { + background-color: #F00; + box-shadow: #7D7B80 0 -1px 6px 1px, inset #600 0 -1px 8px, #F00 0 3px 11px; +} +.mini-led-gray, +.mini-led-gray-blink, +.mini-led-red, +.mini-led-red-blink, +.mini-led-orange, +.mini-led-orange-blink, +.mini-led-green, +.mini-led-green-blink, +.mini-led-yellow, +.mini-led-yellow-blink, +.mini-led-blue, +.mini-led-blue-blink { + margin: 0 auto; + margin-top: 5px; + width: 12px; + height: 12px; + border-radius: 50%; +} + +#config-cards textarea { + font-family: Courier; +} + +#message-stage { + position: fixed; + bottom: 0; +} +#message-stage i.stauts-icon { + margin-right: 10px; +} + +#save-config-btn.get-attention a { + background-color: #f0ad4e; /* orange */ + color: white; +} +#save-config-btn.saved-success a { + background-color: #5cb85c; /* green */ + color: white; +} \ No newline at end of file diff --git a/include/grids.php b/include/grids.php index 68a1138..abd658d 100644 --- a/include/grids.php +++ b/include/grids.php @@ -45,9 +45,27 @@ // Creation of the LIMIT for build different pages $page = "LIMIT $offset, $limit"; + // ... filtering by the bootstrap table plugin + $filter = isset($_GET['filter']) ? json_decode($_GET['filter'],true) : []; // this is passed by the bootstrap table filter plugin (if a filter was chosen by the user): these are the concrete set filters with their value + $where = !empty($filter)?'WHERE TRUE':''; + $allowed_query_filters = ['user_id', 'log_trusted_ip','log_trusted_port','log_remote_ip','log_remote_port']; // these are valid filters that could be used (defined here for sql security reason) + $query_filters_existing = []; + foreach($filter as $unsanitized_filter_key => $unsanitized_filter_val) { + if(in_array($unsanitized_filter_key, $allowed_query_filters)) { // if this condition does not match: ignore it, because this parameter should not be passed + // if $unsanitized_filter_key is in array $allowed_query_filters its a valid key and can not be harmful, so it can be considered sanitized + $where .= " AND $unsanitized_filter_key = ?"; + $query_filters_existing[] = $unsanitized_filter_key; + } + } + // Select the logs - $req_string = "SELECT *, (SELECT COUNT(*) FROM log) AS nb FROM log ORDER BY log_id DESC $page"; + $req_string = "SELECT *, (SELECT COUNT(*) FROM log $where) AS nb FROM log $where ORDER BY log_id DESC $page"; $req = $bdd->prepare($req_string); + + // dynamically bind the params + foreach(array_merge($query_filters_existing,$query_filters_existing) as $i => $query_filter) // array_merge -> duplicated the array contents; this is needed because our where clause is bound two times (in subquery + the outer query) + $req->bindValue($i+1, $filter[$query_filter]); + $req->execute(); $list = array(); @@ -75,7 +93,6 @@ "log_received" => $received, "log_send" => $sent)); - } while ($data = $req->fetch()); } else { @@ -203,4 +220,36 @@ $req->execute(array($_POST['del_admin_id'])); } + // ---------------- UPDATE CONFIG ---------------- + else if(isset($_POST['update_config'])){ + + $pathinfo = pathinfo($_POST['config_file']); + + $config_full_uri = $_POST['config_file']; // the complete path to the file, including the file (name) its self and the fully qualified path + $config_full_path = $pathinfo['dirname']; // path to file (without filename its self) + $config_name = basename($_POST['config_file']); // config file name only (without path) + $config_parent_dir = basename($config_full_path); // name of the dir that contains the config file (without path) + + /* + * create backup for history + */ + if (!file_exists($dir="../$config_full_path/history")) + mkdir($dir, 0777, true); + $ts = time(); + copy("../$config_full_uri", "../$config_full_path/history/${ts}_${config_name}"); + + /* + * write config + */ + $conf_success = file_put_contents('../'.$_POST['config_file'], $_POST['config_content']); + + echo json_encode([ + 'debug' => [ + 'config_file' => $_POST['config_file'], + 'config_content' => $_POST['config_content'] + ], + 'config_success' => $conf_success !== false, + ]); + } + ?> diff --git a/include/html/grids.php b/include/html/grids.php index 5c4845f..ff3dd6e 100644 --- a/include/html/grids.php +++ b/include/html/grids.php @@ -1,9 +1,40 @@ + +
= file_get_contents($file) ?>