commit ced9eba276d85618d08d5d126a5c6e01a6a7bf89
Author: Jarkko Toivanen <jt@jakest.us>
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 @@
+<?php
+$url = explode('/', $_SERVER['REQUEST_URI']);
+while ($url[0] !== "api") {
+	array_shift($url);
+}
+array_shift($url);
+$count = 0;
+while (!empty($url[0])) {
+	switch ($url[0]) {
+		case 'asd':
+			echo "asdasd";
+			break;
+		default:
+			echo $url[0] . "\n";
+	}
+	$count += 1;
+	array_shift($url);
+}
+echo "\n" . $count;
+?>
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..b946115
--- /dev/null
+++ b/inc/database.php
@@ -0,0 +1,52 @@
+<?php
+if(count(get_included_files()) ==1) {
+	http_response_code(403);
+	die("403: Forbidden");
+}
+class DataBase extends SQLite3 {
+	function __construct() {
+		$this->open('database.db');
+		
+		$sql = "
+			CREATE TABLE IF NOT EXISTS users (
+			ID	INTEGER	PRIMARY KEY	AUTOINCREMENT	UNIQUE,
+			HANDLE	TEXT	NOT NULL	UNIQUE,
+			NAME	TEXT	NOT NULL,
+			ABOUT	TEXT	NOT NULL
+			);
+
+			CREATE TABLE IF NOT EXISTS posts (
+			ID	INTEGER	PRIMARY KEY	AUTOINCREMENT	UNIQUE,
+			TIME	INTEGER	NOT NULL,
+			USERID	INTEGER	NOT NULL,
+			TEXT	TEXT	NOT NULL
+			);
+
+			INSERT OR IGNORE INTO users (ID, HANDLE, NAME, ABOUT) VALUES ('0', 'SYSTEM', 'SYSTEM', '');
+
+		";
+		
+		$ret = $this->exec($sql);
+		
+	}
+	
+	function addUser($handle, $name, $about="") {
+		$sql = "INSERT INTO users (HANDLE, NAME, ABOUT) VALUES ('$handle', '$name', '$about')";
+		$ret = $this->exec($sql);
+		if(!$ret) {
+			die($this->lastErrorMsg());
+		}
+	}
+
+	function addPost($contents) {
+		$userid = 0;
+		$time = time();
+
+		$sql = "INSERT INTO posts (TIME, USERID, TEXT) values ('$time', '$userid', '$contents')";
+		$ret = $this->exec($sql);
+		if(!$ret) {
+			die($this->lastErrorMsg());
+		}
+	}
+}
+?>
diff --git a/index.php b/index.php
new file mode 100755
index 0000000..b388092
--- /dev/null
+++ b/index.php
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<meta charset="UTF-8">
+	<title>Snuffler</title>
+</head>
+<body>
+	<form>
+		<textarea name="text" rows="5" placeholder="Whatcha snuffin' about?"></textarea><br />
+		<select id="user" name="user">
+			<option value=0>SYSTEM</option>
+			<option value=1>User</option>
+		</select>
+		<input type="submit" id="submit" name="submit" value="Snuff!" />
+	<h1>Snuffs</h1>
+</body>
+</html>
+
+
+<?php
+require_once "inc/database.php";
+
+$database = new DataBase();
+
+if(!$database) {
+	die($database->lastErrorMsg());
+}
+$database->close();
+
+?>
\ No newline at end of file