$defaultRaw, 'parsed'=>[], 'exists'=>false, 'via'=>'none']; $r = bg_config_read($catalog[$key]); if (trim((string)($r['raw'] ?? '')) === '' && $defaultRaw !== '') { $r['raw'] = $defaultRaw; $r['parsed'] = @parse_ini_string($defaultRaw, false, INI_SCANNER_RAW) ?: []; } return $r; } function sx_config_parsed($key, $fallback = []) { $r = sx_config_read_key($key); return is_array($r['parsed'] ?? null) ? $r['parsed'] : $fallback; } function sx_save_config_key($key, $content, $user = null) { return bg_config_save_key($key, (string)$content); } function sx_json_config($key, $fallback = []) { $r = sx_config_read_key($key); if (is_array($r['parsed'] ?? null)) return $r['parsed']; return $fallback; } function sx_scanner_raw_from_values(array $old, array $updates) { $merged = array_merge($old, $updates); $out = "# --- BastionGuard Anti-Ransomware Config ---\n"; $out .= 'suspicious_only=' . (!empty($merged['suspicious_only']) ? '1' : '0') . "\n"; $out .= 'ignore_paths=' . ($merged['ignore_paths'] ?? '/proc;/sys;/dev;/run;/tmp') . "\n"; $out .= 'ignore_ext=' . ($merged['ignore_ext'] ?? '.tmp;.log;.cache') . "\n"; $out .= 'suspicious_ext=' . ($merged['suspicious_ext'] ?? '.locked;.encrypted;.crypt;.enc') . "\n\n"; $out .= "# --- Ransomware Scanner ---\n"; $out .= 'enable_yara=' . (!empty($merged['enable_yara']) ? '1' : '0') . "\n"; $out .= 'enable_sanesecurity=' . (!empty($merged['enable_sanesecurity']) ? '1' : '0') . "\n"; $out .= 'scan_interval=' . max(1, (int)($merged['scan_interval'] ?? 60)) . "\n"; $out .= 'scan_path=' . ($merged['scan_path'] ?? '/home') . "\n"; return $out; } function sx_clamd_read() { $res = bg_admin_helper(['read-clamd-b64'], 60); if ((int)($res['code'] ?? 1) === 0) { $raw = base64_decode(trim((string)$res['output']), true); if ($raw !== false) return ['raw'=>$raw, 'path'=>'auto', 'via'=>'helper', 'error'=>'']; } foreach (['/etc/clamd/clamd.conf','/etc/clamav/clamd.conf','/etc/clamd.d/clamd.conf','/etc/clamd.conf'] as $p) { if (is_file($p) && is_readable($p)) return ['raw'=>(string)file_get_contents($p), 'path'=>$p, 'via'=>'direct', 'error'=>'']; } return ['raw'=>"OnAccessIncludePath /home\nScanPE yes\nScanELF yes\nScanOLE2 yes\nScanPDF yes\nScanSWF yes\nScanXMLDOCS yes\nScanHWP3 yes\nScanArchive yes\n", 'path'=>'not found', 'via'=>'default', 'error'=>(string)($res['output'] ?? '')]; } function sx_parse_clamd($raw) { $paths = []; $opts = []; foreach (preg_split('/\R/', (string)$raw) as $line) { $t = trim($line); if ($t === '') continue; $commented = str_starts_with($t, '#'); if ($commented) $t = trim(substr($t, 1)); if (!preg_match('/^([A-Za-z0-9_]+)\s+(.+)$/', $t, $m)) continue; $key = $m[1]; $value = trim($m[2]); if (!$commented && $key === 'OnAccessIncludePath') $paths[] = $value; if (in_array(strtolower($value), ['yes','no'], true)) $opts[$key] = (!$commented && strtolower($value) === 'yes'); } return ['paths'=>array_values(array_unique($paths)), 'options'=>$opts]; } function sx_build_clamd($raw, array $paths = null, array $options = null) { $lines = preg_split('/\R/', (string)$raw); $out = []; $seenOpt = []; foreach ($lines as $line) { $t = trim($line); $commented = str_starts_with($t, '#'); $probe = $commented ? trim(substr($t,1)) : $t; if (preg_match('/^OnAccessIncludePath\s+/', $probe) && $paths !== null) continue; if ($options !== null && preg_match('/^([A-Za-z0-9_]+)\s+(yes|no)\s*$/i', $probe, $m)) { $key = $m[1]; if (array_key_exists($key, $options)) { $out[] = $key . ' ' . (!empty($options[$key]) ? 'yes' : 'no'); $seenOpt[$key] = true; continue; } } $out[] = $line; } if ($paths !== null) { $out[] = ''; $out[] = '# BastionGuard WebPanel On-Access paths'; foreach (array_values(array_unique(array_filter(array_map('trim',$paths)))) as $p) $out[] = 'OnAccessIncludePath ' . $p; } if ($options !== null) { foreach ($options as $k=>$v) if (!isset($seenOpt[$k])) $out[] = $k . ' ' . ($v ? 'yes' : 'no'); } return rtrim(implode("\n", $out)) . "\n"; } function sx_write_clamd($raw) { return bg_admin_helper(['write-clamd-b64', base64_encode((string)$raw)], 120); } function sx_list_yara_rules() { $rules = []; foreach (['/usr/share/BastionGuard/data/yara', bg_bastionguard_data_dir() . '/data/yara'] as $dir) { if (!is_dir($dir) || !is_readable($dir)) continue; foreach (glob($dir.'/*.{yar,yara}', GLOB_BRACE) ?: [] as $file) { $raw = @file_get_contents($file); if ($raw && preg_match_all('/^\s*rule\s+([A-Za-z0-9_]+)/m', $raw, $m)) foreach($m[1] as $r) $rules[]=$r; } } return array_values(array_unique($rules)); } function sx_list_blacklists() { $files = ['/usr/share/BastionGuard/data/phishing/blacklist.txt','/usr/share/BastionGuard/data/phishing/blacklist-reduce.txt','/usr/share/BastionGuard/data/phishing/blacklist_custom.txt', bg_bastionguard_data_dir().'/data/phishing/blacklist.txt', bg_bastionguard_data_dir().'/data/phishing/blacklist-reduce.txt']; $out=[]; foreach($files as $file){ if(!is_file($file)) continue; $lines=0; if(is_readable($file) && ($fh=@fopen($file,'r'))){ while(!feof($fh)){ fgets($fh); $lines++; } fclose($fh); } $out[]=['file'=>$file,'size'=>@filesize($file)?:0,'mtime'=>@filemtime($file)?:0,'lines'=>$lines]; } return $out; } function sx_google_safe_test($key) { $key = trim((string)$key); if ($key === '') return ['code'=>1,'output'=>sx('No API key configured.','Nessuna API key configurata.')]; $res = bg_http_get('https://safebrowsing.googleapis.com/v4/threatLists?key=' . rawurlencode($key), [], 15); $ok = (($res['code'] ?? 0) >= 200 && ($res['code'] ?? 0) < 300 && str_contains((string)($res['body'] ?? ''), 'threatType')); return ['code'=>$ok?0:1, 'output'=>$ok ? sx('Google Safe Browsing key is valid.','Chiave Google Safe Browsing valida.') : ('HTTP '.($res['code'] ?? 0)."\n".(($res['error'] ?? '') ?: substr((string)($res['body'] ?? ''),0,500)))]; } function sx_shell_first_line($cmd) { $out = trim((string)bg_shell_exec($cmd)); $lines = preg_split('/\R+/', $out); return trim((string)($lines[0] ?? '')); } function sx_cmd_exists($cmd) { return bg_cmd_exists($cmd); } function sx_service_active($service) { $service = preg_replace('/[^A-Za-z0-9_.@:-]/', '', (string)$service); if ($service === '') return false; $res = bg_run_argv(['systemctl','is-active','--quiet',$service], 10); return (int)($res['code'] ?? 1) === 0; } function sx_detect_distro() { $id = ''; if (sx_cmd_exists('lsb_release')) { $lsb = sx_shell_first_line('lsb_release -si 2>/dev/null'); if ($lsb !== '' && stripos($lsb, 'n/a') === false) $id = $lsb; } if ($id === '' && is_readable('/etc/os-release')) { foreach (file('/etc/os-release', FILE_IGNORE_NEW_LINES) ?: [] as $line) { if (strpos($line, 'ID=') === 0) { $id = trim(substr($line, 3), " \t\n\r\0\x0B\""); break; } } } if ($id === '') { if (file_exists('/etc/arch-release')) $id = 'arch'; elseif (file_exists('/etc/debian_version')) $id = 'debian'; elseif (file_exists('/etc/redhat-release')) $id = 'fedora'; elseif (file_exists('/etc/gentoo-release')) $id = 'gentoo'; elseif (file_exists('/etc/slackware-version')) $id = 'slackware'; elseif (file_exists('/usr/local/etc/rc.conf')) $id = 'bsd'; } $id = strtolower($id); if (str_contains($id, 'debian') || str_contains($id, 'ubuntu') || str_contains($id, 'mint')) return 'debian'; if (str_contains($id, 'fedora') || str_contains($id, 'rhel') || str_contains($id, 'centos') || str_contains($id, 'alma') || str_contains($id, 'rocky')) return 'fedora'; if (str_contains($id, 'arch') || str_contains($id, 'manjaro') || str_contains($id, 'endeavour')) return 'arch'; if (str_contains($id, 'suse')) return 'opensuse'; if (str_contains($id, 'gentoo')) return 'gentoo'; if (str_contains($id, 'slackware')) return 'slackware'; if (str_contains($id, 'bsd')) return 'bsd'; return 'auto'; } function sx_detect_webserver() { if (sx_service_active('apache2') || sx_service_active('httpd') || sx_cmd_exists('apache2') || sx_cmd_exists('httpd')) return 'apache'; if (sx_service_active('nginx') || sx_cmd_exists('nginx')) return 'nginx'; if (sx_service_active('lshttpd') || sx_service_active('lsws') || sx_cmd_exists('lsws') || sx_cmd_exists('lshttpd')) return 'litespeed'; $out = (string)bg_shell_exec("ps -eo comm 2>/dev/null | grep -E 'apache2|httpd|nginx|lshttpd|lsws' | grep -v grep 2>/dev/null"); if (str_contains($out, 'apache2') || str_contains($out, 'httpd')) return 'apache'; if (str_contains($out, 'nginx')) return 'nginx'; if (str_contains($out, 'lshttpd') || str_contains($out, 'lsws')) return 'litespeed'; return 'unknown'; } function sx_read_webports_conf() { $http = 81; $https = 444; foreach (['/etc/BastionGuard/webports.conf','/tmp/BastionGuard_webports.conf'] as $p) { if (!is_readable($p)) continue; $raw = trim((string)@file_get_contents($p)); if ($raw === '') continue; $parts = preg_split('/\s+/', $raw); $p1 = isset($parts[0]) && is_numeric($parts[0]) ? (int)$parts[0] : 0; $p2 = isset($parts[1]) && is_numeric($parts[1]) ? (int)$parts[1] : 0; if ($p1 > 0 && $p1 < 65536) $http = $p1; if ($p2 > 0 && $p2 < 65536) $https = $p2; break; } return [$http, $https]; } function sx_distro_label($id) { $labels = ['auto'=>'auto','debian'=>'Debian / Ubuntu / Mint','fedora'=>'Fedora / RHEL / CentOS / Alma / Rocky','arch'=>'Arch / Manjaro / Endeavour','opensuse'=>'openSUSE / SLE','gentoo'=>'Gentoo','slackware'=>'Slackware','bsd'=>'BSD']; return $labels[$id] ?? $id; } function sx_webserver_label($id) { $labels = ['apache'=>'Apache / httpd','nginx'=>'NGINX','litespeed'=>'LiteSpeed','unknown'=>sx('not detected','non rilevato')]; return $labels[$id] ?? $id; } $detectedDistro = sx_detect_distro(); $detectedWebserver = sx_detect_webserver(); [$detectedHttp, $detectedHttps] = sx_read_webports_conf(); $detectedUser = bg_detect_desktop_user(); $web = bg_read_json('web_options.json', ['http_port'=>$detectedHttp,'https_port'=>$detectedHttps,'desktop_user'=>$detectedUser]); unset($web['language'], $web['theme']); $web['language'] = bg_language(); $web['theme'] = bg_theme(); if (empty($web['desktop_user']) && $detectedUser !== '') $web['desktop_user'] = $detectedUser; $web['http_port'] = $detectedHttp; $web['https_port'] = $detectedHttps; $web['webpanel_name'] = bg_sanitize_webpanel_name($web['webpanel_name'] ?? 'WebPanel'); $web['dashboard_widgets'] = array_merge(bg_dashboard_widget_defaults(), is_array($web['dashboard_widgets'] ?? null) ? $web['dashboard_widgets'] : []); $desktopUser = $web['desktop_user'] ?: $detectedUser; $desktopMode = bg_desktop_mode_summary($desktopUser); $desktopGuiActive = !empty($desktopMode['gui']); $desktopModeSummary = (string)($desktopMode['summary'] ?? 'headless'); $catalog = bg_services_catalog(); $cfgCatalog = bg_config_catalog(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { csrf_validate(); $a = $_POST['action'] ?? ''; $targetUser = preg_replace('/[^a-zA-Z0-9_-]/', '', (string)($_POST['desktop_user'] ?? $desktopUser)); if ($a === 'save-web') { $web = bg_read_json('web_options.json', []); if (!is_array($web)) $web = []; unset($web['language'], $web['theme']); $web['http_port'] = max(1,min(65535,(int)($_POST['http_port'] ?? 81))); $web['https_port'] = max(1,min(65535,(int)($_POST['https_port'] ?? 444))); $web['desktop_user'] = $targetUser; $web['webpanel_name'] = bg_sanitize_webpanel_name($_POST['webpanel_name'] ?? 'WebPanel'); $selectedWidgets = $_POST['dashboard_widgets'] ?? []; $dashboardWidgets = []; foreach (bg_dashboard_widget_defaults() as $widgetKey => $_defaultEnabled) { $dashboardWidgets[$widgetKey] = isset($selectedWidgets[$widgetKey]); } $web['dashboard_widgets'] = $dashboardWidgets; bg_write_json('web_options.json', $web); bg_flash('success', bg_t('web_options_saved')); bg_redirect('settings.php#options'); } elseif ($a === 'apply-web-config') { $chosenOs = $_POST['os'] ?? $detectedDistro; if ($chosenOs === '' || $chosenOs === 'auto') $chosenOs = $detectedDistro; $httpPort = max(1,min(65535,(int)($_POST['http_port'] ?? $detectedHttp))); $httpsPort = max(1,min(65535,(int)($_POST['https_port'] ?? $detectedHttps))); $res = bg_admin_helper(['apply-web-config', $httpPort, $httpsPort, $chosenOs], 120); if ((int)($res['code'] ?? 1) === 0) { $web['http_port'] = $httpPort; $web['https_port'] = $httpsPort; $web['detected_distro'] = $chosenOs; $web['detected_webserver'] = $detectedWebserver; unset($web['language'], $web['theme']); bg_write_json('web_options.json', $web); } bg_flash(((int)($res['code'] ?? 1)===0)?'success':'warning', $res['output'] ?: sx('Web configuration applied.','Configurazione web applicata.')); bg_redirect('settings.php#options'); } elseif ($a === 'save-clamav-base') { $clamd = sx_clamd_read(); $parsed = sx_parse_clamd($clamd['raw']); $paths = bg_normalize_lines($_POST['onaccess_paths'] ?? ''); $raw = sx_build_clamd($clamd['raw'], $paths, null); $res = sx_write_clamd($raw); $q = trim((string)($_POST['quarantine_path'] ?? '')); if ($q !== '') sx_save_config_key('config_ini', 'quarantinePath=' . $q . "\n", $targetUser); bg_flash(((int)($res['code'] ?? 1)===0)?'success':'warning', $res['output'] ?: sx('ClamAV realtime settings saved.','Impostazioni realtime ClamAV salvate.')); bg_redirect('settings.php#base'); } elseif ($a === 'save-clamav-advanced') { $clamd = sx_clamd_read(); $parsed = sx_parse_clamd($clamd['raw']); $new = []; foreach (array_keys($parsed['options']) as $opt) $new[$opt] = !empty($_POST['scan_option'][$opt]); $raw = sx_build_clamd($clamd['raw'], null, $new); $res = sx_write_clamd($raw); bg_flash(((int)($res['code'] ?? 1)===0)?'success':'warning', $res['output'] ?: sx('ClamAV scan options saved.','Opzioni scansione ClamAV salvate.')); bg_redirect('settings.php#advanced'); } elseif ($a === 'realtime-start' || $a === 'realtime-stop' || $a === 'realtime-restart') { $op = str_replace('realtime-', '', $a); $res = bg_service_action(['clamav-clamonacc.service','clamonacc.service'], $op, false); bg_flash(((int)($res['code'] ?? 1)===0)?'success':'warning', $res['output'] ?: 'systemctl '.$op); bg_redirect('settings.php#base'); } elseif ($a === 'save-ransom-scanner') { $scanner = sx_config_parsed('scanner', []); $updates = [ 'enable_yara'=>!empty($_POST['enable_yara']), 'enable_sanesecurity'=>!empty($_POST['enable_sanesecurity']), 'scan_interval'=>max(1,(int)($_POST['scan_interval'] ?? 60)), 'scan_path'=>sx_join_semicolon($_POST['scan_path'] ?? ''), 'suspicious_only'=>sx_bool($scanner,'suspicious_only',false), 'ignore_paths'=>$scanner['ignore_paths'] ?? '/proc;/sys;/dev;/run;/tmp', 'ignore_ext'=>$scanner['ignore_ext'] ?? '.tmp;.log;.cache', 'suspicious_ext'=>$scanner['suspicious_ext'] ?? '.locked;.encrypted;.crypt;.enc', ]; $res = sx_save_config_key('scanner', sx_scanner_raw_from_values($scanner, $updates), $targetUser); bg_flash(((int)($res['code'] ?? 1)===0)?'success':'warning', $res['output'] ?: sx('Scanner configuration saved.','Configurazione scanner salvata.')); bg_redirect('settings.php#antiransomware'); } elseif ($a === 'save-ransom-advanced') { $scanner = sx_config_parsed('scanner', []); $updates = [ 'suspicious_only'=>!empty($_POST['suspicious_only']), 'ignore_paths'=>sx_join_semicolon($_POST['ignore_paths'] ?? ''), 'ignore_ext'=>sx_join_semicolon($_POST['ignore_ext'] ?? ''), 'suspicious_ext'=>sx_join_semicolon($_POST['suspicious_ext'] ?? ''), 'enable_yara'=>sx_bool($scanner,'enable_yara',true), 'enable_sanesecurity'=>sx_bool($scanner,'enable_sanesecurity',true), 'scan_interval'=>sx_int($scanner,'scan_interval',60), 'scan_path'=>$scanner['scan_path'] ?? '/home', ]; sx_save_config_key('scanner', sx_scanner_raw_from_values($scanner, $updates), $targetUser); $allowLines = []; foreach (preg_split('/\R/', (string)($_POST['allowlist'] ?? '')) as $line) { $line=trim($line); if ($line !== '') $allowLines[]=$line; } $res = sx_save_config_key('allowlist', implode("\n", $allowLines)."\n", $targetUser); bg_flash(((int)($res['code'] ?? 1)===0)?'success':'warning', $res['output'] ?: sx('Advanced anti-ransomware settings saved.','Impostazioni anti-ransomware avanzate salvate.')); bg_redirect('settings.php#advanced-ransomware'); } elseif ($a === 'update-yara' || $a === 'update-sanesecurity' || $a === 'update-phishing') { $cmd = ['update-yara'=>'update-yara','update-sanesecurity'=>'update-sanesecurity','update-phishing'=>'update-phishing'][$a]; $res = bg_admin_helper([$cmd, $targetUser], 900); bg_flash(((int)($res['code'] ?? 1)===0)?'success':'warning', $res['output'] ?: $cmd); bg_redirect($a==='update-phishing'?'settings.php#antiphishing':'settings.php#antiransomware'); } elseif ($a === 'save-antiphish') { $g = "# Google Safe Browsing configuration\n"; $g .= 'google_safe_enabled=' . (!empty($_POST['google_safe_enabled']) ? 'true' : 'false') . "\n"; $g .= 'google_safe_key=' . trim((string)($_POST['google_safe_key'] ?? '')) . "\n"; sx_save_config_key('googlesafe', $g, $targetUser); $fw = 'enabled=' . (!empty($_POST['firewall_enabled']) ? '1' : '0') . "\nmode=" . preg_replace('/[^a-z0-9_-]/i','',$_POST['firewall_mode'] ?? 'auto') . "\n"; $res = sx_save_config_key('firewall', $fw, $targetUser); if (!empty($_POST['auto_update'])) bg_admin_helper(['phish-auto-update','enable'],120); else bg_admin_helper(['phish-auto-update','disable'],120); bg_flash(((int)($res['code'] ?? 1)===0)?'success':'warning', $res['output'] ?: sx('Anti-phishing settings saved.','Impostazioni anti-phishing salvate.')); bg_redirect('settings.php#antiphishing'); } elseif ($a === 'test-googlesafe') { $res = sx_google_safe_test($_POST['google_safe_key'] ?? ''); bg_flash(((int)$res['code']===0)?'success':'warning', $res['output']); bg_redirect('settings.php#antiphishing'); } elseif ($a === 'save-whitelist-blacklist') { $wl = array_values(array_unique(array_map('bg_normalize_domain', bg_normalize_lines($_POST['whitelist'] ?? '')))); $bl = array_values(array_unique(array_map('bg_normalize_domain', bg_normalize_lines($_POST['blacklist'] ?? '')))); $res = sx_save_config_key('whitelist', json_encode(['domains'=>array_values(array_filter($wl))], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES)."\n", $targetUser); $custom = implode("\n", array_values(array_filter($bl)))."\n"; if (trim($custom) !== '') bg_admin_helper(['write-system-file-b64','phishing_custom',base64_encode($custom)], 120); bg_flash(((int)($res['code'] ?? 1)===0)?'success':'warning', sx('Whitelist/blacklist saved.','Whitelist/blacklist salvate.')); bg_redirect('settings.php#advanced-phishing'); } elseif ($a === 'save-payments') { $domains = array_values(array_unique(array_filter(array_map('bg_normalize_domain', bg_normalize_lines($_POST['domains'] ?? ''))))); $paymentsJson = ['version'=>1,'updated_at'=>gmdate('Y-m-d'),'list'=>$domains]; sx_save_config_key('payments', json_encode($paymentsJson, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES)."\n", $targetUser); $settings = sx_json_config('settings', ['version'=>1]); if (!isset($settings['security']) || !is_array($settings['security'])) $settings['security']=[]; $settings['security']['secure_payments_enabled'] = !empty($_POST['enabled']); $res = sx_save_config_key('settings', json_encode($settings, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES)."\n", $targetUser); $ok = ((int)($res['code'] ?? 1)===0); $msg = sx('Safe payments saved. The WebUI never manages CEF/PAC; use the GTK UI for desktop secure browsing.', 'Pagamenti sicuri salvati. La WebUI non gestisce mai CEF/PAC; usa la GUI GTK per la navigazione sicura desktop.'); bg_flash($ok?'success':'warning', $msg); bg_redirect('settings.php#payments'); } elseif ($a === 'save-proxy-bypass') { $domains = array_values(array_unique(array_filter(array_map('bg_normalize_domain', bg_normalize_lines($_POST['domains'] ?? ''))))); $res = sx_save_config_key('proxy_bypass', json_encode(['domains'=>$domains], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES)."\n", $targetUser); $ok = ((int)($res['code'] ?? 1)===0); $msg = sx('Proxy bypass saved. The WebUI never manages CEF/PAC or desktop proxy ownership; use the GTK UI.', 'Bypass proxy salvato. La WebUI non gestisce mai CEF/PAC né la proprietà del proxy desktop; usa la GUI GTK.'); bg_flash($ok?'success':'warning', $msg); bg_redirect('settings.php#proxy-bypass'); } elseif ($a === 'install-secure-ca') { bg_flash('warning', sx('Secure browsing / CEF / PAC bootstrap is disabled in the WebUI. Use the GTK desktop UI for browser proxy setup.', 'Il bootstrap Navigazione sicura / CEF / PAC è disabilitato nella WebUI. Usa la GUI GTK desktop per configurare il proxy browser.')); bg_redirect('settings.php#payments'); } elseif ($a === 'save-email') { $old = sx_json_config('mail', []); $oldProfile = $old['profiles'][0] ?? []; $pass = (string)($_POST['smtp_password'] ?? ''); $profile = [ 'id'=>'default','label'=>trim((string)($_POST['profile_label'] ?? 'Default')) ?: 'Default', 'match_from'=>sx_lines($_POST['match_from'] ?? ''),'match_from_domain'=>sx_lines($_POST['match_from_domain'] ?? ''), 'smtp_host'=>trim((string)($_POST['smtp_host'] ?? '')), 'smtp_port'=>max(1,min(65535,(int)($_POST['smtp_port'] ?? 587))), 'starttls'=>!empty($_POST['starttls']),'implicit_tls'=>!empty($_POST['implicit_tls']),'username'=>trim((string)($_POST['smtp_user'] ?? '')), 'password'=>$pass !== '' ? $pass : (string)($oldProfile['password'] ?? ''), 'signature'=>['display_name'=>trim((string)($_POST['display_name'] ?? '')),'job_title'=>trim((string)($_POST['job_title'] ?? '')),'company'=>trim((string)($_POST['company'] ?? '')),'phone'=>trim((string)($_POST['phone'] ?? '')),'website'=>trim((string)($_POST['website'] ?? '')),'logo_path'=>'/usr/share/BastionGuard/data/logo.png'] ]; $mail = ['version'=>2,'enabled'=>!empty($_POST['enabled']),'scan_outgoing'=>!empty($_POST['scan_outgoing']),'inject_signature'=>!empty($_POST['inject_signature']),'local_smtp_host'=>trim((string)($_POST['local_host'] ?? '127.0.0.1')),'local_smtp_port'=>max(1,min(65535,(int)($_POST['local_port'] ?? 2525))),'local_smtp_tls_port'=>max(1,min(65535,(int)($_POST['local_tls_port'] ?? 2465))),'local_submission_port'=>max(1,min(65535,(int)($_POST['local_submission_port'] ?? 2587))),'advertise_starttls'=>!empty($_POST['advertise_starttls']),'enable_implicit_tls_listener'=>!empty($_POST['enable_implicit_tls_listener']),'default_profile_id'=>'default','profiles'=>[$profile]]; $res = sx_save_config_key('mail', json_encode($mail, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES)."\n", $targetUser); bg_admin_helper(['restart-user-service',$targetUser,'BastionGuard-mailproxy.service'],60); bg_flash(((int)($res['code'] ?? 1)===0)?'success':'warning', $res['output'] ?: sx('Email configuration saved.','Configurazione email salvata.')); bg_redirect('settings.php#email'); } elseif ($a === 'install-thunderbird-extension') { $res = bg_admin_helper(['install-thunderbird-extension',$targetUser],300); bg_flash(((int)($res['code'] ?? 1)===0)?'success':'warning', $res['output'] ?: 'Thunderbird extension install.'); bg_redirect('settings.php#email'); } elseif ($a === 'alert-email') { $old = bg_alert_mail_config(); $cfg = ['enabled'=>!empty($_POST['enabled']),'use_admin_emails'=>!empty($_POST['use_admin_emails']),'recipients'=>trim((string)($_POST['recipients'] ?? '')),'from'=>trim((string)($_POST['from'] ?? 'bastionguard@localhost')),'smtp_host'=>trim((string)($_POST['smtp_host'] ?? '')),'smtp_port'=>max(1,min(65535,(int)($_POST['smtp_port'] ?? 587))),'smtp_secure'=>in_array($_POST['smtp_secure'] ?? 'starttls',['none','starttls','ssl'],true)?$_POST['smtp_secure']:'starttls','smtp_user'=>trim((string)($_POST['smtp_user'] ?? '')),'smtp_pass'=>($_POST['smtp_pass'] ?? '') !== '' ? (string)$_POST['smtp_pass'] : (string)($old['smtp_pass'] ?? ''),'sendmail_fallback'=>!empty($_POST['sendmail_fallback'])]; bg_write_json('alert_email.json', $cfg); if (!empty($_POST['send_test'])) $res = bg_smtp_send($cfg, bg_alert_mail_recipients($cfg), '[BastionGuard] Test alert email', 'BastionGuard WebPanel SMTP alert test.'); else $res = ['code'=>0,'output'=>sx('Server alert email saved.','Email avvisi server salvata.')]; bg_flash(((int)($res['code'] ?? 1)===0)?'success':'warning', $res['output']); bg_redirect('settings.php#server-alerts'); } elseif (str_starts_with($a, 'svc:')) { [$x,$key,$op] = array_pad(explode(':',$a,3),3,''); if (isset($catalog[$key])) $res = bg_service_action($catalog[$key]['services'], $op, $catalog[$key]['user']); else $res = ['code'=>1,'output'=>'Unknown service']; bg_flash(((int)($res['code'] ?? 1)===0)?'success':'warning', $res['output'] ?: 'systemctl '.$op); bg_redirect('settings.php#services'); } } $clamd = sx_clamd_read(); $clamdParsed = sx_parse_clamd($clamd['raw']); $configIni = sx_config_parsed('config_ini', ['quarantinePath'=>bg_bastionguard_data_dir($desktopUser).'/quarantine']); $scanner = sx_config_parsed('scanner', []); $allow = sx_config_read_key('allowlist'); $googlesafe = sx_config_parsed('googlesafe', ['google_safe_enabled'=>'false','google_safe_key'=>'']); $firewall = sx_config_parsed('firewall', ['enabled'=>'1','mode'=>'auto']); $whitelist = sx_json_config('whitelist', ['domains'=>[]]); $settingsJson = sx_json_config('settings', ['version'=>1,'security'=>['secure_payments_enabled'=>false]]); $payments = sx_json_config('payments', ['version'=>1,'list'=>['paypal.com','stripe.com','adyen.com','klarna.com','checkout.com','worldpay.com','braintreepayments.com','amazonpay.com','pay.google.com','pay.apple.com']]); $proxyBypass = sx_json_config('proxy_bypass', ['domains'=>['localhost','127.0.0.1']]); $mail = sx_json_config('mail', bg_config_catalog()['mail']['default']); $mailProfile = $mail['profiles'][0] ?? bg_config_catalog()['mail']['default']['profiles'][0]; $alertMail = bg_alert_mail_config(); $clamdb = bg_clamdb_versions(); $yaraRules = sx_list_yara_rules(); $blacklists = sx_list_blacklists(); include 'includes/header.php'; include 'includes/sidebar.php'; ?>

:

clamd.conf:

$enabled): ?>
>
Anti-Ransomware

>
>

No YARA rules found.

>
Anti-Phishing

>
>
FileLines

No phishing blacklist found.

>

CEF/PAC/browser proxy bootstrap is desktop-only and disabled in the WebUI.

$svc): if(empty($svc['user'])) continue; $st=bg_service_status($svc['services'],true); $proxyLocked=$desktopGuiActive && bg_proxy_sensitive_unit($st['name'] ?: ($svc['services'][0] ?? '')); ?>
EnabledPID

$svc): if(!empty($svc['user'])) continue; $st=bg_service_status($svc['services'],false); ?>
EnabledPID
sx('Enable email protection','Abilita protezione email'),'scan_outgoing'=>sx('Scan outgoing email','Scansiona email in uscita'),'inject_signature'=>sx('Inject automatic signature','Inserisci firma automatica'),'advertise_starttls'=>'STARTTLS','enable_implicit_tls_listener'=>sx('Implicit TLS listener','Listener TLS implicito')] as $k=>$label): ?>
>

Logo: /usr/share/BastionGuard/data/logo.png

>
>

>
>
>
ClamAV DB

Default path: /var/lib/clamav

FileVersion

No database found.



$widgetLabel): ?>
>

: · · HTTP / HTTPS