Compare commits

..

No commits in common. "9dec6938dd2805c70af4362964775ec6818b53db" and "451d7facc57bf67b01fc8afecc164cd62ec3f002" have entirely different histories.

4 changed files with 25 additions and 88 deletions

1
.gitignore vendored
View file

@ -162,4 +162,3 @@ cython_debug/
config/ config/
db/ db/
test.py

View file

@ -38,7 +38,6 @@ class Bot(discord.Client):
if msg_split[1].isdigit() and msg_split[2].isdigit(): if msg_split[1].isdigit() and msg_split[2].isdigit():
if int(msg_split[1]) <= 10 and int(msg_split[1]) >= 1: if int(msg_split[1]) <= 10 and int(msg_split[1]) >= 1:
password = self.password_generate(4) password = self.password_generate(4)
password_hash = self.hash_genarate(password)
cursor = self.db.cursor() cursor = self.db.cursor()
cursor.execute("SELECT * FROM club_member WHERE discord_userid = %s", (str(message.author.id),)) cursor.execute("SELECT * FROM club_member WHERE discord_userid = %s", (str(message.author.id),))
member_info = cursor.fetchall() member_info = cursor.fetchall()
@ -49,7 +48,7 @@ class Bot(discord.Client):
self.db.commit() self.db.commit()
cursor.execute("UPDATE pc_list SET using_user_id = %s WHERE pc_number = %s", (member_info[0][0], msg_split[1])) cursor.execute("UPDATE pc_list SET using_user_id = %s WHERE pc_number = %s", (member_info[0][0], msg_split[1]))
self.db.commit() self.db.commit()
cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password_hash, msg_split[1])) cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password, msg_split[1]))
self.db.commit() self.db.commit()
await message.channel.send(f"使用が開始されました。\nパスワード | {password}\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}\n") await message.channel.send(f"使用が開始されました。\nパスワード | {password}\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}\n")
@ -62,7 +61,7 @@ class Bot(discord.Client):
self.db.commit() self.db.commit()
cursor.execute("UPDATE pc_list SET using_user_id = %s WHERE pc_number = %s", (member_info[0][0], msg_split[1])) cursor.execute("UPDATE pc_list SET using_user_id = %s WHERE pc_number = %s", (member_info[0][0], msg_split[1]))
self.db.commit() self.db.commit()
cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password_hash, msg_split[1])) cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password, msg_split[1]))
self.db.commit() self.db.commit()
await message.channel.send(f"使用が開始されました。\nパスワード | {password}\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}\n") await message.channel.send(f"使用が開始されました。\nパスワード | {password}\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}\n")
@ -76,7 +75,6 @@ class Bot(discord.Client):
if msg_split[1].isdigit() and msg_split[2].isdigit(): if msg_split[1].isdigit() and msg_split[2].isdigit():
if int(msg_split[1]) <= 10 and int(msg_split[1]) >= 1: if int(msg_split[1]) <= 10 and int(msg_split[1]) >= 1:
password = self.password_generate(4) password = self.password_generate(4)
password_hash = self.hash_genarate(password)
cursor = self.db.cursor() cursor = self.db.cursor()
cursor.execute("SELECT * FROM club_member WHERE discord_userid = %s", (str(message.author.id),)) cursor.execute("SELECT * FROM club_member WHERE discord_userid = %s", (str(message.author.id),))
member_info = cursor.fetchall() member_info = cursor.fetchall()
@ -87,7 +85,7 @@ class Bot(discord.Client):
self.db.commit() self.db.commit()
cursor.execute("UPDATE pc_list SET using_user_id = %s WHERE pc_number = %s", (member_info[0][0], msg_split[1])) cursor.execute("UPDATE pc_list SET using_user_id = %s WHERE pc_number = %s", (member_info[0][0], msg_split[1]))
self.db.commit() self.db.commit()
cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password_hash, msg_split[1])) cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password, msg_split[1]))
self.db.commit() self.db.commit()
await message.channel.send(f"使用が開始されました。\nパスワード | {password}\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}\n") await message.channel.send(f"使用が開始されました。\nパスワード | {password}\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}\n")
@ -99,7 +97,7 @@ class Bot(discord.Client):
self.db.commit() self.db.commit()
cursor.execute("UPDATE pc_list SET using_user_id = %s WHERE pc_number = %s", (member_info[0][0], msg_split[1])) cursor.execute("UPDATE pc_list SET using_user_id = %s WHERE pc_number = %s", (member_info[0][0], msg_split[1]))
self.db.commit() self.db.commit()
cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password_hash, msg_split[1])) cursor.execute("UPDATE pc_list SET password_hash = %s WHERE pc_number = %s", (password, msg_split[1]))
self.db.commit() self.db.commit()
await message.channel.send(f"使用が開始されました。\nパスワード | {password}\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}\n") await message.channel.send(f"使用が開始されました。\nパスワード | {password}\nPC番号 | {msg_split[1]}\nデバイス番号 | {msg_split[2]}\n")
await self.get_channel(bot_config["log_channel_id"]).send(f'{member_info[0][2]}がPC{msg_split[1]}を使用しています') await self.get_channel(bot_config["log_channel_id"]).send(f'{member_info[0][2]}がPC{msg_split[1]}を使用しています')

