linfeng@zhonghui 1 rok temu
commit
655c4e542c

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+.idea

+ 80 - 0
Patch.php

@@ -0,0 +1,80 @@
+<?php
+
+/**
+ * User lin
+ * Class Patch
+ * @package helper
+ */
+class Patch
+{
+
+    // 签名
+    public static function sign($param, $key)
+    {
+        try{
+            if(isset($param['sign'])) unset($param['sign']);
+            ksort($param);
+            $stringA = '';
+            foreach ($param as $k=>$v){
+                $stringA .= $k.'='.urlencode($v).'&';
+            }
+            $stringA .= 'key='.$key;
+            $sign = base64_encode(md5($stringA));
+            return $sign;
+        }catch (\Exception $e){
+            return false;
+        }
+    }
+
+    // 验签并返回解析结果
+    public static function checkSign($stream, $key)
+    {
+        try{
+            if(!$stream) return false;
+            $json = base64_decode($stream);
+            $param = json_decode($json, true);
+            $stream_sign = $param['sign'];
+            $sign = self::sign($param, $key);
+            if($sign != $stream_sign) return false;
+            return $param;
+        }catch (\Exception $e){
+            return false;
+        }
+    }
+
+    // 打补丁
+    public static function packPatch($name, $desc, $exec, $ver, $key)
+    {
+        $param = [];
+        // 补丁名称
+        $param['name'] = $name;
+        // 补丁描述
+        $param['desc'] = $desc;
+        // 补丁适用版本,适用于在此版本之前的版本升级到此版本时使用
+        $param['ver'] = $ver;
+        // 补丁发行日期
+        $param['date'] = date('Y-m-d H:i:s');
+        // 补丁代码 - php
+        $param['exec'] = self::packExec($exec);
+        // 签名
+        $param['sign'] = self::sign($param, $key);
+        return base64_encode(json_encode($param));
+    }
+
+    // 编码补丁代码
+    private static function packExec($exec)
+    {
+        $stringA = urlencode(htmlspecialchars($exec));
+        $stringB = base64_encode($stringA);
+        return $stringB;
+    }
+
+    // 解码补丁代码
+    public static function unpackExec($exec)
+    {
+        $stringA = base64_decode($exec);
+        $stringB = htmlspecialchars_decode(urldecode($stringA));
+        return $stringB;
+    }
+
+}

+ 23 - 0
buildPatch.php

@@ -0,0 +1,23 @@
+<?php
+
+date_default_timezone_set('PRC');
+
+require_once __DIR__.'/Patch.php';
+
+$codeDir = __DIR__.'/patch/repair_light_db_gid';
+
+$code = file_get_contents($codeDir . '/code.php');
+$code = str_replace('<?php', '', $code);
+
+$name = '修复分库gid为0的情况';
+$desc = '主要用于修复群组与设备处于关联的情况,但分库里面的gid为0,会导致灯上报状态时无法找寻关联的群组,从而导致群组亮度无法与灯保持一致的问题';
+// 适用于此版本及以下版本使用
+$ver = '999';
+// 补丁key
+$key = 'smartLEDZ';
+
+$stream = Patch::packPatch($name, $desc, $code, $ver, $key);
+
+$is = file_put_contents($codeDir.'/'.date('Y-m-d').'v'.$ver.'_'.time().rand(1000, 9999).'.b', $stream);
+if(!$is) die('补丁生成失败');
+die('补丁已生成');

Plik diff jest za duży
+ 0 - 0
patch/2022-08-02v999_16594123815746.b


Plik diff jest za duży
+ 0 - 0
patch/old_gw/2023-04-08v0_16809494668977.b


Plik diff jest za duży
+ 0 - 0
patch/old_gw/2023-04-08v999_16809494564121.b


Plik diff jest za duży
+ 2 - 0
patch/old_gw/code.php


Plik diff jest za duży
+ 0 - 0
patch/repair_light_db_gid/2023-11-13v999_16998641216533.b


+ 27 - 0
patch/repair_light_db_gid/code.php

@@ -0,0 +1,27 @@
+<?php
+
+$groupList = sqlite("groups")->select();
+
+// 获取所有网关列表
+$gatewayList = sqlite("gateways")->select();
+foreach ($gatewayList as $gateway){
+    // 查询分库所有gid为0的设备
+    $light = sqlite("light", "light/".$gateway["eth_ip"].".db")->where(["group_id"=>0])->select();
+    foreach ($light as $light_v){
+        // 获取当前设备绑定的群组
+        $gid = sqlite("group_device")->where([
+            "gwid"=>$gateway["id"],
+            "device_id"=>$light_v["did"],
+            "btype"=>1,
+        ])->value("gid");
+        if(!$gid) continue; // 此设备未绑定群组,跳过
+
+        foreach ($groupList as $group){
+            if($group["id"] == $gid){
+                sqlite("light", "light/".$gateway["eth_ip"].".db")->where(["did"=>$light_v["did"]])->update(["group_id"=>$group["id"], "group_type"=>$group["type"]]);
+                break;
+            }
+        }
+    }
+}
+

