]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blobdiff - api/installation2.php
Add Settings - RPC Servers (start of multi-server work).
[irc/unrealircd/unrealircd-webpanel.git] / api / installation2.php
index e9dde108a6090f01c646e80bbb17dfda86a49fc6..288f4bebb0a2a0ab8643b0dfaffbb3d8c252f61c 100644 (file)
@@ -2,36 +2,45 @@
 
 require_once "../inc/common.php";
 
-/* only let this happen  */
-if (isset($config['unrealircd']) && empty($config['unrealircd']['host']))
-               die(json_encode(["error" => "Already configured."]));
-
 if (!isset($_POST) || empty($_POST))
                die(json_encode(["error" => "Incorrect parameters"]));
 
-foreach($_POST as $key => $str)
-               ${$key} = $str;
+foreach(array("tls_verify","host","port","user","password","edit_existing") as $k)
+{
+       if (!isset($_POST[$k]))
+               die("MISSING: $k");
+       ${$k} = $_POST[$k];
+}
 
-if ($method == "rpc")
+if ($tls_verify == "false")
+       $tls_verify = false;
+elseif ($tls_verify == "true")
+       $tls_verify = true;
+
+if (($edit_existing) && ($password == "****************"))
 {
-               if (isset($tls_verify))
-               {
-                               if ($tls_verify == "false")
-                                               $tls_verify = false;
-                               elseif ($tls_verify == "true")
-                                               $tls_verify = true;
-               }
-               try {
-                               $rpc = new UnrealIRCd\Connection
-                               (
-                                               "wss://$host:$port",
-                                               "$user:$password",
-                                               ["tls_verify" => $tls_verify]
-                               );
-               }
-               catch (Exception $e)
-               {
-                               die(json_encode(["error" => "Unable to connect to UnrealIRCd: ".$e->getMessage()]));
-               }
-               die(json_encode(["success" => "Successfully connected"]));
+       /* If editing existing and password unchanged,
+        * try to look up existing password.
+        */
+       if (isset($config["unrealircd"][$edit_existing]))
+       {
+               $password = $config["unrealircd"][$edit_existing]["rpc_password"];
+               if (str_starts_with($password, "secret:"))
+                       $password = secret_decrypt($password);
+       }
 }
+
+try {
+               $rpc = new UnrealIRCd\Connection
+               (
+                               "wss://$host:$port",
+                               "$user:$password",
+                               ["tls_verify" => $tls_verify]
+               );
+}
+catch (Exception $e)
+{
+               die(json_encode(["error" => "Unable to connect to UnrealIRCd: ".$e->getMessage()]));
+}
+
+die(json_encode(["success" => "Successfully connected"]));