home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilsf / gsm / GSM / pager_py < prev    next >
Encoding:
Text File  |  1995-06-10  |  3.2 KB  |  125 lines

  1. #!/usr/local/bin/python
  2. import cgi
  3. import posix
  4. import time
  5. import urllib
  6. from string import *
  7. from sys import *
  8. from regex import *
  9.  
  10. #---------------------------------------------------------------------
  11.  
  12. # Configuration...
  13.  
  14. # The file where the phone list is kept
  15. phonebookfile="/usr/local/src/GSM/phonebook";
  16.  
  17. # The web server path of this script for searches
  18. scriptfile="/cgi-bin/pager.py";
  19.  
  20. # The pager message queuing command
  21. qpage="/usr/local/bin/qpage";
  22.  
  23. #---------------------------------------------------------------------
  24.  
  25. # This is the main boddy og the code
  26.  
  27. # First print out an HTML header
  28.  
  29. print "Content-type: text/html"
  30. print
  31. print "<title>GSM Pager Gateway</title>"
  32. print "<h1>GSM Pager Gateway</h1>"
  33. print
  34.  
  35. form = cgi.SvFormContentDict();
  36.  
  37. pb = {};
  38.  
  39. fh = open(phonebookfile);
  40. lines = fh.readlines();
  41. fh.close();
  42. del fh;
  43.  
  44. for line in lines:
  45.     parts = split(line);
  46.     if len(parts) > 1:
  47.         pb[parts[0]] = parts[1];
  48.  
  49. if len(form) != 0:
  50.     if not(form.has_key("username")):
  51.         print 'You must give a user name or select other and give a telephone number.<hr>';
  52.         giveform = 1;
  53.     elif (form["username"] == 'other' and not(form.has_key("usernumber"))):
  54.         print "If you select 'other' from the user list you must give a telephone number.<hr>";
  55.         giveform = 1;
  56.     elif not(form.has_key("message")):
  57.         print "You must give a message text to send.<hr>";
  58.         giveform = 1;
  59.     elif len(form["message"]) >= 160:
  60.         print "The message you gave it too long.  Please cut it down to 160 characters.<hr>"
  61.         giveform = 1;        
  62.     else:
  63.         if (form["username"] == "other"):
  64.             pn = form["usernumber"];
  65.         else:
  66.             pn = pb[form["username"]];
  67.  
  68.         pn = strip(pn);
  69.         if pn[0] == "+":
  70.             pn = pn[1:];
  71.         elif pn[0] == "0":
  72.             pn = "44"+pn[1:];
  73.         mess = form["message"];
  74.         m2 = "";
  75.         for i in range(0, len(mess)):
  76.             if mess[i] == "'":
  77.                 m2 = m2 + '"';
  78.             else:
  79.                 m2 = m2 + mess[i];
  80.         command = qpage+" "+pn+" '"+m2+"'";
  81.  
  82.         if posix.system(command) == 0:
  83.             print "<h2>Message placed in pager queue successfully.</h2><hr>"
  84.         else:
  85.             print "<h2>Message failed to be queue (with unidentified error).</h2><hr>"
  86.         # Lets give a form anyway...
  87.         giveform = 1;
  88. else:
  89.     giveform = 1;
  90.  
  91. if giveform:
  92.     # Print out a form for the user to fill in
  93.     print '<form method=post action="'+scriptfile+'">'
  94.     print 'Select the user you would like to page:'
  95.     print '<Select name="username">'
  96.     for line in lines:
  97.         parts = split(line);
  98.         if len(parts) > 1:
  99.             if (form.has_key("username") and parts[0] == form["username"]):
  100.                 print '<Option selected>'+parts[0];
  101.             else:
  102.                 print '<Option>'+parts[0];
  103.     if (form.has_key("username") and form["username"] == 'other'):
  104.         print '<Option selected>other';
  105.     else:
  106.         print '<option>other'
  107.     print '</select>'
  108.     print "or select 'other' and enter the telephone number of the GSM telephone you want to contact:"
  109.     if form.has_key("usernumber"):
  110.         print '<Input name="usernumber" type="text" size="12" value='+form["usernumber"]+'>.<p>'
  111.     else:
  112.         print '<Input name="usernumber" type="text" size="12">.<p>'
  113.     print 'Enter the text of your message (up to 160 characters).<br>'
  114.     print '<textarea name="message" rows=4 cols=60>'
  115.     if (form.has_key("message")):
  116.         print form["message"];
  117.     print '</textarea>'
  118.     print '<p>'
  119.     print """
  120.     <INPUT TYPE="submit" VALUE="Send message">
  121.     <INPUT TYPE="reset" VALUE="Clear Form">
  122.     <p>
  123.     """
  124.  
  125.