[Prelude-Notify] Patches / Improvements

Alexandre DE DOMMELIN <[email protected]> Tue, 09 Feb 2010 22:06:16 +0000
Newsgroups gmane.comp.security.ids.prelude.devel
Message-ID <[email protected]>
Hello,

While packaging prelude-notify I've noticed some points that could be
improved, you'll find the patches included in this email.

First of all, the config was only relying on ~/.prelude-notifyrc, the
following patches provide a /etc/prelude-notify/prelude-notify.conf, while
keeping the ability to specify custom paramters which will be then stored
in ~/.prelude-notify/prelude-notifyrc.

I've also improved the themes management, you're now able to fully theme
prelude-notify (notifications + systray) by creating a new folder in
~/.prelude-notify/themes/ or in /usr/share/prelude-notify/themes if you
have the needed permissions with the following structure and then just
restart the application : 

[mytheme]
|_ high.png
|_ medium.png
|_ low.png
|_ info.png
|_ [tray]
   |_ notify-ok.png
   |_ notify-bad.png


Hope these patches will be ok for you,

Bests,

Alexandre De Dommelin


PS : After discussion with Sebastien Tricaud (the original maintainer), as
he doesn't have anymore time left to maintain this program he offered me to
take the maintainance of it, that's why the maintainer variable in the
setup.py was also modified.


$ diff -u /home/laotseu/tmp/prelude-notify-0.9/PreludeNotify/pnconfig.py
./PreludeNotify/pnconfig.py
--- /home/laotseu/tmp/prelude-notify-0.9/PreludeNotify/pnconfig.py     
2010-02-08 11:16:36.000000000 +0100
+++ ./PreludeNotify/pnconfig.py       2010-02-09 22:04:02.000000000 +0100
@@ -1,5 +1,6 @@
 # Copyright (C) 2008 PreludeIDS Technologies. All Rights Reserved.
 # Author: Sebastien Tricaud <[email protected]>
+#         Alexandre De Dommelin <[email protected]>
 #
 # This file is part of the Prewikka program.
 #
@@ -24,34 +25,41 @@
 from PreludeNotify import siteconfig
 from ConfigParser import SafeConfigParser
 
-iconok = siteconfig.prefix + "/share/prelude-notify/tray/notify-ok.png"
-iconbad = siteconfig.prefix + "/share/prelude-notify/tray/notify-bad.png"
-themespath = siteconfig.prefix + "/share/prelude-notify/themes/"
+userconfigpath = "%s/.prelude-notify/" % (os.getenv("HOME"))
+globalthemespath = siteconfig.prefix + "/share/prelude-notify/themes/"
+userthemespath = userconfigpath + "/themes/"
 
 class PnConfig(SafeConfigParser):
-        _configname = "%s/.prelude-notifyrc" % (os.getenv("HOME"))
-
+        _globalconfigfile = "/etc/prelude-notify/prelude-notify.conf"
+        _userconfigfile = userconfigpath + "prelude-notifyrc"
+       
         def __init__(self, env):
                 SafeConfigParser.__init__(self)
                 self._updated = {}
                 self.env = env
 
-                if os.path.exists(self._configname):
-                        self.read(self._configname)
+                if os.path.exists(self._userconfigfile):
+                        self.read(self._userconfigfile)
                 else:
-                        for section in "general", "idmef", "manager",
"prewikka", "ui":
-                                self.add_section(section)
+                        self.read(self._globalconfigfile)
+
+               _configtheme = SafeConfigParser.get(self,"ui","theme")
 
-                        SafeConfigParser.set(self, "general",
"threshold_timeout", "5")
-                        SafeConfigParser.set(self, "general",
"x11_idle_timeout", "5")
-                        SafeConfigParser.set(self, "idmef", "profile",
"prelude-notify")
-                        SafeConfigParser.set(self, "idmef", "filter", "")
-                        SafeConfigParser.set(self, "manager",
"addresses", "127.0.0.1")
-                        SafeConfigParser.set(self, "prewikka", "url",
"http://localhost:8000")
-                        SafeConfigParser.set(self, "ui", "theme",
"default")
-                        SafeConfigParser.set(self, "ui", "browser",
"auto")
+               if os.path.isdir( userthemespath + _configtheme ):
+                       self.theme = userthemespath + _configtheme
+               elif os.path.isdir( globalthemespath + _configtheme ):
+                       self.theme = globalthemespath + _configtheme
+               else:
+                       self.theme = globalthemespath + "default"
+
+       def getIconOk(self):
+               return self.theme + "/tray/notify-ok.png"
+       
+       def getIconBad(self):
+               return self.theme + "/tray/notify-bad.png"
 
-                        self.write(open(self._configname, "w"))
+       def getThemePath(self):
+               return self.theme
 
         def set(self, section, key, value):
                 old = SafeConfigParser.get(self, section, key)
@@ -89,5 +97,7 @@
                 except:
                         self._updated = {}
                         return
-
-                self.write(open(self._configname, "w"))
+                if not os.path.isdir( userconfigpath ):
+                       os.mkdir( userconfigpath )
+                       
+                self.write(open(self._userconfigfile, "w"))


