-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-> Bump packages -> Starting to create a firewall -> Finish registration -> Added turnstile -> Added a nice template for the framework -> Wrote the basics of the api -> Extended the api to be better -> Added an option to show or hide errors via debugger -> Rewrote the template :)) -> Added a easy page.twig that everyone can base on components to build new pages :)
- Loading branch information
Showing
170 changed files
with
9,786 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
use MythicalSystems\Api\Api as api; | ||
use MythicalSystemsFramework\User\UserHelper; | ||
|
||
api::init(); | ||
api::allowOnlyGET(); | ||
if (isset($_GET['info']) && !$_GET['info'] == '') { | ||
if (isset($_GET['value']) && !$_GET['value'] == '') { | ||
$info = $_GET['info']; | ||
$value = $_GET['value']; | ||
$user = UserHelper::doesInfoAboutExist($info, $value); | ||
if ($user == 'INFO_EXISTS') { | ||
api::OK('The info exists!', ['RESULT' => $user]); | ||
} elseif ($user == 'INFO_NOT_FOUND') { | ||
api::BadRequest('The info does not exist!', ['RESULT' => $user]); | ||
} | ||
} else { | ||
api::BadRequest('You are missing the post field for value!', []); | ||
} | ||
} else { | ||
api::BadRequest('You are missing the post field for info!', []); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,3 @@ | |
|
||
api::init(); | ||
api::allowOnlyPOST(); | ||
|
||
if (isset($_POST['email']) && isset($_POST['password'])) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
use MythicalSystemsFramework\Api\Api as api; | ||
use MythicalSystemsFramework\Kernel\Debugger; | ||
use MythicalSystemsFramework\Mail\MailService; | ||
use MythicalSystemsFramework\User\UserHelper as user; | ||
use MythicalSystemsFramework\Handlers\ActivityHandler; | ||
|
||
api::init(); | ||
api::allowOnlyPOST(); | ||
|
||
// Hide all errors | ||
Debugger::HideAllErrors(); | ||
try { | ||
if (isset($_POST['username'])) { | ||
api::makeSureValueIsNotNull($_POST['username'], ['message' => 'You are missing the post field for username!']); | ||
} else { | ||
api::BadRequest('You are missing the post field for username!', []); | ||
} | ||
|
||
if (isset($_POST['password'])) { | ||
api::makeSureValueIsNotNull($_POST['password'], ['message' => 'You are missing the post field for password!']); | ||
} else { | ||
api::BadRequest('You are missing the post field for password!', []); | ||
} | ||
|
||
if (isset($_POST['email'])) { | ||
api::makeSureValueIsNotNull($_POST['email'], ['message' => 'You are missing the post field for email!']); | ||
} else { | ||
api::BadRequest('You are missing the post field for email!', []); | ||
} | ||
|
||
if (isset($_POST['first_name'])) { | ||
api::makeSureValueIsNotNull($_POST['first_name'], ['message' => 'You are missing the post field for first_name!']); | ||
} else { | ||
api::BadRequest('You are missing the post field for first_name!', []); | ||
} | ||
|
||
if (isset($_POST['last_name'])) { | ||
api::makeSureValueIsNotNull($_POST['last_name'], ['message' => 'You are missing the post field for last_name!']); | ||
} else { | ||
api::BadRequest('You are missing the post field for last_name!', []); | ||
} | ||
|
||
$user = user::create($_POST['username'], $_POST['password'], $_POST['email'], $_POST['first_name'], $_POST['last_name'], MythicalSystems\CloudFlare\CloudFlare::getRealUserIP()); | ||
|
||
if ($user == 'ERROR_USERNAME_EXISTS') { | ||
api::BadRequest('The username exists!', ['RESULT' => $user]); | ||
} elseif ($user == 'ERROR_EMAIL_EXISTS') { | ||
api::BadRequest('The email exists!', ['RESULT' => $user]); | ||
} elseif ($user == 'ERROR_DATABASE_INSERT_FAILED') { | ||
api::BadRequest('Failed to insert the user into the database!', ['RESULT' => $user]); | ||
} else { | ||
$user_id = user::getSpecificUserData($user, 'uuid', false); | ||
if (MailService::isEnabled() == true) { | ||
// TODO: Add a verify system | ||
} else { | ||
user::updateSpecificUserData($user, 'verified', 'true'); | ||
ActivityHandler::addActivity($user_id, user::getSpecificUserData($user, 'username', false), 'User created an account!', MythicalSystems\CloudFlare\CloudFlare::getRealUserIP(), 'USER_CREATED'); | ||
ActivityHandler::addActivity($user_id, user::getSpecificUserData($user, 'username', false), 'User verified his account!', MythicalSystems\CloudFlare\CloudFlare::getRealUserIP(), 'USER_VERIFIED'); | ||
} | ||
api::OK('The user has been created!', ['TOKEN' => $user]); | ||
} | ||
} catch (Exception $e) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace MythicalSystemsFramework\Api; | ||
|
||
class Api extends \MythicalSystems\Api\Api | ||
{ | ||
public static function makeSureValueIsNotNull(string $info, ?array $array): void | ||
{ | ||
if (!$info == '') { | ||
return; | ||
} else { | ||
self::BadRequest("You are missing the field for $info!", $array); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace MythicalSystemsFramework; | ||
|
||
class App extends \MythicalSystems\Main | ||
{ | ||
/** | ||
* Convert a string to a bool. | ||
*/ | ||
public static function convertStringToBool(string $value): bool | ||
{ | ||
if ($value == 'true') { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace MythicalSystemsFramework\CloudFlare; | ||
|
||
class CloudFlare extends \MythicalSystems\CloudFlare\CloudFlare | ||
{ | ||
/** | ||
* Get the ip of a user. | ||
* | ||
* @return string|null The ipv4 or ipv6 or null incase if the ip is not valid or was tampered with! | ||
*/ | ||
public static function getUserIP(): ?string | ||
{ | ||
$ip = \MythicalSystems\CloudFlare\CloudFlare::getRealUserIP(); | ||
// Check if the ip is valid | ||
if (filter_var($ip, FILTER_VALIDATE_IP)) { | ||
return $ip; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* DEPRECATED: Use getUserIP() instead. | ||
*/ | ||
public static function getRealUserIP(): string | ||
{ | ||
return self::getUserIP(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace MythicalSystemsFramework\CloudFlare; | ||
|
||
use MythicalSystemsFramework\App; | ||
use MythicalSystemsFramework\Managers\Settings as setting; | ||
|
||
class TurnStile extends \MythicalSystems\CloudFlare\Turnstile | ||
{ | ||
/** | ||
* Is cloudflare turnstile enabled? | ||
*/ | ||
public static function isEnabled(): bool | ||
{ | ||
return App::convertStringToBool(setting::getSetting('cloudflare_turnstile', 'enabled')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace MythicalSystemsFramework\Firewall; | ||
|
||
interface Events | ||
{ | ||
public const DROP = 'drop'; | ||
public const ALLOW = 'allow'; | ||
public const NONE = 'none'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
namespace MythicalSystemsFramework\Firewall; | ||
|
||
use MythicalSystemsFramework\Kernel\Logger; | ||
use MythicalSystemsFramework\Database\MySQL; | ||
use MythicalSystemsFramework\Kernel\LoggerTypes; | ||
use MythicalSystemsFramework\Kernel\LoggerLevels; | ||
use MythicalSystemsFramework\CloudFlare\CloudFlare; | ||
|
||
class Firewall extends CloudFlare implements Types | ||
{ | ||
/** | ||
* Check if a ip is allowed to pass! | ||
* | ||
* @param string|null $ip The ip of the user <3 | ||
* | ||
* @return string (DROP|NONE|ALLOW|DATABASE_ERROR) | ||
*/ | ||
public static function check(?string $ip): string | ||
{ | ||
$mysql = new MySQL(); | ||
$conn = $mysql->connectMYSQLI(); | ||
|
||
$stmt = $conn->prepare('SELECT * FROM framework_firewall WHERE ip = ?'); | ||
$stmt->bind_param('s', $ip); | ||
$stmt->execute(); | ||
$result = $stmt->get_result(); | ||
$stmt->close(); | ||
|
||
if ($result->num_rows > 0) { | ||
$row = $result->fetch_assoc(); | ||
$action = $row['action']; | ||
|
||
if ($action === 'DROP' || $action === 'NONE' || $action === 'ALLOW') { | ||
return $action; | ||
} else { | ||
return 'DATABASE_ERROR'; | ||
} | ||
} else { | ||
self::addIP($ip); | ||
|
||
return 'NONE'; | ||
} | ||
} | ||
|
||
/** | ||
* Add an ip to the database. | ||
* | ||
* @param string $ip The ip of the user <3 | ||
* | ||
* @return string The status of the operation. (IP_ADDED/DATABASE_ERROR) | ||
*/ | ||
public static function addIP(string $ip): string | ||
{ | ||
try { | ||
$mysql = new MySQL(); | ||
$conn = $mysql->connectMYSQLI(); | ||
|
||
$stmt = $conn->prepare('INSERT INTO framework_firewall (ip, action) VALUES (?, ?)'); | ||
$type = Types::NONE; | ||
$stmt->bind_param('ss', $ip, $type); | ||
$stmt->execute(); | ||
$stmt->close(); | ||
|
||
return 'IP_ADDED'; | ||
} catch (\Exception $e) { | ||
Logger::log(LoggerTypes::DATABASE, LoggerLevels::ERROR, '(App/Firewall/Firewall.php) Failed to insert ip into database: ' . $e->__toString()); | ||
|
||
return 'DATABASE_ERROR'; | ||
} | ||
} | ||
|
||
/** | ||
* Assign a owner for a ip address! | ||
*/ | ||
public static function assignOwnership(string $ip, string $uuid): string | ||
{ | ||
try { | ||
if (self::check($ip) === 'NONE') { | ||
} | ||
$mysql = new MySQL(); | ||
$conn = $mysql->connectMYSQLI(); | ||
|
||
$stmt = $conn->prepare('UPDATE framework_firewall SET owner = ? WHERE ip = ?'); | ||
$stmt->bind_param('ss', $uuid, $ip); | ||
$stmt->execute(); | ||
$stmt->close(); | ||
|
||
return 'OWNER_ASSIGNED'; | ||
} catch (\Exception $e) { | ||
Logger::log(LoggerTypes::DATABASE, LoggerLevels::ERROR, '(App/Firewall/Firewall.php) Failed to assign ownership to ip: ' . $e->__toString()); | ||
|
||
return 'DATABASE_ERROR'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace MythicalSystemsFramework\Firewall; | ||
|
||
interface Types extends Events | ||
{ | ||
public const IP = 'ip'; | ||
public const USER_AGENT = 'user_agent'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace MythicalSystemsFramework\Mail; | ||
|
||
use MythicalSystemsFramework\Managers\Settings as setting; | ||
|
||
class MailService | ||
{ | ||
/** | ||
* Is the mail server enabled? | ||
*/ | ||
public static function isEnabled(): bool | ||
{ | ||
if (setting::getSetting('mail', 'enabled') == 'true') { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.