-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
54 lines (52 loc) · 1.6 KB
/
functions.php
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
<?php
function _check($user, $pass, $host, $port = 119)
{
$fp = @fsockopen($host, $port, $errno, $errstr, 5);
if (!$fp)
{
die("$errstr ($errno)\n");
}
else
{
stream_set_timeout($fp, 2);
fwrite($fp, "AUTHINFO USER ".$user."\r\n");
fwrite($fp, "AUTHINFO PASS ".$pass."\r\n");
fwrite($fp, "QUIT\r\n");
while (!feof($fp))
{
$data = fgets($fp, 128);
$info = stream_get_meta_data($fp);
if ($info['timed_out'])
{
$fin[0] = 'ERROR';
$fin[1] = 'Connection timed out!';
return serialize($fin);
}
elseif ($ret = _parse($data))
{
$fin[0] = 'OK';
$fin[1] = $ret;
return serialize($fin);
}
}
}
}
function _parse($data)
{
$data = trim(strtolower($data));
$data = explode(" ", $data);
if (is_numeric($data[0]))
{
if ($data[0] == '281') $return = trim($data[4]);
elseif ($data[0] == '482') {
if ($data[1] == '(5)') $return = 'wrong password';
elseif ($data[1] == '(4)') $return = 'limit exceeded';
elseif ($data[1] == '(3)') $return = 'account disabled';
elseif ($data[1] == '(2)') $return = 'unknown user';
elseif ($data[2] == 'rejected') $return = 'unknown user';
else $return = implode(" ", $data);
}
if (!empty($return)) return $return;
}
}
?>