コード例 #1
0
ファイル: AddBySNMP.php プロジェクト: E-Poludnie/IXP-Manager
 public function init()
 {
     $name = $this->createElement('text', 'name');
     $name->addValidator('stringLength', false, array(1, 255, 'UTF-8'))->setAttrib('class', 'span3')->setRequired(true)->setLabel('Name')->addFilter('StringTrim')->addFilter(new OSS_Filter_StripSlashes());
     $this->addElement($name);
     $hostname = $this->createElement('text', 'hostname');
     $hostname->addValidator('stringLength', false, array(1, 255, 'UTF-8'))->setAttrib('class', 'span3')->setRequired(true)->setLabel('Hostname')->addFilter('StringTrim')->addFilter(new OSS_Filter_StripSlashes());
     $this->addElement($hostname);
     $switchtype = $this->createElement('select', 'switchtype');
     $switchtype->setMultiOptions(\Entities\Switcher::$TYPES)->setAttrib('class', 'span3 chzn-select')->setRegisterInArrayValidator(true)->addValidator('greaterThan', true, array(0))->setLabel('Type')->setErrorMessages(array('Please set the switch type'));
     $this->addElement($switchtype);
     $this->addElement(IXP_Form_Cabinet::getPopulatedSelect('cabinetid'));
     $infrastructure = IXP_Form_Infrastructure::getPopulatedSelect('infrastructure');
     $this->addElement($infrastructure);
     $snmppasswd = $this->createElement('text', 'snmppasswd');
     $snmppasswd->addValidator('stringLength', false, array(1, 255, 'UTF-8'))->setAttrib('class', 'span3')->setLabel('SNMP Community')->addFilter('StringTrim')->addFilter(new OSS_Filter_StripSlashes());
     $this->addElement($snmppasswd);
     $active = $this->createElement('checkbox', 'active');
     $active->setLabel('Active?')->setCheckedValue('1')->setUncheckedValue('0')->setValue('1');
     $this->addElement($active);
     $this->addElement(self::createSubmitElement('submit', _('Next')));
     $this->addElement($this->createCancelElement('cancel', OSS_Utils::genUrl('switch', 'list')));
     $manualAdd = new OSS_Form_Element_Buttonlink('manualAdd');
     $manualAdd->setAttrib('href', OSS_Utils::genUrl('switch', 'add'))->setAttrib('label', _('Manual / Non-SNMP Add'));
     $this->addElement($manualAdd);
 }
コード例 #2
0
 public function init()
 {
     $this->setAttrib('id', 'customer_notes')->setAttrib('name', 'customer_notes')->setAction(OSS_Utils::genUrl('profile', 'update-customer-notes'));
     $notify = $this->createElement('radio', 'notify');
     $notify->addMultiOptions(['none' => 'Disable all email notifications', 'default' => 'Email me on changes to only watched customers and notes', 'all' => 'Email me on any change to any customer note'])->setValue('default');
     $this->addElement($notify);
     $this->addElement(OSS_Form::createSubmitElement('submit', _('Change Notification Preference')));
 }
コード例 #3
0
 public function init()
 {
     $this->setAttrib('id', 'change_password')->setAttrib('name', 'change_password')->setAction(OSS_Utils::genUrl('profile', 'change-password'));
     $this->addElement(OSS_Form_Auth::createPasswordElement('current_password')->setLabel(_('Current Password'))->setAttrib('class', 'span6'));
     $this->addElement(OSS_Form_Auth::createPasswordElement('new_password')->removeValidator('stringLength')->addValidator('stringLength', false, array(8, 255, 'UTF-8'))->setLabel(_('New Password'))->setAttrib('class', 'span6'));
     $this->addElement(OSS_Form_Auth::createPasswordConfirmElement('confirm_password', 'new_password')->setAttrib('class', 'span6'));
     $this->addElement(OSS_Form::createSubmitElement('submit', _('Change Password')));
 }
コード例 #4
0
ファイル: Image.php プロジェクト: opensolutions/oss-framework
 /**
  * The constructor generates a Captcha image.
  *
  * @param int $dotNoise  The dot noise level. Default: 100.
  * @param int $lineNoise The line noise level. Default: 5.
  * @param int $wordLen   The length of the Captcha word. Default: 6.
  * @param int $timeout   The timeout in seconds. Default: 1800.
  * @return OSS_Captcha_Image
  */
 public function __construct($dotNoise = 100, $lineNoise = 5, $wordLen = 6, $timeout = 1800)
 {
     parent::__construct();
     $captchaDir = OSS_Utils::getTempDir() . '/captchas';
     if (!file_exists($captchaDir)) {
         mkdir($captchaDir, 0777, true);
     }
     if (strpos(dirname(__FILE__), 'src/') === false) {
         $font = dirname(__FILE__) . '/../../data/font/freeserif.ttf';
     } else {
         $font = dirname(__FILE__) . '/../../../data/font/freeserif.ttf';
     }
     $this->setTimeout($timeout)->setWordLen($wordLen)->setHeight(80)->setFont($font)->setFontSize(40)->setImgDir($captchaDir)->setDotNoiseLevel($dotNoise)->setLineNoiseLevel($lineNoise);
     return $this;
 }
