|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DevOpsSantana\AAPanel; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class AAPanelFTP |
|
7
|
|
|
* @package DevOpsSantana\AAPanel |
|
8
|
|
|
* @author Rogério Santana <https://github.com/devopssantana> |
|
9
|
|
|
* @since : 2022 |
|
10
|
|
|
*/ |
|
11
|
|
|
class AAPanelFTP extends AAPanelConnect |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class Construct |
|
16
|
|
|
*/ |
|
17
|
|
|
public function __construct() |
|
18
|
|
|
{ |
|
19
|
|
|
parent::__construct(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @description FTP Account List |
|
24
|
|
|
* @param int $limit |
|
25
|
|
|
* @param string $orderBy |
|
26
|
|
|
* @return mixed |
|
27
|
|
|
*/ |
|
28
|
|
|
public function List(int $limit = 100, string $orderBy = 'name'): mixed |
|
29
|
|
|
{ |
|
30
|
|
|
$url = $this->serverUrl . '/data?action=getData&table=ftps'; |
|
31
|
|
|
|
|
32
|
|
|
$this->data['limit'] = $limit; |
|
33
|
|
|
$this->data['order'] = $orderBy; |
|
34
|
|
|
return (parent::Execute($url, $this->data)); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @description FTP Account Create |
|
39
|
|
|
* @param $ftpUsername |
|
40
|
|
|
* @param $ftpPassword |
|
41
|
|
|
* @param string $path |
|
42
|
|
|
* @param $description |
|
43
|
|
|
* @return mixed |
|
44
|
|
|
*/ |
|
45
|
|
|
public function Create($ftpUsername, $ftpPassword, $description, string $path = '/www/wwwroot/'): mixed |
|
46
|
|
|
{ |
|
47
|
|
|
$url = $this->serverUrl . '/ftp?action=AddUser'; |
|
48
|
|
|
|
|
49
|
|
|
$this->data['ftp_username'] = $ftpUsername; |
|
50
|
|
|
$this->data['ftp_password'] = $ftpPassword; |
|
51
|
|
|
$this->data['ps'] = $description; |
|
52
|
|
|
$this->data['path'] = $path; |
|
53
|
|
|
return (parent::Execute($url, $this->data)); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @description FTP Account Delete |
|
58
|
|
|
* @param $id |
|
59
|
|
|
* @param $ftpUsername |
|
60
|
|
|
* @return mixed |
|
61
|
|
|
*/ |
|
62
|
|
|
public function Delete($id, $ftpUsername): mixed |
|
63
|
|
|
{ |
|
64
|
|
|
$url = $this->serverUrl . '/ftp?action=DeleteUser'; |
|
65
|
|
|
|
|
66
|
|
|
$this->data['id'] = $id; |
|
67
|
|
|
$this->data['username'] = $ftpUsername; |
|
68
|
|
|
return (parent::Execute($url, $this->data)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @description FTP Account Change Pwd |
|
73
|
|
|
* @param $id |
|
74
|
|
|
* @param $ftpUsername |
|
75
|
|
|
* @param $newPwd |
|
76
|
|
|
* @return mixed |
|
77
|
|
|
*/ |
|
78
|
|
|
public function ChangePwd($id, $ftpUsername, $newPwd): mixed |
|
79
|
|
|
{ |
|
80
|
|
|
$url = $this->serverUrl . '/ftp?action=SetUserPassword'; |
|
81
|
|
|
|
|
82
|
|
|
$this->data['id'] = $id; |
|
83
|
|
|
$this->data['ftp_username'] = $ftpUsername; |
|
84
|
|
|
$this->data['new_password'] = $newPwd; |
|
85
|
|
|
return (parent::Execute($url, $this->data)); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @description FTP Account Change Status |
|
90
|
|
|
* @param $id |
|
91
|
|
|
* @param $ftpUsername |
|
92
|
|
|
* @param $actualStatus |
|
93
|
|
|
* @return mixed |
|
94
|
|
|
*/ |
|
95
|
|
|
public function ChangeStatus(int $id, string $ftpUsername, $actualStatus): mixed |
|
96
|
|
|
{ |
|
97
|
|
|
$url = $this->serverUrl . '/ftp?action=SetStatus'; |
|
98
|
|
|
|
|
99
|
|
|
$this->data['id'] = $id; |
|
100
|
|
|
$this->data['username'] = $ftpUsername; |
|
101
|
|
|
$this->data['status'] = $actualStatus == 0 ? '1' : '0'; |
|
102
|
|
|
return (parent::Execute($url, $this->data)); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @description FTP Check required fields |
|
107
|
|
|
* @param $ftpUsername |
|
108
|
|
|
* @param $ftpPassword |
|
109
|
|
|
* @return bool |
|
110
|
|
|
*/ |
|
111
|
|
|
public function Verify(string $ftpUsername, string $ftpPassword): bool |
|
112
|
|
|
{ |
|
113
|
|
|
if (!empty($ftpUsername) && !empty($ftpPassword)) { |
|
114
|
|
|
return true; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
return false; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|