Move react over
0
exam2/pages/404.php → exam/dist/404.php
vendored
0
exam2/pages/500.php → exam/dist/500.php
vendored
9052
exam/dist/assets/index-D81sf-ye.js
vendored
Normal file
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
31
exam/dist/index.html
vendored
@ -1,5 +1,26 @@
|
||||
<h1>Redirect to React</h1>
|
||||
<form action="/phpCourse/exam/api/user/1" enctype="multipart/form-data" method="POST">
|
||||
<input type="file" name="image" />
|
||||
<input type="submit">Send</input>
|
||||
</form>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link
|
||||
rel="icon"
|
||||
type="image/svg+xml"
|
||||
href="/phpCourse/exam/dist/vite.svg"
|
||||
/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + React + TS</title>
|
||||
<script
|
||||
type="module"
|
||||
crossorigin
|
||||
src="/phpCourse/exam/dist/assets/index-D81sf-ye.js"
|
||||
></script>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
crossorigin
|
||||
href="/phpCourse/exam/dist/assets/index-DiwrgTda.css"
|
||||
/>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
0
exam2/pages/vite.svg → exam/dist/vite.svg
vendored
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
@ -5,7 +5,7 @@ import react from '@vitejs/plugin-react';
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
build: {
|
||||
outDir: '../pages',
|
||||
outDir: '../dist',
|
||||
},
|
||||
base: 'phpCourse/exam/pages',
|
||||
base: 'phpCourse/exam/dist',
|
||||
});
|
||||
@ -1,37 +0,0 @@
|
||||
RewriteEngine On
|
||||
|
||||
##
|
||||
## You may need to uncomment the following line for some hosting environments,
|
||||
## if you have installed to a subdirectory, enter the name here also.
|
||||
##
|
||||
RewriteBase /phpCourse/exam
|
||||
|
||||
##
|
||||
## Black listed folders
|
||||
##
|
||||
RewriteRule ^phpCourse/exam/app/.* index.php [L,NC]
|
||||
RewriteRule ^phpCourse/exam/config/.* index.php [L,NC]
|
||||
RewriteRule ^phpCourse/exam/vendor/.* index.php [L,NC]
|
||||
RewriteRule ^phpCourse/exam/routes/.* index.php [L,NC]
|
||||
|
||||
##
|
||||
## White listed folders
|
||||
##
|
||||
RewriteCond %{REQUEST_FILENAME} -f
|
||||
RewriteCond %{REQUEST_FILENAME} !/api/docs/.*
|
||||
RewriteCond %{REQUEST_FILENAME} !/pages/.*
|
||||
RewriteCond %{REQUEST_FILENAME} !/pages/assets/.*
|
||||
RewriteRule !^index.php index.php [L,NC]
|
||||
|
||||
##
|
||||
## Block all PHP files, except index
|
||||
##
|
||||
RewriteCond %{REQUEST_FILENAME} -f
|
||||
RewriteCond %{REQUEST_FILENAME} \.php$
|
||||
RewriteRule !^index.php index.php [L,NC]
|
||||
|
||||
##
|
||||
## Standard routes
|
||||
##
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^ index.php [L]
|
||||
@ -1,2 +0,0 @@
|
||||
Order deny,allow
|
||||
Allow from All
|
||||
@ -1,114 +0,0 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: PHP Course Exam
|
||||
version: 1.0.0
|
||||
contact:
|
||||
name: Kilian Kurt Hofmann
|
||||
email: khofmann@zedat.fu-berlin.de
|
||||
description: PHP Course (ABV FU Berlin) 2024 Exam
|
||||
paths:
|
||||
/users:
|
||||
get:
|
||||
summary: Get Users
|
||||
description: Returns all users
|
||||
parameters: []
|
||||
operationId: ""
|
||||
responses:
|
||||
"200":
|
||||
description: Default response
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/UsersListResponse"
|
||||
"401":
|
||||
description: Not allowed
|
||||
tags:
|
||||
- Users
|
||||
security:
|
||||
- BasicAuth: []
|
||||
put:
|
||||
summary: Add User
|
||||
description: Add a new user
|
||||
parameters: []
|
||||
operationId: ""
|
||||
responses:
|
||||
"200":
|
||||
description: Default response
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/TrueResponse"
|
||||
"401":
|
||||
description: Not allowed
|
||||
"500":
|
||||
description: Error
|
||||
tags:
|
||||
- Users
|
||||
security:
|
||||
- BasicAuth: []
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/UserAddBody"
|
||||
externalDocs:
|
||||
url: "https://khofmann.userpage.fu-berlin.de/phpCourse/exam/api/docs/"
|
||||
security: []
|
||||
servers:
|
||||
- url: "https://khofmann.userpage.fu-berlin.de/phpCourse/exam/api/"
|
||||
description: ""
|
||||
variables: {}
|
||||
components:
|
||||
links: {}
|
||||
callbacks: {}
|
||||
schemas:
|
||||
UsersListResponse:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/UserType"
|
||||
UserType:
|
||||
type: object
|
||||
properties:
|
||||
ID:
|
||||
type: number
|
||||
description: User ID
|
||||
example: 1
|
||||
FirstName:
|
||||
type: string
|
||||
description: Given name of user
|
||||
example: Max
|
||||
LastName:
|
||||
type: string
|
||||
description: Family name of User
|
||||
example: Mustermann
|
||||
token:
|
||||
type: string
|
||||
description: Access Token
|
||||
format: uuid
|
||||
example: 3be6453c-03eb-4357-ae5a-984a0e574a54
|
||||
UserAddBody:
|
||||
type: object
|
||||
required:
|
||||
- FirstName
|
||||
- LastName
|
||||
properties:
|
||||
FirstName:
|
||||
type: string
|
||||
description: Given name of user
|
||||
example: Max
|
||||
LastName:
|
||||
type: string
|
||||
description: Family name of User
|
||||
example: Mustermann
|
||||
TrueResponse:
|
||||
type: boolean
|
||||
example: true
|
||||
securitySchemes:
|
||||
BasicAuth:
|
||||
type: apiKey
|
||||
name: token
|
||||
in: header
|
||||
tags:
|
||||
- name: Users
|
||||
- name: Posts
|
||||
@ -1,10 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<link href="./index.css" rel="stylesheet" />
|
||||
|
||||
<title>API Docs</title>
|
||||
</head>
|
||||
|
||||
<body></body>
|
||||
</html>
|
||||
@ -1,3 +0,0 @@
|
||||
<?php
|
||||
|
||||
Headers::redirect("docs/index.html");
|
||||
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
switch ($method) {
|
||||
case "GET":
|
||||
return get();
|
||||
default:
|
||||
return Response::api("$method not supported", 500);
|
||||
}
|
||||
|
||||
function get()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
$query =
|
||||
"SELECT
|
||||
*
|
||||
FROM
|
||||
egb_gaestebuch";
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->execute();
|
||||
|
||||
Response::api($stmt->fetchAll());
|
||||
}
|
||||
@ -1,90 +0,0 @@
|
||||
<?php
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
$params = PathParams::get();
|
||||
|
||||
if (empty($params[2])) {
|
||||
return Response::api("Missing param", 500);
|
||||
}
|
||||
|
||||
switch ($method) {
|
||||
case "GET":
|
||||
if (Auth::hasPermission("read")) return get($params[2]);
|
||||
break;
|
||||
case "POST":
|
||||
if (Auth::hasPermission("write")) return post($params[2]);
|
||||
break;
|
||||
case "DELETE":
|
||||
if (Auth::hasPermission("write")) return delete($params[2]);
|
||||
break;
|
||||
default:
|
||||
return Response::api("$method not supported", 500);
|
||||
}
|
||||
|
||||
return Response::api("Not allowed", 401);
|
||||
|
||||
function get($id)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
$query =
|
||||
"SELECT
|
||||
*
|
||||
FROM
|
||||
Users
|
||||
WHERE
|
||||
ID = :ID";
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(":ID", $id);
|
||||
$stmt->execute();
|
||||
|
||||
Response::api($stmt->fetchAll());
|
||||
}
|
||||
|
||||
function post($id)
|
||||
{
|
||||
|
||||
$db = Database::getInstance();
|
||||
|
||||
$query =
|
||||
"UPDATE
|
||||
Users
|
||||
SET
|
||||
FirstName = :FIRST, LastName = :LAST
|
||||
WHERE
|
||||
ID = :ID";
|
||||
|
||||
$_POST = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(":FIRST", $_POST["firstName"]);
|
||||
$stmt->bindValue(":LAST", $_POST["lastName"]);
|
||||
$stmt->bindValue(":ID", $id);
|
||||
|
||||
Response::api($stmt->execute());
|
||||
} catch (Exception $e) {
|
||||
Response::api($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
function delete($id)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
$query =
|
||||
"DELETE FROM
|
||||
Users
|
||||
WHERE
|
||||
ID = :ID";
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(":ID", $id);
|
||||
|
||||
Response::api($stmt->execute());
|
||||
} catch (Exception $e) {
|
||||
Response::api($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
switch ($method) {
|
||||
case "GET":
|
||||
if (Auth::hasPermission("read")) return get();
|
||||
break;
|
||||
case "PUT":
|
||||
if (Auth::hasPermission("write")) return put();
|
||||
break;
|
||||
default:
|
||||
return Response::api("$method not supported", 500);
|
||||
}
|
||||
|
||||
return Response::api("Not allowed", 401);
|
||||
|
||||
function get()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
$query =
|
||||
"SELECT
|
||||
*
|
||||
FROM
|
||||
Users";
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->execute();
|
||||
|
||||
Response::api($stmt->fetchAll());
|
||||
}
|
||||
|
||||
function put()
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
$_PUT = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
$query =
|
||||
"INSERT INTO
|
||||
Users(FirstName, LastName, Token)
|
||||
VALUES(:FIRST, :LAST, UUID())";
|
||||
|
||||
try {
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(":FIRST", $_PUT["firstName"]);
|
||||
$stmt->bindValue(":LAST", $_PUT["lastName"]);
|
||||
|
||||
Response::api($stmt->execute());
|
||||
} catch (Exception $e) {
|
||||
Response::api($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
Order deny,allow
|
||||
Deny from all
|
||||
Allow from 127.0.0.1
|
||||
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
if (strpos($_SERVER["REQUEST_URI"], "api") === false) {
|
||||
ini_set("display_errors", 1);
|
||||
}
|
||||
ini_set("default_charset", "utf-8");
|
||||
ini_set('session.cookie_httponly', 1);
|
||||
ini_set('session.cookie_secure', 1);
|
||||
ini_set('session.use_only_cookies', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once __DIR__ . "/../vendor/autoloader.php";
|
||||
Headers::html();
|
||||
|
||||
require_once __DIR__ . "/../routes/routes.php";
|
||||
@ -1,3 +0,0 @@
|
||||
Order deny,allow
|
||||
Deny from all
|
||||
Allow from 127.0.0.1
|
||||
@ -1,5 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
"basePath" => "phpCourse/exam/",
|
||||
];
|
||||
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
"host" => "usersql.zedat.fu-berlin.de",
|
||||
"user" => "khofmann-sql",
|
||||
"passwd" => "xz8c7m7p",
|
||||
"database" => "khofmann-db1",
|
||||
"charset" => "utf8",
|
||||
];
|
||||
@ -1,3 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once "./app/app.php";
|
||||
@ -1,14 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/phpCourse/exam/pages/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + React + TS</title>
|
||||
<script type="module" crossorigin src="/phpCourse/exam/pages/assets/index-D81sf-ye.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/phpCourse/exam/pages/assets/index-DiwrgTda.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
@ -1,3 +0,0 @@
|
||||
Order deny,allow
|
||||
Deny from all
|
||||
Allow from 127.0.0.1
|
||||
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
$path = ltrim(str_replace(Config::getBasePath(), "", $_SERVER['REQUEST_URI']), "/");
|
||||
|
||||
try {
|
||||
$segments = PathParams::get();
|
||||
|
||||
if ($segments[0] === "api") {
|
||||
if ($segments[1] !== "docs") {
|
||||
require_once __DIR__ . "/../api/{$segments[1]}/index.php";
|
||||
} else {
|
||||
Headers::redirect("index.html");
|
||||
}
|
||||
} else {
|
||||
require_once __DIR__ . "/../pages/index.html";
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
require_once __DIR__ . "/../pages/500.php";
|
||||
}
|
||||
3
exam2/vendor/.htaccess
vendored
@ -1,3 +0,0 @@
|
||||
Order deny,allow
|
||||
Deny from all
|
||||
Allow from 127.0.0.1
|
||||
28
exam2/vendor/auth/auth.php
vendored
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Auth
|
||||
{
|
||||
public static function hasPermission(string $required)
|
||||
{
|
||||
$db = Database::getInstance();
|
||||
|
||||
if (!isset($_SERVER["HTTP_TOKEN"])) return false;
|
||||
$token = $_SERVER["HTTP_TOKEN"];
|
||||
|
||||
$query =
|
||||
"SELECT
|
||||
UserPermissions.Permission
|
||||
FROM
|
||||
UserPermissions, Users
|
||||
WHERE
|
||||
Users.ID = UserPermissions.fkUserID AND
|
||||
Users.Token = :TOKEN";
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(":TOKEN", $token);
|
||||
$stmt->execute();
|
||||
$perms = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
|
||||
|
||||
return in_array($required, $perms);
|
||||
}
|
||||
}
|
||||
7
exam2/vendor/autoloader.php
vendored
@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
spl_autoload_register(function ($name) {
|
||||
$_name = lcfirst($name);
|
||||
|
||||
require_once __DIR__ . "/$_name/$_name.php";
|
||||
});
|
||||
44
exam2/vendor/config/config.php
vendored
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Config
|
||||
{
|
||||
private static array $instances = [];
|
||||
|
||||
private array $app;
|
||||
private array $database;
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
$this->app = require_once __DIR__ . "/../../config/app.php";
|
||||
$this->database = require_once __DIR__ . "/../../config/database.php";
|
||||
}
|
||||
|
||||
protected function __clone()
|
||||
{
|
||||
}
|
||||
|
||||
public function __wakeup()
|
||||
{
|
||||
throw new \Exception("Cannot unserialize a singleton.");
|
||||
}
|
||||
|
||||
private static function getInstance(): Config
|
||||
{
|
||||
$cls = static::class;
|
||||
if (!isset(self::$instances[$cls])) {
|
||||
self::$instances[$cls] = new static();
|
||||
}
|
||||
|
||||
return self::$instances[$cls];
|
||||
}
|
||||
|
||||
public static function getBasePath()
|
||||
{
|
||||
return Config::getInstance()->app["basePath"];
|
||||
}
|
||||
|
||||
public static function getDatabase()
|
||||
{
|
||||
return Config::getInstance()->database;
|
||||
}
|
||||
}
|
||||
32
exam2/vendor/database/database.php
vendored
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Database extends PDO
|
||||
{
|
||||
private static array $instances = [];
|
||||
|
||||
protected function __construct($dsn, $username = null, $password = null, array $options = null)
|
||||
{
|
||||
parent::__construct($dsn, $username, $password, $options);
|
||||
}
|
||||
|
||||
public static function getInstance(): Database
|
||||
{
|
||||
$cls = static::class;
|
||||
if (!isset(self::$instances[$cls])) {
|
||||
$dataAccess = Config::getDatabase();
|
||||
self::$instances[$cls] = new static(
|
||||
"mysql:host={$dataAccess["host"]};dbname={$dataAccess["database"]};charset={$dataAccess["charset"]}",
|
||||
$dataAccess["user"],
|
||||
$dataAccess["passwd"],
|
||||
[
|
||||
PDO::ATTR_PERSISTENT => false,
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return self::$instances[$cls];
|
||||
}
|
||||
}
|
||||
22
exam2/vendor/headers/headers.php
vendored
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Headers
|
||||
{
|
||||
public static function json()
|
||||
{
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
header("Content-Type: text/json");
|
||||
}
|
||||
|
||||
public static function html()
|
||||
{
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
}
|
||||
|
||||
public static function redirect(string $newUrl, bool $permanent = FALSE)
|
||||
{
|
||||
header('Location: ' . $newUrl, true, $permanent ? 301 : 303);
|
||||
|
||||
exit();
|
||||
}
|
||||
}
|
||||
11
exam2/vendor/pathParams/pathParams.php
vendored
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
class PathParams
|
||||
{
|
||||
public static function get()
|
||||
{
|
||||
$path = ltrim(str_replace(Config::getBasePath(), "", $_SERVER['REQUEST_URI']), "/");
|
||||
$segs = explode("/", $path);
|
||||
return $segs ? $segs : [];
|
||||
}
|
||||
}
|
||||
11
exam2/vendor/response/response.php
vendored
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Response
|
||||
{
|
||||
public static function api($content, int $code = 200)
|
||||
{
|
||||
Headers::json();
|
||||
http_response_code($code);
|
||||
echo json_encode($content);
|
||||
}
|
||||
}
|
||||