-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_ftp_users.php
70 lines (67 loc) · 1.84 KB
/
list_ftp_users.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
require 'config.php';
$parser = new PEAR2\Console\CommandLine(array(
'description' => 'Creates new FTP user',
'version' => '0.0.1', // the version of your program
));
$parser->addOption(
'interactive',
array(
'short_name' => '-i',
'long_name' => '--interactive',
'description' => 'Run interactively',
'action' => 'StoreTrue'
)
);
$parser->addOption(
'owner',
array(
'short_name' => '-o',
'long_name' => '--owner',
'description' => 'system user name',
'action' => 'StoreString',
'help_name' => 'system_user_name'
)
);
try {
$result = $parser->parse();
if ($result->options["interactive"]){
//TODO Запуск в интерактивном режиме
}
if (empty(array_filter($result->options))){
$parser->displayUsage();
}
try {
$cmd = escapeshellcmd('id -u ' . $result->options["owner"]);
$uid = exec($cmd . " 2>&1",$aResult, $return_val);
if ($return_val<>0)
throw new \Exception ("Can't get user uid");
} catch (Exception $ex) {
echo 'Error: ', $ex->getMessage(), "\n";
exit(1);
}
try {
if (($handle = fopen($pure_pwdfile,'r')) === FALSE) {
throw new \Exception ("Can't open pure-ftpd passwords file");
}
} catch (Exception $ex) {
echo 'Error: ', $ex->getMessage(), "\n";
exit(1);
}
$json_arr=array();
while (($data = fgetcsv($handle, 0, ":")) !== FALSE) {
if ($data[2] == $uid){
$json_arr[] = $data[0];
}
}
echo json_encode($json_arr) . "\n";
exit(0);
}
catch (Exception $exc) {
$parser->displayError($exc->getMessage());
}