Viewing File: /usr/local/cpanel/whostmgr/docroot/templates/hulkd/index.cmb.min.js

define("app/services/HulkdDataSource",["angular","jquery","lodash","cjt/util/locale","cjt/util/query","cjt/util/parse","cjt/io/api","cjt/io/whm-v1-request","cjt/io/whm-v1"],(function(e,t,i,n,r,s,o,l,a){"use strict";var c=e.module("App");return c.factory("HulkdDataSource",["$q","PAGE","COUNTRY_CONSTANTS",function(t,n,a){var u={};return u.whitelist=[],u.blacklist=[],u.whitelist_comments={},u.blacklist_comments={},u.whitelist_is_cached=!1,u.blacklist_is_cached=!1,u.config_settings={},u.enabled=n.hulkd_status.is_enabled,u.hulkd_status=function(){var e=t.defer(),i=new l.Class;return i.initialize("","cphulk_status"),o.promise(i.getRunArguments()).done((function(t){t=t.parsedResponse,u.enabled=s.parsePerlBoolean(t.data.is_enabled),e.resolve(u.enabled)})),e.promise},u.get_countries_with_known_ip_ranges=function(){var e=t.defer(),i=new l.Class;return i.initialize("","get_countries_with_known_ip_ranges"),o.promise(i.getRunArguments()).done((function(t){t=t.parsedResponse,e.resolve(t.data)})),e.promise},u.clear_caches=function(){u.whitelist=[],u.blacklist=[],u.whitelist_comments={},u.blacklist_comments={},u.whitelist_is_cached=!1,u.blacklist_is_cached=!1},u.enable_hulkd=function(){var e=t.defer(),i=new l.Class;return i.initialize("","enable_cphulk"),o.promise(i.getRunArguments()).done((function(t){(t=t.parsedResponse).status?(e.resolve(t),u.enabled=!0):e.reject(t.error)})),e.promise},u.disable_hulkd=function(){var e=t.defer(),i=new l.Class;return i.initialize("","disable_cphulk"),o.promise(i.getRunArguments()).done((function(t){(t=t.parsedResponse).status?(e.resolve(t.status),u.enabled=!1,u.clear_caches()):e.reject(t.error)})),e.promise},u.convert_config_settings=function(e){var t={};return t.block_brute_force_with_firewall=s.parsePerlBoolean(e.cphulk_config.block_brute_force_with_firewall),t.block_excessive_brute_force_with_firewall=s.parsePerlBoolean(e.cphulk_config.block_excessive_brute_force_with_firewall),t.brute_force_period_mins=e.cphulk_config.brute_force_period_mins,t.command_to_run_on_brute_force=e.cphulk_config.command_to_run_on_brute_force,t.command_to_run_on_excessive_brute_force=e.cphulk_config.command_to_run_on_excessive_brute_force,t.is_enabled=s.parsePerlBoolean(e.cphulk_config.is_enabled),t.ip_brute_force_period_mins=e.cphulk_config.ip_brute_force_period_mins,t.lookback_period_min=e.cphulk_config.lookback_period_min,t.max_failures=e.cphulk_config.max_failures,t.max_failures_byip=e.cphulk_config.max_failures_byip,t.mark_as_brute=e.cphulk_config.mark_as_brute,t.notify_on_root_login=s.parsePerlBoolean(e.cphulk_config.notify_on_root_login),t.notify_on_root_login_for_known_netblock=s.parsePerlBoolean(e.cphulk_config.notify_on_root_login_for_known_netblock),t.notify_on_brute=s.parsePerlBoolean(e.cphulk_config.notify_on_brute),t.can_temp_ban_firewall=s.parsePerlBoolean(e.cphulk_config.can_temp_ban_firewall),t.iptable_error=e.cphulk_config.iptable_error,t.username_based_protection=s.parsePerlBoolean(e.cphulk_config.username_based_protection),t.ip_based_protection=s.parsePerlBoolean(e.cphulk_config.ip_based_protection),t.username_based_protection_local_origin=s.parsePerlBoolean(e.cphulk_config.username_based_protection_local_origin),t.username_based_protection_for_root=s.parsePerlBoolean(e.cphulk_config.username_based_protection_for_root),t.country_whitelist=e.cphulk_config.country_whitelist?e.cphulk_config.country_whitelist.split(","):[],t.country_blacklist=e.cphulk_config.country_blacklist?e.cphulk_config.country_blacklist.split(","):[],u.config_settings=t,t},u.save_config_settings=function(e){var n=t.defer(),r=new l.Class;r.initialize("","save_cphulk_config");for(var a=0,c=i.keys(e),u=c.length;a<u;a++)if("is_enabled"!==c[a]){var d=e[c[a]];i.isArray(d)?d=d.join(","):i.isBoolean(d)&&(d=d?1:0),r.addArgument(c[a],d)}return o.promise(r.getRunArguments()).done((function(e){(e=e.parsedResponse).status?(e.data.restart_ssh=s.parsePerlBoolean(e.data.restart_ssh),n.resolve(e.data)):n.reject(e.error)})),n.promise},u.load_config_settings=function(){var e=t.defer(),i=new l.Class;return i.initialize("","load_cphulk_config"),o.promise(i.getRunArguments()).done((function(t){if((t=t.parsedResponse).status){var i=t.data,n=u.convert_config_settings(i);e.resolve(n)}else e.reject(t.error)})),e.promise},u.set_cphulk_config_keys=function(i){var n,s,a,c=[];return e.forEach(i,(function(e,t){c.push({func:"set_cphulk_config_key",data:{key:t,value:e}})})),(n=c,s=t.defer(),a=new l.Class,a.initialize("","batch"),n.forEach((function(e,t){a.addArgument("command-"+t,e.func+"?"+r.make_query_string(e.data))})),o.promise(a.getRunArguments()).done((function(e){if((e=e.parsedResponse).status){var t=e.data;s.resolve(t)}else s.reject(e.error)})),s.promise).then((function(e){var t=e.pop();t=t.parsedResponse;var i=u.convert_config_settings(t.data);return u._parse_xlisted_countries(i)}))},u.load_xlisted_countries=function(){return u.load_config_settings().then((function(e){return u._parse_xlisted_countries(e)}))},u._parse_xlisted_countries=function(e){var t={};return e.country_blacklist.forEach((function(e){t[e]=a.BLACKLISTED})),e.country_whitelist.forEach((function(e){t[e]=a.WHITELISTED})),t},u.add_to_list=function(e,n){var r=t.defer(),s=new l.Class;return s.initialize("","batch_create_cphulk_records",null,null,{json:!0}),s.addArgument("list_name",e),s.addArgument("records",n),o.promise(s.getRunArguments()).done((function(t){if((t=t.parsedResponse).status){for(var s={added:[],rejected:t.data.ips_failed,updated:[]},o=t.data.original_ips_added||[],l=u[e+"list"],a=u[e+"list_comments"],c=0,d=o.length;c<d;c++){var _=o[c],f=t.data.ips_added[c];-1===i.indexOf(u.whitelist,f)?(l.push(f),s.added.push(f)):s.updated.push(f);var m=i.find(n,(function(e){return e.ip===_}));m&&m.comment&&(a[f]=m.comment),"white"===e&&(s.requester_ip=t.data.requester_ip,s.requester_ip_is_whitelisted=t.data.requester_ip_is_whitelisted)}r.resolve(s)}else{var p={main_message:t.error,secondary_messages:[]};Object.keys(t.data.ips_failed).forEach((function(e){var i=t.data.ips_failed[e];p.secondary_messages.push(i)})),r.reject(p)}})),r.promise},u.add_to_whitelist=function(e){return u.add_to_list("white",e)},u.add_to_blacklist=function(e){return u.add_to_list("black",e)},u.remove_from_list=function(e,n){var r=t.defer(),s=new l.Class;s.initialize("","delete_cphulk_record"),s.addArgument("list_name",n);for(var a=0;a<e.length;a++)s.addArgument("ip-"+a,e[a]);return o.promise(s.getRunArguments()).done((function(e){if((e=e.parsedResponse).status){var t=0;if("white"===n)for(u.whitelist=i.difference(u.whitelist,e.data.ips_removed),t=0;t<e.data.ips_removed.length;t++)delete u.whitelist_comments[e.data.ips_removed[t]];else for(u.blacklist=i.difference(u.blacklist,e.data.ips_removed),t=0;t<e.data.ips_removed.length;t++)delete u.blacklist_comments[e.data.ips_removed[t]];r.resolve({removed:e.data.ips_removed,not_removed:e.data.ips_failed,requester_ip:e.data.requester_ip,requester_ip_is_whitelisted:e.data.requester_ip_is_whitelisted})}else r.reject(e.error)})),r.promise},u.remove_from_whitelist=function(e){return u.remove_from_list(e,"white")},u.remove_from_blacklist=function(e){return u.remove_from_list(e,"black")},u.remove_all_from_whitelist=function(){return u.remove_from_whitelist(u.whitelist)},u.remove_all_from_blacklist=function(){return u.remove_from_blacklist(u.blacklist)},u.load_list=function(e){var i=t.defer(),n=new l.Class;return n.initialize("","read_cphulk_records"),n.addArgument("list_name",e),o.promise(n.getRunArguments()).done((function(t){if((t=t.parsedResponse).status){var n={};if("white"===e){t.data.requester_ip_is_whitelisted||(n.whitelist_warning=t.data.warning_ip),t.data.restart_ssh&&(n.restart_ssh=!0),t.data.warning_ssh&&(n.warning_ssh=t.data.warning_ssh),u.whitelist=Object.keys(t.data.ips_in_list).slice();for(var r=0;r<u.whitelist.length;r++)t.data.ips_in_list[u.whitelist[r]]&&(u.whitelist_comments[u.whitelist[r]]=t.data.ips_in_list[u.whitelist[r]]);u.whitelist_is_cached=!0,n.list=u.whitelist,n.comments=u.whitelist_comments,n.requester_ip=t.data.requester_ip,n.requester_ip_is_whitelisted=t.data.requester_ip_is_whitelisted,i.resolve(n)}else if("black"===e){u.blacklist=Object.keys(t.data.ips_in_list).slice();for(var s=0;s<u.blacklist.length;s++)t.data.ips_in_list[u.blacklist[s]]&&(u.blacklist_comments[u.blacklist[s]]=t.data.ips_in_list[u.blacklist[s]]);u.blacklist_is_cached=!0,n.list=u.blacklist,n.comments=u.blacklist_comments,n.requester_ip=t.data.requester_ip,i.resolve(n)}}else i.reject(t.error)})),i.promise},c.firstLoad&&c.firstLoad.configs&&n.config_values&&(c.firstLoad.configs=!1,u.config_settings=u.convert_config_settings(n.config_values)),u}])})),define("app/directives/disableValidation",["angular"],(function(e){"use strict";var t;try{t=e.module("App")}catch(i){t=e.module("App",[])}t.directive("disableValidation",(function(){return{require:"ngModel",restrict:"A",link:function(t,i,n,r){var s=e.copy(r.$validators);Object.keys(s).forEach((function(e){r.$validators[e]=function(i){return t.$eval(n.disableValidation)||s[e](i,i)}})),t.$watch(n.disableValidation,(function(){var e=r.$viewValue;t.$applyAsync((function(){r.$setViewValue(""),r.$setViewValue(e)}))}))}}}))})),define("app/views/configController",["angular","lodash","cjt/util/locale","cjt/validator/datatype-validators","cjt/validator/compare-validators","cjt/validator/length-validators","uiBootstrap","cjt/directives/validationContainerDirective","cjt/directives/validationItemDirective","cjt/decorators/growlDecorator","app/services/HulkdDataSource","app/directives/disableValidation"],(function(e,t,i){"use strict";return e.module("App").controller("configController",["$scope","HulkdDataSource","growl","PAGE",function(e,n,r,s){function o(e){32===e.keyCode&&e.preventDefault()}e.username_protection_level="local",e.username_protection_enabled=!0,e.growlProtectionChangeRequiresSave=function(){r.warning(i.maketext("You changed the protection level of [asis,cPHulk]. Click Save to implement this change."))},e.$watch((function(){return e.username_protection_enabled}),(function(t,i){t!==i&&e.growlProtectionChangeRequiresSave()})),e.$watch((function(){return e.config_settings.ip_based_protection}),(function(t,i){t!==i&&e.growlProtectionChangeRequiresSave()})),e.align_username_protection_settings=function(){e.config_settings.username_based_protection?(e.username_protection_level="both",e.username_protection_enabled=!0):e.config_settings.username_based_protection_local_origin?(e.username_protection_level="local",e.username_protection_enabled=!0):e.username_protection_enabled=!1},e.prepare_username_protection_settings_for_save=function(){e.username_protection_enabled?"local"===e.username_protection_level?(e.config_settings.username_based_protection_local_origin=!0,e.config_settings.username_based_protection=!1):e.config_settings.username_based_protection=!0:(e.config_settings.username_based_protection_local_origin=!1,e.config_settings.username_based_protection=!1)},e.handle_protection_keydown=function(e){o(e)},e.handle_protection_keyup=function(t,i){32!==t.keyCode&&13!==t.keyCode||(t.preventDefault(),void 0!==e.config_settings[i]&&("username"===i?e.username_protection_enabled=!e.username_protection_enabled:e.config_settings[i]=!e.config_settings[i]))},e.collapse_keydown=function(e){o(e)},e.collapse_keyup=function(t,i){32!==t.keyCode&&13!==t.keyCode||(t.preventDefault(),void 0!==e[i]&&(e[i]=!e[i]))},e.disableSave=function(t){return t.$invalid||e.loadingPageData},e.save=function(t){if(t.$valid)return e.loadingPageData=!0,e.prepare_username_protection_settings_for_save(),n.save_config_settings(e.config_settings).then((function(e){r.success(i.maketext("The system successfully saved your [asis,cPHulk] configuration settings.")),e.restart_ssh?r.warning(i.maketext("The system disabled the [asis,UseDNS] setting for [asis,SSHD] in order to add IP addresses to the whitelist. You must restart SSH through the [output,url,_1,Restart SSH Server,_2] page to implement the change.",s.security_token+"/scripts/ressshd",{target:"_blank"})):e.warning&&r.warning(e.warning)}),(function(e){r.error(e)})).finally((function(){e.loadingPageData=!1}))},e.fetch=function(){t.isEmpty(n.config_settings)?(e.loadingPageData=!0,n.load_config_settings().then((function(t){e.config_settings=t,e.align_username_protection_settings()}),(function(e){r.error(e)})).finally((function(){e.loadingPageData=!1}))):(e.config_settings=n.config_settings,e.align_username_protection_settings())},e.bruteInfoCollapse=!0,e.excessiveBruteInfoCollapse=!0,e.loadingPageData=!1,e.fetch()}])})),define("app/directives/countryCodesTableDirective",["angular","lodash","cjt/core","uiBootstrap","cjt/modules","cjt/directives/toggleSortDirective","cjt/directives/searchDirective","cjt/directives/pageSizeDirective","cjt/filters/startFromFilter","cjt/decorators/paginationDecorator","cjt/directives/quickFiltersDirective"],(function(e,t,i){"use strict";e.module("App").directive("countryCodesTable",["COUNTRY_CONSTANTS","$timeout",function(e,t){var n="directives/countryCodesTable.ptt",r="templates/hulkd/"+n;return{templateUrl:i.config.debug?i.buildFullPath(r):n,restrict:"EA",scope:{items:"=",onChange:"&onChange"},replace:!0,controller:["$scope","$filter","$uibModal",function(i,n,r){var s;i.modal_instance=null,i.country_blacklist_in_progress=!1,i.confirm_country_blacklisting=function(){return i.country_blacklist_in_progress=!0,i.modal_instance=r.open({templateUrl:"confirm_country_blacklisting.html",scope:i}),!0},i.cancel_country_blacklisting=function(){i.clear_modal_instance(),i.deselectAll(),i.country_blacklisting_in_progress=!1},i.continue_country_blacklisting=function(e){i.clear_modal_instance(),i.country_blacklist_in_progress=!1,i.blacklistCountries(e)},i.clear_modal_instance=function(){i.modal_instance&&(i.modal_instance.close(),i.modal_instance=null)},i.filteredList=i.items,i.COUNTRY_CONSTANTS=e;var o={};i.items.forEach((function(e){o[e.code]=e,e.searchableCode="("+e.code+")"})),i.loading=!1,i.meta={filterValue:"",sortBy:"name",quickFilterValue:"all"},i.selectedItems=[],i.toggleSelect=function(e,t){var i=t.indexOf(e);i>-1?t.splice(i,1):t.push(e)},i.toggleSelectAll=function(){i.allSelected()?i.deselectAll():i.selectAll()},i.selectAll=function(){i.selectedItems=i.filteredList.map((function(e){return e.code}))},i.deselectAll=function(){i.selectedItems=[]},i.allSelected=function(){return i.selectedItems.length&&i.selectedItems.length===i.filteredList.length},i.exists=function(e,t){return t.indexOf(e)>-1},i.sortList=function(e){i.fetch()},i.searchList=function(e){i.fetch()},i.getCountriesFromCodes=function(e){return e.map((function(e){return o[e]}))},i.whitelistCountries=function(t){i.getCountriesFromCodes(t).forEach((function(t){t.status=e.WHITELISTED})),i.countriesUpdated()},i.blacklistCountries=function(t){i.getCountriesFromCodes(t).forEach((function(t){t.status=e.BLACKLISTED})),i.countriesUpdated()},i.unlistCountries=function(t){i.getCountriesFromCodes(t).forEach((function(t){t.status=e.UNLISTED})),i.countriesUpdated()},i.countriesUpdated=function(){i.onChange&&(s&&(t.cancel(s),s=!1),s=t((function(){i.countriesUpdating=!0;var t=[],n=[];i.items.forEach((function(i){i.status===e.WHITELISTED?t.push(i.code):i.status===e.BLACKLISTED&&n.push(i.code)})),i.onChange({whitelist:t,blacklist:n}).finally((function(){i.countriesUpdating=!1}))}),250))};var l={filter:n("filter"),orderBy:n("orderBy")};i.quickFilterUpdated=function(){i.deselectAll(),i.fetch()},i.fetch=function(){var e=[];return e=""!==i.meta.filterValue?l.filter(i.items,i.meta.filterValue,!1):i.items,"all"!==i.meta.quickFilterValue&&(e=l.filter(e,{status:i.meta.quickFilterValue},!1)),""!==i.meta.sortDirection&&""!==i.meta.sortBy&&(e=l.orderBy(e,i.meta.sortBy,"asc"===i.meta.sortDirection)),i.meta.totalItems=e.length,i.filteredList=e,e},i.fetch()}]}}])})),define("app/views/countriesController",["angular","lodash","cjt/util/locale","app/directives/countryCodesTableDirective","cjt/decorators/growlDecorator","app/services/HulkdDataSource"],(function(e,t,i){return e.module("App").controller("countriesController",["$scope","growl","HulkdDataSource","COUNTRY_CONSTANTS","COUNTRY_CODES","XLISTED_COUNTRIES",function(e,t,n,r,s,o){function l(e,t){return e.map((function(e){return e.status=t[e.code]||r.UNLISTED,e}))}var a,c;e.countries=l(s,o),e.countriesUpdated=function(r,u){return c&&c.destroy(),a=t.info(i.maketext("Updating the country whitelist and blacklist …")),n.set_cphulk_config_keys({country_whitelist:r.sort().join(","),country_blacklist:u.sort().join(",")}).then((function(n){o=n,e.countries=l(s,n),a.destroy(),c=t.success(i.maketext("Country whitelist and blacklist updated."))}))}}])})),define("app/utils/download",[],(function(){"use strict";return{getDownloadName:function(e){return e+".txt"},getTextDownloadUrl:function(e){var t=new Blob([e],{type:"plain/text"});return window.URL.createObjectURL(t)},cleanupDownloadUrl:function(e){e&&window.URL.revokeObjectURL(e)},formatList:function(e){return e&&e.length?e.map((function(e){return e.ip+(e.comment?" # "+e.comment:"")})).join("\n")+"\n":""}}})),define("app/views/hulkdWhitelistController",["angular","jquery","lodash","cjt/util/locale","app/utils/download","uiBootstrap","cjt/directives/toggleSortDirective","cjt/directives/pageSizeDirective","cjt/decorators/paginationDecorator","cjt/decorators/growlDecorator","cjt/filters/startFromFilter","app/services/HulkdDataSource"],(function(e,t,i,n,r){"use strict";var s=e.module("App");return s.config(["$compileProvider",function(e){e.aHrefSanitizationWhitelist(/^blob:https:/)}]),s.controller("hulkdWhitelistController",["$rootScope","$scope","$filter","$routeParams","$uibModal","HulkdDataSource","growl","PAGE","growlMessages","$timeout",function(s,o,l,a,c,u,d,_,f,m){o.whitelist_reverse=!1,o.whitelist=[],o.whitelist_comments={},o.adding_batch_to_whitelist=!1,o.new_whitelist_records="",o.ip_being_edited=!1,o.current_ip=null,o.current_comment="",o.updating_comment=!1,o.modal_instance=null,o.loading=!1,o.downloadAllLink="",o.downloadSelectionLink="",o.meta={sortDirection:"asc",sortBy:"white_ip",sortType:"",sortReverse:!1,filter:"",maxPages:0,totalItems:o.whitelist.length||0,currentPage:1,pageNumberStart:0,pageNumberEnd:0,pageSize:20,pageSizes:[20,50,100]},o.LOCALE=n;var p={filter:l("filter"),orderBy:l("orderBy"),startFrom:l("startFrom"),limitTo:l("limitTo")};if(o.delete_in_progress=!1,o.ips_to_delete=[],a.ip&&a.ip.length>0||null!==_.ipToAdd){var g;a.ip&&a.ip.length>0?g=a.ip:null!==_.ipToAdd&&(g=_.ipToAdd),_.ipToAdd=null,void 0!==g&&o._add_to_whitelist([{ip:g,comment:""}])}o.growl_whitelist_warning=function(e){var t=n.maketext("Your current IP address “[_1]” is not on the whitelist.",i.escape(e));s.whitelist_warning_message=d.error(t,{variables:{buttonLabel:n.maketext("Add to Whitelist"),showAction:!0,action:function(){s.one_click_add_to_whitelist(e).then((function(){o.downloadAllLink=o.generateDownloadAllLink()}))}},onclose:function(){s.whitelist_warning_message=null}})},o.edit_whitelist_ip=function(e){o.current_ip=e,o.current_comment=o.whitelist_comments.hasOwnProperty(e)?o.whitelist_comments[e]:"",o.ip_being_edited=!0;var i=t("#whitelist_current_comment"),n=setInterval((function(){i.is(":visible")&&(i.focus(),i.select(),clearInterval(n))}),250)},o.cancel_whitelist_editing=function(){o.current_ip=null,o.current_comment="",o.ip_being_edited=!1,o.focus_on_whitelist()},o.delete_tooltip=function(e){return n.maketext("Click to delete “[_1]” from the whitelist.",e)},o.edit_tooltip=function(e){return n.maketext("Click to edit the comment for “[_1]”.",e)},o.update_whitelist_comment=function(){o.updating_comment||(o.updating_comment=!0,u.add_to_whitelist([{ip:o.current_ip,comment:o.current_comment}]).then((function(e){o.whitelist_comments=u.whitelist_comments,e.updated.forEach((function(e){d.success(n.maketext("You have successfully updated the comment for “[_1]”.",i.escape(e)))}));var t=[];if(Object.keys(e.rejected).forEach((function(n){t.push(i.escape(n)+": "+i.escape(e.rejected[n]))})),t.length>0){var r=n.maketext("Some records failed to update.")+"<br>";r+=t.join("<br>"),d.error(r)}}),(function(e){d.error(e)})).finally((function(){o.updating_comment=!1,o.cancel_whitelist_editing(),o.focus_on_whitelist()})))};var h=/^(([\da-fA-F]{1,4}:){4})(([\da-fA-F]{1,4}:){3})([\da-fA-F]{1,4})$/,k=/^((\d{1,3}.){3}\d{1,3})-((\d{1,3}.){3}\d{1,3})$/,w=/-/,b=/:/;function v(e,t){return e[1].toLowerCase()<t[1].toLowerCase()?-1:e[1].toLowerCase()>t[1].toLowerCase()?1:o.ip_padder(e[0])<o.ip_padder(t[0])?-1:o.ip_padder(e[0])>o.ip_padder(t[0])?1:0}function y(e,t){var i=[];return e.forEach((function(e){var n=t[e];i.push({ip:e,comment:n})})),i}o.splitLongIp=function(e){if(b.test(e))if(w.test(e)){var t=e.split(w),i="",n=h.exec(t[0]);if(n&&(i+=n[1]+"<br>"+n[3]+n[5]),i+="-<br>",(n=h.exec(t[1]))&&(i+=n[1]+"<br>"+n[3]+n[5]),i.length>5)return i}else{var r=h.exec(e);if(r)return r[1]+"<br>"+r[3]+r[5]}else{var s=k.exec(e);if(s)return s[1]+"-<br>"+s[3]}return e},o.$watch((function(){return u.enabled}),(function(){o.load_list()})),o.$watch((function(){return!0===s.ip_added_with_one_click}),(function(){o.applyFilters(),s.ip_added_with_one_click=!1})),o.$watchGroup(["whitelist.length","meta.filteredList.length"],(function(){0!==o.whitelist.length&&0!==o.meta.filteredList.length||t("#whitelist_select_all_checkbox").prop("checked",!1)})),o.selectPage=function(i){t("#whitelist_select_all_checkbox").prop("checked",!1),i&&e.isNumber(i)&&(o.meta.currentPage=i),o.load_list()},o.selectPageSize=function(){return o.load_list({reset_focus:!1})},o.filterList=function(){o.meta.currentPage=1,o.load_list({reset_focus:!1})},o.toggleFilter=function(){o.meta.filter="",o.load_list({reset_focus:!1})},o.sortList=function(e){o.meta.sortReverse="asc"!==e.sortDirection,o.applyFilters()},o.orderByComments=function(e,t){for(var n=i.toPairs(e),r=[],s=0;s<t.length;s++)if(!i.has(e,t[s])){var l=[t[s],""];r.push(l)}var a=i.sortBy(r,(function(e){return o.ip_padder(e[0])}));n.sort(v);var c=i.map(n,(function(e){return e[0]})),u=i.map(a,(function(e){return e[0]})),d=c.concat(u);return"desc"===o.meta.sortDirection?d.reverse():d},o.applyFilters=function(){var e,t,i=[];i=o.whitelist,""!==o.meta.sortDirection&&""!==o.meta.sortBy&&(i="white_ip"===o.meta.sortBy?p.orderBy(i,o.ip_padder,o.meta.sortReverse):o.orderByComments(o.whitelist_comments,o.whitelist)),o.meta.totalItems=o.whitelist.length;var n=o.meta.filter.toLowerCase();return n&&(i=p.filter(i,(function(e){return-1!==e.indexOf(n)||o.whitelist_comments[e]&&-1!==o.whitelist_comments[e].toLowerCase().indexOf(n)}))),o.meta.filteredItems=i.length,e=(o.meta.currentPage-1)*o.meta.pageSize,t=o.meta.pageSize,i=p.limitTo(p.startFrom(i,e),t),o.meta.pageNumberStart=e+1,o.meta.pageNumberEnd=o.meta.currentPage*o.meta.pageSize,0===o.meta.totalItems&&(o.meta.pageNumberStart=0),o.meta.pageNumberEnd>o.meta.totalItems&&(o.meta.pageNumberEnd=o.meta.totalItems),o.meta.filteredList=i,i},o.load_list=function(e){if(u.enabled&&!o.loading){o.loading=!0;var t=void 0===e||!e.hasOwnProperty("reset_focus")||e.reset_focus;if(!u.whitelist_is_cached)return o.meta.filteredList=[],u.load_list("white").then((function(e){o.whitelist=u.whitelist,o.whitelist_comments=u.whitelist_comments,o.downloadAllLink=o.generateDownloadAllLink(),o.applyFilters(),e.hasOwnProperty("requester_ip_is_whitelisted")&&e.requester_ip_is_whitelisted<=0&&e.hasOwnProperty("requester_ip")&&null===s.whitelist_warning_message&&o.growl_whitelist_warning(e.requester_ip),e.restart_ssh?d.warning(n.maketext("The system disabled the [asis,UseDNS] setting for [asis,SSHD] in order to add IP addresses to the whitelist. You must restart SSH through the [output,url,_1,Restart SSH Server,_2] page to implement the change.",_.security_token+"/scripts/ressshd",{target:"_blank"})):e.warning_ssh&&d.warning(e.warning_ssh)}),(function(e){d.error(e)})).finally((function(){t&&o.focus_on_whitelist(),o.loading=!1}));o.whitelist=u.whitelist,o.whitelist_comments=u.whitelist_comments,o.downloadAllLink=o.generateDownloadAllLink(),o.applyFilters(),t&&o.focus_on_whitelist(),o.loading=!1}return null},o.force_load_whitelist=function(){return u.whitelist_is_cached=!1,o.whitelist=[],o.whitelist_comments={},o.meta.filteredList=[],o.load_list()},o.delete_confirmation_message=function(){return 1===o.ips_to_delete.length?n.maketext("Do you want to permanently delete “[_1]” from the whitelist?",o.ips_to_delete[0]):n.maketext("Do you want to permanently delete [quant,_1,record,records] from the whitelist?",o.ips_to_delete.length)},o.itemsAreChecked=function(){return t(".whitelist_select_item").filter(":checked").length>0},o.check_whitelist_selection=function(){0===t(".whitelist_select_item").filter(":not(:checked)").length?t("#whitelist_select_all_checkbox").prop("checked",!0):t("#whitelist_select_all_checkbox").prop("checked",!1),o.downloadSelectionLink=o.generateDownloadSelectionLink()},o.getSelection=function(){var e=[],i=t(".whitelist_select_item:checked");return 0===i.length?[]:(i.each((function(){e.push(t(this).data("ip"))})),e)},o.confirm_whitelist_deletion=function(e){if(0===o.whitelist.length)return!1;if(o.delete_in_progress=!0,void 0!==e)o.ips_to_delete=[e],o.is_single_deletion=!0;else{var t=o.getSelection();if(0===t.length)return!1;o.ips_to_delete=t,o.is_single_deletion=!1}return o.modal_instance=c.open({templateUrl:"confirm_whitelist_deletion.html",scope:o}),!0},o.clear_modal_instance=function(){o.modal_instance&&(o.modal_instance.close(),o.modal_instance=null)},o.cancel_deletion=function(){o.delete_in_progress=!1,o.ips_to_delete=[],o.clear_modal_instance(),o.focus_on_whitelist()},o.delete_whitelist_ips=function(e){o.clear_modal_instance(),u.remove_from_whitelist(o.ips_to_delete).then((function(e){o.whitelist=u.whitelist,o.whitelist_comments=u.whitelist_comments,o.applyFilters(),o.focus_on_whitelist(),1===e.removed.length?d.success(n.maketext("You have successfully deleted “[_1]” from the whitelist.",i.escape(e.removed[0]))):d.success(n.maketext("You have successfully deleted [quant,_1,record,records] from the whitelist.",e.removed.length)),e.hasOwnProperty("requester_ip_is_whitelisted")&&e.requester_ip_is_whitelisted<=0&&e.hasOwnProperty("requester_ip")&&o.growl_whitelist_warning(e.requester_ip),e.not_removed.keys&&e.not_removed.keys.length>0&&d.warning(n.maketext("The system was unable to delete [quant,_1,record,records] from the whitelist.",e.not_removed.keys.length))}),(function(e){d.error(e)})).finally((function(){o.delete_in_progress=!1,o.ips_to_delete=[],e||o.deselect_all_whitelist(),m((function(){o.downloadAllLink=o.generateDownloadAllLink(),o.downloadSelectionLink=o.generateDownloadSelectionLink()}))}))},o.confirm_delete_all=function(){return 0!==o.whitelist.length&&(o.delete_in_progress=!0,o.modal_instance=c.open({templateUrl:"confirm_whitelist_delete_all.html",scope:o}),!0)},o.cancel_delete_all=function(){o.delete_in_progress=!1,o.clear_modal_instance(),o.focus_on_whitelist()},o.delete_all=function(){o.clear_modal_instance(),u.remove_all_from_whitelist().then((function(e){o.whitelist=u.whitelist,o.whitelist_comments=u.whitelist_comments,o.applyFilters(),o.focus_on_whitelist(),e.not_removed.keys&&e.not_removed.keys.length>0?(d.success(n.maketext("You have successfully deleted [quant,_1,record,records] from the whitelist.",e.removed.keys.length)),d.warning(n.maketext("The system was unable to delete [quant,_1,record,records] from the whitelist.",e.not_removed.keys.length))):d.success(n.maketext("You have deleted all records from the whitelist.")),e.hasOwnProperty("requester_ip_is_whitelisted")&&e.requester_ip_is_whitelisted<=0&&e.hasOwnProperty("requester_ip")&&o.growl_whitelist_warning(e.requester_ip)}),(function(e){d.error(e)})).finally((function(){o.delete_in_progress=!1,o.deselect_all_whitelist(),m((function(){o.downloadAllLink=o.generateDownloadAllLink(),o.downloadSelectionLink=o.generateDownloadSelectionLink()}))}))},o.select_all_whitelist=function(){return 0!==o.whitelist.length&&(t(".whitelist_select_item").prop("checked",!0),t("#whitelist_select_all_checkbox").prop("checked",!0),o.downloadSelectionLink=o.generateDownloadSelectionLink(),!0)},o.deselect_all_whitelist=function(){return 0!==o.whitelist.length&&(t(".whitelist_select_item").prop("checked",!1),t("#whitelist_select_all_checkbox").prop("checked",!1),o.downloadSelectionLink=o.generateDownloadSelectionLink(),!0)},o.toggle_whitelist_selection=function(){!0===t("#whitelist_select_all_checkbox").prop("checked")?o.select_all_whitelist():o.deselect_all_whitelist()},o.focus_on_whitelist=function(){var e=t("#whitelist_batch_add"),i=setInterval((function(){e.is(":visible")&&(e.focus(),e.select(),clearInterval(i))}),250)},o.add_to_whitelist=function(){if(o.new_whitelist_records&&!o.adding_batch_to_whitelist){var e=function(e){for(var t=e.split("\n"),i=[],n=0;n<t.length;n++){var r=t[n];if(r&&r.length>0){var s=r.split("#"),o=s.shift().trim(),l=s.join("#").trim();i.push({ip:o,comment:l})}}return i}(o.new_whitelist_records);return o._add_to_whitelist(e)}},o._add_to_whitelist=function(t){return o.adding_batch_to_whitelist=!0,u.add_to_whitelist(t).then((function(r){o.whitelist=u.whitelist,o.whitelist_comments=u.whitelist_comments,o.downloadAllLink=o.generateDownloadAllLink(),o.applyFilters(),1===r.added.length?d.success(n.maketext("You have successfully added “[_1]” to the whitelist.",i.escape(r.added[0]))):r.added.length>1&&d.success(n.maketext("You have successfully added [quant,_1,IP address,IP addresses] to the whitelist.",r.added.length)),1===r.updated.length?d.success(n.maketext("You have successfully updated the comment for “[_1]”.",i.escape(r.updated[0]))):r.updated.length>1&&d.success(n.maketext("You have successfully updated the [numerate,_1,comment,comments] for [quant,_1,IP address,IP addresses].",r.updated.length)),r.hasOwnProperty("requester_ip_is_whitelisted")&&r.requester_ip_is_whitelisted>0&&null!==s.whitelist_warning_message&&(s.whitelist_warning_message.ttl=0,s.whitelist_warning_message.promises=[],s.whitelist_warning_message.promises.push(m(e.bind(f,(function(){f.deleteMessage(s.whitelist_warning_message),s.whitelist_warning_message=null})),200)));var l=Object.keys(r.rejected);if(l.length>0){var a=n.maketext("Some IP addresses were not added to the whitelist.");a+="<br>\n",o.new_whitelist_records=l.map((function(e){var i=t.find((function(t){return t.ip===e}));return i&&i.comment?e+" # "+i.comment+"\n":e+"\n"})).join(""),a+="<ul>\n",l.forEach((function(e){r.rejected[e]&&(a+="<li>"+i.escape(r.rejected[e])+"</li>\n")})),a+="</ul>\n",d.error(a)}else o.new_whitelist_records=""}),(function(e){var t=e.main_message,n=e.secondary_messages.length;n>0&&(t+="<ul>\n"),e.secondary_messages.forEach((function(e){t+="<li>"+i.escape(e)+"</li>\n"})),n>0&&(t+="</ul>\n"),d.error(t)})).finally((function(){o.adding_batch_to_whitelist=!1,o.focus_on_whitelist()}))},o.ip_padder=function(e){var t="";if(e)for(var i=e.split("."),n=0;n<i.length;n++){for(var r=i[n];r.length<3;)r="0"+r;t+=r}return t},o.downloadName=function(){return r.getDownloadName("whitelist")},o.generateDownloadAllLink=function(){o.downloadAllLink&&(r.cleanupDownloadUrl(o.downloadAllLink),o.downloadAllLink=null);var e=o.whitelist;if(!e||0===e.length)return"";var t=y(e,o.whitelist_comments);return r.getTextDownloadUrl(r.formatList(t))},o.generateDownloadSelectionLink=function(){if(o.downloadSelectionLink&&(r.cleanupDownloadUrl(o.downloadSelectionLink),o.downloadSelectionLink=null),!o.whitelist||0===o.whitelist.length)return"";var e=o.getSelection();if(!e||0===e.length)return"";var t=y(e,o.whitelist_comments);return r.getTextDownloadUrl(r.formatList(t))},o.focus_on_whitelist()}])})),define("app/views/hulkdBlacklistController",["angular","jquery","lodash","cjt/util/locale","app/utils/download","uiBootstrap","cjt/directives/toggleSortDirective","cjt/decorators/paginationDecorator","cjt/decorators/growlDecorator","cjt/filters/startFromFilter","app/services/HulkdDataSource"],(function(e,t,i,n,r){"use strict";var s=e.module("App");return s.config(["$compileProvider",function(e){e.aHrefSanitizationWhitelist(/^blob:https:/)}]),s.controller("hulkdBlacklistController",["$scope","$filter","$routeParams","$uibModal","HulkdDataSource","growl","PAGE","$timeout",function(s,o,l,a,c,u,d,_){s.blacklist_reverse=!1,s.blacklist=[],s.blacklist_comments={},s.adding_batch_to_blacklist=!1,s.new_blacklist_records="",s.ip_being_edited=!1,s.current_ip=null,s.current_comment="",s.updating_comment=!1,s.modal_instance=null,s.loading=!1,s.downloadAllLink="",s.downloadSelectionLink="",s.meta={sortDirection:"asc",sortBy:"black_ip",sortType:"",sortReverse:!1,filter:"",maxPages:0,totalItems:s.blacklist.length||0,currentPage:1,pageNumberStart:0,pageNumberEnd:0,pageSize:20,pageSizes:[20,50,100]},s.LOCALE=n;var f={filter:o("filter"),orderBy:o("orderBy"),startFrom:o("startFrom"),limitTo:o("limitTo")};s.delete_in_progress=!1,s.ips_to_delete=[],s.selecting_page_size=!1,s.edit_blacklist_ip=function(e){s.current_ip=e,s.current_comment=s.blacklist_comments.hasOwnProperty(e)?s.blacklist_comments[e]:"",s.ip_being_edited=!0;var i=t("#blacklist_current_comment"),n=setInterval((function(){i.is(":visible")&&(i.focus(),i.select(),clearInterval(n))}),250)},s.cancel_blacklist_editing=function(){s.current_ip=null,s.current_comment="",s.ip_being_edited=!1,s.focus_on_blacklist()},s.delete_tooltip=function(e){return n.maketext("Click to delete “[_1]” from the blacklist.",e)},s.edit_tooltip=function(e){return n.maketext("Click to edit the comment for “[_1]”.",e)},s.update_blacklist_comment=function(){s.updating_comment||(s.updating_comment=!0,c.add_to_blacklist([{ip:s.current_ip,comment:s.current_comment}]).then((function(e){s.blacklist_comments=c.blacklist_comments,e.updated.forEach((function(e){u.success(n.maketext("You have successfully updated the comment for “[_1]”.",i.escape(e)))}));var t=[];if(Object.keys(e.rejected).forEach((function(n){t.push(i.escape(n)+": "+i.escape(e.rejected[n]))})),t.length>0){var r=n.maketext("Some records failed to update.")+"<br>";r+=t.join("<br>"),u.error(r)}}),(function(e){u.error(e)})).finally((function(){s.updating_comment=!1,s.cancel_blacklist_editing(),s.focus_on_blacklist()})))};var m=/^(([\da-fA-F]{1,4}:){4})(([\da-fA-F]{1,4}:){3})([\da-fA-F]{1,4})$/,p=/^((\d{1,3}.){3}\d{1,3})-((\d{1,3}.){3}\d{1,3})$/,g=/-/,h=/:/;if(s.splitLongIp=function(e){if(h.test(e))if(g.test(e)){var t=e.split(g),i="",n=m.exec(t[0]);if(n&&(i+=n[1]+"<br>"+n[3]+n[5]),i+="-<br>",(n=m.exec(t[1]))&&(i+=n[1]+"<br>"+n[3]+n[5]),i.length>5)return i}else{var r=m.exec(e);if(r)return r[1]+"<br>"+r[3]+r[5]}else{var s=p.exec(e);if(s)return s[1]+"-<br>"+s[3]}return e},s.$watch((function(){return c.enabled}),(function(){s.load_list()})),s.$watchGroup(["blacklist.length","meta.filteredList.length"],(function(){0!==s.blacklist.length&&0!==s.meta.filteredList.length||t("#blacklist_select_all_checkbox").prop("checked",!1)})),s.selectPage=function(i){t("#blacklist_select_all_checkbox").prop("checked",!1),i&&e.isNumber(i)&&(s.meta.currentPage=i),s.load_list()},s.selectPageSize=function(){return s.load_list({reset_focus:!1})},s.filterList=function(){s.meta.currentPage=1,s.load_list({reset_focus:!1})},s.toggleFilter=function(){s.meta.filter="",s.load_list({reset_focus:!1})},s.sortList=function(e){s.meta.sortReverse="asc"!==e.sortDirection,s.applyFilters()},s.orderByComments=function(e,t){for(var n=i.toPairs(e),r=[],o=0;o<t.length;o++)if(!i.has(e,t[o])){var l=[t[o],""];r.push(l)}var a=i.sortBy(r,(function(e){return s.ip_padder(e[0])}));n.sort(w);var c=i.map(n,(function(e){return e[0]})),u=i.map(a,(function(e){return e[0]})),d=c.concat(u);return"desc"===s.meta.sortDirection?d.reverse():d},s.applyFilters=function(){var e,t,i=[];i=s.blacklist,""!==s.meta.sortDirection&&""!==s.meta.sortBy&&(i="black_ip"===s.meta.sortBy?f.orderBy(i,s.ip_padder,s.meta.sortReverse):s.orderByComments(s.blacklist_comments,s.blacklist)),s.meta.totalItems=s.blacklist.length;var n=s.meta.filter.toLowerCase();return n&&(i=f.filter(i,(function(e){return-1!==e.indexOf(n)||s.blacklist_comments[e]&&-1!==s.blacklist_comments[e].toLowerCase().indexOf(n)}))),s.meta.filteredItems=i.length,e=(s.meta.currentPage-1)*s.meta.pageSize,t=s.meta.pageSize,i=f.limitTo(f.startFrom(i,e),t),s.meta.pageNumberStart=e+1,s.meta.pageNumberEnd=s.meta.currentPage*s.meta.pageSize,0===s.meta.totalItems&&(s.meta.pageNumberStart=0),s.meta.pageNumberEnd>s.meta.totalItems&&(s.meta.pageNumberEnd=s.meta.totalItems),s.meta.filteredList=i,i},s.load_list=function(e){if(c.enabled&&!s.loading){s.loading=!0;var t=void 0===e||!e.hasOwnProperty("reset_focus")||e.reset_focus;if(!c.blacklist_is_cached)return s.meta.filteredList=[],c.load_list("black").then((function(){s.blacklist=c.blacklist,s.blacklist_comments=c.blacklist_comments,s.downloadAllLink=s.generateDownloadAllLink(),s.applyFilters()}),(function(e){u.error(e)})).finally((function(){t&&s.focus_on_blacklist(),s.selecting_page_size=!1,s.loading=!1}));s.blacklist=c.blacklist,s.blacklist_comments=c.blacklist_comments,s.downloadAllLink=s.generateDownloadAllLink(),s.applyFilters(),t&&s.focus_on_blacklist(),s.loading=!1}return null},s.force_load_blacklist=function(){return c.blacklist_is_cached=!1,s.blacklist=[],s.blacklist_comments={},s.meta.filteredList=[],s.load_list()},s.delete_confirmation_message=function(){return 1===s.ips_to_delete.length?n.maketext("Do you want to permanently delete “[_1]” from the blacklist?",s.ips_to_delete[0]):n.maketext("Do you want to permanently delete [quant,_1,record,records] from the backlist?",s.ips_to_delete.length)},s.itemsAreChecked=function(){return t(".blacklist_select_item").filter(":checked").length>0},s.check_blacklist_selection=function(){0===t(".blacklist_select_item").filter(":not(:checked)").length?t("#blacklist_select_all_checkbox").prop("checked",!0):t("#blacklist_select_all_checkbox").prop("checked",!1),s.downloadSelectionLink=s.generateDownloadSelectionLink()},s.getSelection=function(){var e=[],i=t(".blacklist_select_item:checked");return 0===i.length?[]:(i.each((function(){e.push(t(this).data("ip"))})),e)},s.confirm_blacklist_deletion=function(e){if(0===s.blacklist.length)return!1;if(s.delete_in_progress=!0,void 0!==e)s.ips_to_delete=[e],s.is_single_deletion=!0;else{var t=s.getSelection();if(0===t.length)return!1;s.ips_to_delete=t,s.is_single_deletion=!1}return s.modal_instance=a.open({templateUrl:"confirm_blacklist_deletion.html",scope:s}),!0},s.clear_modal_instance=function(){s.modal_instance&&(s.modal_instance.close(),s.modal_instance=null)},s.cancel_deletion=function(){s.delete_in_progress=!1,s.ips_to_delete=[],s.clear_modal_instance(),s.focus_on_blacklist()},s.delete_blacklist_ips=function(e){s.clear_modal_instance(),c.remove_from_blacklist(s.ips_to_delete).then((function(e){s.blacklist=c.blacklist,s.blacklist_comments=c.blacklist_comments,s.applyFilters(),s.focus_on_blacklist(),1===e.removed.length?u.success(n.maketext("You have successfully deleted “[_1]” from the blacklist.",i.escape(e.removed[0]))):u.success(n.maketext("You have successfully deleted [quant,_1,record,records] from the blacklist.",e.removed.length)),e.not_removed.keys&&e.not_removed.keys.length>0&&u.warning(n.maketext("The system was unable to delete [quant,_1,record,records] from the blacklist.",e.not_removed.keys.length))}),(function(e){u.error(e)})).finally((function(){s.delete_in_progress=!1,s.ips_to_delete=[],e||s.deselect_all_blacklist(),_((function(){s.downloadAllLink=s.generateDownloadAllLink(),s.downloadSelectionLink=s.generateDownloadSelectionLink()}))}))},s.confirm_delete_all=function(){return 0!==s.blacklist.length&&(s.delete_in_progress=!0,s.modal_instance=a.open({templateUrl:"confirm_blacklist_delete_all.html",scope:s}),!0)},s.cancel_delete_all=function(){s.delete_in_progress=!1,s.clear_modal_instance(),s.focus_on_blacklist()},s.delete_all=function(){s.clear_modal_instance(),c.remove_all_from_blacklist().then((function(e){s.blacklist=c.blacklist,s.blacklist_comments=c.blacklist_comments,s.applyFilters(),s.focus_on_blacklist(),e.not_removed.keys&&e.not_removed.keys.length>0?(u.success(n.maketext("You have successfully deleted [quant,_1,record,records] from the blacklist.",e.removed.keys.length)),u.warning(n.maketext("The system was unable to delete [quant,_1,record,records] from the blacklist.",e.not_removed.keys.length))):u.success(n.maketext("You have deleted all records from the blacklist."))}),(function(e){u.error(e)})).finally((function(){s.delete_in_progress=!1,s.deselect_all_blacklist(),_((function(){s.downloadAllLink=s.generateDownloadAllLink(),s.downloadSelectionLink=s.generateDownloadSelectionLink()}))}))},s.select_all_blacklist=function(){return 0!==s.blacklist.length&&(t(".blacklist_select_item").prop("checked",!0),t("#blacklist_select_all_checkbox").prop("checked",!0),s.downloadSelectionLink=s.generateDownloadSelectionLink(),!0)},s.deselect_all_blacklist=function(){return 0!==s.blacklist.length&&(t(".blacklist_select_item").prop("checked",!1),t("#blacklist_select_all_checkbox").prop("checked",!1),s.downloadSelectionLink=s.generateDownloadSelectionLink(),!0)},s.toggle_blacklist_selection=function(){!0===t("#blacklist_select_all_checkbox").prop("checked")?s.select_all_blacklist():s.deselect_all_blacklist()},s.focus_on_blacklist=function(){var e=t("#blacklist_batch_add"),i=setInterval((function(){e.is(":visible")&&(e.focus(),e.select(),clearInterval(i))}),250)},s.add_to_blacklist=function(){if(s.new_blacklist_records&&!s.adding_batch_to_blacklist){var e=function(e){for(var t=e.split("\n"),i=[],n=0;n<t.length;n++){var r=t[n];if(r&&r.length>0){var s=r.split("#"),o=s.shift().trim(),l=s.join("#").trim();i.push({ip:o,comment:l})}}return i}(s.new_blacklist_records);return s._add_to_blacklist(e)}},s._add_to_blacklist=function(e){s.adding_batch_to_blacklist=!0,c.add_to_blacklist(e).then((function(t){s.blacklist=c.blacklist,s.blacklist_comments=c.blacklist_comments,s.downloadAllLink=s.generateDownloadAllLink(),s.applyFilters(),1===t.added.length?u.success(n.maketext("You have successfully added “[_1]” to the blacklist.",i.escape(t.added[0]))):t.added.length>1&&u.success(n.maketext("You have successfully added [quant,_1,IP address,IP addresses] to the blacklist.",t.added.length)),1===t.updated.length?u.success(n.maketext("You have successfully updated the comment for “[_1]”.",i.escape(t.updated[0]))):t.updated.length>1&&u.success(n.maketext("You have successfully updated the [numerate,_1,comment,comments] for [quant,_1,IP address,IP addresses].",t.updated.length));var r=Object.keys(t.rejected);if(r.length>0){var o=n.maketext("Some IP addresses were not added to the blacklist.");o+="<br>\n",s.new_blacklist_records=r.map((function(t){var i=e.find((function(e){return e.ip===t}));return i&&i.comment?t+" # "+i.comment+"\n":t+"\n"})).join(""),o+="<ul>\n",r.forEach((function(e){t.rejected[e]&&(o+="<li>"+i.escape(t.rejected[e])+"</li>\n")})),o+="</ul>\n",u.error(o)}else s.new_blacklist_records=""}),(function(e){var t=e.main_message,n=e.secondary_messages.length;n>0&&(t+="<ul>\n"),e.secondary_messages.forEach((function(e){t+="<li>"+i.escape(e)+"</li>\n"})),n>0&&(t+="</ul>\n"),u.error(t)})).finally((function(){s.adding_batch_to_blacklist=!1,s.focus_on_blacklist()}))},l.ip&&l.ip.length>0||null!==d.ipToAdd){var k;l.ip&&l.ip.length>0?k=l.ip:null!==d.ipToAdd&&(k=d.ipToAdd),d.ipToAdd=null,void 0!==k&&s._add_to_blacklist([{ip:k,comment:""}])}function w(e,t){return e[1].toLowerCase()<t[1].toLowerCase()?-1:e[1].toLowerCase()>t[1].toLowerCase()?1:s.ip_padder(e[0])<s.ip_padder(t[0])?-1:s.ip_padder(e[0])>s.ip_padder(t[0])?1:0}function b(e,t){var i=[];return e.forEach((function(e){var n=t[e];i.push({ip:e,comment:n})})),i}s.ip_padder=function(e){var t="";if(e)for(var i=e.split("."),n=0;n<i.length;n++){for(var r=i[n];r.length<3;)r="0"+r;t+=r}return t},s.downloadName=function(){return r.getDownloadName("blacklist")},s.generateDownloadAllLink=function(){s.downloadAllLink&&(r.cleanupDownloadUrl(s.downloadAllLink),s.downloadAllLink=null);var e=s.blacklist;if(!e||0===e.length)return"";var t=b(e,s.blacklist_comments);return r.getTextDownloadUrl(r.formatList(t))},s.generateDownloadSelectionLink=function(){if(s.downloadSelectionLink&&(r.cleanupDownloadUrl(s.downloadSelectionLink),s.downloadSelectionLink=null),!s.blacklist||0===s.blacklist.length)return"";var e=s.getSelection();if(!e||0===e.length)return"";var t=b(e,s.blacklist_comments);return r.getTextDownloadUrl(r.formatList(t))},s.focus_on_blacklist()}])})),define("app/services/FailedLoginService",["angular","cjt/util/locale","cjt/io/api","cjt/io/whm-v1-request","cjt/io/whm-v1"],(function(e,t,i,n,r){e.module("App").factory("FailedLoginService",["$q",function(t){var r={};function s(t){for(var i,n=[],r=0,s=t.length;r<s;r++)n.push((i=t[r],e.isDefined(i.timeleft)&&(i.timeleft=parseInt(i.timeleft,10)),e.isDefined(i.service)&&e.isDefined(i.authservice)&&""===i.authservice&&(i.authservice=i.service),i));return n}return r.getBrutes=function(e){var r=t.defer(),o=new n.Class;return o.initialize("","get_cphulk_brutes"),e&&(e.filterBy&&null!==e.filterValue&&void 0!==e.filterValue&&o.addFilter(e.filterBy,e.filterCompare,e.filterValue),e.sortBy&&e.sortDirection&&o.addSorting(e.sortBy,e.sortDirection,e.sortType),null!==e.pageNumber&&void 0!==e.pageNumber&&o.addPaging(e.pageNumber,e.pageSize||20)),i.promise(o.getRunArguments()).done((function(e){if((e=e.parsedResponse).status){var t=e;t.data=s(t.data),r.resolve(t)}else r.reject(e.error)})),r.promise},r.getExcessiveBrutes=function(e){var r=t.defer(),o=new n.Class;return o.initialize("","get_cphulk_excessive_brutes"),e&&(e.filterBy&&null!==e.filterValue&&void 0!==e.filterValue&&o.addFilter(e.filterBy,e.filterCompare,e.filterValue),e.sortBy&&e.sortDirection&&o.addSorting(e.sortBy,e.sortDirection,e.sortType),null!==e.pageNumber&&void 0!==e.pageNumber&&o.addPaging(e.pageNumber,e.pageSize||20)),i.promise(o.getRunArguments()).done((function(e){if((e=e.parsedResponse).status){var t=e;t.data=s(t.data),r.resolve(t)}else r.reject(e.error)})),r.promise},r.getFailedLogins=function(e){var r=t.defer(),o=new n.Class;return o.initialize("","get_cphulk_failed_logins"),e&&(e.filterBy&&null!==e.filterValue&&void 0!==e.filterValue&&o.addFilter(e.filterBy,e.filterCompare,e.filterValue),e.sortBy&&e.sortDirection&&o.addSorting(e.sortBy,e.sortDirection,e.sortType),null!==e.pageNumber&&void 0!==e.pageNumber&&o.addPaging(e.pageNumber,e.pageSize||20)),i.promise(o.getRunArguments()).done((function(e){if((e=e.parsedResponse).status){var t=e;t.data=s(t.data),r.resolve(t)}else r.reject(e.error)})),r.promise},r.getBlockedUsers=function(e){var r=t.defer(),o=new n.Class;return o.initialize("","get_cphulk_user_brutes"),e&&(e.filterBy&&null!==e.filterValue&&void 0!==e.filterValue&&o.addFilter(e.filterBy,e.filterCompare,e.filterValue),e.sortBy&&e.sortDirection&&o.addSorting(e.sortBy,e.sortDirection,e.sortType),null!==e.pageNumber&&void 0!==e.pageNumber&&o.addPaging(e.pageNumber,e.pageSize||20)),i.promise(o.getRunArguments()).done((function(e){if((e=e.parsedResponse).status){var t=e;t.data=s(t.data),r.resolve(t)}else r.reject(e.error)})),r.promise},r.clearHistory=function(){var e=t.defer(),r=new n.Class;return r.initialize("","flush_cphulk_login_history"),i.promise(r.getRunArguments()).done((function(t){if((t=t.parsedResponse).status){var i=t;i.data=s(i.data),e.resolve(i)}else e.reject(t.error)})),e.promise},r.unBlockAddress=function(e){var r=t.defer(),s=new n.Class;return s.initialize("","flush_cphulk_login_history_for_ips"),s.addArgument("ip",e),i.promise(s.getRunArguments()).done((function(e){if((e=e.parsedResponse).status){var t=e;r.resolve(t.data)}else r.reject(e.error)})),r.promise},r}])})),define("app/views/historyController",["angular","lodash","cjt/util/locale","uiBootstrap","cjt/directives/toggleSortDirective","cjt/directives/actionButtonDirective","cjt/decorators/growlDecorator","app/services/FailedLoginService","app/services/HulkdDataSource"],(function(e,t,i){return e.module("App").controller("historyController",["$scope","$filter","$q","$timeout","FailedLoginService","HulkdDataSource","growl",function(n,r,s,o,l,a,c){function u(e,t){var i=parseInt(t.meta.paginate.page_size,10);e.pageSize=0===i?n.meta.pageSizes[0]:i,e.totalRows=t.meta.paginate.total_records,e.pageNumber=t.meta.paginate.current_page,e.pageNumberStart=t.meta.paginate.current_record,0===e.totalRows&&(e.pageNumberStart=0),e.pageNumberEnd=e.pageNumber*i,e.pageNumberEnd>e.totalRows&&(e.pageNumberEnd=e.totalRows)}n.changePageSize=function(e){if("logins"===e){if(n.logins.length>0)return n.fetchFailedLogins({isUpdate:!0})}else if("users"===e){if(n.users.length>0)return n.fetchBlockedUsers({isUpdate:!0})}else if("brutes"===e){if(n.brutes.length>0)return n.fetchBrutes({isUpdate:!0})}else if("excessiveBrutes"===e&&n.excessiveBrutes.length>0)return n.fetchExcessiveBrutes({isUpdate:!0})},n.fetchPage=function(t,i){return"logins"===t?(i&&e.isNumber(i)&&(n.meta.logins.currentPage=i),n.fetchFailedLogins({isUpdate:!0})):"users"===t?(i&&e.isNumber(i)&&(n.meta.users.currentPage=i),n.fetchBlockedUsers({isUpdate:!0})):"brutes"===t?(i&&e.isNumber(i)&&(n.meta.brutes.currentPage=i),n.fetchBrutes({isUpdate:!0})):"excessiveBrutes"===t?(i&&e.isNumber(i)&&(n.meta.excessiveBrutes.currentPage=i),n.fetchExcessiveBrutes({isUpdate:!0})):void 0},n.sortBruteList=function(e){return n.meta.brutes.sortReverse="asc"!==e.sortDirection,n.fetchBrutes({isUpdate:!0})},n.sortExcessiveBruteList=function(e){return n.meta.excessiveBrutes.sortReverse="asc"!==e.sortDirection,n.fetchExcessiveBrutes({isUpdate:!0})},n.sortLoginList=function(e){return n.meta.logins.sortReverse="asc"!==e.sortDirection,n.fetchFailedLogins({isUpdate:!0})},n.sortBlockedUsers=function(e){return n.meta.users.sortReverse="asc"!==e.sortDirection,n.fetchBlockedUsers({isUpdate:!0})},n.search=function(e){return"logins"===e?n.fetchFailedLogins({isUpdate:!0}):"users"===e?n.fetchBlockedUsers({isUpdate:!0}):"brutes"===e?n.fetchBrutes({isUpdate:!0}):"excessiveBrutes"===e?n.fetchExcessiveBrutes({isUpdate:!0}):void 0},n.loadTable=function(){n.loadingPageData=!0;var e=n.selectedTable;return"failedLogins"===e?(n.logins=[],s.all([n.fetchConfig(),n.fetchFailedLogins()]).finally((function(){n.loadingPageData=!1}))):"users"===e?(n.users=[],s.all([n.fetchConfig(),n.fetchBlockedUsers()]).finally((function(){n.loadingPageData=!1}))):"brutes"===e?(n.brutes=[],s.all([n.fetchConfig(),n.fetchBrutes()]).finally((function(){n.loadingPageData=!1}))):"excessiveBrutes"===e?(n.excessiveBrutes=[],s.all([n.fetchConfig(),n.fetchExcessiveBrutes()]).finally((function(){n.loadingPageData=!1}))):(n.logins=[],n.brutes=[],n.excessiveBrutes=[],n.users=[],s.all([n.fetchConfig(),n.fetchFailedLogins(),n.fetchBlockedUsers(),n.fetchBrutes(),n.fetchExcessiveBrutes()]).finally((function(){n.loadingPageData=!1})))},n.refreshLogins=function(){return n.loadTable()},n.clearHistory=function(){return n.clearingHistory=!0,l.clearHistory().then((function(e){c.success(i.maketext("The system cleared the tables.")),n.logins=[],n.brutes=[],n.excessiveBrutes=[],n.users=[],u(n.meta.logins,e),u(n.meta.brutes,e),u(n.meta.excessiveBrutes,e),u(n.meta.users,e),n.meta.logins.filterValue="",n.meta.brutes.filterValue="",n.meta.excessiveBrutes.filterValue="",n.meta.users.filterValue=""}),(function(e){c.error(e)})).finally((function(){n.clearingHistory=!1}))},n.fetchConfig=function(){t.isEmpty(a.config_settings)?a.load_config_settings().then((function(e){n.config_settings=e}),(function(e){c.error(e)})):n.config_settings=a.config_settings},n.fetchFailedLogins=function(e){return e&&e.isUpdate?n.updatingPageData=!0:n.loadingPageData=!0,l.getFailedLogins(n.meta.logins).then((function(e){n.logins=e.data,u(n.meta.logins,e)}),(function(e){c.error(e)})).finally((function(){n.updatingPageData=!1}))},n.fetchBrutes=function(e){return e&&e.isUpdate?n.updatingPageData=!0:n.loadingPageData=!0,l.getBrutes(n.meta.brutes).then((function(e){n.brutes=e.data,u(n.meta.brutes,e)}),(function(e){c.error(e)})).finally((function(){n.updatingPageData=!1}))},n.fetchExcessiveBrutes=function(e){return e&&e.isUpdate?n.updatingPageData=!0:n.loadingPageData=!0,l.getExcessiveBrutes(n.meta.excessiveBrutes).then((function(e){n.excessiveBrutes=e.data,u(n.meta.excessiveBrutes,e)}),(function(e){c.error(e)})).finally((function(){n.updatingPageData=!1}))},n.fetchBlockedUsers=function(e){return e&&e.isUpdate?n.updatingPageData=!0:n.loadingPageData=!0,l.getBlockedUsers(n.meta.users).then((function(e){n.users=e.data,u(n.meta.users,e)}),(function(e){c.error(e)})).finally((function(){n.updatingPageData=!1}))},n.unBlockAddress=function(e,t){var r=t.target;if(r){if(/disabled/.test(r.className))return;r.className+=" disabled"}return l.unBlockAddress(e).then((function(t){t.records_removed>0&&(n.removeBrute(e),c.success(i.maketext("The system removed the block for: [_1]",e)))}),(function(e){c.error(e)}))},n.removeBrute=function(e){var i=t.find(n.brutes,{ip:e});return i?(n.brutes=t.difference(n.brutes,[i]),!0):!!(i=t.find(n.excessiveBrutes,{ip:e}))&&(n.excessiveBrutes=t.difference(n.excessiveBrutes,[i]),!0)},n.meta={pageSizes:[20,50,100],maxPages:0,brutes:{sortDirection:"asc",sortBy:"logintime",sortType:"",filterBy:"*",filterCompare:"contains",filterValue:"",pageNumber:1,pageNumberStart:0,pageNumberEnd:0,pageSize:20,totalRows:0},excessiveBrutes:{sortDirection:"asc",sortBy:"logintime",sortType:"",filterBy:"*",filterCompare:"contains",filterValue:"",pageNumber:1,pageNumberStart:0,pageNumberEnd:0,pageSize:20,totalRows:0},logins:{sortDirection:"asc",sortBy:"user",sortType:"",filterBy:"*",filterCompare:"contains",filterValue:"",pageNumber:1,pageNumberStart:0,pageNumberEnd:0,pageSize:20,totalRows:0},users:{sortDirection:"asc",sortBy:"user",sortType:"",filterBy:"*",filterCompare:"contains",filterValue:"",pageNumber:1,pageNumberStart:0,pageNumberEnd:0,pageSize:20,totalRows:0}},n.loadingPageData=!0,n.updatingPageData=!1,n.clearingHistory=!1,n.selectedTable="failedLogins",n.$on("$viewContentLoaded",(function(){o((function(){n.refreshLogins()}))})),n.lookbackPeriodMinsDescription=function(e){if(void 0!==e)return i.maketext("The system counts Failed Logins for the duration of the specified period, which is currently set to [quant,_1,minute,minutes].",e.lookback_period_min)},n.blockedUsersDescription=function(e){if(void 0!==e)return i.maketext("The system blocks users for [quant,_1,minute,minutes]. You can configure this value with the “[_2]” option.",e.brute_force_period_mins,i.maketext("Brute Force Protection Period (in minutes)"))},n.blockedIPsDescription=function(e){if(void 0!==e)return i.maketext("The system blocks [asis,IP] addresses for [quant,_1,minute,minutes]. You can configure this value with the “[_2]” option.",e.ip_brute_force_period_mins,i.maketext("IP Address-based Brute Force Protection Period (in minutes)"))}}])})),define("app/views/hulkdEnableController",["angular","jquery","cjt/util/locale","cjt/util/parse","uiBootstrap","cjt/directives/toggleSortDirective","cjt/directives/actionButtonDirective","cjt/decorators/growlDecorator","app/services/HulkdDataSource"],(function(e,t,i,n){return e.module("App").controller("hulkdEnableController",["$scope","HulkdDataSource","growl","growlMessages","PAGE",function(e,r,s,o,l){e.hulkdEnabled=n.parsePerlBoolean(l.hulkd_status.is_enabled),e.knobLabel=" ",e.changing_status=!1,e.status_check_in_progress=!1,e.handle_keydown=function(e){32===e.keyCode&&e.preventDefault()},e.handle_keyup=function(t){32!==t.keyCode&&13!==t.keyCode||(t.preventDefault(),e.toggle_status())},e.toggle_status=function(){e.changing_status||(e.changing_status=!0,e.hulkdEnabled?(o.destroyAllMessages(),r.disable_hulkd().then((function(){e.hulkdEnabled=!1,s.success(i.maketext("[asis,cPHulk] is now disabled."))}),(function(e){s.error(e)})).finally((function(){e.changing_status=!1}))):r.enable_hulkd().then((function(t){e.hulkdEnabled=!0,s.success(i.maketext("[asis,cPHulk] is now enabled.")),t.data&&t.data.restart_ssh?s.warning(i.maketext("The system disabled the [asis,UseDNS] setting for [asis,SSHD] in order to add IP addresses to the whitelist. You must restart SSH through the [output,url,_1,Restart SSH Server,_2] page to implement the change.",l.security_token+"/scripts/ressshd",{target:"_blank"})):t.data&&t.data.warning&&s.warning(t.data.warning)}),(function(e){s.error(e)})).finally((function(){e.changing_status=!1})))},e.get_status=function(){if(!e.status_check_in_progress)return e.status_check_in_progress=!0,r.hulkd_status().then((function(t){t!==e.hulkdEnabled&&(!1===t&&o.destroyAllMessages(),s.warning(i.maketext("The status for [asis,cPHulk] has changed, possibly in another browser session."))),e.hulkdEnabled=t}),(function(e){s.error(e)})).finally((function(){e.status_check_in_progress=!1}))},e.init=function(){t(document).ready((function(){t(window).on("focus",(function(){e.get_status()}))}))},e.init()}])})),define("app/index",["angular","jquery","lodash","cjt/util/locale","cjt/core","cjt/modules","ngRoute","uiBootstrap","ngSanitize","ngAnimate"],(function(e,t,i,n,r){"use strict";return function(){return e.module("App",["cjt2.config.whm.configProvider","ngRoute","ui.bootstrap","ngSanitize","ngAnimate","angular-growl","cjt2.whm"]),require(["cjt/bootstrap","app/views/configController","app/views/countriesController","app/views/hulkdWhitelistController","app/views/hulkdBlacklistController","app/views/historyController","app/views/hulkdEnableController","app/services/HulkdDataSource","angular-growl"],(function(t){var i=e.module("App");i.value("PAGE",PAGE),i.value("COUNTRY_CONSTANTS",{WHITELISTED:"whitelisted",BLACKLISTED:"blacklisted",UNLISTED:"unlisted"}),i.firstLoad={configs:!0},i.controller("BaseController",["$rootScope","$scope",function(e,t){t.loading=!1,e.$on("$routeChangeStart",(function(){t.loading=!0})),e.$on("$routeChangeSuccess",(function(){t.loading=!1})),e.$on("$routeChangeError",(function(){t.loading=!1}))}]),i.config(["$routeProvider","$animateProvider",function(e,t){t.classNameFilter(/^((?!no-animate).)*$/),e.when("/config",{controller:"configController",templateUrl:r.buildFullPath("hulkd/views/configView.ptt")}),e.when("/whitelist",{controller:"hulkdWhitelistController",templateUrl:r.buildFullPath("hulkd/views/hulkdWhitelistView.ptt")}),e.when("/blacklist",{controller:"hulkdBlacklistController",templateUrl:r.buildFullPath("hulkd/views/hulkdBlacklistView.ptt")}),e.when("/history",{controller:"historyController",templateUrl:r.buildFullPath("hulkd/views/historyView.ptt")}),e.when("/countries",{controller:"countriesController",templateUrl:r.buildFullPath("hulkd/views/countriesView.ptt"),resolve:{COUNTRY_CODES:["HulkdDataSource",function(e){return e.get_countries_with_known_ip_ranges()}],XLISTED_COUNTRIES:["HulkdDataSource",function(e){return e.load_xlisted_countries()}]}}),e.otherwise({redirectTo:"/config"})}]),i.run(["$rootScope","$timeout","$location","HulkdDataSource","growl","growlMessages",function(t,i,r,s,o,l){t.$on("$routeChangeStart",(function(){t.currentRoute=r.path()})),t.whitelist_warning_message=null,t.ip_added_with_one_click=!1,t.one_click_add_to_whitelist=function(r){return s.add_to_whitelist([{ip:r}]).then((function(r){o.success(n.maketext("You have successfully added “[_1]” to the whitelist.",r.added[0])),Object.prototype.hasOwnProperty.call(r,"requester_ip")&&r.added.indexOf(r.requester_ip)>-1&&null!==t.whitelist_warning_message&&(t.whitelist_warning_message.ttl=0,t.whitelist_warning_message.promises=[],t.whitelist_warning_message.promises.push(i(e.bind(l,(function(){l.deleteMessage(t.whitelist_warning_message),t.whitelist_warning_message=null})),200)),t.ip_added_with_one_click=!0)}),(function(e){for(var t=e.main_message,i=e.secondary_messages.length,n=0;n<i;n++)0===n&&(t+="<br>"),t+="<br>",t+=e.secondary_messages[n];o.error(t)}))}}]),t(document)}))}}));
Back to Directory File Manager