コード例 #5
0
/**
 * Function to generate a Zend Controller URL from Smarty templates.
 *
 * The URL is made up of parameters as supplied in the $params associative array.
 * 'module', 'controller' and 'action' are special parameters which indicate the module,
 * controller and action to call. Any other parameters are added as additional name / value
 * pairs.
 *
 * Calls OSS_Utils::genUrl()
 *
 * @category   OSS
 * @package    OSS_Smarty
 * @subpackage Functions
 *
 * @param array $params An array of the parameters to make up the URL
 * @param Smarty $smarty A reference to the Smarty object
 * @return string
 */
function smarty_function_genUrl($params, &$smarty)
{
    if (!isset($params['controller'])) {
        $params['controller'] = false;
    }
    if (!isset($params['action'])) {
        $params['action'] = false;
    }
    if (!isset($params['module']) || $params['module'] == 'default') {
        $params['module'] = false;
    }
    $p = $params;
    unset($p['controller']);
    unset($p['action']);
    unset($p['module']);
    return OSS_Utils::genUrl($params['controller'], $params['action'], $params['module'], $p);
}
コード例 #6
0
ファイル: Profile.php プロジェクト: E-Poludnie/IXP-Manager
 public function init()
 {
     $this->setDecorators([['ViewScript', ['viewScript' => 'profile/forms/profile.phtml']]]);
     $this->setAttrib('id', 'profile')->setAttrib('name', 'profile')->setAction(OSS_Utils::genUrl('profile', 'change-profile'));
     $name = $this->createElement('text', 'name');
     $name->addValidator('stringLength', false, array(1, 255, 'UTF-8'))->setRequired(true)->setLabel('Name')->setAttrib('class', 'span6')->addFilter('StringTrim')->addFilter('StripTags')->addFilter(new OSS_Filter_StripSlashes());
     $this->addElement($name);
     $position = $this->createElement('text', 'position');
     $position->addValidator('stringLength', false, array(1, 50, 'UTF-8'))->setRequired(true)->setLabel('Position')->setAttrib('class', 'span6')->addFilter('StripTags')->addFilter('StringTrim')->addFilter(new OSS_Filter_StripSlashes());
     $this->addElement($position);
     $email = OSS_Form_User::createEmailElement();
     $email->setAttrib('class', 'span9');
     $this->addElement($email);
     $mobile = IXP_Form_User::createMobileElement()->setAttrib('class', 'span6');
     $this->addElement($mobile);
     $phone = $this->createElement('text', 'phone');
     $phone->addValidator('stringLength', false, array(1, 32, 'UTF-8'))->setLabel(_('Phone'))->setAttrib('class', 'span6')->addFilter('StringTrim')->addFilter('StripTags')->addFilter(new OSS_Filter_StripSlashes());
     $this->addElement($phone);
     $this->addElement(OSS_Form_Auth::createPasswordElement('current_password')->setLabel(_('Current Password'))->setAttrib('class', 'span6'));
     $this->addElement(self::createSubmitElement('submit', _('Update')));
 }
コード例 #7
0
 /**
  * Converts seconds to "A hours B minutes C seconds" string, skipping the unnecessary parts,
  * like it won't return with "0 hours 0 minutes 34 seconds" but with "34 seconds".
  *
  * @param int $seconds
  * @return string
  */
 public static function secondsToTimeString($seconds)
 {
     $data = OSS_Utils::secondsToHMS($seconds);
     $retVal = '';
     if ($data['hours'] > 0) {
         $retVal .= "{$data['hours']} hour" . ($data['hours'] != 1 ? 's' : '');
     }
     if ($data['minutes'] > 0) {
         $retVal .= " {$data['minutes']} minute" . ($data['minutes'] != 1 ? 's' : '');
     }
     if ($data['seconds'] > 0) {
         $retVal .= " {$data['seconds']} second" . ($data['seconds'] != 1 ? 's' : '');
     }
     return trim($retVal);
 }
