]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - settings/install2.php
Add Settings - RPC Servers (start of multi-server work).
[irc/unrealircd/unrealircd-webpanel.git] / settings / install2.php
1 <?php
2
3 require_once "../inc/common.php";
4
5 /* Get the base url */
6 $uri = $_SERVER['REQUEST_URI'];
7 $tok = split($uri, "/");
8 $base_url = "";
9 for ($i=0; isset($tok[$i]); $i++)
10 {
11 if ($tok[$i] == "settings" && strstr($tok[$i + 1], "install.php"))
12 {
13 if ($i)
14 {
15 for($j=0; $j < $i; $j++)
16 {
17 strcat($base_url,$tok[$j]);
18 strcat($base_url,"/");
19 }
20 }
21 }
22 }
23 if (!strlen($base_url))
24 $base_url = "/";
25 define('BASE_URL', $base_url);
26
27 $writable = (is_writable("../config/")) ? true: false;
28 ?>
29 <!DOCTYPE html>
30 <head>
31 <div class="media">
32 <div class="media-body">
33
34 <meta name="viewport" content="width=device-width, initial-scale=1">
35 <meta name="HandheldFriendly" content="true">
36
37
38
39 <!-- Latest compiled and minified CSS -->
40 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
41
42 <!-- Font Awesome JS -->
43 <script defer src="https://use.fontawesome.com/releases/v6.2.1/js/solid.js" integrity="sha384-tzzSw1/Vo+0N5UhStP3bvwWPq+uvzCMfrN1fEFe+xBmv1C/AtVX5K0uZtmcHitFZ" crossorigin="anonymous"></script>
44 <script defer src="https://use.fontawesome.com/releases/v6.2.1/js/fontawesome.js" integrity="sha384-6OIrr52G08NpOFSZdxxz1xdNSndlD4vdcf/q2myIUVO0VsqaGHJsB0RaBE01VTOY" crossorigin="anonymous"></script>
45
46 <!-- Font Awesome icons -->
47 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css">
48 <script src="../js/unrealircd-admin.js"></script>
49 <title>UnrealIRCd Panel</title>
50 <link rel="icon" type="image/x-icon" href="<?php echo get_config("base_url"); ?>img/favicon.ico">
51
52 <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
53 <!-- Popper.JS -->
54 <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
55 <!-- Bootstrap JS -->
56 <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
57 </div></div>
58 </head>
59
60 <body role="document">
61
62 <div class="container mt-4"><div class="row justify-content-center"><img src="../img/unreal.jpg" width="35px" height="35px" style="margin-right: 15px"><h3>UnrealIRCd Admin Panel Configuration and Setup</h3></div></div>
63 <?php
64
65 if (isset($config['unrealircd']) && empty($config['unrealircd']['host']))
66 {
67 ?><br><div class="container"><?php Message::Fail("You're already configured!"); ?>
68 <br>
69 <a class="text-center btn btn-primary" href="<?php echo BASE_URL; ?>">Take me home!</a>
70 </div>
71 <?php
72 return;
73 }
74 elseif (isset($_POST) && !empty($_POST))
75 {
76 ?><br><div class="container"><?php
77 $opts = (object)$_POST;
78
79 $config["unrealircd"] = [
80 "rpc_user" => $opts->rpc_user,
81 "rpc_password" => $opts->rpc_password,
82 "host"=>$opts->rpc_iphost,
83 "port"=>$opts->rpc_port,
84 "tls_verify_cert"=>isset($opts->rpc_ssl)?true:false,
85 ];
86
87 /* And write the new config */
88 write_config();
89 ?>
90 <br>
91 Great! Everything has been completely set up for you. You can now browse the admin panel.<br><br>
92 <a class="text-center btn btn-primary" href="<?php echo get_config("base_url"); ?>">Let's go!</a></div>
93 <?php
94 return;
95 }
96
97 ?>
98 <style>
99 table tr td {
100 font-style: italic;
101 }
102 </style>
103 <!-- Form start -->
104 <form method="post">
105 <div id="page2" class="container">
106 <h5>RPC Uplink Information</h5>
107 <br>
108 Let's get you linked with UnrealIRCd.
109 <br><br>
110 If you don't have your credentials, you will need to create them. This is done in your <code>unrealircd.conf</code> <div id="rpc_instructions" class="ml-4 btn btn-sm btn-info">View instructions</div>
111 <br><br>
112 <div class="form-group">
113 <label for="rpc_iphost">Hostname or IP</label>
114 <input name="rpc_iphost" type="text" class="revalidation-needed-rpc form-control" id="rpc_iphost" aria-describedby="hostname_help" value="127.0.0.1">
115 <small id="hostname_help" class="form-text text-muted">The hostname or IP address of your UnrealIRCd server. You should use <code>127.0.0.1</code> for the same machine.</small>
116 </div>
117 <div class="form-group">
118 <label for="rpc_port">Server Port</label>
119 <input name="rpc_port" type="text" class="revalidation-needed-rpc form-control" id="rpc_port" aria-describedby="port_help" value="8600">
120 <small id="port_help" class="form-text text-muted">The port which you designated for RPC connections in your <code>unrealircd.conf</code></small>
121 </div>
122 <div class="form-group form-check">
123 <input name="rpc_ssl" type="checkbox" class="revalidation-needed-rpc form-check-input" value="ssl" id="rpc_ssl">
124 <label class="form-check-label" for="rpc_ssl">My UnrealIRCd server is on a different machine, verify the TLS connection.</label>
125 </div>
126 <div class="form-group">
127 <label for="rpc_username">Username</label>
128 <input name="rpc_user" type="text" class="revalidation-needed-rpc form-control" id="rpc_user" aria-describedby="username_help" autocomplete="new-password">
129 <small id="username_help" class="form-text text-muted">The name of your <code>rpc-user</code> block as defined in your <code>unrealircd.conf</code></small>
130 </div>
131 <div class="form-group">
132 <label for="rpc_password">Password</label>
133 <input name="rpc_password" type="password" class="revalidation-needed-rpc form-control" id="rpc_password" autocomplete="new-password">
134 </div>
135 <div class="text-center">
136 <button id="page2_next" type="submit" class="btn btn-primary ml-3">Submit</div>
137 <div id="page2_test_connection" class="btn btn-primary ml-3">Test connection</div>
138 </div>
139 </div>
140 <!-- Form end -->
141 </form>
142
143 <script>
144 let BASE_URL = '<?php echo get_config("base_url"); ?>';
145
146 let page2 = document.getElementById('page2');
147 let rpc_instructions = document.getElementById('rpc_instructions');
148
149 let rpc_host = document.getElementById('rpc_iphost');
150 let rpc_port = document.getElementById('rpc_port');
151 let rpc_user = document.getElementById('rpc_user');
152 let rpc_pass = document.getElementById('rpc_password');
153 let rpc_tls = document.getElementById('rpc_ssl');
154
155 let page2_back = document.getElementById('page2_back');
156 let page2_next = document.getElementById('page2_next');
157 let test_conn = document.getElementById('page2_test_connection');
158
159 rpc_instructions.addEventListener('click', e => {
160 window.open("https://www.unrealircd.org/docs/UnrealIRCd_webpanel#Configuring_UnrealIRCd");
161 });
162
163 page2_next.addEventListener('click', e => {
164 page2.style.display = 'none';
165 page3.style.display = '';
166 sql_form.style.display = 'none';
167 });
168
169 revalidate_rpc = document.querySelectorAll('.revalidation-needed-rpc');
170 for (let i = 0; i < revalidate_rpc.length; i++)
171 {
172 revalidate_rpc[i].addEventListener('input', e => {
173 page2_next.style.display = 'none';
174 test_conn.innerHTML = 'Test connection';
175 test_conn.style.display = '';
176 test_conn.classList.remove('disabled');
177 });
178 }
179
180 /* The RPC connection tester! */
181 test_conn.addEventListener('click', e => {
182 test_conn.classList.add('disabled');
183 test_conn.innerHTML = "Checking...";
184 fetch(BASE_URL + 'api/installation2.php', {
185 method:'POST',
186 headers: {'Content-Type':'application/x-www-form-urlencoded'},
187 body: 'method=rpc&'+
188 'host='+encodeURIComponent(rpc_host.value)+
189 '&port='+encodeURIComponent(rpc_port.value)+
190 '&user='+encodeURIComponent(rpc_user.value)+
191 '&password='+encodeURIComponent(rpc_pass.value)+
192 '&tls_verify='+rpc_tls.checked
193 })
194 .then(response => response.json())
195 .then(data => {
196 if (data.success)
197 {
198 // do something with the JSON data
199 test_conn.innerHTML = "Success!";
200 setTimeout(function() {
201 test_conn.style.display = 'none';
202 page2_next.style.display = '';
203 }, 2000);
204 }
205 else
206 {
207 test_conn.innerHTML = "Failed!";
208 setTimeout(function() {
209 test_conn.innerHTML = "Test connection";
210 test_conn.classList.remove('disabled');
211 }, 2000);
212 }
213 })
214 .catch(error => {
215 test_conn.innerHTML = "Failed!";
216 setTimeout(function() {
217 test_conn.innerHTML = "Test connection";
218 test_conn.classList.remove('disabled');
219 }, 2000);
220 });
221 });
222 </script>