2006-08-02 13:59:57 +01:00
|
|
|
#!/usr/bin/python
|
2007-06-11 13:09:24 +01:00
|
|
|
"""
|
|
|
|
Scyther : An automatic verifier for security protocols.
|
|
|
|
Copyright (C) 2007 Cas Cremers
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
"""
|
|
|
|
|
2006-08-02 13:59:57 +01:00
|
|
|
|
|
|
|
"""
|
|
|
|
Preferences window and logic for saving and loading such things.
|
|
|
|
Thus, some default things can be set here.
|
|
|
|
|
|
|
|
init loads stuff
|
|
|
|
save save the settings after some changes
|
|
|
|
set(k,v)
|
|
|
|
get(k)
|
|
|
|
|
|
|
|
Currently used:
|
|
|
|
|
|
|
|
match
|
|
|
|
maxruns
|
|
|
|
scytheroptions
|
2006-08-09 10:26:15 +01:00
|
|
|
bindir where the scyther executables reside
|
|
|
|
splashscreen 0/1
|
2006-08-02 13:59:57 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
""" Import externals """
|
|
|
|
|
|
|
|
import wx
|
|
|
|
import os.path
|
2006-08-02 23:44:10 +01:00
|
|
|
import sys
|
2006-08-02 13:59:57 +01:00
|
|
|
from time import localtime,strftime
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
""" Import scyther-gui components """
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
""" Globals """
|
2006-08-10 12:50:57 +01:00
|
|
|
# Do we have the Python Imaging library?
|
|
|
|
havePIL = True
|
BUGFIX: PIL no longer works on my Feisty machines: PIL disabled.
Currently, both my Feisty Ubuntu's have stopped working with the GUI of
Scyther. So to be on the safe side, PIL is disabled for now, until I've
resolved the problem.
The error is the following:
---------------------------------------------------------------------------
Traceback (most recent call last):
File "/home/cas/src/scyther-dev/gui/Gui/Scytherthread.py", line 351, in onViewButton
w = Attackwindow.AttackWindow(btn.claim)
File "/home/cas/src/scyther-dev/gui/Gui/Attackwindow.py", line 176, in __init__
self.CreateInteriorWindowComponents()
File "/home/cas/src/scyther-dev/gui/Gui/Attackwindow.py", line 209, in CreateInteriorWindowComponents
dp = AttackDisplay(self, self, attacks[0])
File "/home/cas/src/scyther-dev/gui/Gui/Attackwindow.py", line 73, in __init__
self.original = Image.open(filename)
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 1912, in open
return factory(fp, filename)
File "/usr/lib/python2.5/site-packages/PIL/ImageFile.py", line 82, in __init__
self._open()
File "/usr/lib/python2.5/site-packages/PIL/EpsImagePlugin.py", line 277, in _open
raise IOError, "cannot determine EPS bounding box"
IOError: cannot determine EPS bounding box
---------------------------------------------------------------------------
Great. Bounding boxes in eps again.
2007-11-13 19:49:09 +00:00
|
|
|
havePIL = False # For now, override (bounding box bug on Feisty?)
|
2006-08-10 12:50:57 +01:00
|
|
|
try:
|
|
|
|
import Image
|
|
|
|
except ImportError:
|
|
|
|
havePIL = False
|
2006-08-02 13:59:57 +01:00
|
|
|
|
|
|
|
""" Locations of preferences. The last one is supposedly writable. """
|
|
|
|
prefname = "scythergui-config"
|
2006-08-02 23:44:10 +01:00
|
|
|
preflocs = []
|
2006-08-02 13:59:57 +01:00
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2006-08-10 12:50:57 +01:00
|
|
|
def usePIL():
|
|
|
|
"""
|
|
|
|
Determine whether or not we should use the PIL library
|
|
|
|
"""
|
|
|
|
global havePIL
|
|
|
|
|
|
|
|
# Only if we have it, and it is windows.
|
|
|
|
if havePIL:
|
|
|
|
if sys.platform.startswith("lin"):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
|
2006-08-02 13:59:57 +01:00
|
|
|
class Preferences(dict):
|
|
|
|
|
|
|
|
def parse(self,line):
|
|
|
|
line = line.strip()
|
|
|
|
|
|
|
|
""" Skip comments """
|
|
|
|
if not line.startswith("#"):
|
|
|
|
split = line.find("=")
|
|
|
|
if split != -1:
|
|
|
|
key = line[:split].strip()
|
|
|
|
data = line[(split+1):]
|
|
|
|
self[key] = data.decode("string_escape")
|
2006-08-08 16:00:20 +01:00
|
|
|
#print "Read %s=%s" % (key,self[key])
|
2006-08-02 13:59:57 +01:00
|
|
|
|
|
|
|
def load(self,file=""):
|
|
|
|
if file == None:
|
|
|
|
self["test1"] = "Dit is met een ' en een \", en dan\nde eerste dinges"
|
|
|
|
self["test2"] = "En dit de tweede"
|
|
|
|
elif file == "":
|
|
|
|
"""
|
|
|
|
Test default locations
|
|
|
|
"""
|
|
|
|
for f in preflocs:
|
2006-08-02 23:44:10 +01:00
|
|
|
self.load(os.path.join(f,prefname))
|
2006-08-02 13:59:57 +01:00
|
|
|
|
|
|
|
else:
|
|
|
|
"""
|
|
|
|
Read this file
|
|
|
|
"""
|
|
|
|
if os.path.isfile(file):
|
|
|
|
fp = open(file,"r")
|
|
|
|
for l in fp.readlines():
|
|
|
|
self.parse(l)
|
|
|
|
fp.close()
|
|
|
|
|
|
|
|
def show(self):
|
|
|
|
print "Preferences:"
|
|
|
|
for k in self.keys():
|
|
|
|
print "%s=%s" % (k, self[k])
|
|
|
|
|
|
|
|
def save(self):
|
|
|
|
|
|
|
|
print "Saving preferences"
|
2006-08-02 23:44:10 +01:00
|
|
|
prefpath = preflocs[-1]
|
2006-08-02 13:59:57 +01:00
|
|
|
if not os.access(prefpath,os.W_OK):
|
|
|
|
os.makedirs(prefpath)
|
|
|
|
savename = os.path.join(prefpath,prefname)
|
|
|
|
fp = open(savename,"w")
|
|
|
|
|
|
|
|
fp.write("# Scyther-gui configuration file.\n#\n")
|
|
|
|
date = strftime("%c",localtime())
|
|
|
|
fp.write("# Last written on %s\n" % (date))
|
|
|
|
fp.write("# Do not edit - any changes will be overwritten by Scyther-gui\n\n")
|
|
|
|
|
|
|
|
l = list(self.keys())
|
|
|
|
l.sort()
|
|
|
|
for k in l:
|
|
|
|
fp.write("%s=%s\n" % (k, self[k].encode("string_escape")))
|
|
|
|
|
|
|
|
fp.close()
|
|
|
|
|
|
|
|
def init():
|
|
|
|
"""
|
|
|
|
Load the preferences from a file, if possible
|
|
|
|
"""
|
2006-08-02 23:44:10 +01:00
|
|
|
global prefs,preflocs
|
|
|
|
|
|
|
|
sp = wx.StandardPaths.Get()
|
|
|
|
confdir = sp.GetConfigDir()
|
|
|
|
confdir += "/scyther"
|
2006-08-08 16:00:20 +01:00
|
|
|
#print confdir
|
2006-08-02 23:44:10 +01:00
|
|
|
userconfdir = sp.GetUserConfigDir()
|
|
|
|
userconfdir += "/"
|
|
|
|
if sys.platform.startswith("lin"):
|
|
|
|
userconfdir += "."
|
|
|
|
userconfdir += "scyther"
|
2006-08-08 16:00:20 +01:00
|
|
|
#print userconfdir
|
2006-08-02 23:44:10 +01:00
|
|
|
|
|
|
|
preflocs = [confdir,userconfdir]
|
2006-08-02 13:59:57 +01:00
|
|
|
|
|
|
|
prefs = Preferences()
|
|
|
|
prefs.load("")
|
|
|
|
|
|
|
|
|
|
|
|
def get(key,alt=None):
|
|
|
|
global prefs
|
|
|
|
|
|
|
|
if prefs.has_key(key):
|
|
|
|
return prefs[key]
|
|
|
|
else:
|
|
|
|
return alt
|
|
|
|
|
|
|
|
def set(key,value):
|
|
|
|
global prefs
|
|
|
|
|
|
|
|
prefs[key]=value
|
|
|
|
return
|
|
|
|
|
|
|
|
def save():
|
|
|
|
global prefs
|
|
|
|
|
|
|
|
prefs.save()
|
|
|
|
|
|
|
|
|