public function removeAdminIsAutogeneratedAjax() { ipRequest()->mustBePost(); // Removing temporary data ipStorage()->remove('Ip', 'adminIsAutogenerated'); // If user wants to change credentials, redirecting to Administrators list if (ipRequest()->getPost('action') == 'change') { // todo: redirect and automatically select user and open popup $redirect = ipActionUrl(array('aa' => 'Administrators.index')) . "#/hash=&administrator=" . \Ip\Internal\Admin\Backend::userId(); \Ip\Internal\System\Model::sendUsageStatistics(array('action' => 'Install.adminChange')); return \Ip\Response\JsonRpc::result(array('redirect' => $redirect)); } \Ip\Internal\System\Model::sendUsageStatistics(array('action' => 'Install.adminKeep')); return \Ip\Response\JsonRpc::result(array('close' => 1)); }
public function sendUsageStatisticsAjax() { ipRequest()->mustBePost(); $usageStatistics = false; // Send stats just after admin login if (isset($_SESSION['module']['system']['adminJustLoggedIn'])) { $usageStatistics = array('action' => 'Admin.login', 'data' => array('admin' => ipAdminId())); // Removing session variable to send these stats only once unset($_SESSION['module']['system']['adminJustLoggedIn']); } // if we have some kind of definition then we send data if ($usageStatistics !== false) { \Ip\Internal\System\Model::sendUsageStatistics($usageStatistics); } return \Ip\Response\JsonRpc::result('ok'); }
public function updateConfig() { ipRequest()->mustBePost(); $configModel = ConfigModel::instance(); $form = $configModel->getThemeConfigForm(ipConfig()->theme()); $post = ipRequest()->getPost(); $errors = $form->validate($post); if ($errors) { return JsonRpc::error('Invalid form'); } $configModel = ConfigModel::instance(); $model = Model::instance(); $theme = $model->getTheme(ipConfig()->theme()); if (!$theme) { throw new \Ip\Exception("Theme doesn't exist"); } $options = $theme->getOptionsAsArray(); $valuesToStore = array(); foreach ($options as $option) { if (empty($option['name'])) { continue; } $field = $form->getField($option['name']); if (!$field) { continue; } switch ($option['type']) { case 'checkbox': /** * @var \Ip\Form\Field\Checkbox $field */ $value = $field->isChecked($post, $option['name']); break; case 'RepositoryFile': $value = ''; if (!empty($post[$option['name']][0])) { $value = $post[$option['name']][0]; } break; default: $value = $field->getValueAsString($post, $option['name']); } $valuesToStore[$option['name']] = $value; } $valuesToStore = ipFilter('ipDesignOptionsSave', $valuesToStore); foreach ($valuesToStore as $key => $value) { $configModel->setConfigValue(ipConfig()->theme(), $key, $value); } $lessCompiler = LessCompiler::instance(); $lessCompiler->rebuild(ipConfig()->theme()); \Ip\Internal\Core\Service::invalidateAssetCache(); ipAddJsVariable('ipModuleDesignConfiguration', Helper::getConfigurationBoxHtml()); return JsonRpc::result(true); }
public function createDatabase() { if (!Helper::isInstallAvailable()) { return sprintf(__('Please remove content from %s file.', 'Install', false), 'config.php'); } $db = ipRequest()->getPost('db'); if (!isset($_SESSION['db_errors'])) { $_SESSION['db_errors'] = array(); } foreach (array('hostname', 'username', 'database') as $key) { if (empty($db[$key])) { $_SESSION['db_errors'][] = 'Required fields'; return \Ip\Response\JsonRpc::error(__('Please fill in required fields.', 'Install', false)); } } if (empty($db['tablePrefix'])) { $db['tablePrefix'] = ''; } if (strlen($db['tablePrefix']) > 7) { $_SESSION['db_errors'][] = 'Prefix too long'; return \Ip\Response\JsonRpc::error(__("Prefix can't be longer than 7 symbols.", 'Install', false)); } if ($db['tablePrefix'] != '' && !preg_match('/^([A-Za-z_][A-Za-z0-9_]*)$/', $db['tablePrefix'])) { $_SESSION['db_errors'][] = 'Prefix is bad'; return \Ip\Response\JsonRpc::error(__("Prefix can't contain any special characters and should start with a letter.", 'Install', false)); } $dbConfig = array('hostname' => $db['hostname'], 'username' => $db['username'], 'password' => $db['password'], 'tablePrefix' => $db['tablePrefix'], 'database' => '', 'charset' => 'utf8'); ipConfig()->set('db', $dbConfig); try { ipDb()->getConnection(); } catch (\Exception $e) { $_SESSION['db_errors'][] = 'Cannot connect'; return \Ip\Response\JsonRpc::error(__("Can't connect to database.", 'Install'), false); } try { Model::createAndUseDatabase($db['database']); } catch (\Ip\Exception $e) { $_SESSION['db_errors'][] = 'DB cannot be created'; return \Ip\Response\JsonRpc::error(__('Specified database does not exists and cannot be created.', 'Install', false)); } if (Helper::testDBTables($db['tablePrefix']) && empty($db['replaceTables'])) { $_SESSION['db_errors'][] = 'Replace tables'; return \Ip\Response\JsonRpc::error(__('Do you like to replace existing tables in the database?', 'Install', false), 'table_exists'); } $errors = Model::createDatabaseStructure($db['database'], $db['tablePrefix']); if (!$errors) { $errors = Model::importData($dbConfig['tablePrefix']); } if ($errors) { $_SESSION['db_errors'][] = 'Failed install'; return \Ip\Response\JsonRpc::error(__('There were errors while executing install queries. ' . serialize($errors), 'Install', false)); } $dbConfig['database'] = $db['database']; $_SESSION['db'] = $dbConfig; $configToFile = array(); $configToFile['sessionName'] = 'ses' . rand(); $configToFile['db'] = $_SESSION['db']; $configToFile['timezone'] = $_SESSION['config']['timezone']; if (Helper::checkModRewrite() != 'success') { $configToFile['rewritesDisabled'] = true; } $admin = ipRequest()->getPost('admin'); if ($admin) { $adminUsername = $admin['username']; $adminEmail = $admin['email']; $adminPassword = $admin['password']; } $cachedBaseUrl = substr(rtrim(ipConfig()->baseUrl(), "/"), 0, -strlen('install')); try { ipConfig()->set('db', $dbConfig); // if admin data is posted then user will be created if ($admin) { Model::insertAdmin($adminUsername, $adminEmail, $adminPassword); } ipSetOptionLang('Config.websiteTitle', $_SESSION['config']['websiteName'], 'en'); ipSetOptionLang('Config.websiteEmail', $_SESSION['config']['websiteEmail'], 'en'); Model::generateCronPassword(); ipStorage()->set('Ip', 'cachedBaseUrl', $cachedBaseUrl); ipStorage()->set('Ip', 'websiteId', $_SESSION['websiteId']); ipStorage()->set('Ip', 'getImpressPagesSupport', $_SESSION['config']['support']); } catch (\Exception $e) { $_SESSION['db_errors'][] = $e->getTraceAsString(); return \Ip\Response\JsonRpc::error($e->getTraceAsString()); } try { Model::writeConfigFile($configToFile, ipFile('config.php')); } catch (\Exception $e) { $_SESSION['db_errors'][] = 'Cannot write config file'; return \Ip\Response\JsonRpc::error(__('Can\'t write configuration "/config.php"', 'Install', false)); } // Send usage statistics $usageStatistics = Helper::setUsageStatistics('Install.database', $_SESSION['db_errors']); \Ip\Internal\System\Model::sendUsageStatistics($usageStatistics); $redirect = $cachedBaseUrl . 'admin'; return \Ip\Response\JsonRpc::result(array('redirect' => $redirect)); }
public function downloadPlugins() { ipRequest()->mustBePost(); $plugins = ipRequest()->getPost('plugins'); if (!is_writable(Model::pluginInstallDir())) { return JsonRpc::error(__('Directory is not writable. Please check your email and install the plugin manually.', 'Ip-admin', false), 777); } try { if (!is_array($plugins)) { return JsonRpc::error(__('Download failed: invalid parameters', 'Ip-admin', false), 101); } if (function_exists('set_time_limit')) { set_time_limit(count($plugins) * 180 + 30); } $pluginDownloader = new PluginDownloader(); foreach ($plugins as $plugin) { if (!empty($plugin['url']) && !empty($plugin['name']) && !empty($plugin['signature'])) { $pluginDownloader->downloadPlugin($plugin['name'], $plugin['url'], $plugin['signature']); } } } catch (\Ip\Exception $e) { return JsonRpc::error($e->getMessage(), $e->getCode()); } catch (\Exception $e) { return JsonRpc::error(__('Unknown error. Please see logs.', 'Ip-admin', false), 987); } return JsonRpc::result(array('plugins' => $plugins)); }