25 lines
2.7 KiB
PHP
25 lines
2.7 KiB
PHP
<?php
|
|
umask(0077);
|
|
$base='/mnt/user/appdata/lobehub/deployment';
|
|
if(file_exists("$base/.env"))throw new Exception('Refusing to overwrite existing environment');
|
|
$env=file_get_contents("$base/env.upstream.example");
|
|
function setting($key,$value){global $env;$line=$key.'='.$value;if(preg_match('/^'.preg_quote($key,'/').'=/m',$env))$env=preg_replace_callback('/^'.preg_quote($key,'/').'=[^\r\n]*/m',fn()=>$line,$env);else $env.="\n$line\n";}
|
|
foreach(['KEY_VAULTS_SECRET','AUTH_SECRET'] as $k)setting($k,base64_encode(random_bytes(32)));
|
|
foreach(['POSTGRES_PASSWORD','RUSTFS_SECRET_KEY','GATEWAY_SERVICE_TOKEN'] as $k)setting($k,bin2hex(random_bytes(32)));
|
|
function b64url($v){return rtrim(strtr(base64_encode($v),'+/','-_'),'=');}
|
|
$key=openssl_pkey_new(['private_key_bits'=>2048,'private_key_type'=>OPENSSL_KEYTYPE_RSA]);
|
|
if(!$key)throw new Exception('RSA generation failed');
|
|
$rsa=openssl_pkey_get_details($key)['rsa'];$meta=['kty'=>'RSA','alg'=>'RS256','kid'=>bin2hex(random_bytes(8)),'use'=>'sig'];$pub=$meta+['n'=>b64url($rsa['n']),'e'=>b64url($rsa['e'])];$priv=$pub;
|
|
foreach(['d'=>'d','p'=>'p','q'=>'q','dp'=>'dmp1','dq'=>'dmq1','qi'=>'iqmp'] as $j=>$k)$priv[$j]=b64url($rsa[$k]);
|
|
setting('JWKS_KEY',json_encode(['keys'=>[$priv]],JSON_UNESCAPED_SLASHES));setting('JWKS_PUBLIC_KEY',json_encode(['keys'=>[$pub]],JSON_UNESCAPED_SLASHES));
|
|
foreach(['LOBE_PORT'=>'3210','APP_URL'=>'http://192.168.1.2:3210','RUSTFS_PORT'=>'19000','RUSTFS_ADMIN_PORT'=>'19001','S3_ENDPOINT'=>'http://192.168.1.2:19000','AGENT_GATEWAY_PORT'=>'18787','DEVICE_GATEWAY_PORT'=>'18788','AGENT_GATEWAY_URL'=>'http://192.168.1.2:18787','DEVICE_GATEWAY_PUBLIC_URL'=>'http://192.168.1.2:18788','OPENAI_PROXY_URL'=>'http://192.168.1.212:8120/v1','ENABLED_OPENAI'=>'1','SSRF_ALLOW_PRIVATE_IP_ADDRESS'=>'1'] as $k=>$v)setting($k,$v);
|
|
$models='-all,+flash-next-strata-iq3=Athena Strata 256K<262144:reasoning:fc>,+flash-next-strata-iq3-512k=Athena Strata 512K<524288:reasoning:fc>,+flash-next-strata-iq3-dual=Athena Dual Slot 256K<262144:reasoning:fc>,+qwen3-8-27b-medium=Athena Qwen 27B<80000:reasoning:fc>';
|
|
setting('OPENAI_MODEL_LIST',"'$models'");
|
|
setting('DEFAULT_AGENT_CONFIG', "'model=flash-next-strata-iq3;provider=openai;chatConfig.enableAutoCreateTopic=false'");
|
|
setting('SYSTEM_AGENT','default=openai/flash-next-strata-iq3');
|
|
$source=file_get_contents('/mnt/user/appdata/agent-zero/.env');
|
|
if(!preg_match('/^API_KEY_OPENAI\s*=\s*(.*)$/m',$source,$m))throw new Exception('Existing Athena credential unavailable');
|
|
$credential=trim(trim($m[1]),"\"'");if(!$credential)throw new Exception('Empty credential');setting('OPENAI_API_KEY',$credential);
|
|
file_put_contents("$base/.env",$env);chmod("$base/.env",0600);
|
|
echo "LobeHub persistent configuration generated; Athena credential transferred internally.\n";
|