major refactoring of almost all files
This commit is contained in:
@@ -1,10 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
namespace Froxlor\System;
|
||||
|
||||
use Froxlor\Settings;
|
||||
use Froxlor\Database\Database;
|
||||
|
||||
use Exception;
|
||||
use Froxlor\Cron\TaskId;
|
||||
use Froxlor\Database\Database;
|
||||
use Froxlor\FroxlorLogger;
|
||||
use Froxlor\Settings;
|
||||
use PDO;
|
||||
|
||||
class Cronjob
|
||||
{
|
||||
@@ -20,15 +46,15 @@ class Cronjob
|
||||
*/
|
||||
public static function checkLastGuid()
|
||||
{
|
||||
$mylog = \Froxlor\FroxlorLogger::getInstanceOf();
|
||||
$mylog = FroxlorLogger::getInstanceOf();
|
||||
|
||||
$group_lines = array();
|
||||
$group_guids = array();
|
||||
$group_lines = [];
|
||||
$group_guids = [];
|
||||
$update_to_guid = 0;
|
||||
|
||||
$froxlor_guid = 0;
|
||||
$result_stmt = Database::query("SELECT MAX(`guid`) as `fguid` FROM `" . TABLE_PANEL_CUSTOMERS . "`");
|
||||
$result = $result_stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
$result = $result_stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$froxlor_guid = $result['fguid'];
|
||||
|
||||
// possibly no customers yet or f*cked up lastguid settings
|
||||
@@ -41,7 +67,6 @@ class Cronjob
|
||||
if (file_exists($g_file)) {
|
||||
if (is_readable($g_file)) {
|
||||
if (true == ($groups = file_get_contents($g_file))) {
|
||||
|
||||
$group_lines = explode("\n", $groups);
|
||||
|
||||
foreach ($group_lines as $group) {
|
||||
@@ -57,7 +82,7 @@ class Cronjob
|
||||
continue;
|
||||
}
|
||||
|
||||
$guid = isset($group[2]) ? (int) $group[2] : 0;
|
||||
$guid = isset($group[2]) ? (int)$group[2] : 0;
|
||||
|
||||
if ($guid > $update_to_guid) {
|
||||
$update_to_guid = $guid;
|
||||
@@ -70,22 +95,22 @@ class Cronjob
|
||||
} elseif ($update_to_guid == $froxlor_guid) {
|
||||
// if it's equal, that means we already have a collision
|
||||
// to ensure it won't happen again, increase the guid by one
|
||||
$update_to_guid = (int) $update_to_guid ++;
|
||||
$update_to_guid = (int)$update_to_guid++;
|
||||
}
|
||||
|
||||
// now check if it differs from our settings
|
||||
if ($update_to_guid != Settings::Get('system.lastguid')) {
|
||||
$mylog->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_NOTICE, 'Updating froxlor last guid to ' . $update_to_guid);
|
||||
$mylog->logAction(FroxlorLogger::CRON_ACTION, LOG_NOTICE, 'Updating froxlor last guid to ' . $update_to_guid);
|
||||
Settings::Set('system.lastguid', $update_to_guid);
|
||||
}
|
||||
} else {
|
||||
$mylog->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_NOTICE, 'File /etc/group not readable; cannot check for latest guid');
|
||||
$mylog->logAction(FroxlorLogger::CRON_ACTION, LOG_NOTICE, 'File /etc/group not readable; cannot check for latest guid');
|
||||
}
|
||||
} else {
|
||||
$mylog->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_NOTICE, 'File /etc/group not readable; cannot check for latest guid');
|
||||
$mylog->logAction(FroxlorLogger::CRON_ACTION, LOG_NOTICE, 'File /etc/group not readable; cannot check for latest guid');
|
||||
}
|
||||
} else {
|
||||
$mylog->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_NOTICE, 'File /etc/group does not exist; cannot check for latest guid');
|
||||
$mylog->logAction(FroxlorLogger::CRON_ACTION, LOG_NOTICE, 'File /etc/group does not exist; cannot check for latest guid');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,12 +118,12 @@ class Cronjob
|
||||
* Inserts a task into the PANEL_TASKS-Table
|
||||
*
|
||||
* @param
|
||||
* int Type of task
|
||||
* int Type of task
|
||||
* @param
|
||||
* string Parameter (possible to pass multiple times)
|
||||
* string Parameter (possible to pass multiple times)
|
||||
*
|
||||
* @author Florian Lippert <flo@syscp.org>
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @author Florian Lippert <flo@syscp.org> (2003-2009)
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
*/
|
||||
public static function inserttask($type, ...$params)
|
||||
{
|
||||
@@ -121,81 +146,81 @@ class Cronjob
|
||||
$del_stmt = Database::prepare("
|
||||
DELETE FROM `" . TABLE_PANEL_TASKS . "` WHERE `type` = :type
|
||||
");
|
||||
Database::pexecute($del_stmt, array(
|
||||
Database::pexecute($del_stmt, [
|
||||
'type' => $type
|
||||
));
|
||||
]);
|
||||
|
||||
// insert the new task
|
||||
Database::pexecute($ins_stmt, array(
|
||||
Database::pexecute($ins_stmt, [
|
||||
'type' => $type,
|
||||
'data' => ''
|
||||
));
|
||||
]);
|
||||
} elseif ($type == TaskId::CREATE_HOME && count($params) == 4 && $params[0] != '' && $params[1] != '' && $params[2] != '' && ($params[3] == 0 || $params[3] == 1)) {
|
||||
$data = array();
|
||||
$data = [];
|
||||
$data['loginname'] = $params[0];
|
||||
$data['uid'] = $params[1];
|
||||
$data['gid'] = $params[2];
|
||||
$data['store_defaultindex'] = $params[3];
|
||||
$data = json_encode($data);
|
||||
Database::pexecute($ins_stmt, array(
|
||||
Database::pexecute($ins_stmt, [
|
||||
'type' => TaskId::CREATE_HOME,
|
||||
'data' => $data
|
||||
));
|
||||
]);
|
||||
} elseif ($type == TaskId::DELETE_CUSTOMER_FILES && isset($params[0]) && $params[0] != '') {
|
||||
$data = array();
|
||||
$data = [];
|
||||
$data['loginname'] = $params[0];
|
||||
$data = json_encode($data);
|
||||
Database::pexecute($ins_stmt, array(
|
||||
Database::pexecute($ins_stmt, [
|
||||
'type' => TaskId::DELETE_CUSTOMER_FILES,
|
||||
'data' => $data
|
||||
));
|
||||
]);
|
||||
} elseif ($type == TaskId::DELETE_EMAIL_DATA && count($params) == 2 && $params[0] != '' && $params[1] != '') {
|
||||
$data = array();
|
||||
$data = [];
|
||||
$data['loginname'] = $params[0];
|
||||
$data['email'] = $params[1];
|
||||
$data = json_encode($data);
|
||||
Database::pexecute($ins_stmt, array(
|
||||
Database::pexecute($ins_stmt, [
|
||||
'type' => TaskId::DELETE_EMAIL_DATA,
|
||||
'data' => $data
|
||||
));
|
||||
]);
|
||||
} elseif ($type == TaskId::DELETE_FTP_DATA && count($params) == 2 && $params[0] != '' && $params[1] != '') {
|
||||
$data = array();
|
||||
$data = [];
|
||||
$data['loginname'] = $params[0];
|
||||
$data['homedir'] = $params[1];
|
||||
$data = json_encode($data);
|
||||
Database::pexecute($ins_stmt, array(
|
||||
Database::pexecute($ins_stmt, [
|
||||
'type' => TaskId::DELETE_FTP_DATA,
|
||||
'data' => $data
|
||||
));
|
||||
]);
|
||||
} elseif ($type == TaskId::DELETE_DOMAIN_PDNS && isset($params[0]) && $params[0] != '' && Settings::Get('system.bind_enable') == '1' && Settings::Get('system.dns_server') == 'PowerDNS') {
|
||||
// -> if bind disabled or dns-server not PowerDNS -> no task
|
||||
$data = array();
|
||||
$data = [];
|
||||
$data['domain'] = $params[0];
|
||||
$data = json_encode($data);
|
||||
Database::pexecute($ins_stmt, array(
|
||||
Database::pexecute($ins_stmt, [
|
||||
'type' => TaskId::DELETE_DOMAIN_PDNS,
|
||||
'data' => $data
|
||||
));
|
||||
]);
|
||||
} elseif ($type == TaskId::DELETE_DOMAIN_SSL && isset($params[0]) && $params[0] != '') {
|
||||
$data = array();
|
||||
$data = [];
|
||||
$data['domain'] = $params[0];
|
||||
$data = json_encode($data);
|
||||
Database::pexecute($ins_stmt, array(
|
||||
Database::pexecute($ins_stmt, [
|
||||
'type' => TaskId::DELETE_DOMAIN_SSL,
|
||||
'data' => $data
|
||||
));
|
||||
]);
|
||||
} elseif ($type == TaskId::CREATE_CUSTOMER_BACKUP && isset($params[0]) && is_array($params[0])) {
|
||||
$data = json_encode($params[0]);
|
||||
Database::pexecute($ins_stmt, array(
|
||||
Database::pexecute($ins_stmt, [
|
||||
'type' => TaskId::CREATE_CUSTOMER_BACKUP,
|
||||
'data' => $data
|
||||
));
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an array of all cronjobs and when they last were executed
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getCronjobsLastRun()
|
||||
@@ -206,7 +231,7 @@ class Cronjob
|
||||
$result = Database::query($query);
|
||||
|
||||
$cronjobs_last_run = [];
|
||||
while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
|
||||
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
||||
$cronjobs_last_run[] = [
|
||||
'title' => $lng['crondesc'][$row['desc_lng_key']],
|
||||
'lastrun' => $row['lastrun']
|
||||
@@ -223,15 +248,15 @@ class Cronjob
|
||||
|
||||
$upd_stmt = Database::prepare("
|
||||
UPDATE `" . TABLE_PANEL_CRONRUNS . "` SET `isactive` = :active WHERE `module` = :module");
|
||||
Database::pexecute($upd_stmt, array(
|
||||
Database::pexecute($upd_stmt, [
|
||||
'active' => $isactive,
|
||||
'module' => $module
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an array of tasks that are queued to be run by the cronjob
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getOutstandingTasks()
|
||||
@@ -242,15 +267,14 @@ class Cronjob
|
||||
$result = Database::query($query);
|
||||
|
||||
$tasks = [];
|
||||
while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
|
||||
|
||||
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
||||
if ($row['data'] != '') {
|
||||
$row['data'] = json_decode($row['data'], true);
|
||||
}
|
||||
|
||||
$task_id = $row['type'];
|
||||
if (\Froxlor\Cron\TaskId::isValid($task_id)) {
|
||||
$task_constname = \Froxlor\Cron\TaskId::convertToConstant($task_id);
|
||||
if (TaskId::isValid($task_id)) {
|
||||
$task_constname = TaskId::convertToConstant($task_id);
|
||||
$task = [
|
||||
'desc' => isset($lng['tasks'][$task_constname]) ? $lng['tasks'][$task_constname] : $task_constname
|
||||
];
|
||||
@@ -294,7 +318,6 @@ class Cronjob
|
||||
public static function dieWithMail($message, $subject = "[froxlor] Cronjob error")
|
||||
{
|
||||
if (Settings::Get('system.send_cron_errors') == '1') {
|
||||
|
||||
$_mail = new Mailer(true);
|
||||
$_mailerror = false;
|
||||
$mailerr_msg = "";
|
||||
@@ -307,7 +330,7 @@ class Cronjob
|
||||
} catch (\PHPMailer\PHPMailer\Exception $e) {
|
||||
$mailerr_msg = $e->errorMessage();
|
||||
$_mailerror = true;
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$mailerr_msg = $e->getMessage();
|
||||
$_mailerror = true;
|
||||
}
|
||||
@@ -327,8 +350,8 @@ class Cronjob
|
||||
$upd_stmt = Database::prepare("
|
||||
UPDATE `" . TABLE_PANEL_CRONRUNS . "` SET `lastrun` = UNIX_TIMESTAMP() WHERE `cronfile` = :cron;
|
||||
");
|
||||
Database::pexecute($upd_stmt, array(
|
||||
Database::pexecute($upd_stmt, [
|
||||
'cron' => $cronname
|
||||
));
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
namespace Froxlor\System;
|
||||
|
||||
use Froxlor\Database\Database;
|
||||
use Froxlor\Froxlor;
|
||||
use Froxlor\Settings;
|
||||
use Froxlor\Validate\Validate;
|
||||
|
||||
class Crypt
|
||||
{
|
||||
@@ -48,7 +74,7 @@ class Crypt
|
||||
private static function specialShuffle($str = null)
|
||||
{
|
||||
$len = mb_strlen($str);
|
||||
$sploded = array();
|
||||
$sploded = [];
|
||||
while ($len-- > 0) {
|
||||
$sploded[] = mb_substr($str, $len, 1);
|
||||
}
|
||||
@@ -56,35 +82,6 @@ class Crypt
|
||||
return join('', $sploded);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make encrypted password from clear text password
|
||||
*
|
||||
* @author Michal Wojcik <m.wojcik@sonet3.pl>
|
||||
* @author Michael Kaufmann <mkaufmann@nutime.de>
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
*
|
||||
* 0 - default crypt (depends on system configuration)
|
||||
* 1 - MD5 $1$
|
||||
* 2 - BLOWFISH $2y$07$
|
||||
* 3 - SHA-256 $5$ (default)
|
||||
* 4 - SHA-512 $6$
|
||||
*
|
||||
* @param string $password
|
||||
* Password to be encrypted
|
||||
* @param bool $htpasswd
|
||||
* optional whether to generate a SHA1 password for directory protection
|
||||
*
|
||||
* @return string encrypted password
|
||||
*/
|
||||
public static function makeCryptPassword($password, $htpasswd = false)
|
||||
{
|
||||
if ($htpasswd) {
|
||||
return '{SHA}' . base64_encode(sha1($password, true));
|
||||
}
|
||||
$algo = Settings::Get('system.passwordcryptfunc') !== null ? Settings::Get('system.passwordcryptfunc') : PASSWORD_DEFAULT;
|
||||
return password_hash($password, $algo);
|
||||
}
|
||||
|
||||
/**
|
||||
* return an array of available hashes
|
||||
*
|
||||
@@ -95,9 +92,9 @@ class Crypt
|
||||
global $lng;
|
||||
|
||||
// get available pwd-hases
|
||||
$available_pwdhashes = array(
|
||||
$available_pwdhashes = [
|
||||
PASSWORD_DEFAULT => $lng['serversettings']['systemdefault']
|
||||
);
|
||||
];
|
||||
if (defined('PASSWORD_BCRYPT')) {
|
||||
$available_pwdhashes[PASSWORD_BCRYPT] = 'Bcrypt/Blowfish';
|
||||
}
|
||||
@@ -119,30 +116,30 @@ class Crypt
|
||||
* an error message will be output and 'exit' is called
|
||||
*
|
||||
* @param string $password
|
||||
* the password to validate
|
||||
* the password to validate
|
||||
*
|
||||
* @return string either the password or an errormessage+exit
|
||||
*/
|
||||
public static function validatePassword($password = null, $json_response = false)
|
||||
{
|
||||
if (Settings::Get('panel.password_min_length') > 0) {
|
||||
$password = \Froxlor\Validate\Validate::validate($password, Settings::Get('panel.password_min_length'), '/^.{' . (int) Settings::Get('panel.password_min_length') . ',}$/D', 'notrequiredpasswordlength', array(), $json_response);
|
||||
$password = Validate::validate($password, Settings::Get('panel.password_min_length'), '/^.{' . (int)Settings::Get('panel.password_min_length') . ',}$/D', 'notrequiredpasswordlength', [], $json_response);
|
||||
}
|
||||
|
||||
if (Settings::Get('panel.password_regex') != '') {
|
||||
$password = \Froxlor\Validate\Validate::validate($password, Settings::Get('panel.password_regex'), Settings::Get('panel.password_regex'), 'notrequiredpasswordcomplexity', array(), $json_response);
|
||||
$password = Validate::validate($password, Settings::Get('panel.password_regex'), Settings::Get('panel.password_regex'), 'notrequiredpasswordcomplexity', [], $json_response);
|
||||
} else {
|
||||
if (Settings::Get('panel.password_alpha_lower')) {
|
||||
$password = \Froxlor\Validate\Validate::validate($password, '/.*[a-z]+.*/', '/.*[a-z]+.*/', 'notrequiredpasswordcomplexity', array(), $json_response);
|
||||
$password = Validate::validate($password, '/.*[a-z]+.*/', '/.*[a-z]+.*/', 'notrequiredpasswordcomplexity', [], $json_response);
|
||||
}
|
||||
if (Settings::Get('panel.password_alpha_upper')) {
|
||||
$password = \Froxlor\Validate\Validate::validate($password, '/.*[A-Z]+.*/', '/.*[A-Z]+.*/', 'notrequiredpasswordcomplexity', array(), $json_response);
|
||||
$password = Validate::validate($password, '/.*[A-Z]+.*/', '/.*[A-Z]+.*/', 'notrequiredpasswordcomplexity', [], $json_response);
|
||||
}
|
||||
if (Settings::Get('panel.password_numeric')) {
|
||||
$password = \Froxlor\Validate\Validate::validate($password, '/.*[0-9]+.*/', '/.*[0-9]+.*/', 'notrequiredpasswordcomplexity', array(), $json_response);
|
||||
$password = Validate::validate($password, '/.*[0-9]+.*/', '/.*[0-9]+.*/', 'notrequiredpasswordcomplexity', [], $json_response);
|
||||
}
|
||||
if (Settings::Get('panel.password_special_char_required')) {
|
||||
$password = \Froxlor\Validate\Validate::validate($password, '/.*[' . preg_quote(Settings::Get('panel.password_special_char'), '/') . ']+.*/', '/.*[' . preg_quote(Settings::Get('panel.password_special_char'), '/') . ']+.*/', 'notrequiredpasswordcomplexity', array(), $json_response);
|
||||
$password = Validate::validate($password, '/.*[' . preg_quote(Settings::Get('panel.password_special_char'), '/') . ']+.*/', '/.*[' . preg_quote(Settings::Get('panel.password_special_char'), '/') . ']+.*/', 'notrequiredpasswordcomplexity', [], $json_response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,13 +155,13 @@ class Crypt
|
||||
* or if the very old md5() sum is used
|
||||
*
|
||||
* @param array $userinfo
|
||||
* user-data from table
|
||||
* user-data from table
|
||||
* @param string $password
|
||||
* the password to validate
|
||||
* the password to validate
|
||||
* @param string $table
|
||||
* either panel_customers or panel_admins
|
||||
* either panel_customers or panel_admins
|
||||
* @param string $uid
|
||||
* user-id-field in $table
|
||||
* user-id-field in $table
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
@@ -187,21 +184,49 @@ class Crypt
|
||||
}
|
||||
|
||||
if ($pwd_hash == $pwd_check || password_verify($password, $pwd_hash)) {
|
||||
|
||||
// check for update of hash (only if our database is ready to handle the bigger string)
|
||||
$is_ready = \Froxlor\Froxlor::versionCompare2("0.9.33", \Froxlor\Froxlor::getVersion()) <= 0 ;
|
||||
$is_ready = Froxlor::versionCompare2("0.9.33", Froxlor::getVersion()) <= 0;
|
||||
if ((password_needs_rehash($pwd_hash, $algo) || $update_hash) && $is_ready) {
|
||||
$upd_stmt = \Froxlor\Database\Database::prepare("
|
||||
$upd_stmt = Database::prepare("
|
||||
UPDATE " . $table . " SET `password` = :newpasswd WHERE `" . $uid . "` = :uid
|
||||
");
|
||||
$params = array(
|
||||
$params = [
|
||||
'newpasswd' => self::makeCryptPassword($password),
|
||||
'uid' => $userinfo[$uid]
|
||||
);
|
||||
\Froxlor\Database\Database::pexecute($upd_stmt, $params);
|
||||
];
|
||||
Database::pexecute($upd_stmt, $params);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make encrypted password from clear text password
|
||||
*
|
||||
* @param string $password
|
||||
* Password to be encrypted
|
||||
* @param bool $htpasswd
|
||||
* optional whether to generate a SHA1 password for directory protection
|
||||
*
|
||||
* @return string encrypted password
|
||||
* @author Michal Wojcik <m.wojcik@sonet3.pl>
|
||||
* @author Michael Kaufmann <mkaufmann@nutime.de>
|
||||
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||
*
|
||||
* 0 - default crypt (depends on system configuration)
|
||||
* 1 - MD5 $1$
|
||||
* 2 - BLOWFISH $2y$07$
|
||||
* 3 - SHA-256 $5$ (default)
|
||||
* 4 - SHA-512 $6$
|
||||
*
|
||||
*/
|
||||
public static function makeCryptPassword($password, $htpasswd = false)
|
||||
{
|
||||
if ($htpasswd) {
|
||||
return '{SHA}' . base64_encode(sha1($password, true));
|
||||
}
|
||||
$algo = Settings::Get('system.passwordcryptfunc') !== null ? Settings::Get('system.passwordcryptfunc') : PASSWORD_DEFAULT;
|
||||
return password_hash($password, $algo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
namespace Froxlor\System;
|
||||
|
||||
class IPTools
|
||||
@@ -25,23 +48,11 @@ class IPTools
|
||||
return implode('.', $netmask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an $address (IP) is IPv6
|
||||
*
|
||||
* @param string $address
|
||||
*
|
||||
* @return string|bool ip address on success, false on failure
|
||||
*/
|
||||
public static function is_ipv6($address)
|
||||
{
|
||||
return filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given $ip is in range of given ip/cidr range
|
||||
*
|
||||
* @param array $ip_cidr 0 => ip, 1 => netmask in decimal, e.g. [0 => '123.123.123.123', 1 => 24]
|
||||
* @param string $ip ip-address to check
|
||||
* @param string $ip ip-address to check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -59,11 +70,23 @@ class IPTools
|
||||
return (($ip_decimal & $netmask_decimal) == ($range_decimal & $netmask_decimal));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an $address (IP) is IPv6
|
||||
*
|
||||
* @param string $address
|
||||
*
|
||||
* @return string|bool ip address on success, false on failure
|
||||
*/
|
||||
public static function is_ipv6($address)
|
||||
{
|
||||
return filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given ipv6 $ip is in range of given ip/cidr range
|
||||
*
|
||||
* @param array $ip_cidr 0 => ip, 1 => netmask in decimal, e.g. [0 => '123:123::1', 1 => 64]
|
||||
* @param string $ip ip-address to check
|
||||
* @param string $ip ip-address to check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -87,12 +110,16 @@ class IPTools
|
||||
$start_result = '';
|
||||
for ($i = 0; $i < 8; $i++) {
|
||||
$start_result .= substr($start, $i * 4, 4);
|
||||
if ($i != 7) $start_result .= ':';
|
||||
if ($i != 7) {
|
||||
$start_result .= ':';
|
||||
}
|
||||
}
|
||||
$end_result = '';
|
||||
for ($i = 0; $i < 8; $i++) {
|
||||
$end_result .= substr($end, $i * 4, 4);
|
||||
if ($i != 7) $end_result .= ':';
|
||||
if ($i != 7) {
|
||||
$end_result .= ':';
|
||||
}
|
||||
}
|
||||
|
||||
$first = self::ip2long6($start_result);
|
||||
@@ -103,19 +130,6 @@ class IPTools
|
||||
return $in_range;
|
||||
}
|
||||
|
||||
private static function ip2long6($ip)
|
||||
{
|
||||
$ip_n = inet_pton($ip);
|
||||
$bits = 15; // 16 x 8 bit = 128bit
|
||||
$ipv6long = '';
|
||||
while ($bits >= 0) {
|
||||
$bin = sprintf("%08b", (ord($ip_n[$bits])));
|
||||
$ipv6long = $bin . $ipv6long;
|
||||
$bits--;
|
||||
}
|
||||
return gmp_strval(gmp_init($ipv6long, 2), 10);
|
||||
}
|
||||
|
||||
private static function inet6_expand(string $addr)
|
||||
{
|
||||
// Check if there are segments missing, insert if necessary
|
||||
@@ -123,9 +137,10 @@ class IPTools
|
||||
$part = explode('::', $addr);
|
||||
$part[0] = explode(':', $part[0]);
|
||||
$part[1] = explode(':', $part[1]);
|
||||
$missing = array();
|
||||
for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++)
|
||||
$missing = [];
|
||||
for ($i = 0; $i < (8 - (count($part[0]) + count($part[1]))); $i++) {
|
||||
array_push($missing, '0000');
|
||||
}
|
||||
$missing = array_merge($part[0], $missing);
|
||||
$part = array_merge($missing, $part[1]);
|
||||
} else {
|
||||
@@ -133,7 +148,9 @@ class IPTools
|
||||
}
|
||||
// Pad each segment until it has 4 digits
|
||||
foreach ($part as &$p) {
|
||||
while (strlen($p) < 4) $p = '0' . $p;
|
||||
while (strlen($p) < 4) {
|
||||
$p = '0' . $p;
|
||||
}
|
||||
}
|
||||
unset($p);
|
||||
// Join segments
|
||||
@@ -150,16 +167,37 @@ class IPTools
|
||||
{
|
||||
/* Make sure the prefix is a number between 1 and 127 (inclusive) */
|
||||
$prefix = intval($prefix);
|
||||
if ($prefix < 0 || $prefix > 128) return false;
|
||||
if ($prefix < 0 || $prefix > 128) {
|
||||
return false;
|
||||
}
|
||||
$mask = '0b';
|
||||
for ($i = 0; $i < $prefix; $i++) $mask .= '1';
|
||||
for ($i = strlen($mask) - 2; $i < 128; $i++) $mask .= '0';
|
||||
for ($i = 0; $i < $prefix; $i++) {
|
||||
$mask .= '1';
|
||||
}
|
||||
for ($i = strlen($mask) - 2; $i < 128; $i++) {
|
||||
$mask .= '0';
|
||||
}
|
||||
$mask = gmp_strval(gmp_init($mask), 16);
|
||||
$result = '';
|
||||
for ($i = 0; $i < 8; $i++) {
|
||||
$result .= substr($mask, $i * 4, 4);
|
||||
if ($i != 7) $result .= ':';
|
||||
if ($i != 7) {
|
||||
$result .= ':';
|
||||
}
|
||||
} // for
|
||||
return inet_ntop(inet_pton($result));
|
||||
}
|
||||
|
||||
private static function ip2long6($ip)
|
||||
{
|
||||
$ip_n = inet_pton($ip);
|
||||
$bits = 15; // 16 x 8 bit = 128bit
|
||||
$ipv6long = '';
|
||||
while ($bits >= 0) {
|
||||
$bin = sprintf("%08b", (ord($ip_n[$bits])));
|
||||
$ipv6long = $bin . $ipv6long;
|
||||
$bits--;
|
||||
}
|
||||
return gmp_strval(gmp_init($ipv6long, 2), 10);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
namespace Froxlor\System;
|
||||
|
||||
use Froxlor\Settings;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
class Mailer extends \PHPMailer\PHPMailer\PHPMailer
|
||||
class Mailer extends PHPMailer
|
||||
{
|
||||
|
||||
/**
|
||||
* class constructor
|
||||
*
|
||||
* @param string $exceptions
|
||||
* whether to throw exceptions or not
|
||||
* whether to throw exceptions or not
|
||||
*
|
||||
*/
|
||||
public function __construct($exceptions = false)
|
||||
|
||||
@@ -1,15 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you can also view it online at
|
||||
* https://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright the authors
|
||||
* @author Froxlor team <team@froxlor.org>
|
||||
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
|
||||
*/
|
||||
|
||||
namespace Froxlor\System;
|
||||
|
||||
use Froxlor\Database\Database;
|
||||
use Monolog\Handler\AbstractProcessingHandler;
|
||||
use Monolog\Logger;
|
||||
|
||||
class MysqlHandler extends AbstractProcessingHandler
|
||||
{
|
||||
|
||||
protected $pdoStatement = null;
|
||||
|
||||
protected static $froxlorLevels = array(
|
||||
protected static $froxlorLevels = [
|
||||
Logger::DEBUG => LOG_DEBUG,
|
||||
Logger::INFO => LOG_INFO,
|
||||
Logger::NOTICE => LOG_NOTICE,
|
||||
@@ -18,13 +41,14 @@ class MysqlHandler extends AbstractProcessingHandler
|
||||
Logger::CRITICAL => LOG_ERR,
|
||||
Logger::ALERT => LOG_ERR,
|
||||
Logger::EMERGENCY => LOG_ERR
|
||||
);
|
||||
];
|
||||
protected $pdoStatement = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param bool|int $level
|
||||
* Debug level which this handler should store
|
||||
* Debug level which this handler should store
|
||||
* @param bool $bubble
|
||||
*/
|
||||
public function __construct($level = Logger::DEBUG, $bubble = true)
|
||||
@@ -32,21 +56,6 @@ class MysqlHandler extends AbstractProcessingHandler
|
||||
parent::__construct($level, $bubble);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the data to the logger table
|
||||
*
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
protected function insert(array $data)
|
||||
{
|
||||
if ($this->pdoStatement === null) {
|
||||
$sql = "INSERT INTO `panel_syslog` SET `text` = :message, `user` = :contextUser, `action` = :contextAction, `type` = :level, `date` = :datetime";
|
||||
$this->pdoStatement = \Froxlor\Database\Database::prepare($sql);
|
||||
}
|
||||
return $this->pdoStatement->execute($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the record down to the log
|
||||
*
|
||||
@@ -63,4 +72,19 @@ class MysqlHandler extends AbstractProcessingHandler
|
||||
':datetime' => $record['datetime']->format('U')
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the data to the logger table
|
||||
*
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
protected function insert(array $data)
|
||||
{
|
||||
if ($this->pdoStatement === null) {
|
||||
$sql = "INSERT INTO `panel_syslog` SET `text` = :message, `user` = :contextUser, `action` = :contextAction, `type` = :level, `date` = :datetime";
|
||||
$this->pdoStatement = Database::prepare($sql);
|
||||
}
|
||||
return $this->pdoStatement->execute($data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user