]>
Commit | Line | Data |
---|---|---|
46e8f612 VP |
1 | <?php |
2 | ||
998dd7ec BM |
3 | die("WORK IN PROGRESS: This setup is being recoded to an all in one 'online install screen'. Try a 'git pull' tomorrow, maybe then the new setup is working."); |
4 | ||
46e8f612 | 5 | require_once "../../common.php"; |
1cedd608 VP |
6 | ?> |
7 | <!DOCTYPE html> | |
8 | <head> | |
9 | <div class="media"> | |
10 | <div class="media-body"> | |
46e8f612 | 11 | |
1cedd608 VP |
12 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
13 | <meta name="HandheldFriendly" content="true"> | |
14 | ||
ea90b321 | 15 | <link href="<?php echo get_config("base_url"); ?>css/unrealircd-admin.css" rel="stylesheet"> |
1cedd608 VP |
16 | |
17 | ||
18 | <!-- Latest compiled and minified CSS --> | |
19 | <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css"> | |
20 | ||
21 | <!-- Font Awesome JS --> | |
22 | <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> | |
23 | <script defer src="https://use.fontawesome.com/releases/v6.2.1/js/fontawesome.js" integrity="sha384-6OIrr52G08NpOFSZdxxz1xdNSndlD4vdcf/q2myIUVO0VsqaGHJsB0RaBE01VTOY" crossorigin="anonymous"></script> | |
24 | ||
25 | <!-- Font Awesome icons --> | |
26 | <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css"> | |
ea90b321 | 27 | <script src="<?php echo get_config("base_url"); ?>js/unrealircd-admin.js"></script> |
1cedd608 | 28 | <title>UnrealIRCd Panel</title> |
ea90b321 | 29 | <link rel="icon" type="image/x-icon" href="<?php echo get_config("base_url"); ?>img/favicon.ico"> |
1cedd608 VP |
30 | </head> |
31 | <body role="document"> | |
32 | ||
33 | <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> | |
34 | <!-- Popper.JS --> | |
35 | <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> | |
36 | <!-- Bootstrap JS --> | |
37 | <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script> | |
38 | ||
39 | ||
40 | <?php | |
46e8f612 VP |
41 | if (!isset($_POST) || empty($_POST)) |
42 | { | |
4f39e83f VP |
43 | ?> |
44 | <div class="container"> | |
45 | <h4>SQL Setup</h4> | |
46 | In order to use SQL Auth, the relevant SQL tables must be created.<br> | |
47 | 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> | |
48 | Thanks for using SQL Auth plugin!<br><br> | |
49 | ||
50 | <form method="post"> | |
51 | <button id="createbtn" name="createbtn" class="btn btn-primary" type="submit">Create the tables!</button> | |
52 | </form> | |
53 | </div> | |
54 | <?php | |
46e8f612 VP |
55 | } |
56 | elseif (isset($_POST['createbtn'])) | |
57 | { | |
4f39e83f VP |
58 | $conn = sqlnew(); |
59 | $conn->query("CREATE TABLE IF NOT EXISTS " . get_config("mysql::table_prefix") . "users ( | |
60 | user_id int AUTO_INCREMENT NOT NULL, | |
61 | user_name VARCHAR(255) NOT NULL, | |
62 | user_pass VARCHAR(255) NOT NULL, | |
63 | user_email VARCHAR(255), | |
64 | user_fname VARCHAR(255), | |
65 | user_lname VARCHAR(255), | |
66 | user_bio VARCHAR(255), | |
67 | created VARCHAR(255), | |
68 | PRIMARY KEY (user_id) | |
69 | )"); | |
70 | ||
71 | /** | |
72 | * Patch for beta users | |
73 | * This adds the email column to existing tables without it | |
74 | */ | |
75 | $columns = $conn->query("SHOW COLUMNS FROM " . get_config("mysql::table_prefix") . "users"); | |
76 | $column_names = array(); | |
77 | $c = $columns->fetchAll(); | |
78 | ||
79 | foreach($c as $column) { | |
80 | $column_names[] = $column['Field']; | |
81 | } | |
82 | $column_exists = in_array("user_email", $column_names); | |
83 | if (!$column_exists) { | |
84 | $conn->query("ALTER TABLE " . get_config("mysql::table_prefix") . "users ADD COLUMN user_email varchar(255)"); | |
85 | } | |
86 | ||
87 | /** | |
88 | * Another patch for beta users | |
89 | * This changes the size of the meta_value so we can store more | |
90 | */ | |
91 | ||
92 | $conn->query("CREATE TABLE IF NOT EXISTS " . get_config("mysql::table_prefix") . "user_meta ( | |
93 | meta_id int AUTO_INCREMENT NOT NULL, | |
94 | user_id int NOT NULL, | |
95 | meta_key VARCHAR(255) NOT NULL, | |
96 | meta_value VARCHAR(255), | |
97 | PRIMARY KEY (meta_id) | |
98 | )"); | |
99 | $conn->query("CREATE TABLE IF NOT EXISTS " . get_config("mysql::table_prefix") . "auth_settings ( | |
100 | id int AUTO_INCREMENT NOT NULL, | |
101 | setting_key VARCHAR(255) NOT NULL, | |
102 | setting_value VARCHAR(255), | |
103 | PRIMARY KEY (id) | |
104 | )"); | |
105 | $conn->query("CREATE TABLE IF NOT EXISTS " . get_config("mysql::table_prefix") . "fail2ban ( | |
106 | id int AUTO_INCREMENT NOT NULL, | |
107 | ip VARCHAR(255) NOT NULL, | |
108 | count VARCHAR(255), | |
109 | PRIMARY KEY (id) | |
110 | )"); | |
111 | $c = []; | |
112 | if (($columns = $conn->query("SHOW COLUMNS FROM ".get_config("mysql::table_prefix")."user_meta"))); | |
113 | $c = $columns->fetchAll(); | |
114 | if (!empty($c)) | |
115 | $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"); | |
116 | ||
117 | ||
b41fa16f | 118 | new DbSettingss(); |
4f39e83f VP |
119 | |
120 | ||
121 | /* make sure everything went well */ | |
122 | $tables = ["users", "user_meta", "fail2ban", "auth_settings"]; | |
123 | $errors = 0; // counter | |
124 | $error_messages = ""; | |
125 | foreach($tables as $table) | |
126 | { | |
ca3c76f7 | 127 | $prefix = get_config("sql::table_prefix"); |
34d54266 | 128 | $sql = "SHOW TABLES LIKE '$prefix%'"; // SQL query to check if table exists |
4f39e83f VP |
129 | |
130 | $result = $conn->query($sql); | |
34d54266 | 131 | if ($result->rowCount()) |
4f39e83f VP |
132 | { /* great! */ } |
133 | ||
134 | else { | |
135 | $errors++; | |
136 | strcat($error_messages,"Table '$prefix$table' was not created successfully.<br>"); | |
137 | } | |
138 | } | |
139 | if (!$errors) | |
140 | { | |
141 | if (defined('DEFAULT_USER')) // we've got a default account | |
142 | { | |
143 | $lkup = new PanelUser(DEFAULT_USER['username']); | |
144 | ||
145 | if (!$lkup->id) // doesn't exist, add it with full privileges | |
146 | { | |
147 | $user = []; | |
148 | $user['user_name'] = DEFAULT_USER['username']; | |
149 | $user['user_pass'] = DEFAULT_USER['password']; | |
150 | $user['err'] = ""; | |
151 | create_new_user($user); | |
152 | } | |
153 | $lkup = new PanelUser(DEFAULT_USER['username']); | |
154 | if (!user_can($lkup, PERMISSION_MANAGE_USERS)) | |
155 | $lkup->add_permission(PERMISSION_MANAGE_USERS); | |
156 | } | |
157 | Message::Success("Congratulations, you're all ready to go!"); | |
158 | } | |
159 | else | |
160 | Message::Fail("An error was encountered:", $error_messages); | |
161 | ||
162 | ?> | |
163 | <a class="btn btn-primary" href="<?php echo get_config("base_url"); ?>">Take me home!</a> | |
164 | <a class="btn btn-warning" href="<?php echo get_config("base_url")."settings"; ?>">Settings</a> | |
165 | <?php | |
46e8f612 VP |
166 | } |
167 | require_once "../../footer.php"; |