X-Git-Url: https://jfr.im/git/irc/unrealircd/unrealircd-webpanel.git/blobdiff_plain/630261974fd350964443aed92704938d4a8bd858..41aad10cbe0755aee50f597cb2cadd3029de7e1d:/api/installation2.php?ds=sidebyside diff --git a/api/installation2.php b/api/installation2.php index e9dde10..288f4be 100644 --- a/api/installation2.php +++ b/api/installation2.php @@ -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"]));