Last active
January 28, 2019 13:14
-
-
Save codekidX/37455098e70f6d71a9cbbea3871f5fa1 to your computer and use it in GitHub Desktop.
Example of external authentication script for ejabberd server
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/env python | |
import sys | |
import logging | |
from struct import pack, unpack | |
logging.basicConfig(level=logging.INFO, | |
format='%(asctime)s %(levelname)s %(message)s', | |
filename='/var/log/ejabberd/extauth.log', | |
filemode='a') | |
def input_from_ejabberd(): | |
iplen = sys.stdin.read(2) | |
(count,) = unpack('>h', iplen) | |
input = sys.stdin.read(iplen) | |
logging.info("Incoming input from ejabberd: %s", input) | |
return input | |
def done(is_authenticated=False): | |
result = 0 | |
if is_authenticated: | |
result = 1 | |
op = pack('>hh', 2, result) | |
sys.stdout.write(op) | |
sys.stdout.flush() | |
while True: | |
user_pass = input_from_ejabberd() | |
if len(user_pass) > 1: | |
done(True) | |
else: | |
done(False) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment