Skip to content

Commit

Permalink
first upload
Browse files Browse the repository at this point in the history
  • Loading branch information
9r3i committed Nov 12, 2022
1 parent 5a661a4 commit ba13ec7
Show file tree
Hide file tree
Showing 315 changed files with 13,320 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# options - no indexes and symlinks
Options -Indexes
Options +SymlinksIfOwnerMatch

# error handlers
ErrorDocument 403 "error: 403 Forbidden"
ErrorDocument 404 "error: 404 Not Found"
ErrorDocument 500 "error: 500 Internal Server Error"
1 change: 1 addition & 0 deletions databases/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deny from all
3 changes: 3 additions & 0 deletions databases/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
header('content-type:text/plain',true,401);
exit('Error: 401 Unauthorized.');
Binary file added databases/root.sdb
Binary file not shown.
Binary file added databases/site.sdb
Binary file not shown.
1 change: 1 addition & 0 deletions eday/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deny from all
1 change: 1 addition & 0 deletions eday/classes/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deny from all
133 changes: 133 additions & 0 deletions eday/classes/admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php
/* class admin for e-day
* started at august 25th 2018
*/
class admin{
private $page=false;
private $method=false;
private $args=[];
private $loaded=[];
private $errors=[];
public $error=false;
public $error_level=0;
function __construct(){
$path=defined('EDAY_ADMIN_PATH')?EDAY_ADMIN_PATH:'';
$exp=explode('/',$path);
$this->page=$exp[0]?$exp[0]:false;
$this->method=isset($exp[1])&&$exp[1]?$exp[1]:false;
$this->args=array_slice($exp,2);
return $this;
}
/* ----- static functions ----- */
public static function hasAccess(){
return defined('EDAY_ADMIN_PATH')?true:false;
}
public static function isLogin(){
if(!$_COOKIE['eday-token']
||!preg_match('/^eday\-[a-z0-9]{5,7}$/',$_COOKIE['eday-token'])){
@setcookie('eday-token','',time()-10);
return false;
}
if(defined('EDAY_ADMIN_TOKEN')
&&defined('EDAY_ADMIN_USERNAME')
&&defined('EDAY_ADMIN_TYPE')
&&defined('EDAY_ADMIN_ID')
&&password_verify($_COOKIE['eday-token'],EDAY_ADMIN_TOKEN)){
return (object)[
'username'=>EDAY_ADMIN_USERNAME,
'token'=>EDAY_ADMIN_TOKEN,
'type'=>EDAY_ADMIN_TYPE,
'id'=>EDAY_ADMIN_ID,
];
}
$db=site::db();
$sel=$db->query('select * from logs where token="'.$_COOKIE['eday-token'].'"');
if(!$sel||!isset($sel[0])){
@setcookie('eday-token','',time()-10);
return false;
}
$user=$db->query('select * from users where username="'.$sel[0]['username'].'"');
if(!$user||!isset($user[0])){
@setcookie('eday-token','',time()-10);
return false;
}
define('EDAY_ADMIN_TOKEN',password_hash($sel[0]['token'],PASSWORD_BCRYPT));
define('EDAY_ADMIN_USERNAME',$sel[0]['username']);
define('EDAY_ADMIN_TYPE',$user[0]['type']);
define('EDAY_ADMIN_ID',$user[0]['id']);
return (object)[
'username'=>$sel[0]['username'],
'token'=>$sel[0]['token'],
'type'=>$user[0]['type'],
'id'=>$user[0]['id'],
];
}
/* ----- static functions - require access ----- */
public static function editorPath(){
if(!self::hasAccess()){return false;}
$editor=self::config('editor');
return EDAY_EDITOR_PATH.$editor.'/'.$editor.'.js';
}
public static function config($k=null,$c='config'){
if(!self::hasAccess()){return false;}
$ini=@parse_ini_file(EDAY_ADMIN_DIR.'config.ini',true);
$ini=is_array($ini)?$ini:[];
$config=is_string($c)&&isset($ini[$c])?$ini[$c]:$ini;
return is_string($k)&&isset($config[$k])?$config[$k]:$config;
}
public static function token(){
if(!self::hasAccess()){return false;}
return 'eday-'.base_convert(mt_rand(),10,36);
}
public static function themeURL($p=''){
if(!self::hasAccess()){return false;}
if(!defined('EDAY_ACCESS_TOKEN')){return false;}
if(preg_match('/^js/i',$p)){
$p=preg_replace('/^js/i','script',$p);
$g=base64_encode(@file_get_contents(EDAY_ROOT.$p));
return 'data:application/javascript;base64,'.$g;
}return EDAY_ADDR.'files/kitchen/'.$p;
}
public static function redirect($k=null){
if(!self::hasAccess()||!is_string($k)){return false;}
header('location: '.site::url.'?admin='.$k);
exit;
}
public static function html($p=''){
if(!self::hasAccess()){return false;}
$f=EDAY_ADMIN_DIR.'pages/'.$p.'.php';
return is_file($f)?@require($f):false;
}
/* ----- non-static functions ----- */
public function isLoaded($k=null){
return is_string($k)&&in_array($k,$this->loaded)?true:false;
}
public function start(){
if(!self::isLogin()&&$this->page!='log'){
return self::redirect('log/in');
}
$page=$this->page($this->page);
if(!$page){return false;}
if(!is_string($this->method)||!method_exists($page,$this->method)){
return $this->error('Admin page "'.$this->page
.'" method "'.$this->method.'" is not available.',4);
}
$call=@\call_user_func_array([$page,$this->method],$this->args);
return $call!==false?true:$this->error('Failed to execute admin page "'.$this->page.'".',2);
}
private function page($k=null){
if(!is_string($k)){return $this->error('Invalid admin page.',16);}
$f=EDAY_ADMIN_DIR.'kitchen/'.$k.'.php';
if(!is_file($f)){return $this->error('Admin page "'.$k.'" is not available.',8);}
if(in_array($k,$this->loaded)){
return $this->error('Admin page "'.$k.'" has been loaded.',1);
}$this->loaded[]=$k;
return require_once($f);
}
private function error($s=null,$l=1){
$this->error_level=$l;
$this->error=is_string($s)?$s:'Unknown error.';
$this->errors[]=$this->error;
return false;
}
}
153 changes: 153 additions & 0 deletions eday/classes/api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php
/* class api for e-day
* started at august 24th 2018
*/
class api{
const version='1.0.0';
protected $errors=[];
protected $methods=[];
public $error=false;
public function __construct(){
/* check error */
if(eday::$error){$this->error=eday::$error;}
/* return this object */
return $this;
}
public function serverStart($l=0){
/* set time limit */
@set_time_limit($l);
/* set request header */
$this->serverHeader();
/* set registered method */
$this->methods=[
'draw'=>'serverDraw',
];
/* check eday request */
if(isset($_POST['eday'])){
return $this->serverLoad();
}return false;
}
private function serverDraw($class=null,$method=null){
return false;
}
private function serverLoad(){
/* check error */
if($this->error){
$res['message']=$this->error;
return $this->serverResult($this->serverEncode($res,$ax));
}
/* get client type */
$ax=isset($_GET['client'])&&$_GET['client']=='ajax'?true:false;
$res=array('status'=>'error','message'=>'Invalid request.');
/* decode request */
$get=$this->serverDecode($_POST['eday'],$ax);
if(!$get){
$res['message']='Failed to decode request.';
return $this->serverResult($this->serverEncode($res,$ax));
}
/* check timezone request */
if(isset($get['timezone'])){
if(!@date_default_timezone_set($get['timezone'])){
$res['message']='Invalid timezone "'.$get['timezone'].'".';
return $this->serverResult($this->serverEncode($res,$ax));
}
}
/* check username and password */
if(!isset($get['username'],$get['password'])){
$res['message']='Require username and password.';
return $this->serverResult($this->serverEncode($res,$ax));
}
/* validation username and password */
if(!preg_match('/^[a-z0-9]+$/',$get['username'])){
$res['message']='Require username and password.';
return $this->serverResult($this->serverEncode($res,$ax));
}
$db=site::db();
$sel=$db->query('select * from users where username="'.$get['username'].'"');
if(!$sel||$db->error||!isset($sel[0])||!password_verify($get['password'],$sel[0]['password'])){
$res['message']=$db->error?$db->error:'Invalid username or password.';
return $this->serverResult($this->serverEncode($res,$ax));
}
/* check request */
if(!isset($get['request'])){
$res['message']='Require method request.';
return $this->serverResult($this->serverEncode($res,$ax));
}
/* set arguments */
$args=isset($get['args'])&&is_array($get['args'])?$get['args']:[];
/* check method */
if(!@array_key_exists($get['request'],$this->methods)
||!method_exists($this,$this->methods[$get['request']])){
$res['message']='Method request does not exist.';
return $this->serverResult($this->serverEncode($res,$ax));
}
/* start execution request */
$exec=false;
try{
$exec=@\call_user_func_array([$this,$this->methods[$get['request']]],$args);
if(eday::$error){$this->error=eday::$error;}
elseif(!$exec){
throw new Exception('Failed to execute API request.');
}
}catch(Exception $e){
$this->error=$e->getMessage();
}
/* check result */
if(!$exec||$this->error){
$res['message']=$this->error?$this->error:'Failed to execute request.';
return $this->serverResult($this->serverEncode($res,$ax));
}
/* prepare result output */
$res['status']=$this->error?'error':'OK';
$res['message']=$this->error?$this->error:'connected';
$res['result']=$exec;
$res['errors']=$this->errors;
$res['error']=$this->error;
$res['info']=$this->serverInfo();
/* return the result */
return $this->serverResult($this->serverEncode($res,$ax));
}
private function serverEncode($s=null,$a=false){
return @base64_encode($a?@json_encode($s):@serialize($s));
}
private function serverDecode($s=null,$a=false){
$s=@base64_decode($s);
return $a?@json_decode($s,true):@unserialize($s);
}
private function serverInfo(){
return [
'api::version'=>$this::version,
'eday::version'=>eday::version,
'php::version'=>PHP_VERSION,
'request_length'=>strlen($_POST['eday']),
'memory_usage'=>number_format(memory_get_usage()/1024,2,'.',''),
'memory_peak_usage'=>number_format(memory_get_peak_usage()/1024,2,'.',''),
'precess_time'=>number_format(microtime(true)-$_SERVER['REQUEST_TIME_FLOAT'],3,'.',''),
'remote_addr'=>$_SERVER['REMOTE_ADDR'],
];
}
private function serverResult($s=null){
header('HTTP/1.1 200 OK');
header('Content-Length: '.strlen($s));
exit($s);
}
private function serverHeader(){
/* access control - to allow the access via ajax */
header('Access-Control-Allow-Origin: *'); /* allow origin */
header('Access-Control-Request-Method: POST, GET, OPTIONS'); /* request method */
header('Access-Control-Request-Headers: X-PINGOTHER, Content-Type'); /* request header */
header('Access-Control-Max-Age: 86400'); /* max age (24 hours) */
header('Access-Control-Allow-Credentials: true'); /* allow credentials */
/* set content type of response header */
header('Content-Type: text/plain;charset=utf-8;');
/* checking options */
if(isset($_SERVER['REQUEST_METHOD'])&&strtoupper($_SERVER['REQUEST_METHOD'])=='OPTIONS'){
header('Content-Language: en-US');
header('Content-Encoding: gzip');
header('Content-Length: 0');
header('Vary: Accept-Encoding, Origin');
header('HTTP/1.1 200 OK');
exit;
}
}
}
87 changes: 87 additions & 0 deletions eday/classes/base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/* class base for e-day
* started at august 27th 2018
*/
class base{
/* parse menu
* @param $menus - must be an array, generated by parseMenuChildren
* @example:
$sel=$db->query('SELECT * FROM `menus`');
$parsed=base::parseMenuChildren($sel);
$menus=base::parseMenu($parsed);
*/
public static function parseMenu($menus=null,$pr=0){
if(!is_array($menus)){return false;}
$x=isset($menus[$pr])?$menus[$pr]:[];
unset($menus[$pr]);$r=[];
foreach($x as $k=>$v){
if(isset($menus[$k])){
$v[2]=\call_user_func_array([__CLASS__,__METHOD__],[$menus,$k]);
}
if($pr){$r[$k]=$v;}
else{$r[$v[3]][$k]=$v;}
}return $r;
}
/* parse menu children
* - result array for parseMenu
* require menu keys:
* - int id
* - string name
* - string uri
* - string type
* - int parent
*/
public static function parseMenuChildren($menus=null){
if(!is_array($menus)){return false;}
$r=[];
foreach($menus as $menu){
$n=[$menu['uri'],$menu['name'],[],$menu['type']];
$r[$menu['parent']][$menu['id']]=$n;
}return $r;
}
/* price */
public static function price($s=null){
if(!is_numeric($s)&&!is_string($s)){$s=0;}
$d=str_split((string)$s);
$i=count($d);$r='';$c=0;
while($i--){
$c++;
if($c>=3){$c=0;$r=','.$d[$i].$r;}
else{$r=$d[$i].$r;}
}return preg_replace('/^[^0-9]+/','',$r);
}
/* time ago */
public static function timeAgo($str=null){
if(!is_int($str)&&!is_string($str)){return false;}
$time=preg_match('/^\d+$/',(string)$str)?(int)$str:strtotime((string)$str);
$now=time();$range=$now-$time;
$minute=floor($range/60);
$hour=floor($minute/60);
$day=floor($hour/24);
$date=date('d',$time);
$month=date('m',$time);
$year=date('Y',$time);
$moon=date('m')-$month;
if($range<60){return 'Just now';}
elseif($minute<60){
return ($minute<2?'A':$minute).' minute'.($minute>1?'s':'').' ago';
}elseif($hour<24&&$date==date('d')){
return ($hour<2?'An':$hour).' hour'.($hour>1?'s':'').' ago';
}elseif($day<date('t')&&$moon<2&&$year==date('Y')){
$week=date('W')-date('W',$time);
if(date('d')-$date==1){
return 'Yesterday at '.date('H:i',$time);
}elseif($week==0||date('d')-$date<3){
return date('l',$time).' at '.date('H:i',$time);
}elseif($week==1){
return 'Last week on '.date('l',$time).' at '.date('H:i',$time);
}return $week.' weeks ago on '.date('l',$time);
}elseif($year==date('Y')){
if($moon<2){
return 'Last month on '.date('F jS',$time);
}return date('F jS',$time);
}elseif(date('Y')-$year==1){
return 'Last year on '.date('F jS',$time);;
}return date('F jS Y',$time);
}
}
Loading

0 comments on commit ba13ec7

Please sign in to comment.