Last active
December 21, 2015 03:39
-
-
Save seanr/6244109 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Check/Hacked/Hacked.php b/Check/Hacked/Hacked.php | |
new file mode 100644 | |
index 0000000..4761c84 | |
--- /dev/null | |
+++ b/Check/Hacked/Hacked.php | |
@@ -0,0 +1,105 @@ | |
+<?php | |
+/** | |
+ * @file | |
+ * Contains \SiteAudit\Check\Hacked. | |
+ */ | |
+ | |
+class SiteAuditCheckHackedHacked extends SiteAuditCheckAbstract { | |
+ /** | |
+ * Implements \SiteAudit\Check\Abstract\getLabel(). | |
+ */ | |
+ public function getLabel() { | |
+ return dt('Hacked'); | |
+ } | |
+ | |
+ /** | |
+ * Implements \SiteAudit\Check\Abstract\getDescription(). | |
+ */ | |
+ public function getDescription() { | |
+ return dt('Determine whether core or contrib modules have been modified.'); | |
+ } | |
+ | |
+ /** | |
+ * Implements \SiteAudit\Check\Abstract\getResultFail(). | |
+ */ | |
+ public function getResultFail() { | |
+ return dt('Unable to determine whether core or contrib modules have been modified!'); | |
+ } | |
+ | |
+ /** | |
+ * Implements \SiteAudit\Check\Abstract\getResultInfo(). | |
+ */ | |
+ public function getResultInfo() { | |
+ return dt('Hacked! module not available to drush, either as part of site to be audited or in drush commands.'); | |
+ } | |
+ | |
+ /** | |
+ * Implements \SiteAudit\Check\Abstract\getResultPass(). | |
+ */ | |
+ public function getResultPass() { | |
+ return dt('No modifications were found.'); | |
+ } | |
+ | |
+ /** | |
+ * Implements \SiteAudit\Check\Abstract\getResultWarn(). | |
+ */ | |
+ public function getResultWarn() { | |
+ $ret_val = dt('The following extension(s) have been modified:'); | |
+ | |
+ if (drush_get_option('html')) { | |
+ $ret_val = '<p>' . $ret_val . '</p>'; | |
+ $ret_val .= '<table class="table table-condensed">'; | |
+ $ret_val .= '<thead><tr><th>Name</th><th>Title</th><th>Version</th><th>Changed</th></thead>'; | |
+ $ret_val .= '<tbody>'; | |
+ foreach ($this->registry['hacked'] as $row) { | |
+ $ret_val .= '<tr><td>' . implode('</td><td>', $row) . '</td></tr>'; | |
+ } | |
+ $ret_val .= '</tbody>'; | |
+ $ret_val .= '</table>'; | |
+ } | |
+ else { | |
+ foreach ($this->registry['hacked'] as $row) { | |
+ $ret_val .= PHP_EOL . str_repeat(' ', 6) . '- ' . implode(' -- ', $row); | |
+ } | |
+ } | |
+ return $ret_val; | |
+ } | |
+ | |
+ /** | |
+ * Implements \SiteAudit\Check\Abstract\getAction(). | |
+ */ | |
+ public function getAction() {} | |
+ | |
+ /** | |
+ * Implements \SiteAudit\Check\Abstract\calculateScore(). | |
+ */ | |
+ public function calculateScore() { | |
+ $result = drush_invoke_process('@self', 'hacked-list-projects', array(), array('--include-unchanged=0'), FALSE); | |
+ if ($result === FALSE) return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO; | |
+ | |
+ $rows = array(); | |
+ foreach ($result['object'] as $info) { | |
+ if ($info['counts']['different'] != 0) { | |
+ $rows[] = array( | |
+ $info['project_name'], | |
+ $info['title'], | |
+ $info['existing_version'], | |
+ $info['counts']['different'], | |
+ ); | |
+ } | |
+ } | |
+ | |
+ $this->registry['hacked'] = $result; | |
+ if (empty($result['object'])) { | |
+ $this->abort = TRUE; | |
+ return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL; | |
+ } | |
+ else if (!empty($rows)) { | |
+ $this->registry['hacked'] = $rows; | |
+ return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_WARN; | |
+ } | |
+ else { | |
+ return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS; | |
+ } | |
+ } | |
+} | |
diff --git a/Report/Hacked.php b/Report/Hacked.php | |
new file mode 100644 | |
index 0000000..7c6fb48 | |
--- /dev/null | |
+++ b/Report/Hacked.php | |
@@ -0,0 +1,23 @@ | |
+<?php | |
+/** | |
+ * @file | |
+ * Contains \SiteAudit\Report\Hacked. | |
+ */ | |
+ | |
+class SiteAuditReportHacked extends SiteAuditReportAbstract { | |
+ /** | |
+ * Implements \SiteAudit\Report\Abstract\getLabel(). | |
+ */ | |
+ public function getLabel() { | |
+ return dt('Hacked'); | |
+ } | |
+ | |
+ /** | |
+ * Implements \SiteAudit\Report\Abstract\getCheckNames(). | |
+ */ | |
+ public function getCheckNames() { | |
+ return array( | |
+ 'Hacked', | |
+ ); | |
+ } | |
+} | |
diff --git a/site_audit.drush.inc b/site_audit.drush.inc | |
index 8721920..859911b 100644 | |
--- a/site_audit.drush.inc | |
+++ b/site_audit.drush.inc | |
@@ -106,6 +106,13 @@ function site_audit_drush_command() { | |
'options' => $options, | |
); | |
+ $items['audit_hacked'] = array( | |
+ 'description' => dt('Audit the codebase to check for modifications to core and contrib extensions.'), | |
+ 'aliases' => array('ah'), | |
+ 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL, | |
+ 'options' => $options, | |
+ ); | |
+ | |
$arguments_gi = array( | |
'url' => dt('The URL that you wish to test.'), | |
'key' => dt('Google Code API Key - see https://developers.google.com/speed/docs/insights/v1/getting_started#auth'), | |
@@ -189,6 +196,9 @@ function site_audit_drush_help($section) { | |
case 'drush:audit_views': | |
return dt('Audit Views displays'); | |
+ case 'drush:audit_hacked': | |
+ return dt('Audit the codebase to check for modifications to core and contrib extensions.'); | |
+ | |
case 'meta:site_audit:title': | |
return dt('Tools for auditing a Drupal site'); | |
@@ -410,6 +420,14 @@ function drush_site_audit_audit_views() { | |
} | |
/** | |
+ * Audit the codebase to check for modifications to core and contrib extensions. | |
+ */ | |
+function drush_site_audit_audit_hacked() { | |
+ $report = new SiteAuditReportHacked(); | |
+ $report->render(); | |
+} | |
+ | |
+/** | |
* Validate parameters. | |
* | |
* @param string $url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment