Esempio n. 1
0
 function VerifyHost($hosts = '')
 {
     if (!$hosts) {
         return TRUE;
     }
     $allowedlist = explode(',', $hosts);
     $isin = FALSE;
     foreach ($allowedlist as $value) {
         $net = '';
         $mask = '';
         if (strpos($value, '/') === FALSE) {
             $net = $value;
         } else {
             list($net, $mask) = explode('/', $value);
         }
         $net = trim($net);
         $mask = trim($mask);
         if ($mask == '') {
             $mask = '255.255.255.255';
         } elseif (is_numeric($mask)) {
             $mask = prefix2mask($mask);
         }
         if (isipinstrict($this->ip, $net, $mask)) {
             return TRUE;
         }
     }
     return FALSE;
 }
Esempio n. 2
0
 $tmp = explode(',', $nodeedit['permit']);
 if (count($tmp) > 3) {
     $error['permit'] = 'Zbyt duża ilość wpisów!';
 } else {
     $toadd = array();
     foreach ($tmp as $val) {
         $val = trim($val);
         if (strpos($val, '/') === FALSE) {
             if (!check_ip($val)) {
                 $error['permit'] = 'Błędny adres IP';
             } else {
                 $toadd[] = $val;
             }
         } else {
             $tmp2 = explode('/', $val);
             $netaddr = getnetaddr($tmp2[0], prefix2mask($tmp2[1]));
             if (!$netaddr || $tmp2[1] > 32 || $tmp2[1] < 8) {
                 $error['permit'] = 'Błędny adres IP';
             } else {
                 $toadd[] = $netaddr . '/' . $tmp2[1];
             }
         }
     }
     if (count($toadd) == 1) {
         $nodeedit['permit'] = $toadd[0];
     } else {
         if (!empty($toadd)) {
             $nodeedit['permit'] = implode(';', $toadd);
         }
     }
 }
Esempio n. 3
0
File: netadd.php Progetto: itav/lms
         $error['gateway'] = trans('Incorrect gateway IP address!');
     } elseif (!isipin($netadd['gateway'], getnetaddr($netadd['address'], prefix2mask($netadd['prefix'])), prefix2mask($netadd['prefix']))) {
         $error['gateway'] = trans('Specified gateway address does not match with network address!');
     }
 }
 if ($netadd['dhcpstart'] != '') {
     if (!check_ip($netadd['dhcpstart'])) {
         $error['dhcpstart'] = trans('Incorrect IP address for DHCP range start!');
     } elseif (!isipin($netadd['dhcpstart'], getnetaddr($netadd['address'], prefix2mask($netadd['prefix'])), prefix2mask($netadd['prefix'])) && $netadd['address'] != '') {
         $error['dhcpstart'] = trans('IP address for DHCP range start does not match with network address!');
     }
 }
 if ($netadd['dhcpend'] != '') {
     if (!check_ip($netadd['dhcpend'])) {
         $error['dhcpend'] = trans('Incorrect IP address for DHCP range end!');
     } elseif (!isipin($netadd['dhcpend'], getnetaddr($netadd['address'], prefix2mask($netadd['prefix'])), prefix2mask($netadd['prefix'])) && $netadd['address'] != '') {
         $error['dhcpend'] = trans('IP address for DHCP range end does not match with network address!');
     }
 }
 if (!isset($error['dhcpstart']) && !isset($error['dhcpend'])) {
     if ($netadd['dhcpstart'] != '' && $netadd['dhcpend'] == '' || $netadd['dhcpstart'] == '' && $netadd['dhcpend'] != '') {
         $error['dhcpend'] = trans('Both IP addresses for DHCP range are required!');
     }
     if ($netadd['dhcpstart'] != '' && $netadd['dhcpend'] != '' && !(ip_long($netadd['dhcpend']) >= ip_long($netadd['dhcpstart']))) {
         $error['dhcpend'] = trans('End of DHCP range has to be equal or greater than start!');
     }
 }
 if (!empty($netadd['ownerid']) && !$LMS->CustomerExists($netadd['ownerid'])) {
     $error['ownerid'] = trans('Customer with the specified ID does not exist');
 }
 if (!$error) {
Esempio n. 4
0
    public function NetworkAdd($netadd)
    {
        global $SYSLOG_RESOURCE_KEYS;
        if ($netadd['prefix'] != '') {
            $netadd['mask'] = prefix2mask($netadd['prefix']);
        }
        $netadd['name'] = strtoupper($netadd['name']);
        $args = array('name' => $netadd['name'], 'address' => $netadd['address'], 'mask' => $netadd['mask'], 'interface' => strtolower($netadd['interface']), 'gateway' => $netadd['gateway'], 'dns' => $netadd['dns'], 'dns2' => $netadd['dns2'], 'domain' => $netadd['domain'], 'wins' => $netadd['wins'], 'dhcpstart' => $netadd['dhcpstart'], 'dhcpend' => $netadd['dhcpend'], 'notes' => $netadd['notes'], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_HOST] => $netadd['hostid']);
        if ($this->db->Execute('INSERT INTO networks (name, address, mask, interface, gateway, 
				dns, dns2, domain, wins, dhcpstart, dhcpend, notes, hostid) 
				VALUES (?, inet_aton(?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array_values($args))) {
            $netid = $this->db->GetOne('SELECT id FROM networks WHERE address = inet_aton(?) AND hostid = ?', array($netadd['address'], $netadd['hostid']));
            if ($this->syslog && $netid) {
                $args[$SYSLOG_RESOURCE_KEYS[SYSLOG_RES_NETWORK]] = $netid;
                $keys = array($SYSLOG_RESOURCE_KEYS[SYSLOG_RES_NETWORK], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_HOST]);
                if ($netadd['ownerid']) {
                    $args[$SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUST]] = $netadd['ownerid'];
                    $keys[] = $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUST];
                    $this->db->Execute('INSERT INTO nodes (name, ownerid, netid) VALUES(?, ?, ?)', array($netadd['name'], $netadd['ownerid'], $netid));
                }
                $this->syslog->AddMessage(SYSLOG_RES_NETWORK, SYSLOG_OPER_ADD, $args, $keys);
            }
            return $netid;
        } else {
            return FALSE;
        }
    }
