Quellcode durchsuchen

删除升级文件, 修改默认为 aliyin sms

joe vor 4 Jahren
Ursprung
Commit
4514d9ee5c

+ 0 - 377
app/admin/controller/system/SystemUpgradeclient.php

@@ -1,377 +0,0 @@
-<?php
-
-namespace app\admin\controller\system;
-
-use app\admin\controller\AuthController;
-use crmeb\services\JsonService as Json;
-use crmeb\services\MysqlBackupService;
-use crmeb\services\UpgradeService as uService;
-use think\facade\Db;
-
-/**
- * 在线升级控制器
- * Class SystemUpgradeclient
- * @package app\admin\controller\system
- *
- */
-class SystemUpgradeclient extends AuthController
-{
-
-    protected $serverweb = array('version' => '1.0', 'version_code' => 0);//本站点信息
-
-    public function initialize()
-    {
-        parent::initialize();
-        //屏蔽所有错误避免操作文件夹发生错误提示
-        ini_set('display_errors', 0);
-        error_reporting(0);
-        self::snyweninfo();//更新站点信息
-        $this->assign(['auth' => self::isauth(), 'app' => uService::isWritable(app()->getRootPath()), 'extend' => uService::isWritable(EXTEND_PATH), 'public' => uService::isWritable(app()->getRootPath() . 'public')]);
-    }
-
-    //同步更新站点信息
-    public function snyweninfo()
-    {
-        $this->serverweb['ip'] = $this->request->ip();
-        $this->serverweb['host'] = $this->request->host();
-        $this->serverweb['https'] = !empty($this->request->domain()) ? $this->request->domain() : sys_config('site_url');
-        $this->serverweb['webname'] = sys_config('site_name');
-        $local = uService::getVersion();
-        if ($local['code'] == 200 && isset($local['msg']['version']) && isset($local['msg']['version_code'])) {
-            $this->serverweb['version'] = uService::replace($local['msg']['version']);
-            $this->serverweb['version_code'] = (int)uService::replace($local['msg']['version_code']);
-        }
-        uService::snyweninfo($this->serverweb);
-    }
-
-    //是否授权
-    public function isauth()
-    {
-        return uService::isauth();
-    }
-
-    public function index()
-    {
-        $server = uService::start();
-        $version = $this->serverweb['version'];
-        $version_code = $this->serverweb['version_code'];
-        $this->assign(compact('server', 'version', 'version_code'));
-        return $this->fetch();
-    }
-
-    public function get_list()
-    {
-        $list = uService::request_post(uService::$isList, ['page' => input('post.page/d'), 'limit' => input('post.limit/d')]);
-        if (is_array($list) && isset($list['code']) && isset($list['data']) && $list['code'] == 200) {
-            $list = $list['data'];
-        } else {
-            $list = [];
-        }
-        Json::successful('ok', ['list' => $list, 'page' => input('post.page/d') + 1]);
-    }
-
-    //删除备份文件
-    public function setcopydel()
-    {
-        $post = input('post.');
-        if (!isset($post['id'])) Json::fail('删除备份文件失败,缺少参数ID');
-        if (!isset($post['ids'])) Json::fail('删除备份文件失败,缺少参数IDS');
-        $fileservice = new uService;
-        if (is_array($post['ids'])) {
-            foreach ($post['ids'] as $file) {
-                $fileservice->del_dir(app()->getRootPath() . 'public' . DS . 'copyfile' . $file);
-            }
-        }
-        if ($post['id']) {
-            $copyFile = app()->getRootPath() . 'public' . DS . 'copyfile' . $post['id'];
-            $fileservice->del_dir($copyFile);
-        }
-        Json::successful('删除成功');
-    }
-
-    public function get_new_version_conte()
-    {
-        $post = $this->request->post();
-        if (!isset($post['id'])) Json::fail('缺少参数ID');
-        $versionInfo = uService::request_post(uService::$NewVersionCount, ['id' => $post['id']]);
-        if (isset($versionInfo['code']) && isset($versionInfo['data']['count']) && $versionInfo['code'] == 200) {
-            return Json::successful(['count' => $versionInfo['data']['count']]);
-        } else {
-            return Json::fail('服务器异常');
-        }
-    }
-
-    //一键升级
-    public function auto_upgrad()
-    {
-        $prefix = config('database.prefix');
-        $fileservice = new uService;
-        $post = $this->request->post();
-        if (!isset($post['id'])) Json::fail('缺少参数ID');
-        $versionInfo = $fileservice->request_post(uService::$isNowVersion, ['id' => $post['id']]);
-        if ($versionInfo === null) Json::fail('服务器异常,请稍后再试');
-        if (isset($versionInfo['code']) && $versionInfo['code'] == 400) Json::fail(isset($versionInfo['msg']) ? $versionInfo['msg'] : '您暂时没有权限升级,请联系管理员!');
-        if (is_array($versionInfo) && isset($versionInfo['data'])) {
-            $list = $versionInfo['data'];
-            $id = [];
-            foreach ($list as $key => $val) {
-                $savefile = app()->getRootPath() . 'public' . DS . 'upgrade_lv';
-                //1,检查远程下载文件,并下载
-                if (($save_path = $fileservice->check_remote_file_exists($val['zip_name'], $savefile)) === false) Json::fail('远程升级包不存在');
-                //2,首先解压文件
-                $savename = app()->getRootPath() . 'public' . DS . 'upgrade_lv' . DS . time();
-                $fileservice->zipopen($save_path, $savename);
-                //3,执行SQL文件
-                Db::startTrans();
-                try {
-                    //参数3不介意大小写的
-                    $sqlfile = $fileservice->list_dir_info($savename . DS, true, 'sql');
-                    if (is_array($sqlfile) && !empty($sqlfile)) {
-                        foreach ($sqlfile as $file) {
-                            if (file_exists($file)) {
-                                //为一键安装做工作记得表前缀要改为[#DB_PREFIX#]哦
-                                $execute_sql = explode(";\r", str_replace(['[#DB_PREFIX#]', "\n"], [$prefix, "\r"], file_get_contents($file)));
-                                foreach ($execute_sql as $_sql) {
-                                    if ($query_string = trim(str_replace(array(
-                                        "\r",
-                                        "\n",
-                                        "\t"
-                                    ), '', $_sql))) Db::execute($query_string);
-                                }
-                                //执行完sql记得删掉哦
-                                $fileservice->unlink_file($file);
-                            }
-                        }
-                    }
-                    Db::commit();
-                } catch (\Exception $e) {
-                    Db::rollback();
-                    //删除解压下的文件
-                    $fileservice->del_dir(app()->getRootPath() . 'public' . DS . 'upgrade_lv');
-                    //删除压缩包
-                    $fileservice->unlink_file($save_path);
-                    //升级失败发送错误信息
-                    $fileservice->request_post(uService::$isInsertLog, [
-                        'content' => '升级失败,错误信息为:' . $e->getMessage(),
-                        'add_time' => time(),
-                        'ip' => $this->request->ip(),
-                        'http' => $this->request->domain(),
-                        'type' => 'error',
-                        'version' => $val['version']
-                    ]);
-                    return Json::fail('升级失败SQL文件执行有误');
-                }
-                //4,备份文件
-                $copyFile = app()->getRootPath() . 'public' . DS . 'copyfile' . $val['id'];
-                $copyList = $fileservice->get_dirs($savename . DS);
-                if (isset($copyList['dir'])) {
-                    if ($copyList['dir'][0] == '.' && $copyList['dir'][1] == '..') {
-                        array_shift($copyList['dir']);
-                        array_shift($copyList['dir']);
-                    }
-                    foreach ($copyList['dir'] as $dir) {
-                        if (file_exists(app()->getRootPath() . $dir, $copyFile . DS . $dir)) {
-                            $fileservice->copy_dir(app()->getRootPath() . $dir, $copyFile . DS . $dir);
-                        }
-                    }
-                }
-                //5,覆盖文件
-                $fileservice->handle_dir($savename, app()->getRootPath());
-                //6,删除升级生成的目录
-                $fileservice->del_dir(app()->getRootPath() . 'public' . DS . 'upgrade_lv');
-                //7,删除压缩包
-                $fileservice->unlink_file($save_path);
-                //8,改写本地升级文件
-                $handle = fopen(app()->getRootPath() . '.version', 'w+');
-                if ($handle === false) Json::fail(app()->getRootPath() . '.version' . '无法写入打开');
-                $content = <<<EOT
-version={$val['version']}
-version_code={$val['id']}
-EOT;
-                if (fwrite($handle, $content) === false) Json::fail('升级包写入失败');
-                fclose($handle);
-                //9,向服务端发送升级日志
-                $posts = [
-                    'ip' => $this->request->ip(),
-                    'https' => $this->request->domain(),
-                    'update_time' => time(),
-                    'content' => '一键升级成功,升级版本号为:' . $val['version'] . '。版本code为:' . $val['id'],
-                    'type' => 'log',
-                    'versionbefor' => $this->serverweb['version'],
-                    'versionend' => $val['version']
-                ];
-                $inset = $fileservice->request_post(uService::$isInsertLog, $posts);
-                $id[] = $val['id'];
-            }
-            //10,升级完成
-            Json::successful('升级成功', ['code' => end($id), 'version' => $val['version']]);
-        } else {
-            Json::fail('服务器异常,请稍后再试');
-        }
-    }
-
-    //在线升级
-    public function online_upgrad()
-    {
-        $prefix = config('database.prefix');
-        $fileservice = new uService;
-        $post = $this->request->post();
-        if (!isset($post['id'])) Json::fail('缺少参数ID');
-        //获取升级列表
-        $versionInfo = $fileservice->request_post(uService::$isNowVersion, ['id' => 18]);
-        if ($versionInfo === null) Json::fail('服务器异常,请稍后再试');
-        //检测授权
-        if(!$fileservice->isauth()) Json::fail('请先去授权后在升级');
-        if (isset($versionInfo['code']) && $versionInfo['code'] == 400) Json::fail(isset($versionInfo['msg']) ? $versionInfo['msg'] : '您暂时没有权限升级,请联系管理员!');
-        if(!is_array($versionInfo) || !isset($versionInfo['data'])) Json::fail('服务器异常,请稍后再试');
-        $rootpath = app()->getRootPath();
-        $list = $versionInfo['data'];
-        $id = [];
-        $savefile = $rootpath . 'public' . DS . 'upgrade_lv';
-        foreach ($list as $key => $val) {
-
-            //1,检查远程下载文件,并下载
-            if (($save_path = $fileservice->check_remote_file_exists($val['zip_name'], $savefile)) === false) Json::fail('远程升级包不存在');
-            //2,首先解压文件
-            $savename = $rootpath . 'public' . DS . 'upgrade_lv' . DS . time();
-            $fileservice->zipopen($save_path, $savename);
-        }
-        //3,备份文件
-        $saveDir = $rootpath . 'backup\\'.date('Ymd',time()).'\\';
-        $filepath = $saveDir . 'crmeb_'.time().'.zip';
-        $zip = new \ZipArchive();
-        if(!$zip->open($filepath,\ZIPARCHIVE::CREATE))
-        {
-            Json::fail("创建[$filepath]失败");
-        }
-        try{
-            $this->createZip($rootpath,$zip);
-        }catch (\think\Exception $e){
-            $message  = '[异常时间]: '. date('Y-m-d H:i:s') . PHP_EOL;
-            $message .= '[异常消息]: '. $e->getMessage() . PHP_EOL;
-            $message .= '[异常文件]: '. $e->getFile() . PHP_EOL;
-            $message .= '[异常行数]: '. $e->getLine() . PHP_EOL;
-            Json::fail($message);
-        }
-        $zip->close();
-        //4 备份sql
-        if(!$this->backupSql($saveDir)){
-            Json::fail('备份数据库失败');
-        }
-        //5 执行SQL文件
-        Db::startTrans();
-        try {
-            //参数3不介意大小写的
-            $sqlfile = $fileservice->list_dir_info($savename . DS, true, 'sql');
-            if (is_array($sqlfile) && !empty($sqlfile)) {
-                foreach ($sqlfile as $file) {
-                    if (file_exists($file)) {
-                        //为一键安装做工作记得表前缀要改为[#DB_PREFIX#]哦
-                        $execute_sql = explode(";\r", str_replace(['[#DB_PREFIX#]', "\n"], [$prefix, "\r"], file_get_contents($file)));
-                        foreach ($execute_sql as $_sql) {
-                            if ($query_string = trim(str_replace(array(
-                                "\r",
-                                "\n",
-                                "\t"
-                            ), '', $_sql))) Db::execute($query_string);
-                        }
-                        //执行完sql记得删掉哦
-                        $fileservice->unlink_file($file);
-                    }
-                }
-            }
-            Db::commit();
-        } catch (\Exception $e) {
-            Db::rollback();
-            //删除解压下的文件
-            $fileservice->del_dir(app()->getRootPath() . 'public' . DS . 'upgrade_lv');
-            //删除压缩包
-            $fileservice->unlink_file($save_path);
-            //升级失败发送错误信息
-            $fileservice->request_post(uService::$isInsertLog, [
-                'content' => '升级失败,错误信息为:' . $e->getMessage(),
-                'add_time' => time(),
-                'ip' => $this->request->ip(),
-                'http' => $this->request->domain(),
-                'type' => 'error',
-                'version' => $val['version']
-            ]);
-            return Json::fail('升级失败SQL文件执行有误');
-        }
-
-        //6 覆盖文件
-        $fileservice->handle_dir($savename, app()->getRootPath());
-        //7 删除升级生成的目录
-        $fileservice->del_dir(app()->getRootPath() . 'public' . DS . 'upgrade_lv');
-        //8 删除压缩包
-        $fileservice->unlink_file($save_path);
-        //9 改写本地升级文件
-        $handle = fopen(app()->getRootPath() . '.version', 'w+');
-        if ($handle === false) Json::fail(app()->getRootPath() . '.version' . '无法写入打开');
-        $content = <<<EOT
-version={$val['version']}
-version_code={$val['id']}
-EOT;
-        if (fwrite($handle, $content) === false) Json::fail('升级包写入失败');
-        fclose($handle);
-        //10 向服务端发送升级日志
-        $posts = [
-            'ip' => $this->request->ip(),
-            'https' => $this->request->domain(),
-            'update_time' => time(),
-            'content' => '一键升级成功,升级版本号为:' . $val['version'] . '。版本code为:' . $val['id'],
-            'type' => 'log',
-            'versionbefor' => $this->serverweb['version'],
-            'versionend' => $val['version']
-        ];
-        $inset = $fileservice->request_post(uService::$isInsertLog, $posts);
-        $id[] = $val['id'];
-
-        //11 升级完成
-        Json::successful('升级成功', ['code' => end($id), 'version' => $val['version']]);
-
-    }
-    //备份sql
-    public function backupSql($saveDir)
-    {
-        $config = array(
-            'path'=>$saveDir,
-            //数据库备份卷大小
-            'compress' => 1,
-            //数据库备份文件是否启用压缩 0不压缩 1 压缩
-            'level' => 5,
-        );
-        $back = new MysqlBackupService($config);
-        $list = $back->dataList(null);
-        $tables = array_column($list,'name');
-        $back->setFile(['name'=>'crmeb','part'=>time()]);
-        $data = '';
-        foreach ($tables as $t) {
-            $res = $back->backup($t, 0);
-            if ($res == false && $res != 0) {
-                $data .= $t . '|';
-            }
-        }
-        return $data ? false : true;
-    }
-    //创建zip
-    private function createZip($dir,$zipObj)
-    {
-        $dir_source = opendir($dir);
-        while(($file = readdir($dir_source)) != false)
-        {
-            if($file=="." || $file==".." ) continue;
-
-            $sub_file = $dir.'/'.$file;
-            if(is_dir($sub_file) && $file != 'backup' && $file != 'runtime' && $file = 'uploads')
-            {
-                $zipObj->addEmptyDir($sub_file);
-                $this->createZip($sub_file,$zipObj);
-            }
-            if(is_file($sub_file))
-            {
-                $zipObj->addFile($sub_file);
-            }
-        }
-    }
-}

