コード例 #1
0
ファイル: observer.php プロジェクト: quickpacket/noclayer
 public static function Device($model, $method)
 {
     if ($method == 'before_update') {
         //\Log::debug('device update'.$model->hostname);
         $old_data = \DB::select('rack', 'rack_pos')->from('device')->where('id', $model->id)->as_object()->execute();
         if (count($old_data) > 0) {
             $rack = $old_data[0]->rack;
             $pos = $old_data[0]->rack_pos;
             if ($rack != $model->rack or $pos != $model->rack_pos) {
                 \Log::debug('device update' . $model->hostname);
                 $network = $model->network;
                 foreach ($network as $net) {
                     $ips = \Basic\Model_Network_Ip::find()->where('networkID', $net->id)->get();
                     foreach ($ips as $ip) {
                         // \Log::debug('ip::'.print_r($ip,true));
                         $sub = \Ipm\Model_Subnet::find()->where('range_from', '<=', $ip->addrint)->where('range_to', '>=', $ip->addrint)->get_one();
                         if ($sub) {
                             \Ipm\Observer::IsValidLocation($sub, $model, $ip);
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: history.php プロジェクト: quickpacket/noclayer
 public function get_ip_history($node, $array = false)
 {
     $this->subArray = array();
     //get usage from all
     if ($node == 'all') {
         $ips = Model_History::find()->order_by('time', 'desc')->limit(1000)->get();
         foreach ($ips as $ip) {
             $device = $ip->dev;
             $sub = \Ipm\Model_Subnet::find()->where('range_from', '<=', $ip->ip_int)->where('range_to', '>=', $ip->ip_int)->get_one();
             $erased = $sub ? 0 : 1;
             if ($ip->device > 0) {
                 $erased = 0;
             }
             // 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' => $erased)));
         }
     } else {
         $this->populate_hist_nodes($node);
     }
     $out = array('history' => $this->subArray);
     if ($array) {
         return $out;
     } else {
         echo json_encode($out);
     }
 }
コード例 #3
0
ファイル: 003_vpsset.php プロジェクト: quickpacket/noclayer
 private function updateSubnet($ip)
 {
     $ip_int = $this->___IPv4_dotquadA_to_intA($ip);
     $sub = \Ipm\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 \Ipm\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 \Ipm\Model_Subnet($data);
         $sub->save();
         return $sub;
     }
 }
コード例 #4
0
ファイル: main.php プロジェクト: quickpacket/noclayer
[
<?php 
$data = array();
foreach ($nodes as $node) {
    $subs = \Ipm\Model_Node::find()->where('parent', $node->id)->count();
    $subs += \Ipm\Model_Subnet::find()->where('parent', $node->id)->count();
    $b = array('attr' => array('id' => 'node_' . $node->id, 'rel' => 'node'), 'data' => $node->name, 'state' => $subs == 0 ? '' : 'closed');
    array_push($data, $b);
}
echo json_encode($data);
?>
]
コード例 #5
0
ファイル: update.php プロジェクト: quickpacket/noclayer
 public function action_index()
 {
     $val = \Validation::forge('data');
     $val->add_field('name', 'subnet name', 'required|min_length[1]|max_length[50]');
     $val->add_field('old', 'subnet old name', 'required|min_length[1]|max_length[50]');
     if ($val->run()) {
         $out = array();
         if ($this->type >= 0) {
             $sub = \Ipm\Model_Subnet::find()->where('subnet', $val->validated('old'))->get_one();
             $ip = new Ipv4($val->validated('name'));
             /***
              * '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('old'));
                 
                  $ip2= 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));
                 }
                 
             }
             */
         }
     }
 }
コード例 #6
0
ファイル: get.php プロジェクト: quickpacket/noclayer
 public function action_index()
 {
     $this->limit = 30;
     $this->out = array('data' => array(), 'total' => 0, 'from' => 0, 'limit' => $this->limit);
     if ($this->id) {
         $val2 = \Validation::forge('data');
         $val2->add_field('from', 'from', 'required|min_length[1]|max_length[50]');
         $val2->add_field('type', 'type', 'required|min_length[1]|max_length[50]');
         if ($val2->run()) {
             $this->offset = (int) $val2->validated('from') * $this->limit;
             $this->out['from'] = (int) $val2->validated('from');
             switch ($val2->validated('type')) {
                 case 0:
                     //get all devices
                     $devices = \DB::select()->from('device')->as_object()->execute();
                     $res = \DB::select()->from('device')->execute();
                     $this->out['total'] = count($res);
                     $this->devices($devices, false);
                     break;
                 case 1:
                 case 2:
                     //get subnodes
                     $devices = $this->get_ip_usage($this->id, true);
                     //print_r($devices);
                     $this->out['total'] = count($devices);
                     //make limit offset
                     $this->devices($devices);
                     break;
                 case 3:
                     $this->subArray = array();
                     $sub = \Ipm\Model_Subnet::find($this->id);
                     $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);
                         }
                     }
                     $this->out['total'] = count($this->subArray);
                     $this->devices($this->subArray);
                     break;
             }
         }
         echo json_encode($this->out);
     }
 }