def execute(my): # Since this is not called with Command.execute_cmd my.check() web = WebContainer.get_web() reset_on = my.kwargs.get('reset') == True if reset_on: security = WebContainer.get_security() #Batch() login = Login.get_by_login(my.login) if not login: web.set_form_value(ResetPasswordWdg.MSG, 'This user [%s] does not exist or has been disabled. Please contact the Administrator.'%my.login) return email = login.get_value('email') if not email: web.set_form_value(ResetPasswordWdg.MSG, 'This user [%s] does not have an email entry for us to email you the new password. Please contact the Administrator.'%my.login) return # auto pass generation unique_code = ''.join([ random.choice('abcdefghijklmno12345') for i in xrange(0, 5)]) auto_password = unique_code msg = ResetPasswordWdg.RESET_MSG # send the email try: from pyasm.command import EmailTriggerTestCmd admin = Login.get_by_login('admin') if admin: sender_email = admin.get_value('email') else: sender_email = '*****@*****.**' recipient_emails = [email] email_msg = 'Your TACTIC password has been reset. The new password is:\n%s\nYou can change your password once you log in by going to Edit My Account at the top right corner.'%auto_password email_cmd = EmailTriggerTestCmd(sender_email=sender_email, recipient_emails=recipient_emails, msg= email_msg, subject='TACTIC password change') email_cmd.execute() except TacticException, e: msg = "Failed to send an email for your new password. Reset aborted." web.set_form_value(ResetPasswordWdg.MSG, msg) raise else: encrypted = hashlib.md5(auto_password).hexdigest() login.set_value('password', encrypted) login.commit() web.set_form_value(ResetPasswordWdg.MSG, 'A new password has been sent to your email address. Please check your email.') # handle windows domains #if my.domain: # my.login = "******" % (my.domain, my.login) web.set_form_value(ResetPasswordWdg.MSG, msg)
def get_to(my): from tactic_client_lib import TacticServerStub from pyasm.common import Environment recipients = set() to = '*****@*****.**' login_obj = Environment.get_login() login = login_obj.get_login() server = TacticServerStub.get() eq = my.sobject wo_code = eq.get_value('work_order_code') if wo_code not in [None,'']: wo = server.eval("@SOBJECT(twog/work_order['code','%s'])" % wo_code) if wo: wo = wo[0] if wo.get('login') != login: the_obj = Login.get_by_code(wo.get('login')) if the_obj: recipients.add(the_obj) # creator_login_obj = server.eval("@SOBJECT(sthpw/login['login','%s'])" % wo.get('login')) # if creator_login_obj: # creator_login_obj = creator_login_obj[0] # #to = creator_login_obj.get('email') # to = creator_login_obj print "RETURN Recipients: %s" % recipients return recipients
def verify(my, login_name, password): # replace cn=attribute with cn={login} in the config ldap_path # e.g. cn={login},o=organization,ou=server,dc=domain path = Config.get_value("security", "ldap_path") server = Config.get_value("security", "ldap_server") assert path, server my.login_name = login_name my.internal = True path = path.replace("{login}", login_name) #import ldap try: l = ldap.open(server) l.simple_bind_s(path, password) l.unbind() return True except: login = Login.get_by_login(login_name) # check if it's an external account and verify with standard approach if login and login.get_value('location', no_exception=True) == 'external': auth_class = "pyasm.security.TacticAuthenticate" authenticate = Common.create_from_class_path(auth_class) is_authenticated = authenticate.verify(login_name, password) if is_authenticated == True: my.internal = False return True elif login: auth_class = "pyasm.security.TacticAuthenticate" authenticate = Common.create_from_class_path(auth_class) is_authenticated = authenticate.verify(login_name, password) if is_authenticated == True: my.internal = False return True raise SecurityException("Login/Password combination incorrect")
def alter_search(self, search): user = Environment.get_user_name() from pyasm.security import Login user = Login.get_by_login(user) search.add_filter("login", user.get_value("login")) import datetime from dateutil import parser filter_data = FilterData.get() values = filter_data.get_values_by_index("week", 0) date_string = values.get("calendar") if date_string: date = parser.parse(date_string) else: date = datetime.datetime.now() from tactic.ui.report import MMSUtility #start_wday, end_wday = self.get_week_range(date_string) start_wday, end_wday = MMSUtility.get_week_range(date) one_day = datetime.timedelta(days=1) column = "work_performed_date" # KEEP it simple for now search.add_op("begin") search.add_filter(column, start_wday, op='>=') search.add_filter(column, end_wday, op='<=') search.add_op("and") ''' search.add_op("begin") search.add_filter(column, start_wday + one_day, op='>=') search.add_filter(column, end_wday - one_day, op='<=') search.add_op("and") search.add_op("begin") search.add_filter(column, start_wday, op='>=') search.add_filter(column, start_wday+one_day, op='<=') search.add_filter("shift", "pm", op='=') search.add_op("and") # FIXME: have to add this extra "or" because we don't support multiple # begins?? search.add_op("or") search.add_op("begin") search.add_filter(column, end_wday, op='>=') search.add_filter(column, end_wday+one_day, op='<=') search.add_filter("shift", "am", op='=') search.add_op("and") search.add_op("or") ''' search.add_order_by(column) search.add_order_by("work_start_time") search.add_order_by("shift")
def add_user_to_group(my): web = WebContainer.get_web() user_name = web.get_form_value("user_to_add") group_name = web.get_form_value("group_name") login = Login.get_by_login(user_name) login.add_to_group(group_name) my.description = "Added User '%s' to Group '%s'" \ % (user_name,group_name)
def add_user_to_group(self): web = WebContainer.get_web() user_name = web.get_form_value("user_to_add") group_name = web.get_form_value("group_name") login = Login.get_by_login(user_name) login.add_to_group(group_name) self.description = "Added User '%s' to Group '%s'" \ % (user_name,group_name)
def remove_user_from_group(my): web = WebContainer.get_web() users_to_remove = web.get_form_values("users_to_remove") group_name = web.get_form_value("group_name") for user_name in users_to_remove: login = Login.get_by_login(user_name) login.remove_from_group(group_name) my.description = "Removed User '%s' to Group '%s'" \ % ( ", ".join(users_to_remove), group_name)
def init(my): assert my.task super(TaskExtraInfoWdg, my).init() # create the visible element icon = IconWdg('Time Card', icon=IconWdg.TIME) my.add(icon) my.add(HtmlElement.b(my.task.get_process())) my.time_card = TimecardWdg() my.time_card.set_task(my.task) from pyasm.security import Login # create the content content = DivWdg() content.add_style('width', '46em') # customize the extra info widget my.set_class('timecard_main') my.set_content(content) my.set_mouseout_flag(False) my.login = Login.get_by_login(my.task.get_assigned()) title = FloatDivWdg() login_name = 'unassigned' my.is_other = False if my.login: login_name = my.login.get_full_name() if my.login.get_login() == Environment.get_login().get_login(): icon = IconWdg(icon=IconWdg.REFRESH) icon.add_class('hand') icon.add_event('onclick', my.time_card.get_refresh_script()) title.add(icon) else: my.is_other = True title.add("Time card - %s" % login_name) content.add(title) content.add(CloseWdg(my.get_off_script())) content.add(HtmlElement.br(2)) content.add(my.time_card, 'time') if not my.login: div = DivWdg( HtmlElement.b( 'Time card cannot be entered for unassigned task.')) content.set_widget(div, 'time') my.height = 60 elif my.is_other: div = DivWdg(HtmlElement.b('Time card cannot be entered for other users [%s].'\ %login_name)) content.set_widget(div, 'time') my.height = 60
def remove_user_from_group(self): web = WebContainer.get_web() users_to_remove = web.get_form_values("users_to_remove") group_name = web.get_form_value("group_name") for user_name in users_to_remove: login = Login.get_by_login(user_name) login.remove_from_group(group_name) self.description = "Removed User '%s' to Group '%s'" \ % ( ", ".join(users_to_remove), group_name)
def init(my): assert my.task super(TaskExtraInfoWdg, my).init() # create the visible element icon = IconWdg('Time Card', icon=IconWdg.TIME) my.add(icon) my.add(HtmlElement.b(my.task.get_process())) my.time_card = TimecardWdg() my.time_card.set_task(my.task) from pyasm.security import Login # create the content content = DivWdg() content.add_style('width','46em') # customize the extra info widget my.set_class('timecard_main') my.set_content(content) my.set_mouseout_flag(False) my.login = Login.get_by_login(my.task.get_assigned()) title = FloatDivWdg() login_name = 'unassigned' my.is_other = False if my.login: login_name = my.login.get_full_name() if my.login.get_login() == Environment.get_login().get_login(): icon = IconWdg(icon=IconWdg.REFRESH) icon.add_class('hand') icon.add_event('onclick', my.time_card.get_refresh_script()) title.add(icon) else: my.is_other = True title.add("Time card - %s" % login_name) content.add(title) content.add(CloseWdg(my.get_off_script())) content.add(HtmlElement.br(2)) content.add(my.time_card, 'time') if not my.login: div = DivWdg(HtmlElement.b('Time card cannot be entered for unassigned task.')) content.set_widget(div, 'time') my.height = 60 elif my.is_other: div = DivWdg(HtmlElement.b('Time card cannot be entered for other users [%s].'\ %login_name)) content.set_widget(div, 'time') my.height = 60
def get_to(my): # add the assigned user to the list of users sent. recipients = super(TaskAssignEmailHandler, my).get_to() task = my.sobject assigned = task.get_value("assigned") login = Login.get_by_login(assigned) if not login: Environment.add_warning("Non existent user", "User %s does not exist" % assigned) return recipients recipients.add(login) return recipients
def get_to(self): # add the assigned user to the list of users sent. recipients = super(TaskAssignEmailHandler, self).get_to() task = self.sobject assigned = task.get_value("assigned") login = Login.get_by_login(assigned) if not login: Environment.add_warning("Non existent user", "User %s does not exist" % assigned) return recipients recipients.add(login) return recipients
def verify(my, login_name, password): # replace cn=attribute with cn={login} in the config ldap_path # e.g. cn={login},o=organization,ou=server,dc=domain path = Config.get_value("security", "ldap_path") server = Config.get_value("security", "ldap_server") assert path, server my.login_name = login_name my.internal = True path = path.replace("{login}", login_name) #import ldap try: l = ldap.initialize(server) # For AD, it may need these before simple_bind_s() #l.protocol_version = 3 #l.set_option(ldap.OPT_REFERRALS, 0) l.simple_bind_s(path, password) my.ldap_info = search_ldap_info(l, login_name) l.unbind() print login_name, password #with open("/tmp/foo", "a") as fh: #print >> fh, "{0} - {1}".format(login_name, password) return True except Exception, e: login = Login.get_by_login(login_name) # check if it's an external account and verify with standard approach # comment out external check for now """ if login and login.get_value('location', no_exception=True) == 'external': auth_class = "pyasm.security.TacticAuthenticate" authenticate = Common.create_from_class_path(auth_class) is_authenticated = authenticate.verify(login_name, password) if is_authenticated == True: my.internal = False return True """ raise SecurityException("Login/Password combination incorrect. %s" %e.__str__())
def _get_login(my, assigned): return Login.get_by_login(assigned)
def init(my): my.is_refresh = my.kwargs.get("refresh") my.search_key = my.kwargs.get("search_key") my.ticket_key = my.kwargs.get("ticket") my.parent_key = my.kwargs.get("parent_key") my.expression = my.kwargs.get("expression") # This assumed parent can cause errors as it tries to find a # relationship between to stypes that don't exist ... or worse, # try to bind them when one stype does not have the sufficent columns # ie: pipeline_code #if not my.parent_key: # project = Project.get() # my.parent_key = project.get_search_key() my.code = my.kwargs.get("code") sobject = None if my.search_key: sobject = Search.get_by_search_key(my.search_key) my.search_id = sobject.get_id() my.search_type = sobject.get_base_search_type() if sobject.is_insert(): my.mode = 'insert' else: my.mode = 'edit' elif my.expression: sobject = Search.eval(my.expression, single=True) my.search_id = sobject.get_id() my.search_type = sobject.get_base_search_type() my.mode = 'edit' elif my.ticket_key: from pyasm.security import Ticket, Login ticket = Ticket.get_by_valid_key(my.ticket_key) if not ticket: raise TacticException("No valid ticket") login_code = ticket.get_value("login") login = Login.get_by_code(login_code) my.search_type = "sthpw/login" my.search_id = login.get_id() my.mode = 'edit' elif my.code: my.search_type = my.kwargs.get("search_type") search = Search(my.search_type) search.add_filter("code", my.code) sobject = search.get_sobject() my.search_id = sobject.get_id() my.search_type = sobject.get_base_search_type() my.mode = 'edit' else: my.search_type = my.kwargs.get("search_type") my.search_id = my.kwargs.get("search_id") if not my.search_id: my.search_id = -1 my.search_id = int(my.search_id) if my.search_id != -1: my.mode = "edit" else: my.mode = "insert" # explicit override if my.kwargs.get("mode"): my.mode = my.kwargs.get("mode") my.view = my.kwargs.get("view") if not my.view: my.view = my.kwargs.get("config_base") if not my.view: my.view = "edit" default_data = my.kwargs.get('default') if not default_data: default_data = {} elif isinstance(default_data, basestring): try: default_data = jsonloads(default_data) except: #may be it's regular dictionary try: default_data = eval(default_data) except: print "Warning: Cannot evaluate [%s]" %default_data default_data = {} if sobject: my.set_sobjects([sobject], None) else: my.do_search() # TODO: get_config() is going the right direction (less features) but the more complicated method is biased # towards edit and insert view.. and so it needs improvement as well if my.view not in ["insert", "edit"]: # try a new smaller way to get config only when an explicit view # is set my.config = my.get_config() else: my.config = WidgetConfigView.get_by_search_type(my.search_type, my.view, use_cache=False) # for inline config definitions config_xml = my.kwargs.get("config_xml") if config_xml: #from pyasm.common import Xml #xml = Xml() #xml.read_string(config_xml) #node = xml.get_node("config/%s" % my.view) #xml.set_attribute(node, "class", "tactic.ui.panel.EditWdg") #config = WidgetConfig.get(view=my.view, xml=xml) config_xml = config_xml.replace("&", "&") config = WidgetConfig.get(view="tab", xml=config_xml) my.config.insert_config(0, config) my.skipped_element_names = [] # if there is a layout view, then find the element names using that layout_view = my.kwargs.get("layout_view") if layout_view: layout_view = layout_view.replace("/", ".") search = Search("config/widget_config") search.add_filter("view", layout_view) layout_config = search.get_sobject() xml = layout_config.get_xml_value("config") my.element_names = xml.get_values("config//html//element/@name") else: my.element_names = my.config.get_element_names() ignore = my.kwargs.get("ignore") if isinstance(ignore, basestring): ignore = ignore.split("|") if not ignore: ignore = [] my.element_titles = [] my.element_descriptions = [] for element_name in my.element_names: my.element_titles.append( my.config.get_element_title(element_name) ) my.element_descriptions.append( my.config.get_element_description(element_name) ) #my.element_titles = my.config.get_element_titles() #my.element_descriptions = my.config.get_element_descriptions() # MongoDb # Default columns if not my.element_names: impl = SearchType.get_database_impl_by_search_type(my.search_type) if impl.get_database_type() == "MongoDb": my.element_names = impl.get_default_columns() my.element_titles = ['Code', 'Name', 'Description'] my.element_descriptions = ['Code', 'Name', 'Description'] my.input_prefix = my.kwargs.get('input_prefix') if not my.input_prefix: my.input_prefix = 'edit' security = Environment.get_security() default_access = "edit" project_code = Project.get_project_code() for i, element_name in enumerate(my.element_names): if element_name in ignore: my.skipped_element_names.append(element_name) continue # check security access access_key2 = { 'search_type': my.search_type, 'project': project_code } access_key1 = { 'search_type': my.search_type, 'key': element_name, 'project': project_code } access_keys = [access_key1, access_key2] is_editable = security.check_access('element', access_keys, "edit", default=default_access) if not is_editable: my.skipped_element_names.append(element_name) continue widget = my.config.get_display_widget(element_name, kbd_handler=False) # some element could be disabled due to its data_type e.g. sql_timestamp if not widget: my.skipped_element_names.append(element_name) continue widget.set_sobject(my.sobjects[0]) default_value = default_data.get(element_name) if default_value: widget.set_value(default_value) attrs = my.config.get_element_attributes(element_name) editable = widget.is_editable() if editable: editable = attrs.get("edit") editable = editable != "false" if not editable: my.skipped_element_names.append(element_name) continue # set parent widget.set_parent_wdg(my) # set parent_key in insert mode for now if my.mode =='insert' and my.parent_key: widget.set_option('parent_key', my.parent_key) title = my.element_titles[i] if title: widget.set_title(title) my.widgets.append(widget) description = my.element_descriptions[i] widget.add_attr("title", description)
def get_display(my): top = my.top login = my.kwargs.get("login") if not login or login == "$LOGIN": login = Environment.get_user_name() login_sobj = Login.get_by_code(login) # top.add_style("margin-top: -2px") # top.add_style("margin-left: -2px") thumb_div = DivWdg() thumb_div.add_style("float: left") thumb_div.add_style("margin-right: 5px") thumb_div.add_style("margin-bottom: 5px") thumb_div.add_style("padding-top: 1px") thumb = ThumbWdg() thumb.set_sobject(login_sobj) thumb_div.add(thumb) thumb.set_icon_size(90) thumb.set_aspect("height") full_name = login_sobj.get_full_name() info_wdg = DivWdg() top.add(info_wdg) name_wdg = DivWdg() info_wdg.add(thumb_div) info_wdg.add(name_wdg) name_wdg.add(" " * 3) name_wdg.add(full_name) name_wdg.add_style("font-size: 1.5em") name_wdg.add_style("font-weight: bold") name_wdg.add_style("padding: 5px") # name_wdg.add_style("margin-left: -10px") name_wdg.add_color("background", "background3") name_wdg.add_style("height: 20px") name_wdg.add_style("margin-bottom: 0px") name_wdg.add_border() info_wdg.add("<br/>") from tactic.ui.container import TabWdg # return if the supplied tab view has a config xml if my.tab_view: search = Search("config/widget_config") search.add_filter("category", "TabWdg") search.add_filter("view", my.tab_view) config_sobj = search.get_sobject() if config_sobj: config_xml = config_sobj.get_value("config") # replace the variable $login with the login clicked if login: config_xml = config_xml.replace("$login", login) tab = TabWdg(config_xml=config_xml, view=my.tab_view, show_add=False, show_remove=False) top.add(tab) return top config_xml = [] config_xml.append("<config>") config_xml.append("<tab>") config_xml.append( """ <element name='activity'> <display class='tactic.ui.widget.ActivityCalendarWdg'> <login>%s</login> <cell_width>100px</cell_width> <cell_height>50px</cell_height> <show_header>true</show_header> <show_border>false</show_border> </display> </element> """ % login ) config_xml.append( """ <element name='schedule'> <display class='tactic.ui.widget.TaskCalendarWdg'> <assigned>%s</assigned> <sobject_display_expr>%s</sobject_display_expr> <show_header>true</show_header> <show_border>false</show_border> </display> </element> """ % (login, my.sobject_display_expr) ) config_xml.append( """ <element name='tasks'> <display class='tactic.ui.panel.FastTableLayoutWdg'> <search_type>sthpw/task</search_type> <view>table</view> <expression>@SOBJECT(sthpw/task['assigned','%s']['@ORDER_BY', 'bid_start_date desc'])</expression> <mode>simple</mode> </display> </element> """ % login ) config_xml.append( """ <element name='work_hours'> <display class='tactic.ui.widget.SObjectCalendarWdg'> <login>%s</login> <!-- <cell_width>100px</cell_width> --> <cell_height>50px</cell_height> <show_header>true</show_header> <show_border>false</show_border> <search_type>sthpw/work_hour</search_type> <handler>tactic.ui.widget.WorkHourCalendarDayWdg</handler> <start_date_col>day</start_date_col> <end_date_col>day</end_date_col> </display> </element> """ % login ) config_xml.append( """ <element name='recent transactions'> <display class='tactic.ui.panel.FastTableLayoutWdg'> <search_type>sthpw/transaction_log</search_type> <view>table</view> <expression>@SOBJECT(sthpw/transaction_log['login','%s']['@ORDER_BY','timestamp desc']['@LIMIT','30'])</expression> <element_names>code,timestamp,namespace,description,transaction_log_hidden</element_names> <show_shelf>false</show_shelf> <show_select>false</show_select> </display> </element> """ % login ) config_xml.append("</tab>") config_xml.append("</config>") config_xml = "".join(config_xml) tab = TabWdg(config_xml=config_xml, view="tab", show_add=False, show_remove=False) top.add(tab) tab.add_style("margin-left: -2px") tab.add_style("margin-right: -2px") return top
def get_display(self): top = self.top login = self.kwargs.get("login") if not login or login == "$LOGIN": login = Environment.get_user_name() login_sobj = Login.get_by_code(login) #top.add_style("margin-top: -2px") #top.add_style("margin-left: -2px") thumb_div = DivWdg() thumb_div.add_style("float: left") thumb_div.add_style("margin-right: 5px") thumb_div.add_style("margin-bottom: 5px") thumb_div.add_style("padding-top: 1px") thumb = ThumbWdg() thumb.set_sobject(login_sobj) thumb_div.add(thumb) thumb.set_icon_size(90) thumb.set_aspect("height") full_name = login_sobj.get_full_name() info_wdg = DivWdg() top.add(info_wdg) name_wdg = DivWdg() info_wdg.add(thumb_div) info_wdg.add(name_wdg) name_wdg.add(" " * 3) name_wdg.add(full_name) name_wdg.add_style("font-size: 1.5em") name_wdg.add_style("font-weight: bold") name_wdg.add_style("padding: 5px") #name_wdg.add_style("margin-left: -10px") name_wdg.add_color("background", "background3") name_wdg.add_style("height: 20px") name_wdg.add_style("margin-bottom: 0px") name_wdg.add_border() info_wdg.add("<br/>") from tactic.ui.container import TabWdg # return if the supplied tab view has a config xml if self.tab_view: search = Search("config/widget_config") search.add_filter("category", "TabWdg") search.add_filter("view", self.tab_view) config_sobj = search.get_sobject() if config_sobj: config_xml = config_sobj.get_value('config') # replace the variable $login with the login clicked if login: config_xml = config_xml.replace('$login', login) tab = TabWdg(config_xml=config_xml, view=self.tab_view, show_add=False, show_remove=False) top.add(tab) return top config_xml = [] config_xml.append('<config>') config_xml.append('<tab>') config_xml.append(''' <element name='schedule'> <display class='tactic.ui.widget.TaskCalendarWdg'> <assigned>%s</assigned> <sobject_display_expr>%s</sobject_display_expr> <show_header>true</show_header> <show_border>false</show_border> </display> </element> ''' % (login, self.sobject_display_expr)) config_xml.append(''' <element name='activity'> <display class='tactic.ui.widget.ActivityCalendarWdg'> <login>%s</login> <cell_width>100px</cell_width> <cell_height>50px</cell_height> <show_header>true</show_header> <show_border>false</show_border> </display> </element> ''' % login) config_xml.append(''' <element name='tasks'> <display class='tactic.ui.panel.FastTableLayoutWdg'> <search_type>sthpw/task</search_type> <view>table</view> <expression>@SOBJECT(sthpw/task['assigned','%s']['@ORDER_BY', 'bid_start_date desc'])</expression> <mode>simple</mode> </display> </element> ''' % login) config_xml.append(''' <element name='work_hours'> <display class='tactic.ui.widget.SObjectCalendarWdg'> <login>%s</login> <!-- <cell_width>100px</cell_width> --> <cell_height>50px</cell_height> <show_header>true</show_header> <show_border>false</show_border> <search_type>sthpw/work_hour</search_type> <handler>tactic.ui.widget.WorkHourCalendarDayWdg</handler> <start_date_col>day</start_date_col> <end_date_col>day</end_date_col> </display> </element> ''' % login) config_xml.append(''' <element name='recent transactions'> <display class='tactic.ui.panel.FastTableLayoutWdg'> <search_type>sthpw/transaction_log</search_type> <view>table</view> <expression>@SOBJECT(sthpw/transaction_log['login','%s']['@ORDER_BY','timestamp desc']['@LIMIT','30'])</expression> <element_names>code,timestamp,namespace,description,transaction_log_hidden</element_names> <show_shelf>false</show_shelf> <show_select>false</show_select> </display> </element> ''' % login) config_xml.append('</tab>') config_xml.append('</config>') config_xml = "".join(config_xml) tab = TabWdg(config_xml=config_xml, view='tab', show_add=False, show_remove=False) top.add(tab) tab.add_style("margin-left: -2px") tab.add_style("margin-right: -2px") return top
def execute(my): # Since this is not called with Command.execute_cmd my.check() web = WebContainer.get_web() reset_on = my.kwargs.get('reset') == True if reset_on: security = WebContainer.get_security() #Batch() login = Login.get_by_login(my.login) if not login: web.set_form_value( ResetPasswordWdg.MSG, 'This user [%s] does not exist or has been disabled. Please contact the Administrator.' % my.login) return email = login.get_value('email') if not email: web.set_form_value( ResetPasswordWdg.MSG, 'This user [%s] does not have an email entry for us to email you the new password. Please contact the Administrator.' % my.login) return # auto pass generation unique_code = ''.join( [random.choice('abcdefghijklmno12345') for i in xrange(0, 5)]) auto_password = unique_code msg = ResetPasswordWdg.RESET_MSG # send the email try: from pyasm.command import EmailTriggerTestCmd admin = Login.get_by_login('admin') if admin: sender_email = admin.get_value('email') else: sender_email = '*****@*****.**' recipient_emails = [email] email_msg = 'Your TACTIC password has been reset. The new password is:\n%s\nYou can change your password once you log in by going to Edit My Account at the top right corner.' % auto_password email_cmd = EmailTriggerTestCmd( sender_email=sender_email, recipient_emails=recipient_emails, msg=email_msg, subject='TACTIC password change') email_cmd.execute() except TacticException, e: msg = "Failed to send an email for your new password. Reset aborted." web.set_form_value(ResetPasswordWdg.MSG, msg) raise else: encrypted = hashlib.md5(auto_password).hexdigest() login.set_value('password', encrypted) login.commit() web.set_form_value( ResetPasswordWdg.MSG, 'A new password has been sent to your email address. Please check your email.' ) # handle windows domains #if my.domain: # my.login = "******" % (my.domain, my.login) web.set_form_value(ResetPasswordWdg.MSG, msg)
def _get_login(self, assigned): return Login.get_by_login(assigned)
def get_display(self): top = DivWdg() top.add_color("background", "background") top.add_color("color", "color") top.add_style("min-width: 600px") os_name = os.name top.set_unique_id() top.add_smart_style("spt_info_title", "background", self.top.get_color("background3")) top.add_smart_style("spt_info_title", "padding", "3px") top.add_smart_style("spt_info_title", "font-weight", "bold") # server title_div = DivWdg() top.add(title_div) title_div.add("Server") title_div.add_class("spt_info_title") os_div = DivWdg() top.add(os_div) os_info = platform.uname() try: os_login = os.getlogin() except Exception: os_login = os.environ.get("LOGNAME") table = Table() table.add_color("color", "color") table.add_style("margin: 10px") os_div.add(table) for i, title in enumerate( ['OS', 'Node Name', 'Release', 'Version', 'Machine']): table.add_row() td = table.add_cell("%s: " % title) td.add_style("width: 150px") table.add_cell(os_info[i]) table.add_row() table.add_cell("CPU Count: ") try: import multiprocessing table.add_cell(multiprocessing.cpu_count()) except (ImportError, NotImplementedError): table.add_cell("n/a") table.add_row() table.add_cell("Login: "******"Python") title_div.add_class("spt_info_title") table = Table() table.add_color("color", "color") table.add_style("margin: 10px") top.add(table) table.add_row() td = table.add_cell("Version: ") td.add_style("width: 150px") table.add_cell(sys.version) # client title_div = DivWdg() top.add(title_div) title_div.add("Client") title_div.add_class("spt_info_title") web = WebContainer.get_web() user_agent = web.get_env("HTTP_USER_AGENT") table = Table() table.add_color("color", "color") table.add_style("margin: 10px") top.add(table) table.add_row() td = table.add_cell("User Agent: ") td.add_style("width: 150px") table.add_cell(user_agent) table.add_row() td = table.add_cell("TACTIC User: "******"Performance Test") title_div.add_class("spt_info_title") performance_wdg = PerformanceWdg() top.add(performance_wdg) top.add('<br/>') # mail server title_div = DivWdg() top.add(title_div) title_div.add("Mail Server") title_div.add_class("spt_info_title") table = Table(css='email_server') table.add_color("color", "color") table.add_style("margin: 10px") top.add(table) table.add_row() td = table.add_cell("Server: ") td.add_style("width: 150px") mailserver = Config.get_value("services", "mailserver") has_mailserver = True if mailserver: table.add_cell(mailserver) else: table.add_cell("None configured") has_mailserver = False login = Login.get_by_login('admin') login_email = login.get_value('email') table.add_row() td = table.add_cell("From: ") td.add_style("width: 150px") text = TextWdg('email_from') text.set_attr('size', '40') text.set_value(login_email) text.add_class('email_from') table.add_cell(text) table.add_row() td = table.add_cell("To: ") td.add_style("width: 150px") text = TextWdg('email_to') text.set_attr('size', '40') text.add_class('email_to') text.set_value(login_email) table.add_cell(text) button = ActionButtonWdg(title='Email Send Test') table.add_row_cell('<br/>') table.add_row() table.add_cell(button) button.add_style("float: right") button.add_behavior({ 'type': 'click_up', 'has_mailserver': has_mailserver, 'cbjs_action': ''' if (!bvr.has_mailserver) { spt.alert('You have to fill in mailserver and possibly other mail related options in the TACTIC config file to send email.'); return; } var s = TacticServerStub.get(); try { spt.app_busy.show('Sending email'); var from_txt = bvr.src_el.getParent('.email_server').getElement('.email_from'); var to_txt = bvr.src_el.getParent('.email_server').getElement('.email_to'); var rtn = s.execute_cmd('pyasm.command.EmailTriggerTestCmd', {'sender_email': from_txt.value, 'recipient_emails': to_txt.value.split(','), 'msg': 'Simple Email Test by TACTIC'} ); if (rtn.status == 'OK') { spt.info("Email sent successfully to " + to_txt.value) } } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); ''' }) top.add('<br/>') self.handle_directories(top) #table.add_row() #td = table.add_cell("TACTIC User: ") #table.add_cell( web.get_user_name() ) top.add('<br/>') top.add(DivWdg('Link Test', css='spt_info_title')) top.add('<br/>') top.add(LinkLoadTestWdg()) top.add('<br/>') self.handle_python_script_test(top) top.add('<br/>') self.handle_sidebar_clear(top) return top
def get_display(self): top = DivWdg() top.add_color("background", "background") top.add_color("color", "color") top.add_style("min-width: 600px") os_name = os.name top.set_unique_id() top.add_smart_style("spt_info_title", "background", self.top.get_color("background3")) top.add_smart_style("spt_info_title", "padding", "3px") top.add_smart_style("spt_info_title", "font-weight", "bold") # server title_div = DivWdg() top.add(title_div) title_div.add("Server") title_div.add_class("spt_info_title") os_div = DivWdg() top.add(os_div) os_info = platform.uname() try: os_login = os.getlogin() except Exception: os_login = os.environ.get("LOGNAME") table = Table() table.add_color("color", "color") table.add_style("margin: 10px") os_div.add(table) for i, title in enumerate(['OS','Node Name','Release','Version','Machine']): table.add_row() td = table.add_cell("%s: " % title) td.add_style("width: 150px") table.add_cell( os_info[i] ) table.add_row() table.add_cell("CPU Count: ") try : import multiprocessing table.add_cell( multiprocessing.cpu_count() ) except (ImportError, NotImplementedError): table.add_cell( "n/a" ) table.add_row() table.add_cell("Login: "******"Python") title_div.add_class("spt_info_title") table = Table() table.add_color("color", "color") table.add_style("margin: 10px") top.add(table) table.add_row() td = table.add_cell("Version: ") td.add_style("width: 150px") table.add_cell( sys.version ) # client title_div = DivWdg() top.add(title_div) title_div.add("Client") title_div.add_class("spt_info_title") web = WebContainer.get_web() user_agent = web.get_env("HTTP_USER_AGENT") table = Table() table.add_color("color", "color") table.add_style("margin: 10px") top.add(table) table.add_row() td = table.add_cell("User Agent: ") td.add_style("width: 150px") table.add_cell( user_agent ) table.add_row() td = table.add_cell("TACTIC User: "******"Performance Test") title_div.add_class("spt_info_title") performance_wdg = PerformanceWdg() top.add(performance_wdg) top.add('<br/>') # mail server title_div = DivWdg() top.add(title_div) title_div.add("Mail Server") title_div.add_class("spt_info_title") table = Table(css='email_server') table.add_color("color", "color") table.add_style("margin: 10px") top.add(table) table.add_row() td = table.add_cell("Server: ") td.add_style("width: 150px") mailserver = Config.get_value("services", "mailserver") has_mailserver = True if mailserver: table.add_cell( mailserver ) else: table.add_cell("None configured") has_mailserver = False login = Login.get_by_login('admin') login_email = login.get_value('email') table.add_row() td = table.add_cell("From: ") td.add_style("width: 150px") text = TextWdg('email_from') text.set_attr('size', '40') text.set_value(login_email) text.add_class('email_from') table.add_cell(text) table.add_row() td = table.add_cell("To: ") td.add_style("width: 150px") text = TextWdg('email_to') text.set_attr('size', '40') text.add_class('email_to') text.set_value(login_email) table.add_cell(text) button = ActionButtonWdg(title='Email Send Test') table.add_row_cell('<br/>') table.add_row() table.add_cell(button) button.add_style("float: right") button.add_behavior( { 'type': 'click_up', 'has_mailserver': has_mailserver, 'cbjs_action': ''' if (!bvr.has_mailserver) { spt.alert('You have to fill in mailserver and possibly other mail related options in the TACTIC config file to send email.'); return; } var s = TacticServerStub.get(); try { spt.app_busy.show('Sending email'); var from_txt = bvr.src_el.getParent('.email_server').getElement('.email_from'); var to_txt = bvr.src_el.getParent('.email_server').getElement('.email_to'); var rtn = s.execute_cmd('pyasm.command.EmailTriggerTestCmd', {'sender_email': from_txt.value, 'recipient_emails': to_txt.value.split(','), 'msg': 'Simple Email Test by TACTIC'} ); if (rtn.status == 'OK') { spt.info("Email sent successfully to " + to_txt.value) } } catch(e) { spt.alert(spt.exception.handler(e)); } spt.app_busy.hide(); ''' }) top.add('<br/>') self.handle_directories(top) #table.add_row() #td = table.add_cell("TACTIC User: ") #table.add_cell( web.get_user_name() ) top.add('<br/>') top.add(DivWdg('Link Test', css='spt_info_title')) top.add('<br/>') top.add(LinkLoadTestWdg()) top.add('<br/>') self.handle_python_script_test(top) top.add('<br/>') self.handle_sidebar_clear(top) return top
def get_display(self): top = DivWdg() top.add_class("ad_input_top") name = self.get_name() text = TextWdg(self.get_input_name()) # get the login sobject = self.get_current_sobject() client = sobject.get_value("contact_name") print "client: ", client if client: login_sobj = Login.get_by_code(client) else: login_sobj = Environment.get_login() # build the display_name login = login_sobj.get_value("login") display_name = login_sobj.get_value("display_name") if not display_name: display_name = "%s %s" % (user.get('first_name'), user.get('last_name')) display_name = display_name.replace('"', "'") print "login: "******"spt_ad_input") if login: hidden.set_value(login) top.add(hidden) # copy over some options #text.set_options( self.options.copy() ) if login: text.set_value(display_name) text.set_option("read_only", "true") text.add_class("spt_ad_display") top.add(text) top.add(" ") groups_str = self.get_option("groups_allowed_to_search") if groups_str: stmt = 'groups_list = %s' % groups_str exec stmt else: groups_list = None allow_search = True if groups_list: allow_search = False login_in_group_list = Search.eval("@SOBJECT(sthpw/login_in_group['login','=','%s'])" % login) for login_in_group in login_in_group_list: group = login_in_group.get_value("login_group") if group in groups_list: allow_search = True break if login == 'admin': allow_search = True if allow_search: button = IconButtonWdg('Search for User', IconWdg.USER) #button = ButtonWdg() button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent('.ad_input_top'); var content = top.getElement('.ad_input_content'); spt.toggle_show_hide(content); ''' } ) top.add(button) ad_top = DivWdg() ad_top.add_class("ad_input_content") ad_top.add_style("display: none") ad_top.add_style("position: absolute") ad_top.add_style("background: #222") ad_top.add_style("min-width: 300px") ad_top.add_style("border: solid 1px #000") ad_top.add_style("padding: 20px") cbjs_action = ''' var value = bvr.src_el.getAttribute('spt_input_value'); var display_value = bvr.src_el.getAttribute('spt_display_value'); var phone_number = bvr.src_el.getAttribute('spt_phone_number'); var email = bvr.src_el.getAttribute('spt_mail'); var top = bvr.src_el.getParent('.ad_input_top'); var content = top.getElement('.ad_input_content'); var input = top.getElement('.spt_ad_input'); var display = top.getElement('.spt_ad_display'); input.value = value; display.value = display_value; server = TacticServerStub.get() server.execute_cmd("tactic.active_directory.ADCacheUserCbk", {login: value}) spt.toggle_show_hide(content); ''' ad_search_wdg = ADSearchWdg(cbjs_action=cbjs_action) ad_top.add(ad_search_wdg) top.add(ad_top) return top
def get_display(self): top = DivWdg() top.add_class("ad_input_top") name = self.get_name() text = TextWdg(self.get_input_name()) # get the login sobject = self.get_current_sobject() client = sobject.get_value("contact_name") print "client: ", client if client: login_sobj = Login.get_by_code(client) else: login_sobj = Environment.get_login() # build the display_name login = login_sobj.get_value("login") display_name = login_sobj.get_value("display_name") if not display_name: display_name = "%s %s" % (user.get('first_name'), user.get('last_name')) display_name = display_name.replace('"', "'") print "login: "******"spt_ad_input") if login: hidden.set_value(login) top.add(hidden) # copy over some options #text.set_options( self.options.copy() ) if login: text.set_value(display_name) text.set_option("read_only", "true") text.add_class("spt_ad_display") top.add(text) top.add(" ") groups_str = self.get_option("groups_allowed_to_search") if groups_str: stmt = 'groups_list = %s' % groups_str exec stmt else: groups_list = None allow_search = True if groups_list: allow_search = False login_in_group_list = Search.eval( "@SOBJECT(sthpw/login_in_group['login','=','%s'])" % login) for login_in_group in login_in_group_list: group = login_in_group.get_value("login_group") if group in groups_list: allow_search = True break if login == 'admin': allow_search = True if allow_search: button = IconButtonWdg('Search for User', IconWdg.USER) #button = ButtonWdg() button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent('.ad_input_top'); var content = top.getElement('.ad_input_content'); spt.toggle_show_hide(content); ''' }) top.add(button) ad_top = DivWdg() ad_top.add_class("ad_input_content") ad_top.add_style("display: none") ad_top.add_style("position: absolute") ad_top.add_style("background: #222") ad_top.add_style("min-width: 300px") ad_top.add_style("border: solid 1px #000") ad_top.add_style("padding: 20px") cbjs_action = ''' var value = bvr.src_el.getAttribute('spt_input_value'); var display_value = bvr.src_el.getAttribute('spt_display_value'); var phone_number = bvr.src_el.getAttribute('spt_phone_number'); var email = bvr.src_el.getAttribute('spt_mail'); var top = bvr.src_el.getParent('.ad_input_top'); var content = top.getElement('.ad_input_content'); var input = top.getElement('.spt_ad_input'); var display = top.getElement('.spt_ad_display'); input.value = value; display.value = display_value; server = TacticServerStub.get() server.execute_cmd("tactic.active_directory.ADCacheUserCbk", {login: value}) spt.toggle_show_hide(content); ''' ad_search_wdg = ADSearchWdg(cbjs_action=cbjs_action) ad_top.add(ad_search_wdg) top.add(ad_top) return top
# All Rights Reserved # # PROPRIETARY INFORMATION. This software is proprietary to # Southpaw Technology, and is not to be reproduced, transmitted, # or disclosed in any way without written permission. # # # import sys import os import tacticenv from pyasm.security import Batch, Login from pyasm.search import Search Batch() search = Search("sthpw/login") search.add_filter("login", "admin") admin = search.get_sobject() password = Login.get_default_encrypted_password() admin.set_value("password", password) admin.commit() print "Successfully reset admin password. You will be prompted to change it on startup of TACTIC." raw_input()
class ADAuthenticate(Authenticate): '''Test authenticate mechanism which caches user info''' def __init__(my): my.ad_exists = True if os.name != 'nt': my.ad_exists = False my.groups = set() my.data = {} my.tactic_groups = [] def get_mode(my): return 'cache' def verify(my, login_name, password): if login_name.find("\\") != -1: domain, base_login_name = login_name.split("\\") else: base_login_name = login_name domain = None # confirm that there is a domain present if required require_domain = Config.get_value("active_directory", "require_domain") domain_component = Config.get_value("active_directory", "domain_component") script_path = Config.get_value("active_directory", "allow_script") if script_path: flag = False try: from tactic.command import PythonCmd from pyasm.command import Command kwargs = {'login': login_name} cmd = PythonCmd(script_path=script_path, **kwargs) #flag = Command.execute_cmd(cmd) flag = cmd.execute() except Exception, e: print e raise if flag != True: return False if require_domain == "true" and not domain: raise SecurityException("Domain Selection Required") # skip authentication if ad does not exist if not my.ad_exists: print "WARNING: Active directory does not exist ... skipping verify" return True ad_connect = ADConnect() ad_connect.set_user(base_login_name) ad_connect.set_password(password) info = ad_connect.lookup() try: lookup_domain = info[1] except: lookup_domain = '' # lookup domain takes prescedence if lookup_domain: domain = lookup_domain #ad_connect.set_domain(lookup_domain) elif domain: pass #ad_connect.set_domain(domain) domain = "%s%s" % (domain, domain_component) ad_connect.set_domain(domain) #ad_connect.set_user(base_login_name) #ad_connect.set_password(password) is_logged_in = ad_connect.logon() # preload data for further use later with original full login_name if is_logged_in: my.load_user_data(base_login_name, domain) else: # If AD authentication fails, attempt login via Tactic database+ # (Only allow login for external users) login = Login.get_by_login(base_login_name) if login and login.get_value('location', no_exception=True) == 'external': auth_class = "pyasm.security.TacticAuthenticate" authenticate = Common.create_from_class_path(auth_class) is_authenticated = authenticate.verify(base_login_name, password) if is_authenticated == True: return True return is_logged_in