]>
Commit | Line | Data |
---|---|---|
03ddd26b BM |
1 | <?php |
2 | ||
00db45aa | 3 | if (!defined('UPATH')) |
55fd88eb | 4 | die("Access denied"); |
00db45aa | 5 | |
41aad10c BM |
6 | function get_active_rpc_server() |
7 | { | |
8 | // TODO: make user able to override this - either in user or in session | |
9 | ||
10 | foreach (get_config("unrealircd") as $displayname=>$e) | |
11 | { | |
12 | if (isset($e["default"]) && $e["default"]) | |
13 | return $displayname; | |
14 | } | |
15 | return null; | |
16 | } | |
17 | ||
ea90b321 | 18 | function connect_to_ircd() |
11c301be | 19 | { |
ea90b321 | 20 | GLOBAL $rpc; |
41aad10c | 21 | GLOBAL $config; |
e77b1514 | 22 | |
41aad10c BM |
23 | $server = get_active_rpc_server(); |
24 | if (!$server) | |
25 | die("No RPC server configured as primary"); | |
26 | $host = $config["unrealircd"][$server]["host"]; | |
27 | $port = $config["unrealircd"][$server]["port"]; | |
28 | $rpc_user = $config["unrealircd"][$server]["rpc_user"]; | |
29 | $rpc_password = $config["unrealircd"][$server]["rpc_password"]; | |
a4850187 BM |
30 | if (str_starts_with($rpc_password, "secret:")) |
31 | $rpc_password = secret_decrypt($rpc_password); | |
41aad10c | 32 | $tls_verify = $config["unrealircd"][$server]["tls_verify_cert"]; |
ea90b321 | 33 | |
50f6d124 | 34 | if (!$host || !$port || !$rpc_user) |
41aad10c BM |
35 | die("RPC Server is missing credentials"); |
36 | ||
50f6d124 | 37 | if ($rpc_password === null) |
41aad10c | 38 | { |
50f6d124 BM |
39 | die("Your RPC password in the DB was encrypted with a different key than config/config.php contains.<br>\n". |
40 | "Either restore your previous config/config.php or start with a fresh database.<br>\n"); | |
41aad10c | 41 | } |
ea90b321 BM |
42 | |
43 | /* Connect now */ | |
44 | try { | |
45 | $rpc = new UnrealIRCd\Connection | |
46 | ( | |
47 | "wss://$host:$port", | |
48 | "$rpc_user:$rpc_password", | |
49 | ["tls_verify" => $tls_verify] | |
50 | ); | |
51 | } | |
52 | catch (Exception $e) | |
53 | { | |
54 | echo "Unable to connect to UnrealIRCd: ".$e->getMessage() . "<br><br>"; | |
55 | echo "Verify your connection details in config.php (rpc user, rpc password, host) and ". | |
56 | "verify your UnrealIRCd configuration (listen block with listen::options::rpc and ". | |
57 | "an rpc-user block with the correct IP allowed and the correct username and password)."; | |
58 | throw $e; | |
59 | } | |
60 | ||
61 | $user = unreal_get_current_user(); | |
62 | if ($user) | |
63 | { | |
64 | /* Set issuer for all the RPC commands */ | |
65 | $rpc->rpc()->set_issuer($user->username); | |
66 | } | |
e77b1514 | 67 | } |
ea90b321 BM |
68 | |
69 | connect_to_ircd(); |