Guest User

sashi

a guest
Jan 3rd, 2008
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. # Writen by Stephane Graber <[email protected]>
  4. # Last modification : Sat Dec 02 23:24:40 CET 2006
  5.  
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19.  
  20. # Modified by Sashi:
  21. # Edited default pastebin to .org archlinux's pastebin
  22. # Modified default pastebin as ArchLinux's pastebin
  23. # Added pastebin.com
  24. # Added dpaste.com
  25. # Removed stgraber.org's pastebin as it is not working
  26.  
  27. import urllib, os, sys, re
  28. defaultPB="http://pastebin.archlinux.org" #Default pastebin
  29. version="0.7.1" #Version number to show in the usage
  30.  
  31. #Return the parameters depending of the pastebin used
  32. def getParameters(website,content,user,version):
  33. "Return the parameters array for the selected pastebin"
  34. params={}
  35.  
  36. if re.search("http://pastebin.archlinux.org", website):
  37. params['poster']=user
  38. params['code2']=content
  39. params['format']="text" #The format, for syntax hilighting
  40. params['homosapien']="1"
  41. params['paste']="Send"
  42. params['remember']="0" #Do you want a cookie ?
  43. params['expiry']="f" #The expiration, f = forever
  44. params['regexp']="None"
  45. elif website == "http://pastebin.ca":
  46. params['name']=user
  47. params['content']=content
  48. params['type']="1" #The expiration, 1 = raw
  49. params['save']="0" #Do you want a cookie ?
  50. params['s']="Submit Post"
  51. params['regexp']='">http://pastebin.ca/(.*)</a></p><p>'
  52. elif re.search("http://.*\.pastebin\.com", website):
  53. params['poster']=user
  54. params['code2']=content
  55. params['parent_pid']="" #For reply, "" means homepage (new thread)
  56. params['format']="text" #The format, for syntax hilighting
  57. params['paste']="Send"
  58. params['remember']="0" #Do you want a cookie ?
  59. params['expiry']="f" #The expiration, f = forever
  60. params['regexp']="None"
  61. elif website == "http://pastebin.com":
  62. params['poster']=user
  63. params['code2']=content
  64. params['parent_pid']="" #For reply, "" means homepage (new thread)
  65. params['format']="text" #The format, for syntax hilighting
  66. params['paste']="Send"
  67. params['remember']="0" #Do you want a cookie ?
  68. params['expiry']="f" #The expiration, f = forever
  69. params['regexp']="None"
  70. elif website == "http://dpaste.com":
  71. params['content']=content
  72. params['language']=""
  73. params['title']="title"
  74. params['poster']=user
  75. params['submit']="Paste it"
  76. params['regexp']="None"
  77. else:
  78. sys.exit("Unknown website, please post a request for this pastebin to be added ("+website+")")
  79.  
  80. return params
  81.  
  82. #Check if a filename is passed as an argument, otherwise show the usages
  83. try:
  84. filename=sys.argv[1]
  85. except:
  86. sys.exit("usage: "+sys.argv[0]+" [filename|-] [URL]\n\nDefault pastebin: "+defaultPB+"\nVersion: "+version)
  87.  
  88. #If - is specified as a filename read from stdin, otherwise load the specified file.
  89. if filename == "-":
  90. content=sys.stdin.read()
  91. else:
  92. try:
  93. f=open(filename)
  94. content=f.read()
  95. f.close()
  96. except:
  97. sys.exit("Unable to read from: "+filename)
  98.  
  99. #Check if an extra pastebin is pasted as an argument otherwise use the default Pastebin
  100. try:
  101. website=sys.argv[2]
  102. except:
  103. website=defaultPB
  104.  
  105. user=os.environ.get('USER') #Get the current username from the environment
  106. params=getParameters(website,content,user,version) #Get the parameters array
  107. reLink=params['regexp'] #Extract the regexp
  108. params['regexp']=None #Remove the regexp from what will be sent
  109. params=urllib.urlencode(params) #Convert to a format usable with the HTML POST
  110.  
  111. page=urllib.urlopen(website+'/',params) #Send the informations and be redirected to the final page
  112.  
  113. try:
  114. if reLink != "None": #Check if we have to apply a regexp
  115. print website+"/"+re.split(reLink, page.read())[1] #Print the result of the Regexp
  116. else:
  117. print page.url #Get the final page and show the url
  118. except:
  119. sys.exit("Unable to read or parse the result page, it could be a server timeout or a change server side, try with another pastebin.")
  120.  
Advertisement
Add Comment
Please, Sign In to add comment