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)); } } }
public function action_mac() { if ($_POST) { $val = \Validation::forge(); $val->add_field('did', 'node id', 'required|min_length[1]|max_length[20]'); if ($val->run()) { $out = array('sources' => array(), 'mac' => array(), 'custom' => array()); $device = \Basic\Model_Device::find($val->validated('did')); $source = Model_Source::find()->where('typeID', 1)->get(); $sources = array(); foreach ($source as $s) { array_push($sources, array('id' => $s->id, 'url' => $s->content)); } $out['sources'] = $sources; foreach ($device->network as $network) { foreach ($network->mac as $mac) { $cacti = Model_Cacti::find()->where('macID', $mac->id)->get_one(); /* TODO: dodati extend u cacti modelu 'graph' => array( 'key_from' => 'id', 'model_to' => '\Graphing\Model_Cacti', 'key_to' => 'macID', 'cascade_save' => false, 'cascade_delete' => false, ) */ if ($cacti) { array_push($out['mac'], array('id' => $mac->id, 'type' => $mac->type, 'cacti' => array('id' => $cacti->id, 'name' => $cacti->name, 'graph' => $cacti->graphID, 's' => $cacti->sourceID))); } else { array_push($out['mac'], array('id' => $mac->id, 'type' => $mac->type, 'cacti' => array())); } } } $customs = Model_Cacti::find()->where('deviceID', $device->id)->where('macID', 0)->get(); foreach ($customs as $cacti) { array_push($out['custom'], array('id' => $cacti->id, 'name' => $cacti->name, 'graph' => $cacti->graphID, 's' => $cacti->sourceID)); } echo json_encode($out); } } }