You've already forked postfixadmin
mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2025-08-06 06:42:37 +03:00
reformat (phpcs)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$finder = PhpCsFixer\Finder::create()
|
$finder = PhpCsFixer\Finder::create()
|
||||||
->exclude('smarty')
|
->exclude('lib')
|
||||||
->exclude('vendor')
|
->exclude('vendor')
|
||||||
->exclude('templates')
|
->exclude('templates')
|
||||||
->exclude('templates_c')
|
->exclude('templates_c')
|
||||||
|
@@ -847,11 +847,9 @@ function generate_password() {
|
|||||||
// add random characters to $password until $length is reached
|
// add random characters to $password until $length is reached
|
||||||
$password = "";
|
$password = "";
|
||||||
while (strlen($password) < $length) {
|
while (strlen($password) < $length) {
|
||||||
|
if (function_exists('random_int')) {
|
||||||
if(function_exists('random_int')) {
|
|
||||||
$random = random_int(0, strlen($possible) -1);
|
$random = random_int(0, strlen($possible) -1);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$random = mt_rand(0, strlen($possible) - 1);
|
$random = mt_rand(0, strlen($possible) - 1);
|
||||||
}
|
}
|
||||||
$char = substr($possible, $random, 1);
|
$char = substr($possible, $random, 1);
|
||||||
@@ -1064,7 +1062,7 @@ function _pacrypt_php_crypt($pw, $pw_db) {
|
|||||||
} else {
|
} else {
|
||||||
$salt_method = 'MD5'; // default.
|
$salt_method = 'MD5'; // default.
|
||||||
// no pw provided. create new password hash
|
// no pw provided. create new password hash
|
||||||
if(strpos($CONF['encrypt'], ':') !== false) {
|
if (strpos($CONF['encrypt'], ':') !== false) {
|
||||||
// use specified hash method
|
// use specified hash method
|
||||||
$split_method = explode(':', $CONF['encrypt']);
|
$split_method = explode(':', $CONF['encrypt']);
|
||||||
$salt_method = $split_method[1];
|
$salt_method = $split_method[1];
|
||||||
@@ -1127,17 +1125,15 @@ function _php_crypt_generate_crypt_salt($hash_type='MD5') {
|
|||||||
|
|
||||||
// used for php_crypt method
|
// used for php_crypt method
|
||||||
function _php_crypt_random_string($characters, $length) {
|
function _php_crypt_random_string($characters, $length) {
|
||||||
|
|
||||||
$random_int_exists = true;
|
$random_int_exists = true;
|
||||||
if(!function_exists('random_int')) {
|
if (!function_exists('random_int')) {
|
||||||
$random_int_exists = false;
|
$random_int_exists = false;
|
||||||
}
|
}
|
||||||
$string = '';
|
$string = '';
|
||||||
for ($p = 0; $p < $length; $p++) {
|
for ($p = 0; $p < $length; $p++) {
|
||||||
if($random_int_exists) {
|
if ($random_int_exists) {
|
||||||
$string .= $characters[random_int(0, strlen($characters) -1)];
|
$string .= $characters[random_int(0, strlen($characters) -1)];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// should really use a stronger randomness source
|
// should really use a stronger randomness source
|
||||||
$string .= $characters[mt_rand(0, strlen($characters) - 1)];
|
$string .= $characters[mt_rand(0, strlen($characters) - 1)];
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,6 @@
|
|||||||
# This class is too static - if you inherit a class from it, it will share the static $instance and all its contents
|
# This class is too static - if you inherit a class from it, it will share the static $instance and all its contents
|
||||||
# Therefore the class is marked as final to prevent someone accidently does this ;-)
|
# Therefore the class is marked as final to prevent someone accidently does this ;-)
|
||||||
final class Config {
|
final class Config {
|
||||||
|
|
||||||
private static $instance = null;
|
private static $instance = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -67,7 +66,6 @@ final class Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$_this->setAll($newConfig);
|
$_this->setAll($newConfig);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,7 +95,7 @@ final class Config {
|
|||||||
$zero = $name[0];
|
$zero = $name[0];
|
||||||
$one = $name[1];
|
$one = $name[1];
|
||||||
$two = $name[2];
|
$two = $name[2];
|
||||||
if(isset($config[$zero], $config[$zero][$one], $config[$zero][$one][$two])) {
|
if (isset($config[$zero], $config[$zero][$one], $config[$zero][$one][$two])) {
|
||||||
return $config[$zero][$one][$two];
|
return $config[$zero][$one][$two];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@@ -149,7 +149,6 @@ class PostfixAdmin {
|
|||||||
* Dispatches a CLI request
|
* Dispatches a CLI request
|
||||||
*/
|
*/
|
||||||
public function dispatch() {
|
public function dispatch() {
|
||||||
|
|
||||||
check_db_version(); # ensure the database layout is up to date
|
check_db_version(); # ensure the database layout is up to date
|
||||||
|
|
||||||
if (!isset($this->args[0])) {
|
if (!isset($this->args[0])) {
|
||||||
|
@@ -2,12 +2,8 @@
|
|||||||
|
|
||||||
require_once('common.php');
|
require_once('common.php');
|
||||||
|
|
||||||
class GeneratePasswordTest extends PHPUnit_Framework_TestCase
|
class GeneratePasswordTest extends PHPUnit_Framework_TestCase {
|
||||||
{
|
public function testBasic() {
|
||||||
public function testBasic()
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
$one = generate_password();
|
$one = generate_password();
|
||||||
|
|
||||||
$two = generate_password();
|
$two = generate_password();
|
||||||
@@ -15,7 +11,5 @@ class GeneratePasswordTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertNotEquals($one, $two);
|
$this->assertNotEquals($one, $two);
|
||||||
$this->assertNotEmpty($one);
|
$this->assertNotEmpty($one);
|
||||||
$this->assertNotEmpty($two);
|
$this->assertNotEmpty($two);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,10 +2,8 @@
|
|||||||
|
|
||||||
require_once('common.php');
|
require_once('common.php');
|
||||||
|
|
||||||
class PaCryptTest extends PHPUnit_Framework_TestCase
|
class PaCryptTest extends PHPUnit_Framework_TestCase {
|
||||||
{
|
public function testMd5Crypt() {
|
||||||
public function testMd5Crypt()
|
|
||||||
{
|
|
||||||
$hash = _pacrypt_md5crypt('test', '');
|
$hash = _pacrypt_md5crypt('test', '');
|
||||||
|
|
||||||
$this->assertNotEmpty($hash);
|
$this->assertNotEmpty($hash);
|
||||||
@@ -14,8 +12,7 @@ class PaCryptTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($hash, _pacrypt_md5crypt('test', $hash));
|
$this->assertEquals($hash, _pacrypt_md5crypt('test', $hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCrypt()
|
public function testCrypt() {
|
||||||
{
|
|
||||||
|
|
||||||
// E_NOTICE if we pass in '' for the salt
|
// E_NOTICE if we pass in '' for the salt
|
||||||
$hash = _pacrypt_crypt('test', 'sa');
|
$hash = _pacrypt_crypt('test', 'sa');
|
||||||
@@ -24,11 +21,9 @@ class PaCryptTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertNotEquals('test', $hash);
|
$this->assertNotEquals('test', $hash);
|
||||||
|
|
||||||
$this->assertEquals($hash, _pacrypt_crypt('test', $hash));
|
$this->assertEquals($hash, _pacrypt_crypt('test', $hash));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMySQLEncrypt()
|
public function testMySQLEncrypt() {
|
||||||
{
|
|
||||||
if (!db_mysql()) {
|
if (!db_mysql()) {
|
||||||
$this->markTestSkipped('Not using MySQL');
|
$this->markTestSkipped('Not using MySQL');
|
||||||
}
|
}
|
||||||
@@ -48,8 +43,7 @@ class PaCryptTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($hash2, _pacrypt_mysql_encrypt('test', 'salt'));
|
$this->assertEquals($hash2, _pacrypt_mysql_encrypt('test', 'salt'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAuthlib()
|
public function testAuthlib() {
|
||||||
{
|
|
||||||
|
|
||||||
// too many options!
|
// too many options!
|
||||||
foreach (
|
foreach (
|
||||||
@@ -67,8 +61,7 @@ class PaCryptTest extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPacryptDovecot()
|
public function testPacryptDovecot() {
|
||||||
{
|
|
||||||
global $CONF;
|
global $CONF;
|
||||||
if (!file_exists('/usr/bin/doveadm')) {
|
if (!file_exists('/usr/bin/doveadm')) {
|
||||||
$this->markTestSkipped("No /usr/bin/doveadm");
|
$this->markTestSkipped("No /usr/bin/doveadm");
|
||||||
@@ -84,8 +77,7 @@ class PaCryptTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expected_hash, _pacrypt_dovecot('test', $expected_hash));
|
$this->assertEquals($expected_hash, _pacrypt_dovecot('test', $expected_hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPhpCrypt()
|
public function testPhpCrypt() {
|
||||||
{
|
|
||||||
global $CONF;
|
global $CONF;
|
||||||
|
|
||||||
$config = Config::getInstance();
|
$config = Config::getInstance();
|
||||||
@@ -104,18 +96,15 @@ class PaCryptTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
|
|
||||||
$this->assertNotEquals($fail, $expected);
|
$this->assertNotEquals($fail, $expected);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPhpCryptRandomString(){
|
public function testPhpCryptRandomString() {
|
||||||
$str1 = _php_crypt_random_string('abcdefg123456789', 2);
|
$str1 = _php_crypt_random_string('abcdefg123456789', 2);
|
||||||
$str2 = _php_crypt_random_string('abcdefg123456789', 2);
|
$str2 = _php_crypt_random_string('abcdefg123456789', 2);
|
||||||
|
|
||||||
$this->assertNotEmpty($str1);
|
$this->assertNotEmpty($str1);
|
||||||
$this->assertNotEmpty($str2);
|
$this->assertNotEmpty($str2);
|
||||||
$this->assertNotEquals($str1, $str2);
|
$this->assertNotEquals($str1, $str2);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,11 +15,11 @@ abstract class RemoteTest extends PHPUnit_Framework_TestCase {
|
|||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
if($this->server_url == 'http://change.me/to/work') {
|
if ($this->server_url == 'http://change.me/to/work') {
|
||||||
$this->markTestSkipped("Test skipped; Configuration change to \$this->server_url required");
|
$this->markTestSkipped("Test skipped; Configuration change to \$this->server_url required");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!class_exists('Zend_XmlRpc_Client', true)) {
|
if (!class_exists('Zend_XmlRpc_Client', true)) {
|
||||||
$this->markTestSkipped("Test skipped; Zend_XmlRpc_Client not found");
|
$this->markTestSkipped("Test skipped; Zend_XmlRpc_Client not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,14 +2,11 @@
|
|||||||
|
|
||||||
require_once('common.php');
|
require_once('common.php');
|
||||||
|
|
||||||
class ValidatePasswordTest extends PHPUnit_Framework_TestCase
|
class ValidatePasswordTest extends PHPUnit_Framework_TestCase {
|
||||||
{
|
public function testBasic() {
|
||||||
public function testBasic()
|
|
||||||
{
|
|
||||||
|
|
||||||
$config = Config::getInstance();
|
$config = Config::getInstance();
|
||||||
|
|
||||||
// Set to the defaults, just to make sure.
|
// Set to the defaults, just to make sure.
|
||||||
Config::write('password_validation', array(
|
Config::write('password_validation', array(
|
||||||
# '/regular expression/' => '$PALANG key (optional: + parameter)',
|
# '/regular expression/' => '$PALANG key (optional: + parameter)',
|
||||||
'/.{5}/' => 'password_too_short 5', # minimum length 5 characters
|
'/.{5}/' => 'password_too_short 5', # minimum length 5 characters
|
||||||
|
Reference in New Issue
Block a user