Started code yeaah
This commit is contained in:
commit
69b07bb0c2
9 changed files with 127 additions and 0 deletions
1
.gitignore
vendored
Executable file
1
.gitignore
vendored
Executable file
|
@ -0,0 +1 @@
|
|||
/database.db
|
2
.htaccess
Normal file
2
.htaccess
Normal file
|
@ -0,0 +1,2 @@
|
|||
php_flag display_errors on
|
||||
php_flag html_errors on
|
2
README.md
Executable file
2
README.md
Executable file
|
@ -0,0 +1,2 @@
|
|||
- Requires `SQLite3` (`sudo apt install php-sqlite3` on Debian)
|
||||
- API requires mod_rewrite (`sudo a2enmod rewrite`) and configuring `AllowOverride all` for .htaccess
|
4
api/.htaccess
Normal file
4
api/.htaccess
Normal file
|
@ -0,0 +1,4 @@
|
|||
RewriteEngine on
|
||||
RewriteCond %{HTTP:Authorization} ^(.*)
|
||||
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
|
||||
RewriteRule ^ index.php
|
20
api/index.php
Normal file
20
api/index.php
Normal 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
BIN
favicon.ico
Executable file
Binary file not shown.
After Width: | Height: | Size: 1 MiB |
2
inc/.htaccess
Executable file
2
inc/.htaccess
Executable file
|
@ -0,0 +1,2 @@
|
|||
order deny,allow
|
||||
deny from all
|
63
inc/database.php
Executable file
63
inc/database.php
Executable file
|
@ -0,0 +1,63 @@
|
|||
<?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 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";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
33
index.php
Executable file
33
index.php
Executable file
|
@ -0,0 +1,33 @@
|
|||
<!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) {
|
||||
echo $database->lastErrorMsg();
|
||||
} else {
|
||||
echo "Opened database successfully\n";
|
||||
}
|
||||
|
||||
$database->close();
|
||||
|
||||
?>
|
Loading…
Reference in a new issue