diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index 0fc307a260..19b6501b98 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -766,6 +766,12 @@ function drupal_settings_initialize() { if (file_exists(DRUPAL_ROOT . '/' . conf_path() . '/settings.php')) { include_once DRUPAL_ROOT . '/' . conf_path() . '/settings.php'; } + + // Auth Tag1 D7ES module on Pantheon + if (getenv('PANTHEON_D7ES_API_KEY')) { + $conf['tag1_d7es_billing_email'] = getenv('PANTHEON_D7ES_API_KEY'); + } + $is_https = drupal_is_https(); // Load environmental config, if present. diff --git a/modules/pantheon/tag1_d7es/LICENSE.txt b/modules/pantheon/tag1_d7es/LICENSE.txt new file mode 100644 index 0000000000..d159169d10 --- /dev/null +++ b/modules/pantheon/tag1_d7es/LICENSE.txt @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/modules/pantheon/tag1_d7es/README.md b/modules/pantheon/tag1_d7es/README.md new file mode 100644 index 0000000000..9777874df8 --- /dev/null +++ b/modules/pantheon/tag1_d7es/README.md @@ -0,0 +1,52 @@ +# tag1_d7es + +Drupal 7 module to support Tag1's D7ES offering. + +Installation and use of this module constitutes your acceptance of and agreement +to be bound by Tag1 Consulting Inc's Terms of Service and Privacy Policy, +as published at D7ES.Tag1.com. + +## Requirements +* A properly configured [cron job](https://www.drupal.org/docs/7/setting-up-cron/overview) +* An active customer account created at https://d7es.tag1.com/ + +## Configuration +1. Download and enable the module as usual. +2. Visit the module's configuration page at `/admin/config/system/tag1-d7es` and +enter the Billing email address used when creating the customer account. You +will also need to supply one or more email addresses that should be notified of +available security updates. +3. Save the form. Status messages will let you know if the site is authenticated +and sending data successfully. + +## How does it work? +This module will report the following information about your site to the Tag1 +D7ES team: + +* the version of Drupal core +* name and version of contributed modules and themes +* database type and version +* PHP version +* the URL of your website +* the billing account email address +* list of email addresses who should be notified when a security update is available + +This report is submitted via a cron job a maximum of once per 24 hours. + +The full JSON payload sent by your site may be previewed from the module's +configuration page under the "Debugging" fieldset. + +## For extra security + +For extra security, you may wish to configure the "Billing email address" and +"Notification email addresses" outside of the site's database. You can use the +variables `tag1_d7es_billing_email` and `tag1_d7es_email_addresses` to define +these values directly in settings.php, or by calling an environment variable. + +```php +// Including value in code. +$conf['tag1_d7es_billing_email'] = 'my-billing@email.com'; + +// Sourcing from an environment variable. +$conf['tag1_d7es_billing_email'] = $_ENV['MY_BILLING_EMAIL_VARIABLE']; +``` diff --git a/modules/pantheon/tag1_d7es/includes/uuid.inc b/modules/pantheon/tag1_d7es/includes/uuid.inc new file mode 100644 index 0000000000..293f9756df --- /dev/null +++ b/modules/pantheon/tag1_d7es/includes/uuid.inc @@ -0,0 +1,70 @@ +Installation and use of this module constitutes your acceptance of and agreement to be bound by Tag1 Consulting Inc's Terms of Service and Privacy Policy, as published at D7ES.Tag1.com. +core = 7.x +package = Tag1 +configure = admin/config/system/tag1-d7es +files[] = tests/tag1_d7es.test +files[] = tests/tag1_d7es_ctools.test +files[] = tests/tag1_d7es_admin.test +files[] = tests/tag1_d7es_admin_ctools.test +files[] = tests/tag1_d7es_fetch_url.test +files[] = tests/tag1_d7es_mail.test +files[] = tests/tag1_d7es_update.test + +; Information added by Drupal.org packaging script on 2024-11-27 +version = "7.x-1.1" +core = "7.x" +project = "tag1_d7es" +datestamp = "1732731772" diff --git a/modules/pantheon/tag1_d7es/tag1_d7es.install b/modules/pantheon/tag1_d7es/tag1_d7es.install new file mode 100644 index 0000000000..f1d76f77f0 --- /dev/null +++ b/modules/pantheon/tag1_d7es/tag1_d7es.install @@ -0,0 +1,95 @@ +configuration page to configure authentication and notifications. Installation and use of this module constitutes your acceptance of and agreement to be bound by Tag1 Consulting Inc\'s Terms of Service and Privacy Policy, as published at D7ES.Tag1.com.')); +} + +/** + * Implements hook_uninstall(). + */ +function tag1_d7es_uninstall() { + if (variable_get('tag1_d7es_original_update_fetch_url')) { + variable_set('update_fetch_url', variable_get('tag1_d7es_original_update_fetch_url')); + variable_del('tag1_d7es_original_update_fetch_url'); + } + else { + variable_del('update_fetch_url'); + } + variable_del('tag1_d7es_site_id'); + variable_del('tag1_d7es_phone_home'); + variable_del('tag1_d7es_billing_email'); + variable_del('tag1_d7es_email_addresses'); + variable_del('tag1_d7es_endpoint'); + variable_del('tag1_d7es_send_update_emails'); +} + +/** + * Implements hook_requirements(). + */ +function tag1_d7es_requirements($phase) { + $requirements = array(); + + // Display reporting status. + if ($phase == 'runtime') { + $description = ''; + $last_phone_home = variable_get('tag1_d7es_phone_home'); + if ($last_phone_home == 0) { + $value = t('Never'); + $description = t('The Tag1 D7ES module has not successfully connected. Please visit the configuration page to configure authentication and notifications.'); + $severity = REQUIREMENT_ERROR; + } + elseif (is_null(variable_get('tag1_d7es_billing_email')) || is_null(variable_get('tag1_d7es_email_addresses'))) { + $value = t('Missing configuration'); + $description = t('The Tag1 D7ES module is missing key configuration. Please visit the configuration page to configure authentication and notifications.'); + $severity = REQUIREMENT_ERROR; + } + elseif ($last_phone_home <= REQUEST_TIME - 604800) { + $value = t('Last run: %phone-home-last ago.', array( + '%phone-home-last' => format_interval(REQUEST_TIME - $last_phone_home), + )); + $description = t('Last report sent over a week ago. Please check that cron is running successfully.'); + $severity = REQUIREMENT_WARNING; + } + else { + $value = t('Last run: %phone-home-last ago.', array( + '%phone-home-last' => format_interval(REQUEST_TIME - $last_phone_home), + )); + $severity = REQUIREMENT_OK; + } + + $requirements['tag1_d7es'] = array( + 'title' => 'Tag1 D7ES', + 'value' => $value, + 'description' => $description, + 'severity' => $severity, + ); + } + + return $requirements; +} + +/** + * Set update_fetch_url if able. + */ +function tag1_d7es_update_7100(&$sandbox) { + if (variable_get('update_fetch_url')) { + variable_set('tag1_d7es_original_update_fetch_url', variable_get('update_fetch_url')); + } + if (variable_get('tag1_d7es_phone_home')) { + variable_set('update_fetch_url', tag1_d7es_personalize_updates_endpoint()); + } +} diff --git a/modules/pantheon/tag1_d7es/tag1_d7es.module b/modules/pantheon/tag1_d7es/tag1_d7es.module new file mode 100644 index 0000000000..acf731b720 --- /dev/null +++ b/modules/pantheon/tag1_d7es/tag1_d7es.module @@ -0,0 +1,897 @@ +the configuration page (under advanced settings) to correct it."; + watchdog( + 'tag1_d7es', + $log_message, + array(), + WATCHDOG_ERROR + ); + if ($display_messages) { + drupal_set_message($config_error, 'error'); + } + return FALSE; + } + + // Ensure the billing email address is provided. + if (!$billing_email) { + $config_error = 'Unable to send data because the billing email address is not provided.'; + $message = "$config_error Please visit the configuration page to provide it."; + watchdog( + 'tag1_d7es', + $message, + array(), + WATCHDOG_ERROR + ); + if ($display_messages) { + drupal_set_message($config_error, 'error'); + } + return FALSE; + } + + return TRUE; +} + +/** + * Send data to Tag1. + * + * @param string $billing_email + * The primary billing email address, used for authentication. + * @param array $data + * The data payload. + * @param bool $display_messages + * Whether messages should be displayed in addition to being logged. + * @param string $override_url + * Allows validation against a new endpoint without officially saving it. + * + * @return bool + * Returns TRUE if the transmission was successful. + */ +function _tag1_d7es_transmit($billing_email, $data, $display_messages = FALSE, $override_url = '') { + $url = $override_url ?: _tag1_d7es_get_endpoint(); + $auth_token = base64_encode($billing_email); + $headers = array( + 'Content-Type' => 'application/json', + 'Authorization' => 'Basic ' . $auth_token, + 'x-api-key' => $auth_token, + ); + $options = array( + 'method' => 'POST', + 'headers' => $headers, + 'data' => json_encode($data), + ); + + $response = drupal_http_request($url, $options); + switch ($response->code) { + case 200: + $message = 'Tag1 D7ES information transmitted successfully.'; + watchdog( + 'tag1_d7es', + $message, + array(), + WATCHDOG_INFO + ); + variable_set('tag1_d7es_phone_home', REQUEST_TIME); + if ($display_messages) { + drupal_set_message($message, 'status'); + } + return TRUE; + + case 403: + $message = 'Authentication error. Please review the billing address and API endpoint (if configured).'; + watchdog( + 'tag1_d7es', + $message, + array(), + WATCHDOG_ERROR + ); + if ($display_messages) { + drupal_set_message($message, 'error'); + } + return FALSE; + + default: + $variables = array( + '%response_code' => $response->code, + '%message' => '', + '%error' => '', + ); + $error_data = json_decode($response->data); + if (isset($error_data->message)) { + $variables['%message'] = $error_data->message; + } + if (isset($error_data->error)) { + $variables['%error'] = $error_data->error; + } + watchdog( + 'tag1_d7es', + 'Failure sending information to Tag1 D7ES: "%response_code %message %error".', + $variables, + WATCHDOG_ERROR + ); + if ($display_messages) { + drupal_set_message(t('Module report failed to submit. Please review the site error logs for more information.'), 'error'); + } + } + return FALSE; +} + +/** + * Build the phone-home payload. + * + * @param string $site_id + * Pass the site ID if it's already known. + * @param string $billing_email + * Pass the billing email if it's already known. + * + * @return array + * The data array for the request. + */ +function _tag1_d7es_payload($site_id = '', $billing_email = '') { + if (!$site_id) { + $site_id = variable_get('tag1_d7es_site_id'); + } + if (!$billing_email) { + $billing_email = variable_get('tag1_d7es_billing_email'); + } + $data = _tag1_d7es_runtime_info() + array( + 'siteId' => $site_id, + 'timestamp' => REQUEST_TIME, + 'siteUrl' => $GLOBALS['base_url'], + 'billingEmail' => $billing_email, + ); + + // Email addresses are optional. + $data['emails'] = array(); + $emails = variable_get('tag1_d7es_email_addresses', NULL); + if ($emails) { + $data['emails'] = array_map('trim', explode(',', $emails)); + } + + // Add module and theme data. + $data['modules'] = _tag1_d7es_project_info(system_rebuild_module_data()); + $data['themes'] = _tag1_d7es_project_info(system_rebuild_theme_data()); + + // Add platform-specific data. + if (tag1_d7es_detect_platform() == TAG1_D7ES_PLATFORM_PANTHEON) { + if (getenv('PANTHEON_SITE')) { + $data['pantheonSiteId'] = getenv('PANTHEON_SITE'); + } + if (getenv('PANTHEON_DEPLOYMENT_IDENTIFIER')) { + $data['pantheonBuildId'] = getenv('PANTHEON_DEPLOYMENT_IDENTIFIER'); + } + } + + return $data; +} + +/** + * Determine the endpoint to use. + * + * @return string + * The URL for the API endpoint. + */ +function _tag1_d7es_get_endpoint() { + return variable_get('tag1_d7es_endpoint', TAG1_D7ES_ENDPOINT); +} + +/** + * Build module/theme information. + * + * @param array $projects + * A list of projects returned by system_rebuild_module_data() and + * system_rebuild_theme_data(). + * + * @return array + * Parsed data array for projects. + */ +function _tag1_d7es_project_info(array $projects) { + $data = []; + + // Remove hidden and core projects. + foreach ($projects as $project) { + if (!isset($project->info['hidden']) && (!isset($project->info['package']) || $project->info['package'] != 'Core')) { + $data[] = array( + 'name' => $project->name, + 'version' => isset($project->info['version']) ? $project->info['version'] : '', + 'enabled' => (bool) $project->status, + ); + } + } + + return $data; +} + +/** + * Build system runtime information. + * + * @return array + * Specific runtime information to include with the data payload. + */ +function _tag1_d7es_runtime_info() { + // Map runtime string identifier with desired $data key. + $key_mapping = array( + 'drupal' => 'core', + 'database_system_version' => 'dbVersion', + ); + + // Poll runtime information. See system_status(); + include_once DRUPAL_ROOT . '/includes/install.inc'; + drupal_load_updates(); + $runtime = module_invoke('system', 'requirements', 'runtime'); + + // Build data array. + $data = array(); + foreach ($key_mapping as $key => $value) { + if (array_key_exists($key, $runtime)) { + $data[$value] = $runtime[$key]['value']; + } + } + + // Easier to add PHP info directly. + $data['php'] = phpversion(); + + return $data; +} + +/** + * Implements hook_menu(). + */ +function tag1_d7es_menu() { + $items['admin/config/system/tag1-d7es'] = array( + 'title' => 'Tag1 D7ES', + 'description' => 'Configure the credentials and notification settings for Tag1 D7ES.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('tag1_d7es_admin_form'), + 'access arguments' => array('administer site configuration'), + ); + return $items; +} + +/** + * Form constructor for the tag1_d7es system settings. + * + * @see tag1_d7es_admin_form_submit() + * @ingroup forms + */ +function tag1_d7es_admin_form($form, $form_state) { + $form['description'] = array( + '#type' => 'markup', + '#markup' => '

' . t("Configure this module to communicate with Tag1's D7ES service. Installation and use of this module constitutes your acceptance of and agreement to be bound by Tag1 Consulting Inc's Terms of Service and Privacy Policy, as published at D7ES.Tag1.com") . '

', + ); + + // The billing email address is only needed for non-platform customers. + $form['tag1_d7es_billing_email'] = array( + '#type' => 'textfield', + '#title' => t('Billing email address'), + '#size' => 80, + '#maxlength' => 255, + '#default_value' => variable_get('tag1_d7es_billing_email', ''), + '#required' => TRUE, + '#description' => t('The primary billing email address.'), + '#access' => !(tag1_d7es_detect_platform()), + ); + + $form['tag1_d7es_email_addresses'] = array( + '#type' => 'textfield', + '#title' => t('Notification email addresses'), + '#size' => 80, + '#maxlength' => 255, + '#default_value' => variable_get('tag1_d7es_email_addresses', ''), + '#required' => TRUE, + '#description' => t('A comma-separated list of email addresses that should receive notifications about available updates.'), + ); + + $form['tag1_d7es_send_update_emails'] = array( + '#type' => 'checkbox', + '#title' => t('Continue to send core "Available updates" notifications.'), + '#access' => module_exists('update') && variable_get('update_notify_emails'), + '#description' => t('To prevent duplicate email notifications of an update, this module disables the emails from the Update Status module by default.'), + '#default_value' => variable_get('tag1_d7es_send_update_emails', 0), + ); + + $form['advanced'] = array( + '#type' => 'fieldset', + '#title' => t('Advanced'), + '#collapsed' => TRUE, + '#collapsible' => TRUE, + ); + $form['advanced']['tag1_d7es_site_id'] = array( + '#type' => 'textfield', + '#title' => t('Site ID'), + '#required' => TRUE, + '#default_value' => variable_get('tag1_d7es_site_id', ''), + '#description' => t('A UUID created on module installation that is specific to your site. In regular operations this value should not need to be changed.'), + ); + $form['advanced']['tag1_d7es_endpoint'] = array( + '#type' => 'textfield', + '#title' => t('API Endpoint'), + '#default_value' => variable_get('tag1_d7es_endpoint'), + '#description' => t('A different API endpoint to use (typically for testing purposes). In regular operations this value should not need to be changed.'), + ); + + $form['advanced']['drush_endpoint'] = array( + '#type' => 'markup', + '#markup' => ' +' . tag1_d7es_personalize_drush_source_endpoint() . ' +
You can use this URL to configure Drush for updates
', + '#access' => (variable_get('update_fetch_url') && !tag1_d7es_detect_platform()), + ); + + $form['actions'] = array('#type' => 'actions'); + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => t('Save configuration'), + ); + + $form['debugging'] = array( + '#type' => 'fieldset', + '#title' => t('Debugging'), + '#collapsed' => TRUE, + '#collapsible' => TRUE, + ); + $form['debugging']['payload'] = array( + '#type' => 'textarea', + '#title' => t('Payload'), + '#default_value' => json_encode(_tag1_d7es_payload()), + ); + + $form['#validate'][] = 'tag1_d7es_admin_form_validate'; + + return $form; +} + +/** + * Form validation handler for tag1_d7es_admin_form(). + */ +function tag1_d7es_admin_form_validate($form, &$form_state) { + if (!tag1_d7es_uuid_is_valid($form_state['values']['tag1_d7es_site_id'])) { + form_set_error('tag1_d7es_site_id', t('The Site ID is not a valid UUID.')); + } +} + +/** + * Form submission handler for tag1_d7es_admin_form(). + */ +function tag1_d7es_admin_form_submit($form, &$form_state) { + // If the module is freshly installed, or if the billing address or API + // endpoint has changed, verify that we can make a request to the API. + if ( + !drupal_valid_test_ua() && ( + variable_get('tag1_d7es_phone_home') === 0 || + $form_state['values']['tag1_d7es_billing_email'] != variable_get('tag1_d7es_billing_email') || + (isset($form_state['values']['tag1_d7es_endpoint']) && $form_state['values']['tag1_d7es_endpoint'] != _tag1_d7es_get_endpoint()) + ) + ) { + $submitted_billing_email = $form_state['values']['tag1_d7es_billing_email']; + $submitted_api_endpoint = $form_state['values']['tag1_d7es_endpoint'] ?: TAG1_D7ES_ENDPOINT; + $preflight = tag1_d7es_preflight($form_state['values']['tag1_d7es_site_id'], $submitted_billing_email, TRUE); + if ($preflight) { + $data = _tag1_d7es_payload($form_state['values']['tag1_d7es_site_id'], $form_state['values']['tag1_d7es_billing_email']); + $success = _tag1_d7es_transmit($submitted_billing_email, $data, TRUE, $submitted_api_endpoint); + if ($success) { + variable_set('tag1_d7es_phone_home', REQUEST_TIME); + variable_set('update_fetch_url', tag1_d7es_personalize_updates_endpoint($submitted_billing_email)); + } + } + } + + system_settings_form_submit($form, $form_state); + if ($form_state['values']['tag1_d7es_endpoint'] === '' || $form_state['values']['tag1_d7es_endpoint'] === TAG1_D7ES_ENDPOINT) { + variable_del('tag1_d7es_endpoint'); + } + +} + +/** + * Determine the customer-specific Release XML endpoint. + * + * @param string $billing_email + * The billing email address for personalization. + */ +function tag1_d7es_personalize_updates_endpoint($billing_email = '') { + if (!$billing_email) { + $billing_email = variable_get('tag1_d7es_billing_email'); + } + $base_url = TAG1_D7ES_UPDATES_ENDPOINT; + $auth = $billing_email . ':' . base64_encode($billing_email) . '@'; + return substr_replace($base_url, $auth, (strpos($base_url, '//') + 2), 0); +} + +/** + * Determine the customer-specific Drush source XML endpoint. + * + * @param string $billing_email + * The billing email address for personalization. + */ +function tag1_d7es_personalize_drush_source_endpoint($billing_email = '') { + if (!$billing_email) { + $billing_email = variable_get('tag1_d7es_billing_email', ''); + } + $base_url = TAG1_D7ES_UPDATES_ENDPOINT; + $auth = urlencode($billing_email) . ':' . urlencode(base64_encode($billing_email)) . '@'; + return substr_replace($base_url, $auth, (strpos($base_url, '//') + 2), 0); +} + +/** + * Determine if this is a platform-level customer. + * + * @return string|bool + * Returns the platform name if detected, FALSE otherwise. + */ +function tag1_d7es_detect_platform() { + if (getenv('PANTHEON_ENVIRONMENT') && getenv('PANTHEON_D7ES_API_KEY')) { + return TAG1_D7ES_PLATFORM_PANTHEON; + } + + return FALSE; +} + +/** + * Wrapper function to create UUIDs. + * + * Uses ctools or the UUID module if either is enabled. Like in + * ctools_uuid_generate(), we are copying this from the ctools and uuid modules. + * + * @see http://php.net/uniqid#65879 + * + * @return string + * A generated UUID. + */ +function tag1_d7es_uuid_generate() { + if (module_exists('ctools')) { + return ctools_uuid_generate(); + } + elseif (module_exists('uuid')) { + return uuid_generate(); + } + else { + module_load_include('inc', 'tag1_d7es', 'includes/uuid'); + + $callback = &drupal_static(__FUNCTION__); + + if (empty($callback)) { + if (function_exists('uuid_create') && !function_exists('uuid_make')) { + $callback = '_tag1_d7es_uuid_generate_pecl'; + } + elseif (function_exists('com_create_guid')) { + $callback = '_tag1_d7es_uuid_generate_com'; + } + else { + $callback = '_tag1_d7es_uuid_generate_php'; + } + } + return $callback(); + } +} + +/** + * Check that a string is in the format of a UUID. Copied from CTools. + * + * @param string $uuid + * The string to test. + * + * @return bool + * TRUE if the string is well-formed. + * + * @see http://drupal.org/project/ctools + * @see http://drupal.org/project/uuid + */ +function tag1_d7es_uuid_is_valid($uuid = '') { + if (empty($uuid)) { + return FALSE; + } + if (module_exists('ctools')) { + return ctools_uuid_is_valid($uuid); + } + elseif (function_exists('uuid_is_valid') || module_exists('uuid')) { + return uuid_is_valid($uuid); + } + else { + module_load_include('inc', 'tag1_d7es', 'includes/uuid'); + return uuid_is_valid($uuid); + } +} + +/** + * Implements hook_mail_alter(). + */ +function tag1_d7es_mail_alter(&$message) { + if ($message['id'] == 'update_status_notify') { + if (variable_get('tag1_d7es_send_update_emails', 0) !== 1) { + $message['send'] = FALSE; + } + } +} + +/** + * Determine if the subscription is still active. + * + * @return bool + * Whether the subscription should be considered active. + */ +function tag1_d7es_subscription_is_active() { + // We expect the module to report successfully at least once per week. + return variable_get('tag1_d7es_phone_home', 0) >= REQUEST_TIME - (TAG1_D7ES_PHONE_HOME_PERIOD * 7); +} + +/** + * Implements hook_update_status_alter(). + */ +function tag1_d7es_update_status_alter(&$projects) { + $available = update_get_available(); + foreach ($projects as &$project_data) { + if (tag1_d7es_subscription_is_active()) { + // All projects from Drupal.org will have this status at D7 EOL. + if ($project_data['status'] === UPDATE_NOT_SUPPORTED) { + // See if we can determine an updated release. + unset($project_data['status']); + unset($project_data['extra']); + + // BEGIN from update_calculate_project_update_status(). + // Figure out the target major version. + $existing_major = $project_data['existing_major']; + $supported_majors = array(); + if (isset($available[$project_data['name']]['supported_majors'])) { + $supported_majors = explode(',', $available[$project_data['name']]['supported_majors']); + } + elseif (isset($available[$project_data['name']]['default_major'])) { + // Older release history XML file without supported or recommended. + $supported_majors[] = $available[$project_data['name']]['default_major']; + } + + if (in_array($existing_major, $supported_majors)) { + // Still supported, stay at the current major version. + $target_major = $existing_major; + } + elseif (isset($available[$project_data['name']]['recommended_major'])) { + // Since 'recommended_major' is defined, we know this is the new XML + // format. Therefore, we know the current release is unsupported since + // its major version was not in the 'supported_majors' list. We should + // find the best release from the recommended major version. + $target_major = $available[$project_data['name']]['recommended_major']; + $project_data['status'] = UPDATE_NOT_SUPPORTED; + } + elseif (isset($available[$project_data['name']]['default_major'])) { + // Older release history XML file without recommended, so recommend + // the currently defined "default_major" version. + $target_major = $available[$project_data['name']]['default_major']; + } + else { + // Malformed XML file? Stick with the current version. + $target_major = $existing_major; + } + + // Make sure we never tell the admin to downgrade. If we recommended an + // earlier version than the one they're running, they'd face an + // impossible data migration problem, since Drupal never supports a DB + // downgrade path. In the unfortunate case that what they're running is + // unsupported, and there's nothing newer for them to upgrade to, we + // can't print out a "Recommended version", but just have to tell them + // what they have is unsupported and let them figure it out. + $target_major = max($existing_major, $target_major); + + $release_patch_changed = ''; + $patch = ''; + + // If the project is marked as UPDATE_FETCH_PENDING, it means that the + // data we currently have (if any) is stale, and we've got a task queued + // up to (re)fetch the data. In that case, we mark it as such, merge in + // whatever data we have (e.g. project title and link), and move on. + if (!empty($available[$project_data['name']]['fetch_status']) && $available[$project_data['name']]['fetch_status'] == UPDATE_FETCH_PENDING) { + $project_data['status'] = UPDATE_FETCH_PENDING; + $project_data['reason'] = t('No available update data'); + $project_data['fetch_status'] = $available[$project_data['name']]['fetch_status']; + return; + } + + // Defend ourselves from XML history files that contain no releases. + if (empty($available[$project_data['name']]['releases'])) { + $project_data['status'] = UPDATE_UNKNOWN; + $project_data['reason'] = t('No available releases found'); + return; + } + foreach ($available[$project_data['name']]['releases'] as $version => $release) { + // First, if this is the existing release, check a few conditions. + if ($project_data['existing_version'] === $version) { + if (isset($release['terms']['Release type']) && + in_array('Insecure', $release['terms']['Release type'])) { + $project_data['status'] = UPDATE_NOT_SECURE; + } + elseif ($release['status'] == 'unpublished') { + $project_data['status'] = UPDATE_REVOKED; + if (empty($project_data['extra'])) { + $project_data['extra'] = array(); + } + $project_data['extra'][] = array( + 'class' => array('release-revoked'), + 'label' => t('Release revoked'), + 'data' => t('Your currently installed release has been revoked, and is no longer available for download. Disabling everything included in this release or upgrading is strongly recommended!'), + ); + } + elseif (isset($release['terms']['Release type']) && + in_array('Unsupported', $release['terms']['Release type'])) { + $project_data['status'] = UPDATE_NOT_SUPPORTED; + if (empty($project_data['extra'])) { + $project_data['extra'] = array(); + } + $project_data['extra'][] = array( + 'class' => array('release-not-supported'), + 'label' => t('Release not supported'), + 'data' => t('Your currently installed release is now unsupported, and is no longer available for download. Disabling everything included in this release or upgrading is strongly recommended!'), + ); + } + } + + // Otherwise, ignore unpublished, insecure, or unsupported releases. + if ($release['status'] == 'unpublished' || + (isset($release['terms']['Release type']) && + (in_array('Insecure', $release['terms']['Release type']) || + in_array('Unsupported', $release['terms']['Release type'])))) { + continue; + } + + // See if this is a higher major version than our target and yet still + // supported. If so, record it as an "Also available" release. + // Note: some projects have a HEAD release from CVS days, which could + // be one of those being compared. They would not have version_major + // set, so we must call isset first. + if (isset($release['version_major']) && $release['version_major'] > $target_major) { + if (in_array($release['version_major'], $supported_majors)) { + if (!isset($project_data['also'])) { + $project_data['also'] = array(); + } + if (!isset($project_data['also'][$release['version_major']])) { + $project_data['also'][$release['version_major']] = $version; + $project_data['releases'][$version] = $release; + } + } + // Otherwise, this release can't matter to us, since it's neither + // from the release series we're currently using nor the recommended + // release. We don't even care about security updates for this + // branch, since if a project maintainer puts out a security release + // at a higher major version and not at the lower major version, + // they must remove the lower version from the supported major + // versions at the same time, in which case we won't hit this code. + continue; + } + + // Look for the 'latest version' if we haven't found it yet. Latest is + // defined as the most recent version for the target major version. + if (!isset($project_data['latest_version']) + && $release['version_major'] == $target_major) { + $project_data['latest_version'] = $version; + $project_data['releases'][$version] = $release; + } + + // Look for the development snapshot release for this branch. + if (!isset($project_data['dev_version']) + && $release['version_major'] == $target_major + && isset($release['version_extra']) + && $release['version_extra'] == 'dev') { + $project_data['dev_version'] = $version; + $project_data['releases'][$version] = $release; + } + + // Look for the 'recommended' version if we haven't found it yet (see + // phpdoc at the top of this function for the definition). + if (!isset($project_data['recommended']) + && $release['version_major'] == $target_major + && isset($release['version_patch'])) { + if ($patch != $release['version_patch']) { + $patch = $release['version_patch']; + $release_patch_changed = $release; + } + if (empty($release['version_extra']) && $patch == $release['version_patch']) { + $project_data['recommended'] = $release_patch_changed['version']; + $project_data['releases'][$release_patch_changed['version']] = $release_patch_changed; + } + } + + // Stop searching once we hit the currently installed version. + if ($project_data['existing_version'] === $version) { + break; + } + + // If we're running a dev snapshot and have a timestamp, stop + // searching for security updates once we hit an official release + // older than what we've got. Allow 100 seconds of leeway to handle + // differences between the datestamp in the .info file and the + // timestamp of the tarball itself (which are usually off by 1 or 2 + // seconds) so that we don't flag that as a new release. + if ($project_data['install_type'] == 'dev') { + if (empty($project_data['datestamp'])) { + // We don't have current timestamp info, so we can't know. + continue; + } + elseif (isset($release['date']) && ($project_data['datestamp'] + 100 > $release['date'])) { + // We're newer than this, so we can skip it. + continue; + } + } + + // See if this release is a security update. + if (isset($release['terms']['Release type']) + && in_array('Security update', $release['terms']['Release type'])) { + $project_data['security updates'][] = $release; + } + } + + // If we were unable to find a recommended version, then make the latest + // version the recommended version if possible. + if (!isset($project_data['recommended']) && isset($project_data['latest_version'])) { + $project_data['recommended'] = $project_data['latest_version']; + } + + // Check to see if we need an update or not. + if (!empty($project_data['security updates'])) { + // If we found security updates, that always trumps any other status. + $project_data['status'] = UPDATE_NOT_SECURE; + } + + if (isset($project_data['status'])) { + // If we already know the status, we're done. + return; + } + + // If we don't know what to recommend, there's nothing we can report. + // Bail out early. + if (!isset($project_data['recommended'])) { + $project_data['status'] = UPDATE_UNKNOWN; + $project_data['reason'] = t('No available releases found'); + return; + } + + // If we're running a dev snapshot, compare the date of the dev snapshot + // with the latest official version, and record the absolute latest in + // 'latest_dev' so we can correctly decide if there's a newer release + // than our current snapshot. + if ($project_data['install_type'] == 'dev') { + if (isset($project_data['dev_version']) && $available[$project_data['name']]['releases'][$project_data['dev_version']]['date'] > $available[$project_data['name']]['releases'][$project_data['latest_version']]['date']) { + $project_data['latest_dev'] = $project_data['dev_version']; + } + else { + $project_data['latest_dev'] = $project_data['latest_version']; + } + } + + // Figure out the status, based on what we've seen and the install type. + switch ($project_data['install_type']) { + case 'official': + if ($project_data['existing_version'] === $project_data['recommended'] || $project_data['existing_version'] === $project_data['latest_version']) { + $project_data['status'] = UPDATE_CURRENT; + } + else { + $project_data['status'] = UPDATE_NOT_CURRENT; + } + break; + + case 'dev': + $latest = $available[$project_data['name']]['releases'][$project_data['latest_dev']]; + if (empty($project_data['datestamp'])) { + $project_data['status'] = UPDATE_NOT_CHECKED; + $project_data['reason'] = t('Unknown release date'); + } + elseif (($project_data['datestamp'] + 100 > $latest['date'])) { + $project_data['status'] = UPDATE_CURRENT; + } + else { + $project_data['status'] = UPDATE_NOT_CURRENT; + } + break; + + default: + $project_data['status'] = UPDATE_UNKNOWN; + $project_data['reason'] = t('Invalid info'); + } + // END from update_calculate_project_update_status(). + } + } + else { + // Module is enabled but subscription has lapsed. + if (in_array($project_data['status'], [UPDATE_NOT_SECURE, UPDATE_NOT_CURRENT])) { + if (isset($project_data['recommended'])) { + $version = $project_data['recommended']; + } + elseif (isset($project_data['latest_version'])) { + $version = $project_data['latest_version']; + } + else { + $version = NULL; + } + if ($version && isset($project_data['releases']) && isset($project_data['releases'][$version])) { + $release = $project_data['releases'][$version]; + if (isset($release['terms']['Release type']) && + in_array('Tag1 D7ES', $release['terms']['Release type'])) { + $project_data['status'] = UPDATE_NOT_SUPPORTED; + } + } + } + } + + // Handle projects that we specify as Insecure via our update XML. + if ($project_data['status'] === UPDATE_NOT_SECURE && !isset($project_data['recommended'])) { + // Switch to more generic messaging. + $project_data['status'] = UPDATE_NOT_SUPPORTED; + if (isset($available[$project_data['name']]['recommended_alternative']) && tag1_d7es_subscription_is_active()) { + $message = $available[$project_data['name']]['recommended_alternative']; + } + else { + $message = t('This project is no longer supported, and is no longer available for download. Disabling everything included by this project is strongly recommended!'); + } + $project_data['extra'] = array( + array( + 'class' => array('project-not-supported'), + 'label' => t('Project not supported'), + 'data' => $message, + ), + ); + } + + } +} + +/** + * Return the recommended release from the fetched project data. + * + * @param array $project + * Project information. + * + * @return array + * Parsed release data. + */ +function _tag1_d7es_get_release_data(array $project) { + $version = isset($project['recommended']) ? $project['recommended'] : $project['latest_version']; + if ($release = $project['releases'][$version]) { + return $release; + } + return array(); +}