コード例 #8
0
 /**
  * Parse the XML response from Realex and update the transaction object
  *
  * This function:
  *
  *  - transforms the XML response to an array
  *  - validates the response hash
  *  - updates the authcode, pasref, state and response fields of the \Entities\RealexTransaction object
  *
  * @param string $xml The XML response from Realex for processing
  * @param \Entities\RealexTransaction $rtrans An instance of the \Entities\RealexTransaciton object
  * @return \Entities\ReleaxTransaction The updated $rtrans object for fluent interface
  * @throws OSS_PaymentProcessor_Realex_Receipt_Exception
  */
 private function _parseResponse($xml, $rtrans)
 {
     $resp = OSS_Array::objectToArray(OSS_Utils::parseXML($xml));
     $rtrans->setResult($this->_checkResponse($resp));
     if (isset($resp['authcode'])) {
         $rtrans->setAuthcode($resp['authcode']);
     }
     //if( isset( $resp['pasref'] ) )
     // $rtrans['pasref'] = $resp['pasref'];
     $rtrans->setState(\Entities\RealexTransaction::STATE_COMPLETE);
     $this->_log("[RTRANS: {$rtrans->getId()}] Realex::_parseResponse() - Realex result: {$rtrans->getResult()}");
     //FIXME: Barry
     if ($rtrans->isSuccessful() && !$this->_keep_request_data) {
         $rtrans->setRequest('');
     }
     $rtrans->setUpdated(new \DateTime());
     $this->getD2EM()->flush();
     //FIXME Transaction stats.
     //if( !CreditcardTransactionStatsTable::update( $cctrans['request_type'], $cctrans['result'], $cctrans['amount'] ) )
     //$this->_log( "CreditcardTrasactionStatTable::update() failed for [CCTRANS: {$cctrans['id']}].", OSS_Log::ALERT );
     if (in_array($rtrans->getRequestType(), array('receipt-in', 'payment-out')) && !$rtrans->isSuccessful()) {
         throw new OSS_PaymentProcessor_Realex_Receipt_Exception($rtrans, $resp['message']);
     }
     return $rtrans;
 }
コード例 #9
0
ファイル: Utils.php プロジェクト: opensolutions/oss-framework
 /**
  * Returns with the temporary directory set in the application.ini, or if it is not set, then with the result of sys_get_temp_dir().
  *
  * @todo: this method is rarely called, but a way to speed it up is to store the path in session, and then look for it when called
  *
  * @return string
  */
 public static function getTempDir()
 {
     $tempDir = OSS_Utils::getIniOption('temporary_directory');
     return $tempDir == '' ? sys_get_temp_dir() : $tempDir;
 }
コード例 #10
0
 /**
  *
  *
  */
 public function billingRegistrationAction()
 {
     $this->view->cust = $c = $this->_loadCustomer();
     $this->view->form = $form = new IXP_Form_Customer_BillingRegistration();
     $form->updateCancelLocation(OSS_Utils::genUrl('customer', 'overview', null, ['id' => $c->getId()]));
     if (!isset($this->_options['reseller']['no_billing_for_resold_customers']) || !$this->_options['reseller']['no_billing_for_resold_customers'] || !$this->resellerMode() || !$c->isResoldCustomer()) {
         $form->assignEntityToForm($c->getBillingDetails(), $this);
     }
     $old = clone $c->getBillingDetails();
     $form->assignEntityToForm($c->getRegistrationDetails(), $this);
     // Process a submitted form if it passes initial validation
     if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
         $form->assignFormToEntity($c->getBillingDetails(), $this, true);
         $form->assignFormToEntity($c->getRegistrationDetails(), $this, true);
         $this->getD2EM()->flush();
         if (isset($this->_options['billing_updates']['notify']) && !$c->getReseller()) {
             $this->view->oldDetails = $old;
             $this->view->customer = $c;
             $this->getMailer()->setFrom($this->_options['identity']['email'], $this->_options['identity']['name'])->setSubject($this->_options['identity']['sitename'] . ' - ' . _('Billing Details Change Notification'))->addTo($this->_options['billing_updates']['notify'], $this->_options['identity']['sitename'] . ' - Accounts')->setBodyHtml($this->view->render('customer/email/billing-details-changed.phtml'))->send();
             if ($this->getUser()->getPrivs() == \Entities\User::AUTH_SUPERUSER) {
                 $this->addMessage("Notification of updated billing details has been sent to " . $this->_options['billing_updates']['notify'], OSS_Message::INFO);
             }
         }
         $this->redirect('customer/overview/id/' . $c->getId() . '/tab/billing');
     }
 }
