mirror of
https://github.com/elseif/MikroTikPatch.git
synced 2026-08-26 18:15:56 +00:00
Compare commits
12 Commits
7.22.3-arm
...
7.23.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbf8ed23e3 | ||
|
|
7039d76825 | ||
|
|
5e9340c741 | ||
|
|
ac2cfdeafd | ||
|
|
e728aec84c | ||
|
|
1d9971b387 | ||
|
|
1cfb6dba3d | ||
|
|
ba0ffe3cd7 | ||
|
|
7cf469dc0c | ||
|
|
30d6ac5fe6 | ||
|
|
7fd1b6c563 | ||
|
|
ed3dcd0ab1 |
79
.github/workflows/mikrotik_patch_7.yml
vendored
79
.github/workflows/mikrotik_patch_7.yml
vendored
@@ -188,7 +188,64 @@ jobs:
|
||||
for cmd in $COMMANDS; do
|
||||
sudo ln -sf /pckg/option/bin/busybox ./option-root/bin/$cmd
|
||||
done
|
||||
sudo mksquashfs option-root option.sfs -quiet -comp xz -no-xattrs -b 256k
|
||||
sudo mkdir -p option-root/home/web/webfig/
|
||||
BUSYBOX=$(./busybox/busybox_x86 | head -1 | cut -d' ' -f2)
|
||||
sudo tee option.jg > /dev/null << EOF
|
||||
[
|
||||
{
|
||||
name:'Patch About',
|
||||
title:'Patch About',
|
||||
icon: 30,
|
||||
prio: 2000,
|
||||
c:[
|
||||
{
|
||||
title:'Patch About',
|
||||
type:'item',
|
||||
path:[24, 2],
|
||||
autorefresh: 1000,
|
||||
ro: 1,
|
||||
c: [
|
||||
{name:'Author',type:'string',def:'elseif@live.cn'},
|
||||
{name:'GitHub',type:'string',def:'https://github.com/elseif/MikroTikPatch', url:1},
|
||||
{name:'Telegram',type:'string',def:'https://t.me/mikrotikpatch', url:1},
|
||||
{name:'Homepage',type:'string',def:'https://mikrotik.ltd', url:1},
|
||||
{type:'separator'},
|
||||
{name:'Busybox',type:'string',def:'$BUSYBOX'},
|
||||
{name:'Uptime',type:'interval',id:'u1'},
|
||||
{name:'Architecture Name',type:'string',id:'s1a'},
|
||||
{name:'Board Name',type:'string',id:'s2c'},
|
||||
{name:'Version',type:'version',id:'s16'},
|
||||
{name:'Build Time',type:'string',id:'s27'}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
EOF
|
||||
sudo apt-get install python3-crcmod > /dev/null
|
||||
HASH=$(sudo python3 -E <<EOF
|
||||
import hashlib, crcmod, sys
|
||||
with open('option.jg','rb') as f:
|
||||
data = f.read()
|
||||
sha1 = hashlib.sha1(data).hexdigest()[:12]
|
||||
crc = crcmod.mkCrcFun(0x104C11DB7, initCrc=0xFFFFFFFF, rev=False, xorOut=0xFFFFFFFF)(data)
|
||||
print(f"{sha1} {crc}")
|
||||
EOF
|
||||
)
|
||||
SHA1_PREFIX=$(echo "$HASH" | awk '{print $1}')
|
||||
CRC=$(echo "$HASH" | awk '{print $2}')
|
||||
sudo mv option.jg option-$SHA1_PREFIX.jg
|
||||
sudo python3 -E << EOF
|
||||
import gzip
|
||||
gzip.open('option-$SHA1_PREFIX.jg.gz', 'wb', compresslevel=0).write(open('option-$SHA1_PREFIX.jg', 'rb').read())
|
||||
EOF
|
||||
SIZE=$(stat -c %s option-$SHA1_PREFIX.jg.gz)
|
||||
sudo mv option-$SHA1_PREFIX.jg.gz option-root/home/web/webfig/
|
||||
sudo tee option-root/home/web/webfig/option.info > /dev/null << EOF
|
||||
{ crc: $CRC, size: $SIZE, name: "option.jg", unique: "option-$SHA1_PREFIX.jg",version: "$LATEST_VERSION" },
|
||||
EOF
|
||||
sudo ln -sf option-$SHA1_PREFIX.jg.gz option-root/home/web/webfig/option.jg.gz
|
||||
sudo mksquashfs option-root option.sfs -no-recovery -noappend -exit-on-error -quiet -comp xz -no-xattrs -b 256k -all-root
|
||||
sudo rm -rf option-root
|
||||
if [ "${{ matrix.arch }}" == "x86" ]; then
|
||||
sudo wget -O cpython.tar.gz -nv https://github.com/astral-sh/python-build-standalone/releases/download/20241206/cpython-3.11.11+20241206-x86_64-unknown-linux-musl-install_only_stripped.tar.gz
|
||||
@@ -201,7 +258,7 @@ jobs:
|
||||
sudo rm cpython.tar.gz
|
||||
sudo rm -rf ./python/include
|
||||
sudo rm -rf ./python/share
|
||||
sudo mksquashfs python python3.sfs -quiet -comp xz -no-xattrs -b 256k
|
||||
sudo mksquashfs python python3.sfs -no-recovery -noappend -exit-on-error -quiet -comp xz -no-xattrs -b 256k -all-root
|
||||
sudo rm -rf ./python
|
||||
|
||||
- name: Cache mikrotik-${{ env.LATEST_VERSION }}${{ env.ARCH }}.iso
|
||||
@@ -235,7 +292,7 @@ jobs:
|
||||
- name: Patch mikrotik-${{ env.LATEST_VERSION }}${{ env.ARCH }}.iso
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && (matrix.arch == 'x86' || matrix.arch == 'arm64')
|
||||
run: |
|
||||
sudo apt-get install -y mkisofs xorriso > /dev/null
|
||||
sudo apt-get install -y build-essential binutils-arm-linux-gnueabi mkisofs xorriso > /dev/null
|
||||
sudo mkdir ./iso
|
||||
sudo mount -o loop,ro mikrotik.iso ./iso
|
||||
sudo mkdir ./new_iso
|
||||
@@ -711,6 +768,20 @@ jobs:
|
||||
- name: Upload Files
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && env.RELEASE == 'true'
|
||||
run: |
|
||||
sudo apt-get install -y knockd lftp > /dev/null
|
||||
knock -4 ${{ secrets.SSH_SERVER }} ${{ secrets.SSH_KNOCK_PORT }}
|
||||
echo "Knocking on server..."
|
||||
for i in 1 2 3; do
|
||||
if knock -4 ${{ secrets.SSH_SERVER }} ${{ secrets.SSH_KNOCK_PORT }} ; then
|
||||
echo "Knock successful"
|
||||
break
|
||||
else
|
||||
echo "Knock attempt $i failed, retrying..."
|
||||
sleep 2
|
||||
fi
|
||||
done
|
||||
echo "Waiting for firewall to open SSH port..."
|
||||
sleep 3
|
||||
sudo chown -R root:root ./publish/
|
||||
LOCAL_PATH=./publish/$LATEST_VERSION
|
||||
REMOTE_PATH=${{ secrets.SSH_DIRECTORY }}
|
||||
@@ -792,7 +863,7 @@ jobs:
|
||||
|
||||
- name: Upload Files as Artifact (No Release)
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && env.RELEASE == 'false'
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: mikrotik-${{ env.LATEST_VERSION }}${{ env.ARCH }}
|
||||
path: |
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
### 感谢赞助
|
||||
[](https://www.digitalocean.com/?refcode=dbf6ed365068&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=badge)
|
||||
|
||||
[DartNode(aff)](https://dartnode.com?aff=SnazzyLobster067) | [ZMTO(aff)](https://console.zmto.com/?affid=1588) | [Vultr(aff)](https://www.vultr.com/?ref=9807160-9J)
|
||||
|
||||
# MikroTik RouterOS Patch [[English](README_EN.md)]
|
||||
@@ -63,7 +62,7 @@ graph TD
|
||||
### patch.py
|
||||
替换公钥并签名
|
||||
|
||||
## 所有的修补操作都自动运行在[Github Action](https://github.com/elseif/MikroTikPatch/blob/main/.github/workflows/)。
|
||||
[](https://dartnode.com "Powered by DartNode - Free VPS for Open Source")
|
||||
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
105
patch.py
105
patch.py
@@ -321,46 +321,79 @@ def patch_loader(loader_file):
|
||||
print("loader module import failed. cannot run patch_loader.py")
|
||||
|
||||
def patch_squashfs(path,key_dict):
|
||||
url_replacements = {
|
||||
os.environ.get('MIKRO_LICENCE_URL', '').encode(): os.environ.get('CUSTOM_LICENCE_URL', '').encode(),
|
||||
os.environ.get('MIKRO_UPGRADE_URL', '').encode(): os.environ.get('CUSTOM_UPGRADE_URL', '').encode(),
|
||||
os.environ.get('MIKRO_CLOUD_URL', '').encode(): os.environ.get('CUSTOM_CLOUD_URL', '').encode(),
|
||||
os.environ.get('MIKRO_CLOUD_PUBLIC_KEY', '').encode(): os.environ.get('CUSTOM_CLOUD_PUBLIC_KEY', '').encode(),
|
||||
}
|
||||
url_replacements = {k: v for k, v in url_replacements.items() if k and v}
|
||||
renew_replacements = {
|
||||
os.environ.get('MIKRO_RENEW_URL', '').encode(): os.environ.get('CUSTOM_RENEW_URL', '').encode(),
|
||||
}
|
||||
renew_replacements = {k: v for k, v in renew_replacements.items() if k and v}
|
||||
|
||||
for root, dirs, files in os.walk(path):
|
||||
for _file in files:
|
||||
file = os.path.join(root,_file)
|
||||
if os.path.isfile(file):
|
||||
if _file =='loader':
|
||||
patch_loader(file)
|
||||
continue
|
||||
if _file =='BOOTX64.EFI':
|
||||
print(f'patch {file} ...')
|
||||
data = open(file,'rb').read()
|
||||
data = patch_kernel(data,key_dict)
|
||||
open(file,'wb').write(data)
|
||||
continue
|
||||
data = open(file,'rb').read()
|
||||
if 'mode' in files and 'keyman' in files:
|
||||
for file_path in [os.path.join(root, 'mode'),os.path.join(root, 'keyman')]:
|
||||
with open(file_path, 'rb') as f:
|
||||
data = f.read()
|
||||
modified = False
|
||||
for old_public_key,new_public_key in key_dict.items():
|
||||
_data = replace_key(old_public_key,new_public_key,data,file)
|
||||
if _data != data:
|
||||
open(file,'wb').write(_data)
|
||||
url_dict = {
|
||||
os.environ['MIKRO_LICENCE_URL'].encode():os.environ['CUSTOM_LICENCE_URL'].encode(),
|
||||
os.environ['MIKRO_UPGRADE_URL'].encode():os.environ['CUSTOM_UPGRADE_URL'].encode(),
|
||||
os.environ['MIKRO_CLOUD_URL'].encode():os.environ['CUSTOM_CLOUD_URL'].encode(),
|
||||
os.environ['MIKRO_CLOUD_PUBLIC_KEY'].encode():os.environ['CUSTOM_CLOUD_PUBLIC_KEY'].encode(),
|
||||
}
|
||||
data = open(file,'rb').read()
|
||||
for old_url,new_url in url_dict.items():
|
||||
new_data = replace_key(old_public_key,new_public_key,data,file_path)
|
||||
if new_data != data:
|
||||
data = new_data
|
||||
modified = True
|
||||
assert modified, f'{file_path} key not patched'
|
||||
with open(f'{file_path}_', 'wb') as f:
|
||||
f.write(data)
|
||||
if 'loader' in files and os.path.isfile(os.path.join(root, 'loader')):
|
||||
loader_file = os.path.join(root, 'loader')
|
||||
patch_loader(loader_file)
|
||||
|
||||
if 'BOOTX64.EFI' in files and os.path.isfile(os.path.join(root, 'BOOTX64.EFI')):
|
||||
efi_file = os.path.join(root, 'BOOTX64.EFI')
|
||||
with open(efi_file, 'rb') as f:
|
||||
data = f.read()
|
||||
new_data = patch_kernel(data,key_dict)
|
||||
assert new_data != data, f'{file_path} key not patched'
|
||||
with open(efi_file, 'wb') as f:
|
||||
f.write(new_data)
|
||||
|
||||
|
||||
for filename in files:
|
||||
if filename in ['mode','keyman','loader','BOOTX64.EFI']:
|
||||
continue
|
||||
file_path = os.path.join(root,filename)
|
||||
if not os.path.isfile(file_path):
|
||||
continue
|
||||
|
||||
modified = False
|
||||
with open(file_path, 'rb') as f:
|
||||
data = f.read()
|
||||
|
||||
for old_public_key,new_public_key in key_dict.items():
|
||||
new_data = replace_key(old_public_key,new_public_key,data,file_path)
|
||||
if new_data != data:
|
||||
data = new_data
|
||||
modified = True
|
||||
|
||||
for old_url,new_url in url_replacements.items():
|
||||
if old_url in data:
|
||||
print(f'{file_path} url patched {old_url.decode()[:7]}...')
|
||||
data = data.replace(old_url,new_url)
|
||||
modified = True
|
||||
|
||||
if filename == 'licupgr':
|
||||
for old_url,new_url in renew_replacements.items():
|
||||
if old_url in data:
|
||||
print(f'{file} url patched {old_url.decode()[:7]}...')
|
||||
print(f'{file_path} url patched {old_url.decode()[:7]}...')
|
||||
data = data.replace(old_url,new_url)
|
||||
open(file,'wb').write(data)
|
||||
|
||||
if os.path.split(file)[1] == 'licupgr':
|
||||
url_dict = {
|
||||
os.environ['MIKRO_RENEW_URL'].encode():os.environ['CUSTOM_RENEW_URL'].encode(),
|
||||
}
|
||||
for old_url,new_url in url_dict.items():
|
||||
if old_url in data:
|
||||
print(f'{file} url patched {old_url.decode()[:7]}...')
|
||||
data = data.replace(old_url,new_url)
|
||||
open(file,'wb').write(data)
|
||||
modified = True
|
||||
|
||||
if modified:
|
||||
with open(file_path, 'wb') as f:
|
||||
f.write(data)
|
||||
|
||||
def run_shell_command(command):
|
||||
process = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
Reference in New Issue
Block a user