public static function ipBeforeController() { //show admin submenu if needed if (ipRoute()->isAdmin()) { ipAddJs('Ip/Internal/Core/assets/js/jquery-ui/jquery-ui.js'); ipAddCss('Ip/Internal/Core/assets/js/jquery-ui/jquery-ui.css'); $submenu = Submenu::getSubmenuItems(); $submenu = ipFilter('ipAdminSubmenu', $submenu); if ($submenu) { ipResponse()->setLayoutVariable('submenu', $submenu); } } // Show admin toolbar if admin is logged in: if (ipAdminId() && !ipRequest()->getRequest('pa') || ipRequest()->getRequest('aa') && ipAdminId()) { if (!ipRequest()->getQuery('ipDesignPreview') && !ipRequest()->getQuery('disableAdminNavbar')) { ipAddJs('Ip/Internal/Admin/assets/admin.js'); ipAddJsVariable('ipAdminNavbar', static::getAdminNavbarHtml()); } } // Show popup with autogenerated user information if needed $adminIsAutogenerated = ipStorage()->get('Ip', 'adminIsAutogenerated'); if ($adminIsAutogenerated) { $adminId = \Ip\Internal\Admin\Backend::userId(); $admin = \Ip\Internal\Administrators\Model::getById($adminId); ipAddJs('Ip/Internal/Admin/assets/adminIsAutogenerated.js'); $data = array('adminUsername' => $admin['username'], 'adminPassword' => ipStorage()->get('Ip', 'adminIsAutogenerated'), 'adminEmail' => $admin['email']); ipAddJsVariable('ipAdminIsAutogenerated', ipView('view/adminIsAutoGenerated.php', $data)->render()); } if (ipContent()->getCurrentPage()) { // initialize management if (ipIsManagementState()) { if (!ipRequest()->getQuery('ipDesignPreview') && !ipRequest()->getQuery('disableManagement')) { \Ip\Internal\Content\Helper::initManagement(); } } //show page content $response = ipResponse(); $response->setDescription(\Ip\ServiceLocator::content()->getDescription()); $response->setKeywords(ipContent()->getKeywords()); $response->setTitle(ipContent()->getTitle()); } }
public function login() { if (\Ip\Internal\Admin\Backend::userId()) { //user has already been logged in \Ip\Internal\Content\Service::setManagementMode(1); return new \Ip\Response\Redirect(ipHomeUrl()); } // If none of the administrator exist, we create default one and log in user $administrators = \Ip\Internal\Administrators\Model::getAll(); if (empty($administrators)) { $adminUsername = '******'; $adminEmail = ipGetOptionLang('Config.websiteEmail'); $adminPassword = Model::randString(8); $adminId = \Ip\Internal\Administrators\Service::add($adminUsername, $adminEmail, $adminPassword); \Ip\Internal\AdminPermissionsModel::addPermission('Super admin', $adminId); // Set variable to know that user is autogenerated ipStorage()->set('Ip', 'adminIsAutogenerated', $adminPassword); // Logging in new admin $model = Model::instance(); if ($model->login($adminUsername, $adminPassword)) { \Ip\Internal\System\Model::sendUsageStatistics(array('action' => 'Install.adminIsAutogenerated')); $redirectUrl = ipHomeUrl(); return new \Ip\Response\Redirect($redirectUrl); } else { \Ip\Internal\System\Model::sendUsageStatistics(array('action' => 'Install.adminIsAutogeneratedFailed')); // todo: handle errors // $errors = $model->getErrors(); } } $content = ipView('view/login.php', array('loginForm' => FormHelper::getLoginForm())); ipAddJs('Ip/Internal/Admin/assets/login.js'); $response = ipResponse(); $response->setLayout('Ip/Internal/Admin/view/loginLayout.php'); $response->setLayoutVariable('content', $content); ipAddJs('assets/languageSelect.js'); $response->setLayoutVariable('languageSelectForm', FormHelper::getLanguageSelectForm()); return $response; }
public static function update_3() { $table = ipTable('permission'); $sql = "\n CREATE TABLE IF NOT EXISTS {$table} (\n `administratorId` int(11) DEFAULT NULL,\n `permission` varchar(255) NOT NULL DEFAULT '',\n PRIMARY KEY (`administratorId`, `permission`)\n ) ENGINE=MyISAM DEFAULT CHARSET=utf8;\n "; ipDb()->execute($sql); $permissions = $permissions = ipDb()->selectColumn('permission', 'permission', array()); if (empty($permissions)) { $administrators = \Ip\Internal\Administrators\Model::getAll(); foreach ($administrators as $administrator) { \Ip\Internal\AdminPermissionsModel::addPermission('Super admin', $administrator['id']); } } }
public static function sendUsageStatistics($data = array(), $timeout = 3) { if (!function_exists('curl_init')) { return; } if (!isset($data['action'])) { $data['action'] = 'Ping.default'; } if (!isset($data['php'])) { $data['php'] = phpversion(); } if (!isset($data['db'])) { $data['db'] = null; // todo: make a db type/version check stable to work during install and later on // if (class_exists('PDO')) { // $pdo = ipDb()->getConnection(); // if ($pdo) { // $data['db'] = $pdo->getAttribute(\PDO::ATTR_SERVER_VERSION); // } // } } if (!isset($data['developmentEnvironment'])) { $data['developmentEnvironment'] = ipConfig()->get('developmentEnvironment'); } if (!isset($data['showErrors'])) { $data['showErrors'] = ipConfig()->get('showErrors'); } if (!isset($data['debugMode'])) { $data['debugMode'] = ipConfig()->get('debugMode'); } if (!isset($data['timezone'])) { $data['timezone'] = ipConfig()->get('timezone'); } if (!isset($data['data'])) { $data['data'] = array(); } if (!isset($data['websiteId'])) { $data['websiteId'] = ipStorage()->get('Ip', 'websiteId'); } if (!isset($data['websiteUrl'])) { $data['websiteUrl'] = ipConfig()->baseUrl(); } if (!isset($data['version'])) { $data['version'] = \Ip\Application::getVersion(); } if (!isset($data['locale'])) { $data['locale'] = \Ip\ServiceLocator::translator()->getAdminLocale(); } if (!isset($data['doSupport'])) { $data['doSupport'] = ipStorage()->get('Ip', 'getImpressPagesSupport'); } if (!isset($data['administrators'])) { $administrators = \Ip\Internal\Administrators\Model::getAll(); $adminCollection = array(); foreach ($administrators as $admin) { $permissions = \Ip\Internal\AdminPermissionsModel::getUserPermissions($admin['id']); $adminCollection[] = array('id' => $admin['id'], 'email' => $admin['email'], 'permissions' => $permissions); } $data['administrators'] = $adminCollection; } if (!isset($data['themes'])) { $data['themes'] = array('active' => ipConfig()->theme(), 'all' => \Ip\Internal\Design\Model::instance()->getAvailableThemes()); } if (!isset($data['plugins'])) { $plugins = \Ip\Internal\Plugins\Model::getAllPluginNames(); $activePlugins = \Ip\Internal\Plugins\Service::getActivePluginNames(); $pluginCollection = array(); foreach ($plugins as $pluginName) { $pluginCollection[] = array('name' => $pluginName, 'active' => in_array($pluginName, $activePlugins) ? true : false); } $data['plugins'] = $pluginCollection; } if (!isset($data['languages'])) { $data['languages'] = ipContent()->getLanguages(); } if (!isset($data['pages'])) { $result = array(); try { $table = ipTable('page'); $sql = "\n SELECT\n `languageCode` AS `language`, COUNT( 1 ) AS `quantity`\n FROM\n {$table}\n GROUP BY\n `languageCode`\n "; $result = ipDb()->fetchAll($sql); } catch (\Exception $e) { // Do nothing. } $data['pages'] = $result; } $postFields = 'data=' . urlencode(serialize($data)); // Use sockets instead of CURL $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, ipConfig()->get('usageStatisticsUrl', 'http://service.impresspages.org/stats')); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); // curl_setopt($ch, CURLOPT_REFERER, ipConfig()->baseUrl()); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_exec($ch); }