~kline/torgateway

ref: 9e9275834728a965eae36cee4579dbdc108dc018 torgateway/freenode.py -rw-r--r-- 1.3 KiB
9e927583Gareth Pulham Add registration via XML-RPC 1 year, 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import xmlrpc.client

class RegistrationError(RuntimeError):
    pass

# ValueError returns with a reason, and permits token/username reuse
# RegistrationError returns a reason but requires staff intervention (stuck account)
def register_user(username, password, certfp):
    services = xmlrpc.client.ServerProxy("http://localhost:8192/xmlrpc")

    fakemail = "{}@tor.fake.mail.freenode.net".format(username)
    feedback = services.atheme.command("*", "*", "::1337", "nickserv", "register", username, password, fakemail)
    if "is now registered" not in feedback:
        raise ValueError(feedback)

    try:
        cookie = services.atheme.login(username, password)
    except xmlrpc.client.Fault as e:
        raise RegistrationError(
            "Unable to update account {}, fault {}. Please report this error and username to staff".format(
                username, e.faultCode
            )
        )
    
    feedback = services.atheme.command(cookie, username, "::1337", "nickserv", "cert", "add", certfp)
    if "Added fingerprint" not in feedback:
        token = services.atheme.command(cookie, username, "::1337", "nickserv", "drop", username).split()[-1]
        services.atheme.command(cookie, username, "::1337", "nickserv", "drop", username, token)
        raise ValueError(feedback)