Esempio n. 1
0
def index(req):
    try:
        if (server_info.get_info(req)== 0):
            server = server_info.set_info(req)
        else:
            server=server_info.get_info(req)
            if server == 0:
                return 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
        ldap_server.bind_s(server[0],server[1])
        ldap_server.unbind()
        return template_page.page_header()+"""<link rel="stylesheet" href="deneme.css" type="text/css" media="screen"/>
        <link rel="SHORTCUT ICON" href="img/icon.ico"/>
        <script type="text/javascript">
        function a(){
        document.getElementById("main_frame").data= "./list.py";
        }
        function b(){
        document.getElementById("main_frame").data= "./delete_user.py";
        }
        function c(){
        document.getElementById("main_frame").data= "./add.py";
        }
        function d(){
        document.getElementById("main_frame").data= "./search.py";
        }
        function e(){
        document.getElementById("main_frame").data= "./export.py";
        }
        function f()
        {
        document.getElementById("main_frame").data="./file_input.py/form"
        }
        </script>
        <title> pyldapadmin</title>
        </head>
        <body>
       <div id="sayfa"><div id="baslik"></div><div id="anabolge"><div id="yanmenu">
       <p><a href="#" onclick="a()" ><img src="./img/list.png" alt=""/><br/>"""+ _('List')+"""</a></p>
       <p><a href="#" onclick="b()"><img src="./img/trash.png" alt=""/><br/>"""+_(' delete')+"""</a></p>
       <p><a href="#" onclick="c()"><img src="./img/user.png" alt=""/><br/>"""+_('add user')+"""</a></p>
       <p><a href="#" onclick="d()"><img src="./img/search.png" alt=""/><br/>"""+_('search')+""" </a></p>
       <p><a href="#" onclick="e()"><img src="./img/download.png" alt=""/><br/>"""+_('export')+""" </a></p>
       <p><a href="#" onclick="f()"><img src="./img/import.png" alt=""/><br/>"""+_('import')+""" </a></p>

       <p><a href="./server_info.py" onclick=""><img src="./img/exit.png" alt=""/><br/>"""+_('logout')+"""</a></p></div>
       <div id="icerik">
           <object id="main_frame" data="login.py"  width="100%" height="400px"></object>
       </div></div><div id="altlik"></div></div>
               </body></html>"""
    except UnboundLocalError,e:
        return template_page.page_header()+'<title>error page</title></head><body><p><img alt="error" src="./img/error.png"/>there is some problem please<a href="./">try</a>again.</p></body></html>'
Esempio n. 2
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>'+_('delete')+'</title></head><body>'
    try:
        ldap_server.bind_s(server[0],server[1])
        base_dn=server[3]
        counter=0
        filter = '(objectclass=*)'
        attrs = ["*"]
        result=ldap_server.search_s(base_dn,ldap.SCOPE_SUBTREE,filter,attrs)
        page+='<form method="post" action="delete_user.py/remove"><div align="left">'
        for dn in result:
            page+='<input type="checkbox" name="remove" value="'+dn[0]+'">'+dn[0]+'<br/>'
            counter+=1
        page+='<input type="submit" value="'+_('submit')+'">'
        page+='</body></html>'
    except:
        page+=_('there is some problem please')+' <a href="./">'+_('try')+'</a>'+_('again')+'.</body></html>'
    ldap_server.unbind()
    return page
Esempio n. 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>'
    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])
Esempio n. 4
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>search page</title></head><body>'
    try:
        ldap_server.bind_s(server[0],server[1])
        base_dn = server[3]
        filter = '(objectclass=*)'
        attrs = ['*']
        res=ldap_server.search_s(base_dn , ldap.SCOPE_SUBTREE, filter, attrs)
        for result in res:
            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 ldap.LDAPError, e:
        return str(e)
