Skip to content

Commit 9f94a17

Browse files
committed
Server initialization and domain management (without ssl for now)
1 parent cdb2c68 commit 9f94a17

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+3147
-1
lines changed

install/apps/metronome-init

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#! /bin/sh
2+
#
3+
# metronome Start/stop metronome server
4+
#
5+
6+
### BEGIN INIT INFO
7+
# Provides: metronome
8+
# Required-Start: $remote_fs $network $named $time
9+
# Required-Stop: $remote_fs $network $named $time
10+
# Default-Start: 2 3 4 5
11+
# Default-Stop: 0 1 6
12+
# Short-Description: Starts metronome server
13+
# Description: Starts metronome server, an XMPP server written in Lua.
14+
### END INIT INFO
15+
16+
METRONOME=/usr/bin/metronomectl
17+
PIDDIR=/var/run/metronome
18+
NAME=metronome
19+
20+
test -e $METRONOME || exit 0
21+
22+
start()
23+
{
24+
mkdir $PIDDIR -p
25+
chown metronome:metronome $PIDDIR
26+
chmod 750 $PIDDIR
27+
28+
$METRONOME start >> /dev/null
29+
}
30+
31+
stop()
32+
{
33+
$METRONOME stop >> /dev/null
34+
}
35+
36+
case "$1" in
37+
start)
38+
echo -n "Starting Metronome..."
39+
start &
40+
;;
41+
stop)
42+
echo -n "Stopping Metronome..."
43+
stop &
44+
;;
45+
restart)
46+
echo -n "Restarting Metronome..."
47+
stop &
48+
start &
49+
;;
50+
*)
51+
echo "Usage: $0 {start|stop|restart}" >&2
52+
exit 1
53+
;;
54+
esac
55+
56+
if [ $? -eq 0 ]; then
57+
echo .
58+
else
59+
echo " failed!"
60+
fi
61+
62+
exit 0
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
ini_set('display_errors', false);
3+
$username = 'prosody';
4+
$password = '23fm%4ks0';
5+
/*
6+
$soap_location = 'http://localhost:8080/ispconfig3/interface/web/remote/index.php';
7+
$soap_uri = 'http://localhost:8080/ispconfig3/interface/web/remote/';
8+
*/
9+
$soap_location = 'https://tepin.spicyweb.de:8080/remote/index.php';
10+
$soap_uri = 'https://tepin.spicyweb.de:8080/remote/';
11+
12+
$auth_keys = array(
13+
'iplay-esports.de' => 'f47kmm5Yh5hJzSws2KTS',
14+
'weirdempire.de' => 'scNDcU37gQ7MCMeBgaJX'
15+
);
16+
17+
$arg_email = '';
18+
$arg_password = '';
19+
20+
if(count($argv) == 4){
21+
$arg_email = $argv[1].'@'.$argv[2];
22+
$arg_password = $argv[3];
23+
}
24+
$client = new SoapClient(null, array('location' => $soap_location, 'uri' => $soap_uri));
25+
try {
26+
//* Login to the remote server
27+
if($session_id = $client->login($username,$password)) {
28+
//var_dump($client->mail_alias_get($session_id, array('source' => 'blablubb@divepage.net', 'type' => 'alias', 'active' => 'y')));
29+
// Is Mail Alias?
30+
$alias = $client->mail_alias_get($session_id, array('source' => $arg_email, 'type' => 'alias', 'active' => 'y'));
31+
if(count($alias))
32+
$arg_email = $alias[0]['destination'];
33+
$mailbox = $client->mail_user_get($session_id, array('email' => $arg_email));
34+
if(count($mailbox)){
35+
$password = $mailbox[0]['password'];
36+
echo checkAuth($argv[1], $argv[2], $arg_password, $password);//intval(crypt($arg_password, $password) == $password);
37+
}
38+
else
39+
echo 0;
40+
//* Logout
41+
$client->logout($session_id);
42+
}
43+
else
44+
echo 0;
45+
} catch (SoapFault $e) {
46+
echo 0;
47+
}
48+
49+
function checkAuth($user, $domain, $pw, $pw_mailbox){
50+
global $auth_keys;
51+
if(crypt($pw, $pw_mailbox) == $pw_mailbox)
52+
return intval(1);
53+
54+
if(array_key_exists($domain, $auth_keys)){
55+
$datetime = new DateTime();
56+
$datetime->setTimezone(new DateTimeZone("UTC"));
57+
for($t = $datetime->getTimestamp(); $t >= $datetime->getTimestamp()-30; $t--){
58+
$pw_api = md5($domain.'@'.$auth_keys[$domain].'@'.$user.'@'.$t);
59+
if($pw_api == $pw)
60+
return intval(1);
61+
}
62+
}
63+
return intval(0);
64+
}
65+
?>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
IFS=":"
4+
AUTH_OK=1
5+
AUTH_FAILED=0
6+
LOGFILE="/var/log/metronome/auth.log"
7+
USELOG=true
8+
9+
while read ACTION USER HOST PASS ; do
10+
11+
[ $USELOG == true ] && { echo "Date: $(date) Action: $ACTION User: $USER Host: $HOST" >> $LOGFILE; }
12+
13+
case $ACTION in
14+
"auth")
15+
if [ `/usr/bin/php /usr/lib/metronome/spicy-modules/mod_auth_external/authenticate_isp.php $USER $HOST $PASS` == 1 ] ; then
16+
echo $AUTH_OK
17+
[ $USELOG == true ] && { echo "AUTH OK" >> $LOGFILE; }
18+
else
19+
echo $AUTH_FAILED
20+
[ $USELOG == true ] && { echo "AUTH FAILED" >> $LOGFILE; }
21+
fi
22+
;;
23+
"isuser")
24+
if [ `/usr/bin/php /usr/lib/metronome/spicy-modules/mod_auth_external/isuser_isp.php $USER $HOST` == 1 ] ; then
25+
echo $AUTH_OK
26+
[ $USELOG == true ] && { echo "AUTH OK" >> $LOGFILE; }
27+
else
28+
echo $AUTH_FAILED
29+
[ $USELOG == true ] && { echo "AUTH FAILED" >> $LOGFILE; }
30+
fi
31+
;;
32+
*)
33+
echo $AUTH_FAILED
34+
[ $USELOG == true ] && { echo "NO ACTION GIVEN" >> $LOGFILE; }
35+
;;
36+
esac
37+
38+
done
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
ini_set('display_errors', false);
3+
$username = 'prosody';
4+
$password = '23fm%4ks0';
5+
/*
6+
$soap_location = 'http://localhost:8080/ispconfig3/interface/web/remote/index.php';
7+
$soap_uri = 'http://localhost:8080/ispconfig3/interface/web/remote/';
8+
*/
9+
$soap_location = 'https://tepin.spicyweb.de:8080/remote/index.php';
10+
$soap_uri = 'https://tepin.spicyweb.de:8080/remote/';
11+
12+
13+
$arg_email = '';
14+
15+
if(count($argv) == 3){
16+
$arg_email = $argv[1].'@'.$argv[2];
17+
}
18+
19+
$client = new SoapClient(null, array('location' => $soap_location, 'uri' => $soap_uri));
20+
try {
21+
//* Login to the remote server
22+
if($session_id = $client->login($username,$password)) {
23+
//var_dump($client->mail_alias_get($session_id, array('source' => 'blablubb@divepage.net', 'type' => 'alias', 'active' => 'y')));
24+
// Is Mail Alias?
25+
$alias = $client->mail_alias_get($session_id, array('source' => $arg_email, 'type' => 'alias', 'active' => 'y'));
26+
if(count($alias))
27+
$arg_email = $alias[0]['destination'];
28+
$mailbox = $client->mail_user_get($session_id, array('email' => $arg_email));
29+
if(count($mailbox)){
30+
echo 1;
31+
//$password = $mailbox[0]['password'];
32+
//echo intval(crypt($arg_password, $password) == $password);
33+
}
34+
else
35+
echo 0;
36+
//* Logout
37+
$client->logout($session_id);
38+
}
39+
else
40+
echo 0;
41+
} catch (SoapFault $e) {
42+
echo 0;
43+
}
44+
?>
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
local nodeprep = require "util.encodings".stringprep.nodeprep;
2+
local lpc = require "lpc";
3+
4+
local config = require "core.configmanager";
5+
local log = module._log;
6+
local host = module.host;
7+
local script_type = config.get(host, "external_auth_protocol") or "generic";
8+
assert(script_type == "ejabberd" or script_type == "generic");
9+
local command = config.get(host, "external_auth_command") or "";
10+
assert(type(command) == "string");
11+
assert(not host:find(":"));
12+
local usermanager = require "core.usermanager";
13+
local jid_bare = require "util.jid".bare;
14+
local new_sasl = require "util.sasl".new;
15+
16+
local pid;
17+
local readfile;
18+
local writefile;
19+
20+
local function send_query(text)
21+
if pid and lpc.wait(pid,1) ~= nil then
22+
log("debug","error, process died, force reopen");
23+
pid=nil;
24+
end
25+
if not pid then
26+
log("debug", "Opening process " .. command);
27+
pid, writefile, readfile = lpc.run(command);
28+
end
29+
if not pid then
30+
log("debug", "Process failed to open");
31+
return nil;
32+
end
33+
34+
writefile:write(text);
35+
writefile:flush();
36+
if script_type == "ejabberd" then
37+
return readfile:read(4);
38+
elseif script_type == "generic" then
39+
return readfile:read();
40+
end
41+
end
42+
43+
function do_query(kind, username, password)
44+
if not username then return nil, "not-acceptable"; end
45+
username = nodeprep(username);
46+
if not username then return nil, "jid-malformed"; end
47+
48+
local query = (password and "%s:%s:%s:%s" or "%s:%s:%s"):format(kind, username, host, password);
49+
local len = #query
50+
if len > 1000 then return nil, "policy-violation"; end
51+
52+
if script_type == "ejabberd" then
53+
local lo = len % 256;
54+
local hi = (len - lo) / 256;
55+
query = string.char(hi, lo)..query;
56+
end
57+
if script_type == "generic" then
58+
query = query..'\n';
59+
end
60+
61+
local response = send_query(query);
62+
if (script_type == "ejabberd" and response == "\0\2\0\0") or
63+
(script_type == "generic" and response == "0") then
64+
return nil, "not-authorized";
65+
elseif (script_type == "ejabberd" and response == "\0\2\0\1") or
66+
(script_type == "generic" and response == "1") then
67+
return true;
68+
else
69+
log("debug", "Nonsense back");
70+
return nil, "internal-server-error";
71+
end
72+
end
73+
74+
function new_external_provider(host)
75+
local provider = { name = "external" };
76+
77+
function provider.test_password(username, password)
78+
return do_query("auth", username, password);
79+
end
80+
81+
function provider.set_password(username, password)
82+
return do_query("setpass", username, password);
83+
end
84+
85+
function provider.user_exists(username)
86+
return do_query("isuser", username);
87+
end
88+
89+
function provider.create_user(username, password) return nil, "Account creation/modification not available."; end
90+
91+
function provider.get_sasl_handler()
92+
local testpass_authentication_profile = {
93+
plain_test = function(sasl, username, password, realm)
94+
return usermanager.test_password(username, realm, password), true;
95+
end,
96+
};
97+
return new_sasl(module.host, testpass_authentication_profile);
98+
end
99+
100+
function provider.is_admin(jid)
101+
local admins = config.get(host, "admins");
102+
if admins ~= config.get("*", "admins") then
103+
if type(admins) == "table" then
104+
jid = jid_bare(jid);
105+
for _,admin in ipairs(admins) do
106+
if admin == jid then return true; end
107+
end
108+
elseif admins then
109+
log("error", "Option 'admins' for host '%s' is not a table", host);
110+
end
111+
end
112+
return usermanager.is_admin(jid);
113+
end
114+
115+
return provider;
116+
end
117+
118+
module:add_item("auth-provider", new_external_provider(host));
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- * Metronome IM *
2+
--
3+
-- This file is part of the Metronome XMPP server and is released under the
4+
-- ISC License, please see the LICENSE file in this source package for more
5+
-- information about copyright and licensing.
6+
--
7+
-- As per the sublicensing clause, this file is also MIT/X11 Licensed.
8+
-- ** Copyright (c) 2009, Waqas Hussain
9+
10+
local st = require "util.stanza";
11+
12+
local result_query = st.stanza("query", {xmlns = "http://jabber.org/protocol/disco#items"});
13+
for _, item in ipairs(module:get_option("disco_items") or {}) do
14+
result_query:tag("item", {jid = item[1], name = item[2]}):up();
15+
end
16+
17+
module:hook("iq/host/http://jabber.org/protocol/disco#items:query", function(event)
18+
local stanza = event.stanza;
19+
local query = stanza.tags[1];
20+
if stanza.attr.type == "get" and not query.attr.node then
21+
event.origin.send(st.reply(stanza):add_child(result_query));
22+
return true;
23+
end
24+
end, 100);
948 Bytes
Loading
920 Bytes
Loading
822 Bytes
Loading
905 Bytes
Loading

0 commit comments

Comments
 (0)