andre 3 жил өмнө
parent
commit
3b8dbe7abb
3 өөрчлөгдсөн 349 нэмэгдсэн , 338 устгасан
  1. 0 334
      api/Sf/Admin.php
  2. 345 0
      api/cwp7/Admin.php
  3. 4 4
      api/test.php

+ 0 - 334
api/Sf/Admin.php

@@ -1,334 +0,0 @@
-<?php
-/**
- * Sf_Admin
- *
- * @author André Genrich <andre.genrich@thurdata.ch>
- * @author Roland Käser <roland.keaser@thurdata.ch>
- * @version 0.9
- * @copyright Copyright (c) 2021, Thurdata
- * @example ../test.php
- */
-/**
- * Sf_Admin class documentation
- */
-/**
- * Sf_Admin is a class which allows to manage CWP accounts via web-api/v2.1-admin
- *
- * You may create, modify, migrate, delete and get the attributes of a CWP account using this class
- *
- * For the usage examples of all class methods check the source code of test.php
- */
-class Sf_Admin {
-    private $loginSuccess;
-    private $constructorSuccess;
-    private $sfURL;
-    private $sfConType;
-    private $sfPort;
-    private $sfSecure;
-    private $sfAdminName;
-    private $sfPassword;
-    protected $sfToken;
-	/**
-	 * Constructor
-         * @param string $CWPURL CWP URL (example: https://CWP.my.lan)
-	 * @param string $username admin/user account's e-mail
-	 * @param string $password admin/user account's password
-	 * @param string $secure optional false to force unsecure (default true)
-	 */
-    function __construct($CWPURL, $username, $password, $secure=true) {
-        if(!in_array('curl', get_loaded_extensions())) {
-            $this->constructorSuccess = false;
-            return array('error_msg' => 'Error: PHP curl extension not available');
-        }
-        if (empty($CWPURL) || empty($username) || empty($password)) {
-            $this->constructorSuccess = false;
-            return array('error_msg' => 'Error: Server login info missing, check server configuration');
-        }
-        if(preg_match('/^https/', $CWPURL)) {
-            $this->sfConType = 'https://';
-            if($secure) {
-                $this->sfSecure = true;
-            } else {
-                $this->sfSecure = false;
-            }
-        }else {
-            $this->sfConType = 'http://';
-            $this->sfSecure = false;
-        }
-        $sfHostname = str_replace(array('http://', 'https://'), array('',''), $CWPURL);
-        $sfHostname = explode(':', $sfHostname);
-        if (gethostbyname($sfHostname[0]) == $sfHostname[0] && !filter_var($sfHostname[0], FILTER_VALIDATE_IP)) {
-            $this->constructorSuccess = false;
-            return array('error_msg' => 'Error: Cannot resolve ' . $sfHostname[0] . ', check server configuration');
-        }
-        $this->sfPort = ($sfHostname[1]) ? $sfHostname[1] :  '8000';
-        $this->sfURL = $this->sfConType . $sfHostname[0] . ':' . $this->sfPort;
-        $this->sfAdminName = $username;
-        $this->sfPassword = $password;
-        $this->sfToken = null;
-        $this->constructorSuccess = true;
-    }
-
-    public function constructorSuccess() {
-        return $this->constructorSuccess;
-    }
-	/**
-	 * login
-	 * 
-	 * fetch and set CWP lofin token
-	 * @return array error or true
-	 */
-    public function login() {
-        if (!$this->constructorSuccess()) {
-                return array('error_msg' => 'Error: construct failed, something missing');
-        }
-        $sfClient = curl_init();
-        
-        curl_setopt($sfClient, CURLOPT_URL, $this->sfURL . '/api2/auth-token/');
-        curl_setopt($sfClient, CURLOPT_CONNECTTIMEOUT, '30');
-        curl_setopt($sfClient, CURLOPT_POST, true);
-        curl_setopt($sfClient, CURLOPT_FOLLOWLOCATION, true);
-        curl_setopt($sfClient, CURLOPT_RETURNTRANSFER, true);
-        curl_setopt($sfClient, CURLOPT_POSTFIELDS, array('username' => $this->sfAdminName, 'password' => $this->sfPassword));
-        if(!$this->sfSecure) {
-            curl_setopt($sfClient, CURLOPT_SSL_VERIFYPEER, false);
-            curl_setopt($sfClient, CURLOPT_SSL_VERIFYHOST, false);
-        }
-        curl_setopt($sfClient, CURLOPT_HEADER, false);
-        $authResponse = curl_exec($sfClient);
-        $responseCode = curl_getinfo($sfClient, CURLINFO_RESPONSE_CODE);
-        if($responseCode != 200) {
-            curl_close($sfClient);
-            unset($sfClient);
-            return array('error_msg' => $authResponse, 'response_code' => $responseCode);
-        };
-        curl_close($sfClient);
-        unset($sfClient);
-        
-        $authResponseData = json_decode($authResponse, true);
-        if (!$authResponseData['token']) {
-                $this->loginSuccess = false;
-                error_log(print_r($authResponseData,true));
-                return array('error_msg' => $authResponse);
-        } else {
-                $this->sfToken = $authResponseData['token'];
-                $this->loginSuccess = true;
-                return true;
-        }
-    }
-	/**
-	 * loginSuccess
-	 * 
-	 * @return bool
-	 */
-    public function loginSuccess() {
-        return $this->loginSuccess;
-    }
-	/**
-	 * getAllAccounts
-	 * 
-	 * @return array of CWP accounts array of informations or error message
-	 */
-    public function getAllAccounts() {
-        if (!$this->loginSuccess()) {
-            return array('error_msg' => 'Error: not authenticated');
-        }
-        $sfClient = curl_init();
-        curl_setopt($sfClient, CURLOPT_URL, $this->sfURL . '/api/v2.1/admin/users/');
-        curl_setopt($sfClient, CURLOPT_CONNECTTIMEOUT, '30');
-        curl_setopt($sfClient, CURLOPT_FOLLOWLOCATION, true);
-        curl_setopt($sfClient, CURLOPT_RETURNTRANSFER, true);
-        if(!$this->sfSecure) {
-            curl_setopt($sfClient, CURLOPT_SSL_VERIFYPEER, false);
-            curl_setopt($sfClient, CURLOPT_SSL_VERIFYHOST, false);
-        }
-        curl_setopt($sfClient, CURLOPT_HTTPHEADER, array( 'Authorization: Token ' . $this->sfToken, 'Accept: application/json; charset=utf-8; indent=4'));
-        $response = curl_exec($sfClient);
-        if(curl_getinfo($sfClient, CURLINFO_RESPONSE_CODE) != 200) {
-            curl_close($sfClient);
-            return array('error_msg' => $response);
-        };
-        curl_close($sfClient);
-        return json_decode($response, true);
-    }
-	/**
-	 * getAccount
-	 * 
-	 * @param string $email login e-mail
-	 * 
-	 * @return array of account informations or error message
-	 */
-    public function getAccount($email) {
-        if (!$this->loginSuccess()) {
-            return array('error_msg' => 'Error: not authenticated');
-        }
-        $sfClient = curl_init();
-        curl_setopt($sfClient, CURLOPT_URL, $this->sfURL . '/api/v2.1/admin/users/' . $email . '/');
-        curl_setopt($sfClient, CURLOPT_CONNECTTIMEOUT, '30');
-        curl_setopt($sfClient, CURLOPT_FOLLOWLOCATION, true);
-        curl_setopt($sfClient, CURLOPT_RETURNTRANSFER, true);
-        if(!$this->sfSecure) {
-            curl_setopt($sfClient, CURLOPT_SSL_VERIFYPEER, false);
-            curl_setopt($sfClient, CURLOPT_SSL_VERIFYHOST, false);
-        }
-        curl_setopt($sfClient, CURLOPT_HTTPHEADER, array( 'Authorization: Token ' . $this->sfToken, 'Accept: application/json; charset=utf-8; indent=4'));
-        $response = curl_exec($sfClient);
-        if(curl_getinfo($sfClient, CURLINFO_RESPONSE_CODE) != 200) {
-            curl_close($sfClient);
-            return array('error_msg' => $response);
-        };
-        curl_close($sfClient);
-        return json_decode($response, true);
-	}
-	/**
-	 * getAccount
-	 * 
-	 * @param array $params avvount informations, email required.
-     * 
-	 * @see https://download.CWP.com/published/web-api/v2.1-admin/accounts.md#user-content-Add%20User
-     * 
-	 * @return array of account informations or error message
-	 */
-    public function createAccount($params) {
-        if (!$this->loginSuccess()) {
-            return array('error_msg' => 'Error: not authenticated');
-        }
-        if(!isset($params['email'])) {
-            return array('error_msg' => 'Error: missing parameter email');
-        }
-        $sfClient = curl_init();
-        curl_setopt($sfClient, CURLOPT_URL, $this->sfURL . '/api/v2.1/admin/users/');
-        curl_setopt($sfClient, CURLOPT_CONNECTTIMEOUT, '30');
-        curl_setopt($sfClient, CURLOPT_FOLLOWLOCATION, true);
-        curl_setopt($sfClient, CURLOPT_RETURNTRANSFER, true);
-        if(!$this->sfSecure) {
-            curl_setopt($sfClient, CURLOPT_SSL_VERIFYPEER, false);
-            curl_setopt($sfClient, CURLOPT_SSL_VERIFYHOST, false);
-        }
-        curl_setopt($sfClient, CURLOPT_HTTPHEADER, array( 'Authorization: Token ' . $this->sfToken, 'Accept: application/json; charset=utf-8; indent=4'));
-		curl_setopt($sfClient, CURLOPT_POST, 1);
-		curl_setopt($sfClient, CURLOPT_POSTFIELDS, $params);
-        $response = curl_exec($sfClient);
-        if(curl_getinfo($sfClient, CURLINFO_RESPONSE_CODE) != 200) {
-            curl_close($sfClient);
-            return array('error_msg' => $response);
-        };
-        curl_close($sfClient);
-        return json_decode($response, true);
-	}
-	/**
-	 * modifyAccount
-	 * 
-	 * @param array $params avvount informations, email required.
-     * 
-	 * @see https://download.CWP.com/published/web-api/v2.1-admin/accounts.md#user-content-Add%20User
-     * 
-	 * @return array of account informations or error message
-	 */
-    public function modifyAccount($params) {
-        if (!$this->loginSuccess()) {
-            return array('error_msg' => 'Error: not authenticated');
-        }
-        if(!isset($params['email'])) {
-            return array('error_msg' => 'Error: missing parameter email');
-        }
-        $account = $params['email'];
-        unset($params['email']);
-        $sfClient = curl_init();
-        curl_setopt($sfClient, CURLOPT_URL, $this->sfURL . '/api/v2.1/admin/users/' . $account . '/');
-		curl_setopt($sfClient, CURLOPT_CUSTOMREQUEST, 'PUT');
-        curl_setopt($sfClient, CURLOPT_CONNECTTIMEOUT, '30');
-        curl_setopt($sfClient, CURLOPT_FOLLOWLOCATION, true);
-        curl_setopt($sfClient, CURLOPT_RETURNTRANSFER, true);
-        if(!$this->sfSecure) {
-            curl_setopt($sfClient, CURLOPT_SSL_VERIFYPEER, false);
-            curl_setopt($sfClient, CURLOPT_SSL_VERIFYHOST, false);
-        }
-        curl_setopt($sfClient, CURLOPT_HTTPHEADER, array( 'Authorization: Token ' . $this->sfToken, 'Accept: application/json; charset=utf-8; indent=4'));
-		curl_setopt($sfClient, CURLOPT_POST, 1);
-		curl_setopt($sfClient, CURLOPT_POSTFIELDS, $params);
-        $response = curl_exec($sfClient);
-        if(curl_getinfo($sfClient, CURLINFO_RESPONSE_CODE) != 200) {
-            curl_close($sfClient);
-            return array('error_msg' => $response);
-        };
-        curl_close($sfClient);
-        return json_decode($response, true);
-	}
-	/**
-	 * deleteAccount
-	 * 
-	 * @param string $email login e-mail
-	 * 
-	 * @return array success => true or error message
-	 */
-    public function deleteAccount($email)
-	{
-        if (!$this->loginSuccess()) {
-            return array('error_msg' => 'Error: not authenticated');
-        }
-        if(!isset($email)) {
-            return array('error_msg' => 'Error: missing parameter email');
-        }
-        $sfClient = curl_init();
-        curl_setopt($sfClient, CURLOPT_URL, $this->sfURL . '/api/v2.1/admin/users/' . $email . '/');
-		curl_setopt($sfClient, CURLOPT_CUSTOMREQUEST, 'DELETE');
-        curl_setopt($sfClient, CURLOPT_CONNECTTIMEOUT, '30');
-        curl_setopt($sfClient, CURLOPT_FOLLOWLOCATION, true);
-        curl_setopt($sfClient, CURLOPT_RETURNTRANSFER, true);
-        if(!$this->sfSecure) {
-            curl_setopt($sfClient, CURLOPT_SSL_VERIFYPEER, false);
-            curl_setopt($sfClient, CURLOPT_SSL_VERIFYHOST, false);
-        }
-        curl_setopt($sfClient, CURLOPT_HTTPHEADER, array( 'Authorization: Token ' . $this->sfToken, 'Accept: application/json; charset=utf-8; indent=4'));
-        $response = curl_exec($sfClient);
-        if(curl_getinfo($sfClient, CURLINFO_RESPONSE_CODE) != 200) {
-            curl_close($sfClient);
-            return array('error_msg' => $response);
-        };
-        curl_close($sfClient);
-        return json_decode($response, true);
-	}
-	/**
-	 * migrateAccount
-	 * 
-	 * @param string $from source account login e-mail
-	 * @param string $to destination account login e-mail (must exist)
-	 * 
-	 * @return array success => true or error message
-	 */
-    public function migrateAccount($from, $to)
-	{
-        if (!$this->loginSuccess()) {
-            return array('error_msg' => 'Error: not authenticated');
-        }
-        if(!isset($from)) {
-            return array('error_msg' => 'Error: missing parameter from');
-        }
-        if(!isset($to)) {
-            return array('error_msg' => 'Error: missing parameter to');
-        }
-        $postFields = array();
-        $postFields['op'] = 'migrate';
-        $postFields['to_user'] = $to;
-        $sfClient = curl_init();
-        curl_setopt($sfClient, CURLOPT_URL, $this->sfURL . '/api2/accounts/' . $from . '/');
-        curl_setopt($sfClient, CURLOPT_CONNECTTIMEOUT, '30');
-        curl_setopt($sfClient, CURLOPT_FOLLOWLOCATION, true);
-        curl_setopt($sfClient, CURLOPT_RETURNTRANSFER, true);
-        if(!$this->sfSecure) {
-            curl_setopt($sfClient, CURLOPT_SSL_VERIFYPEER, false);
-            curl_setopt($sfClient, CURLOPT_SSL_VERIFYHOST, false);
-        }
-        curl_setopt($sfClient, CURLOPT_HTTPHEADER, array( 'Authorization: Token ' . $this->sfToken, 'Accept: application/json; charset=utf-8; indent=4'));
-        curl_setopt($sfClient, CURLOPT_POST, 1);
-		curl_setopt($sfClient, CURLOPT_POSTFIELDS, $postFields);
-        $response = curl_exec($sfClient);
-        if(curl_getinfo($sfClient, CURLINFO_RESPONSE_CODE) != 200) {
-            curl_close($sfClient);
-            return array('error_msg' => $response);
-        };
-        curl_close($sfClient);
-        return json_decode($response, true);
-	}
-}

