diff --git a/phpmvc/1.0/README.md b/phpmvc/1.0/README.md new file mode 100644 index 000000000..0eb9d898b --- /dev/null +++ b/phpmvc/1.0/README.md @@ -0,0 +1,31 @@ +# php MVC环境 + + + +## 0x01 Poc1 +._Upload_index.php + +![](README/E1824D20-553E-48E1-A2BD-9DE3EE778560.png) + +http://127.0.0.1/Upload/index.php abcde10db05bd4f6a24c94d7edde441d18545 + +![](README/E742BF5A-8219-4E81-8421-9F1532B8419F.png) + +0x02 Poc2 + +后台sql注入漏洞 +http://127.0.0.1//?p=admin&a=login +拼接后的语句是 +SELECT email, password FROM Admins WHERE email = 'admin' and 1=1 -- @qq.com' LIMIT 0,1 + +也可以直接用sqlmap注入 +![](README/90374552-4DDE-46A8-B6FE-60A5E5D0A7AA.png) + + +![](README/7C7D1344-6039-4324-824D-981C92FA71E6.png) + + + + + +[CTF线下赛writeup&tinyblog代码审计](https://zhuanlan.zhihu.com/p/34552875) diff --git a/phpmvc/1.0/README/7C7D1344-6039-4324-824D-981C92FA71E6.png b/phpmvc/1.0/README/7C7D1344-6039-4324-824D-981C92FA71E6.png new file mode 100644 index 000000000..a2f3fe5f2 Binary files /dev/null and b/phpmvc/1.0/README/7C7D1344-6039-4324-824D-981C92FA71E6.png differ diff --git a/phpmvc/1.0/README/90374552-4DDE-46A8-B6FE-60A5E5D0A7AA.png b/phpmvc/1.0/README/90374552-4DDE-46A8-B6FE-60A5E5D0A7AA.png new file mode 100644 index 000000000..1f2b894ca Binary files /dev/null and b/phpmvc/1.0/README/90374552-4DDE-46A8-B6FE-60A5E5D0A7AA.png differ diff --git a/phpmvc/1.0/README/E1824D20-553E-48E1-A2BD-9DE3EE778560.png b/phpmvc/1.0/README/E1824D20-553E-48E1-A2BD-9DE3EE778560.png new file mode 100644 index 000000000..21fc7f11b Binary files /dev/null and b/phpmvc/1.0/README/E1824D20-553E-48E1-A2BD-9DE3EE778560.png differ diff --git a/phpmvc/1.0/README/E742BF5A-8219-4E81-8421-9F1532B8419F.png b/phpmvc/1.0/README/E742BF5A-8219-4E81-8421-9F1532B8419F.png new file mode 100644 index 000000000..d2df9cc73 Binary files /dev/null and b/phpmvc/1.0/README/E742BF5A-8219-4E81-8421-9F1532B8419F.png differ diff --git a/phpmvc/1.0/docker-compose.yml b/phpmvc/1.0/docker-compose.yml new file mode 100644 index 000000000..a9e2424f5 --- /dev/null +++ b/phpmvc/1.0/docker-compose.yml @@ -0,0 +1,7 @@ +version: '2' +services: + php5-phpmvc_1.0: + build: ./phpmvc + image: s1riu5/phpmvc:1.0 + ports: + - 80:80 diff --git a/phpmvc/1.0/phpmvc/Dockerfile b/phpmvc/1.0/phpmvc/Dockerfile new file mode 100644 index 000000000..3cda365b9 --- /dev/null +++ b/phpmvc/1.0/phpmvc/Dockerfile @@ -0,0 +1,7 @@ +FROM s1riu5/lnmp:5.6 + +COPY www /www +COPY db.sql /docker-entrypoint-initdb.d/ + +RUN chmod -R 777 /www + diff --git a/phpmvc/1.0/phpmvc/db.sql b/phpmvc/1.0/phpmvc/db.sql new file mode 100644 index 000000000..3d2007067 --- /dev/null +++ b/phpmvc/1.0/phpmvc/db.sql @@ -0,0 +1,47 @@ +-- +-- +-- Author Pierre-Henry Soria +-- Copyright (c) 2015-2017, Pierre-Henry Soria. All Rights Reserved. +-- License Lesser General Public License +-- Link http://hizup.uk +-- +-- + +-- +-- Set some SQL Variables -- +-- + +CREATE DATABASE IF NOT EXISTS `cp` default charset utf8 COLLATE utf8_general_ci; + +use cp; + +set sql_mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"; + +SET @sAdminEmail = 'test@test.com'; +SET @sAdminPassword = '$2y$14$kefF6aqkuOEWo7CIFduNf.7O8BuGR4uWrIAFcHWm2u99OcLPDFWOe'; +SET @sPostTitle = 'My First Post'; +SET @sPostBody = 'Hello! Here is my first blog post!!\r\n\r\n\r\nLorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim.\r\n\r\nDonec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus.\r\n\r\nAenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.\r\n\r\nEtiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante.\r\n\r\nEtiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, metus.\r\n\r\nNullam accumsan lorem in dui. Cras ultricies mi eu turpis hendrerit fringilla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer lacinia. Nam pretium turpis et arcu. Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Sed aliquam ultrices mauris. Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris. Praesent adipiscing. Phasellus ullamcorper ipsum rutrum nunc. Nunc nonummy metus. Vestibulum volutpat pretium libero. Cras id dui.'; +SET @sPostDate = NOW(); + + +CREATE TABLE IF NOT EXISTS Posts ( + id int(10) unsigned NOT NULL AUTO_INCREMENT, + title varchar(50) DEFAULT NULL, + body longtext NOT NULL, + createdDate datetime NOT NULL DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY (id) +) DEFAULT CHARSET=utf8; + +INSERT INTO Posts (title, body, createdDate) VALUES +(@sPostTitle, @sPostBody, @sPostDate); + + +CREATE TABLE IF NOT EXISTS Admins ( + id int(10) unsigned NOT NULL AUTO_INCREMENT, + email varchar(120) NOT NULL, + password char(60) NOT NULL, + PRIMARY KEY (id) +) DEFAULT CHARSET=utf8; + +INSERT INTO Admins (email, password) VALUES +(@sAdminEmail, @sAdminPassword); -- The admin password is: pwd123 diff --git a/phpmvc/1.0/phpmvc/www/.DS_Store b/phpmvc/1.0/phpmvc/www/.DS_Store new file mode 100644 index 000000000..6492ee3a7 Binary files /dev/null and b/phpmvc/1.0/phpmvc/www/.DS_Store differ diff --git a/phpmvc/1.0/phpmvc/www/.htaccess b/phpmvc/1.0/phpmvc/www/.htaccess new file mode 100755 index 000000000..e303c53a3 --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/.htaccess @@ -0,0 +1,12 @@ + +# BEGIN WordPress + +RewriteEngine On +RewriteBase / +RewriteRule ^index\.php$ - [L] +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule . /index.php [L] + + +# END WordPress \ No newline at end of file diff --git a/phpmvc/1.0/phpmvc/www/Controller/Admin.php b/phpmvc/1.0/phpmvc/www/Controller/Admin.php new file mode 100755 index 000000000..5cfa289db --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/Controller/Admin.php @@ -0,0 +1,54 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ + +namespace TestProject\Controller; + +class Admin extends Blog +{ + + public function login() + { + if ($this->isLogged()) + header('Location: ' . ROOT_URL . '?p=blog&a=all'); + + if (isset($_POST['email'], $_POST['password'])) + { + $this->oUtil->getModel('Admin'); + $this->oModel = new \TestProject\Model\Admin; + + if ($this->oModel->login($_POST['email'], $_POST['password'])) + { + $_SESSION['is_logged'] = 1; // Admin is logged now + header('Location: ' . ROOT_URL . '?p=blog&a=all'); + exit; + } + else + $this->oUtil->sErrMsg = 'Incorrect Login!'; + } + + $this->oUtil->getView('login'); + } + + public function logout() + { + if (!$this->isLogged()) exit; + + // If there is a session, destroy it to disconnect the admin + if (!empty($_SESSION)) + { + $_SESSION = array(); + session_unset(); + session_destroy(); + } + + // Redirect to the homepage + header('Location: ' . ROOT_URL); + exit; + } + +} diff --git a/phpmvc/1.0/phpmvc/www/Controller/Blog.php b/phpmvc/1.0/phpmvc/www/Controller/Blog.php new file mode 100755 index 000000000..12d89401a --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/Controller/Blog.php @@ -0,0 +1,173 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ + +namespace TestProject\Controller; + +class Blog +{ + + protected $oUtil, $oModel; + private $_iId; + + public function __construct() + { + // Enable PHP Session + if (empty($_SESSION)) + @session_start(); + + $this->oUtil = new \TestProject\Engine\Util; + + /** Get the Model class in all the controller class **/ + $this->oUtil->getModel('Blog'); + $this->oModel = new \TestProject\Model\Blog; + + /** Get the Post ID in the constructor in order to avoid the duplication of the same code **/ + $this->_iId = (int) (!empty($_GET['id']) ? $_GET['id'] : 0); + } + + + /***** Front end *****/ + // Homepage + public function index() + { + $this->oUtil->oPosts = $this->oModel->get(0, 5); // Get only the latest 5 posts + + $this->oUtil->getView('index'); + + } + + public function post() + { + $this->oUtil->oPost = $this->oModel->getById($this->_iId); // Get the data of the post + + $this->oUtil->getView('post'); + } + + public function notFound() + { + $this->oUtil->getView('not_found'); + } + + + /***** For Admin (Back end) *****/ + public function all() + { + if (!$this->isLogged()) exit; + + $this->oUtil->oPosts = $this->oModel->getAll(); + + $this->oUtil->getView('index'); + } + + + public function add() + { + if (!$this->isLogged()) exit; + + if ($_SERVER['CONTENT_TYPE'] === 'text/xml') { + $content = simplexml_load_string(file_get_contents("php://input")); + print_r($content); + }else{ + if (!empty($_POST['add_submit'])) + { + if (isset($_POST['title'], $_POST['body']) && mb_strlen($_POST['title']) <= 50) // Allow a maximum of 50 characters + { + $aData = array('title' => $_POST['title'], 'body' => $_POST['body'], 'created_date' => date('Y-m-d H:i:s')); + + if ($this->oModel->add($aData)) + $this->oUtil->sSuccMsg = 'Hurray!! The post has been added.'; + else + $this->oUtil->sErrMsg = 'Whoops! An error has occurred! Please try again later.'; + } + else + { + $this->oUtil->sErrMsg = 'All fields are required and the title cannot exceed 50 characters.'; + } + } + } + + $this->oUtil->getView('add_post'); + } + + public function edit() + { + if (!$this->isLogged()) exit; + + if (!empty($_POST['edit_submit'])) + { + if (isset($_POST['title'], $_POST['body'])) + { + $aData = array('post_id' => $this->_iId, 'title' => $_POST['title'], 'body' => $_POST['body']); + + if ($this->oModel->update($aData)) + $this->oUtil->sSuccMsg = 'Hurray! The post has been updated.'; + else + $this->oUtil->sErrMsg = 'Whoops! An error has occurred! Please try again later'; + } + else + { + $this->oUtil->sErrMsg = 'All fields are required.'; + } + } + + /* Get the data of the post */ + $this->oUtil->oPost = $this->oModel->getById($this->_iId); + + $this->oUtil->getView('edit_post'); + } + + public function delete() + { + if (!$this->isLogged()) exit; + + if (!empty($_POST['delete']) && $this->oModel->delete($this->_iId)) + header('Location: ' . ROOT_URL); + else + exit('Whoops! Post cannot be deleted.'); + } + + public function upload() + { + if (!empty($_FILES)) { + + if ($_FILES["file"]["error"] > 0 || $_FILES["file"]["size"] > 20000) + { + die("Error, maybe the file size is too large."); + } + else + { + $arr = explode(".", $_FILES["file"]["name"]); + if ($arr[count($arr) - 1] !== 'png') { + die("Wrong ! You must upload a png file."); + } + echo "Upload: " . $_FILES["file"]["name"] . "
"; + echo "Type: " . $_FILES["file"]["type"] . "
"; + echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
"; + echo "Stored in: " . $_FILES["file"]["tmp_name"]; + if (file_exists(ROOT_PATH . 'Upload/' . $_FILES["file"]["name"])) + { + echo $_FILES["file"]["name"] . " already exists. "; + } + else + { + move_uploaded_file($_FILES["file"]["tmp_name"], ROOT_PATH . 'Upload/' . $_FILES["file"]["name"]); + echo "Stored in: " . ROOT_PATH . 'Upload/' . $_FILES["file"]["name"]; + #system("convert " . ROOT_PATH . 'Upload/' . $_FILES["file"]["name"] . " " . ROOT_PATH . 'Upload/' . $_FILES["file"]["name"] . ".convert"); + } + } + }else{ + $this->oUtil->getView('upload'); + } + } + + protected function isLogged() + { + return !empty($_SESSION['is_logged']); + } + +} diff --git a/phpmvc/1.0/phpmvc/www/Engine/Config.php b/phpmvc/1.0/phpmvc/www/Engine/Config.php new file mode 100755 index 000000000..cc0ec6105 --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/Engine/Config.php @@ -0,0 +1,23 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ + +namespace TestProject\Engine; +final class Config +{ + + // Database info (if you want to test the script, please edit the below constants with yours) + const + DB_HOST = 'localhost', + DB_NAME = 'cp', + DB_USR = 'root', + DB_PWD = 'shadow', + + // Title of the site + SITE_NAME = 'My Simple Blog!'; + +} diff --git a/phpmvc/1.0/phpmvc/www/Engine/Db.php b/phpmvc/1.0/phpmvc/www/Engine/Db.php new file mode 100755 index 000000000..5ed8e1069 --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/Engine/Db.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ + +namespace TestProject\Engine; + +class Db extends \PDO +{ + + public function __construct() + { + $aDriverOptions[\PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES UTF8'; + parent::__construct('mysql:host=' . Config::DB_HOST . ';dbname=' . Config::DB_NAME . ';', Config::DB_USR, Config::DB_PWD, $aDriverOptions); + $this->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); + } + +} diff --git a/phpmvc/1.0/phpmvc/www/Engine/Loader.php b/phpmvc/1.0/phpmvc/www/Engine/Loader.php new file mode 100755 index 000000000..cdf3685f5 --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/Engine/Loader.php @@ -0,0 +1,37 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ + +namespace TestProject\Engine; + +// First, include necessary Pattern classes +require_once __DIR__ . '/Pattern/Base.trait.php'; +require_once __DIR__ . '/Pattern/Singleton.trait.php'; + +class Loader +{ + use \TestProject\Engine\Pattern\Singleton; // Thanks Trait feature of PHP 5.4, I don't duplicate pattern code + + public function init() + { + // Register the loader method + spl_autoload_register(array(__CLASS__, '_loadClasses')); + } + + private function _loadClasses($sClass) + { + // Remove namespace and backslash + $sClass = str_replace(array(__NAMESPACE__, 'TestProject', '\\'), '/', $sClass); + + if (is_file(__DIR__ . '/' . $sClass . '.php')) + require_once __DIR__ . '/' . $sClass . '.php'; + + if (is_file(ROOT_PATH . $sClass . '.php')) + require_once ROOT_PATH . $sClass . '.php'; + } + +} diff --git a/phpmvc/1.0/phpmvc/www/Engine/Pattern/Base.trait.php b/phpmvc/1.0/phpmvc/www/Engine/Pattern/Base.trait.php new file mode 100755 index 000000000..5e0dc3d1c --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/Engine/Pattern/Base.trait.php @@ -0,0 +1,15 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ + +namespace TestProject\Engine\Pattern; + +trait Base +{ + final private function __construct() {} + final private function __clone() {} +} diff --git a/phpmvc/1.0/phpmvc/www/Engine/Pattern/Singleton.trait.php b/phpmvc/1.0/phpmvc/www/Engine/Pattern/Singleton.trait.php new file mode 100755 index 000000000..87e555aab --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/Engine/Pattern/Singleton.trait.php @@ -0,0 +1,31 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ + +namespace TestProject\Engine\Pattern; + +trait Singleton +{ + + use Base; + + protected static $_oInstance = null; + + /** + * Get instance of class. + * + * @access public + * @static + * @return object Return the instance class or create first instance of the class. + */ + public static function getInstance() + { + return (null === static::$_oInstance) ? static::$_oInstance = new static : static::$_oInstance; + } + +} + diff --git a/phpmvc/1.0/phpmvc/www/Engine/Router.php b/phpmvc/1.0/phpmvc/www/Engine/Router.php new file mode 100755 index 000000000..f627fcc53 --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/Engine/Router.php @@ -0,0 +1,40 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ + +namespace TestProject\Engine; + +class Router +{ + public static function run (array $aParams) + { + $sNamespace = 'TestProject\Controller\\'; + $sDefCtrl = $sNamespace . 'Blog'; + $sCtrlPath = ROOT_PATH . 'Controller/'; + $sTemplatePath = ROOT_PATH . 'Template/' . $aParams['template']; + //fix by tinyfisher + //$sTemplatePath = str_replace(array(".","\/"), "", $sTemplatePath); + include $sTemplatePath; + $sCtrl = ucfirst($aParams['ctrl']); + + if (is_file($sCtrlPath . $sCtrl . '.php')) + { + $sCtrl = $sNamespace . $sCtrl; + $oCtrl = new $sCtrl; + + if ((new \ReflectionClass($oCtrl))->hasMethod($aParams['act']) && (new \ReflectionMethod($oCtrl, $aParams['act']))->isPublic()) + call_user_func(array($oCtrl, $aParams['act'])); + else + call_user_func(array($oCtrl, 'notFound')); + } + else + { + call_user_func(array(new $sDefCtrl, 'notFound')); + } + } + +} diff --git a/phpmvc/1.0/phpmvc/www/Engine/Util.php b/phpmvc/1.0/phpmvc/www/Engine/Util.php new file mode 100755 index 000000000..2993bec19 --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/Engine/Util.php @@ -0,0 +1,45 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ + +namespace TestProject\Engine; + +class Util +{ + public function getView($sViewName) + { + $this->_get($sViewName, 'View'); + } + + public function getModel($sModelName) + { + $this->_get($sModelName, 'Model'); + } + + /** + * This method is useful in order to avoid the duplication of code (create almost the same method for "getView" and "getModel" + */ + private function _get($sFileName, $sType) + { + $sFullPath = ROOT_PATH . $sType . '/' . $sFileName . '.php'; + if (is_file($sFullPath)) + require $sFullPath; + else + exit('The "' . $sFullPath . '" file doesn\'t exist'); + } + + /** + * Set variables for the template views. + * + * @return void + */ + public function __set($sKey, $mVal) + { + $this->$sKey = $mVal; + } + +} diff --git a/phpmvc/1.0/phpmvc/www/LICENSE.txt b/phpmvc/1.0/phpmvc/www/LICENSE.txt new file mode 100755 index 000000000..65c5ca88a --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/LICENSE.txt @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/phpmvc/1.0/phpmvc/www/Model/Admin.php b/phpmvc/1.0/phpmvc/www/Model/Admin.php new file mode 100755 index 000000000..85acf07da --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/Model/Admin.php @@ -0,0 +1,26 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ + +namespace TestProject\Model; + +class Admin extends Blog +{ + + public function login($sEmail, $sPassword) + { + $oStmt = $this->oDb->prepare("SELECT email, password FROM Admins WHERE email = '{$sEmail}' LIMIT 1"); + $oStmt->execute(); + //fix by tinyfisher + //$oStmt = $this->oDb->prepare("SELECT email, password FROM Admins WHERE email = ? LIMIT 1"); + //$oStmt->execute($sEmail); + $oRow = $oStmt->fetch(\PDO::FETCH_OBJ); + + return password_verify($sPassword, @$oRow->password); // Use the PHP 5.5 password function + } + +} diff --git a/phpmvc/1.0/phpmvc/www/Model/Blog.php b/phpmvc/1.0/phpmvc/www/Model/Blog.php new file mode 100755 index 000000000..a4c3ecaa5 --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/Model/Blog.php @@ -0,0 +1,65 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ + +namespace TestProject\Model; + +class Blog +{ + protected $oDb; + + public function __construct() + { + $this->oDb = new \TestProject\Engine\Db; + } + + public function get($iOffset, $iLimit) + { + $oStmt = $this->oDb->prepare('SELECT * FROM Posts ORDER BY createdDate DESC LIMIT :offset, :limit'); + $oStmt->bindParam(':offset', $iOffset, \PDO::PARAM_INT); + $oStmt->bindParam(':limit', $iLimit, \PDO::PARAM_INT); + $oStmt->execute(); + return $oStmt->fetchAll(\PDO::FETCH_OBJ); + } + + public function getAll() + { + $oStmt = $this->oDb->query('SELECT * FROM Posts ORDER BY createdDate DESC'); + return $oStmt->fetchAll(\PDO::FETCH_OBJ); + } + + public function add(array $aData) + { + $oStmt = $this->oDb->prepare('INSERT INTO Posts (title, body, createdDate) VALUES(:title, :body, :created_date)'); + return $oStmt->execute($aData); + } + + public function getById($iId) + { + $oStmt = $this->oDb->prepare('SELECT * FROM Posts WHERE id = :postId LIMIT 1'); + $oStmt->bindParam(':postId', $iId, \PDO::PARAM_INT); + $oStmt->execute(); + return $oStmt->fetch(\PDO::FETCH_OBJ); + } + + public function update(array $aData) + { + $oStmt = $this->oDb->prepare('UPDATE Posts SET title = :title, body = :body WHERE id = :postId LIMIT 1'); + $oStmt->bindValue(':postId', $aData['post_id'], \PDO::PARAM_INT); + $oStmt->bindValue(':title', $aData['title']); + $oStmt->bindValue(':body', $aData['body']); + return $oStmt->execute(); + } + + public function delete($iId) + { + $oStmt = $this->oDb->prepare('DELETE FROM Posts WHERE id = :postId LIMIT 1'); + $oStmt->bindParam(':postId', $iId, \PDO::PARAM_INT); + return $oStmt->execute(); + } + +} diff --git a/phpmvc/1.0/phpmvc/www/README.md b/phpmvc/1.0/phpmvc/www/README.md new file mode 100755 index 000000000..bb464d24c --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/README.md @@ -0,0 +1,68 @@ +# Simple PHP MVC Blog System + + +## Description + +This *PHP Blog System* has an MVC pattern, uses Traits (PHP 5.4), Namespace (PHP 5.3), Singleton pattern, PDO (PHP 5.1) and the new PHP Password Hashing feature (PHP 5.5). + +The project was a *PHP Challenge Project* I have done. + + +## Why this PHP 5.4 Project can be very Useful for You? + +If you need to code a simple website under a Professional and very nice/clean code (as I really enjoy doing), this script will be very useful in order to *start on good basis* and *save time and money*. + +However, if you need to build a blog system, again this project can be used as a *framework* to start your project easily under a *good development pattern* and *good development practice* and organization. + + +## Requirements that were Requested for the Project + +### Requirements + +* The project should be written in object-oriented PHP targeting version 5.3 or higher +* It should be all self-written, no existing frameworks or libraries +* It should have good security (e.g., hashed passwords, protect against SQL injection, shouldn't have any error when we try to change URL query strings or to hack it, etc) +* Should use a MySQL database to store admin account and article data + +### Specification + +*Build a simple blog with the following functionalities* + +#### The Frontend + +* List of blog articles showing the **title**, **body** truncated to 100 characters, and **date**. It should show only the latest 5 articles +* Single blog article showing the **title**, **full body**, and the **date** + +#### The Backend + +* List of all the blog articles +* Possibility to add a new blog article with a title and body. The title should allow a maximum of 50 characters +* Possibility to edit an existing blog article +* Possibility to delete an article +* Logout feature for the admin user + +HTML and CSS code should be kept to the minimum needed to make the website functional – This project is purely to assess how you approach the problem and not how good it looks. + + +## Server Requirements of the Web App + +*Application Server* PHP 5.5.0 or higher. + +*PHP Extension* mbstring + +*Database MySQL/MariaDB 5* or higher. + + +## The Author + +Pierre-Henry Soria + + +## Contact the Author + +By email at: *phy [AT] hizup [D0T] uk* + + +## License + +This blog system (PHP script) is under [Lesser General Public License](http://www.gnu.org/copyleft/lesser.html) (LGPL); See the LICENSE.txt file for more information. diff --git a/phpmvc/1.0/phpmvc/www/Template/pc b/phpmvc/1.0/phpmvc/www/Template/pc new file mode 100755 index 000000000..077149a36 --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/Template/pc @@ -0,0 +1,2 @@ + diff --git a/phpmvc/1.0/phpmvc/www/View/add_post.php b/phpmvc/1.0/phpmvc/www/View/add_post.php new file mode 100755 index 000000000..8c0f8b641 --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/View/add_post.php @@ -0,0 +1,25 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ +?> + + + +
+ +


