コード例 #1
0
ファイル: MiniDLNA.php プロジェクト: BillTheBest/MetaNAS
 public function stop()
 {
     $em = Zend_Registry::get('em');
     $minidlna = $em->getRepository('Entity\\MiniDLNA')->findAll();
     if (count($minidlna) != 0) {
         $minidlna = $minidlna[0];
         $minidlna->setEnabled(false);
     } else {
         $minidlna = new Entity\MiniDLNA();
         $minidlna->setEnabled(false);
     }
     try {
         $this->writeConf($minidlna);
         $em->persist($minidlna);
         $em->flush();
     } catch (Exception $e) {
     }
     $desc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "STDOUT"));
     $proc = proc_open($this->CONTROL . " onestop", $desc, $pipes);
     $stdout = stream_get_contents($pipes[1]);
     $retval = proc_close($proc);
     return $stdout;
 }
コード例 #2
0
 public function editAction()
 {
     $em = Zend_Registry::get('em');
     $minidlna = $em->getRepository('Entity\\MiniDLNA')->findAll();
     if (count($minidlna) != 0) {
         $minidlna = $minidlna[0];
     } else {
         $minidlna = new Entity\MiniDLNA();
     }
     $form = new MetaNAS_Form_Edit();
     $jail = Tivoka::createRequest('1', 'plugins.jail.info');
     $this->lib->getRpc()->send($jail);
     $jail = json_decode($jail->result);
     $form->media_dir->setAttrib('root', $jail[0]->fields->jail_path . '/' . $jail[0]->fields->jail_name);
     if ($this->getRequest()->isPost()) {
         $this->_helper->viewRenderer->setNoRender(TRUE);
         $this->getResponse()->setHeader('Content-type', 'application/json');
         if ($form->isValid($_POST)) {
             $values = $form->getValues();
             $minidlna->setMediaDir($values['media_dir']);
             if (isset($values['inotify'])) {
                 $minidlna->setInotify($values['inotify']);
             }
             $minidlna->setNotifyInterval($values['notify_interval']);
             $minidlna->setFriendlyName($values['friendly_name']);
             if (isset($values['tivo'])) {
                 $minidlna->setTivo($values['tivo']);
             }
             $minidlna->setRescan($values['rescan']);
             $minidlna->setStrictDLNA($values['strict_dlna']);
             $minidlna->setModelNumber($values['model_number']);
             $minidlna->setSerial($values['serial']);
             $minidlna->setAuxiliary($values['auxiliary']);
             $em->persist($minidlna);
             $em->flush();
             $this->lib->writeConf($minidlna);
             echo json_encode(array('error' => false, 'message' => 'Settings successfully updated'));
         } else {
             /*
              * This is an internal API of the MetaNAS GUI
              *
              * The JSON returned in case of form validation error must
              * return the following object:
              * {
              * 'error': true,
              * 'type': 'form',
              * 'formid': 'formid', // Id of the dijit form
              * 'errors': {   // Array of errors with fieldnames as keys
              *  'fieldname': ['error 1', 'error 2'],
              *   }
              * }
              */
             $data = array('error' => true, 'type' => 'form', 'formid' => $_POST['__form_id']);
             $errors = array();
             foreach ($form->getMessages() as $field => $val) {
                 $errors[$field] = array();
                 foreach ($val as $error => $msg) {
                     $errors[$field][] = $msg;
                 }
             }
             $data['errors'] = $errors;
             echo json_encode($data);
         }
     } else {
         $form->media_dir->setValue($minidlna->getMediaDir());
         $form->port->setValue($minidlna->getPort());
         $form->inotify->setValue($minidlna->getInotify());
         $form->notify_interval->setValue($minidlna->getNotifyInterval());
         $form->friendly_name->setValue($minidlna->getFriendlyName());
         $form->tivo->setValue($minidlna->getTivo());
         $form->strict_dlna->setValue($minidlna->getStrictDLNA());
         $form->model_number->setValue($minidlna->getModelNumber());
         $form->serial->setValue($minidlna->getSerial());
         $form->auxiliary->setValue($minidlna->getAuxiliary());
         $form->rescan->setValue($minidlna->getRescan());
         $this->view->form = $form;
     }
 }