This commit is contained in:
Arthur K. 2025-03-15 13:52:06 +03:00
parent 365e0feddc
commit ce19d6a62c
Signed by: wzray
GPG key ID: B97F30FDC4636357
24 changed files with 212 additions and 96 deletions

View file

@ -11,6 +11,6 @@ else
exit 1
fi
ssh -p 8022 u0_a343@"$phone_ip" 'su -c setprop service.adb.tcp.port 5555 && su -c stop adbd && su -c start adbd'
ssh -p 8022 u0_a230@"$phone_ip" 'su -c setprop service.adb.tcp.port 5555 && su -c stop adbd && su -c start adbd'
sleep 0.1
adb connect "$phone_ip"

View file

@ -3,7 +3,7 @@
url="$(git remote get-url "${1:-origin}")"
if [[ "$url" =~ ^https?:\/\/ ]]; then
echo "$url"
xdg-open "$url"
elif [[ "$url" =~ ^[a-zA-Z0-9_-]+@([a-zA-Z0-9_.-]+):(.*) ]]; then
url="https://${BASH_REMATCH[1]}/${BASH_REMATCH[2]}"
url="${url%.git}"

View file

@ -46,8 +46,6 @@ def run_until_successful(fn: Callable[..., T], *args, **kwargs) -> T:
return fn(*args, **kwargs)
except Exception:
pass
else:
break # no it's not >( # pyright: ignore
def send_message(chat_id: int, text: str, token: str):
@ -180,14 +178,22 @@ class Api:
self._first_auth()
def get_status_list(self):
def _make_request(self, method: Literal["GET", "POST"], endpoint: str):
self._ensure_authorized()
r = run_until_successful(self._session.get, 'https://my.itmo.ru/api/requests/my', timeout=2)
r = run_until_successful(self._session.request, method, f'https://my.itmo.ru/api/{endpoint}', timeout=2)
if r.status_code == 403:
self._first_auth() # do full reauth if 403 after self._ensure_authorized()
r = run_until_successful(self._session.request, method, f'https://my.itmo.ru/api/{endpoint}', timeout=2)
if r.status_code != 200 or r.json()['error_code'] != 0:
raise ApiException(r.status_code, r.text)
return [StatusObject.from_dict(obj) for obj in r.json()['result']]
return r.json()
def get_status_list(self):
return [StatusObject.from_dict(obj) for obj in self._make_request('GET', 'requests/my')['result']]
def to_dict(self) -> Any:
@ -305,13 +311,13 @@ def main():
print('\n'.join(map(format_status, message)))
file.write(' '.join(map(format_status, message)))
# update_filter = LastUpdateFilter(ignore_now=True)
# for message in listen_for_messages(api, filter_func=update_filter):
# formatted_messages = list(map(format_message, message))
# print('\n---\n'.join(formatted_messages))
# for message in formatted_messages:
# send_message(owner_id, message, bot_token)
# update_filter.update()
update_filter = LastUpdateFilter(ignore_now=True)
for message in listen_for_messages(api, filter_func=update_filter):
formatted_messages = list(map(format_message, message))
print('\n---\n'.join(formatted_messages))
for message in formatted_messages:
send_message(owner_id, message, bot_token)
update_filter.update()
if __name__ == "__main__":

View file

@ -1,17 +1,18 @@
#!/bin/bash
IFNAME="wg_lva"
PIPE="/var/run/vpnd.sock"
send_cmd() {
[ -p $PIPE ] && echo "$@" > $PIPE && \
cat < $PIPE
}
IFNAME="rix"
while [ "$#" -gt 0 ]; do
case "$1" in
'd'|'-d'|'--dpi') DPI="_d"
;;
'm'|'msk') IFNAME='wg_msk'
;;
'-v'|'--verbose') VERBOSE=1
;;
*) echo "Wrong argument!"; exit 1
;;
'm'|'msk') IFNAME='msk';;
'-v'|'--verbose') VERBOSE=1;;
*) echo "Wrong argument!"; exit 1;;
esac
shift
done
@ -22,18 +23,17 @@ else
set -x
fi
UP_NAME="$(ip link show | grep 'wg' | cut -d ' ' -f 2 | sed 's/://')"
UP_NAME="$(send_cmd status)"
IFNAME="${IFNAME}${DPI}"
if [ -n "${UP_NAME}" ]; then
if [ "${UP_NAME}" != "${IFNAME}" ]; then
wg-quick down "${UP_NAME}"
wg-quick up "${IFNAME}"
send_cmd down
send_cmd up "$IFNAME"
else
wg-quick down "${UP_NAME}"
send_cmd down
fi
else
wg-quick up "${IFNAME}"
send_cmd up "$IFNAME"
fi
pkill -36 dwmblocks