+ 0 - 197
crmeb/services/UpgradeService.php

@@ -1,197 +0,0 @@
-<?php
-
-namespace crmeb\services;
-
-class UpgradeService extends FileService
-{
-    //请求域名
-    public static $domain = 'http://shop.crmeb.net/';
-    //及时更新网址信息
-    public static $updatewebinfourl = 'index.php/admin/server.upgrade_api/updatewebinfo.html';
-    //公共接口地址 获取版本号
-    public static $isNowVersionUrl = 'index.php/admin/server.upgrade_api/now_version.html';
-    //公共接口地址 获取版本详情
-    public static $isVersionInfo = 'index.php/admin/server.upgrade_api/version_info.html';
-    //公共接口地址 获取历史版本列表
-    public static $isList = 'index.php/admin/server.upgrade_api/get_version_list.html';
-    //公共接口地址 写入更新版本信息
-    public static $isInsertLog = 'index.php/admin/server.upgrade_api/set_upgrade_info.html';
-    //公共接口地址 获取大于当前版本的所有版本
-    public static $isNowVersion = 'index.php/admin/server.upgrade_api/get_now_version.html';
-    //公共接口地址 更新网址信息
-    protected static $UpdateWeBinfo = 'index.php/admin/server.upgrade_api/updatewebinfo.html';
-    //公共接口地址 获取多少版本未更新
-    public static $NewVersionCount = 'index.php/admin/server.upgrade_api/new_version_count.html';
-    //公共接口地址 判断是否有权限 返回1有权限,0无权限
-    protected static $Isauth = 'index.php/admin/server.upgrade_api/isauth.html';
-    //相隔付
-    private static $seperater = "{&&}";
-
-    //更新网址信息
-    public function snyweninfo($serverweb)
-    {
-        return self::request_post(self::$UpdateWeBinfo, $serverweb);
-    }
-
-    //判断是否有权限 返回1有权限,0无权限
-    public function isauth()
-    {
-        return self::request_post(self::$Isauth);
-    }
-
-    /*
-     *获取ip token 生成当前时间和过期时间
-     * @param string ip
-     * @param int $valid_peroid 过期周期 15天
-     */
-    public static function get_token($ip = '', $valid_peroid = 1296000)
-    {
-        $request = app('request');
-        if (empty($ip)) $ip = $request->ip();
-        $to_ken = $request->domain() . self::$seperater . $ip . self::$seperater . time() . self::$seperater . (time() + $valid_peroid) . self::$seperater;
-        $token = self::enCode($to_ken);
-        return $token;
-    }
-
-    private static function getRet($msg, $code = 400)
-    {
-        return ['msg' => $msg, 'code' => $code];
-    }
-
-    /**
-     *
-     * @param string $url
-     * @param array $post_data
-     */
-    public static function start()
-    {
-        $pach = app()->getRootPath() . 'version';
-        $request = app('request');
-        if (!file_exists($pach)) return self::getRet($pach . '升级文件丢失,请联系管理员');
-        $version = @file($pach);
-        if (!isset($version[0])) return self::getRet('获取失败');
-        $lv = self::request_post(self::$isNowVersionUrl, ['token' => self::get_token($request->ip())]);
-        if (isset($lv['code']) && $lv['code'] == 200)
-            $version_lv = isset($lv['data']['version']) && $lv['data']['version'] ? $lv['data']['version'] : false;
-        else
-            return isset($lv['msg']) ? self::getRet($lv['msg']) : self::getRet('获取失败');
-        if ($version_lv === false) return self::getRet('获取失败');
-        if (strstr($version[0], '=') !== false) {
-            $version = explode('=', $version[0]);
-            if ($version[1] != $version_lv) {
-                return self::getRet($version_lv, 200);
-            }
-        }
-        return self::getRet('获取失败');
-    }
-
-    public static function getVersion()
-    {
-        $pach = app()->getRootPath() . '.version';
-        if (!file_exists($pach)) return self::getRet($pach . '升级文件丢失,请联系管理员');
-        $version = @file($pach);
-        if (!isset($version[0]) && !isset($version[1])) return self::getRet('获取失败');
-        $arr = [];
-        foreach ($version as $val) {
-            list($k, $v) = explode('=', $val);
-            $arr[$k] = $v;
-        }
-        return self::getRet($arr, 200);
-    }
-
-    /**
-     * 模拟post进行url请求
-     * @param string $url
-     * @param array $post_data
-     */
-    public static function request_post($url = '', $post_data = array())
-    {
-        if (strstr($url, 'http') === false) $url = self::$domain . $url;
-        if (empty($url)) {
-            return false;
-        }
-        if (!isset($post_data['token'])) $post_data['token'] = self::get_token();
-        $o = "";
-        foreach ($post_data as $k => $v) {
-            $o .= "$k=" . urlencode($v) . "&";
-        }
-        $post_data = substr($o, 0, -1);
-        $postUrl = $url;
-        $curlPost = $post_data;
-        $ch = curl_init();//初始化curl
-        curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
-        curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
-        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
-        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
-        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
-        curl_setopt($ch, CURLOPT_TIMEOUT, 20);
-        $data = curl_exec($ch);//运行curl
-        curl_close($ch);
-        if ($data) {
-            $data = json_decode($data, true);
-        }
-        return $data;
-    }
-
-    /**
-     * 验证远程文件是否存在 以及下载
-     * @param string $url 文件路径
-     * @param string $savefile 保存地址
-     */
-    public static function check_remote_file_exists($url, $savefile)
-    {
-        $url = self::$domain . 'public' . DS . 'uploads' . DS . 'upgrade' . DS . $url;
-        $url = str_replace('\\', '/', $url);
-        $curl = curl_init($url);
-        curl_setopt($curl, CURLOPT_NOBODY, true);
-        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
-        // 发送请求
-        $result = curl_exec($curl);
-        $found = false;
-        // 如果请求没有发送失败
-        if ($result !== false) {
-            // 再检查http响应码是否为200
-            $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
-            if ($statusCode == 200) {
-                curl_close($curl);
-
-                $fileservice = new self;
-                //下载文件
-                $zip = $fileservice->down_remote_file($url, $savefile);
-                if ($zip['error'] > 0) return false;
-                if (!isset($zip['save_path']) && empty($zip['save_path'])) return false;
-                if (!file_exists($zip['save_path'])) return false;
-                return $zip['save_path'];
-            }
-        }
-        curl_close($curl);
-        return $found;
-    }
-
-    /**
-     * 通用加密
-     * @param String $string 需要加密的字串
-     * @param String $skey 加密EKY
-     * @return String
-     */
-    private static function enCode($string = '', $skey = 'fb')
-    {
-        $skey = array_reverse(str_split($skey));
-        $strArr = str_split(base64_encode($string));
-        $strCount = count($strArr);
-        foreach ($skey as $key => $value) {
-            $key < $strCount && $strArr[$key] .= $value;
-        }
-        return str_replace('=', 'O0O0O', join('', $strArr));
-    }
-
-    /**
-     * 去除回车,去取空格,去除换行,去除tab
-     * @param String $str 需要去除的字串
-     * @return String
-     */
-    public static function replace($str)
-    {
-        return trim(str_replace(array("\r", "\n", "\t"), '', $str));
-    }
-}

+ 1 - 1
crmeb/services/sms/Sms.php

@@ -34,7 +34,7 @@ class Sms extends BaseManager
      */
     protected function getDefaultDriver()
     {
-        return Config::get('sms.default', 'sms');
+        return Config::get('sms.default', 'aliyun');
     }