iobroker.backitup
Version:
ioBroker.backitup allows you to backup and restore your ioBroker installation and other systems, such as databases, Zigbee, scripts and many more.
1 lines • 1.71 MB
JavaScript
import{o as Ve,g as yM,c as DM,a as dM}from"./defaultTheme-007y2GZo.js";import{a as n,b as De,c as Ie,_ as Ya,f as Bu,k as Gu,e as Fu,i as pe,l as Hu,m as zM,n as $i,d as Vu,o as Qa,j as Zu,p as Xu}from"./ConfigCustomBackItUpSet__loadShare__react__loadShare__.js-PbBEGjBn.js";import{y as Xi,z as Ua,x as At,c as ze,d as Ce,e as Oe,A as Jt,a as V,b as ae,g as Ee,h as X,B as Pr,C as $,D as P,i as le,E as ss,l as Ke,m as ee,F as Ku,G as qu,H as Ns,I as eN,o as va,w as ce,J as Qt,K as at,L as tN,M as Ut,f as sN,j as Ct,k as Cs,N as ba,O as vt,P as IM,Q as yi,R as wM,S as hM,T as iN,U as rN,V as ne,W as Lr,X as oN,s as $a,v as Ze,u as CM,Y as MN,Z as AM,t as nN}from"./ConfigCustomBackItUpSet__loadShare___mf_0_mui_mf_1_material__loadShare__.js-DqH6EEuz.js";import{i as Wr,h as Te,k as $e,l as Nt,m as aN,n as Pi,o as cN,p as xo,q as ko,r as Yo,s as zs,_ as Qo,t as Ki,u as Uo,v as uN,w as NN,x as Pa,y as lN,z as vo,A as LN,B as jN,C as Zs,D as gN,E as TN,F as yN,G as DN,H as dN,I as zN,J as IN,K as wN,L as hN,M as Wa,N as Ra,O as Wi,P as CN,Q as Ja,R as AN,S as mN,T as pN,U as Ba,V as ON,W as EN,X as Rr,Y as _N,Z as fN,$ as SN,a0 as xN,a1 as kN,a2 as Jr,a3 as YN,a4 as QN,a5 as UN,a6 as vN,a7 as Di,a8 as bN,a9 as $N,aa as PN,ab as WN,ac as RN,ad as JN,ae as BN,a as GN,af as FN,ag as HN,ah as VN,ai as ZN,aj as ci,ak as XN,al as KN,e as qN,am as el,an as tl,ao as sl}from"./ConfigCustomBackItUpSet__loadShare___mf_0_mui_mf_1_icons_mf_2_material__loadShare__.js-CQvVIJ-2.js";import{C as il,D as Ga,u as rl}from"./index-CIxckz69.js";function ol(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}import{u as Ml}from"./useTheme-BJvXTe_2.js";import{G as J,h as nl,i as al,j as cl,k as ul,l as Nl,m as ll,n as Ll,o as jl,p as gl,q as Tl,r as yl,s as Dl,t as dl,u as zl,v as Il,w as wl,x as mM,y as hl,z as Cl,A as Al}from"./index-B4kfzNee.js";import"./useTheme-VSAXF632.js";import"./ConfigCustomBackItUpSet__loadShare___mf_0_emotion_mf_1_react__loadShare__.js-DG2MT8MH.js";const jr=11/23/100;function pM(r){const e={r:0,g:0,b:0};if(r.length===7)e.r=parseInt(r.substring(1,3),16),e.g=parseInt(r.substring(3,5),16),e.b=parseInt(r.substring(5,7),16);else if(r.length===4){const t=r[1],s=r[2],i=r[3];e.r=parseInt(t+t,16),e.g=parseInt(s+s,16),e.b=parseInt(i+i,16)}return e}function ml(r){return`#${Math.round(r.r).toString(16)}${Math.round(r.g).toString(16)}${Math.round(r.b).toString(16)}`}function pl(r,e,t){const s=pM(r),i=pM(e);return s.r+=i.r*(.05+jr*(t-1)),s.g+=i.g*(.05+jr*(t-1)),s.b+=i.b*(.05+jr*(t-1)),ml(s)}function gr(r,e){const t={};for(let s=1;s<=24;s++)t[`elevation${s}`]={backgroundColor:pl(r,e,s)};return t}function Ol(r,e){var M,a,u,N,l,c,L,j,g,y,d;let t,s;r==="dark"?(s={MuiAppBar:{colorDefault:{backgroundColor:"#272727"}},MuiLink:{root:{textTransform:"uppercase",transition:"color .3s ease",color:Ve[200],"&:hover":{color:Ve[100]}}},MuiPaper:gr("#121212","#fff")},t={name:r,palette:{mode:"dark",background:{paper:"#121212",default:"#121212"},primary:{main:"#4dabf5"},secondary:{main:"#436a93"},expert:"#14bb00",text:{primary:"#ffffff",secondary:"#ffffff"}}}):r==="blue"?(s={MuiAppBar:{colorDefault:{backgroundColor:"#3399CC"}},MuiLink:{root:{textTransform:"uppercase",transition:"color .3s ease",color:Ve[400],"&:hover":{color:Ve[300]}}}},t={name:r,palette:{mode:"dark",background:{paper:"#151d21",default:"#151d21"},primary:{main:"#4dabf5"},secondary:{main:"#436a93"},expert:"#14bb00",text:{primary:"#ffffff",secondary:"#ffffff"}}}):r==="colored"?(s={MuiAppBar:{colorDefault:{backgroundColor:"#2a3135"}},MuiLink:{root:{textTransform:"uppercase",transition:"color .3s ease",color:Ve[200],"&:hover":{color:Ve[100]}}},MuiPaper:gr("#151d21","#fff")},t={name:r,palette:{mode:"light",primary:{main:"#3399CC"},secondary:{main:"#164477"},expert:"#96fc96"}}):r==="PT"?(s={MuiAppBar:{colorDefault:{backgroundColor:"#0F99DE"}},MuiLink:{root:{textTransform:"uppercase",transition:"color .3s ease",color:Ve[400],"&:hover":{color:Ve[300]}}}},t={name:r,palette:{mode:"light",primary:{main:"#0F99DE"},secondary:{main:"#88A536"},expert:"#BD1B24"}}):r==="NW"?(s={MuiAppBar:{colorDefault:{backgroundColor:"#272727"}},MuiLink:{root:{textTransform:"uppercase",transition:"color .3s ease",color:Ve[400],"&:hover":{color:Ve[300]}}},MuiPaper:gr("#121212","#fff")},t={name:r,palette:{mode:"dark",background:{paper:"#121212",default:"#121212"},primary:{main:"#00af78"},secondary:{main:"#005a40"},expert:"#14bb00",text:{primary:"#ffffff",secondary:"#ffffff"}}}):(s={MuiLink:{root:{textTransform:"uppercase",transition:"color .3s ease",color:Ve[400],"&:hover":{color:Ve[300]}}}},t={name:r,palette:{mode:"light",primary:{main:"#3399CC",dark:"#256c97",light:"#76d0fd"},secondary:{main:"#164477"},expert:"#14bb00"}}),t.toolbar={height:48},t.saveToolbar={background:(a=(M=t.palette)==null?void 0:M.primary)==null?void 0:a.main,button:{borderRadius:3,height:32}},t.palette&&(t.palette.grey={main:yM[300],dark:yM[400]});const i=DM(t),o=i.palette;return DM(i,{...e||void 0,components:{...s,MuiButton:{variants:[{props:{variant:"contained",color:"grey"},style:{backgroundColor:(u=o.grey)==null?void 0:u[300],color:o.getContrastText&&((N=o.grey)!=null&&N[300])?o.getContrastText(o.grey[300]):void 0}},{props:{variant:"outlined",color:"grey"},style:{color:(l=o.text)==null?void 0:l.primary,borderColor:o.mode==="light"?"rgba(0, 0, 0, 0.23)":"rgba(255, 255, 255, 0.23)","&.Mui-disabled":{border:`1px solid ${(c=o.action)==null?void 0:c.disabledBackground}`},"&:hover":{borderColor:o.mode==="light"?"rgba(0, 0, 0, 0.23)":"rgba(255, 255, 255, 0.23)",backgroundColor:dM(((L=o.text)==null?void 0:L.primary)||"",((j=o.action)==null?void 0:j.hoverOpacity)||.04)}}},{props:{variant:"text",color:"grey"},style:{color:(g=o.text)==null?void 0:g.primary,"&:hover":{backgroundColor:dM(((y=o.text)==null?void 0:y.primary)||"",((d=o.action)==null?void 0:d.hoverOpacity)||.04)}}}]},...(e==null?void 0:e.components)||void 0}})}function El(){let r,e;const t=new Promise((s,i)=>{r=s,e=i});return t.resolve=r,t.reject=e,t}function Br(r){return(r==null?void 0:r.rows.map(e=>e.value).filter(e=>!!e))??[]}function wt(r){return r!=null&&r.startsWith("system.host.")||(r=`system.host.${r}`),r}function $s(r){return r!=null&&r.startsWith("system.host.")&&(r=r.substring(12)),r}function OM(r){return new Promise(e=>{setTimeout(e,r)})}function di(r){r=(r||"").toString();const e=r[0]==="*",t=r[r.length-1]==="*";return r=r.replace(/[-/\\^$+?.()|[\]{}]/g,"\\$&").replace(/\*/g,".*"),(e?"":"^")+r+(t?"":"$")}typeof globalThis.process<"u"&&(globalThis.location||={href:"http://localhost:8081/",protocol:"http:",host:"localhost:8081",pathname:"/",hostname:"localhost",reload:()=>{}},globalThis.localStorage||={_keys:{},setItem:(r,e)=>{globalThis.localStorage._keys[r]=e},getItem:r=>r in globalThis.localStorage._keys?globalThis.localStorage._keys[r]:null,removeItem:r=>{r in globalThis.localStorage._keys&&delete globalThis.localStorage._keys[r]}},globalThis.sessionStorage||=globalThis.localStorage,globalThis.navigator||={language:"en"});var ct;(function(r){r[r.CONNECTING=0]="CONNECTING",r[r.CONNECTED=1]="CONNECTED",r[r.OBJECTS_LOADED=2]="OBJECTS_LOADED",r[r.READY=3]="READY"})(ct||(ct={}));var ke;(function(r){r.PERMISSION_ERROR="permissionError",r.NOT_CONNECTED="notConnectedError",r.TIMEOUT="timeout",r.NOT_ADMIN="Allowed only in admin",r.NOT_SUPPORTED="Not supported"})(ke||(ke={}));const $je=ke.PERMISSION_ERROR;ke.NOT_CONNECTED;const _l=["material","echarts","vis"];class fe{props;connId;lastAccessToken=null;ignoreState="";connected=!1;subscribed=!1;firstConnect=!0;waitForRestart=!1;loaded=!1;simStates={};objectViewCached;constructor(e){this.props=this.applyDefaultProps(e),this.connId=`${this.props.name?`${this.props.name}-`:""}${Math.round(Math.random()*1e6).toString().padStart(6,"0")}`,this.waitForSocketLib().then(()=>this.startSocket()).catch(t=>{alert(`Socket connection could not be initialized: ${t}`)})}applyDefaultProps(e){return{...e,protocol:e.protocol||globalThis.location.protocol,host:e.host||globalThis.location.hostname,port:e.port||(globalThis.location.port==="3000"?8081:globalThis.location.port),ioTimeout:Math.max(e.ioTimeout||2e4,2e4),cmdTimeout:Math.max(e.cmdTimeout||5e3,5e3),admin5only:e.admin5only||!1,autoSubscribes:e.autoSubscribes??[],autoSubscribeLog:e.autoSubscribeLog??!1,doNotLoadACL:e.doNotLoadACL??!0,doNotLoadAllObjects:e.doNotLoadAllObjects??!0}}statesSubscribes={};filesSubscribes={};objectsSubscribes={};objects={};states={};acl=null;isSecure=!1;onReadyDone=!1;onConnectionHandlers=[];onLogHandlers=[];onCmdStdoutHandler;onCmdStderrHandler;onCmdExitHandler;onError(e){(this.props.onError??console.error)(e)}_socket;_waitForSocketPromise;_waitForFirstConnectionPromise=El();_instanceSubscriptions={};_promises={};_authTimer=null;_refreshTimer=null;_systemConfig;get systemConfig(){return this._systemConfig}systemLang="en";static isWeb(){return globalThis.socketUrl!==void 0}waitForSocketLib(){return this._waitForSocketPromise?this._waitForSocketPromise:(this._waitForSocketPromise=new Promise(async(e,t)=>{if(this.props.connect){e();return}if(typeof globalThis.io>"u"&&typeof globalThis.iob>"u")if(typeof globalThis.registerSocketOnLoad=="function")globalThis.registerSocketOnLoad(()=>e());else{for(let s=1;s<=30;s++){if(globalThis.io||globalThis.iob)return e();await OM(100)}t(new Error("Socket library could not be loaded!"))}else e()}),this._waitForSocketPromise)}async startSocket(){if(this._socket)return;let e=this.props.host,t=this.props.port,s=(this.props.protocol||globalThis.location.protocol).replace(":",""),i=globalThis.location.pathname;if(globalThis.location.hostname==="iobroker.net"||globalThis.location.hostname==="iobroker.pro")i="";else{if(globalThis.socketUrl){const u=new globalThis.URL(globalThis.socketUrl);e=u.hostname,t=u.port,s=u.protocol.replace(":","")}const a=i.lastIndexOf("/");if(a!==-1&&(i=i.substring(0,a+1)),fe.isWeb()){const u=i.split("/");u.length>2&&(u.pop(),u.pop(),_l.includes(u[u.length-1])&&u.pop(),i=u.join("/"),i.endsWith("/")||(i+="/"))}}const o=t?`${s}://${e}:${t}`:`${s}://${e}`,M=this.props.connect||(globalThis.io||globalThis.iob).connect;return this._socket=M(o,{path:i.endsWith("/")?`${i}socket.io`:`${i}/socket.io`,query:"ws=true",name:this.props.name,timeout:this.props.ioTimeout,uuid:this.props.uuid,token:this.props.token}),this._socket.on("connect",a=>{var N;(N=globalThis.addEventListener)==null||N.call(globalThis,"storage",this.onAccessTokenUpdated);const u=fe.readTokens();if(u&&!u.owner){const l=Date.now();this.saveTokens({access_token:u.access_token,refresh_token:u.refresh_token,expires_in:Math.round((u.expires_in.getTime()-l)/1e3),refresh_token_expires_in:Math.round((u.refresh_token_expires_in.getTime()-l)/1e3),token_type:"Bearer"},u.stayLoggedIn)}this.onReadyDone=!1,a!==!0?(this.connected=!0,setTimeout(()=>this.getVersion().then(l=>{const[c,L,j]=l.version.split(".");parseInt(c,10)*1e4+parseInt(L,10)*100+parseInt(j,10)<40102?(this._authTimer=null,this.onPreConnect(!1,!1)):this._socket.emit("authenticate",(y,d)=>this.onPreConnect(y,d))}).catch(l=>this.onError({message:l.toString(),operation:"getVersion"})),500)):this._socket.emit("authenticate",(l,c)=>{this.onPreConnect(l,c)})}),this._socket.on("reconnect",()=>{var a,u;this.onReadyDone=!1,(u=(a=this.props).onProgress)==null||u.call(a,ct.READY),this.connected=!0,this.waitForRestart?globalThis.location.reload():(this._subscribe(!0),this.onConnectionHandlers.forEach(N=>N(!0)))}),this._socket.on("disconnect",()=>{var a,u;this.onReadyDone=!1,this.connected=!1,this.subscribed=!1,(u=(a=this.props).onProgress)==null||u.call(a,ct.CONNECTING),this.onConnectionHandlers.forEach(N=>N(!1))}),this._socket.on("reauthenticate",()=>this.authenticate()),this._socket.on("log",a=>{var u,N;(N=(u=this.props).onLog)==null||N.call(u,a),this.onLogHandlers.forEach(l=>l(a))}),this._socket.on("error",a=>{let u;a==null?u="":typeof a.toString=="function"?u=a.toString():(u=JSON.stringify(a),console.error(`Received strange error: ${u}`)),u.includes("User not authorized")?this.authenticate():u.includes("websocket error")?(console.error(`Socket Error => reload: ${a}`),globalThis.location.reload()):console.error(`Socket Error: ${a}`)}),this._socket.on("connect_error",a=>console.error(`Connect error: ${a}`)),this._socket.on("permissionError",a=>this.onError({message:"no permission",operation:a.operation,type:a.type,id:a.id||""})),this._socket.on("objectChange",(a,u)=>{setTimeout(()=>this.objectChange(a,u),0)}),this._socket.on("stateChange",(a,u)=>{setTimeout(()=>this.stateChange(a,u),0)}),this._socket.on("im",(a,u,N)=>{setTimeout(()=>this.instanceMessage(a,u,N),0)}),this._socket.on("fileChange",(a,u,N)=>{setTimeout(()=>this.fileChange(a,u,N),0)}),this._socket.on("cmdStdout",(a,u)=>{var N;(N=this.onCmdStdoutHandler)==null||N.call(this,a,u)}),this._socket.on("cmdStderr",(a,u)=>{var N;(N=this.onCmdStderrHandler)==null||N.call(this,a,u)}),this._socket.on("cmdExit",(a,u)=>{var N;(N=this.onCmdExitHandler)==null||N.call(this,a,u)}),Promise.resolve()}onPreConnect(e,t){var s,i;this._authTimer&&(clearTimeout(this._authTimer),this._authTimer=null),this.connected=!0,this.isSecure=t,this.waitForRestart?globalThis.location.reload():(this.firstConnect?this.loadData().catch(o=>{console.error(`Cannot load data: ${o}`)}):(i=(s=this.props).onProgress)==null||i.call(s,ct.READY),this._subscribe(!0),this.onConnectionHandlers.forEach(o=>o(!0)),this.checkAccessTokenExpire()),this._waitForFirstConnectionPromise.resolve()}static readTokens(){let e=globalThis.sessionStorage.getItem("iob_tokens");const t=!e;if(e||(e=globalThis.localStorage.getItem("iob_tokens")),!e)return null;const[s,i,o,M,a]=e.split(";"),u=new Date(i);return u.getTime()<Date.now()?null:{refresh_token:s,refresh_token_expires_in:u,access_token:o,expires_in:new Date(M),owner:a,stayLoggedIn:t}}static saveTokensStatic(e,t,s){const i=`${e.refresh_token};${new Date(Date.now()+e.refresh_token_expires_in*1e3).toISOString()};${e.access_token};${new Date(Date.now()+e.expires_in*1e3).toISOString()}${s?`;${s}`:""}`;t?globalThis.localStorage.setItem("iob_tokens",i):globalThis.sessionStorage.setItem("iob_tokens",i)}saveTokens(e,t){fe.saveTokensStatic(e,t,this.connId)}static deleteTokensStatic(){globalThis.localStorage.removeItem("iob_tokens"),globalThis.sessionStorage.removeItem("iob_tokens")}deleteTokens(e,t){const s=fe.readTokens();s&&(t?fe.deleteTokensStatic():s.stayLoggedIn===e&&s.owner===this.connId&&(s.stayLoggedIn?globalThis.localStorage.removeItem("iob_tokens"):globalThis.sessionStorage.removeItem("iob_tokens")))}onAccessTokenUpdated=e=>{if(e.key==="iob_tokens"){const t=fe.readTokens();t&&(console.log(`Tab ${this.connId} received updated token: ${t.access_token}`),this.updateTokenExpiration(t.access_token))}};updateTokenExpiration(e){this.lastAccessToken!==e&&(this.lastAccessToken=e,this._socket.emit("updateTokenExpiration",e,(t,s)=>{t?(console.error(`[UPDATE/${new Date().toISOString()}] cannot say to server about new token: ${t}`),globalThis.location.reload()):s?console.log(`[UPDATE/${new Date().toISOString()}] server accepted new token: ${e}`):(console.error(`[UPDATE/${new Date().toISOString()}] cannot say to server about new token`),globalThis.location.reload())})),this.checkAccessTokenExpire()}refreshTokens(e,t){if(!e){console.log(`[REFRESH/${new Date().toISOString()}] No token structure found => reloading the page`),setTimeout(()=>globalThis.location.reload(),500);return}t||!e.owner||e.owner===this.connId?(console.log(`[REFRESH/${new Date().toISOString()}] claim ownership of the token`),this.acquireTokenLock()?(console.log(`[REFRESH/${new Date().toISOString()}] refreshing token`),fetch("./oauth/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:`grant_type=refresh_token&refresh_token=${e.refresh_token}&client_id=ioBroker&stayloggedin=${e.stayLoggedIn}`}).then(s=>{if(s.ok)return s.json();throw new Error("Cannot refresh access token")}).then(s=>{if(s.access_token)console.log(`[REFRESH/${new Date().toISOString()}] received new token: ${s.access_token}`),this.saveTokens(s,e.stayLoggedIn),this.releaseTokenLock(),this.updateTokenExpiration(s.access_token);else throw new Error("Cannot get access token")}).catch(s=>{console.warn(`[REFRESH/${new Date().toISOString()}] cannot refresh token: ${s}`),this.releaseTokenLock(),this.deleteTokens(e.stayLoggedIn),console.error(s),globalThis.location.reload()})):(console.log(`[REFRESH/${new Date().toISOString()}] Someone else is updating the token, so wait for the next check`),this.checkAccessTokenExpire())):this.lastAccessToken!==e.access_token&&this.updateTokenExpiration(e.access_token)}acquireTokenLock(){const e=Date.now(),t=globalThis.localStorage.getItem("iob_token_semaphore");if(t)try{const i=JSON.parse(t);if(e<i.expiry)return!1}catch{}const s={connId:this.connId,expiry:e+10*1e3};return globalThis.localStorage.setItem("iob_token_semaphore",JSON.stringify(s)),!0}releaseTokenLock(){const e=globalThis.localStorage.getItem("iob_token_semaphore");if(e)try{JSON.parse(e).connId===this.connId&&globalThis.localStorage.removeItem("iob_token_semaphore")}catch{globalThis.localStorage.removeItem("iob_token_semaphore")}}checkAccessTokenExpire(){if(this._refreshTimer&&(clearTimeout(this._refreshTimer),this._refreshTimer=null),this.isSecure){const e=fe.readTokens();if(e){const t=e.expires_in.getTime();if(t<Date.now()+3e4){const s=t<Date.now()+5500;console.log(`[TOKEN/${new Date().toISOString()}] Updating refresh token ${e.access_token}`),e.refresh_token?e.owner===this.connId||s?(e.owner===this.connId?console.log(`[TOKEN/${new Date().toISOString()}] We are the owner of the token`):console.log(`[TOKEN/${new Date().toISOString()}] We are not the owner of the token, but we will take ownership`),this.props.tokenTimeoutHandler?(console.log(`[TOKEN/${new Date().toISOString()}] Asking GUI if we should prolong the token`),this.props.tokenTimeoutHandler(t).then(i=>{i?(console.log(`[TOKEN/${new Date().toISOString()}] Token will be prolonged`),this.refreshTokens(e,s)):(console.log(`[TOKEN/${new Date().toISOString()}] Token will not be prolonged. Reloading the page`),setTimeout(()=>globalThis.location.reload(),Date.now()>t?500:t-Date.now()))})):(console.log(`[TOKEN/${new Date().toISOString()}] No tokenTimeoutHandler defined. Prolonging the token`),this.refreshTokens(e,s))):this.lastAccessToken!==e.access_token?(console.log(`[TOKEN/${new Date().toISOString()}] We are not the owner of the token, but we will inform the server about new token`),this.refreshTokens(e)):(console.log(`[TOKEN/${new Date().toISOString()}] We are not the owner of the token and the token did not change. Check in 3 seconds if the owner updated the token`),this._refreshTimer=setTimeout(()=>{this._refreshTimer=null,this.checkAccessTokenExpire()},3e3)):(console.log(`[TOKEN/${new Date().toISOString()}] We do not have a refresh token, so we need to reauthenticate`),setTimeout(()=>globalThis.location.reload(),Date.now()>t?500:t-Date.now()))}else this._refreshTimer=setTimeout(()=>{this._refreshTimer=null,this.checkAccessTokenExpire()},t-Date.now()-3e4>12e4?12e4:t-Date.now()-3e4)}}}static isCloud(){return globalThis.location.hostname.includes("amazonaws.com")||globalThis.location.hostname.includes("iobroker.in")?!0:typeof globalThis.socketUrl>"u"?!1:globalThis.socketUrl.includes("iobroker.in")||globalThis.socketUrl.includes("amazonaws")}isConnected(){return this.connected}waitForFirstConnection(){return this._waitForFirstConnectionPromise}async getUserPermissions(){return this.request({commandTimeout:!1,executor:(e,t)=>{this._socket.emit("getUserPermissions",(s,i)=>{s?t(s):e(i||null)})}})}async loadData(){if(this.loaded)return;const e=10;for(let t=1;t<=e;t++){if(this.doLoadData().catch(s=>console.error(`Cannot load data: ${s}`)),this.loaded)return;await OM(fe.isCloud()?5e3:1e3)}}async doLoadData(){var e,t,s,i,o,M,a,u,N;if(!this.loaded){if(!this.props.doNotLoadACL)try{this.acl=await this.getUserPermissions()}catch(l){this.onError(`Cannot read user permissions: ${l}`);return}try{this.props.admin5only&&!fe.isWeb()&&(!globalThis.vendorPrefix||globalThis.vendorPrefix==="@@vendorPrefix@@")?this._systemConfig=await this.getCompactSystemConfig():this._systemConfig=await this.getSystemConfig()}catch(l){this.onError(`Cannot read system config: ${l}`);return}this._systemConfig&&(this.systemLang=(e=this._systemConfig.common)==null?void 0:e.language,this.systemLang||(this.systemLang=globalThis.navigator.userLanguage||globalThis.navigator.language,/^(en|de|ru|pt|nl|fr|it|es|pl|uk)-?/.test(this.systemLang)?this.systemLang=this.systemLang.substring(0,2):/^(en|de|ru|pt|nl|fr|it|es|pl|uk|zh-cn)$/.test(this.systemLang)||(this.systemLang="en"),this._systemConfig.common.language=this.systemLang)),(s=(t=this.props).onLanguage)==null||s.call(t,this.systemLang),this.loaded=!0,(o=(i=this.props).onProgress)==null||o.call(i,ct.CONNECTED),this.firstConnect=!1,this.props.doNotLoadAllObjects?this.props.admin5only?this.objects={}:this.objects={"system.config":this._systemConfig}:this.objects=await this.getObjects(),(a=(M=this.props).onProgress)==null||a.call(M,ct.READY),this.onReadyDone||(this.onReadyDone=!0,(N=(u=this.props).onReady)==null||N.call(u,this.objects))}}authenticate(){globalThis.location.search.includes("&href=")?globalThis.location.href=`${globalThis.location.protocol}//${globalThis.location.host}${globalThis.location.pathname}${globalThis.location.search}`:globalThis.location.href=`${globalThis.location.protocol}//${globalThis.location.host}${globalThis.location.pathname}?login&href=${encodeURIComponent(globalThis.location.search+globalThis.location.hash)}`}async subscribeState(...e){let t,s,i;e.length===3?[t,s,i]=e:([t,i]=e,s=!1);let o;if(Array.isArray(t)?o=t:o=[t],typeof i!="function")throw new Error("The state change handler must be a function!");const M=[];for(let a=0;a<o.length;a++){const u=o[a];this.statesSubscribes[u]?!this.statesSubscribes[u].cbs.includes(i)&&this.statesSubscribes[u].cbs.push(i):(this.statesSubscribes[u]={reg:new RegExp(di(u)),cbs:[i]},t!==this.ignoreState&&M.push(u))}if(this.connected)if(M.length&&this._socket.emit("subscribe",M),s){let a;for(let u=0;u<o.length;u++){try{a=await this.getBinaryState(o[u])}catch(N){console.error(`Cannot getBinaryState "${o[u]}": ${JSON.stringify(N)}`),a=void 0}a!=null&&i(o[u],a)}}else if(o.find(a=>a.includes("*"))){let a;for(let u=0;u<o.length;u++){try{a=await this.getForeignStates(o[u])}catch(N){console.error(`Cannot getForeignStates "${o[u]}": ${JSON.stringify(N)}`);return}if(a)for(const[N,l]of Object.entries(a)){const c=i(N,l);c instanceof Promise&&c.catch(L=>console.error(`Cannot call state change handler: ${L}`))}}}else try{const a=await(fe.isWeb()?this.getStates(o):this.getForeignStates(o));if(a)for(const[u,N]of Object.entries(a)){const l=i(u,N);l instanceof Promise&&l.catch(c=>console.error(`Cannot call state change handler: ${c}`))}}catch(a){console.error(`Cannot getState "${o.join(", ")}": ${a.message}`);return}}async subscribeStateAsync(e,t){return this.subscribeState(e,t)}unsubscribeState(e,t){var o;let s;Array.isArray(e)?s=e:s=[e];const i=[];for(let M=0;M<s.length;M++){const a=s[M];if(this.statesSubscribes[a]){const u=this.statesSubscribes[a];if(t){const N=u.cbs.indexOf(t);N!==-1&&u.cbs.splice(N,1)}else u.cbs=[];(o=u.cbs)!=null&&o.length||(delete this.statesSubscribes[a],a!==this.ignoreState&&i.push(a))}}this.connected&&i.length&&this._socket.emit("unsubscribe",s)}subscribeObject(e,t){let s;if(Array.isArray(e)?s=e:s=[e],typeof t!="function")throw new Error("The object change handler must be a function!");const i=[];for(let o=0;o<s.length;o++){const M=s[o];this.objectsSubscribes[M]?!this.objectsSubscribes[M].cbs.includes(t)&&this.objectsSubscribes[M].cbs.push(t):(this.objectsSubscribes[M]={reg:new RegExp(di(M)),cbs:[t]},i.push(M))}return this.connected&&i.length&&this._socket.emit("subscribeObjects",i),Promise.resolve()}unsubscribeObject(e,t){var o;let s;Array.isArray(e)?s=e:s=[e];const i=[];for(let M=0;M<s.length;M++){const a=s[M];if(this.objectsSubscribes[a]){const u=this.objectsSubscribes[a];if(t){const N=u.cbs.indexOf(t);N!==-1&&u.cbs.splice(N,1)}else u.cbs=[];(o=u.cbs)!=null&&o.length||(delete this.objectsSubscribes[a],i.push(a))}}return this.connected&&i.length&&this._socket.emit("unsubscribeObjects",i),Promise.resolve()}objectChange(e,t){var o,M;let s;this.objects[e]&&(s={_id:e,type:this.objects[e].type});let i=!1;t?(t._rev&&this.objects[e]&&(this.objects[e]._rev=t._rev),(!this.objects[e]||JSON.stringify(this.objects[e])!==JSON.stringify(t))&&(this.objects[e]=t,i=!0)):this.objects[e]&&(delete this.objects[e],i=!0);for(const[a,u]of Object.entries(this.objectsSubscribes))(a===e||u.reg.test(e))&&u.cbs.forEach(N=>{try{const l=N(e,t,s);l instanceof Promise&&l.catch(c=>console.error(`Cannot call object change handler: ${c}`))}catch(l){console.error(`Error by callback of objectChange: ${l}`)}});if(i){const a=(M=(o=this.props).onObjectChange)==null?void 0:M.call(o,e,t);a instanceof Promise&&a.catch(u=>console.error(`Cannot call object change handler: ${u}`))}}stateChange(e,t){for(const s of Object.values(this.statesSubscribes))if(s.reg.test(e))for(const i of s.cbs)try{const o=i(e,t??null);o instanceof Promise&&o.catch(M=>console.error(`Cannot call state change handler: ${M}`))}catch(o){console.error(`Error by callback of stateChanged: ${o}`)}}instanceMessage(e,t,s){var i;(i=this._instanceSubscriptions[t])==null||i.forEach(o=>{if(o.messageType===e){const M=o.callback(s,t,e);M instanceof Promise&&M.catch(a=>console.error(`Cannot call instance message handler: ${a}`))}})}fileChange(e,t,s){for(const i of Object.values(this.filesSubscribes))if(i.regId.test(e)&&i.regFilePattern.test(t))for(const o of i.cbs)try{o(e,t,s)}catch(M){console.error(`Error by callback of fileChange: ${M}`)}}async subscribeFiles(e,t,s){if(typeof s!="function")throw new Error("The state change handler must be a function!");let i;Array.isArray(t)?i=t:i=[t];const o=[];for(let M=0;M<i.length;M++){const a=i[M],u=`${e}$%$${a}`;this.filesSubscribes[u]?!this.filesSubscribes[u].cbs.includes(s)&&this.filesSubscribes[u].cbs.push(s):(this.filesSubscribes[u]={regId:new RegExp(di(e)),regFilePattern:new RegExp(di(a)),cbs:[s]},o.push(a))}return this.connected&&o.length&&this._socket.emit("subscribeFiles",e,o),Promise.resolve()}unsubscribeFiles(e,t,s){var M;let i;Array.isArray(t)?i=t:i=[t];const o=[];for(let a=0;a<i.length;a++){const u=i[a],N=`${e}$%$${u}`;if(this.filesSubscribes[N]){const l=this.filesSubscribes[N];if(s){const c=l.cbs.indexOf(s);c!==-1&&l.cbs.splice(c,1)}else l.cbs=[];(M=l.cbs)!=null&&M.length||(delete this.filesSubscribes[N],o.push(u))}}this.connected&&o.length&&this._socket.emit("unsubscribeFiles",e,o)}async request({cacheKey:e,forceUpdate:t,commandTimeout:s,onTimeout:i,requireAdmin:o,requireFeatures:M,executor:a}){if(o&&fe.isWeb())return Promise.reject(new Error(ke.NOT_ADMIN));if(e&&!t&&e in this._promises)return this._promises[e];if(!this.connected)return Promise.reject(new Error(ke.NOT_CONNECTED));if(M!=null&&M.length){for(const N of M)if(!await this.checkFeatureSupported(N))throw new Error(ke.NOT_SUPPORTED)}const u=new Promise(async(N,l)=>{const c={elapsed:!1,clearTimeout:()=>{}};let L;s!==!1&&(L=setTimeout(()=>{c.elapsed=!0,i==null||i(),e&&this._promises[e]instanceof Promise&&delete this._promises[e],l(new Error(ke.TIMEOUT))},s??this.props.cmdTimeout),c.clearTimeout=()=>{clearTimeout(L)});try{await a(N,l,c)}catch(j){e&&this._promises[e]instanceof Promise&&delete this._promises[e],l(new Error(j.toString()))}});return e&&(this._promises[e]=u),u}resetCache(e,t){t?Object.keys(this._promises).filter(s=>s.startsWith(e)).forEach(s=>{delete this._promises[s]}):delete this._promises[e]}getStates(e){return this.request({commandTimeout:!1,executor:(t,s)=>{this._socket.emit("getStates",e,(i,o)=>{this.states=o??{},i?s(i):t(this.states)})}})}getState(e){return this.request({commandTimeout:!1,executor:(t,s)=>{if(e&&e===this.ignoreState){t(this.simStates[e]||{val:null,ack:!0});return}this._socket.emit("getState",e,(i,o)=>{i?s(i):t(o)})}})}getBinaryState(e){return this.request({commandTimeout:!1,executor:(t,s)=>{this._socket.emit("getBinaryState",e,(i,o)=>{i?s(i):t(o)})}})}setBinaryState(e,t){return this.request({commandTimeout:!1,executor:(s,i)=>{this._socket.emit("setBinaryState",e,t,o=>{o?i(o):s()})}})}setState(e,t,s){return typeof s=="boolean"&&(t={val:t,ack:s}),this.request({commandTimeout:!1,executor:(i,o)=>{if(e&&e===this.ignoreState){let M;if(typeof s=="boolean"||typeof t=="object"&&t.val!==void 0?M=t:M={val:t,ack:!1,ts:Date.now(),lc:Date.now(),from:"system.adapter.vis.0"},this.simStates[e]=M,this.statesSubscribes[e])for(const a of this.statesSubscribes[e].cbs)try{const u=a(e,M);u instanceof Promise&&u.catch(N=>console.error(`Cannot call state change handler: ${N}`))}catch(u){console.error(`Error by callback of stateChanged: ${u}`)}i();return}this._socket.emit("setState",e,t,M=>{M?o(M):i()})}})}getObjects(e,t){return this.request({commandTimeout:!1,executor:(s,i)=>{if(!e&&this.objects){s(this.objects);return}this._socket.emit(fe.isWeb()?"getObjects":"getAllObjects",(o,M)=>{var a,u;t||(u=(a=this.props).onProgress)==null||u.call(a,ct.OBJECTS_LOADED),o?i(o):(this.objects=M??{},s(this.objects))})}})}getObjectsById(e){return this.request({commandTimeout:!1,executor:(t,s)=>{this._socket.emit("getObjects",e,(i,o)=>{i?s(i):t(o)})}})}_subscribe(e){var t,s;if(e&&!this.subscribed){this.subscribed=!0,(t=this.props.autoSubscribes)!=null&&t.length&&this._socket.emit("subscribeObjects",this.props.autoSubscribes);const i=Object.keys(this.objectsSubscribes);i.length&&this._socket.emit("subscribeObjects",i),Object.keys(this.objectsSubscribes).forEach(o=>this._socket.emit("subscribeObjects",o)),this.props.autoSubscribeLog&&this._socket.emit("requireLog",!0),Object.keys(this.statesSubscribes).forEach(o=>this._socket.emit("subscribe",o)),Object.keys(this.filesSubscribes).forEach(o=>{const[M,a]=o.split("$%$");this._socket.emit("subscribeFiles",M,a)})}else if(!e&&this.subscribed){this.subscribed=!1,(s=this.props.autoSubscribes)!=null&&s.length&&this._socket.emit("unsubscribeObjects",this.props.autoSubscribes);const i=Object.keys(this.objectsSubscribes);i.length&&this._socket.emit("unsubscribeObjects",i),this.props.autoSubscribeLog&&this._socket.emit("requireLog",!1),Object.keys(this.statesSubscribes).forEach(o=>this._socket.emit("unsubscribe",o)),Object.keys(this.filesSubscribes).forEach(o=>{const[M,a]=o.split("$%$");this._socket.emit("unsubscribeFiles",M,a)})}}requireLog(e){return this.request({commandTimeout:!1,executor:(t,s)=>{this._socket.emit("requireLog",e,i=>{i?s(i):t()})}})}delObject(e,t=!1){return this.request({commandTimeout:!1,executor:(s,i)=>{this._socket.emit("delObject",e,{maintenance:t},o=>{o?i(o):s()})}})}delObjects(e,t){return this.request({commandTimeout:!1,executor:(s,i)=>{this._socket.emit("delObjects",e,{maintenance:t},o=>{o?i(o):s()})}})}setObject(e,t){return t?(t=JSON.parse(JSON.stringify(t)),delete t.from,delete t.user,delete t.ts,this.request({commandTimeout:!1,executor:(s,i)=>{this._socket.emit("setObject",e,t,o=>{o?i(o):s()})}})):Promise.reject(new Error("Null object is not allowed"))}getObject(e){return this.request({commandTimeout:!1,executor:(t,s)=>{if(e&&e===this.ignoreState){t({_id:this.ignoreState,type:"state",common:{name:"ignored state",type:"mixed"}});return}this._socket.emit("getObject",e,(i,o)=>{i?s(i):t(o)})}})}sendTo(e,t,s){return this.request({commandTimeout:!1,executor:i=>{this._socket.emit("sendTo",e,t,s,o=>{i(o)})}})}extendObject(e,t){return t?(t=JSON.parse(JSON.stringify(t)),delete t.from,delete t.user,delete t.ts,this.request({commandTimeout:!1,executor:(s,i)=>{this._socket.emit("extendObject",e,t,o=>{o?i(o):s()})}})):Promise.reject(new Error("Null object is not allowed"))}registerLogHandler(e){this.onLogHandlers.includes(e)||this.onLogHandlers.push(e)}unregisterLogHandler(e){const t=this.onLogHandlers.indexOf(e);t!==-1&&this.onLogHandlers.splice(t,1)}registerConnectionHandler(e){this.onConnectionHandlers.includes(e)||this.onConnectionHandlers.push(e)}unregisterConnectionHandler(e){const t=this.onConnectionHandlers.indexOf(e);t!==-1&&this.onConnectionHandlers.splice(t,1)}registerCmdStdoutHandler(e){this.onCmdStdoutHandler=e}unregisterCmdStdoutHandler(){this.onCmdStdoutHandler=void 0}registerCmdStderrHandler(e){this.onCmdStderrHandler=e}unregisterCmdStderrHandler(){this.onCmdStderrHandler=void 0}registerCmdExitHandler(e){this.onCmdExitHandler=e}unregisterCmdExitHandler(){this.onCmdExitHandler=void 0}getEnums(e,t){return this.request({cacheKey:`enums_${e||"all"}`,forceUpdate:t,commandTimeout:!1,executor:(s,i)=>{this._socket.emit("getObjectView","system","enum",{startkey:`enum.${e||""}`,endkey:e?`enum.${e}.香`:"enum.香"},(o,M)=>{if(o)i(o);else{const a={};if(M)for(let u=0;u<M.rows.length;u++)e&&M.rows[u].id===`enum.${e}`||(a[M.rows[u].id]=M.rows[u].value);s(a)}})}})}getObjectView(e,t,s){return this.getObjectViewCustom("system",s,e,t)}async getObjectViewSystem(e,t,s){var M;const i=`${e}_${t||""}_${s||""}`,o=await this.getObjectViewCustom("system",e,t,s);return(M=this.objectViewCached)!=null&&M[i]&&(this.objectViewCached[i]=o),o}async getObjectViewSystemCached(e,t,s){var M;const i=`${e}_${t||""}_${s||""}`;if((M=this.objectViewCached)!=null&&M[i])return Promise.resolve(this.objectViewCached[i]);const o=await this.getObjectViewCustom("system",e,t,s);return this.objectViewCached||={},this.objectViewCached[i]=o,o}getObjectViewCustom(e,t,s,i){return this.request({commandTimeout:!1,executor:(o,M)=>{s||="",i||="香",this._socket.emit("getObjectView",e,t,{startkey:s,endkey:i},(a,u)=>{if(a)M(a);else{const N={};if(u&&u.rows)for(let l=0;l<u.rows.length;l++)N[u.rows[l].id]=u.rows[l].value;o(N)}})}})}readMetaItems(){return this.request({commandTimeout:!1,executor:(e,t)=>{this._socket.emit("getObjectView","system","meta",{startkey:"",endkey:"香"},(s,i)=>{var o;s?t(s):e((o=i.rows)==null?void 0:o.map(M=>M.value).filter(M=>!!M))})}})}readDir(e,t){return this.request({commandTimeout:!1,executor:(s,i)=>{this._socket.emit("readDir",e,t,(o,M)=>{o?i(o):s(M)})}})}readFile(e,t,s){return this.request({commandTimeout:!1,executor:(i,o)=>{this._socket.emit(s?"readFile64":"readFile",e,t,(M,a,u)=>{M?o(M):i({file:a,mimeType:u})})}})}writeFile64(e,t,s){return this.request({commandTimeout:!1,executor:(i,o)=>{if(typeof s=="string")this._socket.emit("writeFile",e,t,s,M=>{M?o(M):i()});else{const M=btoa(new Uint8Array(s).reduce((a,u)=>a+String.fromCharCode(u),""));this._socket.emit("writeFile64",e,t,M,a=>{a?o(a):i()})}}})}deleteFile(e,t){return this.request({commandTimeout:!1,executor:(s,i)=>{this._socket.emit("deleteFile",e,t,o=>{o?i(o):s()})}})}deleteFolder(e,t){return this.request({commandTimeout:!1,executor:(s,i)=>{this._socket.emit("deleteFolder",e,t,o=>{o?i(o):s()})}})}rename(e,t,s){return this.request({commandTimeout:!1,executor:(i,o)=>{this._socket.emit("rename",e,t,s,M=>{M?o(M):i()})}})}renameFile(e,t,s){return this.request({commandTimeout:!1,executor:(i,o)=>{this._socket.emit("renameFile",e,t,s,M=>{M?o(M):i()})}})}cmdExec(e,t,s,i){return this.request({commandTimeout:i,executor:(o,M,a)=>{e=wt(e),this._socket.emit("cmdExec",e,s,t,u=>{a.elapsed||(a.clearTimeout(),u?M(u):o())})}})}getSystemConfig(e){return this.request({cacheKey:"systemConfig",forceUpdate:e,commandTimeout:!1,executor:async t=>{let s=await this.getObject("system.config");s??={},s.common??={},s.native??={},t(s)}})}getCompactSystemConfig(e){return this.request({cacheKey:"systemConfigCommon",forceUpdate:e,commandTimeout:!1,requireAdmin:!0,executor:(t,s)=>{this._socket.emit("getCompactSystemConfig",(i,o)=>{i?s(i):(o??={},o.common??={},o.native??={},t(o))})}})}getForeignStates(e){return this.request({commandTimeout:!1,executor:(t,s)=>{this._socket.emit("getForeignStates",e||"*",(i,o)=>{i?s(i):t(o??{})})}})}getForeignObjects(e,t){return this.request({commandTimeout:!1,executor:(s,i)=>{this._socket.emit("getForeignObjects",e||"*",t,(o,M)=>{o?i(o):s(M)})}})}setSystemConfig(e){return this.setObject("system.config",e)}getRawSocket(){return this._socket}getHistory(e,t){return this.request({commandTimeout:!1,executor:(s,i)=>{this._socket.emit("getHistory",e,t,(o,M)=>{o?i(o):s(M)})}})}getHistoryEx(e,t){return this.request({commandTimeout:!1,executor:(s,i)=>{this._socket.emit("getHistory",e,t,(o,M,a,u)=>{o?i(o):s({values:M,sessionId:u,step:a})})}})}getIpAddresses(e,t){return e=wt(e),this.request({cacheKey:`IPs_${e}`,forceUpdate:t,commandTimeout:!1,executor:async s=>{const i=await this.getObject(e);s((i==null?void 0:i.common.address)??[])}})}getVersion(e){return this.request({cacheKey:"version",forceUpdate:e,commandTimeout:!1,executor:(t,s)=>{this._socket.emit("getVersion",(i,o,M)=>{i&&!o&&typeof i=="string"&&i.match(/\d+\.\d+\.\d+/)?t({version:i,serverName:"socketio"}):i?s(i):t({version:o,serverName:M})})}})}getWebServerName(){return this.request({cacheKey:"webName",commandTimeout:!1,executor:(e,t)=>{this._socket.emit("getAdapterName",(s,i)=>{s?t(s):e(i)})}})}fileExists(e,t){return this.request({commandTimeout:!1,executor:(s,i)=>{this._socket.emit("fileExists",e,t,(o,M)=>{o?i(o):s(!!M)})}})}getCurrentUser(){return this.request({commandTimeout:!1,executor:e=>{this._socket.emit("authEnabled",(t,s)=>{e(s)})}})}getUuid(){return this.request({cacheKey:"uuid",commandTimeout:!1,executor:async e=>{var s;const t=await this.getObject("system.meta.uuid");e((s=t==null?void 0:t.native)==null?void 0:s.uuid)}})}checkFeatureSupported(e,t){return this.request({cacheKey:`supportedFeatures_${e}`,forceUpdate:t,commandTimeout:!1,executor:(s,i)=>{this._socket.emit("checkFeatureSupported",e,(o,M)=>{o?i(o):s(M)})}})}getAdapterInstances(e,t){return typeof e=="boolean"&&(t=e,e=""),e||="",this.request({cacheKey:`instances_${e}`,forceUpdate:t,commandTimeout:!1,executor:async s=>{const i=e?`system.adapter.${e}.`:"system.adapter.",o=`${i}香`,M=await this.getObjectViewSystem("instance",i,o),a=Object.values(M);s(e?a.filter(u=>u.common.name===e):a)}})}getAdapters(e,t){return typeof e=="boolean"&&(t=e,e=""),e||="",this.request({cacheKey:`adapter_${e}`,forceUpdate:t,commandTimeout:!1,executor:async s=>{const i=await this.getObjectViewSystem("adapter",`system.adapter.${e||""}`,`system.adapter.${e||"香"}`),o=Object.values(i);s(e?o.filter(M=>M.common.name===e):o)}})}getGroups(e){return this.request({cacheKey:"groups",forceUpdate:e,commandTimeout:!1,executor:(t,s)=>{this._socket.emit("getObjectView","system","group",{startkey:"system.group.",endkey:"system.group.香"},(i,o)=>{i?s(i):t(Br(o))})}})}logout(){return this.request({commandTimeout:!1,executor:(e,t)=>{this._socket.emit("logout",s=>{s?t(s):e(null)})}})}subscribeOnInstance(e,t,s,i){return this.request({commandTimeout:!1,executor:(o,M)=>{this._socket.emit("clientSubscribe",e,t,s,(a,u)=>{a?M(a):u&&(u.error?M(u.error):(e.startsWith("system.adapter.")||(e=`system.adapter.${e}`),this._instanceSubscriptions[e]=this._instanceSubscriptions[e]||[],this._instanceSubscriptions[e].find(N=>N.messageType===t&&N.callback===i)||this._instanceSubscriptions[e].push({messageType:t,callback:i}),o(u)))})}})}unsubscribeFromInstance(e,t,s){var M;e.startsWith("system.adapter.")||(e=`system.adapter.${e}`);let i;const o=[];do{i=!1;const a=(M=this._instanceSubscriptions[e])==null?void 0:M.findIndex(u=>(!t||u.messageType===t)&&(!s||u.callback===s));if(a!=null&&a!==-1){i=!0;const u=this._instanceSubscriptions[e][a].messageType;this._instanceSubscriptions[e].splice(a,1),this._instanceSubscriptions[e].length||delete this._instanceSubscriptions[e],this._instanceSubscriptions[e]&&this._instanceSubscriptions[e].find(l=>l.messageType===u)||o.push(this.request({commandTimeout:!1,executor:(l,c)=>{this._socket.emit("clientUnsubscribe",e,t,(L,j)=>L?c(L):l(j))}}))}}while(i&&(!s||!t));return o.length?Promise.all(o).then(a=>!!a.find(u=>u)):Promise.resolve(!1)}log(e,t){return e?this.request({commandTimeout:!1,executor:s=>(this._socket.emit("log",e,t),s(null))}):Promise.resolve(null)}setStateToIgnore(e){this.ignoreState=e}}function fl(r,e){if(!e)return;let t;if(e.length<700&&(e.indexOf("/")!==-1||e.indexOf("\\")!==-1))if(r.toLowerCase().includes("private"))t="private";else if(e.toLowerCase().includes("private"))t="private";else if(r.toLowerCase().includes("public"))t="public";else if(e.toLowerCase().includes("public"))t="public";else if(r.toLowerCase().includes("chain"))t="chained";else if(e.toLowerCase().includes("chain"))t="chained";else return;else t=e.substring(0,26)==="-----BEGIN RSA PRIVATE KEY"||e.substring(0,22)==="-----BEGIN PRIVATE KEY"?"private":"public",t==="public"&&e.split("-----END CERTIFICATE-----").filter(i=>i.replace(/\r\n|\r|\n/,"").trim()).length>1&&(t="chained");return{name:r,type:t}}function Sl(r){var s,i,o,M;const e=[{name:"[IPv4] 0.0.0.0 - Listen on all IPs",address:"0.0.0.0",family:"ipv4"}],t=[{name:"[IPv6] :: - Listen on all IPs",address:"::",family:"ipv6"}];if((i=(s=r.native)==null?void 0:s.hardware)!=null&&i.networkInterfaces){const a=(M=(o=r.native)==null?void 0:o.hardware)==null?void 0:M.networkInterfaces;Object.keys(a).forEach(u=>{var N;(N=a[u])==null||N.forEach(l=>{l.family!=="IPv6"?e.push({name:`[${l.family}] ${l.address} - ${u}`,address:l.address,family:"ipv4"}):t.push({name:`[${l.family}] ${l.address} - ${u}`,address:l.address,family:"ipv6"})})})}return{IPs4:e,IPs6:t}}class Pje extends fe{constructor(e){super(e)}request(e){return super.request({requireAdmin:!0,...e})}getCertificates(e){return this.request({cacheKey:"cert",forceUpdate:e,commandTimeout:!1,executor:async t=>{var i;const s=await this.getObject("system.certificates");(i=s==null?void 0:s.native)!=null&&i.certificates?t(Object.entries(s.native.certificates).map(([o,M])=>fl(o,M)).filter(o=>!!o)):t([])}})}getLogs(e,t=200){return this.request({commandTimeout:!1,executor:s=>{this._socket.emit("sendToHost",e,"getLogs",t||200,i=>{s(i)})}})}upgradeAdapterWithWebserver(e,t){return this.request({commandTimeout:!1,executor:s=>{this._socket.emit("sendToHost",e,"upgradeAdapterWithWebserver",t,i=>{s(i)})}})}upgradeController(e,t,s){return this.request({commandTimeout:!1,executor:(i,o)=>{this._socket.emit("sendToHost",e,"upgradeController",{version:t,adminInstance:s},M=>{const a=M;a.error?o(a.error):i(a.result)})}})}updateLicenses(e,t){return this.request({commandTimeout:!1,executor:(s,i)=>{this._socket.emit("updateLicenses",e,t,(o,M)=>{o?i(o):s(M)})}})}upgradeOsPackages(e,t,s){return this.request({commandTimeout:!1,executor:i=>{this._socket.emit("sendToHost",e,"upgradeOsPackages",{packages:t,restart:!!s},o=>{i(o)})}})}getLogsFiles(e){return this.request({commandTimeout:!1,executor:(t,s)=>{this._socket.emit("readLogs",e,(i,o)=>{i&&s(i),t(o)})}})}delLogs(e){return this.request({commandTimeout:!1,executor:(t,s)=>{this._socket.emit("sendToHost",e,"delLogs",null,i=>{i&&s(i),t()})}})}deleteFile(e,t){return this.request({commandTimeout:!1,executor:(s,i)=>{this._socket.emit("deleteFile",e,t,o=>{o&&i(o),s()})}})}deleteFolder(e,t){return this.request({commandTimeout:!1,executor:(s,i)=>{this._socket.emit("deleteFolder",e,t,o=>{o&&i(o),s()})}})}rename(e,t,s){return this.request({commandTimeout:!1,executor:(i,o)=>{this._socket.emit("rename",e,t,s,M=>{M&&o(M),i()})}})}renameFile(e,t,s){return this.request({commandTimeout:!1,executor:(i,o)=>{this._socket.emit("renameFile",e,t,s,M=>{M&&o(M),i()})}})}getHosts(e){return this.request({cacheKey:"hosts",forceUpdate:e,commandTimeout:!1,executor:(t,s)=>{this._socket.emit("getObjectView","system","host",{startkey:"system.host.",endkey:"system.host.香"},(i,o)=>{i?s(i):t(Br(o))})}})}getUsers(e){return this.request({cacheKey:"users",forceUpdate:e,commandTimeout:!1,executor:(t,s)=>{this._socket.emit("getObjectView","system","user",{startkey:"system.user.",endkey:"system.user.香"},(i,o)=>{i?s(i):t(Br(o))})}})}renameGroup(e,t,s){return this.request({commandTimeout:!1,executor:async i=>{const o=await this.getGroups(!0),M=o.filter(u=>u._id.startsWith(`${e}.`));for(const u of M){const N=u._id,l=t+u._id.substring(e.length);u._id=l,await this.setObject(l,u),await this.delObject(N)}const a=o.find(u=>u._id===e);if(a){const u=a._id;a._id=t,s!==void 0&&(a.common??={},a.common.name=s),await this.setObject(t,a),await this.delObject(u)}i()}})}getHostInfo(e,t,s){return e=wt(e),this.request({cacheKey:`hostInfo_${e}`,forceUpdate:t,commandTimeout:s,executor:(i,o,M)=>{this._socket.emit("sendToHost",e,"getHostInfo",null,a=>{M.elapsed||(M.clearTimeout(),a===ke.PERMISSION_ERROR?o('May not read "getHostInfo"'):a?i(a):o('Cannot read "getHostInfo"'))})}})}getHostInfoShort(e,t,s){return e=wt(e),this.request({cacheKey:`hostInfoShort_${e}`,forceUpdate:t,commandTimeout:s,executor:(i,o,M)=>{this._socket.emit("sendToHost",e,"getHostInfoShort",null,a=>{M.elapsed||(M.clearTimeout(),a===ke.PERMISSION_ERROR?o('May not read "getHostInfoShort"'):a?i(a):o('Cannot read "getHostInfoShort"'))})}})}getRepository(e,t,s,i){return this.request({cacheKey:`repository_${e}`,forceUpdate:s,commandTimeout:i,executor:(o,M,a)=>{this._socket.emit("sendToHost",e,"getRepository",t,u=>{a.elapsed||(a.clearTimeout(),u===ke.PERMISSION_ERROR?M('May not read "getRepository"'):u?o(u):M('Cannot read "getRepository"'))})}})}getInstalled(e,t,s){return e=wt(e),this.request({cacheKey:`installed_${e}`,forceUpdate:t,commandTimeout:s,executor:(i,o,M)=>{this._socket.emit("sendToHost",e,"getInstalled",null,a=>{M.elapsed||(M.clearTimeout(),a===ke.PERMISSION_ERROR?o('May not read "getInstalled"'):a?i(a):o('Cannot read "getInstalled"'))})}})}cmdExec(e,t,s,i){return this.request({commandTimeout:i,executor:(o,M,a)=>{e=wt(e),this._socket.emit("cmdExec",e,s,t,u=>{a.elapsed||(a.clearTimeout(),u&&M(u),o())})}})}readBaseSettings(e){return e=$s(e),this.request({requireFeatures:["CONTROLLER_READWRITE_BASE_SETTINGS"],executor:(t,s,i)=>{this._socket.emit("sendToHost",e,"readBaseSettings",null,o=>{i.elapsed||(i.clearTimeout(),o===ke.PERMISSION_ERROR?s('May not read "BaseSettings"'):o?o.error?s(new Error(o.error)):t(o):s('Cannot read "BaseSettings"'))})}})}writeBaseSettings(e,t){return e=$s(e),this.request({requireFeatures:["CONTROLLER_READWRITE_BASE_SETTINGS"],executor:(s,i,o)=>{this._socket.emit("sendToHost",e,"writeBaseSettings",t,M=>{o.elapsed||(o.clearTimeout(),M===ke.PERMISSION_ERROR?i('May not write "BaseSettings"'):M?s(M):i('Cannot write "BaseSettings"'))})}})}restartController(e){return e=$s(e),this.request({executor:(t,s,i)=>{this._socket.emit("sendToHost",e,"restartController",null,()=>{i.elapsed||(i.clearTimeout(),t(!0))})}})}getDiagData(e,t){return e=$s(e),this.request({executor:(s,i,o)=>{this._socket.emit("sendToHost",e,"getDiagData",t,M=>{o.elapsed||(o.clearTimeout(),s(M||null))})}})}changePassword(e,t){return this.request({executor:(s,i,o)=>{this._socket.emit("changePassword",e,t,M=>{o.elapsed||(o.clearTimeout(),M&&i(M),s())})}})}getIpAddresses(e,t){return e=wt(e),this.request({cacheKey:`IPs_${e}`,forceUpdate:t,commandTimeout:!1,executor:async s=>{const i=await this.getObject(e);s((i==null?void 0:i.common.address)??[])}})}getHostByIp(e,t){return e=$s(e),this.request({cacheKey:`rIPs_${e}`,forceUpdate:t,executor:(s,i,o)=>{this._socket.emit("getHostByIp",e,(M,a)=>{if(o.elapsed)return;o.clearTimeout();const{IPs4:u,IPs6:N}=Sl(a);s([...u,...N])})}})}encrypt(e){return this.request({executor:(t,s,i)=>{this._socket.emit("encrypt",e,(o,M)=>{i.elapsed||(i.clearTimeout(),o&&s(o),t(M))})}})}decrypt(e){return this.request({executor:(t,s,i)=>{this._socket.emit("decrypt",e,(o,M)=>{i.elapsed||(i.clearTimeout(),o&&s(o),t(M))})}})}chmodFile(e,t,s){return this.request({executor:(i,o,M)=>{this._socket.emit("chmodFile",e,t,s,(a,u)=>{M.elapsed||(M.clearTimeout(),a&&o(a),i(u))})}})}chownFile(e,t,s){return this.request({executor:(i,o,M)=>{this._socket.emit("chownFile",e,t,s,(a,u)=>{M.elapsed||(M.clearTimeout(),a&&o(a),i(u))})}})}getNotifications(e,t){return this.request({executor:(s,i,o)=>{this._socket.emit("sendToHost",e,"getNotifications",{category:t},M=>{o.elapsed||(o.clearTimeout(),s(M))})}})}clearNotifications(e,t){return this.request({executor:(s,i,o)=>{this._socket.emit("sendToHost",e,"clearNotifications",{category:t},M=>{o.elapsed||(o.clearTimeout(),s(M))})}})}getIsEasyModeStrict(){return this.request({executor:(e,t,s)=>{this._socket.emit("getIsEasyModeStrict",(i,o)=>{s.elapsed||(s.clearTimeout(),i&&t(i),e(!!o))})}})}getEasyMode(){return this.request({executor:(e,t,s)=>{this._socket.emit("getEasyMode",(i,o)=>{s.elapsed||(s.clearTimeout(),i?t(new Error(i)):e(o))})}})}getRatings(e){return this.request({executor:(t,s,i)=>{this._socket.emit("getRatings",!!e,(o,M)=>{i.elapsed||(i.clearTimeout(),o?s(new Error(o)):t(M))})}})}getCurrentSession(e){const t=new AbortController;return this.request({commandTimeout:e||5e3,onTimeout:()=>{t.abort()},executor:async(s,i,o)=>{try{const M=await fetch("./session",{signal:t.signal});if(o.elapsed)return;o.clearTimeout();const a=await M.json();s(a)}catch(M){i(`getCurrentSession: ${M}`)}}})}getCurrentInstance(){return this.request({cacheKey:"currentInstance",executor:(e,t,s)=>{this._socket.emit("getCurrentInstance",(i,o)=>{s.elapsed||(s.clearTimeout(),i?t(i):e(o))})}})}getAdapterInstances(e,t){let s;return typeof e=="boolean"?(t=e,s=""):s=e||"",this.request({cacheKey:`instances_${s}`,forceUpdate:t,executor:(i,o,M)=>{this._socket.emit("getAdapterInstances",s,(a,u)=>{M.elapsed||(M.clearTimeout(),a&&o(a),i(u))})}})}getAdapters(e,t){let s;return typeof e=="boolean"?(t=e,s=""):s=e||"",this.request({cacheKey:`adapter_${s}`,forceUpdate:t,executor:(i,o,M)=>{this._socket.emit("getAdapters",s,(a,u)=>{M.elapsed||(M.clearTimeout(),a&&o(a),i(u))})}})}getCompactAdapters(e){return this.request({cacheKey:"compactAdapters",forceUpdate:e,executor:(t,s,i)=>{this._socket.emit("getCompactAdapters",(o,M)=>{i.elapsed||(i.clearTimeout(),o&&s(o),t(M))})}})}getAdaptersResetCache(e){e=e??"",this.resetCache(`adapter_${e}`),this.resetCache("compactAdapters")}getCompactInstances(e){return this.request({cacheKey:"compactInstances",forceUpdate:e,executor:(t,s,i)=>{this._socket.emit("getCompactInstances",(o,M)=>{i.elapsed||(i.clearTi