added ubercart ssl module

This commit is contained in:
Bachir Soussi Chiadmi 2015-12-02 11:36:55 +01:00
parent 35e914df58
commit ed6ae84181
5 changed files with 859 additions and 0 deletions

View File

@ -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.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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.
<signature of Ty Coon>, 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.

View File

@ -0,0 +1,78 @@
<?php
function uc_ssl_admin()
{
$form = array();
$form['uc_ssl_ssl_domain'] = array(
'#type' => 'textfield',
'#title' => t('Secure Domain Name'),
'#default_value' => variable_get('uc_ssl_ssl_domain', ''),
//'#size' => 2,
//'#maxlength' => 2,
'#description' => t("This field accepts domain names in the following format: https://something.com OR https://something.com:5938. <br><br><b>IPMORTANT DRUPAL 7 NOTICE ABOUT DOMAIN NAMES:</b> This module DOES support using port numbers and different domains for SSL and normal HTTP like it's Drupal 6 predecessor HOWEVER, this is NOT meant for a production environment!!!! RFC restrictions PROHIBIT passing cookie data between sites with different port numbers (80 to 5933 for example. The ONLY exception is for the default ports of 80 and 443 which are never specified to begin with and thus pass RFC requirements for sharing data!!) and it treats them as separate sites. So if you use a port number drupal WILL require you to login BEFORE that url will work (drupal 6 has the same limitation btw, I just never documented it). In Drupal 7 this results in the 'Store' configuration panel NOT showing up. You must login to the store config panel by going to the https://yoursite.com:PORTNUMBER/admin/store url FIRST and login. Once you have done that, you can access store/admin. The administration panel overlay code for drupal 7 is NOT compatible with this module because it is NOT a secure method to access data!!!! ALWAYS go DIRECTLY to the /store/admin link DIRECTLY. The same goes for /cart. /cart WILL ask you to login. Once your site is ready for production you must absolutely use the SAME url for both secure AND non-secure pages. So your site should always be accessed from http://yoursite.com and https://yoursite.com OR http://www.yoursite.com and https://www.yoursite.com. It should NEVER be accessed like this: http://yoursite.com http://ssl.yoursite.com. Or any other sub domain for that matter. It will result in drupal asking you to login!"),
'#required' => TRUE,
);
$form['uc_ssl_non_ssl_domain'] = array(
'#type' => 'textfield',
'#title' => t('NON-Secure Domain Name'),
'#default_value' => variable_get('uc_ssl_non_ssl_domain', ''),
//'#size' => 2,
//'#maxlength' => 2,
'#description' => t("This field accepts domain names in the following format: http://something.com OR http://something.com:8080"),
'#required' => TRUE,
);
$form['uc_ssl_status'] = array(
'#type' => 'radios',
'#title' => t('Ubercart SSL Status'),
'#default_value' => variable_get('uc_ssl_status', ''),
'#options' => array( TRUE => t('Enabled'), FALSE => t('Disabled')),
'#required' => TRUE,
);
$form['uc_ssl_switch_to_non_ssl'] = array(
'#type' => 'radios',
'#title' => t('Ubercart Non-SSL Switch'),
'#default_value' => variable_get('uc_ssl_switch_to_non_ssl', ''),
'#options' => array( TRUE => t('Enabled'), FALSE => t('Disabled')),
'#required' => TRUE,
'#description' => t("Since this module switches to SSL mode during checkout, all links will link back to a secured version of the website. If you want to switch back to non-secured mode after a transaction is complete or they click on a keep shopping link, etc. This isnt really necessary but some people may want to save on the small resources savings you can get from doing this. So if you want to keep http for any non-cart related things, you should check this as enabled. If you dont care, then set it to disabled.<br><br>DRUPAL 7 NOTICE: Enabling this will DISABLE the Overlay module because it cannot work securely in a mixed SSL environment!! Setting this back to Disabled WILL NOT re-enable the Overlay module. You must re-enable the Overlay module yourself."),
);
$form['uc_ssl_case_insensitive'] = array(
'#type' => 'radios',
'#title' => t('Ubercart SSL Case Sensitivity'),
'#default_value' => variable_get('uc_ssl_case_insensitive', TRUE),
'#options' => array( TRUE => t('Enabled'), FALSE => t('Disabled')),
'#required' => TRUE,
'#description' => t('By default drupal allows paths to be accessed in a case insensitive manor. This is fine but not very secure. SSL Standards dictate that paths should always be case sensitive. So in order to be compatible with SSL standards, we allow the administrator to change SSL path recognition to case sensitive by simply setting this setting to disabled. In order to stick close to drupal standards, this module defaults this value to Enabled which means /Cart AND /cart would match and be secured where as in case sensitive mode /Cart would NOT be secured, alerting the user to an insecure page but /cart would be secured.'),
);
return system_settings_form($form);
}
function uc_ssl_admin_validate($form, &$form_state)
{
$ssl_domain = $form_state['values']['uc_ssl_ssl_domain'];
$non_ssl_domain = $form_state['values']['uc_ssl_non_ssl_domain'];
if (!valid_url($ssl_domain) || !stristr($ssl_domain, 'https://'))
{
form_set_error('uc_ssl_ssl_domain', t('You must enter a valid SSL Domain name.'));
}
if (!valid_url($non_ssl_domain) || !stristr($non_ssl_domain, 'http://'))
{
form_set_error('uc_ssl_non_ssl_domain', t('You must enter a valid Non-SSL Domain name.'));
}
if (!uc_ssl_check($ssl_domain.base_path()))
{
form_set_error('uc_ssl_ssl_domain', t('CRITICAL ERROR! The domain you entered for the secured domain came back as non-secure or it does not point back to this installation of drupal. Your secure domain name MUST be setup and MUST be pointing at this install of drupal.'));
variable_set('uc_ssl_status', '0');
$form_state['values']['uc_ssl_status'] = '0';
$form['values']['uc_ssl_status'] = '0';
}
}