Plik diff jest za duży
+ 0 - 0
patch/repair_low_ver_back_3ch/2023-10-30v999_16986539448628.b


+ 36 - 0
patch/repair_low_ver_back_3ch/code.php

@@ -0,0 +1,36 @@
+<?php
+
+// +----------------------------------------
+// | overlay文件系统目录分布
+// +----------------------------------------
+$lowerDir = realpath(__DIR__."/../../smartLEDZ"); // read层·原始文件
+$upperDir = realpath(__DIR__."/../../smartLEDZ_Upper"); // write层
+$mergedDir = realpath(__DIR__."/../../smartLEDZ_Merged"); // 读写·数据交互层(read层 + write层) - [ 程序运行在此 ]
+
+$app_path = $lowerDir; // 当前运行的项目主目录
+$targetDir = $lowerDir; //
+if(is_dir($mergedDir)){ // 存在overlay
+    $app_path = $mergedDir;
+    $targetDir = $mergedDir;
+}
+
+$sceneList = sqlite("scenes")->select();
+foreach ($sceneList as $sv){
+    $groupSet = json_decode($sv["group_set"], true);
+    if(count($groupSet) == 0) continue;
+    $isUp = false;
+    foreach ($groupSet as &$gv){
+        if(isset($gv["color_mode"])) continue;
+        $isUp = true;
+        $gv["color_x"] = 1;
+        $gv["color_y"] = 1;
+        $gv["color_mode"] = 1;
+        $gv["color_fine"] = 0;
+    }
+    if($isUp) sqlite("scenes")->where(["id"=>$sv["id"]])->update(["group_set"=>json_encode($groupSet)]);
+}
+
+$zoneList = sqlite("zones")->where(["days"=>"null"])->select();
+foreach ($zoneList as $zv){
+    sqlite("zones")->where(["id"=>$zv["id"]])->update(["days"=>""]);
+}

Plik diff jest za duży
+ 0 - 0
patch/restore_client_auto_back/2023-09-14v999_16946776344261.b


+ 47 - 0
patch/restore_client_auto_back/code.php

@@ -0,0 +1,47 @@
+<?php
+
+// +----------------------------------------
+// | overlay文件系统目录分布
+// +----------------------------------------
+$lowerDir = realpath(__DIR__."/../../smartLEDZ"); // read层·原始文件
+$upperDir = realpath(__DIR__."/../../smartLEDZ_Upper"); // write层
+$mergedDir = realpath(__DIR__."/../../smartLEDZ_Merged"); // 读写·数据交互层(read层 + write层) - [ 程序运行在此 ]
+
+$app_path = $lowerDir; // 当前运行的项目主目录
+$targetDir = $lowerDir; //
+if(is_dir($mergedDir)){ // 存在overlay
+    $app_path = $mergedDir;
+    $targetDir = $mergedDir;
+}
+
+if(file_exists($app_path . "/logs/gw_back")){
+    unlink($app_path . "/logs/gw_back");
+}
+
+if(!is_dir($app_path . "/restore")) mkdir($app_path . "/restore");
+$unCmd = sprintf("tar -xvf %s/smartLEDZ_DB_U.tar -C %s/restore", $app_path, $app_path);
+
+exec($unCmd);
+
+// 检查备份文件是什么APP版本备份的
+exec("tar -tf " . $app_path."/smartLEDZ_DB_U.tar", $output);
+if(in_array("overlay/www/smartLEDZ/db/smartLEDZ.db", $output)){
+    // 旧overlay版备份
+    exec(sprintf("cp -r %s/restore/overlay/www/smartLEDZ/* %s", $app_path, $targetDir));
+    exec(sprintf("rm -rf %s/restore/overlay", $app_path));
+
+}else if(in_array("mnt/mmcblk0p1/www/smartLEDZ/db/smartLEDZ.db", $output)){
+    // 旧版APP备份
+    exec(sprintf("cp -r %s/restore/mnt/mmcblk0p1/www/smartLEDZ/* %s", $app_path, $targetDir));
+    exec(sprintf("rm -rf %s/restore/mnt", $app_path));
+
+}else if(in_array("mnt/mmcblk0p1/www/smartLEDZ_Merged/db/smartLEDZ.db", $output)){
+    // 新overlay版备份
+    exec(sprintf("cp -r %s/restore/mnt/mmcblk0p1/www/smartLEDZ_Merged/* %s", $app_path, $targetDir));
+    exec(sprintf("rm -rf %s/restore/mnt", $app_path));
+}
+
+exec(sprintf("cp -r %s/db/exec.json.bak %s/db/exec.json", $targetDir, $targetDir));
+
+// 热重载Socket
+file_put_contents($app_path . "/workerman/reload", "");

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików