; Example password protection gadget ; ; To set up this gadget, save this to a file called "password.ms2" ; Next, create a directory called "ms2" in your root Islandnet directory. ; Once this is done upload the password.ms2 file. You will also need to ; create a password file called password.txt that is a ; simple text file of the of the format: ; ; username:password ; i.e. ; bob:secretword1234 ; ; First define some values for use later on ; you can change the password filename to whatever you want ; here. Also, if you want your files somewhere else other than ; the ms2 directory, change it here. The gadget knows how to ; handle the following formats: gif, jpeg, zip, html, txt. It ; treats anything else as "octet/stream" which means that it ; treats it as a binary file. ; ; To actually use this gadget you will need to call it in the following manner: ; ; http://www.islandnet.com/cgi-bin/ms2/login/password/filename ; i.e. ; http://www.islandnet.com/cgi-bin/ms2/moron/password/grannybeta1.zip passfile = "ms2/password.txt" subdirectory = "ms2/" ; Here we get the filename that the user wants, ; their username and their password. We strip ; out the / character so they cannot get out of the ms2 directory filename = subdirectory + strip( varget( "arg", 3 ), "/" ) response = decode() type = nth( filename, 2, "." ) ; Here we figure out what mimetype to use for the file ; If you need a different mimetype, add it here if ( ( type=="htm" ) || ( type=="html" ) ) mime = "text/html" elif type == "txt" mime = "text/plain" elif ( ( type=="jpg" ) || ( type=="jpeg" ) ) mime = "image/jpeg" elif type == "gif" mime = "image/gif" elif type == "zip" mime = "application/zip" else mime = "application/octet-stream" endif username = nth( response, 1, ":" ) password = nth( response, 2, ":" ) ; Now that we have their password we scan through the password file ; for a match match = 0 lock( passfile ) if input = open( passfile , "r" ) record = collapse( read( input ) ) if not eof( input ) loop if ( pos( ":",record ) > 0) ; catch blank lines match = ( ( username == nth( record, 1 , ":") ) \ && ( password == nth( record, 2 , ":" ) ) ) endif record = read( input ) until match || eof( input ) endif endif close( input ) unlock( passfile ) ; If we have a match and the file they asked for exists, ; then send them the file. If we do not have a match ; prompt for the password again. if match if exists( filename ) mimetype( mime ) include( filename ) else print( "Unknown Filename" ) endif exit else getauth( "Password Protected Area" ) print( "Sorry, you need to specify a username and password." ) exit endif