Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -1752,4 +1752,7 @@
/static_build/node_modules/
/static_build/.sass-cache/
/static_build/.bundle/
/static_build/nbproject/private/
/static_build/nbproject/private/
/static_build/nbproject/project.xml
/dist/containmentUnit-1.0.10.zip
/static_build/nbproject/project.properties
1 change: 1 addition & 0 deletions containmentUnit/controllers/casperjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def exeScript(self):
stdout_value, stderr_value = myProc.communicate()
self.scriptOutput = repr(stdout_value)
self.scriptErrors = stderr_value
return self.getScriptOutput(self.scriptOutputFile)
except:
print "\n\t Error: second attempt failed, program will quit."
self.stopProxy()
Expand Down
175 changes: 123 additions & 52 deletions containmentUnit/controllers/wraith.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from pylons.controllers.util import redirect
from pylons.decorators.rest import restrict
from browsermobproxy import Server
from time import strftime
from containmentUnit.lib.base import BaseController, render
import containmentUnit.lib.proxyPortManager as portManager

#print "app root is: " + APP_ROOT;
#This opens a pipe to the standard cmd shell and sets input and output
Expand All @@ -30,6 +32,7 @@ def __before__(self):


def _updateRequestData(self,requirePaths):
portManager.lock.acquire()
self.reqParams = json.loads(request.body)

if self.reqParams['siteName'] != None:
Expand All @@ -46,13 +49,15 @@ def _updateRequestData(self,requirePaths):

if self.reqParams['protocol'] != "https":
self.protocol = "http"
portManager.lock.release()


@restrict("POST")
def generateSiteYaml(self):

self._updateRequestData(True)

portManager.lock.acquire()
if self._addSiteToExisting() == False:
return self.scriptOutput

Expand Down Expand Up @@ -108,6 +113,8 @@ def generateSiteYaml(self):
self._writeOutput(yamlCache,self.siteName+'_History.yaml')
print "Yaml file successfully created :)"

portManager.lock.release()

if self.updatingRecord == False :
return self.generateBaseTestImages()
else:
Expand All @@ -117,6 +124,7 @@ def generateSiteYaml(self):

def updateSitePaths(self):

portManager.lock.acquire()
self.reqParams = json.loads(request.body)
self.siteName = self.reqParams['siteName']
selfSiteName = self.siteName
Expand Down Expand Up @@ -160,12 +168,14 @@ def updateSitePaths(self):
if y < (len(newPathArray) - 1):
self._appendOutput(',', filePath)
self._appendOutput(']}', filePath)

portManager.lock.release()
return self.generateSiteYaml()
else:
#Should only occur in error. You can't select an existing path if the file is empty
self.scriptOutput += "File is empty, path not found."
portManager.lock.release()
return self.generateSiteYaml()
portManager.lock.release()
return self.scriptOutput

else:
Expand Down Expand Up @@ -206,7 +216,7 @@ def updateSitePaths(self):
if y < (len(newPathArray) - 1):
self._appendOutput(',', filePath)
self._appendOutput(']}', filePath)

portManager.lock.release()
return self.generateSiteYaml()
else:
#Adds Paths to file that is empty
Expand All @@ -219,7 +229,9 @@ def updateSitePaths(self):
self._appendOutput(']}', filePath)

self.scriptOutput += "Path : " + selfPathName + " added successfully</br>"
portManager.lock.release()
return self.generateSiteYaml()
portManager.lock.release()
return self.scriptOutput


Expand Down Expand Up @@ -289,26 +301,35 @@ def getLatestTestImages(self):
@restrict("PUT")
def removeExistingSite(self):
#Delete log files
portManager.lock.acquire()
self.siteName = request.params['siteName']
if os.path.isfile(self.scriptDirectory+'logs/' + self.siteName +'_GetLatestImageOutput.log'):
os.remove(self.scriptDirectory+'logs/' + self.siteName +'_GetLatestImageOutput.log')
if os.path.isfile(self.scriptDirectory+'logs/' + self.siteName +'_GenBaseImageOutput.log'):
os.remove(self.scriptDirectory+'logs/' + self.siteName +'_GenBaseImageOutput.log')

latestLog = self.scriptDirectory+'logs/' + self.siteName +'_GetLatestImageOutput.log'
baseLog = self.scriptDirectory+'logs/' + self.siteName +'_GenBaseImageOutput.log'
baseDirectory = self.scriptDirectory + "screenCaptures/" + self.siteName + "_base_shots"
latestDirectory = self.scriptDirectory + "screenCaptures/" + self.siteName + "_latest_shots"
pathsFile = self.scriptDirectory+'pathData/' + self.siteName +'_paths.json'
historyFile = self.scriptDirectory + self.siteName +'_History.yaml'