View file

@ -1,59 +0,0 @@
import psycopg2
import os
import json
from flask import Flask, request, jsonify
config_dir_path = "./config/"
db_config_path = config_dir_path + "db.json"
if not os.path.isfile(db_config_path):
if not os.path.isdir(config_dir_path):
os.mkdir(config_dir_path)
db_config = {
"host": "localhost",
"db": "dislocker",
"username": "user",
"password": "example_pass",
"port": "5432"
}
with open(db_config_path, "w") as w:
json.dump(db_config, w, indent=4)
elif os.path.isfile(db_config_path):
with open(db_config_path, "r") as r:
db_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 check(self, pc_number, password):
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):
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__)
auth = Auth(db_config["host"], db_config["db"], db_config["port"], db_config["username"], db_config["password"])
@app.route('/verify', methods=['POST'])
def verify():
pc_number = int(request.json.get('pc_number'))
password = request.json.get('password')
if auth.check(pc_number, password) == 0:
auth.delete(pc_number)
return jsonify({'message': 'ok'}), 200
else:
return jsonify({'message': 'damedesu'}), 401
if __name__ == '__main__':
app.run()

View file

@ -1,11 +1,10 @@
import psycopg2
import os import os
import json import json
import customtkinter import customtkinter
from winotify import Notification, audio from winotify import Notification, audio
import keyboard import keyboard
import subprocess import subprocess
import requests
import hashlib
class App(customtkinter.CTk): class App(customtkinter.CTk):
def __init__(self): def __init__(self):
@ -90,18 +89,15 @@ class Lock(customtkinter.CTkToplevel):
self.signin_button = customtkinter.CTkButton(self.button_frame, text='サインイン', command=self.auth) self.signin_button = customtkinter.CTkButton(self.button_frame, text='サインイン', command=self.auth)
self.signin_button.grid(row=0, column=0, padx=10, pady=10) self.signin_button.grid(row=0, column=0, padx=10, pady=10)
def hash_genarate(self, source):
hashed = hashlib.md5(source.encode())
return hashed.hexdigest()
def auth(self): def auth(self):
auth_url = client_config["auth_host_url"] + "/verify" self.db = psycopg2.connect(f"host={db_config["host"]} dbname={db_config["db"]} port={db_config["port"]} user={db_config["username"]} password={db_config["password"]}")
auth_json = { cursor = self.db.cursor()
"pc_number": client_config["pc_number"], cursor.execute("SELECT * FROM pc_list WHERE pc_number = %s", (10,))
"password": self.hash_genarate(self.password_entry.get()) pc_info = cursor.fetchall()
} auth_password = str(self.password_entry.get())
responce = requests.post(auth_url, json=auth_json) if pc_info[0][2] == auth_password:
if responce.status_code == 200: cursor.execute("UPDATE pc_list SET password_hash = NULL WHERE pc_number = %s", (10,))
self.db.commit()
self.destroy() self.destroy()
app.exit() app.exit()
else: else:
@ -115,19 +111,22 @@ class Lock(customtkinter.CTkToplevel):
config_dir_path = "./config/" config_dir_path = "./config/"
client_config_path = config_dir_path + "client.json" db_config_path = config_dir_path + "db.json"
if not os.path.isfile(client_config_path): if not os.path.isfile(db_config_path):
if not os.path.isdir(config_dir_path): if not os.path.isdir(config_dir_path):
os.mkdir(config_dir_path) os.mkdir(config_dir_path)
client_config = { db_config = {
"auth_host_url": "localhost", "host": "localhost",
"pc_number": "" "db": "dislocker",
"username": "user",
"password": "example_pass",
"port": "5432"
} }
with open(client_config_path, "w") as w: with open(db_config_path, "w") as w:
json.dump(client_config, w, indent=4) json.dump(db_config, w, indent=4)
elif os.path.isfile(client_config_path): elif os.path.isfile(db_config_path):
with open(client_config_path, "r") as r: with open(db_config_path, "r") as r:
db_config = json.load(r) db_config = json.load(r)
if __name__ == '__main__': if __name__ == '__main__':