Exemple #1
0
 public function action_set()
 {
     if ($_POST) {
         /*
         			'eid':eid,
         			'num':num,
         			'did':CACTI.did,
         			'sour':$('#cacti_source').val(),
         			'graph':$('#cacti_graph').val()
         */
         $this->user = \Sentry::user()->get('id');
         $val = \Validation::forge();
         $val->add_field('eid', 'Action', 'required|min_length[1]|max_length[20]');
         $val->add_field('did', 'Action', 'required|min_length[1]|max_length[20]');
         $val->add_field('sour', 'Value', 'required|min_length[1]');
         $val->add_field('graph', 'Value', 'required|min_length[1]|max_length[200]');
         $val->add_field('num', 'Value', 'required|max_length[200]');
         $val->add_field('type', 'Value', 'required|max_length[200]');
         $val->add_field('name', 'Value', 'required|max_length[200]');
         if ($val->run()) {
             if ($val->validated('type') == 'custom') {
                 $cacti = Model_Cacti::find($val->validated('eid'));
                 if (!$cacti) {
                     $query = array('sourceID' => $val->validated('sour'), 'name' => $val->validated('name'), 'num' => '0', 'macID' => '0', 'graphID' => $val->validated('graph'), 'meta_update_time' => time(), 'meta_update_user' => $this->user, 'deviceID' => $val->validated('did'));
                     $cacti = new Model_Cacti($query);
                 } else {
                     $cacti->sourceID = $val->validated('sour');
                     $cacti->graphID = $val->validated('graph');
                     $cacti->meta_update_time = time();
                     $cacti->name = $val->validated('name');
                 }
                 $cacti->save();
             } elseif ($val->validated('type') == 'port') {
                 $mac = \Basic\Model_Network_Mac::find($val->validated('eid'));
                 $cacti = Model_Cacti::find()->where('macID', $mac->id)->get_one();
                 if (!$cacti) {
                     $query = array('sourceID' => $val->validated('sour'), 'name' => $val->validated('name'), 'num' => $val->validated('num'), 'macID' => $val->validated('eid'), 'graphID' => $val->validated('graph'), 'meta_update_time' => time(), 'meta_update_user' => $this->user, 'deviceID' => $val->validated('did'));
                     $cacti = new Model_Cacti($query);
                 } else {
                     $cacti->sourceID = $val->validated('sour');
                     $cacti->graphID = $val->validated('graph');
                     $cacti->meta_update_time = time();
                 }
                 $cacti->save();
             }
             echo json_encode(array('id' => $cacti->id, 'name' => $cacti->name, 's' => $cacti->sourceID, 'g' => $cacti->graphID));
         }
     }
 }
Exemple #2
0
 private function getDevicePort($dev, $num, $type)
 {
     $network = \Basic\Model_Device_Network::find()->where('deviceID', $dev->id)->get_one();
     //echo $network->id;
     switch ($dev->cat) {
         case 2:
             //switch
         //switch
         case 8:
             //FC switch
         //FC switch
         case 3:
             //router
             $ports = \Basic\Model_Network_Mac::find()->where('networkID', $network->id)->offset($num - 1)->get_one();
             break;
         case 5:
             $ext = array();
             $int = array();
             $ports = new \stdClass();
             // get all device ports
             $ps = \Basic\Model_Network_Mac::find()->where('networkID', $network->id)->get();
             // split utp and patch ports
             foreach ($ps as $port) {
                 if ($port->type == 3) {
                     array_push($ext, $port->id);
                 }
                 if ($port->type == 1) {
                     array_push($int, $port->id);
                 }
             }
             if ($type == 4) {
                 $ports->id = $ext[$num - 1];
             }
             if ($type == 1) {
                 $ports->id = $int[$num - 1];
             }
             break;
         default:
             $ports = \Basic\Model_Network_Ip::find()->where('networkID', $network->id)->offset($num - 1)->get_one();
             break;
     }
     return $ports->id;
 }