Exemple #1
0
 /**
  * @return array|string
  */
 public static function getIpNotifications()
 {
     if (!function_exists('curl_init')) {
         return array();
     }
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, \Ip\Internal\System\Model::instance()->getImpressPagesAPIUrl());
     curl_setopt($ch, CURLOPT_POST, 1);
     $postFields = 'module_group=service&module_name=communication&action=getInfo&version=1&afterLogin='******'&systemVersion=' . \Ip\ServiceLocator::storage()->get('Ip', 'version');
     $plugins = \Ip\Internal\Plugins\Model::getActivePlugins();
     foreach ($plugins as $plugin) {
         $postFields .= '&plugins[' . $plugin['name'] . ']=' . $plugin['version'];
     }
     curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
     curl_setopt($ch, CURLOPT_REFERER, ipConfig()->baseUrl());
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_TIMEOUT, 30);
     $answer = curl_exec($ch);
     $notices = json_decode($answer);
     if (!is_array($notices)) {
         // json decode error or wrong answer
         ipLog()->error('System.updateCheckInvalidResponse', array('curl_error' => curl_error($ch), 'response' => $answer));
         return array();
     }
     return $notices;
 }
Exemple #2
0
 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));
 }
Exemple #3
0
 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');
 }
Exemple #4
0
 public function loginAjax()
 {
     ipRequest()->mustBePost();
     $validateForm = FormHelper::getLoginForm();
     $errors = $validateForm->validate(ipRequest()->getPost());
     $username = ipRequest()->getPost('login');
     if (empty($errors)) {
         $model = Model::instance();
         if (!$model->login($username, ipRequest()->getPost('password'))) {
             $errors = $model->getErrors();
         }
     }
     $redirectUrl = ipHomeUrl();
     $model = Model::instance();
     $adminMenuItems = $model->getAdminMenuItems(null);
     if (!empty($adminMenuItems)) {
         //redirect user to the first module
         $firstMenuItem = $adminMenuItems[0];
         $redirectUrl = $firstMenuItem->getUrl();
     }
     if (empty($errors)) {
         $answer = array('status' => 'success', 'redirectUrl' => $redirectUrl);
     } else {
         $answer = array('status' => 'error', 'errors' => $errors);
         $usageStatistics = array('action' => 'Admin.loginFailed', 'data' => array('admin' => $username, 'errors' => $errors));
         \Ip\Internal\System\Model::sendUsageStatistics($usageStatistics);
     }
     if (ipRequest()->getPost('ajax', 1)) {
         $response = new \Ip\Response\Json($answer);
         return $response;
     } else {
         //MultiSite autologin
         return new \Ip\Response\Redirect($redirectUrl);
     }
 }
 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));
 }