]> git.mxchange.org Git - mailer.git/blobdiff - inc/install-functions.php
Heacy rewrite/cleanup:
[mailer.git] / inc / install-functions.php
index 4e3605f2b665afc866cb926d7c32833022a7b191..5942280ffa3af7a7728bffd4338c51e71aa0673e 100644 (file)
@@ -36,7 +36,7 @@
  ************************************************************************/
 
 // Some security stuff...
-if ((!defined('__SECURITY')) || (!isInstallationPhase())) {
+if ((!defined('__SECURITY')) || (!isInstaller())) {
        die();
 } // END - if
 
@@ -68,7 +68,17 @@ function initInstaller () {
                'warn_no_pass'    => 'other_config',
                'write_footer'    => 'other_config',
                'enable_backlink' => 'other_config',
+               // first_admin
+               'admin_login'     => 'first_admin',
+               'admin_email'     => 'first_admin',
+               'admin_password1' => 'first_admin',
+               'admin_password2' => 'first_admin',
        );
+
+       // Set mininmum password length/score and other config entries
+       setConfigEntry('min_password_length', 5);
+       setConfigEntry('min_password_score' , 3);
+       setConfigEntry('verbose_sql'        , 'N');
 }
 
 // Write the local config-local.php file from "template"
@@ -220,7 +230,7 @@ function isPlainInstaller () {
 // Handle all given failed fields
 function handleInstallerFailedFields ($failedFields) {
        // Don't do anything with no array or no entries
-       if ((!is_array($failedFields)) || (count($failedFields) == 0)) {
+       if (!isFilledArray($failedFields)) {
                // Abort here
                reportBug(__FUNCTION__, __LINE__, 'failedFields[]=' . gettype($failedFields) . ' verification failed');
        } // END - if
@@ -278,10 +288,10 @@ function doInstallerPostCheck ($currentTab, &$saveStatus) {
        // Is the function there?
        if (!function_exists($callbackName)) {
                // Not found, which is not bad, but it means the post-check won't be run
-               //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Call-back function ' . $callbackName . ' not found. saveStatus[status]=' . $saveStatus['status'] . ', currentTab=' . $currentTab);
+               /* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Call-back function ' . $callbackName . ' not found. saveStatus[status]=' . $saveStatus['status'] . ', currentTab=' . $currentTab);
 
                // Abort here
-               return;
+               return FALSE;
        } // END - if
 
        // Init 'tab-specific error message'
@@ -295,13 +305,13 @@ function doInstallerPostCheck ($currentTab, &$saveStatus) {
        $isValid = (bool) call_user_func($callbackName, $currentTab);
 
        // Is it not valid?
-       if (($isValid === FALSE) || (count($GLOBALS['installer_failed_fields'][$currentTab]) > 0)) {
+       if (($isValid === FALSE) || (isFilledArray($GLOBALS['installer_failed_fields'][$currentTab]))) {
                // Then change status and message
                $saveStatus['status']  = 'failed';
                $saveStatus['message'] = '{%message,INSTALLER_POST_CHECK_' . strtoupper($currentTab) . '_FAILED=' . $GLOBALS['installer_post_error'][$currentTab] . '%}';
 
                // Is there failed fields?
-               if (count($GLOBALS['installer_failed_fields'][$currentTab]) > 0) {
+               if (isFilledArray($GLOBALS['installer_failed_fields'][$currentTab])) {
                        // Then merge both
                        $saveStatus['failed_fields'] = merge_array($saveStatus['failed_fields'], $GLOBALS['installer_failed_fields'][$currentTab]);
                } // END - if
@@ -356,7 +366,7 @@ function generateInstallerExtensionTable () {
                if ((loadExtension($ext_name, 'test', '0.0.0', TRUE)) && (isExtensionProductive($ext_name)) && (substr($ext_name, 0, 10) != 'admintheme')) {
                        // Default is not disabled
                        $disabled = '';
-                       if ($ext_name == 'sql_patches') {
+                       if (in_array($ext_name, array('sql_patches', 'timezone'))) {
                                // Always keep this enabled
                                $disabled = ' disabled="disabled"';
                        } // END - if
@@ -468,10 +478,12 @@ function isInstallerWebmasterValid ($value) {
                (isEmailValid($value))
        ||
                // Or is there 'localhost/127.0.0.1' as hostname? Then don't check email address (e.g. you@localhost)
-               (in_array(detectServerName(), array('localhost', '127.0.0.1')))
+               (isDeveloperSystem())
        ) && (
                // Is not default "email address"
                $value != getMessage('DEFAULT_WEBMASTER')
+       ) && (
+               strlen($value) >= 11
        ));
 
        // Return it
@@ -541,6 +553,32 @@ function isInstallerMysqlPrefixValid ($value) {
 
 // ----------------- Other configuration -----------------
 
+// ----------------- First administator -----------------
+
+// Call-back function to check validity of 'admin_login'
+function isInstallerAdminLoginValid ($value) {
+       // Length should not be shorter than 4 characters
+       return (strlen($value) >= 4);
+}
+
+// Call-back function to check validity of 'admin_email'
+function isInstallerAdminEmailValid ($value) {
+       // Just call webmaster-check function
+       return isInstallerWebmasterValid($value);
+}
+
+// Call-back function to check validity of 'admin_password1'
+function isInstallerAdminPassword1Valid ($value) {
+       // Check if it is strong
+       return isStrongPassword($value);
+}
+
+// Call-back function to check validity of 'admin_password2'
+function isInstallerAdminPassword2Valid ($value) {
+       // Check if it is strong
+       return isStrongPassword($value);
+}
+
 // ----------------- Extensions -----------------
 
 // Call-back function to check 'sel' (array!)
@@ -696,7 +734,7 @@ function isInstallerPostDatabaseConfigValid ($currentTab) {
 
                // Abort here
                return FALSE;
-       } elseif (count($engines) == 0) {
+       } elseif (!isFilledArray($engines)) {
                // No engine is active
                $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_DATABASE_NO_ENGINES_ACTIVE--}';
                array_push($GLOBALS['installer_failed_fields'][$currentTab], 'mysql_engine');
@@ -800,6 +838,55 @@ function isInstallerPostDatabaseConfigValid ($currentTab) {
        return $isValid;
 }
 
+// Call-back function to check if first admin data is valid
+function isInstallerPostFirstAdminValid ($currentTab) {
+       // Is all data valid?
+       if (!isPostRequestElementSet('admin_login')) {
+               // Login not set
+               $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_FIRST_ADMIN_LOGIN_EMPTY--}';
+               array_push($GLOBALS['installer_failed_fields'][$currentTab], 'admin_login');
+               return FALSE;
+       } elseif (strlen(postRequestElement('admin_login')) < 4) {
+               // Login to short
+               $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_FIRST_ADMIN_LOGIN_SHORT--}';
+               array_push($GLOBALS['installer_failed_fields'][$currentTab], 'admin_login');
+               return FALSE;
+       } elseif (!isPostRequestElementSet('admin_email')) {
+               // Email address not set
+               $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_FIRST_ADMIN_EMAIL_EMPTY--}';
+               array_push($GLOBALS['installer_failed_fields'][$currentTab], 'admin_email');
+               return FALSE;
+       } elseif (!isInstallerAdminEmailValid(postRequestElement('admin_email'))) {
+               // Invalid email address
+               $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_FIRST_ADMIN_EMAIL_INVALID--}';
+               array_push($GLOBALS['installer_failed_fields'][$currentTab], 'admin_email');
+               return FALSE;
+       } elseif ((!isPostRequestElementSet('admin_password1')) && (isPostRequestElementSet('admin_password2'))) {
+               // Password 1 not set
+               $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_FIRST_ADMIN_PASSWORD1_EMPTY--}';
+               array_push($GLOBALS['installer_failed_fields'][$currentTab], 'admin_password1');
+               return FALSE;
+       } elseif ((isPostRequestElementSet('admin_password1')) && (!isPostRequestElementSet('admin_password2'))) {
+               // Password 2 not set
+               $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_FIRST_ADMIN_PASSWORD2_EMPTY--}';
+               array_push($GLOBALS['installer_failed_fields'][$currentTab], 'admin_password2');
+               return FALSE;
+       } elseif (postRequestElement('admin_password1') != postRequestElement('admin_password2')) {
+               // Passwords mismatch
+               $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_FIRST_ADMIN_PASSWORDS_MISMATCH--}';
+               array_push($GLOBALS['installer_failed_fields'][$currentTab], 'admin_password1', 'admin_password2');
+               return FALSE;
+       } elseif (!isStrongPassword(postRequestElement('admin_password1'))) {
+               // Weak passwords entered
+               $GLOBALS['installer_post_error'][$currentTab] = '{--INSTALLER_POST_FIRST_ADMIN_PASSWORDS_WEAK--}';
+               array_push($GLOBALS['installer_failed_fields'][$currentTab], 'admin_password1', 'admin_password2');
+               return FALSE;
+       } // END - if
+
+       // All tests passed
+       return TRUE;
+}
+
 // Store given tab in session
 function installTabOkay ($currentTab) {
        // Is it set?
@@ -859,5 +946,11 @@ function importInstallSqlDump ($dumpName) {
        importSqlDump('install', $dumpName, 'install');
 }
 
+// Wrapper to check if tables.sql and menu-foo.sql are readable
+function isInstallerSqlsReadable ($path) {
+       // Determine it
+       return ((isFileReadable($path . 'install/tables.sql')) && (isFileReadable($path . 'install/menu-' . getLanguage() . '.sql')));
+}
+
 // [EOF]
 ?>