Esempio n. 5
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])
Esempio n. 6
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])
Esempio n. 7
0
def remove(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>'+_('delete')+'</title></head><body>'
    ldap_server.bind_s(server[0],server[1])
    try:
        if(str(type(req.form["remove"][0])) == str(mod_python.util.StringField)):
            for list in req.form["remove"]:
                ldap_server.delete_s(list)
                page+=list+'<br/> '+_('removed')+'<br/>'
        else:
            ldap_server.delete_s(req.form["remove"])
            page+=req.form["remove"]+_('removed')+'<br/>'
    except ldap.LDAPError, e:
        page+= e.message['info']
        if (e.message['desc'] == 'No such object'):
            page+=e.message['desc']
        if (e.message['info'] == 'no write access to parent'):
            page +='<br/><img src="../img/gpg.png">'
Esempio n. 8
0
def index(req):
    server = server_info.get_info(req)
    language=gettext.translation('messages',dir, languages=[server[4]])
    _=language.ugettext
    page = template_page.page_header()
    page += '<title>'+_('export')+'</title></head><body>'
    page+='<div>\
    <form method="post" action="export.py/searching">\
    <h3>'+_('export options')+':</h3>\
    <p>ldap server: <b>'+server[2]+'</b></p>\
    <p>'+_('search scope')+':\
    <select name="scope" style="width: 200px">\
        <option selected="selected" value="ldap.SCOPE_SUBTREE">'+_('Sub (entire subtree)')+'</option>\
        <option value="ldap.SCOPE_ONELEVEL">'+_('One (one level beneath base)')+'</option>\
        <option value="ldap.SCOPE_BASE">'+_('Base (base dn only)')+'</option>\
    </select></p>\
    <p>'+_('Show Attributtes')+': <input type="text" name="att" value="*"/></p>\
    <p>'+_('base')+': <input type="text" name="base" value="'+server[3]+'"/></p>\
    <p>'+_('filter')+':<input type="text" name="filter" value="objectClass=*"/></p>\
    <p><input type="submit" value="'+_('search')+'"/></p>\
    </form></div></body></html>'
    return page
Esempio n. 9
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])
Esempio n. 10
0
def upload(req):
   try:
        if (server_info.get_info(req)== 0):
            server = server_info.set_info(req)
        else:
            server=server_info.get_info(req)
            if server == 0:
                return 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
        ldap_server.bind_s(server[0],server[1])
        #ldap_server.unbind()
   except:
        page = template_page.page_header()+'<title>error page</title></head><body><p><img alt="error" src="./img/error.png"/>there is some problem please <a href="./">try</a>again.</p></body></html>'
        server_info.index(req)
        return page
   try: # Windows needs stdio set for binary mode.
      import msvcrt
    #  import ldap.modlist as modlist


      msvcrt.setmode (0, os.O_BINARY) # stdin  = 0
      msvcrt.setmode (1, os.O_BINARY) # stdout = 1
   except ImportError:
      pass
   #try:
    #    if (server_info.get_info(req)== 0):
     #       server = server_info.set_info(req)
    #    else:
      #      server=server_info.get_info(req)
      #      if server == 0:
      #          return 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
       # ldap_server.bind_s(server[0],server[1])

   # A nested FieldStorage instance holds the file
   fileitem = req.form['file']
   add=[]
   error=[]
   temp = 1
   # Test if the file was uploaded
   if fileitem.filename:
       if( fileitem.filename.split(".")[-1].lower() == "txt" or fileitem.filename.split(".")[-1].lower() == "ldif"):
           line=fileitem.file.readline()
           line = line.split(":")
           while (temp):
               attrs = {}
               attrs["objectClass"]=[]
               #return str(type(line))
             #  while (type(line) == 'str' ):
              #     line = fileitem.file.readline()
               if ( line[0] == "dn"):
                   dn = line[1]
                   dn=dn.replace(" ","")
                   add.append( dn)
                   while(1):
                       line=fileitem.file.readline()
                       if not(line):
                            temp = 0
                            break
                       try:
                            line = line.split(":")
                            value = line[1]
                            value=value.replace(" ","")
                            if(line[0] == "dn" ):
                                break
                            if not (line[0] == "objectClass" ):
                                attrs[line[0]]=value.split("\n")[0]
                            else:
                                attrs[line[0]].append(value.split("\n")[0])
                       except:
                            if (line ==''):
                                temp = 0
                                break
                            else:
                                pass
                   try:
                      ldif = modlist.addModlist(attrs)
                      ldap_server.add_s(dn,ldif)
                   except ldap.LDAPError, e:
                       return e
                       error.append(dn)
                      # return "yppl"
               else:
                   line = fileitem.file.readline()
                   line = line.split(":")
            #http://www.grotan.com/ldap/python-ldap-samples.html örnek
           ###okuma bitti 
           #return readed_lines
       else:
          message = 'wrong file type'
