mirror of
https://git.ugnet.gay/CrossTalk/azul.git
synced 2026-11-25 08:19:55 +00:00
0.6 final
This commit is contained in:
1 parent
7c0581eb97
commit
b89e1932bb
160 files changed
+20534
-4664
No files matched your search
@@ -1,30 +0,0 @@
|
||||
from core import db
|
||||
from core.conn import Conn
|
||||
import settings
|
||||
|
||||
# TODO: INS-ize this
|
||||
def main(*ids: str) -> None:
|
||||
if not ids:
|
||||
print("Nothing to do.")
|
||||
return
|
||||
print("Deleting {} circles:".format(len(ids)))
|
||||
for i in ids:
|
||||
print('=>', i)
|
||||
ans = input("Are you sure? (y/N) ")
|
||||
if ans.lower() != 'y':
|
||||
print("Operation cancelled.")
|
||||
return
|
||||
print("Deleting.")
|
||||
|
||||
conn = Conn(settings.DB)
|
||||
with conn.session() as sess:
|
||||
circles = sess.query(db.Circle).filter(db.Circle.chat_id.in_(ids))
|
||||
circlememberships = sess.query(db.CircleMembership).filter(db.CircleMembership.chat_id.in_(ids))
|
||||
print("delete circles", len(ids))
|
||||
circlememberships.delete(synchronize_session = False)
|
||||
circles.delete(synchronize_session = False)
|
||||
sess.flush()
|
||||
|
||||
if __name__ == '__main__':
|
||||
import funcli
|
||||
funcli.main()
|
||||
@@ -1,19 +0,0 @@
|
||||
from core import db
|
||||
from core.conn import Conn
|
||||
import settings
|
||||
|
||||
# TODO: INS-ize this
|
||||
def main(*, verbose: bool = False) -> None:
|
||||
total = 0
|
||||
conn = Conn(settings.DB)
|
||||
with conn.session() as sess:
|
||||
for circle in sess.query(db.Circle).all():
|
||||
total += 1
|
||||
if verbose:
|
||||
print(circle.chat_id, circle.name)
|
||||
|
||||
print("Total:", total)
|
||||
|
||||
if __name__ == '__main__':
|
||||
import funcli
|
||||
funcli.main()
|
||||
@@ -1,27 +0,0 @@
|
||||
from datetime import datetime, timedelta
|
||||
from core import db
|
||||
from core.conn import Conn
|
||||
import settings
|
||||
|
||||
# TODO: INS-ize this
|
||||
def main(*, since: int = 60, verbose: bool = False) -> None:
|
||||
online_since = datetime.utcnow() - timedelta(minutes = since)
|
||||
total = 0
|
||||
total_online = 0
|
||||
|
||||
conn = Conn(settings.DB)
|
||||
with conn.session() as sess:
|
||||
for u in sess.query(db.User).all():
|
||||
total += 1
|
||||
if verbose:
|
||||
print(u.email)
|
||||
if online_since is not None and u.date_login is not None:
|
||||
total_online += (1 if u.date_login >= online_since else 0)
|
||||
|
||||
print("Total:", total)
|
||||
if online_since is not None:
|
||||
print("Online:", total_online)
|
||||
|
||||
if __name__ == '__main__':
|
||||
import funcli
|
||||
funcli.main()
|
||||
@@ -1,15 +0,0 @@
|
||||
import asyncio, settings
|
||||
from insclient.cmds import maintenance
|
||||
|
||||
async def main(minutes: str):
|
||||
try:
|
||||
resp = await maintenance(minutes, b'AzuL-SERV', settings.INS_LINK_PASSWORD)
|
||||
print("Operation successful!")
|
||||
except Exception as e:
|
||||
print("Operation failed:", e)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
_, minutes = sys.argv
|
||||
asyncio.run(main(minutes))
|
||||
@@ -0,0 +1,34 @@
|
||||
import getpass, hashlib, sys
|
||||
import settings
|
||||
from core import db
|
||||
|
||||
def main() -> None:
|
||||
args = sys.argv[1:]
|
||||
if args[:1] == ['--hash-key']:
|
||||
key = getpass.getpass('Admin key: ')
|
||||
if len(key) < 12:
|
||||
print('Use at least 12 characters.')
|
||||
return
|
||||
if key != getpass.getpass('Again: '):
|
||||
print('Those don\'t match.')
|
||||
return
|
||||
print('ADMIN_KEY = \'{}\''.format(hashlib.sha256(key.encode('utf-8')).hexdigest()))
|
||||
return
|
||||
off = '--off' in args
|
||||
logins = [arg for arg in args if not arg.startswith('--')]
|
||||
if len(logins) != 1:
|
||||
print('Usage: python script/makeadmin.py <e-mail or username> [--off]')
|
||||
print(' python script/makeadmin.py --hash-key')
|
||||
return
|
||||
db.ensure_schema(db.engine)
|
||||
login = logins[0]
|
||||
with db.Session() as sess:
|
||||
row = sess.query(db.User).filter((db.User.email == login) | (db.User.username == login)).one_or_none()
|
||||
if row is None:
|
||||
print('No account is called {}.'.format(login))
|
||||
return
|
||||
row.is_admin = not off
|
||||
print('{} ({}) is {} an administrator.'.format(row.username, row.email, 'no longer' if off else 'now'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,105 +0,0 @@
|
||||
from core import db
|
||||
from core.conn import Conn
|
||||
import settings
|
||||
|
||||
# TODO: INS-ize this
|
||||
def main(id: str, action: str, *args: str) -> None:
|
||||
memberships_to_add = []
|
||||
conn = Conn(settings.DB)
|
||||
with conn.session() as sess:
|
||||
circle = sess.query(db.Circle).filter(db.Circle.chat_id == id).one_or_none()
|
||||
if circle is None:
|
||||
print('Circle {} does not exist'.format(id))
|
||||
return
|
||||
if action.lower() == 'role':
|
||||
if len(args) < 2:
|
||||
print('Insufficient arguments for action role')
|
||||
return
|
||||
email = args[0]
|
||||
role = args[1]
|
||||
|
||||
user = sess.query(db.User).filter(db.User.email == email).one_or_none()
|
||||
if user is None:
|
||||
print('role: User {} does not exist'.format(email))
|
||||
return
|
||||
m = sess.query(db.CircleMembership).filter(db.CircleMembership.chat_id == circle.chat_id, db.CircleMembership.member_id == user.id).one_or_none()
|
||||
if m is None:
|
||||
print('role: User {} not a member of this circle'.format(user.email))
|
||||
return
|
||||
|
||||
if m.state != 3:
|
||||
print('role: User {}\'s role in this circle is not set to accepted'.format(user.email))
|
||||
return
|
||||
elif m.role == 1:
|
||||
print('role: User {} is an owner of this circle and cannot be set to any other role. Use "owner" to transfer their ownership to someone else'.format(user.email))
|
||||
return
|
||||
if role not in ('2','3'):
|
||||
if role == '1':
|
||||
print('role: Cannot set user {}\'s circle role to owner with this command. Use "owner" to perform this action'.format(user.email))
|
||||
else:
|
||||
print('role: Role specified is not valid. Accepted values are 2 (co-owner) and 3 (member)')
|
||||
return
|
||||
|
||||
m.role = int(role)
|
||||
memberships_to_add.append(m)
|
||||
elif action.lower() == 'owner':
|
||||
if len(args) < 1:
|
||||
print('Insufficient arguments for action owner')
|
||||
return
|
||||
email = args[0]
|
||||
|
||||
user = sess.query(db.User).filter(db.User.email == email).one_or_none()
|
||||
if user is None:
|
||||
print('owner: User {} does not exist'.format(email))
|
||||
return
|
||||
m = sess.query(db.CircleMembership).filter(db.CircleMembership.chat_id == circle.chat_id, db.CircleMembership.member_id == user.id).one_or_none()
|
||||
if m is None:
|
||||
print('role: User {} not a member in this circle'.format(user.email))
|
||||
return
|
||||
|
||||
if m.state != 3:
|
||||
print('owner: User {}\'s role in circle is not set to accepted'.format(user.email))
|
||||
return
|
||||
if m.role == 1:
|
||||
print('owner: User {} is already owner'.format(user.email))
|
||||
return
|
||||
|
||||
m_owner = sess.query(db.CircleMembership).filter(db.CircleMembership.chat_id == circle.chat_id, db.CircleMembership.role == 1).one_or_none()
|
||||
if m_owner is not None:
|
||||
m_owner.role = 3
|
||||
m.role = 1
|
||||
memberships_to_add.append(m)
|
||||
if m_owner is not None:
|
||||
memberships_to_add.append(m_owner)
|
||||
elif action.lower() == 'remove':
|
||||
if len(args) < 1:
|
||||
print('Insufficient arguments for action remove')
|
||||
return
|
||||
email = args[0]
|
||||
|
||||
user = sess.query(db.User).filter(db.User.email == email).one_or_none()
|
||||
if user is None:
|
||||
print('remove: User {} does not exist'.format(email))
|
||||
return
|
||||
m = sess.query(db.CircleMembership).filter(db.CircleMembership.chat_id == circle.chat_id, db.CircleMembership.member_id == user.id).one_or_none()
|
||||
if m is None or m.state == 0:
|
||||
print('remove: User {} not a member in this circle'.format(user.email))
|
||||
return
|
||||
if m.role == 1:
|
||||
print('remove: User {} is an owner and cannot be removed from circle'.format(user.email))
|
||||
return
|
||||
|
||||
m.role = 3
|
||||
m.state = 0
|
||||
memberships_to_add.append(m)
|
||||
else:
|
||||
print('Invalid action')
|
||||
|
||||
if memberships_to_add:
|
||||
sess.add_all(memberships_to_add)
|
||||
sess.flush()
|
||||
print('Action successfully performed')
|
||||
|
||||
if __name__ == '__main__':
|
||||
import funcli
|
||||
funcli.main()
|
||||
@@ -1,125 +0,0 @@
|
||||
import asyncio, ast, json, settings
|
||||
from insclient.cmds import list_sessions, session_detail, session_delete
|
||||
|
||||
async def main(action: str, id: str | None):
|
||||
try:
|
||||
def _print_sessions(resp):
|
||||
if not resp or resp[0] != 'ALLTHESESSIONS':
|
||||
print("No sessions returned or unexpected response format")
|
||||
return
|
||||
tokens = resp[2:]
|
||||
buf = []
|
||||
sessions = []
|
||||
i = 0
|
||||
while i < len(tokens):
|
||||
tok = tokens[i]
|
||||
if tok.startswith('"'):
|
||||
buf = [tok]
|
||||
while not buf[-1].endswith('"') and i + 1 < len(tokens):
|
||||
i += 1
|
||||
buf.append(tokens[i])
|
||||
raw = " ".join(buf).strip('"')
|
||||
try:
|
||||
sid, uuid, email, raw_meta = raw.split('|', 3)
|
||||
meta = ast.literal_eval(raw_meta)
|
||||
sessions.append((sid, uuid, email, meta))
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
buf = [tok]
|
||||
if tok.endswith('}'):
|
||||
raw = " ".join(buf)
|
||||
try:
|
||||
sid, uuid, email, raw_meta = raw.split('|', 3)
|
||||
meta = ast.literal_eval(raw_meta)
|
||||
sessions.append((sid, uuid, email, meta))
|
||||
except Exception:
|
||||
pass
|
||||
i += 1
|
||||
|
||||
for sid, uuid, email, meta in sessions:
|
||||
print(
|
||||
f" Session ID:\t {sid}\n"
|
||||
f" UUID:\t\t {uuid}\n"
|
||||
f" Email:\t {email}\n"
|
||||
f" Client:\t {meta.get('program')}\n"
|
||||
f" Version:\t {meta.get('version')}\n"
|
||||
f" Method:\t {meta.get('via')}\n"
|
||||
)
|
||||
|
||||
if action == 'list_all':
|
||||
resp = await list_sessions(None, b'AzuL-SERV', settings.INS_LINK_PASSWORD)
|
||||
_print_sessions(resp)
|
||||
return
|
||||
|
||||
elif action == 'list_by_user':
|
||||
resp = await list_sessions(id, b'AzuL-SERV', settings.INS_LINK_PASSWORD)
|
||||
_print_sessions(resp)
|
||||
return
|
||||
|
||||
elif action == 'details':
|
||||
resp = await session_detail(id, b'AzuL-SERV', settings.INS_LINK_PASSWORD)
|
||||
if not resp or resp[0] != 'SESSION':
|
||||
print("No such session or unexpected response")
|
||||
return
|
||||
|
||||
if len(resp) >= 3 and resp[2] == 'KILLED':
|
||||
print(f"Session {id} was killed")
|
||||
return
|
||||
|
||||
_, ts, sess_id, username, uuid, email, uin = resp[:7]
|
||||
chat_enabled = resp[-1]
|
||||
meta_tokens = resp[7:-1]
|
||||
|
||||
raw_client = ''
|
||||
if not meta_tokens:
|
||||
raw_client = ''
|
||||
elif len(meta_tokens) == 1:
|
||||
token = meta_tokens[0]
|
||||
if token.startswith('"') and token.endswith('"'):
|
||||
raw_client = token.strip('"')
|
||||
else:
|
||||
raw_client = token
|
||||
else:
|
||||
combined = " ".join(meta_tokens)
|
||||
if combined.startswith('"') and combined.endswith('"'):
|
||||
raw_client = combined.strip('"')
|
||||
else:
|
||||
raw_client = combined
|
||||
|
||||
try:
|
||||
client_meta = ast.literal_eval(raw_client) if raw_client else {}
|
||||
except Exception:
|
||||
client_meta = {}
|
||||
|
||||
print(f" Details for session {sess_id}:")
|
||||
print(f" Username:\t {username}")
|
||||
print(f" UUID:\t\t {uuid}")
|
||||
print(f" Email:\t {email}")
|
||||
print(f" UIN:\t\t {uin}")
|
||||
print(f" Chat enabled:\t {chat_enabled}")
|
||||
print(" Client info:")
|
||||
for k, v in client_meta.items():
|
||||
print(f"\t{k}: {v}")
|
||||
return
|
||||
|
||||
elif action in ('close', 'kill'):
|
||||
await session_delete(id, b'AzuL-SERV', settings.INS_LINK_PASSWORD)
|
||||
print("Operation successful")
|
||||
return
|
||||
|
||||
else:
|
||||
print('Unknown action. Valid actions: list_all, list_by_user, details, close, kill')
|
||||
return
|
||||
|
||||
except Exception as e:
|
||||
print("Operation failed:", e)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
|
||||
_, action, *rest = sys.argv
|
||||
id_arg = rest[0] if rest else None
|
||||
|
||||
asyncio.run(main(action, id_arg))
|
||||
@@ -1,101 +0,0 @@
|
||||
# TODO: holy shit clean this up this is awful
|
||||
import argparse, asyncio, getpass, settings
|
||||
from insclient.cmds import usercreate, userupdate, userdelete
|
||||
from core.conn import Conn
|
||||
from core import db
|
||||
|
||||
def _parse_args():
|
||||
p = argparse.ArgumentParser(prog='manageuser.py')
|
||||
sub = p.add_subparsers(dest='cmd', required=True)
|
||||
|
||||
sc_create = sub.add_parser('create')
|
||||
sc_create.add_argument('email')
|
||||
sc_create.add_argument('username')
|
||||
sc_create.add_argument('first_name')
|
||||
sc_create.add_argument('last_name')
|
||||
sc_create.add_argument('uin', type=int)
|
||||
sc_create.add_argument('--password', '-p', help='user password (if omitted, prompted)')
|
||||
sc_create.add_argument('--oldmsn', action='store_true')
|
||||
sc_create.add_argument('--yahoo', action='store_true')
|
||||
sc_create.add_argument('--oldaim', action='store_true')
|
||||
sc_create.add_argument('--msim', action='store_true')
|
||||
|
||||
sc_mod = sub.add_parser('modify')
|
||||
sc_mod.add_argument('email')
|
||||
sc_mod.add_argument('field')
|
||||
sc_mod.add_argument('value')
|
||||
sc_mod.add_argument('--oldmsn', action='store_true', help='also (re)generate legacy MSN MD5 hash when changing password')
|
||||
sc_mod.add_argument('--yahoo', action='store_true', help='also (re)generate legacy Yahoo hashes when changing password')
|
||||
sc_mod.add_argument('--oldaim', action='store_true', help='also (re)generate legacy AIM MD5 hash when changing password')
|
||||
sc_mod.add_argument('--msim', action='store_true', help='also (re)generate legacy MSIM SHA-1 hash when changing password')
|
||||
|
||||
sc_del = sub.add_parser('delete')
|
||||
sc_del.add_argument('email', help='email of the user to delete')
|
||||
|
||||
return p.parse_args()
|
||||
|
||||
async def _do_create(email: str, username: str, first_name: str, last_name: str, uin: int, user_password: str, oldmsn: bool, yahoo: bool, oldaim: bool, msim: bool) -> None:
|
||||
try:
|
||||
await usercreate(
|
||||
email, username, first_name, last_name, uin, user_password,
|
||||
oldmsn, yahoo, oldaim, msim, b'AzuL-SERV', settings.INS_LINK_PASSWORD
|
||||
)
|
||||
print("Operation successful!")
|
||||
except Exception as e:
|
||||
print("Operation failed:", e)
|
||||
|
||||
async def _do_modify(email: str, field: str, value: str, oldmsn: bool, yahoo: bool, oldaim: bool, msim: bool) -> None:
|
||||
conn = Conn(settings.DB)
|
||||
with conn.session() as sess:
|
||||
user = sess.query(db.User).filter(db.User.email == email).first()
|
||||
if not user:
|
||||
print('User does not exist.')
|
||||
return
|
||||
uuid = user.uuid
|
||||
|
||||
if field == 'password' and value == '-':
|
||||
value = getpass.getpass('Password: ')
|
||||
|
||||
try:
|
||||
if field == 'password':
|
||||
await userupdate(uuid, field, value, b'AzuL-SERV', settings.INS_LINK_PASSWORD, support_old_msn=oldmsn, support_yahoo=yahoo, support_aim=oldaim, support_msim=msim)
|
||||
else:
|
||||
await userupdate(uuid, field, value, b'AzuL-SERV', settings.INS_LINK_PASSWORD)
|
||||
print("Operation successful!")
|
||||
except Exception as e:
|
||||
print("Operation failed:", e)
|
||||
|
||||
async def _do_delete(email: str) -> None:
|
||||
conn = Conn(settings.DB)
|
||||
with conn.session() as sess:
|
||||
user = sess.query(db.User).filter(db.User.email == email).first()
|
||||
if not user:
|
||||
print('User does not exist.')
|
||||
return
|
||||
uuid = user.uuid
|
||||
|
||||
try:
|
||||
await userdelete(uuid, b'AzuL-SERV', settings.INS_LINK_PASSWORD)
|
||||
print("Operation successful!")
|
||||
except Exception as e:
|
||||
print("Operation failed:", e)
|
||||
|
||||
def main():
|
||||
args = _parse_args()
|
||||
if args.cmd == 'create':
|
||||
pw = args.password
|
||||
if not pw:
|
||||
pw = getpass.getpass('Password: ')
|
||||
asyncio.run(_do_create(
|
||||
args.email, args.username, args.first_name, args.last_name, args.uin,
|
||||
pw, args.oldmsn, args.yahoo, args.oldaim, args.msim
|
||||
))
|
||||
elif args.cmd == 'modify':
|
||||
asyncio.run(_do_modify(
|
||||
args.email, args.field, args.value, args.oldmsn, args.yahoo, args.oldaim, args.msim
|
||||
))
|
||||
elif args.cmd == 'delete':
|
||||
asyncio.run(_do_delete(args.email))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,24 +0,0 @@
|
||||
import asyncio, settings
|
||||
from insclient.cmds import alert
|
||||
|
||||
async def main(emails: str):
|
||||
message = input('Enter alert message: ').strip()
|
||||
if not message:
|
||||
print('Message is required.')
|
||||
return
|
||||
|
||||
url = input('Enter a URL (or leave blank): ').strip() or ''
|
||||
icon = input('Enter an icon URL (or leave blank): ').strip() or ''
|
||||
targets = emails if emails.strip() and emails.strip() != '*' else 'all'
|
||||
|
||||
try:
|
||||
await alert(message, b'AzuL-SERV', settings.INS_LINK_PASSWORD, url, icon, targets)
|
||||
print("Operation successful!")
|
||||
except Exception as e:
|
||||
print("Operation failed:", e)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
_, emails = sys.argv
|
||||
asyncio.run(main(emails))
|
||||
Reference in new issue
Block a user