So the client wants to be a big shot at the launch party for the site, what else is new. So I made this silly, badly made script for him and he is so pleased he wants to do this all day long so I thought I would share it despite its unmodular construction. At the lauch party the client will enter his secret password and the site will miraculously go live at his click. Yee ha. Hope someone gets a kick out of this, made my money man think I'm swell.
Peas,
jg
#!/usr/bin/perl -w use strict; use CGI qw/:standard/; use CGI::Carp qw/fatalsToBrowser /; my $q = CGI->new(); my $pass = $q->param('pass'); if ($pass ne "securityrisk"){ die; } else { rename ("index.html", "old.html") || die "Can't rename: $!"; rename ("indexalt.htm", "index.html") || die "Can't rename: $!"; print $q->header(-target=>'ResultWindow',-nhp=>1,-expires=>'now',-loca +tion=>'http://www.thenewest.org/'); }
_____________________________________________________
Ain't no time to hate! Barely time to wait! ~RH

Replies are listed 'Best First'.
(kudra: learn the virtue of laziness) Re: Silly Badly Done Script Which Impresses the Heck Out of Client
by kudra (Vicar) on Oct 04, 2001 at 12:06 UTC
    I think you went to even more work than needed to open a web site. After one experience a few years ago, I concluded anything that takes 10 seconds or longer is too much work for the task...

    Knowing that the board member they were sending to open the site was the sort who considered computers paperweights, we decided to reduce the 'opening' to one click. We used the boss's mac to avoid explaining which mouse button to use. Then I set the 'home' page to blank, loaded the blank page, and set the home page back to the site and maneuvered the mouse so the pointer appeared over the home button.

    He still managed to tap the mouse a few times until my boss mercifully pushed his finger on to the button. It was worth all my seconds of work as the confusion on his face was replaced with carefully crafted photo-op joy at the marvels of technology.

Re: Silly Badly Done Script Which Impresses the Heck Out of Client
by tachyon (Chancellor) on Oct 04, 2001 at 09:53 UTC

    Here's a few unsolicited comments. Perfect start with -w and strict. You then get CGI.pm to import a whole lot of functions into your namespace (via the qw/:standard/) but don't actually use any of them as you proceed to use the object oriented interface. Does not really hurt but suggest you don't quite understand what happens when you do this. Other than that quibble your indentation could use a little work, how about:

    #!/usr/bin/perl -w use strict; use CGI; use CGI::Carp qw/fatalsToBrowser/; my $q = CGI->new(); if ( $q->param('pass') eq "securityrisk" ){ rename ("index.html", "old.html") || die "Can't rename: $!"; rename ("indexalt.htm", "index.html") || die "Can't rename: $!"; print $q->header( -target => 'ResultWindow', -nhp => 1, -expires => 'now', -location => 'http://www.thenewest.org/' ); }

    All in all a good solid piece of code.

    cheers

    tachyon

    Update

    Fixed typo thanks crazyinsomniac

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Silly Badly Done Script Which Impresses the Heck Out of Client
by Zaxo (Archbishop) on Oct 04, 2001 at 12:03 UTC

    Two points not covered by tachyon:

    1. In rename ("index.html", "old.html") for example, it would be better to use absolute paths. Otherwise the current directory comes into it and it may not be what you expect.
    2. Is '...,-nhp=>1, ...' a typo for -nph=1 ?
    I agree that this is pretty solid code.

    After Compline,
    Zaxo

Re: Silly Badly Done Script Which Impresses the Heck Out of Client
by cLive ;-) (Prior) on Oct 04, 2001 at 20:31 UTC
    Simple, fun, but a little overkill perhaps :)

    Why rename the launch page? Why not just overwrite it? Also, a CGI::Carp error would not look very pretty at a launch if they had mistyped!

    Of course, if you knew the IP of the machine doing the launch (and assuming the script is in the same directory as the home page, the home page is in the web root dir and you're on *nix) you could have just done:

    #!/usr/bin/perl # where XXX etc replaced by machine's IP if ($ENV{'REMOTE_ADDR'} eq 'XXX.XXX.XXX.XXX') { system('mv','-f','indexalt.htm','index.htm'); } print "Location: /\n\n"; exit(0);

    So, if the IP is wrong, they just get the 'password' page again.

    .02

    cLive ;-)

Re: Silly Badly Done Script Which Impresses the Heck Out of Client
by Fletch (Bishop) on Oct 04, 2001 at 19:51 UTC

    As long as both arguments are of the same type (file=>file or directory=>directory) and you're on a real OS then rename should overwrite any existing target file. So you could have just done:

    rename( "indexalt.html" => "index.html" ) or warn "Couldn't rename: $!";";
Re: Silly Badly Done Script Which Impresses the Heck Out of Client
by netjackal (Acolyte) on Oct 23, 2001 at 15:23 UTC
    Not really a commment on your code although i must agree with many that it was well thought of.

    This is just to share my experience in doing something like this. It was actually to shut down the website ... there was a party (go figure) to bring the site down. The 'committee' decided that the best way would be at a certain time I will bring the site down by sshing to the webserver and running a script that replaces the main page with a 'down' page. But since the webserver was modperl i also had to restart the servers. In the meantime the entire staff were doing refreshes to see when the 'down' page came up. I had to tell everyone to stop that 'cos the live connections were causing the apache server to not shut down until the connections died ...

    Hope the story at least brought some fun into your lives.

Re: Silly Badly Done Script Which Impresses the Heck Out of Client
by George_Sherston (Vicar) on Oct 23, 2001 at 15:53 UTC
    Tachyon rightly points out that you don't need both
    use CGI qw/:standard/;
    and
    my $q = CGI->new();
    etc But I think there's quite a lot to be said for keeping the former rather than the latter. I was convinced of this by pixel in this node. I don't really understand OO programming, but as far as I understand it, in most cgi scripts written with CGI.pm there's only ever going to be one object, and an OO programme with one object is an unnecessary elaboration of a functional programme. Is that right?

    Anyway, I get really bored typing $q-> over and over.

    § George Sherston
Re: Silly Badly Done Script Which Impresses the Heck Out of Client
by khippy (Scribe) on Oct 10, 2001 at 12:28 UTC
    Did I get the idea wrong?
    IMHO you are trying to block an URL if there has no
    user logged in correctly, right?

    Your code handles the lonely user trying to get that,
    but as soon as he is lucky, any other user can reach
    the URL, because the index.html exists.

    Another anoying thing is, that one might type your
    URL completed with indexalt.html to reach it
    directly.

    I don't think, that this is an useable idea to
    protect one's URL from unauthorized visits.

    --
    there are no silly questions
    killerhippy
      I'm not sure where you got that idea but it was just a widget to let the client rename the index file so that the site went live at his command as opposed to me FTPing or SSHing in for him to go live. Client was very amused BTW, not that it earned me a bonus ;}
      jg
      _____________________________________________________
      Ain't no time to hate! Barely time to wait! ~RH