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