コード例 #11
0
 /**
  *
  * @param IXP_Form_Contact $form The form object
  * @param \Entities\Contact $object The Doctrine2 entity (being edited or blank for add)
  * @param bool $isEdit True of we are editing an object, false otherwise
  * @param array $options Options passed onto Zend_Form
  * @param string $cancelLocation Where to redirect to if 'Cancal' is clicked
  * @return void
  */
 protected function formPostProcess($form, $object, $isEdit, $options = null, $cancelLocation = null)
 {
     $this->view->groups = $this->getD2EM()->getRepository("\\Entities\\ContactGroup")->getGroupNamesTypeArray();
     $this->view->jsonGroups = json_encode($this->view->groups);
     // ROLE is treated as a special group and if it is not set, it will disable the contact role functionality
     if (!isset($this->_options['contact']['group']['types'][\Entities\ContactGroup::TYPE_ROLE])) {
         $form->removeElement('role');
     }
     // redirect back to whence we came on form submission
     if ($this->getParam("user", false)) {
         $form->getElement('login')->setValue(1);
         $form->setAction(OSS_Utils::genUrl('contact', $isEdit ? 'edit' : 'add', false, ['user' => true]));
     } else {
         if ($this->getParam("uid", false)) {
             $form->setAction(OSS_Utils::genUrl('contact', $isEdit ? 'edit' : 'add', false, ['uid' => $this->getParam("uid")]));
         }
     }
     if ($cid = $this->getParam('cid', false)) {
         $form->updateCancelLocation(OSS_Utils::genUrl('customer', 'overview', false, ['id' => $cid, 'tab' => $this->getParam('user', false) || $this->getParam('uid', false) ? 'users' : 'contacts']));
     }
     if ($isEdit) {
         $form->getElement('custid')->setValue($object->getCustomer()->getId());
         $this->view->contactGroups = $this->getD2R("\\Entities\\ContactGroup")->getGroupNamesTypeArray(false, $object->getId());
     } else {
         if ($this->getParam('custid', false) && ($cust = $this->getD2R('\\Entities\\Customer')->find($this->getParam('custid')))) {
             $form->getElement('custid')->setValue($cust->getId());
         }
     }
     if ($object->getUser()) {
         $form->getElement('login')->setValue(1);
         $form->getElement('username')->setValue($object->getUser()->getUsername());
         $form->getElement('password')->setAttrib('placeholder', 'Set to change password');
         $form->getElement('privs')->setValue($object->getUser()->getPrivs());
         $form->getElement('disabled')->setValue($object->getUser()->getDisabled());
     } else {
         $form->getElement('password')->setValue(OSS_String::random(12));
         $form->getElement('username')->addValidator('OSSDoctrine2Uniqueness', true, ['entity' => '\\Entities\\User', 'property' => 'username']);
     }
     switch ($this->getUser()->getPrivs()) {
         case \Entities\User::AUTH_SUPERUSER:
             $form->getElement('username')->removeValidator('stringLength');
             break;
         case \Entities\User::AUTH_CUSTADMIN:
             $form->removeElement('password');
             $form->removeElement('privs');
             $form->removeElement('custid');
             $form->removeElement('facilityaccess');
             $form->removeElement('mayauthorize');
             $form->removeElement('notes');
             if ($isEdit && $object->getUser()) {
                 $form->getElement('username')->setAttrib('readonly', 'readonly');
             }
             break;
         default:
             throw new OSS_Exception('Unhandled user type / security issues');
     }
 }
コード例 #12
0
ファイル: Auth.php プロジェクト: RavenB/OSS-Framework
 /**
  * Takes an id as a parameter, and prints the matching CAPTCHA image as a binary raw string to the output,
  * or prints nothing if no matching CAPTCHA found.
  */
 public function captchaImageAction()
 {
     $captchaId = preg_replace("/[^0-9a-z]+/u", '', strtolower(basename($this->_getParam('id'))));
     $captchaFile = OSS_Utils::getTempDir() . "/captchas/{$captchaId}.png";
     if (@file_exists($captchaFile)) {
         Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer');
         @ob_end_clean();
         header('Content-type: image/png');
         @readfile($captchaFile);
     } else {
         $this->_forward('error-404', 'error');
     }
 }
