Compare commits
346 commits
for_sqlite
...
main
Author | SHA1 | Date | |
---|---|---|---|
9bf5a82343 | |||
a4dad36dff | |||
368d51d5f7 | |||
c7c8da46ed | |||
9d17d2cb4b | |||
6e49fc5431 | |||
1eb535408b | |||
2861c9ffd4 | |||
5604c7a2bb | |||
af18cae3ff | |||
c8d6517c3c | |||
683be42817 | |||
a8bf3ab4b7 | |||
ecfc39695a | |||
9e01485e0a | |||
a0056ef2c4 | |||
08a1178209 | |||
4547e05700 | |||
bc35550693 | |||
461bcf6fba | |||
ee4061d10b | |||
d643e6d1ba | |||
e65f6024d3 | |||
43519b104d | |||
2d963de60f | |||
6e7b59de65 | |||
aeb67bf093 | |||
98574811f3 | |||
d4fb94c0a2 | |||
df9100d66f | |||
b6bbefbcbe | |||
d1cf551fd3 | |||
b704606dec | |||
07742da1f5 | |||
4969680f09 | |||
d88a40a360 | |||
5de0d66829 | |||
af62f218c2 | |||
e3d0e2ae24 | |||
5bff1f6a16 | |||
a2c7fd6f05 | |||
a5b7ba9c18 | |||
dba2358534 | |||
bef78a85d6 | |||
d932730ed7 | |||
ace3cab44b | |||
12415c9674 | |||
9474eaa739 | |||
b9b55ac2f9 | |||
5488be9ec9 | |||
aa413cee19 | |||
5c7611481c | |||
ae117944c0 | |||
b835fe5a74 | |||
35aad379a4 | |||
781e408910 | |||
98e45292ab | |||
d2bb01533b | |||
8a69b25d52 | |||
b96496018f | |||
76df98f6d8 | |||
7960315a40 | |||
1385eff922 | |||
d93111b723 | |||
d6e046178e | |||
f237d4ce06 | |||
0b718125ee | |||
970e04bc75 | |||
b0865354a3 | |||
dfb21e3a25 | |||
c82351e186 | |||
5f17506447 | |||
ab96092b39 | |||
cb3bc05faf | |||
6bf928ac13 | |||
31fd32acc9 | |||
364b32c0e7 | |||
8775b22738 | |||
6fae61351d | |||
69cb9537ff | |||
42e36bf1c4 | |||
224492568a | |||
aa9379b2a6 | |||
421b1b48c7 | |||
aebab83b86 | |||
33dd3aef9b | |||
02e0b8b95d | |||
885f625403 | |||
1cd58404c6 | |||
6ea299f661 | |||
f13d119eb2 | |||
ff30611ebd | |||
65d1f6e568 | |||
fc16d15ef9 | |||
f1967f0388 | |||
db16ddce29 | |||
3575818af8 | |||
f7f3e5d40b | |||
4f78a54b2f | |||
5578cffad6 | |||
0fc7c0c3eb | |||
fd8b5e3a8b | |||
71ca2c0cda | |||
99fd556319 | |||
6b617a6a63 | |||
1e1ab94dcf | |||
b090e27056 | |||
8c8e9e6f06 | |||
83ef0bbd07 | |||
20b46e8c40 | |||
84d1b0cb59 | |||
7b75da62a3 | |||
ab6e77a99f | |||
a28df9ad77 | |||
9389441262 | |||
45d6b9f3c8 | |||
45b1b767ac | |||
8658955998 | |||
6bcb570b10 | |||
8ade781d4b | |||
cf47a5b2ad | |||
c08afa08c3 | |||
5a709197e7 | |||
e4b99a85ff | |||
9fe9330b13 | |||
65403a4cca | |||
0fcfc8009f | |||
ebef42cc55 | |||
20fa6f1fb8 | |||
7e35bd6089 | |||
61e01ae055 | |||
487dfbd96d | |||
cc771d5196 | |||
4836e6ae8f | |||
e97562b9b2 | |||
7282af55e0 | |||
611bd03b80 | |||
75fa89497e | |||
3f31307164 | |||
9279edc8ca | |||
4713dc7a23 | |||
550cf83e86 | |||
e41324eae4 | |||
b1994c5def | |||
a6c856cf48 | |||
036e1c0b0b | |||
e50a5748c9 | |||
55f989d365 | |||
cf0013e53a | |||
5384cc9668 | |||
518eea2061 | |||
77ada9a5e2 | |||
e585e9d596 | |||
86a4ef8766 | |||
631fd990cb | |||
3086f689ad | |||
b3687e8a2d | |||
4366aa06ca | |||
25f3ae6404 | |||
c6c602a34b | |||
27361d40db | |||
b6b34ce315 | |||
665b53c28d | |||
bd1aa2243c | |||
de8412e4eb | |||
bf1dc817ab | |||
2ddcc6626a | |||
d433f38d94 | |||
26f5269ce5 | |||
35ba7e0dff | |||
668af84ca8 | |||
698e629063 | |||
ef0bd4b509 | |||
3160f1c079 | |||
7bade8c366 | |||
aae08d4701 | |||
ca6ff5d050 | |||
1e8ef35e3f | |||
2d5ea6a48d | |||
125ca3e601 | |||
cd6461641c | |||
69dbdd0bc3 | |||
edd01a0d4d | |||
9269441051 | |||
7d7cc17193 | |||
4b4455694e | |||
ee4113f95d | |||
829184a91a | |||
55b55046df | |||
db55479da9 | |||
8e635eb92c | |||
c107400ed2 | |||
07fcc298a9 | |||
03319676e9 | |||
7fc3ca701c | |||
66f39eb293 | |||
19cf8e195c | |||
9cb5f22cfc | |||
d7094656a3 | |||
19afc4a57a | |||
9dc9938732 | |||
04ae26862f | |||
111686c257 | |||
8a88a1a31f | |||
8019674b13 | |||
60d4fc9c81 | |||
7a1aa6a7db | |||
f7ecdc535f | |||
3073f12e6c | |||
f304346426 | |||
b5fc778715 | |||
3aad819485 | |||
c55fd3162b | |||
7f92544102 | |||
dca3cad736 | |||
a10f5c47e9 | |||
ba9f227e09 | |||
b9d9e797d3 | |||
a9d15357c4 | |||
2663ad2ff6 | |||
425edead34 | |||
c4b4718583 | |||
16ea317730 | |||
8deb85e9fb | |||
b47305439c | |||
8e8c052b0c | |||
b5285c0f21 | |||
3bf7918bb4 | |||
a8f9ad0ec6 | |||
95e8855c27 | |||
a9109dba0a | |||
e48a0fc3c2 | |||
2edd37fbfd | |||
765a0bd2ba | |||
348fa96759 | |||
5a1ac0e3c1 | |||
5653b79906 | |||
db9afe38f2 | |||
b630d7aa98 | |||
a193d25877 | |||
1cc6d1d60f | |||
ad5f84d238 | |||
e23662422e | |||
451ea60140 | |||
e9a322f839 | |||
7b3708dd51 | |||
41788bb622 | |||
78114d3f04 | |||
ab7147ffde | |||
18de0e7b85 | |||
34ce84532d | |||
c1ce0ceb5b | |||
e3ff1a78b2 | |||
45323b2f48 | |||
b908ce17ed | |||
f7b6caca30 | |||
1bf03a600e | |||
7129a08508 | |||
585ddf8cf1 | |||
00a4c00fcf | |||
707e2e3ed6 | |||
d76ba87887 | |||
889c464c5f | |||
abf03bd4d6 | |||
b37573a371 | |||
9f59b8dab1 | |||
ce3bf1cd3c | |||
e1fee8b2e5 | |||
d640155e75 | |||
8b7e7a2a65 | |||
f26e0d9ad9 | |||
c9b7259728 | |||
aeb9553113 | |||
80a266142b | |||
62537a1038 | |||
57f428e910 | |||
18970c9079 | |||
9e4f39f8fa | |||
60af46a32b | |||
bf418936d4 | |||
73502817e0 | |||
4ecf209e7e | |||
f7f7033ea5 | |||
2ef4d639bf | |||
a16a0424dc | |||
41e85cb6bc | |||
dde933fc14 | |||
5de39f92a4 | |||
7d06ad18c4 | |||
0a7bb89a98 | |||
5cd099a411 | |||
e3d9f73fd7 | |||
a6082c1f0a | |||
18076cdf31 | |||
1147b50fd1 | |||
3e4798e8d5 | |||
f6c7342002 | |||
0f21c03003 | |||
7087090211 | |||
d8f9717304 | |||
0c4da769ac | |||
260779fca3 | |||
5c15c0b092 | |||
de96b457eb | |||
d03d5ec4ef | |||
0427c021a0 | |||
128ebc88b3 | |||
5133e550ed | |||
7d8c14c080 | |||
7093733a69 | |||
dedccf5f95 | |||
9b8d9dac2c | |||
94d4e16cfd | |||
c1e9ca4878 | |||
9dec6938dd | |||
26902aa0b3 | |||
32a183244f | |||
bd12378f3c | |||
451d7facc5 | |||
e58ae29ca7 | |||
5b9395a1d2 | |||
a52533f34b | |||
0b03527e33 | |||
4d391c7a9a | |||
3f1611dde1 | |||
bdaf1ac0d8 | |||
f2679a8307 | |||
e849afbf91 | |||
7f6bbfc420 | |||
4cbd7e1cf1 | |||
7f7b8733b6 | |||
639fd23970 | |||
f748e48517 | |||
0436035b0a | |||
b01ce7b373 | |||
b084ead6b7 | |||
a81327a680 | |||
22bc5fe240 | |||
ace0af03d6 | |||
7cfd94053e | |||
20d9d15063 | |||
dfcc4d7c37 | |||
e0e4ac73bb | |||
61219d52ef | |||
05f17d6d68 | |||
68bd6ca282 |
10
.gitignore
vendored
|
@ -50,7 +50,6 @@ coverage.xml
|
|||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
|
@ -160,5 +159,10 @@ cython_debug/
|
|||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
config/*
|
||||
db/*
|
||||
config/
|
||||
db/
|
||||
test.py
|
||||
data/
|
||||
export/
|
||||
temp/
|
||||
log/
|
||||
|
|
15
Dockerfile_auth
Normal file
|
@ -0,0 +1,15 @@
|
|||
FROM python:3
|
||||
USER root
|
||||
|
||||
RUN mkdir /dislocker
|
||||
|
||||
ENV TZ JST-9
|
||||
ENV TERM xterm
|
||||
|
||||
RUN pip install --upgrade pip
|
||||
RUN pip install --upgrade setuptools
|
||||
|
||||
RUN python -m pip install flask psycopg2-binary requests
|
||||
|
||||
WORKDIR /dislocker
|
||||
CMD python -u ./dislocker_auth.py
|
15
Dockerfile_bot
Normal file
|
@ -0,0 +1,15 @@
|
|||
FROM python:3
|
||||
USER root
|
||||
|
||||
RUN mkdir /dislocker
|
||||
|
||||
ENV TZ JST-9
|
||||
ENV TERM xterm
|
||||
|
||||
RUN pip install --upgrade pip
|
||||
RUN pip install --upgrade setuptools
|
||||
|
||||
RUN python -m pip install discord.py psycopg2-binary requests openpyxl
|
||||
|
||||
WORKDIR /dislocker
|
||||
CMD python -u ./dislocker.py
|
|
@ -1,2 +1,9 @@
|
|||
# Dislocker
|
||||
|
||||
課題研究用リポジトリ
|
||||
# 環境構築
|
||||
## サーバー側
|
||||
基本的にはDocker上での起動を推奨します。
|
||||
このリポジトリをクローンし、`docker compose up -d`で起動すると一式のコンテナが起動します。
|
||||
データベースだけを起動したい場合は、ファイルに`compose_db.yml`を指定してください。
|
||||
## クライアント側
|
||||
pyinstallerでビルドしたものを、起動してください。
|
||||
|
|
45
compose.yml
Normal file
|
@ -0,0 +1,45 @@
|
|||
services:
|
||||
bot:
|
||||
build:
|
||||
context: "./"
|
||||
dockerfile: "Dockerfile_bot"
|
||||
restart: always
|
||||
environment:
|
||||
- TZ=Asia/Tokyo
|
||||
depends_on:
|
||||
- db
|
||||
volumes:
|
||||
- ./:/dislocker
|
||||
networks:
|
||||
- dislocker_network
|
||||
|
||||
auth:
|
||||
build:
|
||||
context: "./"
|
||||
dockerfile: "Dockerfile_auth"
|
||||
restart: always
|
||||
environment:
|
||||
- TZ=Asia/Tokyo
|
||||
volumes:
|
||||
- ./:/dislocker
|
||||
ports:
|
||||
- 12244:5000
|
||||
networks:
|
||||
- dislocker_network
|
||||
|
||||
db:
|
||||
image: postgres:16-alpine3.20
|
||||
restart: always
|
||||
environment:
|
||||
- TZ=Asia/Tokyo
|
||||
volumes:
|
||||
- ./data/db:/var/lib/postgresql/data
|
||||
ports:
|
||||
- 12245:5432
|
||||
env_file:
|
||||
- ./data/.env
|
||||
networks:
|
||||
- dislocker_network
|
||||
|
||||
networks:
|
||||
dislocker_network:
|
18
compose_db.yml
Normal file
|
@ -0,0 +1,18 @@
|
|||
services:
|
||||
db:
|
||||
image: postgres:16-alpine3.20
|
||||
restart: always
|
||||
environment:
|
||||
- TZ=Asia/Tokyo
|
||||
- POSTGRES_DB=dislocker
|
||||
- POSTGRES_USER=dislocker
|
||||
- POSTGRES_PASSWORD=Password
|
||||
volumes:
|
||||
- ./data/db:/var/lib/postgresql/data
|
||||
ports:
|
||||
- 12245:5432
|
||||
networks:
|
||||
- dislocker_network
|
||||
|
||||
networks:
|
||||
dislocker_network:
|
1752
dislocker.py
484
dislocker_auth.py
Normal file
|
@ -0,0 +1,484 @@
|
|||
import psycopg2
|
||||
import os
|
||||
import json
|
||||
from flask import Flask, request, jsonify, render_template
|
||||
import uuid
|
||||
import string
|
||||
import random
|
||||
import hashlib
|
||||
|
||||
config_dir_path = "./config/"
|
||||
server_config_path = config_dir_path + "server.json"
|
||||
onetime_config_path = config_dir_path + "onetime.json"
|
||||
if not os.path.isfile(server_config_path):
|
||||
if not os.path.isdir(config_dir_path):
|
||||
os.mkdir(config_dir_path)
|
||||
|
||||
server_config = {
|
||||
"db": {
|
||||
"host": "localhost",
|
||||
"port": "5432",
|
||||
"db_name": "dislocker",
|
||||
"username": "user",
|
||||
"password": "password"
|
||||
},
|
||||
"bot": {
|
||||
"token": "TYPE HERE BOTS TOKEN KEY",
|
||||
"activity": {
|
||||
"name": "Dislocker",
|
||||
"details": "ロック中...",
|
||||
"type": "playing",
|
||||
"state": "ロック中..."
|
||||
},
|
||||
"log_channel_id" : "TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!)",
|
||||
"config_channel_id": "TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!)",
|
||||
"config_public_channel_id": "TYPE HERE CHANNEL ID (YOU MUST USE INT !!!!)"
|
||||
}
|
||||
}
|
||||
with open(server_config_path, "w") as w:
|
||||
json.dump(server_config, w, indent=4)
|
||||
elif os.path.isfile(server_config_path):
|
||||
with open(server_config_path, "r") as r:
|
||||
server_config = json.load(r)
|
||||
|
||||
class Auth():
|
||||
def __init__(self, host, db, port, user, password):
|
||||
self.db = psycopg2.connect(f"host={host} dbname={db} port={port} user={user} password={password}")
|
||||
|
||||
def token_generate(self, length):
|
||||
letters = string.ascii_letters + string.digits
|
||||
token = ''.join(random.choice(letters) for _ in range(length))
|
||||
return token
|
||||
|
||||
def master_password_generate(self, length):
|
||||
characters = string.ascii_letters + string.digits + string.punctuation
|
||||
master_password = ''.join(random.choice(characters) for _ in range(length))
|
||||
return master_password
|
||||
|
||||
def hash_genarate(self, source):
|
||||
hashed = hashlib.sha256(source.encode())
|
||||
return hashed.hexdigest()
|
||||
|
||||
def check(self, **kwargs):
|
||||
try:
|
||||
cursor = self.db.cursor()
|
||||
pc_number = int(kwargs["pc_number"])
|
||||
pc_uuid = str(kwargs["pc_uuid"])
|
||||
pc_token = str(kwargs["pc_token"])
|
||||
if "device_list" in kwargs:
|
||||
if kwargs["device_list"] == []:
|
||||
device_list = None
|
||||
else:
|
||||
device_list = kwargs["device_list"]
|
||||
else:
|
||||
device_list = None
|
||||
|
||||
keyboard_number = 0
|
||||
mouse_number = 0
|
||||
|
||||
if "password_hash" in kwargs:
|
||||
password_hash = str(kwargs["password_hash"])
|
||||
cursor.execute("SELECT * FROM pc_list WHERE pc_number = %s AND password_hash = %s AND pc_uuid = %s AND pc_token = %s", (pc_number, password_hash, pc_uuid, pc_token))
|
||||
pc_info = cursor.fetchall()
|
||||
if pc_info:
|
||||
if device_list == None:
|
||||
pass
|
||||
else:
|
||||
for device in device_list:
|
||||
cursor.execute("SELECT * FROM keyboard_list WHERE device_instance_path = %s", (device["device_instance_path"],))
|
||||
keyboard_record = cursor.fetchall()
|
||||
if keyboard_record:
|
||||
keyboard_number = int(keyboard_record[0][0])
|
||||
break
|
||||
else:
|
||||
pass
|
||||
|
||||
for device in device_list:
|
||||
cursor.execute("SELECT * FROM mouse_list WHERE device_instance_path = %s", (device["device_instance_path"],))
|
||||
mouse_record = cursor.fetchall()
|
||||
if mouse_record:
|
||||
mouse_number = int(mouse_record[0][0])
|
||||
break
|
||||
else:
|
||||
pass
|
||||
|
||||
return {"result": 0, "about": "ok", "output_dict": {"keyboard_number": keyboard_number, "mouse_number": mouse_number}}
|
||||
else:
|
||||
return {"result": 1, "about": "incorrect_password"}
|
||||
else:
|
||||
cursor.execute("SELECT * FROM pc_list WHERE pc_number = %s AND pc_uuid = %s AND pc_token = %s", (pc_number, pc_uuid, pc_token))
|
||||
pc_info = cursor.fetchall()
|
||||
if pc_info:
|
||||
return {"result": 0, "about": "ok"}
|
||||
else:
|
||||
return {"result": 1, "about": "unregistered_pc"}
|
||||
|
||||
except Exception as error:
|
||||
print("PCの登録状況を調査中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
return {"result": 1, "about": "error"}
|
||||
|
||||
finally:
|
||||
cursor.close()
|
||||
|
||||
def device_use_register(self, **kwargs):
|
||||
try:
|
||||
pc_number = int(kwargs["pc_number"])
|
||||
if kwargs["keyboard_number"] == "own":
|
||||
keyboard_number = 0
|
||||
else:
|
||||
keyboard_number = int(kwargs["keyboard_number"])
|
||||
|
||||
if kwargs["mouse_number"] == "own":
|
||||
mouse_number = 0
|
||||
else:
|
||||
mouse_number = int(kwargs["mouse_number"])
|
||||
|
||||
|
||||
cursor = self.db.cursor()
|
||||
cursor.execute("SELECT * FROM pc_list WHERE pc_number = %s", (pc_number,))
|
||||
pc_list_record = cursor.fetchall()
|
||||
pc_using_member_id = pc_list_record[0][1]
|
||||
if pc_using_member_id == None:
|
||||
return {"result": 1, "about": "not_used"}
|
||||
else:
|
||||
cursor.execute("SELECT * FROM pc_usage_history WHERE member_id = %s AND pc_number = %s ORDER BY id DESC LIMIT 1", (pc_using_member_id, pc_number))
|
||||
pc_usage_history_record = cursor.fetchall()
|
||||
pc_usage_history_record_id = pc_usage_history_record[0][0]
|
||||
|
||||
cursor.execute("UPDATE pc_usage_history SET keyboard_number = %s, mouse_number = %s WHERE id = %s", (keyboard_number, mouse_number, pc_usage_history_record_id))
|
||||
|
||||
if keyboard_number == 0:
|
||||
pass
|
||||
else:
|
||||
cursor.execute("UPDATE keyboard_list SET using_member_id = %s WHERE keyboard_number = %s", (pc_using_member_id, keyboard_number))
|
||||
|
||||
if mouse_number == 0:
|
||||
pass
|
||||
else:
|
||||
cursor.execute("UPDATE mouse_list SET using_member_id = %s WHERE mouse_number = %s", (pc_using_member_id, mouse_number))
|
||||
|
||||
self.db.commit()
|
||||
return {"result": 0, "about": "ok"}
|
||||
|
||||
except Exception as error:
|
||||
print("デバイスの使用登録中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
return {"result": 1, "about": "error"}
|
||||
|
||||
def device_register(self, **kwargs):
|
||||
try:
|
||||
cursor = self.db.cursor()
|
||||
mode = kwargs["mode"]
|
||||
number = kwargs["number"]
|
||||
device_instance_path = kwargs["device_instance_path"]
|
||||
device_name = kwargs["device_name"]
|
||||
|
||||
if mode == "keyboard":
|
||||
keyboard_number = int(kwargs["number"])
|
||||
cursor.execute("SELECT * FROM keyboard_list WHERE keyboard_number = %s", (keyboard_number,))
|
||||
keyboard_record = cursor.fetchall()
|
||||
if keyboard_record:
|
||||
cursor.execute("UPDATE keyboard_list SET device_instance_path = %s, device_name = %s WHERE keyboard_number = %s", (device_instance_path, device_name, keyboard_number))
|
||||
self.db.commit()
|
||||
return {"result": 0, "about": "ok"}
|
||||
else:
|
||||
cursor.execute("INSERT INTO keyboard_list (keyboard_number, device_instance_path, device_name) VALUES (%s, %s, %s)", (keyboard_number, device_instance_path, device_name))
|
||||
return {"result": 0, "about": "ok"}
|
||||
elif mode == "mouse":
|
||||
mouse_number = int(kwargs["number"])
|
||||
cursor.execute("SELECT * FROM mouse_list WHERE mouse_number = %s", (mouse_number,))
|
||||
mouse_record = cursor.fetchall()
|
||||
if mouse_record:
|
||||
cursor.execute("UPDATE mouse_list SET device_instance_path = %s, device_name = %s WHERE mouse_number = %s", (device_instance_path, device_name, mouse_number))
|
||||
self.db.commit()
|
||||
return {"result": 0, "about": "ok"}
|
||||
else:
|
||||
cursor.execute("INSERT INTO mouse_list (mouse_number, device_instance_path, device_name) VALUES (%s, %s, %s)", (mouse_number, device_instance_path, device_name))
|
||||
return {"result": 0, "about": "ok"}
|
||||
|
||||
except Exception as error:
|
||||
print("停止処理中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
return {"result": 1, "about": "error"}
|
||||
|
||||
def delete(self, pc_number):
|
||||
try:
|
||||
cursor = self.db.cursor()
|
||||
cursor.execute("UPDATE pc_list SET password_hash = NULL WHERE pc_number = %s", (pc_number,))
|
||||
self.db.commit()
|
||||
return {"result": 0, "about": "ok"}
|
||||
|
||||
except Exception as error:
|
||||
print("パスワードの削除中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
return {"result": 1, "about": "error"}
|
||||
|
||||
finally:
|
||||
cursor.close()
|
||||
|
||||
def user_register_check(self, **kwargs):
|
||||
try:
|
||||
discord_user_id = str(kwargs["discord_user_id"])
|
||||
|
||||
cursor = self.db.cursor()
|
||||
|
||||
cursor.execute("SELECT * FROM club_member WHERE discord_user_id = %s", (discord_user_id,))
|
||||
user_record = cursor.fetchall()
|
||||
#ユーザーデータが見つかった場合(登録済みの場合)
|
||||
if user_record:
|
||||
member_id = user_record[0][0]
|
||||
name = user_record[0][1]
|
||||
discord_user_name = user_record[0][2]
|
||||
return {"result": 0, "about": "exist", "user_info": {"member_id": member_id, "name": name, "discord_user_name": discord_user_name}}
|
||||
#ユーザーデータがなかったら(未登録の場合)
|
||||
else:
|
||||
return {"result": 1, "about": "user_data_not_found"}
|
||||
|
||||
except Exception as error:
|
||||
print("ユーザーの登録状況を調査中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
return {"result": 1, "about": "error"}
|
||||
|
||||
finally:
|
||||
cursor.close()
|
||||
|
||||
def stop(self, **kwargs):
|
||||
# bot側のfstopを基に
|
||||
try:
|
||||
pc_number = kwargs["pc_number"]
|
||||
cursor = self.db.cursor()
|
||||
cursor.execute("SELECT * FROM pc_list WHERE pc_number = %s", (pc_number,))
|
||||
pc_list_record = cursor.fetchall()
|
||||
pc_using_member_id = pc_list_record[0][1]
|
||||
pc_password_hash = pc_list_record[0][2]
|
||||
if pc_using_member_id == None:
|
||||
return {"result": 1, "about": "not_used"}
|
||||
else:
|
||||
cursor.execute("UPDATE pc_list SET using_member_id = NULL WHERE pc_number = %s", (pc_number,))
|
||||
if pc_password_hash == None:
|
||||
pass
|
||||
else:
|
||||
cursor.execute("UPDATE pc_list SET password_hash = NULL WHERE pc_number = %s", (pc_number,))
|
||||
cursor.execute("SELECT * FROM pc_usage_history WHERE member_id = %s AND pc_number = %s ORDER BY id DESC LIMIT 1", (pc_using_member_id, pc_number))
|
||||
pc_usage_history_record = cursor.fetchall()
|
||||
pc_usage_history_record_id = pc_usage_history_record[0][0]
|
||||
keyboard_number = pc_usage_history_record[0][3]
|
||||
mouse_number = pc_usage_history_record[0][4]
|
||||
if keyboard_number == None:
|
||||
pass
|
||||
else:
|
||||
# keyboard_listの使用中ユーザーを消す
|
||||
cursor.execute("UPDATE keyboard_list SET using_member_id = NULL WHERE keyboard_number = %s", (keyboard_number,))
|
||||
if mouse_number == None:
|
||||
pass
|
||||
else:
|
||||
# mouse_listの使用中ユーザーを消す
|
||||
cursor.execute("UPDATE mouse_list SET using_member_id = NULL WHERE mouse_number = %s", (mouse_number,))
|
||||
cursor.execute("UPDATE pc_usage_history SET end_use_time = clock_timestamp() WHERE id = %s", (pc_usage_history_record_id,))
|
||||
self.db.commit()
|
||||
return {"result": 0, "about": "ok"}
|
||||
|
||||
except Exception as error:
|
||||
print("停止処理中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
return {"result": 1, "about": "error"}
|
||||
|
||||
finally:
|
||||
cursor.close()
|
||||
|
||||
def register(self, **kwargs):
|
||||
try:
|
||||
cursor = self.db.cursor()
|
||||
pc_number = int(kwargs["pc_number"])
|
||||
pc_uuid = str(kwargs["pc_uuid"])
|
||||
cursor.execute("SELECT pc_number FROM pc_list WHERE pc_number = %s", (pc_number,))
|
||||
pc_record_number_source = cursor.fetchall()
|
||||
|
||||
if pc_record_number_source == []:
|
||||
pc_token = self.token_generate(36)
|
||||
master_password = self.master_password_generate(16)
|
||||
master_password_hash = self.hash_genarate(master_password)
|
||||
cursor.execute("INSERT INTO pc_list (pc_number, pc_uuid, pc_token, master_password) VALUES (%s, %s, %s, %s)", (pc_number, pc_uuid, pc_token, master_password))
|
||||
self.db.commit()
|
||||
return {"result": 0, "about": "ok", "output_dict": {"pc_token": pc_token, "master_password": master_password, "master_password_hash": master_password_hash}}
|
||||
else:
|
||||
cursor.execute("SELECT pc_uuid FROM pc_list WHERE pc_number = %s", (pc_number,))
|
||||
pc_record_uuid_source = cursor.fetchall()
|
||||
pc_record_uuid = pc_record_uuid_source[0][0]
|
||||
if pc_record_uuid == None:
|
||||
pc_token = self.token_generate(36)
|
||||
master_password = self.master_password_generate(16)
|
||||
master_password_hash = self.hash_genarate(master_password)
|
||||
cursor.execute("UPDATE pc_list SET pc_uuid = %s, pc_token = %s, master_password = %s WHERE pc_number = %s", (pc_uuid, pc_token, master_password, pc_number))
|
||||
self.db.commit()
|
||||
return {"result": 0, "about": "ok", "output_dict": {"pc_token": pc_token, "master_password": master_password, "master_password_hash": master_password_hash}}
|
||||
else:
|
||||
return {"result": 1, "about": "exist"}
|
||||
|
||||
except Exception as error:
|
||||
print("PCの登録処理中にエラーが発生しました。\nエラー内容")
|
||||
print(str(error.__class__.__name__))
|
||||
print(str(error.args))
|
||||
print(str(error))
|
||||
return {"result": 1, "about": "error"}
|
||||
|
||||
finally:
|
||||
cursor.close()
|
||||
|
||||
|
||||
app = Flask(__name__, static_folder="./resource/")
|
||||
auth = Auth(server_config["db"]["host"], server_config["db"]["db_name"], server_config["db"]["port"], server_config["db"]["username"], server_config["db"]["password"])
|
||||
|
||||
@app.route('/register', methods=['POST'])
|
||||
def register():
|
||||
pc_number = int(request.json.get('pc_number'))
|
||||
pc_uuid = str(request.json.get('pc_uuid'))
|
||||
onetime_password = str(request.json.get('onetime'))
|
||||
|
||||
if os.path.isfile(onetime_config_path):
|
||||
with open(onetime_config_path, "r") as r:
|
||||
onetime_config = json.load(r)
|
||||
|
||||
if onetime_password == onetime_config["onetime"]["pc_register"]["password"]:
|
||||
register_result = auth.register(pc_number=pc_number, pc_uuid=pc_uuid)
|
||||
if register_result["result"] == 0:
|
||||
pc_token = register_result["output_dict"]["pc_token"]
|
||||
master_password = register_result["output_dict"]["master_password"]
|
||||
master_password_hash = register_result["output_dict"]["master_password_hash"]
|
||||
onetime_config["onetime"]["pc_register"]["current_count"] += 1
|
||||
|
||||
if onetime_config["onetime"]["pc_register"]["current_count"] == onetime_config["onetime"]["pc_register"]["max_count"]:
|
||||
onetime_config["onetime"]["pc_register"]["password"] = None
|
||||
with open(onetime_config_path, "w") as w:
|
||||
json.dump(onetime_config, w, indent=4)
|
||||
return jsonify({'message': 'ok', 'pc_token': pc_token, 'master_password': master_password, 'master_password_hash': master_password_hash}), 200
|
||||
else:
|
||||
with open(onetime_config_path, "w") as w:
|
||||
json.dump(onetime_config, w, indent=4)
|
||||
return jsonify({'message': 'ok', 'pc_token': pc_token, 'master_password': master_password, 'master_password_hash': master_password_hash}), 200
|
||||
elif register_result["result"] == 1:
|
||||
if register_result["about"] == "exist":
|
||||
return jsonify({'message': 'exist'}), 400
|
||||
else:
|
||||
return jsonify({'message': 'damedesu'}), 500
|
||||
|
||||
else:
|
||||
return jsonify({'message': 'damedesu'}), 401
|
||||
else:
|
||||
return jsonify({'message': 'damedesu'}), 401
|
||||
|
||||
@app.route('/verify', methods=['POST'])
|
||||
def verify():
|
||||
pc_number = int(request.json.get('pc_number'))
|
||||
password_hash = request.json.get('password')
|
||||
pc_uuid = request.json.get('pc_uuid')
|
||||
pc_token = request.json.get('pc_token')
|
||||
devices = request.json.get('devices')
|
||||
|
||||
print(str(pc_number) + "の認証処理を開始...")
|
||||
pc_auth = auth.check(pc_number=pc_number, password_hash=password_hash, pc_uuid=pc_uuid, pc_token=pc_token, device_list=devices)
|
||||
|
||||
if pc_auth["result"] == 0:
|
||||
auth.delete(pc_number)
|
||||
#auth.device_use_register(pc_number=pc_number, keyboard_number=pc_auth["output_dict"]["keyboard_number"], mouse_number=pc_auth["output_dict"]["mouse_number"])
|
||||
print(str(pc_number) + "の認証処理は成功しました.")
|
||||
return jsonify({'message': 'ok'}), 200
|
||||
elif pc_auth["result"] == 1:
|
||||
if pc_auth["about"] == "incorrect_password":
|
||||
print(str(pc_number) + "の認証処理はパスワードが正しくないため失敗しました.")
|
||||
return jsonify({'message': 'incorrect_password'}), 401
|
||||
else:
|
||||
print(str(pc_number) + "の認証処理は失敗しました.")
|
||||
return jsonify({'message': 'damedesu'}), 500
|
||||
|
||||
@app.route('/stop', methods=['POST'])
|
||||
def stop():
|
||||
pc_number = int(request.json.get('pc_number'))
|
||||
pc_uuid = str(request.json.get('pc_uuid'))
|
||||
pc_token = str(request.json.get('pc_token'))
|
||||
print(str(pc_number) + "の使用停止処理を開始...")
|
||||
|
||||
pc_auth = auth.check(pc_number=pc_number, pc_uuid=pc_uuid, pc_token=pc_token)
|
||||
|
||||
if pc_auth["result"] == 0:
|
||||
pc_stop = auth.stop(pc_number=pc_number)
|
||||
if pc_stop["result"] == 0:
|
||||
print(str(pc_number) + "の使用停止処理は成功しました.")
|
||||
return jsonify({'message': 'ok'}), 200
|
||||
else:
|
||||
print(str(pc_number) + "の使用停止処理は失敗しました.")
|
||||
return jsonify({'message': 'error'}), 500
|
||||
else:
|
||||
return jsonify({'message': 'damedesu'}), 401
|
||||
|
||||
@app.route('/device_register', methods=['POST'])
|
||||
def device_register():
|
||||
onetime_password = str(request.json.get('onetime'))
|
||||
mode = str(request.json.get('mode'))
|
||||
number = int(request.json.get('number'))
|
||||
device_instance_path = str(request.json.get('device_instance_path'))
|
||||
device_name = str(request.json.get('device_name'))
|
||||
|
||||
if os.path.isfile(onetime_config_path):
|
||||
with open(onetime_config_path, "r") as r:
|
||||
onetime_config = json.load(r)
|
||||
|
||||
if onetime_password == onetime_config["onetime"]["device_register"]:
|
||||
if mode == "keyboard":
|
||||
print("キーボードの登録処理を開始...")
|
||||
device_register = auth.device_register(mode="keyboard", number=number, device_instance_path=device_instance_path, device_name=device_name)
|
||||
if device_register["result"] == 0:
|
||||
print(f"キーボード {number} 番の登録処理は成功しました.")
|
||||
onetime_config["onetime"]["device_register"]["current_count"] += 1
|
||||
|
||||
if onetime_config["onetime"]["device_register"]["current_count"] == onetime_config["onetime"]["device_register"]["max_count"]:
|
||||
onetime_config["onetime"]["device_register"] = None
|
||||
with open(onetime_config_path, "w") as w:
|
||||
json.dump(onetime_config, w, indent=4)
|
||||
return jsonify({'message': 'ok'}), 200
|
||||
else:
|
||||
with open(onetime_config_path, "w") as w:
|
||||
json.dump(onetime_config, w, indent=4)
|
||||
return jsonify({'message': 'ok'}), 200
|
||||
else:
|
||||
print(f"キーボード {number} 番の登録処理は失敗しました.")
|
||||
return jsonify({'message': 'error'}), 500
|
||||
|
||||
elif mode == "mouse":
|
||||
print("マウスの登録処理を開始...")
|
||||
device_register = auth.device_register(mode="mouse", number=number, device_instance_path=device_instance_path, device_name=device_name)
|
||||
if device_register["result"] == 0:
|
||||
print(f"マウス {number} 番の登録処理は成功しました.")
|
||||
onetime_config["onetime"]["device_register"]["current_count"] += 1
|
||||
|
||||
if onetime_config["onetime"]["device_register"]["current_count"] == onetime_config["onetime"]["device_register"]["max_count"]:
|
||||
onetime_config["onetime"]["device_register"] = None
|
||||
with open(onetime_config_path, "w") as w:
|
||||
json.dump(onetime_config, w, indent=4)
|
||||
return jsonify({'message': 'ok'}), 200
|
||||
else:
|
||||
with open(onetime_config_path, "w") as w:
|
||||
json.dump(onetime_config, w, indent=4)
|
||||
return jsonify({'message': 'ok'}), 200
|
||||
else:
|
||||
print(f"マウス {number} 番の登録処理は失敗しました.")
|
||||
return jsonify({'message': 'error'}), 500
|
||||
else:
|
||||
return jsonify({'message': 'damedesu'}), 401
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host="0.0.0.0", port=5000, debug=False)
|
672
dislocker_client.py
Normal file
|
@ -0,0 +1,672 @@
|
|||
import os
|
||||
import json
|
||||
import tkinter.messagebox
|
||||
import customtkinter
|
||||
from winotify import Notification, audio
|
||||
import keyboard
|
||||
import subprocess
|
||||
import requests
|
||||
import hashlib
|
||||
import string
|
||||
import random
|
||||
import tkinter
|
||||
import threading
|
||||
import sys
|
||||
import shutil
|
||||
import uuid
|
||||
import time
|
||||
import win32com.client
|
||||
import pythoncom
|
||||
from PIL import Image
|
||||
|
||||
app_name = "Dislocker"
|
||||
dislocker_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
||||
|
||||
os.chdir(dislocker_dir)
|
||||
|
||||
sp_startupinfo = subprocess.STARTUPINFO()
|
||||
sp_startupinfo.dwFlags = subprocess.STARTF_USESHOWWINDOW
|
||||
sp_startupinfo.wShowWindow = subprocess.SW_HIDE
|
||||
|
||||
resource_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "resource")
|
||||
config_dir_path = "./config/"
|
||||
client_config_path = config_dir_path + "client.json"
|
||||
if not os.path.isfile(client_config_path):
|
||||
if not os.path.isdir(config_dir_path):
|
||||
os.mkdir(config_dir_path)
|
||||
|
||||
client_config = {
|
||||
"initial": True,
|
||||
"auth_host_url": "http://localhost",
|
||||
"pc_number": 1,
|
||||
"master_password_hash": "",
|
||||
"testing": False,
|
||||
"eraser": True,
|
||||
"erase_data": {
|
||||
"example": {
|
||||
"process_name": "example.exe",
|
||||
"dir_path": "example"
|
||||
}
|
||||
},
|
||||
"pc_uuid": "",
|
||||
"pc_token": "",
|
||||
"hard_lock": False
|
||||
}
|
||||
|
||||
elif os.path.isfile(client_config_path):
|
||||
with open(client_config_path, "r") as r:
|
||||
client_config = json.load(r)
|
||||
|
||||
def get_input_devices():
|
||||
str_computer = "."
|
||||
obj_wmi_service = win32com.client.Dispatch("WbemScripting.SWbemLocator")
|
||||
obj_swem_services = obj_wmi_service.ConnectServer(str_computer, "root\\cimv2")
|
||||
col_items = obj_swem_services.ExecQuery("Select * from Win32_PnPEntity where PNPDeviceID like 'HID%'")
|
||||
|
||||
input_devices = []
|
||||
for obj_item in col_items:
|
||||
input_devices.append({
|
||||
"device_id": obj_item.DeviceID,
|
||||
"PNPDeviceID": obj_item.PNPDeviceID,
|
||||
"Description": obj_item.Description,
|
||||
"device_name": obj_item.Name,
|
||||
"Manufacturer": obj_item.Manufacturer,
|
||||
"Service": obj_item.Service,
|
||||
"FriendlyName": obj_item.Name, # デバイスとプリンターで表示される名前
|
||||
"device_instance_path": obj_item.DeviceID # デバイスインスタンスパス
|
||||
})
|
||||
|
||||
return input_devices
|
||||
|
||||
def device_register(**kwargs):
|
||||
onetime = str(kwargs["onetime"])
|
||||
mode = str(kwargs["mode"])
|
||||
number = int(kwargs["number"])
|
||||
device_instance_path = str(kwargs["device_instance_path"])
|
||||
device_name = str(kwargs["device_name"])
|
||||
device_register_json = {
|
||||
"number": number,
|
||||
"device_instance_path": device_instance_path,
|
||||
"device_name": device_name,
|
||||
"mode": mode,
|
||||
"onetime": onetime
|
||||
}
|
||||
register_url = client_config["auth_host_url"] + "/device_register"
|
||||
responce = requests.post(register_url, json=device_register_json)
|
||||
if responce.status_code == 200:
|
||||
print("デバイスの登録に成功しました。")
|
||||
return {"result": 0, "about": "ok"}
|
||||
elif responce.status_code == 401:
|
||||
print("認証に失敗しました。")
|
||||
return {"result": 1, "about": "auth_failed"}
|
||||
else:
|
||||
print("内部エラーによりデバイスの登録に失敗しました。")
|
||||
return {"result": 1, "about": "error"}
|
||||
|
||||
def master_password_gen():
|
||||
numbers = string.digits # (1)
|
||||
password = ''.join(random.choice(numbers) for _ in range(10)) # (2)
|
||||
password_hash = hashlib.sha256(password.encode()).hexdigest()
|
||||
result = {"password": password, "password_hash": password_hash}
|
||||
return result
|
||||
|
||||
def init(**kwargs):
|
||||
task_exist = subprocess.run('tasklist /fi "IMAGENAME eq dislocker_client.exe"', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True)
|
||||
if 'dislocker_client.exe' in task_exist.stdout:
|
||||
task_count = task_exist.stdout.count("dislocker_client.exe")
|
||||
if task_count == 1:
|
||||
pass
|
||||
else:
|
||||
return 1
|
||||
|
||||
if client_config["initial"] == True:
|
||||
pc_uuid = uuid.uuid4()
|
||||
client_config["pc_uuid"] = str(pc_uuid)
|
||||
|
||||
if "pc_number" in kwargs:
|
||||
client_config["pc_number"] = int(kwargs["pc_number"])
|
||||
else:
|
||||
tkinter.messagebox.showerror(title=f"{app_name} | 登録時にエラー", message=f"登録時にエラーが発生しました。\nPC番号が指定されていません。1個目の引数にPC番号、2個目の引数にワンタイムパスワードを指定して、もう一度お試しください。")
|
||||
return 2
|
||||
|
||||
if "onetime" in kwargs:
|
||||
onetime = str(kwargs["onetime"])
|
||||
else:
|
||||
tkinter.messagebox.showerror(title=f"{app_name} | 登録時にエラー", message=f"登録時にエラーが発生しました。\nワンタイムパスワードが指定されていません。1個目の引数にPC番号、2個目の引数にワンタイムパスワードを指定して、もう一度お試しください。")
|
||||
return 2
|
||||
|
||||
if "host_url" in kwargs:
|
||||
client_config["auth_host_url"] = str(kwargs["host_url"])
|
||||
else:
|
||||
pass
|
||||
|
||||
register_url = client_config["auth_host_url"] + "/register"
|
||||
register_json = {
|
||||
"pc_number": int(client_config["pc_number"]),
|
||||
"pc_uuid": str(pc_uuid),
|
||||
"onetime": onetime
|
||||
}
|
||||
|
||||
responce = requests.post(register_url, json=register_json)
|
||||
|
||||
if responce.status_code == 200:
|
||||
print("PCの情報が登録されました。")
|
||||
responce_json = responce.json()
|
||||
pc_token = str(responce_json["pc_token"])
|
||||
master_password_hash = str(responce_json["master_password_hash"])
|
||||
master_password = str(responce_json["master_password"])
|
||||
client_config["pc_token"] = pc_token
|
||||
client_config["master_password_hash"] = master_password_hash
|
||||
|
||||
msgbox = tkinter.messagebox.showinfo(title=f"{app_name} | 初回起動を検出", message=f"初回起動のようです。\nマスターパスワードを記録しておいてください。\nBotが起動している場合は、管理者がDiscordから確認することもできます。\n\n{master_password}\n\n")
|
||||
client_config["initial"] = False
|
||||
|
||||
with open(client_config_path, "w") as w:
|
||||
json.dump(client_config, w, indent=4)
|
||||
return 2
|
||||
|
||||
elif responce.status_code == 400:
|
||||
msgbox = tkinter.messagebox.showerror(title=f"{app_name} | 登録時にエラー", message=f"登録時にエラーが発生しました。\n指定されたPC番号には既に登録されています。PCを置き換えたい場合は、Botから登録を解除してください。")
|
||||
return 2
|
||||
|
||||
elif responce.status_code == 401:
|
||||
msgbox = tkinter.messagebox.showerror(title=f"{app_name} | 登録時にエラー", message=f"登録時にエラーが発生しました。\nワンタイムパスワードが間違っている可能性があります。")
|
||||
return 2
|
||||
|
||||
elif responce.status_code == 500:
|
||||
msgbox = tkinter.messagebox.showerror(title=f"{app_name} | 登録時にエラー", message=f"登録時にエラーが発生しました。\nサーバーで内部エラーが発生しています。")
|
||||
return 2
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
class App(customtkinter.CTk):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
if client_config["testing"] == True:
|
||||
pass
|
||||
else:
|
||||
self.block_taskmgr()
|
||||
self.block_key()
|
||||
shutup_window = keyboard.press_and_release('windows + d')
|
||||
self.attributes('-fullscreen', True)
|
||||
self.attributes('-topmost', True)
|
||||
|
||||
if client_config["hard_lock"] == True:
|
||||
exit_explorer = subprocess.run('taskkill /f /im explorer.exe', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True)
|
||||
if exit_explorer.returncode == 0:
|
||||
pass
|
||||
else:
|
||||
signout_session = subprocess.run('shutdown /l /f /t 3', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True)
|
||||
error_msgbox = tkinter.messagebox.showerror(title=f"{app_name} | 初回処理のエラー", message=f"初回処理の実行にエラーが発生しました。\n自動的にサインアウトされます。")
|
||||
|
||||
self.title(f"{app_name} | ロック中")
|
||||
self.iconbitmap(default=resource_path + '\\icon\\dislocker.ico')
|
||||
self.frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent')
|
||||
self.frame.grid(row=0, column=0, sticky='nsew')
|
||||
|
||||
lock = Lock()
|
||||
|
||||
def exit(self):
|
||||
self.unlock_taskmgr()
|
||||
if client_config["hard_lock"] == True:
|
||||
self.wake_explorer()
|
||||
else:
|
||||
pass
|
||||
|
||||
self.toast()
|
||||
self.destroy()
|
||||
|
||||
def block_key(self):
|
||||
block_keys = ['ctrl', 'alt', 'windows', 'shift', 'delete']
|
||||
for i in block_keys:
|
||||
keyboard.block_key(i)
|
||||
|
||||
def block_taskmgr(self):
|
||||
block = subprocess.run('reg add HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System /v DisableTaskMgr /t REG_DWORD /d 1 /f', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True)
|
||||
print(block)
|
||||
|
||||
def unlock_taskmgr(self):
|
||||
unlock = subprocess.run('reg delete HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System /v DisableTaskMgr /f', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True)
|
||||
print(unlock)
|
||||
|
||||
def wake_explorer(self):
|
||||
wake_explorer = subprocess.Popen('explorer', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True)
|
||||
|
||||
|
||||
def toast(self):
|
||||
success = Notification(
|
||||
app_id='Dislocker',
|
||||
title='ご協力ありがとうございます!',
|
||||
msg='パスワード認証に成功しました。\n現在使われたパスワードは削除されます。',
|
||||
icon=resource_path + r'\success.png'
|
||||
)
|
||||
success.set_audio(audio.Default, loop=False)
|
||||
success.show()
|
||||
|
||||
def handler_close(self):
|
||||
pass
|
||||
|
||||
|
||||
class Lock(customtkinter.CTkToplevel):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
if client_config["testing"] == True:
|
||||
self.title(f'{app_name} | PC番号 {client_config["pc_number"]} | テストモード')
|
||||
else:
|
||||
self.title(f'{app_name} | PC番号 {client_config["pc_number"]} | ロックされています')
|
||||
|
||||
self.iconbitmap(default=resource_path + '\\icon\\dislocker.ico')
|
||||
self.window_width = 760
|
||||
self.window_height = 320
|
||||
self.screen_width = self.winfo_screenwidth()
|
||||
self.screen_height = self.winfo_screenheight()
|
||||
self.center_x = int(self.screen_width/2 - self.window_width/2)
|
||||
self.center_y = int(self.screen_height/2 - self.window_height/2)
|
||||
self.geometry(f"{str(self.window_width)}x{str(self.window_height)}+{str(self.center_x)}+{str(self.center_y)}")
|
||||
self.resizable(height=False, width=False)
|
||||
self.attributes('-topmost', True)
|
||||
self.grab_set()
|
||||
self.lift()
|
||||
self.protocol("WM_DELETE_WINDOW", self.handler_close)
|
||||
|
||||
self.emoji_font = customtkinter.CTkFont(family="Segoe UI Emoji", size=32)
|
||||
self.title_font = customtkinter.CTkFont(family="meiryo", size=32, weight="bold")
|
||||
self.pc_number_font = customtkinter.CTkFont(family="meiryo", size=64, weight="bold")
|
||||
self.title_small_font = customtkinter.CTkFont(family="meiryo", size=16)
|
||||
self.general_font = customtkinter.CTkFont(family="meiryo", size=18)
|
||||
self.general_small_font = customtkinter.CTkFont(family="meiryo", size=12)
|
||||
self.textbox_font = customtkinter.CTkFont(family="meiryo", size=14)
|
||||
self.button_font = customtkinter.CTkFont(family="meiryo", size=14)
|
||||
|
||||
self.cover_img = customtkinter.CTkImage(light_image=Image.open(resource_path + '\\cover\\dislocker_light.png'), dark_image=Image.open(resource_path + '\\cover\\dislocker_dark.png'), size=(160, 320))
|
||||
|
||||
self.grid_columnconfigure(0, weight=1)
|
||||
self.grid_columnconfigure(1, weight=6)
|
||||
|
||||
self.cover_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent')
|
||||
self.cover_frame.grid(row=0, column=0, padx=0, pady=0, sticky="nsew", rowspan=4)
|
||||
|
||||
self.cover_img_label = customtkinter.CTkLabel(self.cover_frame, image=self.cover_img, text="")
|
||||
self.cover_img_label.grid(row=0, column=0, padx=0, pady=0, sticky="w")
|
||||
|
||||
self.msg_title_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent')
|
||||
self.msg_title_frame.grid(row=0, column=1, padx=10, pady=10, sticky="nsew")
|
||||
|
||||
#self.icon_title_1 = customtkinter.CTkLabel(self.msg_title_frame, text='😎', font=self.emoji_font, justify="left")
|
||||
#self.icon_title_1.grid(row=0, column=0, padx=10, sticky="w")
|
||||
|
||||
self.msg_title_1 = customtkinter.CTkLabel(self.msg_title_frame, text=f'ちょっと待って!! ', font=self.title_font, justify="left")
|
||||
self.msg_title_1.grid(row=0, column=0, padx=10, sticky="we")
|
||||
|
||||
self.pc_number_title_1 = customtkinter.CTkLabel(self.msg_title_frame, text=f'PC番号 | {client_config["pc_number"]}', font=self.title_font, justify="right")
|
||||
self.pc_number_title_1.grid(row=0, column=1, padx=10, sticky="e")
|
||||
|
||||
self.msg_title_2 = customtkinter.CTkLabel(self.msg_title_frame, text="本当にあなたですか?", font=self.title_small_font, justify="left")
|
||||
self.msg_title_2.grid(row=1, column=0, padx=10, columnspan=2, sticky="w")
|
||||
|
||||
self.msg_subtitle_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent')
|
||||
self.msg_subtitle_frame.grid(row=1, column=1, padx=10, pady=0, sticky="nsew")
|
||||
self.msg_subtitle_frame.grid_columnconfigure(0, weight=1)
|
||||
|
||||
self.msg_subtitle_1 = customtkinter.CTkLabel(self.msg_subtitle_frame, text='サインインするには、Discordを開き、Dislockerから送信された\nパスワードを入力してください。', font=self.general_font, justify="left")
|
||||
self.msg_subtitle_1.grid(row=0, column=0, padx=10, sticky="w")
|
||||
|
||||
self.msg_subtitle_2 = customtkinter.CTkLabel(self.msg_subtitle_frame, text='※ パスワードの有効期限は発行から5分間です。期限が切れた場合は、もう一度発行してください。', font=self.general_small_font, justify="left")
|
||||
self.msg_subtitle_2.grid(row=1, column=0, padx=10, sticky="w")
|
||||
|
||||
self.input_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent')
|
||||
self.input_frame.grid(row=2, column=1, padx=10, pady=0, sticky="nsew")
|
||||
self.input_frame.columnconfigure(0, weight=1)
|
||||
|
||||
self.password_entry = customtkinter.CTkEntry(self.input_frame, placeholder_text='パスワード', show='*', font=self.textbox_font)
|
||||
self.password_entry.grid(row=0, column=0, padx=10, sticky="ew")
|
||||
self.password_entry.bind("<Return>", self.auth_start_ev)
|
||||
|
||||
self.button_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent')
|
||||
self.button_frame.grid(row=3, column=1, padx=10, pady=10, sticky="nsew")
|
||||
self.button_frame.columnconfigure(0, weight=3)
|
||||
self.button_frame.columnconfigure(1, weight=1)
|
||||
self.button_frame.columnconfigure(2, weight=1)
|
||||
|
||||
self.signin_button = customtkinter.CTkButton(self.button_frame, text='サインイン', command=self.auth_start, font=self.button_font)
|
||||
self.signin_button.grid(row=0, column=2, padx=10, sticky="e")
|
||||
|
||||
self.signout_button = customtkinter.CTkButton(self.button_frame, text='サインアウト', command=self.signout, font=self.button_font)
|
||||
self.signout_button.grid(row=0, column=1, padx=10, sticky="e")
|
||||
|
||||
self.help_button = customtkinter.CTkButton(self.button_frame, text='ヘルプ', command=self.help_dummy, font=self.button_font)
|
||||
self.help_button.grid(row=0, column=0, padx=10, sticky="w")
|
||||
|
||||
self.keyboard_listener_thread = threading.Thread(target=self.keyboard_listener)
|
||||
self.keyboard_listener_thread.daemon = True
|
||||
self.keyboard_listener_thread.start()
|
||||
|
||||
def help_wakeup(self):
|
||||
help = Help()
|
||||
|
||||
def keyboard_listener(self):
|
||||
keyboard.add_hotkey('ctrl+shift+q', self.exit)
|
||||
|
||||
def hash_genarate(self, source):
|
||||
hashed = hashlib.sha256(source.encode())
|
||||
return hashed.hexdigest()
|
||||
|
||||
def auth_start(self):
|
||||
auth_thread = threading.Thread(target=self.auth)
|
||||
auth_thread.daemon = True
|
||||
auth_thread.start()
|
||||
|
||||
def auth_start_ev(self, event):
|
||||
auth_thread = threading.Thread(target=self.auth)
|
||||
auth_thread.daemon = True
|
||||
auth_thread.start()
|
||||
|
||||
def button_disable(self):
|
||||
self.help_button.configure(state="disabled", fg_color="gray")
|
||||
self.signin_button.configure(state="disabled", fg_color="gray")
|
||||
self.signout_button.configure(state="disabled", fg_color="gray")
|
||||
|
||||
def button_enable(self):
|
||||
self.help_button.configure(state="normal", fg_color="#3c8dd0")
|
||||
self.signin_button.configure(state="normal", fg_color="#3c8dd0")
|
||||
self.signout_button.configure(state="normal", fg_color="#3c8dd0")
|
||||
|
||||
def get_input_devices(self):
|
||||
try:
|
||||
pythoncom.CoInitialize()
|
||||
str_computer = "."
|
||||
obj_wmi_service = win32com.client.Dispatch("WbemScripting.SWbemLocator")
|
||||
obj_swem_services = obj_wmi_service.ConnectServer(str_computer, "root\\cimv2")
|
||||
col_items = obj_swem_services.ExecQuery("Select * from Win32_PnPEntity where PNPDeviceID like 'HID%'")
|
||||
|
||||
input_devices = []
|
||||
for obj_item in col_items:
|
||||
input_devices.append({
|
||||
"device_id": obj_item.DeviceID,
|
||||
"PNPDeviceID": obj_item.PNPDeviceID,
|
||||
"Description": obj_item.Description,
|
||||
"device_name": obj_item.Name,
|
||||
"Manufacturer": obj_item.Manufacturer,
|
||||
"Service": obj_item.Service,
|
||||
"FriendlyName": obj_item.Name, # デバイスとプリンターで表示される名前
|
||||
"device_instance_path": obj_item.DeviceID # デバイスインスタンスパス
|
||||
})
|
||||
|
||||
pythoncom.CoUninitialize()
|
||||
return input_devices
|
||||
except pythoncom.com_error as e:
|
||||
print("Error:", e)
|
||||
return []
|
||||
|
||||
def auth(self):
|
||||
self.button_disable()
|
||||
password = str(self.password_entry.get())
|
||||
#devices = self.get_input_devices()
|
||||
devices = []
|
||||
|
||||
if len(password) == 10:
|
||||
print("マスターパスワードで認証を試行します。")
|
||||
master_password_hash = self.hash_genarate(str(self.password_entry.get()))
|
||||
if client_config["master_password_hash"] == master_password_hash:
|
||||
print("マスターパスワードで認証しました。")
|
||||
self.exit()
|
||||
else:
|
||||
print("マスターパスワードで認証できませんでした。")
|
||||
self.withdraw()
|
||||
msgbox = tkinter.messagebox.showinfo(title=f"{app_name} | 誤ったパスワード", message=f"パスワードが間違っています!")
|
||||
self.msg_subtitle_1.configure(text='パスワードが間違っています! ')
|
||||
self.button_enable()
|
||||
self.deiconify()
|
||||
|
||||
print("認証サーバーにアクセスします。")
|
||||
auth_url = client_config["auth_host_url"] + "/verify"
|
||||
auth_json = {
|
||||
"pc_number": int(client_config["pc_number"]),
|
||||
"pc_uuid": str(client_config["pc_uuid"]),
|
||||
"pc_token": str(client_config["pc_token"]),
|
||||
"devices": devices,
|
||||
"password": self.hash_genarate(str(self.password_entry.get()))
|
||||
}
|
||||
try:
|
||||
responce = requests.post(auth_url, json=auth_json)
|
||||
if responce.status_code == 200:
|
||||
print("認証サーバー経由で認証しました。")
|
||||
self.exit()
|
||||
elif responce.status_code == 401:
|
||||
print("認証サーバー経由での認証に失敗しました。")
|
||||
self.withdraw()
|
||||
msgbox = tkinter.messagebox.showinfo(title=f"{app_name} | 誤ったパスワード", message=f"パスワードが間違っています!")
|
||||
self.msg_subtitle_1.configure(text='パスワードが間違っています! ')
|
||||
self.button_enable()
|
||||
self.deiconify()
|
||||
elif responce.status_code == 500:
|
||||
print("内部エラーにより認証に失敗しました。")
|
||||
self.withdraw()
|
||||
msgbox = tkinter.messagebox.showinfo(title=f"{app_name} | 内部エラー", message=f"サーバーの内部エラーにより認証に失敗しました。")
|
||||
self.msg_subtitle_1.configure(text='内部エラーにより認証に失敗しました。 ')
|
||||
self.button_enable()
|
||||
self.deiconify()
|
||||
except:
|
||||
print("認証サーバーにアクセスできません。マスターパスワードで認証を試行します。")
|
||||
master_password_hash = self.hash_genarate(str(self.password_entry.get()))
|
||||
if client_config["master_password_hash"] == master_password_hash:
|
||||
print("マスターパスワードで認証しました。")
|
||||
self.exit()
|
||||
else:
|
||||
print("マスターパスワードで認証できませんでした。")
|
||||
self.withdraw()
|
||||
msgbox = tkinter.messagebox.showinfo(title=f"{app_name} | ネットワークエラー", message=f"認証サーバーにアクセスできませんでした。\n続行するには、マスターパスワードを入力してください。")
|
||||
self.msg_subtitle_1.configure(text='ネットワークエラーが発生しています。\n続行するには、マスターパスワードを入力して下さい。 ')
|
||||
self.button_enable()
|
||||
self.deiconify()
|
||||
|
||||
def signout(self):
|
||||
app.unlock_taskmgr()
|
||||
self.destroy()
|
||||
signout_command = subprocess.run('shutdown /l /f', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True)
|
||||
print(signout_command)
|
||||
|
||||
|
||||
def handler_close(self):
|
||||
pass
|
||||
|
||||
def help_dummy(self):
|
||||
self.withdraw()
|
||||
msgbox = tkinter.messagebox.showinfo(title=f"{app_name} | 未実装", message=f"ヘルプページは製作途中です。\nDiscordサーバーの指示に従って、認証を進めてください。")
|
||||
self.deiconify()
|
||||
|
||||
def wakeup_shutdown_background(self):
|
||||
wakeup = subprocess.Popen(f'{dislocker_dir}\\dislocker_client_shutdown.exe', startupinfo=sp_startupinfo)
|
||||
|
||||
def exit(self):
|
||||
try:
|
||||
self.wakeup_shutdown_background()
|
||||
except:
|
||||
pass
|
||||
|
||||
self.destroy()
|
||||
app.exit()
|
||||
|
||||
|
||||
class Help(customtkinter.CTkToplevel):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
if client_config["testing"] == True:
|
||||
self.title(f'{app_name} | ヘルプ | テストモード')
|
||||
else:
|
||||
self.title(f'{app_name} | ヘルプ')
|
||||
self.iconbitmap(default=resource_path + '\\icon\\dislocker.ico')
|
||||
self.geometry("600x400")
|
||||
self.resizable(height=False, width=False)
|
||||
self.attributes('-topmost', True)
|
||||
self.grab_set()
|
||||
self.lift()
|
||||
self.protocol("WM_DELETE_WINDOW", self.handler_close)
|
||||
msgbox = tkinter.messagebox.showinfo(title=f"{app_name} | 未実装", message=f"ヘルプページは製作途中です。\nDiscordサーバーの指示に従って、認証を進めてください。")
|
||||
self.destroy()
|
||||
|
||||
def handler_close(self):
|
||||
self.destroy()
|
||||
|
||||
|
||||
class Stop():
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
stop_thread = threading.Thread(target=self.stop)
|
||||
stop_thread.run()
|
||||
|
||||
def delete_appdata(self, **kwargs):
|
||||
process_name = kwargs["process_name"]
|
||||
dir_path = kwargs["dir_path"]
|
||||
|
||||
if not os.path.exists(dir_path):
|
||||
print(f"エラー: 指定されたディレクトリ {dir_path} が存在しません。")
|
||||
return 1
|
||||
|
||||
i = 0
|
||||
i_max = 10
|
||||
result = 1
|
||||
while i != i_max:
|
||||
i += 1
|
||||
try:
|
||||
# プロセスの終了
|
||||
subprocess.run(f'taskkill /f /t /im {process_name}', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True)
|
||||
print(f"{process_name} を終了しました。")
|
||||
time.sleep(0.1)
|
||||
# ディレクトリの削除
|
||||
shutil.rmtree(dir_path)
|
||||
if os.path.isdir(dir_path):
|
||||
pass
|
||||
else:
|
||||
print(f"{dir_path} を削除しました。")
|
||||
result = 0
|
||||
i = i_max
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"プロセス終了エラー: {e}")
|
||||
|
||||
except PermissionError as e:
|
||||
print(f"権限エラー: {e}")
|
||||
|
||||
except Exception as e:
|
||||
print("エラーが発生しました。\nエラー内容:")
|
||||
print(f"エラータイプ: {e.__class__.__name__}")
|
||||
print(f"エラー引数: {e.args}")
|
||||
print(f"エラーメッセージ: {str(e)}")
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def shutdown(self):
|
||||
shutdown_command = subprocess.run('shutdown /s /f /t 0', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True)
|
||||
|
||||
def stop(self):
|
||||
print("停止処理を実行。")
|
||||
if client_config["eraser"] == True:
|
||||
appdata_local = os.path.expandvars("%LOCALAPPDATA%")
|
||||
appdata_roaming = os.path.expandvars("%APPDATA%")
|
||||
epic_del = self.delete_appdata(process_name="EpicGamesLauncher.exe", dir_path=f"{appdata_local}\\EpicGamesLauncher\\Saved")
|
||||
chrome_del = self.delete_appdata(process_name="chrome.exe", dir_path=f"{appdata_local}\\Google\\Chrome\\User Data")
|
||||
discord_del = self.delete_appdata(process_name="discord.exe", dir_path=f"{appdata_roaming}\\discord")
|
||||
steam_del = self.delete_appdata(process_name="steam.exe", dir_path=f"{appdata_local}\\Steam")
|
||||
ea_del = self.delete_appdata(process_name="EADesktop.exe", dir_path=f"{appdata_local}\\Electronic Arts")
|
||||
riot_del = self.delete_appdata(process_name="RiotClientServices.exe", dir_path=f"{appdata_local}\\Riot Games\\Riot Client")
|
||||
else:
|
||||
print("削除処理をスキップ。")
|
||||
stop_url = client_config["auth_host_url"] + "/stop"
|
||||
stop_json = {
|
||||
"pc_number": int(client_config["pc_number"]),
|
||||
"pc_uuid": str(client_config["pc_uuid"]),
|
||||
"pc_token": str(client_config["pc_token"])
|
||||
}
|
||||
try:
|
||||
responce = requests.post(stop_url, json=stop_json)
|
||||
if responce.status_code == 200:
|
||||
print("停止処理は成功しました。")
|
||||
elif responce.status_code == 401:
|
||||
print("認証に失敗しました。")
|
||||
else:
|
||||
print("内部エラーにより停止処理に失敗しました。")
|
||||
except:
|
||||
print("ネットワークエラーにより停止処理に失敗しました。")
|
||||
finally:
|
||||
self.shutdown()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = sys.argv
|
||||
if len(args) >= 2:
|
||||
if args[1] == "stop":
|
||||
init_result = init()
|
||||
if init_result == 1:
|
||||
print("多重起動を検出。")
|
||||
elif init_result == 2:
|
||||
pass
|
||||
else:
|
||||
stop = Stop()
|
||||
stop.run()
|
||||
|
||||
elif args[1] == "setup":
|
||||
if len(args) == 4:
|
||||
init_result = init(pc_number=args[2], onetime=args[3])
|
||||
elif len(args) == 5:
|
||||
init_result = init(pc_number=args[2], onetime=args[3], host_url=args[4])
|
||||
else:
|
||||
print("引数エラー。")
|
||||
error_msgbox = tkinter.messagebox.showerror(title=f"{app_name} | 引数エラー", message=f"引数が多すぎるか、少なすぎます。\n引数がPC番号、ワンタイムパスワード、ホストURLの順で正しく指定されているか確認してください。")
|
||||
if init_result == 1:
|
||||
warning_msgbox = tkinter.messagebox.showwarning(title=f"{app_name} | 多重起動エラー", message=f"すでに {app_name} は実行されています。\n正常に起動しない場合は、既に起動しているプロセスを終了してから、もう一度起動してみてください。")
|
||||
elif init_result == 2:
|
||||
pass
|
||||
else:
|
||||
pass
|
||||
|
||||
elif args[1] == "deviceregister":
|
||||
init_result = init()
|
||||
if init_result == 1:
|
||||
warning_msgbox = tkinter.messagebox.showwarning(title=f"{app_name} | 多重起動エラー", message=f"すでに {app_name} は実行されています。\n正常に起動しない場合は、既に起動しているプロセスを終了してから、もう一度起動してみてください。")
|
||||
elif init_result == 2:
|
||||
pass
|
||||
else:
|
||||
mode = input('登録するデバイスはキーボードとマウスのどちらですか?(keyboard/mouse): ')
|
||||
input_devices = get_input_devices()
|
||||
|
||||
i = 0
|
||||
for device in input_devices:
|
||||
print(f"{str(i + 1)} 番目 | デバイス名: {device['device_name']} \n製造元: {device['Manufacturer']} \nデバイスインスタンスパス: {device['device_instance_path']}")
|
||||
print("-" * 20)
|
||||
i += 1
|
||||
device_num = input('どのデバイスを登録しますか?番号で指定してください: ')
|
||||
device_register_num = input('そのデバイスは何番目のデバイスとして登録しますか?番号で指定してください: ')
|
||||
onetime = input('ワンタイムパスワードを入力してください: ')
|
||||
device_register_result = device_register(onetime=onetime, mode=mode, number=int(device_register_num), device_instance_path=input_devices[int(device_num) - 1]["device_instance_path"], device_name=input_devices[int(device_num) - 1]["device_name"])
|
||||
if device_register_result["result"] == 0:
|
||||
print("登録されました。")
|
||||
elif device_register_result["result"] == 1:
|
||||
if device_register_result["about"] == "auth_failed":
|
||||
print("認証に失敗しました。")
|
||||
else:
|
||||
print("エラーが発生しました。")
|
||||
|
||||
elif args[1] == "guitest":
|
||||
init_result = init()
|
||||
client_config["testing"] = True
|
||||
app = App()
|
||||
app.mainloop()
|
||||
|
||||
else:
|
||||
print("引数エラー。")
|
||||
else:
|
||||
init_result = init()
|
||||
if init_result == 1:
|
||||
warning_msgbox = tkinter.messagebox.showwarning(title=f"{app_name} | 多重起動エラー", message=f"すでに {app_name} は実行されています。\n正常に起動しない場合は、既に起動しているプロセスを終了してから、もう一度起動してみてください。")
|
||||
elif init_result == 2:
|
||||
pass
|
||||
else:
|
||||
app = App()
|
||||
app.protocol("WM_DELETE_WINDOW", app.handler_close)
|
||||
app.mainloop()
|
166
dislocker_client_shutdown.py
Normal file
|
@ -0,0 +1,166 @@
|
|||
import os
|
||||
import json
|
||||
import tkinter.messagebox
|
||||
import tkinter
|
||||
import subprocess
|
||||
import requests
|
||||
import tkinter
|
||||
import sys
|
||||
import time
|
||||
import shutil
|
||||
|
||||
app_name = "Dislocker"
|
||||
dislocker_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
||||
|
||||
os.chdir(dislocker_dir)
|
||||
|
||||
sp_startupinfo = subprocess.STARTUPINFO()
|
||||
sp_startupinfo.dwFlags = subprocess.STARTF_USESHOWWINDOW
|
||||
sp_startupinfo.wShowWindow = subprocess.SW_HIDE
|
||||
|
||||
resource_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "resource")
|
||||
config_dir_path = "./config/"
|
||||
client_config_path = config_dir_path + "client.json"
|
||||
if not os.path.isfile(client_config_path):
|
||||
msgbox = tkinter.messagebox.showerror(title=f"{app_name} | エラー", message=f"設定ファイルが正しく構成されていません。")
|
||||
|
||||
elif os.path.isfile(client_config_path):
|
||||
with open(client_config_path, "r") as r:
|
||||
client_config = json.load(r)
|
||||
|
||||
def init(**kwargs):
|
||||
task_exist = subprocess.run('tasklist /fi "IMAGENAME eq dislocker_shutdown.exe"', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True)
|
||||
if 'dislocker_shutdown.exe' in task_exist.stdout:
|
||||
task_count = task_exist.stdout.count("dislocker_shutdown.exe")
|
||||
if task_count == 1:
|
||||
pass
|
||||
else:
|
||||
return 1
|
||||
|
||||
if client_config["initial"] == True:
|
||||
msgbox = tkinter.messagebox.showerror(title=f"{app_name} | エラー", message=f"設定ファイルが正しく構成されていません。")
|
||||
return 2
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
class App(tkinter.Tk):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
if client_config["testing"] == True:
|
||||
pass
|
||||
else:
|
||||
pass
|
||||
|
||||
self.geometry("160x100")
|
||||
|
||||
self.title(f"{app_name} | シャットダウンを監視")
|
||||
self.iconbitmap(default=resource_path + '\\icon\\dislocker_shutdown.ico')
|
||||
|
||||
self.protocol("WM_SAVE_YOURSELF", self.handler_close)
|
||||
|
||||
self.frame = tkinter.Frame(self)
|
||||
self.frame.grid(row=0, column=0, sticky='nsew')
|
||||
|
||||
self.withdraw()
|
||||
|
||||
def delete_appdata(self, **kwargs):
|
||||
process_name = kwargs["process_name"]
|
||||
dir_path = kwargs["dir_path"]
|
||||
|
||||
if not os.path.exists(dir_path):
|
||||
print(f"エラー: 指定されたディレクトリ {dir_path} が存在しません。")
|
||||
return 1
|
||||
|
||||
i = 0
|
||||
i_max = 10
|
||||
result = 1
|
||||
while i != i_max:
|
||||
i += 1
|
||||
try:
|
||||
# プロセスの終了
|
||||
subprocess.run(f'taskkill /f /t /im {process_name}', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True)
|
||||
print(f"{process_name} を終了しました。")
|
||||
time.sleep(0.1)
|
||||
# ディレクトリの削除
|
||||
shutil.rmtree(dir_path)
|
||||
if os.path.isdir(dir_path):
|
||||
pass
|
||||
else:
|
||||
print(f"{dir_path} を削除しました。")
|
||||
result = 0
|
||||
i = i_max
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"プロセス終了エラー: {e}")
|
||||
|
||||
except PermissionError as e:
|
||||
print(f"権限エラー: {e}")
|
||||
|
||||
except Exception as e:
|
||||
print("エラーが発生しました。\nエラー内容:")
|
||||
print(f"エラータイプ: {e.__class__.__name__}")
|
||||
print(f"エラー引数: {e.args}")
|
||||
print(f"エラーメッセージ: {str(e)}")
|
||||
|
||||
def handler_close(self):
|
||||
print("停止処理を実行。")
|
||||
stop_url = client_config["auth_host_url"] + "/stop"
|
||||
stop_json = {
|
||||
"pc_number": int(client_config["pc_number"]),
|
||||
"pc_uuid": str(client_config["pc_uuid"]),
|
||||
"pc_token": str(client_config["pc_token"])
|
||||
}
|
||||
try:
|
||||
responce = requests.post(stop_url, json=stop_json)
|
||||
if responce.status_code == 200:
|
||||
print("停止処理は成功しました。")
|
||||
elif responce.status_code == 401:
|
||||
print("認証に失敗しました。")
|
||||
else:
|
||||
print("内部エラーにより停止処理に失敗しました。")
|
||||
except:
|
||||
print("ネットワークエラーにより停止処理に失敗しました。")
|
||||
|
||||
print("データ削除を実行。")
|
||||
try:
|
||||
if client_config["eraser"] == True:
|
||||
appdata_local = os.path.expandvars("%LOCALAPPDATA%")
|
||||
appdata_roaming = os.path.expandvars("%APPDATA%")
|
||||
epic_del = self.delete_appdata(process_name="EpicGamesLauncher.exe", dir_path=f"{appdata_local}\\EpicGamesLauncher\\Saved")
|
||||
chrome_del = self.delete_appdata(process_name="chrome.exe", dir_path=f"{appdata_local}\\Google\\Chrome\\User Data")
|
||||
discord_del = self.delete_appdata(process_name="discord.exe", dir_path=f"{appdata_roaming}\\discord")
|
||||
steam_del = self.delete_appdata(process_name="steam.exe", dir_path=f"{appdata_local}\\Steam")
|
||||
ea_del = self.delete_appdata(process_name="EADesktop.exe", dir_path=f"{appdata_local}\\Electronic Arts")
|
||||
riot_del = self.delete_appdata(process_name="RiotClientServices.exe", dir_path=f"{appdata_local}\\Riot Games\\Riot Client")
|
||||
"""
|
||||
for i in client_config['erase_data'].keys():
|
||||
if i == 'example':
|
||||
pass
|
||||
else:
|
||||
erase_process_name = client_config['erase_data'][i]['process_name']
|
||||
erase_dir_path = client_config['erase_data'][i]['dir_path']
|
||||
erase_del = self.delete_appdata(process_name=erase_process_name, dir_path=erase_dir_path)
|
||||
"""
|
||||
|
||||
else:
|
||||
print("削除処理をスキップ。")
|
||||
except:
|
||||
print("データ削除に失敗しました。")
|
||||
|
||||
self.destroy()
|
||||
|
||||
def icon(self):
|
||||
self.iconify()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
init_result = init()
|
||||
if init_result == 1:
|
||||
warning_msgbox = tkinter.messagebox.showwarning(title=f"{app_name} | 多重起動エラー", message=f"すでに {app_name} は実行されています。\n正常に起動しない場合は、既に起動しているプロセスを終了してから、もう一度起動してみてください。")
|
||||
elif init_result == 2:
|
||||
pass
|
||||
else:
|
||||
app = App()
|
||||
app.mainloop()
|
441
dislocker_client_universal.py
Normal file
|
@ -0,0 +1,441 @@
|
|||
import os
|
||||
import json
|
||||
import tkinter.messagebox
|
||||
import customtkinter
|
||||
import subprocess
|
||||
import requests
|
||||
import hashlib
|
||||
import string
|
||||
import random
|
||||
import tkinter
|
||||
import threading
|
||||
import sys
|
||||
import shutil
|
||||
import uuid
|
||||
import time
|
||||
|
||||
app_name = "Dislocker"
|
||||
dislocker_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
||||
|
||||
os.chdir(dislocker_dir)
|
||||
|
||||
resource_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "resource")
|
||||
config_dir_path = "./config/"
|
||||
client_config_path = config_dir_path + "client.json"
|
||||
if not os.path.isfile(client_config_path):
|
||||
if not os.path.isdir(config_dir_path):
|
||||
os.mkdir(config_dir_path)
|
||||
|
||||
client_config = {
|
||||
"initial": 1,
|
||||
"auth_host_url": "http://localhost",
|
||||
"pc_number": 1,
|
||||
"master_password_hash": "",
|
||||
"testing": 0,
|
||||
"eraser": 1,
|
||||
"pc_uuid": "",
|
||||
"pc_token": ""
|
||||
}
|
||||
|
||||
elif os.path.isfile(client_config_path):
|
||||
with open(client_config_path, "r") as r:
|
||||
client_config = json.load(r)
|
||||
|
||||
def master_password_gen():
|
||||
numbers = string.digits # (1)
|
||||
password = ''.join(random.choice(numbers) for _ in range(10)) # (2)
|
||||
password_hash = hashlib.md5(password.encode()).hexdigest()
|
||||
result = {"password": password, "password_hash": password_hash}
|
||||
return result
|
||||
|
||||
def init(**kwargs):
|
||||
if client_config["initial"] == 1:
|
||||
pc_uuid = uuid.uuid4()
|
||||
client_config["pc_uuid"] = str(pc_uuid)
|
||||
|
||||
if "pc_number" in kwargs:
|
||||
client_config["pc_number"] = int(kwargs["pc_number"])
|
||||
else:
|
||||
tkinter.messagebox.showerror(title=f"{app_name} | 登録時にエラー", message=f"登録時にエラーが発生しました。\nPC番号が指定されていません。1個目の引数にPC番号、2個目の引数にワンタイムパスワードを指定して、もう一度お試しください。")
|
||||
return 2
|
||||
|
||||
if "onetime" in kwargs:
|
||||
onetime = str(kwargs["onetime"])
|
||||
else:
|
||||
tkinter.messagebox.showerror(title=f"{app_name} | 登録時にエラー", message=f"登録時にエラーが発生しました。\nワンタイムパスワードが指定されていません。1個目の引数にPC番号、2個目の引数にワンタイムパスワードを指定して、もう一度お試しください。")
|
||||
return 2
|
||||
|
||||
register_url = client_config["auth_host_url"] + "/register"
|
||||
register_json = {
|
||||
"pc_number": int(client_config["pc_number"]),
|
||||
"pc_uuid": str(pc_uuid),
|
||||
"onetime": onetime
|
||||
}
|
||||
|
||||
responce = requests.post(register_url, json=register_json)
|
||||
|
||||
if responce.status_code == 200:
|
||||
print("PCの情報が登録されました。")
|
||||
responce_json = responce.json()
|
||||
pc_token = str(responce_json["pc_token"])
|
||||
client_config["pc_token"] = pc_token
|
||||
|
||||
master_password = master_password_gen()
|
||||
msgbox = tkinter.messagebox.showinfo(title=f"{app_name} | 初回起動を検出", message=f"初回起動のようです。\nマスターパスワードを記録しておいてください。\nこれ以降二度と表示されることはないでしょう。\n\n{master_password["password"]}\n\nまた、認証先サーバーの接続先を指定してください。ロックを解除できなくなります。")
|
||||
client_config["master_password_hash"] = master_password["password_hash"]
|
||||
client_config["initial"] = 0
|
||||
|
||||
with open(client_config_path, "w") as w:
|
||||
json.dump(client_config, w, indent=4)
|
||||
return 2
|
||||
else:
|
||||
msgbox = tkinter.messagebox.showerror(title=f"{app_name} | 登録時にエラー", message=f"登録時にエラーが発生しました。\nワンタイムパスワードが間違っている可能性があります。")
|
||||
return 2
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
class App(customtkinter.CTk):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.title(f"{app_name} | ロック中")
|
||||
if client_config["testing"] == 1:
|
||||
pass
|
||||
else:
|
||||
self.attributes('-fullscreen', True)
|
||||
self.attributes('-topmost', True)
|
||||
|
||||
self.frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent')
|
||||
self.frame.grid(row=0, column=0, sticky='nsew')
|
||||
|
||||
lock = Lock()
|
||||
|
||||
def exit(self):
|
||||
self.unlock_taskmgr()
|
||||
self.toast()
|
||||
self.destroy()
|
||||
|
||||
def handler_close(self):
|
||||
pass
|
||||
|
||||
|
||||
class Lock(customtkinter.CTkToplevel):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
if client_config["testing"] == 1:
|
||||
self.title(f'{app_name} | PC番号 {client_config["pc_number"]} | テストモード')
|
||||
else:
|
||||
self.title(f'{app_name} | PC番号 {client_config["pc_number"]} | ロックされています')
|
||||
|
||||
self.window_width = 600
|
||||
self.window_height = 320
|
||||
self.screen_width = self.winfo_screenwidth()
|
||||
self.screen_height = self.winfo_screenheight()
|
||||
self.center_x = int(self.screen_width/2 - self.window_width/2)
|
||||
self.center_y = int(self.screen_height/2 - self.window_height/2)
|
||||
self.geometry(f"{str(self.window_width)}x{str(self.window_height)}+{str(self.center_x)}+{str(self.center_y)}")
|
||||
self.resizable(height=False, width=False)
|
||||
self.attributes('-topmost', True)
|
||||
self.grab_set()
|
||||
self.lift()
|
||||
self.protocol("WM_DELETE_WINDOW", self.handler_close)
|
||||
|
||||
self.emoji_font = customtkinter.CTkFont(family="Noto Color Emoji", size=32)
|
||||
self.title_font = customtkinter.CTkFont(family="Noto Sans CJK JP", size=32, weight="bold")
|
||||
self.pc_number_font = customtkinter.CTkFont(family="Noto Sans CJK JP", size=64, weight="bold")
|
||||
self.title_small_font = customtkinter.CTkFont(family="Noto Sans CJK JP", size=16)
|
||||
self.general_font = customtkinter.CTkFont(family="Noto Sans CJK JP", size=18)
|
||||
self.general_small_font = customtkinter.CTkFont(family="Noto Sans CJK JP", size=12)
|
||||
self.textbox_font = customtkinter.CTkFont(family="Noto Sans CJK JP", size=14)
|
||||
self.button_font = customtkinter.CTkFont(family="Noto Sans CJK JP", size=14)
|
||||
|
||||
|
||||
self.msg_title_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent')
|
||||
self.msg_title_frame.grid(row=0, column=0, padx=10, pady=10, sticky="nsew")
|
||||
|
||||
self.icon_title_1 = customtkinter.CTkLabel(self.msg_title_frame, text='😎', font=self.emoji_font, justify="left")
|
||||
self.icon_title_1.grid(row=0, column=0, padx=10, sticky="w")
|
||||
|
||||
self.msg_title_1 = customtkinter.CTkLabel(self.msg_title_frame, text=f'ちょっと待って!! PC番号 | {client_config["pc_number"]}', font=self.title_font, justify="left")
|
||||
self.msg_title_1.grid(row=0, column=1, padx=10, sticky="w")
|
||||
|
||||
self.msg_title_2 = customtkinter.CTkLabel(self.msg_title_frame, text="本当にあなたですか?", font=self.title_small_font, justify="left")
|
||||
self.msg_title_2.grid(row=1, column=1, padx=10, sticky="w")
|
||||
|
||||
self.msg_subtitle_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent')
|
||||
self.msg_subtitle_frame.grid(row=1, column=0, padx=10, pady=10, sticky="nsew")
|
||||
self.msg_subtitle_frame.grid_columnconfigure(0, weight=1)
|
||||
|
||||
self.msg_subtitle_1 = customtkinter.CTkLabel(self.msg_subtitle_frame, text='サインインするには、Discordのダイレクトメッセージに送信された\nパスワードを入力してください。', font=self.general_font, justify="left")
|
||||
self.msg_subtitle_1.grid(row=0, column=0, padx=10, sticky="ew")
|
||||
|
||||
self.msg_subtitle_2 = customtkinter.CTkLabel(self.msg_subtitle_frame, text='※ パスワードの有効期限は23:59までです。', font=self.general_small_font, justify="left")
|
||||
self.msg_subtitle_2.grid(row=1, column=0, padx=10, sticky="w")
|
||||
|
||||
self.input_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent')
|
||||
self.input_frame.grid(row=2, column=0, padx=10, pady=10, sticky="nsew")
|
||||
self.input_frame.columnconfigure(0, weight=1)
|
||||
|
||||
self.password_entry = customtkinter.CTkEntry(self.input_frame, placeholder_text='パスワード', show='*', font=self.textbox_font)
|
||||
self.password_entry.grid(row=0, column=0, padx=10, sticky="ew")
|
||||
self.password_entry.bind("<Return>", self.auth_start_ev)
|
||||
|
||||
self.button_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color='transparent')
|
||||
self.button_frame.grid(row=3, column=0, padx=10, pady=10, sticky="nsew")
|
||||
self.button_frame.columnconfigure(0, weight=3)
|
||||
self.button_frame.columnconfigure(1, weight=1)
|
||||
self.button_frame.columnconfigure(2, weight=1)
|
||||
|
||||
self.signin_button = customtkinter.CTkButton(self.button_frame, text='サインイン', command=self.auth_start, font=self.button_font)
|
||||
self.signin_button.grid(row=0, column=2, padx=10, sticky="e")
|
||||
|
||||
self.signout_button = customtkinter.CTkButton(self.button_frame, text='サインアウト', command=self.signout, font=self.button_font)
|
||||
self.signout_button.grid(row=0, column=1, padx=10, sticky="e")
|
||||
|
||||
self.help_button = customtkinter.CTkButton(self.button_frame, text='ヘルプ', command=self.help_dummy, font=self.button_font)
|
||||
self.help_button.grid(row=0, column=0, padx=10, sticky="w")
|
||||
|
||||
def help_wakeup(self):
|
||||
help = Help()
|
||||
|
||||
def hash_genarate(self, source):
|
||||
hashed = hashlib.md5(source.encode())
|
||||
return hashed.hexdigest()
|
||||
|
||||
def auth_start(self):
|
||||
auth_thread = threading.Thread(target=self.auth)
|
||||
auth_thread.daemon = True
|
||||
auth_thread.start()
|
||||
|
||||
def auth_start_ev(self, event):
|
||||
auth_thread = threading.Thread(target=self.auth)
|
||||
auth_thread.daemon = True
|
||||
auth_thread.start()
|
||||
|
||||
def button_disable(self):
|
||||
self.help_button.configure(state="disabled", fg_color="gray")
|
||||
self.signin_button.configure(state="disabled", fg_color="gray")
|
||||
self.signout_button.configure(state="disabled", fg_color="gray")
|
||||
|
||||
def button_enable(self):
|
||||
self.help_button.configure(state="normal", fg_color="#3c8dd0")
|
||||
self.signin_button.configure(state="normal", fg_color="#3c8dd0")
|
||||
self.signout_button.configure(state="normal", fg_color="#3c8dd0")
|
||||
|
||||
|
||||
def auth(self):
|
||||
self.button_disable()
|
||||
password = str(self.password_entry.get())
|
||||
|
||||
if len(password) == 10:
|
||||
print("マスターパスワードで認証を試行します。")
|
||||
master_password_hash = self.hash_genarate(str(self.password_entry.get()))
|
||||
if client_config["master_password_hash"] == master_password_hash:
|
||||
print("マスターパスワードで認証しました。")
|
||||
self.exit()
|
||||
else:
|
||||
print("マスターパスワードで認証できませんでした。")
|
||||
self.withdraw()
|
||||
msgbox = tkinter.messagebox.showinfo(title=f"{app_name} | 誤ったパスワード", message=f"パスワードが間違っています!")
|
||||
self.msg_subtitle_1.configure(text='パスワードが間違っています! ')
|
||||
self.button_enable()
|
||||
self.deiconify()
|
||||
|
||||
|
||||
print("認証サーバーにアクセスします。")
|
||||
auth_url = client_config["auth_host_url"] + "/verify"
|
||||
auth_json = {
|
||||
"pc_number": int(client_config["pc_number"]),
|
||||
"pc_uuid": str(client_config["pc_uuid"]),
|
||||
"pc_token": str(client_config["pc_token"]),
|
||||
"password": self.hash_genarate(str(self.password_entry.get()))
|
||||
}
|
||||
try:
|
||||
responce = requests.post(auth_url, json=auth_json)
|
||||
if responce.status_code == 200:
|
||||
print("認証サーバー経由で認証しました。")
|
||||
self.exit()
|
||||
else:
|
||||
print("認証サーバー経由での認証に失敗しました。")
|
||||
self.withdraw()
|
||||
msgbox = tkinter.messagebox.showinfo(title=f"{app_name} | 誤ったパスワード", message=f"パスワードが間違っています!")
|
||||
self.msg_subtitle_1.configure(text='パスワードが間違っています! ')
|
||||
self.button_enable()
|
||||
self.deiconify()
|
||||
except:
|
||||
print("認証サーバーにアクセスできません。マスターパスワードで認証を試行します。")
|
||||
master_password_hash = self.hash_genarate(str(self.password_entry.get()))
|
||||
if client_config["master_password_hash"] == master_password_hash:
|
||||
print("マスターパスワードで認証しました。")
|
||||
self.exit()
|
||||
else:
|
||||
print("マスターパスワードで認証できませんでした。")
|
||||
self.withdraw()
|
||||
msgbox = tkinter.messagebox.showinfo(title=f"{app_name} | ネットワークエラー", message=f"認証サーバーにアクセスできませんでした。\n続行するには、マスターパスワードを入力してください。")
|
||||
self.msg_subtitle_1.configure(text='ネットワークエラーが発生しています。\n続行するには、マスターパスワードを入力して下さい。 ')
|
||||
self.button_enable()
|
||||
self.deiconify()
|
||||
|
||||
def signout(self):
|
||||
self.withdraw()
|
||||
msgbox = tkinter.messagebox.showinfo(title=f"{app_name} | 未実装", message=f"ログアウトは未実装です。")
|
||||
self.deiconify()
|
||||
|
||||
def handler_close(self):
|
||||
pass
|
||||
|
||||
def help_dummy(self):
|
||||
self.withdraw()
|
||||
msgbox = tkinter.messagebox.showinfo(title=f"{app_name} | 未実装", message=f"ヘルプページは製作途中です。\nDiscordサーバーの指示に従って、認証を進めてください。")
|
||||
self.deiconify()
|
||||
|
||||
def exit(self):
|
||||
self.destroy()
|
||||
app.exit()
|
||||
|
||||
|
||||
class Help(customtkinter.CTkToplevel):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
if client_config["testing"] == 1:
|
||||
self.title(f'{app_name} | ヘルプ | テストモード')
|
||||
else:
|
||||
self.title(f'{app_name} | ヘルプ')
|
||||
self.geometry("600x400")
|
||||
self.resizable(height=False, width=False)
|
||||
self.attributes('-topmost', True)
|
||||
self.grab_set()
|
||||
self.lift()
|
||||
self.protocol("WM_DELETE_WINDOW", self.handler_close)
|
||||
msgbox = tkinter.messagebox.showinfo(title=f"{app_name} | 未実装", message=f"ヘルプページは製作途中です。\nDiscordサーバーの指示に従って、認証を進めてください。")
|
||||
self.destroy()
|
||||
|
||||
def handler_close(self):
|
||||
self.destroy()
|
||||
|
||||
class Stop():
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
print("停止処理を実行中...")
|
||||
stop_thread = threading.Thread(target=self.stop)
|
||||
stop_thread.run()
|
||||
|
||||
|
||||
def delete_appdata(self, **kwargs):
|
||||
process_name = kwargs["process_name"]
|
||||
dir_path = kwargs["dir_path"]
|
||||
|
||||
if not os.path.exists(dir_path):
|
||||
print(f"エラー: 指定されたディレクトリ {dir_path} が存在しません。")
|
||||
return 1
|
||||
|
||||
try:
|
||||
# プロセスの終了
|
||||
subprocess.run(['taskkill', '/f', '/t', '/im', process_name])
|
||||
print(f"{process_name} を終了しました。")
|
||||
|
||||
time.sleep(0.1)
|
||||
|
||||
# ディレクトリの削除
|
||||
i = 1
|
||||
ic = 0
|
||||
while i == 1:
|
||||
shutil.rmtree(dir_path)
|
||||
if os.path.isdir(dir_path):
|
||||
ic += 1
|
||||
if ic == 10:
|
||||
i = 0
|
||||
else:
|
||||
i = 0
|
||||
print(f"{dir_path} を削除しました。")
|
||||
|
||||
return 0
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"プロセス終了エラー: {e}")
|
||||
return 1
|
||||
except PermissionError as e:
|
||||
print(f"権限エラー: {e}")
|
||||
return 1
|
||||
except Exception as error:
|
||||
print("エラーが発生しました。\nエラー内容:")
|
||||
print(f"エラータイプ: {error.__class__.__name__}")
|
||||
print(f"エラー引数: {error.args}")
|
||||
print(f"エラーメッセージ: {str(error)}")
|
||||
return 1
|
||||
|
||||
def shutdown(self):
|
||||
shutdown_command = subprocess.run(['shutdown', '/s', '/t', '1'])
|
||||
|
||||
def stop(self):
|
||||
print("停止処理を実行。")
|
||||
if client_config["eraser"] == 1:
|
||||
#appdata_local = os.path.expandvars("%LOCALAPPDATA%")
|
||||
#appdata_roaming = os.path.expandvars("%APPDATA%")
|
||||
#epic_del = app.delete_appdata(process_name="EpicGamesLauncher.exe", dir_path=f"{appdata_local}\\EpicGamesLauncher\\Saved")
|
||||
#chrome_del = app.delete_appdata(process_name="chrome.exe", dir_path=f"{appdata_local}\\Google\\Chrome\\User Data")
|
||||
#discord_del = app.delete_appdata(process_name="discord.exe", dir_path=f"{appdata_roaming}\\discord")
|
||||
#steam_del = app.delete_appdata(process_name="steam.exe", dir_path=f"{appdata_local}\\Steam")
|
||||
#ea_del = app.delete_appdata(process_name="EADesktop.exe", dir_path=f"{appdata_local}\\Electronic Arts")
|
||||
#riot_del = app.delete_appdata(process_name="RiotClientServices.exe", dir_path=f"{appdata_local}\\Riot Games\\Riot Client")
|
||||
pass
|
||||
else:
|
||||
print("削除処理をスキップ。")
|
||||
stop_url = client_config["auth_host_url"] + "/stop"
|
||||
stop_json = {
|
||||
"pc_number": int(client_config["pc_number"]),
|
||||
"pc_uuid": str(client_config["pc_uuid"]),
|
||||
"pc_token": str(client_config["pc_token"])
|
||||
}
|
||||
try:
|
||||
responce = requests.post(stop_url, json=stop_json)
|
||||
if responce.status_code == 200:
|
||||
print("停止処理は成功しました。")
|
||||
elif responce.status_code == 401:
|
||||
print("認証に失敗しました。")
|
||||
tkinter.messagebox.showwarning(title=f"{app_name} | エラー", message=f"認証に失敗しました。\nDiscordサーバーの指示に従って、停止処理を自身で行ってください。")
|
||||
else:
|
||||
print("内部エラーにより停止処理に失敗しました。")
|
||||
result_msgbox = tkinter.messagebox.showwarning(title=f"{app_name} | エラー", message=f"内部エラーにより停止処理に失敗しました。\nDiscordサーバーの指示に従って、停止処理を自身で行ってください。")
|
||||
except:
|
||||
print("ネットワークエラーにより停止処理に失敗しました。")
|
||||
result_msgbox = tkinter.messagebox.showwarning(title=f"{app_name} | エラー", message=f"ネットワークエラーにより停止処理に失敗しました。\nDiscordサーバーの指示に従って、停止処理を自身で行ってください。")
|
||||
finally:
|
||||
self.shutdown()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = sys.argv
|
||||
if len(args) >= 2:
|
||||
if args[1] == "stop":
|
||||
init_result = init()
|
||||
if init_result == 1:
|
||||
warning_msgbox = tkinter.messagebox.showwarning(title=f"{app_name} | 多重起動エラー", message=f"もう終了処理を行っています。\nPCがシャットダウンするまで、もう少しお待ちください。")
|
||||
elif init_result == 2:
|
||||
pass
|
||||
else:
|
||||
stop = Stop()
|
||||
stop.run()
|
||||
|
||||
elif args[1] == "setup":
|
||||
init_result = init(pc_number=args[2], onetime=args[3])
|
||||
if init_result == 1:
|
||||
warning_msgbox = tkinter.messagebox.showwarning(title=f"{app_name} | 多重起動エラー", message=f"すでに {app_name} は実行されています。\n正常に起動しない場合は、既に起動しているプロセスを終了してから、もう一度起動してみてください。")
|
||||
elif init_result == 2:
|
||||
pass
|
||||
else:
|
||||
pass
|
||||
else:
|
||||
print("引数エラー。")
|
||||
else:
|
||||
init_result = init()
|
||||
if init_result == 1:
|
||||
warning_msgbox = tkinter.messagebox.showwarning(title=f"{app_name} | 多重起動エラー", message=f"すでに {app_name} は実行されています。\n正常に起動しない場合は、既に起動しているプロセスを終了してから、もう一度起動してみてください。")
|
||||
elif init_result == 2:
|
||||
pass
|
||||
else:
|
||||
app = App()
|
||||
app.protocol("WM_DELETE_WINDOW", app.handler_close)
|
||||
app.mainloop()
|
1605
dislocker_slash.py
Normal file
1
docs/pyinstaller.txt
Normal file
|
@ -0,0 +1 @@
|
|||
pyinstaller .\dislocker_client.py --noconsole --icon .\resource\icon\dislocker.ico --add-data ".\resource:resource"
|
|
@ -1,13 +1,11 @@
|
|||
# ログイン
|
||||
psql -U suti7 -d dislocker
|
||||
|
||||
CREATE TABLE user
|
||||
(user_id INTEGER PRIMARY KEY NOT NULL,
|
||||
discord_id INTEGER NOT NULL,
|
||||
discord_username VARCHAR(32) NOT NULL,
|
||||
PRIMARY KEY (user_id));
|
||||
CREATE TABLE club_member (id SERIAL NOT NULL, name VARCHAR(30) NOT NULL, discord_username VARCHAR(32) NOT NULL, discord_userid VARCHAR(18) NOT NULL, PRIMARY KEY (id));
|
||||
CREATE TABLE pc_list (pc_number INTEGER NOT NULL, using_user_id INTEGER, password_hash VARCHAR(32), PRIMARY KEY (pc_number), FOREIGN KEY (using_user_id) REFERENCES club_member(id));
|
||||
CREATE TABLE pc_usage_history (id SERIAL NOT NULL, member_id INTEGER NOT NULL, pc_number INTEGER NOT NULL, device_number INTEGER NOT NULL, start_use_time TIMESTAMP NOT NULL, end_use_time TIMESTAMP, use_detail VARCHAR(30), PRIMARY KEY (id), FOREIGN KEY (member_id) REFERENCES club_member(id), FOREIGN KEY (pc_number) REFERENCES pc_list(pc_number));
|
||||
|
||||
CREATE TABLE user_list (user_id INTEGER NOT NULL, discord_username VARCHAR(32) NOT NULL, discord_userid INTEGER NOT NULL, PRIMARY KEY (user_id));
|
||||
# PC登録
|
||||
INSERT INTO pc_list (pc_number) VALUES (PC番号をいれる);
|
||||
|
||||
# テーブルを作る
|
||||
CREATE TABLE web_auth (id SERIAL, username VARCHAR(10) NOT NULL, password VARCHAR(32) NOT NULL, PRIMARY KEY(id));
|
||||
INSERTのとき文字列はシングルクォーテーションで囲む!!!
|
4
requirements.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
discord.py
|
||||
psycopg2-binary
|
||||
openpyxl
|
||||
flask
|
5
requirements_client.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
customtkinter
|
||||
winotify
|
||||
keyboard
|
||||
requests
|
||||
pywin32
|
BIN
resource/cover/dislocker_dark.png
Normal file
After Width: | Height: | Size: 47 KiB |
BIN
resource/cover/dislocker_light.png
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
resource/icon/dislocker.ico
Normal file
After Width: | Height: | Size: 352 KiB |
BIN
resource/icon/dislocker_label.png
Normal file
After Width: | Height: | Size: 6.6 KiB |
BIN
resource/icon/dislocker_label_logo.png
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
resource/icon/dislocker_label_logo_white.png
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
resource/icon/dislocker_shutdown.ico
Normal file
After Width: | Height: | Size: 352 KiB |
BIN
resource/icon/png/128.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
resource/icon/png/16.png
Normal file
After Width: | Height: | Size: 695 B |
BIN
resource/icon/png/256.png
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
resource/icon/png/32.png
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
resource/icon/png/512.png
Normal file
After Width: | Height: | Size: 101 KiB |
BIN
resource/icon/png/64.png
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
resource/icon/png/shutdown/128.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
resource/icon/png/shutdown/16.png
Normal file
After Width: | Height: | Size: 727 B |
BIN
resource/icon/png/shutdown/256.png
Normal file
After Width: | Height: | Size: 34 KiB |
BIN
resource/icon/png/shutdown/32.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
resource/icon/png/shutdown/512.png
Normal file
After Width: | Height: | Size: 103 KiB |
BIN
resource/icon/png/shutdown/64.png
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
resource/success.png
Normal file
After Width: | Height: | Size: 33 KiB |
10
resource/verify.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Verify</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>だめです</h1>
|
||||
</body>
|
||||
|
||||
</html>
|
16
script/download.cmd
Normal file
|
@ -0,0 +1,16 @@
|
|||
@echo off
|
||||
set dir=%~dp0
|
||||
cd %dir%
|
||||
|
||||
set download_url=""
|
||||
|
||||
curl -L %download_url% -o %dir%\dislocker_client.zip
|
||||
|
||||
mkdir %dir%\temp_ds
|
||||
tar -xf %dir%\dislocker_client.zip -C %dir%\temp_ds
|
||||
|
||||
mkdir C:\ProgramData\Dislocker
|
||||
xcopy /e %dir%\temp_ds C:\ProgramData\Dislocker
|
||||
rmdir /s /q %dir%\temp_ds
|
||||
del %dir%\dislocker_client.zip
|
||||
C:\ProgramData\Dislocker\setup.cmd
|
26
script/setup.cmd
Normal file
|
@ -0,0 +1,26 @@
|
|||
@echo off
|
||||
set dir=%~dp0
|
||||
cd %dir%
|
||||
schtasks /create /tn "Dislocker_Client" /tr "%dir%dislocker_client.exe" /sc onlogon /ru "%USERNAME%" /rl highest /f
|
||||
if %ERRORLEVEL% == 0 (
|
||||
echo タスクスケジューラーの設定は完了しました。
|
||||
)
|
||||
if %ERRORLEVEL% == 1 (
|
||||
echo タスクスケジューラーの設定でエラーが発生しました。
|
||||
)
|
||||
Cscript "%dir%shortcut.vbs" "%dir%" "%dir%" "dislocker_client.exe" "stop" "シャットダウンと停止処理"
|
||||
if %ERRORLEVEL% == 0 (
|
||||
Cscript "%dir%shortcut.vbs" "%USERPROFILE%/Desktop" "%dir%" "dislocker_client.exe" "stop" "シャットダウンと停止処理"
|
||||
echo ショートカットの作成は完了しました。
|
||||
)
|
||||
if %ERRORLEVEL% == 1 (
|
||||
echo ショートカットの作成でエラーが発生しました。
|
||||
)
|
||||
|
||||
set /P pc_number=PC番号を入力
|
||||
set /P onetime=ワンタイムパスワードを入力
|
||||
set /P host_url=ホストURLを入力 (必要な場合のみ)
|
||||
|
||||
start %dir%dislocker_client.exe setup %pc_number% %onetime% %host_url%
|
||||
|
||||
pause
|
8
script/shortcut.vbs
Normal file
|
@ -0,0 +1,8 @@
|
|||
Set WshShell = CreateObject("WScript.Shell")
|
||||
Set args = Wscript.Arguments
|
||||
Set Shortcut = WshShell.CreateShortcut(args(0) & "\シャットダウンと終了処理.lnk")
|
||||
Shortcut.TargetPath = args(1) & args(2)
|
||||
Shortcut.Arguments = args(3)
|
||||
Shortcut.WorkingDirectory = args(1)
|
||||
Shortcut.Save
|
||||
WScript.Quit(0)
|
19
script/update.cmd
Normal file
|
@ -0,0 +1,19 @@
|
|||
@echo off
|
||||
set dir=%~dp0
|
||||
cd %dir%
|
||||
|
||||
set update_package_path="0"
|
||||
set /P update_package_path=アップデート元のzipファイルのパスを入力 :
|
||||
if %update_package_path%=="0" (set update_package_path=C:%HOMEPATH%\Downloads\dislocker_client_latest.zip)
|
||||
set dislocker_dir_path="0"
|
||||
set /P dislocker_dir_path=Dislockerのディレクトリのパスを入力 :
|
||||
if %dislocker_dir_path%=="0" (set dislocker_dir_path=C:\Dislocker)
|
||||
mkdir %dir%\temp_ds
|
||||
tar -xf %update_package_path% -C %dir%\temp_ds
|
||||
rmdir /s /q %dislocker_dir_path%\_internal
|
||||
mkdir %dislocker_dir_path%\_internal
|
||||
xcopy /e %dir%\temp_ds\_internal %dislocker_dir_path%\_internal
|
||||
xcopy /Y %dir%\temp_ds\dislocker_client.exe %dislocker_dir_path%\dislocker_client.exe
|
||||
rmdir /s /q %dir%\temp_ds
|
||||
echo アップデート完了。Defenderの警告を消すため、一度起動しておいてください。
|
||||
pause
|
24
script/update_online.cmd
Normal file
|
@ -0,0 +1,24 @@
|
|||
@echo off
|
||||
set dir=%~dp0
|
||||
cd %dir%
|
||||
|
||||
set download_url=""
|
||||
|
||||
taskkill /f /t /im dislocker_client_shutdown.exe
|
||||
taskkill /f /t /im dislocker_client.exe
|
||||
|
||||
curl -L %download_url% -o %dir%\dislocker_client.zip
|
||||
|
||||
mkdir %dir%\temp_ds\
|
||||
tar -xf %dir%\dislocker_client.zip -C %dir%\temp_ds\
|
||||
|
||||
rmdir /s /q C:\ProgramData\Dislocker\_internal\
|
||||
xcopy /e %dir%\temp_ds\_internal\ C:\ProgramData\Dislocker\_internal\
|
||||
xcopy /Y %dir%\temp_ds\dislocker_client.exe C:\ProgramData\Dislocker\dislocker_client.exe
|
||||
xcopy /Y %dir%\temp_ds\dislocker_client_shutdown.exe C:\ProgramData\Dislocker\dislocker_client_shutdown.exe
|
||||
xcopy /Y %dir%\temp_ds\shortcut.vbs C:\ProgramData\Dislocker\shortcut.vbs
|
||||
xcopy /Y %dir%\temp_ds\setup.cmd C:\ProgramData\Dislocker\setup.cmd
|
||||
rmdir /s /q %dir%\temp_ds\
|
||||
del %dir%\dislocker_client.zip
|
||||
echo アップデート完了。Defenderの警告を消すため、一度起動しておいてください。
|
||||
pause
|
34
test.py
|
@ -1,34 +0,0 @@
|
|||
# インストールした discord.py を読み込む
|
||||
import discord
|
||||
import secrets
|
||||
import string
|
||||
|
||||
|
||||
# 接続に必要なオブジェクトを生成
|
||||
client = discord.Client()
|
||||
|
||||
# 起動時に動作する処理
|
||||
@client.event
|
||||
async def on_ready():
|
||||
# 起動したらターミナルにログイン通知が表示される
|
||||
print('ログインしました')
|
||||
|
||||
# メッセージ受信時に動作する処理
|
||||
@client.event
|
||||
async def on_message(message):
|
||||
# メッセージ送信者がBotだった場合は無視する
|
||||
if message.author.bot:
|
||||
return
|
||||
# 「/neko」と発言したら「にゃーん」が返る処理
|
||||
if message.content == '/neko':
|
||||
await message.channel.send('にゃーん')
|
||||
|
||||
if message.content == '/password':
|
||||
await message.channel.send(get_random_password_string(4))
|
||||
def get_random_password_string(length):
|
||||
pass_chars = string.ascii_letters + string.digits
|
||||
password = ''.join(secrets.choice(pass_chars) for x in range(length))
|
||||
return password
|
||||
|
||||
# Botの起動とDiscordサーバーへの接続
|
||||
client.run('MTI0NzA1Mzc1NzUxOTM2NDEyNw.Gh5gIt.kz1acBMxphff9mEZLLWrEdEoVD4RJwgBW5P14o')
|