Ejemplo n.º 1
0
    /**
     * Returns customer nodes
     * 
     * @param int $id Customer id
     * @param int $count Limit
     * @return array Nodes
     */
    public function getCustomerNodes($id, $count = null)
    {
        if ($result = $this->db->GetAll('SELECT n.id, n.name, mac, ipaddr,
				inet_ntoa(ipaddr) AS ip, ipaddr_pub,
				inet_ntoa(ipaddr_pub) AS ip_pub, passwd, access,
				warning, info, ownerid, lastonline, location,
				(SELECT COUNT(*) FROM nodegroupassignments
					WHERE nodeid = n.id) AS gcount,
				n.netid, net.name AS netname
				FROM vnodes n
				JOIN networks net ON net.id = n.netid
				WHERE ownerid = ?
				ORDER BY n.name ASC ' . ($count ? 'LIMIT ' . $count : ''), array($id))) {
            // assign network(s) to node record
            $network_manager = new LMSNetworkManager($this->db, $this->auth, $this->cache);
            $networks = (array) $network_manager->GetNetworks();
            foreach ($result as $idx => $node) {
                $ids[$node['id']] = $idx;
                $result[$idx]['lastonlinedate'] = lastonline_date($node['lastonline']);
                //foreach ($networks as $net)
                //	if (isipin($node['ip'], $net['address'], $net['mask'])) {
                //		$result[$idx]['network'] = $net;
                //		break;
                //	}
                if ($node['ipaddr_pub']) {
                    foreach ($networks as $net) {
                        if (isipin($node['ip_pub'], $net['address'], $net['mask'])) {
                            $result[$idx]['network_pub'] = $net;
                            break;
                        }
                    }
                }
            }
            // get EtherWerX channels
            if (ConfigHelper::checkValue(ConfigHelper::getConfig('phpui.ewx_support', false))) {
                $channels = $this->db->GetAllByKey('SELECT nodeid, channelid, c.name, c.id, cid,
				        nc.upceil, nc.downceil
					FROM ewx_stm_nodes
					JOIN ewx_stm_channels nc ON (channelid = nc.id)
					LEFT JOIN ewx_channels c ON (c.id = nc.cid)
					WHERE nodeid IN (' . implode(',', array_keys($ids)) . ')', 'nodeid');
                if ($channels) {
                    foreach ($channels as $channel) {
                        $idx = $ids[$channel['nodeid']];
                        $result[$idx]['channelid'] = $channel['id'] ? $channel['id'] : $channel['channelid'];
                        $result[$idx]['channelname'] = $channel['name'];
                        $result[$idx]['cid'] = $channel['cid'];
                        $result[$idx]['downceil'] = $channel['downceil'];
                        $result[$idx]['upceil'] = $channel['upceil'];
                    }
                }
            }
        }
        return $result;
    }
Ejemplo n.º 2
0
Archivo: netadd.php Proyecto: 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) {
Ejemplo n.º 3
0
Archivo: netedit.php Proyecto: 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']);
Ejemplo n.º 4
0
    function GetCustomerNodes($id, $count = NULL)
    {
        if ($result = $this->DB->GetAll('SELECT n.id, n.name, n.mac, n.ipaddr, n.pppoelogin,
				inet_ntoa(n.ipaddr) AS ip, n.ipaddr_pub,
				inet_ntoa(n.ipaddr_pub) AS ip_pub, n.passwd, n.access, n.netdev , n.producer, n.model, 
				nd.id AS devid, nd.name AS devname, nd.location AS devlocation, 
				n.warning, n.info, n.ownerid, n.lastonline, n.location, n.blockade, 
				(SELECT 1 FROM monitnodes WHERE monitnodes.id = n.id AND monitnodes.active=1) AS monitoring, 
				(SELECT COUNT(*) FROM nodegroupassignments WHERE nodeid = n.id) AS gcount,
				n.netid, net.name AS netname 
				FROM vnodes n 
				JOIN networks net ON net.id = n.netid 
				LEFT JOIN netdevices nd ON (nd.id = n.netdev) 
				WHERE ownerid = ?
				ORDER BY name ASC ' . ($count ? 'LIMIT ' . $count : ''), array($id))) {
            // assign network(s) to node record
            $networks = (array) $this->GetNetworks();
            foreach ($result as $idx => $node) {
                $ids[$node['id']] = $idx;
                $result[$idx]['lastonlinedate'] = lastonline_date($node['lastonline']);
                if ($node['ipaddr_pub']) {
                    foreach ($networks as $net) {
                        if (isipin($node['ip_pub'], $net['address'], $net['mask'])) {
                            $result[$idx]['network_pub'] = $net;
                            break;
                        }
                    }
                }
            }
            // get EtherWerX channels
            if (chkconfig($this->CONFIG['phpui']['ewx_support'])) {
                $channels = $this->DB->GetAllByKey('SELECT nodeid, channelid, c.name, c.id, cid,
				        nc.upceil, nc.downceil
					FROM ewx_stm_nodes
					JOIN ewx_stm_channels nc ON (channelid = nc.id)
					LEFT JOIN ewx_channels c ON (c.id = nc.cid)
					WHERE nodeid IN (' . implode(',', array_keys($ids)) . ')', 'nodeid');
                if ($channels) {
                    foreach ($channels as $channel) {
                        $idx = $ids[$channel['nodeid']];
                        $result[$idx]['channelid'] = $channel['id'] ? $channel['id'] : $channel['channelid'];
                        $result[$idx]['channelname'] = $channel['name'];
                        $result[$idx]['cid'] = $channel['cid'];
                        $result[$idx]['downceil'] = $channel['downceil'];
                        $result[$idx]['upceil'] = $channel['upceil'];
                    }
                }
            }
        }
        return $result;
    }
Ejemplo n.º 5
0
    function GetCustomerNodes($id, $count = NULL)
    {
        if ($result = $this->DB->GetAll('SELECT id, name, mac, ipaddr,
				inet_ntoa(ipaddr) AS ip, ipaddr_pub,
				inet_ntoa(ipaddr_pub) AS ip_pub, passwd, access,
				warning, info, ownerid, lastonline, location,
				(SELECT COUNT(*) FROM nodegroupassignments
					WHERE nodeid = vnodes.id) AS gcount
				FROM vnodes
				WHERE ownerid = ?
				ORDER BY name ASC ' . ($count ? 'LIMIT ' . $count : ''), array($id))) {
            // assign network(s) to node record
            $networks = (array) $this->GetNetworks();
            foreach ($result as $idx => $node) {
                $ids[$node['id']] = $idx;
                $result[$idx]['lastonlinedate'] = lastonline_date($node['lastonline']);
                foreach ($networks as $net) {
                    if (isipin($node['ip'], $net['address'], $net['mask'])) {
                        $result[$idx]['network'] = $net;
                        break;
                    }
                }
                if ($node['ipaddr_pub']) {
                    foreach ($networks as $net) {
                        if (isipin($node['ip_pub'], $net['address'], $net['mask'])) {
                            $result[$idx]['network_pub'] = $net;
                            break;
                        }
                    }
                }
            }
            // get EtherWerX channels
            if (chkconfig($this->CONFIG['phpui']['ewx_support'])) {
                $channels = $this->DB->GetAllByKey('SELECT nodeid, channelid, c.name, c.id, cid,
				        nc.upceil, nc.downceil
					FROM ewx_stm_nodes
					JOIN ewx_stm_channels nc ON (channelid = nc.id)
					LEFT JOIN ewx_channels c ON (c.id = nc.cid)
					WHERE nodeid IN (' . implode(',', array_keys($ids)) . ')', 'nodeid');
                if ($channels) {
                    foreach ($channels as $channel) {
                        $idx = $ids[$channel['nodeid']];
                        $result[$idx]['channelid'] = $channel['id'] ? $channel['id'] : $channel['channelid'];
                        $result[$idx]['channelname'] = $channel['name'];
                        $result[$idx]['cid'] = $channel['cid'];
                        $result[$idx]['downceil'] = $channel['downceil'];
                        $result[$idx]['upceil'] = $channel['upceil'];
                    }
                }
            }
        }
        return $result;
    }
Ejemplo n.º 6
0
    protected function customerNodesProvider($customer_id, $type = '', $count = null)
    {
        $type = strtolower($type);
        switch ($type) {
            case 'netdev':
                $type = 'nd.ownerid = ?';
                break;
            default:
                $type = 'n.ownerid = ?';
        }
        $result = $this->db->GetAll("SELECT\n                                        n.id, n.name, mac, ipaddr, inet_ntoa(ipaddr) AS ip, nd.name as netdev_name,\n                                        ipaddr_pub, n.authtype, inet_ntoa(ipaddr_pub) AS ip_pub,\n                                        passwd, access, warning, info, n.ownerid, lastonline, n.location,\n                                        (SELECT COUNT(*)\n                                        FROM nodegroupassignments\n                                        WHERE nodeid = n.id) AS gcount,\n                                        n.netid, net.name AS netname\n                                     FROM\n                                        vnodes n\n                                        JOIN networks net ON net.id = n.netid\n                                        LEFT JOIN netdevices nd ON n.netdev = nd.id\n                                     WHERE\n                                        " . $type . "\n                                     ORDER BY\n                                        n.name ASC " . ($count ? 'LIMIT ' . $count : ''), array($customer_id));
        if ($result) {
            // assign network(s) to node record
            $network_manager = new LMSNetworkManager($this->db, $this->auth, $this->cache);
            $networks = (array) $network_manager->GetNetworks();
            foreach ($result as $idx => $node) {
                $ids[$node['id']] = $idx;
                $result[$idx]['lastonlinedate'] = lastonline_date($node['lastonline']);
                if ($node['ipaddr_pub']) {
                    foreach ($networks as $net) {
                        if (isipin($node['ip_pub'], $net['address'], $net['mask'])) {
                            $result[$idx]['network_pub'] = $net;
                            break;
                        }
                    }
                }
            }
            // get EtherWerX channels
            if (ConfigHelper::checkValue(ConfigHelper::getConfig('phpui.ewx_support', false))) {
                $channels = $this->db->GetAllByKey('SELECT nodeid, channelid, c.name, c.id, cid,
				        nc.upceil, nc.downceil
			 		FROM ewx_stm_nodes
					JOIN ewx_stm_channels nc ON (channelid = nc.id)
					LEFT JOIN ewx_channels c ON (c.id = nc.cid)
					WHERE nodeid IN (' . implode(',', array_keys($ids)) . ')', 'nodeid');
                if ($channels) {
                    foreach ($channels as $channel) {
                        $idx = $ids[$channel['nodeid']];
                        $result[$idx]['channelid'] = $channel['id'] ? $channel['id'] : $channel['channelid'];
                        $result[$idx]['channelname'] = $channel['name'];
                        $result[$idx]['cid'] = $channel['cid'];
                        $result[$idx]['downceil'] = $channel['downceil'];
                        $result[$idx]['upceil'] = $channel['upceil'];
                    }
                }
            }
        }
        return $result;
    }