]> git.sur5r.net Git - bacula/bacula/commitdiff
baculum: Tweak fields validation in initial wizard
authorMarcin Haba <marcin.haba@bacula.pl>
Fri, 1 Jan 2016 08:48:57 +0000 (09:48 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Fri, 1 Jan 2016 11:39:17 +0000 (12:39 +0100)
gui/baculum/protected/Class/ConfigurationManager.php
gui/baculum/protected/Lang/en/messages.mo
gui/baculum/protected/Lang/en/messages.po
gui/baculum/protected/Lang/pl/messages.mo
gui/baculum/protected/Lang/pl/messages.po
gui/baculum/protected/Pages/ConfigurationWizard.page
gui/baculum/protected/Pages/ConfigurationWizard.php
gui/baculum/themes/Baculum-v1/style.css

index b5692817bb5de9554adea1793c505579a668d526..db22b11468fc91cd5b1ea4ca150c399053a8710e 100644 (file)
@@ -43,6 +43,11 @@ class ConfigurationManager extends TModule
         */
        const USERS_FILE = 'Application.Data.baculum';
 
+       /**
+        * User name allowed characters pattern
+        */
+       const USER_PATTERN = '[a-zA-Z0-9]+';
+
        /**
         * PostgreSQL default params
         */
@@ -71,6 +76,7 @@ class ConfigurationManager extends TModule
 
        /**
         * Get database name by database type (short name).
+        *
         * @access public
         * @param string $type database type ('pgsql', 'mysql' ...)
         * @return mixed database name or null if database name not found
@@ -88,6 +94,7 @@ class ConfigurationManager extends TModule
 
        /**
         * Check if given database type is PostgreSQL type.
+        *
         * @access public
         * @param string $type database type ('pgsql', 'mysql' ...)
         * @return boolean true if database type is PostgreSQL, otherwise false
@@ -98,6 +105,7 @@ class ConfigurationManager extends TModule
 
        /**
         * Check if given database type is MySQL type.
+        *
         * @access public
         * @param string $type database type ('pgsql', 'mysql' ...)
         * @return boolean true if database type is MySQL, otherwise false
@@ -108,6 +116,7 @@ class ConfigurationManager extends TModule
 
        /**
         * Check if given database type is SQLite type.
+        *
         * @access public
         * @param string $type database type ('sqlite', 'mysql' ...)
         * @return boolean true if database type is SQLite, otherwise false
@@ -119,6 +128,7 @@ class ConfigurationManager extends TModule
        /**
         * Get currently set application language short name.
         * If no language set then default language is taken.
+        *
         * @access public
         * @return string lanuage short name
         */
@@ -135,6 +145,7 @@ class ConfigurationManager extends TModule
 
        /**
         * Save application configuration.
+        *
         * @access public
         * @param array $config structure of config file params
         * @return boolean true if config save is successfully, false if config save is failure
@@ -146,6 +157,7 @@ class ConfigurationManager extends TModule
 
        /**
         * Get application configuration.
+        *
         * @access public
         * @return array application configuration
         */
@@ -156,6 +168,7 @@ class ConfigurationManager extends TModule
 
        /**
         * Check if application configuration file exists.
+        *
         * @access public
         * @return boolean true if file exists, otherwise false
         */
@@ -163,6 +176,16 @@ class ConfigurationManager extends TModule
                return file_exists(Prado::getPathOfNamespace(self::CONFIG_FILE, '.conf'));
        }
 
+       /**
+        * Get user name allowed characters pattern
+        *
+        * @access public
+        * @return string user name pattern
+        */
+       public function getUserPattern() {
+               return self::USER_PATTERN;
+       }
+
        /**
         * Get encrypted password to use in HTTP Basic auth.
         *
@@ -284,6 +307,7 @@ class ConfigurationManager extends TModule
 
        /**
         * Check if users configuration file exists.
+        *
         * @access public
         * @return boolean true if file exists, otherwise false
         */
