Delete Site AA Panel API

How To Delete A Site From AA Panel Using Their API

<?php
/**
 * aapanel
 * @author 
 * @link https://www.bt.cn/api-doc.pdf
 * @link
 * @version 1.0
 * @example
 * $bt = new Bt('https://127.0.0.1/8888','xxxxxxxxxxxxxxxx');
 * echo $bt->GetSystemTotal();//Get basic system statistics
 * @return Array
 */
class Bt{

private $BT_KEY = "api-key-here"; //Interface key
    private $BT_PANEL = "https://XXX.XX.XXX.XXX:XXXX"; //Panel address

    /**
    * Initialization
    * @param [type] $bt_panel Pagoda interface address
    * @param [type] $bt_key Pagoda Api key
    */
    public function __construct($bt_panel = null,$bt_key = null){
    if($bt_panel) $this->BT_PANEL = $bt_panel;
    if($bt_key) $this->BT_KEY = $bt_key;
    }

  /**
  * Delete website
  * @param [type] $id site ID
  * @param [type] $webname website name
  * @param [type] $ftp whether to delete the associated FTP
  * @param [type] $database whether to delete the associated database
  * @param [type] $path whether to delete the root directory of the associated website
  *
  */
  public function WebDeleteSite($id,$webname,$ftp,$database,$path){
  $url = $this->BT_PANEL.$this->config("WebDeleteSite");

  $p_data = $this->GetKeyData();
  $p_data['id'] = $id;
  $p_data['webname'] = $webname;
  $p_data['ftp'] = $ftp;
  $p_data['database'] = $database;
  $p_data['path'] = $path;

  $result = $this->HttpPostCookie($url,$p_data);

  $data = json_decode($result,true);
  return $data;
  }

  /**
     * Construct associative array with signature
     */
  public function GetKeyData(){
  $now_time = time();
  $p_data = array(
  'request_token' => md5($now_time.''.md5($this->BT_KEY)),
  'request_time' => $now_time
  );
  return $p_data;
  }

  /**
     * Initiate POST request
     * @param String $url target net fill, with https://
     * @param Array|String $data the data to be submitted
     * @return string
     */
  private function HttpPostCookie($url, $data,$timeout = 60)
  {
    //Define the cookie storage location
  $cookie_file='./'.md5($this->BT_PANEL).'.cookie';
  if(!file_exists($cookie_file)){
  $fp = fopen($cookie_file,'w+');
  fclose($fp);
  }

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
  curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  $output = curl_exec($ch);
  curl_close($ch);
  return $output;
  }

  /**
  * Load pagoda data interface
  * @param [type] $str [description]
  * @return [type] [description]
  */
  private function config($str){
  require_once('config.php');
  return $config[$str];
  }
  }

  // Modify to your own pagoda interface and Api key
   $bt = new Bt('https://XXX.XX.XXX.XXX:XXXX','api-key-here');
   header('Content-type: application/json');
   echo json_encode($bt->WebDeleteSite());

  ?>

Was this helpful?

Leave a Comment