Help Desk Software & Beyond
October 21, 2017, 06:36:01 AM *
Welcome, Guest. Please login or register.
To post messages you need to register. We apologize for inconvenience, but this is to prevent spam.
Registration is instant (no email verification) and we do not ask for any personal information.

Login with username, password and session length
News: Welcome to Help Desk Software forum!
 
   Home   Help Search Login Register  
Pages: [1] 2 3
  Print  
Author Topic: If HTTPS do this else do that  (Read 33304 times)
loneguard
Jr. Member
**

Karma: 0
Posts: 98


View Profile
« on: October 08, 2007, 12:26:10 PM »

I have searched this forum, but found nothing. I've search the web and found only elaborate scripts that would check the status of HTTPS and execute some javascript. I have two versions of my StatCounter statistics javascript. One executes if the page is HTTPS, the other if the page is HTTP. They're both invisible and they both sit on my home.tpl page.
It's so very simple in Smarty-->PHP:

{if $smarty.server.HTTPS eq "on"}
do this
{else}
do that
{/if}

How would I do that in cgi - something I could put, perhaps, in footer.shtml?
Logged
Sparky
Moderator
Hero Member
*****

Karma: 85
Posts: 2,275


stop pushing all those buttons


View Profile
« Reply #1 on: October 08, 2007, 12:53:27 PM »

Quote
How would I do that in cgi - something I could put, perhaps, in footer.shtml?

Your statement is somewhat contradictory.  CGI/PERL is on the server.  Anything in the footer is client-side on the browser like Javascript.

There are a few ways to do what you want...



Javascript

In your header file, in one of your Javascripts, you can set a Javascript variable with an SSI call.  You'll only need the single line in blue if you put it inside an existing JS.  SSI will either work on your server or it won't... just try it.

Quote
<script language="JavaScript"><!--
portSSL = "<!--#echo var="SERVER_PORT" -->";
//-->
</script>

The port will be either 443 (https) or 80 (http).   That "portSSL" variable will be just the number 80 or 443.

Then in your footer, you can run your if/then logic using Javascript.



ALTERNATELY....

PERL

You can write your own CGI/PERL script or modify one of the TTX modules.

Just reference the server environment variable directly within the PERL program.

$ENV{SERVER_PORT};

Then run your if/then login within the PERL



OR ALTERNATELY AGAIN...

PERL/Javascript combo

You could use some combination of the two by passing variables between the CGI/PERL on the server and the Javascript in the browser.  Using SSI to call the function maybe and macros to pass some variables back into the Javascript.



And depending on what your IF/THEN is supposed to do:

You could just edit the .htaccess file (Unix) on the server to do all sorts of neat re-direct tricks depending on the URL.  Unfortunately it ignores the port number as far as I know BUT if you're on a shared SSL certificate, your entire URL will be different anyway.
Logged

Did you update the paths in ttxcfg.cgi after moving TTX to your new location?   Undecided
To those seeking help.... please report back when you figure it out.  Cheesy
loneguard
Jr. Member
**

Karma: 0
Posts: 98


View Profile
« Reply #2 on: October 08, 2007, 01:03:33 PM »

My statement is contradictory because I don't know what I'm talking about. Hence, 'newbie' moniker  Smiley
I'm not on a shared SSL, but I like the Javascript solution and I think I'll try that.
Thank you Sparky.
Logged
Sparky
Moderator
Hero Member
*****

Karma: 85
Posts: 2,275


stop pushing all those buttons


View Profile
« Reply #3 on: October 08, 2007, 01:08:22 PM »

SSI is easy if you're on a Unix/Linux Apache server.  Generally, it can only be called from a .shtml page but you can change that in your .htaccess file.

I run into problems with SSI when pages are dynamically generated from within another script.  Example:  If hypothetical shopping cart pages are put together on the fly from a database combined with HTML templates, then SSI is not going to work.
Logged

Did you update the paths in ttxcfg.cgi after moving TTX to your new location?   Undecided
To those seeking help.... please report back when you figure it out.  Cheesy
loneguard
Jr. Member
**

Karma: 0
Posts: 98


View Profile
« Reply #4 on: October 08, 2007, 01:33:50 PM »

Yes, my html pages are made on the fly, but obviously not the newticket.html page.
I'm getting some 'code corrupt' messages. I think it has to do with the fact that my javascript is a two-piece code:

Quote
<!-- Start of StatCounter Code -->
<script type="text/javascript" language="javascript">
var sc_project=xxxxxx;
var sc_invisible=1;
var sc_partition=0;
var sc_security="xxxxxxxx";
var sc_https=1;
</script>
<script type="text/javascript" language="javascript" src="https://secure.statcounter.com/counter/counter.js"></script><noscript><a href="http://www.statcounter.com/" target="_blank"><img  src="https://c1.statcounter.com/counter.php?sc_project=xxxxxxx&amp;java=0&amp;security=xxxxxxx&amp;invisible=1" alt="Aquasana Canada Web Traffic" border="0"></a> </noscript>
<!-- End of StatCounter Code -->

