Вход Регистрация
»

Название : Класс для работы с API панели Vesta CP


» Описание: Простой класс для работы с API бесплатной панели управления веб-хостингом - Vesta CP.
Коды ответов API можете посмотреть тут: https://vestacp.com/docs/api/#return_codes
» Добавил: * UndeX
» Время добавления: 7 Сент 2016 в 09:21
» Посмотров: 1002
» textarea
» Рейтинг: [+1 | -1]
Комментарии [1]
  1. class VestaApi {
  2.  
  3. public $vst_host;
  4. public $vst_user;
  5. public $vst_pass;
  6.  
  7. function __construct($vst_host, $vst_user, $vst_pass){
  8. $this->host = $vst_host;
  9. $this->user = $vst_user;
  10. $this->pass = $vst_pass;
  11. }
  12.  
  13. function add_user($login, $password, $email, $package, $first_name, $last_name, $returncode = 'yes'){
  14. $command = 'v-add-user';
  15. $postvars = array(
  16. 'user' => $this->user,
  17. 'password' => $this->pass,
  18. 'returncode' => $returncode,
  19. 'cmd' => $command,
  20. 'arg1' => $login,
  21. 'arg2' => $password,
  22. 'arg3' => $email,
  23. 'arg4' => $package,
  24. 'arg5' => $fist_name,
  25. 'arg6' => $last_name
  26. );
  27. $postdata = http_build_query($postvars);
  28.  
  29. // Send POST query via cURL
  30. $postdata = http_build_query($postvars);
  31. $curl = curl_init();
  32. curl_setopt($curl, CURLOPT_URL, 'https://' . $this->host . ':8083/api/');
  33. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  34. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  35. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  36. curl_setopt($curl, CURLOPT_POST, true);
  37. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  38. $answer = curl_exec($curl);
  39.  
  40. return $answer;
  41. }
  42.  
  43. function add_domain($username, $domain, $returncode = 'yes'){
  44. $command = 'v-add-domain';
  45. // Prepare POST query
  46. $postvars = array(
  47. 'user' => $this->user,
  48. 'password' => $this->pass,
  49. 'returncode' => $returncode,
  50. 'cmd' => $command,
  51. 'arg1' => $username,
  52. 'arg2' => $domain
  53. );
  54. $postdata = http_build_query($postvars);
  55.  
  56. // Send POST query via cURL
  57. $postdata = http_build_query($postvars);
  58. $curl = curl_init();
  59. curl_setopt($curl, CURLOPT_URL, 'https://' . $this->host . ':8083/api/');
  60. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  61. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  62. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  63. curl_setopt($curl, CURLOPT_POST, true);
  64. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  65. $answer = curl_exec($curl);
  66.  
  67. return $answer;
  68. }
  69.  
  70. function add_database($username, $db_name, $db_user, $db_pass, $returncode = 'yes'){
  71. $command = 'v-add-database';
  72. // Prepare POST query
  73. $postvars = array(
  74. 'user' => $this->user,
  75. 'password' => $this->pass,
  76. 'returncode' => $returncode,
  77. 'cmd' => $command,
  78. 'arg1' => $username,
  79. 'arg2' => $db_name,
  80. 'arg3' => $db_user,
  81. 'arg4' => $db_pass
  82. );
  83. $postdata = http_build_query($postvars);
  84.  
  85. // Send POST query via cURL
  86. $curl = curl_init();
  87. curl_setopt($curl, CURLOPT_URL, 'https://' . $this->host . ':8083/api/');
  88. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  89. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  90. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  91. curl_setopt($curl, CURLOPT_POST, true);
  92. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  93. $answer = curl_exec($curl);
  94.  
  95. return $answer;
  96. }
  97.  
  98. function user_info($username, $format = 'json'){
  99. $command = 'v-list-user';
  100. // Prepare POST query
  101. $postvars = array(
  102. 'user' => $this->user,
  103. 'password' => $this->pass,
  104. 'cmd' => $command,
  105. 'arg1' => $username,
  106. 'arg2' => $format
  107. );
  108. $postdata = http_build_query($postvars);
  109.  
  110. // Send POST query via cURL
  111. $postdata = http_build_query($postvars);
  112. $curl = curl_init();
  113. curl_setopt($curl, CURLOPT_URL, 'https://' . $this->host . ':8083/api/');
  114. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  115. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  116. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  117. curl_setopt($curl, CURLOPT_POST, true);
  118. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  119. $answer = curl_exec($curl);
  120.  
  121. return $answer;
  122. }
  123.  
  124. function list_users($format = 'json'){
  125. $command = 'v-list-users';
  126. // Prepare POST query
  127. $postvars = array(
  128. 'user' => $this->user,
  129. 'password' => $this->pass,
  130. 'cmd' => $command,
  131. 'arg1' => $format
  132. );
  133. $postdata = http_build_query($postvars);
  134.  
  135. // Send POST query via cURL
  136. $postdata = http_build_query($postvars);
  137. $curl = curl_init();
  138. curl_setopt($curl, CURLOPT_URL, 'https://' . $this->host . ':8083/api/');
  139. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  140. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  141. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  142. curl_setopt($curl, CURLOPT_POST, true);
  143. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  144. $answer = curl_exec($curl);
  145.  
  146. return $answer;
  147. }
  148.  
  149. function user_domain_info($username, $domain, $format = 'json'){
  150. $command = 'v-list-web-domain';
  151. // Prepare POST query
  152. $postvars = array(
  153. 'user' => $this->user,
  154. 'password' => $this->pass,
  155. 'cmd' => $command,
  156. 'arg1' => $username,
  157. 'arg2' => $domain,
  158. 'arg3' => $format
  159. );
  160. $postdata = http_build_query($postvars);
  161.  
  162. // Send POST query via cURL
  163. $postdata = http_build_query($postvars);
  164. $curl = curl_init();
  165. curl_setopt($curl, CURLOPT_URL, 'https://' . $this->host . ':8083/api/');
  166. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  167. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  168. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  169. curl_setopt($curl, CURLOPT_POST, true);
  170. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  171. $answer = curl_exec($curl);
  172.  
  173. return $answer;
  174. }
  175.  
  176. function list_user_domains($username, $format = 'json'){
  177. $command = 'v-list-web-domains';
  178. // Prepare POST query
  179. $postvars = array(
  180. 'user' => $this->user,
  181. 'password' => $this->pass,
  182. 'cmd' => $command,
  183. 'arg1' => $username,
  184. 'arg2' => $format
  185. );
  186. $postdata = http_build_query($postvars);
  187.  
  188. // Send POST query via cURL
  189. $postdata = http_build_query($postvars);
  190. $curl = curl_init();
  191. curl_setopt($curl, CURLOPT_URL, 'https://' . $this->host . ':8083/api/');
  192. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  193. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  194. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  195. curl_setopt($curl, CURLOPT_POST, true);
  196. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  197. $answer = curl_exec($curl);
  198.  
  199. return $answer;
  200. }
  201.  
  202. function del_user($username, $returncode = 'yes'){
  203. $command = 'v-delete-user';
  204. // Prepare POST query
  205. $postvars = array(
  206. 'user' => $this->user,
  207. 'password' => $this->pass,
  208. 'returncode' => $returncode,
  209. 'cmd' => $command,
  210. 'arg1' => $username
  211. );
  212. $postdata = http_build_query($postvars);
  213.  
  214. // Send POST query via cURL
  215. $postdata = http_build_query($postvars);
  216. $curl = curl_init();
  217. curl_setopt($curl, CURLOPT_URL, 'https://' . $this->host . ':8083/api/');
  218. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  219. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  220. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  221. curl_setopt($curl, CURLOPT_POST, true);
  222. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  223. $answer = curl_exec($curl);
  224.  
  225. return $answer;
  226. }
  227.  
  228. function auth($login, $password, $returncode = 'yes'){
  229. $command = 'v-check-user-password';
  230. // Prepare POST query
  231. $postvars = array(
  232. 'user' => $this->user,
  233. 'password' => $this->pass,
  234. 'cmd' => $command,
  235. 'arg1' => $username,
  236. 'arg2' => $password
  237. );
  238. $postdata = http_build_query($postvars);
  239.  
  240. // Send POST query via cURL
  241. $postdata = http_build_query($postvars);
  242. $curl = curl_init();
  243. curl_setopt($curl, CURLOPT_URL, 'https://' . $this->host . ':8083/api/');
  244. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  245. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  246. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  247. curl_setopt($curl, CURLOPT_POST, true);
  248. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  249. $answer = curl_exec($curl);
  250.  
  251. return $answer;
  252. }
  253.  
  254. function cmd($postvars){
  255. // Send POST query via cURL
  256. $postdata = http_build_query($postvars);
  257. $curl = curl_init();
  258. curl_setopt($curl, CURLOPT_URL, 'https://' . $this->host . ':8083/api/');
  259. curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
  260. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  261. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  262. curl_setopt($curl, CURLOPT_POST, true);
  263. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  264. $answer = curl_exec($curl);
  265.  
  266. return $answer;
  267. }
  268. }
  269. ?>
Онлайн: 5
Реклама