Files
Athena-Deck/integrations/librechat-unraid/media/fix-http-cookies.php
T

8 lines
2.1 KiB
PHP

<?php
function run($a){$p=proc_open($a,[1=>['pipe','w'],2=>['pipe','w']],$ps);$o=stream_get_contents($ps[1]);$e=stream_get_contents($ps[2]);foreach($ps as$s)fclose($s);if(proc_close($p))throw new Exception('Container operation failed; output suppressed');return $o;}
$xp='/boot/config/plugins/dockerMan/templates-user/my-LibreChat.xml';$root='/mnt/nvme-storage/appdata/librechat';$x=simplexml_load_file($xp);$domain=null;foreach($x->Config as$c)if((string)$c['Target']==='DOMAIN_SERVER')$domain=(string)$c;if($domain!=='http://192.168.1.2:3080')throw new Exception('Expected HTTP LAN deployment only');
$back=$root.'/install-backups/http-cookies-'.gmdate('Ymd-His');mkdir($back,0700,true);copy($xp,$back.'/my-LibreChat.xml');chmod($back.'/my-LibreChat.xml',0600);
$found=false;foreach($x->Config as$c)if((string)$c['Target']==='SESSION_COOKIE_SECURE'){$c[0]='false';$found=true;}if(!$found){$c=$x->addChild('Config','false');foreach(['Name'=>'HTTPS-only Session Cookie','Target'=>'SESSION_COOKIE_SECURE','Type'=>'Variable','Mode'=>'','Display'=>'always','Mask'=>'false','Description'=>'false nur für freigegebenen HTTP-LAN-Betrieb; bei HTTPS wieder true setzen.']as$k=>$v)$c->addAttribute($k,$v);}$x->asXML($xp);chmod($xp,0600);
$a=['docker','create','--name','LibreChat','--network','bridge','--restart','unless-stopped','--pids-limit','2048','-l','net.unraid.docker.managed=dockerman'];foreach(['WebUI'=>'net.unraid.docker.webui','Icon'=>'net.unraid.docker.icon']as$k=>$v)if((string)$x->$k!='')array_push($a,'-l',$v.'='.(string)$x->$k);foreach($x->Config as$c){$v=(string)$c;$target=(string)$c['Target'];$type=(string)$c['Type'];if($type==='Variable')array_push($a,'-e',$target.'='.$v);elseif($type==='Port')array_push($a,'-p',$v.':'.$target.'/'.(string)$c['Mode']);elseif($type==='Path')array_push($a,'-v',$v.':'.$target.':'.(string)$c['Mode']);else throw new Exception('Unknown config type');}$a[]=(string)$x->Repository;
run(['docker','stop','--time','30','LibreChat']);run(['docker','rm','LibreChat']);run($a);run(['docker','start','LibreChat']);echo json_encode(['http_cookie_fix_applied'=>true,'image_authorization_preserved'=>true,'backup'=>$back])."\n";