コード例 #13
0
 /**
  * @param IXP_Form_Interface_Physical $form The form object
  * @param \Entities\PhysicalInterface $object The Doctrine2 entity (being edited or blank for add)
  * @param bool $isEdit True of we are editing an object, false otherwise
  * @param array $options Options passed onto Zend_Form
  * @param string $cancelLocation Where to redirect to if 'Cancal' is clicked
  * @return void
  */
 protected function formPostProcess($form, $object, $isEdit, $options = null, $cancelLocation = null)
 {
     if ($isEdit) {
         if ($object->getRelatedInterface() && $object->getSwitchPort()->getType() == \Entities\SwitchPort::TYPE_FANOUT) {
             $object = $object->getRelatedInterface();
         }
         $form->enableFanoutPort($this->resellerMode() && $object->getVirtualInterface()->getCustomer()->isResoldCustomer());
         $form->getElement('switchid')->setValue($object->getSwitchPort()->getSwitcher()->getId());
         $form->getElement('switchportid')->setValue($object->getSwitchPort()->getId());
         $form->getElement('preselectSwitchPort')->setValue($object->getSwitchPort()->getId());
         $form->getElement('preselectPhysicalInterface')->setValue($object->getId());
         $form->getElement('virtualinterfaceid')->setValue($object->getVirtualInterface()->getId());
         if ($form->getElement('fanout')) {
             if ($object->getFanoutPhysicalInterface()) {
                 $form->getElement('fanout')->setValue(true);
                 $form->getElement('fn_switchid')->setValue($object->getFanoutPhysicalInterface()->getSwitchPort()->getSwitcher()->getId());
                 $form->getElement('fn_switchportid')->setValue($object->getFanoutPhysicalInterface()->getSwitchPort()->getId());
                 $form->getElement('fn_monitorindex')->setValue($object->getFanoutPhysicalInterface()->getMonitorindex());
                 $form->getElement('fn_preselectSwitchPort')->setValue($object->getFanoutPhysicalInterface()->getSwitchPort()->getId());
                 $form->getElement('fn_preselectPhysicalInterface')->setValue($object->getFanoutPhysicalInterface()->getId());
             } else {
                 $form->getElement('fn_monitorindex')->setValue($this->getD2EM()->getRepository('\\Entities\\PhysicalInterface')->getNextMonitorIndex($object->getVirtualInterface()->getCustomer()->getReseller()));
             }
         }
         if ($this->getParam('rtn', false) == 'pi') {
             $form->setAction(OSS_Utils::genUrl('physical-interface', 'edit', false, ['id' => $object->getId(), 'rtn' => 'pi']));
         } else {
             $form->getElement('cancel')->setAttrib('href', OSS_Utils::genUrl('virtual-interface', 'edit', false, ['id' => $object->getVirtualInterface()->getId()]));
         }
     } else {
         if ($this->getRequest()->isPost() && ($vintid = isset($_POST['virtualinterfaceid']) && $_POST['virtualinterfaceid'])) {
             $vint = $this->getD2EM()->getRepository('\\Entities\\VirtualInterface')->find($_POST['virtualinterfaceid']);
         } else {
             if (($vintid = $this->getRequest()->getParam('vintid')) !== null) {
                 $vint = $this->getD2EM()->getRepository('\\Entities\\VirtualInterface')->find($vintid);
             }
         }
         if (!isset($vint) || !$vint) {
             $this->addMessage('You need a containing virtual interface before you add a physical interface', OSS_Message::ERROR);
             $this->redirect('virtual-interface/add');
         }
         $form->enableFanoutPort($this->resellerMode() && $vint->getCustomer()->isResoldCustomer());
         $form->getElement('virtualinterfaceid')->setValue($vint->getId());
         $form->getElement('cancel')->setAttrib('href', OSS_Utils::genUrl('virtual-interface', 'edit', false, ['id' => $vint->getId()]));
         if (!$object->getMonitorindex()) {
             $form->getElement('monitorindex')->setValue($this->getD2EM()->getRepository('\\Entities\\PhysicalInterface')->getNextMonitorIndex($vint->getCustomer()));
         }
         if ($form->getElement('fanout')) {
             $form->getElement('fn_monitorindex')->setValue($this->getD2EM()->getRepository('\\Entities\\PhysicalInterface')->getNextMonitorIndex($vint->getCustomer()->getReseller()));
         }
     }
 }
