~usmteam/usm/usm_directory

« back to all changes in this revision

Viewing changes to usr/share/usm/plugins/usm_directory/usm_directory.py

  • Committer: Oliver M
  • Date: 2009-03-06 09:22:16 UTC
  • Revision ID: oly@digitaloctave.com-20090306092216-mv74wmnaq6w2kczd
apparmor fix, can connect to directory and list and view groups config generation has changed and will change further most likely, as slapd.conf is becoming obsolete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
#Ubuntu Server Manager
3
 
#Copyright (C) 2007 usmteam
4
 
#
5
 
#This file is part of Ubuntu Server Manager 
6
 
#
7
 
#This program is free software; you can redistribute it and/or
8
 
#modify it under the terms of the GNU General Public License
9
 
#as published by the Free Software Foundation; either version 2
10
 
#of the License, or (at your option) any later version.
11
 
#
12
 
#This program is distributed in the hope that it will be useful,
13
 
#but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
#GNU General Public License for more details.
16
 
#
17
 
#You should have received a copy of the GNU General Public License
18
 
#along with this program; if not, write to the Free Software
19
 
#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
 
 
21
 
import xml.dom.minidom 
22
 
import cgitb; cgitb.enable()
23
 
import sys
24
 
import os
25
 
import commands
26
 
import cgi
27
 
 
28
 
from lib.lib_xml_data_form import xml_form
29
 
from lib.lib_xml_data_form import validate_form
30
 
from lib.lib_xml_data_form import config
31
 
from lib.lib_plugins import plugins
32
 
from usmroot import *
33
 
 
34
 
 
35
 
#slapd -d 1
36
 
#ldapsearch -x -s base (objectclass=*) namingContexts
37
 
 
38
 
class plugin(plugins):
39
 
    plugin_name="usm_directory"
40
 
    plugin_fold="usm_directory"
41
 
    plugin_form="usm_directory.xml"
42
 
    def __init__(self):
43
 
        plugins.__init__(self)  #run __init__ method from plugins class instead of overridding
44
 
        
45
 
        self.hostname=commands.getstatusoutput("hostname")[1]
46
 
        
47
 
        xmlform=xml_form(self.path+"core/objects/server.xml")
48
 
        self.server_tagset={}
49
 
        self.server_tagset["basenode"]="server"
50
 
        self.server_tagset["tagdepth"]="core",
51
 
        self.server_tagset["config"]=xmlform.read("settings")
52
 
        self.server_config=config(self.web_page,self.server_tagset,self.profilerootpath+"core/server.xml","server")
53
 
                
54
 
        #xmlform=xml_form(self.pluginpath+self.plugin_form)
55
 
        #self.tagset3={}
56
 
        #self.tagset3["basenode"]="shares"
57
 
        #self.tagset3["tagdepth"]="share",
58
 
        #self.tagset3["config"]=xmlform.read("share")
59
 
 
60
 
    def index(self,form,web_page,globals={}):
61
 
        htmout=""
62
 
        htmout+=plugins.index(self,form,web_page)
63
 
        if self.web_page["subpage"]=="restart":
64
 
            htmout+=self.page_restart()
65
 
        if not self.check_process("slapd"):
66
 
            self.notify+=self.web.notifybox("The slapd directopry Service is not running, try hitting restart icon above.")
67
 
 
68
 
        return self.web.notify(self.notify)+htmout
69
 
 
70
 
    def toolbar(self):
71
 
        tbar=self.web.tool_icon("index.py?Page="+self.web_page["page"]+"&amp;SubPage=help","images/icons/tango/32x32/apps/help-browser.png","<b>Action: Help</b><br><i>Description: Help Documentation for this plugin module.</i>")
72
 
        tbar+=self.web.tool_icon("index.py?Page="+self.web_page["page"]+"&amp;SubPage=form_share","images/icons/tango/32x32/places/folder-remote.png","<b>Action: New Share</b><br><i>Description: Add New Shared Folder</i>")
73
 
        tbar+=self.web.tool_icon("index.py?Page="+self.web_page["page"]+"&amp;SubPage=log","images/icons/tango/32x32/categories/preferences-desktop.png","<b>Action: Log files</b><br><i>Description: View your samba log files.</i>")
74
 
        tbar+=self.web.tool_icon("index.py?Page="+self.web_page["page"]+"&amp;SubPage=restart","images/icons/tango/32x32/actions/view-refresh.png","<b>Action: Restart</b><br><i>Description: Restart samba service</i>")
75
 
        return self.web.tool_bar("Shared Network Folders Configuration",tbar)
76
 
        
77
 
    def page_default(self):#if any zones exist display them in a table
78
 
        htmout=self.toolbar()
79
 
        style=""
80
 
        #htmout+=self.web.table_start("Shared Network Folders",("N","Folder","Path","Comments","Modify"))
81
 
        #count = 1
82
 
        #for share in self.config.get_list(self.tagset3):
83
 
        #    path=(self.tagset3["tagdepth"][0],share),
84
 
        #    conf=self.config.get_config_dict(path,self.tagset3)
