]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - inc/connection.php
Nicer error dialog in connect_to_ircd()
[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)
82343073
BM
13 {
14 Message::Fail("No RPC server configured. Go to Settings - RPC Servers.");
15 die;
16 }
41aad10c
BM
17 $host = $config["unrealircd"][$server]["host"];
18 $port = $config["unrealircd"][$server]["port"];
19 $rpc_user = $config["unrealircd"][$server]["rpc_user"];
20 $rpc_password = $config["unrealircd"][$server]["rpc_password"];
a4850187
BM
21 if (str_starts_with($rpc_password, "secret:"))
22 $rpc_password = secret_decrypt($rpc_password);
41aad10c 23 $tls_verify = $config["unrealircd"][$server]["tls_verify_cert"];
ea90b321 24
50f6d124 25 if (!$host || !$port || !$rpc_user)
41aad10c
BM
26 die("RPC Server is missing credentials");
27
50f6d124 28 if ($rpc_password === null)
41aad10c 29 {
82343073
BM
30 Message::Fail("Your RPC password in the DB was encrypted with a different key than config/config.php contains.<br>\n".
31 "Either restore your previous config/config.php or start with a fresh database.<br>\n");
32 die;
41aad10c 33 }
ea90b321
BM
34
35 /* Connect now */
36 try {
37 $rpc = new UnrealIRCd\Connection
38 (
39 "wss://$host:$port",
40 "$rpc_user:$rpc_password",
41 ["tls_verify" => $tls_verify]
42 );
43 }
44 catch (Exception $e)
45 {
82343073
BM
46 Message::Fail("Unable to connect to UnrealIRCd: ".$e->getMessage() . "<br>".
47 "Verify your connection details in config.php (rpc user, rpc password, host) and ".
48 "verify your UnrealIRCd configuration (listen block with listen::options::rpc and ".
49 "an rpc-user block with the correct IP allowed and the correct username and password).");
ea90b321
BM
50 throw $e;
51 }
52
53 $user = unreal_get_current_user();
54 if ($user)
55 {
56 /* Set issuer for all the RPC commands */
57 $rpc->rpc()->set_issuer($user->username);
58 }
e77b1514 59}
ea90b321
BM
60
61connect_to_ircd();