Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # remote-order.py Copyrigth 2012 Itxaka Serrano Garcia <itxakaserrano@gmail.com>
- # licensed under the GPL2
- # see the full license at http://www.gnu.org/licenses/gpl-2.0.txt
- from pastebin import PastebinAPI
- from bs4 import BeautifulSoup
- import urllib2, os, logging, datetime
- # logging config
- logging.basicConfig(filename='remote-order.log',level=logging.DEBUG, format='%(levelname)s-%(asctime)s-%(message)s')
- logging.info("Script started")
- # variables to configure
- developer_key = ""
- user_key = ""
- user_login = ""
- user_password = ""
- try:
- x = PastebinAPI()
- # create the user_key. Not sure if we need to create one every X hours or just one works forever.
- if user_key == "":
- user_key = x.generate_user_key(developer_key, user_login, user_password)
- print "Your user key is: ", user_key
- sys.exit(0)
- else:
- continue
- # get the pastes
- data = x.pastes_by_user(developer_key, user_key,10)
- # parse the data to extract
- soup = BeautifulSoup(data)
- pastes = soup.find_all("paste_key")
- # this is needed to get the first paste we made, as we are using it for the commands
- pastes = pastes[len(pastes) - 1]
- # download the raw pastebin
- url = "http://pastebin.com/raw.php?i=" + pastes.text
- cmd = urllib2.urlopen(url)
- cmd = cmd.read()
- # execute and store the output to a file
- os.system(cmd + " > output.txt")
- with open("output.txt","r") as f:
- output = f.read()
- # we paste the output to a new pastebin, private, that expires in 10 minutes
- x.paste(developer_key, output, paste_name = "Result of command " + cmd, \
- api_user_key = user_key, paste_private = "private", paste_format=None, paste_expire_date = "10M")
- # log the finish
- logging.info("Program finished ok")
- except Exception as e:
- logging.critical(e)
- except TypeError as e:
- logging.critical(e)
- finally:
- # remove the output.txt file
- os.remove("output.txt")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement