Example #1
0
 function updateHostsFile()
 {
     # update hosts file, so that user on server desktop can reach the website.
     $this->requireCommandLine(__FUNCTION__);
     $count = 0;
     $ip = $this->miscconfig['localip'];
     if (!$ip) {
         $ip = getlocalip();
     }
     if (trim($ip) == '') {
         return True;
     }
     $doms = $this->getDomains("");
     #print_r($doms);
     $line = "\n" . $ip;
     foreach ($doms as $domain) {
         # Limit entries per line to avoid problems due to the line being too long
         # 255 Character Limit Per Line
         if ($count == 2) {
             $line .= '\\n' . $ip;
             $count = 0;
         }
         $line .= " www." . $domain['domainname'] . " " . $domain['domainname'] . " mail." . $domain['domainname'];
         $count++;
     }
     # process subdomains as well
     $subdomains = $this->get_subdomains();
     foreach ($subdomains as $subdomain) {
         # Limit entries per line to avoid problems due to the line being too long
         # 255 Character Limit Per Line
         if ($count == 2) {
             $line .= '\\n' . $ip;
             $count = 0;
         }
         $subd = $subdomain['subdomain'] . "." . $subdomain['domainname'];
         $line .= " www.{$subd} {$subd}";
         $count++;
     }
     # Causes issues because localhost is already defined in its own line
     // $line.=" localhost";
     echo "updating hosts file: ip: ({$ip})  line: ({$line})\n ";
     passthru2("bash /var/www/new/ehcp/updateHostsFile.sh \"{$line}\"");
     # No longer needed
     //replaceOrAddLineInFile("$ip ",$line,"/etc/hosts");
     echo "update complete\n";
     return True;
 }
Example #2
0
function getlocalip2($interface = 'eth0')
{
    global $localip;
    if ($localip != '') {
        return $localip;
    }
    $ip = getlocalip($interface);
    if ($ip == '') {
        $ip = getlocalip('eth1');
    }
    if ($ip == '') {
        $ip = getlocalip('eth2');
    }
    if ($ip == '') {
        $ipline = exec("ifconfig | grep 'inet ' | grep 'dres' | grep 255.255 | grep -v '127.0.0'");
        $ipline = strstr($ipline, "addr:");
        $pos = strpos($ipline, " ");
        $ip = trim(substr($ipline, 5, $pos - 5));
        if ($ip == '') {
            echo "Your ip cannot be determined automatically... \n";
        }
    }
    $localip = $ip;
    return $ip;
}