Menu

[r10232]: / trunk / gui / services / views.py  Maximize  Restore  History

Download this file

283 lines (246 with data), 9.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#+
# Copyright 2010 iXsystems, Inc.
# All rights reserved
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted providing that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
#####################################################################
from django.shortcuts import render
from django.http import HttpResponseRedirect, HttpResponse
from django.utils import simplejson
from django.utils.translation import ugettext as _
from freenasUI.services import models
from freenasUI.middleware.notifier import notifier
def home(request):
try:
activedirectory = models.ActiveDirectory.objects.order_by("-id")[0]
except IndexError:
activedirectory = models.ActiveDirectory.objects.create()
try:
afp = models.AFP.objects.order_by("-id")[0]
except IndexError:
afp = models.AFP.objects.create()
try:
cifs = models.CIFS.objects.order_by("-id")[0]
except IndexError:
cifs = models.CIFS.objects.create()
try:
dynamicdns = models.DynamicDNS.objects.order_by("-id")[0]
except IndexError:
dynamicdns = models.DynamicDNS.objects.create()
try:
nfs = models.NFS.objects.order_by("-id")[0]
except IndexError:
nfs = models.NFS.objects.create()
try:
ftp = models.FTP.objects.order_by("-id")[0]
except IndexError:
ftp = models.FTP.objects.create()
try:
tftp = models.TFTP.objects.order_by("-id")[0]
except IndexError:
tftp = models.TFTP.objects.create()
try:
rsyncd = models.Rsyncd.objects.order_by("-id")[0]
except IndexError:
rsyncd = models.Rsyncd.objects.create()
try:
smart = models.SMART.objects.order_by("-id")[0]
except IndexError:
smart = models.SMART.objects.create()
try:
snmp = models.SNMP.objects.order_by("-id")[0]
except IndexError:
snmp = models.SNMP.objects.create()
try:
ssh = models.SSH.objects.order_by("-id")[0]
except IndexError:
ssh = models.SSH.objects.create()
try:
ups = models.UPS.objects.order_by("-id")[0]
except IndexError:
ups = models.UPS.objects.create()
try:
ldap = models.LDAP.objects.order_by("-id")[0]
except IndexError:
ldap = models.LDAP.objects.create()
plugins = None
try:
if notifier().plugins_jail_configured():
plugins = models.Plugins.objects.order_by("-id")[0]
except IndexError:
plugins = None
srv = models.services.objects.all()
return render(request, 'services/index.html', {
'srv': srv,
'cifs': cifs,
'afp': afp,
'nfs': nfs,
'rsyncd': rsyncd,
#'unison': unison,
'dynamicdns': dynamicdns,
'snmp': snmp,
'ups': ups,
#'webserver': webserver,
#'bittorrent': bittorrent,
'ftp': ftp,
'tftp': tftp,
'smart': smart,
'ssh': ssh,
'activedirectory': activedirectory,
'ldap': ldap,
'plugins': plugins,
})
def iscsi(request):
gconfid = models.iSCSITargetGlobalConfiguration.objects.all().order_by("-id")[0].id
return render(request, 'services/iscsi.html', {
'focus_tab' : request.GET.get('tab',''),
'gconfid': gconfid,
})
def iscsi_targets(request):
target_list = models.iSCSITarget.objects.all()
return render(request, 'services/iscsi_targets.html', {
'target_list': target_list,
})
def iscsi_assoctargets(request, objtype=None):
asctarget_list = models.iSCSITargetToExtent.objects.all()
return render(request, 'services/iscsi_assoctargets.html', {
'asctarget_list': asctarget_list,
})
def iscsi_extents(request, objtype=None):
extent_file_list = models.iSCSITargetExtent.objects.filter(iscsi_target_extent_type='File')
return render(request, 'services/iscsi_extents.html', {
'extent_file_list': extent_file_list,
})
def iscsi_dextents(request):
extent_device_list = models.iSCSITargetExtent.objects.filter(iscsi_target_extent_type__in=['Disk','ZVOL'])
return render(request, 'services/iscsi_dextents.html', {
'extent_device_list': extent_device_list,
})
def iscsi_auth(request):
target_auth_list = models.iSCSITargetAuthCredential.objects.all()
return render(request, 'services/iscsi_auth.html', {
'target_auth_list': target_auth_list,
})
def iscsi_authini(request):
auth_initiator_list = models.iSCSITargetAuthorizedInitiator.objects.all()
return render(request, 'services/iscsi_authini.html', {
'auth_initiator_list': auth_initiator_list,
})
def iscsi_portals(request):
iscsiportal_list = models.iSCSITargetPortal.objects.all()
return render(request, 'services/iscsi_portals.html', {
'iscsiportal_list': iscsiportal_list,
})
def servicesToggleView(request, formname):
form2namemap = {
'cifs_toggle' : 'cifs',
'afp_toggle' : 'afp',
'nfs_toggle' : 'nfs',
'iscsitarget_toggle' : 'iscsitarget',
'dynamicdns_toggle' : 'dynamicdns',
'snmp_toggle' : 'snmp',
'httpd_toggle' : 'httpd',
'ftp_toggle' : 'ftp',
'tftp_toggle' : 'tftp',
'ssh_toggle' : 'ssh',
'activedirectory_toggle' : 'activedirectory',
'ldap_toggle' : 'ldap',
'rsync_toggle' : 'rsync',
'smartd_toggle' : 'smartd',
'ups_toggle' : 'ups',
'plugins_toggle' : 'plugins',
}
changing_service = form2namemap[formname]
if changing_service == "":
raise "Unknown service - Invalid request?"
# Do not allow LDAP and AD to be enabled simultaniously
opposing_service = None
opp_svc_entry = None
if changing_service == "ldap":
opposing_service = "activedirectory"
if changing_service == "activedirectory":
opposing_service = "ldap"
svc_entry = models.services.objects.get(srv_service=changing_service)
if opposing_service:
opp_svc_entry = models.services.objects.get(srv_service=opposing_service)
# Turning things off is always ok
if svc_entry.srv_enable:
svc_entry.srv_enable = 0
else:
if opposing_service and not opp_svc_entry.srv_enable == 1 or not opposing_service:
svc_entry.srv_enable = 1
svc_entry.save()
# forcestop then start to make sure the service is of the same
# status.
if changing_service in ("ldap", "activedirectory"):
if svc_entry.srv_enable == 1:
started = notifier().start(changing_service)
else:
started = notifier().stop(changing_service)
elif changing_service == 'plugins':
if svc_entry.srv_enable == 1:
started = notifier().start('plugins_jail')
else:
started = notifier().stop('plugins_jail')
else:
started = notifier().restart(changing_service)
error = False
message = False
if started is True:
status = 'on'
if svc_entry.srv_enable == 0:
error = True
message = _("The service could not be stopped.")
svc_entry.srv_enable = 1
svc_entry.save()
elif started is False:
status = 'off'
if svc_entry.srv_enable == 1:
error = True
message = _("The service could not be started.")
svc_entry.srv_enable = 0
svc_entry.save()
if changing_service in ('ldap','activedirectory', 'ups'):
notifier().stop(changing_service)
elif changing_service == 'plugins':
notifier().stop('plugins_jail')
else:
if svc_entry.srv_enable == 1:
status ='on'
else:
status = 'off'
data = {
'service': changing_service,
'status': status,
'error': error,
'message': message,
}
return HttpResponse(simplejson.dumps(data), mimetype="application/json")
def rsyncmod(request):
return render(request, "services/rsyncmod.html", {
'rsyncmod_list': models.RsyncMod.objects.all(),
})
def enable(request, svc):
return render(request, "services/enable.html", {
'svc': svc,
})
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.