+ +

+ +


+ +

+ +

+
+ + diff --git a/phpmvc/1.0/phpmvc/www/View/edit_post.php b/phpmvc/1.0/phpmvc/www/View/edit_post.php new file mode 100755 index 000000000..261925cb8 --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/View/edit_post.php @@ -0,0 +1,29 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ +?> + + + +oPost)): ?> +

Post Data Not Found!

+ + +
+


+ +

+ +


+ +

+ +

+
+ + + diff --git a/phpmvc/1.0/phpmvc/www/View/inc/control_buttons.php b/phpmvc/1.0/phpmvc/www/View/inc/control_buttons.php new file mode 100755 index 000000000..a5931a83c --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/View/inc/control_buttons.php @@ -0,0 +1,15 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ +?> + + + | +
| + + + diff --git a/phpmvc/1.0/phpmvc/www/View/inc/footer.php b/phpmvc/1.0/phpmvc/www/View/inc/footer.php new file mode 100755 index 000000000..3cc32a79e --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/View/inc/footer.php @@ -0,0 +1,21 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ +?> + + + + diff --git a/phpmvc/1.0/phpmvc/www/View/inc/header.php b/phpmvc/1.0/phpmvc/www/View/inc/header.php new file mode 100755 index 000000000..2e22686a9 --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/View/inc/header.php @@ -0,0 +1,18 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ +?> + + + + + <?=\TestProject\Engine\Config::SITE_NAME?> + + + + +
diff --git a/phpmvc/1.0/phpmvc/www/View/inc/msg.php b/phpmvc/1.0/phpmvc/www/View/inc/msg.php new file mode 100755 index 000000000..7da747f59 --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/View/inc/msg.php @@ -0,0 +1,15 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ +?> +sErrMsg)): ?> +

