From e02153b7b6aaabec8593652b8d401b23d4332e03 Mon Sep 17 00:00:00 2001 From: Skillet Date: Tue, 1 Aug 2023 21:46:41 -0400 Subject: [PATCH] ability to use remote admins --- autowl/Cogs/Group.py | 20 ++++++++++++++ poetry.lock | 66 ++++++++++++++++++++++++++++++++++---------- pyproject.toml | 1 + simpleFileServer.py | 21 +++++++++++++- 4 files changed, 92 insertions(+), 16 deletions(-) diff --git a/autowl/Cogs/Group.py b/autowl/Cogs/Group.py index 0c271db..d7d99ec 100644 --- a/autowl/Cogs/Group.py +++ b/autowl/Cogs/Group.py @@ -1,3 +1,5 @@ +import os.path + import discord import random import logging @@ -64,6 +66,24 @@ class Group(commands.Cog, name="group"): ): await self.baseperm(interaction, role, perms) + @app_commands.command() + async def addremote( + self, + interaction: discord.Interaction, + shortname: str, + remoteURL: str, + perms: str = 'whitelist' + ): + if os.path.exists(f"wlgrps/{shortname}.cfg"): + await interaction.response.send_message("Already exists!") + return + else: + outfile = open(f"./wlgrps/{shortname}.cfg", "w") + outfile.write(f"remotelist={remoteURL}\n") + outfile.write(f"permissions={perms}\n") + outfile.close() + await interaction.response.send_message("created!") + @app_commands.command() async def remove( self, diff --git a/poetry.lock b/poetry.lock index dac1674..7baa16a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,10 +1,9 @@ -# This file is automatically @generated by Poetry 1.4.0 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.5.0 and should not be changed by hand. [[package]] name = "aiohttp" version = "3.8.3" description = "Async http client/server framework (asyncio)" -category = "main" optional = false python-versions = ">=3.6" files = [ @@ -113,7 +112,6 @@ speedups = ["Brotli", "aiodns", "cchardet"] name = "aiosignal" version = "1.3.1" description = "aiosignal: a list of registered asynchronous callbacks" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -128,7 +126,6 @@ frozenlist = ">=1.1.0" name = "async-timeout" version = "4.0.2" description = "Timeout context manager for asyncio programs" -category = "main" optional = false python-versions = ">=3.6" files = [ @@ -140,7 +137,6 @@ files = [ name = "attrs" version = "22.2.0" description = "Classes Without Boilerplate" -category = "main" optional = false python-versions = ">=3.6" files = [ @@ -155,11 +151,21 @@ docs = ["furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib- tests = ["attrs[tests-no-zope]", "zope.interface"] tests-no-zope = ["cloudpickle", "cloudpickle", "hypothesis", "hypothesis", "mypy (>=0.971,<0.990)", "mypy (>=0.971,<0.990)", "pympler", "pympler", "pytest (>=4.3.0)", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-mypy-plugins", "pytest-xdist[psutil]", "pytest-xdist[psutil]"] +[[package]] +name = "certifi" +version = "2023.7.22" +description = "Python package for providing Mozilla's CA Bundle." +optional = false +python-versions = ">=3.6" +files = [ + {file = "certifi-2023.7.22-py3-none-any.whl", hash = "sha256:92d6037539857d8206b8f6ae472e8b77db8058fec5937a1ef3f54304089edbb9"}, + {file = "certifi-2023.7.22.tar.gz", hash = "sha256:539cc1d13202e33ca466e88b2807e29f4c13049d6d87031a3c110744495cb082"}, +] + [[package]] name = "charset-normalizer" version = "2.1.1" description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." -category = "main" optional = false python-versions = ">=3.6.0" files = [ @@ -174,7 +180,6 @@ unicode-backport = ["unicodedata2"] name = "discord-py" version = "2.1.0" description = "A Python wrapper for the Discord API" -category = "main" optional = false python-versions = ">=3.8.0" files = [ @@ -195,7 +200,6 @@ voice = ["PyNaCl (>=1.3.0,<1.6)"] name = "frozenlist" version = "1.3.3" description = "A list-like structure which implements collections.abc.MutableSequence" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -279,7 +283,6 @@ files = [ name = "idna" version = "3.4" description = "Internationalized Domain Names in Applications (IDNA)" -category = "main" optional = false python-versions = ">=3.5" files = [ @@ -291,7 +294,6 @@ files = [ name = "jsonpickle" version = "3.0.1" description = "Python library for serializing any arbitrary object graph into JSON" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -308,7 +310,6 @@ testing-libs = ["simplejson", "ujson"] name = "multidict" version = "6.0.4" description = "multidict implementation" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -392,7 +393,6 @@ files = [ name = "mysql-connector-python" version = "8.0.32" description = "MySQL driver written in Python" -category = "main" optional = false python-versions = "*" files = [ @@ -435,7 +435,6 @@ gssapi = ["gssapi (>=1.6.9,<=1.8.2)"] name = "protobuf" version = "3.20.3" description = "Protocol Buffers" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -463,11 +462,48 @@ files = [ {file = "protobuf-3.20.3.tar.gz", hash = "sha256:2e3427429c9cffebf259491be0af70189607f365c2f41c7c3764af6f337105f2"}, ] +[[package]] +name = "requests" +version = "2.31.0" +description = "Python HTTP for Humans." +optional = false +python-versions = ">=3.7" +files = [ + {file = "requests-2.31.0-py3-none-any.whl", hash = "sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f"}, + {file = "requests-2.31.0.tar.gz", hash = "sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1"}, +] + +[package.dependencies] +certifi = ">=2017.4.17" +charset-normalizer = ">=2,<4" +idna = ">=2.5,<4" +urllib3 = ">=1.21.1,<3" + +[package.extras] +socks = ["PySocks (>=1.5.6,!=1.5.7)"] +use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] + +[[package]] +name = "urllib3" +version = "2.0.4" +description = "HTTP library with thread-safe connection pooling, file post, and more." +optional = false +python-versions = ">=3.7" +files = [ + {file = "urllib3-2.0.4-py3-none-any.whl", hash = "sha256:de7df1803967d2c2a98e4b11bb7d6bd9210474c46e8a0401514e3a42a75ebde4"}, + {file = "urllib3-2.0.4.tar.gz", hash = "sha256:8d22f86aae8ef5e410d4f539fde9ce6b2113a001bb4d189e0aed70642d602b11"}, +] + +[package.extras] +brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)"] +secure = ["certifi", "cryptography (>=1.9)", "idna (>=2.0.0)", "pyopenssl (>=17.1.0)", "urllib3-secure-extra"] +socks = ["pysocks (>=1.5.6,!=1.5.7,<2.0)"] +zstd = ["zstandard (>=0.18.0)"] + [[package]] name = "yarl" version = "1.8.2" description = "Yet another URL library" -category = "main" optional = false python-versions = ">=3.7" files = [ @@ -554,4 +590,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "657a426f0ae90149e993e58c29cf306637e5be673688d0234db90915e46e5d18" +content-hash = "b229771a7e4a57a69fcf1af09b6cabcb918748e74eb4ff4922bbd943e73b15ea" diff --git a/pyproject.toml b/pyproject.toml index b37c38c..72b28d9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,7 @@ python = "^3.10" "discord.py" = "^2.1.0" jsonpickle = "^3.0.1" mysql-connector-python = "^8.0.32" +requests = "^2.31.0" [build-system] diff --git a/simpleFileServer.py b/simpleFileServer.py index bf778ec..10d1c91 100644 --- a/simpleFileServer.py +++ b/simpleFileServer.py @@ -1,10 +1,15 @@ import http.server import os +import re import socketserver +import traceback +import urllib.request from urllib.parse import urlparse from urllib.parse import parse_qs from sys import stderr +import requests + PORT = 8000 @@ -26,10 +31,24 @@ class serveRA(http.server.SimpleHTTPRequestHandler): return try: file = open(grpfile, 'rb') - self.copyfile(file, self.wfile) + firstline = file.readline().decode('utf-8') + if firstline.startswith('remotelist='): + remote = firstline.split('=')[1].strip() + response = requests.get(remote, headers={'Accept': 'text/html,*/*'}) + responsetext = response.text + config = file.read().decode('utf-8') + confgrps = re.findall(r"^permissions/(.+)=(.+)", config, flags=re.M) + baseperm = re.match(r"^permissions=(.+)", config, flags=re.M) + responsetext = re.sub(r"^Group=(.+):(.+)", fr'Group=\1:{baseperm[0]}', responsetext, flags=re.M) + for congrp in confgrps: + responsetext = re.sub(rf"^Group=({congrp[0]}):(.+)", rf"Group=\1:{congrp[1]}", responsetext, flags=re.M) + self.wfile.write(responsetext.encode('utf-8')) + else: + self.copyfile(file, self.wfile) file.close() except: print('failed to open file!', file=stderr) + print(traceback.format_exc()) return