Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Scratchcat1 authored Jan 9, 2018
1 parent cfc4356 commit d38caa0
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 53 deletions.
2 changes: 1 addition & 1 deletion AATC_Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def GetUserID(self,Username):
def GetUsername(self,UserID):
self.Send("GetUsername",(UserID,))
Sucess,Message,Username = self.Recv()
return Sucess,Message,Username #Username will be ["asfgg"] as it is how database returns it
return Sucess,Message,Username

def AddUser(self,Username,Password):
self.Send("AddUser",(Username,Password))
Expand Down
27 changes: 4 additions & 23 deletions AATC_Crypto.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#AATC crypto module
import codecs,recvall,ast,binascii,os,AATC_Config,AATC_CryptoBeta
import codecs,recvall,ast,os,AATC_Config,AATC_CryptoBeta
from Crypto.Cipher import AES,PKCS1_OAEP
from Crypto.PublicKey import RSA

Expand Down Expand Up @@ -196,26 +196,7 @@ def SetEncryptionKeys(self,AESKey,IV):























##############################################



Expand All @@ -242,8 +223,8 @@ def SplitData(self,data):


def GenerateKeys(AES_KeySize):
AESKey = binascii.b2a_hex(os.urandom(AES_KeySize//2)) # Here to allow regeneration of AES key while still in loop if required.
IV = binascii.b2a_hex(os.urandom(AES_KeySize//2))
AESKey = os.urandom(AES_KeySize) # Here to allow regeneration of AES key while still in loop if required.
IV = os.urandom(AES_KeySize)
return AESKey,IV


37 changes: 23 additions & 14 deletions AATC_DB.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ class DBConnection:
"""


def __init__(self,DatabaseName = "Main.db"):
print("Initializing database connection '",DatabaseName,"'")
def __init__(self):
print("Initializing database connection ")
self._db_con = sql.connect("localhost","AATC_Server","password","AATC_Database")
self._cur = self._db_con.cursor()
self._cur_header = self._db_con.cursor()

def Exit(self):
self._db_con.close()
def Table_Headers(self,TableName):
self._cur_header.execute("SHOW COLUMNS FROM "+ TableName)
self._cur_header.execute("SHOW COLUMNS FROM %s",( TableName))
result = self._cur_header.fetchall()
Headers = []
for item in result:
Expand Down Expand Up @@ -328,7 +328,7 @@ def MonitorChangePassword(self,MonitorID,OldPassword,NewPassword):
return False, "Incorrect old password"

def GetMonitorDrones(self,MonitorID):
self._cur.execute("SELECT Drone.* FROM Drone,MonitorPermission WHERE Drone.UserID = MonitorPermission.UserID and MonitorPermission.MonitorID = %s",(MonitorID,))
self._cur.execute("SELECT Drone.* FROM Drone,MonitorPermission WHERE Drone.UserID = MonitorPermission.UserID AND MonitorPermission.MonitorID = %s",(MonitorID,))
self._db_con.commit()
return True,str(self.Table_Headers("Drone")),self._cur.fetchall()

Expand All @@ -345,11 +345,8 @@ def GetMonitorFlightWaypoints(self,MonitorID):
def GetMonitorID(self,MonitorName):
self._cur.execute("SELECT MonitorID FROM Monitor WHERE MonitorName = %s",(MonitorName,))
result = self._cur.fetchall()
if len(result) != 0:
Sucess = True
else:
Sucess = False
return Sucess,"['MonitorID']",result
return True,"['MonitorID']",result

def GetMonitorName(self,MonitorID):
self._cur.execute("SELECT MonitorName FROM Monitor WHERE MonitorID = %s",(MonitorID,))
return True,"['MonitorName']",self._cur.fetchall()
Expand Down Expand Up @@ -491,28 +488,40 @@ def Bot_GetUserID(self,chat_id):
##########################################################################

def ResetDatabase(self):
self._cur.execute("SET FOREIGN_KEY_CHECKS = 0")
self._cur.execute("SET FOREIGN_KEY_CHECKS = 0") #Otherwise dropping tables will raise errors.
TABLES = ["User","Drone","Monitor","MonitorPermission","Flight","FlightWaypoints","NoFlyZone","DroneCredentials","InputStack","Sessions"]
for item in TABLES:
for item in TABLES: # Drops all tables
self._cur.execute("DROP TABLE IF EXISTS {0}".format(item))

self._cur.execute("CREATE TABLE User(UserID INTEGER PRIMARY KEY AUTO_INCREMENT, Username TEXT,Password TEXT, PublicVisibleFlights INT, PermissionAdder INT , ZoneCreatorPermission INT, ZoneRemoverPermission INT,ZoneModifierPermission INT)")
self._cur.execute("CREATE TABLE Drone(DroneID INTEGER PRIMARY KEY AUTO_INCREMENT, UserID INT, DroneName TEXT, DroneType TEXT, DroneSpeed INT, DroneRange INT, DroneWeight REAL, FlightsFlown INT, LastCoords TEXT, LastBattery REAL)")
self._cur.execute("CREATE TABLE Monitor(MonitorID INTEGER PRIMARY KEY AUTO_INCREMENT, MonitorName TEXT, MonitorPassword TEXT)")
self._cur.execute("CREATE TABLE MonitorPermission(MonitorID INT ,UserID INT, LastAccessed TEXT, ExpiryDate TEXT,PRIMARY KEY(MonitorID,UserID),FOREIGN KEY(MonitorID) REFERENCES Monitor(MonitorID))")
self._cur.execute("CREATE TABLE Flight(FlightID INTEGER PRIMARY KEY AUTO_INCREMENT, DroneID INT, StartCoords TEXT, EndCoords TEXT, StartTime REAL, ETA REAL, EndTime REAL, Distance REAL,XOffset REAL , YOffset REAL , ZOffset REAL,Completed INT)")
self._cur.execute("CREATE TABLE FlightWaypoints(FlightID INT, WaypointNumber INT, Coords TEXT, ETA REAL, BlockTime INT)")
self._cur.execute("CREATE TABLE FlightWaypoints(FlightID INT, WaypointNumber INT, Coords TEXT, ETA REAL, BlockTime INT ,PRIMARY KEY(FlightID,WaypointNumber))")
self._cur.execute("CREATE TABLE NoFlyZone(ZoneID INTEGER PRIMARY KEY AUTO_INCREMENT, StartCoord TEXT, EndCoord TEXT, Level INT, OwnerUserID INT)")
self._cur.execute("CREATE TABLE DroneCredentials(DroneID INTEGER PRIMARY KEY AUTO_INCREMENT ,DronePassword TEXT)")

self._cur.execute("CREATE TABLE InputStack(chat_id INT , stack_pos INT, value TEXT)")
self._cur.execute("CREATE TABLE InputStack(chat_id INT , stack_pos INT, value TEXT, PRIMARY KEY(chat_id,stack_pos))")
self._cur.execute("CREATE TABLE Sessions(chat_id INT PRIMARY KEY, UserID INT)")

self._cur.execute("SET FOREIGN_KEY_CHECKS = 1")
self._cur.execute("SET FOREIGN_KEY_CHECKS = 1") # Reenables checks
self._db_con.commit()



#Pre Primary/Forigen key thing
##self._cur.execute("CREATE TABLE User(UserID INTEGER PRIMARY KEY AUTO_INCREMENT, Username TEXT,Password TEXT, PublicVisibleFlights INT, PermissionAdder INT , ZoneCreatorPermission INT, ZoneRemoverPermission INT,ZoneModifierPermission INT)")
##self._cur.execute("CREATE TABLE Drone(DroneID INTEGER PRIMARY KEY AUTO_INCREMENT, UserID INT, DroneName TEXT, DroneType TEXT, DroneSpeed INT, DroneRange INT, DroneWeight REAL, FlightsFlown INT, LastCoords TEXT, LastBattery REAL)")
##self._cur.execute("CREATE TABLE Monitor(MonitorID INTEGER PRIMARY KEY AUTO_INCREMENT, MonitorName TEXT, MonitorPassword TEXT)")
##self._cur.execute("CREATE TABLE MonitorPermission(MonitorID INT ,UserID INT, LastAccessed TEXT, ExpiryDate TEXT,PRIMARY KEY(MonitorID,UserID),FOREIGN KEY(MonitorID) REFERENCES Monitor(MonitorID))")
##self._cur.execute("CREATE TABLE Flight(FlightID INTEGER PRIMARY KEY AUTO_INCREMENT, DroneID INT, StartCoords TEXT, EndCoords TEXT, StartTime REAL, ETA REAL, EndTime REAL, Distance REAL,XOffset REAL , YOffset REAL , ZOffset REAL,Completed INT)")
##self._cur.execute("CREATE TABLE FlightWaypoints(FlightID INT, WaypointNumber INT, Coords TEXT, ETA REAL, BlockTime INT)")
##self._cur.execute("CREATE TABLE NoFlyZone(ZoneID INTEGER PRIMARY KEY AUTO_INCREMENT, StartCoord TEXT, EndCoord TEXT, Level INT, OwnerUserID INT)")
##self._cur.execute("CREATE TABLE DroneCredentials(DroneID INTEGER PRIMARY KEY AUTO_INCREMENT ,DronePassword TEXT)")
##
##self._cur.execute("CREATE TABLE InputStack(chat_id INT , stack_pos INT, value TEXT)")
##self._cur.execute("CREATE TABLE Sessions(chat_id INT PRIMARY KEY, UserID INT)")



Expand Down
4 changes: 2 additions & 2 deletions AATC_Drone_Logic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AATC_Drone,threading,queue,math,time,AATC_GPIO,random, AATC_Config
import AATC_Drone,threading,queue,time,AATC_GPIO,random, AATC_Config
import AATC_Coordinate

class DroneLogicSystem:
Expand Down Expand Up @@ -97,7 +97,7 @@ def GetAllFlightInfo(D,DRONEID,FlightID): #Gets all drone flight information
WSucess,WaypointsMessage,FlightWaypointsData = D.GetFlightWaypoints(FlightID)
if not (DSucess and FSucess and WSucess):
print(DroneMessage,FlightMessage,WaypointsMessage)
raise Exception("FlightData or FlightWaypointData was not sucessfully obtained")
raise Exception("FlightData or FlightWaypointData or DroneData was not sucessfully obtained")

DroneInfo = AATC_Drone.MakeDroneInfo(DroneMessage, DroneData)
Flight = AATC_Drone.GetFlightObject(FlightMessage,FlightData)
Expand Down
20 changes: 10 additions & 10 deletions AATC_Server_002.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
def GetTime():
return int(time.time())

def CoordLessThanOrEqual(Coord1,Coord2):# True if Coord1 <= Coord2
List1 = list(Coord1)
List2 = list(Coord2)
BoolList = []
for x in range(len(List1)): #Goes through each item in the lists
if List1[x] <= List2[x]: #If The Coord1[x] <= Coord2[x]
BoolList.append(True)
else:
BoolList.append(False)
return all(BoolList)
##def CoordLessThanOrEqual(Coord1,Coord2):# True if Coord1 <= Coord2
## List1 = list(Coord1)
## List2 = list(Coord2)
## BoolList = []
## for x in range(len(List1)): #Goes through each item in the lists
## if List1[x] <= List2[x]: #If The Coord1[x] <= Coord2[x]
## BoolList.append(True)
## else:
## BoolList.append(False)
## return all(BoolList)



Expand Down
5 changes: 2 additions & 3 deletions AATC_Server_Starter.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,16 @@ def StartProcesses(Control_Queue):
Control_Queue.put(("Controller","Create_Process",("Cleaner",AATC_Server.Cleaner)))

Control_Queue.put(("Controller","Create_Process",("Hedabot",HedaBot.TelebotLaunch,())))
###Control_Queue.put(("Controller","Create_Process",("Flask_Server",StartFlaskServer,())))
print("[StartProcesses] All processes started")


if __name__ == "__main__":
print("Server is starting")




Control_Queue = AATC_GPIO.Create_Controller()
StartProcesses(Control_Queue)


Main_Command = ""
while Main_Command != "EXIT":
Expand Down

0 comments on commit d38caa0

Please sign in to comment.