$ip, 'resolve_text' => $res); else $response = array('resolve_ip' => $ip, 'resolve_text' => gettext("Cannot resolve")); echo json_encode(str_replace("\\","\\\\", $response)); // single escape chars can break JSON decode exit; } # --- AJAX REVERSE DNS RESOLVE End --- # --- AJAX GEOIP CHECK Start --- if (isset($_POST['geoip'])) { $ip = strtolower($_POST['geoip']); if (is_ipaddr($ip)) { $url = "https://api.hackertarget.com/geoip/?q={$ip}"; $conn = curl_init("https://api.hackertarget.com/geoip/?q={$ip}"); curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($conn, CURLOPT_FRESH_CONNECT, true); curl_setopt($conn, CURLOPT_RETURNTRANSFER, 1); set_curlproxy($conn); $res = curl_exec($conn); curl_close($conn); } else { $res = ''; } if ($res && $res != $ip && !preg_match('/error/', $res)) $response = array('geoip_text' => $res); else $response = array('geoip_text' => gettext("Cannot check {$ip}")); echo json_encode(str_replace("\\","\\\\", $response)); // single escape chars can break JSON decode exit; } # --- AJAX GEOIP CHECK End --- if ($_POST['mode'] == 'todelete') { $ip = ""; if ($_POST['ip']) $ip = $_POST['ip']; if (is_ipaddr($ip)) exec("/sbin/pfctl -t {$suri_pf_table} -T delete {$ip}"); else $input_errors[] = gettext("An invalid IP address was provided as a parameter."); } if ($_POST['remove']) { exec("/sbin/pfctl -t {$suri_pf_table} -T flush"); header("Location: /suricata/suricata_blocked.php"); exit; } /* TODO: build a file with block ip and disc */ if ($_POST['download']) { $blocked_ips_array_save = ""; exec("/sbin/pfctl -t {$suri_pf_table} -T show", $blocked_ips_array_save); /* build the list */ if (is_array($blocked_ips_array_save) && count($blocked_ips_array_save) > 0) { $save_date = date("Y-m-d-H-i-s"); $file_name = "suricata_blocked_{$save_date}.tar.gz"; safe_mkdir("{$g['tmp_path']}/suricata_blocked"); file_put_contents("{$g['tmp_path']}/suricata_blocked/suricata_block.pf", ""); foreach($blocked_ips_array_save as $counter => $fileline) { if (empty($fileline)) continue; $fileline = trim($fileline, " \n\t"); file_put_contents("{$g['tmp_path']}/suricata_blocked/suricata_block.pf", "{$fileline}\n", FILE_APPEND); } // Create a tar gzip archive of blocked host IP addresses exec("/usr/bin/tar -czf {$g['tmp_path']}/{$file_name} -C{$g['tmp_path']}/suricata_blocked suricata_block.pf"); // If we successfully created the archive, send it to the browser. if(file_exists("{$g['tmp_path']}/{$file_name}")) { ob_start(); //important or other posts will fail if (isset($_SERVER['HTTPS'])) { header('Pragma: '); header('Cache-Control: '); } else { header("Pragma: private"); header("Cache-Control: private, must-revalidate"); } header("Content-Type: application/octet-stream"); header("Content-length: " . filesize("{$g['tmp_path']}/{$file_name}")); header("Content-disposition: attachment; filename = {$file_name}"); ob_end_clean(); //important or other post will fail readfile("{$g['tmp_path']}/{$file_name}"); // Clean up the temp files and directory unlink_if_exists("{$g['tmp_path']}/{$file_name}"); rmdir_recursive("{$g['tmp_path']}/suricata_blocked"); } else $savemsg = gettext("An error occurred while creating archive"); } else $savemsg = gettext("No content on suricata block list"); } if ($_POST['save']) { /* no errors */ if (!$input_errors) { config_set_path('installedpackages/suricata/alertsblocks/brefresh', $_POST['brefresh'] ? 'on' : 'off'); config_set_path('installedpackages/suricata/alertsblocks/blertnumber', $_POST['blertnumber']); write_config("Suricata pkg: updated BLOCKED tab settings."); header("Location: /suricata/suricata_blocked.php"); exit; } } $pglinks = array("", "/suricata/suricata_interfaces.php", "@self"); $pgtitle = array("Services", "Suricata", "Blocked Hosts"); include_once("head.inc"); /* refresh every 60 secs */ if ($pconfig['brefresh'] == 'on') { print ''; } /* Display Alert message */ if ($input_errors) { print_input_errors($input_errors); } if ($savemsg) { print_info_box($savemsg); } $tab_array = array(); $tab_array[] = array(gettext("Interfaces"), false, "/suricata/suricata_interfaces.php"); $tab_array[] = array(gettext("Global Settings"), false, "/suricata/suricata_global.php"); $tab_array[] = array(gettext("Updates"), false, "/suricata/suricata_download_updates.php"); $tab_array[] = array(gettext("Alerts"), false, "/suricata/suricata_alerts.php"); $tab_array[] = array(gettext("Blocks"), true, "/suricata/suricata_blocked.php"); $tab_array[] = array(gettext("Files"), false, "/suricata/suricata_files.php"); $tab_array[] = array(gettext("Pass Lists"), false, "/suricata/suricata_passlist.php"); $tab_array[] = array(gettext("Suppress"), false, "/suricata/suricata_suppress.php"); $tab_array[] = array(gettext("Logs View"), false, "/suricata/suricata_logs_browser.php?instance={$instanceid}"); $tab_array[] = array(gettext("Logs Mgmt"), false, "/suricata/suricata_logs_mgmt.php"); $tab_array[] = array(gettext("SID Mgmt"), false, "/suricata/suricata_sid_mgmt.php"); $tab_array[] = array(gettext("Sync"), false, "/pkg_edit.php?xml=suricata/suricata_sync.xml"); $tab_array[] = array(gettext("IP Lists"), false, "/suricata/suricata_ip_list_mgmt.php"); display_top_tabs($tab_array, true); $form = new Form(false); $form->setAttribute('id', 'formblock'); $section = new Form_Section('Blocked Hosts Log View Settings'); $group = new Form_Group('Save or Remove Hosts'); $group->add(new Form_Button( 'download', 'Download', null, 'fa-solid fa-download' ))->removeClass('btn-default')->addClass('btn-info btn-sm') ->setHelp('All blocked hosts will be saved'); $group->add(new Form_Button( 'remove', 'Clear', null, 'fa-solid fa-trash-can' ))->removeClass('btn-default')->addClass('btn-danger btn-sm') ->setHelp('All blocked hosts will be cleared'); $section->add($group); $group = new Form_Group('Save Settings'); $group->add(new Form_Button( 'save', 'Save', null, 'fa-solid fa-save' ))->removeClass('btn-default')->addClass('btn-success btn-sm') ->setHelp('Save auto-refresh and view settings'); $group->add(new Form_Checkbox( 'brefresh', null, 'Refresh', ((config_get_path('installedpackages/suricata/alertsblocks/brefresh')=="on") || (config_get_path('installedpackages/suricata/alertsblocks/brefresh')=='')), 'on' ))->setHelp('Default is ON'); $group->add(new Form_Input( 'blertnumber', 'Blocked Entries', 'number', $bnentries ))->setHelp('Number of blocked entries to view. Default is 500'); $section->add($group); $form->add($section); $form->addGlobal(new Form_Input( 'id', 'id', 'hidden', '' )); $form->addGlobal(new Form_Input( 'ip', 'ip', 'hidden', '' )); $form->addGlobal(new Form_Input( 'mode', 'mode', 'hidden', '' )); print($form); ?>
| =gettext("Blocked IP"); ?> | =gettext("Block Date/Time"); ?> | =gettext("Block Alert Description"); ?> | =gettext("Block Rule GID:SID"); ?> | =gettext("Remove Block"); ?> |
|---|---|---|---|---|
| =$tmp_ip;?> =$rdns_link;?> | =$blocked_time;?> | =$blocked_desc;?> | =$blocked_ruleid;?> | "> |
| 1) print($counter . gettext(" host IP addresses are currently being blocked.")); else print($counter . gettext(" host IP address is currently being blocked.")); } else { print(gettext("There are currently no hosts being blocked by Suricata.")); } ?> | ||||