sErrMsg?>

+ + +sSuccMsg)): ?> +

sSuccMsg?>

+ diff --git a/phpmvc/1.0/phpmvc/www/View/index.php b/phpmvc/1.0/phpmvc/www/View/index.php new file mode 100755 index 000000000..d03611c45 --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/View/index.php @@ -0,0 +1,34 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ + + +/** + * Since PHP 5.4, the echo short tag " is always available, so I use it to simplify the visibility of the template +*/ +?> + + +oPosts)): ?> +

There is no Blog Post.

+

+ + + oPosts as $oPost): ?> +

title)?>

+ +

body, 0, 100, '...')))?>

+

Want to see more?

+

Posted on createdDate?>

+ + +

+ + + + + diff --git a/phpmvc/1.0/phpmvc/www/View/login.php b/phpmvc/1.0/phpmvc/www/View/login.php new file mode 100755 index 000000000..5cefc34bd --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/View/login.php @@ -0,0 +1,25 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ +?> + + + +
+ +


+ +

+ +


+ +

+ +

+
+ + diff --git a/phpmvc/1.0/phpmvc/www/View/not_found.php b/phpmvc/1.0/phpmvc/www/View/not_found.php new file mode 100755 index 000000000..28c637cc8 --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/View/not_found.php @@ -0,0 +1,15 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ +?> + + +

