I was suffering from hundreds of people using scripts on my server, so I've started searching around for a free script protector, which would read authorised domains from a text file. I couldn't find any, so I found myself learning a little Perl. This is my first script, so please don't laugh if you see silly mistakes and needlessly long code.. Need your ideas and help to make it better.

The script needs a text file with authorised domains in it, one per line.. And the log file.. I could not find out how to create the log file if it does not exist. The code should do, but I guess it's a good old permissions problem. Here it comes, will be waiting for your comments..
#!/usr/bin/perl # SECURE DOMAIN SCRIPT PROTECTOR # # This script protects any Perl script against unauthorised use. # Put it before the script but after the line "#!/usr/bin/perl". # Script reads "authoriseddomains.txt" file which includes authorised # domains, one domain per line. If calling URL does not match any # of the domains listed, gives an error and logs an error message. # # Created 30/09/2001 Last Modified 06/10/2001 # Created by : Mustafa Odabasi - modabasi@virgo.com.tr # Version 1.0.1b ###################################################################### +###### # DEFINING DATE VARIABLE chop ($date = `/usr/bin/date`); # OPENING AUTHENTICATION FILE open(DOM,"authoriseddomains.txt") or die ("Can't open authoriseddomain +s.txt: $!"); # CONTROL PROSEDURE while (<DOM>){ chomp; if ("$ENV{'HTTP_REFERER'}" =~ /$_/i){ $sonuc = 1; { } } if (eof(DOM)) { if ($sonuc != 1) { # LOGGING UNAUTHORISED ACCESS open(LOG,">> /var/log/scriptprotector.log") or die ("Can't open script +protector.log: $!"); print LOG "$date Calling URL: $ENV{'HTTP_REFERER'} Client: $ENV{'REMOTE_ADDR'} -----------------------------------------------\n"; close(LOG); # SHOW AN ERROR MESSAGE TO THE CLIENT print "Content-type: text/html\n\n"; print "<html><head><title>AUTHORISATION FAILED</title></head> <body bgcolor=white> <br><center><b><font face=\"Arial\" color=red size=\"3\">AUTHORISATION + FAILED</font> <br><br><font face=\"Arial\" color=blue size=\"3\">$ENV{'HTTP_REFERER' +}</font> <br><br><font face=\"Arial\" color=red size=\"3\">is not authorised to + use this script. <br><br>Remote address </font><font face=\"Arial\" color=blue size=\"3 +\">$ENV{'REMOTE_ADDR'}</font> <font face=\"Arial\" color=red size=\"3 +\">logged. <br><br>$ENV{'SERVER_SIGNATURE'} </b></font></center> </body></html>"; exit; } } } close(DOM); ###################################################################### +###### # PROTECTION CODES END HERE, YOUR EXISTING SCRIPT CONTINUES AFTER THIS + POINT ###################################################################### +######


Mustafa Odabasi
modabasi@virgo.com.tr

In reply to Script protector from a 'very' newbie.. by modabasi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.