commit f14509349747f6ebeaa3d70555eb08ecaea81ff2 Author: Jarkko Toivanen Date: Fri Sep 27 05:47:54 2024 +0300 Started code yeaah diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..a5cee70 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/database.db \ No newline at end of file diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..3b6603b --- /dev/null +++ b/.htaccess @@ -0,0 +1,2 @@ +php_flag display_errors on +php_flag html_errors on \ No newline at end of file diff --git a/README.md b/README.md new file mode 100755 index 0000000..6b71c01 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +- Requires `SQLite3` (`sudo apt install php-sqlite3` on Debian) +- API requires mod_rewrite (`sudo a2enmod rewrite`) and configuring `AllowOverride all` for .htaccess + +The icon is from https://www.flaticon.com/authors/smashicons diff --git a/api/.htaccess b/api/.htaccess new file mode 100644 index 0000000..46d7c45 --- /dev/null +++ b/api/.htaccess @@ -0,0 +1,4 @@ +RewriteEngine on +RewriteCond %{HTTP:Authorization} ^(.*) +RewriteRule .* - [e=HTTP_AUTHORIZATION:%1] +RewriteRule ^ index.php \ No newline at end of file diff --git a/api/index.php b/api/index.php new file mode 100644 index 0000000..d0d9a76 --- /dev/null +++ b/api/index.php @@ -0,0 +1,20 @@ + diff --git a/favicon.ico b/favicon.ico new file mode 100755 index 0000000..9f24a77 Binary files /dev/null and b/favicon.ico differ diff --git a/inc/.htaccess b/inc/.htaccess new file mode 100755 index 0000000..ff2beb8 --- /dev/null +++ b/inc/.htaccess @@ -0,0 +1,2 @@ +order deny,allow +deny from all diff --git a/inc/database.php b/inc/database.php new file mode 100755 index 0000000..a118c3e --- /dev/null +++ b/inc/database.php @@ -0,0 +1,63 @@ +open('database.db'); + + $sql = " + CREATE TABLE users ( + ID INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, + HANDLE TEXT NOT NULL UNIQUE, + NAME TEXT NOT NULL, + ABOUT TEXT NOT NULL + ); + + CREATE TABLE posts ( + ID INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, + TIME INTEGER NOT NULL, + USERID INTEGER NOT NULL, + TEXT TEXT NOT NULL + ); + + INSERT INTO users (ID, HANDLE, NAME, ABOUT) VALUES ('0', 'SYSTEM', 'SYSTEM', ''); + + "; + + $ret = $this->exec($sql); + if(!$ret) { + echo $this->lastErrorMsg(); + } else { + echo "Created required tables\n"; + } + + echo "Initialized database\n"; + + } + + function addUser($handle, $name, $about="") { + $sql = "INSERT INTO users (HANDLE, NAME, ABOUT) VALUES ('$handle', '$name', '$about')"; + $ret = $this->exec($sql); + if(!$ret) { + echo $this->lastErrorMsg(); + } else { + echo "User added\n"; + } + } + + function addPost($contents) { + $userid = 0; + $time = time(); + + $sql = "INSERT INTO posts (TIME, USERID, TEXT) values ('$time', '$userid', '$contents')"; + $ret = $this->exec($sql); + if(!$ret) { + echo $this->lastErrorMsg(); + } else { + echo "Post added\n"; + } + } +} +?> diff --git a/index.php b/index.php new file mode 100755 index 0000000..dad99f7 --- /dev/null +++ b/index.php @@ -0,0 +1,33 @@ + + + + + Snuffler + + +
+
+ + +

Snuffs

+ + + + +lastErrorMsg(); +} else { + echo "Opened database successfully\n"; +} + +$database->close(); + +?> \ No newline at end of file