exit; } if (isset($_GET["dhcpd-leases"])) { dhcpd_leases_force(); exit; } if (isset($_GET["dhcpd-leases-script"])) { dhcpd_leases_script(); exit; } if (isset($_GET["flush-arp-cache"])) { flush_arp_cache(); exit; } if (isset($_GET["etc-hosts-default"])) { etc_hosts_defaults(); exit; } if (isset($_GET["etc-hosts"])) { etc_hosts(); exit; } if (isset($_GET["artica-ifup-content"])) { artica_ifup_content(); exit; } if (isset($_GET["ucarp-down"])) { ucarp_down(); exit; } while (list($num, $ligne) = each($_GET)) {
function etc_hosts() { $unix = new unix(); $echo = $unix->find_program("echo"); $sock = new sockets(); $hostname = $sock->GET_INFO("myhostname"); if ($hostname == null) { $hostname = $sock->getFrameWork("system.php?hostname-g=yes"); $sock->SET_INFO($hostname, "myhostname"); } $q = new mysql(); $DisableEtcHosts = $sock->GET_INFO("DisableEtcHosts"); if (!is_numeric($DisableEtcHosts)) { $DisableEtcHosts = 0; } if ($DisableEtcHosts == 1) { $GLOBALS["SCRIPTS"][] = "# [" . __LINE__ . "] *******************************"; $GLOBALS["SCRIPTS"][] = "# [" . __LINE__ . "] **** HOSTS FILE ****"; $GLOBALS["SCRIPTS"][] = "# [" . __LINE__ . "] *******************************"; $GLOBALS["SCRIPTS"][] = "# [" . __LINE__ . "] Disabled by DisableEtcHosts"; return; } if ($q->COUNT_ROWS("net_hosts", "artica_backup") == 0) { if (!$q->ok) { echo $q->mysql_error . "\n"; return; } etc_hosts_defaults(); } if ($q->COUNT_ROWS("net_hosts", "artica_backup") == 0) { $GLOBALS["SCRIPTS"][] = "# [" . __LINE__ . "] net_hosts issue on MySQL keep the file untouched"; return; } if (strpos($hostname, ".") > 0) { $rre = explode(".", $hostname); $netbiosname = $rre[0]; } $f[] = "::1 localhost ip6-localhost ip6-loopback"; $f[] = "::1 {$hostname}\t{$netbiosname}"; $f[] = "fe00::0 ip6-localnet"; $f[] = "ff00::0 ip6-mcastprefix"; $f[] = "ff02::1 ip6-allnodes"; $f[] = "ff02::2 ip6-allrouters"; $f[] = "ff02::3 ip6-allhosts"; $f[] = "ff02::3 ip6-allhosts"; $GLOBALS["SCRIPTS"][] = "# [" . __LINE__ . "]"; $GLOBALS["SCRIPTS"][] = "# [" . __LINE__ . "] *******************************"; $GLOBALS["SCRIPTS"][] = "# [" . __LINE__ . "] **** HOSTS FILE ****"; $GLOBALS["SCRIPTS"][] = "# [" . __LINE__ . "] *******************************"; $GLOBALS["SCRIPTS"][] = "# [" . __LINE__ . "]"; $GLOBALS["SCRIPTS"][] = "# this first line flush the host file"; $GLOBALS["SCRIPTS"][] = "{$echo} \"127.0.0.1 {$hostname}\t{$netbiosname}\" >/etc/hosts"; while (list($index, $line) = each($f)) { $GLOBALS["SCRIPTS"][] = "{$echo} \"{$line}\" >> /etc/hosts"; } $sql = "SELECT * FROM net_hosts ORDER BY hostname"; $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo $q->mysql_error . "\n"; return; } $ip = new IP(); while ($ligne = mysql_fetch_assoc($results)) { while (list($a, $b) = each($ligne)) { $ligne[$a] = str_replace("\r\n", " ", $ligne[$a]); $ligne[$a] = str_replace("\n", " ", $ligne[$a]); $ligne[$a] = str_replace("\r", " ", $ligne[$a]); $ligne[$a] = trim($ligne[$a]); } if (!$ip->isValid($ligne["ipaddr"])) { $GLOBALS["SCRIPTS"][] = "# [" . __LINE__ . "]: {$ligne["ipaddr"]} not valid for {$ligne["hostname"]}"; continue; } if (trim($ligne["hostname"]) == null) { continue; } if (trim($ligne["alias"]) != null) { $ligne["alias"] = "\t{$ligne["alias"]}"; } $lineExe = trim("{$ligne["ipaddr"]}\t{$ligne["hostname"]}{$ligne["alias"]}"); $GLOBALS["SCRIPTS"][] = "{$echo} \"{$lineExe}\" >> /etc/hosts"; } $q = new mysql_squid_builder(); $sql = "SELECT * FROM dnsmasq_records"; $results = $q->QUERY_SQL($sql); if (!$q->ok) { echo $q->mysql_error . "\n"; return; } while ($ligne = mysql_fetch_assoc($results)) { $ipaddr = trim($ligne["ipaddr"]); $hostname = trim($ligne["hostname"]); if (strpos($hostname, ".") > 0) { $hostname_EXPLODED = explode(".", $hostname); $alias = $hostname_EXPLODED[0]; } $results2 = $q->QUERY_SQL("SELECT hostname FROM dnsmasq_cname WHERE recordid={$ligne["ID"]}"); $aliases = array(); while ($ligne2 = mysql_fetch_assoc($results2)) { if (trim($ligne2["hostname"]) == null) { continue; } $alias = $ligne2["hostname"]; break; } $lineExe = trim("{$ipaddr}\t{$hostname}\t{$alias}"); $GLOBALS["SCRIPTS"][] = "{$echo} \"{$lineExe}\" >> /etc/hosts"; } $GLOBALS["SCRIPTS"][] = "#"; return true; }