public function saveAction()
 {
     if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) {
         try {
             foreach ($data as $key) {
                 $certificate = new Push_Model_Certificate();
                 $certificate->find($key["name"], "type");
                 if (!$certificate->getId()) {
                     $certificate->setType($key["name"]);
                 }
                 $certificate->setPath($key["value"])->save();
             }
             $data = array("success" => 1, "message" => $this->_("Keys successfully saved"));
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }
 public function saveAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             if (empty($datas['type'])) {
                 throw new Exception('An error occurred during process. Please try again later.');
             }
             if (empty($datas['path'])) {
                 $datas['path'] = null;
             }
             $certificat = new Push_Model_Certificate();
             $certificat->find($datas['type'], 'type');
             if (!$certificat->getId()) {
                 $certificat->setType($datas['type']);
             }
             $certificat->setPath($datas['path'])->save();
             $html = array('success' => '1', 'success_message' => $this->_('Info successfully saved'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }
 public function uploadAction()
 {
     if (!empty($_FILES)) {
         try {
             $path = '/var/apps/iphone/certificates/';
             $base_path = Core_Model_Directory::getBasePathTo($path);
             $filename = uniqid() . '.pem';
             $app_id = $this->getRequest()->getParam('app_id');
             if (!is_dir($base_path)) {
                 mkdir($base_path, 0775, true);
             }
             $adapter = new Zend_File_Transfer_Adapter_Http();
             $adapter->setDestination($base_path);
             $adapter->setValidators(array('Extension' => array('pem', 'case' => false)));
             $adapter->getValidator('Extension')->setMessages(array('fileExtensionFalse' => $this->_("Extension not allowed, \\'%s\\' only", '%extension%')));
             $files = $adapter->getFileInfo();
             foreach ($files as $file => $info) {
                 if (!$adapter->isUploaded($file)) {
                     throw new Exception($this->_('An error occurred during process. Please try again later.'));
                 } else {
                     if (!$adapter->isValid($file)) {
                         if (count($adapter->getMessages()) == 1) {
                             $erreur_message = $this->_('Error : <br/>');
                         } else {
                             $erreur_message = $this->_('Errors : <br/>');
                         }
                         foreach ($adapter->getMessages() as $message) {
                             $erreur_message .= '- ' . $message . '<br/>';
                         }
                         throw new Exception($erreur_message);
                     } else {
                         $adapter->addFilter(new Zend_Filter_File_Rename(array('target' => $base_path . $filename, 'overwrite' => true)));
                         $adapter->receive($file);
                     }
                 }
             }
             $certificat = new Push_Model_Certificate();
             $certificat->find(array('type' => 'ios', 'app_id' => $app_id));
             if (!$certificat->getId()) {
                 $certificat->setType('ios')->setAppId($app_id);
             }
             $certificat->setPath($path . $filename)->save();
             $datas = array('success' => 1, 'files' => 'eeeee', 'message_success' => $this->_('Info successfully saved'), 'message_button' => 0, 'message_timeout' => 2);
         } catch (Exception $e) {
             $datas = array('error' => 1, 'message' => $e->getMessage());
         }
         $this->getLayout()->setHtml(Zend_Json::encode($datas));
     }
 }
Exemplo n.º 4
0
 public function uploadcertificateAction()
 {
     if ($app_id = $this->getRequest()->getParam("app_id")) {
         try {
             if (empty($_FILES) || empty($_FILES['file']['name'])) {
                 throw new Exception("No file has been sent");
             }
             $application = new Application_Model_Application();
             $application->find($app_id);
             $base_path = Core_Model_Directory::getBasePathTo("var/apps/iphone/");
             $path = Core_Model_Directory::getPathTo("var/apps/iphone/");
             $adapter = new Zend_File_Transfer_Adapter_Http();
             $adapter->setDestination(Core_Model_Directory::getTmpDirectory(true));
             if ($adapter->receive()) {
                 $file = $adapter->getFileInfo();
                 $certificat = new Push_Model_Certificate();
                 $certificat->find(array('type' => 'ios', 'app_id' => $app_id));
                 if (!$certificat->getId()) {
                     $certificat->setType("ios")->setAppId($app_id);
                 }
                 $new_name = uniqid("cert_") . ".pem";
                 if (!rename($file["file"]["tmp_name"], $base_path . $new_name)) {
                     throw new Exception($this->_("An error occurred while saving. Please try again later."));
                 }
                 $certificat->setPath($path . $new_name)->save();
                 $data = array("success" => 1, "message" => $this->_("The file has been successfully uploaded"));
             } else {
                 $messages = $adapter->getMessages();
                 if (!empty($messages)) {
                     $message = implode("\n", $messages);
                 } else {
                     $message = $this->_("An error occurred during the process. Please try again later.");
                 }
                 throw new Exception($message);
             }
         } catch (Exception $e) {
             $data = array("error" => 1, "message" => $e->getMessage());
         }
         $this->_sendHtml($data);
     }
 }