-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dumpyara: rebrand for personal usage [skip ci]
* Setup a python bot with venv * Setup a github workflow Change-Id: I746c928ccd13e80b44175448a731ba4905328afc
- Loading branch information
1 parent
3754745
commit df6271f
Showing
5 changed files
with
165 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Dump | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
env: | ||
DUMP_URL: "" # Direct url to a recovery zip | ||
|
||
jobs: | ||
dump: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Set up Git | ||
uses: actions/checkout@v3 | ||
|
||
- name: Create .githubtoken file | ||
run: echo "${{ secrets.GIT_TOKEN }}" > .githubtoken | ||
|
||
- name: Create .tgtoken file | ||
run: echo "${{ secrets.TELEGRAM_TOKEN }}" > .tgtoken | ||
|
||
- name: Set up environment | ||
run: bash setup.sh | ||
|
||
# protobuf-compiler is required for this | ||
#- name: Install otadump | ||
# uses: actions-rs/install@v0.1 | ||
# with: | ||
# crate: otadump | ||
# version: latest | ||
|
||
- name: Run dumpyara | ||
run: bash dumpyara.sh "$DUMP_URL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[Unit] | ||
Description=Dumpyara service | ||
After=multi-user.target | ||
|
||
[Service] | ||
# Base settings | ||
Type=simple | ||
Restart=always | ||
RestartSec=10 | ||
|
||
# Execution parameters | ||
User=itsvixano | ||
WorkingDirectory=/home/itsvixano/bot/dumpyara | ||
ExecStart=/bin/sh -c 'source .venv/bin/activate && python3 main.py' | ||
|
||
# Limit damage in case something goes awry | ||
MemoryLimit=512M | ||
CPUQuota=200% | ||
|
||
# Security | ||
PrivateTmp=true | ||
ProtectSystem=full | ||
NoNewPrivileges=true | ||
ProtectControlGroups=true | ||
ProtectKernelModules=true | ||
ProtectKernelTunables=true | ||
PrivateDevices=true | ||
RestrictAddressFamilies=AF_INET AF_INET6 | ||
RestrictNamespaces=true | ||
RestrictRealtime=true | ||
SystemCallArchitectures=native | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/python3 | ||
|
||
# pip install pyTelegramBotAPI | ||
|
||
import os | ||
import subprocess | ||
import telebot | ||
import re | ||
|
||
allowed_user_ids = [ | ||
172222663, # GiovanniRN5 | ||
690187343, # lostark13 | ||
419006851, # dereference | ||
] | ||
|
||
# Read the Telegram token from the file | ||
token_file = ".tgtoken" | ||
with open(token_file, "r") as file: | ||
bot_token = file.read().strip() | ||
|
||
bot = telebot.TeleBot(bot_token) | ||
|
||
|
||
def is_valid_url(url): | ||
regex = re.compile( | ||
r"^(https?:\/\/)?(www\.)?([^\s.]+\.\S{2,}|localhost[\:?\d]*)\S*$" | ||
) | ||
return re.match(regex, url) | ||
|
||
|
||
@bot.message_handler(commands=["alive"]) | ||
def check_alive(message): | ||
chat_id = message.chat.id | ||
bot.send_message(chat_id, "I'm alive and ready to go!") | ||
|
||
|
||
@bot.message_handler(commands=["dump"]) | ||
def dump(message): | ||
chat_id = message.chat.id | ||
user_id = message.from_user.id | ||
file_path = ".github/workflows/dump.yml" | ||
|
||
if user_id not in allowed_user_ids: | ||
bot.send_message(chat_id, "You are not authorized to use this command.") | ||
return | ||
|
||
# Extract the url from the message | ||
dump_url = ( | ||
message.text.split(" ", 1)[1].strip() | ||
if len(message.text.split(" ", 1)) > 1 | ||
else "" | ||
) | ||
|
||
if not is_valid_url(dump_url): | ||
bot.send_message(chat_id, "Invalid URL provided.") | ||
return | ||
|
||
try: | ||
with open(file_path, "r") as file: | ||
lines = file.readlines() | ||
|
||
with open(file_path, "w") as file: | ||
for line in lines: | ||
if line.startswith(" DUMP_URL:"): | ||
line = f' DUMP_URL: "{dump_url}" # Direct url to a recovery zip\n' | ||
file.write(line) | ||
|
||
# Commit and push the changes | ||
subprocess.run(["git", "add", "."]) | ||
subprocess.run(["git", "commit", "-m", dump_url, "--no-gpg-sign", "--allow-empty"]) | ||
subprocess.run(["git", "push"]) | ||
|
||
bot.send_message(chat_id, "Dump started successfully!") | ||
bot.send_message( | ||
chat_id, | ||
"Feel free to check the dump progress [here](https://github.com/Jiovanni-dump/dumpyara/actions)", | ||
parse_mode="Markdown", | ||
) | ||
except Exception as e: | ||
bot.send_message(chat_id, f"An error occurred: {str(e)}") | ||
|
||
if __name__ == '__main__': | ||
bot.polling() |