| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
- /**
- * test.php
- *
- * contains examples about how to use
- * class methods for Sf_Admin
- *
- * @author André Genrich <andre.genrich@thurdata.ch>
- * @version 1
- * @copyright Copyright (c) Thurdata GmbH 2020
- * @license GPL
- * @name test.php
- */
- /////////////
- // Require //
- /////////////
- require_once('config.php');
- require_once('cwp7/Admin.php');
- //////////
- // Args //
- //////////
- if(PHP_SAPI != 'cli')
- $args = $_GET;
- else
- $args = parse_args($argv);
- if(isset($args['action']))
- {
- $action = $args['action'];
- }
- else
- {
- echo 'No action, exiting' . PHP_EOL;
- exit (-1);
- }
- function parse_args($argv){
- array_shift($argv);
- $out = array();
- foreach ($argv as $arg){
- if (substr($arg,0,2) == '--'){
- $eqPos = strpos($arg,'=');
- if ($eqPos === false){
- $key = substr($arg,2);
- $out[$key] = isset($out[$key]) ? $out[$key] : true;
- } else {
- $key = substr($arg,2,$eqPos-2);
- $out[$key] = substr($arg,$eqPos+1);
- }
- } else if (substr($arg,0,1) == '-'){
- if (substr($arg,2,1) == '='){
- $key = substr($arg,1,1);
- $out[$key] = substr($arg,3);
- } else {
- $chars = str_split(substr($arg,1));
- foreach ($chars as $char){
- $key = $char;
- $out[$key] = isset($out[$key]) ? $out[$key] : true;
- }
- }
- } else {
- $out[] = $arg;
- }
- }
- return $out;
- }
- /////////////////
- // Constructor //
- /////////////////
- $cwp7 = new cwp7_Admin($cwp7Host, $cwp7Token);
- $r = $cwp7->constructorSuccess();
- if(isset($r['error_msg'])) {
- echo 'Error : cannot construct :-(' . PHP_EOL;
- print_r($r);
- exit();
- }
- /////////////
- // Actions //
- /////////////
- if($action == 'gaa')
- {
- $r = $cwp7->getAllAccounts();
- if($r['status'] == 'Error') {
- echo 'Error : could not fetch list of accounts on '. $cwp7Host . ' :-(' . PHP_EOL;
- } else {
- echo 'OK : got a list of '. count($r['msj']) . ' accounts on ' . $cwp7Host . ' :-)' . PHP_EOL;
- }
- print_r($r);
- }
- // Get Account Informations
- if($action == 'gai')
- {
- $r = $cwp7->getAccount($args['account_name']);
- if($r['status'] == 'Error') {
- echo 'Error : could not fetch information of '. $args['account_name'] . ' :-(' . PHP_EOL;
- } else {
- echo 'OK : got the infos for account ' . $args['account_name'] . ' :-)' . PHP_EOL;
- }
- print_r($r);
- }
- // Get all Packages
- if($action == 'gap')
- {
- $r = $cwp7->getPackages();
- if($r['status'] == 'Error') {
- echo 'Error : could not fetch information of packages :-(' . PHP_EOL;
- } else {
- echo 'OK : got the infos of ' . count($r['msj']) . ' packages :-)' . PHP_EOL;
- }
- print_r($r);
- }
- // Get Quota Informations
- if($action == 'gqu')
- {
- $r = $cwp7->getQuota($args['account_name']);
- if($r['status'] == 'Error') {
- echo 'Error : could not fetch quota information of '. $args['account_name'] . ' :-(' . PHP_EOL;
- } else {
- echo 'OK : got the quota infos for account ' . $args['account_name'] . ' :-)' . PHP_EOL;
- }
- print_r($r);
- }
- // Get AutoSSL Informations
- if($action == 'gas')
- {
- $r = $cwp7->getAutoSSL($args['account_name']);
- if($r['status'] == 'Error') {
- echo 'Error : could not fetch AutoSSL information of '. $args['account_name'] . ' :-(' . PHP_EOL;
- } else {
- echo 'OK : got the AutoSSL infos for account ' . $args['account_name'] . ' :-)' . PHP_EOL;
- }
- print_r($r);
- }
|