static function getBaseEnd($ip, $rangelist = null) { if (isIPV6($ip)) { $comp = expandIP6ToArray($ip); $last = array_pop($comp); $base = self::createDottedRevedIPV6($comp[6]) . "."; $base .= self::createDottedRevedIPV6($comp[5]) . "."; $base .= self::createDottedRevedIPV6($comp[4]) . "."; $base .= self::createDottedRevedIPV6($comp[3]) . "."; $base .= self::createDottedRevedIPV6($comp[2]) . "."; $base .= self::createDottedRevedIPV6($comp[1]) . "."; $base .= self::createDottedRevedIPV6($comp[0]) . "."; if ($rangelist && false) { // FIXME: OA: The whole rangelist must be reworked // I dont care it now, clients cannot declare rangelists foreach ($rangelist as $v) { list($rb, $rf, $rl) = $v; if ($rb === $base && $last >= $rf && $last <= $rl) { $base = "{$rf}-{$rl}.{$base}"; break; } } } } else { $comp = explode(".", $ip); $last = array_pop($comp); $base = "{$comp['2']}.{$comp['1']}.{$comp['0']}"; if ($rangelist) { foreach ($rangelist as $v) { list($rb, $rf, $rl) = $v; if ($rb === $base && $last >= $rf && $last <= $rl) { $base = "{$rf}-{$rl}.{$base}"; break; } } } } return array($base, $last); }
function getIndividualIpList() { if (isIPV6($this->lastip)) { $sep = ':'; } else { $sep = '.'; } $base = explode($sep, $this->lastip); $end = array_pop($base); $base = explode($sep, $this->firstip); $start = array_pop($base); $base = implode($sep, $base); if (isIPV6($this->lastip)) { for ($i = hexdec($start); $i <= hexdec($end); $i++) { $out[] = "{$base}{$sep}" . dechex($i); } } else { for ($i = $start; $i <= $end; $i++) { $out[] = "{$base}{$sep}{$i}"; } } $ex = get_namelist_from_objectlist($this->ippoolextraip_a); $out = lx_merge_good($out, $ex); $exception = get_namelist_from_objectlist($this->ippoolexceptionip_a); //dprintr($exception); foreach ($out as $k => $v) { if (isset($exception[$v])) { unset($out[$k]); } } $exception = get_namelist_from_objectlist($this->ippoolpingip_a); //dprintr($exception); foreach ($out as $k => $v) { if (isset($exception[$v])) { unset($out[$k]); } } return $out; }
function full_validate_ipaddress($ip, $variable = 'ipaddress') { // variable is nname or ipaddress global $gbl, $sgbl, $login, $ghtml; global $global_dontlogshell; $global_dontlogshell = true; $gen = $login->getObject('general')->generalmisc_b; if (!validate_ipaddress($ip)) { throw new lxException('Invalid IP address: ' . $ip, $variable); } if (isIPV6($ip)) { $ret = lxshell_return("ping6", "-n", "-c", "1", "-w", "5", $ip); } else { $ret = lxshell_return("ping", "-n", "-c", "1", "-w", "5", $ip); } // If the return status is 1, the ping fail and nobody uses. But if return is 0, somebody is using the IP if (intval($ret) !== 1) { throw new lxexception('Another host is using the IP ' . $ip . ' and it is responding to the IP ping. Please you will ensure to use an available IP to add.', $variable); } $global_dontlogshell = false; }
public function setInternalParam($mountpoint) { $name = $this->main->ostemplate; if ($this->main->isWindows()) { return; } if (!$mountpoint) { return; } if ($name === 'unknown') { return; } $name = strtolower($name); $mountpoint = expand_real_root($mountpoint); $result = $this->getScriptS($name); dprint("Distro Name {$name}, Scripts: \n"); dprintr($result); $init = strtilfirst($name, "-"); dprint("File is {$init}.inittab\n"); if (lxfile_exists("../file/sysfile/inittab/{$init}.inittab")) { dprint("Copying {$init}.inittab\n"); $content = lfile_get_contents("../file/sysfile/inittab/{$init}.inittab"); if ($this->main->text_inittab) { $content .= "\n{$this->main->text_inittab}"; } lfile_put_contents("{$mountpoint}/etc/inittab", $content); } $iplist = get_namelist_from_objectlist($this->main->vmipaddress_a); if ($this->main->mainipaddress) { $main_ip = $this->main->mainipaddress; $iplist = array_remove($iplist, $main_ip); } else { $main_ip = array_shift($iplist); } if ($this->main->networknetmask) { $main_netmask = $this->main->networknetmask; } else { $main_netmask = "255.255.255.0"; } $iplist = implode(" ", $iplist); $iplistnew = preg_split('/ /', $iplist, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); //counting the elements of the array aka ip $ipcnt = count($iplistnew); for ($i = 0; $i < $ipcnt; $i++) { if (isIPV6($iplistnew[$i])) { $iplist6new[$i] = $iplistnew[$i]; $ip6list = implode(" ", $iplist6new); } elseif (!isIPV6($iplistnew[$i])) { $iplist4new[$i] = $iplistnew[$i]; $ip4list = implode(" ", $iplist4new); } else { throw new lxException("The Iplist does not contain any values"); } } $ipadd = $result['ADD_IP']; $sethostname = $result['SET_HOSTNAME']; $setuserpass = $result['SET_USERPASS']; $ipdel = $result['DEL_IP']; if ($this->main->networkgateway) { $gw = $this->main->networkgateway; } else { $gw = os_get_network_gateway(); } $gwn = strtil($gw, '.') . '.0'; $hostname = $this->main->hostname; if (!$hostname) { $hostname = os_get_hostname(); } if ($result['STARTUP_SCRIPT'] != 'systemd') { $name = createTempDir("{$mountpoint}/tmp", 'xen-scripts'); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/functions", $name); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$ipadd}", $name); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$sethostname}", $name); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$setuserpass}", $name); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$ipdel}", $name); $basepath = strfrom($name, $mountpoint); lfile_put_contents("{$name}/tmpfile.sh", "source /{$basepath}/functions\nsource /{$basepath}/{$ipdel}\n"); $delipstring = "IPDELALL=yes chroot {$mountpoint} bash /{$basepath}/tmpfile.sh"; log_shell($delipstring); log_shell(system($delipstring, $ret1) . ":return {$ret1}"); putenv("VE_STATE=stopped"); lfile_put_contents("{$name}/tmpfile.sh", "source /{$basepath}/functions\n source /{$basepath}/{$ipadd}\n"); $string = "IPDELALL=yes MAIN_NETMASK={$main_netmask} MAIN_IP_ADDRESS={$main_ip} IP_ADDR=\"{$iplist}\" NETWORK_GATEWAY={$gw} NETWORK_GATEWAY_NET={$gwn} chroot {$mountpoint} bash /{$basepath}/tmpfile.sh"; log_shell($string); log_shell(system($string, $ret1) . ":return {$ret1}"); lfile_put_contents("{$name}/tmpfile.sh", "source /{$basepath}/functions\n source /{$basepath}/{$sethostname}\n"); $string = "HOSTNM={$hostname} chroot {$mountpoint} bash /{$basepath}/tmpfile.sh"; log_shell($string); log_shell(system($string, $ret1) . ":return {$ret1}"); if ($this->main->subaction === 'rebuild' || $this->main->dbaction === 'add' || $this->main->isOn('__var_rootpassword_changed') && $this->main->rootpassword) { $rootpass = "******"; lfile_put_contents("{$name}/tmpfile.sh", "source /{$basepath}/functions\n source /{$basepath}/{$setuserpass}\n"); $string = "USERPW={$rootpass} chroot {$mountpoint} bash /{$basepath}/tmpfile.sh"; log_shell($string); log_shell(system($string)); } lxfile_rm_rec($name); } else { if ($result['STARTUP_SCRIPT'] == 'systemd') { $script_dir = createTempDir("{$mountpoint}", "hypervm-runonce"); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/functions", $script_dir); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$ipadd}", $script_dir); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$sethostname}", $script_dir); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$setuserpass}", $script_dir); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$ipdel}", $script_dir); $basepath = strfrom($script_dir, $mountpoint); $startupdir = 'lib/systemd/system'; $startupscript = 'fedora-startup.service'; $setrootpass = ''; if ($this->main->subaction === 'rebuild' || $this->main->dbaction === 'add' || $this->main->isOn('__var_rootpassword_changed') && $this->main->rootpassword) { $rootpass = "******"; $setrootpass = "******"; } $run_once_script = "#!/bin/bash\n" . "source {$basepath}/functions\n" . '(' . "IPDELALL=yes source {$basepath}/{$ipdel}" . " & IPDELALL=yes VE_STATE=stopped MAIN_NETMASK={$main_netmask} MAIN_IP_ADDRESS={$main_ip} IP_ADDR=\"{$iplist}\" NETWORK_GATEWAY={$gw} NETWORK_GATEWAY_NET={$gwn} source {$basepath}/{$ipadd}" . " & HOSTNM={$hostname} source {$basepath}/{$sethostname}" . "{$setrootpass})\n" . "service fedora-startup disable\nrm -f /{$startupdir}/{$startupscript}\nrm -rf {$basepath}"; lfile_put_contents("{$script_dir}/hypervm-runonce.sh", $run_once_script); lxfile_cp_rec("__path_program_root/bin/xen-dists/scripts/{$startupscript}", "{$mountpoint}/{$startupdir}"); lfile_put_contents("{$mountpoint}/{$startupdir}/{$startupscript}", lfile_get_contents("{$mountpoint}/{$startupdir}/{$startupscript}") . "ExecStart={$basepath}/hypervm-runonce.sh\n"); system("ln -s /lib/systemd/system/fedora-startup.service {$mountpoint}/etc/systemd/system/multi-user.target.wants/fedora-startup.service"); system("chmod 755 {$script_dir}/hypervm-runonce.sh"); } } if ($this->main->nameserver) { $nlist = explode(" ", $this->main->nameserver); $nstring = null; foreach ($nlist as $l) { $nstring .= "nameserver {$l}\n"; } lfile_put_contents("{$mountpoint}/etc/resolv.conf", $nstring); } if ($this->main->timezone) { lxfile_rm("{$mountpoint}/etc/localtime"); $cmdstring = "ln -sf ../usr/share/zoneinfo/{$this->main->timezone} {$mountpoint}/etc/localtime"; log_log("localtime", $cmdstring); do_exec_system('__system__', "/", $cmdstring, $out, $err, $ret, null); //lxfile_cp("/usr/share/zoneinfo/{$this->main->timezone}", "$mountpoint/etc/localtime"); } lunlink("{$mountpoint}/etc/sysconfig/network-scripts/ifcfg-venet0"); lunlink("{$mountpoint}/etc/sysconfig/network-scripts/ifcfg-venet0:0"); $this->main->doKloxoInit($mountpoint); }