summaryrefslogtreecommitdiff
path: root/cgi
diff options
context:
space:
mode:
Diffstat (limited to 'cgi')
-rwxr-xr-xcgi/gb_newentry.cgi31
1 files changed, 16 insertions, 15 deletions
diff --git a/cgi/gb_newentry.cgi b/cgi/gb_newentry.cgi
index 9e8c4dd..14cfb91 100755
--- a/cgi/gb_newentry.cgi
+++ b/cgi/gb_newentry.cgi
@@ -1,14 +1,15 @@
#!/usr/bin/python3
import os,sys,html,json,datetime
-import urllib.parse,urllib.request
+import urllib.parse
+import requests
-if os.environ['SERVER_NAME']!='chrisoft.org':
- import socks,socket
- socks.set_default_proxy(socks.SOCKS5,"127.0.0.1",1080)
- socket.socket=socks.socksocket
- def getaddrinfo(*args):
- return [(socket.AF_INET,socket.SOCK_STREAM,6,'',(args[0],args[1]))]
- socket.getaddrinfo=getaddrinfo
+#if os.environ['SERVER_NAME']!='chrisoft.org':
+# import socks,socket
+# socks.set_default_proxy(socks.SOCKS5,"127.0.0.1",1080)
+# socket.socket=socks.socksocket
+# def getaddrinfo(*args):
+# return [(socket.AF_INET,socket.SOCK_STREAM,6,'',(args[0],args[1]))]
+# socket.getaddrinfo=getaddrinfo
def fail(x=None):
print('Status: 400 Bad Request',end='\r\n')
@@ -38,13 +39,11 @@ if len(mname)+len(mcontent)>16384:
fail(x=':)')
try:
- with open(os.environ['DOCUMENT_ROOT']+'/grecaptcha_key',mode='r',encoding='utf-8') as gr_secret_f:
- gr_secret=gr_secret_f.read()
- req={'secret':gr_secret,'response':f['gr_ret'],'remoteip':os.environ['REMOTE_ADDR']}
- r=urllib.request.Request('https://www.google.com/recaptcha/api/siteverify',data=urllib.parse.urlencode(req).encode('utf-8'),method='POST')
- rr=urllib.request.urlopen(r,timeout=5)
- rsp=json.loads(str(rr.read(),'utf-8'))
- if not rsp['success'] or rsp['score']<0.6:
+ with open(os.environ['DOCUMENT_ROOT']+'/abuseipdb_key',mode='r',encoding='utf-8') as apikey_f:
+ apikey=apikey_f.read()
+ rsp=requests.get('https://api.abuseipdb.com/api/v2/check',params={'ipAddress':urllib.parse.quote(os.environ['REMOTE_ADDR']),'maxAgeInDays':'120','verbose':'','key':apikey.strip()})
+ rspj=rsp.json()['data']
+ if rspj['totalReports']>0:
fail(x=':)')
except Exception as e:
fail(x=e)
@@ -67,3 +66,5 @@ with open(archivp,mode='a',encoding='utf-8') as f:
f.write(f'author: {mname}\n')
f.write(f'time: {mtime}\n')
f.write(f'IP: {os.environ["REMOTE_ADDR"]}\n\n')
+
+# vim: set noexpandtab :