1
2
3
4
5
6
7
8
9
10
11
12
13 """ Portal class
14
15 $Id: ZentinelPortal.py,v 1.17 2004/04/08 15:35:25 edahl Exp $
16 """
17
18 import urllib, urlparse
19 import re
20
21 import Globals
22
23 from zExceptions import Redirect
24 from AccessControl import getSecurityManager, ClassSecurityInfo
25
26 from Products.Sessions.BrowserIdManager import constructBrowserIdManager
27 from Products.Sessions.SessionDataManager import constructSessionDataManager
28
29 from Products.CMFCore.PortalObject import PortalObjectBase
30 from Products.CMFCore.utils import getToolByName
31
32 from Products.ZenUtils import Security, Time
33 from Products.ZenUtils.Utils import prepId
34
35 from ZenossSecurity import *
36
37 from Products.AdvancedQuery import MatchGlob, Eq, Or
38
40 """
41 The *only* function this class should have is to help in the setup
42 of a new ZentinelPortal. It should not assist in the functionality at all.
43 """
44 meta_type = 'ZentinelPortal'
45
46 _properties = (
47 {'id':'title', 'type':'string'},
48 {'id':'description', 'type':'text'},
49 )
50 title = ''
51 description = ''
52
53 security = ClassSecurityInfo()
54
57
60
61
62 security.declareProtected(ZEN_COMMON, 'searchDevices')
64 """Returns the concatenation of a device name, ip and mac
65 search on the list of devices.
66 """
67 zcatalog = self.dmd.Devices.deviceSearch
68 glob = queryString.rstrip('*') + '*'
69 glob = MatchGlob('id', glob)
70 query = Or(glob, Eq('getDeviceIp', queryString))
71 brains = zcatalog.evalAdvancedQuery(query)
72 if REQUEST and len(brains) == 1:
73 raise Redirect(urllib.quote(brains[0].getPrimaryId))
74 brains += self.dmd.Networks.ipSearch.evalAdvancedQuery(glob)
75 return [ b.getObject() for b in brains ]
76
77 security.declareProtected(ZEN_COMMON, 'searchDevices')
97
98 security.declareProtected(ZEN_COMMON, 'dotNetProxy')
99 - def dotNetProxy(self, path='', params={}, REQUEST=None):
100 """
101 Logs in to Zenoss.net using the user's credentials and retrieves data,
102 thereby putting it in the current domain
103 """
104 session = self.dmd.ZenUsers.getUserSettings().getDotNetSession()
105 response = session.open(path.lstrip('/'))
106 if response:
107 data = response.read()
108 headers = response.headers.dict
109 url = response.geturl()
110 response.close()
111 else:
112 return response
113 localbase = 'http://localhost:8080/zport/dotNetProxy?path='
114 allrefs = re.compile(r"""(href *= *["']|src *= *["'])(.*?)(["'])""")
115 proxyrefs = re.compile(
116 r"""((<a[^<>]*?|location\.)href *= *["'])(.*?)(['"])""")
117
118 def mod_rewrite(matchobj):
119 start, path, end = matchobj.groups()
120 if not path.startswith('javascript'):
121 path = urlparse.urljoin(url, path)
122 return start + path + end
123
124 def make_proxied(matchobj):
125 start, trash, path, end = matchobj.groups()
126 path = path.replace(session.base_url, localbase)
127 return start + path + end
128
129 data = re.sub(allrefs, mod_rewrite, data)
130 data = re.sub(proxyrefs, make_proxied, data)
131 for header in headers:
132 REQUEST.RESPONSE.setHeader(header, headers[header])
133 return data
134
142
143
145 """Check to see of a user has a role.
146 """
147 if obj is None: obj = self
148 user = getSecurityManager().getUser()
149 if user: return user.has_role(role, obj)
150
151
153 """Check to see of a user has a permission.
154 """
155 if obj is None: obj = self
156 user = getSecurityManager().getUser()
157 if user: return user.has_permission(perm, obj)
158
161
163 """
164 On first run, log us in as admin automatically.
165
166 This is done via a proxy form with hidden fields, so that the browser
167 doesn't ask to save the password (which will be changed on the next
168 screen).
169 """
170 if not self.dmd._rq:
171 return """
172 <form id="_proxy_form">
173 <input type="hidden" name="__ac_name"/>
174 <input type="hidden" name="__ac_password"/>
175 </form>
176 <script>
177 var origform=document.forms[0];
178 var newform = document.getElementById('_proxy_form');
179 newform.__ac_name.value = 'admin';
180 newform.__ac_password.value = 'zenoss';
181 newform.action = origform.action;
182 newform.method = origform.method;
183 newform.submit()
184 </script>
185 """
186
187
188 Globals.InitializeClass(ZentinelPortal)
189
190
192
193 klass = ZentinelPortal
194
199
200
202 p.manage_addProduct['MailHost'].manage_addMailHost(
203 'MailHost', smtp_host='localhost')
204
205
210
211
217
218
222
223
225
226 mp = p.manage_permission
227 mp(ZEN_CHANGE_SETTINGS,[ZEN_MANAGER_ROLE, OWNER_ROLE, MANAGER_ROLE,], 1)
228 mp(ZEN_CHANGE_DEVICE, [ZEN_MANAGER_ROLE, OWNER_ROLE, MANAGER_ROLE,], 1)
229 mp(ZEN_MANAGE_DMD, [ZEN_MANAGER_ROLE, OWNER_ROLE, MANAGER_ROLE,], 1)
230 mp(ZEN_DELETE, [ZEN_MANAGER_ROLE, OWNER_ROLE, MANAGER_ROLE,], 1)
231 mp(ZEN_ADD, [ZEN_MANAGER_ROLE, OWNER_ROLE, MANAGER_ROLE,], 1)
232 mp(ZEN_VIEW, [ZEN_USER_ROLE, ZEN_MANAGER_ROLE,
233 MANAGER_ROLE, OWNER_ROLE])
234 mp(ZEN_COMMON, ["Authenticated", ZEN_USER_ROLE, ZEN_MANAGER_ROLE,
235 MANAGER_ROLE, OWNER_ROLE], 1)
236
237
238 mp(ZEN_MANAGE_EVENTMANAGER,
239 [ZEN_MANAGER_ROLE, OWNER_ROLE, MANAGER_ROLE,], 1)
240 mp(ZEN_MANAGE_EVENTS,
241 [ZEN_MANAGER_ROLE, OWNER_ROLE, MANAGER_ROLE,], 1)
242 mp(ZEN_SEND_EVENTS,
243 [ZEN_MANAGER_ROLE, OWNER_ROLE, MANAGER_ROLE,], 1)
244
245 mp(ZEN_CHANGE_ALERTING_RULES,
246 [ZEN_MANAGER_ROLE, MANAGER_ROLE, OWNER_ROLE], 1)
247 mp(ZEN_CHANGE_ADMIN_OBJECTS, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1)
248 mp(ZEN_CHANGE_EVENT_VIEWS, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1)
249 mp(ZEN_ADMIN_DEVICE, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1)
250 mp(ZEN_MANAGE_DEVICE, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1)
251 mp(ZEN_ZPROPERTIES_EDIT, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1)
252 mp(ZEN_ZPROPERTIES_VIEW,
253 [ZEN_MANAGER_ROLE, MANAGER_ROLE, ZEN_USER_ROLE], 1)
254 mp(ZEN_EDIT_LOCAL_TEMPLATES, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1)
255 mp(ZEN_RUN_COMMANDS, [ZEN_USER_ROLE, ZEN_MANAGER_ROLE, MANAGER_ROLE], 1)
256 mp(ZEN_DEFINE_COMMANDS_EDIT, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1)
257 mp(ZEN_DEFINE_COMMANDS_VIEW,
258 [ZEN_MANAGER_ROLE, MANAGER_ROLE, ZEN_USER_ROLE], 1)
259 mp(ZEN_MAINTENANCE_WINDOW_EDIT, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1)
260 mp(ZEN_MAINTENANCE_WINDOW_VIEW,
261 [ZEN_MANAGER_ROLE, MANAGER_ROLE, ZEN_USER_ROLE], 1)
262 mp(ZEN_ADMINISTRATORS_EDIT, [ZEN_MANAGER_ROLE, MANAGER_ROLE], 1)
263 mp(ZEN_ADMINISTRATORS_VIEW,
264 [ZEN_MANAGER_ROLE, MANAGER_ROLE, ZEN_USER_ROLE], 1)
265
266
267
269 from Products.CMFCore.DirectoryView import addDirectoryViews
270 ps = getToolByName(p, 'portal_skins')
271 addDirectoryViews(ps, 'skins', globals())
272 ps.manage_addProduct['OFSP'].manage_addFolder(id='custom')
273 ps.addSkinSelection('Basic', "custom, zenmodel", make_default=1)
274 p.setupCurrentSkin()
275
276
278 """build a session manager and brower id manager for zport"""
279 constructBrowserIdManager(p, cookiepath="/zport")
280 constructSessionDataManager(p, "session_data_manager",
281 title="Session Data Manager",
282 path='/temp_folder/session_data')
283
284
285 - def setup(self, p, create_userfolder):
295
296
297 - def create(self, parent, id, create_userfolder):
305
306
307 - def setupDefaultProperties(self, p, title, description,
308 email_from_address, email_from_name,
309 validate_email,
310 ):
316
317
318 manage_addZentinelPortal = Globals.HTMLFile('dtml/addPortal', globals())
319 manage_addZentinelPortal.__name__ = 'addPortal'
320
321 -def manage_addZentinelPortal(obj, id="zport", title='Zentinel Portal',
322 description='',
323 create_userfolder=True,
324 email_from_address='postmaster@localhost',
325 email_from_name='Portal Administrator',
326 validate_email=0, RESPONSE=None):
339