| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?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;
- }
- ///////////
- // Login //
- ///////////
- $cwp7 = new cwp7_Admin($cwp7URL, $cwp7AdminEmail, $cwp7AdminPassword);
- $r = $cwp7->login();
- if(isset($r['error_msg'])) {
- echo 'Error : cannot login to ' . $cwp7URL . ' :-(' . PHP_EOL;
- print_r($r);
- exit();
- }
- /////////////
- // Actions //
- /////////////
- // nop
- if($action == 'nop')
- {
- echo 'OK : login success, no further operation :-)' . PHP_EOL;
- exit;
- }
- // Get All Accounts
- if($action == 'gaa')
- {
- $r = $sf->getAllAccounts();
- if(isset($r['error_msg'])) {
- echo 'Error : could not fetch list of accounts for '. $seafileURL . ' :-(' . PHP_EOL;
- print_r($r);
- } else {
- echo 'OK : got a list of '. $r['total_count'] . ' accounts for ' . $seafileURL . ' :-)' . PHP_EOL;
- }
- }
- // Get Account Informations
- if($action == 'gai')
- {
- $r = $sf->getAccount($args['account_name']);
- if(isset($r['error_msg'])) {
- echo 'Error : could not fetch information of '. $args['account_name'] . ' :-(' . PHP_EOL;
- print_r($r);
- } else {
- echo 'OK : got the infos for account ' . $args['account_name'] . ' :-)' . PHP_EOL;
- }
- }
- // Create Account
- if($action == 'ca')
- {
- $attrs = array('email'=> $args['account_name'], 'password'=> $args['password']);
- $r = $sf->createAccount($attrs);
- if(isset($r['error_msg'])) {
- echo 'Error : cannot create account ' . $args['account_name'] . ' :-(' . PHP_EOL;
- print_r($r);
- } else {
- echo 'OK : account ' . $args['account_name'] . ' created :-)' . PHP_EOL;
- }
- }
- // Modify Account
- if($action == 'moa')
- {
- $attrs = array('email'=> $args['account_name'], 'quota_total' => $args['quota_total']);
- $r = $sf->modifyAccount($attrs);
- if(isset($r['error_msg'])) {
- echo 'Error : cannot modify account ' . $args['account_name'] . ' :-(' . PHP_EOL;
- print_r($r);
- } else {
- echo 'OK : modify account ' . $args['account_name'] . ' :-)' . PHP_EOL;
- print_r($r);
- }
- }
- // Migrate Account
- if($action == 'mia')
- {
- $r = $sf->migrateAccount($args['account_name'], $args['new_account_name']);
- if(isset($r['error_msg'])) {
- echo 'Error : account ' . $args['account_name'] . ' not migrated to ' . $args['new_account_name'] . ' :-(' . PHP_EOL;
- print_r($r);
- } else {
- echo 'OK : account ' . $args['account_name'] . ' migrated to ' . $args['new_account_name'] . ' :-)' . PHP_EOL;
- }
- }
- // Delete Account
- if($action == 'da')
- {
- $r = $sf->deleteAccount($args['account_name']);
- if(isset($r['error_msg'])) {
- echo 'Error : account ' . $args['account_name'] . ' not deleted :-(' . PHP_EOL;
- print_r($r);
- } else {
- echo 'OK : account ' . $args['account_name'] . ' deleted :-)' . PHP_EOL;
- }
- }
|