示例#1
0
文件: add.py 项目: COMU/pyldapadmin
def index(req):
    server=server_info.get_info(req)
    language=gettext.translation('messages',dir, languages=[server[4]])
    _=language.ugettext
    ldap_server = ldap.initialize('ldap://'+server[2])
    ldap_server.protocol_version = ldap.VERSION3
    page=template_page.page_header()+'<title>'+_('adding...')+'</title></head><body>'
    try:
        ldap_server.bind_s(server[0],server[1])
        ldap_schema_object=attr.get_att(server[0],server[1],server[2])
        ldap_server.unbind()
        Schema=ldap_schema_object.keys()
        Schema.sort(key=str.lower)
        page+='<form action="./add_user.py" method="post"><p>'
        page+='<select multiple="multiple" name="objectclass_menu" size="15" >'
        for key in Schema:
            if (ldap_schema_object[key]["KIND"] == 'AUXILIARY'):
                page+='<option value="'+key+'">'+key+'</option>'
            elif(ldap_schema_object[key]["KIND"] == 'STRUCTURAL'):
                page+='<option value="'+key+'" style="font-weight:bold">'+key+'</option>'
        page+='</select><input type="submit" value="'+_('continue')+'" /></p>'
        page+='</form></body></html>'
        return page
    except:
        return template_page.error(server[4])
示例#2
0
def searching(req):
    server=server_info.get_info(req)
    language=gettext.translation('messages',dir, languages=[server[4]])
    _=language.ugettext
    ldap_server = ldap.initialize('ldap://'+server[2])
    ldap_server.protocol_version = ldap.VERSION3
    page = template_page.page_header()+'<title>'+_('searching')+'...</title></head><body>'
    try:
        ldap_server.bind_s(server[0],server[1])
        att = req.form['att']
        att = att.split(',')
        scope = req.form['scope']
        base = escape(req.form['base'])
        filter = escape(req.form['filter'])
        if(scope == 'ldap.SCOPE_SUBTREE' ):
            result = ldap_server.search_s(base ,ldap.SCOPE_SUBTREE, filter, att)
        elif(scope == 'ldap.SCOPE_ONELEVEL' ):
            result = ldap_server.search_s(base ,ldap.SCOPE_ONELEVEL, filter, att)
        elif(scope == 'ldap.SCOPE_BASE'):
            result = ldap_server.search_s(base ,ldap.SCOPE_BASE, filter, att)
        for result in result:
            page+="<p><b>%s</b>:" %(str(result[0]))
            page+="<br/>"
            for key in result[1].keys():
                page+="%s:<br/>" %(key)
                for att_value in result[1][key]:
                    page+='<input type="text" value="%s"/> ' %(att_value)
                page+="<br/>"
            page+="</p>"
        page+='<p><a href="../login.py">'+_('back')+'</a></p>'
        page+='</body></html>'
        ldap_server.unbind()
        return page
    except:
        return template_page.error(server[4])
示例#3
0
def index(req):
    server=server_info.get_info(req)
    language=gettext.translation('messages',dir, languages=[server[4]])
    _=language.ugettext
    ldap_server = ldap.initialize('ldap://'+server[2])
    ldap_server.protocol_version = ldap.VERSION3
    page=template_page.page_header()+'<title>'+_('adding')+'</title></head><body>'
    list=req.form.keys()
    record=()
    obje=[]
    record_obje=[]
    record_att_value=()
    record_att=[]
    record+=('objectclass',)
    for att in list:
        if ( match('objectclass',att)):
            obje.append(cgi.escape(att.split('objectclass')[1]))
        else:
            if(att == 'rdn'):
                rdn=cgi.escape(req.form[att])
            else:
                try:
                    if( cgi.escape(req.form[att]) != ''):
                        record_att_value=(cgi.escape(att),[cgi.escape(req.form[att])])
                        record_att.append(record_att_value)
                except:
                    return req.form[att]
    record+=(obje,)
    record_obje.append(record)
    for final_att in record_att:
        record_obje.append(final_att)
    try:
        ldap_server.bind_s(server[0],server[1])
        ldap_server.add_s(rdn,record_obje)
        page+=_('adding successfull complete')+'.<a href="./login.py">'+ _('return')+'</a>'
    except ldap.LDAPError, e:
        if (e.message['desc'] == 'Already exists'):
            return page+'<p><img alt="error" src="./img/error.png"/> '+_('it already there')+' </p><p> '+_('go main')+'<a href="./login.py">'+_('page')+'</a></p></body></html>'
        elif (e.message['info'] == 'no write access to parent'):
            return page+'<p><img alt="error" src="./img/error.png"/>'+_('no write access to parent')+'</p><p>'+_('go main')+' <a href="./login.py">'+_('page')+'</a></p></body></html>'
        return template_page.error(server[4])
示例#4
0
def searching(req):
    server=server_info.get_info(req)
    language=gettext.translation('messages',dir, languages=[server[4]])
    _=language.ugettext
    ldap_server = ldap.initialize('ldap://'+server[2])
    ldap_server.protocol_version = ldap.VERSION3
    page = template_page.page_header()+'<title>'+_('export')+'...</title></head><body>'
    try:
        ldap_server.bind_s(server[0],server[1])
        att = req.form['att']
        att = att.split(',')
        scope = req.form['scope']
        base = escape(req.form['base'])
        filter = escape(req.form['filter'])
        textarea=""
        if(scope == 'ldap.SCOPE_SUBTREE' ):
            result = ldap_server.search_s(base ,ldap.SCOPE_SUBTREE, filter, att)
        elif(scope == 'ldap.SCOPE_ONELEVEL' ):
            result = ldap_server.search_s(base ,ldap.SCOPE_ONELEVEL, filter, att)
        elif(scope == 'ldap.SCOPE_BASE'):
            result = ldap_server.search_s(base ,ldap.SCOPE_BASE, filter, att)
        for result in result:
            textarea+="dn: %s\n" %(str(result[0]))
            textarea+=""
            for key in result[1].keys():
                for att_value in result[1][key]:
                    textarea+='%s: %s\n' %(key,att_value)

            textarea+="\n"
        page+='<textarea cols=40 rows=20 wrap="soft" readonly="readonly">'+textarea+'</textarea>'
        page+='<p><a href="../login.py">'+_('back')+'</a></p>'
        page+='</body></html>'
        ldap_server.unbind()
        return page
    except:
        return template_page.error(server[4])