mirror of
https://github.com/elseif/MikroTikPatch.git
synced 2026-08-26 10:05:50 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba0ffe3cd7 | ||
|
|
7cf469dc0c | ||
|
|
30d6ac5fe6 | ||
|
|
7fd1b6c563 | ||
|
|
ed3dcd0ab1 | ||
|
|
0a270a1108 |
32
.github/workflows/mikrotik_patch_7.yml
vendored
32
.github/workflows/mikrotik_patch_7.yml
vendored
@@ -207,7 +207,7 @@ jobs:
|
||||
- name: Cache mikrotik-${{ env.LATEST_VERSION }}${{ env.ARCH }}.iso
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && (matrix.arch == 'x86' || matrix.arch == 'arm64')
|
||||
id: cache-mikrotik
|
||||
uses: actions/cache@v4
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
mikrotik.iso
|
||||
@@ -222,7 +222,7 @@ jobs:
|
||||
- name: Cache refind
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86'
|
||||
id: cache-refind
|
||||
uses: actions/cache@v4
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: refind-bin-0.14.2.zip
|
||||
key: refind
|
||||
@@ -235,7 +235,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
|
||||
@@ -332,7 +332,7 @@ jobs:
|
||||
- name: Cache chr-${{ env.LATEST_VERSION }}${{ env.ARCH }}.img.zip
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && (matrix.arch == 'x86' || matrix.arch == 'arm64')
|
||||
id: cache-chr-img
|
||||
uses: actions/cache@v4
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
chr.img
|
||||
@@ -588,7 +588,7 @@ jobs:
|
||||
- name: Cache all_packages${{ env.ARCH }}-${{ env.LATEST_VERSION }}.zip
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch != 'x86' && matrix.arch != 'arm64'
|
||||
id: cache-all-packages
|
||||
uses: actions/cache@v4
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: all_packages.zip
|
||||
key: all_packages${{ env.ARCH }}-${{ env.LATEST_VERSION }}.zip
|
||||
@@ -602,7 +602,7 @@ jobs:
|
||||
- name: Cache Main package routeros-${{ env.LATEST_VERSION }}${{ env.ARCH }}.npk
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch != 'x86' && matrix.arch != 'arm64'
|
||||
id: cache-main-package
|
||||
uses: actions/cache@v4
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: routeros.npk
|
||||
key: routeros-${{ env.LATEST_VERSION }}${{ env.ARCH }}.npk
|
||||
@@ -672,7 +672,7 @@ jobs:
|
||||
- name: Cache NetInstall ${{ env.LATEST_VERSION }}${{ env.ARCH }}
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && env.RELEASE == 'true'
|
||||
id: cache-netinstall
|
||||
uses: actions/cache@v4
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: |
|
||||
netinstall.zip
|
||||
@@ -711,6 +711,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 }}
|
||||
@@ -775,7 +789,7 @@ jobs:
|
||||
|
||||
- name: Create Release tag ${{ env.LATEST_VERSION }} ${{ env.ARCH }}
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && env.RELEASE == 'true'
|
||||
uses: softprops/action-gh-release@v2
|
||||
uses: softprops/action-gh-release@v3
|
||||
with:
|
||||
name: "RouterOS ${{ env.LATEST_VERSION }} ${{ env.ARCH }}"
|
||||
body_path: "CHANGELOG"
|
||||
@@ -792,7 +806,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")
|
||||
|
||||
|
||||
|
||||
|
||||
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