Page Not Found

+ +

Whoops! Sorry but this page doesn't seem to exist.

+ + diff --git a/phpmvc/1.0/phpmvc/www/View/post.php b/phpmvc/1.0/phpmvc/www/View/post.php new file mode 100755 index 000000000..938a32d99 --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/View/post.php @@ -0,0 +1,30 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ +?> + + +oPost)): ?> +

The post can't be be found!

+ + +
+ + +

oPost->title)?>

+

oPost->body))?>

+

Posted on oPost->createdDate?>

+ + oPost; + require 'inc/control_buttons.php'; + ?> +
+ + + + diff --git a/phpmvc/1.0/phpmvc/www/View/upload.php b/phpmvc/1.0/phpmvc/www/View/upload.php new file mode 100755 index 000000000..6440ae39b --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/View/upload.php @@ -0,0 +1,22 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ +?> + + + + + +
+ + +
+ +
+ + + diff --git a/phpmvc/1.0/phpmvc/www/_create_admin_pwd.php b/phpmvc/1.0/phpmvc/www/_create_admin_pwd.php new file mode 100755 index 000000000..0db04069a --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/_create_admin_pwd.php @@ -0,0 +1,14 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ + +/** Allows to create an admin password easily **/ +/* I use PHP 5.5 password hashing for this app test. Thanks this new PHP feature, the password gets a salt and it is much more secure than a simple SHA1 algorithm */ + +$sPwd = 'pwd123'; // Admin Password +$sHashedPwd = password_hash($sPwd , PASSWORD_BCRYPT, array('cost' => 14)); +echo 'Password is: ' . $sHashedPwd; diff --git a/phpmvc/1.0/phpmvc/www/index.php b/phpmvc/1.0/phpmvc/www/index.php new file mode 100755 index 000000000..43197c603 --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/index.php @@ -0,0 +1,42 @@ + + * @copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * @license Lesser General Public License + * @link http://hizup.uk + */ +// Note, the script requires PHP 5.5 or higher test + +namespace TestProject; +use TestProject\Engine as E; + + + +if (version_compare(PHP_VERSION, '5.5.0', '<')) + exit('Your PHP version is ' . PHP_VERSION . '. The script requires PHP 5.5 or higher.'); +if (!extension_loaded('mbstring')) + exit('The script requires "mbstring" PHP extension. Please install it.'); + + +// Set constants (root server path + root URL) +define('PROT', (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS'] == 'on')) ? 'https://' : 'http://'); +define('ROOT_URL', PROT . $_SERVER['HTTP_HOST'] . str_replace('\\', '', dirname(htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES))) . '/'); // Remove backslashes for Windows compatibility +define('ROOT_PATH', __DIR__ . '/'); + + + +try +{ + require ROOT_PATH . 'Engine/Loader.php'; + E\Loader::getInstance()->init(); // Load necessary classes + $aParams = ['ctrl' => (!empty($_GET['p']) ? $_GET['p'] : 'blog'), 'act' => (!empty($_GET['a']) ? $_GET['a'] : 'index'), 'template' => (!empty($_GET['t']) ? $_GET['t'] : 'pc')]; // I use the new PHP 5.4 short array syntax + E\Router::run($aParams); +} +catch (\Exception $oE) +{ + echo $oE->getMessage(); +} + + +?> \ No newline at end of file diff --git a/phpmvc/1.0/phpmvc/www/readme_tech.txt b/phpmvc/1.0/phpmvc/www/readme_tech.txt new file mode 100755 index 000000000..bea943af9 --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/readme_tech.txt @@ -0,0 +1,5 @@ +- Please note that you need PHP 5.5 or higher to execute the script +- Please create a database name/user and exucute "db.sql" first +- To change the MySQL connection information, please edit /Engine/Config.php +- Admin login (email/password) is: test@test.com / pwd123 +- Navigation Tip. On the website, there is no logo or "Homepage" link. To come back to the homepage, please click on the "Simple Blog" link located in the bottom page diff --git a/phpmvc/1.0/phpmvc/www/static/style.css b/phpmvc/1.0/phpmvc/www/static/style.css new file mode 100755 index 000000000..66794932a --- /dev/null +++ b/phpmvc/1.0/phpmvc/www/static/style.css @@ -0,0 +1,23 @@ +/* + * Author Pierre-Henry Soria + * Copyright (c) 2015, Pierre-Henry Soria. All Rights Reserved. + * License Lesser General Public License + * Link http://hizup.uk + */ + +body{color:#666;font-size:14px;font-family:Arial,Helvetica,sans-serif;background:#efefef} +h1{font-size:2em} +.center{text-align:center;margin-left:auto;margin-right:auto;width:80%} +.right{float:right;margin-right:10px} +.left{float:left;margin-left:10px} +.left,.right{width:200px} +.success{color:green} +.error{color:red} +.success,.error,.bold{font-weight:bold;font-size:16px} +.small{font-size:x-small} +.italic{font-style:italic} +.inline{display:inline} +header{margin-bottom:10px} +footer{font-size:.9em;text-align:center;padding:8px;margin-top:28px;border-top:1px solid #c8c8c8} +input,textarea{width:260px} +.clear{clear:both}