UNPKG

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.

5 lines 1.51 MB
import{o as we,g as Wi,c as Ji,a as Bi}from"./defaultTheme-BMwjsIOh.js";import{C as Y,R as a}from"./ConfigCustomBackItUpSet__loadShare__react__loadShare__-4sGW5l7i.js";import{a as g,C as z}from"./ConfigCustomBackItUpSet__loadShare___mf_0_mui_mf_1_icons_mf_2_material__loadShare__-CYjy_hHw.js";import{C as ua,D as _r,u as La}from"./index-sktH4Z2h.js";import{g as la}from"./_commonjsHelpers-D6-XlEtG.js";import{u as ja}from"./useTheme-DoCphjEc.js";import"./ConfigCustomBackItUpSet__mf_v__runtimeInit__mf_v__-kW6JvUJ8.js";import"./useTheme-CFHr9g1E.js";import"./ConfigCustomBackItUpSet__loadShare___mf_0_emotion_mf_1_react__loadShare__-BkqgHVEH.js";const MM=11/23/100;function Fi(i){const e={r:0,g:0,b:0};if(i.length===7)e.r=parseInt(i.substring(1,3),16),e.g=parseInt(i.substring(3,5),16),e.b=parseInt(i.substring(5,7),16);else if(i.length===4){const t=i[1],s=i[2],M=i[3];e.r=parseInt(t+t,16),e.g=parseInt(s+s,16),e.b=parseInt(M+M,16)}return e}function ga(i){return`#${Math.round(i.r).toString(16)}${Math.round(i.g).toString(16)}${Math.round(i.b).toString(16)}`}function Ta(i,e,t){const s=Fi(i),M=Fi(e);return s.r+=M.r*(.05+MM*(t-1)),s.g+=M.g*(.05+MM*(t-1)),s.b+=M.b*(.05+MM*(t-1)),ga(s)}function Ri(i,e){const t={};for(let s=1;s<=24;s++)t[`elevation${s}`]={backgroundColor:Ta(i,e,s)};return t}function Da(i,e){var r,n,N,u,L,c,l,j,T,y,d;let t,s;i==="dark"?(s={MuiAppBar:{colorDefault:{backgroundColor:"#272727"}},MuiLink:{root:{textTransform:"uppercase",transition:"color .3s ease",color:we[200],"&:hover":{color:we[100]}}},MuiPaper:Ri("#121212","#fff")},t={name:i,palette:{mode:"dark",background:{paper:"#121212",default:"#121212"},primary:{main:"#4dabf5"},secondary:{main:"#436a93"},expert:"#14bb00",text:{primary:"#ffffff",secondary:"#ffffff"}}}):i==="blue"?(s={MuiAppBar:{colorDefault:{backgroundColor:"#3399CC"}},MuiLink:{root:{textTransform:"uppercase",transition:"color .3s ease",color:we[400],"&:hover":{color:we[300]}}}},t={name:i,palette:{mode:"dark",background:{paper:"#151d21",default:"#151d21"},primary:{main:"#4dabf5"},secondary:{main:"#436a93"},expert:"#14bb00",text:{primary:"#ffffff",secondary:"#ffffff"}}}):i==="colored"?(s={MuiAppBar:{colorDefault:{backgroundColor:"#2a3135"}},MuiLink:{root:{textTransform:"uppercase",transition:"color .3s ease",color:we[200],"&:hover":{color:we[100]}}},MuiPaper:Ri("#151d21","#fff")},t={name:i,palette:{mode:"light",primary:{main:"#3399CC"},secondary:{main:"#164477"},expert:"#96fc96"}}):i==="PT"?(s={MuiAppBar:{colorDefault:{backgroundColor:"#0F99DE"}},MuiLink:{root:{textTransform:"uppercase",transition:"color .3s ease",color:we[400],"&:hover":{color:we[300]}}}},t={name:i,palette:{mode:"light",primary:{main:"#0F99DE"},secondary:{main:"#88A536"},expert:"#BD1B24"}}):i==="DX"?(s={MuiAppBar:{colorDefault:{backgroundColor:"#a9a9a9"}},MuiLink:{root:{textTransform:"uppercase",transition:"color .3s ease",color:we[400],"&:hover":{color:we[300]}}}},t={name:i,palette:{mode:"light",primary:{main:"#F5F5F7"},secondary:{main:"#a9a9a9"},expert:"#BD1B24",text:{primary:"#007AFE",secondary:"#007AFE",disabled:"#007AFEAA"}}}):(s={MuiLink:{root:{textTransform:"uppercase",transition:"color .3s ease",color:we[400],"&:hover":{color:we[300]}}}},t={name:i,palette:{mode:"light",primary:{main:"#3399CC",dark:"#256c97",light:"#76d0fd"},secondary:{main:"#164477"},expert:"#14bb00"}}),t.toolbar={height:48},t.saveToolbar={background:(n=(r=t.palette)==null?void 0:r.primary)==null?void 0:n.main,button:{borderRadius:3,height:32}},t.palette&&(t.palette.grey={main:Wi[300],dark:Wi[400]});const M=Ji(t),o=M.palette;return Ji(M,{...e||void 0,components:{...s,MuiButton:{variants:[{props:{variant:"contained",color:"grey"},style:{backgroundColor:(N=o.grey)==null?void 0:N[300],color:o.getContrastText&&((u=o.grey)!=null&&u[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:Bi(((l=o.text)==null?void 0:l.primary)||"",((j=o.action)==null?void 0:j.hoverOpacity)||.04)}}},{props:{variant:"text",color:"grey"},style:{color:(T=o.text)==null?void 0:T.primary,"&:hover":{backgroundColor:Bi(((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 ya(){let i,e;const t=new Promise((s,M)=>{i=s,e=M});return t.resolve=i,t.reject=e,t}function mM(i){return(i==null?void 0:i.rows.map(e=>e.value).filter(e=>!!e))??[]}function Je(i){return i!=null&&i.startsWith("system.host.")||(i=`system.host.${i}`),i}function Bt(i){return i!=null&&i.startsWith("system.host.")&&(i=i.substring(12)),i}function Gi(i){return new Promise(e=>{setTimeout(e,i)})}function Ds(i){i=(i||"").toString();const e=i[0]==="*",t=i[i.length-1]==="*";return i=i.replace(/[-/\\^$+?.()|[\]{}]/g,"\\$&").replace(/\*/g,".*"),(e?"":"^")+i+(t?"":"$")}var ke;(function(i){i[i.CONNECTING=0]="CONNECTING",i[i.CONNECTED=1]="CONNECTED",i[i.OBJECTS_LOADED=2]="OBJECTS_LOADED",i[i.READY=3]="READY"})(ke||(ke={}));var ue;(function(i){i.PERMISSION_ERROR="permissionError",i.NOT_CONNECTED="notConnectedError",i.TIMEOUT="timeout",i.NOT_ADMIN="Allowed only in admin",i.NOT_SUPPORTED="Not supported"})(ue||(ue={}));const jNe=ue.PERMISSION_ERROR;ue.NOT_CONNECTED;const da=["material","echarts","vis"];class ae{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||window.location.protocol,host:e.host||window.location.hostname,port:e.port||(window.location.port==="3000"?8081:window.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}}props;connId;lastAccessToken=null;ignoreState="";connected=!1;subscribed=!1;firstConnect=!0;waitForRestart=!1;loaded=!1;simStates={};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=ya();_instanceSubscriptions={};_promises={};_authTimer=null;_refreshTimer=null;_systemConfig;get systemConfig(){return this._systemConfig}systemLang="en";static isWeb(){return window.socketUrl!==void 0}waitForSocketLib(){return this._waitForSocketPromise?this._waitForSocketPromise:(this._waitForSocketPromise=new Promise(async(e,t)=>{if(typeof window.io>"u"&&typeof window.iob>"u")if(typeof window.registerSocketOnLoad=="function")window.registerSocketOnLoad(()=>e());else{for(let s=1;s<=30;s++){if(window.io||window.iob)return e();await Gi(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||window.location.protocol).replace(":",""),M=window.location.pathname;if(window.location.hostname==="iobroker.net"||window.location.hostname==="iobroker.pro")M="";else{if(window.socketUrl){const n=new URL(window.socketUrl);e=n.hostname,t=n.port,s=n.protocol.replace(":","")}const r=M.lastIndexOf("/");if(r!==-1&&(M=M.substring(0,r+1)),ae.isWeb()){const n=M.split("/");n.length>2&&(n.pop(),n.pop(),da.includes(n[n.length-1])&&n.pop(),M=n.join("/"),M.endsWith("/")||(M+="/"))}}const o=t?`${s}://${e}:${t}`:`${s}://${e}`;return this._socket=(window.io||window.iob).connect(o,{path:M.endsWith("/")?`${M}socket.io`:`${M}/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",r=>{window.addEventListener("storage",this.onAccessTokenUpdated);const n=ae.readTokens();if(n&&!n.owner){const N=Date.now();this.saveTokens({access_token:n.access_token,refresh_token:n.refresh_token,expires_in:Math.round((n.expires_in.getTime()-N)/1e3),refresh_token_expires_in:Math.round((n.refresh_token_expires_in.getTime()-N)/1e3),token_type:"Bearer"},n.stayLoggedIn)}this.onReadyDone=!1,r!==!0?(this.connected=!0,setTimeout(()=>this.getVersion().then(N=>{const[u,L,c]=N.version.split(".");parseInt(u,10)*1e4+parseInt(L,10)*100+parseInt(c,10)<40102?(this._authTimer=null,this.onPreConnect(!1,!1)):this._socket.emit("authenticate",(j,T)=>this.onPreConnect(j,T))}).catch(N=>this.onError({message:N.toString(),operation:"getVersion"})),500)):this._socket.emit("authenticate",(N,u)=>{this.onPreConnect(N,u)})}),this._socket.on("reconnect",()=>{var r,n;this.onReadyDone=!1,(n=(r=this.props).onProgress)==null||n.call(r,ke.READY),this.connected=!0,this.waitForRestart?window.location.reload():(this._subscribe(!0),this.onConnectionHandlers.forEach(N=>N(!0)))}),this._socket.on("disconnect",()=>{var r,n;this.onReadyDone=!1,this.connected=!1,this.subscribed=!1,(n=(r=this.props).onProgress)==null||n.call(r,ke.CONNECTING),this.onConnectionHandlers.forEach(N=>N(!1))}),this._socket.on("reauthenticate",()=>this.authenticate()),this._socket.on("log",r=>{var n,N;(N=(n=this.props).onLog)==null||N.call(n,r),this.onLogHandlers.forEach(u=>u(r))}),this._socket.on("error",r=>{let n;r==null?n="":typeof r.toString=="function"?n=r.toString():(n=JSON.stringify(r),console.error(`Received strange error: ${n}`)),n.includes("User not authorized")?this.authenticate():n.includes("websocket error")?(console.error(`Socket Error => reload: ${r}`),window.location.reload()):console.error(`Socket Error: ${r}`)}),this._socket.on("connect_error",r=>console.error(`Connect error: ${r}`)),this._socket.on("permissionError",r=>this.onError({message:"no permission",operation:r.operation,type:r.type,id:r.id||""})),this._socket.on("objectChange",(r,n)=>{setTimeout(()=>this.objectChange(r,n),0)}),this._socket.on("stateChange",(r,n)=>{setTimeout(()=>this.stateChange(r,n),0)}),this._socket.on("im",(r,n,N)=>{setTimeout(()=>this.instanceMessage(r,n,N),0)}),this._socket.on("fileChange",(r,n,N)=>{setTimeout(()=>this.fileChange(r,n,N),0)}),this._socket.on("cmdStdout",(r,n)=>{var N;(N=this.onCmdStdoutHandler)==null||N.call(this,r,n)}),this._socket.on("cmdStderr",(r,n)=>{var N;(N=this.onCmdStderrHandler)==null||N.call(this,r,n)}),this._socket.on("cmdExit",(r,n)=>{var N;(N=this.onCmdExitHandler)==null||N.call(this,r,n)}),Promise.resolve()}onPreConnect(e,t){var s,M;this._authTimer&&(clearTimeout(this._authTimer),this._authTimer=null),this.connected=!0,this.isSecure=t,this.waitForRestart?window.location.reload():(this.firstConnect?this.loadData().catch(o=>console.error(`Cannot load data: ${o}`)):(M=(s=this.props).onProgress)==null||M.call(s,ke.READY),this._subscribe(!0),this.onConnectionHandlers.forEach(o=>o(!0)),this.checkAccessTokenExpire()),this._waitForFirstConnectionPromise.resolve()}static readTokens(){let e=window.sessionStorage.getItem("iob_tokens");const t=!e;if(e||(e=window.localStorage.getItem("iob_tokens")),!e)return null;const[s,M,o,r,n]=e.split(";"),N=new Date(M);return N.getTime()<Date.now()?null:{refresh_token:s,refresh_token_expires_in:N,access_token:o,expires_in:new Date(r),owner:n,stayLoggedIn:t}}static saveTokensStatic(e,t,s){const M=`${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?window.localStorage.setItem("iob_tokens",M):window.sessionStorage.setItem("iob_tokens",M)}saveTokens(e,t){ae.saveTokensStatic(e,t,this.connId)}static deleteTokensStatic(){window.localStorage.removeItem("iob_tokens"),window.sessionStorage.removeItem("iob_tokens")}deleteTokens(e,t){const s=ae.readTokens();s&&(t?ae.deleteTokensStatic():s.stayLoggedIn===e&&s.owner===this.connId&&(s.stayLoggedIn?window.localStorage.removeItem("iob_tokens"):window.sessionStorage.removeItem("iob_tokens")))}onAccessTokenUpdated=e=>{if(e.key==="iob_tokens"){const t=ae.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(`Cannot update expiration time: ${t}`),window.location.reload()):s||(console.error("Cannot update expiration time"),window.location.reload())})),this.checkAccessTokenExpire()}refreshTokens(e,t){if(!e){setTimeout(()=>window.location.reload(),500);return}t||!e.owner||e.owner===this.connId?this.acquireTokenLock()?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)this.saveTokens(s,e.stayLoggedIn),this.releaseTokenLock(),this.updateTokenExpiration(s.access_token);else throw new Error("Cannot get access token")}).catch(s=>{this.releaseTokenLock(),this.deleteTokens(e.stayLoggedIn),console.error(s),window.location.reload()}):this.checkAccessTokenExpire():this.lastAccessToken!==e.access_token&&this.updateTokenExpiration(e.access_token)}acquireTokenLock(){const e=Date.now(),t=localStorage.getItem("iob_token_semaphore");if(t)try{const M=JSON.parse(t);if(e<M.expiry)return!1}catch{}const s={connId:this.connId,expiry:e+10*1e3};return localStorage.setItem("iob_token_semaphore",JSON.stringify(s)),!0}releaseTokenLock(){const e=localStorage.getItem("iob_token_semaphore");if(e)try{JSON.parse(e).connId===this.connId&&localStorage.removeItem("iob_token_semaphore")}catch{localStorage.removeItem("iob_token_semaphore")}}checkAccessTokenExpire(){if(this._refreshTimer&&(clearTimeout(this._refreshTimer),this._refreshTimer=null),this.isSecure){const e=ae.readTokens();if(e){const t=e.expires_in.getTime();if(t<Date.now()+3e4){const s=t<Date.now()+5500;e.refresh_token?e.owner===this.connId||s?this.props.tokenTimeoutHandler?this.props.tokenTimeoutHandler(t).then(M=>{M?this.refreshTokens(e,s):setTimeout(()=>window.location.reload(),Date.now()>t?500:t-Date.now())}):this.refreshTokens(e,s):this.lastAccessToken!==e.access_token?this.refreshTokens(e):this._refreshTimer=setTimeout(()=>{this._refreshTimer=null,this.checkAccessTokenExpire()},3e3):setTimeout(()=>window.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 window.location.hostname.includes("amazonaws.com")||window.location.hostname.includes("iobroker.in")?!0:typeof window.socketUrl>"u"?!1:window.socketUrl.includes("iobroker.in")||window.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,M)=>{s?t(s):e(M||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 Gi(ae.isCloud()?5e3:1e3)}}async doLoadData(){var e,t,s,M,o,r,n,N,u;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&&!ae.isWeb()&&(!window.vendorPrefix||window.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=window.navigator.userLanguage||window.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=(M=this.props).onProgress)==null||o.call(M,ke.CONNECTED),this.firstConnect=!1,this.props.doNotLoadAllObjects?this.props.admin5only?this.objects={}:this.objects={"system.config":this._systemConfig}:this.objects=await this.getObjects(),(n=(r=this.props).onProgress)==null||n.call(r,ke.READY),this.onReadyDone||(this.onReadyDone=!0,(u=(N=this.props).onReady)==null||u.call(N,this.objects))}}authenticate(){window.location.search.includes("&href=")?window.location.href=`${window.location.protocol}//${window.location.host}${window.location.pathname}${window.location.search}`:window.location.href=`${window.location.protocol}//${window.location.host}${window.location.pathname}?login&href=${encodeURIComponent(window.location.search+window.location.hash)}`}async subscribeState(...e){let t,s,M;e.length===3?[t,s,M]=e:([t,M]=e,s=!1);let o;if(Array.isArray(t)?o=t:o=[t],typeof M!="function")throw new Error("The state change handler must be a function!");const r=[];for(let n=0;n<o.length;n++){const N=o[n];this.statesSubscribes[N]?!this.statesSubscribes[N].cbs.includes(M)&&this.statesSubscribes[N].cbs.push(M):(this.statesSubscribes[N]={reg:new RegExp(Ds(N)),cbs:[M]},t!==this.ignoreState&&r.push(N))}if(this.connected)if(r.length&&this._socket.emit("subscribe",r),s){let n;for(let N=0;N<o.length;N++){try{n=await this.getBinaryState(o[N])}catch(u){console.error(`Cannot getBinaryState "${o[N]}": ${JSON.stringify(u)}`),n=void 0}n!=null&&M(o[N],n)}}else if(o.find(n=>n.includes("*"))){let n;for(let N=0;N<o.length;N++){try{n=await this.getForeignStates(o[N])}catch(u){console.error(`Cannot getForeignStates "${o[N]}": ${JSON.stringify(u)}`);return}if(n)for(const[u,L]of Object.entries(n)){const c=M(u,L);c instanceof Promise&&c.catch(l=>console.error(`Cannot call state change handler: ${l}`))}}}else try{const n=await(ae.isWeb()?this.getStates(o):this.getForeignStates(o));if(n)for(const[N,u]of Object.entries(n)){const L=M(N,u);L instanceof Promise&&L.catch(c=>console.error(`Cannot call state change handler: ${c}`))}}catch(n){console.error(`Cannot getState "${o.join(", ")}": ${n.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 M=[];for(let r=0;r<s.length;r++){const n=s[r];if(this.statesSubscribes[n]){const N=this.statesSubscribes[n];if(t){const u=N.cbs.indexOf(t);u!==-1&&N.cbs.splice(u,1)}else N.cbs=[];(o=N.cbs)!=null&&o.length||(delete this.statesSubscribes[n],n!==this.ignoreState&&M.push(n))}}this.connected&&M.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 M=[];for(let o=0;o<s.length;o++){const r=s[o];this.objectsSubscribes[r]?!this.objectsSubscribes[r].cbs.includes(t)&&this.objectsSubscribes[r].cbs.push(t):(this.objectsSubscribes[r]={reg:new RegExp(Ds(r)),cbs:[t]},M.push(r))}return this.connected&&M.length&&this._socket.emit("subscribeObjects",M),Promise.resolve()}unsubscribeObject(e,t){var o;let s;Array.isArray(e)?s=e:s=[e];const M=[];for(let r=0;r<s.length;r++){const n=s[r];if(this.objectsSubscribes[n]){const N=this.objectsSubscribes[n];if(t){const u=N.cbs.indexOf(t);u!==-1&&N.cbs.splice(u,1)}else N.cbs=[];(o=N.cbs)!=null&&o.length||(delete this.objectsSubscribes[n],M.push(n))}}return this.connected&&M.length&&this._socket.emit("unsubscribeObjects",M),Promise.resolve()}objectChange(e,t){var o,r;let s;this.objects[e]&&(s={_id:e,type:this.objects[e].type});let M=!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,M=!0)):this.objects[e]&&(delete this.objects[e],M=!0);for(const[n,N]of Object.entries(this.objectsSubscribes))(n===e||N.reg.test(e))&&N.cbs.forEach(u=>{try{const L=u(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(M){const n=(r=(o=this.props).onObjectChange)==null?void 0:r.call(o,e,t);n instanceof Promise&&n.catch(N=>console.error(`Cannot call object change handler: ${N}`))}}stateChange(e,t){for(const s of Object.values(this.statesSubscribes))if(s.reg.test(e))for(const M of s.cbs)try{const o=M(e,t??null);o instanceof Promise&&o.catch(r=>console.error(`Cannot call state change handler: ${r}`))}catch(o){console.error(`Error by callback of stateChanged: ${o}`)}}instanceMessage(e,t,s){var M;(M=this._instanceSubscriptions[t])==null||M.forEach(o=>{if(o.messageType===e){const r=o.callback(s,t,e);r instanceof Promise&&r.catch(n=>console.error(`Cannot call instance message handler: ${n}`))}})}fileChange(e,t,s){for(const M of Object.values(this.filesSubscribes))if(M.regId.test(e)&&M.regFilePattern.test(t))for(const o of M.cbs)try{o(e,t,s)}catch(r){console.error(`Error by callback of fileChange: ${r}`)}}async subscribeFiles(e,t,s){if(typeof s!="function")throw new Error("The state change handler must be a function!");let M;Array.isArray(t)?M=t:M=[t];const o=[];for(let r=0;r<M.length;r++){const n=M[r],N=`${e}$%$${n}`;this.filesSubscribes[N]?!this.filesSubscribes[N].cbs.includes(s)&&this.filesSubscribes[N].cbs.push(s):(this.filesSubscribes[N]={regId:new RegExp(Ds(e)),regFilePattern:new RegExp(Ds(n)),cbs:[s]},o.push(n))}return this.connected&&o.length&&this._socket.emit("subscribeFiles",e,o),Promise.resolve()}unsubscribeFiles(e,t,s){var r;let M;Array.isArray(t)?M=t:M=[t];const o=[];for(let n=0;n<M.length;n++){const N=M[n],u=`${e}$%$${N}`;if(this.filesSubscribes[u]){const L=this.filesSubscribes[u];if(s){const c=L.cbs.indexOf(s);c!==-1&&L.cbs.splice(c,1)}else L.cbs=[];(r=L.cbs)!=null&&r.length||(delete this.filesSubscribes[u],o.push(N))}}this.connected&&o.length&&this._socket.emit("unsubscribeFiles",e,o)}async request({cacheKey:e,forceUpdate:t,commandTimeout:s,onTimeout:M,requireAdmin:o,requireFeatures:r,executor:n}){if(o&&ae.isWeb())return Promise.reject(new Error(ue.NOT_ADMIN));if(e&&!t&&e in this._promises)return this._promises[e];if(!this.connected)return Promise.reject(new Error(ue.NOT_CONNECTED));if(r!=null&&r.length){for(const u of r)if(!await this.checkFeatureSupported(u))throw new Error(ue.NOT_SUPPORTED)}const N=new Promise(async(u,L)=>{const c={elapsed:!1,clearTimeout:()=>{}};let l;s!==!1&&(l=setTimeout(()=>{c.elapsed=!0,M==null||M(),e&&this._promises[e]instanceof Promise&&delete this._promises[e],L(new Error(ue.TIMEOUT))},s??this.props.cmdTimeout),c.clearTimeout=()=>{clearTimeout(l)});try{await n(u,L,c)}catch(j){e&&this._promises[e]instanceof Promise&&delete this._promises[e],L(new Error(j.toString()))}});return e&&(this._promises[e]=N),N}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,(M,o)=>{this.states=o??{},M?s(M):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,(M,o)=>{M?s(M):t(o)})}})}getBinaryState(e){return this.request({commandTimeout:!1,executor:(t,s)=>{this._socket.emit("getBinaryState",e,(M,o)=>{M?s(M):t(o)})}})}setBinaryState(e,t){return this.request({commandTimeout:!1,executor:(s,M)=>{this._socket.emit("setBinaryState",e,t,o=>{o?M(o):s()})}})}setState(e,t,s){return typeof s=="boolean"&&(t={val:t,ack:s}),this.request({commandTimeout:!1,executor:(M,o)=>{if(e&&e===this.ignoreState){let r;if(typeof s=="boolean"||typeof t=="object"&&t.val!==void 0?r=t:r={val:t,ack:!1,ts:Date.now(),lc:Date.now(),from:"system.adapter.vis.0"},this.simStates[e]=r,this.statesSubscribes[e])for(const n of this.statesSubscribes[e].cbs)try{const N=n(e,r);N instanceof Promise&&N.catch(u=>console.error(`Cannot call state change handler: ${u}`))}catch(N){console.error(`Error by callback of stateChanged: ${N}`)}M();return}this._socket.emit("setState",e,t,r=>{r?o(r):M()})}})}getObjects(e,t){return this.request({commandTimeout:!1,executor:(s,M)=>{if(!e&&this.objects){s(this.objects);return}this._socket.emit(ae.isWeb()?"getObjects":"getAllObjects",(o,r)=>{var n,N;t||(N=(n=this.props).onProgress)==null||N.call(n,ke.OBJECTS_LOADED),o?M(o):(this.objects=r??{},s(this.objects))})}})}getObjectsById(e){return this.request({commandTimeout:!1,executor:(t,s)=>{this._socket.emit("getObjects",e,(M,o)=>{M?s(M):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 M=Object.keys(this.objectsSubscribes);M.length&&this._socket.emit("subscribeObjects",M),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[r,n]=o.split("$%$");this._socket.emit("subscribeFiles",r,n)})}else if(!e&&this.subscribed){this.subscribed=!1,(s=this.props.autoSubscribes)!=null&&s.length&&this._socket.emit("unsubscribeObjects",this.props.autoSubscribes);const M=Object.keys(this.objectsSubscribes);M.length&&this._socket.emit("unsubscribeObjects",M),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[r,n]=o.split("$%$");this._socket.emit("unsubscribeFiles",r,n)})}}requireLog(e){return this.request({commandTimeout:!1,executor:(t,s)=>{this._socket.emit("requireLog",e,M=>{M?s(M):t()})}})}delObject(e,t=!1){return this.request({commandTimeout:!1,executor:(s,M)=>{this._socket.emit("delObject",e,{maintenance:t},o=>{o?M(o):s()})}})}delObjects(e,t){return this.request({commandTimeout:!1,executor:(s,M)=>{this._socket.emit("delObjects",e,{maintenance:t},o=>{o?M(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,M)=>{this._socket.emit("setObject",e,t,o=>{o?M(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,(M,o)=>{M?s(M):t(o)})}})}sendTo(e,t,s){return this.request({commandTimeout:!1,executor:M=>{this._socket.emit("sendTo",e,t,s,o=>{M(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,M)=>{this._socket.emit("extendObject",e,t,o=>{o?M(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,M)=>{this._socket.emit("getObjectView","system","enum",{startkey:`enum.${e||""}`,endkey:e?`enum.${e}.香`:"enum.香"},(o,r)=>{if(o)M(o);else{const n={};if(r)for(let N=0;N<r.rows.length;N++)e&&r.rows[N].id===`enum.${e}`||(n[r.rows[N].id]=r.rows[N].value);s(n)}})}})}getObjectView(e,t,s){return this.getObjectViewCustom("system",s,e,t)}getObjectViewSystem(e,t,s){return this.getObjectViewCustom("system",e,t,s)}getObjectViewCustom(e,t,s,M){return this.request({commandTimeout:!1,executor:(o,r)=>{s=s||"",M=M||"香",this._socket.emit("getObjectView",e,t,{startkey:s,endkey:M},(n,N)=>{if(n)r(n);else{const u={};if(N&&N.rows)for(let L=0;L<N.rows.length;L++)u[N.rows[L].id]=N.rows[L].value;o(u)}})}})}readMetaItems(){return this.request({commandTimeout:!1,executor:(e,t)=>{this._socket.emit("getObjectView","system","meta",{startkey:"",endkey:"香"},(s,M)=>{var o;s?t(s):e((o=M.rows)==null?void 0:o.map(r=>r.value).filter(r=>!!r))})}})}readDir(e,t){return this.request({commandTimeout:!1,executor:(s,M)=>{this._socket.emit("readDir",e,t,(o,r)=>{o?M(o):s(r)})}})}readFile(e,t,s){return this.request({commandTimeout:!1,executor:(M,o)=>{this._socket.emit(s?"readFile64":"readFile",e,t,(r,n,N)=>{r?o(r):M({file:n,mimeType:N})})}})}writeFile64(e,t,s){return this.request({commandTimeout:!1,executor:(M,o)=>{if(typeof s=="string")this._socket.emit("writeFile",e,t,s,r=>{r?o(r):M()});else{const r=btoa(new Uint8Array(s).reduce((n,N)=>n+String.fromCharCode(N),""));this._socket.emit("writeFile64",e,t,r,n=>{n?o(n):M()})}}})}deleteFile(e,t){return this.request({commandTimeout:!1,executor:(s,M)=>{this._socket.emit("deleteFile",e,t,o=>{o?M(o):s()})}})}deleteFolder(e,t){return this.request({commandTimeout:!1,executor:(s,M)=>{this._socket.emit("deleteFolder",e,t,o=>{o?M(o):s()})}})}rename(e,t,s){return this.request({commandTimeout:!1,executor:(M,o)=>{this._socket.emit("rename",e,t,s,r=>{r?o(r):M()})}})}renameFile(e,t,s){return this.request({commandTimeout:!1,executor:(M,o)=>{this._socket.emit("renameFile",e,t,s,r=>{r?o(r):M()})}})}cmdExec(e,t,s,M){return this.request({commandTimeout:M,executor:(o,r,n)=>{e=Je(e),this._socket.emit("cmdExec",e,s,t,N=>{n.elapsed||(n.clearTimeout(),N?r(N):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",(M,o)=>{M?s(M):(o??={},o.common??={},o.native??={},t(o))})}})}getForeignStates(e){return this.request({commandTimeout:!1,executor:(t,s)=>{this._socket.emit("getForeignStates",e||"*",(M,o)=>{M?s(M):t(o??{})})}})}getForeignObjects(e,t){return this.request({commandTimeout:!1,executor:(s,M)=>{this._socket.emit("getForeignObjects",e||"*",t,(o,r)=>{o?M(o):s(r)})}})}setSystemConfig(e){return this.setObject("system.config",e)}getRawSocket(){return this._socket}getHistory(e,t){return this.request({commandTimeout:!1,executor:(s,M)=>{this._socket.emit("getHistory",e,t,(o,r)=>{o?M(o):s(r)})}})}getHistoryEx(e,t){return this.request({commandTimeout:!1,executor:(s,M)=>{this._socket.emit("getHistory",e,t,(o,r,n,N)=>{o?M(o):s({values:r,sessionId:N,step:n})})}})}getIpAddresses(e,t){return e=Je(e),this.request({cacheKey:`IPs_${e}`,forceUpdate:t,commandTimeout:!1,executor:async s=>{const M=await this.getObject(e);s((M==null?void 0:M.common.address)??[])}})}getVersion(e){return this.request({cacheKey:"version",forceUpdate:e,commandTimeout:!1,executor:(t,s)=>{this._socket.emit("getVersion",(M,o,r)=>{M&&!o&&typeof M=="string"&&M.match(/\d+\.\d+\.\d+/)?t({version:M,serverName:"socketio"}):M?s(M):t({version:o,serverName:r})})}})}getWebServerName(){return this.request({cacheKey:"webName",commandTimeout:!1,executor:(e,t)=>{this._socket.emit("getAdapterName",(s,M)=>{s?t(s):e(M)})}})}fileExists(e,t){return this.request({commandTimeout:!1,executor:(s,M)=>{this._socket.emit("fileExists",e,t,(o,r)=>{o?M(o):s(!!r)})}})}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,M)=>{this._socket.emit("checkFeatureSupported",e,(o,r)=>{o?M(o):s(r)})}})}getAdapterInstances(e,t){return typeof e=="boolean"&&(t=e,e=""),e=e||"",this.request({cacheKey:`instances_${e}`,forceUpdate:t,commandTimeout:!1,executor:async s=>{const M=e?`system.adapter.${e}.`:"system.adapter.",o=`${M}香`,r=await this.getObjectViewSystem("instance",M,o),n=Object.values(r);s(e?n.filter(N=>N.common.name===e):n)}})}getAdapters(e,t){return typeof e=="boolean"&&(t=e,e=""),e=e||"",this.request({cacheKey:`adapter_${e}`,forceUpdate:t,commandTimeout:!1,executor:async s=>{const M=await this.getObjectViewSystem("adapter",`system.adapter.${e||""}`,`system.adapter.${e||"香"}`),o=Object.values(M);s(e?o.filter(r=>r.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.香"},(M,o)=>{M?s(M):t(mM(o))})}})}logout(){return this.request({commandTimeout:!1,executor:(e,t)=>{this._socket.emit("logout",s=>{s?t(s):e(null)})}})}subscribeOnInstance(e,t,s,M){return this.request({commandTimeout:!1,executor:(o,r)=>{this._socket.emit("clientSubscribe",e,t,s,(n,N)=>{n?r(n):N&&(N.error?r(N.error):(e.startsWith("system.adapter.")||(e=`system.adapter.${e}`),this._instanceSubscriptions[e]=this._instanceSubscriptions[e]||[],this._instanceSubscriptions[e].find(u=>u.messageType===t&&u.callback===M)||this._instanceSubscriptions[e].push({messageType:t,callback:M}),o(N)))})}})}unsubscribeFromInstance(e,t,s){var r;e.startsWith("system.adapter.")||(e=`system.adapter.${e}`);let M;const o=[];do{M=!1;const n=(r=this._instanceSubscriptions[e])==null?void 0:r.findIndex(N=>(!t||N.messageType===t)&&(!s||N.callback===s));if(n!=null&&n!==-1){M=!0;const N=this._instanceSubscriptions[e][n].messageType;this._instanceSubscriptions[e].splice(n,1),this._instanceSubscriptions[e].length||delete this._instanceSubscriptions[e],this._instanceSubscriptions[e]&&this._instanceSubscriptions[e].find(L=>L.messageType===N)||o.push(this.request({commandTimeout:!1,executor:(L,c)=>{this._socket.emit("clientUnsubscribe",e,t,(l,j)=>l?c(l):L(j))}}))}}while(M&&(!s||!t));return o.length?Promise.all(o).then(n=>!!n.find(N=>N)):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 za(i,e){if(!e)return;let t;if(e.length<700&&(e.indexOf("/")!==-1||e.indexOf("\\")!==-1))if(i.toLowerCase().includes("private"))t="private";else if(e.toLowerCase().includes("private"))t="private";else if(i.toLowerCase().includes("public"))t="public";else if(e.toLowerCase().includes("public"))t="public";else if(i.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(M=>M.replace(/\r\n|\r|\n/,"").trim()).length>1&&(t="chained");return{name:i,type:t}}function Ia(i){var s,M,o,r;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((M=(s=i.native)==null?void 0:s.hardware)!=null&&M.networkInterfaces){const n=(r=(o=i.native)==null?void 0:o.hardware)==null?void 0:r.networkInterfaces;Object.keys(n).forEach(N=>{n[N].forEach(u=>{u.family!=="IPv6"?e.push({name:`[${u.family}] ${u.address} - ${N}`,address:u.address,family:"ipv4"}):t.push({name:`[${u.family}] ${u.address} - ${N}`,address:u.address,family:"ipv6"})})})}return{IPs4:e,IPs6:t}}class gNe extends ae{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 M;const s=await this.getObject("system.certificates");(M=s==null?void 0:s.native)!=null&&M.certificates?t(Object.entries(s.native.certificates).map(([o,r])=>za(o,r)).filter(o=>!!o)):t([])}})}getLogs(e,t=200){return this.request({commandTimeout:!1,executor:s=>{this._socket.emit("sendToHost",e,"getLogs",t||200,M=>{s(M)})}})}upgradeAdapterWithWebserver(e,t){return this.request({commandTimeout:!1,executor:s=>{this._socket.emit("sendToHost",e,"upgradeAdapterWithWebserver",t,M=>{s(M)})}})}upgradeController(e,t,s){return this.request({commandTimeout:!1,executor:(M,o)=>{this._socket.emit("sendToHost",e,"upgradeController",{version:t,adminInstance:s},r=>{const n=r;n.error?o(n.error):M(n.result)})}})}updateLicenses(e,t){return this.request({commandTimeout:!1,executor:(s,M)=>{this._socket.emit("updateLicenses",e,t,(o,r)=>{o?M(o):s(r)})}})}upgradeOsPackages(e,t,s){return this.request({commandTimeout:!1,executor:M=>{this._socket.emit("sendToHost",e,"upgradeOsPackages",{packages:t,restart:!!s},o=>{M(o)})}})}getLogsFiles(e){return this.request({commandTimeout:!1,executor:(t,s)=>{this._socket.emit("readLogs",e,(M,o)=>{M&&s(M),t(o)})}})}delLogs(e){return this.request({commandTimeout:!1,executor:(t,s)=>{this._socket.emit("sendToHost",e,"delLogs",null,M=>{M&&s(M),t()})}})}deleteFile(e,t){return this.request({commandTimeout:!1,executor:(s,M)=>{this._socket.emit("deleteFile",e,t,o=>{o&&M(o),s()})}})}deleteFolder(e,t){return this.request({commandTimeout:!1,executor:(s,M)=>{this._socket.emit("deleteFolder",e,t,o=>{o&&M(o),s()})}})}rename(e,t,s){return this.request({commandTimeout:!1,executor:(M,o)=>{this._socket.emit("rename",e,t,s,r=>{r&&o(r),M()})}})}renameFile(e,t,s){return this.request({commandTimeout:!1,executor:(M,o)=>{this._socket.emit("renameFile",e,t,s,r=>{r&&o(r),M()})}})}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.香"},(M,o)=>{M?s(M):t(mM(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.香"},(M,o)=>{M?s(M):t(mM(o))})}})}renameGroup(e,t,s){return this.request({commandTimeout:!1,executor:async M=>{const o=await this.getGroups(!0),r=o.filter(N=>N._id.startsWith(`${e}.`));for(const N of r){const u=N._id,L=t+N._id.substring(e.length);N._id=L,await this.setObject(L,N),await this.delObject(u)}const n=o.find(N=>N._id===e);if(n){const N=n._id;n._id=t,s!==void 0&&(n.common??={},n.common.name=s),await this.setObject(t,n),await this.delObject(N)}M()}})}getHostInfo(e,t,s){return e=Je(e),this.request({cacheKey:`hostInfo_${e}`,forceUpdate:t,commandTimeout:s,executor:(M,o,r)=>{this._socket.emit("sendToHost",e,"getHostInfo",null,n=>{r.elapsed||(r.clearTimeout(),n===ue.PERMISSION_ERROR?o('May not read "getHostInfo"'):n?M(n):o('Cannot read "getHostInfo"'))})}})}getHostInfoShort(e,t,s){return e=Je(e),this.request({cacheKey:`hostInfoShort_${e}`,forceUpdate:t,commandTimeout:s,executor:(M,o,r)=>{this._socket.emit("sendToHost",e,"getHostInfoShort",null,n=>{r.elapsed||(r.clearTimeout(),n===ue.PERMISSION_ERROR?o('May not read "getHostInfoShort"'):n?M(n):o('Cannot read "getHostInfoShort"'))})}})}getRepository(e,t,s,M){return this.request({cacheKey:`repository_${e}`,forceUpdate:s,commandTimeout:M,executor:(o,r,n)=>{this._socket.emit("sendToHost",e,"getRepository",t,N=>{n.elapsed||(n.clearTimeout(),N===ue.PERMISSION_ERROR?r('May not read "getRepository"'):N?o(N):r('Cannot read "getRepository"'))})}})}getInstalled(e,t,s){return e=Je(e),this.request({cacheKey:`installed_${e}`,forceUpdate:t,commandTimeout:s,executor:(M,o,r)=>{this._socket.emit("sendToHost",e,"getInstalled",null,n=>{r.elapsed||(r.clearTimeout(),n===ue.PERMISSION_ERROR?o('May not read "getInstalled"'):n?M(n):o('Cannot read "getInstalled"'))})}})}cmdExec(e,t,s,M){return this.request({commandTimeout:M,executor:(o,r,n)=>{e=Je(e),this._socket.emit("cmdExec",e,s,t,N=>{n.elapsed||(n.clearTimeout(),N&&r(N),o())})}})}readBaseSettings(e){return e=Bt(e),this.request({requireFeatures:["CONTROLLER_READWRITE_BASE_SETTINGS"],executor:(t,s,M)=>{this._socket.emit("sendToHost",e,"readBaseSettings",null,o=>{M.elapsed||(M.clearTimeout(),o===ue.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=Bt(e),this.request({requireFeatures:["CONTROLLER_READWRITE_BASE_SETTINGS"],executor:(s,M,o)=>{this._socket.emit("sendToHost",e,"writeBaseSettings",t,r=>{o.elapsed||(o.clearTimeout(),r===ue.PERMISSION_ERROR?M('May not write "BaseSettings"'):r?s(r):M('Cannot write "BaseSettings"'))})}})}restartController(e){return e=Bt(e),this.request({executor:(t,s,M)=>{this._socket.emit("sendToHost",e,"restartController",null,()=>{M.elapsed||(M.clearTimeout(),t(!0))})}})}getDiagData(e,t){return e=Bt(e),this.request({executor:(s,M,o)=>{this._socket.emit("sendToHost",e,"getDiagData",t,r=>{o.elapsed||(o.clearTimeout(),s(r||null))})}})}changePassword(e,t){return this.request({executor:(s,M,o)=>{this._socket.emit("changePassword",e,t,r=>{o.elapsed||(o.clearTimeout(),r&&M(r),s())})}})}getIpAddresses(e,t){return e=Je(e),this.request({cacheKey:`IPs_${e}`,forceUpdate:t,commandTimeout:!1,executor:async s=>{const M=await this.getObject(e);s((M==null?void 0:M.common.address)??[])}})}getHostByIp(e,t){return e=Bt(e),this.request({cacheKey:`rIPs_${e}`,forceUpdate:t,executor:(s,M,o)=>{this._socket.emit("getHostByIp",e,(r,n)=>{if(o.elapsed)return;o.clearTimeout();const{IPs4:N,IPs6:u}=Ia(n);s([...N,...u])})}})}encrypt(e){return this.request({executor:(t,s,M)=>{this._socket.emit("encrypt",e,(o,r)=>{M.elapsed||(M.clearTimeout(),o&&s(o),t(r))})}})}decrypt(e){return this.request({executor:(t,s,M)=>{this._socket.emit("decrypt",e,(o,r)=>{M.elapsed||(M.clearTimeout(),o&&s(o),t(r))})}})}chmodFile(e,t,s){return this.request({executor:(M,o,r)=>{this._socket.emit("chmodFile",e,t,s,(n,N)=>{r.elapsed||(r.clearTimeout(),n&&o(n),M(N))})}})}chownFile(e,t,s){return this.request({executor:(M,o,r)=>{this._socket.emit("chownFile",e,t,s,(n,N)=>{r.elapsed||(r.clearTimeout(),n&&o(n),M(N))})}})}getNotifications(e,t){return this.request({executor:(s,M,o)=>{this._socket.emit("sendToHost",e,"getNotifications",{category:t},r=>{o.elapsed||(o.clearTimeout(),s(r))})}})}clearNotifications(e,t){return this.request({executor:(s,M,o)=>{this._socket.emit("sendToHost",e,"clearNotifications",{category:t},r=>{o.elapsed||(o.clearTimeout(),s(r))})}})}getIsEasyModeStrict(){return this.request({executor:(e,t,s)=>{this._socket.emit("getIsEasyModeStrict",(M,o)=>{s.elapsed||(s.clearTimeout(),M&&t(M),e(!!o))})}})}getEasyMode(){return this.request({executor:(e,t,s)=>{this._socket.emit("getEasyMode",(M,o)=>{s.elapsed||(s.clearTimeout(),M?t(new Error(M)):e(o))})}})}getRatings(e){return this.request({executor:(t,s,M)=>{this._socket.emit("getRatings",!!e,(o,r)=>{M.elapsed||(M.clearTimeout(),o?s(new Error(o)):t(r))})}})}getCurrentSession(e){const t=new AbortController;return this.request({commandTimeout:e||5e3,onTimeout:()=>{t.abort()},executor:async(s,M,o)=>{try{const r=await fetch("./session",{signal:t.signal});if(o.elapsed)return;o.clearTimeout();const n=await r.json();s(n)}catch(r){M(`getCurrentSession: ${r}`)}}})}getCurrentInstance(){return this.request({cacheKey:"currentInstance",executor:(e,t,s)=>{this._socket.emit("getCurrentInstance",(M,o)=>{s.elapsed||(s.clearTimeout(),M?t(M):e(o))})}})}getAdapterInstances(e,t){let s;return typeof e=="boolean"?(t=e,s=""):s=e||"",this.request({cacheKey:`instances_${s}`,forceUpdate:t,executor:(M,o,r)=>{this._socket.emit("getAdapterInstances",s,(n,N)=>{r.elapsed||(r.clearTimeout(),n&&o(n),M(N))})}})}getAdapters(e,t){let s;return typeof e=="boolean"?(t=e,s=""):s=e||"",this.request({cacheKey:`adapter_${s}`,forceUpdate:t,executor:(M,o,r)=>{this._socket.emit("getAdapters",s,(n,N)=>{r.elapsed||(r.clearTimeout(),n&&o(n),M(N))})}})}getCompactAdapters(e){return this.request({cacheKey:"compactAdapters",forceUpdate:e,executor:(t,s,M)=>{this._socket.emit("getCompactAdapters",(o,r)=>{M.elapsed||(M.clearTimeout(),o&&s(o),t(r))})}})}getAdaptersResetCache(e){e=e??"",this.resetCache(`adapter_${e}`),this.resetCache("compactAdapters")}getCompactInstances(e){return this.request({cacheKey:"compactInstances",forceUpdate:e,executor:(t,s,M)=>{this._socket.emit("getCompactInstances",(o,r)=>{M.elapsed||(M.clearTimeout(),o&&s(o),t(r))})}})}getAdapterInstancesResetCache(e){e=e??"",this.resetCache(`instances_${e}`),this.resetCache("compactInstances")}getCompactInstalled(e,t,s){return e=Je(e),this.request({cacheKey:`installedCompact_${e}`,forceUpdate:t,commandTimeout:s,executor:(M,o,r)=>{this._socket.emit("getCompactInstalled",e,n=>{r.elapsed||(r.clearTimeout(),n===ue.PERMISSION_ERROR?o('May not read "getCompactInstalled"'):n?M(n):o('Cannot read "getCompactInstalled"'))})}})}getInstalledResetCache(e){e?(this.resetCache(`installedCompact_${e}`),this.resetCache(`installed_${e}`)):(this.resetCache("installedCompact_",!0),this.resetCache("installed_",!0))}getCompactRepository(e,t,s){return e=Je(e),this.request({cacheKey:`repositoryCompact_${e}`,forceUpdate:t,commandTimeout:s,executor:(M,o,r)=>{this._socket.emit("getCompactRepository",e,n=>{r.elapsed||(r.clearTimeout(),n===ue.PERMISSION_ERROR?o('May not read "getCompactRepository"'):n?M(n):o('Cannot read "getCompactRepository"'))})}})}getRepositoryResetCache(e){e?(this.resetCache(`repositoryCompact_${e}`),this.resetCache(`repository_${e}`)):(this.resetCache("repositoryCompact_",!0),this.resetCache("repository_",!0))}getCompactHosts(e){return this.request({cacheKey:"hostsCompact",forceUpdate:e,executor:(t,s,M)=>{this._socket.emit("getCompactHosts",(o,r)=>{M.elapsed||(M.clearTimeout(),o&&s(o),t(r))})}})}getCompactSystemRepositories(e){return this.request({cacheKey:"repositoriesCompact",forceUpdate:e,executor:(t,s,M)=>{this._socket.emit("getCompactSystemRepositories",(o,r)=>{M.elapsed||(M.clearTimeout(),o&&s(o),t(r))})}})}}const J=typeof __SENTRY_DEBUG__>"u"||__SENTRY_DEBUG__,V=globalThis,lt="9.46.0";function Rs(){return Gs(V),V}function Gs(i){const e=i.__SENTRY__=i.__SENTRY__||{};return e.version=e.version||lt,e[lt]=e[lt]||{}}function Ns(i,e,t=V){const s=t.__SENTRY__=t.__SENTRY__||{},M=s[lt]=s[lt]||{};return M[i]||(M[i]=e())}const Ca=["debug","info","warn","error","log","assert","trace"],wa="Sentry Logger ",vs={};function vt(i){if(!("console"in V))return i();const e=V.console,t={},s=Object.keys(vs);s.forEach(M=>{const o=vs[M];t[M]=e[M],e[M]=o});try{return i()}finally{s.forEach(M=>{e[M]=t[M]})}}function ha(){ui().enabled=!0}function Aa(){ui().enabled=!1}function xr(){return ui().enabled}function ma(...i){Ni("log",...i)}function Oa(...i){Ni("warn",...i)}function pa(...i){Ni("error",...i)}function Ni(i,...e){J&&xr()&&vt(()=>{V.console[i](`${wa}[${i}]:`,...e)})}function ui(){return J?Ns("loggerSettings",()=>({enabled:!1})):{enabled:!1}}const W={enable:ha,disable:Aa,isEnabled:xr,log:ma,warn:Oa,error:pa},Sr=50,jt="?",Hi=/\(error: (.*)\)/,Vi=/captureMessage|captureException/;function fr(...i){const e=i.sort((t,s)=>t[0]-s[0]).map(t=>t[1]);return(t,s=0,M=0)=>{const o=[],r=t.split(` `);for(let n=s;n<r.length;n++){const N=r[n];if(N.length>1024)continue;const u=Hi.test(N)?N.replace(Hi,"$1"):N;if(!u.match(/\S*Error: /)){for(const L of e){const c=L(u);if(c){o.push(c);break}}if(o.length>=Sr+M)break}}return _a(o.slice(M))}}function Ea(i){return Array.isArray(i)?fr(...i):i}function _a(i){if(!i.length)return[];const e=Array.from(i);return/sentryWrapped/.test(ys(e).function||"")&&e.pop(),e.reverse(),Vi.test(ys(e).function||"")&&(e.pop(),Vi.test(ys(e).function||"")&&e.pop()),e.slice(0,Sr).map(t=>({...t,filename:t.filename||ys(e).filename,function:t.function||jt}))}function ys(i){return i[i.length-1]||{}}const iM="<anonymous>";function Mt(i){try{return!i||typeof i!="function"?iM:i.name||iM}catch{return iM}}function Zi(i){const e=i.exception;if(e){const t=[];try{return e.values.forEach(s=>{s.stacktrace.frames&&t.push(...s.stacktrace.frames)}),t}catch{return}}}const fs={},Xi={};function dt(i,e){fs[i]=fs[i]||[],fs[i].push(e)}function zt(i,e){if(!Xi[i]){Xi[i]=!0;try{e()}catch(t){J&&W.error(`Error while instrumenting ${i}`,t)}}}function xe(i,e){const t=i&&fs[i];if(t)for(const s of t)try{s(e)}catch(M){J&&W.error(`Error while triggering instrumentation handler. Type: ${i} Name: ${Mt(s)} Error:`,M)}}let oM=null;function xa(i){const e="error";dt(e,i),zt(e,Sa)}function Sa(){oM=V.onerror,V.onerror=function(i,e,t,s,M){return xe("error",{column:s,error:M,line:t,msg:i,url:e}),oM?oM.apply(this,arguments):!1},V.onerror.__SENTRY_INSTRUMENTED__=!0}let rM=null;function fa(i){const e="unhandledrejection";dt(e,i),zt(e,ka)}function ka(){rM=V.onunhandledrejection,V.onunhandledrejection=function(i){return xe("unhandledrejection",i),rM?rM.apply(this,arguments):!0},V.onunhandledrejection.__SENTRY_INSTRUMENTED__=!0}const kr=Object.prototype.toString;function Li(i){switch(kr.call(i)){case"[object Error]":case"[object Exception]":case"[obj