define("app/services/backupConfigurationServices",["angular","lodash","cjt/util/parse","cjt/io/whm-v1-request","cjt/io/whm-v1","cjt/services/APIService"],(function(e,t,a,n){"use strict";var i="",s=e.module("whm.backupConfiguration.backupConfigurationServices.service",[]);s.value("PAGE",PAGE);var o=["backup_daily_enable","backup_monthly_enable","backup_weekly_enable","backupaccts","backupbwdata","backupenable","backupfiles","backuplogs","backupmount","backupsuspendedaccts","check_min_free_space","force_prune_daily","force_prune_monthly","force_prune_weekly","keeplocal","linkdest","localzonesonly","postbackup","psqlbackup"],r=["backup_daily_retention","backup_monthly_retention","backup_weekly_day","backup_weekly_retention","errorthreshhold","maximum_restore_timeout","maximum_timeout","min_free_space"],d=["backup_monthly_dates","backupdays"];s.factory("backupConfigurationServices",["$q","APIService","PAGE",function(s,u,c){var l=this;function p(e){for(var t=e.data.backup_config,n=0,i=o.length;n<i;n++){var s=o[n];t[s]=a.parsePerlBoolean(t[s])}var u=0;for(i=r.length;u<i;u++){var c=r[u];t[c]=parseInt(t[c],10)}var p=0;for(i=d.length;p<i;p++){var m=d[p],g=t[m].split(",");t[m]={},g.forEach((function(e){t[m][e]=e}))}return l.settings=t,l.settings}function m(e){var t=e.data,n=[];return t.forEach((function(e){e.disabled=a.parsePerlBoolean(e.disabled),e.upload_system_backup=a.parsePerlBoolean(e.upload_system_backup),e.only_used_for_logs=a.parsePerlBoolean(e.only_used_for_logs),n.push(e)})),l.destinations=n,l.destinations}function g(e){var t=e.data,n=t.type.toLowerCase(),i={};for(var s in i[n]={},t.disabled=a.parsePerlBoolean(t.disabled),t.upload_system_backup=a.parsePerlBoolean(t.upload_system_backup),t.only_used_for_logs=a.parsePerlBoolean(t.only_used_for_logs),t.timeout&&(t.timeout=parseInt(t.timeout,10)),t.passive&&(t.passive=a.parsePerlBoolean(t.passive)),t.port&&(t.port=parseInt(t.port,10)),t.mount&&(t.mount=a.parsePerlBoolean(t.mount)),t.ssl&&(t.ssl=a.parsePerlBoolean(t.ssl)),t)t.hasOwnProperty(s)&&(i[n][s]=t[s]);return i}function f(e){var t;for(var a in e)e.hasOwnProperty(a)&&(t=e[a]);return t}function h(e){var t="";for(var a in e)e.hasOwnProperty(a)&&(t+=e[a]+",");return t.substring(0,t.length-1)}function y(e){var t=e.destination,a=e.apiCall;return a.addArgument("id",t.id),a.addArgument("name",t.name),a.addArgument("type",t.type),a.addArgument("disabled",t.disabled?1:0),a.addArgument("upload_system_backup",t.upload_system_backup?1:0),a.addArgument("only_used_for_logs",t.only_used_for_logs?1:0),"Local"!==t.destination&&t.timeout&&a.addArgument("timeout",t.timeout),"FTP"!==t.type&&"SFTP"!==t.type&&"Rsync"!==t.type&&"WebDAV"!==t.type||!t.port||a.addArgument("port",t.port),"Custom"===t.type&&(a.addArgument("script",t.script),a.addArgument("host",t.host),a.addArgument("path",t.path),a.addArgument("username",t.username),a.addArgument("password",t.password)),"FTP"===t.type&&(a.addArgument("host",t.host),a.addArgument("path",t.path),a.addArgument("passive",t.passive?1:0),a.addArgument("username",t.username),a.addArgument("password",t.password)),"GoogleDrive"===t.type&&(a.addArgument("client_id",t.client_id),a.addArgument("client_secret",t.client_secret),a.addArgument("folder",t.folder)),"Local"===t.type&&(a.addArgument("mount",t.mount?1:0),a.addArgument("path",t.path),a.addArgument("no_mount_fail",t.no_mount_fail)),"AmazonS3"!==t.type&&"S3Compatible"!==t.type||(a.addArgument("folder",t.folder),a.addArgument("bucket",t.bucket),a.addArgument("aws_access_key_id",t.aws_access_key_id),a.addArgument("password",t.password),"S3Compatible"===t.type&&a.addArgument("host",t.host)),"SFTP"===t.type&&(a.addArgument("host",t.host),a.addArgument("path",t.path),a.addArgument("username",t.username),a.addArgument("authtype",t.authtype),a.addArgument("password",t.password),a.addArgument("privatekey",t.privatekey),a.addArgument("passphrase",t.passphrase)),"Rsync"===t.type&&(a.addArgument("host",t.host),a.addArgument("path",t.path),a.addArgument("username",t.username),a.addArgument("authtype",t.authtype),a.addArgument("password",t.password),a.addArgument("privatekey",t.privatekey),a.addArgument("passphrase",t.passphrase)),"WebDAV"===t.type&&(a.addArgument("host",t.host),a.addArgument("path",t.path),a.addArgument("ssl",t.ssl?1:0),a.addArgument("username",t.username),a.addArgument("password",t.password)),"Backblaze"===t.type&&(a.addArgument("application_key",t.application_key),a.addArgument("application_key_id",t.application_key_id),a.addArgument("bucket_id",t.bucket_id),a.addArgument("bucket_name",t.bucket_name),a.addArgument("path",t.path)),a}l.settings=null,l.destinations=[];var k=function(){};return k.prototype=new u,e.extend(k.prototype,{_testHarness:function(e,t){switch(e){case"parseDestination":return g(t);case"parseDestinations":return m(t);case"serializeProperty":return h(t);case"parseConfigData":return p(t);case"serializeDestination":return f(t);case"buildDestinationAPICall":return y(t);default:return null}},getBackupConfig:function(){if(l.settings)return s.resolve(l.settings);var e=new n.Class;return e.initialize(i,"backup_config_get"),this.deferred(e,{transformAPISuccess:p}).promise},setBackupConfig:function(e){var t=new n.Class;return t.initialize(i,"backup_config_set"),t.addArgument("backup_daily_enable",e.backup_daily_enable?1:0),t.addArgument("backupenable",e.backupenable?1:0),t.addArgument("backup_monthly_enable",e.backup_monthly_enable?1:0),t.addArgument("backuptype",e.backuptype),t.addArgument("backup_daily_retention",e.backup_daily_retention),e.backup_daily_enable&&t.addArgument("backupdays",h(e.backupdays)),t.addArgument("backupfiles",e.backupfiles?1:0),t.addArgument("backupaccts",e.backupaccts?1:0),t.addArgument("keeplocal",e.keeplocal?1:0),t.addArgument("localzonesonly",e.localzonesonly?1:0),t.addArgument("backupbwdata",e.backupbwdata?1:0),t.addArgument("backuplogs",e.backuplogs?1:0),t.addArgument("backupsuspendedaccts",e.backupsuspendedaccts?1:0),t.addArgument("backupdir",e.backupdir),t.addArgument("remote_restore_staging_dir",e.remote_restore_staging_dir),t.addArgument("backupmount",e.backupmount?1:0),t.addArgument("mysqlbackup",e.mysqlbackup),t.addArgument("backup_monthly_retention",e.backup_monthly_retention),t.addArgument("check_min_free_space",e.check_min_free_space?1:0),t.addArgument("min_free_space",e.min_free_space),t.addArgument("min_free_space_unit",e.min_free_space_unit),t.addArgument("force_prune_daily",e.force_prune_daily?1:0),t.addArgument("force_prune_weekly",e.force_prune_weekly?1:0),t.addArgument("force_prune_monthly",e.force_prune_monthly?1:0),t.addArgument("maximum_timeout",e.maximum_timeout),t.addArgument("maximum_restore_timeout",e.maximum_restore_timeout),t.addArgument("backup_weekly_enable",e.backup_weekly_enable?1:0),t.addArgument("backup_weekly_day",e.backup_weekly_day),t.addArgument("backup_weekly_retention",e.backup_weekly_retention),e.backup_monthly_dates&&t.addArgument("backup_monthly_dates",h(e.backup_monthly_dates)),this.deferred(t).promise},getDestinationList:function(){if(l.destinations.length>0)return s.resolve(l.destinations);var e=new n.Class;return e.initialize(i,"backup_destination_list"),this.deferred(e,{transformAPISuccess:m}).promise},validateDestination:function(e){var t=new n.Class;return t.initialize(i,"backup_destination_validate"),t.addArgument("id",e),t.addArgument("disableonfail",1),this.deferred(t).promise},deleteDestination:function(e){var a=new n.Class;return a.initialize(i,"backup_destination_delete"),a.addArgument("id",e),this.deferred(a,{transformAPISuccess:function(a){return l.destinations.length>0&&t.remove(l.destinations,(function(t){return t.id===e})),a}}).promise},toggleStatus:function(e,t){var a=new n.Class;return a.initialize(i,"backup_destination_set"),a.addArgument("id",e),a.addArgument("disabled",t?1:0),this.deferred(a).promise},getDestination:function(e){var t=new n.Class;return t.initialize(i,"backup_destination_get"),t.addArgument("id",e),this.deferred(t,{transformAPISuccess:g}).promise},updateCurrentDestination:function(e){var a=f(e),s=new n.Class;return s.initialize(i,"backup_destination_set"),y({destination:a,apiCall:s}),this.deferred(s,{transformAPISuccess:function(a){var n=Object.keys(e)[0],i=e[n],s=t.find(l.destinations,(function(e){return e.id===i.id}));if(s&&"object"==typeof i)for(var o in i)i.hasOwnProperty(o)&&(s[o]=i[o]);return a.data}}).promise},setNewDestination:function(e){var a=f(e),s=new n.Class;return s.initialize(i,"backup_destination_add"),y({destination:a,apiCall:s}),this.deferred(s,{transformAPISuccess:function(a){var n=t.assign({},e[Object.keys(e)[0]],a.data);return l.destinations.push(n),a.data}}).promise},generateGoogleCredentials:function(e,t){var a=new n.Class;return a.initialize(i,"backup_generate_google_oauth_uri"),a.addArgument("client_id",e),a.addArgument("client_secret",t),this.deferred(a,{transformAPISuccess:function(e){return e.data}}).promise},checkForGoogleCredentials:function(e){var t=new n.Class;return t.initialize(i,"backup_does_client_id_have_google_credentials"),t.addArgument("client_id",e),this.deferred(t,{transformAPISuccess:function(e){return!!e.data.exists}}).promise},generateSSHKeyPair:function(e,t){var a=new n.Class;return a.initialize(i,"generatesshkeypair"),a.addArgument("user",t),a.addArgument("passphrase",e.passphrase),a.addArgument("name",e.name),a.addArgument("bits",e.bits),a.addArgument("algorithm","RSA"===e.algorithm?"rsa2":"dsa"),a.addArgument("abort_on_existing_key",1),a.addArgument("comment",e.comment?e.comment:""),this.deferred(a).promise},listSSHKeys:function(){var e=new n.Class;return e.initialize(i,"listsshkeys"),e.addArgument("user","root"),e.addArgument("private",1),e.addArgument("public",0),this.deferred(e,{transformAPISuccess:function(e){var t=[];return e.data.forEach((function(e){t.push(e.file)})),t}}).promise}}),new k}])})),define("app/services/validationLog",["angular","lodash","cjt/core","cjt/util/locale","cjt/services/alertService"],(function(e,t,a,n,i){"use strict";e.module("whm.backupConfiguration.validationLog.service",[]).factory("validationLog",["$window","alertService",function(e,a){var i=[];function s(e){"object"==typeof e&&(e.hasOwnProperty("destinationId")?this.cloneProperties(e):(this.name=e.name,this.destinationId=e.id,this.transport=e.type,this.status="running",this.updateBeginTime()),"running"===this.status&&s.inProgress++)}return s.quickAccess={},s.inProgress=0,s.updateQuickAccess=function(e){s.quickAccess={},Array.isArray(e)&&e.length>0&&e.forEach((function(e){"object"==typeof e&&e.hasOwnProperty("destinationId")&&(s.quickAccess[e.destinationId]=e)}))},s.getStatusFor=function(e){return s.quickAccess.hasOwnProperty(e)?s.quickAccess[e].status:null},s.prototype.cloneProperties=function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t])},s.prototype.updateBeginTime=function(){var e=new Date;this.beginTime=Date.now(),e.setTime(this.beginTime),this.formattedBeginTime=e.toLocaleTimeString()},s.prototype.resetElapsedTime=function(){delete this.endTime,delete this.elapsedTime,delete this.alert,delete this.formattedElapsedTime,this.status="running",s.inProgress++},s.prototype.generateElapsedTime=function(){this.endTime=Date.now(),this.elapsedTime=this.endTime-this.beginTime,this.formattedElapsedTime=n.maketext("[_1] [numerate,_1,second,seconds]",Math.round(this.elapsedTime/1e3))},s.prototype.markAsComplete=function(e){this.generateElapsedTime(),"success"===e.type?this.status="success":this.status="failure",s.inProgress--,this.alert=e},s.prototype.addTo=function(e){if(Array.isArray(e)){if(!s.quickAccess.hasOwnProperty(this.destinationId))return e.push(this),s.quickAccess[this.destinationId]=this,!0;this.status="running",this.updateBeginTime(),this.resetElapsedTime()}return!1},{getLogEntries:function(){if(0===i.length){var t=e.sessionStorage.getItem("destination_validation_log");if(t)JSON.parse(t).forEach((function(e){i.push(new s(e))}));s.updateQuickAccess(i)}return i},cacheLogEntries:function(){e.sessionStorage.setItem("destination_validation_log",JSON.stringify(i))},clearCache:function(){e.sessionStorage.removeItem("destination_validation_log")},hasLogEntries:function(){return i&&i.length>0},updateValidationInfo:function(e,a){s.quickAccess.hasOwnProperty(e)&&(s.quickAccess[e].name=t.escape(a))},add:function(e){var t=null;s.quickAccess.hasOwnProperty(e.id)?((t=s.quickAccess[e.id]).resetElapsedTime(),t.updateBeginTime()):((t=new s(e)).addTo(i),s.quickAccess[t.destinationId]=t),this.cacheLogEntries()},remove:function(e){s.quickAccess.hasOwnProperty(e)&&("running"===s.quickAccess[e].status&&s.inProgress--,delete s.quickAccess[e],t.remove(i,(function(t){return t.destinationId===e})),this.cacheLogEntries())},isValidationInProgressFor:function(e){return"running"===s.getStatusFor(e.id)},isValidationRunning:function(){return s.inProgress>0},getInProgressCount:function(){return s.inProgress},validateAllStatus:function(e){return s.quickAccess.hasOwnProperty(e)?s.quickAccess[e].status:null},validateAllSuccessFor:function(e){return"success"===this.validateAllStatus(e)},validateAllFailureFor:function(e){return"failure"===this.validateAllStatus(e)},markAsComplete:function(e,t){s.quickAccess.hasOwnProperty(e)&&(s.quickAccess[e].markAsComplete(t),this.cacheLogEntries())},showValidationMessageFor:function(e){s.quickAccess.hasOwnProperty(e)&&s.quickAccess[e].hasOwnProperty("alert")&&a.add(s.quickAccess[e].alert)}}}])})),define("app/directives/formValidator",["angular","cjt/util/locale","cjt/validator/validator-utils","cjt/validator/domain-validators","cjt/validator/path-validators","cjt/validator/ip-validators","cjt/validator/validateDirectiveFactory"],(function(e,t,a,n,i,s){"use strict";var o=/^(127(\.\d+){1,3}|[0:]+1|localhost)$/i,r=/^http(s)*:\/*/,d=/:\d*$/,u=/^[a-z0-9-]*$/,c=/^[a-z0-9-.]*$/,l=/^[A-Za-z0-9-]*$/,p=/^[-]/,m=/[-]$/,g=/^[-.]/,f=/[-.]$/,h=/^b2-/i,y=t.maketext("You must enter a relative path."),k=t.maketext("You must enter a path within the user home directory."),v=t.maketext("You cannot enter a loopback address for the remote address."),b=t.maketext("You must enter a value without slashes."),_=t.maketext("You must enter a value without spaces."),S=t.maketext("The remote host address must not contain a protocol."),A=t.maketext("The remote host address must not contain path information."),w=t.maketext("The remote host address must not contain a port number."),D=t.maketext("You must enter an absolute path."),C=t.maketext("The remote host address must be a valid hostname or IP address."),P=t.maketext("The bucket name must be between [numf,3] and [numf,63] characters."),T=t.maketext("The bucket name must be between [numf,6] and [numf,50] characters."),L=t.maketext("The bucket name must not begin or end with a hyphen."),x=t.maketext("The bucket name must not begin or end with a hyphen or a period."),V=t.maketext("The bucket name must only contain numbers, hyphens, and lowercase letters."),B=t.maketext("The bucket name must only contain numbers, periods, hyphens, and lowercase letters."),I=t.maketext("The bucket name must only contain numbers, hyphens, and letters."),E=t.maketext("The [asis,Backblaze] [asis,B2] bucket name must not begin with “b2-” because [asis,Backblaze] reserves this prefix."),j={backupLocation:function(e,t){var n=a.initializeValidationResult();return n.isValid=!1,e?"absolute"!==t&&e.length>0&&"/"===e[0]?n.add("backupConfigIssue",y):"../"===e.substring(0,3)?n.add("backupConfigIssue",k):n=i.methods.validPath(e):n.isValid=!0,n},bucket:function(e,t){var n=a.initializeValidationResult();return n.isValid=!1,"b2"===t&&h.test(e)?n.add("backupConfigIssue",E):"b2"!==t||l.test(e)?"amazon"!==t||c.test(e)?"amazon"===t||"b2"===t||u.test(e)?"amazon"===t&&(g.test(e)||f.test(e))?n.add("backupConfigIssue",x):"amazon"!==t&&"b2"!==t&&(p.test(e)||m.test(e))?n.add("backupConfigIssue",L):"b2"===t&&(e.length<6||e.length>50)?n.add("backupConfigIssue",T):e.length<3||e.length>63?n.add("backupConfigIssue",P):n.isValid=!0:n.add("backupConfigIssue",V):n.add("backupConfigIssue",B):n.add("backupConfigIssue",I),n},remoteHost:function(e){var t=a.initializeValidationResult();t.isValid=!1;var i=s.methods.ipv4(e);if(i.isValid)return o.test(e)?(t.add("backupConfigIssue",v),t):i;if(r.test(e))return t.add("backupConfigIssue",S),t;if(e.indexOf("/")>=0||e.indexOf("\\")>=0)return t.add("backupConfigIssue",A),t;if(d.test(e))return t.add("backupConfigIssue",w),t;var u=n.methods.fqdn(e);return i.isValid||u.isValid?u:(t.add("backupConfigIssue",C),t)},noslashes:function(e){var t=a.initializeValidationResult();return t.isValid=!1,e.indexOf("/")<0&&e.indexOf("\\")<0?t.isValid=!0:t.add("backupConfigIssue",b),t},nospaces:function(e){var t=a.initializeValidationResult();return t.isValid=!1,e.indexOf(" ")<0?t.isValid=!0:t.add("backupConfigIssue",_),t},fullPath:function(e){var t=a.initializeValidationResult();return t.isValid=!0,e?(0!==e.indexOf("/")?(t.isValid=!1,t.add("backupConfigIssue",D)):t=i.methods.validPath(e),t):t}};return e.module("cjt2.validate").run(["validatorFactory",function(e){e.generate(j)}]),{methods:j,name:"backupConfigurationValidators",description:"Validation library for Backup Configuration.",version:1}})),define("app/views/config",["angular","lodash","cjt/util/locale","cjt/util/table","cjt/services/alertService","cjt/directives/alertList","cjt/directives/actionButtonDirective","cjt/directives/validationContainerDirective","cjt/directives/validationItemDirective","cjt/validator/datatype-validators","cjt/validator/username-validators","cjt/validator/compare-validators","app/services/backupConfigurationServices"],(function(e,t,a,n){"use strict";return e.module("whm.backupConfiguration").controller("config",["$scope","$location","$anchorScroll","$q","$window","backupConfigurationServices","alertService","$timeout",function(e,n,i,s,o,r,d,u){var c=function(e){var a=t.clone(e);return e.hasOwnProperty("backupdays")&&(a.backupdays=t.clone(e.backupdays)),e.hasOwnProperty("backup_monthly_dates")&&(a.backup_monthly_dates=t.clone(e.backup_monthly_dates)),a};e.getBackupConfiguration=function(){d.clear(),r.getBackupConfig().then((function(t){e.initialFormData?e.formData=c(t):(e.formData=c(t),e.initialFormData=c(t)),e.backupConfigLoaded=!0,e.formEnabled=e.formData.backupenable,e.setMonthlyBackupDays()}),(function(t){d.add({type:"danger",message:t,id:"configuration-loading-error",closeable:!0}),e.backupConfigLoaded=!0}))},e.handleUnitToggle=function(t){if("%"===t)e.formData.min_free_space_unit="percent";else{if("MB"!==t)throw"DEVELOPER ERROR: value argument has unexpected value: "+t;e.formData.min_free_space_unit="MB"}},e.handleDaysToggle=function(t,a){e.formData.backupdays[t]?delete e.formData.backupdays[t]:e.formData.backupdays[t]=t.toString(),a.$setDirty(),e.selectedDays=Object.keys(e.formData.backupdays)},e.handleDayToggle=function(t,a){e.formData.backup_weekly_day=t,a.$setDirty()},e.handleMonthlyToggle=function(t){if(e.formData.backup_monthly_dates||(e.formData.backup_monthly_dates={}),"first"===t)e.formData.backup_monthly_dates[1]?delete e.formData.backup_monthly_dates[1]:e.formData.backup_monthly_dates[1]="1";else{if("fifteenth"!==t)throw"DEVELOPER ERROR: value argument has unexpected value: "+t;e.formData.backup_monthly_dates[15]?delete e.formData.backup_monthly_dates[15]:e.formData.backup_monthly_dates[15]="15"}e.setMonthlyBackupDays()},e.setMonthlyBackupDays=function(){e.monthlyBackupBool||(e.monthlyBackupBool={}),e.formData.backup_monthly_dates[1]?e.monthlyBackupBool.first=!0:e.monthlyBackupBool.first=!1,e.formData.backup_monthly_dates[15]?e.monthlyBackupBool.fifteenth=!0:e.monthlyBackupBool.fifteenth=!1,e.monthlyBackupBool.first||e.monthlyBackupBool.fifteenth||delete e.formData.backup_monthly_dates},e.redirectToSelectUsers=function(){window.open("../backup_user_selection")},e.saveConfiguration=function(t){return e.saving=!0,r.setBackupConfig(e.formData).then((function(n){e.initialFormData=c(e.formData),d.add({type:"success",autoClose:5e3,message:a.maketext("The system successfully saved the backup configuration."),id:"save-configuration-succeeded"}),t.$setPristine()})).catch((function(e){d.add({type:"danger",closeable:!0,message:e,id:"save-configuration-failed"})})).finally((function(){e.saving=!1}))},e.resetConfiguration=function(t){e.formData=c(e.initialFormData),e.enableBackupConfig(),e.selectedDays=Object.keys(e.formData.backupdays),e.setMonthlyBackupDays(),t.$setPristine(),n.hash("backup_status"),i()},e.enableBackupConfig=function(){e.formData.backupenable?e.formEnabled=!0:e.formEnabled=!1},e.noDecimalPoints=function(e){var t=e.originalEvent;(t.hasOwnProperty("key")&&"."===t.key||190===t.keyCode)&&e.preventDefault()},e.onlyNumbers=function(e){e.originalEvent.clipboardData.getData("text").match(/[0-9]+/)||e.preventDefault()},e.init=function(){e.backupConfigLoaded=!1,e.getBackupConfiguration(),e.dailyDays=[a.maketext("Sunday"),a.maketext("Monday"),a.maketext("Tuesday"),a.maketext("Wednesday"),a.maketext("Thursday"),a.maketext("Friday"),a.maketext("Saturday")],e.weeklyDays=[a.maketext("Sunday"),a.maketext("Monday"),a.maketext("Tuesday"),a.maketext("Wednesday"),a.maketext("Thursday"),a.maketext("Friday"),a.maketext("Saturday")],e.absolutePathRegEx=/^\/./,e.relativePathRegEx=/^\w./,e.remoteHostValidation=/^[a-z0-9.-]{1,}$/i,e.remoteHostLoopbackValue=/^(127(\.\d+){1,3}|[0:]+1|localhost)$/i,e.disallowedPathChars=/[\\?%*:|"<>]/g,e.validating=!1,e.toggled=!0,e.saving=!1,e.deleting=!1,e.updating=!1,e.showDeleteConfirmation=!1,e.destinationName="",e.destinationId="",e.activeTab=0},e.init()}])})),define("app/views/destinations",["angular","lodash","cjt/util/locale","cjt/util/table","cjt/services/alertService","cjt/directives/alertList","cjt/directives/toggleSortDirective","cjt/directives/actionButtonDirective","cjt/directives/validationContainerDirective","cjt/directives/validationItemDirective","cjt/validator/datatype-validators","cjt/validator/username-validators","cjt/validator/compare-validators","app/services/backupConfigurationServices","app/services/validationLog"],(function(e,t,a,n){"use strict";var i=e.module("whm.backupConfiguration"),s=new n;return i.controller("destinations",["$scope","$location","$q","$window","backupConfigurationServices","alertService","$timeout","validationLog",function(n,i,o,r,d,u,c,l){n.setupDeleteConfirmation=function(e,t,a){n.index=a,n.showDeleteConfirmation=!n.showDeleteConfirmation,n.updating=!n.updating,n.destinationName=e,n.destinationId=t},n.enableBackupConfig=function(){n.formData.backupenable?n.formEnabled=!0:n.formEnabled=!1},n.isValidationInProgressFor=function(e){return l.isValidationInProgressFor(e)},n.isValidationRunning=function(){return l.isValidationRunning()},n.validateDestination=function(e,i,s){s||(s={}),s.all||n.clearAlerts(),n.destinationState.validatingDestination=!0,n.displayAlertRows=[],n.displayAlertRows.push(e);var o=t.find(n.destinationState.destinationList,(function(t){return t.id===e}));return l.add(o),n.currentlyValidating=l.getLogEntries(),d.validateDestination(e).then((function(o){var r={type:"success",id:"validate-destination-succeeded-"+e,message:a.maketext("The validation for the “[_1]” destination succeeded.",t.escape(i)),closeable:!0,autoClose:1e4};s.all&&(r.replace=!1),l.markAsComplete(e,r),n.destinationState.validatingAllDestinations||u.add(r)})).catch((function(a){var i={type:"danger",message:t.escape(a),closeable:!0,replace:!1,id:"validate-destination-failed-"+e};s.all&&(i.replace=!1),o.disabled=!0,l.markAsComplete(e,i),n.destinationState.validatingAllDestinations||u.add(i)})).finally((function(){n.destinationState.validatingDestination=n.isValidationRunning(),n.destinationState.showValidationIconHint=!0}))},n.getDestinations=function(){return n.destinationState.destinationListLoaded=!1,d.getDestinationList().then((function(e){n.destinationState.destinationList=e,n.destinationState.destinationListLoaded=!0,n.updating=!1,n.currentlyValidating=l.getLogEntries(),n.setPagination(e)}),(function(e){n.destinationState.destinationListLoaded=!0,n.updating=!1,u.add({type:"danger",closeable:!0,message:e,id:"fetch-destinations-failed"})}))},n.setPagination=function(e){e&&(s.load(e),s.setSort("name,type","asc"),s.meta.limit=e.length,s.meta.pageSize=e.length),s.update(),n.meta=s.getMetadata(),n.filteredDestinationList=s.getList()},n.updateTable=function(){n.setPagination()},n.setTemplatePath=function(e){"Custom"===e?n.templatePath="views/customTransport.ptt":"FTP"===e?n.templatePath="views/FTPTransport.ptt":"GoogleDrive"===e?n.templatePath="views/GoogleTransport.ptt":"Local"===e||"Additional Local Directory"===e?n.templatePath="views/LocalTransport.ptt":"SFTP"===e?n.templatePath="views/SFTPTransport.ptt":"Amazon S3"===e||"AmazonS3"===e?n.templatePath="views/AmazonS3Transport.ptt":"Rsync"===e?n.templatePath="views/RsyncTransport.ptt":"WebDAV"===e?n.templatePath="views/WebDAVTransport.ptt":"S3Compatible"===e?n.templatePath="views/S3CompatibleTransport.ptt":"Backblaze"===e&&(n.templatePath="views/B2.ptt")},n.formattedTransportType=function(e){return"Backblaze"===e?"Backblaze B2":"GoogleDrive"===e?"Google Drive™":e},n.getDestination=function(e,t){return n.destinationState.fetchingDestination=!0,n.destinationState.newMode=!1,n.setTemplatePath(t),d.getDestination(e).then((function(e){n.destinationState.destination=e,n.destinationState.destinationMode=!0,n.destinationState.fetchingDestination=!1,n.destinationState.editMode=!0,"SFTP"!==t&&"Rsync"!==t||n.getSSHKeyList(),"GoogleDrive"===t&&n.checkCredentials(e.googledrive.client_id,e.googledrive.client_secret)}),(function(e){n.destinationState.fetchingDestination=!1,u.add({type:"danger",closeable:!0,message:e,id:"fetch-destination-error"})}))},n.createNewDestination=function(e){n.destinationState.destination={},n.destinationState.editMode=!1,n.destinationState.newMode=!0,n.setTemplatePath(e),"Custom"===e?n.destinationState.destination.custom={type:e,timeout:30}:"FTP"===e?n.destinationState.destination.ftp={type:e,port:21,passive:!0,timeout:30}:"GoogleDrive"===e?n.destinationState.destination.googledrive={type:e,timeout:30}:"Local"===e||"Additional Local Directory"===e?n.destinationState.destination.local={type:"Local",mount:!1}:"SFTP"===e?(n.destinationState.destination.sftp={type:e,authtype:"key",port:22,timeout:30},n.getSSHKeyList()):"AmazonS3"===e?n.destinationState.destination.amazons3={type:"AmazonS3",timeout:30}:"S3Compatible"===e?n.destinationState.destination.s3compatible={type:"S3Compatible",timeout:30}:"Rsync"===e?(n.destinationState.destination.rsync={type:e,authtype:"key",timeout:30,port:22},n.getSSHKeyList()):"WebDAV"===e?n.destinationState.destination.webdav={type:e}:"Backblaze"===e&&(n.destinationState.destination.backblaze={type:e,timeout:180}),n.destinationState.destinationMode=!0},n.saveDestination=function(e,i){n.clearAlerts(),n.destinationState.savingDestination=!0;var s=Object.keys(e),o=e[s[0]].name;return n.destinationState.newMode?d.setNewDestination(e).then((function(i){return n.destinationId=i.id,n.destinationState.googleCredentialsGenerated=!1,n.destinationState.destinationMode=!1,n.destinationState.newMode=!1,u.add({type:"success",autoClose:5e3,message:a.maketext("The system successfully saved the “[_1]” destination.",t.escape(o)),id:"save-new-destination-success"}),"GoogleDrive"===e[s[0]].type&&(n.destinationState.checkCredentialsOnSave=!0,n.checkCredentials(e[s[0]].client_id,e[s[0]].client_secret,n.destinationState.checkCredentialsOnSave)),n.getDestinations()})).then((function(){i&&n.validateDestination(n.destinationId,t.escape(o),{all:!0})})).catch((function(e){u.add({type:"danger",closeable:!0,message:t.escape(e),id:"save-new-destination-error"})})).finally((function(){n.destinationState.savingDestination=!1})):n.destinationState.editMode?d.updateCurrentDestination(e).then((function(i){return n.destinationState.editMode=!1,u.add({type:"success",autoClose:5e3,message:a.maketext("The system successfully saved the “[_1]” destination.",t.escape(o)),id:"edit-destination-success"}),"GoogleDrive"===e[s[0]].type&&(n.destinationState.checkCredentialsOnSave=!0,n.checkCredentials(e[s[0]].client_id,e[s[0]].client_secret,n.destinationState.checkCredentialsOnSave)),n.destinationState.destinationMode=!1,n.getDestinations()})).then((function(){var a=e[s[0]].id;l.updateValidationInfo(a,t.escape(o)),i&&n.validateDestination(e[s[0]].id,t.escape(o),{all:!0})})).catch((function(e){u.add({type:"danger",closeable:!0,message:e,id:"edit-destination-error"})})).finally((function(){n.destinationState.savingDestination=!1})):void 0},n.saveAndValidateDestination=function(e){return n.saveDestination(e,!0)},n.cancelDestination=function(e){n.clearAlerts(),n.destinationState.destinationMode=!1,n.destinationState.editMode=!1,n.destinationState.newMode=!1,n.destinationState.googleCredentialsGenerated=!1,e||document.getElementById("additional_destinations_label").scrollIntoView()},n.deleteDestination=function(e){n.deleting=!0,n.showDeleteConfirmation=!1,n.displayAlertRows=[],n.displayAlertRows.push(e),d.deleteDestination(e).then((function(i){n.deleting=!1,l.remove(e),n.currentlyValidating=l.getLogEntries(),u.add({type:"success",autoClose:5e3,id:"delete-destination-success",message:a.maketext("The system successfully deleted the “[_1]” destination.",t.escape(n.destinationName))}),n.getDestinations()}),(function(e){n.deleting=!1,n.updating=!1,u.add({type:"danger",id:"delete-destination-failed",closeable:!0,message:e})}))},n.toggleStatus=function(e){var i,s;return n.toggled=!1,n.updating=!0,n.displayAlertRows=[],n.displayAlertRows.push(e.id),e.disabled?e.disabled&&(s=a.maketext("You enabled the destination “[_1]”.",t.escape(e.name)),i=!1):(s=a.maketext("You disabled the destination “[_1]”.",t.escape(e.name)),i=!0),d.toggleStatus(e.id,i).then((function(t){u.add({type:"success",autoClose:5e3,id:"toggle-destination-success",message:s}),e.disabled=!e.disabled}),(function(e){u.add({type:"danger",closeable:!0,id:"toggle-destination-failed",message:e})})).finally((function(){n.toggled=!0,n.updating=!1}))},n.validateAllDestinations=function(){n.currentlyValidating=[],n.destinationState.validatingAllDestinations=!0;var a=[];return e.forEach(n.destinationState.destinationList,(function(e){a.push(n.validateDestination(e.id,t.escape(e.name),{all:!0}))})),o.all(a).finally((function(){n.destinationState.validatingAllDestinations=!1,n.destinationState.validatingDestination=n.isValidationRunning()}))},n.validateAllSuccessFor=function(e){return l.validateAllSuccessFor(e)},n.validateAllFailureFor=function(e){return l.validateAllFailureFor(e)},n.showValidationMessageFor=function(e){l.showValidationMessageFor(e)},n.generateCredentials=function(e,t){return n.destinationState.generatingCredentials=!0,d.generateGoogleCredentials(e,t).then((function(t){n.destinationState.generatingCredentials=!1,u.add({type:"info",closeable:!0,replace:!1,message:a.maketext("A new window will appear that will allow you to generate Google® credentials."),id:"check-google-credentials-popup-"+e.substring(0,6)}),c((function(){r.open(t.uri,"generate_google_credentials")}),2e3)}),(function(t){n.destinationState.generatingCredentials=!1,u.add({type:"danger",closeable:!0,message:t,replace:!1,id:"generate-google-credentials-failed-"+e.substring(0,6)})}))},n.checkCredentials=function(e,i,s){return d.checkForGoogleCredentials(e).then((function(o){o?n.destinationState.googleCredentialsGenerated=!0:s&&!o?(n.destinationState.googleCredentialsGenerated=!1,u.add({type:"warning",closeable:!0,replace:!1,message:a.maketext("No [asis,Google Drive™] credentials have been generated for client id, “[_1]” ….",t.escape(e.substring(0,5)))+a.maketext("You must generate new credentials to access destinations that require this client [asis,ID]."),id:"no-google-credentials-generated-warning-"+e.substring(0,6)})):s||n.generateCredentials(e,i)}),(function(e){n.destinationState.googleCredentialsGenerated=!1,u.add({type:"danger",closeable:!0,message:e,group:"failed-during-check-google-credentials-error"})}))},n.toggleKeyGenerationForm=function(){n.destinationState.showKeyGenerationForm=!n.destinationState.showKeyGenerationForm},n.generateKey=function(e){var t;n.destinationState.generatingKey=!0,n.destinationState.destination.sftp?t=n.destinationState.destination.sftp.username:n.destinationState.destination.rsync&&(t=n.destinationState.destination.rsync.username),d.generateSSHKeyPair(e,t).then((function(){n.destinationState.generatingKey=!1,u.add({type:"success",autoClose:5e3,id:"ssh-key-generation-succeeded",message:a.maketext("The system generated the key successfully.")}),n.destinationState.destination.sftp?n.destinationState.destination.sftp.privatekey=n.setPrivateKey(e.name):n.destinationState.destination.rsync&&(n.destinationState.destination.rsync.privatekey=n.setPrivateKey(e.name)),n.toggleKeyGenerationForm(),n.getSSHKeyList()}),(function(e){n.destinationState.generatingKey=!1,u.add({type:"danger",closeable:!0,message:e,id:"ssh-key-generation-failed"})}))},n.getSSHKeyList=function(){n.destinationState.sshKeyListLoaded=!1,d.listSSHKeys().then((function(e){n.destinationState.sshKeyListLoaded=!0,n.destinationState.sshKeyList=e}),(function(e){n.destinationState.sshKeyListLoaded=!0,u.add({type:"danger",message:e,closeable:!0,id:"ssh-keys-fetch-failed"})}))},n.setPrivateKey=function(e){var t="/root/.ssh/"+e;n.destinationState.destination.sftp?n.destinationState.destination.sftp.privatekey=t:n.destinationState.destination.rsync&&(n.destinationState.destination.rsync.privatekey=t);var a=r.document.getElementById("private_key");return void 0!==a&&(a.select(),a.focus()),t},n.toggleKeyType=function(e){"DSA"===e?(this.newSSHKey.bits="1024",this.destinationState.keyBitsSet=!0,this.newSSHKey.name&&""!==this.newSSHKey.name||(this.newSSHKey.name="id_dsa")):"RSA"===e&&(this.newSSHKey.bits="4096",this.destinationState.keyBitsSet=!1,this.newSSHKey.name&&""!==this.newSSHKey.name||(this.newSSHKey.name="id_rsa"))},n.clearAlerts=function(){u.clear()},n.toggleSSLWebDAV=function(){n.destinationState.destination.webdav.ssl=!n.destinationState.destination.webdav.ssl},n.checkForLoopBack=function(e){e===n.remoteHostLoopbackValue?n.destinationState.isLoopback=!0:n.destinationState.isLoopback=!1},n.checkForDisallowedChars=function(e,t){t.lastIndex=1;var a=t.test(e);n.destinationState.isDisallowedChar=a},n.noDecimalPoints=function(e){var t=e.originalEvent;(t.hasOwnProperty("key")&&"."===t.key||190===t.keyCode)&&e.preventDefault()},n.onlyNumbers=function(e){e.originalEvent.clipboardData.getData("text").match(/[0-9]+/)||e.preventDefault()},n.init=function(){n.absolutePathRegEx=/^\/./,n.relativePathRegEx=/^\w./,n.remoteHostValidation=/^[a-z0-9.-]{1,}$/i,n.remoteHostLoopbackValue=/^(127(\.\d+){1,3}|[0:]+1|localhost)$/i,n.disallowedPathChars=/[\\?%*:|"<>]/g,n.validating=!1,n.toggled=!0,n.saving=!1,n.deleting=!1,n.updating=!1,n.showDeleteConfirmation=!1,n.destinationName="",n.destinationId="",n.activeTab=1,n.currentlyValidating=l.getLogEntries(),n.destinationState={destinationSelected:"Custom",destinationMode:!1,savingDestination:!1,validatingDestination:n.isValidationRunning(),fetchingDestination:!1,destinationListLoaded:!1,validatingAllDestinations:!1,destinationList:[],newMode:!1,editMode:!1,generatingCredentials:!1,googleCredentialsGenerated:!1,showKeyGenerationForm:!1,generatingKey:!1,keyBitsSet:!1,sshKeyListLoaded:!1,isLoopback:!1,isDisallowedChar:!1,checkCredentialsOnSave:!1,showValidationIconHint:!1},l.hasLogEntries()&&(n.destinationState.showValidationIconHint=!0),n.meta={},n.displayAlertRows=[],n.getDestinations()},n.init()}])})),define("app/views/validationResults",["angular","cjt/util/locale","cjt/util/table","cjt/services/alertService","cjt/directives/alertList","cjt/directives/toggleSortDirective","cjt/directives/actionButtonDirective","app/services/validationLog"],(function(e,t,a){"use strict";return e.module("whm.backupConfiguration").controller("validationResults",["$scope","alertService","validationLog",function(e,t,n){var i=new a;e.sortValidationEntries=function(){e.currentlyValidating=i.update(),e.meta=i.getMetadata()},e.init=function(){e.currentlyValidating=n.getLogEntries(),i.load(e.currentlyValidating),i.setSort("name,transport","asc"),i.meta.limit=e.currentlyValidating.length,i.meta.pageSize=e.currentlyValidating.length,e.$watch("currentlyValidating",(function(){e.sortValidationEntries(),n.cacheLogEntries()}),!0)},e.init()}])})),define("app/index",["angular","cjt/core","cjt/modules","ngRoute","app/services/backupConfigurationServices","app/services/validationLog"],(function(e,t){"use strict";return function(){return e.module("whm.backupConfiguration",["cjt2.config.whm.configProvider","ngRoute","cjt2.whm","whm.backupConfiguration.backupConfigurationServices.service","whm.backupConfiguration.validationLog.service"]),require(["cjt/bootstrap","app/directives/formValidator","app/views/config","app/views/destinations","app/views/validationResults"],(function(t){var a=e.module("whm.backupConfiguration");a.value("PAGE",PAGE),a.controller("BaseController",["$rootScope","$scope","$location",function(e,t,a){t.loading=!1,e.$on("$routeChangeStart",(function(){t.loading=!0,e.currentRoute=a.path()}))}]),a.config(["$routeProvider",function(e){e.when("/settings",{controller:"config",templateUrl:"views/config.ptt"}),e.when("/destinations",{controller:"destinations",templateUrl:"views/destinations.ptt"}),e.when("/validation",{controller:"validationResults",templateUrl:"views/validationResults.ptt"}),e.otherwise({redirectTo:"/settings"})}]);var n=e.element("#pageContainer");null!==n[0]&&t(n[0],"whm.backupConfiguration")}))}}));