+ 345 - 0
api/cwp7/Admin.php

@@ -0,0 +1,345 @@
+<?php
+/**
+ * cwp7_Admin
+ *
+ * @author André Genrich <andre.genrich@thurdata.ch>
+ * @author Roland Käser <roland.keaser@thurdata.ch>
+ * @version 0.9
+ * @copyright Copyright (c) 2021, Thurdata
+ * @example ../test.php
+ */
+/**
+ * cwp7_Admin class documentation
+ */
+/**
+ * cwp7_Admin is a class which allows to manage cwp7 accounts via web-api
+ *
+ * You may create, modify, migrate, delete and get the attributes of a cwp7 account using this class
+ *
+ * For the usage examples of all class methods check the source code of test.php
+ */
+class cwp7_Admin {
+    private $constructorSuccess;
+    private $cwp7URL;
+    private $cwp7ConType;
+    private $cwp7Port;
+    private $cwp7Secure;
+    protected $cwp7Token;
+	/**
+	 * Constructor
+     * @param string $cwp7URL cwp7 URL (example: https://cwp7.my.lan)
+	 * @param string $username admin/user account's name
+	 * @param string $token api token
+	 * @param string $secure optional false to force unsecure (default true)
+	 */
+    function __construct($cwp7URL, $token, $secure=true) {
+        if(!in_array('curl', get_loaded_extensions())) {
+            $this->constructorSuccess = false;
+            return array('error_msg' => 'Error: PHP curl extension not available');
+        }
+        if (empty($cwp7URL) || empty($token)) {
+            $this->constructorSuccess = false;
+            return array('error_msg' => 'Error: Server login info missing, check server configuration');
+        }
+        if(preg_match('/^https/', $cwp7URL)) {
+            $this->cwp7ConType = 'https://';
+            if($secure) {
+                $this->cwp7Secure = true;
+            } else {
+                $this->cwp7Secure = false;
+            }
+        } else {
+            $this->cwp7ConType = 'http://';
+            $this->cwp7Secure = false;
+        }
+        $cwp7Hostname = str_replace(array('http://', 'https://'), array('',''), $cwp7URL);
+        $cwp7Hostname = explode(':', $cwp7Hostname);
+        if (gethostbyname($cwp7Hostname[0]) == $cwp7Hostname[0] && !filter_var($cwp7Hostname[0], FILTER_VALIDATE_IP)) {
+            $this->constructorSuccess = false;
+            return array('error_msg' => 'Error: Cannot resolve ' . $cwp7Hostname[0] . ', check server configuration');
+        }
+        $this->cwp7Port = ($cwp7Hostname[1]) ? $cwp7Hostname[1] :  '2304';
+        $this->cwp7URL = $this->cwp7ConType . $cwp7Hostname[0] . ':' . $this->cwp7Port;
+        $this->cwp7Token = $token;
+        $this->constructorSuccess = true;
+    }
+
+    public function constructorSuccess() {
+        return $this->constructorSuccess;
+    }
+	/**
+	 * getAllAccounts
+	 * 
+	 * @return array of cwp7 accounts array of informations or error message
+	 */
+    public function getAllAccounts() {
+        if (!$this->constructorSuccess()) {
+            return array('error_msg' => 'Error: not connect');
+        }
+        $data = array("key" => $this->cwp7Token, "action" => 'list');
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $this->cwp7URL . '/v1/account');
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
+        if(!$this->cwp7Secure) {
+            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYHOST, false);
+        }
+        curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data));
+        curl_setopt ($ch, CURLOPT_POST, 1);
+        $response = curl_exec($ch);
+        if(curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200) {
+            curl_close($ch);
+            return array('error_msg' => $response);
+        };
+        curl_close($ch);
+        return json_decode($response, true);
+    }
+	/**
+	 * getAccount
+	 * 
+	 * @param string $email login e-mail
+	 * 
+	 * @return array of account informations or error message
+	 */
+    public function getAccount($user) {
+        if (!$this->constructorSuccess()) {
+            return array('error_msg' => 'Error: not connect');
+        }
+        $data = array("key" => $this->cwp7Token, "action"=>'list', "user" => $user);
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $this->cwp7URL . '/v1/accountdetail');
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
+        if(!$this->cwp7Secure) {
+            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYHOST, false);
+        }
+        curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data));
+        curl_setopt ($ch, CURLOPT_POST, 1);
+        $response = curl_exec($ch);
+        if(curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200) {
+            curl_close($ch);
+            return array('error_msg' => $response);
+        };
+        curl_close($ch);
+        return json_decode($response, true);
+    }
+	/**
+	 * createAccount
+	 * 
+	 * @param array $params avvount informations, email required.
+     * 
+	 * @return array of account informations or error message
+	 */
+    public function createAccount($params) {
+        if (!$this->constructorSuccess()) {
+            return array('error_msg' => 'Error: not connected');
+        }
+        if(!isset($params['domain'])) {
+            return array('error_msg' => 'Error: missing parameter domain');
+        }
+        if(!isset($params['user'])) {
+            return array('error_msg' => 'Error: missing parameter user');
+        }
+        if(!isset($params['pass'])) {
+            return array('error_msg' => 'Error: missing parameter pass');
+        }
+        if(!isset($params['email'])) {
+            return array('error_msg' => 'Error: missing parameter email');
+        }
+        if(!isset($params['package'])) {
+            return array('error_msg' => 'Error: missing parameter package');
+        }
+        if(!isset($params['autossl'])) {
+            $params['autossl'] = 0;
+        }
+        $data = array(
+            "key"           => $this->cwp7Token,
+            "action"        =>'add',
+            "domain"        => $params['domain'],
+            "user"          => $params['user'],
+            "pass"          => base64_encode($params['pass']),
+            "email"         => $params['email'],
+            "package"       => $params['package'],
+            "autossl"       => $params['autossl'],
+            "encodepass"    => true,
+        );
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $this->cwp7URL . '/v1/account');
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
+        if(!$this->cwp7Secure) {
+            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYHOST, false);
+        }
+        curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data));
+        curl_setopt ($ch, CURLOPT_POST, 1);
+        $response = curl_exec($ch);
+        if(curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200) {
+            curl_close($ch);
+            return array('error_msg' => $response);
+        };
+        curl_close($ch);
+        return json_decode($response, true);
+	}
+	/**
+	 * modifyAccount
+	 * 
+	 * @param array $params account informations, user, e-mail & new package required.
+     * 
+	 * @see https://download.cwp7.com/published/web-api/v2.1-admin/accounts.md#user-content-Add%20User
+     * 
+	 * @return array status -> OK or error message
+	 */
+    public function modifyAccount($params) {
+        if (!$this->constructorSuccess()) {
+            return array('error_msg' => 'Error: not connected');
+        }
+        if(!isset($params['user'])) {
+            return array('error_msg' => 'Error: missing parameter user');
+        }
+        if(!isset($params['email'])) {
+            return array('error_msg' => 'Error: missing parameter email');
+        }
+        if(!isset($params['package'])) {
+            return array('error_msg' => 'Error: missing parameter package');
+        }
+        $data = array(
+            "key"           => $this->cwp7Token,
+            "action"        =>'upd',
+            "user"          => $params['user'],
+            "email"         => $params['email'],
+            "package"       => $params['package'],
+        );
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $this->cwp7URL . '/v1/account');
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
+        if(!$this->cwp7Secure) {
+            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYHOST, false);
+        }
+        curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data));
+        curl_setopt ($ch, CURLOPT_POST, 1);
+        $response = curl_exec($ch);
+        if(curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200) {
+            curl_close($ch);
+            return array('error_msg' => $response);
+        };
+        curl_close($ch);
+        return json_decode($response, true);
+	}
+	/**
+	 * deleteAccount
+	 * 
+	 * @param array user & e-mail required
+	 * 
+	 * @return array success => true or error message
+	 */
+    public function deleteAccount($params)
+	{
+        if (!$this->constructorSuccess()) {
+            return array('error_msg' => 'Error: not connected');
+        }
+        if(!isset($params['user'])) {
+            return array('error_msg' => 'Error: missing parameter user');
+        }
+        if(!isset($params['email'])) {
+            return array('error_msg' => 'Error: missing parameter email');
+        }
+        $data = array(
+            "key"           => $this->cwp7Token,
+            "action"        =>'del',
+            "user"          => $params['user'],
+            "email"         => $params['email'],
+        );
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $this->cwp7URL . '/v1/account');
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
+        if(!$this->cwp7Secure) {
+            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYHOST, false);
+        }
+        curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data));
+        curl_setopt ($ch, CURLOPT_POST, 1);
+        $response = curl_exec($ch);
+        if(curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200) {
+            curl_close($ch);
+            return array('error_msg' => $response);
+        };
+        curl_close($ch);
+        return json_decode($response, true);
+	}
+	/**
+	 * suspendAccount
+	 * 
+	 * @param string $user required
+	 * 
+	 * @return array success => true or error message
+	 */
+    public function suspendAccount($user)
+	{
+        if (!$this->constructorSuccess()) {
+            return array('error_msg' => 'Error: not connected');
+        }
+        $data = array(
+            "key"           => $this->cwp7Token,
+            "action"        =>'susp',
+            "user"          => $user,
+        );
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $this->cwp7URL . '/v1/account');
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
+        if(!$this->cwp7Secure) {
+            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYHOST, false);
+        }
+        curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data));
+        curl_setopt ($ch, CURLOPT_POST, 1);
+        $response = curl_exec($ch);
+        if(curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200) {
+            curl_close($ch);
+            return array('error_msg' => $response);
+        };
+        curl_close($ch);
+        return json_decode($response, true);
+	}
+	/**
+	 * unsuspendAccount
+	 * 
+	 * @param string $user required
+	 * 
+	 * @return array success => true or error message
+	 */
+    public function unsuspendAccount($user)
+	{
+        if (!$this->constructorSuccess()) {
+            return array('error_msg' => 'Error: not connected');
+        }
+        $data = array(
+            "key"           => $this->cwp7Token,
+            "action"        =>'unsp',
+            "user"          => $user,
+        );
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $this->cwp7URL . '/v1/account');
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
+        if(!$this->cwp7Secure) {
+            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($cwp7Client, CURLOPT_SSL_VERIFYHOST, false);
+        }
+        curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($data));
+        curl_setopt ($ch, CURLOPT_POST, 1);
+        $response = curl_exec($ch);
+        if(curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200) {
+            curl_close($ch);
+            return array('error_msg' => $response);
+        };
+        curl_close($ch);
+        return json_decode($response, true);
+	}
+}

+ 4 - 4
api/test.php

@@ -18,7 +18,7 @@
 /////////////
 
 require_once('config.php');
-require_once('Sf/Admin.php');
+require_once('cwp7/Admin.php');
 
 //////////
 // Args //
@@ -74,10 +74,10 @@ function parse_args($argv){
 // Login //
 ///////////
 
-$sf = new Sf_Admin($seafileURL, $seafileAdminEmail, $seafileAdminPassword);
-$r = $sf->login();
+$cwp7 = new cwp7_Admin($cwp7URL, $cwp7AdminEmail, $cwp7AdminPassword);
+$r = $cwp7->login();
 if(isset($r['error_msg'])) {
-	echo 'Error : cannot login to ' . $seafileURL . ' :-(' . PHP_EOL;
+	echo 'Error : cannot login to ' . $cwp7URL . ' :-(' . PHP_EOL;
 	print_r($r);
 	exit();
 }