'', 'invite_commission' => 'integer|nullable', 'invite_gen_limit' => 'integer|nullable', 'invite_never_expire' => '', 'commission_first_time_enable' => '', 'commission_auto_check_enable' => '', 'commission_withdraw_limit' => 'nullable|numeric', 'commission_withdraw_method' => 'nullable|array', 'withdraw_close_enable' => '', 'commission_distribution_enable' => '', 'commission_distribution_l1' => 'nullable|numeric', 'commission_distribution_l2' => 'nullable|numeric', 'commission_distribution_l3' => 'nullable|numeric', // site 'logo' => 'nullable|url', 'force_https' => '', 'stop_register' => '', 'app_name' => '', 'app_description' => '', 'app_url' => 'nullable|url', 'subscribe_url' => 'nullable', 'try_out_enable' => '', 'try_out_plan_id' => 'integer', 'try_out_hour' => 'numeric', 'tos_url' => 'nullable|url', 'currency' => '', 'currency_symbol' => '', 'ticket_must_wait_reply' => '', // subscribe 'plan_change_enable' => '', 'reset_traffic_method' => 'in:0,1,2,3,4', 'surplus_enable' => '', 'new_order_event_id' => '', 'renew_order_event_id' => '', 'change_order_event_id' => '', 'show_info_to_server_enable' => '', 'show_protocol_to_server_enable' => '', 'subscribe_path' => '', // server 'server_token' => 'nullable|min:16', 'server_pull_interval' => 'integer', 'server_push_interval' => 'integer', 'device_limit_mode' => 'integer', 'server_ws_enable' => 'boolean', 'server_ws_url' => 'nullable|url', // frontend 'frontend_theme' => '', 'frontend_theme_sidebar' => 'nullable|in:dark,light', 'frontend_theme_header' => 'nullable|in:dark,light', 'frontend_theme_color' => 'nullable|in:default,darkblue,black,green', 'frontend_background_url' => 'nullable|url', // email 'email_host' => '', 'email_port' => '', 'email_username' => '', 'email_password' => '', 'email_encryption' => '', 'email_from_address' => '', 'remind_mail_enable' => '', 'automatic_mail_level' => 'sometimes|integer|in:1,2,3', 'mail_flow' => 'sometimes|array:enabled,resend_enabled,resend_key,resend_from,resend_webhook_secret,reply_to,daily_limit,monthly_limit,inbound_enabled,imap_host,imap_port,imap_username,imap_password,imap_folder,auto_reply_enabled,auto_reply_subject,auto_reply_text,report_enabled,master_url,master_bot_code,master_chat_code', 'mail_flow.enabled' => 'sometimes|boolean', 'mail_flow.resend_enabled' => 'sometimes|boolean', 'mail_flow.resend_key' => 'nullable|string|max:256', 'mail_flow.resend_from' => 'nullable|email|max:254', 'mail_flow.resend_webhook_secret' => 'nullable|string|max:256', 'mail_flow.reply_to' => 'nullable|email|max:254', 'mail_flow.daily_limit' => 'sometimes|integer|min:1|max:100', 'mail_flow.monthly_limit' => 'sometimes|integer|min:1|max:3000', 'mail_flow.inbound_enabled' => 'sometimes|boolean', 'mail_flow.imap_host' => 'nullable|string|regex:/^[a-zA-Z0-9.-]+$/|max:253', 'mail_flow.imap_port' => 'sometimes|integer|min:1|max:65535', 'mail_flow.imap_username' => 'nullable|string|max:254', 'mail_flow.imap_password' => 'nullable|string|max:1024', 'mail_flow.imap_folder' => 'sometimes|string|regex:/^[a-zA-Z0-9_ .\\/-]+$/|max:100', 'mail_flow.auto_reply_enabled' => 'sometimes|boolean', 'mail_flow.auto_reply_subject' => 'sometimes|string|max:200', 'mail_flow.auto_reply_text' => 'sometimes|string|max:5000', 'mail_flow.report_enabled' => 'sometimes|boolean', 'mail_flow.master_url' => 'nullable|url:https|max:500', 'mail_flow.master_bot_code' => 'nullable|string|max:100', 'mail_flow.master_chat_code' => 'nullable|string|max:100', // telegram 'telegram_bot_enable' => '', 'telegram_bot_token' => '', 'telegram_webhook_url' => 'nullable|url', 'telegram_discuss_id' => '', 'telegram_channel_id' => '', 'telegram_discuss_link' => 'nullable|url', // app 'windows_version' => '', 'windows_download_url' => '', 'macos_version' => '', 'macos_download_url' => '', 'android_version' => '', 'android_download_url' => '', // safe 'email_whitelist_enable' => 'boolean', 'email_whitelist_suffix' => 'nullable|array', 'email_gmail_limit_enable' => 'boolean', 'captcha_enable' => 'boolean', 'captcha_type' => 'in:recaptcha,turnstile,recaptcha-v3', 'recaptcha_enable' => 'boolean', 'recaptcha_key' => '', 'recaptcha_site_key' => '', 'recaptcha_v3_secret_key' => '', 'recaptcha_v3_site_key' => '', 'recaptcha_v3_score_threshold' => 'numeric|min:0|max:1', 'turnstile_secret_key' => '', 'turnstile_site_key' => '', 'email_verify' => 'bool', 'safe_mode_enable' => 'boolean', 'register_limit_by_ip_enable' => 'boolean', 'register_limit_count' => 'integer', 'register_limit_expire' => 'integer', 'secure_path' => 'min:8|regex:/^[\w-]*$/', 'password_limit_enable' => 'boolean', 'password_limit_count' => 'integer', 'password_limit_expire' => 'integer', 'default_remind_expire' => 'boolean', 'default_remind_traffic' => 'boolean', 'subscribe_template_singbox' => 'nullable', 'subscribe_template_clash' => 'nullable', 'subscribe_template_clashmeta' => 'nullable', 'subscribe_template_stash' => 'nullable', 'subscribe_template_surge' => 'nullable', 'subscribe_template_surfboard' => 'nullable' ]; /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return self::RULES; } public function after(): array { return [function ($validator) { if ((int) $this->input('automatic_mail_level') === 2 && !\Illuminate\Support\Facades\Schema::hasTable('v2_mail_messages')) { $validator->errors()->add('automatic_mail_level', '二档到期通知需要先执行邮件记录数据库迁移。'); } if (!$this->has('mail_flow')) { return; } $settings = array_replace(\App\Services\MailFlow\Settings::all(), (array) $this->input('mail_flow')); foreach (['resend_key', 'resend_webhook_secret', 'imap_password'] as $key) { if (empty($settings[$key])) { $settings[$key] = \App\Services\MailFlow\Settings::get($key); } } if (empty($settings['enabled'])) { return; } foreach (['v2_mail_messages', 'v2_mail_quota_buckets', 'v2_mail_daily_reports'] as $table) { if (!\Illuminate\Support\Facades\Schema::hasTable($table)) { $validator->errors()->add('mail_flow.enabled', '请先执行邮件功能数据库迁移。'); break; } } $required = []; if (!empty($settings['resend_enabled'])) { $required = array_merge($required, ['resend_key', 'resend_from']); } if (!empty($settings['inbound_enabled'])) { $required = array_merge($required, ['imap_host', 'imap_username', 'imap_password']); if (!function_exists('imap_open')) { $validator->errors()->add('mail_flow.inbound_enabled', '请先安装 PHP IMAP 扩展。'); } } if (!empty($settings['auto_reply_enabled'])) { $required[] = 'reply_to'; if (empty($settings['inbound_enabled'])) { $validator->errors()->add('mail_flow.auto_reply_enabled', '请先启用常规邮箱收件。'); } } if (!empty($settings['report_enabled'])) { $required = array_merge($required, ['master_url', 'master_bot_code', 'master_chat_code']); } foreach (array_unique($required) as $key) { if (empty($settings[$key])) { $validator->errors()->add('mail_flow.' . $key, '请补齐此项配置。'); } } }]; } public function messages() { // illiteracy prompt return [ 'app_url.url' => '站点URL格式不正确,必须携带http(s)://', 'subscribe_url.url' => '订阅URL格式不正确,必须携带http(s)://', 'server_token.min' => '通讯密钥长度必须大于16位', 'tos_url.url' => '服务条款URL格式不正确,必须携带http(s)://', 'telegram_webhook_url.url' => 'Telegram Webhook地址格式不正确,必须携带http(s)://', 'telegram_discuss_link.url' => 'Telegram群组地址必须为URL格式,必须携带http(s)://', 'logo.url' => 'LOGO URL格式不正确,必须携带https(s)://', 'secure_path.min' => '后台路径长度最小为8位', 'secure_path.regex' => '后台路径只能为字母或数字', 'captcha_type.in' => '人机验证类型只能选择 recaptcha、turnstile 或 recaptcha-v3', 'recaptcha_v3_score_threshold.numeric' => 'reCAPTCHA v3 分数阈值必须为数字', 'recaptcha_v3_score_threshold.min' => 'reCAPTCHA v3 分数阈值不能小于0', 'recaptcha_v3_score_threshold.max' => 'reCAPTCHA v3 分数阈值不能大于1' ]; } }