if os.path.isfile(latestLog):
os.remove(latestLog)
if os.path.isfile(baseLog):
os.remove(baseLog)

#Delete Images and Folders
if os.path.exists(self.scriptDirectory + "screenCaptures/" + self.siteName + "_base_shots"):
shutil.rmtree(self.scriptDirectory + "screenCaptures/" + self.siteName + "_base_shots")
if os.path.exists(baseDirectory):
shutil.rmtree(baseDirectory)

if os.path.exists(self.scriptDirectory + "screenCaptures/" + self.siteName + "_latest_shots"):
shutil.rmtree(self.scriptDirectory + "screenCaptures/" + self.siteName + "_latest_shots")
if os.path.exists(latestDirectory):
shutil.rmtree(latestDirectory)

#Delete Path Files
if os.path.isfile(self.scriptDirectory+'pathData/' + self.siteName +'_paths.json'):
os.remove(self.scriptDirectory+'pathData/' + self.siteName +'_paths.json')
if os.path.isfile(pathsFile):
os.remove(pathsFile)

#Delete yaml
if os.path.isfile(self.scriptDirectory + self.siteName +'_History.yaml'):
os.remove(self.scriptDirectory + self.siteName +'_History.yaml')
if os.path.isfile(historyFile):
os.remove(historyFile)

#remove site from existingSites.config
f = open(self.scriptDirectory + "existingSites.config","r+")
Expand All @@ -326,30 +347,37 @@ def removeExistingSite(self):
f = open(self.scriptDirectory + "wraithGalleryIndex.html","r+")
d = f.readlines()
f.seek(0)

search = '<span class="wcSite"><label>Site : </label>'+self.siteName+'</span>'
for i in d:
if i != '<div><a href="wraith/loadWraithGallery?siteName=' + self.siteName +'" target="_blank">' + self.siteName + '\'s gallery</a></div>\n':
if not re.search(search,i):
f.write(i)

f.truncate()
f.close()
portManager.lock.release()
return "Site : " + self.siteName + " has been removed from the system."


def _writeOutput(self,data,filename):
portManager.lock.acquire()
fileStream = open(self.scriptDirectory+filename,'w')
fileStream.write(data)
fileStream.close()
portManager.lock.release()

def _appendOutput(self,data,filename):
portManager.lock.acquire()
fileStream = open(self.scriptDirectory+filename,'a')
fileStream.write(data)
fileStream.close()
portManager.lock.release()

def _getScriptOutput(self,filename):

fileStream = open(self.scriptDirectory+filename,'r')
output = fileStream.read()
fileStream.close();

return output

@restrict("GET")
Expand All @@ -367,6 +395,7 @@ def loadWraithGallery(self):
@restrict("GET")
def getExistingSites(self):
# Read existing site entries from log
portManager.lock.acquire()
fileStream = open(self.scriptDirectory+"existingSites.config",'r')
temp = fileStream.read().splitlines()
newtemp = ''
Expand All @@ -378,6 +407,7 @@ def getExistingSites(self):
newtemp += '{"siteName": "' +entry +'"}'
count += 1
temp = '{"sites":['+str(newtemp)+']}'
portManager.lock.release()
return json.dumps(temp)

@restrict("GET")
Expand All @@ -389,64 +419,105 @@ def getExistingSitePaths(self):
def _addSiteToExisting(self):
print "Adding site to existingSites.config "
fileStream = self._getScriptOutput('existingSites.config')


portManager.lock.acquire()
foundSite = False
if fileStream != None:

with open(self.scriptDirectory+'existingSites.config') as f:
print("stream is open")

for line in f:
if re.search(self.siteName+'\n',line):
if self.siteName+'\n'==line:
foundSite = True
break


if self.updatingRecord :
print("Existing Record is being updated.")
return True
else:
print("The Site Already Exists.")
self.scriptOutput += self.siteName + " already exists, please remove or update paths to edit."
return False
if foundSite:
if self.updatingRecord :
print("Existing Record is being updated.")
portManager.lock.release()
return True
else:
print("The Site Already Exists.")
self.scriptOutput += self.siteName + " already exists, please remove or update paths to edit."
portManager.lock.release()
return False

