made some work for pastedb / pastecache..
This commit is contained in:
0
pastedb/pastedb01/services/__init__.py
Normal file
0
pastedb/pastedb01/services/__init__.py
Normal file
BIN
pastedb/pastedb01/services/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
pastedb/pastedb01/services/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
pastedb/pastedb01/services/__pycache__/defau.cpython-310.pyc
Normal file
BIN
pastedb/pastedb01/services/__pycache__/defau.cpython-310.pyc
Normal file
Binary file not shown.
BIN
pastedb/pastedb01/services/__pycache__/dpaste.cpython-310.pyc
Normal file
BIN
pastedb/pastedb01/services/__pycache__/dpaste.cpython-310.pyc
Normal file
Binary file not shown.
BIN
pastedb/pastedb01/services/__pycache__/opendev.cpython-310.pyc
Normal file
BIN
pastedb/pastedb01/services/__pycache__/opendev.cpython-310.pyc
Normal file
Binary file not shown.
BIN
pastedb/pastedb01/services/__pycache__/paste2.cpython-310.pyc
Normal file
BIN
pastedb/pastedb01/services/__pycache__/paste2.cpython-310.pyc
Normal file
Binary file not shown.
BIN
pastedb/pastedb01/services/__pycache__/pastie.cpython-310.pyc
Normal file
BIN
pastedb/pastedb01/services/__pycache__/pastie.cpython-310.pyc
Normal file
Binary file not shown.
BIN
pastedb/pastedb01/services/__pycache__/rentry.cpython-310.pyc
Normal file
BIN
pastedb/pastedb01/services/__pycache__/rentry.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
pastedb/pastedb01/services/__pycache__/sprunge.cpython-310.pyc
Normal file
BIN
pastedb/pastedb01/services/__pycache__/sprunge.cpython-310.pyc
Normal file
Binary file not shown.
BIN
pastedb/pastedb01/services/__pycache__/termbin.cpython-310.pyc
Normal file
BIN
pastedb/pastedb01/services/__pycache__/termbin.cpython-310.pyc
Normal file
Binary file not shown.
26
pastedb/pastedb01/services/defau.py
Normal file
26
pastedb/pastedb01/services/defau.py
Normal file
@ -0,0 +1,26 @@
|
||||
import requests
|
||||
import json
|
||||
import hashlib
|
||||
|
||||
def serviceTag():
|
||||
return 'p.defau.lt'
|
||||
|
||||
def upload(data):
|
||||
json_data = json.dumps(data)
|
||||
md5sum = hashlib.md5(json_data.encode('utf-8')).hexdigest()
|
||||
|
||||
url = 'https://p.defau.lt/submit.php'
|
||||
response = requests.post(url, data={'code': json_data})
|
||||
|
||||
if response.status_code == 200:
|
||||
key = response.url
|
||||
name = 'defau_' + md5sum[:5]
|
||||
return {'name': name, 'service': 'p.defau.lt', 'key': key, 'md5sum': md5sum}
|
||||
else:
|
||||
return None
|
||||
|
||||
def get(trace):
|
||||
url = trace[key]
|
||||
response = requests.request.get(url)
|
||||
return response.content
|
||||
|
32
pastedb/pastedb01/services/dpaste.py
Normal file
32
pastedb/pastedb01/services/dpaste.py
Normal file
@ -0,0 +1,32 @@
|
||||
import hashlib
|
||||
import json
|
||||
import requests
|
||||
|
||||
def upload(data):
|
||||
try:
|
||||
content = json.dumps(data)
|
||||
syntax = 'json'
|
||||
expiry_days = ''
|
||||
|
||||
r = requests.post('https://dpaste.com/api/v2/',
|
||||
data={'content': content,
|
||||
'syntax': syntax,
|
||||
'expiry_days': expiry_days},
|
||||
headers={'User-Agent': 'My Python Project'})
|
||||
|
||||
if r.status_code == 201:
|
||||
dpaste_url = r.headers['Location']
|
||||
#print(f'JSON object uploaded to dpaste.com: {dpaste_url}')
|
||||
md5sum = hashlib.md5(content.encode('utf-8')).hexdigest()
|
||||
|
||||
return {
|
||||
'service': 'dpaste',
|
||||
'key': dpaste_url,
|
||||
'md5sum': md5sum,
|
||||
'name': 'dpaste_' + dpaste_url.rsplit('/', 1)[-1]
|
||||
}
|
||||
else:
|
||||
return None
|
||||
except requests.exceptions.RequestException:
|
||||
return None
|
||||
|
70
pastedb/pastedb01/services/old_rentry.py
Normal file
70
pastedb/pastedb01/services/old_rentry.py
Normal file
@ -0,0 +1,70 @@
|
||||
import json
|
||||
import hashlib
|
||||
import http.cookiejar
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
from http.cookies import SimpleCookie
|
||||
|
||||
_headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
|
||||
|
||||
class UrllibClient:
|
||||
"""Simple HTTP Session Client, keeps cookies."""
|
||||
|
||||
def __init__(self):
|
||||
self.cookie_jar = http.cookiejar.CookieJar()
|
||||
self.opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(self.cookie_jar))
|
||||
urllib.request.install_opener(self.opener)
|
||||
|
||||
def get(self, url, headers={}):
|
||||
request = urllib.request.Request(url, headers=headers)
|
||||
return self._request(request)
|
||||
|
||||
def post(self, url, data=None, headers={}):
|
||||
postdata = urllib.parse.urlencode(data).encode()
|
||||
request = urllib.request.Request(url, postdata, headers)
|
||||
return self._request(request)
|
||||
|
||||
def _request(self, request):
|
||||
response = self.opener.open(request)
|
||||
response.status_code = response.getcode()
|
||||
response.data = response.read().decode('utf-8')
|
||||
return response
|
||||
|
||||
|
||||
def json_loads(string):
|
||||
try:
|
||||
return json.loads(string)
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
def upload(data):
|
||||
client, cookie = UrllibClient(), SimpleCookie()
|
||||
|
||||
cookie.load(vars(client.get('https://rentry.co'))['headers']['Set-Cookie'])
|
||||
csrftoken = cookie['csrftoken'].value
|
||||
|
||||
json_data = json.dumps(data)
|
||||
md5sum = hashlib.md5(json_data.encode('utf-8')).hexdigest()
|
||||
|
||||
payload = {
|
||||
'csrfmiddlewaretoken': csrftoken,
|
||||
'url': md5sum,
|
||||
'edit_code': '',
|
||||
'text': json_data
|
||||
}
|
||||
|
||||
response = client.post('https://rentry.co/api/new', payload, headers=_headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
json_response = json_loads(response.data)
|
||||
return {
|
||||
"service": "rentry",
|
||||
"name": json_response["slug"],
|
||||
"key": f"https://rentry.co/{json_response['slug']}",
|
||||
"md5sum": md5sum
|
||||
}
|
||||
else:
|
||||
return None
|
||||
|
40
pastedb/pastedb01/services/opendev.py
Executable file
40
pastedb/pastedb01/services/opendev.py
Executable file
@ -0,0 +1,40 @@
|
||||
import requests
|
||||
import json
|
||||
import hashlib
|
||||
|
||||
url = 'https://paste.opendev.org/json/'
|
||||
|
||||
def upload(data):
|
||||
try:
|
||||
content = json.dumps(data)
|
||||
|
||||
# create JSON payload for new paste
|
||||
payload = {
|
||||
'language': 'text',
|
||||
'code': content,
|
||||
'private': False
|
||||
#'expire': '1day'
|
||||
}
|
||||
|
||||
# send request to create new paste
|
||||
response = requests.post(url + '?method=pastes.newPaste', json=payload)
|
||||
|
||||
status = response.status_code
|
||||
paste_id = response.json()['data']
|
||||
|
||||
if status == 200:
|
||||
#print(f'JSON object uploaded to dpaste.com: {dpaste_url}')
|
||||
md5sum = hashlib.md5(content.encode('utf-8')).hexdigest()
|
||||
|
||||
return {
|
||||
'service': "opendev",
|
||||
'key': url,
|
||||
'md5sum': md5sum,
|
||||
'name': 'opendev_' + paste_id + '_' + md5sum[:5]
|
||||
}
|
||||
else:
|
||||
return None
|
||||
except requests.exceptions.RequestException:
|
||||
return None
|
||||
# we can get the paste back by:
|
||||
## $ > curl -d '{"paste_id":819463}' -H 'Content-Type: application/json' https://paste.opendev.org/json/?method=pastes.getPaste |jq .data.code
|
20
pastedb/pastedb01/services/paste2.py
Normal file
20
pastedb/pastedb01/services/paste2.py
Normal file
@ -0,0 +1,20 @@
|
||||
import requests
|
||||
|
||||
def upload(data):
|
||||
url = 'https://paste2.org/'
|
||||
|
||||
response = requests.post(url, data={'data': data})
|
||||
response.raise_for_status()
|
||||
|
||||
# Extract the URL of the uploaded paste from the response
|
||||
paste_url = None
|
||||
for line in response.text.splitlines():
|
||||
if line.startswith('<input type="text" id="paste-url" value="'):
|
||||
paste_url = line.split('"')[3]
|
||||
break
|
||||
|
||||
if paste_url is None:
|
||||
raise ValueError('Could not extract paste URL from response')
|
||||
|
||||
return paste_url
|
||||
|
25
pastedb/pastedb01/services/pastie.py
Normal file
25
pastedb/pastedb01/services/pastie.py
Normal file
@ -0,0 +1,25 @@
|
||||
import requests
|
||||
import json
|
||||
import hashlib
|
||||
|
||||
def upload(data):
|
||||
try:
|
||||
json_data = json.dumps(data)
|
||||
md5sum = hashlib.md5(json_data.encode('utf-8')).hexdigest()
|
||||
response = requests.post('https://pastie.io/documents', data=json_data)
|
||||
if response.status_code == 200:
|
||||
key = response.json()['key']
|
||||
pastie_url = f'https://pastie.io/{key}'
|
||||
# print(f'JSON object uploaded to Pastie: {pastie_url}')
|
||||
|
||||
return {
|
||||
"service": "pastie",
|
||||
"name": 'pastie_' + key,
|
||||
"key": pastie_url,
|
||||
"md5sum": md5sum
|
||||
}
|
||||
else:
|
||||
return None
|
||||
except requests.exceptions.RequestException:
|
||||
return None
|
||||
|
16
pastedb/pastedb01/services/rentry.py
Normal file
16
pastedb/pastedb01/services/rentry.py
Normal file
@ -0,0 +1,16 @@
|
||||
import subprocess
|
||||
import json
|
||||
import hashlib
|
||||
import re
|
||||
|
||||
|
||||
def upload(data):
|
||||
md5sum = hashlib.md5(json.dumps(data).encode('utf-8')).hexdigest()
|
||||
command = ['./external/rentry', 'new', json.dumps(data)]
|
||||
output = subprocess.check_output(command, universal_newlines=True)
|
||||
#print(output)
|
||||
lines = output.strip().split('\n')
|
||||
url = re.search("(?P<url>https?://[^\s]+)", lines[0]).group("url")
|
||||
edit_code = lines[1].split(':')[-1].strip()
|
||||
return {'name': 'rentry_' + edit_code, 'service': 'Rentry', 'key': url, 'md5sum': md5sum}
|
||||
|
40
pastedb/pastedb01/services/sprunge.py
Normal file
40
pastedb/pastedb01/services/sprunge.py
Normal file
@ -0,0 +1,40 @@
|
||||
import requests
|
||||
import json
|
||||
import hashlib
|
||||
import re
|
||||
|
||||
url = 'http://sprunge.us'
|
||||
|
||||
def upload(data):
|
||||
try:
|
||||
json_data = json.dumps(data)
|
||||
md5sum = hashlib.md5(json_data.encode('utf-8')).hexdigest()
|
||||
|
||||
# Send the HTTP POST request to the Sprunge API
|
||||
response = requests.post(url, data={'sprunge': json_data})
|
||||
if response.status_code == 200:
|
||||
|
||||
# Get the URL of the uploaded text from the response body
|
||||
sprunge_url = response.text.strip()
|
||||
|
||||
#print('Uploaded to:', sprunge_url)
|
||||
|
||||
# Use a regular expression to extract the random ID from the URL
|
||||
match = re.match(r'^http://sprunge\.us/(\w+)$', sprunge_url)
|
||||
if match:
|
||||
random_id = match.group(1)
|
||||
#print('Random ID:', random_id)
|
||||
key = "sprunge_" + random_id + '_' + md5sum[:5]
|
||||
else:
|
||||
print('Invalid Sprunge URL:', sprunge_url)
|
||||
|
||||
return {
|
||||
"service": "sprunge",
|
||||
"name": key,
|
||||
"key": sprunge_url,
|
||||
"md5sum": md5sum
|
||||
}
|
||||
else:
|
||||
return None
|
||||
except requests.exceptions.RequestException:
|
||||
return None
|
26
pastedb/pastedb01/services/termbin.py
Normal file
26
pastedb/pastedb01/services/termbin.py
Normal file
@ -0,0 +1,26 @@
|
||||
import subprocess
|
||||
import hashlib
|
||||
import time
|
||||
import random
|
||||
import string
|
||||
|
||||
def generate_name():
|
||||
"""Generate a random name for the paste"""
|
||||
ts = int(time.time())
|
||||
rand_str = ''.join(random.choices(string.ascii_lowercase, k=5))
|
||||
name = f"termbin-{ts}-{rand_str}"
|
||||
return name
|
||||
|
||||
def upload(data):
|
||||
"""Upload the data to termbin.com"""
|
||||
name = generate_name()
|
||||
try:
|
||||
cmd = f"echo '{data}' | nc termbin.com 9999"
|
||||
response = subprocess.check_output(cmd, shell=True, timeout=5).decode()
|
||||
url = f"https://termbin.com/{name}"
|
||||
md5sum = hashlib.md5(data.encode('utf-8')).hexdigest()
|
||||
return {'service': 'termbin', 'key': url, 'md5sum': md5sum}
|
||||
except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e:
|
||||
print(f"Upload failed with error: {e}")
|
||||
return None
|
||||
|
Reference in New Issue
Block a user