a4f2a41999-07-21Martin Nilsson /* This is a roxen module. Copyright © 1997-1999, Idonex AB.
2b004e1997-01-25Peter Bortas  * * Adds some java script that will prevent others from putting * your page in a frame. *
bd8fa31998-04-03Peter Bortas  * Will also remove occuranses of "indexfiles" from the end of the URL.
2b004e1997-01-25Peter Bortas  *
0247a31998-03-11David Hedbor  * made by Peter Bortas <peter@idonex.se> Januari -97
aa899c1997-11-14Peter Bortas  *
bd8fa31998-04-03Peter Bortas  * Thanks for suggestions and bugreports: * Barry Treahy <treahy@allianceelec.com> * Chris Burgess <chris@ibex.co.nz>
2b004e1997-01-25Peter Bortas  */
485b561999-11-29Martin Nilsson constant cvs_version = "$Id: killframe.pike,v 1.23 1999/11/29 16:49:19 nilsson Exp $";
07bf511997-08-31Peter Bortas constant thread_safe=1;
6677ac1997-08-31Peter Bortas 
2b004e1997-01-25Peter Bortas #include <module.h> inherit "module";
93f8551998-04-03Peter Bortas void create() {
485b561999-11-29Martin Nilsson  defvar( "killindex", 1, "Kill trailing 'indexfiles'?", TYPE_FLAG,
e859de1998-04-03Peter Bortas  "When set, the killframe module will remove occurrences of "
93f8551998-04-03Peter Bortas  "'indexfiles' (as set in the active directory module) from " "the end of the URL, leaving only a slash." ); }
2b004e1997-01-25Peter Bortas 
e859de1998-04-03Peter Bortas mixed register_module()
2b004e1997-01-25Peter Bortas { return ({ MODULE_PARSER, "Killframe tag",
ceccc01998-08-01Peter Bortas  ("Makes pages frameproof." "<br>This module defines a tag," "<pre>" "&lt;killframe&gt;: Adds some java script that will prevent others\n" " from putting your page in a frame.\n\n" " Will also strip any occurrences of 'indexfiles'\n" " from the end of the URL." "</pre>" ), ({}), 1, });
2b004e1997-01-25Peter Bortas } string tag_killframe( string tag, mapping m, object id ) {
3f094d1998-08-10Per Hedbor  NOCACHE();
8756ae1998-03-08Per Hedbor  if(m->help) return register_module()[2];
ceccc01998-08-01Peter Bortas 
6b56dc1998-06-06Peter Bortas  if( !id->supports->javascript ) return "";
ceccc01998-08-01Peter Bortas 
6b56dc1998-06-06Peter Bortas  string javascript;
ceccc01998-08-01Peter Bortas 
93f8551998-04-03Peter Bortas  while( id->misc->orig ) id = id->misc->orig;
07bf511997-08-31Peter Bortas 
6b56dc1998-06-06Peter Bortas  // Some versions of IE will choke on :80. (Reload and repeat..) string tmp;
ceccc01998-08-01Peter Bortas  string prestate;
6b56dc1998-06-06Peter Bortas  string my_url = id->conf->query("MyWorldLocation");
ceccc01998-08-01Peter Bortas  //Get the prestates in correct order. id->prestates is sorted. if( sscanf(id->raw_url, "/(%s)", tmp) ) prestate = "("+ tmp +")/";
6b56dc1998-06-06Peter Bortas  if( sscanf(my_url, "%s:80/", tmp ) )
ceccc01998-08-01Peter Bortas  my_url = tmp +"/"+ (prestate?prestate:"") + id->not_query[1..];
6b56dc1998-06-06Peter Bortas  else
ceccc01998-08-01Peter Bortas  my_url += (prestate?prestate:"") + id->not_query[1..];
6b56dc1998-06-06Peter Bortas  // Links to index.html are ugly. All pages deserve a uniqe URL, and for // index-pages that URL in /.
485b561999-11-29Martin Nilsson  if( query("killindex") || m->killindex )
93f8551998-04-03Peter Bortas  {
6b56dc1998-06-06Peter Bortas  //Get indexfiles from the directory-module if there is one. array indexfiles = ({}); if( id->conf->dir_module ) indexfiles = id->conf->dir_module->query("indexfiles");
93f8551998-04-03Peter Bortas 
6b56dc1998-06-06Peter Bortas  int l=strlen(my_url)-1; foreach( indexfiles, string index ) if( my_url[l-strlen(index)..] == "/" +index ) my_url = my_url[..l-strlen(index)];
93f8551998-04-03Peter Bortas  }
6b56dc1998-06-06Peter Bortas  // Put back the variables if there were any. if(id->query) my_url += "?"+ id->query;
93f8551998-04-03Peter Bortas 
ceccc01998-08-01Peter Bortas  //top.location = self.location breaks some versions of IE. //Mozilla 3 on Solaris cows with top.frames.length if( id->client && id->client[0][..8] == "Mozilla/3" ) javascript = ( " if(top.location != \""+ my_url +"\")\n" " top.location = \""+ my_url +"\";\n" ); else javascript = ( " if(top.frames.length>1)\n" " top.location = \""+ my_url +"\";\n" );
a4f2a41999-07-21Martin Nilsson  return("<script language=\"javascript\"><!--\n"
6b56dc1998-06-06Peter Bortas  + javascript + "//--></script>\n");
2b004e1997-01-25Peter Bortas }