Current File : //var/webuzo-data/roundcube/plugins/webuzo/webuzo.php |
<?php
class webuzo extends rcube_plugin{
public $task = '?(?!logout).*';
public $noframe = true;
public $noajax = false;
public $home;
function init(){
global $globals;
// Include globals
if(is_readable('/usr/local/webuzo/universal.php')){
include('/usr/local/webuzo/universal.php');
include('/usr/local/webuzo/globals.php');
}
// Include Plugins classes
require_once(__DIR__ . '/autologon/autologon.php');
require_once(__DIR__ . '/soft_password/soft_password.php');
require_once(__DIR__ . '/soft2fa/soft2fa.php');
// Pass $this (the plugin instance) to the class
$autologon = new autologon($this);
$soft_password = new soft_password($this);
$soft2fa = new soft2fa($this);
// Init Plugins
$autologon->initialize();
$soft_password->initialize();
$soft2fa->initialize();
}
public function writedata($path, $data, $set_perms = 0){
global $globals;
@define('SOFTACULOUS', 1);
include_once($globals['mainfiles'].'/functions/file_functions.php');
$globals['mainfiles'].'/functions/file_functions.php';
$ret = $this->write_raw_data($path, json_encode($data, JSON_PRETTY_PRINT), $set_perms);
return $ret;
}
private function writefile($file, $data, $overwrite = 0, $chmod = 0, $dchmod = 0){
return writefile_fn($file, $data, $overwrite, $chmod, $dchmod);
}
private function write_raw_data($path, $data, $set_perms = 0){
global $globals;
$ret = $this->writefile($path, $data, 1);
if(posix_getuid() == 0){
chown(dirname($path), $globals['panel_user']);
chgrp(dirname($path), $globals['panel_user']);
chown($path, $globals['panel_user']);
chgrp($path, $globals['panel_user']);
}
if(!empty($set_perms)){
chmod($path, $set_perms);
}
return $ret;
}
public function loaddata($path){
if(!file_exists($path)){
return [];
}
$path = $this->cleanpath($path);
$realpath = $this->cleanpath(realpath($path));
// Security Fix
if($path !== $realpath){
return [];
}
$data = file_get_contents($path);
$data = json_decode($data, true);
$json_error = json_last_error();
// Retry to load if there was no error
if(!is_array($data) && empty($json_error)){
$data = file_get_contents($path);
$data = json_decode($data, true);
}
// Is it a serialized string !
if(empty($data)){
$tmp = file_get_contents($path);
if($this->soft_is_serialized_str($tmp)){
$data = unserialize($tmp);
}
}
return $data;
}
private function cleanpath($path){
$path = str_replace('\\\\', '/', $path);
$path = str_replace('\\', '/', $path);
$path = str_replace('//', '/', $path);
if($path == '/'){
return '/';
}
return rtrim($path, '/');
}
private function soft_is_serialized_str($data, $strict = true){
// if it isn't a string, it isn't serialized.
if (!is_string($data)) {
return false;
}
$data = trim($data);
if ('N;' == $data) {
return true;
}
if (strlen($data) < 4) {
return false;
}
if (':' !== $data[1]) {
return false;
}
if ($strict) {
$lastc = substr($data, -1);
if (';' !== $lastc && '}' !== $lastc) {
return false;
}
} else {
$semicolon = strpos($data, ';');
$brace = strpos($data, '}');
// Either ; or } must exist.
if (false === $semicolon && false === $brace) {
return false;
}
// But neither must be in the first X characters.
if (false !== $semicolon && $semicolon < 3) {
return false;
}
if (false !== $brace && $brace < 4) {
return false;
}
}
$token = $data[0];
switch ($token) {
case 's' :
if ($strict) {
if ('"' !== substr($data, -2, 1)) {
return false;
}
} elseif (false === strpos($data, '"')) {
return false;
}
// or else fall through
case 'a' :
case 'O' :
return (bool) preg_match("/^{$token}:[0-9]+:/s", $data);
case 'b' :
case 'i' :
case 'd' :
$end = $strict ? '$' : '';
return (bool) preg_match("/^{$token}:[0-9.E-]+;$end/", $data);
}
return false;
}
public function generateRandStr($length, $special = 0){
global $globals, $softpanel;
$randstack = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
$len = count($randstack) - 1;
$specialchars = array('!', '[', ']', '(', ')', '.', '-', '@');
if(!empty($softpanel->special_pass_chars)){
$specialchars = $softpanel->special_pass_chars;
}
$randstr = '';
while(strlen($randstr) < $length){
$tmp = function_exists('random_int') ? random_int(0, $len) : array_rand($randstack);
$randstr .= $randstack[$tmp];
if(!empty($special) && strlen($randstr) < $length && (strlen($randstr)%2 == 0)){
$randstr .= $specialchars[array_rand($specialchars)];
}
}
return str_shuffle($randstr);
}
}