add insert and bash keys wg
This commit is contained in:
parent
e59fec22a7
commit
da42091020
139
data.py
139
data.py
|
@ -1,43 +1,114 @@
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
import subprocess
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
#initialize database
|
||||||
create = sqlite3.connect("db")
|
create = sqlite3.connect("db")
|
||||||
connect = create.cursor()
|
connect = create.cursor()
|
||||||
# Create TABLE only used once
|
|
||||||
# connect.execute("""CREATE TABLE IPS (
|
|
||||||
# user_vpn,
|
|
||||||
# user_ips text
|
|
||||||
# )""")
|
|
||||||
|
|
||||||
def insert_ips():
|
#Create TABLE only used once
|
||||||
#user input
|
connect.execute("""CREATE TABLE VPN (
|
||||||
# user_name = input(str("username: "))
|
user_vpn text,
|
||||||
# user_ips = input(str("ip: "))
|
user_ips text,
|
||||||
# #add input to list inside tuple
|
public_key blob,
|
||||||
# users = [
|
private_key blob,
|
||||||
# (user_name,user_ips)
|
symbol,
|
||||||
# ]
|
date blob,
|
||||||
# insert 2 values to IPS TABLE
|
time blob
|
||||||
# connect.executemany("INSERT INTO IPS VALUES (?,?) ", users)
|
)""")
|
||||||
# commit the input to db
|
|
||||||
# create.commit()
|
def user_input():
|
||||||
# read db with row id
|
#read keys
|
||||||
connect.execute("SELECT rowid, * FROM IPS") #to check with rowid use WHERE rowid = 1
|
subprocess.run("wg genkey | tee privatekey | wg pubkey > publickey",
|
||||||
#close the db
|
shell=True,capture_output=True
|
||||||
def checking():
|
)
|
||||||
userinput = '10.10.11.1'
|
#convert keys to txt file
|
||||||
|
subprocess.run("mv publickey publickey.txt && mv privatekey privatekey.txt",shell=True)
|
||||||
|
#format date and time
|
||||||
|
now = datetime.now()
|
||||||
|
dates = now.strftime("%Y-%m-%d")
|
||||||
|
times = now.strftime("%H:%M:%S")
|
||||||
|
#read keys file
|
||||||
|
with open("publickey.txt","r") as pk:
|
||||||
|
public = pk.read()
|
||||||
|
print(public)
|
||||||
|
with open("privatekey.txt","r") as prk:
|
||||||
|
private = prk.read()
|
||||||
|
# user input
|
||||||
|
user_name = input(str("Insert username: "))
|
||||||
|
user_ips = input(str("Insert IP:"))
|
||||||
|
user_public_key = public
|
||||||
|
user_private_key = private
|
||||||
|
date = dates
|
||||||
|
time = times
|
||||||
|
# reverse function
|
||||||
|
add_ips(
|
||||||
|
user_name,
|
||||||
|
user_ips,
|
||||||
|
user_public_key,
|
||||||
|
user_private_key,
|
||||||
|
date,
|
||||||
|
time
|
||||||
|
)
|
||||||
|
#add users & ips & keys & date & time into db
|
||||||
|
def add_ips(
|
||||||
|
user_name,
|
||||||
|
user_ips,
|
||||||
|
user_public_key,
|
||||||
|
user_private_key,
|
||||||
|
date,
|
||||||
|
time
|
||||||
|
):
|
||||||
|
#insert keys with symbols
|
||||||
|
symbols = '< > & " = '
|
||||||
|
connect.execute('INSERT INTO VPN (symbol) VALUES (?)', (symbols,))
|
||||||
|
#insert values to VPN TABLE
|
||||||
|
connect.execute("INSERT INTO VPN (symbol) VALUES (?,?,?,?,?,?,?)",
|
||||||
|
(
|
||||||
|
('User = ' + user_name),
|
||||||
|
(user_ips + "/24"),
|
||||||
|
(user_public_key),
|
||||||
|
(user_private_key),
|
||||||
|
('Date: ' + date),
|
||||||
|
('Time: ' + time)
|
||||||
|
))
|
||||||
|
|
||||||
|
#Commit into db
|
||||||
|
create.commit()
|
||||||
|
|
||||||
|
#delete the keys
|
||||||
|
subprocess.run("rm privatekey.txt publickey.txt",shell=True)
|
||||||
|
|
||||||
|
#should deltet after finish
|
||||||
|
connect.execute("SELECT rowid, * FROM VPN") #to check with rowid use WHERE rowid = 1
|
||||||
items = connect.fetchall()
|
items = connect.fetchall()
|
||||||
for item in items:
|
for item in items:
|
||||||
item_list = [item[2]]
|
print(item)
|
||||||
print(item_list)
|
|
||||||
# if item_list == userinput:
|
|
||||||
# print('ip exist')
|
|
||||||
# break
|
|
||||||
# else:
|
|
||||||
# print('new ip')
|
|
||||||
# break
|
|
||||||
#call the func
|
|
||||||
insert_ips()
|
|
||||||
checking()
|
|
||||||
|
|
||||||
#close the db
|
#-----------------------------------------------------
|
||||||
|
|
||||||
|
# #Checking if the ip exsit
|
||||||
|
# def checking():
|
||||||
|
# #read db with row id
|
||||||
|
# connect.execute("SELECT rowid, * FROM VPN") #to check with rowid use WHERE rowid = 1
|
||||||
|
# items = connect.fetchall()
|
||||||
|
# for item in items:
|
||||||
|
# print(item[3])
|
||||||
|
# userinput = '10.10.11.1'
|
||||||
|
# items = connect.fetchall()
|
||||||
|
# for item in items:
|
||||||
|
# item_list = [item[2]]
|
||||||
|
# print(item_list)
|
||||||
|
# if item_list == userinput:
|
||||||
|
# print('ip exist')
|
||||||
|
# break
|
||||||
|
# else:
|
||||||
|
# print('new ip')
|
||||||
|
# break
|
||||||
|
|
||||||
|
# #call fucn
|
||||||
|
user_input()
|
||||||
|
# checking()
|
||||||
|
|
||||||
|
#Close the db after finishing
|
||||||
create.close()
|
create.close()
|
|
@ -27,7 +27,7 @@ sleep 1
|
||||||
#Checking IPS
|
#Checking IPS
|
||||||
echo "Checking.....";sleep 1
|
echo "Checking.....";sleep 1
|
||||||
python3 -c 'import cat;cat.cat_search()'
|
python3 -c 'import cat;cat.cat_search()'
|
||||||
check_ip() {
|
check_ip () {
|
||||||
for ip in "${ips[@]}"
|
for ip in "${ips[@]}"
|
||||||
do
|
do
|
||||||
if [[ "$ip" == "$user_input" ]];then
|
if [[ "$ip" == "$user_input" ]];then
|
||||||
|
|
Loading…
Reference in New Issue