and I'm not sure where to close the brace. 
Quote
if (portSSL == "443") {
Logged
loneguard
Jr. Member
**

Karma: 0
Posts: 98


View Profile
« Reply #5 on: October 08, 2007, 01:37:29 PM »

I'm being called away - Thanksgiving obligations....
Logged
Sparky
Moderator
Hero Member
*****

Karma: 85
Posts: 2,275


stop pushing all those buttons


View Profile
« Reply #6 on: October 08, 2007, 01:49:22 PM »

Yes, my html pages are made on the fly, but obviously not the newticket.html page.

Of course it is...  newticket.html is only a template.

TTX dynamically puts those pages together on the fly...  header.shtml + newticket.html + footer.shtml + all the macros are filled in.

You can easily create a new TTX macro for the port though.

Pick someplace good in TTXTicket.pm...

Quote
my $port = $ENV{SERVER_PORT};
$data->{THE_PORT} = $port;

Then inside a Javascript in your newticket.html template...

Quote
portSSL = "(%THE_PORT%)";



and I'm not sure where to close the brace. 
Quote
if (portSSL == "443") {

You close it after you execute the IF

Quote
if (portSSL == "443") {
  // all your javascript that gets executed if the port is secure.
} else {
  // all your javascript that gets executed if the port is not secure.
}
Logged

Did you update the paths in ttxcfg.cgi after moving TTX to your new location?   Undecided
To those seeking help.... please report back when you figure it out.  Cheesy
loneguard
Jr. Member
**

Karma: 0
Posts: 98


View Profile
« Reply #7 on: October 08, 2007, 03:12:59 PM »

When I tried putting the javascript in my footer.html page, I got errors, probably because I was treating it as a static page.
Let me try to put it in TTXticket.pm and see what happens.
Logged
Sparky
Moderator
Hero Member
*****

Karma: 85
Posts: 2,275


stop pushing all those buttons


View Profile
« Reply #8 on: October 08, 2007, 03:15:36 PM »

When I tried putting the javascript in my footer.html page, I got errors, probably because I was treating it as a static page.
Let me try to put it in TTXticket.pm and see what happens.

someplace in the "ticket" subroutine would be best.
Logged

Did you update the paths in ttxcfg.cgi after moving TTX to your new location?   Undecided
To those seeking help.... please report back when you figure it out.  Cheesy
loneguard
Jr. Member
**

Karma: 0
Posts: 98


View Profile
« Reply #9 on: October 08, 2007, 03:21:15 PM »

That's where I put it, and got this:

Quote
Fatal Error: Unable to load module TTXTicket

Global symbol "$data" requires explicit package name at /home/aquasana/public_html/cgi-bin/TTXTicket.pm line 582. Compilation failed in require at (eval 12) line 2. BEGIN failed--compilation aborted at (eval 12) line 2.

SD:/home/aquasana/public_html/cgi-bin
Logged
Sparky
Moderator
Hero Member
*****

Karma: 85
Posts: 2,275


stop pushing all those buttons


View Profile
« Reply #10 on: October 08, 2007, 03:24:41 PM »

exactly where?


I'd put it here...

Quote
sub ticket {
  my ($cfg, $query, $data) = @_;
  checkgroups($cfg);
  TTXCommon::tickedvars($cfg, $data);

  my $port = $ENV{SERVER_PORT};
  $data->{THE_PORT} = $port;
« Last Edit: October 08, 2007, 03:26:49 PM by sparky672 » Logged

Did you update the paths in ttxcfg.cgi after moving TTX to your new location?   Undecided
To those seeking help.... please report back when you figure it out.  Cheesy
loneguard
Jr. Member
**

Karma: 0
Posts: 98


View Profile
« Reply #11 on: October 08, 2007, 03:26:59 PM »

Quote
sub ticket {
 
  my $port = $ENV{SERVER_PORT};
  $data->{THE_PORT} = $port; 

  my ($cfg, $query, $data) = @_;
  checkgroups($cfg);
  TTXCommon::tickedvars($cfg, $data);
Logged
loneguard
Jr. Member
**

Karma: 0
Posts: 98


View Profile
« Reply #12 on: October 08, 2007, 03:28:15 PM »

I think it would be prudent to leave this until my web traffic drops, perhaps tonight.
It's a live e-commerce site, after all.
Will you be here around 10-11pm EDT?
Logged
loneguard
Jr. Member
**

Karma: 0
Posts: 98


View Profile
« Reply #13 on: October 08, 2007, 03:30:14 PM »

Your place is better. No error.
Logged
Sparky
Moderator
Hero Member
*****

Karma: 85
Posts: 2,275


stop pushing all those buttons


View Profile
« Reply #14 on: October 08, 2007, 03:30:33 PM »

Quote
sub ticket {
 
  my $port = $ENV{SERVER_PORT};
  $data->{THE_PORT} = $port; 

  my ($cfg, $query, $data) = @_;
  checkgroups($cfg);
  TTXCommon::tickedvars($cfg, $data);

$data variable has to be defined first so make changes as per my previous post.
Logged

Did you update the paths in ttxcfg.cgi after moving TTX to your new location?   Undecided
To those seeking help.... please report back when you figure it out.  Cheesy
Pages: [1] 2 3
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1 RC3 | SMF © 2001-2006, Lewis Media Valid XHTML 1.0! Valid CSS!
Page created in 0.026 seconds with 20 queries.