63 lines
2.3 KiB
Python
63 lines
2.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
from irc3.plugins.command import command
|
|
from urllib.parse import urlparse
|
|
import irc3
|
|
import random
|
|
import string
|
|
import os
|
|
############################################################################################
|
|
TURLPATH='/Users/dr1p/m4pl1mp/d/'
|
|
RSYNC=f"rsync -az {TURLPATH}/* dr1p@ansibomb.com:/var/www/html/d"
|
|
############################################################################################
|
|
HTML="""<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Redirect</title>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="Refresh" content="0; url='{}'"/>
|
|
</head>
|
|
<body>
|
|
<p>You are being redirected to <a href="{}">some interesting page</a>.</p>
|
|
<p>If you are not redirected after a few seconds, please click on the link above!</p>
|
|
</body>
|
|
</html>"""
|
|
############################################################################################
|
|
@irc3.plugin
|
|
class Plugin:
|
|
def __init__(self, bot):
|
|
self.bot = bot
|
|
########################################################################################
|
|
def turl_generate(self,url):
|
|
S=list(string.ascii_letters+string.digits)
|
|
random.shuffle(S); S=''.join(S)[:5]
|
|
while os.path.isfile(f'{TURLPATH}{S}/index.html'):
|
|
S=list(string.ascii_letters+string.digits)
|
|
random.shuffle(S); S=''.join(S)[:5]
|
|
os.mkdir(f'{TURLPATH}{S}')
|
|
f=open(f'{TURLPATH}{S}/index.html','w')
|
|
_HTML=HTML.format(url,url)
|
|
for _ in _HTML:
|
|
f.write(_)
|
|
f.close()
|
|
return f'{S}'
|
|
########################################################################################
|
|
def turl_validate(self,url):
|
|
result=urlparse(url)
|
|
validation=all([result.scheme,result.netloc,result.path])
|
|
if validation:
|
|
return 1
|
|
return 0
|
|
########################################################################################
|
|
@command(permission='view')
|
|
def turl(self,mask,target,args):
|
|
"""turl
|
|
%%turl <message>...
|
|
"""
|
|
url=''.join(args['<message>'])
|
|
if self.turl_validate(url):
|
|
url=self.turl_generate(url)
|
|
os.system(f'RSYNC')
|
|
msg=f'{mask.nick}: https://ansibomb.com/d/{url}'
|
|
self.bot.privmsg(target,self.bot.emo(msg))
|
|
############################################################################################
|