Initial commit

This commit is contained in:
Rayhan Hanaputra
2025-10-10 22:18:06 +07:00
committed by GitHub
commit ea02892f14
1246 changed files with 289342 additions and 0 deletions
@@ -0,0 +1,13 @@
<?php
namespace Controllers;
class ErrorController {
public function notFound(){
echo 'not found';
}
}
@@ -0,0 +1,19 @@
<?php
namespace Controllers;
class IndexController {
private $tpl;
public function __construct() {
}
public function main() {
$this->tpl = new \utils\template(VIEW . 'index.tpl');
$this->tpl->render(["test"=>"foo"]);
}
}
@@ -0,0 +1,53 @@
<?php
namespace Controllers;
class PageController {
private $file;
private $userData;
private $util;
public function __construct() {
$this->util = new \utils\util();
$this->file = new \models\fileModel();
$this->userData = $_SESSION['userData'];
if(!isset($this->userData)) $this->util->alertExit("Login Dulu bang!!");
}
public function samplePage() {
$this->file->copyFile(ROOT . 'public/sample.html', ROOT . 'user/' . $this->userData['uuid'] . '/' . $this->userData['uuid'] . '.html');
$this->file->copyFile(ROOT . 'public/sample.js', ROOT . 'user/' . $this->userData['uuid'] . '/' . $this->userData['uuid'] . '.js');
$this->file->copyFile(ROOT . 'public/sample.css', ROOT . 'user/' . $this->userData['uuid'] . '/' . $this->userData['uuid'] . '.css');
$this->util->alertExit("Create Success");
}
public function viewPage() {
$tpl = new \utils\template(VIEW . 'page.tpl');
$tpl->render([
"script" => './user/' . $this->userData['uuid'] . '/' . $this->userData['uuid'] . '.js',
"css" => './user/' . $this->userData['uuid'] . '/' . $this->userData['uuid'] . '.css',
"html" => $this->file->getFile(ROOT . 'user/' . $this->userData['uuid'] . '/' . $this->userData['uuid'] . '.html')
]);
}
public function edit() {
if(!in_array($_REQUEST['type'], ['html', 'js', 'css'])) $this->util->alertExit("Invalid type");
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$this->file->createFile(ROOT . 'user/' . $this->userData['uuid'] . '/' . $this->userData['uuid'] . '.' . $_POST['type'], $_POST['data']);
$this->util->alertExit("Edit Success");
}
$tpl = new \utils\template(VIEW . 'textarea.tpl');
$tpl->render(["type" => $_GET['type'], "data" => $this->file->getFile(ROOT . 'user/' . $this->userData['uuid'] . '/' . $this->userData['uuid'] . '.' . $_GET['type'])]);
}
}
@@ -0,0 +1,76 @@
<?php
namespace Controllers;
class UserController {
private $file;
private $user;
private $util;
public function __construct() {
$this->util = new \utils\util();
$this->file = new \models\fileModel();
$this->user = new \models\userModel($this->file);
}
public function login() {
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$_POST['username'] = str_replace(array('.', '/', '\\'), '_', $_POST['username']);
if(empty($_POST['username']) || empty($_POST['password']))
$this->util->alertExit("username or password is empty");
$userData = $this->user->getUserByUsername($_POST['username']);
$hPassword = hash("sha256", $_POST['password']);
if($userData['password'] == $hPassword)
$_SESSION['userData'] = $userData;
else
$this->util->alertExit("username or password is wrong");
$this->util->alertExit("Login Success");
}
$tpl = new \utils\template(VIEW . 'login.tpl');
$tpl->render([]);
}
public function register() {
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$_POST['username'] = str_replace(array('.', '/', '\\'), '_', $_POST['username']);
if(empty($_POST['username']) || empty($_POST['password']))
$this->util->alertExit("username or password is empty");
if(strlen($_POST['username']) < 10)
$this->util->alertExit("username length must be greater than 10");
$userData = $this->user->getUserByUsername($_POST['username']);
if($userData != null)
$this->util->alertExit("username already exists");
$this->user->createUser($_POST['username'], $_POST['password']);
$this->util->alertExit("Register Success");
}
$tpl = new \utils\template(VIEW . 'register.tpl');
$tpl->render([]);
}
public function logout() {
session_destroy();
$this->util->alertExit("Logout Success");
}
}
@@ -0,0 +1,23 @@
<?php
define('APP', ROOT . 'application/');
define('CORE', APP . 'core/');
define('CONT', APP . 'controllers/');
define('VIEW', APP . 'views/');
#ini_set('display_errors', 1);
function autoload($class) {
$class = str_replace('\\', '/', $class);
$classFilePath = APP . "$class.php";
if (file_exists($classFilePath)) {
require_once($classFilePath);
}
}
spl_autoload_register("autoload");
session_start();
@@ -0,0 +1,72 @@
<?php
namespace Core;
class Core {
private $module;
private $action;
private $instance;
public function __construct($module = null, $action = null) {
$this->module = $module;
$this->action = $action;
}
public function run(){
$this->init();
$this->getInstance();
$this->action();
}
public function init() {
$util = new \utils\util();
$_module = $_GET['module'];
$_action = $_GET['action'];
if(!isset($_module) && !isset($_action)){
$tmp = explode('/', $_SERVER['PATH_INFO']);
$_module = $tmp[1];
$_action = $tmp[2];
}
$this->module = $util->alphaNumeric($_module, 'index');
$this->action = $util->alphaNumeric($_action, 'main');
}
public function action() {
$_instance = $this->instance;
$_action = $this->action;
if(method_exists($_instance, $_action)){
$_instance->$_action();
}
}
public function getInstance() {
$_module = $this->module;
if(!file_exists(CONT . $_module . 'Controller.php')){
$_module = 'index';
$this->module = $_module;
$this->action = 'main';
}
$className = 'controllers\\' . $_module . 'Controller';
$this->instance = new $className();
}
}
@@ -0,0 +1,30 @@
<?php
namespace Models;
class FileModel {
public function __construct(){}
public function createFile($filePath, $fileContents){
return @file_put_contents($filePath, $fileContents);
}
public function getFile($filePath){
return @file_get_contents($filePath);
}
public function copyFile($filePathSrc, $filePathDst){
return copy($filePathSrc, $filePathDst);
}
public function createDir($dirPath){
return mkdir($dirPath, 0777);
}
}
@@ -0,0 +1,45 @@
<?php
namespace Models;
class UserModel {
private $file;
public function __construct($file){
$this->file = $file;
}
public function createUser($username, $password) {
$uuid = exec("uuid");
$hPassword = hash("sha256", $password);
$filePath = "/tmp/${username}.user";
$fileContents = "${uuid}|${hPassword}";
$this->file->createFile($filePath, $fileContents);
$this->file->createDir(ROOT . 'user/' . $uuid);
return array("uuid" => $uuid, "username" => $username, "password" => $hPassword);
}
public function getUserByUsername($username) {
$filePath = "/tmp/${username}.user";
$fileContents = $this->file->getFile($filePath);
if($fileContents == false)
return false;
$data = explode('|', $fileContents);
return array("uuid" => $data[0], "username" => $username, "password" => $data[1]);
}
}
@@ -0,0 +1,94 @@
<?php
namespace Utils;
class Template {
private $source;
private $stream;
private $assetsDir;
private $debug;
public function __construct($source = '') {
$this->debug = 0;
$this->source = $source;
$this->stream = file_get_contents($source);
$this->setAssetsDir(ROOT);
}
public function setSource($source) {
$this->source = $source;
$this->stream = file_get_contents($source);
}
public function load($data) {
foreach($data as $k => $v){
$this->stream = str_replace('{{'.$k.'}}', $v, $this->stream);
}
}
public function setAssetsDir($dir)
{
if (!empty($_SERVER['PATH_INFO'])) {
$dir = preg_replace('/\/index\.php\/\w+\/\w+\//', '', rtrim($_SERVER['REQUEST_URI'], '/') . '/');
$this->assetsDir = $dir;
return ;
}
$dir = rtrim($dir, '/') . '/';
$this->assetsDir = $dir;
}
public function fixPaths(){
$regexp = '!(src|href)=(["\']?)([a-z0-9/\:_.-]+)(["\'\s>])!i';
return preg_replace_callback($regexp, [$this, 'fileCallback'], $this->stream);
}
public function fileCallback($matches){
$file = $matches[3];
if (preg_match('/\.(js|css|less|ico|png|svg|jpeg)$/', $file)) {
$file = $this->fileMod($file);
}
return $matches[1] . '=' . $matches[2] . $file . $matches[4];
}
public function fileMod($file){
$time = 0;
if($file[0] != '/'){
if ($time = @filemtime($this->assetsDir . $file)) {
$file .= '?s=' . $time;
}
}
else{
if ($time = @filemtime(ROOT . $file)) {
$file .= '?s=' . $time;
}
}
return $file;
}
public function render($data) {
$this->load($data);
$this->stream = $this->fixPaths();
}
public function __destruct(){
if($this->debug) {
echo "========== DEBUG Start ==========\n";
echo file_get_contents($this->source);
echo "========== DEBUG End ==========\n";
}
echo $this->stream;
}
}
@@ -0,0 +1,23 @@
<?php
namespace Utils;
class Util {
public function isAlphaNumeric($str){
return preg_match("/^[a-zA-Z0-9]+$/", $str) ? true : false;
}
public function alphaNumeric($str, $default = ''){
return preg_match("/^[a-zA-Z0-9]+$/", $str) ? $str : $default;
}
public function alertExit($str, $back = 1){
echo "<script>alert(`$str`); window.location.href = '/';</script>; if($back) history.back();";
;
exit();
}
}
@@ -0,0 +1,96 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WONDERER PAGE</title>
<style>
body {
background: linear-gradient(135deg, #1f1f1f, #2c2c2c);
color: #fff;
font-family: 'Roboto', sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
padding: 0;
}
h1 {
font-size: 3em;
margin-bottom: 20px;
text-transform: uppercase;
letter-spacing: 5px;
}
a {
display: inline-block;
margin: 10px 20px;
padding: 10px 30px;
border-radius: 30px;
background: rgba(255, 255, 255, 0.1);
color: #fff;
text-decoration: none;
font-weight: bold;
transition: background 0.3s ease, color 0.3s ease;
}
a:hover {
background: #00b3ff;
color: #1f1f1f;
}
hr {
width: 80%;
margin: 30px 0;
border: 1px solid rgba(255, 255, 255, 0.1);
}
.edit-links {
display: flex;
justify-content: center;
gap: 15px;
margin-top: 20px;
}
.edit-links a {
background: #555;
}
.edit-links a:hover {
background: #ff007a;
}
@keyframes glow {
0% {
box-shadow: 0 0 5px #00b3ff, 0 0 10px #00b3ff, 0 0 20px #00b3ff, 0 0 40px #00b3ff;
}
100% {
box-shadow: 0 0 10px #ff007a, 0 0 20px #ff007a, 0 0 40px #ff007a, 0 0 80px #ff007a;
}
}
a:hover {
animation: glow 0.5s ease-in-out infinite alternate;
}
</style>
</head>
<body>
<h1>Dashboard</h1>
<a href="index.php?module=user&action=login">Login</a>
<a href="index.php?module=user&action=register">Register</a>
<a href="index.php?module=user&action=logout">Logout</a>
<br><hr>
<a href="index.php?module=page&action=samplePage">Create Sample Page</a>
<a href="index.php?module=page&action=viewPage">View Page</a>
<br><hr>
<div class="edit-links">
<span>Edit:</span>
<a href="index.php?module=page&action=edit&type=html">HTML</a>
<a href="index.php?module=page&action=edit&type=js">JS</a>
<a href="index.php?module=page&action=edit&type=css">CSS</a>
</div>
</body>
</html>
@@ -0,0 +1,80 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<style>
body {
background: linear-gradient(135deg, #0f0f0f, #2e2e2e);
color: #fff;
font-family: 'Roboto', sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
padding: 0;
}
h1 {
font-size: 2.5em;
margin-bottom: 20px;
text-transform: uppercase;
letter-spacing: 4px;
color: #00b3ff;
}
form {
background: rgba(255, 255, 255, 0.1);
padding: 20px 40px;
border-radius: 10px;
box-shadow: 0 0 15px rgba(0, 179, 255, 0.3);
text-align: center;
}
input[type="text"], input[type="password"] {
width: 100%;
padding: 10px;
margin: 10px 0;
border: none;
border-radius: 5px;
background: rgba(255, 255, 255, 0.2);
color: #fff;
font-size: 1em;
}
input[type="submit"] {
width: 100%;
padding: 10px;
border: none;
border-radius: 5px;
background: #00b3ff;
color: #fff;
font-size: 1em;
font-weight: bold;
cursor: pointer;
transition: background 0.3s ease, box-shadow 0.3s ease;
}
input[type="submit"]:hover {
background: #ff007a;
box-shadow: 0 0 10px #ff007a, 0 0 20px #ff007a, 0 0 40px #ff007a;
}
input[type="text"]:focus, input[type="password"]:focus {
background: rgba(255, 255, 255, 0.3);
outline: none;
}
</style>
</head>
<body>
<h1>Silahkan Login</h1>
<form action="" method="POST">
<input type="text" name="username" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<input type="submit" value="Login">
</form>
</body>
</html>
@@ -0,0 +1,116 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wonderer Your Page</title>
<script src="{{script}}"></script>
<link rel="stylesheet" href="{{css}}">
<style>
body {
background: linear-gradient(135deg, #101010, #303030);
color: #ffffff;
font-family: 'Roboto', sans-serif;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
}
h1, h2, h3 {
color: #00b3ff;
text-transform: uppercase;
margin: 20px 0;
text-align: center;
letter-spacing: 2px;
}
p, li {
font-size: 1.1em;
line-height: 1.6em;
margin: 10px 0;
color: #dddddd;
}
a {
color: #00b3ff;
text-decoration: none;
border-bottom: 1px solid rgba(0, 179, 255, 0.3);
transition: color 0.3s ease, border-bottom 0.3s ease;
}
a:hover {
color: #ff007a;
border-bottom: 1px solid rgba(255, 0, 122, 0.5);
}
button {
padding: 10px 20px;
border-radius: 5px;
background: #00b3ff;
color: #ffffff;
font-size: 1em;
font-weight: bold;
cursor: pointer;
border: none;
transition: background 0.3s ease, box-shadow 0.3s ease;
}
button:hover {
background: #ff007a;
box-shadow: 0 0 10px #ff007a, 0 0 20px #ff007a, 0 0 40px #ff007a;
}
input[type="text"], input[type="password"], textarea {
width: 100%;
padding: 10px;
margin: 10px 0;
border: none;
border-radius: 5px;
background: rgba(255, 255, 255, 0.1);
color: #ffffff;
font-size: 1em;
}
input[type="text"]:focus, input[type="password"]:focus, textarea:focus {
background: rgba(255, 255, 255, 0.2);
outline: none;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
table, th, td {
border: 1px solid rgba(255, 255, 255, 0.1);
padding: 10px;
text-align: left;
}
th {
background: #00b3ff;
color: #101010;
}
td {
background: rgba(255, 255, 255, 0.1);
}
th, td {
transition: background 0.3s ease;
}
td:hover {
background: rgba(255, 255, 255, 0.2);
}
</style>
</head>
<body>
{{html}}
</body>
</html>
@@ -0,0 +1,80 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register</title>
<style>
body {
background: linear-gradient(135deg, #141414, #282828);
color: #ffffff;
font-family: 'Roboto', sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
padding: 0;
}
h1 {
font-size: 2.5em;
margin-bottom: 20px;
text-transform: uppercase;
letter-spacing: 4px;
color: #00b3ff;
}
form {
background: rgba(255, 255, 255, 0.1);
padding: 20px 40px;
border-radius: 10px;
box-shadow: 0 0 15px rgba(0, 179, 255, 0.3);
text-align: center;
}
input[type="text"], input[type="password"] {
width: 100%;
padding: 10px;
margin: 10px 0;
border: none;
border-radius: 5px;
background: rgba(255, 255, 255, 0.2);
color: #ffffff;
font-size: 1em;
}
input[type="submit"] {
width: 100%;
padding: 10px;
border: none;
border-radius: 5px;
background: #00b3ff;
color: #ffffff;
font-size: 1em;
font-weight: bold;
cursor: pointer;
transition: background 0.3s ease, box-shadow 0.3s ease;
}
input[type="submit"]:hover {
background: #ff007a;
box-shadow: 0 0 10px #ff007a, 0 0 20px #ff007a, 0 0 40px #ff007a;
}
input[type="text"]:focus, input[type="password"]:focus {
background: rgba(255, 255, 255, 0.3);
outline: none;
}
</style>
</head>
<body>
<h1>Daftar</h1>
<form action="" method="POST">
<input type="text" name="username" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<input type="submit" value="Register">
</form>
</body>
</html>
@@ -0,0 +1,84 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit {{type}}</title>
<style>
body {
background: linear-gradient(135deg, #1a1a1a, #333333);
color: #ffffff;
font-family: 'Roboto', sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
margin: 0;
padding: 20px;
}
h1 {
font-size: 2.5em;
margin-bottom: 20px;
text-transform: uppercase;
letter-spacing: 4px;
color: #00b3ff;
}
form {
background: rgba(255, 255, 255, 0.1);
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 15px rgba(0, 179, 255, 0.3);
text-align: center;
width: 100%;
max-width: 900px;
}
textarea {
width: 100%;
padding: 15px;
margin: 10px 0;
border: none;
border-radius: 5px;
background: rgba(255, 255, 255, 0.2);
color: #ffffff;
font-size: 1em;
font-family: 'Courier New', Courier, monospace;
resize: vertical;
}
textarea:focus {
background: rgba(255, 255, 255, 0.3);
outline: none;
}
input[type="submit"] {
padding: 10px 20px;
border: none;
border-radius: 5px;
background: #00b3ff;
color: #ffffff;
font-size: 1em;
font-weight: bold;
cursor: pointer;
transition: background 0.3s ease, box-shadow 0.3s ease;
margin-top: 20px;
}
input[type="submit"]:hover {
background: #ff007a;
box-shadow: 0 0 10px #ff007a, 0 0 20px #ff007a, 0 0 40px #ff007a;
}
</style>
</head>
<body>
<h1>Edit {{type}}</h1>
<form action="" method="POST">
<textarea name="data" cols="100" rows="20">{{data}}</textarea><br>
<input type="hidden" name="type" value="{{type}}">
<input type="submit" value="Save">
</form>
</body>
</html>