Ejemplo n.º 1
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $what = new \Zend\Form\Element\Radio('What');
     $what->setValueOptions(array(\Model\Client\Client::MEMBERSHIP_AUTOMATIC => $this->_('Store search parameters. Group memberships will be updated automatically.'), \Model\Client\Client::MEMBERSHIP_ALWAYS => $this->_('Add current search results. Group memberships will be set only this time.'), \Model\Client\Client::MEMBERSHIP_NEVER => $this->_('Exclude search results from a group.')));
     $what->setValue(\Model\Client\Client::MEMBERSHIP_AUTOMATIC);
     $this->add($what);
     $where = new \Zend\Form\Element\Radio('Where');
     $where->setValueOptions(array('new' => $this->_('Store in new group'), 'existing' => $this->_('Store in existing group')));
     $where->setValue('new')->setAttribute('onchange', 'selectElements()');
     $this->add($where);
     $newGroup = new \Zend\Form\Element\Text('NewGroup');
     $newGroup->setLabel('Name');
     $this->add($newGroup);
     $description = new \Zend\Form\Element\Text('Description');
     $description->setLabel('Description');
     $this->add($description);
     $existingGroup = new \Library\Form\Element\SelectSimple('ExistingGroup');
     $existingGroup->setLabel('Group');
     $groups = array();
     foreach ($this->getOption('GroupManager')->getGroups(null, null, 'Name') as $group) {
         $groups[] = $group['Name'];
     }
     $existingGroup->setValueOptions($groups);
     $this->add($existingGroup);
     $submit = new \Library\Form\Element\Submit('Submit');
     $submit->setLabel('OK');
     $this->add($submit);
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $inputFilter->add(array('name' => 'NewGroup', 'continue_if_empty' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateLength'), 'callbackOptions' => array(0, 255), 'message' => $this->_('The input is more than 255 characters long')), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateLength'), 'callbackOptions' => array(1, 255), 'message' => "Value is required and can't be empty"), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateGroupExists'), 'message' => $this->_('The name already exists'))))));
     $inputFilter->add(array('name' => 'Description', 'required' => false, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'Null', 'options' => array('type' => 'string'))), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateLength'), 'callbackOptions' => array(0, 255), 'message' => $this->_('The input is more than 255 characters long'))))));
     $this->setInputFilter($inputFilter);
 }
Ejemplo n.º 2
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $preferences = $this->get('Preferences');
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $communicationServerUri = new \Zend\Form\Element\Text('communicationServerUri');
     $communicationServerUri->setLabel('Communication server URI');
     $preferences->add($communicationServerUri);
     $inputFilter->add(array('name' => 'communicationServerUri', 'validators' => array(array('name' => 'Uri', 'options' => array('uriHandler' => 'Zend\\Uri\\Http', 'allowRelative' => false)))));
     $lockValidity = new \Zend\Form\Element\Text('lockValidity');
     $lockValidity->setLabel('Maximum seconds to lock a computer')->setAttribute('size', 5);
     $preferences->add($lockValidity);
     $inputFilter->add($this->_getIntegerFilter('lockValidity'));
     $sessionValidity = new \Zend\Form\Element\Text('sessionValidity');
     $sessionValidity->setLabel('Maximum duration of an agent session in seconds')->setAttribute('size', 5);
     $preferences->add($sessionValidity);
     $inputFilter->add($this->_getIntegerFilter('sessionValidity'));
     $sessionCleanupInterval = new \Zend\Form\Element\Text('sessionCleanupInterval');
     $sessionCleanupInterval->setLabel('Interval in seconds to cleanup sessions')->setAttribute('size', 5);
     $preferences->add($sessionCleanupInterval);
     $inputFilter->add($this->_getIntegerFilter('sessionCleanupInterval'));
     $sessionRequired = new \Zend\Form\Element\Checkbox('sessionRequired');
     $sessionRequired->setLabel('Session required for inventory');
     $preferences->add($sessionRequired);
     $logLevel = new \Library\Form\Element\SelectSimple('logLevel');
     $logLevel->setLabel('Log level')->setValueOptions(array(0, 1, 2));
     $preferences->add($logLevel);
     $autoMergeDuplicates = new \Zend\Form\Element\Checkbox('autoMergeDuplicates');
     $autoMergeDuplicates->setLabel('Merge duplicates automatically (not recommended)');
     $preferences->add($autoMergeDuplicates);
     $parentFilter = new \Zend\InputFilter\InputFilter();
     $parentFilter->add($inputFilter, 'Preferences');
     $this->setInputFilter($parentFilter);
 }
