From c4177056ffacb038779fa3a1783a28382d7e54eb Mon Sep 17 00:00:00 2001 From: ibering Date: Tue, 26 Jul 2016 09:31:44 +0200 Subject: [PATCH 1/5] #ITC-434 Bugfix for problem with host macros --- app/View/Helper/CustomVariablesHelper.php | 347 +++++++++++----------- 1 file changed, 173 insertions(+), 174 deletions(-) diff --git a/app/View/Helper/CustomVariablesHelper.php b/app/View/Helper/CustomVariablesHelper.php index d1a69833cd..73b3f5d311 100755 --- a/app/View/Helper/CustomVariablesHelper.php +++ b/app/View/Helper/CustomVariablesHelper.php @@ -25,188 +25,187 @@ class CustomVariablesHelper extends AppHelper { - /** - * Initialize the Helper and set the needed variables - * - * @param string $macrotype (host or service) - * @param array $customMacros an array of existing custom macros (if there are any) - * @return void - * @author Daniel Ziegler - * @since 3.0 - * - */ - public function setup($macrotype = 'HOST', $objecttype_id = null, $customMacros = []){ - $this->macrotype = $macrotype; - $this->customMacros = $customMacros; - $this->macroPrefix = '$_'; - $this->macroSuffix = '$'; - $this->objecttype_id = $objecttype_id; - //$this->Controller = $this->params->params['controller']; - //$this->Model = Inflector::singularize($this->Controller); - } + /** + * Initialize the Helper and set the needed variables + * + * @param string $macrotype (host or service) + * @param array $customMacros an array of existing custom macros (if there are any) + * @return void + * @author Daniel Ziegler + * @since 3.0 + * + */ + public function setup($macrotype = 'HOST', $objecttype_id = null, $customMacros = []){ + $this->macrotype = $macrotype; + $this->customMacros = $customMacros; + $this->macroPrefix = '$_'; + $this->macroSuffix = '$'; + $this->objecttype_id = $objecttype_id; + //$this->Controller = $this->params->params['controller']; + //$this->Model = Inflector::singularize($this->Controller); + } - /** - * Returns the container for ajax and the add button. Use in views - * - * ### Options - * Check this::addButton for the options - * - * @param array $options Array of options - * @return string `
` and `` HTML objects - * @author Daniel Ziegler - * @since 3.0 - * - */ - public function prepare($macrotype = 'HOST', $options = []){ - $html = $this->__startWrap(); - $html.= $this->fetchHtml(); - $html.= $this->__endWrap(); - $html.= $this->addButton($options); - return $html; - } + /** + * Returns the container for ajax and the add button. Use in views + * + * ### Options + * Check this::addButton for the options + * + * @param array $options Array of options + * @return string `
` and `` HTML objects + * @author Daniel Ziegler + * @since 3.0 + * + */ + public function prepare($macrotype = 'HOST', $options = []){ + $html = $this->__startWrap(); + $html.= $this->fetchHtml(); + $html.= $this->__endWrap(); + $html.= $this->addButton($options); + return $html; + } - /** - * Returns a string with the add new custom variable/macro button - * - * ### Options - * - * - `class` The CSS classes of the object - * - `href` The href link attribute - * - `style` CSS style properties - * - `label` Label/Caption of the Button - * - `jsSelector` The selector for javascript event bindings - * - * @param array $options Array of options - * @return string `` HTML object - * @author Daniel Ziegler - * @since 3.0 - * - */ - public function addButton($options = []){ - $_options = [ - 'class' => 'btn btn-success btn-xs pull-right margin-top-10', - 'href' => 'javascript:void(0);', - 'style' => '', - 'label' => ' '.__('Add new macro'), - 'jsSelector' => 'addCustomMacro' - ]; - $options = Hash::merge($_options, $options); - //return ''.$options['label'].''; - return ''; - } + /** + * Returns a string with the add new custom variable/macro button + * + * ### Options + * + * - `class` The CSS classes of the object + * - `href` The href link attribute + * - `style` CSS style properties + * - `label` Label/Caption of the Button + * - `jsSelector` The selector for javascript event bindings + * + * @param array $options Array of options + * @return string `` HTML object + * @author Daniel Ziegler + * @since 3.0 + * + */ + public function addButton($options = []){ + $_options = [ + 'class' => 'btn btn-success btn-xs pull-right margin-top-10', + 'href' => 'javascript:void(0);', + 'style' => '', + 'label' => ' '.__('Add new macro'), + 'jsSelector' => 'addCustomMacro' + ]; + $options = Hash::merge($_options, $options); + //return ''.$options['label'].''; + return ''; + } - /** - * Returns a string with the scaffold in HTML for macros - * - * ### Options - * - * - `name` Name of the macro - * - `value` Value of the macro - * - `macrotype` Type of the macro (default: $this->macrotype) - * - * @param integer $counter count of the current macro - * @return string $html with the scaffold in HTML for macros - * @author Daniel Ziegler - * @since 3.0 - * - */ - public function html($counter = 0, $options = []){ + /** + * Returns a string with the scaffold in HTML for macros + * + * ### Options + * + * - `name` Name of the macro + * - `value` Value of the macro + * - `macrotype` Type of the macro (default: $this->macrotype) + * + * @param integer $counter count of the current macro + * @return string $html with the scaffold in HTML for macros + * @author Daniel Ziegler + * @since 3.0 + * + */ + public function html($counter = 0, $options = []){ - $_options = [ - 'name' => '', - 'value' => '', - 'macrotype' => $this->macrotype, - 'id' => null, - 'objecttype_id' => $this->objecttype_id - ]; + $_options = [ + 'name' => '', + 'value' => '', + 'macrotype' => $this->macrotype, + 'id' => null, + 'objecttype_id' => $this->objecttype_id + ]; - $options = Hash::merge($_options, $options); - $html = '
-
-
- '.$this->macroPrefix.$options['macrotype'].$options['name'].$this->macroSuffix.' -
-
- - -
-
- - -
'; - if($options['id'] !== null){ - $html.=''; - } - if($options['objecttype_id'] !== null){ - $html.=''; - } - $html.='
- -
- - - -
-
'; + $options = Hash::merge($_options, $options); + $html = '
+
+
+ '.$this->macroPrefix.$options['macrotype'].$options['name'].$this->macroSuffix.' +
+
+ + +
+
+ + +
'; + if($options['id'] !== null){ + $html.=''; + } + if($options['objecttype_id'] !== null){ + $html.=''; + } + $html.='
+ +
+ + + +
+
'; - return $html; - } + return $html; + } - /** - * Returns a `
`HTML Object for wrappig the customvariables - * - * @return string `
` Object for wraping the customvariables - * @author Daniel Ziegler - * @since 3.0 - * - */ - public function __startWrap(){ - return '
'; - } + /** + * Returns a `
`HTML Object for wrappig the customvariables + * + * @return string `
` Object for wraping the customvariables + * @author Daniel Ziegler + * @since 3.0 + * + */ + public function __startWrap(){ + return '
'; + } - /** - * Returns a `
` HTML Object and clsoe the wrapper div - * - * @return string `
` closing div - * @author Daniel Ziegler - * @since 3.0 - * - */ - public function __endWrap(){ - return '
'; - } + /** + * Returns a `
` HTML Object and clsoe the wrapper div + * + * @return string `
` closing div + * @author Daniel Ziegler + * @since 3.0 + * + */ + public function __endWrap(){ + return '
'; + } - /** - * Returns the HTML of the custom variables (input fields) - * - * @return array $_customvariables if you dont want to use $this->customMacros and know what you are doint - * @author Daniel Ziegler - * @since 3.0 - * - */ - public function fetchHtml($_customvariables = []){ - $html = ''; - $customvariables = $this->customMacros; - if(!empty($_customvariables)){ - $customvariables = $_customvariables; - } - - if(!empty($customvariables)){ - $i = 0; - foreach($customvariables as $macro){ - if(!isset($macro['id'])){ - $macro['id'] = null; - } - $html.=$this->html($i, [ - 'name' => $macro['name'], - 'value' => $macro['value'], - 'id' => $macro['id'], - 'objecttype_id' => $this->objecttype_id - ]); - $i++; - } - } - return $html; - } + /** + * Returns the HTML of the custom variables (input fields) + * + * @return array $_customvariables if you dont want to use $this->customMacros and know what you are doint + * @author Daniel Ziegler + * @since 3.0 + * + */ + public function fetchHtml($_customvariables = []){ + $html = ''; + $customvariables = $this->customMacros; + if(!empty($_customvariables)){ + $customvariables = $_customvariables; + } + if(!empty($customvariables)){ + $i = Hash::apply($customvariables, '{n}.id', 'max')+1; + foreach($customvariables as $macro){ + if(!isset($macro['id'])){ + $macro['id'] = null; + } + $html.=$this->html($i, [ + 'name' => $macro['name'], + 'value' => $macro['value'], + 'id' => $macro['id'], + 'objecttype_id' => $this->objecttype_id + ]); + $i++; + } + } + return $html; + } } From bd41dc564e0e5b2a226f95729e20982b704f90fe Mon Sep 17 00:00:00 2001 From: ibering Date: Wed, 27 Jul 2016 11:42:24 +0200 Subject: [PATCH 2/5] #ITC-538 hide values in user defined macros, added hidden field -> password --- app/Config/Schema/schema_itcockpit_26.php | 1 + app/View/Macros/add_macro.ctp | 10 +++--- app/View/Macros/index.ctp | 11 +++++-- .../controllers/macros/index_controller.js | 33 ++++++++++++++++++- app/webroot/smartadmin/css/your_style.css | 10 ++++++ 5 files changed, 57 insertions(+), 8 deletions(-) diff --git a/app/Config/Schema/schema_itcockpit_26.php b/app/Config/Schema/schema_itcockpit_26.php index 915c47e02f..b0b1f4a9e7 100644 --- a/app/Config/Schema/schema_itcockpit_26.php +++ b/app/Config/Schema/schema_itcockpit_26.php @@ -602,6 +602,7 @@ public function after($event = array()) { 'name' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 10, 'collate' => 'utf8_swedish_ci', 'charset' => 'utf8'), 'value' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_swedish_ci', 'charset' => 'utf8'), 'description' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_swedish_ci', 'charset' => 'utf8'), + 'password' => ['type' => 'integer', 'null' => false, 'default' => 0, 'length' => 1], 'created' => array('type' => 'datetime', 'null' => false, 'default' => null), 'modified' => array('type' => 'datetime', 'null' => false, 'default' => null), 'indexes' => array( diff --git a/app/View/Macros/add_macro.ctp b/app/View/Macros/add_macro.ctp index 1edf64935f..64c68f6318 100755 --- a/app/View/Macros/add_macro.ctp +++ b/app/View/Macros/add_macro.ctp @@ -47,13 +47,15 @@ $uuid = sha1(UUID::v4()); + - - - + + + + + - \ No newline at end of file diff --git a/app/View/Macros/index.ctp b/app/View/Macros/index.ctp index 64af73da80..b0fbfde5ff 100755 --- a/app/View/Macros/index.ctp +++ b/app/View/Macros/index.ctp @@ -43,7 +43,7 @@
@@ -90,17 +90,22 @@ - +
+ + - + + + + diff --git a/app/webroot/js/app/controllers/macros/index_controller.js b/app/webroot/js/app/controllers/macros/index_controller.js index e8d24aeb91..cc9c3da5f7 100755 --- a/app/webroot/js/app/controllers/macros/index_controller.js +++ b/app/webroot/js/app/controllers/macros/index_controller.js @@ -25,6 +25,7 @@ App.Controllers.MacrosIndexController = Frontend.AppController.extend({ macroNames: null, + limit: 256, //limit for user macros components: ['Ajaxloader'], @@ -35,12 +36,34 @@ App.Controllers.MacrosIndexController = Frontend.AppController.extend({ $('.addMacro').click(function(){ this.addMacro(); + this.checkLimitReached(); }.bind(this)); $(document).on('click', '.deleteMacro', function(){ $(this).parent().parent().remove(); + self.checkLimitReached(); self.updateMacroNames(); }); + $(document).on('click', '.isPassword', function(){ + $(this).children('i').toggleClass('fa-eye-slash fa-eye').promise().done(function(){ + this.parent().toggleClass('txt-color-red txt-color-blue'); + if(this.hasClass('fa-eye')){ + this.closest('tr').find('input.systemsetting-input[name*="value"]').each(function(){ + $(this).addClass('macroPassword'); + }); + this.closest('tr').find('input:hidden[name*="password"]').each(function(){ + $(this).val(1); + }); + }else{ + this.closest('tr').find('input.systemsetting-input[name*="value"]').each(function(){ + $(this).removeClass('macroPassword'); + }); + this.closest('tr').find('input:hidden[name*="password"]').each(function(){ + $(this).val(0); + }); + } + }); + }); }, @@ -68,6 +91,14 @@ App.Controllers.MacrosIndexController = Frontend.AppController.extend({ $("[macro='name']").each(function(intKey, nameObject){ this.macroNames[$(nameObject).attr('uuid')] = $(nameObject).val(); }.bind(this)); - } + }, + checkLimitReached: function(){ + if($('#macrosTable > tbody > tr').not().has('td[id!="limitReached"]').length >= this.limit){ + $('#addNewMacro').hide(); + }else{ + $('#limitReached').parent().remove(); + $('#addNewMacro').show(); + } + } }); diff --git a/app/webroot/smartadmin/css/your_style.css b/app/webroot/smartadmin/css/your_style.css index a94e90da35..05ed0a24d5 100755 --- a/app/webroot/smartadmin/css/your_style.css +++ b/app/webroot/smartadmin/css/your_style.css @@ -1415,3 +1415,13 @@ label[class^='aco-host']:after, label[class^='aco-service']:after{ #FilterIndexForm label:after{ content:''; } + +.macroPassword{ + filter: blur(2px); + -webkit-filter: blur(2px); + -moz-filter: blur(2px); + -o-filter: blur(2px); + -ms-filter: blur(2px); + filter:progid:DXImageTransform.Microsoft.Blur(PixelRadius='2'); + -ms-filter:progid:DXImageTransform.Microsoft.Blur(PixelRadius='2'); +} \ No newline at end of file From 592148a7d89840bc6023845419e0ff8459f472a0 Mon Sep 17 00:00:00 2001 From: ibering Date: Fri, 29 Jul 2016 10:55:25 +0200 Subject: [PATCH 3/5] Bugfix #ITC-585, set NULL as default parameter for user and password (SetupShell and email config) --- app/Config/email.php | 4 +- app/Console/Command/SetupShell.php | 646 ++++++++++++++--------------- 2 files changed, 325 insertions(+), 325 deletions(-) diff --git a/app/Config/email.php b/app/Config/email.php index 5d685d5989..e89e7a3d8b 100644 --- a/app/Config/email.php +++ b/app/Config/email.php @@ -4,8 +4,8 @@ class EmailConfig { "transport" => "Smtp", "host" => "127.0.0.1", "port" => 25, - "username" => "", - "password" => "", + "username" => null, + "password" => null, ); public $fast = array( diff --git a/app/Console/Command/SetupShell.php b/app/Console/Command/SetupShell.php index 200c424cdc..15ea93e326 100644 --- a/app/Console/Command/SetupShell.php +++ b/app/Console/Command/SetupShell.php @@ -24,330 +24,330 @@ // confirmation. class SetupShell extends AppShell{ - public $uses = ['Systemsetting', 'User', 'Cronjob', 'ContainerUserMembership']; - - public $load = true; - - public function main(){ - if($this->load === true){ - App::uses('Folder', 'Utility'); - App::import('Component', 'Auth'); - $this->Auth = @new AuthComponent(null); - $this->load = false; - } - - - $this->stdout->styles('green', ['text' => 'green']); - $this->stdout->styles('blue', ['text' => 'blue']); - $this->stdout->styles('red', ['text' => 'red']); - - $this->parser = $this->getOptionParser(); - $this->out('This shell helps you to setup your fresh installation of openITCOCKPIT.'); - $this->out('NOTICE:'); - $this->out('Only run this shell, if you installed openITCOCKPIT right now and never logged in to the interface!'); - $this->out('If you continue, you will lose all your archive data!'); - $this->hr(); - $this->out(__d('oitc_console', '[Y]es I want to continue the setup of openITCOCKPIT')); - $this->out(__d('oitc_console', '[N]o and exit shell')); - $this->stdout->styles('red_bold', ['text' => 'red', 'bold' => true]); - - - $this->Userdata = ['User' => []]; - $this->Systemdata = ['Systemsetting' => []]; - $this->Mail = []; - - $menuSelection = strtoupper($this->in(__d('oitc_console', 'Are you sure to continue?'), array('Y', 'N'))); - switch($menuSelection){ - case 'Y': - $this->setup(); - break; - case 'N': - exit(1); - default: - $this->out(__d('oitc_console', 'You have made an invalid selection. Please choose by entering Y or N.')); - } - - $this->hr(); - $this->main(); - } - - public function setup(){ - if($this->fetchUserdata()){ - $this->User->create(); - if($this->User->saveAll($this->Userdata)){ - $this->out('User created successfully'); - if($this->fetchSystemAddress()){ - if($this->Systemsetting->save($this->Systemdata)){ - $this->out('Saved IP address successfully'); - if($this->fetchMailconfig()){ - if($this->Systemsetting->save($this->Systemdata)){ - //Return mail address saved successfully - $file = fopen(APP . 'Config' . DS . 'email.php', 'w+'); - fwrite($file, $this->mailTemplate($this->Mail)); - fclose($file); - $this->out('Mail configuration saved successfully'); - - $this->createMysqlPartitions(); - $this->createCronjobs(); - $this->out(''); - $this->hr(); - $this->out('You can now open the interface in your browser and login, have a nice day!'); - $this->hr(); - exit(0); - } - } - } - - } - }else{ - $this->out('The following errors occured:'); - $validationErrors = []; - foreach($this->User->validationErrors as $fieldName => $validationErrors){ - foreach($validationErrors as $validationError){ - $validationErrors[] = $validationError; - } - } - $validationErrors = array_unique($validationErrors); - foreach($validationErrors as $validationError){ - $this->out("\t" . '' . $validationError . ''); - } - } - } - - } - - public function fetchUserdata(){ - $this->Userdata['User']['firstname'] = $this->askFirstname(); - $this->Userdata['User']['lastname'] = $this->askLastname(); - $this->Userdata['User']['email'] = $this->askEmail(); - $this->Userdata['User']['new_password'] = $this->askPassword(); - $this->Userdata['User']['confirm_new_password'] = $this->Userdata['User']['new_password']; - $this->Userdata['User']['status'] = 1; - $this->Userdata['User']['usergroup_id'] = 1; - $this->Userdata['User']['Container'] = [0 => '1']; - $this->Userdata['ContainerUserMembership'] = [ - [ - 'container_id' => 1, - 'permission_level' => 2 - ], - ]; - - $this->out('You entered:'); - $this->out('First name:', false); - $this->out('' . $this->Userdata['User']['firstname'] . ''); - $this->out('Last name:', false); - $this->out('' . $this->Userdata['User']['lastname'] . ''); - $this->out('Email:', false); - $this->out('' . $this->Userdata['User']['email'] . ''); - $this->out('Password:', false); - $this->out('' . $this->Userdata['User']['new_password'] . ''); - - if(!$this->askContinue('If you want to continue type Y or N if you want to change the data')){ - $this->fetchUserdata(); - } - - return true; - - } - - public function askFirstname(){ - $input = $this->in(__d('oitc_console', 'Please enter your first name')); - $input = trim($input); - if(strlen($input) > 0){ - return $input; - } - $this->askFirstname(); - } - - public function askLastname(){ - $input = $this->in(__d('oitc_console', 'Please enter your last name')); - $input = trim($input); - if(strlen($input) > 0){ - return $input; - } - $this->askLastname(); - } - - public function askEmail(){ - $input = $this->in(__d('oitc_console', 'Please enter your email address. This will be the username for the login.')); - $input = trim($input); - if(!Validation::email($input)){ - $this->askEmail(); - } - return $input; - } - - public function askPassword(){ - $this->out('The password must consist of 6-12 alphanumeric characters and must contain at least one digit'); - $pw1 = $this->in(__d('oitc_console', 'Please enter a password for the login.')); - $pw1 = trim($pw1); - if(strlen($pw1) >= 6 && strlen($pw1) <= 12){ - $pw2 = $this->in(__d('oitc_console', 'Please confirm your password')); - $pw2 = trim($pw2); - if($pw1 == $pw2){ - return $pw1; - } - } - $this->out('Password mismatch!'); - $this->askPassword(); - } - - public function askContinue($message){ - $input = strtoupper($this->in(__d('oitc_console', $message), array('Y', 'N'))); - $input = trim($input); - if($input == 'Y'){ - return true; - }elseif($input == 'N'){ - return false; - }else{ - $this->askContinue(); - } - } - - public function fetchSystemAddress(){ - $currentValue = $this->Systemsetting->findByKey('SYSTEM.ADDRESS'); - $currentValue['Systemsetting']['value'] = $this->askSystemIp(); - $this->Systemdata = $currentValue; - return true; - } - - public function askSystemIp(){ - $input = $this->in(__d('oitc_console', 'Please enter the FQDN or IP address of your openITCOCKPIT Server. If you do not know your IP address enter a random one and change it via the interface later.')); - $input = trim($input); - if(strlen($input) > 0){ - return $input; - } - $this->askSystemIp(); - } - - public function fetchMailconfig(){ - $this->out('The installer will ask you now for your mail configuration'); - $this->out('This configuration is used by the interface and the monitoring software to send emails'); - $this->out('You don\'t need to install a local mailserver'); - $this->out('If you want to change this settings later ', false); - $this->out('' . APP . 'Config' . DS . 'email.php ', false); - $this->out(' is the place you need to search for'); - - $currentValue = $this->Systemsetting->findByKey('MONITORING.FROM_ADDRESS'); - $currentValue['Systemsetting']['value'] = $this->askFromAddress(); - $this->Systemdata = ['Systemsetting' => []]; - $this->Systemdata = $currentValue; - - $this->Mail['host'] = $this->askMailhost(); - $this->Mail['port'] = $this->askMailPort(); - $this->Mail['username'] = $this->askMailUser(); - $this->Mail['password'] = $this->askMailPassword(); - return true; - } - - public function askFromAddress(){ - $this->out('openITCOCKPIT requires a valid mail address to send mails. (e.g. openitcockpit@example.org)'); - $input = $this->in(__d('oitc_console', 'Please enter your return mail address')); - $input = trim($input); - if(!Validation::email($input)){ - $this->askFromAddress(); - } - return $input; - } - - public function askMailhost(){ - $this->out('If you want to use a local installed mail server (e.g.postfix) enter 127.0.0.1 as address and left username and password blank'); - $input = $this->in(__d('oitc_console', 'Please enter the address of your mail server (e.g. mail.example.org)')); - $input = trim($input); - if(strlen($input) > 0){ - return $input; - } - $this->askMailhost(); - } - - public function askMailPort(){ - $this->out('I guess you want to enter 25 as port'); - $input = $this->in(__d('oitc_console', 'Please enter the port of your mail server'), null, 25); - $input = trim($input); - if(strlen($input) > 0 && is_numeric($input)){ - return $input; - } - $this->askMailPort(); - } - - public function askMailUser(){ - $this->out('Your username may looks like ', false); - $this->out('domain\jdoe or john.doe@example.org'); - $input = $this->in(__d('oitc_console', 'Please enter your username, or leave it blank if you don\'t need a user')); - $input = trim($input); - return $input; - } - - public function askMailPassword(){ - $input = $this->in(__d('oitc_console', 'Please enter your password, or leave it blank if you don\'t need a password')); - $input = trim($input); - return $input; - } - - public function createMysqlPartitions(){ - $this->out('Create MySQL partitions', false); - if(file_exists('/etc/openitcockpit/mysql.cnf')){ - exec('mysql --defaults-extra-file=/etc/openitcockpit/mysql.cnf < ' . APP . 'partitions.sql', $out, $ret); - if($ret == 0){ - $this->out(' ...OK'); - return true; - } - $this->out(' ...ERROR'); - return false; - } - $this->out(' MySQL configuration file /etc/openitcockpit/mysql.cnf does not exist'); - return false; - } - - public function mailTemplate($options){ - return 'load === true){ + App::uses('Folder', 'Utility'); + App::import('Component', 'Auth'); + $this->Auth = @new AuthComponent(null); + $this->load = false; + } + + + $this->stdout->styles('green', ['text' => 'green']); + $this->stdout->styles('blue', ['text' => 'blue']); + $this->stdout->styles('red', ['text' => 'red']); + + $this->parser = $this->getOptionParser(); + $this->out('This shell helps you to setup your fresh installation of openITCOCKPIT.'); + $this->out('NOTICE:'); + $this->out('Only run this shell, if you installed openITCOCKPIT right now and never logged in to the interface!'); + $this->out('If you continue, you will lose all your archive data!'); + $this->hr(); + $this->out(__d('oitc_console', '[Y]es I want to continue the setup of openITCOCKPIT')); + $this->out(__d('oitc_console', '[N]o and exit shell')); + $this->stdout->styles('red_bold', ['text' => 'red', 'bold' => true]); + + + $this->Userdata = ['User' => []]; + $this->Systemdata = ['Systemsetting' => []]; + $this->Mail = []; + + $menuSelection = strtoupper($this->in(__d('oitc_console', 'Are you sure to continue?'), array('Y', 'N'))); + switch($menuSelection){ + case 'Y': + $this->setup(); + break; + case 'N': + exit(1); + default: + $this->out(__d('oitc_console', 'You have made an invalid selection. Please choose by entering Y or N.')); + } + + $this->hr(); + $this->main(); + } + + public function setup(){ + if($this->fetchUserdata()){ + $this->User->create(); + if($this->User->saveAll($this->Userdata)){ + $this->out('User created successfully'); + if($this->fetchSystemAddress()){ + if($this->Systemsetting->save($this->Systemdata)){ + $this->out('Saved IP address successfully'); + if($this->fetchMailconfig()){ + if($this->Systemsetting->save($this->Systemdata)){ + //Return mail address saved successfully + $file = fopen(APP . 'Config' . DS . 'email.php', 'w+'); + fwrite($file, $this->mailTemplate($this->Mail)); + fclose($file); + $this->out('Mail configuration saved successfully'); + + $this->createMysqlPartitions(); + $this->createCronjobs(); + $this->out(''); + $this->hr(); + $this->out('You can now open the interface in your browser and login, have a nice day!'); + $this->hr(); + exit(0); + } + } + } + + } + }else{ + $this->out('The following errors occured:'); + $validationErrors = []; + foreach($this->User->validationErrors as $fieldName => $validationErrors){ + foreach($validationErrors as $validationError){ + $validationErrors[] = $validationError; + } + } + $validationErrors = array_unique($validationErrors); + foreach($validationErrors as $validationError){ + $this->out("\t" . '' . $validationError . ''); + } + } + } + + } + + public function fetchUserdata(){ + $this->Userdata['User']['firstname'] = $this->askFirstname(); + $this->Userdata['User']['lastname'] = $this->askLastname(); + $this->Userdata['User']['email'] = $this->askEmail(); + $this->Userdata['User']['new_password'] = $this->askPassword(); + $this->Userdata['User']['confirm_new_password'] = $this->Userdata['User']['new_password']; + $this->Userdata['User']['status'] = 1; + $this->Userdata['User']['usergroup_id'] = 1; + $this->Userdata['User']['Container'] = [0 => '1']; + $this->Userdata['ContainerUserMembership'] = [ + [ + 'container_id' => 1, + 'permission_level' => 2 + ], + ]; + + $this->out('You entered:'); + $this->out('First name:', false); + $this->out('' . $this->Userdata['User']['firstname'] . ''); + $this->out('Last name:', false); + $this->out('' . $this->Userdata['User']['lastname'] . ''); + $this->out('Email:', false); + $this->out('' . $this->Userdata['User']['email'] . ''); + $this->out('Password:', false); + $this->out('' . $this->Userdata['User']['new_password'] . ''); + + if(!$this->askContinue('If you want to continue type Y or N if you want to change the data')){ + $this->fetchUserdata(); + } + + return true; + + } + + public function askFirstname(){ + $input = $this->in(__d('oitc_console', 'Please enter your first name')); + $input = trim($input); + if(strlen($input) > 0){ + return $input; + } + $this->askFirstname(); + } + + public function askLastname(){ + $input = $this->in(__d('oitc_console', 'Please enter your last name')); + $input = trim($input); + if(strlen($input) > 0){ + return $input; + } + $this->askLastname(); + } + + public function askEmail(){ + $input = $this->in(__d('oitc_console', 'Please enter your email address. This will be the username for the login.')); + $input = trim($input); + if(!Validation::email($input)){ + $this->askEmail(); + } + return $input; + } + + public function askPassword(){ + $this->out('The password must consist of 6-12 alphanumeric characters and must contain at least one digit'); + $pw1 = $this->in(__d('oitc_console', 'Please enter a password for the login.')); + $pw1 = trim($pw1); + if(strlen($pw1) >= 6 && strlen($pw1) <= 12){ + $pw2 = $this->in(__d('oitc_console', 'Please confirm your password')); + $pw2 = trim($pw2); + if($pw1 == $pw2){ + return $pw1; + } + } + $this->out('Password mismatch!'); + $this->askPassword(); + } + + public function askContinue($message){ + $input = strtoupper($this->in(__d('oitc_console', $message), array('Y', 'N'))); + $input = trim($input); + if($input == 'Y'){ + return true; + }elseif($input == 'N'){ + return false; + }else{ + $this->askContinue(); + } + } + + public function fetchSystemAddress(){ + $currentValue = $this->Systemsetting->findByKey('SYSTEM.ADDRESS'); + $currentValue['Systemsetting']['value'] = $this->askSystemIp(); + $this->Systemdata = $currentValue; + return true; + } + + public function askSystemIp(){ + $input = $this->in(__d('oitc_console', 'Please enter the FQDN or IP address of your openITCOCKPIT Server. If you do not know your IP address enter a random one and change it via the interface later.')); + $input = trim($input); + if(strlen($input) > 0){ + return $input; + } + $this->askSystemIp(); + } + + public function fetchMailconfig(){ + $this->out('The installer will ask you now for your mail configuration'); + $this->out('This configuration is used by the interface and the monitoring software to send emails'); + $this->out('You don\'t need to install a local mailserver'); + $this->out('If you want to change this settings later ', false); + $this->out('' . APP . 'Config' . DS . 'email.php ', false); + $this->out(' is the place you need to search for'); + + $currentValue = $this->Systemsetting->findByKey('MONITORING.FROM_ADDRESS'); + $currentValue['Systemsetting']['value'] = $this->askFromAddress(); + $this->Systemdata = ['Systemsetting' => []]; + $this->Systemdata = $currentValue; + + $this->Mail['host'] = $this->askMailhost(); + $this->Mail['port'] = $this->askMailPort(); + $this->Mail['username'] = $this->askMailUser(); + $this->Mail['password'] = $this->askMailPassword(); + return true; + } + + public function askFromAddress(){ + $this->out('openITCOCKPIT requires a valid mail address to send mails. (e.g. openitcockpit@example.org)'); + $input = $this->in(__d('oitc_console', 'Please enter your return mail address')); + $input = trim($input); + if(!Validation::email($input)){ + $this->askFromAddress(); + } + return $input; + } + + public function askMailhost(){ + $this->out('If you want to use a local installed mail server (e.g.postfix) enter 127.0.0.1 as address and left username and password blank'); + $input = $this->in(__d('oitc_console', 'Please enter the address of your mail server (e.g. mail.example.org)')); + $input = trim($input); + if(strlen($input) > 0){ + return $input; + } + $this->askMailhost(); + } + + public function askMailPort(){ + $this->out('I guess you want to enter 25 as port'); + $input = $this->in(__d('oitc_console', 'Please enter the port of your mail server'), null, 25); + $input = trim($input); + if(strlen($input) > 0 && is_numeric($input)){ + return $input; + } + $this->askMailPort(); + } + + public function askMailUser(){ + $this->out('Your username may looks like ', false); + $this->out('domain\jdoe or john.doe@example.org'); + $input = $this->in(__d('oitc_console', 'Please enter your username, or leave it blank if you don\'t need a user')); + $input = trim($input); + return (empty($input))?null:$input; + } + + public function askMailPassword(){ + $input = $this->in(__d('oitc_console', 'Please enter your password, or leave it blank if you don\'t need a password')); + $input = trim($input); + return (empty($input))?null:$input; + } + + public function createMysqlPartitions(){ + $this->out('Create MySQL partitions', false); + if(file_exists('/etc/openitcockpit/mysql.cnf')){ + exec('mysql --defaults-extra-file=/etc/openitcockpit/mysql.cnf < ' . APP . 'partitions.sql', $out, $ret); + if($ret == 0){ + $this->out(' ...OK'); + return true; + } + $this->out(' ...ERROR'); + return false; + } + $this->out(' MySQL configuration file /etc/openitcockpit/mysql.cnf does not exist'); + return false; + } + + public function mailTemplate($options){ + return ' "Smtp", - "host" => "' . $options['host'] . '", - "port" => ' . $options['port'] . ', - "username" => "' . $options['username'] . '", - "password" => "' . $options['password'] . '", - ); - - public $fast = array( - "from" => "you@localhost", - "sender" => null, - "to" => null, - "cc" => null, - "bcc" => null, - "replyTo" => null, - "readReceipt" => null, - "returnPath" => null, - "messageId" => true, - "subject" => null, - "message" => null, - "headers" => null, - "viewRender" => null, - "template" => false, - "layout" => false, - "viewVars" => null, - "attachments" => null, - "emailFormat" => null, - "transport" => "Smtp", - "host" => "localhost", - "port" => 25, - "timeout" => 30, - "username" => "user", - "password" => "secret", - "client" => null, - "log" => true - ); + public $default = array( + "transport" => "Smtp", + "host" => "' . $options['host'] . '", + "port" => ' . $options['port'] . ', + "username" => "' . $options['username'] . '", + "password" => "' . $options['password'] . '", + ); + + public $fast = array( + "from" => "you@localhost", + "sender" => null, + "to" => null, + "cc" => null, + "bcc" => null, + "replyTo" => null, + "readReceipt" => null, + "returnPath" => null, + "messageId" => true, + "subject" => null, + "message" => null, + "headers" => null, + "viewRender" => null, + "template" => false, + "layout" => false, + "viewVars" => null, + "attachments" => null, + "emailFormat" => null, + "transport" => "Smtp", + "host" => "localhost", + "port" => 25, + "timeout" => 30, + "username" => "user", + "password" => "secret", + "client" => null, + "log" => true + ); }'; - } - - public function createCronjobs(){ - $this->out('Checking for missing cronjobs'); - //Check if load cronjob exists - if(!$this->Cronjob->checkForCronjob('CpuLoad', 'Core')){ - //Cron does not exists, so we create it - $this->Cronjob->add('CpuLoad', 'Core', 15); - } - } + } + + public function createCronjobs(){ + $this->out('Checking for missing cronjobs'); + //Check if load cronjob exists + if(!$this->Cronjob->checkForCronjob('CpuLoad', 'Core')){ + //Cron does not exists, so we create it + $this->Cronjob->add('CpuLoad', 'Core', 15); + } + } } From 29b733cc4c45fe3d5f667de1c203b58c2f4bd635 Mon Sep 17 00:00:00 2001 From: ibering Date: Fri, 29 Jul 2016 13:36:08 +0200 Subject: [PATCH 4/5] ITC-585 Refactor mail configuration for cake 2.8 --- app/Console/Command/SetupShell.php | 60 +++------ .../Shell/Setup/MailConfigValueIntTest.php | 56 ++++++++ .../Case/Shell/Setup/MailConfigValueTest.php | 103 ++++++++++++++ .../Case/Shell/Setup/MailConfiguratorTest.php | 66 +++++++++ .../MailConfigWithUsernameAndPassword.txt | 39 ++++++ .../Setup/MailConfigWithoutCredentials.txt | 39 ++++++ .../Exceptions/NotIntException.php | 33 +++++ .../SetupShell/MailConfigValue.php | 69 ++++++++++ .../SetupShell/MailConfigValueInt.php | 76 +++++++++++ .../SetupShell/MailConfigurator.php | 126 ++++++++++++++++++ 10 files changed, 622 insertions(+), 45 deletions(-) create mode 100644 app/Test/Case/Shell/Setup/MailConfigValueIntTest.php create mode 100644 app/Test/Case/Shell/Setup/MailConfigValueTest.php create mode 100644 app/Test/Case/Shell/Setup/MailConfiguratorTest.php create mode 100644 app/Test/resources/Shell/Setup/MailConfigWithUsernameAndPassword.txt create mode 100644 app/Test/resources/Shell/Setup/MailConfigWithoutCredentials.txt create mode 100644 app/src/itnovum/openITCOCKPIT/Exceptions/NotIntException.php create mode 100644 app/src/itnovum/openITCOCKPIT/SetupShell/MailConfigValue.php create mode 100644 app/src/itnovum/openITCOCKPIT/SetupShell/MailConfigValueInt.php create mode 100644 app/src/itnovum/openITCOCKPIT/SetupShell/MailConfigurator.php diff --git a/app/Console/Command/SetupShell.php b/app/Console/Command/SetupShell.php index 15ea93e326..42eb65c5c7 100644 --- a/app/Console/Command/SetupShell.php +++ b/app/Console/Command/SetupShell.php @@ -23,6 +23,10 @@ // License agreement and license key will be shipped with the order // confirmation. +use \itnovum\openITCOCKPIT\SetupShell\MailConfigValue; +use \itnovum\openITCOCKPIT\SetupShell\MailConfigValueInt; +use \itnovum\openITCOCKPIT\SetupShell\MailConfigurator; + class SetupShell extends AppShell{ public $uses = ['Systemsetting', 'User', 'Cronjob', 'ContainerUserMembership']; @@ -83,7 +87,14 @@ public function setup(){ if($this->Systemsetting->save($this->Systemdata)){ //Return mail address saved successfully $file = fopen(APP . 'Config' . DS . 'email.php', 'w+'); - fwrite($file, $this->mailTemplate($this->Mail)); + $mailHost = new MailConfigValue($this->Mail['host']); + $mailPort = new MailConfigValueInt((int)$this->Mail['port']); + $mailUsername = new MailConfigValue($this->Mail['username']); + $mailPassword = new MailConfigValue($this->Mail['password']); + $mailConfigurator = new MailConfigurator( + $mailHost, $mailPort, $mailUsername, $mailPassword + ); + fwrite($file, $mailConfigurator->getConfig()); fclose($file); $this->out('Mail configuration saved successfully'); @@ -275,13 +286,13 @@ public function askMailUser(){ $this->out('domain\jdoe or john.doe@example.org'); $input = $this->in(__d('oitc_console', 'Please enter your username, or leave it blank if you don\'t need a user')); $input = trim($input); - return (empty($input))?null:$input; + return $input; } public function askMailPassword(){ $input = $this->in(__d('oitc_console', 'Please enter your password, or leave it blank if you don\'t need a password')); $input = trim($input); - return (empty($input))?null:$input; + return $input; } public function createMysqlPartitions(){ @@ -299,48 +310,7 @@ public function createMysqlPartitions(){ return false; } - public function mailTemplate($options){ - return ' "Smtp", - "host" => "' . $options['host'] . '", - "port" => ' . $options['port'] . ', - "username" => "' . $options['username'] . '", - "password" => "' . $options['password'] . '", - ); - - public $fast = array( - "from" => "you@localhost", - "sender" => null, - "to" => null, - "cc" => null, - "bcc" => null, - "replyTo" => null, - "readReceipt" => null, - "returnPath" => null, - "messageId" => true, - "subject" => null, - "message" => null, - "headers" => null, - "viewRender" => null, - "template" => false, - "layout" => false, - "viewVars" => null, - "attachments" => null, - "emailFormat" => null, - "transport" => "Smtp", - "host" => "localhost", - "port" => 25, - "timeout" => 30, - "username" => "user", - "password" => "secret", - "client" => null, - "log" => true - ); - -}'; - } + public function createCronjobs(){ $this->out('Checking for missing cronjobs'); diff --git a/app/Test/Case/Shell/Setup/MailConfigValueIntTest.php b/app/Test/Case/Shell/Setup/MailConfigValueIntTest.php new file mode 100644 index 0000000000..8cba891677 --- /dev/null +++ b/app/Test/Case/Shell/Setup/MailConfigValueIntTest.php @@ -0,0 +1,56 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + + +namespace itnovum\openITCOCKPIT\SetupShell; + + +class MailConfigValueIntTest extends \PHPUnit_Framework_TestCase +{ + public function testIsNotInt(){ + $this->setExpectedException('\itnovum\openITCOCKPIT\Exceptions\NotIntException'); + $intValue = new MailConfigValueInt('string'); + } + + public function testGetIntValueForConfig(){ + $intValue = new MailConfigValueInt(5); + $this->assertEquals(5, $intValue->getValueForConfig()); + } + + public function testGetIntValue(){ + $intValue = new MailConfigValueInt(5); + $this->assertEquals(5, $intValue->getValue()); + } + + public function testGetZeroValue(){ + $intValue = new MailConfigValueInt(0); + $this->assertEquals(0, $intValue->getValue()); + } + + public function testGetZeroValueForConfig(){ + $intValue = new MailConfigValueInt(0); + $this->assertEquals(0, $intValue->getValueForConfig()); + } +} diff --git a/app/Test/Case/Shell/Setup/MailConfigValueTest.php b/app/Test/Case/Shell/Setup/MailConfigValueTest.php new file mode 100644 index 0000000000..236c5511ab --- /dev/null +++ b/app/Test/Case/Shell/Setup/MailConfigValueTest.php @@ -0,0 +1,103 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + +// run test with: oitc test app Shell/Setup/MailConfigValue +namespace itnovum\openITCOCKPIT\SetupShell; + + +class MailConfigValueTest extends \PHPUnit_Framework_TestCase +{ + public function testGetEmptyValueForConfig() + { + $configValue = new MailConfigValue(''); + $this->assertEquals('null', $configValue->getValueForConfig()); + } + + public function testGetStringValueForConfig() + { + $configValue = new MailConfigValue('string'); + $this->assertEquals('"string"', $configValue->getValueForConfig()); + } + + public function testGetZeroValueForConfig() + { + $configValue = new MailConfigValue(0); + $this->assertEquals('null', $configValue->getValueForConfig()); + } + + public function testGetFalseValueForConfig() + { + $configValue = new MailConfigValue(false); + $this->assertEquals('null', $configValue->getValueForConfig()); + } + + public function testGetEmptyValue() + { + $configValue = new MailConfigValue(''); + $this->assertEquals('', $configValue->getValue()); + } + + public function testGetStringValue() + { + $configValue = new MailConfigValue('string'); + $this->assertEquals('string', $configValue->getValue()); + } + + public function testGetZeroValue() + { + $configValue = new MailConfigValue(0); + $this->assertEquals(0, $configValue->getValue()); + } + + public function testGetFalseValue() + { + $configValue = new MailConfigValue(false); + $this->assertEquals(false, $configValue->getValue()); + } + + public function testIsEmptyValue() + { + $configValue = new MailConfigValue(''); + $this->assertTrue($configValue->isEmpty()); + } + + public function testIsEmptyStringValue() + { + $configValue = new MailConfigValue('string'); + $this->assertFalse($configValue->isEmpty()); + } + + public function testIsEmptyZeroValue() + { + $configValue = new MailConfigValue(0); + $this->assertTrue($configValue->isEmpty()); + } + + public function testisEmptyFalseValue() + { + $configValue = new MailConfigValue(false); + $this->assertTrue($configValue->isEmpty()); + } +} diff --git a/app/Test/Case/Shell/Setup/MailConfiguratorTest.php b/app/Test/Case/Shell/Setup/MailConfiguratorTest.php new file mode 100644 index 0000000000..1b3855981d --- /dev/null +++ b/app/Test/Case/Shell/Setup/MailConfiguratorTest.php @@ -0,0 +1,66 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + + +namespace itnovum\openITCOCKPIT\SetupShell; + + +class MailConfiguratorTest extends \PHPUnit_Framework_TestCase +{ + private $resourcePath; + + public function setUp() + { + $this->resourcePath = TESTS.'resources'.DS.'Shell'.DS.'Setup'.DS; + } + + public function testGetConfigWithUsernameAndPassword(){ + $mailConfigurator = new MailConfigurator( + new MailConfigValue('host'), + new MailConfigValueInt(50), + new MailConfigValue('foobar'), + new MailConfigValue('barfoo') + ); + + $this->assertStringEqualsFile( + $this->resourcePath.'MailConfigWithUsernameAndPassword.txt', + $mailConfigurator->getConfig() + ); + } + + public function testGetConfigWithoutCredentials(){ + $mailConfigurator = new MailConfigurator( + new MailConfigValue('host'), + new MailConfigValueInt(50), + new MailConfigValue(''), + new MailConfigValue('') + ); + + $this->assertStringEqualsFile( + $this->resourcePath.'MailConfigWithoutCredentials.txt', + $mailConfigurator->getConfig() + ); + } +} diff --git a/app/Test/resources/Shell/Setup/MailConfigWithUsernameAndPassword.txt b/app/Test/resources/Shell/Setup/MailConfigWithUsernameAndPassword.txt new file mode 100644 index 0000000000..ecf207f992 --- /dev/null +++ b/app/Test/resources/Shell/Setup/MailConfigWithUsernameAndPassword.txt @@ -0,0 +1,39 @@ + "Smtp", + "host" => "host", + "port" => 50, + "username" => "foobar", + "password" => "barfoo", + ); + + public $fast = array( + "from" => "you@localhost", + "sender" => null, + "to" => null, + "cc" => null, + "bcc" => null, + "replyTo" => null, + "readReceipt" => null, + "returnPath" => null, + "messageId" => true, + "subject" => null, + "message" => null, + "headers" => null, + "viewRender" => null, + "template" => false, + "layout" => false, + "viewVars" => null, + "attachments" => null, + "emailFormat" => null, + "transport" => "Smtp", + "host" => "localhost", + "port" => 25, + "timeout" => 30, + "username" => "user", + "password" => "secret", + "client" => null, + "log" => true + ); +} diff --git a/app/Test/resources/Shell/Setup/MailConfigWithoutCredentials.txt b/app/Test/resources/Shell/Setup/MailConfigWithoutCredentials.txt new file mode 100644 index 0000000000..c3b34a16c7 --- /dev/null +++ b/app/Test/resources/Shell/Setup/MailConfigWithoutCredentials.txt @@ -0,0 +1,39 @@ + "Smtp", + "host" => "host", + "port" => 50, + "username" => null, + "password" => null, + ); + + public $fast = array( + "from" => "you@localhost", + "sender" => null, + "to" => null, + "cc" => null, + "bcc" => null, + "replyTo" => null, + "readReceipt" => null, + "returnPath" => null, + "messageId" => true, + "subject" => null, + "message" => null, + "headers" => null, + "viewRender" => null, + "template" => false, + "layout" => false, + "viewVars" => null, + "attachments" => null, + "emailFormat" => null, + "transport" => "Smtp", + "host" => "localhost", + "port" => 25, + "timeout" => 30, + "username" => "user", + "password" => "secret", + "client" => null, + "log" => true + ); +} diff --git a/app/src/itnovum/openITCOCKPIT/Exceptions/NotIntException.php b/app/src/itnovum/openITCOCKPIT/Exceptions/NotIntException.php new file mode 100644 index 0000000000..6bff9dc56c --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/Exceptions/NotIntException.php @@ -0,0 +1,33 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + + +namespace itnovum\openITCOCKPIT\Exceptions; + + +class NotIntException extends \Exception +{ + +} \ No newline at end of file diff --git a/app/src/itnovum/openITCOCKPIT/SetupShell/MailConfigValue.php b/app/src/itnovum/openITCOCKPIT/SetupShell/MailConfigValue.php new file mode 100644 index 0000000000..8d749d6c6f --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/SetupShell/MailConfigValue.php @@ -0,0 +1,69 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + + +namespace itnovum\openITCOCKPIT\SetupShell; + + +class MailConfigValue +{ + /** + * @var String + */ + private $value; + + /** + * MailConfigValue constructor. + * @param String $value + */ + function __construct($value) + { + $this->value = $value; + } + + /** + * @return String + */ + public function getValue(){ + return $this->value; + } + + /** + * @return string + */ + public function getValueForConfig(){ + if($this->isEmpty()){ + return 'null'; + } + return sprintf('"%s"', $this->value); + } + + /** + * @return bool + */ + public function isEmpty(){ + return empty($this->value); + } +} \ No newline at end of file diff --git a/app/src/itnovum/openITCOCKPIT/SetupShell/MailConfigValueInt.php b/app/src/itnovum/openITCOCKPIT/SetupShell/MailConfigValueInt.php new file mode 100644 index 0000000000..4f534c82aa --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/SetupShell/MailConfigValueInt.php @@ -0,0 +1,76 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + + +namespace itnovum\openITCOCKPIT\SetupShell; + + + +use itnovum\openITCOCKPIT\Exceptions\NotIntException; + +class MailConfigValueInt +{ + /** + * @var int + */ + private $value; + + /** + * MailConfigValueInt constructor. + * @param $value + * @throws NotIntException + */ + function __construct($value) + { + if(!is_int($value)){ + throw new NotIntException(sprintf('Value should be int %s given', gettype($value))); + } + $this->value = $value; + } + + /** + * @return String + */ + public function getValue(){ + return $this->value; + } + + /** + * @return string + */ + public function getValueForConfig(){ + if($this->isEmpty()){ + return 0; + } + return $this->value; + } + + /** + * @return bool + */ + public function isEmpty(){ + return empty($this->value); + } +} \ No newline at end of file diff --git a/app/src/itnovum/openITCOCKPIT/SetupShell/MailConfigurator.php b/app/src/itnovum/openITCOCKPIT/SetupShell/MailConfigurator.php new file mode 100644 index 0000000000..a64409413d --- /dev/null +++ b/app/src/itnovum/openITCOCKPIT/SetupShell/MailConfigurator.php @@ -0,0 +1,126 @@ + +// +// This file is dual licensed +// +// 1. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +// 2. +// If you purchased an openITCOCKPIT Enterprise Edition you can use this file +// under the terms of the openITCOCKPIT Enterprise Edition license agreement. +// License agreement and license key will be shipped with the order +// confirmation. + + +namespace itnovum\openITCOCKPIT\SetupShell; + + +class MailConfigurator +{ + /** + * @var MailConfigValue + */ + private $host; + + /** + * @var MailConfigValueInt + */ + private $port; + + /** + * @var MailConfigValue + */ + private $username; + + /** + * @var MailConfigValue + */ + private $password; + + /** + * MailConfigurator constructor. + * @param MailConfigValue $host + * @param MailConfigValueInt $port + * @param MailConfigValue $username + * @param MailConfigValue $password + */ + public function __construct(MailConfigValue $host, MailConfigValueInt $port, MailConfigValue $username, MailConfigValue $password) + { + $this->host = $host; + $this->port = $port; + $this->username = $username; + $this->password = $password; + } + + /** + * @return string + */ + public function getConfig(){ + return sprintf( + $this->getTemplate(), + $this->host->getValueForConfig(), + $this->port->getValueForConfig(), + $this->username->getValueForConfig(), + $this->password->getValueForConfig() + ); + } + + /** + * @return string + */ + public function getTemplate(){ + $template = ' "Smtp", + "host" => %s, + "port" => %s, + "username" => %s, + "password" => %s, + ); + + public $fast = array( + "from" => "you@localhost", + "sender" => null, + "to" => null, + "cc" => null, + "bcc" => null, + "replyTo" => null, + "readReceipt" => null, + "returnPath" => null, + "messageId" => true, + "subject" => null, + "message" => null, + "headers" => null, + "viewRender" => null, + "template" => false, + "layout" => false, + "viewVars" => null, + "attachments" => null, + "emailFormat" => null, + "transport" => "Smtp", + "host" => "localhost", + "port" => 25, + "timeout" => 30, + "username" => "user", + "password" => "secret", + "client" => null, + "log" => true + ); +} +'; + return $template; + } +} \ No newline at end of file From c3caaa43b7f9da894986af1a8a13e39af120dca0 Mon Sep 17 00:00:00 2001 From: Maximilian Pappert Date: Wed, 3 Aug 2016 08:20:44 +0200 Subject: [PATCH 5/5] [-]Fixed Paginator list length for lists > 100 ITC-600 #dev-to-qa-queue --- app/Controller/AppController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Controller/AppController.php b/app/Controller/AppController.php index aa9e0fd2c4..2238b5976f 100644 --- a/app/Controller/AppController.php +++ b/app/Controller/AppController.php @@ -237,8 +237,13 @@ protected function __getUserRights(){ } } + if(!empty($this->Auth->user('paginatorlength'))){ $this->Paginator->settings['limit'] = $this->Auth->user('paginatorlength'); + if($this->Auth->user('paginatorlength') > 100){ + //paginator maxLimit must be also set now + $this->Paginator->settings['maxLimit'] = $this->Auth->user('paginatorlength'); + } }else{ $this->Paginator->settings['limit'] = 25; }