prod_check.module 72 KB

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