diff --git a/.gitignore b/.gitignore index b00ecde..9e8e355 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ _temp/ front/styles/bg_pattern_peace_old.png test.png -TODO.md \ No newline at end of file +TODO.md +front/images/* +front/images/counter/* \ No newline at end of file diff --git a/api/_auth.php b/api/_auth.php index 5fdaa29..f83bd7c 100644 --- a/api/_auth.php +++ b/api/_auth.php @@ -1,7 +1,10 @@ prepare("SELECT * FROM posts WHERE id = ?"); - $s->bind_param("s", $id); + $s = $db->prepare("SELECT * FROM comments WHERE comment_section_id=? AND created_at>=? AND created_at<=? ORDER BY created_at"); + $s->bind_param("sss", $sec_id, date("Y-m-d H:i:s", $ts_from), date("Y-m-d H:i:s", $ts_to)); $s->execute(); - $d = $s->get_result()->fetch_assoc(); + $d = $s->get_result(); - if (!(bool)$d) { - return null; + if (!(bool)$d) + return new ReturnT(data: $result); + + $isAdmin = false; + if ($LOGGED_IN && User_HasRole($THIS_USER, "admin")->GetData()) + $isAdmin = true; + + while ($row = $d->fetch_array()) { + if (!$isAdmin && $row["needs_check"]) + continue; + + $newResultRow = array( + "id" => $row["id"], + "author_id" => $row["author_id"], + "created_at" => $row["created_at"], + "contents" => $row["contents"] + ); + + if ($isAdmin) + $newResultRow["needs_check"] = (bool)$row["needs_check"]; + + $result[] = $newResultRow; + } + + return new ReturnT(data: $result); } -if (ThisFileIsRequested(__FILE__)) { - require_once("../_json.php"); +// Methods + +/* + * METHOD + * Get comments from range of selected comment section + */ +function Comments_GetSectionRange_Method (array $req): ReturnT { + // Input sanity checks $SectionID = null; + $TSFrom = 0; + $TSTo = 0xffffffff; - if (isset($_REQUEST["id"])) { - if (!ctype_digit($_REQUEST["id"])) - ReturnJSONError($Err_RDP_InvalidID, "id must be numeric"); - $SectionID = intval($_REQUEST["id"]); + if (isset($req["id"])) { + if (!ctype_digit($req["id"])) + return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "id must be numeric"); + $SectionID = intval($req["id"]); } else { - ReturnJSONError($Err_RDP_InvalidID, "id must be specified"); + return new ReturnT(err_code: E_UIN_INSUFARGS, err_desc: "id must be specified"); } - /* - $ResponseData = ComSec_GetComms($SectionID); - if ($ResponseData) - ReturnJSONData($ResponseData); + if (isset($req["ts_from"])) { + $TSFrom = $req["ts_from"]; + + if (strlen($TSFrom) > 24) + return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "start timestamp cant be this long"); + + if (!ctype_digit($TSFrom)) + return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "start timestamp must be numeric"); + + $TSFrom = intval($TSFrom); + + if ($TSFrom > 0xffffffff) + return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "start timestamp cant be bigger than INT32_MAX"); + } + + if (isset($req["ts_to"])) { + $TSTo = $req["ts_to"]; + + if (strlen($TSTo) > 24) + return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "start timestamp cant be this long"); + + if (!ctype_digit($TSTo)) + return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "start timestamp must be numeric"); + + $TSTo = intval($TSTo); + + if ($TSTo > 0xffffffff) + return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "start timestamp cant be bigger than INT32_MAX"); + } + + if ($TSTo < $TSFrom) + return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "start timestamp cant be bigger than end timestamp"); + + // Actions + + return Comments_GetSectionRange($SectionID, $TSFrom, $TSTo); +} + + + +if (Utils_ThisFileIsRequested(__FILE__)) { + require_once("../_json.php"); + + $result = Comments_GetSectionRange_Method($_REQUEST); + + if ($result->IsError()) + $result->ThrowJSONError(); else - ReturnJSONError($Err_DP_IDNotFound, "wrong id"); - */ + JSON_ReturnData($result->GetData()); } ?> \ No newline at end of file diff --git a/api/post/create.php b/api/post/create.php index 2788e85..b81ef07 100644 --- a/api/post/create.php +++ b/api/post/create.php @@ -88,6 +88,8 @@ function Post_Create ( bool $comms_enabled = false, bool $edit_lock = false ): ReturnT { + global $db; + $result = null; // Author ID should exist @@ -113,7 +115,7 @@ function Post_Create ( * Create single publication */ function Post_Create_Method (array $req, array $files): ReturnT { - global $db, $Config, $LOGGED_IN, $THIS_USER; + global $Config, $LOGGED_IN, $THIS_USER; $author_id = $THIS_USER; $tags = null; @@ -168,7 +170,7 @@ function Post_Create_Method (array $req, array $files): ReturnT { -if (ThisFileIsRequested(__FILE__)) { +if (Utils_ThisFileIsRequested(__FILE__)) { require_once("../_json.php"); // TODO: cleanup if bad result diff --git a/api/post/index.php b/api/post/index.php index e87f852..c06dfae 100644 --- a/api/post/index.php +++ b/api/post/index.php @@ -1,14 +1,39 @@ prepare("SELECT id FROM posts"); // NOTICE: very naive and will impact performance when many posts are exist + $s->execute(); + $d = $s->get_result()->fetch_assoc(); + + if ($d) + return count($d); + else + return 0; +} + /* * FUNCTION * Increment number of views for post @@ -79,10 +104,10 @@ function Post_GetByID_Method (array $req) { $PostID = null; if (isset($req["id"])) { if (!ctype_digit($req["id"])) - return new ReturnT(err_code: E_UIN_BADARGS, "id must be numeric"); + return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "id must be numeric"); $PostID = intval($req["id"]); } else { - return new ReturnT(err_code: E_UIN_INSUFARGS, "id must be specified"); + return new ReturnT(err_code: E_UIN_INSUFARGS, err_desc: "id must be specified"); } // Actions diff --git a/api/user/__admin_session.php b/api/user/__admin_session.php index 2f03500..2b52c5f 100644 --- a/api/user/__admin_session.php +++ b/api/user/__admin_session.php @@ -15,7 +15,7 @@ if (Utils_ThisFileIsRequested(__FILE__)) { JSON_ReturnError(code: E_UNS_INTERNAL, desc: "you need to enable debug mode in configuration file first"); if (!isset($_REQUEST["id"])) - JSON_ReturnError(code: E_UIN_WRONGID, desc: "valid id must be specified"); + JSON_ReturnError(code: E_UIN_INSUFARGS, desc: "valid id must be specified"); if (!isset($_SESSION["userid"])) session_start(); diff --git a/api/user/create.php b/api/user/create.php index b450f75..d8518ec 100644 --- a/api/user/create.php +++ b/api/user/create.php @@ -16,13 +16,15 @@ require_once("index.php"); * Create new user account */ function User_Create (string $login, string $password, ?string $email = null, ?string $invite_id = null, ?string $avatar_path = null): ReturnT { + global $db; + $salt = Utils_GenerateRandomString(8); $pwd_hash = hash("sha256", $password . $salt, true); // TODO: process invite $s = $db->prepare("INSERT INTO users (login,email,password_hash,salt,avatar_path,role,invite_id) VALUES (?,?,?,?,?,?,?)"); - $role = "newbie"; // TODO: make decision from config + $role = "newbie"; // TODO: make decision from config or supply by argument $s->bind_param("sssssss", $login, $email, $pwd_hash, $salt, $avatar_path, $role, $invite_id); if ($s->execute() === false) @@ -40,7 +42,7 @@ function User_Create (string $login, string $password, ?string $email = null, ?s * Create new user account */ function User_Create_Method (array $req): ReturnT { - global $db, $Config, $LOGGED_IN; + global $Config, $LOGGED_IN; $login = null; $password = null; diff --git a/api/user/delete.php b/api/user/delete.php index 70a62d7..668b6d5 100644 --- a/api/user/delete.php +++ b/api/user/delete.php @@ -15,6 +15,8 @@ require_once("./index.php"); * Delete existing account */ function User_Delete (int $id): ReturnT { + global $db; + $s = $db->prepare("delete from users where id = ?"); $s->bind_param("s", $id); @@ -30,7 +32,7 @@ function User_Delete (int $id): ReturnT { * Delete existing account */ function User_Delete_Method (array $req): ReturnT { - global $db, $LOGGED_IN, $THIS_USER; + global $LOGGED_IN, $THIS_USER; $id = null; @@ -47,7 +49,7 @@ function User_Delete_Method (array $req): ReturnT { } // If its attempt to delete other account - if (!User_HasRole($THIS_USER, "admin").GetData() && $THIS_USER !== $id) + if (!User_HasRole($THIS_USER, "admin")->GetData() && $THIS_USER !== $id) return new ReturnT(err_code: E_ACS_INSUFROLE, err_desc: "you must be admin to delete other accounts"); // Actions @@ -63,7 +65,7 @@ if (Utils_ThisFileIsRequested(__FILE__)) { // HACK: for debugging purposes. Will be removed later if ($Config["debug"]) $_POST = $_REQUEST; - + $result = User_Delete_Method($_POST); if ($result->IsError()) { diff --git a/api/user/index.php b/api/user/index.php index 7032a3b..fc1576e 100644 --- a/api/user/index.php +++ b/api/user/index.php @@ -1,10 +1,17 @@ prepare("SELECT * FROM users WHERE login = ?"); @@ -28,7 +35,7 @@ function User_LoginExist ($login): bool { * FUNCTION * Check if user with supplied ID exists */ -function User_IDExist ($id): bool { +function User_IDExist (int $id): bool { global $db; $s = $db->prepare("SELECT * FROM users WHERE id = ?"); @@ -42,7 +49,7 @@ function User_IDExist ($id): bool { * FUNCTION * Check if user has specified role */ -function User_HasRole ($id, $role): ReturnT { +function User_HasRole (int $id, string $role): ReturnT { global $db; $s = $db->prepare("SELECT * FROM users WHERE id = ?"); @@ -60,7 +67,7 @@ function User_HasRole ($id, $role): ReturnT { * FUNCTION * Check if user is moderator (or higher) */ -function User_IsMod ($id): ReturnT { +function User_IsMod (int $id): ReturnT { global $db; $s = $db->prepare("SELECT * FROM users WHERE id = ?"); @@ -79,7 +86,7 @@ function User_IsMod ($id): ReturnT { * Get user information from DB */ function User_GetInfoByID (int $id): ReturnT { - global $THIS_USER; + global $db, $THIS_USER; $result = array(); @@ -97,7 +104,7 @@ function User_GetInfoByID (int $id): ReturnT { $result["avatar_path"] = $d["avatar_path"]; $result["role"] = $d["role"]; $result["banned"] = $d["banned"]; - if (($id === $THIS_USER) || User_IsMod($THIS_USER).GetData()) { // User himself and mods can see additional info + if (($id === $THIS_USER) || User_IsMod($THIS_USER)->GetData()) { // User himself and mods can see additional info $result["email"] = $d["email"]; $result["invite_id"] = $d["invite_id"]; } @@ -114,7 +121,7 @@ function User_GetInfoByID (int $id): ReturnT { * Get user information from DB */ function User_GetInfoByID_Method (array $req): ReturnT { - global $db, $THIS_USER, $LOGGED_IN; + global $THIS_USER, $LOGGED_IN; // Input sanity checks @@ -127,7 +134,7 @@ function User_GetInfoByID_Method (array $req): ReturnT { if ($LOGGED_IN) $UserID = $THIS_USER; else - return new ReturnT(err_code: E_UIN_BADARGS, err_desc: "id must be specified or valid session must be provided"); + return new ReturnT(err_code: E_UIN_INSUFARGS, err_desc: "id must be specified or valid session must be provided"); } // Actions diff --git a/docs/DB.md b/docs/DB.md index 9da1a62..6dba1d5 100644 --- a/docs/DB.md +++ b/docs/DB.md @@ -4,10 +4,14 @@ We are using MariaDB, but any MySQL-compatible database should be enough. There are instructions how to setup it for using with E949. +1. Login to your SQL database with admin account: + ```bash mysql -u root -p ``` +2. Setup new user and database: + ```mysql CREATE USER e949@localhost IDENTIFIED BY 'password'; CREATE DATABASE e949 CHARACTER SET = 'utf8'; @@ -16,10 +20,14 @@ FLUSH PRIVILEGES; EXIT ``` +3. Login with new account: + ```bash mysql -u e949 -p ``` +4. Create tables: + ```mysql USE e949; CREATE TABLE users ( @@ -72,4 +80,6 @@ CREATE TABLE invites ( CREATE TABLE approved_tags ( value VARCHAR(255) NOT NULL COMMENT 'The tag itself' ); -``` \ No newline at end of file +``` + +5. Profit!!! \ No newline at end of file diff --git a/front/counter.php b/front/counter.php new file mode 100644 index 0000000..51c0c13 --- /dev/null +++ b/front/counter.php @@ -0,0 +1,24 @@ + +
+ "; + while (count($allNumbers) < 7) + $allNumbers[] = ""; + + foreach ($allNumbers as $numberImg) + echo $numberImg; + ?> +
\ No newline at end of file diff --git a/front/favicon.html b/front/favicon.html new file mode 100644 index 0000000..d41c581 --- /dev/null +++ b/front/favicon.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/front/head.php b/front/head.php new file mode 100644 index 0000000..5fa76ec --- /dev/null +++ b/front/head.php @@ -0,0 +1,16 @@ + + ... + +if (!isset($PAGE_TITLE)) { + http_response_code(500); + die("\$PAGE_TITLE not set"); +} + +echo "E949: $PAGE_TITLE\n"; + +require_once("favicon.html"); + +?> + + \ No newline at end of file diff --git a/front/searchbox.php b/front/searchbox.php new file mode 100644 index 0000000..3e88d61 --- /dev/null +++ b/front/searchbox.php @@ -0,0 +1,42 @@ + + \ No newline at end of file diff --git a/front/styles/bg_pattern_peace.png b/front/styles/bg_pattern_peace.png deleted file mode 100644 index 1ab9550..0000000 Binary files a/front/styles/bg_pattern_peace.png and /dev/null differ diff --git a/front/styles/bg_pattern_peace_old.png b/front/styles/bg_pattern_peace_old.png deleted file mode 100644 index 9a6c9df..0000000 Binary files a/front/styles/bg_pattern_peace_old.png and /dev/null differ diff --git a/front/styles/default.css b/front/styles/default.css index 082fca8..12b0c60 100644 --- a/front/styles/default.css +++ b/front/styles/default.css @@ -1,5 +1,7 @@ -body, div, h1, h2, h3, h4, h5, h6, p, ul, li, dd, dt { - font-family: Verdana, Sans-Serif; +body { + background-color: #094e59; + background-image: url("../images/bg_pattern_peace.png"); + background-repeat: repeat; } body, div, p, a { @@ -7,37 +9,11 @@ body, div, p, a { margin: 0; } -h1, h2, h3, h4, h5, h6, p, a { - color: #00c07c; - text-decoration: none; -} - -a { - color: #009049; -} - -body { - background-color: #094e59; - background-image: url("./bg_pattern_peace.png"); - background-repeat: repeat; -} - div.wrapper { text-align: center; margin: auto; } -/*div.wrapper img { - width: 60%; - height: 60%; -}*/ - -h1.title { - font-size: 4em; - padding: 0; - margin: 0; -} - div.nav { margin-bottom: 0.25rem; } @@ -63,6 +39,30 @@ div.notsearchbox { font-size: 80%; } +h1, h2, h3, h4, h5, h6, p, ul, li, dd, dt { + font-family: Verdana, Sans-Serif; +} + +h1, h2, h3, h4, h5, h6, p, a { + color: #00c07c; + text-decoration: none; +} + +a { + color: #009049; +} + +div.nav a.useraccount { + color: orange; + text-decoration: underline; +} + +h1.title { + font-size: 4em; + padding: 0; + margin: 0; +} + @media only screen and (max-height: 600px) { div.wrapper { top: 25vh; diff --git a/index.html b/index.html deleted file mode 100644 index 564064f..0000000 --- a/index.html +++ /dev/null @@ -1,60 +0,0 @@ - - - - E949: Index - - - - - - - - - - - -
-
- -
- -
- - - - - - - -
-
-

- Serving 3,451,953 posts
- Takedown Policy and Process | - Contact Us | - Advertising | - Terms of Service | - Privacy -

-
-
- - \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..4e70b1c --- /dev/null +++ b/index.php @@ -0,0 +1,44 @@ + + + + + + + +
+
+ +
+ +
+

+ Serving 3,451,953 posts
+ Takedown Policy and Process | + Contact Us | + Advertising | + Terms of Service | + Privacy +

+
+
+ + \ No newline at end of file