Ejemplo n.º 3
0
 public function testInArrayValidator()
 {
     $element = new \Library\Form\Element\SelectSimple();
     $element->setValueOptions(array('option1', 'option2'));
     $factory = new \Zend\InputFilter\Factory();
     $input = $factory->createInput($element->getInputSpecification());
     $input->setValue('option1');
     $this->assertTrue($input->isValid());
     $input->setValue('option2');
     $this->assertTrue($input->isValid());
     $input->setValue('option3');
     $this->assertFalse($input->isValid());
 }
Ejemplo n.º 4
0
    public function testFormElementHelperIntegration()
    {
        $element = new \Library\Form\Element\SelectSimple('test');
        $element->setValueOptions(array('option<b>1', 'option2'))->setValue('option<b>1');
        $expected = <<<EOT
<select name="test">
<option selected="selected">option&lt;b&gt;1</option>
<option>option2</option>
</select>
EOT;
        $view = new \Zend\View\Renderer\PhpRenderer();
        $view->setHelperPluginManager(static::$_helperManager);
        $helper = static::$_helperManager->get('formElement');
        $helper->setView($view);
        $this->assertEquals($expected, $helper($element));
    }
Ejemplo n.º 5
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $type = new \Library\Form\Element\SelectSimple('Type');
     $type->setLabel('Type')->setValueOptions($this->getOption('DeviceManager')->getTypes());
     $this->add($type);
     $description = new \Zend\Form\Element\Text('Description');
     $description->setLabel('Description');
     $this->add($description);
     $submit = new \Library\Form\Element\Submit('Submit');
     $submit->setLabel('OK');
     $this->add($submit);
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $inputFilter->add(array('name' => 'Description', 'required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 255)))));
     $this->setInputFilter($inputFilter);
 }
Ejemplo n.º 6
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $preferences = $this->get('Preferences');
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $packageDeployment = new \Zend\Form\Element\Checkbox('packageDeployment');
     $packageDeployment->setLabel('Enable package download');
     $preferences->add($packageDeployment);
     $packagePath = new \Zend\Form\Element\Text('packagePath');
     $packagePath->setLabel('Package storage directory');
     $preferences->add($packagePath);
     $inputFilter->add(array('name' => 'packagePath', 'validators' => array(array('name' => 'Library\\Validator\\DirectoryWritable'))));
     $packageBaseUriHttp = new \Zend\Form\Element\Text('packageBaseUriHttp');
     $packageBaseUriHttp->setLabel('HTTP package base URL');
     $preferences->add($packageBaseUriHttp);
     $inputFilter->add(array('name' => 'packageBaseUriHttp', 'filters' => array(array('name' => 'StringTrim'), array('name' => 'PregReplace', 'options' => array('pattern' => '#(.*://|/$)#', 'replacement' => ''))), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateUri'))))));
     $packageBaseUriHttps = new \Zend\Form\Element\Text('packageBaseUriHttps');
     $packageBaseUriHttps->setLabel('HTTPS package base URL');
     $preferences->add($packageBaseUriHttps);
     $inputFilter->add(array('name' => 'packageBaseUriHttps', 'filters' => array(array('name' => 'StringTrim'), array('name' => 'PregReplace', 'options' => array('pattern' => '#(.*://|/$)#', 'replacement' => ''))), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateUri'))))));
     $downloadPeriodDelay = new \Zend\Form\Element\Text('downloadPeriodDelay');
     $downloadPeriodDelay->setLabel('Delay (in seconds) between periods')->setAttribute('size', 5);
     $preferences->add($downloadPeriodDelay);
     $inputFilter->add($this->_getIntegerFilter('downloadPeriodDelay'));
     $downloadCycleDelay = new \Zend\Form\Element\Text('downloadCycleDelay');
     $downloadCycleDelay->setLabel('Delay (in seconds) between cycles')->setAttribute('size', 5);
     $preferences->add($downloadCycleDelay);
     $inputFilter->add($this->_getIntegerFilter('downloadCycleDelay'));
     $downloadFragmentDelay = new \Zend\Form\Element\Text('downloadFragmentDelay');
     $downloadFragmentDelay->setLabel('Delay (in seconds) between fragments')->setAttribute('size', 5);
     $preferences->add($downloadFragmentDelay);
     $inputFilter->add($this->_getIntegerFilter('downloadFragmentDelay'));
     $downloadMaxPriority = new \Library\Form\Element\SelectSimple('downloadMaxPriority');
     $downloadMaxPriority->setLabel('Maximum package priority (packages with higher value will not be downloaded)')->setValueOptions(range(0, 10));
     $preferences->add($downloadMaxPriority);
     $downloadTimeout = new \Zend\Form\Element\Text('downloadTimeout');
     $downloadTimeout->setLabel('Timeout (in days)')->setAttribute('size', 5);
     $preferences->add($downloadTimeout);
     $inputFilter->add($this->_getIntegerFilter('downloadTimeout'));
     $parentFilter = new \Zend\InputFilter\InputFilter();
     $parentFilter->add($inputFilter, 'Preferences');
     $this->setInputFilter($parentFilter);
 }
Ejemplo n.º 7
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $integerFilter = array('name' => 'Callback', 'options' => array('callback' => array($this, 'normalize'), 'callback_params' => 'integer'));
     $integerValidator = array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateType'), 'callbackOptions' => 'integer'));
     // Package name
     $name = new Element\Text('Name');
     $name->setLabel('Name');
     $this->add($name);
     $inputFilter->add(array('name' => 'Name', 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 255)), array('name' => 'Library\\Validator\\NotInArray', 'options' => array('haystack' => $this->getOption('packageManager')->getAllNames(), 'caseSensitivity' => \Library\Validator\NotInArray::CASE_INSENSITIVE)))));
     // Comment
     $comment = new Element\Textarea('Comment');
     $comment->setLabel('Comment');
     $this->add($comment);
     $inputFilter->add(array('name' => 'Comment', 'required' => false, 'filters' => array(array('name' => 'StringTrim'))));
     // Platform combobox
     $platform = new Element\Select('Platform');
     $platform->setLabel('Platform')->setAttribute('type', 'select_untranslated')->setAttribute('id', 'form_package_build_platform')->setAttribute('onchange', 'changePlatform()')->setValueOptions(array('windows' => 'Windows', 'linux' => 'Linux', 'mac' => 'MacOS'));
     $this->add($platform);
     // Action combobox
     // Translate labels manually to let xgettext recognize them
     $action = new Element\Select('DeployAction');
     $action->setLabel('Action')->setAttribute('onchange', 'changeParam()')->setValueOptions(array('launch' => $this->_('Download package, execute command, retrieve result'), 'execute' => $this->_('Optionally download package, execute command'), 'store' => $this->_('Just download package to target path')));
     $this->add($action);
     // Command line or target path for action
     // Label is set by JavaScript code.
     $actionParam = new Element\Text('ActionParam');
     $this->add($actionParam);
     $inputFilter->add(array('name' => 'ActionParam', 'required' => true));
     // Upload file
     $file = new Element\File('File');
     $file->setLabel('File');
     $this->add($file);
     $inputFilter->add(array('name' => 'File'));
     // Requirement is set in isValid()
     // Priority combobox
     $priority = new \Library\Form\Element\SelectSimple('Priority');
     $priority->setValueOptions(range(0, 10))->setLabel('Priority (0: exclusive, 10: lowest)');
     $this->add($priority);
     // Maximum fragment size.
     $maxFragmentSize = new Element\Text('MaxFragmentSize');
     $maxFragmentSize->setAttribute('size', '8')->setLabel('Maximum fragment size (kB)');
     $this->add($maxFragmentSize);
     $inputFilter->add(array('name' => 'MaxFragmentSize', 'required' => false, 'filters' => array($integerFilter), 'validators' => array($integerValidator)));
     // Warn user before installation
     $warn = new Element\Checkbox('Warn');
     $warn->setLabel('Warn user')->setAttribute('id', 'form_package_build_warn')->setAttribute('onchange', 'toggleWarn()');
     $this->add($warn);
     // Message to display to user before installation
     $warnMessage = new Element\Textarea('WarnMessage');
     $warnMessage->setLabel('Message');
     $this->add($warnMessage);
     $inputFilter->add(array('name' => 'WarnMessage', 'required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateNotificationMessage'), 'message' => $this->_('Message must not contain double quotes.'))))));
     // Countdown before installation starts automatically
     $warnCountdown = new Element\Text('WarnCountdown');
     $warnCountdown->setAttribute('size', '5')->setLabel('Countdown (seconds)');
     $this->add($warnCountdown);
     $inputFilter->add(array('name' => 'WarnCountdown', 'required' => false, 'filters' => array($integerFilter), 'validators' => array($integerValidator)));
     // Allow user abort
     $warnAllowAbort = new Element\Checkbox('WarnAllowAbort');
     $warnAllowAbort->setLabel('Allow abort by user');
     $this->add($warnAllowAbort);
     // Allow user delay
     $warnAllowDelay = new Element\Checkbox('WarnAllowDelay');
     $warnAllowDelay->setLabel('Allow delay by user');
     $this->add($warnAllowDelay);
     // Message to display to user after deployment
     $postInstMessage = new Element\Textarea('PostInstMessage');
     $postInstMessage->setLabel('Post-installation message');
     $this->add($postInstMessage);
     $inputFilter->add(array('name' => 'PostInstMessage', 'required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateNotificationMessage'), 'message' => $this->_('Message must not contain double quotes.'))))));
     // Submit button
     $submit = new \Library\Form\Element\Submit('Submit');
     $submit->setLabel('Build');
     $this->add($submit);
     $this->setInputFilter($inputFilter);
 }
