* @version 1 * @copyright Copyright (c) Thurdata GmbH 2020 * @license GPL * @name test.php */ ///////////// // Require // ///////////// require_once('config.php'); require_once('Sf/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 // /////////// $sf = new Sf_Admin($seafileURL, $seafileAdminEmail, $seafileAdminPassword); $r = $sf->login(); if(isset($r['error_msg'])) { echo 'Error : cannot login to ' . $seafileURL . ' :-(' . 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; } }