PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 4.8.9
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v4.8.9
8.7.8 8.7.7 8.7.6 8.7.5 8.7.4 8.7.3 8.7.2 8.7.1 8.7.0 8.6.9 8.6.8 8.6.7 8.6.6 8.6.5 8.6.4 8.6.2 8.6.1 8.6.0 8.5.9 8.5.8 8.5.7 8.5.6 8.5.5 8.5.4 8.5.3 All 534 releases
chatbot / includes / class-wpbot-gc-download.php

class-wpbot-gc-download.php in WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services 4.8.9, at includes/class-wpbot-gc-download.php

112 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 class WPBotGCDownload
7 {
8 private $download_url = 'https://github.com/qcloud/gc/raw/master/wpbotgc.zip';
9 private $filename = 'wpbotgc.zip';
10 public function __construct(){
11 add_action('wp_ajax_qcld_wp_chatbot_gc_client_download', array($this, 'downloadgc'));
12 add_action('wp_ajax_nopriv_qcld_wp_chatbot_gc_client_download', array($this, 'downloadgc'));
13 add_action('wp_ajax_qcld_wp_chatbot_gc_client_extract', array($this, 'extractgc'));
14 add_action('wp_ajax_nopriv_qcld_wp_chatbot_gc_client_extract', array($this, 'extractgc'));
15
16 }
17
18 public function create_folder($gcdirectory){
19 return @mkdir( $gcdirectory, 0777, true );
20 }
21
22 public function create_file($filename){
23 if ( ! @file_exists( $filename ) ) {
24 if ( ! @is_writable( dirname( $filename ) ) ) {
25 return false;
26 }
27
28 if ( ! @touch( $filename ) ) {
29 return false;
30 }
31 } elseif ( ! @is_writable( $filename ) ) {
32 return false;
33 }
34
35 $is_written = false;
36 if ( ( $handle = @fopen( $filename, 'w' ) ) !== false ) {
37 if ( @fwrite( $handle, '<?php //silence is golden' ) !== false ) {
38 $is_written = true;
39 }
40
41 @fclose( $handle );
42 }
43
44 return $is_written;
45 }
46
47 public function downloadgc(){
48 $gcdirectory = QCLD_wpCHATBOT_GC_DIRNAME;
49
50 if ( ! is_dir( $gcdirectory ) ) {
51 $this->create_folder( $gcdirectory );
52 }
53 if(!file_exists($gcdirectory.'/index.php')){
54 $this->create_file( $gcdirectory.'/index.php' );
55 }
56
57 if(is_dir($gcdirectory)){
58
59 $zipFile = $gcdirectory."/".$this->filename; // Local Zip File Path
60 $zipResource = fopen($zipFile, "w");
61 // Get The Zip File From Server
62 $ch = curl_init();
63 curl_setopt($ch, CURLOPT_URL, $this->download_url);
64 curl_setopt($ch, CURLOPT_FAILONERROR, true);
65 curl_setopt($ch, CURLOPT_HEADER, 0);
66 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
67 curl_setopt($ch, CURLOPT_AUTOREFERER, true);
68 curl_setopt($ch, CURLOPT_BINARYTRANSFER,true);
69 curl_setopt($ch, CURLOPT_TIMEOUT, 10);
70 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
71 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
72 curl_setopt($ch, CURLOPT_FILE, $zipResource);
73 $page = curl_exec($ch);
74 if(!$page) {
75 $response = array('status'=>'error','content'=> curl_error($ch));
76 echo wp_send_json($response);
77 wp_die();
78 }
79 curl_close($ch);
80 $response = array('status'=>'success','content'=> 'File downloaded successfully');
81 }else{
82 $response = array('status'=>'error','content'=> 'Server does not allow to create files and folders');
83 }
84
85 echo wp_send_json($response);
86 wp_die();
87 }
88
89 function extractgc(){
90 $gcdirectory = QCLD_wpCHATBOT_GC_DIRNAME;
91 $gcfilename = QCLD_wpCHATBOT_GC_DIRNAME.'/'.$this->filename;
92 /* Open the Zip file */
93 $zip = new ZipArchive;
94 $extractPath = "path_to_extract";
95 if($zip->open($gcfilename) != "true"){
96 $response = array('status'=>'error','content'=> 'File Not Found!');
97 echo wp_send_json($response);
98 wp_die();
99 }
100 /* Extract Zip File */
101 $zip->extractTo($gcdirectory);
102 $zip->close();
103 @unlink($gcfilename);
104 $response = array('status'=>'success','content'=> 'Files Extracted successfully!');
105 echo wp_send_json($response);
106 wp_die();
107
108 }
109 }
110
111 new WPBotGCDownload();
112