<s> from collections import defaultdict , OrderedDict <EOL> from datetime import datetime <EOL> import cPickle as pickle <EOL> import json <EOL> import logging <EOL> import math <EOL> import os <EOL> import re <EOL> import stat <EOL> import subprocess <EOL> from OpenSSL import crypto <EOL> from django . conf import settings <EOL> from django . contrib . formtools . wizard . views import SessionWizardView <EOL> from django . core . files . storage import FileSystemStorage <EOL> from django . db import transaction <EOL> from django . db . models import Q <EOL> from django . forms import FileField <EOL> from django . forms . formsets import BaseFormSet , formset_factory <EOL> from django . http import HttpResponse <EOL> from django . shortcuts import render_to_response <EOL> from django . utils . html import escapejs <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . utils . translation import ugettext as __ <EOL> from dojango import forms <EOL> from freenasOS import Configuration , Update <EOL> from freenasUI import choices <EOL> from freenasUI . account . models import bsdGroups , bsdUsers <EOL> from freenasUI . common import humanize_size , humanize_number_si <EOL> from freenasUI . common . forms import ModelForm , Form <EOL> from freenasUI . common . freenasldap import ( <EOL> FreeNAS_ActiveDirectory , <EOL> FreeNAS_LDAP <EOL> ) <EOL> from freenasUI . common . ssl import ( <EOL> create_self_signed_CA , <EOL> create_certificate_signing_request , <EOL> create_certificate , <EOL> sign_certificate , <EOL> load_certificate , <EOL> load_privatekey , <EOL> export_privatekey , <EOL> generate_key <EOL> ) <EOL> from freenasUI . directoryservice . forms import ( <EOL> ActiveDirectoryForm , <EOL> LDAPForm , <EOL> NISForm , <EOL> NT4Form , <EOL> ) <EOL> from freenasUI . directoryservice . models import ( <EOL> ActiveDirectory , <EOL> LDAP , <EOL> NIS , <EOL> NT4 , <EOL> ) <EOL> from freenasUI . freeadmin . views import JsonResp <EOL> from freenasUI . middleware . exceptions import MiddlewareError <EOL> from freenasUI . middleware . notifier import notifier <EOL> from freenasUI . services . models import ( <EOL> services , <EOL> iSCSITarget , <EOL> iSCSITargetGroups , <EOL> iSCSITargetAuthorizedInitiator , <EOL> iSCSITargetExtent , <EOL> iSCSITargetPortal , <EOL> iSCSITargetPortalIP , <EOL> iSCSITargetToExtent , <EOL> ) <EOL> from freenasUI . sharing . models import ( <EOL> AFP_Share , <EOL> CIFS_Share , <EOL> NFS_Share , <EOL> NFS_Share_Path , <EOL> ) <EOL> from freenasUI . storage . forms import VolumeAutoImportForm <EOL> from freenasUI . storage . models import Disk , Volume , Scrub <EOL> from freenasUI . system import models <EOL> from freenasUI . tasks . models import SMARTTest <EOL> log = logging . getLogger ( '<STR_LIT>' ) <EOL> WIZARD_PROGRESSFILE = '<STR_LIT>' <EOL> def clean_path_execbit ( path ) : <EOL> """<STR_LIT>""" <EOL> current = path <EOL> while True : <EOL> try : <EOL> mode = os . stat ( current ) . st_mode <EOL> if mode & stat . S_IXOTH == <NUM_LIT:0> : <EOL> raise forms . ValidationError ( <EOL> _ ( "<STR_LIT>" ) % ( <EOL> current , <EOL> ) <EOL> ) <EOL> except OSError : <EOL> break <EOL> current = os . path . realpath ( os . path . join ( current , os . path . pardir ) ) <EOL> if current == '<STR_LIT:/>' : <EOL> break <EOL> def clean_path_locked ( mp ) : <EOL> qs = Volume . objects . filter ( vol_name = mp . replace ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if qs . exists ( ) : <EOL> obj = qs [ <NUM_LIT:0> ] <EOL> if not obj . is_decrypted ( ) : <EOL> raise forms . ValidationError ( <EOL> _ ( "<STR_LIT>" ) % ( <EOL> obj . vol_name , <EOL> ) <EOL> ) <EOL> class BootEnvAddForm ( Form ) : <EOL> name = forms . CharField ( <EOL> label = _ ( '<STR_LIT:Name>' ) , <EOL> max_length = <NUM_LIT:50> , <EOL> ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . _source = kwargs . pop ( '<STR_LIT:source>' , None ) <EOL> super ( BootEnvAddForm , self ) . __init__ ( * args , ** kwargs ) <EOL> def clean_name ( self ) : <EOL> name = self . cleaned_data . get ( '<STR_LIT:name>' ) <EOL> if not re . search ( r'<STR_LIT>' , name , re . I ) : <EOL> raise forms . ValidationError ( <EOL> _ ( '<STR_LIT>' ) <EOL> ) <EOL> return name <EOL> def save ( self , * args , ** kwargs ) : <EOL> kwargs = { } <EOL> if self . _source : <EOL> kwargs [ '<STR_LIT>' ] = self . _source <EOL> clone = Update . CreateClone ( <EOL> self . cleaned_data . get ( '<STR_LIT:name>' ) , <EOL> ** kwargs <EOL> ) <EOL> if clone is False : <EOL> raise MiddlewareError ( _ ( '<STR_LIT>' ) ) <EOL> class BootEnvRenameForm ( Form ) : <EOL> name = forms . CharField ( <EOL> label = _ ( '<STR_LIT:Name>' ) , <EOL> max_length = <NUM_LIT:50> , <EOL> ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . _name = kwargs . pop ( '<STR_LIT:name>' ) <EOL> super ( BootEnvRenameForm , self ) . __init__ ( * args , ** kwargs ) <EOL> def save ( self , * args , ** kwargs ) : <EOL> rename = Update . RenameClone ( <EOL> self . _name , <EOL> self . cleaned_data . get ( '<STR_LIT:name>' ) , <EOL> ) <EOL> if rename is False : <EOL> raise MiddlewareError ( _ ( '<STR_LIT>' ) ) <EOL> class BootEnvPoolAttachForm ( Form ) : <EOL> attach_disk = forms . ChoiceField ( <EOL> choices = ( ) , <EOL> widget = forms . Select ( ) , <EOL> label = _ ( '<STR_LIT>' ) ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . label = kwargs . pop ( '<STR_LIT:label>' ) <EOL> super ( BootEnvPoolAttachForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fields [ '<STR_LIT>' ] . choices = self . _populate_disk_choices ( ) <EOL> self . fields [ '<STR_LIT>' ] . choices . sort ( <EOL> key = lambda a : float ( <EOL> re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , a [ <NUM_LIT:0> ] ) <EOL> ) <EOL> ) <EOL> def _populate_disk_choices ( self ) : <EOL> diskchoices = dict ( ) <EOL> used_disks = [ ] <EOL> for v in Volume . objects . all ( ) : <EOL> used_disks . extend ( v . get_disks ( ) ) <EOL> disks = notifier ( ) . get_disks ( ) <EOL> for disk in disks : <EOL> if disk in used_disks : <EOL> continue <EOL> devname , capacity = disks [ disk ] [ '<STR_LIT>' ] , disks [ disk ] [ '<STR_LIT>' ] <EOL> capacity = humanize_number_si ( int ( capacity ) ) <EOL> diskchoices [ devname ] = "<STR_LIT>" % ( devname , capacity ) <EOL> choices = diskchoices . items ( ) <EOL> choices . sort ( key = lambda a : float ( <EOL> re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , a [ <NUM_LIT:0> ] ) <EOL> ) ) <EOL> return choices <EOL> def done ( self ) : <EOL> devname = self . cleaned_data [ '<STR_LIT>' ] <EOL> rv = notifier ( ) . bootenv_attach_disk ( self . label , devname ) <EOL> if rv : <EOL> notifier ( ) . sync_disks ( ) <EOL> return True <EOL> else : <EOL> return False <EOL> class BootEnvPoolReplaceForm ( Form ) : <EOL> replace_disk = forms . ChoiceField ( <EOL> choices = ( ) , <EOL> widget = forms . Select ( ) , <EOL> label = _ ( '<STR_LIT>' ) ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . label = kwargs . pop ( '<STR_LIT:label>' ) <EOL> super ( BootEnvPoolReplaceForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fields [ '<STR_LIT>' ] . choices = self . _populate_disk_choices ( ) <EOL> self . fields [ '<STR_LIT>' ] . choices . sort ( <EOL> key = lambda a : float ( <EOL> re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , a [ <NUM_LIT:0> ] ) <EOL> ) <EOL> ) <EOL> def _populate_disk_choices ( self ) : <EOL> diskchoices = dict ( ) <EOL> used_disks = [ ] <EOL> for v in Volume . objects . all ( ) : <EOL> used_disks . extend ( v . get_disks ( ) ) <EOL> disks = notifier ( ) . get_disks ( ) <EOL> for disk in disks : <EOL> if disk in used_disks : <EOL> continue <EOL> devname , capacity = disks [ disk ] [ '<STR_LIT>' ] , disks [ disk ] [ '<STR_LIT>' ] <EOL> capacity = humanize_number_si ( int ( capacity ) ) <EOL> diskchoices [ devname ] = "<STR_LIT>" % ( devname , capacity ) <EOL> choices = diskchoices . items ( ) <EOL> choices . sort ( key = lambda a : float ( <EOL> re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , a [ <NUM_LIT:0> ] ) <EOL> ) ) <EOL> return choices <EOL> def done ( self ) : <EOL> devname = self . cleaned_data [ '<STR_LIT>' ] <EOL> rv = notifier ( ) . bootenv_replace_disk ( self . label , devname ) <EOL> if rv == <NUM_LIT:0> : <EOL> notifier ( ) . sync_disks ( ) <EOL> return True <EOL> else : <EOL> return False <EOL> class CommonWizard ( SessionWizardView ) : <EOL> template_done = '<STR_LIT>' <EOL> def done ( self , form_list , ** kwargs ) : <EOL> response = render_to_response ( self . template_done , { <EOL> '<STR_LIT>' : getattr ( self , '<STR_LIT>' , None ) , <EOL> } ) <EOL> if not self . request . is_ajax ( ) : <EOL> response . content = ( <EOL> "<STR_LIT>" <EOL> + response . content + <EOL> "<STR_LIT>" <EOL> ) <EOL> return response <EOL> def process_step ( self , form ) : <EOL> proc = super ( CommonWizard , self ) . process_step ( form ) <EOL> """<STR_LIT>""" <EOL> if hasattr ( form , '<STR_LIT>' ) : <EOL> retval = form . done ( <EOL> request = self . request , <EOL> form_list = self . form_list , <EOL> wizard = self ) <EOL> if self . get_step_index ( ) == self . steps . count - <NUM_LIT:1> : <EOL> self . retval = retval <EOL> return proc <EOL> def render_to_response ( self , context , ** kwargs ) : <EOL> response = super ( CommonWizard , self ) . render_to_response ( <EOL> context , <EOL> ** kwargs ) <EOL> if not self . request . is_ajax ( ) : <EOL> return HttpResponse ( <EOL> "<STR_LIT>" <EOL> + response . rendered_content + <EOL> "<STR_LIT>" <EOL> ) <EOL> return response <EOL> class FileWizard ( CommonWizard ) : <EOL> file_storage = FileSystemStorage ( location = '<STR_LIT>' ) <EOL> class InitialWizard ( CommonWizard ) : <EOL> template_done = '<STR_LIT>' <EOL> def get_template_names ( self ) : <EOL> return [ <EOL> '<STR_LIT>' % self . steps . current , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> def get_context_data ( self , form , ** kwargs ) : <EOL> context = super ( InitialWizard , self ) . get_context_data ( form , ** kwargs ) <EOL> if self . steps . last : <EOL> context [ '<STR_LIT>' ] = self . get_form_list ( ) . keys ( ) <EOL> return context <EOL> def done ( self , form_list , ** kwargs ) : <EOL> events = [ ] <EOL> curstep = <NUM_LIT:0> <EOL> progress = { <EOL> '<STR_LIT>' : curstep , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } <EOL> with open ( WIZARD_PROGRESSFILE , '<STR_LIT:wb>' ) as f : <EOL> f . write ( pickle . dumps ( progress ) ) <EOL> cleaned_data = self . get_all_cleaned_data ( ) <EOL> volume_name = cleaned_data . get ( '<STR_LIT>' ) <EOL> volume_type = cleaned_data . get ( '<STR_LIT>' ) <EOL> shares = cleaned_data . get ( '<STR_LIT>' ) <EOL> form_list = self . get_form_list ( ) <EOL> volume_form = form_list . get ( '<STR_LIT>' ) <EOL> volume_import = form_list . get ( '<STR_LIT>' ) <EOL> ds_form = form_list . get ( '<STR_LIT>' ) <EOL> with transaction . atomic ( ) : <EOL> _n = notifier ( ) <EOL> if volume_form or volume_import : <EOL> curstep += <NUM_LIT:1> <EOL> progress [ '<STR_LIT>' ] = curstep <EOL> with open ( WIZARD_PROGRESSFILE , '<STR_LIT:wb>' ) as f : <EOL> f . write ( pickle . dumps ( progress ) ) <EOL> if volume_import : <EOL> volume_name , guid = cleaned_data . get ( <EOL> '<STR_LIT>' <EOL> ) . split ( '<STR_LIT:|>' ) <EOL> if not _n . zfs_import ( volume_name , guid ) : <EOL> raise MiddlewareError ( _ ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) % volume_name ) <EOL> volume = Volume ( <EOL> vol_name = volume_name , <EOL> vol_fstype = '<STR_LIT>' , <EOL> ) <EOL> volume . save ( ) <EOL> Scrub . objects . create ( scrub_volume = volume ) <EOL> if volume_form : <EOL> bysize = volume_form . _get_unused_disks_by_size ( ) <EOL> if volume_type == '<STR_LIT>' : <EOL> groups = volume_form . _grp_autoselect ( bysize ) <EOL> else : <EOL> groups = volume_form . _grp_predefined ( bysize , volume_type ) <EOL> _n . init ( <EOL> "<STR_LIT>" , <EOL> volume , <EOL> groups = groups , <EOL> init_rand = False , <EOL> ) <EOL> disks = [ ] <EOL> for o in SMARTTest . objects . all ( ) : <EOL> for disk in o . smarttest_disks . all ( ) : <EOL> if disk . pk not in disks : <EOL> disks . append ( disk . pk ) <EOL> qs = Disk . objects . filter ( disk_enabled = True ) . exclude ( pk__in = disks ) <EOL> if qs . exists ( ) : <EOL> smarttest = SMARTTest . objects . create ( <EOL> smarttest_type = '<STR_LIT:S>' , <EOL> smarttest_dayweek = '<STR_LIT>' , <EOL> ) <EOL> smarttest . smarttest_disks . add ( * list ( qs ) ) <EOL> else : <EOL> volume = Volume . objects . filter ( vol_fstype = '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> volume_name = volume . vol_name <EOL> curstep += <NUM_LIT:1> <EOL> progress [ '<STR_LIT>' ] = curstep <EOL> progress [ '<STR_LIT>' ] = False <EOL> progress [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> with open ( WIZARD_PROGRESSFILE , '<STR_LIT:wb>' ) as f : <EOL> f . write ( pickle . dumps ( progress ) ) <EOL> services_restart = [ ] <EOL> for i , share in enumerate ( shares ) : <EOL> if not share : <EOL> continue <EOL> share_name = share . get ( '<STR_LIT>' ) <EOL> share_purpose = share . get ( '<STR_LIT>' ) <EOL> share_allowguest = share . get ( '<STR_LIT>' ) <EOL> share_timemachine = share . get ( '<STR_LIT>' ) <EOL> share_iscsisize = share . get ( '<STR_LIT>' ) <EOL> share_user = share . get ( '<STR_LIT>' ) <EOL> share_usercreate = share . get ( '<STR_LIT>' ) <EOL> share_userpw = share . get ( '<STR_LIT>' ) <EOL> share_group = share . get ( '<STR_LIT>' ) <EOL> share_groupcreate = share . get ( '<STR_LIT>' ) <EOL> share_mode = share . get ( '<STR_LIT>' ) <EOL> if share_purpose != '<STR_LIT>' : <EOL> dataset_name = '<STR_LIT>' % ( volume_name , share_name ) <EOL> errno , errmsg = _n . create_zfs_dataset ( <EOL> dataset_name , <EOL> _restart_collectd = False , <EOL> ) <EOL> if share_purpose == '<STR_LIT>' : <EOL> _n . change_dataset_share_type ( dataset_name , '<STR_LIT>' ) <EOL> elif share_purpose == '<STR_LIT>' : <EOL> _n . change_dataset_share_type ( dataset_name , '<STR_LIT>' ) <EOL> elif share_purpose == '<STR_LIT>' : <EOL> _n . change_dataset_share_type ( dataset_name , '<STR_LIT>' ) <EOL> qs = bsdGroups . objects . filter ( bsdgrp_group = share_group ) <EOL> if not qs . exists ( ) : <EOL> if share_groupcreate : <EOL> gid = _n . group_create ( share_group ) <EOL> group = bsdGroups . objects . create ( <EOL> bsdgrp_gid = gid , <EOL> bsdgrp_group = share_group , <EOL> ) <EOL> else : <EOL> group = bsdGroups . objects . all ( ) [ <NUM_LIT:0> ] <EOL> else : <EOL> group = qs [ <NUM_LIT:0> ] <EOL> qs = bsdUsers . objects . filter ( bsdusr_username = share_user ) <EOL> if not qs . exists ( ) : <EOL> if share_usercreate : <EOL> if share_userpw : <EOL> password = share_userpw . encode ( '<STR_LIT:utf8>' ) <EOL> password_disabled = False <EOL> else : <EOL> password = '<STR_LIT:!>' <EOL> password_disabled = True <EOL> uid , gid , unixhash , smbhash = _n . user_create ( <EOL> username = share_user , <EOL> fullname = share_user , <EOL> password = password , <EOL> shell = '<STR_LIT>' , <EOL> homedir = '<STR_LIT>' , <EOL> password_disabled = password_disabled <EOL> ) <EOL> bsdUsers . objects . create ( <EOL> bsdusr_username = share_user , <EOL> bsdusr_full_name = share_user , <EOL> bsdusr_uid = uid , <EOL> bsdusr_group = group , <EOL> bsdusr_unixhash = unixhash , <EOL> bsdusr_smbhash = smbhash , <EOL> ) <EOL> else : <EOL> errno , errmsg = _n . create_zfs_vol ( <EOL> '<STR_LIT>' % ( volume_name , share_name ) , <EOL> share_iscsisize , <EOL> sparse = True , <EOL> ) <EOL> if errno > <NUM_LIT:0> : <EOL> raise MiddlewareError ( <EOL> _ ( '<STR_LIT>' ) % errmsg <EOL> ) <EOL> path = '<STR_LIT>' % ( volume_name , share_name ) <EOL> sharekwargs = { } <EOL> if '<STR_LIT>' == share_purpose : <EOL> if share_allowguest : <EOL> sharekwargs [ '<STR_LIT>' ] = True <EOL> CIFS_Share . objects . create ( <EOL> cifs_name = share_name , <EOL> cifs_path = path , <EOL> ** sharekwargs <EOL> ) <EOL> if '<STR_LIT>' == share_purpose : <EOL> if share_timemachine : <EOL> sharekwargs [ '<STR_LIT>' ] = True <EOL> AFP_Share . objects . create ( <EOL> afp_name = share_name , <EOL> afp_path = path , <EOL> ** sharekwargs <EOL> ) <EOL> if '<STR_LIT>' == share_purpose : <EOL> nfs_share = NFS_Share . objects . create ( <EOL> nfs_comment = share_name , <EOL> ) <EOL> NFS_Share_Path . objects . create ( <EOL> share = nfs_share , <EOL> path = path , <EOL> ) <EOL> if '<STR_LIT>' == share_purpose : <EOL> qs = iSCSITargetPortal . objects . all ( ) <EOL> if qs . exists ( ) : <EOL> portal = qs [ <NUM_LIT:0> ] <EOL> else : <EOL> portal = iSCSITargetPortal . objects . create ( ) <EOL> iSCSITargetPortalIP . objects . create ( <EOL> iscsi_target_portalip_portal = portal , <EOL> iscsi_target_portalip_ip = '<STR_LIT>' , <EOL> ) <EOL> qs = iSCSITargetAuthorizedInitiator . objects . all ( ) <EOL> if qs . exists ( ) : <EOL> authini = qs [ <NUM_LIT:0> ] <EOL> else : <EOL> authini = ( <EOL> iSCSITargetAuthorizedInitiator . objects . create ( ) <EOL> ) <EOL> try : <EOL> nic = list ( choices . NICChoices ( <EOL> nolagg = True , novlan = True , exclude_configured = False ) <EOL> ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> mac = subprocess . Popen ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( nic , ) , <EOL> shell = True , <EOL> stdout = subprocess . PIPE ) . communicate ( ) [ <NUM_LIT:0> ] <EOL> ltg = iSCSITargetExtent . objects . order_by ( '<STR_LIT>' ) <EOL> if ltg . count ( ) > <NUM_LIT:0> : <EOL> lid = ltg [ <NUM_LIT:0> ] . id <EOL> else : <EOL> lid = <NUM_LIT:0> <EOL> serial = mac . strip ( ) + "<STR_LIT>" % lid <EOL> except : <EOL> serial = "<STR_LIT>" <EOL> target = iSCSITarget . objects . create ( <EOL> iscsi_target_name = '<STR_LIT>' % share_name , <EOL> ) <EOL> iSCSITargetGroups . objects . create ( <EOL> iscsi_target = target , <EOL> iscsi_target_portalgroup = portal , <EOL> iscsi_target_initiatorgroup = authini , <EOL> ) <EOL> iscsi_target_extent_path = '<STR_LIT>' % ( <EOL> volume_name , <EOL> share_name , <EOL> ) <EOL> extent = iSCSITargetExtent . objects . create ( <EOL> iscsi_target_extent_name = '<STR_LIT>' % share_name , <EOL> iscsi_target_extent_type = '<STR_LIT>' , <EOL> iscsi_target_extent_path = iscsi_target_extent_path , <EOL> iscsi_target_extent_serial = serial , <EOL> ) <EOL> iSCSITargetToExtent . objects . create ( <EOL> iscsi_target = target , <EOL> iscsi_extent = extent , <EOL> ) <EOL> if share_purpose not in services_restart : <EOL> services . objects . filter ( srv_service = share_purpose ) . update ( <EOL> srv_enable = True <EOL> ) <EOL> services_restart . append ( share_purpose ) <EOL> progress [ '<STR_LIT>' ] = int ( <EOL> ( float ( i + <NUM_LIT:1> ) / float ( len ( shares ) ) ) * <NUM_LIT:100> <EOL> ) <EOL> with open ( WIZARD_PROGRESSFILE , '<STR_LIT:wb>' ) as f : <EOL> f . write ( pickle . dumps ( progress ) ) <EOL> console = cleaned_data . get ( '<STR_LIT>' ) <EOL> adv = models . Advanced . objects . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> advdata = dict ( adv . __dict__ ) <EOL> advdata [ '<STR_LIT>' ] = console <EOL> advdata . pop ( '<STR_LIT>' , None ) <EOL> advform = AdvancedForm ( <EOL> advdata , <EOL> instance = adv , <EOL> ) <EOL> if advform . is_valid ( ) : <EOL> advform . save ( ) <EOL> advform . done ( self . request , events ) <EOL> if cleaned_data . get ( '<STR_LIT>' ) : <EOL> bsdUsers . objects . filter ( bsdusr_uid = <NUM_LIT:0> ) . update ( <EOL> bsdusr_email = cleaned_data . get ( '<STR_LIT>' ) , <EOL> ) <EOL> email = models . Email . objects . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> em = EmailForm ( cleaned_data , instance = email ) <EOL> if em . is_valid ( ) : <EOL> em . save ( ) <EOL> try : <EOL> settingsm = models . Settings . objects . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> settingsm = models . Settings . objects . create ( ) <EOL> settingsdata = settingsm . __dict__ <EOL> settingsdata . update ( { <EOL> '<STR_LIT>' : cleaned_data . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : cleaned_data . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : cleaned_data . get ( '<STR_LIT>' ) , <EOL> } ) <EOL> settingsform = SettingsForm ( <EOL> data = settingsdata , <EOL> instance = settingsm , <EOL> ) <EOL> if settingsform . is_valid ( ) : <EOL> settingsform . save ( ) <EOL> else : <EOL> log . warn ( <EOL> '<STR_LIT>' , <EOL> settingsform . _errors , <EOL> ) <EOL> if ds_form : <EOL> curstep += <NUM_LIT:1> <EOL> progress [ '<STR_LIT>' ] = curstep <EOL> progress [ '<STR_LIT>' ] = True <EOL> with open ( WIZARD_PROGRESSFILE , '<STR_LIT:wb>' ) as f : <EOL> f . write ( pickle . dumps ( progress ) ) <EOL> if cleaned_data . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> try : <EOL> ad = ActiveDirectory . objects . all ( ) . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> except : <EOL> ad = ActiveDirectory . objects . create ( ) <EOL> addata = ad . __dict__ <EOL> addata . update ( { <EOL> '<STR_LIT>' : cleaned_data . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : cleaned_data . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : cleaned_data . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : True , <EOL> } ) <EOL> adform = ActiveDirectoryForm ( <EOL> data = addata , <EOL> instance = ad , <EOL> ) <EOL> if adform . is_valid ( ) : <EOL> adform . save ( ) <EOL> else : <EOL> log . warn ( <EOL> '<STR_LIT>' , <EOL> adform . _errors , <EOL> ) <EOL> elif cleaned_data . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> try : <EOL> ldap = LDAP . objects . all ( ) . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> except : <EOL> ldap = LDAP . objects . create ( ) <EOL> ldapdata = ldap . __dict__ <EOL> ldapdata . update ( { <EOL> '<STR_LIT>' : cleaned_data . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : cleaned_data . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : cleaned_data . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : cleaned_data . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : True , <EOL> } ) <EOL> ldapform = LDAPForm ( <EOL> data = ldapdata , <EOL> instance = ldap , <EOL> ) <EOL> if ldapform . is_valid ( ) : <EOL> ldapform . save ( ) <EOL> else : <EOL> log . warn ( <EOL> '<STR_LIT>' , <EOL> ldapform . _errors , <EOL> ) <EOL> elif cleaned_data . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> try : <EOL> nis = NIS . objects . all ( ) . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> except : <EOL> nis = NIS . objects . create ( ) <EOL> nisdata = nis . __dict__ <EOL> nisdata . update ( { <EOL> '<STR_LIT>' : cleaned_data . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : cleaned_data . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : cleaned_data . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : cleaned_data . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : True , <EOL> } ) <EOL> nisform = NISForm ( <EOL> data = nisdata , <EOL> instance = nis , <EOL> ) <EOL> if nisform . is_valid ( ) : <EOL> nisform . save ( ) <EOL> else : <EOL> log . warn ( <EOL> '<STR_LIT>' , <EOL> nisform . _errors , <EOL> ) <EOL> elif cleaned_data . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> try : <EOL> nt4 = NT4 . objects . all ( ) . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> except : <EOL> nt4 = NT4 . objects . create ( ) <EOL> nt4data = nt4 . __dict__ <EOL> for name , value in cleaned_data . items ( ) : <EOL> if not name . startswith ( '<STR_LIT>' ) : <EOL> continue <EOL> nt4data [ name . replace ( '<STR_LIT>' , '<STR_LIT>' ) ] = value <EOL> nt4data [ '<STR_LIT>' ] = True <EOL> nt4form = NT4Form ( <EOL> data = nt4data , <EOL> instance = nt4 , <EOL> ) <EOL> if nt4form . is_valid ( ) : <EOL> nt4form . save ( ) <EOL> else : <EOL> log . warn ( <EOL> '<STR_LIT>' , <EOL> nt4form . _errors , <EOL> ) <EOL> for i , share in enumerate ( shares ) : <EOL> if not share : <EOL> continue <EOL> share_name = share . get ( '<STR_LIT>' ) <EOL> share_purpose = share . get ( '<STR_LIT>' ) <EOL> share_user = share . get ( '<STR_LIT>' ) <EOL> share_group = share . get ( '<STR_LIT>' ) <EOL> share_mode = share . get ( '<STR_LIT>' ) <EOL> if share_purpose == '<STR_LIT>' : <EOL> continue <EOL> if share_purpose == '<STR_LIT>' : <EOL> share_acl = '<STR_LIT>' <EOL> elif share_purpose == '<STR_LIT>' : <EOL> share_acl = '<STR_LIT>' <EOL> else : <EOL> share_acl = '<STR_LIT>' <EOL> _n . mp_change_permission ( <EOL> path = '<STR_LIT>' % ( volume_name , share_name ) , <EOL> user = share_user , <EOL> group = share_group , <EOL> mode = share_mode , <EOL> recursive = False , <EOL> acl = share_acl , <EOL> ) <EOL> curstep += <NUM_LIT:1> <EOL> progress [ '<STR_LIT>' ] = curstep <EOL> progress [ '<STR_LIT>' ] = False <EOL> progress [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> with open ( WIZARD_PROGRESSFILE , '<STR_LIT:wb>' ) as f : <EOL> f . write ( pickle . dumps ( progress ) ) <EOL> _n . reload ( "<STR_LIT>" ) <EOL> progress [ '<STR_LIT>' ] = <NUM_LIT:50> <EOL> with open ( WIZARD_PROGRESSFILE , '<STR_LIT:wb>' ) as f : <EOL> f . write ( pickle . dumps ( progress ) ) <EOL> _n . start ( "<STR_LIT>" ) <EOL> _n . start ( "<STR_LIT>" ) <EOL> _n . restart ( "<STR_LIT>" ) <EOL> _n . reload ( "<STR_LIT>" ) <EOL> progress [ '<STR_LIT>' ] = <NUM_LIT> <EOL> with open ( WIZARD_PROGRESSFILE , '<STR_LIT:wb>' ) as f : <EOL> f . write ( pickle . dumps ( progress ) ) <EOL> _n . restart ( "<STR_LIT>" ) <EOL> _n . reload ( "<STR_LIT:user>" ) <EOL> for service in services_restart : <EOL> _n . restart ( service ) <EOL> Update . CreateClone ( '<STR_LIT>' % ( <EOL> datetime . now ( ) . strftime ( "<STR_LIT>" ) <EOL> ) ) <EOL> progress [ '<STR_LIT>' ] = <NUM_LIT:100> <EOL> with open ( WIZARD_PROGRESSFILE , '<STR_LIT:wb>' ) as f : <EOL> f . write ( pickle . dumps ( progress ) ) <EOL> os . unlink ( WIZARD_PROGRESSFILE ) <EOL> return JsonResp ( <EOL> self . request , <EOL> message = __ ( '<STR_LIT>' ) , <EOL> events = events , <EOL> ) <EOL> class SettingsForm ( ModelForm ) : <EOL> class Meta : <EOL> fields = '<STR_LIT>' <EOL> model = models . Settings <EOL> widgets = { <EOL> '<STR_LIT>' : forms . widgets . FilteringSelect ( ) , <EOL> '<STR_LIT>' : forms . widgets . FilteringSelect ( ) , <EOL> '<STR_LIT>' : forms . widgets . FilteringSelect ( ) , <EOL> '<STR_LIT>' : forms . widgets . TextInput ( ) , <EOL> '<STR_LIT>' : forms . widgets . TextInput ( ) , <EOL> } <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( SettingsForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . instance . _original_stg_guiprotocol = self . instance . stg_guiprotocol <EOL> self . instance . _original_stg_guiaddress = self . instance . stg_guiaddress <EOL> self . instance . _original_stg_guiport = self . instance . stg_guiport <EOL> self . instance . _original_stg_guihttpsport = self . instance . stg_guihttpsport <EOL> self . instance . _original_stg_guihttpsredirect = self . instance . stg_guihttpsredirect <EOL> self . instance . _original_stg_syslogserver = ( <EOL> self . instance . stg_syslogserver <EOL> ) <EOL> self . instance . _original_stg_guicertificate = self . instance . stg_guicertificate <EOL> self . fields [ '<STR_LIT>' ] . choices = settings . LANGUAGES <EOL> self . fields [ '<STR_LIT>' ] . label = _ ( "<STR_LIT>" ) <EOL> self . fields [ '<STR_LIT>' ] = forms . ChoiceField ( <EOL> label = self . fields [ '<STR_LIT>' ] . label <EOL> ) <EOL> self . fields [ '<STR_LIT>' ] . choices = [ <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ] + list ( choices . IPChoices ( ipv6 = False ) ) <EOL> self . fields [ '<STR_LIT>' ] = forms . ChoiceField ( <EOL> label = self . fields [ '<STR_LIT>' ] . label <EOL> ) <EOL> self . fields [ '<STR_LIT>' ] . choices = [ <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ] + list ( choices . IPChoices ( ipv4 = False ) ) <EOL> def clean ( self ) : <EOL> cdata = self . cleaned_data <EOL> proto = cdata . get ( "<STR_LIT>" ) <EOL> if proto == "<STR_LIT:http>" : <EOL> return cdata <EOL> certificate = cdata [ "<STR_LIT>" ] <EOL> if not certificate : <EOL> raise forms . ValidationError ( <EOL> "<STR_LIT>" ) <EOL> return cdata <EOL> def save ( self ) : <EOL> super ( SettingsForm , self ) . save ( ) <EOL> if self . instance . _original_stg_syslogserver != self . instance . stg_syslogserver : <EOL> notifier ( ) . restart ( "<STR_LIT>" ) <EOL> notifier ( ) . reload ( "<STR_LIT>" ) <EOL> def done ( self , request , events ) : <EOL> if ( <EOL> self . instance . _original_stg_guiprotocol != self . instance . stg_guiprotocol or <EOL> self . instance . _original_stg_guiaddress != self . instance . stg_guiaddress or <EOL> self . instance . _original_stg_guiport != self . instance . stg_guiport or <EOL> self . instance . _original_stg_guihttpsport != self . instance . stg_guihttpsport or <EOL> self . instance . _original_stg_guihttpsredirect != self . instance . stg_guihttpsredirect or <EOL> self . instance . _original_stg_guicertificate != self . instance . stg_guicertificate <EOL> ) : <EOL> if self . instance . stg_guiaddress == "<STR_LIT>" : <EOL> address = request . META [ '<STR_LIT>' ] . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] <EOL> else : <EOL> address = self . instance . stg_guiaddress <EOL> if self . instance . stg_guiprotocol == '<STR_LIT>' : <EOL> protocol = '<STR_LIT:http>' <EOL> else : <EOL> protocol = self . instance . stg_guiprotocol <EOL> newurl = "<STR_LIT>" % ( <EOL> protocol , <EOL> address <EOL> ) <EOL> if self . instance . stg_guiport and protocol == '<STR_LIT:http>' : <EOL> newurl += "<STR_LIT::>" + str ( self . instance . stg_guiport ) <EOL> elif self . instance . stg_guihttpsport and protocol == '<STR_LIT>' : <EOL> newurl += "<STR_LIT::>" + str ( self . instance . stg_guihttpsport ) <EOL> notifier ( ) . start_ssl ( "<STR_LIT>" ) <EOL> if self . instance . _original_stg_guiprotocol != self . instance . stg_guiprotocol : <EOL> events . append ( "<STR_LIT>" % newurl ) <EOL> else : <EOL> events . append ( "<STR_LIT>" % newurl ) <EOL> class NTPForm ( ModelForm ) : <EOL> force = forms . BooleanField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = False , <EOL> help_text = _ ( <EOL> "<STR_LIT>" <EOL> ) , <EOL> ) <EOL> class Meta : <EOL> fields = '<STR_LIT>' <EOL> model = models . NTPServer <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( NTPForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . usable = True <EOL> def clean_ntp_address ( self ) : <EOL> addr = self . cleaned_data . get ( "<STR_LIT>" ) <EOL> p1 = subprocess . Popen ( <EOL> [ "<STR_LIT>" , "<STR_LIT>" , addr ] , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE <EOL> ) <EOL> p1 . communicate ( ) <EOL> if p1 . returncode != <NUM_LIT:0> : <EOL> self . usable = False <EOL> return addr <EOL> def clean_ntp_maxpoll ( self ) : <EOL> maxp = self . cleaned_data . get ( "<STR_LIT>" ) <EOL> minp = self . cleaned_data . get ( "<STR_LIT>" ) <EOL> if not maxp > minp : <EOL> raise forms . ValidationError ( _ ( <EOL> "<STR_LIT>" <EOL> ) ) <EOL> return maxp <EOL> def clean ( self ) : <EOL> cdata = self . cleaned_data <EOL> if not cdata . get ( "<STR_LIT>" , False ) and not self . usable : <EOL> self . _errors [ '<STR_LIT>' ] = self . error_class ( [ _ ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) ] ) <EOL> del cdata [ '<STR_LIT>' ] <EOL> return cdata <EOL> def save ( self ) : <EOL> super ( NTPForm , self ) . save ( ) <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> notifier ( ) . restart ( "<STR_LIT>" ) <EOL> class AdvancedForm ( ModelForm ) : <EOL> class Meta : <EOL> fields = '<STR_LIT>' <EOL> model = models . Advanced <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( AdvancedForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . instance . _original_adv_motd = self . instance . adv_motd <EOL> self . instance . _original_adv_consolemenu = self . instance . adv_consolemenu <EOL> self . instance . _original_adv_powerdaemon = self . instance . adv_powerdaemon <EOL> self . instance . _original_adv_serialconsole = ( <EOL> self . instance . adv_serialconsole <EOL> ) <EOL> self . instance . _original_adv_serialspeed = self . instance . adv_serialspeed <EOL> self . instance . _original_adv_serialport = self . instance . adv_serialport <EOL> self . instance . _original_adv_consolescreensaver = ( <EOL> self . instance . adv_consolescreensaver <EOL> ) <EOL> self . instance . _original_adv_consolemsg = self . instance . adv_consolemsg <EOL> self . instance . _original_adv_advancedmode = ( <EOL> self . instance . adv_advancedmode <EOL> ) <EOL> self . instance . _original_adv_autotune = self . instance . adv_autotune <EOL> self . instance . _original_adv_debugkernel = self . instance . adv_debugkernel <EOL> self . instance . _original_adv_periodic_notifyuser = self . instance . adv_periodic_notifyuser <EOL> def save ( self ) : <EOL> super ( AdvancedForm , self ) . save ( ) <EOL> loader_reloaded = False <EOL> if self . instance . _original_adv_motd != self . instance . adv_motd : <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> if self . instance . _original_adv_consolemenu != self . instance . adv_consolemenu : <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> if self . instance . _original_adv_powerdaemon != self . instance . adv_powerdaemon : <EOL> notifier ( ) . restart ( "<STR_LIT>" ) <EOL> if self . instance . _original_adv_serialconsole != self . instance . adv_serialconsole : <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> if not loader_reloaded : <EOL> notifier ( ) . reload ( "<STR_LIT>" ) <EOL> loader_reloaded = True <EOL> elif ( self . instance . _original_adv_serialspeed != self . instance . adv_serialspeed or <EOL> self . instance . _original_adv_serialport != self . instance . adv_serialport ) : <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> if not loader_reloaded : <EOL> notifier ( ) . reload ( "<STR_LIT>" ) <EOL> loader_reloaded = True <EOL> if self . instance . _original_adv_consolescreensaver != self . instance . adv_consolescreensaver : <EOL> if self . instance . adv_consolescreensaver == <NUM_LIT:0> : <EOL> notifier ( ) . stop ( "<STR_LIT>" ) <EOL> else : <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> if not loader_reloaded : <EOL> notifier ( ) . reload ( "<STR_LIT>" ) <EOL> loader_reloaded = True <EOL> if ( <EOL> self . instance . _original_adv_autotune != self . instance . adv_autotune <EOL> and not loader_reloaded <EOL> ) : <EOL> notifier ( ) . reload ( "<STR_LIT>" ) <EOL> if self . instance . _original_adv_debugkernel != self . instance . adv_debugkernel : <EOL> notifier ( ) . reload ( "<STR_LIT>" ) <EOL> if self . instance . _original_adv_periodic_notifyuser != self . instance . adv_periodic_notifyuser : <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> def done ( self , request , events ) : <EOL> if self . instance . _original_adv_consolemsg != self . instance . adv_consolemsg : <EOL> if self . instance . adv_consolemsg : <EOL> events . append ( "<STR_LIT>" ) <EOL> else : <EOL> events . append ( "<STR_LIT>" ) <EOL> if self . instance . _original_adv_advancedmode != self . instance . adv_advancedmode : <EOL> request . session . pop ( "<STR_LIT>" , None ) <EOL> if ( <EOL> self . instance . _original_adv_autotune != self . instance . adv_autotune <EOL> and self . instance . adv_autotune is True <EOL> ) : <EOL> events . append ( "<STR_LIT>" ) <EOL> class EmailForm ( ModelForm ) : <EOL> em_pass1 = forms . CharField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> widget = forms . PasswordInput , <EOL> required = False ) <EOL> em_pass2 = forms . CharField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> widget = forms . PasswordInput , <EOL> help_text = _ ( "<STR_LIT>" ) , <EOL> required = False ) <EOL> class Meta : <EOL> model = models . Email <EOL> exclude = ( '<STR_LIT>' , ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( EmailForm , self ) . __init__ ( * args , ** kwargs ) <EOL> try : <EOL> self . fields [ '<STR_LIT>' ] . initial = self . instance . em_pass <EOL> self . fields [ '<STR_LIT>' ] . initial = self . instance . em_pass <EOL> except : <EOL> pass <EOL> self . fields [ '<STR_LIT>' ] . widget . attrs [ '<STR_LIT>' ] = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> ro = True <EOL> if len ( self . data ) > <NUM_LIT:0> : <EOL> if self . data . get ( "<STR_LIT>" , None ) == "<STR_LIT>" : <EOL> ro = False <EOL> else : <EOL> if self . instance . em_smtp is True : <EOL> ro = False <EOL> if ro : <EOL> self . fields [ '<STR_LIT>' ] . widget . attrs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . fields [ '<STR_LIT>' ] . widget . attrs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . fields [ '<STR_LIT>' ] . widget . attrs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> def clean_em_user ( self ) : <EOL> if ( <EOL> self . cleaned_data [ '<STR_LIT>' ] is True and <EOL> self . cleaned_data [ '<STR_LIT>' ] == "<STR_LIT>" <EOL> ) : <EOL> raise forms . ValidationError ( _ ( "<STR_LIT>" ) ) <EOL> return self . cleaned_data [ '<STR_LIT>' ] <EOL> def clean_em_pass1 ( self ) : <EOL> if ( <EOL> self . cleaned_data [ '<STR_LIT>' ] is True and <EOL> self . cleaned_data [ '<STR_LIT>' ] == "<STR_LIT>" <EOL> ) : <EOL> if self . instance . em_pass : <EOL> return self . instance . em_pass <EOL> raise forms . ValidationError ( _ ( "<STR_LIT>" ) ) <EOL> return self . cleaned_data [ '<STR_LIT>' ] <EOL> def clean_em_pass2 ( self ) : <EOL> if ( <EOL> self . cleaned_data [ '<STR_LIT>' ] is True and <EOL> self . cleaned_data . get ( '<STR_LIT>' , "<STR_LIT>" ) == "<STR_LIT>" <EOL> ) : <EOL> if self . instance . em_pass : <EOL> return self . instance . em_pass <EOL> raise forms . ValidationError ( _ ( "<STR_LIT>" ) ) <EOL> pass1 = self . cleaned_data . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> pass2 = self . cleaned_data . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if pass1 != pass2 : <EOL> raise forms . ValidationError ( <EOL> _ ( "<STR_LIT>" ) <EOL> ) <EOL> return pass2 <EOL> def save ( self , commit = True ) : <EOL> email = super ( EmailForm , self ) . save ( commit = False ) <EOL> if commit : <EOL> email . em_pass = self . cleaned_data [ '<STR_LIT>' ] <EOL> email . save ( ) <EOL> return email <EOL> class ConfigUploadForm ( Form ) : <EOL> config = FileField ( label = _ ( "<STR_LIT>" ) ) <EOL> """<STR_LIT>""" <EOL> SYSCTL_TUNABLE_VARNAME_FORMAT = """<STR_LIT>""" <EOL> SYSCTL_VARNAME_FORMAT_RE = re . compile ( '<STR_LIT>' , re . I ) <EOL> LOADER_VARNAME_FORMAT_RE = re . compile ( '<STR_LIT>' , re . I ) <EOL> class TunableForm ( ModelForm ) : <EOL> class Meta : <EOL> fields = '<STR_LIT>' <EOL> model = models . Tunable <EOL> def clean_tun_comment ( self ) : <EOL> return self . cleaned_data . get ( '<STR_LIT>' ) . strip ( ) <EOL> def clean_tun_value ( self ) : <EOL> value = self . cleaned_data . get ( '<STR_LIT>' ) <EOL> if '<STR_LIT:">' in value or "<STR_LIT:'>" in value : <EOL> raise forms . ValidationError ( _ ( '<STR_LIT>' ) ) <EOL> return value <EOL> def clean_tun_var ( self ) : <EOL> value = self . cleaned_data . get ( '<STR_LIT>' ) . strip ( ) <EOL> qs = models . Tunable . objects . filter ( tun_var = value ) <EOL> if self . instance . id : <EOL> qs = qs . exclude ( id = self . instance . id ) <EOL> if qs . exists ( ) : <EOL> raise forms . ValidationError ( _ ( <EOL> '<STR_LIT>' <EOL> ) ) <EOL> return value <EOL> def clean ( self ) : <EOL> cdata = self . cleaned_data <EOL> value = cdata . get ( '<STR_LIT>' ) <EOL> if value : <EOL> if ( <EOL> cdata . get ( '<STR_LIT>' ) in ( '<STR_LIT>' , '<STR_LIT>' ) and <EOL> not LOADER_VARNAME_FORMAT_RE . match ( value ) <EOL> ) or ( <EOL> cdata . get ( '<STR_LIT>' ) == '<STR_LIT>' and <EOL> not SYSCTL_VARNAME_FORMAT_RE . match ( value ) <EOL> ) : <EOL> self . errors [ '<STR_LIT>' ] = self . error_class ( <EOL> [ _ ( SYSCTL_TUNABLE_VARNAME_FORMAT ) ] <EOL> ) <EOL> cdata . pop ( '<STR_LIT>' , None ) <EOL> return cdata <EOL> def save ( self ) : <EOL> super ( TunableForm , self ) . save ( ) <EOL> if self . cleaned_data . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> notifier ( ) . reload ( "<STR_LIT>" ) <EOL> else : <EOL> notifier ( ) . reload ( "<STR_LIT>" ) <EOL> class SystemDatasetForm ( ModelForm ) : <EOL> sys_pool = forms . ChoiceField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = False <EOL> ) <EOL> class Meta : <EOL> fields = '<STR_LIT>' <EOL> model = models . SystemDataset <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( SystemDatasetForm , self ) . __init__ ( * args , ** kwargs ) <EOL> pool_choices = [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> for v in Volume . objects . filter ( vol_fstype = '<STR_LIT>' ) : <EOL> if v . is_decrypted ( ) : <EOL> pool_choices . append ( ( v . vol_name , v . vol_name ) ) <EOL> self . fields [ '<STR_LIT>' ] . choices = pool_choices <EOL> self . instance . _original_sys_pool = self . instance . sys_pool <EOL> self . instance . _original_sys_syslog_usedataset = self . instance . sys_syslog_usedataset <EOL> self . instance . _original_sys_rrd_usedataset = self . instance . sys_rrd_usedataset <EOL> def save ( self ) : <EOL> super ( SystemDatasetForm , self ) . save ( ) <EOL> if self . instance . sys_pool : <EOL> try : <EOL> notifier ( ) . system_dataset_create ( mount = False ) <EOL> except : <EOL> raise MiddlewareError ( _ ( "<STR_LIT>" ) ) <EOL> if self . instance . _original_sys_pool != self . instance . sys_pool : <EOL> try : <EOL> notifier ( ) . system_dataset_migrate ( <EOL> self . instance . _original_sys_pool , self . instance . sys_pool <EOL> ) <EOL> except : <EOL> raise MiddlewareError ( _ ( "<STR_LIT>" ) ) <EOL> notifier ( ) . restart ( "<STR_LIT>" ) <EOL> if self . instance . _original_sys_syslog_usedataset != self . instance . sys_syslog_usedataset : <EOL> notifier ( ) . restart ( "<STR_LIT>" ) <EOL> if self . instance . _original_sys_rrd_usedataset != self . instance . sys_rrd_usedataset : <EOL> notifier ( ) . restart ( "<STR_LIT>" ) <EOL> class InitialWizardDSForm ( Form ) : <EOL> ds_type = forms . ChoiceField ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> choices = ( <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ) , <EOL> initial = '<STR_LIT>' , <EOL> ) <EOL> ds_ad_domainname = forms . CharField ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> required = False , <EOL> ) <EOL> ds_ad_bindname = forms . CharField ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> required = False , <EOL> ) <EOL> ds_ad_bindpw = forms . CharField ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> required = False , <EOL> widget = forms . widgets . PasswordInput ( ) , <EOL> ) <EOL> ds_ldap_hostname = forms . CharField ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> required = False , <EOL> ) <EOL> ds_ldap_basedn = forms . CharField ( <EOL> label = ( '<STR_LIT>' ) , <EOL> required = False , <EOL> ) <EOL> ds_ldap_binddn = forms . CharField ( <EOL> label = ( '<STR_LIT>' ) , <EOL> required = False , <EOL> ) <EOL> ds_ldap_bindpw = forms . CharField ( <EOL> label = ( '<STR_LIT>' ) , <EOL> required = False , <EOL> widget = forms . widgets . PasswordInput ( ) , <EOL> ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( InitialWizardDSForm , self ) . __init__ ( * args , ** kwargs ) <EOL> for fname , field in NISForm ( ) . fields . items ( ) : <EOL> if fname . find ( '<STR_LIT>' ) == - <NUM_LIT:1> : <EOL> self . fields [ '<STR_LIT>' % fname ] = field <EOL> field . required = False <EOL> for fname , field in NT4Form ( ) . fields . items ( ) : <EOL> if ( <EOL> fname . find ( '<STR_LIT>' ) == - <NUM_LIT:1> and <EOL> fname not in NT4Form . advanced_fields <EOL> ) : <EOL> self . fields [ '<STR_LIT>' % fname ] = field <EOL> field . required = False <EOL> pertype = defaultdict ( list ) <EOL> for fname in self . fields . keys ( ) : <EOL> if fname . startswith ( '<STR_LIT>' ) : <EOL> pertype [ '<STR_LIT>' ] . append ( '<STR_LIT>' % fname ) <EOL> elif fname . startswith ( '<STR_LIT>' ) : <EOL> pertype [ '<STR_LIT>' ] . append ( '<STR_LIT>' % fname ) <EOL> elif fname . startswith ( '<STR_LIT>' ) : <EOL> pertype [ '<STR_LIT>' ] . append ( '<STR_LIT>' % fname ) <EOL> elif fname . startswith ( '<STR_LIT>' ) : <EOL> pertype [ '<STR_LIT>' ] . append ( '<STR_LIT>' % fname ) <EOL> self . jsChange = '<STR_LIT>' % ( <EOL> '<STR_LIT>' , <EOL> escapejs ( json . dumps ( pertype ) ) , <EOL> ) <EOL> self . fields [ '<STR_LIT>' ] . widget . attrs [ '<STR_LIT>' ] = ( <EOL> self . jsChange <EOL> ) <EOL> @ classmethod <EOL> def show_condition ( cls , wizard ) : <EOL> ad = ActiveDirectory . objects . all ( ) . filter ( ad_enable = True ) . exists ( ) <EOL> ldap = LDAP . objects . all ( ) . filter ( ldap_enable = True ) . exists ( ) <EOL> nt4 = NT4 . objects . all ( ) . filter ( nt4_enable = True ) . exists ( ) <EOL> nis = NIS . objects . all ( ) . filter ( nis_enable = True ) . exists ( ) <EOL> return not ( ad or ldap or nt4 or nis ) <EOL> def clean ( self ) : <EOL> cdata = self . cleaned_data <EOL> if cdata . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> domain = cdata . get ( '<STR_LIT>' ) <EOL> bindname = cdata . get ( '<STR_LIT>' ) <EOL> bindpw = cdata . get ( '<STR_LIT>' ) <EOL> binddn = '<STR_LIT>' % ( bindname , domain ) <EOL> errors = [ ] <EOL> if not ( domain and bindname and bindpw ) : <EOL> if domain or bindname or bindpw : <EOL> if not domain : <EOL> self . _errors [ '<STR_LIT>' ] = self . error_class ( [ <EOL> _ ( '<STR_LIT>' ) , <EOL> ] ) <EOL> if not bindname : <EOL> self . _errors [ '<STR_LIT>' ] = self . error_class ( [ <EOL> _ ( '<STR_LIT>' ) , <EOL> ] ) <EOL> if not bindpw : <EOL> self . _errors [ '<STR_LIT>' ] = self . error_class ( [ <EOL> _ ( '<STR_LIT>' ) , <EOL> ] ) <EOL> else : <EOL> cdata . pop ( '<STR_LIT>' , None ) <EOL> else : <EOL> try : <EOL> ret = FreeNAS_ActiveDirectory . validate_credentials ( <EOL> domain , binddn = binddn , bindpw = bindpw , errors = errors <EOL> ) <EOL> except Exception , e : <EOL> raise forms . ValidationError ( "<STR_LIT>" % e ) <EOL> if ret is False : <EOL> raise forms . ValidationError ( "<STR_LIT>" % errors [ <NUM_LIT:0> ] ) <EOL> elif cdata . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> hostname = cdata . get ( '<STR_LIT>' ) <EOL> binddn = cdata . get ( '<STR_LIT>' ) <EOL> bindpw = cdata . get ( '<STR_LIT>' ) <EOL> errors = [ ] <EOL> if not ( hostname and binddn and bindpw ) : <EOL> if hostname or binddn or bindpw : <EOL> if not hostname : <EOL> self . _errors [ '<STR_LIT>' ] = self . error_class ( [ <EOL> _ ( '<STR_LIT>' ) , <EOL> ] ) <EOL> if not binddn : <EOL> self . _errors [ '<STR_LIT>' ] = self . error_class ( [ <EOL> _ ( '<STR_LIT>' ) , <EOL> ] ) <EOL> if not bindpw : <EOL> self . _errors [ '<STR_LIT>' ] = self . error_class ( [ <EOL> _ ( '<STR_LIT>' ) , <EOL> ] ) <EOL> else : <EOL> cdata . pop ( '<STR_LIT>' , None ) <EOL> else : <EOL> try : <EOL> ret = FreeNAS_LDAP . validate_credentials ( <EOL> hostname , binddn = binddn , bindpw = bindpw , errors = errors <EOL> ) <EOL> except Exception , e : <EOL> raise forms . ValidationError ( "<STR_LIT>" % e ) <EOL> if ret is False : <EOL> raise forms . ValidationError ( "<STR_LIT>" % errors [ <NUM_LIT:0> ] ) <EOL> elif cdata . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> values = [ ] <EOL> empty = True <EOL> for fname in self . fields . keys ( ) : <EOL> if fname . startswith ( '<STR_LIT>' ) : <EOL> value = cdata . get ( fname ) <EOL> values . append ( ( fname , value ) ) <EOL> if empty and value : <EOL> empty = False <EOL> if not empty : <EOL> for fname , value in values : <EOL> if not value and NISForm . base_fields [ <EOL> fname . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ] . required : <EOL> self . _errors [ fname ] = self . error_class ( [ <EOL> _ ( '<STR_LIT>' ) , <EOL> ] ) <EOL> elif cdata . get ( '<STR_LIT>' ) == '<STR_LIT>' : <EOL> values = [ ] <EOL> empty = True <EOL> for fname in self . fields . keys ( ) : <EOL> if fname . startswith ( '<STR_LIT>' ) : <EOL> value = cdata . get ( fname ) <EOL> values . append ( ( fname , value ) ) <EOL> if empty and value : <EOL> empty = False <EOL> if not empty : <EOL> for fname , value in values : <EOL> if not value and NT4Form . base_fields [ <EOL> fname . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ] . required : <EOL> self . _errors [ fname ] = self . error_class ( [ <EOL> _ ( '<STR_LIT>' ) , <EOL> ] ) <EOL> password1 = cdata . get ( '<STR_LIT>' ) <EOL> password2 = cdata . get ( '<STR_LIT>' ) <EOL> if password1 != password2 : <EOL> self . _errors [ '<STR_LIT>' ] = self . error_class ( [ <EOL> _ ( '<STR_LIT>' ) <EOL> ] ) <EOL> return cdata <EOL> def done ( self , request = None , ** kwargs ) : <EOL> dsdata = self . cleaned_data <EOL> request . session [ '<STR_LIT>' ] = dsdata <EOL> class InitialWizardShareForm ( Form ) : <EOL> share_name = forms . CharField ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> max_length = <NUM_LIT> , <EOL> ) <EOL> share_purpose = forms . ChoiceField ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> choices = ( <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ( '<STR_LIT>' , _ ( '<STR_LIT>' ) ) , <EOL> ) , <EOL> ) <EOL> share_allowguest = forms . BooleanField ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> required = False , <EOL> ) <EOL> share_timemachine = forms . BooleanField ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> required = False , <EOL> ) <EOL> share_iscsisize = forms . CharField ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> max_length = <NUM_LIT:255> , <EOL> required = False , <EOL> ) <EOL> share_user = forms . CharField ( <EOL> max_length = <NUM_LIT:100> , <EOL> required = False , <EOL> ) <EOL> share_group = forms . CharField ( <EOL> max_length = <NUM_LIT:100> , <EOL> required = False , <EOL> ) <EOL> share_usercreate = forms . BooleanField ( <EOL> required = False , <EOL> ) <EOL> share_userpw = forms . CharField ( <EOL> required = False , <EOL> max_length = <NUM_LIT:100> , <EOL> ) <EOL> share_groupcreate = forms . BooleanField ( <EOL> required = False , <EOL> ) <EOL> share_mode = forms . CharField ( <EOL> max_length = <NUM_LIT:3> , <EOL> required = False , <EOL> ) <EOL> def clean_share_name ( self ) : <EOL> share_name = self . cleaned_data . get ( '<STR_LIT>' ) <EOL> qs = Volume . objects . filter ( vol_fstype = '<STR_LIT>' ) <EOL> if qs . exists ( ) : <EOL> volume_name = qs [ <NUM_LIT:0> ] . vol_name <EOL> path = '<STR_LIT>' % ( volume_name , share_name ) <EOL> if os . path . exists ( path ) : <EOL> raise forms . ValidationError ( <EOL> _ ( '<STR_LIT>' ) % path <EOL> ) <EOL> class SharesBaseFormSet ( BaseFormSet ) : <EOL> RE_FIELDS = re . compile ( r'<STR_LIT>' ) <EOL> def data_to_store ( self ) : <EOL> """<STR_LIT>""" <EOL> keys = defaultdict ( dict ) <EOL> for key , val in self . data . items ( ) : <EOL> reg = self . RE_FIELDS . search ( key ) <EOL> if not reg : <EOL> continue <EOL> idx , name = reg . groups ( ) <EOL> keys [ idx ] [ name ] = val <EOL> return json . dumps ( keys . values ( ) ) <EOL> def errors_json ( self ) : <EOL> return json . dumps ( self . errors ) <EOL> InitialWizardShareFormSet = formset_factory ( <EOL> InitialWizardShareForm , <EOL> formset = SharesBaseFormSet , <EOL> ) <EOL> class InitialWizardVolumeForm ( Form ) : <EOL> volume_name = forms . CharField ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> max_length = <NUM_LIT:200> , <EOL> ) <EOL> volume_type = forms . ChoiceField ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> choices = ( ) , <EOL> widget = forms . RadioSelect , <EOL> initial = '<STR_LIT>' , <EOL> ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( InitialWizardVolumeForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fields [ '<STR_LIT>' ] . choices = ( <EOL> ( <EOL> '<STR_LIT>' , <EOL> _ ( '<STR_LIT>' ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> _ ( '<STR_LIT>' ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> _ ( '<STR_LIT>' ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> _ ( '<STR_LIT>' ) <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> _ ( '<STR_LIT>' ) <EOL> ) , <EOL> ) <EOL> self . types_avail = self . _types_avail ( self . _get_unused_disks_by_size ( ) ) <EOL> @ classmethod <EOL> def show_condition ( cls , wizard ) : <EOL> imported = wizard . get_cleaned_data_for_step ( '<STR_LIT>' ) <EOL> if imported : <EOL> return False <EOL> has_disks = ( <EOL> len ( cls . _types_avail ( cls . _get_unused_disks_by_size ( ) ) ) > <NUM_LIT:0> <EOL> ) <EOL> volume_exists = Volume . objects . all ( ) . exists ( ) <EOL> return has_disks or ( not has_disks and not volume_exists ) <EOL> @ staticmethod <EOL> def _get_unused_disks ( ) : <EOL> _n = notifier ( ) <EOL> disks = _n . get_disks ( ) <EOL> for volume in Volume . objects . all ( ) : <EOL> for disk in volume . get_disks ( ) : <EOL> disks . pop ( disk , None ) <EOL> return disks <EOL> @ classmethod <EOL> def _get_unused_disks_by_size ( cls ) : <EOL> disks = cls . _get_unused_disks ( ) <EOL> bysize = defaultdict ( list ) <EOL> for disk , attrs in disks . items ( ) : <EOL> size = int ( attrs [ '<STR_LIT>' ] ) <EOL> size = size - ( size % <NUM_LIT> ) <EOL> bysize [ size ] . append ( disk ) <EOL> return bysize <EOL> @ staticmethod <EOL> def _higher_disks_group ( bysize ) : <EOL> higher = ( None , <NUM_LIT:0> ) <EOL> for size , _disks in bysize . items ( ) : <EOL> if len ( _disks ) > higher [ <NUM_LIT:1> ] : <EOL> higher = ( size , len ( _disks ) ) <EOL> return higher <EOL> @ classmethod <EOL> def _types_avail ( cls , disks ) : <EOL> types = [ ] <EOL> ndisks = cls . _higher_disks_group ( disks ) [ <NUM_LIT:1> ] <EOL> if ndisks >= <NUM_LIT:4> : <EOL> types . extend ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> if ndisks >= <NUM_LIT:3> : <EOL> types . append ( '<STR_LIT>' ) <EOL> if ndisks > <NUM_LIT:0> : <EOL> types . extend ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> return types <EOL> @ staticmethod <EOL> def _grp_type ( num ) : <EOL> check = OrderedDict ( ( <EOL> ( '<STR_LIT>' , lambda y : y == <NUM_LIT:2> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> lambda y : False if y < <NUM_LIT:3> else math . log ( y - <NUM_LIT:1> , <NUM_LIT:2> ) % <NUM_LIT:1> == <NUM_LIT:0> <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> lambda y : False if y < <NUM_LIT:4> else math . log ( y - <NUM_LIT:2> , <NUM_LIT:2> ) % <NUM_LIT:1> == <NUM_LIT:0> <EOL> ) , <EOL> ( <EOL> '<STR_LIT>' , <EOL> lambda y : False if y < <NUM_LIT:5> else math . log ( y - <NUM_LIT:3> , <NUM_LIT:2> ) % <NUM_LIT:1> == <NUM_LIT:0> <EOL> ) , <EOL> ( '<STR_LIT>' , lambda y : True ) , <EOL> ) ) <EOL> for name , func in check . items ( ) : <EOL> if func ( num ) : <EOL> return name <EOL> return '<STR_LIT>' <EOL> @ classmethod <EOL> def _grp_autoselect ( cls , disks ) : <EOL> higher = cls . _higher_disks_group ( disks ) <EOL> groups = OrderedDict ( ) <EOL> grpid = <NUM_LIT:0> <EOL> for size , devs in [ ( higher [ <NUM_LIT:0> ] , disks [ higher [ <NUM_LIT:0> ] ] ) ] : <EOL> num = len ( devs ) <EOL> if num in ( <NUM_LIT:4> , <NUM_LIT:8> ) : <EOL> mod = <NUM_LIT:0> <EOL> perrow = num / <NUM_LIT:2> <EOL> rows = <NUM_LIT:2> <EOL> vdevtype = cls . _grp_type ( num / <NUM_LIT:2> ) <EOL> elif num < <NUM_LIT:12> : <EOL> mod = <NUM_LIT:0> <EOL> perrow = num <EOL> rows = <NUM_LIT:1> <EOL> vdevtype = cls . _grp_type ( num ) <EOL> elif num < <NUM_LIT> : <EOL> mod = num % <NUM_LIT:2> <EOL> rows = <NUM_LIT:2> <EOL> perrow = ( num - mod ) / <NUM_LIT:2> <EOL> vdevtype = cls . _grp_type ( perrow ) <EOL> elif num >= <NUM_LIT> : <EOL> div9 = int ( num / <NUM_LIT:9> ) <EOL> div10 = int ( num / <NUM_LIT:10> ) <EOL> mod9 = num % <NUM_LIT:9> <EOL> mod10 = num % <NUM_LIT:10> <EOL> if mod9 >= <NUM_LIT> * div9 and mod10 >= <NUM_LIT> * div10 : <EOL> perrow = <NUM_LIT:9> <EOL> rows = div9 <EOL> mod = mod9 <EOL> else : <EOL> perrow = <NUM_LIT:10> <EOL> rows = div10 <EOL> mod = mod10 <EOL> vdevtype = cls . _grp_type ( perrow ) <EOL> else : <EOL> perrow = num <EOL> rows = <NUM_LIT:1> <EOL> vdevtype = '<STR_LIT>' <EOL> mod = <NUM_LIT:0> <EOL> for i in range ( rows ) : <EOL> groups [ grpid ] = { <EOL> '<STR_LIT:type>' : vdevtype , <EOL> '<STR_LIT>' : devs [ i * perrow : perrow * ( i + <NUM_LIT:1> ) ] , <EOL> } <EOL> grpid += <NUM_LIT:1> <EOL> if mod > <NUM_LIT:0> : <EOL> groups [ grpid ] = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : devs [ - mod : ] , <EOL> } <EOL> grpid += <NUM_LIT:1> <EOL> return groups <EOL> @ classmethod <EOL> def _grp_predefined ( cls , disks , grptype ) : <EOL> higher = cls . _higher_disks_group ( disks ) <EOL> maindisks = disks [ higher [ <NUM_LIT:0> ] ] <EOL> groups = OrderedDict ( ) <EOL> grpid = <NUM_LIT:0> <EOL> if grptype == '<STR_LIT>' : <EOL> for i in range ( len ( maindisks ) / <NUM_LIT:2> ) : <EOL> groups [ grpid ] = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : maindisks [ i * <NUM_LIT:2> : <NUM_LIT:2> * ( i + <NUM_LIT:1> ) ] , <EOL> } <EOL> grpid += <NUM_LIT:1> <EOL> elif grptype . startswith ( '<STR_LIT>' ) : <EOL> if grptype == '<STR_LIT>' : <EOL> optimalrow = <NUM_LIT:9> <EOL> elif grptype == '<STR_LIT>' : <EOL> optimalrow = <NUM_LIT:10> <EOL> else : <EOL> optimalrow = <NUM_LIT:11> <EOL> div = len ( maindisks ) / optimalrow <EOL> mod = len ( maindisks ) % optimalrow <EOL> if mod >= <NUM_LIT:2> : <EOL> div += <NUM_LIT:1> <EOL> perrow = len ( maindisks ) / ( div if div else <NUM_LIT:1> ) <EOL> for i in range ( div ) : <EOL> groups [ grpid ] = { <EOL> '<STR_LIT:type>' : grptype , <EOL> '<STR_LIT>' : maindisks [ i * perrow : perrow * ( i + <NUM_LIT:1> ) ] , <EOL> } <EOL> grpid += <NUM_LIT:1> <EOL> else : <EOL> groups [ grpid ] = { <EOL> '<STR_LIT:type>' : grptype , <EOL> '<STR_LIT>' : maindisks , <EOL> } <EOL> return groups <EOL> def _get_disk_size ( self , disk , bysize ) : <EOL> size = None <EOL> for _size , disks in bysize . items ( ) : <EOL> if disk in disks : <EOL> size = _size <EOL> break <EOL> return size <EOL> def _groups_to_disks_size ( self , bysize , groups , swapsize ) : <EOL> size = <NUM_LIT:0> <EOL> disks = [ ] <EOL> for group in groups . values ( ) : <EOL> lower = None <EOL> for disk in group [ '<STR_LIT>' ] : <EOL> _size = self . _get_disk_size ( disk , bysize ) <EOL> if _size and ( not lower or lower > _size ) : <EOL> lower = _size - swapsize <EOL> if not lower : <EOL> continue <EOL> if group [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> size += lower <EOL> elif group [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> size += lower * ( len ( group [ '<STR_LIT>' ] ) - <NUM_LIT:1> ) <EOL> elif group [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> size += lower * ( len ( group [ '<STR_LIT>' ] ) - <NUM_LIT:2> ) <EOL> elif group [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> size += lower * len ( group [ '<STR_LIT>' ] ) <EOL> disks . extend ( group [ '<STR_LIT>' ] ) <EOL> return disks , humanize_size ( size ) <EOL> def choices ( self ) : <EOL> swapsize = models . Advanced . objects . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> ] . adv_swapondrive <EOL> swapsize *= <NUM_LIT> * <NUM_LIT> * <NUM_LIT> <EOL> types = defaultdict ( dict ) <EOL> bysize = self . _get_unused_disks_by_size ( ) <EOL> for _type , descr in self . fields [ '<STR_LIT>' ] . choices : <EOL> if _type == '<STR_LIT>' : <EOL> groups = self . _grp_autoselect ( bysize ) <EOL> else : <EOL> groups = self . _grp_predefined ( bysize , _type ) <EOL> types [ _type ] = self . _groups_to_disks_size ( bysize , groups , swapsize ) <EOL> return json . dumps ( types ) <EOL> def clean_volume_name ( self ) : <EOL> volume_name = self . cleaned_data . get ( '<STR_LIT>' ) <EOL> if not volume_name : <EOL> return volume_name <EOL> qs = Volume . objects . filter ( vol_name = volume_name ) <EOL> if qs . exists ( ) : <EOL> raise forms . ValidationError ( <EOL> _ ( "<STR_LIT>" ) <EOL> ) <EOL> return volume_name <EOL> def clean ( self ) : <EOL> volume_type = self . cleaned_data . get ( '<STR_LIT>' ) <EOL> if not volume_type : <EOL> self . _errors [ '<STR_LIT>' ] = self . error_class ( [ <EOL> _ ( '<STR_LIT>' ) , <EOL> ] ) <EOL> return self . cleaned_data <EOL> class InitialWizardVolumeImportForm ( VolumeAutoImportForm ) : <EOL> @ classmethod <EOL> def show_condition ( cls , wizard ) : <EOL> volume = wizard . get_cleaned_data_for_step ( '<STR_LIT>' ) <EOL> if volume and volume . get ( '<STR_LIT>' ) : <EOL> return False <EOL> if Volume . objects . all ( ) . exists ( ) : <EOL> return False <EOL> return len ( cls . _populate_disk_choices ( ) ) > <NUM_LIT:0> <EOL> class InitialWizardSettingsForm ( Form ) : <EOL> stg_language = forms . ChoiceField ( <EOL> choices = settings . LANGUAGES , <EOL> label = _ ( '<STR_LIT>' ) , <EOL> required = False , <EOL> ) <EOL> stg_kbdmap = forms . ChoiceField ( <EOL> choices = [ ( '<STR_LIT>' , '<STR_LIT>' ) ] + list ( choices . KBDMAP_CHOICES ( ) ) , <EOL> label = _ ( '<STR_LIT>' ) , <EOL> required = False , <EOL> ) <EOL> stg_timezone = forms . ChoiceField ( <EOL> choices = choices . TimeZoneChoices ( ) , <EOL> label = _ ( '<STR_LIT>' ) , <EOL> required = False , <EOL> ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( InitialWizardSettingsForm , self ) . __init__ ( * args , ** kwargs ) <EOL> try : <EOL> settingsm = models . Settings . objects . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> settingsm = models . Settings . objects . create ( ) <EOL> self . fields [ '<STR_LIT>' ] . initial = settingsm . stg_language <EOL> self . fields [ '<STR_LIT>' ] . initial = settingsm . stg_kbdmap <EOL> self . fields [ '<STR_LIT>' ] . initial = settingsm . stg_timezone <EOL> def done ( self , request = None , ** kwargs ) : <EOL> request . session [ '<STR_LIT>' ] = self . cleaned_data . get ( '<STR_LIT>' ) <EOL> class InitialWizardSystemForm ( Form ) : <EOL> sys_console = forms . BooleanField ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> help_text = _ ( '<STR_LIT>' ) , <EOL> required = False , <EOL> ) <EOL> sys_email = forms . EmailField ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> help_text = _ ( '<STR_LIT>' ) , <EOL> required = False , <EOL> ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( InitialWizardSystemForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . _instance = models . Email . objects . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> for fname , field in EmailForm ( instance = self . _instance ) . fields . items ( ) : <EOL> self . fields [ fname ] = field <EOL> field . initial = getattr ( self . _instance , fname , None ) <EOL> field . required = False <EOL> try : <EOL> adv = models . Advanced . objects . order_by ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> adv = models . Advanced . objects . create ( ) <EOL> self . fields [ '<STR_LIT>' ] . initial = adv . adv_consolemsg <EOL> self . fields [ '<STR_LIT>' ] . widget . attrs [ '<STR_LIT>' ] = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> def clean ( self ) : <EOL> em = EmailForm ( self . cleaned_data , instance = self . _instance ) <EOL> if self . cleaned_data . get ( '<STR_LIT>' ) and not em . is_valid ( ) : <EOL> for fname , errors in em . _errors . items ( ) : <EOL> self . _errors [ fname ] = errors <EOL> return self . cleaned_data <EOL> class InitialWizardConfirmForm ( Form ) : <EOL> pass <EOL> class UpdateForm ( ModelForm ) : <EOL> curtrain = forms . CharField ( <EOL> label = _ ( '<STR_LIT>' ) , <EOL> widget = forms . TextInput ( attrs = { '<STR_LIT>' : True , '<STR_LIT>' : True } ) , <EOL> required = False , <EOL> ) <EOL> class Meta : <EOL> fields = '<STR_LIT>' <EOL> model = models . Update <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( UpdateForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . _conf = Configuration . Configuration ( ) <EOL> self . _conf . LoadTrainsConfig ( ) <EOL> self . fields [ '<STR_LIT>' ] . initial = self . _conf . CurrentTrain ( ) <EOL> class CertificateAuthorityForm ( ModelForm ) : <EOL> class Meta : <EOL> fields = '<STR_LIT>' <EOL> model = models . CertificateAuthority <EOL> def save ( self ) : <EOL> super ( CertificateAuthorityForm , self ) . save ( ) <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> class CertificateAuthorityEditForm ( ModelForm ) : <EOL> cert_name = forms . CharField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_certificate = forms . CharField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> widget = forms . Textarea ( ) , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_serial = forms . IntegerField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text , <EOL> ) <EOL> def save ( self ) : <EOL> super ( CertificateAuthorityEditForm , self ) . save ( ) <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> class Meta : <EOL> fields = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> model = models . CertificateAuthority <EOL> class CertificateAuthorityImportForm ( ModelForm ) : <EOL> cert_name = forms . CharField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_certificate = forms . CharField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> widget = forms . Textarea ( ) , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text , <EOL> ) <EOL> cert_passphrase = forms . CharField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = False , <EOL> help_text = _ ( "<STR_LIT>" ) , <EOL> widget = forms . PasswordInput ( render_value = True ) , <EOL> ) <EOL> cert_passphrase2 = forms . CharField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = False , <EOL> widget = forms . PasswordInput ( render_value = True ) , <EOL> ) <EOL> cert_serial = forms . IntegerField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text , <EOL> ) <EOL> def clean_cert_certificate ( self ) : <EOL> cdata = self . cleaned_data <EOL> certificate = cdata . get ( '<STR_LIT>' ) <EOL> if not certificate : <EOL> raise forms . ValidationError ( _ ( "<STR_LIT>" ) ) <EOL> regex = re . compile ( r"<STR_LIT>" , re . M | re . S ) <EOL> matches = regex . findall ( certificate ) <EOL> nmatches = len ( matches ) <EOL> if not nmatches : <EOL> raise forms . ValidationError ( _ ( <EOL> "<STR_LIT>" <EOL> ) ) <EOL> if nmatches > <NUM_LIT:1> : <EOL> self . instance . cert_chain = True <EOL> return certificate <EOL> def clean_cert_name ( self ) : <EOL> cdata = self . cleaned_data <EOL> name = cdata . get ( '<STR_LIT>' ) <EOL> certs = models . CertificateAuthority . objects . filter ( cert_name = name ) <EOL> if certs : <EOL> raise forms . ValidationError ( _ ( <EOL> "<STR_LIT>" <EOL> ) ) <EOL> if name in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> raise forms . ValidationError ( _ ( <EOL> "<STR_LIT>" . format ( name ) <EOL> ) ) <EOL> return name <EOL> def clean_cert_passphrase ( self ) : <EOL> cdata = self . cleaned_data <EOL> passphrase = cdata . get ( '<STR_LIT>' ) <EOL> privatekey = cdata . get ( '<STR_LIT>' ) <EOL> if not privatekey : <EOL> return passphrase <EOL> try : <EOL> privatekey = load_privatekey ( <EOL> privatekey , <EOL> passphrase <EOL> ) <EOL> except Exception : <EOL> raise forms . ValidationError ( _ ( "<STR_LIT>" ) ) <EOL> return passphrase <EOL> def clean_cert_passphrase2 ( self ) : <EOL> cdata = self . cleaned_data <EOL> passphrase = cdata . get ( '<STR_LIT>' ) <EOL> passphrase2 = cdata . get ( '<STR_LIT>' ) <EOL> if passphrase and passphrase != passphrase2 : <EOL> raise forms . ValidationError ( _ ( <EOL> '<STR_LIT>' <EOL> ) ) <EOL> return passphrase <EOL> def save ( self ) : <EOL> self . instance . cert_type = models . CA_TYPE_EXISTING <EOL> cert_info = load_certificate ( self . instance . cert_certificate ) <EOL> self . instance . cert_country = cert_info [ '<STR_LIT>' ] <EOL> self . instance . cert_state = cert_info [ '<STR_LIT:state>' ] <EOL> self . instance . cert_city = cert_info [ '<STR_LIT>' ] <EOL> self . instance . cert_organization = cert_info [ '<STR_LIT>' ] <EOL> self . instance . cert_common = cert_info [ '<STR_LIT>' ] <EOL> self . instance . cert_email = cert_info [ '<STR_LIT:email>' ] <EOL> self . instance . cert_digest_algorithm = cert_info [ '<STR_LIT>' ] <EOL> cert_privatekey = self . cleaned_data . get ( '<STR_LIT>' ) <EOL> cert_passphrase = self . cleaned_data . get ( '<STR_LIT>' ) <EOL> if cert_passphrase and cert_privatekey : <EOL> privatekey = export_privatekey ( <EOL> cert_privatekey , <EOL> cert_passphrase <EOL> ) <EOL> self . instance . cert_privatekey = privatekey <EOL> super ( CertificateAuthorityImportForm , self ) . save ( ) <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> class Meta : <EOL> fields = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> model = models . CertificateAuthority <EOL> class CertificateAuthorityCreateInternalForm ( ModelForm ) : <EOL> cert_name = forms . CharField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_key_length = forms . ChoiceField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> choices = choices . CERT_KEY_LENGTH_CHOICES , <EOL> initial = <NUM_LIT> <EOL> ) <EOL> cert_digest_algorithm = forms . ChoiceField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> choices = choices . CERT_DIGEST_ALGORITHM_CHOICES , <EOL> initial = '<STR_LIT>' <EOL> ) <EOL> cert_lifetime = forms . IntegerField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> initial = <NUM_LIT> <EOL> ) <EOL> cert_country = forms . ChoiceField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> choices = choices . COUNTRY_CHOICES ( ) , <EOL> initial = '<STR_LIT>' , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_state = forms . CharField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_city = forms . CharField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_organization = forms . CharField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_email = forms . CharField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text , <EOL> ) <EOL> cert_common = forms . CharField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> def clean_cert_name ( self ) : <EOL> cdata = self . cleaned_data <EOL> name = cdata . get ( '<STR_LIT>' ) <EOL> certs = models . CertificateAuthority . objects . filter ( cert_name = name ) <EOL> if certs : <EOL> raise forms . ValidationError ( <EOL> "<STR_LIT>" <EOL> ) <EOL> if name in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> raise forms . ValidationError ( _ ( <EOL> "<STR_LIT>" . format ( name ) <EOL> ) ) <EOL> return name <EOL> def save ( self ) : <EOL> self . instance . cert_type = models . CA_TYPE_INTERNAL <EOL> cert_info = { <EOL> '<STR_LIT>' : self . instance . cert_key_length , <EOL> '<STR_LIT>' : self . instance . cert_country , <EOL> '<STR_LIT:state>' : self . instance . cert_state , <EOL> '<STR_LIT>' : self . instance . cert_city , <EOL> '<STR_LIT>' : self . instance . cert_organization , <EOL> '<STR_LIT>' : self . instance . cert_common , <EOL> '<STR_LIT:email>' : self . instance . cert_email , <EOL> '<STR_LIT>' : self . instance . cert_serial , <EOL> '<STR_LIT>' : self . instance . cert_lifetime , <EOL> '<STR_LIT>' : self . instance . cert_digest_algorithm <EOL> } <EOL> ( cert , key ) = create_self_signed_CA ( cert_info ) <EOL> self . instance . cert_certificate = crypto . dump_certificate ( crypto . FILETYPE_PEM , cert ) <EOL> self . instance . cert_privatekey = crypto . dump_privatekey ( crypto . FILETYPE_PEM , key ) <EOL> self . instance . cert_serial = <NUM_LIT:0> <NUM_LIT:2> <EOL> super ( CertificateAuthorityCreateInternalForm , self ) . save ( ) <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> class Meta : <EOL> fields = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> model = models . CertificateAuthority <EOL> class CertificateAuthorityCreateIntermediateForm ( ModelForm ) : <EOL> cert_name = forms . CharField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_key_length = forms . ChoiceField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> choices = choices . CERT_KEY_LENGTH_CHOICES , <EOL> initial = <NUM_LIT> <EOL> ) <EOL> cert_digest_algorithm = forms . ChoiceField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> choices = choices . CERT_DIGEST_ALGORITHM_CHOICES , <EOL> initial = '<STR_LIT>' <EOL> ) <EOL> cert_lifetime = forms . IntegerField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> initial = <NUM_LIT> <EOL> ) <EOL> cert_country = forms . ChoiceField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> choices = choices . COUNTRY_CHOICES ( ) , <EOL> initial = '<STR_LIT>' , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_state = forms . CharField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text , <EOL> ) <EOL> cert_city = forms . CharField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_organization = forms . CharField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_email = forms . CharField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_common = forms . CharField ( <EOL> label = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . CertificateAuthority . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( CertificateAuthorityCreateIntermediateForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fields [ '<STR_LIT>' ] . required = True <EOL> self . fields [ '<STR_LIT>' ] . queryset = ( <EOL> models . CertificateAuthority . objects . exclude ( <EOL> Q ( cert_certificate__isnull = True ) | <EOL> Q ( cert_privatekey__isnull = True ) | <EOL> Q ( cert_certificate__exact = '<STR_LIT>' ) | <EOL> Q ( cert_privatekey__exact = '<STR_LIT>' ) <EOL> ) <EOL> ) <EOL> self . fields [ '<STR_LIT>' ] . widget . attrs [ "<STR_LIT>" ] = ( <EOL> "<STR_LIT>" <EOL> ) <EOL> def clean_cert_name ( self ) : <EOL> cdata = self . cleaned_data <EOL> name = cdata . get ( '<STR_LIT>' ) <EOL> certs = models . CertificateAuthority . objects . filter ( cert_name = name ) <EOL> if certs : <EOL> raise forms . ValidationError ( <EOL> "<STR_LIT>" <EOL> ) <EOL> if name in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> raise forms . ValidationError ( _ ( <EOL> "<STR_LIT>" . format ( name ) <EOL> ) ) <EOL> return name <EOL> def save ( self ) : <EOL> self . instance . cert_type = models . CA_TYPE_INTERMEDIATE <EOL> cert_info = { <EOL> '<STR_LIT>' : self . instance . cert_key_length , <EOL> '<STR_LIT>' : self . instance . cert_country , <EOL> '<STR_LIT:state>' : self . instance . cert_state , <EOL> '<STR_LIT>' : self . instance . cert_city , <EOL> '<STR_LIT>' : self . instance . cert_organization , <EOL> '<STR_LIT>' : self . instance . cert_common , <EOL> '<STR_LIT:email>' : self . instance . cert_email , <EOL> '<STR_LIT>' : self . instance . cert_lifetime , <EOL> '<STR_LIT>' : self . instance . cert_digest_algorithm <EOL> } <EOL> signing_cert = self . instance . cert_signedby <EOL> publickey = generate_key ( self . instance . cert_key_length ) <EOL> signkey = load_privatekey ( signing_cert . cert_privatekey ) <EOL> cert = create_certificate ( cert_info ) <EOL> cert . set_pubkey ( publickey ) <EOL> cacert = crypto . load_certificate ( crypto . FILETYPE_PEM , signing_cert . cert_certificate ) <EOL> cert . set_issuer ( cacert . get_subject ( ) ) <EOL> cert . add_extensions ( [ <EOL> crypto . X509Extension ( "<STR_LIT>" , True , "<STR_LIT>" ) , <EOL> crypto . X509Extension ( "<STR_LIT>" , True , "<STR_LIT>" ) , <EOL> crypto . X509Extension ( "<STR_LIT>" , False , "<STR_LIT>" , subject = cert ) , <EOL> ] ) <EOL> cert . set_serial_number ( signing_cert . cert_serial ) <EOL> self . instance . cert_serial = <NUM_LIT:0> <NUM_LIT:3> <EOL> sign_certificate ( cert , signkey , self . instance . cert_digest_algorithm ) <EOL> self . instance . cert_certificate = crypto . dump_certificate ( crypto . FILETYPE_PEM , cert ) <EOL> self . instance . cert_privatekey = crypto . dump_privatekey ( crypto . FILETYPE_PEM , publickey ) <EOL> super ( CertificateAuthorityCreateIntermediateForm , self ) . save ( ) <EOL> ca = models . CertificateAuthority . objects . get ( cert_name = self . instance . cert_signedby . cert_name ) <EOL> ca . cert_serial = ca . cert_serial + <NUM_LIT:1> <EOL> ca . save ( ) <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> class Meta : <EOL> fields = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> model = models . CertificateAuthority <EOL> class CertificateForm ( ModelForm ) : <EOL> class Meta : <EOL> fields = '<STR_LIT>' <EOL> model = models . Certificate <EOL> def save ( self ) : <EOL> super ( CertificateForm , self ) . save ( ) <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> class CertificateEditForm ( ModelForm ) : <EOL> cert_name = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_certificate = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> widget = forms . Textarea ( ) , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( CertificateEditForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fields [ '<STR_LIT>' ] . widget . attrs [ '<STR_LIT>' ] = True <EOL> self . fields [ '<STR_LIT>' ] . widget . attrs [ '<STR_LIT>' ] = True <EOL> self . fields [ '<STR_LIT>' ] . widget . attrs [ '<STR_LIT>' ] = True <EOL> def save ( self ) : <EOL> super ( CertificateEditForm , self ) . save ( ) <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> class Meta : <EOL> fields = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> model = models . Certificate <EOL> class CertificateCSREditForm ( ModelForm ) : <EOL> cert_name = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_CSR = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> widget = forms . Textarea ( ) , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_certificate = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> widget = forms . Textarea ( ) , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( CertificateCSREditForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fields [ '<STR_LIT>' ] . widget . attrs [ '<STR_LIT>' ] = True <EOL> self . fields [ '<STR_LIT>' ] . widget . attrs [ '<STR_LIT>' ] = True <EOL> def save ( self ) : <EOL> self . instance . cert_type = models . CERT_TYPE_EXISTING <EOL> super ( CertificateCSREditForm , self ) . save ( ) <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> class Meta : <EOL> fields = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> model = models . Certificate <EOL> class CertificateImportForm ( ModelForm ) : <EOL> cert_name = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_certificate = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> widget = forms . Textarea ( ) , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_privatekey = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> widget = forms . Textarea ( ) , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_passphrase = forms . CharField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = False , <EOL> help_text = _ ( "<STR_LIT>" ) , <EOL> widget = forms . PasswordInput ( render_value = True ) , <EOL> ) <EOL> cert_passphrase2 = forms . CharField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = False , <EOL> widget = forms . PasswordInput ( render_value = True ) , <EOL> ) <EOL> def clean_cert_passphrase ( self ) : <EOL> cdata = self . cleaned_data <EOL> passphrase = cdata . get ( '<STR_LIT>' ) <EOL> privatekey = cdata . get ( '<STR_LIT>' ) <EOL> if not privatekey : <EOL> return passphrase <EOL> try : <EOL> load_privatekey ( privatekey , passphrase ) <EOL> except Exception : <EOL> raise forms . ValidationError ( _ ( "<STR_LIT>" ) ) <EOL> return passphrase <EOL> def clean_cert_passphrase2 ( self ) : <EOL> cdata = self . cleaned_data <EOL> passphrase = cdata . get ( '<STR_LIT>' ) <EOL> passphrase2 = cdata . get ( '<STR_LIT>' ) <EOL> if passphrase and passphrase != passphrase2 : <EOL> raise forms . ValidationError ( _ ( <EOL> '<STR_LIT>' <EOL> ) ) <EOL> return passphrase <EOL> def clean_cert_name ( self ) : <EOL> cdata = self . cleaned_data <EOL> name = cdata . get ( '<STR_LIT>' ) <EOL> certs = models . Certificate . objects . filter ( cert_name = name ) <EOL> if certs : <EOL> raise forms . ValidationError ( _ ( <EOL> "<STR_LIT>" <EOL> ) ) <EOL> if name in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> raise forms . ValidationError ( _ ( <EOL> "<STR_LIT>" . format ( name ) <EOL> ) ) <EOL> return name <EOL> def save ( self ) : <EOL> self . instance . cert_type = models . CERT_TYPE_EXISTING <EOL> cert_info = load_certificate ( self . instance . cert_certificate ) <EOL> self . instance . cert_country = cert_info [ '<STR_LIT>' ] <EOL> self . instance . cert_state = cert_info [ '<STR_LIT:state>' ] <EOL> self . instance . cert_city = cert_info [ '<STR_LIT>' ] <EOL> self . instance . cert_organization = cert_info [ '<STR_LIT>' ] <EOL> self . instance . cert_common = cert_info [ '<STR_LIT>' ] <EOL> self . instance . cert_email = cert_info [ '<STR_LIT:email>' ] <EOL> self . instance . cert_digest_algorithm = cert_info [ '<STR_LIT>' ] <EOL> cert_privatekey = self . cleaned_data . get ( '<STR_LIT>' ) <EOL> cert_passphrase = self . cleaned_data . get ( '<STR_LIT>' ) <EOL> if cert_passphrase and cert_privatekey : <EOL> privatekey = export_privatekey ( <EOL> cert_privatekey , <EOL> cert_passphrase <EOL> ) <EOL> self . instance . cert_privatekey = privatekey <EOL> super ( CertificateImportForm , self ) . save ( ) <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> class Meta : <EOL> fields = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> model = models . Certificate <EOL> class CertificateCreateInternalForm ( ModelForm ) : <EOL> cert_name = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_key_length = forms . ChoiceField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> choices = choices . CERT_KEY_LENGTH_CHOICES , <EOL> initial = <NUM_LIT> <EOL> ) <EOL> cert_digest_algorithm = forms . ChoiceField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> choices = choices . CERT_DIGEST_ALGORITHM_CHOICES , <EOL> initial = '<STR_LIT>' <EOL> ) <EOL> cert_lifetime = forms . IntegerField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> initial = <NUM_LIT> <EOL> ) <EOL> cert_country = forms . ChoiceField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> choices = choices . COUNTRY_CHOICES ( ) , <EOL> initial = '<STR_LIT>' , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_state = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_city = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_organization = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_email = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_common = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( CertificateCreateInternalForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fields [ '<STR_LIT>' ] . required = True <EOL> self . fields [ '<STR_LIT>' ] . queryset = ( <EOL> models . CertificateAuthority . objects . exclude ( <EOL> Q ( cert_certificate__isnull = True ) | <EOL> Q ( cert_privatekey__isnull = True ) | <EOL> Q ( cert_certificate__exact = '<STR_LIT>' ) | <EOL> Q ( cert_privatekey__exact = '<STR_LIT>' ) <EOL> ) <EOL> ) <EOL> self . fields [ '<STR_LIT>' ] . widget . attrs [ "<STR_LIT>" ] = ( <EOL> "<STR_LIT>" <EOL> ) <EOL> def clean_cert_name ( self ) : <EOL> cdata = self . cleaned_data <EOL> name = cdata . get ( '<STR_LIT>' ) <EOL> certs = models . Certificate . objects . filter ( cert_name = name ) <EOL> if certs : <EOL> raise forms . ValidationError ( <EOL> "<STR_LIT>" <EOL> ) <EOL> if name . find ( '<STR_LIT:">' ) != - <NUM_LIT:1> : <EOL> raise forms . ValidationError ( <EOL> """<STR_LIT>""" <EOL> ) <EOL> if name in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> raise forms . ValidationError ( _ ( <EOL> "<STR_LIT>" . format ( name ) <EOL> ) ) <EOL> return name <EOL> def save ( self ) : <EOL> self . instance . cert_type = models . CERT_TYPE_INTERNAL <EOL> cert_info = { <EOL> '<STR_LIT>' : self . instance . cert_key_length , <EOL> '<STR_LIT>' : self . instance . cert_country , <EOL> '<STR_LIT:state>' : self . instance . cert_state , <EOL> '<STR_LIT>' : self . instance . cert_city , <EOL> '<STR_LIT>' : self . instance . cert_organization , <EOL> '<STR_LIT>' : self . instance . cert_common , <EOL> '<STR_LIT:email>' : self . instance . cert_email , <EOL> '<STR_LIT>' : self . instance . cert_lifetime , <EOL> '<STR_LIT>' : self . instance . cert_digest_algorithm <EOL> } <EOL> signing_cert = self . instance . cert_signedby <EOL> publickey = generate_key ( self . instance . cert_key_length ) <EOL> signkey = crypto . load_privatekey ( <EOL> crypto . FILETYPE_PEM , <EOL> signing_cert . cert_privatekey <EOL> ) <EOL> cert = create_certificate ( cert_info ) <EOL> cert . set_pubkey ( publickey ) <EOL> cacert = crypto . load_certificate ( crypto . FILETYPE_PEM , signing_cert . cert_certificate ) <EOL> cert . set_issuer ( cacert . get_subject ( ) ) <EOL> cert . add_extensions ( [ <EOL> crypto . X509Extension ( "<STR_LIT>" , False , "<STR_LIT>" , <EOL> subject = cert ) , <EOL> ] ) <EOL> cert_serial = signing_cert . cert_serial <EOL> if not cert_serial : <EOL> cert_serial = <NUM_LIT:1> <EOL> cert . set_serial_number ( cert_serial ) <EOL> sign_certificate ( cert , signkey , self . instance . cert_digest_algorithm ) <EOL> self . instance . cert_certificate = crypto . dump_certificate ( crypto . FILETYPE_PEM , cert ) <EOL> self . instance . cert_privatekey = crypto . dump_privatekey ( crypto . FILETYPE_PEM , publickey ) <EOL> super ( CertificateCreateInternalForm , self ) . save ( ) <EOL> ca = models . CertificateAuthority . objects . get ( cert_name = self . instance . cert_signedby . cert_name ) <EOL> ca_cert_serial = ca . cert_serial <EOL> if not ca_cert_serial : <EOL> ca_cert_serial = cert_serial <EOL> ca_cert_serial += <NUM_LIT:1> <EOL> ca . cert_serial = ca_cert_serial <EOL> ca . save ( ) <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> class Meta : <EOL> fields = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> model = models . Certificate <EOL> class CertificateCreateCSRForm ( ModelForm ) : <EOL> cert_name = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_key_length = forms . ChoiceField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> choices = choices . CERT_KEY_LENGTH_CHOICES , <EOL> initial = <NUM_LIT> <EOL> ) <EOL> cert_digest_algorithm = forms . ChoiceField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> choices = choices . CERT_DIGEST_ALGORITHM_CHOICES , <EOL> initial = '<STR_LIT>' <EOL> ) <EOL> cert_country = forms . ChoiceField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> choices = choices . COUNTRY_CHOICES ( ) , <EOL> initial = '<STR_LIT>' , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_state = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_city = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text , <EOL> ) <EOL> cert_organization = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_email = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> cert_common = forms . CharField ( <EOL> label = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . verbose_name , <EOL> required = True , <EOL> help_text = models . Certificate . _meta . get_field ( '<STR_LIT>' ) . help_text <EOL> ) <EOL> def clean_cert_name ( self ) : <EOL> cdata = self . cleaned_data <EOL> name = cdata . get ( '<STR_LIT>' ) <EOL> certs = models . Certificate . objects . filter ( cert_name = name ) <EOL> if certs : <EOL> raise forms . ValidationError ( <EOL> "<STR_LIT>" <EOL> ) <EOL> if name in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> raise forms . ValidationError ( _ ( <EOL> "<STR_LIT>" . format ( name ) <EOL> ) ) <EOL> return name <EOL> def save ( self ) : <EOL> self . instance . cert_type = models . CERT_TYPE_CSR <EOL> req_info = { <EOL> '<STR_LIT>' : self . instance . cert_key_length , <EOL> '<STR_LIT>' : self . instance . cert_country , <EOL> '<STR_LIT:state>' : self . instance . cert_state , <EOL> '<STR_LIT>' : self . instance . cert_city , <EOL> '<STR_LIT>' : self . instance . cert_organization , <EOL> '<STR_LIT>' : self . instance . cert_common , <EOL> '<STR_LIT:email>' : self . instance . cert_email , <EOL> '<STR_LIT>' : self . instance . cert_digest_algorithm <EOL> } <EOL> ( req , key ) = create_certificate_signing_request ( req_info ) <EOL> self . instance . cert_CSR = crypto . dump_certificate_request ( crypto . FILETYPE_PEM , req ) <EOL> self . instance . cert_privatekey = crypto . dump_privatekey ( crypto . FILETYPE_PEM , key ) <EOL> super ( CertificateCreateCSRForm , self ) . save ( ) <EOL> notifier ( ) . start ( "<STR_LIT>" ) <EOL> class Meta : <EOL> fields = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> model = models . Certificate <EOL> class BackupForm ( Form ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( BackupForm , self ) . __init__ ( * args , ** kwargs ) <EOL> backup_hostname = forms . CharField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = True ) <EOL> backup_username = forms . CharField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = True ) <EOL> backup_password = forms . CharField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = False , <EOL> widget = forms . widgets . PasswordInput ( ) , <EOL> ) <EOL> backup_password2 = forms . CharField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = False , <EOL> widget = forms . widgets . PasswordInput ( ) , <EOL> ) <EOL> backup_directory = forms . CharField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = True ) <EOL> backup_data = forms . BooleanField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = False ) <EOL> backup_compression = forms . BooleanField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = False ) <EOL> backup_auth_keys = forms . BooleanField ( <EOL> label = _ ( "<STR_LIT>" ) , <EOL> required = False ) <EOL> def clean_backup_password2 ( self ) : <EOL> pwd = self . cleaned_data . get ( '<STR_LIT>' ) <EOL> pwd2 = self . cleaned_data . get ( '<STR_LIT>' ) <EOL> if pwd and pwd != pwd2 : <EOL> raise forms . ValidationError ( <EOL> _ ( "<STR_LIT>" ) <EOL> ) <EOL> return pwd2 </s>
