We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 727
    • 502 Posts
    This is an auto-generated support/comment thread for Encryption.

    Use this forum to post any comments about this addition or any questions you have regarding its use.

    Brief Description:
    This snippet allows you to specify which pages on your site are encrypted. It supports both shared and dedicated SSL certificates and friendly URLs.
      • 7923
      • 4,213 Posts
      Looks sweet, thanks alot for contributing!


        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 5100
        • 5 Posts
        HI
        This snippet works beautiful with shared SSL too.

        But when I’m passing along query string arguments along to the Secure Page it doesn’t pass them along.

        If you modify the snippet in two places (where the redirect actually happens)

        $modx->sendRedirect($secureserver.$document."?".$_SERVER['QUERY_STRING']);

          $modx->sendRedirect($unsecureserver.$document."?".$_SERVER['QUERY_STRING']);


        Now I have tested it only to make sure it passes along QueryString arguments.
        Still testing to see what it does with the submitted forms.(POST)

        This is my first post here . So please correct me if I’m mistaken.


        MODIFIED SNIPPET CODE
        <?php
        /*
        ::::::::::::::::::::::::::::::::::::::::
         Snippet name: Encryption
         Short Desc: Encrypts a page if needed using SSL
         Version: 1.0.0
         Author: Andrew Ayre ([email protected])
         License: LGPL
        ::::::::::::::::::::::::::::::::::::::::
        Description:
          Checks a template variable to see if a page should be encrypted using SSL or not.
          The template variable must be called "encryption" and if the value of the template
          variable is "On" for a specific page, then it will be encrypted using SSL.
          **Before using configure the values $secureserver and $unsecureserver below.**
        ::::::::::::::::::::::::::::::::::::::::
        Example Usage:
          Place the call to the snippet at the very top of any template used for encrypted
          pages:
            [[Encryption]]
            [[Encryption?alwaysencrypt=`1`]]
        ::::::::::::::::::::::::::::::::::::::::
        */
        
        /***********************
        * Modified by Kishore Chintoju 
        * [email protected]
        * To pass along the QueryString arguments if any
        ***********************/
        
        
        // CONFIGURATION SECTION
        // secure location of modx installation - no trailing slash
        $secureserver = "https://yourhostingcompany/~yoursite";
        // unsecure location of modx installation - no trailing slash
        $unsecureserver = "http://www.yoursite.com.au/";
        // END OF CONFIGURATION SECTION
        
        // parameters
        // alwaysencrypt - set to 1 to always encrypt the page
        $alwaysencrypt = isset($alwaysencrypt)? $alwaysencrypt: 0;
        
        // get encryption setting of current document = must be "On" or "0"
        $tv = $modx->getTemplateVar('encryption', "", $modx->documentIdentifer);
        $encryption = $tv['value'];
        
        if ($alwaysencrypt) {
          $encryption = 'On';
        }
        
        // get page name of current document
        $url = $modx->makeUrl($modx->documentIdentifier);
        $document = strrchr($url, "/");
        
        // if SSL off and we are about to access a secure page then redirect
        if(strtolower($_SERVER['HTTPS']) != "on" && $encryption == "On")
        {
          $modx->sendRedirect($secureserver.$document."?".$_SERVER['QUERY_STRING']); //CHANGE
        }
        // if SSL is on and we are about to acccess an unsecure page then redirect
        else if (strtolower($_SERVER['HTTPS']) == "on" && $encryption != "On")
        {
          $modx->sendRedirect($unsecureserver.$document."?".$_SERVER['QUERY_STRING']);//CHANGE
        }
        return "";
        ?>



        Thanks
        Kishore
          • 727
          • 502 Posts
          Excellent - I’ll update the snippet in the resources in the next couple of days. Thanks!!

          Update: It’s updated in the resources to version 1.0.1.

          Andy
            • 5100
            • 5 Posts
            Hi Andy
            That’s updated.

            I just ran into one more problem.


            • I’m using this to encrypt some of the pages our clients access.
            • I’m using ’web user login’ to isolate some of pages as staff only access.

            When I try to make one of those staff only pages secure with a secure template (Which has the snippet Encryption).
            It starts circular redirection between my secure and unsecure server which never ends.

            Is there anyway this can be prevented.

            Thanks
            Kishore

              • 727
              • 502 Posts
              I’[m not sure where the redirection is coming from. Is the encrypted page also the page that is shown immediately after logging in? If so then make the first page after logging in a "jumping off point" with links to the encrypted pages. Let me know if that helps.

              Andy
                • 5100
                • 5 Posts
                HI Andy,
                First page after logging in is not the redirection point.

                After logging in web user has 8 pages which are exclusive to him and only one is secure in that. If tried to access that page then its going into loop redirection.
                And if I take out the Encryption snippet then its OK. (or) If I put this page as a public access with SSL enabled using Encryption snippet, then its OK.

                Only when I tried to use them both, then It doesn’t work.

                I’m sorry But I didn’t understand the "jumping off point" (i.e should I put one more page and redirect from that)

                Currently after logging in the user will go to his homepage. Then here he will have to click on link to access this page.

                Hope I have explained it clearly without confusion. Anyway thanks in advance.

                Kishore
                  • 727
                  • 502 Posts
                  Hmmm...I’m not sure. When encryption disabled: when you hover the pointer over the link what does the browser show as the URL? When you click on the link what URL does it actually go to?

                  Andy
                    • 5100
                    • 5 Posts
                    HI andy

                    URL Without encryption
                    http://www.mysite.com.au/ViewRegistration.html (Using Friendly URL’s)

                    URL with Encryption
                    url_a. http://www.mysite.com.au/ViewRegistration.html (When I hover over the link)
                    url_b. http://www.myhosting.com.au/mysite/ViewRegistration.html (After clicking Encryption redirects here)

                    This works normally fine

                    When I make this secure accessible to only certain group of web users.

                    It stops responding on click. But in Firefox I can verify that there is redirection loop going on from url_a to url_b
                    . Then Firefox informs me that this redirection will never end.

                    Hope this clears.

                    Thanks
                    Kishore


                      • 727
                      • 502 Posts
                      Where is "/mysite" coming from?
                      Why doesn’t the encrypt redirection go to a https page?

                      Andy