public function action_index() { if ($_POST) { $dev = ''; $val = \Validation::forge(); $val->add_field('type', 'Action', 'required|min_length[1]|max_length[20]'); $val->add_field('url', 'Value', 'required|min_length[1]'); $val->add_field('usr', 'Value', 'max_length[200]'); $val->add_field('pwd', 'Value', 'max_length[200]'); $val->add_field('auth', 'Value', 'max_length[200]'); $val->add_field('dev', 'Value', 'max_length[200]'); $id = false; if ($val->run()) { switch ($val->validated('type')) { case 1: $name = 'Cacti'; $cacti = new \Cacti($val->validated('url')); //$cacti->authentication(); $code = $cacti->testConnection($val->validated('usr'), $val->validated('pwd')); if ($code == 200) { $graph = Model_Source::find()->where('content', $val->validated('url'))->where('meta_update_user', $this->user)->get_one(); if (!$graph) { $q = array('typeID' => $val->validated('type'), 'user' => $val->validated('usr'), 'pass' => $val->validated('pwd'), 'content' => $val->validated('url'), 'meta_update_time' => time(), 'meta_update_user' => $this->user); $source = new Model_Source($q); $source->save(); $id = $source->id; $code = 'ok'; } else { $code = 'no'; } } break; case 2: $name = 'Munin'; $munin = new \Munin($val->validated('url'), $val->validated('auth')); $code = $munin->testConnection($val->validated('usr'), $val->validated('pwd')); if ($code == 200) { $graph = Model_Munin::query()->where('deviceID', $val->validated('dev'))->where('meta_update_user', $this->user)->get_one(); if ($graph) { $graph->user = $val->validated('usr'); $graph->pass = $val->validated('pwd'); $graph->url = $val->validated('url'); $graph->save(); $dev = $val->validated('dev'); $id = $graph->id; $code = 'ok'; } else { $code = 'no'; } } break; } echo json_encode(array('code' => $code, 'data' => array('id' => $id, 'dev' => $dev, 'name' => $name, 'content' => $val->validated('url')))); } } }
public function action_index() { if ($_POST) { $val = \Validation::forge(); $val->add_field('id', 'Action', 'required|min_length[1]|max_length[20]'); $val->add_field('action', 'Value', 'required|min_length[1]|max_length[20]'); if ($val->run()) { $source = Model_Source::find($val->validated('id')); if ($val->validated('action') == 'get') { $type = Model_Type::find($source->typeID); $out = array('id' => $source['id'], 'type' => array('id' => $source->typeID, 'name' => $type->name), 'user' => $source['user'], 'pass' => $source['pass'], 'content' => $source['content']); } if ($val->validated('action') == 'remove') { } echo json_encode(array('source' => $out)); } } }
public function action_get($sourceID = null, $id = null, $size, $rd) { ob_start(); $source = Model_Source::find($sourceID); if ($source) { $cacti = new \Cacti($source->content); $code = $cacti->authentication($source->user, $source->pass); if ($code == 200) { $graph = $cacti->graph($id, $size, $rd); ob_end_clean(); header('Content-Type: image/png'); echo $graph['ret']; //$this->resize($graph['ret'],$size); // // //echo ; } } // }
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); } } }