Attachment 'PhoneDial.py'

Download

   1 """
   2     MoinMoin - "PhoneDial" action
   3     =============================
   4 
   5     Copyright (c) 2002 by Thomas Waldmann <tw@waldmann-edv.de>
   6     All rights reserved, see COPYING for details.
   7 
   8     This is released under the Gnu General Public Licence. A copy of
   9     this can be found at http://www.opensource.org/licenses/gpl-license.html
  10 
  11     SerialLink class taken from PyGarmin (GPL), see http://pygarmin.sourceforge.net/
  12 
  13     So what is this thing doing and how it has to be configured ?
  14     =============================================================
  15 
  16     This action dials a phone number using an Eurit 40 ISDN telephone
  17     attached via a serial interface to the SERVERs COM ports.
  18 
  19     You maybe could also use a modem for dialing and then take the call
  20     with a phone attached to the same line. This action simply sends an
  21     ATD<phonenumber> to the device attached to the serial port.
  22 
  23     Add this to your moin_config.py:
  24     phonedial_serialdevice = "COM1"             (Win32 and untested)
  25     phonedial_serialdevice = "/dev/ttyS0"       (Linux)
  26     
  27     Add this to your ./data/intermap.txt (in your wiki):
  28     FON http://whatever/moin.cgi?action=PhoneDial&number=
  29     
  30     Add this to your pages (example):
  31     Ring my best friend: FON:0123456789
  32     
  33     After saving the page, the FON entry should get a link to the
  34     PhoneDial action. And if you click on it, it should dial the number
  35     using the device attached to the com port.
  36 
  37     BTW: these are my first footsteps in Python and MoinMoin Programming.
  38     
  39     So if you are more experienced concerning Python (and moinmoin), then
  40     please review this and please, if you improve it, send me a copy of your
  41     improvements. Thanks.
  42 
  43     Version History:
  44     
  45     20020110 first public version - "it works for me" 
  46     20020206 filtering out special characters like "-" or "/" for not
  47              confusing the Eurit phone
  48     
  49     Known Bugs:
  50     
  51     After clicking on a FON link, you will see the FrontPage.
  52     
  53     Known Limitations:
  54     
  55     It is the web server computer (where moin.cgi runs) that is dialling via
  56     the com port. If you work at a different PC far away from the server or
  57     if you have multiple phones you want to get dialling, you maybe need more
  58     than this script.
  59         
  60 """
  61 
  62 # is this all needed ?:
  63 import os, string, time, sys
  64 from MoinMoin import config, util, wikiutil, webapi
  65 from MoinMoin.Page import Page
  66 
  67 # Now some practical implementations
  68 
  69 class SerialLink:
  70    """
  71      A serial link will look something like this, though real
  72      implementations will probably override most of it.
  73    """
  74    def __init__(self, f, timeout = 5):
  75       self.f = f
  76       self.initserial()
  77       self.settimeout(timeout)
  78 
  79    def initserial(self):
  80       "Set up baud rate, handshaking, etc"
  81       pass
  82    
  83    def read(self, n):
  84       """
  85       Read n bytes and return them. Real implementations should
  86       raise a LinkException if there is a timeout > self.timeout
  87       """
  88       return self.f.read(n)
  89 
  90    def write(self, data):
  91       self.f.write(data)
  92 
  93    def settimeout(self, secs):
  94       self.timeout = secs
  95       
  96    def __del__(self):
  97       """Should close down any opened resources"""
  98       pass
  99 
 100 
 101 class UnixSerialLink(SerialLink):
 102 
 103    def __init__(self, device):
 104       f = open(device, "w+", 0)
 105       SerialLink.__init__(self, f)
 106 
 107    def initserial(self):
 108       from tty import *
 109       
 110       fd = self.f.fileno()
 111       setraw(fd)
 112       mode = tcgetattr(fd)
 113       mode[ISPEED] = mode[OSPEED] = B2400
 114       # mode[LFLAG] = mode[LFLAG] | ECHO
 115       tcsetattr(fd, TCSAFLUSH, mode)
 116 
 117    def read(self, n):
 118       import select
 119       
 120       i = 0
 121       data = []
 122       while i < n:
 123          iset,oset,eset = select.select([self.f.fileno()], [], [], self.timeout)
 124          if iset == []:
 125            raise LinkException, "time out"
 126          b = self.f.read(1)
 127          data.append(b)
 128          i = i + 1
 129       return string.join(data,'')
 130 
 131    def __del__(self):
 132       self.f.close()
 133 
 134 # Win32 Serial Link ==================================================
 135 
 136 if os.name == 'nt':
 137    from win32file import * 
 138    import win32con
 139 
 140 class Win32SerialLink(SerialLink):
 141    def __init__(self, device):
 142       self.device = device
 143       handle = CreateFile(device,
 144          win32con.GENERIC_READ | win32con.GENERIC_WRITE,
 145          0, # exclusive access
 146          None, # no security
 147          win32con.OPEN_EXISTING,
 148          0,
 149          None)
 150       SerialLink.__init__(self, handle)
 151 
 152    def initserial(self):
 153       # Remove anything that was there
 154       PurgeComm(self.f, PURGE_TXABORT | PURGE_RXABORT
 155          | PURGE_TXCLEAR | PURGE_RXCLEAR )
 156 
 157       # Setup the connection info.
 158       dcb = GetCommState( self.f )
 159       dcb.BaudRate = CBR_2400
 160       dcb.ByteSize = 8
 161       dcb.Parity = NOPARITY
 162       dcb.StopBits = ONESTOPBIT
 163       SetCommState(self.f, dcb)
 164 
 165    def read(self, n):
 166       buffer = AllocateReadBuffer(n)
 167       rc, data = ReadFile(self.f, buffer)
 168       if len(data) != n:
 169          raise LinkException, "time out";
 170       return data
 171 
 172    def write(self, n):
 173       rc,n = WriteFile(self.f, n)
 174       if rc:
 175          raise LinkException, "WriteFile error";
 176 
 177    def settimeout(self, secs):
 178       SerialLink.settimeout(self, secs)
 179       # Setup time-outs
 180       timeouts = 0xFFFFFFFF, 0, 1000*secs, 0, 1000*secs
 181       SetCommTimeouts(self.f, timeouts)
 182 
 183    def __del__(self):
 184       CloseHandle(self.f)
 185 
 186       
 187 class Eurit:
 188    """
 189    A representation of the Eurit telephone, which is connected
 190    via some physical connection, typically a SerialLink of some sort.
 191    """
 192    def __init__(self):
 193       if os.name == 'nt':
 194          serialDevice =  config.phonedial_serialdevice
 195          self.link = Win32SerialLink(serialDevice)
 196       else:
 197          serialDevice =  config.phonedial_serialdevice
 198          self.link = UnixSerialLink(serialDevice)
 199    
 200    # === this is the important part, here we do the dialling:
 201    def dial(self, number):
 202       self.link.write("ATD" + number + "\r");
 203    # ========================================================
 204 
 205 
 206 def execute(pagename, form):
 207 
 208     # get the phone number
 209     if form.has_key('number'):
 210         number = form['number'].value
 211     else:
 212         number = ""
 213 
 214     number = string.replace(number,'/','')
 215     number = string.replace(number,'-','')
 216     
 217     eurit = Eurit()
 218     eurit.dial(number)
 219     page = Page(pagename)
 220     page.send_page(form, msg="<b>Dialled " + number + ".</b>")

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2011-04-14 07:28:03, 4.7 KB) [[attachment:CreateNewPage.py]]
  • [get | view] (2011-04-14 07:26:24, 4.2 KB) [[attachment:CreateNewPage1.6.py]]
  • [get | view] (2006-09-10 21:29:29, 40.4 KB) [[attachment:CreatePdfDocument2_0_3.py]]
  • [get | view] (2006-09-12 06:05:06, 40.5 KB) [[attachment:CreatePdfDocument2_0_4.py]]
  • [get | view] (2006-09-12 12:00:09, 40.6 KB) [[attachment:CreatePdfDocument2_0_5.py]]
  • [get | view] (2006-11-14 21:56:11, 43.5 KB) [[attachment:CreatePdfDocument2_0_6.py]]
  • [get | view] (2006-11-15 17:00:47, 43.8 KB) [[attachment:CreatePdfDocument2_0_7.py]]
  • [get | view] (2006-11-16 22:06:18, 43.8 KB) [[attachment:CreatePdfDocument2_0_8.py]]
  • [get | view] (2006-12-17 15:54:21, 43.6 KB) [[attachment:CreatePdfDocument2_0_9.py]]
  • [get | view] (2007-08-20 09:10:23, 67.2 KB) [[attachment:CreatePdfDocument2_1_0.py]]
  • [get | view] (2007-08-21 07:39:49, 67.1 KB) [[attachment:CreatePdfDocument2_1_1.py]]
  • [get | view] (2007-09-11 19:16:37, 67.3 KB) [[attachment:CreatePdfDocument2_1_2.py]]
  • [get | view] (2007-09-18 20:17:58, 68.1 KB) [[attachment:CreatePdfDocument2_1_3.py]]
  • [get | view] (2007-09-21 13:32:54, 71.1 KB) [[attachment:CreatePdfDocument2_1_4.py]]
  • [get | view] (2007-09-23 20:56:30, 73.4 KB) [[attachment:CreatePdfDocument2_1_5.py]]
  • [get | view] (2007-09-25 20:54:48, 74.5 KB) [[attachment:CreatePdfDocument2_2_0.py]]
  • [get | view] (2008-06-23 21:08:49, 77.0 KB) [[attachment:CreatePdfDocument2_3_0.py]]
  • [get | view] (2008-06-26 19:25:07, 81.0 KB) [[attachment:CreatePdfDocument2_3_1.py]]
  • [get | view] (2008-07-06 05:50:38, 83.1 KB) [[attachment:CreatePdfDocument2_3_2.py]]
  • [get | view] (2008-07-09 17:42:02, 83.3 KB) [[attachment:CreatePdfDocument2_3_3.py]]
  • [get | view] (2008-09-07 11:11:01, 83.5 KB) [[attachment:CreatePdfDocument2_3_4.py]]
  • [get | view] (2009-01-11 15:53:09, 84.3 KB) [[attachment:CreatePdfDocument2_3_5.py]]
  • [get | view] (2009-02-16 06:52:06, 84.2 KB) [[attachment:CreatePdfDocument2_3_6.py]]
  • [get | view] (2010-01-29 11:53:21, 82.8 KB) [[attachment:CreatePdfDocument2_4_0.py]]
  • [get | view] (2010-01-31 14:10:03, 84.6 KB) [[attachment:CreatePdfDocument2_4_1.py]]
  • [get | view] (2010-09-18 16:23:23, 85.6 KB) [[attachment:CreatePdfDocument2_4_2.py]]
  • [get | view] (2006-06-16 20:56:53, 4.9 KB) [[attachment:FlashManager.py-1.5.3-1]]
  • [get | view] (2003-12-07 18:15:53, 3.9 KB) [[attachment:HTML2MoinMoin.py]]
  • [get | view] (2005-10-16 08:24:35, 4.9 KB) [[attachment:HelpOn-1.3.5-4.py]]
  • [get | view] (2006-02-03 19:21:04, 4.9 KB) [[attachment:HelpOn-1.5.1-5.py]]
  • [get | view] (2006-07-04 10:45:22, 4.8 KB) [[attachment:HelpOn-1.5.4-6.py]]
  • [get | view] (2006-07-04 22:39:14, 4.8 KB) [[attachment:HelpOn-1.6.0-7.py]]
  • [get | view] (2006-07-06 13:50:17, 4.0 KB) [[attachment:HelpOn-1.6.0-8.py]]
  • [get | view] (2008-01-10 17:43:24, 4.8 KB) [[attachment:HelpOn-1.6.0-9.py]]
  • [get | view] (2008-08-19 14:44:54, 5.0 KB) [[attachment:HelpOn-1.7.1-10.py]]
  • [get | view] (2005-02-20 18:28:34, 10.8 KB) [[attachment:IRSS.py]]
  • [get | view] (2005-03-09 22:46:23, 2.9 KB) [[attachment:ImportHtml-1.2.py]]
  • [get | view] (2003-12-07 18:15:53, 2.8 KB) [[attachment:ImportHtml.py]]
  • [get | view] (2003-12-07 18:15:53, 1.8 KB) [[attachment:IrcChat.py]]
  • [get | view] (2008-06-09 11:27:20, 4.4 KB) [[attachment:MoinCrypt.py]]
  • [get | view] (2010-11-29 12:08:27, 7.5 KB) [[attachment:PageActions.py]]
  • [get | view] (2006-08-07 15:12:19, 0.5 KB) [[attachment:PermanentLink.py]]
  • [get | view] (2003-12-07 18:15:53, 6.3 KB) [[attachment:PhoneDial.py]]
  • [get | view] (2005-04-17 14:21:47, 3.6 KB) [[attachment:RecommendPage-1.3.4-1.py]]
  • [get | view] (2005-04-19 18:21:52, 5.5 KB) [[attachment:RecommendPage-1.3.4-2.py]]
  • [get | view] (2005-05-02 19:53:09, 5.6 KB) [[attachment:RecommendPage-1.3.4-3.py]]
  • [get | view] (2005-09-03 07:33:35, 6.3 KB) [[attachment:RecommendPage-1.3.4-4.py]]
  • [get | view] (2005-09-05 17:44:03, 6.9 KB) [[attachment:RecommendPage-1.3.5-5.py]]
  • [get | view] (2005-09-07 16:42:26, 7.5 KB) [[attachment:RecommendPage-1.3.5-6.py]]
  • [get | view] (2005-09-08 16:06:28, 7.7 KB) [[attachment:RecommendPage-1.3.5-7.py]]
  • [get | view] (2005-11-01 11:31:51, 9.0 KB) [[attachment:RecommendPage-1.3.5-8.py]]
  • [get | view] (2006-02-03 19:40:51, 8.3 KB) [[attachment:RecommendPage-1.5.1-9.py]]
  • [get | view] (2008-01-11 09:14:35, 6.8 KB) [[attachment:RecommendPage-1.6.0-10.py]]
  • [get | view] (2008-08-19 14:44:59, 6.9 KB) [[attachment:RecommendPage-1.7.1-11.py]]
  • [get | view] (2008-06-09 11:27:40, 1.7 KB) [[attachment:ShowActions.py]]
  • [get | view] (2008-06-09 10:34:02, 5.3 KB) [[attachment:ShowDecrypted.py]]
  • [get | view] (2005-03-30 21:17:28, 7.7 KB) [[attachment:Slideshow.py]]
  • [get | view] (2004-02-02 20:48:31, 2.0 KB) [[attachment:SubscribeUser.py]]
  • [get | view] (2007-01-26 17:08:30, 2.2 KB) [[attachment:Subscribers-1.6.0.py]]
  • [get | view] (2003-12-07 18:15:53, 1.8 KB) [[attachment:Subscribers.py]]
  • [get | view] (2006-03-18 23:16:51, 0.8 KB) [[attachment:UserPreferences.py]]
  • [get | view] (2004-01-05 09:56:25, 8.1 KB) [[attachment:VisualSiteMap.py]]
  • [get | view] (2015-08-30 21:04:23, 11.1 KB) [[attachment:VisualSiteMap_1.10.py]]
  • [get | view] (2004-10-08 10:59:16, 9.3 KB) [[attachment:VisualSiteMap_1.2.py]]
  • [get | view] (2005-03-16 01:30:09, 9.8 KB) [[attachment:VisualSiteMap_1.3.py]]
  • [get | view] (2014-08-19 01:34:10, 10.8 KB) [[attachment:VisualSiteMap_1.9.py]]
  • [get | view] (2007-08-18 18:52:55, 1.0 KB) [[attachment:backlink.py]]
  • [get | view] (2007-03-15 05:53:49, 23.5 KB) [[attachment:findandreplace0.1Beta.py]]
  • [get | view] (2005-03-27 20:32:10, 3.6 KB) [[attachment:gallery2image-1.3.3-1.py]]
  • [get | view] (2005-08-03 20:14:56, 4.0 KB) [[attachment:gallery2image-1.3.3-2.py]]
  • [get | view] (2005-11-13 18:10:26, 20.7 KB) [[attachment:gallery2image-1.3.5-10.py]]
  • [get | view] (2005-11-25 22:03:50, 20.8 KB) [[attachment:gallery2image-1.3.5-11.py]]
  • [get | view] (2005-08-08 17:23:43, 8.4 KB) [[attachment:gallery2image-1.3.5-4.py]]
  • [get | view] (2005-08-13 15:15:45, 13.7 KB) [[attachment:gallery2image-1.3.5-5.py]]
  • [get | view] (2005-08-31 22:05:22, 15.5 KB) [[attachment:gallery2image-1.3.5-6.py]]
  • [get | view] (2005-10-29 20:23:50, 15.9 KB) [[attachment:gallery2image-1.3.5-8.py]]
  • [get | view] (2005-11-01 11:31:24, 17.6 KB) [[attachment:gallery2image-1.3.5-9.py]]
  • [get | view] (2006-01-27 20:52:32, 20.9 KB) [[attachment:gallery2image-1.5.1-12.py]]
  • [get | view] (2006-08-06 09:01:01, 22.1 KB) [[attachment:gallery2image-1.5.4-13.py]]
  • [get | view] (2006-08-11 18:21:40, 22.2 KB) [[attachment:gallery2image-1.5.4-14.py]]
  • [get | view] (2006-11-16 20:23:27, 22.6 KB) [[attachment:gallery2image-1.5.6-16.py]]
  • [get | view] (2006-08-11 18:30:22, 22.2 KB) [[attachment:gallery2image-1.6.0-15.py]]
  • [get | view] (2008-02-06 10:13:45, 22.3 KB) [[attachment:gallery2image-1.6.0-16.py]]
  • [get | view] (2008-05-20 15:51:09, 22.4 KB) [[attachment:gallery2image-1.6.3-17.py]]
  • [get | view] (2006-09-06 06:19:48, 1.3 KB) [[attachment:getmmap.py]]
  • [get | view] (2004-07-18 09:48:00, 1.5 KB) [[attachment:localnames.py]]
  • [get | view] (2005-03-25 15:02:31, 2.6 KB) [[attachment:newpageonly.py]]
  • [get | view] (2005-03-30 09:02:00, 3.5 KB) [[attachment:newpageonly_20050330.py]]
  • [get | view] (2006-06-06 19:12:27, 9.7 KB) [[attachment:pdf.py]]
  • [get | view] (2006-08-30 10:51:51, 36.0 KB) [[attachment:pdf2_0_0.py]]
  • [get | view] (2006-08-30 13:57:36, 36.5 KB) [[attachment:pdf2_0_1.py]]
  • [get | view] (2006-02-04 04:25:29, 1.0 KB) [[attachment:sisterindex.py]]
  • [get | view] (2004-10-28 07:33:10, 0.7 KB) [[attachment:xml.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.