Software / code / prosody-modules
Annotate
mod_auth_external_insecure/examples/python/prosody-auth-example.py @ 6055:23c4c61a1068
mod_muc_gateway_optimize: New module to optimize muc presence to remote gateways
Some gateways are happy to receive presence for each participant
in MUCs that they are in only once, to any one of their joined JIDs.
| author | Stephen Paul Weber <singpolyma@singpolyma.net> |
|---|---|
| date | Sun, 17 Nov 2024 22:32:52 -0500 |
| parent | 3884:f84ede3e9e3b |
| rev | line source |
|---|---|
|
1194
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python2 |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 import sys |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 def auth(username, password): |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 if username == "someone": |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 return "1" |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 return "0" |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 def respond(ret): |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 sys.stdout.write(ret+"\n") |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 sys.stdout.flush() |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 methods = { |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 "auth": { "function": auth, "parameters": 2 } |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 } |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 while 1: |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 line = sys.stdin.readline().rstrip("\n") |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 method, sep, data = line.partition(":") |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 if method in methods: |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 method_info = methods[method] |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 split_data = data.split(":", method_info["parameters"]) |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 if len(split_data) == method_info["parameters"]: |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 respond(method_info["function"](*split_data)) |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 else: |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 respond("error: incorrect number of parameters to method '%s'"%method) |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 else: |
|
f5eadba27120
mod_auth_external: Add example Python script
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 respond("error: method '%s' not implemented"%method) |