Skip to content

Commit

Permalink
Обновил библиотеку Mercury, теперь можно по желанию отключать безопас…
Browse files Browse the repository at this point in the history
…ный режим securityMode. Обновил ключи удаленного доступа, теперь их может быть много и с именами :)
  • Loading branch information
hobbytes committed Aug 7, 2018
1 parent 2cc35b2 commit b44edae
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 60 deletions.
10 changes: 4 additions & 6 deletions login.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
<div id="login" style="margin:auto; text-align:center; max-width:500px; height:80%;">
<div style="text-align:center; margin:auto; width:auto; height:auto; ">
<div id="loginin" style="padding-top: 50%;">
<div id="labelos" style="font-size:30px; padding:30px; color:#fff; text-shadow: 1px 1px 1px grey; user-select: none; cursor: default; text-transform:uppercase; font-weight: 700;">Forest OS</div>
<div id="labelos">Forest OS</div>
<?

/* #Display errors */
/*
ini_set('display_errors','On');
error_reporting(E_ALL);
*/

ini_set('display_errors','Off');

if (function_exists('date_default_timezone_set'))
date_default_timezone_set('Europe/Moscow');
Expand Down Expand Up @@ -105,7 +103,7 @@
?>
</div>
<?
$gui->button($language[$_SESSION['locale'].'_login_button'], '#fff', '#092738', '30','logins');
$gui->button($language[$_SESSION['locale'].'_login_button'], '#fff', '#f45c43', '30','logins');
$gui->formend();

$timezone = file_get_contents('system/users/'.$_SESSION['superuser'].'/settings/timezone.foc');
Expand Down
5 changes: 2 additions & 3 deletions os.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?

/* #Display errors

/* #Display errors */
ini_set('display_errors','Off');
error_reporting(E_ALL);
*/

require 'system/core/library/gui.php';
require 'system/core/library/bd.php';
Expand Down
2 changes: 2 additions & 0 deletions system/apps/Settings/lang/security.lang
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ru_tempkey_copy = 'Скопируйте этот ключ: '
ru_notchangepass = 'Пароль изменен!'
ru_notnewerrorpass = 'Новые пароли не совпадают!'
ru_notolderrorpass = 'Вы ввели неправильный старый пароль!'
ru_namekey_label = 'Введите имя ключа'

en_settings_security = Security
en_changepassword_label = Change Password
Expand All @@ -30,3 +31,4 @@ en_tempkey_copy = 'Copy this key: '
en_notchangepass = 'Password changed!'
en_notnewerrorpass = 'New passwords do not match!'
en_notolderrorpass = 'You have entered the wrong old password!'
en_namekey_label = 'Enter the key name'
105 changes: 89 additions & 16 deletions system/apps/Settings/security.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
$AppID = $_GET['appid'];
$AppName = $_GET['appname'];
$Folder = $_GET['destination'];
$erase = $_GET['erase'];
$oldpassword = $_GET['oldpassword'];
$newpassword = $_GET['newpassword'];
$checkpassword = $_GET['checkpassword'];

$GetKeyStatus = $_GET['getkey'];

/* get localization file */
$language_security = parse_ini_file('lang/security.lang');
Expand All @@ -32,26 +27,64 @@

<?php

/* get data */

$erase = $_GET['erase'];
$oldpassword = $_GET['oldpassword'];
$newpassword = $_GET['newpassword'];
$checkpassword = $_GET['checkpassword'];
$GetKeyStatus = $_GET['getkey'];

if($erase == 'true'){
file_put_contents('../../core/journal.mcj','');
}

$settingsbd = new readbd;
$gui = new gui;
$infob = new info;
global $security;

