From a61a7fbb50517362dfd34288a71c180c8161c8b7 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sun, 8 Mar 2015 05:19:06 +0100 Subject: [PATCH] You see, there's retarded and there's me. --- _sakura/components/Configuration.php | 0 _sakura/components/Hashing.php | 171 +++++++++++++++++++++++++++ _sakura/components/Main.php | 100 ++++++++++++++++ _sakura/sakura.php | 6 +- 4 files changed, 274 insertions(+), 3 deletions(-) create mode 100644 _sakura/components/Configuration.php create mode 100644 _sakura/components/Hashing.php create mode 100644 _sakura/components/Main.php diff --git a/_sakura/components/Configuration.php b/_sakura/components/Configuration.php new file mode 100644 index 0000000..e69de29 diff --git a/_sakura/components/Hashing.php b/_sakura/components/Hashing.php new file mode 100644 index 0000000..37cce25 --- /dev/null +++ b/_sakura/components/Hashing.php @@ -0,0 +1,171 @@ +Upgrade your PHP Version to at least PHP 5.4!'); + + // Assign $config values to $_CONF + self::$_CONF = $config; + + // Initialise database + self::$_DB = new Database(); + } + + // Get values from the configuration + public static function getConfig($key, $subkey = null) { + if(array_key_exists($key, self::$_CONF)) { + if($subkey) + return self::$_CONF[$key][$subkey]; + else + return self::$_CONF[$key]; + } else { + return false; + } + } + + // Initialise Twig + public function initTwig($templateName = null, $templatesFolder = null) { + // Assign default values set in the configuration if $templateName and $templatesFolder are null + $templateName = is_null($templateName) ? self::getConfig('etc', 'design') : $templateName; + $templatesFolder = is_null($templatesFolder) ? self::getConfig('etc', 'templatesPath') : $templatesFolder; + + // Initialise Twig Filesystem Loader + $twigLoader = new \Twig_Loader_Filesystem($templatesFolder . $templateName); + + // And now actually initialise the templating engine + $this->twig = new \Twig_Environment($twigLoader, array( + // 'cache' => $satoko['cacheFolder'] + )); + } + + // Error Handler + public static function ErrorHandler($errno, $errstr, $errfile, $errline) { + // Set some variables to work with including A HUGE fallback hackjob for the templates folder + $errstr = str_replace(self::getConfig('etc', 'localPath'), '', $errstr); + $errfile = str_replace(self::getConfig('etc', 'localPath'), '', $errfile); + $templates = (self::getConfig('etc', 'templatesPath') !== null && !empty(self::getConfig('etc', 'templatesPath'))) ? self::getConfig('etc', 'templatesPath') : '/var/www/flashii.net/_sakuya/templates/'; + + switch ($errno) { + case E_ERROR: + case E_USER_ERROR: + $error = 'FATAL ERROR: ' . $errstr . ' on line ' . $errline . ' in ' . $errfile; + break; + + case E_WARNING: + case E_USER_WARNING: + $error = 'WARNING: ' . $errstr . ' on line ' . $errline . ' in ' . $errfile; + break; + + case E_NOTICE: + case E_USER_NOTICE: + $error = 'NOTICE: ' . $errstr . ' on line ' . $errline . ' in ' . $errfile; + break; + + default: + $error = 'Unknown error type [' . $errno . ']: ' . $errstr . ' on line ' . $errline . ' in ' . $errfile; + break; + } + + // Use file_get_contents instead of Twig in case the problem is related to twig + $errorPage = file_get_contents($templates. 'errorPage.tpl'); + + // str_replace {{ error }} on the error page with the error data + $error = str_replace('{{ error }}', $error, $errorPage); + + // Truncate all previous outputs + ob_clean(); + + // Die and display error message + die($error); + } + + // Legacy password hashing to be able to validate passwords from users on the old backend. + public static function legacyPasswordHash($data) { + return hash('sha512', strrev(hash('sha512', $data))); + } + +} \ No newline at end of file diff --git a/_sakura/sakura.php b/_sakura/sakura.php index 2aad456..e5c8a65 100644 --- a/_sakura/sakura.php +++ b/_sakura/sakura.php @@ -18,9 +18,9 @@ require_once 'config/config.php'; // Include libraries require_once 'vendor/autoload.php'; -require_once 'components/SockBase.php'; -require_once 'components/SockHashing.php'; -require_once 'components/SockConfiguration.php'; +require_once 'components/Base.php'; +require_once 'components/Hashing.php'; +require_once 'components/Configuration.php'; // Generate path to database driver $_DBNGNPATH = 'components/database/' . $fiiConf['db']['driver'] . '.php';