@@ -293,6 +317,7 @@ class ConfigurationManager extends TModule
 
        /**
         * Clear all content of users file.
+        *
         * @access public
         * @return boolean true if file cleared successfully, otherwise false
         */
@@ -320,6 +345,15 @@ class ConfigurationManager extends TModule
        public function switchToUser($http_protocol, $host, $port, $user, $password) {
                $urlPrefix = $this->Application->getModule('friendly-url')->getUrlPrefix();
                $location = sprintf("%s://%s:%s@%s:%d%s", $http_protocol, $user, $password, $host, $port, $urlPrefix);
+               $refresh_url = sprintf("%s://%s:%d%s", $http_protocol, $host, $port, $urlPrefix);
+
+               /**
+                * Refresh page is required due to lack of auth data in $_SERVER superglobal array
+                * after re-login by URI.
+                */
+               $_SESSION['refresh_page'] = $refresh_url;
+
+               // Log in by header
                header("Location: $location");
        }
 
index 4ffd86e024aa42f7275e0df2f77ba6344ff76226..53838bef85aa50cdf1adec9dc4379f4b44dca07f 100644 (file)
Binary files a/gui/baculum/protected/Lang/en/messages.mo and b/gui/baculum/protected/Lang/en/messages.mo differ
index 1179348a934262ee55383386fdffb69f0bf32c48..714dd3945578a8bc1cc484548a30223bdf8aa68e 100644 (file)
@@ -1130,3 +1130,6 @@ msgstr "Username:"
 msgid "Please note that for each user (excluding administrator) there should exist separate Bconsole config file in form:"
 msgstr "Please note that for each user (excluding administrator) there should exist separate Bconsole config file in form:"
 
+msgid "Invalid login value. Login may contain a-z A-Z 0-9 characters."
+msgstr "Invalid login value. Login may contain a-z A-Z 0-9 characters."
+
index 5b082983cc07bab398ac793328a01c696cbcf168..b748100927d705003a7429c13a7a557d26bfc906 100644 (file)
Binary files a/gui/baculum/protected/Lang/pl/messages.mo and b/gui/baculum/protected/Lang/pl/messages.mo differ
index ae77299db47519b936ec2f4b2b1ae1783f6bc2ae..774876fb357ba5c551e27fc0118adeeb40b1f01c 100644 (file)
@@ -1131,3 +1131,6 @@ msgstr "Nazwa użytkownika:"
 msgid "Please note that for each user (excluding administrator) there should exist separate Bconsole config file in form:"
 msgstr "Uwaga! Dla każdego użytkownika (wyłączając administratora) powinien istnieć osobny plik konfiguracyjny Bconsole w postaci:"
 
+msgid "Invalid login value. Login may contain a-z A-Z 0-9 characters."
+msgstr "Niepoprawny login. Login może zawierać znaki z zakresu: a-z A-Z 0-9"
+
index 2568fb78b0d6e2181e13b494ea64345df1c97783..b0ca6c48e5f62e8f69d8bdf992f8bb77d0316e84 100644 (file)
@@ -61,7 +61,7 @@
                                                <com:TListItem Value="en" Text="<%[ English ]%>" />
                                                <com:TListItem Value="pl" Text="<%[ Polish ]%>" />
                                        </com:TActiveDropDownList>
-                                       <com:TCompareValidator CssClass="validator" Display="Dynamic" ControlToValidate="Lang" DataType="String" ValueToCompare="none" Operator="NotEqual" Text="<%[ Please select language. ]%>" />
+                                       <com:TCompareValidator CssClass="validator-block" Display="Dynamic" ControlToValidate="Lang" DataType="String" ValueToCompare="none" Operator="NotEqual" Text="<%[ Please select language. ]%>" />
                                </div>
                        </div>
                </com:TWizardStep>
