Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
-Minor bug fixes and improvements.
-AATC_Hedabot_Temp will no longer recieve regular updates (program was tempoary solution until ```Hedabot.py``` was developed and stable)
  • Loading branch information
Scratchcat1 authored Nov 14, 2017
1 parent 073fcf5 commit e81a308
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 37 deletions.
2 changes: 1 addition & 1 deletion AATC_AStar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
try:
import PriorityQueue.PriorityQueueC as PriorityQueue
except:
print("PriotityQueueC not available, defaulting to pure python")
print("PriorityQueueC not available, defaulting to pure python")
import PriorityQueue.PriorityQueue as PriorityQueue

except:
Expand Down
13 changes: 6 additions & 7 deletions AATC_Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
#
#############################################################


import socket,codecs,ast,recvall,AATC_Crypto
#Create Socket
#Create Connection

def Connect(remote_ip,PORT):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Expand All @@ -38,13 +43,6 @@ def Connect(remote_ip,PORT):
return s




import socket,codecs,ast,recvall,AATC_Crypto
#Create Socket
#Create Connection


##def split(tup,num = 3): # Used to remove the data section for non data
## Sucess,Message,Data = tup[0],tup[1],tup[2]
## if num == 3:
Expand Down Expand Up @@ -233,6 +231,7 @@ def GetMonitorPermissionUser(self):
def Exit(self):
self.Send("Exit",())
Sucess,Message,_ = self.Recv()
self.con.close()
return Sucess,Message


Expand Down
4 changes: 2 additions & 2 deletions AATC_Client_Text_UI.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def SetDroneCredentials(self):
DroneID = int(input("DroneID >>"))
DronePassword = input("Drone Password >>")
Sucess,Message = self.UserInterface.SetDroneCredentials(DroneID,DronePassword)
self.DisplayResults(Sucess,Message,Credentials)
self.DisplayResults(Sucess,Message)

def CheckDroneOwnership(self):
UserID = int(input("UserID >>"))
Expand Down Expand Up @@ -282,7 +282,7 @@ def SetFlightVisibility(self):

def SetAccountType(self):
Permission = input("Account Type >>")
Type = int(input("Account Type >>"))
Type = int(input("Account Type VAlue >>"))
Sucess,Message = self.UserInterface.SetAccountType(Permission,Type)
self.DisplayResults(Sucess,Message)

