def delete_iscsi_lun(request): return_dict = {} try: if 'target_name' not in request.REQUEST: raise Exception("Malformed request. No target specified. Please use the menus.") if 'store' not in request.REQUEST: raise Exception("Malformed request. No LUN specified. Please use the menus.") store = request.REQUEST['store'] target_name = request.REQUEST['target_name'] if request.method == "GET": return_dict["target_name"] = target_name return_dict["store"] = store return django.shortcuts.render_to_response("delete_iscsi_lun_conf.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: ret, err = iscsi_stgt.delete_lun(target_name, store) if not ret: if err: raise Exception(err) else: raise Exception("Unknown error.") audit_str = "Deleted ISCSI LUN %s from target %s"%(store, target_name) url = '/view_iscsi_targets?action=lun_deleted' audit.audit("delete_iscsi_lun", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect(url) except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Remove an ISCSI LUN' return_dict['tab'] = 'view_iscsi_targets_tab' return_dict["error"] = 'Error removing an ISCSI LUN' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_cifs_share(request): return_dict = {} try: if request.method == "GET": #Return the conf page share_id = request.GET["share_id"] name = request.GET["name"] return_dict["share_id"] = share_id return_dict["name"] = name return django.shortcuts.render_to_response("delete_cifs_share_conf.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: share_id = request.POST["share_id"] name = request.POST["name"] #logger.debug("Delete share request for name %s"%name) ret, err = cifs_common.delete_share(share_id) if err: raise Exception(err) ret, err = cifs_unicell.generate_smb_conf() if err: raise Exception(err) audit_str = "Deleted CIFS share %s"%name audit.audit("delete_cifs_share", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect('/view_cifs_shares?action=deleted') except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Delete a CIFS share' return_dict['tab'] = 'view_cifs_shares_tab' return_dict["error"] = 'Error deleting a CIFS share' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_nfs_share(request): return_dict = {} try: if request.method == "GET": #Return the conf page path = request.GET["path"] return_dict["path"] = path return django.shortcuts.render_to_response( "delete_nfs_share_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: path = request.POST["path"] #logger.debug("Delete share request for name %s"%name) result, err = nfs.delete_share(path) if err: raise Exception(err) audit_str = "Deleted NFS share %s" % path audit.audit("delete_nfs_share", audit_str, request.META) return django.http.HttpResponseRedirect( '/view_nfs_shares?ack=deleted') except Exception, e: return_dict['base_template'] = "networking_base.html" return_dict["page_title"] = 'Remove NFS share ' return_dict['tab'] = 'view_nfs_shares_tab' return_dict["error"] = 'Error removing NFS share' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_cifs_share(request): return_dict = {} try: if request.method == "GET": #Return the conf page share_id = request.GET["share_id"] name = request.GET["name"] return_dict["share_id"] = share_id return_dict["name"] = name return django.shortcuts.render_to_response("delete_cifs_share_conf.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: share_id = request.POST["share_id"] name = request.POST["name"] #logger.debug("Delete share request for name %s"%name) ret, err = cifs_common.delete_share(share_id) if err: raise Exception(err) ret, err = cifs_unicell.generate_smb_conf() if err: raise Exception(err) audit_str = "Deleted CIFS share %s"%name audit.audit("delete_cifs_share", audit_str, request.META) return django.http.HttpResponseRedirect('/view_cifs_shares?ack=deleted') except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Delete a CIFS share' return_dict['tab'] = 'view_cifs_shares_tab' return_dict["error"] = 'Error deleting a CIFS share' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_nfs_share(request): return_dict = {} try: if request.method == "GET": #Return the conf page path = request.GET["path"] return_dict["path"] = path return django.shortcuts.render_to_response("delete_nfs_share_conf.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: path = request.POST["path"] #logger.debug("Delete share request for name %s"%name) try : result, err = nfs.delete_share(path) if not result: if not err: raise Exception('Unknown error!') else: raise Exception(err) except Exception, e: return_dict["error"] = "Error deleting NFS share - %s"%str(e) return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request)) audit_str = "Deleted NFS share %s"%path audit.audit("delete_nfs_share", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect('/view_nfs_shares?action=deleted') except Exception, e: s = str(e) return_dict["error"] = "An error occurred when processing your request : %s"%s return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def remove_bond(request): return_dict = {} try: if 'name' not in request.REQUEST: raise Exception("No bond name specified. Please use the menus") name = request.REQUEST["name"] return_dict["name"] = name if request.method == "GET" : #Return the conf page return django.shortcuts.render_to_response("remove_bond_conf.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: result, err = networking.remove_bond(name) if not result: if not err: raise Exception("Error removing bond") else: raise Exception(err) audit_str = "Removed network bond %s"%(name) audit.audit("remove_bond", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect('/view_interfaces?action=removed_bond') except Exception, e: return_dict['base_template'] = "networking_base.html" return_dict["page_title"] = 'Remove a network interface bond' return_dict['tab'] = 'view_interfaces_tab' return_dict["error"] = 'Error removing a network interface bond' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def upload_ssl_certificate(request): return_dict = {} try: if request.method == "GET": #Return the conf page form = pki_forms.UploadCertForm() return_dict['form'] = form return django.shortcuts.render_to_response("upload_ssl_certificate.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: form = pki_forms.UploadCertForm(request.POST) return_dict['form'] = form if not form.is_valid(): return django.shortcuts.render_to_response("upload_ssl_certificate.html", return_dict, context_instance = django.template.context.RequestContext(request)) cd = form.cleaned_data ret, err = pki.upload_ssl_certificate(cd) if err: raise Exception(err) audit_str = "Uploaded a SSL certificate named %s"%cd['name'] audit.audit("upload_certificate", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect('/view_ssl_certificates?ack=uploaded_cert') except Exception, e: return_dict['base_template'] = "system_base.html" return_dict["page_title"] = 'Upload a SSL certificate' return_dict['tab'] = 'certificates_tab' return_dict["error"] = 'Error uploading a SSL certificate' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_iscsi_target(request): return_dict = {} try: if request.method == "GET": #Return the form form = iscsi_stgt_forms.IscsiTargetForm() return_dict["form"] = form return django.shortcuts.render_to_response("create_iscsi_target.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: #Form submission so create return_dict = {} form = iscsi_stgt_forms.IscsiTargetForm(request.POST) if form.is_valid(): cd = form.cleaned_data ret, err = iscsi_stgt.create_target(cd["name"]) if not ret: if err: raise Exception(err) else: raise Exception("Unknown error.") audit_str = "Created an ISCSI target %s"%cd["name"] audit.audit("create_iscsi_target", audit_str, request.META["REMOTE_ADDR"]) url = '/view_iscsi_targets?action=created' return django.http.HttpResponseRedirect(url) else: return_dict["form"] = form return django.shortcuts.render_to_response("create_iscsi_target.html", return_dict, context_instance = django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Create an ISCSI target' return_dict['tab'] = 'view_iscsi_targets_tab' return_dict["error"] = 'Error creating an ISCSI target' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_ssl_certificate(request): return_dict = {} try: if 'name' not in request.REQUEST: raise Exception("No certificate name specified. Please use the menus") name = request.REQUEST["name"] return_dict["name"] = name if request.method == "GET": #Return the conf page return django.shortcuts.render_to_response("delete_ssl_certificate_conf.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: ret, err = pki.delete_ssl_certificate(name) if err: raise Exception(err) audit_str = "Deleted SSL certificate name '%s'"%name audit.audit("delete_certificate", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect('/view_ssl_certificates?ack=deleted') except Exception, e: return_dict['base_template'] = "system_base.html" return_dict["page_title"] = 'Delete a SSL certificate' return_dict['tab'] = 'certificates_tab' return_dict["error"] = 'Error deleting SSL certificate' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_nfs_share(request): return_dict = {} try: if request.method == "GET": #Return the conf page form = nfs_shares_forms.ShareForm() return_dict['form'] = form return django.shortcuts.render_to_response("create_nfs_share.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: form = nfs_shares_forms.ShareForm(request.POST) path = request.POST["path"] return_dict['form'] = form if not form.is_valid(): return django.shortcuts.render_to_response("create_nfs_share.html", return_dict, context_instance = django.template.context.RequestContext(request)) cd = form.cleaned_data try : result, err = nfs.save_share(cd, True) if not result: if not err: raise Exception('Unknown error!') else: raise Exception(err) except Exception, e: return_dict["error"] = "Error creating NFS share information - %s"%str(e) return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request)) audit_str = "Created NFS share %s"%path audit.audit("create_nfs_share", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect('/view_nfs_shares?action=created') except Exception, e: s = str(e) return_dict["error"] = "An error occurred when processing your request : %s"%s return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_local_user(request): return_dict = {} try: if "userid" not in request.REQUEST: return_dict["error"] = "Invalid request. No user name specified." return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request)) if request.method == "GET": #Return the form return_dict["userid"] = request.GET["userid"] return django.shortcuts.render_to_response("delete_local_user_conf.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: #Form submission so create return_dict = {} try : ret = local_users.delete_local_user(request.POST["userid"]) audit_str = "Deleted a local user %s"%request.POST["userid"] audit.audit("delete_local_user", audit_str, request.META["REMOTE_ADDR"]) url = '/view_local_users?action=deleted' if ret: warnings = ','.join(ret) url = "%s&warnings=%s"%(url, warnings) return django.http.HttpResponseRedirect(url) except Exception, e: return_dict["error"] = "Error deleting the local user - %s" %e return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict["error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict["error"] = "An error occurred when processing your request : %s"%s return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_share(request): return_dict = {} try: if request.method == "GET": #Return the conf page share_id = request.GET["share_id"] name = request.GET["name"] return_dict["share_id"] = share_id return_dict["name"] = name return django.shortcuts.render_to_response("delete_share_conf.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: share_id = request.POST["share_id"] name = request.POST["name"] #logger.debug("Delete share request for name %s"%name) try : samba_settings.delete_share(share_id) samba_settings.generate_smb_conf() except Exception, e: return_dict["error"] = "Error deleting share - %s" %e return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request)) audit_str = "Deleted Samba share %s"%name audit.audit("delete_share", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect('/display_shares?action=deleted') except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict["error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict["error"] = "An error occurred when processing your request : %s"%s return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def change_local_user_password(request): return_dict = {} try: if request.method == "GET": #Return the form if "userid" not in request.GET: return_dict["error"] = "Invalid request. No user name specified." return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request)) d = {} d["userid"] = request.GET["userid"] form = samba_shares_forms.PasswordChangeForm(initial=d) return_dict["form"] = form return django.shortcuts.render_to_response("change_local_user_password.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: #Form submission so create return_dict = {} form = samba_shares_forms.PasswordChangeForm(request.POST) if form.is_valid(): cd = form.cleaned_data try : local_users.change_password(cd["userid"], cd["password"]) except Exception, e: return_dict["error"] = "Error creating the local user - %s" %e return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request)) audit_str = "Changed password for local user %s"%cd["userid"] audit.audit("change_local_user_password", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect('/view_local_users?action=changed_password') else:
def create_ftp_user_dirs(request): return_dict = {} try: config, err = vsftp.get_ftp_config() if err: raise Exception(err) if 'dataset' not in config: raise Exception( 'No home dataset has been configured for the FTP service. Please do that before creating FTP home directories' ) users, err = local_users.get_local_users() if err: raise Exception(err) res, err = vsftp.create_ftp_user_dirs(config['dataset'], users) if err: raise Exception(err) audit.audit("create_ftp_dir", 'Created FTP user directories', request.META) return django.http.HttpResponseRedirect( '/view_ftp_configuration?ack=dirs_created') except Exception, e: return_dict['base_template'] = "services_base.html" return_dict["page_title"] = 'Create FTP user directories' return_dict['tab'] = 'ftp_service_settings' return_dict["error"] = 'Error creating FTP user directories ' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def remove_iscsi_acl(request): return_dict = {} try: if 'acl' not in request.REQUEST: raise Exception("Malformed request. No ACL specified. Please use the menus.") if 'target_name' not in request.REQUEST: raise Exception("Malformed request. No target specified. Please use the menus.") acl = request.REQUEST['acl'] target_name = request.REQUEST['target_name'] if request.method == "GET": return_dict["target_name"] = target_name return_dict["acl"] = acl return django.shortcuts.render_to_response("remove_iscsi_acl_conf.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: ret, err = iscsi_stgt.remove_acl(target_name, acl) if not ret: if err: raise Exception(err) else: raise Exception("Unknown error.") audit_str = "Removed ISCSI ACL %s for target %s"%(acl, target_name) url = '/view_iscsi_targets?action=removed_acl' audit.audit("remove_iscsi_acl", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect(url) except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Remove ISCSI ACL' return_dict['tab'] = 'view_iscsi_targets_tab' return_dict["error"] = 'error Removing ISCSI ACL' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_nfs_share(request): return_dict = {} try: if request.method == "GET": #Return the conf page path = request.GET["path"] return_dict["path"] = path return django.shortcuts.render_to_response("delete_nfs_share_conf.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: path = request.POST["path"] #logger.debug("Delete share request for name %s"%name) result, err = nfs.delete_share(path) if err: raise Exception(err) audit_str = "Deleted NFS share %s"%path audit.audit("delete_nfs_share", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect('/view_nfs_shares?action=deleted') except Exception, e: return_dict['base_template'] = "networking_base.html" return_dict["page_title"] = 'Remove NFS share ' return_dict['tab'] = 'view_nfs_shares_tab' return_dict["error"] = 'Error removing NFS share' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_local_user(request): return_dict = {} try: if "username" not in request.REQUEST: raise Exception("Invalid request. No user name specified.") if request.method == "GET": #Return the form return_dict["username"] = request.GET["username"] return django.shortcuts.render_to_response("delete_local_user_conf.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: #Form submission so create return_dict = {} ret, err = local_users.delete_local_user(request.POST["username"]) if not ret: if err: raise Exception(err) else: raise Exception('Error deleting local user') audit_str = "Deleted a local user %s"%request.POST["username"] audit.audit("delete_local_user", audit_str, request.META["REMOTE_ADDR"]) url = '/view_local_users?action=deleted' return django.http.HttpResponseRedirect(url) except Exception, e: return_dict['base_template'] = 'users-groups_base.html' return_dict["page_title"] = 'Delete a local user' return_dict['tab'] = 'view_local_users_tab' return_dict["error"] = 'Error deleting a local user' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_rsync_share(request): return_dict = {} try: if request.method == "GET": name = request.GET.get("name") return_dict["name"] = name return django.shortcuts.render_to_response( "delete_rsync_share.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: name = request.POST.get("name") delshare, err = rsync.delete_rsync_share(name) if err: raise Exception(err) audit_str = "Deleted RSYNC share %s" % name audit.audit("delete_rsync_share", audit_str, request.META) return django.http.HttpResponseRedirect( "/view_rsync_shares/?ack=deleted") except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'RSync shares' return_dict['tab'] = 'view_rsync_shares_tab' return_dict["error"] = 'Error deleting RSync share' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_local_user(request): return_dict = {} try: if request.method == "GET": #Return the form form = samba_shares_forms.LocalUserForm() return_dict["form"] = form return django.shortcuts.render_to_response("create_local_user.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: #Form submission so create return_dict = {} form = samba_shares_forms.LocalUserForm(request.POST) if form.is_valid(): cd = form.cleaned_data try : ret = local_users.create_local_user(cd["userid"], cd["name"], cd["password"]) audit_str = "Created a local user %s"%cd["userid"] audit.audit("create_local_user", audit_str, request.META["REMOTE_ADDR"]) url = '/view_local_users?action=created' if ret: warnings = ','.join(ret) url = "%s&warnings=%s"%(url, warnings) return django.http.HttpResponseRedirect(url) except Exception, e: return_dict["error"] = "Error creating the local user - %s" %e return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request)) else:
def add_iscsi_acl(request): return_dict = {} try: if 'target_name' not in request.REQUEST: raise Exception( "Malformed request. No target specified. Please use the menus." ) target_name = request.REQUEST['target_name'] target, err = iscsi_stgt.get_target(target_name) if err: raise Exception(err) if not target: raise Exception('Specified target not found') if request.method == "GET": #Return the form initial = {} initial['target_name'] = target_name form = iscsi_stgt_forms.IscsiAclForm(initial=initial) return_dict["form"] = form return django.shortcuts.render_to_response( "add_iscsi_acl.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: #Form submission so create return_dict = {} form = iscsi_stgt_forms.IscsiAclForm(request.POST) if form.is_valid(): cd = form.cleaned_data ret, err = iscsi_stgt.add_acl(cd['target_name'], cd['acl']) if not ret: if err: raise Exception(err) else: raise Exception("Unknown error.") audit_str = "Added ISCSI ACL %s for target %s" % ( cd["acl"], cd['target_name']) url = '/view_iscsi_target?name=%s&ack=added_acl' % target_name audit.audit("add_iscsi_acl", audit_str, request.META) return django.http.HttpResponseRedirect(url) else: return_dict["form"] = form return django.shortcuts.render_to_response( "add_iscsi_acl.html", return_dict, context_instance=django.template.context.RequestContext( request)) except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Add ISCSI ACL' return_dict['tab'] = 'view_iscsi_targets_tab' return_dict["error"] = 'Error adding ISCSI ACL' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def edit_local_user_gid(request): return_dict = {} try: group_list,err = local_users.get_local_groups() if err: raise Exception(err) if 'username' not in request.REQUEST: raise Exception("Unknown user specified") username = request.REQUEST["username"] ud,err = local_users.get_local_user(username) if err: raise Exception(err) if not ud: raise Exception("Specified user information not found") if request.method == "GET": # Shd be an edit request # Set initial form values initial = {} initial['username'] = ud['username'] initial['gid'] = ud['gid'] form = local_user_forms.EditLocalUserGidForm(initial = initial, group_list = group_list) return_dict["form"] = form return django.shortcuts.render_to_response('edit_local_user_gid.html', return_dict, context_instance=django.template.context.RequestContext(request)) else: # Shd be an save request form = local_user_forms.EditLocalUserGidForm(request.POST, group_list = group_list) return_dict["form"] = form if form.is_valid(): cd = form.cleaned_data ret, err = local_users.set_local_user_gid(cd) if not ret: if err: raise Exception(err) else: raise Exception("Error saving user information") audit_str = "Modified local user's primary group %s"%cd["username"] audit.audit("modify_local_user_gid", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect('/view_local_user?username=%s&searchby=username&action=gid_changed'%cd["username"]) else: #Invalid form return django.shortcuts.render_to_response('edit_local_user_gid.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = 'users-groups_base.html' return_dict["page_title"] = "Modify local user's primary group" return_dict['tab'] = 'view_local_users_tab' return_dict["error"] = 'Error modifying local users primary group' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_local_user(request): return_dict = {} try: group_list, err = local_users.get_local_groups() if err: raise Exception(err) if request.method == "GET": #Return the form #form = local_user_forms.LocalUserForm(group_list = group_list) form = local_user_forms.LocalUserForm() return_dict["form"] = form return django.shortcuts.render_to_response( "create_local_user.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: #Form submission so create return_dict = {} #form = local_user_forms.LocalUserForm(request.POST, group_list = group_list) form = local_user_forms.LocalUserForm(request.POST) if form.is_valid(): cd = form.cleaned_data #ret, err = local_users.create_local_user(cd["username"], cd["name"], cd["password"], cd['gid']) ret, err = local_users.create_local_user( cd["username"], cd["name"], cd["password"], 1000) if not ret: if err: raise Exception(err) else: raise Exception("Error creating the local user.") audit_str = "Created a local user %s" % cd["username"] audit.audit("create_local_user", audit_str, request.META) if group_list: url = '/edit_local_user_group_membership/?username=%s&ack=created' % cd[ 'username'] else: url = '/view_local_users?ack=created' return django.http.HttpResponseRedirect(url) else: return_dict["form"] = form return django.shortcuts.render_to_response( "create_local_user.html", return_dict, context_instance=django.template.context.RequestContext( request)) except Exception, e: return_dict['base_template'] = 'users-groups_base.html' return_dict["page_title"] = 'Create a local users' return_dict['tab'] = 'view_local_users_tab' return_dict["error"] = 'Error creating a local user' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_dir(request): return_dict = {} try: if 'path' not in request.REQUEST: raise Exception('Invalid request. Please use the menus') path = request.REQUEST['path'] pools, err = zfs.get_pools() ds_list = [] for pool in pools: if pool['properties']['mountpoint']['value'] == path: raise Exception('The selected directory is the mountpoint of a pool and so cannot be deleted.') for ds in pool["datasets"]: if ds['properties']['type']['value'] == 'filesystem': if ds['properties']['mountpoint']['value'] == path: raise Exception('The selected directory is the mountpoint of a dataset and so cannot be deleted.') if request.method == "GET": if 'path' not in request.GET: raise Exception('No directory specified') initial = {} initial['path'] = request.GET['path'] form = folder_management_forms.DirForm(initial=initial) return_dict['form'] = form return django.shortcuts.render_to_response('delete_dir_conf.html', return_dict, context_instance=django.template.context.RequestContext(request)) else: form = folder_management_forms.DirForm(request.POST) if form.is_valid(): cd = form.cleaned_data path = cd['path'] if not os.path.exists(path): raise Exception('The specified directory does not exist!') if len(path.split("/")) < 2: raise Exception('Cannot delete specified directory - Invalid path') # Need to also check if the path is a share or not. If share, dont delete again. # Checking NFS exports,err = nfs.load_exports_list() if exports: for export in exports: #print id(export["path"]),id(path) if export["path"] == path: raise Exception('Cannot delete the specified directory as it is path of an NFS share') shutil.rmtree(path,ignore_errors=True) audit_str = "Deleted directory '%s'" %path audit.audit("delete_dir", audit_str, request.META) return django.http.HttpResponseRedirect('/dir_manager/?ack=deleted_dir') else: raise Exception('Could not delete the specified directory as there was an error in the specified parameters.') except Exception, e: return_dict['base_template'] = "storage_base.html" return_dict["page_title"] = 'Delete a directory' return_dict['tab'] = 'dir_permissions_tab' return_dict["error"] = 'Error deleting directory' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def modify_sticky_bit(request): return_dict = {} try: if 'path' not in request.REQUEST: raise Exception('Invalid request. Please use the menus.') path = request.REQUEST['path'] sticky_bit_enabled, err = _sticky_bit_enabled(path) if err: raise Exception(err) if request.method == "GET": initial = {} initial['path'] = path initial['sticky_bit_enabled'] = sticky_bit_enabled form = folder_management_forms.ModifyStickyBitForm(initial=initial) return_dict["form"] = form return django.shortcuts.render_to_response('modify_sticky_bit.html', return_dict, context_instance=django.template.context.RequestContext(request)) else: form = folder_management_forms.ModifyStickyBitForm(request.POST) return_dict["form"] = form if form.is_valid(): cd = form.cleaned_data s = os.stat(path) if cd['sticky_bit_enabled']: audit_str = 'Enabled sticky bit ' if cd['recursive']: audit_str += 'recursively ' for root, dirs, files in os.walk(path): for target in dirs: os.chmod('%s/%s'%(root,target), (s.st_mode | stat.S_ISVTX)) os.chmod(path, (s.st_mode | stat.S_ISVTX)) audit_str += 'for path %s'%path #print audit_str else: audit_str = 'Disabled sticky bit ' if cd['recursive']: audit_str += 'recursively ' for root, dirs, files in os.walk(path): for target in dirs: os.chmod('%s/%s'%(root,target), (s.st_mode & ~stat.S_ISVTX)) os.chmod(path, (s.st_mode & ~stat.S_ISVTX)) audit_str += 'for path %s'%path #print audit_str audit.audit("modify_dir_sticky_bit", audit_str, request.META) return django.http.HttpResponseRedirect('/view_dir_ownership_permissions?path=%s&ack=modified_sticky_bit'%cd['path']) else: return django.shortcuts.render_to_response('modify_dir_ownership.html', return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "storage_base.html" return_dict["page_title"] = 'Modify directory sticky bit settings' return_dict['tab'] = 'dir_permissions_tab' return_dict["error"] = 'Error modifying directory sticky bit settings' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def change_local_user_password(request): return_dict = {} try: if request.method == "GET": #Return the form if "username" not in request.GET: raise Exception("Invalid request. No user name specified.") d = {} d["username"] = request.GET["username"] form = local_user_forms.PasswordChangeForm(initial=d) return_dict["form"] = form return django.shortcuts.render_to_response( "change_local_user_password.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: #Form submission so create return_dict = {} form = local_user_forms.PasswordChangeForm(request.POST) if form.is_valid(): cd = form.cleaned_data rc, err = local_users.change_password(cd["username"], cd["password"]) if not rc: if err: raise Exception(err) else: raise Exception( "Error changing the local user password") audit_str = "Changed password for local user %s" % cd[ "username"] audit.audit("change_local_user_password", audit_str, request.META) return django.http.HttpResponseRedirect( '/view_local_users?ack=changed_password') else: return_dict["form"] = form return django.shortcuts.render_to_response( "change_local_user_password.html", return_dict, context_instance=django.template.context.RequestContext( request)) except Exception, e: return_dict['base_template'] = 'users-groups_base.html' return_dict["page_title"] = "Modify local user's password" return_dict['tab'] = 'view_local_users_tab' return_dict["error"] = "Error modifying local user's password" return_dict["error_details"] = str(e) return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def edit_nfs_share(request): return_dict = {} try: if request.method == "GET": #Return the conf page path = request.GET["path"] d, err = nfs.get_share(path) if not d: raise Exception('Could not find the specified share. Please use the menus. : %s'%err) initial = {} initial['path'] = d['path'] if 'clients' in d: client_list = [] for client in d['clients']: client_list.append(client['name']) initial['clients'] = ','.join(client_list) initial['readonly'] = False initial['root_squash'] = False initial['all_squash'] = False if 'options' in d: for option in d['options']: if option == 'ro': initial['readonly'] = True elif option == 'root_squash': initial['root_squash'] = True elif option == 'all_squash': initial['all_squash'] = True form = nfs_shares_forms.ShareForm(initial=initial) return_dict['form'] = form return django.shortcuts.render_to_response("edit_nfs_share.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: form = nfs_shares_forms.ShareForm(request.POST) path = request.POST["path"] return_dict['form'] = form if not form.is_valid(): return django.shortcuts.render_to_response("edit_nfs_share.html", return_dict, context_instance = django.template.context.RequestContext(request)) cd = form.cleaned_data try : result, err = nfs.save_share(cd) if not result: if not err: raise Exception('Unknown error!') else: raise Exception(err) except Exception, e: return_dict["error"] = "Error saving NFS share information - %s"%str(e) return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request)) audit_str = "Edited NFS share %s"%path audit.audit("edit_nfs_share", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect('/view_nfs_shares?action=saved') except Exception, e: s = str(e) return_dict["error"] = "An error occurred when processing your request : %s"%s return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def edit_nfs_share(request): return_dict = {} try: if request.method == "GET": #Return the conf page path = request.GET["path"] d, err = nfs.get_share(path) if err: raise Exception(err) if not d: raise Exception('Could not find the specified share. Please use the menus.') initial = {} initial['path'] = d['path'] if 'clients' in d: client_list = [] for client in d['clients']: client_list.append(client['name']) initial['clients'] = ','.join(client_list) initial['readonly'] = False initial['root_squash'] = False initial['all_squash'] = False if 'options' in d: for option in d['options']: if option == 'ro': initial['readonly'] = True elif option == 'root_squash': initial['root_squash'] = True elif option == 'all_squash': initial['all_squash'] = True form = nfs_shares_forms.ShareForm(initial=initial) return_dict['form'] = form return django.shortcuts.render_to_response("edit_nfs_share.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: form = nfs_shares_forms.ShareForm(request.POST) path = request.POST["path"] return_dict['form'] = form if not form.is_valid(): return django.shortcuts.render_to_response("edit_nfs_share.html", return_dict, context_instance = django.template.context.RequestContext(request)) cd = form.cleaned_data result, err = nfs.save_share(cd) if err: raise Exception(err) audit_str = "Edited NFS share %s"%path audit.audit("edit_nfs_share", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect('/view_nfs_shares?action=saved') except Exception, e: return_dict['base_template'] = "networking_base.html" return_dict["page_title"] = 'Modify a NFS share ' return_dict['tab'] = 'view_nfs_shares_tab' return_dict["error"] = 'Error modifying a NFS share' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def add_iscsi_user_authentication(request): return_dict = {} try: if 'authentication_type' not in request.REQUEST: raise Exception("Malformed request. No user type specified. Please use the menus.") if 'target_name' not in request.REQUEST: raise Exception("Malformed request. No target specified. Please use the menus.") authentication_type = request.REQUEST['authentication_type'] target_name = request.REQUEST['target_name'] if authentication_type not in ['incoming', 'outgoing']: raise Exception("Invalid user type. Please use the menus.") if request.method == "GET": #Return the form initial = {} initial['authentication_type'] = authentication_type initial['target_name'] = target_name form = iscsi_stgt_forms.IscsiAuthenticationForm(initial = initial) return_dict["form"] = form return django.shortcuts.render_to_response("add_iscsi_target_user.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: #Form submission so create return_dict = {} form = iscsi_stgt_forms.IscsiAuthenticationForm(request.POST) if form.is_valid(): cd = form.cleaned_data ret, err = iscsi_stgt.add_user_authentication(cd['target_name'], cd['authentication_type'], cd["username"], cd["password"]) if not ret: if err: raise Exception(err) else: raise Exception("Error adding the ISCSI target user.") if cd['authentication_type'] == 'incoming': audit_str = "Added ISCSI initiator authentication user %s for target %s"%(cd["username"], cd['target_name']) url = '/view_iscsi_targets?action=added_initiator_authentication' else: audit_str = "Added ISCSI target authentication user %s for target %s"%(cd["username"], cd['target_name']) url = '/view_iscsi_targets?action=added_target_authentication' audit.audit("add_iscsi_target_authentication", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect(url) else: return_dict["form"] = form return django.shortcuts.render_to_response("add_iscsi_target_user.html", return_dict, context_instance = django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Add ISCSI authentication user' return_dict['tab'] = 'view_iscsi_targets_tab' return_dict["error"] = 'Error adding ISCSI authentication user' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def change_service_status(request): return_dict = {} try: if request.method == "GET": raise Exception("Invalid request. Please use the menus") if 'service' not in request.POST: raise Exception("Invalid request. Please use the menus") if 'action' not in request.POST or request.POST['action'] not in [ 'start', 'stop', 'restart', 'enable', 'disable' ]: raise Exception("Invalid request. Please use the menus") service = request.POST['service'] action = request.POST['action'] if 'action' == 'start' and service == 'vsftpd': #Need to make sure that all local users have their directories created so do it.. config, err = vsftp.get_ftp_config() if err: raise Exception(err) users, err = local_users.get_local_users() if err: raise Exception(err) ret, err = create_ftp_user_dirs(config['dataset'], users) if err: raise Exception(err) audit_str = "Service status change of %s initiated to %s state." % ( service, action) audit.audit("change_service_status", audit_str, request.META) out, err = services_management.change_service_status(service, action) if err: raise Exception(err) if out: return django.http.HttpResponseRedirect( '/view_services?&service_change_status=%s' % ','.join(out)) else: return django.http.HttpResponseRedirect( '/view_services?service_change_status=none') except Exception, e: return_dict['base_template'] = "services_base.html" return_dict["page_title"] = 'Modify system service state' return_dict['tab'] = 'view_services_tab' return_dict["error"] = 'Error modifying system services state' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_local_user(request): return_dict = {} try: if "userid" not in request.REQUEST: return_dict["error"] = "Invalid request. No user name specified." return django.shortcuts.render_to_response( 'logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext( request)) if request.method == "GET": #Return the form return_dict["userid"] = request.GET["userid"] return django.shortcuts.render_to_response( "delete_local_user_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: #Form submission so create return_dict = {} try: ret = local_users.delete_local_user(request.POST["userid"]) audit_str = "Deleted a local user %s" % request.POST["userid"] audit.audit("delete_local_user", audit_str, request.META["REMOTE_ADDR"]) url = '/view_local_users?action=deleted' if ret: warnings = ','.join(ret) url = "%s&warnings=%s" % (url, warnings) return django.http.HttpResponseRedirect(url) except Exception, e: return_dict["error"] = "Error deleting the local user - %s" % e return django.shortcuts.render_to_response( 'logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext( request)) except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict[ "error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict[ "error"] = "An error occurred when processing your request : %s" % s return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def edit_dns_nameservers(request): return_dict = {} try: ns_list, err = networking.get_name_servers() if err: raise Exception(err) if request.method == "GET": if not ns_list: form = networking_forms.DNSNameServersForm() else: form = networking_forms.DNSNameServersForm( initial={'nameservers': ','.join(ns_list)}) url = "edit_dns_nameservers.html" else: form = networking_forms.DNSNameServersForm(request.POST) if form.is_valid(): cd = form.cleaned_data nameservers = cd["nameservers"] if ',' in nameservers: slist = nameservers.split(',') else: slist = nameservers.split(' ') res, err = networking.set_name_servers(slist) if not res: if err: raise Exception(err) else: raise Exception('Error updating nameservers') audit_str = "Updated the DNS nameserver list to %s" % nameservers audit.audit("set_dns_nameservers", audit_str, request.META) return django.http.HttpResponseRedirect( '/view_dns_nameservers?ack=saved') else: #invalid form url = "edit_dns_nameservers.html" return_dict["form"] = form return django.shortcuts.render_to_response( url, return_dict, context_instance=django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "networking_base.html" return_dict["page_title"] = 'Modify DNS servers' return_dict['tab'] = 'view_dns_nameservers_tab' return_dict["error"] = 'Error modifying DNS servers' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def upload_ssh_host_key(request): return_dict = {} user = request.GET.get('user','replicator') return_dict["selected_user"] = user if request.method == 'POST': try: authorized_key = request.POST.get('authorized_key',None) # This is a delete operation. authorized_key in post is delete and as a file is file upload if authorized_key: user = request.POST.get("selected_user") key = request.POST.get("authorized_key") description = "%s" %(user) audit.audit ("remove_ssh_host_key", description, request.META) files = open((pki._get_known_hosts(user)), 'r').readlines() authorized_keys = open(pki._get_known_hosts(user),'w') for file in files: if key.strip() != file.strip(): authorized_keys.write(file) ack_message = "host_deleted" else: authorized_key = request.FILES.get('pub_key') ip = request.POST.get('ip') user = request.POST.get('user','replicator') description = "%s %s %s" %(user, ip, authorized_key) audit.audit ("upload_ssh_host_key", description, request.META) hosts_file = pki._get_known_hosts(user) print hosts_file with open("/tmp/hosts_file", 'wb+') as destination: for chunk in authorized_key.chunks(): destination.write(chunk) with open("/tmp/hosts_file",'r') as key: data = key.read() print data with open(hosts_file,'ab') as key: key.write(ip+" "+data) perm,err = pki.ssh_dir_permissions(user) if err: raise Exception(err) ack_message = "host_added" return django.http.HttpResponseRedirect("/known_hosts_ssh_keys/?ack=%s&user=%s"%(ack_message,user)) except Exception,e: return_dict['base_template'] = "key_management_base.html" return_dict["page_title"] = 'Upload a Host Key' return_dict['tab'] = 'upload_host_key_tab' return_dict["error"] = 'Error adding host key. Please check the value' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_bond(request): return_dict = {} try: interfaces, err = networking.get_interfaces() if err: raise Exception(err) if not interfaces: raise Exception("Error loading network interface information : No interfaces found") bonds, err = networking.get_bonding_info_all() if err: raise Exception(err) return_dict['interfaces'] = interfaces if_list = [] existing_bonds = [] for if_name, iface in interfaces.items(): if 'bonding_master' in iface and iface['bonding_master']: existing_bonds.append(if_name) continue if 'slave_to' in iface and iface['slave_to']: continue if 'eth' not in if_name: continue if_list.append(if_name) if request.method == "GET": form = networking_forms.CreateBondForm(interfaces = if_list, existing_bonds = existing_bonds) return_dict['form'] = form return django.shortcuts.render_to_response("create_bond.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: form = networking_forms.CreateBondForm(request.POST, interfaces = if_list, existing_bonds = existing_bonds) return_dict['form'] = form if not form.is_valid(): return django.shortcuts.render_to_response("create_bond.html", return_dict, context_instance = django.template.context.RequestContext(request)) cd = form.cleaned_data result, err = networking.create_bond(cd['name'], cd['slaves'], int(cd['mode'])) if not err: raise Exception(err) audit_str = "Created a network bond named %s with slaves %s"%(cd['name'], ','.join(cd['slaves'])) audit.audit("create_bond", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect('/view_interfaces?action=created_bond') except Exception, e: return_dict['base_template'] = "networking_base.html" return_dict["page_title"] = 'Create a network interface bond' return_dict['tab'] = 'view_interfaces_tab' return_dict["error"] = 'Error creating a network interface bond' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_local_group(request): return_dict = {} try: if request.method == "GET": #Return the form form = local_user_forms.LocalGroupForm() return_dict["form"] = form return django.shortcuts.render_to_response( "create_local_group.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: #Form submission so create return_dict = {} #print '1' form = local_user_forms.LocalGroupForm(request.POST) if form.is_valid(): #print '2' cd = form.cleaned_data ret, err = local_users.create_local_group(cd["grpname"]) #print '3' if not ret: if err: raise Exception(err) else: raise Exception("Error creating the local group.") audit_str = "Created a local group %s" % cd["grpname"] audit.audit("create_local_group", audit_str, request.META) #url = '/view_local_groups?ack=created' url = '/modify_group_membership?grpname=%s&ack=created' % cd[ 'grpname'] return django.http.HttpResponseRedirect(url) else: return_dict["form"] = form return django.shortcuts.render_to_response( "create_local_group.html", return_dict, context_instance=django.template.context.RequestContext( request)) except Exception, e: return_dict['base_template'] = 'users-groups_base.html' return_dict["page_title"] = 'Create a local user group' return_dict['tab'] = 'view_local_groups_tab' return_dict["error"] = 'Error create a local user group' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_local_group(request): return_dict = {} try: if "grpname" not in request.REQUEST: raise Exception("Invalid request. No group name specified.") gd, err = local_users.get_local_group(request.REQUEST['grpname']) if err or (not gd): if err: raise Exception(err) else: raise Exception("Could not retrieve group information") if gd['members']: raise Exception( "Cannot delete this group as it has the following members : %s" % (','.join(gd['members']))) if request.method == "GET": #Return the form return_dict["grpname"] = request.GET["grpname"] return django.shortcuts.render_to_response( "delete_local_group_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: #Form submission so create return_dict = {} ret, err = local_users.delete_local_group(request.POST["grpname"]) if not ret: if err: raise Exception('Error deleting group : %s' % err) else: raise Exception('Error deleting group') audit_str = "Deleted a local group %s" % request.POST["grpname"] audit.audit("delete_local_group", audit_str, request.META) url = '/view_local_groups?ack=deleted' return django.http.HttpResponseRedirect(url) except Exception, e: return_dict['base_template'] = 'users-groups_base.html' return_dict["page_title"] = 'Delete a local user group' return_dict['tab'] = 'view_local_groups_tab' return_dict["error"] = 'Error deleting a local user group' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def internal_audit(request): response = django.http.HttpResponse() if request.method == "GET": response.write("Error!") else: if not "who" in request.POST or request.POST["who"] != "batch": response.write("Unknown requester") return response if (not "audit_action" in request.POST) or (not "audit_str" in request.POST): response.write("Insufficient information!") else: audit.audit(request.POST["audit_action"], request.POST["audit_str"], "0.0.0.0") response.write("Success") return response
def change_admin_password(request): """ Used to change a user's password for the management utility""" try: return_dict = {} if request.user and request.user.is_authenticated(): if request.method == 'POST': iv_logging.debug("Admin password change posted") #user has submitted the password info form = admin_forms.ChangeAdminPasswordForm(request.POST) if form.is_valid(): cd = form.cleaned_data oldPasswd = cd['oldPasswd'] newPasswd1 = cd['newPasswd1'] newPasswd2 = cd['newPasswd2'] #Checking for old password is done in the form itself if request.user.check_password(oldPasswd): if newPasswd1 == newPasswd2: # all systems go so now change password request.user.set_password(newPasswd1); request.user.save() return_dict['success'] = True iv_logging.info("Admin password change request successful.") audit_str = "Changed admin password" audit.audit("modify_admin_password", audit_str, request.META["REMOTE_ADDR"]) else: return_dict['error'] = 'New passwords do not match' # else invalid form or error so existing form data to return_dict and # fall through to redisplay the form if 'success' not in return_dict: return_dict['form'] = form iv_logging.info("Admin password change request failed.") else: form = admin_forms.ChangeAdminPasswordForm() return_dict['form'] = form return django.shortcuts.render_to_response('change_admin_password_form.html', return_dict, context_instance = django.template.context.RequestContext(request)) else: #User not authenticated so return a login screen return django.http.HttpResponseRedirect('/login/') except Exception, e: return_dict['base_template'] = "admin_base.html" return_dict["page_title"] = 'Change admininistrator password' return_dict['tab'] = 'change_admin_pswd_tab' return_dict["error"] = 'Error changing administrator password' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance = django.template.context.RequestContext(request))
def create_iscsi_lun(request): return_dict = {} target_name = request.REQUEST['target_name'] try: if 'target_name' not in request.REQUEST: raise Exception("Malformed request. No target specified. Please use the menus.") zvols, err = zfs.get_all_zvols() if err: raise Exception(err) if not zvols: raise Exception("There are no block device volumes created. Please create one first before adding a LUN.") if request.method == "GET": #Return the form initial = {} initial['target_name'] = target_name form = iscsi_stgt_forms.IscsiLunForm(initial = initial, zvols = zvols) return_dict["form"] = form return django.shortcuts.render_to_response("create_iscsi_lun.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: #Form submission so create return_dict = {} form = iscsi_stgt_forms.IscsiLunForm(request.POST, zvols = zvols) if form.is_valid(): cd = form.cleaned_data ret, err = iscsi_stgt.create_lun(cd["target_name"], cd['path']) if not ret: if err: raise Exception(err) else: raise Exception("Unknown error.") audit_str = "Created an ISCSI LUN in target %s with path %s"%(cd["target_name"], cd['path']) audit.audit("create_iscsi_lun", audit_str, request.META["REMOTE_ADDR"]) url = '/view_iscsi_targets?action=lun_created' return django.http.HttpResponseRedirect(url) else: return_dict["form"] = form return django.shortcuts.render_to_response("create_iscsi_lun.html", return_dict, context_instance = django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Create an ISCSI LUN' return_dict['tab'] = 'view_iscsi_targets_tab' return_dict["error"] = 'Error creating an ISCSI LUN' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def set_interface_state(request): return_dict = {} try: if 'name' not in request.REQUEST: raise Exception( "No interface name specified. Please use the menus") if 'state' not in request.REQUEST: raise Exception("No state specified. Please use the menus") name = request.REQUEST["name"] return_dict["name"] = name state = request.REQUEST["state"] return_dict["state"] = state if request.method == "GET" and state == 'down': #Return the conf page return django.shortcuts.render_to_response( "set_interface_state_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: result, err = networking.set_interface_state(name, state) if not result: if err: raise Exception(err) else: raise Exception("Error setting interface state") audit_str = "Set the state of network interface %s to %s" % (name, state) audit.audit("set_interface_state", audit_str, request.META) return django.http.HttpResponseRedirect( '/view_interfaces?ack=state_%s' % state) except Exception, e: return_dict['base_template'] = "networking_base.html" return_dict["page_title"] = 'Set interface state' return_dict['tab'] = 'view_interfaces_tab' return_dict["error"] = 'Error setting interface state' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_share(request): return_dict = {} try: if request.method == "GET": #Return the conf page share_id = request.GET["share_id"] name = request.GET["name"] return_dict["share_id"] = share_id return_dict["name"] = name return django.shortcuts.render_to_response( "delete_share_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: share_id = request.POST["share_id"] name = request.POST["name"] #logger.debug("Delete share request for name %s"%name) try: samba_settings.delete_share(share_id) samba_settings.generate_smb_conf() except Exception, e: return_dict["error"] = "Error deleting share - %s" % e return django.shortcuts.render_to_response( 'logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext( request)) audit_str = "Deleted Samba share %s" % name audit.audit("delete_share", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect( '/display_shares?action=deleted') except Exception, e: s = str(e) if "Another transaction is in progress".lower() in s.lower(): return_dict[ "error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds" else: return_dict[ "error"] = "An error occurred when processing your request : %s" % s return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def add_iscsi_acl(request): return_dict = {} try: if 'target_name' not in request.REQUEST: raise Exception("Malformed request. No target specified. Please use the menus.") target_name = request.REQUEST['target_name'] target, err = iscsi_stgt.get_target(target_name) if err: raise Exception(err) if not target: raise Exception('Specified target not found') if request.method == "GET": #Return the form initial = {} initial['target_name'] = target_name form = iscsi_stgt_forms.IscsiAclForm(initial = initial) return_dict["form"] = form return django.shortcuts.render_to_response("add_iscsi_acl.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: #Form submission so create return_dict = {} form = iscsi_stgt_forms.IscsiAclForm(request.POST) if form.is_valid(): cd = form.cleaned_data ret, err = iscsi_stgt.add_acl(cd['target_name'], cd['acl']) if not ret: if err: raise Exception(err) else: raise Exception("Unknown error.") audit_str = "Added ISCSI ACL %s for target %s"%(cd["acl"], cd['target_name']) url = '/view_iscsi_targets?action=added_acl' audit.audit("add_iscsi_acl", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect(url) else: return_dict["form"] = form return django.shortcuts.render_to_response("add_iscsi_acl.html", return_dict, context_instance = django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Add ISCSI ACL' return_dict['tab'] = 'view_iscsi_targets_tab' return_dict["error"] = 'Error adding ISCSI ACL' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def change_local_user_password(request): return_dict = {} try: if request.method == "GET": #Return the form if "userid" not in request.GET: return_dict[ "error"] = "Invalid request. No user name specified." return django.shortcuts.render_to_response( 'logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext( request)) d = {} d["userid"] = request.GET["userid"] form = samba_shares_forms.PasswordChangeForm(initial=d) return_dict["form"] = form return django.shortcuts.render_to_response( "change_local_user_password.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: #Form submission so create return_dict = {} form = samba_shares_forms.PasswordChangeForm(request.POST) if form.is_valid(): cd = form.cleaned_data try: local_users.change_password(cd["userid"], cd["password"]) except Exception, e: return_dict[ "error"] = "Error creating the local user - %s" % e return django.shortcuts.render_to_response( 'logged_in_error.html', return_dict, context_instance=django.template.context. RequestContext(request)) audit_str = "Changed password for local user %s" % cd["userid"] audit.audit("change_local_user_password", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect( '/view_local_users?action=changed_password') else:
def create_iscsi_target(request): return_dict = {} try: if request.method == "GET": #Return the form form = iscsi_stgt_forms.IscsiTargetForm() return_dict["form"] = form return django.shortcuts.render_to_response( "create_iscsi_target.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: #Form submission so create return_dict = {} form = iscsi_stgt_forms.IscsiTargetForm(request.POST) if form.is_valid(): cd = form.cleaned_data ret, err = iscsi_stgt.create_target(cd["name"]) if not ret: if err: raise Exception(err) else: raise Exception("Unknown error.") audit_str = "Created an ISCSI target %s" % cd["name"] audit.audit("create_iscsi_target", audit_str, request.META) url = '/view_iscsi_targets?ack=created' return django.http.HttpResponseRedirect(url) else: return_dict["form"] = form return django.shortcuts.render_to_response( "create_iscsi_target.html", return_dict, context_instance=django.template.context.RequestContext( request)) except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Create an ISCSI target' return_dict['tab'] = 'view_iscsi_targets_tab' return_dict["error"] = 'Error creating an ISCSI target' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def remove_iscsi_user_authentication(request): return_dict = {} try: if 'authentication_type' not in request.REQUEST: raise Exception("Malformed request. No user type specified. Please use the menus.") if 'target_name' not in request.REQUEST: raise Exception("Malformed request. No target namespecified. Please use the menus.") if 'username' not in request.REQUEST: raise Exception("Malformed request. No user name specified. Please use the menus.") authentication_type = request.REQUEST['authentication_type'] target_name = request.REQUEST['target_name'] username = request.REQUEST['username'] if authentication_type not in ['incoming', 'outgoing']: raise Exception("Invalid user type. Please use the menus.") if request.method == "GET": return_dict["target_name"] = target_name return_dict["username"] = username return_dict["authentication_type"] = authentication_type return django.shortcuts.render_to_response("remove_iscsi_user_auth_conf.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: ret, err = iscsi_stgt.remove_user_authentication(target_name, username, authentication_type) if not ret: if err: raise Exception(err) else: raise Exception("Unknown error.") if authentication_type == 'incoming': audit_str = "Removed ISCSI initiator authentication user %s for target %s"%(username, target_name) url = '/view_iscsi_targets?action=removed_initiator_authentication' else: audit_str = "Removed ISCSI target authentication user %s for target %s"%(username, target_name) url = '/view_iscsi_targets?action=removed_target_authentication' audit.audit("remove_iscsi_target_authentication", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect(url) except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Remove ISCSI authentication user' return_dict['tab'] = 'view_iscsi_targets_tab' return_dict["error"] = 'Error removing ISCSI authentication user' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def remove_iscsi_acl(request): return_dict = {} try: if 'acl' not in request.REQUEST: raise Exception( "Malformed request. No ACL specified. Please use the menus.") if 'target_name' not in request.REQUEST: raise Exception( "Malformed request. No target specified. Please use the menus." ) acl = request.REQUEST['acl'] target_name = request.REQUEST['target_name'] if request.method == "GET": return_dict["target_name"] = target_name return_dict["acl"] = acl return django.shortcuts.render_to_response( "remove_iscsi_acl_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: ret, err = iscsi_stgt.remove_acl(target_name, acl) if not ret: if err: raise Exception(err) else: raise Exception("Unknown error.") audit_str = "Removed ISCSI ACL %s for target %s" % (acl, target_name) url = '/view_iscsi_target?name=%s&ack=removed_acl' % target_name audit.audit("remove_iscsi_acl", audit_str, request.META) return django.http.HttpResponseRedirect(url) except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Remove ISCSI ACL' return_dict['tab'] = 'view_iscsi_targets_tab' return_dict["error"] = 'error Removing ISCSI ACL' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_iscsi_lun(request): return_dict = {} try: if 'target_name' not in request.REQUEST: raise Exception( "Malformed request. No target specified. Please use the menus." ) if 'store' not in request.REQUEST: raise Exception( "Malformed request. No LUN specified. Please use the menus.") store = request.REQUEST['store'] target_name = request.REQUEST['target_name'] if request.method == "GET": return_dict["target_name"] = target_name return_dict["store"] = store return django.shortcuts.render_to_response( "delete_iscsi_lun_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: ret, err = iscsi_stgt.delete_lun(target_name, store) if not ret: if err: raise Exception(err) else: raise Exception("Unknown error.") audit_str = "Deleted ISCSI LUN %s from target %s" % (store, target_name) url = '/view_iscsi_target?name=%s&ack=lun_deleted' % target_name audit.audit("delete_iscsi_lun", audit_str, request.META) return django.http.HttpResponseRedirect(url) except Exception, e: return_dict['base_template'] = "shares_base.html" return_dict["page_title"] = 'Remove an ISCSI LUN' return_dict['tab'] = 'view_iscsi_targets_tab' return_dict["error"] = 'Error removing an ISCSI LUN' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def change_service_status(request): return_dict = {} try: if request.method == "GET": raise Exception("Invalid request. Please use the menus") if 'service' not in request.POST: raise Exception("Invalid request. Please use the menus") if 'action' not in request.POST or request.POST['action'] not in ['start', 'stop']: raise Exception("Invalid request. Please use the menus") audit_str = "Service status change of %s initiated to %s state."%(request.POST['service'], request.POST['action']) d, err = _change_service_status(request.POST['service'], request.POST['action']) if not d: audit_str += 'Request failed.' audit.audit("change_service_status", audit_str, request.META["REMOTE_ADDR"]) if err: raise Exception(err) else: raise Exception('Changing service status error') if d['status_code'] == 0: audit_str += 'Request succeeded.' else: audit_str += 'Request failed.' audit.audit("change_service_status", audit_str, request.META["REMOTE_ADDR"]) if request.POST['action'] == 'start': if d['status_code'] == 0: return django.http.HttpResponseRedirect('/view_services?&action=start_success') else: return django.http.HttpResponseRedirect('/view_services?&action=start_fail') elif request.POST['action'] == 'stop': if d['status_code'] == 0: return django.http.HttpResponseRedirect('/view_services?&action=stop_success') else: return django.http.HttpResponseRedirect('/view_services?&action=stop_fail') except Exception, e: return_dict['base_template'] = "services_base.html" return_dict["page_title"] = 'Modify system service state' return_dict['tab'] = 'view_services_tab' return_dict["error"] = 'Error modifying system services state' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def upload_ssh_user_key(request): return_dict = {} user = request.GET.get('user','replicator') return_dict["selected_user"] = user if request.method == 'POST': try: # This works for user deleting the key files. This should be moved to a new function in itself authorized_key = request.POST.get('authorized_key',None) if authorized_key: description = "" user = request.POST.get("selected_user") key = request.POST.get("authorized_key") description = "%s" %(user) audit.audit ("remove_ssh_user_key", description, request.META) files = open((pki._get_authorized_file(user)), 'r').readlines() authorized_keys = open(pki._get_authorized_file(user),'w') for file in files: if key.strip() != file.strip(): authorized_keys.write(file) ack_message = "key_deleted" # This works for user uploading new keys else: desscription = "" authorized_key = request.FILES.get('pub_key') user = request.POST.get('user') description = "%s %s" %(user, authorized_key) audit.audit ("upload_ssh_user_key", description, request.META) with open('/%s/authorized_keys'%(pki._get_ssh_dir(user)), 'ab') as destination: for chunk in authorized_key.chunks(): destination.write(chunk) perm,err = pki.ssh_dir_permissions(user) if err: raise Exception(err) ack_message = "key_added" return django.http.HttpResponseRedirect("/user_ssh_keys/?ack=%s&user=%s"%(ack_message,user)) except Exception,e: return_dict['base_template'] = "key_management_base.html" return_dict["page_title"] = 'Upload a Public Key' return_dict['tab'] = 'upload_public_key_tab' return_dict["error"] = 'Error adding Public key. Please check the value' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_local_user(request): return_dict = {} try: if "userid" not in request.REQUEST: return_dict["error"] = "Invalid request. No user name specified." return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request) ) if request.method == "GET": # Return the form return_dict["userid"] = request.GET["userid"] return django.shortcuts.render_to_response( "delete_local_user_conf.html", return_dict, context_instance=django.template.context.RequestContext(request), ) else: # Form submission so create return_dict = {} try: ret = local_users.delete_local_user(request.POST["userid"]) audit_str = "Deleted a local user %s" % request.POST["userid"] audit.audit("delete_local_user", audit_str, request.META["REMOTE_ADDR"]) url = "/view_local_users?action=deleted" if ret: warnings = ",".join(ret) url = "%s&warnings=%s" % (url, warnings) return django.http.HttpResponseRedirect(url) except Exception, e: return_dict["error"] = "Error deleting the local user - %s" % e return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request), ) except Exception, e: s = str(e) return_dict["error"] = "An error occurred when processing your request : %s" % s return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request) )
def create_dir(request): return_dict = {} try: if not "error" in return_dict: if "ack" in request.GET: if request.GET["ack"] == "ace_deleted": return_dict['ack_message'] = "ACL entry successfully removed" elif request.GET["ack"] == "aces_added": return_dict['ack_message'] = "ACL entries successfully added" elif request.GET["ack"] == "aces_modified": return_dict['ack_message'] = "ACL entries successfully modified" if 'path' not in request.REQUEST: raise Exception('Unspecified base directory. Please use the menus.') path = request.REQUEST['path'] try: stat_info = os.stat(path) except Exception, e: raise Exception('Error accessing specified base directory : %s'%str(e)) return_dict['path'] = path if request.method == "GET": # Set initial form values initial = {} initial['path'] = path form = folder_management_forms.CreateDirForm(initial = initial) return_dict['form'] = form return django.shortcuts.render_to_response('create_dir.html', return_dict, context_instance=django.template.context.RequestContext(request)) else: form = folder_management_forms.CreateDirForm(request.POST) if form.is_valid(): cd = form.cleaned_data dir_name = cd['dir_name'] directory = path +"/"+dir_name if os.path.exists(directory): raise Exception('The specified directory already exists') os.makedirs(directory) os.chown(directory, 1000, 1000) audit_str = "Created new directory '%s' in '%s'" %(dir_name, path) audit.audit("create_dir", audit_str, request.META) return django.http.HttpResponseRedirect('/dir_manager/?ack=created_dir') else: return_dict['form'] = form return django.shortcuts.render_to_response('create_dir.html', return_dict, context_instance=django.template.context.RequestContext(request))
def edit_dns_nameservers(request): return_dict = {} try: ns_list, err = networking.get_name_servers() if err: raise Exception(err) if request.method=="GET": if not ns_list: form = networking_forms.DNSNameServersForm() else: form = networking_forms.DNSNameServersForm(initial={'nameservers': ','.join(ns_list)}) url = "edit_dns_nameservers.html" else: form = networking_forms.DNSNameServersForm(request.POST) if form.is_valid(): cd = form.cleaned_data nameservers = cd["nameservers"] if ',' in nameservers: slist = nameservers.split(',') else: slist = nameservers.split(' ') res, err = networking.set_name_servers(slist) if not res: if err: raise Exception(err) else: raise Exception('Error updating nameservers') audit_str = "Updated the DNS nameserver list to %s"%nameservers audit.audit("set_dns_nameservers", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect('/view_dns_nameservers?action=saved') else: #invalid form url = "edit_dns_nameservers.html" return_dict["form"] = form return django.shortcuts.render_to_response(url, return_dict, context_instance = django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = "networking_base.html" return_dict["page_title"] = 'Modify DNS servers' return_dict['tab'] = 'view_dns_nameservers_tab' return_dict["error"] = 'Error modifying DNS servers' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def remove_vlan(request): return_dict = {} try: if 'name' not in request.REQUEST: raise Exception("No VLAN name specified. Please use the menus") name = request.REQUEST["name"] return_dict["name"] = name if request.method == "GET": #Return the conf page return django.shortcuts.render_to_response( "remove_vlan_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: result, err = networking.remove_vlan(name) if not result: if not err: raise Exception("Error removing VLAN") else: raise Exception(err) result, err = networking.restart_networking() if err: raise Exception(err) audit_str = "Removed VLAN %s" % (name) audit.audit("remove_vlan", audit_str, request.META) return django.http.HttpResponseRedirect( '/view_interfaces?ack=removed_vlan') except Exception, e: return_dict['base_template'] = "networking_base.html" return_dict["page_title"] = 'Remove a VLAN' return_dict['tab'] = 'view_interfaces_tab' return_dict["error"] = 'Error removing a VLAN' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_nfs_share(request): return_dict = {} try: pools, err = zfs.get_pools() if err: raise Exception(err) ds_list = [] for pool in pools: for ds in pool["datasets"]: if ds['properties']['type']['value'] == 'filesystem': ds_list.append({'name': ds["name"], 'mountpoint': ds["mountpoint"]}) if not ds_list: raise Exception('No ZFS datasets available. Please create a dataset before creating shares.') if request.method == "GET": #Return the conf page form = nfs_shares_forms.CreateShareForm(dataset_list = ds_list) return_dict['form'] = form return django.shortcuts.render_to_response("create_nfs_share.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: form = nfs_shares_forms.CreateShareForm(request.POST, dataset_list = ds_list) path = request.POST.get("path") return_dict['form'] = form if not form.is_valid(): return django.shortcuts.render_to_response("create_nfs_share.html", return_dict, context_instance = django.template.context.RequestContext(request)) cd = form.cleaned_data result, err = nfs.save_share(cd, True) if err: raise Exception(err) audit_str = "Created NFS share %s"%path audit.audit("create_nfs_share", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect('/view_nfs_shares?action=created') except Exception, e: return_dict['base_template'] = "networking_base.html" return_dict["page_title"] = 'Create a NFS share ' return_dict['tab'] = 'view_nfs_shares_tab' return_dict["error"] = 'Error creating a NFS share' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def delete_local_group(request): return_dict = {} try: if "grpname" not in request.REQUEST: raise Exception("Invalid request. No group name specified.") gd, err = local_users.get_local_group(request.REQUEST['grpname']) if err or (not gd): if err: raise Exception(err) else: raise Exception("Could not retrieve group information") if gd['members']: raise Exception("Cannot delete this group as it has the following members : %s"%(','.join(gd['members']))) if request.method == "GET": #Return the form return_dict["grpname"] = request.GET["grpname"] return django.shortcuts.render_to_response("delete_local_group_conf.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: #Form submission so create return_dict = {} ret, err = local_users.delete_local_group(request.POST["grpname"]) if not ret: if err: raise Exception('Error deleting group : %s'%err) else: raise Exception('Error deleting group') audit_str = "Deleted a local group %s"%request.POST["grpname"] audit.audit("delete_local_group", audit_str, request.META["REMOTE_ADDR"]) url = '/view_local_groups?action=deleted' return django.http.HttpResponseRedirect(url) except Exception, e: return_dict['base_template'] = 'users-groups_base.html' return_dict["page_title"] = 'Delete a local user group' return_dict['tab'] = 'view_local_groups_tab' return_dict["error"] = 'Error deleting a local user group' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def change_local_user_password(request): return_dict = {} try: if request.method == "GET": #Return the form if "username" not in request.GET: raise Exception("Invalid request. No user name specified.") d = {} d["username"] = request.GET["username"] form = local_user_forms.PasswordChangeForm(initial=d) return_dict["form"] = form return django.shortcuts.render_to_response("change_local_user_password.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: #Form submission so create return_dict = {} form = local_user_forms.PasswordChangeForm(request.POST) if form.is_valid(): cd = form.cleaned_data rc, err = local_users.change_password(cd["username"], cd["password"]) if not rc: if err: raise Exception(err) else: raise Exception("Error changing the local user password") audit_str = "Changed password for local user %s"%cd["username"] audit.audit("change_local_user_password", audit_str, request.META["REMOTE_ADDR"]) return django.http.HttpResponseRedirect('/view_local_users?action=changed_password') else: return_dict["form"] = form return django.shortcuts.render_to_response("change_local_user_password.html", return_dict, context_instance = django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = 'users-groups_base.html' return_dict["page_title"] = "Modify local user's password" return_dict['tab'] = 'view_local_users_tab' return_dict["error"] = "Error modifying local user's password" return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_local_user(request): return_dict = {} try: if request.method == "GET": #Return the form form = samba_shares_forms.LocalUserForm() return_dict["form"] = form return django.shortcuts.render_to_response( "create_local_user.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: #Form submission so create return_dict = {} form = samba_shares_forms.LocalUserForm(request.POST) if form.is_valid(): cd = form.cleaned_data try: ret = local_users.create_local_user( cd["userid"], cd["name"], cd["password"]) audit_str = "Created a local user %s" % cd["userid"] audit.audit("create_local_user", audit_str, request.META["REMOTE_ADDR"]) url = '/view_local_users?action=created' if ret: warnings = ','.join(ret) url = "%s&warnings=%s" % (url, warnings) return django.http.HttpResponseRedirect(url) except Exception, e: return_dict[ "error"] = "Error creating the local user - %s" % e return django.shortcuts.render_to_response( 'logged_in_error.html', return_dict, context_instance=django.template.context. RequestContext(request)) else:
def delete_local_user(request): return_dict = {} try: if "username" not in request.REQUEST: raise Exception("Invalid request. No user name specified.") if request.method == "GET": #Return the form return_dict["username"] = request.GET["username"] return django.shortcuts.render_to_response( "delete_local_user_conf.html", return_dict, context_instance=django.template.context.RequestContext( request)) else: #Form submission so create return_dict = {} ret, err = local_users.delete_local_user(request.POST["username"]) if not ret: if err: raise Exception(err) else: raise Exception('Error deleting local user') audit_str = "Deleted a local user %s" % request.POST["username"] audit.audit("delete_local_user", audit_str, request.META) url = '/view_local_users?ack=deleted' return django.http.HttpResponseRedirect(url) except Exception, e: return_dict['base_template'] = 'users-groups_base.html' return_dict["page_title"] = 'Delete a local user' return_dict['tab'] = 'view_local_users_tab' return_dict["error"] = 'Error deleting a local user' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response( "logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_local_group(request): return_dict = {} try: if request.method == "GET": #Return the form form = local_user_forms.LocalGroupForm() return_dict["form"] = form return django.shortcuts.render_to_response("create_local_group.html", return_dict, context_instance = django.template.context.RequestContext(request)) else: #Form submission so create return_dict = {} #print '1' form = local_user_forms.LocalGroupForm(request.POST) if form.is_valid(): #print '2' cd = form.cleaned_data ret, err = local_users.create_local_group(cd["grpname"]) #print '3' if not ret: if err: raise Exception(err) else: raise Exception("Error creating the local group.") audit_str = "Created a local group %s"%cd["grpname"] audit.audit("create_local_group", audit_str, request.META["REMOTE_ADDR"]) url = '/view_local_groups?action=created' return django.http.HttpResponseRedirect(url) else: return_dict["form"] = form return django.shortcuts.render_to_response("create_local_group.html", return_dict, context_instance = django.template.context.RequestContext(request)) except Exception, e: return_dict['base_template'] = 'users-groups_base.html' return_dict["page_title"] = 'Create a local user group' return_dict['tab'] = 'view_local_groups_tab' return_dict["error"] = 'Error create a local user group' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def remove_background_task(request): return_dict = {} try: if 'task_id' not in request.REQUEST: raise Exception('Invalid request. Please use the menus.') task, err = scheduler_utils.get_task(request.REQUEST['task_id']) if err: raise Exception(err) ret, err = scheduler_utils.remove_task(request.REQUEST['task_id']) if err: raise Exception(err) audit.audit("remove_background_task", task['description'], request.META) return django.http.HttpResponseRedirect('/view_background_tasks?ack=deleted') except Exception, e: return_dict['base_template'] = "scheduler_base.html" return_dict["page_title"] = 'Background tasks' return_dict['tab'] = 'view_background_tasks_tab' return_dict["error"] = 'Error removing background task' return_dict["error_details"] = str(e) return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))