PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 6.0.0
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v6.0.0
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 6.0.0, at includes/class-wpbot-gc-download.php

123 lines 4.5 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 $nonce = sanitize_text_field($_POST['nonce']);
49 if (! wp_verify_nonce($nonce,'wp_chatbot')) {
50 wp_send_json(array('success' => false, 'msg' => esc_html__('Failed in Security check', 'sm')));
51 wp_die();
52
53 }else{
54 $gcdirectory = QCLD_wpCHATBOT_GC_DIRNAME;
55
56 if ( ! is_dir( $gcdirectory ) ) {
57 $this->create_folder( $gcdirectory );
58 }
59 if(!file_exists($gcdirectory.'/index.php')){
60 $this->create_file( $gcdirectory.'/index.php' );
61 }
62
63 if(is_dir($gcdirectory)){
64
65 $zipFile = $gcdirectory."/".$this->filename; // Local Zip File Path
66 $zipResource = fopen($zipFile, "w");
67 // Get The Zip File From Server
68 $ch = curl_init();
69 curl_setopt($ch, CURLOPT_URL, $this->download_url);
70 curl_setopt($ch, CURLOPT_FAILONERROR, true);
71 curl_setopt($ch, CURLOPT_HEADER, 0);
72 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
73 curl_setopt($ch, CURLOPT_AUTOREFERER, true);
74 curl_setopt($ch, CURLOPT_BINARYTRANSFER,true);
75 curl_setopt($ch, CURLOPT_TIMEOUT, 10);
76 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
77 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
78 curl_setopt($ch, CURLOPT_FILE, $zipResource);
79 $page = curl_exec($ch);
80 if(!$page) {
81 $response = array('status'=>'error','content'=> curl_error($ch));
82 //Sanitization to be checked
83 wp_send_json($response);
84 }
85 curl_close($ch);
86 $response = array('status'=>'success','content'=> 'File downloaded successfully');
87 }else{
88 $response = array('status'=>'error','content'=> 'Server does not allow to create files and folders');
89 }
90 //Sanitization to be checked
91 wp_send_json($response);
92 }
93 }
94
95 function extractgc(){
96 $nonce = sanitize_text_field($_POST['nonce']);
97 if (! wp_verify_nonce($nonce,'wp_chatbot')) {
98 wp_send_json(array('success' => false, 'msg' => esc_html__('Failed in Security check', 'sm')));
99
100 }else{
101 $gcdirectory = QCLD_wpCHATBOT_GC_DIRNAME;
102 $gcfilename = QCLD_wpCHATBOT_GC_DIRNAME.'/'.$this->filename;
103 /* Open the Zip file */
104 $zip = new ZipArchive;
105 $extractPath = "path_to_extract";
106 if($zip->open($gcfilename) != "true"){
107 $response = array('status'=>'error','content'=> 'File Not Found!');
108 //Sanitization to be checked
109 wp_send_json($response);
110 }
111 /* Extract Zip File */
112 $zip->extractTo($gcdirectory);
113 $zip->close();
114 @unlink($gcfilename);
115 $response = array('status'=>'success','content'=> 'Files Extracted successfully!');
116 //Sanitization to be checked
117 wp_send_json($response);
118 }
119 }
120 }
121
122 new WPBotGCDownload();
123