Skip to content

Commit d3d6456

Browse files
author
Till Brehm
committed
Merge branch 'master' into 'master'
XMPP Service with prosody See merge request ispconfig/ispconfig3!759
2 parents d375fad + 95fa12f commit d3d6456

File tree

64 files changed

+1044
-93
lines changed

Some content is hidden

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

64 files changed

+1044
-93
lines changed
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/prosody/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/local/lib/prosody/auth/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/local/lib/prosody/auth/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
File renamed without changes.

install/apps/metronome_libs/mod_auth_external/db_conf.inc.php renamed to install/apps/xmpp_libs/auth_prosody/db_conf.inc.php

File renamed without changes.

install/apps/metronome_libs/mod_auth_external/db_isuser.php renamed to install/apps/xmpp_libs/auth_prosody/db_isuser.php

File renamed without changes.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/php
2+
<?php
3+
4+
define('DEBUG', true);
5+
usage(count($argv) < 3 || count($argv) > 4);
6+
7+
$operation = $argv[1];
8+
$host = $argv[2];
9+
10+
$configFile = file_get_contents('/etc/prosody/storage.cfg.lua');
11+
preg_match_all('/(host|database|port|username|password) *= *"?([^"\n]*)"?;/', $configFile, $matches);
12+
$config = array();
13+
foreach($matches[1] AS $ix => $key) {
14+
$config[$key] = $matches[2][$ix];
15+
}
16+
17+
try {
18+
// Connect to database
19+
$db = new mysqli($config['host'], $config['username'], $config['password'], $config['database']);
20+
21+
switch($operation){
22+
case 'user':
23+
usage(count($argv) != 4);
24+
$user = $argv[3];
25+
do_query($db->prepare("DELETE FROM prosody WHERE user = ? AND host = ?"), $host, $user);
26+
do_query($db->prepare("DELETE FROM prosodyarchive WHERE user = ? AND host = ?"), $host, $user);
27+
break;
28+
case 'domain':
29+
do_query($db->prepare("DELETE FROM prosody WHERE host = ?"), $host);
30+
do_query($db->prepare("DELETE FROM prosodyarchive WHERE host = ?"), $host);
31+
do_query($db->prepare("DELETE FROM prosody WHERE host LIKE ?"), "%.$host");
32+
do_query($db->prepare("DELETE FROM prosodyarchive WHERE host LIKE ?"), "%.$host");
33+
break;
34+
}
35+
$db->close();
36+
} catch (Exception $ex) {
37+
var_dump($ex);
38+
}
39+
40+
41+
function do_query($query, $host, $user = false){
42+
if($user !== false)
43+
$query->bind_param('ss', $user, $host);
44+
else
45+
$query->bind_param('s', $host);
46+
$query->execute();
47+
$entries = $query->affected_rows;
48+
$query->close();
49+
if(DEBUG) echo "$entries deleted!\n";
50+
return $entries;
51+
}
52+
53+
function result_false($cond = true) {
54+
if(!$cond) return;
55+
exit(1);
56+
}
57+
58+
function usage($cond = false){
59+
if(!$cond) return;
60+
echo "USAGE: \n prosody-purge domain my.domain.com \n prosody-purge user my.domain.com username \n";
61+
result_false();
62+
}

install/apps/metronome_libs/mod_auth_external/authenticate_isp.sh renamed to install/apps/xmpp_libs/mod_auth_external/authenticate_isp.sh

File renamed without changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
$query = $db->prepare("SELECT jid, password FROM xmpp_user WHERE jid LIKE ? AND active='y' AND server_id=?");
21+
$query->bind_param('si', $arg_email, $isp_server_id);
22+
$query->execute();
23+
$query->bind_result($jid, $password);
24+
$query->fetch();
25+
$query->close();
26+
27+
result_false(is_null($jid));
28+
checkAuth($arg_password, $password);
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($pw_arg, $pw_db){
44+
if(crypt($pw_arg, $pw_db) == $pw_db)
45+
result_true();
46+
result_false();
47+
}
48+
?>
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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
$query = $db->prepare("SELECT count(*) AS usercount FROM xmpp_user WHERE jid LIKE ? AND active='y' AND server_id=?");
19+
$query->bind_param('si', $arg_email, $isp_server_id);
20+
$query->execute();
21+
$query->bind_result($usercount);
22+
$query->fetch();
23+
$query->close();
24+
25+
result_false($usercount != 1);
26+
result_true();
27+
28+
}catch(Exception $ex){
29+
echo 0;
30+
exit();
31+
}
32+
33+
function result_false($cond = true){
34+
if(!$cond) return;
35+
echo 0;
36+
exit();
37+
}
38+
function result_true(){
39+
echo 1;
40+
exit();
41+
}
42+
43+
?>

install/apps/metronome_libs/mod_auth_external/mod_auth_external.lua renamed to install/apps/xmpp_libs/mod_auth_external/mod_auth_external.lua

File renamed without changes.

0 commit comments

Comments
 (0)