]>
Commit | Line | Data |
---|---|---|
54b9603c BM |
1 | <?php |
2 | ||
3 | require_once "../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"> | |
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"> | |
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?method=rpc&host='+rpc_host.value+'&port='+rpc_port.value+'&user='+rpc_user.value+'&password='+rpc_pass.value+'&tls_verify='+rpc_tls.checked) | |
185 | .then(response => response.json()) | |
186 | .then(data => { | |
187 | if (data.success) | |
188 | { | |
189 | // do something with the JSON data | |
190 | test_conn.innerHTML = "Success!"; | |
191 | setTimeout(function() { | |
192 | test_conn.style.display = 'none'; | |
193 | page2_next.style.display = ''; | |
194 | }, 2000); | |
195 | } | |
196 | else | |
197 | { | |
198 | test_conn.innerHTML = "Failed!"; | |
199 | setTimeout(function() { | |
200 | test_conn.innerHTML = "Test connection"; | |
201 | test_conn.classList.remove('disabled'); | |
202 | }, 2000); | |
203 | } | |
204 | }) | |
205 | .catch(error => { | |
206 | test_conn.innerHTML = "Failed!"; | |
207 | setTimeout(function() { | |
208 | test_conn.innerHTML = "Test connection"; | |
209 | test_conn.classList.remove('disabled'); | |
210 | }, 2000); | |
211 | }); | |
212 | }); | |
213 | </script> |