Skip to content

Commit

Permalink
add entry point for bitsrun
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerwooo committed Nov 12, 2022
1 parent fbd4a62 commit 05bf830
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 106 deletions.
9 changes: 5 additions & 4 deletions bitsrun/__main__.py → bitsrun/cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import argparse
import sys

from .action import Action
from .config import read_config
from .user import User
from bitsrun.action import Action
from bitsrun.config import read_config
from bitsrun.user import User


def main():
Expand All @@ -27,10 +27,11 @@ def main():
try:
if args.action == "login":
res = user.do_action(Action.LOGIN)
print(res)

# Output login result by default if not silent
if not args.silent:
print(f"{res.get('username')} ({res.get('real_name')}) logged in")
print(f"{res.get('username')} ({res.get('online_ip')}) logged in")

else:
res = user.do_action(Action.LOGOUT)
Expand Down
19 changes: 15 additions & 4 deletions bitsrun/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@

from requests import Session

from .action import Action
from .exception import AlreadyLoggedOutException, AlreadyOnlineException, UsernameUnmatchedException
from .utils import fkbase64, get_user_info, parse_homepage, xencode
from bitsrun.action import Action
from bitsrun.exception import (
AlreadyLoggedOutException,
AlreadyOnlineException,
UsernameUnmatchedException,
)
from bitsrun.utils import fkbase64, get_user_info, parse_homepage, xencode

API_BASE = "http://10.0.0.55"
TYPE_CONST = 1
Expand Down Expand Up @@ -74,7 +78,14 @@ def _make_params(self, action: Action) -> Dict[str, str]:
info = "{SRBX1}" + fkbase64(xencode(json_data, token))
chksum = sha1(
"{0}{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}{7}".format(
token, self.username, hmd5, self.acid, self.ip, N_CONST, TYPE_CONST, info
token,
self.username,
hmd5,
self.acid,
self.ip,
N_CONST,
TYPE_CONST,
info,
).encode()
).hexdigest()

Expand Down
14 changes: 12 additions & 2 deletions bitsrun/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ def ordat(msg, idx):
msg_len = len(msg)
pwd = []
for i in range(0, msg_len, 4):
pwd.append(ordat(msg, i) | ordat(msg, i + 1) << 8 | ordat(msg, i + 2) << 16 | ordat(msg, i + 3) << 24)
pwd.append(
ordat(msg, i)
| ordat(msg, i + 1) << 8
| ordat(msg, i + 2) << 16
| ordat(msg, i + 3) << 24
)
if key:
pwd.append(msg_len)
return pwd
Expand All @@ -111,7 +116,12 @@ def lencode(msg, key) -> str:
return ""
ll = m
for i in range(0, msg_len):
msg[i] = chr(msg[i] & 0xFF) + chr(msg[i] >> 8 & 0xFF) + chr(msg[i] >> 16 & 0xFF) + chr(msg[i] >> 24 & 0xFF)
msg[i] = (
chr(msg[i] & 0xFF)
+ chr(msg[i] >> 8 & 0xFF)
+ chr(msg[i] >> 16 & 0xFF)
+ chr(msg[i] >> 24 & 0xFF)
)
if key:
return "".join(msg)[0:ll]
return "".join(msg)
Expand Down
7 changes: 0 additions & 7 deletions login-bit.sh

This file was deleted.

Loading

0 comments on commit 05bf830

Please sign in to comment.