Compare commits
No commits in common. "ab7147ffde111d05a7e7f8decd057e7f6a2b1bb1" and "34ce84532dae9354a2da539ecd140215e85c5b33" have entirely different histories.
ab7147ffde
...
34ce84532d
2 changed files with 11 additions and 92 deletions
|
@ -34,53 +34,18 @@ class Auth():
|
|||
self.db = psycopg2.connect(f"host={host} dbname={db} port={port} user={user} password={password}")
|
||||
|
||||
def check(self, pc_number, password):
|
||||
try:
|
||||
cursor = self.db.cursor()
|
||||
cursor.execute("SELECT * FROM pc_list WHERE pc_number = %s AND password_hash = %s", (pc_number, password))
|
||||
pc_info = cursor.fetchall()
|
||||
if not pc_info:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
finally:
|
||||
cursor.close()
|
||||
cursor = self.db.cursor()
|
||||
cursor.execute("SELECT * FROM pc_list WHERE pc_number = %s AND password_hash = %s", (pc_number, password))
|
||||
pc_info = cursor.fetchall()
|
||||
if not pc_info:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
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()
|
||||
finally:
|
||||
cursor.close()
|
||||
|
||||
def stop(self, **kwargs):
|
||||
try:
|
||||
pc_number = int(kwargs["pc_number"])
|
||||
cursor = self.db.cursor()
|
||||
cursor.execute("SELECT * FROM pc_list WHERE pc_number = %s", (pc_number,))
|
||||
pc_list_record = cursor.fetchall()
|
||||
if not pc_list_record[0][1] == None:
|
||||
cursor.execute("UPDATE pc_list SET using_user_id = NULL WHERE pc_number = %s", (pc_number,))
|
||||
|
||||
if not pc_list_record[0][2] == None:
|
||||
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_list_record[0][1], pc_number))
|
||||
pc_usage_history_record = cursor.fetchall()
|
||||
cursor.execute("UPDATE pc_usage_history SET end_use_time = current_timestamp WHERE id = %s", (pc_usage_history_record[0][0],))
|
||||
self.db.commit()
|
||||
result = {"result": "ok"}
|
||||
|
||||
else:
|
||||
result = {"result": "not_used"}
|
||||
|
||||
except:
|
||||
result = {"result": "error"}
|
||||
|
||||
finally:
|
||||
cursor.close()
|
||||
return result
|
||||
|
||||
cursor = self.db.cursor()
|
||||
cursor.execute("UPDATE pc_list SET password_hash = NULL WHERE pc_number = %s", (pc_number,))
|
||||
self.db.commit()
|
||||
|
||||
|
||||
app = Flask(__name__, static_folder="./resource/")
|
||||
|
@ -90,29 +55,13 @@ auth = Auth(server_config["db"]["host"], server_config["db"]["db_name"], server_
|
|||
def verify():
|
||||
pc_number = int(request.json.get('pc_number'))
|
||||
password = request.json.get('password')
|
||||
print(str(pc_number) + "の認証処理を開始...")
|
||||
print(str(pc_number), str(password))
|
||||
|
||||
if auth.check(pc_number, password) == 0:
|
||||
auth.delete(pc_number)
|
||||
print(str(pc_number) + "の認証処理は成功しました.")
|
||||
return jsonify({'message': 'ok'}), 200
|
||||
else:
|
||||
print(str(pc_number) + "の認証処理は失敗しました.")
|
||||
return jsonify({'message': 'damedesu'}), 401
|
||||
|
||||
@app.route('/stop', methods=['POST'])
|
||||
def stop():
|
||||
pc_number = int(request.json.get('pc_number'))
|
||||
print(str(pc_number) + "の使用停止処理を開始...")
|
||||
pc_stop = auth.stop(pc_number=pc_number)
|
||||
if pc_stop["result"] == "ok":
|
||||
print(str(pc_number) + "の使用停止処理は成功しました.")
|
||||
return jsonify({'message': 'ok'}), 200
|
||||
else:
|
||||
print(str(pc_number) + "の使用停止処理は失敗しました.")
|
||||
return jsonify({'message': 'error'}), 500
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host="0.0.0.0", port=5000, debug=True)
|
|
@ -11,8 +11,6 @@ import string
|
|||
import random
|
||||
import tkinter
|
||||
import threading
|
||||
import signal
|
||||
import sys
|
||||
|
||||
class App(customtkinter.CTk):
|
||||
def __init__(self):
|
||||
|
@ -146,7 +144,6 @@ class Lock(customtkinter.CTkToplevel):
|
|||
|
||||
def auth_start(self):
|
||||
auth_thread = threading.Thread(target=self.auth)
|
||||
auth_thread.daemon = True
|
||||
auth_thread.start()
|
||||
|
||||
def auth(self):
|
||||
|
@ -226,34 +223,7 @@ class Help(customtkinter.CTkToplevel):
|
|||
def handler_close(self):
|
||||
self.destroy()
|
||||
|
||||
class Monitor():
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
def start(self):
|
||||
monitor_thread = threading.Thread(target=self.run)
|
||||
monitor_thread.start()
|
||||
|
||||
def signal_handler(self, signum, frame):
|
||||
print("シャットダウンを検出。")
|
||||
stop_url = client_config["auth_host_url"] + "/stop"
|
||||
stop_json = {
|
||||
"pc_number": int(client_config["pc_number"])
|
||||
}
|
||||
try:
|
||||
responce = requests.post(stop_url, json=stop_json)
|
||||
if responce.status_code == 200:
|
||||
print("停止処理は成功しました。")
|
||||
self.exit()
|
||||
else:
|
||||
print("内部エラーにより停止処理に失敗しました。")
|
||||
except:
|
||||
print("ネットワークエラーにより停止処理に失敗しました。")
|
||||
finally:
|
||||
sys.exit()
|
||||
|
||||
def run(self):
|
||||
signal.signal(signal.SIGTERM, self.signal_handler)
|
||||
|
||||
|
||||
def master_password_gen():
|
||||
|
|
Loading…
Reference in a new issue