]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - plugins/sql_auth/setup.php
Move to new style config, with config in config/ directory.
[irc/unrealircd/unrealircd-webpanel.git] / plugins / sql_auth / setup.php
CommitLineData
46e8f612
VP
1<?php
2
3require_once "../../common.php";
1cedd608
VP
4?>
5<!DOCTYPE html>
6<head>
7<div class="media">
8<div class="media-body">
46e8f612 9
1cedd608
VP
10 <meta name="viewport" content="width=device-width, initial-scale=1">
11 <meta name="HandheldFriendly" content="true">
12
ea90b321 13<link href="<?php echo get_config("base_url"); ?>css/unrealircd-admin.css" rel="stylesheet">
1cedd608
VP
14
15
16 <!-- Latest compiled and minified CSS -->
17 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
18
19<!-- Font Awesome JS -->
20<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>
21<script defer src="https://use.fontawesome.com/releases/v6.2.1/js/fontawesome.js" integrity="sha384-6OIrr52G08NpOFSZdxxz1xdNSndlD4vdcf/q2myIUVO0VsqaGHJsB0RaBE01VTOY" crossorigin="anonymous"></script>
22
23<!-- Font Awesome icons -->
24<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css">
ea90b321 25<script src="<?php echo get_config("base_url"); ?>js/unrealircd-admin.js"></script>
1cedd608 26<title>UnrealIRCd Panel</title>
ea90b321 27<link rel="icon" type="image/x-icon" href="<?php echo get_config("base_url"); ?>img/favicon.ico">
1cedd608
VP
28</head>
29<body role="document">
30
31<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
32<!-- Popper.JS -->
33<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>
34<!-- Bootstrap JS -->
35<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
36
37
38<?php
46e8f612
VP
39if (!isset($_POST) || empty($_POST))
40{
41 ?>
1cedd608 42 <div class="container">
46e8f612
VP
43 <h4>SQL Setup</h4>
44 In order to use SQL Auth, the relevant SQL tables must be created.<br>
45 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>
46 Thanks for using SQL Auth plugin!<br><br>
47
48 <form method="post">
49 <button id="createbtn" name="createbtn" class="btn btn-primary" type="submit">Create the tables!</button>
50 </form>
1cedd608 51 </div>
46e8f612
VP
52 <?php
53}
54elseif (isset($_POST['createbtn']))
55{
56 $conn = sqlnew();
ea90b321 57 $conn->query("CREATE TABLE IF NOT EXISTS " . get_config("mysql::table_prefix") . "users (
46e8f612
VP
58 user_id int AUTO_INCREMENT NOT NULL,
59 user_name VARCHAR(255) NOT NULL,
60 user_pass VARCHAR(255) NOT NULL,
61 user_email VARCHAR(255),
62 user_fname VARCHAR(255),
63 user_lname VARCHAR(255),
64 user_bio VARCHAR(255),
65 created VARCHAR(255),
66 PRIMARY KEY (user_id)
67 )");
68
69 /**
70 * Patch for beta users
71 * This adds the email column to existing tables without it
72 */
ea90b321 73 $columns = $conn->query("SHOW COLUMNS FROM " . get_config("mysql::table_prefix") . "users");
46e8f612
VP
74 $column_names = array();
75 $c = $columns->fetchAll();
76
77 foreach($c as $column) {
78 $column_names[] = $column['Field'];
79 }
80 $column_exists = in_array("user_email", $column_names);
81 if (!$column_exists) {
ea90b321 82 $conn->query("ALTER TABLE " . get_config("mysql::table_prefix") . "users ADD COLUMN user_email varchar(255)");
46e8f612
VP
83 }
84
85 /**
86 * Another patch for beta users
87 * This changes the size of the meta_value so we can store more
88 */
89
ea90b321 90 $conn->query("CREATE TABLE IF NOT EXISTS " . get_config("mysql::table_prefix") . "user_meta (
46e8f612
VP
91 meta_id int AUTO_INCREMENT NOT NULL,
92 user_id int NOT NULL,
93 meta_key VARCHAR(255) NOT NULL,
94 meta_value VARCHAR(255),
95 PRIMARY KEY (meta_id)
96 )");
ea90b321 97 $conn->query("CREATE TABLE IF NOT EXISTS " . get_config("mysql::table_prefix") . "auth_settings (
46e8f612
VP
98 id int AUTO_INCREMENT NOT NULL,
99 setting_key VARCHAR(255) NOT NULL,
100 setting_value VARCHAR(255),
101 PRIMARY KEY (id)
102 )");
ea90b321 103 $conn->query("CREATE TABLE IF NOT EXISTS " . get_config("mysql::table_prefix") . "fail2ban (
46e8f612
VP
104 id int AUTO_INCREMENT NOT NULL,
105 ip VARCHAR(255) NOT NULL,
106 count VARCHAR(255),
107 PRIMARY KEY (id)
108 )");
109 $c = [];
ea90b321 110 if (($columns = $conn->query("SHOW COLUMNS FROM ".get_config("mysql::table_prefix")."user_meta")));
46e8f612
VP
111 $c = $columns->fetchAll();
112 if (!empty($c))
ea90b321 113 $conn->query("ALTER TABLE `".get_config("mysql::table_prefix")."user_meta` CHANGE `meta_value` `meta_value` VARCHAR(5000) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NULL DEFAULT NULL");
46e8f612
VP
114
115
116 new AuthSettings();
117
118 Message::Success("Congratulations, you're all ready to go!");
119 ?>
ea90b321
BM
120 <a class="btn btn-primary" href="<?php echo get_config("base_url"); ?>">Take me home!</a>
121 <a class="btn btn-warning" href="<?php echo get_config("base_url")."settings"; ?>">Settings</a>
46e8f612
VP
122 <?php
123}
124require_once "../../footer.php";