-
-
Save KoolKeith/87cbc670bcc84fb8e33bd46b7c1e62de to your computer and use it in GitHub Desktop.
Join Python receiver thingy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
port: 1818 | |
commands: | |
# Join Push Text : Command to run | |
"eg=:=shutdown": "systemctl poweroff" | |
#fallback-cmd: "./fallbacktest.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3.6 | |
""" | |
Allows you to run commands on Join pushes | |
-- | |
Changelog: | |
1.1.0: | |
- Fallback commands | |
- Pass join pushes to commands as "JOIN_PUSH" env. value | |
(accessible as "$JOIN_PUSH" on (Ba)sh, "%JOIN_PUSH%" on cmd (i assume)) | |
1.0.0: | |
- Initial release | |
-- | |
Copyright 2017+ Admicos | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | |
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the | |
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit | |
persons to whom the Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the | |
Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | |
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | |
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | |
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
""" | |
from urllib import parse | |
import socket | |
import yaml | |
import re | |
import os | |
def extract_message(raw: str): | |
"""Extract message from Join's request""" | |
return parse.unquote(re.search(r".* ?message=(.*) .*", raw.split("\r\n")[0]).group(1)) | |
def main(cfg: dict): | |
print("..--== By Admicos ==--..") | |
print("This requires a running Chrome/ium instance with the Join extension.") | |
print(f"Don't forget to set the 'EventGhost' port to {cfg['port']}") | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind(("127.0.0.1", cfg["port"])) | |
s.listen(5) | |
print("Started listening") | |
while True: | |
c, addr = s.accept() | |
d = c.recv(512).decode("utf-8") | |
msg = extract_message(d) | |
print(f"{addr}: {msg}") | |
cmd = cfg["commands"].get(msg) | |
fallback_cmd = cfg.get("fallback-cmd") | |
if cmd: | |
print(f" - Running '{cmd}'") | |
os.environ["JOIN_PUSH"] = msg | |
os.system(cmd) | |
elif fallback_cmd: | |
print(f" - Running '{fallback_cmd}'") | |
os.environ["JOIN_PUSH"] = msg | |
os.system(fallback_cmd) | |
else: | |
print(f" - No command for '{msg}', ignoring") | |
c.close() | |
if __name__ == '__main__': | |
with open("config.yml") as f: | |
config = yaml.load(f) | |
main(config) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment