$expire)) { session_destroy(); header("Location: login.php"); exit; } $_SESSION['login_time'] = time(); $userName = htmlspecialchars($_SESSION['username']); // 读取配置库 $dbHost = "10.150.117.190"; $dbUser = "root"; $dbPwd = "hp93000"; $dbName = "alert_mail_stat"; $conn = mysqli_connect($dbHost, $dbUser, $dbPwd, $dbName); mysqli_set_charset($conn, "utf8mb4"); $currentLang = mysqli_fetch_assoc(mysqli_query($conn, "SELECT v FROM sys_config WHERE k='lang'"))['v'] ?? "zh"; // 多语言(统一侧边栏中英对照) $langMap = [ 'zh' => [ 'page_subtitle' => '爱德万测试 · 系统通知配置', 'menu_monitor' => '监控面板', 'menu_workorder' => '工单系统', 'menu_system' => '系统管理', 'menu_admin' => '后台配置', 'menu_smtp' => '邮箱SMTP配置', 'menu_notify' => '工单通知告警配置', 'smtp_config' => '邮箱SMTP配置', 'smtp_host' => 'SMTP服务器', 'smtp_port' => '端口', 'smtp_ssl' => '启用SSL/TLS', 'smtp_account' => '发件账号', 'smtp_pwd' => '授权密码', 'smtp_from' => '发件人邮箱', 'save_smtp' => '保存邮箱配置', 'save_success' => '保存成功', 'notify_title' => '工单告警通知配置', 'dingtalk_webhook' => '钉钉Webhook地址', 'dingtalk_secret' => '钉钉加签密钥(可选)', 'wecom_webhook' => '企业微信Webhook地址', 'wecom_mention' => '企业微信@人员(多个用逗号分隔)', 'notify_switch' => '开启工单自动推送告警', 'save_notify' => '保存通知配置', 'placeholder_webhook' => '请输入Webhook完整地址', 'placeholder_secret' => '不使用加签留空', 'placeholder_mention' => 'all代表所有人,或填写手机号' ], 'en' => [ 'page_subtitle' => 'Advantest · System Notify Config', 'menu_monitor' => 'Monitor Panel', 'menu_workorder' => 'Work Order System', 'menu_system' => 'System Manage', 'menu_admin' => 'System Config', 'menu_smtp' => 'SMTP Mail Config', 'menu_notify' => 'Work Order Alert Notify', 'smtp_config' => 'SMTP Mail Config', 'smtp_host' => 'SMTP Host', 'smtp_port' => 'Port', 'smtp_ssl' => 'Enable SSL/TLS', 'smtp_account' => 'SMTP Account', 'smtp_pwd' => 'Auth Password', 'smtp_from' => 'Sender Email', 'save_smtp' => 'Save Mail Config', 'save_success' => 'Saved successfully', 'notify_title' => 'Work Order Alert Notification', 'dingtalk_webhook' => 'DingTalk Webhook', 'dingtalk_secret' => 'DingTalk Secret (Optional)', 'wecom_webhook' => 'WeCom Webhook', 'wecom_mention' => 'WeCom Mention User (split by comma)', 'notify_switch' => 'Auto push work order alert', 'save_notify' => 'Save Notify Config', 'placeholder_webhook' => 'Input full webhook url', 'placeholder_secret' => 'Leave empty if no secret', 'placeholder_mention' => 'all for everyone, or mobile number' ] ]; $t = $langMap[$currentLang]; // 保存提交处理 if ($_POST['act'] === "save_smtp") { $host = trim($_POST['smtp_host'] ?? ''); $port = intval($_POST['smtp_port'] ?? 25); $ssl = intval($_POST['smtp_ssl'] ?? 0); $user = trim($_POST['smtp_user'] ?? ''); $pwd = trim($_POST['smtp_pass'] ?? ''); $from = trim($_POST['smtp_from'] ?? ''); mysqli_query($conn, "UPDATE sys_smtp_config SET smtp_host='$host',smtp_port=$port,smtp_ssl=$ssl,smtp_user='$user',smtp_pass='$pwd',send_from='$from' WHERE id=1"); echo ""; exit; } if ($_POST['act'] === "save_notify") { $ding_webhook = trim($_POST['dingtalk_webhook'] ?? ''); $ding_secret = trim($_POST['dingtalk_secret'] ?? ''); $wecom_webhook = trim($_POST['wecom_webhook'] ?? ''); $wecom_mention = trim($_POST['wecom_mention'] ?? ''); $notify_open = intval($_POST['notify_open'] ?? 0); // 通知配置表,不存在先建表(首次访问自动创建) mysqli_query($conn, "CREATE TABLE IF NOT EXISTS sys_workorder_notify ( id INT PRIMARY KEY AUTO_INCREMENT, dingtalk_webhook VARCHAR(500) NOT NULL DEFAULT '', dingtalk_secret VARCHAR(200) NOT NULL DEFAULT '', wecom_webhook VARCHAR(500) NOT NULL DEFAULT '', wecom_mention VARCHAR(300) NOT NULL DEFAULT '', notify_open TINYINT NOT NULL DEFAULT 0, update_time DATETIME NOT NULL DEFAULT NOW() ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;"); $exist = mysqli_fetch_assoc(mysqli_query($conn, "SELECT id FROM sys_workorder_notify LIMIT 1")); if ($exist) { mysqli_query($conn, "UPDATE sys_workorder_notify SET dingtalk_webhook='$ding_webhook', dingtalk_secret='$ding_secret', wecom_webhook='$wecom_webhook', wecom_mention='$wecom_mention', notify_open=$notify_open, update_time=NOW() WHERE id = {$exist['id']}"); } else { mysqli_query($conn, "INSERT INTO sys_workorder_notify (dingtalk_webhook,dingtalk_secret,wecom_webhook,wecom_mention,notify_open) VALUES ('$ding_webhook','$ding_secret','$wecom_webhook','$wecom_mention',$notify_open)"); } echo ""; exit; } // 读取SMTP配置 $smtpRow = []; $sql = "SELECT * FROM sys_smtp_config WHERE id = 1"; $res = mysqli_query($conn, $sql); if ($res instanceof mysqli_result) { $smtpRow = mysqli_fetch_assoc($res) ?: []; } $smtpConfig = $smtpRow; // 读取工单通知配置 $notifyConfig = []; $notifyRes = mysqli_query($conn, "SELECT * FROM sys_workorder_notify LIMIT 1"); if ($notifyRes instanceof mysqli_result) { $notifyConfig = mysqli_fetch_assoc($notifyRes) ?: []; } ?>