From 6e72d4fd98d2b2cc7e05790cdbbab37fec414eb4 Mon Sep 17 00:00:00 2001 From: Hpiz Date: Tue, 9 Jun 2020 16:33:56 -0400 Subject: [PATCH] Added LDAPRecord Fix for authentication page not working when no "District" defined Improved speed of setup page when not fully configured Fix for missing DB columns on Authentication settings page Fix for slider text being hidden by items below it Set Core debug mode to false --- .gitignore | 1 + .idea/School Accounts Manager.iml | 1 + .idea/php.xml | 1 + app/api/ad/ADConnection.php | 14 +- app/app/App.php | 6 +- app/views/layouts/navbar.php | 6 +- app/views/settings/application.php | 5 +- app/views/settings/authentication.php | 11 +- app/views/settings/district/create.php | 6 +- app/views/settings/email.php | 3 - composer.json | 3 +- composer.lock | 320 ++++++++++++++++++++++++- public/css/style2.css | 8 +- system/app/forms/FormSlider.php | 23 +- 14 files changed, 374 insertions(+), 34 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..57872d0f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor/ diff --git a/.idea/School Accounts Manager.iml b/.idea/School Accounts Manager.iml index 5830d76c..5b32a4d6 100644 --- a/.idea/School Accounts Manager.iml +++ b/.idea/School Accounts Manager.iml @@ -4,6 +4,7 @@ + diff --git a/.idea/php.xml b/.idea/php.xml index c3c0acc9..9147d5db 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -28,6 +28,7 @@ + diff --git a/app/api/ad/ADConnection.php b/app/api/ad/ADConnection.php index bfd55019..2de93e55 100644 --- a/app/api/ad/ADConnection.php +++ b/app/api/ad/ADConnection.php @@ -12,6 +12,7 @@ use Adldap\Adldap\Auth\PasswordRequiredException; use Adldap\Adldap\Auth\UsernameRequiredException; +use Adldap\AdldapException; use Adldap\Connections\Provider; use Adldap\Connections\ProviderInterface; use App\Models\Database\DistrictDatabase; @@ -75,17 +76,20 @@ public function __construct(array $configuration = []) } } - - $this->addProvider($configuration); try { + $this->addProvider($configuration); + set_error_handler([$this, 'handleError']); - if ($configuration["username"] !== '' && $configuration["password"] !== '') { + if ($configuration["username"] !== '' && $configuration["password"] !== '' && $configuration["base_dn"] !== '') { $this->connection = $this->connect(); } else { throw new AppException("Missing username or password"); } new AppErrorHandler(); + } catch (AdldapException $exception) { + $this->ldapLogger->warning($exception); + } catch (Exception $exception) { self::$lastError = $exception->getMessage(); @@ -116,6 +120,7 @@ public static function isConnected(): bool * Now check if connection is legit */ if (self::$instance->connection instanceof Provider === false) { + self::$logger->info("AD not connected"); return false; } /** @@ -123,9 +128,12 @@ public static function isConnected(): bool */ self::$logger->debug(self::$instance->connection->getConnection()->getLastError()); if (!self::$instance->connection->getConnection()->getLastError()) { + self::$logger->info("AD not connected"); + return false; } + self::$logger->info("AD connected"); return true; } diff --git a/app/app/App.php b/app/app/App.php index 617411c7..c4b26d95 100644 --- a/app/app/App.php +++ b/app/app/App.php @@ -48,6 +48,7 @@ use System\App\Error\AppErrorHandler; use System\App\UserLogger; use System\App\ControllerFactory; +use System\Core; use System\Request; use System\App\Router; use App\Models\User\User; @@ -151,10 +152,7 @@ private function setErrorMode(): void public function inDebugMode(): bool { - if (AppDatabase::getDebugMode()) { - return true; - } - return false; + return Core::inDebugMode(); } diff --git a/app/views/layouts/navbar.php b/app/views/layouts/navbar.php index c5bb8cff..94f99534 100644 --- a/app/views/layouts/navbar.php +++ b/app/views/layouts/navbar.php @@ -108,8 +108,6 @@ Settings Setup - About @@ -130,7 +128,9 @@ Profile - + About + Help Logout diff --git a/app/views/settings/application.php b/app/views/settings/application.php index 95351995..cc7ff768 100644 --- a/app/views/settings/application.php +++ b/app/views/settings/application.php @@ -46,9 +46,7 @@ $forceHTTPS->addOption("False", '0', !AppDatabase::getForceHTTPS()); $forceHTTPS->addOption("True", '1', AppDatabase::getForceHTTPS()); -$debugMode = new FormSlider("Debug Mode", "Caution: Enabling debug mode is a security risk and should only be used on development systems.", "debugMode", AppDatabase::getDebugMode()); -$debugMode->addOption("False", '0', !AppDatabase::getDebugMode()); -$debugMode->addOption("True", '1', AppDatabase::getDebugMode()); + $homepageMessage = new System\App\Forms\FormTextArea(); $homepageMessage->setLabel("Homepage Message") ->setSubLabel("Accepts HTML and inline style") @@ -64,7 +62,6 @@ ->addElementToNewRow($homepageMessage) ->addElementToNewRow($webFQDN) ->addElementToNewRow($forceHTTPS) - ->addElementToCurrentRow($debugMode) ->addElementToNewRow($webHelpDesk) ->addElementToNewRow($submitButton); echo $form->print(); diff --git a/app/views/settings/authentication.php b/app/views/settings/authentication.php index baf5a279..7e424fe6 100644 --- a/app/views/settings/authentication.php +++ b/app/views/settings/authentication.php @@ -33,7 +33,7 @@ $auth = new AuthDatabase(); if ($auth->getLDAPEnabled()) { - $adTestResult = ADConnection::isConnected(); + $ldapConnected = ADConnection::isConnected(); } @@ -44,17 +44,16 @@ $adminPassword->isPassword(); -$ldapConnected = false; -if (ADConnection::isConnected()) { - $ldapConnected = true; -} - $isLDAPEnabled = $auth->getLDAPEnabled(); $ldapEnabled = new System\App\Forms\FormSlider("AD Logon Enabled", "Allow logon with Active Directory accounts", "ldapEnabled", $isLDAPEnabled); $ldapEnabled->addOption("False", 0, !$isLDAPEnabled) ->addOption("True", 1, $isLDAPEnabled); +if (!$ldapConnected) { + $ldapEnabled->disable(); +} + $button = new FormFloatingButton(''); $button->setId('floatingSaveButton') diff --git a/app/views/settings/district/create.php b/app/views/settings/district/create.php index fb27af95..53e5e318 100644 --- a/app/views/settings/district/create.php +++ b/app/views/settings/district/create.php @@ -1,12 +1,12 @@
-

Create New District

+

Create New Domain

addElementToCurrentRow($name) ->addElementToNewRow($createButton); echo $form->print(); diff --git a/app/views/settings/email.php b/app/views/settings/email.php index 39c28e82..0c806249 100644 --- a/app/views/settings/email.php +++ b/app/views/settings/email.php @@ -51,9 +51,6 @@ $smtpPassword = new FormText("SMTP Password", 'SMTP Auth password', 'smtpPassword', $email->getSMTPPassword()); -$useSMTPSSL = new FormRadio('Use SMTP over SSL', 'Sends emails securly', 'useSMTPSSL'); -$useSMTPSSL->addOption('False', 0, !$email->getUseSMTPSSL()); -$useSMTPSSL->addOption('True', 1, $email->getUseSMTPSSL()); $useEncryption = new FormSlider('Use Encryption', 'Sends emails securly', 'useEncryption'); $useEncryption->addOption('False', 0, !$email->getUseSMTPEncryption()); diff --git a/composer.json b/composer.json index 236fa067..a4537ba0 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "visualappeal/php-auto-update": "^0.12.3", "ext-zip": "*", "ext-json": "*", - "ext-pdo": "*" + "ext-pdo": "*", + "directorytree/ldaprecord": "^1.7" } } diff --git a/composer.lock b/composer.lock index 2a654e83..fef26e74 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "35ce1c0500f0820008273c4320561be7", + "content-hash": "b0f9ff269c7b3e7a97a9c6c33f143efa", "packages": [ { "name": "adldap2/adldap2", @@ -182,6 +182,72 @@ ], "time": "2017-01-18T12:58:33+00:00" }, + { + "name": "directorytree/ldaprecord", + "version": "v1.7.2", + "source": { + "type": "git", + "url": "https://github.com/DirectoryTree/LdapRecord.git", + "reference": "9ec289149bb94908821e17758c6a27eca755d29f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/DirectoryTree/LdapRecord/zipball/9ec289149bb94908821e17758c6a27eca755d29f", + "reference": "9ec289149bb94908821e17758c6a27eca755d29f", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-ldap": "*", + "illuminate/contracts": "^5.0|^6.0|^7.0", + "nesbot/carbon": "^1.0|^2.0", + "php": ">=7.2", + "psr/log": "^1.0", + "psr/simple-cache": "^1.0", + "tightenco/collect": "^5.0|^6.0|^7.0" + }, + "require-dev": { + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "LdapRecord\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Steve Bauman", + "email": "steven_bauman@outlook.com", + "role": "Developer" + } + ], + "description": "A fully-featured LDAP ORM.", + "homepage": "https://www.ldaprecord.com", + "keywords": [ + "active directory", + "ad", + "adLDAP", + "adldap2", + "directory", + "ldap", + "ldaprecord", + "orm", + "windows" + ], + "funding": [ + { + "url": "https://github.com/stevebauman", + "type": "github" + } + ], + "time": "2020-05-26T20:11:45+00:00" + }, { "name": "guzzlehttp/guzzle", "version": "5.3.4", @@ -460,6 +526,89 @@ ], "time": "2017-06-19T01:22:40+00:00" }, + { + "name": "nesbot/carbon", + "version": "2.35.0", + "source": { + "type": "git", + "url": "https://github.com/briannesbitt/Carbon.git", + "reference": "4b9bd835261ef23d36397a46a76b496a458305e5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/4b9bd835261ef23d36397a46a76b496a458305e5", + "reference": "4b9bd835261ef23d36397a46a76b496a458305e5", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": "^7.1.8 || ^8.0", + "symfony/polyfill-mbstring": "^1.0", + "symfony/translation": "^3.4 || ^4.0 || ^5.0" + }, + "require-dev": { + "doctrine/orm": "^2.7", + "friendsofphp/php-cs-fixer": "^2.14 || ^3.0", + "kylekatarnls/multi-tester": "^1.1", + "phpmd/phpmd": "^2.8", + "phpstan/phpstan": "^0.11", + "phpunit/phpunit": "^7.5 || ^8.0", + "squizlabs/php_codesniffer": "^3.4" + }, + "bin": [ + "bin/carbon" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev", + "dev-3.x": "3.x-dev" + }, + "laravel": { + "providers": [ + "Carbon\\Laravel\\ServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Carbon\\": "src/Carbon/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Brian Nesbitt", + "email": "brian@nesbot.com", + "homepage": "http://nesbot.com" + }, + { + "name": "kylekatarnls", + "homepage": "http://github.com/kylekatarnls" + } + ], + "description": "An API extension for DateTime that supports 281 different languages.", + "homepage": "http://carbon.nesbot.com", + "keywords": [ + "date", + "datetime", + "time" + ], + "funding": [ + { + "url": "https://opencollective.com/Carbon", + "type": "open_collective" + }, + { + "url": "https://tidelift.com/funding/github/packagist/nesbot/carbon", + "type": "tidelift" + } + ], + "time": "2020-05-24T18:27:52+00:00" + }, { "name": "phpmailer/phpmailer", "version": "v6.1.6", @@ -867,6 +1016,169 @@ ], "time": "2020-05-12T16:47:27+00:00" }, + { + "name": "symfony/translation", + "version": "v5.1.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/translation.git", + "reference": "d387f07d4c15f9c09439cf3f13ddbe0b2c5e8be2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/translation/zipball/d387f07d4c15f9c09439cf3f13ddbe0b2c5e8be2", + "reference": "d387f07d4c15f9c09439cf3f13ddbe0b2c5e8be2", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/polyfill-mbstring": "~1.0", + "symfony/polyfill-php80": "^1.15", + "symfony/translation-contracts": "^2" + }, + "conflict": { + "symfony/config": "<4.4", + "symfony/dependency-injection": "<5.0", + "symfony/http-kernel": "<5.0", + "symfony/twig-bundle": "<5.0", + "symfony/yaml": "<4.4" + }, + "provide": { + "symfony/translation-implementation": "2.0" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "^4.4|^5.0", + "symfony/console": "^4.4|^5.0", + "symfony/dependency-injection": "^5.0", + "symfony/finder": "^4.4|^5.0", + "symfony/http-kernel": "^5.0", + "symfony/intl": "^4.4|^5.0", + "symfony/service-contracts": "^1.1.2|^2", + "symfony/yaml": "^4.4|^5.0" + }, + "suggest": { + "psr/log-implementation": "To use logging capability in translator", + "symfony/config": "", + "symfony/yaml": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Translation\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Translation Component", + "homepage": "https://symfony.com", + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-05-30T20:35:19+00:00" + }, + { + "name": "symfony/translation-contracts", + "version": "v2.1.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/translation-contracts.git", + "reference": "e5ca07c8f817f865f618aa072c2fe8e0e637340e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/e5ca07c8f817f865f618aa072c2fe8e0e637340e", + "reference": "e5ca07c8f817f865f618aa072c2fe8e0e637340e", + "shasum": "" + }, + "require": { + "php": ">=7.2.5" + }, + "suggest": { + "symfony/translation-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\Translation\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to translation", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-05-20T17:43:50+00:00" + }, { "name": "symfony/var-dumper", "version": "v5.1.0", @@ -1059,7 +1371,11 @@ "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, - "platform": [], + "platform": { + "ext-zip": "*", + "ext-json": "*", + "ext-pdo": "*" + }, "platform-dev": [], "plugin-api-version": "1.1.0" } diff --git a/public/css/style2.css b/public/css/style2.css index 708c5ce0..43eb9d61 100644 --- a/public/css/style2.css +++ b/public/css/style2.css @@ -114,26 +114,26 @@ and open the template in the editor. } .form-element { - margin-bottom: 2em !important; + margin-bottom: 2em; } @media only screen and (min-width: 576px) { .form-element { - margin-bottom: 2em !important; + margin-bottom: 2em; } } @media only screen and (min-width: 768px) { .form-element { - margin-bottom: 1em !important; + margin-bottom: 1em; } } @media only screen and (min-width: 992px) { .form-element { - margin-bottom: 1em !important; + margin-bottom: 1em; } } diff --git a/system/app/forms/FormSlider.php b/system/app/forms/FormSlider.php index bd61d375..7dcd8b60 100644 --- a/system/app/forms/FormSlider.php +++ b/system/app/forms/FormSlider.php @@ -36,8 +36,28 @@ class FormSlider extends FormRadio { + /** + * FormSlider constructor. + * + * @param string $label + * @param string $subLabel + * @param string $name + * @param string $value + */ + public function __construct($label = '', $subLabel = '', $name = '', $value = '') + { + parent::__construct($label, $subLabel, $name, $value); + $this->addElementClasses('mb-4'); + } + + public function getElementHTML() { + $disable = ''; + if ($this->isDisabled()) { + $disable = ' disabled '; + + } /* @var $option FormRadioOption */ $selectedOption = new FormRadioOption(''); @@ -62,7 +82,8 @@ public function getElementHTML() $function .= '}' . '$("#' . $outputId . '").html(output);'; $this->setScript(Javascript::on($this->getId(), $function, 'click touch')); - $html = ''; + $width = 50 * (count($this->getOptions()) - 1); + $html = ''; $html .= '
' . $selectedOption->getLabel() . '
'; return $html; }