if(isset($_GET['delete_key_name'])){
$delete_key_name = $_GET['delete_key_name'];
$TempKeyArray = $settingsbd->readglobal2("TempKey", "forestusers", "login", $_SESSION["loginuser"], true);

$get_keys = explode("[", $TempKeyArray);

foreach ($get_keys as $key) {
if(!empty($key)){
$key = str_replace(']', '', $key);
if(preg_match("/$delete_key_name/",$key)){
$_TempKeyArray = str_replace('['.$key.']', '', $TempKeyArray);
if($_TempKeyArray != $TempKeyArray){
$settingsbd->updatebd("forestusers", "TempKey", $_TempKeyArray, "login", $_SESSION["loginuser"]);
}
}
}
}
}

if($GetKeyStatus == 'true'){
$settingsbd->readglobal2("password", "forestusers", "login", $_SESSION["loginuser"]);

$GetKeyName = $_GET['key_name'];

if(empty($GetKeyName)){
$GetKeyName = 'fos';
}

$_p = $settingsbd->readglobal2("password", "forestusers", "login", $_SESSION["loginuser"], true);
$TempKeyArray = $settingsbd->readglobal2("TempKey", "forestusers", "login", $_SESSION["loginuser"], true);
$settingsbd->addColumn("forestusers", "TempKey", "VARCHAR", "255");
$GetKey = uniqid('fos-',$security->crypt_s(md5($getdata.date('d-m-y-h-i-s')), $_SESSION["loginuser"]));

$GetKey = uniqid($GetKeyName.'-', $security->crypt_s(md5($_p.date('d-m-y-h-i-s')), $_SESSION["loginuser"]));
$TempKeyArray = $TempKeyArray.'['.$GetKey.']';

if(!empty($GetKey)){
$settingsbd->updatebd("forestusers","TempKey",$GetKey,"login",$_SESSION["loginuser"]);
$settingsbd->updatebd("forestusers", "TempKey", $TempKeyArray, "login", $_SESSION["loginuser"]);
}
}

if($GetKeyStatus == 'false'){
$settingsbd->updatebd("forestusers","TempKey","0","login",$_SESSION["loginuser"]);
$settingsbd->updatebd("forestusers","TempKey","","login",$_SESSION["loginuser"]);
}

