File: //volume1/@appstore/WebStation/ui/webstation.js
/* Copyright (c) 2021 Synology Inc. All rights reserved. */
Ext.ns("SYNO.SDS.WebStation.Util");SYNO.SDS.WebStation.Util.BackendMap={server:{"0":"Nginx","1":"Apache HTTP Server 2.2","2":"Apache HTTP Server 2.4"},php:{"3":"PHP 5.6","4":"PHP 7.0","5":"PHP 7.1","6":"PHP 7.2","7":"PHP 7.3","8":"PHP 7.4"},pkgID:{"Apache HTTP Server 2.2":"Apache2.2","Apache HTTP Server 2.4":"Apache2.4","PHP 5.6":"PHP5.6","PHP 7.0":"PHP7.0","PHP 7.1":"PHP7.1","PHP 7.2":"PHP7.2","PHP 7.3":"PHP7.3","PHP 7.4":"PHP7.4"}};SYNO.SDS.WebStation.Util.HomeShareStatus={StatusNormal:0,StatusNotEnable:1,StatusIsEncrypted:2,StatusBackendNotExist:3,StatusUnknownError:4};SYNO.SDS.WebStation.Util.getReqCompoundParam=function(a,c){if(!(c instanceof Array)){return null}for(var b=0;b<c.length;b++){if(false===SYNO.ux.Utils.checkApiConsistency(a,c[b])){continue}return c[b]}return null};SYNO.SDS.WebStation.Util.getSuccessRespCompoundData=function(b,d){if(!(d.result instanceof Array)){return null}for(var c=0;c<d.result.length;c++){var a=d.result[c];if(false===SYNO.ux.Utils.checkApiConsistency(b,a)){continue}if(true===a.has_fail||false===a.success){break}if(d.result[c].data){return d.result[c].data}else{return null}}return null};SYNO.SDS.WebStation.Util.getFailRespCompoundParam=function(b,d){if(false===d.has_fail){return null}if(!(d.result instanceof Array)){return null}for(var c=0;c<d.result.length;c++){var a=d.result[c];if(b!=a.api){continue}if(false===a.success){return a.error}}return null};Ext.define("SYNO.SDS.WebStation.Status",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(a){this.module=a.module;this.appWin=a.appWin;this.owner=a.owner;this.webapiStatus=[{api:"SYNO.WebStation.Status",method:"get",version:1},{api:"SYNO.Core.Package.Server",method:"list",version:1},{api:"SYNO.Core.Package",methods:"list",version:1}];var b=this.fillConfig(a);this.callParent([b]);this.mon(SYNO.SDS.StatusNotifier,"thirdpartychanged",this.onPkgChanged,this)},fillConfig:function(a){var b={itemId:"Status",autoFlexcroll:false,useDefaultBtn:false,layout:"border",items:[this.createGeneralStatus(),this.createSupportBackend()]};Ext.apply(b,a);return b},busy:function(){this.appWin.setStatusBusy()},unbusy:function(){this.appWin.clearStatusBusy()},onPkgChanged:function(a,b){this.busy();this.sendWebAPI({compound:{params:this.webapiStatus},timeout:3600000,scope:this,callback:this.webapiDone})},createGeneralStatus:function(){var a=[];a.push({xtype:"syno_displayfield",id:this.default_backend_status=Ext.id(),fieldLabel:_TT("SYNO.SDS.WebStation.Application","status","default_server_status"),name:"default_backend_status",htmlEncode:false,value:"--",isDirty:function(){return false}},{xtype:"syno_displayfield",id:this.userdir_status=Ext.id(),fieldLabel:_TT("SYNO.SDS.WebStation.Application","status","personal_website_status"),name:"userdir_status",htmlEncode:false,value:"--",isDirty:function(){return false}},{xtype:"syno_displayfield",id:this.vhost_status=Ext.id(),fieldLabel:_TT("SYNO.SDS.WebStation.Application","status","vhost_status"),name:"vhost_status",htmlEncode:false,value:"--",isDirty:function(){return false}});return{xtype:"syno_fieldset",title:_T("log","general"),region:"north",labelWidth:"230",items:a}},createSupportBackend:function(){this.support_backend_store=new Ext.data.SimpleStore({fields:["backend","status"],data:[["Nginx",true]]});var b=new Ext.grid.ColumnModel({defaults:{menuDisabled:false,sortable:false},columns:[{header:_TT("SYNO.SDS.WebStation.Application","common","name"),dataIndex:"backend",align:"left",sortable:false},{header:_TT("SYNO.SDS.WebStation.Application","common","status"),dataIndex:"status",align:"center",sortable:false,renderer:function(e){if(e){var d=_T("pkgmgr","status_installed");return'<span class="green-status" style="padding-right:8px;">'+d+"</span>"}else{return'<font style="padding-right:8px"> -- </font>'}}},{xtype:"actioncolumn",header:_TT("SYNO.SDS.WebStation.Application","status","management"),align:"center",sortable:false,renderer:function(e,g,h,i,f,d){if("Nginx"==h.get("backend")){return"<font> -- </font>"}},items:[{getClass:function(d,f,g){var e=g.get("backend");if("Nginx"==e){return""}return"syno-webstation-management"},handler:function(f,h,d){var e=f.store.getAt(h).get("backend");var g;if("Nginx"===e){return}g=this.getPkgID(e);SYNO.SDS.AppLaunch("SYNO.SDS.PkgManApp.Instance",{action:"open",packages:[g]})}}],scope:this}]});var a=new Ext.grid.RowSelectionModel({singleSelect:false});var c=new SYNO.ux.GridPanel({title:_TT("SYNO.SDS.WebStation.Application","status","support_backend"),hideHeaders:false,colModel:b,selModel:a,bodyStyle:"padding-right:0px; padding-left:0px;",store:this.support_backend_store});return{xtype:"syno_fieldset",title:_TT("SYNO.SDS.WebStation.Application","status","support_backend"),bwrapStyle:"padding-right: 0px; padding-left:0px",region:"center",layout:"fit",items:c}},getPkgID:function(a){var b=SYNO.SDS.WebStation.Util.BackendMap.pkgID;if(a in b){return b[a]}else{return""}},onPageActivate:function(){this.busy();this.sendWebAPI({compound:{params:this.webapiStatus},timeout:3600000,scope:this,callback:this.webapiDone})},webapiDone:function(g,f,d){if(g===true){var a=SYNO.API.Util.GetValByAPI(f,"SYNO.WebStation.Status","get");var e=SYNO.API.Util.GetValByAPI(f,"SYNO.Core.Package.Server","list");var b=SYNO.API.Util.GetValByAPI(f,"SYNO.Core.Package","list");var c=this.getPackageList(e,b);a.available_php_backend=a.available_php_backend||[];this.setDefaultBackendStatus(a);this.setUserdirStatus(a);this.setSupportBackend(a,c);this.setVHostStatus(a)}this.unbusy()},setDefaultBackendStatus:function(c){var e;var a;if(this.checkBackendStatus(c,c.backend,c.php)){e=_T("helpbrowser","font_normal");a="green"}else{e=_T("common","status_abnormal");a="red"}var d=String.format('<font class="{0}-status">{1}</font>',a,e);var b=this.getForm().findField("default_backend_status");b.setValue(d)},setVHostStatus:function(c){var b;if(c.VirtualHost.total===0){b=this.getForm().findField("vhost_status");b.setValue("--");return}var e;var a;if(c.VirtualHost.error===0){e=_T("helpbrowser","font_normal");a="green"}else{e=_T("common","status_abnormal");a="red"}var d=String.format('<font class="{0}-status">{1}</font>',a,e);b=this.getForm().findField("vhost_status");b.setValue(d)},setUserdirStatus:function(c){var a="green";var e=_T("common","enabled");if(!c.userdir||c.home_share_status!==SYNO.SDS.WebStation.Util.HomeShareStatus.StatusNormal){e=_T("common","disabled");a="red"}else{if(!this.checkBackendStatus(c,c.userdir_backend,c.userdir_php)){e=_T("common","status_abnormal");a="red"}}var d=String.format('<font class="{0}-status">{1}</font>',a,e);var b=this.getForm().findField("userdir_status");b.setValue(d)},getPackageList:function(c,a){var b=[];if("data" in c){c.data.forEach(function(e,d,f){b.push(e.id)})}if("packages" in a){a.packages.forEach(function(e,d,f){b.push(e.id)})}return b},setSupportBackend:function(d,c){var e=[];e.push(["Nginx",true]);var b=SYNO.SDS.WebStation.Util.BackendMap;var a;for(a=1;;a++){if(!(a in b.server)){break}if(d.available_server_backend.indexOf(a)!==-1){e.push([b.server[a],true])}else{if(c.indexOf(this.getPkgID(b.server[a]))!==-1){e.push([b.server[a],false])}}}for(a=3;;a++){if(!(a in b.php)){break}if(d.available_php_backend.indexOf(a)!==-1){e.push([b.php[a],true])}else{if(c.indexOf(this.getPkgID(b.php[a]))!==-1){e.push([b.php[a],false])}}}this.support_backend_store.loadData(e)},checkBackendStatus:function(b,c,e){var d=false;e=(typeof e!=="undefined")?e:null;if(e!==null){for(var a=0;a<b.php_profiles.profiles.length;a++){if(e===b.php_profiles.profiles[a].uuid){d=true;break}}}else{d=true}if(!d){return false}if(b.available_server_backend.indexOf(c)==-1){return false}return true},errorHandling:function(a){}});Ext.define("SYNO.SDS.WebStation.Web.VHostEditor",{extend:"SYNO.SDS.ModalWindow",constructor:function(a){this.module=a.module;this.owner=a.owner;this.store=a.store;this.webapi=a.webapi;this.status_data=a.status_data;this.uuid="";this.panel=new SYNO.SDS.WebStation.Web.VHostPanel({module:this.module,owner:this,status_data:this.status_data});this.callParent([Ext.apply({title:"Virtual Host",closable:true,width:510,height:570,items:[this.panel],buttons:[{text:_T("common","ok"),btnStyle:"blue",disabled:this._S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",scope:this,handler:this.onApply},{text:_T("common","cancel"),scope:this,handler:function(){this.close()}}]},a)])},sendRequest:function(b){var a=this.panel.getData();a.apply_permission=b;this.sendWebAPI({api:this.webapi.api,method:this.webapi.method,version:this.webapi.version,params:{host:a},callback:function(d,c){this.clearStatusBusy();if(!d){this.onError(c.code,c.errors);return}this.fireEvent("close");this.close()},scope:this})},onForceAcl:function(a){if(a!="yes"){return}if(!this.panel.getForm().isValid()||!this.validator()){return}if(!this.panel.getForm().isDirty()){this.close();return}this.setStatusBusy();this.sendRequest(true)},onApply:function(){if(!this.panel.getForm().isValid()){this.setStatusError({text:_TT("SYNO.SDS.WebStation.Application","error","err_backend_invalid")});return}if(!this.validator()){return}if(!this.panel.getForm().isDirty()){this.close();return}this.setStatusBusy();this.sendRequest(false)},handleConflictHost:function(b){var d=this.panel.getForm();var e;var c;var a;if(!d.findField("fqdn").disabled){c=d.findField("name_http_port");a=d.findField("name_https_port");e={text:_TT("SYNO.SDS.WebStation.Application","error","err_host_duplicated")}}else{c=d.findField("port_http_port");a=d.findField("port_https_port");e={text:_TT("SYNO.SDS.WebStation.Application","error","err_port_conflict")}}if(d.findField("name_port").checked&&-1!==b.indexOf(80)&&-1!==b.indexOf(443)){d.findField("fqdn").markInvalid(e.text)}if(!c.disabled&&-1!==b.indexOf(parseInt(c.getValue(),10))){c.markInvalid(e.text)}if(!a.disabled&&-1!==b.indexOf(parseInt(a.getValue(),10))){a.markInvalid(e.text)}this.setStatusError(e)},onError:function(b,a){var c=this.panel.getForm();switch(b){case 1004:this.handleConflictHost(a.conflict_ports);break;case 1007:c.findField("fqdn").markInvalid(_TT("SYNO.SDS.WebStation.Application","error","err_fqdn_invalid"));this.setStatusError({text:_TT("SYNO.SDS.WebStation.Application","error","err_fqdn_invalid")});break;case 1008:this.setStatusError({text:_TT("SYNO.SDS.WebStation.Application","error","err_port_invalid")});break;case 1009:this.setStatusError({text:_TT("SYNO.SDS.WebStation.Application","error","err_port_conflict")});break;case 1015:this.setStatusError({text:_TT("SYNO.SDS.WebStation.Application","error","err_root_invalid")});break;case 1017:this.setStatusError({text:_TT("SYNO.SDS.WebStation.Application","error","err_php_invalid")});break;case 1018:this.setStatusError({text:_TT("SYNO.SDS.WebStation.Application","error","err_backend_invalid")});break;case 1021:this.setStatusError({text:_T("app_port_alias","err_fqdn_duplicated")});break;case 1022:this.module.appWin.getMsgBox().confirm("ACL Error",_TT("SYNO.SDS.WebStation.Application","error","err_vhost_acl"),this.onForceAcl,this);break;default:this.setStatusError({text:_T("error","error_error_system")});break}},setData:function(a){return this.panel.setData(a)},validator:function(){var a=this.panel.getForm().getValues();if(a.based==="name"&&!a.name_port&&!a.name_http&&!a.name_https){this.setStatusError({text:_TT("SYNO.SDS.WebStation.Application","error","err_no_port_set")});return false}else{if(a.based==="port"&&!a.port_http&&!a.port_https){this.setStatusError({text:_TT("SYNO.SDS.WebStation.Application","error","err_no_port_set")});return false}}return true}});Ext.define("SYNO.SDS.WebStation.Web.VHostPanel",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(a){var b=Ext.apply({autoHeight:true,monitorValid:true,items:[{xtype:"syno_radio",name:"based",boxLabel:_TT("SYNO.SDS.WebStation.Application","vhost","name_based"),checked:true,inputValue:"name",id:this.name_based=Ext.id(),scope:this,handler:this.enableHandler},{xtype:"syno_textfield",vtype:"FQDN",maxlength:255,allowBlank:false,indent:1,width:270,fieldLabel:_TT("SYNO.SDS.WebStation.Application","vhost","hostname"),name:"fqdn",validator:this.validateFQDN.createDelegate(this)},{xtype:"syno_compositefield",indent:1,fieldLabel:_TT("SYNO.SDS.WebStation.Application","vhost","port"),items:[{xtype:"syno_checkbox",name:"name_port",boxLabel:"80 / 443",checked:true,inputValue:"default"}]},{xtype:"syno_compositefield",indent:1,items:[{xtype:"syno_checkbox",name:"name_http",boxLabel:"HTTP",width:90,inputValue:"http",scope:this,handler:this.enableHandler},{disabled:true,xtype:"syno_textfield",vtype:"port",allowBlank:false,name:"name_http_port",width:60,maxlength:5,validator:function(c){return c!=80}}]},{xtype:"syno_compositefield",indent:1,items:[{xtype:"syno_checkbox",name:"name_https",boxLabel:"HTTPS",width:90,inputValue:"https",scope:this,handler:this.enableHandler},{disabled:true,xtype:"syno_textfield",vtype:"port",allowBlank:false,name:"name_https_port",width:60,maxlength:5,validator:function(c){return c!=443}}]},{xtype:"syno_radio",name:"based",indent:0,boxLabel:_TT("SYNO.SDS.WebStation.Application","vhost","port_based"),inputValue:"port",scope:this,handler:this.enableHandler},{xtype:"syno_compositefield",indent:1,fieldLabel:_TT("SYNO.SDS.WebStation.Application","vhost","port"),items:[{disabled:true,xtype:"syno_checkbox",name:"port_http",width:90,boxLabel:"HTTP",inputValue:"http",scope:this,handler:this.enableHandler},{disabled:true,xtype:"syno_textfield",vtype:"port",allowBlank:false,name:"port_http_port",width:60,maxlength:5}]},{xtype:"syno_compositefield",indent:1,items:[{disabled:true,xtype:"syno_checkbox",name:"port_https",width:90,boxLabel:"HTTPS",inputValue:"https",scope:this,handler:this.enableHandler},{disabled:true,xtype:"syno_textfield",vtype:"port",allowBlank:false,name:"port_https_port",width:60,maxlength:5}]},{xtype:"syno_compositefield",fieldLabel:_TT("SYNO.SDS.WebStation.Application","vhost","docroot"),items:[{xtype:"syno_textfield",allowBlank:false,readOnly:true,width:180,name:"root"},{xtype:"syno_button",text:_TT("SYNO.SDS.WebStation.Application","vhost","choose_dir"),width:90,scope:this,handler:this.docrootSelect}]},{xtype:"syno_compositefield",fieldLabel:_TT("SYNO.SDS.WebStation.Application","vhost","https_settings"),items:[{xtype:"syno_checkbox",name:"hsts",boxLabel:"HSTS"}]},{xtype:"syno_compositefield",items:[{xtype:"syno_checkbox",name:"http2",boxLabel:"HTTP/2"}]},{xtype:"syno_combobox",name:"backend",fieldLabel:_TT("SYNO.SDS.WebStation.Application","vhost","http_backend"),displayField:"backend_name",allowBlank:false,valueField:"backend_id",store:new Ext.data.SimpleStore({fields:["backend_id","backend_name"],listeners:{load:{scope:this,fn:this.onAvailableServerLoad}}})},{xtype:"syno_combobox",name:"php_backend",fieldLabel:"PHP",displayField:"profile_name",allowBlank:false,valueField:"uuid",store:new Ext.data.SimpleStore({fields:["uuid","profile_name"],listeners:{load:{scope:this,fn:this.onAvailablePHPLoad}}})}]},a);this.module=a.module;this.owner=a.owner;this.status_data=a.status_data;this.FQDNChecker=new SYNO.SDS.AdminCenter.Utils.Validator.FQDNConflictChecker();this.FQDNChecker.FindListFQDNPortPair(this,"SYNO.WebStation.HTTP.VHost");this.callParent([b]);this.loadComboData()},loadComboData:function(){var a={api:"SYNO.WebStation.Status",method:"get",version:1};var b=SYNO.SDS.WebStation.Util.getSuccessRespCompoundData(a,this.status_data);var c={api:"SYNO.WebStation.PHP.Profile",method:"list",version:1};var e=SYNO.SDS.WebStation.Util.getSuccessRespCompoundData(c,this.status_data).profiles;this.getForm().findField("backend").getStore().loadData(b.available_server_backend.map(function(f){return[f,SYNO.SDS.WebStation.Util.BackendMap.server[f]]}));var d=[[null,_TT("SYNO.SDS.WebStation.Application","default","php_not_configured")]].concat(e.map(function(f){return[f.uuid,f.profile_name+" ( "+SYNO.SDS.WebStation.Util.BackendMap.php[f.backend]+" )"]}));this.getForm().findField("php_backend").getStore().loadData(d)},onAvailableServerLoad:function(b,a){var e=this.getForm().findField("backend");var d=e.getValue();if(0===d.length){e.setValue(0);return 0}for(var c=0;c<a.length;c++){if(a[c].get("backend_id")===d){e.reset();return 0}}e.clearValue();e.validate()},onAvailablePHPLoad:function(b,a){var e=this.getForm().findField("php_backend");var d=e.getValue();if(d==="nan"||d===""){e.setValue(null);return 0}for(var c=0;c<a.length;c++){if(a[c].get("uuid")===d){e.reset();return 0}}this.handlePHPNotAvaliable(e,d)},handlePHPNotAvaliable:function(a,b){a.setValue("");a.markInvalid(_TT("SYNO.SDS.WebStation.Application","error","err_backend_not_found"))},docrootSelect:function(){var a=new SYNO.SDS.Utils.FileChooser.Chooser({owner:this.owner,needrw:false,usage:{type:"chooseDir"},title:_TT("SYNO.SDS.WebStation.Application","vhost","docroot"),folderToolbar:true,enumCluster:false,listeners:{scope:this,choose:function(c,b,d){var e=b.path;if(!e){return}e=e.replace(/^\/+/,"");if(!e){return}this.getForm().findField("root").setValue(e);c.close()}},treeFilter:function(c,b){if(b&&(b.spath==="/home"||b.spath==="/homes"||b.mountType==="remote")){return false}return true}});a.show()},enableHandler:function(){var e=this.getForm(),a=function(g){e.findField(g).enable()},b=function(g){e.findField(g).disable()},d=["fqdn","name_port","name_http","name_https"],f=["port_http","port_https"],c=["name_http","name_https","port_http","port_https"];if(e.findField(this.name_based).getValue()){Ext.each(d,a);Ext.each(f,b)}else{Ext.each(f,a);Ext.each(d,b)}Ext.each(c,function(h){var g=e.findField(h);if(!g.disabled&&g.getValue()){e.findField(h+"_port").enable()}else{e.findField(h+"_port").disable()}})},getData:function(){var b=this.getForm().getValues(),a={port:{http:[],https:[]},https:{},version:2};if(b.based==="name"){a.fqdn=b.fqdn;if(b.name_port){a.port.http.push(80);a.port.https.push(443)}if(b.name_http){a.port.http.push(parseInt(b.name_http_port,10))}if(b.name_https){a.port.https.push(parseInt(b.name_https_port,10))}}else{if(b.port_http){a.port.http.push(parseInt(b.port_http_port,10))}if(b.port_https){a.port.https.push(parseInt(b.port_https_port,10))}}a.root=b.root;a.https.hsts=b.hsts;a.https.http2=b.http2;a.backend=b.backend;a.php=b.php_backend;if(this.uuid){a.UUID=this.uuid}return a},setData:function(f){var d={};if(f.fqdn){d.based="name";d.fqdn=f.fqdn;if(!f.port.http){f.port.http=[]}if(!f.port.https){f.port.https=[]}var e=f.port.http.indexOf(80),c=f.port.https.indexOf(443);if(e!==-1&&c!==-1){d.name_port=true;f.port.http.splice(e,1);f.port.https.splice(c,1)}else{d.name_port=false}if(f.port.http.length){d.name_http=true;d.name_http_port=f.port.http[0]}if(f.port.https.length){d.name_https=true;d.name_https_port=f.port.https[0]}}else{d.based="port";if(f.port.http){d.port_http=true;d.port_http_port=f.port.http[0]}if(f.port.https){d.port_https=true;d.port_https_port=f.port.https[0]}}d.root=f.root;d.hsts=f.https.hsts;d.http2=f.https.http2;d.backend=f.backend;d.php_backend=f.php;if(f.UUID){this.uuid=f.UUID}this.vhost_data=d;this.getForm().setValues(this.vhost_data);this.loadComboData()},validateFQDN:function(b){var c=this.getForm().getValues();if(c.based!=="name"){return true}if(c.name_port&&(this.FQDNChecker.IsConflict(b,80)||this.FQDNChecker.IsConflict(b,443))){return _T("app_port_alias","err_fqdn_duplicated")}var a;if(c.name_http){a=parseInt(c.name_http_port,10);if(a&&this.FQDNChecker.IsConflict(b,a)){return _T("app_port_alias","err_fqdn_duplicated")}}if(c.name_https){a=parseInt(c.name_https_port,10);if(a&&this.FQDNChecker.IsConflict(b,a)){return _T("app_port_alias","err_fqdn_duplicated")}}return true}});Ext.define("SYNO.SDS.WebStation.VHostTab",{extend:"SYNO.ux.GridPanel",constructor:function(a){this.module=a.module;this.appWin=a.appWin;this.owner=a.owner;this.store=new SYNO.API.JsonStore({api:"SYNO.WebStation.HTTP.VHost",version:1,method:"list",root:"hosts",totalProperty:"total",fields:[{name:"error",convert:this.converterError},{name:"fqdn",convert:this.converterFqdn},{name:"port",convert:this.converterPort},{name:"protocol",convert:this.converterProtocol},"root"],idProperty:"UUID",appWindow:this.owner,autoDestroy:true,listeners:{beforeload:{scope:this,fn:this.onStoreBeforeLoaded},load:{scope:this,fn:this.onStoreLoaded}}});var b=this.fillConfig(a);this.callParent([b]);this.mon(SYNO.SDS.StatusNotifier,"thirdpartychanged",this.onPkgChanged,this)},fillConfig:function(a){return Ext.apply({title:_TT("SYNO.SDS.WebStation.Application","title","vhost"),tbar:{xtype:"syno_toolbar",defaultType:"syno_button",items:this.getActionGroup().getArray()},columns:[{dataIndex:"error",header:_TT("SYNO.SDS.WebStation.Application","common","status"),align:"left",sortable:true,renderer:function(d){var c;var b;if(d){c=_T("helpbrowser","font_normal");b="green"}else{c=_T("common","status_abnormal");b="red"}return String.format('<font class="{0}-status">{1}</font>',b,c)}},{dataIndex:"fqdn",header:_T("service","service_host_name"),align:"left",sortable:true},{dataIndex:"port",header:_T("service","service_vhost_port"),align:"left",sortable:true},{dataIndex:"protocol",header:_T("service","service_vhost_type"),align:"left",sortable:true},{dataIndex:"root",header:_T("service","service_sub_folder"),align:"left",sortable:true}],selModel:new Ext.grid.RowSelectionModel({singleSelect:false,listeners:{selectionchange:{scope:this,fn:this.onSelectionChange}}}),viewConfig:{forceFit:true},enableHdMenu:false,enableColumnMove:false,enableColLock:false,sortable:true,listeners:{rowdblclick:{scope:this,fn:this.onRowDblclick},rowcontextmenu:{scope:this,fn:this.onRowContextMenu},containercontextmenu:{scope:this,fn:this.onContainerContextMenu}}},a)},getGetWebAPICompoundParam:function(){return[{api:"SYNO.WebStation.PHP.Profile",method:"list",version:1},{api:"SYNO.WebStation.Status",method:"get",version:1}]},createHandler:function(){this.busy();this.sendWebAPI({compound:{stopwhenerror:false,params:this.getGetWebAPICompoundParam()},scope:this,params:{},callback:function(c,b){var a=new SYNO.SDS.WebStation.Web.VHostEditor({owner:this.appWin,module:this,status_data:b,webapi:{api:"SYNO.WebStation.HTTP.VHost",method:"add",version:1},listeners:{close:this.webapiDone,scope:this}});a.show()}})},editHandler:function(){this.busy();var a=this.getSelectionModel().getSelections();if(a.length!==1){return}this.sendWebAPI({compound:{stopwhenerror:false,params:this.getGetWebAPICompoundParam()},scope:this,params:{},callback:function(d,c){var b=new SYNO.SDS.WebStation.Web.VHostEditor({owner:this.appWin,module:this,status_data:c,webapi:{api:"SYNO.WebStation.HTTP.VHost",method:"update",version:1},listeners:{close:this.webapiDone,scope:this}});b.setData(a[0].json);b.show()}})},deleteHandler:function(){var b=this.getSelectionModel(),a=b.getSelections();if(!a.length){return}this.owner.getMsgBox().confirmDelete(_TT("SYNO.SDS.WebStation.Application","title","vhost"),_T("common","remove_cfrmrmv"),function(d){if("yes"!==d){return}this.busy();var c=[];if(a.length===1){b.selectNext()}Ext.each(a,function(e){this.store.remove(e);c.push(e.json.UUID)},this);this.sendWebAPI({api:"SYNO.WebStation.HTTP.VHost",method:"delete",version:1,params:{uuids:c},scope:this,callback:this.webapiDone})},this)},onPkgChanged:function(a,b){this.store.load()},onPageActivate:function(){this.store.load()},onStoreBeforeLoaded:function(a,b,c){this.busy()},onStoreLoaded:function(c,b,d,e){this.unbusy();var a=this.getSelectionModel().getSelections().length,f=this.getActionGroup();if(a===0){f.disable("delete");f.disable("edit")}return},onSelectionChange:function(b,c){var a=b.getSelections().length,d=this.getActionGroup();if(a===0){d.disable("delete");d.disable("edit")}else{d.enable("delete");if(a===1){d.enable("edit")}else{d.disable("edit")}}},onRowDblclick:function(b,d,c,a){this.editHandler()},onRowContextMenu:function(b,g,c,a){var d=new SYNO.ux.Menu({autoDestroy:true,items:this.getActionGroup().getArray()}),f=this.getSelectionModel();f.selectRow(g,f.isSelected(g));d.showAt(c.getXY());c.preventDefault()},onContainerContextMenu:function(b,c,a){var d=new SYNO.ux.Menu({autoDestroy:true,items:this.getActionGroup().getArray()});d.showAt(c.getXY());c.preventDefault()},busy:function(){this.el.mask(_T("common","loading"),"x-mask-loading")},unbusy:function(){this.el.unmask()},webapiDone:function(c,b,a){this.unbusy();this.store.load()},converterError:function(b,a){if(a.error!==999){return false}return true},converterFqdn:function(b,a){if(a.fqdn){return a.fqdn}return"*"},converterPort:function(b,a){var c=[];Ext.each(a.port.http,function(d){c.push(d)});Ext.each(a.port.https,function(d){c.push(d)});return c.join(" / ")},converterProtocol:function(b,a){var c=[];if(a.port.http){c.push("HTTP")}if(a.port.https){c.push("HTTPS")}return c.join(" / ")},getActionGroup:function(){if(this.actionGroup){return this.actionGroup}this.actionGroup=new SYNO.SDS.Utils.ActionGroup([new Ext.Action({text:_T("common","create"),itemId:"create",disabled:this._S("demo_mode"),scope:this,handler:this.createHandler}),new Ext.Action({text:_T("common","alt_edit"),itemId:"edit",scope:this,handler:this.editHandler}),new Ext.Action({text:_T("common","delete"),itemId:"delete",scope:this,handler:this.deleteHandler})]);return this.actionGroup}});Ext.define("SYNO.SDS.WebStation.Default",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(a){this.appWin=a.appWin;this.webapiDefault={api:"SYNO.WebStation.Default",methods:{get:"get",set:"set"},version:1};this.webapiStatus={api:"SYNO.WebStation.Status",methods:{get:"get"},version:1};this.webapiPHPProfile={api:"SYNO.WebStation.PHP.Profile",methods:{get:"list"},version:1};this.webapiHomeService={api:"SYNO.Core.Share",methods:{get:"get"},version:1};var b=this.fillConfig(a);this.status_data=undefined;this.serverData=null;this.userdirServerData=null;this.phpData=null;this.callParent([b]);this.mon(this,"afterlayout",this.addToolTip,this,{single:true});this.mon(SYNO.SDS.StatusNotifier,"thirdpartychanged",this.loadForm,this);this.mon(SYNO.SDS.StatusNotifier,"sharefolderchanged",this.loadForm,this)},fillConfig:function(a){var b={autoScroll:true,useDefaultBtn:true,webapi:this.webapiDefault,items:[this.createItems()]};Ext.apply(b,a);return b},createItems:function(){var a=[];a.push({xtype:"syno_combobox",name:"backend",fieldLabel:_TT("SYNO.SDS.WebStation.Application","default","http_backend"),valueField:"backend_id",displayField:"backend_name",store:new Ext.data.SimpleStore({fields:["backend_id","backend_name"],listeners:{load:{scope:this,fn:this.onAvailableDefaultServerLoad}}}),validator:this.validatorBackend.createDelegate(this),allowBlank:false});a.push({xtype:"syno_combobox",name:"php",fieldLabel:"PHP",valueField:"uuid",displayField:"profile_name",store:new Ext.data.SimpleStore({fields:["uuid","profile_name"],listeners:{load:{scope:this,fn:this.onAvailableDefaultServerPHPLoad}}}),validator:this.validatorPHP.createDelegate(this),allowBlank:false,tpl:'<tpl for="."><div ext:qtip="{profile_name}" class="x-combo-list-item">{profile_name}</div></tpl>'});a.push({xtype:"syno_checkbox",name:"userdir",boxLabel:_TT("SYNO.SDS.WebStation.Application","default","enable_userdir"),listeners:{check:{scope:this,fn:function(c,b){var d=false;if(b){d=this.userHomeCheckHandler()}this.handleUserdirEnableStatus(d)}},disable:{scope:this,fn:function(b){this.handleUserdirEnableStatus(false)}}}},{xtype:"syno_displayfield",indent:1,value:_TT("SYNO.SDS.WebStation.Application","default","enable_userdir_desc")},{xtype:"syno_combobox",indent:1,name:"userdir_backend",fieldLabel:_TT("SYNO.SDS.WebStation.Application","default","http_backend"),valueField:"backend_id",displayField:"backend_name",store:new Ext.data.SimpleStore({fields:["backend_id","backend_name"],listeners:{load:{scope:this,fn:this.onAvailableUserdirServerLoad}}}),validator:this.validatorBackend.createDelegate(this),allowBlank:false},{xtype:"syno_combobox",indent:1,name:"userdir_php",fieldLabel:"PHP",valueField:"uuid",displayField:"profile_name",store:new Ext.data.SimpleStore({fields:["uuid","profile_name"],listeners:{load:{scope:this,fn:this.onAvailableUserdirPHPLoad}}}),validator:this.validatorPHP.createDelegate(this),allowBlank:false,tpl:'<tpl for="."><div ext:qtip="{profile_name}" class="x-combo-list-item">{profile_name}</div></tpl>'});return a},addToolTip:function(){var a=this.getForm().findField("userdir");SYNO.SDS.Utils.AddTip(a.getEl(),_TT("SYNO.SDS.WebStation.Application","default","install_apache_for_enable_userdir_tips"))},userHomeCheckHandler:function(){var a=this.status_data.home_share_status;if(a===SYNO.SDS.WebStation.Util.HomeShareStatus.StatusNotEnable){this.getForm().findField("userdir").reset();this.appWin.getMsgBox().confirm(_TT("SYNO.SDS.WebStation.Application","default","userdir"),_TT("SYNO.SDS.WebStation.Application","default","userdir_warning"),function(b){if("yes"===b){SYNO.SDS.AppLaunch("SYNO.SDS.AdminCenter.Application",Ext.apply({fn:"SYNO.SDS.AdminCenter.User.Main",userHomeDialog:true}))}},this)}else{if(a===SYNO.SDS.WebStation.Util.HomeShareStatus.StatusIsEncrypted){this.getForm().findField("userdir").reset();this.appWin.getMsgBox().confirm(_TT("SYNO.SDS.WebStation.Application","default","userdir"),_TT("SYNO.SDS.WebStation.Application","default","userdir_encrypt_warning"),function(b){if("yes"===b){SYNO.SDS.AppLaunch("SYNO.SDS.AdminCenter.Application",Ext.apply({fn:"SYNO.SDS.AdminCenter.Share.Main"}))}},this)}else{if(this.home_share_data.hasOwnProperty("is_cold_storage_share")&&this.home_share_data.is_cold_storage_share){this.getForm().findField("userdir").reset();this.appWin.getMsgBox().alert(_TT("SYNO.SDS.WebStation.Application","default","userdir"),_TT("SYNO.SDS.WebStation.Application","default","userdir_pata_warning"))}else{return true}}}return false},processParams:function(e,c){this.callParent(arguments);var a={api:this.webapiStatus.api,method:this.webapiStatus.methods.get,version:this.webapiStatus.version};c.push(a);var b={api:this.webapiPHPProfile.api,method:this.webapiPHPProfile.methods.get,version:this.webapiPHPProfile.version};c.push(b);var d={api:this.webapiHomeService.api,method:this.webapiHomeService.methods.get,params:{additional:["is_cold_storage_share"],name:"homes"},version:this.webapiHomeService.version};c.push(d);return c},handleUserdirEnableStatus:function(b){var a=["userdir_backend","userdir_php"];a.forEach(function(c){var d=this.getForm().findField(c);if(d.disabled===b){d.setDisabled(!b)}},this)},processReturnData:function(b,f,d){this.appWin.clearStatusBusy();this.el.unmask();if(f.has_fail){var k=f.result.filter(function(l){return !l.success});var i=k.find(function(l){return l.api==="SYNO.Core.Share"});var e=i&&i.error.code===402;if(!e||k.length>1){this.errorHandling(k[0].error.code);return}}var h={api:this.webapiStatus.api,method:this.webapiStatus.methods.get,version:this.webapiStatus.version};this.status_data=SYNO.SDS.WebStation.Util.getSuccessRespCompoundData(h,f);var j={api:this.webapiHomeService.api,method:this.webapiHomeService.methods.get,version:this.webapiHomeService.version};this.home_share_data=SYNO.SDS.WebStation.Util.getSuccessRespCompoundData(j,f);var a={api:this.webapiPHPProfile.api,method:this.webapiPHPProfile.methods.get,version:this.webapiPHPProfile.version};this.profile_list=SYNO.SDS.WebStation.Util.getSuccessRespCompoundData(a,f);var g=this.getForm().findField("userdir");this.getForm().loadRecords(f.result,d.compound);if(this.status_data.home_share_status===SYNO.SDS.WebStation.Util.HomeShareStatus.StatusBackendNotExist){g.disable()}else{g.enable();this.handleUserdirEnableStatus(g.getValue())}var c=this.status_data.available_server_backend;this.serverData=c.map(function(l){return[l,SYNO.SDS.WebStation.Util.BackendMap.server[l]]});this.userdirServerData=c.filter(function(l){return l!==0}).map(function(l){return[l,SYNO.SDS.WebStation.Util.BackendMap.server[l]]});this.phpData=[[null,_TT("SYNO.SDS.WebStation.Application","default","php_not_configured")]].concat(this.profile_list.profiles.map(function(l){return[l.uuid,l.profile_name+" ( "+SYNO.SDS.WebStation.Util.BackendMap.php[l.backend]+" )"]}));[{field:"backend",data:this.serverData},{field:"php",data:this.phpData},{field:"userdir_backend",data:this.userdirServerData},{field:"userdir_php",data:this.phpData}].forEach(function(l){this.getForm().findField(l.field).getStore().loadData(l.data)},this)},onPageActivate:function(){this.loadForm()},onAvailableDefaultServerLoad:function(b,a){var c=this.getForm().findField("backend");this.onAvailableServerLoad(b,a,c)},onAvailableUserdirServerLoad:function(b,a){var c=this.getForm().findField("userdir_backend");this.onAvailableServerLoad(b,a,c)},onAvailableServerLoad:function(c,b,f){var e=f.getValue();for(var d=0;d<b.length;d++){if(b[d].get("backend_id")===e){f.reset();return 0}}if(f.disabled){var a=b.length?b[0].get("backend_id"):"";f.setValue(a)}else{f.clearValue()}f.validate()},onAvailableDefaultServerPHPLoad:function(b,a){var c=this.getForm().findField("php");this.onAvailablePHPLoad(b,a,c)},onAvailableUserdirPHPLoad:function(b,a){var c=this.getForm().findField("userdir_php");this.onAvailablePHPLoad(b,a,c)},onAvailablePHPLoad:function(b,a,e){var d=e.getValue();if(d==="nan"){e.reset();return 0}for(var c=0;c<a.length;c++){if(a[c].get("uuid")===d){e.reset();return 0}}e.clearValue();e.validate()},validatorBackend:function(a){return this.validatorComboBox(a,this.serverData)},validatorPHP:function(a){return this.validatorComboBox(a,this.phpData)},validatorComboBox:function(b,a){if(!a){return true}var c=false;a.forEach(function(e){if(e[1]===b){c=true}},c);if(c){return true}return _TT("SYNO.SDS.WebStation.Application","error","err_backend_not_found")},errorHandling:function(a){this.appWin.getMsgBox().alert(this.title,SYNO.API.getErrorString(a))}});Ext.define("SYNO.SDS.WebStation.Web.PHPAdvancedSetting",{extend:"SYNO.SDS.ModalWindow",constructor:function(a){this.module=a.module;this.owner=a.owner;this.default_settings=a.default_settings;this.available_php_backend=a.available_php_backend;this.webapi=a.webapi;var b=[];this.general_settings_form=this.createGeneralSettingForm({title:_TT("SYNO.SDS.WebStation.Application","title","general_settings"),owner:this,module:this.module});this.fpm_setting_form=this.createFpmSettingForm({title:_TT("SYNO.SDS.WebStation.Application","php_advanced_setting","fpm_setting"),owner:this,module:this.module});this.core_setting_column=this.createCoreSettingColumn({title:_TT("SYNO.SDS.WebStation.Application","php_advanced_setting","core_setting"),owner:this,module:this.module});b.push(this.general_settings_form);b.push(this.fpm_setting_form);b.push(this.core_setting_column);this.callParent([Ext.apply({title:_TT("SYNO.SDS.WebStation.Application","php","php_advanced_setting"),closable:true,width:750,height:650,layout:"fit",items:[{xtype:"syno_tabpanel",itemId:"php_advanced_setting",plain:true,activeTab:0,deferredRender:false,items:b}],buttons:[{text:_T("common","ok"),btnStyle:"blue",disabled:this._S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",scope:this,handler:this.onApply},{text:_T("common","cancel"),scope:this,handler:function(){this.close()}}]},a)]);this.mon(this,"afterlayout",this.updateView,this)},setInitData:function(){this.profile={profile_name:"",profile_desc:"",backend:this.available_php_backend[0],custom_open_basedir:false,display_errors:false,enable_cache:false,enable_xdebug:false,extensions:[],fpm_settings:{mode:"dynamic",max_children:20,max_spare_servers:3,min_spare_servers:1,start_servers:2},open_basedir:"",php_settings:{}}},setData:function(a){this.profile=a},updateView:function(){this.current_backend=this.profile.backend;var a=this.general_settings_form.getForm();a.setValues(this.profile);a.clearInvalid();var b=this.fpm_setting_form.getForm();b.setValues(this.profile.fpm_settings);b.clearInvalid();this.updateSettingSimpleStore();this.updateExtensionSimpleStore();this.updateAvaliableExtensionsStore();this.updateOpenBasedDir()},updateOpenBasedDir:function(){var d=this.general_settings_form.getForm();var c=d.findField("custom_open_basedir").getValue();var b=d.findField("open_basedir");var a=d.findField("open_basedir_desc");if(c){b.enable();a.enable()}else{b.disable();a.disable()}},updateSettingSimpleStore:function(){var a=[];var e,d,g;var f=this.general_settings_form.getForm().findField("backend");var c=f.getValue();for(var b=0;b<this.default_settings.default_settings.length;b++){if(this.default_settings.default_settings[b].backend===c){g=this.default_settings.default_settings[b]}}for(e in g.core){if(g.core.hasOwnProperty(e)){d=(this.profile===undefined||this.profile.php_settings[e]===undefined)?g.core[e]:this.profile.php_settings[e];a.push([e,d])}}for(e in g.extensions){if(g.extensions.hasOwnProperty(e)){d=(this.profile===undefined||this.profile.php_settings[e]===undefined)?g.extensions[e]:this.profile.php_settings[e];a.push([e,d])}}this.php_settings_store.loadData(a)},updateExtensionSimpleStore:function(){var b=this.general_settings_form.getForm().findField("backend");var k=b.getValue();var h;var e;for(e=0;e<this.default_settings.extensions_list.length;e++){if(this.default_settings.extensions_list[e].backend===k){h=this.default_settings.extensions_list[e].extensions}}var l=[];var c,a,f,g;var m=h.length;for(e=0;e<m;e++){c=h[e];a=c.name;f=c.enable;if(this.profile!==undefined){for(var d=0;d<this.profile.extensions.length;d++){if(this.profile.extensions[d]===a){f=true;break}}}g=c.description;l.push([f,a,g])}this.extension_store.loadData(l)},updateAvaliableExtensionsStore:function(){var e;for(var b=0;b<this.default_settings.default_settings.length;b++){if(this.default_settings.default_settings[b].backend===this.current_backend){e=this.default_settings.default_settings[b]}}var d=["all","core"];for(var c in e.extensions){if(e.extensions.hasOwnProperty(c)){if(c.indexOf(".")<0){continue}var a=c.split(".")[0];if(d.indexOf(a)>=0){continue}d.push(a)}}this.available_extensions.loadData(d.map(function(f){return[f]}))},createGeneralSettingBasicFieldSets:function(){var b=[];var a=this.available_php_backend.map(function(d){return[d,SYNO.SDS.WebStation.Util.BackendMap.php[d]]});var c=new Ext.data.SimpleStore({fields:["value","display"],data:a,listeners:{update:{scope:this,fn:function(g,d,e,f){console.log(d)}}}});b.push({xtype:"syno_textfield",name:"profile_name",width:250,fieldLabel:_TT("SYNO.SDS.WebStation.Application","php","profile_name"),allowBlank:false,emptyText:"Profile Name"},{xtype:"syno_textfield",name:"profile_desc",width:250,fieldLabel:_TT("SYNO.SDS.WebStation.Application","php","profile_desc"),allowBlank:false,emptyText:"Profile Description"},{xtype:"syno_combobox",name:"backend",id:this.comboId=Ext.id(),fieldLabel:_TT("SYNO.SDS.WebStation.Application","php","version"),valueField:"value",displayField:"display",width:250,store:c,isDirty:function(){return false},listeners:{select:{scope:this,fn:function(){this.updateExtensionSimpleStore();this.updateSettingSimpleStore();this.updateAvaliableExtensionsStore()}}}},{xtype:"syno_checkbox",name:"enable_cache",boxLabel:_TT("SYNO.SDS.WebStation.Application","php","php_cache_enabled")},{xtype:"syno_checkbox",name:"enable_xdebug",boxLabel:_TT("SYNO.SDS.WebStation.Application","php","php_xdebug_enabled")},{xtype:"syno_checkbox",name:"display_errors",boxLabel:_TT("SYNO.SDS.WebStation.Application","php","php_display_errors")},{xtype:"syno_checkbox",name:"custom_open_basedir",boxLabel:_TT("SYNO.SDS.WebStation.Application","php","php_openbasedir_customize"),listeners:{check:{scope:this,fn:this.updateOpenBasedDir}}},{xtype:"syno_textfield",id:this.open_basedir=Ext.id(),name:"open_basedir",indent:1,width:400,fieldLabel:"open_basedir"},{xtype:"syno_displayfield",id:this.open_basedir_desc=Ext.id(),name:"open_basedir_desc",indent:1,value:_TT("SYNO.SDS.WebStation.Application","php","php_openbasedir_warning"),htmlEncode:false});return{xtype:"syno_fieldset",region:"north",items:b,cls:"syno-php-general-fieldset"}},createGeneralSettingExtensionsFieldSets:function(){var a=[];this.colIndexed=new SYNO.ux.EnableColumn({id:"enable",dataIndex:"enable",menuDisabled:true,bindRowClick:false,align:"center",width:60,fixed:true});this.extension_store=new Ext.data.SimpleStore({fields:["enable","name","description"],data:[]});a.push({xtype:"syno_gridpanel",cls:"without-dirty-red-grid",plugins:[this.colIndexed],colModel:new Ext.grid.ColumnModel([this.colIndexed,{header:_TT("SYNO.SDS.WebStation.Application","php","extension_name"),id:"name",dataIndex:"name",menuDisabled:true,width:90,fixed:true,resizable:true},{header:_TT("SYNO.SDS.WebStation.Application","php","extension_desc"),id:"description",dataIndex:"description",menuDisabled:true,width:200,resizable:true,renderer:function(b){return'<div ext:qtip="'+b+'">'+b+"</div>"}}]),store:this.extension_store,autoExpandColumn:"name",selModel:new Ext.grid.RowSelectionModel()});return{xtype:"syno_fieldset",title:_TT("SYNO.SDS.WebStation.Application","php","extensions"),region:"center",layout:"fit",items:a,cls:"syno-php-general-fieldset"}},createGeneralSettingForm:function(b){var a={title:"",trackResetOnLoad:true,itemId:"php_general_settings",labelWidth:275,layout:"border",items:[this.createGeneralSettingBasicFieldSets(),this.createGeneralSettingExtensionsFieldSets()]};Ext.apply(a,b);return new SYNO.ux.FormPanel(a)},createCoreSettingColumnModel:function(){return new Ext.grid.ColumnModel([{header:_TT("SYNO.SDS.WebStation.Application","php","extension_name"),sortable:true,width:"15px",dataIndex:"name",align:"left"},{header:_TT("SYNO.SDS.WebStation.Application","php_advanced_setting","value"),dataIndex:"value",align:"center",editor:{xtype:"syno_textfield",allowBlank:true}}])},createCoreSettingSearchFilter:function(a){return new SYNO.ux.TextFilter({iconStyle:"filter",itemId:"search",emptyText:_TT("SYNO.SDS.WebStation.Application","php_advanced_setting","search"),store:a,localFilter:true,localFilterField:["name"],blOr:true})},createCoreSettingSearchComboBox:function(a){return{xtype:"syno_combobox",name:"extension_name",fieldLabel:"",displayField:"extension_name",valueField:"extension_name",store:this.available_extensions,value:"all",listeners:{scope:this,select:function(g,c,d,f){var e=c.get("extension_name");if(e==="all"&&a.isFiltered()){a.clearFilter();return}var b;if(e==="core"){b=new RegExp("[^.]","g")}else{b=new RegExp("^"+e+"\\.","g")}a.filter([{property:"name",value:b}])}}}},createCoreSettingColumn:function(d){this.php_settings_store=new Ext.data.SimpleStore({fields:["name","value"],data:[]});this.available_extensions=new Ext.data.SimpleStore({fields:["extension_name"],data:[]});var a=this.createCoreSettingColumnModel();var e=this.createCoreSettingSearchFilter(this.php_settings_store);var b=this.createCoreSettingSearchComboBox(this.php_settings_store);var c={cm:a,ds:this.php_settings_store,tbar:{items:[b,"->",e]},enableHdMenu:false,enableColumnMove:false,clicksToEdit:1};Ext.apply(c,d);return new SYNO.ux.EditorGridPanel(c)},createFpmSettingForm:function(b){var c=new Ext.data.SimpleStore({fields:["mode","value"],data:[[_TT("SYNO.SDS.WebStation.Application","php_advanced_setting","fpm_mode_static"),"static"],[_TT("SYNO.SDS.WebStation.Application","php_advanced_setting","fpm_mode_dynamic"),"dynamic"],[_TT("SYNO.SDS.WebStation.Application","php_advanced_setting","fpm_mode_ondemand"),"ondemand"]]});var a={title:"",trackResetOnLoad:true,itemId:"php_fpm_settings",labelWidth:275,items:[{xtype:"syno_combobox",name:"mode",fieldLabel:_TT("SYNO.SDS.WebStation.Application","php_advanced_setting","fpm_process_mode"),displayField:"mode",valueField:"value",store:c},{xtype:"syno_numberfield",name:"max_children",maxlength:64,fieldLabel:_TT("SYNO.SDS.WebStation.Application","php_advanced_setting","fpm_max_children"),allowBlank:false,minValue:1,validator:this.validateMaxChildren.bind(this),validateOnBlur:false},{xtype:"syno_numberfield",name:"start_servers",maxlength:64,fieldLabel:_TT("SYNO.SDS.WebStation.Application","php_advanced_setting","fpm_start_servers"),allowBlank:false,minValue:1,validator:this.validateStartServers.bind(this)},{xtype:"syno_numberfield",name:"min_spare_servers",maxlength:64,fieldLabel:_TT("SYNO.SDS.WebStation.Application","php_advanced_setting","fpm_min_spare_servers"),allowBlank:false,minValue:1,validator:this.validateMinSpareServers.bind(this)},{xtype:"syno_numberfield",name:"max_spare_servers",maxlength:64,fieldLabel:_TT("SYNO.SDS.WebStation.Application","php_advanced_setting","fpm_max_spare_servers"),allowBlank:false,minValue:1,validator:this.validateMaxSpareServers.bind(this)}]};Ext.apply(a,b);return new SYNO.ux.FormPanel(a)},validateMaxChildren:function(a){a=parseInt(a,10);var b=this.fpm_setting_form.getForm().getFieldValues(false);if(b.mode!=="dynamic"){return true}if(b.min_spare_servers>=a){return _TT("SYNO.SDS.WebStation.Application","error","err_fpm_less_min_spare")}if(b.max_spare_servers>=a){return _TT("SYNO.SDS.WebStation.Application","error","err_fpm_less_max_spare")}return true},validateStartServers:function(a){a=parseInt(a,10);var b=this.fpm_setting_form.getForm().getFieldValues(false);if(b.mode!=="dynamic"){return true}if(b.min_spare_servers>a){return _TT("SYNO.SDS.WebStation.Application","error","err_fpm_less_min_spare")}if(b.max_spare_servers<a){return _TT("SYNO.SDS.WebStation.Application","error","err_fpm_larger_max_spare")}return true},validateMinSpareServers:function(a){a=parseInt(a,10);var b=this.fpm_setting_form.getForm().getFieldValues(false);if(b.mode!=="dynamic"){return true}if(b.start_servers<a){return _TT("SYNO.SDS.WebStation.Application","error","err_fpm_larger_start_servers")}if(b.max_children<=a){return _TT("SYNO.SDS.WebStation.Application","error","err_fpm_larger_max_children")}return true},validateMaxSpareServers:function(a){a=parseInt(a,10);var b=this.fpm_setting_form.getForm().getFieldValues(false);if(b.mode!=="dynamic"){return true}if(b.start_servers>a){return _TT("SYNO.SDS.WebStation.Application","error","err_fpm_less_start_servers")}if(b.max_children<=a){return _TT("SYNO.SDS.WebStation.Application","error","err_fpm_larger_max_children")}return true},sendRequest:function(){var g=this.general_settings_form.getForm();if(!g.isValid()){this.clearStatusBusy();return}var d=g.getFieldValues(false);var e={uuid:this.profile.uuid,profile_name:d.profile_name,profile_desc:d.profile_desc,backend:d.backend,custom_open_basedir:d.custom_open_basedir,display_errors:d.display_errors,enable_cache:d.enable_cache,enable_xdebug:d.enable_xdebug};if(d.custom_open_basedir){e.open_basedir=d.open_basedir}else{e.open_basedir=""}var h=this.fpm_setting_form.getForm();var f=h.getFieldValues(false);if(!h.isValid()||!this.validateStartServers()||!this.validateMaxChildren()){this.clearStatusBusy();this.setStatusError({text:_TT("SYNO.SDS.WebStation.Application","error","err_fpm_settings_invalid")});return}e.fpm_settings=f;var c=this.profile.php_settings;var a=this.php_settings_store.getModifiedRecords();a.each(function(i){c[i.get("name")]=i.getChanges().value});e.php_settings=c;var b=[];this.extension_store.each(function(i){if(i.data.enable){b.push(i.data.name)}});e.extensions=b;this.sendWebAPI({api:this.webapi.api,method:this.webapi.method,version:this.webapi.version,scope:this,params:{profile:e},callback:function(j,i){this.clearStatusBusy();this.fireEvent("close");this.close()}})},onApply:function(){this.setStatusBusy();this.sendRequest()}});Ext.define("SYNO.SDS.WebStation.PHPProfileTab",{extend:"SYNO.ux.GridPanel",constructor:function(a){this.module=a.module;this.appWin=a.appWin;this.owner=a.owner;this.store=new SYNO.API.JsonStore({api:"SYNO.WebStation.PHP.Profile",version:1,method:"list",root:"profiles",totalProperty:"total",fields:["profile_name",{name:"backend",convert:this.converterPHPBackend},"profile_desc"],idProperty:"uuid",appWindow:this.owner,autoDestroy:true,listeners:{beforeload:{scope:this,fn:this.onStoreBeforeLoaded},load:{scope:this,fn:this.onStoreLoaded}}});var b=this.fillConfig(a);this.callParent([b]);this.mon(SYNO.SDS.StatusNotifier,"thirdpartychanged",this.onPkgChanged,this)},fillConfig:function(a){return Ext.apply({title:"",tbar:{xtype:"syno_toolbar",defaultType:"syno_button",items:this.getActionGroup().getArray()},columns:[{dataIndex:"profile_name",header:_TT("SYNO.SDS.WebStation.Application","php","profile_name"),align:"left",sortable:true},{dataIndex:"backend",header:_TT("SYNO.SDS.WebStation.Application","php","version"),align:"left",sortable:true},{dataIndex:"profile_desc",header:_TT("SYNO.SDS.WebStation.Application","php","profile_desc"),align:"left",sortable:true}],selModel:new Ext.grid.RowSelectionModel({singleSelect:false,listeners:{selectionchange:{scope:this,fn:this.onSelectionChange}}}),viewConfig:{forceFit:true},enableHdMenu:false,enableColumnMove:false,enableColLock:false,sortable:true,listeners:{rowdblclick:{scope:this,fn:this.onRowDblclick},rowcontextmenu:{scope:this,fn:this.onRowContextMenu},containercontextmenu:{scope:this,fn:this.onContainerContextMenu}}},a)},createHandler:function(){this.busy();this.sendWebAPI({api:"SYNO.WebStation.PHP",method:"get",version:1,scope:this,params:{},callback:function(a,b){this.sendWebAPI({api:"SYNO.WebStation.Status",method:"get",version:1,scope:this,callback:function(e,d){var c=new SYNO.SDS.WebStation.Web.PHPAdvancedSetting({owner:this.appWin,module:this,default_settings:b,available_php_backend:d.available_php_backend,webapi:{api:"SYNO.WebStation.PHP.Profile",method:"add",version:1},listeners:{close:this.webapiDone,scope:this}});c.setInitData();c.show()}})}})},editHandler:function(){var a=this.getSelectionModel().getSelections();if(a.length!==1){return}this.busy();this.sendWebAPI({api:"SYNO.WebStation.PHP",method:"get",version:1,scope:this,params:{},callback:function(b,c){this.sendWebAPI({api:"SYNO.WebStation.Status",method:"get",version:1,scope:this,callback:function(f,e){var d=new SYNO.SDS.WebStation.Web.PHPAdvancedSetting({owner:this.appWin,module:this,default_settings:c,available_php_backend:e.available_php_backend,webapi:{api:"SYNO.WebStation.PHP.Profile",method:"update",version:1},listeners:{close:this.webapiDone,scope:this}});d.setData(a[0].json);d.show()}})}})},deleteHandler:function(){var b=this.getSelectionModel(),a=b.getSelections();if(!a.length){return}this.owner.getMsgBox().confirmDelete(_TT("SYNO.SDS.WebStation.Application","title","vhost"),_T("common","remove_cfrmrmv"),function(d){if("yes"!==d){return}this.busy();var c=[];if(a.length===1){b.selectNext()}Ext.each(a,function(e){this.store.remove(e);c.push(e.json.uuid)},this);this.sendWebAPI({api:"SYNO.WebStation.PHP.Profile",method:"delete",version:1,params:{uuids:c},scope:this,callback:this.webapiDone})},this)},onPkgChanged:function(a,b){this.store.load()},onPageActivate:function(){this.store.load()},onStoreBeforeLoaded:function(a,b,c){this.busy()},onStoreLoaded:function(c,b,d,e){var a=this.getSelectionModel().getSelections().length,f=this.getActionGroup();if(a===0){f.disable("delete");f.disable("edit")}this.sendWebAPI({api:"SYNO.WebStation.Status",method:"get",version:1,scope:this,callback:function(h,g){this.unbusy();if(g.available_php_backend===null){this.el.mask(_TT("SYNO.SDS.WebStation.Application","php","php_no_backend"),"syno-ux-mask-info")}}});return},onSelectionChange:function(b,c){var a=b.getSelections().length,d=this.getActionGroup();if(a===0){d.disable("delete");d.disable("edit")}else{d.enable("delete");if(a===1){d.enable("edit")}else{d.disable("edit")}}},onRowDblclick:function(b,d,c,a){this.editHandler()},onRowContextMenu:function(b,g,c,a){var d=new SYNO.ux.Menu({autoDestroy:true,items:this.getActionGroup().getArray()}),f=this.getSelectionModel();f.selectRow(g,f.isSelected(g));d.showAt(c.getXY());c.preventDefault()},onContainerContextMenu:function(b,c,a){var d=new SYNO.ux.Menu({autoDestroy:true,items:this.getActionGroup().getArray()});d.showAt(c.getXY());c.preventDefault()},busy:function(){this.el.mask(_T("common","loading"),"x-mask-loading")},unbusy:function(){this.el.unmask()},webapiDone:function(c,b,a){this.unbusy();this.store.load()},converterPHPBackend:function(b,a){if(b in SYNO.SDS.WebStation.Util.BackendMap.php){return SYNO.SDS.WebStation.Util.BackendMap.php[b]}},getActionGroup:function(){if(this.actionGroup){return this.actionGroup}this.actionGroup=new SYNO.SDS.Utils.ActionGroup([new Ext.Action({text:_T("common","create"),itemId:"create",disabled:this._S("demo_mode"),scope:this,handler:this.createHandler}),new Ext.Action({text:_T("common","alt_edit"),itemId:"edit",scope:this,handler:this.editHandler}),new Ext.Action({text:_T("common","delete"),itemId:"delete",scope:this,handler:this.deleteHandler})]);return this.actionGroup}});Ext.ns("SYNO.SDS.WebStation");Ext.define("SYNO.SDS.WebStation.Application",{extend:"SYNO.SDS.AppInstance",appWindowName:"SYNO.SDS.WebStation.Main"});Ext.define("SYNO.SDS.WebStation.WelcomePage",{extend:"SYNO.SDS.ModalWindow",constructor:function(a){this.callParent([this.fillConfig(a)])},fillConfig:function(a){var b={width:450,height:205,title:_TT("SYNO.SDS.WebStation.Application","welcomepage","title"),closable:true,items:[{xtype:"syno_formpanel",itemId:"WebStationWelcomePage",items:[{xtype:"syno_displayfield",hideLabel:true,value:_TT("SYNO.SDS.WebStation.Application","welcomepage","tips")},{name:"noAutoLaunch",xtype:"syno_checkbox",checked:SYNO.SDS.UserSettings.getProperty("SYNO.SDS.WebStation.Application","nolaunch")||false,boxLabel:_TT("SYNO.SDS.WebStation.Application","welcomepage","no_tip_again")}]}],fbar:{toolbarCls:"x-panel-fbar x-statusbar",items:[{xtype:"syno_button",text:_T("common","ok"),btnStyle:"blue",handler:this.saveSettings,scope:this}]}};Ext.apply(b,a);return b},getSettingForm:function(){return this.getComponent("WebStationWelcomePage")},getNoLaunchField:function(){return this.getSettingForm().getForm().findField("noAutoLaunch")},saveSettings:function(){var a=this.getNoLaunchField().getValue();SYNO.SDS.UserSettings.setProperty("SYNO.SDS.WebStation.Application","nolaunch",a);this.close()}});Ext.define("SYNO.SDS.WebStation.Main",{extend:"SYNO.SDS.PageListAppWindow",activePage:"SYNO.SDS.WebStation.Status",width:990,minWidth:880,height:580,minHeight:580,constructor:function(a){this.appInstance=a.appInstance;var b;b=Ext.apply({width:this.width,height:this.height,listItems:[{text:_TT("SYNO.SDS.WebStation.Application","common","status"),fn:"SYNO.SDS.WebStation.Status",iconCls:"syno-webstation-overview"},{text:_TT("SYNO.SDS.WebStation.Application","helptoc","general_settings"),fn:"SYNO.SDS.WebStation.Default"},{text:_TT("SYNO.SDS.WebStation.Application","title","php_settings"),fn:"SYNO.SDS.WebStation.PHPProfileTab",iconCls:"syno-webstation-php"},{text:_TT("SYNO.SDS.WebStation.Application","title","vhost"),fn:"SYNO.SDS.WebStation.VHostTab",iconCls:"syno-webstation-vhost"}]},a);this.callParent([b]);this.mon(this,"show",this.showWelcome,this,{single:true})},showWelcome:function(){this.selectPage("SYNO.SDS.WebStation.Status");if(true!==SYNO.SDS.UserSettings.getProperty("SYNO.SDS.WebStation.Application","nolaunch")){var a=new SYNO.SDS.WebStation.WelcomePage({owner:this});a.show()}}});