2 |
3 |
8 | Powerful API client hosting VestaCP for Laravel 9 |
10 | 11 | 18 | 19 | 20 | ## Installation 21 | 22 | 23 | #### Via Composer 24 | 25 | Going your project directory on shell and run this command: 26 | 27 | ```sh 28 | $ composer require tabuna/vesta-api 29 | ``` 30 | 31 | Publication 32 | ```php 33 | php artisan vendor:publish --provider="VestaAPI\Providers\VestaServiceProvider" 34 | ``` 35 | 36 | Generate api key 37 | 38 | ```bash 39 | bash /usr/local/vesta/bin/v-generate-api-key 40 | ``` 41 | 42 | 43 | ## Usage 44 | 45 | 46 | Simple usage 47 | ```php 48 | use VestaAPI\Facades\Vesta; 49 | 50 | $backups = Vesta::server('testVDS')->setUserName('MyUserName')->listUserBackups(); 51 | 52 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tabuna/vesta-api", 3 | "description": "VestaCP client for Laravel", 4 | "keywords": [ 5 | "framework", 6 | "laravel", 7 | "hosting", 8 | "vesta", 9 | "panel" 10 | ], 11 | "type": "library", 12 | "require": { 13 | "guzzlehttp/guzzle": "^6.5", 14 | "laravel/framework": "^7.0" 15 | }, 16 | "license": "GPL-3.0", 17 | "support": { 18 | "issues": "https://github.com/tabuna/VestaAPI/issues", 19 | "source": "https://github.com/tabuna/VestaAPI" 20 | }, 21 | "authors": [ 22 | { 23 | "name": "Alexandr Chernyaev", 24 | "email": "bliz48rus@gmail.com" 25 | } 26 | ], 27 | "autoload": { 28 | "psr-4": { 29 | "VestaAPI\\": "src/" 30 | } 31 | }, 32 | "extra": { 33 | "laravel": { 34 | "providers": [ 35 | "VestaAPI\\Providers\\VestaServiceProvider" 36 | ], 37 | "aliases": { 38 | "Dashboard": "VestaAPI\\Facades\\Vesta" 39 | } 40 | } 41 | }, 42 | "minimum-stability": "stable", 43 | "prefer-stable": true 44 | } -------------------------------------------------------------------------------- /config/vesta.php: -------------------------------------------------------------------------------- 1 | 'testVDS', 12 | 13 | /* 14 | |-------------------------------------------------------------------------- 15 | | Remote Server 16 | |-------------------------------------------------------------------------- 17 | */ 18 | 19 | 'servers' => [ 20 | 'testVDS' => [ 21 | 'host' => '0.0.0.0', 22 | 'key' => 'secretString', 23 | ], 24 | ], 25 | 26 | ]; 27 | -------------------------------------------------------------------------------- /src/Exceptions/VestaExceptions.php: -------------------------------------------------------------------------------- 1 | message) { 17 | case 1: 18 | $return = redirect()->back()->withErrors(['Not enough arguments provided']); 19 | break; 20 | case 2: 21 | $return = redirect()->back()->withErrors(['Object or argument is not valid']); 22 | break; 23 | case 3: 24 | $return = redirect()->back()->withErrors(["Object doesn't exist"]); 25 | break; 26 | case 4: 27 | $return = redirect()->back()->withErrors(['Object already exists']); 28 | break; 29 | case 5: 30 | $return = redirect()->back()->withErrors(['Object is suspended']); 31 | break; 32 | case 6: 33 | $return = redirect()->back()->withErrors(['Object is already unsuspended']); 34 | break; 35 | case 7: 36 | $return = redirect()->back()->withErrors(["Object can't be deleted because is used by the other object"]); 37 | break; 38 | case 8: 39 | $return = redirect()->back()->withErrors(['Object cannot be created because of hosting package limits']); 40 | break; 41 | case 9: 42 | $return = redirect()->back()->withErrors(['Wrong password']); 43 | break; 44 | case 10: 45 | $return = redirect()->back()->withErrors(['Object cannot be accessed be the user']); 46 | break; 47 | case 11: 48 | $return = redirect()->back()->withErrors(['Subsystem is disabled']); 49 | break; 50 | case 12: 51 | $return = redirect()->back()->withErrors(['Configuration is broken']); 52 | break; 53 | case 13: 54 | $return = redirect()->back()->withErrors(['Not enough disk space to complete the action']); 55 | break; 56 | case 14: 57 | $return = redirect()->back()->withErrors(['Server is to busy to complete the action']); 58 | break; 59 | case 15: 60 | $return = redirect()->back()->withErrors(['Connection failed. Host is unreachable']); 61 | break; 62 | case 16: 63 | $return = redirect()->back()->withErrors(['FTP server is not responding']); 64 | break; 65 | case 17: 66 | $return = redirect()->back()->withErrors(['Database server is not responding']); 67 | break; 68 | case 18: 69 | $return = redirect()->back()->withErrors(['RRDtool failed to update the database']); 70 | break; 71 | case 19: 72 | $return = redirect()->back()->withErrors(['Update operation failed']); 73 | break; 74 | case 20: 75 | $return = redirect()->back()->withErrors(['Service restart failed']); 76 | break; 77 | default: 78 | $return = redirect()->back()->withErrors([$e->getMessage()]); 79 | } 80 | 81 | return $return; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Facades/Vesta.php: -------------------------------------------------------------------------------- 1 | registerConfig(); 15 | } 16 | 17 | /** 18 | * Register config. 19 | */ 20 | protected function registerConfig() 21 | { 22 | $this->publishes([ 23 | __DIR__.'/../../config/vesta.php' => config_path('vesta.php'), 24 | ]); 25 | 26 | $this->mergeConfigFrom( 27 | __DIR__.'/../../config/vesta.php', 28 | 'vesta' 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Services/BD.php: -------------------------------------------------------------------------------- 1 | returnCode = 'no'; 15 | 16 | return json_decode($this->send('v-list-databases', $this->userName, 'json'), true); 17 | } 18 | 19 | /** 20 | * Change user database. 21 | * 22 | * @param $database 23 | * @param $dbuser 24 | * 25 | * @return mixed 26 | */ 27 | public function changeDbUser($database, $dbuser) 28 | { 29 | return $this->send('v-change-database-user', $this->userName, $database, $dbuser); 30 | } 31 | 32 | /** 33 | * Change data base password. 34 | * 35 | * @param $database 36 | * @param $password 37 | * 38 | * @return mixed 39 | */ 40 | public function changeDbPassword($database, $password) 41 | { 42 | return $this->send('v-change-database-password', $this->userName, $database, $password); 43 | } 44 | 45 | /** 46 | * List Only BD. 47 | * 48 | * @param $database 49 | * 50 | * @return mixed 51 | */ 52 | public function listOnlyBD($database) 53 | { 54 | $this->returnCode = 'no'; 55 | $listBd = $this->send('v-list-database', $this->userName, $database, 'json'); 56 | $data = json_decode($listBd, true); 57 | 58 | return $data; 59 | } 60 | 61 | /** 62 | * Add date base. 63 | * 64 | * @param $database 65 | * @param $dbuser 66 | * @param $password 67 | * @param string $type 68 | * @param $charset 69 | * 70 | * @return mixed 71 | */ 72 | public function addDateBase($database, $dbuser, $password, $type, $charset) 73 | { 74 | return $this->send( 75 | 'v-add-database', 76 | $this->userName, 77 | $database, 78 | $dbuser, 79 | $password, 80 | $type, 81 | 'localhost', 82 | $charset 83 | ); 84 | } 85 | 86 | /** 87 | * Delete data base. 88 | * 89 | * @param $database 90 | * 91 | * @return mixed 92 | */ 93 | public function deleteDateBase($database) 94 | { 95 | return $this->send('v-delete-database', $this->userName, $database); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/Services/Cron.php: -------------------------------------------------------------------------------- 1 | returnCode = 'no'; 15 | $listDns = $this->send('v-list-cron-jobs', $this->userName, 'json'); 16 | $data = json_decode($listDns, true); 17 | 18 | return $data; 19 | } 20 | 21 | /** 22 | * Add Cron. 23 | * 24 | * @param $min 25 | * @param $hour 26 | * @param $day 27 | * @param $month 28 | * @param $wday 29 | * @param $cmd 30 | * 31 | * @return mixed 32 | */ 33 | public function addCron($min, $hour, $day, $month, $wday, $cmd) 34 | { 35 | return $this->send( 36 | 'v-add-cron-job', 37 | $this->userName, 38 | $min, 39 | $hour, 40 | $day, 41 | $month, 42 | $wday, 43 | $cmd 44 | ); 45 | } 46 | 47 | /** 48 | * Show Cron. 49 | * 50 | * @param $job 51 | * 52 | * @return mixed 53 | */ 54 | public function showCron($job) 55 | { 56 | $this->returnCode = 'no'; 57 | $request = $this->send('v-list-cron-job', $this->userName, $job, 'json'); 58 | $data = json_decode($request, true); 59 | 60 | return $data; 61 | } 62 | 63 | /** 64 | * Delete cron. 65 | * 66 | * @param $job 67 | * 68 | * @return mixed 69 | */ 70 | public function deleteCron($job) 71 | { 72 | return $this->send('v-delete-cron-job', $this->userName, $job); 73 | } 74 | 75 | /** 76 | * Edit cron. 77 | * 78 | * @param $job 79 | * @param $min 80 | * @param $hour 81 | * @param $day 82 | * @param $month 83 | * @param $wday 84 | * @param $cmd 85 | * 86 | * @return mixed 87 | */ 88 | public function editCron($job, $min, $hour, $day, $month, $wday, $cmd) 89 | { 90 | return $this->send( 91 | 'v-change-cron-job', 92 | $this->userName, 93 | $job, 94 | $min, 95 | $hour, 96 | $day, 97 | $month, 98 | $wday, 99 | $cmd 100 | ); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/Services/DNS.php: -------------------------------------------------------------------------------- 1 | returnCode = 'no'; 15 | $listDns = $this->send('v-list-dns-domains', $this->userName, 'json'); 16 | $data = json_decode($listDns, true); 17 | 18 | return $data; 19 | } 20 | 21 | /** 22 | * List Only DNS. 23 | * 24 | * @param $dns 25 | * 26 | * @return mixed 27 | */ 28 | public function listOnlyDNS($dns) 29 | { 30 | $this->returnCode = 'no'; 31 | $listDNS = $this->send('v-list-dns-domain', $this->userName, $dns, 'json'); 32 | $data = json_decode($listDNS, true); 33 | 34 | return $data; 35 | } 36 | 37 | /** 38 | * Delete DNS record domain. 39 | * 40 | * @param $domain 41 | * 42 | * @return mixed 43 | */ 44 | public function deleteDNDDomain($domain) 45 | { 46 | return $this->send('v-delete-dns-domain', $this->userName, $domain); 47 | } 48 | 49 | /** 50 | * Delete DNS record. 51 | * 52 | * @param $domain 53 | * @param $recordId 54 | * 55 | * @return mixed 56 | */ 57 | public function deleteDNSRecord($domain, $recordId) 58 | { 59 | return $this->send('v-delete-dns-record', $this->userName, $domain, $recordId); 60 | } 61 | 62 | /** 63 | * Add DNS domain. 64 | * 65 | * @param $domain 66 | * @param $ip 67 | * @param $ns1 68 | * @param $ns2 69 | * @param null $ns3 70 | * @param null $ns4 71 | * 72 | * @return mixed 73 | */ 74 | public function addDNSDomain($domain, $ip, $ns1, $ns2, $ns3 = null, $ns4 = null) 75 | { 76 | return $this->send( 77 | 'v-add-dns-domain', 78 | $this->userName, 79 | $domain, 80 | $ip, 81 | $ns1, 82 | $ns2, 83 | $ns3, 84 | $ns4, 85 | 'no' 86 | ); 87 | } 88 | 89 | /** 90 | * Set expiriation date. 91 | * 92 | * @param $domain 93 | * @param $exp 94 | * 95 | * @return mixed 96 | */ 97 | public function changeDNSDomainExp($domain, $exp) 98 | { 99 | return $this->send('v-change-dns-domain-exp', $this->userName, $domain, $exp, 'no'); 100 | } 101 | 102 | /** 103 | * Set TTL. 104 | * 105 | * @param $domain 106 | * @param $ttl 107 | * 108 | * @return mixed 109 | */ 110 | public function changeDNSDomainTtl($domain, $ttl) 111 | { 112 | return $this->send('v-change-dns-domain-ttl', $this->userName, $domain, $ttl, 'no'); 113 | } 114 | 115 | /** 116 | * List DNS record domain. 117 | * 118 | * @param $domain 119 | * 120 | * @return mixed 121 | */ 122 | public function listDNSRecords($domain) 123 | { 124 | $this->returnCode = 'no'; 125 | $data = $this->send('v-list-dns-records', $this->userName, $domain, 'json'); 126 | $data = json_decode($data, true); 127 | 128 | return $data; 129 | } 130 | 131 | /** 132 | * Change DNS domain record. 133 | * 134 | * @param $domain 135 | * @param $recordId 136 | * @param $val 137 | * @param $priority 138 | * 139 | * @return mixed 140 | */ 141 | public function changeDNSDomainRecord($domain, $recordId, $val, $priority) 142 | { 143 | return $this->send( 144 | 'v-change-dns-record', 145 | $this->userName, 146 | $domain, 147 | $recordId, 148 | $val, 149 | $priority 150 | ); 151 | } 152 | 153 | /** 154 | * Remove DNS record. 155 | * 156 | * @param $domain 157 | * @param $recordId 158 | */ 159 | public function removeDNSRecord($domain, $recordId) 160 | { 161 | $this->send('v-delete-dns-record', $this->userName, $domain, $recordId); 162 | } 163 | 164 | /** 165 | * Add DNS record. 166 | * 167 | * @param $domain 168 | * @param $rec 169 | * @param $type 170 | * @param $val 171 | * @param $priority 172 | */ 173 | public function addDNSRecord($domain, $rec, $type, $val, $priority) 174 | { 175 | $this->send('v-add-dns-record', $this->userName, $domain, $rec, $type, $val, $priority); 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /src/Services/FileSystem.php: -------------------------------------------------------------------------------- 1 | 0, 17 | 'PERMISSIONS' => 1, 18 | 'DATE' => 2, 19 | 'TIME' => 3, 20 | 'OWNER' => 4, 21 | 'GROUP' => 5, 22 | 'SIZE' => 6, 23 | 'NAME' => 7, 24 | ]; 25 | 26 | /** 27 | * @param $src 28 | * @param $dst 29 | * 30 | * @return mixed 31 | */ 32 | public function moveFile($src, $dst) 33 | { 34 | $this->returnCode = 'no'; 35 | 36 | return $this->send('v-move-fs-file', $this->userName, $src, $dst); 37 | } 38 | 39 | /** 40 | * @param string $path 41 | * 42 | * @return mixed 43 | */ 44 | public function openFile($path = '') 45 | { 46 | $path = '/home/'.$this->userName.'/'.$path; 47 | $this->returnCode = 'no'; 48 | 49 | return $this->send('v-open-fs-file', $this->userName, $path); 50 | } 51 | 52 | /** 53 | * @param $patch 54 | * 55 | * @return mixed 56 | */ 57 | public function addDir($patch) 58 | { 59 | $this->returnCode = 'no'; 60 | 61 | return $this->send('v-add-fs-directory', $this->userName, $patch); 62 | } 63 | 64 | /** 65 | * @param $patch 66 | * 67 | * @return mixed 68 | */ 69 | public function addFile($patch) 70 | { 71 | $this->returnCode = 'no'; 72 | 73 | return $this->send('v-add-fs-file', $this->userName, $patch); 74 | } 75 | 76 | /** 77 | * @param $srcFile 78 | * @param $permissions 79 | * 80 | * @return mixed 81 | */ 82 | public function changePermission($srcFile, $permissions) 83 | { 84 | $srcFile = '/home/'.$this->userName.'/'.$srcFile; 85 | $this->returnCode = 'no'; 86 | 87 | return $this->send('v-change-fs-file-permission', $this->userName, $srcFile, $permissions); 88 | } 89 | 90 | /** 91 | * @param $srcDir 92 | * @param $dstDir 93 | * 94 | * @return mixed 95 | */ 96 | public function copyDir($srcDir, $dstDir) 97 | { 98 | $this->returnCode = 'no'; 99 | 100 | return $this->send('v-copy-fs-directory', $this->userName, $srcDir, $dstDir); 101 | } 102 | 103 | /** 104 | * @param $srcDir 105 | * @param $dstDir 106 | * 107 | * @return mixed 108 | */ 109 | public function copyFile($srcDir, $dstDir) 110 | { 111 | $this->returnCode = 'no'; 112 | 113 | return $this->send('v-copy-fs-file', $this->userName, $srcDir, $dstDir); 114 | } 115 | 116 | /** 117 | * @param $dstDir 118 | * 119 | * @return mixed 120 | */ 121 | public function deleteDir($dstDir) 122 | { 123 | $this->returnCode = 'no'; 124 | $dstDir = '/home/'.$this->userName.'/'.$dstDir; 125 | 126 | return $this->send('v-delete-fs-dir', $this->userName, $dstDir); 127 | } 128 | 129 | /** 130 | * @param $dstFile 131 | * 132 | * @return mixed 133 | */ 134 | public function deleteFile($dstFile) 135 | { 136 | $this->returnCode = 'no'; 137 | $dstFile = '/home/'.$this->userName.'/'.$dstFile; 138 | 139 | return $this->send('v-delete-fs-file', $this->userName, $dstFile); 140 | } 141 | 142 | /** 143 | * @param $srcFile 144 | * @param $dstDir 145 | * 146 | * @return mixed 147 | */ 148 | public function extractArchive($srcFile, $dstDir) 149 | { 150 | $this->returnCode = 'no'; 151 | 152 | return $this->send('v-extract-fs-archive', $this->userName, $srcFile, $dstDir); 153 | } 154 | 155 | /** 156 | * @param $path 157 | * 158 | * @return mixed 159 | */ 160 | public function listDirectory($path = '') 161 | { 162 | $path = '/home/'.$this->userName.'/'.$path; 163 | $this->returnCode = 'no'; 164 | $responseVesta = $this->send('v-list-fs-directory', $this->userName, $path); 165 | 166 | return $this->parseListing($responseVesta); 167 | } 168 | 169 | /** 170 | * @param $raw 171 | * 172 | * @return array 173 | */ 174 | public function parseListing($raw) 175 | { 176 | $raw = explode(PHP_EOL, $raw); 177 | $raw = array_filter($raw); 178 | $data = []; 179 | 180 | foreach ($raw as $o) { 181 | $info = explode($this->delimeter, $o); 182 | 183 | $value = [ 184 | 'type' => $info[$this->info_positions['TYPE']], 185 | 'permissions' => $info[$this->info_positions['PERMISSIONS']], 186 | 'date' => $info[$this->info_positions['DATE']], 187 | 'time' => $info[$this->info_positions['TIME']], 188 | 'owner' => $info[$this->info_positions['OWNER']], 189 | 'group' => $info[$this->info_positions['GROUP']], 190 | 'size' => $info[$this->info_positions['SIZE']], 191 | 'name' => (!empty($info[$this->info_positions['NAME']])) ? $info[$this->info_positions['NAME']] : '../', 192 | ]; 193 | 194 | array_push($data, $value); 195 | } 196 | 197 | return $data; 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /src/Services/Service.php: -------------------------------------------------------------------------------- 1 | send('v-restart-dns'); 15 | } 16 | 17 | /** 18 | * @param $query 19 | * 20 | * @return mixed 21 | */ 22 | public function userSearch($query) 23 | { 24 | $this->returnCode = 'no'; 25 | 26 | return json_decode($this->send('v-search-user-object', $this->userName, $query, 'json'), true); 27 | } 28 | 29 | /** 30 | * @return array 31 | */ 32 | public function listStats() 33 | { 34 | $this->returnCode = 'no'; 35 | $data = json_decode($this->send('v-list-users-stats', 'json'), true); 36 | 37 | return array_reverse($data, true); 38 | } 39 | 40 | /** 41 | * @return mixed 42 | */ 43 | public function listRRD() 44 | { 45 | $this->returnCode = 'no'; 46 | 47 | return json_decode($this->send('v-list-sys-rrd', 'json'), true); 48 | } 49 | 50 | /** 51 | * @return mixed 52 | */ 53 | public function listSysInfo() 54 | { 55 | $this->returnCode = 'no'; 56 | 57 | return json_decode($this->send('v-list-sys-info', 'json'), true); 58 | } 59 | 60 | /** 61 | * @return mixed 62 | */ 63 | public function listSysService() 64 | { 65 | $this->returnCode = 'no'; 66 | 67 | return json_decode($this->send('v-list-sys-services', 'json'), true); 68 | } 69 | 70 | /** 71 | * @param $service 72 | * 73 | * @return mixed 74 | */ 75 | public function restartService($service) 76 | { 77 | return $this->send('v-restart-service', $service); 78 | } 79 | 80 | /** 81 | * @param $service 82 | * 83 | * @return mixed 84 | */ 85 | public function startService($service) 86 | { 87 | return $this->send('v-start-service', $service); 88 | } 89 | 90 | /** 91 | * @param $service 92 | * 93 | * @return mixed 94 | */ 95 | public function stopService($service) 96 | { 97 | return $this->send('v-stop-service', $service); 98 | } 99 | 100 | /** 101 | * @return mixed 102 | */ 103 | public function listIp() 104 | { 105 | $this->returnCode = 'no'; 106 | 107 | return json_decode($this->send('v-list-sys-ips', 'json'), true); 108 | } 109 | 110 | /** 111 | * @param $ip 112 | * 113 | * @return mixed 114 | */ 115 | public function getIp($ip) 116 | { 117 | $this->returnCode = 'no'; 118 | 119 | return json_decode($this->send('v-list-sys-ip', $ip, 'json'), true); 120 | } 121 | 122 | /** 123 | * @return mixed 124 | * 125 | * @internal param string $restart 126 | */ 127 | public function rebuildWebDomains() 128 | { 129 | return $this->send('v-rebuild-web-domains', $this->userName); 130 | } 131 | 132 | /** 133 | * @return mixed 134 | * 135 | * @internal param string $restart 136 | */ 137 | public function rebuildDNSDomains() 138 | { 139 | return $this->send('v-rebuild-dns-domains', $this->userName); 140 | } 141 | 142 | /** 143 | * @return mixed 144 | */ 145 | public function rebuildMailDomains() 146 | { 147 | return $this->send('v-rebuild-mail-domains', $this->userName); 148 | } 149 | 150 | /** 151 | * @return mixed 152 | */ 153 | public function rebuildDataBases() 154 | { 155 | return $this->send('v-rebuild-databases', $this->userName); 156 | } 157 | 158 | /** 159 | * @return mixed 160 | * 161 | * @internal param string $restart 162 | */ 163 | public function rebuildCronJobs() 164 | { 165 | return $this->send('v-rebuild-cron-jobs', $this->userName); 166 | } 167 | 168 | /** 169 | * @return mixed 170 | */ 171 | public function updateUserCounters() 172 | { 173 | return $this->send('v-update-user-counters', $this->userName); 174 | } 175 | 176 | /** 177 | * @param $package 178 | * 179 | * @return mixed 180 | */ 181 | public function updateSysVesta($package) 182 | { 183 | return $this->send('v-update-sys-vesta', $package); 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /src/Services/User.php: -------------------------------------------------------------------------------- 1 | send('v-add-user', $username, $password, $email, $package, $fistName, $lastName); 22 | } 23 | 24 | /** 25 | * @param $password 26 | * 27 | * @return mixed 28 | */ 29 | public function changeUserPassword($password) 30 | { 31 | return $this->send('v-change-user-password', $this->userName, $password); 32 | } 33 | 34 | /** 35 | * @param $email 36 | * 37 | * @return mixed 38 | */ 39 | public function changeUserEmail($email) 40 | { 41 | return $this->send('v-change-user-contact', $this->userName, $email); 42 | } 43 | 44 | /** 45 | * List User Account. 46 | * 47 | * @return mixed 48 | */ 49 | public function listUserAccount() 50 | { 51 | $this->returnCode = 'no'; 52 | $answer = $this->send('v-list-user', $this->userName, 'json'); 53 | $data = json_decode($answer, true); 54 | 55 | return $data; 56 | } 57 | 58 | /** 59 | * @return mixed 60 | */ 61 | public function listUserLog() 62 | { 63 | $this->returnCode = 'no'; 64 | $answer = $this->send('v-list-user-log', $this->userName, 'json'); 65 | $data = json_decode($answer, true); 66 | 67 | return $data; 68 | } 69 | 70 | /** 71 | * List User Backups. 72 | * 73 | * @return mixed 74 | */ 75 | public function listUserBackups() 76 | { 77 | $this->returnCode = 'no'; 78 | $answer = $this->send('v-list-user-backups', $this->userName, 'json'); 79 | $data = json_decode($answer, true); 80 | 81 | return $data; 82 | } 83 | 84 | /** 85 | * Delete backup user. 86 | * 87 | * @param $backup 88 | * 89 | * @return mixed 90 | */ 91 | public function deleteUserBackup($backup) 92 | { 93 | return $this->send('v-delete-user-backup', $this->userName, $backup); 94 | } 95 | 96 | /** 97 | * Show Backup. 98 | * 99 | * @param $backup 100 | * 101 | * @return mixed 102 | */ 103 | public function showUserBackup($backup) 104 | { 105 | $this->returnCode = 'no'; 106 | $answer = $this->send('v-list-user-backup', $this->userName, $backup, 'json'); 107 | $data = json_decode($answer, true); 108 | 109 | return $data; 110 | } 111 | 112 | /** 113 | * @param $arg 114 | * 115 | * @return mixed 116 | */ 117 | public function restoreBackup($arg) 118 | { 119 | $backup = 'no'; 120 | $web = 'no'; 121 | $dns = 'no'; 122 | $mail = 'no'; 123 | $db = 'no'; 124 | $cron = 'no'; 125 | $udir = 'no'; 126 | extract($arg, EXTR_OVERWRITE); 127 | 128 | return $this->send( 129 | 'v-schedule-user-restore', 130 | $this->userName, 131 | $backup, 132 | $web, 133 | $dns, 134 | $mail, 135 | $db, 136 | $cron, 137 | $udir 138 | ); 139 | } 140 | 141 | /** 142 | * @return mixed 143 | */ 144 | public function deleteUser() 145 | { 146 | return $this->send('v-delete-user', $this->userName, 'no'); 147 | } 148 | 149 | /** 150 | * @return mixed 151 | */ 152 | public function suspendUser() 153 | { 154 | return $this->send('v-suspend-user', $this->userName, 'no'); 155 | } 156 | 157 | /** 158 | * @return mixed 159 | */ 160 | public function unsuspendUser() 161 | { 162 | return $this->send('v-unsuspend-user', $this->userName, 'no'); 163 | } 164 | 165 | /** 166 | * @param $package 167 | * 168 | * @return mixed 169 | */ 170 | public function changePackage($package) 171 | { 172 | return $this->send('v-suspend-user', $this->userName, $package); 173 | } 174 | 175 | /** 176 | * @return mixed 177 | */ 178 | public function listUserPackages() 179 | { 180 | $this->returnCode = 'no'; 181 | $answer = $this->send('v-list-user-packages', 'json'); 182 | $data = json_decode($answer, true); 183 | 184 | return $data; 185 | } 186 | 187 | /** 188 | * @param $option 189 | * 190 | * @return mixed 191 | */ 192 | public function getValue($option) 193 | { 194 | $this->returnCode = 'no'; 195 | 196 | return $this->send('v-get-user-value', $this->userName, $option); 197 | } 198 | 199 | /** 200 | * @param string $ssh 201 | * 202 | * @return mixed 203 | */ 204 | public function changeShell($ssh = 'nologin') 205 | { 206 | return $this->send('v-change-user-shell', $this->userName, $ssh); 207 | } 208 | 209 | /** 210 | * @return mixed 211 | */ 212 | public function adminListUserAccount() 213 | { 214 | $this->returnCode = 'no'; 215 | $answer = $this->send('v-list-user', $this->userName, 'json'); 216 | $data = json_decode($answer, true); 217 | 218 | return $data; 219 | } 220 | 221 | /** 222 | * @return mixed 223 | */ 224 | public function adminListUserPackages() 225 | { 226 | $this->returnCode = 'no'; 227 | $answer = $this->send('v-list-user-packages', 'json'); 228 | $data = json_decode($answer, true); 229 | 230 | return $data; 231 | } 232 | 233 | /** 234 | * @return mixed 235 | */ 236 | public function adminListUserShell() 237 | { 238 | $this->returnCode = 'no'; 239 | $answer = $this->send('v-list-sys-shells', 'json'); 240 | $data = json_decode($answer, true); 241 | 242 | return $data; 243 | } 244 | } 245 | -------------------------------------------------------------------------------- /src/Services/VestaAPI.php: -------------------------------------------------------------------------------- 1 | keysCheck($server, $allServers)) { 59 | throw new \Exception('Specified server config does not contain host or key'); 60 | } 61 | 62 | $this->key = (string) $allServers[$server]['key']; 63 | $this->host = (string) $allServers[$server]['host']; 64 | 65 | return $this; 66 | } 67 | 68 | /** 69 | * @param string $server 70 | * @param array $config 71 | * 72 | * @return bool 73 | */ 74 | private function keysCheck($server, $config) 75 | { 76 | return !isset($config[$server]['key']) || !isset($config[$server]['host']); 77 | } 78 | 79 | /** 80 | * @param string $userName 81 | * 82 | * @throws \Exception 83 | * 84 | * @return $this 85 | */ 86 | public function setUserName($userName = '') 87 | { 88 | if (empty($userName)) { 89 | throw new \Exception('Server is not specified'); 90 | } 91 | $this->userName = $userName; 92 | 93 | return $this; 94 | } 95 | 96 | /** 97 | * @param string $cmd 98 | * 99 | * @throws VestaExceptions 100 | * 101 | * @return string 102 | */ 103 | public function send($cmd) 104 | { 105 | $postVars = [ 106 | 'user' => $this->userName, 107 | 'password' => $this->key, 108 | 'returncode' => $this->returnCode, 109 | 'cmd' => $cmd, 110 | ]; 111 | $args = func_get_args(); 112 | foreach ($args as $num => $arg) { 113 | if ($num === 0) { 114 | continue; 115 | } 116 | $postVars['arg'.$num] = $args[$num]; 117 | } 118 | 119 | $client = new Client([ 120 | 'base_uri' => 'https://'.$this->host.':8083/api/', 121 | 'timeout' => 10.0, 122 | 'verify' => false, 123 | 'form_params' => $postVars, 124 | ]); 125 | 126 | $query = $client->post('index.php') 127 | ->getBody() 128 | ->getContents(); 129 | 130 | if ($this->returnCode == 'yes' && $query != 0) { 131 | throw new VestaExceptions($query); 132 | } 133 | 134 | return $query; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/Services/Web.php: -------------------------------------------------------------------------------- 1 | returnCode = 'no'; 17 | $answer = $this->send('v-list-web-domain', $this->userName, $domain, 'json'); 18 | 19 | $data = json_decode($answer, true); 20 | 21 | $ftpU = strpos($data[$domain]['FTP_USER'], ':'); 22 | $ftpPath = strpos($data[$domain]['FTP_PATH'], ':'); 23 | 24 | if ($ftpU !== false) { 25 | $ftAr = explode(':', $data[$domain]['FTP_USER']); 26 | $data[$domain]['FTP_USER'] = $ftAr; 27 | } 28 | if ($ftpPath !== false) { 29 | $ftpP = explode(':', $data[$domain]['FTP_PATH']); 30 | $data[$domain]['FTP_PATH'] = $ftpP; 31 | } 32 | 33 | return $data; 34 | } 35 | 36 | /** 37 | * List Web Domains. 38 | * 39 | * @return mixed 40 | */ 41 | public function listWebDomain() 42 | { 43 | $this->returnCode = 'no'; 44 | $answer = $this->send('v-list-web-domains', $this->userName, 'json'); 45 | $data = json_decode($answer, true); 46 | 47 | return $data; 48 | } 49 | 50 | /** 51 | * Add Web Domains. 52 | * 53 | * @param $domain 54 | * @param $ip 55 | * 56 | * @return mixed 57 | */ 58 | public function addWebDomain($domain, $ip) 59 | { 60 | return $this->send('v-add-web-domain', $this->userName, $domain, $ip); 61 | } 62 | 63 | /** 64 | * Support DNS. 65 | * 66 | * @param $domain 67 | * @param $ip 68 | * 69 | * @return mixed 70 | */ 71 | public function addDns($domain, $ip) 72 | { 73 | return $this->send('v-add-dns-domain', $this->userName, $domain, $ip); 74 | } 75 | 76 | /** 77 | * Support Mail. 78 | * 79 | * @param $domain 80 | * 81 | * @return mixed 82 | */ 83 | public function addMail($domain) 84 | { 85 | return $this->send('v-add-mail-domain', $this->userName, $domain); 86 | } 87 | 88 | /** 89 | * Add domain aliases. 90 | * 91 | * @param $domain 92 | * @param $alias 93 | */ 94 | public function addWebDomainAlias($domain, $alias) 95 | { 96 | $this->send('v-add-web-domain-alias', $this->userName, $domain, $alias, 'no'); 97 | } 98 | 99 | /** 100 | * Support Alias DNS. 101 | * 102 | * @param $domain 103 | * @param $alias 104 | * 105 | * @return mixed 106 | */ 107 | public function addDnsAlias($domain, $alias) 108 | { 109 | return $this->send('v-add-dns-on-web-alias', $this->userName, $domain, $alias, 'no'); 110 | } 111 | 112 | /** 113 | * Delete www. alias if it wasn't found. 114 | * 115 | * @param $domain 116 | * @param $alias 117 | * 118 | * @return mixed 119 | */ 120 | public function deleteWebDomainAlias($domain, $alias) 121 | { 122 | return $this->send('v-delete-web-domain-alias', $this->userName, $domain, $alias, 'no'); 123 | } 124 | 125 | /** 126 | * Add FTP domain. 127 | * 128 | * @param $domain 129 | * @param $ftpUserName 130 | * @param $ftpPassword 131 | * @param $ftpPath 132 | * 133 | * @return mixed 134 | */ 135 | public function addFtpDomain($domain, $ftpUserName, $ftpPassword, $ftpPath) 136 | { 137 | return $this->send( 138 | 'v-add-web-domain-ftp', 139 | $this->userName, 140 | $domain, 141 | $ftpUserName, 142 | $ftpPassword, 143 | $ftpPath 144 | ); 145 | } 146 | 147 | /** 148 | * Add proxy support. 149 | * 150 | * @param $domain 151 | * @param $ext 152 | * 153 | * @return mixed 154 | */ 155 | public function addDomainProxy($domain, $ext) 156 | { 157 | return $this->send('v-add-web-domain-proxy', $this->userName, $domain, '', $ext, 'no'); 158 | } 159 | 160 | /** 161 | * Delete domain. 162 | * 163 | * @param $domain 164 | * 165 | * @return mixed 166 | */ 167 | public function deleteDomain($domain) 168 | { 169 | return $this->send('v-delete-domain', $this->userName, $domain); 170 | } 171 | 172 | /** 173 | * Chane dns domain IP. 174 | * 175 | * @param $domain 176 | * @param $ip 177 | * 178 | * @return mixed 179 | */ 180 | public function changeWebDomainIp($domain, $ip) 181 | { 182 | return $this->send('v-change-web-domain-ip', $this->userName, $domain, $ip, 'no'); 183 | } 184 | 185 | /** 186 | * Delete web domain. 187 | * 188 | * @param $domain 189 | * @param $ftpUserName 190 | * 191 | * @return mixed 192 | */ 193 | public function deleteWebDomain($domain, $ftpUserName) 194 | { 195 | return $this->send('v-delete-web-domain-ftp', $this->userName, $domain, $ftpUserName); 196 | } 197 | 198 | /** 199 | * Change web domain. 200 | * 201 | * @param $domain 202 | * @param $ftpUserName 203 | * @param $ftpPath 204 | * 205 | * @return mixed 206 | */ 207 | public function changeWebDomain($domain, $ftpUserName, $ftpPath) 208 | { 209 | return $this->send( 210 | 'v-change-web-domain-ftp-path', 211 | $this->userName, 212 | $domain, 213 | $ftpUserName, 214 | $ftpPath 215 | ); 216 | } 217 | 218 | /** 219 | * Change ftp password. 220 | * 221 | * @param $domain 222 | * @param $ftpUserName 223 | * @param $password 224 | * 225 | * @return mixed 226 | */ 227 | public function changeFtpPassword($domain, $ftpUserName, $password) 228 | { 229 | return $this->send( 230 | 'v-change-web-domain-ftp-password', 231 | $this->userName, 232 | $domain, 233 | $ftpUserName, 234 | $password 235 | ); 236 | } 237 | } 238 | --------------------------------------------------------------------------------