Пример #1
0
 public function get_used($subnet, $count = false)
 {
     $ipv4 = new Ipv4($subnet);
     $data = $ipv4->get();
     $query = \Basic\Model_Network_Ip::find()->where('addrint', '>=', 1)->where('addrint', '>=', $data['from'])->where('addrint', '<=', $data['to'])->order_by('addrint', 'asc');
     if ($count) {
         return $query->count();
     }
     return $query->get();
 }
Пример #2
0
    public function action_index()
    {
        $val = \Validation::forge('data');
        $val->add_field('name', 'subnet name', 'required|min_length[1]|max_length[50]');
        if ($val->run()) {
            $out = array();
            if ($this->type >= 0) {
                /***
                 * 'subnet'=>$this->_subnet,
                            'mask'=>$this->_maskbit,
                            'from'=>$this->_intAddrFrom,
                            'to'=>$this->_intAddrTo,
                            'hosts'=>$this->_numberOfHosts,
                            'network'=>$this->_network
                 */
                if ($this->type == 2 or $this->type == 1) {
                    $ip = new Ipv4($val->validated('name'));
                    $ipdata = $ip->get();
                    //check if subnet already exist
                    //$sub=  Model_Subnet::find()->where('range_from','<',$ip['from'])->where('range_from','<',$ip[''])->get();
                    $from = $ipdata['from'];
                    $to = $ipdata['to'];
                    $query = \DB::query('select * from ipm_subnet where 
                    (range_from>=' . $from . ' and range_from<=' . $to . ') 
                    or 
                    (range_to>=' . $from . ' and range_to<=' . $to . ') 
                    or
                    (range_from>=' . $from . ' and range_to<=' . $to . ') 
                    
');
                    $sub = $query->execute();
                    $m = false;
                    foreach ($sub as $s) {
                        $error = $s;
                        $m = true;
                    }
                    if (!$m) {
                        $data = array('subnet' => $ipdata['subnet'], 'alias' => '', 'description' => '', 'size' => $ipdata['hosts'], 'mask' => $ipdata['mask'], 'type' => 0, 'vlan' => 0, 'parent' => $this->id, 'meta_update_user' => $this->user, 'range_from' => $ipdata['from'], 'range_to' => $ipdata['to']);
                        $sub = new Model_Subnet($data);
                        $sub->save();
                        $data = $this->get_ip_usage($this->id, true);
                        echo json_encode(array('id' => $sub->id, 'subnet' => $sub->subnet, 'status' => 'valid', 'data' => $data));
                    } else {
                        echo json_encode(array('status' => 'taken', 'err' => $error));
                    }
                }
            }
        }
    }
Пример #3
0
 private function updateSubnet($ip)
 {
     $ip_int = $this->___IPv4_dotquadA_to_intA($ip);
     $sub = Model_Subnet::find()->where('range_from', '<=', $ip_int)->where('range_to', '>=', $ip_int)->get_one();
     if ($sub) {
         return $sub;
     } else {
         $newsub = $this->c_class_from_Ipv4($ip);
         $ip_ob = new Ipv4($newsub);
         $ipdata = $ip_ob->get();
         $data = array('subnet' => $ipdata['subnet'], 'alias' => '', 'description' => '', 'size' => $ipdata['hosts'], 'mask' => $ipdata['mask'], 'type' => 0, 'vlan' => 0, 'parent' => $this->defualtNode(), 'meta_update_user' => 1, 'range_from' => $ipdata['from'], 'range_to' => $ipdata['to']);
         $sub = new Model_Subnet($data);
         $sub->save();
         return $sub;
         /*
          'subnet'=>$this->_subnet,
          'mask'=>$this->_maskbit,
          'from'=>$this->_intAddrFrom,
          'to'=>$this->_intAddrTo,
          'hosts'=>$this->_numberOfHosts,
          'network'=>$this->_network
         */
     }
 }
Пример #4
0
 /**
  * @param string $value
  * @param int    $port
  *
  * @return $this
  * @throws \InvalidArgumentException
  */
 public function add($value, $port = null)
 {
     if ($value == "*") {
         $this->_values[] = "*";
         return $this;
     }
     if (Ipv4::test($value)) {
         $this->_values[] = new Ipv4($value, $port);
         return $this;
     }
     if (Ipv6::test($value)) {
         $this->_values[] = new Ipv6($value, $port);
         return $this;
     }
     throw new \InvalidArgumentException("{$value} is invalid address");
 }
Пример #5
0
 /**
  * Does the substraction of this address with the given address. Each byte
  * substracts up separately with remainteds. No adderss may substract lower
  * than the 0.0.0.0 address.
  * 
  * @param Ipv4 $other
  * @return Ipv4 the result
  */
 public function substract(Ipv4 $other)
 {
     $new1 = $other->_not();
     $new2 = $this->add($new1);
     return $new2->add(new Ipv4(array(0, 0, 0, 1)));
 }
Пример #6
0
 /**
  * Gets whether given ipv4 is included in this network.
  * 
  * @param Ipv4 $address
  * @return boolean
  */
 public function contains(Ipv4 $address)
 {
     return $address->_and($this->getNetmaskIp())->equals($this->getNetworkIp());
 }