X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/blobdiff_plain/11c301be78d4126799ddafb8f85af298693216e8..ea90b321a4b3768028d841b307c362af97a5e6e1:/connection.php diff --git a/connection.php b/connection.php index ba17c90..114088f 100644 --- a/connection.php +++ b/connection.php @@ -3,29 +3,44 @@ if (!defined('UPATH')) die("Access denied"); -if (!defined('UNREALIRCD_RPC_USER') || - !defined('UNREALIRCD_RPC_PASSWORD') || - !defined('UNREALIRCD_HOST') || - !defined('UNREALIRCD_PORT') -) die("Unable to find RPC credentials in your config.php"); - -$tls_verify = (defined('UNREALIRCD_SSL_VERIFY')) ? UNREALIRCD_SSL_VERIFY : true; -$api_login = UNREALIRCD_RPC_USER.":".UNREALIRCD_RPC_PASSWORD; - -/* Connect now */ -try { - $rpc = new UnrealIRCd\Connection - ( - "wss://".UNREALIRCD_HOST.":".UNREALIRCD_PORT, - $api_login, - Array("tls_verify"=>$tls_verify) - ); -} -catch (Exception $e) +function connect_to_ircd() { - echo "Unable to connect to UnrealIRCd: ".$e->getMessage() . "

"; - echo "Verify your connection details in config.php (rpc user, rpc password, host) and ". - "verify your UnrealIRCd configuration (listen block with listen::options::rpc and ". - "an rpc-user block with the correct IP allowed and the correct username and password)."; - throw $e; + GLOBAL $rpc; + + $host = get_config("unrealircd::host"); + $port = get_config("unrealircd::port"); + $rpc_user = get_config("unrealircd::rpc_user"); + $rpc_password = get_config("unrealircd::rpc_password"); + + if (!$host || !$port || !$rpc_user || !$rpc_password) + die("Unable to find RPC credentials in your config.php"); + + $tls_verify = get_config("unrealircd::tls_verify_cert"); + + /* Connect now */ + try { + $rpc = new UnrealIRCd\Connection + ( + "wss://$host:$port", + "$rpc_user:$rpc_password", + ["tls_verify" => $tls_verify] + ); + } + catch (Exception $e) + { + echo "Unable to connect to UnrealIRCd: ".$e->getMessage() . "

"; + echo "Verify your connection details in config.php (rpc user, rpc password, host) and ". + "verify your UnrealIRCd configuration (listen block with listen::options::rpc and ". + "an rpc-user block with the correct IP allowed and the correct username and password)."; + throw $e; + } + + $user = unreal_get_current_user(); + if ($user) + { + /* Set issuer for all the RPC commands */ + $rpc->rpc()->set_issuer($user->username); + } } + +connect_to_ircd();