home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/python
- import cgi
- import posix
- import time
- import urllib
- from string import *
- from sys import *
- from regex import *
-
- #---------------------------------------------------------------------
-
- # Configuration...
-
- # The file where the phone list is kept
- phonebookfile="/usr/local/src/GSM/phonebook";
-
- # The web server path of this script for searches
- scriptfile="/cgi-bin/pager.py";
-
- # The pager message queuing command
- qpage="/usr/local/bin/qpage";
-
- #---------------------------------------------------------------------
-
- # This is the main boddy og the code
-
- # First print out an HTML header
-
- print "Content-type: text/html"
- print
- print "<title>GSM Pager Gateway</title>"
- print "<h1>GSM Pager Gateway</h1>"
- print
-
- form = cgi.SvFormContentDict();
-
- pb = {};
-
- fh = open(phonebookfile);
- lines = fh.readlines();
- fh.close();
- del fh;
-
- for line in lines:
- parts = split(line);
- if len(parts) > 1:
- pb[parts[0]] = parts[1];
-
- if len(form) != 0:
- if not(form.has_key("username")):
- print 'You must give a user name or select other and give a telephone number.<hr>';
- giveform = 1;
- elif (form["username"] == 'other' and not(form.has_key("usernumber"))):
- print "If you select 'other' from the user list you must give a telephone number.<hr>";
- giveform = 1;
- elif not(form.has_key("message")):
- print "You must give a message text to send.<hr>";
- giveform = 1;
- elif len(form["message"]) >= 160:
- print "The message you gave it too long. Please cut it down to 160 characters.<hr>"
- giveform = 1;
- else:
- if (form["username"] == "other"):
- pn = form["usernumber"];
- else:
- pn = pb[form["username"]];
-
- pn = strip(pn);
- if pn[0] == "+":
- pn = pn[1:];
- elif pn[0] == "0":
- pn = "44"+pn[1:];
- mess = form["message"];
- m2 = "";
- for i in range(0, len(mess)):
- if mess[i] == "'":
- m2 = m2 + '"';
- else:
- m2 = m2 + mess[i];
- command = qpage+" "+pn+" '"+m2+"'";
-
- if posix.system(command) == 0:
- print "<h2>Message placed in pager queue successfully.</h2><hr>"
- else:
- print "<h2>Message failed to be queue (with unidentified error).</h2><hr>"
- # Lets give a form anyway...
- giveform = 1;
- else:
- giveform = 1;
-
- if giveform:
- # Print out a form for the user to fill in
- print '<form method=post action="'+scriptfile+'">'
- print 'Select the user you would like to page:'
- print '<Select name="username">'
- for line in lines:
- parts = split(line);
- if len(parts) > 1:
- if (form.has_key("username") and parts[0] == form["username"]):
- print '<Option selected>'+parts[0];
- else:
- print '<Option>'+parts[0];
- if (form.has_key("username") and form["username"] == 'other'):
- print '<Option selected>other';
- else:
- print '<option>other'
- print '</select>'
- print "or select 'other' and enter the telephone number of the GSM telephone you want to contact:"
- if form.has_key("usernumber"):
- print '<Input name="usernumber" type="text" size="12" value='+form["usernumber"]+'>.<p>'
- else:
- print '<Input name="usernumber" type="text" size="12">.<p>'
- print 'Enter the text of your message (up to 160 characters).<br>'
- print '<textarea name="message" rows=4 cols=60>'
- if (form.has_key("message")):
- print form["message"];
- print '</textarea>'
- print '<p>'
- print """
- <INPUT TYPE="submit" VALUE="Send message">
- <INPUT TYPE="reset" VALUE="Clear Form">
- <p>
- """
-
-