prod_check.module 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851
  1. <?php
  2. /**
  3. * Because of http://drupal.org/node/1067802 and the 'fuzzyness' about the issue
  4. * db_query() is preferred over db_select() inside all of the checks defined in
  5. * _prod_check_functions()! prod_check needs to be as fast and less intrusive as
  6. * possible!
  7. */
  8. /**
  9. * Our own definition of the core requirements states. These can be found in
  10. * includes/install.inc and are only available in hook_install(). That's why
  11. * we redefine them here (yes, it's double!). It's nicer than including the
  12. * install.inc file...
  13. * Let's see if this will pose problems...
  14. */
  15. define('PROD_CHECK_REQUIREMENT_INFO', -1);
  16. define('PROD_CHECK_REQUIREMENT_OK', 0);
  17. define('PROD_CHECK_REQUIREMENT_WARNING', 1);
  18. define('PROD_CHECK_REQUIREMENT_ERROR', 2);
  19. /**
  20. * This one is for use with the XMLRPC API, so that you have proper links when
  21. * using the prod_monitor module.
  22. */
  23. $protocol = 'http://';
  24. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
  25. $protocol = 'https://';
  26. }
  27. define('PRODCHECK_BASEURL', $protocol.$_SERVER['HTTP_HOST'].'/');
  28. /**
  29. * Implementation of hook_help().
  30. */
  31. function prod_check_help($path, $arg) {
  32. $output = '';
  33. switch ($path) {
  34. case 'admin/help#prod_check':
  35. $output .= '<p>'.t('Production check is a module that will add a report detailing the status of several settings and modules. The report is tailored for a <strong>production environment</strong>. It will tell you which modules should (not) be running, what settings are OK or not and much more. It is an easy way to have an overview of the status of your site when bringing it live, so that you can quickly put all the configuration details in order to be ready for production use.').'</p>';
  36. $output .= '<p>'.t('Using the settings page, you can enable <strong>XMLRPC support</strong> so that it can report back to the <strong>Production monitor</strong> module, available as an extra module in this package. If you install the <em>Production monitor</em> module on a central site, you can monitor several sites in a glance, ensuring that no one changes settings without you knowing about it. See the <em>Production monitor</em> built in help for more information.').'</p>';
  37. $output .= '<p>'.t('If you prefer using <strong>!link</strong> for monitoring, you can simply enable support for that on the settings page by ticking the appropriate checkmark. An extra set of checkboxes will appear, allowing you to configure in detail what exactly you wish !link to monitor.', prod_check_link_array('Nagios', 'http://drupal.org/project/nagios')).'</p>';
  38. break;
  39. case 'admin/reports/prod-check':
  40. case 'admin/reports/prod-check/status':
  41. $output .= '<p>'.t('This is an overview of all checks performed by the <em>Production check</em> module and their status. You can click the links inside the report to jump to the module\'s settings page, or to go to the project page of a module, in case you need to download it for installation.').'</p>';
  42. break;
  43. case 'admin/config/system/prod-check':
  44. $output .= '<p><strong>'.t('Sitemail check').'</strong><br />';
  45. $output .= t('The value entered here is used in a regular expression. Prod check will use it to see if the e-mail address you have entered in <em>Site information</em> is no longer a development e-mail address.').'</p>';
  46. $output .= '<p><strong>'.t('Advanced APC settings').'</strong><br />';
  47. $output .= t('Production check enables a <em>hidden</em> path where you can review your APC setup. This is absolutely unmissable if you want to properly setup APC and tune it specifically for your website.').'</p>';
  48. $output .= '<p><strong>'.t('Enable XMLRPC API').'</strong><br />';
  49. $output .= t('By ticking this box, you open up the module\'s XMLRPC functions so they can be called by the <strong>Production monitor</strong> module for remote monitoring of your site. When enabling XMLRPC, you <strong>must</strong> enter an <strong>API key</strong> to secure the transfer of data. It\'s limited to 128 characters. A mixture of alphanumeric and special characters will increase security.').'</p>';
  50. $output .= '<p><strong>'.t('Report module list every <em>x</em> at time <em>y</em>').'</strong><br />';
  51. $output .= t('Select on which day of the week and at what time <em>Production check</em> is allowed to pass the module list of the site it is on to <em>Production monitor</em>. Set this carefully, as the amount data being transfered is quite big!').'<br />';
  52. $output .= t('Depending on when the cron is run on the <em>Production monitor</em> site, the module list will be reported on or maybe even several hours(!) after the time given here!').'</p>';
  53. $output .= '<p><strong>'.t('Enable Nagios integration').'</strong><br />';
  54. $output .= t('By ticking this box, you open up the module\'s Nagios hooks, so that it can interface with the !link module. You will obviously need to install this module next to <em>Production check</em> to enable this functionality.', prod_check_link_array('Nagios', 'http://drupal.org/project/nagios')).'<br />';
  55. $output .= t('When the checkbox is enabled, a new array of checkboxes will appear, allowing you to specify in detail what will be reported to !link.', prod_check_link_array('Nagios', 'http://drupal.org/project/nagios')).'</p>';
  56. break;
  57. }
  58. return $output;
  59. }
  60. /**
  61. * Implementation of hook_permission()
  62. */
  63. function prod_check_permission() {
  64. return array(
  65. 'administer production check' => array(
  66. 'title' => t('Administer Production Check'),
  67. 'description' => t('Configure Production Check settings.'),
  68. ),
  69. 'access production check' => array(
  70. 'title' => t("Access Production check's status page"),
  71. 'description' => t('View the report on all checks performed by Production check.'),
  72. ),
  73. 'switch to production mode' => array(
  74. 'title' => t("Switch to production mode"),
  75. 'description' => t('Allow a user to switch a site to production mode.'),
  76. ),
  77. );
  78. }
  79. /**
  80. * Implementation of hook_menu()
  81. */
  82. function prod_check_menu() {
  83. $items = array();
  84. $items['admin/reports/prod-check'] = array(
  85. 'title' => 'Production check',
  86. 'description' => 'View the Production check report page.',
  87. 'page callback' => 'prod_check_status',
  88. 'access callback' => 'user_access',
  89. 'access arguments' => array('access production check'),
  90. 'type' => MENU_NORMAL_ITEM,
  91. 'file' => 'includes/prod_check.admin.inc',
  92. );
  93. // Default tab (callback for this is it's parent path).
  94. $items['admin/reports/prod-check/status'] = array(
  95. 'title' => 'Status',
  96. 'type' => MENU_DEFAULT_LOCAL_TASK,
  97. 'weight' => 0,
  98. );
  99. $items['admin/reports/prod-check/prod-mode'] = array(
  100. 'title' => 'Production mode',
  101. 'description' => 'Setup this site so it is ready for production.',
  102. 'page callback' => 'drupal_get_form',
  103. 'page arguments' => array('prod_check_prod_mode_form'),
  104. 'access callback' => 'user_access',
  105. 'access arguments' => array('switch to production mode'),
  106. 'type' => MENU_LOCAL_TASK,
  107. 'file' => 'includes/prod_check.admin.inc',
  108. 'weight' => 1,
  109. );
  110. $items['admin/config/system/prod-check'] = array(
  111. 'title' => 'Production check',
  112. 'description' => 'Setup the Production check module.',
  113. 'page callback' => 'drupal_get_form',
  114. 'page arguments' => array('prod_check_settings_form'),
  115. 'access callback' => 'user_access',
  116. 'access arguments' => array('administer production check'),
  117. 'type' => MENU_NORMAL_ITEM,
  118. 'file' => 'includes/prod_check.admin.inc',
  119. );
  120. $items['admin/reports/status/apc'] = array(
  121. 'title' => 'APC',
  122. 'page callback' => 'prod_check_apc',
  123. 'access callback' => 'user_access',
  124. 'access arguments' => array('access production check'),
  125. 'type' => MENU_CALLBACK,
  126. 'file' => 'includes/prod_check.admin.inc',
  127. );
  128. $items['admin/reports/status/memcache'] = array(
  129. 'title' => 'Memcache',
  130. 'page callback' => 'prod_check_memcache',
  131. 'access callback' => 'user_access',
  132. 'access arguments' => array('access production check'),
  133. 'type' => MENU_CALLBACK,
  134. 'file' => 'includes/prod_check.admin.inc',
  135. );
  136. return $items;
  137. }
  138. /**
  139. * Implementation of hook_flush_caches()
  140. */
  141. function prod_check_flush_caches() {
  142. // We set this variable to a negative value to allow for immediate refetching
  143. // of the module update data when update.php was run.
  144. if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update') {
  145. variable_set('prod_check_module_list_lastrun', -1);
  146. }
  147. return array();
  148. }
  149. /**
  150. * Implementation of hook_theme()
  151. */
  152. function prod_check_theme($existing, $type, $theme, $path) {
  153. return array(
  154. 'prod_check_status_report' => array(
  155. 'variables' => array('requirements' => NULL),
  156. 'file' => 'includes/prod_check.theme.inc',
  157. ),
  158. );
  159. }
  160. /**
  161. * Helper function that assembles the list of disabled modules to check.
  162. */
  163. function _prod_check_get_disabled_modules_whitelist() {
  164. $modules = array();
  165. $modules += module_invoke_all('prod_check_disabled_modules_whitelist');
  166. $modules = array_unique(array_map('drupal_strtolower', $modules));
  167. // Allow other modules to add or delete modules to force check
  168. drupal_alter('prod_check_disabled_modules_whitelist', $modules);
  169. return $modules;
  170. }
  171. /**
  172. * Implements hook_prod_check_disabled_modules_whitelist().
  173. *
  174. * Check for updates for these modules even if they are disabled. Some modules
  175. * (f.e. cache backends) are included directly but don't necessarily have the
  176. * module enabled in the module list. This list can be extended by other modules
  177. * or updated with other commonly used modules that are used in such a way.
  178. */
  179. function prod_check_prod_check_disabled_modules_whitelist() {
  180. return array('apc', 'memcache', 'varnish');
  181. }
  182. /**
  183. * Implements hook_update_projects_alter().
  184. *
  185. * If we chose to exclude disabled modules, check if some of those are on the
  186. * whitelist.
  187. */
  188. function prod_check_update_projects_alter(&$projects) {
  189. if (variable_get('prod_check_exclude_disabled_modules', 0)) {
  190. $force_checked_modules = _prod_check_get_disabled_modules_whitelist();
  191. foreach ($projects as $project_name => $project) {
  192. if ($project['project_type'] == 'module-disabled') {
  193. if (!in_array($project['name'], $force_checked_modules)) {
  194. unset($projects[$project_name]);
  195. }
  196. }
  197. }
  198. }
  199. }
  200. /**
  201. * Custom callback to override /nagios page.
  202. */
  203. function prod_check_nagios_status_page() {
  204. // Make sure this page is not cached.
  205. drupal_page_is_cacheable(FALSE);
  206. header("Pragma: no-cache");
  207. header("Expires: 0");
  208. if ($_SERVER['HTTP_USER_AGENT'] != variable_get('nagios_ua', 'Nagios')) {
  209. switch (variable_get('prod_check_nagios_unique', 'default')) {
  210. case '404': drupal_not_found();
  211. break;
  212. case 'home': drupal_goto('<front>');
  213. break;
  214. default: nagios_status_page();
  215. }
  216. }
  217. else {
  218. nagios_status_page();
  219. }
  220. }
  221. /**
  222. * Implementation of hook_xmlrpc
  223. * http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_xmlrpc/6
  224. */
  225. function prod_check_xmlrpc() {
  226. if (variable_get('prod_check_enable_xmlrpc', 0) == 1) {
  227. return array(
  228. array(
  229. 'prod_check.get_settings',
  230. 'prod_check_get_settings',
  231. array('struct', 'string'),
  232. t('Returns a struct containing a form to be displayed on the prod_monitor module\'s settings page for site specific configuration.')
  233. ),
  234. array(
  235. 'prod_check.get_data',
  236. 'prod_check_get_data',
  237. array('struct', 'string', 'struct'),
  238. t('Returns a struct containing the result of all requested checks.')
  239. ),
  240. );
  241. }
  242. }
  243. /**
  244. * Helper function to check for correct API key.
  245. */
  246. function _prod_check_valid_key($ping_key) {
  247. $connect_key = variable_get('prod_check_xmlrpc_key', '');
  248. $result = FALSE;
  249. if ($connect_key && $ping_key == $connect_key) {
  250. $result = TRUE;
  251. }
  252. return $result;
  253. }
  254. /**
  255. * XMLRPC version of _prod_check_functions()
  256. * Returnes a keyed array of functions that can be parsed by the reciever into
  257. * a form or status page.
  258. */
  259. function prod_check_get_settings($ping_key) {
  260. $data = FALSE;
  261. if (_prod_check_valid_key($ping_key)) {
  262. $data = _prod_check_functions();
  263. }
  264. return $data;
  265. }
  266. /**
  267. * XMLRPC callback function that returns all data of requested checks.
  268. *
  269. * @param ping_key Api key for this site
  270. * @param checks Array of all checks to perform
  271. *
  272. * @return Array of all data to be displayed by the requesting site in a
  273. * 'status_form' theme.
  274. */
  275. function prod_check_get_data($ping_key, $checks) {
  276. $data = FALSE;
  277. if (_prod_check_valid_key($ping_key)) {
  278. $data = array();
  279. foreach ($checks as $set => $calls) {
  280. $data[$set] = array();
  281. foreach ($calls as $key => $function) {
  282. $check = call_user_func($function, 'xmlrpc');
  283. if (is_array($check) && !empty($check)) {
  284. $data[$set] = array_merge($data[$set], $check);
  285. }
  286. }
  287. }
  288. }
  289. return $data;
  290. }
  291. /**
  292. * Nagios support, see http://drupal.org/project/nagios
  293. */
  294. /**
  295. * Implementation of hook_nagios_info()
  296. */
  297. function prod_check_nagios_info() {
  298. if (variable_get('prod_check_enable_nagios', 0)) {
  299. return array(
  300. 'name' => 'Production check',
  301. 'id' => 'PRDCHK',
  302. );
  303. }
  304. }
  305. /**
  306. * Implementation of hook_nagios_settings()
  307. */
  308. /*function prod_check_nagios_settings() {
  309. if (variable_get('prod_check_enable_nagios', 0)) {
  310. foreach(prod_check_functions() as $function => $description) {
  311. $var = 'prod_check_' . $function;
  312. $form[$var] = array(
  313. '#type' => 'checkboxes',
  314. '#title' => $function,
  315. '#default_value' => variable_get($var, TRUE),
  316. '#description' => $description,
  317. );
  318. }
  319. }
  320. }*/
  321. /**
  322. * Implementation of hook_nagios()
  323. */
  324. function prod_check_nagios() {
  325. $status = array();
  326. if (variable_get('prod_check_enable_nagios', 0)) {
  327. $checks = variable_get('prod_check_nagios_checks', array());
  328. foreach ($checks as $set => $calls) {
  329. // TODO: add check on $set here. Single out 'perf_data' and treat differently.
  330. foreach ($calls as $key => $function) {
  331. $check = call_user_func($function, 'nagios');
  332. if (is_array($check) && !empty($check)) {
  333. $status = array_merge($status, $check);
  334. }
  335. }
  336. }
  337. // Not verbose? Then filter the output.
  338. if (variable_get('prod_check_nagios_verbose', 0) == 0) {
  339. $nagios = array(
  340. 'OK' => array(
  341. 'count' => 0,
  342. ),
  343. 'Unknown' => array(
  344. 'count' => 0,
  345. 'items' => array(),
  346. ),
  347. 'Warning' => array(
  348. 'count' => 0,
  349. 'items' => array(),
  350. ),
  351. 'CRITICAL' => array(
  352. 'count' => 0,
  353. 'items' => array(),
  354. ),
  355. );
  356. $highest = 0;
  357. foreach ($status as $item => $check) {
  358. switch ($check['status']) {
  359. case NAGIOS_STATUS_OK:
  360. $nagios['OK']['count']++;
  361. break;
  362. case NAGIOS_STATUS_UNKNOWN:
  363. $nagios['Unknown']['count']++;
  364. $nagios['Unknown']['items'][] = $item;
  365. break;
  366. case NAGIOS_STATUS_WARNING:
  367. $nagios['Warning']['count']++;
  368. $nagios['Warning']['items'][] = $item;
  369. break;
  370. case NAGIOS_STATUS_CRITICAL:
  371. $nagios['CRITICAL']['count']++;
  372. $nagios['CRITICAL']['items'][] = $item;
  373. break;
  374. }
  375. if ($check['status'] > $highest) {
  376. $highest = $check['status'];
  377. }
  378. }
  379. // Build message.
  380. $message = '[';
  381. foreach ($nagios as $state => $value) {
  382. // Ignore 0 values.
  383. if (!$value['count']) {
  384. continue;
  385. }
  386. $message .= '@'.strtolower($state).' '.$state;
  387. if(isset($nagios[$state]['items'])) {
  388. $message .= ': '.implode('|', $nagios[$state]['items']);
  389. }
  390. $message .= ', ';
  391. }
  392. // Remove last comma and space.
  393. $message = rtrim($message, ', ');
  394. $message .= ']';
  395. // TODO: add | followed by performance data here if enabled.
  396. // Reset status array.
  397. $status = array();
  398. $status['PRODCHK'] = array(
  399. 'status' => $highest,
  400. 'type' => 'state',
  401. 'text' => t($message, array('@ok' => $nagios['OK']['count'], '@unknown' => $nagios['Unknown']['count'], '@warning' => $nagios['Warning']['count'], '@critical' => $nagios['CRITICAL']['count'])),
  402. );
  403. }
  404. }
  405. // Keep this outside of the if to avoid PHP notices on the nagios status page.
  406. return $status;
  407. }
  408. /**
  409. * Function that gives status feedback on requirements.
  410. *
  411. * @param checks an associative array of associative arrays consisting of the
  412. * following keys:
  413. * #title: the title to be displayed in the status table
  414. * #state: true or false, see examples on how to use this
  415. * #severity: the severity when the check fails
  416. * #value_ok: value to show when check will pass
  417. * #value_nok: to show when check will fail
  418. * #description_ok: description to show when check will pass
  419. * #description_nok: description to show when check will fail
  420. *
  421. * @return array result array that can be themed with the 'status_report' theme.
  422. */
  423. function prod_check_execute_check($checks, $caller, $compatibility = 'all') {
  424. $result = array();
  425. if (is_array($checks) && $compatibility == 'all') {
  426. foreach (element_children($checks) as $key) {
  427. if (!$checks[$key]['#state']) {
  428. // Check failed
  429. switch ($caller) {
  430. case 'internal':
  431. case 'xmlrpc':
  432. $result[$key] = array(
  433. 'title' => $checks[$key]['#title'],
  434. 'value' => $checks[$key]['#value_nok'],
  435. 'severity' => $checks[$key]['#severity'],
  436. 'description' => $checks[$key]['#description_nok'],
  437. );
  438. break;
  439. case 'nagios':
  440. $result[$checks[$key]['#nagios_key']] = array(
  441. 'status' => $checks[$key]['#severity'],
  442. 'type' => $checks[$key]['#nagios_type'],
  443. 'text' => strip_tags($checks[$key]['#description_nok']),
  444. );
  445. break;
  446. }
  447. }
  448. else {
  449. // Check passed
  450. switch ($caller) {
  451. case 'internal':
  452. case 'xmlrpc':
  453. $result[$key] = array(
  454. 'title' => $checks[$key]['#title'],
  455. 'value' => $checks[$key]['#value_ok'],
  456. 'severity' => PROD_CHECK_REQUIREMENT_OK,
  457. 'description' => $checks[$key]['#description_ok'],
  458. );
  459. break;
  460. case 'nagios':
  461. $result[$checks[$key]['#nagios_key']] = array(
  462. 'status' => NAGIOS_STATUS_OK,
  463. 'type' => $checks[$key]['#nagios_type'],
  464. 'text' => strip_tags($checks[$key]['#description_ok']),
  465. );
  466. break;
  467. }
  468. }
  469. }
  470. }
  471. // Special stuff here, only compatible with prod_monitor!
  472. else if (is_array($checks) && $compatibility == 'prod_mon') {
  473. $result = $checks;
  474. }
  475. return $result;
  476. }
  477. /**
  478. * Helper function to generate generic 'settings OK' description.
  479. */
  480. function prod_check_ok_title($title, $path, $text = 'Your !link settings are OK for production use.') {
  481. return t($text, array('!link' => '<em>'.l(t($title), $path, array('attributes' => array('title' => t($title)), 'query' => drupal_get_destination())).'</em>'));
  482. }
  483. /**
  484. * Helper function to generate link array to pass to the t() function
  485. */
  486. function prod_check_link_array($title, $path, $fragment=NULL) {
  487. $options = array(
  488. 'attributes' => array(
  489. 'title' => t($title),
  490. ),
  491. 'query' => array(
  492. drupal_get_destination(),
  493. ),
  494. );
  495. if ($fragment) {
  496. $options['fragment'] = $fragment;
  497. }
  498. return array('!link' => '<em>'.l(t($title), $path, $options).'</em>');
  499. }
  500. // --- All check functions follow here ---
  501. /**
  502. * Keyed array containing all check functions and their description so they can
  503. * be easily executed from a simple loop.
  504. * If you add a new function, add it here as well, or it will never be executed.
  505. * NOTE: NO use of t() here since we'll be doing that later! This content has to
  506. * be translated by the site displaying it: Prod check or Prod monitor!
  507. */
  508. function _prod_check_functions() {
  509. $functions = array();
  510. // Settings
  511. $functions['settings'] = array(
  512. 'title' => 'Settings',
  513. 'description' => 'Checks wether various settings are fit for a production environment.',
  514. 'functions' => array(
  515. '_prod_check_error_reporting' => 'Error reporting',
  516. '_prod_check_user_register' => 'User registration',
  517. '_prod_check_site_mail' => 'Site e-mail',
  518. ),
  519. );
  520. // Server
  521. $functions['server'] = array(
  522. 'title' => 'Server',
  523. 'description' => 'Checks certain server side parameters such as APC.',
  524. 'functions' => array(
  525. '_prod_check_apc' => 'APC',
  526. '_prod_check_dblog_php' => 'PHP errors',
  527. '_prod_check_release_notes' => 'Release notes',
  528. ),
  529. );
  530. // Performance settings
  531. $functions['performance'] = array(
  532. 'title' => 'Performance',
  533. 'description' => 'Checks if performance settings are OK for production use.',
  534. 'functions' => array(
  535. '_prod_check_page_cache' => 'Page caching',
  536. '_prod_check_page_compression' => 'Page compression',
  537. '_prod_check_boost' => 'Boost settings',
  538. '_prod_check_block_cache' => 'Block cache',
  539. '_prod_check_preprocess_css' => 'Optimize CSS files',
  540. '_prod_check_preprocess_js' => 'Optimize JavaScript files',
  541. ),
  542. );
  543. // Security
  544. $functions['security'] = array(
  545. 'title' => 'Security',
  546. 'description' => 'Various security related checks.',
  547. 'functions' => array(
  548. '_prod_check_node_available' => 'Is /node available?',
  549. /*'_prod_check_user_pass' => 'User passwords',*/
  550. '_prod_check_anonymous_rights' => 'Anonymous user rights',
  551. '_prod_check_admin_username' => 'Is user 1 named "admin"?'
  552. ),
  553. );
  554. // Modules
  555. $functions['modules'] = array(
  556. 'title' => 'Modules',
  557. 'description' => 'Checks if certain modules are on or off and if they\'re properly configured.',
  558. 'functions' => array(
  559. '_prod_check_contact' => 'Contact',
  560. '_prod_check_devel' => 'Devel',
  561. '_prod_check_search_config' => 'Search config',
  562. '_prod_check_update_status' => 'Update status',
  563. '_prod_check_webform' => 'Webform',
  564. '_prod_check_missing_module_files' => 'Active modules',
  565. ),
  566. );
  567. // SEO
  568. $functions['seo'] = array(
  569. 'title' => 'SEO',
  570. 'description' => 'Checks if basic SEO modules are enabled.',
  571. 'functions' => array(
  572. '_prod_check_googleanalytics' => 'Google Analytics',
  573. '_prod_check_metatag' => 'Metatag',
  574. '_prod_check_page_title' => 'Page titles',
  575. '_prod_check_pathauto' => 'Path auto',
  576. '_prod_check_redirect' => 'Redirect',
  577. '_prod_check_xmlsitemap' => 'XML sitemap',
  578. ),
  579. );
  580. // Production monitor only!
  581. $functions['prod_mon'] = array(
  582. 'title' => 'Production monitor',
  583. 'description' => 'Specific checks that only work with Production monitor!',
  584. 'functions' => array(
  585. '_prod_check_module_list' => 'Check module updates',
  586. '_prod_check_cron_last' => 'Report last cron run',
  587. ),
  588. );
  589. // Invoke hook_prod_check_alter() here to add additional checks implemented by third
  590. // party modules.
  591. drupal_alter('prod_check', $functions);
  592. return $functions;
  593. }
  594. // --- SETTINGS ---
  595. // TODO: find a solution of the use of t() here. Should be used on the site
  596. // displaying the content! Maybe use a custom theme instead of
  597. // theme_status_report()...? Any ideas?
  598. // Logging and errors check
  599. function _prod_check_error_reporting($caller = 'internal') {
  600. $check = array();
  601. $title = 'Logging and errors';
  602. $path = 'admin/config/development/logging';
  603. if ($caller != 'internal') {
  604. $path = PRODCHECK_BASEURL . $path;
  605. }
  606. $setting[ERROR_REPORTING_HIDE] = t('None');
  607. $setting[ERROR_REPORTING_DISPLAY_SOME] = t('Errors and warnings');
  608. $setting[ERROR_REPORTING_DISPLAY_ALL] = t('All messages');
  609. $current = variable_get('error_level', ERROR_REPORTING_DISPLAY_ALL);
  610. $check['prod_check_error_reporting'] = array(
  611. '#title' => t($title),
  612. '#state' => $current == ERROR_REPORTING_HIDE,
  613. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR,
  614. '#value_ok' => $setting[ERROR_REPORTING_HIDE],
  615. '#value_nok' => $setting[$current],
  616. '#description_ok' => prod_check_ok_title($title, $path),
  617. '#description_nok' => t('Your !link settings are set to %setting1, they should be set to %setting2 on a producion environment!',
  618. array(
  619. '!link' => '<em>'.l(t($title), $path, array('attributes' => array('title' => t($title)), 'query' => drupal_get_destination())).'</em>',
  620. '%setting1' => $setting[$current],
  621. '%setting2' => $setting[ERROR_REPORTING_HIDE],
  622. )
  623. ),
  624. '#nagios_key' => 'ERR',
  625. '#nagios_type' => 'state',
  626. );
  627. return prod_check_execute_check($check, $caller);
  628. }
  629. // Account settings check
  630. function _prod_check_user_register($caller = 'internal') {
  631. $check = array();
  632. $title = 'Account settings';
  633. $path = 'admin/config/people/accounts';
  634. if ($caller != 'internal') {
  635. $path = PRODCHECK_BASEURL . $path;
  636. }
  637. $setting[USER_REGISTER_ADMINISTRATORS_ONLY] = t('Administrators only');
  638. $setting[USER_REGISTER_VISITORS] = t('Visitors');
  639. $setting[USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL] = t('Visitors, but administrator approval is required');
  640. $current = variable_get('user_register', 1);
  641. $check['prod_check_user_register'] = array(
  642. '#title' => t($title),
  643. '#state' => $current != USER_REGISTER_VISITORS,
  644. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING,
  645. '#value_ok' => $setting[$current],
  646. '#value_nok' => $setting[USER_REGISTER_VISITORS],
  647. '#description_ok' => prod_check_ok_title($title, $path),
  648. '#description_nok' => t('Your !link settings are set to %setting1. Are you sure this is what you want and did not mean to use %setting2? With improperly setup access rights, this can be dangerous...',
  649. array(
  650. '!link' => '<em>'.l(t($title), $path, array('attributes' => array('title' => t($title)), 'query' => drupal_get_destination())).'</em>',
  651. '%setting1' => $setting[$current],
  652. '%setting2' => $setting[USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL],
  653. )
  654. ),
  655. '#nagios_key' => 'USR',
  656. '#nagios_type' => 'state',
  657. );
  658. return prod_check_execute_check($check, $caller);
  659. }
  660. // Site e-mail address check
  661. function _prod_check_site_mail($caller = 'internal') {
  662. $check = array();
  663. $title = 'Site e-mail';
  664. $path = 'admin/config/system/site-information';
  665. if ($caller != 'internal') {
  666. $path = PRODCHECK_BASEURL . $path;
  667. }
  668. $site_mail = variable_get('site_mail', '');
  669. $arguments = array('%mail' => $site_mail);
  670. $check['prod_check_site_mail'] = array(
  671. '#title' => t($title),
  672. '#state' => $site_mail != '' && !preg_match('/' . preg_quote(variable_get('prod_check_sitemail', '')) . '/i', $site_mail),
  673. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR,
  674. '#value_ok' => t('Global site e-mail address OK: %mail', $arguments),
  675. '#value_nok' => t('Global site e-mail address set to %mail', $arguments),
  676. '#description_ok' => prod_check_ok_title($title, $path),
  677. '#description_nok' => t('The !link address of the website should not be a development address on production sites!', prod_check_link_array($title, $path)),
  678. '#nagios_key' => 'MAIL',
  679. '#nagios_type' => 'state',
  680. );
  681. return prod_check_execute_check($check, $caller);
  682. }
  683. // --- SERVER ---
  684. // APC check
  685. function _prod_check_apc($caller = 'internal') {
  686. $check = array();
  687. $desc_ok = $desc_nok = '';
  688. $title = 'APC';
  689. $path = 'admin/reports/status/apc';
  690. if ($caller != 'internal') {
  691. $path = PRODCHECK_BASEURL . $path;
  692. }
  693. if (!function_exists('apc_cache_info')) {
  694. $desc_nok = t('!link does not appear to be running.', prod_check_link_array($title, $path));
  695. $val_nok = t('Disabled');
  696. $error = TRUE;
  697. }
  698. else if ($cache = @apc_cache_info('opcode')) {
  699. $apc_expunge = variable_get('prod_check_apc_expunge', 0);
  700. $detailed_info = ': '.t('hits').': '.$cache['num_hits'].', '.t('misses').': '.$cache['num_misses'].', '.t('cache full count').': '.$cache['expunges'].'.';
  701. if ($cache['num_misses'] >= $cache['num_hits']) {
  702. $desc_nok = t('!link not properly configured, too many misses', prod_check_link_array($title, $path)) . $detailed_info;
  703. $val_nok = t('Not functioning properly.');
  704. $error = TRUE;
  705. }
  706. else if ($cache['expunges'] > $apc_expunge) {
  707. $desc_nok = t('!link not properly configured, cache size too small', prod_check_link_array($title, $path)) . $detailed_info;
  708. $val_nok = t('Not functioning properly.');
  709. $error = TRUE;
  710. }
  711. else {
  712. $desc_ok = t('!link running fine', prod_check_link_array($title, $path)) . $detailed_info;
  713. $val_ok = t('Enabled');
  714. $error = FALSE;
  715. }
  716. }
  717. else {
  718. $desc_nok = t('Could not retrieve !link cache data.', prod_check_link_array($title, $path));
  719. $val_nok = t('Not functioning properly.');
  720. $error = TRUE;
  721. }
  722. $check['prod_check_apc'] = array(
  723. '#title' => t($title),
  724. '#state' => !$error,
  725. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR,
  726. '#value_ok' => t('Enabled'),
  727. '#value_nok' => t('Disabled'),
  728. '#description_ok' => $desc_ok,
  729. '#description_nok' => $desc_nok,
  730. '#nagios_key' => 'APC',
  731. '#nagios_type' => 'state',
  732. );
  733. return prod_check_execute_check($check, $caller);
  734. }
  735. // PHP errors
  736. function _prod_check_dblog_php($caller = 'internal') {
  737. if (!module_exists('dblog')) {
  738. return;
  739. }
  740. $check = array();
  741. $title = 'PHP errors';
  742. $path = 'admin/reports/dblog';
  743. if ($caller != 'internal') {
  744. $path = PRODCHECK_BASEURL . $path;
  745. }
  746. $error = FALSE;
  747. $error_level = variable_get('prod_check_dblog_php', WATCHDOG_WARNING);
  748. $threshold = variable_get('prod_check_dblog_php_threshold', 1);
  749. $result = db_query(
  750. 'SELECT COUNT(*) FROM (SELECT count(wid) FROM {watchdog} WHERE type = :type AND severity <= :severity GROUP BY variables HAVING COUNT(wid) >= :threshold) subquery',
  751. array(
  752. ':type' => 'php',
  753. ':severity' => $error_level,
  754. ':threshold' => $threshold,
  755. )
  756. )->fetchField();
  757. if ($result) {
  758. $error = TRUE;
  759. }
  760. $check['prod_check_dblog_php'] = array(
  761. '#title' => t($title),
  762. '#state' => !$error,
  763. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING,
  764. '#value_ok' => t('No PHP errors reported.'),
  765. '#value_nok' => t('PHP errors reported!'),
  766. '#description_ok' => t('Status is OK for production use.'),
  767. '#description_nok' => format_plural(
  768. $result,
  769. '@count PHP error occuring more than !threshold time(s) has been reported! Check the !link for details!',
  770. '@count PHP errors occuring more than !threshold time(s) have been reported! Check the !link for details!',
  771. array(
  772. '!link' => implode(prod_check_link_array($title, $path)),
  773. '!threshold' => $threshold,
  774. )
  775. ),
  776. '#nagios_key' => 'PHP',
  777. '#nagios_type' => 'state',
  778. );
  779. return prod_check_execute_check($check, $caller);
  780. }
  781. // .txt files present in root check
  782. function _prod_check_release_notes($caller = 'internal') {
  783. $check = array();
  784. $title = 'Release notes & help files';
  785. $files = array(
  786. 'CHANGELOG.txt',
  787. 'COPYRIGHT.txt',
  788. 'INSTALL.mysql.txt',
  789. 'INSTALL.pgsql.txt',
  790. 'INSTALL.sqlite.txt',
  791. 'INSTALL.txt',
  792. 'LICENSE.txt',
  793. 'MAINTAINERS.txt',
  794. 'README.txt',
  795. 'UPGRADE.txt',
  796. 'sites/all/README.txt',
  797. 'sites/all/themes/README.txt',
  798. 'sites/all/modules/README.txt',
  799. );
  800. $remaining_files = array();
  801. $error = FALSE;
  802. foreach ($files as $file) {
  803. if (file_exists(DRUPAL_ROOT . '/' . $file)) {
  804. array_push($remaining_files, $file);
  805. $error = TRUE;
  806. }
  807. }
  808. $check['prod_check_release_notes'] = array(
  809. '#title' => t($title),
  810. '#state' => !$error,
  811. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING,
  812. '#value_ok' => t('Release note & help files have been removed.'),
  813. '#value_nok' => t('Release note & help files still present on your server!'),
  814. '#description_ok' => t('Status is OK for production use.'),
  815. '#description_nok' => t('Leaving the "!files" files present on the webserver is a minor security risk. These files are useless on production anyway and they simply should not be there.', array(
  816. '!files' => implode(', ', $remaining_files)
  817. )
  818. ),
  819. '#nagios_key' => 'REL',
  820. '#nagios_type' => 'state',
  821. );
  822. return prod_check_execute_check($check, $caller);
  823. }
  824. // --- PERFORMANCE ---
  825. // Page cache
  826. function _prod_check_page_cache($caller = 'internal') {
  827. $check = array();
  828. $error = FALSE;
  829. $title = 'Cache pages for anonymous users';
  830. $path = 'admin/config/development/performance';
  831. if ($caller != 'internal') {
  832. $path = PRODCHECK_BASEURL . $path;
  833. }
  834. if (variable_get('cache', 0) == 0) {
  835. $error = TRUE;
  836. // Maybe Boost is enabled?
  837. if (variable_get('boost_enabled', 0) == 1) {
  838. $error = FALSE;
  839. $path .= '/boost';
  840. }
  841. }
  842. $check['prod_check_page_cache'] = array(
  843. '#title' => t($title),
  844. '#state' => !$error,
  845. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR,
  846. '#value_ok' => t('Enabled'),
  847. '#value_nok' => t('Disabled'),
  848. '#description_ok' => prod_check_ok_title($title, $path),
  849. '#description_nok' => t('Your !link settings are disabled. You should at least set page caching to "Cache pages for anonymous users" on a production site! You should also consider using the !boost module or a more powerful system like !varnish!',
  850. array(
  851. '!link' => '<em>'.l(t($title), $path, array('attributes' => array('title' => t($title)), 'query' => drupal_get_destination())).'</em>',
  852. '!boost' => '<em>'.l(t('Boost'), 'http://drupal.org/project/boost', array('attributes' => array('title' => t('Boost')))).'</em>',
  853. '!varnish' => '<em>'.l(t('Varnish'), 'http://drupal.org/project/steroids', array('attributes' => array('title' => t('Varnish')))).'</em>',
  854. )
  855. ),
  856. '#nagios_key' => 'PCACHE',
  857. '#nagios_type' => 'state',
  858. );
  859. return prod_check_execute_check($check, $caller);
  860. }
  861. // Page compression
  862. function _prod_check_page_compression($caller = 'internal') {
  863. $check = array();
  864. $status = TRUE;
  865. $title = 'Compress cached pages.';
  866. $path = 'admin/config/development/performance';
  867. if ($caller != 'internal') {
  868. $path = PRODCHECK_BASEURL . $path;
  869. }
  870. // Adjust path if Boost is enabled.
  871. if (variable_get('boost_enabled', 0) == 1) {
  872. $path .= '/boost';
  873. }
  874. if (variable_get('page_compression', 0) == 0) {
  875. $status = FALSE;
  876. // When using Varnish, turning off page compression is a good thing!
  877. if (module_exists('varnish') || module_exists('steroids')) {
  878. $status = TRUE;
  879. }
  880. }
  881. $check['prod_check_page_compression'] = array(
  882. '#title' => t($title),
  883. '#state' => $status,
  884. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR,
  885. '#value_ok' => t('Enabled'),
  886. '#value_nok' => t('Disabled'),
  887. '#description_ok' => prod_check_ok_title($title, $path),
  888. '#description_nok' => t('Your !link settings are disabled. You should enable page compression on production sites!', prod_check_link_array($title, $path)),
  889. '#nagios_key' => 'PCOMP',
  890. '#nagios_type' => 'state',
  891. );
  892. return prod_check_execute_check($check, $caller);
  893. }
  894. // Boost settings check
  895. function _prod_check_boost($caller = 'internal') {
  896. $result = array();
  897. if (module_exists('boost')) {
  898. $check = array();
  899. $path = 'admin/config/development/performance/boost';
  900. if ($caller != 'internal') {
  901. $path = PRODCHECK_BASEURL . $path;
  902. }
  903. $title = 'Boost: ';
  904. // Cache lifetime check
  905. $subtitle = 'HTML max. cache lifetime ';
  906. $var = variable_get('boost_cache_lifetime', 3600);
  907. $check['prod_check_boost_cache_lifetime'] = array(
  908. '#title' => t($title.$subtitle),
  909. '#state' => $var <= 3600,
  910. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING,
  911. '#value_ok' => t('Set to !seconds seconds.', array('!seconds' => $var)),
  912. '#value_nok' => t('Set too high?'),
  913. '#description_ok' => prod_check_ok_title($subtitle, $path),
  914. '#description_nok' => t('Your !link settings might be set too high. Do consider that view blocks will remain unchanged for the amount of time you set here, even when new content is added! The default value of 1 hour is usually OK.', prod_check_link_array($subtitle, $path)),
  915. '#nagios_key' => 'BCLFT',
  916. '#nagios_type' => 'state',
  917. );
  918. // Clear pages check
  919. $subtitle = 'Clear expired pages on cron runs';
  920. $var = variable_get('boost_expire_cron', TRUE);
  921. $check['prod_check_boost_expire_cron'] = array(
  922. '#title' => t($title.$subtitle),
  923. '#state' => $var,
  924. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING,
  925. '#value_ok' => t('Enabled'),
  926. '#value_nok' => t('Disabled'),
  927. '#description_ok' => prod_check_ok_title($subtitle, $path),
  928. '#description_nok' => t('!link is disabled! You should enable this to ensure that expired pages get flushed when the cron runs. This is imperative if you wish to keep view blocks up to date!', prod_check_link_array($subtitle, $path)),
  929. '#nagios_key' => 'BCLPG',
  930. '#nagios_type' => 'state',
  931. );
  932. /*
  933. // Crawl on cron check
  934. // The Boost module is in development atm, as soon as it is released we'll fix this.
  935. $subtitle = 'Crawl on cron';
  936. $var = variable_get('boost_crawl_on_cron', FALSE);
  937. $check['prod_check_boost_crawl_on_cron'] = array(
  938. '#title' => t($title.$subtitle),
  939. '#state' => $var,
  940. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING,
  941. '#value_ok' => t('Enabled'),
  942. '#value_nok' => t('Disabled'),
  943. '#description_ok' => prod_check_ok_title($subtitle, $path),
  944. '#description_nok' => t('!link is disabled! You should enable this to ensure that the users are served cached pages all the time. The crawler caches pages before anyone can access them.', prod_check_link_array($subtitle, $path)),
  945. '#nagios_key' => 'BCRCR',
  946. '#nagios_type' => 'state',
  947. );
  948. */
  949. // Apache etag check
  950. $subtitle = 'ETag';
  951. $var = variable_get('boost_apache_etag', 0);
  952. $check['prod_check_boost_apache_etag'] = array(
  953. '#title' => t($title.$subtitle),
  954. '#state' => $var >= 2,
  955. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING,
  956. '#value_ok' => t('Enabled'),
  957. '#value_nok' => t('Not properly configured.'),
  958. '#description_ok' => prod_check_ok_title($subtitle, $path),
  959. '#description_nok' => t('Your !link settings are not ok! You should enable entity tags (!etag) in Boost so that user side caching and bandwith usage will be optimal! You do need to enable !mod for this to work.',
  960. array(
  961. '!link' => '<em>'.l(t($subtitle), $path, array('attributes' => array('title' => t($subtitle)), 'query' => drupal_get_destination())).'</em>',
  962. '!etag' => '<em>'.l(t('ETags'), 'http://en.wikipedia.org/wiki/HTTP_ETag', array('attributes' => array('title' => t('Etags')))).'</em>',
  963. '!mod' => '<em>'.l(t('mod_headers'), 'http://httpd.apache.org/docs/2.0/mod/mod_headers.html', array('attributes' => array('title' => t('mod_headers')))).'</em>',
  964. )
  965. ),
  966. '#nagios_key' => 'BETAG',
  967. '#nagios_type' => 'state',
  968. );
  969. $result = prod_check_execute_check($check, $caller);
  970. }
  971. return $result;
  972. }
  973. // Block cache
  974. function _prod_check_block_cache($caller = 'internal') {
  975. $check = array();
  976. $title = 'Cache blocks';
  977. $path = 'admin/config/development/performance';
  978. if ($caller != 'internal') {
  979. $path = PRODCHECK_BASEURL . $path;
  980. }
  981. $check['prod_check_block_cache'] = array(
  982. '#title' => t($title),
  983. '#state' => variable_get('block_cache', 0) != 0,
  984. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR,
  985. '#value_ok' => t('Enabled'),
  986. '#value_nok' => t('Disabled'),
  987. '#description_ok' => prod_check_ok_title($title, $path),
  988. '#description_nok' => t('Your !link settings are disabled. You should really enable this for production as it can cause huge performance increases, especially on high load websites!', prod_check_link_array($title, $path)),
  989. '#nagios_key' => 'BCACHE',
  990. '#nagios_type' => 'state',
  991. );
  992. return prod_check_execute_check($check, $caller);
  993. }
  994. // Optimize CSS files
  995. function _prod_check_preprocess_css($caller = 'internal') {
  996. $check = array();
  997. $state = TRUE;
  998. $title = 'Aggregate and compress CSS files.';
  999. $path = 'admin/config/development/performance';
  1000. // Check settings.
  1001. if (variable_get('preprocess_css', 0) == 0) {
  1002. $state = FALSE;
  1003. // TODO: In D6 there was an extra check on the 'advagg' module. Keep an eye out for a D7 port or a D7 alternative!
  1004. }
  1005. if ($caller != 'internal') {
  1006. $path = PRODCHECK_BASEURL . $path;
  1007. }
  1008. $check['prod_check_preprocess_css'] = array(
  1009. '#title' => t($title),
  1010. '#state' => $state,
  1011. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR,
  1012. '#value_ok' => t('Enabled'),
  1013. '#value_nok' => t('Disabled'),
  1014. '#description_ok' => prod_check_ok_title($title, $path),
  1015. '#description_nok' => t('Your !link settings are disabled, they should be enabled on a producion environment! This should not cause trouble if you steer clear of @import statements.', prod_check_link_array($title, $path)),
  1016. '#nagios_key' => 'CCOMP',
  1017. '#nagios_type' => 'state',
  1018. );
  1019. return prod_check_execute_check($check, $caller);
  1020. }
  1021. // Optimize JavaScript files
  1022. function _prod_check_preprocess_js($caller = 'internal') {
  1023. $check = array();
  1024. $state = TRUE;
  1025. $title = 'Aggregate JavaScript files.';
  1026. $path = 'admin/config/development/performance';
  1027. // Check settings.
  1028. if (variable_get('preprocess_js', 0) == 0) {
  1029. $state = FALSE;
  1030. // TODO: In D6 there was an extra check on the 'advagg' module. Keep an eye out for a D7 port or a D7 alternative!
  1031. }
  1032. if ($caller != 'internal') {
  1033. $path = PRODCHECK_BASEURL . $path;
  1034. }
  1035. $check['prod_check_preprocess_js'] = array(
  1036. '#title' => t($title),
  1037. '#state' => $state,
  1038. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING,
  1039. '#value_ok' => t('Enabled'),
  1040. '#value_nok' => t('Disabled'),
  1041. '#description_ok' => prod_check_ok_title($title, $path),
  1042. '#description_nok' => t('Your !link settings are disabled, ideally they should be enabled on a producion environment but this requires testing first, since it can cause JavaScript errors in certain cases.', prod_check_link_array($title, $path)),
  1043. '#nagios_key' => 'JCOMP',
  1044. '#nagios_type' => 'state',
  1045. );
  1046. return prod_check_execute_check($check, $caller);
  1047. }
  1048. // --- Security ---
  1049. // /node available
  1050. function _prod_check_node_available($caller = 'internal') {
  1051. $check = array();
  1052. $msg = '';
  1053. $title = 'Is /node available?';
  1054. $path = '';
  1055. if ($caller != 'internal') {
  1056. $path = PRODCHECK_BASEURL;
  1057. }
  1058. $result = menu_execute_active_handler('node', FALSE);
  1059. switch ($result) {
  1060. case MENU_ACCESS_DENIED:
  1061. $msg = t('The default /node page created by Drupal core has been disabled by means of an <em>Access Denied</em>. Better still is to simply unset the menu item by using hook_menu_alter().');
  1062. $secure = FALSE;
  1063. break;
  1064. case MENU_NOT_FOUND:
  1065. $secure = TRUE;
  1066. break;
  1067. default:
  1068. $frontpage = variable_get('site_frontpage', '');
  1069. if (!empty($frontpage) && $frontpage != 'node') {
  1070. $msg = t('The default /node page created by Drupal core is still enabled. With improper setup of node types, this can reveal sensitive information (e.g. using the profile module with automatic publish to front activated)!');
  1071. $secure = FALSE;
  1072. }
  1073. else {
  1074. // Using /node as default frontpage.
  1075. $secure = TRUE;
  1076. }
  1077. }
  1078. $check['prod_check_node_available'] = array(
  1079. '#title' => t($title),
  1080. '#state' => $secure,
  1081. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING,
  1082. '#value_ok' => t('Secure'),
  1083. '#value_nok' => t('Security risk!'),
  1084. '#description_ok' => t('No security risk found.'),
  1085. '#description_nok' => $msg,
  1086. '#nagios_key' => 'NODE',
  1087. '#nagios_type' => 'state',
  1088. );
  1089. return prod_check_execute_check($check, $caller);
  1090. }
  1091. // Users
  1092. function _prod_check_user_pass($caller = 'internal') {
  1093. $check = array();
  1094. $secure = TRUE;
  1095. $list = '';
  1096. $title = 'User passwords';
  1097. $path = '';
  1098. if ($caller != 'internal') {
  1099. $path = PRODCHECK_BASEURL;
  1100. }
  1101. // Be sure to omit the anonymous user with id 0.
  1102. $result = db_query('SELECT uid, name FROM {users} WHERE uid <> 0 AND status = 1 AND MD5(name) = pass');
  1103. foreach ($result as $row) {
  1104. $list .= l($row['name'], $path.'user/'.$row['uid'].'/edit', array('attributes' => array('title' => t('Edit user').' '.$row['name']), 'query' => drupal_get_destination())).', ';
  1105. }
  1106. if (!empty($list)) {
  1107. $secure = FALSE;
  1108. // Remove last comma and space.
  1109. $list = rtrim($list, ', ');
  1110. }
  1111. $check['prod_check_user_pass'] = array(
  1112. '#title' => t($title),
  1113. '#state' => $secure,
  1114. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR,
  1115. '#value_ok' => t('Secure'),
  1116. '#value_nok' => t('Security risk!'),
  1117. '#description_ok' => t('No security risk found.'),
  1118. '#description_nok' => t('Some users have a password that is identical to their username! You should check the following users:' .' '.$list.'.'),
  1119. '#nagios_key' => 'USRBD',
  1120. '#nagios_type' => 'state',
  1121. );
  1122. return prod_check_execute_check($check, $caller);
  1123. }
  1124. // Anonymous
  1125. function _prod_check_anonymous_rights($caller = 'internal') {
  1126. $check = array();
  1127. $secure = TRUE;
  1128. $title = 'Anonymous user rights';
  1129. $path = 'admin/people/permissions';
  1130. if ($caller != 'internal') {
  1131. $path = PRODCHECK_BASEURL . $path;
  1132. }
  1133. $perms = db_query('SELECT permission FROM {role_permission} WHERE rid = 1')->fetchCol();
  1134. $perms = implode(', ', $perms);
  1135. if (preg_match('/(\baccess\sall\b|\badd\b|\badminister\b|\bchange\b|\bclear\b|\bcreate\b|\bdelete\b|\bedit\b|\brevert\b|\bsave\b|\bsend\smail\b|\bset\svariable\b|\bupdate\b|\bupload\b|\bPHP\b|\bdevel\b)/i', $perms)) {
  1136. $secure = FALSE;
  1137. }
  1138. $check['prod_check_anonymous_rights'] = array(
  1139. '#title' => t($title),
  1140. '#state' => $secure,
  1141. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR,
  1142. '#value_ok' => t('Secure'),
  1143. '#value_nok' => t('Security risk!'),
  1144. '#description_ok' => t('No security risk found.'),
  1145. '#description_nok' => t('The anonymous user seems to have elevated privileges! Please check the !link.', prod_check_link_array('permissions page', $path)),
  1146. '#nagios_key' => 'ANON',
  1147. '#nagios_type' => 'state',
  1148. );
  1149. return prod_check_execute_check($check, $caller);
  1150. }
  1151. /**
  1152. * Simple check to ensure the admin username is not easily guessable by a robot.
  1153. */
  1154. function _prod_check_admin_username($caller = 'internal') {
  1155. global $base_url;
  1156. $check = array();
  1157. $title = "Administrator's username (User 1)";
  1158. $secure = TRUE;
  1159. $superuser = user_load(1);
  1160. // By default severity and description are for the less severe case which is
  1161. // overridden when the username is actually still just the default "admin".
  1162. $severity = ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING;
  1163. $description_nok = t('Ideally the admin username should not contain the word "admin" or any part of the current domain. The current admin username is %name.', array('%name' => $superuser->name));
  1164. // Determine if part of the current domain is in the admin username.
  1165. $parsed_base = parse_url($base_url);
  1166. $host_parts = explode('.', $parsed_base['host']);
  1167. $name_contains_host_part = FALSE;
  1168. foreach($host_parts as $part) {
  1169. if (stripos($superuser->name, $part) !== FALSE) {
  1170. $name_contains_host_part = TRUE;
  1171. }
  1172. }
  1173. // The username contains "admin".
  1174. if (stripos($superuser->name, 'admin') !== FALSE
  1175. // Or the current domain.
  1176. || $name_contains_host_part) {
  1177. $secure = FALSE;
  1178. }
  1179. // It is very bad if the admin still has the default username.
  1180. if ($superuser->name == 'admin') {
  1181. $secure = FALSE;
  1182. $severity = ($caller == 'nagios') ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR;
  1183. $description_nok = t('The admin user seems to have the default username "admin". This is both extremely easy for a robot to guess and extremely bad if said robot subsequently guesses the admin password. Please change the admin username, ideally to something that does not contain the word "admin" or any part of the current domain.');
  1184. }
  1185. $check['prod_check_admin_username'] = array(
  1186. '#title' => t($title),
  1187. '#state' => $secure,
  1188. '#severity' => $severity,
  1189. '#value_ok' => t('Secure'),
  1190. '#value_nok' => t('Security risk!'),
  1191. '#description_ok' => t('No security risk found.'),
  1192. '#description_nok' => $description_nok,
  1193. '#nagios_key' => 'ADMINUN',
  1194. '#nagios_type' => 'state',
  1195. );
  1196. return prod_check_execute_check($check, $caller);
  1197. }
  1198. // --- MODULES ---
  1199. // Contact
  1200. function _prod_check_contact($caller = 'internal') {
  1201. if (!module_exists('contact')) {
  1202. return;
  1203. }
  1204. $check = array();
  1205. $error = FALSE;
  1206. $title = 'Contact';
  1207. $path = 'admin/structure/contact';
  1208. if ($caller != 'internal') {
  1209. $path = PRODCHECK_BASEURL . $path;
  1210. }
  1211. // Check all mails in the contact table.
  1212. $prod_check_sitemail = preg_quote(variable_get('prod_check_sitemail', ''));
  1213. $categories = array();
  1214. $result = db_query('SELECT category, recipients FROM {contact}');
  1215. foreach ($result as $row) {
  1216. $recipients = explode(',', $row->recipients);
  1217. foreach ($recipients as $mail) {
  1218. if (preg_match('/' . $prod_check_sitemail . '/i', $mail)) {
  1219. $categories[] = $row->category . ': ' . $mail;
  1220. $error = TRUE;
  1221. }
  1222. }
  1223. }
  1224. $arguments = array('!contact' => $title, '%categories' => implode(', ', $categories));
  1225. $check['prod_check_contact'] = array(
  1226. '#title' => t($title),
  1227. '#state' => !$error,
  1228. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR,
  1229. '#value_ok' => t('!contact e-mail addresses are OK.', $arguments),
  1230. '#value_nok' => t('!contact e-mail addresses are %categories', $arguments),
  1231. '#description_ok' => prod_check_ok_title($title, $path),
  1232. '#description_nok' => t('The !link recepient e-mail addresses should not be development addresses on production sites!', prod_check_link_array($title, $path)),
  1233. '#nagios_key' => 'CNT',
  1234. '#nagios_type' => 'state',
  1235. );
  1236. return prod_check_execute_check($check, $caller);
  1237. }
  1238. // Devel
  1239. function _prod_check_devel($caller = 'internal') {
  1240. $checks = array();
  1241. $modules = array(
  1242. 'DVL' => array(
  1243. 'name' => 'devel',
  1244. 'title' => 'Devel',
  1245. 'path' => 'admin/config/development/devel',
  1246. ),
  1247. 'DVG' => array(
  1248. 'name' => 'devel_generate',
  1249. 'title' => 'Devel generate',
  1250. 'path' => 'admin/generate',
  1251. ),
  1252. 'DVN' => array(
  1253. 'name' => 'devel_node_access',
  1254. 'title' => 'Devel node access',
  1255. 'path' => 'admin/config/development/devel',
  1256. ),
  1257. 'DVT' => array(
  1258. 'name' => 'devel_themer',
  1259. 'title' => 'Theme developer',
  1260. 'path' => 'admin/config/development/devel_themer',
  1261. ),
  1262. );
  1263. foreach ($modules as $key => &$data) {
  1264. $data['error'] = (module_exists($data['name'])) ? TRUE : FALSE;
  1265. $title = $data['title'];
  1266. $path = $data['path'];
  1267. if ($caller != 'internal') {
  1268. $path = PRODCHECK_BASEURL . $path;
  1269. }
  1270. $checks['prod_check_'.$data['name']] = array(
  1271. '#title' => t($title),
  1272. '#state' => !$data['error'],
  1273. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR,
  1274. '#value_ok' => t('Disabled'),
  1275. '#value_nok' => t('Enabled'),
  1276. '#description_ok' => t('Your settings are OK for production use.'),
  1277. '#description_nok' => t('You have enabled the !link module. This should not be running on a production environment!', prod_check_link_array($title, $path)),
  1278. '#nagios_key' => $key,
  1279. '#nagios_type' => 'state',
  1280. );
  1281. }
  1282. return prod_check_execute_check($checks, $caller);
  1283. }
  1284. // Search config
  1285. function _prod_check_search_config($caller = 'internal') {
  1286. if (!module_exists('search')) {
  1287. return;
  1288. }
  1289. $check = array();
  1290. $error = FALSE;
  1291. $title = 'Search config';
  1292. $path = 'admin/people/permissions';
  1293. $fragment = 'module-search_config';
  1294. $str_anonymous_content = $severity = $value_nok = $msg_nok = $msg_ok = '';
  1295. if ($caller != 'internal') {
  1296. $path = PRODCHECK_BASEURL . $path;
  1297. }
  1298. if (!module_exists('search_config')) {
  1299. $error = TRUE;
  1300. $severity = ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING;
  1301. $value_nok = t('Disabled');
  1302. $msg_nok = t('You have not enabled the !link module. Please double check if you need this module or not, to be able to hide certain content types from being searched by users.', prod_check_link_array($title, 'http://drupal.org/project/search_config'));
  1303. }
  1304. else {
  1305. $check_anonymous_search_all = db_query("SELECT rid, permission, module FROM {role_permission} WHERE rid = 1 AND module = 'search_config' AND permission = 'search all content'")->fetchField();
  1306. $check_anonymous_content_types = db_query("SELECT permission, module FROM {role_permission} WHERE rid = 1 AND module = 'search_config'")->fetchCol();
  1307. if($check_anonymous_search_all == 1) {
  1308. $error = TRUE;
  1309. $msg_nok = t('You have enabled the !link module, but anonymous users can search every content type!', prod_check_link_array($title, $path, $fragment));
  1310. }
  1311. else {
  1312. $error = FALSE;
  1313. $str_anonymous_content = implode(', ', $check_anonymous_content_types);
  1314. $msg_ok = t('You have enabled the !link module, anonymous users can search for "!content_types" -content type(s).', array(
  1315. '!link' => implode(prod_check_link_array($title, $path, $fragment)),
  1316. '!content_types' => $str_anonymous_content,
  1317. ));
  1318. }
  1319. if ($error) {
  1320. $severity = ($caller == 'nagios') ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR;
  1321. $value_nok = t('Not properly configured.');
  1322. }
  1323. }
  1324. $check['prod_check_search_config'] = array(
  1325. '#title' => t($title),
  1326. '#state' => !$error,
  1327. '#severity' => $severity,
  1328. '#value_ok' => t('Enabled'),
  1329. '#value_nok' => $value_nok,
  1330. '#description_ok' => $msg_ok,
  1331. '#description_nok' => $msg_nok,
  1332. '#nagios_key' => 'SRCH',
  1333. '#nagios_type' => 'state',
  1334. );
  1335. return prod_check_execute_check($check, $caller);
  1336. }
  1337. // Update status
  1338. function _prod_check_update_status($caller = 'internal') {
  1339. $check = array();
  1340. $title = 'Update status';
  1341. $path = 'admin/reports/updates';
  1342. if ($caller != 'internal') {
  1343. $path = PRODCHECK_BASEURL . $path;
  1344. }
  1345. $check['prod_check_update_status'] = array(
  1346. '#title' => t($title),
  1347. '#state' => !module_exists('update'),
  1348. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING,
  1349. '#value_ok' => t('Disabled'),
  1350. '#value_nok' => t('Enabled'),
  1351. '#description_ok' => t('Your settings are OK for production use.'),
  1352. '#description_nok' => t('You have enabled the !link module. It would be better to turn this off on production, contrary to what Drupal core claims, and keep it running on development. Updating and testing should happen on development before deploying to production anyway.', prod_check_link_array($title, $path)),
  1353. '#nagios_key' => 'UPD',
  1354. '#nagios_type' => 'state',
  1355. );
  1356. return prod_check_execute_check($check, $caller);
  1357. }
  1358. // Webform
  1359. function _prod_check_webform($caller = 'internal') {
  1360. if (!module_exists('webform')) {
  1361. return;
  1362. }
  1363. $check = array();
  1364. $title = 'Webform';
  1365. $path = 'admin/config/content/webform';
  1366. if ($caller != 'internal') {
  1367. $path = PRODCHECK_BASEURL . $path;
  1368. }
  1369. $webform_mail = variable_get('webform_default_from_address', variable_get('site_mail', ini_get('sendmail_from')));
  1370. $arguments = array('!webform' => $title, '%mail' => $webform_mail);
  1371. $check['prod_check_webform'] = array(
  1372. '#title' => t($title),
  1373. '#state' => $webform_mail != '' && !preg_match('/' . preg_quote(variable_get('prod_check_sitemail', '')) . '/i', $webform_mail),
  1374. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR,
  1375. '#value_ok' => t('!webform default from e-mail address OK: %mail', $arguments),
  1376. '#value_nok' => t('!webform default from e-mail address set to %mail', $arguments),
  1377. '#description_ok' => prod_check_ok_title($title, $path),
  1378. '#description_nok' => t('The !link default from e-mail address should not be a development address on production sites!', prod_check_link_array($title, $path)),
  1379. '#nagios_key' => 'WFRM',
  1380. '#nagios_type' => 'state',
  1381. );
  1382. return prod_check_execute_check($check, $caller);
  1383. }
  1384. // Active modules
  1385. function _prod_check_missing_module_files($caller = 'internal') {
  1386. $missing = $total = 0;
  1387. $check = $modules = array();
  1388. $title = 'Active modules';
  1389. // Get a list of .module files for active modules. If a module is active but
  1390. // the .module file is missing, this can cause serious performance issues, see
  1391. // http://drupal.org/node/1080330.
  1392. $result = db_query("SELECT filename FROM {system} WHERE status = 1 AND filename NOT LIKE '%.info'");
  1393. foreach ($result as $row) {
  1394. $path = DRUPAL_ROOT . '/' . $row->filename;
  1395. if(!file_exists($path)) {
  1396. $modules[] = $row->filename;
  1397. $missing++;
  1398. }
  1399. $total++;
  1400. }
  1401. $check['prod_check_modules_available'] = array(
  1402. '#title' => t($title),
  1403. '#state' => $missing == 0,
  1404. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR,
  1405. '#value_ok' => t('A total of !total active modules are registered in the database. No missing entries found.', array('!total' => $total)),
  1406. '#value_nok' => t('A total of !total active modules are registered in the database. !missing missing entries found!', array('!total' => $total, '!missing' => $missing)),
  1407. '#description_ok' => t('All *.module files are present.'),
  1408. '#description_nok' => t('The following files are missing: %modules.', array('%modules' => implode(', ', $modules))),
  1409. '#nagios_key' => 'MODS',
  1410. '#nagios_type' => 'state',
  1411. );
  1412. return prod_check_execute_check($check, $caller);
  1413. }
  1414. // --- SEO ---
  1415. // TODO: make generic function for all of these, only $title, $path & $key change!
  1416. // Google Analytics
  1417. function _prod_check_googleanalytics($caller = 'internal') {
  1418. $check = array();
  1419. $error = FALSE;
  1420. $ga_account = variable_get('googleanalytics_account', 'UA-');
  1421. $severity = $value_nok = $msg_nok = $msg_ok = '';
  1422. $title_ok = 'settings';
  1423. $text_ok = 'Check the !link to verify if they are as you expect.';
  1424. $title = 'Google Analytics';
  1425. $path = 'admin/config/system/googleanalytics';
  1426. if ($caller != 'internal') {
  1427. $path = PRODCHECK_BASEURL . $path;
  1428. }
  1429. if (!module_exists('googleanalytics')) {
  1430. $error = TRUE;
  1431. $severity = ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING;
  1432. $value_nok = t('Disabled');
  1433. $msg_nok = t('You have not enabled the !link module. If you wish to track and optimise your site !link is absolutely necessary.', prod_check_link_array($title, 'http://drupal.org/project/google_analytics'));
  1434. }
  1435. else if (empty($ga_account) || $ga_account == 'UA-') {
  1436. $error = TRUE;
  1437. $severity = ($caller == 'nagios') ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR;
  1438. $value_nok = t('Not properly configured.');
  1439. $msg_nok = t('You did not !link! Tracking will not be functional!', prod_check_link_array('enter a Google Analytics account', $path));
  1440. }
  1441. $check['prod_check_googleanalytics'] = array(
  1442. '#title' => t($title),
  1443. '#state' => !$error,
  1444. '#severity' => $severity,
  1445. '#value_ok' => t('Enabled'),
  1446. '#value_nok' => $value_nok,
  1447. '#description_ok' => prod_check_ok_title($title_ok, $path, $text_ok),
  1448. '#description_nok' => $msg_nok,
  1449. '#nagios_key' => 'GA',
  1450. '#nagios_type' => 'state',
  1451. );
  1452. return prod_check_execute_check($check, $caller);
  1453. }
  1454. // Meta tags
  1455. function _prod_check_metatag($caller = 'internal') {
  1456. $check = array();
  1457. $title_ok = 'settings';
  1458. $text_ok = 'Check the !link to verify if they are as you expect.';
  1459. $title = 'Metatag';
  1460. $path = 'admin/config/search/metatags';
  1461. if ($caller != 'internal') {
  1462. $path = PRODCHECK_BASEURL . $path;
  1463. }
  1464. $check['prod_check_metatag'] = array(
  1465. '#title' => t($title),
  1466. '#state' => module_exists('metatag'),
  1467. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING,
  1468. '#value_ok' => t('Enabled'),
  1469. '#value_nok' => t('Disabled'),
  1470. '#description_ok' => prod_check_ok_title($title_ok, $path, $text_ok),
  1471. '#description_nok' => t('You have not enabled the !link module. If you care about ranking your site in search engines, this module is an absolute must.', prod_check_link_array($title, 'http://drupal.org/project/metatag')),
  1472. '#nagios_key' => 'META',
  1473. '#nagios_type' => 'state',
  1474. );
  1475. return prod_check_execute_check($check, $caller);
  1476. }
  1477. function _prod_check_page_title($caller = 'internal') {
  1478. $check = array();
  1479. $error = FALSE;
  1480. $pager = variable_get('page_title_pager_pattern', '');
  1481. $value_nok = $msg_nok = '';
  1482. $title_ok = 'settings';
  1483. $text_ok = 'Check the !link to verify if they are as you expect.';
  1484. $title = 'Page titles';
  1485. $path = 'admin/config/search/page-title';
  1486. if ($caller != 'internal') {
  1487. $path = PRODCHECK_BASEURL . $path;
  1488. }
  1489. if (!module_exists('page_title')) {
  1490. $error = TRUE;
  1491. $value_nok = t('Disabled');
  1492. $msg_nok = t('You have not enabled the !link module. This module can help out with problems such as pages with paging being marked as duplicate content by search engines.', prod_check_link_array($title, 'http://drupal.org/project/page_title'));
  1493. }
  1494. else if (empty($pager)) {
  1495. $error = TRUE;
  1496. $value_nok = t('Not properly configured.');
  1497. $msg_nok = t('You have not !link You should really do this if you want proper Google Indexing.', prod_check_link_array('set a pager suffix', $path));
  1498. }
  1499. $check['prod_check_page_title'] = array(
  1500. '#title' => t($title),
  1501. '#state' => !$error,
  1502. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING,
  1503. '#value_ok' => t('Enabled'),
  1504. '#value_nok' => $value_nok,
  1505. '#description_ok' => prod_check_ok_title($title_ok, $path, $text_ok),
  1506. '#description_nok' => $msg_nok,
  1507. '#nagios_key' => 'PTIT',
  1508. '#nagios_type' => 'state',
  1509. );
  1510. return prod_check_execute_check($check, $caller);
  1511. }
  1512. // Pathauto
  1513. function _prod_check_pathauto($caller = 'internal') {
  1514. $check = array();
  1515. $title_ok = 'settings';
  1516. $text_ok = 'Check the !link to verify if they are as you expect.';
  1517. $title = 'Path auto';
  1518. $path = 'admin/config/search/path/settings';
  1519. if ($caller != 'internal') {
  1520. $path = PRODCHECK_BASEURL . $path;
  1521. }
  1522. $check['prod_check_pathauto'] = array(
  1523. '#title' => t($title),
  1524. '#state' => module_exists('pathauto'),
  1525. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING,
  1526. '#value_ok' => t('Enabled'),
  1527. '#value_nok' => t('Disabled'),
  1528. '#description_ok' => prod_check_ok_title($title_ok, $path, $text_ok),
  1529. '#description_nok' => t('You have not enabled the !link module. This module is a must for search engines. Pathauto will automatically generate human readable URLs for every piece of content in the site.', prod_check_link_array($title, 'http://drupal.org/project/pathauto')),
  1530. '#nagios_key' => 'PATH',
  1531. '#nagios_type' => 'state',
  1532. );
  1533. return prod_check_execute_check($check, $caller);
  1534. }
  1535. // Redirect
  1536. function _prod_check_redirect($caller = 'internal') {
  1537. $check = array();
  1538. $title_ok = 'settings';
  1539. $text_ok = 'Check the !link to verify if they are as you expect.';
  1540. $title = 'Redirect';
  1541. $path = 'admin/config/search/redirect/settings';
  1542. if ($caller != 'internal') {
  1543. $path = PRODCHECK_BASEURL . $path;
  1544. }
  1545. $check['prod_check_redirect'] = array(
  1546. '#title' => t($title),
  1547. '#state' => module_exists('redirect'),
  1548. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING,
  1549. '#value_ok' => t('Enabled'),
  1550. '#value_nok' => t('Disabled'),
  1551. '#description_ok' => prod_check_ok_title($title_ok, $path, $text_ok),
  1552. '#description_nok' => t('You have not enabled the !link module. This module ensures, when properly configured, that when paths for content are changhed, the old paths are given a 301 redirect to the new paths.', prod_check_link_array($title, 'http://drupal.org/project/redirect')),
  1553. '#nagios_key' => 'REDIR',
  1554. '#nagios_type' => 'state',
  1555. );
  1556. return prod_check_execute_check($check, $caller);
  1557. }
  1558. // XML sitemap
  1559. function _prod_check_xmlsitemap($caller = 'internal') {
  1560. $check = array();
  1561. $title_ok = 'settings';
  1562. $text_ok = 'Check the !link to verify if they are as you expect.';
  1563. $title = 'XML sitemap';
  1564. $path = 'admin/config/search/xmlsitemap/settings';
  1565. if ($caller != 'internal') {
  1566. $path = PRODCHECK_BASEURL . $path;
  1567. }
  1568. $check['prod_check_sitemap'] = array(
  1569. '#title' => t($title),
  1570. '#state' => module_exists('xmlsitemap'),
  1571. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_WARNING : PROD_CHECK_REQUIREMENT_WARNING,
  1572. '#value_ok' => t('Enabled'),
  1573. '#value_nok' => t('Disabled'),
  1574. '#description_ok' => prod_check_ok_title($title_ok, $path, $text_ok),
  1575. '#description_nok' => t('You have not enabled the !link module. This module generates an XML sitemap which can be submitted to search engines, guaranteeing optimal indexation of all urls within the site.', prod_check_link_array($title, 'http://drupal.org/project/xmlsitemap')),
  1576. '#nagios_key' => 'XMLS',
  1577. '#nagios_type' => 'state',
  1578. );
  1579. return prod_check_execute_check($check, $caller);
  1580. }
  1581. // --- Production monitor only! ---
  1582. // Module list
  1583. function _prod_check_module_list($caller = 'internal') {
  1584. global $base_url;
  1585. $check = array();
  1586. $now = REQUEST_TIME;
  1587. $last = variable_get('prod_check_module_list_lastrun', 0);
  1588. // The if() is split up this way for full perfomance: we only run once a week,
  1589. // so on 6 out of 7 days, we won't pass the first if statement.
  1590. // First check if we are scheduled to run this day of the week. See
  1591. // prod_check_flush_caches() for the -1 case.
  1592. if (variable_get('prod_check_module_list_day', 0) == date('w', $now) || $last == -1){
  1593. // First check if we already ran today.
  1594. if (date('Ymd', $last) != date('Ymd', $now)) {
  1595. $time = explode(':', variable_get('prod_check_module_list_time', '03:00'));
  1596. // Only run if we are spot on, or past the scheduled point. This CAN cause
  1597. // a run hours after the scheduled time, all depending on the cron setup
  1598. // on the prod_monitor site!
  1599. if (date('H', $now) >= $time[0] && date('i', $now) >= $time[1]) {
  1600. module_load_include('inc', 'prod_check', 'includes/prod_check.update');
  1601. // PANIC! We don't cache this! Should we!? The core update module does
  1602. // (for one hour) but this function here ONLY gets called ONCE a week at
  1603. // a very specific given time. Feel free to comment.
  1604. $projects = array();
  1605. // Process enabled modules and themes.
  1606. _prod_check_process_info_list($projects, system_rebuild_module_data(), 'module', TRUE);
  1607. _prod_check_process_info_list($projects, system_rebuild_theme_data(), 'theme', TRUE);
  1608. // Process disabled modules and themes.
  1609. _prod_check_process_info_list($projects, system_rebuild_module_data(), 'module', FALSE);
  1610. _prod_check_process_info_list($projects, system_rebuild_theme_data(), 'theme', FALSE);
  1611. // Allow other modules to alter projects before fetching and comparing.
  1612. drupal_alter('update_projects', $projects);
  1613. $check['prod_check_module_list']['projects'] = $projects;
  1614. $check['prod_check_module_list']['site_key'] = drupal_hmac_base64($base_url, drupal_get_private_key());
  1615. $check['prod_check_module_list']['last_update'] = $now;
  1616. // Remember when we ran last.
  1617. variable_set('prod_check_module_list_lastrun', $now);
  1618. }
  1619. }
  1620. }
  1621. return prod_check_execute_check($check, $caller, 'prod_mon');
  1622. }
  1623. // Module list
  1624. function _prod_check_cron_last($caller = 'internal') {
  1625. $check = array();
  1626. $check['prod_check_cron_last'] = variable_get('cron_last', 0);
  1627. return prod_check_execute_check($check, $caller, 'prod_mon');
  1628. }