+ {% elif case.priority < 3 %}
+
+ {% else %}
+
+ {% endif %}
+ {% if case.status.startswith("OK") %}
+
+ {% endif %}
{{case.status}} P{{case.priority}}
- [第
#{{case.current_step}}次/最大{{case.max_step}}次]
-
{{case.timestamp|time_duration}}
-
[
-
template
+
+ {% if case.priority < 3 %}
+ [第#{{case.current_step}}次/最大{{case.max_step}}次]
+ {{case.timestamp|time_duration}}
+ [
+
template
+ {% else %}
+ [第
#{{case.current_step}}次/最大{{case.max_step}}次]
+
{{case.timestamp|time_duration}}
+
[
+
template
+ {% endif %}
+
{%if case.strategy_id>0%}
¦
@@ -28,11 +45,17 @@
{{_('alerting cases')}}
expression
{%endif%}
- ¦
- delete
+ {% if case.status.startswith("OK") %}
+ ¦
+ delete
+ {% endif %}
¦
{{_('event list')}}
- ]
+ {% if case.priority < 3 %}
+ ]
+ {% else %}
+ ]
+ {% endif %}
{{case.endpoint}}
@@ -43,7 +66,11 @@ {{_('alerting cases')}}
¦
{{case.cond}}
¦
- note: {{case.note}}
+ {% if case.priority < 3 %}
+ note: {{case.note}}
+ {% else %}
+ note: {{case.note}}
+ {% endif %}
{%endfor%}
@@ -57,6 +84,13 @@
{{_('alerting cases')}}
{{ blocks.pager('/portal/alarm-dash/case?status='+status, total, limit, page) }}
+
{%endblock%}
diff --git a/rrd/view/__init__.py b/rrd/view/__init__.py
index 6fa04eb..8b7a83b 100644
--- a/rrd/view/__init__.py
+++ b/rrd/view/__init__.py
@@ -16,7 +16,7 @@
import datetime
import time
-from flask import g, session, request, redirect
+from flask import g, abort, session, request, redirect
from rrd import app, config
from rrd.view.utils import get_usertoken_from_session, get_current_user_profile
@@ -64,7 +64,9 @@ def app_before():
not path.startswith("/portal/links/") and \
not path.startswith("/auth/register"):
return redirect("/auth/login")
-
+ if path.startswith("/portal/"):
+ if not (g.user.is_admin() or g.user.is_root()):
+ return abort(403, "no such privilege")
if path.startswith("/screen"):
g.nav_menu = "nav_screen"
elif path.startswith("/portal/hostgroup") or path.startswith("/portal/group"):
diff --git a/rrd/view/auth/auth.py b/rrd/view/auth/auth.py
index c203c4c..f5a40b5 100644
--- a/rrd/view/auth/auth.py
+++ b/rrd/view/auth/auth.py
@@ -38,7 +38,9 @@ def auth_login():
ret = { "msg": "", }
name = request.form.get("name")
+ user_id = -1
password = request.form.get("password")
+ random_pass = view_utils.gen_random_pass(12)
ldap = request.form.get("ldap") or "0"
if not name or not password:
@@ -52,15 +54,39 @@ def auth_login():
h = {"Content-type":"application/json"}
d = {
"name": name,
- "password": password,
+ "password": random_pass,
"cnname": ldap_info['cnname'],
"email": ldap_info['email'],
"phone": ldap_info['phone'],
}
- r = requests.post("%s/user/create" %(config.API_ADDR,), \
- data=json.dumps(d), headers=h)
- log.debug("%s:%s" %(r.status_code, r.text))
+ root_sig = view_utils.get_root_sig("root", config.ROOT_PASSWD)
+ if not root_sig:
+ ret["msg"] = "ldap user login failed"
+ return json.dumps(ret)
+
+ Apitoken = {"name":"root", "sig":root_sig}
+ h.update({"apitoken":json.dumps(Apitoken)})
+ r = requests.get("%s/user/name/%s" % (config.API_ADDR,name), headers=h)
+ if r.status_code == 200:
+ j = r.json()
+ user_id = j["id"]
+
+ d = {
+ "user_id": user_id, "password": random_pass,
+ }
+ req = requests.put("%s/admin/change_user_passwd" % (config.API_ADDR,), \
+ data=json.dumps(d), headers=h)
+ log.debug("%s:%s" % (req.status_code, req.text))
+
+ if req.status_code != 200:
+ raise Exception("%s %s" % (req.status_code, req.text))
+ else:
+ req = requests.post("%s/user/create" %(config.API_ADDR,), \
+ data=json.dumps(d), headers=h)
+ log.debug("%s:%s" %(req.status_code, reqr.text))
+
+ password = random_pass
#TODO: update password in db if ldap password changed
except Exception as e:
diff --git a/rrd/view/utils.py b/rrd/view/utils.py
index feed416..f68f2dc 100644
--- a/rrd/view/utils.py
+++ b/rrd/view/utils.py
@@ -16,6 +16,7 @@
import json
import requests
+import random
from flask import g, redirect, session, abort, request
from functools import wraps
@@ -116,6 +117,17 @@ def login_user(name, password):
set_user_cookie(ut, session)
return ut
+def get_root_sig(name, password):
+ params = {
+ "name": name,
+ "password": password,
+ }
+ r = requests.post("%s/user/login" %config.API_ADDR, data=params)
+ if r.status_code != 200:
+ raise Exception("%s : %s" %(r.status_code, r.text))
+
+ j = r.json()
+ return j["sig"]
def ldap_login_user(name, password):
import ldap
@@ -179,3 +191,10 @@ def ldap_login_user(name, password):
raise e
finally:
cli and cli.unbind_s()
+
+def gen_random_pass(pass_len):
+ s = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~!@#$%^&*()_+{}|:"<>?'
+ nonce = ''
+ for i in range(pass_len):
+ nonce = "%s%s" % (nonce, random.choice(s))
+ return nonce