Ejemplo n.º 8
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $inputFilter = new \Zend\InputFilter\InputFilter();
     // Agent options
     $agent = new \Zend\Form\Fieldset('Agent');
     $inputFilterAgent = new \Zend\InputFilter\InputFilter();
     $contactInterval = new Element\Text('contactInterval');
     $contactInterval->setLabel('Agent contact interval (in hours)')->setAttribute('size', '5');
     $agent->add($contactInterval);
     $inputFilterAgent->add($this->_getIntegerFilter('contactInterval', 1));
     $inventoryInterval = new Element\Text('inventoryInterval');
     $inventoryInterval->setLabel('Inventory interval (in days, 0 = always, -1 = never)')->setAttribute('size', '5');
     $agent->add($inventoryInterval);
     $inputFilterAgent->add($this->_getIntegerFilter('inventoryInterval', -1));
     $this->add($agent);
     $inputFilter->add($inputFilterAgent, 'Agent');
     // Download options
     $download = new \Zend\Form\Fieldset('Download');
     $inputFilterDownload = new \Zend\InputFilter\InputFilter();
     $packageDeployment = new Element\Checkbox('packageDeployment');
     $packageDeployment->setLabel('Enable package download')->setAttribute('onchange', 'toggle(this)');
     $download->add($packageDeployment);
     $downloadPeriodDelay = new Element\Text('downloadPeriodDelay');
     $downloadPeriodDelay->setLabel('Delay (in seconds) between periods')->setAttribute('size', '5');
     $download->add($downloadPeriodDelay);
     $inputFilterDownload->add($this->_getIntegerFilter('downloadPeriodDelay', 1));
     $downloadCycleDelay = new Element\Text('downloadCycleDelay');
     $downloadCycleDelay->setLabel('Delay (in seconds) between cycles')->setAttribute('size', '5');
     $download->add($downloadCycleDelay);
     $inputFilterDownload->add($this->_getIntegerFilter('downloadCycleDelay', 1));
     $downloadFragmentDelay = new Element\Text('downloadFragmentDelay');
     $downloadFragmentDelay->setLabel('Delay (in seconds) between fragments')->setAttribute('size', '5');
     $download->add($downloadFragmentDelay);
     $inputFilterDownload->add($this->_getIntegerFilter('downloadFragmentDelay', 1));
     $downloadMaxPriority = new Element\Text('downloadMaxPriority');
     $downloadMaxPriority->setLabel('Maximum package priority')->setAttribute('size', '5');
     $download->add($downloadMaxPriority);
     $inputFilterDownload->add($this->_getIntegerFilter('downloadMaxPriority', 1));
     $downloadTimeout = new Element\Text('downloadTimeout');
     $downloadTimeout->setLabel('Timeout (in days)')->setAttribute('size', '5');
     $download->add($downloadTimeout);
     $inputFilterDownload->add($this->_getIntegerFilter('downloadTimeout', 1));
     $this->add($download);
     $inputFilter->add($inputFilterDownload, 'Download');
     // Network scanning options
     $scan = new \Zend\Form\Fieldset('Scan');
     $inputFilterScan = new \Zend\InputFilter\InputFilter();
     $allowScan = new Element\Checkbox('allowScan');
     $allowScan->setLabel('Allow network scanning')->setAttribute('onchange', 'toggle(this)');
     $scan->add($allowScan);
     $subnets = new \Library\Form\Element\SelectSimple('scanThisNetwork');
     $subnets->setLabel('Always scan this network')->setEmptyOption('');
     $scan->add($subnets);
     $inputFilterScan->add(array('name' => 'scanThisNetwork', 'required' => false));
     $scanSnmp = new Element\Checkbox('scanSnmp');
     $scanSnmp->setLabel('Use SNMP');
     $scan->add($scanSnmp);
     $this->add($scan);
     $inputFilter->add($inputFilterScan, 'Scan');
     $submit = new \Library\Form\Element\Submit('Submit');
     $submit->setLabel('OK');
     $this->add($submit);
     $this->setInputFilter($inputFilter);
 }
