Software /
code /
prosody-modules
Changeset
1164:b6280e8886f4
mod_auth_external: Move example scripts to new examples/ dir, and add Lua and Go examples
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 15 Aug 2013 16:44:43 +0100 |
parents | 1163:52bee1247014 |
children | 1165:b8762c9fb270 |
files | mod_auth_external/authorize_example.sh mod_auth_external/examples/bash/prosody-auth-example.sh mod_auth_external/examples/go/prosody-auth-example/main.go mod_auth_external/examples/lua/prosody-auth-example.lua |
diffstat | 4 files changed, 68 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_auth_external/authorize_example.sh Thu Aug 15 15:30:24 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -#!/bin/bash - -IFS=":" -AUTH_OK=1 -AUTH_FAILED=0 -LOGFILE="/var/log/prosody/auth.log" -USELOG=true - -while read ACTION USER HOST PASS ; do - - [ $USELOG == true ] && { echo "Date: $(date) Action: $ACTION User: $USER Host: $HOST Pass: $PASS" >> $LOGFILE; } - - case $ACTION in - "auth") - if [ $USER == "someone" ] ; then - echo $AUTH_OK - else - echo $AUTH_FAILED - fi - ;; - *) - echo $AUTH_FAILED - ;; - esac - -done
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_auth_external/examples/bash/prosody-auth-example.sh Thu Aug 15 16:44:43 2013 +0100 @@ -0,0 +1,26 @@ +#!/bin/bash + +IFS=":" +AUTH_OK=1 +AUTH_FAILED=0 +LOGFILE="/var/log/prosody/auth.log" +USELOG=true + +while read ACTION USER HOST PASS ; do + + [ $USELOG == true ] && { echo "Date: $(date) Action: $ACTION User: $USER Host: $HOST Pass: $PASS" >> $LOGFILE; } + + case $ACTION in + "auth") + if [ $USER == "someone" ] ; then + echo $AUTH_OK + else + echo $AUTH_FAILED + fi + ;; + *) + echo $AUTH_FAILED + ;; + esac + +done
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_auth_external/examples/go/prosody-auth-example/main.go Thu Aug 15 16:44:43 2013 +0100 @@ -0,0 +1,29 @@ +package main + +import "fmt" +import "bufio" +import "os" +import "strings" + +const ( + ACTION = iota + USER + HOST + PASSWORD +) + +func main() { + stdin := bufio.NewScanner(os.Stdin) + for stdin.Scan() { + parts := strings.SplitN(stdin.Text(), ":", 4) + switch parts[ACTION] { + case "auth": + if parts[USER] == "someone" { + fmt.Printf("1\n") + continue + } + + default: fmt.Printf("0\n") + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mod_auth_external/examples/lua/prosody-auth-example.lua Thu Aug 15 16:44:43 2013 +0100 @@ -0,0 +1,13 @@ +local actions = {}; + +function actions.auth(data) + local user, host, pass = data:match("^([^:]+):([^:]+):(.+)$"); + if user == "someone" then + return "1"; + end +end + +for line in io.lines() do + local action, data = line:match("^([^:]+)(.*)$"); + print(actions[action] and actions[action](data) or "0"); +end