Esempio n. 5
0
File: netedit.php Progetto: rzt/lms
		else
			if(!isipin($networkdata['gateway'],getnetaddr($networkdata['address'],prefix2mask($networkdata['prefix'])),prefix2mask($networkdata['prefix'])))
				$error['gateway'] =  trans('Specified gateway address does not match with network address!');

	if($networkdata['dhcpstart']!='')
		if(!check_ip($networkdata['dhcpstart']))
			$error['dhcpstart'] = trans('Incorrect IP address for DHCP range start!');
		else
			if(!isipin($networkdata['dhcpstart'],getnetaddr($networkdata['address'],prefix2mask($networkdata['prefix'])),prefix2mask($networkdata['prefix'])) && $networkdata['address']!='')
				$error['dhcpstart'] = trans('IP address for DHCP range start does not match with network address!');

	if($networkdata['dhcpend']!='')
		if(!check_ip($networkdata['dhcpend']))
			$error['dhcpend'] =  trans('Incorrect IP address for DHCP range end!');
		else
			if(!isipin($networkdata['dhcpend'],getnetaddr($networkdata['address'],prefix2mask($networkdata['prefix'])),prefix2mask($networkdata['prefix'])) && $networkdata['address']!='')
				$error['dhcpend'] = trans('IP address for DHCP range end does not match with network address!');
	
	if(!isset($error['dhcpstart']) && !isset($error['dhcpend']))
	{
		if(($networkdata['dhcpstart']!='' && $networkdata['dhcpend']=='')||($networkdata['dhcpstart']=='' && $networkdata['dhcpend']!=''))
			$error['dhcpend'] = trans('Both IP addresses for DHCP range are required!');
		if($networkdata['dhcpstart']!='' && $networkdata['dhcpend']!='' && !(ip_long($networkdata['dhcpend']) >= ip_long($networkdata['dhcpstart'])))
			$error['dhcpend'] = trans('End of DHCP range has to be equal or greater than start!');
	}
	
	if(!$error)
	{
	        if(isset($networkdata['needshft']) && $networkdata['needshft'])
		        $LMS->NetworkShift($network['address'],$network['mask'],$networkdata['addresslong'] - $network['addresslong']);
Esempio n. 6
0
    $allowedlist = explode(',', $CONFIG['phpui']['allow_from']);
    $isin = FALSE;
    foreach ($allowedlist as $value) {
        $net = '';
        $mask = '';
        if (strpos($value, '/') === FALSE) {
            $net = $value;
        } else {
            list($net, $mask) = explode('/', $value);
        }
        $net = trim($net);
        $mask = trim($mask);
        if ($mask == '') {
            $mask = '255.255.255.255';
        } elseif (is_numeric($mask)) {
            $mask = prefix2mask($mask);
        }
        if (isipinstrict($ipaddr, $net, $mask)) {
            $isin = TRUE;
            break;
        }
    }
    if (!$isin) {
        header('HTTP/1.1 403 Forbidden');
        echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
		<HTML><HEAD>
		<TITLE>403 Forbidden</TITLE>
		</HEAD><BODY>
		<H1>Forbidden</H1>
		You don\'t have permission to access ' . $_SERVER['REQUEST_URI'] . '
		on this server.<P>
Esempio n. 7
0
    function NetworkAdd($netadd)
    {
        if ($netadd['prefix'] != '') {
            $netadd['mask'] = prefix2mask($netadd['prefix']);
        }
        if ($this->DB->Execute('INSERT INTO networks (name, address, mask, interface, gateway, 
				dns, dns2, domain, wins, dhcpstart, dhcpend, notes, hostid, ipnat) 
				VALUES (?, inet_aton(?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array(strtoupper($netadd['name']), $netadd['address'], $netadd['mask'], strtolower($netadd['interface']), $netadd['gateway'], $netadd['dns'], $netadd['dns2'], $netadd['domain'], $netadd['wins'], $netadd['dhcpstart'], $netadd['dhcpend'], $netadd['notes'], $netadd['hostid'] ? $netadd['hostid'] : NULL, $netadd['ipnat'] ? $netadd['ipnat'] : ''))) {
            return $this->DB->getLastInsertId('networks');
        } else {
            return FALSE;
        }
    }
Esempio n. 8
0
    function NetworkAdd($netadd)
    {
        if ($netadd['prefix'] != '') {
            $netadd['mask'] = prefix2mask($netadd['prefix']);
        }
        if ($this->DB->Execute('INSERT INTO networks (name, address, mask, interface, gateway, 
				dns, dns2, domain, wins, dhcpstart, dhcpend, notes) 
				VALUES (?, inet_aton(?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array(strtoupper($netadd['name']), $netadd['address'], $netadd['mask'], strtolower($netadd['interface']), $netadd['gateway'], $netadd['dns'], $netadd['dns2'], $netadd['domain'], $netadd['wins'], $netadd['dhcpstart'], $netadd['dhcpend'], $netadd['notes']))) {
            return $this->DB->GetOne('SELECT id FROM networks WHERE address = inet_aton(?)', array($netadd['address']));
        } else {
            return FALSE;
        }
    }
Esempio n. 9
0
    public function NetworkAdd($netadd)
    {
        if ($netadd['prefix'] != '') {
            $netadd['mask'] = prefix2mask($netadd['prefix']);
        }
        $netadd['name'] = strtoupper($netadd['name']);
        $args = array('name' => $netadd['name'], 'address' => $netadd['address'], 'mask' => $netadd['mask'], 'interface' => strtolower($netadd['interface']), 'gateway' => $netadd['gateway'], 'dns' => $netadd['dns'], 'dns2' => $netadd['dns2'], 'domain' => $netadd['domain'], 'wins' => $netadd['wins'], 'dhcpstart' => $netadd['dhcpstart'], 'dhcpend' => $netadd['dhcpend'], 'notes' => $netadd['notes'], 'vlanid' => intval($netadd['vlanid']), SYSLOG::RES_HOST => $netadd['hostid'], 'authtype' => $netadd['authtype']);
        if ($this->db->Execute('INSERT INTO networks (name, address, mask, interface, gateway,
				dns, dns2, domain, wins, dhcpstart, dhcpend, notes, vlanid, hostid, authtype)
				VALUES (?, inet_aton(?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array_values($args))) {
            $netid = $this->db->GetLastInsertID('networks');
            if (!$netid) {
                return false;
            }
            if ($this->syslog) {
                $this->syslog->AddMessage(SYSLOG::RES_NETWORK, SYSLOG::OPER_ADD, $args);
            }
            if ($netadd['ownerid']) {
                $args = array('name' => $netadd['name'], SYSLOG::RES_CUST => $netadd['ownerid'], SYSLOG::RES_NETWORK => $netid);
                $this->db->Execute('INSERT INTO nodes (name, ownerid, netid) VALUES(?, ?, ?)', array_values($args));
                if ($this->syslog) {
                    $this->syslog->AddMessage(SYSLOG::RES_NODE, SYSLOG::OPER_ADD, $args);
                }
            }
            return $netid;
        } else {
            return false;
        }
    }