]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | if (!defined('UPATH')) | |
4 | die("Access denied"); | |
5 | ||
6 | function connect_to_ircd() | |
7 | { | |
8 | GLOBAL $rpc; | |
9 | ||
10 | $host = get_config("unrealircd::host"); | |
11 | $port = get_config("unrealircd::port"); | |
12 | $rpc_user = get_config("unrealircd::rpc_user"); | |
13 | $rpc_password = get_config("unrealircd::rpc_password"); | |
14 | if (str_starts_with($rpc_password, "secret:")) | |
15 | $rpc_password = secret_decrypt($rpc_password); | |
16 | ||
17 | if (!$host || !$port || !$rpc_user) | |
18 | die("Unable to find RPC credentials in your config.php"); | |
19 | if ($rpc_password === null) | |
20 | die("Your RPC password in the DB was encrypted with a different key than config/config.php contains.<br>\n". | |
21 | "Either restore your previous config/config.php or start with a fresh database.<br>\n"); | |
22 | ||
23 | $tls_verify = get_config("unrealircd::tls_verify_cert"); | |
24 | ||
25 | /* Connect now */ | |
26 | try { | |
27 | $rpc = new UnrealIRCd\Connection | |
28 | ( | |
29 | "wss://$host:$port", | |
30 | "$rpc_user:$rpc_password", | |
31 | ["tls_verify" => $tls_verify] | |
32 | ); | |
33 | } | |
34 | catch (Exception $e) | |
35 | { | |
36 | echo "Unable to connect to UnrealIRCd: ".$e->getMessage() . "<br><br>"; | |
37 | echo "Verify your connection details in config.php (rpc user, rpc password, host) and ". | |
38 | "verify your UnrealIRCd configuration (listen block with listen::options::rpc and ". | |
39 | "an rpc-user block with the correct IP allowed and the correct username and password)."; | |
40 | throw $e; | |
41 | } | |
42 | ||
43 | $user = unreal_get_current_user(); | |
44 | if ($user) | |
45 | { | |
46 | /* Set issuer for all the RPC commands */ | |
47 | $rpc->rpc()->set_issuer($user->username); | |
48 | } | |
49 | } | |
50 | ||
51 | connect_to_ircd(); |