@@ -70,7 +70,7 @@
                        <div id="licence-agree">
                                <com:TCheckBox ID="LicenceAgree"  Checked="<%=$this->getPage()->firstRun === false || $this->LicenceAgree->Checked === true%>" />
                                <com:TLabel  ForControl="LicenceAgree" Text="<%[ I have read the license terms and agree to ]%>" /><br />
-                               <com:TRequiredFieldValidator CssClass="validator" ControlToValidate="LicenceAgree" FocusOnError="true" Display="Dynamic" Text="<%[ Need to move on to accept the license. ]%>" />
+                               <com:TRequiredFieldValidator CssClass="validator-block" ControlToValidate="LicenceAgree" FocusOnError="true" Display="Dynamic" Text="<%[ Need to move on to accept the license. ]%>" />
                        </div>
                </com:TWizardStep>
                <com:TWizardStep ID="Step3" Title="<%[ Step 3 - params of Bacula database connection ]%>" StepType="Auto">
@@ -84,7 +84,7 @@
                                                        <com:TListItem Value="mysql" Text="MySQL" />
                                                        <com:TListItem Value="sqlite" Text="SQLite" />
                                                </com:TActiveDropDownList>
-                                               <com:TCompareValidator CssClass="validator" Display="Dynamic" ControlToValidate="DBType" DataType="String" ValueToCompare="none" Operator="NotEqual" Text="<%[ Please select database type. ]%>" />
+                                               <com:TCompareValidator CssClass="validator-block" Display="Dynamic" ControlToValidate="DBType" DataType="String" ValueToCompare="none" Operator="NotEqual" Text="<%[ Please select database type. ]%>" />
                                        </div>
                                </div>
                                
                                        <div class="text"><com:TLabel ForControl="DBName" Text="<%[ Database name: ]%>" /></div>
                                        <div class="field">
                                                <com:TTextBox ID="DBName" CssClass="textbox" />
-                                               <com:TRequiredFieldValidator CssClass="validator" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="DBName" Text="<%[ Please enter database name. ]%>" />
+                                               <com:TRequiredFieldValidator CssClass="validator-block" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="DBName" Text="<%[ Please enter database name. ]%>" />
                                        </div>
                                </div>
                                <div class="line">
                                        <div class="text"><com:TLabel ForControl="Login" Text="<%[ Login: ]%>" /></div>
                                        <div class="field">
                                                <com:TActiveTextBox ID="Login" CssClass="textbox" />
-                                               <com:TRequiredFieldValidator ID="LoginValidator" CssClass="validator" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="Login" Text="<%[ Please enter login. ]%>" />
+                                               <com:TRequiredFieldValidator ID="LoginValidator" CssClass="validator-block" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="Login" Text="<%[ Please enter login. ]%>" />
                                        </div>
                                </div>
                                <div class="line">
                                        <div class="text"><com:TLabel ForControl="IP" Text="<%[ IP address (or hostname): ]%>" /></div>
                                        <div class="field">
                                                <com:TActiveTextBox ID="IP" CssClass="textbox" />
-                                               <com:TRequiredFieldValidator ID="IPValidator" CssClass="validator" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="IP" Text="<%[ Please enter IP address or hostname. ]%>" />
+                                               <com:TRequiredFieldValidator ID="IPValidator" CssClass="validator-block" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="IP" Text="<%[ Please enter IP address or hostname. ]%>" />
                                        </div>
                                </div>
                                <div class="line">
                                        <div class="text"><com:TLabel ForControl="Port" Text="<%[ Port: ]%>" /></div>
                                        <div class="field">
                                                <com:TActiveTextBox ID="Port" CssClass="textbox" Width="55px" MaxLength="5" Enabled="false" />