コード例 #14
0
 /**
  * Add new switch by polling it via SNMP
  */
 public function addBySnmpAction()
 {
     $this->view->sw = $sw = new \Entities\Switcher();
     $this->view->f = $f = new IXP_Form_Switch_AddBySNMP();
     if ($this->getRequest()->isPost() && $f->isValid($_POST)) {
         do {
             // ensure provided name and hostname are not in use
             if ($this->getD2R('\\Entities\\Switcher')->findOneBy(['name' => $f->getValue('name')]) || $this->getD2R('\\Entities\\Switcher')->findOneBy(['hostname' => $f->getValue('hostname')])) {
                 $this->addMessage('A switch already exists with the given name / hostname', OSS_Message::ERROR);
                 break;
             }
             // can we talk to it by SNMP and discover some basic details?
             try {
                 $snmp = new \OSS_SNMP\SNMP($f->getValue('hostname'), $f->getValue('snmppasswd'));
                 $vendor = $snmp->getPlatform()->getVendor();
             } catch (\OSS_SNMP\Exception $e) {
                 $this->addMessage("Could not query {$f->getValue('hostname')} via SNMP.\n                        Consider using the <a href=\"" . OSS_Utils::genUrl('switch', 'add') . "\">the manual add method</a>.", OSS_Message::ERROR);
                 break;
             }
             if ($vendor == 'Unknown') {
                 $this->addMessage("Could not interpret switch system description string - most likely\n                            because no platform interpretor exists for it.<br/><br/>Please see\n                            <a href=\"https://github.com/opensolutions/OSS_SNMP/wiki/Device-Discovery\">this OSS_SNMP page</a>\n                            and consider adding one.<br /><br />\n                            Otherwise use the <a href=\"" . OSS_Utils::genUrl('switch', 'add') . "\">the manual add method</a>.", OSS_Message::ERROR);
                 break;
             }
             if (!($eVendor = $this->getD2R('\\Entities\\Vendor')->findOneBy(['name' => $vendor]))) {
                 $this->addMessage("No vendor defined for [{$vendor}]. Please\n                        <a href=\"" . OSS_Utils::genUrl('vendor', 'add') . "\">add one first</a>.", OSS_Message::ERROR);
                 break;
             }
             // now we have a switch with all the necessary details, add it:
             $s = new Switcher();
             $s->setCabinet($this->getD2R('\\Entities\\Cabinet')->find($f->getValue('cabinetid')));
             $s->setVendor($eVendor);
             $s->setName($f->getValue('name'));
             $s->setHostname($f->getValue('hostname'));
             $s->setIpv4addr($this->_resolve($s->getHostname(), DNS_A));
             $s->setIpv6addr($this->_resolve($s->getHostname(), DNS_AAAA));
             $s->setSnmppasswd($f->getValue('snmppasswd'));
             $s->setInfrastructure($this->getD2R('\\Entities\\Infrastructure')->find($f->getValue('infrastructure')));
             $s->setSwitchtype($f->getValue('switchtype'));
             $s->setModel($snmp->getPlatform()->getModel());
             $s->setActive(true);
             $s->setOs($snmp->getPlatform()->getOs());
             $s->setOsDate($snmp->getPlatform()->getOsDate());
             $s->setOsVersion($snmp->getPlatform()->getOsVersion());
             $s->setLastPolled(new DateTime());
             $this->getD2EM()->persist($s);
             $this->getD2EM()->flush();
             // clear the cache
             $this->getD2R('\\Entities\\Switcher')->clearCache();
             $this->addMessage("Switch polled and added successfully! Please configure the ports found below.", OSS_Message::SUCCESS);
             $this->redirect('switch-port/snmp-poll/switch/' . $s->getId());
         } while (false);
     }
     $this->_display('add-by-snmp.phtml');
 }
コード例 #15
0
 /**
  * Function which can be over-ridden to perform any pre-deletion tasks
  *
  * You can stop the deletion by returning false but you should also add a
  * message to explain why.
  *
  * @param object $object The Doctrine2 entity to delete
  * @return bool Return false to stop / cancel the deletion
  */
 protected function preDelete($object)
 {
     if ($object->getPhysicalInterface()) {
         $c = $object->getPhysicalInterface()->getVirtualInterface()->getCustomer();
         $this->addMessage("Could not delete switch port {$object->getName()} as it is assigned to a physical interface for <a href=\"" . OSS_Utils::genUrl('customer', 'overview', false, ['tab' => 'ports', 'id' => $c->getId()]) . "\">{$c->getName()}</a>.", OSS_Message::ERROR);
         return false;
     }
     return true;
 }
コード例 #16
0
/**
 * Function to to calculate diffrence between two days
 *
 * parameters:
 * 'date1' string, default 'Y-m-d'
 * 'date2' string, default 'Y-m-d'
 *
 * @category   OSS
 * @package    OSS_Smarty
 * @subpackage Functions
 *
 * @param array $params 
 * @param Smarty $smarty A reference to the Smarty template object
 * @return string
 */
function smarty_function_dateDiffDays($params, &$smarty)
{
    return OSS_Utils::dateDiffDays($params['date1'], $params['date2']);
}
コード例 #17
0
 /**
  * Function which can be over-ridden to perform any pre-deletion tasks
  *
  * You can stop the deletion by returning false but you should also add a
  * message to explain why.
  *
  * @param \Entities\IPv4Address $object The Doctrine2 entity to delete
  * @return bool Return false to stop / cancel the deletion
  */
 protected function preDelete($object)
 {
     if ($object->getVlanInterface()) {
         $this->addMessage('This IP address is assigned to a VLAN interface. Please remove <a href="' . OSS_Utils::genUrl('vlan-interface', 'edit', false, ['id' => $object->getVlanInterface()->getId()]) . '">this assignment</a> before deleting the address.', OSS_Message::ERROR);
         return false;
     }
     return true;
 }
