Esempio n. 1
0
 public function action_edit()
 {
     if ($_POST) {
         $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('eid', 'Value', 'max_length[200]');
         if ($val->run()) {
             // add munin later...
             $cacti = new \Cacti($val->validated('url'));
             $code = $cacti->testConnection($val->validated('usr'), $val->validated('pwd'));
             if ($code == 200) {
                 $graph = Model_Source::find($val->validated('eid'));
                 if ($graph) {
                     //$graph->'typeID'=>$val->validated('type');
                     $graph->user = $val->validated('usr');
                     $graph->pass = $val->validated('pwd');
                     $graph->content = $val->validated('url');
                     $graph->meta_update_time = time();
                     //'meta_update_user'=>$this->user
                     //);
                     //$source=new Model_Graphing_Source($q);
                     $graph->save();
                     $code = 'ok';
                 } else {
                     $code = 'no';
                 }
             }
             echo json_encode(array('code' => $code, 'data' => array('name' => 'Cacti', 'content' => $val->validated('url'))));
         }
     }
 }