-                                               <com:TRequiredFieldValidator ID="PortValidator" CssClass="validator" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="Port" Text="<%[ Please enter database port. ]%>" />
+                                               <com:TRequiredFieldValidator ID="PortValidator" CssClass="validator-block" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="Port" Text="<%[ Please enter database port. ]%>" />
                                        </div>
                                </div>
                                <com:TActivePanel ID="DBPathField" CssClass="line" Display="<%=$this->getPage()->firstRun === false && !$this->IsCallBack && $this->getPage()->applicationConfig['db']['type'] == 'sqlite' ? 'Fixed' : $this->DBPathField->Display%>">
                                        <div class="text"><com:TLabel ForControl="DBPath" Text="<%[ SQLite database path: ]%>" /></div>
                                        <div class="field">
                                                <com:TActiveTextBox ID="DBPath" CssClass="textbox" Enabled="false" />
-                                               <com:TRequiredFieldValidator ID="DBPathValidator" Display="Dynamic" CssClass="validator" ControlCssClass="invalidate" ControlToValidate="DBPath" Text="<%[ Please enter database path. ]%>" />
+                                               <com:TRequiredFieldValidator ID="DBPathValidator" Display="Dynamic" CssClass="validator-block" ControlCssClass="invalidate" ControlToValidate="DBPath" Text="<%[ Please enter database path. ]%>" />
                                        </div>
                                </com:TActivePanel>
                                <div class="line">
                                                                <td align="center" valign="middle">
                                                                        <com:TActiveLabel ID="DbTestLoader" Display="None"><img src="<%=$this->getTheme()->getBaseUrl()%>/ajax-loader.gif" alt="<%[ Loading... ]%>" /></com:TActiveLabel>
                                                                        <com:TActiveLabel ID="DbTestResultOk" Display="None" CssClass="validate"><img src="<%=$this->getTheme()->getBaseUrl()%>/icon_ok.png" alt="Validate" /> <%[ OK ]%></com:TActiveLabel>
-                                                                       <com:TActiveLabel ID="DbTestResultErr" Display="None" CssClass="validator"><img src="<%=$this->getTheme()->getBaseUrl()%>/icon_err.png" alt="Invalidate" /> <%[ Connection error ]%></com:TActiveLabel>
+                                                                       <com:TActiveLabel ID="DbTestResultErr" Display="None" CssClass="validator-block"><img src="<%=$this->getTheme()->getBaseUrl()%>/icon_err.png" alt="Invalidate" /> <%[ Connection error ]%></com:TActiveLabel>
                                                                </td>
                                                        </tr>
                                                </table>
                                        <div class="text"><com:TLabel ForControl="BconsolePath" Text="<%[ Bconsole binary file path: ]%>" /></div>
                                        <div class="field">
                                                <com:TTextBox ID="BconsolePath" CssClass="textbox" CausesValidation="false" />
-                                               <com:TRequiredFieldValidator CssClass="validator" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="BconsolePath" Text="<%[ Please enter bconsole path. ]%>" />
+                                               <com:TRequiredFieldValidator CssClass="validator-block" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="BconsolePath" Text="<%[ Please enter bconsole path. ]%>" />
                                        </div>
                                </div>
                                <div class="line">
                                        <div class="text"><com:TLabel ForControl="BconsoleConfigPath" Text="<%[ Bconsole admin config file path: ]%>" /></div>
                                        <div class="field">
                                                <com:TTextBox ID="BconsoleConfigPath" CssClass="textbox" CausesValidation="false" />
-                                               <com:TRequiredFieldValidator CssClass="validator" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="BconsoleConfigPath" Text="<%[ Please enter bconsole config file path. ]%>" />
+                                               <com:TRequiredFieldValidator CssClass="validator-block" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="BconsoleConfigPath" Text="<%[ Please enter bconsole config file path. ]%>" />
                                        </div>
                                </div>
                                <div class="line">
                                                                <td align="center" valign="middle">
                                                                        <com:TActiveLabel ID="BconsoleTestLoader" Display="None"><img src="<%=$this->getTheme()->getBaseUrl()%>/ajax-loader.gif" alt="<%[ Loading... ]%>" /></com:TActiveLabel>
                                                                        <com:TActiveLabel ID="BconsoleTestResultOk" Display="None" CssClass="validate"><img src="<%=$this->getTheme()->getBaseUrl()%>/icon_ok.png" alt="Validate" /> <%[ OK ]%></com:TActiveLabel>
