<s> from twisted . application import internet , service <EOL> from twisted . internet import protocol , reactor <EOL> from twisted . web import client , resource , server <EOL> import sys , os . path <EOL> sys . path . append ( os . path . abspath ( '<STR_LIT:.>' ) ) <EOL> from easygsm . lib . serialmodem import tmpSerialPort <EOL> import modems , webmin , ipfwd , irc <EOL> class SampleService ( service . Service ) : <EOL> modem = None <EOL> ipfwd_enabled = False <EOL> irc_enabled = False <EOL> irc = None <EOL> def startService ( self ) : <EOL> log . msg ( "<STR_LIT>" ) <EOL> service . Service . startService ( self ) <EOL> def stopService ( self ) : <EOL> log . msg ( "<STR_LIT>" ) <EOL> if not self . mode . sms_terminated : <EOL> self . modem . sendLine ( chr ( <NUM_LIT> ) ) <EOL> service . Service . stopService ( self ) <EOL> def got_sms ( self , messages ) : <EOL> for message in messages : <EOL> if self . ipfwd_enabled : <EOL> pass <EOL> if self . irc_enabled : <EOL> pass <EOL> print "<STR_LIT>" , message <EOL> def sent_sms ( self , message_index ) : <EOL> print "<STR_LIT>" , message_index <EOL> def makeService ( config ) : <EOL> ser = service . MultiService ( ) <EOL> s = SampleService ( ) <EOL> m = tmpSerialPort ( modems . Telit ( mode = config . get ( "<STR_LIT>" , <NUM_LIT:1> ) , <EOL> gsc = s . got_sms , <EOL> ssc = s . sent_sms ) , <EOL> config [ "<STR_LIT>" ] , <EOL> reactor , <EOL> baudrate = config . get ( "<STR_LIT>" , <NUM_LIT> ) , <EOL> timeout = config . get ( "<STR_LIT>" , <NUM_LIT:0> ) ) <EOL> s . modem = m . protocol <EOL> if config . get ( "<STR_LIT>" ) : <EOL> e = webmin . Webmin ( ) <EOL> e . modem = s . modem <EOL> w = internet . TCPServer ( config . get ( "<STR_LIT>" , <NUM_LIT> ) , <EOL> server . Site ( e ) ) <EOL> w . setServiceParent ( ser ) <EOL> if config . get ( "<STR_LIT>" ) : <EOL> agent = client . Agent ( reactor ) <EOL> s . ipfwd_enabled = True <EOL> s . ipfwd_get_frequency = config . get ( "<STR_LIT>" ) <EOL> s . ipfwd_server = config . get ( "<STR_LIT>" ) <EOL> s . ipfwd_send_uri = config . get ( "<STR_LIT>" ) <EOL> s . ipfwd_get_uri = config . get ( "<STR_LIT>" ) <EOL> s . ipfwd_got_uri = config . get ( "<STR_LIT>" ) <EOL> if config . get ( "<STR_LIT>" ) : <EOL> s . irc_enabled = True <EOL> i = protocol . ReconnectingClientFactory ( ) <EOL> i . protocol = irc . IRCBot <EOL> s . irc = i . protocol <EOL> i . nickname = config . get ( "<STR_LIT>" ) <EOL> i . channel = config . get ( "<STR_LIT>" ) <EOL> i . send_sms = s . modem . send_sms <EOL> irc_service = internet . TCPClient ( config . get ( "<STR_LIT>" ) , <EOL> config . get ( "<STR_LIT>" , <NUM_LIT> ) , <EOL> i ) <EOL> irc_service . setServiceParent ( ser ) <EOL> return ser </s>