if(!empty($oldpassword) && !empty($newpassword) && !empty($checkpassword)){
Expand Down Expand Up @@ -102,21 +135,47 @@
<b style="font-size:20px;">
'.$language_security[$_SESSION['locale'].'_tempkey_label'].'
</b>
<div id="GetKey'.$AppID.'" onClick="GetKey'.$AppID.'();" class="ui-forest-button ui-forest-accept" style="margin:10 0;">
'.$language_security[$_SESSION['locale'].'_tempkey_button'].'
</div>
<div id="EraseKey'.$AppID.'" onClick="EraseKey'.$AppID.'();" class="ui-forest-button ui-forest-cancel" style="margin:10 0;">
'.$language_security[$_SESSION['locale'].'_tempkeyerase_button'].'
</div>';
<br><br>
<div>'.$language_security[$_SESSION['locale'].'_namekey_label'].':</div>';
$gui->inputslabel('', 'text', 'key_name'.$AppID, 'fos','25', $language_security[$_SESSION['locale'].'_namekey_label']);

if(!empty($GetKey)){
echo
$language_security[$_SESSION['locale'].'_tempkey_copy'].'
<div style="margin: 10 0; padding: 7px; font-weight: 900; width: max-content; border: 2px dashed #8c7f3b; background: #e6d26a;">
<div style="margin: 10 0; padding: 7px; font-weight: 900; width: max-content; border: 2px dashed #144015; background: #4caf50; color: #074009;">
'.$GetKey.'
</div>';
}

echo '<div id="GetKey'.$AppID.'" onClick="GetKey'.$AppID.'();" class="ui-forest-button ui-forest-accept" style="margin:10 0;">
'.$language_security[$_SESSION['locale'].'_tempkey_button'].'
</div>';

$TempKeyArray = $settingsbd->readglobal2("TempKey", "forestusers", "login", $_SESSION["loginuser"], true);

if(!empty($TempKeyArray)){
$get_keys = explode("[", $TempKeyArray);

foreach ($get_keys as $key) {
$temp = stristr($key, '.', true);
$key = stristr($key, '-', true);

if(!empty($key)){
echo '<div style="margin: 10 0; padding: 7px; min-width:70px; font-weight: 900; width: max-content; border: 2px dashed #8c7f3b; background: #e6d26a;">
'.$key.'
<div style="float:right; color:#e66a6a;" onClick="DeleteKey'.$AppID.'(\''.$temp.'\')" class="ui-forest-blink">x</div>
</div>';
}
}
}

unset($get_keys, $key, $TempKeyArray);

echo '<div id="EraseKey'.$AppID.'" onClick="EraseKey'.$AppID.'();" class="ui-forest-button ui-forest-cancel" style="margin:10 0;">
'.$language_security[$_SESSION['locale'].'_tempkeyerase_button'].'
</div>';

echo '</div><hr>';

$infob->readstat('../../core/journal.mcj');
Expand All @@ -131,7 +190,9 @@

$AppContainer->EndContainer();
?>

<script>

<?php
// back button
$AppContainer->Event(
Expand All @@ -148,10 +209,22 @@
$Folder,
'security',
array(
'key_name' => '"+escape($("#key_name'.$AppID.'").val())+"',
'getkey' => 'true'
)
);

// Delete Key
$AppContainer->Event(
"DeleteKey",
'key',
$Folder,
'security',
array(
'delete_key_name' => '"+key+"'
)
);

// Erase Key
$AppContainer->Event(
"EraseKey",
Expand Down
1 change: 0 additions & 1 deletion system/apps/Settings/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
$AppContainer->StartContainer();
?>

<div id="<?echo $AppName.$AppID;?>" style="background-color:#f2f2f2; height:500px; max-height:95%; max-width:100%; width:800px; padding-top:10px; border-radius:0px 0px 5px 5px; overflow:auto;">
<div style="width:100%; text-align:left; padding-bottom:10px; font-size:30px; border-bottom:#d8d8d8 solid 2px; text-overflow:ellipsis; overflow:hidden;">
<span onClick="back<?echo $AppID;?>();" class="ui-forest" style="background-color:#d8d8d8; color:#000; border-radius:30%; cursor:pointer; font-size:25px; margin-left:5px;"> &#9668 </span><?echo $language_users[$_SESSION['locale'].'_settings_users']?></div>
<?php
Expand Down
17 changes: 17 additions & 0 deletions system/core/design/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,23 @@ body {
-webkit-backdrop-filter: blur(3px);
}

#labelos{
font-size: 30px;
padding: 30px;
color: #fff;
text-shadow: 0px 0px 1px #8e8e8e;
user-select: none;
cursor: default;
text-transform: uppercase;
font-weight: 700;
transition: all 0.2s ease;
}

#labelos:hover{
color: #8bc34a;
text-shadow: 0px 0px 1px #afffb2;
}

