created containerfile and reorganised src files into src directory
This commit is contained in:
parent
e6149ec3db
commit
c2419c36fa
17 changed files with 97 additions and 17 deletions
7
Containerfile
Normal file
7
Containerfile
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
FROM php:7.4-apache
|
||||||
|
|
||||||
|
COPY src/ /var/www/html/
|
||||||
|
|
||||||
|
# Use the default production configuration
|
||||||
|
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
|
||||||
|
RUN a2enmod rewrite
|
|
@ -35,8 +35,8 @@ class Loader {
|
||||||
public function get_page_name(){
|
public function get_page_name(){
|
||||||
$uri = Core::get_get_data();
|
$uri = Core::get_get_data();
|
||||||
$page = "/none";
|
$page = "/none";
|
||||||
if(isset($uri["page"])){
|
if(isset($uri["path"])){
|
||||||
$page = parse_url($uri["page"]);
|
$page = parse_url($uri["path"]);
|
||||||
$page = $page["path"];
|
$page = $page["path"];
|
||||||
}
|
}
|
||||||
return $page;
|
return $page;
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
<?php include("core/init.php");
|
|
||||||
$b = new StartUp();
|
|
||||||
$b->start();
|
|
4
src/.htaccess
Normal file
4
src/.htaccess
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
RewriteEngine on
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
|
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
// this class starts the whole thing going.
|
// this class starts the whole thing going.
|
||||||
class StartUp {
|
class Init {
|
||||||
public function start (){
|
public function start (){
|
||||||
// define a constant for checking later on
|
// define a constant for checking later on
|
||||||
define("LETSGO",true);
|
define("LETSGO",true);
|
||||||
|
@ -29,7 +29,7 @@ class StartUp {
|
||||||
// YOU REALLY SHOULD HAVE YOUR OWN CONFIG FILE!!!
|
// YOU REALLY SHOULD HAVE YOUR OWN CONFIG FILE!!!
|
||||||
|
|
||||||
if (!file_exists($config)) {
|
if (!file_exists($config)) {
|
||||||
$config = Core::root_dir()."/config/config.sample.ini";
|
$config = Core::root_dir()."/sample-config/config.sample.ini";
|
||||||
}
|
}
|
||||||
|
|
||||||
// define services file location
|
// define services file location
|
||||||
|
@ -39,7 +39,7 @@ class StartUp {
|
||||||
// YOU REALLY SHOULD HAVE YOUR OWN SERVICES FILE!!!
|
// YOU REALLY SHOULD HAVE YOUR OWN SERVICES FILE!!!
|
||||||
|
|
||||||
if (!file_exists($services)) {
|
if (!file_exists($services)) {
|
||||||
$services = Core::root_dir()."/config/services.sample.ini";
|
$services = Core::root_dir()."/sample-config/services.sample.ini";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the config settings in the Core::Config variable
|
// Store the config settings in the Core::Config variable
|
|
@ -4,13 +4,7 @@
|
||||||
public static function root_dir(){
|
public static function root_dir(){
|
||||||
return $_SERVER['DOCUMENT_ROOT'];
|
return $_SERVER['DOCUMENT_ROOT'];
|
||||||
}
|
}
|
||||||
public static function get_current_page_name(){
|
|
||||||
if (!isset(self::$CurrentPage->Name)){
|
|
||||||
return "Login";
|
|
||||||
} else {
|
|
||||||
return self::$CurrentPage->Name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static function get_post_data(){
|
public static function get_post_data(){
|
||||||
$data = [];
|
$data = [];
|
||||||
foreach($_POST as $key=>$value){
|
foreach($_POST as $key=>$value){
|
||||||
|
@ -48,10 +42,29 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static function get_current_git_commit( $branch='master' ) {
|
public static function get_current_git_commit( $branch='master' ) {
|
||||||
if ( $hash = file_get_contents( sprintf( '.git/refs/heads/%s', $branch ) ) ) {
|
$gitref = sprintf( self::root_dir().'/../.git/refs/heads/%s', $branch );
|
||||||
|
if ( file_exists($gitref) && $hash = file_get_contents( $gitref ) ) {
|
||||||
return trim($hash);
|
return trim($hash);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static function full_url(){
|
||||||
|
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
|
||||||
|
$addr = "https";
|
||||||
|
} else {
|
||||||
|
$addr = "http";
|
||||||
|
}
|
||||||
|
// Here append the common URL characters.
|
||||||
|
$addr .= "://";
|
||||||
|
|
||||||
|
// Append the host(domain name, ip) to the URL.
|
||||||
|
$addr .= $_SERVER['HTTP_HOST'];
|
||||||
|
|
||||||
|
// Append the requested resource location to the URL
|
||||||
|
$addr .= $_SERVER['REQUEST_URI'];
|
||||||
|
|
||||||
|
// Return the address
|
||||||
|
return $addr;
|
||||||
|
}
|
||||||
}
|
}
|
47
src/core/init/loader.php
Normal file
47
src/core/init/loader.php
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
require ("core.php");
|
||||||
|
require ("user.php");
|
||||||
|
require ("responder.php");
|
||||||
|
require ("errors.php");
|
||||||
|
class Loader {
|
||||||
|
public function request_page(){
|
||||||
|
// Check if user is authenticated and go to the relevant section
|
||||||
|
if (User::is_authenticated()){
|
||||||
|
$this->go_to_page(true);
|
||||||
|
} else {
|
||||||
|
$this->go_to_page(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function go_to_page($authenticated) {
|
||||||
|
switch ($authenticated) {
|
||||||
|
case false:
|
||||||
|
require(Core::root_dir()."/public/unauthorized.php");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$p = $this->get_page_name();
|
||||||
|
if (substr($p,0,6) != "/admin") {
|
||||||
|
header('Content-Type: application/json'); // <-- header declaration
|
||||||
|
}
|
||||||
|
if(substr($p,0,1) == "/") {
|
||||||
|
Core::$CurrentPage = substr($p,1);
|
||||||
|
} else {
|
||||||
|
Core::$CurrentPage = $p;
|
||||||
|
}
|
||||||
|
require_once(Core::root_dir()."/public/respond.php");
|
||||||
|
// } else {
|
||||||
|
// Core::$CurrentPage = "Error";
|
||||||
|
// require_once(Core::RootDir()."/public/error.php");
|
||||||
|
// }
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function get_page_name(){
|
||||||
|
$uri = Core::get_get_data();
|
||||||
|
$page = "/none";
|
||||||
|
if(isset($uri["path"])){
|
||||||
|
$page = parse_url($uri["path"]);
|
||||||
|
$page = $page["path"];
|
||||||
|
}
|
||||||
|
return $page;
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,6 +25,9 @@ class Responder {
|
||||||
case "get/all":
|
case "get/all":
|
||||||
$resp = $this->all_urls();
|
$resp = $this->all_urls();
|
||||||
break;
|
break;
|
||||||
|
case "get/select":
|
||||||
|
$resp = $this->selection();
|
||||||
|
break;
|
||||||
case "none":
|
case "none":
|
||||||
case "test":
|
case "test":
|
||||||
case "home":
|
case "home":
|
||||||
|
@ -51,6 +54,13 @@ class Responder {
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
private function selection(){
|
||||||
|
$response = new Response();
|
||||||
|
$response->message = "Not Implemented";
|
||||||
|
$uri = Core::full_url();
|
||||||
|
$response->payload = parse_url($uri);
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
private function dummy_response(){
|
private function dummy_response(){
|
||||||
// Generate a dummy response for testing
|
// Generate a dummy response for testing
|
||||||
$response = new Response();
|
$response = new Response();
|
|
@ -1,3 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
// entry point - inport and run the public index.php file
|
// entry point - inport and run the public index.php file
|
||||||
require("public/index.php");
|
include("core/init.php");
|
||||||
|
$b = new Init();
|
||||||
|
$b->start();
|
Loading…
Reference in a new issue