30 lines
4.4 KiB
PHP
30 lines
4.4 KiB
PHP
<?php
|
|
declare(strict_types=1);umask(0077);ini_set('display_errors','0');
|
|
$dir='/var/www/wwwroot/fuc-xb-test/private/launch-ready-20261105';$root='/var/www/wwwroot/fuc-xb-test/current';
|
|
if(is_file($dir.'/configured.json'))throw new RuntimeException('Already configured; inspect before repeating');
|
|
$credentials=json_decode(stream_get_contents(STDIN),true,16,JSON_THROW_ON_ERROR);
|
|
if(empty($credentials['merchant_id'])||empty($credentials['api_key']))throw new RuntimeException('Missing registered merchant');
|
|
chdir('/www/wwwroot/fuuuu.cloud');require 'config/.config.php';
|
|
$dsn=!empty($_ENV['db_socket'])?'mysql:unix_socket='.$_ENV['db_socket']:'mysql:host='.$_ENV['db_host'].';port='.$_ENV['db_port'];
|
|
$pdo=new PDO($dsn.';dbname='.$_ENV['db_database'].';charset=utf8mb4',$_ENV['db_username'],$_ENV['db_password'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION,PDO::ATTR_DEFAULT_FETCH_MODE=>PDO::FETCH_ASSOC]);
|
|
$pdo->exec('SET TRANSACTION READ ONLY');$pdo->beginTransaction();
|
|
$smtp=$pdo->query("SELECT item,value FROM config WHERE item IN ('smtp_host','smtp_port','smtp_username','smtp_password','smtp_sender','smtp_ssl')")->fetchAll(PDO::FETCH_KEY_PAIR);
|
|
$resend=$pdo->query("SELECT apikey,auther FROM mail_must WHERE client='resend' AND status=1 LIMIT 1")->fetch();$pdo->rollBack();unset($pdo);
|
|
if(($smtp['smtp_host']??'')!=='mail.privateemail.com'||($smtp['smtp_sender']??'')!=='[email protected]'||(int)$smtp['smtp_port']!==465||empty($smtp['smtp_password'])||empty($resend['apikey']))throw new RuntimeException('Registered source mail settings changed');
|
|
chdir($root);putenv('XB_INSTANCE=fuc-xb-test');$_SERVER['XB_INSTANCE']=$_ENV['XB_INSTANCE']='fuc-xb-test';
|
|
require $root.'/vendor/autoload.php';$app=require $root.'/bootstrap/app.php';$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
|
use Illuminate\Support\Facades\{DB,Cache,Crypt};use App\Models\{Payment,Plugin};
|
|
if(DB::connection()->getDatabaseName()!=='fuc_xb_test')throw new RuntimeException('Wrong database');
|
|
$lock=fopen($dir.'/panel.lock','c');if(!flock($lock,LOCK_EX|LOCK_NB))throw new RuntimeException('Another preparation is running');
|
|
if(Payment::count())throw new RuntimeException('Unexpected existing payment channels');
|
|
$before=DB::table('v2_settings')->orderBy('id')->get()->toJson();file_put_contents($dir.'/settings-before-mail-payment.json',$before);chmod($dir.'/settings-before-mail-payment.json',0600);
|
|
$result=DB::transaction(function()use($dir,$smtp,$resend,$credentials){
|
|
$flow=array_replace((array)admin_setting('mail_flow',[]),['enabled'=>true,'resend_enabled'=>true,'resend_key'=>'encrypted:'.Crypt::encryptString($resend['apikey']),'resend_from'=>$resend['auther'],'reply_to'=>'[email protected]','inbound_enabled'=>false,'auto_reply_enabled'=>false,'report_enabled'=>false,'daily_limit'=>100,'monthly_limit'=>3000]);
|
|
app(App\Support\Setting::class)->save(['mail_flow'=>$flow,'automatic_mail_policy'=>['level'=>3,'since'=>null],'remind_mail_enable'=>0,'email_host'=>$smtp['smtp_host'],'email_port'=>(int)$smtp['smtp_port'],'email_username'=>$smtp['smtp_username'],'email_password'=>$smtp['smtp_password'],'email_encryption'=>'ssl','email_from_address'=>'[email protected]','email_verify'=>1,'stop_register'=>1,'telegram_bot_enable'=>0,'server_ws_enable'=>0]);
|
|
$pm=app(App\Services\Plugin\PluginManager::class);if(!Plugin::where('code','epay')->exists())$pm->install('epay');$pm->enable('epay');
|
|
$channels=[];foreach(['alipay'=>'支付宝','wxpay'=>'微信支付']as$type=>$name){$p=Payment::create(['uuid'=>App\Utils\Helper::randomChar(8),'name'=>'空中支付 · '.$name,'payment'=>'EPay','enable'=>false,'sort'=>count($channels)+1,'handling_fee_fixed'=>0,'handling_fee_percent'=>0,'notify_domain'=>'https://fuc-xb-test.gemcook.net','config'=>['url'=>'https://pay.airspay.top','pid'=>$credentials['merchant_id'],'key'=>$credentials['api_key'],'type'=>$type]]);$channels[$type]=['id'=>$p->id,'uuid'=>$p->uuid];}
|
|
$result=['configured'=>true,'smtp_configured'=>true,'resend_configured'=>true,'real_mail_sent_by_configuration'=>0,'bulk_automatic_mail_disabled'=>true,'inbound_mail_disabled'=>true,'registration_still_disabled'=>true,'payment_channels'=>$channels,'payment_channels_disabled_until_cutover'=>true,'real_money_paid'=>0,'websocket_disabled_polling_native'=>true,'production_site_changed'=>false];
|
|
file_put_contents($dir.'/configured.json',json_encode($result,JSON_PRETTY_PRINT));chmod($dir.'/configured.json',0600);return $result;
|
|
});
|
|
Cache::store('redis')->forget(App\Support\Setting::CACHE_KEY);echo json_encode($result).PHP_EOL;
|