::-webkit-scrollbar {
width: 5px;
height: 5px;
Expand Down
11 changes: 7 additions & 4 deletions system/core/library/Mercury/AppContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AppContainer {
public $width = '800px'; // app container width @string
public $customStyle = NULL; // custom CSS style @string
public $isMobile = NULL; // which device style @string
public $securityMode = true; // use security fucntion @boolean
public $showError = false; // error display @boolean
public $showStatistics = false; // statistics display @boolean

Expand Down Expand Up @@ -70,10 +71,12 @@ public function StartContainer(){
}

// check security
global $security;
require $_SERVER['DOCUMENT_ROOT'].'/system/core/library/etc/security.php';
$security = new security;
$security->appprepare();
if($this->securityMode){
global $security;
require_once $_SERVER['DOCUMENT_ROOT'].'/system/core/library/etc/security.php';
$security = new security;
$security->appprepare();
}

// find libraries
if(!empty($this->LibraryArray)){
Expand Down
28 changes: 23 additions & 5 deletions system/core/library/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public function construct($what, $type, $keyaccess = NULL){
$bds->readglobalfunction('password', 'users', $what, $type);
$this->_password = $getdata;
}else{
$this->_login = $bds->readglobal2("login", "forestusers", "TempKey", $keyaccess, true);
$this->_password = $bds->readglobal2("password", "forestusers", "TempKey", $keyaccess, true);
$this->_login = $bds->readglobal2("login", "forestusers", "TempKey", $keyaccess, true, true);
$this->_password = $bds->readglobal2("password", "forestusers", "TempKey", $keyaccess, true, true);
}
}

Expand All @@ -25,6 +25,7 @@ public function isAuth() {
else return false;
}


/**
* @param string $login
* @param string $password
Expand All @@ -34,8 +35,8 @@ public function auth($login, $password, $keyaccess = NULL) {
if(!empty($keyaccess)){
$bds = new readbd;
global $getdata;
$login = $bds->readglobal2("login", "forestusers", "TempKey", $keyaccess, true);
$password = $bds->readglobal2("password", "forestusers", "TempKey", $keyaccess, true);
$login = $bds->readglobal2("login", "forestusers", "TempKey", $keyaccess, true, true);
$password = $bds->readglobal2("password", "forestusers", "TempKey", $keyaccess, true, true);
if(empty($login) && empty($password)){
global $infob;
$infob->writestat('WARNING! Wrong Access Key -> '.$keyaccess, 'system/core/journal.mcj');
Expand All @@ -49,9 +50,26 @@ public function auth($login, $password, $keyaccess = NULL) {
$_SESSION["loginuser"] = $login;

if(!empty($keyaccess)){

$bds = new readbd;
global $getdata;
$bds->updatebd("forestusers", "TempKey", "0", "login", $login);

$TempKeyArray = $bds->readglobal2("TempKey", "forestusers", "login", $login, true);

$get_keys = explode("[", $TempKeyArray);

foreach ($get_keys as $key) {
if(!empty($key)){
$key = str_replace(']', '', $key);
if(preg_match("/$keyaccess/", $key)){
$_TempKeyArray = str_replace('['.$key.']', '', $TempKeyArray);
if($_TempKeyArray != $TempKeyArray){
$bds->updatebd("forestusers", "TempKey", $_TempKeyArray, "login", $login);
}
}
}
}

}

return true;
Expand Down
9 changes: 7 additions & 2 deletions system/core/library/bd.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ public static function addColumn($table, $newColumn, $type, $size){
}
}

public static function readglobal2($globaldata,$from,$what,$like, $Return = false){
public static function readglobal2($globaldata,$from,$what,$like, $Return = false, $likeMode = false){
global $getdata;
$conn = new PDO (DB_DSN, DB_USERNAME, DB_PASSWORD);
$sql = "SELECT $globaldata,$what FROM $from where $what='$like'";
if($likeMode){
$sql = "SELECT $globaldata,$what FROM $from where $what like '%$like%'";
}else{
$sql = "SELECT $globaldata,$what FROM $from where $what='$like'";
}

$id = $conn->query($sql);
$row = $id->fetch();
if(!$Return){
Expand Down
8 changes: 5 additions & 3 deletions system/core/library/etc.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function browser($agent) {
}

function writestat($alarmbody,$folder){
include '../bd.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/system/core/library/bd.php';
global $getdata, $getstat, $security;
//$maxFileSize = '10000'; //Max size for journal file
//$currentFileSize = filesize($folder); //current size of journal file
Expand All @@ -47,11 +47,13 @@ function writestat($alarmbody,$folder){
}

function readstat($folder){

if(!isset($_SESSION)){
session_start();
}
include './etc/security.php';
include '../bd.php';

require_once $_SERVER['DOCUMENT_ROOT'].'/system/core/library/etc/security.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/system/core/library/bd.php';
global $getdata, $getstat;
$security = new security;
$bd = new readbd;
Expand Down
Loading

0 comments on commit b44edae

Please sign in to comment.