Esempio n. 11
0
def index(req):
    att_list=[]
    may_att_list=[]
    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
    ldap_schema_object=attr.get_att(server[0],server[1],server[2])
    page=template_page.page_header()+'<title>'+_('add record')+'</title></head><body><form action="./adding.py" method="post"><h4>objectclass:</h4><p>'
    if(str(type(req.form['objectclass_menu'])) == str(util.StringField)):
        page+='<input type="text" name="objectclass'+req.form['objectclass_menu']+'" value="'+req.form['objectclass_menu']+'"/>'
        att_list.append(ldap_schema_object[str(req.form['objectclass_menu'])]["MUST"])
        may_att_list.append(ldap_schema_object[str(req.form['objectclass_menu'])]["MAY"])
    else:
        for objectc in req.form["objectclass_menu"]:
            page+='<input type="text" name="objectclass'+objectc+'" value="'+objectc+'"/>'
            if (att_list.count(ldap_schema_object[objectc]["MUST"])==0):
                att_list.append(ldap_schema_object[objectc]["MUST"])
            if (may_att_list.count(ldap_schema_object[objectc]["MAY"])==0):
                may_att_list.append(ldap_schema_object[objectc]["MAY"])
    att_list_changer=[]
    page+='</p>'

#in may and must list (may_att_list and att_list) must only one same attribute.. This is the controller...
    for may_list in may_att_list:
        for make_may_list in may_list:
            if (att_list_changer.count(make_may_list)== 0):
                att_list_changer.append(make_may_list)
    if ((att_list_changer.count('uid')== 1) and (att_list_changer.count('userid'))==1 ):
        att_list_changer.remove('userid')
    may_att_list = att_list_changer
    att_list_changer = []
    for may_list in att_list:
        for make_may_list in may_list:
            if (att_list_changer.count(make_may_list) == 0):
                att_list_changer.append(make_may_list)
    if ((att_list_changer.count('uid')== 1) and (att_list_changer.count('userid'))==1 ):
        att_list_changer.remove('userid')
    att_list = att_list_changer
#################################################
    #remove attribute which is in may list and must list. This attribute is in only must list
    for may_list in att_list:
        if (may_att_list.count(may_list)):
            may_att_list.remove(may_list)
################################################
    page+='<p>'+_('where i put this rec rd')+':<input type="text" name="rdn"/></p>'
    if(type(att_list) == list ):
        page+="<h2>"+_('Required Attributes')+"</h2>"
        for att in att_list:
                page+='<p>'+str(att)+':<input type="text" name="'+str(att)+'"/></p>'
        page+='<h2>'+_('Optional Attributes')+'</h2>'
       # for counter in range(len(may_att_list)):
        for att in may_att_list:
                if (att == "userPassword"):
                    page+='<p>'+str(att)+':<input type="password" name="'+str(att)+'"/></p>'
                else:
                    page+='<p>'+str(att)+':<input type="text" name="'+str(att)+'"/></p>'
    else:
        pass
    page+='<p><input type="submit" value="'+_('send')+'"/></p>'
    page+="</form></body></html>"
    return page