From c2419c36fad71bb8848bd6f5f9e9aad571041fff Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Tue, 10 Aug 2021 15:52:47 +0100 Subject: [PATCH] created containerfile and reorganised src files into src directory --- Containerfile | 7 +++ core/init/loader.php | 4 +- public/index.php | 3 -- src/.htaccess | 4 ++ {core => src/core}/db/db.php | 0 {core => src/core}/init.php | 6 +-- {core => src/core}/init/core.php | 29 ++++++++---- {core => src/core}/init/errors.php | 0 src/core/init/loader.php | 47 +++++++++++++++++++ {core => src/core}/init/responder.php | 10 ++++ {core => src/core}/init/user.php | 0 index.php => src/index.php | 4 +- {public => src/public}/error.php | 0 {public => src/public}/respond.php | 0 {public => src/public}/unauthorized.php | 0 .../sample-config}/config.sample.ini | 0 .../sample-config}/services.sample.ini | 0 17 files changed, 97 insertions(+), 17 deletions(-) create mode 100644 Containerfile delete mode 100644 public/index.php create mode 100644 src/.htaccess rename {core => src/core}/db/db.php (100%) rename {core => src/core}/init.php (90%) rename {core => src/core}/init/core.php (69%) rename {core => src/core}/init/errors.php (100%) create mode 100644 src/core/init/loader.php rename {core => src/core}/init/responder.php (89%) rename {core => src/core}/init/user.php (100%) rename index.php => src/index.php (53%) rename {public => src/public}/error.php (100%) rename {public => src/public}/respond.php (100%) rename {public => src/public}/unauthorized.php (100%) rename {config => src/sample-config}/config.sample.ini (100%) rename {config => src/sample-config}/services.sample.ini (100%) diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..f2a44ed --- /dev/null +++ b/Containerfile @@ -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 diff --git a/core/init/loader.php b/core/init/loader.php index b16e1d3..d333bce 100644 --- a/core/init/loader.php +++ b/core/init/loader.php @@ -35,8 +35,8 @@ class Loader { public function get_page_name(){ $uri = Core::get_get_data(); $page = "/none"; - if(isset($uri["page"])){ - $page = parse_url($uri["page"]); + if(isset($uri["path"])){ + $page = parse_url($uri["path"]); $page = $page["path"]; } return $page; diff --git a/public/index.php b/public/index.php deleted file mode 100644 index cea0619..0000000 --- a/public/index.php +++ /dev/null @@ -1,3 +0,0 @@ -start(); diff --git a/src/.htaccess b/src/.htaccess new file mode 100644 index 0000000..36b5b0b --- /dev/null +++ b/src/.htaccess @@ -0,0 +1,4 @@ +RewriteEngine on +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA] diff --git a/core/db/db.php b/src/core/db/db.php similarity index 100% rename from core/db/db.php rename to src/core/db/db.php diff --git a/core/init.php b/src/core/init.php similarity index 90% rename from core/init.php rename to src/core/init.php index 55124af..2239eba 100644 --- a/core/init.php +++ b/src/core/init.php @@ -1,6 +1,6 @@ Name)){ - return "Login"; - } else { - return self::$CurrentPage->Name; - } - } + public static function get_post_data(){ $data = []; foreach($_POST as $key=>$value){ @@ -48,10 +42,29 @@ } } 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); } else { 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; + } } diff --git a/core/init/errors.php b/src/core/init/errors.php similarity index 100% rename from core/init/errors.php rename to src/core/init/errors.php diff --git a/src/core/init/loader.php b/src/core/init/loader.php new file mode 100644 index 0000000..8255be7 --- /dev/null +++ b/src/core/init/loader.php @@ -0,0 +1,47 @@ +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; + } +} diff --git a/core/init/responder.php b/src/core/init/responder.php similarity index 89% rename from core/init/responder.php rename to src/core/init/responder.php index 8671c08..5579370 100644 --- a/core/init/responder.php +++ b/src/core/init/responder.php @@ -25,6 +25,9 @@ class Responder { case "get/all": $resp = $this->all_urls(); break; + case "get/select": + $resp = $this->selection(); + break; case "none": case "test": case "home": @@ -51,6 +54,13 @@ class Responder { 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(){ // Generate a dummy response for testing $response = new Response(); diff --git a/core/init/user.php b/src/core/init/user.php similarity index 100% rename from core/init/user.php rename to src/core/init/user.php diff --git a/index.php b/src/index.php similarity index 53% rename from index.php rename to src/index.php index 0dedf26..37ad07f 100644 --- a/index.php +++ b/src/index.php @@ -1,3 +1,5 @@ start(); diff --git a/public/error.php b/src/public/error.php similarity index 100% rename from public/error.php rename to src/public/error.php diff --git a/public/respond.php b/src/public/respond.php similarity index 100% rename from public/respond.php rename to src/public/respond.php diff --git a/public/unauthorized.php b/src/public/unauthorized.php similarity index 100% rename from public/unauthorized.php rename to src/public/unauthorized.php diff --git a/config/config.sample.ini b/src/sample-config/config.sample.ini similarity index 100% rename from config/config.sample.ini rename to src/sample-config/config.sample.ini diff --git a/config/services.sample.ini b/src/sample-config/services.sample.ini similarity index 100% rename from config/services.sample.ini rename to src/sample-config/services.sample.ini