Skip to content

Commit

Permalink
V1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zsuroy committed Feb 8, 2022
1 parent 2b0c6f1 commit ae58ac2
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 15 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 相关权限
+ 无障碍服务权限
+ 后台运行权限
Expand All @@ -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. 待完成
Expand All @@ -60,3 +60,9 @@ AutoBoot
1. 定时在3.20重启手机
2. 定时Ping-Pong心跳检测
3. 接收远程脚本任务(可以实现一系列自动化操作进行扩展)

## V1.2.0 | 2022.2.8
1. 优化APP提示信息
2. 更新接收远程委派重启时间(APP/WEB)
+ 优先采纳接收到远程数据控制重启
+ 本地时间周五允许重启
56 changes: 50 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"; // 自动打开无障碍服务
Expand Down Expand Up @@ -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"]);
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"build"
],
"packageName": "cn.suroy.autoreboot",
"versionName": "1.0.0",
"versionName": "1.2.0",
"versionCode": 1
}
6 changes: 3 additions & 3 deletions web/app-router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
21 changes: 19 additions & 2 deletions web/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

?>
2 changes: 1 addition & 1 deletion web/data/0.json
Original file line number Diff line number Diff line change
@@ -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"}
{"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"}
8 changes: 8 additions & 0 deletions web/data/demo.json
Original file line number Diff line number Diff line change
@@ -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" // 当前时间
}

0 comments on commit ae58ac2

Please sign in to comment.