View file

@ -2,6 +2,7 @@
# shellcheck disable=SC2034
die() {
[ -n "$oc_pid" ] && kill -s TERM $oc_pid
echo "exitting..."
rm -f $PIPE
exit 0
@ -11,6 +12,7 @@ trap 'die' SIGTERM SIGQUIT SIGINT
PIPE="/var/run/vpnd.sock"
oc_pid=
up_name=
[ -p $PIPE ] && exit 1
[ "$(id -u)" != "0" ] && exit 1
@ -21,7 +23,7 @@ for config in /etc/openconnect/config_*; do
CONFIGS+=("${config#config_}")
done
COMMANDS=("up" "down")
COMMANDS=("up" "down" "status")
in_arr() {
declare -n arr="$2"
@ -37,12 +39,22 @@ down() {
kill -s TERM $oc_pid
wait $oc_pid
oc_pid=
up_name=
}
up() {
[ -n "$oc_pid" ] && down
openconnect --config "/etc/openconnect/config_$1" &
oc_pid="$!"
up_name="$1"
}
status() {
# if [ -z "$up_name" ]; then
# echo "DOWN" > $PIPE
# else
# fi
echo "$up_name" > $PIPE
}
main() {
@ -50,18 +62,25 @@ main() {
while :; do
read -r cmd ifname < $PIPE
if ! in_arr "$ifname" "CONFIGS"; then
echo "ERROR: Invalid interface $ifname" > $PIPE
elif ! in_arr "$cmd" "COMMANDS"; then
if ! in_arr "$cmd" "COMMANDS"; then
echo "ERROR: Invalid command $cmd" > $PIPE
else
case "$cmd" in
"up") up "$ifname" > $PIPE ;;
"down") down > $PIPE ;;
"up")
if ! in_arr "$ifname" "CONFIGS"; then
echo "ERROR: Invalid interface $ifname" > $PIPE
else
up "$ifname"
echo "$ifname" > $PIPE
fi
;;
"down") down; echo "down" > $PIPE;;
"status") status;;
esac
fi
done
}
echo "Running..."
main

View file

@ -1,7 +0,0 @@
#!/bin/bash
PIPE="/var/run/vpnd.sock"
[ -p $PIPE ] &&
echo "$@" > $PIPE &&
cat < $PIPE

View file

@ -25,14 +25,13 @@ remove() {
}
# shellcheck disable=SC1091
create_or_activate() {
# shellcheck disable=SC1091
if [ -d "${VENV_FOLDER}" ]; then
source "${VENV_FOLDER}/bin/activate"
else
if [ ! -d "${VENV_FOLDER}" ]; then
python3 -m venv "${VENV_FOLDER}"
source "${VENV_FOLDER}/bin/activate"
fi
source "${VENV_FOLDER}/bin/activate"
}

View file

@ -1,7 +1,19 @@
#!/bin/bash
IFNAME="$(ip link show | grep 'wg_' | cut -d ' ' -f 2 | sed 's/://' | sed 's/wg_//' | tr '[:lower:]' '[:upper:]' | sed 's/_D/ (dpi)/')"
if [ -n "${IFNAME}" ]; then
echo "󰦝 ${IFNAME}"
PIPE="/var/run/vpnd.sock"
send_cmd() {
[ -p $PIPE ] && echo "$@" > $PIPE && \
cat < $PIPE
}
IFNAME="$(send_cmd status)"
case "$IFNAME" in
"msk") IFNAME="Moscow";;
"rix") IFNAME="Riga";;
esac
if [ -n "$IFNAME" ]; then
echo "󰦝 $IFNAME"
fi