/**
  * @param  $formData
  * @param string $entryPoint
  * @return bool
  */
 function tryCreateSubmit($formData, $entryPoint = 'internal')
 {
     global $wgOpenStackManagerProxyGateways;
     $goback = '<br />';
     $goback .= Linker::link($this->getPageTitle(), $this->msg('openstackmanager-backproxylist')->escaped());
     $project = $formData['project'];
     $backendPort = $formData['backendport'];
     $backendHost = $formData['backendhost'];
     $region = $formData['region'];
     $proxyName = $formData['proxyname'];
     $proxyDomain = $formData['domain'];
     $outputPage = $this->getOutput();
     $gatewayIP = $wgOpenStackManagerProxyGateways[$region];
     if (!array_key_exists($region, $wgOpenStackManagerProxyGateways)) {
         $outputPage->addWikiMsg('openstackmanager-addhostfailed', $proxyName, $gatewayIP);
         $outputPage->addHTML($goback);
         return true;
     }
     $domain = OpenStackNovaDomain::getDomainByName($proxyDomain);
     $gatewayhostbyip = OpenStackNovaHost::getHostByPublicIP($gatewayIP);
     $fqdn = $proxyName . '.' . $domain->getFullyQualifiedDomainName();
     $dnsSuccess = $this->addHost($proxyName, $proxyDomain, $gatewayIP);
     if ($dnsSuccess) {
         $outputPage->addWikiMsg('openstackmanager-addedhost', $proxyName, $gatewayIP);
     } else {
         $outputPage->addWikiMsg('openstackmanager-addhostfailed', $proxyName, $gatewayIP);
         $outputPage->addHTML($goback);
         return true;
     }
     # DNS looks good, now we can set up the proxy.
     $newProxy = $this->userNova->createProxy($fqdn, $backendHost, $backendPort);
     if ($newProxy) {
         $outputPage->addWikiMsg('openstackmanager-createdproxy', $fqdn, $backendHost . ":" . $backendPort);
     } else {
         $outputPage->addWikiMsg('openstackmanager-createproxyfailed', $fqdn);
         $this->deleteHost($fqdn, $gatewayIP);
         $outputPage->addHTML($goback);
         return true;
     }
     $outputPage->addHTML($goback);
     return true;
 }
 /**
  * Adds a host entry based on the hostname, IP addrss, and a domain. Returns null
  * if the entry already exists, or if the additional fails. This function should be used
  * for adding public DNS entries.
  *
  * @static
  * @param  $hostname
  * @param  $ip
  * @param  $domain OpenStackNovaDomain
  * @return bool|null|OpenStackNovaHost
  */
 static function addPublicHost($hostname, $ip, $domain)
 {
     global $wgAuth;
     global $wgOpenStackManagerLDAPInstanceBaseDN;
     OpenStackNovaLdapConnection::connect();
     $domainname = $domain->getFullyQualifiedDomainName();
     $host = OpenStackNovaHost::getHostByPublicIP($ip);
     if ($host) {
         $wgAuth->printDebug("Failed to add public host {$hostname} as the DNS entry already exists", NONSENSITIVE);
         return null;
     }
     $hostEntry = array();
     $hostEntry['objectclass'][] = 'dcobject';
     $hostEntry['objectclass'][] = 'dnsdomain';
     $hostEntry['objectclass'][] = 'domainrelatedobject';
     $hostEntry['dc'] = $ip;
     $hostEntry['arecord'] = $ip;
     $hostEntry['associateddomain'][] = $hostname . '.' . $domainname;
     $dn = 'dc=' . $ip . ',' . $wgOpenStackManagerLDAPInstanceBaseDN;
     $success = LdapAuthenticationPlugin::ldap_add($wgAuth->ldapconn, $dn, $hostEntry);
     if ($success) {
         $domain->updateSOA();
         $wgAuth->printDebug("Successfully added public host {$hostname}", NONSENSITIVE);
         return new OpenStackNovaHost(false, null, $ip);
     } else {
         $wgAuth->printDebug("Failed to add public host {$hostname} with dn = {$dn}", NONSENSITIVE);
         return null;
     }
 }
 /**
  * @param $formData
  * @param string $entryPoint
  * @return bool
  */
 function tryRemoveHostSubmit($formData, $entryPoint = 'internal')
 {
     $id = $formData['id'];
     $address = $this->userNova->getAddress($id);
     $outputPage = $this->getOutput();
     if (!$address) {
         $outputPage->addWikiMsg('openstackmanager-invalidaddress', $id);
         return true;
     }
     $ip = $address->getPublicIp();
     $hostname = $formData['hostname'];
     $fqdn = $formData['fqdn'];
     $host = OpenStackNovaHost::getHostByPublicIP($ip);
     if ($host) {
         $records = $host->getAssociatedDomains();
         if (count($records) > 1) {
             # We need to keep the host, but remove the fqdn
             $success = $host->deleteAssociatedDomain($fqdn);
             if ($success) {
                 $outputPage->addWikiMsg('openstackmanager-removedhost', $hostname, $ip);
             } else {
                 $outputPage->addWikiMsg('openstackmanager-removehostfailed', $ip, $hostname);
             }
         } else {
             # We need to remove the host entry
             $success = $host->deleteHost();
             if ($success) {
                 $outputPage->addWikiMsg('openstackmanager-removedhost', $hostname, $ip);
             } else {
                 $outputPage->addWikiMsg('openstackmanager-removehostfailed', $ip, $hostname);
             }
         }
     } else {
         $outputPage->addWikiMsg('openstackmanager-nonexistenthost');
     }
     $out = '<br />';
     $out .= Linker::link($this->getPageTitle(), $this->msg('openstackmanager-backaddresslist')->escaped());
     $outputPage->addHTML($out);
     return true;
 }