Debian Codegraph @

doc/output/html/index.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>Cockpit documentation</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 class="article toc2 toc-left">
437 <div id="header">
438 <h1>Cockpit documentation</h1>
439 <div id="toc" class="toc2">
440 <div id="toctitle">Table of Contents</div>
441 <ul class="sectlevel1">
442 <li><a href="#guide">Deployment Guide</a>
443 <ul class="sectlevel2">
444 <li><a href="#cockpit-manual">Manual pages</a>
445 <ul class="sectlevel3">
446 <li><a href="#_cockpit1">cockpit(1)</a></li>
447 <li><a href="#_cockpit_conf5">cockpit.conf(5)</a></li>
448 <li><a href="#_cockpit_ws8">cockpit-ws(8)</a></li>
449 <li><a href="#_cockpit_tls8">cockpit-tls(8)</a></li>
450 <li><a href="#_cockpit_desktop1">cockpit-desktop(1)</a></li>
451 <li><a href="#_cockpit_bridge1">cockpit-bridge(1)</a></li>
452 <li><a href="#_pam_ssh_add8">pam_ssh_add(8)</a></li>
453 </ul>
454 </li>
455 <li><a href="#https">SSL/TLS Usage</a>
456 <ul class="sectlevel3">
457 <li><a href="#https-required">HTTPS Requirement</a></li>
458 <li><a href="#https-certificates">Certificates</a></li>
459 </ul>
460 </li>
461 <li><a href="#listen">TCP Port and Address</a>
462 <ul class="sectlevel3">
463 <li><a href="#listen-systemd">Cockpit systemd Socket</a></li>
464 <li><a href="#listen-selinux">SELinux Port</a></li>
465 <li><a href="#listen-firewalld">Firewalld Port</a></li>
466 </ul>
467 </li>
468 <li><a href="#startup">Start up</a>
469 <ul class="sectlevel3">
470 <li><a href="#startup-shutdown">Process exit</a></li>
471 <li><a href="#startup-boot">Boot start up</a></li>
472 </ul>
473 </li>
474 <li><a href="#multi-host">Managing multiple hosts at the same time</a></li>
475 <li><a href="#authentication">Cockpit Authentication</a>
476 <ul class="sectlevel3">
477 <li><a href="#initial-auth">Directly logging into the primary server</a></li>
478 <li><a href="#direct-secondary-auth">Directly logging into a secondary server without a primary session</a></li>
479 <li><a href="#secondary-auth">Logging into a secondary server from the primary session</a></li>
480 </ul>
481 </li>
482 <li><a href="#sso">Single Sign On</a>
483 <ul class="sectlevel3">
484 <li><a href="#sso-server">Server Requirements</a></li>
485 <li><a href="#sso-client">Client Requirements</a></li>
486 </ul>
487 </li>
488 <li><a href="#cert-authentication">Certificate/smart card authentication</a>
489 <ul class="sectlevel3">
490 <li><a href="#certauth-server-cert-generation">User certificate generation</a></li>
491 <li><a href="#certauth-server-ipa">Certificate mapping with FreeIPA</a></li>
492 <li><a href="#certauth-server-ms-ad">Certificate mapping with Microsoft Active Directory</a></li>
493 <li><a href="#certauth-server-samba-ad">Certificate mapping with Samba Active Directory</a></li>
494 <li><a href="#certauth-server-cockpitconf">Cockpit web server configuration</a></li>
495 <li><a href="#certauth-server-resourcelimits">Cockpit web server resource limits</a></li>
496 <li><a href="#certauth-forwarding">Authentication to other services like sudo and ssh</a></li>
497 </ul>
498 </li>
499 <li><a href="#privileges">Privileges and Permissions</a>
500 <ul class="sectlevel3">
501 <li><a href="#privileges-polkit">Customizing Polkit Privileges</a></li>
502 </ul>
503 </li>
504 </ul>
505 </li>
506 <li><a href="#features">Feature Internals</a>
507 <ul class="sectlevel2">
508 <li><a href="#feature-systemd">systemd</a></li>
509 <li><a href="#feature-journal">Journal</a></li>
510 <li><a href="#feature-networkmanager">NetworkManager</a></li>
511 <li><a href="#feature-firewall">Firewall</a></li>
512 <li><a href="#feature-storaged">storaged</a></li>
513 <li><a href="#feature-users">User Tools</a></li>
514 <li><a href="#feature-realmd">realmd</a></li>
515 <li><a href="#feature-terminal">Terminal</a></li>
516 <li><a href="#feature-pcp">PCP Metrics</a></li>
517 <li><a href="#feature-machines">Multiple Machines</a></li>
518 <li><a href="#feature-selinux">SELinux Policy</a></li>
519 <li><a href="#feature-tuned">Tuned Profiles</a></li>
520 <li><a href="#feature-sosreport">SOS Report</a></li>
521 <li><a href="#feature-packagekit">Package Updates</a></li>
522 </ul>
523 </li>
524 <li><a href="#development">Developer Guide</a>
525 <ul class="sectlevel2">
526 <li><a href="#embedding">Embedding and Integrating Cockpit</a>
527 <ul class="sectlevel3">
528 <li><a href="#embedding-full">Embedding the Cockpit Interface</a></li>
529 <li><a href="#embedding-components">Integrating Cockpit Components into Web Applications</a></li>
530 <li><a href="#embedding-deep">Deep Integration</a></li>
531 <li><a href="#embedding-cors">Pinging Cockpit</a></li>
532 </ul>
533 </li>
534 <li><a href="#packages">Cockpit Packages</a>
535 <ul class="sectlevel3">
536 <li><a href="#package-layout">Layout of Package Files</a></li>
537 <li><a href="#_package_manifest">Package Manifest</a></li>
538 <li><a href="#package-manifest-override">Manifest overrides</a></li>
539 <li><a href="#package-links">Package Links and Paths</a></li>
540 <li><a href="#package-minified">Content Negotiation</a></li>
541 <li><a href="#package-api">Using Cockpit API</a></li>
542 <li><a href="#package-bridges">Bridges for specific tasks</a></li>
543 <li><a href="#package-replace">Replacing an existing package</a></li>
544 </ul>
545 </li>
546 <li><a href="#urls">Cockpit URLs</a>
547 <ul class="sectlevel3">
548 <li><a href="#urls-components">Component URLs</a></li>
549 <li><a href="#urls-visible">Visible URLs</a></li>
550 </ul>
551 </li>
552 <li><a href="#_api_base1">API: base1</a>
553 <ul class="sectlevel3">
554 <li><a href="#_cockpit_js">cockpit.js</a></li>
555 <li><a href="#_cockpit_js_object_caching">cockpit.js: Object Caching</a></li>
556 <li><a href="#_cockpit_js_raw_channels">cockpit.js: Raw Channels</a></li>
557 <li><a href="#_cockpit_js_dbus_client">cockpit.js: DBus Client</a></li>
558 <li><a href="#_cockpit_js_errors">cockpit.js: Errors</a></li>
559 <li><a href="#_cockpit_js_file_access">cockpit.js: File Access</a></li>
560 <li><a href="#_cockpit_js_http_client">cockpit.js: HTTP Client</a></li>
561 <li><a href="#_cockpit_js_localization">cockpit.js: Localization</a></li>
562 <li><a href="#_cockpit_js_page_location_and_jumping">cockpit.js: Page Location and Jumping</a></li>
563 <li><a href="#_cockpit_js_user_session">cockpit.js: User Session</a></li>
564 <li><a href="#_cockpit_js_manifests">cockpit.js: Manifests</a></li>
565 <li><a href="#_cockpit_js_metrics">cockpit.js: Metrics</a></li>
566 <li><a href="#_cockpit_js_series_data">cockpit.js: Series Data</a></li>
567 <li><a href="#_cockpit_js_spawning_processes">cockpit.js: Spawning Processes</a></li>
568 <li><a href="#_cockpit_js_utilities">cockpit.js: Utilities</a></li>
569 </ul>
570 </li>
571 <li><a href="#_api_shell">API: shell</a>
572 <ul class="sectlevel3">
573 <li><a href="#_index_html">index.html</a></li>
574 </ul>
575 </li>
576 <li><a href="#_api_system">API: system</a>
577 <ul class="sectlevel3">
578 <li><a href="#_logs_html">logs.html</a></li>
579 <li><a href="#_terminal_html">terminal.html</a></li>
580 </ul>
581 </li>
582 </ul>
583 </li>
584 </ul>
585 </div>
586 </div>
587 <div id="content">
588 <div class="sect1">
589 <h2 id="guide">Deployment Guide</h2>
590 <div class="sectionbody">
591 <div class="paragraph">
592 <p>Documentation for Cockpit 368.</p>
593 </div>
594 <div class="paragraph">
595 <p>Latest version <a href="https://docs.cockpit-project.org/">available here</a>.</p>
596 </div>
597 <div class="sect2">
598 <h3 id="cockpit-manual">Manual pages</h3>
599 <div class="sect3">
600 <h4 id="_cockpit1">cockpit(1)</h4>
601 <div class="sect4">
602 <h5 id="_name">Name</h5>
603 <div class="paragraph">
604 <p>cockpit - Cockpit</p>
605 </div>
606 </div>
607 <div class="sect4">
608 <h5 id="_description">Description</h5>
609 <div class="paragraph">
610 <p>Cockpit is a web accessible interactive admin interface for Linux
611 machines. Cockpit can usually be accessed on port <code>9090</code> of the
612 machine it&#8217;s installed on. Cockpit starts on demand. Use your system
613 credentials to log in.</p>
614 </div>
615 </div>
616 <div class="sect4">
617 <h5 id="_components">Components</h5>
618 <div class="paragraph">
619 <p>The <strong>cockpit-ws</strong> web service listens on port <code>9090</code> and is started
620 on demand by <strong>systemd</strong>. The Cockpit web service authenticates the
621 user, loads Cockpit into the browser, and starts <strong>cockpit-bridge</strong> in a
622 Linux user session.</p>
623 </div>
624 <div class="paragraph">
625 <p>The <strong>cockpit-bridge</strong> provides Cockpit in the web browser with access
626 to the system APIs. It does this over its standard in and standard out.
627 The bridge is started like a shell once per Linux user session.</p>
628 </div>
629 </div>
630 <div class="sect4">
631 <h5 id="_bugs">Bugs</h5>
632 <div class="paragraph">
633 <p>Please send bug reports to either the distribution bug tracker or the <a href="https://github.com/cockpit-project/cockpit/issues/new">upstream bug tracker</a>.</p>
634 </div>
635 </div>
636 <div class="sect4">
637 <h5 id="_author">Author</h5>
638 <div class="paragraph">
639 <p>Cockpit has been written by many
640 <a href="https://github.com/cockpit-project/cockpit">contributors</a>.</p>
641 </div>
642 </div>
643 <div class="sect4">
644 <h5 id="_see_also">See also</h5>
645 <div class="paragraph">
646 <p><a href="cockpit-tls.8.html">cockpit-tls</a>(8) , <a href="cockpit-bridge.1.html">cockpit-bridge</a>(1) , systemd(1), <strong><a href="https://docs.cockpit-project.org/cockpit-guide/latest">Cockpit guide</a></strong></p>
647 </div>
648 </div>
649 </div>
650 <div class="sect3">
651 <h4 id="_cockpit_conf5">cockpit.conf(5)</h4>
652 <div class="sect4">
653 <h5 id="_name_2">Name</h5>
654 <div class="paragraph">
655 <p>cockpit.conf - Cockpit configuration file</p>
656 </div>
657 </div>
658 <div class="sect4">
659 <h5 id="_description_2">Description</h5>
660 <div class="paragraph">
661 <p>Cockpit can be configured via /etc/cockpit/cockpit.conf. If
662 <strong>$XDG_CONFIG_DIRS</strong> is set, then the first path containing a
663 <strong>../cockpit/cockpit.conf</strong> is used instead. Other configuration files
664 and directories are searched for in the same way.</p>
665 </div>
666 <div class="paragraph">
667 <p>This file is not required and may need to be created manually. The file
668 has a INI file syntax and thus contains key / value pairs, grouped into
669 topical groups. See the examples below for details.</p>
670 </div>
671 <div class="paragraph">
672 <p>Note: The port that cockpit listens on cannot be changed in this file.
673 To change the port change the systemd <strong>cockpit.socket</strong> file.</p>
674 </div>
675 </div>
676 <div class="sect4">
677 <h5 id="_webservice">WebService</h5>
678 <div class="dlist">
679 <dl>
680 <dt class="hdlist1"><strong>Origins</strong></dt>
681 <dd>
682 <p>By default cockpit will not accept crossdomain websocket connections.
683 Use this setting to allow access from alternate domains. Origins
684 should include scheme, host and port, if necessary. Wildcards and glob
685 expressions are permitted. IPv6 addresses must have their brackets escaped
686 with backslashes (e.g. <code>\[::1\]</code>) as they are matched using <code>fnmatch()</code>.
687 <br></p>
688 </dd>
689 </dl>
690 </div>
691 <div class="listingblock">
692 <div class="content">
693 <pre class="highlight"><code class="language-ini" data-lang="ini">[WebService]
694 Origins = https://somedomain1.com https://somedomain2.com:9090 https://*.somedomain3.com https://\[::1\]:9090</code></pre>
695 </div>
696 </div>
697 <div class="dlist">
698 <dl>
699 <dt class="hdlist1"><strong>ProtocolHeader</strong></dt>
700 <dd>
701 <p>Configure cockpit to look at the contents of this header to determine
702 if a connection is using tls. This should only be used when cockpit is
703 behind a reverse proxy, and care should be taken to make sure that
704 incoming requests cannot set this header.
705 <br></p>
706 </dd>
707 </dl>
708 </div>
709 <div class="listingblock">
710 <div class="content">
711 <pre class="highlight"><code class="language-ini" data-lang="ini">[WebService]
712 ProtocolHeader = X-Forwarded-Proto</code></pre>
713 </div>
714 </div>
715 <div class="dlist">
716 <dl>
717 <dt class="hdlist1"><strong>ForwardedForHeader</strong></dt>
718 <dd>
719 <p>Configure cockpit to look at the contents of this header to determine
720 the real origin of a connection. This should only be used when cockpit
721 is behind a reverse proxy, and care should be taken to make sure that
722 incoming requests cannot set this header.
723 <br></p>
724 </dd>
725 </dl>
726 </div>
727 <div class="listingblock">
728 <div class="content">
729 <pre class="highlight"><code class="language-ini" data-lang="ini">[WebService]
730 ForwardedForHeader = X-Forwarded-For</code></pre>
731 </div>
732 </div>
733 <div class="dlist">
734 <dl>
735 <dt class="hdlist1"><strong>LoginTitle</strong></dt>
736 <dd>
737 <p>Set the browser title for the login screen.</p>
738 </dd>
739 <dt class="hdlist1"><strong>LoginTo</strong></dt>
740 <dd>
741 <p>When set to <code>true</code> the <em>Connect to</em> option on the login screen is
742 visible and allows logging into another server. When set to <code>false</code>,
743 direct remote logins are disallowed. If this option is not specified
744 then it will be automatically detected based on whether the
745 <strong>cockpit-bridge</strong> package is installed and the <strong>ssh</strong> program is
746 available.<br>
747 <br>
748 If cockpit-ws is exposed to the public internet, and also has access
749 to a private internal network, it is recommended to explicitly set
750 <strong>LoginTo=false</strong>. This prevents unauthenticated remote attackers from
751 scanning the internal network for existing machines and open ports.</p>
752 </dd>
753 <dt class="hdlist1"><strong>RequireHost</strong></dt>
754 <dd>
755 <p>When set to <code>true</code> cockpit will require users to use the <em>Connect
756 to</em> option to specify the host to log into.</p>
757 </dd>
758 <dt class="hdlist1"><strong>AllowMultiHost</strong></dt>
759 <dd>
760 <p>When set to <code>true</code>, cockpit will allow users to connect to multiple
761 hosts in one session. The default is OS specific.<br>
762 <br>
763 When connecting to multiple servers, JavaScript runs without
764 isolation. All systems will be vulnerable to potential attacks from
765 other connected hosts. Enable this option <em>only</em> when all hosts are
766 trusted.</p>
767 </dd>
768 <dt class="hdlist1"><strong>MaxStartups</strong></dt>
769 <dd>
770 <p>Same as the <strong>sshd</strong> configuration option by the same name. Specifies
771 the maximum number of concurrent login attempts allowed. Additional
772 connections will be dropped until authentication succeeds or the
773 connections are closed. Defaults to 10.<br>
774 <br>
775 Alternatively, random early drop can be enabled by specifying the
776 three colon separated values <strong>start:rate:full</strong> (e.g. "10:30:60").
777 Cockpit will start refusing authentication attempts with a probability
778 of <strong>rate/100</strong> (30%) if there are currently <strong>start</strong> (10)
779 unauthenticated connections. The probability increases linearly and
780 all connection attempts are refused if the number of unauthenticated
781 connections reaches <strong>full</strong> (60).</p>
782 </dd>
783 <dt class="hdlist1"><strong>MaxConcurrentConnections</strong></dt>
784 <dd>
785 <p>Limits the number of concurrent HTTP connections on the Cockpit port.
786 Connection attempts that exceed this limit are rejected early on
787 without reading a single byte. This can be used during brute-force
788 attacks. It differs from <strong>MaxStartups</strong>, which protects against too
789 many concurrent authentication attempts. Defaults to 500.</p>
790 </dd>
791 <dt class="hdlist1"><strong>AllowUnencrypted</strong></dt>
792 <dd>
793 <p>If true, cockpit will accept unencrypted HTTP connections. Otherwise,
794 it redirects all HTTP connections to HTTPS. Exceptions are connections
795 from localhost and for certain URLs (like <strong>/ping</strong>). Defaults to
796 false.</p>
797 </dd>
798 <dt class="hdlist1"><strong>UrlRoot</strong></dt>
799 <dd>
800 <p>The root URL where you will be serving cockpit. When provided cockpit
801 will expect all requests to be prefixed with the given url. This is
802 mostly useful when you are using cockpit behind a reverse proxy, such
803 as nginx. <code>/cockpit/</code> and <code>/cockpit+</code> are reserved and should not
804 be used. For example <code>/cockpit-new/</code> is ok. <code>/cockpit/</code> and
805 <code>/cockpit+new/</code> are not.</p>
806 </dd>
807 <dt class="hdlist1"><strong>ClientCertAuthentication</strong></dt>
808 <dd>
809 <p>If true, enable TLS client certificates for authenticating users.
810 Commonly these are provided by a smart card, but it&#8217;s equally possible
811 to import certificates directly into the web browser. Please see the
812 <a href="https://docs.cockpit-project.org/cockpit-guide/latest/guide/cert-authentication.html">Certificate/smart
813 card authentication</a> section in the Cockpit guide for details.</p>
814 </dd>
815 <dt class="hdlist1"><strong>Shell</strong></dt>
816 <dd>
817 <p>The relative URL to top level component to display in Cockpit once
818 logged in. Defaults to <code>/shell/index.html</code></p>
819 </dd>
820 <dt class="hdlist1"><strong>CustomLoginPage</strong></dt>
821 <dd>
822 <p>Load the login page from an alternative directory. The directory must
823 contain a <code>login.html</code> and optionally a <code>po.js</code> file for translations.
824 When not set, the hardcoded <code>$prefix/share/cockpit/static</code> directory is used.</p>
825 </dd>
826 </dl>
827 </div>
828 </div>
829 <div class="sect4">
830 <h5 id="_log">Log</h5>
831 <div class="dlist">
832 <dl>
833 <dt class="hdlist1"><strong>Fatal</strong></dt>
834 <dd>
835 <p>The kind of log messages in the bridge to treat as fatal. Separate
836 multiple values with spaces. Relevant values are: <strong>criticals</strong> and
837 <strong>warnings</strong>.</p>
838 </dd>
839 </dl>
840 </div>
841 </div>
842 <div class="sect4">
843 <h5 id="_oauth">OAuth</h5>
844 <div class="paragraph">
845 <p>Cockpit can be configured to support the
846 <a href="https://tools.ietf.org/html/rfc6749#section-4.2">implicit grant</a> OAuth
847 authorization flow. When successful the resulting oauth token will be
848 passed to cockpit-ws using the <strong>Bearer</strong> auth-scheme. For a login to be
849 successful, cockpit will also need a to be configured to verify and
850 allow <strong>Bearer</strong> tokens.</p>
851 </div>
852 <div class="dlist">
853 <dl>
854 <dt class="hdlist1"><strong>URL</strong></dt>
855 <dd>
856 <p>This is the url that cockpit will redirect the users browser to when
857 it needs to obtain an oauth token. Cockpit will add a redirect_uri
858 parameter to the url with the location of where the oauth provider
859 should redirect to once a token has been obtained.</p>
860 </dd>
861 <dt class="hdlist1"><strong>ErrorParam</strong></dt>
862 <dd>
863 <p>When a oauth provider redirects a user back to cockpit, look for this
864 parameter in the querystring or fragment portion of the url to find a
865 error message. When not provided it will default to
866 <strong>error_description</strong></p>
867 </dd>
868 <dt class="hdlist1"><strong>TokenParam</strong></dt>
869 <dd>
870 <p>When a oauth provider redirects a user back to cockpit, look for this
871 parameter in the querystring or fragment portion of the url to find
872 the access token. When not provided it will default to
873 <strong>access_token</strong></p>
874 </dd>
875 </dl>
876 </div>
877 </div>
878 <div class="sect4">
879 <h5 id="_session">Session</h5>
880 <div class="dlist">
881 <dl>
882 <dt class="hdlist1"><strong>Banner</strong></dt>
883 <dd>
884 <p>The contents of the specified file (commonly <strong>/etc/issue</strong>) are shown
885 on the login page. By default, no banner is displayed.</p>
886 </dd>
887 <dt class="hdlist1"><strong>IdleTimeout</strong></dt>
888 <dd>
889 <p>Time in minutes after which session expires and user is logged out if
890 no user action has been performed in the given time. This idle timeout
891 only applies to interactive password logins. With non-interactive
892 authentication methods like Kerberos, OAuth, or certificate login, the
893 browser cannot forget credentials, and thus automatic logouts are not
894 useful for protecting credentials of forgotten sessions. Set to <strong>0</strong>
895 to disable session timeout.
896 <br></p>
897 </dd>
898 </dl>
899 </div>
900 <div class="listingblock">
901 <div class="content">
902 <pre class="highlight"><code class="language-ini" data-lang="ini">[Session]
903 IdleTimeout=15</code></pre>
904 </div>
905 </div>
906 <div class="dlist">
907 <dl>
908 <dt class="hdlist1"></dt>
909 <dd>
910 <p>When not specified, there is no idle timeout by default.</p>
911 </dd>
912 <dt class="hdlist1"><strong>WarnBeforeConnecting</strong></dt>
913 <dd>
914 <p>Whether to warn before connecting to remote hosts from the Shell.
915 Defaults to true.
916 <br></p>
917 </dd>
918 </dl>
919 </div>
920 <div class="listingblock">
921 <div class="content">
922 <pre class="highlight"><code class="language-ini" data-lang="ini">[Session]
923 WarnBeforeConnecting=false</code></pre>
924 </div>
925 </div>
926 </div>
927 <div class="sect4">
928 <h5 id="_bugs_2">Bugs</h5>
929 <div class="paragraph">
930 <p>Please send bug reports to either the distribution bug tracker or the <a href="https://github.com/cockpit-project/cockpit/issues/new">upstream bug tracker</a>.</p>
931 </div>
932 </div>
933 <div class="sect4">
934 <h5 id="_author_2">Author</h5>
935 <div class="paragraph">
936 <p>Cockpit has been written by many
937 <a href="https://github.com/cockpit-project/cockpit">contributors</a>.</p>
938 </div>
939 </div>
940 <div class="sect4">
941 <h5 id="_see_also_2">See also</h5>
942 <div class="paragraph">
943 <p><a href="cockpit-ws.8.html">cockpit-ws</a>(8), <a href="cockpit-tls.8.html">cockpit-tls</a>(8)</p>
944 </div>
945 </div>
946 </div>
947 <div class="sect3">
948 <h4 id="_cockpit_ws8">cockpit-ws(8)</h4>
949 <div class="sect4">
950 <h5 id="_name_3">Name</h5>
951 <div class="paragraph">
952 <p>cockpit-ws - Cockpit web service</p>
953 </div>
954 </div>
955 <div class="sect4">
956 <h5 id="_synopsis">Synopsis</h5>
957 <div class="paragraph">
958 <p><strong>cockpit-ws</strong> [<strong>--help</strong>] [<strong>--port</strong> <em>PORT</em>] [<strong>--address</strong> <em>ADDRESS</em>] [<strong>--no-tls</strong>]
959 [<strong>--for-tls-proxy</strong>] [<strong>--local-ssh</strong>] [<strong>--local-session</strong> <em>BRIDGE</em>]</p>
960 </div>
961 </div>
962 <div class="sect4">
963 <h5 id="_description_3">Description</h5>
964 <div class="paragraph">
965 <p>The <strong>cockpit-ws</strong> program is the web service component used for
966 communication between the browser application and various configuration
967 tools and services like <a href="cockpit-bridge.1.html">cockpit-bridge</a>(1).</p>
968 </div>
969 <div class="paragraph">
970 <p>Users or administrators should never need to start this program as it
971 automatically started by systemd(1) on boot up, through
972 <a href="cockpit-tls.8.html">cockpit-tls</a>(8).</p>
973 </div>
974 </div>
975 <div class="sect4">
976 <h5 id="_transport_security">Transport security</h5>
977 <div class="paragraph">
978 <p><strong>cockpit-ws</strong> is normally run behind the <strong>cockpit-tls</strong> TLS
979 terminating proxy, and only deals with unencrypted HTTP by itself. But
980 for backwards compatibility it can also handle TLS connections by itself
981 when being run directly. For details how to configure certificates,
982 please refer to the <a href="cockpit-tls.8.html">cockpit-tls</a>(8) documentation.</p>
983 </div>
984 </div>
985 <div class="sect4">
986 <h5 id="_timeout">Timeout</h5>
987 <div class="paragraph">
988 <p>When started via systemd(1) then <strong>cockpit-ws</strong> will exit after 90
989 seconds if nobody logs in, or after the last user is disconnected.</p>
990 </div>
991 </div>
992 <div class="sect4">
993 <h5 id="_options">Options</h5>
994 <div class="dlist">
995 <dl>
996 <dt class="hdlist1"><strong>--help</strong></dt>
997 <dd>
998 <p>Show help options.</p>
999 </dd>
1000 <dt class="hdlist1"><strong>--port</strong> <em>PORT</em></dt>
1001 <dd>
1002 <p>Serve HTTP requests <em>PORT</em> instead of port <strong>9090</strong>. Usually Cockpit is
1003 started on demand by <strong>systemd</strong> socket activation, and this option
1004 has no effect. Update the <strong>ListenStream</strong> directive
1005 <strong>cockpit.socket</strong> file in the usual <strong>systemd</strong> manner.</p>
1006 </dd>
1007 <dt class="hdlist1"><strong>--address</strong> <em>ADDRESS</em></dt>
1008 <dd>
1009 <p>Bind to address <em>ADDRESS</em> instead of binding to all available
1010 addresses. Usually Cockpit is started on demand by <strong>systemd</strong> socket
1011 activation, and this option has no effect. In that case, update the
1012 <strong>ListenStream</strong> directive in the <strong>cockpit.socket</strong> file in the usual
1013 <strong>systemd</strong> manner.</p>
1014 </dd>
1015 <dt class="hdlist1"><strong>--no-tls</strong></dt>
1016 <dd>
1017 <p>Disable http to https redirection.</p>
1018 </dd>
1019 <dt class="hdlist1"><strong>--for-tls-proxy</strong></dt>
1020 <dd>
1021 <p>Tell <strong>cockpit-ws</strong> that it is running behind a local reverse proxy
1022 that does the TLS termination. Then Cockpit puts https:// URLs into
1023 the default <strong>Content-Security-Policy</strong>, and accepts only https://
1024 origins, instead of http: ones by default. However, if <strong>Origins</strong> is
1025 set in the <a href="cockpit.conf.5.html">cockpit.conf</a>(5) configuration file, it will override
1026 this default.</p>
1027 </dd>
1028 <dt class="hdlist1"><strong>--local-ssh</strong></dt>
1029 <dd>
1030 <p>Normally <strong>cockpit-ws</strong> uses <strong>cockpit-session</strong> and PAM to
1031 authenticate the user and start a user session. With this option
1032 enabled, it will instead authenticate via SSH at <strong>127.0.0.1</strong> port
1033 <strong>22</strong>.</p>
1034 </dd>
1035 <dt class="hdlist1"><strong>--local-session</strong> <em>BRIDGE</em></dt>
1036 <dd>
1037 <p>Skip all authentication and <strong>cockpit-session</strong>, and launch the
1038 <strong>cockpit-bridge</strong> specified in <em>BRIDGE</em> in the local session. If the
1039 <em>BRIDGE</em> is specified as <code>-</code> then expect an already running bridge
1040 that is connected to stdin and stdout of this <strong>cockpit-ws</strong> process.
1041 This allows the web server to run as any unprivileged user in an
1042 already running session.<br>
1043 <br>
1044 This mode implies <strong>--no-tls</strong>, thus you need to use http:// URLs with
1045 this.</p>
1046 </dd>
1047 </dl>
1048 </div>
1049 <div class="admonitionblock warning">
1050 <table>
1051 <tr>
1052 <td class="icon">
1053 <div class="title">Warning</div>
1054 </td>
1055 <td class="content">
1056 <div class="paragraph">
1057 <p>With <strong>--local-session</strong> <em>BRIDGE</em>, you <em>have to isolate the opened TCP port</em> somehow
1058 (for example in a network namespace), otherwise all other users (or
1059 even remote machines if the port is not just listening on localhost)
1060 can access the session!</p>
1061 </div>
1062 </td>
1063 </tr>
1064 </table>
1065 </div>
1066 </div>
1067 <div class="sect4">
1068 <h5 id="_environment">Environment</h5>
1069 <div class="paragraph">
1070 <p>The <strong>cockpit-ws</strong> process will use the <strong>XDG_CONFIG_DIRS</strong> environment
1071 variable from the
1072 <a href="https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG
1073 basedir spec</a> to find its <a href="cockpit.conf.5.html">cockpit.conf</a>(5) configuration file.</p>
1074 </div>
1075 <div class="paragraph">
1076 <p>In addition the <strong>XDG_DATA_DIRS</strong> environment variable from the
1077 <a href="https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG
1078 basedir spec</a> can be used to override the location to serve static files
1079 from. These are the files that are served to a non-logged in user.</p>
1080 </div>
1081 </div>
1082 <div class="sect4">
1083 <h5 id="_bugs_3">Bugs</h5>
1084 <div class="paragraph">
1085 <p>Please send bug reports to either the distribution bug tracker or the <a href="https://github.com/cockpit-project/cockpit/issues/new">upstream bug tracker</a>.</p>
1086 </div>
1087 </div>
1088 <div class="sect4">
1089 <h5 id="_author_3">Author</h5>
1090 <div class="paragraph">
1091 <p>Cockpit has been written by many
1092 <a href="https://github.com/cockpit-project/cockpit">contributors</a>.</p>
1093 </div>
1094 </div>
1095 <div class="sect4">
1096 <h5 id="_see_also_3">See also</h5>
1097 <div class="paragraph">
1098 <p><a href="cockpit-tls.8.html">cockpit-tls</a>(8) , <a href="cockpit.conf.5.html">cockpit.conf</a>(5) , systemd(1)</p>
1099 </div>
1100 </div>
1101 </div>
1102 <div class="sect3">
1103 <h4 id="_cockpit_tls8">cockpit-tls(8)</h4>
1104 <div class="sect4">
1105 <h5 id="_name_4">Name</h5>
1106 <div class="paragraph">
1107 <p>cockpit-tls - TLS proxy for Cockpit web service</p>
1108 </div>
1109 </div>
1110 <div class="sect4">
1111 <h5 id="_synopsis_2">Synopsis</h5>
1112 <div class="paragraph">
1113 <p><strong>cockpit-tls</strong> [<strong>--help</strong>] [<strong>--port</strong> <em>PORT</em>] [<strong>--no-tls</strong>] [<strong>--idle-timeout</strong> <em>SECONDS</em>]</p>
1114 </div>
1115 </div>
1116 <div class="sect4">
1117 <h5 id="_description_4">Description</h5>
1118 <div class="paragraph">
1119 <p>The <strong>cockpit-tls</strong> program is a TLS terminating HTTP proxy for
1120 <a href="cockpit-ws.8.html">cockpit-ws</a>(8). It manages a set of isolated cockpit-ws instances,
1121 one per TLS client certificate, plus one for TLS without a client
1122 certificate, and one for unencrypted HTTP. With that, one session cannot
1123 tamper with another one through possible security vulnerability
1124 exploits.</p>
1125 </div>
1126 <div class="paragraph">
1127 <p>Users or administrators should never need to start this program as it
1128 automatically started by systemd(1) via socket activation.</p>
1129 </div>
1130 </div>
1131 <div class="sect4">
1132 <h5 id="_transport_security_2">Transport security</h5>
1133 <div class="paragraph">
1134 <p>To specify the TLS certificate the web service should use, simply drop a
1135 file with the extension <strong>.cert</strong> in the <strong>/etc/cockpit/ws-certs.d</strong>
1136 directory, or below <strong>$XDG_CONFIG_DIRS</strong> if set (see
1137 <a href="cockpit.conf.5.html">cockpit.conf</a>(5)). If there are multiple files
1138 in this directory, then the highest priority one is chosen after
1139 sorting.</p>
1140 </div>
1141 <div class="paragraph">
1142 <p>The <strong>.cert</strong> file should contain at least two OpenSSL style PEM blocks.
1143 First one or more <code>BEGIN CERTIFICATE</code> blocks for the server
1144 certificate and intermediate certificate authorities and a second one
1145 containing a <code>BEGIN PRIVATE KEY</code> or similar. The key must not be
1146 encrypted.</p>
1147 </div>
1148 <div class="paragraph">
1149 <p>If there is no TLS certificate, a self-signed certificate is
1150 automatically generated using <strong>sscg</strong> (if available) or <strong>openssl</strong> and
1151 stored in the <strong>0-self-signed.cert</strong> file.</p>
1152 </div>
1153 <div class="paragraph">
1154 <p>When enrolling into a FreeIPA domain, an SSL certificate is requested
1155 from the IPA server and stored in <strong>10-ipa.cert</strong>.</p>
1156 </div>
1157 <div class="paragraph">
1158 <p>To check which certificate <strong>cockpit-ws</strong> will use, run the following
1159 command.</p>
1160 </div>
1161 <div class="literalblock">
1162 <div class="content">
1163 <pre>$ sudo /usr/libexec/cockpit-certificate-ensure --check</pre>
1164 </div>
1165 </div>
1166 <div class="paragraph">
1167 <p>Or, on Debian-based systems:</p>
1168 </div>
1169 <div class="literalblock">
1170 <div class="content">
1171 <pre>$ sudo /usr/lib/cockpit/cockpit-certificate-ensure --check</pre>
1172 </div>
1173 </div>
1174 <div class="paragraph">
1175 <p>If using <strong>certmonger</strong> to manage certificates, following command can be
1176 used to generate a certificate/key pair:</p>
1177 </div>
1178 <div class="literalblock">
1179 <div class="content">
1180 <pre>CERT_FILE=/etc/cockpit/ws-certs.d/50-certmonger.crt
1181 KEY_FILE=/etc/cockpit/ws-certs.d/50-certmonger.key
1182
1183 getcert request -f ${CERT_FILE} -k ${KEY_FILE} -D $(hostname --fqdn)</pre>
1184 </div>
1185 </div>
1186 </div>
1187 <div class="sect4">
1188 <h5 id="_options_2">Options</h5>
1189 <div class="dlist">
1190 <dl>
1191 <dt class="hdlist1"><strong>--help</strong></dt>
1192 <dd>
1193 <p>Show help options.</p>
1194 </dd>
1195 <dt class="hdlist1"><strong>--port</strong> <em>PORT</em></dt>
1196 <dd>
1197 <p>Serve HTTP requests on <em>PORT</em> instead of port 9090. Usually Cockpit is
1198 started on demand by <strong>systemd</strong> socket activation, and this option
1199 has no effect. Update the <strong>ListenStream</strong> directive
1200 <strong>cockpit.socket</strong> file in the usual <strong>systemd</strong> manner.</p>
1201 </dd>
1202 <dt class="hdlist1"><strong>--no-tls</strong></dt>
1203 <dd>
1204 <p>Don&#8217;t use TLS. Certificates will not be read, and https connections
1205 denied. Then <strong>cockpit-tls</strong> will only manage a single cockpit-ws
1206 instance, and thus not do anything different than running
1207 <strong>cockpit-ws --no-tls</strong> directly. Only use this for debugging or
1208 testing.</p>
1209 </dd>
1210 <dt class="hdlist1"><strong>--idle-timeout</strong> <em>SECONDS</em></dt>
1211 <dd>
1212 <p>If greater than 0, exit if no connections have happened for the given
1213 number of seconds, i. e. the server is idle. If not given, the default
1214 is 90.</p>
1215 </dd>
1216 </dl>
1217 </div>
1218 </div>
1219 <div class="sect4">
1220 <h5 id="_environment_2">Environment</h5>
1221 <div class="paragraph">
1222 <p>The <strong>cockpit-tls</strong> program expects the <strong>RUNTIME_DIRECTORY</strong>
1223 environment variable to be set to an empty directory (preferably in
1224 <strong>/run/</strong>) that is only accessible by the system user under which it is
1225 running. This contains the Unix sockets for communicating with the
1226 <strong>cockpit-ws</strong> instances, and in the future, state information about
1227 client certificates. This variable is normally set by the
1228 <strong>cockpit.service</strong> systemd unit.</p>
1229 </div>
1230 <div class="paragraph">
1231 <p>In addition, <strong>cockpit-tls</strong> will use the <strong>XDG_CONFIG_DIRS</strong>
1232 environment variable from the
1233 <a href="https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG
1234 basedir spec</a> to find its certificates and the <a href="cockpit.conf.5.html">cockpit.conf</a>(5)
1235 configuration file.</p>
1236 </div>
1237 </div>
1238 <div class="sect4">
1239 <h5 id="_bugs_4">Bugs</h5>
1240 <div class="paragraph">
1241 <p>Please send bug reports to either the distribution bug tracker or the <a href="https://github.com/cockpit-project/cockpit/issues/new">upstream bug tracker</a>.</p>
1242 </div>
1243 </div>
1244 <div class="sect4">
1245 <h5 id="_author_4">Author</h5>
1246 <div class="paragraph">
1247 <p>Cockpit has been written by many
1248 <a href="https://github.com/cockpit-project/cockpit">contributors</a>.</p>
1249 </div>
1250 </div>
1251 <div class="sect4">
1252 <h5 id="_see_also_4">See also</h5>
1253 <div class="paragraph">
1254 <p><a href="cockpit-ws.8.html">cockpit-ws</a>(8) , <a href="cockpit.conf.5.html">cockpit.conf</a>(5) , systemd(1)</p>
1255 </div>
1256 </div>
1257 </div>
1258 <div class="sect3">
1259 <h4 id="_cockpit_desktop1">cockpit-desktop(1)</h4>
1260 <div class="sect4">
1261 <h5 id="_name_5">Name</h5>
1262 <div class="paragraph">
1263 <p>cockpit-desktop - Cockpit Desktop integration</p>
1264 </div>
1265 </div>
1266 <div class="sect4">
1267 <h5 id="_synopsis_3">Synopsis</h5>
1268 <div class="paragraph">
1269 <p><strong>cockpit-desktop</strong> <em>URLPATH</em> [<em>SSH_HOST</em>]</p>
1270 </div>
1271 </div>
1272 <div class="sect4">
1273 <h5 id="_description_5">Description</h5>
1274 <div class="paragraph">
1275 <p>The <strong>cockpit-desktop</strong> program provides secure access to Cockpit pages
1276 in an already running desktop session. It starts a web server
1277 (<strong>cockpit-ws</strong>) and a web browser in an isolated network namespace, and
1278 a <a href="cockpit-bridge.1.html">cockpit-bridge</a>(1) in the running user session.</p>
1279 </div>
1280 <div class="paragraph">
1281 <p>This avoids having to log into Cockpit, and having to enable
1282 <strong>cockpit.socket</strong> system-wide. The network isolation ensures that no
1283 other user, and not even other processes in the user&#8217;s session, can
1284 access this local web server.</p>
1285 </div>
1286 <div class="paragraph">
1287 <p><strong>URLPATH</strong> is the Cockpit page to open, i. e. the path component of
1288 Cockpit URLs. It is highly recommended to only open a
1289 <a href="https://docs.cockpit-project.org/cockpit-guide/latest/guide/embedding.html">particular page frame</a>, not the entire Cockpit navigation and menu. For example, the
1290 path <code>/cockpit/@localhost/storage/index.html</code> will open the Storage
1291 page. It is also possible to give abbreviated forms of urls, such as
1292 &#8220;/storage&#8221; or &#8220;/network/firewall&#8221;.</p>
1293 </div>
1294 <div class="paragraph">
1295 <p><em>SSH_HOST</em> is an optional SSH remote host specification (<em>hostname</em>
1296 or <em>username@hostname</em>). If given, <strong>cockpit-bridge</strong> will be started
1297 on the remote host through <strong>ssh(1)</strong> instead, i. e. the Cockpit web
1298 browser will show that remote host. Note that this is more of an
1299 experimental/demo feature.</p>
1300 </div>
1301 </div>
1302 <div class="sect4">
1303 <h5 id="_environment_3">Environment</h5>
1304 <div class="paragraph">
1305 <p>The <strong>BROWSER</strong> environment variable specifies the browser command (and
1306 possibly options) that will be used to open the requested Cockpit page.
1307 If not set, <strong>cockpit-desktop</strong> attempts to use an internal minimalistic
1308 WebKit browser, and failing that, will attempt to detect some reasonable
1309 alternatives.</p>
1310 </div>
1311 </div>
1312 <div class="sect4">
1313 <h5 id="_bugs_5">Bugs</h5>
1314 <div class="paragraph">
1315 <p>Please send bug reports to either the distribution bug tracker or the <a href="https://github.com/cockpit-project/cockpit/issues/new">upstream bug tracker</a>.</p>
1316 </div>
1317 </div>
1318 <div class="sect4">
1319 <h5 id="_author_5">Author</h5>
1320 <div class="paragraph">
1321 <p>Cockpit has been written by many
1322 <a href="https://github.com/cockpit-project/cockpit">contributors</a>.</p>
1323 </div>
1324 </div>
1325 <div class="sect4">
1326 <h5 id="_see_also_5">See also</h5>
1327 <div class="paragraph">
1328 <p><a href="cockpit-ws.8.html">cockpit-ws</a>(8), <a href="cockpit-bridge.1.html">cockpit-bridge</a>(1)</p>
1329 </div>
1330 </div>
1331 </div>
1332 <div class="sect3">
1333 <h4 id="_cockpit_bridge1">cockpit-bridge(1)</h4>
1334 <div class="sect4">
1335 <h5 id="_name_6">Name</h5>
1336 <div class="paragraph">
1337 <p>cockpit-bridge - Cockpit Host Bridge</p>
1338 </div>
1339 </div>
1340 <div class="sect4">
1341 <h5 id="_synopsis_4">Synopsis</h5>
1342 <div class="paragraph">
1343 <p><strong>cockpit-bridge</strong> [<strong>--help</strong>] [<strong>--packages</strong>]</p>
1344 </div>
1345 </div>
1346 <div class="sect4">
1347 <h5 id="_description_6">Description</h5>
1348 <div class="paragraph">
1349 <p>The <strong>cockpit-bridge</strong> program is used by Cockpit to relay messages and
1350 commands from the Web front end to the server. Among other things it
1351 relays DBus, and spawns processes on behalf of the Web user interface.</p>
1352 </div>
1353 <div class="paragraph">
1354 <p>This program is not routinely run by users or administrators. It is in
1355 the <strong>$PATH</strong> so that Cockpit can find it when connecting between hosts.
1356 However there are some diagnostics available when running from the
1357 command line.</p>
1358 </div>
1359 </div>
1360 <div class="sect4">
1361 <h5 id="_options_3">Options</h5>
1362 <div class="dlist">
1363 <dl>
1364 <dt class="hdlist1"><strong>--help</strong></dt>
1365 <dd>
1366 <p>Show help options.</p>
1367 </dd>
1368 <dt class="hdlist1"><strong>--interact</strong>=<em>boundary</em></dt>
1369 <dd>
1370 <p>Interact with the raw cockpit1 protocol. Useful for debugging and
1371 testing. Specify a <em>boundary</em> which should be on an empty line
1372 between messages.</p>
1373 </dd>
1374 <dt class="hdlist1"><strong>--packages</strong></dt>
1375 <dd>
1376 <p>List all available Cockpit packages and exit. Note this includes
1377 packages available to the user running this command.</p>
1378 </dd>
1379 <dt class="hdlist1"><strong>--version</strong></dt>
1380 <dd>
1381 <p>Show Cockpit version information.</p>
1382 </dd>
1383 </dl>
1384 </div>
1385 </div>
1386 <div class="sect4">
1387 <h5 id="_bugs_6">Bugs</h5>
1388 <div class="paragraph">
1389 <p>Please send bug reports to either the distribution bug tracker or the <a href="https://github.com/cockpit-project/cockpit/issues/new">upstream bug tracker</a>.</p>
1390 </div>
1391 </div>
1392 <div class="sect4">
1393 <h5 id="_author_6">Author</h5>
1394 <div class="paragraph">
1395 <p>Cockpit has been written by many
1396 <a href="https://github.com/cockpit-project/cockpit">contributors</a>.</p>
1397 </div>
1398 </div>
1399 <div class="sect4">
1400 <h5 id="_see_also_6">See also</h5>
1401 <div class="paragraph">
1402 <p><a href="cockpit-ws.8.html">cockpit-ws</a>(8)</p>
1403 </div>
1404 </div>
1405 </div>
1406 <div class="sect3">
1407 <h4 id="_pam_ssh_add8">pam_ssh_add(8)</h4>
1408 <div class="sect4">
1409 <h5 id="_name_7">Name</h5>
1410 <div class="paragraph">
1411 <p>pam_ssh_add - PAM module to auto load ssh keys into an agent</p>
1412 </div>
1413 </div>
1414 <div class="sect4">
1415 <h5 id="_description_7">Description</h5>
1416 <div class="paragraph">
1417 <p><strong>pam_ssh_add</strong> provides authentication and session modules that allow users
1418 to start their session with a running ssh-agent with as many ssh keys
1419 loaded as possible.</p>
1420 </div>
1421 <div class="paragraph">
1422 <p>If used, the authentication module simply stores the authentication
1423 token for later use by the session module. Because this module performs
1424 no actual authentication it returns PAM_CRED_INSUFFICIENT on success and
1425 should always be accompanied by an actual authentication module in your
1426 pam configuration.</p>
1427 </div>
1428 <div class="paragraph">
1429 <p>By default the session module will start a new ssh-agent and run
1430 ssh-add, loading any keys that exist in the default path for the newly
1431 logged in user. If any keys prompt for a password, and a authentication
1432 token was successfully stored, that token will be provided as the
1433 password.</p>
1434 </div>
1435 </div>
1436 <div class="sect4">
1437 <h5 id="_options_4">Options</h5>
1438 <div class="dlist">
1439 <dl>
1440 <dt class="hdlist1"><strong>debug</strong></dt>
1441 <dd>
1442 <p>This option will turn on debug logging to syslog.</p>
1443 </dd>
1444 </dl>
1445 </div>
1446 </div>
1447 <div class="sect4">
1448 <h5 id="_examples">Examples</h5>
1449 <div class="literalblock">
1450 <div class="content">
1451 <pre> auth required pam_unix.so
1452 auth optional pam_ssh_add.so
1453 session optional pam_ssh_add.so</pre>
1454 </div>
1455 </div>
1456 </div>
1457 <div class="sect4">
1458 <h5 id="_bugs_7">Bugs</h5>
1459 <div class="paragraph">
1460 <p>Please send bug reports to either the distribution bug tracker or the <a href="https://github.com/cockpit-project/cockpit/issues/new">upstream bug tracker</a>.</p>
1461 </div>
1462 </div>
1463 <div class="sect4">
1464 <h5 id="_author_7">Author</h5>
1465 <div class="paragraph">
1466 <p>Cockpit has been written by many
1467 <a href="https://github.com/cockpit-project/cockpit">contributors</a>.</p>
1468 </div>
1469 </div>
1470 </div>
1471 </div>
1472 <div class="sect2">
1473 <h3 id="https">SSL/TLS Usage</h3>
1474 <div class="paragraph">
1475 <p>Cockpit usually requires that web browsers communicate with it using
1476 HTTPS, for security reasons.</p>
1477 </div>
1478 <div class="sect3">
1479 <h4 id="https-required">HTTPS Requirement</h4>
1480 <div class="paragraph">
1481 <p>Cockpit listens for both HTTP and HTTPS connections on the same port, by
1482 default 9090. If an HTTP connection is made, Cockpit will redirect that
1483 connection to HTTPS. There are some exceptions:</p>
1484 </div>
1485 <div class="ulist">
1486 <ul>
1487 <li>
1488 <p>If an HTTP connection comes from <code>localhost</code> (<code>127.0.0.1</code> or
1489 <code>::1</code>, then Cockpit will allow communication without redirecting to
1490 HTTPS.</p>
1491 </li>
1492 <li>
1493 <p>Certain URLs, like <code>/ping</code> are not required to use HTTPS.</p>
1494 </li>
1495 </ul>
1496 </div>
1497 <div class="paragraph">
1498 <p>This behavior can be overridden by setting the <code>AllowUnencrypted</code>
1499 option in <code>cockpit.conf</code>.</p>
1500 </div>
1501 </div>
1502 <div class="sect3">
1503 <h4 id="https-certificates">Certificates</h4>
1504 <div class="paragraph">
1505 <p>Cockpit will load a certificate from the <code>/etc/cockpit/ws-certs.d</code>,
1506 directory, or below <code>$XDG_CONFIG_DIRS</code> if set (see
1507 <a href="./cockpit.conf.5.html">cockpit.conf</a>). It will use the last file
1508 with a <code>.cert</code> or <code>.crt</code> extension in alphabetical order. The file
1509 should contain one or more OpenSSL style <code>BEGIN CERTIFICATE</code> blocks
1510 for the server certificate and the intermediate certificate authorities.</p>
1511 </div>
1512 <div class="paragraph">
1513 <p>The private key must be contained in a separate file with the same name
1514 as the certificate, but with a <code>.key</code> suffix instead. The key must not
1515 be encrypted.</p>
1516 </div>
1517 <div class="paragraph">
1518 <p>If no certificate is found, a self-signed certificate is created and
1519 stored in the <code>0-self-signed.cert</code> file. On some platforms, Cockpit
1520 will also generate a ca.crt in that directory, which may be safely
1521 imported into client browsers.</p>
1522 </div>
1523 <div class="paragraph">
1524 <p>Cockpit will read the files as root, so they can have tight permissions.</p>
1525 </div>
1526 <div class="paragraph">
1527 <p>To check which certificate <code>cockpit-ws</code> will use run the following
1528 command.</p>
1529 </div>
1530 <div class="literalblock">
1531 <div class="content">
1532 <pre>$ sudo /usr/libexec/cockpit-certificate-ensure --check</pre>
1533 </div>
1534 </div>
1535 <div class="paragraph">
1536 <p>Or, on Debian-based systems:</p>
1537 </div>
1538 <div class="literalblock">
1539 <div class="content">
1540 <pre>$ sudo /usr/lib/cockpit/cockpit-certificate-ensure --check</pre>
1541 </div>
1542 </div>
1543 <div class="paragraph">
1544 <p>If using <code>certmonger</code> to manage certificates, following command can be
1545 used to automatically prepare a certificate/key file pair:</p>
1546 </div>
1547 <div class="literalblock">
1548 <div class="content">
1549 <pre>getcert request -f /etc/cockpit/ws-certs.d/50-certmonger.cert \
1550 -k /etc/cockpit/ws-certs.d/50-certmonger.key \
1551 -D myhostname.example.com \
1552 [--ca=...]</pre>
1553 </div>
1554 </div>
1555 <div class="paragraph">
1556 <p>This will not work on Red Hat Enterprise Linux 8 by default. Adjust the
1557 SELinux type of the certificate directory to <code>cert_t</code> to allow
1558 certmonger to write its certificates there:</p>
1559 </div>
1560 <div class="literalblock">
1561 <div class="content">
1562 <pre>semanage fcontext -a -t cert_t '/etc/cockpit/ws-certs\.d(/.*)?'
1563 restorecon -v /etc/cockpit/ws-certs.d</pre>
1564 </div>
1565 </div>
1566 </div>
1567 </div>
1568 <div class="sect2">
1569 <h3 id="listen">TCP Port and Address</h3>
1570 <div class="paragraph">
1571 <p>Cockpit&#8217;s <code>cockpit-ws</code> component is configured by default to accept
1572 connections on port <code>9090</code>. This is the port that is documented for a
1573 "Web-based System Manager" to listen on. It is also relatively
1574 memorable.</p>
1575 </div>
1576 <div class="paragraph">
1577 <p>However there are many reasons you may wish to change the default port.
1578 For example other software may use port <code>9090</code> or you may wish to
1579 setup Cockpit to listen on <code>443</code> instead. It is also possible to have
1580 Cockpit only listen on one specific IP address.</p>
1581 </div>
1582 <div class="paragraph">
1583 <p>Note that it is only required to have Cockpit listening on a TCP port on
1584 the server that you access with your web browser. If you add multiple
1585 servers with host switcher, Cockpit will connect to those servers via
1586 <code>ssh</code>.</p>
1587 </div>
1588 <div class="paragraph">
1589 <p>The systems that Cockpit runs on are typically locked down with
1590 firewalls, SELinux, so changing the default port is not as easy as
1591 editing a configuration file.</p>
1592 </div>
1593 <div class="sect3">
1594 <h4 id="listen-systemd">Cockpit systemd Socket</h4>
1595 <div class="paragraph">
1596 <p>On servers with
1597 <a href="https://www.freedesktop.org/wiki/Software/systemd/"><code>systemd</code></a> Cockpit
1598 starts on demand via socket activation. To change its port and/or
1599 address you should place the following content in the
1600 <code>/etc/systemd/system/cockpit.socket.d/listen.conf</code> file. Create the
1601 file and directories in that path which not already exist. The
1602 <code>ListenStream</code> option specifies the desired address and TCP port.</p>
1603 </div>
1604 <div class="literalblock">
1605 <div class="content">
1606 <pre>[Socket]
1607 ListenStream=
1608 ListenStream=443</pre>
1609 </div>
1610 </div>
1611 <div class="literalblock">
1612 <div class="content">
1613 <pre>[Socket]
1614 ListenStream=
1615 ListenStream=7777
1616 ListenStream=192.168.1.1:443
1617 FreeBind=yes</pre>
1618 </div>
1619 </div>
1620 <div class="admonitionblock note">
1621 <table>
1622 <tr>
1623 <td class="icon">
1624 <div class="title">Note</div>
1625 </td>
1626 <td class="content">
1627 The first line with an empty value is intentional. <code>systemd</code>
1628 allows multiple <code>Listen</code> directives to be declared in a single socket
1629 unit; an empty value in a drop-in file resets the list and thus disables
1630 the default port 9090 from the original unit.
1631 </td>
1632 </tr>
1633 </table>
1634 </div>
1635 <div class="paragraph">
1636 <p>The <code>FreeBind</code> option is highly recommended when defining specific IP
1637 addresses. See the
1638 <a href="https://www.freedesktop.org/software/systemd/man/systemd.socket.html"><code>systemd.socket</code>
1639 manpage</a> for details.</p>
1640 </div>
1641 <div class="paragraph">
1642 <p>In order for the changes to take effect, run the following commands:</p>
1643 </div>
1644 <div class="literalblock">
1645 <div class="content">
1646 <pre>$ sudo systemctl daemon-reload
1647 $ sudo systemctl restart cockpit.socket</pre>
1648 </div>
1649 </div>
1650 </div>
1651 <div class="sect3">
1652 <h4 id="listen-selinux">SELinux Port</h4>
1653 <div class="paragraph">
1654 <p>If <a href="https://selinuxproject.org/page/Main_Page">SELinux</a> is protecting your
1655 server, then you will need to tell it to allow Cockpit to listen on the
1656 new port. Run the following command to do so. The last argument
1657 specifies the desired TCP port.</p>
1658 </div>
1659 <div class="literalblock">
1660 <div class="content">
1661 <pre>$ sudo semanage port -a -t websm_port_t -p tcp 9999</pre>
1662 </div>
1663 </div>
1664 <div class="paragraph">
1665 <p>If the port is already defined by some other part of the SELinux policy,
1666 then you will need to use the <code>-m</code> argument to modify the definition.
1667 That&#8217;s the case with the <code>443</code> SSL port, which is typically defined as
1668 an <code>http_port_t</code> port.</p>
1669 </div>
1670 <div class="literalblock">
1671 <div class="content">
1672 <pre>$ sudo semanage port -m -t websm_port_t -p tcp 443</pre>
1673 </div>
1674 </div>
1675 <div class="paragraph">
1676 <p>The changes should take effect immediately.</p>
1677 </div>
1678 </div>
1679 <div class="sect3">
1680 <h4 id="listen-firewalld">Firewalld Port</h4>
1681 <div class="paragraph">
1682 <p>If <a href="https://fedoraproject.org/wiki/FirewallD">Firewalld</a> is configured as
1683 your firewall, then you will need to tell it to allow Cockpit to receive
1684 connections on the new port. Run the following commands to do so. The
1685 last options specify the desired TCP port.</p>
1686 </div>
1687 <div class="literalblock">
1688 <div class="content">
1689 <pre>$ sudo firewall-cmd [--zone=ZONE] --add-port=443/tcp
1690 $ sudo firewall-cmd --permanent [--zone=ZONE] --add-port=443/tcp</pre>
1691 </div>
1692 </div>
1693 </div>
1694 </div>
1695 <div class="sect2">
1696 <h3 id="startup">Start up</h3>
1697 <div class="paragraph">
1698 <p>Cockpit&#8217;s <code>cockpit-ws</code> component is what the browser connects to and
1699 it typically starts on demand via
1700 <a href="https://www.freedesktop.org/wiki/Software/systemd/"><code>systemd</code></a> socket
1701 activation.</p>
1702 </div>
1703 <div class="paragraph">
1704 <p>The actual <code>cockpit.service</code> and <code>cockpit-ws</code> process will start on
1705 demand when a browser accesses the <code>cockpit.socket</code>,
1706 <a href="listen.html">usually on port 9090</a>. Once a user logs in then a
1707 <code>cockpit-bridge</code> process will be started in a Linux user login
1708 session.</p>
1709 </div>
1710 <div class="paragraph">
1711 <p>Only systems that you connect to with your browser need to have the
1712 <code>cockpit.socket</code> enabled. For systems that you add through host
1713 switcher the bridge is started via SSH on demand.</p>
1714 </div>
1715 <div class="sect3">
1716 <h4 id="startup-shutdown">Process exit</h4>
1717 <div class="paragraph">
1718 <p>The <code>cockpit-bridge</code> process will exit when the user logs out. In
1719 addition, after 10 minutes of inactivity, the <code>cockpit-ws</code> process
1720 will exit on its own. The browser will automatically disconnect if it
1721 fails to hear from the <code>cockpit-ws</code> process for 30 seconds.</p>
1722 </div>
1723 </div>
1724 <div class="sect3">
1725 <h4 id="startup-boot">Boot start up</h4>
1726 <div class="paragraph">
1727 <p>To make Cockpit available by default after system boot the
1728 <code>cockpit.socket</code> needs to be enabled:</p>
1729 </div>
1730 <div class="literalblock">
1731 <div class="content">
1732 <pre>$ sudo systemctl enable cockpit.socket</pre>
1733 </div>
1734 </div>
1735 <div class="paragraph">
1736 <p>If you wish to not have Cockpit available by default via a browser, then
1737 the <code>cockpit.socket</code> should be disabled:</p>
1738 </div>
1739 <div class="literalblock">
1740 <div class="content">
1741 <pre>$ sudo systemctl disable cockpit.socket</pre>
1742 </div>
1743 </div>
1744 </div>
1745 </div>
1746 <div class="sect2">
1747 <h3 id="multi-host">Managing multiple hosts at the same time</h3>
1748 <div class="admonitionblock warning">
1749 <table>
1750 <tr>
1751 <td class="icon">
1752 <div class="title">Warning</div>
1753 </td>
1754 <td class="content">
1755 <div class="paragraph">
1756 <p>This feature is deprecated as of Cockpit 322.</p>
1757 </div>
1758 </td>
1759 </tr>
1760 </table>
1761 </div>
1762 <div class="paragraph">
1763 <p>Cockpit allows you to access multiple hosts in a single session, by
1764 establishing SSH connections to other hosts. This is quite similar to
1765 logging into these other hosts using the <code>ssh</code> command on the command
1766 line, with one very important difference:</p>
1767 </div>
1768 <div class="paragraph">
1769 <p>Code from the local host and all the remote hosts run at the same time,
1770 in the same browser context. They are not isolated from each other in
1771 the browser. All code effectively has the same privileges as the primary
1772 session on the local host.</p>
1773 </div>
1774 <div class="paragraph">
1775 <p>Thus, <em>you should only only connect to remote hosts that you trust</em>. You
1776 must be sure that none of the hosts that you connect to will cause
1777 Cockpit to load malicious JavaScript code into your browser.</p>
1778 </div>
1779 <div class="paragraph">
1780 <p>Therefore, Cockpit will warn you before connecting to more than one
1781 host. It is also possible to disable multiple hosts entirely, and some
1782 operating systems do this already by default.</p>
1783 </div>
1784 <div class="paragraph">
1785 <p>You can prevent loading of JavaScript, HTML, etc from more than one host
1786 by adding this to <code>cockpit.conf</code>:</p>
1787 </div>
1788 <div class="literalblock">
1789 <div class="content">
1790 <pre> [WebService]
1791 AllowMultiHost=false</pre>
1792 </div>
1793 </div>
1794 <div class="paragraph">
1795 <p>When you allow multiple hosts in a single Cockpit session by setting
1796 <code>AllowMultiHost</code> to true, then the user will be warned once per
1797 session, before connecting to the second host. If that is still too
1798 much, you can switch the warning off completely by adding the following
1799 to <code>cockpit.conf</code>:</p>
1800 </div>
1801 <div class="literalblock">
1802 <div class="content">
1803 <pre> [Session]
1804 WarnBeforeConnecting=false</pre>
1805 </div>
1806 </div>
1807 </div>
1808 <div class="sect2">
1809 <h3 id="authentication">Cockpit Authentication</h3>
1810 <div class="paragraph">
1811 <p>While cockpit allows you to monitor and administer several servers at
1812 the same time, there is always a primary server your browser connects to
1813 that runs the Cockpit web service (cockpit-ws) through which connections
1814 to additional servers are established. See
1815 <a href="https://raw.githubusercontent.com/cockpit-project/cockpit/main/doc/cockpit-transport.png">this
1816 diagram</a> for how it works.</p>
1817 </div>
1818 <div class="paragraph">
1819 <p>Normally, a session is established on the primary server, and you use
1820 the Shell UI of that session to connect to secondary servers.</p>
1821 </div>
1822 <div class="paragraph">
1823 <p>However, it is also possible to instruct the <code>cockpit-ws</code> process on
1824 the primary server to directly connect to a secondary server, without
1825 opening a session on the primary server at all. This is done on the main
1826 login page of Cockpit, by filling out the "Connect to" field.</p>
1827 </div>
1828 <div class="sect3">
1829 <h4 id="initial-auth">Directly logging into the primary server</h4>
1830 <div class="paragraph">
1831 <p>The most common way to use Cockpit is to just log directly into the
1832 server that you want to access. This can be done if you have direct
1833 network access to port 9090 on that server.</p>
1834 </div>
1835 <div class="paragraph">
1836 <p>By default the cockpit web service is installed on thec base system and
1837 <a href="listen.html">socket activated by systemd</a>. In this setup access is
1838 controlled by a cockpit specific pam stack, generally located at
1839 <code>/etc/pam.d/cockpit</code>. By default this is configured to allow you to
1840 login with the username and password of any local account on the system.
1841 You can also setup a <a href="sso.html">Kerberos based SSO solution</a> or
1842 <a href="cert-authentication.html">certificate/smart card authentication</a>.</p>
1843 </div>
1844 <div class="paragraph">
1845 <p>You can also
1846 <a href="https://github.com/cockpit-project/cockpit/blob/main/doc/authentication.md#actions">disable
1847 authentication schemes</a> to enforce authentication policies, or to
1848 suppress undesired browser GSSAPI authentication dialogs.</p>
1849 </div>
1850 <div class="paragraph">
1851 <p>The web server can also be run from the
1852 <a href="https://quay.io/cockpit/ws">cockpit/ws</a> container. If you are
1853 running cockpit on a container host operating system like
1854 <a href="https://getfedora.org/coreos/">Fedora CoreOS</a> this will be the only
1855 supported mode. In this setup, cockpit establishes an SSH connection
1856 from the container to the underlying host, meaning that it is up to your
1857 SSH server to grant access. To login with a local account, <code>sshd</code> will
1858 need to be configured to allow password based authentication.
1859 Alternatively you can setup a <a href="sso.html">Kerberos based SSO solution</a>.</p>
1860 </div>
1861 <div class="paragraph">
1862 <p>Like <code>sshd</code>, cockpit can be configured to limit the number of
1863 concurrent login attempts allowed. This is done by adding a
1864 <code>MaxStartups</code> option to the <code>WebService</code> section of your
1865 <code>cockpit.conf</code>. Additional connections will be dropped until
1866 authentication succeeds or the connections are closed.</p>
1867 </div>
1868 </div>
1869 <div class="sect3">
1870 <h4 id="direct-secondary-auth">Directly logging into a secondary server without a primary session</h4>
1871 <div class="paragraph">
1872 <p>It is also possible to log into a secondary server without opening a
1873 session on the primary server. This is useful if you are not actually
1874 interested in the primary server and would only use it because you do
1875 not have direct network access to the secondary server.</p>
1876 </div>
1877 <div class="paragraph">
1878 <p>In this case, <code>cockpit-ws</code> still runs on the primary server, but the
1879 credentials from the login screen are directly used with SSH to log into
1880 the secondary server given in the "Connect To" field of the login
1881 screen.</p>
1882 </div>
1883 <div class="paragraph">
1884 <p>Thus, the PAM configuration and accounts on the primary server don&#8217;t
1885 matter at all. Often, the only purpose of the primary server is to sit
1886 on the boundary of your network and forward connections to internal
1887 machines.</p>
1888 </div>
1889 <div class="paragraph">
1890 <p>In this case, the login page will prompt you to verify unknown SSH keys.
1891 Accepted keys will be remembered in the local storage of your browser.</p>
1892 </div>
1893 </div>
1894 <div class="sect3">
1895 <h4 id="secondary-auth">Logging into a secondary server from the primary session</h4>
1896 <div class="paragraph">
1897 <p>Once you have a session on the primary server, it is possible connect to
1898 additional servers by using the host switching UI of the Cockpit Shell.
1899 This is useful if you have direct network access to the primary server,
1900 but not to the secondary server.</p>
1901 </div>
1902 <div class="paragraph">
1903 <p>On the command line, you would log into the primary server and then use
1904 SSH to log into the secondary one. Cockpit does just the same, and uses
1905 SSH to log into the secondary server. Instead of running a interactive
1906 shell there, however, it starts a <code>cockpit-bridge</code> process.</p>
1907 </div>
1908 <div class="paragraph">
1909 <p><em>Warning:</em> Unlike with SSH on the command line though, this will also
1910 load and use the Cockpit pages (i.e. JavaScript) from the remote
1911 machine, which means that the remote machine can execute arbitrary code
1912 on your primary and all other connected secondary machines. Hence, only
1913 connect to <em>machines which you trust</em>.</p>
1914 </div>
1915 <div class="paragraph">
1916 <p>Due to this security risk, this host switcher functionality is disabled
1917 by default, except on long-term stable Linux distributions (Red Hat
1918 Enterprise Linux 9, Debian 12, and Ubuntu 22.04/24.04 LTS). If you are
1919 comfortable with the security implications, you can enable it manually
1920 with the <code>AllowMultiHost</code> option in <code>cockpit.conf</code>.</p>
1921 </div>
1922 <div class="paragraph">
1923 <p>These servers will need to be running an SSH server and be configured to
1924 support one of the following authentication methods.</p>
1925 </div>
1926 <div class="sect4">
1927 <h5 id="_password">Password</h5>
1928 <div class="paragraph">
1929 <p>The target server will need to have password based authentication
1930 enabled in <code>sshd</code>.</p>
1931 </div>
1932 </div>
1933 <div class="sect4">
1934 <h5 id="_kerberos">Kerberos</h5>
1935 <div class="paragraph">
1936 <p>The target server will need to be a member of the same domain as the
1937 primary server and your domain must be whitelisted in your browser. See
1938 the <a href="sso.html">SSO documentation</a> for how to set this up.</p>
1939 </div>
1940 </div>
1941 <div class="sect4">
1942 <h5 id="_public_key">Public key</h5>
1943 <div class="paragraph">
1944 <p>When you successfully log into the primary server, a <code>ssh-agent</code> is
1945 started and keys are loaded into it by running <code>ssh-add</code> without any
1946 arguments. Any passphrase prompt is answered with the password used to
1947 log into the primary server.</p>
1948 </div>
1949 <div class="paragraph">
1950 <p>Cockpit provides a user interface for loading other keys into the agent
1951 that could not be automatically loaded.</p>
1952 </div>
1953 <div class="paragraph">
1954 <p>The target server will need to have public key authentication enabled in
1955 <code>sshd</code>, and the public key you wish to use must be present in
1956 <code>~/.ssh/authorized_keys</code>. Cockpit has a user interface for creating
1957 SSH keys and for authorizing them.</p>
1958 </div>
1959 </div>
1960 <div class="sect4">
1961 <h5 id="host-keys">SSH host keys</h5>
1962 <div class="paragraph">
1963 <p>Cockpit will prompt the user to verify unknown SSH host keys, and will
1964 write accepted host keys into <code>~/.ssh/known_hosts</code>.</p>
1965 </div>
1966 </div>
1967 </div>
1968 </div>
1969 <div class="sect2">
1970 <h3 id="sso">Single Sign On</h3>
1971 <div class="paragraph">
1972 <p>Cockpit can use Kerberos for Single Sign On authentication, where users
1973 are automatically authenticated if they have a valid Kerberos ticket.</p>
1974 </div>
1975 <div class="sect3">
1976 <h4 id="sso-server">Server Requirements</h4>
1977 <div class="paragraph">
1978 <p>To authenticate users, the server that Cockpit is running on must be
1979 joined to a domain. This can usually be accomplished using the
1980 <a href="https://freedesktop.org/software/realmd/docs/realm.html"><code>realm join example.com</code></a>
1981 command.</p>
1982 </div>
1983 <div class="paragraph">
1984 <p>The domain must be resolvable by DNS. For instance, the SRV records of
1985 the kerberos server should be resolvable:</p>
1986 </div>
1987 <div class="literalblock">
1988 <div class="content">
1989 <pre>$ host -t SRV _kerberos._udp.example.com
1990 _kerberos._udp.example.com has SRV record 0 100 88 dc.example.com</pre>
1991 </div>
1992 </div>
1993 <div class="paragraph">
1994 <p>The server running Cockpit should have a fully qualified name that ends
1995 with the domain name.</p>
1996 </div>
1997 <div class="paragraph">
1998 <p>There must be a valid Kerberos host key for the server in the
1999 <code>/etc/krb5.keytab</code> file. Alternatively, if you would like to use a
2000 different keytab, you can do so by placing it in
2001 <code>/etc/cockpit/krb5.keytab</code>, or below <code>$XDG_CONFIG_DIRS</code> if set (see
2002 <a href="./cockpit.conf.5.html">cockpit.conf</a>). It may be necessary to create
2003 a kerberos service principal and update the keytab if it is not present.
2004 Depending on your domain type different service names are required:</p>
2005 </div>
2006 <div class="dlist">
2007 <dl>
2008 <dt class="hdlist1">Active Directory</dt>
2009 <dd>
2010 <p><code>HOST/[email protected]</code></p>
2011 </dd>
2012 <dt class="hdlist1">IPA and MIT</dt>
2013 <dd>
2014 <p><code>HTTP/[email protected]</code></p>
2015 </dd>
2016 </dl>
2017 </div>
2018 <div class="paragraph">
2019 <p>When joining an IPA domain with Cockpit and the <code>ipa</code> command line
2020 tool is available, both the service principal name and a
2021 <code>/etc/cockpit/krb5.keytab</code> get created automatically, so that Kerberos
2022 based single sign on into Cockpit works out of the box. If you want/need
2023 to do this by hand or in a script, first create or modify the <code>HTTP/</code>
2024 service principal:</p>
2025 </div>
2026 <div class="literalblock">
2027 <div class="content">
2028 <pre>$ sudo ipa service-add --ok-as-delegate=true --ok-to-auth-as-delegate=true \
2029 HTTP/[email protected]
2030 # or, if it already exists, just enable delegation:
2031 $ sudo ipa service-mod --ok-as-delegate=true --ok-to-auth-as-delegate=true \
2032 HTTP/[email protected]</pre>
2033 </div>
2034 </div>
2035 <div class="paragraph">
2036 <p>Then generate a key for that principal:</p>
2037 </div>
2038 <div class="literalblock">
2039 <div class="content">
2040 <pre>$ sudo ipa-getkeytab -p HTTP/[email protected] -k /etc/cockpit/krb5.keytab</pre>
2041 </div>
2042 </div>
2043 <div class="paragraph">
2044 <p>The following command can be used to list the
2045 <code>/etc/cockpit/krb5.keytab</code>:</p>
2046 </div>
2047 <div class="literalblock">
2048 <div class="content">
2049 <pre>$ sudo klist -k /etc/cockpit/krb5.keytab</pre>
2050 </div>
2051 </div>
2052 <div class="paragraph">
2053 <p>Lastly accounts from the domain must be resolvable to unix accounts on
2054 the server running Cockpit. For example:</p>
2055 </div>
2056 <div class="literalblock">
2057 <div class="content">
2058 <pre>$ getent passwd [email protected]
2059 [email protected]:*:381001109:381000513:User Name:/home/user:/bin/sh</pre>
2060 </div>
2061 </div>
2062 <div class="paragraph">
2063 <p>If you wish to delegate your kerberos credentials to Cockpit, and allow
2064 Cockpit to then connect to other machines using those credentials, you
2065 should enable delegation for the hosts running Cockpit, and in some
2066 cases the <code>HTTP</code> service as well. When joining an IPA domain, this is
2067 enabled by default.</p>
2068 </div>
2069 <div class="paragraph">
2070 <p>Domain admins (usually the <code>[email protected]</code> group) should normally
2071 also be able to administer any joined machine. Enable sudo access for
2072 that group with the following command on the IPA server, for version
2073 4.7.1 and later:</p>
2074 </div>
2075 <div class="literalblock">
2076 <div class="content">
2077 <pre>ipa-advise enable-admins-sudo | sh -ex</pre>
2078 </div>
2079 </div>
2080 <div class="paragraph">
2081 <p>On earlier FreeIPA versions, run these commands instead, as a domain
2082 admin on any joined machine:</p>
2083 </div>
2084 <div class="literalblock">
2085 <div class="content">
2086 <pre>ipa sudorule-add --hostcat=all --cmdcat=all All
2087 ipa sudorule-add-user --groups=admins All</pre>
2088 </div>
2089 </div>
2090 <div class="paragraph">
2091 <p>Note that this does not change security properties; domain admins can
2092 give this privilege to themselves, so it is safe to enable by default.</p>
2093 </div>
2094 </div>
2095 <div class="sect3">
2096 <h4 id="sso-client">Client Requirements</h4>
2097 <div class="paragraph">
2098 <p>The client side, where your web browser is running, should have a valid
2099 kerberos ticket in the current user session. A command like this will
2100 get one:</p>
2101 </div>
2102 <div class="literalblock">
2103 <div class="content">
2104 <pre>$ kinit [email protected]
2105 Password for [email protected]:</pre>
2106 </div>
2107 </div>
2108 <div class="paragraph">
2109 <p>In addition your browser must be usually be configured to allow kerberos
2110 authentication for the domain.</p>
2111 </div>
2112 <div class="dlist">
2113 <dl>
2114 <dt class="hdlist1">Mozilla Firefox</dt>
2115 <dd>
2116 <p>Go to <code>about:config</code> and set the
2117 <code>network.negotiate-auth.trusted-uris</code> setting to your domain name
2118 preceded by a dot, ie: <code>.example.com</code></p>
2119 </dd>
2120 <dt class="hdlist1">Google Chrome</dt>
2121 <dd>
2122 <p>On Linux: create the file
2123 <code>/etc/opt/chrome/policies/managed/example-com.json</code> with the
2124 contents:</p>
2125 </dd>
2126 <dt class="hdlist1"></dt>
2127 </dl>
2128 </div>
2129 <div class="literalblock">
2130 <div class="content">
2131 <pre>{
2132 "AuthServerWhitelist": "*example.com"
2133 }</pre>
2134 </div>
2135 </div>
2136 <div class="dlist">
2137 <dl>
2138 <dt class="hdlist1"></dt>
2139 <dd>
2140 <p>and restart the browser. On other platforms, exit your browser
2141 completely, and start it with a command line like this:
2142 <code>google-chrome --auth-server-whitelist=*example.com</code></p>
2143 </dd>
2144 </dl>
2145 </div>
2146 <div class="paragraph">
2147 <p>Use a fully qualified server name (with the domain name at the end) to
2148 access Cockpit in your web browser.</p>
2149 </div>
2150 <div class="paragraph">
2151 <p>If you wish to connect from one server to another in Cockpit using
2152 kerberos SSO, then you have to explicitly enable all sorts of things.
2153 For starters, make sure that delegated credentials are allowed by your
2154 domain (see above). Next when requesting your kerberos ticket make sure
2155 that forwardable tickets are requested:</p>
2156 </div>
2157 <div class="literalblock">
2158 <div class="content">
2159 <pre>$ kinit -f [email protected]
2160 Password for [email protected]:</pre>
2161 </div>
2162 </div>
2163 <div class="paragraph">
2164 <p>Make sure that the forwardable flag <code>F</code> is present in your ticket:</p>
2165 </div>
2166 <div class="literalblock">
2167 <div class="content">
2168 <pre>$ klist -f
2169 Ticket cache: KEYRING:persistent:1000:1000
2170 Default principal: [email protected]
2171
2172 Valid starting Expires Service principal
2173 18.03.2017 05:39:23 19.03.2017 05:39:20 krbtgt/[email protected]
2174 Flags: FIA</pre>
2175 </div>
2176 </div>
2177 <div class="paragraph">
2178 <p>Lastly configure your browser to allow delegated, forwardable kerberos
2179 credentials to be sent to Cockpit:</p>
2180 </div>
2181 <div class="dlist">
2182 <dl>
2183 <dt class="hdlist1">Mozilla Firefox</dt>
2184 <dd>
2185 <p>Go to <code>about:config</code> and set the
2186 <code>network.negotiate-auth.delegation-uris</code> setting to your domain name
2187 preceded by a dot, ie: <code>.example.com</code></p>
2188 </dd>
2189 <dt class="hdlist1">Google Chrome</dt>
2190 <dd>
2191 <p>On Linux: create the file
2192 <code>/etc/opt/chrome/policies/managed/example-com.json</code> with the
2193 contents:</p>
2194 </dd>
2195 <dt class="hdlist1"></dt>
2196 </dl>
2197 </div>
2198 <div class="literalblock">
2199 <div class="content">
2200 <pre>{
2201 "AuthServerWhitelist": "*example.com",
2202 "AuthNegotiateDelegateWhitelist": "*example.com"
2203 }</pre>
2204 </div>
2205 </div>
2206 <div class="dlist">
2207 <dl>
2208 <dt class="hdlist1"></dt>
2209 <dd>
2210 <p>and restart the browser. On other platforms, exit your browser
2211 completely, and start it with a command line like this:
2212 <code>google-chrome --auth-server-whitelist=*example.com --auth-negotiate-delegate-whitelist=*example.com</code></p>
2213 </dd>
2214 </dl>
2215 </div>
2216 </div>
2217 </div>
2218 <div class="sect2">
2219 <h3 id="cert-authentication">Certificate/smart card authentication</h3>
2220 <div class="paragraph">
2221 <p>Cockpit can use TLS client certificates for authenticating users.
2222 Commonly these are provided by a smart card, but it&#8217;s equally possible
2223 to import certificates directly into the web browser.</p>
2224 </div>
2225 <div class="paragraph">
2226 <p>This requires the host to be in an Identity Management domain like
2227 <a href="https://www.freeipa.org">FreeIPA</a> or
2228 <a href="https://en.wikipedia.org/wiki/Active_Directory">Active Directory</a>, which
2229 can associate certificates to users.</p>
2230 </div>
2231 <div class="paragraph">
2232 <p>To authenticate users from a Identity Management domain, the server that
2233 Cockpit is running on must be joined to that domain. See the
2234 <a href="sso.html#sso-server">SSO server requirements</a> for details.</p>
2235 </div>
2236 <div class="sect3">
2237 <h4 id="certauth-server-cert-generation">User certificate generation</h4>
2238 <div class="paragraph">
2239 <p>Generating the certificates for users is usually done with a certificate
2240 management system like <a href="https://pagure.io/certmonger">certmonger</a> or
2241 <a href="https://www.freeipa.org/page/PKI">FreeIPA</a>, which are not documented
2242 here. This command generates a simple key and certificate request for
2243 the "alice" user:</p>
2244 </div>
2245 <div class="literalblock">
2246 <div class="content">
2247 <pre>openssl req -new -newkey rsa:2048 -days 365 \
2248 -keyout alice.key -out alice.csr -subj "/CN=alice"</pre>
2249 </div>
2250 </div>
2251 <div class="paragraph">
2252 <p>Now get this certificate request signed by the Certificate Authority of
2253 your Identity Management domain, to get a PEM certificate. Browsers and
2254 smart cart utilities accept PKCS#12 format for importing/transfer, so
2255 convert the certificate/key pair; it will ask for and protect it with a
2256 transfer password:</p>
2257 </div>
2258 <div class="literalblock">
2259 <div class="content">
2260 <pre>openssl pkcs12 -export -in alice.pem -inkey alice.key -out alice.p12</pre>
2261 </div>
2262 </div>
2263 <div class="paragraph">
2264 <p>Don&#8217;t forget to clean up the key file when you do not need it any more:</p>
2265 </div>
2266 <div class="literalblock">
2267 <div class="content">
2268 <pre>shred -u alice.key</pre>
2269 </div>
2270 </div>
2271 <div class="paragraph">
2272 <p>You can now import <code>alice.p12</code> directly into your browser, with giving
2273 the transfer password set above. Or
2274 <a href="https://linux.die.net/man/1/pkcs15-init">put the certificate onto a smart
2275 card</a>:</p>
2276 </div>
2277 <div class="literalblock">
2278 <div class="content">
2279 <pre>pkcs15-init --store-private-key alice.p12 --format pkcs12 --auth-id 01</pre>
2280 </div>
2281 </div>
2282 </div>
2283 <div class="sect3">
2284 <h4 id="certauth-server-ipa">Certificate mapping with FreeIPA</h4>
2285 <div class="paragraph">
2286 <p>The recommended method to sign a user certificate request and associate
2287 it to a user is <code>ipa cert-request</code>:</p>
2288 </div>
2289 <div class="literalblock">
2290 <div class="content">
2291 <pre>ipa cert-request alice.csr --principal=alice --certificate-out=alice.pem</pre>
2292 </div>
2293 </div>
2294 <div class="paragraph">
2295 <p>Alternatively, if you are using a different CA, you can use
2296 <code>ipa user-add-cert</code> to associate the signed certificate to the user.
2297 This expects PEM format, but without the <code>-----BEGIN</code>/<code>-----END</code>
2298 markers:</p>
2299 </div>
2300 <div class="literalblock">
2301 <div class="content">
2302 <pre>ipa user-add-cert alice --certificate="$(grep -v ^---- alice.pem)"</pre>
2303 </div>
2304 </div>
2305 <div class="paragraph">
2306 <p>See the
2307 <a href="https://www.freeipa.org/page/V4/User_Certificates#Feature_Management">FreeIPA
2308 User Certificates documentation</a> for details.</p>
2309 </div>
2310 </div>
2311 <div class="sect3">
2312 <h4 id="certauth-server-ms-ad">Certificate mapping with Microsoft Active Directory</h4>
2313 <div class="paragraph">
2314 <p>The domain user certificates get imported into the
2315 <code>userCertificate;binary</code> LDAP attribute. The following commands
2316 convert the PEM certificate into binary DER form, create an
2317 <a href="https://ldap.com/ldif-the-ldap-data-interchange-format/">LDIF</a> file and
2318 apply it to the LDAP server running on the domain controller
2319 "dc.example.com":</p>
2320 </div>
2321 <div class="literalblock">
2322 <div class="content">
2323 <pre>openssl x509 -outform der -in alice.pem -out alice.der
2324
2325 cat &lt;&lt;EOF &gt; alice.ldif
2326 version: 1
2327 dn: cn=alice,ou=users,ou=YOUR_NETBIOS_NAME,dc=example,dc=com
2328 changetype: modify
2329 add: userCertificate;binary
2330 userCertificate;binary:&lt; file://$(pwd)/alice.der
2331 EOF
2332
2333 ldapmodify -H ldap://dc.example.com -f alice.ldif</pre>
2334 </div>
2335 </div>
2336 </div>
2337 <div class="sect3">
2338 <h4 id="certauth-server-samba-ad">Certificate mapping with Samba Active Directory</h4>
2339 <div class="paragraph">
2340 <p>At least some versions of <a href="https://www.samba.org/">Samba</a> do not support
2341 the <code>userCertificate;binary</code> LDAP attribute, so the import has to
2342 happen in base64 PEM form into the textual <code>userCertificate</code> attribute
2343 instead. Also, Samba uses a slightly different user hierarchy:</p>
2344 </div>
2345 <div class="literalblock">
2346 <div class="content">
2347 <pre>cat &lt;&lt;EOF &gt; alice.ldif
2348 version: 1
2349 dn: cn=alice,cn=users,dc=example,dc=com
2350 changetype: modify
2351 add: userCertificate
2352 userCertificate: $(grep -v ^---- alice.pem | tr -d '\n')
2353 EOF
2354
2355 ldapmodify -H ldap://dc.example.com -f alice.ldif</pre>
2356 </div>
2357 </div>
2358 <div class="paragraph">
2359 <p>As <code>userCertificate</code> is a text instead of binary field, you need to
2360 set up a
2361 <a href="https://www.mankier.com/5/sssd.conf#Certificate_Mapping_Section">certificate
2362 mapping rule</a> in <code>sssd.conf(5)</code> in a <code>[certmap/domain/rulename]</code>
2363 section, for example:</p>
2364 </div>
2365 <div class="literalblock">
2366 <div class="content">
2367 <pre>[certmap/example.com/adcerts]
2368 # we match full certificates, so it is not important to check anything here
2369 matchrule = &lt;KU&gt;digitalSignature
2370 maprule = LDAP:(userCertificate={cert!base64})</pre>
2371 </div>
2372 </div>
2373 </div>
2374 <div class="sect3">
2375 <h4 id="certauth-server-cockpitconf">Cockpit web server configuration</h4>
2376 <div class="paragraph">
2377 <p>Set the trusted Certificate Authority of your user certificates in
2378 <code>sssd</code>, either by copying the CA PEM file to
2379 <code>/etc/sssd/pki/sssd_auth_ca_db.pem</code> or setting the
2380 <a href="https://www.mankier.com/5/sssd.conf#Services_Sections-PAM_configuration_options"><code>pam_cert_db_path</code></a>
2381 configuration option to the path of the CA. If you use FreeIPA and its
2382 CA:</p>
2383 </div>
2384 <div class="literalblock">
2385 <div class="content">
2386 <pre>cp /etc/ipa/ca.crt /etc/sssd/pki/sssd_auth_ca_db.pem</pre>
2387 </div>
2388 </div>
2389 <div class="paragraph">
2390 <p>Certificate authentication needs to be enabled in
2391 <a href="cockpit.conf.5.html">cockpit.conf</a>(5) explicitly:</p>
2392 </div>
2393 <div class="literalblock">
2394 <div class="content">
2395 <pre>[WebService]
2396 ClientCertAuthentication = yes</pre>
2397 </div>
2398 </div>
2399 <div class="paragraph">
2400 <p>When enabling this mode,
2401 <a href="https://github.com/cockpit-project/cockpit/blob/main/doc/authentication.md">other
2402 authentication types</a> commonly get disabled, so that <em>only</em> client
2403 certificate authentication will be accepted. By default, after a failed
2404 certificate authentication attempt, Cockpit&#8217;s normal login page will
2405 appear and permit other login types such as <code>basic</code> (passwords) or
2406 <code>negotiate</code> (Kerberos). For example, password authentication gets
2407 disabled with:</p>
2408 </div>
2409 <div class="literalblock">
2410 <div class="content">
2411 <pre>[basic]
2412 action = none</pre>
2413 </div>
2414 </div>
2415 </div>
2416 <div class="sect3">
2417 <h4 id="certauth-server-resourcelimits">Cockpit web server resource limits</h4>
2418 <div class="paragraph">
2419 <p>When using certificate authentication, all requests with a particular
2420 certificate will be handled by a separate and isolated instance of the
2421 <a href="cockpit-ws.8.html">cockpit-ws</a>(8) web server. This protects against
2422 possible vulnerabilities in the web server and prevents an attacker from
2423 impersonating another user. However, this introduces a potential Denial
2424 of Service: Some remote attacker could create a large number of
2425 certificates and send a large number of http requests to Cockpit with
2426 these.</p>
2427 </div>
2428 <div class="paragraph">
2429 <p>To mitigate that, all <code>cockpit-ws</code> instances run in a
2430 <code>system-cockpithttps.slice</code>
2431 <a href="https://www.freedesktop.org/software/systemd/man/systemd.slice.html">systemd
2432 slice unit</a> which
2433 <a href="https://www.freedesktop.org/software/systemd/man/systemd.resource-control.html">limits
2434 the collective resources</a> of these web server instances: by default,
2435 this slice sets a limit of 200 threads (roughly 100 instances of
2436 <code>cockpit-ws</code>&#8201;&#8212;&#8201;in other words, a maximum of 100 parallel user
2437 sessions with different certificates) and a 75% (soft)/90% (hard) memory
2438 limit.</p>
2439 </div>
2440 <div class="paragraph">
2441 <p>You are welcome to adjust these limits to your need through a
2442 <a href="https://www.freedesktop.org/software/systemd/man/systemd.unit.html">drop-in</a>.
2443 For example:</p>
2444 </div>
2445 <div class="literalblock">
2446 <div class="content">
2447 <pre># systemctl edit system-cockpithttps.slice
2448
2449 [Slice]
2450 # change existing value
2451 TasksMax=100
2452 # add new restriction
2453 CPUQuota=30%</pre>
2454 </div>
2455 </div>
2456 </div>
2457 <div class="sect3">
2458 <h4 id="certauth-forwarding">Authentication to other services like sudo and ssh</h4>
2459 <div class="paragraph">
2460 <p>Once you logged into Cockpit with a certificate, you likely need to
2461 switch to administrative mode (root privileges through sudo), or connect
2462 to remote machines through SSH. If your user account has a password,
2463 that can be used for authenticating to sudo or ssh as usual.</p>
2464 </div>
2465 <div class="paragraph">
2466 <p><em>Supported with FreeIPA only:</em> As an alternative to password
2467 authentication, you can also declare the initial Cockpit certificate
2468 authentication as trusted for authenticating to SSH, sudo, or other
2469 services. For that purpose, Cockpit automatically creates an
2470 <a href="https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-sfu/bde93b0e-f3c9-4ddf-9f44-e1453be7af5a">S4U2Proxy
2471 Kerberos ticket</a> in the user session:</p>
2472 </div>
2473 <div class="literalblock">
2474 <div class="content">
2475 <pre>$ klist
2476 Ticket cache: FILE:/run/user/1894000001/cockpit-session-3692.ccache
2477 Default principal: [email protected]
2478
2479 Valid starting Expires Service principal
2480 07/30/21 09:19:06 07/31/21 09:19:06 HTTP/[email protected]
2481 07/30/21 09:19:06 07/31/21 09:19:06 krbtgt/[email protected]
2482 for client HTTP/[email protected]</pre>
2483 </div>
2484 </div>
2485 <div class="paragraph">
2486 <p>You can set up
2487 <a href="https://www.freeipa.org/page/V4/Service_Constraint_Delegation">constrained
2488 delegation rules</a> to enumerate which hosts (including its own) that
2489 ticket is trusted to access. For example, if the cockpit session runs on
2490 host <code>myhost.example.com</code> and should be trusted to access its own host
2491 (through sudo) and another host <code>remote.example.com</code> (through ssh),
2492 create a delegation like this:</p>
2493 </div>
2494 <div class="literalblock">
2495 <div class="content">
2496 <pre># a list of target machines which can be accessed by a particular rule
2497 ipa servicedelegationtarget-add cockpit-target
2498 ipa servicedelegationtarget-add-member cockpit-target \
2499 --principals=host/[email protected] \
2500 --principals=host/[email protected]
2501
2502 # allow cockpit sessions (HTTP/ principal) to access that host list
2503 ipa servicedelegationrule-add cockpit-delegation
2504 ipa servicedelegationrule-add-member cockpit-delegation \
2505 --principals=HTTP/[email protected]
2506 ipa servicedelegationrule-add-target cockpit-delegation \
2507 --servicedelegationtargets=cockpit-target</pre>
2508 </div>
2509 </div>
2510 <div class="paragraph">
2511 <p>In addition, you need to enable GSS (Kerberos) authentication in the
2512 corresponding services.</p>
2513 </div>
2514 <div class="ulist">
2515 <ul>
2516 <li>
2517 <p>For SSH, enable <code>GSSAPIAuthentication yes</code> in
2518 <a href="https://linux.die.net/man/5/sshd_config">/etc/ssh/sshd_config</a>.</p>
2519 </li>
2520 <li>
2521 <p>For sudo, enable <code>pam_sss_gss</code> as described in the
2522 <a href="https://www.mankier.com/8/pam_sss_gss">manpage</a>: In
2523 <code>/etc/sssd/sssd.conf</code>: Add an entry for your domain:</p>
2524 <div class="literalblock">
2525 <div class="content">
2526 <pre>[domain/example.com]
2527 pam_gssapi_services = sudo, sudo-i</pre>
2528 </div>
2529 </div>
2530 <div class="paragraph">
2531 <p>In <code>/etc/pam.d/sudo</code>, enable the module in the first line:</p>
2532 </div>
2533 <div class="literalblock">
2534 <div class="content">
2535 <pre>auth sufficient pam_sss_gss.so</pre>
2536 </div>
2537 </div>
2538 </li>
2539 </ul>
2540 </div>
2541 <div class="paragraph">
2542 <p><em>Caveat:</em> The delegated S4U ticket is not yet forwarded to remote SSH
2543 hosts when connecting to them from Cockpit, so authenticating to sudo on
2544 the remote host with that ticket does not work. This will be provided in
2545 a future version.</p>
2546 </div>
2547 </div>
2548 </div>
2549 <div class="sect2">
2550 <h3 id="privileges">Privileges and Permissions</h3>
2551 <div class="paragraph">
2552 <p>When a user is logged into Cockpit, they are logged into a normal
2553 session that has exactly the same privileges as if they logged in via
2554 SSH or on the console.</p>
2555 </div>
2556 <div class="paragraph">
2557 <p>However, Cockpit will usually try to escalate the privileges of the user
2558 using <a href="https://www.freedesktop.org/wiki/Software/polkit/">Policy Kit</a> or
2559 <a href="https://www.sudo.ws/">sudo</a>. If the user is able to escalate privileges
2560 from the command line by typing in their password again (or without
2561 typing in any password), then Cockpit will be able to escalate the
2562 privileges of the session to "root" immediately upon login.</p>
2563 </div>
2564 <div class="paragraph">
2565 <p>The user can change the privileges of a session from within that
2566 session, via the "Administrative access" indicator in the top bar. From
2567 that indicator, the user can drop "root" privileges and regain them. On
2568 the next login, Cockpit will give the session the same privileges.</p>
2569 </div>
2570 <div class="paragraph">
2571 <p>Usually a user needs to be in the <code>wheel</code> Unix user group for the user
2572 to be able to escalate privileges in this way. However both Policy Kit
2573 and sudo may be configured to use other criteria.</p>
2574 </div>
2575 <div class="sect3">
2576 <h4 id="privileges-polkit">Customizing Polkit Privileges</h4>
2577 <div class="paragraph">
2578 <p>Services like
2579 <a href="https://www.freedesktop.org/wiki/Software/systemd/">systemd</a> and
2580 <a href="https://wiki.gnome.org/Projects/NetworkManager">NetworkManager</a> use
2581 <a href="https://www.freedesktop.org/wiki/Software/polkit/">Polkit</a> to validate
2582 and escalate privileges. It is possible to customize these rules with
2583 files in <code>/etc/polkit-1/rules.d</code>.</p>
2584 </div>
2585 <div class="paragraph">
2586 <p>Polkit rules files are
2587 <a href="https://www.freedesktop.org/software/polkit/docs/latest/polkit.8.html">javascript
2588 with specific methods and objects</a>. For example, placing the following
2589 polkit rule to <code>/etc/polkit-1/rules.d/10-operators.rule</code> allows all
2590 users in the <code>operators</code> group to start, stop, restart and otherwise
2591 manage systemd services:</p>
2592 </div>
2593 <div class="literalblock">
2594 <div class="content">
2595 <pre>polkit.addRule(function(action, subject) {
2596 if (action.id == "org.freedesktop.systemd1.manage-units") {
2597 if (subject.isInGroup("operators")) {
2598 return polkit.Result.YES;
2599 }
2600 }
2601 });</pre>
2602 </div>
2603 </div>
2604 <div class="paragraph">
2605 <p>In order to allow a certain group to perform any administrative action
2606 you could add a rule like this:</p>
2607 </div>
2608 <div class="literalblock">
2609 <div class="content">
2610 <pre>polkit.addAdminRule(function(action, subject) {
2611 return ["unix-group:operators"];
2612 });</pre>
2613 </div>
2614 </div>
2615 </div>
2616 </div>
2617 </div>
2618 </div>
2619 <div class="sect1">
2620 <h2 id="features">Feature Internals</h2>
2621 <div class="sectionbody">
2622 <div class="sect2">
2623 <h3 id="feature-systemd">systemd</h3>
2624 <div class="paragraph">
2625 <p>Cockpit uses <a href="https://www.freedesktop.org/wiki/Software/systemd/">systemd</a>
2626 and the DBus APIs it provides to configure and monitor core aspects of
2627 the system. Use of alternate system APIs are not currently implemented.</p>
2628 </div>
2629 <div class="paragraph">
2630 <p>For non root users, systemd controls access to its APIs via
2631 <a href="privileges.html">Policy Kit</a> and a user logged into Cockpit will have
2632 the same permissions as they do from the command line.</p>
2633 </div>
2634 <div class="paragraph">
2635 <p>Cockpit retrieves information about the host and changes the hostname
2636 via the <code>hostnamed</code> daemon. To perform similar tasks from the command
2637 line use the
2638 <a href="https://www.freedesktop.org/software/systemd/man/hostnamectl.html"><code>hostnamectl</code></a>
2639 command:</p>
2640 </div>
2641 <div class="literalblock">
2642 <div class="content">
2643 <pre>$ hostnamectl
2644 Static hostname: pink.example.com
2645 Pretty hostname: Pink
2646 Icon name: computer-desktop
2647 Chassis: desktop
2648 Machine ID: ef00b79be229463cbb844c3e715de96c
2649 Boot ID: 934983d64d34465cb5a8383b5a89ad8c
2650 Operating System: Fedora 22 (Twenty Two)
2651 CPE OS Name: cpe:/o:fedoraproject:fedora:22
2652 Kernel: Linux 4.0.4-301.fc22.x86_64
2653 Architecture: x86-64</pre>
2654 </div>
2655 </div>
2656 <div class="paragraph">
2657 <p>Cockpit configures the system time and time zone via the <code>timedated</code>
2658 daemon. To perform similar tasks from the command line use the
2659 <a href="https://www.freedesktop.org/software/systemd/man/timedatectl.html"><code>timedatectl</code></a>
2660 command:</p>
2661 </div>
2662 <div class="literalblock">
2663 <div class="content">
2664 <pre>$ timedatectl list-timezones
2665 Africa/Abidjan
2666 Africa/Accra
2667 Africa/Addis_Ababa
2668 Africa/Algiers
2669 ...</pre>
2670 </div>
2671 </div>
2672 <div class="paragraph">
2673 <p>Cockpit can manage the list of NTP servers used by <code>systemd-timesyncd</code>
2674 by putting its own file into <code>/etc/systemd/timesyncd.conf.d/</code>. Note
2675 that <code>systemd-timesyncd</code> is not always enabled, depending on the
2676 configuration of the machine. In that case, Cockpit disabled the UI for
2677 managing the list of NTP servers. In some cases use of <code>ntpd</code> can
2678 cause the <code>timedated</code> daemon to behave inconsistently with regards to
2679 time synchronization.</p>
2680 </div>
2681 <div class="paragraph">
2682 <p>Cockpit reboots or powers down the machine by using the
2683 <a href="https://www.freedesktop.org/software/systemd/man/shutdown.html"><code>shutdown</code></a>
2684 command. To perform similar tasks from the command line, run it
2685 directly:</p>
2686 </div>
2687 <div class="literalblock">
2688 <div class="content">
2689 <pre>$ sudo shutdown +15
2690 Shutdown scheduled for Sa 2015-09-26 15:49:40 CEST, use 'shutdown -c' to cancel.</pre>
2691 </div>
2692 </div>
2693 <div class="paragraph">
2694 <p>Cockpit manages system services and sockets via systemd. To perform
2695 similar tasks from the command line use the
2696 <a href="https://www.freedesktop.org/software/systemd/man/systemctl.html"><code>systemctl</code></a>
2697 command:</p>
2698 </div>
2699 <div class="literalblock">
2700 <div class="content">
2701 <pre>$ systemctl status cockpit
2702 ● cockpit.service - Cockpit Web Service
2703 Loaded: loaded (/usr/lib/systemd/system/cockpit.service; static; vendor preset: disabled)
2704 Drop-In: /etc/systemd/system/cockpit.service.d
2705 └─debug.conf
2706 Active: active (running) since Sa 2015-09-26 13:28:02 CEST; 2h 7min ago
2707 Docs: man:cockpit-ws(8)
2708 Main PID: 6957 (cockpit-ws)
2709 Memory: 1.8M
2710 CGroup: /system.slice/cockpit.service
2711 ├─ 6957 /usr/libexec/cockpit-ws
2712 └─29598 /usr/bin/ssh-agent</pre>
2713 </div>
2714 </div>
2715 <div class="paragraph">
2716 <p>In order to customize who can perform various actions in system,
2717 <a href="privileges.html#privileges-polkit">create polkit rules</a> with the following actions
2718 and details:</p>
2719 </div>
2720 <div class="dlist">
2721 <dl>
2722 <dt class="hdlist1"><code>org.freedesktop.systemd1.manage-units</code></dt>
2723 <dd>
2724 <p>Permission to manage system services or other units. Details
2725 available: <code>unit</code>, <code>verb</code></p>
2726 </dd>
2727 <dt class="hdlist1"><code>org.freedesktop.systemd1.manage-unit-files</code></dt>
2728 <dd>
2729 <p>Permission to manage system services or other unit files.</p>
2730 </dd>
2731 <dt class="hdlist1"><code>org.freedesktop.systemd1.reload-daemon</code></dt>
2732 <dd>
2733 <p>Permission to reload the systemd state.</p>
2734 </dd>
2735 </dl>
2736 </div>
2737 <div class="paragraph">
2738 <p>For example, placing the following polkit rule to
2739 <code>/etc/polkit-1/rules.d/10-http.rule</code> allows all users in the
2740 <code>operators</code> group start, stop, and restart the Apache HTTP service:</p>
2741 </div>
2742 <div class="literalblock">
2743 <div class="content">
2744 <pre>polkit.addRule(function(action, subject) {
2745 if (action.id == "org.freedesktop.systemd1.manage-units") {
2746 if (subject.isInGroup("operators") &amp;&amp; action.lookup("unit") == "httpd.service") {
2747 var verb = action.lookup("verb");
2748 if (verb == "start" || verb == "stop" || verb == "restart") {
2749 return polkit.Result.YES;
2750 }
2751 }
2752 }
2753 });</pre>
2754 </div>
2755 </div>
2756 </div>
2757 <div class="sect2">
2758 <h3 id="feature-journal">Journal</h3>
2759 <div class="paragraph">
2760 <p>The systemd journal provides Cockpit with indexed log data. This log
2761 data is found on the Journal page, as well as in various other places
2762 when configuring services, storage, networking etc.</p>
2763 </div>
2764 <div class="paragraph">
2765 <p>Cockpit accesses Journal data via the
2766 <a href="https://www.freedesktop.org/software/systemd/man/journalctl.html"><code>journalctl</code></a>
2767 command. Similar tasks can be performed at the command line:</p>
2768 </div>
2769 <div class="literalblock">
2770 <div class="content">
2771 <pre>$ sudo journalctl -f -u docker
2772 ...</pre>
2773 </div>
2774 </div>
2775 </div>
2776 <div class="sect2">
2777 <h3 id="feature-networkmanager">NetworkManager</h3>
2778 <div class="paragraph">
2779 <p>If available on the system, Cockpit uses
2780 <a href="https://wiki.gnome.org/Projects/NetworkManager">NetworkManager</a> and the
2781 DBus APIs it provides to interact with the system&#8217;s network
2782 configuration.</p>
2783 </div>
2784 <div class="paragraph">
2785 <p>For non root users, NetworkManager controls access to its APIs via
2786 <a href="privileges.html">Policy Kit</a> and a user logged into Cockpit will have
2787 the same permissions as they do from the command line.</p>
2788 </div>
2789 <div class="paragraph">
2790 <p>To perform similar tasks from the command line, use the
2791 <a href="https://fedoraproject.org/wiki/Networking/CLI">nmcli</a> command:</p>
2792 </div>
2793 <div class="literalblock">
2794 <div class="content">
2795 <pre>$ nmcli general status
2796 STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN
2797 connected full enabled enabled enabled enabled</pre>
2798 </div>
2799 </div>
2800 <div class="paragraph">
2801 <p>Devices marked as "not managed" with the <code>NM_CONTROLLED=no</code> setting
2802 will not be displayed in the interface.</p>
2803 </div>
2804 </div>
2805 <div class="sect2">
2806 <h3 id="feature-firewall">Firewall</h3>
2807 <div class="paragraph">
2808 <p>Cockpit uses <a href="https://www.firewalld.org">firewalld</a> to interact with the
2809 system&#8217;s firewall. No firewall configuration UI will be shown if
2810 firewalld is not installed.</p>
2811 </div>
2812 <div class="paragraph">
2813 <p>Firewalld controls access to its APIs via PolicyKit. The user logged
2814 into Cockpit needs to have the appropriate permissions to view or modify
2815 the settings.</p>
2816 </div>
2817 <div class="paragraph">
2818 <p>Cockpit can currently only show, add, and remove predefined firewalld
2819 services in the default zone.</p>
2820 </div>
2821 <div class="paragraph">
2822 <p>To perform similar tasks from the command line, use
2823 <a href="https://www.firewalld.org/documentation/man-pages/firewall-cmd.html">firewall-cmd</a>.
2824 For example, to get the same list of allowed services that Cockpit
2825 displays:</p>
2826 </div>
2827 <div class="literalblock">
2828 <div class="content">
2829 <pre>$ sudo firewall-cmd --list-services
2830 dhcpv6-client samba-client mdns ssh cockpit</pre>
2831 </div>
2832 </div>
2833 <div class="paragraph">
2834 <p>To enable an additional service, use:</p>
2835 </div>
2836 <div class="literalblock">
2837 <div class="content">
2838 <pre>$ firewall-cmd --add-service pop3
2839 success</pre>
2840 </div>
2841 </div>
2842 </div>
2843 <div class="sect2">
2844 <h3 id="feature-storaged">storaged</h3>
2845 <div class="paragraph">
2846 <p>If available on the system, Cockpit uses
2847 <a href="https://github.com/storaged-project/storaged/"><code>storaged</code></a> to configure
2848 and monitor storage, disks, mounts etc. on the system. This
2849 functionality is present in the Cockpit <em>storaged</em> package.</p>
2850 </div>
2851 <div class="paragraph">
2852 <p>The <code>storaged</code> project is originally based on a project called
2853 <a href="https://www.freedesktop.org/wiki/Software/udisks/"><code>udisks</code></a> and added
2854 support for many more features such as
2855 <a href="https://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)">LVM</a>,
2856 <a href="https://en.wikipedia.org/wiki/ISCSI">iSCSI</a>,
2857 <a href="https://en.wikipedia.org/wiki/Linux_DM_Multipath">Multipath</a>, and
2858 <a href="https://btrfs.wiki.kernel.org/index.php/Main_Page">BTRFS</a>. The same tools
2859 and backwards compatible API are available between <code>storaged</code> and
2860 <code>udisks</code> the projects. Cockpit can use <code>udisks</code> but disables many of
2861 it&#8217;s storage related features, including updating <code>/etc/fstab</code> and
2862 <code>/etc/crypttab</code> for stability reasons.</p>
2863 </div>
2864 <div class="paragraph">
2865 <p>For non root users, storaged controls access to its APIs via
2866 <a href="privileges.html">Policy Kit</a> and a user logged into Cockpit will have
2867 the same permissions as they do from the command line.</p>
2868 </div>
2869 <div class="paragraph">
2870 <p>To perform similar tasks from the command line, use the <code>storagedctl</code>
2871 command:</p>
2872 </div>
2873 <div class="literalblock">
2874 <div class="content">
2875 <pre>$ udisksctl dump
2876 ...</pre>
2877 </div>
2878 </div>
2879 <div class="paragraph">
2880 <p>To perform LVM tasks, you may use the various LVM commands, such as
2881 <code>vgcreate</code>, <code>lvresize</code> and so on. Cockpit will detect such changes
2882 made at the command line.</p>
2883 </div>
2884 <div class="paragraph">
2885 <p>Cockpit recognizes devices with multiple paths and can start the
2886 <code>multipathd</code> service in case it is not running. On the command line,
2887 you can control multipath features with the <code>mpathconf</code>,
2888 <code>multipathd</code>, and <code>multipath</code> commands.</p>
2889 </div>
2890 <div class="paragraph">
2891 <p>To manage iSCSI initiators from the command line, you can use
2892 <code>iscsiadm</code> and related tools.</p>
2893 </div>
2894 </div>
2895 <div class="sect2">
2896 <h3 id="feature-users">User Tools</h3>
2897 <div class="paragraph">
2898 <p>Cockpit uses the usual tools to create and modify local user accounts.
2899 Examples are <code>useradd</code>, <code>usermod</code> and <code>passwd</code>. These same tools
2900 are available for use on the command line.</p>
2901 </div>
2902 </div>
2903 <div class="sect2">
2904 <h3 id="feature-realmd">realmd</h3>
2905 <div class="paragraph">
2906 <p>If available on the system, Cockpit uses
2907 <a href="https://www.freedesktop.org/software/realmd/">realmd</a> and the DBus APIs
2908 it provides to configure the system&#8217;s Active Directory or IPA domain
2909 membership.</p>
2910 </div>
2911 <div class="paragraph">
2912 <p>Not all systems can join all kinds of domains. This depends on the
2913 availability of the necessary client software.</p>
2914 </div>
2915 <div class="paragraph">
2916 <p>For non root users, realmd controls access to its APIs via
2917 <a href="privileges.html">Policy Kit</a> and a user logged into Cockpit will have
2918 the same permissions as they do from the command line.</p>
2919 </div>
2920 <div class="paragraph">
2921 <p>To perform similar tasks from the command line, use the
2922 <a href="https://www.freedesktop.org/software/realmd/docs/realm.html">realm</a>
2923 command:</p>
2924 </div>
2925 <div class="literalblock">
2926 <div class="content">
2927 <pre>$ realm join example.com
2928 Password for Administrator:</pre>
2929 </div>
2930 </div>
2931 <div class="paragraph">
2932 <p><a href="http://www.freedesktop.org/software/realmd/">realmd</a> sets up
2933 domain-qualified user names by default, i. e. login user names look like
2934 &#8220;[email protected]&#8221;. For using unqualified names (just &#8220;user&#8221;),
2935 set the <code>fully-qualified-names</code> option in
2936 <a href="https://www.freedesktop.org/software/realmd/docs/realmd-conf.html">/etc/realmd.conf</a>
2937 before joining a domain.</p>
2938 </div>
2939 <div class="paragraph">
2940 <p>Cockpit requests an SSL certificate from the IPA server for
2941 <code>cockpit-ws</code> with the
2942 <a href="https://www.freeipa.org/page/Certmonger">ipa-getcert</a> command.</p>
2943 </div>
2944 </div>
2945 <div class="sect2">
2946 <h3 id="feature-terminal">Terminal</h3>
2947 <div class="paragraph">
2948 <p>Cockpit provides a standard shell in a terminal. This shell and the
2949 processes running in it have the <a href="privileges.html">same privileges</a> as if
2950 the user had logged in via SSH.</p>
2951 </div>
2952 </div>
2953 <div class="sect2">
2954 <h3 id="feature-pcp">PCP Metrics</h3>
2955 <div class="paragraph">
2956 <p>If available, Cockpit uses the <a href="https://pcp.io/">Performance Co-Pilot</a>
2957 framework to gather metrics data about the system. This data is used to
2958 display the history graphs on the "Metrics and history" page. Cockpit
2959 can use the PCP logging feature to display archived data about the
2960 system from a different point in time. If PCP is not available, then
2961 Cockpit gathers the metrics data itself, but archival features are not
2962 available.</p>
2963 </div>
2964 <div class="paragraph">
2965 <p>Whether or not metrics are archived depends on whether the
2966 <a href="https://linux.die.net/man/1/pmlogger"><code>pmlogger.service</code></a> systemd unit
2967 is running or not. The "Enable PCP metrics collector" button on the
2968 Metrics page will enable and start this service.</p>
2969 </div>
2970 <div class="paragraph">
2971 <p>To see similar metrics data from the command line, you can use tools
2972 like <a href="https://linux.die.net/man/1/pmstat"><code>pmstat</code></a> or
2973 <a href="https://linux.die.net/man/1/pminfo"><code>pminfo</code></a>:</p>
2974 </div>
2975 <div class="literalblock">
2976 <div class="content">
2977 <pre>$ pmstat
2978 @ Sat Sep 26 15:30:10 2015
2979 loadavg memory swap io system cpu
2980 1 min swpd free buff cache pi po bi bo in cs us sy id
2981 4.19 0 20710m 605148 6450m 0 0 0 2548 5688 14K 19 3 76
2982 ...</pre>
2983 </div>
2984 </div>
2985 <div class="paragraph">
2986 <p>These metrics can also be exposed to other machines on a TCP port with
2987 <a href="https://linux.die.net/man/1/pmproxy">pmproxy</a> and
2988 <a href="https://redis.io/">Redis</a> or <a href="https://valkey.io/">Valkey</a>:</p>
2989 </div>
2990 <div class="literalblock">
2991 <div class="content">
2992 <pre>systemctl enable --now redis pmproxy
2993 # if you use firewalld, open port 44322:
2994 firewall-cmd --permanent --add-service pmproxy
2995 firewall-cmd --reload</pre>
2996 </div>
2997 </div>
2998 <div class="paragraph">
2999 <p>This allows you to gather and visualize PCP metrics from multiple
3000 machines with <a href="https://grafana.com/">Grafana</a> and the
3001 <a href="https://grafana-pcp.readthedocs.io">PCP Grafana plugin</a>.</p>
3002 </div>
3003 </div>
3004 <div class="sect2">
3005 <h3 id="feature-machines">Multiple Machines</h3>
3006 <div class="admonitionblock warning">
3007 <table>
3008 <tr>
3009 <td class="icon">
3010 <div class="title">Warning</div>
3011 </td>
3012 <td class="content">
3013 <div class="paragraph">
3014 <p>This feature is deprecated as of Cockpit 322.</p>
3015 </div>
3016 </td>
3017 </tr>
3018 </table>
3019 </div>
3020 <div class="paragraph">
3021 <p>Cockpit can connect to multiple machines from a single Cockpit session.
3022 These are listed in the host switcher.</p>
3023 </div>
3024 <div class="paragraph">
3025 <p>These additional machines are accessed via SSH from the machine that the
3026 first machine connected to, and are <a href="authentication.html">authenticated</a>
3027 with the logged in user&#8217;s password and/or SSH keys.</p>
3028 </div>
3029 <div class="paragraph">
3030 <p>SSH host keys are stored in <code>/etc/ssh/ssh_known_hosts</code>.</p>
3031 </div>
3032 <div class="paragraph">
3033 <p>The machine data is stored in <code>/etc/cockpit/machines.d/*.json</code>, or
3034 below <code>$XDG_CONFIG_DIRS</code> if set (see
3035 <a href="./cockpit.conf.5.html">cockpit.conf</a>). Settings in lexicographically
3036 later files amend or override settings in earlier ones. Cockpit itself
3037 writes into <code>99-webui.json</code>; packages or admins who want to
3038 pre-configure machines should ship files like <code>05-mymachine.json</code> so
3039 that changes from the web interface override the pre-configured files.</p>
3040 </div>
3041 <div class="paragraph">
3042 <p>Each JSON file contains an object that maps machine IDs to objects that
3043 define the properties of that machine. The ID can be a human readable
3044 name or an IP address or any other unique value, and is shown in the web
3045 interface until connecting to it the first time, at which point the web
3046 interface will show the machine&#8217;s host name.</p>
3047 </div>
3048 <div class="paragraph">
3049 <p>The following properties are recognized:</p>
3050 </div>
3051 <div class="dlist">
3052 <dl>
3053 <dt class="hdlist1"><code>"address"</code></dt>
3054 <dd>
3055 <p><em>(string, mandatory)</em> IP address or DNS name of the machine</p>
3056 </dd>
3057 <dt class="hdlist1"><code>"visible"</code></dt>
3058 <dd>
3059 <p><em>(boolean, optional)</em> If <code>true</code>, the machine will be displayed and
3060 available for managing with Cockpit. If <code>false</code> (the default), it
3061 will not be displayed, but still taken into account for type-ahead
3062 search when adding new machines in the web interface.</p>
3063 </dd>
3064 <dt class="hdlist1"><code>"user"</code></dt>
3065 <dd>
3066 <p><em>(string, optional)</em> User name on the remote machine. When not given,
3067 Cockpit will default to the user name that was being used to log into
3068 Cockpit itself.</p>
3069 </dd>
3070 <dt class="hdlist1"><code>"port"</code></dt>
3071 <dd>
3072 <p><em>(integer, optional)</em> ssh port of the remote machine. When not given,
3073 the default port 22 is used.</p>
3074 </dd>
3075 <dt class="hdlist1"><code>"color"</code></dt>
3076 <dd>
3077 <p><em>(string, optional)</em> Color to assign to the machine label in the web
3078 interface. This can be either given as
3079 <code>rgb(r_value, g_value, b_value)</code> with each value being an integer
3080 between 0 and 255, or as a color name like <code>yellow</code>. When not given,
3081 Cockpit will assign an unused color automatically.</p>
3082 </dd>
3083 </dl>
3084 </div>
3085 <div class="paragraph">
3086 <p>Example:</p>
3087 </div>
3088 <div class="literalblock">
3089 <div class="content">
3090 <pre>{
3091 "web server": {
3092 "address": "192.168.2.4",
3093 "visible": true,
3094 "color": "rgb(100, 200, 0)",
3095 "user": "admin"
3096 },
3097 "192.168.2.1": {
3098 "address": "192.168.2.1",
3099 "port": 2222,
3100 "visible": true,
3101 "color": "green"
3102 }
3103 }</pre>
3104 </div>
3105 </div>
3106 </div>
3107 <div class="sect2">
3108 <h3 id="feature-selinux">SELinux Policy</h3>
3109 <div class="paragraph">
3110 <p>If present on the system Cockpit can set the SELinux mode to enforcing
3111 or permissive. It can also use <code>setroubleshootd</code> to show audit issues
3112 and apply suggested fixes.</p>
3113 </div>
3114 <div class="paragraph">
3115 <p>To perform similar tasks from the command line use the <code>setenforce</code>
3116 and <code>sealert</code> tools.</p>
3117 </div>
3118 <div class="paragraph">
3119 <p>To clear out all the information that <code>setroubleshootd</code> tracks, you
3120 can use a commands like:</p>
3121 </div>
3122 <div class="literalblock">
3123 <div class="content">
3124 <pre>$ sudo killall setroubleshootd
3125 $ sudo rm -rf /var/lib/setroubleshoot/*</pre>
3126 </div>
3127 </div>
3128 </div>
3129 <div class="sect2">
3130 <h3 id="feature-tuned">Tuned Profiles</h3>
3131 <div class="paragraph">
3132 <p>If present on the system Cockpit can use Tuned and the DBUS API it
3133 provides to set system performance profiles. To perform similar tasks
3134 from the command line, use the <code>tuned-adm</code> command.</p>
3135 </div>
3136 </div>
3137 <div class="sect2">
3138 <h3 id="feature-sosreport">SOS Report</h3>
3139 <div class="paragraph">
3140 <p>If present on the system Cockpit can use <code>sosreport</code> to collect system
3141 configuration and diagnostic information.</p>
3142 </div>
3143 <div class="paragraph">
3144 <p>To perform similar tasks from the command line, use the <code>sosreport</code>
3145 command.</p>
3146 </div>
3147 </div>
3148 <div class="sect2">
3149 <h3 id="feature-packagekit">Package Updates</h3>
3150 <div class="paragraph">
3151 <p>Cockpit uses the
3152 <a href="https://www.freedesktop.org/software/PackageKit/gtk-doc/api-reference.html">PackageKit</a>
3153 D-Bus API to get information about available package updates and to
3154 apply them, in an Operating System independent manner.</p>
3155 </div>
3156 <div class="paragraph">
3157 <p>To perform similar tasks from the command line, use the
3158 <a href="https://www.freedesktop.org/software/PackageKit/pk-using.html">pkcon</a>
3159 command:</p>
3160 </div>
3161 <div class="literalblock">
3162 <div class="content">
3163 <pre>$ pkcon refresh
3164
3165 $ pkcon get-updates
3166 Available sudo-1.8.20p2-1.fc26.x86_64 (updates-testing)
3167 Allows restricted root access for specified users
3168 Available vim-filesystem-2:8.0.617-1.fc26.x86_64 (updates-testing)
3169 VIM filesystem layout
3170 Available vim-minimal-2:8.0.617-1.fc26.x86_64 (updates-testing)
3171 A minimal version of the VIM editor
3172
3173 $ pkcon get-update-detail sudo
3174 Details about the update:6.x86_64 [fedora]
3175 Package: sudo-1.8.20p2-1.fc26.x86_64
3176 Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1452941
3177 Update text: - update to 1.8.20p2
3178 - added sudo package to dnf/yum protected packages
3179
3180 $ pkcon update
3181 The following packages have to be updated:
3182 sudo-1.8.20p2-1.fc26.x86_64 Allows restricted root access for specified users
3183 vim-filesystem-2:8.0.617-1.fc26.x86_64 VIM filesystem layout
3184 vim-minimal-2:8.0.617-1.fc26.x86_64 A minimal version of the VIM editor
3185 Proceed with changes? [N/y] y
3186 [...]</pre>
3187 </div>
3188 </div>
3189 <div class="paragraph">
3190 <p>Of course you can also use your Operating System specific commands for
3191 that, such as <code>dnf updateinfo info</code> on Fedora or <code>sudo apt upgrade</code>
3192 on Debian.</p>
3193 </div>
3194 </div>
3195 </div>
3196 </div>
3197 <div class="sect1">
3198 <h2 id="development">Developer Guide</h2>
3199 <div class="sectionbody">
3200 <div class="sect2">
3201 <h3 id="embedding">Embedding and Integrating Cockpit</h3>
3202 <div class="paragraph">
3203 <p>Cockpit can be embedded in other web applications either as a whole or
3204 specific Cockpit components can be integrated. Due to frame security
3205 policy restrictions, this only works if Cockpit and the web application
3206 have the <em>same origin</em>; this is commonly achieved by running both from a
3207 common reverse proxy.</p>
3208 </div>
3209 <div class="sect3">
3210 <h4 id="embedding-full">Embedding the Cockpit Interface</h4>
3211 <div class="paragraph">
3212 <p>Cockpit can be embedded into a larger web page as a frame. To embed the
3213 entire Cockpit Window use the URI: <code>https://server.example.com:9090/</code></p>
3214 </div>
3215 <div class="listingblock">
3216 <div class="content">
3217 <pre class="highlight"><code class="language-html" data-lang="html">&lt;html&gt;
3218 &lt;head&gt;
3219 &lt;title&gt;Embedded Cockpit&lt;/title&gt;
3220 &lt;/head&gt;
3221 &lt;body&gt;
3222 This is Cockpit.
3223 &lt;br/&gt;
3224 &lt;iframe width="800px" height="600px"
3225 src="https://server.example.com:9090/"/&gt;
3226 &lt;/body&gt;
3227 &lt;/html&gt;</code></pre>
3228 </div>
3229 </div>
3230 </div>
3231 <div class="sect3">
3232 <h4 id="embedding-components">Integrating Cockpit Components into Web Applications</h4>
3233 <div class="paragraph">
3234 <p>Instead of embedding the entirety of Cockpit, you can integrate specific
3235 components. Only those components explicitly documented as API should be
3236 integrated. Other components can and will change regularly.</p>
3237 </div>
3238 <div class="paragraph">
3239 <p>The component will load from the server in question and a WebSocket
3240 connection will be established with the server to relay the component&#8217;s
3241 message stream.</p>
3242 </div>
3243 <div class="paragraph">
3244 <p>Cockpit components are HTML files contained in <a href="packages.html">packages</a>.
3245 These can be placed in an iframe or web browser window. Each documented
3246 and stable component has a well-known URL and these are documented in
3247 the <a href="development.html">API reference</a>. Each component URL begins with the
3248 string <code>/cockpit/@localhost/</code> followed a package name, and then the
3249 component itself.</p>
3250 </div>
3251 <div class="paragraph">
3252 <p>For example the <a href="api-terminal-html.html">terminal.html</a> in the
3253 <a href="api-system.html">system</a> package, has this URL:
3254 <code>/cockpit/@localhost/system/terminal.html</code></p>
3255 </div>
3256 <div class="listingblock">
3257 <div class="content">
3258 <pre class="highlight"><code class="language-html" data-lang="html">&lt;html&gt;
3259 &lt;head&gt;
3260 &lt;title&gt;Embedded Terminal&lt;/title&gt;
3261 &lt;/head&gt;
3262 &lt;body&gt;
3263 This is a terminal.
3264 &lt;br/&gt;
3265 &lt;iframe width="800px" height="600px"
3266 src="https://server.example.com:9090/cockpit/@localhost/system/terminal.html"/&gt;
3267 &lt;/body&gt;
3268 &lt;/html&gt;</code></pre>
3269 </div>
3270 </div>
3271 </div>
3272 <div class="sect3">
3273 <h4 id="embedding-deep">Deep Integration</h4>
3274 <div class="paragraph">
3275 <p>Most often <a href="#embedding-components">simple integration</a> will be used
3276 to bring Cockpit components into web applications. However it is also
3277 possible to do deep integration for embedders who wish to perform
3278 non-standard authentication with the server, and relay the component&#8217;s
3279 message stream to the server themselves.</p>
3280 </div>
3281 <div class="admonitionblock warning">
3282 <table>
3283 <tr>
3284 <td class="icon">
3285 <div class="title">Warning</div>
3286 </td>
3287 <td class="content">
3288 <div class="paragraph">
3289 <p>Deep integration capability is in heavy flux and is not yet documented.</p>
3290 </div>
3291 </td>
3292 </tr>
3293 </table>
3294 </div>
3295 </div>
3296 <div class="sect3">
3297 <h4 id="embedding-cors">Pinging Cockpit</h4>
3298 <div class="paragraph">
3299 <p>When embedding Cockpit or integrating Cockpit components, it may be
3300 necessary to check whether Cockpit is available on a server before
3301 proceeding.</p>
3302 </div>
3303 <div class="paragraph">
3304 <p>To do this perform a <code>/ping</code> request to Cockpit. This is a simple HTTP
3305 GET request. It returns the following:</p>
3306 </div>
3307 <div class="literalblock">
3308 <div class="content">
3309 <pre>GET: https://server.example.com:9090/ping
3310 200 OK: { "service": "cockpit" }</pre>
3311 </div>
3312 </div>
3313 <div class="paragraph">
3314 <p>The <code>/ping</code> request allows
3315 <a href="https://en.wikipedia.org/wiki/Cross-origin_resource_sharing">Cross Origin
3316 Resource Sharing</a> headers and as such can be performed from Javascript
3317 code with any origin. The request can also be made via plain HTTP
3318 without SSL. It is by design that no further information is present in
3319 the response.</p>
3320 </div>
3321 <div class="paragraph">
3322 <p>A complete example of using <code>/ping</code> is available in the Cockpit
3323 sources in the <code>/examples/ping-server/</code> directory.</p>
3324 </div>
3325 </div>
3326 </div>
3327 <div class="sect2">
3328 <h3 id="packages">Cockpit Packages</h3>
3329 <div class="paragraph">
3330 <p>Cockpit is separated into various packages, each of which brings
3331 specific features and/or code.</p>
3332 </div>
3333 <div class="admonitionblock warning">
3334 <table>
3335 <tr>
3336 <td class="icon">
3337 <div class="title">Warning</div>
3338 </td>
3339 <td class="content">
3340 <div class="paragraph">
3341 <p>In addition, any APIs or behavior not explicitly documented here is an
3342 internal API and can be changed at any time.</p>
3343 </div>
3344 </td>
3345 </tr>
3346 </table>
3347 </div>
3348 <div class="sect3">
3349 <h4 id="package-layout">Layout of Package Files</h4>
3350 <div class="paragraph">
3351 <p>A package consists of one or more files placed in a directory or its
3352 subdirectories. It must have a <code>manifest.json</code> file and follow certain
3353 naming conventions.</p>
3354 </div>
3355 <div class="paragraph">
3356 <p>The name of a package is the name of the directory.</p>
3357 </div>
3358 <div class="paragraph">
3359 <p>The name of the package must be ASCII alphanumeric, and may contain an
3360 underscore. Names of directories and files in the package must consist
3361 of ASCII alphanumeric along with dash, underscore, dot, and comma. No
3362 spaces are allowed.</p>
3363 </div>
3364 <div class="paragraph">
3365 <p>Cockpit uses the data directories from the
3366 <a href="https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG
3367 Base Directory Specification</a> to locate packages. The <code>$XDG_DATA_DIRS</code>
3368 represents a colon separate list of system data directories, and
3369 <code>$XDG_DATA_HOME</code> is a user specific data directory. If the environment
3370 variables are not set, defaults are used, according to the spec. If
3371 cockpit has been built with an alternate <code>--prefix=/path</code> then the
3372 <code>$prefix/share/cockpit</code> is used by default.</p>
3373 </div>
3374 <div class="paragraph">
3375 <p>A <code>cockpit/</code> subdirectories in any of these data directories is the
3376 location where packages are loaded by Cockpit. If Cockpit finds a
3377 package with the same name, in multiple data directories, then the first
3378 one wins. According to the spec the first data directory is
3379 <code>$XDG_DATA_HOME</code> and then <code>$XDG_DATA_DIRS</code> in order.</p>
3380 </div>
3381 <div class="paragraph">
3382 <p>This means that, by default the following directories are searched for
3383 cockpit packages, and in this order:</p>
3384 </div>
3385 <div class="ulist">
3386 <ul>
3387 <li>
3388 <p><code>~/.local/share/cockpit/</code></p>
3389 </li>
3390 <li>
3391 <p><code>/usr/local/share/cockpit/</code></p>
3392 </li>
3393 <li>
3394 <p><code>/usr/share/cockpit/</code></p>
3395 </li>
3396 </ul>
3397 </div>
3398 <div class="paragraph">
3399 <p>Packages placed in <code>$XDG_DATA_HOME</code> are not cached by Cockpit or the
3400 web browser. Other packages are cached aggressively, and are accessed
3401 using a checksum of the files in the packages and their names.</p>
3402 </div>
3403 <div class="paragraph">
3404 <p>You can use the following command to list the packages installed on a
3405 server. You&#8217;ll note that it&#8217;s output may change when you run the command
3406 as different users, if there are packages installed in the user&#8217;s home
3407 directory.</p>
3408 </div>
3409 <div class="literalblock">
3410 <div class="content">
3411 <pre>$ cockpit-bridge --packages
3412 ...</pre>
3413 </div>
3414 </div>
3415 <div class="paragraph">
3416 <p>To further clarify things, here is an example package called
3417 "my-package" and its file layout:</p>
3418 </div>
3419 <div class="literalblock">
3420 <div class="content">
3421 <pre>/usr/share/cockpit/
3422 my-package/
3423 manifest.json
3424 file.html
3425 some.js</pre>
3426 </div>
3427 </div>
3428 <div class="paragraph">
3429 <p>Place or symlink packages in your <code>~/.local/share/cockpit</code> directory
3430 (or appropriate <code>$XDG_DATA_HOME</code> location) that you would like to
3431 modify and develop. System installed packages should not change while
3432 Cockpit is running.</p>
3433 </div>
3434 </div>
3435 <div class="sect3">
3436 <h4 id="_package_manifest">Package Manifest</h4>
3437 <div class="paragraph">
3438 <p>Each package has a <code>manifest.json</code> file. It is a JSON object. The
3439 following fields may be present in the manifest:</p>
3440 </div>
3441 <div class="dlist">
3442 <dl>
3443 <dt class="hdlist1">content-security-policy</dt>
3444 <dd>
3445 <p>By default Cockpit serves packages using a strict
3446 <a href="https://en.wikipedia.org/wiki/Content_Security_Policy">Content Security
3447 Policy</a>, which among other things does not allow inline styles or
3448 scripts. This can be overridden on a per-package basis, with this
3449 setting.
3450 +
3451 If the overridden content security policy does not contain a
3452 <code>default-src</code>, <code>connect-src</code>, <code>base-uri</code>, <code>form-action</code>,
3453 <code>object-src</code>, or <code>block-all-mixed-content</code> then these will be
3454 added to the policy from the manifest.</p>
3455 </dd>
3456 <dt class="hdlist1">name</dt>
3457 <dd>
3458 <p>An optional string that changes the name of the package. Normally
3459 packages derive their name from the directory that they are located
3460 in. This field overrides that name.</p>
3461 </dd>
3462 <dt class="hdlist1">priority</dt>
3463 <dd>
3464 <p>An optional integer that specifies which package is preferred in cases
3465 where there are conflicts. For example given two packages with the
3466 same <code>name</code> a package is chosen based on its priority. A higher integer
3467 means higher priority.</p>
3468 </dd>
3469 <dt class="hdlist1">conditions</dt>
3470 <dd>
3471 <p>An optional list of <code>{"predicate": "value"}</code> objects. Cockpit will
3472 only consider the package if <em>all</em> conditions are met. This is
3473 preferable to using <code>priority</code>.<br>
3474 <br>
3475 Currently supported predicates are <code>path-exists</code> and <code>path-not-exists</code>
3476 (since Cockpit 286) and <code>any</code> (since Cockpit 348). <code>any</code> accepts a
3477 list of conditions and evaluates to true if <em>at least one</em> of the nested
3478 conditions is met. Unknown predicates are ignored.</p>
3479 </dd>
3480 <dt class="hdlist1">requires</dt>
3481 <dd>
3482 <p>An optional JSON object that contains a <code>"cockpit"</code> string version
3483 number. The package will only be usable if the Cockpit bridge and
3484 javascript base are equal or newer than the given version number.</p>
3485 </dd>
3486 <dt class="hdlist1">version</dt>
3487 <dd>
3488 <p>An informational version number for the package.</p>
3489 </dd>
3490 <dt class="hdlist1">preload</dt>
3491 <dd>
3492 <p>A list of identifiers of the components that should be preloaded.
3493 Normally, the files of a component are loaded when the user navigates
3494 to it for the first time. The files of a preloaded component are
3495 loaded immediately after the user logs in, and the initialization code
3496 of the component is invoked.
3497 +
3498 The value of this field is an array of strings, where each string is
3499 one of the keys used in the <code>dashboard</code>, <code>menu</code>, or <code>tools</code>
3500 fields that are explained below.</p>
3501 </dd>
3502 <dt class="hdlist1">parent</dt>
3503 <dd>
3504 <p>This option is used when module does not have its own menu item but is
3505 a part of a different module. This is described by JSON object with
3506 properties <code>component</code> which takes name of the superordinate
3507 component and <code>docs</code> with list of documentation URLs for the given
3508 page. See below for structure of <code>docs</code> property.</p>
3509 </dd>
3510 </dl>
3511 </div>
3512 <div class="paragraph">
3513 <p>In addition, the following keys contain information about where
3514 components of the package should appear in Cockpit&#8217;s user interface.
3515 Each of these keys is optional and contains an object mapping unique
3516 identifiers to menu items, which are described below. (The naming of
3517 these fields doesn&#8217;t perfectly match the current user interface for
3518 historical reasons.)</p>
3519 </div>
3520 <div class="dlist">
3521 <dl>
3522 <dt class="hdlist1">dashboard</dt>
3523 <dd>
3524 <p>Dashboard items appear in the menu under the section <em>Apps</em>.</p>
3525 </dd>
3526 <dt class="hdlist1">menu</dt>
3527 <dd>
3528 <p>These items appear in the menu under the section <em>System</em>. This
3529 section is roughly ordered into these categories (with their <em>order</em>
3530 in parentheses):
3531 +</p>
3532 <div class="ulist">
3533 <ul>
3534 <li>
3535 <p>System Information (10)</p>
3536 </li>
3537 <li>
3538 <p>Logs (20)</p>
3539 </li>
3540 <li>
3541 <p>Configuring major subsystems (30-40)</p>
3542 </li>
3543 <li>
3544 <p>Things running on the machine (VMs, Containers - 50-60)</p>
3545 </li>
3546 <li>
3547 <p>Implementation Details (Accounts, Services - 70-100)</p>
3548 </li>
3549 </ul>
3550 </div>
3551 </dd>
3552 <dt class="hdlist1">tools</dt>
3553 <dd>
3554 <p>These items appear in the menu under the section <em>Tools</em>.</p>
3555 </dd>
3556 </dl>
3557 </div>
3558 <div class="paragraph">
3559 <p>Menu items and tools are registered using JSON objects that have the
3560 following properties:</p>
3561 </div>
3562 <div class="dlist">
3563 <dl>
3564 <dt class="hdlist1">label</dt>
3565 <dd>
3566 <p>The label for the menu item or tool.</p>
3567 </dd>
3568 <dt class="hdlist1">order</dt>
3569 <dd>
3570 <p>An optional order integer to place this menu item or tool. Lower
3571 integers are listed first.</p>
3572 </dd>
3573 <dt class="hdlist1">path</dt>
3574 <dd>
3575 <p>The relative path to the HTML file within the package that implements
3576 the menu item or tool.</p>
3577 </dd>
3578 <dt class="hdlist1">docs</dt>
3579 <dd>
3580 <p>List of documentation URLs for the given page. Each item is an object
3581 containing <code>label</code> and <code>url</code>.</p>
3582 </dd>
3583 <dt class="hdlist1">keywords</dt>
3584 <dd>
3585 <p>Keywords that describe the page and which are used for searching.
3586 These keywords should be lowercase. Keywords is a list containing
3587 keyword items as described below. Page label is prepended as first
3588 keyword in the first keyword item.</p>
3589 </dd>
3590 </dl>
3591 </div>
3592 <div class="paragraph">
3593 <p>Keyword items are registered using JSON objects that have the following
3594 properties:</p>
3595 </div>
3596 <div class="dlist">
3597 <dl>
3598 <dt class="hdlist1">matches</dt>
3599 <dd>
3600 <p>List of keywords to be matched.</p>
3601 </dd>
3602 <dt class="hdlist1">goto</dt>
3603 <dd>
3604 <p>Optional path that is used for all keywords in this item. When this
3605 argument starts with slash, then it is used as pathname, otherwise it
3606 is used as hash. Defining <code>goto:"page_hash"</code> in page with
3607 <code>path:"/page_path"</code> would redirect to <code>/page_path#page_hash</code>,
3608 while <code>goto:"/page_path"</code> would redirect to <code>/page_path</code> ignoring
3609 default page path.</p>
3610 </dd>
3611 <dt class="hdlist1">weight</dt>
3612 <dd>
3613 <p>How much keywords are prioritized over others. Default is 3.</p>
3614 </dd>
3615 <dt class="hdlist1">translate</dt>
3616 <dd>
3617 <p><code>false</code> when keywords should not be localized. Default is <code>true</code>.</p>
3618 </dd>
3619 </dl>
3620 </div>
3621 <div class="paragraph">
3622 <p>An example manifest.json with some optional properties set:</p>
3623 </div>
3624 <div class="literalblock">
3625 <div class="content">
3626 <pre>{
3627 "version": 0,
3628 "require": {
3629 "cockpit": "120"
3630 },
3631 "tools": {
3632 "mytool": {
3633 "label": "My Tool",
3634 "path": "tool.html"
3635 }
3636 }
3637 }</pre>
3638 </div>
3639 </div>
3640 <div class="literalblock">
3641 <div class="content">
3642 <pre>{
3643 "version": 0,
3644 "require": {
3645 "cockpit": "120"
3646 },
3647 "conditions": [
3648 {"path-exists": "/usr/bin/mytool"},
3649 {"path-exists": "/etc/mytool.conf"},
3650 {"path-not-exist": "/etc/incompatible-tool"}
3651 ],
3652 "tools": {
3653 "mytool": {
3654 "label": "My Tool",
3655 "path": "tool.html"
3656 }
3657 }
3658 }</pre>
3659 </div>
3660 </div>
3661 <div class="paragraph">
3662 <p>The following example shows how to use disjunctive conditions with <code>any</code>
3663 to specify alternative requirements (available since Cockpit 348). This
3664 package will be available if either <code>/usr/bin/alt1</code> or <code>/usr/bin/alt2</code>
3665 exists. In any case, <code>/etc/incompatible-tool</code> must not exist.</p>
3666 </div>
3667 <div class="literalblock">
3668 <div class="content">
3669 <pre>"conditions": [
3670 {"any": [{"path-exists": "/usr/bin/alt1"}, {"path-exists": "/usr/bin/alt2"}]},
3671 {"path-not-exists": "/etc/incompatible-tool"}
3672 ]</pre>
3673 </div>
3674 </div>
3675 </div>
3676 <div class="sect3">
3677 <h4 id="package-manifest-override">Manifest overrides</h4>
3678 <div class="paragraph">
3679 <p>To change a manifest system-wide, a file
3680 <code>&lt;package-directory-name&gt;.override.json</code> may be placed into
3681 <code>/etc/cockpit/</code>, or below <code>$XDG_CONFIG_DIRS</code> if set (see
3682 <a href="./cockpit.conf.5.html">cockpit.conf</a>). To change it for a particular
3683 user only, put the override into <code>~/.config/cockpit</code>.</p>
3684 </div>
3685 <div class="paragraph">
3686 <p>These override the information in the manifest in the simple
3687 <a href="https://tools.ietf.org/html/rfc7386">JSON Merge Patch</a> format.</p>
3688 </div>
3689 <div class="paragraph">
3690 <p>This can be used to hide or modify menu items of an existing package.
3691 For example <code>/etc/cockpit/systemd.override.json</code> or
3692 <code>~/.config/cockpit/systemd.override.json</code> could hide the <em>Logs</em> menu
3693 item and move the <em>Services</em> menu item to the top of the menu.</p>
3694 </div>
3695 <div class="literalblock">
3696 <div class="content">
3697 <pre>{
3698 "menu": {
3699 "logs": null,
3700 "services": {
3701 "order": -1
3702 }
3703 }
3704 }</pre>
3705 </div>
3706 </div>
3707 </div>
3708 <div class="sect3">
3709 <h4 id="package-links">Package Links and Paths</h4>
3710 <div class="paragraph">
3711 <p>When referring to files in your package, such as in a hyperlink or a
3712 <code>&lt;style&gt;</code> tag or <code>&lt;script&gt;</code> tag, simply use a relative path, and
3713 refer to the files in the same directory. When you need to refer to
3714 files in another package use a relative link.</p>
3715 </div>
3716 <div class="paragraph">
3717 <p>For example here&#8217;s how to include the base <code>cockpit.js</code> script in your
3718 HTML from the <code>latest</code> package:</p>
3719 </div>
3720 <div class="literalblock">
3721 <div class="content">
3722 <pre>&lt;script src="../base1/cockpit.js"&gt;&lt;/script&gt;</pre>
3723 </div>
3724 </div>
3725 <div class="paragraph">
3726 <p>Do not assume you can link to any file in any other package. Refer to
3727 the <a href="development.html">list of API packages</a> for those that are available
3728 for use.</p>
3729 </div>
3730 </div>
3731 <div class="sect3">
3732 <h4 id="package-minified">Content Negotiation</h4>
3733 <div class="paragraph">
3734 <p>In order to support gzipped and/or minified data, the files in a package
3735 are loaded using content negotiation logic. A HTTP request for the file
3736 <code>test.js</code> in the package named <code>mypackage</code> will return
3737 <code>mypackage/test.js</code> or <code>mypackage/test.js.gz</code> (in undefined
3738 preference). If neither exists, then it returns
3739 <code>mypackage/test.js.min</code> or <code>mypackage/test.js.min.gz</code> (again in
3740 undefined preference).</p>
3741 </div>
3742 <div class="paragraph">
3743 <p>When packages are loaded from a system directory, Cockpit optimizes the
3744 file system lookups above, by pre-listing the files. This is one of the
3745 reasons that you should never change packages installed to a system
3746 directory while Cockpit is running.</p>
3747 </div>
3748 </div>
3749 <div class="sect3">
3750 <h4 id="package-api">Using Cockpit API</h4>
3751 <div class="paragraph">
3752 <p>Cockpit has API available for writing packages. There is no API
3753 available for external callers to invoke via HTTP, REST or otherwise.</p>
3754 </div>
3755 <div class="paragraph">
3756 <p>API from various packages can be used to implement Cockpit packages.
3757 Each package listed here has some API available for use. Only the API
3758 explicitly documented should be used.</p>
3759 </div>
3760 <div class="ulist">
3761 <ul>
3762 <li>
3763 <p><a href="development.html">API Listing</a></p>
3764 </li>
3765 </ul>
3766 </div>
3767 <div class="paragraph">
3768 <p>To include javascript from the API, simply load it into your HTML using
3769 a script tag. Alternatively you can use an javascript loader.</p>
3770 </div>
3771 </div>
3772 <div class="sect3">
3773 <h4 id="package-bridges">Bridges for specific tasks</h4>
3774 <div class="paragraph">
3775 <p>On the server side the <a href="cockpit-bridge.1.html">cockpit-bridge</a>(1)
3776 connects to various system APIs that the front end UI requests it to.
3777 There are additional bridges for specific tasks that the main
3778 <code>cockpit-bridge</code> cannot handle, such as using the PCP C library API.</p>
3779 </div>
3780 <div class="paragraph">
3781 <p>These additional bridges can be registered in a <code>"bridges"</code> section of
3782 a package&#8217;s <code>manifest.json</code> file. Building such a bridge is a complex
3783 tasks, and we will skip over that here. However it is useful to adjust
3784 how these additional bridges are called, and so we&#8217;ll look at how they
3785 are registered.</p>
3786 </div>
3787 <div class="paragraph">
3788 <p>An example <code>manifest.json</code> with a bridges section:</p>
3789 </div>
3790 <div class="literalblock">
3791 <div class="content">
3792 <pre>{
3793 "bridges": [
3794 {
3795 "match": { "payload": "metrics1" },
3796 "spawn": [ "/usr/libexec/cockpit-pcp" ]
3797 }
3798 ]
3799 }</pre>
3800 </div>
3801 </div>
3802 <div class="paragraph">
3803 <p>The bridges are considered in the order they are listed in the array.
3804 Use the <code>manifest.json`</code>"priority"` field to control order between
3805 packages. The bridges are registered using JSON objects that have the
3806 following properties:</p>
3807 </div>
3808 <div class="dlist">
3809 <dl>
3810 <dt class="hdlist1">environ</dt>
3811 <dd>
3812 <p>Optional, additional environment variables to pass to the bridge
3813 command.</p>
3814 </dd>
3815 <dt class="hdlist1">match</dt>
3816 <dd>
3817 <p>The <code>"match"</code> object describes which channel open command options
3818 need to match for a given channel to be handed over to this bridge.</p>
3819 </dd>
3820 <dt class="hdlist1">privileged</dt>
3821 <dd>
3822 <p>If set to <code>true</code>, this marks the bridge as a superuser bridge.
3823 Cockpit will start one of these explicitly when trying to escalate the
3824 privileges of a session. A privileged bridge can not have a
3825 <code>"match"</code> property.</p>
3826 </dd>
3827 <dt class="hdlist1">label</dt>
3828 <dd>
3829 <p>Setting this enables selection of privileged bridges in the UI. When
3830 no privileged bridge has a <code>label</code>, then Cockpit will start the
3831 bridge that runs <code>sudo</code>. This is the case in a default Cockpit
3832 installation. When at least one privileged bridge has a <code>label</code> then
3833 the user can select one of them when escalating privileges. As a
3834 special case, if only one bridge has a <code>label</code>, then the step of
3835 selecting a bridge is omitted in the UI and that one bridge is always
3836 started.
3837 +
3838 Thus, if you add a privileged bridge with a <code>label</code> in a new
3839 manifest, Cockpit will use that bridge the next time a user opens the
3840 "Administrative access" dialog. If you want the user to choose between
3841 the <code>sudo</code> method and your new one, you need to duplicate the
3842 <code>sudo</code> bridge definition in your manifest and give it a label.</p>
3843 </dd>
3844 <dt class="hdlist1">problem</dt>
3845 <dd>
3846 <p>If a problem is specified, and this bridge fails to start up then
3847 channels will be closed with this problem code. Otherwise later
3848 bridges or internal handlers for the channel will be invoked.</p>
3849 </dd>
3850 <dt class="hdlist1">spawn</dt>
3851 <dd>
3852 <p>The command and arguments to invoke.</p>
3853 </dd>
3854 </dl>
3855 </div>
3856 <div class="paragraph">
3857 <p>The <code>spawn</code> and <code>environ</code> values can be dynamically taken from a
3858 matching open command values. When a value in either the <code>spawn</code> or
3859 <code>environ</code> array contains a named variable wrapped in <code>${}</code>, the
3860 variable will be replaced with the value contained in the matching open
3861 command. Only named variables are supported and name can only contain
3862 letters, numbers and the following symbols: <code>._-</code></p>
3863 </div>
3864 <div class="paragraph">
3865 <p>For example a bridges section like:</p>
3866 </div>
3867 <div class="literalblock">
3868 <div class="content">
3869 <pre>{
3870 "bridges": [
3871 {
3872 "match": { "payload": "example" },
3873 "environ": [ "TAG=${tag}" ],
3874 "spawn: [ "/example-bridge", "--tag", "${tag}" ],
3875 "problem": "access-denied"
3876 }
3877 ]
3878 }</pre>
3879 </div>
3880 </div>
3881 <div class="paragraph">
3882 <p>when a open command is received with a payload of <code>example</code> with
3883 <code>tag</code> value of <code>tag1</code>. The following command will be spawned</p>
3884 </div>
3885 <div class="literalblock">
3886 <div class="content">
3887 <pre>TAG=tag1 /example-bridge --tag tag1</pre>
3888 </div>
3889 </div>
3890 <div class="paragraph">
3891 <p>Processes that are reused so if another open command with a "tag" of
3892 <code>tag1</code> is received. The open command will be passed to existing
3893 process, rather than spawning a new one. However a open command with an
3894 tag of <code>tag2</code> will spawn a new command:</p>
3895 </div>
3896 <div class="literalblock">
3897 <div class="content">
3898 <pre>TAG=tag2 /example-bridge --tag tag2</pre>
3899 </div>
3900 </div>
3901 <div class="paragraph">
3902 <p>If you need to include <code>${}</code>, as an actual value in your arguments you
3903 can escape it by prefixing it with a <code>\</code></p>
3904 </div>
3905 </div>
3906 <div class="sect3">
3907 <h4 id="package-replace">Replacing an existing package</h4>
3908 <div class="paragraph">
3909 <p>If the functionality in a package replaces that of another package then
3910 it can replace that package by claiming the same <code>name</code> and a higher
3911 <code>priority</code>.</p>
3912 </div>
3913 <div class="paragraph">
3914 <p>For example, a package in the <code>/usr/share/cockpit/disks</code> directory
3915 could replace Cockpit&#8217;s <em>storage</em> package with a <code>manifest.json</code> like
3916 this:</p>
3917 </div>
3918 <div class="literalblock">
3919 <div class="content">
3920 <pre>{
3921 "version": 0,
3922 "name": "storage",
3923 "priority": 10,
3924 "menu": {
3925 "index": {
3926 "label": "Disk Storage",
3927 "order": 15
3928 }
3929 }
3930 }</pre>
3931 </div>
3932 </div>
3933 </div>
3934 </div>
3935 <div class="sect2">
3936 <h3 id="urls">Cockpit URLs</h3>
3937 <div class="paragraph">
3938 <p>Cockpit URLs follow a specific structure, related to the components they
3939 are loading. Various components are loaded in <code>&lt;iframe&gt;</code> tags. The
3940 URLs for these components are described first. Further down below you
3941 can find information about the top level bookmarkable Cockpit address
3942 URLs.</p>
3943 </div>
3944 <div class="sect3">
3945 <h4 id="urls-components">Component URLs</h4>
3946 <div class="paragraph">
3947 <p>Cockpit components are HTML documents. They are organized into
3948 <a href="packages.html">packages</a>. Each package contains information about which
3949 HTML components are available in that package. Components should always
3950 use relative URLs to access resources, such as images, scripts or CSS
3951 files, even if they refer to a resource in another package.</p>
3952 </div>
3953 <div class="paragraph">
3954 <p>The following are valid component URLs, each bit will be discussed
3955 below:</p>
3956 </div>
3957 <div class="literalblock">
3958 <div class="content">
3959 <pre>/cockpit/@localhost/package/component.html#/hash
3960 /cockpit/$checksum/package/component.html#/hash
3961 /cockpit/@server.example.com/package/component.html#/hash
3962 /cockpit+embedder/@localhost/package/component.html#/hash</pre>
3963 </div>
3964 </div>
3965 <div class="paragraph">
3966 <p>All resource URLs are under the <code>/cockpit</code> namespace. In cases where a
3967 Cockpit component is being <a href="embedding.html">embedded</a> the <code>/cockpit</code>
3968 may be followed by a plus sign and another <code>embedder</code> specific
3969 identifier.</p>
3970 </div>
3971 <div class="paragraph">
3972 <p>What follows is either a <code>@host</code> or <code>$checksum</code> which tells cockpit
3973 where to <a href="packages.html">find the package</a>. Checksums are used when more
3974 than one host has identical packages and the resources can be cached.</p>
3975 </div>
3976 <div class="paragraph">
3977 <p>The <code>package</code> name is next, followed by the <code>component</code> HTML path
3978 inside that package. And lastly a hash allows for navigation within a
3979 single component. The hash should follow a URL path and/or query string
3980 form.</p>
3981 </div>
3982 <div class="admonitionblock warning">
3983 <table>
3984 <tr>
3985 <td class="icon">
3986 <div class="title">Warning</div>
3987 </td>
3988 <td class="content">
3989 <div class="paragraph">
3990 <p>Never assume that the <code>@host</code> or <code>$checksum</code> portion is predictable.
3991 Only refer to resources in packages on the same host.</p>
3992 </div>
3993 </td>
3994 </tr>
3995 </table>
3996 </div>
3997 </div>
3998 <div class="sect3">
3999 <h4 id="urls-visible">Visible URLs</h4>
4000 <div class="paragraph">
4001 <p>The above Component URLs are usually not visible to the user. Instead
4002 the Cockpit Web Service wraps the components in a shell which allows
4003 navigation, and provides bookmarkable clean URLs to the component. These
4004 URLs do not affect <a href="embedding.html">embedders</a> or
4005 <a href="packages.html">components</a> directly.</p>
4006 </div>
4007 <div class="paragraph">
4008 <p>If no path is present then the Cockpit will redirect to the default page
4009 for the server.</p>
4010 </div>
4011 <div class="paragraph">
4012 <p>If the first segment of the path begins with an <code>@</code> sign, then the
4013 component is being shown from a non-local host.</p>
4014 </div>
4015 <div class="paragraph">
4016 <p>The next segment of the path, (or first if the component is being shown
4017 on the local host) is the <a href="packages.html">package name</a>. The remainder of
4018 the path is a component file in the package. If no further path segments
4019 are present, a default <code>index.html</code> component in the package is
4020 loaded. An extension of <code>.html</code> is automatically appended.</p>
4021 </div>
4022 <div class="paragraph">
4023 <p>The hash portion of the path is automatically transferred to the
4024 component as the hash of its <a href="#urls-components">resource URL</a>.</p>
4025 </div>
4026 </div>
4027 </div>
4028 <div class="sect2">
4029 <h3 id="_api_base1">API: base1</h3>
4030 <div class="paragraph">
4031 <p>This package contains basic support API available to other packages.</p>
4032 </div>
4033 <div class="sect3">
4034 <h4 id="_cockpit_js">cockpit.js</h4>
4035 <div class="paragraph">
4036 <p>Basic cockpit API to interact with the system</p>
4037 </div>
4038 <div class="sect4">
4039 <h5 id="api-cockpit-loading">Loading cockpit.js</h5>
4040 <div class="paragraph">
4041 <p><code>cockpit.js</code> should be loaded via a script tag.</p>
4042 </div>
4043 <div class="literalblock">
4044 <div class="content">
4045 <pre>&lt;script src="../base1/cockpit.js"&gt;</pre>
4046 </div>
4047 </div>
4048 </div>
4049 </div>
4050 <div class="sect3">
4051 <h4 id="_cockpit_js_object_caching">cockpit.js: Object Caching</h4>
4052 <div class="paragraph">
4053 <p>If the same information is displayed by multiple components in Cockpit,
4054 <code>cockpit.cache()</code> provides a way to share data between them. The
4055 shared data should be simple objects, arrays, and values, and not
4056 contain functions or other objects.</p>
4057 </div>
4058 <div class="sect4">
4059 <h5 id="cockpit-cache-func">cockpit.cache()</h5>
4060 <div class="literalblock">
4061 <div class="content">
4062 <pre>cache = cockpit.cache(key, provider, consumer)</pre>
4063 </div>
4064 </div>
4065 <div class="paragraph">
4066 <p>Create a new cache object. The <code>key</code> should be a globally unique
4067 string that describes the data being cached. This string must describe
4068 the data, across all machines and all versions of cockpit. It is
4069 customary to include a version number in the <code>key</code> string.</p>
4070 </div>
4071 <div class="literalblock">
4072 <div class="content">
4073 <pre>function provider(result, key) {
4074 result("myvalue");
4075
4076 return {
4077 close: function() {
4078 /* closed */
4079 }
4080 };
4081 }</pre>
4082 </div>
4083 </div>
4084 <div class="paragraph">
4085 <p>The <code>provider</code> is a function that will be invoked to start retrieving
4086 data for the cache. It will be passed a <code>result</code> function as its first
4087 argument. The <code>result</code> should be invoked whenever new data is
4088 available. The <code>key</code> argument matches the key string the cache was
4089 created with.</p>
4090 </div>
4091 <div class="paragraph">
4092 <p>The <code>provider</code> can return an object with a <code>close</code> method. This
4093 method will be invoked when the cache no longer needs data from the
4094 provider.</p>
4095 </div>
4096 <div class="literalblock">
4097 <div class="content">
4098 <pre>function consumer(value, key) {
4099 /* ... */
4100 }</pre>
4101 </div>
4102 </div>
4103 <div class="paragraph">
4104 <p>The <code>consumer</code> is a function that will be passed new values when they
4105 are available, whether they come from the <code>provider</code> or a source in a
4106 different component/frame.</p>
4107 </div>
4108 </div>
4109 <div class="sect4">
4110 <h5 id="cockpit-cache-close">cache.close()</h5>
4111 <div class="literalblock">
4112 <div class="content">
4113 <pre>cache.close()</pre>
4114 </div>
4115 </div>
4116 <div class="paragraph">
4117 <p>Close a cache and stop calling its <code>consumer</code>. If the <code>provider</code> was
4118 invoked, then the <code>close()</code> method it returned will be invoked.</p>
4119 </div>
4120 </div>
4121 </div>
4122 <div class="sect3">
4123 <h4 id="_cockpit_js_raw_channels">cockpit.js: Raw Channels</h4>
4124 <div class="paragraph">
4125 <p>At a low level Cockpit communicates with the system via messages passed
4126 through various channels. These are usually exposed via higher level
4127 APIs, such as the <code>cockpit.spawn()</code> function. It is rare to use raw
4128 channels directly.</p>
4129 </div>
4130 <div class="sect4">
4131 <h5 id="cockpit-channels-channel">cockpit.channel()</h5>
4132 <div class="literalblock">
4133 <div class="content">
4134 <pre>channel = cockpit.channel(options)</pre>
4135 </div>
4136 </div>
4137 <div class="paragraph">
4138 <p>This function creates a new channel for communication with the system.
4139 It returns a new channel object. The <code>options</code> argument is a plain
4140 object. At least the <code>"payload"</code> option is required, and based on the
4141 payload type, other options may be required.</p>
4142 </div>
4143 <div class="dlist">
4144 <dl>
4145 <dt class="hdlist1"><code>"binary"</code></dt>
4146 <dd>
4147 <p>Set to <code>true</code> to transfer binary payloads. Both messages sent via
4148 <a href="#cockpit-channels-send"><code>channel.send()</code></a> and those received via
4149 <a href="#cockpit-channels-message"><code>channel.onmessage</code></a> should be arrays
4150 of bytes, either <code>Uint8Array</code> or <code>Array</code> depending on browser
4151 support.</p>
4152 </dd>
4153 <dt class="hdlist1"><code>"payload"</code></dt>
4154 <dd>
4155 <p>The payload type for the channel. Only specific payload types are
4156 supported.</p>
4157 </dd>
4158 <dt class="hdlist1"><code>"superuser"</code></dt>
4159 <dd>
4160 <p>Set to <code>"require"</code> to open this channel as root. If the currently
4161 logged in user is not permitted to become root (eg: via <code>pkexec</code>)
4162 then the <code>channel</code> will immediately be
4163 <a href="#cockpit-channels-close-ev">closed</a> with a <code>"access-denied"</code>
4164 problem code.
4165 +
4166 Set to <code>"try"</code> to try to open the channel as root, but if that
4167 fails, then fall back to an unprivileged channel.</p>
4168 </dd>
4169 </dl>
4170 </div>
4171 <div class="paragraph">
4172 <p>The channel object returned has the following fields and methods and
4173 events. You should call the <code>channel.close()</code> method when done with
4174 the channel.</p>
4175 </div>
4176 <div class="paragraph">
4177 <p>A valid channel will always be returned and the is ready to
4178 <code>channel.send()</code>. The channel may
4179 <a href="#cockpit-channels-close-ev">close shortly afterword</a> due to a
4180 failure.</p>
4181 </div>
4182 </div>
4183 <div class="sect4">
4184 <h5 id="cockpit-channels-binary">channel.binary</h5>
4185 <div class="paragraph">
4186 <p>Will be <code>true</code> for an binary channel. Will be set to <code>false</code> if the
4187 channel is textual.</p>
4188 </div>
4189 </div>
4190 <div class="sect4">
4191 <h5 id="cockpit-channels-options">channel.options</h5>
4192 <div class="paragraph">
4193 <p>The options used to open this channel. This should not be changed.</p>
4194 </div>
4195 </div>
4196 <div class="sect4">
4197 <h5 id="cockpit-channels-valid">channel.valid</h5>
4198 <div class="paragraph">
4199 <p>Will be <code>true</code> for an open channel. Will be set to <code>false</code> if the
4200 channel closes.</p>
4201 </div>
4202 </div>
4203 <div class="sect4">
4204 <h5 id="cockpit-channels-send">channel.send()</h5>
4205 <div class="literalblock">
4206 <div class="content">
4207 <pre>channel.send(data)</pre>
4208 </div>
4209 </div>
4210 <div class="paragraph">
4211 <p>Send a message over the channel. The contents of the message depends on
4212 the payload type of the channel. If a binary channel, then <code>data</code> is
4213 expected to be an <code>Array</code> of bytes or a <code>Uint8Array</code>. If not binary,
4214 then the <code>data</code> will be converted to a string if not already a string.</p>
4215 </div>
4216 </div>
4217 <div class="sect4">
4218 <h5 id="cockpit-channels-control">channel.control()</h5>
4219 <div class="literalblock">
4220 <div class="content">
4221 <pre>channel.control(options)</pre>
4222 </div>
4223 </div>
4224 <div class="paragraph">
4225 <p>Notify the channel to tune certain parameters on the fly. The
4226 <code>options</code> is a plain javascript object, and the contents depend on the
4227 <code>"payload"</code> of the channel.</p>
4228 </div>
4229 <div class="paragraph">
4230 <p>One common operation is to set <code>"command"</code> to <code>"done"</code> in the
4231 options field. To indicate that no further messages will be sent through
4232 the channel.</p>
4233 </div>
4234 </div>
4235 <div class="sect4">
4236 <h5 id="cockpit-channels-wait">channel.wait()</h5>
4237 <div class="literalblock">
4238 <div class="content">
4239 <pre>promise = channel.wait([callback])</pre>
4240 </div>
4241 </div>
4242 <div class="paragraph">
4243 <p>Returns a <code>promise</code> that is ready when the channel is ready, or fails
4244 if the client closes. If a <code>callback</code> is specified, it is attached to
4245 the promise. The promise will be rejected or resolved with the contents
4246 <code>options</code> passed to the
4247 <a href="#cockpit-channels-onready">channel.onready</a> and
4248 <a href="#cockpit-channels-close-ev">channel.onclose</a> events respectively.</p>
4249 </div>
4250 <div class="paragraph">
4251 <p>In general it&#8217;s not necessary to wait for the channel before starting to
4252 use the channel.</p>
4253 </div>
4254 </div>
4255 <div class="sect4">
4256 <h5 id="cockpit-channels-close">channel.close()</h5>
4257 <div class="literalblock">
4258 <div class="content">
4259 <pre>channel.close([options])</pre>
4260 </div>
4261 </div>
4262 <div class="paragraph">
4263 <p>Close the channel.</p>
4264 </div>
4265 <div class="paragraph">
4266 <p>If <code>options</code> is present it can be a plain javascript object containing
4267 additional channel close options to send to the peer. If closing for
4268 because of a problem, set the <code>"problem"</code> field to a
4269 <a href="cockpit-error.html#cockpit-problems">problem code</a>. If <code>options</code> is not an object it
4270 will be treated as a <code>"problem"</code>.</p>
4271 </div>
4272 <div class="paragraph">
4273 <p>The <a href="#cockpit-channels-close-ev">close event</a> will fire. A channel
4274 can also be closed by a peer or if the underlying transport closes.</p>
4275 </div>
4276 </div>
4277 <div class="sect4">
4278 <h5 id="cockpit-channels-message">channel.onmessage</h5>
4279 <div class="literalblock">
4280 <div class="content">
4281 <pre>channel.addEventListener("message", function(event, data) { ... })</pre>
4282 </div>
4283 </div>
4284 <div class="paragraph">
4285 <p>An event triggered when the channel receives a message. The message is
4286 passed as a string to the handler in the <code>data</code>. In the case of binary
4287 channels <code>data</code> is an <code>Uint8Array</code> or an <code>Array</code> of bytes if the
4288 former is not supported by the browser. The contents of the message
4289 depends on the payload type of the channel.</p>
4290 </div>
4291 </div>
4292 <div class="sect4">
4293 <h5 id="cockpit-channels-oncontrol">channel.oncontrol</h5>
4294 <div class="literalblock">
4295 <div class="content">
4296 <pre>channel.addEventListener("control", function(event, options) { ... })</pre>
4297 </div>
4298 </div>
4299 <div class="paragraph">
4300 <p>An event triggered when the channel receives an control message in the
4301 middle of the flow. One particular use is when the <code>command</code> is set to
4302 <code>"done"</code> then no further messages will be received in the channel. The
4303 exact form of these messages depend on the <code>"payload"</code> of the channel.</p>
4304 </div>
4305 </div>
4306 <div class="sect4">
4307 <h5 id="cockpit-channels-onready">channel.onready</h5>
4308 <div class="literalblock">
4309 <div class="content">
4310 <pre>channel.addEventListener("ready", function(event, options) { ... })</pre>
4311 </div>
4312 </div>
4313 <div class="paragraph">
4314 <p>An event triggered when the other end of the channel is ready to start
4315 processing messages. This indicates the channel is completely open. It
4316 is possible to start sending messages on the channel before this point.</p>
4317 </div>
4318 </div>
4319 <div class="sect4">
4320 <h5 id="cockpit-channels-close-ev">channel.onclose</h5>
4321 <div class="literalblock">
4322 <div class="content">
4323 <pre>channel.addEventListener("close", function(event, options) { ... })</pre>
4324 </div>
4325 </div>
4326 <div class="paragraph">
4327 <p>An event triggered when the channel closes. This can happen either
4328 because <a href="#cockpit-channels-close">channel.close()</a> function was
4329 called, or if the peer closed the channel, or the underlying transport
4330 closes.</p>
4331 </div>
4332 <div class="paragraph">
4333 <p>The <code>options</code> will contain various close information, including a
4334 <code>"problem"</code> field which will be set if the channel was closed because
4335 of a problem.</p>
4336 </div>
4337 </div>
4338 <div class="sect4">
4339 <h5 id="cockpit-transport-origin">cockpit.transport.origin</h5>
4340 <div class="literalblock">
4341 <div class="content">
4342 <pre>cockpit.transport.origin</pre>
4343 </div>
4344 </div>
4345 <div class="paragraph">
4346 <p>The HTTP origin that is being used by the underlying channel transport.
4347 This is read-only, you should not assign a value. If the browser
4348 supports <code>window.location.origin</code> then this will be identical to that
4349 value.</p>
4350 </div>
4351 </div>
4352 <div class="sect4">
4353 <h5 id="cockpit-transport-host">cockpit.transport.host</h5>
4354 <div class="literalblock">
4355 <div class="content">
4356 <pre>cockpit.transport.host</pre>
4357 </div>
4358 </div>
4359 <div class="paragraph">
4360 <p>The host that this transport is going to talk to by default. This is
4361 read-only, you should not assign a value. If the value is null that
4362 means that the transport has not been setup yet.</p>
4363 </div>
4364 </div>
4365 <div class="sect4">
4366 <h5 id="cockpit-transport-csrf-token">cockpit.transport.csrf_token</h5>
4367 <div class="literalblock">
4368 <div class="content">
4369 <pre>cockpit.transport.csrf_token</pre>
4370 </div>
4371 </div>
4372 <div class="paragraph">
4373 <p>A cross site request forgery token for use with external channels. This
4374 becomes valid once the connection is properly established.</p>
4375 </div>
4376 </div>
4377 <div class="sect4">
4378 <h5 id="cockpit-transport-options">cockpit.transport.options</h5>
4379 <div class="literalblock">
4380 <div class="content">
4381 <pre>cockpit.transport.options</pre>
4382 </div>
4383 </div>
4384 <div class="paragraph">
4385 <p>Initialization options received over the underlying channel transport.
4386 These will be empty until connection is properly established.</p>
4387 </div>
4388 </div>
4389 <div class="sect4">
4390 <h5 id="cockpit-transport-wait">cockpit.transport.wait()</h5>
4391 <div class="literalblock">
4392 <div class="content">
4393 <pre>cockpit.transport.wait(callback)</pre>
4394 </div>
4395 </div>
4396 <div class="paragraph">
4397 <p>Call the <code>callback</code> function once the underlying channel transport is
4398 initialized. This will start the initialization if not already in
4399 progress or completed. If the channel transport is already initialized,
4400 then <code>callback</code> will be called immediately.</p>
4401 </div>
4402 <div class="paragraph">
4403 <p>In general it&#8217;s not necessary to wait for the transport before starting
4404 to open channels.</p>
4405 </div>
4406 </div>
4407 <div class="sect4">
4408 <h5 id="cockpit-transport-close">cockpit.transport.close()</h5>
4409 <div class="literalblock">
4410 <div class="content">
4411 <pre>cockpit.transport.close([problem])</pre>
4412 </div>
4413 </div>
4414 <div class="paragraph">
4415 <p>Close the underlying channel transport. All channels open channels will
4416 close. The <code>problem</code> argument should be a problem code string. If not
4417 specified it will default to <code>"disconnected"</code>.</p>
4418 </div>
4419 </div>
4420 <div class="sect4">
4421 <h5 id="cockpit-transport-filter">cockpit.transport.filter()</h5>
4422 <div class="literalblock">
4423 <div class="content">
4424 <pre>cockpit.transport.filter((message, channelid, control) =&gt; { ... })</pre>
4425 </div>
4426 </div>
4427 <div class="paragraph">
4428 <p>Add a filter to the underlying channel transport. All incoming messages
4429 will be passed to each of the filter callbacks that are registered.</p>
4430 </div>
4431 <div class="paragraph">
4432 <p>This function is rarely used.</p>
4433 </div>
4434 <div class="paragraph">
4435 <p>Filter callbacks are called in the order they are registered. If a
4436 filter callback returns <code>false</code> then the message will not be
4437 dispatched further, whether to other filters, or to channels, etc.</p>
4438 </div>
4439 <div class="paragraph">
4440 <p>The <code>message</code> is the string or array with the raw message including,
4441 the framing. The <code>channelid</code> is the channel identifier or an empty
4442 string for control messages. If <code>control</code> is set then this is a
4443 control message,d and the <code>control</code> argument contains the parsed JSON
4444 object of the control message.</p>
4445 </div>
4446 </div>
4447 <div class="sect4">
4448 <h5 id="cockpit-transport-inject">cockpit.transport.inject()</h5>
4449 <div class="literalblock">
4450 <div class="content">
4451 <pre>cockpit.transport.inject(message, [out])</pre>
4452 </div>
4453 </div>
4454 <div class="paragraph">
4455 <p>Inject a message into the underlying channel transport. The <code>message</code>
4456 should be a <code>string</code> or an array of bytes, and should be valid
4457 according to the Cockpit message protocol. If the <code>out</code> argument is
4458 equal to <code>false</code> then the message will be injected as an incoming
4459 message as if it was received on the underlying channel transport.</p>
4460 </div>
4461 <div class="paragraph">
4462 <p>This function is rarely used. In general you should only <code>inject()</code>
4463 messages you got from a <code>filter()</code>.</p>
4464 </div>
4465 </div>
4466 <div class="sect4">
4467 <h5 id="cockpit-base64-encode">cockpit.base64_encode()</h5>
4468 <div class="literalblock">
4469 <div class="content">
4470 <pre>string = cockpit.base64_encode(data)</pre>
4471 </div>
4472 </div>
4473 <div class="paragraph">
4474 <p>Encode binary data into a string using the Base64 encoding. The <code>data</code>
4475 argument can either be a <code>string</code>, an <code>Array</code>, an <code>ArrayBuffer</code> or
4476 a <code>Uint8Array</code>. The return value is a string.</p>
4477 </div>
4478 </div>
4479 <div class="sect4">
4480 <h5 id="cockpit-base64-decode">cockpit.base64_decode()</h5>
4481 <div class="literalblock">
4482 <div class="content">
4483 <pre>data = cockpit.base64_decode(string, [constructor])</pre>
4484 </div>
4485 </div>
4486 <div class="paragraph">
4487 <p>Decode binary data from a Base64 encoded string. The <code>string</code> argument
4488 should be a javascript string. The returned <code>data</code>&gt; will be an array
4489 of bytes.</p>
4490 </div>
4491 <div class="paragraph">
4492 <p>You can pass <code>Uint8Array</code>, <code>Array</code> or <code>String</code> as an alternate
4493 <code>constructor</code> if you want the decoded data in an alternate form. The
4494 default is to return an <code>Array</code>. Note that if you use a <code>String</code> for
4495 the decoded data, then you must guarantee that the data does not contain
4496 bytes that would be invalid for a string.</p>
4497 </div>
4498 </div>
4499 </div>
4500 <div class="sect3">
4501 <h4 id="_cockpit_js_dbus_client">cockpit.js: DBus Client</h4>
4502 <div class="paragraph">
4503 <p>Cockpit allows access to DBus services via this API.</p>
4504 </div>
4505 <div class="sect4">
4506 <h5 id="cockpit-dbus-types">DBus Types</h5>
4507 <div class="paragraph">
4508 <p>DBus values are represented as javascript values and objects as follows:</p>
4509 </div>
4510 <div class="dlist">
4511 <dl>
4512 <dt class="hdlist1"><code>BYTE 'y'</code></dt>
4513 <dd>
4514 <p>Javascript number.</p>
4515 </dd>
4516 <dt class="hdlist1"><code>BOOLEAN 'b'</code></dt>
4517 <dd>
4518 <p>Javascript boolean.</p>
4519 </dd>
4520 <dt class="hdlist1"><code>INT16 'n'</code></dt>
4521 <dd>
4522 <p>Javascript number.</p>
4523 </dd>
4524 <dt class="hdlist1"><code>UINT16 'q'</code></dt>
4525 <dd>
4526 <p>Javascript number.</p>
4527 </dd>
4528 <dt class="hdlist1"><code>INT32 'i'</code></dt>
4529 <dd>
4530 <p>Javascript number.</p>
4531 </dd>
4532 <dt class="hdlist1"><code>UINT32 'u'</code></dt>
4533 <dd>
4534 <p>Javascript number.</p>
4535 </dd>
4536 <dt class="hdlist1"><code>INT64 'x'</code></dt>
4537 <dd>
4538 <p>Javascript number.</p>
4539 </dd>
4540 <dt class="hdlist1"><code>UINT64 't'</code></dt>
4541 <dd>
4542 <p>Javascript number.</p>
4543 </dd>
4544 <dt class="hdlist1"><code>DOUBLE 'd'</code></dt>
4545 <dd>
4546 <p>Javascript number.</p>
4547 </dd>
4548 <dt class="hdlist1"><code>STRING 's'</code></dt>
4549 <dd>
4550 <p>Javascript string.</p>
4551 </dd>
4552 <dt class="hdlist1"><code>OBJECT_PATH 'o'</code></dt>
4553 <dd>
4554 <p>Javascript string.</p>
4555 </dd>
4556 <dt class="hdlist1"><code>SIGNATURE 'g'</code></dt>
4557 <dd>
4558 <p>Javascript string.</p>
4559 </dd>
4560 <dt class="hdlist1"><code>ARRAY of BYTE 'ay'</code></dt>
4561 <dd>
4562 <p>A string containing base64 encoded data.</p>
4563 </dd>
4564 <dt class="hdlist1"><code>ARRAY of DICT_ENTRY with STRING keys 'a{s?}'</code></dt>
4565 <dd>
4566 <p>A javascript plain object with the keys as property names.</p>
4567 </dd>
4568 <dt class="hdlist1"><code>ARRAY of DICT_ENTRY with other keys 'a{??}'</code></dt>
4569 <dd>
4570 <p>A javascript plain object each key JSON encoded into a string property
4571 name.</p>
4572 </dd>
4573 <dt class="hdlist1"><code>ARRAY of other</code></dt>
4574 <dd>
4575 <p>A javascript array.</p>
4576 </dd>
4577 <dt class="hdlist1"><code>VARIANT</code></dt>
4578 <dd>
4579 <p>A javascript plain object with the <code>"t"</code> property set to a DBus type
4580 string, and the <code>"v"</code> property set to a value.</p>
4581 </dd>
4582 <dt class="hdlist1"><code>HANDLE 'h'</code></dt>
4583 <dd>
4584 <p>A javascript object that describes a cockpit channel which represents
4585 the passed file descriptor. The <code>payload</code> is always set to
4586 <code>stream</code>. Pass it to
4587 <a href="cockpit-channels.html#cockpit-channels-channel">cockpit.channel()</a> to create the
4588 channel and start reading or writing on it. Handles can only be
4589 received, not sent from within cockpit.</p>
4590 </dd>
4591 </dl>
4592 </div>
4593 </div>
4594 <div class="sect4">
4595 <h5 id="cockpit-dbus-dbus">cockpit.dbus()</h5>
4596 <div class="literalblock">
4597 <div class="content">
4598 <pre>client = cockpit.dbus(name, [options])</pre>
4599 </div>
4600 </div>
4601 <div class="paragraph">
4602 <p>Create a DBus client for the given bus <code>name</code> (eg: service name). Use
4603 the following functions to make DBus method calls, watch for events,
4604 etc. The optional <code>options</code> argument is a javascript plain object, and
4605 may include:</p>
4606 </div>
4607 <div class="dlist">
4608 <dl>
4609 <dt class="hdlist1"><code>"bus"</code></dt>
4610 <dd>
4611 <p>The DBus bus to connect to. Specifying <code>"session"</code> will connect to
4612 the DBus user session bus, <code>"user"</code> will connect to the user bus (on
4613 some systems this is identical to the session bus), <code>"system"</code> will
4614 connect to the DBus system bus, and <code>"none"</code> to the non-standard bus
4615 specified with the <code>address</code> option. This defaults to "system" if
4616 not present.</p>
4617 </dd>
4618 <dt class="hdlist1"><code>"address"</code></dt>
4619 <dd>
4620 <p>The bus address to connect to in case <code>bus</code> is <code>"none"</code>.</p>
4621 </dd>
4622 <dt class="hdlist1"><code>"superuser"</code></dt>
4623 <dd>
4624 <p>Set to <code>"require"</code> to talk to this service as root. The DBus service
4625 will see the DBus method calls and accesses as coming from root,
4626 rather than the logged in user. This is useful for talking to services
4627 that do not correctly use
4628 <a href="https://www.freedesktop.org/software/polkit">polkit</a> to authorize
4629 administrative users. If the currently logged in user is not permitted
4630 to become root (eg: via <code>pkexec</code>) then the <code>client</code> will
4631 immediately be <a href="#cockpit-dbus-onclose">closed</a> with a
4632 <code>"access-denied"</code> problem code.
4633 +
4634 Set to <code>"try"</code> to try to talk as root, but if that fails, fall back
4635 to unprivileged.</p>
4636 </dd>
4637 <dt class="hdlist1"><code>"track"</code></dt>
4638 <dd>
4639 <p>It is valid for a DBus service to exit, and be restarted in such a way
4640 that clients continue to talk to it across the restart. Some services
4641 are not written with this in mind. If the <code>"track"</code> option is set to
4642 <code>true</code> then the channel will close when the service exits and/or
4643 disconnects from the DBus bus.</p>
4644 </dd>
4645 </dl>
4646 </div>
4647 <div class="paragraph">
4648 <p>If the <code>name</code> argument is null, and no options other than <code>"bus"</code>
4649 are specified, then a shared DBus <code>client</code> is created. When using such
4650 a client with a DBus bus, a <code>"name"</code> option must be specified on
4651 various other methods in order to specify which client to talk to.</p>
4652 </div>
4653 </div>
4654 <div class="sect4">
4655 <h5 id="cockpit-dbus-wait">client.wait()</h5>
4656 <div class="literalblock">
4657 <div class="content">
4658 <pre>promise = client.wait([callback])</pre>
4659 </div>
4660 </div>
4661 <div class="paragraph">
4662 <p>Returns a <code>promise</code> that is ready when the client is ready, or fails
4663 if the client closes. If a <code>callback</code> is specified, it is attached to
4664 the promise.</p>
4665 </div>
4666 </div>
4667 <div class="sect4">
4668 <h5 id="cockpit-dbus-close">client.close()</h5>
4669 <div class="literalblock">
4670 <div class="content">
4671 <pre>client.close([problem])</pre>
4672 </div>
4673 </div>
4674 <div class="paragraph">
4675 <p>Close the DBus client. If <code>problem</code> is specified it should be a
4676 <a href="cockpit-error.html#cockpit-problems">problem code</a> string.</p>
4677 </div>
4678 </div>
4679 <div class="sect4">
4680 <h5 id="cockpit-dbus-onclose">client.onclose</h5>
4681 <div class="literalblock">
4682 <div class="content">
4683 <pre>client.addEventListener("close", options =&gt; { ... })</pre>
4684 </div>
4685 </div>
4686 <div class="paragraph">
4687 <p>An event triggered when the DBus client closes. This can happen either
4688 because <a href="#cockpit-dbus-close">client.close()</a> function was called, or
4689 the DBus service went away, or some other problem or disconnection.</p>
4690 </div>
4691 <div class="paragraph">
4692 <p>The <code>options</code> will contain various close information, including a
4693 <code>"problem"</code> field which will be set if the channel was closed because
4694 of a problem.</p>
4695 </div>
4696 </div>
4697 <div class="sect4">
4698 <h5 id="cockpit-dbus-onowned">client.onowner</h5>
4699 <div class="literalblock">
4700 <div class="content">
4701 <pre>client.addEventListener("owner", (event, owner) =&gt; { ... })</pre>
4702 </div>
4703 </div>
4704 <div class="paragraph">
4705 <p>An event triggered when the owner of the DBus name changes. The owner
4706 value will be the id of the name owner on the bus or null if the name is
4707 unowned. The absence of an owner should not be treated as a
4708 disconnection. However this makes it possible to take some action based
4709 on the actual status of the service, for example disconnecting a pending
4710 signal handler.</p>
4711 </div>
4712 </div>
4713 <div class="sect4">
4714 <h5 id="cockpit-dbus-options">client.options</h5>
4715 <div class="paragraph">
4716 <p>Set to the options used when creating the client. Will not change for
4717 the life of the client.</p>
4718 </div>
4719 </div>
4720 <div class="sect4">
4721 <h5 id="cockpit-dbus-unique-name">client.unique_name</h5>
4722 <div class="paragraph">
4723 <p>The unique DBus name of the client. Initially null, and becomes valid
4724 once the the client is ready.</p>
4725 </div>
4726 </div>
4727 <div class="sect4">
4728 <h5 id="cockpit-dbus-proxy">client.proxy()</h5>
4729 <div class="literalblock">
4730 <div class="content">
4731 <pre>proxy = client.proxy([interface, path], [options])</pre>
4732 </div>
4733 </div>
4734 <div class="paragraph">
4735 <p>Create proxy javascript object for a DBus <code>interface</code>. At the
4736 specified DBus object <code>path</code>. The proxy will have properties, methods
4737 and signals from to the DBus interface, and allows for natural
4738 interaction. If no <code>interface</code> is specified then the DBus bus name of
4739 the client is used. If no <code>path</code> is specified, then the DBus name of
4740 the client is converted to a path.</p>
4741 </div>
4742 <div class="paragraph">
4743 <p>If creating lots of proxies for a given <code>interface</code> it is more
4744 efficient to use the <a href="#cockpit-dbus-proxies"><code>client.proxies()</code></a>
4745 function.</p>
4746 </div>
4747 <div class="paragraph">
4748 <p>The proxy is loaded when the
4749 <a href="#cockpit-dbus-proxy-valid"><code>proxy.valid</code></a> field is <code>true</code>, and
4750 it is set to <code>false</code> if the underlying <code>interface</code> and/or <code>path</code>
4751 don&#8217;t or no longer exist, or the <code>client</code> has closed. You can wait for
4752 proxy to become valid by passing a callback to its
4753 <a href="#cockpit-dbus-proxy-wait"><code>proxy.wait()</code></a> function. The
4754 <a href="#cockpit-dbus-proxy-onchanged"><code>proxy.onchanged</code></a> event will also
4755 fire when the proxy becomes valid or invalid. DBus properties and
4756 methods on the proxy are not defined until the proxy becomes valid.</p>
4757 </div>
4758 <div class="literalblock">
4759 <div class="content">
4760 <pre>value = proxy.Prop1
4761 proxy.WritableProp = value</pre>
4762 </div>
4763 </div>
4764 <div class="paragraph">
4765 <p>All DBus properties on the <code>interface</code> that start with an upper case
4766 letter (as is convention) will be automatically defined on this proxy,
4767 and will update their values as the DBus property values change. In
4768 addition the <a href="#cockpit-dbus-proxy-onchanged"><code>proxy.onchanged</code></a>
4769 event will fire every time the properties change.</p>
4770 </div>
4771 <div class="paragraph">
4772 <p>If you assign a value to a writable property on the proxy, the proxy
4773 will try to set that property on the DBus <code>interface</code> at <code>path</code>. The
4774 actual proxy property value will not update until the DBus service has
4775 notified the proxy of the change. If setting a property fails a warning
4776 will be logged. In order to have more reliable setting of properties, or
4777 track when they have been set, or if setting fails, use the
4778 <a href="#cockpit-dbus-call"><code>client.call()</code></a> directly. It should be noted
4779 that DBus service implementations may also be inconsistent in their
4780 behavior when setting a property fails.</p>
4781 </div>
4782 <div class="paragraph">
4783 <p>You can access the raw property data using the
4784 <a href="#cockpit-dbus-proxy-data"><code>proxy.data</code></a> field, including data for
4785 properties that do not start with an upper case letter.</p>
4786 </div>
4787 <div class="literalblock">
4788 <div class="content">
4789 <pre>proxy.Method(arg1, arg2)
4790 .then((retval1, retval2) =&gt; {
4791 ...
4792 })
4793 .catch(ex =&gt; {
4794 ...
4795 });</pre>
4796 </div>
4797 </div>
4798 <div class="paragraph">
4799 <p>All DBus methods on the <code>interface</code> that start with an upper case
4800 letter (as is convention) will be automatically defined on this proxy.
4801 These methods are called with arguments as normal javascript arguments.
4802 A
4803 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
4804 that will complete successfully when the method returns, or fail if an
4805 error occurs. The return values from the DBus method will be passed to
4806 the <code>then</code> handler function directly.</p>
4807 </div>
4808 <div class="paragraph">
4809 <p>Methods that do not start with an upper case letter can be invoked by
4810 using the usual <a href="#cockpit-dbus-proxy-call"><code>proxy.call()</code></a>
4811 directly.</p>
4812 </div>
4813 <div class="literalblock">
4814 <div class="content">
4815 <pre>proxy.addEventListener("signal", (event, arg1, arg2) =&gt; {
4816 ...
4817 });</pre>
4818 </div>
4819 </div>
4820 <div class="paragraph">
4821 <p>All DBus signals on the <code>interface</code> that start with an upper case
4822 letter (as is convention) will be automatically emit events on this
4823 proxy. These events will contain the signal arguments after the standard
4824 <code>event</code> argument.</p>
4825 </div>
4826 <div class="paragraph">
4827 <p>Signals that do not start with an upper case letter can be subscribed to
4828 by using <a href="#cockpit-dbus-proxy-signal"><code>proxy.onsignal</code></a> directly.</p>
4829 </div>
4830 <div class="paragraph">
4831 <p>Usually a proxy asks the <code>client</code> to watch and notify it of changes to
4832 the relevant object or path. You can pass an <code>options</code> argument with
4833 the <code>watch</code> field set to <code>false</code> to prevent this.</p>
4834 </div>
4835 </div>
4836 <div class="sect4">
4837 <h5 id="cockpit-dbus-proxy-client">proxy.client</h5>
4838 <div class="paragraph">
4839 <p>Set to the DBus client of the proxy. Will not change for the life of the
4840 proxy.</p>
4841 </div>
4842 </div>
4843 <div class="sect4">
4844 <h5 id="cockpit-dbus-proxy-path">proxy.path</h5>
4845 <div class="paragraph">
4846 <p>Set to the DBus object path of the proxy. Will not change for the life
4847 of the proxy.</p>
4848 </div>
4849 </div>
4850 <div class="sect4">
4851 <h5 id="cockpit-dbus-proxy-iface">proxy.iface</h5>
4852 <div class="paragraph">
4853 <p>Set to the DBus interface name of the proxy. Will not change for the
4854 life of the proxy.</p>
4855 </div>
4856 </div>
4857 <div class="sect4">
4858 <h5 id="cockpit-dbus-proxy-valid">proxy.valid</h5>
4859 <div class="paragraph">
4860 <p>Set to <code>true</code> when the proxy&#8217;s DBus interface is present at its DBus
4861 path, and all information for the proxy has loaded. Is set to <code>false</code>
4862 while loading, and after the proxy no longer refers a DBus interface and
4863 path. Also set to <code>false</code> if the <code>client</code> closes.</p>
4864 </div>
4865 <div class="paragraph">
4866 <p>Use the by <a href="#cockpit-dbus-proxy-wait"><code>proxy.wait()</code></a> function to
4867 wait for a proxy to load. The
4868 <a href="#cockpit-dbus-proxy-onchanged"><code>proxy.onchanged</code></a> event will also
4869 be emitted when the proxy becomes valid or invalid. DBus properties and
4870 methods on the proxy are not defined until the proxy becomes valid.</p>
4871 </div>
4872 </div>
4873 <div class="sect4">
4874 <h5 id="cockpit-dbus-proxy-data">proxy.data</h5>
4875 <div class="paragraph">
4876 <p>A plain javascript object containing all the raw property data that this
4877 proxy has loaded. This will be updated automatically as the proxy is
4878 notified of property changes from the DBus service. The
4879 <a href="#cockpit-dbus-proxy-onchanged"><code>proxy.onchanged</code></a> event will be
4880 emitted when it changes.</p>
4881 </div>
4882 </div>
4883 <div class="sect4">
4884 <h5 id="cockpit-dbus-proxy-call">proxy.call()</h5>
4885 <div class="literalblock">
4886 <div class="content">
4887 <pre>invocation = proxy.call(method, args, [options])</pre>
4888 </div>
4889 </div>
4890 <div class="paragraph">
4891 <p>Make a DBus method call on this proxy.</p>
4892 </div>
4893 <div class="paragraph">
4894 <p>For DBus methods that start with an upper case letter, is usually more
4895 convenient <a href="#cockpit-dbus-proxy">to call the method directly on the
4896 proxy</a>. However if methods that do not follow the usual DBus convention,
4897 or specify additional options, or the caller cannot be sure that the
4898 method actually exists, you can use this method.</p>
4899 </div>
4900 <div class="paragraph">
4901 <p>This function also works on proxies that have are still loading and have
4902 not become valid yet.</p>
4903 </div>
4904 <div class="paragraph">
4905 <p>The <code>method</code> should be a DBus method name, and the <code>args</code> should be
4906 an array of arguments to pass to the method. The <code>options</code> are
4907 <a href="#cockpit-dbus-call">described elsewhere</a>.</p>
4908 </div>
4909 <div class="paragraph">
4910 <p>The returned value is identical to the one returned from
4911 <a href="#cockpit-dbus-call">client.call()</a>. It is a
4912 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
4913 that will complete successfully when the method returns, or fail if an
4914 error occurs.</p>
4915 </div>
4916 </div>
4917 <div class="sect4">
4918 <h5 id="cockpit-dbus-proxy-wait">proxy.wait()</h5>
4919 <div class="literalblock">
4920 <div class="content">
4921 <pre>promise = proxy.wait()
4922 proxy.wait(() =&gt; {
4923 ...
4924 });</pre>
4925 </div>
4926 </div>
4927 <div class="paragraph">
4928 <p>Wait for a proxy to finish loading. This function returns a promise. If
4929 a callback function is passed as an argument then that function will be
4930 invoked when the proxy is ready. If this method is called after a proxy
4931 has already loaded, then the promise will be resolved immediately, and
4932 any callback will be invoked immediately. Use the promise or
4933 <code>proxy.valid</code> to determine whether the proxy is valid.</p>
4934 </div>
4935 </div>
4936 <div class="sect4">
4937 <h5 id="cockpit-dbus-proxy-onchanged">proxy.onchanged</h5>
4938 <div class="literalblock">
4939 <div class="content">
4940 <pre>proxy.addEventListener("changed", (event, data) =&gt; {
4941 ...
4942 });</pre>
4943 </div>
4944 </div>
4945 <div class="paragraph">
4946 <p>This event is emitted when the proxy&#8217;s properties change.</p>
4947 </div>
4948 <div class="paragraph">
4949 <p>The <code>data</code> has the following form, and will only include properties
4950 that have changed:</p>
4951 </div>
4952 <div class="literalblock">
4953 <div class="content">
4954 <pre>{
4955 "Prop1": "value",
4956 "Prop2": 5
4957 }</pre>
4958 </div>
4959 </div>
4960 </div>
4961 <div class="sect4">
4962 <h5 id="cockpit-dbus-proxy-signal">proxy.onsignal</h5>
4963 <div class="literalblock">
4964 <div class="content">
4965 <pre>proxy.addEventListener("signal", (event, name, args) =&gt; {
4966 ...
4967 });</pre>
4968 </div>
4969 </div>
4970 <div class="paragraph">
4971 <p>This event is emitted when the proxy&#8217;s emits an event.</p>
4972 </div>
4973 <div class="paragraph">
4974 <p>For most events, that have names which start with an upper case letter,
4975 you can just <a href="#cockpit-dbus-proxy">connect to that event as a signal
4976 directly</a>. However if you wish to be notified when any signal is
4977 emitted, or for signals that do not follow the usual DBus convention,
4978 you can connect to this event.</p>
4979 </div>
4980 <div class="paragraph">
4981 <p>The <code>name</code> is the DBus signal name, and the <code>args</code> is an array of
4982 arguments that were emitted with the signal.</p>
4983 </div>
4984 </div>
4985 <div class="sect4">
4986 <h5 id="cockpit-dbus-proxies">client.proxies()</h5>
4987 <div class="literalblock">
4988 <div class="content">
4989 <pre>proxies = client.proxies([interface], [path_namespace], [options])</pre>
4990 </div>
4991 </div>
4992 <div class="paragraph">
4993 <p>Create <a href="#cockpit-dbus-proxy">proxy javascript objects</a> for a DBus
4994 interfaces. The proxies will have properties, methods and signals from
4995 the DBus <code>interface</code>, and allow for natural interaction. If no
4996 <code>interface</code> is specified then the DBus bus name of the client is used.
4997 If no <code>path_namespace</code> is provided then <code>"/"</code> will be used.</p>
4998 </div>
4999 <div class="paragraph">
5000 <p>Proxies will be automatically created for instances of the <code>interface</code>
5001 available at the DBus service. The optional <code>path_namespace</code> argument
5002 can be used to restrict the proxies for instances that have DBus paths
5003 which have the namespace path prefix.</p>
5004 </div>
5005 <div class="literalblock">
5006 <div class="content">
5007 <pre>proxy1 = proxies["/dbus/path1"];
5008 proxy2 = proxies["/dbus/path2"];
5009 for (proxy in proxies) {
5010 ...
5011 }</pre>
5012 </div>
5013 </div>
5014 <div class="paragraph">
5015 <p>The returned <code>proxies</code> object will is used as a dictionary, and will
5016 have values containing proxies for DBus interface instances, with the
5017 keys being the DBus paths of those instances. It is possible to
5018 enumerate over the returned <code>proxies</code>.</p>
5019 </div>
5020 <div class="paragraph">
5021 <p>Proxies will be automatically added and removed from the <code>proxies</code>
5022 object as they appear and disappear in the service. The
5023 <a href="#cockpit-dbus-proxies-onadded"><code>proxies.onadded</code></a> and
5024 <a href="#cockpit-dbus-proxies-onremoved"><code>proxies.onremoved</code></a> events will
5025 be emitted. DBus services may not support notifications of paths
5026 disappearing.</p>
5027 </div>
5028 <div class="paragraph">
5029 <p>Use the <code>proxies.wait()</code> function to be notified when the initial set
5030 of proxies has been populated.</p>
5031 </div>
5032 <div class="paragraph">
5033 <p>Usually a proxies ask the <code>client</code> to watch and be notified of changes
5034 to the relevant object or path. You can pass an <code>options</code> argument
5035 with the <code>watch</code> field set to <code>false</code> to prevent this.</p>
5036 </div>
5037 </div>
5038 <div class="sect4">
5039 <h5 id="cockpit-dbus-proxies-wait">proxies.wait()</h5>
5040 <div class="literalblock">
5041 <div class="content">
5042 <pre>promise = proxies.wait()
5043 proxies.wait(() =&gt; {
5044 ...
5045 });</pre>
5046 </div>
5047 </div>
5048 <div class="paragraph">
5049 <p>Wait for a <code>proxies</code> object to populate its initial set of proxies.
5050 This function returns a promise. If a callback function is passed as an
5051 argument then that function will be invoked when the proxies are ready.
5052 If this method is called after the proxies have populated, then the
5053 promise will be resolved immediately, and any callback will be invoked
5054 immediately.</p>
5055 </div>
5056 </div>
5057 <div class="sect4">
5058 <h5 id="cockpit-dbus-proxies-client">proxies.client</h5>
5059 <div class="paragraph">
5060 <p>Set to the DBus client of the proxies. Will not change.</p>
5061 </div>
5062 </div>
5063 <div class="sect4">
5064 <h5 id="cockpit-dbus-proxies-iface">proxies.iface</h5>
5065 <div class="paragraph">
5066 <p>Set to the DBus interface name of the proxies. Will not change.</p>
5067 </div>
5068 </div>
5069 <div class="sect4">
5070 <h5 id="cockpit-dbus-proxies-path_namespace">proxies.path_namespace</h5>
5071 <div class="paragraph">
5072 <p>Set to the DBus path namespace used which the proxies must have as a
5073 DBus path prefix. Will not change.</p>
5074 </div>
5075 </div>
5076 <div class="sect4">
5077 <h5 id="cockpit-dbus-proxies-onadded">proxies.onadded</h5>
5078 <div class="literalblock">
5079 <div class="content">
5080 <pre>proxies.addEventListener("added", (event, proxy) =&gt; {
5081 ...
5082 })</pre>
5083 </div>
5084 </div>
5085 <div class="paragraph">
5086 <p>This event is emitted when a proxy is added to the <code>proxies</code> object.
5087 The proxy will already have loaded.</p>
5088 </div>
5089 </div>
5090 <div class="sect4">
5091 <h5 id="cockpit-dbus-proxies-onchanged">proxies.onchanged</h5>
5092 <div class="literalblock">
5093 <div class="content">
5094 <pre>proxies.addEventListener("changed", (event, proxy) =&gt; {
5095 ...
5096 })</pre>
5097 </div>
5098 </div>
5099 <div class="paragraph">
5100 <p>This event is emitted when one of the proxy in the <code>proxies</code> object
5101 changes its properties.</p>
5102 </div>
5103 </div>
5104 <div class="sect4">
5105 <h5 id="cockpit-dbus-proxies-onremoved">proxies.onremoved</h5>
5106 <div class="literalblock">
5107 <div class="content">
5108 <pre>proxies.addEventListener("removed", (event, proxy) =&gt; {
5109 ...
5110 })</pre>
5111 </div>
5112 </div>
5113 <div class="paragraph">
5114 <p>This event is emitted when a proxy is removed to the <code>proxies</code> object.</p>
5115 </div>
5116 </div>
5117 <div class="sect4">
5118 <h5 id="cockpit-dbus-call">client.call()</h5>
5119 <div class="literalblock">
5120 <div class="content">
5121 <pre>invocation = client.call(path, interface, method, args, [options])</pre>
5122 </div>
5123 </div>
5124 <div class="paragraph">
5125 <p>Make a DBus method call.</p>
5126 </div>
5127 <div class="paragraph">
5128 <p>The <code>path</code> is the DBus object path to make the call on, <code>interface</code>
5129 is the DBus interface for the method and <code>method</code> is the name of the
5130 method to call. The <code>args</code> is an array of arguments to pass to the
5131 method, each of which must be appropriate for the expected
5132 <a href="#cockpit-dbus">DBus type</a> of that argument. The <code>args</code> may be
5133 <code>null</code> if no arguments are to be sent.</p>
5134 </div>
5135 <div class="paragraph">
5136 <p>The returned value is a
5137 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
5138 that will complete successfully when the method returns, or fail if an
5139 error occurs.</p>
5140 </div>
5141 <div class="paragraph">
5142 <p>If <code>options</code> is specified it should be a plain javascript object,
5143 which may contain the following properties:</p>
5144 </div>
5145 <div class="dlist">
5146 <dl>
5147 <dt class="hdlist1"><code>flags</code></dt>
5148 <dd>
5149 <p>A string containing DBus message flags. The character <code>"i"</code>
5150 indicates to the dbus service that interactive authentication is
5151 allowed. If the entire <code>flags</code> field is missing, then <code>"i"</code> is set
5152 by default.</p>
5153 </dd>
5154 <dt class="hdlist1"><code>type</code></dt>
5155 <dd>
5156 <p>A valid DBus type signature to use when calling the method. In the
5157 absence of this, the DBus service will be introspected (and the result
5158 cached) to ask what the method type signature is.</p>
5159 </dd>
5160 <dt class="hdlist1"><code>timeout</code></dt>
5161 <dd>
5162 <p>The timeout of the call in milliseconds. The call will fail with the
5163 <code>"timeout"</code> problem code. If "timeout" is not given, the call will
5164 never time out.</p>
5165 </dd>
5166 </dl>
5167 </div>
5168 </div>
5169 <div class="sect4">
5170 <h5 id="cockpit-dbus-then">invocation.then()</h5>
5171 <div class="literalblock">
5172 <div class="content">
5173 <pre>invocation.then((args, options) =&gt; { ... })</pre>
5174 </div>
5175 </div>
5176 <div class="paragraph">
5177 <p>This is a standard
5178 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
5179 method. It sets up a handler to be called when the DBus method call
5180 finishes successfully.</p>
5181 </div>
5182 <div class="paragraph">
5183 <p>The <code>args</code> argument is an array of return values from the DBus method.
5184 Each of them will be converted to an appropriate
5185 <a href="#cockpit-dbus">javascript type</a>.</p>
5186 </div>
5187 <div class="paragraph">
5188 <p>The <code>options</code> argument may contain additional information about the
5189 reply. If the <code>type</code> option was specified when performing the method
5190 call, then the <code>options</code> in the reply here will also contain a
5191 <code>type</code> field containing the DBus type signature of the output. If the
5192 <code>flags</code> option was specified when performing the call then the
5193 <code>options</code> in the reply here will contain message flags. Possible out
5194 message flags are:</p>
5195 </div>
5196 <div class="dlist">
5197 <dl>
5198 <dt class="hdlist1"><code>&gt;</code></dt>
5199 <dd>
5200 <p>A big endian message.</p>
5201 </dd>
5202 <dt class="hdlist1"><code>&lt;</code></dt>
5203 <dd>
5204 <p>A little endian message.</p>
5205 </dd>
5206 </dl>
5207 </div>
5208 </div>
5209 <div class="sect4">
5210 <h5 id="cockpit-dbus-catch">invocation.catch()</h5>
5211 <div class="literalblock">
5212 <div class="content">
5213 <pre>invocation.catch(exception =&gt; { ... })</pre>
5214 </div>
5215 </div>
5216 <div class="paragraph">
5217 <p>This is a standard
5218 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
5219 method. It sets up a handler to be called when the DBus method call
5220 fails.</p>
5221 </div>
5222 <div class="paragraph">
5223 <p>The <code>exception</code> object passed to the handler can have the following
5224 properties:</p>
5225 </div>
5226 <div class="dlist">
5227 <dl>
5228 <dt class="hdlist1"><code>problem</code></dt>
5229 <dd>
5230 <p>A <a href="cockpit-error.html#cockpit-problems">problem code</a> string when a problem occurred
5231 starting or communicating with the DBus service. This is <code>null</code> in
5232 the cases where an actual DBus error was occurred.</p>
5233 </dd>
5234 <dt class="hdlist1"><code>name</code></dt>
5235 <dd>
5236 <p>The DBus error name. This will be <code>null</code> in cases where the failure
5237 was not due to a DBus error.</p>
5238 </dd>
5239 <dt class="hdlist1"><code>message</code></dt>
5240 <dd>
5241 <p>A DBus error message. This will be <code>null</code> in cases where the failure
5242 was not due to a DBus error.</p>
5243 </dd>
5244 </dl>
5245 </div>
5246 </div>
5247 <div class="sect4">
5248 <h5 id="cockpit-dbus-subscribe">client.subscribe()</h5>
5249 <div class="literalblock">
5250 <div class="content">
5251 <pre>subscription = client.subscribe(match, (path, interface, signal, args) =&gt; { ... })</pre>
5252 </div>
5253 </div>
5254 <div class="paragraph">
5255 <p>Subscribe to signals. The <code>match</code> argument is a javascript plain
5256 object which defines what signals to subscribe to. Each property in the
5257 <code>match</code> argument restricts signals subscribed to. If a property is not
5258 present then it is treated as a wildcard, matching anything. If an empty
5259 object is specified as <code>match</code> then all signals will be subscribed to.
5260 The <code>match</code> argument may contain the following properties:</p>
5261 </div>
5262 <div class="dlist">
5263 <dl>
5264 <dt class="hdlist1"><code>interface</code></dt>
5265 <dd>
5266 <p>A DBus interface to match.</p>
5267 </dd>
5268 <dt class="hdlist1"><code>path</code></dt>
5269 <dd>
5270 <p>A DBus object path to match. May not be used together with the
5271 <code>path_namespace</code> property. It should be a valid DBus object path,
5272 that is, it should have no trailing slash.</p>
5273 </dd>
5274 <dt class="hdlist1"><code>path_namespace</code></dt>
5275 <dd>
5276 <p>A DBus object path prefix to match. Any paths in the hierarchy below
5277 this top path will match. May not be used together with the <code>path</code>
5278 property.</p>
5279 </dd>
5280 <dt class="hdlist1"><code>member</code></dt>
5281 <dd>
5282 <p>The DBus signal name to match.</p>
5283 </dd>
5284 <dt class="hdlist1"><code>arg0</code></dt>
5285 <dd>
5286 <p>Matches the first argument of a DBus message, which must be a string.</p>
5287 </dd>
5288 </dl>
5289 </div>
5290 <div class="paragraph">
5291 <p>The handler passed as the second argument will be invoked when the
5292 signal is received. A <code>subscription</code> is returned which can be used to
5293 remove the subscription by calling its <code>subscription.remove()</code> method.</p>
5294 </div>
5295 <div class="paragraph">
5296 <p>It is not a problem to subscribe to the same signals more than once,
5297 with identical or slightly different <code>match</code> arguments.</p>
5298 </div>
5299 </div>
5300 <div class="sect4">
5301 <h5 id="cockpit-dbus-remove">subscription.remove()</h5>
5302 <div class="literalblock">
5303 <div class="content">
5304 <pre>subscription.remove()</pre>
5305 </div>
5306 </div>
5307 <div class="paragraph">
5308 <p>Unsubscribe from the DBus signal subscription.</p>
5309 </div>
5310 </div>
5311 <div class="sect4">
5312 <h5 id="cockpit-dbus-watch">client.watch()</h5>
5313 <div class="literalblock">
5314 <div class="content">
5315 <pre>watch = client.watch(path)
5316 watch = client.watch({ "path_namespace": path_namespace, "interface": interface })</pre>
5317 </div>
5318 </div>
5319 <div class="paragraph">
5320 <p>Watch for property and interface changes on the given DBus object
5321 <code>path</code> DBus <code>path_namespace</code>. If <code>interface</code> is specified only
5322 properties on that DBus interface will be watched.</p>
5323 </div>
5324 <div class="paragraph">
5325 <p>The <a href="#cockpit-dbus-proxy"><code>client.proxy()</code></a> and
5326 <a href="#cockpit-dbus-proxies"><code>client.proxies()</code></a> functions and the
5327 objects they return are high level wrappers around <code>client.watch()</code>.</p>
5328 </div>
5329 <div class="paragraph">
5330 <p>The property and interface changes will be available in raw form on the
5331 <a href="#cockpit-dbus-onnotify"><code>client.onnotify</code></a> event.</p>
5332 </div>
5333 <div class="paragraph">
5334 <p>Property and interface changes that are caused by a method call or
5335 signal will show up before that method call reply is received, or signal
5336 event is triggered. It should be possible to rely on this guarantee,
5337 unless the DBus service in question behaves incorrectly. Internally
5338 these watches work well with code that implements the
5339 <a href="https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager">ObjectManager</a>
5340 portion of the DBus specification. If no ObjectManager implementation is
5341 available, the watch falls back to using DBus
5342 <a href="https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-introspectable">Introspection</a>
5343 along with the usual
5344 <a href="https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties">PropertiesChanged</a>
5345 signal. If the DBus service implements none of these, or implements them
5346 in an inconsistent manner, then this function will provide inconsistent
5347 or unexpected results.</p>
5348 </div>
5349 <div class="paragraph">
5350 <p>The parameter is either a DBus <code>path</code> or a plain javascript object
5351 with zero or more of the following fields. If an empty javascript object
5352 is used as an argument, then all paths, interfaces and properties will
5353 be watched.</p>
5354 </div>
5355 <div class="dlist">
5356 <dl>
5357 <dt class="hdlist1"><code>interface</code></dt>
5358 <dd>
5359 <p>Watch properties on this DBus interface.</p>
5360 </dd>
5361 <dt class="hdlist1"><code>path</code></dt>
5362 <dd>
5363 <p>Watch interfaces and properties at this DBus path. May not be used
5364 together with the <code>path_namespace</code> property.</p>
5365 </dd>
5366 <dt class="hdlist1"><code>path_namespace</code></dt>
5367 <dd>
5368 <p>Watch interfaces and properties under this DBus path. It should be a
5369 valid DBus object path, that is, it should have no trailing slash. If
5370 an ObjectManager implementation is available at this interface, then
5371 it is used. May not be used together with the <code>path</code> property.</p>
5372 </dd>
5373 </dl>
5374 </div>
5375 <div class="paragraph">
5376 <p>The returned value is a
5377 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
5378 that will complete successfully when the watch has populated its initial
5379 set of properties and interfaces, and these have been notified via
5380 <a href="#cockpit-dbus-onnotify"><code>client.onnotify</code></a>.</p>
5381 </div>
5382 <div class="paragraph">
5383 <p>A watch can be removed by calling the
5384 <a href="#cockpit-dbus-watch-remove"><code>watch.remove()</code></a> method on the
5385 returned value. If identical watches are added more than once, then they
5386 must also be removed the same number of times before the removal takes
5387 effect.</p>
5388 </div>
5389 </div>
5390 <div class="sect4">
5391 <h5 id="cockpit-dbus-watch-then">watch.then()</h5>
5392 <div class="literalblock">
5393 <div class="content">
5394 <pre>watch.then(() =&gt; { ... })</pre>
5395 </div>
5396 </div>
5397 <div class="paragraph">
5398 <p>This is a standard
5399 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
5400 method. It sets up a handler to be called when the watch has populated
5401 its initial properties and interfaces.</p>
5402 </div>
5403 </div>
5404 <div class="sect4">
5405 <h5 id="cockpit-dbus-watch-catch">watch.catch()</h5>
5406 <div class="literalblock">
5407 <div class="content">
5408 <pre>watch.catch(ex =&gt; { ... })</pre>
5409 </div>
5410 </div>
5411 <div class="paragraph">
5412 <p>This is a standard
5413 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
5414 method. It sets up a handler to be called if the watch fails to populate
5415 its initial properties and interfaces. Note that a watch will only fail
5416 if the DBus client closes or is somehow disconnected. It does not fail
5417 in the case of missing interfaces or properties.</p>
5418 </div>
5419 </div>
5420 <div class="sect4">
5421 <h5 id="cockpit-dbus-watch-remove">watch.remove()</h5>
5422 <div class="literalblock">
5423 <div class="content">
5424 <pre>watch.remove()</pre>
5425 </div>
5426 </div>
5427 <div class="paragraph">
5428 <p>Remove the watch. This may not have any immediate effect if other
5429 watches are in place. In particular, if identical watches are added more
5430 than once, then they must also be removed the same number of times
5431 before the removal takes effect.</p>
5432 </div>
5433 </div>
5434 <div class="sect4">
5435 <h5 id="cockpit-dbus-onnotify">client.onnotify</h5>
5436 <div class="literalblock">
5437 <div class="content">
5438 <pre>client.addEventListener("notify", data =&gt; { ... })</pre>
5439 </div>
5440 </div>
5441 <div class="paragraph">
5442 <p>An event triggered when <a href="#cockpit-dbus-watch">watched</a> properties or
5443 interfaces change.</p>
5444 </div>
5445 <div class="paragraph">
5446 <p>The <a href="#cockpit-dbus-proxy"><code>client.proxy()</code></a> and
5447 <a href="#cockpit-dbus-proxies"><code>client.proxies()</code></a> functions and the
5448 objects they return are high level wrappers around the <code>data</code> provided
5449 by this event.</p>
5450 </div>
5451 <div class="paragraph">
5452 <p>The <code>data</code> has the following form:</p>
5453 </div>
5454 <div class="literalblock">
5455 <div class="content">
5456 <pre>{
5457 "/path1": {
5458 "org.Interface1": {
5459 "Prop1": "value",
5460 "Prop2": 5
5461 },
5462 "org.Interface2": null
5463 }
5464 }</pre>
5465 </div>
5466 </div>
5467 <div class="paragraph">
5468 <p>Multiple paths may be present, each of which may have multiple
5469 interfaces, each of which may have multiple properties. The first time a
5470 given path and interface is emitted from this signal, it will have all
5471 its properties and interfaces. Thereafter only changes are noted. If an
5472 interface is set to <code>null</code>, then that interface has disappeared.</p>
5473 </div>
5474 </div>
5475 <div class="sect4">
5476 <h5 id="cockpit-dbus-notify">client.notify()</h5>
5477 <div class="literalblock">
5478 <div class="content">
5479 <pre>client.notify(data)</pre>
5480 </div>
5481 </div>
5482 <div class="paragraph">
5483 <p>Emits a synthetic <a href="#cockpit-dbus-onnotify"><code>notify</code></a> event. The
5484 <code>data</code> argument should follow the same layout as described for the
5485 <code>notify</code> event.</p>
5486 </div>
5487 </div>
5488 <div class="sect4">
5489 <h5 id="cockpit-dbus-onmeta">client.onmeta</h5>
5490 <div class="literalblock">
5491 <div class="content">
5492 <pre>client.onmeta = (ev, data) =&gt; { ... }</pre>
5493 </div>
5494 </div>
5495 <div class="paragraph">
5496 <p>An event triggered when the meta data about
5497 <a href="#cockpit-dbus-watch">watched</a> interfaces is loaded.</p>
5498 </div>
5499 <div class="paragraph">
5500 <p>The <a href="#cockpit-dbus-proxy"><code>client.proxy()</code></a> and
5501 <a href="#cockpit-dbus-proxies"><code>client.proxies()</code></a> functions and the
5502 objects they return are high level wrappers around the <code>data</code> provided
5503 by this event.</p>
5504 </div>
5505 <div class="paragraph">
5506 <p>The <code>data</code> has the following form:</p>
5507 </div>
5508 <div class="literalblock">
5509 <div class="content">
5510 <pre> {
5511 "org.Interface": {
5512 "methods": {
5513 "Method1": {
5514 "in": [ "s", "v" ],
5515 "out": [ "i" ]
5516 },
5517 "Method2": { }
5518 },
5519 "signals": {
5520 "Signal": {
5521 "in": [ "b", "s" ]
5522 }
5523 },
5524 "properties": {
5525 "Prop1": {
5526 "flags": "rw",
5527 "type": "s"
5528 },
5529 "Prop2": {
5530 "flags": "r",
5531 "type": "b"
5532 }
5533 }
5534 }
5535 }</pre>
5536 </div>
5537 </div>
5538 <div class="paragraph">
5539 <p>Multiple interfaces may be present, each of which may have methods and
5540 properties. This is emitted before the first
5541 <a href="#cockpit-dbus-proxy"><code>client.onnotify</code></a> event for the relevant
5542 interface.</p>
5543 </div>
5544 </div>
5545 <div class="sect4">
5546 <h5 id="cockpit-dbus-variant">cockpit.variant()</h5>
5547 <div class="literalblock">
5548 <div class="content">
5549 <pre>variant = cockpit.variant(type, value)</pre>
5550 </div>
5551 </div>
5552 <div class="paragraph">
5553 <p>A DBus variant is represented as a plain javascript object with a
5554 <code>"t"</code> property represesting the full DBus type of the variant, and a
5555 <code>"v"</code> property containing the variant value.</p>
5556 </div>
5557 <div class="paragraph">
5558 <p>This is a helper function for creating such a variant object.</p>
5559 </div>
5560 </div>
5561 </div>
5562 <div class="sect3">
5563 <h4 id="_cockpit_js_errors">cockpit.js: Errors</h4>
5564 <div class="paragraph">
5565 <p>cockpit.js: Errors</p>
5566 </div>
5567 <div class="paragraph">
5568 <p>Problem codes and messages</p>
5569 </div>
5570 <div class="sect4">
5571 <h5 id="cockpit-problems">Problem Codes</h5>
5572 <div class="paragraph">
5573 <p>Cockpit represents problems with standardized problem string codes.</p>
5574 </div>
5575 <div class="dlist">
5576 <dl>
5577 <dt class="hdlist1"><code>"access-denied"</code></dt>
5578 <dd>
5579 <p>The user is not permitted to perform the action in question.</p>
5580 </dd>
5581 <dt class="hdlist1"><code>"authentication-failed"</code></dt>
5582 <dd>
5583 <p>User authentication failed.</p>
5584 </dd>
5585 <dt class="hdlist1"><code>"internal-error"</code></dt>
5586 <dd>
5587 <p>An unexpected internal error without further info. This should not
5588 happen during the normal course of operations.</p>
5589 </dd>
5590 <dt class="hdlist1"><code>"no-cockpit"</code></dt>
5591 <dd>
5592 <p>The system does not have a compatible version of Cockpit installed or
5593 installed properly.</p>
5594 </dd>
5595 <dt class="hdlist1"><code>"no-session"</code></dt>
5596 <dd>
5597 <p>Cockpit is not logged in.</p>
5598 </dd>
5599 <dt class="hdlist1"><code>"not-found"</code></dt>
5600 <dd>
5601 <p>Something specifically requested was not found, such as a file,
5602 executable etc.</p>
5603 </dd>
5604 <dt class="hdlist1"><code>"terminated"</code></dt>
5605 <dd>
5606 <p>Something was terminated forcibly, such as a connection, process
5607 session, etc.</p>
5608 </dd>
5609 <dt class="hdlist1"><code>"timeout"</code></dt>
5610 <dd>
5611 <p>Something timed out.</p>
5612 </dd>
5613 <dt class="hdlist1"><code>"unknown-hostkey"</code></dt>
5614 <dd>
5615 <p>The remote host had an unexpected or unknown key.</p>
5616 </dd>
5617 <dt class="hdlist1"><code>"no-forwarding"</code></dt>
5618 <dd>
5619 <p>Could not forward authentication credentials to the remote host.</p>
5620 </dd>
5621 </dl>
5622 </div>
5623 </div>
5624 <div class="sect4">
5625 <h5 id="cockpit-messages">cockpit.message()</h5>
5626 <div class="literalblock">
5627 <div class="content">
5628 <pre>message = cockpit.message(problem)
5629 message = cockpit.message(exception)</pre>
5630 </div>
5631 </div>
5632 <div class="paragraph">
5633 <p>Return a message for the <code>exception</code> or <code>problem</code> code passed as an
5634 argument. If the argument is an object with a <code>"message"</code> property, as
5635 is the case with most exceptions, that will be returned directly. If the
5636 argument is an object with a <code>"problem"</code> property, then it will be
5637 used as the problem code. An appropriate message will be returned for
5638 problem codes.</p>
5639 </div>
5640 </div>
5641 </div>
5642 <div class="sect3">
5643 <h4 id="_cockpit_js_file_access">cockpit.js: File Access</h4>
5644 <div class="paragraph">
5645 <p>The <code>cockpit.file</code> API lets you read, write, and watch regular files
5646 in their entirety. It cannot efficiently do random access in a big file
5647 or read non-regular files such as <code>/dev/random</code>.</p>
5648 </div>
5649 <div class="literalblock">
5650 <div class="content">
5651 <pre>file = cockpit.file(path,
5652 { syntax: syntax_object,
5653 binary: boolean,
5654 max_read_size: int,
5655 superuser: string,
5656 })
5657
5658 promise = file.read()
5659 promise
5660 .then((content, tag) =&gt; { ... })
5661 .catch(error =&gt; { ... })
5662
5663 promise = file.replace(content, [ expected_tag ])
5664 promise
5665 .then(new_tag =&gt; { ... })
5666 .catch(error =&gt; { ... })
5667
5668 promise = file.modify(callback, [ initial_content, initial_tag ]
5669 promise
5670 .then((new_content, new_tag) =&gt; { ... })
5671 .catch(error =&gt; { ... })
5672
5673 file.watch((content, tag, [error]) =&gt; { }, [ { read: boolean } ])
5674
5675 file.close()</pre>
5676 </div>
5677 </div>
5678 <div class="sect4">
5679 <h5 id="cockpit-file-simple">Simple reading and writing</h5>
5680 <div class="paragraph">
5681 <p>You can read a file with code like this:</p>
5682 </div>
5683 <div class="literalblock">
5684 <div class="content">
5685 <pre>cockpit.file("/path/to/file").read()
5686 .then((content, tag) =&gt; {
5687 ...
5688 })
5689 .catch(error =&gt; {
5690 ...
5691 });</pre>
5692 </div>
5693 </div>
5694 <div class="paragraph">
5695 <p>It is recommended to use absolute paths. Relative paths are resolved
5696 against <code>/</code>. To work with the current user&#8217;s files
5697 <a href="cockpit-login.html#cockpit-user">cockpit.user()</a> can be used to get the user&#8217;s home
5698 directory.</p>
5699 </div>
5700 <div class="paragraph">
5701 <p>The <code>read()</code> method returns a
5702 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>.</p>
5703 </div>
5704 <div class="paragraph">
5705 <p>When successful, the promise will be resolved with the content of the
5706 file. Unless you specify options to change this (see below), the file is
5707 assumed to be text in the UTF-8 encoding, and <code>content</code> will be a
5708 string.</p>
5709 </div>
5710 <div class="paragraph">
5711 <p>The tag that is passed to the <code>then()</code> callback is a short string that
5712 is associated with the file and changes whenever the content of the file
5713 changes. It is meant to be used with <code>replace()</code>.</p>
5714 </div>
5715 <div class="paragraph">
5716 <p>It is not an error when the file does not exist. In this case, the
5717 <code>then()</code> callback will be called with a <code>null</code> value for <code>content</code>
5718 and <code>tag</code> is <code>"-"</code>.</p>
5719 </div>
5720 <div class="paragraph">
5721 <p>The <code>superuser</code> option can be used the same way as described in the
5722 <a href="cockpit-channels.html#cockpit-channels-channel">cockpit.channel()</a> to provide a different
5723 access level to the file.</p>
5724 </div>
5725 <div class="paragraph">
5726 <p>You can use the <code>max_read_size</code> option to limit the amount of data
5727 that is read. If the file is larger than the given number of bytes, no
5728 data is read and the channel is closed with problem code <code>too-large</code>.
5729 The default limit is 16 MiB. The limit can be completely removed by
5730 setting it to -1.</p>
5731 </div>
5732 <div class="paragraph">
5733 <p>To write to a file, use code like this:</p>
5734 </div>
5735 <div class="literalblock">
5736 <div class="content">
5737 <pre>cockpit.file("/path/to/file").replace("my new content\n")
5738 .then(tag =&gt; {
5739 ...
5740 })
5741 .catch(error =&gt; {
5742 ...
5743 });</pre>
5744 </div>
5745 </div>
5746 <div class="paragraph">
5747 <p>The <code>replace()</code> method returns a
5748 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>.</p>
5749 </div>
5750 <div class="paragraph">
5751 <p>When the promise is resolved, the file has been atomically replaced (via
5752 the <code>rename()</code> syscall) with the new content. As with <code>read()</code>, by
5753 default the new content is a string and will be written to the file as
5754 UTF-8. The returned tag corresponds to the new content of the file.</p>
5755 </div>
5756 <div class="paragraph">
5757 <p>When the promise is rejected because of an error, the file or its meta
5758 data has not been changed in any way.</p>
5759 </div>
5760 <div class="paragraph">
5761 <p>As a special case, passing the value <code>null</code> to <code>replace()</code> will
5762 remove the file.</p>
5763 </div>
5764 <div class="paragraph">
5765 <p>The <code>replace()</code> method can also check for conflicting changes to a
5766 file. You can pass a tag (as returned by <code>read()</code> or <code>replace()</code>) to
5767 <code>replace()</code>, and the file will only be replaced if it still has the
5768 given tag. If the tag of the file has changed, <code>replace()</code> will fail
5769 with an error object that has <code>error.problem == "change-conflict"</code>.
5770 See <code>modify()</code> below for a convenient way to achieve transactional
5771 updates to a file.</p>
5772 </div>
5773 </div>
5774 <div class="sect4">
5775 <h5 id="cockpit-file-format">File format</h5>
5776 <div class="paragraph">
5777 <p>By default, a file is assumed to be text encoded in UTF-8, and the
5778 <code>read()</code> and <code>replace()</code> functions use strings to represent the
5779 content.</p>
5780 </div>
5781 <div class="paragraph">
5782 <p>By specifying the <code>syntax.parser()</code> and <code>syntax.stringify()</code>
5783 options, you can cause <code>read()</code> to parse the content before passing it
5784 back to you, and <code>replace()</code> to unparse it before writing.</p>
5785 </div>
5786 <div class="paragraph">
5787 <p>The main idea is to be able to write <code>{ syntax: JSON }</code>, of course,
5788 but you can easily pass in individual functions or make your own
5789 parser/unparser object:</p>
5790 </div>
5791 <div class="literalblock">
5792 <div class="content">
5793 <pre>cockpit.file("/path/to/file.json", { syntax: JSON })
5794
5795 var syntax_object = {
5796 parse: my_parser,
5797 stringify: my_unparser
5798 };
5799
5800 cockpit.file("/path/to/file", { syntax: syntax_object })</pre>
5801 </div>
5802 </div>
5803 <div class="paragraph">
5804 <p>Any exceptions thrown by the <code>parse()</code> and <code>stringify()</code> functions
5805 are caught and reported as read or write errors.</p>
5806 </div>
5807 <div class="paragraph">
5808 <p>The <code>null</code> value that is used to represent the content of a
5809 non-existing file (see "Simple reading and writing", above) is not
5810 passed through the <code>parse()</code> and <code>stringify()</code> functions.</p>
5811 </div>
5812 </div>
5813 <div class="sect4">
5814 <h5 id="cockpit-file-binary">Binary files</h5>
5815 <div class="paragraph">
5816 <p>By default the content of the file is assumed to be text encoded as
5817 UTF-8 and it can not contain zero bytes. The content is represented as a
5818 JavaScript string with <code>read()</code>, <code>replace()</code>, etc. By setting the
5819 <code>binary</code> option to true when creating the proxy, no assumptions are
5820 placed on the content, and it is represented as a <code>Uint8Array</code> in
5821 JavaScript.</p>
5822 </div>
5823 </div>
5824 <div class="sect4">
5825 <h5 id="cockpit-file-atomic">Atomic modifications</h5>
5826 <div class="paragraph">
5827 <p>Use <code>modify()</code> to modify the content of the file safely. A call to
5828 <code>modify()</code> will read the content of the file, call <code>callback</code> on the
5829 content, and then replace the content of the file with the return value
5830 of the callback.</p>
5831 </div>
5832 <div class="paragraph">
5833 <p>The <code>modify()</code> method uses the <code>read()</code> and <code>replace()</code> methods
5834 internally in the obvious way. Thus, the <code>syntax.parse()</code> and
5835 <code>syntax.stringify()</code> options work as expected, <code>null</code> represents a
5836 non-existing file, and the watch callbacks are fired.</p>
5837 </div>
5838 <div class="paragraph">
5839 <p>It will do this one or more times, until no other conflicting changes
5840 have been made to the file between reading and replacing it.</p>
5841 </div>
5842 <div class="paragraph">
5843 <p>The callback is called like this</p>
5844 </div>
5845 <div class="literalblock">
5846 <div class="content">
5847 <pre>new_content = callback (old_content)</pre>
5848 </div>
5849 </div>
5850 <div class="paragraph">
5851 <p>The callback is allowed to mutate <code>old_content</code>, but note that this
5852 will also mutate the objects that are passed to the watch callbacks.
5853 Returning <code>undefined</code> from the proxy is the same as returning
5854 <code>old_content</code>.</p>
5855 </div>
5856 <div class="paragraph">
5857 <p>The <code>modify()</code> method returns a
5858 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>.</p>
5859 </div>
5860 <div class="paragraph">
5861 <p>The promise will be resolved with the new content and its tag, like so</p>
5862 </div>
5863 <div class="literalblock">
5864 <div class="content">
5865 <pre>function shout(old_content) {
5866 return old_content.toUpperCase();
5867 }
5868
5869 cockpit.file("/path/to/file").modify(shout)
5870 .then((content, tag) =&gt; {
5871 ...
5872 })
5873 .catch(error =&gt; {
5874 ...
5875 });</pre>
5876 </div>
5877 </div>
5878 <div class="paragraph">
5879 <p>If you have cached the last content and tag results of the <code>read()</code> or
5880 <code>modify()</code> method, or the last values passed to a watch callback, you
5881 can pass them to <code>modify()</code> as the second and third argument. In this
5882 case, <code>modify()</code> will skip the initial read and start with the given
5883 values.</p>
5884 </div>
5885 </div>
5886 <div class="sect4">
5887 <h5 id="cockpit-file-notify">Change notifications</h5>
5888 <div class="paragraph">
5889 <p>Calling <code>watch()</code> will start monitoring the file for external changes.</p>
5890 </div>
5891 <div class="literalblock">
5892 <div class="content">
5893 <pre>handle = file.watch(callback);
5894
5895 handle_no_read = file.watch(callback, { read: false });</pre>
5896 </div>
5897 </div>
5898 <div class="paragraph">
5899 <p>Whenever a change occurs, the <code>callback()</code> is called with the new
5900 content and tag of the file. This might happen because of external
5901 changes, but also as part of calls to <code>read()</code>, <code>replace()</code>, and
5902 <code>modify()</code>.</p>
5903 </div>
5904 <div class="paragraph">
5905 <p>When a read error occurs, the <code>callback()</code> is called with an error as
5906 a third argument. Write errors are not reported via the watch callback.</p>
5907 </div>
5908 <div class="paragraph">
5909 <p>Calling <code>watch()</code> will also automatically call <code>read()</code> to get the
5910 initial content of the file. Thus, you normally don&#8217;t need to call
5911 <code>read()</code> at all when using <code>watch()</code>.</p>
5912 </div>
5913 <div class="paragraph">
5914 <p>To disable the automatic reading, e.g. for large files or unreadable
5915 file system objects, set the <code>read</code> option to <code>false</code>. The first
5916 <code>content</code> argument of the callback will then always be <code>null</code>.</p>
5917 </div>
5918 <div class="paragraph">
5919 <p>To free the resources used for monitoring, call <code>handle.remove()</code>.</p>
5920 </div>
5921 </div>
5922 <div class="sect4">
5923 <h5 id="cockpit-file-path">file.path</h5>
5924 <div class="paragraph">
5925 <p>A string containing the path that was passed to the <code>cockpit.file()</code>
5926 method.</p>
5927 </div>
5928 </div>
5929 <div class="sect4">
5930 <h5 id="cockpit-file-close">Closing</h5>
5931 <div class="paragraph">
5932 <p>Call the <code>close()</code> method on a file proxy to cancel all ongoing
5933 operations, such as reading, writing, and monitoring. The proxy should
5934 not be used after closing it.</p>
5935 </div>
5936 </div>
5937 </div>
5938 <div class="sect3">
5939 <h4 id="_cockpit_js_http_client">cockpit.js: HTTP Client</h4>
5940 <div class="paragraph">
5941 <p>Cockpit allows access to local HTTP and REST services via this API.</p>
5942 </div>
5943 <div class="sect4">
5944 <h5 id="cockpit-http-constructor">cockpit.http()</h5>
5945 <div class="literalblock">
5946 <div class="content">
5947 <pre>http = cockpit.http(endpoint, [options])
5948 http = cockpit.http(options)</pre>
5949 </div>
5950 </div>
5951 <div class="paragraph">
5952 <p>Create a new HTTP client. The <code>endpoint</code> can be a file path starting
5953 with <code>/</code> to connect to a unix socket, or it can be a port number to
5954 connect to. The optional <code>options</code> argument is a javascript plain
5955 object, and may include:</p>
5956 </div>
5957 <div class="dlist">
5958 <dl>
5959 <dt class="hdlist1"><code>"address"</code></dt>
5960 <dd>
5961 <p>Connect to an address other than localhost. Must be a valid host name
5962 or IP address. To use this option you also must provide a port number.</p>
5963 </dd>
5964 <dt class="hdlist1"><code>"port"</code></dt>
5965 <dd>
5966 <p>Port number to use with "address" option, when not given in
5967 <code>endpoint</code>.</p>
5968 </dd>
5969 <dt class="hdlist1"><code>"tls"</code></dt>
5970 <dd>
5971 <p>Object properties for an https connection. See
5972 <code>http-stream2 TLS options</code>.</p>
5973 </dd>
5974 <dt class="hdlist1"><code>"headers"</code></dt>
5975 <dd>
5976 <p>Additional HTTP headers to include with the HTTP request. This is a
5977 plain javascript object with each key as a header name, and each value
5978 as the header value.</p>
5979 </dd>
5980 <dt class="hdlist1"><code>"superuser"</code></dt>
5981 <dd>
5982 <p>Set to <code>"require"</code> to open this channel as root. If the currently
5983 logged in user is not permitted to become root (eg: via <code>pkexec</code>)
5984 then the <code>channel</code> will immediately be
5985 <a href="#cockpit-channels-close-ev">closed</a> with a <code>"access-denied"</code>
5986 problem code.
5987 +
5988 Set to <code>"try"</code> to try to make the request as root, but if that
5989 fails, fall back to perform an unprivileged request.</p>
5990 </dd>
5991 <dt class="hdlist1"><code>"tls"</code></dt>
5992 <dd>
5993 <p>If set to a plain javascript object, then the connection will be an
5994 HTTPS connection and include TLS encryption. The fields of the <code>tls</code>
5995 object declare various TLS configuration and data. All fields are
5996 optional:
5997 +</p>
5998 <div class="ulist">
5999 <ul>
6000 <li>
6001 <p><code>"authority"</code>: Certificate authority(s) to expect as signers of
6002 the server&#8217;s TLS certificate, represented as a plain javascript
6003 object. It should have either a <code>"file"</code> field containing a readable
6004 PEM file on the system containing authorities, or a <code>"data"</code> with
6005 PEM encoded certificate data.</p>
6006 </li>
6007 <li>
6008 <p><code>"certificate"</code>: A client certificate to use, represented as a
6009 plain javascript object. It should have either a <code>"file"</code> field
6010 containing a readable PEM file on the system to use as a certificate,
6011 or a <code>"data"</code> with PEM encoded certificate data.</p>
6012 </li>
6013 <li>
6014 <p><code>"key"</code>: A client key to use, represented as a plain javascript
6015 object. It should have either a <code>"file"</code> field containing a readable
6016 PEM file on the system to use as a key, or a <code>"data"</code> with PEM
6017 encoded key data.</p>
6018 </li>
6019 <li>
6020 <p><code>"validate"</code>: A boolean that describes whether to validate the
6021 server&#8217;s TLS certificate or not. By default local connections are not
6022 validated, and remote connections are validated.</p>
6023 </li>
6024 </ul>
6025 </div>
6026 </dd>
6027 </dl>
6028 </div>
6029 <div class="paragraph">
6030 <p>Here is a somewhat complex example of using most of the above
6031 <code>options</code> when when calling <code>cockpit.http()</code>:</p>
6032 </div>
6033 <div class="literalblock">
6034 <div class="content">
6035 <pre>http = cockpit.http({
6036 "address": "localhost",
6037 "headers": {
6038 "Authorization": "Basic dXNlcjpwYXNzd29yZA=="
6039 },
6040 "port": 443,
6041 "tls": {
6042 "validate": true,
6043 "authority": {
6044 "file": "/etc/pki/tls/certs/ca-bundle.crt",
6045 },
6046 "certificate": {
6047 "data": "-----BEGIN CERTIFICATE-----\nMIIDsDCCA..."
6048 },
6049 "key": {
6050 "data": "-----BEGIN RSA PRIVATE KEY-----\nMIIEogIBA..."
6051 }
6052 }
6053 });</pre>
6054 </div>
6055 </div>
6056 </div>
6057 <div class="sect4">
6058 <h5 id="cockpit-http-get">http.get()</h5>
6059 <div class="literalblock">
6060 <div class="content">
6061 <pre>request = http.get(path, [params, [headers]])</pre>
6062 </div>
6063 </div>
6064 <div class="paragraph">
6065 <p>Perform an HTTP GET request for the given <code>path</code>. If the <code>params</code> is
6066 specified it should be a plain javascript object, which will be turned
6067 into a query string.</p>
6068 </div>
6069 <div class="paragraph">
6070 <p>Optionally a plain javascript object containing headers can be included
6071 in the <code>headers</code> argument.</p>
6072 </div>
6073 <div class="paragraph">
6074 <p>The return value is a
6075 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
6076 that will complete if the request happens successfully, or fail if
6077 there&#8217;s a problem.</p>
6078 </div>
6079 </div>
6080 <div class="sect4">
6081 <h5 id="cockpit-http-post">http.post()</h5>
6082 <div class="literalblock">
6083 <div class="content">
6084 <pre>request = http.post(path, body, [headers])</pre>
6085 </div>
6086 </div>
6087 <div class="paragraph">
6088 <p>Perform an HTTP POST request for the given <code>path</code>. The <code>body</code> can be
6089 a string, or a javascript plain object, which will be encoded as JSON
6090 data. If <code>body</code> is <code>undefined</code> or <code>null</code> then an empty HTTP body
6091 will be sent.</p>
6092 </div>
6093 <div class="paragraph">
6094 <p>Optionally a plain javascript object containing headers can be included
6095 in the <code>headers</code> argument.</p>
6096 </div>
6097 <div class="paragraph">
6098 <p>The return value is a
6099 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
6100 that will complete if the request happens successfully, or fail if
6101 there&#8217;s a problem.</p>
6102 </div>
6103 </div>
6104 <div class="sect4">
6105 <h5 id="cockpit-http-request">http.request()</h5>
6106 <div class="literalblock">
6107 <div class="content">
6108 <pre>request = http.request(options)</pre>
6109 </div>
6110 </div>
6111 <div class="paragraph">
6112 <p>Perform an HTTP request. The <code>options</code> can contain the following:</p>
6113 </div>
6114 <div class="dlist">
6115 <dl>
6116 <dt class="hdlist1"><code>"body"</code></dt>
6117 <dd>
6118 <p>The HTTP request body. If you do not specify a body, then you must
6119 call <a href="#cockpit-http-input">request.input()</a> to complete the body
6120 and allow the request to start.</p>
6121 </dd>
6122 <dt class="hdlist1"><code>"headers"</code></dt>
6123 <dd>
6124 <p>A javascript plain object containing HTTP headers.</p>
6125 </dd>
6126 <dt class="hdlist1"><code>"method"</code></dt>
6127 <dd>
6128 <p>The HTTP method. Defaults to <code>"GET"</code>.</p>
6129 </dd>
6130 <dt class="hdlist1"><code>"params"</code></dt>
6131 <dd>
6132 <p>A javascript plain object containing query string parameters.</p>
6133 </dd>
6134 <dt class="hdlist1"><code>"path"</code></dt>
6135 <dd>
6136 <p>The HTTP path. Defaults to <code>/</code>.</p>
6137 </dd>
6138 </dl>
6139 </div>
6140 <div class="paragraph">
6141 <p>The return value is a
6142 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
6143 that will complete if the request happens successfully, or fail if
6144 there&#8217;s a problem.</p>
6145 </div>
6146 </div>
6147 <div class="sect4">
6148 <h5 id="cockpit-http-then">request.then()</h5>
6149 <div class="literalblock">
6150 <div class="content">
6151 <pre>request.then(data =&gt; { ... })</pre>
6152 </div>
6153 </div>
6154 <div class="paragraph">
6155 <p>This is a standard
6156 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
6157 method. It sets up a handler to be called when the request finishes
6158 successfully.</p>
6159 </div>
6160 <div class="paragraph">
6161 <p>The <code>data</code> argument contains the body result of the request. If it a
6162 string, unless the process was opened in binary mode, in which case the
6163 <code>data</code> is an array of bytes. If a <code>request.stream()</code> handler is set
6164 up, then any standard output data consumed by the handler will not be
6165 included in the <code>data</code> argument.</p>
6166 </div>
6167 </div>
6168 <div class="sect4">
6169 <h5 id="cockpit-http-catch">request.catch()</h5>
6170 <div class="literalblock">
6171 <div class="content">
6172 <pre>request.catch((exception[, data]) =&gt; { ... })</pre>
6173 </div>
6174 </div>
6175 <div class="paragraph">
6176 <p>This is a standard
6177 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
6178 method. It sets up a handler to be called when the request fails, or
6179 returns an error code.</p>
6180 </div>
6181 <div class="paragraph">
6182 <p>The <code>exception</code> object passed to the handler can have the following
6183 fields:</p>
6184 </div>
6185 <div class="dlist">
6186 <dl>
6187 <dt class="hdlist1"><code>problem</code></dt>
6188 <dd>
6189 <p>A <a href="cockpit-error.html#cockpit-problems">problem code</a> string when a problem occurred
6190 starting or communicating with the server. This is <code>null</code> if the
6191 process exited or was terminated.</p>
6192 </dd>
6193 <dt class="hdlist1"><code>status</code></dt>
6194 <dd>
6195 <p>The numeric status of the response. This is <code>null</code> if no response
6196 was received.</p>
6197 </dd>
6198 <dt class="hdlist1"><code>reason</code></dt>
6199 <dd>
6200 <p>A string reason returned in the response. This is <code>null</code> if no
6201 response was received.</p>
6202 </dd>
6203 <dt class="hdlist1"><code>message</code></dt>
6204 <dd>
6205 <p>A string message returned in the response. This is <code>null</code> if no
6206 response was received.</p>
6207 </dd>
6208 </dl>
6209 </div>
6210 <div class="paragraph">
6211 <p>If the request returned a response body, it will be available in the
6212 <code>data</code> argument. Otherwise this argument will be <code>undefined</code>.</p>
6213 </div>
6214 </div>
6215 <div class="sect4">
6216 <h5 id="cockpit-http-response">request.response()</h5>
6217 <div class="literalblock">
6218 <div class="content">
6219 <pre>request.response((status, headers) =&gt; { ... })</pre>
6220 </div>
6221 </div>
6222 <div class="paragraph">
6223 <p>This sets up a handler to be called when the HTTP request gets the
6224 initial response from the server. The <code>status</code> argument is the HTTP
6225 status integer, and the <code>headers</code> is a plain javascript object
6226 containing the headers of the response.</p>
6227 </div>
6228 </div>
6229 <div class="sect4">
6230 <h5 id="cockpit-http-stream">request.stream()</h5>
6231 <div class="literalblock">
6232 <div class="content">
6233 <pre>request.stream(data =&gt; { ... })</pre>
6234 </div>
6235 </div>
6236 <div class="paragraph">
6237 <p>This sets up a handler to be called when the request returns output
6238 data. The handler will be called multiple times.</p>
6239 </div>
6240 <div class="paragraph">
6241 <p>Only one handler may be registered at a time. Registering an additional
6242 handler replaces the previous one. The handler receives either string
6243 <code>data</code> or an array of binary bytes as its argument. A stream handler
6244 may return a number, which indicates the number of characters or bytes
6245 consumed from <code>data</code>. Any data not consumed will be included again the
6246 next time the handler is called.</p>
6247 </div>
6248 <div class="paragraph">
6249 <p>If a <code>request.stream()</code> handler is set up, then the <code>request.then()</code>
6250 handlers will only get any remaining data not consumed by the stream
6251 handler.</p>
6252 </div>
6253 </div>
6254 <div class="sect4">
6255 <h5 id="cockpit-http-input">request.input()</h5>
6256 <div class="literalblock">
6257 <div class="content">
6258 <pre>request.input(data, [stream])</pre>
6259 </div>
6260 </div>
6261 <div class="paragraph">
6262 <p>This method writes <code>data</code> to the HTTP request body. It is only valid
6263 if no <code>"body"</code> has been specified in
6264 <a href="#cockpit-http-request">http.request()</a> options. If <code>stream</code> is
6265 <code>true</code> then this function can be called again to provide further data.</p>
6266 </div>
6267 </div>
6268 <div class="sect4">
6269 <h5 id="cockpit-http-close">request.close()</h5>
6270 <div class="literalblock">
6271 <div class="content">
6272 <pre>request.close([problem])</pre>
6273 </div>
6274 </div>
6275 <div class="paragraph">
6276 <p>Cancel the request. If <code>problem</code> is specified it should be a standard
6277 <a href="cockpit-error.html#cockpit-problems">problem code</a> string.</p>
6278 </div>
6279 </div>
6280 <div class="sect4">
6281 <h5 id="cockpit-http-close-all">http.close()</h5>
6282 <div class="literalblock">
6283 <div class="content">
6284 <pre>http.close([problem])</pre>
6285 </div>
6286 </div>
6287 <div class="paragraph">
6288 <p>Cancel all outstanding requests with the given problem code. This is
6289 useful when you know that the server is going down soon.</p>
6290 </div>
6291 </div>
6292 </div>
6293 <div class="sect3">
6294 <h4 id="_cockpit_js_localization">cockpit.js: Localization</h4>
6295 <div class="paragraph">
6296 <p>Cockpit provides a <a href="https://www.gnu.org/software/gettext/"><code>gettext()</code></a>
6297 like API for easy translation of strings.</p>
6298 </div>
6299 <div class="sect4">
6300 <h5 id="cockpit-locale-language">cockpit.language</h5>
6301 <div class="paragraph">
6302 <p>The current locale language code. This is set based on the
6303 <a href="#cockpit-locale-locale"><code>cockpit.locale()</code></a> data loaded.</p>
6304 </div>
6305 </div>
6306 <div class="sect4">
6307 <h5 id="cockpit-locale-locale">cockpit.locale()</h5>
6308 <div class="literalblock">
6309 <div class="content">
6310 <pre>cockpit.locale(po)</pre>
6311 </div>
6312 </div>
6313 <div class="paragraph">
6314 <p>Load locale information for a given <code>po</code> data. The data should be JSON
6315 data in the <a href="https://www.npmjs.org/package/po2json">po2json</a> format. The
6316 data will be loaded globally. If <code>po</code> data has already been loaded,
6317 then this will extend that loaded data with additional strings. Any
6318 identical translations strings will be replaced with the new strings. A
6319 <code>null</code> argument clears all the locale information previously loaded.</p>
6320 </div>
6321 <div class="paragraph">
6322 <p>Various methods such as
6323 <a href="#cockpit-locale-gettext"><code>cockpit.gettext()</code></a> make use of the
6324 loaded data.</p>
6325 </div>
6326 </div>
6327 <div class="sect4">
6328 <h5 id="cockpit-locale-gettext">cockpit.gettext()</h5>
6329 <div class="literalblock">
6330 <div class="content">
6331 <pre>translated = cockpit.gettext([context], string)
6332 var _ = cockpit.gettext
6333 var C_ = cockpit.gettext
6334 translated = _("string")
6335 translated = C_("context", "string")</pre>
6336 </div>
6337 </div>
6338 <div class="paragraph">
6339 <p>Lookup <code>string</code> for translation in the loaded locale data. The
6340 translated string will be returned, or <code>string</code> will be returned if no
6341 such translated string is present. The <code>context</code> argument is an
6342 optional string used to qualify the string.</p>
6343 </div>
6344 <div class="paragraph">
6345 <p>This function can be assigned to a variable called <code>_</code> (underscore)
6346 which will make your code work with the typical <code>_("string")</code> syntax.</p>
6347 </div>
6348 </div>
6349 <div class="sect4">
6350 <h5 id="cockpit-locale-noop">cockpit.noop()</h5>
6351 <div class="literalblock">
6352 <div class="content">
6353 <pre>var N_ = cockpit.noop
6354 var NC_ = cockpit.noop</pre>
6355 </div>
6356 </div>
6357 <div class="paragraph">
6358 <p>A noop function suitable for assigning to <code>N_</code> or <code>NC_</code> so that
6359 gettext scanners will be able to find translatable strings. More
6360 specifically this function returns its last argument.</p>
6361 </div>
6362 </div>
6363 <div class="sect4">
6364 <h5 id="cockpit-locale-ngettext">cockpit.ngettext()</h5>
6365 <div class="literalblock">
6366 <div class="content">
6367 <pre>translated = cockpit.ngettext([context], string1, stringN, number)</pre>
6368 </div>
6369 </div>
6370 <div class="paragraph">
6371 <p>Lookup a string appropriate for a pluralization form of the <code>number</code>.
6372 Various languages have complex pluralization forms that go far between
6373 the singular and plural forms speakers of English are familiar with. If
6374 no such translated string is found then either one of <code>string1</code> or
6375 <code>stringN</code> is returned according to simple pluralization rules.</p>
6376 </div>
6377 <div class="paragraph">
6378 <p>The <code>context</code> argument is an optional string used to qualify the
6379 string.</p>
6380 </div>
6381 </div>
6382 <div class="sect4">
6383 <h5 id="cockpit-locale-translate">cockpit.translate()</h5>
6384 <div class="literalblock">
6385 <div class="content">
6386 <pre>cockpit.translate()
6387 cockpit.translate(element, ...)
6388 cockpit.translate(selection)</pre>
6389 </div>
6390 </div>
6391 <div class="paragraph">
6392 <p>The document will be scanned for <code>translate</code> tags and they will be
6393 translated according to the strings in loaded locale data. One or more
6394 <code>element</code> arguments may be specified. These are DOM elements for
6395 specific parts of the document to be translated. If no <code>element</code> is
6396 specified then the entire document is translated.</p>
6397 </div>
6398 <div class="paragraph">
6399 <p>If an array or array-like object is passed as a <code>selection</code> then all
6400 DOM elements in the array will be treated as parts of the document to be
6401 translated.</p>
6402 </div>
6403 </div>
6404 </div>
6405 <div class="sect3">
6406 <h4 id="_cockpit_js_page_location_and_jumping">cockpit.js: Page Location and Jumping</h4>
6407 <div class="paragraph">
6408 <p>Page location and navigation between components</p>
6409 </div>
6410 <div class="sect4">
6411 <h5 id="cockpit-location-general">Page location</h5>
6412 <div class="literalblock">
6413 <div class="content">
6414 <pre>location = cockpit.location
6415 cockpit.location = "/path"</pre>
6416 </div>
6417 </div>
6418 <div class="paragraph">
6419 <p>Cockpit components often have different views, without changing the HTML
6420 file that is being viewed. These are known as pages.
6421 <code>cockpit.location</code> is an object that can be used to read the current
6422 page and to navigate to a different page location. It works by updating
6423 <code>window.location.hash</code>.</p>
6424 </div>
6425 <div class="paragraph">
6426 <p>The <code>cockpit.location</code> looks like a HTTP path with a possible query
6427 string:</p>
6428 </div>
6429 <div class="literalblock">
6430 <div class="content">
6431 <pre>/path/sub/page?option=value,option2</pre>
6432 </div>
6433 </div>
6434 <div class="paragraph">
6435 <p>The <a href="#cockpit-location-path"><code>location.path</code></a> and
6436 <a href="#cockpit-location-options"><code>location.options</code></a> contain a parsed
6437 form of the location. While the location cannot be modified in place, a
6438 new one can be created by assigning a string to <code>cockpit.location</code> or
6439 by calling the <a href="#cockpit-location-go"><code>location.go()</code></a> function.</p>
6440 </div>
6441 <div class="paragraph">
6442 <p><code>cockpit.location</code> is designed similarly to <code>window.location</code> in
6443 that the location object is preplaced whenever the current page location
6444 changes. To be aware of when the page location changes listen for the
6445 <a href="#cockpit-location-changed"><code>cockpit.onlocationchanged</code></a> event.</p>
6446 </div>
6447 <div class="paragraph">
6448 <p>Using the location object as a string will result in the
6449 <a href="#cockpit-location-href"><code>location.href</code></a>.</p>
6450 </div>
6451 <div class="sect5">
6452 <h6 id="cockpit-location-href">location.href</h6>
6453 <div class="paragraph">
6454 <p>The string representation of this page location, including any options.</p>
6455 </div>
6456 </div>
6457 <div class="sect5">
6458 <h6 id="cockpit-location-path">location.path</h6>
6459 <div class="paragraph">
6460 <p>An array of path segments, parsed and decoded appropriately. An empty
6461 array denotes the root path.</p>
6462 </div>
6463 </div>
6464 <div class="sect5">
6465 <h6 id="cockpit-location-options">location.options</h6>
6466 <div class="paragraph">
6467 <p>A javascript object containing the various options present in the
6468 location.</p>
6469 </div>
6470 <div class="paragraph">
6471 <p>If an option appears more than once, its value will be an array.</p>
6472 </div>
6473 </div>
6474 <div class="sect5">
6475 <h6 id="cockpit-location-go">location.go()</h6>
6476 <div class="literalblock">
6477 <div class="content">
6478 <pre>location.go(path, [options])</pre>
6479 </div>
6480 </div>
6481 <div class="paragraph">
6482 <p>Changes the current location to the given <code>path</code> and <code>options</code>. If
6483 the <code>path</code> argument is a string, it will be parsed into a path. If it
6484 is a relative path, then the result will be relative to the current
6485 <code>location.path</code>. If the <code>path</code> argument is an array of path
6486 segments, it will be treated as a full parsed absolute path.</p>
6487 </div>
6488 <div class="paragraph">
6489 <p>Any options found in a <code>path</code> will be added to those in the optional
6490 <code>options</code> argument, and used in the result.</p>
6491 </div>
6492 <div class="paragraph">
6493 <p>The location change will only take effect if the location has not
6494 changed in the meantime. This can be to good effect by saving a
6495 <code>cockpit.location</code> object and doing a conditional navigation, by
6496 calling the saved <code>location.go()</code> method later. This will only
6497 navigate if the user or other code has not navigated in the meantime.</p>
6498 </div>
6499 </div>
6500 <div class="sect5">
6501 <h6 id="cockpit-location-replace">location.replace()</h6>
6502 <div class="literalblock">
6503 <div class="content">
6504 <pre>location.replace(path, [options])</pre>
6505 </div>
6506 </div>
6507 <div class="paragraph">
6508 <p>Similar to <a href="#cockpit-location-go"><code>location.go()</code></a> except the
6509 location change will not result in a navigation change in the browser&#8217;s
6510 history.</p>
6511 </div>
6512 </div>
6513 <div class="sect5">
6514 <h6 id="cockpit-location-decode">location.decode()</h6>
6515 <div class="literalblock">
6516 <div class="content">
6517 <pre>path = location.decode(href, [options])</pre>
6518 </div>
6519 </div>
6520 <div class="paragraph">
6521 <p>Decode a cockpit href into its <code>path</code> array. If the <code>options</code>
6522 argument is specified, then it will be populated with options found in
6523 the href.</p>
6524 </div>
6525 <div class="paragraph">
6526 <p>If href is a relative path it will be resolved relative to
6527 <code>location.href</code>.</p>
6528 </div>
6529 </div>
6530 <div class="sect5">
6531 <h6 id="cockpit-location-encode">location.encode()</h6>
6532 <div class="literalblock">
6533 <div class="content">
6534 <pre>href = location.encode(path, [options])</pre>
6535 </div>
6536 </div>
6537 <div class="paragraph">
6538 <p>Encode the given <code>path</code> and <code>options</code> into a cockpit href. The
6539 <code>path</code> argument may be an array of path segments, or a string path. If
6540 a relative path is passed, it will be resolved relative to
6541 <code>location.href</code>.</p>
6542 </div>
6543 </div>
6544 <div class="sect5">
6545 <h6 id="cockpit-location-changed">cockpit.onlocationchanged</h6>
6546 <div class="literalblock">
6547 <div class="content">
6548 <pre>cockpit.addEventListener("locationchanged", function() { ... })</pre>
6549 </div>
6550 </div>
6551 <div class="paragraph">
6552 <p>An event emitted when over the <code>cockpit.location</code> changes. Typically a
6553 component reacts to this event by updating its interface to reflect the
6554 new <a href="#cockpit-location-path"><code>cockpit.location.path</code></a> and
6555 <a href="#cockpit-location-options"><code>cockpit.location.options</code></a>.</p>
6556 </div>
6557 <div class="paragraph">
6558 <p>This event is not triggered immediately during a <code>location.go()</code> or
6559 similar call. It will be triggered asynchronously at a later time.</p>
6560 </div>
6561 </div>
6562 </div>
6563 <div class="sect4">
6564 <h5 id="cockpit-jump">Jumping between components</h5>
6565 <div class="literalblock">
6566 <div class="content">
6567 <pre>cockpit.jump("/system/log")</pre>
6568 </div>
6569 </div>
6570 <div class="paragraph">
6571 <p>In Cockpit in there multiple components shown. In order to tell Cockpit
6572 to jump to and show another component and a certain location within that
6573 component, use the <code>cockpit.jump()</code> function. Stable component paths
6574 are documented. Don&#8217;t assume you can navigate into paths that are not
6575 stable API.</p>
6576 </div>
6577 <div class="sect5">
6578 <h6 id="cockpit-jump-jump">cockpit.jump()</h6>
6579 <div class="literalblock">
6580 <div class="content">
6581 <pre>cockpit.jump(path, [ host ])</pre>
6582 </div>
6583 </div>
6584 <div class="paragraph">
6585 <p>Ask Cockpit to jump to another component. The location of the current
6586 component will not be affected. The <code>path</code> argument can be a string
6587 path, starting with <code>/</code> or an array containing the parts of a path
6588 that will be joined to create a path. If <code>host</code> is not specified, then
6589 the component on the same host as the caller will be displayed. If host
6590 is null, then the host portion of the path will be removed, displaying
6591 the component on the host that cockpit is connected directly to.</p>
6592 </div>
6593 <div class="paragraph">
6594 <p>If the calling component is not running within Cockpit, or the calling
6595 component is not currently displayed, then the jump will not happen, and
6596 this function has no effect.</p>
6597 </div>
6598 </div>
6599 <div class="sect5">
6600 <h6 id="cockpit-jump-hidden">cockpit.hidden</h6>
6601 <div class="paragraph">
6602 <p>A boolean property that indicates if the current component page is
6603 visible or hidden. When the code or user jumps to another component, the
6604 prior one remains loaded and initialized but is hidden. Use this
6605 property together with the
6606 <a href="#cockpit-jump-visibilitychange"><code>cockpit.onvisibilitychange</code></a>
6607 event to decide whether or not to perform expensive tasks to update the
6608 interface.</p>
6609 </div>
6610 <div class="paragraph">
6611 <p>This property is analogous to the <code>document.hidden</code> page visibility
6612 API, but works with the document and frame implementation of Cockpit.</p>
6613 </div>
6614 </div>
6615 <div class="sect5">
6616 <h6 id="cockpit-jump-visibilitychange">cockpit.onvisibilitychange</h6>
6617 <div class="literalblock">
6618 <div class="content">
6619 <pre>cockpit.onvisibilitychange = function() { ... }</pre>
6620 </div>
6621 </div>
6622 <div class="paragraph">
6623 <p>This event is emitted when the
6624 <a href="#cockpit-jump-hidden"><code>cockpit.hidden</code></a> property changes. This
6625 event is similar to the <code>document.onvisibilitychange</code> API, but works
6626 with the document and frame implementation of Cockpit.</p>
6627 </div>
6628 </div>
6629 </div>
6630 </div>
6631 <div class="sect3">
6632 <h4 id="_cockpit_js_user_session">cockpit.js: User Session</h4>
6633 <div class="paragraph">
6634 <p>User information and login session state</p>
6635 </div>
6636 <div class="sect4">
6637 <h5 id="cockpit-logout">cockpit.logout()</h5>
6638 <div class="literalblock">
6639 <div class="content">
6640 <pre>cockpit.logout([reload])</pre>
6641 </div>
6642 </div>
6643 <div class="paragraph">
6644 <p>Logout of Cockpit. Unless <code>reload</code> is <code>false</code> this will also cause
6645 the page to be reloaded, so that the user can see the logged out state.</p>
6646 </div>
6647 </div>
6648 <div class="sect4">
6649 <h5 id="cockpit-user">cockpit.user()</h5>
6650 <div class="literalblock">
6651 <div class="content">
6652 <pre>var promise = cockpit.user();
6653 promise.then(user =&gt; { ... });</pre>
6654 </div>
6655 </div>
6656 <div class="paragraph">
6657 <p>This object contains information about the user that&#8217;s currently logged
6658 into cockpit. The following fields are defined:</p>
6659 </div>
6660 <div class="dlist">
6661 <dl>
6662 <dt class="hdlist1"><code>"id"</code></dt>
6663 <dd>
6664 <p>This is unix user id.</p>
6665 </dd>
6666 <dt class="hdlist1"><code>"gid"</code></dt>
6667 <dd>
6668 <p>This is unix user group id.</p>
6669 </dd>
6670 <dt class="hdlist1"><code>"name"</code></dt>
6671 <dd>
6672 <p>This is the unix user name like <code>"root"</code>.</p>
6673 </dd>
6674 <dt class="hdlist1"><code>"full_name"</code></dt>
6675 <dd>
6676 <p>This is a readable name for the user.</p>
6677 </dd>
6678 <dt class="hdlist1"><code>"groups"</code></dt>
6679 <dd>
6680 <p>This is an array of group names to which the user belongs. Since
6681 version 318, the first item in this list is the primary group.</p>
6682 </dd>
6683 <dt class="hdlist1"><code>"home"</code></dt>
6684 <dd>
6685 <p>This is user&#8217;s home directory.</p>
6686 </dd>
6687 <dt class="hdlist1"><code>"shell"</code></dt>
6688 <dd>
6689 <p>This is unix user shell.</p>
6690 </dd>
6691 </dl>
6692 </div>
6693 <div class="paragraph">
6694 <p>Returns a promise that completes once the user information is available.</p>
6695 </div>
6696 <div class="admonitionblock warning">
6697 <table>
6698 <tr>
6699 <td class="icon">
6700 <div class="title">Warning</div>
6701 </td>
6702 <td class="content">
6703 <div class="paragraph">
6704 <p><code>cockpit.user()</code> is soft-deprecated since Cockpit 336, if your page
6705 does not need to maintain compatibility with older Cockpit versions you
6706 can use <a href="cockpit-util.html#cockpit-info">cockpit.info</a> to obtain the user information.</p>
6707 </div>
6708 </td>
6709 </tr>
6710 </table>
6711 </div>
6712 </div>
6713 <div class="sect4">
6714 <h5 id="cockpit-permission">Permission lookup</h5>
6715 <div class="paragraph">
6716 <p>Cockpit provides a mechanism for checking if the current user satisfies
6717 a given criteria. This is meant for updating UI elements based on what
6718 actions the user can perform. It is <em>not an access control mechanism</em>.</p>
6719 </div>
6720 <div class="sect5">
6721 <h6 id="cockpit-permission-constructor">cockpit.permission()</h6>
6722 <div class="literalblock">
6723 <div class="content">
6724 <pre>permission = cockpit.permission([options])</pre>
6725 </div>
6726 </div>
6727 <div class="paragraph">
6728 <p>Create a new permission object to check if the current user has a
6729 particular permission specified by <code>options</code>:</p>
6730 </div>
6731 <div class="dlist">
6732 <dl>
6733 <dt class="hdlist1"><code>admin: true</code></dt>
6734 <dd>
6735 <p>True if the session has superuser privileges, i.e. can run channels as
6736 root with <code>{ superuser: "require" }</code>.</p>
6737 </dd>
6738 <dt class="hdlist1"><code>group:</code> <em>name</em></dt>
6739 <dd>
6740 <p>True if the currently logged user is a member of group <em>name</em>.</p>
6741 </dd>
6742 </dl>
6743 </div>
6744 <div class="paragraph">
6745 <p>The permission result is always true for the "root" user. When
6746 <code>options</code> is not given, check if the current user is root.</p>
6747 </div>
6748 </div>
6749 <div class="sect5">
6750 <h6 id="cockpit-permission-allowed">permission.allowed</h6>
6751 <div class="paragraph">
6752 <p>A boolean value which indicates if the permission is allowed or not.
6753 This will be <code>null</code> if the permission is unknown, or there was an
6754 error checking the permission or the permission data has not yet loaded.
6755 This property will update asynchronously and if you wish to be notified
6756 of changes connect to the
6757 <a href="#cockpit-permission-changed">permission.onchanged</a> event.</p>
6758 </div>
6759 </div>
6760 <div class="sect5">
6761 <h6 id="cockpit-permission-changed">permission.onchanged</h6>
6762 <div class="literalblock">
6763 <div class="content">
6764 <pre>permission.addEventListener("changed", function() { ... })</pre>
6765 </div>
6766 </div>
6767 <div class="paragraph">
6768 <p>This event is fired when the permission changes. In particular the
6769 <a href="#cockpit-permission-allowed">permission.allowed</a> property.</p>
6770 </div>
6771 </div>
6772 <div class="sect5">
6773 <h6 id="cockpit-permission-close">permission.close()</h6>
6774 <div class="literalblock">
6775 <div class="content">
6776 <pre>permission.close()</pre>
6777 </div>
6778 </div>
6779 <div class="paragraph">
6780 <p>Closes the permission object and tears down any registered callbacks and
6781 dbus subscriptions.</p>
6782 </div>
6783 </div>
6784 </div>
6785 </div>
6786 <div class="sect3">
6787 <h4 id="_cockpit_js_manifests">cockpit.js: Manifests</h4>
6788 <div class="sect4">
6789 <h5 id="cockpit-manifest-loading">Loading Manifests</h5>
6790 <div class="paragraph">
6791 <p>For a convenient access to all page manifests, include
6792 <code>&lt;script src="../manifests.js"&gt;&lt;/script&gt;</code> into your page to register
6793 the manifests at the <code>cockpit.manifests</code> global variable.</p>
6794 </div>
6795 <div class="paragraph">
6796 <p>You can also load <code>../manifests.json</code> directly in your page, with
6797 <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch"><code>fetch()</code></a>.</p>
6798 </div>
6799 </div>
6800 </div>
6801 <div class="sect3">
6802 <h4 id="_cockpit_js_metrics">cockpit.js: Metrics</h4>
6803 <div class="paragraph">
6804 <p>Metrics about the system can be retrieved from several sources using
6805 <a href="#cockpit-metrics-function"><code>cockpit.metrics()</code></a> metrics channels. The
6806 metrics are made available as series data, and can be used with the
6807 <a href="cockpit-series-data.html#cockpit-series"><code>cockpit.series()</code></a> and
6808 <a href="cockpit-series-data.html#cockpit-grid"><code>cockpit.grid()</code></a> facilities.</p>
6809 </div>
6810 <div class="sect4">
6811 <h5 id="cockpit-metrics-function">cockpit.metrics()</h5>
6812 <div class="literalblock">
6813 <div class="content">
6814 <pre>metrics = cockpit.metrics(interval, options, cache)</pre>
6815 </div>
6816 </div>
6817 <div class="paragraph">
6818 <p>Opens a new metrics channel. The data retrieved will be available in the
6819 <a href="#cockpit-metrics-series"><code>metrics.series</code></a> series sink, and can be
6820 used together with <a href="cockpit-series-data.html#cockpit-grid"><code>cockpit.grid()</code></a> objects.</p>
6821 </div>
6822 <div class="paragraph">
6823 <p>The <code>interval</code> is in milliseconds, and is the granularity of the
6824 series data retrieved. Any grids consuming the data must have the same
6825 interval.</p>
6826 </div>
6827 <div class="paragraph">
6828 <p>The <code>cache</code> argument is a cache identifier. If specified, then this
6829 metrics channel will share data with other metrics channels of the same
6830 identifier. Make sure to use a globally unique string.</p>
6831 </div>
6832 <div class="paragraph">
6833 <p>The <code>options</code> argument is either a javascript plain object, or an
6834 array of those. Each object can have the following fields.</p>
6835 </div>
6836 <div class="dlist">
6837 <dl>
6838 <dt class="hdlist1"><code>"metrics"</code></dt>
6839 <dd>
6840 <p>An array of full metric descriptions, as javascript objects. The
6841 specifics of these, and how to determine which ones to use, can
6842 unfortunately only be found in the low-level protocol documentation.
6843 This option is required.</p>
6844 </dd>
6845 <dt class="hdlist1"><code>"source"</code></dt>
6846 <dd>
6847 <p>The source to use for real-time data. This is used by the <code>follow</code>
6848 method, see below. Set to <code>"internal"</code> to retrieve internal metrics
6849 read by the bridge. If set to <code>"direct"</code> or <code>"pmcd"</code> then data
6850 will be retrieved from <a href="https://pcp.io">PCP</a>if it is available. The
6851 default is <code>"internal"</code>.</p>
6852 </dd>
6853 <dt class="hdlist1"><code>"archive_source"</code></dt>
6854 <dd>
6855 <p>The source to use for retrieving historical data. This is used by the
6856 <code>fetch</code> method, see below. Set to <code>"pcp-archive"</code> to retrieve data
6857 from PCP archives. The default is not to try to retrieve historical
6858 data.</p>
6859 </dd>
6860 </dl>
6861 </div>
6862 <div class="paragraph">
6863 <p>When the <code>options</code> argument is an array of javascript objects, then
6864 the metrics channel tries to use them in order until one succeeds. This
6865 way, you can prefer PCP as the source but fall back to internal metrics
6866 when PCP is not available, for example. The channel gives no indication
6867 which of the options has been used, and <code>fetch</code> and <code>follow</code> might
6868 use different entries from the list.</p>
6869 </div>
6870 </div>
6871 <div class="sect4">
6872 <h5 id="cockpit-metrics-fetch">metrics.fetch()</h5>
6873 <div class="literalblock">
6874 <div class="content">
6875 <pre>metrics.fetch(beg, end)</pre>
6876 </div>
6877 </div>
6878 <div class="paragraph">
6879 <p>Retrieve archived metrics data between <code>beg</code> and <code>end</code>. The
6880 arguments can either be numbers, in which case they are interval based
6881 offsets, or they can be javascript Date objects.</p>
6882 </div>
6883 </div>
6884 <div class="sect4">
6885 <h5 id="cockpit-metrics-follow">metrics.follow()</h5>
6886 <div class="literalblock">
6887 <div class="content">
6888 <pre>metrics.follow()</pre>
6889 </div>
6890 </div>
6891 <div class="paragraph">
6892 <p>Start retrieving live metrics data as it become available.</p>
6893 </div>
6894 </div>
6895 <div class="sect4">
6896 <h5 id="cockpit-metrics-close">metrics.close()</h5>
6897 <div class="literalblock">
6898 <div class="content">
6899 <pre>metrics.close()</pre>
6900 </div>
6901 </div>
6902 <div class="paragraph">
6903 <p>Stop the retrieval of metrics and release resources.</p>
6904 </div>
6905 </div>
6906 <div class="sect4">
6907 <h5 id="cockpit-metrics-series">metrics.series</h5>
6908 <div class="paragraph">
6909 <p>The series sink where data retrieved data will be processed.</p>
6910 </div>
6911 </div>
6912 <div class="sect4">
6913 <h5 id="cockpit-metrics-meta">metrics.meta</h5>
6914 <div class="paragraph">
6915 <p>The metrics meta data last received.</p>
6916 </div>
6917 </div>
6918 <div class="sect4">
6919 <h5 id="cockpit-metrics-onchanged">metrics.onchanged</h5>
6920 <div class="literalblock">
6921 <div class="content">
6922 <pre>metrics.onchanged = function() { }</pre>
6923 </div>
6924 </div>
6925 <div class="paragraph">
6926 <p>An event triggered when one of the properties on this metrics object
6927 changes.</p>
6928 </div>
6929 </div>
6930 </div>
6931 <div class="sect3">
6932 <h4 id="_cockpit_js_series_data">cockpit.js: Series Data</h4>
6933 <div class="paragraph">
6934 <p>Series data consists of values along a continuous (usually time) axis.
6935 We can place these in grids which expose a distinct subset of these
6936 values. These are the underlying mechanism for displaying metrics data
6937 in graphs.</p>
6938 </div>
6939 <div class="sect4">
6940 <h5 id="cockpit-grid">cockpit.grid()</h5>
6941 <div class="literalblock">
6942 <div class="content">
6943 <pre>grid = cockpit.grid(interval, [beg, end])</pre>
6944 </div>
6945 </div>
6946 <div class="paragraph">
6947 <p>Creates a grid object to contain series data.</p>
6948 </div>
6949 <div class="paragraph">
6950 <p>The <code>interval</code> is the granularity of the grid. Usually this is a
6951 number of milliseconds, when used with time series data. The <code>beg</code> and
6952 <code>end</code> are the bounds of the grid. If omitted they will be set to zero
6953 for an initially empty grid.</p>
6954 </div>
6955 <div class="paragraph">
6956 <p>If <code>beg</code> and/or <code>end</code> are negative (including negative zero) then
6957 they are interpreted in number of intervals relative to the current
6958 time. Thus cockpit.grid(1000, -300, -0) will create a grid for the most
6959 recent 5 minutes.</p>
6960 </div>
6961 </div>
6962 <div class="sect4">
6963 <h5 id="cockpit-grid-add">grid.add()</h5>
6964 <div class="literalblock">
6965 <div class="content">
6966 <pre>row = grid.add(series, path)
6967 row = grid.add(callback, [early])
6968 row = grid.add()</pre>
6969 </div>
6970 </div>
6971 <div class="paragraph">
6972 <p>Adds a row to the grid. The returned <code>row</code> is a Javascript array that
6973 will contain series data. The arguments control how the row is populated
6974 from the series data. The <code>row</code> is a sparse array. Its <code>row.length</code>
6975 will not match the expected size of the grid, unless and until the row
6976 has been completely filled in. The first index of the <code>row</code> will
6977 contain the data from the series data at the
6978 <a href="#cockpit-grid-beg"><code>grid.beg</code></a> offset.</p>
6979 </div>
6980 <div class="paragraph">
6981 <p>When no arguments are passed, an empty row is added, and it is not
6982 populated with data.</p>
6983 </div>
6984 <div class="paragraph">
6985 <p>When called with a <code>series</code> and <code>path</code> argument then the row will be
6986 populated directly with series data. The <code>series</code> can either be a
6987 <a href="#cockpit-series">series object</a> or an object that has an
6988 <code>obj.series</code> property. The <a href="#cockpit-series-interval">series
6989 interval</a> must match the interval of this grid. If <code>path</code> is missing
6990 or empty, then the series data is placed into the row directly.
6991 Otherwise <code>path</code> indicates which part of the series data to place in
6992 the row. When <code>path</code> is an array, it is used as a set of property
6993 names or array indexes to follow into nested series data. When <code>path</code>
6994 is a dotted string, it is split and used the same way to locate the
6995 correct value in nested series data. The exact format of the series data
6996 depends on its producer, and relevant paths will be documented there.</p>
6997 </div>
6998 <div class="paragraph">
6999 <p>If a <code>callback</code> function is specified, then it will be invoked to
7000 provide series data for the row. The function is invoked as
7001 <code>callback(row, index, count)</code>, where the <code>row</code> is the row to fill
7002 in, the <code>index</code> is the index to start filling in and <code>count</code> is the
7003 number of items to fill in. The <code>this</code> variable will be set to the
7004 grid while invoking the <code>callback</code>. The callback is called after other
7005 data rows for a given series have been filled in. Callbacks are called
7006 in the order added, unless the <code>early</code> argument is set to <code>true</code>, in
7007 which case the callback is called earlier than callbacks without the
7008 <code>early</code> argument set.</p>
7009 </div>
7010 <div class="paragraph">
7011 <p>To remove the row use the <a href="#cockpit-grid-remove"><code>grid.remove()</code>
7012 method.</a></p>
7013 </div>
7014 <div class="paragraph">
7015 <p>The row will start being populated with data when the <code>series</code>
7016 produces data. To make this happen right away, use the
7017 <a href="#cockpit-grid-sync"><code>grid.sync()</code></a> method.</p>
7018 </div>
7019 </div>
7020 <div class="sect4">
7021 <h5 id="cockpit-grid-remove">grid.remove()</h5>
7022 <div class="literalblock">
7023 <div class="content">
7024 <pre>grid.remove(row)</pre>
7025 </div>
7026 </div>
7027 <div class="paragraph">
7028 <p>Remove a previously added <code>row</code> from the grid. The row will no longer
7029 be updated with series data.</p>
7030 </div>
7031 </div>
7032 <div class="sect4">
7033 <h5 id="cockpit-grid-sync">grid.sync()</h5>
7034 <div class="literalblock">
7035 <div class="content">
7036 <pre>grid.sync()</pre>
7037 </div>
7038 </div>
7039 <div class="paragraph">
7040 <p>Load or reload data from the series into the rows. This does not clear
7041 the rows before populating them. Some data may be populated immediately,
7042 others may have to wait until data can be loaded. Internally this
7043 function calls <a href="#cockpit-series-load"><code>series.load()</code></a> for each
7044 series.</p>
7045 </div>
7046 <div class="paragraph">
7047 <p>All rows with callbacks will be invoked to regenerate all the data. The
7048 <a href="#cockpit-grid-onnotify"><code>grid.onnotify</code></a> event will be triggered.
7049 It is not necessary to call this function after a call of the
7050 <a href="#cockpit-grid-move"><code>grid.move()</code></a> method.</p>
7051 </div>
7052 </div>
7053 <div class="sect4">
7054 <h5 id="cockpit-grid-move">grid.move()</h5>
7055 <div class="literalblock">
7056 <div class="content">
7057 <pre>grid.move(beg[, end])</pre>
7058 </div>
7059 </div>
7060 <div class="paragraph">
7061 <p>Move the grid to new <code>beg</code> and <code>end</code> range. Data will be discarded
7062 from the rows and <a href="#cockpit-grid-sync"><code>grid.sync()</code></a> will be
7063 called to load or reload series data for the new range of offsets.</p>
7064 </div>
7065 <div class="paragraph">
7066 <p>If <code>end</code> is not specified it will be set to <code>beg</code>. If <code>beg</code> and/or
7067 <code>end</code> are negative (including negative zero) then they will be set to
7068 the number of intervals prior to the current time taken as an interval.</p>
7069 </div>
7070 <div class="paragraph">
7071 <p>If <code>beg</code> and/or <code>end</code> are negative (including negative zero) then
7072 they are interpreted in number of intervals relative to the current
7073 time. Thus cockpit.grid(1000, -300, -0) will create a grid for the most
7074 recent 5 minutes.</p>
7075 </div>
7076 </div>
7077 <div class="sect4">
7078 <h5 id="cockpit-grid-walk">grid.walk()</h5>
7079 <div class="literalblock">
7080 <div class="content">
7081 <pre>grid.walk()</pre>
7082 </div>
7083 </div>
7084 <div class="paragraph">
7085 <p>Move the grid forward every
7086 <a href="#cockpit-grid-interval"><code>grid.interval</code></a> milliseconds. To stop
7087 moving forward, call <a href="#cockpit-grid-move"><code>grid.move()</code></a>.</p>
7088 </div>
7089 </div>
7090 <div class="sect4">
7091 <h5 id="cockpit-grid-notify">grid.notify()</h5>
7092 <div class="literalblock">
7093 <div class="content">
7094 <pre>grid.notify(index, count)</pre>
7095 </div>
7096 </div>
7097 <div class="paragraph">
7098 <p>This function is called to have rows with callbacks recalculate their
7099 data. It is not normally necessary to call this function, as it will be
7100 invoked automatically when new series data is available or has been
7101 loaded. This function triggers the
7102 <a href="#cockpit-grid-onnotify"><code>grid.onnotify</code></a> event.</p>
7103 </div>
7104 </div>
7105 <div class="sect4">
7106 <h5 id="cockpit-grid-onnotify">grid.onnotify</h5>
7107 <div class="literalblock">
7108 <div class="content">
7109 <pre>grid.addEventListener("notify", function(index, count) { ... });</pre>
7110 </div>
7111 </div>
7112 <div class="paragraph">
7113 <p>An event that is triggered when some part of the series data in grid
7114 changes. The <code>index</code> is the row index where things changed, and the
7115 <code>count</code> is the length of the data that changed.</p>
7116 </div>
7117 </div>
7118 <div class="sect4">
7119 <h5 id="cockpit-grid-close">grid.close()</h5>
7120 <div class="literalblock">
7121 <div class="content">
7122 <pre>grid.close()</pre>
7123 </div>
7124 </div>
7125 <div class="paragraph">
7126 <p>Close the grid, and stop updating the rows.</p>
7127 </div>
7128 </div>
7129 <div class="sect4">
7130 <h5 id="cockpit-grid-interval">grid.interval</h5>
7131 <div class="paragraph">
7132 <p>The granularity of the grid. For time series data this is an interval in
7133 milliseconds. In order to use a given <a href="#cockpit-grid">grid</a> and
7134 <a href="#cockpit-series">series</a> together, their interval properties must
7135 match.</p>
7136 </div>
7137 </div>
7138 <div class="sect4">
7139 <h5 id="cockpit-grid-beg">grid.beg</h5>
7140 <div class="paragraph">
7141 <p>The beginning offset of the series data in the grid. Do not set this
7142 property directly. Use the <a href="#cockpit-grid-move">grid.move()</a> method
7143 instead.</p>
7144 </div>
7145 </div>
7146 <div class="sect4">
7147 <h5 id="cockpit-grid-end">grid.end</h5>
7148 <div class="paragraph">
7149 <p>The ending offset of the series data in the grid. Do not set this
7150 property directly. Use the <a href="#cockpit-grid-move">grid.move()</a> method
7151 instead.</p>
7152 </div>
7153 </div>
7154 <div class="sect4">
7155 <h5 id="cockpit-series">cockpit.series()</h5>
7156 <div class="literalblock">
7157 <div class="content">
7158 <pre>series = cockpit.series(interval, [cache, fetch])</pre>
7159 </div>
7160 </div>
7161 <div class="paragraph">
7162 <p>Create a new sink of series data. This is usually done by producers of
7163 series data, and it is rare to invoke this function directly.</p>
7164 </div>
7165 <div class="paragraph">
7166 <p>The <code>interval</code> is the granularity of the series data. For time series
7167 data this is an interval in milliseconds. If a <code>cache</code> string is
7168 specified, series data will be cached across frames for series with the
7169 same <code>cache</code> cache identifier to load and/or reload.</p>
7170 </div>
7171 <div class="paragraph">
7172 <p>If a <code>fetch</code> callback is specified, then it will be invoked when grids
7173 request certain ranges of data. The <code>fetch</code> callback is invoked with
7174 <code>function fetch(beg, end) { ... }</code> range offsets. The
7175 <a href="#cockpit-series-input">series.input()</a> should be called with data
7176 retrieved, either immediately or at a later time. The callback may be
7177 called multiple times for the same ranges of data. It is up to the
7178 callback to determine when or whether it should retrieve the data more
7179 than once.</p>
7180 </div>
7181 <div class="paragraph">
7182 <p>A producer of series data, usually calls this function and creates
7183 itself a <code>obj.series</code> property containing this series object.</p>
7184 </div>
7185 </div>
7186 <div class="sect4">
7187 <h5 id="cockpit-series-input">series.input()</h5>
7188 <div class="literalblock">
7189 <div class="content">
7190 <pre>series.input(beg, items[, mapping])</pre>
7191 </div>
7192 </div>
7193 <div class="paragraph">
7194 <p>Send series data into the series sink. Any grids that have added rows
7195 based on this series, will have data filled in. The <code>beg</code> is the
7196 beginning offset of <code>items</code>. The <code>items</code> are an array one or more
7197 series data items.</p>
7198 </div>
7199 <div class="paragraph">
7200 <p>Producers may wish to provide additional properties that can be used in
7201 lookup paths that rows can pull from. This is done in the <code>mapping</code>
7202 argument. If specified it is a tree of objects. Each sub object should
7203 have a property with the name <code>""</code> empty string, which will be used as
7204 the property name or index in place of the one used in the lookup path.</p>
7205 </div>
7206 </div>
7207 <div class="sect4">
7208 <h5 id="cockpit-series-load">series.load()</h5>
7209 <div class="literalblock">
7210 <div class="content">
7211 <pre>series.load(beg, end)</pre>
7212 </div>
7213 </div>
7214 <div class="paragraph">
7215 <p>Load data from the series into any grids that have rows based on this
7216 series data. Any cached data will be filled in immediately. Any data not
7217 cached, will be requested from the producer, if possible, and may arrive
7218 at a later time.</p>
7219 </div>
7220 <div class="paragraph">
7221 <p>The <code>beg</code> and <code>end</code> denote the range of data to load.</p>
7222 </div>
7223 </div>
7224 <div class="sect4">
7225 <h5 id="cockpit-series-interval">series.interval</h5>
7226 <div class="paragraph">
7227 <p>The granularity of the series. For time series data this is an interval
7228 in milliseconds. In order to use a given <a href="#cockpit-grid">grid</a> and
7229 <a href="#cockpit-series">series</a> together, their interval properties must
7230 match.</p>
7231 </div>
7232 </div>
7233 <div class="sect4">
7234 <h5 id="cockpit-series-limit">series.limit</h5>
7235 <div class="paragraph">
7236 <p>The maximum number of items to cache for loading and/or reloading. You
7237 can change this value to a different number. Having a number close to
7238 zero will break certain usage of grids, such as
7239 <a href="#cockpit-grid-walk"><code>grid.walk()</code></a>.</p>
7240 </div>
7241 </div>
7242 </div>
7243 <div class="sect3">
7244 <h4 id="_cockpit_js_spawning_processes">cockpit.js: Spawning Processes</h4>
7245 <div class="paragraph">
7246 <p>This is the API for spawning a process and receiving its output, as well
7247 as exit codes.</p>
7248 </div>
7249 <div class="sect4">
7250 <h5 id="cockpit-spawn-spawn">cockpit.spawn()</h5>
7251 <div class="literalblock">
7252 <div class="content">
7253 <pre>process = cockpit.spawn(args, [options])</pre>
7254 </div>
7255 </div>
7256 <div class="paragraph">
7257 <p>Spawns a process on the system.</p>
7258 </div>
7259 <div class="paragraph">
7260 <p>The <code>args</code> should be an array starting with the executable and
7261 containing all the arguments to pass on the command line. If <code>args</code> is
7262 a string then it is interpreted as an executable name. The optional
7263 <code>options</code> argument is a javascript plain object and can contain any of
7264 the following fields:</p>
7265 </div>
7266 <div class="dlist">
7267 <dl>
7268 <dt class="hdlist1"><code>"binary"</code></dt>
7269 <dd>
7270 <p>If set to <code>true</code> then handle the input and output of the process as
7271 arrays of binary bytes.</p>
7272 </dd>
7273 <dt class="hdlist1"><code>"directory"</code></dt>
7274 <dd>
7275 <p>The directory to spawn the process in.</p>
7276 </dd>
7277 <dt class="hdlist1"><code>"err"</code></dt>
7278 <dd>
7279 <p>Controls where the standard error is sent. By default it is logged to
7280 the journal. If set to <code>"out"</code> it is included in with the output
7281 data. If set to <code>"ignore"</code> then the error output is discarded. If
7282 set to <code>"message"</code>, then it will be returned as the error message.
7283 When the <code>"pty"</code> field is set, this field has no effect.</p>
7284 </dd>
7285 <dt class="hdlist1"><code>"environ"</code></dt>
7286 <dd>
7287 <p>An optional array that contains strings to be used as additional
7288 environment variables for the new process. These are <code>"NAME=VALUE"</code>
7289 strings.</p>
7290 </dd>
7291 <dt class="hdlist1"><code>"pty"</code></dt>
7292 <dd>
7293 <p>Launch the process in its own PTY terminal, and send/receive terminal
7294 input and output.</p>
7295 </dd>
7296 <dt class="hdlist1"><code>"batch"</code></dt>
7297 <dd>
7298 <p>Batch data coming from the process in blocks of at least this size.
7299 This is not a guarantee. After a short timeout the data will be sent
7300 even if the data doesn&#8217;t match the batch size. Defaults to zero.</p>
7301 </dd>
7302 <dt class="hdlist1"><code>"latency"</code></dt>
7303 <dd>
7304 <p>The timeout for flushing any cached data in milliseconds.</p>
7305 </dd>
7306 <dt class="hdlist1"><code>"superuser"</code></dt>
7307 <dd>
7308 <p>Set to <code>"require"</code> to spawn the process as root instead of the
7309 logged in user. If the currently logged in user is not permitted to
7310 become root (eg: via <code>pkexec</code>) then the <code>client</code> will immediately
7311 be <a href="cockpit-dbus.html#cockpit-dbus-onclose">closed</a> with a <code>"access-denied"</code>
7312 problem code.
7313 +
7314 Set to <code>"try"</code> to try to run the process as root, but if that fails,
7315 fall back to an unprivileged process.</p>
7316 </dd>
7317 </dl>
7318 </div>
7319 <div class="paragraph">
7320 <p>The spawned process is a
7321 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a>
7322 that will complete if the process exits successfully, or fail if there&#8217;s
7323 a problem. Some additional methods besides the standard promise methods
7324 are documented below.</p>
7325 </div>
7326 <div class="paragraph">
7327 <p>The standard output of the process is made available via the spawned
7328 process object. Any non-UTF8 output from the process will be coerced
7329 into textual form. It is highly recommended that only textual output be
7330 produced by the command. The standard error is logged to the journal.</p>
7331 </div>
7332 </div>
7333 <div class="sect4">
7334 <h5 id="cockpit-spawn-script">cockpit.script()</h5>
7335 <div class="literalblock">
7336 <div class="content">
7337 <pre>process = cockpit.script(script, [args], [options])</pre>
7338 </div>
7339 </div>
7340 <div class="paragraph">
7341 <p>Run a shell script on the system.</p>
7342 </div>
7343 <div class="paragraph">
7344 <p>This function <a href="#cockpit-spawn-spawn">spawns</a> a Bourne shell script
7345 process. The full text of the <code>/bin/sh</code> shell script should be passed
7346 in as the first argument. The <code>args</code> can be an array of arguments, not
7347 including the executable, which are passed to the script as <code>$1</code>,
7348 <code>$2</code> and so on. Shebang options are not used or respected.</p>
7349 </div>
7350 <div class="paragraph">
7351 <p>The <code>options</code> is an optional javascript plain object and can include
7352 any of the fields listed for the
7353 <a href="#cockpit-spawn-spawn"><code>cockpit.spawn()</code></a> function.</p>
7354 </div>
7355 <div class="paragraph">
7356 <p>The spawned process is a
7357 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a>
7358 that will complete if the script exits successfully, or fail if there&#8217;s
7359 a problem. Some additional methods besides the standard promise methods
7360 are documented below.</p>
7361 </div>
7362 <div class="paragraph">
7363 <p>The standard output of the process is made available via the spawned
7364 process object. Any non-UTF8 output from the process will be coerced
7365 into textual form. It is highly recommended that only textual output be
7366 produced by the command. The standard error is logged to the journal by
7367 default.</p>
7368 </div>
7369 </div>
7370 <div class="sect4">
7371 <h5 id="cockpit-spawn-then">process.then()</h5>
7372 <div class="literalblock">
7373 <div class="content">
7374 <pre>process.then((data[, message]) =&gt; { ... })</pre>
7375 </div>
7376 </div>
7377 <div class="paragraph">
7378 <p>This is a standard
7379 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a>
7380 method. It sets up a handler to be called when the process finishes
7381 successfully.</p>
7382 </div>
7383 <div class="paragraph">
7384 <p>The <code>data</code> argument contains the standard output of the process. If it
7385 a string, unless the process was opened in binary mode, in which case
7386 the <code>data</code> is an array of bytes. If a <code>process.stream()</code> handler is
7387 set up, then any standard output data consumed by the handler will not
7388 be included in the <code>data</code> argument.</p>
7389 </div>
7390 <div class="paragraph">
7391 <p>If the process was spawned with the <code>"err"</code> option set to
7392 <code>"message"</code> then the second argument will contain the standard error
7393 output of the process.</p>
7394 </div>
7395 </div>
7396 <div class="sect4">
7397 <h5 id="cockpit-spawn-catch">process.catch()</h5>
7398 <div class="literalblock">
7399 <div class="content">
7400 <pre>process.catch((exception[, data]) =&gt; { ... })</pre>
7401 </div>
7402 </div>
7403 <div class="paragraph">
7404 <p>This is a standard
7405 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>
7406 method. It sets up a handler to be called when the process fails,
7407 terminates or exits.</p>
7408 </div>
7409 <div class="paragraph">
7410 <p>The <code>exception</code> object passed to the handler can have the following
7411 fields:</p>
7412 </div>
7413 <div class="dlist">
7414 <dl>
7415 <dt class="hdlist1"><code>message</code></dt>
7416 <dd>
7417 <p>A message describing the exception. If the process was spawned with
7418 the <code>"err"</code> option set to <code>"message"</code> then the second argument
7419 will contain the standard error output of the process.</p>
7420 </dd>
7421 <dt class="hdlist1"><code>problem</code></dt>
7422 <dd>
7423 <p>A <a href="cockpit-error.html#cockpit-problems">problem code</a> string when a problem occurred
7424 starting or communicating with the process. This is <code>null</code> if the
7425 process exited or was terminated.</p>
7426 </dd>
7427 <dt class="hdlist1"><code>exit_status</code></dt>
7428 <dd>
7429 <p>The numeric exit status of the process. This is <code>null</code> if the
7430 process did not exit.</p>
7431 </dd>
7432 <dt class="hdlist1"><code>exit_signal</code></dt>
7433 <dd>
7434 <p>A string representing a unix signal that caused the process to
7435 terminate. This is <code>null</code> if the process did not terminate because
7436 of a signal.</p>
7437 </dd>
7438 </dl>
7439 </div>
7440 <div class="paragraph">
7441 <p>If the process actually ran and produced output before failing, it will
7442 be available in the <code>data</code> argument. Otherwise this argument will be
7443 <code>undefined</code>.</p>
7444 </div>
7445 </div>
7446 <div class="sect4">
7447 <h5 id="cockpit-spawn-stream">process.stream()</h5>
7448 <div class="literalblock">
7449 <div class="content">
7450 <pre>process.stream(data =&gt; { ... })</pre>
7451 </div>
7452 </div>
7453 <div class="paragraph">
7454 <p>This sets up a handler to be called when the process has standard
7455 output. The handler will be called multiple times. The handler will be
7456 called regardless of whether the process ends up exiting successfully or
7457 not.</p>
7458 </div>
7459 <div class="paragraph">
7460 <p>Only one handler may be registered at a time. Registering an additional
7461 handler replaces the previous one. The handler receives either string
7462 <code>data</code> or an array of binary bytes as its argument. A stream handler
7463 may return a number, which indicates the number of characters or bytes
7464 consumed from <code>data</code>. Any data not consumed will be included again the
7465 next time the handler is called.</p>
7466 </div>
7467 <div class="paragraph">
7468 <p>If a <code>process.stream()</code> handler is set up, then the <code>process.then()</code>
7469 handlers will only get any remaining data not consumed by the stream
7470 handler.</p>
7471 </div>
7472 </div>
7473 <div class="sect4">
7474 <h5 id="cockpit-spawn-input">process.input()</h5>
7475 <div class="literalblock">
7476 <div class="content">
7477 <pre>process.input(data, [stream])</pre>
7478 </div>
7479 </div>
7480 <div class="paragraph">
7481 <p>This method writes <code>data</code> to the standard input of the process. If
7482 <code>data</code> is <code>null</code> or <code>undefined</code> it is not sent. The <code>data</code>
7483 should be a string or an array of bytes if the process was opened in
7484 binary mode.</p>
7485 </div>
7486 <div class="paragraph">
7487 <p>If <code>stream</code> is set to <code>true</code> then this function may be called again
7488 with further input. Otherwise the standard input of the process is
7489 closed.</p>
7490 </div>
7491 </div>
7492 <div class="sect4">
7493 <h5 id="cockpit-spawn-close">process.close()</h5>
7494 <div class="literalblock">
7495 <div class="content">
7496 <pre>process.close([problem])</pre>
7497 </div>
7498 </div>
7499 <div class="paragraph">
7500 <p>Close the process by closing its standard input and output. If
7501 <code>problem</code> is specified it should be a standard
7502 <a href="cockpit-error.html#cockpit-problems">problem code</a> string. In this case the process
7503 will be terminated with a signal.</p>
7504 </div>
7505 </div>
7506 </div>
7507 <div class="sect3">
7508 <h4 id="_cockpit_js_utilities">cockpit.js: Utilities</h4>
7509 <div class="paragraph">
7510 <p>Various utility functions</p>
7511 </div>
7512 <div class="sect4">
7513 <h5 id="cockpit-format">cockpit.format()</h5>
7514 <div class="literalblock">
7515 <div class="content">
7516 <pre>string = cockpit.format(template, args)
7517 string = cockpit.format(template, [arg, ...])</pre>
7518 </div>
7519 </div>
7520 <div class="paragraph">
7521 <p>Format a string interpolating <code>args</code> into <code>template</code> using shell
7522 like syntax. The <code>args</code> may be either an array or javascript object.
7523 The <code>template</code> can contain fields that look like <code>$name</code> or
7524 <code>${name}</code> or <code>$0</code>. Numeric fields are used with array <code>args</code> and
7525 start at zero.</p>
7526 </div>
7527 <div class="paragraph">
7528 <p>In the second form, multiple <code>arg</code> arguments may be passed directly,
7529 and interpolated as as numeric fields in the <code>template</code>.</p>
7530 </div>
7531 <div class="paragraph">
7532 <p>All falsy arguments except the numbers <code>0</code> and `0.0`are replaced by
7533 an empty string.</p>
7534 </div>
7535 </div>
7536 <div class="sect4">
7537 <h5 id="cockpit-format-number">cockpit.format_number()</h5>
7538 <div class="literalblock">
7539 <div class="content">
7540 <pre>string = cockpit.format_number(number, [precision])</pre>
7541 </div>
7542 </div>
7543 <div class="paragraph">
7544 <p>Formats <code>number</code> into a displayable <code>string</code>. If the number is not
7545 an integer, it is rounded to the given number of decimal places,
7546 defaulting to 3. If the number is near zero, but not quite zero it is
7547 rounded to the smallest non-zero value of the given precision; i.e.
7548 ±0.001 for default precision 3.</p>
7549 </div>
7550 <div class="paragraph">
7551 <p>If <code>number</code> is <code>null</code> or <code>undefined</code> an empty string will be
7552 returned.</p>
7553 </div>
7554 </div>
7555 <div class="sect4">
7556 <h5 id="cockpit-format-bytes">cockpit.format_bytes()</h5>
7557 <div class="literalblock">
7558 <div class="content">
7559 <pre>string = cockpit.format_bytes(number, [options])</pre>
7560 </div>
7561 </div>
7562 <div class="paragraph">
7563 <p>Formats <code>number</code> into a displayable <code>string</code> with a suffix, such as
7564 <em>kB</em> or <em>MB</em>.</p>
7565 </div>
7566 <div class="paragraph">
7567 <p>By default, SI units are used. IEC units (1024-based) can be requested
7568 by including <code>base2: true</code> in <code>options</code>.</p>
7569 </div>
7570 <div class="paragraph">
7571 <p>By default, non-integer numbers will be formatted with 3 digits of
7572 precision. This can be changed with <code>options.precision</code>.</p>
7573 </div>
7574 <div class="paragraph">
7575 <p>If <code>number</code> is <code>null</code> or <code>undefined</code> an empty string will be
7576 returned.</p>
7577 </div>
7578 </div>
7579 <div class="sect4">
7580 <h5 id="cockpit-format-bytes-per-sec">cockpit.format_bytes_per_sec()</h5>
7581 <div class="literalblock">
7582 <div class="content">
7583 <pre>string = cockpit.format_bytes_per_sec(number, [options])</pre>
7584 </div>
7585 </div>
7586 <div class="paragraph">
7587 <p>Format <code>number</code> of bytes into a displayable speed <code>string</code>.</p>
7588 </div>
7589 <div class="paragraph">
7590 <p>This function is mostly equivalent to <code>cockpit.format_bytes()</code> but the
7591 returned value contains a unit like <em>kB/s</em> or <em>MB/s</em>.</p>
7592 </div>
7593 </div>
7594 <div class="sect4">
7595 <h5 id="cockpit-format-bits-per-sec">cockpit.format_bits_per_sec()</h5>
7596 <div class="literalblock">
7597 <div class="content">
7598 <pre>string = cockpit.format_bits_per_sec(number, [options])</pre>
7599 </div>
7600 </div>
7601 <div class="paragraph">
7602 <p>Format <code>number</code> of bits into a displayable speed <code>string</code>.</p>
7603 </div>
7604 <div class="paragraph">
7605 <p>This function is mostly equivalent to <code>cockpit.format_bytes()</code> but the
7606 returned value contains a unit like <em>kbps</em> or <em>Mbps</em>.</p>
7607 </div>
7608 <div class="paragraph">
7609 <p>This function does not support IEC units. <code>base2</code> may not be passed as
7610 part of <code>options</code>.</p>
7611 </div>
7612 </div>
7613 <div class="sect4">
7614 <h5 id="cockpit-init">cockpit.init()</h5>
7615 <div class="literalblock">
7616 <div class="content">
7617 <pre>await cockpit.init();
7618
7619 cockpit.init().then(() =&gt; { ... });</pre>
7620 </div>
7621 </div>
7622 <div class="paragraph">
7623 <p>Requests initialization of the Cockpit client library. This will ensure
7624 that the transport is connected and we are ready to create channels. It
7625 also populates the <code>cockpit.info</code> field.</p>
7626 </div>
7627 <div class="paragraph">
7628 <p>This function returns a promise. Initialization isn&#8217;t complete until the
7629 promise has resolved. You can either <code>await</code> it or call <code>.then()</code> on
7630 it.</p>
7631 </div>
7632 </div>
7633 <div class="sect4">
7634 <h5 id="cockpit-info">cockpit.info</h5>
7635 <div class="literalblock">
7636 <div class="content">
7637 <pre>cockpit.info.channels[payload]
7638
7639 cockpit.info.os_release[field]
7640
7641 cockpit.info.user
7642
7643 cockpit.info.ws.version</pre>
7644 </div>
7645 </div>
7646 <div class="paragraph">
7647 <p>This object contains information about Cockpit itself. It is only
7648 available after cockpit.init() has been called and awaited.</p>
7649 </div>
7650 <div class="dlist">
7651 <dl>
7652 <dt class="hdlist1"><code>channels</code></dt>
7653 <dd>
7654 <p>This is a mapping of channel payload types (keys, strings) supported
7655 by the bridge to capabilities advertised by those channels (values,
7656 lists of strings). Channels are listed even if they don&#8217;t advertise
7657 any capabilities, making this useful as a way to determine which
7658 channel types are supported by the bridge.</p>
7659 </dd>
7660 <dt class="hdlist1"><code>os_release</code></dt>
7661 <dd>
7662 <p>This is the data from the <code>/etc/os-release</code> or
7663 <code>/usr/lib/os-release</code> on the system that the bridge is running on.
7664 It is a mapping from the key names to their values. See the
7665 <a href="https://www.freedesktop.org/software/systemd/man/latest/os-release.html">os-release
7666 Specification</a> for information about the available keys.</p>
7667 </dd>
7668 <dt class="hdlist1"><code>user</code></dt>
7669 <dd>
7670 <p>Contains information about the user we&#8217;re logged in as.</p>
7671 <div class="dlist">
7672 <dl>
7673 <dt class="hdlist1"><code>uid</code></dt>
7674 <dd>
7675 <p>This is unix user id as an integer.</p>
7676 </dd>
7677 <dt class="hdlist1"><code>gid</code></dt>
7678 <dd>
7679 <p>This is unix user group id as an integer.</p>
7680 </dd>
7681 <dt class="hdlist1"><code>name</code></dt>
7682 <dd>
7683 <p>This is the unix user name like <code>"root"</code>.</p>
7684 </dd>
7685 <dt class="hdlist1"><code>fullname</code></dt>
7686 <dd>
7687 <p>This is a readable name for the user, from the GECOS field.</p>
7688 </dd>
7689 <dt class="hdlist1"><code>group</code></dt>
7690 <dd>
7691 <p>This is the primary group name of the user.</p>
7692 </dd>
7693 <dt class="hdlist1"><code>groups</code></dt>
7694 <dd>
7695 <p>This is an array of group names to which the user belongs. The first
7696 item in this list is the primary group.</p>
7697 </dd>
7698 <dt class="hdlist1"><code>home</code></dt>
7699 <dd>
7700 <p>This is user&#8217;s home directory.</p>
7701 </dd>
7702 <dt class="hdlist1"><code>shell</code></dt>
7703 <dd>
7704 <p>This is unix user shell.</p>
7705 </dd>
7706 </dl>
7707 </div>
7708 </dd>
7709 <dt class="hdlist1"><code>ws</code></dt>
7710 <dd>
7711 <p>Contains information about the webserver Cockpit is being served with.</p>
7712 <div class="dlist">
7713 <dl>
7714 <dt class="hdlist1"><code>version</code></dt>
7715 <dd>
7716 <p>The version of the webserver.</p>
7717 </dd>
7718 </dl>
7719 </div>
7720 </dd>
7721 </dl>
7722 </div>
7723 </div>
7724 <div class="sect4">
7725 <h5 id="cockpit-event-target">cockpit.event_target</h5>
7726 <div class="literalblock">
7727 <div class="content">
7728 <pre>cockpit.event_target(object, [handlers])</pre>
7729 </div>
7730 </div>
7731 <div class="paragraph">
7732 <p>Adds an
7733 <a href="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget">EventTarget</a>
7734 implementation to the <code>object</code>. Optionally store the handlers in
7735 <code>handlers</code> if its specified.</p>
7736 </div>
7737 </div>
7738 </div>
7739 </div>
7740 <div class="sect2">
7741 <h3 id="_api_shell">API: shell</h3>
7742 <div class="paragraph">
7743 <p>This package contains the shell that loads other components.</p>
7744 </div>
7745 <div class="sect3">
7746 <h4 id="_index_html">index.html</h4>
7747 <div class="literalblock">
7748 <div class="content">
7749 <pre>&lt;iframe src="http://127.0.0.1:9090/cockpit+app/@localhost/shell/index.html"
7750 width="600" height="400"&gt;&lt;/iframe&gt;</pre>
7751 </div>
7752 </div>
7753 <div class="paragraph">
7754 <p>This is a Cockpit component that provides an interface to configure a
7755 single machine. It loads other components on demand to make that happen.</p>
7756 </div>
7757 <div class="dlist">
7758 <dl>
7759 <dt class="hdlist1">Component URL</dt>
7760 <dd>
7761 <p><code>/cockpit+app/@localhost/shell/index.html</code></p>
7762 </dd>
7763 </dl>
7764 </div>
7765 </div>
7766 </div>
7767 <div class="sect2">
7768 <h3 id="_api_system">API: system</h3>
7769 <div class="paragraph">
7770 <p>This package contains general components for basic control of a system.</p>
7771 </div>
7772 <div class="sect3">
7773 <h4 id="_logs_html">logs.html</h4>
7774 <div class="paragraph">
7775 <p>System log component</p>
7776 </div>
7777 <div class="sect4">
7778 <h5 id="api-logs-html-description">Description</h5>
7779 <div class="literalblock">
7780 <div class="content">
7781 <pre>&lt;iframe src="http://127.0.0.1:9090/cockpit+app/@localhost/system/logs.html"
7782 width="600" height="400"&gt;&lt;/iframe&gt;</pre>
7783 </div>
7784 </div>
7785 <div class="paragraph">
7786 <p>This is a Cockpit component that brings up system log viewer, with
7787 filtering capabilities. On systemd based systems this displays the
7788 entries from journal.</p>
7789 </div>
7790 <div class="dlist">
7791 <dl>
7792 <dt class="hdlist1">Component URL</dt>
7793 <dd>
7794 <p><code>/cockpit+app/@localhost/system/logs.html</code></p>
7795 </dd>
7796 <dt class="hdlist1">Filter by priority</dt>
7797 <dd>
7798 <p><code>#?prio=notice</code><br>
7799 <br>
7800 Filters the log to show entries below the specific priority,
7801 inclusive. These
7802 <a href="https://en.wikipedia.org/wiki/Syslog#Severity_levels">priorities are
7803 syslog level keywords</a>. Specifying <code>*</code> as a priority will show all
7804 available entries. The default priority is <code>err</code>.</p>
7805 </dd>
7806 <dt class="hdlist1">Filter by service</dt>
7807 <dd>
7808 <p><code>#?service=sshd.service</code><br>
7809 <br>
7810 Filters the log to show entries related to the specific service. The
7811 format of the service is specific to the logging implementation. For
7812 journald these are systemd service unit names.</p>
7813 </dd>
7814 <dt class="hdlist1">Filter by tag</dt>
7815 <dd>
7816 <p><code>#?tag=kernel</code><br>
7817 <br>
7818 Filters the log to show entries related to the specific syslog
7819 identifier.</p>
7820 </dd>
7821 <dt class="hdlist1">Filter by message</dt>
7822 <dd>
7823 <p><code>#?grep=</code><br>
7824 <br>
7825 Filters the log to show entries where the <code>MESSAGE=</code> field matches
7826 the specified regular expression. PERL-compatible regular expressions
7827 are used. If the pattern is all lowercase, matching is case
7828 insensitive. Otherwise, matching is case sensitive.</p>
7829 </dd>
7830 <dt class="hdlist1">Filter by any field</dt>
7831 <dd>
7832 <p><code>#?FIELD=VALUE</code><br>
7833 <br>
7834 A field is referring to the components of a structured journal entry.
7835 The match must be exact. Value can be comma separated list in which
7836 case they are automatically matched as alternatives.</p>
7837 </dd>
7838 <dt class="hdlist1">Start at point</dt>
7839 <dd>
7840 <p><code>#?start=boot</code><br>
7841 <br>
7842 Filters the log to show entries after the specific point in time.
7843 Valid values are <code>boot</code> (since last boot), <code>last-24h</code> (last 24
7844 hours), <code>last-week</code> (last seven days) and <code>previous-boot</code>
7845 (previous boot).</p>
7846 </dd>
7847 <dt class="hdlist1">Follow the journal</dt>
7848 <dd>
7849 <p><code>#?follow=true</code><br>
7850 <br>
7851 Keep listening on new entries. Valid values are <code>true</code> (follow) and
7852 <code>false</code> (do not follow).</p>
7853 </dd>
7854 <dt class="hdlist1">Show log entry</dt>
7855 <dd>
7856 <p><code>#/6e272d82993c4e0d...</code><br>
7857 <br>
7858 To show a specific log entry, put the log entry cursor in a path after
7859 the hash above. Note that cursors are logging system specific, and
7860 journal cursors are subject to change.</p>
7861 </dd>
7862 </dl>
7863 </div>
7864 </div>
7865 </div>
7866 <div class="sect3">
7867 <h4 id="_terminal_html">terminal.html</h4>
7868 <div class="paragraph">
7869 <p>Server terminal component</p>
7870 </div>
7871 <div class="sect4">
7872 <h5 id="api-terminal-html-description">Description</h5>
7873 <div class="literalblock">
7874 <div class="content">
7875 <pre>&lt;iframe src="http://127.0.0.1:9090/cockpit+app/@localhost/system/terminal.html"
7876 width="600" height="400"&gt;&lt;/iframe&gt;</pre>
7877 </div>
7878 </div>
7879 <div class="paragraph">
7880 <p>This is a Cockpit component that brings up a web-based terminal for the
7881 logged in user.</p>
7882 </div>
7883 <div class="dlist">
7884 <dl>
7885 <dt class="hdlist1">Component URL</dt>
7886 <dd>
7887 <p><code>/cockpit+app/@localhost/system/terminal.html</code></p>
7888 </dd>
7889 </dl>
7890 </div>
7891 </div>
7892 </div>
7893 </div>
7894 </div>
7895 </div>
7896 </div>
7897 <div id="footer">
7898 <div id="footer-text">
7899 Last updated 2026-09-23 13:50:34 UTC
7900 </div>
7901 </div>
7902 </body>
7903 </html>