public function getTodoList(ImportEvent $event) { $time = time() - $this->config->get(CronJobs::cronKey . '/lastRun', 0); $running = $time < 3600; $todos[] = ['name' => 'Check cron job are running', 'description' => $running ? "" : "Cron daemon is not running properly (ignore during development)", 'status' => $running ? 'complete' : 'incomplete', 'link' => '/admin/cron-jobs']; $event->addContent(['Cron' => $todos]); }
public function getLoginRedirect(string $reason, bool $return = false, string $to = '') { $query = http_build_query(['redir' => $to ?: $this->request->getUri(), 'msg' => $reason]); $url = sprintf('%s?%s', $this->config->get('private/urls/login', '/login'), $query); if (!$return) { $this->setCookie('redir', $url); $redir = new Redirection($url); $redir->redirect(); } return $url; }
public function track() { if (empty($_COOKIE[self::HTTP_REFERRER_COOKIE]) && ($referrer = getenv('HTTP_REFERER'))) { $uri = parse_url($referrer); $domain = preg_quote($this->config->getPublicVars('domain')); $value = !preg_match("/{$domain}/", $uri['host']) ? sprintf('%s||%s', $this->request->getPath(), $referrer) : '/'; $this->response->setCookie(self::HTTP_REFERRER_COOKIE, $value, '+1 year'); } if (empty($_COOKIE[self::HTTP_CAMPAIGN_COOKIE]) && ($cmp = $this->request->getParameter('_cmp'))) { $this->response->setCookie(self::HTTP_CAMPAIGN_COOKIE, $cmp, '+1 year'); } }
public function getData(SeoEvent $event) { $url = $event->getUrl(); $result = $this->cache->get('seo-titles', function () { return $this->config->get('seo'); }, 3600); if ($data = $result['titles'][$url] ?? null) { if (!empty($data['title'])) { $event->setTitle($data['title']); } if (!empty($data['description'])) { $event->setMeta([['name' => 'description', 'content' => $data['description']]]); } } }
public function index($_jobs) { $lastRun = $this->config->get(self::cronKey . '/lastRun', 0); foreach ($_jobs as $job) { $schedules = json_decode($job->schedules_json); foreach ($schedules as $schedule) { $str = @join(' ', [$schedule->min, $schedule->hour, $schedule->daymonth, $schedule->month, $schedule->dayweek]); $cron = CronExpression::factory($str); $next = $cron->getNextRunDate()->format('Y-m-d H:i:s'); if (empty($settings['schedules'][$job->cron_job_id]) || strtotime($settings['schedules'][$job->cron_job_id]) > strtotime($next)) { $job->metadata = ['nextRun' => $next]; } } } return (new View())->set('lastRun', time() - $lastRun)->set('baseDir', $this->bootLoader->getBaseDir()); }
protected function encrypt_decrypt($action, $string) { $output = false; $encrypt_method = "BF"; $secret_key = $this->config->get(JwtEx::JWT_KEY, 'sanchit123456'); $key = hash('sha256', $secret_key); $iv = substr(sha1($secret_key), 0, 8); if ($action == 'encrypt') { $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv); $output = base64_encode($output); } else { if ($action == 'decrypt') { $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); } } return $output; }
public function getTodoList(ImportEvent $event) { $logins = ['Twitter', 'Google', 'Facebook']; $providers = $this->config->get('private/auth/providers'); foreach ($logins as $login) { $enabled = false; foreach ($providers as $provider) { if ($provider['name'] === $login) { $enabled = $provider['enabled'] == 'true'; break; } } $todos[] = ['name' => "Enable {$login} login provider", 'status' => $enabled ? 'complete' : 'incomplete', 'link' => '/admin/logins']; if ($enabled) { $todos[] = $this->todoMaker->createManualItem("check-{$login}-login", "Check {$login} login", "Check {$login} login app is working properly", '/login'); } } $todos[] = $this->todoMaker->createManualItem("check-forgot-password-email", "Check forgot password email", 'Check email is being delivered and working properly', '/forgot-password'); $event->addContent(['Authentication' => $todos ?? []]); }
public function getTodoList(ImportEvent $event) { $titles = $this->config->get('seo/titles', []); $groups = $this->config->get('groups/groups', []); $todos[] = ['name' => 'Create a "signature" key in public keys', 'description' => 'To use {signature} tag in emails', 'status' => $this->config->get('public/signature') ? 'complete' : 'incomplete', 'link' => '/admin/config']; $todos[] = ['name' => 'Create a "logo_url_dark" key in public keys', 'description' => 'Logo image for white background', 'status' => $this->config->get('public/logo_url_dark') ? 'complete' : 'incomplete', 'link' => '/admin/config']; $todos[] = ['name' => 'Create a "logo_url_light" key in public keys', 'description' => 'Logo image for black background', 'status' => $this->config->get('public/logo_url_light') ? 'complete' : 'incomplete', 'link' => '/admin/config']; $todos[] = ['name' => 'Enable "Minify" plugin to compress js and css', 'description' => 'For faster website loading', 'status' => is_callable(['Minute\\Minify\\Minify', 'minify']) ? 'complete' : 'incomplete', 'link' => '/admin/plugins']; $todos[] = ['name' => 'Install web analytics', 'description' => 'For measuring traffic and advertising ROI', 'status' => !empty($this->config->get('trackers/trackers')) ? 'complete' : 'incomplete', 'link' => '/admin/analytics']; $todos[] = ['name' => 'Setup page titles and descriptions', 'description' => 'Helps improve website SEO', 'status' => !empty($titles['/login']) ? 'complete' : 'incomplete', 'link' => '/admin/page-titles']; $todos[] = ['name' => 'Setup user groups for site', 'description' => 'To control website access', 'status' => is_array($groups) && count($groups) > 1 ? 'complete' : 'incomplete', 'link' => '/admin/user-groups']; $event->addContent(['Admin' => $todos]); }
public function minify(ResponseEvent $event) { if ($event->isSimpleHtmlResponse()) { /** @var HttpResponseEx $response */ $response = $event->getResponse(); try { if ($content = $response->getContent()) { $settings = $this->cache->get('minify-settings', function () { return $this->config->get(self::MINIFY_KEY); }, 3600); $version = $settings['version'] ?? 0 ?: 0.01; if (!empty($settings['css']['files'])) { $content = $this->compress('#<lin' . 'k (?:.+)?href="(/static/(?!cache/)[^"]+\\.css)"(?:.*)/?>#', $content, 'css', $version, $settings['css']['excludes'] ?? null); } if (!empty($settings['js']['files'])) { $content = $this->compress('#<scrip' . 't (?:.+)?src="(/static/(?!cache/)[^"]+\\.js)"(?:.*)>\\s*</script>#', $content, 'js', $version, $settings['js']['excludes'] ?? null); } $response->setContent($content); } } catch (\Exception $e) { echo ''; } } }
public function getCachedSessionData($reload) { $key = sprintf("session-user-%d", $this->session->getLoggedInUserId()); $userData = function () { $user_id = $this->session->getLoggedInUserId(); /** @var User $user_info */ if ($user_info = User::find($user_id)) { $user_data = array_diff_key($user_info->getAttributes(), ['password' => 1, 'verified' => 1, 'ident' => 1]); $user_data['groups'] = $this->userInfo->getUserGroups($user_id, true) ?: []; } else { $user_data = null; } if (!empty($user_data) && empty($user_data['full_name'])) { $user_data['full_name'] = trim(sprintf('%s %s', $user_data['first_name'], $user_data['last_name'])) ?: 'Anonymous'; } foreach ($this->providers->getEnabled() as $provider) { unset($provider['key'], $provider['secret']); $providers[] = $provider; } return ['site' => $this->config->getPublicVars(), 'user' => $user_data, 'providers' => $providers ?? []]; }; $data = $reload ? $userData() : $this->cache->get($key, $userData, 300); return $data; }
public function startSession(int $userId, $su = false) { $expiry = $this->config->get('private/site/session_length', '+1 day'); $jwtValue = $this->jwt->encode((object) ['user_id' => $userId], $expiry); $this->response->setCookie($su ? self::ADMIN_COOKIE_NAME : self::COOKIE_NAME, $jwtValue, $expiry); }
/** * JwtEx constructor. * * @param JWT $jwt * @param Config $config * * @internal param string $key */ public function __construct(JWT $jwt, Config $config) { $this->config = $config; $this->jwt = $jwt; $this->key = $this->config->get(self::JWT_KEY, 'sanchit123456'); }
public function getHttpdConf(ImportEvent $event) { $httpd = file_get_contents(__DIR__ . '/data/apache.conf.txt'); $conf = $this->engine->render($httpd, array_merge($this->config->getPublicVars(), ['path' => realpath($this->bootLoader->getBaseDir() . '/public')])); $event->setContent(['conf' => $conf]); }
public function createAutoItem($key, $name, $description, $link = '#') { $value = $this->config->get($key); return ['name' => $name, 'description' => $description, 'status' => !empty($value) ? 'complete' : 'incomplete', 'link' => $link]; }
public function getProviders() { return $this->config->get(self::AUTH_PROVIDER_KEY, [['name' => 'Email', 'enabled' => true]]); }
/** * AccessManager constructor. * * @param Config $config */ public function __construct(Config $config) { $this->config = $config; $this->groups = $this->config->get(self::GROUP_KEY, ['trial' => [], 'paid' => ['trial'], 'admin' => ['paid'], 'editor' => []]); }
public function getTodoList(ImportEvent $event) { $todos[] = ['name' => 'Setup Gmail integration for support desk', 'description' => 'Allows members to update support tickets via email', 'status' => $this->config->get('google/gmail/auth/token/access_token') ? 'complete' : 'incomplete', 'link' => '/admin/gmail/setup']; $todos[] = ['name' => 'Create "support" pages', 'description' => 'Create pages with page type as "support"', 'status' => MPage::where('type', '=', 'support')->where('enabled', '=', 'true')->count() ? 'complete' : 'incomplete', 'link' => '/admin/pages']; $event->addContent(['Support' => $todos]); }
public function getTodoList(ImportEvent $event) { $todos[] = ['name' => 'Enable minifier for CSS', 'description' => '', 'status' => $this->config->get('minify/css/files') ? 'complete' : 'incomplete', 'link' => '/admin/minify']; $todos[] = ['name' => 'Enable minifier for Javascript', 'description' => '', 'status' => $this->config->get('minify/js/files') ? 'complete' : 'incomplete', 'link' => '/admin/minify']; $event->addContent(['Minifier' => $todos]); }