Expand Down
6 changes: 4 additions & 2 deletions AATC_Config.py

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions AATC_CryptoBeta.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import time,codecs,socket,hashlib,AATC_Config
import time,codecs,socket,hashlib,AATC_Config,copy
from Crypto.PublicKey import RSA
from Crypto.Hash import SHA256
from Crypto.Signature import PKCS1_PSS
Expand All @@ -20,6 +20,7 @@ def GenerateCertificate(Name,Issuer,NotBefore,NotAfter,PublicKey,IssuerPrivateKe
return Certificate

def VerifyCertificates(CertificateChain,RootCertificates,con = False, Reverse = False):
CertificateChain = copy.deepcopy(CertificateChain) #To prevent loss of chain when verifing.
if len(CertificateChain) > AATC_Config.MAX_CERTIFICATE_CHAIN_LENGTH:
return False
if Reverse:
Expand Down Expand Up @@ -83,7 +84,7 @@ def GetSignatureSource(Certificate):

# CERTIFICATE CHAIN MUST RUN FROM ROOT CERTIFIATE TO SERVER

def CreateTestChain(length,RSA_KeySize,PRIVATE_KEY):
def CreateTestChain(length,RSA_KeySize,PRIVATE_KEY,hostname="localhost"):
chain = []
Issuer = "IssuerA"
for x in range(length):
Expand All @@ -93,12 +94,11 @@ def CreateTestChain(length,RSA_KeySize,PRIVATE_KEY):
puk = RSAKey.publickey().exportKey("DER")

if x == str(length-1):
print("HI")
x = "localhost"
x = hostname
cert = GenerateCertificate(x,Issuer,1,10000000000,puk,PRIVATE_KEY)
Issuer = x
PRIVATE_KEY = pk
print(cert,"\n\n Private Key :",pk,"\n"*2)
#print(cert,"\n\n Private Key :",pk,"\n"*2)
chain.append(cert)
return chain,pk

Expand Down
17 changes: 9 additions & 8 deletions AATC_DB.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def SetAccountType(self,UserID,Permission,Value):
options = ["ZoneCreatorPermission","ZoneRemoverPermission","ZoneModifierPermission"]
if Permission not in options:
return False,"This setting does not exist. Options are :"+str(options)
self.cur.execute("UPDATE User SET "+Permission+" =%s WHERE UserID = %s and PermissionAdder > 2",(Value,UserID)) #The string concatation is safe as only strings which are found exactly in options can be inserted and so are safe strings, cannot contain any other commands
self.cur.execute("UPDATE User SET "+Permission+" =%s WHERE UserID = %s AND PermissionAdder > 2",(Value,UserID)) #The string concatation is safe as only strings which are found exactly in options can be inserted and so are safe strings, cannot contain any other commands
self.db_con.commit()
return True,"Set AccountType Value"

Expand Down Expand Up @@ -352,6 +352,7 @@ def AddMonitorPermission(self,UserID,MonitorID,ExpiryDate):

def RemoveMonitorPermission(self,UserID,MonitorID):
self.cur.execute("DELETE FROM MonitorPermission WHERE UserID = %s AND MonitorID = %s",(UserID,MonitorID))
self.db_con.commit()
return True,"Deleted MonitorPermission"

def ModifyMonitorPermissionDate(self,UserID,MonitorID,NewDate):
Expand Down Expand Up @@ -425,7 +426,7 @@ def GetNoFlyZones(self):
###########################################################################
################## InputStack #################################

def addValue(self,value,chat_id):
def Bot_addValue(self,value,chat_id):
self.cur.execute("SELECT MAX(stack_pos) FROM InputStack WHERE chat_id = %s",(chat_id,))
result = self.cur.fetchall()
if not result[0][0] == None:
Expand All @@ -435,37 +436,37 @@ def addValue(self,value,chat_id):
self.cur.execute("INSERT INTO InputStack VALUES(%s,%s,%s)",(chat_id,stack_pos,value))
self.db_con.commit()

def getCommand(self,chat_id):
def Bot_getCommand(self,chat_id):
self.cur.execute("SELECT value FROM InputStack WHERE chat_id = %s AND stack_pos = 0",(chat_id,))
result = self.cur.fetchall()
return result[0][0]

def getStack(self,chat_id):
def Bot_getStack(self,chat_id):
self.cur.execute("SELECT value FROM InputStack WHERE chat_id = %s ORDER BY stack_pos ASC",(chat_id,))
result = self.cur.fetchall()
return result

def getStackSize(self,chat_id):
def Bot_getStackSize(self,chat_id):
self.cur.execute("SELECT COUNT(1) FROM InputStack WHERE chat_id = %s",(chat_id,))
result = self.cur.fetchall()
return result[0][0]

def flushStack(self,chat_id):
def Bot_flushStack(self,chat_id):
self.cur.execute("DELETE FROM InputStack WHERE chat_id = %s",(chat_id,))
self.db_con.commit()

##################################################################
####################### Sessions ##########################

def SetUserID(self,chat_id,UserID):
def Bot_SetUserID(self,chat_id,UserID):
self.cur.execute("SELECT 1 FROM Sessions WHERE chat_id = %s",(chat_id,))
if len(self.cur.fetchall()) == 0:
self.cur.execute("INSERT INTO Sessions VALUES(%s,%s)",(chat_id,UserID))
else:
self.cur.execute("UPDATE Sessions SET UserID = %s WHERE chat_id = %s",(UserID,chat_id))
self.db_con.commit()

def GetUserID(self,chat_id):
def Bot_GetUserID(self,chat_id):
self.cur.execute("SELECT UserID FROM Sessions WHERE chat_id = %s",(chat_id,))
result = self.cur.fetchall()
if len(result) == 0:
Expand Down
3 changes: 2 additions & 1 deletion AATC_Server_002.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def Connection_Loop(self):


self.DB.Exit()
self.con.close()
print("Process is exiting")

def Send(self,data):
Expand Down Expand Up @@ -503,7 +504,7 @@ def Send(self,data):
def Login(self,Arguments):
Username,Password = Arguments[0],Arguments[1]
Sucess,Message,UserID = self.DB.CheckCredentials(Username,Password)
self.DB.SetUserID(self.chat_id,UserID)
self.DB.Bot_SetUserID(self.chat_id,UserID)
return Sucess,Message,[]


Expand Down
2 changes: 1 addition & 1 deletion AATC_Server_Starter.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def StartProcesses(Control_Queue):
Control_Queue.put(("Controller","Create_Process",("Grapher",AATC_NoFlyZoneGrapher.NoFlyZoneGrapher)))
Control_Queue.put(("Controller","Create_Process",("Cleaner",AATC_Server.Cleaner)))

Control_Queue.put(("Controller","Create_Process",("Hedabot",HedaBot.TelebotLaunch,(HedaBot.telepot.Bot(HedaBot.BOT_TOKEN),))))
Control_Queue.put(("Controller","Create_Process",("Hedabot",HedaBot.TelebotLaunch,())))
print("[StartProcesses] All processes started")


Expand Down
27 changes: 17 additions & 10 deletions HedaBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(self,Thread_Name,Input_Queue,signature = "\nHeda ∞",start_update_
self.chat_id = 0

self.ticker = Ticker(3) # Used to limit the frequency at which messages are sent
self.Restart_Ticker = Ticker(1/60)
self.Update_Queue = []
self.DB = AATC_DB.DBConnection()
self.OutputQueue = multiprocessing.Queue()
Expand Down Expand Up @@ -109,7 +110,13 @@ def mainLoop(self):
time.sleep(0.5)
except Exception as e:
print("Error in Telebot",self.Thread_Name,"Error:",e)
self.bot = telepot.Bot(BOT_TOKEN)
self.Restart_Ticker.wait_ok()
try:
self.bot = telepot.Bot(BOT_TOKEN)
except Exception as e:
print("Error in Telebot",self.Thread_Name,"Error connecting to telegram servers. Check your internet connection and API Token. Connection may be blocked by administrator.")


if not self.Input_Queue.empty():
data = self.Input_Queue.get()
command,arguments = data[0],data[1]
Expand Down Expand Up @@ -192,27 +199,27 @@ def processInput(self,messageText,chat_id):
try:
if "/" in messageText:
if "/cancel" == messageText:
self.DB.flushStack(chat_id)
self.DB.Bot_flushStack(chat_id)
return "Command cancelled"
elif "/quote" == messageText:
return self.GetQuote()
else:
self.DB.flushStack(chat_id)
self.DB.Bot_flushStack(chat_id)
messageText = messageText.replace("/","")
elif lowerText in ["help","?"]:
return self.ShowCommandsList


self.DB.addValue(messageText,chat_id)
self.DB.Bot_addValue(messageText,chat_id)

stack_size = self.DB.getStackSize(chat_id)
command = self.DB.getCommand(chat_id)
stack_size = self.DB.Bot_getStackSize(chat_id)
command = self.DB.Bot_getCommand(chat_id)
command_size = len(self.CommandDictionary[command])

if stack_size == command_size+1:
UserID = self.DB.GetUserID(chat_id)
stack = self.DB.getStack(chat_id)
self.DB.flushStack(chat_id)
UserID = self.DB.Bot_GetUserID(chat_id)
stack = self.DB.Bot_getStack(chat_id)
self.DB.Bot_flushStack(chat_id)

packet = convertDBStack(stack,self.CommandDictionary)

Expand Down Expand Up @@ -483,7 +490,7 @@ def CreateCommandDictionary():



BOT_TOKEN = "YOUR TOKEN HERE"
BOT_TOKEN = "472230564:AAEHTSJ446LE_BO_hQ8B4PeVmUTrB8gRsEA"
if __name__ == "__main__":
bot = telepot.Bot(BOT_TOKEN)
heda = Telebot()
Expand Down

0 comments on commit e81a308

Please sign in to comment.