85
 
        #    style=self.web.switch_style(style,"tabrow1","tabrow2")
86
 
        #    htmout+="<tr class=\""+style+"\"><td >" + str(count) + "</td>"
87
 
        #    htmout+="<td><a href=\"index.py?Page=Shares&amp;SubPage=form_share&amp;name="+ str(share) +"\">" + str(share) + "</a></td>"
88
 
        #    htmout+="<td>" + conf["path"] + "</td>"
89
 
        #    htmout+="<td>" + conf["comments"] + "</td>"
90
 
        #    htmout+="<td>"
91
 
        #    htmout+=self.web.but_img("index.py?Page="+self.web_page["page"]+"&amp;SubPage=form_share&amp;name="+ str(share),"/images/icons/silk/icons/table_edit.png","Edit")
92
 
        #    htmout+=self.web.but_img_confirm("index.py?Page="+self.web_page["page"]+"&amp;SubPage=del_share&amp;name="+ share,"/images/icons/silk/icons/delete.png","Are You Sure you wish to remove this share, this will not remove your files and will only disable the sharing of this folder ?","Del")
93
 
        #    htmout+="</td></tr>"
94
 
        #    count+=1
95
 
        #htmout+=self.web.table_end()+"<br />"
96
 
        return htmout
97
 
 
98
 
    def page_broadcast(self):
99
 
        xml="<service name=\"shares\">"
100
 
        xml+="<win exe=\"explorer.exe\">\\\\</win>"
101
 
        xml+="<gnome exe=\"nautilus\">smb://</gnome>"
102
 
        xml+="<kde></kde>"
103
 
        self.load_config_file(self.profilepath,"customshares.xml","shares")
104
 
        items = self.doc.getSubTagAttrib(self.tagset3["tagdepth"][0])
105
 
        for item  in items:
106
 
            xml+="<item name=\""+item+"\">"+item+"</item>"
107
 
        xml+="</service>"
108
 
        return xml
109
 
    
110
 
    def get_password(self):
111
 
        fp = open(self.path+"security/users/.usmpasswd")
112
 
        password=""
113
 
        for line in fp.readlines():
114
 
            sp=line.split(":")
115
 
            if sp[0]=="usmadmin":
116
 
                password=sp[2]
117
 
        fp.close()
118
 
        return password
119
 
        
120
 
    def generateconfig(self):#if any zones exist display them in a table
121
 
        path=(self.server_tagset["tagdepth"][0],self.hostname),
122
 
        conf=self.server_config.get_config_dict(path,self.server_tagset)
123
 
        domain=""
124
 
        for dc in conf["domain"].split("."):
125
 
            domain+="dc="+dc+","
126
 
        domain=domain.rstrip(",")
127
 
        conf=""
128
 
        conf+="include         /etc/openldap/schema/core.schema\n"
129
 
        conf+="include         /etc/openldap/schema/cosine.schema\n"
130
 
        conf+="include         /etc/openldap/schema/inetorgperson.schema\n"
131
 
        conf+="include         /etc/openldap/schema/nis.schema\n\n"
132
 
 
133
 
        conf+="allow bind_v2\n"
134
 
        conf+="pidfile         /var/run/openldap/slapd.pid\n"
135
 
        conf+="argsfile        /var/run/openldap/slapd.args\n"
136
 
        conf+="loglevel        none\n"
137
 
        conf+="modulepath      /usr/lib/openldap/openldap\n\n"
138
 
        
139
 
        conf+="# Save the time that the entry gets modified, for database #1\n"
140
 
        conf+="lastmod         on\n\n"
141
 
 
142
 
 
143
 
        conf+="access to attrs=userPassword\n"
144
 
        conf+="by dn=\"uid=root,ou=People,"+domain+"\" write\n"
145
 
        conf+="by dn=\"cn=Manager,"+domain+"\" write\n"
146
 
        conf+="by anonymous auth\n"
147
 
        conf+="by self write\n"
148
 
        conf+="by * none\n\n"
149
 
 
150
 
        conf+="# The admin dn has full write access, everyone else\n"
151
 
        conf+="# can read everything.\n"
152
 
        conf+="access to dn.base=\"\" by * read\n"
153
 
        conf+="access to *\n"
154
 
        conf+="by dn=\"cn=Manager,"+domain+"\" write\n"
155
 
        conf+="by * read\n\n"
156
 
 
157
 
        conf+="database        bdb\n"
158
 
        conf+="suffix          \""+domain+"\"\n"
159
 
        conf+="rootdn          \"cn=Manager,"+domain+"\"\n"
160
 
        conf+="rootpw          {MD5}"+self.get_password()+"\n\n"
161
 
 
162
 
        conf+="directory       /var/lib/openldap-data\n"
163
 
        conf+="index   objectClass     eq\n\n"
164
 
        print "regenerate new config"
165
 
        print conf
166
 
        self.save_config("/etc/ldap/slapd.conf",conf)
167
 
        return conf+"\n"
168
 
 
169
 
    def page_restart(self):
170
 
        htm=self.generateconfig()
171
 
        cmd.write("restart|slapd")
172
 
        return htm