3
#Copyright (C) 2007 usmteam
5
#This file is part of Ubuntu Server Manager
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.
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.
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.
21
import xml.dom.minidom
22
import cgitb; cgitb.enable()
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
36
#ldapsearch -x -s base (objectclass=*) namingContexts
38
class plugin(plugins):
39
plugin_name="usm_directory"
40
plugin_fold="usm_directory"
41
plugin_form="usm_directory.xml"
43
plugins.__init__(self) #run __init__ method from plugins class instead of overridding
45
self.hostname=commands.getstatusoutput("hostname")[1]
47
xmlform=xml_form(self.path+"core/objects/server.xml")
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")
54
#xmlform=xml_form(self.pluginpath+self.plugin_form)
56
#self.tagset3["basenode"]="shares"
57
#self.tagset3["tagdepth"]="share",
58
#self.tagset3["config"]=xmlform.read("share")
60
def index(self,form,web_page,globals={}):
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.")
68
return self.web.notify(self.notify)+htmout
71
tbar=self.web.tool_icon("index.py?Page="+self.web_page["page"]+"&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"]+"&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"]+"&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"]+"&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)
77
def page_default(self):#if any zones exist display them in a table
80
#htmout+=self.web.table_start("Shared Network Folders",("N","Folder","Path","Comments","Modify"))
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&SubPage=form_share&name="+ str(share) +"\">" + str(share) + "</a></td>"
88
# htmout+="<td>" + conf["path"] + "</td>"
89
# htmout+="<td>" + conf["comments"] + "</td>"
91
# htmout+=self.web.but_img("index.py?Page="+self.web_page["page"]+"&SubPage=form_share&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"]+"&SubPage=del_share&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>"
95
#htmout+=self.web.table_end()+"<br />"
98
def page_broadcast(self):
99
xml="<service name=\"shares\">"
100
xml+="<win exe=\"explorer.exe\">\\\\</win>"
101
xml+="<gnome exe=\"nautilus\">smb://</gnome>"
103
self.load_config_file(self.profilepath,"customshares.xml","shares")
104
items = self.doc.getSubTagAttrib(self.tagset3["tagdepth"][0])
106
xml+="<item name=\""+item+"\">"+item+"</item>"
110
def get_password(self):
111
fp = open(self.path+"security/users/.usmpasswd")
113
for line in fp.readlines():
115
if sp[0]=="usmadmin":
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)
124
for dc in conf["domain"].split("."):
126
domain=domain.rstrip(",")
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"
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"
139
conf+="# Save the time that the entry gets modified, for database #1\n"
140
conf+="lastmod on\n\n"
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"
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"
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"
162
conf+="directory /var/lib/openldap-data\n"
163
conf+="index objectClass eq\n\n"
164
print "regenerate new config"
166
self.save_config("/etc/ldap/slapd.conf",conf)
169
def page_restart(self):
170
htm=self.generateconfig()
171
cmd.write("restart|slapd")