Exemple #1
0
 public function action_data()
 {
     if ($_POST) {
         $val = \Validation::forge();
         $val->add_field('type', 'type ', 'required|min_length[1]|max_length[20]');
         $val->add_field('val', 'val ', 'required|min_length[1]|max_length[20]');
         if ($val->run()) {
             $data = Model_Data::find()->where('name', $val->validated('type'))->get_one();
             if ($data) {
                 $data->value = $val->validated('val');
                 $data->save();
             }
         }
     }
     echo json_encode(array('stat' => 'ok'));
 }
Exemple #2
0
 public function action_index()
 {
     $sources = Model_Source::find()->where('meta_update_user', $this->user)->get();
     $out = array('sources' => array(), 'data' => array(), 'munin' => array());
     foreach ($sources as $source) {
         $type = Model_Type::find($source->typeID);
         array_push($out['sources'], array('id' => $source['id'], 'type' => array('id' => $source->typeID, 'name' => $type->name), 'content' => $source['content']));
     }
     $data = Model_Data::find()->where('meta_update_user', $this->user)->get();
     foreach ($data as $d) {
         array_push($out['data'], array('value' => $d->value, 'name' => $d->name));
     }
     $munins = Model_Munin::find('all');
     foreach ($munins as $munin) {
         $device = $munin->device;
         array_push($out['munin'], array('id' => $munin->deviceID, 'url' => $munin->url, 'host' => $device->hostname));
     }
     echo json_encode($out);
 }