This repository has been archived by the owner on Mar 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathejabberd_auth.module
104 lines (93 loc) · 3.24 KB
/
ejabberd_auth.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
//[FIXME] creation du script d'auth sans forcement passer par la page d'admin
/**
* Implemenation of hook_perm().
* [TODO] Maybe hard to implement
*/
function ejabberd_auth_perm() {
return array('ejabberd_auth');
}
function ejabberd_auth_menu() {
$items['admin/settings/ejabberd_auth'] = array(
'description' => 'Ejabberd auth with drupal users',
'title' => 'Ejabberd authentification',
'page callback' => 'drupal_get_form',
'page arguments' => array('ejabberd_auth_admin_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function ejabberd_auth_admin_settings() {
$form['ejabberd_php_cli'] = array(
'#type' => 'textfield',
'#title' => 'PHP path',
'#default_value' => variable_get('ejabberd_php_cli', '/usr/bin/php'),
'#description' => t("Where is the php cli?"),
);
$form['ejabberd_auth_path'] = array(
'#type' => 'textfield',
'#title' => 'Script path',
'#default_value' => variable_get('ejabberd_auth_path', '/tmp/ejabberd_auth.phps'),
'#description' => t("Where the auth script is generated"),
);
$form['ejabberd_auth_salt'] = array(
'#type' => 'textfield',
'#title' => 'Salt',
'#default_value' => variable_get('ejabberd_auth_salt', 'Casimir'),
'#description' => t("The secret word, don't keep the default one"),
);
$form['ejabberd_auth_timeout'] = array(
'#type' => 'textfield',
'#title' => 'Timeout',
'#default_value' => variable_get('ejabberd_auth_timeout', '180'),
'#description' => t("Timeout"),
);
$form['ejabberd_auth_type'] = array(
'#type' => 'select',
'#title' => 'Script type',
'#options' => array(
0 => 'Simple',
1 => 'Autonomous',
),
'#default_value' => variable_get('ejabberd_auth_type', 0),
'#description' => t('A simple script linked to drupal installation or an autonomous script?'),
);
return system_settings_form($form);
}
function ejabberd_auth_admin_settings_validate($form, &$form_state) {
$clean = TRUE;
if(! is_numeric($form_state['values']['ejabberd_auth_timeout'])) {
form_set_error('ejabberd_auth_timeout', t("Please, I'd like a number"));
$clean = FALSE;
}
$path = $form_state['values']['ejabberd_auth_path'];
if(! is_writable(dirname($path))) {
form_set_error('ejabberd_auth_path', t("Path not writable"));
$clean = FALSE;
}
if($clean) {
$f = fopen($path, 'w');
fwrite($f, "#!" . $form_state['values']['ejabberd_php_cli'] . "\n");
$inc = dirname(__FILE__) .'/drupalAuth.inc';
if(1 == $form_state['values']['ejabberd_auth_type']) {
fwrite($f, file_get_contents($inc));
} else {
fwrite($f, '<' . "?php\ninclude_once '$inc';\n");
}
$timeout = $form_state['values']['ejabberd_auth_timeout'];
$salt = str_replace("'", "\'", $form_state['values']['ejabberd_auth_salt']);
$db = (object)parse_url($GLOBALS['db_url']);
fwrite($f, <<<EOD
error_reporting(0);
\$auth = new JabberAuth('$GLOBALS[db_url]');
\$auth->salt = '$salt';
\$auth->timeout = $timeout;
\$auth->play(); // We simply start process !
EOD
);
fclose($f);
chmod($path, 0755);
drupal_set_message('The script is available at '. $form_state['values']['ejabberd_auth_path']);
}
}