django-ejabberd-bridge icon indicating copy to clipboard operation
django-ejabberd-bridge copied to clipboard

the django-command and python-command behave differently.

Open hackrole opened this issue 10 years ago • 0 comments

I have use you script on my django project. and conf the ejabberd.cfg as:: {auth_method, external}. {extauth_program, "python /home/daipeng/stime_project/stime/manage.py ejabberd_auth"}.

then ejabberd.log keep output: C(<0.1126.0>:extauth:146) : extauth script has exitted abruptly with reason 'normal' but the django logging log nothing at all. And I try to run python manage.py ejabberd_auth. it seems works fine.

so I try to write a python script like below::

import sys
import logging
\#import hashlib
import struct
\#from sell_time import models


sys.stderr = open("/var/log/ejabberd/extauth_err4.log", "a")
logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s %(levelname)s %(message)s",
    filename="/var/log/ejabberd/extauth4.log",
    filemode="a"
)
logging.info("extauth script started, waiting for ejabberd requests")


def from_ejabberd():
     input_length = sys.stdin.read(2)
     logging.info("Bytes read: %s" % len(input_length))
     logging.info("Input lenght: %s" % input_length)
     (size,) = struct.unpack('>h', input_length)
     return sys.stdin.read(size).split(':')


def to_ejabberd(success):
    answer = 0
    if success:
        answer = 1

    token = struct.pack('>hh', 2, answer)
    sys.stdout.write(token)
    sys.stdout.flush()


def auth(mobile, server, password):
    return True


def isuser(mobile, server):
    return True


def setpass(mobile, server, password):
    return False


while True:
    data = from_ejabberd()
    success = False
    logging.info(data)
    if data[0] == "auth": 
        success = auth(data[1], data[2], data[3])
    elif data[0] == "isuser":
        success = isuser(data[1], data[2])
    elif data[0] == "setpass":
        success = setpass(data[1], data[2], data[3])

    msg = "data: %s with result: %s" % (data, success)
    logging.info(msg)
    to_ejabberd(success)

the config the ejabberd like below:: {auth_method, external}. {extauth_program, "python /home/daipeng/stime_project/stime/ejabberd_auth.py"}.

it works fine.

So I would like to know what happens, why the django just can't run and can't log anything.

hackrole avatar Sep 11 '14 02:09 hackrole