diff --git a/README.md b/README.md index 87e4b43..7b6451b 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ AutoBoot ## START 1. 部署 API 到远程服务器 2. 不支持 HTTPS 时,可以通过部署路由中转 -3. 下载Release 或者autojs编译打包app +3. 下载 [Release](https://github.com/zsuroy/autoboot/releases) 或者autojs编译打包app 4. 给予 APP 相关权限 + 无障碍服务权限 + 后台运行权限 @@ -51,7 +51,7 @@ AutoBoot + 通过shell开机唤醒APP/或转为系统APP -## V1.1.0 | 2021.1.31 +## V1.1.0 | 2022.1.31 1. 完成APP开发调试 2. 完成远程API接口开发调试 3. 待完成 @@ -60,3 +60,9 @@ AutoBoot 1. 定时在3.20重启手机 2. 定时Ping-Pong心跳检测 3. 接收远程脚本任务(可以实现一系列自动化操作进行扩展) + +## V1.2.0 | 2022.2.8 +1. 优化APP提示信息 +2. 更新接收远程委派重启时间(APP/WEB) + + 优先采纳接收到远程数据控制重启 + + 本地时间周五允许重启 \ No newline at end of file diff --git a/main.js b/main.js index f8c2373..b988ee4 100644 --- a/main.js +++ b/main.js @@ -2,11 +2,11 @@ * Android 重启小助手 * @author Suroy * @date 2022.1.30 + * @lastedit 2022.2.8 * @url https://suroy.cn * @other * shell: am start -p org.autojs.autojs # 启动autojs(root) * - * */ "auto"; // 自动打开无障碍服务 @@ -48,15 +48,19 @@ function setup(opt) device.wakeUp(); toast('Hello, This is Suroy!'); console.log(device.model, device.getBattery()+"%"); - console.info(opt); + // console.info(opt); var remTimes = 0; threads.start(function(){ // new thread setInterval(function(){ - console.log("Heart Detect"); + // console.log("Heart Detect"); var myDate = new Date(); if(myDate.getHours() == opt["TIME_HOUR"] && myDate.getMinutes() == opt["TIME_MIN"]){ - power("re", opt["CLICK_METHOD"]); // restart + var configs = defConfig(opt["IMEI"], opt["PHONE"]); + if(configs==1 || (configs == 2 && myDate.getDay() == 5) ) + power("re", opt["CLICK_METHOD"]); // restart + else + console.info("Reboot: sleep"); } // heart ping(opt["IMEI"], opt["PHONE"], opt["BAT"]); @@ -128,7 +132,7 @@ function clickMapTxt(txt, types) */ function ping(id, dev, bat){ if(DEBUG_SUROY) console.show(); - var host = DEBUG_SUROY ? "http://192.168.123.41/debug/autoboot/" : "http://dev.suroy.cn/"; + var host = DEBUG_SUROY ? "http://192.168.123.41/debug/autoboot/" : "http://suroy.cn/"; var api = host + "app.php?mod=ping&id=" + id + "&dev=" + dev + "&bat=" + bat; api = encodeURI(api); try { @@ -152,7 +156,7 @@ function ping(id, dev, bat){ * @param {string} dev */ function remote(id, dev){ - var host = DEBUG_SUROY ? "http://192.168.123.41/debug/autoboot/" : "http://dev.suroy.cn/"; + var host = DEBUG_SUROY ? "http://192.168.123.41/debug/autoboot/" : "http://suroy.cn/"; var api = host + "app.php?mod=remote&id=" + id; try { @@ -219,3 +223,43 @@ function getRes(url){ console.error(e) } } + + +/** + * 默认重启时间设置监测 + * @param {int} id + * @param {string} dev + * @returns {int} 0,关;1,开;2,开; + */ +function defConfig(id, dev){ + var host = DEBUG_SUROY ? "http://192.168.123.41/debug/autoboot/" : "http://suroy.cn/"; + var api = host + "app.php?mod=remote&id=" + id; + + try { + var r = http.get(api, { + headers: { + 'Accept-Language': 'zh-cn,zh;q=0.5', + 'User-Agent': 'Mozilla/5.0 (Linux; U; Android; zh-CN; ' + dev + ' Build/PKQ1.190616.001) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/78.0.3904.108 AutoBoot/13.7.4.1155 Mobile Safari/537.36 ' + } + }); + var cmd = r.body.json(); + if(cmd.code == 0) + { + + if(cmd.data.config) + { + console.warn("config: default"); + return 1; // 维持默认设置 + } + } + else{ + toastLog(cmd.msg); + } + // log("remote: " + JSON.stringify(cmd)); + } catch (e) { + // 捕捉所有异常 + console.error(e); + return 2; // 网络错误,维持本地设置 + } + return 0; +} diff --git a/project.json b/project.json index a6c2aaf..eaf3d39 100644 --- a/project.json +++ b/project.json @@ -5,6 +5,6 @@ "build" ], "packageName": "cn.suroy.autoreboot", - "versionName": "1.0.0", + "versionName": "1.2.0", "versionCode": 1 } \ No newline at end of file diff --git a/web/app-router.php b/web/app-router.php index 6b47005..9b5a875 100644 --- a/web/app-router.php +++ b/web/app-router.php @@ -17,7 +17,7 @@ $name = @$_GET['name']; $id = isset($_GET['id']) ? @$_GET['id'] : 1; $fname = './data/'.$name.'-'.$id.'.yml'; - $url = 'http://127.0.0.1/addon/airport/app.php?mod=get&name='.$name.'&id='.$id; + $url = 'http://127.0.0.1/app.php?mod=get&name='.$name.'&id='.$id; $info = getSSLPage($url); exit($info); break; @@ -26,13 +26,13 @@ $dev = isset($_GET['dev']) ? urldecode(@$_GET['dev']) : 'Android'; // 名字 $bat = isset($_GET['bat']) ? @$_GET['bat'] : 0; // 电量 $dev = str_replace(' ', '', $dev); // 空格报错 - $url = 'http://127.0.0.1/addon/autoboot/app.php?mod=ping&addr='.$_SERVER['REMOTE_ADDR'].'&dev='.$dev.'&id='.$id.'&bat='.$bat; + $url = 'http://127.0.0.1/app.php?mod=ping&addr='.$_SERVER['REMOTE_ADDR'].'&dev='.$dev.'&id='.$id.'&bat='.$bat; $info = getSSLPage($url); exit($info); break; case 'remote': // Autoboot | remote $id = isset($_GET['id']) ? @$_GET['id'] : 1; - $url = 'http://127.0.0.1/addon/autoboot/app.php?mod=remote&id='.$id; + $url = 'http://127.0.0.1/app.php?mod=remote&id='.$id; $info = getSSLPage($url); exit($info); break; diff --git a/web/app.php b/web/app.php index f23cfb4..3976fe7 100644 --- a/web/app.php +++ b/web/app.php @@ -52,8 +52,10 @@ if(is_file($fname)) { $info = file_get_contents($fname); - // {"action":0,"description":"restart","remarks":"Action: 0-close; 1-rebootNow; 2-shutdown","source":"https://suroy.cn/logo.png","time":"2022-01-31 04:05:14"} - exit('{"code":0, "data": '.$info.'}'); + // {“config”:0,"action":0,"description":"restart","remarks":"Action: 0-close; 1-rebootNow; 2-shutdown","source":"https://suroy.cn/logo.png","time":"2022-01-31 04:05:14"} + $info_db = json_decode($info, true); + $info_db["config"] = defWeekCfg(); // 重定义维持原重启时间设置 + exit('{"code":0, "data": '.json_encode($info_db).'}'); } exit('{"code":1, "msg": "Wait for Suroy\'s adding a settings."}'); break; @@ -86,4 +88,19 @@ function real_ip() return $ip; } +/** + * 定义维持默认原设置时间 + * @note 于重定义维持原重启时间设置 + * @return bool + */ +function defWeekCfg($sw=1) +{ + $arr = array(0); // 重启时间 0-6 => Sun - Sat + $weekday = date('w'); + if(in_array($weekday, $arr) && $sw) + return 1; + else + return 0; +} + ?> \ No newline at end of file diff --git a/web/data/0.json b/web/data/0.json index e667732..5e97a4c 100644 --- a/web/data/0.json +++ b/web/data/0.json @@ -1 +1 @@ -{"action":3,"description":"reboot","source":"http://dev.suroy.cn/open/remote.js","remarks":"Action: 0-close; 1-rebootNow; 2-shutdown; 3-runScript","time":"2022-01-31 04:05:14"} \ No newline at end of file +{"config":1,"action":3,"description":"reboot","source":"http://dev.suroy.cn/open/remote.js","remarks":"Action: 0-close; 1-rebootNow; 2-shutdown; 3-runScript","time":"2022-01-31 04:05:14"} \ No newline at end of file diff --git a/web/data/demo.json b/web/data/demo.json new file mode 100644 index 0000000..00f90cd --- /dev/null +++ b/web/data/demo.json @@ -0,0 +1,8 @@ +{ + "config":1, // 维持原重启时间设置 + "action":3, // 远程命令行为 + "description":"reboot", // 描述 + "source":"http://dev.suroy.cn/open/remote.js", // 远程脚本地址 + "remarks":"Action: 0-close; 1-rebootNow; 2-shutdown; 3-runScript", // 行为备注说明 + "time":"2022-01-31 04:05:14" // 当前时间 +} \ No newline at end of file