[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a
Naparuba
naparuba at gmail.com
Tue Feb 28 22:13:22 UTC 2012
The following commit has been merged in the debian/master branch:
commit 588f2653e4ebbcd9a1bf7a403ac0a5c1c7d80344
Author: Naparuba <naparuba at gmail.com>
Date: Thu Jan 12 17:10:59 2012 +0100
Add : make the skonfUI run. Lot of duplicate from webui, first we code, then we factorize :)
diff --git a/shinken/daemons/skonfdaemon.py b/shinken/daemons/skonfdaemon.py
index daac622..32f6f2d 100644
--- a/shinken/daemons/skonfdaemon.py
+++ b/shinken/daemons/skonfdaemon.py
@@ -396,6 +396,19 @@ class Skonf(Daemon):
+
+ # We check if the photo directory exists. If not, try to create it
+ def check_photo_dir(self):
+ print "Checking photo path", self.photo_dir
+ if not os.path.exists(self.photo_dir):
+ print "Truing to create photo dir", self.photo_dir
+ try:
+ os.mkdir(self.photo_dir)
+ except Exception, exp:
+ print "Photo dir creation failed", exp
+
+
+
# Main loop function
def main(self):
try:
@@ -543,6 +556,152 @@ class Skonf(Daemon):
if self.conf.human_timestamp_log:
logger.set_human_format()
+ # Ok start to work :)
+ self.check_photo_dir()
+
+ self.request = request
+ self.response = response
+
+ self.load_plugins()
+
+ # Declare the whole app static files AFTER the plugin ones
+ self.declare_common_static()
+
+ print "Starting Skonf application"
+ srv = run(host=self.http_host, port=self.http_port, server=self.http_backend)
+
+
+
+
+ # Here we will load all plugins (pages) under the webui/plugins
+ # directory. Each one can have a page, views and htdocs dir that we must
+ # route correctly
+ def load_plugins(self):
+ from shinken.webui import plugins_skonf as plugins
+ plugin_dir = os.path.abspath(os.path.dirname(plugins.__file__))
+ print "Loading plugin directory : %s" % plugin_dir
+
+ # Load plugin directories
+ plugin_dirs = [ fname for fname in os.listdir(plugin_dir)
+ if os.path.isdir(os.path.join(plugin_dir, fname)) ]
+
+ print "Plugin dirs", plugin_dirs
+ sys.path.append(plugin_dir)
+ # We try to import them, but we keep only the one of
+ # our type
+ for fdir in plugin_dirs:
+ print "Try to load", fdir
+ mod_path = 'shinken.webui.plugins_skonf.%s.%s' % (fdir, fdir)
+ print "MOD PATH", mod_path
+ try:
+ m = __import__(mod_path, fromlist=[mod_path])
+ m_dir = os.path.abspath(os.path.dirname(m.__file__))
+ sys.path.append(m_dir)
+
+ #print "Loaded module m", m
+ print m.__file__
+ pages = m.pages
+ print "Try to load pages", pages
+ for (f, entry) in pages.items():
+ routes = entry.get('routes', None)
+ v = entry.get('view', None)
+ static = entry.get('static', False)
+
+ # IMPORTANT : apply VIEW BEFORE route!
+ if v:
+ #print "Link function", f, "and view", v
+ f = view(v)(f)
+
+ # Maybe there is no route to link, so pass
+ if routes:
+ for r in routes:
+ method = entry.get('method', 'GET')
+ print "link function", f, "and route", r, "method", method
+
+ # Ok, we will just use the lock for all
+ # plugin page, but not for static objects
+ # so we set the lock at the function level.
+ lock_version = self.lockable_function(f)
+ f = route(r, callback=lock_version, method=method)
+
+ # If the plugin declare a static entry, register it
+ # and remeber : really static! because there is no lock
+ # for them!
+ if static:
+ self.add_static(fdir, m_dir)
+
+ # And we add the views dir of this plugin in our TEMPLATE
+ # PATH
+ bottle.TEMPLATE_PATH.append(os.path.join(m_dir, 'views'))
+
+ # And finally register me so the pages can get data and other
+ # useful stuff
+ m.app = self
+
+
+ except Exception, exp:
+ logger.log("Warning in loading plugins : %s" % exp)
+
+
+
+
+
+ def add_static(self, fdir, m_dir):
+ static_route = '/static/'+fdir+'/:path#.+#'
+ #print "Declaring static route", static_route
+ def plugin_static(path):
+ print "Ask %s and give %s" % (path, os.path.join(m_dir, 'htdocs'))
+ return static_file(path, root=os.path.join(m_dir, 'htdocs'))
+ route(static_route, callback=plugin_static)
+
+
+
+
+ # We want a lock manager version of the plugin fucntions
+ def lockable_function(self, f):
+ #print "We create a lock verion of", f
+ def lock_version(**args):
+ #self.wait_for_no_writers()
+ t = time.time()
+ try:
+ return f(**args)
+ finally:
+ print "rendered in", time.time() - t
+ # We can remove us as a reader from now. It's NOT an atomic operation
+ # so we REALLY not need a lock here (yes, I try without and I got
+ # a not so accurate value there....)
+ #self.global_lock.acquire()
+ #self.nb_readers -= 1
+ #self.global_lock.release()
+ #print "The lock version is", lock_version
+ return lock_version
+
+
+ def declare_common_static(self):
+ @route('/static/photos/:path#.+#')
+ def give_photo(path):
+ # If the file really exist, give it. If not, give a dummy image.
+ if os.path.exists(os.path.join(self.photo_dir, path+'.jpg')):
+ return static_file(path+'.jpg', root=self.photo_dir)
+ else:
+ return static_file('images/user.png', root=os.path.join(bottle_dir, 'htdocs'))
+
+ # Route static files css files
+ @route('/static/:path#.+#')
+ def server_static(path):
+ return static_file(path, root=os.path.join(bottle_dir, 'htdocs'))
+
+ # And add the favicon ico too
+ @route('/favicon.ico')
+ def give_favicon():
+ return static_file('favicon.ico', root=os.path.join(bottle_dir, 'htdocs', 'images'))
+
+
+
+
+
+
+ def old_run(self):
suppl_socks = None
# Now create the external commander. It's just here to dispatch
@@ -623,3 +782,16 @@ class Skonf(Daemon):
self.broks.update(broks)
self.external_commands.extend(external_commands)
+
+
+ def get_user_auth(self):
+ # First we look for the user sid
+ # so we bail out if it's a false one
+ user_name = self.request.get_cookie("user", secret=self.auth_secret)
+
+ # If we cannot check the cookie, bailout
+ if not user_name:
+ return None
+
+ #c = self.datamgr.get_contact(user_name)
+ return user_name
diff --git a/contrib/alternative-installation/shinken-install/tools/__init__.py b/shinken/webui/plugins_skonf/__init__.py
similarity index 100%
copy from contrib/alternative-installation/shinken-install/tools/__init__.py
copy to shinken/webui/plugins_skonf/__init__.py
diff --git a/contrib/alternative-installation/shinken-install/tools/__init__.py b/shinken/webui/plugins_skonf/action/__init__.py
similarity index 100%
copy from contrib/alternative-installation/shinken-install/tools/__init__.py
copy to shinken/webui/plugins_skonf/action/__init__.py
diff --git a/shinken/webui/plugins/action/action.py b/shinken/webui/plugins_skonf/action/action.py
similarity index 100%
copy from shinken/webui/plugins/action/action.py
copy to shinken/webui/plugins_skonf/action/action.py
diff --git a/contrib/alternative-installation/shinken-install/tools/__init__.py b/shinken/webui/plugins_skonf/dummy/__init__.py
similarity index 100%
copy from contrib/alternative-installation/shinken-install/tools/__init__.py
copy to shinken/webui/plugins_skonf/dummy/__init__.py
diff --git a/shinken/webui/plugins/dummy/dummy.py b/shinken/webui/plugins_skonf/dummy/dummy.py
similarity index 100%
copy from shinken/webui/plugins/dummy/dummy.py
copy to shinken/webui/plugins_skonf/dummy/dummy.py
diff --git a/shinken/webui/plugins/dummy/views/dummy.tpl b/shinken/webui/plugins_skonf/dummy/views/dummy.tpl
similarity index 100%
copy from shinken/webui/plugins/dummy/views/dummy.tpl
copy to shinken/webui/plugins_skonf/dummy/views/dummy.tpl
diff --git a/contrib/alternative-installation/shinken-install/tools/__init__.py b/shinken/webui/plugins_skonf/login/__init__.py
similarity index 100%
copy from contrib/alternative-installation/shinken-install/tools/__init__.py
copy to shinken/webui/plugins_skonf/login/__init__.py
diff --git a/shinken/webui/plugins/login/htdocs/js/pass_shark.js b/shinken/webui/plugins_skonf/login/htdocs/js/pass_shark.js
similarity index 100%
copy from shinken/webui/plugins/login/htdocs/js/pass_shark.js
copy to shinken/webui/plugins_skonf/login/htdocs/js/pass_shark.js
diff --git a/shinken/webui/plugins/login/login.py b/shinken/webui/plugins_skonf/login/login.py
similarity index 96%
copy from shinken/webui/plugins/login/login.py
copy to shinken/webui/plugins_skonf/login/login.py
index 6c43096..14dd067 100644
--- a/shinken/webui/plugins/login/login.py
+++ b/shinken/webui/plugins_skonf/login/login.py
@@ -34,7 +34,7 @@ def get_page():
def user_login():
user = app.get_user_auth()
if user:
- redirect("/problems")
+ redirect("/main")
err = app.request.GET.get('error', None)
login_text = app.login_text
@@ -70,7 +70,7 @@ def user_auth():
if is_mobile == '1':
redirect("/mobile/main")
else:
- redirect("/problems")
+ redirect("/main")
else:
redirect("/user/login?error=Invalid user or Password")
@@ -81,8 +81,9 @@ def user_auth():
# Should be /dashboad in the future. If not, go login :)
def get_root():
user = app.request.get_cookie("user", secret=app.auth_secret)
+ print "USER IS FOUND", user
if user:
- redirect("/problems")
+ redirect("/main")
elif app.remote_user_variable in app.request.headers and app.remote_user_enable == '1':
user_name = app.request.headers[app.remote_user_variable]
c = app.datamgr.get_contact(user_name)
@@ -92,7 +93,7 @@ def get_root():
redirect("/user/login")
else:
app.response.set_cookie('user', user_name, secret=app.auth_secret, path='/')
- redirect("/problems")
+ redirect("/main")
else:
redirect("/user/login")
diff --git a/shinken/webui/plugins/login/views/auth.tpl b/shinken/webui/plugins_skonf/login/views/auth.tpl
similarity index 100%
copy from shinken/webui/plugins/login/views/auth.tpl
copy to shinken/webui/plugins_skonf/login/views/auth.tpl
diff --git a/shinken/webui/plugins/login/views/login.tpl b/shinken/webui/plugins_skonf/login/views/login.tpl
similarity index 100%
copy from shinken/webui/plugins/login/views/login.tpl
copy to shinken/webui/plugins_skonf/login/views/login.tpl
diff --git a/shinken/webui/plugins/login/views/login_mobile.tpl b/shinken/webui/plugins_skonf/login/views/login_mobile.tpl
similarity index 100%
copy from shinken/webui/plugins/login/views/login_mobile.tpl
copy to shinken/webui/plugins_skonf/login/views/login_mobile.tpl
diff --git a/contrib/alternative-installation/shinken-install/tools/__init__.py b/shinken/webui/plugins_skonf/lookup/__init__.py
similarity index 100%
copy from contrib/alternative-installation/shinken-install/tools/__init__.py
copy to shinken/webui/plugins_skonf/lookup/__init__.py
diff --git a/shinken/webui/plugins/lookup/lookup.py b/shinken/webui/plugins_skonf/lookup/lookup.py
similarity index 100%
copy from shinken/webui/plugins/lookup/lookup.py
copy to shinken/webui/plugins_skonf/lookup/lookup.py
diff --git a/contrib/alternative-installation/shinken-install/tools/__init__.py b/shinken/webui/plugins_skonf/main/__init__.py
similarity index 100%
copy from contrib/alternative-installation/shinken-install/tools/__init__.py
copy to shinken/webui/plugins_skonf/main/__init__.py
diff --git a/shinken/webui/plugins/dummy/dummy.py b/shinken/webui/plugins_skonf/main/main.py
similarity index 85%
copy from shinken/webui/plugins/dummy/dummy.py
copy to shinken/webui/plugins_skonf/main/main.py
index a5d4a3a..41929b5 100644
--- a/shinken/webui/plugins/dummy/dummy.py
+++ b/shinken/webui/plugins_skonf/main/main.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-#Copyright (C) 2009-2011 :
+#Copyright (C) 2009-2012 :
# Gabes Jean, naparuba at gmail.com
# Gerhard Lausser, Gerhard.Lausser at consol.de
# Gregory Starck, g.starck at gmail.com
@@ -29,7 +29,7 @@ app = None
# Our page. If the useer call /dummy/TOTO arg1 will be TOTO.
# if it's /dummy/, it will be 'nothing'
-def get_page(arg1='nothing'):
+def get_page():
# First we look for the user sid
# so we bail out if it's a false one
user = app.get_user_auth()
@@ -38,14 +38,10 @@ def get_page(arg1='nothing'):
redirect("/user/login")
return
- # Here we can call app.datamgr beause when the webui "loaded" us, it
- # populated app with it's own value.
- my_host = app.datamgr.get_host(arg1)
-
# we return values for the template (view). But beware, theses values are the
# only one the tempalte will have, so we must give it an app link and the
# user we are loggued with (it's a contact object in fact)
- return {'app' : app, 'user' : user, 'host' : my_host}
+ return {'app' : app, 'user' : user}
# This is the dict teh webui will try to "load".
@@ -56,5 +52,5 @@ def get_page(arg1='nothing'):
# the dummy/htdocs/ directory. Bewere : it will take the plugin name to match.
# * optional : you can add 'method' : 'POST' so this adress will be only available for
# POST calls. By default it's GET. Look at the lookup module for sample about this.
-pages = {get_page : { 'routes' : ['/dummy/:arg1', '/dummy/'], 'view' : 'dummy', 'static' : True}}
+pages = {get_page : { 'routes' : ['/main/', '/main'], 'view' : 'main', 'static' : True}}
diff --git a/shinken/webui/plugins_skonf/main/views/main.tpl b/shinken/webui/plugins_skonf/main/views/main.tpl
new file mode 100644
index 0000000..2fde6ac
--- /dev/null
+++ b/shinken/webui/plugins_skonf/main/views/main.tpl
@@ -0,0 +1,5 @@
+
+%rebase layout_skonf globals()
+<div> <h1> Rebase Layout </h1> </div>
+
+ {{!'<br>'.join(globals())}}
diff --git a/shinken/webui/views/footer_element.tpl b/shinken/webui/views/footer_element_skonf.tpl
similarity index 100%
copy from shinken/webui/views/footer_element.tpl
copy to shinken/webui/views/footer_element_skonf.tpl
diff --git a/shinken/webui/views/header_element.tpl b/shinken/webui/views/header_element_skonf.tpl
similarity index 96%
copy from shinken/webui/views/header_element.tpl
copy to shinken/webui/views/header_element_skonf.tpl
index d255212..14c7392 100644
--- a/shinken/webui/views/header_element.tpl
+++ b/shinken/webui/views/header_element_skonf.tpl
@@ -6,7 +6,7 @@
<!-- userinfo -->
<ul class="userinfo">
<li class="left"> </li>
- <li>Hello {{user.get_name()}}!</li>
+ <li>Hello {{user}}!</li>
<li>|</li>
<li><a id="toggleUserinfo" href="#">Parameters</a></li>
<li>|</li>
diff --git a/shinken/webui/views/layout.tpl b/shinken/webui/views/layout_skonf.tpl
similarity index 93%
copy from shinken/webui/views/layout.tpl
copy to shinken/webui/views/layout_skonf.tpl
index 35fb382..fda5b40 100644
--- a/shinken/webui/views/layout.tpl
+++ b/shinken/webui/views/layout_skonf.tpl
@@ -7,7 +7,7 @@
%if not 'print_menu' in locals() : print_menu = True
%if not 'print_header' in locals() : print_header = True
%if not 'refresh' in locals() : refresh = False
-%if not 'user' in locals() : user = None
+%if not 'user' in locals() : user = 'unknown'
%if not 'app' in locals() : app = None
%# If not need, disable the top right banner
@@ -79,10 +79,10 @@
<div id="userinfo">
<div class="userinfoContent">
<img src='/static/images/cut_honeycomb.png' alt="" style="width:200px; height:108px;position: absolute;top: 0;left: 0px;border: 0;">
- <div class="left"> <img style="width:60px; height:80px;" src='/static/photos/{{user.get_name()}}' alt=""> </div>
+ <div class="left"> <img style="width:60px; height:80px;" src='/static/photos/{{user}}' alt=""> </div>
<div>
- <p>Name : {{user.get_name()}}</p>
- <p>Email : {{user.email}}</p>
+ <p>Name : {{user}}</p>
+ <p>Email : {{user}}</p>
</div>
<div class="userinfoClose"> <a href="#" id="closeUserinfo"><img style="width: 16px;height: 16px;" src="/static/images/disabled.png" alt="" title="">Close</a> </div>
@@ -95,16 +95,16 @@
<div class="container_16">
%if print_header:
- %include header_element globals()
+ %include header_element_skonf globals()
%end
%if print_menu:
- %include nav_element globals()
+ %include nav_element_skonf globals()
%end
<div id="main_container" class="grid_16">
%include
</div>
<div class="clear"></div>
- %include footer_element
+ %include footer_element_skonf
</div>
</body>
</html>
diff --git a/shinken/webui/views/nav_element.tpl b/shinken/webui/views/nav_element_skonf.tpl
similarity index 91%
copy from shinken/webui/views/nav_element.tpl
copy to shinken/webui/views/nav_element_skonf.tpl
index 687686c..6b3aa38 100644
--- a/shinken/webui/views/nav_element.tpl
+++ b/shinken/webui/views/nav_element_skonf.tpl
@@ -24,8 +24,8 @@ closeDelay:12000
<!-- New UL starts here -->
<ul>
<div>
- <img style="width:20px; height:20px; padding:10px 0 0 10px;" src='/static/photos/{{user.get_name()}}'>
- <span>{{user.get_name()}}</span>
+ <img style="width:20px; height:20px; padding:10px 0 0 10px;" src='/static/photos/{{user}}'>
+ <span>{{user}}</span>
<hr/>
<li><a href="/user/logout">Log out</a></li>
</div>
--
UNNAMED PROJECT
More information about the Pkg-nagios-changes
mailing list