def ajax_switch_visibility_control(): state = True if int(html.var("state")) is 1 else False # check permissions if config.user_id and config.may('general.edit_profile'): #User DB auslesen users = userdb.load_users(lock=True) user = users.get(config.user_id) # Custom attributes if config.may('general.edit_user_attributes'): for name, attr in userdb.get_user_attributes(): if attr['user_editable']: if name == "force_authuser": users[config.user_id][name] = state userdb.save_users(users) break auth_user_value = 1 if state is True else 0 #render_visibility_control ??? der Aufruf geht hier leider nicht, findet anscheinend die Funktion nicht, deshalb hier doppelter Code ??? html.write("<table class=visibility_control>\n") url = defaults.url_prefix + ("check_mk/switch_user_visibility.py?state=%d") % (1 - auth_user_value) onclick = "get_url('%s', updateContents, 'snapin_visibility_control'); parent.frames[1].location.reload();" % url html.write("<tr><td class=left>See only your own items</td><td>") html.icon_button("#", _("See only your own items %s") % (auth_user_value and "off" or "on"), "snapin_switch_" + (auth_user_value and "on" or "off"), onclick=onclick) html.write("</td></tr>") html.write("</table>") html.set_browser_reload(1) html.reload_sidebar()
def show_report_form(details): users = userdb.load_users() user = users.get(config.user_id, {}) details.setdefault("name", user.get("alias")) details.setdefault("mail", user.get("mail")) html.begin_form("report", method = "GET") html.show_user_errors() vs = vs_crash_report() vs.render_input("_report", details) vs.set_focus("report") forms.end() html.button("report", _("Submit Report")) html.hidden_fields() html.end_form()
def show_report_form(details): users = userdb.load_users() user = users.get(config.user_id, {}) details.setdefault("name", user.get("alias")) details.setdefault("mail", user.get("mail")) html.begin_form("report", method="GET") html.show_user_errors() vs = vs_crash_report() vs.render_input("_report", details) vs.set_focus("report") forms.end() html.button("_report", _("Submit Report")) html.hidden_fields() html.end_form()
def check_auth_cookie(cookie_name): username, issue_time, cookie_hash = html.cookie(cookie_name, '::').split(':', 2) # FIXME: Ablauf-Zeit des Cookies testen #max_cookie_age = 10 #if float(issue_time) < time.time() - max_cookie_age: # del_auth_cookie() # return '' users = userdb.load_users().keys() if not username in users: raise MKAuthException(_('Username is unknown')) # Validate the hash serial = load_serial(username) if cookie_hash != generate_hash(username, issue_time, serial): raise MKAuthException(_('Invalid credentials')) # Once reached this the cookie is a good one. Renew it! renew_cookie(cookie_name, username, serial) # Return the authenticated username return username
def notify_mail(user_id, msg): users = userdb.load_users(lock=False) user = users.get(user_id) if not user: raise MKInternalError(_('This user does not exist.')) if not user.get('email'): raise MKInternalError(_('This user has no mail address configured.')) recipient_name = user.get('alias') if not recipient_name: recipient_name = user_id sender_name = users[config.user.id].get('alias') if not sender_name: sender_name = user_id # Code mostly taken from notify_via_email() from notify.py module subject = _('Check_MK: Notification') body = _('''Greetings %s, %s sent you a notification: --- %s --- ''') % (recipient_name, sender_name, msg['text']) if msg['valid_till']: body += _( 'This notification has been created at %s and is valid till %s.' ) % (time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(msg['time'])), time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(msg['valid_till']))) # FIXME: Maybe use the configured mail command for Check_MK-Notify one day # TODO: mail does not accept umlauts: "contains invalid character '\303'" in mail # addresses. handle this correctly. command = [ "mail", "-s", subject.encode("utf-8"), user['email'].encode("utf-8") ] # Make sure that mail(x) is using UTF-8. Otherwise we cannot send notifications # with non-ASCII characters. Unfortunately we do not know whether C.UTF-8 is # available. If e.g. nail detects a non-Ascii character in the mail body and # the specified encoding is not available, it will silently not send the mail! # Our resultion in future: use /usr/sbin/sendmail directly. # Our resultion in the present: look with locale -a for an existing UTF encoding # and use that. for encoding in os.popen("locale -a 2>/dev/null"): l = encoding.lower() if "utf8" in l or "utf-8" in l or "utf.8" in l: encoding = encoding.strip() os.putenv("LANG", encoding) break else: raise MKInternalError( _('No UTF-8 encoding found in your locale -a! Please provide C.UTF-8 encoding.' )) try: p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, close_fds=True) except OSError, e: raise MKInternalError( _('Mail could not be delivered. ' 'Failed to execute command "%s": %s') % (" ".join(command), e))
def add_gui_user_infos_to_details(details): import userdb users = userdb.load_users() user = users.get(config.user.id, {}) details.setdefault("name", user.get("alias")) details.setdefault("mail", user.get("mail"))
def notify_mail(user_id, msg): import subprocess, time users = userdb.load_users(lock = False) user = users.get(user_id) if not user: raise MKInternalError(_('This user does not exist.')) if not user.get('email'): raise MKInternalError(_('This user has no mail address configured.')) recipient_name = user.get('alias') if not recipient_name: recipient_name = user_id sender_name = users[config.user_id].get('alias') if not sender_name: sender_name = user_id # Code mostly taken from notify_via_email() from notify.py module subject = _('Check_MK: Notification') body = _('''Greetings %s, %s sent you a notification: --- %s --- ''') % (recipient_name, sender_name, msg['text']) if msg['valid_till']: body += _('This notification has been created at %s and is valid till %s.') % ( time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(msg['time'])), time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(msg['valid_till'])) ) # FIXME: Maybe use the configured mail command for Check_MK-Notify one day command = u"mail -s '$SUBJECT$' '$CONTACTEMAIL$'" command_utf8 = command.replace('$SUBJECT$', subject).replace('$CONTACTEMAIL$', user['email']).encode("utf-8") # Make sure that mail(x) is using UTF-8. Otherwise we cannot send notifications # with non-ASCII characters. Unfortunately we do not know whether C.UTF-8 is # available. If e.g. nail detects a non-Ascii character in the mail body and # the specified encoding is not available, it will silently not send the mail! # Our resultion in future: use /usr/sbin/sendmail directly. # Our resultion in the present: look with locale -a for an existing UTF encoding # and use that. for encoding in os.popen("locale -a 2>/dev/null"): l = encoding.lower() if "utf8" in l or "utf-8" in l or "utf.8" in l: encoding = encoding.strip() os.putenv("LANG", encoding) break else: raise MKInternalError(_('No UTF-8 encoding found in your locale -a! Please provide C.UTF-8 encoding.')) p = subprocess.Popen(command_utf8, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) stdout_txt, stderr_txt = p.communicate(body.encode("utf-8")) exitcode = p.returncode if exitcode != 0: raise MKInternalError(_('Mail could not be delivered. Exit code of command is %r') % exitcode) else: return True
def load_serial(user_id): users = userdb.load_users() return users.get(user_id, {}).get('serial', 0)
def notify_mail(user_id, msg): import subprocess, time users = userdb.load_users(lock=False) user = users.get(user_id) if not user: raise MKInternalError(_('This user does not exist.')) if not user.get('email'): raise MKInternalError(_('This user has no mail address configured.')) recipient_name = user.get('alias') if not recipient_name: recipient_name = user_id sender_name = users[config.user_id].get('alias') if not sender_name: sender_name = user_id # Code mostly taken from notify_via_email() from notify.py module subject = _('Check_MK: Notification') body = _('''Greetings %s, %s sent you a notification: --- %s --- ''') % (recipient_name, sender_name, msg['text']) if msg['valid_till']: body += _( 'This notification has been created at %s and is valid till %s.' ) % (time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(msg['time'])), time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(msg['valid_till']))) # FIXME: Maybe use the configured mail command for Check_MK-Notify one day command = u"mail -s '$SUBJECT$' '$CONTACTEMAIL$'" command_utf8 = command.replace('$SUBJECT$', subject).replace( '$CONTACTEMAIL$', user['email']).encode("utf-8") # Make sure that mail(x) is using UTF-8. Otherwise we cannot send notifications # with non-ASCII characters. Unfortunately we do not know whether C.UTF-8 is # available. If e.g. nail detects a non-Ascii character in the mail body and # the specified encoding is not available, it will silently not send the mail! # Our resultion in future: use /usr/sbin/sendmail directly. # Our resultion in the present: look with locale -a for an existing UTF encoding # and use that. for encoding in os.popen("locale -a 2>/dev/null"): l = encoding.lower() if "utf8" in l or "utf-8" in l or "utf.8" in l: encoding = encoding.strip() os.putenv("LANG", encoding) break else: raise MKInternalError( _('No UTF-8 encoding found in your locale -a! Please provide C.UTF-8 encoding.' )) p = subprocess.Popen(command_utf8, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) stdout_txt, stderr_txt = p.communicate(body.encode("utf-8")) exitcode = p.returncode if exitcode != 0: raise MKInternalError( _('Mail could not be delivered. Exit code of command is %r') % exitcode) else: return True
def notify_mail(user_id, msg): users = userdb.load_users(lock = False) user = users.get(user_id) if not user: raise MKInternalError(_('This user does not exist.')) if not user.get('email'): raise MKInternalError(_('This user has no mail address configured.')) recipient_name = user.get('alias') if not recipient_name: recipient_name = user_id sender_name = users[config.user.id].get('alias') if not sender_name: sender_name = user_id # Code mostly taken from notify_via_email() from notify.py module subject = _('Check_MK: Notification') body = _('''Greetings %s, %s sent you a notification: --- %s --- ''') % (recipient_name, sender_name, msg['text']) if msg['valid_till']: body += _('This notification has been created at %s and is valid till %s.') % ( time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(msg['time'])), time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(msg['valid_till'])) ) # FIXME: Maybe use the configured mail command for Check_MK-Notify one day # TODO: mail does not accept umlauts: "contains invalid character '\303'" in mail # addresses. handle this correctly. command = ["mail", "-s", subject.encode("utf-8"), user['email'].encode("utf-8")] # Make sure that mail(x) is using UTF-8. Otherwise we cannot send notifications # with non-ASCII characters. Unfortunately we do not know whether C.UTF-8 is # available. If e.g. nail detects a non-Ascii character in the mail body and # the specified encoding is not available, it will silently not send the mail! # Our resultion in future: use /usr/sbin/sendmail directly. # Our resultion in the present: look with locale -a for an existing UTF encoding # and use that. for encoding in os.popen("locale -a 2>/dev/null"): l = encoding.lower() if "utf8" in l or "utf-8" in l or "utf.8" in l: encoding = encoding.strip() os.putenv("LANG", encoding) break else: raise MKInternalError(_('No UTF-8 encoding found in your locale -a! Please provide C.UTF-8 encoding.')) try: p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, close_fds=True) except OSError, e: raise MKInternalError(_('Mail could not be delivered. ' 'Failed to execute command "%s": %s') % (" ".join(command), e))