]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - connection.php
unrealircd::rpc_password is now encrypted with secret::key (XChaCha20-Poly1305-IETF)
[irc/unrealircd/unrealircd-webpanel.git] / connection.php
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 || !$rpc_password)
18 die("Unable to find RPC credentials in your config.php");
19
20 $tls_verify = get_config("unrealircd::tls_verify_cert");
21
22 /* Connect now */
23 try {
24 $rpc = new UnrealIRCd\Connection
25 (
26 "wss://$host:$port",
27 "$rpc_user:$rpc_password",
28 ["tls_verify" => $tls_verify]
29 );
30 }
31 catch (Exception $e)
32 {
33 echo "Unable to connect to UnrealIRCd: ".$e->getMessage() . "<br><br>";
34 echo "Verify your connection details in config.php (rpc user, rpc password, host) and ".
35 "verify your UnrealIRCd configuration (listen block with listen::options::rpc and ".
36 "an rpc-user block with the correct IP allowed and the correct username and password).";
37 throw $e;
38 }
39
40 $user = unreal_get_current_user();
41 if ($user)
42 {
43 /* Set issuer for all the RPC commands */
44 $rpc->rpc()->set_issuer($user->username);
45 }
46 }
47
48 connect_to_ircd();