v2board/app/Http/Controllers/Admin/ConfigController.php

192 lines
9.8 KiB
PHP
Raw Normal View History

2019-10-29 15:33:36 +08:00
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\Admin\ConfigSave;
2020-05-17 15:23:39 +08:00
use App\Services\TelegramService;
2019-10-29 15:33:36 +08:00
use Illuminate\Http\Request;
2020-02-09 18:01:06 +08:00
use App\Utils\Dict;
2019-10-29 15:33:36 +08:00
use App\Http\Controllers\Controller;
class ConfigController extends Controller
{
2020-03-18 17:33:58 +08:00
public function getEmailTemplate()
{
2020-03-18 18:12:19 +08:00
$path = resource_path('views/mail/');
$files = array_map(function ($item) use ($path) {
return str_replace($path, '', $item);
}, glob($path . '*'));
2020-03-18 17:33:58 +08:00
return response([
2020-03-18 18:12:19 +08:00
'data' => $files
2020-03-18 17:33:58 +08:00
]);
}
2021-07-29 01:41:31 +08:00
public function getThemeTemplate()
{
$path = public_path('theme/');
$files = array_map(function ($item) use ($path) {
return str_replace($path, '', $item);
}, glob($path . '*'));
return response([
'data' => $files
]);
}
2020-05-17 16:00:28 +08:00
public function setTelegramWebhook(Request $request)
2020-05-17 15:23:39 +08:00
{
2020-05-17 16:00:28 +08:00
$telegramService = new TelegramService($request->input('telegram_bot_token'));
2020-05-19 16:32:35 +08:00
$telegramService->getMe();
$telegramService->setWebhook(
2020-05-31 15:15:20 +08:00
url(
'/api/v1/guest/telegram/webhook?access_token=' . md5(config('v2board.telegram_bot_token', $request->input('telegram_bot_token')))
)
2020-05-19 16:32:35 +08:00
);
2020-05-17 15:23:39 +08:00
return response([
'data' => true
]);
}
2020-01-11 13:36:52 +08:00
public function fetch()
{
2020-02-09 18:53:45 +08:00
// TODO: default should be in Dict
2019-10-29 15:33:36 +08:00
return response([
2020-01-31 17:18:00 +08:00
'data' => [
'invite' => [
'invite_force' => (int)config('v2board.invite_force', 0),
'invite_commission' => config('v2board.invite_commission', 10),
'invite_gen_limit' => config('v2board.invite_gen_limit', 5),
'invite_never_expire' => config('v2board.invite_never_expire', 0),
2020-05-03 23:17:55 +08:00
'commission_first_time_enable' => config('v2board.commission_first_time_enable', 1),
2020-10-29 00:37:37 +08:00
'commission_auto_check_enable' => config('v2board.commission_auto_check_enable', 1),
2021-01-08 00:33:11 +08:00
'commission_withdraw_limit' => config('v2board.commission_withdraw_limit', 100),
2021-02-03 18:17:32 +08:00
'commission_withdraw_method' => config('v2board.commission_withdraw_method', Dict::WITHDRAW_METHOD_WHITELIST_DEFAULT),
'withdraw_close_enable' => config('v2board.withdraw_close_enable', 0)
2020-01-31 17:18:00 +08:00
],
'site' => [
2020-02-08 16:38:03 +08:00
'safe_mode_enable' => (int)config('v2board.safe_mode_enable', 0),
2020-01-31 17:18:00 +08:00
'stop_register' => (int)config('v2board.stop_register', 0),
'email_verify' => (int)config('v2board.email_verify', 0),
'app_name' => config('v2board.app_name', 'V2Board'),
2020-02-09 18:53:45 +08:00
'app_description' => config('v2board.app_description', 'V2Board is best!'),
2020-01-31 17:18:00 +08:00
'app_url' => config('v2board.app_url'),
'subscribe_url' => config('v2board.subscribe_url'),
2020-02-08 23:03:48 +08:00
'try_out_plan_id' => (int)config('v2board.try_out_plan_id', 0),
2020-02-09 01:29:26 +08:00
'try_out_hour' => (int)config('v2board.try_out_hour', 1),
2020-02-09 17:17:21 +08:00
'email_whitelist_enable' => (int)config('v2board.email_whitelist_enable', 0),
2020-05-25 18:02:13 +08:00
'email_whitelist_suffix' => config('v2board.email_whitelist_suffix', Dict::EMAIL_WHITELIST_SUFFIX_DEFAULT),
2020-10-09 23:27:36 +08:00
'email_gmail_limit_enable' => config('v2board.email_gmail_limit_enable', 0),
'recaptcha_enable' => (int)config('v2board.recaptcha_enable', 0),
'recaptcha_key' => config('v2board.recaptcha_key'),
2021-05-06 23:12:58 +08:00
'recaptcha_site_key' => config('v2board.recaptcha_site_key'),
'tos_url' => config('v2board.tos_url')
2020-01-31 17:18:00 +08:00
],
2020-02-18 02:33:57 +08:00
'subscribe' => [
2020-03-02 00:04:07 +08:00
'plan_change_enable' => (int)config('v2board.plan_change_enable', 1),
2020-03-02 00:14:58 +08:00
'reset_traffic_method' => (int)config('v2board.reset_traffic_method', 0),
2021-07-01 21:04:22 +08:00
'surplus_enable' => (int)config('v2board.surplus_enable', 1),
'new_order_event_id' => (int)config('v2board.new_order_event_id', 0),
'renew_order_event_id' => (int)config('v2board.renew_order_event_id', 0),
'change_order_event_id' => (int)config('v2board.change_order_event_id', 0),
2020-02-18 02:33:57 +08:00
],
2020-01-31 17:18:00 +08:00
'pay' => [
// alipay
'alipay_enable' => (int)config('v2board.alipay_enable'),
'alipay_appid' => config('v2board.alipay_appid'),
'alipay_pubkey' => config('v2board.alipay_pubkey'),
'alipay_privkey' => config('v2board.alipay_privkey'),
// stripe
2020-03-05 23:05:36 +08:00
'stripe_alipay_enable' => (int)config('v2board.stripe_alipay_enable', 0),
'stripe_wepay_enable' => (int)config('v2board.stripe_wepay_enable', 0),
2020-06-04 18:00:33 +08:00
'stripe_card_enable' => (int)config('v2board.stripe_card_enable', 0),
2020-03-06 01:06:04 +08:00
'stripe_sk_live' => config('v2board.stripe_sk_live'),
'stripe_pk_live' => config('v2board.stripe_pk_live'),
2020-01-31 17:18:00 +08:00
'stripe_webhook_key' => config('v2board.stripe_webhook_key'),
2020-03-05 00:06:40 +08:00
'stripe_currency' => config('v2board.stripe_currency', 'hkd'),
2020-01-31 17:18:00 +08:00
// bitpayx
2020-07-17 21:20:43 +08:00
'bitpayx_name' => config('v2board.bitpayx_name', '在线支付'),
2020-03-05 23:05:36 +08:00
'bitpayx_enable' => (int)config('v2board.bitpayx_enable', 0),
2020-01-31 17:18:00 +08:00
'bitpayx_appsecret' => config('v2board.bitpayx_appsecret'),
2020-07-20 19:56:39 +08:00
// mGate
'mgate_name' => config('v2board.mgate_name', '在线支付'),
'mgate_enable' => (int)config('v2board.mgate_enable', 0),
'mgate_url' => config('v2board.mgate_url'),
'mgate_app_id' => config('v2board.mgate_app_id'),
'mgate_app_secret' => config('v2board.mgate_app_secret'),
2020-07-17 21:20:43 +08:00
// Epay
'epay_name' => config('v2board.epay_name', '在线支付'),
'epay_enable' => (int)config('v2board.epay_enable', 0),
'epay_url' => config('v2board.epay_url'),
'epay_pid' => config('v2board.epay_pid'),
'epay_key' => config('v2board.epay_key'),
2020-01-31 17:18:00 +08:00
],
'frontend' => [
2021-07-29 01:41:31 +08:00
'frontend_theme' => config('v2board.frontend_theme', 'v2board'),
2020-02-17 03:35:03 +08:00
'frontend_theme_sidebar' => config('v2board.frontend_theme_sidebar', 'light'),
'frontend_theme_header' => config('v2board.frontend_theme_header', 'dark'),
'frontend_theme_color' => config('v2board.frontend_theme_color', 'default'),
2020-07-17 20:01:28 +08:00
'frontend_background_url' => config('v2board.frontend_background_url'),
2021-03-25 17:26:22 +08:00
'frontend_admin_path' => config('v2board.frontend_admin_path', 'admin'),
'frontend_customer_service_method' => config('v2board.frontend_customer_service_method', 0),
'frontend_customer_service_id' => config('v2board.frontend_customer_service_id'),
2020-01-31 17:18:00 +08:00
],
'server' => [
'server_token' => config('v2board.server_token'),
2020-05-30 14:43:18 +08:00
'server_license' => config('v2board.server_license'),
2020-07-26 17:17:35 +08:00
'server_log_enable' => config('v2board.server_log_enable', 0),
'server_v2ray_domain' => config('v2board.server_v2ray_domain'),
'server_v2ray_protocol' => config('v2board.server_v2ray_protocol'),
2020-01-31 17:18:00 +08:00
],
'tutorial' => [
'apple_id' => config('v2board.apple_id')
2020-03-18 18:12:19 +08:00
],
'email' => [
2020-08-19 15:41:31 +08:00
'email_template' => config('v2board.email_template', 'default'),
'email_host' => config('v2board.email_host'),
'email_port' => config('v2board.email_port'),
'email_username' => config('v2board.email_username'),
'email_password' => config('v2board.email_password'),
'email_encryption' => config('v2board.email_encryption'),
'email_from_address' => config('v2board.email_from_address')
2020-04-30 16:08:26 +08:00
],
'telegram' => [
'telegram_bot_enable' => config('v2board.telegram_bot_enable', 0),
'telegram_bot_token' => config('v2board.telegram_bot_token')
2020-11-19 21:21:21 +08:00
],
'app' => [
2020-11-19 21:27:53 +08:00
'windows_version' => config('v2board.windows_version'),
2020-11-19 21:21:21 +08:00
'windows_download_url' => config('v2board.windows_download_url'),
'macos_version' => config('v2board.macos_version'),
'macos_download_url' => config('v2board.macos_download_url'),
'android_version' => config('v2board.android_version'),
'android_download_url' => config('v2board.android_download_url')
2020-01-31 17:18:00 +08:00
]
]
2019-10-29 15:33:36 +08:00
]);
}
2020-01-11 13:36:52 +08:00
public function save(ConfigSave $request)
{
2019-10-29 15:33:36 +08:00
$data = $request->input();
2020-01-31 17:18:00 +08:00
$array = \Config::get('v2board');
2019-10-29 15:33:36 +08:00
foreach ($data as $k => $v) {
2020-07-15 15:57:12 +08:00
if (!in_array($k, array_keys($request->validated()))) {
2020-01-04 18:11:13 +08:00
abort(500, '参数' . $k . '不在规则内,禁止修改');
2019-10-29 15:33:36 +08:00
}
2020-01-31 17:18:00 +08:00
$array[$k] = $v;
}
$data = var_export($array, 1);
if (!\File::put(base_path() . '/config/v2board.php', "<?php\n return $data ;")) {
abort(500, '修改失败');
2019-10-29 15:33:36 +08:00
}
2020-07-25 00:28:04 +08:00
if (function_exists('opcache_reset')) {
2020-11-18 11:12:38 +08:00
if (opcache_reset() === false) {
2020-09-23 22:40:20 +08:00
abort(500, '缓存清除失败请卸载或检查opcache配置状态');
2020-09-23 14:37:24 +08:00
}
2020-03-30 16:11:08 +08:00
}
2020-07-25 00:19:13 +08:00
\Artisan::call('config:cache');
2019-10-29 15:33:36 +08:00
return response([
'data' => true
]);
}
}