1. Added `sessions` command to sessionkiller mode
2. Change modules repo for 4.0 to 4.0 branch (wtf why it wasn't changed before)
3. Added venv files to .gitignore
4. Black formatting
5. And some shit that I forgot to describe
This commit is contained in:
fuccsoc 2023-09-18 02:46:57 +03:00
parent 141a4ecf25
commit 228d66054d
4 changed files with 80 additions and 10 deletions

5
.gitignore vendored
View File

@ -15,4 +15,7 @@ __pycache__/
.idea
config.ini
unknown_errors.txt
.env
.env
bin/
lib/
pyvenv.cfg

View File

@ -109,7 +109,9 @@ async def main():
"auths_hashes",
[
auth.hash
for auth in (await app.send(GetAuthorizations())).authorizations
for auth in (
await app.invoke(GetAuthorizations())
).authorizations
],
)

View File

@ -14,6 +14,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# TODO: Add ability to kill session by hash
import time
from datetime import datetime
from html import escape
@ -27,10 +29,72 @@ from pyrogram.types import Message
from utils.db import db
from utils.misc import modules_help, prefix
from textwrap import dedent
from datetime import datetime
auth_hashes = db.get("core.sessionkiller", "auths_hashes", [])
@Client.on_message(filters.command(["sessions"], prefix) & filters.me)
async def sessions_list(client: Client, message: Message):
formatted_sessions = []
sessions = (await client.invoke(GetAuthorizations())).authorizations
for num, session in enumerate(sessions, 1):
formatted_sessions.append(
(
"<b>{num}</b>. <b>{model}</b> on <code>{platform}</code>\n"
"<b>Hash:</b> {hash}\n"
"<b>App name:</b> <code>{app_name}</code> v.{version}\n"
"<b>Created (last activity):</b> {created} ({last_activity})\n"
"<b>IP and location: </b>: <code>{ip}</code> (<i>{location}</i>)\n"
"<b>Official status:</b> <code>{official}</code>\n"
"<b>2FA accepted:</b> <code>{password_pending}</code>\n"
"<b>Can accept calls / secret chats:</b> {calls} / {secret_chats}"
).format(
num=num,
model=escape(session.device_model),
platform=escape(
session.platform
if session.platform != ""
else "unknown platform"
),
hash=session.hash,
app_name=escape(session.app_name),
version=escape(
session.app_version
if session.app_version != ""
else "unknown"
),
created=datetime.fromtimestamp(
session.date_created
).isoformat(),
last_activity=datetime.fromtimestamp(
session.date_active
).isoformat(),
ip=session.ip,
location=session.country,
official="" if session.official_app else "❌️",
password_pending="❌️️" if session.password_pending else "",
calls="❌️️" if session.call_requests_disabled else "",
secret_chats="❌️️"
if session.encrypted_requests_disabled
else "",
)
)
answer = "<b>Active sessions at your account:</b>\n\n"
chunk = []
for s in formatted_sessions:
chunk.append(s)
if len(chunk) == 5:
answer += "\n\n".join(chunk)
await message.reply(answer)
answer = ""
chunk.clear()
if len(chunk):
await message.reply("\n\n".join(chunk))
await message.delete()
@Client.on_message(
filters.command(["sessionkiller", "sk"], prefix) & filters.me
)
@ -49,17 +113,17 @@ async def sessionkiller(client: Client, message: Message):
elif message.command[1] in ["enable", "on", "1", "yes", "true"]:
db.set("core.sessionkiller", "enabled", True)
await message.edit("<b>Sessionkiller enabled!</b>")
db.set(
"core.sessionkiller",
"auths_hashes",
[
auth["hash"]
for auth in (await client.invoke(GetAuthorizations()))[
"authorizations"
]
auth.hash
for auth in (
await client.invoke(GetAuthorizations())
).authorizations
],
)
elif message.command[1] in ["disable", "off", "0", "no", "false"]:
db.set("core.sessionkiller", "enabled", False)
await message.edit("<b>Sessionkiller disabled!</b>")
@ -130,7 +194,8 @@ async def check_new_login(
return
modules_help["sessionkiller"] = {
modules_help["sessions"] = {
"sessionkiller [enable|disable]": "When enabled, every new session will be terminated.\n"
"Useful for additional protection for your account"
"Useful for additional protection for your account",
"sessions": "List all sessions on your account",
}

View File

@ -11,4 +11,4 @@ db_url = env.str("DATABASE_URL", "")
db_name = env.str("DATABASE_NAME")
test_server = env.bool("TEST_SERVER", False)
modules_repo_branch = env.str("MODULES_REPO_BRANCH", "main")
modules_repo_branch = env.str("MODULES_REPO_BRANCH", "4.0")