m4pl1mp/plugins/turl_plugin.py

63 lines
2.3 KiB
Python
Raw Permalink Normal View History

2022-04-04 17:51:05 +00:00
# -*- coding: utf-8 -*-
from irc3.plugins.command import command
from urllib.parse import urlparse
import irc3
import random
import string
import os
############################################################################################
2022-04-04 18:54:11 +00:00
TURLPATH='/Users/dr1p/m4pl1mp/d/'
RSYNC=f"rsync -az {TURLPATH}/* dr1p@ansibomb.com:/var/www/html/d"
2022-04-04 17:51:05 +00:00
############################################################################################
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]
2022-04-04 18:54:11 +00:00
while os.path.isfile(f'{TURLPATH}{S}/index.html'):
2022-04-04 17:51:05 +00:00
S=list(string.ascii_letters+string.digits)
random.shuffle(S); S=''.join(S)[:5]
2022-04-04 18:54:11 +00:00
os.mkdir(f'{TURLPATH}{S}')
f=open(f'{TURLPATH}{S}/index.html','w')
2022-04-04 17:51:05 +00:00
_HTML=HTML.format(url,url)
for _ in _HTML:
f.write(_)
f.close()
return f'{S}'
########################################################################################
def turl_validate(self,url):
result=urlparse(url)
2022-04-04 17:56:36 +00:00
validation=all([result.scheme,result.netloc,result.path])
2022-04-04 17:51:05 +00:00
if validation:
return 1
return 0
########################################################################################
@command(permission='view')
def turl(self,mask,target,args):
"""turl
%%turl <message>...
"""
url=''.join(args['<message>'])
2022-04-04 18:54:11 +00:00
if self.turl_validate(url):
2022-04-04 17:51:05 +00:00
url=self.turl_generate(url)
2022-04-04 18:54:11 +00:00
os.system(f'RSYNC')
2022-04-04 17:51:05 +00:00
msg=f'{mask.nick}: https://ansibomb.com/d/{url}'
self.bot.privmsg(target,self.bot.emo(msg))
############################################################################################