コード例 #1
0
ファイル: add.php プロジェクト: quickpacket/noclayer
    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));
                    }
                }
            }
        }
    }
コード例 #2
0
ファイル: location.php プロジェクト: quickpacket/noclayer
 public function getParentData($node)
 {
     $result = array();
     $subnets = Model_Subnet::find()->where('parent', $node)->get();
     foreach ($subnets as $sub) {
         $m = $this->getData($sub->id);
         if (count($m) > 0) {
             $result = array_merge($result, $m);
         }
     }
     return $result;
 }
コード例 #3
0
ファイル: test.php プロジェクト: quickpacket/noclayer
 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
ファイル: get.php プロジェクト: quickpacket/noclayer
 public function populate_nodes($node)
 {
     $nodes = Model_Node::find($node);
     $subnets = Model_Subnet::find()->where('parent', $nodes->id)->order_by('size', 'desc')->get();
     foreach ($subnets as $sub) {
         $ips = \Basic\Model_Network_Ip::find()->where('addrint', '>=', $sub->range_from)->where('addrint', '<=', $sub->range_to)->get();
         foreach ($ips as $ip) {
             $dev = $ip->network->device;
             if (!in_array($dev->id, $this->subArray)) {
                 array_push($this->subArray, $dev->id);
             }
         }
     }
     $subs = Model_Node::find()->where('parent', $nodes->id)->get();
     foreach ($subs as $sub) {
         $this->populate_nodes($sub->id);
     }
 }
コード例 #5
0
ファイル: subnet.php プロジェクト: quickpacket/noclayer
 public function get_ip_usage($node, $array = false)
 {
     $this->subArray = array();
     //get usage from all
     if ($node == 'all') {
         $subnets = Model_Subnet::find()->order_by('size', 'desc')->get();
         foreach ($subnets as $sub) {
             array_push($this->subArray, array('id' => $sub->id, 'subnet' => $sub->subnet, 'size' => $sub->size, 'used' => $this->get_used($sub->subnet, true), 'reserved' => '0'));
         }
     } else {
         $this->populate_nodes($node);
     }
     $out = array('subnets' => $this->subArray);
     if ($array) {
         return $out;
     } else {
         echo json_encode($out);
     }
 }
コード例 #6
0
ファイル: rem.php プロジェクト: quickpacket/noclayer
 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
              */
             $sub = Model_Subnet::find()->where('subnet', $val->validated('name'))->get_one();
             if ($sub) {
                 $sub->delete();
                 switch ($this->type) {
                     case 0:
                         //get all
                         $data = $this->get_ip_usage('all', true);
                         break;
                     case 1:
                     case 2:
                         //get subnodes
                         $data = $this->get_ip_usage($sub->parent, true);
                         break;
                         //subnets
                     //subnets
                     case 3:
                         $data = $this->get_ip_usage($sub->parent, true);
                         break;
                 }
                 $out = array('status' => 'ok', 'data' => $data);
             } else {
                 $out = array('status' => 'no');
             }
             echo json_encode($out);
         }
     }
 }
コード例 #7
0
ファイル: subnets.php プロジェクト: quickpacket/noclayer
 /**
  * 
  * Building tree
  */
 public function action_index()
 {
     if ($_POST) {
         $val = \Validation::forge();
         $val->add_field('id', 'node id', 'required|min_length[1]|max_length[20]');
         $val->add_field('rel', 'node type', 'required|min_length[1]|max_length[20]');
         if ($val->run()) {
             switch ($this->gettype($val->validated('rel'))) {
                 //root
                 case 0:
                     echo '[{"attr":{"id":"main_1","rel":"main"},"data":"My company","state":"closed"}]';
                     break;
                     //main
                 //main
                 case 1:
                     $data['nodes'] = Model_Node::find()->where('parent', 0)->get();
                     return \Response::forge(\View::forge('nodes/main', $data));
                     break;
                     //submain
                 //submain
                 case 2:
                     $data['nodes'] = Model_Node::find()->where('parent', $val->validated('id'))->get();
                     $data['subnets'] = Model_Subnet::find()->where('parent', $val->validated('id'))->get();
                     return \Response::forge(\View::forge('nodes/subnode', $data));
                     break;
                     //subnets
                 //subnets
                 case 3:
                     $data['subnets'] = Model_Subnet::find()->where('parent', $val->validated('id'))->get();
                     return \Response::forge(\View::forge('nodes/subnet', $data));
                     break;
                     //subnet
                 //subnet
                 case 3:
                     echo '{:P}';
                     break;
             }
             //echo $val->validated('id');
         }
     }
 }
コード例 #8
0
ファイル: history.php プロジェクト: quickpacket/noclayer
 public function action_index()
 {
     if ($this->type >= 0) {
         switch ($this->type) {
             default:
                 echo json_encode(array('nop' => 'ok'));
                 break;
                 break;
             case 0:
                 //get all
                 $this->get_ip_history('all');
                 break;
             case 1:
             case 2:
                 //get subnodes
                 $this->get_ip_history($this->id);
                 break;
                 //subnets
             //subnets
             case 3:
                 $sub = Model_Subnet::find($this->id);
                 $this->subArray = array();
                 if ($sub) {
                     $from_pos = $sub['range_from'];
                     $to_pos = $sub['range_to'];
                     $ips = Model_History::find()->where('ip_int', '>=', $from_pos)->where('ip_int', '<=', $to_pos)->get();
                     foreach ($ips as $ip) {
                         $device = $ip->dev;
                         // print_r($device);
                         array_push($this->subArray, array('id' => $ip->id, 'ip' => $ip->ip_dotted, 'date' => date('d/m/Y H:i:s', $ip->time), 'device' => array('id' => $ip->device, 'name' => $ip->devname, 'erased' => 0)));
                     }
                 }
                 $out = array('history' => $this->subArray);
                 echo json_encode($out);
                 break;
                 //reserved ip-s
         }
     }
 }
コード例 #9
0
ファイル: get.php プロジェクト: quickpacket/noclayer
 public function action_index()
 {
     if ($this->type >= 0) {
         switch ($this->type) {
             default:
                 echo json_encode(array('nop' => 'ok'));
                 break;
                 break;
             case 0:
                 //get all
                 $this->get_ip_usage('all');
                 break;
             case 1:
             case 2:
                 //get subnodes
                 $this->get_ip_usage($this->id);
                 break;
                 //subnets
             //subnets
             case 3:
                 $this->subnet = Model_Subnet::find($this->id);
                 if ($this->subnet) {
                     $used = $this->get_used($this->subnet['subnet']);
                     $parent = Model_Node::find($this->subnet->parent);
                     $ip_used = array();
                     foreach ($used as $ip) {
                         $device = $ip->network->device;
                         array_push($ip_used, array('id' => $ip['id'], 'ip' => $ip['ipv4'], 'device' => $device->hostname, 'did' => $device->id, 'vps' => $this->isVPS($ip)));
                     }
                     echo json_encode(array('used' => $ip_used, 'parent' => $parent['name']));
                 }
                 break;
                 //reserved ip-s
         }
     }
 }