Ejemplo n.º 9
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $preferences = $this->get('Preferences');
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $integerFilter = array('name' => 'Callback', 'options' => array('callback' => array($this, 'normalize'), 'callback_params' => 'integer'));
     $integerValidator = array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateType'), 'callbackOptions' => 'integer'));
     $deploy = new \Zend\Form\Fieldset('Deploy');
     $deploy->setLabel('Defaults for deploying updated packages');
     $deployNonnotified = new \Zend\Form\Element\Checkbox('defaultDeployNonnotified');
     $deployNonnotified->setLabel('Not notified');
     $deploy->add($deployNonnotified);
     $deploySuccess = new \Zend\Form\Element\Checkbox('defaultDeploySuccess');
     $deploySuccess->setLabel('Success');
     $deploy->add($deploySuccess);
     $deployNotified = new \Zend\Form\Element\Checkbox('defaultDeployNotified');
     $deployNotified->setLabel('Running');
     $deploy->add($deployNotified);
     $deployError = new \Zend\Form\Element\Checkbox('defaultDeployError');
     $deployError->setLabel('Error');
     $deploy->add($deployError);
     $deployGroups = new \Zend\Form\Element\Checkbox('defaultDeployGroups');
     $deployGroups->setLabel('Groups');
     $deploy->add($deployGroups);
     $preferences->add($deploy);
     $defaultPlatform = new \Zend\Form\Element\Select('defaultPlatform');
     $defaultPlatform->setLabel('Default platform')->setAttribute('type', 'select_untranslated')->setValueOptions(array('windows' => 'Windows', 'linux' => 'Linux', 'mac' => 'MacOS'));
     $preferences->add($defaultPlatform);
     $defaultAction = new \Zend\Form\Element\Select('defaultAction');
     $defaultAction->setLabel('Default action')->setValueOptions(array('launch' => $this->_('Download package, execute command, retrieve result'), 'execute' => $this->_('Optionally download package, execute command'), 'store' => $this->_('Just download package to target path')));
     $preferences->add($defaultAction);
     $defaultActionParam = new \Zend\Form\Element\Text('defaultActionParam');
     $defaultActionParam->setLabel('Default action parameter');
     $preferences->add($defaultActionParam);
     $defaultPackagePriority = new \Library\Form\Element\SelectSimple('defaultPackagePriority');
     $defaultPackagePriority->setValueOptions(range(0, 10))->setLabel('Default priority (0: exclusive, 10: lowest)');
     $preferences->add($defaultPackagePriority);
     $defaultMaxFragmentSize = new \Zend\Form\Element\Text('defaultMaxFragmentSize');
     $defaultMaxFragmentSize->setAttribute('size', '8')->setLabel('Default maximum fragment size (kB)');
     $preferences->add($defaultMaxFragmentSize);
     $inputFilter->add(array('name' => 'defaultMaxFragmentSize', 'required' => false, 'filters' => array($integerFilter), 'validators' => array($integerValidator)));
     $defaultWarn = new \Zend\Form\Element\Checkbox('defaultWarn');
     $defaultWarn->setLabel('Warn user by default');
     $preferences->add($defaultWarn);
     $defaultWarnMessage = new \Zend\Form\Element\Textarea('defaultWarnMessage');
     $defaultWarnMessage->setLabel('Default warn message');
     $preferences->add($defaultWarnMessage);
     $defaultWarnCountdown = new \Zend\Form\Element\Text('defaultWarnCountdown');
     $defaultWarnCountdown->setAttribute('size', '5')->setLabel('Default warn countdown (seconds)');
     $preferences->add($defaultWarnCountdown);
     $inputFilter->add(array('name' => 'defaultWarnCountdown', 'required' => false, 'filters' => array($integerFilter), 'validators' => array($integerValidator)));
     $defaultWarnAllowAbort = new \Zend\Form\Element\Checkbox('defaultWarnAllowAbort');
     $defaultWarnAllowAbort->setLabel('Allow user abort by default');
     $preferences->add($defaultWarnAllowAbort);
     $defaultWarnAllowDelay = new \Zend\Form\Element\Checkbox('defaultWarnAllowDelay');
     $defaultWarnAllowDelay->setLabel('Allow user delay by default');
     $preferences->add($defaultWarnAllowDelay);
     $defaultPostInstMessage = new \Zend\Form\Element\Textarea('defaultPostInstMessage');
     $defaultPostInstMessage->setLabel('Default post-installation message');
     $preferences->add($defaultPostInstMessage);
     $parentFilter = new \Zend\InputFilter\InputFilter();
     $parentFilter->add($inputFilter, 'Preferences');
     $this->setInputFilter($parentFilter);
 }