コード例 #1
0
ファイル: update.php プロジェクト: quickpacket/noclayer
 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'))));
         }
     }
 }
コード例 #2
0
ファイル: get.php プロジェクト: quickpacket/noclayer
 public function action_munin()
 {
     $out = array('status' => 'no', 'list' => array('data' => array(), 'id' => ''));
     $val = \Validation::forge();
     $val->add_field('did', 'node id', 'required|min_length[1]|max_length[20]');
     if ($val->run()) {
         $mundata = Model_Munin::query()->where('deviceID', $val->validated('did'))->get_one();
         if ($mundata) {
             $auth = $mundata->pass != '' ? 1 : 0;
             $munin = new \Munin($mundata->url, $auth);
             if ($auth > 0) {
                 $munin->authentication($mundata->user, $mundata->pass);
             }
             $list = $munin->graph_list();
             $out['status'] = 'ok';
             $out['list']['data'] = $list;
             $out['list']['id'] = $val->validated('did');
         }
         echo json_encode($out);
     }
 }
コード例 #3
0
ファイル: test.php プロジェクト: quickpacket/noclayer
 public function action_index()
 {
     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('auth', 'Value', 'max_length[200]');
         if ($val->run()) {
             //cacti
             if ($val->validated('type') == 1) {
                 $cacti = new \Cacti($val->validated('url'));
                 $code = $cacti->testConnection($val->validated('usr'), $val->validated('pwd'));
             }
             //munin
             if ($val->validated('type') == 2) {
                 $munin = new \Munin($val->validated('url'), $val->validated('auth'));
                 $code = $munin->testConnection($val->validated('usr'), $val->validated('pwd'));
             }
             echo json_encode(array('code' => $code));
         }
     }
 }