]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - plugins/sql_auth/setup.php
Move SQL setup to its own page
[irc/unrealircd/unrealircd-webpanel.git] / plugins / sql_auth / setup.php
CommitLineData
46e8f612
VP
1<?php
2
3require_once "../../common.php";
4require_once "../../header.php";
5
6if (!isset($_POST) || empty($_POST))
7{
8 ?>
9
10 <h4>SQL Setup</h4>
11 In order to use SQL Auth, the relevant SQL tables must be created.<br>
12 If, for some reason, that's not what you want, please remove <code>"sql_auth"</code> from the plugins option in your webpanel configuration.<br><br>
13 Thanks for using SQL Auth plugin!<br><br>
14
15 <form method="post">
16 <button id="createbtn" name="createbtn" class="btn btn-primary" type="submit">Create the tables!</button>
17 </form>
18 <?php
19}
20elseif (isset($_POST['createbtn']))
21{
22 $conn = sqlnew();
23 $conn->query("CREATE TABLE IF NOT EXISTS " . SQL_PREFIX . "users (
24 user_id int AUTO_INCREMENT NOT NULL,
25 user_name VARCHAR(255) NOT NULL,
26 user_pass VARCHAR(255) NOT NULL,
27 user_email VARCHAR(255),
28 user_fname VARCHAR(255),
29 user_lname VARCHAR(255),
30 user_bio VARCHAR(255),
31 created VARCHAR(255),
32 PRIMARY KEY (user_id)
33 )");
34
35 /**
36 * Patch for beta users
37 * This adds the email column to existing tables without it
38 */
39 $columns = $conn->query("SHOW COLUMNS FROM " . SQL_PREFIX . "users");
40 $column_names = array();
41 $c = $columns->fetchAll();
42
43 foreach($c as $column) {
44 $column_names[] = $column['Field'];
45 }
46 $column_exists = in_array("user_email", $column_names);
47 if (!$column_exists) {
48 $conn->query("ALTER TABLE " . SQL_PREFIX . "users ADD COLUMN user_email varchar(255)");
49 }
50
51 /**
52 * Another patch for beta users
53 * This changes the size of the meta_value so we can store more
54 */
55
56 $conn->query("CREATE TABLE IF NOT EXISTS " . SQL_PREFIX . "user_meta (
57 meta_id int AUTO_INCREMENT NOT NULL,
58 user_id int NOT NULL,
59 meta_key VARCHAR(255) NOT NULL,
60 meta_value VARCHAR(255),
61 PRIMARY KEY (meta_id)
62 )");
63 $conn->query("CREATE TABLE IF NOT EXISTS " . SQL_PREFIX . "auth_settings (
64 id int AUTO_INCREMENT NOT NULL,
65 setting_key VARCHAR(255) NOT NULL,
66 setting_value VARCHAR(255),
67 PRIMARY KEY (id)
68 )");
69 $conn->query("CREATE TABLE IF NOT EXISTS " . SQL_PREFIX . "fail2ban (
70 id int AUTO_INCREMENT NOT NULL,
71 ip VARCHAR(255) NOT NULL,
72 count VARCHAR(255),
73 PRIMARY KEY (id)
74 )");
75 $c = [];
76 if (($columns = $conn->query("SHOW COLUMNS FROM ".SQL_PREFIX."user_meta")));
77 $c = $columns->fetchAll();
78 if (!empty($c))
79 $conn->query("ALTER TABLE `".SQL_PREFIX."user_meta` CHANGE `meta_value` `meta_value` VARCHAR(5000) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NULL DEFAULT NULL");
80
81
82 new AuthSettings();
83
84 Message::Success("Congratulations, you're all ready to go!");
85 ?>
86 <a class="btn btn-primary" href="<?php echo BASE_URL; ?>">Take me home!</a>
87 <a class="btn btn-warning" href="<?php echo BASE_URL."settings"; ?>">Settings</a>
88 <?php
89}
90require_once "../../footer.php";