Skip to content

Commit

Permalink
Fix detecting local time logic error
Browse files Browse the repository at this point in the history
  • Loading branch information
ellermister committed May 27, 2024
1 parent 4101bda commit 5af29df
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ docker logs -f mtproxy

## 使用方式

配置文件 `mtp_config`,如果你想手动修改密钥或者参数请注意格式。


运行服务

```bash
Expand All @@ -122,6 +125,12 @@ bash mtproxy.sh stop
bash mtproxy.sh restart
```

重新安装/重新配置

```bash
bash mtproxy.sh reinstall
```

## 卸载安装

因为是绿色版卸载极其简单,直接删除所在目录即可。
Expand All @@ -142,6 +151,26 @@ rm -rf /home/mtproxy
cd /home/mtproxy && bash mtproxy.sh start > /dev/null 2>&1 &
```


## 计划任务守护

因为默认官方的 mtproxy 程序存在BUG,pid 大于 65535 时处理存在问题。进程容易坏死和异常退出。

建议通过计划任务去守护进程,编辑方式 `crontab -e`

每分钟检测进程并启动

```bash
* * * * * cd /home/mtproxy && bash mtproxy.sh start > /dev/null 2>&1 &
```

## MTProxy Admin Bot

https://t.me/MTProxybot
> Sorry, an error has occurred during your request. Please try again later.(Code xxxxxx)

如果你在申请绑定代理推广时遇到了此类错误,官方没有给出明确的原因,根据网友反馈,此类问题多出现于账号注册不足与 2~3 年,**建议使用 3 年以上的账号以及未被 banned 的账号。**

## 引用项目

- https://github.com/TelegramMessenger/MTProxy
Expand Down
10 changes: 8 additions & 2 deletions mtproxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ check_sys() {
fi
}

function abs() {
echo ${1#-};
}

function get_ip_public() {
public_ip=$(curl -s https://api.ip.sb/ip -A Mozilla --ipv4)
[ -z "$public_ip" ] && public_ip=$(curl -s ipinfo.io/ip -A Mozilla --ipv4)
Expand Down Expand Up @@ -282,9 +286,11 @@ do_kill_process() {
}

do_check_system_datetime_and_update() {
offset=$(ntpdate -q time.google.com | grep -oP 'offset \K[\d]+' | tail -n 1)
dateFromLocal=$(date +%s)
dateFromServer=$(date -d "$(curl -v --silent ip.sb 2>&1 | grep Date | sed -e 's/< Date: //')" +%s)
offset=$(abs $(( "$dateFromServer" - "$dateFromLocal")))
tolerance=60
if [ "$offset" -gt "$tolerance" ] || [ "$offset" -lt "-$tolerance" ];then
if [ "$offset" -gt "$tolerance" ];then
echo "检测到系统时间不同步于世界时间, 即将更新"
ntpdate -u time.google.com
fi
Expand Down

0 comments on commit 5af29df

Please sign in to comment.