Started code yeaah

This commit is contained in:
Jarkko Toivanen 2024-09-27 05:47:54 +03:00
commit ced9eba276
Signed by: jt
GPG key ID: 9151B109B73ECAD5
9 changed files with 115 additions and 0 deletions

1
.gitignore vendored Executable file
View file

@ -0,0 +1 @@
/database.db

2
.htaccess Normal file
View file

@ -0,0 +1,2 @@
php_flag display_errors on
php_flag html_errors on

4
README.md Executable file
View file

@ -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

4
api/.htaccess Normal file
View file

@ -0,0 +1,4 @@
RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
RewriteRule ^ index.php

20
api/index.php Normal file
View file

@ -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;
?>

BIN
favicon.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 MiB

2
inc/.htaccess Executable file
View file

@ -0,0 +1,2 @@
order deny,allow
deny from all

52
inc/database.php Executable file
View file

@ -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());
}
}
}
?>

30
index.php Executable file
View file

@ -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();
?>