View File

@ -0,0 +1,14 @@
name = Ubercart SSL
description = (D7) Secure Ubercart /cart links with an SSL Cert. Do NOT enable this unless your site works with SSL as it WILL break your cart. If it does, just disable this and get your site working with SSL first and then re-enable this module. This module does not require Ubercart so it can be used for anything else as well, its just that its most common use is to be used with Ubercart so that is why I named it so. Feel free to use it with anything you like.
package = Ubercart - extra
core = 7.x
project = "uc_ssl"
configure = admin/config/system/uc_ssl
; Information added by drupal.org packaging script on 2012-12-03
version = "7.x-1.11"
core = "7.x"
project = "uc_ssl"
datestamp = "1354572030"

View File

@ -0,0 +1,12 @@
<?php
/**
* Implementation of hook_uninstall().
*/
function uc_ssl_uninstall()
{
variable_del('uc_ssl_ssl_domain');
variable_del('uc_ssl_non_ssl_domain');
variable_del('uc_ssl_status');
variable_del('uc_ssl_switch_to_non_ssl');
}

View File

@ -0,0 +1,416 @@
<?php
//
//Note about the include/exclude hooks. As an example, this module includes /cart* which essentially secures ALL cart pages with SSL. But it also implements an exclude which is called /cart Which you would think would negate the include but it DOES NOT. Even though Excludes take presedence over includes, it still allows /cart/1 for example, to be secured. Why? Because the exclude is not a wildcard match! Thus the exclude would NOT match /cart/1 because it's defined as /cart. Thus while /cart IS excluded (not secured with SSL),/cart/1 is STILL secured.
//Implementation of hook_include_ssl_paths()
//NOTE: Exclude takes presedence over Includes!!! So if the same path is in both hooks, then the path will be EXCLUDED from secured pages.
//Since base_url has a design flaw in D4/D5/D6/D7 that seemingly will never be fixed, we fix it here.
function uc_ssl_boot()
{
global $conf;
//the $conf['https'] option MUST be enabled if mixed ssl mode is enabled. We make sure its enabled here. If it's not enabled then user
//sessions will not persist across the secure and non-secure domain names resulting in the user being prompted to log in whenever they are
//sent to a secure page.
if (uc_ssl_switch_to_non_ssl() && !isset($conf['https']) || (isset($conf['https']) && !$conf['https']))
{
$conf['https'] = TRUE;
}
if ($GLOBALS['base_url'])
{
//If base_url exists and is set to a non-secure protocol while the page being called is secure, allow base_url to be changed to
//the secure version of the website. Drupal for some reason doesnt have this logic anywhere for $base_url.
if (uc_ssl_page_is_in_https_mode() && stristr($GLOBALS['base_url'], 'http://'))
{
$GLOBALS['base_url'] = str_ireplace('http://', 'https://', $GLOBALS['base_url']);
}
}
}
function uc_ssl_permission()
{
$perms = array(
'administer uc_ssl' => array(
'title' => t('Administer Ubercart SSL settings'),
),
);
return $perms;
}
function uc_ssl_page_is_in_https_mode()
{
if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']))
{
return TRUE;
}
return FALSE;
}
function uc_ssl_disable_overlay_module()
{
$modules = module_list();
$base_path = base_path();
if (variable_get('uc_ssl_switch_to_non_ssl', '') && in_array('overlay', $modules))
{
//Overlay is on, lets disable it.
module_disable(array(0 => 'overlay'));
}
}
function uc_ssl_init()
{
//Drupals Overlay panel is not secure! Fix that here by disable it all together. We cannot allow this. Drupal 7 is insecure by default, such a sad thing :/
uc_ssl_disable_overlay_module();
//menu_rebuild();
//First and foremost, make sure Clean URLs are on.
if (uc_ssl_clean_urls_enabled() && !drupal_is_cli())
{
//Setup a hook for ssl checking
uc_ssl_check();
//Run ssl check on every page load.
uc_ssl_run();
}
}
function uc_ssl_include_ssl_paths()
{
global $user;
$paths = array(
'All Ubercart Cart pages' => '/cart*', //Secure ALL cart pages.
//NOTE: If you remove the /user definition here, you CAN NOT use Mixed SSL Mode with D7. It HAS to exist because D7 http sessions are missing
//data that https sessions require. But http sessions work with the https session variables. Thus, you MUST login with https or your sessions
//will not carry between the http and https versions of your wesite. This is a D7 bug only, I believe its more of a feature than a bug.
'All User pages' => '/user*', //Secure ALL user pages.
//Added support for Drupal commerce which is based upon Ubercart.
'All Drupal Commerce Checkout pages' => '/checkout*', //Secure ALL cart pages. NOTE: SEE EXCLUDES to see why the cart listing itself isnt secured!
//This supports both UC and Commerce admins
'All Ubercart Cart Admin pages' => '/admin/store*', //Secure ALL UC admin pages.
#'example 1' => '/cart', //Only secure the /cart and /cart/ page.
#'example 2' => 'cart', //Only secure the /cart and /cart/ page.
#'example 3' => 'cart/', //Only secure the /cart and /cart/ page.
#'example 4' => '/cart*/something', //matches /cartThis/something and /cart/something but NOT thiscart/something etc.
#'example 5' => '/cart/*/something', //Matches /cart/123/something and cart/this/something, but NOT /cart/something
#'example 6' => '/cart/something', //Only secure the /cart/something and /cart/something/ page.
);
return $paths;
}
//Implementation of hook_exclude_ssl_paths()
function uc_ssl_exclude_ssl_paths()
{
$paths = array(
//These excludes no longer seem to be required for the D7 version and thus they have been removed until issues come up again.
//'Exclude the cart page itself' => '/cart', //We dont need to secure the cart contents so we exclude that here
//'Exclude Autocomplete' => '*autocomplete*',
//'Exclude Ajax' => '*ajax*',
#'example 1' => '/cart', //Only exclude the /cart and /cart/ page.
#'example 2' => 'cart', //Only exclude the /cart and /cart/ page.
#'example 3' => 'cart/', //Only secure the /cart and /cart/ page.
#'example 4' => '/cart*/something', //matches /cartThis/something and /cart/something but NOT thiscart/something etc.
#'example 5' => '/cart/*/something', //Matches /cart/123/something and cart/this/something, but NOT /cart/something
#'example 6' => '/cart/something', //Only exclude the /cart/something and /cart/something/ page.
);
return $paths;
}
//Implementation of hook_exclude_ssl_paths()
//This function is so you can completely ignore ANY switching at all no matter what.
function uc_ssl_exclude_ssl_switch_paths()
{
$paths = array(
#'example 1' => '/*ajax*', //Dont touch ajax paths whatsoever, this is just an example.
);
return $paths;
}
function uc_ssl_menu()
{
$items = array();
$items['admin/config/system/uc_ssl'] = array(
'title' => 'Ubercart SSL',
// 'title' => 'Ubercart SSL module settings',
'description' => 'Ubercart SSL module settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('uc_ssl_admin'),
'access arguments' => array('administer uc_ssl'),
'type' => MENU_NORMAL_ITEM,
'file' => 'uc_ssl.admin.inc',
);
return $items;
}
function uc_ssl_enabled()
{
return variable_get('uc_ssl_status', '');
}
function uc_ssl_is_configured()
{
$query = "SELECT count(name) AS count from {variable} WHERE name = 'uc_ssl_status'";
$results = db_query($query);
$rows = $results->fetchAll();
$rows = $rows[0];
//If uc_ssl is not configured, warn the user and show a link to config it.
if (!$rows->count)
{
$admin_link = 'http://'.$_SERVER['HTTP_HOST'].url().'admin/config/system/uc_ssl';
drupal_set_message("Please configure Ubercart SSL for SSL enabled cart checkouts to work: <a href = '$admin_link'>$admin_link</a>", 'warning');
}
return $rows->count;
}
function uc_ssl_switch_to_non_ssl()
{
return variable_get('uc_ssl_switch_to_non_ssl', '');
}
function uc_ssl_path_match($path, $pages)
{
$result = FALSE; //This is here just to get rid of retarded php 'notice' messages. I hate php notices.
if (!empty($pages))
{
//Trim off trailing / and then re-add it to avoid double /'s. This allows cart and cart/ to match as the same thing or cart/1 and cart/1/ to be the same.
$path = trim($path, '/').'/';
$regexp = '/^(';
foreach ($pages AS $key => $regexp_path)
{
if ($regexp_path)
{
$regexp_path = trim($regexp_path, '/').'/';
$regexp_path1 = str_replace('/', '\/', $regexp_path); //replace / with a \/
$regexp_path2 = str_replace('*', '.*', $regexp_path1);//replace * with a .*
$regexp .= $regexp_path2.'|'; //Append a | to signify end of this expression
}
}
$regexp = trim($regexp, '|');
$regexp .= ')$/';
if (variable_get('uc_ssl_case_insensitive', 1))
{
$regexp .= 'i';
}
$result = preg_match($regexp, $path);
}
return $result;
}
function is_clean_url($path)
{
//Skip ANY ?q= urls since these do NOT come from a web browser when clean URLs is on. Doing this allows us to skip
//ajax and autocomplete type URLs that come from within drupal itself. This is a major problem with Secure_Pages module
//and we dont want the same problems so we restrict people to using ONLY clean URLs.
if (!stristr($path, '?q='))
{
return TRUE;
}
return FALSE;
}
function uc_ssl_http_request($url)
{
//Handle JS type urls in the background as they are likely to be ajax type posts.
if (arg(0) == 'js')
{
$js_response = drupal_http_request($url);
return;
}
//Handle post type URLs. This should handle ajax POST urls such as the tax calculation/progress bars.
if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST['uc_ssl_post']))
{
$_POST['uc_ssl_post'] = 1;
$options['headers'] = array('Content-Type' => 'application/x-www-form-urlencoded');
$options['method'] = 'POST';
$options['data'] = http_build_query($_POST, '', '&');
//Drupal 7 decided to completely recode drupal_http_request so I dont know if this will cause issues or not. Report any bugs please.
//$response = drupal_http_request($url, $headers, 'POST', http_build_query($_POST, '', '&'));
$response = drupal_http_request($url, $options);
return;
}
//All other types of urls are handled normally.
// Reset destination variables or we'll get sent there instead of to $url
unset($_REQUEST['destination'], $_GET['destination']);
drupal_goto($url);
return;
}
function uc_ssl_run()
{
//Set the current path without url() since it will mess up regex checks. Using url() also supports languages, base_path does not.
//$current_path = trim($_SERVER['REQUEST_URI'], url());
$root = url();
$current_path = substr(trim($_SERVER['REQUEST_URI']),strlen($root));
$ssl_domain = variable_get('uc_ssl_ssl_domain', '');
$nonssl_domain = variable_get('uc_ssl_non_ssl_domain', '');
//If uc_ssl is configured, run it.
if (uc_ssl_is_configured() && is_clean_url($current_path))
{
if (uc_ssl_enabled())
{
//Get a list of all the URL links that should be included and excluded from SSL pages from other modules.
$items = array();
$exclude_secured_urls = array();
$exclude_secured_urls = module_invoke('uc_ssl', 'exclude_ssl_paths', $exclude_secured_urls);
foreach (module_implements('exclude_ssl_paths') as $module)
{
$new = module_invoke($module, 'exclude_ssl_paths', $exclude_secured_urls);
if ($module != 'uc_ssl') //Skip uc_ssl since we already processed it above. Allow external modules to change uc_ssl defaults.
{
if (is_array($new))
{
$exclude_secured_urls = array_merge($exclude_secured_urls, $new);
}
}
}
$include_secured_urls = array();
$include_secured_urls = module_invoke('uc_ssl', 'include_ssl_paths', $include_secured_urls);
foreach (module_implements('include_ssl_paths') as $module)
{
$new = module_invoke($module, 'include_ssl_paths', $include_secured_urls);
if ($module != 'uc_ssl') //Skip uc_ssl since we already processed it above. Allow external modules to change uc_ssl defaults.
{
if (is_array($new))
{
$include_secured_urls = array_merge($include_secured_urls, $new);
}
}
}
// Get a list of all the URL links that should not switch between HTTP/HTTPS at all.
$exclude_switch_urls = array();
$exclude_switch_urls = module_invoke('uc_ssl', 'exclude_ssl_switch_paths', $exclude_switch_urls);
foreach (module_implements('exclude_ssl_switch_paths') as $module)
{
$new = module_invoke($module, 'exclude_ssl_switch_paths', $exclude_switch_urls);
if ($module != 'uc_ssl') //Skip uc_ssl since we already processed it above. Allow external modules to change uc_ssl defaults.
{
if (is_array($new))
{
$exclude_switch_urls = array_merge($exclude_switch_urls, $new);
}
}
}
// make sure we return an array
if (! is_array($include_secured_urls)) { $include_secured_urls = array(); }
if (! is_array($exclude_secured_urls)) { $exclude_secured_urls = array(); }
if (! is_array($exclude_switch_urls)) { $exclude_switch_urls = array(); }
//If the path is in the exclude switch hook, dont do ANYTHING at all.
if (uc_ssl_path_match($current_path, $exclude_switch_urls))
{
return;
}
//Switch to SSL no matter what the link is if Switch isnt on.
if (!uc_ssl_switch_to_non_ssl())
{
if (!uc_ssl_page_is_in_https_mode() && !uc_ssl_path_match($current_path, $exclude_secured_urls))
{
uc_ssl_http_request($ssl_domain . $_SERVER['REQUEST_URI']);
}
}
else
{
//If uc_ssl_switch_to_non_ssl() is enabled then we switch back to non-ssl link for non-cart links.
if (uc_ssl_page_is_in_https_mode())
{
//The only exceptions are the links listed in the exclude list by other modules.
if (uc_ssl_path_match($current_path, $exclude_secured_urls))
{
uc_ssl_http_request($nonssl_domain . $_SERVER['REQUEST_URI']);
}
if (!uc_ssl_path_match($current_path, $include_secured_urls) && uc_ssl_switch_to_non_ssl())
{
uc_ssl_http_request($nonssl_domain . $_SERVER['REQUEST_URI']);
}
}
}
//If on a cart url, use HTTPS and re-post/re-direct to the SSL version of the url.
if (!uc_ssl_page_is_in_https_mode() && uc_ssl_path_match($current_path, $include_secured_urls) && !uc_ssl_path_match($current_path, $exclude_secured_urls))
{
uc_ssl_http_request($ssl_domain . $_SERVER['REQUEST_URI']);
}
}
}
}
function uc_ssl_clean_urls_enabled()
{
$check = variable_get('clean_url', 0);
if ($check == 1)
{
return TRUE;
}
drupal_set_message('Ubercart SSL (uc_ssl): The uc_ssl module REQUIRES that Clean URLs be enabled in order to work properly. This allows the module to distinguish between an Ajax call and a Web browser call as the two are handled differently so we need a way to distinguish them and this is the quickest easiest way to do so. This will also make your website URLs search engine friendly as well which is a good thing. Please enable clean urls here: <a href="?q=admin/settings/clean-urls">Clean URLs</a>', 'warn');
return FALSE;
}
//This is a quickie hook to see if SSL works or not. It's not fool proof but it works for me.
function uc_ssl_check($site = '')
{
error_reporting(E_ALL);
if (!$site)
{
if (isset($_GET['uc_ssl_check']) && $_GET['uc_ssl_check'])
{
if (uc_ssl_page_is_in_https_mode())
{
echo TRUE;
}
else
{
echo FALSE;
}
exit;
}
}
else
{
$check = drupal_http_request($site."?uc_ssl_check=1");
if (isset($check->data) && $check->data == '1')
{
return TRUE;
}
//IF we are here, then the request failed for some reason, so we try to use a different method.
if (ini_get('allow_url_fopen'))
{
if (file_get_contents($site."?uc_ssl_check=1") == '1')
{
return TRUE;
}
}
//If we are here, something went wrong. Give the user some ideas on what they need to fix.
drupal_set_message("Ubercart SSL (uc_ssl): The uc_ssl_check() function is returning FALSE because it was unable to contact the SSL (https) version of your website that you defined in the settings. This can be caused by 3 things. 1. Your website is not setup properly for SSL, 2. The OpenSSL extension is not enabled on in your PHP installation, 3. allow_url_fopen is not enabled in php.ini. If #2 fails, uc_ssl will try to use file_get_contents() which requires allow_url_fopen to be set to TRUE in php.ini. Hopefully these hints will help you fix this issue so that you can use uc_ssl. You can try to debug this by going to $site?uc_ssl_check=1", "error");
}
return FALSE;
}
if (!function_exists('printr'))
{
function printr($arr)
{
echo "<pre>";
print_r($arr);
echo "</pre>";
}
}