else:
print("attempting to write output")
self._appendOutput(self.siteName+'\n','existingSites.config')
#preserve our paths to file so we can reference them from the web interface.
self._writeOutput(self.rawPathData,"pathData/"+self.siteName+'_paths.json')
self.scriptOutput += "Site : " + self.siteName + " added Successfully"
return True
else:
print("attempting to write output")
self._appendOutput(self.siteName+'\n','existingSites.config')
#preserve our paths to file so we can reference them from the web interface.
self._writeOutput(self.rawPathData,"pathData/"+self.siteName+'_paths.json')
self.scriptOutput += "Site : " + self.siteName + " added Successfully"
portManager.lock.release()
return True
else:
self._writeOutput(self.siteName+'\n','existingSites.config')
#preserve our paths to file so we can reference them from the web interface.
self._writeOutput(self.rawPathData,"pathData/"+self.siteName+'_paths.json')
self.scriptOutput += "Site : " + self.siteName + " added Successfully"
portManager.lock.release()
return True

portManager.lock.release()
return False

def _addSiteToGalleryIndex(self):
print "Adding site to wraithGalleryIndex.html "
link = '<div><a href="wraith/loadWraithGallery?siteName=' + self.siteName +'" target="_blank">' + self.siteName + '\'s gallery</a></div>\n'
print "# Adding site to wraithGalleryIndex.html #"

timeStamp = strftime("%A %m/%d/%y @ %I:%M:%S %p")

myFile = self.scriptDirectory+'wraithGalleryIndex.html'
link = '<a href="wraith/loadWraithGallery?siteName=' + self.siteName +'" target="_blank"><div class="wraithGalCard"><span class="wraithLogo"></span><span class="wcSite"><label>Site : </label>' + self.siteName + '</span><span class="wcLastUpdate">'+ timeStamp.encode('utf-8') +'</span></div></a>\n'
foundSite = False
portManager.lock.acquire()
if os.path.isfile(self.scriptDirectory+'wraithGalleryIndex.html'):

with open(self.scriptDirectory+'wraithGalleryIndex.html') as f:
print("stream is open")

for line in f:
if link==line:
print("The Gallery Already Exists.")
self.scriptOutput += self.siteName + "'s gallery is already listed."
return

if os.stat(myFile).st_size > 0 :
with open(myFile) as f:
print("# Opened wriathGalleryIndex #")
search = '<span class="wcSite"><label>Site : </label>'+self.siteName+'</span>'
for line in f:

else:
print("Adding site to gallery Index.")
self._appendOutput(link,'wraithGalleryIndex.html')
return
if re.search(search,line):
foundSite = True
if foundSite:
print("The Gallery Already Exists.")
self.scriptOutput += self.siteName + "'s gallery is already listed."
self.__updateGalleryIndex()
portManager.lock.release()
return

else:
print("Adding site to gallery Index.")
self._appendOutput(link,'wraithGalleryIndex.html')
portManager.lock.release()
return
else:
print("Adding site to gallery Index.")
self._writeOutput(link,'wraithGalleryIndex.html')
portManager.lock.release()
return
else:
print("Adding site to gallery Index.")
print("# wriathGalleryIndex is empty adding site to file. #")
self._writeOutput(link,'wraithGalleryIndex.html')
portManager.lock.release()
return


def __updateGalleryIndex(self):
timeStamp = strftime("%A %m/%d/%y @ %I:%M:%S %p")
link = '<a href="wraith/loadWraithGallery?siteName=' + self.siteName +'" target="_blank"><div class="wraithGalCard"><span class="wraithLogo"></span><span class="wcSite"><label>Site : </label>' + self.siteName + '</span><span class="wcLastUpdate">'+ timeStamp.encode('utf-8') +'</span></div></a>\n'
portManager.lock.acquire()
#update gallery index
f = open(self.scriptDirectory + "wraithGalleryIndex.html","r+")
d = f.readlines()
f.seek(0)
search = '<span class="wcSite"><label>Site : </label>'+self.siteName+'</span>'
for i in d:
if re.search(search,i):
f.write(link)

f.truncate()
f.close()
portManager.lock.release()



Expand Down
2 changes: 2 additions & 0 deletions containmentUnit/lib/proxyPortManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def assignProxyPort():
global serverPort
global indexCount

lock.acquire()
print " # Assigning Proxy Port # "

clientPort = serverPort + 1
Expand Down Expand Up @@ -98,6 +99,7 @@ def assignProxyPort():
count += 1

addPortMapEntry(clientPort)
lock.release()

def addPortMapEntry(portNum):
global portMap
Expand Down
2 changes: 1 addition & 1 deletion containmentUnit/public/Wraith/configs/existingSites.config
Original file line number Diff line number Diff line change
@@ -1 +1 @@
secure.bhg.com
example.site.com
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"paths":[{"url": "example/path/data", "label":"example_label"},{"url": "/example/path/data/2", "label":"example_label2"}]}
Empty file.
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
<div><a href="wraith/loadWraithGallery?siteName=secure.bhg.com" target="_blank">secure.bhg.com's gallery</a></div>
Loading