Autism the likes of which has never been seen before.
This commit is contained in:
parent
5d9d457a38
commit
d7d61529be
7 changed files with 206 additions and 129 deletions
|
@ -22,7 +22,7 @@ class Configuration {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialise Database configuration values.
|
// Initialise Database configuration values.
|
||||||
// Different from __construct as that is called before the database connection is initially
|
// Different from init as that is called before the database connection is initially
|
||||||
// established
|
// established
|
||||||
public static function initDB() {
|
public static function initDB() {
|
||||||
|
|
||||||
|
@ -53,9 +53,8 @@ class Configuration {
|
||||||
public static function setLocalConfig($key, $subkey, $value) {
|
public static function setLocalConfig($key, $subkey, $value) {
|
||||||
|
|
||||||
if($subkey) {
|
if($subkey) {
|
||||||
if(!isset(self::$_LCNF[$key])) {
|
if(!isset(self::$_LCNF[$key]))
|
||||||
self::$_LCNF[$key] = array();
|
self::$_LCNF[$key] = array();
|
||||||
}
|
|
||||||
self::$_LCNF[$key][$subkey] = $value;
|
self::$_LCNF[$key][$subkey] = $value;
|
||||||
} else {
|
} else {
|
||||||
self::$_LCNF[$key] = $value;
|
self::$_LCNF[$key] = $value;
|
||||||
|
|
|
@ -48,6 +48,7 @@ class Hashing {
|
||||||
|
|
||||||
// Returns an array formatted like: [algorithm, iterations, salt, hash]
|
// Returns an array formatted like: [algorithm, iterations, salt, hash]
|
||||||
public static function create_hash($pass) {
|
public static function create_hash($pass) {
|
||||||
|
|
||||||
$salt = base64_encode(
|
$salt = base64_encode(
|
||||||
\mcrypt_create_iv(
|
\mcrypt_create_iv(
|
||||||
self::$_PBKDF2_SALT_BYTES,
|
self::$_PBKDF2_SALT_BYTES,
|
||||||
|
@ -74,10 +75,12 @@ class Hashing {
|
||||||
);
|
);
|
||||||
|
|
||||||
return $passwordData;
|
return $passwordData;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validates hashed password
|
// Validates hashed password
|
||||||
public static function validate_password($password, $params) {
|
public static function validate_password($password, $params) {
|
||||||
|
|
||||||
if(count($params) < self::$_HASH_SECTIONS);
|
if(count($params) < self::$_HASH_SECTIONS);
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -96,17 +99,19 @@ class Hashing {
|
||||||
);
|
);
|
||||||
|
|
||||||
return $validate;
|
return $validate;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compares two strings $a and $b in length-constant time.
|
// Compares two strings $a and $b in length-constant time.
|
||||||
public static function slow_equals($a, $b) {
|
public static function slow_equals($a, $b) {
|
||||||
|
|
||||||
$diff = strlen($a) ^ strlen($b);
|
$diff = strlen($a) ^ strlen($b);
|
||||||
|
|
||||||
for($i = 0; $i < strlen($a) && $i < strlen($b); $i++) {
|
for($i = 0; $i < strlen($a) && $i < strlen($b); $i++)
|
||||||
$diff |= ord($a[$i]) ^ ord($b[$i]);
|
$diff |= ord($a[$i]) ^ ord($b[$i]);
|
||||||
}
|
|
||||||
|
|
||||||
return $diff === 0;
|
return $diff === 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -126,6 +131,7 @@ class Hashing {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private static function pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output = false) {
|
private static function pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output = false) {
|
||||||
|
|
||||||
$algorithm = strtolower($algorithm);
|
$algorithm = strtolower($algorithm);
|
||||||
|
|
||||||
if(!in_array($algorithm, hash_algos(), true))
|
if(!in_array($algorithm, hash_algos(), true))
|
||||||
|
@ -155,9 +161,8 @@ class Hashing {
|
||||||
$last = $xorsum = hash_hmac($algorithm, $last, $password, true);
|
$last = $xorsum = hash_hmac($algorithm, $last, $password, true);
|
||||||
|
|
||||||
// Perform the other $count - 1 interations
|
// Perform the other $count - 1 interations
|
||||||
for($j = 1; $j < $count; $j++) {
|
for($j = 1; $j < $count; $j++)
|
||||||
$xorsum ^= ($last = hash_hmac($algorithm, $last, $password, true));
|
$xorsum ^= ($last = hash_hmac($algorithm, $last, $password, true));
|
||||||
}
|
|
||||||
|
|
||||||
$output .= $xorsum;
|
$output .= $xorsum;
|
||||||
|
|
||||||
|
@ -165,7 +170,9 @@ class Hashing {
|
||||||
return substr($output, 0, $key_length);
|
return substr($output, 0, $key_length);
|
||||||
else
|
else
|
||||||
return bin2hex(substr($output, 0, $key_length));
|
return bin2hex(substr($output, 0, $key_length));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
|
|
||||||
namespace Flashii;
|
namespace Flashii;
|
||||||
|
|
||||||
class Flashii {
|
class Main {
|
||||||
|
|
||||||
public $_TPL;
|
public $_TPL;
|
||||||
public $_MD;
|
public $_MD;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
function __construct($config) {
|
public static function init($config) {
|
||||||
|
|
||||||
// Stop the execution if the PHP Version is older than 5.4.0
|
// Stop the execution if the PHP Version is older than 5.4.0
|
||||||
if(version_compare(phpversion(), '5.4.0', '<'))
|
if(version_compare(phpversion(), '5.4.0', '<'))
|
||||||
|
@ -31,10 +31,10 @@ class Flashii {
|
||||||
Configuration::initDB();
|
Configuration::initDB();
|
||||||
|
|
||||||
// Templating engine
|
// Templating engine
|
||||||
$this->initTwig();
|
self::initTwig();
|
||||||
|
|
||||||
// Markdown Parser
|
// Markdown Parser
|
||||||
$this->initParsedown();
|
self::initParsedown();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,29 +46,45 @@ class Flashii {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialise Twig
|
// Initialise Twig
|
||||||
private function initTwig($templateName = null, $templatesFolder = null) {
|
private static function initTwig() {
|
||||||
|
|
||||||
// Assign default values set in the configuration if $templateName and $templatesFolder are null
|
|
||||||
$templateName = is_null($templateName) ? Configuration::getLocalConfig('etc', 'design') : $templateName;
|
|
||||||
$templatesFolder = is_null($templatesFolder) ? Configuration::getLocalConfig('etc', 'templatesPath') : $templatesFolder;
|
|
||||||
|
|
||||||
// Initialise Twig Filesystem Loader
|
// Initialise Twig Filesystem Loader
|
||||||
$twigLoader = new \Twig_Loader_Filesystem($templatesFolder . $templateName);
|
$twigLoader = new \Twig_Loader_Filesystem(Configuration::getLocalConfig('etc', 'templatesPath') .'/'. Configuration::getLocalConfig('etc', 'design'));
|
||||||
|
|
||||||
// And now actually initialise the templating engine
|
// And now actually initialise the templating engine
|
||||||
$this->_TPL = new \Twig_Environment($twigLoader, array(
|
self::$_TPL = new \Twig_Environment($twigLoader, array(
|
||||||
// 'cache' => ROOT_DIRECTORY. $satoko['cacheFolder']
|
|
||||||
|
// 'cache' => SATOKO_ROOT_DIRECTORY. self::getConfig('path', 'cache') // Set cache directory
|
||||||
|
|
||||||
));
|
));
|
||||||
|
|
||||||
// Load String template loader
|
// Load String template loader
|
||||||
$this->_TPL->addExtension(new \Twig_Extension_StringLoader());
|
self::$_TPL->addExtension(new \Twig_Extension_StringLoader());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialise Parsedown
|
// Initialise Parsedown
|
||||||
private function initParsedown() {
|
private function initParsedown() {
|
||||||
|
|
||||||
$this->_MD = new \Parsedown();
|
self::$_MD = new \Parsedown();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify ReCAPTCHA
|
||||||
|
public static function verifyCaptcha($response) {
|
||||||
|
|
||||||
|
// Attempt to get the response
|
||||||
|
$resp = @file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='. self::getConfig('recaptcha_private') .'&response='. $response);
|
||||||
|
|
||||||
|
// In the highly unlikely case that it failed to get anything forge a false
|
||||||
|
if(!$resp)
|
||||||
|
return array('success' => false, 'error-codes' => array('Could not connect to the ReCAPTCHA server.'));
|
||||||
|
|
||||||
|
// Decode the response JSON from the servers
|
||||||
|
$resp = json_decode($resp, true);
|
||||||
|
|
||||||
|
// Return shit
|
||||||
|
return $resp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +97,7 @@ class Flashii {
|
||||||
$templates = (self::getConfig('etc', 'templatesPath') !== null && !empty(self::getConfig('etc', 'templatesPath'))) ? self::getConfig('etc', 'templatesPath') : '/var/www/flashii.net/_sakuya/templates/';
|
$templates = (self::getConfig('etc', 'templatesPath') !== null && !empty(self::getConfig('etc', 'templatesPath'))) ? self::getConfig('etc', 'templatesPath') : '/var/www/flashii.net/_sakuya/templates/';
|
||||||
|
|
||||||
switch ($errno) {
|
switch ($errno) {
|
||||||
|
|
||||||
case E_ERROR:
|
case E_ERROR:
|
||||||
case E_USER_ERROR:
|
case E_USER_ERROR:
|
||||||
$error = '<b>FATAL ERROR</b>: ' . $errstr . ' on line ' . $errline . ' in ' . $errfile;
|
$error = '<b>FATAL ERROR</b>: ' . $errstr . ' on line ' . $errline . ' in ' . $errfile;
|
||||||
|
@ -98,7 +115,7 @@ class Flashii {
|
||||||
|
|
||||||
default:
|
default:
|
||||||
$error = '<b>Unknown error type</b> [' . $errno . ']: ' . $errstr . ' on line ' . $errline . ' in ' . $errfile;
|
$error = '<b>Unknown error type</b> [' . $errno . ']: ' . $errstr . ' on line ' . $errline . ' in ' . $errfile;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use file_get_contents instead of Twig in case the problem is related to twig
|
// Use file_get_contents instead of Twig in case the problem is related to twig
|
||||||
|
|
|
@ -21,29 +21,29 @@ class Database {
|
||||||
|
|
||||||
if(!extension_loaded('PDO')) {
|
if(!extension_loaded('PDO')) {
|
||||||
// Return error and die
|
// Return error and die
|
||||||
die('<h1>PDO extension not loaded.</h1>');
|
trigger_error('<b>SQL Driver</b>: PDO extension not loaded.', E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialise connection
|
// Initialise connection
|
||||||
self::initConnect(
|
self::initConnect(
|
||||||
(
|
(
|
||||||
Configuration::getLocalConfig('db', 'unixsocket') ?
|
Board::getConfig('db', 'unixsocket') ?
|
||||||
self::prepareSock(
|
self::prepareSock(
|
||||||
Configuration::getLocalConfig('db', 'host'),
|
Board::getConfig('db', 'host'),
|
||||||
Configuration::getLocalConfig('db', 'database')
|
Board::getConfig('db', 'database')
|
||||||
) :
|
) :
|
||||||
self::prepareHost(
|
self::prepareHost(
|
||||||
Configuration::getLocalConfig('db', 'host'),
|
Board::getConfig('db', 'host'),
|
||||||
Configuration::getLocalConfig('db', 'database'),
|
Board::getConfig('db', 'database'),
|
||||||
(
|
(
|
||||||
Configuration::getLocalConfig('db', 'port') !== null ?
|
Board::getConfig('db', 'port') !== null ?
|
||||||
Configuration::getLocalConfig('db', 'port') :
|
Board::getConfig('db', 'port') :
|
||||||
3306
|
3306
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
Configuration::getLocalConfig('db', 'username'),
|
Board::getConfig('db', 'username'),
|
||||||
Configuration::getLocalConfig('db', 'password')
|
Board::getConfig('db', 'password')
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ class Database {
|
||||||
self::$sql = new PDO($DSN, $dbUname, $dbPword);
|
self::$sql = new PDO($DSN, $dbUname, $dbPword);
|
||||||
} catch(PDOException $e) {
|
} catch(PDOException $e) {
|
||||||
// Catch connection errors
|
// Catch connection errors
|
||||||
die("<h3>" . $e->getMessage() . "</h3>");
|
trigger_error('SQL Driver: '. $e->getMessage(), E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -82,10 +82,10 @@ class Database {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch array from database
|
// Fetch array from database
|
||||||
public static function fetch($table, $fetchAll = true, $data = null) {
|
public static function fetch($table, $fetchAll = true, $data = null, $order = null, $limit = null, $group = null, $distinct = false, $column = '*') {
|
||||||
|
|
||||||
// Begin preparation of the statement
|
// Begin preparation of the statement
|
||||||
$prepare = 'SELECT * FROM `' . Configuration::getLocalConfig('db', 'prefix') . $table . '`';
|
$prepare = 'SELECT '. ($distinct ? 'DISTINCT ' : '') . $column .' FROM `' . Board::getConfig('db', 'prefix') . $table . '`';
|
||||||
|
|
||||||
// If $data is set and is an array continue
|
// If $data is set and is an array continue
|
||||||
if(is_array($data)) {
|
if(is_array($data)) {
|
||||||
|
@ -93,11 +93,55 @@ class Database {
|
||||||
$prepare .= ' WHERE';
|
$prepare .= ' WHERE';
|
||||||
|
|
||||||
foreach($data as $key => $value) {
|
foreach($data as $key => $value) {
|
||||||
$prepare .= ' `'. $key .'` '. $value[1] .' :'. $key .($key == key(array_slice($data, -1, 1, true)) ? ';' : ' AND');
|
$prepare .= ' `'. $key .'` '. $value[1] .' :'. $key . ($key == key(array_slice($data, -1, 1, true)) ? '' : ' AND');
|
||||||
|
|
||||||
|
// Unset variables to be safe
|
||||||
|
unset($key);
|
||||||
|
unset($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If $order is set and is an array continue
|
||||||
|
if(is_array($order)) {
|
||||||
|
|
||||||
|
$prepare .= ' ORDER BY `'. $order[0] .'`'. (!empty($order[1]) && $order[1] ? ' DESC' : '');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// If $group is set and is an array continue
|
||||||
|
if(is_array($group)) {
|
||||||
|
|
||||||
|
$prepare .= ' GROUP BY';
|
||||||
|
|
||||||
|
foreach($group as $key => $value) {
|
||||||
|
$prepare .= ' `'. $value .'`'. ($key == key(array_slice($group, -1, 1, true)) ? '' : ',');
|
||||||
|
|
||||||
|
// Unset variables to be safe
|
||||||
|
unset($key);
|
||||||
|
unset($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// If $limit is set and is an array continue
|
||||||
|
if(is_array($limit)) {
|
||||||
|
|
||||||
|
$prepare .= ' LIMIT';
|
||||||
|
|
||||||
|
foreach($limit as $key => $value) {
|
||||||
|
$prepare .= ' '. $value . ($key == key(array_slice($limit, -1, 1, true)) ? '' : ',');
|
||||||
|
|
||||||
|
// Unset variables to be safe
|
||||||
|
unset($key);
|
||||||
|
unset($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the finishing semicolon
|
||||||
|
$prepare .= ';';
|
||||||
|
|
||||||
// Actually prepare the preration
|
// Actually prepare the preration
|
||||||
$query = self::$sql->prepare($prepare);
|
$query = self::$sql->prepare($prepare);
|
||||||
|
|
||||||
|
@ -121,6 +165,7 @@ class Database {
|
||||||
else
|
else
|
||||||
$result = $query->fetch(PDO::FETCH_BOTH);
|
$result = $query->fetch(PDO::FETCH_BOTH);
|
||||||
|
|
||||||
|
|
||||||
// And return the output
|
// And return the output
|
||||||
return $result;
|
return $result;
|
||||||
|
|
||||||
|
@ -130,7 +175,7 @@ class Database {
|
||||||
public static function insert($table, $data) {
|
public static function insert($table, $data) {
|
||||||
|
|
||||||
// Begin preparation of the statement
|
// Begin preparation of the statement
|
||||||
$prepare = 'INSERT INTO `' . Configuration::getLocalConfig('db', 'prefix') . $table . '` ';
|
$prepare = 'INSERT INTO `' . Board::getConfig('db', 'prefix') . $table . '` ';
|
||||||
|
|
||||||
// Run the foreach statement twice for (`stuff`) VALUES (:stuff)
|
// Run the foreach statement twice for (`stuff`) VALUES (:stuff)
|
||||||
for($i = 0; $i < 2; $i++) {
|
for($i = 0; $i < 2; $i++) {
|
||||||
|
@ -170,7 +215,7 @@ class Database {
|
||||||
public static function update($table, $data) {
|
public static function update($table, $data) {
|
||||||
|
|
||||||
// Begin preparation of the statement
|
// Begin preparation of the statement
|
||||||
$prepare = 'UPDATE `' . Configuration::getLocalConfig('db', 'prefix') . $table . '`';
|
$prepare = 'UPDATE `' . Board::getConfig('db', 'prefix') . $table . '`';
|
||||||
|
|
||||||
// Run a foreach on $data and complete the statement
|
// Run a foreach on $data and complete the statement
|
||||||
foreach($data as $key => $values) {
|
foreach($data as $key => $values) {
|
||||||
|
|
|
@ -4,11 +4,14 @@
|
||||||
* (c)Flashwave/Flashii Media 2013-2015 <http://flash.moe>
|
* (c)Flashwave/Flashii Media 2013-2015 <http://flash.moe>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Declare Namespace
|
||||||
|
namespace Flashii;
|
||||||
|
|
||||||
// Start output buffering
|
// Start output buffering
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
// Define Sakura version
|
// Define Sakura version
|
||||||
define('SAKURA_VERSION', '20150221');
|
define('SAKURA_VERSION', '20150321');
|
||||||
|
|
||||||
// Define Sakura Path
|
// Define Sakura Path
|
||||||
define('ROOT_DIRECTORY', str_replace('_sakura', '', dirname(__FILE__)));
|
define('ROOT_DIRECTORY', str_replace('_sakura', '', dirname(__FILE__)));
|
||||||
|
@ -39,7 +42,7 @@ else
|
||||||
set_error_handler(array('Flashii\Flashii', 'ErrorHandler'));
|
set_error_handler(array('Flashii\Flashii', 'ErrorHandler'));
|
||||||
|
|
||||||
// Initialise Flashii Class
|
// Initialise Flashii Class
|
||||||
$flashii = new Flashii\Flashii($fiiConf);
|
Main::init($fiiConf);
|
||||||
|
|
||||||
// Set base page rendering data
|
// Set base page rendering data
|
||||||
$renderData = array(
|
$renderData = array(
|
||||||
|
|
|
@ -3,8 +3,11 @@
|
||||||
* Flashii.net Main Index
|
* Flashii.net Main Index
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Declare Namespace
|
||||||
|
namespace Flashii;
|
||||||
|
|
||||||
// Include components
|
// Include components
|
||||||
require_once('/var/www/flashii.net/_sakura/sakura.php');
|
require_once('/var/www/flashii.net/_sakura/sakura.php');
|
||||||
|
|
||||||
// Print page contents
|
// Print page contents
|
||||||
print $flashii->_TPL->render('errors/http404.tpl', $renderData);
|
print Main::$_TPL->render('errors/http404.tpl', $renderData);
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
* Flashii.net Main Index
|
* Flashii.net Main Index
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Declare Namespace
|
||||||
|
namespace Flashii;
|
||||||
|
|
||||||
// Include components
|
// Include components
|
||||||
require_once('/var/www/flashii.net/_sakura/sakura.php');
|
require_once('/var/www/flashii.net/_sakura/sakura.php');
|
||||||
|
|
||||||
|
@ -12,4 +15,4 @@ $renderData['page'] = [
|
||||||
];
|
];
|
||||||
|
|
||||||
// Print page contents
|
// Print page contents
|
||||||
print $flashii->_TPL->render('main/index.tpl', $renderData);
|
print Main::$_TPL->render('main/index.tpl', $renderData);
|
||||||
|
|
Reference in a new issue