public function uploadAction() { if ($code = $this->getRequest()->getPost("code")) { try { if (empty($_FILES) || empty($_FILES['file']['name'])) { throw new Exception("No file has been sent"); } $path = Core_Model_Directory::getPathTo(System_Model_Config::IMAGE_PATH); $base_path = Core_Model_Directory::getBasePathTo(System_Model_Config::IMAGE_PATH); if (!is_dir($base_path)) { mkdir($base_path, 0777, true); } $adapter = new Zend_File_Transfer_Adapter_Http(); $adapter->setDestination($base_path); if ($adapter->receive()) { $file = $adapter->getFileInfo(); $config = new System_Model_Config(); $config->find($code, "code"); $config->setValue($path . DS . $file['file']['name'])->save(); $message = sprintf("Your %s has been successfully saved", $code); $this->_sendHtml(array("success" => 1, "message" => $this->_($message))); } 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()); } } }
protected function _save($data) { foreach ($data as $code => $values) { if (!in_array($code, $this->_codes)) { continue; } if ($code == "favicon") { continue; } $config = new System_Model_Config(); $config->find($code, "code"); $config->setValue($values["value"])->save(); } return $this; }
public function apkisgeneratedAction() { $appName = $this->getRequest()->getParam('app_name'); $apk_base_path = Core_Model_Directory::getBasePathTo("var/tmp/applications/android/{$appName}/Siberian/app/build/outputs/apk/app-release.apk"); $apk_path = Core_Model_Directory::getPathTo("var/tmp/applications/android/{$appName}/Siberian/app/build/outputs/apk/app-release.apk"); $apk_is_generated = false; $link = $this->getUrl() . $apk_path; $link = str_replace("//", "/", $link); if (file_exists($apk_base_path)) { if (time() - filemtime($apk_base_path) <= 600) { $apk_is_generated = true; } } $user = new Backoffice_Model_User(); try { $user = $user->findAll(null, "user_id ASC", array("limit" => "1"))->current(); $sender = System_Model_Config::getValueFor("support_email"); $support_name = System_Model_Config::getValueFor("support_name"); $layout = $this->getLayout()->loadEmail('application', 'download_source'); $subject = $this->_('Android APK Generation'); $layout->getPartial('content_email')->setLink($link); $layout->getPartial('content_email')->setApkStatus($apk_is_generated); $content = $layout->render(); $mail = new Zend_Mail('UTF-8'); $mail->setBodyHtml($content); $mail->setFrom($sender, $support_name); $mail->addTo($user->getEmail()); $mail->setSubject($subject); $mail->send(); } catch (Exception $e) { $logger = Zend_Registry::get("logger"); $logger->sendException("Fatal Error Sending the APK Generation Email: \n" . print_r($e, true), "apk_generation_"); } die('ok'); }
public function forgottenpasswordAction() { if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) { try { if (empty($data['email'])) { throw new Exception($this->_('Please enter your email address')); } $user = new Backoffice_Model_User(); $user->find($data['email'], 'email'); if (!$user->getId()) { throw new Exception($this->_("Your email address does not exist")); } $password = Core_Model_Lib_String::generate(8); $user->setPassword($password)->save(); $sender = System_Model_Config::getValueFor("support_email"); $support_name = System_Model_Config::getValueFor("support_name"); $layout = $this->getLayout()->loadEmail('admin', 'forgot_password'); $subject = $this->_('Your new password'); $layout->getPartial('content_email')->setPassword($password); $content = $layout->render(); $mail = new Zend_Mail('UTF-8'); $mail->setBodyHtml($content); $mail->setFrom($sender, $support_name); $mail->addTo($user->getEmail(), $user->getName()); $mail->setSubject($subject); $mail->send(); $data = array("success" => 1, "message" => $this->_('Your new password has been sent to the entered email address')); } catch (Exception $e) { $data = array("error" => 1, "message" => $e->getMessage()); } } $this->_sendHtml($data); }
public function checkAction() { if ($this->getRequest()->isPost()) { $admin_can_publish = $this->getSession()->getAdmin()->canPublishThemself(); $errors = $this->getApplication()->isAvailableForPublishing($admin_can_publish); if (!empty($errors)) { $message = $this->_('In order to publish your application, we need:<br />- '); $message .= join('<br />- ', $errors); $html = array('message' => $message, 'message_button' => 1, 'message_loader' => 1); } else { if (Siberian_Version::TYPE == "MAE") { $backoffice_email = null; $system = new System_Model_Config(); if ($system->getValueFor("support_email")) { $backoffice_email = $system->getValueFor("support_email"); } else { $user = new Backoffice_Model_User(); $backoffice_user = $user->findAll(array(), "user_id ASC", array("limit" => 1))->current(); if ($backoffice_user) { $backoffice_email = $backoffice_user->getEmail(); } } $layout = $this->getLayout()->loadEmail('application', 'publish_app'); $layout->getPartial('content_email')->setApp($this->getApplication())->setAdmin($this->getAdmin())->setBackofficeEmail($backoffice_email); $content = $layout->render(); $sender = $backoffice_email; $mail = new Zend_Mail('UTF-8'); $mail->setBodyHtml($content); $mail->setFrom($sender); $mail->addTo($backoffice_email); $mail->setSubject($this->_('%s – Publication request', $this->getApplication()->getName())); $mail->send(); $html = array('success_message' => $this->_("Your app will be published"), 'message_button' => 0, 'message_loader' => 0, 'message_timeout' => 3); } else { if (Siberian_Version::TYPE == "PE") { $url = $this->getUrl('subscription/application/create'); $html = array('url' => $url); } } } $this->getResponse()->setBody(Zend_Json::encode($html))->sendResponse(); die; } }
public function saveAction() { if ($param = Zend_Json::decode($this->getRequest()->getRawBody())) { try { $role = new Acl_Model_Role(); if (empty($param["role"]) or !is_array($param["role"])) { throw new Exception($this->_("An error occurred while saving. Please, try again later.")); } $role_data = $param["role"]; $resources_data = !empty($param["resources"]) ? $param["resources"] : array(); if (isset($role_data["id"])) { $role->find($role_data["id"]); } $resource = new Acl_Model_Resource(); $resources_data = $resource->flattenedResources($resources_data); $role->setResources($resources_data)->setLabel($role_data["label"])->setCode($role_data["code"])->save(); $config = new System_Model_Config(); $config->find(Acl_Model_Role::DEFAULT_ADMIN_ROLE_CODE, "code"); $default_role_id = $config->getValue(); $new_default_role_id = null; if ($default_role_id == $role->getId() and !$role_data["default"]) { $new_default_role_id = Acl_Model_Role::DEFAULT_ROLE_ID; } else { if ($role_data["default"]) { $new_default_role_id = $role->getId(); } } if (!empty($new_default_role_id)) { $config->setValue($new_default_role_id)->save(); } $data = array("success" => true, "message" => $this->_("Your role has been successfully saved")); } catch (Exception $e) { $data = array("error" => true, "message" => $e->getMessage()); } $this->_sendHtml($data); } }
public function getLogo() { try { $logo = ""; if ($this->getCurrentWhiteLabelEditor()) { $logo = $this->getCurrentWhiteLabelEditor()->getLogoUrl(); } if (!$logo) { $logo = System_Model_Config::getValueFor("logo"); } if (!$logo) { $logo = $this->getImage("header/logo.png"); } } catch (Exception $e) { $logo = $this->getImage("header/logo.png"); } return $logo; }
protected function _initLocale() { $locale = new Zend_Locale(); $locale_code = Core_Model_Language::DEFAULT_LOCALE; $is_installing = $this->getRequest()->isInstalling(); if ($this->getRequest()->isApplication() && $this->getApplication()->getLocale()) { $locale_code = $this->getApplication()->getLocale(); } else { if (!$is_installing) { $currency_code = System_Model_Config::getValueFor("system_currency"); if ($currency_code) { $currency = new Zend_Currency(null, $currency_code); Core_Model_Language::setCurrentCurrency($currency); } $territory = System_Model_Config::getValueFor("system_territory"); if ($territory) { $locale_code = $locale->getLocaleToTerritory($territory); } else { $locale_code = new Zend_Locale(Core_Model_Language::getCurrentLocale()); } } } if (!$is_installing) { $timezone = System_Model_Config::getValueFor("system_timezone"); if ($timezone) { date_default_timezone_set($timezone); } } $locale->setLocale($locale_code); Zend_Registry::set('Zend_Locale', $locale); }
<?php $data = array("code" => "application_try_apk", "label" => "Try to generate the apk when downloading the Android source"); $config = new System_Model_Config(); $config->find($data["code"], "code")->setData($data)->save();
public function forgotpasswordAction() { if ($data = $this->getRequest()->getPost()) { try { if (empty($data['email'])) { throw new Exception($this->_('Please enter your email address')); } $admin = new Admin_Model_Admin(); $admin->findByEmail($data['email']); if (!$admin->getId()) { throw new Exception($this->_("This email address does not exist")); } $password = Core_Model_Lib_String::generate(8); $admin->setPassword($password)->save(); $sender = System_Model_Config::getValueFor("support_email"); $support_name = System_Model_Config::getValueFor("support_name"); $layout = $this->getLayout()->loadEmail('admin', 'forgot_password'); $subject = $this->_('%s - Your new password', $support_name); $layout->getPartial('content_email')->setPassword($password); $content = $layout->render(); $mail = new Zend_Mail('UTF-8'); $mail->setBodyHtml($content); $mail->setFrom($sender, $support_name); $mail->addTo($admin->getEmail(), $admin->getName()); $mail->setSubject($subject); $mail->send(); $data = array("success" => 1); } catch (Exception $e) { $data = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($data); } }
protected function _generateApk() { $output = array(); $alias = $this->getDevice()->getAlias(); $store_password = $this->getDevice()->getStorePass(); $key_password = $this->getDevice()->getKeyPass(); $src = "var/tmp/applications/android/{$this->_folder_name}/Siberian"; // Generates the keystore $keystore_base_path = Core_Model_Directory::getBasePathTo('var/apps/android/keystore/' . $this->getApplication()->getId() . '.pks'); if (!file_exists($keystore_base_path)) { $organization = preg_replace('/[,\\s]+/', " ", System_Model_Config::getValueFor("company_name")); if (!$organization) { $organization = "Default"; } exec('keytool -genkey -noprompt -alias ' . $alias . ' -dname "CN=' . $organization . ', O=' . $organization . '" -keystore ' . $keystore_base_path . ' -storepass ' . $store_password . ' -keypass ' . $key_password . ' -validity 36135 2>&1', $output); } // Adds the URL called at the end of the gradlew $gradlew_path = Core_Model_Directory::getBasePathTo("{$src}/app/gradlew"); $gradlew_content = file_get_contents($gradlew_path); $url = Core_Model_Url::create("application/device/apkisgenerated", array("app_name" => $this->_folder_name)); $gradlew_content .= 'wget "' . $url . '"'; file_put_contents($gradlew_path, $gradlew_content); // Sets the Android SDK path $data = 'sdk.dir=' . Core_Model_Directory::getBasePathTo("var/apps/android/sdk"); file_put_contents("{$src}/local.properties", $data); // Updates the build.gradle $content = file_get_contents("{$src}/app/build.gradle.save"); $arraySearch = array('my_storePassword', 'my_keyAlias', 'my_keyPassword', 'my_packageName', 'my_keystore_path'); $arrayReplace = array($store_password, $alias, $key_password, $this->_package_name, $keystore_base_path); $content = str_replace($arraySearch, $arrayReplace, $content); file_put_contents("{$src}/app/build.gradle", $content); // Changes the current directory chdir(Core_Model_Directory::getBasePathTo("{$src}/app")); // Creates a environment variable putenv('GRADLE_USER_HOME=' . Core_Model_Directory::getBasePathTo("var/tmp/applications/android/gradle")); // Executes gradlew exec('bash gradlew build 2>&1', $output); if (in_array('BUILD SUCCESSFUL', $output)) { return Core_Model_Directory::getBasePathTo("{$src}/app/build/outputs/apk/app-release.apk"); } else { Zend_Registry::get("logger")->sendException(print_r($output, true), "apk_generation_", false); return false; } }
private function __getFtp() { if (!$this->__ftp) { $host = System_Model_Config::getValueFor("ftp_host"); if ($host) { $user = System_Model_Config::getValueFor("ftp_username"); $password = System_Model_Config::getValueFor("ftp_password"); $port = System_Model_Config::getValueFor("ftp_port"); $path = System_Model_Config::getValueFor("ftp_path"); $this->__ftp = new Siberian_Ftp($host, $user, $password, $port, $path); } } return $this->__ftp; }
<?php $default_role = new System_Model_Config(); $default_role->find("default_role", "code"); $data = array("code" => Acl_Model_Role::DEFAULT_ADMIN_ROLE_CODE, "label" => "Default admin role"); $default_role->addData($data)->save();
public function saveftpAction() { if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) { try { $error_code = 0; $ftp_host = !empty($data["host"]) ? $data["host"] : null; $ftp_user = !empty($data["username"]) ? $data["username"] : null; $ftp_password = !empty($data["password"]) ? $data["password"] : null; $ftp_port = !empty($data["port"]) ? $data["port"] : Siberian_Ftp::DEFAULT_PORT; $ftp_path = null; if (!empty($data["path"])) { $ftp_path = rtrim($data["path"], "/"); } if (!$ftp_path) { $ftp_path = Siberian_Ftp::DEFAULT_PATH; } $ftp = new Siberian_Ftp($ftp_host, $ftp_user, $ftp_password, $ftp_port, $ftp_path); if (!$ftp->checkConnection()) { $error_code = 1; throw new Exception($this->_("Unable to connect to your FTP. Please check the connection information.")); } else { if (!$ftp->isSiberianDirectory()) { $error_code = 2; throw new Exception($this->_("Unable to detect your site. Please make sure the entered path is correct.")); } } $fields = array("ftp_host" => $ftp_host, "ftp_username" => $ftp_user, "ftp_password" => $ftp_password, "ftp_port" => $ftp_port, "ftp_path" => $ftp_path); foreach ($fields as $key => $value) { $config = new System_Model_Config(); $config->find($key, "code"); if (!$config->getId()) { $config->setCode($key)->setLabel(ucfirst(implode(" ", explode("_", $key)))); } $config->setCode($key)->setValue($value)->save(); } $data = array("success" => 1, "message" => $this->_("Info successfully saved")); } catch (Exception $e) { $data = array("error" => 1, "code" => $error_code, "message" => $e->getMessage()); } $this->_sendHtml($data); } }
public function sendCreationAccountEmail($password) { $layout = Zend_Controller_Action_HelperBroker::getStaticHelper('layout')->getLayoutInstance()->loadEmail('admin', 'create_account'); $layout->getPartial('content_email')->setAdmin($this)->setPassword($password); $content = $layout->render(); $sender = System_Model_Config::getValueFor("support_email"); $support_name = System_Model_Config::getValueFor("support_name"); $mail = new Zend_Mail('UTF-8'); $mail->setBodyHtml($content); $mail->setFrom($sender, $support_name); $mail->addTo($this->getEmail()); $mail->setSubject($this->_("Welcome!")); $mail->send(); return $this; }
public function findDefaultRoleId() { return System_Model_Config::getValueFor(self::DEFAULT_ADMIN_ROLE_CODE); }
<?php // Reset labels $data = array(array("code" => "platform_name", "label" => "Platform Name"), array("code" => "company_name", "label" => "Name"), array("code" => "company_phone", "label" => "Phone"), array("code" => "company_address", "label" => "Address"), array("code" => "company_country", "label" => "Country"), array("code" => "company_vat_number", "label" => "VAT Number"), array("code" => "system_territory", "label" => "Timezone"), array("code" => "system_timezone", "label" => "Timezone"), array("code" => "system_currency", "label" => "Currency"), array("code" => "system_default_language", "label" => "Default Languages"), array("code" => "system_publication_access_type", "label" => "Publication access type"), array("code" => "support_email", "label" => "Support Email Address"), array("code" => "support_link", "label" => "Support Link"), array("code" => "support_name", "label" => "Name"), array("code" => "support_chat_code", "label" => "Online Chat"), array("code" => Acl_Model_Role::DEFAULT_ADMIN_ROLE_CODE, "label" => "Default admin role")); foreach ($data as $configData) { $config = new System_Model_Config(); $config->find($configData["code"], "code")->setLabel($configData["label"])->save(); }
public function forgotpasswordpostAction() { if ($datas = $this->getRequest()->getPost() and !$this->getSession()->isLoggedIn('admin') and !$this->getSession()->isLoggedIn('pos')) { try { if (empty($datas['email'])) { throw new Exception($this->_('Please enter your email address')); } $admin = new Admin_Model_Admin(); $admin->findByEmail($datas['email']); if (!$admin->getId()) { throw new Exception($this->_("Your email address does not exist")); } $password = Core_Model_Lib_String::generate(8); $admin->setPassword($password)->save(); $sender = System_Model_Config::getValueFor("support_email"); $support_name = System_Model_Config::getValueFor("support_name"); $layout = $this->getLayout()->loadEmail('admin', 'forgot_password'); $subject = $this->_('%s - Your new password', $support_name); $layout->getPartial('content_email')->setPassword($password); $content = $layout->render(); $mail = new Zend_Mail('UTF-8'); $mail->setBodyHtml($content); $mail->setFrom($sender, $support_name); $mail->addTo($admin->getEmail(), $admin->getName()); $mail->setSubject($subject); $mail->send(); $this->getSession()->addSuccess($this->_('Your new password has been sent to the entered email address')); } catch (Exception $e) { $this->getSession()->addError($e->getMessage()); } } $this->_redirect('/'); return $this; }