The following program is theoretically supposed to use a supported library. Issues have come up where the library is not working and now another interface is being requierd to be used. <br><br>At this point I'm looking at just changing the send commands but don't feel confident in doing so. Wondering specifically what would have to be changed to what.<br>
<br>Thanks for your time :)<br><br>#!/usr/bin/env python<br>#<br># ogss -- SMS Shell through Gmail and libgmail<br>#<br># Version 0.2<br>#<br># Author: <a href="mailto:btoews@mastahyeti.com">btoews@mastahyeti.com</a><br>#<br>
# License: GPL 2.0<br>#<br># NOTE:<br>#   You should ensure you are permitted to use this script before using it<br>#   to access Google's Gmail servers.<br>#<br>def main(argv):<br>    print "Starting ogss"<br>
<br>    logfile = os.path.join(os.environ["HOME"],"ogss.log")<br>    print "Logfile at:"+logfile<br>    execd = []<br>    #Checking to see if the logfile already exists<br>    #if it doesn't we create it.<br>
    if not os.path.exists(logfile):<br>        print "Creating log file"<br>        try:<br>            open(logfile,"w").close()<br>        except:<br>            print "Failed to open create log file. Check permissions"<br>
            exit()<br>    #Opening log file for reading and parseing its contents into a list<br>    #Must do this to ensure that we dont execute old commands<br>    print "Opening log file for reading"<br>    try:<br>
        r = open(logfile,"r")<br>        for line in r:<br>            eid = line.split("~")<br>            if len(eid)>=2:    <br>                execd.append(int(eid[0]))<br>        r.close()<br>    except:<br>
        print "Failed to open or read log file. Check permissions"<br>        exit()<br><br>    clist = [["3 River Wireless","@<a href="http://sms.3rivers.net">sms.3rivers.net</a>"],["7-11 Speakout","@<a href="http://cingularme.com">cingularme.com</a>"],["Airtel (Karnataka","India)Alaska Communications Systems"],["Alltel Wireless","@<a href="http://message.alltel.com">message.alltel.com</a>"],["AT&T Wireless","@<a href="http://txt.att.net">txt.att.net</a>"],["Bell Mobility (Canada)","@<a href="http://txt.bell.ca">txt.bell.ca</a>"],["Boost Mobile","@<a href="http://myboostmobile.com">myboostmobile.com</a>"],["Cellular One (Dobson)","@<a href="http://mobile.celloneusa.com">mobile.celloneusa.com</a>"],["Cingular (Postpaid)","@<a href="http://cingularme.com">cingularme.com</a>"],["Centennial Wireless","@<a href="http://cwemail.com">cwemail.com</a>"],["Cingular (GoPhone prepaid)","@<a href="http://cingularme.com">cingularme.com</a>"],["Claro (Nicaragua)","@<a href="http://ideasclaro-ca.com">ideasclaro-ca.com</a>"],["Comcel","@<a href="http://comcel.com.co">comcel.com.co</a>"],["Cricket","@<a href="http://sms.mycricket.com">sms.mycricket.com</a>"],["CTI","@<a href="http://sms.ctimovil.com.ar">sms.ctimovil.com.ar</a>"],["Emtel (Mauritius)","@<a href="http://emtelworld.net">emtelworld.net</a>"],["Fido (Canada)","@<a href="http://fido.ca">fido.ca</a>"],["General Communications Inc.","@<a href="http://msg.gci.net">msg.gci.net</a>"],["Globalstar","@<a href="http://msg.globalstarusa.com">msg.globalstarusa.com</a>"],["Helio","@<a href="http://myhelio.com">myhelio.com</a>"],["Illinois Valley Cellular","@<a href="http://ivctext.com">ivctext.com</a>"],["i wireless",".<a href="mailto:iws@iwspcs.net">iws@iwspcs.net</a>"],["Meteor (Ireland)","@<a href="http://sms.mymeteor.ie">sms.mymeteor.ie</a>"],["Mero Mobile (Nepal)","@<a href="http://sms.spicenepal.com">sms.spicenepal.com</a>"],["MetroPCS","@<a href="http://mymetropcs.com">mymetropcs.com</a>"],["Movicom","@<a href="http://movimensaje.com.ar">movimensaje.com.ar</a>"],["Mobitel (Sri Lanka)","@<a href="http://sms.mobitel.lk">sms.mobitel.lk</a>"],["Movistar (Colombia)","@<a href="http://movistar.com.co">movistar.com.co</a>"],["MTN (South Africa)","@<a href="http://sms.co.za">sms.co.za</a>"],["MTS (Canada)","@<a href="http://text.mtsmobility.com">text.mtsmobility.com</a>"],["Nextel (Argentina)","@<a href="http://nextel.net.ar">nextel.net.ar</a>"],["Orange (Poland)","@orange.pl"],["Personal (Argentina)","@<a href="http://personal-net.com.ar">personal-net.com.ar</a>"],["Plus GSM (Poland)","@<a href="http://text.plusgsm.pl">text.plusgsm.pl</a>"],["President\s Choice (Canada)","@<a href="http://txt.bell.ca">txt.bell.ca</a>"],["Qwest","@<a href="http://qwestmp.com">qwestmp.com</a>"],["Rogers (Canada)","@<a href="http://pcs.rogers.com">pcs.rogers.com</a>"],["Sasktel (Canada)","@<a href="http://sms.sasktel.com">sms.sasktel.com</a>"],["Setar Mobile email (Aruba)","@<a href="http://mas.aw">mas.aw</a>"],["Solo Mobile","@<a href="http://txt.bell.ca">txt.bell.ca</a>"],["Sprint (PCS)","@<a href="http://messaging.sprintpcs.com">messaging.sprintpcs.com</a>"],["Sprint (Nextel)","@<a href="http://page.nextel.com">page.nextel.com</a>"],["Suncom","@<a href="http://tms.suncom.com">tms.suncom.com</a>"],["T-Mobile","@<a href="http://tmomail.net">tmomail.net</a>"],["T-Mobile (Austria)","@<a href="http://sms.t-mobile.at">sms.t-mobile.at</a>"],["Telus Mobility (Canada)","@<a href="http://msg.telus.com">msg.telus.com</a>"],["Thumb Cellular","@<a href="http://sms.thumbcellular.com">sms.thumbcellular.com</a>"],["Tigo (Formerly Ola)","@<a href="http://sms.tigo.com.co">sms.tigo.com.co</a>"],["Unicel","@<a href="http://utext.com">utext.com</a>"],["US Cellular","@<a href="http://email.uscc.net">email.uscc.net</a>"],["Verizon","@<a href="http://vtext.com">vtext.com</a>"],["Virgin Mobile (Canada)","@<a href="http://vmobile.ca">vmobile.ca</a>"],["Virgin Mobile (USA)","@<a href="http://vmobl.com">vmobl.com</a>"],["YCC","@<a href="http://sms.ycc.ru">sms.ycc.ru</a>"],["Orange (UK)","@<a href="http://orange.net">orange.net</a>"],["Cincinnati Bell Wireless","@<a href="http://gocbw.com">gocbw.com</a>"],["T-Mobile Germany","@<a href="http://t-mobile-sms.de">t-mobile-sms.de</a>"],["Vodafone Germany","@<a href="http://vodafone-sms.de">vodafone-sms.de</a>"],["E-Plus","@<a href="http://smsmail.eplus.de">smsmail.eplus.de</a>"]]<br>
<br>    print "Parsing user input"<br>    if len(argv)<4:<br>        if len(argv) == 2:<br>            if argv[1] == "-c":<br>                counter = 0        <br>                for car in clist:<br>
                    print str(counter) + "--" + car[0]<br>                    counter += 1<br>                exit()<br>        else:<br>            print "------Useage---------------------------------------------------------------\n\r------Start Service --- ogss.py USERNAME PASSWORD CELL-NUMBER CARRIER-NUMBER\n\r------List carriers --- ogss.py -c"<br>
            print "------Useage from phone----------------------------------------------------\n\r------Ogss COMMAND"<br>            exit()<br>    username   = argv[1]<br>    password   = argv[2]<br>    number     = argv[3]<br>
    carrier     = clist[int(argv[4])]<br>    cell_email = number+carrier[1]<br><br>    print "Connecting to Gmail"<br>    account = libgmail.GmailAccount(username,password)<br>    print "Logging into Gmail"<br>
    account.login()<br><br>    print "Opening log file for writing"<br>    try:<br>        w = open(logfile,"a")<br>    except:<br>        print "Failed to open log file. Check permissions."<br>
        exit()<br><br>    #If the logfile is empty (if this is the first use) we want to<br>    #send instructions to the users cell phone.    <br>    #if len(execd) < 1:<br>    #    instructions = libgmail.GmailComposedMessage(cell_email,"OGSS Instructions","To use OGSS reply to this message with an SMS starting with \"Ogss\". Whatever follows \"Ogss\" will be executed on your computer")<br>
    #    account.sendMessage(instructions)<br>    print "Listening for commands"<br>    while True:<br>        try:<br>            searchResult = account.getMessagesByQuery("from:"+cell_email,True)<br>
            maxid = 0<br>            if len(searchResult)>0:<br>                #Here we search through the inbox to find the most recent message sent<br>                #from the specified phone number<br>                for thread in searchResult:<br>
                    for message in thread:<br>                        if cell_email == message.sender:<br>                            if int(<a href="http://message.id">message.id</a>,16)>maxid:<br>                                maxid = int(<a href="http://message.id">message.id</a>,16)<br>
                                maxmessage = message<br>                #Removeing all the garbage from the message to find the command<br>                #TODO find a neater way of parsing message<br>                ogsssplit = maxmessage.source.split("Ogss")<br>
                spansplit = ogsssplit[len(ogsssplit)-1].split("</SPAN>")<br>                command = spansplit[0]<br>                command = command.split()<br>                #If the id of the most recent message does not already exist in <br>
                #the log file, run the command<br>                if execd.count(int(<a href="http://maxmessage.id">maxmessage.id</a>,16))==0:            <br>                    print "Processing Command"<br>                    cresult = Popen(command,stdout=PIPE)<br>
                    body = cresult.stdout.read()<br>                    tosend = libgmail.GmailComposedMessage(cell_email,"STDOUT","\n"+body)<br>                    print "Seding back results"<br>
                    account.sendMessage(tosend)<br>                    print "Logging..."<br>                    execd.append(int(<a href="http://maxmessage.id">maxmessage.id</a>,16))<br>                    towrite = str(int(<a href="http://maxmessage.id">maxmessage.id</a>,16))+"~ "<br>
                    for arg in command:<br>                        towrite += arg+" "<br>                    w.write(towrite+"\n")<br>                    print "Listening for commands"<br>            #TODO add ability to choose sleep time    <br>
            time.sleep(2)<br>        except (KeyboardInterrupt, SystemExit):    <br>            w.close()<br>            print "Exiting..."<br>            exit()<br>if __name__ == "__main__":<br>    import os,time,sys,libgmail<br>
    from subprocess import Popen,PIPE<br>    main(sys.argv)<br>