-                                                                       <com:TActiveLabel ID="BconsoleTestResultErr" Display="None" CssClass="validator"><img src="<%=$this->getTheme()->getBaseUrl()%>/icon_err.png" alt="Invalidate" /> <%[ Connection error ]%></com:TActiveLabel>
+                                                                       <com:TActiveLabel ID="BconsoleTestResultErr" Display="None" CssClass="validator-block"><img src="<%=$this->getTheme()->getBaseUrl()%>/icon_err.png" alt="Invalidate" /> <%[ Connection error ]%></com:TActiveLabel>
                                                                </td>
                                                        </tr>
                                                </table>
                                        <div class="text"><com:TLabel ForControl="BconsoleConfigCustomPath" Text="<%[ Bconsole custom config file path: ]%>" /></div>
                                        <div class="field">
                                                <com:TTextBox ID="BconsoleConfigCustomPath" CssClass="textbox" CausesValidation="false" />
-                                               <com:TRequiredFieldValidator CssClass="validator" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="BconsoleConfigCustomPath" Text="<%[ Please enter bconsole custom config file path. ]%>" />
+                                               <com:TRequiredFieldValidator CssClass="validator-block" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="BconsoleConfigCustomPath" Text="<%[ Please enter bconsole custom config file path. ]%>" />
                                        </div>
                                </div>
                                <div class="line">
                                <div class="text"><com:TLabel ForControl="PanelLogin" Text="<%[ Administration login: ]%>" /></div>
                                <div class="field">
                                        <com:TTextBox ID="PanelLogin" CssClass="textbox" CausesValidation="false" />
-                                       <com:TRequiredFieldValidator CssClass="validator" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="PanelLogin" Text="<%[ Please enter login. ]%>" />
+                                       <com:TRequiredFieldValidator CssClass="validator-block" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="PanelLogin" Text="<%[ Please enter login. ]%>" />
+                                       <com:TRegularExpressionValidator CssClass="validator-block" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="PanelLogin" RegularExpression="<%=$this->userPattern%>" Text="<%[ Invalid login value. Login may contain a-z A-Z 0-9 characters. ]%>" />
                                </div>
                        </div>
                        <div class="line">
                                <div class="text"><com:TLabel ForControl="PanelPassword" Text="<%[ Administration password: ]%>" /></div>
                                <div class="field">
                                        <com:TTextBox ID="PanelPassword" CssClass="textbox" TextMode="Password" MaxLength="30" PersistPassword="true" />
-                                       <com:TRequiredFieldValidator CssClass="validator" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="PanelPassword" Text="<%[ Please enter password. ]%>"/>
-                                       <com:TRegularExpressionValidator CssClass="validator" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="PanelPassword" RegularExpression="[\S\s]{5,30}" Text="<%[ Password must be longer than 4 chars. ]%>" />
+                                       <com:TRequiredFieldValidator CssClass="validator-block" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="PanelPassword" Text="<%[ Please enter password. ]%>"/>
+                                       <com:TRegularExpressionValidator CssClass="validator-block" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="PanelPassword" RegularExpression="[\S\s]{5,30}" Text="<%[ Password must be longer than 4 chars. ]%>" />
                                </div>
                        </div>
                        <div class="line">
                                <div class="text"><com:TLabel ForControl="RetypePanelPassword" Text="<%[ Retype administration password: ]%>" /></div>
                                <div class="field">
                                        <com:TTextBox ID="RetypePanelPassword" CssClass="textbox" TextMode="Password" MaxLength="30" PersistPassword="true" />
