function execute( $par ) { global $wgOpenStackManagerNovaAdminKeys; if ( !$this->getUser()->isLoggedIn() ) { $this->notLoggedIn(); return; } $this->userLDAP = new OpenStackNovaUser(); if ( ! $this->userLDAP->exists() ) { $this->noCredentials(); return; } $project = $this->getRequest()->getVal( 'project' ); $userCredentials = $this->userLDAP->getCredentials(); $this->userNova = new OpenStackNovaController( $userCredentials, $project ); $adminCredentials = $wgOpenStackManagerNovaAdminKeys; $this->adminNova = new OpenStackNovaController( $adminCredentials ); $action = $this->getRequest()->getVal( 'action' ); if ( $action == "create" ) { if ( ! $this->userLDAP->inProject( $project ) ) { $this->notInProject(); return; } $this->createInstance(); } elseif ( $action == "delete" ) { if ( ! $this->userLDAP->inProject( $project ) ) { $this->notInProject(); return; } $this->deleteInstance(); } elseif ( $action == "configure" ) { if ( ! $this->userLDAP->inProject( $project ) ) { $this->notInProject(); return; } $this->configureInstance(); } elseif ( $action == "reboot" ) { if ( ! $this->userLDAP->inProject( $project ) ) { $this->notInProject(); return; } $this->rebootInstance(); } elseif ( $action == "consoleoutput" ) { if ( ! $this->userLDAP->inProject( $project ) ) { $this->notInProject(); return; } $this->getConsoleOutput(); } else { $this->listInstances(); } }
/** * @return bool */ function removeHost() { $this->setHeaders(); $this->getOutput()->setPagetitle(wfMsg('openstackmanager-removehost')); $project = $this->getRequest()->getText('project'); if (!$this->userLDAP->inRole('netadmin', $project)) { $this->notInRole('netadmin'); return false; } $userCredentials = $this->userLDAP->getCredentials(); $this->userNova = new OpenStackNovaController($userCredentials, $project); $ip = $this->getRequest()->getText('ip'); $domain = $this->getRequest()->getText('domain'); $hostname = $this->getRequest()->getText('hostname'); if (!$this->getRequest()->wasPosted()) { $this->getOutput()->addWikiMsg('openstackmanager-removehost-confirm', $hostname, $ip); } $addressInfo = array(); $addressInfo['project'] = array('type' => 'hidden', 'default' => $project, 'name' => 'project'); $addressInfo['ip'] = array('type' => 'hidden', 'default' => $ip, 'name' => 'ip'); $addressInfo['domain'] = array('type' => 'hidden', 'default' => $domain, 'name' => 'domain'); $addressInfo['hostname'] = array('type' => 'hidden', 'default' => $hostname, 'name' => 'hostname'); $addressInfo['action'] = array('type' => 'hidden', 'default' => 'removehost', 'name' => 'action'); $addressForm = new SpecialNovaAddressForm($addressInfo, 'openstackmanager-novaaddress'); $addressForm->setTitle(SpecialPage::getTitleFor('NovaAddress')); $addressForm->setSubmitID('novaaddress-form-removehostsubmit'); $addressForm->setSubmitCallback(array($this, 'tryRemoveHostSubmit')); $addressForm->setSubmitText('confirm'); $addressForm->show(); return true; }
/** * @param $formData * @param string $entryPoint * @return bool */ function tryRemoveRuleSubmit( $formData, $entryPoint = 'internal' ) { $project = $formData['project']; $fromport = $formData['fromport']; $toport = $formData['toport']; $protocol = $formData['protocol']; if ( isset( $formData['ranges'] ) ) { $ranges = explode( ',', $formData['ranges'] ); } else { $ranges = array(); } $groups = array(); if ( isset( $formData['groups'] ) ) { $rawgroups = explode( ',', $formData['groups'] ); foreach ( $rawgroups as $rawgroup ) { $rawgroup = explode( ':', $rawgroup ); $groups[] = array( 'groupname' => $rawgroup[0], 'project' => $rawgroup[1] ); } } $userCredentials = $this->userLDAP->getCredentials(); $this->userNova = new OpenStackNovaController( $userCredentials, $project ); $securitygroup = $this->adminNova->getSecurityGroup( $formData['groupname'], $project ); if ( ! $securitygroup ) { $this->getOutput()->addWikiMsg( 'openstackmanager-nonexistantsecuritygroup' ); return false; } $groupname = $securitygroup->getGroupName(); $success = $this->userNova->removeSecurityGroupRule( $groupname, $fromport, $toport, $protocol, $ranges, $groups ); if ( $success ) { # TODO: Ensure group isn't being used $this->getOutput()->addWikiMsg( 'openstackmanager-removedrule' ); } else { $this->getOutput()->addWikiMsg( 'openstackmanager-removerulefailed' ); } $out = '<br />'; $out .= Linker::link( $this->getTitle(), wfMsgHtml( 'openstackmanager-backsecuritygrouplist' ) ); $this->getOutput()->addHTML( $out ); return true; }
/** * @return void */ function listKeys() { global $wgOpenStackManagerNovaKeypairStorage; $this->setHeaders(); $this->getOutput()->setPagetitle(wfMsg('openstackmanager-keylist')); $this->getOutput()->addModuleStyles('ext.openstack'); $keyInfo = array(); if ($wgOpenStackManagerNovaKeypairStorage == 'nova') { $projects = $this->userLDAP->getProjects(); $keyInfo['keyname'] = array('type' => 'text', 'label-message' => 'openstackmanager-novakeyname', 'default' => '', 'section' => 'key', 'name' => 'keyname'); $project_keys = array(); foreach ($projects as $project) { $project_keys["{$project}"] = $project; } $keyInfo['project'] = array('type' => 'select', 'options' => $project_keys, 'label-message' => 'openstackmanager-project', 'name' => 'project'); } $keyInfo['key'] = array('type' => 'textarea', 'section' => 'key', 'default' => '', 'label-message' => 'openstackmanager-novapublickey', 'name' => 'key'); $keyForm = new SpecialNovaKeyForm($keyInfo, 'openstackmanager-novakey'); $keyForm->setTitle(SpecialPage::getTitleFor('NovaKey')); $keyForm->setSubmitID('novakey-form-createkeysubmit'); $keyForm->setSubmitCallback(array($this, 'tryImportSubmit')); $keyForm->show(); $out = ''; if ($wgOpenStackManagerNovaKeypairStorage == 'nova') { foreach ($projects as $project) { $userCredentials = $this->userLDAP->getCredentials(); $this->userNova = new OpenStackNovaController($userCredentials, $project); $keypairs = $this->userNova->getKeypairs(); if (!$keypairs) { continue; } $out .= Html::element('h2', array(), $project); $projectOut = Html::element('th', array(), wfMsg('openstackmanager-name')); $projectOut .= Html::element('th', array(), wfMsg('openstackmanager-fingerprint')); foreach ($keypairs as $keypair) { $keyOut = Html::element('td', array('class' => 'Nova_col'), $keypair->getKeyName()); $keyOut .= Html::element('td', array(), $keypair->getKeyFingerprint()); $projectOut .= Html::rawElement('tr', array(), $keyOut); } $out .= Html::rawElement('table', array('id' => 'novakeylist', 'class' => 'wikitable sortable collapsible'), $projectOut); } } elseif ($wgOpenStackManagerNovaKeypairStorage == 'ldap') { $keypairs = $this->userLDAP->getKeypairs(); $keysOut = ''; $keysOut .= Html::element('th', array(), wfMsg('openstackmanager-keys')); $keysOut .= Html::element('th', array(), wfMsg('openstackmanager-actions')); foreach ($keypairs as $hash => $key) { $keyOut = Html::element('td', array('class' => 'Nova_col'), $key); $msg = wfMsgHtml('openstackmanager-delete'); $link = Linker::link($this->getTitle(), $msg, array(), array('action' => 'delete', 'hash' => $hash)); $action = Html::rawElement('li', array(), $link); $action = Html::rawElement('ul', array(), $action); $keyOut .= Html::rawElement('td', array(), $action); $keysOut .= Html::rawElement('tr', array(), $keyOut); } $out .= Html::rawElement('table', array('id' => 'novakeylist', 'class' => 'wikitable'), $keysOut); } else { $this->getOutput()->addWikiMsg('openstackmanager-invalidkeypair'); } $this->getOutput()->addHTML($out); }