Skip to content

Commit 6b1fde7

Browse files
author
Marius Cramer
committed
Merge remote-tracking branch 'ispc/master'
2 parents 108dd92 + 8d3466b commit 6b1fde7

File tree

1,312 files changed

+32403
-24921
lines changed

Some content is hidden

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

1,312 files changed

+32403
-24921
lines changed

helper_scripts/recreate_webalizer_stats.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
//######################################################################################################
66

77

8-
$sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE server_id = ".$conf["server_id"];
9-
$records = $app->db->queryAllRecords($sql);
8+
$sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE server_id = ?";
9+
$records = $app->db->queryAllRecords($sql, $conf["server_id"]);
1010
foreach($records as $rec) {
1111
$domain = escapeshellcmd($rec["domain"]);
1212
$logdir = escapeshellcmd($rec["document_root"].'/log');

install/apps/metronome-init

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
reload()
37+
{
38+
&METRONOME reload >> /dev/null
39+
}
40+
41+
restart()
42+
{
43+
&METRONOME restart >> /dev/null
44+
}
45+
46+
case "$1" in
47+
start)
48+
echo -n "Starting Metronome..."
49+
start &
50+
;;
51+
stop)
52+
echo -n "Stopping Metronome..."
53+
stop &
54+
;;
55+
reload)
56+
echo -n "Reloading Metronome config..."
57+
reload &
58+
;;
59+
restart)
60+
echo -n "Restarting Metronome..."
61+
restart &
62+
;;
63+
*)
64+
echo "Usage: $0 {start|stop|reload|restart}" >&2
65+
exit 1
66+
;;
67+
esac
68+
69+
if [ $? -eq 0 ]; then
70+
echo .
71+
else
72+
echo " failed!"
73+
fi
74+
75+
exit 0
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/isp-modules/mod_auth_external/db_auth.php $USER $HOST $PASS 2>/dev/null` == 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/isp-modules/mod_auth_external/db_isuser.php $USER $HOST 2>/dev/null` == 1 ] ; then
25+
echo $AUTH_OK
26+
[ $USELOG == true ] && { echo "ISUSER OK" >> $LOGFILE; }
27+
else
28+
echo $AUTH_FAILED
29+
[ $USELOG == true ] && { echo "ISUSER FAILED" >> $LOGFILE; }
30+
fi
31+
;;
32+
*)
33+
echo $AUTH_FAILED
34+
[ $USELOG == true ] && { echo "UNKNOWN ACTION GIVEN: $ACTION" >> $LOGFILE; }
35+
;;
36+
esac
37+
38+
done
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
ini_set('display_errors', false);
3+
require_once('db_conf.inc.php');
4+
5+
try{
6+
// Connect database
7+
$db = new mysqli($db_host, $db_user, $db_pass, $db_name);
8+
result_false(mysqli_connect_errno());
9+
10+
// Get arguments
11+
$arg_email = '';
12+
$arg_password = '';
13+
14+
result_false(count($argv) != 4);
15+
$arg_email = $argv[1].'@'.$argv[2];
16+
$arg_password = $argv[3];
17+
18+
// check for existing user
19+
$dbmail = $db->real_escape_string($arg_email);
20+
$result = $db->query("SELECT jid, password FROM xmpp_user WHERE jid LIKE ? AND active='y' AND server_id=?", $dbmail, $isp_server_id);
21+
result_false($result->num_rows != 1);
22+
23+
$user = $result->fetch_object();
24+
25+
// check for domain autologin api key
26+
$domain_key = 'f47kmm5Yh5hJzSws2KTS';
27+
28+
checkAuth($argv[1], $argv[2], $arg_password, $user->password, $domain_key);
29+
}catch(Exception $ex){
30+
echo 0;
31+
exit();
32+
}
33+
34+
function result_false($cond = true){
35+
if(!$cond) return;
36+
echo 0;
37+
exit();
38+
}
39+
function result_true(){
40+
echo 1;
41+
exit();
42+
}
43+
function checkAuth($user, $domain, $pw_arg, $pw_db, $domain_key){
44+
if(crypt($pw_arg, $pw_db) == $pw_db)
45+
result_true();
46+
47+
if($domain_key){
48+
$datetime = new DateTime();
49+
$datetime->setTimezone(new DateTimeZone("UTC"));
50+
for($t = $datetime->getTimestamp(); $t >= $datetime->getTimestamp()-30; $t--){
51+
$pw_api = md5($domain.'@'.$domain_key.'@'.$user.'@'.$t);
52+
if($pw_api == $pw_arg)
53+
result_true();
54+
}
55+
}
56+
result_false();
57+
}
58+
?>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
$db_user = '{mysql_server_ispconfig_user}';
3+
$db_pass = '{mysql_server_ispconfig_password}';
4+
$db_name = '{mysql_server_database}';
5+
$db_host = '{mysql_server_ip}';
6+
$isp_server_id = '{server_id}';
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
ini_set('display_errors', false);
3+
require_once('db_conf.inc.php');
4+
5+
try{
6+
// Connect database
7+
$db = new mysqli($db_host, $db_user, $db_pass, $db_name);
8+
result_false(mysqli_connect_errno());
9+
10+
// Get arguments
11+
$arg_email = '';
12+
13+
result_false(count($argv) != 3);
14+
$arg_email = $argv[1].'@'.$argv[2];
15+
16+
// check for existing user
17+
$dbmail = $db->real_escape_string($arg_email);
18+
$result = $db->query("SELECT jid, password FROM xmpp_user WHERE jid LIKE ? AND active='y' AND server_id=?", $dbmail, $isp_server_id);
19+
result_false($result->num_rows != 1);
20+
result_true();
21+
22+
}catch(Exception $ex){
23+
echo 0;
24+
exit();
25+
}
26+
27+
function result_false($cond = true){
28+
if(!$cond) return;
29+
echo 0;
30+
exit();
31+
}
32+
function result_true(){
33+
echo 1;
34+
exit();
35+
}
36+
37+
?>
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

0 commit comments

Comments
 (0)