Debian Codegraph @

doc/output/html/development.html

raw
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <meta http-equiv="X-UA-Compatible" content="IE=edge">
6 <meta name="viewport" content="width=device-width, initial-scale=1.0">
7 <meta name="generator" content="Asciidoctor 2.0.26">
8 <title>Developer Guide</title>
9 <style>
10 /*! Asciidoctor default stylesheet | MIT License | https://asciidoctor.org */
11 /* Uncomment the following line when using as a custom stylesheet */
12 /* @import "https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700"; */
13 html{font-family:sans-serif;-webkit-text-size-adjust:100%}
14 a{background:none}
15 a:focus{outline:thin dotted}
16 a:active,a:hover{outline:0}
17 h1{font-size:2em;margin:.67em 0}
18 b,strong{font-weight:bold}
19 abbr{font-size:.9em}
20 abbr[title]{cursor:help;border-bottom:1px dotted #dddddf;text-decoration:none}
21 dfn{font-style:italic}
22 hr{height:0}
23 mark{background:#ff0;color:#000}
24 code,kbd,pre,samp{font-family:monospace;font-size:1em}
25 pre{white-space:pre-wrap}
26 q{quotes:"\201C" "\201D" "\2018" "\2019"}
27 small{font-size:80%}
28 sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}
29 sup{top:-.5em}
30 sub{bottom:-.25em}
31 img{border:0}
32 svg:not(:root){overflow:hidden}
33 figure{margin:0}
34 audio,video{display:inline-block}
35 audio:not([controls]){display:none;height:0}
36 fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}
37 legend{border:0;padding:0}
38 button,input,select,textarea{font-family:inherit;font-size:100%;margin:0}
39 button,input{line-height:normal}
40 button,select{text-transform:none}
41 button,html input[type=button],input[type=reset],input[type=submit]{-webkit-appearance:button;cursor:pointer}
42 button[disabled],html input[disabled]{cursor:default}
43 input[type=checkbox],input[type=radio]{padding:0}
44 button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}
45 textarea{overflow:auto;vertical-align:top}
46 table{border-collapse:collapse;border-spacing:0}
47 *,::before,::after{box-sizing:border-box}
48 html,body{font-size:100%}
49 body{background:#fff;color:rgba(0,0,0,.8);padding:0;margin:0;font-family:"Noto Serif","DejaVu Serif",serif;line-height:1;position:relative;cursor:auto;-moz-tab-size:4;-o-tab-size:4;tab-size:4;word-wrap:anywhere;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased}
50 a:hover{cursor:pointer}
51 img,object,embed{max-width:100%;height:auto}
52 object,embed{height:100%}
53 img{-ms-interpolation-mode:bicubic}
54 .left{float:left!important}
55 .right{float:right!important}
56 .text-left{text-align:left!important}
57 .text-right{text-align:right!important}
58 .text-center{text-align:center!important}
59 .text-justify{text-align:justify!important}
60 .hide{display:none}
61 img,object,svg{display:inline-block;vertical-align:middle}
62 textarea{height:auto;min-height:50px}
63 select{width:100%}
64 .subheader,.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{line-height:1.45;color:#7a2518;font-weight:400;margin-top:0;margin-bottom:.25em}
65 div,dl,dt,dd,ul,ol,li,h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6,pre,form,p,blockquote,th,td{margin:0;padding:0}
66 a{color:#2156a5;text-decoration:underline;line-height:inherit}
67 a:hover,a:focus{color:#1d4b8f}
68 a img{border:0}
69 p{line-height:1.6;margin-bottom:1.25em;text-rendering:optimizeLegibility}
70 p aside{font-size:.875em;line-height:1.35;font-style:italic}
71 h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{font-family:"Open Sans","DejaVu Sans",sans-serif;font-weight:300;font-style:normal;color:#ba3925;text-rendering:optimizeLegibility;margin-top:1em;margin-bottom:.5em;line-height:1.0125em}
72 h1 small,h2 small,h3 small,#toctitle small,.sidebarblock>.content>.title small,h4 small,h5 small,h6 small{font-size:60%;color:#e99b8f;line-height:0}
73 h1{font-size:2.125em}
74 h2{font-size:1.6875em}
75 h3,#toctitle,.sidebarblock>.content>.title{font-size:1.375em}
76 h4,h5{font-size:1.125em}
77 h6{font-size:1em}
78 hr{border:solid #dddddf;border-width:1px 0 0;clear:both;margin:1.25em 0 1.1875em}
79 em,i{font-style:italic;line-height:inherit}
80 strong,b{font-weight:bold;line-height:inherit}
81 small{font-size:60%;line-height:inherit}
82 code{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;font-weight:400;color:rgba(0,0,0,.9)}
83 ul,ol,dl{line-height:1.6;margin-bottom:1.25em;list-style-position:outside;font-family:inherit}
84 ul,ol{margin-left:1.5em}
85 ul li ul,ul li ol{margin-left:1.25em;margin-bottom:0}
86 ul.circle{list-style-type:circle}
87 ul.disc{list-style-type:disc}
88 ul.square{list-style-type:square}
89 ul.circle ul:not([class]),ul.disc ul:not([class]),ul.square ul:not([class]){list-style:inherit}
90 ol li ul,ol li ol{margin-left:1.25em;margin-bottom:0}
91 dl dt{margin-bottom:.3125em;font-weight:bold}
92 dl dd{margin-bottom:1.25em}
93 blockquote{margin:0 0 1.25em;padding:.5625em 1.25em 0 1.1875em;border-left:1px solid #ddd}
94 blockquote,blockquote p{line-height:1.6;color:rgba(0,0,0,.85)}
95 @media screen and (min-width:768px){h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2}
96 h1{font-size:2.75em}
97 h2{font-size:2.3125em}
98 h3,#toctitle,.sidebarblock>.content>.title{font-size:1.6875em}
99 h4{font-size:1.4375em}}
100 table{background:#fff;margin-bottom:1.25em;border:1px solid #dedede;word-wrap:normal}
101 table thead,table tfoot{background:#f7f8f7}
102 table thead tr th,table thead tr td,table tfoot tr th,table tfoot tr td{padding:.5em .625em .625em;font-size:inherit;color:rgba(0,0,0,.8);text-align:left}
103 table tr th,table tr td{padding:.5625em .625em;font-size:inherit;color:rgba(0,0,0,.8)}
104 table tr.even,table tr.alt{background:#f8f8f7}
105 table thead tr th,table tfoot tr th,table tbody tr td,table tr td,table tfoot tr td{line-height:1.6}
106 h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2;word-spacing:-.05em}
107 h1 strong,h2 strong,h3 strong,#toctitle strong,.sidebarblock>.content>.title strong,h4 strong,h5 strong,h6 strong{font-weight:400}
108 .center{margin-left:auto;margin-right:auto}
109 .stretch{width:100%}
110 .clearfix::before,.clearfix::after,.float-group::before,.float-group::after{content:" ";display:table}
111 .clearfix::after,.float-group::after{clear:both}
112 :not(pre).nobreak{word-wrap:normal}
113 :not(pre).nowrap{white-space:nowrap}
114 :not(pre).pre-wrap{white-space:pre-wrap}
115 :not(pre):not([class^=L])>code{font-size:.9375em;font-style:normal!important;letter-spacing:0;padding:.1em .5ex;word-spacing:-.15em;background:#f7f7f8;border-radius:4px;line-height:1.45;text-rendering:optimizeSpeed}
116 pre{color:rgba(0,0,0,.9);font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;line-height:1.45;text-rendering:optimizeSpeed}
117 pre code,pre pre{color:inherit;font-size:inherit;line-height:inherit}
118 pre.nowrap,pre.nowrap pre{white-space:pre;word-wrap:normal}
119 em em{font-style:normal}
120 strong strong{font-weight:400}
121 .keyseq{color:rgba(51,51,51,.8)}
122 kbd{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;display:inline-block;color:rgba(0,0,0,.8);font-size:.65em;line-height:1.45;background:#f7f7f7;border:1px solid #ccc;border-radius:3px;box-shadow:0 1px 0 rgba(0,0,0,.2),inset 0 0 0 .1em #fff;margin:0 .15em;padding:.2em .5em;vertical-align:middle;position:relative;top:-.1em;white-space:nowrap}
123 .keyseq kbd:first-child{margin-left:0}
124 .keyseq kbd:last-child{margin-right:0}
125 .menuseq,.menuref{color:#000}
126 .menuseq b:not(.caret),.menuref{font-weight:inherit}
127 .menuseq{word-spacing:-.02em}
128 .menuseq b.caret{font-size:1.25em;line-height:.8}
129 .menuseq i.caret{font-weight:bold;text-align:center;width:.45em}
130 b.button::before,b.button::after{position:relative;top:-1px;font-weight:400}
131 b.button::before{content:"[";padding:0 3px 0 2px}
132 b.button::after{content:"]";padding:0 2px 0 3px}
133 p a>code:hover{color:rgba(0,0,0,.9)}
134 #header,#content,#footnotes,#footer{width:100%;margin:0 auto;max-width:62.5em;*zoom:1;position:relative;padding-left:.9375em;padding-right:.9375em}
135 #header::before,#header::after,#content::before,#content::after,#footnotes::before,#footnotes::after,#footer::before,#footer::after{content:" ";display:table}
136 #header::after,#content::after,#footnotes::after,#footer::after{clear:both}
137 #content{margin-top:1.25em}
138 #content::before{content:none}
139 #header>h1:first-child{color:rgba(0,0,0,.85);margin-top:2.25rem;margin-bottom:0}
140 #header>h1:first-child+#toc{margin-top:8px;border-top:1px solid #dddddf}
141 #header>h1:only-child{border-bottom:1px solid #dddddf;padding-bottom:8px}
142 #header .details{border-bottom:1px solid #dddddf;line-height:1.45;padding-top:.25em;padding-bottom:.25em;padding-left:.25em;color:rgba(0,0,0,.6);display:flex;flex-flow:row wrap}
143 #header .details span:first-child{margin-left:-.125em}
144 #header .details span.email a{color:rgba(0,0,0,.85)}
145 #header .details br{display:none}
146 #header .details br+span::before{content:"\00a0\2013\00a0"}
147 #header .details br+span.author::before{content:"\00a0\22c5\00a0";color:rgba(0,0,0,.85)}
148 #header .details br+span#revremark::before{content:"\00a0|\00a0"}
149 #header #revnumber{text-transform:capitalize}
150 #header #revnumber::after{content:"\00a0"}
151 #content>h1:first-child:not([class]){color:rgba(0,0,0,.85);border-bottom:1px solid #dddddf;padding-bottom:8px;margin-top:0;padding-top:1rem;margin-bottom:1.25rem}
152 #toc{border-bottom:1px solid #e7e7e9;padding-bottom:.5em}
153 #toc>ul{margin-left:.125em}
154 #toc ul.sectlevel0>li>a{font-style:italic}
155 #toc ul.sectlevel0 ul.sectlevel1{margin:.5em 0}
156 #toc ul{font-family:"Open Sans","DejaVu Sans",sans-serif;list-style-type:none}
157 #toc li{line-height:1.3334;margin-top:.3334em}
158 #toc a{text-decoration:none}
159 #toc a:active{text-decoration:underline}
160 #toctitle{color:#7a2518;font-size:1.2em}
161 @media screen and (min-width:768px){#toctitle{font-size:1.375em}
162 body.toc2{padding-left:15em;padding-right:0}
163 body.toc2 #header>h1:nth-last-child(2){border-bottom:1px solid #dddddf;padding-bottom:8px}
164 #toc.toc2{margin-top:0!important;background:#f8f8f7;position:fixed;width:15em;left:0;top:0;border-right:1px solid #e7e7e9;border-top-width:0!important;border-bottom-width:0!important;z-index:1000;padding:1.25em 1em;height:100%;overflow:auto}
165 #toc.toc2 #toctitle{margin-top:0;margin-bottom:.8rem;font-size:1.2em}
166 #toc.toc2>ul{font-size:.9em;margin-bottom:0}
167 #toc.toc2 ul ul{margin-left:0;padding-left:1em}
168 #toc.toc2 ul.sectlevel0 ul.sectlevel1{padding-left:0;margin-top:.5em;margin-bottom:.5em}
169 body.toc2.toc-right{padding-left:0;padding-right:15em}
170 body.toc2.toc-right #toc.toc2{border-right-width:0;border-left:1px solid #e7e7e9;left:auto;right:0}}
171 @media screen and (min-width:1280px){body.toc2{padding-left:20em;padding-right:0}
172 #toc.toc2{width:20em}
173 #toc.toc2 #toctitle{font-size:1.375em}
174 #toc.toc2>ul{font-size:.95em}
175 #toc.toc2 ul ul{padding-left:1.25em}
176 body.toc2.toc-right{padding-left:0;padding-right:20em}}
177 #content #toc{border:1px solid #e0e0dc;margin-bottom:1.25em;padding:1.25em;background:#f8f8f7;border-radius:4px}
178 #content #toc>:first-child{margin-top:0}
179 #content #toc>:last-child{margin-bottom:0}
180 #footer{max-width:none;background:rgba(0,0,0,.8);padding:1.25em}
181 #footer-text{color:hsla(0,0%,100%,.8);line-height:1.44}
182 #content{margin-bottom:.625em}
183 .sect1{padding-bottom:.625em}
184 @media screen and (min-width:768px){#content{margin-bottom:1.25em}
185 .sect1{padding-bottom:1.25em}}
186 .sect1:last-child{padding-bottom:0}
187 .sect1+.sect1{border-top:1px solid #e7e7e9}
188 #content h1>a.anchor,h2>a.anchor,h3>a.anchor,#toctitle>a.anchor,.sidebarblock>.content>.title>a.anchor,h4>a.anchor,h5>a.anchor,h6>a.anchor{position:absolute;z-index:1001;width:1.5ex;margin-left:-1.5ex;display:block;text-decoration:none!important;visibility:hidden;text-align:center;font-weight:400}
189 #content h1>a.anchor::before,h2>a.anchor::before,h3>a.anchor::before,#toctitle>a.anchor::before,.sidebarblock>.content>.title>a.anchor::before,h4>a.anchor::before,h5>a.anchor::before,h6>a.anchor::before{content:"\00A7";font-size:.85em;display:block;padding-top:.1em}
190 #content h1:hover>a.anchor,#content h1>a.anchor:hover,h2:hover>a.anchor,h2>a.anchor:hover,h3:hover>a.anchor,#toctitle:hover>a.anchor,.sidebarblock>.content>.title:hover>a.anchor,h3>a.anchor:hover,#toctitle>a.anchor:hover,.sidebarblock>.content>.title>a.anchor:hover,h4:hover>a.anchor,h4>a.anchor:hover,h5:hover>a.anchor,h5>a.anchor:hover,h6:hover>a.anchor,h6>a.anchor:hover{visibility:visible}
191 #content h1>a.link,h2>a.link,h3>a.link,#toctitle>a.link,.sidebarblock>.content>.title>a.link,h4>a.link,h5>a.link,h6>a.link{color:#ba3925;text-decoration:none}
192 #content h1>a.link:hover,h2>a.link:hover,h3>a.link:hover,#toctitle>a.link:hover,.sidebarblock>.content>.title>a.link:hover,h4>a.link:hover,h5>a.link:hover,h6>a.link:hover{color:#a53221}
193 details,.audioblock,.imageblock,.literalblock,.listingblock,.stemblock,.videoblock{margin-bottom:1.25em}
194 details{margin-left:1.25rem}
195 details>summary{cursor:pointer;display:block;position:relative;line-height:1.6;margin-bottom:.625rem;outline:none;-webkit-tap-highlight-color:transparent}
196 details>summary::-webkit-details-marker{display:none}
197 details>summary::before{content:"";border:solid transparent;border-left:solid;border-width:.3em 0 .3em .5em;position:absolute;top:.5em;left:-1.25rem;transform:translateX(15%)}
198 details[open]>summary::before{border:solid transparent;border-top:solid;border-width:.5em .3em 0;transform:translateY(15%)}
199 details>summary::after{content:"";width:1.25rem;height:1em;position:absolute;top:.3em;left:-1.25rem}
200 .admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{text-rendering:optimizeLegibility;text-align:left;font-family:"Noto Serif","DejaVu Serif",serif;font-size:1rem;font-style:italic}
201 table.tableblock.fit-content>caption.title{white-space:nowrap;width:0}
202 .paragraph.lead>p,#preamble>.sectionbody>[class=paragraph]:first-of-type p{font-size:1.21875em;line-height:1.6;color:rgba(0,0,0,.85)}
203 .admonitionblock>table{border-collapse:separate;border:0;background:none;width:100%}
204 .admonitionblock>table td.icon{text-align:center;width:80px}
205 .admonitionblock>table td.icon img{max-width:none}
206 .admonitionblock>table td.icon .title{font-weight:bold;font-family:"Open Sans","DejaVu Sans",sans-serif;text-transform:uppercase}
207 .admonitionblock>table td.content{padding-left:1.125em;padding-right:1.25em;border-left:1px solid #dddddf;color:rgba(0,0,0,.6);word-wrap:anywhere}
208 .admonitionblock>table td.content>:last-child>:last-child{margin-bottom:0}
209 .exampleblock>.content{border:1px solid #e6e6e6;margin-bottom:1.25em;padding:1.25em;background:#fff;border-radius:4px}
210 .sidebarblock{border:1px solid #dbdbd6;margin-bottom:1.25em;padding:1.25em;background:#f3f3f2;border-radius:4px}
211 .sidebarblock>.content>.title{color:#7a2518;margin-top:0;text-align:center}
212 .exampleblock>.content>:first-child,.sidebarblock>.content>:first-child{margin-top:0}
213 .exampleblock>.content>:last-child,.exampleblock>.content>:last-child>:last-child,.exampleblock>.content .olist>ol>li:last-child>:last-child,.exampleblock>.content .ulist>ul>li:last-child>:last-child,.exampleblock>.content .qlist>ol>li:last-child>:last-child,.sidebarblock>.content>:last-child,.sidebarblock>.content>:last-child>:last-child,.sidebarblock>.content .olist>ol>li:last-child>:last-child,.sidebarblock>.content .ulist>ul>li:last-child>:last-child,.sidebarblock>.content .qlist>ol>li:last-child>:last-child{margin-bottom:0}
214 .literalblock pre,.listingblock>.content>pre{border-radius:4px;overflow-x:auto;padding:1em;font-size:.8125em}
215 @media screen and (min-width:768px){.literalblock pre,.listingblock>.content>pre{font-size:.90625em}}
216 @media screen and (min-width:1280px){.literalblock pre,.listingblock>.content>pre{font-size:1em}}
217 .literalblock pre,.listingblock>.content>pre:not(.highlight),.listingblock>.content>pre[class=highlight],.listingblock>.content>pre[class^="highlight "]{background:#f7f7f8}
218 .literalblock.output pre{color:#f7f7f8;background:rgba(0,0,0,.9)}
219 .listingblock>.content{position:relative}
220 .listingblock pre>code{display:block}
221 .listingblock code[data-lang]::before{display:none;content:attr(data-lang);position:absolute;font-size:.75em;top:.425rem;right:.5rem;line-height:1;text-transform:uppercase;color:inherit;opacity:.5}
222 .listingblock:hover code[data-lang]::before{display:block}
223 .listingblock.terminal pre .command::before{content:attr(data-prompt);padding-right:.5em;color:inherit;opacity:.5}
224 .listingblock.terminal pre .command:not([data-prompt])::before{content:"$"}
225 .listingblock pre.highlightjs{padding:0}
226 .listingblock pre.highlightjs>code{padding:1em;border-radius:4px}
227 .listingblock pre.prettyprint{border-width:0}
228 .prettyprint{background:#f7f7f8}
229 pre.prettyprint .linenums{line-height:1.45;margin-left:2em}
230 pre.prettyprint li{background:none;list-style-type:inherit;padding-left:0}
231 pre.prettyprint li code[data-lang]::before{opacity:1}
232 pre.prettyprint li:not(:first-child) code[data-lang]::before{display:none}
233 table.linenotable{border-collapse:separate;border:0;margin-bottom:0;background:none}
234 table.linenotable td[class]{color:inherit;vertical-align:top;padding:0;line-height:inherit;white-space:normal}
235 table.linenotable td.code{padding-left:.75em}
236 table.linenotable td.linenos,pre.pygments .linenos{border-right:1px solid;opacity:.35;padding-right:.5em;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}
237 pre.pygments span.linenos{display:inline-block;margin-right:.75em}
238 .quoteblock{margin:0 1em 1.25em 1.5em;display:table}
239 .quoteblock:not(.excerpt)>.title{margin-left:-1.5em;margin-bottom:.75em}
240 .quoteblock blockquote,.quoteblock p{color:rgba(0,0,0,.85);font-size:1.15rem;line-height:1.75;word-spacing:.1em;letter-spacing:0;font-style:italic;text-align:justify}
241 .quoteblock blockquote{margin:0;padding:0;border:0}
242 .quoteblock blockquote::before{content:"\201c";float:left;font-size:2.75em;font-weight:bold;line-height:.6em;margin-left:-.6em;color:#7a2518;text-shadow:0 1px 2px rgba(0,0,0,.1)}
243 .quoteblock blockquote>.paragraph:last-child p{margin-bottom:0}
244 .quoteblock .attribution{margin-top:.75em;margin-right:.5ex;text-align:right}
245 .verseblock{margin:0 1em 1.25em}
246 .verseblock pre{font-family:"Open Sans","DejaVu Sans",sans-serif;font-size:1.15rem;color:rgba(0,0,0,.85);font-weight:300;text-rendering:optimizeLegibility}
247 .verseblock pre strong{font-weight:400}
248 .verseblock .attribution{margin-top:1.25rem;margin-left:.5ex}
249 .quoteblock .attribution,.verseblock .attribution{font-size:.9375em;line-height:1.45;font-style:italic}
250 .quoteblock .attribution br,.verseblock .attribution br{display:none}
251 .quoteblock .attribution cite,.verseblock .attribution cite{display:block;letter-spacing:-.025em;color:rgba(0,0,0,.6)}
252 .quoteblock.abstract blockquote::before,.quoteblock.excerpt blockquote::before,.quoteblock .quoteblock blockquote::before{display:none}
253 .quoteblock.abstract blockquote,.quoteblock.abstract p,.quoteblock.excerpt blockquote,.quoteblock.excerpt p,.quoteblock .quoteblock blockquote,.quoteblock .quoteblock p{line-height:1.6;word-spacing:0}
254 .quoteblock.abstract{margin:0 1em 1.25em;display:block}
255 .quoteblock.abstract>.title{margin:0 0 .375em;font-size:1.15em;text-align:center}
256 .quoteblock.excerpt>blockquote,.quoteblock .quoteblock{padding:0 0 .25em 1em;border-left:.25em solid #dddddf}
257 .quoteblock.excerpt,.quoteblock .quoteblock{margin-left:0}
258 .quoteblock.excerpt blockquote,.quoteblock.excerpt p,.quoteblock .quoteblock blockquote,.quoteblock .quoteblock p{color:inherit;font-size:1.0625rem}
259 .quoteblock.excerpt .attribution,.quoteblock .quoteblock .attribution{color:inherit;font-size:.85rem;text-align:left;margin-right:0}
260 p.tableblock:last-child{margin-bottom:0}
261 td.tableblock>.content{margin-bottom:1.25em;word-wrap:anywhere}
262 td.tableblock>.content>:last-child{margin-bottom:-1.25em}
263 table.tableblock,th.tableblock,td.tableblock{border:0 solid #dedede}
264 table.grid-all>*>tr>*{border-width:1px}
265 table.grid-cols>*>tr>*{border-width:0 1px}
266 table.grid-rows>*>tr>*{border-width:1px 0}
267 table.frame-all{border-width:1px}
268 table.frame-ends{border-width:1px 0}
269 table.frame-sides{border-width:0 1px}
270 table.frame-none>colgroup+*>:first-child>*,table.frame-sides>colgroup+*>:first-child>*{border-top-width:0}
271 table.frame-none>:last-child>:last-child>*,table.frame-sides>:last-child>:last-child>*{border-bottom-width:0}
272 table.frame-none>*>tr>:first-child,table.frame-ends>*>tr>:first-child{border-left-width:0}
273 table.frame-none>*>tr>:last-child,table.frame-ends>*>tr>:last-child{border-right-width:0}
274 table.stripes-all>*>tr,table.stripes-odd>*>tr:nth-of-type(odd),table.stripes-even>*>tr:nth-of-type(even),table.stripes-hover>*>tr:hover{background:#f8f8f7}
275 th.halign-left,td.halign-left{text-align:left}
276 th.halign-right,td.halign-right{text-align:right}
277 th.halign-center,td.halign-center{text-align:center}
278 th.valign-top,td.valign-top{vertical-align:top}
279 th.valign-bottom,td.valign-bottom{vertical-align:bottom}
280 th.valign-middle,td.valign-middle{vertical-align:middle}
281 table thead th,table tfoot th{font-weight:bold}
282 tbody tr th{background:#f7f8f7}
283 tbody tr th,tbody tr th p,tfoot tr th,tfoot tr th p{color:rgba(0,0,0,.8);font-weight:bold}
284 p.tableblock>code:only-child{background:none;padding:0}
285 p.tableblock{font-size:1em}
286 ol{margin-left:1.75em}
287 ul li ol{margin-left:1.5em}
288 dl dd{margin-left:1.125em}
289 dl dd:last-child,dl dd:last-child>:last-child{margin-bottom:0}
290 li p,ul dd,ol dd,.olist .olist,.ulist .ulist,.ulist .olist,.olist .ulist{margin-bottom:.625em}
291 ul.checklist,ul.none,ol.none,ul.no-bullet,ol.no-bullet,ol.unnumbered,ul.unstyled,ol.unstyled{list-style-type:none}
292 ul.no-bullet,ol.no-bullet,ol.unnumbered{margin-left:.625em}
293 ul.unstyled,ol.unstyled{margin-left:0}
294 li>p:empty:only-child::before{content:"";display:inline-block}
295 ul.checklist>li>p:first-child{margin-left:-1em}
296 ul.checklist>li>p:first-child>.fa-square-o:first-child,ul.checklist>li>p:first-child>.fa-check-square-o:first-child{width:1.25em;font-size:.8em;position:relative;bottom:.125em}
297 ul.checklist>li>p:first-child>input[type=checkbox]:first-child{margin-right:.25em}
298 ul.inline{display:flex;flex-flow:row wrap;list-style:none;margin:0 0 .625em -1.25em}
299 ul.inline>li{margin-left:1.25em}
300 .unstyled dl dt{font-weight:400;font-style:normal}
301 ol.arabic{list-style-type:decimal}
302 ol.decimal{list-style-type:decimal-leading-zero}
303 ol.loweralpha{list-style-type:lower-alpha}
304 ol.upperalpha{list-style-type:upper-alpha}
305 ol.lowerroman{list-style-type:lower-roman}
306 ol.upperroman{list-style-type:upper-roman}
307 ol.lowergreek{list-style-type:lower-greek}
308 .hdlist>table,.colist>table{border:0;background:none}
309 .hdlist>table>tbody>tr,.colist>table>tbody>tr{background:none}
310 td.hdlist1,td.hdlist2{vertical-align:top;padding:0 .625em}
311 td.hdlist1{font-weight:bold;padding-bottom:1.25em}
312 td.hdlist2{word-wrap:anywhere}
313 .literalblock+.colist,.listingblock+.colist{margin-top:-.5em}
314 .colist td:not([class]):first-child{padding:.4em .75em 0;line-height:1;vertical-align:top}
315 .colist td:not([class]):first-child img{max-width:none}
316 .colist td:not([class]):last-child{padding:.25em 0}
317 .thumb,.th{line-height:0;display:inline-block;border:4px solid #fff;box-shadow:0 0 0 1px #ddd}
318 .imageblock.left{margin:.25em .625em 1.25em 0}
319 .imageblock.right{margin:.25em 0 1.25em .625em}
320 .imageblock>.title{margin-bottom:0}
321 .imageblock.thumb,.imageblock.th{border-width:6px}
322 .imageblock.thumb>.title,.imageblock.th>.title{padding:0 .125em}
323 .image.left,.image.right{margin-top:.25em;margin-bottom:.25em;display:inline-block;line-height:0}
324 .image.left{margin-right:.625em}
325 .image.right{margin-left:.625em}
326 a.image{text-decoration:none;display:inline-block}
327 a.image object{pointer-events:none}
328 sup.footnote,sup.footnoteref{font-size:.875em;position:static;vertical-align:super}
329 sup.footnote a,sup.footnoteref a{text-decoration:none}
330 sup.footnote a:active,sup.footnoteref a:active,#footnotes .footnote a:first-of-type:active{text-decoration:underline}
331 #footnotes{padding-top:.75em;padding-bottom:.75em;margin-bottom:.625em}
332 #footnotes hr{width:20%;min-width:6.25em;margin:-.25em 0 .75em;border-width:1px 0 0}
333 #footnotes .footnote{padding:0 .375em 0 .225em;line-height:1.3334;font-size:.875em;margin-left:1.2em;margin-bottom:.2em}
334 #footnotes .footnote a:first-of-type{font-weight:bold;text-decoration:none;margin-left:-1.05em}
335 #footnotes .footnote:last-of-type{margin-bottom:0}
336 #content #footnotes{margin-top:-.625em;margin-bottom:0;padding:.75em 0}
337 div.unbreakable{page-break-inside:avoid}
338 .big{font-size:larger}
339 .small{font-size:smaller}
340 .underline{text-decoration:underline}
341 .overline{text-decoration:overline}
342 .line-through{text-decoration:line-through}
343 .aqua{color:#00bfbf}
344 .aqua-background{background:#00fafa}
345 .black{color:#000}
346 .black-background{background:#000}
347 .blue{color:#0000bf}
348 .blue-background{background:#0000fa}
349 .fuchsia{color:#bf00bf}
350 .fuchsia-background{background:#fa00fa}
351 .gray{color:#606060}
352 .gray-background{background:#7d7d7d}
353 .green{color:#006000}
354 .green-background{background:#007d00}
355 .lime{color:#00bf00}
356 .lime-background{background:#00fa00}
357 .maroon{color:#600000}
358 .maroon-background{background:#7d0000}
359 .navy{color:#000060}
360 .navy-background{background:#00007d}
361 .olive{color:#606000}
362 .olive-background{background:#7d7d00}
363 .purple{color:#600060}
364 .purple-background{background:#7d007d}
365 .red{color:#bf0000}
366 .red-background{background:#fa0000}
367 .silver{color:#909090}
368 .silver-background{background:#bcbcbc}
369 .teal{color:#006060}
370 .teal-background{background:#007d7d}
371 .white{color:#bfbfbf}
372 .white-background{background:#fafafa}
373 .yellow{color:#bfbf00}
374 .yellow-background{background:#fafa00}
375 span.icon>.fa{cursor:default}
376 a span.icon>.fa{cursor:inherit}
377 .admonitionblock td.icon [class^="fa icon-"]{font-size:2.5em;text-shadow:1px 1px 2px rgba(0,0,0,.5);cursor:default}
378 .admonitionblock td.icon .icon-note::before{content:"\f05a";color:#19407c}
379 .admonitionblock td.icon .icon-tip::before{content:"\f0eb";text-shadow:1px 1px 2px rgba(155,155,0,.8);color:#111}
380 .admonitionblock td.icon .icon-warning::before{content:"\f071";color:#bf6900}
381 .admonitionblock td.icon .icon-caution::before{content:"\f06d";color:#bf3400}
382 .admonitionblock td.icon .icon-important::before{content:"\f06a";color:#bf0000}
383 .conum[data-value]{display:inline-block;color:#fff!important;background:rgba(0,0,0,.8);border-radius:50%;text-align:center;font-size:.75em;width:1.67em;height:1.67em;line-height:1.67em;font-family:"Open Sans","DejaVu Sans",sans-serif;font-style:normal;font-weight:bold}
384 .conum[data-value] *{color:#fff!important}
385 .conum[data-value]+b{display:none}
386 .conum[data-value]::after{content:attr(data-value)}
387 pre .conum[data-value]{position:relative;top:-.125em}
388 b.conum *{color:inherit!important}
389 .conum:not([data-value]):empty{display:none}
390 dt,th.tableblock,td.content,div.footnote{text-rendering:optimizeLegibility}
391 h1,h2,p,td.content,span.alt,summary{letter-spacing:-.01em}
392 p strong,td.content strong,div.footnote strong{letter-spacing:-.005em}
393 p,blockquote,dt,td.content,td.hdlist1,span.alt,summary{font-size:1.0625rem}
394 p{margin-bottom:1.25rem}
395 .sidebarblock p,.sidebarblock dt,.sidebarblock td.content,p.tableblock{font-size:1em}
396 .exampleblock>.content{background:#fffef7;border-color:#e0e0dc;box-shadow:0 1px 4px #e0e0dc}
397 .print-only{display:none!important}
398 @page{margin:1.25cm .75cm}
399 @media print{*{box-shadow:none!important;text-shadow:none!important}
400 html{font-size:80%}
401 a{color:inherit!important;text-decoration:underline!important}
402 a.bare,a[href^="#"],a[href^="mailto:"]{text-decoration:none!important}
403 a[href^="http:"]:not(.bare)::after,a[href^="https:"]:not(.bare)::after{content:"(" attr(href) ")";display:inline-block;font-size:.875em;padding-left:.25em}
404 abbr[title]{border-bottom:1px dotted}
405 abbr[title]::after{content:" (" attr(title) ")"}
406 pre,blockquote,tr,img,object,svg{page-break-inside:avoid}
407 thead{display:table-header-group}
408 svg{max-width:100%}
409 p,blockquote,dt,td.content{font-size:1em;orphans:3;widows:3}
410 h2,h3,#toctitle,.sidebarblock>.content>.title{page-break-after:avoid}
411 #header,#content,#footnotes,#footer{max-width:none}
412 #toc,.sidebarblock,.exampleblock>.content{background:none!important}
413 #toc{border-bottom:1px solid #dddddf!important;padding-bottom:0!important}
414 body.book #header{text-align:center}
415 body.book #header>h1:first-child{border:0!important;margin:2.5em 0 1em}
416 body.book #header .details{border:0!important;display:block;padding:0!important}
417 body.book #header .details span:first-child{margin-left:0!important}
418 body.book #header .details br{display:block}
419 body.book #header .details br+span::before{content:none!important}
420 body.book #toc{border:0!important;text-align:left!important;padding:0!important;margin:0!important}
421 body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-break-before:always}
422 .listingblock code[data-lang]::before{display:block}
423 #footer{padding:0 .9375em}
424 .hide-on-print{display:none!important}
425 .print-only{display:block!important}
426 .hide-for-print{display:none!important}
427 .show-for-print{display:inherit!important}}
428 @media amzn-kf8,print{#header>h1:first-child{margin-top:1.25rem}
429 .sect1{padding:0!important}
430 .sect1+.sect1{border:0}
431 #footer{background:none}
432 #footer-text{color:rgba(0,0,0,.6);font-size:.9em}}
433 @media amzn-kf8{#header,#content,#footnotes,#footer{padding:0}}
434 </style>
435 </head>
436 <body id="development" class="article toc2 toc-left">
437 <div id="header">
438 <h1>Developer Guide</h1>
439 <div id="toc" class="toc2">
440 <div id="toctitle">Table of Contents</div>
441 <ul class="sectlevel1">
442 <li><a href="#embedding">Embedding and Integrating Cockpit</a>
443 <ul class="sectlevel2">
444 <li><a href="#embedding-full">Embedding the Cockpit Interface</a></li>
445 <li><a href="#embedding-components">Integrating Cockpit Components into Web Applications</a></li>
446 <li><a href="#embedding-deep">Deep Integration</a></li>
447 <li><a href="#embedding-cors">Pinging Cockpit</a></li>
448 </ul>
449 </li>
450 <li><a href="#packages">Cockpit Packages</a>
451 <ul class="sectlevel2">
452 <li><a href="#package-layout">Layout of Package Files</a></li>
453 <li><a href="#_package_manifest">Package Manifest</a></li>
454 <li><a href="#package-manifest-override">Manifest overrides</a></li>
455 <li><a href="#package-links">Package Links and Paths</a></li>
456 <li><a href="#package-minified">Content Negotiation</a></li>
457 <li><a href="#package-api">Using Cockpit API</a></li>
458 <li><a href="#package-bridges">Bridges for specific tasks</a></li>
459 <li><a href="#package-replace">Replacing an existing package</a></li>
460 </ul>
461 </li>
462 <li><a href="#urls">Cockpit URLs</a>
463 <ul class="sectlevel2">
464 <li><a href="#urls-components">Component URLs</a></li>
465 <li><a href="#urls-visible">Visible URLs</a></li>
466 </ul>
467 </li>
468 <li><a href="#_api_base1">API: base1</a>
469 <ul class="sectlevel2">
470 <li><a href="#_cockpit_js">cockpit.js</a>
471 <ul class="sectlevel3">
472 <li><a href="#api-cockpit-loading">Loading cockpit.js</a></li>
473 </ul>
474 </li>
475 <li><a href="#_cockpit_js_object_caching">cockpit.js: Object Caching</a>
476 <ul class="sectlevel3">
477 <li><a href="#cockpit-cache-func">cockpit.cache()</a></li>
478 <li><a href="#cockpit-cache-close">cache.close()</a></li>
479 </ul>
480 </li>
481 <li><a href="#_cockpit_js_raw_channels">cockpit.js: Raw Channels</a>
482 <ul class="sectlevel3">
483 <li><a href="#cockpit-channels-channel">cockpit.channel()</a></li>
484 <li><a href="#cockpit-channels-binary">channel.binary</a></li>
485 <li><a href="#cockpit-channels-options">channel.options</a></li>
486 <li><a href="#cockpit-channels-valid">channel.valid</a></li>
487 <li><a href="#cockpit-channels-send">channel.send()</a></li>
488 <li><a href="#cockpit-channels-control">channel.control()</a></li>
489 <li><a href="#cockpit-channels-wait">channel.wait()</a></li>
490 <li><a href="#cockpit-channels-close">channel.close()</a></li>
491 <li><a href="#cockpit-channels-message">channel.onmessage</a></li>
492 <li><a href="#cockpit-channels-oncontrol">channel.oncontrol</a></li>
493 <li><a href="#cockpit-channels-onready">channel.onready</a></li>
494 <li><a href="#cockpit-channels-close-ev">channel.onclose</a></li>
495 <li><a href="#cockpit-transport-origin">cockpit.transport.origin</a></li>
496 <li><a href="#cockpit-transport-host">cockpit.transport.host</a></li>
497 <li><a href="#cockpit-transport-csrf-token">cockpit.transport.csrf_token</a></li>
498 <li><a href="#cockpit-transport-options">cockpit.transport.options</a></li>
499 <li><a href="#cockpit-transport-wait">cockpit.transport.wait()</a></li>
500 <li><a href="#cockpit-transport-close">cockpit.transport.close()</a></li>
501 <li><a href="#cockpit-transport-filter">cockpit.transport.filter()</a></li>
502 <li><a href="#cockpit-transport-inject">cockpit.transport.inject()</a></li>
503 <li><a href="#cockpit-base64-encode">cockpit.base64_encode()</a></li>
504 <li><a href="#cockpit-base64-decode">cockpit.base64_decode()</a></li>
505 </ul>
506 </li>
507 <li><a href="#_cockpit_js_dbus_client">cockpit.js: DBus Client</a>
508 <ul class="sectlevel3">
509 <li><a href="#cockpit-dbus-types">DBus Types</a></li>
510 <li><a href="#cockpit-dbus-dbus">cockpit.dbus()</a></li>
511 <li><a href="#cockpit-dbus-wait">client.wait()</a></li>
512 <li><a href="#cockpit-dbus-close">client.close()</a></li>
513 <li><a href="#cockpit-dbus-onclose">client.onclose</a></li>
514 <li><a href="#cockpit-dbus-onowned">client.onowner</a></li>
515 <li><a href="#cockpit-dbus-options">client.options</a></li>
516 <li><a href="#cockpit-dbus-unique-name">client.unique_name</a></li>
517 <li><a href="#cockpit-dbus-proxy">client.proxy()</a></li>
518 <li><a href="#cockpit-dbus-proxy-client">proxy.client</a></li>
519 <li><a href="#cockpit-dbus-proxy-path">proxy.path</a></li>
520 <li><a href="#cockpit-dbus-proxy-iface">proxy.iface</a></li>
521 <li><a href="#cockpit-dbus-proxy-valid">proxy.valid</a></li>
522 <li><a href="#cockpit-dbus-proxy-data">proxy.data</a></li>
523 <li><a href="#cockpit-dbus-proxy-call">proxy.call()</a></li>
524 <li><a href="#cockpit-dbus-proxy-wait">proxy.wait()</a></li>
525 <li><a href="#cockpit-dbus-proxy-onchanged">proxy.onchanged</a></li>
526 <li><a href="#cockpit-dbus-proxy-signal">proxy.onsignal</a></li>
527 <li><a href="#cockpit-dbus-proxies">client.proxies()</a></li>
528 <li><a href="#cockpit-dbus-proxies-wait">proxies.wait()</a></li>
529 <li><a href="#cockpit-dbus-proxies-client">proxies.client</a></li>
530 <li><a href="#cockpit-dbus-proxies-iface">proxies.iface</a></li>
531 <li><a href="#cockpit-dbus-proxies-path_namespace">proxies.path_namespace</a></li>
532 <li><a href="#cockpit-dbus-proxies-onadded">proxies.onadded</a></li>
533 <li><a href="#cockpit-dbus-proxies-onchanged">proxies.onchanged</a></li>
534 <li><a href="#cockpit-dbus-proxies-onremoved">proxies.onremoved</a></li>
535 <li><a href="#cockpit-dbus-call">client.call()</a></li>
536 <li><a href="#cockpit-dbus-then">invocation.then()</a></li>
537 <li><a href="#cockpit-dbus-catch">invocation.catch()</a></li>
538 <li><a href="#cockpit-dbus-subscribe">client.subscribe()</a></li>
539 <li><a href="#cockpit-dbus-remove">subscription.remove()</a></li>
540 <li><a href="#cockpit-dbus-watch">client.watch()</a></li>
541 <li><a href="#cockpit-dbus-watch-then">watch.then()</a></li>
542 <li><a href="#cockpit-dbus-watch-catch">watch.catch()</a></li>
543 <li><a href="#cockpit-dbus-watch-remove">watch.remove()</a></li>
544 <li><a href="#cockpit-dbus-onnotify">client.onnotify</a></li>
545 <li><a href="#cockpit-dbus-notify">client.notify()</a></li>
546 <li><a href="#cockpit-dbus-onmeta">client.onmeta</a></li>
547 <li><a href="#cockpit-dbus-variant">cockpit.variant()</a></li>
548 </ul>
549 </li>
550 <li><a href="#_cockpit_js_errors">cockpit.js: Errors</a>
551 <ul class="sectlevel3">
552 <li><a href="#cockpit-problems">Problem Codes</a></li>
553 <li><a href="#cockpit-messages">cockpit.message()</a></li>
554 </ul>
555 </li>
556 <li><a href="#_cockpit_js_file_access">cockpit.js: File Access</a>
557 <ul class="sectlevel3">
558 <li><a href="#cockpit-file-simple">Simple reading and writing</a></li>
559 <li><a href="#cockpit-file-format">File format</a></li>
560 <li><a href="#cockpit-file-binary">Binary files</a></li>
561 <li><a href="#cockpit-file-atomic">Atomic modifications</a></li>
562 <li><a href="#cockpit-file-notify">Change notifications</a></li>
563 <li><a href="#cockpit-file-path">file.path</a></li>
564 <li><a href="#cockpit-file-close">Closing</a></li>
565 </ul>
566 </li>
567 <li><a href="#_cockpit_js_http_client">cockpit.js: HTTP Client</a>
568 <ul class="sectlevel3">
569 <li><a href="#cockpit-http-constructor">cockpit.http()</a></li>
570 <li><a href="#cockpit-http-get">http.get()</a></li>
571 <li><a href="#cockpit-http-post">http.post()</a></li>
572 <li><a href="#cockpit-http-request">http.request()</a></li>
573 <li><a href="#cockpit-http-then">request.then()</a></li>
574 <li><a href="#cockpit-http-catch">request.catch()</a></li>
575 <li><a href="#cockpit-http-response">request.response()</a></li>
576 <li><a href="#cockpit-http-stream">request.stream()</a></li>
577 <li><a href="#cockpit-http-input">request.input()</a></li>
578 <li><a href="#cockpit-http-close">request.close()</a></li>
579 <li><a href="#cockpit-http-close-all">http.close()</a></li>
580 </ul>
581 </li>
582 <li><a href="#_cockpit_js_localization">cockpit.js: Localization</a>
583 <ul class="sectlevel3">
584 <li><a href="#cockpit-locale-language">cockpit.language</a></li>
585 <li><a href="#cockpit-locale-locale">cockpit.locale()</a></li>
586 <li><a href="#cockpit-locale-gettext">cockpit.gettext()</a></li>
587 <li><a href="#cockpit-locale-noop">cockpit.noop()</a></li>
588 <li><a href="#cockpit-locale-ngettext">cockpit.ngettext()</a></li>
589 <li><a href="#cockpit-locale-translate">cockpit.translate()</a></li>
590 </ul>
591 </li>
592 <li><a href="#_cockpit_js_page_location_and_jumping">cockpit.js: Page Location and Jumping</a>
593 <ul class="sectlevel3">
594 <li><a href="#cockpit-location-general">Page location</a></li>
595 <li><a href="#cockpit-jump">Jumping between components</a></li>
596 </ul>
597 </li>
598 <li><a href="#_cockpit_js_user_session">cockpit.js: User Session</a>
599 <ul class="sectlevel3">
600 <li><a href="#cockpit-logout">cockpit.logout()</a></li>
601 <li><a href="#cockpit-user">cockpit.user()</a></li>
602 <li><a href="#cockpit-permission">Permission lookup</a></li>
603 </ul>
604 </li>
605 <li><a href="#_cockpit_js_manifests">cockpit.js: Manifests</a>
606 <ul class="sectlevel3">
607 <li><a href="#cockpit-manifest-loading">Loading Manifests</a></li>
608 </ul>
609 </li>
610 <li><a href="#_cockpit_js_metrics">cockpit.js: Metrics</a>
611 <ul class="sectlevel3">
612 <li><a href="#cockpit-metrics-function">cockpit.metrics()</a></li>
613 <li><a href="#cockpit-metrics-fetch">metrics.fetch()</a></li>
614 <li><a href="#cockpit-metrics-follow">metrics.follow()</a></li>
615 <li><a href="#cockpit-metrics-close">metrics.close()</a></li>
616 <li><a href="#cockpit-metrics-series">metrics.series</a></li>
617 <li><a href="#cockpit-metrics-meta">metrics.meta</a></li>
618 <li><a href="#cockpit-metrics-onchanged">metrics.onchanged</a></li>
619 </ul>
620 </li>
621 <li><a href="#_cockpit_js_series_data">cockpit.js: Series Data</a>
622 <ul class="sectlevel3">
623 <li><a href="#cockpit-grid">cockpit.grid()</a></li>
624 <li><a href="#cockpit-grid-add">grid.add()</a></li>
625 <li><a href="#cockpit-grid-remove">grid.remove()</a></li>
626 <li><a href="#cockpit-grid-sync">grid.sync()</a></li>
627 <li><a href="#cockpit-grid-move">grid.move()</a></li>
628 <li><a href="#cockpit-grid-walk">grid.walk()</a></li>
629 <li><a href="#cockpit-grid-notify">grid.notify()</a></li>
630 <li><a href="#cockpit-grid-onnotify">grid.onnotify</a></li>
631 <li><a href="#cockpit-grid-close">grid.close()</a></li>
632 <li><a href="#cockpit-grid-interval">grid.interval</a></li>
633 <li><a href="#cockpit-grid-beg">grid.beg</a></li>
634 <li><a href="#cockpit-grid-end">grid.end</a></li>
635 <li><a href="#cockpit-series">cockpit.series()</a></li>
636 <li><a href="#cockpit-series-input">series.input()</a></li>
637 <li><a href="#cockpit-series-load">series.load()</a></li>
638 <li><a href="#cockpit-series-interval">series.interval</a></li>
639 <li><a href="#cockpit-series-limit">series.limit</a></li>
640 </ul>
641 </li>
642 <li><a href="#_cockpit_js_spawning_processes">cockpit.js: Spawning Processes</a>
643 <ul class="sectlevel3">
644 <li><a href="#cockpit-spawn-spawn">cockpit.spawn()</a></li>
645 <li><a href="#cockpit-spawn-script">cockpit.script()</a></li>
646 <li><a href="#cockpit-spawn-then">process.then()</a></li>
647 <li><a href="#cockpit-spawn-catch">process.catch()</a></li>
648 <li><a href="#cockpit-spawn-stream">process.stream()</a></li>
649 <li><a href="#cockpit-spawn-input">process.input()</a></li>
650 <li><a href="#cockpit-spawn-close">process.close()</a></li>
651 </ul>
652 </li>
653 <li><a href="#_cockpit_js_utilities">cockpit.js: Utilities</a>
654 <ul class="sectlevel3">
655 <li><a href="#cockpit-format">cockpit.format()</a></li>
656 <li><a href="#cockpit-format-number">cockpit.format_number()</a></li>
657 <li><a href="#cockpit-format-bytes">cockpit.format_bytes()</a></li>
658 <li><a href="#cockpit-format-bytes-per-sec">cockpit.format_bytes_per_sec()</a></li>
659 <li><a href="#cockpit-format-bits-per-sec">cockpit.format_bits_per_sec()</a></li>
660 <li><a href="#cockpit-init">cockpit.init()</a></li>
661 <li><a href="#cockpit-info">cockpit.info</a></li>
662 <li><a href="#cockpit-event-target">cockpit.event_target</a></li>
663 </ul>
664 </li>
665 </ul>
666 </li>
667 <li><a href="#_api_shell">API: shell</a>
668 <ul class="sectlevel2">
669 <li><a href="#_index_html">index.html</a></li>
670 </ul>
671 </li>
672 <li><a href="#_api_system">API: system</a>
673 <ul class="sectlevel2">
674 <li><a href="#_logs_html">logs.html</a>
675 <ul class="sectlevel3">
676 <li><a href="#api-logs-html-description">Description</a></li>
677 </ul>
678 </li>
679 <li><a href="#_terminal_html">terminal.html</a>
680 <ul class="sectlevel3">
681 <li><a href="#api-terminal-html-description">Description</a></li>
682 </ul>
683 </li>
684 </ul>
685 </li>
686 </ul>
687 </div>
688 </div>
689 <div id="content">
690 <div class="sect1">
691 <h2 id="embedding">Embedding and Integrating Cockpit</h2>
692 <div class="sectionbody">
693 <div class="paragraph">
694 <p>Cockpit can be embedded in other web applications either as a whole or
695 specific Cockpit components can be integrated. Due to frame security
696 policy restrictions, this only works if Cockpit and the web application
697 have the <em>same origin</em>; this is commonly achieved by running both from a
698 common reverse proxy.</p>
699 </div>
700 <div class="sect2">
701 <h3 id="embedding-full">Embedding the Cockpit Interface</h3>
702 <div class="paragraph">
703 <p>Cockpit can be embedded into a larger web page as a frame. To embed the
704 entire Cockpit Window use the URI: <code>https://server.example.com:9090/</code></p>
705 </div>
706 <div class="listingblock">
707 <div class="content">
708 <pre class="highlight"><code class="language-html" data-lang="html">&lt;html&gt;
709 &lt;head&gt;
710 &lt;title&gt;Embedded Cockpit&lt;/title&gt;
711 &lt;/head&gt;
712 &lt;body&gt;
713 This is Cockpit.
714 &lt;br/&gt;
715 &lt;iframe width="800px" height="600px"
716 src="https://server.example.com:9090/"/&gt;
717 &lt;/body&gt;
718 &lt;/html&gt;</code></pre>
719 </div>
720 </div>
721 </div>
722 <div class="sect2">
723 <h3 id="embedding-components">Integrating Cockpit Components into Web Applications</h3>
724 <div class="paragraph">
725 <p>Instead of embedding the entirety of Cockpit, you can integrate specific
726 components. Only those components explicitly documented as API should be
727 integrated. Other components can and will change regularly.</p>
728 </div>
729 <div class="paragraph">
730 <p>The component will load from the server in question and a WebSocket
731 connection will be established with the server to relay the component&#8217;s
732 message stream.</p>
733 </div>
734 <div class="paragraph">
735 <p>Cockpit components are HTML files contained in <a href="#">packages</a>.
736 These can be placed in an iframe or web browser window. Each documented
737 and stable component has a well-known URL and these are documented in
738 the <a href="#">API reference</a>. Each component URL begins with the
739 string <code>/cockpit/@localhost/</code> followed a package name, and then the
740 component itself.</p>
741 </div>
742 <div class="paragraph">
743 <p>For example the <a href="#">terminal.html</a> in the
744 <a href="#">system</a> package, has this URL:
745 <code>/cockpit/@localhost/system/terminal.html</code></p>
746 </div>
747 <div class="listingblock">
748 <div class="content">
749 <pre class="highlight"><code class="language-html" data-lang="html">&lt;html&gt;
750 &lt;head&gt;
751 &lt;title&gt;Embedded Terminal&lt;/title&gt;
752 &lt;/head&gt;
753 &lt;body&gt;
754 This is a terminal.
755 &lt;br/&gt;
756 &lt;iframe width="800px" height="600px"
757 src="https://server.example.com:9090/cockpit/@localhost/system/terminal.html"/&gt;
758 &lt;/body&gt;
759 &lt;/html&gt;</code></pre>
760 </div>
761 </div>
762 </div>
763 <div class="sect2">
764 <h3 id="embedding-deep">Deep Integration</h3>
765 <div class="paragraph">
766 <p>Most often <a href="#embedding-components">simple integration</a> will be used
767 to bring Cockpit components into web applications. However it is also
768 possible to do deep integration for embedders who wish to perform
769 non-standard authentication with the server, and relay the component&#8217;s
770 message stream to the server themselves.</p>
771 </div>
772 <div class="admonitionblock warning">
773 <table>
774 <tr>
775 <td class="icon">
776 <div class="title">Warning</div>
777 </td>
778 <td class="content">
779 <div class="paragraph">
780 <p>Deep integration capability is in heavy flux and is not yet documented.</p>
781 </div>
782 </td>
783 </tr>
784 </table>
785 </div>
786 </div>
787 <div class="sect2">
788 <h3 id="embedding-cors">Pinging Cockpit</h3>
789 <div class="paragraph">
790 <p>When embedding Cockpit or integrating Cockpit components, it may be
791 necessary to check whether Cockpit is available on a server before
792 proceeding.</p>
793 </div>
794 <div class="paragraph">
795 <p>To do this perform a <code>/ping</code> request to Cockpit. This is a simple HTTP
796 GET request. It returns the following:</p>
797 </div>
798 <div class="literalblock">
799 <div class="content">
800 <pre>GET: https://server.example.com:9090/ping
801 200 OK: { "service": "cockpit" }</pre>
802 </div>
803 </div>
804 <div class="paragraph">
805 <p>The <code>/ping</code> request allows
806 <a href="https://en.wikipedia.org/wiki/Cross-origin_resource_sharing">Cross Origin
807 Resource Sharing</a> headers and as such can be performed from Javascript
808 code with any origin. The request can also be made via plain HTTP
809 without SSL. It is by design that no further information is present in
810 the response.</p>
811 </div>
812 <div class="paragraph">
813 <p>A complete example of using <code>/ping</code> is available in the Cockpit
814 sources in the <code>/examples/ping-server/</code> directory.</p>
815 </div>
816 </div>
817 </div>
818 </div>
819 <div class="sect1">
820 <h2 id="packages">Cockpit Packages</h2>
821 <div class="sectionbody">
822 <div class="paragraph">
823 <p>Cockpit is separated into various packages, each of which brings
824 specific features and/or code.</p>
825 </div>
826 <div class="admonitionblock warning">
827 <table>
828 <tr>
829 <td class="icon">
830 <div class="title">Warning</div>
831 </td>
832 <td class="content">
833 <div class="paragraph">
834 <p>In addition, any APIs or behavior not explicitly documented here is an
835 internal API and can be changed at any time.</p>
836 </div>
837 </td>
838 </tr>
839 </table>
840 </div>
841 <div class="sect2">
842 <h3 id="package-layout">Layout of Package Files</h3>
843 <div class="paragraph">
844 <p>A package consists of one or more files placed in a directory or its
845 subdirectories. It must have a <code>manifest.json</code> file and follow certain
846 naming conventions.</p>
847 </div>
848 <div class="paragraph">
849 <p>The name of a package is the name of the directory.</p>
850 </div>
851 <div class="paragraph">
852 <p>The name of the package must be ASCII alphanumeric, and may contain an
853 underscore. Names of directories and files in the package must consist
854 of ASCII alphanumeric along with dash, underscore, dot, and comma. No
855 spaces are allowed.</p>
856 </div>
857 <div class="paragraph">
858 <p>Cockpit uses the data directories from the
859 <a href="https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG
860 Base Directory Specification</a> to locate packages. The <code>$XDG_DATA_DIRS</code>
861 represents a colon separate list of system data directories, and
862 <code>$XDG_DATA_HOME</code> is a user specific data directory. If the environment
863 variables are not set, defaults are used, according to the spec. If
864 cockpit has been built with an alternate <code>--prefix=/path</code> then the
865 <code>$prefix/share/cockpit</code> is used by default.</p>
866 </div>
867 <div class="paragraph">
868 <p>A <code>cockpit/</code> subdirectories in any of these data directories is the
869 location where packages are loaded by Cockpit. If Cockpit finds a
870 package with the same name, in multiple data directories, then the first
871 one wins. According to the spec the first data directory is
872 <code>$XDG_DATA_HOME</code> and then <code>$XDG_DATA_DIRS</code> in order.</p>
873 </div>
874 <div class="paragraph">
875 <p>This means that, by default the following directories are searched for
876 cockpit packages, and in this order:</p>
877 </div>
878 <div class="ulist">
879 <ul>
880 <li>
881 <p><code>~/.local/share/cockpit/</code></p>
882 </li>
883 <li>
884 <p><code>/usr/local/share/cockpit/</code></p>
885 </li>
886 <li>
887 <p><code>/usr/share/cockpit/</code></p>
888 </li>
889 </ul>
890 </div>
891 <div class="paragraph">
892 <p>Packages placed in <code>$XDG_DATA_HOME</code> are not cached by Cockpit or the
893 web browser. Other packages are cached aggressively, and are accessed
894 using a checksum of the files in the packages and their names.</p>
895 </div>
896 <div class="paragraph">
897 <p>You can use the following command to list the packages installed on a
898 server. You&#8217;ll note that it&#8217;s output may change when you run the command
899 as different users, if there are packages installed in the user&#8217;s home
900 directory.</p>
901 </div>
902 <div class="literalblock">
903 <div class="content">
904 <pre>$ cockpit-bridge --packages
905 ...</pre>
906 </div>
907 </div>
908 <div class="paragraph">
909 <p>To further clarify things, here is an example package called
910 "my-package" and its file layout:</p>
911 </div>
912 <div class="literalblock">
913 <div class="content">
914 <pre>/usr/share/cockpit/
915 my-package/
916 manifest.json
917 file.html
918 some.js</pre>
919 </div>
920 </div>
921 <div class="paragraph">
922 <p>Place or symlink packages in your <code>~/.local/share/cockpit</code> directory
923 (or appropriate <code>$XDG_DATA_HOME</code> location) that you would like to
924 modify and develop. System installed packages should not change while
925 Cockpit is running.</p>
926 </div>
927 </div>
928 <div class="sect2">
929 <h3 id="_package_manifest">Package Manifest</h3>
930 <div class="paragraph">
931 <p>Each package has a <code>manifest.json</code> file. It is a JSON object. The
932 following fields may be present in the manifest:</p>
933 </div>
934 <div class="dlist">
935 <dl>
936 <dt class="hdlist1">content-security-policy</dt>
937 <dd>
938 <p>By default Cockpit serves packages using a strict
939 <a href="https://en.wikipedia.org/wiki/Content_Security_Policy">Content Security
940 Policy</a>, which among other things does not allow inline styles or
941 scripts. This can be overridden on a per-package basis, with this
942 setting.
943 +
944 If the overridden content security policy does not contain a
945 <code>default-src</code>, <code>connect-src</code>, <code>base-uri</code>, <code>form-action</code>,
946 <code>object-src</code>, or <code>block-all-mixed-content</code> then these will be
947 added to the policy from the manifest.</p>
948 </dd>
949 <dt class="hdlist1">name</dt>
950 <dd>
951 <p>An optional string that changes the name of the package. Normally
952 packages derive their name from the directory that they are located
953 in. This field overrides that name.</p>
954 </dd>
955 <dt class="hdlist1">priority</dt>
956 <dd>
957 <p>An optional integer that specifies which package is preferred in cases
958 where there are conflicts. For example given two packages with the
959 same <code>name</code> a package is chosen based on its priority. A higher integer
960 means higher priority.</p>
961 </dd>
962 <dt class="hdlist1">conditions</dt>
963 <dd>
964 <p>An optional list of <code>{"predicate": "value"}</code> objects. Cockpit will
965 only consider the package if <em>all</em> conditions are met. This is
966 preferable to using <code>priority</code>.<br>
967 <br>
968 Currently supported predicates are <code>path-exists</code> and <code>path-not-exists</code>
969 (since Cockpit 286) and <code>any</code> (since Cockpit 348). <code>any</code> accepts a
970 list of conditions and evaluates to true if <em>at least one</em> of the nested
971 conditions is met. Unknown predicates are ignored.</p>
972 </dd>
973 <dt class="hdlist1">requires</dt>
974 <dd>
975 <p>An optional JSON object that contains a <code>"cockpit"</code> string version
976 number. The package will only be usable if the Cockpit bridge and
977 javascript base are equal or newer than the given version number.</p>
978 </dd>
979 <dt class="hdlist1">version</dt>
980 <dd>
981 <p>An informational version number for the package.</p>
982 </dd>
983 <dt class="hdlist1">preload</dt>
984 <dd>
985 <p>A list of identifiers of the components that should be preloaded.
986 Normally, the files of a component are loaded when the user navigates
987 to it for the first time. The files of a preloaded component are
988 loaded immediately after the user logs in, and the initialization code
989 of the component is invoked.
990 +
991 The value of this field is an array of strings, where each string is
992 one of the keys used in the <code>dashboard</code>, <code>menu</code>, or <code>tools</code>
993 fields that are explained below.</p>
994 </dd>
995 <dt class="hdlist1">parent</dt>
996 <dd>
997 <p>This option is used when module does not have its own menu item but is
998 a part of a different module. This is described by JSON object with
999 properties <code>component</code> which takes name of the superordinate
1000 component and <code>docs</code> with list of documentation URLs for the given
1001 page. See below for structure of <code>docs</code> property.</p>
1002 </dd>
1003 </dl>
1004 </div>
1005 <div class="paragraph">
1006 <p>In addition, the following keys contain information about where
1007 components of the package should appear in Cockpit&#8217;s user interface.
1008 Each of these keys is optional and contains an object mapping unique
1009 identifiers to menu items, which are described below. (The naming of
1010 these fields doesn&#8217;t perfectly match the current user interface for
1011 historical reasons.)</p>
1012 </div>
1013 <div class="dlist">
1014 <dl>
1015 <dt class="hdlist1">dashboard</dt>
1016 <dd>
1017 <p>Dashboard items appear in the menu under the section <em>Apps</em>.</p>
1018 </dd>
1019 <dt class="hdlist1">menu</dt>
1020 <dd>
1021 <p>These items appear in the menu under the section <em>System</em>. This
1022 section is roughly ordered into these categories (with their <em>order</em>
1023 in parentheses):
1024 +</p>
1025 <div class="ulist">
1026 <ul>
1027 <li>
1028 <p>System Information (10)</p>
1029 </li>
1030 <li>
1031 <p>Logs (20)</p>
1032 </li>
1033 <li>
1034 <p>Configuring major subsystems (30-40)</p>
1035 </li>
1036 <li>
1037 <p>Things running on the machine (VMs, Containers - 50-60)</p>
1038 </li>
1039 <li>
1040 <p>Implementation Details (Accounts, Services - 70-100)</p>
1041 </li>
1042 </ul>
1043 </div>
1044 </dd>
1045 <dt class="hdlist1">tools</dt>
1046 <dd>
1047 <p>These items appear in the menu under the section <em>Tools</em>.</p>
1048 </dd>
1049 </dl>
1050 </div>
1051 <div class="paragraph">
1052 <p>Menu items and tools are registered using JSON objects that have the
1053 following properties:</p>
1054 </div>
1055 <div class="dlist">
1056 <dl>
1057 <dt class="hdlist1">label</dt>
1058 <dd>
1059 <p>The label for the menu item or tool.</p>
1060 </dd>
1061 <dt class="hdlist1">order</dt>
1062 <dd>
1063 <p>An optional order integer to place this menu item or tool. Lower
1064 integers are listed first.</p>
1065 </dd>
1066 <dt class="hdlist1">path</dt>
1067 <dd>
1068 <p>The relative path to the HTML file within the package that implements
1069 the menu item or tool.</p>
1070 </dd>
1071 <dt class="hdlist1">docs</dt>
1072 <dd>
1073 <p>List of documentation URLs for the given page. Each item is an object
1074 containing <code>label</code> and <code>url</code>.</p>
1075 </dd>
1076 <dt class="hdlist1">keywords</dt>
1077 <dd>
1078 <p>Keywords that describe the page and which are used for searching.
1079 These keywords should be lowercase. Keywords is a list containing
1080 keyword items as described below. Page label is prepended as first
1081 keyword in the first keyword item.</p>
1082 </dd>
1083 </dl>
1084 </div>
1085 <div class="paragraph">
1086 <p>Keyword items are registered using JSON objects that have the following
1087 properties:</p>
1088 </div>
1089 <div class="dlist">
1090 <dl>
1091 <dt class="hdlist1">matches</dt>
1092 <dd>
1093 <p>List of keywords to be matched.</p>
1094 </dd>
1095 <dt class="hdlist1">goto</dt>
1096 <dd>
1097 <p>Optional path that is used for all keywords in this item. When this
1098 argument starts with slash, then it is used as pathname, otherwise it
1099 is used as hash. Defining <code>goto:"page_hash"</code> in page with
1100 <code>path:"/page_path"</code> would redirect to <code>/page_path#page_hash</code>,
1101 while <code>goto:"/page_path"</code> would redirect to <code>/page_path</code> ignoring
1102 default page path.</p>
1103 </dd>
1104 <dt class="hdlist1">weight</dt>
1105 <dd>
1106 <p>How much keywords are prioritized over others. Default is 3.</p>
1107 </dd>
1108 <dt class="hdlist1">translate</dt>
1109 <dd>
1110 <p><code>false</code> when keywords should not be localized. Default is <code>true</code>.</p>
1111 </dd>
1112 </dl>
1113 </div>
1114 <div class="paragraph">
1115 <p>An example manifest.json with some optional properties set:</p>
1116 </div>
1117 <div class="literalblock">
1118 <div class="content">
1119 <pre>{
1120 "version": 0,
1121 "require": {
1122 "cockpit": "120"
1123 },
1124 "tools": {
1125 "mytool": {
1126 "label": "My Tool",
1127 "path": "tool.html"
1128 }
1129 }
1130 }</pre>
1131 </div>
1132 </div>
1133 <div class="literalblock">
1134 <div class="content">
1135 <pre>{
1136 "version": 0,
1137 "require": {
1138 "cockpit": "120"
1139 },
1140 "conditions": [
1141 {"path-exists": "/usr/bin/mytool"},
1142 {"path-exists": "/etc/mytool.conf"},
1143 {"path-not-exist": "/etc/incompatible-tool"}
1144 ],
1145 "tools": {
1146 "mytool": {
1147 "label": "My Tool",
1148 "path": "tool.html"
1149 }
1150 }
1151 }</pre>
1152 </div>
1153 </div>
1154 <div class="paragraph">
1155 <p>The following example shows how to use disjunctive conditions with <code>any</code>
1156 to specify alternative requirements (available since Cockpit 348). This
1157 package will be available if either <code>/usr/bin/alt1</code> or <code>/usr/bin/alt2</code>
1158 exists. In any case, <code>/etc/incompatible-tool</code> must not exist.</p>
1159 </div>
1160 <div class="literalblock">
1161 <div class="content">
1162 <pre>"conditions": [
1163 {"any": [{"path-exists": "/usr/bin/alt1"}, {"path-exists": "/usr/bin/alt2"}]},
1164 {"path-not-exists": "/etc/incompatible-tool"}
1165 ]</pre>
1166 </div>
1167 </div>
1168 </div>
1169 <div class="sect2">
1170 <h3 id="package-manifest-override">Manifest overrides</h3>
1171 <div class="paragraph">
1172 <p>To change a manifest system-wide, a file
1173 <code>&lt;package-directory-name&gt;.override.json</code> may be placed into
1174 <code>/etc/cockpit/</code>, or below <code>$XDG_CONFIG_DIRS</code> if set (see
1175 <a href="./cockpit.conf.5.html">cockpit.conf</a>). To change it for a particular
1176 user only, put the override into <code>~/.config/cockpit</code>.</p>
1177 </div>
1178 <div class="paragraph">
1179 <p>These override the information in the manifest in the simple
1180 <a href="https://tools.ietf.org/html/rfc7386">JSON Merge Patch</a> format.</p>
1181 </div>
1182 <div class="paragraph">
1183 <p>This can be used to hide or modify menu items of an existing package.
1184 For example <code>/etc/cockpit/systemd.override.json</code> or
1185 <code>~/.config/cockpit/systemd.override.json</code> could hide the <em>Logs</em> menu
1186 item and move the <em>Services</em> menu item to the top of the menu.</p>
1187 </div>
1188 <div class="literalblock">
1189 <div class="content">
1190 <pre>{
1191 "menu": {
1192 "logs": null,
1193 "services": {
1194 "order": -1
1195 }
1196 }
1197 }</pre>
1198 </div>
1199 </div>
1200 </div>
1201 <div class="sect2">
1202 <h3 id="package-links">Package Links and Paths</h3>
1203 <div class="paragraph">
1204 <p>When referring to files in your package, such as in a hyperlink or a
1205 <code>&lt;style&gt;</code> tag or <code>&lt;script&gt;</code> tag, simply use a relative path, and
1206 refer to the files in the same directory. When you need to refer to
1207 files in another package use a relative link.</p>
1208 </div>
1209 <div class="paragraph">
1210 <p>For example here&#8217;s how to include the base <code>cockpit.js</code> script in your
1211 HTML from the <code>latest</code> package:</p>
1212 </div>
1213 <div class="literalblock">
1214 <div class="content">
1215 <pre>&lt;script src="../base1/cockpit.js"&gt;&lt;/script&gt;</pre>
1216 </div>
1217 </div>
1218 <div class="paragraph">
1219 <p>Do not assume you can link to any file in any other package. Refer to
1220 the <a href="#">list of API packages</a> for those that are available
1221 for use.</p>
1222 </div>
1223 </div>
1224 <div class="sect2">
1225 <h3 id="package-minified">Content Negotiation</h3>
1226 <div class="paragraph">
1227 <p>In order to support gzipped and/or minified data, the files in a package
1228 are loaded using content negotiation logic. A HTTP request for the file
1229 <code>test.js</code> in the package named <code>mypackage</code> will return
1230 <code>mypackage/test.js</code> or <code>mypackage/test.js.gz</code> (in undefined
1231 preference). If neither exists, then it returns
1232 <code>mypackage/test.js.min</code> or <code>mypackage/test.js.min.gz</code> (again in
1233 undefined preference).</p>
1234 </div>
1235 <div class="paragraph">
1236 <p>When packages are loaded from a system directory, Cockpit optimizes the
1237 file system lookups above, by pre-listing the files. This is one of the
1238 reasons that you should never change packages installed to a system
1239 directory while Cockpit is running.</p>
1240 </div>
1241 </div>
1242 <div class="sect2">
1243 <h3 id="package-api">Using Cockpit API</h3>
1244 <div class="paragraph">
1245 <p>Cockpit has API available for writing packages. There is no API
1246 available for external callers to invoke via HTTP, REST or otherwise.</p>
1247 </div>
1248 <div class="paragraph">
1249 <p>API from various packages can be used to implement Cockpit packages.
1250 Each package listed here has some API available for use. Only the API
1251 explicitly documented should be used.</p>
1252 </div>
1253 <div class="ulist">
1254 <ul>
1255 <li>
1256 <p><a href="#">API Listing</a></p>
1257 </li>
1258 </ul>
1259 </div>
1260 <div class="paragraph">
1261 <p>To include javascript from the API, simply load it into your HTML using
1262 a script tag. Alternatively you can use an javascript loader.</p>
1263 </div>
1264 </div>
1265 <div class="sect2">
1266 <h3 id="package-bridges">Bridges for specific tasks</h3>
1267 <div class="paragraph">
1268 <p>On the server side the <a href="cockpit-bridge.1.html">cockpit-bridge</a>(1)
1269 connects to various system APIs that the front end UI requests it to.
1270 There are additional bridges for specific tasks that the main
1271 <code>cockpit-bridge</code> cannot handle, such as using the PCP C library API.</p>
1272 </div>
1273 <div class="paragraph">
1274 <p>These additional bridges can be registered in a <code>"bridges"</code> section of
1275 a package&#8217;s <code>manifest.json</code> file. Building such a bridge is a complex
1276 tasks, and we will skip over that here. However it is useful to adjust
1277 how these additional bridges are called, and so we&#8217;ll look at how they
1278 are registered.</p>
1279 </div>
1280 <div class="paragraph">
1281 <p>An example <code>manifest.json</code> with a bridges section:</p>
1282 </div>
1283 <div class="literalblock">
1284 <div class="content">
1285 <pre>{
1286 "bridges": [
1287 {
1288 "match": { "payload": "metrics1" },
1289 "spawn": [ "/usr/libexec/cockpit-pcp" ]
1290 }
1291 ]
1292 }</pre>
1293 </div>
1294 </div>
1295 <div class="paragraph">
1296 <p>The bridges are considered in the order they are listed in the array.
1297 Use the <code>manifest.json`</code>"priority"` field to control order between
1298 packages. The bridges are registered using JSON objects that have the
1299 following properties:</p>
1300 </div>
1301 <div class="dlist">
1302 <dl>
1303 <dt class="hdlist1">environ</dt>
1304 <dd>
1305 <p>Optional, additional environment variables to pass to the bridge
1306 command.</p>
1307 </dd>
1308 <dt class="hdlist1">match</dt>
1309 <dd>
1310 <p>The <code>"match"</code> object describes which channel open command options
1311 need to match for a given channel to be handed over to this bridge.</p>
1312 </dd>
1313 <dt class="hdlist1">privileged</dt>
1314 <dd>
1315 <p>If set to <code>true</code>, this marks the bridge as a superuser bridge.
1316 Cockpit will start one of these explicitly when trying to escalate the
1317 privileges of a session. A privileged bridge can not have a
1318 <code>"match"</code> property.</p>
1319 </dd>
1320 <dt class="hdlist1">label</dt>
1321 <dd>
1322 <p>Setting this enables selection of privileged bridges in the UI. When
1323 no privileged bridge has a <code>label</code>, then Cockpit will start the
1324 bridge that runs <code>sudo</code>. This is the case in a default Cockpit
1325 installation. When at least one privileged bridge has a <code>label</code> then
1326 the user can select one of them when escalating privileges. As a
1327 special case, if only one bridge has a <code>label</code>, then the step of
1328 selecting a bridge is omitted in the UI and that one bridge is always
1329 started.
1330 +
1331 Thus, if you add a privileged bridge with a <code>label</code> in a new
1332 manifest, Cockpit will use that bridge the next time a user opens the
1333 "Administrative access" dialog. If you want the user to choose between
1334 the <code>sudo</code> method and your new one, you need to duplicate the
1335 <code>sudo</code> bridge definition in your manifest and give it a label.</p>
1336 </dd>
1337 <dt class="hdlist1">problem</dt>
1338 <dd>
1339 <p>If a problem is specified, and this bridge fails to start up then
1340 channels will be closed with this problem code. Otherwise later
1341 bridges or internal handlers for the channel will be invoked.</p>
1342 </dd>
1343 <dt class="hdlist1">spawn</dt>
1344 <dd>
1345 <p>The command and arguments to invoke.</p>
1346 </dd>
1347 </dl>
1348 </div>
1349 <div class="paragraph">
1350 <p>The <code>spawn</code> and <code>environ</code> values can be dynamically taken from a
1351 matching open command values. When a value in either the <code>spawn</code> or
1352 <code>environ</code> array contains a named variable wrapped in <code>${}</code>, the
1353 variable will be replaced with the value contained in the matching open
1354 command. Only named variables are supported and name can only contain
1355 letters, numbers and the following symbols: <code>._-</code></p>
1356 </div>
1357 <div class="paragraph">
1358 <p>For example a bridges section like:</p>
1359 </div>
1360 <div class="literalblock">
1361 <div class="content">
1362 <pre>{
1363 "bridges": [
1364 {
1365 "match": { "payload": "example" },
1366 "environ": [ "TAG=${tag}" ],
1367 "spawn: [ "/example-bridge", "--tag", "${tag}" ],
1368 "problem": "access-denied"
1369 }
1370 ]
1371 }</pre>
1372 </div>
1373 </div>
1374 <div class="paragraph">
1375 <p>when a open command is received with a payload of <code>example</code> with
1376 <code>tag</code> value of <code>tag1</code>. The following command will be spawned</p>
1377 </div>
1378 <div class="literalblock">
1379 <div class="content">
1380 <pre>TAG=tag1 /example-bridge --tag tag1</pre>
1381 </div>
1382 </div>
1383 <div class="paragraph">
1384 <p>Processes that are reused so if another open command with a "tag" of
1385 <code>tag1</code> is received. The open command will be passed to existing
1386 process, rather than spawning a new one. However a open command with an
1387 tag of <code>tag2</code> will spawn a new command:</p>
1388 </div>
1389 <div class="literalblock">
1390 <div class="content">
1391 <pre>TAG=tag2 /example-bridge --tag tag2</pre>
1392 </div>
1393 </div>
1394 <div class="paragraph">
1395 <p>If you need to include <code>${}</code>, as an actual value in your arguments you
1396 can escape it by prefixing it with a <code>\</code></p>
1397 </div>
1398 </div>
1399 <div class="sect2">
1400 <h3 id="package-replace">Replacing an existing package</h3>
1401 <div class="paragraph">
1402 <p>If the functionality in a package replaces that of another package then
1403 it can replace that package by claiming the same <code>name</code> and a higher
1404 <code>priority</code>.</p>
1405 </div>
1406 <div class="paragraph">
1407 <p>For example, a package in the <code>/usr/share/cockpit/disks</code> directory
1408 could replace Cockpit&#8217;s <em>storage</em> package with a <code>manifest.json</code> like
1409 this:</p>
1410 </div>
1411 <div class="literalblock">
1412 <div class="content">
1413 <pre>{
1414 "version": 0,
1415 "name": "storage",
1416 "priority": 10,
1417 "menu": {
1418 "index": {
1419 "label": "Disk Storage",
1420 "order": 15
1421 }
1422 }
1423 }</pre>
1424 </div>
1425 </div>
1426 </div>
1427 </div>
1428 </div>
1429 <div class="sect1">
1430 <h2 id="urls">Cockpit URLs</h2>
1431 <div class="sectionbody">
1432 <div class="paragraph">
1433 <p>Cockpit URLs follow a specific structure, related to the components they
1434 are loading. Various components are loaded in <code>&lt;iframe&gt;</code> tags. The
1435 URLs for these components are described first. Further down below you
1436 can find information about the top level bookmarkable Cockpit address
1437 URLs.</p>
1438 </div>
1439 <div class="sect2">
1440 <h3 id="urls-components">Component URLs</h3>
1441 <div class="paragraph">
1442 <p>Cockpit components are HTML documents. They are organized into
1443 <a href="#">packages</a>. Each package contains information about which
1444 HTML components are available in that package. Components should always
1445 use relative URLs to access resources, such as images, scripts or CSS
1446 files, even if they refer to a resource in another package.</p>
1447 </div>
1448 <div class="paragraph">
1449 <p>The following are valid component URLs, each bit will be discussed
1450 below:</p>
1451 </div>
1452 <div class="literalblock">
1453 <div class="content">
1454 <pre>/cockpit/@localhost/package/component.html#/hash
1455 /cockpit/$checksum/package/component.html#/hash
1456 /cockpit/@server.example.com/package/component.html#/hash
1457 /cockpit+embedder/@localhost/package/component.html#/hash</pre>
1458 </div>
1459 </div>
1460 <div class="paragraph">
1461 <p>All resource URLs are under the <code>/cockpit</code> namespace. In cases where a
1462 Cockpit component is being <a href="#">embedded</a> the <code>/cockpit</code>
1463 may be followed by a plus sign and another <code>embedder</code> specific
1464 identifier.</p>
1465 </div>
1466 <div class="paragraph">
1467 <p>What follows is either a <code>@host</code> or <code>$checksum</code> which tells cockpit
1468 where to <a href="#">find the package</a>. Checksums are used when more
1469 than one host has identical packages and the resources can be cached.</p>
1470 </div>
1471 <div class="paragraph">
1472 <p>The <code>package</code> name is next, followed by the <code>component</code> HTML path
1473 inside that package. And lastly a hash allows for navigation within a
1474 single component. The hash should follow a URL path and/or query string
1475 form.</p>
1476 </div>
1477 <div class="admonitionblock warning">
1478 <table>
1479 <tr>
1480 <td class="icon">
1481 <div class="title">Warning</div>
1482 </td>
1483 <td class="content">
1484 <div class="paragraph">
1485 <p>Never assume that the <code>@host</code> or <code>$checksum</code> portion is predictable.
1486 Only refer to resources in packages on the same host.</p>
1487 </div>
1488 </td>
1489 </tr>
1490 </table>
1491 </div>
1492 </div>
1493 <div class="sect2">
1494 <h3 id="urls-visible">Visible URLs</h3>
1495 <div class="paragraph">
1496 <p>The above Component URLs are usually not visible to the user. Instead
1497 the Cockpit Web Service wraps the components in a shell which allows
1498 navigation, and provides bookmarkable clean URLs to the component. These
1499 URLs do not affect <a href="#">embedders</a> or
1500 <a href="#">components</a> directly.</p>
1501 </div>
1502 <div class="paragraph">
1503 <p>If no path is present then the Cockpit will redirect to the default page
1504 for the server.</p>
1505 </div>
1506 <div class="paragraph">
1507 <p>If the first segment of the path begins with an <code>@</code> sign, then the
1508 component is being shown from a non-local host.</p>
1509 </div>
1510 <div class="paragraph">
1511 <p>The next segment of the path, (or first if the component is being shown
1512 on the local host) is the <a href="#">package name</a>. The remainder of
1513 the path is a component file in the package. If no further path segments
1514 are present, a default <code>index.html</code> component in the package is
1515 loaded. An extension of <code>.html</code> is automatically appended.</p>
1516 </div>
1517 <div class="paragraph">
1518 <p>The hash portion of the path is automatically transferred to the
1519 component as the hash of its <a href="#urls-components">resource URL</a>.</p>
1520 </div>
1521 </div>
1522 </div>
1523 </div>
1524 <div class="sect1">
1525 <h2 id="_api_base1">API: base1</h2>
1526 <div class="sectionbody">
1527 <div class="paragraph">
1528 <p>This package contains basic support API available to other packages.</p>
1529 </div>
1530 <div class="sect2">
1531 <h3 id="_cockpit_js">cockpit.js</h3>
1532 <div class="paragraph">
1533 <p>Basic cockpit API to interact with the system</p>
1534 </div>
1535 <div class="sect3">
1536 <h4 id="api-cockpit-loading">Loading cockpit.js</h4>
1537 <div class="paragraph">
1538 <p><code>cockpit.js</code> should be loaded via a script tag.</p>
1539 </div>
1540 <div class="literalblock">
1541 <div class="content">
1542 <pre>&lt;script src="../base1/cockpit.js"&gt;</pre>
1543 </div>
1544 </div>
1545 </div>
1546 </div>
1547 <div class="sect2">
1548 <h3 id="_cockpit_js_object_caching">cockpit.js: Object Caching</h3>
1549 <div class="paragraph">
1550 <p>If the same information is displayed by multiple components in Cockpit,
1551 <code>cockpit.cache()</code> provides a way to share data between them. The
1552 shared data should be simple objects, arrays, and values, and not
1553 contain functions or other objects.</p>
1554 </div>
1555 <div class="sect3">
1556 <h4 id="cockpit-cache-func">cockpit.cache()</h4>
1557 <div class="literalblock">
1558 <div class="content">
1559 <pre>cache = cockpit.cache(key, provider, consumer)</pre>
1560 </div>
1561 </div>
1562 <div class="paragraph">
1563 <p>Create a new cache object. The <code>key</code> should be a globally unique
1564 string that describes the data being cached. This string must describe
1565 the data, across all machines and all versions of cockpit. It is
1566 customary to include a version number in the <code>key</code> string.</p>
1567 </div>
1568 <div class="literalblock">
1569 <div class="content">
1570 <pre>function provider(result, key) {
1571 result("myvalue");
1572
1573 return {
1574 close: function() {
1575 /* closed */
1576 }
1577 };
1578 }</pre>
1579 </div>
1580 </div>
1581 <div class="paragraph">
1582 <p>The <code>provider</code> is a function that will be invoked to start retrieving
1583 data for the cache. It will be passed a <code>result</code> function as its first
1584 argument. The <code>result</code> should be invoked whenever new data is
1585 available. The <code>key</code> argument matches the key string the cache was
1586 created with.</p>
1587 </div>
1588 <div class="paragraph">
1589 <p>The <code>provider</code> can return an object with a <code>close</code> method. This
1590 method will be invoked when the cache no longer needs data from the
1591 provider.</p>
1592 </div>
1593 <div class="literalblock">
1594 <div class="content">
1595 <pre>function consumer(value, key) {
1596 /* ... */
1597 }</pre>
1598 </div>
1599 </div>
1600 <div class="paragraph">
1601 <p>The <code>consumer</code> is a function that will be passed new values when they
1602 are available, whether they come from the <code>provider</code> or a source in a
1603 different component/frame.</p>
1604 </div>
1605 </div>
1606 <div class="sect3">
1607 <h4 id="cockpit-cache-close">cache.close()</h4>
1608 <div class="literalblock">
1609 <div class="content">
1610 <pre>cache.close()</pre>
1611 </div>
1612 </div>
1613 <div class="paragraph">
1614 <p>Close a cache and stop calling its <code>consumer</code>. If the <code>provider</code> was
1615 invoked, then the <code>close()</code> method it returned will be invoked.</p>
1616 </div>
1617 </div>
1618 </div>
1619 <div class="sect2">
1620 <h3 id="_cockpit_js_raw_channels">cockpit.js: Raw Channels</h3>
1621 <div class="paragraph">
1622 <p>At a low level Cockpit communicates with the system via messages passed
1623 through various channels. These are usually exposed via higher level
1624 APIs, such as the <code>cockpit.spawn()</code> function. It is rare to use raw
1625 channels directly.</p>
1626 </div>
1627 <div class="sect3">
1628 <h4 id="cockpit-channels-channel">cockpit.channel()</h4>
1629 <div class="literalblock">
1630 <div class="content">
1631 <pre>channel = cockpit.channel(options)</pre>
1632 </div>
1633 </div>
1634 <div class="paragraph">
1635 <p>This function creates a new channel for communication with the system.
1636 It returns a new channel object. The <code>options</code> argument is a plain
1637 object. At least the <code>"payload"</code> option is required, and based on the
1638 payload type, other options may be required.</p>
1639 </div>
1640 <div class="dlist">
1641 <dl>
1642 <dt class="hdlist1"><code>"binary"</code></dt>
1643 <dd>
1644 <p>Set to <code>true</code> to transfer binary payloads. Both messages sent via
1645 <a href="#cockpit-channels-send"><code>channel.send()</code></a> and those received via
1646 <a href="#cockpit-channels-message"><code>channel.onmessage</code></a> should be arrays
1647 of bytes, either <code>Uint8Array</code> or <code>Array</code> depending on browser
1648 support.</p>
1649 </dd>
1650 <dt class="hdlist1"><code>"payload"</code></dt>
1651 <dd>
1652 <p>The payload type for the channel. Only specific payload types are
1653 supported.</p>
1654 </dd>
1655 <dt class="hdlist1"><code>"superuser"</code></dt>
1656 <dd>
1657 <p>Set to <code>"require"</code> to open this channel as root. If the currently
1658 logged in user is not permitted to become root (eg: via <code>pkexec</code>)
1659 then the <code>channel</code> will immediately be
1660 <a href="#cockpit-channels-close-ev">closed</a> with a <code>"access-denied"</code>
1661 problem code.
1662 +
1663 Set to <code>"try"</code> to try to open the channel as root, but if that
1664 fails, then fall back to an unprivileged channel.</p>
1665 </dd>
1666 </dl>
1667 </div>
1668 <div class="paragraph">
1669 <p>The channel object returned has the following fields and methods and
1670 events. You should call the <code>channel.close()</code> method when done with
1671 the channel.</p>
1672 </div>
1673 <div class="paragraph">
1674 <p>A valid channel will always be returned and the is ready to
1675 <code>channel.send()</code>. The channel may
1676 <a href="#cockpit-channels-close-ev">close shortly afterword</a> due to a
1677 failure.</p>
1678 </div>
1679 </div>
1680 <div class="sect3">
1681 <h4 id="cockpit-channels-binary">channel.binary</h4>
1682 <div class="paragraph">
1683 <p>Will be <code>true</code> for an binary channel. Will be set to <code>false</code> if the
1684 channel is textual.</p>
1685 </div>
1686 </div>
1687 <div class="sect3">
1688 <h4 id="cockpit-channels-options">channel.options</h4>
1689 <div class="paragraph">
1690 <p>The options used to open this channel. This should not be changed.</p>
1691 </div>
1692 </div>
1693 <div class="sect3">
1694 <h4 id="cockpit-channels-valid">channel.valid</h4>
1695 <div class="paragraph">
1696 <p>Will be <code>true</code> for an open channel. Will be set to <code>false</code> if the
1697 channel closes.</p>
1698 </div>
1699 </div>
1700 <div class="sect3">
1701 <h4 id="cockpit-channels-send">channel.send()</h4>
1702 <div class="literalblock">
1703 <div class="content">
1704 <pre>channel.send(data)</pre>
1705 </div>
1706 </div>
1707 <div class="paragraph">
1708 <p>Send a message over the channel. The contents of the message depends on
1709 the payload type of the channel. If a binary channel, then <code>data</code> is
1710 expected to be an <code>Array</code> of bytes or a <code>Uint8Array</code>. If not binary,
1711 then the <code>data</code> will be converted to a string if not already a string.</p>
1712 </div>
1713 </div>
1714 <div class="sect3">
1715 <h4 id="cockpit-channels-control">channel.control()</h4>
1716 <div class="literalblock">
1717 <div class="content">
1718 <pre>channel.control(options)</pre>
1719 </div>
1720 </div>
1721 <div class="paragraph">
1722 <p>Notify the channel to tune certain parameters on the fly. The
1723 <code>options</code> is a plain javascript object, and the contents depend on the
1724 <code>"payload"</code> of the channel.</p>
1725 </div>
1726 <div class="paragraph">
1727 <p>One common operation is to set <code>"command"</code> to <code>"done"</code> in the
1728 options field. To indicate that no further messages will be sent through
1729 the channel.</p>
1730 </div>
1731 </div>
1732 <div class="sect3">
1733 <h4 id="cockpit-channels-wait">channel.wait()</h4>
1734 <div class="literalblock">
1735 <div class="content">
1736 <pre>promise = channel.wait([callback])</pre>
1737 </div>
1738 </div>
1739 <div class="paragraph">
1740 <p>Returns a <code>promise</code> that is ready when the channel is ready, or fails
1741 if the client closes. If a <code>callback</code> is specified, it is attached to
1742 the promise. The promise will be rejected or resolved with the contents
1743 <code>options</code> passed to the
1744 <a href="#cockpit-channels-onready">channel.onready</a> and
1745 <a href="#cockpit-channels-close-ev">channel.onclose</a> events respectively.</p>
1746 </div>
1747 <div class="paragraph">
1748 <p>In general it&#8217;s not necessary to wait for the channel before starting to
1749 use the channel.</p>
1750 </div>
1751 </div>
1752 <div class="sect3">
1753 <h4 id="cockpit-channels-close">channel.close()</h4>
1754 <div class="literalblock">
1755 <div class="content">
1756 <pre>channel.close([options])</pre>
1757 </div>
1758 </div>
1759 <div class="paragraph">
1760 <p>Close the channel.</p>
1761 </div>
1762 <div class="paragraph">
1763 <p>If <code>options</code> is present it can be a plain javascript object containing
1764 additional channel close options to send to the peer. If closing for
1765 because of a problem, set the <code>"problem"</code> field to a
1766 <a href="#cockpit-problems">problem code</a>. If <code>options</code> is not an object it
1767 will be treated as a <code>"problem"</code>.</p>
1768 </div>
1769 <div class="paragraph">
1770 <p>The <a href="#cockpit-channels-close-ev">close event</a> will fire. A channel
1771 can also be closed by a peer or if the underlying transport closes.</p>
1772 </div>
1773 </div>
1774 <div class="sect3">
1775 <h4 id="cockpit-channels-message">channel.onmessage</h4>
1776 <div class="literalblock">
1777 <div class="content">
1778 <pre>channel.addEventListener("message", function(event, data) { ... })</pre>
1779 </div>
1780 </div>
1781 <div class="paragraph">
1782 <p>An event triggered when the channel receives a message. The message is
1783 passed as a string to the handler in the <code>data</code>. In the case of binary
1784 channels <code>data</code> is an <code>Uint8Array</code> or an <code>Array</code> of bytes if the
1785 former is not supported by the browser. The contents of the message
1786 depends on the payload type of the channel.</p>
1787 </div>
1788 </div>
1789 <div class="sect3">
1790 <h4 id="cockpit-channels-oncontrol">channel.oncontrol</h4>
1791 <div class="literalblock">
1792 <div class="content">
1793 <pre>channel.addEventListener("control", function(event, options) { ... })</pre>
1794 </div>
1795 </div>
1796 <div class="paragraph">
1797 <p>An event triggered when the channel receives an control message in the
1798 middle of the flow. One particular use is when the <code>command</code> is set to
1799 <code>"done"</code> then no further messages will be received in the channel. The
1800 exact form of these messages depend on the <code>"payload"</code> of the channel.</p>
1801 </div>
1802 </div>
1803 <div class="sect3">
1804 <h4 id="cockpit-channels-onready">channel.onready</h4>
1805 <div class="literalblock">
1806 <div class="content">
1807 <pre>channel.addEventListener("ready", function(event, options) { ... })</pre>
1808 </div>
1809 </div>
1810 <div class="paragraph">
1811 <p>An event triggered when the other end of the channel is ready to start
1812 processing messages. This indicates the channel is completely open. It
1813 is possible to start sending messages on the channel before this point.</p>
1814 </div>
1815 </div>
1816 <div class="sect3">
1817 <h4 id="cockpit-channels-close-ev">channel.onclose</h4>
1818 <div class="literalblock">
1819 <div class="content">
1820 <pre>channel.addEventListener("close", function(event, options) { ... })</pre>
1821 </div>
1822 </div>
1823 <div class="paragraph">
1824 <p>An event triggered when the channel closes. This can happen either
1825 because <a href="#cockpit-channels-close">channel.close()</a> function was
1826 called, or if the peer closed the channel, or the underlying transport
1827 closes.</p>
1828 </div>
1829 <div class="paragraph">
1830 <p>The <code>options</code> will contain various close information, including a
1831 <code>"problem"</code> field which will be set if the channel was closed because
1832 of a problem.</p>
1833 </div>
1834 </div>
1835 <div class="sect3">
1836 <h4 id="cockpit-transport-origin">cockpit.transport.origin</h4>
1837 <div class="literalblock">
1838 <div class="content">
1839 <pre>cockpit.transport.origin</pre>
1840 </div>
1841 </div>
1842 <div class="paragraph">
1843 <p>The HTTP origin that is being used by the underlying channel transport.
1844 This is read-only, you should not assign a value. If the browser
1845 supports <code>window.location.origin</code> then this will be identical to that
1846 value.</p>
1847 </div>
1848 </div>
1849 <div class="sect3">
1850 <h4 id="cockpit-transport-host">cockpit.transport.host</h4>
1851 <div class="literalblock">
1852 <div class="content">
1853 <pre>cockpit.transport.host</pre>
1854 </div>
1855 </div>
1856 <div class="paragraph">
1857 <p>The host that this transport is going to talk to by default. This is
1858 read-only, you should not assign a value. If the value is null that
1859 means that the transport has not been setup yet.</p>
1860 </div>
1861 </div>
1862 <div class="sect3">
1863 <h4 id="cockpit-transport-csrf-token">cockpit.transport.csrf_token</h4>
1864 <div class="literalblock">
1865 <div class="content">
1866 <pre>cockpit.transport.csrf_token</pre>
1867 </div>
1868 </div>
1869 <div class="paragraph">
1870 <p>A cross site request forgery token for use with external channels. This
1871 becomes valid once the connection is properly established.</p>
1872 </div>
1873 </div>
1874 <div class="sect3">
1875 <h4 id="cockpit-transport-options">cockpit.transport.options</h4>
1876 <div class="literalblock">
1877 <div class="content">
1878 <pre>cockpit.transport.options</pre>
1879 </div>
1880 </div>
1881 <div class="paragraph">
1882 <p>Initialization options received over the underlying channel transport.
1883 These will be empty until connection is properly established.</p>
1884 </div>
1885 </div>
1886 <div class="sect3">
1887 <h4 id="cockpit-transport-wait">cockpit.transport.wait()</h4>
1888 <div class="literalblock">
1889 <div class="content">
1890 <pre>cockpit.transport.wait(callback)</pre>
1891 </div>
1892 </div>
1893 <div class="paragraph">
1894 <p>Call the <code>callback</code> function once the underlying channel transport is
1895 initialized. This will start the initialization if not already in
1896 progress or completed. If the channel transport is already initialized,
1897 then <code>callback</code> will be called immediately.</p>
1898 </div>
1899 <div class="paragraph">
1900 <p>In general it&#8217;s not necessary to wait for the transport before starting
1901 to open channels.</p>
1902 </div>
1903 </div>
1904 <div class="sect3">
1905 <h4 id="cockpit-transport-close">cockpit.transport.close()</h4>
1906 <div class="literalblock">
1907 <div class="content">
1908 <pre>cockpit.transport.close([problem])</pre>
1909 </div>
1910 </div>
1911 <div class="paragraph">
1912 <p>Close the underlying channel transport. All channels open channels will
1913 close. The <code>problem</code> argument should be a problem code string. If not
1914 specified it will default to <code>"disconnected"</code>.</p>
1915 </div>
1916 </div>
1917 <div class="sect3">
1918 <h4 id="cockpit-transport-filter">cockpit.transport.filter()</h4>
1919 <div class="literalblock">
1920 <div class="content">
1921 <pre>cockpit.transport.filter((message, channelid, control) =&gt; { ... })</pre>
1922 </div>
1923 </div>
1924 <div class="paragraph">
1925 <p>Add a filter to the underlying channel transport. All incoming messages
1926 will be passed to each of the filter callbacks that are registered.</p>
1927 </div>
1928 <div class="paragraph">
1929 <p>This function is rarely used.</p>
1930 </div>
1931 <div class="paragraph">
1932 <p>Filter callbacks are called in the order they are registered. If a
1933 filter callback returns <code>false</code> then the message will not be
1934 dispatched further, whether to other filters, or to channels, etc.</p>
1935 </div>
1936 <div class="paragraph">
1937 <p>The <code>message</code> is the string or array with the raw message including,
1938 the framing. The <code>channelid</code> is the channel identifier or an empty
1939 string for control messages. If <code>control</code> is set then this is a
1940 control message,d and the <code>control</code> argument contains the parsed JSON
1941 object of the control message.</p>
1942 </div>
1943 </div>
1944 <div class="sect3">
1945 <h4 id="cockpit-transport-inject">cockpit.transport.inject()</h4>
1946 <div class="literalblock">
1947 <div class="content">
1948 <pre>cockpit.transport.inject(message, [out])</pre>
1949 </div>
1950 </div>
1951 <div class="paragraph">
1952 <p>Inject a message into the underlying channel transport. The <code>message</code>
1953 should be a <code>string</code> or an array of bytes, and should be valid
1954 according to the Cockpit message protocol. If the <code>out</code> argument is
1955 equal to <code>false</code> then the message will be injected as an incoming
1956 message as if it was received on the underlying channel transport.</p>
1957 </div>
1958 <div class="paragraph">
1959 <p>This function is rarely used. In general you should only <code>inject()</code>
1960 messages you got from a <code>filter()</code>.</p>
1961 </div>
1962 </div>
1963 <div class="sect3">
1964 <h4 id="cockpit-base64-encode">cockpit.base64_encode()</h4>
1965 <div class="literalblock">
1966 <div class="content">
1967 <pre>string = cockpit.base64_encode(data)</pre>
1968 </div>
1969 </div>
1970 <div class="paragraph">
1971 <p>Encode binary data into a string using the Base64 encoding. The <code>data</code>
1972 argument can either be a <code>string</code>, an <code>Array</code>, an <code>ArrayBuffer</code> or
1973 a <code>Uint8Array</code>. The return value is a string.</p>
1974 </div>
1975 </div>
1976 <div class="sect3">
1977 <h4 id="cockpit-base64-decode">cockpit.base64_decode()</h4>
1978 <div class="literalblock">
1979 <div class="content">
1980 <pre>data = cockpit.base64_decode(string, [constructor])</pre>
1981 </div>
1982 </div>
1983 <div class="paragraph">
1984 <p>Decode binary data from a Base64 encoded string. The <code>string</code> argument
1985 should be a javascript string. The returned <code>data</code>&gt; will be an array
1986 of bytes.</p>
1987 </div>
1988 <div class="paragraph">
1989 <p>You can pass <code>Uint8Array</code>, <code>Array</code> or <code>String</code> as an alternate
1990 <code>constructor</code> if you want the decoded data in an alternate form. The
1991 default is to return an <code>Array</code>. Note that if you use a <code>String</code> for
1992 the decoded data, then you must guarantee that the data does not contain
1993 bytes that would be invalid for a string.</p>
1994 </div>
1995 </div>
1996 </div>
1997 <div class="sect2">
1998 <h3 id="_cockpit_js_dbus_client">cockpit.js: DBus Client</h3>
1999 <div class="paragraph">
2000 <p>Cockpit allows access to DBus services via this API.</p>
2001 </div>
2002 <div class="sect3">
2003 <h4 id="cockpit-dbus-types">DBus Types</h4>
2004 <div class="paragraph">
2005 <p>DBus values are represented as javascript values and objects as follows:</p>
2006 </div>
2007 <div class="dlist">
2008 <dl>
2009 <dt class="hdlist1"><code>BYTE 'y'</code></dt>
2010 <dd>
2011 <p>Javascript number.</p>
2012 </dd>
2013 <dt class="hdlist1"><code>BOOLEAN 'b'</code></dt>
2014 <dd>
2015 <p>Javascript boolean.</p>
2016 </dd>
2017 <dt class="hdlist1"><code>INT16 'n'</code></dt>
2018 <dd>
2019 <p>Javascript number.</p>
2020 </dd>
2021 <dt class="hdlist1"><code>UINT16 'q'</code></dt>
2022 <dd>
2023 <p>Javascript number.</p>
2024 </dd>
2025 <dt class="hdlist1"><code>INT32 'i'</code></dt>
2026 <dd>
2027 <p>Javascript number.</p>
2028 </dd>
2029 <dt class="hdlist1"><code>UINT32 'u'</code></dt>
2030 <dd>
2031 <p>Javascript number.</p>
2032 </dd>
2033 <dt class="hdlist1"><code>INT64 'x'</code></dt>
2034 <dd>
2035 <p>Javascript number.</p>
2036 </dd>
2037 <dt class="hdlist1"><code>UINT64 't'</code></dt>
2038 <dd>
2039 <p>Javascript number.</p>
2040 </dd>
2041 <dt class="hdlist1"><code>DOUBLE 'd'</code></dt>
2042 <dd>
2043 <p>Javascript number.</p>
2044 </dd>
2045 <dt class="hdlist1"><code>STRING 's'</code></dt>
2046 <dd>
2047 <p>Javascript string.</p>
2048 </dd>
2049 <dt class="hdlist1"><code>OBJECT_PATH 'o'</code></dt>
2050 <dd>
2051 <p>Javascript string.</p>
2052 </dd>
2053 <dt class="hdlist1"><code>SIGNATURE 'g'</code></dt>
2054 <dd>
2055 <p>Javascript string.</p>
2056 </dd>
2057 <dt class="hdlist1"><code>ARRAY of BYTE 'ay'</code></dt>
2058 <dd>
2059 <p>A string containing base64 encoded data.</p>
2060 </dd>
2061 <dt class="hdlist1"><code>ARRAY of DICT_ENTRY with STRING keys 'a{s?}'</code></dt>
2062 <dd>
2063 <p>A javascript plain object with the keys as property names.</p>
2064 </dd>
2065 <dt class="hdlist1"><code>ARRAY of DICT_ENTRY with other keys 'a{??}'</code></dt>
2066 <dd>
2067 <p>A javascript plain object each key JSON encoded into a string property
2068 name.</p>
2069 </dd>
2070 <dt class="hdlist1"><code>ARRAY of other</code></dt>
2071 <dd>
2072 <p>A javascript array.</p>
2073 </dd>
2074 <dt class="hdlist1"><code>VARIANT</code></dt>
2075 <dd>
2076 <p>A javascript plain object with the <code>"t"</code> property set to a DBus type
2077 string, and the <code>"v"</code> property set to a value.</p>
2078 </dd>
2079 <dt class="hdlist1"><code>HANDLE 'h'</code></dt>
2080 <dd>
2081 <p>A javascript object that describes a cockpit channel which represents
2082 the passed file descriptor. The <code>payload</code> is always set to
2083 <code>stream</code>. Pass it to
2084 <a href="#cockpit-channels-channel">cockpit.channel()</a> to create the
2085 channel and start reading or writing on it. Handles can only be
2086 received, not sent from within cockpit.</p>
2087 </dd>
2088 </dl>
2089 </div>
2090 </div>
2091 <div class="sect3">
2092 <h4 id="cockpit-dbus-dbus">cockpit.dbus()</h4>
2093 <div class="literalblock">
2094 <div class="content">
2095 <pre>client = cockpit.dbus(name, [options])</pre>
2096 </div>
2097 </div>
2098 <div class="paragraph">
2099 <p>Create a DBus client for the given bus <code>name</code> (eg: service name). Use
2100 the following functions to make DBus method calls, watch for events,
2101 etc. The optional <code>options</code> argument is a javascript plain object, and
2102 may include:</p>
2103 </div>
2104 <div class="dlist">
2105 <dl>
2106 <dt class="hdlist1"><code>"bus"</code></dt>
2107 <dd>
2108 <p>The DBus bus to connect to. Specifying <code>"session"</code> will connect to
2109 the DBus user session bus, <code>"user"</code> will connect to the user bus (on
2110 some systems this is identical to the session bus), <code>"system"</code> will
2111 connect to the DBus system bus, and <code>"none"</code> to the non-standard bus
2112 specified with the <code>address</code> option. This defaults to "system" if
2113 not present.</p>
2114 </dd>
2115 <dt class="hdlist1"><code>"address"</code></dt>
2116 <dd>
2117 <p>The bus address to connect to in case <code>bus</code> is <code>"none"</code>.</p>
2118 </dd>
2119 <dt class="hdlist1"><code>"superuser"</code></dt>
2120 <dd>
2121 <p>Set to <code>"require"</code> to talk to this service as root. The DBus service
2122 will see the DBus method calls and accesses as coming from root,
2123 rather than the logged in user. This is useful for talking to services
2124 that do not correctly use
2125 <a href="https://www.freedesktop.org/software/polkit">polkit</a> to authorize
2126 administrative users. If the currently logged in user is not permitted
2127 to become root (eg: via <code>pkexec</code>) then the <code>client</code> will
2128 immediately be <a href="#cockpit-dbus-onclose">closed</a> with a
2129 <code>"access-denied"</code> problem code.
2130 +
2131 Set to <code>"try"</code> to try to talk as root, but if that fails, fall back
2132 to unprivileged.</p>
2133 </dd>
2134 <dt class="hdlist1"><code>"track"</code></dt>
2135 <dd>
2136 <p>It is valid for a DBus service to exit, and be restarted in such a way
2137 that clients continue to talk to it across the restart. Some services
2138 are not written with this in mind. If the <code>"track"</code> option is set to
2139 <code>true</code> then the channel will close when the service exits and/or
2140 disconnects from the DBus bus.</p>
2141 </dd>
2142 </dl>
2143 </div>
2144 <div class="paragraph">
2145 <p>If the <code>name</code> argument is null, and no options other than <code>"bus"</code>
2146 are specified, then a shared DBus <code>client</code> is created. When using such
2147 a client with a DBus bus, a <code>"name"</code> option must be specified on
2148 various other methods in order to specify which client to talk to.</p>
2149 </div>
2150 </div>
2151 <div class="sect3">
2152 <h4 id="cockpit-dbus-wait">client.wait()</h4>
2153 <div class="literalblock">
2154 <div class="content">
2155 <pre>promise = client.wait([callback])</pre>
2156 </div>
2157 </div>
2158 <div class="paragraph">
2159 <p>Returns a <code>promise</code> that is ready when the client is ready, or fails
2160 if the client closes. If a <code>callback</code> is specified, it is attached to
2161 the promise.</p>
2162 </div>
2163 </div>
2164 <div class="sect3">
2165 <h4 id="cockpit-dbus-close">client.close()</h4>
2166 <div class="literalblock">
2167 <div class="content">
2168 <pre>client.close([problem])</pre>
2169 </div>
2170 </div>
2171 <div class="paragraph">
2172 <p>Close the DBus client. If <code>problem</code> is specified it should be a
2173 <a href="#cockpit-problems">problem code</a> string.</p>
2174 </div>
2175 </div>
2176 <div class="sect3">
2177 <h4 id="cockpit-dbus-onclose">client.onclose</h4>
2178 <div class="literalblock">
2179 <div class="content">
2180 <pre>client.addEventListener("close", options =&gt; { ... })</pre>
2181 </div>
2182 </div>
2183 <div class="paragraph">
2184 <p>An event triggered when the DBus client closes. This can happen either
2185 because <a href="#cockpit-dbus-close">client.close()</a> function was called, or
2186 the DBus service went away, or some other problem or disconnection.</p>
2187 </div>
2188 <div class="paragraph">
2189 <p>The <code>options</code> will contain various close information, including a
2190 <code>"problem"</code> field which will be set if the channel was closed because
2191 of a problem.</p>
2192 </div>
2193 </div>
2194 <div class="sect3">
2195 <h4 id="cockpit-dbus-onowned">client.onowner</h4>
2196 <div class="literalblock">
2197 <div class="content">
2198 <pre>client.addEventListener("owner", (event, owner) =&gt; { ... })</pre>
2199 </div>
2200 </div>
2201 <div class="paragraph">
2202 <p>An event triggered when the owner of the DBus name changes. The owner
2203 value will be the id of the name owner on the bus or null if the name is
2204 unowned. The absence of an owner should not be treated as a
2205 disconnection. However this makes it possible to take some action based
2206 on the actual status of the service, for example disconnecting a pending
2207 signal handler.</p>
2208 </div>
2209 </div>
2210 <div class="sect3">
2211 <h4 id="cockpit-dbus-options">client.options</h4>
2212 <div class="paragraph">
2213 <p>Set to the options used when creating the client. Will not change for
2214 the life of the client.</p>
2215 </div>
2216 </div>
2217 <div class="sect3">
2218 <h4 id="cockpit-dbus-unique-name">client.unique_name</h4>
2219 <div class="paragraph">
2220 <p>The unique DBus name of the client. Initially null, and becomes valid
2221 once the the client is ready.</p>
2222 </div>
2223 </div>
2224 <div class="sect3">
2225 <h4 id="cockpit-dbus-proxy">client.proxy()</h4>
2226 <div class="literalblock">
2227 <div class="content">
2228 <pre>proxy = client.proxy([interface, path], [options])</pre>
2229 </div>
2230 </div>
2231 <div class="paragraph">
2232 <p>Create proxy javascript object for a DBus <code>interface</code>. At the
2233 specified DBus object <code>path</code>. The proxy will have properties, methods
2234 and signals from to the DBus interface, and allows for natural
2235 interaction. If no <code>interface</code> is specified then the DBus bus name of
2236 the client is used. If no <code>path</code> is specified, then the DBus name of
2237 the client is converted to a path.</p>
2238 </div>
2239 <div class="paragraph">
2240 <p>If creating lots of proxies for a given <code>interface</code> it is more
2241 efficient to use the <a href="#cockpit-dbus-proxies"><code>client.proxies()</code></a>
2242 function.</p>
2243 </div>
2244 <div class="paragraph">
2245 <p>The proxy is loaded when the
2246 <a href="#cockpit-dbus-proxy-valid"><code>proxy.valid</code></a> field is <code>true</code>, and
2247 it is set to <code>false</code> if the underlying <code>interface</code> and/or <code>path</code>
2248 don&#8217;t or no longer exist, or the <code>client</code> has closed. You can wait for
2249 proxy to become valid by passing a callback to its
2250 <a href="#cockpit-dbus-proxy-wait"><code>proxy.wait()</code></a> function. The
2251 <a href="#cockpit-dbus-proxy-onchanged"><code>proxy.onchanged</code></a> event will also
2252 fire when the proxy becomes valid or invalid. DBus properties and
2253 methods on the proxy are not defined until the proxy becomes valid.</p>
2254 </div>
2255 <div class="literalblock">
2256 <div class="content">
2257 <pre>value = proxy.Prop1
2258 proxy.WritableProp = value</pre>
2259 </div>
2260 </div>
2261 <div class="paragraph">
2262 <p>All DBus properties on the <code>interface</code> that start with an upper case
2263 letter (as is convention) will be automatically defined on this proxy,
2264 and will update their values as the DBus property values change. In
2265 addition the <a href="#cockpit-dbus-proxy-onchanged"><code>proxy.onchanged</code></a>
2266 event will fire every time the properties change.</p>
2267 </div>
2268 <div class="paragraph">
2269 <p>If you assign a value to a writable property on the proxy, the proxy
2270 will try to set that property on the DBus <code>interface</code> at <code>path</code>. The
2271 actual proxy property value will not update until the DBus service has
2272 notified the proxy of the change. If setting a property fails a warning
2273 will be logged. In order to have more reliable setting of properties, or
2274 track when they have been set, or if setting fails, use the
2275 <a href="#cockpit-dbus-call"><code>client.call()</code></a> directly. It should be noted
2276 that DBus service implementations may also be inconsistent in their
2277 behavior when setting a property fails.</p>
2278 </div>
2279 <div class="paragraph">
2280 <p>You can access the raw property data using the
2281 <a href="#cockpit-dbus-proxy-data"><code>proxy.data</code></a> field, including data for
2282 properties that do not start with an upper case letter.</p>
2283 </div>
2284 <div class="literalblock">
2285 <div class="content">
2286 <pre>proxy.Method(arg1, arg2)
2287 .then((retval1, retval2) =&gt; {
2288 ...
2289 })
2290 .catch(ex =&gt; {
2291 ...
2292 });</pre>
2293 </div>
2294 </div>
2295 <div class="paragraph">
2296 <p>All DBus methods on the <code>interface</code> that start with an upper case
2297 letter (as is convention) will be automatically defined on this proxy.
2298 These methods are called with arguments as normal javascript arguments.
2299 A
2300 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
2301 that will complete successfully when the method returns, or fail if an
2302 error occurs. The return values from the DBus method will be passed to
2303 the <code>then</code> handler function directly.</p>
2304 </div>
2305 <div class="paragraph">
2306 <p>Methods that do not start with an upper case letter can be invoked by
2307 using the usual <a href="#cockpit-dbus-proxy-call"><code>proxy.call()</code></a>
2308 directly.</p>
2309 </div>
2310 <div class="literalblock">
2311 <div class="content">
2312 <pre>proxy.addEventListener("signal", (event, arg1, arg2) =&gt; {
2313 ...
2314 });</pre>
2315 </div>
2316 </div>
2317 <div class="paragraph">
2318 <p>All DBus signals on the <code>interface</code> that start with an upper case
2319 letter (as is convention) will be automatically emit events on this
2320 proxy. These events will contain the signal arguments after the standard
2321 <code>event</code> argument.</p>
2322 </div>
2323 <div class="paragraph">
2324 <p>Signals that do not start with an upper case letter can be subscribed to
2325 by using <a href="#cockpit-dbus-proxy-signal"><code>proxy.onsignal</code></a> directly.</p>
2326 </div>
2327 <div class="paragraph">
2328 <p>Usually a proxy asks the <code>client</code> to watch and notify it of changes to
2329 the relevant object or path. You can pass an <code>options</code> argument with
2330 the <code>watch</code> field set to <code>false</code> to prevent this.</p>
2331 </div>
2332 </div>
2333 <div class="sect3">
2334 <h4 id="cockpit-dbus-proxy-client">proxy.client</h4>
2335 <div class="paragraph">
2336 <p>Set to the DBus client of the proxy. Will not change for the life of the
2337 proxy.</p>
2338 </div>
2339 </div>
2340 <div class="sect3">
2341 <h4 id="cockpit-dbus-proxy-path">proxy.path</h4>
2342 <div class="paragraph">
2343 <p>Set to the DBus object path of the proxy. Will not change for the life
2344 of the proxy.</p>
2345 </div>
2346 </div>
2347 <div class="sect3">
2348 <h4 id="cockpit-dbus-proxy-iface">proxy.iface</h4>
2349 <div class="paragraph">
2350 <p>Set to the DBus interface name of the proxy. Will not change for the
2351 life of the proxy.</p>
2352 </div>
2353 </div>
2354 <div class="sect3">
2355 <h4 id="cockpit-dbus-proxy-valid">proxy.valid</h4>
2356 <div class="paragraph">
2357 <p>Set to <code>true</code> when the proxy&#8217;s DBus interface is present at its DBus
2358 path, and all information for the proxy has loaded. Is set to <code>false</code>
2359 while loading, and after the proxy no longer refers a DBus interface and
2360 path. Also set to <code>false</code> if the <code>client</code> closes.</p>
2361 </div>
2362 <div class="paragraph">
2363 <p>Use the by <a href="#cockpit-dbus-proxy-wait"><code>proxy.wait()</code></a> function to
2364 wait for a proxy to load. The
2365 <a href="#cockpit-dbus-proxy-onchanged"><code>proxy.onchanged</code></a> event will also
2366 be emitted when the proxy becomes valid or invalid. DBus properties and
2367 methods on the proxy are not defined until the proxy becomes valid.</p>
2368 </div>
2369 </div>
2370 <div class="sect3">
2371 <h4 id="cockpit-dbus-proxy-data">proxy.data</h4>
2372 <div class="paragraph">
2373 <p>A plain javascript object containing all the raw property data that this
2374 proxy has loaded. This will be updated automatically as the proxy is
2375 notified of property changes from the DBus service. The
2376 <a href="#cockpit-dbus-proxy-onchanged"><code>proxy.onchanged</code></a> event will be
2377 emitted when it changes.</p>
2378 </div>
2379 </div>
2380 <div class="sect3">
2381 <h4 id="cockpit-dbus-proxy-call">proxy.call()</h4>
2382 <div class="literalblock">
2383 <div class="content">
2384 <pre>invocation = proxy.call(method, args, [options])</pre>
2385 </div>
2386 </div>
2387 <div class="paragraph">
2388 <p>Make a DBus method call on this proxy.</p>
2389 </div>
2390 <div class="paragraph">
2391 <p>For DBus methods that start with an upper case letter, is usually more
2392 convenient <a href="#cockpit-dbus-proxy">to call the method directly on the
2393 proxy</a>. However if methods that do not follow the usual DBus convention,
2394 or specify additional options, or the caller cannot be sure that the
2395 method actually exists, you can use this method.</p>
2396 </div>
2397 <div class="paragraph">
2398 <p>This function also works on proxies that have are still loading and have
2399 not become valid yet.</p>
2400 </div>
2401 <div class="paragraph">
2402 <p>The <code>method</code> should be a DBus method name, and the <code>args</code> should be
2403 an array of arguments to pass to the method. The <code>options</code> are
2404 <a href="#cockpit-dbus-call">described elsewhere</a>.</p>
2405 </div>
2406 <div class="paragraph">
2407 <p>The returned value is identical to the one returned from
2408 <a href="#cockpit-dbus-call">client.call()</a>. It is a
2409 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
2410 that will complete successfully when the method returns, or fail if an
2411 error occurs.</p>
2412 </div>
2413 </div>
2414 <div class="sect3">
2415 <h4 id="cockpit-dbus-proxy-wait">proxy.wait()</h4>
2416 <div class="literalblock">
2417 <div class="content">
2418 <pre>promise = proxy.wait()
2419 proxy.wait(() =&gt; {
2420 ...
2421 });</pre>
2422 </div>
2423 </div>
2424 <div class="paragraph">
2425 <p>Wait for a proxy to finish loading. This function returns a promise. If
2426 a callback function is passed as an argument then that function will be
2427 invoked when the proxy is ready. If this method is called after a proxy
2428 has already loaded, then the promise will be resolved immediately, and
2429 any callback will be invoked immediately. Use the promise or
2430 <code>proxy.valid</code> to determine whether the proxy is valid.</p>
2431 </div>
2432 </div>
2433 <div class="sect3">
2434 <h4 id="cockpit-dbus-proxy-onchanged">proxy.onchanged</h4>
2435 <div class="literalblock">
2436 <div class="content">
2437 <pre>proxy.addEventListener("changed", (event, data) =&gt; {
2438 ...
2439 });</pre>
2440 </div>
2441 </div>
2442 <div class="paragraph">
2443 <p>This event is emitted when the proxy&#8217;s properties change.</p>
2444 </div>
2445 <div class="paragraph">
2446 <p>The <code>data</code> has the following form, and will only include properties
2447 that have changed:</p>
2448 </div>
2449 <div class="literalblock">
2450 <div class="content">
2451 <pre>{
2452 "Prop1": "value",
2453 "Prop2": 5
2454 }</pre>
2455 </div>
2456 </div>
2457 </div>
2458 <div class="sect3">
2459 <h4 id="cockpit-dbus-proxy-signal">proxy.onsignal</h4>
2460 <div class="literalblock">
2461 <div class="content">
2462 <pre>proxy.addEventListener("signal", (event, name, args) =&gt; {
2463 ...
2464 });</pre>
2465 </div>
2466 </div>
2467 <div class="paragraph">
2468 <p>This event is emitted when the proxy&#8217;s emits an event.</p>
2469 </div>
2470 <div class="paragraph">
2471 <p>For most events, that have names which start with an upper case letter,
2472 you can just <a href="#cockpit-dbus-proxy">connect to that event as a signal
2473 directly</a>. However if you wish to be notified when any signal is
2474 emitted, or for signals that do not follow the usual DBus convention,
2475 you can connect to this event.</p>
2476 </div>
2477 <div class="paragraph">
2478 <p>The <code>name</code> is the DBus signal name, and the <code>args</code> is an array of
2479 arguments that were emitted with the signal.</p>
2480 </div>
2481 </div>
2482 <div class="sect3">
2483 <h4 id="cockpit-dbus-proxies">client.proxies()</h4>
2484 <div class="literalblock">
2485 <div class="content">
2486 <pre>proxies = client.proxies([interface], [path_namespace], [options])</pre>
2487 </div>
2488 </div>
2489 <div class="paragraph">
2490 <p>Create <a href="#cockpit-dbus-proxy">proxy javascript objects</a> for a DBus
2491 interfaces. The proxies will have properties, methods and signals from
2492 the DBus <code>interface</code>, and allow for natural interaction. If no
2493 <code>interface</code> is specified then the DBus bus name of the client is used.
2494 If no <code>path_namespace</code> is provided then <code>"/"</code> will be used.</p>
2495 </div>
2496 <div class="paragraph">
2497 <p>Proxies will be automatically created for instances of the <code>interface</code>
2498 available at the DBus service. The optional <code>path_namespace</code> argument
2499 can be used to restrict the proxies for instances that have DBus paths
2500 which have the namespace path prefix.</p>
2501 </div>
2502 <div class="literalblock">
2503 <div class="content">
2504 <pre>proxy1 = proxies["/dbus/path1"];
2505 proxy2 = proxies["/dbus/path2"];
2506 for (proxy in proxies) {
2507 ...
2508 }</pre>
2509 </div>
2510 </div>
2511 <div class="paragraph">
2512 <p>The returned <code>proxies</code> object will is used as a dictionary, and will
2513 have values containing proxies for DBus interface instances, with the
2514 keys being the DBus paths of those instances. It is possible to
2515 enumerate over the returned <code>proxies</code>.</p>
2516 </div>
2517 <div class="paragraph">
2518 <p>Proxies will be automatically added and removed from the <code>proxies</code>
2519 object as they appear and disappear in the service. The
2520 <a href="#cockpit-dbus-proxies-onadded"><code>proxies.onadded</code></a> and
2521 <a href="#cockpit-dbus-proxies-onremoved"><code>proxies.onremoved</code></a> events will
2522 be emitted. DBus services may not support notifications of paths
2523 disappearing.</p>
2524 </div>
2525 <div class="paragraph">
2526 <p>Use the <code>proxies.wait()</code> function to be notified when the initial set
2527 of proxies has been populated.</p>
2528 </div>
2529 <div class="paragraph">
2530 <p>Usually a proxies ask the <code>client</code> to watch and be notified of changes
2531 to the relevant object or path. You can pass an <code>options</code> argument
2532 with the <code>watch</code> field set to <code>false</code> to prevent this.</p>
2533 </div>
2534 </div>
2535 <div class="sect3">
2536 <h4 id="cockpit-dbus-proxies-wait">proxies.wait()</h4>
2537 <div class="literalblock">
2538 <div class="content">
2539 <pre>promise = proxies.wait()
2540 proxies.wait(() =&gt; {
2541 ...
2542 });</pre>
2543 </div>
2544 </div>
2545 <div class="paragraph">
2546 <p>Wait for a <code>proxies</code> object to populate its initial set of proxies.
2547 This function returns a promise. If a callback function is passed as an
2548 argument then that function will be invoked when the proxies are ready.
2549 If this method is called after the proxies have populated, then the
2550 promise will be resolved immediately, and any callback will be invoked
2551 immediately.</p>
2552 </div>
2553 </div>
2554 <div class="sect3">
2555 <h4 id="cockpit-dbus-proxies-client">proxies.client</h4>
2556 <div class="paragraph">
2557 <p>Set to the DBus client of the proxies. Will not change.</p>
2558 </div>
2559 </div>
2560 <div class="sect3">
2561 <h4 id="cockpit-dbus-proxies-iface">proxies.iface</h4>
2562 <div class="paragraph">
2563 <p>Set to the DBus interface name of the proxies. Will not change.</p>
2564 </div>
2565 </div>
2566 <div class="sect3">
2567 <h4 id="cockpit-dbus-proxies-path_namespace">proxies.path_namespace</h4>
2568 <div class="paragraph">
2569 <p>Set to the DBus path namespace used which the proxies must have as a
2570 DBus path prefix. Will not change.</p>
2571 </div>
2572 </div>
2573 <div class="sect3">
2574 <h4 id="cockpit-dbus-proxies-onadded">proxies.onadded</h4>
2575 <div class="literalblock">
2576 <div class="content">
2577 <pre>proxies.addEventListener("added", (event, proxy) =&gt; {
2578 ...
2579 })</pre>
2580 </div>
2581 </div>
2582 <div class="paragraph">
2583 <p>This event is emitted when a proxy is added to the <code>proxies</code> object.
2584 The proxy will already have loaded.</p>
2585 </div>
2586 </div>
2587 <div class="sect3">
2588 <h4 id="cockpit-dbus-proxies-onchanged">proxies.onchanged</h4>
2589 <div class="literalblock">
2590 <div class="content">
2591 <pre>proxies.addEventListener("changed", (event, proxy) =&gt; {
2592 ...
2593 })</pre>
2594 </div>
2595 </div>
2596 <div class="paragraph">
2597 <p>This event is emitted when one of the proxy in the <code>proxies</code> object
2598 changes its properties.</p>
2599 </div>
2600 </div>
2601 <div class="sect3">
2602 <h4 id="cockpit-dbus-proxies-onremoved">proxies.onremoved</h4>
2603 <div class="literalblock">
2604 <div class="content">
2605 <pre>proxies.addEventListener("removed", (event, proxy) =&gt; {
2606 ...
2607 })</pre>
2608 </div>
2609 </div>
2610 <div class="paragraph">
2611 <p>This event is emitted when a proxy is removed to the <code>proxies</code> object.</p>
2612 </div>
2613 </div>
2614 <div class="sect3">
2615 <h4 id="cockpit-dbus-call">client.call()</h4>
2616 <div class="literalblock">
2617 <div class="content">
2618 <pre>invocation = client.call(path, interface, method, args, [options])</pre>
2619 </div>
2620 </div>
2621 <div class="paragraph">
2622 <p>Make a DBus method call.</p>
2623 </div>
2624 <div class="paragraph">
2625 <p>The <code>path</code> is the DBus object path to make the call on, <code>interface</code>
2626 is the DBus interface for the method and <code>method</code> is the name of the
2627 method to call. The <code>args</code> is an array of arguments to pass to the
2628 method, each of which must be appropriate for the expected
2629 <a href="#cockpit-dbus">DBus type</a> of that argument. The <code>args</code> may be
2630 <code>null</code> if no arguments are to be sent.</p>
2631 </div>
2632 <div class="paragraph">
2633 <p>The returned value is a
2634 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
2635 that will complete successfully when the method returns, or fail if an
2636 error occurs.</p>
2637 </div>
2638 <div class="paragraph">
2639 <p>If <code>options</code> is specified it should be a plain javascript object,
2640 which may contain the following properties:</p>
2641 </div>
2642 <div class="dlist">
2643 <dl>
2644 <dt class="hdlist1"><code>flags</code></dt>
2645 <dd>
2646 <p>A string containing DBus message flags. The character <code>"i"</code>
2647 indicates to the dbus service that interactive authentication is
2648 allowed. If the entire <code>flags</code> field is missing, then <code>"i"</code> is set
2649 by default.</p>
2650 </dd>
2651 <dt class="hdlist1"><code>type</code></dt>
2652 <dd>
2653 <p>A valid DBus type signature to use when calling the method. In the
2654 absence of this, the DBus service will be introspected (and the result
2655 cached) to ask what the method type signature is.</p>
2656 </dd>
2657 <dt class="hdlist1"><code>timeout</code></dt>
2658 <dd>
2659 <p>The timeout of the call in milliseconds. The call will fail with the
2660 <code>"timeout"</code> problem code. If "timeout" is not given, the call will
2661 never time out.</p>
2662 </dd>
2663 </dl>
2664 </div>
2665 </div>
2666 <div class="sect3">
2667 <h4 id="cockpit-dbus-then">invocation.then()</h4>
2668 <div class="literalblock">
2669 <div class="content">
2670 <pre>invocation.then((args, options) =&gt; { ... })</pre>
2671 </div>
2672 </div>
2673 <div class="paragraph">
2674 <p>This is a standard
2675 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
2676 method. It sets up a handler to be called when the DBus method call
2677 finishes successfully.</p>
2678 </div>
2679 <div class="paragraph">
2680 <p>The <code>args</code> argument is an array of return values from the DBus method.
2681 Each of them will be converted to an appropriate
2682 <a href="#cockpit-dbus">javascript type</a>.</p>
2683 </div>
2684 <div class="paragraph">
2685 <p>The <code>options</code> argument may contain additional information about the
2686 reply. If the <code>type</code> option was specified when performing the method
2687 call, then the <code>options</code> in the reply here will also contain a
2688 <code>type</code> field containing the DBus type signature of the output. If the
2689 <code>flags</code> option was specified when performing the call then the
2690 <code>options</code> in the reply here will contain message flags. Possible out
2691 message flags are:</p>
2692 </div>
2693 <div class="dlist">
2694 <dl>
2695 <dt class="hdlist1"><code>&gt;</code></dt>
2696 <dd>
2697 <p>A big endian message.</p>
2698 </dd>
2699 <dt class="hdlist1"><code>&lt;</code></dt>
2700 <dd>
2701 <p>A little endian message.</p>
2702 </dd>
2703 </dl>
2704 </div>
2705 </div>
2706 <div class="sect3">
2707 <h4 id="cockpit-dbus-catch">invocation.catch()</h4>
2708 <div class="literalblock">
2709 <div class="content">
2710 <pre>invocation.catch(exception =&gt; { ... })</pre>
2711 </div>
2712 </div>
2713 <div class="paragraph">
2714 <p>This is a standard
2715 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
2716 method. It sets up a handler to be called when the DBus method call
2717 fails.</p>
2718 </div>
2719 <div class="paragraph">
2720 <p>The <code>exception</code> object passed to the handler can have the following
2721 properties:</p>
2722 </div>
2723 <div class="dlist">
2724 <dl>
2725 <dt class="hdlist1"><code>problem</code></dt>
2726 <dd>
2727 <p>A <a href="#cockpit-problems">problem code</a> string when a problem occurred
2728 starting or communicating with the DBus service. This is <code>null</code> in
2729 the cases where an actual DBus error was occurred.</p>
2730 </dd>
2731 <dt class="hdlist1"><code>name</code></dt>
2732 <dd>
2733 <p>The DBus error name. This will be <code>null</code> in cases where the failure
2734 was not due to a DBus error.</p>
2735 </dd>
2736 <dt class="hdlist1"><code>message</code></dt>
2737 <dd>
2738 <p>A DBus error message. This will be <code>null</code> in cases where the failure
2739 was not due to a DBus error.</p>
2740 </dd>
2741 </dl>
2742 </div>
2743 </div>
2744 <div class="sect3">
2745 <h4 id="cockpit-dbus-subscribe">client.subscribe()</h4>
2746 <div class="literalblock">
2747 <div class="content">
2748 <pre>subscription = client.subscribe(match, (path, interface, signal, args) =&gt; { ... })</pre>
2749 </div>
2750 </div>
2751 <div class="paragraph">
2752 <p>Subscribe to signals. The <code>match</code> argument is a javascript plain
2753 object which defines what signals to subscribe to. Each property in the
2754 <code>match</code> argument restricts signals subscribed to. If a property is not
2755 present then it is treated as a wildcard, matching anything. If an empty
2756 object is specified as <code>match</code> then all signals will be subscribed to.
2757 The <code>match</code> argument may contain the following properties:</p>
2758 </div>
2759 <div class="dlist">
2760 <dl>
2761 <dt class="hdlist1"><code>interface</code></dt>
2762 <dd>
2763 <p>A DBus interface to match.</p>
2764 </dd>
2765 <dt class="hdlist1"><code>path</code></dt>
2766 <dd>
2767 <p>A DBus object path to match. May not be used together with the
2768 <code>path_namespace</code> property. It should be a valid DBus object path,
2769 that is, it should have no trailing slash.</p>
2770 </dd>
2771 <dt class="hdlist1"><code>path_namespace</code></dt>
2772 <dd>
2773 <p>A DBus object path prefix to match. Any paths in the hierarchy below
2774 this top path will match. May not be used together with the <code>path</code>
2775 property.</p>
2776 </dd>
2777 <dt class="hdlist1"><code>member</code></dt>
2778 <dd>
2779 <p>The DBus signal name to match.</p>
2780 </dd>
2781 <dt class="hdlist1"><code>arg0</code></dt>
2782 <dd>
2783 <p>Matches the first argument of a DBus message, which must be a string.</p>
2784 </dd>
2785 </dl>
2786 </div>
2787 <div class="paragraph">
2788 <p>The handler passed as the second argument will be invoked when the
2789 signal is received. A <code>subscription</code> is returned which can be used to
2790 remove the subscription by calling its <code>subscription.remove()</code> method.</p>
2791 </div>
2792 <div class="paragraph">
2793 <p>It is not a problem to subscribe to the same signals more than once,
2794 with identical or slightly different <code>match</code> arguments.</p>
2795 </div>
2796 </div>
2797 <div class="sect3">
2798 <h4 id="cockpit-dbus-remove">subscription.remove()</h4>
2799 <div class="literalblock">
2800 <div class="content">
2801 <pre>subscription.remove()</pre>
2802 </div>
2803 </div>
2804 <div class="paragraph">
2805 <p>Unsubscribe from the DBus signal subscription.</p>
2806 </div>
2807 </div>
2808 <div class="sect3">
2809 <h4 id="cockpit-dbus-watch">client.watch()</h4>
2810 <div class="literalblock">
2811 <div class="content">
2812 <pre>watch = client.watch(path)
2813 watch = client.watch({ "path_namespace": path_namespace, "interface": interface })</pre>
2814 </div>
2815 </div>
2816 <div class="paragraph">
2817 <p>Watch for property and interface changes on the given DBus object
2818 <code>path</code> DBus <code>path_namespace</code>. If <code>interface</code> is specified only
2819 properties on that DBus interface will be watched.</p>
2820 </div>
2821 <div class="paragraph">
2822 <p>The <a href="#cockpit-dbus-proxy"><code>client.proxy()</code></a> and
2823 <a href="#cockpit-dbus-proxies"><code>client.proxies()</code></a> functions and the
2824 objects they return are high level wrappers around <code>client.watch()</code>.</p>
2825 </div>
2826 <div class="paragraph">
2827 <p>The property and interface changes will be available in raw form on the
2828 <a href="#cockpit-dbus-onnotify"><code>client.onnotify</code></a> event.</p>
2829 </div>
2830 <div class="paragraph">
2831 <p>Property and interface changes that are caused by a method call or
2832 signal will show up before that method call reply is received, or signal
2833 event is triggered. It should be possible to rely on this guarantee,
2834 unless the DBus service in question behaves incorrectly. Internally
2835 these watches work well with code that implements the
2836 <a href="https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager">ObjectManager</a>
2837 portion of the DBus specification. If no ObjectManager implementation is
2838 available, the watch falls back to using DBus
2839 <a href="https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-introspectable">Introspection</a>
2840 along with the usual
2841 <a href="https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties">PropertiesChanged</a>
2842 signal. If the DBus service implements none of these, or implements them
2843 in an inconsistent manner, then this function will provide inconsistent
2844 or unexpected results.</p>
2845 </div>
2846 <div class="paragraph">
2847 <p>The parameter is either a DBus <code>path</code> or a plain javascript object
2848 with zero or more of the following fields. If an empty javascript object
2849 is used as an argument, then all paths, interfaces and properties will
2850 be watched.</p>
2851 </div>
2852 <div class="dlist">
2853 <dl>
2854 <dt class="hdlist1"><code>interface</code></dt>
2855 <dd>
2856 <p>Watch properties on this DBus interface.</p>
2857 </dd>
2858 <dt class="hdlist1"><code>path</code></dt>
2859 <dd>
2860 <p>Watch interfaces and properties at this DBus path. May not be used
2861 together with the <code>path_namespace</code> property.</p>
2862 </dd>
2863 <dt class="hdlist1"><code>path_namespace</code></dt>
2864 <dd>
2865 <p>Watch interfaces and properties under this DBus path. It should be a
2866 valid DBus object path, that is, it should have no trailing slash. If
2867 an ObjectManager implementation is available at this interface, then
2868 it is used. May not be used together with the <code>path</code> property.</p>
2869 </dd>
2870 </dl>
2871 </div>
2872 <div class="paragraph">
2873 <p>The returned value is a
2874 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
2875 that will complete successfully when the watch has populated its initial
2876 set of properties and interfaces, and these have been notified via
2877 <a href="#cockpit-dbus-onnotify"><code>client.onnotify</code></a>.</p>
2878 </div>
2879 <div class="paragraph">
2880 <p>A watch can be removed by calling the
2881 <a href="#cockpit-dbus-watch-remove"><code>watch.remove()</code></a> method on the
2882 returned value. If identical watches are added more than once, then they
2883 must also be removed the same number of times before the removal takes
2884 effect.</p>
2885 </div>
2886 </div>
2887 <div class="sect3">
2888 <h4 id="cockpit-dbus-watch-then">watch.then()</h4>
2889 <div class="literalblock">
2890 <div class="content">
2891 <pre>watch.then(() =&gt; { ... })</pre>
2892 </div>
2893 </div>
2894 <div class="paragraph">
2895 <p>This is a standard
2896 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
2897 method. It sets up a handler to be called when the watch has populated
2898 its initial properties and interfaces.</p>
2899 </div>
2900 </div>
2901 <div class="sect3">
2902 <h4 id="cockpit-dbus-watch-catch">watch.catch()</h4>
2903 <div class="literalblock">
2904 <div class="content">
2905 <pre>watch.catch(ex =&gt; { ... })</pre>
2906 </div>
2907 </div>
2908 <div class="paragraph">
2909 <p>This is a standard
2910 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
2911 method. It sets up a handler to be called if the watch fails to populate
2912 its initial properties and interfaces. Note that a watch will only fail
2913 if the DBus client closes or is somehow disconnected. It does not fail
2914 in the case of missing interfaces or properties.</p>
2915 </div>
2916 </div>
2917 <div class="sect3">
2918 <h4 id="cockpit-dbus-watch-remove">watch.remove()</h4>
2919 <div class="literalblock">
2920 <div class="content">
2921 <pre>watch.remove()</pre>
2922 </div>
2923 </div>
2924 <div class="paragraph">
2925 <p>Remove the watch. This may not have any immediate effect if other
2926 watches are in place. In particular, if identical watches are added more
2927 than once, then they must also be removed the same number of times
2928 before the removal takes effect.</p>
2929 </div>
2930 </div>
2931 <div class="sect3">
2932 <h4 id="cockpit-dbus-onnotify">client.onnotify</h4>
2933 <div class="literalblock">
2934 <div class="content">
2935 <pre>client.addEventListener("notify", data =&gt; { ... })</pre>
2936 </div>
2937 </div>
2938 <div class="paragraph">
2939 <p>An event triggered when <a href="#cockpit-dbus-watch">watched</a> properties or
2940 interfaces change.</p>
2941 </div>
2942 <div class="paragraph">
2943 <p>The <a href="#cockpit-dbus-proxy"><code>client.proxy()</code></a> and
2944 <a href="#cockpit-dbus-proxies"><code>client.proxies()</code></a> functions and the
2945 objects they return are high level wrappers around the <code>data</code> provided
2946 by this event.</p>
2947 </div>
2948 <div class="paragraph">
2949 <p>The <code>data</code> has the following form:</p>
2950 </div>
2951 <div class="literalblock">
2952 <div class="content">
2953 <pre>{
2954 "/path1": {
2955 "org.Interface1": {
2956 "Prop1": "value",
2957 "Prop2": 5
2958 },
2959 "org.Interface2": null
2960 }
2961 }</pre>
2962 </div>
2963 </div>
2964 <div class="paragraph">
2965 <p>Multiple paths may be present, each of which may have multiple
2966 interfaces, each of which may have multiple properties. The first time a
2967 given path and interface is emitted from this signal, it will have all
2968 its properties and interfaces. Thereafter only changes are noted. If an
2969 interface is set to <code>null</code>, then that interface has disappeared.</p>
2970 </div>
2971 </div>
2972 <div class="sect3">
2973 <h4 id="cockpit-dbus-notify">client.notify()</h4>
2974 <div class="literalblock">
2975 <div class="content">
2976 <pre>client.notify(data)</pre>
2977 </div>
2978 </div>
2979 <div class="paragraph">
2980 <p>Emits a synthetic <a href="#cockpit-dbus-onnotify"><code>notify</code></a> event. The
2981 <code>data</code> argument should follow the same layout as described for the
2982 <code>notify</code> event.</p>
2983 </div>
2984 </div>
2985 <div class="sect3">
2986 <h4 id="cockpit-dbus-onmeta">client.onmeta</h4>
2987 <div class="literalblock">
2988 <div class="content">
2989 <pre>client.onmeta = (ev, data) =&gt; { ... }</pre>
2990 </div>
2991 </div>
2992 <div class="paragraph">
2993 <p>An event triggered when the meta data about
2994 <a href="#cockpit-dbus-watch">watched</a> interfaces is loaded.</p>
2995 </div>
2996 <div class="paragraph">
2997 <p>The <a href="#cockpit-dbus-proxy"><code>client.proxy()</code></a> and
2998 <a href="#cockpit-dbus-proxies"><code>client.proxies()</code></a> functions and the
2999 objects they return are high level wrappers around the <code>data</code> provided
3000 by this event.</p>
3001 </div>
3002 <div class="paragraph">
3003 <p>The <code>data</code> has the following form:</p>
3004 </div>
3005 <div class="literalblock">
3006 <div class="content">
3007 <pre> {
3008 "org.Interface": {
3009 "methods": {
3010 "Method1": {
3011 "in": [ "s", "v" ],
3012 "out": [ "i" ]
3013 },
3014 "Method2": { }
3015 },
3016 "signals": {
3017 "Signal": {
3018 "in": [ "b", "s" ]
3019 }
3020 },
3021 "properties": {
3022 "Prop1": {
3023 "flags": "rw",
3024 "type": "s"
3025 },
3026 "Prop2": {
3027 "flags": "r",
3028 "type": "b"
3029 }
3030 }
3031 }
3032 }</pre>
3033 </div>
3034 </div>
3035 <div class="paragraph">
3036 <p>Multiple interfaces may be present, each of which may have methods and
3037 properties. This is emitted before the first
3038 <a href="#cockpit-dbus-proxy"><code>client.onnotify</code></a> event for the relevant
3039 interface.</p>
3040 </div>
3041 </div>
3042 <div class="sect3">
3043 <h4 id="cockpit-dbus-variant">cockpit.variant()</h4>
3044 <div class="literalblock">
3045 <div class="content">
3046 <pre>variant = cockpit.variant(type, value)</pre>
3047 </div>
3048 </div>
3049 <div class="paragraph">
3050 <p>A DBus variant is represented as a plain javascript object with a
3051 <code>"t"</code> property represesting the full DBus type of the variant, and a
3052 <code>"v"</code> property containing the variant value.</p>
3053 </div>
3054 <div class="paragraph">
3055 <p>This is a helper function for creating such a variant object.</p>
3056 </div>
3057 </div>
3058 </div>
3059 <div class="sect2">
3060 <h3 id="_cockpit_js_errors">cockpit.js: Errors</h3>
3061 <div class="paragraph">
3062 <p>cockpit.js: Errors</p>
3063 </div>
3064 <div class="paragraph">
3065 <p>Problem codes and messages</p>
3066 </div>
3067 <div class="sect3">
3068 <h4 id="cockpit-problems">Problem Codes</h4>
3069 <div class="paragraph">
3070 <p>Cockpit represents problems with standardized problem string codes.</p>
3071 </div>
3072 <div class="dlist">
3073 <dl>
3074 <dt class="hdlist1"><code>"access-denied"</code></dt>
3075 <dd>
3076 <p>The user is not permitted to perform the action in question.</p>
3077 </dd>
3078 <dt class="hdlist1"><code>"authentication-failed"</code></dt>
3079 <dd>
3080 <p>User authentication failed.</p>
3081 </dd>
3082 <dt class="hdlist1"><code>"internal-error"</code></dt>
3083 <dd>
3084 <p>An unexpected internal error without further info. This should not
3085 happen during the normal course of operations.</p>
3086 </dd>
3087 <dt class="hdlist1"><code>"no-cockpit"</code></dt>
3088 <dd>
3089 <p>The system does not have a compatible version of Cockpit installed or
3090 installed properly.</p>
3091 </dd>
3092 <dt class="hdlist1"><code>"no-session"</code></dt>
3093 <dd>
3094 <p>Cockpit is not logged in.</p>
3095 </dd>
3096 <dt class="hdlist1"><code>"not-found"</code></dt>
3097 <dd>
3098 <p>Something specifically requested was not found, such as a file,
3099 executable etc.</p>
3100 </dd>
3101 <dt class="hdlist1"><code>"terminated"</code></dt>
3102 <dd>
3103 <p>Something was terminated forcibly, such as a connection, process
3104 session, etc.</p>
3105 </dd>
3106 <dt class="hdlist1"><code>"timeout"</code></dt>
3107 <dd>
3108 <p>Something timed out.</p>
3109 </dd>
3110 <dt class="hdlist1"><code>"unknown-hostkey"</code></dt>
3111 <dd>
3112 <p>The remote host had an unexpected or unknown key.</p>
3113 </dd>
3114 <dt class="hdlist1"><code>"no-forwarding"</code></dt>
3115 <dd>
3116 <p>Could not forward authentication credentials to the remote host.</p>
3117 </dd>
3118 </dl>
3119 </div>
3120 </div>
3121 <div class="sect3">
3122 <h4 id="cockpit-messages">cockpit.message()</h4>
3123 <div class="literalblock">
3124 <div class="content">
3125 <pre>message = cockpit.message(problem)
3126 message = cockpit.message(exception)</pre>
3127 </div>
3128 </div>
3129 <div class="paragraph">
3130 <p>Return a message for the <code>exception</code> or <code>problem</code> code passed as an
3131 argument. If the argument is an object with a <code>"message"</code> property, as
3132 is the case with most exceptions, that will be returned directly. If the
3133 argument is an object with a <code>"problem"</code> property, then it will be
3134 used as the problem code. An appropriate message will be returned for
3135 problem codes.</p>
3136 </div>
3137 </div>
3138 </div>
3139 <div class="sect2">
3140 <h3 id="_cockpit_js_file_access">cockpit.js: File Access</h3>
3141 <div class="paragraph">
3142 <p>The <code>cockpit.file</code> API lets you read, write, and watch regular files
3143 in their entirety. It cannot efficiently do random access in a big file
3144 or read non-regular files such as <code>/dev/random</code>.</p>
3145 </div>
3146 <div class="literalblock">
3147 <div class="content">
3148 <pre>file = cockpit.file(path,
3149 { syntax: syntax_object,
3150 binary: boolean,
3151 max_read_size: int,
3152 superuser: string,
3153 })
3154
3155 promise = file.read()
3156 promise
3157 .then((content, tag) =&gt; { ... })
3158 .catch(error =&gt; { ... })
3159
3160 promise = file.replace(content, [ expected_tag ])
3161 promise
3162 .then(new_tag =&gt; { ... })
3163 .catch(error =&gt; { ... })
3164
3165 promise = file.modify(callback, [ initial_content, initial_tag ]
3166 promise
3167 .then((new_content, new_tag) =&gt; { ... })
3168 .catch(error =&gt; { ... })
3169
3170 file.watch((content, tag, [error]) =&gt; { }, [ { read: boolean } ])
3171
3172 file.close()</pre>
3173 </div>
3174 </div>
3175 <div class="sect3">
3176 <h4 id="cockpit-file-simple">Simple reading and writing</h4>
3177 <div class="paragraph">
3178 <p>You can read a file with code like this:</p>
3179 </div>
3180 <div class="literalblock">
3181 <div class="content">
3182 <pre>cockpit.file("/path/to/file").read()
3183 .then((content, tag) =&gt; {
3184 ...
3185 })
3186 .catch(error =&gt; {
3187 ...
3188 });</pre>
3189 </div>
3190 </div>
3191 <div class="paragraph">
3192 <p>It is recommended to use absolute paths. Relative paths are resolved
3193 against <code>/</code>. To work with the current user&#8217;s files
3194 <a href="#cockpit-user">cockpit.user()</a> can be used to get the user&#8217;s home
3195 directory.</p>
3196 </div>
3197 <div class="paragraph">
3198 <p>The <code>read()</code> method returns a
3199 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>.</p>
3200 </div>
3201 <div class="paragraph">
3202 <p>When successful, the promise will be resolved with the content of the
3203 file. Unless you specify options to change this (see below), the file is
3204 assumed to be text in the UTF-8 encoding, and <code>content</code> will be a
3205 string.</p>
3206 </div>
3207 <div class="paragraph">
3208 <p>The tag that is passed to the <code>then()</code> callback is a short string that
3209 is associated with the file and changes whenever the content of the file
3210 changes. It is meant to be used with <code>replace()</code>.</p>
3211 </div>
3212 <div class="paragraph">
3213 <p>It is not an error when the file does not exist. In this case, the
3214 <code>then()</code> callback will be called with a <code>null</code> value for <code>content</code>
3215 and <code>tag</code> is <code>"-"</code>.</p>
3216 </div>
3217 <div class="paragraph">
3218 <p>The <code>superuser</code> option can be used the same way as described in the
3219 <a href="#cockpit-channels-channel">cockpit.channel()</a> to provide a different
3220 access level to the file.</p>
3221 </div>
3222 <div class="paragraph">
3223 <p>You can use the <code>max_read_size</code> option to limit the amount of data
3224 that is read. If the file is larger than the given number of bytes, no
3225 data is read and the channel is closed with problem code <code>too-large</code>.
3226 The default limit is 16 MiB. The limit can be completely removed by
3227 setting it to -1.</p>
3228 </div>
3229 <div class="paragraph">
3230 <p>To write to a file, use code like this:</p>
3231 </div>
3232 <div class="literalblock">
3233 <div class="content">
3234 <pre>cockpit.file("/path/to/file").replace("my new content\n")
3235 .then(tag =&gt; {
3236 ...
3237 })
3238 .catch(error =&gt; {
3239 ...
3240 });</pre>
3241 </div>
3242 </div>
3243 <div class="paragraph">
3244 <p>The <code>replace()</code> method returns a
3245 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>.</p>
3246 </div>
3247 <div class="paragraph">
3248 <p>When the promise is resolved, the file has been atomically replaced (via
3249 the <code>rename()</code> syscall) with the new content. As with <code>read()</code>, by
3250 default the new content is a string and will be written to the file as
3251 UTF-8. The returned tag corresponds to the new content of the file.</p>
3252 </div>
3253 <div class="paragraph">
3254 <p>When the promise is rejected because of an error, the file or its meta
3255 data has not been changed in any way.</p>
3256 </div>
3257 <div class="paragraph">
3258 <p>As a special case, passing the value <code>null</code> to <code>replace()</code> will
3259 remove the file.</p>
3260 </div>
3261 <div class="paragraph">
3262 <p>The <code>replace()</code> method can also check for conflicting changes to a
3263 file. You can pass a tag (as returned by <code>read()</code> or <code>replace()</code>) to
3264 <code>replace()</code>, and the file will only be replaced if it still has the
3265 given tag. If the tag of the file has changed, <code>replace()</code> will fail
3266 with an error object that has <code>error.problem == "change-conflict"</code>.
3267 See <code>modify()</code> below for a convenient way to achieve transactional
3268 updates to a file.</p>
3269 </div>
3270 </div>
3271 <div class="sect3">
3272 <h4 id="cockpit-file-format">File format</h4>
3273 <div class="paragraph">
3274 <p>By default, a file is assumed to be text encoded in UTF-8, and the
3275 <code>read()</code> and <code>replace()</code> functions use strings to represent the
3276 content.</p>
3277 </div>
3278 <div class="paragraph">
3279 <p>By specifying the <code>syntax.parser()</code> and <code>syntax.stringify()</code>
3280 options, you can cause <code>read()</code> to parse the content before passing it
3281 back to you, and <code>replace()</code> to unparse it before writing.</p>
3282 </div>
3283 <div class="paragraph">
3284 <p>The main idea is to be able to write <code>{ syntax: JSON }</code>, of course,
3285 but you can easily pass in individual functions or make your own
3286 parser/unparser object:</p>
3287 </div>
3288 <div class="literalblock">
3289 <div class="content">
3290 <pre>cockpit.file("/path/to/file.json", { syntax: JSON })
3291
3292 var syntax_object = {
3293 parse: my_parser,
3294 stringify: my_unparser
3295 };
3296
3297 cockpit.file("/path/to/file", { syntax: syntax_object })</pre>
3298 </div>
3299 </div>
3300 <div class="paragraph">
3301 <p>Any exceptions thrown by the <code>parse()</code> and <code>stringify()</code> functions
3302 are caught and reported as read or write errors.</p>
3303 </div>
3304 <div class="paragraph">
3305 <p>The <code>null</code> value that is used to represent the content of a
3306 non-existing file (see "Simple reading and writing", above) is not
3307 passed through the <code>parse()</code> and <code>stringify()</code> functions.</p>
3308 </div>
3309 </div>
3310 <div class="sect3">
3311 <h4 id="cockpit-file-binary">Binary files</h4>
3312 <div class="paragraph">
3313 <p>By default the content of the file is assumed to be text encoded as
3314 UTF-8 and it can not contain zero bytes. The content is represented as a
3315 JavaScript string with <code>read()</code>, <code>replace()</code>, etc. By setting the
3316 <code>binary</code> option to true when creating the proxy, no assumptions are
3317 placed on the content, and it is represented as a <code>Uint8Array</code> in
3318 JavaScript.</p>
3319 </div>
3320 </div>
3321 <div class="sect3">
3322 <h4 id="cockpit-file-atomic">Atomic modifications</h4>
3323 <div class="paragraph">
3324 <p>Use <code>modify()</code> to modify the content of the file safely. A call to
3325 <code>modify()</code> will read the content of the file, call <code>callback</code> on the
3326 content, and then replace the content of the file with the return value
3327 of the callback.</p>
3328 </div>
3329 <div class="paragraph">
3330 <p>The <code>modify()</code> method uses the <code>read()</code> and <code>replace()</code> methods
3331 internally in the obvious way. Thus, the <code>syntax.parse()</code> and
3332 <code>syntax.stringify()</code> options work as expected, <code>null</code> represents a
3333 non-existing file, and the watch callbacks are fired.</p>
3334 </div>
3335 <div class="paragraph">
3336 <p>It will do this one or more times, until no other conflicting changes
3337 have been made to the file between reading and replacing it.</p>
3338 </div>
3339 <div class="paragraph">
3340 <p>The callback is called like this</p>
3341 </div>
3342 <div class="literalblock">
3343 <div class="content">
3344 <pre>new_content = callback (old_content)</pre>
3345 </div>
3346 </div>
3347 <div class="paragraph">
3348 <p>The callback is allowed to mutate <code>old_content</code>, but note that this
3349 will also mutate the objects that are passed to the watch callbacks.
3350 Returning <code>undefined</code> from the proxy is the same as returning
3351 <code>old_content</code>.</p>
3352 </div>
3353 <div class="paragraph">
3354 <p>The <code>modify()</code> method returns a
3355 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>.</p>
3356 </div>
3357 <div class="paragraph">
3358 <p>The promise will be resolved with the new content and its tag, like so</p>
3359 </div>
3360 <div class="literalblock">
3361 <div class="content">
3362 <pre>function shout(old_content) {
3363 return old_content.toUpperCase();
3364 }
3365
3366 cockpit.file("/path/to/file").modify(shout)
3367 .then((content, tag) =&gt; {
3368 ...
3369 })
3370 .catch(error =&gt; {
3371 ...
3372 });</pre>
3373 </div>
3374 </div>
3375 <div class="paragraph">
3376 <p>If you have cached the last content and tag results of the <code>read()</code> or
3377 <code>modify()</code> method, or the last values passed to a watch callback, you
3378 can pass them to <code>modify()</code> as the second and third argument. In this
3379 case, <code>modify()</code> will skip the initial read and start with the given
3380 values.</p>
3381 </div>
3382 </div>
3383 <div class="sect3">
3384 <h4 id="cockpit-file-notify">Change notifications</h4>
3385 <div class="paragraph">
3386 <p>Calling <code>watch()</code> will start monitoring the file for external changes.</p>
3387 </div>
3388 <div class="literalblock">
3389 <div class="content">
3390 <pre>handle = file.watch(callback);
3391
3392 handle_no_read = file.watch(callback, { read: false });</pre>
3393 </div>
3394 </div>
3395 <div class="paragraph">
3396 <p>Whenever a change occurs, the <code>callback()</code> is called with the new
3397 content and tag of the file. This might happen because of external
3398 changes, but also as part of calls to <code>read()</code>, <code>replace()</code>, and
3399 <code>modify()</code>.</p>
3400 </div>
3401 <div class="paragraph">
3402 <p>When a read error occurs, the <code>callback()</code> is called with an error as
3403 a third argument. Write errors are not reported via the watch callback.</p>
3404 </div>
3405 <div class="paragraph">
3406 <p>Calling <code>watch()</code> will also automatically call <code>read()</code> to get the
3407 initial content of the file. Thus, you normally don&#8217;t need to call
3408 <code>read()</code> at all when using <code>watch()</code>.</p>
3409 </div>
3410 <div class="paragraph">
3411 <p>To disable the automatic reading, e.g. for large files or unreadable
3412 file system objects, set the <code>read</code> option to <code>false</code>. The first
3413 <code>content</code> argument of the callback will then always be <code>null</code>.</p>
3414 </div>
3415 <div class="paragraph">
3416 <p>To free the resources used for monitoring, call <code>handle.remove()</code>.</p>
3417 </div>
3418 </div>
3419 <div class="sect3">
3420 <h4 id="cockpit-file-path">file.path</h4>
3421 <div class="paragraph">
3422 <p>A string containing the path that was passed to the <code>cockpit.file()</code>
3423 method.</p>
3424 </div>
3425 </div>
3426 <div class="sect3">
3427 <h4 id="cockpit-file-close">Closing</h4>
3428 <div class="paragraph">
3429 <p>Call the <code>close()</code> method on a file proxy to cancel all ongoing
3430 operations, such as reading, writing, and monitoring. The proxy should
3431 not be used after closing it.</p>
3432 </div>
3433 </div>
3434 </div>
3435 <div class="sect2">
3436 <h3 id="_cockpit_js_http_client">cockpit.js: HTTP Client</h3>
3437 <div class="paragraph">
3438 <p>Cockpit allows access to local HTTP and REST services via this API.</p>
3439 </div>
3440 <div class="sect3">
3441 <h4 id="cockpit-http-constructor">cockpit.http()</h4>
3442 <div class="literalblock">
3443 <div class="content">
3444 <pre>http = cockpit.http(endpoint, [options])
3445 http = cockpit.http(options)</pre>
3446 </div>
3447 </div>
3448 <div class="paragraph">
3449 <p>Create a new HTTP client. The <code>endpoint</code> can be a file path starting
3450 with <code>/</code> to connect to a unix socket, or it can be a port number to
3451 connect to. The optional <code>options</code> argument is a javascript plain
3452 object, and may include:</p>
3453 </div>
3454 <div class="dlist">
3455 <dl>
3456 <dt class="hdlist1"><code>"address"</code></dt>
3457 <dd>
3458 <p>Connect to an address other than localhost. Must be a valid host name
3459 or IP address. To use this option you also must provide a port number.</p>
3460 </dd>
3461 <dt class="hdlist1"><code>"port"</code></dt>
3462 <dd>
3463 <p>Port number to use with "address" option, when not given in
3464 <code>endpoint</code>.</p>
3465 </dd>
3466 <dt class="hdlist1"><code>"tls"</code></dt>
3467 <dd>
3468 <p>Object properties for an https connection. See
3469 <code>http-stream2 TLS options</code>.</p>
3470 </dd>
3471 <dt class="hdlist1"><code>"headers"</code></dt>
3472 <dd>
3473 <p>Additional HTTP headers to include with the HTTP request. This is a
3474 plain javascript object with each key as a header name, and each value
3475 as the header value.</p>
3476 </dd>
3477 <dt class="hdlist1"><code>"superuser"</code></dt>
3478 <dd>
3479 <p>Set to <code>"require"</code> to open this channel as root. If the currently
3480 logged in user is not permitted to become root (eg: via <code>pkexec</code>)
3481 then the <code>channel</code> will immediately be
3482 <a href="#cockpit-channels-close-ev">closed</a> with a <code>"access-denied"</code>
3483 problem code.
3484 +
3485 Set to <code>"try"</code> to try to make the request as root, but if that
3486 fails, fall back to perform an unprivileged request.</p>
3487 </dd>
3488 <dt class="hdlist1"><code>"tls"</code></dt>
3489 <dd>
3490 <p>If set to a plain javascript object, then the connection will be an
3491 HTTPS connection and include TLS encryption. The fields of the <code>tls</code>
3492 object declare various TLS configuration and data. All fields are
3493 optional:
3494 +</p>
3495 <div class="ulist">
3496 <ul>
3497 <li>
3498 <p><code>"authority"</code>: Certificate authority(s) to expect as signers of
3499 the server&#8217;s TLS certificate, represented as a plain javascript
3500 object. It should have either a <code>"file"</code> field containing a readable
3501 PEM file on the system containing authorities, or a <code>"data"</code> with
3502 PEM encoded certificate data.</p>
3503 </li>
3504 <li>
3505 <p><code>"certificate"</code>: A client certificate to use, represented as a
3506 plain javascript object. It should have either a <code>"file"</code> field
3507 containing a readable PEM file on the system to use as a certificate,
3508 or a <code>"data"</code> with PEM encoded certificate data.</p>
3509 </li>
3510 <li>
3511 <p><code>"key"</code>: A client key to use, represented as a plain javascript
3512 object. It should have either a <code>"file"</code> field containing a readable
3513 PEM file on the system to use as a key, or a <code>"data"</code> with PEM
3514 encoded key data.</p>
3515 </li>
3516 <li>
3517 <p><code>"validate"</code>: A boolean that describes whether to validate the
3518 server&#8217;s TLS certificate or not. By default local connections are not
3519 validated, and remote connections are validated.</p>
3520 </li>
3521 </ul>
3522 </div>
3523 </dd>
3524 </dl>
3525 </div>
3526 <div class="paragraph">
3527 <p>Here is a somewhat complex example of using most of the above
3528 <code>options</code> when when calling <code>cockpit.http()</code>:</p>
3529 </div>
3530 <div class="literalblock">
3531 <div class="content">
3532 <pre>http = cockpit.http({
3533 "address": "localhost",
3534 "headers": {
3535 "Authorization": "Basic dXNlcjpwYXNzd29yZA=="
3536 },
3537 "port": 443,
3538 "tls": {
3539 "validate": true,
3540 "authority": {
3541 "file": "/etc/pki/tls/certs/ca-bundle.crt",
3542 },
3543 "certificate": {
3544 "data": "-----BEGIN CERTIFICATE-----\nMIIDsDCCA..."
3545 },
3546 "key": {
3547 "data": "-----BEGIN RSA PRIVATE KEY-----\nMIIEogIBA..."
3548 }
3549 }
3550 });</pre>
3551 </div>
3552 </div>
3553 </div>
3554 <div class="sect3">
3555 <h4 id="cockpit-http-get">http.get()</h4>
3556 <div class="literalblock">
3557 <div class="content">
3558 <pre>request = http.get(path, [params, [headers]])</pre>
3559 </div>
3560 </div>
3561 <div class="paragraph">
3562 <p>Perform an HTTP GET request for the given <code>path</code>. If the <code>params</code> is
3563 specified it should be a plain javascript object, which will be turned
3564 into a query string.</p>
3565 </div>
3566 <div class="paragraph">
3567 <p>Optionally a plain javascript object containing headers can be included
3568 in the <code>headers</code> argument.</p>
3569 </div>
3570 <div class="paragraph">
3571 <p>The return value is a
3572 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
3573 that will complete if the request happens successfully, or fail if
3574 there&#8217;s a problem.</p>
3575 </div>
3576 </div>
3577 <div class="sect3">
3578 <h4 id="cockpit-http-post">http.post()</h4>
3579 <div class="literalblock">
3580 <div class="content">
3581 <pre>request = http.post(path, body, [headers])</pre>
3582 </div>
3583 </div>
3584 <div class="paragraph">
3585 <p>Perform an HTTP POST request for the given <code>path</code>. The <code>body</code> can be
3586 a string, or a javascript plain object, which will be encoded as JSON
3587 data. If <code>body</code> is <code>undefined</code> or <code>null</code> then an empty HTTP body
3588 will be sent.</p>
3589 </div>
3590 <div class="paragraph">
3591 <p>Optionally a plain javascript object containing headers can be included
3592 in the <code>headers</code> argument.</p>
3593 </div>
3594 <div class="paragraph">
3595 <p>The return value is a
3596 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
3597 that will complete if the request happens successfully, or fail if
3598 there&#8217;s a problem.</p>
3599 </div>
3600 </div>
3601 <div class="sect3">
3602 <h4 id="cockpit-http-request">http.request()</h4>
3603 <div class="literalblock">
3604 <div class="content">
3605 <pre>request = http.request(options)</pre>
3606 </div>
3607 </div>
3608 <div class="paragraph">
3609 <p>Perform an HTTP request. The <code>options</code> can contain the following:</p>
3610 </div>
3611 <div class="dlist">
3612 <dl>
3613 <dt class="hdlist1"><code>"body"</code></dt>
3614 <dd>
3615 <p>The HTTP request body. If you do not specify a body, then you must
3616 call <a href="#cockpit-http-input">request.input()</a> to complete the body
3617 and allow the request to start.</p>
3618 </dd>
3619 <dt class="hdlist1"><code>"headers"</code></dt>
3620 <dd>
3621 <p>A javascript plain object containing HTTP headers.</p>
3622 </dd>
3623 <dt class="hdlist1"><code>"method"</code></dt>
3624 <dd>
3625 <p>The HTTP method. Defaults to <code>"GET"</code>.</p>
3626 </dd>
3627 <dt class="hdlist1"><code>"params"</code></dt>
3628 <dd>
3629 <p>A javascript plain object containing query string parameters.</p>
3630 </dd>
3631 <dt class="hdlist1"><code>"path"</code></dt>
3632 <dd>
3633 <p>The HTTP path. Defaults to <code>/</code>.</p>
3634 </dd>
3635 </dl>
3636 </div>
3637 <div class="paragraph">
3638 <p>The return value is a
3639 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
3640 that will complete if the request happens successfully, or fail if
3641 there&#8217;s a problem.</p>
3642 </div>
3643 </div>
3644 <div class="sect3">
3645 <h4 id="cockpit-http-then">request.then()</h4>
3646 <div class="literalblock">
3647 <div class="content">
3648 <pre>request.then(data =&gt; { ... })</pre>
3649 </div>
3650 </div>
3651 <div class="paragraph">
3652 <p>This is a standard
3653 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
3654 method. It sets up a handler to be called when the request finishes
3655 successfully.</p>
3656 </div>
3657 <div class="paragraph">
3658 <p>The <code>data</code> argument contains the body result of the request. If it a
3659 string, unless the process was opened in binary mode, in which case the
3660 <code>data</code> is an array of bytes. If a <code>request.stream()</code> handler is set
3661 up, then any standard output data consumed by the handler will not be
3662 included in the <code>data</code> argument.</p>
3663 </div>
3664 </div>
3665 <div class="sect3">
3666 <h4 id="cockpit-http-catch">request.catch()</h4>
3667 <div class="literalblock">
3668 <div class="content">
3669 <pre>request.catch((exception[, data]) =&gt; { ... })</pre>
3670 </div>
3671 </div>
3672 <div class="paragraph">
3673 <p>This is a standard
3674 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
3675 method. It sets up a handler to be called when the request fails, or
3676 returns an error code.</p>
3677 </div>
3678 <div class="paragraph">
3679 <p>The <code>exception</code> object passed to the handler can have the following
3680 fields:</p>
3681 </div>
3682 <div class="dlist">
3683 <dl>
3684 <dt class="hdlist1"><code>problem</code></dt>
3685 <dd>
3686 <p>A <a href="#cockpit-problems">problem code</a> string when a problem occurred
3687 starting or communicating with the server. This is <code>null</code> if the
3688 process exited or was terminated.</p>
3689 </dd>
3690 <dt class="hdlist1"><code>status</code></dt>
3691 <dd>
3692 <p>The numeric status of the response. This is <code>null</code> if no response
3693 was received.</p>
3694 </dd>
3695 <dt class="hdlist1"><code>reason</code></dt>
3696 <dd>
3697 <p>A string reason returned in the response. This is <code>null</code> if no
3698 response was received.</p>
3699 </dd>
3700 <dt class="hdlist1"><code>message</code></dt>
3701 <dd>
3702 <p>A string message returned in the response. This is <code>null</code> if no
3703 response was received.</p>
3704 </dd>
3705 </dl>
3706 </div>
3707 <div class="paragraph">
3708 <p>If the request returned a response body, it will be available in the
3709 <code>data</code> argument. Otherwise this argument will be <code>undefined</code>.</p>
3710 </div>
3711 </div>
3712 <div class="sect3">
3713 <h4 id="cockpit-http-response">request.response()</h4>
3714 <div class="literalblock">
3715 <div class="content">
3716 <pre>request.response((status, headers) =&gt; { ... })</pre>
3717 </div>
3718 </div>
3719 <div class="paragraph">
3720 <p>This sets up a handler to be called when the HTTP request gets the
3721 initial response from the server. The <code>status</code> argument is the HTTP
3722 status integer, and the <code>headers</code> is a plain javascript object
3723 containing the headers of the response.</p>
3724 </div>
3725 </div>
3726 <div class="sect3">
3727 <h4 id="cockpit-http-stream">request.stream()</h4>
3728 <div class="literalblock">
3729 <div class="content">
3730 <pre>request.stream(data =&gt; { ... })</pre>
3731 </div>
3732 </div>
3733 <div class="paragraph">
3734 <p>This sets up a handler to be called when the request returns output
3735 data. The handler will be called multiple times.</p>
3736 </div>
3737 <div class="paragraph">
3738 <p>Only one handler may be registered at a time. Registering an additional
3739 handler replaces the previous one. The handler receives either string
3740 <code>data</code> or an array of binary bytes as its argument. A stream handler
3741 may return a number, which indicates the number of characters or bytes
3742 consumed from <code>data</code>. Any data not consumed will be included again the
3743 next time the handler is called.</p>
3744 </div>
3745 <div class="paragraph">
3746 <p>If a <code>request.stream()</code> handler is set up, then the <code>request.then()</code>
3747 handlers will only get any remaining data not consumed by the stream
3748 handler.</p>
3749 </div>
3750 </div>
3751 <div class="sect3">
3752 <h4 id="cockpit-http-input">request.input()</h4>
3753 <div class="literalblock">
3754 <div class="content">
3755 <pre>request.input(data, [stream])</pre>
3756 </div>
3757 </div>
3758 <div class="paragraph">
3759 <p>This method writes <code>data</code> to the HTTP request body. It is only valid
3760 if no <code>"body"</code> has been specified in
3761 <a href="#cockpit-http-request">http.request()</a> options. If <code>stream</code> is
3762 <code>true</code> then this function can be called again to provide further data.</p>
3763 </div>
3764 </div>
3765 <div class="sect3">
3766 <h4 id="cockpit-http-close">request.close()</h4>
3767 <div class="literalblock">
3768 <div class="content">
3769 <pre>request.close([problem])</pre>
3770 </div>
3771 </div>
3772 <div class="paragraph">
3773 <p>Cancel the request. If <code>problem</code> is specified it should be a standard
3774 <a href="#cockpit-problems">problem code</a> string.</p>
3775 </div>
3776 </div>
3777 <div class="sect3">
3778 <h4 id="cockpit-http-close-all">http.close()</h4>
3779 <div class="literalblock">
3780 <div class="content">
3781 <pre>http.close([problem])</pre>
3782 </div>
3783 </div>
3784 <div class="paragraph">
3785 <p>Cancel all outstanding requests with the given problem code. This is
3786 useful when you know that the server is going down soon.</p>
3787 </div>
3788 </div>
3789 </div>
3790 <div class="sect2">
3791 <h3 id="_cockpit_js_localization">cockpit.js: Localization</h3>
3792 <div class="paragraph">
3793 <p>Cockpit provides a <a href="https://www.gnu.org/software/gettext/"><code>gettext()</code></a>
3794 like API for easy translation of strings.</p>
3795 </div>
3796 <div class="sect3">
3797 <h4 id="cockpit-locale-language">cockpit.language</h4>
3798 <div class="paragraph">
3799 <p>The current locale language code. This is set based on the
3800 <a href="#cockpit-locale-locale"><code>cockpit.locale()</code></a> data loaded.</p>
3801 </div>
3802 </div>
3803 <div class="sect3">
3804 <h4 id="cockpit-locale-locale">cockpit.locale()</h4>
3805 <div class="literalblock">
3806 <div class="content">
3807 <pre>cockpit.locale(po)</pre>
3808 </div>
3809 </div>
3810 <div class="paragraph">
3811 <p>Load locale information for a given <code>po</code> data. The data should be JSON
3812 data in the <a href="https://www.npmjs.org/package/po2json">po2json</a> format. The
3813 data will be loaded globally. If <code>po</code> data has already been loaded,
3814 then this will extend that loaded data with additional strings. Any
3815 identical translations strings will be replaced with the new strings. A
3816 <code>null</code> argument clears all the locale information previously loaded.</p>
3817 </div>
3818 <div class="paragraph">
3819 <p>Various methods such as
3820 <a href="#cockpit-locale-gettext"><code>cockpit.gettext()</code></a> make use of the
3821 loaded data.</p>
3822 </div>
3823 </div>
3824 <div class="sect3">
3825 <h4 id="cockpit-locale-gettext">cockpit.gettext()</h4>
3826 <div class="literalblock">
3827 <div class="content">
3828 <pre>translated = cockpit.gettext([context], string)
3829 var _ = cockpit.gettext
3830 var C_ = cockpit.gettext
3831 translated = _("string")
3832 translated = C_("context", "string")</pre>
3833 </div>
3834 </div>
3835 <div class="paragraph">
3836 <p>Lookup <code>string</code> for translation in the loaded locale data. The
3837 translated string will be returned, or <code>string</code> will be returned if no
3838 such translated string is present. The <code>context</code> argument is an
3839 optional string used to qualify the string.</p>
3840 </div>
3841 <div class="paragraph">
3842 <p>This function can be assigned to a variable called <code>_</code> (underscore)
3843 which will make your code work with the typical <code>_("string")</code> syntax.</p>
3844 </div>
3845 </div>
3846 <div class="sect3">
3847 <h4 id="cockpit-locale-noop">cockpit.noop()</h4>
3848 <div class="literalblock">
3849 <div class="content">
3850 <pre>var N_ = cockpit.noop
3851 var NC_ = cockpit.noop</pre>
3852 </div>
3853 </div>
3854 <div class="paragraph">
3855 <p>A noop function suitable for assigning to <code>N_</code> or <code>NC_</code> so that
3856 gettext scanners will be able to find translatable strings. More
3857 specifically this function returns its last argument.</p>
3858 </div>
3859 </div>
3860 <div class="sect3">
3861 <h4 id="cockpit-locale-ngettext">cockpit.ngettext()</h4>
3862 <div class="literalblock">
3863 <div class="content">
3864 <pre>translated = cockpit.ngettext([context], string1, stringN, number)</pre>
3865 </div>
3866 </div>
3867 <div class="paragraph">
3868 <p>Lookup a string appropriate for a pluralization form of the <code>number</code>.
3869 Various languages have complex pluralization forms that go far between
3870 the singular and plural forms speakers of English are familiar with. If
3871 no such translated string is found then either one of <code>string1</code> or
3872 <code>stringN</code> is returned according to simple pluralization rules.</p>
3873 </div>
3874 <div class="paragraph">
3875 <p>The <code>context</code> argument is an optional string used to qualify the
3876 string.</p>
3877 </div>
3878 </div>
3879 <div class="sect3">
3880 <h4 id="cockpit-locale-translate">cockpit.translate()</h4>
3881 <div class="literalblock">
3882 <div class="content">
3883 <pre>cockpit.translate()
3884 cockpit.translate(element, ...)
3885 cockpit.translate(selection)</pre>
3886 </div>
3887 </div>
3888 <div class="paragraph">
3889 <p>The document will be scanned for <code>translate</code> tags and they will be
3890 translated according to the strings in loaded locale data. One or more
3891 <code>element</code> arguments may be specified. These are DOM elements for
3892 specific parts of the document to be translated. If no <code>element</code> is
3893 specified then the entire document is translated.</p>
3894 </div>
3895 <div class="paragraph">
3896 <p>If an array or array-like object is passed as a <code>selection</code> then all
3897 DOM elements in the array will be treated as parts of the document to be
3898 translated.</p>
3899 </div>
3900 </div>
3901 </div>
3902 <div class="sect2">
3903 <h3 id="_cockpit_js_page_location_and_jumping">cockpit.js: Page Location and Jumping</h3>
3904 <div class="paragraph">
3905 <p>Page location and navigation between components</p>
3906 </div>
3907 <div class="sect3">
3908 <h4 id="cockpit-location-general">Page location</h4>
3909 <div class="literalblock">
3910 <div class="content">
3911 <pre>location = cockpit.location
3912 cockpit.location = "/path"</pre>
3913 </div>
3914 </div>
3915 <div class="paragraph">
3916 <p>Cockpit components often have different views, without changing the HTML
3917 file that is being viewed. These are known as pages.
3918 <code>cockpit.location</code> is an object that can be used to read the current
3919 page and to navigate to a different page location. It works by updating
3920 <code>window.location.hash</code>.</p>
3921 </div>
3922 <div class="paragraph">
3923 <p>The <code>cockpit.location</code> looks like a HTTP path with a possible query
3924 string:</p>
3925 </div>
3926 <div class="literalblock">
3927 <div class="content">
3928 <pre>/path/sub/page?option=value,option2</pre>
3929 </div>
3930 </div>
3931 <div class="paragraph">
3932 <p>The <a href="#cockpit-location-path"><code>location.path</code></a> and
3933 <a href="#cockpit-location-options"><code>location.options</code></a> contain a parsed
3934 form of the location. While the location cannot be modified in place, a
3935 new one can be created by assigning a string to <code>cockpit.location</code> or
3936 by calling the <a href="#cockpit-location-go"><code>location.go()</code></a> function.</p>
3937 </div>
3938 <div class="paragraph">
3939 <p><code>cockpit.location</code> is designed similarly to <code>window.location</code> in
3940 that the location object is preplaced whenever the current page location
3941 changes. To be aware of when the page location changes listen for the
3942 <a href="#cockpit-location-changed"><code>cockpit.onlocationchanged</code></a> event.</p>
3943 </div>
3944 <div class="paragraph">
3945 <p>Using the location object as a string will result in the
3946 <a href="#cockpit-location-href"><code>location.href</code></a>.</p>
3947 </div>
3948 <div class="sect4">
3949 <h5 id="cockpit-location-href">location.href</h5>
3950 <div class="paragraph">
3951 <p>The string representation of this page location, including any options.</p>
3952 </div>
3953 </div>
3954 <div class="sect4">
3955 <h5 id="cockpit-location-path">location.path</h5>
3956 <div class="paragraph">
3957 <p>An array of path segments, parsed and decoded appropriately. An empty
3958 array denotes the root path.</p>
3959 </div>
3960 </div>
3961 <div class="sect4">
3962 <h5 id="cockpit-location-options">location.options</h5>
3963 <div class="paragraph">
3964 <p>A javascript object containing the various options present in the
3965 location.</p>
3966 </div>
3967 <div class="paragraph">
3968 <p>If an option appears more than once, its value will be an array.</p>
3969 </div>
3970 </div>
3971 <div class="sect4">
3972 <h5 id="cockpit-location-go">location.go()</h5>
3973 <div class="literalblock">
3974 <div class="content">
3975 <pre>location.go(path, [options])</pre>
3976 </div>
3977 </div>
3978 <div class="paragraph">
3979 <p>Changes the current location to the given <code>path</code> and <code>options</code>. If
3980 the <code>path</code> argument is a string, it will be parsed into a path. If it
3981 is a relative path, then the result will be relative to the current
3982 <code>location.path</code>. If the <code>path</code> argument is an array of path
3983 segments, it will be treated as a full parsed absolute path.</p>
3984 </div>
3985 <div class="paragraph">
3986 <p>Any options found in a <code>path</code> will be added to those in the optional
3987 <code>options</code> argument, and used in the result.</p>
3988 </div>
3989 <div class="paragraph">
3990 <p>The location change will only take effect if the location has not
3991 changed in the meantime. This can be to good effect by saving a
3992 <code>cockpit.location</code> object and doing a conditional navigation, by
3993 calling the saved <code>location.go()</code> method later. This will only
3994 navigate if the user or other code has not navigated in the meantime.</p>
3995 </div>
3996 </div>
3997 <div class="sect4">
3998 <h5 id="cockpit-location-replace">location.replace()</h5>
3999 <div class="literalblock">
4000 <div class="content">
4001 <pre>location.replace(path, [options])</pre>
4002 </div>
4003 </div>
4004 <div class="paragraph">
4005 <p>Similar to <a href="#cockpit-location-go"><code>location.go()</code></a> except the
4006 location change will not result in a navigation change in the browser&#8217;s
4007 history.</p>
4008 </div>
4009 </div>
4010 <div class="sect4">
4011 <h5 id="cockpit-location-decode">location.decode()</h5>
4012 <div class="literalblock">
4013 <div class="content">
4014 <pre>path = location.decode(href, [options])</pre>
4015 </div>
4016 </div>
4017 <div class="paragraph">
4018 <p>Decode a cockpit href into its <code>path</code> array. If the <code>options</code>
4019 argument is specified, then it will be populated with options found in
4020 the href.</p>
4021 </div>
4022 <div class="paragraph">
4023 <p>If href is a relative path it will be resolved relative to
4024 <code>location.href</code>.</p>
4025 </div>
4026 </div>
4027 <div class="sect4">
4028 <h5 id="cockpit-location-encode">location.encode()</h5>
4029 <div class="literalblock">
4030 <div class="content">
4031 <pre>href = location.encode(path, [options])</pre>
4032 </div>
4033 </div>
4034 <div class="paragraph">
4035 <p>Encode the given <code>path</code> and <code>options</code> into a cockpit href. The
4036 <code>path</code> argument may be an array of path segments, or a string path. If
4037 a relative path is passed, it will be resolved relative to
4038 <code>location.href</code>.</p>
4039 </div>
4040 </div>
4041 <div class="sect4">
4042 <h5 id="cockpit-location-changed">cockpit.onlocationchanged</h5>
4043 <div class="literalblock">
4044 <div class="content">
4045 <pre>cockpit.addEventListener("locationchanged", function() { ... })</pre>
4046 </div>
4047 </div>
4048 <div class="paragraph">
4049 <p>An event emitted when over the <code>cockpit.location</code> changes. Typically a
4050 component reacts to this event by updating its interface to reflect the
4051 new <a href="#cockpit-location-path"><code>cockpit.location.path</code></a> and
4052 <a href="#cockpit-location-options"><code>cockpit.location.options</code></a>.</p>
4053 </div>
4054 <div class="paragraph">
4055 <p>This event is not triggered immediately during a <code>location.go()</code> or
4056 similar call. It will be triggered asynchronously at a later time.</p>
4057 </div>
4058 </div>
4059 </div>
4060 <div class="sect3">
4061 <h4 id="cockpit-jump">Jumping between components</h4>
4062 <div class="literalblock">
4063 <div class="content">
4064 <pre>cockpit.jump("/system/log")</pre>
4065 </div>
4066 </div>
4067 <div class="paragraph">
4068 <p>In Cockpit in there multiple components shown. In order to tell Cockpit
4069 to jump to and show another component and a certain location within that
4070 component, use the <code>cockpit.jump()</code> function. Stable component paths
4071 are documented. Don&#8217;t assume you can navigate into paths that are not
4072 stable API.</p>
4073 </div>
4074 <div class="sect4">
4075 <h5 id="cockpit-jump-jump">cockpit.jump()</h5>
4076 <div class="literalblock">
4077 <div class="content">
4078 <pre>cockpit.jump(path, [ host ])</pre>
4079 </div>
4080 </div>
4081 <div class="paragraph">
4082 <p>Ask Cockpit to jump to another component. The location of the current
4083 component will not be affected. The <code>path</code> argument can be a string
4084 path, starting with <code>/</code> or an array containing the parts of a path
4085 that will be joined to create a path. If <code>host</code> is not specified, then
4086 the component on the same host as the caller will be displayed. If host
4087 is null, then the host portion of the path will be removed, displaying
4088 the component on the host that cockpit is connected directly to.</p>
4089 </div>
4090 <div class="paragraph">
4091 <p>If the calling component is not running within Cockpit, or the calling
4092 component is not currently displayed, then the jump will not happen, and
4093 this function has no effect.</p>
4094 </div>
4095 </div>
4096 <div class="sect4">
4097 <h5 id="cockpit-jump-hidden">cockpit.hidden</h5>
4098 <div class="paragraph">
4099 <p>A boolean property that indicates if the current component page is
4100 visible or hidden. When the code or user jumps to another component, the
4101 prior one remains loaded and initialized but is hidden. Use this
4102 property together with the
4103 <a href="#cockpit-jump-visibilitychange"><code>cockpit.onvisibilitychange</code></a>
4104 event to decide whether or not to perform expensive tasks to update the
4105 interface.</p>
4106 </div>
4107 <div class="paragraph">
4108 <p>This property is analogous to the <code>document.hidden</code> page visibility
4109 API, but works with the document and frame implementation of Cockpit.</p>
4110 </div>
4111 </div>
4112 <div class="sect4">
4113 <h5 id="cockpit-jump-visibilitychange">cockpit.onvisibilitychange</h5>
4114 <div class="literalblock">
4115 <div class="content">
4116 <pre>cockpit.onvisibilitychange = function() { ... }</pre>
4117 </div>
4118 </div>
4119 <div class="paragraph">
4120 <p>This event is emitted when the
4121 <a href="#cockpit-jump-hidden"><code>cockpit.hidden</code></a> property changes. This
4122 event is similar to the <code>document.onvisibilitychange</code> API, but works
4123 with the document and frame implementation of Cockpit.</p>
4124 </div>
4125 </div>
4126 </div>
4127 </div>
4128 <div class="sect2">
4129 <h3 id="_cockpit_js_user_session">cockpit.js: User Session</h3>
4130 <div class="paragraph">
4131 <p>User information and login session state</p>
4132 </div>
4133 <div class="sect3">
4134 <h4 id="cockpit-logout">cockpit.logout()</h4>
4135 <div class="literalblock">
4136 <div class="content">
4137 <pre>cockpit.logout([reload])</pre>
4138 </div>
4139 </div>
4140 <div class="paragraph">
4141 <p>Logout of Cockpit. Unless <code>reload</code> is <code>false</code> this will also cause
4142 the page to be reloaded, so that the user can see the logged out state.</p>
4143 </div>
4144 </div>
4145 <div class="sect3">
4146 <h4 id="cockpit-user">cockpit.user()</h4>
4147 <div class="literalblock">
4148 <div class="content">
4149 <pre>var promise = cockpit.user();
4150 promise.then(user =&gt; { ... });</pre>
4151 </div>
4152 </div>
4153 <div class="paragraph">
4154 <p>This object contains information about the user that&#8217;s currently logged
4155 into cockpit. The following fields are defined:</p>
4156 </div>
4157 <div class="dlist">
4158 <dl>
4159 <dt class="hdlist1"><code>"id"</code></dt>
4160 <dd>
4161 <p>This is unix user id.</p>
4162 </dd>
4163 <dt class="hdlist1"><code>"gid"</code></dt>
4164 <dd>
4165 <p>This is unix user group id.</p>
4166 </dd>
4167 <dt class="hdlist1"><code>"name"</code></dt>
4168 <dd>
4169 <p>This is the unix user name like <code>"root"</code>.</p>
4170 </dd>
4171 <dt class="hdlist1"><code>"full_name"</code></dt>
4172 <dd>
4173 <p>This is a readable name for the user.</p>
4174 </dd>
4175 <dt class="hdlist1"><code>"groups"</code></dt>
4176 <dd>
4177 <p>This is an array of group names to which the user belongs. Since
4178 version 318, the first item in this list is the primary group.</p>
4179 </dd>
4180 <dt class="hdlist1"><code>"home"</code></dt>
4181 <dd>
4182 <p>This is user&#8217;s home directory.</p>
4183 </dd>
4184 <dt class="hdlist1"><code>"shell"</code></dt>
4185 <dd>
4186 <p>This is unix user shell.</p>
4187 </dd>
4188 </dl>
4189 </div>
4190 <div class="paragraph">
4191 <p>Returns a promise that completes once the user information is available.</p>
4192 </div>
4193 <div class="admonitionblock warning">
4194 <table>
4195 <tr>
4196 <td class="icon">
4197 <div class="title">Warning</div>
4198 </td>
4199 <td class="content">
4200 <div class="paragraph">
4201 <p><code>cockpit.user()</code> is soft-deprecated since Cockpit 336, if your page
4202 does not need to maintain compatibility with older Cockpit versions you
4203 can use <a href="#cockpit-info">cockpit.info</a> to obtain the user information.</p>
4204 </div>
4205 </td>
4206 </tr>
4207 </table>
4208 </div>
4209 </div>
4210 <div class="sect3">
4211 <h4 id="cockpit-permission">Permission lookup</h4>
4212 <div class="paragraph">
4213 <p>Cockpit provides a mechanism for checking if the current user satisfies
4214 a given criteria. This is meant for updating UI elements based on what
4215 actions the user can perform. It is <em>not an access control mechanism</em>.</p>
4216 </div>
4217 <div class="sect4">
4218 <h5 id="cockpit-permission-constructor">cockpit.permission()</h5>
4219 <div class="literalblock">
4220 <div class="content">
4221 <pre>permission = cockpit.permission([options])</pre>
4222 </div>
4223 </div>
4224 <div class="paragraph">
4225 <p>Create a new permission object to check if the current user has a
4226 particular permission specified by <code>options</code>:</p>
4227 </div>
4228 <div class="dlist">
4229 <dl>
4230 <dt class="hdlist1"><code>admin: true</code></dt>
4231 <dd>
4232 <p>True if the session has superuser privileges, i.e. can run channels as
4233 root with <code>{ superuser: "require" }</code>.</p>
4234 </dd>
4235 <dt class="hdlist1"><code>group:</code> <em>name</em></dt>
4236 <dd>
4237 <p>True if the currently logged user is a member of group <em>name</em>.</p>
4238 </dd>
4239 </dl>
4240 </div>
4241 <div class="paragraph">
4242 <p>The permission result is always true for the "root" user. When
4243 <code>options</code> is not given, check if the current user is root.</p>
4244 </div>
4245 </div>
4246 <div class="sect4">
4247 <h5 id="cockpit-permission-allowed">permission.allowed</h5>
4248 <div class="paragraph">
4249 <p>A boolean value which indicates if the permission is allowed or not.
4250 This will be <code>null</code> if the permission is unknown, or there was an
4251 error checking the permission or the permission data has not yet loaded.
4252 This property will update asynchronously and if you wish to be notified
4253 of changes connect to the
4254 <a href="#cockpit-permission-changed">permission.onchanged</a> event.</p>
4255 </div>
4256 </div>
4257 <div class="sect4">
4258 <h5 id="cockpit-permission-changed">permission.onchanged</h5>
4259 <div class="literalblock">
4260 <div class="content">
4261 <pre>permission.addEventListener("changed", function() { ... })</pre>
4262 </div>
4263 </div>
4264 <div class="paragraph">
4265 <p>This event is fired when the permission changes. In particular the
4266 <a href="#cockpit-permission-allowed">permission.allowed</a> property.</p>
4267 </div>
4268 </div>
4269 <div class="sect4">
4270 <h5 id="cockpit-permission-close">permission.close()</h5>
4271 <div class="literalblock">
4272 <div class="content">
4273 <pre>permission.close()</pre>
4274 </div>
4275 </div>
4276 <div class="paragraph">
4277 <p>Closes the permission object and tears down any registered callbacks and
4278 dbus subscriptions.</p>
4279 </div>
4280 </div>
4281 </div>
4282 </div>
4283 <div class="sect2">
4284 <h3 id="_cockpit_js_manifests">cockpit.js: Manifests</h3>
4285 <div class="sect3">
4286 <h4 id="cockpit-manifest-loading">Loading Manifests</h4>
4287 <div class="paragraph">
4288 <p>For a convenient access to all page manifests, include
4289 <code>&lt;script src="../manifests.js"&gt;&lt;/script&gt;</code> into your page to register
4290 the manifests at the <code>cockpit.manifests</code> global variable.</p>
4291 </div>
4292 <div class="paragraph">
4293 <p>You can also load <code>../manifests.json</code> directly in your page, with
4294 <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch"><code>fetch()</code></a>.</p>
4295 </div>
4296 </div>
4297 </div>
4298 <div class="sect2">
4299 <h3 id="_cockpit_js_metrics">cockpit.js: Metrics</h3>
4300 <div class="paragraph">
4301 <p>Metrics about the system can be retrieved from several sources using
4302 <a href="#cockpit-metrics-function"><code>cockpit.metrics()</code></a> metrics channels. The
4303 metrics are made available as series data, and can be used with the
4304 <a href="#cockpit-series"><code>cockpit.series()</code></a> and
4305 <a href="#cockpit-grid"><code>cockpit.grid()</code></a> facilities.</p>
4306 </div>
4307 <div class="sect3">
4308 <h4 id="cockpit-metrics-function">cockpit.metrics()</h4>
4309 <div class="literalblock">
4310 <div class="content">
4311 <pre>metrics = cockpit.metrics(interval, options, cache)</pre>
4312 </div>
4313 </div>
4314 <div class="paragraph">
4315 <p>Opens a new metrics channel. The data retrieved will be available in the
4316 <a href="#cockpit-metrics-series"><code>metrics.series</code></a> series sink, and can be
4317 used together with <a href="#cockpit-grid"><code>cockpit.grid()</code></a> objects.</p>
4318 </div>
4319 <div class="paragraph">
4320 <p>The <code>interval</code> is in milliseconds, and is the granularity of the
4321 series data retrieved. Any grids consuming the data must have the same
4322 interval.</p>
4323 </div>
4324 <div class="paragraph">
4325 <p>The <code>cache</code> argument is a cache identifier. If specified, then this
4326 metrics channel will share data with other metrics channels of the same
4327 identifier. Make sure to use a globally unique string.</p>
4328 </div>
4329 <div class="paragraph">
4330 <p>The <code>options</code> argument is either a javascript plain object, or an
4331 array of those. Each object can have the following fields.</p>
4332 </div>
4333 <div class="dlist">
4334 <dl>
4335 <dt class="hdlist1"><code>"metrics"</code></dt>
4336 <dd>
4337 <p>An array of full metric descriptions, as javascript objects. The
4338 specifics of these, and how to determine which ones to use, can
4339 unfortunately only be found in the low-level protocol documentation.
4340 This option is required.</p>
4341 </dd>
4342 <dt class="hdlist1"><code>"source"</code></dt>
4343 <dd>
4344 <p>The source to use for real-time data. This is used by the <code>follow</code>
4345 method, see below. Set to <code>"internal"</code> to retrieve internal metrics
4346 read by the bridge. If set to <code>"direct"</code> or <code>"pmcd"</code> then data
4347 will be retrieved from <a href="https://pcp.io">PCP</a>if it is available. The
4348 default is <code>"internal"</code>.</p>
4349 </dd>
4350 <dt class="hdlist1"><code>"archive_source"</code></dt>
4351 <dd>
4352 <p>The source to use for retrieving historical data. This is used by the
4353 <code>fetch</code> method, see below. Set to <code>"pcp-archive"</code> to retrieve data
4354 from PCP archives. The default is not to try to retrieve historical
4355 data.</p>
4356 </dd>
4357 </dl>
4358 </div>
4359 <div class="paragraph">
4360 <p>When the <code>options</code> argument is an array of javascript objects, then
4361 the metrics channel tries to use them in order until one succeeds. This
4362 way, you can prefer PCP as the source but fall back to internal metrics
4363 when PCP is not available, for example. The channel gives no indication
4364 which of the options has been used, and <code>fetch</code> and <code>follow</code> might
4365 use different entries from the list.</p>
4366 </div>
4367 </div>
4368 <div class="sect3">
4369 <h4 id="cockpit-metrics-fetch">metrics.fetch()</h4>
4370 <div class="literalblock">
4371 <div class="content">
4372 <pre>metrics.fetch(beg, end)</pre>
4373 </div>
4374 </div>
4375 <div class="paragraph">
4376 <p>Retrieve archived metrics data between <code>beg</code> and <code>end</code>. The
4377 arguments can either be numbers, in which case they are interval based
4378 offsets, or they can be javascript Date objects.</p>
4379 </div>
4380 </div>
4381 <div class="sect3">
4382 <h4 id="cockpit-metrics-follow">metrics.follow()</h4>
4383 <div class="literalblock">
4384 <div class="content">
4385 <pre>metrics.follow()</pre>
4386 </div>
4387 </div>
4388 <div class="paragraph">
4389 <p>Start retrieving live metrics data as it become available.</p>
4390 </div>
4391 </div>
4392 <div class="sect3">
4393 <h4 id="cockpit-metrics-close">metrics.close()</h4>
4394 <div class="literalblock">
4395 <div class="content">
4396 <pre>metrics.close()</pre>
4397 </div>
4398 </div>
4399 <div class="paragraph">
4400 <p>Stop the retrieval of metrics and release resources.</p>
4401 </div>
4402 </div>
4403 <div class="sect3">
4404 <h4 id="cockpit-metrics-series">metrics.series</h4>
4405 <div class="paragraph">
4406 <p>The series sink where data retrieved data will be processed.</p>
4407 </div>
4408 </div>
4409 <div class="sect3">
4410 <h4 id="cockpit-metrics-meta">metrics.meta</h4>
4411 <div class="paragraph">
4412 <p>The metrics meta data last received.</p>
4413 </div>
4414 </div>
4415 <div class="sect3">
4416 <h4 id="cockpit-metrics-onchanged">metrics.onchanged</h4>
4417 <div class="literalblock">
4418 <div class="content">
4419 <pre>metrics.onchanged = function() { }</pre>
4420 </div>
4421 </div>
4422 <div class="paragraph">
4423 <p>An event triggered when one of the properties on this metrics object
4424 changes.</p>
4425 </div>
4426 </div>
4427 </div>
4428 <div class="sect2">
4429 <h3 id="_cockpit_js_series_data">cockpit.js: Series Data</h3>
4430 <div class="paragraph">
4431 <p>Series data consists of values along a continuous (usually time) axis.
4432 We can place these in grids which expose a distinct subset of these
4433 values. These are the underlying mechanism for displaying metrics data
4434 in graphs.</p>
4435 </div>
4436 <div class="sect3">
4437 <h4 id="cockpit-grid">cockpit.grid()</h4>
4438 <div class="literalblock">
4439 <div class="content">
4440 <pre>grid = cockpit.grid(interval, [beg, end])</pre>
4441 </div>
4442 </div>
4443 <div class="paragraph">
4444 <p>Creates a grid object to contain series data.</p>
4445 </div>
4446 <div class="paragraph">
4447 <p>The <code>interval</code> is the granularity of the grid. Usually this is a
4448 number of milliseconds, when used with time series data. The <code>beg</code> and
4449 <code>end</code> are the bounds of the grid. If omitted they will be set to zero
4450 for an initially empty grid.</p>
4451 </div>
4452 <div class="paragraph">
4453 <p>If <code>beg</code> and/or <code>end</code> are negative (including negative zero) then
4454 they are interpreted in number of intervals relative to the current
4455 time. Thus cockpit.grid(1000, -300, -0) will create a grid for the most
4456 recent 5 minutes.</p>
4457 </div>
4458 </div>
4459 <div class="sect3">
4460 <h4 id="cockpit-grid-add">grid.add()</h4>
4461 <div class="literalblock">
4462 <div class="content">
4463 <pre>row = grid.add(series, path)
4464 row = grid.add(callback, [early])
4465 row = grid.add()</pre>
4466 </div>
4467 </div>
4468 <div class="paragraph">
4469 <p>Adds a row to the grid. The returned <code>row</code> is a Javascript array that
4470 will contain series data. The arguments control how the row is populated
4471 from the series data. The <code>row</code> is a sparse array. Its <code>row.length</code>
4472 will not match the expected size of the grid, unless and until the row
4473 has been completely filled in. The first index of the <code>row</code> will
4474 contain the data from the series data at the
4475 <a href="#cockpit-grid-beg"><code>grid.beg</code></a> offset.</p>
4476 </div>
4477 <div class="paragraph">
4478 <p>When no arguments are passed, an empty row is added, and it is not
4479 populated with data.</p>
4480 </div>
4481 <div class="paragraph">
4482 <p>When called with a <code>series</code> and <code>path</code> argument then the row will be
4483 populated directly with series data. The <code>series</code> can either be a
4484 <a href="#cockpit-series">series object</a> or an object that has an
4485 <code>obj.series</code> property. The <a href="#cockpit-series-interval">series
4486 interval</a> must match the interval of this grid. If <code>path</code> is missing
4487 or empty, then the series data is placed into the row directly.
4488 Otherwise <code>path</code> indicates which part of the series data to place in
4489 the row. When <code>path</code> is an array, it is used as a set of property
4490 names or array indexes to follow into nested series data. When <code>path</code>
4491 is a dotted string, it is split and used the same way to locate the
4492 correct value in nested series data. The exact format of the series data
4493 depends on its producer, and relevant paths will be documented there.</p>
4494 </div>
4495 <div class="paragraph">
4496 <p>If a <code>callback</code> function is specified, then it will be invoked to
4497 provide series data for the row. The function is invoked as
4498 <code>callback(row, index, count)</code>, where the <code>row</code> is the row to fill
4499 in, the <code>index</code> is the index to start filling in and <code>count</code> is the
4500 number of items to fill in. The <code>this</code> variable will be set to the
4501 grid while invoking the <code>callback</code>. The callback is called after other
4502 data rows for a given series have been filled in. Callbacks are called
4503 in the order added, unless the <code>early</code> argument is set to <code>true</code>, in
4504 which case the callback is called earlier than callbacks without the
4505 <code>early</code> argument set.</p>
4506 </div>
4507 <div class="paragraph">
4508 <p>To remove the row use the <a href="#cockpit-grid-remove"><code>grid.remove()</code>
4509 method.</a></p>
4510 </div>
4511 <div class="paragraph">
4512 <p>The row will start being populated with data when the <code>series</code>
4513 produces data. To make this happen right away, use the
4514 <a href="#cockpit-grid-sync"><code>grid.sync()</code></a> method.</p>
4515 </div>
4516 </div>
4517 <div class="sect3">
4518 <h4 id="cockpit-grid-remove">grid.remove()</h4>
4519 <div class="literalblock">
4520 <div class="content">
4521 <pre>grid.remove(row)</pre>
4522 </div>
4523 </div>
4524 <div class="paragraph">
4525 <p>Remove a previously added <code>row</code> from the grid. The row will no longer
4526 be updated with series data.</p>
4527 </div>
4528 </div>
4529 <div class="sect3">
4530 <h4 id="cockpit-grid-sync">grid.sync()</h4>
4531 <div class="literalblock">
4532 <div class="content">
4533 <pre>grid.sync()</pre>
4534 </div>
4535 </div>
4536 <div class="paragraph">
4537 <p>Load or reload data from the series into the rows. This does not clear
4538 the rows before populating them. Some data may be populated immediately,
4539 others may have to wait until data can be loaded. Internally this
4540 function calls <a href="#cockpit-series-load"><code>series.load()</code></a> for each
4541 series.</p>
4542 </div>
4543 <div class="paragraph">
4544 <p>All rows with callbacks will be invoked to regenerate all the data. The
4545 <a href="#cockpit-grid-onnotify"><code>grid.onnotify</code></a> event will be triggered.
4546 It is not necessary to call this function after a call of the
4547 <a href="#cockpit-grid-move"><code>grid.move()</code></a> method.</p>
4548 </div>
4549 </div>
4550 <div class="sect3">
4551 <h4 id="cockpit-grid-move">grid.move()</h4>
4552 <div class="literalblock">
4553 <div class="content">
4554 <pre>grid.move(beg[, end])</pre>
4555 </div>
4556 </div>
4557 <div class="paragraph">
4558 <p>Move the grid to new <code>beg</code> and <code>end</code> range. Data will be discarded
4559 from the rows and <a href="#cockpit-grid-sync"><code>grid.sync()</code></a> will be
4560 called to load or reload series data for the new range of offsets.</p>
4561 </div>
4562 <div class="paragraph">
4563 <p>If <code>end</code> is not specified it will be set to <code>beg</code>. If <code>beg</code> and/or
4564 <code>end</code> are negative (including negative zero) then they will be set to
4565 the number of intervals prior to the current time taken as an interval.</p>
4566 </div>
4567 <div class="paragraph">
4568 <p>If <code>beg</code> and/or <code>end</code> are negative (including negative zero) then
4569 they are interpreted in number of intervals relative to the current
4570 time. Thus cockpit.grid(1000, -300, -0) will create a grid for the most
4571 recent 5 minutes.</p>
4572 </div>
4573 </div>
4574 <div class="sect3">
4575 <h4 id="cockpit-grid-walk">grid.walk()</h4>
4576 <div class="literalblock">
4577 <div class="content">
4578 <pre>grid.walk()</pre>
4579 </div>
4580 </div>
4581 <div class="paragraph">
4582 <p>Move the grid forward every
4583 <a href="#cockpit-grid-interval"><code>grid.interval</code></a> milliseconds. To stop
4584 moving forward, call <a href="#cockpit-grid-move"><code>grid.move()</code></a>.</p>
4585 </div>
4586 </div>
4587 <div class="sect3">
4588 <h4 id="cockpit-grid-notify">grid.notify()</h4>
4589 <div class="literalblock">
4590 <div class="content">
4591 <pre>grid.notify(index, count)</pre>
4592 </div>
4593 </div>
4594 <div class="paragraph">
4595 <p>This function is called to have rows with callbacks recalculate their
4596 data. It is not normally necessary to call this function, as it will be
4597 invoked automatically when new series data is available or has been
4598 loaded. This function triggers the
4599 <a href="#cockpit-grid-onnotify"><code>grid.onnotify</code></a> event.</p>
4600 </div>
4601 </div>
4602 <div class="sect3">
4603 <h4 id="cockpit-grid-onnotify">grid.onnotify</h4>
4604 <div class="literalblock">
4605 <div class="content">
4606 <pre>grid.addEventListener("notify", function(index, count) { ... });</pre>
4607 </div>
4608 </div>
4609 <div class="paragraph">
4610 <p>An event that is triggered when some part of the series data in grid
4611 changes. The <code>index</code> is the row index where things changed, and the
4612 <code>count</code> is the length of the data that changed.</p>
4613 </div>
4614 </div>
4615 <div class="sect3">
4616 <h4 id="cockpit-grid-close">grid.close()</h4>
4617 <div class="literalblock">
4618 <div class="content">
4619 <pre>grid.close()</pre>
4620 </div>
4621 </div>
4622 <div class="paragraph">
4623 <p>Close the grid, and stop updating the rows.</p>
4624 </div>
4625 </div>
4626 <div class="sect3">
4627 <h4 id="cockpit-grid-interval">grid.interval</h4>
4628 <div class="paragraph">
4629 <p>The granularity of the grid. For time series data this is an interval in
4630 milliseconds. In order to use a given <a href="#cockpit-grid">grid</a> and
4631 <a href="#cockpit-series">series</a> together, their interval properties must
4632 match.</p>
4633 </div>
4634 </div>
4635 <div class="sect3">
4636 <h4 id="cockpit-grid-beg">grid.beg</h4>
4637 <div class="paragraph">
4638 <p>The beginning offset of the series data in the grid. Do not set this
4639 property directly. Use the <a href="#cockpit-grid-move">grid.move()</a> method
4640 instead.</p>
4641 </div>
4642 </div>
4643 <div class="sect3">
4644 <h4 id="cockpit-grid-end">grid.end</h4>
4645 <div class="paragraph">
4646 <p>The ending offset of the series data in the grid. Do not set this
4647 property directly. Use the <a href="#cockpit-grid-move">grid.move()</a> method
4648 instead.</p>
4649 </div>
4650 </div>
4651 <div class="sect3">
4652 <h4 id="cockpit-series">cockpit.series()</h4>
4653 <div class="literalblock">
4654 <div class="content">
4655 <pre>series = cockpit.series(interval, [cache, fetch])</pre>
4656 </div>
4657 </div>
4658 <div class="paragraph">
4659 <p>Create a new sink of series data. This is usually done by producers of
4660 series data, and it is rare to invoke this function directly.</p>
4661 </div>
4662 <div class="paragraph">
4663 <p>The <code>interval</code> is the granularity of the series data. For time series
4664 data this is an interval in milliseconds. If a <code>cache</code> string is
4665 specified, series data will be cached across frames for series with the
4666 same <code>cache</code> cache identifier to load and/or reload.</p>
4667 </div>
4668 <div class="paragraph">
4669 <p>If a <code>fetch</code> callback is specified, then it will be invoked when grids
4670 request certain ranges of data. The <code>fetch</code> callback is invoked with
4671 <code>function fetch(beg, end) { ... }</code> range offsets. The
4672 <a href="#cockpit-series-input">series.input()</a> should be called with data
4673 retrieved, either immediately or at a later time. The callback may be
4674 called multiple times for the same ranges of data. It is up to the
4675 callback to determine when or whether it should retrieve the data more
4676 than once.</p>
4677 </div>
4678 <div class="paragraph">
4679 <p>A producer of series data, usually calls this function and creates
4680 itself a <code>obj.series</code> property containing this series object.</p>
4681 </div>
4682 </div>
4683 <div class="sect3">
4684 <h4 id="cockpit-series-input">series.input()</h4>
4685 <div class="literalblock">
4686 <div class="content">
4687 <pre>series.input(beg, items[, mapping])</pre>
4688 </div>
4689 </div>
4690 <div class="paragraph">
4691 <p>Send series data into the series sink. Any grids that have added rows
4692 based on this series, will have data filled in. The <code>beg</code> is the
4693 beginning offset of <code>items</code>. The <code>items</code> are an array one or more
4694 series data items.</p>
4695 </div>
4696 <div class="paragraph">
4697 <p>Producers may wish to provide additional properties that can be used in
4698 lookup paths that rows can pull from. This is done in the <code>mapping</code>
4699 argument. If specified it is a tree of objects. Each sub object should
4700 have a property with the name <code>""</code> empty string, which will be used as
4701 the property name or index in place of the one used in the lookup path.</p>
4702 </div>
4703 </div>
4704 <div class="sect3">
4705 <h4 id="cockpit-series-load">series.load()</h4>
4706 <div class="literalblock">
4707 <div class="content">
4708 <pre>series.load(beg, end)</pre>
4709 </div>
4710 </div>
4711 <div class="paragraph">
4712 <p>Load data from the series into any grids that have rows based on this
4713 series data. Any cached data will be filled in immediately. Any data not
4714 cached, will be requested from the producer, if possible, and may arrive
4715 at a later time.</p>
4716 </div>
4717 <div class="paragraph">
4718 <p>The <code>beg</code> and <code>end</code> denote the range of data to load.</p>
4719 </div>
4720 </div>
4721 <div class="sect3">
4722 <h4 id="cockpit-series-interval">series.interval</h4>
4723 <div class="paragraph">
4724 <p>The granularity of the series. For time series data this is an interval
4725 in milliseconds. In order to use a given <a href="#cockpit-grid">grid</a> and
4726 <a href="#cockpit-series">series</a> together, their interval properties must
4727 match.</p>
4728 </div>
4729 </div>
4730 <div class="sect3">
4731 <h4 id="cockpit-series-limit">series.limit</h4>
4732 <div class="paragraph">
4733 <p>The maximum number of items to cache for loading and/or reloading. You
4734 can change this value to a different number. Having a number close to
4735 zero will break certain usage of grids, such as
4736 <a href="#cockpit-grid-walk"><code>grid.walk()</code></a>.</p>
4737 </div>
4738 </div>
4739 </div>
4740 <div class="sect2">
4741 <h3 id="_cockpit_js_spawning_processes">cockpit.js: Spawning Processes</h3>
4742 <div class="paragraph">
4743 <p>This is the API for spawning a process and receiving its output, as well
4744 as exit codes.</p>
4745 </div>
4746 <div class="sect3">
4747 <h4 id="cockpit-spawn-spawn">cockpit.spawn()</h4>
4748 <div class="literalblock">
4749 <div class="content">
4750 <pre>process = cockpit.spawn(args, [options])</pre>
4751 </div>
4752 </div>
4753 <div class="paragraph">
4754 <p>Spawns a process on the system.</p>
4755 </div>
4756 <div class="paragraph">
4757 <p>The <code>args</code> should be an array starting with the executable and
4758 containing all the arguments to pass on the command line. If <code>args</code> is
4759 a string then it is interpreted as an executable name. The optional
4760 <code>options</code> argument is a javascript plain object and can contain any of
4761 the following fields:</p>
4762 </div>
4763 <div class="dlist">
4764 <dl>
4765 <dt class="hdlist1"><code>"binary"</code></dt>
4766 <dd>
4767 <p>If set to <code>true</code> then handle the input and output of the process as
4768 arrays of binary bytes.</p>
4769 </dd>
4770 <dt class="hdlist1"><code>"directory"</code></dt>
4771 <dd>
4772 <p>The directory to spawn the process in.</p>
4773 </dd>
4774 <dt class="hdlist1"><code>"err"</code></dt>
4775 <dd>
4776 <p>Controls where the standard error is sent. By default it is logged to
4777 the journal. If set to <code>"out"</code> it is included in with the output
4778 data. If set to <code>"ignore"</code> then the error output is discarded. If
4779 set to <code>"message"</code>, then it will be returned as the error message.
4780 When the <code>"pty"</code> field is set, this field has no effect.</p>
4781 </dd>
4782 <dt class="hdlist1"><code>"environ"</code></dt>
4783 <dd>
4784 <p>An optional array that contains strings to be used as additional
4785 environment variables for the new process. These are <code>"NAME=VALUE"</code>
4786 strings.</p>
4787 </dd>
4788 <dt class="hdlist1"><code>"pty"</code></dt>
4789 <dd>
4790 <p>Launch the process in its own PTY terminal, and send/receive terminal
4791 input and output.</p>
4792 </dd>
4793 <dt class="hdlist1"><code>"batch"</code></dt>
4794 <dd>
4795 <p>Batch data coming from the process in blocks of at least this size.
4796 This is not a guarantee. After a short timeout the data will be sent
4797 even if the data doesn&#8217;t match the batch size. Defaults to zero.</p>
4798 </dd>
4799 <dt class="hdlist1"><code>"latency"</code></dt>
4800 <dd>
4801 <p>The timeout for flushing any cached data in milliseconds.</p>
4802 </dd>
4803 <dt class="hdlist1"><code>"superuser"</code></dt>
4804 <dd>
4805 <p>Set to <code>"require"</code> to spawn the process as root instead of the
4806 logged in user. If the currently logged in user is not permitted to
4807 become root (eg: via <code>pkexec</code>) then the <code>client</code> will immediately
4808 be <a href="#cockpit-dbus-onclose">closed</a> with a <code>"access-denied"</code>
4809 problem code.
4810 +
4811 Set to <code>"try"</code> to try to run the process as root, but if that fails,
4812 fall back to an unprivileged process.</p>
4813 </dd>
4814 </dl>
4815 </div>
4816 <div class="paragraph">
4817 <p>The spawned process is a
4818 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a>
4819 that will complete if the process exits successfully, or fail if there&#8217;s
4820 a problem. Some additional methods besides the standard promise methods
4821 are documented below.</p>
4822 </div>
4823 <div class="paragraph">
4824 <p>The standard output of the process is made available via the spawned
4825 process object. Any non-UTF8 output from the process will be coerced
4826 into textual form. It is highly recommended that only textual output be
4827 produced by the command. The standard error is logged to the journal.</p>
4828 </div>
4829 </div>
4830 <div class="sect3">
4831 <h4 id="cockpit-spawn-script">cockpit.script()</h4>
4832 <div class="literalblock">
4833 <div class="content">
4834 <pre>process = cockpit.script(script, [args], [options])</pre>
4835 </div>
4836 </div>
4837 <div class="paragraph">
4838 <p>Run a shell script on the system.</p>
4839 </div>
4840 <div class="paragraph">
4841 <p>This function <a href="#cockpit-spawn-spawn">spawns</a> a Bourne shell script
4842 process. The full text of the <code>/bin/sh</code> shell script should be passed
4843 in as the first argument. The <code>args</code> can be an array of arguments, not
4844 including the executable, which are passed to the script as <code>$1</code>,
4845 <code>$2</code> and so on. Shebang options are not used or respected.</p>
4846 </div>
4847 <div class="paragraph">
4848 <p>The <code>options</code> is an optional javascript plain object and can include
4849 any of the fields listed for the
4850 <a href="#cockpit-spawn-spawn"><code>cockpit.spawn()</code></a> function.</p>
4851 </div>
4852 <div class="paragraph">
4853 <p>The spawned process is a
4854 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a>
4855 that will complete if the script exits successfully, or fail if there&#8217;s
4856 a problem. Some additional methods besides the standard promise methods
4857 are documented below.</p>
4858 </div>
4859 <div class="paragraph">
4860 <p>The standard output of the process is made available via the spawned
4861 process object. Any non-UTF8 output from the process will be coerced
4862 into textual form. It is highly recommended that only textual output be
4863 produced by the command. The standard error is logged to the journal by
4864 default.</p>
4865 </div>
4866 </div>
4867 <div class="sect3">
4868 <h4 id="cockpit-spawn-then">process.then()</h4>
4869 <div class="literalblock">
4870 <div class="content">
4871 <pre>process.then((data[, message]) =&gt; { ... })</pre>
4872 </div>
4873 </div>
4874 <div class="paragraph">
4875 <p>This is a standard
4876 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a>
4877 method. It sets up a handler to be called when the process finishes
4878 successfully.</p>
4879 </div>
4880 <div class="paragraph">
4881 <p>The <code>data</code> argument contains the standard output of the process. If it
4882 a string, unless the process was opened in binary mode, in which case
4883 the <code>data</code> is an array of bytes. If a <code>process.stream()</code> handler is
4884 set up, then any standard output data consumed by the handler will not
4885 be included in the <code>data</code> argument.</p>
4886 </div>
4887 <div class="paragraph">
4888 <p>If the process was spawned with the <code>"err"</code> option set to
4889 <code>"message"</code> then the second argument will contain the standard error
4890 output of the process.</p>
4891 </div>
4892 </div>
4893 <div class="sect3">
4894 <h4 id="cockpit-spawn-catch">process.catch()</h4>
4895 <div class="literalblock">
4896 <div class="content">
4897 <pre>process.catch((exception[, data]) =&gt; { ... })</pre>
4898 </div>
4899 </div>
4900 <div class="paragraph">
4901 <p>This is a standard
4902 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
4903 method. It sets up a handler to be called when the process fails,
4904 terminates or exits.</p>
4905 </div>
4906 <div class="paragraph">
4907 <p>The <code>exception</code> object passed to the handler can have the following
4908 fields:</p>
4909 </div>
4910 <div class="dlist">
4911 <dl>
4912 <dt class="hdlist1"><code>message</code></dt>
4913 <dd>
4914 <p>A message describing the exception. If the process was spawned with
4915 the <code>"err"</code> option set to <code>"message"</code> then the second argument
4916 will contain the standard error output of the process.</p>
4917 </dd>
4918 <dt class="hdlist1"><code>problem</code></dt>
4919 <dd>
4920 <p>A <a href="#cockpit-problems">problem code</a> string when a problem occurred
4921 starting or communicating with the process. This is <code>null</code> if the
4922 process exited or was terminated.</p>
4923 </dd>
4924 <dt class="hdlist1"><code>exit_status</code></dt>
4925 <dd>
4926 <p>The numeric exit status of the process. This is <code>null</code> if the
4927 process did not exit.</p>
4928 </dd>
4929 <dt class="hdlist1"><code>exit_signal</code></dt>
4930 <dd>
4931 <p>A string representing a unix signal that caused the process to
4932 terminate. This is <code>null</code> if the process did not terminate because
4933 of a signal.</p>
4934 </dd>
4935 </dl>
4936 </div>
4937 <div class="paragraph">
4938 <p>If the process actually ran and produced output before failing, it will
4939 be available in the <code>data</code> argument. Otherwise this argument will be
4940 <code>undefined</code>.</p>
4941 </div>
4942 </div>
4943 <div class="sect3">
4944 <h4 id="cockpit-spawn-stream">process.stream()</h4>
4945 <div class="literalblock">
4946 <div class="content">
4947 <pre>process.stream(data =&gt; { ... })</pre>
4948 </div>
4949 </div>
4950 <div class="paragraph">
4951 <p>This sets up a handler to be called when the process has standard
4952 output. The handler will be called multiple times. The handler will be
4953 called regardless of whether the process ends up exiting successfully or
4954 not.</p>
4955 </div>
4956 <div class="paragraph">
4957 <p>Only one handler may be registered at a time. Registering an additional
4958 handler replaces the previous one. The handler receives either string
4959 <code>data</code> or an array of binary bytes as its argument. A stream handler
4960 may return a number, which indicates the number of characters or bytes
4961 consumed from <code>data</code>. Any data not consumed will be included again the
4962 next time the handler is called.</p>
4963 </div>
4964 <div class="paragraph">
4965 <p>If a <code>process.stream()</code> handler is set up, then the <code>process.then()</code>
4966 handlers will only get any remaining data not consumed by the stream
4967 handler.</p>
4968 </div>
4969 </div>
4970 <div class="sect3">
4971 <h4 id="cockpit-spawn-input">process.input()</h4>
4972 <div class="literalblock">
4973 <div class="content">
4974 <pre>process.input(data, [stream])</pre>
4975 </div>
4976 </div>
4977 <div class="paragraph">
4978 <p>This method writes <code>data</code> to the standard input of the process. If
4979 <code>data</code> is <code>null</code> or <code>undefined</code> it is not sent. The <code>data</code>
4980 should be a string or an array of bytes if the process was opened in
4981 binary mode.</p>
4982 </div>
4983 <div class="paragraph">
4984 <p>If <code>stream</code> is set to <code>true</code> then this function may be called again
4985 with further input. Otherwise the standard input of the process is
4986 closed.</p>
4987 </div>
4988 </div>
4989 <div class="sect3">
4990 <h4 id="cockpit-spawn-close">process.close()</h4>
4991 <div class="literalblock">
4992 <div class="content">
4993 <pre>process.close([problem])</pre>
4994 </div>
4995 </div>
4996 <div class="paragraph">
4997 <p>Close the process by closing its standard input and output. If
4998 <code>problem</code> is specified it should be a standard
4999 <a href="#cockpit-problems">problem code</a> string. In this case the process
5000 will be terminated with a signal.</p>
5001 </div>
5002 </div>
5003 </div>
5004 <div class="sect2">
5005 <h3 id="_cockpit_js_utilities">cockpit.js: Utilities</h3>
5006 <div class="paragraph">
5007 <p>Various utility functions</p>
5008 </div>
5009 <div class="sect3">
5010 <h4 id="cockpit-format">cockpit.format()</h4>
5011 <div class="literalblock">
5012 <div class="content">
5013 <pre>string = cockpit.format(template, args)
5014 string = cockpit.format(template, [arg, ...])</pre>
5015 </div>
5016 </div>
5017 <div class="paragraph">
5018 <p>Format a string interpolating <code>args</code> into <code>template</code> using shell
5019 like syntax. The <code>args</code> may be either an array or javascript object.
5020 The <code>template</code> can contain fields that look like <code>$name</code> or
5021 <code>${name}</code> or <code>$0</code>. Numeric fields are used with array <code>args</code> and
5022 start at zero.</p>
5023 </div>
5024 <div class="paragraph">
5025 <p>In the second form, multiple <code>arg</code> arguments may be passed directly,
5026 and interpolated as as numeric fields in the <code>template</code>.</p>
5027 </div>
5028 <div class="paragraph">
5029 <p>All falsy arguments except the numbers <code>0</code> and `0.0`are replaced by
5030 an empty string.</p>
5031 </div>
5032 </div>
5033 <div class="sect3">
5034 <h4 id="cockpit-format-number">cockpit.format_number()</h4>
5035 <div class="literalblock">
5036 <div class="content">
5037 <pre>string = cockpit.format_number(number, [precision])</pre>
5038 </div>
5039 </div>
5040 <div class="paragraph">
5041 <p>Formats <code>number</code> into a displayable <code>string</code>. If the number is not
5042 an integer, it is rounded to the given number of decimal places,
5043 defaulting to 3. If the number is near zero, but not quite zero it is
5044 rounded to the smallest non-zero value of the given precision; i.e.
5045 ±0.001 for default precision 3.</p>
5046 </div>
5047 <div class="paragraph">
5048 <p>If <code>number</code> is <code>null</code> or <code>undefined</code> an empty string will be
5049 returned.</p>
5050 </div>
5051 </div>
5052 <div class="sect3">
5053 <h4 id="cockpit-format-bytes">cockpit.format_bytes()</h4>
5054 <div class="literalblock">
5055 <div class="content">
5056 <pre>string = cockpit.format_bytes(number, [options])</pre>
5057 </div>
5058 </div>
5059 <div class="paragraph">
5060 <p>Formats <code>number</code> into a displayable <code>string</code> with a suffix, such as
5061 <em>kB</em> or <em>MB</em>.</p>
5062 </div>
5063 <div class="paragraph">
5064 <p>By default, SI units are used. IEC units (1024-based) can be requested
5065 by including <code>base2: true</code> in <code>options</code>.</p>
5066 </div>
5067 <div class="paragraph">
5068 <p>By default, non-integer numbers will be formatted with 3 digits of
5069 precision. This can be changed with <code>options.precision</code>.</p>
5070 </div>
5071 <div class="paragraph">
5072 <p>If <code>number</code> is <code>null</code> or <code>undefined</code> an empty string will be
5073 returned.</p>
5074 </div>
5075 </div>
5076 <div class="sect3">
5077 <h4 id="cockpit-format-bytes-per-sec">cockpit.format_bytes_per_sec()</h4>
5078 <div class="literalblock">
5079 <div class="content">
5080 <pre>string = cockpit.format_bytes_per_sec(number, [options])</pre>
5081 </div>
5082 </div>
5083 <div class="paragraph">
5084 <p>Format <code>number</code> of bytes into a displayable speed <code>string</code>.</p>
5085 </div>
5086 <div class="paragraph">
5087 <p>This function is mostly equivalent to <code>cockpit.format_bytes()</code> but the
5088 returned value contains a unit like <em>kB/s</em> or <em>MB/s</em>.</p>
5089 </div>
5090 </div>
5091 <div class="sect3">
5092 <h4 id="cockpit-format-bits-per-sec">cockpit.format_bits_per_sec()</h4>
5093 <div class="literalblock">
5094 <div class="content">
5095 <pre>string = cockpit.format_bits_per_sec(number, [options])</pre>
5096 </div>
5097 </div>
5098 <div class="paragraph">
5099 <p>Format <code>number</code> of bits into a displayable speed <code>string</code>.</p>
5100 </div>
5101 <div class="paragraph">
5102 <p>This function is mostly equivalent to <code>cockpit.format_bytes()</code> but the
5103 returned value contains a unit like <em>kbps</em> or <em>Mbps</em>.</p>
5104 </div>
5105 <div class="paragraph">
5106 <p>This function does not support IEC units. <code>base2</code> may not be passed as
5107 part of <code>options</code>.</p>
5108 </div>
5109 </div>
5110 <div class="sect3">
5111 <h4 id="cockpit-init">cockpit.init()</h4>
5112 <div class="literalblock">
5113 <div class="content">
5114 <pre>await cockpit.init();
5115
5116 cockpit.init().then(() =&gt; { ... });</pre>
5117 </div>
5118 </div>
5119 <div class="paragraph">
5120 <p>Requests initialization of the Cockpit client library. This will ensure
5121 that the transport is connected and we are ready to create channels. It
5122 also populates the <code>cockpit.info</code> field.</p>
5123 </div>
5124 <div class="paragraph">
5125 <p>This function returns a promise. Initialization isn&#8217;t complete until the
5126 promise has resolved. You can either <code>await</code> it or call <code>.then()</code> on
5127 it.</p>
5128 </div>
5129 </div>
5130 <div class="sect3">
5131 <h4 id="cockpit-info">cockpit.info</h4>
5132 <div class="literalblock">
5133 <div class="content">
5134 <pre>cockpit.info.channels[payload]
5135
5136 cockpit.info.os_release[field]
5137
5138 cockpit.info.user
5139
5140 cockpit.info.ws.version</pre>
5141 </div>
5142 </div>
5143 <div class="paragraph">
5144 <p>This object contains information about Cockpit itself. It is only
5145 available after cockpit.init() has been called and awaited.</p>
5146 </div>
5147 <div class="dlist">
5148 <dl>
5149 <dt class="hdlist1"><code>channels</code></dt>
5150 <dd>
5151 <p>This is a mapping of channel payload types (keys, strings) supported
5152 by the bridge to capabilities advertised by those channels (values,
5153 lists of strings). Channels are listed even if they don&#8217;t advertise
5154 any capabilities, making this useful as a way to determine which
5155 channel types are supported by the bridge.</p>
5156 </dd>
5157 <dt class="hdlist1"><code>os_release</code></dt>
5158 <dd>
5159 <p>This is the data from the <code>/etc/os-release</code> or
5160 <code>/usr/lib/os-release</code> on the system that the bridge is running on.
5161 It is a mapping from the key names to their values. See the
5162 <a href="https://www.freedesktop.org/software/systemd/man/latest/os-release.html">os-release
5163 Specification</a> for information about the available keys.</p>
5164 </dd>
5165 <dt class="hdlist1"><code>user</code></dt>
5166 <dd>
5167 <p>Contains information about the user we&#8217;re logged in as.</p>
5168 <div class="dlist">
5169 <dl>
5170 <dt class="hdlist1"><code>uid</code></dt>
5171 <dd>
5172 <p>This is unix user id as an integer.</p>
5173 </dd>
5174 <dt class="hdlist1"><code>gid</code></dt>
5175 <dd>
5176 <p>This is unix user group id as an integer.</p>
5177 </dd>
5178 <dt class="hdlist1"><code>name</code></dt>
5179 <dd>
5180 <p>This is the unix user name like <code>"root"</code>.</p>
5181 </dd>
5182 <dt class="hdlist1"><code>fullname</code></dt>
5183 <dd>
5184 <p>This is a readable name for the user, from the GECOS field.</p>
5185 </dd>
5186 <dt class="hdlist1"><code>group</code></dt>
5187 <dd>
5188 <p>This is the primary group name of the user.</p>
5189 </dd>
5190 <dt class="hdlist1"><code>groups</code></dt>
5191 <dd>
5192 <p>This is an array of group names to which the user belongs. The first
5193 item in this list is the primary group.</p>
5194 </dd>
5195 <dt class="hdlist1"><code>home</code></dt>
5196 <dd>
5197 <p>This is user&#8217;s home directory.</p>
5198 </dd>
5199 <dt class="hdlist1"><code>shell</code></dt>
5200 <dd>
5201 <p>This is unix user shell.</p>
5202 </dd>
5203 </dl>
5204 </div>
5205 </dd>
5206 <dt class="hdlist1"><code>ws</code></dt>
5207 <dd>
5208 <p>Contains information about the webserver Cockpit is being served with.</p>
5209 <div class="dlist">
5210 <dl>
5211 <dt class="hdlist1"><code>version</code></dt>
5212 <dd>
5213 <p>The version of the webserver.</p>
5214 </dd>
5215 </dl>
5216 </div>
5217 </dd>
5218 </dl>
5219 </div>
5220 </div>
5221 <div class="sect3">
5222 <h4 id="cockpit-event-target">cockpit.event_target</h4>
5223 <div class="literalblock">
5224 <div class="content">
5225 <pre>cockpit.event_target(object, [handlers])</pre>
5226 </div>
5227 </div>
5228 <div class="paragraph">
5229 <p>Adds an
5230 <a href="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget">EventTarget</a>
5231 implementation to the <code>object</code>. Optionally store the handlers in
5232 <code>handlers</code> if its specified.</p>
5233 </div>
5234 </div>
5235 </div>
5236 </div>
5237 </div>
5238 <div class="sect1">
5239 <h2 id="_api_shell">API: shell</h2>
5240 <div class="sectionbody">
5241 <div class="paragraph">
5242 <p>This package contains the shell that loads other components.</p>
5243 </div>
5244 <div class="sect2">
5245 <h3 id="_index_html">index.html</h3>
5246 <div class="literalblock">
5247 <div class="content">
5248 <pre>&lt;iframe src="http://127.0.0.1:9090/cockpit+app/@localhost/shell/index.html"
5249 width="600" height="400"&gt;&lt;/iframe&gt;</pre>
5250 </div>
5251 </div>
5252 <div class="paragraph">
5253 <p>This is a Cockpit component that provides an interface to configure a
5254 single machine. It loads other components on demand to make that happen.</p>
5255 </div>
5256 <div class="dlist">
5257 <dl>
5258 <dt class="hdlist1">Component URL</dt>
5259 <dd>
5260 <p><code>/cockpit+app/@localhost/shell/index.html</code></p>
5261 </dd>
5262 </dl>
5263 </div>
5264 </div>
5265 </div>
5266 </div>
5267 <div class="sect1">
5268 <h2 id="_api_system">API: system</h2>
5269 <div class="sectionbody">
5270 <div class="paragraph">
5271 <p>This package contains general components for basic control of a system.</p>
5272 </div>
5273 <div class="sect2">
5274 <h3 id="_logs_html">logs.html</h3>
5275 <div class="paragraph">
5276 <p>System log component</p>
5277 </div>
5278 <div class="sect3">
5279 <h4 id="api-logs-html-description">Description</h4>
5280 <div class="literalblock">
5281 <div class="content">
5282 <pre>&lt;iframe src="http://127.0.0.1:9090/cockpit+app/@localhost/system/logs.html"
5283 width="600" height="400"&gt;&lt;/iframe&gt;</pre>
5284 </div>
5285 </div>
5286 <div class="paragraph">
5287 <p>This is a Cockpit component that brings up system log viewer, with
5288 filtering capabilities. On systemd based systems this displays the
5289 entries from journal.</p>
5290 </div>
5291 <div class="dlist">
5292 <dl>
5293 <dt class="hdlist1">Component URL</dt>
5294 <dd>
5295 <p><code>/cockpit+app/@localhost/system/logs.html</code></p>
5296 </dd>
5297 <dt class="hdlist1">Filter by priority</dt>
5298 <dd>
5299 <p><code>#?prio=notice</code><br>
5300 <br>
5301 Filters the log to show entries below the specific priority,
5302 inclusive. These
5303 <a href="https://en.wikipedia.org/wiki/Syslog#Severity_levels">priorities are
5304 syslog level keywords</a>. Specifying <code>*</code> as a priority will show all
5305 available entries. The default priority is <code>err</code>.</p>
5306 </dd>
5307 <dt class="hdlist1">Filter by service</dt>
5308 <dd>
5309 <p><code>#?service=sshd.service</code><br>
5310 <br>
5311 Filters the log to show entries related to the specific service. The
5312 format of the service is specific to the logging implementation. For
5313 journald these are systemd service unit names.</p>
5314 </dd>
5315 <dt class="hdlist1">Filter by tag</dt>
5316 <dd>
5317 <p><code>#?tag=kernel</code><br>
5318 <br>
5319 Filters the log to show entries related to the specific syslog
5320 identifier.</p>
5321 </dd>
5322 <dt class="hdlist1">Filter by message</dt>
5323 <dd>
5324 <p><code>#?grep=</code><br>
5325 <br>
5326 Filters the log to show entries where the <code>MESSAGE=</code> field matches
5327 the specified regular expression. PERL-compatible regular expressions
5328 are used. If the pattern is all lowercase, matching is case
5329 insensitive. Otherwise, matching is case sensitive.</p>
5330 </dd>
5331 <dt class="hdlist1">Filter by any field</dt>
5332 <dd>
5333 <p><code>#?FIELD=VALUE</code><br>
5334 <br>
5335 A field is referring to the components of a structured journal entry.
5336 The match must be exact. Value can be comma separated list in which
5337 case they are automatically matched as alternatives.</p>
5338 </dd>
5339 <dt class="hdlist1">Start at point</dt>
5340 <dd>
5341 <p><code>#?start=boot</code><br>
5342 <br>
5343 Filters the log to show entries after the specific point in time.
5344 Valid values are <code>boot</code> (since last boot), <code>last-24h</code> (last 24
5345 hours), <code>last-week</code> (last seven days) and <code>previous-boot</code>
5346 (previous boot).</p>
5347 </dd>
5348 <dt class="hdlist1">Follow the journal</dt>
5349 <dd>
5350 <p><code>#?follow=true</code><br>
5351 <br>
5352 Keep listening on new entries. Valid values are <code>true</code> (follow) and
5353 <code>false</code> (do not follow).</p>
5354 </dd>
5355 <dt class="hdlist1">Show log entry</dt>
5356 <dd>
5357 <p><code>#/6e272d82993c4e0d...</code><br>
5358 <br>
5359 To show a specific log entry, put the log entry cursor in a path after
5360 the hash above. Note that cursors are logging system specific, and
5361 journal cursors are subject to change.</p>
5362 </dd>
5363 </dl>
5364 </div>
5365 </div>
5366 </div>
5367 <div class="sect2">
5368 <h3 id="_terminal_html">terminal.html</h3>
5369 <div class="paragraph">
5370 <p>Server terminal component</p>
5371 </div>
5372 <div class="sect3">
5373 <h4 id="api-terminal-html-description">Description</h4>
5374 <div class="literalblock">
5375 <div class="content">
5376 <pre>&lt;iframe src="http://127.0.0.1:9090/cockpit+app/@localhost/system/terminal.html"
5377 width="600" height="400"&gt;&lt;/iframe&gt;</pre>
5378 </div>
5379 </div>
5380 <div class="paragraph">
5381 <p>This is a Cockpit component that brings up a web-based terminal for the
5382 logged in user.</p>
5383 </div>
5384 <div class="dlist">
5385 <dl>
5386 <dt class="hdlist1">Component URL</dt>
5387 <dd>
5388 <p><code>/cockpit+app/@localhost/system/terminal.html</code></p>
5389 </dd>
5390 </dl>
5391 </div>
5392 </div>
5393 </div>
5394 </div>
5395 </div>
5396 </div>
5397 <div id="footer">
5398 <div id="footer-text">
5399 Last updated 2026-09-23 13:50:34 UTC
5400 </div>
5401 </div>
5402 </body>
5403 </html>