Guest User

sashi

a guest
Dec 31st, 2007
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 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. # Modified default pastebin as ArchLinux's pastebin
  22. # Added pastebin.com
  23. # Added dpaste.com
  24. # Removed stgraber.org's pastebin as it is not working
  25.  
  26. import urllib, os, sys, re
  27. defaultPB="http://archlinux.pastebin.com" #Default pastebin
  28. version="0.7" #Version number to show in the usage
  29.  
  30. #Return the parameters depending of the pastebin used
  31. def getParameters(website,content,user,version):
  32. "Return the parameters array for the selected pastebin"
  33. params={}
  34.  
  35. if website == "http://archlinux.pastebin.com":
  36. params['poster']=user
  37. params['code2']=content
  38. params['parent_pid']="" #For reply, "" means homepage (new thread)
  39. params['format']="text" #The format, for syntax hilighting
  40. params['paste']="Send"
  41. params['remember']="0" #Do you want a cookie ?
  42. params['expiry']="f" #The expiration, f = forever
  43. params['regexp']="None"
  44. elif website == "http://pastebin.ca":
  45. params['name']=user
  46. params['content']=content
  47. params['type']="1" #The expiration, 1 = raw
  48. params['save']="0" #Do you want a cookie ?
  49. params['s']="Submit Post"
  50. params['regexp']='">http://pastebin.ca/(.*)</a></p><p>'
  51. elif re.search("http://.*\.pastebin\.com", website):
  52. params['poster']=user
  53. params['code2']=content
  54. params['parent_pid']="" #For reply, "" means homepage (new thread)
  55. params['format']="text" #The format, for syntax hilighting
  56. params['paste']="Send"
  57. params['remember']="0" #Do you want a cookie ?
  58. params['expiry']="f" #The expiration, f = forever
  59. params['regexp']="None"
  60. elif website == "http://pastebin.com":
  61. params['poster']=user
  62. params['code2']=content
  63. params['parent_pid']="" #For reply, "" means homepage (new thread)
  64. params['format']="text" #The format, for syntax hilighting
  65. params['paste']="Send"
  66. params['remember']="0" #Do you want a cookie ?
  67. params['expiry']="f" #The expiration, f = forever
  68. params['regexp']="None"
  69. elif website == "http://dpaste.com":
  70. params['content']=content
  71. params['language']=""
  72. params['title']="title"
  73. params['poster']=user
  74. params['submit']="Paste it"
  75. params['regexp']="None"
  76. else:
  77. sys.exit("Unknown website, please post a request for this pastebin to be added ("+website+")")
  78.  
  79. return params
  80.  
  81. #Check if a filename is passed as an argument, otherwise show the usages
  82. try:
  83. filename=sys.argv[1]
  84. except:
  85. sys.exit("usage: "+sys.argv[0]+" [filename|-] [URL]\n\nDefault pastebin: "+defaultPB+"\nVersion: "+version)
  86.  
  87. #If - is specified as a filename read from stdin, otherwise load the specified file.
  88. if filename == "-":
  89. content=sys.stdin.read()
  90. else:
  91. try:
  92. f=open(filename)
  93. content=f.read()
  94. f.close()
  95. except:
  96. sys.exit("Unable to read from: "+filename)
  97.  
  98. #Check if an extra pastebin is pasted as an argument otherwise use the default Pastebin
  99. try:
  100. website=sys.argv[2]
  101. except:
  102. website=defaultPB
  103.  
  104. user=os.environ.get('USER') #Get the current username from the environment
  105. params=getParameters(website,content,user,version) #Get the parameters array
  106. reLink=params['regexp'] #Extract the regexp
  107. params['regexp']=None #Remove the regexp from what will be sent
  108. params=urllib.urlencode(params) #Convert to a format usable with the HTML POST
  109.  
  110. page=urllib.urlopen(website+'/',params) #Send the informations and be redirected to the final page
  111.  
  112. try:
  113. if reLink != "None": #Check if we have to apply a regexp
  114. print website+"/"+re.split(reLink, page.read())[1] #Print the result of the Regexp
  115. else:
  116. print page.url #Get the final page and show the url
  117. except:
  118. 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.")
  119.  
Add Comment
Please, Sign In to add comment