コード例 #18
0
ファイル: Auth.php プロジェクト: opensolutions/oss-framework
 /**
  * A utility function for creating a standard 'return to login' button link.
  *
  * @param string $name The element name
  * @return OSS_Form_Element_Buttonlink - The button link element
  */
 public static function createReturnToLoginElement($name = 'return_to_login')
 {
     $fpw = new OSS_Form_Element_Buttonlink($name);
     return $fpw->setAttrib('href', OSS_Utils::genUrl('auth', 'login'))->setAttrib('label', _('Return to Login'));
 }
コード例 #19
0
 public function addWizardAction()
 {
     $this->view->form = $form = new IXP_Form_Interface_AddWizard();
     if ($this->resellerMode()) {
         $this->view->resoldCusts = json_encode($this->getD2R("\\Entities\\Customer")->getResoldCustomerNames());
     }
     $form->enableFanoutPort($this->resellerMode());
     // Process a submitted form if it passes initial validation
     if ($this->getRequest()->isPost()) {
         // make sure we have a custid
         if (!isset($_POST['custid']) && $this->getParam('custid', false)) {
             $_POST['custid'] = $this->getParam('custid');
         }
         if ($form->isValid($_POST)) {
             // check customer information
             if (!($cust = $this->getD2EM()->getRepository('\\Entities\\Customer')->find($form->getValue('custid')))) {
                 $form->getElement('custid')->addError('Invalid customer');
             } else {
                 $vi = new \Entities\VirtualInterface();
                 $form->assignFormToEntity($vi, $this, false);
                 $vi->setCustomer($cust);
                 $this->getD2EM()->persist($vi);
                 $pi = new \Entities\PhysicalInterface();
                 $form->assignFormToEntity($pi, $this, false);
                 $pi->setVirtualInterface($vi);
                 $sp = $this->getD2R('\\Entities\\SwitchPort')->find($form->getValue('switchportid'));
                 $sp->setType(\Entities\SwitchPort::TYPE_PEERING);
                 $pi->setSwitchPort($sp);
                 $pi->setMonitorindex($this->getD2EM()->getRepository('\\Entities\\PhysicalInterface')->getNextMonitorIndex($cust));
                 $this->getD2EM()->persist($pi);
                 if ($form->getElement('fanout')) {
                     if (!$this->processFanoutPhysicalInterface($form, $pi, $vi)) {
                         return false;
                     }
                     if ($pi->getRelatedInterface()) {
                         $pi->getRelatedInterface()->setSpeed($form->getValue("speed"));
                         $pi->getRelatedInterface()->setStatus($form->getValue("status"));
                         $pi->getRelatedInterface()->setDuplex($form->getValue("duplex"));
                     }
                 }
                 $vli = new \Entities\VlanInterface();
                 $form->assignFormToEntity($vli, $this, false);
                 $vli->setVlan($this->getD2EM()->getRepository('\\Entities\\Vlan')->find($form->getElement('vlanid')->getValue()));
                 if (!$this->setIp($form, $vi, $vli, false) || !$this->setIp($form, $vi, $vli, true)) {
                     return false;
                 }
                 $vli->setVirtualInterface($vi);
                 $this->getD2EM()->persist($vli);
                 $this->getD2EM()->flush();
                 $this->getLogger()->info('New virtual, physical and VLAN interface created for ' . $cust->getName());
                 $this->addMessage("New interface created!", OSS_Message::SUCCESS);
                 $this->redirect('customer/overview/tab/ports/id/' . $cust->getId());
             }
         }
     }
     if (!isset($cust) && ($cid = $this->getParam('custid', false))) {
         $cust = $this->getD2EM()->getRepository('\\Entities\\Customer')->find($cid);
     }
     if (!$this->getRequest()->isPost()) {
         if (isset($cust)) {
             $form->getElement('custid')->setValue($cust->getId());
             $form->getElement('maxbgpprefix')->setValue($cust->getMaxprefixes());
         }
     }
     if ($this->getParam('rtn', false) == 'ov') {
         $form->getElement('custid')->setAttrib('disabled', 'disabled');
         $form->getElement('cancel')->setAttrib('href', OSS_Utils::genUrl('customer', 'view', false, ['id' => $this->getParam('custid')]));
     } else {
         $form->getElement('cancel')->setAttrib('href', OSS_Utils::genUrl('virtual-interface', 'list'));
     }
 }
