diff --git a/LibreNMS/Authentication/ADAuthorizationAuthorizer.php b/LibreNMS/Authentication/ADAuthorizationAuthorizer.php index 94c3b95cc2..2ce3e7db4f 100644 --- a/LibreNMS/Authentication/ADAuthorizationAuthorizer.php +++ b/LibreNMS/Authentication/ADAuthorizationAuthorizer.php @@ -11,8 +11,8 @@ class ADAuthorizationAuthorizer extends MysqlAuthorizer use LdapSessionCache; use ActiveDirectoryCommon; - protected static $AUTH_IS_EXTERNAL = 1; - protected static $CAN_UPDATE_PASSWORDS = 0; + protected static $AUTH_IS_EXTERNAL = true; + protected static $CAN_UPDATE_PASSWORDS = false; protected $ldap_connection; @@ -68,7 +68,7 @@ class ADAuthorizationAuthorizer extends MysqlAuthorizer public function userExists($username, $throw_exception = false) { if ($this->authLdapSessionCacheGet('user_exists')) { - return 1; + return true; } $search = ldap_search( @@ -86,10 +86,10 @@ class ADAuthorizationAuthorizer extends MysqlAuthorizer */ $this->authLdapSessionCacheSet('user_exists', 1); - return 1; + return true; } - return 0; + return false; } public function getUserlevel($username) diff --git a/LibreNMS/Authentication/ActiveDirectoryAuthorizer.php b/LibreNMS/Authentication/ActiveDirectoryAuthorizer.php index 3d99751b5c..e743a9d2c5 100644 --- a/LibreNMS/Authentication/ActiveDirectoryAuthorizer.php +++ b/LibreNMS/Authentication/ActiveDirectoryAuthorizer.php @@ -14,7 +14,7 @@ class ActiveDirectoryAuthorizer extends AuthorizerBase { use ActiveDirectoryCommon; - protected static $CAN_UPDATE_PASSWORDS = 0; + protected static $CAN_UPDATE_PASSWORDS = false; protected $ldap_connection; protected $is_bound = false; // this variable tracks if bind has been called so we don't call it multiple times diff --git a/LibreNMS/Authentication/AuthorizerBase.php b/LibreNMS/Authentication/AuthorizerBase.php index 7a7677ac00..2e88797ed1 100644 --- a/LibreNMS/Authentication/AuthorizerBase.php +++ b/LibreNMS/Authentication/AuthorizerBase.php @@ -28,10 +28,10 @@ use LibreNMS\Interfaces\Authentication\Authorizer; abstract class AuthorizerBase implements Authorizer { - protected static $HAS_AUTH_USERMANAGEMENT = 0; - protected static $CAN_UPDATE_USER = 0; - protected static $CAN_UPDATE_PASSWORDS = 0; - protected static $AUTH_IS_EXTERNAL = 0; + protected static $HAS_AUTH_USERMANAGEMENT = false; + protected static $CAN_UPDATE_USER = false; + protected static $CAN_UPDATE_PASSWORDS = false; + protected static $AUTH_IS_EXTERNAL = false; public function canUpdatePasswords($username = '') { @@ -41,7 +41,7 @@ abstract class AuthorizerBase implements Authorizer public function changePassword($username, $newpassword) { //not supported by default - return 0; + return false; } public function canManageUsers() @@ -52,13 +52,13 @@ abstract class AuthorizerBase implements Authorizer public function addUser($username, $password, $level = 0, $email = '', $realname = '', $can_modify_passwd = 0, $description = '') { //not supported by default - return 0; + return false; } public function deleteUser($user_id) { //not supported by default - return 0; + return false; } public function canUpdateUsers() @@ -69,7 +69,7 @@ abstract class AuthorizerBase implements Authorizer public function updateUser($user_id, $realname, $level, $can_modify_passwd, $email) { //not supported by default - return 0; + return false; } public function authIsExternal() diff --git a/LibreNMS/Authentication/HttpAuthAuthorizer.php b/LibreNMS/Authentication/HttpAuthAuthorizer.php index bd15c49bd3..215e61317d 100644 --- a/LibreNMS/Authentication/HttpAuthAuthorizer.php +++ b/LibreNMS/Authentication/HttpAuthAuthorizer.php @@ -7,10 +7,10 @@ use LibreNMS\Exceptions\AuthenticationException; class HttpAuthAuthorizer extends MysqlAuthorizer { - protected static $HAS_AUTH_USERMANAGEMENT = 1; - protected static $CAN_UPDATE_USER = 1; - protected static $CAN_UPDATE_PASSWORDS = 0; - protected static $AUTH_IS_EXTERNAL = 1; + protected static $HAS_AUTH_USERMANAGEMENT = true; + protected static $CAN_UPDATE_USER = true; + protected static $CAN_UPDATE_PASSWORDS = false; + protected static $AUTH_IS_EXTERNAL = true; public function authenticate($credentials) { diff --git a/LibreNMS/Authentication/LdapAuthorizationAuthorizer.php b/LibreNMS/Authentication/LdapAuthorizationAuthorizer.php index d499a7b6db..f89ac1d1c9 100644 --- a/LibreNMS/Authentication/LdapAuthorizationAuthorizer.php +++ b/LibreNMS/Authentication/LdapAuthorizationAuthorizer.php @@ -33,7 +33,7 @@ class LdapAuthorizationAuthorizer extends AuthorizerBase use LdapSessionCache; protected $ldap_connection; - protected static $AUTH_IS_EXTERNAL = 1; + protected static $AUTH_IS_EXTERNAL = true; public function __construct() { @@ -77,7 +77,7 @@ class LdapAuthorizationAuthorizer extends AuthorizerBase public function userExists($username, $throw_exception = false) { if ($this->authLdapSessionCacheGet('user_exists')) { - return 1; + return true; } $filter = '(' . Config::get('auth_ldap_prefix') . $username . ')'; @@ -90,7 +90,7 @@ class LdapAuthorizationAuthorizer extends AuthorizerBase */ $this->authLdapSessionCacheSet('user_exists', 1); - return 1; + return true; } /* @@ -98,7 +98,7 @@ class LdapAuthorizationAuthorizer extends AuthorizerBase * on some end and the user will be happy if it "just works" after the user * has been added to LDAP. */ - return 0; + return false; } public function getUserlevel($username) @@ -209,7 +209,7 @@ class LdapAuthorizationAuthorizer extends AuthorizerBase } } - return 0; + return false; } protected function getMembername($username) diff --git a/LibreNMS/Authentication/LdapAuthorizer.php b/LibreNMS/Authentication/LdapAuthorizer.php index 9e9108dd5f..e835547de3 100644 --- a/LibreNMS/Authentication/LdapAuthorizer.php +++ b/LibreNMS/Authentication/LdapAuthorizer.php @@ -76,7 +76,7 @@ class LdapAuthorizer extends AuthorizerBase $search = ldap_search($connection, trim(Config::get('auth_ldap_suffix'), ','), $filter); $entries = ldap_get_entries($connection, $search); if ($entries['count']) { - return 1; + return true; } } catch (AuthenticationException $e) { if ($throw_exception) { @@ -92,7 +92,7 @@ class LdapAuthorizer extends AuthorizerBase } } - return 0; + return false; } public function getUserlevel($username) @@ -234,7 +234,7 @@ class LdapAuthorizer extends AuthorizerBase return $user; } - return 0; + return false; } protected function getMembername($username) diff --git a/LibreNMS/Authentication/MysqlAuthorizer.php b/LibreNMS/Authentication/MysqlAuthorizer.php index c5711451ea..2386016ca4 100644 --- a/LibreNMS/Authentication/MysqlAuthorizer.php +++ b/LibreNMS/Authentication/MysqlAuthorizer.php @@ -9,9 +9,9 @@ use LibreNMS\Exceptions\AuthenticationException; class MysqlAuthorizer extends AuthorizerBase { - protected static $HAS_AUTH_USERMANAGEMENT = 1; - protected static $CAN_UPDATE_USER = 1; - protected static $CAN_UPDATE_PASSWORDS = 1; + protected static $HAS_AUTH_USERMANAGEMENT = true; + protected static $CAN_UPDATE_USER = true; + protected static $CAN_UPDATE_PASSWORDS = true; public function authenticate($credentials) { @@ -45,9 +45,9 @@ class MysqlAuthorizer extends AuthorizerBase */ if (! static::$CAN_UPDATE_PASSWORDS) { - return 0; + return false; } elseif (empty($username) || ! $this->userExists($username)) { - return 1; + return true; } else { return User::thisAuth()->where('username', $username)->value('can_modify_passwd'); } @@ -57,7 +57,7 @@ class MysqlAuthorizer extends AuthorizerBase { // check if updating passwords is allowed (mostly for classes that extend this) if (! static::$CAN_UPDATE_PASSWORDS) { - return 0; + return false; } /** @var User $user */ @@ -129,7 +129,7 @@ class MysqlAuthorizer extends AuthorizerBase Eloquent::DB()->table('ports_perms')->where('user_id', $user_id)->delete(); Eloquent::DB()->table('users_prefs')->where('user_id', $user_id)->delete(); - return User::destroy($user_id); + return (bool) User::destroy($user_id); } public function getUserlist() @@ -144,7 +144,7 @@ class MysqlAuthorizer extends AuthorizerBase return $user->toArray(); } - return null; + return false; } public function updateUser($user_id, $realname, $level, $can_modify_passwd, $email) @@ -156,6 +156,6 @@ class MysqlAuthorizer extends AuthorizerBase $user->can_modify_passwd = (int) $can_modify_passwd; $user->email = $email; - $user->save(); + return $user->save(); } } diff --git a/LibreNMS/Authentication/RadiusAuthorizer.php b/LibreNMS/Authentication/RadiusAuthorizer.php index 8fb0e5e08b..e74d7586e4 100644 --- a/LibreNMS/Authentication/RadiusAuthorizer.php +++ b/LibreNMS/Authentication/RadiusAuthorizer.php @@ -8,9 +8,9 @@ use LibreNMS\Exceptions\AuthenticationException; class RadiusAuthorizer extends MysqlAuthorizer { - protected static $HAS_AUTH_USERMANAGEMENT = 1; - protected static $CAN_UPDATE_USER = 1; - protected static $CAN_UPDATE_PASSWORDS = 0; + protected static $HAS_AUTH_USERMANAGEMENT = true; + protected static $CAN_UPDATE_USER = true; + protected static $CAN_UPDATE_PASSWORDS = false; /** @var Radius */ protected $radius; diff --git a/LibreNMS/Authentication/SSOAuthorizer.php b/LibreNMS/Authentication/SSOAuthorizer.php index 328cd0147e..30608b97ac 100644 --- a/LibreNMS/Authentication/SSOAuthorizer.php +++ b/LibreNMS/Authentication/SSOAuthorizer.php @@ -34,10 +34,10 @@ use LibreNMS\Util\IP; */ class SSOAuthorizer extends MysqlAuthorizer { - protected static $HAS_AUTH_USERMANAGEMENT = 1; - protected static $CAN_UPDATE_USER = 1; - protected static $CAN_UPDATE_PASSWORDS = 0; - protected static $AUTH_IS_EXTERNAL = 1; + protected static $HAS_AUTH_USERMANAGEMENT = true; + protected static $CAN_UPDATE_USER = true; + protected static $CAN_UPDATE_PASSWORDS = false; + protected static $AUTH_IS_EXTERNAL = true; public function authenticate($credentials) { diff --git a/LibreNMS/Interfaces/Authentication/Authorizer.php b/LibreNMS/Interfaces/Authentication/Authorizer.php index be8a35c2e1..746e83144d 100644 --- a/LibreNMS/Interfaces/Authentication/Authorizer.php +++ b/LibreNMS/Interfaces/Authentication/Authorizer.php @@ -54,7 +54,7 @@ interface Authorizer * can_modify_passwd * * @param int $user_id - * @return array|bool + * @return array|false */ public function getUser($user_id); diff --git a/LibreNMS/OS/Airos.php b/LibreNMS/OS/Airos.php index 0061cfc21d..5ad9f0345e 100644 --- a/LibreNMS/OS/Airos.php +++ b/LibreNMS/OS/Airos.php @@ -73,7 +73,7 @@ class Airos extends OS implements $location = parent::fetchLocation(); // fix longitude having an extra - in the middle after the decimal point - $location->lng = preg_replace('/(-?\d+)\.-?(\d+)/', '$1.$2', $location->getAttributes()['lng']); + $location->lng = (float) preg_replace('/(-?\d+)\.-?(\d+)/', '$1.$2', $location->getAttributes()['lng']); return $location; } diff --git a/LibreNMS/OS/Zxdsl.php b/LibreNMS/OS/Zxdsl.php index 8542d33dae..3f8bfba49b 100644 --- a/LibreNMS/OS/Zxdsl.php +++ b/LibreNMS/OS/Zxdsl.php @@ -43,7 +43,7 @@ class Zxdsl extends \LibreNMS\OS $variant = ' '; $parts = explode('.', trim($oid, '.')); foreach ($parts as $part) { - $variant .= chr(64 + $part); + $variant .= chr(64 + (int) $part); } return trim($variant); diff --git a/database/migrations/2021_02_09_122930_migrate_to_utf8mb4.php b/database/migrations/2021_02_09_122930_migrate_to_utf8mb4.php index 190300172a..3599899513 100644 --- a/database/migrations/2021_02_09_122930_migrate_to_utf8mb4.php +++ b/database/migrations/2021_02_09_122930_migrate_to_utf8mb4.php @@ -39,7 +39,6 @@ class MigrateToUtf8mb4 extends Migration // Get the list of all tables $tableNames = DB::table('information_schema.tables') ->where('table_schema', $databaseName) - ->get(['TABLE_NAME']) ->pluck('TABLE_NAME'); // Iterate through the list and alter each table diff --git a/tests/AuthHTTPTest.php b/tests/AuthHTTPTest.php index c4f2c8bcbd..0f0a2e75c0 100644 --- a/tests/AuthHTTPTest.php +++ b/tests/AuthHTTPTest.php @@ -55,11 +55,11 @@ class AuthHTTPTest extends TestCase { $a = LegacyAuth::reset(); - $this->assertTrue($a->canUpdatePasswords() === 0); - $this->assertTrue($a->changePassword(null, null) === 0); - $this->assertTrue($a->canManageUsers() === 1); - $this->assertTrue($a->canUpdateUsers() === 1); - $this->assertTrue($a->authIsExternal() === 1); + $this->assertFalse($a->canUpdatePasswords()); + $this->assertFalse($a->changePassword(null, null)); + $this->assertTrue($a->canManageUsers()); + $this->assertTrue($a->canUpdateUsers()); + $this->assertTrue($a->authIsExternal()); } public function testOldBehaviourAgainstCurrent() diff --git a/tests/AuthSSOTest.php b/tests/AuthSSOTest.php index da8ddaf1a9..6d78a9941e 100644 --- a/tests/AuthSSOTest.php +++ b/tests/AuthSSOTest.php @@ -118,7 +118,7 @@ class AuthSSOTest extends DBTestCase // Retrieve it and validate $dbuser = $a->getUser($a->getUserid($user)); - $this->assertNull($dbuser); + $this->assertFalse($dbuser); } // Excercise general auth flow with creation enabled @@ -225,11 +225,11 @@ class AuthSSOTest extends DBTestCase { $a = LegacyAuth::reset(); - $this->assertTrue($a->canUpdatePasswords() === 0); - $this->assertTrue($a->changePassword(null, null) === 0); - $this->assertTrue($a->canManageUsers() === 1); - $this->assertTrue($a->canUpdateUsers() === 1); - $this->assertTrue($a->authIsExternal() === 1); + $this->assertFalse($a->canUpdatePasswords()); + $this->assertFalse($a->changePassword(null, null)); + $this->assertTrue($a->canManageUsers()); + $this->assertTrue($a->canUpdateUsers()); + $this->assertTrue($a->authIsExternal()); } /* Everything from here comprises of targeted tests to excercise single methods */ diff --git a/tests/SmokepingCliTest.php b/tests/SmokepingCliTest.php index 8fdcd92d9f..35bcf1cd01 100644 --- a/tests/SmokepingCliTest.php +++ b/tests/SmokepingCliTest.php @@ -24,10 +24,10 @@ namespace LibreNMS\Tests; -use app\Console\Commands\SmokepingGenerateCommand; +use App\Console\Commands\SmokepingGenerateCommand; use App\Models\Device; use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Support\arr; +use Illuminate\Support\Arr; use Illuminate\Support\Str; class SmokepingCliTest extends DBTestCase