+ public static function add_usermeta(&$meta)
+ {
+ $meta = $meta['meta'];
+ $conn = sqlnew();
+ /* check if it exists first, update it if it does */
+ $query = "SELECT * FROM " . SQL_PREFIX . "user_meta WHERE user_id = :id AND meta_key = :key";
+ $stmt = $conn->prepare($query);
+ $stmt->execute(["id" => $meta['id'], "key" => $meta['key']]);
+ if ($stmt->rowCount()) // it exists, update instead of insert
+ {
+ $query = "UPDATE " . SQL_PREFIX . "user_meta SET meta_value = :value WHERE user_id = :id AND meta_key = :key";
+ $stmt = $conn->prepare($query);
+ $stmt->execute($meta);
+ if ($stmt->rowCount())
+ return true;
+ return false;
+ }
+
+ else
+ {
+ $query = "INSERT INTO " . SQL_PREFIX . "user_meta (user_id, meta_key, meta_value) VALUES (:id, :key, :value)";
+ $stmt = $conn->prepare($query);
+ $stmt->execute($meta);
+ if ($stmt->rowCount())
+ return true;
+ return false;
+ }
+ }
+ public static function del_usermeta(&$u)
+ {
+ $conn = sqlnew();
+ $query = "DELETE FROM " . SQL_PREFIX . "user_meta WHERE user_id = :id AND meta_key = :key";
+ $stmt = $conn->prepare($query);
+ $stmt->execute($u['meta']);
+ if ($stmt->rowCount())
+ return true;
+ return false;
+ }
+ public static function user_create(&$u)
+ {
+ $username = $u['user_name'];
+ $first_name = $u['fname'];
+ $last_name = $u['lname'];
+ $password = $u['user_pass'];
+ $user_bio = $u['user_bio'];
+ $conn = sqlnew();
+ $prep = $conn->prepare("INSERT INTO " . SQL_PREFIX . "users (user_name, user_pass, user_fname, user_lname, user_bio, created) VALUES (:name, :pass, :fname, :lname, :user_bio, :created)");
+ $prep->execute(["name" => $username, "pass" => $password, "fname" => $first_name, "lname" => $last_name, "user_bio" => $user_bio, "created" => date("Y-m-d H:i:s")]);
+ if ($prep->rowCount())
+ $u['success'] = true;
+ else
+ $u['errmsg'][] = "Could not add user";
+ }
+
+ public static function get_user_list(&$list)
+ {
+ $conn = sqlnew();
+ $result = $conn->query("SELECT user_id FROM " . SQL_PREFIX . "users");
+ if (!$result) // impossible
+ {
+ die("Something went wrong.");
+ }
+ $userlist = [];
+ while($row = $result->fetch())
+ {
+ $userlist[] = new PanelUser(NULL, $row['user_id']);
+ }
+ if (!empty($userlist))
+ $list = $userlist;
+
+ }
+ public static function user_delete(&$u)
+ {
+ $user = $u['user'];
+ $query = "DELETE FROM " . SQL_PREFIX . "users WHERE user_id = :id";
+ $conn = sqlnew();
+ $stmt = $conn->prepare($query);
+ $stmt->execute(["id" => $user->id]);
+ $deleted = $stmt->rowCount();
+ if ($deleted)
+ {
+ $u['info'][] = "Successfully deleted user \"$user->username\"";
+ $u['boolint'] = 1;
+ } else {
+ $u['info'][] = "Unknown error";
+ $u['boolint'] = 0;
+ }
+ }
+}
+
+
+function security_check()
+{
+ $ip = $_SERVER['REMOTE_ADDR'];
+ if (dnsbl_check($ip))
+ return true;
+
+ else if (fail2ban_check($ip))
+ {
+
+ }
+}
+
+function dnsbl_check($ip)
+{
+ $dnsbl_lookup = DNSBL;
+
+ // clear variable just in case
+ $listed = NULL;
+
+ // if the IP was not given because you're an idiot, stop processing
+ if (!$ip) { return; }
+
+ // get the first two segments of the IPv4
+ $because = split($ip, "."); // why you
+ $you = $because[1]; // gotta play
+ $want = $because[2]; // that song
+ $to = $you.".".$want."."; // so loud?
+
+ // exempt local connections because sometimes they get a false positive
+ if ($to == "192.168." || $to == "127.0.") { return NULL; }
+
+ // you spin my IP right round, right round, to check the records baby, right round-round-round
+ $reverse_ip = glue(array_reverse(split($ip, ".")), ".");
+
+ // checkem
+ foreach ($dnsbl_lookup as $host) {
+
+ //if it was listed
+ if (checkdnsrr($reverse_ip . "." . $host . ".", "A")) {
+
+ //take note
+ $listed = $host;
+ }
+ }
+
+ // if it was safe, return NOTHING
+ if (!$listed) {
+ return NULL;
+ }
+
+ // else, you guessed it, return where it was listed
+ else {
+ return $listed;
+ }
+}
+
+function fail2ban_check($ip)
+{
+