コード例 #20
0
 protected function getBillingDetailsForm()
 {
     $form = new IXP_Form_Customer_BillingDetails();
     if (!isset($this->view->billingDetails)) {
         $this->view->billingDetails = $form;
     }
     $form->assignEntityToForm($this->getCustomer()->getBillingDetails(), $this, true);
     $form->setAction(OSS_Utils::genUrl('dashboard', 'update-billing'));
     return $form;
 }
コード例 #21
0
 /**
  * Get the `Zend_Form` object for adding / editing actions with some processing.
  *
  * You should not override this but rather the `formPostProcess()` function to
  * make changes immediately after the form object has been instantiated.
  *
  * @param bool $isEdit True of we are editing an object, false otherwise
  * @param object $object The Doctrine2 entity (being edited or blank for add)
  * @param array $options Options passed onto Zend_Form
  * @param string $cancelLocation Where to redirect to if 'Cancal' is clicked
  * @return Zend_Form
  */
 protected function getForm($isEdit, $object, $options = null, $cancelLocation = null)
 {
     $options['cancelLocation'] = $cancelLocation === null ? $this->_getBaseUrl() . '/index' : $cancelLocation;
     $options['isEdit'] = $isEdit;
     $formName = $this->feGetParam('form');
     $form = new $formName($options);
     $form->setAction(OSS_Utils::genUrl($this->getRequest()->getControllerName(), $isEdit ? 'edit' : 'add', $this->getRequest()->getModuleName() == "index" ? false : $this->getRequest()->getModuleName(), ['id' => $object->getId()]));
     $this->formPostProcess($form, $object, $isEdit, $options, $cancelLocation);
     return $form;
 }
コード例 #22
0
 /**
  * @param IXP_Form_Interface_Vlan $form The form object
  * @param \Entities\VlanInterface $object The Doctrine2 entity (being edited or blank for add)
  * @param bool $isEdit True of we are editing an object, false otherwise
  * @param array $options Options passed onto Zend_Form
  * @param string $cancelLocation Where to redirect to if 'Cancal' is clicked
  * @return void
  */
 protected function formPostProcess($form, $object, $isEdit, $options = null, $cancelLocation = null)
 {
     if ($isEdit) {
         $form->getElement('virtualinterfaceid')->setValue($object->getVirtualInterface()->getId());
         $form->getElement('preselectCustomer')->setValue($object->getVirtualInterface()->getCustomer()->getId());
         $form->getElement('vlanid')->setValue($object->getVlan()->getId());
         $form->getElement('preselectIPv4Address')->setValue($object->getIPv4Address() ? $object->getIPv4Address()->getAddress() : null);
         $form->getElement('preselectIPv6Address')->setValue($object->getIPv6Address() ? $object->getIPv6Address()->getAddress() : null);
         $form->getElement('preselectVlanInterface')->setValue($object->getId());
         if ($this->getParam('rtn', false) == 'vli') {
             $form->setAction(OSS_Utils::genUrl('vlan-interface', 'edit', false, ['id' => $object->getId(), 'rtn' => 'vli']));
         } else {
             $form->getElement('cancel')->setAttrib('href', OSS_Utils::genUrl('virtual-interface', 'edit', false, ['id' => $object->getVirtualInterface()->getId()]));
         }
     } else {
         if ($this->getRequest()->isPost() && ($vintid = isset($_POST['virtualinterfaceid']) && $_POST['virtualinterfaceid'])) {
             $vint = $this->getD2EM()->getRepository('\\Entities\\VirtualInterface')->find($_POST['virtualinterfaceid']);
         } else {
             if (($vintid = $this->getRequest()->getParam('vintid')) !== null) {
                 $vint = $this->getD2EM()->getRepository('\\Entities\\VirtualInterface')->find($vintid);
             }
         }
         if (!isset($vint) || !$vint) {
             $this->addMessage('You need a containing virtual interface before you add a VLAN interface', OSS_Message::ERROR);
             $this->redirect('virtual-interface/add');
         }
         // make BGP MD5 easy
         $form->getElement('ipv4bgpmd5secret')->setValue(OSS_String::random());
         $form->getElement('ipv6bgpmd5secret')->setValue($form->getElement('ipv4bgpmd5secret')->getValue());
         $form->getElement('maxbgpprefix')->setValue($vint->getCustomer()->getMaxprefixes());
         $form->getElement('virtualinterfaceid')->setValue($vint->getId());
         $form->getElement('preselectCustomer')->setValue($vint->getCustomer()->getId());
         $form->getElement('cancel')->setAttrib('href', OSS_Utils::genUrl('virtual-interface', 'edit', false, ['id' => $vint->getId()]));
     }
 }