Compare commits

..

4 Commits

Author SHA1 Message Date
mercury 294a26ec7d improve update menu 2024-03-28 17:26:55 +04:00
mercury 7d12e5c972 improve update script 2024-03-21 01:36:11 +04:00
mercury 2efcea9dbe improve update script 2024-03-21 01:27:06 +04:00
mercury 5b1bf2b3d5 switch branches after update 2024-03-21 01:19:19 +04:00
8 changed files with 105 additions and 10 deletions
+83 -7
View File
@@ -121,7 +121,7 @@ class Bot
case preg_match('~^/menu (?P<type>addpeer) (?P<arg>(?:-)?\d+)$~', $this->input['callback'], $m):
case preg_match('~^/menu (?P<type>wg) (?P<arg>(?:-)?\d+)$~', $this->input['callback'], $m):
case preg_match('~^/menu (?P<type>client) (?P<arg>\d+(?:_(?:-)?\d+)?)$~', $this->input['callback'], $m):
case preg_match('~^/menu (?P<type>pac|adguard|config|ss|lang|oc|naive|mirror)$~', $this->input['callback'], $m):
case preg_match('~^/menu (?P<type>pac|adguard|config|ss|lang|oc|naive|mirror|update)$~', $this->input['callback'], $m):
case preg_match('~^/menu (?P<type>subzoneslist|reverselist|includelist|excludelist) (?P<arg>(?:-)?\d+)$~', $this->input['callback'], $m):
$this->menu(type: $m['type'] ?? false, arg: $m['arg'] ?? false);
break;
@@ -137,8 +137,14 @@ class Bot
case preg_match('~^/mtproto$~', $this->input['callback'], $m):
$this->mtproto();
break;
case preg_match('~^/updatebot$~', $this->input['callback'], $m):
$this->updatebot();
case preg_match('~^/applyupdatebot$~', $this->input['callback'], $m):
$this->applyupdatebot();
break;
case preg_match('~^/branches$~', $this->input['callback'], $m):
$this->branches();
break;
case preg_match('~^/changeBranch (\d+)$~', $this->input['callback'], $m):
$this->changeBranch($m[1]);
break;
case preg_match('~^/getMirror$~', $this->input['callback'], $m):
$this->getMirror();
@@ -901,10 +907,10 @@ class Bot
$last = file_get_contents('https://raw.githubusercontent.com/mercurykd/vpnbot/master/version');
if (!empty($last) && $last != $this->last && $last != $current) {
$this->last = $last;
$diff = implode("\n", array_slice(explode("\n", $last), 0, count(explode("\n", $last)) - count(explode("\n", $current))));
$diff = array_slice(explode("\n", $last), 0, count(explode("\n", $last)) - count(explode("\n", $current)));
if (!empty($diff)) {
foreach ($c['admin'] as $k => $v) {
$this->send($v, "update:\n$diff");
$this->send($v, "update:\n{$diff[0]}");
}
}
}
@@ -3154,6 +3160,7 @@ DNS-over-HTTPS with IP:
'oc' => $type == 'oc' ? $this->ocMenu() : false,
'naive' => $type == 'naive' ? $this->naiveMenu() : false,
'mirror' => $type == 'mirror' ? $this->mirrorMenu() : false,
'update' => $type == 'update' ? $this->updatebot() : false,
];
$text = $menu[$type ?: 'main' ]['text'];
@@ -3662,6 +3669,41 @@ DNS-over-HTTPS with IP:
}
public function updatebot()
{
exec('git -C / branch', $m);
$track = trim(file_get_contents('/update/branch'));
$data = [
[
[
'text' => "{$m[0]} => $track",
'callback_data' => "/branches",
],
[
'text' => $this->i18n('changelog'),
'web_app' => ['url' => "https://raw.githubusercontent.com/mercurykd/vpnbot/master/version"],
],
],
[
[
'text' => $this->i18n('update bot'),
'callback_data' => "/applyupdatebot",
],
],
];
$data[] = [
[
'text' => $this->i18n('back'),
'callback_data' => "/menu config",
],
];
exec("git -C / branch -vv", $mm);
return [
'text' => '<pre><code class="language-shell">' . implode("\n", $mm) . '</code></pre>',
'data' => $data,
];
}
public function applyupdatebot()
{
$this->exportManual($this->update);
$r = $this->send($this->input['from'], 'update...');
@@ -3672,6 +3714,7 @@ DNS-over-HTTPS with IP:
public function configMenu()
{
exec('git -C / fetch');
$conf = $this->getPacConf();
$text[] = $conf['domain'] ? "Domains:\n{$conf['domain']}\nnp.{$conf['domain']}\noc.{$conf['domain']}" . ($conf['adguardkey'] ? "\n{$conf['adguardkey']}.{$conf['domain']}" : '') : $this->i18n('domain explain');
$ssl = $this->expireCert();
@@ -3785,8 +3828,8 @@ DNS-over-HTTPS with IP:
];
$data[] = [
[
'text' => $this->i18n('update bot'),
'callback_data' => "/updatebot",
'text' => $this->i18n(exec('git rev-list --count HEAD..@{u}') ? 'have updates' : 'no updates'),
'callback_data' => "/menu update",
],
];
$data[] = [
@@ -3801,6 +3844,39 @@ DNS-over-HTTPS with IP:
];
}
public function branches()
{
exec('git -C / branch -r', $m);
array_shift($m);
foreach ($m as $k => $v) {
$data[] = [
[
'text' => $v,
'callback_data' => "/changeBranch $k",
]
];
}
$data[] = [
[
'text' => $this->i18n('back'),
'callback_data' => "/menu update",
]
];
$this->update($this->input['from'], $this->input['message_id'], 'branches', $data);
}
public function changeBranch($i)
{
exec('git -C / branch -r', $m);
array_shift($m);
foreach ($m as $k => $v) {
if ($i == $k) {
file_put_contents('/update/branch', trim(str_replace('origin/', '', $v)));
}
}
$this->menu('config');
}
public function logs()
{
foreach (scandir('/logs/') as $k => $v) {
+8
View File
@@ -321,4 +321,12 @@ $i = [
'en' => 'web panel is only available from telegram',
'ru' => 'веб панель доступна только из телеграмма',
],
'no updates' => [
'en' => 'no updates',
'ru' => 'нет обновлений',
],
'have updates' => [
'en' => 'have updates',
'ru' => 'есть обновления',
],
];
View File
+2 -2
View File
@@ -74,7 +74,6 @@ services:
- ./config/sshd_config:/etc/ssh/sshd_config
- ./logs/:/logs/
- ./app/webapp:/app
- ./app/login.html:/app/login.html
ports:
- 80:80
hostname: nginx
@@ -96,7 +95,7 @@ services:
ipv4_address: 10.10.1.2
logging: *default-logging
php:
image: mercurykd/vpnbot-php:1.2
image: mercurykd/vpnbot-php:1.3
build:
dockerfile: dockerfile/php.dockerfile
args:
@@ -117,6 +116,7 @@ services:
- ./mirror:/mirror
- ./.env:/mirror/.env
- ./update:/update
- ./.git:/.git
environment:
IP: ${IP}
VER: ${VER}
+1
View File
@@ -19,6 +19,7 @@ RUN apk add --no-cache --update php81 \
openssh \
openssl \
curl \
git \
py3-qt5 \
&& wget https://github.com/ameshkov/dnslookup/releases/download/v1.9.1/dnslookup-linux-amd64-v1.9.1.tar.gz \
&& tar -xf dnslookup-linux-amd64-v1.9.1.tar.gz \
+7 -1
View File
@@ -6,10 +6,16 @@ echo "$$" > $pwd/update/update_pid
while true
do
cmd=$(cat $pwd/update/pipe)
branch=$(cat $pwd/update/branch 2>/dev/null)
if [[ -n "$cmd" ]]
then
docker compose down --remove-orphans
git reset --hard
git reset --hard && git clean -fd
git fetch
if [[ -n "$branch" ]]
then
git checkout -t origin/$branch || git checkout $branch
fi
git pull > ./update/message
IP=$(curl https://ipinfo.io/ip) VER=$(git describe --tags) docker compose up -d --force-recreate
bash $pwd/update/update.sh &
+4
View File
@@ -1,3 +1,7 @@
28.03.2024 v1.13
- кнопка обновления показывает есть ли обновления
21.03.2024 v1.12
- доработка скрипта обновления
20.03.2024 v1.11
- XTLS-Reality steal from yourself
18.03.2024 v1.10