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