Source of file HealthCheck_Controller.php
Size: 3,013 Bytes - Last Modified: 2021-12-23T10:10:44+00:00
/var/www/docs.ssmods.com/process/src/code/controllers/HealthCheck_Controller.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 | <?php /** * Class HealthCheck_Controller */ class HealthCheck_Controller extends Controller { public function init() { parent::init(); if(!Member::currentUserID()) { Security::permissionFailure('', 'You need to be logged in to view the health of this site.'); } Requirements::javascript('https://use.fontawesome.com/7eb8f2f8df.js'); Requirements::css("healthcheck/css/simplegrid.css"); Requirements::css("healthcheck/css/app.css"); Requirements::css("https://fonts.googleapis.com/css?family=Open+Sans"); } /** * Display information when default route is viewed * Default routes is /dev/healthcheck */ public function index() { $data = array( 'Title' => 'Health check', 'Content' => 'Health check content...', 'Environment' => Director::get_environment_type(), 'Mailer' => Email::mailer()->class, 'AdminEmail' => Config::inst()->get('Email', 'admin_email'), 'SendAllEmailsTo' => Config::inst()->get('Email', 'send_all_emails_to'), 'Nofollow' => $this->getRobotsMetaTag(), 'Logging' => $this->getLogWriters(), 'SiteMap' => $this->hasSiteMap(), 'LastCommit' => $this->getLastCommit() ); $this->extend('updateIndexData', $data); return $this->customise($data)->renderWith(array("HealthCheck")); } /** * Use PHP to check for robots meta tag * NOTE this doesn't work locally (dev mode) */ public function getRobotsMetaTag() { if (!Director::isDev()) { $metatags = get_meta_tags(Director::absoluteBaseURL()); $robots = empty($metatags['robots']) ? false : true; } return false; } /** * Get the current SS log writers and their default configuration */ public function getLogWriters() { $writers = SS_Log::get_writers(); if ($writers && !empty($writers)) { $writersArray = ArrayList::create(); foreach($writers as $writer) { $writersArray->push(ArrayData::create(array("Type" => get_class($writer), "Details" => reset($writer)))); } return $writersArray; } return false; } /** * Check if the website has an XML sitemap */ public function hasSiteMap() { $file = Director::absoluteBaseURL().'sitemap.xml'; $file_headers = @get_headers($file); if ($file_headers[0] == 'HTTP/1.1 404 Not Found' || $file_headers[0] == 'HTTP/1.0 404 Not Found') { return false; } else { return true; } } /** * Get the last commit for shits and giggles (#gitblame) */ public function getLastCommit() { if(exec("cd ../ && git log -1 --pretty=format:'%s - (%cr) - %an'", $output)){ return $output[0]; } return false; } /** * NOTE this isn't yet implemented. Plans are to allow a quick test. * to ensure emails are being sent. */ public function canSendEmail() { $email = new Email("no-reply@platocreative.co.nz","no-reply@platocreative.co.nz", "Test Email", "This is a test email message."); $this->extend('updateSendEmail', $email); if ($email->send()) { return true; } else { return false; } } } |