-                                       <com:TRequiredFieldValidator ID="RetypePasswordRequireValidator" CssClass="validator" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="RetypePanelPassword" Text="<%[ Please enter retype password. ]%>"/>
-                                       <com:TRegularExpressionValidator ID="RetypePasswordRegexpValidator" CssClass="validator" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="RetypePanelPassword" RegularExpression="[\S\s]{5,30}" Text="<%[ Password must be longer than 4 chars. ]%>" />
-                                       <com:TCustomValidator ID="RetypePasswordCustomValidator" CssClass="validator" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="RetypePanelPassword" OnServerValidate="validateAdministratorPassword" Text="<%[ Passwords must be the same. ]%>" />
+                                       <com:TRequiredFieldValidator ID="RetypePasswordRequireValidator" CssClass="validator-block" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="RetypePanelPassword" Text="<%[ Please enter retype password. ]%>"/>
+                                       <com:TRegularExpressionValidator ID="RetypePasswordRegexpValidator" CssClass="validator-block" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="RetypePanelPassword" RegularExpression="[\S\s]{5,30}" Text="<%[ Password must be longer than 4 chars. ]%>" />
+                                       <com:TCustomValidator ID="RetypePasswordCustomValidator" CssClass="validator-block" Display="Dynamic" ControlCssClass="invalidate" ControlToValidate="RetypePanelPassword" OnServerValidate="validateAdministratorPassword" Text="<%[ Passwords must be the same. ]%>" />
                                </div>
                        </div>
                        <div class="line">
index 8be23c600a651e76403ec77464e7448bcf148963..d9a4e498badbf9bbee5f320a666cbabbd847b568 100644 (file)
@@ -32,6 +32,7 @@ class ConfigurationWizard extends BaculumPage
 {
        public $firstRun;
        public $applicationConfig;
+       public $userPattern;
 
        const DEFAULT_DB_NAME = 'bacula';
        const DEFAULT_DB_LOGIN = 'bacula';
@@ -42,8 +43,10 @@ class ConfigurationWizard extends BaculumPage
        public function onInit($param) {
                parent::onInit($param);
                $this->Lang->SelectedValue = $_SESSION['language'];
-               $this->firstRun = !$this->getModule('configuration')->isApplicationConfig();
-               $this->applicationConfig = $this->getModule('configuration')->getApplicationConfig();
+               $config = $this->getModule('configuration');
+               $this->firstRun = !$config->isApplicationConfig();
+               $this->applicationConfig = $config->getApplicationConfig();
+               $this->userPattern = $config->getUserPattern();
                if($this->firstRun === false && $this->User->getIsAdmin() === false) {
                        die('Access denied.');
                }
@@ -112,6 +115,7 @@ class ConfigurationWizard extends BaculumPage
                        if($this->getModule('configuration')->isUsersConfig() === true) { // version with users config file, so next is try to auto-login
                                $previousUser = ($this->firstRun === false) ? $this->applicationConfig['baculum']['login'] : null;
                                $this->getModule('configuration')->setUsersConfig($cfgData['baculum']['login'], $cfgData['baculum']['password'], $this->firstRun, $previousUser);
+
                                // Automatic login after finish wizard.
                                $http_protocol = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http';
                                $this->getModule('configuration')->switchToUser($http_protocol, $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $cfgData['baculum']['login'], $cfgData['baculum']['password']);
index 57a0789bb74ad4a1fd8847a297ef47780b862f21..23cc8c07576b5e30b2fe1da38fbbe0263b750a47 100644 (file)
@@ -376,7 +376,7 @@ div.actions_btn {
 }
 
 .line {
-       height: 35px;
+       min-height: 35px;
        clear: both;
 }
 
@@ -397,12 +397,16 @@ div.actions_btn {
        width: 98%;
 }
 
-.validator, .validate {
+.validator, .validate, .validator-block {
        color: #e3454b !important;
        font-size: 10pt;
        /*margin-left: 5px;*/
 }
 
+.validator-block {
+       display: block;
+}
+
 .validate {
        color: #96c600 !important;
 }
@@ -873,6 +877,7 @@ fieldset {
 }
 
 fieldset .line {
+       min-height: initial;
        height: 25px;
 }