/**
  * @return void
  */
 function listDomains()
 {
     $this->setHeaders();
     $this->getOutput()->setPagetitle($this->msg('openstackmanager-domainlist'));
     $this->getOutput()->addModuleStyles('ext.openstack');
     $domainInfo = array();
     $domainInfo['domainname'] = array('type' => 'text', 'label-message' => 'openstackmanager-domainname', 'default' => '', 'section' => 'domain', 'name' => 'domainname');
     $domainInfo['fqdn'] = array('type' => 'text', 'label-message' => 'openstackmanager-fqdn', 'default' => '', 'section' => 'domain', 'name' => 'fqdn');
     $domainInfo['location'] = array('type' => 'text', 'label-message' => 'openstackmanager-location', 'default' => '', 'section' => 'domain', 'help-message' => 'openstackmanager-location-help', 'name' => 'location');
     $domainInfo['action'] = array('type' => 'hidden', 'default' => 'create', 'name' => 'action');
     $domainForm = new HTMLForm($domainInfo, $this->getContext(), 'openstackmanager-novadomain');
     $domainForm->setSubmitID('novadomain-form-createdomainsubmit');
     $domainForm->setSubmitCallback(array($this, 'tryCreateSubmit'));
     $domainForm->show();
     $headers = array('openstackmanager-domainname', 'openstackmanager-fqdn', 'openstackmanager-location', 'openstackmanager-actions');
     $domains = OpenStackNovaDomain::getAllDomains();
     $domainRows = array();
     foreach ($domains as $domain) {
         $domainRow = array();
         $domainName = $domain->getDomainName();
         $this->pushResourceColumn($domainRow, $domainName);
         $this->pushResourceColumn($domainRow, $domain->getFullyQualifiedDomainName());
         $this->pushResourceColumn($domainRow, $domain->getLocation());
         $this->pushRawResourceColumn($domainRow, $this->createActionLink('openstackmanager-delete', array('action' => 'delete', 'domainname' => $domainName)));
         $domainRows[] = $domainRow;
     }
     if ($domainRows) {
         $out = $this->createResourceTable($headers, $domainRows);
     } else {
         $out = '';
     }
     $this->getOutput()->addHTML($out);
 }
 /**
  * @return bool
  */
 function configureProject()
 {
     global $wgOpenStackManagerServiceGroupPrefix;
     $this->setHeaders();
     $projectName = $this->getRequest()->getText('projectname');
     $this->getOutput()->setPagetitle($this->msg('openstackmanager-configureproject', $projectName));
     if (!$this->userCanExecute($this->getUser()) && !$this->userLDAP->inRole('projectadmin', $projectName)) {
         $this->notInRole('projectadmin', $projectName);
         return false;
     }
     $project = OpenStackNovaProject::getProjectByName($projectName);
     $volumes = $project->getVolumeSettings();
     $defaultHomedirs = in_array("home", $volumes);
     $defaultProject = in_array("project", $volumes);
     $homePattern = $project->getServiceGroupHomedirPattern();
     $formInfo = array();
     $formInfo['homedirs'] = array('type' => 'check', 'label-message' => 'openstackmanager-configureproject-sharedhomedirs', 'default' => $defaultHomedirs, 'section' => 'volume', 'name' => 'sharedhomedirs');
     $formInfo['storage'] = array('type' => 'check', 'label-message' => 'openstackmanager-configureproject-sharedstorage', 'default' => $defaultProject, 'section' => 'volume', 'name' => 'sharedstorage');
     $formInfo['serviceuserhome'] = array('type' => 'text', 'label-message' => 'openstackmanager-configureproject-serviceuserhome', 'default' => $homePattern, 'section' => 'servicegroup', 'name' => 'serviceuserhome');
     $msg = $this->msg('openstackmanager-configureproject-serviceuserinfo', $wgOpenStackManagerServiceGroupPrefix);
     $formInfo['serviceuserhomeinfo'] = array('type' => 'info', 'section' => 'servicegroup', 'label' => $msg);
     $formInfo['action'] = array('type' => 'hidden', 'default' => 'configureproject', 'name' => 'action');
     $formInfo['projectname'] = array('type' => 'hidden', 'default' => $projectName, 'name' => 'projectname');
     $projectForm = new HTMLForm($formInfo, $this->getContext(), 'openstackmanager-configureproject');
     $projectForm->setSubmitID('novaproject-form-configuresubmit');
     $projectForm->setSubmitCallback(array($this, 'tryConfigureProjectSubmit'));
     $projectForm->show();
     return true;
 }
 /**
  * @return bool
  */
 function removeRule()
 {
     $this->setHeaders();
     $this->getOutput()->setPagetitle($this->msg('openstackmanager-removerule'));
     $project = $this->getRequest()->getText('project');
     $region = $this->getRequest()->getText('region');
     if (!$this->userLDAP->inRole('projectadmin', $project)) {
         $this->notInRole('projectadmin', $project);
         return false;
     }
     $groupid = $this->getRequest()->getText('groupid');
     $ruleid = $this->getRequest()->getText('ruleid');
     if (!$this->getRequest()->wasPosted()) {
         $securitygroup = $this->userNova->getSecurityGroup($groupid);
         if ($securitygroup) {
             $securitygroupname = $securitygroup->getGroupName();
             $this->getOutput()->addWikiMsg('openstackmanager-removerule-confirm', $securitygroupname);
         } else {
             $this->getOutput()->addWikiMsg('openstackmanager-nonexistantsecuritygroup');
             return false;
         }
     }
     $securityGroupInfo = array();
     $securityGroupInfo['groupid'] = array('type' => 'hidden', 'default' => $groupid, 'name' => 'groupid');
     $securityGroupInfo['ruleid'] = array('type' => 'hidden', 'default' => $ruleid, 'name' => 'ruleid');
     $securityGroupInfo['project'] = array('type' => 'hidden', 'default' => $project, 'name' => 'project');
     $securityGroupInfo['region'] = array('type' => 'hidden', 'default' => $region, 'name' => 'region');
     $securityGroupInfo['action'] = array('type' => 'hidden', 'default' => 'removerule', 'name' => 'action');
     $securityGroupForm = new HTMLForm($securityGroupInfo, $this->getContext(), 'openstackmanager-novasecuritygroup');
     $securityGroupForm->setSubmitID('novainstance-form-removerulesubmit');
     $securityGroupForm->setSubmitCallback(array($this, 'tryRemoveRuleSubmit'));
     $securityGroupForm->show();
     return true;
 }
 /**
  * Handle ?action=reboot
  * @return bool
  */
 function rebootInstance()
 {
     $this->setHeaders();
     $project = $this->getRequest()->getText('project');
     $region = $this->getRequest()->getText('region');
     if (!$this->userLDAP->inRole('projectadmin', $project)) {
         $this->notInRole('projectadmin', $project);
         return false;
     }
     $instanceosid = $this->getRequest()->getText('instanceid');
     if (!$this->getRequest()->wasPosted()) {
         # @todo memcache this instanceid lookup
         $instance = $this->userNova->getInstance($instanceosid);
         if (!$instance) {
             $this->getOutput()->addWikiMsg('openstackmanager-nonexistanthost');
             return false;
         }
         $this->getOutput()->addWikiMsg('openstackmanager-rebootinstancequestion', $instance->getInstanceId());
         $instanceid = $instance->getInstanceId();
         $instancename = $instance->getInstanceName();
         $this->getOutput()->setPagetitle($this->msg('openstackmanager-rebootinstancewithname', $instanceid, $instancename));
     } else {
         $this->getOutput()->setPagetitle($this->msg('openstackmanager-rebootinstance'));
     }
     $instanceInfo = array();
     $instanceInfo['instanceid'] = array('type' => 'hidden', 'default' => $instanceosid, 'name' => 'instanceid');
     $instanceInfo['project'] = array('type' => 'hidden', 'default' => $project, 'name' => 'project');
     $instanceInfo['region'] = array('type' => 'hidden', 'default' => $region, 'name' => 'region');
     $instanceInfo['action'] = array('type' => 'hidden', 'default' => 'reboot', 'name' => 'action');
     $instanceForm = new HTMLForm($instanceInfo, $this->getContext(), 'openstackmanager-novainstance');
     $instanceForm->setSubmitID('novainstance-form-deleteinstancesubmit');
     $instanceForm->setSubmitCallback(array($this, 'tryRebootSubmit'));
     $instanceForm->show();
     return true;
 }
 /**
  * @return bool
  */
 function modifyPuppetGroup()
 {
     $this->setHeaders();
     $this->getOutput()->setPagetitle($this->msg('openstackmanager-modifypuppetgroup'));
     $puppetGroupId = $this->getRequest()->getInt('puppetgroupid');
     $group = OpenStackNovaPuppetGroup::newFromId($puppetGroupId);
     if (!$group) {
         $this->getOutput()->addWikiMsg('openstackmanager-nonexistentresource');
         return false;
     }
     $puppetGroupName = $group->getName();
     $project = $group->getProject();
     if ($project) {
         // Project specific
         if (!$this->userLDAP->inRole('projectadmin', $project)) {
             $this->notInRole('projectadmin', $project);
             return false;
         }
     } else {
         // Global project - requires manageglobalpuppet
         if (!$this->userCanExecute($this->getUser())) {
             $this->displayRestrictionError();
             return false;
         }
     }
     $puppetGroupInfo = array();
     $puppetGroupInfo['puppetgroupid'] = array('type' => 'hidden', 'default' => $puppetGroupId, 'name' => 'puppetgroupid');
     $puppetGroupInfo['puppetgroupname'] = array('type' => 'hidden', 'default' => $puppetGroupName, 'name' => 'puppetgroupname');
     $puppetGroupInfo['action'] = array('type' => 'hidden', 'default' => 'modify', 'name' => 'action');
     $puppetGroupForm = new HTMLForm($puppetGroupInfo, $this->getContext(), 'openstackmanager-novapuppetgroup');
     $puppetGroupForm->setSubmitID('novapuppetgroup-form-modifypuppetgroupsubmit');
     $puppetGroupForm->setSubmitCallback(array($this, 'tryModifyGroupSubmit'));
     $puppetGroupForm->show();
     return true;
 }
 /**
  * @return bool
  */
 function deleteProxy()
 {
     $this->setHeaders();
     $this->getOutput()->setPagetitle($this->msg('openstackmanager-deleteproxy'));
     if (!$this->userLDAP->inRole('projectadmin', $this->projectName)) {
         $this->notInRole('projectadmin', $this->projectName);
         return false;
     }
     $proxyfqdn = $this->getRequest()->getText('proxyfqdn');
     $region = $this->getRequest()->getText('region');
     if (!$this->getRequest()->wasPosted()) {
         $this->getOutput()->addWikiMsg('openstackmanager-deleteproxy-confirm', $proxyfqdn);
     }
     $proxyInfo = array();
     $proxyInfo['proxyfqdn'] = array('type' => 'hidden', 'default' => $proxyfqdn, 'name' => 'proxyfqdn');
     $proxyInfo['project'] = array('type' => 'hidden', 'default' => $this->projectName, 'name' => 'project');
     $proxyInfo['action'] = array('type' => 'hidden', 'default' => 'delete', 'name' => 'action');
     $proxyInfo['region'] = array('type' => 'hidden', 'default' => $region, 'name' => 'region');
     $proxyForm = new HTMLForm($proxyInfo, $this->getContext(), 'openstackmanager-novaproxy');
     $proxyForm->setSubmitID('novaproxy-form-deleteproxysubmit');
     $proxyForm->setSubmitCallback(array($this, 'tryDeleteSubmit'));
     $proxyForm->show();
     return true;
 }
 function addKey()
 {
     global $wgOpenStackManagerNovaKeypairStorage;
     $this->setHeaders();
     $this->getOutput()->setPagetitle($this->msg('openstackmanager-addkey'));
     $returnto = $this->getRequest()->getVal('returnto');
     $keyInfo = array();
     if ($wgOpenStackManagerNovaKeypairStorage === 'nova') {
         $projects = $this->userLDAP->getProjects();
         $keyInfo['keyname'] = array('type' => 'text', 'label-message' => 'openstackmanager-novakeyname', 'default' => '', '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', 'default' => '', 'label-message' => 'openstackmanager-novapublickey', 'name' => 'key');
     $keyInfo['action'] = array('type' => 'hidden', 'default' => 'add', 'name' => 'action');
     $keyInfo['returnto'] = array('type' => 'hidden', 'default' => $returnto, 'name' => 'returnto');
     $keyForm = new HTMLForm($keyInfo, $this->getContext(), 'openstackmanager-novakey');
     $keyForm->setSubmitID('novakey-form-createkeysubmit');
     $keyForm->setSubmitCallback(array($this, 'tryImportSubmit'));
     $keyForm->show();
 }
 function showProjectFilter($projects)
 {
     if ($this->getRequest()->wasPosted() && $this->getRequest()->getVal('action') !== 'setprojectfilter') {
         return null;
     }
     $showmsg = $this->getRequest()->getText('showmsg');
     if ($showmsg === "setfilter") {
         $this->getOutput()->addWikiMsg('openstackmanager-setprojects');
     }
     $currentProjects = $this->getProjectFilter();
     $project_keys = array();
     $defaults = array();
     foreach ($projects as $project) {
         $projectName = $project->getProjectName();
         $project_keys[$projectName] = $projectName;
         if (in_array($projectName, $currentProjects)) {
             $defaults[$projectName] = $projectName;
         }
     }
     $projectFilter = array();
     $projectFilter['projects'] = array('type' => 'multiselect', 'label-message' => 'openstackmanager-projects', 'section' => 'projectfilter', 'options' => $project_keys, 'default' => $defaults, 'cssclass' => 'mw-chosen', 'name' => 'projects');
     $projectFilter['action'] = array('type' => 'hidden', 'default' => 'setprojectfilter', 'name' => 'action');
     $projectFilterForm = new HTMLForm($projectFilter, $this->getContext(), 'openstackmanager-novaprojectfilter');
     $projectFilterForm->setSubmitID('novaproject-form-setprojectfiltersubmit');
     $projectFilterForm->setSubmitCallback(array($this, 'trySetProjectFilter'));
     $projectFilterForm->setSubmitTextMsg('openstackmanager-projectfiltersubmit');
     $projectFilterForm->show();
 }
 /**
  * @return bool
  */
 function modifySudoer()
 {
     $this->setHeaders();
     $this->getOutput()->setPagetitle($this->msg('openstackmanager-modifysudoer'));
     if (!$this->userLDAP->inRole('projectadmin', $this->projectName)) {
         $this->notInRole('projectadmin', $this->projectName);
         return false;
     }
     $sudoername = $this->getRequest()->getText('sudoername');
     $sudoer = OpenStackNovaSudoer::getSudoerByName($sudoername, $this->projectName);
     $userArr = $this->getSudoUsers($this->projectName, $sudoer);
     $user_keys = $userArr["keys"];
     $user_defaults = $userArr["defaults"];
     $runasArr = $this->getSudoRunAsUsers($this->projectName, $sudoer);
     $runas_keys = $runasArr["keys"];
     $runas_defaults = $runasArr["defaults"];
     $commands = implode("\n", $sudoer->getSudoerCommands());
     $optionArray = $sudoer->getSudoerOptions();
     $requirePassword = false;
     if (($k = array_search('!authenticate', $optionArray)) !== false) {
         unset($optionArray[$k]);
     } elseif (($k = array_search('authenticate', $optionArray)) !== false) {
         unset($optionArray[$k]);
         $requirePassword = true;
     }
     $options = implode("\n", $optionArray);
     $sudoerInfo = array();
     $sudoerInfo['sudoernameinfo'] = array('type' => 'info', 'label-message' => 'openstackmanager-sudoername', 'default' => $sudoername, 'section' => 'sudoer', 'name' => 'sudoernameinfo');
     $sudoerInfo['sudoername'] = array('type' => 'hidden', 'default' => $sudoername, 'name' => 'sudoername');
     $sudoerInfo['users'] = array('type' => 'multiselect', 'label-message' => 'openstackmanager-sudoerusers', 'options' => $user_keys, 'default' => $user_defaults, 'section' => 'sudoer', 'name' => 'users');
     $sudoerInfo['runas'] = array('type' => 'multiselect', 'label-message' => 'openstackmanager-sudoerrunas', 'options' => $runas_keys, 'default' => $runas_defaults, 'section' => 'sudoer', 'name' => 'runas');
     $sudoerInfo['commands'] = array('type' => 'textarea', 'label-message' => 'openstackmanager-sudoercommands', 'default' => $commands, 'section' => 'sudoer', 'name' => 'commands');
     $sudoerInfo['options'] = array('type' => 'textarea', 'label-message' => 'openstackmanager-sudoeroptions', 'default' => $options, 'section' => 'sudoer', 'name' => 'options');
     $sudoerInfo['project'] = array('type' => 'hidden', 'default' => $this->projectName, 'name' => 'project');
     $sudoerInfo['action'] = array('type' => 'hidden', 'default' => 'modify', 'name' => 'action');
     $sudoerInfo['requirepassword'] = array('type' => 'check', 'label-message' => 'openstackmanager-requirepassword', 'default' => $requirePassword, 'section' => 'sudoer', 'name' => 'requirepassword');
     $sudoerForm = new HTMLForm($sudoerInfo, $this->getContext(), 'openstackmanager-novasudoer');
     $sudoerForm->setSubmitID('novasudoer-form-createsudoersubmit');
     $sudoerForm->setSubmitCallback(array($this, 'tryModifySubmit'));
     $sudoerForm->show();
     return true;
 }
 /**
  * @return bool
  */
 function deleteMember()
 {
     $this->setHeaders();
     $this->getOutput()->setPagetitle($this->msg('openstackmanager-removerolemember'));
     $rolename = $this->getRequest()->getText('rolename');
     $projectname = $this->getRequest()->getText('projectname');
     if ($projectname) {
         if (!$this->userCanExecute($this->getUser()) && !$this->userLDAP->inRole($rolename, $projectname)) {
             $this->displayRestrictionError();
             return false;
         }
         $project = OpenStackNovaProject::getProjectByName($projectname);
         $projectmembers = $project->getMembers();
         natcasesort($projectmembers);
         $role = OpenStackNovaRole::getProjectRoleByName($rolename, $project);
         $rolemembers = $role->getMembers();
         $member_keys = array();
         foreach ($projectmembers as $projectmember) {
             if (in_array($projectmember, $rolemembers)) {
                 $member_keys[$projectmember] = $projectmember;
             }
         }
     } else {
         //TODO: display error
     }
     if (!$member_keys) {
         $this->getOutput()->addWikiMsg('openstackmanager-nomemberstoremove');
         return true;
     }
     $roleInfo = array();
     $roleInfo['members'] = array('type' => 'multiselect', 'label-message' => 'openstackmanager-member', 'options' => $member_keys, 'section' => 'role/info', 'name' => 'members');
     $roleInfo['action'] = array('type' => 'hidden', 'default' => 'deletemember', 'name' => 'action');
     $roleInfo['rolename'] = array('type' => 'hidden', 'default' => $rolename, 'name' => 'rolename');
     $roleInfo['projectname'] = array('type' => 'hidden', 'default' => $projectname, 'name' => 'projectname');
     $roleInfo['returnto'] = array('type' => 'hidden', 'default' => $this->getRequest()->getText('returnto'), 'name' => 'returnto');
     $roleForm = new HTMLForm($roleInfo, $this->getContext(), 'openstackmanager-novarole');
     $roleForm->setSubmitID('novarole-form-deletemembersubmit');
     $roleForm->setSubmitCallback(array($this, 'tryDeleteMemberSubmit'));
     $roleForm->show();
     return true;
 }
 /**
  * @return bool
  */
 function detachVolume()
 {
     $this->setHeaders();
     $this->getOutput()->setPagetitle($this->msg('openstackmanager-detachvolume'));
     $project = $this->getRequest()->getText('project');
     $region = $this->getRequest()->getText('region');
     if (!$this->userLDAP->inRole('projectadmin', $project)) {
         $this->notInRole('projectadmin', $project);
         return false;
     }
     $volumeInfo = array();
     $volumeInfo['volumeinfo'] = array('type' => 'info', 'label-message' => 'openstackmanager-volumename', 'default' => $this->getRequest()->getText('volumeid'), 'section' => 'volume/info', 'name' => 'volumeinfo');
     $volumeInfo['force'] = array('type' => 'toggle', 'label-message' => 'openstackmanager-forcedetachment', 'help-message' => 'openstackmanager-forcedetachmenthelp', 'section' => 'volume/info', 'name' => 'volumeinfo');
     $volumeInfo['volumeid'] = array('type' => 'hidden', 'default' => $this->getRequest()->getText('volumeid'), 'name' => 'volumeid');
     $volumeInfo['project'] = array('type' => 'hidden', 'default' => $project, 'name' => 'project');
     $volumeInfo['region'] = array('type' => 'hidden', 'default' => $region, 'name' => 'region');
     $volumeInfo['action'] = array('type' => 'hidden', 'default' => 'detach', 'name' => 'action');
     $volumeForm = new HTMLForm($volumeInfo, $this->getContext(), 'openstackmanager-novavolume');
     $volumeForm->setSubmitID('novavolume-form-detachvolumesubmit');
     $volumeForm->setSubmitCallback(array($this, 'tryDetachSubmit'));
     $volumeForm->show();
     return true;
 }
 /**
  * @return bool
  */
 function removeHost()
 {
     $this->setHeaders();
     $this->getOutput()->setPagetitle($this->msg('openstackmanager-removehost'));
     $project = $this->getRequest()->getText('project');
     $region = $this->getRequest()->getText('region');
     if (!$this->userLDAP->inRole('projectadmin', $project)) {
         $this->notInRole('projectadmin', $project);
         return false;
     }
     $id = $this->getRequest()->getText('id');
     $fqdn = $this->getRequest()->getText('fqdn');
     $hostname = $this->getRequest()->getText('hostname');
     if (!$this->getRequest()->wasPosted()) {
         $address = $this->userNova->getAddress($id);
         $ip = $address->getPublicIP();
         $this->getOutput()->addWikiMsg('openstackmanager-removehost-confirm', $hostname, $ip);
     }
     $addressInfo = array();
     $addressInfo['project'] = array('type' => 'hidden', 'default' => $project, 'name' => 'project');
     $addressInfo['region'] = array('type' => 'hidden', 'default' => $region, 'name' => 'region');
     $addressInfo['id'] = array('type' => 'hidden', 'default' => $id, 'name' => 'id');
     $addressInfo['fqdn'] = array('type' => 'hidden', 'default' => $fqdn, 'name' => 'fqdn');
     $addressInfo['hostname'] = array('type' => 'hidden', 'default' => $hostname, 'name' => 'hostname');
     $addressInfo['action'] = array('type' => 'hidden', 'default' => 'removehost', 'name' => 'action');
     $addressForm = new HTMLForm($addressInfo, $this->getContext(), 'openstackmanager-novaaddress');
     $addressForm->setSubmitID('novaaddress-form-removehostsubmit');
     $addressForm->setSubmitCallback(array($this, 'tryRemoveHostSubmit'));
     $addressForm->setSubmitText('confirm');
     $addressForm->show();
     return true;
 }
 /**
  * @return bool
  */
 function removeServiceGroup()
 {
     $this->setHeaders();
     $project = $this->getRequest()->getText('projectname');
     if (!$this->userCanExecute($this->getUser()) && !$this->userLDAP->inRole('projectadmin', $project)) {
         $this->notInRole('projectadmin', $project);
         return false;
     }
     $this->getOutput()->setPagetitle($this->msg('openstackmanager-removeservicegroup'));
     $groupName = $this->getRequest()->getText('groupname');
     if (!$this->getRequest()->wasPosted()) {
         $this->getOutput()->addWikiMsg('openstackmanager-removeservicegroupconfirm', $groupName);
     }
     $projectInfo = array();
     $projectInfo['projectname'] = array('type' => 'hidden', 'default' => $project, 'name' => 'projectname');
     $projectInfo['groupname'] = array('type' => 'hidden', 'default' => $groupName, 'name' => 'groupname');
     $projectInfo['action'] = array('type' => 'hidden', 'default' => 'removeservicegroup', 'name' => 'action');
     $projectForm = new HTMLForm($projectInfo, $this->getContext(), 'openstackmanager-novaproject');
     $projectForm->setSubmitID('novaproject-form-removeservicegroupsubmit');
     $projectForm->setSubmitCallback(array($this, 'tryRemoveServiceGroupSubmit'));
     $projectForm->show();
     return true;
 }