Пример #1
0
function BuildDHCP()
{
    $ldap = new clladp();
    if ($ldap->ldapFailed) {
        echo "Starting......: DHCP SERVER ldap connection failed,aborting\n";
        return;
    }
    if (!$ldap->ExistsDN("dc=organizations,{$ldap->suffix}")) {
        echo "Starting......: DHCP SERVER dc=organizations,{$ldap->suffix} no such branch, aborting\n";
        return;
    }
    echo "Starting......: DHCP SERVER ldap connection success\n";
    $dhcpd = new dhcpd();
    $conf = $dhcpd->BuildConf();
    $confpath = dhcp3Config();
    $unix = new unix();
    @mkdir(dirname($confpath), null, true);
    @file_put_contents($confpath, $conf);
    echo "Starting......: DHCP SERVER saving \"{$confpath}\" (" . strlen($conf) . " bytes) done\n";
    if (is_dir("/var/lib/dhcp3")) {
        shell_exec("/bin/chown -R dhcpd:dhcpd /var/lib/dhcp3");
        shell_exec("/bin/chmod 755 /var/lib/dhcp3");
    }
    $complain = $unix->find_program("aa-complain");
    if (is_file($complain)) {
        $dhcpd3 = $unix->find_program("dhcpd3");
        if (is_file($dhcpd3)) {
            shell_exec("{$complain} {$dhcpd3} >/dev/null 2>&1");
        }
    }
}
Пример #2
0
function BuildDHCP(){
	$dhcpd=new dhcpd();
	$conf=$dhcpd->BuildConf();
	$confpath=dhcp3Config();
	$unix=new unix();
	@mkdir(dirname($confpath),null,true);
	@file_put_contents($confpath,$conf);
	echo "Starting......: DHCP SERVER saving \"$confpath\" (". strlen($conf)." bytes) done\n";
	
	if(is_dir("/var/lib/dhcp3")){
		shell_exec("/bin/chown -R dhcpd:dhcpd /var/lib/dhcp3");
		shell_exec("/bin/chmod 755 /var/lib/dhcp3");
	
	}
	$complain=$unix->find_program("aa-complain");
	
	if(is_file($complain)){
		$dhcpd3=$unix->find_program("dhcpd3");
		if(is_file($dhcpd3)){shell_exec("$complain $dhcpd3 >/dev/null 2>&1");}
	}
	
}
Пример #3
0
function dhcpd_conf()
{
    echo "<articadatascgi>" . base64_encode(@file_get_contents(dhcp3Config())) . "</articadatascgi>";
}
Пример #4
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $LOGBIN = "DHCP Server";
    $binpath = $unix->DHCPD_BIN_PATH();
    if (!is_file($binpath)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$LOGBIN}, not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$LOGBIN}, [START] Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return false;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$LOGBIN} Service already started {$pid} since {$timepid}Mn...\n";
        }
        return true;
    }
    $EnableDHCPServer = $sock->GET_INFO("EnableDHCPServer");
    if (!is_numeric($EnableDHCPServer)) {
        $EnableDHCPServer = 0;
    }
    $EnableChilli = $sock->GET_INFO("EnableChilli");
    if (!is_numeric($EnableChilli)) {
        $EnableChilli = 0;
    }
    if ($EnableChilli == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$LOGBIN} replaced by HotSpot feature...\n";
        }
        $EnableDHCPServer = 0;
    }
    if ($EnableDHCPServer == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$LOGBIN} service disabled\n";
        }
        build_progress("{starting_service} {failed}", 110);
        return false;
    }
    build_progress("{starting_service}", 60);
    @mkdir("/var/run/dhcp3-server", 0755, true);
    @mkdir("/var/lib/dhcp3", 0755, true);
    if (!is_file("/var/lib/dhcp3/dhcpd.other")) {
        @file_put_contents("/var/lib/dhcp3/dhcpd.other", "#");
    }
    if (!is_file("/var/lib/dhcp3/dhcpd.leases")) {
        @file_put_contents("/var/lib/dhcp3/dhcpd.leases", "#");
    }
    $unix->SystemCreateUser("dhcpd", "dhcpd");
    $unix->chown_func("dhcpd", "dhcpd", "/var/run/dhcp3-server");
    $unix->chown_func("dhcpd", "dhcpd", "/var/lib/dhcp3/dhcpd.leases");
    $unix->chown_func("dhcpd", "dhcpd", "/var/lib/dhcp3/dhcpd.leases~");
    $DHCP3ListenNIC = $sock->GET_INFO('DHCP3ListenNIC');
    if ($DHCP3ListenNIC == null) {
        $DHCP3ListenNIC = "eth0";
    }
    echo "Starting......: " . date("H:i:s") . " [INIT]: {$LOGBIN} Listen {$DHCP3ListenNIC}\n";
    echo "Starting......: " . date("H:i:s") . " [INIT]: {$LOGBIN} building settings...\n";
    BuildDHCP(true);
    build_progress("{starting_service}", 75);
    $CMD[] = "{$binpath} -q -pf " . PID_PATH();
    $CMD[] = "-cf " . dhcp3Config();
    $CMD[] = "-lf /var/lib/dhcp3/dhcpd.leases";
    $cmd = @implode(" ", $CMD);
    echo "Starting......: " . date("H:i:s") . " [INIT]: {$LOGBIN} service..\n";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    shell_exec($cmd);
    build_progress("{starting_service}", 80);
    for ($i = 0; $i < 6; $i++) {
        $pid = PID_NUM();
        if ($unix->process_exists($pid)) {
            break;
        }
        build_progress("{starting_service}  waiting {$i}/6", 80);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$LOGBIN} service waiting {$i}/6...\n";
        }
        sleep(1);
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$LOGBIN} service Success service started pid:{$pid}...\n";
        }
        build_progress("{starting_service}  {success}", 100);
        return true;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$LOGBIN} service failed...\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: `{$cmd}`\n";
    }
    build_progress("{starting_service}  {failed}", 110);
    return false;
}