---------------------------------------


$ diff -u
/home/laotseu/tmp/prelude-notify-0.9/PreludeNotify/pnstatusicon.py
./PreludeNotify/pnstatusicon.py 
--- /home/laotseu/tmp/prelude-notify-0.9/PreludeNotify/pnstatusicon.py 
2010-02-08 11:16:36.000000000 +0100
+++ ./PreludeNotify/pnstatusicon.py   2010-02-09 22:04:02.000000000 +0100
@@ -1,5 +1,6 @@
 # Copyright (C) 2008 PreludeIDS Technologies. All Rights Reserved.
 # Author: Sebastien Tricaud <[email protected]>
+#         Alexandre De Dommelin <[email protected]> 
 #
 # This file is part of the Prelude-Notify program.
 #
@@ -26,16 +27,16 @@
 class PreludeStatusIcon:
 
         def __init__(self, gloop, config):
-                self.icon =
gtk.status_icon_new_from_file(pnconfig.iconok)
-                self.icon.connect('popup-menu', self.menu)
                 self.config = config
                 self.gloop = gloop
+                self.icon =
gtk.status_icon_new_from_file(self.config.getIconOk())
+               self.icon.connect('popup-menu', self.menu)
 
         def MissedAlerts(self):
-                self.icon.set_from_file(pnconfig.iconbad)
+                self.icon.set_from_file(self.config.getIconBad())
 
         def SeenAlerts(self):
-                self.icon.set_from_file(pnconfig.iconok)
+                self.icon.set_from_file(self.config.getIconOk())
 
         def menu(self, icon, event_button, event_time):
                 m = gtk.Menu()
@@ -143,7 +144,7 @@
                 except AttributeError:
                         print "Cannot add the dialog program name"
                 try:
-                        dialog.set_copyright("Sebastien Tricaud (c)
2008")
+                        dialog.set_copyright("Sebastien Tricaud,
Alexandre De Dommelin (c) 2010")
                 except AttributeError:
                         print "Cannot add the dialog copyright"
                 try:


---------------------------------------


$ diff -u
/home/laotseu/tmp/prelude-notify-0.9/PreludeNotify/notifyaction.py
./PreludeNotify/notifyaction.py 
--- /home/laotseu/tmp/prelude-notify-0.9/PreludeNotify/notifyaction.py 
2010-02-08 11:16:36.000000000 +0100
+++ ./PreludeNotify/notifyaction.py   2010-02-09 22:04:02.000000000 +0100
@@ -61,7 +61,7 @@
         def _severity_map(self, severity):
                 urgency = None
                 imageuri = None
-                baseuri = "file://" + pnconfig.themespath +
self._env.config.get("ui", "theme") + "/"
+                baseuri = "file://" + self._env.config.getThemePath() +
"/"
 
                 for i in (("high", pynotify.URGENCY_CRITICAL),
                           ("medium", pynotify.URGENCY_NORMAL),



---------------------------------------


$ diff -u /home/laotseu/tmp/prelude-notify-0.9/setup.py ./setup.py        
--- /home/laotseu/tmp/prelude-notify-0.9/setup.py       2010-02-08
11:16:36.000000000 +0100
+++ ./setup.py  2010-02-09 22:21:22.000000000 +0100
@@ -4,7 +4,7 @@
 from distutils.core import setup
 from distutils.command.install import install
 
-_VERSION="0.9.0-svn"
+_VERSION="0.9.1"
 
 class my_install(install):
    def init_siteconfig(self):
@@ -22,12 +22,13 @@
 
 setup(name="prelude-notify",
       version=_VERSION,
-      maintainer = "Sebastien Tricaud",
-      maintainer_email = "[email protected]",
+      maintainer = "Alexandre De Dommelin",
+      maintainer_email = "[email protected]",
       url = "http://www.prelude-ids.com",
       packages=[ 'PreludeNotify' ],
       data_files=[ ("share/prelude-notify/themes/default",
glob.glob("pixmaps/themes/default/*")),
-                   ("share/prelude-notify/tray",
glob.glob("pixmaps/tray/*")),
-                   ("share/applications", ["prelude-notify.desktop"]) ],
+                   ("share/prelude-notify/themes/default/tray",
glob.glob("pixmaps/themes/tray/*")),
+                   ("share/applications", ["prelude-notify.desktop"]),
+                   ("/etc/prelude-notify", ["prelude-notify.conf"]) ],
       scripts=[ "prelude-notify" ],
       cmdclass={ 'install': my_install } )




---------------------------------------


$ cat ./prelude-notify.conf 
[idmef]
profile = prelude-notify
filter =

[manager]
addresses = manager.host.tld

[ui]
theme = default
browser = auto

[prewikka]
url = https://manager.host.tld

[general]
threshold_timeout = 5
x11_idle_timeout = 60

_______________________________________________
Prelude-devel site list
[email protected]
http://lists.prelude-technologies.com/mailman/listinfo/prelude-devel