test.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * test.php
  4. *
  5. * contains examples about how to use
  6. * class methods for Sf_Admin
  7. *
  8. * @author André Genrich <andre.genrich@thurdata.ch>
  9. * @version 1
  10. * @copyright Copyright (c) Thurdata GmbH 2020
  11. * @license GPL
  12. * @name test.php
  13. */
  14. /////////////
  15. // Require //
  16. /////////////
  17. require_once('config.php');
  18. require_once('cwp7/Admin.php');
  19. //////////
  20. // Args //
  21. //////////
  22. if(PHP_SAPI != 'cli')
  23. $args = $_GET;
  24. else
  25. $args = parse_args($argv);
  26. if(isset($args['action']))
  27. {
  28. $action = $args['action'];
  29. }
  30. else
  31. {
  32. echo 'No action, exiting' . PHP_EOL;
  33. exit (-1);
  34. }
  35. function parse_args($argv){
  36. array_shift($argv);
  37. $out = array();
  38. foreach ($argv as $arg){
  39. if (substr($arg,0,2) == '--'){
  40. $eqPos = strpos($arg,'=');
  41. if ($eqPos === false){
  42. $key = substr($arg,2);
  43. $out[$key] = isset($out[$key]) ? $out[$key] : true;
  44. } else {
  45. $key = substr($arg,2,$eqPos-2);
  46. $out[$key] = substr($arg,$eqPos+1);
  47. }
  48. } else if (substr($arg,0,1) == '-'){
  49. if (substr($arg,2,1) == '='){
  50. $key = substr($arg,1,1);
  51. $out[$key] = substr($arg,3);
  52. } else {
  53. $chars = str_split(substr($arg,1));
  54. foreach ($chars as $char){
  55. $key = $char;
  56. $out[$key] = isset($out[$key]) ? $out[$key] : true;
  57. }
  58. }
  59. } else {
  60. $out[] = $arg;
  61. }
  62. }
  63. return $out;
  64. }
  65. /////////////////
  66. // Constructor //
  67. /////////////////
  68. $cwp7 = new cwp7_Admin($cwp7Host, $cwp7Token);
  69. $r = $cwp7->constructorSuccess();
  70. if(isset($r['error_msg'])) {
  71. echo 'Error : cannot construct :-(' . PHP_EOL;
  72. print_r($r);
  73. exit();
  74. }
  75. /////////////
  76. // Actions //
  77. /////////////
  78. if($action == 'gaa')
  79. {
  80. $r = $cwp7->getAllAccounts();
  81. if($r['status'] == 'Error') {
  82. echo 'Error : could not fetch list of accounts on '. $cwp7Host . ' :-(' . PHP_EOL;
  83. } else {
  84. echo 'OK : got a list of '. count($r['msj']) . ' accounts on ' . $cwp7Host . ' :-)' . PHP_EOL;
  85. }
  86. print_r($r);
  87. }
  88. // Get Account Informations
  89. if($action == 'gai')
  90. {
  91. $r = $cwp7->getAccount($args['account_name']);
  92. if($r['status'] == 'Error') {
  93. echo 'Error : could not fetch information of '. $args['account_name'] . ' :-(' . PHP_EOL;
  94. } else {
  95. echo 'OK : got the infos for account ' . $args['account_name'] . ' :-)' . PHP_EOL;
  96. }
  97. print_r($r);
  98. }
  99. // Get all Packages
  100. if($action == 'gap')
  101. {
  102. $r = $cwp7->getPackages();
  103. if($r['status'] == 'Error') {
  104. echo 'Error : could not fetch information of packages :-(' . PHP_EOL;
  105. } else {
  106. echo 'OK : got the infos of ' . count($r['msj']) . ' packages :-)' . PHP_EOL;
  107. }
  108. print_r($r);
  109. }
  110. // Get Quota Informations
  111. if($action == 'gqu')
  112. {
  113. $r = $cwp7->getQuota($args['account_name']);
  114. if($r['status'] == 'Error') {
  115. echo 'Error : could not fetch quota information of '. $args['account_name'] . ' :-(' . PHP_EOL;
  116. } else {
  117. echo 'OK : got the quota infos for account ' . $args['account_name'] . ' :-)' . PHP_EOL;
  118. }
  119. print_r($r);
  120. }
  121. // Get AutoSSL Informations
  122. if($action == 'gas')
  123. {
  124. $r = $cwp7->getAutoSSL($args['account_name']);
  125. if($r['status'] == 'Error') {
  126. echo 'Error : could not fetch AutoSSL information of '. $args['account_name'] . ' :-(' . PHP_EOL;
  127. } else {
  128. echo 'OK : got the AutoSSL infos for account ' . $args['account_name'] . ' :-)' . PHP_EOL;
  129. }
  130. print_r($r);
  131. }