| 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 367.</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’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>AllowUnencrypted</strong></dt> |
| 784 | <dd> |
| 785 | <p>If true, cockpit will accept unencrypted HTTP connections. Otherwise, |
| 786 | it redirects all HTTP connections to HTTPS. Exceptions are connections |
| 787 | from localhost and for certain URLs (like <strong>/ping</strong>). Defaults to |
| 788 | false.</p> |
| 789 | </dd> |
| 790 | <dt class="hdlist1"><strong>UrlRoot</strong></dt> |
| 791 | <dd> |
| 792 | <p>The root URL where you will be serving cockpit. When provided cockpit |
| 793 | will expect all requests to be prefixed with the given url. This is |
| 794 | mostly useful when you are using cockpit behind a reverse proxy, such |
| 795 | as nginx. <code>/cockpit/</code> and <code>/cockpit+</code> are reserved and should not |
| 796 | be used. For example <code>/cockpit-new/</code> is ok. <code>/cockpit/</code> and |
| 797 | <code>/cockpit+new/</code> are not.</p> |
| 798 | </dd> |
| 799 | <dt class="hdlist1"><strong>ClientCertAuthentication</strong></dt> |
| 800 | <dd> |
| 801 | <p>If true, enable TLS client certificates for authenticating users. |
| 802 | Commonly these are provided by a smart card, but it’s equally possible |
| 803 | to import certificates directly into the web browser. Please see the |
| 804 | <a href="https://docs.cockpit-project.org/cockpit-guide/latest/guide/cert-authentication.html">Certificate/smart |
| 805 | card authentication</a> section in the Cockpit guide for details.</p> |
| 806 | </dd> |
| 807 | <dt class="hdlist1"><strong>Shell</strong></dt> |
| 808 | <dd> |
| 809 | <p>The relative URL to top level component to display in Cockpit once |
| 810 | logged in. Defaults to <code>/shell/index.html</code></p> |
| 811 | </dd> |
| 812 | <dt class="hdlist1"><strong>CustomLoginPage</strong></dt> |
| 813 | <dd> |
| 814 | <p>Load the login page from an alternative directory. The directory must |
| 815 | contain a <code>login.html</code> and optionally a <code>po.js</code> file for translations. |
| 816 | When not set, the hardcoded <code>$prefix/share/cockpit/static</code> directory is used.</p> |
| 817 | </dd> |
| 818 | </dl> |
| 819 | </div> |
| 820 | </div> |
| 821 | <div class="sect4"> |
| 822 | <h5 id="_log">Log</h5> |
| 823 | <div class="dlist"> |
| 824 | <dl> |
| 825 | <dt class="hdlist1"><strong>Fatal</strong></dt> |
| 826 | <dd> |
| 827 | <p>The kind of log messages in the bridge to treat as fatal. Separate |
| 828 | multiple values with spaces. Relevant values are: <strong>criticals</strong> and |
| 829 | <strong>warnings</strong>.</p> |
| 830 | </dd> |
| 831 | </dl> |
| 832 | </div> |
| 833 | </div> |
| 834 | <div class="sect4"> |
| 835 | <h5 id="_oauth">OAuth</h5> |
| 836 | <div class="paragraph"> |
| 837 | <p>Cockpit can be configured to support the |
| 838 | <a href="https://tools.ietf.org/html/rfc6749#section-4.2">implicit grant</a> OAuth |
| 839 | authorization flow. When successful the resulting oauth token will be |
| 840 | passed to cockpit-ws using the <strong>Bearer</strong> auth-scheme. For a login to be |
| 841 | successful, cockpit will also need a to be configured to verify and |
| 842 | allow <strong>Bearer</strong> tokens.</p> |
| 843 | </div> |
| 844 | <div class="dlist"> |
| 845 | <dl> |
| 846 | <dt class="hdlist1"><strong>URL</strong></dt> |
| 847 | <dd> |
| 848 | <p>This is the url that cockpit will redirect the users browser to when |
| 849 | it needs to obtain an oauth token. Cockpit will add a redirect_uri |
| 850 | parameter to the url with the location of where the oauth provider |
| 851 | should redirect to once a token has been obtained.</p> |
| 852 | </dd> |
| 853 | <dt class="hdlist1"><strong>ErrorParam</strong></dt> |
| 854 | <dd> |
| 855 | <p>When a oauth provider redirects a user back to cockpit, look for this |
| 856 | parameter in the querystring or fragment portion of the url to find a |
| 857 | error message. When not provided it will default to |
| 858 | <strong>error_description</strong></p> |
| 859 | </dd> |
| 860 | <dt class="hdlist1"><strong>TokenParam</strong></dt> |
| 861 | <dd> |
| 862 | <p>When a oauth provider redirects a user back to cockpit, look for this |
| 863 | parameter in the querystring or fragment portion of the url to find |
| 864 | the access token. When not provided it will default to |
| 865 | <strong>access_token</strong></p> |
| 866 | </dd> |
| 867 | </dl> |
| 868 | </div> |
| 869 | </div> |
| 870 | <div class="sect4"> |
| 871 | <h5 id="_session">Session</h5> |
| 872 | <div class="dlist"> |
| 873 | <dl> |
| 874 | <dt class="hdlist1"><strong>Banner</strong></dt> |
| 875 | <dd> |
| 876 | <p>The contents of the specified file (commonly <strong>/etc/issue</strong>) are shown |
| 877 | on the login page. By default, no banner is displayed.</p> |
| 878 | </dd> |
| 879 | <dt class="hdlist1"><strong>IdleTimeout</strong></dt> |
| 880 | <dd> |
| 881 | <p>Time in minutes after which session expires and user is logged out if |
| 882 | no user action has been performed in the given time. This idle timeout |
| 883 | only applies to interactive password logins. With non-interactive |
| 884 | authentication methods like Kerberos, OAuth, or certificate login, the |
| 885 | browser cannot forget credentials, and thus automatic logouts are not |
| 886 | useful for protecting credentials of forgotten sessions. Set to <strong>0</strong> |
| 887 | to disable session timeout. |
| 888 | <br></p> |
| 889 | </dd> |
| 890 | </dl> |
| 891 | </div> |
| 892 | <div class="listingblock"> |
| 893 | <div class="content"> |
| 894 | <pre class="highlight"><code class="language-ini" data-lang="ini">[Session] |
| 895 | IdleTimeout=15</code></pre> |
| 896 | </div> |
| 897 | </div> |
| 898 | <div class="dlist"> |
| 899 | <dl> |
| 900 | <dt class="hdlist1"></dt> |
| 901 | <dd> |
| 902 | <p>When not specified, there is no idle timeout by default.</p> |
| 903 | </dd> |
| 904 | <dt class="hdlist1"><strong>WarnBeforeConnecting</strong></dt> |
| 905 | <dd> |
| 906 | <p>Whether to warn before connecting to remote hosts from the Shell. |
| 907 | Defaults to true. |
| 908 | <br></p> |
| 909 | </dd> |
| 910 | </dl> |
| 911 | </div> |
| 912 | <div class="listingblock"> |
| 913 | <div class="content"> |
| 914 | <pre class="highlight"><code class="language-ini" data-lang="ini">[Session] |
| 915 | WarnBeforeConnecting=false</code></pre> |
| 916 | </div> |
| 917 | </div> |
| 918 | </div> |
| 919 | <div class="sect4"> |
| 920 | <h5 id="_bugs_2">Bugs</h5> |
| 921 | <div class="paragraph"> |
| 922 | <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> |
| 923 | </div> |
| 924 | </div> |
| 925 | <div class="sect4"> |
| 926 | <h5 id="_author_2">Author</h5> |
| 927 | <div class="paragraph"> |
| 928 | <p>Cockpit has been written by many |
| 929 | <a href="https://github.com/cockpit-project/cockpit">contributors</a>.</p> |
| 930 | </div> |
| 931 | </div> |
| 932 | <div class="sect4"> |
| 933 | <h5 id="_see_also_2">See also</h5> |
| 934 | <div class="paragraph"> |
| 935 | <p><a href="cockpit-ws.8.html">cockpit-ws</a>(8), <a href="cockpit-tls.8.html">cockpit-tls</a>(8)</p> |
| 936 | </div> |
| 937 | </div> |
| 938 | </div> |
| 939 | <div class="sect3"> |
| 940 | <h4 id="_cockpit_ws8">cockpit-ws(8)</h4> |
| 941 | <div class="sect4"> |
| 942 | <h5 id="_name_3">Name</h5> |
| 943 | <div class="paragraph"> |
| 944 | <p>cockpit-ws - Cockpit web service</p> |
| 945 | </div> |
| 946 | </div> |
| 947 | <div class="sect4"> |
| 948 | <h5 id="_synopsis">Synopsis</h5> |
| 949 | <div class="paragraph"> |
| 950 | <p><strong>cockpit-ws</strong> [<strong>--help</strong>] [<strong>--port</strong> <em>PORT</em>] [<strong>--address</strong> <em>ADDRESS</em>] [<strong>--no-tls</strong>] |
| 951 | [<strong>--for-tls-proxy</strong>] [<strong>--local-ssh</strong>] [<strong>--local-session</strong> <em>BRIDGE</em>]</p> |
| 952 | </div> |
| 953 | </div> |
| 954 | <div class="sect4"> |
| 955 | <h5 id="_description_3">Description</h5> |
| 956 | <div class="paragraph"> |
| 957 | <p>The <strong>cockpit-ws</strong> program is the web service component used for |
| 958 | communication between the browser application and various configuration |
| 959 | tools and services like <a href="cockpit-bridge.1.html">cockpit-bridge</a>(1).</p> |
| 960 | </div> |
| 961 | <div class="paragraph"> |
| 962 | <p>Users or administrators should never need to start this program as it |
| 963 | automatically started by systemd(1) on boot up, through |
| 964 | <a href="cockpit-tls.8.html">cockpit-tls</a>(8).</p> |
| 965 | </div> |
| 966 | </div> |
| 967 | <div class="sect4"> |
| 968 | <h5 id="_transport_security">Transport security</h5> |
| 969 | <div class="paragraph"> |
| 970 | <p><strong>cockpit-ws</strong> is normally run behind the <strong>cockpit-tls</strong> TLS |
| 971 | terminating proxy, and only deals with unencrypted HTTP by itself. But |
| 972 | for backwards compatibility it can also handle TLS connections by itself |
| 973 | when being run directly. For details how to configure certificates, |
| 974 | please refer to the <a href="cockpit-tls.8.html">cockpit-tls</a>(8) documentation.</p> |
| 975 | </div> |
| 976 | </div> |
| 977 | <div class="sect4"> |
| 978 | <h5 id="_timeout">Timeout</h5> |
| 979 | <div class="paragraph"> |
| 980 | <p>When started via systemd(1) then <strong>cockpit-ws</strong> will exit after 90 |
| 981 | seconds if nobody logs in, or after the last user is disconnected.</p> |
| 982 | </div> |
| 983 | </div> |
| 984 | <div class="sect4"> |
| 985 | <h5 id="_options">Options</h5> |
| 986 | <div class="dlist"> |
| 987 | <dl> |
| 988 | <dt class="hdlist1"><strong>--help</strong></dt> |
| 989 | <dd> |
| 990 | <p>Show help options.</p> |
| 991 | </dd> |
| 992 | <dt class="hdlist1"><strong>--port</strong> <em>PORT</em></dt> |
| 993 | <dd> |
| 994 | <p>Serve HTTP requests <em>PORT</em> instead of port <strong>9090</strong>. Usually Cockpit is |
| 995 | started on demand by <strong>systemd</strong> socket activation, and this option |
| 996 | has no effect. Update the <strong>ListenStream</strong> directive |
| 997 | <strong>cockpit.socket</strong> file in the usual <strong>systemd</strong> manner.</p> |
| 998 | </dd> |
| 999 | <dt class="hdlist1"><strong>--address</strong> <em>ADDRESS</em></dt> |
| 1000 | <dd> |
| 1001 | <p>Bind to address <em>ADDRESS</em> instead of binding to all available |
| 1002 | addresses. Usually Cockpit is started on demand by <strong>systemd</strong> socket |
| 1003 | activation, and this option has no effect. In that case, update the |
| 1004 | <strong>ListenStream</strong> directive in the <strong>cockpit.socket</strong> file in the usual |
| 1005 | <strong>systemd</strong> manner.</p> |
| 1006 | </dd> |
| 1007 | <dt class="hdlist1"><strong>--no-tls</strong></dt> |
| 1008 | <dd> |
| 1009 | <p>Disable http to https redirection.</p> |
| 1010 | </dd> |
| 1011 | <dt class="hdlist1"><strong>--for-tls-proxy</strong></dt> |
| 1012 | <dd> |
| 1013 | <p>Tell <strong>cockpit-ws</strong> that it is running behind a local reverse proxy |
| 1014 | that does the TLS termination. Then Cockpit puts https:// URLs into |
| 1015 | the default <strong>Content-Security-Policy</strong>, and accepts only https:// |
| 1016 | origins, instead of http: ones by default. However, if <strong>Origins</strong> is |
| 1017 | set in the <a href="cockpit.conf.5.html">cockpit.conf</a>(5) configuration file, it will override |
| 1018 | this default.</p> |
| 1019 | </dd> |
| 1020 | <dt class="hdlist1"><strong>--local-ssh</strong></dt> |
| 1021 | <dd> |
| 1022 | <p>Normally <strong>cockpit-ws</strong> uses <strong>cockpit-session</strong> and PAM to |
| 1023 | authenticate the user and start a user session. With this option |
| 1024 | enabled, it will instead authenticate via SSH at <strong>127.0.0.1</strong> port |
| 1025 | <strong>22</strong>.</p> |
| 1026 | </dd> |
| 1027 | <dt class="hdlist1"><strong>--local-session</strong> <em>BRIDGE</em></dt> |
| 1028 | <dd> |
| 1029 | <p>Skip all authentication and <strong>cockpit-session</strong>, and launch the |
| 1030 | <strong>cockpit-bridge</strong> specified in <em>BRIDGE</em> in the local session. If the |
| 1031 | <em>BRIDGE</em> is specified as <code>-</code> then expect an already running bridge |
| 1032 | that is connected to stdin and stdout of this <strong>cockpit-ws</strong> process. |
| 1033 | This allows the web server to run as any unprivileged user in an |
| 1034 | already running session.<br> |
| 1035 | <br> |
| 1036 | This mode implies <strong>--no-tls</strong>, thus you need to use http:// URLs with |
| 1037 | this.</p> |
| 1038 | </dd> |
| 1039 | </dl> |
| 1040 | </div> |
| 1041 | <div class="admonitionblock warning"> |
| 1042 | <table> |
| 1043 | <tr> |
| 1044 | <td class="icon"> |
| 1045 | <div class="title">Warning</div> |
| 1046 | </td> |
| 1047 | <td class="content"> |
| 1048 | <div class="paragraph"> |
| 1049 | <p>With <strong>--local-session</strong> <em>BRIDGE</em>, you <em>have to isolate the opened TCP port</em> somehow |
| 1050 | (for example in a network namespace), otherwise all other users (or |
| 1051 | even remote machines if the port is not just listening on localhost) |
| 1052 | can access the session!</p> |
| 1053 | </div> |
| 1054 | </td> |
| 1055 | </tr> |
| 1056 | </table> |
| 1057 | </div> |
| 1058 | </div> |
| 1059 | <div class="sect4"> |
| 1060 | <h5 id="_environment">Environment</h5> |
| 1061 | <div class="paragraph"> |
| 1062 | <p>The <strong>cockpit-ws</strong> process will use the <strong>XDG_CONFIG_DIRS</strong> environment |
| 1063 | variable from the |
| 1064 | <a href="https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG |
| 1065 | basedir spec</a> to find its <a href="cockpit.conf.5.html">cockpit.conf</a>(5) configuration file.</p> |
| 1066 | </div> |
| 1067 | <div class="paragraph"> |
| 1068 | <p>In addition the <strong>XDG_DATA_DIRS</strong> environment variable from the |
| 1069 | <a href="https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG |
| 1070 | basedir spec</a> can be used to override the location to serve static files |
| 1071 | from. These are the files that are served to a non-logged in user.</p> |
| 1072 | </div> |
| 1073 | </div> |
| 1074 | <div class="sect4"> |
| 1075 | <h5 id="_bugs_3">Bugs</h5> |
| 1076 | <div class="paragraph"> |
| 1077 | <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> |
| 1078 | </div> |
| 1079 | </div> |
| 1080 | <div class="sect4"> |
| 1081 | <h5 id="_author_3">Author</h5> |
| 1082 | <div class="paragraph"> |
| 1083 | <p>Cockpit has been written by many |
| 1084 | <a href="https://github.com/cockpit-project/cockpit">contributors</a>.</p> |
| 1085 | </div> |
| 1086 | </div> |
| 1087 | <div class="sect4"> |
| 1088 | <h5 id="_see_also_3">See also</h5> |
| 1089 | <div class="paragraph"> |
| 1090 | <p><a href="cockpit-tls.8.html">cockpit-tls</a>(8) , <a href="cockpit.conf.5.html">cockpit.conf</a>(5) , systemd(1)</p> |
| 1091 | </div> |
| 1092 | </div> |
| 1093 | </div> |
| 1094 | <div class="sect3"> |
| 1095 | <h4 id="_cockpit_tls8">cockpit-tls(8)</h4> |
| 1096 | <div class="sect4"> |
| 1097 | <h5 id="_name_4">Name</h5> |
| 1098 | <div class="paragraph"> |
| 1099 | <p>cockpit-tls - TLS proxy for Cockpit web service</p> |
| 1100 | </div> |
| 1101 | </div> |
| 1102 | <div class="sect4"> |
| 1103 | <h5 id="_synopsis_2">Synopsis</h5> |
| 1104 | <div class="paragraph"> |
| 1105 | <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> |
| 1106 | </div> |
| 1107 | </div> |
| 1108 | <div class="sect4"> |
| 1109 | <h5 id="_description_4">Description</h5> |
| 1110 | <div class="paragraph"> |
| 1111 | <p>The <strong>cockpit-tls</strong> program is a TLS terminating HTTP proxy for |
| 1112 | <a href="cockpit-ws.8.html">cockpit-ws</a>(8). It manages a set of isolated cockpit-ws instances, |
| 1113 | one per TLS client certificate, plus one for TLS without a client |
| 1114 | certificate, and one for unencrypted HTTP. With that, one session cannot |
| 1115 | tamper with another one through possible security vulnerability |
| 1116 | exploits.</p> |
| 1117 | </div> |
| 1118 | <div class="paragraph"> |
| 1119 | <p>Users or administrators should never need to start this program as it |
| 1120 | automatically started by systemd(1) via socket activation.</p> |
| 1121 | </div> |
| 1122 | </div> |
| 1123 | <div class="sect4"> |
| 1124 | <h5 id="_transport_security_2">Transport security</h5> |
| 1125 | <div class="paragraph"> |
| 1126 | <p>To specify the TLS certificate the web service should use, simply drop a |
| 1127 | file with the extension <strong>.cert</strong> in the <strong>/etc/cockpit/ws-certs.d</strong> |
| 1128 | directory, or below <strong>$XDG_CONFIG_DIRS</strong> if set (see |
| 1129 | <a href="cockpit.conf.5.html">cockpit.conf</a>(5)). If there are multiple files |
| 1130 | in this directory, then the highest priority one is chosen after |
| 1131 | sorting.</p> |
| 1132 | </div> |
| 1133 | <div class="paragraph"> |
| 1134 | <p>The <strong>.cert</strong> file should contain at least two OpenSSL style PEM blocks. |
| 1135 | First one or more <code>BEGIN CERTIFICATE</code> blocks for the server |
| 1136 | certificate and intermediate certificate authorities and a second one |
| 1137 | containing a <code>BEGIN PRIVATE KEY</code> or similar. The key must not be |
| 1138 | encrypted.</p> |
| 1139 | </div> |
| 1140 | <div class="paragraph"> |
| 1141 | <p>If there is no TLS certificate, a self-signed certificate is |
| 1142 | automatically generated using <strong>sscg</strong> (if available) or <strong>openssl</strong> and |
| 1143 | stored in the <strong>0-self-signed.cert</strong> file.</p> |
| 1144 | </div> |
| 1145 | <div class="paragraph"> |
| 1146 | <p>When enrolling into a FreeIPA domain, an SSL certificate is requested |
| 1147 | from the IPA server and stored in <strong>10-ipa.cert</strong>.</p> |
| 1148 | </div> |
| 1149 | <div class="paragraph"> |
| 1150 | <p>To check which certificate <strong>cockpit-ws</strong> will use, run the following |
| 1151 | command.</p> |
| 1152 | </div> |
| 1153 | <div class="literalblock"> |
| 1154 | <div class="content"> |
| 1155 | <pre>$ sudo /usr/libexec/cockpit-certificate-ensure --check</pre> |
| 1156 | </div> |
| 1157 | </div> |
| 1158 | <div class="paragraph"> |
| 1159 | <p>Or, on Debian-based systems:</p> |
| 1160 | </div> |
| 1161 | <div class="literalblock"> |
| 1162 | <div class="content"> |
| 1163 | <pre>$ sudo /usr/lib/cockpit/cockpit-certificate-ensure --check</pre> |
| 1164 | </div> |
| 1165 | </div> |
| 1166 | <div class="paragraph"> |
| 1167 | <p>If using <strong>certmonger</strong> to manage certificates, following command can be |
| 1168 | used to generate a certificate/key pair:</p> |
| 1169 | </div> |
| 1170 | <div class="literalblock"> |
| 1171 | <div class="content"> |
| 1172 | <pre>CERT_FILE=/etc/cockpit/ws-certs.d/50-certmonger.crt |
| 1173 | KEY_FILE=/etc/cockpit/ws-certs.d/50-certmonger.key |
| 1174 | |
| 1175 | getcert request -f ${CERT_FILE} -k ${KEY_FILE} -D $(hostname --fqdn)</pre> |
| 1176 | </div> |
| 1177 | </div> |
| 1178 | </div> |
| 1179 | <div class="sect4"> |
| 1180 | <h5 id="_options_2">Options</h5> |
| 1181 | <div class="dlist"> |
| 1182 | <dl> |
| 1183 | <dt class="hdlist1"><strong>--help</strong></dt> |
| 1184 | <dd> |
| 1185 | <p>Show help options.</p> |
| 1186 | </dd> |
| 1187 | <dt class="hdlist1"><strong>--port</strong> <em>PORT</em></dt> |
| 1188 | <dd> |
| 1189 | <p>Serve HTTP requests on <em>PORT</em> instead of port 9090. Usually Cockpit is |
| 1190 | started on demand by <strong>systemd</strong> socket activation, and this option |
| 1191 | has no effect. Update the <strong>ListenStream</strong> directive |
| 1192 | <strong>cockpit.socket</strong> file in the usual <strong>systemd</strong> manner.</p> |
| 1193 | </dd> |
| 1194 | <dt class="hdlist1"><strong>--no-tls</strong></dt> |
| 1195 | <dd> |
| 1196 | <p>Don’t use TLS. Certificates will not be read, and https connections |
| 1197 | denied. Then <strong>cockpit-tls</strong> will only manage a single cockpit-ws |
| 1198 | instance, and thus not do anything different than running |
| 1199 | <strong>cockpit-ws --no-tls</strong> directly. Only use this for debugging or |
| 1200 | testing.</p> |
| 1201 | </dd> |
| 1202 | <dt class="hdlist1"><strong>--idle-timeout</strong> <em>SECONDS</em></dt> |
| 1203 | <dd> |
| 1204 | <p>If greater than 0, exit if no connections have happened for the given |
| 1205 | number of seconds, i. e. the server is idle. If not given, the default |
| 1206 | is 90.</p> |
| 1207 | </dd> |
| 1208 | </dl> |
| 1209 | </div> |
| 1210 | </div> |
| 1211 | <div class="sect4"> |
| 1212 | <h5 id="_environment_2">Environment</h5> |
| 1213 | <div class="paragraph"> |
| 1214 | <p>The <strong>cockpit-tls</strong> program expects the <strong>RUNTIME_DIRECTORY</strong> |
| 1215 | environment variable to be set to an empty directory (preferably in |
| 1216 | <strong>/run/</strong>) that is only accessible by the system user under which it is |
| 1217 | running. This contains the Unix sockets for communicating with the |
| 1218 | <strong>cockpit-ws</strong> instances, and in the future, state information about |
| 1219 | client certificates. This variable is normally set by the |
| 1220 | <strong>cockpit.service</strong> systemd unit.</p> |
| 1221 | </div> |
| 1222 | <div class="paragraph"> |
| 1223 | <p>In addition, <strong>cockpit-tls</strong> will use the <strong>XDG_CONFIG_DIRS</strong> |
| 1224 | environment variable from the |
| 1225 | <a href="https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG |
| 1226 | basedir spec</a> to find its certificates and the <a href="cockpit.conf.5.html">cockpit.conf</a>(5) |
| 1227 | configuration file.</p> |
| 1228 | </div> |
| 1229 | </div> |
| 1230 | <div class="sect4"> |
| 1231 | <h5 id="_bugs_4">Bugs</h5> |
| 1232 | <div class="paragraph"> |
| 1233 | <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> |
| 1234 | </div> |
| 1235 | </div> |
| 1236 | <div class="sect4"> |
| 1237 | <h5 id="_author_4">Author</h5> |
| 1238 | <div class="paragraph"> |
| 1239 | <p>Cockpit has been written by many |
| 1240 | <a href="https://github.com/cockpit-project/cockpit">contributors</a>.</p> |
| 1241 | </div> |
| 1242 | </div> |
| 1243 | <div class="sect4"> |
| 1244 | <h5 id="_see_also_4">See also</h5> |
| 1245 | <div class="paragraph"> |
| 1246 | <p><a href="cockpit-ws.8.html">cockpit-ws</a>(8) , <a href="cockpit.conf.5.html">cockpit.conf</a>(5) , systemd(1)</p> |
| 1247 | </div> |
| 1248 | </div> |
| 1249 | </div> |
| 1250 | <div class="sect3"> |
| 1251 | <h4 id="_cockpit_desktop1">cockpit-desktop(1)</h4> |
| 1252 | <div class="sect4"> |
| 1253 | <h5 id="_name_5">Name</h5> |
| 1254 | <div class="paragraph"> |
| 1255 | <p>cockpit-desktop - Cockpit Desktop integration</p> |
| 1256 | </div> |
| 1257 | </div> |
| 1258 | <div class="sect4"> |
| 1259 | <h5 id="_synopsis_3">Synopsis</h5> |
| 1260 | <div class="paragraph"> |
| 1261 | <p><strong>cockpit-desktop</strong> <em>URLPATH</em> [<em>SSH_HOST</em>]</p> |
| 1262 | </div> |
| 1263 | </div> |
| 1264 | <div class="sect4"> |
| 1265 | <h5 id="_description_5">Description</h5> |
| 1266 | <div class="paragraph"> |
| 1267 | <p>The <strong>cockpit-desktop</strong> program provides secure access to Cockpit pages |
| 1268 | in an already running desktop session. It starts a web server |
| 1269 | (<strong>cockpit-ws</strong>) and a web browser in an isolated network namespace, and |
| 1270 | a <a href="cockpit-bridge.1.html">cockpit-bridge</a>(1) in the running user session.</p> |
| 1271 | </div> |
| 1272 | <div class="paragraph"> |
| 1273 | <p>This avoids having to log into Cockpit, and having to enable |
| 1274 | <strong>cockpit.socket</strong> system-wide. The network isolation ensures that no |
| 1275 | other user, and not even other processes in the user’s session, can |
| 1276 | access this local web server.</p> |
| 1277 | </div> |
| 1278 | <div class="paragraph"> |
| 1279 | <p><strong>URLPATH</strong> is the Cockpit page to open, i. e. the path component of |
| 1280 | Cockpit URLs. It is highly recommended to only open a |
| 1281 | <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 |
| 1282 | path <code>/cockpit/@localhost/storage/index.html</code> will open the Storage |
| 1283 | page. It is also possible to give abbreviated forms of urls, such as |
| 1284 | “/storage” or “/network/firewall”.</p> |
| 1285 | </div> |
| 1286 | <div class="paragraph"> |
| 1287 | <p><em>SSH_HOST</em> is an optional SSH remote host specification (<em>hostname</em> |
| 1288 | or <em>username@hostname</em>). If given, <strong>cockpit-bridge</strong> will be started |
| 1289 | on the remote host through <strong>ssh(1)</strong> instead, i. e. the Cockpit web |
| 1290 | browser will show that remote host. Note that this is more of an |
| 1291 | experimental/demo feature.</p> |
| 1292 | </div> |
| 1293 | </div> |
| 1294 | <div class="sect4"> |
| 1295 | <h5 id="_environment_3">Environment</h5> |
| 1296 | <div class="paragraph"> |
| 1297 | <p>The <strong>BROWSER</strong> environment variable specifies the browser command (and |
| 1298 | possibly options) that will be used to open the requested Cockpit page. |
| 1299 | If not set, <strong>cockpit-desktop</strong> attempts to use an internal minimalistic |
| 1300 | WebKit browser, and failing that, will attempt to detect some reasonable |
| 1301 | alternatives.</p> |
| 1302 | </div> |
| 1303 | </div> |
| 1304 | <div class="sect4"> |
| 1305 | <h5 id="_bugs_5">Bugs</h5> |
| 1306 | <div class="paragraph"> |
| 1307 | <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> |
| 1308 | </div> |
| 1309 | </div> |
| 1310 | <div class="sect4"> |
| 1311 | <h5 id="_author_5">Author</h5> |
| 1312 | <div class="paragraph"> |
| 1313 | <p>Cockpit has been written by many |
| 1314 | <a href="https://github.com/cockpit-project/cockpit">contributors</a>.</p> |
| 1315 | </div> |
| 1316 | </div> |
| 1317 | <div class="sect4"> |
| 1318 | <h5 id="_see_also_5">See also</h5> |
| 1319 | <div class="paragraph"> |
| 1320 | <p><a href="cockpit-ws.8.html">cockpit-ws</a>(8), <a href="cockpit-bridge.1.html">cockpit-bridge</a>(1)</p> |
| 1321 | </div> |
| 1322 | </div> |
| 1323 | </div> |
| 1324 | <div class="sect3"> |
| 1325 | <h4 id="_cockpit_bridge1">cockpit-bridge(1)</h4> |
| 1326 | <div class="sect4"> |
| 1327 | <h5 id="_name_6">Name</h5> |
| 1328 | <div class="paragraph"> |
| 1329 | <p>cockpit-bridge - Cockpit Host Bridge</p> |
| 1330 | </div> |
| 1331 | </div> |
| 1332 | <div class="sect4"> |
| 1333 | <h5 id="_synopsis_4">Synopsis</h5> |
| 1334 | <div class="paragraph"> |
| 1335 | <p><strong>cockpit-bridge</strong> [<strong>--help</strong>] [<strong>--packages</strong>]</p> |
| 1336 | </div> |
| 1337 | </div> |
| 1338 | <div class="sect4"> |
| 1339 | <h5 id="_description_6">Description</h5> |
| 1340 | <div class="paragraph"> |
| 1341 | <p>The <strong>cockpit-bridge</strong> program is used by Cockpit to relay messages and |
| 1342 | commands from the Web front end to the server. Among other things it |
| 1343 | relays DBus, and spawns processes on behalf of the Web user interface.</p> |
| 1344 | </div> |
| 1345 | <div class="paragraph"> |
| 1346 | <p>This program is not routinely run by users or administrators. It is in |
| 1347 | the <strong>$PATH</strong> so that Cockpit can find it when connecting between hosts. |
| 1348 | However there are some diagnostics available when running from the |
| 1349 | command line.</p> |
| 1350 | </div> |
| 1351 | </div> |
| 1352 | <div class="sect4"> |
| 1353 | <h5 id="_options_3">Options</h5> |
| 1354 | <div class="dlist"> |
| 1355 | <dl> |
| 1356 | <dt class="hdlist1"><strong>--help</strong></dt> |
| 1357 | <dd> |
| 1358 | <p>Show help options.</p> |
| 1359 | </dd> |
| 1360 | <dt class="hdlist1"><strong>--interact</strong>=<em>boundary</em></dt> |
| 1361 | <dd> |
| 1362 | <p>Interact with the raw cockpit1 protocol. Useful for debugging and |
| 1363 | testing. Specify a <em>boundary</em> which should be on an empty line |
| 1364 | between messages.</p> |
| 1365 | </dd> |
| 1366 | <dt class="hdlist1"><strong>--packages</strong></dt> |
| 1367 | <dd> |
| 1368 | <p>List all available Cockpit packages and exit. Note this includes |
| 1369 | packages available to the user running this command.</p> |
| 1370 | </dd> |
| 1371 | <dt class="hdlist1"><strong>--version</strong></dt> |
| 1372 | <dd> |
| 1373 | <p>Show Cockpit version information.</p> |
| 1374 | </dd> |
| 1375 | </dl> |
| 1376 | </div> |
| 1377 | </div> |
| 1378 | <div class="sect4"> |
| 1379 | <h5 id="_bugs_6">Bugs</h5> |
| 1380 | <div class="paragraph"> |
| 1381 | <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> |
| 1382 | </div> |
| 1383 | </div> |
| 1384 | <div class="sect4"> |
| 1385 | <h5 id="_author_6">Author</h5> |
| 1386 | <div class="paragraph"> |
| 1387 | <p>Cockpit has been written by many |
| 1388 | <a href="https://github.com/cockpit-project/cockpit">contributors</a>.</p> |
| 1389 | </div> |
| 1390 | </div> |
| 1391 | <div class="sect4"> |
| 1392 | <h5 id="_see_also_6">See also</h5> |
| 1393 | <div class="paragraph"> |
| 1394 | <p><a href="cockpit-ws.8.html">cockpit-ws</a>(8)</p> |
| 1395 | </div> |
| 1396 | </div> |
| 1397 | </div> |
| 1398 | <div class="sect3"> |
| 1399 | <h4 id="_pam_ssh_add8">pam_ssh_add(8)</h4> |
| 1400 | <div class="sect4"> |
| 1401 | <h5 id="_name_7">Name</h5> |
| 1402 | <div class="paragraph"> |
| 1403 | <p>pam_ssh_add - PAM module to auto load ssh keys into an agent</p> |
| 1404 | </div> |
| 1405 | </div> |
| 1406 | <div class="sect4"> |
| 1407 | <h5 id="_description_7">Description</h5> |
| 1408 | <div class="paragraph"> |
| 1409 | <p><strong>pam_ssh_add</strong> provides authentication and session modules that allow users |
| 1410 | to start their session with a running ssh-agent with as many ssh keys |
| 1411 | loaded as possible.</p> |
| 1412 | </div> |
| 1413 | <div class="paragraph"> |
| 1414 | <p>If used, the authentication module simply stores the authentication |
| 1415 | token for later use by the session module. Because this module performs |
| 1416 | no actual authentication it returns PAM_CRED_INSUFFICIENT on success and |
| 1417 | should always be accompanied by an actual authentication module in your |
| 1418 | pam configuration.</p> |
| 1419 | </div> |
| 1420 | <div class="paragraph"> |
| 1421 | <p>By default the session module will start a new ssh-agent and run |
| 1422 | ssh-add, loading any keys that exist in the default path for the newly |
| 1423 | logged in user. If any keys prompt for a password, and a authentication |
| 1424 | token was successfully stored, that token will be provided as the |
| 1425 | password.</p> |
| 1426 | </div> |
| 1427 | </div> |
| 1428 | <div class="sect4"> |
| 1429 | <h5 id="_options_4">Options</h5> |
| 1430 | <div class="dlist"> |
| 1431 | <dl> |
| 1432 | <dt class="hdlist1"><strong>debug</strong></dt> |
| 1433 | <dd> |
| 1434 | <p>This option will turn on debug logging to syslog.</p> |
| 1435 | </dd> |
| 1436 | </dl> |
| 1437 | </div> |
| 1438 | </div> |
| 1439 | <div class="sect4"> |
| 1440 | <h5 id="_examples">Examples</h5> |
| 1441 | <div class="literalblock"> |
| 1442 | <div class="content"> |
| 1443 | <pre> auth required pam_unix.so |
| 1444 | auth optional pam_ssh_add.so |
| 1445 | session optional pam_ssh_add.so</pre> |
| 1446 | </div> |
| 1447 | </div> |
| 1448 | </div> |
| 1449 | <div class="sect4"> |
| 1450 | <h5 id="_bugs_7">Bugs</h5> |
| 1451 | <div class="paragraph"> |
| 1452 | <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> |
| 1453 | </div> |
| 1454 | </div> |
| 1455 | <div class="sect4"> |
| 1456 | <h5 id="_author_7">Author</h5> |
| 1457 | <div class="paragraph"> |
| 1458 | <p>Cockpit has been written by many |
| 1459 | <a href="https://github.com/cockpit-project/cockpit">contributors</a>.</p> |
| 1460 | </div> |
| 1461 | </div> |
| 1462 | </div> |
| 1463 | </div> |
| 1464 | <div class="sect2"> |
| 1465 | <h3 id="https">SSL/TLS Usage</h3> |
| 1466 | <div class="paragraph"> |
| 1467 | <p>Cockpit usually requires that web browsers communicate with it using |
| 1468 | HTTPS, for security reasons.</p> |
| 1469 | </div> |
| 1470 | <div class="sect3"> |
| 1471 | <h4 id="https-required">HTTPS Requirement</h4> |
| 1472 | <div class="paragraph"> |
| 1473 | <p>Cockpit listens for both HTTP and HTTPS connections on the same port, by |
| 1474 | default 9090. If an HTTP connection is made, Cockpit will redirect that |
| 1475 | connection to HTTPS. There are some exceptions:</p> |
| 1476 | </div> |
| 1477 | <div class="ulist"> |
| 1478 | <ul> |
| 1479 | <li> |
| 1480 | <p>If an HTTP connection comes from <code>localhost</code> (<code>127.0.0.1</code> or |
| 1481 | <code>::1</code>, then Cockpit will allow communication without redirecting to |
| 1482 | HTTPS.</p> |
| 1483 | </li> |
| 1484 | <li> |
| 1485 | <p>Certain URLs, like <code>/ping</code> are not required to use HTTPS.</p> |
| 1486 | </li> |
| 1487 | </ul> |
| 1488 | </div> |
| 1489 | <div class="paragraph"> |
| 1490 | <p>This behavior can be overridden by setting the <code>AllowUnencrypted</code> |
| 1491 | option in <code>cockpit.conf</code>.</p> |
| 1492 | </div> |
| 1493 | </div> |
| 1494 | <div class="sect3"> |
| 1495 | <h4 id="https-certificates">Certificates</h4> |
| 1496 | <div class="paragraph"> |
| 1497 | <p>Cockpit will load a certificate from the <code>/etc/cockpit/ws-certs.d</code>, |
| 1498 | directory, or below <code>$XDG_CONFIG_DIRS</code> if set (see |
| 1499 | <a href="./cockpit.conf.5.html">cockpit.conf</a>). It will use the last file |
| 1500 | with a <code>.cert</code> or <code>.crt</code> extension in alphabetical order. The file |
| 1501 | should contain one or more OpenSSL style <code>BEGIN CERTIFICATE</code> blocks |
| 1502 | for the server certificate and the intermediate certificate authorities.</p> |
| 1503 | </div> |
| 1504 | <div class="paragraph"> |
| 1505 | <p>The private key must be contained in a separate file with the same name |
| 1506 | as the certificate, but with a <code>.key</code> suffix instead. The key must not |
| 1507 | be encrypted.</p> |
| 1508 | </div> |
| 1509 | <div class="paragraph"> |
| 1510 | <p>If no certificate is found, a self-signed certificate is created and |
| 1511 | stored in the <code>0-self-signed.cert</code> file. On some platforms, Cockpit |
| 1512 | will also generate a ca.crt in that directory, which may be safely |
| 1513 | imported into client browsers.</p> |
| 1514 | </div> |
| 1515 | <div class="paragraph"> |
| 1516 | <p>Cockpit will read the files as root, so they can have tight permissions.</p> |
| 1517 | </div> |
| 1518 | <div class="paragraph"> |
| 1519 | <p>To check which certificate <code>cockpit-ws</code> will use run the following |
| 1520 | command.</p> |
| 1521 | </div> |
| 1522 | <div class="literalblock"> |
| 1523 | <div class="content"> |
| 1524 | <pre>$ sudo /usr/libexec/cockpit-certificate-ensure --check</pre> |
| 1525 | </div> |
| 1526 | </div> |
| 1527 | <div class="paragraph"> |
| 1528 | <p>Or, on Debian-based systems:</p> |
| 1529 | </div> |
| 1530 | <div class="literalblock"> |
| 1531 | <div class="content"> |
| 1532 | <pre>$ sudo /usr/lib/cockpit/cockpit-certificate-ensure --check</pre> |
| 1533 | </div> |
| 1534 | </div> |
| 1535 | <div class="paragraph"> |
| 1536 | <p>If using <code>certmonger</code> to manage certificates, following command can be |
| 1537 | used to automatically prepare a certificate/key file pair:</p> |
| 1538 | </div> |
| 1539 | <div class="literalblock"> |
| 1540 | <div class="content"> |
| 1541 | <pre>getcert request -f /etc/cockpit/ws-certs.d/50-certmonger.cert \ |
| 1542 | -k /etc/cockpit/ws-certs.d/50-certmonger.key \ |
| 1543 | -D myhostname.example.com \ |
| 1544 | [--ca=...]</pre> |
| 1545 | </div> |
| 1546 | </div> |
| 1547 | <div class="paragraph"> |
| 1548 | <p>This will not work on Red Hat Enterprise Linux 8 by default. Adjust the |
| 1549 | SELinux type of the certificate directory to <code>cert_t</code> to allow |
| 1550 | certmonger to write its certificates there:</p> |
| 1551 | </div> |
| 1552 | <div class="literalblock"> |
| 1553 | <div class="content"> |
| 1554 | <pre>semanage fcontext -a -t cert_t '/etc/cockpit/ws-certs\.d(/.*)?' |
| 1555 | restorecon -v /etc/cockpit/ws-certs.d</pre> |
| 1556 | </div> |
| 1557 | </div> |
| 1558 | </div> |
| 1559 | </div> |
| 1560 | <div class="sect2"> |
| 1561 | <h3 id="listen">TCP Port and Address</h3> |
| 1562 | <div class="paragraph"> |
| 1563 | <p>Cockpit’s <code>cockpit-ws</code> component is configured by default to accept |
| 1564 | connections on port <code>9090</code>. This is the port that is documented for a |
| 1565 | "Web-based System Manager" to listen on. It is also relatively |
| 1566 | memorable.</p> |
| 1567 | </div> |
| 1568 | <div class="paragraph"> |
| 1569 | <p>However there are many reasons you may wish to change the default port. |
| 1570 | For example other software may use port <code>9090</code> or you may wish to |
| 1571 | setup Cockpit to listen on <code>443</code> instead. It is also possible to have |
| 1572 | Cockpit only listen on one specific IP address.</p> |
| 1573 | </div> |
| 1574 | <div class="paragraph"> |
| 1575 | <p>Note that it is only required to have Cockpit listening on a TCP port on |
| 1576 | the server that you access with your web browser. If you add multiple |
| 1577 | servers with host switcher, Cockpit will connect to those servers via |
| 1578 | <code>ssh</code>.</p> |
| 1579 | </div> |
| 1580 | <div class="paragraph"> |
| 1581 | <p>The systems that Cockpit runs on are typically locked down with |
| 1582 | firewalls, SELinux, so changing the default port is not as easy as |
| 1583 | editing a configuration file.</p> |
| 1584 | </div> |
| 1585 | <div class="sect3"> |
| 1586 | <h4 id="listen-systemd">Cockpit systemd Socket</h4> |
| 1587 | <div class="paragraph"> |
| 1588 | <p>On servers with |
| 1589 | <a href="https://www.freedesktop.org/wiki/Software/systemd/"><code>systemd</code></a> Cockpit |
| 1590 | starts on demand via socket activation. To change its port and/or |
| 1591 | address you should place the following content in the |
| 1592 | <code>/etc/systemd/system/cockpit.socket.d/listen.conf</code> file. Create the |
| 1593 | file and directories in that path which not already exist. The |
| 1594 | <code>ListenStream</code> option specifies the desired address and TCP port.</p> |
| 1595 | </div> |
| 1596 | <div class="literalblock"> |
| 1597 | <div class="content"> |
| 1598 | <pre>[Socket] |
| 1599 | ListenStream= |
| 1600 | ListenStream=443</pre> |
| 1601 | </div> |
| 1602 | </div> |
| 1603 | <div class="literalblock"> |
| 1604 | <div class="content"> |
| 1605 | <pre>[Socket] |
| 1606 | ListenStream= |
| 1607 | ListenStream=7777 |
| 1608 | ListenStream=192.168.1.1:443 |
| 1609 | FreeBind=yes</pre> |
| 1610 | </div> |
| 1611 | </div> |
| 1612 | <div class="admonitionblock note"> |
| 1613 | <table> |
| 1614 | <tr> |
| 1615 | <td class="icon"> |
| 1616 | <div class="title">Note</div> |
| 1617 | </td> |
| 1618 | <td class="content"> |
| 1619 | The first line with an empty value is intentional. <code>systemd</code> |
| 1620 | allows multiple <code>Listen</code> directives to be declared in a single socket |
| 1621 | unit; an empty value in a drop-in file resets the list and thus disables |
| 1622 | the default port 9090 from the original unit. |
| 1623 | </td> |
| 1624 | </tr> |
| 1625 | </table> |
| 1626 | </div> |
| 1627 | <div class="paragraph"> |
| 1628 | <p>The <code>FreeBind</code> option is highly recommended when defining specific IP |
| 1629 | addresses. See the |
| 1630 | <a href="https://www.freedesktop.org/software/systemd/man/systemd.socket.html"><code>systemd.socket</code> |
| 1631 | manpage</a> for details.</p> |
| 1632 | </div> |
| 1633 | <div class="paragraph"> |
| 1634 | <p>In order for the changes to take effect, run the following commands:</p> |
| 1635 | </div> |
| 1636 | <div class="literalblock"> |
| 1637 | <div class="content"> |
| 1638 | <pre>$ sudo systemctl daemon-reload |
| 1639 | $ sudo systemctl restart cockpit.socket</pre> |
| 1640 | </div> |
| 1641 | </div> |
| 1642 | </div> |
| 1643 | <div class="sect3"> |
| 1644 | <h4 id="listen-selinux">SELinux Port</h4> |
| 1645 | <div class="paragraph"> |
| 1646 | <p>If <a href="https://selinuxproject.org/page/Main_Page">SELinux</a> is protecting your |
| 1647 | server, then you will need to tell it to allow Cockpit to listen on the |
| 1648 | new port. Run the following command to do so. The last argument |
| 1649 | specifies the desired TCP port.</p> |
| 1650 | </div> |
| 1651 | <div class="literalblock"> |
| 1652 | <div class="content"> |
| 1653 | <pre>$ sudo semanage port -a -t websm_port_t -p tcp 9999</pre> |
| 1654 | </div> |
| 1655 | </div> |
| 1656 | <div class="paragraph"> |
| 1657 | <p>If the port is already defined by some other part of the SELinux policy, |
| 1658 | then you will need to use the <code>-m</code> argument to modify the definition. |
| 1659 | That’s the case with the <code>443</code> SSL port, which is typically defined as |
| 1660 | an <code>http_port_t</code> port.</p> |
| 1661 | </div> |
| 1662 | <div class="literalblock"> |
| 1663 | <div class="content"> |
| 1664 | <pre>$ sudo semanage port -m -t websm_port_t -p tcp 443</pre> |
| 1665 | </div> |
| 1666 | </div> |
| 1667 | <div class="paragraph"> |
| 1668 | <p>The changes should take effect immediately.</p> |
| 1669 | </div> |
| 1670 | </div> |
| 1671 | <div class="sect3"> |
| 1672 | <h4 id="listen-firewalld">Firewalld Port</h4> |
| 1673 | <div class="paragraph"> |
| 1674 | <p>If <a href="https://fedoraproject.org/wiki/FirewallD">Firewalld</a> is configured as |
| 1675 | your firewall, then you will need to tell it to allow Cockpit to receive |
| 1676 | connections on the new port. Run the following commands to do so. The |
| 1677 | last options specify the desired TCP port.</p> |
| 1678 | </div> |
| 1679 | <div class="literalblock"> |
| 1680 | <div class="content"> |
| 1681 | <pre>$ sudo firewall-cmd [--zone=ZONE] --add-port=443/tcp |
| 1682 | $ sudo firewall-cmd --permanent [--zone=ZONE] --add-port=443/tcp</pre> |
| 1683 | </div> |
| 1684 | </div> |
| 1685 | </div> |
| 1686 | </div> |
| 1687 | <div class="sect2"> |
| 1688 | <h3 id="startup">Start up</h3> |
| 1689 | <div class="paragraph"> |
| 1690 | <p>Cockpit’s <code>cockpit-ws</code> component is what the browser connects to and |
| 1691 | it typically starts on demand via |
| 1692 | <a href="https://www.freedesktop.org/wiki/Software/systemd/"><code>systemd</code></a> socket |
| 1693 | activation.</p> |
| 1694 | </div> |
| 1695 | <div class="paragraph"> |
| 1696 | <p>The actual <code>cockpit.service</code> and <code>cockpit-ws</code> process will start on |
| 1697 | demand when a browser accesses the <code>cockpit.socket</code>, |
| 1698 | <a href="listen.html">usually on port 9090</a>. Once a user logs in then a |
| 1699 | <code>cockpit-bridge</code> process will be started in a Linux user login |
| 1700 | session.</p> |
| 1701 | </div> |
| 1702 | <div class="paragraph"> |
| 1703 | <p>Only systems that you connect to with your browser need to have the |
| 1704 | <code>cockpit.socket</code> enabled. For systems that you add through host |
| 1705 | switcher the bridge is started via SSH on demand.</p> |
| 1706 | </div> |
| 1707 | <div class="sect3"> |
| 1708 | <h4 id="startup-shutdown">Process exit</h4> |
| 1709 | <div class="paragraph"> |
| 1710 | <p>The <code>cockpit-bridge</code> process will exit when the user logs out. In |
| 1711 | addition, after 10 minutes of inactivity, the <code>cockpit-ws</code> process |
| 1712 | will exit on its own. The browser will automatically disconnect if it |
| 1713 | fails to hear from the <code>cockpit-ws</code> process for 30 seconds.</p> |
| 1714 | </div> |
| 1715 | </div> |
| 1716 | <div class="sect3"> |
| 1717 | <h4 id="startup-boot">Boot start up</h4> |
| 1718 | <div class="paragraph"> |
| 1719 | <p>To make Cockpit available by default after system boot the |
| 1720 | <code>cockpit.socket</code> needs to be enabled:</p> |
| 1721 | </div> |
| 1722 | <div class="literalblock"> |
| 1723 | <div class="content"> |
| 1724 | <pre>$ sudo systemctl enable cockpit.socket</pre> |
| 1725 | </div> |
| 1726 | </div> |
| 1727 | <div class="paragraph"> |
| 1728 | <p>If you wish to not have Cockpit available by default via a browser, then |
| 1729 | the <code>cockpit.socket</code> should be disabled:</p> |
| 1730 | </div> |
| 1731 | <div class="literalblock"> |
| 1732 | <div class="content"> |
| 1733 | <pre>$ sudo systemctl disable cockpit.socket</pre> |
| 1734 | </div> |
| 1735 | </div> |
| 1736 | </div> |
| 1737 | </div> |
| 1738 | <div class="sect2"> |
| 1739 | <h3 id="multi-host">Managing multiple hosts at the same time</h3> |
| 1740 | <div class="admonitionblock warning"> |
| 1741 | <table> |
| 1742 | <tr> |
| 1743 | <td class="icon"> |
| 1744 | <div class="title">Warning</div> |
| 1745 | </td> |
| 1746 | <td class="content"> |
| 1747 | <div class="paragraph"> |
| 1748 | <p>This feature is deprecated as of Cockpit 322.</p> |
| 1749 | </div> |
| 1750 | </td> |
| 1751 | </tr> |
| 1752 | </table> |
| 1753 | </div> |
| 1754 | <div class="paragraph"> |
| 1755 | <p>Cockpit allows you to access multiple hosts in a single session, by |
| 1756 | establishing SSH connections to other hosts. This is quite similar to |
| 1757 | logging into these other hosts using the <code>ssh</code> command on the command |
| 1758 | line, with one very important difference:</p> |
| 1759 | </div> |
| 1760 | <div class="paragraph"> |
| 1761 | <p>Code from the local host and all the remote hosts run at the same time, |
| 1762 | in the same browser context. They are not isolated from each other in |
| 1763 | the browser. All code effectively has the same privileges as the primary |
| 1764 | session on the local host.</p> |
| 1765 | </div> |
| 1766 | <div class="paragraph"> |
| 1767 | <p>Thus, <em>you should only only connect to remote hosts that you trust</em>. You |
| 1768 | must be sure that none of the hosts that you connect to will cause |
| 1769 | Cockpit to load malicious JavaScript code into your browser.</p> |
| 1770 | </div> |
| 1771 | <div class="paragraph"> |
| 1772 | <p>Therefore, Cockpit will warn you before connecting to more than one |
| 1773 | host. It is also possible to disable multiple hosts entirely, and some |
| 1774 | operating systems do this already by default.</p> |
| 1775 | </div> |
| 1776 | <div class="paragraph"> |
| 1777 | <p>You can prevent loading of JavaScript, HTML, etc from more than one host |
| 1778 | by adding this to <code>cockpit.conf</code>:</p> |
| 1779 | </div> |
| 1780 | <div class="literalblock"> |
| 1781 | <div class="content"> |
| 1782 | <pre> [WebService] |
| 1783 | AllowMultiHost=false</pre> |
| 1784 | </div> |
| 1785 | </div> |
| 1786 | <div class="paragraph"> |
| 1787 | <p>When you allow multiple hosts in a single Cockpit session by setting |
| 1788 | <code>AllowMultiHost</code> to true, then the user will be warned once per |
| 1789 | session, before connecting to the second host. If that is still too |
| 1790 | much, you can switch the warning off completely by adding the following |
| 1791 | to <code>cockpit.conf</code>:</p> |
| 1792 | </div> |
| 1793 | <div class="literalblock"> |
| 1794 | <div class="content"> |
| 1795 | <pre> [Session] |
| 1796 | WarnBeforeConnecting=false</pre> |
| 1797 | </div> |
| 1798 | </div> |
| 1799 | </div> |
| 1800 | <div class="sect2"> |
| 1801 | <h3 id="authentication">Cockpit Authentication</h3> |
| 1802 | <div class="paragraph"> |
| 1803 | <p>While cockpit allows you to monitor and administer several servers at |
| 1804 | the same time, there is always a primary server your browser connects to |
| 1805 | that runs the Cockpit web service (cockpit-ws) through which connections |
| 1806 | to additional servers are established. See |
| 1807 | <a href="https://raw.githubusercontent.com/cockpit-project/cockpit/main/doc/cockpit-transport.png">this |
| 1808 | diagram</a> for how it works.</p> |
| 1809 | </div> |
| 1810 | <div class="paragraph"> |
| 1811 | <p>Normally, a session is established on the primary server, and you use |
| 1812 | the Shell UI of that session to connect to secondary servers.</p> |
| 1813 | </div> |
| 1814 | <div class="paragraph"> |
| 1815 | <p>However, it is also possible to instruct the <code>cockpit-ws</code> process on |
| 1816 | the primary server to directly connect to a secondary server, without |
| 1817 | opening a session on the primary server at all. This is done on the main |
| 1818 | login page of Cockpit, by filling out the "Connect to" field.</p> |
| 1819 | </div> |
| 1820 | <div class="sect3"> |
| 1821 | <h4 id="initial-auth">Directly logging into the primary server</h4> |
| 1822 | <div class="paragraph"> |
| 1823 | <p>The most common way to use Cockpit is to just log directly into the |
| 1824 | server that you want to access. This can be done if you have direct |
| 1825 | network access to port 9090 on that server.</p> |
| 1826 | </div> |
| 1827 | <div class="paragraph"> |
| 1828 | <p>By default the cockpit web service is installed on thec base system and |
| 1829 | <a href="listen.html">socket activated by systemd</a>. In this setup access is |
| 1830 | controlled by a cockpit specific pam stack, generally located at |
| 1831 | <code>/etc/pam.d/cockpit</code>. By default this is configured to allow you to |
| 1832 | login with the username and password of any local account on the system. |
| 1833 | You can also setup a <a href="sso.html">Kerberos based SSO solution</a> or |
| 1834 | <a href="cert-authentication.html">certificate/smart card authentication</a>.</p> |
| 1835 | </div> |
| 1836 | <div class="paragraph"> |
| 1837 | <p>You can also |
| 1838 | <a href="https://github.com/cockpit-project/cockpit/blob/main/doc/authentication.md#actions">disable |
| 1839 | authentication schemes</a> to enforce authentication policies, or to |
| 1840 | suppress undesired browser GSSAPI authentication dialogs.</p> |
| 1841 | </div> |
| 1842 | <div class="paragraph"> |
| 1843 | <p>The web server can also be run from the |
| 1844 | <a href="https://quay.io/cockpit/ws">cockpit/ws</a> container. If you are |
| 1845 | running cockpit on a container host operating system like |
| 1846 | <a href="https://getfedora.org/coreos/">Fedora CoreOS</a> this will be the only |
| 1847 | supported mode. In this setup, cockpit establishes an SSH connection |
| 1848 | from the container to the underlying host, meaning that it is up to your |
| 1849 | SSH server to grant access. To login with a local account, <code>sshd</code> will |
| 1850 | need to be configured to allow password based authentication. |
| 1851 | Alternatively you can setup a <a href="sso.html">Kerberos based SSO solution</a>.</p> |
| 1852 | </div> |
| 1853 | <div class="paragraph"> |
| 1854 | <p>Like <code>sshd</code>, cockpit can be configured to limit the number of |
| 1855 | concurrent login attempts allowed. This is done by adding a |
| 1856 | <code>MaxStartups</code> option to the <code>WebService</code> section of your |
| 1857 | <code>cockpit.conf</code>. Additional connections will be dropped until |
| 1858 | authentication succeeds or the connections are closed.</p> |
| 1859 | </div> |
| 1860 | </div> |
| 1861 | <div class="sect3"> |
| 1862 | <h4 id="direct-secondary-auth">Directly logging into a secondary server without a primary session</h4> |
| 1863 | <div class="paragraph"> |
| 1864 | <p>It is also possible to log into a secondary server without opening a |
| 1865 | session on the primary server. This is useful if you are not actually |
| 1866 | interested in the primary server and would only use it because you do |
| 1867 | not have direct network access to the secondary server.</p> |
| 1868 | </div> |
| 1869 | <div class="paragraph"> |
| 1870 | <p>In this case, <code>cockpit-ws</code> still runs on the primary server, but the |
| 1871 | credentials from the login screen are directly used with SSH to log into |
| 1872 | the secondary server given in the "Connect To" field of the login |
| 1873 | screen.</p> |
| 1874 | </div> |
| 1875 | <div class="paragraph"> |
| 1876 | <p>Thus, the PAM configuration and accounts on the primary server don’t |
| 1877 | matter at all. Often, the only purpose of the primary server is to sit |
| 1878 | on the boundary of your network and forward connections to internal |
| 1879 | machines.</p> |
| 1880 | </div> |
| 1881 | <div class="paragraph"> |
| 1882 | <p>In this case, the login page will prompt you to verify unknown SSH keys. |
| 1883 | Accepted keys will be remembered in the local storage of your browser.</p> |
| 1884 | </div> |
| 1885 | </div> |
| 1886 | <div class="sect3"> |
| 1887 | <h4 id="secondary-auth">Logging into a secondary server from the primary session</h4> |
| 1888 | <div class="paragraph"> |
| 1889 | <p>Once you have a session on the primary server, it is possible connect to |
| 1890 | additional servers by using the host switching UI of the Cockpit Shell. |
| 1891 | This is useful if you have direct network access to the primary server, |
| 1892 | but not to the secondary server.</p> |
| 1893 | </div> |
| 1894 | <div class="paragraph"> |
| 1895 | <p>On the command line, you would log into the primary server and then use |
| 1896 | SSH to log into the secondary one. Cockpit does just the same, and uses |
| 1897 | SSH to log into the secondary server. Instead of running a interactive |
| 1898 | shell there, however, it starts a <code>cockpit-bridge</code> process.</p> |
| 1899 | </div> |
| 1900 | <div class="paragraph"> |
| 1901 | <p><em>Warning:</em> Unlike with SSH on the command line though, this will also |
| 1902 | load and use the Cockpit pages (i.e. JavaScript) from the remote |
| 1903 | machine, which means that the remote machine can execute arbitrary code |
| 1904 | on your primary and all other connected secondary machines. Hence, only |
| 1905 | connect to <em>machines which you trust</em>.</p> |
| 1906 | </div> |
| 1907 | <div class="paragraph"> |
| 1908 | <p>Due to this security risk, this host switcher functionality is disabled |
| 1909 | by default, except on long-term stable Linux distributions (Red Hat |
| 1910 | Enterprise Linux 9, Debian 12, and Ubuntu 22.04/24.04 LTS). If you are |
| 1911 | comfortable with the security implications, you can enable it manually |
| 1912 | with the <code>AllowMultiHost</code> option in <code>cockpit.conf</code>.</p> |
| 1913 | </div> |
| 1914 | <div class="paragraph"> |
| 1915 | <p>These servers will need to be running an SSH server and be configured to |
| 1916 | support one of the following authentication methods.</p> |
| 1917 | </div> |
| 1918 | <div class="sect4"> |
| 1919 | <h5 id="_password">Password</h5> |
| 1920 | <div class="paragraph"> |
| 1921 | <p>The target server will need to have password based authentication |
| 1922 | enabled in <code>sshd</code>.</p> |
| 1923 | </div> |
| 1924 | </div> |
| 1925 | <div class="sect4"> |
| 1926 | <h5 id="_kerberos">Kerberos</h5> |
| 1927 | <div class="paragraph"> |
| 1928 | <p>The target server will need to be a member of the same domain as the |
| 1929 | primary server and your domain must be whitelisted in your browser. See |
| 1930 | the <a href="sso.html">SSO documentation</a> for how to set this up.</p> |
| 1931 | </div> |
| 1932 | </div> |
| 1933 | <div class="sect4"> |
| 1934 | <h5 id="_public_key">Public key</h5> |
| 1935 | <div class="paragraph"> |
| 1936 | <p>When you successfully log into the primary server, a <code>ssh-agent</code> is |
| 1937 | started and keys are loaded into it by running <code>ssh-add</code> without any |
| 1938 | arguments. Any passphrase prompt is answered with the password used to |
| 1939 | log into the primary server.</p> |
| 1940 | </div> |
| 1941 | <div class="paragraph"> |
| 1942 | <p>Cockpit provides a user interface for loading other keys into the agent |
| 1943 | that could not be automatically loaded.</p> |
| 1944 | </div> |
| 1945 | <div class="paragraph"> |
| 1946 | <p>The target server will need to have public key authentication enabled in |
| 1947 | <code>sshd</code>, and the public key you wish to use must be present in |
| 1948 | <code>~/.ssh/authorized_keys</code>. Cockpit has a user interface for creating |
| 1949 | SSH keys and for authorizing them.</p> |
| 1950 | </div> |
| 1951 | </div> |
| 1952 | <div class="sect4"> |
| 1953 | <h5 id="host-keys">SSH host keys</h5> |
| 1954 | <div class="paragraph"> |
| 1955 | <p>Cockpit will prompt the user to verify unknown SSH host keys, and will |
| 1956 | write accepted host keys into <code>~/.ssh/known_hosts</code>.</p> |
| 1957 | </div> |
| 1958 | </div> |
| 1959 | </div> |
| 1960 | </div> |
| 1961 | <div class="sect2"> |
| 1962 | <h3 id="sso">Single Sign On</h3> |
| 1963 | <div class="paragraph"> |
| 1964 | <p>Cockpit can use Kerberos for Single Sign On authentication, where users |
| 1965 | are automatically authenticated if they have a valid Kerberos ticket.</p> |
| 1966 | </div> |
| 1967 | <div class="sect3"> |
| 1968 | <h4 id="sso-server">Server Requirements</h4> |
| 1969 | <div class="paragraph"> |
| 1970 | <p>To authenticate users, the server that Cockpit is running on must be |
| 1971 | joined to a domain. This can usually be accomplished using the |
| 1972 | <a href="https://freedesktop.org/software/realmd/docs/realm.html"><code>realm join example.com</code></a> |
| 1973 | command.</p> |
| 1974 | </div> |
| 1975 | <div class="paragraph"> |
| 1976 | <p>The domain must be resolvable by DNS. For instance, the SRV records of |
| 1977 | the kerberos server should be resolvable:</p> |
| 1978 | </div> |
| 1979 | <div class="literalblock"> |
| 1980 | <div class="content"> |
| 1981 | <pre>$ host -t SRV _kerberos._udp.example.com |
| 1982 | _kerberos._udp.example.com has SRV record 0 100 88 dc.example.com</pre> |
| 1983 | </div> |
| 1984 | </div> |
| 1985 | <div class="paragraph"> |
| 1986 | <p>The server running Cockpit should have a fully qualified name that ends |
| 1987 | with the domain name.</p> |
| 1988 | </div> |
| 1989 | <div class="paragraph"> |
| 1990 | <p>There must be a valid Kerberos host key for the server in the |
| 1991 | <code>/etc/krb5.keytab</code> file. Alternatively, if you would like to use a |
| 1992 | different keytab, you can do so by placing it in |
| 1993 | <code>/etc/cockpit/krb5.keytab</code>, or below <code>$XDG_CONFIG_DIRS</code> if set (see |
| 1994 | <a href="./cockpit.conf.5.html">cockpit.conf</a>). It may be necessary to create |
| 1995 | a kerberos service principal and update the keytab if it is not present. |
| 1996 | Depending on your domain type different service names are required:</p> |
| 1997 | </div> |
| 1998 | <div class="dlist"> |
| 1999 | <dl> |
| 2000 | <dt class="hdlist1">Active Directory</dt> |
| 2001 | <dd> |
| 2002 | <p><code>HOST/[email protected]</code></p> |
| 2003 | </dd> |
| 2004 | <dt class="hdlist1">IPA and MIT</dt> |
| 2005 | <dd> |
| 2006 | <p><code>HTTP/[email protected]</code></p> |
| 2007 | </dd> |
| 2008 | </dl> |
| 2009 | </div> |
| 2010 | <div class="paragraph"> |
| 2011 | <p>When joining an IPA domain with Cockpit and the <code>ipa</code> command line |
| 2012 | tool is available, both the service principal name and a |
| 2013 | <code>/etc/cockpit/krb5.keytab</code> get created automatically, so that Kerberos |
| 2014 | based single sign on into Cockpit works out of the box. If you want/need |
| 2015 | to do this by hand or in a script, first create or modify the <code>HTTP/</code> |
| 2016 | service principal:</p> |
| 2017 | </div> |
| 2018 | <div class="literalblock"> |
| 2019 | <div class="content"> |
| 2020 | <pre>$ sudo ipa service-add --ok-as-delegate=true --ok-to-auth-as-delegate=true \ |
| 2021 | HTTP/[email protected] |
| 2022 | # or, if it already exists, just enable delegation: |
| 2023 | $ sudo ipa service-mod --ok-as-delegate=true --ok-to-auth-as-delegate=true \ |
| 2024 | HTTP/[email protected]</pre> |
| 2025 | </div> |
| 2026 | </div> |
| 2027 | <div class="paragraph"> |
| 2028 | <p>Then generate a key for that principal:</p> |
| 2029 | </div> |
| 2030 | <div class="literalblock"> |
| 2031 | <div class="content"> |
| 2032 | <pre>$ sudo ipa-getkeytab -p HTTP/[email protected] -k /etc/cockpit/krb5.keytab</pre> |
| 2033 | </div> |
| 2034 | </div> |
| 2035 | <div class="paragraph"> |
| 2036 | <p>The following command can be used to list the |
| 2037 | <code>/etc/cockpit/krb5.keytab</code>:</p> |
| 2038 | </div> |
| 2039 | <div class="literalblock"> |
| 2040 | <div class="content"> |
| 2041 | <pre>$ sudo klist -k /etc/cockpit/krb5.keytab</pre> |
| 2042 | </div> |
| 2043 | </div> |
| 2044 | <div class="paragraph"> |
| 2045 | <p>Lastly accounts from the domain must be resolvable to unix accounts on |
| 2046 | the server running Cockpit. For example:</p> |
| 2047 | </div> |
| 2048 | <div class="literalblock"> |
| 2049 | <div class="content"> |
| 2050 | <pre>$ getent passwd [email protected] |
| 2051 | [email protected]:*:381001109:381000513:User Name:/home/user:/bin/sh</pre> |
| 2052 | </div> |
| 2053 | </div> |
| 2054 | <div class="paragraph"> |
| 2055 | <p>If you wish to delegate your kerberos credentials to Cockpit, and allow |
| 2056 | Cockpit to then connect to other machines using those credentials, you |
| 2057 | should enable delegation for the hosts running Cockpit, and in some |
| 2058 | cases the <code>HTTP</code> service as well. When joining an IPA domain, this is |
| 2059 | enabled by default.</p> |
| 2060 | </div> |
| 2061 | <div class="paragraph"> |
| 2062 | <p>Domain admins (usually the <code>[email protected]</code> group) should normally |
| 2063 | also be able to administer any joined machine. Enable sudo access for |
| 2064 | that group with the following command on the IPA server, for version |
| 2065 | 4.7.1 and later:</p> |
| 2066 | </div> |
| 2067 | <div class="literalblock"> |
| 2068 | <div class="content"> |
| 2069 | <pre>ipa-advise enable-admins-sudo | sh -ex</pre> |
| 2070 | </div> |
| 2071 | </div> |
| 2072 | <div class="paragraph"> |
| 2073 | <p>On earlier FreeIPA versions, run these commands instead, as a domain |
| 2074 | admin on any joined machine:</p> |
| 2075 | </div> |
| 2076 | <div class="literalblock"> |
| 2077 | <div class="content"> |
| 2078 | <pre>ipa sudorule-add --hostcat=all --cmdcat=all All |
| 2079 | ipa sudorule-add-user --groups=admins All</pre> |
| 2080 | </div> |
| 2081 | </div> |
| 2082 | <div class="paragraph"> |
| 2083 | <p>Note that this does not change security properties; domain admins can |
| 2084 | give this privilege to themselves, so it is safe to enable by default.</p> |
| 2085 | </div> |
| 2086 | </div> |
| 2087 | <div class="sect3"> |
| 2088 | <h4 id="sso-client">Client Requirements</h4> |
| 2089 | <div class="paragraph"> |
| 2090 | <p>The client side, where your web browser is running, should have a valid |
| 2091 | kerberos ticket in the current user session. A command like this will |
| 2092 | get one:</p> |
| 2093 | </div> |
| 2094 | <div class="literalblock"> |
| 2095 | <div class="content"> |
| 2096 | <pre>$ kinit [email protected] |
| 2097 | Password for [email protected]:</pre> |
| 2098 | </div> |
| 2099 | </div> |
| 2100 | <div class="paragraph"> |
| 2101 | <p>In addition your browser must be usually be configured to allow kerberos |
| 2102 | authentication for the domain.</p> |
| 2103 | </div> |
| 2104 | <div class="dlist"> |
| 2105 | <dl> |
| 2106 | <dt class="hdlist1">Mozilla Firefox</dt> |
| 2107 | <dd> |
| 2108 | <p>Go to <code>about:config</code> and set the |
| 2109 | <code>network.negotiate-auth.trusted-uris</code> setting to your domain name |
| 2110 | preceded by a dot, ie: <code>.example.com</code></p> |
| 2111 | </dd> |
| 2112 | <dt class="hdlist1">Google Chrome</dt> |
| 2113 | <dd> |
| 2114 | <p>On Linux: create the file |
| 2115 | <code>/etc/opt/chrome/policies/managed/example-com.json</code> with the |
| 2116 | contents:</p> |
| 2117 | </dd> |
| 2118 | <dt class="hdlist1"></dt> |
| 2119 | </dl> |
| 2120 | </div> |
| 2121 | <div class="literalblock"> |
| 2122 | <div class="content"> |
| 2123 | <pre>{ |
| 2124 | "AuthServerWhitelist": "*example.com" |
| 2125 | }</pre> |
| 2126 | </div> |
| 2127 | </div> |
| 2128 | <div class="dlist"> |
| 2129 | <dl> |
| 2130 | <dt class="hdlist1"></dt> |
| 2131 | <dd> |
| 2132 | <p>and restart the browser. On other platforms, exit your browser |
| 2133 | completely, and start it with a command line like this: |
| 2134 | <code>google-chrome --auth-server-whitelist=*example.com</code></p> |
| 2135 | </dd> |
| 2136 | </dl> |
| 2137 | </div> |
| 2138 | <div class="paragraph"> |
| 2139 | <p>Use a fully qualified server name (with the domain name at the end) to |
| 2140 | access Cockpit in your web browser.</p> |
| 2141 | </div> |
| 2142 | <div class="paragraph"> |
| 2143 | <p>If you wish to connect from one server to another in Cockpit using |
| 2144 | kerberos SSO, then you have to explicitly enable all sorts of things. |
| 2145 | For starters, make sure that delegated credentials are allowed by your |
| 2146 | domain (see above). Next when requesting your kerberos ticket make sure |
| 2147 | that forwardable tickets are requested:</p> |
| 2148 | </div> |
| 2149 | <div class="literalblock"> |
| 2150 | <div class="content"> |
| 2151 | <pre>$ kinit -f [email protected] |
| 2152 | Password for [email protected]:</pre> |
| 2153 | </div> |
| 2154 | </div> |
| 2155 | <div class="paragraph"> |
| 2156 | <p>Make sure that the forwardable flag <code>F</code> is present in your ticket:</p> |
| 2157 | </div> |
| 2158 | <div class="literalblock"> |
| 2159 | <div class="content"> |
| 2160 | <pre>$ klist -f |
| 2161 | Ticket cache: KEYRING:persistent:1000:1000 |
| 2162 | Default principal: [email protected] |
| 2163 | |
| 2164 | Valid starting Expires Service principal |
| 2165 | 18.03.2017 05:39:23 19.03.2017 05:39:20 krbtgt/[email protected] |
| 2166 | Flags: FIA</pre> |
| 2167 | </div> |
| 2168 | </div> |
| 2169 | <div class="paragraph"> |
| 2170 | <p>Lastly configure your browser to allow delegated, forwardable kerberos |
| 2171 | credentials to be sent to Cockpit:</p> |
| 2172 | </div> |
| 2173 | <div class="dlist"> |
| 2174 | <dl> |
| 2175 | <dt class="hdlist1">Mozilla Firefox</dt> |
| 2176 | <dd> |
| 2177 | <p>Go to <code>about:config</code> and set the |
| 2178 | <code>network.negotiate-auth.delegation-uris</code> setting to your domain name |
| 2179 | preceded by a dot, ie: <code>.example.com</code></p> |
| 2180 | </dd> |
| 2181 | <dt class="hdlist1">Google Chrome</dt> |
| 2182 | <dd> |
| 2183 | <p>On Linux: create the file |
| 2184 | <code>/etc/opt/chrome/policies/managed/example-com.json</code> with the |
| 2185 | contents:</p> |
| 2186 | </dd> |
| 2187 | <dt class="hdlist1"></dt> |
| 2188 | </dl> |
| 2189 | </div> |
| 2190 | <div class="literalblock"> |
| 2191 | <div class="content"> |
| 2192 | <pre>{ |
| 2193 | "AuthServerWhitelist": "*example.com", |
| 2194 | "AuthNegotiateDelegateWhitelist": "*example.com" |
| 2195 | }</pre> |
| 2196 | </div> |
| 2197 | </div> |
| 2198 | <div class="dlist"> |
| 2199 | <dl> |
| 2200 | <dt class="hdlist1"></dt> |
| 2201 | <dd> |
| 2202 | <p>and restart the browser. On other platforms, exit your browser |
| 2203 | completely, and start it with a command line like this: |
| 2204 | <code>google-chrome --auth-server-whitelist=*example.com --auth-negotiate-delegate-whitelist=*example.com</code></p> |
| 2205 | </dd> |
| 2206 | </dl> |
| 2207 | </div> |
| 2208 | </div> |
| 2209 | </div> |
| 2210 | <div class="sect2"> |
| 2211 | <h3 id="cert-authentication">Certificate/smart card authentication</h3> |
| 2212 | <div class="paragraph"> |
| 2213 | <p>Cockpit can use TLS client certificates for authenticating users. |
| 2214 | Commonly these are provided by a smart card, but it’s equally possible |
| 2215 | to import certificates directly into the web browser.</p> |
| 2216 | </div> |
| 2217 | <div class="paragraph"> |
| 2218 | <p>This requires the host to be in an Identity Management domain like |
| 2219 | <a href="https://www.freeipa.org">FreeIPA</a> or |
| 2220 | <a href="https://en.wikipedia.org/wiki/Active_Directory">Active Directory</a>, which |
| 2221 | can associate certificates to users.</p> |
| 2222 | </div> |
| 2223 | <div class="paragraph"> |
| 2224 | <p>To authenticate users from a Identity Management domain, the server that |
| 2225 | Cockpit is running on must be joined to that domain. See the |
| 2226 | <a href="sso.html#sso-server">SSO server requirements</a> for details.</p> |
| 2227 | </div> |
| 2228 | <div class="sect3"> |
| 2229 | <h4 id="certauth-server-cert-generation">User certificate generation</h4> |
| 2230 | <div class="paragraph"> |
| 2231 | <p>Generating the certificates for users is usually done with a certificate |
| 2232 | management system like <a href="https://pagure.io/certmonger">certmonger</a> or |
| 2233 | <a href="https://www.freeipa.org/page/PKI">FreeIPA</a>, which are not documented |
| 2234 | here. This command generates a simple key and certificate request for |
| 2235 | the "alice" user:</p> |
| 2236 | </div> |
| 2237 | <div class="literalblock"> |
| 2238 | <div class="content"> |
| 2239 | <pre>openssl req -new -newkey rsa:2048 -days 365 \ |
| 2240 | -keyout alice.key -out alice.csr -subj "/CN=alice"</pre> |
| 2241 | </div> |
| 2242 | </div> |
| 2243 | <div class="paragraph"> |
| 2244 | <p>Now get this certificate request signed by the Certificate Authority of |
| 2245 | your Identity Management domain, to get a PEM certificate. Browsers and |
| 2246 | smart cart utilities accept PKCS#12 format for importing/transfer, so |
| 2247 | convert the certificate/key pair; it will ask for and protect it with a |
| 2248 | transfer password:</p> |
| 2249 | </div> |
| 2250 | <div class="literalblock"> |
| 2251 | <div class="content"> |
| 2252 | <pre>openssl pkcs12 -export -in alice.pem -inkey alice.key -out alice.p12</pre> |
| 2253 | </div> |
| 2254 | </div> |
| 2255 | <div class="paragraph"> |
| 2256 | <p>Don’t forget to clean up the key file when you do not need it any more:</p> |
| 2257 | </div> |
| 2258 | <div class="literalblock"> |
| 2259 | <div class="content"> |
| 2260 | <pre>shred -u alice.key</pre> |
| 2261 | </div> |
| 2262 | </div> |
| 2263 | <div class="paragraph"> |
| 2264 | <p>You can now import <code>alice.p12</code> directly into your browser, with giving |
| 2265 | the transfer password set above. Or |
| 2266 | <a href="https://linux.die.net/man/1/pkcs15-init">put the certificate onto a smart |
| 2267 | card</a>:</p> |
| 2268 | </div> |
| 2269 | <div class="literalblock"> |
| 2270 | <div class="content"> |
| 2271 | <pre>pkcs15-init --store-private-key alice.p12 --format pkcs12 --auth-id 01</pre> |
| 2272 | </div> |
| 2273 | </div> |
| 2274 | </div> |
| 2275 | <div class="sect3"> |
| 2276 | <h4 id="certauth-server-ipa">Certificate mapping with FreeIPA</h4> |
| 2277 | <div class="paragraph"> |
| 2278 | <p>The recommended method to sign a user certificate request and associate |
| 2279 | it to a user is <code>ipa cert-request</code>:</p> |
| 2280 | </div> |
| 2281 | <div class="literalblock"> |
| 2282 | <div class="content"> |
| 2283 | <pre>ipa cert-request alice.csr --principal=alice --certificate-out=alice.pem</pre> |
| 2284 | </div> |
| 2285 | </div> |
| 2286 | <div class="paragraph"> |
| 2287 | <p>Alternatively, if you are using a different CA, you can use |
| 2288 | <code>ipa user-add-cert</code> to associate the signed certificate to the user. |
| 2289 | This expects PEM format, but without the <code>-----BEGIN</code>/<code>-----END</code> |
| 2290 | markers:</p> |
| 2291 | </div> |
| 2292 | <div class="literalblock"> |
| 2293 | <div class="content"> |
| 2294 | <pre>ipa user-add-cert alice --certificate="$(grep -v ^---- alice.pem)"</pre> |
| 2295 | </div> |
| 2296 | </div> |
| 2297 | <div class="paragraph"> |
| 2298 | <p>See the |
| 2299 | <a href="https://www.freeipa.org/page/V4/User_Certificates#Feature_Management">FreeIPA |
| 2300 | User Certificates documentation</a> for details.</p> |
| 2301 | </div> |
| 2302 | </div> |
| 2303 | <div class="sect3"> |
| 2304 | <h4 id="certauth-server-ms-ad">Certificate mapping with Microsoft Active Directory</h4> |
| 2305 | <div class="paragraph"> |
| 2306 | <p>The domain user certificates get imported into the |
| 2307 | <code>userCertificate;binary</code> LDAP attribute. The following commands |
| 2308 | convert the PEM certificate into binary DER form, create an |
| 2309 | <a href="https://ldap.com/ldif-the-ldap-data-interchange-format/">LDIF</a> file and |
| 2310 | apply it to the LDAP server running on the domain controller |
| 2311 | "dc.example.com":</p> |
| 2312 | </div> |
| 2313 | <div class="literalblock"> |
| 2314 | <div class="content"> |
| 2315 | <pre>openssl x509 -outform der -in alice.pem -out alice.der |
| 2316 | |
| 2317 | cat <<EOF > alice.ldif |
| 2318 | version: 1 |
| 2319 | dn: cn=alice,ou=users,ou=YOUR_NETBIOS_NAME,dc=example,dc=com |
| 2320 | changetype: modify |
| 2321 | add: userCertificate;binary |
| 2322 | userCertificate;binary:< file://$(pwd)/alice.der |
| 2323 | EOF |
| 2324 | |
| 2325 | ldapmodify -H ldap://dc.example.com -f alice.ldif</pre> |
| 2326 | </div> |
| 2327 | </div> |
| 2328 | </div> |
| 2329 | <div class="sect3"> |
| 2330 | <h4 id="certauth-server-samba-ad">Certificate mapping with Samba Active Directory</h4> |
| 2331 | <div class="paragraph"> |
| 2332 | <p>At least some versions of <a href="https://www.samba.org/">Samba</a> do not support |
| 2333 | the <code>userCertificate;binary</code> LDAP attribute, so the import has to |
| 2334 | happen in base64 PEM form into the textual <code>userCertificate</code> attribute |
| 2335 | instead. Also, Samba uses a slightly different user hierarchy:</p> |
| 2336 | </div> |
| 2337 | <div class="literalblock"> |
| 2338 | <div class="content"> |
| 2339 | <pre>cat <<EOF > alice.ldif |
| 2340 | version: 1 |
| 2341 | dn: cn=alice,cn=users,dc=example,dc=com |
| 2342 | changetype: modify |
| 2343 | add: userCertificate |
| 2344 | userCertificate: $(grep -v ^---- alice.pem | tr -d '\n') |
| 2345 | EOF |
| 2346 | |
| 2347 | ldapmodify -H ldap://dc.example.com -f alice.ldif</pre> |
| 2348 | </div> |
| 2349 | </div> |
| 2350 | <div class="paragraph"> |
| 2351 | <p>As <code>userCertificate</code> is a text instead of binary field, you need to |
| 2352 | set up a |
| 2353 | <a href="https://www.mankier.com/5/sssd.conf#Certificate_Mapping_Section">certificate |
| 2354 | mapping rule</a> in <code>sssd.conf(5)</code> in a <code>[certmap/domain/rulename]</code> |
| 2355 | section, for example:</p> |
| 2356 | </div> |
| 2357 | <div class="literalblock"> |
| 2358 | <div class="content"> |
| 2359 | <pre>[certmap/example.com/adcerts] |
| 2360 | # we match full certificates, so it is not important to check anything here |
| 2361 | matchrule = <KU>digitalSignature |
| 2362 | maprule = LDAP:(userCertificate={cert!base64})</pre> |
| 2363 | </div> |
| 2364 | </div> |
| 2365 | </div> |
| 2366 | <div class="sect3"> |
| 2367 | <h4 id="certauth-server-cockpitconf">Cockpit web server configuration</h4> |
| 2368 | <div class="paragraph"> |
| 2369 | <p>Set the trusted Certificate Authority of your user certificates in |
| 2370 | <code>sssd</code>, either by copying the CA PEM file to |
| 2371 | <code>/etc/sssd/pki/sssd_auth_ca_db.pem</code> or setting the |
| 2372 | <a href="https://www.mankier.com/5/sssd.conf#Services_Sections-PAM_configuration_options"><code>pam_cert_db_path</code></a> |
| 2373 | configuration option to the path of the CA. If you use FreeIPA and its |
| 2374 | CA:</p> |
| 2375 | </div> |
| 2376 | <div class="literalblock"> |
| 2377 | <div class="content"> |
| 2378 | <pre>cp /etc/ipa/ca.crt /etc/sssd/pki/sssd_auth_ca_db.pem</pre> |
| 2379 | </div> |
| 2380 | </div> |
| 2381 | <div class="paragraph"> |
| 2382 | <p>Certificate authentication needs to be enabled in |
| 2383 | <a href="cockpit.conf.5.html">cockpit.conf</a>(5) explicitly:</p> |
| 2384 | </div> |
| 2385 | <div class="literalblock"> |
| 2386 | <div class="content"> |
| 2387 | <pre>[WebService] |
| 2388 | ClientCertAuthentication = yes</pre> |
| 2389 | </div> |
| 2390 | </div> |
| 2391 | <div class="paragraph"> |
| 2392 | <p>When enabling this mode, |
| 2393 | <a href="https://github.com/cockpit-project/cockpit/blob/main/doc/authentication.md">other |
| 2394 | authentication types</a> commonly get disabled, so that <em>only</em> client |
| 2395 | certificate authentication will be accepted. By default, after a failed |
| 2396 | certificate authentication attempt, Cockpit’s normal login page will |
| 2397 | appear and permit other login types such as <code>basic</code> (passwords) or |
| 2398 | <code>negotiate</code> (Kerberos). For example, password authentication gets |
| 2399 | disabled with:</p> |
| 2400 | </div> |
| 2401 | <div class="literalblock"> |
| 2402 | <div class="content"> |
| 2403 | <pre>[basic] |
| 2404 | action = none</pre> |
| 2405 | </div> |
| 2406 | </div> |
| 2407 | </div> |
| 2408 | <div class="sect3"> |
| 2409 | <h4 id="certauth-server-resourcelimits">Cockpit web server resource limits</h4> |
| 2410 | <div class="paragraph"> |
| 2411 | <p>When using certificate authentication, all requests with a particular |
| 2412 | certificate will be handled by a separate and isolated instance of the |
| 2413 | <a href="cockpit-ws.8.html">cockpit-ws</a>(8) web server. This protects against |
| 2414 | possible vulnerabilities in the web server and prevents an attacker from |
| 2415 | impersonating another user. However, this introduces a potential Denial |
| 2416 | of Service: Some remote attacker could create a large number of |
| 2417 | certificates and send a large number of http requests to Cockpit with |
| 2418 | these.</p> |
| 2419 | </div> |
| 2420 | <div class="paragraph"> |
| 2421 | <p>To mitigate that, all <code>cockpit-ws</code> instances run in a |
| 2422 | <code>system-cockpithttps.slice</code> |
| 2423 | <a href="https://www.freedesktop.org/software/systemd/man/systemd.slice.html">systemd |
| 2424 | slice unit</a> which |
| 2425 | <a href="https://www.freedesktop.org/software/systemd/man/systemd.resource-control.html">limits |
| 2426 | the collective resources</a> of these web server instances: by default, |
| 2427 | this slice sets a limit of 200 threads (roughly 100 instances of |
| 2428 | <code>cockpit-ws</code> — in other words, a maximum of 100 parallel user |
| 2429 | sessions with different certificates) and a 75% (soft)/90% (hard) memory |
| 2430 | limit.</p> |
| 2431 | </div> |
| 2432 | <div class="paragraph"> |
| 2433 | <p>You are welcome to adjust these limits to your need through a |
| 2434 | <a href="https://www.freedesktop.org/software/systemd/man/systemd.unit.html">drop-in</a>. |
| 2435 | For example:</p> |
| 2436 | </div> |
| 2437 | <div class="literalblock"> |
| 2438 | <div class="content"> |
| 2439 | <pre># systemctl edit system-cockpithttps.slice |
| 2440 | |
| 2441 | [Slice] |
| 2442 | # change existing value |
| 2443 | TasksMax=100 |
| 2444 | # add new restriction |
| 2445 | CPUQuota=30%</pre> |
| 2446 | </div> |
| 2447 | </div> |
| 2448 | </div> |
| 2449 | <div class="sect3"> |
| 2450 | <h4 id="certauth-forwarding">Authentication to other services like sudo and ssh</h4> |
| 2451 | <div class="paragraph"> |
| 2452 | <p>Once you logged into Cockpit with a certificate, you likely need to |
| 2453 | switch to administrative mode (root privileges through sudo), or connect |
| 2454 | to remote machines through SSH. If your user account has a password, |
| 2455 | that can be used for authenticating to sudo or ssh as usual.</p> |
| 2456 | </div> |
| 2457 | <div class="paragraph"> |
| 2458 | <p><em>Supported with FreeIPA only:</em> As an alternative to password |
| 2459 | authentication, you can also declare the initial Cockpit certificate |
| 2460 | authentication as trusted for authenticating to SSH, sudo, or other |
| 2461 | services. For that purpose, Cockpit automatically creates an |
| 2462 | <a href="https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-sfu/bde93b0e-f3c9-4ddf-9f44-e1453be7af5a">S4U2Proxy |
| 2463 | Kerberos ticket</a> in the user session:</p> |
| 2464 | </div> |
| 2465 | <div class="literalblock"> |
| 2466 | <div class="content"> |
| 2467 | <pre>$ klist |
| 2468 | Ticket cache: FILE:/run/user/1894000001/cockpit-session-3692.ccache |
| 2469 | Default principal: [email protected] |
| 2470 | |
| 2471 | Valid starting Expires Service principal |
| 2472 | 07/30/21 09:19:06 07/31/21 09:19:06 HTTP/[email protected] |
| 2473 | 07/30/21 09:19:06 07/31/21 09:19:06 krbtgt/[email protected] |
| 2474 | for client HTTP/[email protected]</pre> |
| 2475 | </div> |
| 2476 | </div> |
| 2477 | <div class="paragraph"> |
| 2478 | <p>You can set up |
| 2479 | <a href="https://www.freeipa.org/page/V4/Service_Constraint_Delegation">constrained |
| 2480 | delegation rules</a> to enumerate which hosts (including its own) that |
| 2481 | ticket is trusted to access. For example, if the cockpit session runs on |
| 2482 | host <code>myhost.example.com</code> and should be trusted to access its own host |
| 2483 | (through sudo) and another host <code>remote.example.com</code> (through ssh), |
| 2484 | create a delegation like this:</p> |
| 2485 | </div> |
| 2486 | <div class="literalblock"> |
| 2487 | <div class="content"> |
| 2488 | <pre># a list of target machines which can be accessed by a particular rule |
| 2489 | ipa servicedelegationtarget-add cockpit-target |
| 2490 | ipa servicedelegationtarget-add-member cockpit-target \ |
| 2491 | --principals=host/[email protected] \ |
| 2492 | --principals=host/[email protected] |
| 2493 | |
| 2494 | # allow cockpit sessions (HTTP/ principal) to access that host list |
| 2495 | ipa servicedelegationrule-add cockpit-delegation |
| 2496 | ipa servicedelegationrule-add-member cockpit-delegation \ |
| 2497 | --principals=HTTP/[email protected] |
| 2498 | ipa servicedelegationrule-add-target cockpit-delegation \ |
| 2499 | --servicedelegationtargets=cockpit-target</pre> |
| 2500 | </div> |
| 2501 | </div> |
| 2502 | <div class="paragraph"> |
| 2503 | <p>In addition, you need to enable GSS (Kerberos) authentication in the |
| 2504 | corresponding services.</p> |
| 2505 | </div> |
| 2506 | <div class="ulist"> |
| 2507 | <ul> |
| 2508 | <li> |
| 2509 | <p>For SSH, enable <code>GSSAPIAuthentication yes</code> in |
| 2510 | <a href="https://linux.die.net/man/5/sshd_config">/etc/ssh/sshd_config</a>.</p> |
| 2511 | </li> |
| 2512 | <li> |
| 2513 | <p>For sudo, enable <code>pam_sss_gss</code> as described in the |
| 2514 | <a href="https://www.mankier.com/8/pam_sss_gss">manpage</a>: In |
| 2515 | <code>/etc/sssd/sssd.conf</code>: Add an entry for your domain:</p> |
| 2516 | <div class="literalblock"> |
| 2517 | <div class="content"> |
| 2518 | <pre>[domain/example.com] |
| 2519 | pam_gssapi_services = sudo, sudo-i</pre> |
| 2520 | </div> |
| 2521 | </div> |
| 2522 | <div class="paragraph"> |
| 2523 | <p>In <code>/etc/pam.d/sudo</code>, enable the module in the first line:</p> |
| 2524 | </div> |
| 2525 | <div class="literalblock"> |
| 2526 | <div class="content"> |
| 2527 | <pre>auth sufficient pam_sss_gss.so</pre> |
| 2528 | </div> |
| 2529 | </div> |
| 2530 | </li> |
| 2531 | </ul> |
| 2532 | </div> |
| 2533 | <div class="paragraph"> |
| 2534 | <p><em>Caveat:</em> The delegated S4U ticket is not yet forwarded to remote SSH |
| 2535 | hosts when connecting to them from Cockpit, so authenticating to sudo on |
| 2536 | the remote host with that ticket does not work. This will be provided in |
| 2537 | a future version.</p> |
| 2538 | </div> |
| 2539 | </div> |
| 2540 | </div> |
| 2541 | <div class="sect2"> |
| 2542 | <h3 id="privileges">Privileges and Permissions</h3> |
| 2543 | <div class="paragraph"> |
| 2544 | <p>When a user is logged into Cockpit, they are logged into a normal |
| 2545 | session that has exactly the same privileges as if they logged in via |
| 2546 | SSH or on the console.</p> |
| 2547 | </div> |
| 2548 | <div class="paragraph"> |
| 2549 | <p>However, Cockpit will usually try to escalate the privileges of the user |
| 2550 | using <a href="https://www.freedesktop.org/wiki/Software/polkit/">Policy Kit</a> or |
| 2551 | <a href="https://www.sudo.ws/">sudo</a>. If the user is able to escalate privileges |
| 2552 | from the command line by typing in their password again (or without |
| 2553 | typing in any password), then Cockpit will be able to escalate the |
| 2554 | privileges of the session to "root" immediately upon login.</p> |
| 2555 | </div> |
| 2556 | <div class="paragraph"> |
| 2557 | <p>The user can change the privileges of a session from within that |
| 2558 | session, via the "Administrative access" indicator in the top bar. From |
| 2559 | that indicator, the user can drop "root" privileges and regain them. On |
| 2560 | the next login, Cockpit will give the session the same privileges.</p> |
| 2561 | </div> |
| 2562 | <div class="paragraph"> |
| 2563 | <p>Usually a user needs to be in the <code>wheel</code> Unix user group for the user |
| 2564 | to be able to escalate privileges in this way. However both Policy Kit |
| 2565 | and sudo may be configured to use other criteria.</p> |
| 2566 | </div> |
| 2567 | <div class="sect3"> |
| 2568 | <h4 id="privileges-polkit">Customizing Polkit Privileges</h4> |
| 2569 | <div class="paragraph"> |
| 2570 | <p>Services like |
| 2571 | <a href="https://www.freedesktop.org/wiki/Software/systemd/">systemd</a> and |
| 2572 | <a href="https://wiki.gnome.org/Projects/NetworkManager">NetworkManager</a> use |
| 2573 | <a href="https://www.freedesktop.org/wiki/Software/polkit/">Polkit</a> to validate |
| 2574 | and escalate privileges. It is possible to customize these rules with |
| 2575 | files in <code>/etc/polkit-1/rules.d</code>.</p> |
| 2576 | </div> |
| 2577 | <div class="paragraph"> |
| 2578 | <p>Polkit rules files are |
| 2579 | <a href="https://www.freedesktop.org/software/polkit/docs/latest/polkit.8.html">javascript |
| 2580 | with specific methods and objects</a>. For example, placing the following |
| 2581 | polkit rule to <code>/etc/polkit-1/rules.d/10-operators.rule</code> allows all |
| 2582 | users in the <code>operators</code> group to start, stop, restart and otherwise |
| 2583 | manage systemd services:</p> |
| 2584 | </div> |
| 2585 | <div class="literalblock"> |
| 2586 | <div class="content"> |
| 2587 | <pre>polkit.addRule(function(action, subject) { |
| 2588 | if (action.id == "org.freedesktop.systemd1.manage-units") { |
| 2589 | if (subject.isInGroup("operators")) { |
| 2590 | return polkit.Result.YES; |
| 2591 | } |
| 2592 | } |
| 2593 | });</pre> |
| 2594 | </div> |
| 2595 | </div> |
| 2596 | <div class="paragraph"> |
| 2597 | <p>In order to allow a certain group to perform any administrative action |
| 2598 | you could add a rule like this:</p> |
| 2599 | </div> |
| 2600 | <div class="literalblock"> |
| 2601 | <div class="content"> |
| 2602 | <pre>polkit.addAdminRule(function(action, subject) { |
| 2603 | return ["unix-group:operators"]; |
| 2604 | });</pre> |
| 2605 | </div> |
| 2606 | </div> |
| 2607 | </div> |
| 2608 | </div> |
| 2609 | </div> |
| 2610 | </div> |
| 2611 | <div class="sect1"> |
| 2612 | <h2 id="features">Feature Internals</h2> |
| 2613 | <div class="sectionbody"> |
| 2614 | <div class="sect2"> |
| 2615 | <h3 id="feature-systemd">systemd</h3> |
| 2616 | <div class="paragraph"> |
| 2617 | <p>Cockpit uses <a href="https://www.freedesktop.org/wiki/Software/systemd/">systemd</a> |
| 2618 | and the DBus APIs it provides to configure and monitor core aspects of |
| 2619 | the system. Use of alternate system APIs are not currently implemented.</p> |
| 2620 | </div> |
| 2621 | <div class="paragraph"> |
| 2622 | <p>For non root users, systemd controls access to its APIs via |
| 2623 | <a href="privileges.html">Policy Kit</a> and a user logged into Cockpit will have |
| 2624 | the same permissions as they do from the command line.</p> |
| 2625 | </div> |
| 2626 | <div class="paragraph"> |
| 2627 | <p>Cockpit retrieves information about the host and changes the hostname |
| 2628 | via the <code>hostnamed</code> daemon. To perform similar tasks from the command |
| 2629 | line use the |
| 2630 | <a href="https://www.freedesktop.org/software/systemd/man/hostnamectl.html"><code>hostnamectl</code></a> |
| 2631 | command:</p> |
| 2632 | </div> |
| 2633 | <div class="literalblock"> |
| 2634 | <div class="content"> |
| 2635 | <pre>$ hostnamectl |
| 2636 | Static hostname: pink.example.com |
| 2637 | Pretty hostname: Pink |
| 2638 | Icon name: computer-desktop |
| 2639 | Chassis: desktop |
| 2640 | Machine ID: ef00b79be229463cbb844c3e715de96c |
| 2641 | Boot ID: 934983d64d34465cb5a8383b5a89ad8c |
| 2642 | Operating System: Fedora 22 (Twenty Two) |
| 2643 | CPE OS Name: cpe:/o:fedoraproject:fedora:22 |
| 2644 | Kernel: Linux 4.0.4-301.fc22.x86_64 |
| 2645 | Architecture: x86-64</pre> |
| 2646 | </div> |
| 2647 | </div> |
| 2648 | <div class="paragraph"> |
| 2649 | <p>Cockpit configures the system time and time zone via the <code>timedated</code> |
| 2650 | daemon. To perform similar tasks from the command line use the |
| 2651 | <a href="https://www.freedesktop.org/software/systemd/man/timedatectl.html"><code>timedatectl</code></a> |
| 2652 | command:</p> |
| 2653 | </div> |
| 2654 | <div class="literalblock"> |
| 2655 | <div class="content"> |
| 2656 | <pre>$ timedatectl list-timezones |
| 2657 | Africa/Abidjan |
| 2658 | Africa/Accra |
| 2659 | Africa/Addis_Ababa |
| 2660 | Africa/Algiers |
| 2661 | ...</pre> |
| 2662 | </div> |
| 2663 | </div> |
| 2664 | <div class="paragraph"> |
| 2665 | <p>Cockpit can manage the list of NTP servers used by <code>systemd-timesyncd</code> |
| 2666 | by putting its own file into <code>/etc/systemd/timesyncd.conf.d/</code>. Note |
| 2667 | that <code>systemd-timesyncd</code> is not always enabled, depending on the |
| 2668 | configuration of the machine. In that case, Cockpit disabled the UI for |
| 2669 | managing the list of NTP servers. In some cases use of <code>ntpd</code> can |
| 2670 | cause the <code>timedated</code> daemon to behave inconsistently with regards to |
| 2671 | time synchronization.</p> |
| 2672 | </div> |
| 2673 | <div class="paragraph"> |
| 2674 | <p>Cockpit reboots or powers down the machine by using the |
| 2675 | <a href="https://www.freedesktop.org/software/systemd/man/shutdown.html"><code>shutdown</code></a> |
| 2676 | command. To perform similar tasks from the command line, run it |
| 2677 | directly:</p> |
| 2678 | </div> |
| 2679 | <div class="literalblock"> |
| 2680 | <div class="content"> |
| 2681 | <pre>$ sudo shutdown +15 |
| 2682 | Shutdown scheduled for Sa 2015-09-26 15:49:40 CEST, use 'shutdown -c' to cancel.</pre> |
| 2683 | </div> |
| 2684 | </div> |
| 2685 | <div class="paragraph"> |
| 2686 | <p>Cockpit manages system services and sockets via systemd. To perform |
| 2687 | similar tasks from the command line use the |
| 2688 | <a href="https://www.freedesktop.org/software/systemd/man/systemctl.html"><code>systemctl</code></a> |
| 2689 | command:</p> |
| 2690 | </div> |
| 2691 | <div class="literalblock"> |
| 2692 | <div class="content"> |
| 2693 | <pre>$ systemctl status cockpit |
| 2694 | ● cockpit.service - Cockpit Web Service |
| 2695 | Loaded: loaded (/usr/lib/systemd/system/cockpit.service; static; vendor preset: disabled) |
| 2696 | Drop-In: /etc/systemd/system/cockpit.service.d |
| 2697 | └─debug.conf |
| 2698 | Active: active (running) since Sa 2015-09-26 13:28:02 CEST; 2h 7min ago |
| 2699 | Docs: man:cockpit-ws(8) |
| 2700 | Main PID: 6957 (cockpit-ws) |
| 2701 | Memory: 1.8M |
| 2702 | CGroup: /system.slice/cockpit.service |
| 2703 | ├─ 6957 /usr/libexec/cockpit-ws |
| 2704 | └─29598 /usr/bin/ssh-agent</pre> |
| 2705 | </div> |
| 2706 | </div> |
| 2707 | <div class="paragraph"> |
| 2708 | <p>In order to customize who can perform various actions in system, |
| 2709 | <a href="privileges.html#privileges-polkit">create polkit rules</a> with the following actions |
| 2710 | and details:</p> |
| 2711 | </div> |
| 2712 | <div class="dlist"> |
| 2713 | <dl> |
| 2714 | <dt class="hdlist1"><code>org.freedesktop.systemd1.manage-units</code></dt> |
| 2715 | <dd> |
| 2716 | <p>Permission to manage system services or other units. Details |
| 2717 | available: <code>unit</code>, <code>verb</code></p> |
| 2718 | </dd> |
| 2719 | <dt class="hdlist1"><code>org.freedesktop.systemd1.manage-unit-files</code></dt> |
| 2720 | <dd> |
| 2721 | <p>Permission to manage system services or other unit files.</p> |
| 2722 | </dd> |
| 2723 | <dt class="hdlist1"><code>org.freedesktop.systemd1.reload-daemon</code></dt> |
| 2724 | <dd> |
| 2725 | <p>Permission to reload the systemd state.</p> |
| 2726 | </dd> |
| 2727 | </dl> |
| 2728 | </div> |
| 2729 | <div class="paragraph"> |
| 2730 | <p>For example, placing the following polkit rule to |
| 2731 | <code>/etc/polkit-1/rules.d/10-http.rule</code> allows all users in the |
| 2732 | <code>operators</code> group start, stop, and restart the Apache HTTP service:</p> |
| 2733 | </div> |
| 2734 | <div class="literalblock"> |
| 2735 | <div class="content"> |
| 2736 | <pre>polkit.addRule(function(action, subject) { |
| 2737 | if (action.id == "org.freedesktop.systemd1.manage-units") { |
| 2738 | if (subject.isInGroup("operators") && action.lookup("unit") == "httpd.service") { |
| 2739 | var verb = action.lookup("verb"); |
| 2740 | if (verb == "start" || verb == "stop" || verb == "restart") { |
| 2741 | return polkit.Result.YES; |
| 2742 | } |
| 2743 | } |
| 2744 | } |
| 2745 | });</pre> |
| 2746 | </div> |
| 2747 | </div> |
| 2748 | </div> |
| 2749 | <div class="sect2"> |
| 2750 | <h3 id="feature-journal">Journal</h3> |
| 2751 | <div class="paragraph"> |
| 2752 | <p>The systemd journal provides Cockpit with indexed log data. This log |
| 2753 | data is found on the Journal page, as well as in various other places |
| 2754 | when configuring services, storage, networking etc.</p> |
| 2755 | </div> |
| 2756 | <div class="paragraph"> |
| 2757 | <p>Cockpit accesses Journal data via the |
| 2758 | <a href="https://www.freedesktop.org/software/systemd/man/journalctl.html"><code>journalctl</code></a> |
| 2759 | command. Similar tasks can be performed at the command line:</p> |
| 2760 | </div> |
| 2761 | <div class="literalblock"> |
| 2762 | <div class="content"> |
| 2763 | <pre>$ sudo journalctl -f -u docker |
| 2764 | ...</pre> |
| 2765 | </div> |
| 2766 | </div> |
| 2767 | </div> |
| 2768 | <div class="sect2"> |
| 2769 | <h3 id="feature-networkmanager">NetworkManager</h3> |
| 2770 | <div class="paragraph"> |
| 2771 | <p>If available on the system, Cockpit uses |
| 2772 | <a href="https://wiki.gnome.org/Projects/NetworkManager">NetworkManager</a> and the |
| 2773 | DBus APIs it provides to interact with the system’s network |
| 2774 | configuration.</p> |
| 2775 | </div> |
| 2776 | <div class="paragraph"> |
| 2777 | <p>For non root users, NetworkManager controls access to its APIs via |
| 2778 | <a href="privileges.html">Policy Kit</a> and a user logged into Cockpit will have |
| 2779 | the same permissions as they do from the command line.</p> |
| 2780 | </div> |
| 2781 | <div class="paragraph"> |
| 2782 | <p>To perform similar tasks from the command line, use the |
| 2783 | <a href="https://fedoraproject.org/wiki/Networking/CLI">nmcli</a> command:</p> |
| 2784 | </div> |
| 2785 | <div class="literalblock"> |
| 2786 | <div class="content"> |
| 2787 | <pre>$ nmcli general status |
| 2788 | STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN |
| 2789 | connected full enabled enabled enabled enabled</pre> |
| 2790 | </div> |
| 2791 | </div> |
| 2792 | <div class="paragraph"> |
| 2793 | <p>Devices marked as "not managed" with the <code>NM_CONTROLLED=no</code> setting |
| 2794 | will not be displayed in the interface.</p> |
| 2795 | </div> |
| 2796 | </div> |
| 2797 | <div class="sect2"> |
| 2798 | <h3 id="feature-firewall">Firewall</h3> |
| 2799 | <div class="paragraph"> |
| 2800 | <p>Cockpit uses <a href="https://www.firewalld.org">firewalld</a> to interact with the |
| 2801 | system’s firewall. No firewall configuration UI will be shown if |
| 2802 | firewalld is not installed.</p> |
| 2803 | </div> |
| 2804 | <div class="paragraph"> |
| 2805 | <p>Firewalld controls access to its APIs via PolicyKit. The user logged |
| 2806 | into Cockpit needs to have the appropriate permissions to view or modify |
| 2807 | the settings.</p> |
| 2808 | </div> |
| 2809 | <div class="paragraph"> |
| 2810 | <p>Cockpit can currently only show, add, and remove predefined firewalld |
| 2811 | services in the default zone.</p> |
| 2812 | </div> |
| 2813 | <div class="paragraph"> |
| 2814 | <p>To perform similar tasks from the command line, use |
| 2815 | <a href="https://www.firewalld.org/documentation/man-pages/firewall-cmd.html">firewall-cmd</a>. |
| 2816 | For example, to get the same list of allowed services that Cockpit |
| 2817 | displays:</p> |
| 2818 | </div> |
| 2819 | <div class="literalblock"> |
| 2820 | <div class="content"> |
| 2821 | <pre>$ sudo firewall-cmd --list-services |
| 2822 | dhcpv6-client samba-client mdns ssh cockpit</pre> |
| 2823 | </div> |
| 2824 | </div> |
| 2825 | <div class="paragraph"> |
| 2826 | <p>To enable an additional service, use:</p> |
| 2827 | </div> |
| 2828 | <div class="literalblock"> |
| 2829 | <div class="content"> |
| 2830 | <pre>$ firewall-cmd --add-service pop3 |
| 2831 | success</pre> |
| 2832 | </div> |
| 2833 | </div> |
| 2834 | </div> |
| 2835 | <div class="sect2"> |
| 2836 | <h3 id="feature-storaged">storaged</h3> |
| 2837 | <div class="paragraph"> |
| 2838 | <p>If available on the system, Cockpit uses |
| 2839 | <a href="https://github.com/storaged-project/storaged/"><code>storaged</code></a> to configure |
| 2840 | and monitor storage, disks, mounts etc. on the system. This |
| 2841 | functionality is present in the Cockpit <em>storaged</em> package.</p> |
| 2842 | </div> |
| 2843 | <div class="paragraph"> |
| 2844 | <p>The <code>storaged</code> project is originally based on a project called |
| 2845 | <a href="https://www.freedesktop.org/wiki/Software/udisks/"><code>udisks</code></a> and added |
| 2846 | support for many more features such as |
| 2847 | <a href="https://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)">LVM</a>, |
| 2848 | <a href="https://en.wikipedia.org/wiki/ISCSI">iSCSI</a>, |
| 2849 | <a href="https://en.wikipedia.org/wiki/Linux_DM_Multipath">Multipath</a>, and |
| 2850 | <a href="https://btrfs.wiki.kernel.org/index.php/Main_Page">BTRFS</a>. The same tools |
| 2851 | and backwards compatible API are available between <code>storaged</code> and |
| 2852 | <code>udisks</code> the projects. Cockpit can use <code>udisks</code> but disables many of |
| 2853 | it’s storage related features, including updating <code>/etc/fstab</code> and |
| 2854 | <code>/etc/crypttab</code> for stability reasons.</p> |
| 2855 | </div> |
| 2856 | <div class="paragraph"> |
| 2857 | <p>For non root users, storaged controls access to its APIs via |
| 2858 | <a href="privileges.html">Policy Kit</a> and a user logged into Cockpit will have |
| 2859 | the same permissions as they do from the command line.</p> |
| 2860 | </div> |
| 2861 | <div class="paragraph"> |
| 2862 | <p>To perform similar tasks from the command line, use the <code>storagedctl</code> |
| 2863 | command:</p> |
| 2864 | </div> |
| 2865 | <div class="literalblock"> |
| 2866 | <div class="content"> |
| 2867 | <pre>$ udisksctl dump |
| 2868 | ...</pre> |
| 2869 | </div> |
| 2870 | </div> |
| 2871 | <div class="paragraph"> |
| 2872 | <p>To perform LVM tasks, you may use the various LVM commands, such as |
| 2873 | <code>vgcreate</code>, <code>lvresize</code> and so on. Cockpit will detect such changes |
| 2874 | made at the command line.</p> |
| 2875 | </div> |
| 2876 | <div class="paragraph"> |
| 2877 | <p>Cockpit recognizes devices with multiple paths and can start the |
| 2878 | <code>multipathd</code> service in case it is not running. On the command line, |
| 2879 | you can control multipath features with the <code>mpathconf</code>, |
| 2880 | <code>multipathd</code>, and <code>multipath</code> commands.</p> |
| 2881 | </div> |
| 2882 | <div class="paragraph"> |
| 2883 | <p>To manage iSCSI initiators from the command line, you can use |
| 2884 | <code>iscsiadm</code> and related tools.</p> |
| 2885 | </div> |
| 2886 | </div> |
| 2887 | <div class="sect2"> |
| 2888 | <h3 id="feature-users">User Tools</h3> |
| 2889 | <div class="paragraph"> |
| 2890 | <p>Cockpit uses the usual tools to create and modify local user accounts. |
| 2891 | Examples are <code>useradd</code>, <code>usermod</code> and <code>passwd</code>. These same tools |
| 2892 | are available for use on the command line.</p> |
| 2893 | </div> |
| 2894 | </div> |
| 2895 | <div class="sect2"> |
| 2896 | <h3 id="feature-realmd">realmd</h3> |
| 2897 | <div class="paragraph"> |
| 2898 | <p>If available on the system, Cockpit uses |
| 2899 | <a href="https://www.freedesktop.org/software/realmd/">realmd</a> and the DBus APIs |
| 2900 | it provides to configure the system’s Active Directory or IPA domain |
| 2901 | membership.</p> |
| 2902 | </div> |
| 2903 | <div class="paragraph"> |
| 2904 | <p>Not all systems can join all kinds of domains. This depends on the |
| 2905 | availability of the necessary client software.</p> |
| 2906 | </div> |
| 2907 | <div class="paragraph"> |
| 2908 | <p>For non root users, realmd controls access to its APIs via |
| 2909 | <a href="privileges.html">Policy Kit</a> and a user logged into Cockpit will have |
| 2910 | the same permissions as they do from the command line.</p> |
| 2911 | </div> |
| 2912 | <div class="paragraph"> |
| 2913 | <p>To perform similar tasks from the command line, use the |
| 2914 | <a href="https://www.freedesktop.org/software/realmd/docs/realm.html">realm</a> |
| 2915 | command:</p> |
| 2916 | </div> |
| 2917 | <div class="literalblock"> |
| 2918 | <div class="content"> |
| 2919 | <pre>$ realm join example.com |
| 2920 | Password for Administrator:</pre> |
| 2921 | </div> |
| 2922 | </div> |
| 2923 | <div class="paragraph"> |
| 2924 | <p><a href="http://www.freedesktop.org/software/realmd/">realmd</a> sets up |
| 2925 | domain-qualified user names by default, i. e. login user names look like |
| 2926 | “[email protected]”. For using unqualified names (just “user”), |
| 2927 | set the <code>fully-qualified-names</code> option in |
| 2928 | <a href="https://www.freedesktop.org/software/realmd/docs/realmd-conf.html">/etc/realmd.conf</a> |
| 2929 | before joining a domain.</p> |
| 2930 | </div> |
| 2931 | <div class="paragraph"> |
| 2932 | <p>Cockpit requests an SSL certificate from the IPA server for |
| 2933 | <code>cockpit-ws</code> with the |
| 2934 | <a href="https://www.freeipa.org/page/Certmonger">ipa-getcert</a> command.</p> |
| 2935 | </div> |
| 2936 | </div> |
| 2937 | <div class="sect2"> |
| 2938 | <h3 id="feature-terminal">Terminal</h3> |
| 2939 | <div class="paragraph"> |
| 2940 | <p>Cockpit provides a standard shell in a terminal. This shell and the |
| 2941 | processes running in it have the <a href="privileges.html">same privileges</a> as if |
| 2942 | the user had logged in via SSH.</p> |
| 2943 | </div> |
| 2944 | </div> |
| 2945 | <div class="sect2"> |
| 2946 | <h3 id="feature-pcp">PCP Metrics</h3> |
| 2947 | <div class="paragraph"> |
| 2948 | <p>If available, Cockpit uses the <a href="https://pcp.io/">Performance Co-Pilot</a> |
| 2949 | framework to gather metrics data about the system. This data is used to |
| 2950 | display the history graphs on the "Metrics and history" page. Cockpit |
| 2951 | can use the PCP logging feature to display archived data about the |
| 2952 | system from a different point in time. If PCP is not available, then |
| 2953 | Cockpit gathers the metrics data itself, but archival features are not |
| 2954 | available.</p> |
| 2955 | </div> |
| 2956 | <div class="paragraph"> |
| 2957 | <p>Whether or not metrics are archived depends on whether the |
| 2958 | <a href="https://linux.die.net/man/1/pmlogger"><code>pmlogger.service</code></a> systemd unit |
| 2959 | is running or not. The "Enable PCP metrics collector" button on the |
| 2960 | Metrics page will enable and start this service.</p> |
| 2961 | </div> |
| 2962 | <div class="paragraph"> |
| 2963 | <p>To see similar metrics data from the command line, you can use tools |
| 2964 | like <a href="https://linux.die.net/man/1/pmstat"><code>pmstat</code></a> or |
| 2965 | <a href="https://linux.die.net/man/1/pminfo"><code>pminfo</code></a>:</p> |
| 2966 | </div> |
| 2967 | <div class="literalblock"> |
| 2968 | <div class="content"> |
| 2969 | <pre>$ pmstat |
| 2970 | @ Sat Sep 26 15:30:10 2015 |
| 2971 | loadavg memory swap io system cpu |
| 2972 | 1 min swpd free buff cache pi po bi bo in cs us sy id |
| 2973 | 4.19 0 20710m 605148 6450m 0 0 0 2548 5688 14K 19 3 76 |
| 2974 | ...</pre> |
| 2975 | </div> |
| 2976 | </div> |
| 2977 | <div class="paragraph"> |
| 2978 | <p>These metrics can also be exposed to other machines on a TCP port with |
| 2979 | <a href="https://linux.die.net/man/1/pmproxy">pmproxy</a> and |
| 2980 | <a href="https://redis.io/">Redis</a> or <a href="https://valkey.io/">Valkey</a>:</p> |
| 2981 | </div> |
| 2982 | <div class="literalblock"> |
| 2983 | <div class="content"> |
| 2984 | <pre>systemctl enable --now redis pmproxy |
| 2985 | # if you use firewalld, open port 44322: |
| 2986 | firewall-cmd --permanent --add-service pmproxy |
| 2987 | firewall-cmd --reload</pre> |
| 2988 | </div> |
| 2989 | </div> |
| 2990 | <div class="paragraph"> |
| 2991 | <p>This allows you to gather and visualize PCP metrics from multiple |
| 2992 | machines with <a href="https://grafana.com/">Grafana</a> and the |
| 2993 | <a href="https://grafana-pcp.readthedocs.io">PCP Grafana plugin</a>.</p> |
| 2994 | </div> |
| 2995 | </div> |
| 2996 | <div class="sect2"> |
| 2997 | <h3 id="feature-machines">Multiple Machines</h3> |
| 2998 | <div class="admonitionblock warning"> |
| 2999 | <table> |
| 3000 | <tr> |
| 3001 | <td class="icon"> |
| 3002 | <div class="title">Warning</div> |
| 3003 | </td> |
| 3004 | <td class="content"> |
| 3005 | <div class="paragraph"> |
| 3006 | <p>This feature is deprecated as of Cockpit 322.</p> |
| 3007 | </div> |
| 3008 | </td> |
| 3009 | </tr> |
| 3010 | </table> |
| 3011 | </div> |
| 3012 | <div class="paragraph"> |
| 3013 | <p>Cockpit can connect to multiple machines from a single Cockpit session. |
| 3014 | These are listed in the host switcher.</p> |
| 3015 | </div> |
| 3016 | <div class="paragraph"> |
| 3017 | <p>These additional machines are accessed via SSH from the machine that the |
| 3018 | first machine connected to, and are <a href="authentication.html">authenticated</a> |
| 3019 | with the logged in user’s password and/or SSH keys.</p> |
| 3020 | </div> |
| 3021 | <div class="paragraph"> |
| 3022 | <p>SSH host keys are stored in <code>/etc/ssh/ssh_known_hosts</code>.</p> |
| 3023 | </div> |
| 3024 | <div class="paragraph"> |
| 3025 | <p>The machine data is stored in <code>/etc/cockpit/machines.d/*.json</code>, or |
| 3026 | below <code>$XDG_CONFIG_DIRS</code> if set (see |
| 3027 | <a href="./cockpit.conf.5.html">cockpit.conf</a>). Settings in lexicographically |
| 3028 | later files amend or override settings in earlier ones. Cockpit itself |
| 3029 | writes into <code>99-webui.json</code>; packages or admins who want to |
| 3030 | pre-configure machines should ship files like <code>05-mymachine.json</code> so |
| 3031 | that changes from the web interface override the pre-configured files.</p> |
| 3032 | </div> |
| 3033 | <div class="paragraph"> |
| 3034 | <p>Each JSON file contains an object that maps machine IDs to objects that |
| 3035 | define the properties of that machine. The ID can be a human readable |
| 3036 | name or an IP address or any other unique value, and is shown in the web |
| 3037 | interface until connecting to it the first time, at which point the web |
| 3038 | interface will show the machine’s host name.</p> |
| 3039 | </div> |
| 3040 | <div class="paragraph"> |
| 3041 | <p>The following properties are recognized:</p> |
| 3042 | </div> |
| 3043 | <div class="dlist"> |
| 3044 | <dl> |
| 3045 | <dt class="hdlist1"><code>"address"</code></dt> |
| 3046 | <dd> |
| 3047 | <p><em>(string, mandatory)</em> IP address or DNS name of the machine</p> |
| 3048 | </dd> |
| 3049 | <dt class="hdlist1"><code>"visible"</code></dt> |
| 3050 | <dd> |
| 3051 | <p><em>(boolean, optional)</em> If <code>true</code>, the machine will be displayed and |
| 3052 | available for managing with Cockpit. If <code>false</code> (the default), it |
| 3053 | will not be displayed, but still taken into account for type-ahead |
| 3054 | search when adding new machines in the web interface.</p> |
| 3055 | </dd> |
| 3056 | <dt class="hdlist1"><code>"user"</code></dt> |
| 3057 | <dd> |
| 3058 | <p><em>(string, optional)</em> User name on the remote machine. When not given, |
| 3059 | Cockpit will default to the user name that was being used to log into |
| 3060 | Cockpit itself.</p> |
| 3061 | </dd> |
| 3062 | <dt class="hdlist1"><code>"port"</code></dt> |
| 3063 | <dd> |
| 3064 | <p><em>(integer, optional)</em> ssh port of the remote machine. When not given, |
| 3065 | the default port 22 is used.</p> |
| 3066 | </dd> |
| 3067 | <dt class="hdlist1"><code>"color"</code></dt> |
| 3068 | <dd> |
| 3069 | <p><em>(string, optional)</em> Color to assign to the machine label in the web |
| 3070 | interface. This can be either given as |
| 3071 | <code>rgb(r_value, g_value, b_value)</code> with each value being an integer |
| 3072 | between 0 and 255, or as a color name like <code>yellow</code>. When not given, |
| 3073 | Cockpit will assign an unused color automatically.</p> |
| 3074 | </dd> |
| 3075 | </dl> |
| 3076 | </div> |
| 3077 | <div class="paragraph"> |
| 3078 | <p>Example:</p> |
| 3079 | </div> |
| 3080 | <div class="literalblock"> |
| 3081 | <div class="content"> |
| 3082 | <pre>{ |
| 3083 | "web server": { |
| 3084 | "address": "192.168.2.4", |
| 3085 | "visible": true, |
| 3086 | "color": "rgb(100, 200, 0)", |
| 3087 | "user": "admin" |
| 3088 | }, |
| 3089 | "192.168.2.1": { |
| 3090 | "address": "192.168.2.1", |
| 3091 | "port": 2222, |
| 3092 | "visible": true, |
| 3093 | "color": "green" |
| 3094 | } |
| 3095 | }</pre> |
| 3096 | </div> |
| 3097 | </div> |
| 3098 | </div> |
| 3099 | <div class="sect2"> |
| 3100 | <h3 id="feature-selinux">SELinux Policy</h3> |
| 3101 | <div class="paragraph"> |
| 3102 | <p>If present on the system Cockpit can set the SELinux mode to enforcing |
| 3103 | or permissive. It can also use <code>setroubleshootd</code> to show audit issues |
| 3104 | and apply suggested fixes.</p> |
| 3105 | </div> |
| 3106 | <div class="paragraph"> |
| 3107 | <p>To perform similar tasks from the command line use the <code>setenforce</code> |
| 3108 | and <code>sealert</code> tools.</p> |
| 3109 | </div> |
| 3110 | <div class="paragraph"> |
| 3111 | <p>To clear out all the information that <code>setroubleshootd</code> tracks, you |
| 3112 | can use a commands like:</p> |
| 3113 | </div> |
| 3114 | <div class="literalblock"> |
| 3115 | <div class="content"> |
| 3116 | <pre>$ sudo killall setroubleshootd |
| 3117 | $ sudo rm -rf /var/lib/setroubleshoot/*</pre> |
| 3118 | </div> |
| 3119 | </div> |
| 3120 | </div> |
| 3121 | <div class="sect2"> |
| 3122 | <h3 id="feature-tuned">Tuned Profiles</h3> |
| 3123 | <div class="paragraph"> |
| 3124 | <p>If present on the system Cockpit can use Tuned and the DBUS API it |
| 3125 | provides to set system performance profiles. To perform similar tasks |
| 3126 | from the command line, use the <code>tuned-adm</code> command.</p> |
| 3127 | </div> |
| 3128 | </div> |
| 3129 | <div class="sect2"> |
| 3130 | <h3 id="feature-sosreport">SOS Report</h3> |
| 3131 | <div class="paragraph"> |
| 3132 | <p>If present on the system Cockpit can use <code>sosreport</code> to collect system |
| 3133 | configuration and diagnostic information.</p> |
| 3134 | </div> |
| 3135 | <div class="paragraph"> |
| 3136 | <p>To perform similar tasks from the command line, use the <code>sosreport</code> |
| 3137 | command.</p> |
| 3138 | </div> |
| 3139 | </div> |
| 3140 | <div class="sect2"> |
| 3141 | <h3 id="feature-packagekit">Package Updates</h3> |
| 3142 | <div class="paragraph"> |
| 3143 | <p>Cockpit uses the |
| 3144 | <a href="https://www.freedesktop.org/software/PackageKit/gtk-doc/api-reference.html">PackageKit</a> |
| 3145 | D-Bus API to get information about available package updates and to |
| 3146 | apply them, in an Operating System independent manner.</p> |
| 3147 | </div> |
| 3148 | <div class="paragraph"> |
| 3149 | <p>To perform similar tasks from the command line, use the |
| 3150 | <a href="https://www.freedesktop.org/software/PackageKit/pk-using.html">pkcon</a> |
| 3151 | command:</p> |
| 3152 | </div> |
| 3153 | <div class="literalblock"> |
| 3154 | <div class="content"> |
| 3155 | <pre>$ pkcon refresh |
| 3156 | |
| 3157 | $ pkcon get-updates |
| 3158 | Available sudo-1.8.20p2-1.fc26.x86_64 (updates-testing) |
| 3159 | Allows restricted root access for specified users |
| 3160 | Available vim-filesystem-2:8.0.617-1.fc26.x86_64 (updates-testing) |
| 3161 | VIM filesystem layout |
| 3162 | Available vim-minimal-2:8.0.617-1.fc26.x86_64 (updates-testing) |
| 3163 | A minimal version of the VIM editor |
| 3164 | |
| 3165 | $ pkcon get-update-detail sudo |
| 3166 | Details about the update:6.x86_64 [fedora] |
| 3167 | Package: sudo-1.8.20p2-1.fc26.x86_64 |
| 3168 | Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1452941 |
| 3169 | Update text: - update to 1.8.20p2 |
| 3170 | - added sudo package to dnf/yum protected packages |
| 3171 | |
| 3172 | $ pkcon update |
| 3173 | The following packages have to be updated: |
| 3174 | sudo-1.8.20p2-1.fc26.x86_64 Allows restricted root access for specified users |
| 3175 | vim-filesystem-2:8.0.617-1.fc26.x86_64 VIM filesystem layout |
| 3176 | vim-minimal-2:8.0.617-1.fc26.x86_64 A minimal version of the VIM editor |
| 3177 | Proceed with changes? [N/y] y |
| 3178 | [...]</pre> |
| 3179 | </div> |
| 3180 | </div> |
| 3181 | <div class="paragraph"> |
| 3182 | <p>Of course you can also use your Operating System specific commands for |
| 3183 | that, such as <code>dnf updateinfo info</code> on Fedora or <code>sudo apt upgrade</code> |
| 3184 | on Debian.</p> |
| 3185 | </div> |
| 3186 | </div> |
| 3187 | </div> |
| 3188 | </div> |
| 3189 | <div class="sect1"> |
| 3190 | <h2 id="development">Developer Guide</h2> |
| 3191 | <div class="sectionbody"> |
| 3192 | <div class="sect2"> |
| 3193 | <h3 id="embedding">Embedding and Integrating Cockpit</h3> |
| 3194 | <div class="paragraph"> |
| 3195 | <p>Cockpit can be embedded in other web applications either as a whole or |
| 3196 | specific Cockpit components can be integrated. Due to frame security |
| 3197 | policy restrictions, this only works if Cockpit and the web application |
| 3198 | have the <em>same origin</em>; this is commonly achieved by running both from a |
| 3199 | common reverse proxy.</p> |
| 3200 | </div> |
| 3201 | <div class="sect3"> |
| 3202 | <h4 id="embedding-full">Embedding the Cockpit Interface</h4> |
| 3203 | <div class="paragraph"> |
| 3204 | <p>Cockpit can be embedded into a larger web page as a frame. To embed the |
| 3205 | entire Cockpit Window use the URI: <code>https://server.example.com:9090/</code></p> |
| 3206 | </div> |
| 3207 | <div class="listingblock"> |
| 3208 | <div class="content"> |
| 3209 | <pre class="highlight"><code class="language-html" data-lang="html"><html> |
| 3210 | <head> |
| 3211 | <title>Embedded Cockpit</title> |
| 3212 | </head> |
| 3213 | <body> |
| 3214 | This is Cockpit. |
| 3215 | <br/> |
| 3216 | <iframe width="800px" height="600px" |
| 3217 | src="https://server.example.com:9090/"/> |
| 3218 | </body> |
| 3219 | </html></code></pre> |
| 3220 | </div> |
| 3221 | </div> |
| 3222 | </div> |
| 3223 | <div class="sect3"> |
| 3224 | <h4 id="embedding-components">Integrating Cockpit Components into Web Applications</h4> |
| 3225 | <div class="paragraph"> |
| 3226 | <p>Instead of embedding the entirety of Cockpit, you can integrate specific |
| 3227 | components. Only those components explicitly documented as API should be |
| 3228 | integrated. Other components can and will change regularly.</p> |
| 3229 | </div> |
| 3230 | <div class="paragraph"> |
| 3231 | <p>The component will load from the server in question and a WebSocket |
| 3232 | connection will be established with the server to relay the component’s |
| 3233 | message stream.</p> |
| 3234 | </div> |
| 3235 | <div class="paragraph"> |
| 3236 | <p>Cockpit components are HTML files contained in <a href="packages.html">packages</a>. |
| 3237 | These can be placed in an iframe or web browser window. Each documented |
| 3238 | and stable component has a well-known URL and these are documented in |
| 3239 | the <a href="development.html">API reference</a>. Each component URL begins with the |
| 3240 | string <code>/cockpit/@localhost/</code> followed a package name, and then the |
| 3241 | component itself.</p> |
| 3242 | </div> |
| 3243 | <div class="paragraph"> |
| 3244 | <p>For example the <a href="api-terminal-html.html">terminal.html</a> in the |
| 3245 | <a href="api-system.html">system</a> package, has this URL: |
| 3246 | <code>/cockpit/@localhost/system/terminal.html</code></p> |
| 3247 | </div> |
| 3248 | <div class="listingblock"> |
| 3249 | <div class="content"> |
| 3250 | <pre class="highlight"><code class="language-html" data-lang="html"><html> |
| 3251 | <head> |
| 3252 | <title>Embedded Terminal</title> |
| 3253 | </head> |
| 3254 | <body> |
| 3255 | This is a terminal. |
| 3256 | <br/> |
| 3257 | <iframe width="800px" height="600px" |
| 3258 | src="https://server.example.com:9090/cockpit/@localhost/system/terminal.html"/> |
| 3259 | </body> |
| 3260 | </html></code></pre> |
| 3261 | </div> |
| 3262 | </div> |
| 3263 | </div> |
| 3264 | <div class="sect3"> |
| 3265 | <h4 id="embedding-deep">Deep Integration</h4> |
| 3266 | <div class="paragraph"> |
| 3267 | <p>Most often <a href="#embedding-components">simple integration</a> will be used |
| 3268 | to bring Cockpit components into web applications. However it is also |
| 3269 | possible to do deep integration for embedders who wish to perform |
| 3270 | non-standard authentication with the server, and relay the component’s |
| 3271 | message stream to the server themselves.</p> |
| 3272 | </div> |
| 3273 | <div class="admonitionblock warning"> |
| 3274 | <table> |
| 3275 | <tr> |
| 3276 | <td class="icon"> |
| 3277 | <div class="title">Warning</div> |
| 3278 | </td> |
| 3279 | <td class="content"> |
| 3280 | <div class="paragraph"> |
| 3281 | <p>Deep integration capability is in heavy flux and is not yet documented.</p> |
| 3282 | </div> |
| 3283 | </td> |
| 3284 | </tr> |
| 3285 | </table> |
| 3286 | </div> |
| 3287 | </div> |
| 3288 | <div class="sect3"> |
| 3289 | <h4 id="embedding-cors">Pinging Cockpit</h4> |
| 3290 | <div class="paragraph"> |
| 3291 | <p>When embedding Cockpit or integrating Cockpit components, it may be |
| 3292 | necessary to check whether Cockpit is available on a server before |
| 3293 | proceeding.</p> |
| 3294 | </div> |
| 3295 | <div class="paragraph"> |
| 3296 | <p>To do this perform a <code>/ping</code> request to Cockpit. This is a simple HTTP |
| 3297 | GET request. It returns the following:</p> |
| 3298 | </div> |
| 3299 | <div class="literalblock"> |
| 3300 | <div class="content"> |
| 3301 | <pre>GET: https://server.example.com:9090/ping |
| 3302 | 200 OK: { "service": "cockpit" }</pre> |
| 3303 | </div> |
| 3304 | </div> |
| 3305 | <div class="paragraph"> |
| 3306 | <p>The <code>/ping</code> request allows |
| 3307 | <a href="https://en.wikipedia.org/wiki/Cross-origin_resource_sharing">Cross Origin |
| 3308 | Resource Sharing</a> headers and as such can be performed from Javascript |
| 3309 | code with any origin. The request can also be made via plain HTTP |
| 3310 | without SSL. It is by design that no further information is present in |
| 3311 | the response.</p> |
| 3312 | </div> |
| 3313 | <div class="paragraph"> |
| 3314 | <p>A complete example of using <code>/ping</code> is available in the Cockpit |
| 3315 | sources in the <code>/examples/ping-server/</code> directory.</p> |
| 3316 | </div> |
| 3317 | </div> |
| 3318 | </div> |
| 3319 | <div class="sect2"> |
| 3320 | <h3 id="packages">Cockpit Packages</h3> |
| 3321 | <div class="paragraph"> |
| 3322 | <p>Cockpit is separated into various packages, each of which brings |
| 3323 | specific features and/or code.</p> |
| 3324 | </div> |
| 3325 | <div class="admonitionblock warning"> |
| 3326 | <table> |
| 3327 | <tr> |
| 3328 | <td class="icon"> |
| 3329 | <div class="title">Warning</div> |
| 3330 | </td> |
| 3331 | <td class="content"> |
| 3332 | <div class="paragraph"> |
| 3333 | <p>In addition, any APIs or behavior not explicitly documented here is an |
| 3334 | internal API and can be changed at any time.</p> |
| 3335 | </div> |
| 3336 | </td> |
| 3337 | </tr> |
| 3338 | </table> |
| 3339 | </div> |
| 3340 | <div class="sect3"> |
| 3341 | <h4 id="package-layout">Layout of Package Files</h4> |
| 3342 | <div class="paragraph"> |
| 3343 | <p>A package consists of one or more files placed in a directory or its |
| 3344 | subdirectories. It must have a <code>manifest.json</code> file and follow certain |
| 3345 | naming conventions.</p> |
| 3346 | </div> |
| 3347 | <div class="paragraph"> |
| 3348 | <p>The name of a package is the name of the directory.</p> |
| 3349 | </div> |
| 3350 | <div class="paragraph"> |
| 3351 | <p>The name of the package must be ASCII alphanumeric, and may contain an |
| 3352 | underscore. Names of directories and files in the package must consist |
| 3353 | of ASCII alphanumeric along with dash, underscore, dot, and comma. No |
| 3354 | spaces are allowed.</p> |
| 3355 | </div> |
| 3356 | <div class="paragraph"> |
| 3357 | <p>Cockpit uses the data directories from the |
| 3358 | <a href="https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG |
| 3359 | Base Directory Specification</a> to locate packages. The <code>$XDG_DATA_DIRS</code> |
| 3360 | represents a colon separate list of system data directories, and |
| 3361 | <code>$XDG_DATA_HOME</code> is a user specific data directory. If the environment |
| 3362 | variables are not set, defaults are used, according to the spec. If |
| 3363 | cockpit has been built with an alternate <code>--prefix=/path</code> then the |
| 3364 | <code>$prefix/share/cockpit</code> is used by default.</p> |
| 3365 | </div> |
| 3366 | <div class="paragraph"> |
| 3367 | <p>A <code>cockpit/</code> subdirectories in any of these data directories is the |
| 3368 | location where packages are loaded by Cockpit. If Cockpit finds a |
| 3369 | package with the same name, in multiple data directories, then the first |
| 3370 | one wins. According to the spec the first data directory is |
| 3371 | <code>$XDG_DATA_HOME</code> and then <code>$XDG_DATA_DIRS</code> in order.</p> |
| 3372 | </div> |
| 3373 | <div class="paragraph"> |
| 3374 | <p>This means that, by default the following directories are searched for |
| 3375 | cockpit packages, and in this order:</p> |
| 3376 | </div> |
| 3377 | <div class="ulist"> |
| 3378 | <ul> |
| 3379 | <li> |
| 3380 | <p><code>~/.local/share/cockpit/</code></p> |
| 3381 | </li> |
| 3382 | <li> |
| 3383 | <p><code>/usr/local/share/cockpit/</code></p> |
| 3384 | </li> |
| 3385 | <li> |
| 3386 | <p><code>/usr/share/cockpit/</code></p> |
| 3387 | </li> |
| 3388 | </ul> |
| 3389 | </div> |
| 3390 | <div class="paragraph"> |
| 3391 | <p>Packages placed in <code>$XDG_DATA_HOME</code> are not cached by Cockpit or the |
| 3392 | web browser. Other packages are cached aggressively, and are accessed |
| 3393 | using a checksum of the files in the packages and their names.</p> |
| 3394 | </div> |
| 3395 | <div class="paragraph"> |
| 3396 | <p>You can use the following command to list the packages installed on a |
| 3397 | server. You’ll note that it’s output may change when you run the command |
| 3398 | as different users, if there are packages installed in the user’s home |
| 3399 | directory.</p> |
| 3400 | </div> |
| 3401 | <div class="literalblock"> |
| 3402 | <div class="content"> |
| 3403 | <pre>$ cockpit-bridge --packages |
| 3404 | ...</pre> |
| 3405 | </div> |
| 3406 | </div> |
| 3407 | <div class="paragraph"> |
| 3408 | <p>To further clarify things, here is an example package called |
| 3409 | "my-package" and its file layout:</p> |
| 3410 | </div> |
| 3411 | <div class="literalblock"> |
| 3412 | <div class="content"> |
| 3413 | <pre>/usr/share/cockpit/ |
| 3414 | my-package/ |
| 3415 | manifest.json |
| 3416 | file.html |
| 3417 | some.js</pre> |
| 3418 | </div> |
| 3419 | </div> |
| 3420 | <div class="paragraph"> |
| 3421 | <p>Place or symlink packages in your <code>~/.local/share/cockpit</code> directory |
| 3422 | (or appropriate <code>$XDG_DATA_HOME</code> location) that you would like to |
| 3423 | modify and develop. System installed packages should not change while |
| 3424 | Cockpit is running.</p> |
| 3425 | </div> |
| 3426 | </div> |
| 3427 | <div class="sect3"> |
| 3428 | <h4 id="_package_manifest">Package Manifest</h4> |
| 3429 | <div class="paragraph"> |
| 3430 | <p>Each package has a <code>manifest.json</code> file. It is a JSON object. The |
| 3431 | following fields may be present in the manifest:</p> |
| 3432 | </div> |
| 3433 | <div class="dlist"> |
| 3434 | <dl> |
| 3435 | <dt class="hdlist1">content-security-policy</dt> |
| 3436 | <dd> |
| 3437 | <p>By default Cockpit serves packages using a strict |
| 3438 | <a href="https://en.wikipedia.org/wiki/Content_Security_Policy">Content Security |
| 3439 | Policy</a>, which among other things does not allow inline styles or |
| 3440 | scripts. This can be overridden on a per-package basis, with this |
| 3441 | setting. |
| 3442 | + |
| 3443 | If the overridden content security policy does not contain a |
| 3444 | <code>default-src</code>, <code>connect-src</code>, <code>base-uri</code>, <code>form-action</code>, |
| 3445 | <code>object-src</code>, or <code>block-all-mixed-content</code> then these will be |
| 3446 | added to the policy from the manifest.</p> |
| 3447 | </dd> |
| 3448 | <dt class="hdlist1">name</dt> |
| 3449 | <dd> |
| 3450 | <p>An optional string that changes the name of the package. Normally |
| 3451 | packages derive their name from the directory that they are located |
| 3452 | in. This field overrides that name.</p> |
| 3453 | </dd> |
| 3454 | <dt class="hdlist1">priority</dt> |
| 3455 | <dd> |
| 3456 | <p>An optional integer that specifies which package is preferred in cases |
| 3457 | where there are conflicts. For example given two packages with the |
| 3458 | same <code>name</code> a package is chosen based on its priority. A higher integer |
| 3459 | means higher priority.</p> |
| 3460 | </dd> |
| 3461 | <dt class="hdlist1">conditions</dt> |
| 3462 | <dd> |
| 3463 | <p>An optional list of <code>{"predicate": "value"}</code> objects. Cockpit will |
| 3464 | only consider the package if <em>all</em> conditions are met. This is |
| 3465 | preferable to using <code>priority</code>.<br> |
| 3466 | <br> |
| 3467 | Currently supported predicates are <code>path-exists</code> and <code>path-not-exists</code> |
| 3468 | (since Cockpit 286) and <code>any</code> (since Cockpit 348). <code>any</code> accepts a |
| 3469 | list of conditions and evaluates to true if <em>at least one</em> of the nested |
| 3470 | conditions is met. Unknown predicates are ignored.</p> |
| 3471 | </dd> |
| 3472 | <dt class="hdlist1">requires</dt> |
| 3473 | <dd> |
| 3474 | <p>An optional JSON object that contains a <code>"cockpit"</code> string version |
| 3475 | number. The package will only be usable if the Cockpit bridge and |
| 3476 | javascript base are equal or newer than the given version number.</p> |
| 3477 | </dd> |
| 3478 | <dt class="hdlist1">version</dt> |
| 3479 | <dd> |
| 3480 | <p>An informational version number for the package.</p> |
| 3481 | </dd> |
| 3482 | <dt class="hdlist1">preload</dt> |
| 3483 | <dd> |
| 3484 | <p>A list of identifiers of the components that should be preloaded. |
| 3485 | Normally, the files of a component are loaded when the user navigates |
| 3486 | to it for the first time. The files of a preloaded component are |
| 3487 | loaded immediately after the user logs in, and the initialization code |
| 3488 | of the component is invoked. |
| 3489 | + |
| 3490 | The value of this field is an array of strings, where each string is |
| 3491 | one of the keys used in the <code>dashboard</code>, <code>menu</code>, or <code>tools</code> |
| 3492 | fields that are explained below.</p> |
| 3493 | </dd> |
| 3494 | <dt class="hdlist1">parent</dt> |
| 3495 | <dd> |
| 3496 | <p>This option is used when module does not have its own menu item but is |
| 3497 | a part of a different module. This is described by JSON object with |
| 3498 | properties <code>component</code> which takes name of the superordinate |
| 3499 | component and <code>docs</code> with list of documentation URLs for the given |
| 3500 | page. See below for structure of <code>docs</code> property.</p> |
| 3501 | </dd> |
| 3502 | </dl> |
| 3503 | </div> |
| 3504 | <div class="paragraph"> |
| 3505 | <p>In addition, the following keys contain information about where |
| 3506 | components of the package should appear in Cockpit’s user interface. |
| 3507 | Each of these keys is optional and contains an object mapping unique |
| 3508 | identifiers to menu items, which are described below. (The naming of |
| 3509 | these fields doesn’t perfectly match the current user interface for |
| 3510 | historical reasons.)</p> |
| 3511 | </div> |
| 3512 | <div class="dlist"> |
| 3513 | <dl> |
| 3514 | <dt class="hdlist1">dashboard</dt> |
| 3515 | <dd> |
| 3516 | <p>Dashboard items appear in the menu under the section <em>Apps</em>.</p> |
| 3517 | </dd> |
| 3518 | <dt class="hdlist1">menu</dt> |
| 3519 | <dd> |
| 3520 | <p>These items appear in the menu under the section <em>System</em>. This |
| 3521 | section is roughly ordered into these categories (with their <em>order</em> |
| 3522 | in parentheses): |
| 3523 | +</p> |
| 3524 | <div class="ulist"> |
| 3525 | <ul> |
| 3526 | <li> |
| 3527 | <p>System Information (10)</p> |
| 3528 | </li> |
| 3529 | <li> |
| 3530 | <p>Logs (20)</p> |
| 3531 | </li> |
| 3532 | <li> |
| 3533 | <p>Configuring major subsystems (30-40)</p> |
| 3534 | </li> |
| 3535 | <li> |
| 3536 | <p>Things running on the machine (VMs, Containers - 50-60)</p> |
| 3537 | </li> |
| 3538 | <li> |
| 3539 | <p>Implementation Details (Accounts, Services - 70-100)</p> |
| 3540 | </li> |
| 3541 | </ul> |
| 3542 | </div> |
| 3543 | </dd> |
| 3544 | <dt class="hdlist1">tools</dt> |
| 3545 | <dd> |
| 3546 | <p>These items appear in the menu under the section <em>Tools</em>.</p> |
| 3547 | </dd> |
| 3548 | </dl> |
| 3549 | </div> |
| 3550 | <div class="paragraph"> |
| 3551 | <p>Menu items and tools are registered using JSON objects that have the |
| 3552 | following properties:</p> |
| 3553 | </div> |
| 3554 | <div class="dlist"> |
| 3555 | <dl> |
| 3556 | <dt class="hdlist1">label</dt> |
| 3557 | <dd> |
| 3558 | <p>The label for the menu item or tool.</p> |
| 3559 | </dd> |
| 3560 | <dt class="hdlist1">order</dt> |
| 3561 | <dd> |
| 3562 | <p>An optional order integer to place this menu item or tool. Lower |
| 3563 | integers are listed first.</p> |
| 3564 | </dd> |
| 3565 | <dt class="hdlist1">path</dt> |
| 3566 | <dd> |
| 3567 | <p>The relative path to the HTML file within the package that implements |
| 3568 | the menu item or tool.</p> |
| 3569 | </dd> |
| 3570 | <dt class="hdlist1">docs</dt> |
| 3571 | <dd> |
| 3572 | <p>List of documentation URLs for the given page. Each item is an object |
| 3573 | containing <code>label</code> and <code>url</code>.</p> |
| 3574 | </dd> |
| 3575 | <dt class="hdlist1">keywords</dt> |
| 3576 | <dd> |
| 3577 | <p>Keywords that describe the page and which are used for searching. |
| 3578 | These keywords should be lowercase. Keywords is a list containing |
| 3579 | keyword items as described below. Page label is prepended as first |
| 3580 | keyword in the first keyword item.</p> |
| 3581 | </dd> |
| 3582 | </dl> |
| 3583 | </div> |
| 3584 | <div class="paragraph"> |
| 3585 | <p>Keyword items are registered using JSON objects that have the following |
| 3586 | properties:</p> |
| 3587 | </div> |
| 3588 | <div class="dlist"> |
| 3589 | <dl> |
| 3590 | <dt class="hdlist1">matches</dt> |
| 3591 | <dd> |
| 3592 | <p>List of keywords to be matched.</p> |
| 3593 | </dd> |
| 3594 | <dt class="hdlist1">goto</dt> |
| 3595 | <dd> |
| 3596 | <p>Optional path that is used for all keywords in this item. When this |
| 3597 | argument starts with slash, then it is used as pathname, otherwise it |
| 3598 | is used as hash. Defining <code>goto:"page_hash"</code> in page with |
| 3599 | <code>path:"/page_path"</code> would redirect to <code>/page_path#page_hash</code>, |
| 3600 | while <code>goto:"/page_path"</code> would redirect to <code>/page_path</code> ignoring |
| 3601 | default page path.</p> |
| 3602 | </dd> |
| 3603 | <dt class="hdlist1">weight</dt> |
| 3604 | <dd> |
| 3605 | <p>How much keywords are prioritized over others. Default is 3.</p> |
| 3606 | </dd> |
| 3607 | <dt class="hdlist1">translate</dt> |
| 3608 | <dd> |
| 3609 | <p><code>false</code> when keywords should not be localized. Default is <code>true</code>.</p> |
| 3610 | </dd> |
| 3611 | </dl> |
| 3612 | </div> |
| 3613 | <div class="paragraph"> |
| 3614 | <p>An example manifest.json with some optional properties set:</p> |
| 3615 | </div> |
| 3616 | <div class="literalblock"> |
| 3617 | <div class="content"> |
| 3618 | <pre>{ |
| 3619 | "version": 0, |
| 3620 | "require": { |
| 3621 | "cockpit": "120" |
| 3622 | }, |
| 3623 | "tools": { |
| 3624 | "mytool": { |
| 3625 | "label": "My Tool", |
| 3626 | "path": "tool.html" |
| 3627 | } |
| 3628 | } |
| 3629 | }</pre> |
| 3630 | </div> |
| 3631 | </div> |
| 3632 | <div class="literalblock"> |
| 3633 | <div class="content"> |
| 3634 | <pre>{ |
| 3635 | "version": 0, |
| 3636 | "require": { |
| 3637 | "cockpit": "120" |
| 3638 | }, |
| 3639 | "conditions": [ |
| 3640 | {"path-exists": "/usr/bin/mytool"}, |
| 3641 | {"path-exists": "/etc/mytool.conf"}, |
| 3642 | {"path-not-exist": "/etc/incompatible-tool"} |
| 3643 | ], |
| 3644 | "tools": { |
| 3645 | "mytool": { |
| 3646 | "label": "My Tool", |
| 3647 | "path": "tool.html" |
| 3648 | } |
| 3649 | } |
| 3650 | }</pre> |
| 3651 | </div> |
| 3652 | </div> |
| 3653 | <div class="paragraph"> |
| 3654 | <p>The following example shows how to use disjunctive conditions with <code>any</code> |
| 3655 | to specify alternative requirements (available since Cockpit 348). This |
| 3656 | package will be available if either <code>/usr/bin/alt1</code> or <code>/usr/bin/alt2</code> |
| 3657 | exists. In any case, <code>/etc/incompatible-tool</code> must not exist.</p> |
| 3658 | </div> |
| 3659 | <div class="literalblock"> |
| 3660 | <div class="content"> |
| 3661 | <pre>"conditions": [ |
| 3662 | {"any": [{"path-exists": "/usr/bin/alt1"}, {"path-exists": "/usr/bin/alt2"}]}, |
| 3663 | {"path-not-exists": "/etc/incompatible-tool"} |
| 3664 | ]</pre> |
| 3665 | </div> |
| 3666 | </div> |
| 3667 | </div> |
| 3668 | <div class="sect3"> |
| 3669 | <h4 id="package-manifest-override">Manifest overrides</h4> |
| 3670 | <div class="paragraph"> |
| 3671 | <p>To change a manifest system-wide, a file |
| 3672 | <code><package-directory-name>.override.json</code> may be placed into |
| 3673 | <code>/etc/cockpit/</code>, or below <code>$XDG_CONFIG_DIRS</code> if set (see |
| 3674 | <a href="./cockpit.conf.5.html">cockpit.conf</a>). To change it for a particular |
| 3675 | user only, put the override into <code>~/.config/cockpit</code>.</p> |
| 3676 | </div> |
| 3677 | <div class="paragraph"> |
| 3678 | <p>These override the information in the manifest in the simple |
| 3679 | <a href="https://tools.ietf.org/html/rfc7386">JSON Merge Patch</a> format.</p> |
| 3680 | </div> |
| 3681 | <div class="paragraph"> |
| 3682 | <p>This can be used to hide or modify menu items of an existing package. |
| 3683 | For example <code>/etc/cockpit/systemd.override.json</code> or |
| 3684 | <code>~/.config/cockpit/systemd.override.json</code> could hide the <em>Logs</em> menu |
| 3685 | item and move the <em>Services</em> menu item to the top of the menu.</p> |
| 3686 | </div> |
| 3687 | <div class="literalblock"> |
| 3688 | <div class="content"> |
| 3689 | <pre>{ |
| 3690 | "menu": { |
| 3691 | "logs": null, |
| 3692 | "services": { |
| 3693 | "order": -1 |
| 3694 | } |
| 3695 | } |
| 3696 | }</pre> |
| 3697 | </div> |
| 3698 | </div> |
| 3699 | </div> |
| 3700 | <div class="sect3"> |
| 3701 | <h4 id="package-links">Package Links and Paths</h4> |
| 3702 | <div class="paragraph"> |
| 3703 | <p>When referring to files in your package, such as in a hyperlink or a |
| 3704 | <code><style></code> tag or <code><script></code> tag, simply use a relative path, and |
| 3705 | refer to the files in the same directory. When you need to refer to |
| 3706 | files in another package use a relative link.</p> |
| 3707 | </div> |
| 3708 | <div class="paragraph"> |
| 3709 | <p>For example here’s how to include the base <code>cockpit.js</code> script in your |
| 3710 | HTML from the <code>latest</code> package:</p> |
| 3711 | </div> |
| 3712 | <div class="literalblock"> |
| 3713 | <div class="content"> |
| 3714 | <pre><script src="../base1/cockpit.js"></script></pre> |
| 3715 | </div> |
| 3716 | </div> |
| 3717 | <div class="paragraph"> |
| 3718 | <p>Do not assume you can link to any file in any other package. Refer to |
| 3719 | the <a href="development.html">list of API packages</a> for those that are available |
| 3720 | for use.</p> |
| 3721 | </div> |
| 3722 | </div> |
| 3723 | <div class="sect3"> |
| 3724 | <h4 id="package-minified">Content Negotiation</h4> |
| 3725 | <div class="paragraph"> |
| 3726 | <p>In order to support gzipped and/or minified data, the files in a package |
| 3727 | are loaded using content negotiation logic. A HTTP request for the file |
| 3728 | <code>test.js</code> in the package named <code>mypackage</code> will return |
| 3729 | <code>mypackage/test.js</code> or <code>mypackage/test.js.gz</code> (in undefined |
| 3730 | preference). If neither exists, then it returns |
| 3731 | <code>mypackage/test.js.min</code> or <code>mypackage/test.js.min.gz</code> (again in |
| 3732 | undefined preference).</p> |
| 3733 | </div> |
| 3734 | <div class="paragraph"> |
| 3735 | <p>When packages are loaded from a system directory, Cockpit optimizes the |
| 3736 | file system lookups above, by pre-listing the files. This is one of the |
| 3737 | reasons that you should never change packages installed to a system |
| 3738 | directory while Cockpit is running.</p> |
| 3739 | </div> |
| 3740 | </div> |
| 3741 | <div class="sect3"> |
| 3742 | <h4 id="package-api">Using Cockpit API</h4> |
| 3743 | <div class="paragraph"> |
| 3744 | <p>Cockpit has API available for writing packages. There is no API |
| 3745 | available for external callers to invoke via HTTP, REST or otherwise.</p> |
| 3746 | </div> |
| 3747 | <div class="paragraph"> |
| 3748 | <p>API from various packages can be used to implement Cockpit packages. |
| 3749 | Each package listed here has some API available for use. Only the API |
| 3750 | explicitly documented should be used.</p> |
| 3751 | </div> |
| 3752 | <div class="ulist"> |
| 3753 | <ul> |
| 3754 | <li> |
| 3755 | <p><a href="development.html">API Listing</a></p> |
| 3756 | </li> |
| 3757 | </ul> |
| 3758 | </div> |
| 3759 | <div class="paragraph"> |
| 3760 | <p>To include javascript from the API, simply load it into your HTML using |
| 3761 | a script tag. Alternatively you can use an javascript loader.</p> |
| 3762 | </div> |
| 3763 | </div> |
| 3764 | <div class="sect3"> |
| 3765 | <h4 id="package-bridges">Bridges for specific tasks</h4> |
| 3766 | <div class="paragraph"> |
| 3767 | <p>On the server side the <a href="cockpit-bridge.1.html">cockpit-bridge</a>(1) |
| 3768 | connects to various system APIs that the front end UI requests it to. |
| 3769 | There are additional bridges for specific tasks that the main |
| 3770 | <code>cockpit-bridge</code> cannot handle, such as using the PCP C library API.</p> |
| 3771 | </div> |
| 3772 | <div class="paragraph"> |
| 3773 | <p>These additional bridges can be registered in a <code>"bridges"</code> section of |
| 3774 | a package’s <code>manifest.json</code> file. Building such a bridge is a complex |
| 3775 | tasks, and we will skip over that here. However it is useful to adjust |
| 3776 | how these additional bridges are called, and so we’ll look at how they |
| 3777 | are registered.</p> |
| 3778 | </div> |
| 3779 | <div class="paragraph"> |
| 3780 | <p>An example <code>manifest.json</code> with a bridges section:</p> |
| 3781 | </div> |
| 3782 | <div class="literalblock"> |
| 3783 | <div class="content"> |
| 3784 | <pre>{ |
| 3785 | "bridges": [ |
| 3786 | { |
| 3787 | "match": { "payload": "metrics1" }, |
| 3788 | "spawn": [ "/usr/libexec/cockpit-pcp" ] |
| 3789 | } |
| 3790 | ] |
| 3791 | }</pre> |
| 3792 | </div> |
| 3793 | </div> |
| 3794 | <div class="paragraph"> |
| 3795 | <p>The bridges are considered in the order they are listed in the array. |
| 3796 | Use the <code>manifest.json`</code>"priority"` field to control order between |
| 3797 | packages. The bridges are registered using JSON objects that have the |
| 3798 | following properties:</p> |
| 3799 | </div> |
| 3800 | <div class="dlist"> |
| 3801 | <dl> |
| 3802 | <dt class="hdlist1">environ</dt> |
| 3803 | <dd> |
| 3804 | <p>Optional, additional environment variables to pass to the bridge |
| 3805 | command.</p> |
| 3806 | </dd> |
| 3807 | <dt class="hdlist1">match</dt> |
| 3808 | <dd> |
| 3809 | <p>The <code>"match"</code> object describes which channel open command options |
| 3810 | need to match for a given channel to be handed over to this bridge.</p> |
| 3811 | </dd> |
| 3812 | <dt class="hdlist1">privileged</dt> |
| 3813 | <dd> |
| 3814 | <p>If set to <code>true</code>, this marks the bridge as a superuser bridge. |
| 3815 | Cockpit will start one of these explicitly when trying to escalate the |
| 3816 | privileges of a session. A privileged bridge can not have a |
| 3817 | <code>"match"</code> property.</p> |
| 3818 | </dd> |
| 3819 | <dt class="hdlist1">label</dt> |
| 3820 | <dd> |
| 3821 | <p>Setting this enables selection of privileged bridges in the UI. When |
| 3822 | no privileged bridge has a <code>label</code>, then Cockpit will start the |
| 3823 | bridge that runs <code>sudo</code>. This is the case in a default Cockpit |
| 3824 | installation. When at least one privileged bridge has a <code>label</code> then |
| 3825 | the user can select one of them when escalating privileges. As a |
| 3826 | special case, if only one bridge has a <code>label</code>, then the step of |
| 3827 | selecting a bridge is omitted in the UI and that one bridge is always |
| 3828 | started. |
| 3829 | + |
| 3830 | Thus, if you add a privileged bridge with a <code>label</code> in a new |
| 3831 | manifest, Cockpit will use that bridge the next time a user opens the |
| 3832 | "Administrative access" dialog. If you want the user to choose between |
| 3833 | the <code>sudo</code> method and your new one, you need to duplicate the |
| 3834 | <code>sudo</code> bridge definition in your manifest and give it a label.</p> |
| 3835 | </dd> |
| 3836 | <dt class="hdlist1">problem</dt> |
| 3837 | <dd> |
| 3838 | <p>If a problem is specified, and this bridge fails to start up then |
| 3839 | channels will be closed with this problem code. Otherwise later |
| 3840 | bridges or internal handlers for the channel will be invoked.</p> |
| 3841 | </dd> |
| 3842 | <dt class="hdlist1">spawn</dt> |
| 3843 | <dd> |
| 3844 | <p>The command and arguments to invoke.</p> |
| 3845 | </dd> |
| 3846 | </dl> |
| 3847 | </div> |
| 3848 | <div class="paragraph"> |
| 3849 | <p>The <code>spawn</code> and <code>environ</code> values can be dynamically taken from a |
| 3850 | matching open command values. When a value in either the <code>spawn</code> or |
| 3851 | <code>environ</code> array contains a named variable wrapped in <code>${}</code>, the |
| 3852 | variable will be replaced with the value contained in the matching open |
| 3853 | command. Only named variables are supported and name can only contain |
| 3854 | letters, numbers and the following symbols: <code>._-</code></p> |
| 3855 | </div> |
| 3856 | <div class="paragraph"> |
| 3857 | <p>For example a bridges section like:</p> |
| 3858 | </div> |
| 3859 | <div class="literalblock"> |
| 3860 | <div class="content"> |
| 3861 | <pre>{ |
| 3862 | "bridges": [ |
| 3863 | { |
| 3864 | "match": { "payload": "example" }, |
| 3865 | "environ": [ "TAG=${tag}" ], |
| 3866 | "spawn: [ "/example-bridge", "--tag", "${tag}" ], |
| 3867 | "problem": "access-denied" |
| 3868 | } |
| 3869 | ] |
| 3870 | }</pre> |
| 3871 | </div> |
| 3872 | </div> |
| 3873 | <div class="paragraph"> |
| 3874 | <p>when a open command is received with a payload of <code>example</code> with |
| 3875 | <code>tag</code> value of <code>tag1</code>. The following command will be spawned</p> |
| 3876 | </div> |
| 3877 | <div class="literalblock"> |
| 3878 | <div class="content"> |
| 3879 | <pre>TAG=tag1 /example-bridge --tag tag1</pre> |
| 3880 | </div> |
| 3881 | </div> |
| 3882 | <div class="paragraph"> |
| 3883 | <p>Processes that are reused so if another open command with a "tag" of |
| 3884 | <code>tag1</code> is received. The open command will be passed to existing |
| 3885 | process, rather than spawning a new one. However a open command with an |
| 3886 | tag of <code>tag2</code> will spawn a new command:</p> |
| 3887 | </div> |
| 3888 | <div class="literalblock"> |
| 3889 | <div class="content"> |
| 3890 | <pre>TAG=tag2 /example-bridge --tag tag2</pre> |
| 3891 | </div> |
| 3892 | </div> |
| 3893 | <div class="paragraph"> |
| 3894 | <p>If you need to include <code>${}</code>, as an actual value in your arguments you |
| 3895 | can escape it by prefixing it with a <code>\</code></p> |
| 3896 | </div> |
| 3897 | </div> |
| 3898 | <div class="sect3"> |
| 3899 | <h4 id="package-replace">Replacing an existing package</h4> |
| 3900 | <div class="paragraph"> |
| 3901 | <p>If the functionality in a package replaces that of another package then |
| 3902 | it can replace that package by claiming the same <code>name</code> and a higher |
| 3903 | <code>priority</code>.</p> |
| 3904 | </div> |
| 3905 | <div class="paragraph"> |
| 3906 | <p>For example, a package in the <code>/usr/share/cockpit/disks</code> directory |
| 3907 | could replace Cockpit’s <em>storage</em> package with a <code>manifest.json</code> like |
| 3908 | this:</p> |
| 3909 | </div> |
| 3910 | <div class="literalblock"> |
| 3911 | <div class="content"> |
| 3912 | <pre>{ |
| 3913 | "version": 0, |
| 3914 | "name": "storage", |
| 3915 | "priority": 10, |
| 3916 | "menu": { |
| 3917 | "index": { |
| 3918 | "label": "Disk Storage", |
| 3919 | "order": 15 |
| 3920 | } |
| 3921 | } |
| 3922 | }</pre> |
| 3923 | </div> |
| 3924 | </div> |
| 3925 | </div> |
| 3926 | </div> |
| 3927 | <div class="sect2"> |
| 3928 | <h3 id="urls">Cockpit URLs</h3> |
| 3929 | <div class="paragraph"> |
| 3930 | <p>Cockpit URLs follow a specific structure, related to the components they |
| 3931 | are loading. Various components are loaded in <code><iframe></code> tags. The |
| 3932 | URLs for these components are described first. Further down below you |
| 3933 | can find information about the top level bookmarkable Cockpit address |
| 3934 | URLs.</p> |
| 3935 | </div> |
| 3936 | <div class="sect3"> |
| 3937 | <h4 id="urls-components">Component URLs</h4> |
| 3938 | <div class="paragraph"> |
| 3939 | <p>Cockpit components are HTML documents. They are organized into |
| 3940 | <a href="packages.html">packages</a>. Each package contains information about which |
| 3941 | HTML components are available in that package. Components should always |
| 3942 | use relative URLs to access resources, such as images, scripts or CSS |
| 3943 | files, even if they refer to a resource in another package.</p> |
| 3944 | </div> |
| 3945 | <div class="paragraph"> |
| 3946 | <p>The following are valid component URLs, each bit will be discussed |
| 3947 | below:</p> |
| 3948 | </div> |
| 3949 | <div class="literalblock"> |
| 3950 | <div class="content"> |
| 3951 | <pre>/cockpit/@localhost/package/component.html#/hash |
| 3952 | /cockpit/$checksum/package/component.html#/hash |
| 3953 | /cockpit/@server.example.com/package/component.html#/hash |
| 3954 | /cockpit+embedder/@localhost/package/component.html#/hash</pre> |
| 3955 | </div> |
| 3956 | </div> |
| 3957 | <div class="paragraph"> |
| 3958 | <p>All resource URLs are under the <code>/cockpit</code> namespace. In cases where a |
| 3959 | Cockpit component is being <a href="embedding.html">embedded</a> the <code>/cockpit</code> |
| 3960 | may be followed by a plus sign and another <code>embedder</code> specific |
| 3961 | identifier.</p> |
| 3962 | </div> |
| 3963 | <div class="paragraph"> |
| 3964 | <p>What follows is either a <code>@host</code> or <code>$checksum</code> which tells cockpit |
| 3965 | where to <a href="packages.html">find the package</a>. Checksums are used when more |
| 3966 | than one host has identical packages and the resources can be cached.</p> |
| 3967 | </div> |
| 3968 | <div class="paragraph"> |
| 3969 | <p>The <code>package</code> name is next, followed by the <code>component</code> HTML path |
| 3970 | inside that package. And lastly a hash allows for navigation within a |
| 3971 | single component. The hash should follow a URL path and/or query string |
| 3972 | form.</p> |
| 3973 | </div> |
| 3974 | <div class="admonitionblock warning"> |
| 3975 | <table> |
| 3976 | <tr> |
| 3977 | <td class="icon"> |
| 3978 | <div class="title">Warning</div> |
| 3979 | </td> |
| 3980 | <td class="content"> |
| 3981 | <div class="paragraph"> |
| 3982 | <p>Never assume that the <code>@host</code> or <code>$checksum</code> portion is predictable. |
| 3983 | Only refer to resources in packages on the same host.</p> |
| 3984 | </div> |
| 3985 | </td> |
| 3986 | </tr> |
| 3987 | </table> |
| 3988 | </div> |
| 3989 | </div> |
| 3990 | <div class="sect3"> |
| 3991 | <h4 id="urls-visible">Visible URLs</h4> |
| 3992 | <div class="paragraph"> |
| 3993 | <p>The above Component URLs are usually not visible to the user. Instead |
| 3994 | the Cockpit Web Service wraps the components in a shell which allows |
| 3995 | navigation, and provides bookmarkable clean URLs to the component. These |
| 3996 | URLs do not affect <a href="embedding.html">embedders</a> or |
| 3997 | <a href="packages.html">components</a> directly.</p> |
| 3998 | </div> |
| 3999 | <div class="paragraph"> |
| 4000 | <p>If no path is present then the Cockpit will redirect to the default page |
| 4001 | for the server.</p> |
| 4002 | </div> |
| 4003 | <div class="paragraph"> |
| 4004 | <p>If the first segment of the path begins with an <code>@</code> sign, then the |
| 4005 | component is being shown from a non-local host.</p> |
| 4006 | </div> |
| 4007 | <div class="paragraph"> |
| 4008 | <p>The next segment of the path, (or first if the component is being shown |
| 4009 | on the local host) is the <a href="packages.html">package name</a>. The remainder of |
| 4010 | the path is a component file in the package. If no further path segments |
| 4011 | are present, a default <code>index.html</code> component in the package is |
| 4012 | loaded. An extension of <code>.html</code> is automatically appended.</p> |
| 4013 | </div> |
| 4014 | <div class="paragraph"> |
| 4015 | <p>The hash portion of the path is automatically transferred to the |
| 4016 | component as the hash of its <a href="#urls-components">resource URL</a>.</p> |
| 4017 | </div> |
| 4018 | </div> |
| 4019 | </div> |
| 4020 | <div class="sect2"> |
| 4021 | <h3 id="_api_base1">API: base1</h3> |
| 4022 | <div class="paragraph"> |
| 4023 | <p>This package contains basic support API available to other packages.</p> |
| 4024 | </div> |
| 4025 | <div class="sect3"> |
| 4026 | <h4 id="_cockpit_js">cockpit.js</h4> |
| 4027 | <div class="paragraph"> |
| 4028 | <p>Basic cockpit API to interact with the system</p> |
| 4029 | </div> |
| 4030 | <div class="sect4"> |
| 4031 | <h5 id="api-cockpit-loading">Loading cockpit.js</h5> |
| 4032 | <div class="paragraph"> |
| 4033 | <p><code>cockpit.js</code> should be loaded via a script tag.</p> |
| 4034 | </div> |
| 4035 | <div class="literalblock"> |
| 4036 | <div class="content"> |
| 4037 | <pre><script src="../base1/cockpit.js"></pre> |
| 4038 | </div> |
| 4039 | </div> |
| 4040 | </div> |
| 4041 | </div> |
| 4042 | <div class="sect3"> |
| 4043 | <h4 id="_cockpit_js_object_caching">cockpit.js: Object Caching</h4> |
| 4044 | <div class="paragraph"> |
| 4045 | <p>If the same information is displayed by multiple components in Cockpit, |
| 4046 | <code>cockpit.cache()</code> provides a way to share data between them. The |
| 4047 | shared data should be simple objects, arrays, and values, and not |
| 4048 | contain functions or other objects.</p> |
| 4049 | </div> |
| 4050 | <div class="sect4"> |
| 4051 | <h5 id="cockpit-cache-func">cockpit.cache()</h5> |
| 4052 | <div class="literalblock"> |
| 4053 | <div class="content"> |
| 4054 | <pre>cache = cockpit.cache(key, provider, consumer)</pre> |
| 4055 | </div> |
| 4056 | </div> |
| 4057 | <div class="paragraph"> |
| 4058 | <p>Create a new cache object. The <code>key</code> should be a globally unique |
| 4059 | string that describes the data being cached. This string must describe |
| 4060 | the data, across all machines and all versions of cockpit. It is |
| 4061 | customary to include a version number in the <code>key</code> string.</p> |
| 4062 | </div> |
| 4063 | <div class="literalblock"> |
| 4064 | <div class="content"> |
| 4065 | <pre>function provider(result, key) { |
| 4066 | result("myvalue"); |
| 4067 | |
| 4068 | return { |
| 4069 | close: function() { |
| 4070 | /* closed */ |
| 4071 | } |
| 4072 | }; |
| 4073 | }</pre> |
| 4074 | </div> |
| 4075 | </div> |
| 4076 | <div class="paragraph"> |
| 4077 | <p>The <code>provider</code> is a function that will be invoked to start retrieving |
| 4078 | data for the cache. It will be passed a <code>result</code> function as its first |
| 4079 | argument. The <code>result</code> should be invoked whenever new data is |
| 4080 | available. The <code>key</code> argument matches the key string the cache was |
| 4081 | created with.</p> |
| 4082 | </div> |
| 4083 | <div class="paragraph"> |
| 4084 | <p>The <code>provider</code> can return an object with a <code>close</code> method. This |
| 4085 | method will be invoked when the cache no longer needs data from the |
| 4086 | provider.</p> |
| 4087 | </div> |
| 4088 | <div class="literalblock"> |
| 4089 | <div class="content"> |
| 4090 | <pre>function consumer(value, key) { |
| 4091 | /* ... */ |
| 4092 | }</pre> |
| 4093 | </div> |
| 4094 | </div> |
| 4095 | <div class="paragraph"> |
| 4096 | <p>The <code>consumer</code> is a function that will be passed new values when they |
| 4097 | are available, whether they come from the <code>provider</code> or a source in a |
| 4098 | different component/frame.</p> |
| 4099 | </div> |
| 4100 | </div> |
| 4101 | <div class="sect4"> |
| 4102 | <h5 id="cockpit-cache-close">cache.close()</h5> |
| 4103 | <div class="literalblock"> |
| 4104 | <div class="content"> |
| 4105 | <pre>cache.close()</pre> |
| 4106 | </div> |
| 4107 | </div> |
| 4108 | <div class="paragraph"> |
| 4109 | <p>Close a cache and stop calling its <code>consumer</code>. If the <code>provider</code> was |
| 4110 | invoked, then the <code>close()</code> method it returned will be invoked.</p> |
| 4111 | </div> |
| 4112 | </div> |
| 4113 | </div> |
| 4114 | <div class="sect3"> |
| 4115 | <h4 id="_cockpit_js_raw_channels">cockpit.js: Raw Channels</h4> |
| 4116 | <div class="paragraph"> |
| 4117 | <p>At a low level Cockpit communicates with the system via messages passed |
| 4118 | through various channels. These are usually exposed via higher level |
| 4119 | APIs, such as the <code>cockpit.spawn()</code> function. It is rare to use raw |
| 4120 | channels directly.</p> |
| 4121 | </div> |
| 4122 | <div class="sect4"> |
| 4123 | <h5 id="cockpit-channels-channel">cockpit.channel()</h5> |
| 4124 | <div class="literalblock"> |
| 4125 | <div class="content"> |
| 4126 | <pre>channel = cockpit.channel(options)</pre> |
| 4127 | </div> |
| 4128 | </div> |
| 4129 | <div class="paragraph"> |
| 4130 | <p>This function creates a new channel for communication with the system. |
| 4131 | It returns a new channel object. The <code>options</code> argument is a plain |
| 4132 | object. At least the <code>"payload"</code> option is required, and based on the |
| 4133 | payload type, other options may be required.</p> |
| 4134 | </div> |
| 4135 | <div class="dlist"> |
| 4136 | <dl> |
| 4137 | <dt class="hdlist1"><code>"binary"</code></dt> |
| 4138 | <dd> |
| 4139 | <p>Set to <code>true</code> to transfer binary payloads. Both messages sent via |
| 4140 | <a href="#cockpit-channels-send"><code>channel.send()</code></a> and those received via |
| 4141 | <a href="#cockpit-channels-message"><code>channel.onmessage</code></a> should be arrays |
| 4142 | of bytes, either <code>Uint8Array</code> or <code>Array</code> depending on browser |
| 4143 | support.</p> |
| 4144 | </dd> |
| 4145 | <dt class="hdlist1"><code>"payload"</code></dt> |
| 4146 | <dd> |
| 4147 | <p>The payload type for the channel. Only specific payload types are |
| 4148 | supported.</p> |
| 4149 | </dd> |
| 4150 | <dt class="hdlist1"><code>"superuser"</code></dt> |
| 4151 | <dd> |
| 4152 | <p>Set to <code>"require"</code> to open this channel as root. If the currently |
| 4153 | logged in user is not permitted to become root (eg: via <code>pkexec</code>) |
| 4154 | then the <code>channel</code> will immediately be |
| 4155 | <a href="#cockpit-channels-close-ev">closed</a> with a <code>"access-denied"</code> |
| 4156 | problem code. |
| 4157 | + |
| 4158 | Set to <code>"try"</code> to try to open the channel as root, but if that |
| 4159 | fails, then fall back to an unprivileged channel.</p> |
| 4160 | </dd> |
| 4161 | </dl> |
| 4162 | </div> |
| 4163 | <div class="paragraph"> |
| 4164 | <p>The channel object returned has the following fields and methods and |
| 4165 | events. You should call the <code>channel.close()</code> method when done with |
| 4166 | the channel.</p> |
| 4167 | </div> |
| 4168 | <div class="paragraph"> |
| 4169 | <p>A valid channel will always be returned and the is ready to |
| 4170 | <code>channel.send()</code>. The channel may |
| 4171 | <a href="#cockpit-channels-close-ev">close shortly afterword</a> due to a |
| 4172 | failure.</p> |
| 4173 | </div> |
| 4174 | </div> |
| 4175 | <div class="sect4"> |
| 4176 | <h5 id="cockpit-channels-binary">channel.binary</h5> |
| 4177 | <div class="paragraph"> |
| 4178 | <p>Will be <code>true</code> for an binary channel. Will be set to <code>false</code> if the |
| 4179 | channel is textual.</p> |
| 4180 | </div> |
| 4181 | </div> |
| 4182 | <div class="sect4"> |
| 4183 | <h5 id="cockpit-channels-options">channel.options</h5> |
| 4184 | <div class="paragraph"> |
| 4185 | <p>The options used to open this channel. This should not be changed.</p> |
| 4186 | </div> |
| 4187 | </div> |
| 4188 | <div class="sect4"> |
| 4189 | <h5 id="cockpit-channels-valid">channel.valid</h5> |
| 4190 | <div class="paragraph"> |
| 4191 | <p>Will be <code>true</code> for an open channel. Will be set to <code>false</code> if the |
| 4192 | channel closes.</p> |
| 4193 | </div> |
| 4194 | </div> |
| 4195 | <div class="sect4"> |
| 4196 | <h5 id="cockpit-channels-send">channel.send()</h5> |
| 4197 | <div class="literalblock"> |
| 4198 | <div class="content"> |
| 4199 | <pre>channel.send(data)</pre> |
| 4200 | </div> |
| 4201 | </div> |
| 4202 | <div class="paragraph"> |
| 4203 | <p>Send a message over the channel. The contents of the message depends on |
| 4204 | the payload type of the channel. If a binary channel, then <code>data</code> is |
| 4205 | expected to be an <code>Array</code> of bytes or a <code>Uint8Array</code>. If not binary, |
| 4206 | then the <code>data</code> will be converted to a string if not already a string.</p> |
| 4207 | </div> |
| 4208 | </div> |
| 4209 | <div class="sect4"> |
| 4210 | <h5 id="cockpit-channels-control">channel.control()</h5> |
| 4211 | <div class="literalblock"> |
| 4212 | <div class="content"> |
| 4213 | <pre>channel.control(options)</pre> |
| 4214 | </div> |
| 4215 | </div> |
| 4216 | <div class="paragraph"> |
| 4217 | <p>Notify the channel to tune certain parameters on the fly. The |
| 4218 | <code>options</code> is a plain javascript object, and the contents depend on the |
| 4219 | <code>"payload"</code> of the channel.</p> |
| 4220 | </div> |
| 4221 | <div class="paragraph"> |
| 4222 | <p>One common operation is to set <code>"command"</code> to <code>"done"</code> in the |
| 4223 | options field. To indicate that no further messages will be sent through |
| 4224 | the channel.</p> |
| 4225 | </div> |
| 4226 | </div> |
| 4227 | <div class="sect4"> |
| 4228 | <h5 id="cockpit-channels-wait">channel.wait()</h5> |
| 4229 | <div class="literalblock"> |
| 4230 | <div class="content"> |
| 4231 | <pre>promise = channel.wait([callback])</pre> |
| 4232 | </div> |
| 4233 | </div> |
| 4234 | <div class="paragraph"> |
| 4235 | <p>Returns a <code>promise</code> that is ready when the channel is ready, or fails |
| 4236 | if the client closes. If a <code>callback</code> is specified, it is attached to |
| 4237 | the promise. The promise will be rejected or resolved with the contents |
| 4238 | <code>options</code> passed to the |
| 4239 | <a href="#cockpit-channels-onready">channel.onready</a> and |
| 4240 | <a href="#cockpit-channels-close-ev">channel.onclose</a> events respectively.</p> |
| 4241 | </div> |
| 4242 | <div class="paragraph"> |
| 4243 | <p>In general it’s not necessary to wait for the channel before starting to |
| 4244 | use the channel.</p> |
| 4245 | </div> |
| 4246 | </div> |
| 4247 | <div class="sect4"> |
| 4248 | <h5 id="cockpit-channels-close">channel.close()</h5> |
| 4249 | <div class="literalblock"> |
| 4250 | <div class="content"> |
| 4251 | <pre>channel.close([options])</pre> |
| 4252 | </div> |
| 4253 | </div> |
| 4254 | <div class="paragraph"> |
| 4255 | <p>Close the channel.</p> |
| 4256 | </div> |
| 4257 | <div class="paragraph"> |
| 4258 | <p>If <code>options</code> is present it can be a plain javascript object containing |
| 4259 | additional channel close options to send to the peer. If closing for |
| 4260 | because of a problem, set the <code>"problem"</code> field to a |
| 4261 | <a href="cockpit-error.html#cockpit-problems">problem code</a>. If <code>options</code> is not an object it |
| 4262 | will be treated as a <code>"problem"</code>.</p> |
| 4263 | </div> |
| 4264 | <div class="paragraph"> |
| 4265 | <p>The <a href="#cockpit-channels-close-ev">close event</a> will fire. A channel |
| 4266 | can also be closed by a peer or if the underlying transport closes.</p> |
| 4267 | </div> |
| 4268 | </div> |
| 4269 | <div class="sect4"> |
| 4270 | <h5 id="cockpit-channels-message">channel.onmessage</h5> |
| 4271 | <div class="literalblock"> |
| 4272 | <div class="content"> |
| 4273 | <pre>channel.addEventListener("message", function(event, data) { ... })</pre> |
| 4274 | </div> |
| 4275 | </div> |
| 4276 | <div class="paragraph"> |
| 4277 | <p>An event triggered when the channel receives a message. The message is |
| 4278 | passed as a string to the handler in the <code>data</code>. In the case of binary |
| 4279 | channels <code>data</code> is an <code>Uint8Array</code> or an <code>Array</code> of bytes if the |
| 4280 | former is not supported by the browser. The contents of the message |
| 4281 | depends on the payload type of the channel.</p> |
| 4282 | </div> |
| 4283 | </div> |
| 4284 | <div class="sect4"> |
| 4285 | <h5 id="cockpit-channels-oncontrol">channel.oncontrol</h5> |
| 4286 | <div class="literalblock"> |
| 4287 | <div class="content"> |
| 4288 | <pre>channel.addEventListener("control", function(event, options) { ... })</pre> |
| 4289 | </div> |
| 4290 | </div> |
| 4291 | <div class="paragraph"> |
| 4292 | <p>An event triggered when the channel receives an control message in the |
| 4293 | middle of the flow. One particular use is when the <code>command</code> is set to |
| 4294 | <code>"done"</code> then no further messages will be received in the channel. The |
| 4295 | exact form of these messages depend on the <code>"payload"</code> of the channel.</p> |
| 4296 | </div> |
| 4297 | </div> |
| 4298 | <div class="sect4"> |
| 4299 | <h5 id="cockpit-channels-onready">channel.onready</h5> |
| 4300 | <div class="literalblock"> |
| 4301 | <div class="content"> |
| 4302 | <pre>channel.addEventListener("ready", function(event, options) { ... })</pre> |
| 4303 | </div> |
| 4304 | </div> |
| 4305 | <div class="paragraph"> |
| 4306 | <p>An event triggered when the other end of the channel is ready to start |
| 4307 | processing messages. This indicates the channel is completely open. It |
| 4308 | is possible to start sending messages on the channel before this point.</p> |
| 4309 | </div> |
| 4310 | </div> |
| 4311 | <div class="sect4"> |
| 4312 | <h5 id="cockpit-channels-close-ev">channel.onclose</h5> |
| 4313 | <div class="literalblock"> |
| 4314 | <div class="content"> |
| 4315 | <pre>channel.addEventListener("close", function(event, options) { ... })</pre> |
| 4316 | </div> |
| 4317 | </div> |
| 4318 | <div class="paragraph"> |
| 4319 | <p>An event triggered when the channel closes. This can happen either |
| 4320 | because <a href="#cockpit-channels-close">channel.close()</a> function was |
| 4321 | called, or if the peer closed the channel, or the underlying transport |
| 4322 | closes.</p> |
| 4323 | </div> |
| 4324 | <div class="paragraph"> |
| 4325 | <p>The <code>options</code> will contain various close information, including a |
| 4326 | <code>"problem"</code> field which will be set if the channel was closed because |
| 4327 | of a problem.</p> |
| 4328 | </div> |
| 4329 | </div> |
| 4330 | <div class="sect4"> |
| 4331 | <h5 id="cockpit-transport-origin">cockpit.transport.origin</h5> |
| 4332 | <div class="literalblock"> |
| 4333 | <div class="content"> |
| 4334 | <pre>cockpit.transport.origin</pre> |
| 4335 | </div> |
| 4336 | </div> |
| 4337 | <div class="paragraph"> |
| 4338 | <p>The HTTP origin that is being used by the underlying channel transport. |
| 4339 | This is read-only, you should not assign a value. If the browser |
| 4340 | supports <code>window.location.origin</code> then this will be identical to that |
| 4341 | value.</p> |
| 4342 | </div> |
| 4343 | </div> |
| 4344 | <div class="sect4"> |
| 4345 | <h5 id="cockpit-transport-host">cockpit.transport.host</h5> |
| 4346 | <div class="literalblock"> |
| 4347 | <div class="content"> |
| 4348 | <pre>cockpit.transport.host</pre> |
| 4349 | </div> |
| 4350 | </div> |
| 4351 | <div class="paragraph"> |
| 4352 | <p>The host that this transport is going to talk to by default. This is |
| 4353 | read-only, you should not assign a value. If the value is null that |
| 4354 | means that the transport has not been setup yet.</p> |
| 4355 | </div> |
| 4356 | </div> |
| 4357 | <div class="sect4"> |
| 4358 | <h5 id="cockpit-transport-csrf-token">cockpit.transport.csrf_token</h5> |
| 4359 | <div class="literalblock"> |
| 4360 | <div class="content"> |
| 4361 | <pre>cockpit.transport.csrf_token</pre> |
| 4362 | </div> |
| 4363 | </div> |
| 4364 | <div class="paragraph"> |
| 4365 | <p>A cross site request forgery token for use with external channels. This |
| 4366 | becomes valid once the connection is properly established.</p> |
| 4367 | </div> |
| 4368 | </div> |
| 4369 | <div class="sect4"> |
| 4370 | <h5 id="cockpit-transport-options">cockpit.transport.options</h5> |
| 4371 | <div class="literalblock"> |
| 4372 | <div class="content"> |
| 4373 | <pre>cockpit.transport.options</pre> |
| 4374 | </div> |
| 4375 | </div> |
| 4376 | <div class="paragraph"> |
| 4377 | <p>Initialization options received over the underlying channel transport. |
| 4378 | These will be empty until connection is properly established.</p> |
| 4379 | </div> |
| 4380 | </div> |
| 4381 | <div class="sect4"> |
| 4382 | <h5 id="cockpit-transport-wait">cockpit.transport.wait()</h5> |
| 4383 | <div class="literalblock"> |
| 4384 | <div class="content"> |
| 4385 | <pre>cockpit.transport.wait(callback)</pre> |
| 4386 | </div> |
| 4387 | </div> |
| 4388 | <div class="paragraph"> |
| 4389 | <p>Call the <code>callback</code> function once the underlying channel transport is |
| 4390 | initialized. This will start the initialization if not already in |
| 4391 | progress or completed. If the channel transport is already initialized, |
| 4392 | then <code>callback</code> will be called immediately.</p> |
| 4393 | </div> |
| 4394 | <div class="paragraph"> |
| 4395 | <p>In general it’s not necessary to wait for the transport before starting |
| 4396 | to open channels.</p> |
| 4397 | </div> |
| 4398 | </div> |
| 4399 | <div class="sect4"> |
| 4400 | <h5 id="cockpit-transport-close">cockpit.transport.close()</h5> |
| 4401 | <div class="literalblock"> |
| 4402 | <div class="content"> |
| 4403 | <pre>cockpit.transport.close([problem])</pre> |
| 4404 | </div> |
| 4405 | </div> |
| 4406 | <div class="paragraph"> |
| 4407 | <p>Close the underlying channel transport. All channels open channels will |
| 4408 | close. The <code>problem</code> argument should be a problem code string. If not |
| 4409 | specified it will default to <code>"disconnected"</code>.</p> |
| 4410 | </div> |
| 4411 | </div> |
| 4412 | <div class="sect4"> |
| 4413 | <h5 id="cockpit-transport-filter">cockpit.transport.filter()</h5> |
| 4414 | <div class="literalblock"> |
| 4415 | <div class="content"> |
| 4416 | <pre>cockpit.transport.filter((message, channelid, control) => { ... })</pre> |
| 4417 | </div> |
| 4418 | </div> |
| 4419 | <div class="paragraph"> |
| 4420 | <p>Add a filter to the underlying channel transport. All incoming messages |
| 4421 | will be passed to each of the filter callbacks that are registered.</p> |
| 4422 | </div> |
| 4423 | <div class="paragraph"> |
| 4424 | <p>This function is rarely used.</p> |
| 4425 | </div> |
| 4426 | <div class="paragraph"> |
| 4427 | <p>Filter callbacks are called in the order they are registered. If a |
| 4428 | filter callback returns <code>false</code> then the message will not be |
| 4429 | dispatched further, whether to other filters, or to channels, etc.</p> |
| 4430 | </div> |
| 4431 | <div class="paragraph"> |
| 4432 | <p>The <code>message</code> is the string or array with the raw message including, |
| 4433 | the framing. The <code>channelid</code> is the channel identifier or an empty |
| 4434 | string for control messages. If <code>control</code> is set then this is a |
| 4435 | control message,d and the <code>control</code> argument contains the parsed JSON |
| 4436 | object of the control message.</p> |
| 4437 | </div> |
| 4438 | </div> |
| 4439 | <div class="sect4"> |
| 4440 | <h5 id="cockpit-transport-inject">cockpit.transport.inject()</h5> |
| 4441 | <div class="literalblock"> |
| 4442 | <div class="content"> |
| 4443 | <pre>cockpit.transport.inject(message, [out])</pre> |
| 4444 | </div> |
| 4445 | </div> |
| 4446 | <div class="paragraph"> |
| 4447 | <p>Inject a message into the underlying channel transport. The <code>message</code> |
| 4448 | should be a <code>string</code> or an array of bytes, and should be valid |
| 4449 | according to the Cockpit message protocol. If the <code>out</code> argument is |
| 4450 | equal to <code>false</code> then the message will be injected as an incoming |
| 4451 | message as if it was received on the underlying channel transport.</p> |
| 4452 | </div> |
| 4453 | <div class="paragraph"> |
| 4454 | <p>This function is rarely used. In general you should only <code>inject()</code> |
| 4455 | messages you got from a <code>filter()</code>.</p> |
| 4456 | </div> |
| 4457 | </div> |
| 4458 | <div class="sect4"> |
| 4459 | <h5 id="cockpit-base64-encode">cockpit.base64_encode()</h5> |
| 4460 | <div class="literalblock"> |
| 4461 | <div class="content"> |
| 4462 | <pre>string = cockpit.base64_encode(data)</pre> |
| 4463 | </div> |
| 4464 | </div> |
| 4465 | <div class="paragraph"> |
| 4466 | <p>Encode binary data into a string using the Base64 encoding. The <code>data</code> |
| 4467 | argument can either be a <code>string</code>, an <code>Array</code>, an <code>ArrayBuffer</code> or |
| 4468 | a <code>Uint8Array</code>. The return value is a string.</p> |
| 4469 | </div> |
| 4470 | </div> |
| 4471 | <div class="sect4"> |
| 4472 | <h5 id="cockpit-base64-decode">cockpit.base64_decode()</h5> |
| 4473 | <div class="literalblock"> |
| 4474 | <div class="content"> |
| 4475 | <pre>data = cockpit.base64_decode(string, [constructor])</pre> |
| 4476 | </div> |
| 4477 | </div> |
| 4478 | <div class="paragraph"> |
| 4479 | <p>Decode binary data from a Base64 encoded string. The <code>string</code> argument |
| 4480 | should be a javascript string. The returned <code>data</code>> will be an array |
| 4481 | of bytes.</p> |
| 4482 | </div> |
| 4483 | <div class="paragraph"> |
| 4484 | <p>You can pass <code>Uint8Array</code>, <code>Array</code> or <code>String</code> as an alternate |
| 4485 | <code>constructor</code> if you want the decoded data in an alternate form. The |
| 4486 | default is to return an <code>Array</code>. Note that if you use a <code>String</code> for |
| 4487 | the decoded data, then you must guarantee that the data does not contain |
| 4488 | bytes that would be invalid for a string.</p> |
| 4489 | </div> |
| 4490 | </div> |
| 4491 | </div> |
| 4492 | <div class="sect3"> |
| 4493 | <h4 id="_cockpit_js_dbus_client">cockpit.js: DBus Client</h4> |
| 4494 | <div class="paragraph"> |
| 4495 | <p>Cockpit allows access to DBus services via this API.</p> |
| 4496 | </div> |
| 4497 | <div class="sect4"> |
| 4498 | <h5 id="cockpit-dbus-types">DBus Types</h5> |
| 4499 | <div class="paragraph"> |
| 4500 | <p>DBus values are represented as javascript values and objects as follows:</p> |
| 4501 | </div> |
| 4502 | <div class="dlist"> |
| 4503 | <dl> |
| 4504 | <dt class="hdlist1"><code>BYTE 'y'</code></dt> |
| 4505 | <dd> |
| 4506 | <p>Javascript number.</p> |
| 4507 | </dd> |
| 4508 | <dt class="hdlist1"><code>BOOLEAN 'b'</code></dt> |
| 4509 | <dd> |
| 4510 | <p>Javascript boolean.</p> |
| 4511 | </dd> |
| 4512 | <dt class="hdlist1"><code>INT16 'n'</code></dt> |
| 4513 | <dd> |
| 4514 | <p>Javascript number.</p> |
| 4515 | </dd> |
| 4516 | <dt class="hdlist1"><code>UINT16 'q'</code></dt> |
| 4517 | <dd> |
| 4518 | <p>Javascript number.</p> |
| 4519 | </dd> |
| 4520 | <dt class="hdlist1"><code>INT32 'i'</code></dt> |
| 4521 | <dd> |
| 4522 | <p>Javascript number.</p> |
| 4523 | </dd> |
| 4524 | <dt class="hdlist1"><code>UINT32 'u'</code></dt> |
| 4525 | <dd> |
| 4526 | <p>Javascript number.</p> |
| 4527 | </dd> |
| 4528 | <dt class="hdlist1"><code>INT64 'x'</code></dt> |
| 4529 | <dd> |
| 4530 | <p>Javascript number.</p> |
| 4531 | </dd> |
| 4532 | <dt class="hdlist1"><code>UINT64 't'</code></dt> |
| 4533 | <dd> |
| 4534 | <p>Javascript number.</p> |
| 4535 | </dd> |
| 4536 | <dt class="hdlist1"><code>DOUBLE 'd'</code></dt> |
| 4537 | <dd> |
| 4538 | <p>Javascript number.</p> |
| 4539 | </dd> |
| 4540 | <dt class="hdlist1"><code>STRING 's'</code></dt> |
| 4541 | <dd> |
| 4542 | <p>Javascript string.</p> |
| 4543 | </dd> |
| 4544 | <dt class="hdlist1"><code>OBJECT_PATH 'o'</code></dt> |
| 4545 | <dd> |
| 4546 | <p>Javascript string.</p> |
| 4547 | </dd> |
| 4548 | <dt class="hdlist1"><code>SIGNATURE 'g'</code></dt> |
| 4549 | <dd> |
| 4550 | <p>Javascript string.</p> |
| 4551 | </dd> |
| 4552 | <dt class="hdlist1"><code>ARRAY of BYTE 'ay'</code></dt> |
| 4553 | <dd> |
| 4554 | <p>A string containing base64 encoded data.</p> |
| 4555 | </dd> |
| 4556 | <dt class="hdlist1"><code>ARRAY of DICT_ENTRY with STRING keys 'a{s?}'</code></dt> |
| 4557 | <dd> |
| 4558 | <p>A javascript plain object with the keys as property names.</p> |
| 4559 | </dd> |
| 4560 | <dt class="hdlist1"><code>ARRAY of DICT_ENTRY with other keys 'a{??}'</code></dt> |
| 4561 | <dd> |
| 4562 | <p>A javascript plain object each key JSON encoded into a string property |
| 4563 | name.</p> |
| 4564 | </dd> |
| 4565 | <dt class="hdlist1"><code>ARRAY of other</code></dt> |
| 4566 | <dd> |
| 4567 | <p>A javascript array.</p> |
| 4568 | </dd> |
| 4569 | <dt class="hdlist1"><code>VARIANT</code></dt> |
| 4570 | <dd> |
| 4571 | <p>A javascript plain object with the <code>"t"</code> property set to a DBus type |
| 4572 | string, and the <code>"v"</code> property set to a value.</p> |
| 4573 | </dd> |
| 4574 | <dt class="hdlist1"><code>HANDLE 'h'</code></dt> |
| 4575 | <dd> |
| 4576 | <p>A javascript object that describes a cockpit channel which represents |
| 4577 | the passed file descriptor. The <code>payload</code> is always set to |
| 4578 | <code>stream</code>. Pass it to |
| 4579 | <a href="cockpit-channels.html#cockpit-channels-channel">cockpit.channel()</a> to create the |
| 4580 | channel and start reading or writing on it. Handles can only be |
| 4581 | received, not sent from within cockpit.</p> |
| 4582 | </dd> |
| 4583 | </dl> |
| 4584 | </div> |
| 4585 | </div> |
| 4586 | <div class="sect4"> |
| 4587 | <h5 id="cockpit-dbus-dbus">cockpit.dbus()</h5> |
| 4588 | <div class="literalblock"> |
| 4589 | <div class="content"> |
| 4590 | <pre>client = cockpit.dbus(name, [options])</pre> |
| 4591 | </div> |
| 4592 | </div> |
| 4593 | <div class="paragraph"> |
| 4594 | <p>Create a DBus client for the given bus <code>name</code> (eg: service name). Use |
| 4595 | the following functions to make DBus method calls, watch for events, |
| 4596 | etc. The optional <code>options</code> argument is a javascript plain object, and |
| 4597 | may include:</p> |
| 4598 | </div> |
| 4599 | <div class="dlist"> |
| 4600 | <dl> |
| 4601 | <dt class="hdlist1"><code>"bus"</code></dt> |
| 4602 | <dd> |
| 4603 | <p>The DBus bus to connect to. Specifying <code>"session"</code> will connect to |
| 4604 | the DBus user session bus, <code>"user"</code> will connect to the user bus (on |
| 4605 | some systems this is identical to the session bus), <code>"system"</code> will |
| 4606 | connect to the DBus system bus, and <code>"none"</code> to the non-standard bus |
| 4607 | specified with the <code>address</code> option. This defaults to "system" if |
| 4608 | not present.</p> |
| 4609 | </dd> |
| 4610 | <dt class="hdlist1"><code>"address"</code></dt> |
| 4611 | <dd> |
| 4612 | <p>The bus address to connect to in case <code>bus</code> is <code>"none"</code>.</p> |
| 4613 | </dd> |
| 4614 | <dt class="hdlist1"><code>"superuser"</code></dt> |
| 4615 | <dd> |
| 4616 | <p>Set to <code>"require"</code> to talk to this service as root. The DBus service |
| 4617 | will see the DBus method calls and accesses as coming from root, |
| 4618 | rather than the logged in user. This is useful for talking to services |
| 4619 | that do not correctly use |
| 4620 | <a href="https://www.freedesktop.org/software/polkit">polkit</a> to authorize |
| 4621 | administrative users. If the currently logged in user is not permitted |
| 4622 | to become root (eg: via <code>pkexec</code>) then the <code>client</code> will |
| 4623 | immediately be <a href="#cockpit-dbus-onclose">closed</a> with a |
| 4624 | <code>"access-denied"</code> problem code. |
| 4625 | + |
| 4626 | Set to <code>"try"</code> to try to talk as root, but if that fails, fall back |
| 4627 | to unprivileged.</p> |
| 4628 | </dd> |
| 4629 | <dt class="hdlist1"><code>"track"</code></dt> |
| 4630 | <dd> |
| 4631 | <p>It is valid for a DBus service to exit, and be restarted in such a way |
| 4632 | that clients continue to talk to it across the restart. Some services |
| 4633 | are not written with this in mind. If the <code>"track"</code> option is set to |
| 4634 | <code>true</code> then the channel will close when the service exits and/or |
| 4635 | disconnects from the DBus bus.</p> |
| 4636 | </dd> |
| 4637 | </dl> |
| 4638 | </div> |
| 4639 | <div class="paragraph"> |
| 4640 | <p>If the <code>name</code> argument is null, and no options other than <code>"bus"</code> |
| 4641 | are specified, then a shared DBus <code>client</code> is created. When using such |
| 4642 | a client with a DBus bus, a <code>"name"</code> option must be specified on |
| 4643 | various other methods in order to specify which client to talk to.</p> |
| 4644 | </div> |
| 4645 | </div> |
| 4646 | <div class="sect4"> |
| 4647 | <h5 id="cockpit-dbus-wait">client.wait()</h5> |
| 4648 | <div class="literalblock"> |
| 4649 | <div class="content"> |
| 4650 | <pre>promise = client.wait([callback])</pre> |
| 4651 | </div> |
| 4652 | </div> |
| 4653 | <div class="paragraph"> |
| 4654 | <p>Returns a <code>promise</code> that is ready when the client is ready, or fails |
| 4655 | if the client closes. If a <code>callback</code> is specified, it is attached to |
| 4656 | the promise.</p> |
| 4657 | </div> |
| 4658 | </div> |
| 4659 | <div class="sect4"> |
| 4660 | <h5 id="cockpit-dbus-close">client.close()</h5> |
| 4661 | <div class="literalblock"> |
| 4662 | <div class="content"> |
| 4663 | <pre>client.close([problem])</pre> |
| 4664 | </div> |
| 4665 | </div> |
| 4666 | <div class="paragraph"> |
| 4667 | <p>Close the DBus client. If <code>problem</code> is specified it should be a |
| 4668 | <a href="cockpit-error.html#cockpit-problems">problem code</a> string.</p> |
| 4669 | </div> |
| 4670 | </div> |
| 4671 | <div class="sect4"> |
| 4672 | <h5 id="cockpit-dbus-onclose">client.onclose</h5> |
| 4673 | <div class="literalblock"> |
| 4674 | <div class="content"> |
| 4675 | <pre>client.addEventListener("close", options => { ... })</pre> |
| 4676 | </div> |
| 4677 | </div> |
| 4678 | <div class="paragraph"> |
| 4679 | <p>An event triggered when the DBus client closes. This can happen either |
| 4680 | because <a href="#cockpit-dbus-close">client.close()</a> function was called, or |
| 4681 | the DBus service went away, or some other problem or disconnection.</p> |
| 4682 | </div> |
| 4683 | <div class="paragraph"> |
| 4684 | <p>The <code>options</code> will contain various close information, including a |
| 4685 | <code>"problem"</code> field which will be set if the channel was closed because |
| 4686 | of a problem.</p> |
| 4687 | </div> |
| 4688 | </div> |
| 4689 | <div class="sect4"> |
| 4690 | <h5 id="cockpit-dbus-onowned">client.onowner</h5> |
| 4691 | <div class="literalblock"> |
| 4692 | <div class="content"> |
| 4693 | <pre>client.addEventListener("owner", (event, owner) => { ... })</pre> |
| 4694 | </div> |
| 4695 | </div> |
| 4696 | <div class="paragraph"> |
| 4697 | <p>An event triggered when the owner of the DBus name changes. The owner |
| 4698 | value will be the id of the name owner on the bus or null if the name is |
| 4699 | unowned. The absence of an owner should not be treated as a |
| 4700 | disconnection. However this makes it possible to take some action based |
| 4701 | on the actual status of the service, for example disconnecting a pending |
| 4702 | signal handler.</p> |
| 4703 | </div> |
| 4704 | </div> |
| 4705 | <div class="sect4"> |
| 4706 | <h5 id="cockpit-dbus-options">client.options</h5> |
| 4707 | <div class="paragraph"> |
| 4708 | <p>Set to the options used when creating the client. Will not change for |
| 4709 | the life of the client.</p> |
| 4710 | </div> |
| 4711 | </div> |
| 4712 | <div class="sect4"> |
| 4713 | <h5 id="cockpit-dbus-unique-name">client.unique_name</h5> |
| 4714 | <div class="paragraph"> |
| 4715 | <p>The unique DBus name of the client. Initially null, and becomes valid |
| 4716 | once the the client is ready.</p> |
| 4717 | </div> |
| 4718 | </div> |
| 4719 | <div class="sect4"> |
| 4720 | <h5 id="cockpit-dbus-proxy">client.proxy()</h5> |
| 4721 | <div class="literalblock"> |
| 4722 | <div class="content"> |
| 4723 | <pre>proxy = client.proxy([interface, path], [options])</pre> |
| 4724 | </div> |
| 4725 | </div> |
| 4726 | <div class="paragraph"> |
| 4727 | <p>Create proxy javascript object for a DBus <code>interface</code>. At the |
| 4728 | specified DBus object <code>path</code>. The proxy will have properties, methods |
| 4729 | and signals from to the DBus interface, and allows for natural |
| 4730 | interaction. If no <code>interface</code> is specified then the DBus bus name of |
| 4731 | the client is used. If no <code>path</code> is specified, then the DBus name of |
| 4732 | the client is converted to a path.</p> |
| 4733 | </div> |
| 4734 | <div class="paragraph"> |
| 4735 | <p>If creating lots of proxies for a given <code>interface</code> it is more |
| 4736 | efficient to use the <a href="#cockpit-dbus-proxies"><code>client.proxies()</code></a> |
| 4737 | function.</p> |
| 4738 | </div> |
| 4739 | <div class="paragraph"> |
| 4740 | <p>The proxy is loaded when the |
| 4741 | <a href="#cockpit-dbus-proxy-valid"><code>proxy.valid</code></a> field is <code>true</code>, and |
| 4742 | it is set to <code>false</code> if the underlying <code>interface</code> and/or <code>path</code> |
| 4743 | don’t or no longer exist, or the <code>client</code> has closed. You can wait for |
| 4744 | proxy to become valid by passing a callback to its |
| 4745 | <a href="#cockpit-dbus-proxy-wait"><code>proxy.wait()</code></a> function. The |
| 4746 | <a href="#cockpit-dbus-proxy-onchanged"><code>proxy.onchanged</code></a> event will also |
| 4747 | fire when the proxy becomes valid or invalid. DBus properties and |
| 4748 | methods on the proxy are not defined until the proxy becomes valid.</p> |
| 4749 | </div> |
| 4750 | <div class="literalblock"> |
| 4751 | <div class="content"> |
| 4752 | <pre>value = proxy.Prop1 |
| 4753 | proxy.WritableProp = value</pre> |
| 4754 | </div> |
| 4755 | </div> |
| 4756 | <div class="paragraph"> |
| 4757 | <p>All DBus properties on the <code>interface</code> that start with an upper case |
| 4758 | letter (as is convention) will be automatically defined on this proxy, |
| 4759 | and will update their values as the DBus property values change. In |
| 4760 | addition the <a href="#cockpit-dbus-proxy-onchanged"><code>proxy.onchanged</code></a> |
| 4761 | event will fire every time the properties change.</p> |
| 4762 | </div> |
| 4763 | <div class="paragraph"> |
| 4764 | <p>If you assign a value to a writable property on the proxy, the proxy |
| 4765 | will try to set that property on the DBus <code>interface</code> at <code>path</code>. The |
| 4766 | actual proxy property value will not update until the DBus service has |
| 4767 | notified the proxy of the change. If setting a property fails a warning |
| 4768 | will be logged. In order to have more reliable setting of properties, or |
| 4769 | track when they have been set, or if setting fails, use the |
| 4770 | <a href="#cockpit-dbus-call"><code>client.call()</code></a> directly. It should be noted |
| 4771 | that DBus service implementations may also be inconsistent in their |
| 4772 | behavior when setting a property fails.</p> |
| 4773 | </div> |
| 4774 | <div class="paragraph"> |
| 4775 | <p>You can access the raw property data using the |
| 4776 | <a href="#cockpit-dbus-proxy-data"><code>proxy.data</code></a> field, including data for |
| 4777 | properties that do not start with an upper case letter.</p> |
| 4778 | </div> |
| 4779 | <div class="literalblock"> |
| 4780 | <div class="content"> |
| 4781 | <pre>proxy.Method(arg1, arg2) |
| 4782 | .then((retval1, retval2) => { |
| 4783 | ... |
| 4784 | }) |
| 4785 | .catch(ex => { |
| 4786 | ... |
| 4787 | });</pre> |
| 4788 | </div> |
| 4789 | </div> |
| 4790 | <div class="paragraph"> |
| 4791 | <p>All DBus methods on the <code>interface</code> that start with an upper case |
| 4792 | letter (as is convention) will be automatically defined on this proxy. |
| 4793 | These methods are called with arguments as normal javascript arguments. |
| 4794 | A |
| 4795 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> |
| 4796 | that will complete successfully when the method returns, or fail if an |
| 4797 | error occurs. The return values from the DBus method will be passed to |
| 4798 | the <code>then</code> handler function directly.</p> |
| 4799 | </div> |
| 4800 | <div class="paragraph"> |
| 4801 | <p>Methods that do not start with an upper case letter can be invoked by |
| 4802 | using the usual <a href="#cockpit-dbus-proxy-call"><code>proxy.call()</code></a> |
| 4803 | directly.</p> |
| 4804 | </div> |
| 4805 | <div class="literalblock"> |
| 4806 | <div class="content"> |
| 4807 | <pre>proxy.addEventListener("signal", (event, arg1, arg2) => { |
| 4808 | ... |
| 4809 | });</pre> |
| 4810 | </div> |
| 4811 | </div> |
| 4812 | <div class="paragraph"> |
| 4813 | <p>All DBus signals on the <code>interface</code> that start with an upper case |
| 4814 | letter (as is convention) will be automatically emit events on this |
| 4815 | proxy. These events will contain the signal arguments after the standard |
| 4816 | <code>event</code> argument.</p> |
| 4817 | </div> |
| 4818 | <div class="paragraph"> |
| 4819 | <p>Signals that do not start with an upper case letter can be subscribed to |
| 4820 | by using <a href="#cockpit-dbus-proxy-signal"><code>proxy.onsignal</code></a> directly.</p> |
| 4821 | </div> |
| 4822 | <div class="paragraph"> |
| 4823 | <p>Usually a proxy asks the <code>client</code> to watch and notify it of changes to |
| 4824 | the relevant object or path. You can pass an <code>options</code> argument with |
| 4825 | the <code>watch</code> field set to <code>false</code> to prevent this.</p> |
| 4826 | </div> |
| 4827 | </div> |
| 4828 | <div class="sect4"> |
| 4829 | <h5 id="cockpit-dbus-proxy-client">proxy.client</h5> |
| 4830 | <div class="paragraph"> |
| 4831 | <p>Set to the DBus client of the proxy. Will not change for the life of the |
| 4832 | proxy.</p> |
| 4833 | </div> |
| 4834 | </div> |
| 4835 | <div class="sect4"> |
| 4836 | <h5 id="cockpit-dbus-proxy-path">proxy.path</h5> |
| 4837 | <div class="paragraph"> |
| 4838 | <p>Set to the DBus object path of the proxy. Will not change for the life |
| 4839 | of the proxy.</p> |
| 4840 | </div> |
| 4841 | </div> |
| 4842 | <div class="sect4"> |
| 4843 | <h5 id="cockpit-dbus-proxy-iface">proxy.iface</h5> |
| 4844 | <div class="paragraph"> |
| 4845 | <p>Set to the DBus interface name of the proxy. Will not change for the |
| 4846 | life of the proxy.</p> |
| 4847 | </div> |
| 4848 | </div> |
| 4849 | <div class="sect4"> |
| 4850 | <h5 id="cockpit-dbus-proxy-valid">proxy.valid</h5> |
| 4851 | <div class="paragraph"> |
| 4852 | <p>Set to <code>true</code> when the proxy’s DBus interface is present at its DBus |
| 4853 | path, and all information for the proxy has loaded. Is set to <code>false</code> |
| 4854 | while loading, and after the proxy no longer refers a DBus interface and |
| 4855 | path. Also set to <code>false</code> if the <code>client</code> closes.</p> |
| 4856 | </div> |
| 4857 | <div class="paragraph"> |
| 4858 | <p>Use the by <a href="#cockpit-dbus-proxy-wait"><code>proxy.wait()</code></a> function to |
| 4859 | wait for a proxy to load. The |
| 4860 | <a href="#cockpit-dbus-proxy-onchanged"><code>proxy.onchanged</code></a> event will also |
| 4861 | be emitted when the proxy becomes valid or invalid. DBus properties and |
| 4862 | methods on the proxy are not defined until the proxy becomes valid.</p> |
| 4863 | </div> |
| 4864 | </div> |
| 4865 | <div class="sect4"> |
| 4866 | <h5 id="cockpit-dbus-proxy-data">proxy.data</h5> |
| 4867 | <div class="paragraph"> |
| 4868 | <p>A plain javascript object containing all the raw property data that this |
| 4869 | proxy has loaded. This will be updated automatically as the proxy is |
| 4870 | notified of property changes from the DBus service. The |
| 4871 | <a href="#cockpit-dbus-proxy-onchanged"><code>proxy.onchanged</code></a> event will be |
| 4872 | emitted when it changes.</p> |
| 4873 | </div> |
| 4874 | </div> |
| 4875 | <div class="sect4"> |
| 4876 | <h5 id="cockpit-dbus-proxy-call">proxy.call()</h5> |
| 4877 | <div class="literalblock"> |
| 4878 | <div class="content"> |
| 4879 | <pre>invocation = proxy.call(method, args, [options])</pre> |
| 4880 | </div> |
| 4881 | </div> |
| 4882 | <div class="paragraph"> |
| 4883 | <p>Make a DBus method call on this proxy.</p> |
| 4884 | </div> |
| 4885 | <div class="paragraph"> |
| 4886 | <p>For DBus methods that start with an upper case letter, is usually more |
| 4887 | convenient <a href="#cockpit-dbus-proxy">to call the method directly on the |
| 4888 | proxy</a>. However if methods that do not follow the usual DBus convention, |
| 4889 | or specify additional options, or the caller cannot be sure that the |
| 4890 | method actually exists, you can use this method.</p> |
| 4891 | </div> |
| 4892 | <div class="paragraph"> |
| 4893 | <p>This function also works on proxies that have are still loading and have |
| 4894 | not become valid yet.</p> |
| 4895 | </div> |
| 4896 | <div class="paragraph"> |
| 4897 | <p>The <code>method</code> should be a DBus method name, and the <code>args</code> should be |
| 4898 | an array of arguments to pass to the method. The <code>options</code> are |
| 4899 | <a href="#cockpit-dbus-call">described elsewhere</a>.</p> |
| 4900 | </div> |
| 4901 | <div class="paragraph"> |
| 4902 | <p>The returned value is identical to the one returned from |
| 4903 | <a href="#cockpit-dbus-call">client.call()</a>. It is a |
| 4904 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> |
| 4905 | that will complete successfully when the method returns, or fail if an |
| 4906 | error occurs.</p> |
| 4907 | </div> |
| 4908 | </div> |
| 4909 | <div class="sect4"> |
| 4910 | <h5 id="cockpit-dbus-proxy-wait">proxy.wait()</h5> |
| 4911 | <div class="literalblock"> |
| 4912 | <div class="content"> |
| 4913 | <pre>promise = proxy.wait() |
| 4914 | proxy.wait(() => { |
| 4915 | ... |
| 4916 | });</pre> |
| 4917 | </div> |
| 4918 | </div> |
| 4919 | <div class="paragraph"> |
| 4920 | <p>Wait for a proxy to finish loading. This function returns a promise. If |
| 4921 | a callback function is passed as an argument then that function will be |
| 4922 | invoked when the proxy is ready. If this method is called after a proxy |
| 4923 | has already loaded, then the promise will be resolved immediately, and |
| 4924 | any callback will be invoked immediately. Use the promise or |
| 4925 | <code>proxy.valid</code> to determine whether the proxy is valid.</p> |
| 4926 | </div> |
| 4927 | </div> |
| 4928 | <div class="sect4"> |
| 4929 | <h5 id="cockpit-dbus-proxy-onchanged">proxy.onchanged</h5> |
| 4930 | <div class="literalblock"> |
| 4931 | <div class="content"> |
| 4932 | <pre>proxy.addEventListener("changed", (event, data) => { |
| 4933 | ... |
| 4934 | });</pre> |
| 4935 | </div> |
| 4936 | </div> |
| 4937 | <div class="paragraph"> |
| 4938 | <p>This event is emitted when the proxy’s properties change.</p> |
| 4939 | </div> |
| 4940 | <div class="paragraph"> |
| 4941 | <p>The <code>data</code> has the following form, and will only include properties |
| 4942 | that have changed:</p> |
| 4943 | </div> |
| 4944 | <div class="literalblock"> |
| 4945 | <div class="content"> |
| 4946 | <pre>{ |
| 4947 | "Prop1": "value", |
| 4948 | "Prop2": 5 |
| 4949 | }</pre> |
| 4950 | </div> |
| 4951 | </div> |
| 4952 | </div> |
| 4953 | <div class="sect4"> |
| 4954 | <h5 id="cockpit-dbus-proxy-signal">proxy.onsignal</h5> |
| 4955 | <div class="literalblock"> |
| 4956 | <div class="content"> |
| 4957 | <pre>proxy.addEventListener("signal", (event, name, args) => { |
| 4958 | ... |
| 4959 | });</pre> |
| 4960 | </div> |
| 4961 | </div> |
| 4962 | <div class="paragraph"> |
| 4963 | <p>This event is emitted when the proxy’s emits an event.</p> |
| 4964 | </div> |
| 4965 | <div class="paragraph"> |
| 4966 | <p>For most events, that have names which start with an upper case letter, |
| 4967 | you can just <a href="#cockpit-dbus-proxy">connect to that event as a signal |
| 4968 | directly</a>. However if you wish to be notified when any signal is |
| 4969 | emitted, or for signals that do not follow the usual DBus convention, |
| 4970 | you can connect to this event.</p> |
| 4971 | </div> |
| 4972 | <div class="paragraph"> |
| 4973 | <p>The <code>name</code> is the DBus signal name, and the <code>args</code> is an array of |
| 4974 | arguments that were emitted with the signal.</p> |
| 4975 | </div> |
| 4976 | </div> |
| 4977 | <div class="sect4"> |
| 4978 | <h5 id="cockpit-dbus-proxies">client.proxies()</h5> |
| 4979 | <div class="literalblock"> |
| 4980 | <div class="content"> |
| 4981 | <pre>proxies = client.proxies([interface], [path_namespace], [options])</pre> |
| 4982 | </div> |
| 4983 | </div> |
| 4984 | <div class="paragraph"> |
| 4985 | <p>Create <a href="#cockpit-dbus-proxy">proxy javascript objects</a> for a DBus |
| 4986 | interfaces. The proxies will have properties, methods and signals from |
| 4987 | the DBus <code>interface</code>, and allow for natural interaction. If no |
| 4988 | <code>interface</code> is specified then the DBus bus name of the client is used. |
| 4989 | If no <code>path_namespace</code> is provided then <code>"/"</code> will be used.</p> |
| 4990 | </div> |
| 4991 | <div class="paragraph"> |
| 4992 | <p>Proxies will be automatically created for instances of the <code>interface</code> |
| 4993 | available at the DBus service. The optional <code>path_namespace</code> argument |
| 4994 | can be used to restrict the proxies for instances that have DBus paths |
| 4995 | which have the namespace path prefix.</p> |
| 4996 | </div> |
| 4997 | <div class="literalblock"> |
| 4998 | <div class="content"> |
| 4999 | <pre>proxy1 = proxies["/dbus/path1"]; |
| 5000 | proxy2 = proxies["/dbus/path2"]; |
| 5001 | for (proxy in proxies) { |
| 5002 | ... |
| 5003 | }</pre> |
| 5004 | </div> |
| 5005 | </div> |
| 5006 | <div class="paragraph"> |
| 5007 | <p>The returned <code>proxies</code> object will is used as a dictionary, and will |
| 5008 | have values containing proxies for DBus interface instances, with the |
| 5009 | keys being the DBus paths of those instances. It is possible to |
| 5010 | enumerate over the returned <code>proxies</code>.</p> |
| 5011 | </div> |
| 5012 | <div class="paragraph"> |
| 5013 | <p>Proxies will be automatically added and removed from the <code>proxies</code> |
| 5014 | object as they appear and disappear in the service. The |
| 5015 | <a href="#cockpit-dbus-proxies-onadded"><code>proxies.onadded</code></a> and |
| 5016 | <a href="#cockpit-dbus-proxies-onremoved"><code>proxies.onremoved</code></a> events will |
| 5017 | be emitted. DBus services may not support notifications of paths |
| 5018 | disappearing.</p> |
| 5019 | </div> |
| 5020 | <div class="paragraph"> |
| 5021 | <p>Use the <code>proxies.wait()</code> function to be notified when the initial set |
| 5022 | of proxies has been populated.</p> |
| 5023 | </div> |
| 5024 | <div class="paragraph"> |
| 5025 | <p>Usually a proxies ask the <code>client</code> to watch and be notified of changes |
| 5026 | to the relevant object or path. You can pass an <code>options</code> argument |
| 5027 | with the <code>watch</code> field set to <code>false</code> to prevent this.</p> |
| 5028 | </div> |
| 5029 | </div> |
| 5030 | <div class="sect4"> |
| 5031 | <h5 id="cockpit-dbus-proxies-wait">proxies.wait()</h5> |
| 5032 | <div class="literalblock"> |
| 5033 | <div class="content"> |
| 5034 | <pre>promise = proxies.wait() |
| 5035 | proxies.wait(() => { |
| 5036 | ... |
| 5037 | });</pre> |
| 5038 | </div> |
| 5039 | </div> |
| 5040 | <div class="paragraph"> |
| 5041 | <p>Wait for a <code>proxies</code> object to populate its initial set of proxies. |
| 5042 | This function returns a promise. If a callback function is passed as an |
| 5043 | argument then that function will be invoked when the proxies are ready. |
| 5044 | If this method is called after the proxies have populated, then the |
| 5045 | promise will be resolved immediately, and any callback will be invoked |
| 5046 | immediately.</p> |
| 5047 | </div> |
| 5048 | </div> |
| 5049 | <div class="sect4"> |
| 5050 | <h5 id="cockpit-dbus-proxies-client">proxies.client</h5> |
| 5051 | <div class="paragraph"> |
| 5052 | <p>Set to the DBus client of the proxies. Will not change.</p> |
| 5053 | </div> |
| 5054 | </div> |
| 5055 | <div class="sect4"> |
| 5056 | <h5 id="cockpit-dbus-proxies-iface">proxies.iface</h5> |
| 5057 | <div class="paragraph"> |
| 5058 | <p>Set to the DBus interface name of the proxies. Will not change.</p> |
| 5059 | </div> |
| 5060 | </div> |
| 5061 | <div class="sect4"> |
| 5062 | <h5 id="cockpit-dbus-proxies-path_namespace">proxies.path_namespace</h5> |
| 5063 | <div class="paragraph"> |
| 5064 | <p>Set to the DBus path namespace used which the proxies must have as a |
| 5065 | DBus path prefix. Will not change.</p> |
| 5066 | </div> |
| 5067 | </div> |
| 5068 | <div class="sect4"> |
| 5069 | <h5 id="cockpit-dbus-proxies-onadded">proxies.onadded</h5> |
| 5070 | <div class="literalblock"> |
| 5071 | <div class="content"> |
| 5072 | <pre>proxies.addEventListener("added", (event, proxy) => { |
| 5073 | ... |
| 5074 | })</pre> |
| 5075 | </div> |
| 5076 | </div> |
| 5077 | <div class="paragraph"> |
| 5078 | <p>This event is emitted when a proxy is added to the <code>proxies</code> object. |
| 5079 | The proxy will already have loaded.</p> |
| 5080 | </div> |
| 5081 | </div> |
| 5082 | <div class="sect4"> |
| 5083 | <h5 id="cockpit-dbus-proxies-onchanged">proxies.onchanged</h5> |
| 5084 | <div class="literalblock"> |
| 5085 | <div class="content"> |
| 5086 | <pre>proxies.addEventListener("changed", (event, proxy) => { |
| 5087 | ... |
| 5088 | })</pre> |
| 5089 | </div> |
| 5090 | </div> |
| 5091 | <div class="paragraph"> |
| 5092 | <p>This event is emitted when one of the proxy in the <code>proxies</code> object |
| 5093 | changes its properties.</p> |
| 5094 | </div> |
| 5095 | </div> |
| 5096 | <div class="sect4"> |
| 5097 | <h5 id="cockpit-dbus-proxies-onremoved">proxies.onremoved</h5> |
| 5098 | <div class="literalblock"> |
| 5099 | <div class="content"> |
| 5100 | <pre>proxies.addEventListener("removed", (event, proxy) => { |
| 5101 | ... |
| 5102 | })</pre> |
| 5103 | </div> |
| 5104 | </div> |
| 5105 | <div class="paragraph"> |
| 5106 | <p>This event is emitted when a proxy is removed to the <code>proxies</code> object.</p> |
| 5107 | </div> |
| 5108 | </div> |
| 5109 | <div class="sect4"> |
| 5110 | <h5 id="cockpit-dbus-call">client.call()</h5> |
| 5111 | <div class="literalblock"> |
| 5112 | <div class="content"> |
| 5113 | <pre>invocation = client.call(path, interface, method, args, [options])</pre> |
| 5114 | </div> |
| 5115 | </div> |
| 5116 | <div class="paragraph"> |
| 5117 | <p>Make a DBus method call.</p> |
| 5118 | </div> |
| 5119 | <div class="paragraph"> |
| 5120 | <p>The <code>path</code> is the DBus object path to make the call on, <code>interface</code> |
| 5121 | is the DBus interface for the method and <code>method</code> is the name of the |
| 5122 | method to call. The <code>args</code> is an array of arguments to pass to the |
| 5123 | method, each of which must be appropriate for the expected |
| 5124 | <a href="#cockpit-dbus">DBus type</a> of that argument. The <code>args</code> may be |
| 5125 | <code>null</code> if no arguments are to be sent.</p> |
| 5126 | </div> |
| 5127 | <div class="paragraph"> |
| 5128 | <p>The returned value is a |
| 5129 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> |
| 5130 | that will complete successfully when the method returns, or fail if an |
| 5131 | error occurs.</p> |
| 5132 | </div> |
| 5133 | <div class="paragraph"> |
| 5134 | <p>If <code>options</code> is specified it should be a plain javascript object, |
| 5135 | which may contain the following properties:</p> |
| 5136 | </div> |
| 5137 | <div class="dlist"> |
| 5138 | <dl> |
| 5139 | <dt class="hdlist1"><code>flags</code></dt> |
| 5140 | <dd> |
| 5141 | <p>A string containing DBus message flags. The character <code>"i"</code> |
| 5142 | indicates to the dbus service that interactive authentication is |
| 5143 | allowed. If the entire <code>flags</code> field is missing, then <code>"i"</code> is set |
| 5144 | by default.</p> |
| 5145 | </dd> |
| 5146 | <dt class="hdlist1"><code>type</code></dt> |
| 5147 | <dd> |
| 5148 | <p>A valid DBus type signature to use when calling the method. In the |
| 5149 | absence of this, the DBus service will be introspected (and the result |
| 5150 | cached) to ask what the method type signature is.</p> |
| 5151 | </dd> |
| 5152 | <dt class="hdlist1"><code>timeout</code></dt> |
| 5153 | <dd> |
| 5154 | <p>The timeout of the call in milliseconds. The call will fail with the |
| 5155 | <code>"timeout"</code> problem code. If "timeout" is not given, the call will |
| 5156 | never time out.</p> |
| 5157 | </dd> |
| 5158 | </dl> |
| 5159 | </div> |
| 5160 | </div> |
| 5161 | <div class="sect4"> |
| 5162 | <h5 id="cockpit-dbus-then">invocation.then()</h5> |
| 5163 | <div class="literalblock"> |
| 5164 | <div class="content"> |
| 5165 | <pre>invocation.then((args, options) => { ... })</pre> |
| 5166 | </div> |
| 5167 | </div> |
| 5168 | <div class="paragraph"> |
| 5169 | <p>This is a standard |
| 5170 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> |
| 5171 | method. It sets up a handler to be called when the DBus method call |
| 5172 | finishes successfully.</p> |
| 5173 | </div> |
| 5174 | <div class="paragraph"> |
| 5175 | <p>The <code>args</code> argument is an array of return values from the DBus method. |
| 5176 | Each of them will be converted to an appropriate |
| 5177 | <a href="#cockpit-dbus">javascript type</a>.</p> |
| 5178 | </div> |
| 5179 | <div class="paragraph"> |
| 5180 | <p>The <code>options</code> argument may contain additional information about the |
| 5181 | reply. If the <code>type</code> option was specified when performing the method |
| 5182 | call, then the <code>options</code> in the reply here will also contain a |
| 5183 | <code>type</code> field containing the DBus type signature of the output. If the |
| 5184 | <code>flags</code> option was specified when performing the call then the |
| 5185 | <code>options</code> in the reply here will contain message flags. Possible out |
| 5186 | message flags are:</p> |
| 5187 | </div> |
| 5188 | <div class="dlist"> |
| 5189 | <dl> |
| 5190 | <dt class="hdlist1"><code>></code></dt> |
| 5191 | <dd> |
| 5192 | <p>A big endian message.</p> |
| 5193 | </dd> |
| 5194 | <dt class="hdlist1"><code><</code></dt> |
| 5195 | <dd> |
| 5196 | <p>A little endian message.</p> |
| 5197 | </dd> |
| 5198 | </dl> |
| 5199 | </div> |
| 5200 | </div> |
| 5201 | <div class="sect4"> |
| 5202 | <h5 id="cockpit-dbus-catch">invocation.catch()</h5> |
| 5203 | <div class="literalblock"> |
| 5204 | <div class="content"> |
| 5205 | <pre>invocation.catch(exception => { ... })</pre> |
| 5206 | </div> |
| 5207 | </div> |
| 5208 | <div class="paragraph"> |
| 5209 | <p>This is a standard |
| 5210 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> |
| 5211 | method. It sets up a handler to be called when the DBus method call |
| 5212 | fails.</p> |
| 5213 | </div> |
| 5214 | <div class="paragraph"> |
| 5215 | <p>The <code>exception</code> object passed to the handler can have the following |
| 5216 | properties:</p> |
| 5217 | </div> |
| 5218 | <div class="dlist"> |
| 5219 | <dl> |
| 5220 | <dt class="hdlist1"><code>problem</code></dt> |
| 5221 | <dd> |
| 5222 | <p>A <a href="cockpit-error.html#cockpit-problems">problem code</a> string when a problem occurred |
| 5223 | starting or communicating with the DBus service. This is <code>null</code> in |
| 5224 | the cases where an actual DBus error was occurred.</p> |
| 5225 | </dd> |
| 5226 | <dt class="hdlist1"><code>name</code></dt> |
| 5227 | <dd> |
| 5228 | <p>The DBus error name. This will be <code>null</code> in cases where the failure |
| 5229 | was not due to a DBus error.</p> |
| 5230 | </dd> |
| 5231 | <dt class="hdlist1"><code>message</code></dt> |
| 5232 | <dd> |
| 5233 | <p>A DBus error message. This will be <code>null</code> in cases where the failure |
| 5234 | was not due to a DBus error.</p> |
| 5235 | </dd> |
| 5236 | </dl> |
| 5237 | </div> |
| 5238 | </div> |
| 5239 | <div class="sect4"> |
| 5240 | <h5 id="cockpit-dbus-subscribe">client.subscribe()</h5> |
| 5241 | <div class="literalblock"> |
| 5242 | <div class="content"> |
| 5243 | <pre>subscription = client.subscribe(match, (path, interface, signal, args) => { ... })</pre> |
| 5244 | </div> |
| 5245 | </div> |
| 5246 | <div class="paragraph"> |
| 5247 | <p>Subscribe to signals. The <code>match</code> argument is a javascript plain |
| 5248 | object which defines what signals to subscribe to. Each property in the |
| 5249 | <code>match</code> argument restricts signals subscribed to. If a property is not |
| 5250 | present then it is treated as a wildcard, matching anything. If an empty |
| 5251 | object is specified as <code>match</code> then all signals will be subscribed to. |
| 5252 | The <code>match</code> argument may contain the following properties:</p> |
| 5253 | </div> |
| 5254 | <div class="dlist"> |
| 5255 | <dl> |
| 5256 | <dt class="hdlist1"><code>interface</code></dt> |
| 5257 | <dd> |
| 5258 | <p>A DBus interface to match.</p> |
| 5259 | </dd> |
| 5260 | <dt class="hdlist1"><code>path</code></dt> |
| 5261 | <dd> |
| 5262 | <p>A DBus object path to match. May not be used together with the |
| 5263 | <code>path_namespace</code> property. It should be a valid DBus object path, |
| 5264 | that is, it should have no trailing slash.</p> |
| 5265 | </dd> |
| 5266 | <dt class="hdlist1"><code>path_namespace</code></dt> |
| 5267 | <dd> |
| 5268 | <p>A DBus object path prefix to match. Any paths in the hierarchy below |
| 5269 | this top path will match. May not be used together with the <code>path</code> |
| 5270 | property.</p> |
| 5271 | </dd> |
| 5272 | <dt class="hdlist1"><code>member</code></dt> |
| 5273 | <dd> |
| 5274 | <p>The DBus signal name to match.</p> |
| 5275 | </dd> |
| 5276 | <dt class="hdlist1"><code>arg0</code></dt> |
| 5277 | <dd> |
| 5278 | <p>Matches the first argument of a DBus message, which must be a string.</p> |
| 5279 | </dd> |
| 5280 | </dl> |
| 5281 | </div> |
| 5282 | <div class="paragraph"> |
| 5283 | <p>The handler passed as the second argument will be invoked when the |
| 5284 | signal is received. A <code>subscription</code> is returned which can be used to |
| 5285 | remove the subscription by calling its <code>subscription.remove()</code> method.</p> |
| 5286 | </div> |
| 5287 | <div class="paragraph"> |
| 5288 | <p>It is not a problem to subscribe to the same signals more than once, |
| 5289 | with identical or slightly different <code>match</code> arguments.</p> |
| 5290 | </div> |
| 5291 | </div> |
| 5292 | <div class="sect4"> |
| 5293 | <h5 id="cockpit-dbus-remove">subscription.remove()</h5> |
| 5294 | <div class="literalblock"> |
| 5295 | <div class="content"> |
| 5296 | <pre>subscription.remove()</pre> |
| 5297 | </div> |
| 5298 | </div> |
| 5299 | <div class="paragraph"> |
| 5300 | <p>Unsubscribe from the DBus signal subscription.</p> |
| 5301 | </div> |
| 5302 | </div> |
| 5303 | <div class="sect4"> |
| 5304 | <h5 id="cockpit-dbus-watch">client.watch()</h5> |
| 5305 | <div class="literalblock"> |
| 5306 | <div class="content"> |
| 5307 | <pre>watch = client.watch(path) |
| 5308 | watch = client.watch({ "path_namespace": path_namespace, "interface": interface })</pre> |
| 5309 | </div> |
| 5310 | </div> |
| 5311 | <div class="paragraph"> |
| 5312 | <p>Watch for property and interface changes on the given DBus object |
| 5313 | <code>path</code> DBus <code>path_namespace</code>. If <code>interface</code> is specified only |
| 5314 | properties on that DBus interface will be watched.</p> |
| 5315 | </div> |
| 5316 | <div class="paragraph"> |
| 5317 | <p>The <a href="#cockpit-dbus-proxy"><code>client.proxy()</code></a> and |
| 5318 | <a href="#cockpit-dbus-proxies"><code>client.proxies()</code></a> functions and the |
| 5319 | objects they return are high level wrappers around <code>client.watch()</code>.</p> |
| 5320 | </div> |
| 5321 | <div class="paragraph"> |
| 5322 | <p>The property and interface changes will be available in raw form on the |
| 5323 | <a href="#cockpit-dbus-onnotify"><code>client.onnotify</code></a> event.</p> |
| 5324 | </div> |
| 5325 | <div class="paragraph"> |
| 5326 | <p>Property and interface changes that are caused by a method call or |
| 5327 | signal will show up before that method call reply is received, or signal |
| 5328 | event is triggered. It should be possible to rely on this guarantee, |
| 5329 | unless the DBus service in question behaves incorrectly. Internally |
| 5330 | these watches work well with code that implements the |
| 5331 | <a href="https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-objectmanager">ObjectManager</a> |
| 5332 | portion of the DBus specification. If no ObjectManager implementation is |
| 5333 | available, the watch falls back to using DBus |
| 5334 | <a href="https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-introspectable">Introspection</a> |
| 5335 | along with the usual |
| 5336 | <a href="https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties">PropertiesChanged</a> |
| 5337 | signal. If the DBus service implements none of these, or implements them |
| 5338 | in an inconsistent manner, then this function will provide inconsistent |
| 5339 | or unexpected results.</p> |
| 5340 | </div> |
| 5341 | <div class="paragraph"> |
| 5342 | <p>The parameter is either a DBus <code>path</code> or a plain javascript object |
| 5343 | with zero or more of the following fields. If an empty javascript object |
| 5344 | is used as an argument, then all paths, interfaces and properties will |
| 5345 | be watched.</p> |
| 5346 | </div> |
| 5347 | <div class="dlist"> |
| 5348 | <dl> |
| 5349 | <dt class="hdlist1"><code>interface</code></dt> |
| 5350 | <dd> |
| 5351 | <p>Watch properties on this DBus interface.</p> |
| 5352 | </dd> |
| 5353 | <dt class="hdlist1"><code>path</code></dt> |
| 5354 | <dd> |
| 5355 | <p>Watch interfaces and properties at this DBus path. May not be used |
| 5356 | together with the <code>path_namespace</code> property.</p> |
| 5357 | </dd> |
| 5358 | <dt class="hdlist1"><code>path_namespace</code></dt> |
| 5359 | <dd> |
| 5360 | <p>Watch interfaces and properties under this DBus path. It should be a |
| 5361 | valid DBus object path, that is, it should have no trailing slash. If |
| 5362 | an ObjectManager implementation is available at this interface, then |
| 5363 | it is used. May not be used together with the <code>path</code> property.</p> |
| 5364 | </dd> |
| 5365 | </dl> |
| 5366 | </div> |
| 5367 | <div class="paragraph"> |
| 5368 | <p>The returned value is a |
| 5369 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> |
| 5370 | that will complete successfully when the watch has populated its initial |
| 5371 | set of properties and interfaces, and these have been notified via |
| 5372 | <a href="#cockpit-dbus-onnotify"><code>client.onnotify</code></a>.</p> |
| 5373 | </div> |
| 5374 | <div class="paragraph"> |
| 5375 | <p>A watch can be removed by calling the |
| 5376 | <a href="#cockpit-dbus-watch-remove"><code>watch.remove()</code></a> method on the |
| 5377 | returned value. If identical watches are added more than once, then they |
| 5378 | must also be removed the same number of times before the removal takes |
| 5379 | effect.</p> |
| 5380 | </div> |
| 5381 | </div> |
| 5382 | <div class="sect4"> |
| 5383 | <h5 id="cockpit-dbus-watch-then">watch.then()</h5> |
| 5384 | <div class="literalblock"> |
| 5385 | <div class="content"> |
| 5386 | <pre>watch.then(() => { ... })</pre> |
| 5387 | </div> |
| 5388 | </div> |
| 5389 | <div class="paragraph"> |
| 5390 | <p>This is a standard |
| 5391 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> |
| 5392 | method. It sets up a handler to be called when the watch has populated |
| 5393 | its initial properties and interfaces.</p> |
| 5394 | </div> |
| 5395 | </div> |
| 5396 | <div class="sect4"> |
| 5397 | <h5 id="cockpit-dbus-watch-catch">watch.catch()</h5> |
| 5398 | <div class="literalblock"> |
| 5399 | <div class="content"> |
| 5400 | <pre>watch.catch(ex => { ... })</pre> |
| 5401 | </div> |
| 5402 | </div> |
| 5403 | <div class="paragraph"> |
| 5404 | <p>This is a standard |
| 5405 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> |
| 5406 | method. It sets up a handler to be called if the watch fails to populate |
| 5407 | its initial properties and interfaces. Note that a watch will only fail |
| 5408 | if the DBus client closes or is somehow disconnected. It does not fail |
| 5409 | in the case of missing interfaces or properties.</p> |
| 5410 | </div> |
| 5411 | </div> |
| 5412 | <div class="sect4"> |
| 5413 | <h5 id="cockpit-dbus-watch-remove">watch.remove()</h5> |
| 5414 | <div class="literalblock"> |
| 5415 | <div class="content"> |
| 5416 | <pre>watch.remove()</pre> |
| 5417 | </div> |
| 5418 | </div> |
| 5419 | <div class="paragraph"> |
| 5420 | <p>Remove the watch. This may not have any immediate effect if other |
| 5421 | watches are in place. In particular, if identical watches are added more |
| 5422 | than once, then they must also be removed the same number of times |
| 5423 | before the removal takes effect.</p> |
| 5424 | </div> |
| 5425 | </div> |
| 5426 | <div class="sect4"> |
| 5427 | <h5 id="cockpit-dbus-onnotify">client.onnotify</h5> |
| 5428 | <div class="literalblock"> |
| 5429 | <div class="content"> |
| 5430 | <pre>client.addEventListener("notify", data => { ... })</pre> |
| 5431 | </div> |
| 5432 | </div> |
| 5433 | <div class="paragraph"> |
| 5434 | <p>An event triggered when <a href="#cockpit-dbus-watch">watched</a> properties or |
| 5435 | interfaces change.</p> |
| 5436 | </div> |
| 5437 | <div class="paragraph"> |
| 5438 | <p>The <a href="#cockpit-dbus-proxy"><code>client.proxy()</code></a> and |
| 5439 | <a href="#cockpit-dbus-proxies"><code>client.proxies()</code></a> functions and the |
| 5440 | objects they return are high level wrappers around the <code>data</code> provided |
| 5441 | by this event.</p> |
| 5442 | </div> |
| 5443 | <div class="paragraph"> |
| 5444 | <p>The <code>data</code> has the following form:</p> |
| 5445 | </div> |
| 5446 | <div class="literalblock"> |
| 5447 | <div class="content"> |
| 5448 | <pre>{ |
| 5449 | "/path1": { |
| 5450 | "org.Interface1": { |
| 5451 | "Prop1": "value", |
| 5452 | "Prop2": 5 |
| 5453 | }, |
| 5454 | "org.Interface2": null |
| 5455 | } |
| 5456 | }</pre> |
| 5457 | </div> |
| 5458 | </div> |
| 5459 | <div class="paragraph"> |
| 5460 | <p>Multiple paths may be present, each of which may have multiple |
| 5461 | interfaces, each of which may have multiple properties. The first time a |
| 5462 | given path and interface is emitted from this signal, it will have all |
| 5463 | its properties and interfaces. Thereafter only changes are noted. If an |
| 5464 | interface is set to <code>null</code>, then that interface has disappeared.</p> |
| 5465 | </div> |
| 5466 | </div> |
| 5467 | <div class="sect4"> |
| 5468 | <h5 id="cockpit-dbus-notify">client.notify()</h5> |
| 5469 | <div class="literalblock"> |
| 5470 | <div class="content"> |
| 5471 | <pre>client.notify(data)</pre> |
| 5472 | </div> |
| 5473 | </div> |
| 5474 | <div class="paragraph"> |
| 5475 | <p>Emits a synthetic <a href="#cockpit-dbus-onnotify"><code>notify</code></a> event. The |
| 5476 | <code>data</code> argument should follow the same layout as described for the |
| 5477 | <code>notify</code> event.</p> |
| 5478 | </div> |
| 5479 | </div> |
| 5480 | <div class="sect4"> |
| 5481 | <h5 id="cockpit-dbus-onmeta">client.onmeta</h5> |
| 5482 | <div class="literalblock"> |
| 5483 | <div class="content"> |
| 5484 | <pre>client.onmeta = (ev, data) => { ... }</pre> |
| 5485 | </div> |
| 5486 | </div> |
| 5487 | <div class="paragraph"> |
| 5488 | <p>An event triggered when the meta data about |
| 5489 | <a href="#cockpit-dbus-watch">watched</a> interfaces is loaded.</p> |
| 5490 | </div> |
| 5491 | <div class="paragraph"> |
| 5492 | <p>The <a href="#cockpit-dbus-proxy"><code>client.proxy()</code></a> and |
| 5493 | <a href="#cockpit-dbus-proxies"><code>client.proxies()</code></a> functions and the |
| 5494 | objects they return are high level wrappers around the <code>data</code> provided |
| 5495 | by this event.</p> |
| 5496 | </div> |
| 5497 | <div class="paragraph"> |
| 5498 | <p>The <code>data</code> has the following form:</p> |
| 5499 | </div> |
| 5500 | <div class="literalblock"> |
| 5501 | <div class="content"> |
| 5502 | <pre> { |
| 5503 | "org.Interface": { |
| 5504 | "methods": { |
| 5505 | "Method1": { |
| 5506 | "in": [ "s", "v" ], |
| 5507 | "out": [ "i" ] |
| 5508 | }, |
| 5509 | "Method2": { } |
| 5510 | }, |
| 5511 | "signals": { |
| 5512 | "Signal": { |
| 5513 | "in": [ "b", "s" ] |
| 5514 | } |
| 5515 | }, |
| 5516 | "properties": { |
| 5517 | "Prop1": { |
| 5518 | "flags": "rw", |
| 5519 | "type": "s" |
| 5520 | }, |
| 5521 | "Prop2": { |
| 5522 | "flags": "r", |
| 5523 | "type": "b" |
| 5524 | } |
| 5525 | } |
| 5526 | } |
| 5527 | }</pre> |
| 5528 | </div> |
| 5529 | </div> |
| 5530 | <div class="paragraph"> |
| 5531 | <p>Multiple interfaces may be present, each of which may have methods and |
| 5532 | properties. This is emitted before the first |
| 5533 | <a href="#cockpit-dbus-proxy"><code>client.onnotify</code></a> event for the relevant |
| 5534 | interface.</p> |
| 5535 | </div> |
| 5536 | </div> |
| 5537 | <div class="sect4"> |
| 5538 | <h5 id="cockpit-dbus-variant">cockpit.variant()</h5> |
| 5539 | <div class="literalblock"> |
| 5540 | <div class="content"> |
| 5541 | <pre>variant = cockpit.variant(type, value)</pre> |
| 5542 | </div> |
| 5543 | </div> |
| 5544 | <div class="paragraph"> |
| 5545 | <p>A DBus variant is represented as a plain javascript object with a |
| 5546 | <code>"t"</code> property represesting the full DBus type of the variant, and a |
| 5547 | <code>"v"</code> property containing the variant value.</p> |
| 5548 | </div> |
| 5549 | <div class="paragraph"> |
| 5550 | <p>This is a helper function for creating such a variant object.</p> |
| 5551 | </div> |
| 5552 | </div> |
| 5553 | </div> |
| 5554 | <div class="sect3"> |
| 5555 | <h4 id="_cockpit_js_errors">cockpit.js: Errors</h4> |
| 5556 | <div class="paragraph"> |
| 5557 | <p>cockpit.js: Errors</p> |
| 5558 | </div> |
| 5559 | <div class="paragraph"> |
| 5560 | <p>Problem codes and messages</p> |
| 5561 | </div> |
| 5562 | <div class="sect4"> |
| 5563 | <h5 id="cockpit-problems">Problem Codes</h5> |
| 5564 | <div class="paragraph"> |
| 5565 | <p>Cockpit represents problems with standardized problem string codes.</p> |
| 5566 | </div> |
| 5567 | <div class="dlist"> |
| 5568 | <dl> |
| 5569 | <dt class="hdlist1"><code>"access-denied"</code></dt> |
| 5570 | <dd> |
| 5571 | <p>The user is not permitted to perform the action in question.</p> |
| 5572 | </dd> |
| 5573 | <dt class="hdlist1"><code>"authentication-failed"</code></dt> |
| 5574 | <dd> |
| 5575 | <p>User authentication failed.</p> |
| 5576 | </dd> |
| 5577 | <dt class="hdlist1"><code>"internal-error"</code></dt> |
| 5578 | <dd> |
| 5579 | <p>An unexpected internal error without further info. This should not |
| 5580 | happen during the normal course of operations.</p> |
| 5581 | </dd> |
| 5582 | <dt class="hdlist1"><code>"no-cockpit"</code></dt> |
| 5583 | <dd> |
| 5584 | <p>The system does not have a compatible version of Cockpit installed or |
| 5585 | installed properly.</p> |
| 5586 | </dd> |
| 5587 | <dt class="hdlist1"><code>"no-session"</code></dt> |
| 5588 | <dd> |
| 5589 | <p>Cockpit is not logged in.</p> |
| 5590 | </dd> |
| 5591 | <dt class="hdlist1"><code>"not-found"</code></dt> |
| 5592 | <dd> |
| 5593 | <p>Something specifically requested was not found, such as a file, |
| 5594 | executable etc.</p> |
| 5595 | </dd> |
| 5596 | <dt class="hdlist1"><code>"terminated"</code></dt> |
| 5597 | <dd> |
| 5598 | <p>Something was terminated forcibly, such as a connection, process |
| 5599 | session, etc.</p> |
| 5600 | </dd> |
| 5601 | <dt class="hdlist1"><code>"timeout"</code></dt> |
| 5602 | <dd> |
| 5603 | <p>Something timed out.</p> |
| 5604 | </dd> |
| 5605 | <dt class="hdlist1"><code>"unknown-hostkey"</code></dt> |
| 5606 | <dd> |
| 5607 | <p>The remote host had an unexpected or unknown key.</p> |
| 5608 | </dd> |
| 5609 | <dt class="hdlist1"><code>"no-forwarding"</code></dt> |
| 5610 | <dd> |
| 5611 | <p>Could not forward authentication credentials to the remote host.</p> |
| 5612 | </dd> |
| 5613 | </dl> |
| 5614 | </div> |
| 5615 | </div> |
| 5616 | <div class="sect4"> |
| 5617 | <h5 id="cockpit-messages">cockpit.message()</h5> |
| 5618 | <div class="literalblock"> |
| 5619 | <div class="content"> |
| 5620 | <pre>message = cockpit.message(problem) |
| 5621 | message = cockpit.message(exception)</pre> |
| 5622 | </div> |
| 5623 | </div> |
| 5624 | <div class="paragraph"> |
| 5625 | <p>Return a message for the <code>exception</code> or <code>problem</code> code passed as an |
| 5626 | argument. If the argument is an object with a <code>"message"</code> property, as |
| 5627 | is the case with most exceptions, that will be returned directly. If the |
| 5628 | argument is an object with a <code>"problem"</code> property, then it will be |
| 5629 | used as the problem code. An appropriate message will be returned for |
| 5630 | problem codes.</p> |
| 5631 | </div> |
| 5632 | </div> |
| 5633 | </div> |
| 5634 | <div class="sect3"> |
| 5635 | <h4 id="_cockpit_js_file_access">cockpit.js: File Access</h4> |
| 5636 | <div class="paragraph"> |
| 5637 | <p>The <code>cockpit.file</code> API lets you read, write, and watch regular files |
| 5638 | in their entirety. It cannot efficiently do random access in a big file |
| 5639 | or read non-regular files such as <code>/dev/random</code>.</p> |
| 5640 | </div> |
| 5641 | <div class="literalblock"> |
| 5642 | <div class="content"> |
| 5643 | <pre>file = cockpit.file(path, |
| 5644 | { syntax: syntax_object, |
| 5645 | binary: boolean, |
| 5646 | max_read_size: int, |
| 5647 | superuser: string, |
| 5648 | }) |
| 5649 | |
| 5650 | promise = file.read() |
| 5651 | promise |
| 5652 | .then((content, tag) => { ... }) |
| 5653 | .catch(error => { ... }) |
| 5654 | |
| 5655 | promise = file.replace(content, [ expected_tag ]) |
| 5656 | promise |
| 5657 | .then(new_tag => { ... }) |
| 5658 | .catch(error => { ... }) |
| 5659 | |
| 5660 | promise = file.modify(callback, [ initial_content, initial_tag ] |
| 5661 | promise |
| 5662 | .then((new_content, new_tag) => { ... }) |
| 5663 | .catch(error => { ... }) |
| 5664 | |
| 5665 | file.watch((content, tag, [error]) => { }, [ { read: boolean } ]) |
| 5666 | |
| 5667 | file.close()</pre> |
| 5668 | </div> |
| 5669 | </div> |
| 5670 | <div class="sect4"> |
| 5671 | <h5 id="cockpit-file-simple">Simple reading and writing</h5> |
| 5672 | <div class="paragraph"> |
| 5673 | <p>You can read a file with code like this:</p> |
| 5674 | </div> |
| 5675 | <div class="literalblock"> |
| 5676 | <div class="content"> |
| 5677 | <pre>cockpit.file("/path/to/file").read() |
| 5678 | .then((content, tag) => { |
| 5679 | ... |
| 5680 | }) |
| 5681 | .catch(error => { |
| 5682 | ... |
| 5683 | });</pre> |
| 5684 | </div> |
| 5685 | </div> |
| 5686 | <div class="paragraph"> |
| 5687 | <p>It is recommended to use absolute paths. Relative paths are resolved |
| 5688 | against <code>/</code>. To work with the current user’s files |
| 5689 | <a href="cockpit-login.html#cockpit-user">cockpit.user()</a> can be used to get the user’s home |
| 5690 | directory.</p> |
| 5691 | </div> |
| 5692 | <div class="paragraph"> |
| 5693 | <p>The <code>read()</code> method returns a |
| 5694 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>.</p> |
| 5695 | </div> |
| 5696 | <div class="paragraph"> |
| 5697 | <p>When successful, the promise will be resolved with the content of the |
| 5698 | file. Unless you specify options to change this (see below), the file is |
| 5699 | assumed to be text in the UTF-8 encoding, and <code>content</code> will be a |
| 5700 | string.</p> |
| 5701 | </div> |
| 5702 | <div class="paragraph"> |
| 5703 | <p>The tag that is passed to the <code>then()</code> callback is a short string that |
| 5704 | is associated with the file and changes whenever the content of the file |
| 5705 | changes. It is meant to be used with <code>replace()</code>.</p> |
| 5706 | </div> |
| 5707 | <div class="paragraph"> |
| 5708 | <p>It is not an error when the file does not exist. In this case, the |
| 5709 | <code>then()</code> callback will be called with a <code>null</code> value for <code>content</code> |
| 5710 | and <code>tag</code> is <code>"-"</code>.</p> |
| 5711 | </div> |
| 5712 | <div class="paragraph"> |
| 5713 | <p>The <code>superuser</code> option can be used the same way as described in the |
| 5714 | <a href="cockpit-channels.html#cockpit-channels-channel">cockpit.channel()</a> to provide a different |
| 5715 | access level to the file.</p> |
| 5716 | </div> |
| 5717 | <div class="paragraph"> |
| 5718 | <p>You can use the <code>max_read_size</code> option to limit the amount of data |
| 5719 | that is read. If the file is larger than the given number of bytes, no |
| 5720 | data is read and the channel is closed with problem code <code>too-large</code>. |
| 5721 | The default limit is 16 MiB. The limit can be completely removed by |
| 5722 | setting it to -1.</p> |
| 5723 | </div> |
| 5724 | <div class="paragraph"> |
| 5725 | <p>To write to a file, use code like this:</p> |
| 5726 | </div> |
| 5727 | <div class="literalblock"> |
| 5728 | <div class="content"> |
| 5729 | <pre>cockpit.file("/path/to/file").replace("my new content\n") |
| 5730 | .then(tag => { |
| 5731 | ... |
| 5732 | }) |
| 5733 | .catch(error => { |
| 5734 | ... |
| 5735 | });</pre> |
| 5736 | </div> |
| 5737 | </div> |
| 5738 | <div class="paragraph"> |
| 5739 | <p>The <code>replace()</code> method returns a |
| 5740 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>.</p> |
| 5741 | </div> |
| 5742 | <div class="paragraph"> |
| 5743 | <p>When the promise is resolved, the file has been atomically replaced (via |
| 5744 | the <code>rename()</code> syscall) with the new content. As with <code>read()</code>, by |
| 5745 | default the new content is a string and will be written to the file as |
| 5746 | UTF-8. The returned tag corresponds to the new content of the file.</p> |
| 5747 | </div> |
| 5748 | <div class="paragraph"> |
| 5749 | <p>When the promise is rejected because of an error, the file or its meta |
| 5750 | data has not been changed in any way.</p> |
| 5751 | </div> |
| 5752 | <div class="paragraph"> |
| 5753 | <p>As a special case, passing the value <code>null</code> to <code>replace()</code> will |
| 5754 | remove the file.</p> |
| 5755 | </div> |
| 5756 | <div class="paragraph"> |
| 5757 | <p>The <code>replace()</code> method can also check for conflicting changes to a |
| 5758 | file. You can pass a tag (as returned by <code>read()</code> or <code>replace()</code>) to |
| 5759 | <code>replace()</code>, and the file will only be replaced if it still has the |
| 5760 | given tag. If the tag of the file has changed, <code>replace()</code> will fail |
| 5761 | with an error object that has <code>error.problem == "change-conflict"</code>. |
| 5762 | See <code>modify()</code> below for a convenient way to achieve transactional |
| 5763 | updates to a file.</p> |
| 5764 | </div> |
| 5765 | </div> |
| 5766 | <div class="sect4"> |
| 5767 | <h5 id="cockpit-file-format">File format</h5> |
| 5768 | <div class="paragraph"> |
| 5769 | <p>By default, a file is assumed to be text encoded in UTF-8, and the |
| 5770 | <code>read()</code> and <code>replace()</code> functions use strings to represent the |
| 5771 | content.</p> |
| 5772 | </div> |
| 5773 | <div class="paragraph"> |
| 5774 | <p>By specifying the <code>syntax.parser()</code> and <code>syntax.stringify()</code> |
| 5775 | options, you can cause <code>read()</code> to parse the content before passing it |
| 5776 | back to you, and <code>replace()</code> to unparse it before writing.</p> |
| 5777 | </div> |
| 5778 | <div class="paragraph"> |
| 5779 | <p>The main idea is to be able to write <code>{ syntax: JSON }</code>, of course, |
| 5780 | but you can easily pass in individual functions or make your own |
| 5781 | parser/unparser object:</p> |
| 5782 | </div> |
| 5783 | <div class="literalblock"> |
| 5784 | <div class="content"> |
| 5785 | <pre>cockpit.file("/path/to/file.json", { syntax: JSON }) |
| 5786 | |
| 5787 | var syntax_object = { |
| 5788 | parse: my_parser, |
| 5789 | stringify: my_unparser |
| 5790 | }; |
| 5791 | |
| 5792 | cockpit.file("/path/to/file", { syntax: syntax_object })</pre> |
| 5793 | </div> |
| 5794 | </div> |
| 5795 | <div class="paragraph"> |
| 5796 | <p>Any exceptions thrown by the <code>parse()</code> and <code>stringify()</code> functions |
| 5797 | are caught and reported as read or write errors.</p> |
| 5798 | </div> |
| 5799 | <div class="paragraph"> |
| 5800 | <p>The <code>null</code> value that is used to represent the content of a |
| 5801 | non-existing file (see "Simple reading and writing", above) is not |
| 5802 | passed through the <code>parse()</code> and <code>stringify()</code> functions.</p> |
| 5803 | </div> |
| 5804 | </div> |
| 5805 | <div class="sect4"> |
| 5806 | <h5 id="cockpit-file-binary">Binary files</h5> |
| 5807 | <div class="paragraph"> |
| 5808 | <p>By default the content of the file is assumed to be text encoded as |
| 5809 | UTF-8 and it can not contain zero bytes. The content is represented as a |
| 5810 | JavaScript string with <code>read()</code>, <code>replace()</code>, etc. By setting the |
| 5811 | <code>binary</code> option to true when creating the proxy, no assumptions are |
| 5812 | placed on the content, and it is represented as a <code>Uint8Array</code> in |
| 5813 | JavaScript.</p> |
| 5814 | </div> |
| 5815 | </div> |
| 5816 | <div class="sect4"> |
| 5817 | <h5 id="cockpit-file-atomic">Atomic modifications</h5> |
| 5818 | <div class="paragraph"> |
| 5819 | <p>Use <code>modify()</code> to modify the content of the file safely. A call to |
| 5820 | <code>modify()</code> will read the content of the file, call <code>callback</code> on the |
| 5821 | content, and then replace the content of the file with the return value |
| 5822 | of the callback.</p> |
| 5823 | </div> |
| 5824 | <div class="paragraph"> |
| 5825 | <p>The <code>modify()</code> method uses the <code>read()</code> and <code>replace()</code> methods |
| 5826 | internally in the obvious way. Thus, the <code>syntax.parse()</code> and |
| 5827 | <code>syntax.stringify()</code> options work as expected, <code>null</code> represents a |
| 5828 | non-existing file, and the watch callbacks are fired.</p> |
| 5829 | </div> |
| 5830 | <div class="paragraph"> |
| 5831 | <p>It will do this one or more times, until no other conflicting changes |
| 5832 | have been made to the file between reading and replacing it.</p> |
| 5833 | </div> |
| 5834 | <div class="paragraph"> |
| 5835 | <p>The callback is called like this</p> |
| 5836 | </div> |
| 5837 | <div class="literalblock"> |
| 5838 | <div class="content"> |
| 5839 | <pre>new_content = callback (old_content)</pre> |
| 5840 | </div> |
| 5841 | </div> |
| 5842 | <div class="paragraph"> |
| 5843 | <p>The callback is allowed to mutate <code>old_content</code>, but note that this |
| 5844 | will also mutate the objects that are passed to the watch callbacks. |
| 5845 | Returning <code>undefined</code> from the proxy is the same as returning |
| 5846 | <code>old_content</code>.</p> |
| 5847 | </div> |
| 5848 | <div class="paragraph"> |
| 5849 | <p>The <code>modify()</code> method returns a |
| 5850 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>.</p> |
| 5851 | </div> |
| 5852 | <div class="paragraph"> |
| 5853 | <p>The promise will be resolved with the new content and its tag, like so</p> |
| 5854 | </div> |
| 5855 | <div class="literalblock"> |
| 5856 | <div class="content"> |
| 5857 | <pre>function shout(old_content) { |
| 5858 | return old_content.toUpperCase(); |
| 5859 | } |
| 5860 | |
| 5861 | cockpit.file("/path/to/file").modify(shout) |
| 5862 | .then((content, tag) => { |
| 5863 | ... |
| 5864 | }) |
| 5865 | .catch(error => { |
| 5866 | ... |
| 5867 | });</pre> |
| 5868 | </div> |
| 5869 | </div> |
| 5870 | <div class="paragraph"> |
| 5871 | <p>If you have cached the last content and tag results of the <code>read()</code> or |
| 5872 | <code>modify()</code> method, or the last values passed to a watch callback, you |
| 5873 | can pass them to <code>modify()</code> as the second and third argument. In this |
| 5874 | case, <code>modify()</code> will skip the initial read and start with the given |
| 5875 | values.</p> |
| 5876 | </div> |
| 5877 | </div> |
| 5878 | <div class="sect4"> |
| 5879 | <h5 id="cockpit-file-notify">Change notifications</h5> |
| 5880 | <div class="paragraph"> |
| 5881 | <p>Calling <code>watch()</code> will start monitoring the file for external changes.</p> |
| 5882 | </div> |
| 5883 | <div class="literalblock"> |
| 5884 | <div class="content"> |
| 5885 | <pre>handle = file.watch(callback); |
| 5886 | |
| 5887 | handle_no_read = file.watch(callback, { read: false });</pre> |
| 5888 | </div> |
| 5889 | </div> |
| 5890 | <div class="paragraph"> |
| 5891 | <p>Whenever a change occurs, the <code>callback()</code> is called with the new |
| 5892 | content and tag of the file. This might happen because of external |
| 5893 | changes, but also as part of calls to <code>read()</code>, <code>replace()</code>, and |
| 5894 | <code>modify()</code>.</p> |
| 5895 | </div> |
| 5896 | <div class="paragraph"> |
| 5897 | <p>When a read error occurs, the <code>callback()</code> is called with an error as |
| 5898 | a third argument. Write errors are not reported via the watch callback.</p> |
| 5899 | </div> |
| 5900 | <div class="paragraph"> |
| 5901 | <p>Calling <code>watch()</code> will also automatically call <code>read()</code> to get the |
| 5902 | initial content of the file. Thus, you normally don’t need to call |
| 5903 | <code>read()</code> at all when using <code>watch()</code>.</p> |
| 5904 | </div> |
| 5905 | <div class="paragraph"> |
| 5906 | <p>To disable the automatic reading, e.g. for large files or unreadable |
| 5907 | file system objects, set the <code>read</code> option to <code>false</code>. The first |
| 5908 | <code>content</code> argument of the callback will then always be <code>null</code>.</p> |
| 5909 | </div> |
| 5910 | <div class="paragraph"> |
| 5911 | <p>To free the resources used for monitoring, call <code>handle.remove()</code>.</p> |
| 5912 | </div> |
| 5913 | </div> |
| 5914 | <div class="sect4"> |
| 5915 | <h5 id="cockpit-file-path">file.path</h5> |
| 5916 | <div class="paragraph"> |
| 5917 | <p>A string containing the path that was passed to the <code>cockpit.file()</code> |
| 5918 | method.</p> |
| 5919 | </div> |
| 5920 | </div> |
| 5921 | <div class="sect4"> |
| 5922 | <h5 id="cockpit-file-close">Closing</h5> |
| 5923 | <div class="paragraph"> |
| 5924 | <p>Call the <code>close()</code> method on a file proxy to cancel all ongoing |
| 5925 | operations, such as reading, writing, and monitoring. The proxy should |
| 5926 | not be used after closing it.</p> |
| 5927 | </div> |
| 5928 | </div> |
| 5929 | </div> |
| 5930 | <div class="sect3"> |
| 5931 | <h4 id="_cockpit_js_http_client">cockpit.js: HTTP Client</h4> |
| 5932 | <div class="paragraph"> |
| 5933 | <p>Cockpit allows access to local HTTP and REST services via this API.</p> |
| 5934 | </div> |
| 5935 | <div class="sect4"> |
| 5936 | <h5 id="cockpit-http-constructor">cockpit.http()</h5> |
| 5937 | <div class="literalblock"> |
| 5938 | <div class="content"> |
| 5939 | <pre>http = cockpit.http(endpoint, [options]) |
| 5940 | http = cockpit.http(options)</pre> |
| 5941 | </div> |
| 5942 | </div> |
| 5943 | <div class="paragraph"> |
| 5944 | <p>Create a new HTTP client. The <code>endpoint</code> can be a file path starting |
| 5945 | with <code>/</code> to connect to a unix socket, or it can be a port number to |
| 5946 | connect to. The optional <code>options</code> argument is a javascript plain |
| 5947 | object, and may include:</p> |
| 5948 | </div> |
| 5949 | <div class="dlist"> |
| 5950 | <dl> |
| 5951 | <dt class="hdlist1"><code>"address"</code></dt> |
| 5952 | <dd> |
| 5953 | <p>Connect to an address other than localhost. Must be a valid host name |
| 5954 | or IP address. To use this option you also must provide a port number.</p> |
| 5955 | </dd> |
| 5956 | <dt class="hdlist1"><code>"port"</code></dt> |
| 5957 | <dd> |
| 5958 | <p>Port number to use with "address" option, when not given in |
| 5959 | <code>endpoint</code>.</p> |
| 5960 | </dd> |
| 5961 | <dt class="hdlist1"><code>"tls"</code></dt> |
| 5962 | <dd> |
| 5963 | <p>Object properties for an https connection. See |
| 5964 | <code>http-stream2 TLS options</code>.</p> |
| 5965 | </dd> |
| 5966 | <dt class="hdlist1"><code>"headers"</code></dt> |
| 5967 | <dd> |
| 5968 | <p>Additional HTTP headers to include with the HTTP request. This is a |
| 5969 | plain javascript object with each key as a header name, and each value |
| 5970 | as the header value.</p> |
| 5971 | </dd> |
| 5972 | <dt class="hdlist1"><code>"superuser"</code></dt> |
| 5973 | <dd> |
| 5974 | <p>Set to <code>"require"</code> to open this channel as root. If the currently |
| 5975 | logged in user is not permitted to become root (eg: via <code>pkexec</code>) |
| 5976 | then the <code>channel</code> will immediately be |
| 5977 | <a href="#cockpit-channels-close-ev">closed</a> with a <code>"access-denied"</code> |
| 5978 | problem code. |
| 5979 | + |
| 5980 | Set to <code>"try"</code> to try to make the request as root, but if that |
| 5981 | fails, fall back to perform an unprivileged request.</p> |
| 5982 | </dd> |
| 5983 | <dt class="hdlist1"><code>"tls"</code></dt> |
| 5984 | <dd> |
| 5985 | <p>If set to a plain javascript object, then the connection will be an |
| 5986 | HTTPS connection and include TLS encryption. The fields of the <code>tls</code> |
| 5987 | object declare various TLS configuration and data. All fields are |
| 5988 | optional: |
| 5989 | +</p> |
| 5990 | <div class="ulist"> |
| 5991 | <ul> |
| 5992 | <li> |
| 5993 | <p><code>"authority"</code>: Certificate authority(s) to expect as signers of |
| 5994 | the server’s TLS certificate, represented as a plain javascript |
| 5995 | object. It should have either a <code>"file"</code> field containing a readable |
| 5996 | PEM file on the system containing authorities, or a <code>"data"</code> with |
| 5997 | PEM encoded certificate data.</p> |
| 5998 | </li> |
| 5999 | <li> |
| 6000 | <p><code>"certificate"</code>: A client certificate to use, represented as a |
| 6001 | plain javascript object. It should have either a <code>"file"</code> field |
| 6002 | containing a readable PEM file on the system to use as a certificate, |
| 6003 | or a <code>"data"</code> with PEM encoded certificate data.</p> |
| 6004 | </li> |
| 6005 | <li> |
| 6006 | <p><code>"key"</code>: A client key to use, represented as a plain javascript |
| 6007 | object. It should have either a <code>"file"</code> field containing a readable |
| 6008 | PEM file on the system to use as a key, or a <code>"data"</code> with PEM |
| 6009 | encoded key data.</p> |
| 6010 | </li> |
| 6011 | <li> |
| 6012 | <p><code>"validate"</code>: A boolean that describes whether to validate the |
| 6013 | server’s TLS certificate or not. By default local connections are not |
| 6014 | validated, and remote connections are validated.</p> |
| 6015 | </li> |
| 6016 | </ul> |
| 6017 | </div> |
| 6018 | </dd> |
| 6019 | </dl> |
| 6020 | </div> |
| 6021 | <div class="paragraph"> |
| 6022 | <p>Here is a somewhat complex example of using most of the above |
| 6023 | <code>options</code> when when calling <code>cockpit.http()</code>:</p> |
| 6024 | </div> |
| 6025 | <div class="literalblock"> |
| 6026 | <div class="content"> |
| 6027 | <pre>http = cockpit.http({ |
| 6028 | "address": "localhost", |
| 6029 | "headers": { |
| 6030 | "Authorization": "Basic dXNlcjpwYXNzd29yZA==" |
| 6031 | }, |
| 6032 | "port": 443, |
| 6033 | "tls": { |
| 6034 | "validate": true, |
| 6035 | "authority": { |
| 6036 | "file": "/etc/pki/tls/certs/ca-bundle.crt", |
| 6037 | }, |
| 6038 | "certificate": { |
| 6039 | "data": "-----BEGIN CERTIFICATE-----\nMIIDsDCCA..." |
| 6040 | }, |
| 6041 | "key": { |
| 6042 | "data": "-----BEGIN RSA PRIVATE KEY-----\nMIIEogIBA..." |
| 6043 | } |
| 6044 | } |
| 6045 | });</pre> |
| 6046 | </div> |
| 6047 | </div> |
| 6048 | </div> |
| 6049 | <div class="sect4"> |
| 6050 | <h5 id="cockpit-http-get">http.get()</h5> |
| 6051 | <div class="literalblock"> |
| 6052 | <div class="content"> |
| 6053 | <pre>request = http.get(path, [params, [headers]])</pre> |
| 6054 | </div> |
| 6055 | </div> |
| 6056 | <div class="paragraph"> |
| 6057 | <p>Perform an HTTP GET request for the given <code>path</code>. If the <code>params</code> is |
| 6058 | specified it should be a plain javascript object, which will be turned |
| 6059 | into a query string.</p> |
| 6060 | </div> |
| 6061 | <div class="paragraph"> |
| 6062 | <p>Optionally a plain javascript object containing headers can be included |
| 6063 | in the <code>headers</code> argument.</p> |
| 6064 | </div> |
| 6065 | <div class="paragraph"> |
| 6066 | <p>The return value is a |
| 6067 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> |
| 6068 | that will complete if the request happens successfully, or fail if |
| 6069 | there’s a problem.</p> |
| 6070 | </div> |
| 6071 | </div> |
| 6072 | <div class="sect4"> |
| 6073 | <h5 id="cockpit-http-post">http.post()</h5> |
| 6074 | <div class="literalblock"> |
| 6075 | <div class="content"> |
| 6076 | <pre>request = http.post(path, body, [headers])</pre> |
| 6077 | </div> |
| 6078 | </div> |
| 6079 | <div class="paragraph"> |
| 6080 | <p>Perform an HTTP POST request for the given <code>path</code>. The <code>body</code> can be |
| 6081 | a string, or a javascript plain object, which will be encoded as JSON |
| 6082 | data. If <code>body</code> is <code>undefined</code> or <code>null</code> then an empty HTTP body |
| 6083 | will be sent.</p> |
| 6084 | </div> |
| 6085 | <div class="paragraph"> |
| 6086 | <p>Optionally a plain javascript object containing headers can be included |
| 6087 | in the <code>headers</code> argument.</p> |
| 6088 | </div> |
| 6089 | <div class="paragraph"> |
| 6090 | <p>The return value is a |
| 6091 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> |
| 6092 | that will complete if the request happens successfully, or fail if |
| 6093 | there’s a problem.</p> |
| 6094 | </div> |
| 6095 | </div> |
| 6096 | <div class="sect4"> |
| 6097 | <h5 id="cockpit-http-request">http.request()</h5> |
| 6098 | <div class="literalblock"> |
| 6099 | <div class="content"> |
| 6100 | <pre>request = http.request(options)</pre> |
| 6101 | </div> |
| 6102 | </div> |
| 6103 | <div class="paragraph"> |
| 6104 | <p>Perform an HTTP request. The <code>options</code> can contain the following:</p> |
| 6105 | </div> |
| 6106 | <div class="dlist"> |
| 6107 | <dl> |
| 6108 | <dt class="hdlist1"><code>"body"</code></dt> |
| 6109 | <dd> |
| 6110 | <p>The HTTP request body. If you do not specify a body, then you must |
| 6111 | call <a href="#cockpit-http-input">request.input()</a> to complete the body |
| 6112 | and allow the request to start.</p> |
| 6113 | </dd> |
| 6114 | <dt class="hdlist1"><code>"headers"</code></dt> |
| 6115 | <dd> |
| 6116 | <p>A javascript plain object containing HTTP headers.</p> |
| 6117 | </dd> |
| 6118 | <dt class="hdlist1"><code>"method"</code></dt> |
| 6119 | <dd> |
| 6120 | <p>The HTTP method. Defaults to <code>"GET"</code>.</p> |
| 6121 | </dd> |
| 6122 | <dt class="hdlist1"><code>"params"</code></dt> |
| 6123 | <dd> |
| 6124 | <p>A javascript plain object containing query string parameters.</p> |
| 6125 | </dd> |
| 6126 | <dt class="hdlist1"><code>"path"</code></dt> |
| 6127 | <dd> |
| 6128 | <p>The HTTP path. Defaults to <code>/</code>.</p> |
| 6129 | </dd> |
| 6130 | </dl> |
| 6131 | </div> |
| 6132 | <div class="paragraph"> |
| 6133 | <p>The return value is a |
| 6134 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> |
| 6135 | that will complete if the request happens successfully, or fail if |
| 6136 | there’s a problem.</p> |
| 6137 | </div> |
| 6138 | </div> |
| 6139 | <div class="sect4"> |
| 6140 | <h5 id="cockpit-http-then">request.then()</h5> |
| 6141 | <div class="literalblock"> |
| 6142 | <div class="content"> |
| 6143 | <pre>request.then(data => { ... })</pre> |
| 6144 | </div> |
| 6145 | </div> |
| 6146 | <div class="paragraph"> |
| 6147 | <p>This is a standard |
| 6148 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> |
| 6149 | method. It sets up a handler to be called when the request finishes |
| 6150 | successfully.</p> |
| 6151 | </div> |
| 6152 | <div class="paragraph"> |
| 6153 | <p>The <code>data</code> argument contains the body result of the request. If it a |
| 6154 | string, unless the process was opened in binary mode, in which case the |
| 6155 | <code>data</code> is an array of bytes. If a <code>request.stream()</code> handler is set |
| 6156 | up, then any standard output data consumed by the handler will not be |
| 6157 | included in the <code>data</code> argument.</p> |
| 6158 | </div> |
| 6159 | </div> |
| 6160 | <div class="sect4"> |
| 6161 | <h5 id="cockpit-http-catch">request.catch()</h5> |
| 6162 | <div class="literalblock"> |
| 6163 | <div class="content"> |
| 6164 | <pre>request.catch((exception[, data]) => { ... })</pre> |
| 6165 | </div> |
| 6166 | </div> |
| 6167 | <div class="paragraph"> |
| 6168 | <p>This is a standard |
| 6169 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> |
| 6170 | method. It sets up a handler to be called when the request fails, or |
| 6171 | returns an error code.</p> |
| 6172 | </div> |
| 6173 | <div class="paragraph"> |
| 6174 | <p>The <code>exception</code> object passed to the handler can have the following |
| 6175 | fields:</p> |
| 6176 | </div> |
| 6177 | <div class="dlist"> |
| 6178 | <dl> |
| 6179 | <dt class="hdlist1"><code>problem</code></dt> |
| 6180 | <dd> |
| 6181 | <p>A <a href="cockpit-error.html#cockpit-problems">problem code</a> string when a problem occurred |
| 6182 | starting or communicating with the server. This is <code>null</code> if the |
| 6183 | process exited or was terminated.</p> |
| 6184 | </dd> |
| 6185 | <dt class="hdlist1"><code>status</code></dt> |
| 6186 | <dd> |
| 6187 | <p>The numeric status of the response. This is <code>null</code> if no response |
| 6188 | was received.</p> |
| 6189 | </dd> |
| 6190 | <dt class="hdlist1"><code>reason</code></dt> |
| 6191 | <dd> |
| 6192 | <p>A string reason returned in the response. This is <code>null</code> if no |
| 6193 | response was received.</p> |
| 6194 | </dd> |
| 6195 | <dt class="hdlist1"><code>message</code></dt> |
| 6196 | <dd> |
| 6197 | <p>A string message returned in the response. This is <code>null</code> if no |
| 6198 | response was received.</p> |
| 6199 | </dd> |
| 6200 | </dl> |
| 6201 | </div> |
| 6202 | <div class="paragraph"> |
| 6203 | <p>If the request returned a response body, it will be available in the |
| 6204 | <code>data</code> argument. Otherwise this argument will be <code>undefined</code>.</p> |
| 6205 | </div> |
| 6206 | </div> |
| 6207 | <div class="sect4"> |
| 6208 | <h5 id="cockpit-http-response">request.response()</h5> |
| 6209 | <div class="literalblock"> |
| 6210 | <div class="content"> |
| 6211 | <pre>request.response((status, headers) => { ... })</pre> |
| 6212 | </div> |
| 6213 | </div> |
| 6214 | <div class="paragraph"> |
| 6215 | <p>This sets up a handler to be called when the HTTP request gets the |
| 6216 | initial response from the server. The <code>status</code> argument is the HTTP |
| 6217 | status integer, and the <code>headers</code> is a plain javascript object |
| 6218 | containing the headers of the response.</p> |
| 6219 | </div> |
| 6220 | </div> |
| 6221 | <div class="sect4"> |
| 6222 | <h5 id="cockpit-http-stream">request.stream()</h5> |
| 6223 | <div class="literalblock"> |
| 6224 | <div class="content"> |
| 6225 | <pre>request.stream(data => { ... })</pre> |
| 6226 | </div> |
| 6227 | </div> |
| 6228 | <div class="paragraph"> |
| 6229 | <p>This sets up a handler to be called when the request returns output |
| 6230 | data. The handler will be called multiple times.</p> |
| 6231 | </div> |
| 6232 | <div class="paragraph"> |
| 6233 | <p>Only one handler may be registered at a time. Registering an additional |
| 6234 | handler replaces the previous one. The handler receives either string |
| 6235 | <code>data</code> or an array of binary bytes as its argument. A stream handler |
| 6236 | may return a number, which indicates the number of characters or bytes |
| 6237 | consumed from <code>data</code>. Any data not consumed will be included again the |
| 6238 | next time the handler is called.</p> |
| 6239 | </div> |
| 6240 | <div class="paragraph"> |
| 6241 | <p>If a <code>request.stream()</code> handler is set up, then the <code>request.then()</code> |
| 6242 | handlers will only get any remaining data not consumed by the stream |
| 6243 | handler.</p> |
| 6244 | </div> |
| 6245 | </div> |
| 6246 | <div class="sect4"> |
| 6247 | <h5 id="cockpit-http-input">request.input()</h5> |
| 6248 | <div class="literalblock"> |
| 6249 | <div class="content"> |
| 6250 | <pre>request.input(data, [stream])</pre> |
| 6251 | </div> |
| 6252 | </div> |
| 6253 | <div class="paragraph"> |
| 6254 | <p>This method writes <code>data</code> to the HTTP request body. It is only valid |
| 6255 | if no <code>"body"</code> has been specified in |
| 6256 | <a href="#cockpit-http-request">http.request()</a> options. If <code>stream</code> is |
| 6257 | <code>true</code> then this function can be called again to provide further data.</p> |
| 6258 | </div> |
| 6259 | </div> |
| 6260 | <div class="sect4"> |
| 6261 | <h5 id="cockpit-http-close">request.close()</h5> |
| 6262 | <div class="literalblock"> |
| 6263 | <div class="content"> |
| 6264 | <pre>request.close([problem])</pre> |
| 6265 | </div> |
| 6266 | </div> |
| 6267 | <div class="paragraph"> |
| 6268 | <p>Cancel the request. If <code>problem</code> is specified it should be a standard |
| 6269 | <a href="cockpit-error.html#cockpit-problems">problem code</a> string.</p> |
| 6270 | </div> |
| 6271 | </div> |
| 6272 | <div class="sect4"> |
| 6273 | <h5 id="cockpit-http-close-all">http.close()</h5> |
| 6274 | <div class="literalblock"> |
| 6275 | <div class="content"> |
| 6276 | <pre>http.close([problem])</pre> |
| 6277 | </div> |
| 6278 | </div> |
| 6279 | <div class="paragraph"> |
| 6280 | <p>Cancel all outstanding requests with the given problem code. This is |
| 6281 | useful when you know that the server is going down soon.</p> |
| 6282 | </div> |
| 6283 | </div> |
| 6284 | </div> |
| 6285 | <div class="sect3"> |
| 6286 | <h4 id="_cockpit_js_localization">cockpit.js: Localization</h4> |
| 6287 | <div class="paragraph"> |
| 6288 | <p>Cockpit provides a <a href="https://www.gnu.org/software/gettext/"><code>gettext()</code></a> |
| 6289 | like API for easy translation of strings.</p> |
| 6290 | </div> |
| 6291 | <div class="sect4"> |
| 6292 | <h5 id="cockpit-locale-language">cockpit.language</h5> |
| 6293 | <div class="paragraph"> |
| 6294 | <p>The current locale language code. This is set based on the |
| 6295 | <a href="#cockpit-locale-locale"><code>cockpit.locale()</code></a> data loaded.</p> |
| 6296 | </div> |
| 6297 | </div> |
| 6298 | <div class="sect4"> |
| 6299 | <h5 id="cockpit-locale-locale">cockpit.locale()</h5> |
| 6300 | <div class="literalblock"> |
| 6301 | <div class="content"> |
| 6302 | <pre>cockpit.locale(po)</pre> |
| 6303 | </div> |
| 6304 | </div> |
| 6305 | <div class="paragraph"> |
| 6306 | <p>Load locale information for a given <code>po</code> data. The data should be JSON |
| 6307 | data in the <a href="https://www.npmjs.org/package/po2json">po2json</a> format. The |
| 6308 | data will be loaded globally. If <code>po</code> data has already been loaded, |
| 6309 | then this will extend that loaded data with additional strings. Any |
| 6310 | identical translations strings will be replaced with the new strings. A |
| 6311 | <code>null</code> argument clears all the locale information previously loaded.</p> |
| 6312 | </div> |
| 6313 | <div class="paragraph"> |
| 6314 | <p>Various methods such as |
| 6315 | <a href="#cockpit-locale-gettext"><code>cockpit.gettext()</code></a> make use of the |
| 6316 | loaded data.</p> |
| 6317 | </div> |
| 6318 | </div> |
| 6319 | <div class="sect4"> |
| 6320 | <h5 id="cockpit-locale-gettext">cockpit.gettext()</h5> |
| 6321 | <div class="literalblock"> |
| 6322 | <div class="content"> |
| 6323 | <pre>translated = cockpit.gettext([context], string) |
| 6324 | var _ = cockpit.gettext |
| 6325 | var C_ = cockpit.gettext |
| 6326 | translated = _("string") |
| 6327 | translated = C_("context", "string")</pre> |
| 6328 | </div> |
| 6329 | </div> |
| 6330 | <div class="paragraph"> |
| 6331 | <p>Lookup <code>string</code> for translation in the loaded locale data. The |
| 6332 | translated string will be returned, or <code>string</code> will be returned if no |
| 6333 | such translated string is present. The <code>context</code> argument is an |
| 6334 | optional string used to qualify the string.</p> |
| 6335 | </div> |
| 6336 | <div class="paragraph"> |
| 6337 | <p>This function can be assigned to a variable called <code>_</code> (underscore) |
| 6338 | which will make your code work with the typical <code>_("string")</code> syntax.</p> |
| 6339 | </div> |
| 6340 | </div> |
| 6341 | <div class="sect4"> |
| 6342 | <h5 id="cockpit-locale-noop">cockpit.noop()</h5> |
| 6343 | <div class="literalblock"> |
| 6344 | <div class="content"> |
| 6345 | <pre>var N_ = cockpit.noop |
| 6346 | var NC_ = cockpit.noop</pre> |
| 6347 | </div> |
| 6348 | </div> |
| 6349 | <div class="paragraph"> |
| 6350 | <p>A noop function suitable for assigning to <code>N_</code> or <code>NC_</code> so that |
| 6351 | gettext scanners will be able to find translatable strings. More |
| 6352 | specifically this function returns its last argument.</p> |
| 6353 | </div> |
| 6354 | </div> |
| 6355 | <div class="sect4"> |
| 6356 | <h5 id="cockpit-locale-ngettext">cockpit.ngettext()</h5> |
| 6357 | <div class="literalblock"> |
| 6358 | <div class="content"> |
| 6359 | <pre>translated = cockpit.ngettext([context], string1, stringN, number)</pre> |
| 6360 | </div> |
| 6361 | </div> |
| 6362 | <div class="paragraph"> |
| 6363 | <p>Lookup a string appropriate for a pluralization form of the <code>number</code>. |
| 6364 | Various languages have complex pluralization forms that go far between |
| 6365 | the singular and plural forms speakers of English are familiar with. If |
| 6366 | no such translated string is found then either one of <code>string1</code> or |
| 6367 | <code>stringN</code> is returned according to simple pluralization rules.</p> |
| 6368 | </div> |
| 6369 | <div class="paragraph"> |
| 6370 | <p>The <code>context</code> argument is an optional string used to qualify the |
| 6371 | string.</p> |
| 6372 | </div> |
| 6373 | </div> |
| 6374 | <div class="sect4"> |
| 6375 | <h5 id="cockpit-locale-translate">cockpit.translate()</h5> |
| 6376 | <div class="literalblock"> |
| 6377 | <div class="content"> |
| 6378 | <pre>cockpit.translate() |
| 6379 | cockpit.translate(element, ...) |
| 6380 | cockpit.translate(selection)</pre> |
| 6381 | </div> |
| 6382 | </div> |
| 6383 | <div class="paragraph"> |
| 6384 | <p>The document will be scanned for <code>translate</code> tags and they will be |
| 6385 | translated according to the strings in loaded locale data. One or more |
| 6386 | <code>element</code> arguments may be specified. These are DOM elements for |
| 6387 | specific parts of the document to be translated. If no <code>element</code> is |
| 6388 | specified then the entire document is translated.</p> |
| 6389 | </div> |
| 6390 | <div class="paragraph"> |
| 6391 | <p>If an array or array-like object is passed as a <code>selection</code> then all |
| 6392 | DOM elements in the array will be treated as parts of the document to be |
| 6393 | translated.</p> |
| 6394 | </div> |
| 6395 | </div> |
| 6396 | </div> |
| 6397 | <div class="sect3"> |
| 6398 | <h4 id="_cockpit_js_page_location_and_jumping">cockpit.js: Page Location and Jumping</h4> |
| 6399 | <div class="paragraph"> |
| 6400 | <p>Page location and navigation between components</p> |
| 6401 | </div> |
| 6402 | <div class="sect4"> |
| 6403 | <h5 id="cockpit-location-general">Page location</h5> |
| 6404 | <div class="literalblock"> |
| 6405 | <div class="content"> |
| 6406 | <pre>location = cockpit.location |
| 6407 | cockpit.location = "/path"</pre> |
| 6408 | </div> |
| 6409 | </div> |
| 6410 | <div class="paragraph"> |
| 6411 | <p>Cockpit components often have different views, without changing the HTML |
| 6412 | file that is being viewed. These are known as pages. |
| 6413 | <code>cockpit.location</code> is an object that can be used to read the current |
| 6414 | page and to navigate to a different page location. It works by updating |
| 6415 | <code>window.location.hash</code>.</p> |
| 6416 | </div> |
| 6417 | <div class="paragraph"> |
| 6418 | <p>The <code>cockpit.location</code> looks like a HTTP path with a possible query |
| 6419 | string:</p> |
| 6420 | </div> |
| 6421 | <div class="literalblock"> |
| 6422 | <div class="content"> |
| 6423 | <pre>/path/sub/page?option=value,option2</pre> |
| 6424 | </div> |
| 6425 | </div> |
| 6426 | <div class="paragraph"> |
| 6427 | <p>The <a href="#cockpit-location-path"><code>location.path</code></a> and |
| 6428 | <a href="#cockpit-location-options"><code>location.options</code></a> contain a parsed |
| 6429 | form of the location. While the location cannot be modified in place, a |
| 6430 | new one can be created by assigning a string to <code>cockpit.location</code> or |
| 6431 | by calling the <a href="#cockpit-location-go"><code>location.go()</code></a> function.</p> |
| 6432 | </div> |
| 6433 | <div class="paragraph"> |
| 6434 | <p><code>cockpit.location</code> is designed similarly to <code>window.location</code> in |
| 6435 | that the location object is preplaced whenever the current page location |
| 6436 | changes. To be aware of when the page location changes listen for the |
| 6437 | <a href="#cockpit-location-changed"><code>cockpit.onlocationchanged</code></a> event.</p> |
| 6438 | </div> |
| 6439 | <div class="paragraph"> |
| 6440 | <p>Using the location object as a string will result in the |
| 6441 | <a href="#cockpit-location-href"><code>location.href</code></a>.</p> |
| 6442 | </div> |
| 6443 | <div class="sect5"> |
| 6444 | <h6 id="cockpit-location-href">location.href</h6> |
| 6445 | <div class="paragraph"> |
| 6446 | <p>The string representation of this page location, including any options.</p> |
| 6447 | </div> |
| 6448 | </div> |
| 6449 | <div class="sect5"> |
| 6450 | <h6 id="cockpit-location-path">location.path</h6> |
| 6451 | <div class="paragraph"> |
| 6452 | <p>An array of path segments, parsed and decoded appropriately. An empty |
| 6453 | array denotes the root path.</p> |
| 6454 | </div> |
| 6455 | </div> |
| 6456 | <div class="sect5"> |
| 6457 | <h6 id="cockpit-location-options">location.options</h6> |
| 6458 | <div class="paragraph"> |
| 6459 | <p>A javascript object containing the various options present in the |
| 6460 | location.</p> |
| 6461 | </div> |
| 6462 | <div class="paragraph"> |
| 6463 | <p>If an option appears more than once, its value will be an array.</p> |
| 6464 | </div> |
| 6465 | </div> |
| 6466 | <div class="sect5"> |
| 6467 | <h6 id="cockpit-location-go">location.go()</h6> |
| 6468 | <div class="literalblock"> |
| 6469 | <div class="content"> |
| 6470 | <pre>location.go(path, [options])</pre> |
| 6471 | </div> |
| 6472 | </div> |
| 6473 | <div class="paragraph"> |
| 6474 | <p>Changes the current location to the given <code>path</code> and <code>options</code>. If |
| 6475 | the <code>path</code> argument is a string, it will be parsed into a path. If it |
| 6476 | is a relative path, then the result will be relative to the current |
| 6477 | <code>location.path</code>. If the <code>path</code> argument is an array of path |
| 6478 | segments, it will be treated as a full parsed absolute path.</p> |
| 6479 | </div> |
| 6480 | <div class="paragraph"> |
| 6481 | <p>Any options found in a <code>path</code> will be added to those in the optional |
| 6482 | <code>options</code> argument, and used in the result.</p> |
| 6483 | </div> |
| 6484 | <div class="paragraph"> |
| 6485 | <p>The location change will only take effect if the location has not |
| 6486 | changed in the meantime. This can be to good effect by saving a |
| 6487 | <code>cockpit.location</code> object and doing a conditional navigation, by |
| 6488 | calling the saved <code>location.go()</code> method later. This will only |
| 6489 | navigate if the user or other code has not navigated in the meantime.</p> |
| 6490 | </div> |
| 6491 | </div> |
| 6492 | <div class="sect5"> |
| 6493 | <h6 id="cockpit-location-replace">location.replace()</h6> |
| 6494 | <div class="literalblock"> |
| 6495 | <div class="content"> |
| 6496 | <pre>location.replace(path, [options])</pre> |
| 6497 | </div> |
| 6498 | </div> |
| 6499 | <div class="paragraph"> |
| 6500 | <p>Similar to <a href="#cockpit-location-go"><code>location.go()</code></a> except the |
| 6501 | location change will not result in a navigation change in the browser’s |
| 6502 | history.</p> |
| 6503 | </div> |
| 6504 | </div> |
| 6505 | <div class="sect5"> |
| 6506 | <h6 id="cockpit-location-decode">location.decode()</h6> |
| 6507 | <div class="literalblock"> |
| 6508 | <div class="content"> |
| 6509 | <pre>path = location.decode(href, [options])</pre> |
| 6510 | </div> |
| 6511 | </div> |
| 6512 | <div class="paragraph"> |
| 6513 | <p>Decode a cockpit href into its <code>path</code> array. If the <code>options</code> |
| 6514 | argument is specified, then it will be populated with options found in |
| 6515 | the href.</p> |
| 6516 | </div> |
| 6517 | <div class="paragraph"> |
| 6518 | <p>If href is a relative path it will be resolved relative to |
| 6519 | <code>location.href</code>.</p> |
| 6520 | </div> |
| 6521 | </div> |
| 6522 | <div class="sect5"> |
| 6523 | <h6 id="cockpit-location-encode">location.encode()</h6> |
| 6524 | <div class="literalblock"> |
| 6525 | <div class="content"> |
| 6526 | <pre>href = location.encode(path, [options])</pre> |
| 6527 | </div> |
| 6528 | </div> |
| 6529 | <div class="paragraph"> |
| 6530 | <p>Encode the given <code>path</code> and <code>options</code> into a cockpit href. The |
| 6531 | <code>path</code> argument may be an array of path segments, or a string path. If |
| 6532 | a relative path is passed, it will be resolved relative to |
| 6533 | <code>location.href</code>.</p> |
| 6534 | </div> |
| 6535 | </div> |
| 6536 | <div class="sect5"> |
| 6537 | <h6 id="cockpit-location-changed">cockpit.onlocationchanged</h6> |
| 6538 | <div class="literalblock"> |
| 6539 | <div class="content"> |
| 6540 | <pre>cockpit.addEventListener("locationchanged", function() { ... })</pre> |
| 6541 | </div> |
| 6542 | </div> |
| 6543 | <div class="paragraph"> |
| 6544 | <p>An event emitted when over the <code>cockpit.location</code> changes. Typically a |
| 6545 | component reacts to this event by updating its interface to reflect the |
| 6546 | new <a href="#cockpit-location-path"><code>cockpit.location.path</code></a> and |
| 6547 | <a href="#cockpit-location-options"><code>cockpit.location.options</code></a>.</p> |
| 6548 | </div> |
| 6549 | <div class="paragraph"> |
| 6550 | <p>This event is not triggered immediately during a <code>location.go()</code> or |
| 6551 | similar call. It will be triggered asynchronously at a later time.</p> |
| 6552 | </div> |
| 6553 | </div> |
| 6554 | </div> |
| 6555 | <div class="sect4"> |
| 6556 | <h5 id="cockpit-jump">Jumping between components</h5> |
| 6557 | <div class="literalblock"> |
| 6558 | <div class="content"> |
| 6559 | <pre>cockpit.jump("/system/log")</pre> |
| 6560 | </div> |
| 6561 | </div> |
| 6562 | <div class="paragraph"> |
| 6563 | <p>In Cockpit in there multiple components shown. In order to tell Cockpit |
| 6564 | to jump to and show another component and a certain location within that |
| 6565 | component, use the <code>cockpit.jump()</code> function. Stable component paths |
| 6566 | are documented. Don’t assume you can navigate into paths that are not |
| 6567 | stable API.</p> |
| 6568 | </div> |
| 6569 | <div class="sect5"> |
| 6570 | <h6 id="cockpit-jump-jump">cockpit.jump()</h6> |
| 6571 | <div class="literalblock"> |
| 6572 | <div class="content"> |
| 6573 | <pre>cockpit.jump(path, [ host ])</pre> |
| 6574 | </div> |
| 6575 | </div> |
| 6576 | <div class="paragraph"> |
| 6577 | <p>Ask Cockpit to jump to another component. The location of the current |
| 6578 | component will not be affected. The <code>path</code> argument can be a string |
| 6579 | path, starting with <code>/</code> or an array containing the parts of a path |
| 6580 | that will be joined to create a path. If <code>host</code> is not specified, then |
| 6581 | the component on the same host as the caller will be displayed. If host |
| 6582 | is null, then the host portion of the path will be removed, displaying |
| 6583 | the component on the host that cockpit is connected directly to.</p> |
| 6584 | </div> |
| 6585 | <div class="paragraph"> |
| 6586 | <p>If the calling component is not running within Cockpit, or the calling |
| 6587 | component is not currently displayed, then the jump will not happen, and |
| 6588 | this function has no effect.</p> |
| 6589 | </div> |
| 6590 | </div> |
| 6591 | <div class="sect5"> |
| 6592 | <h6 id="cockpit-jump-hidden">cockpit.hidden</h6> |
| 6593 | <div class="paragraph"> |
| 6594 | <p>A boolean property that indicates if the current component page is |
| 6595 | visible or hidden. When the code or user jumps to another component, the |
| 6596 | prior one remains loaded and initialized but is hidden. Use this |
| 6597 | property together with the |
| 6598 | <a href="#cockpit-jump-visibilitychange"><code>cockpit.onvisibilitychange</code></a> |
| 6599 | event to decide whether or not to perform expensive tasks to update the |
| 6600 | interface.</p> |
| 6601 | </div> |
| 6602 | <div class="paragraph"> |
| 6603 | <p>This property is analogous to the <code>document.hidden</code> page visibility |
| 6604 | API, but works with the document and frame implementation of Cockpit.</p> |
| 6605 | </div> |
| 6606 | </div> |
| 6607 | <div class="sect5"> |
| 6608 | <h6 id="cockpit-jump-visibilitychange">cockpit.onvisibilitychange</h6> |
| 6609 | <div class="literalblock"> |
| 6610 | <div class="content"> |
| 6611 | <pre>cockpit.onvisibilitychange = function() { ... }</pre> |
| 6612 | </div> |
| 6613 | </div> |
| 6614 | <div class="paragraph"> |
| 6615 | <p>This event is emitted when the |
| 6616 | <a href="#cockpit-jump-hidden"><code>cockpit.hidden</code></a> property changes. This |
| 6617 | event is similar to the <code>document.onvisibilitychange</code> API, but works |
| 6618 | with the document and frame implementation of Cockpit.</p> |
| 6619 | </div> |
| 6620 | </div> |
| 6621 | </div> |
| 6622 | </div> |
| 6623 | <div class="sect3"> |
| 6624 | <h4 id="_cockpit_js_user_session">cockpit.js: User Session</h4> |
| 6625 | <div class="paragraph"> |
| 6626 | <p>User information and login session state</p> |
| 6627 | </div> |
| 6628 | <div class="sect4"> |
| 6629 | <h5 id="cockpit-logout">cockpit.logout()</h5> |
| 6630 | <div class="literalblock"> |
| 6631 | <div class="content"> |
| 6632 | <pre>cockpit.logout([reload])</pre> |
| 6633 | </div> |
| 6634 | </div> |
| 6635 | <div class="paragraph"> |
| 6636 | <p>Logout of Cockpit. Unless <code>reload</code> is <code>false</code> this will also cause |
| 6637 | the page to be reloaded, so that the user can see the logged out state.</p> |
| 6638 | </div> |
| 6639 | </div> |
| 6640 | <div class="sect4"> |
| 6641 | <h5 id="cockpit-user">cockpit.user()</h5> |
| 6642 | <div class="literalblock"> |
| 6643 | <div class="content"> |
| 6644 | <pre>var promise = cockpit.user(); |
| 6645 | promise.then(user => { ... });</pre> |
| 6646 | </div> |
| 6647 | </div> |
| 6648 | <div class="paragraph"> |
| 6649 | <p>This object contains information about the user that’s currently logged |
| 6650 | into cockpit. The following fields are defined:</p> |
| 6651 | </div> |
| 6652 | <div class="dlist"> |
| 6653 | <dl> |
| 6654 | <dt class="hdlist1"><code>"id"</code></dt> |
| 6655 | <dd> |
| 6656 | <p>This is unix user id.</p> |
| 6657 | </dd> |
| 6658 | <dt class="hdlist1"><code>"gid"</code></dt> |
| 6659 | <dd> |
| 6660 | <p>This is unix user group id.</p> |
| 6661 | </dd> |
| 6662 | <dt class="hdlist1"><code>"name"</code></dt> |
| 6663 | <dd> |
| 6664 | <p>This is the unix user name like <code>"root"</code>.</p> |
| 6665 | </dd> |
| 6666 | <dt class="hdlist1"><code>"full_name"</code></dt> |
| 6667 | <dd> |
| 6668 | <p>This is a readable name for the user.</p> |
| 6669 | </dd> |
| 6670 | <dt class="hdlist1"><code>"groups"</code></dt> |
| 6671 | <dd> |
| 6672 | <p>This is an array of group names to which the user belongs. Since |
| 6673 | version 318, the first item in this list is the primary group.</p> |
| 6674 | </dd> |
| 6675 | <dt class="hdlist1"><code>"home"</code></dt> |
| 6676 | <dd> |
| 6677 | <p>This is user’s home directory.</p> |
| 6678 | </dd> |
| 6679 | <dt class="hdlist1"><code>"shell"</code></dt> |
| 6680 | <dd> |
| 6681 | <p>This is unix user shell.</p> |
| 6682 | </dd> |
| 6683 | </dl> |
| 6684 | </div> |
| 6685 | <div class="paragraph"> |
| 6686 | <p>Returns a promise that completes once the user information is available.</p> |
| 6687 | </div> |
| 6688 | <div class="admonitionblock warning"> |
| 6689 | <table> |
| 6690 | <tr> |
| 6691 | <td class="icon"> |
| 6692 | <div class="title">Warning</div> |
| 6693 | </td> |
| 6694 | <td class="content"> |
| 6695 | <div class="paragraph"> |
| 6696 | <p><code>cockpit.user()</code> is soft-deprecated since Cockpit 336, if your page |
| 6697 | does not need to maintain compatibility with older Cockpit versions you |
| 6698 | can use <a href="cockpit-util.html#cockpit-info">cockpit.info</a> to obtain the user information.</p> |
| 6699 | </div> |
| 6700 | </td> |
| 6701 | </tr> |
| 6702 | </table> |
| 6703 | </div> |
| 6704 | </div> |
| 6705 | <div class="sect4"> |
| 6706 | <h5 id="cockpit-permission">Permission lookup</h5> |
| 6707 | <div class="paragraph"> |
| 6708 | <p>Cockpit provides a mechanism for checking if the current user satisfies |
| 6709 | a given criteria. This is meant for updating UI elements based on what |
| 6710 | actions the user can perform. It is <em>not an access control mechanism</em>.</p> |
| 6711 | </div> |
| 6712 | <div class="sect5"> |
| 6713 | <h6 id="cockpit-permission-constructor">cockpit.permission()</h6> |
| 6714 | <div class="literalblock"> |
| 6715 | <div class="content"> |
| 6716 | <pre>permission = cockpit.permission([options])</pre> |
| 6717 | </div> |
| 6718 | </div> |
| 6719 | <div class="paragraph"> |
| 6720 | <p>Create a new permission object to check if the current user has a |
| 6721 | particular permission specified by <code>options</code>:</p> |
| 6722 | </div> |
| 6723 | <div class="dlist"> |
| 6724 | <dl> |
| 6725 | <dt class="hdlist1"><code>admin: true</code></dt> |
| 6726 | <dd> |
| 6727 | <p>True if the session has superuser privileges, i.e. can run channels as |
| 6728 | root with <code>{ superuser: "require" }</code>.</p> |
| 6729 | </dd> |
| 6730 | <dt class="hdlist1"><code>group:</code> <em>name</em></dt> |
| 6731 | <dd> |
| 6732 | <p>True if the currently logged user is a member of group <em>name</em>.</p> |
| 6733 | </dd> |
| 6734 | </dl> |
| 6735 | </div> |
| 6736 | <div class="paragraph"> |
| 6737 | <p>The permission result is always true for the "root" user. When |
| 6738 | <code>options</code> is not given, check if the current user is root.</p> |
| 6739 | </div> |
| 6740 | </div> |
| 6741 | <div class="sect5"> |
| 6742 | <h6 id="cockpit-permission-allowed">permission.allowed</h6> |
| 6743 | <div class="paragraph"> |
| 6744 | <p>A boolean value which indicates if the permission is allowed or not. |
| 6745 | This will be <code>null</code> if the permission is unknown, or there was an |
| 6746 | error checking the permission or the permission data has not yet loaded. |
| 6747 | This property will update asynchronously and if you wish to be notified |
| 6748 | of changes connect to the |
| 6749 | <a href="#cockpit-permission-changed">permission.onchanged</a> event.</p> |
| 6750 | </div> |
| 6751 | </div> |
| 6752 | <div class="sect5"> |
| 6753 | <h6 id="cockpit-permission-changed">permission.onchanged</h6> |
| 6754 | <div class="literalblock"> |
| 6755 | <div class="content"> |
| 6756 | <pre>permission.addEventListener("changed", function() { ... })</pre> |
| 6757 | </div> |
| 6758 | </div> |
| 6759 | <div class="paragraph"> |
| 6760 | <p>This event is fired when the permission changes. In particular the |
| 6761 | <a href="#cockpit-permission-allowed">permission.allowed</a> property.</p> |
| 6762 | </div> |
| 6763 | </div> |
| 6764 | <div class="sect5"> |
| 6765 | <h6 id="cockpit-permission-close">permission.close()</h6> |
| 6766 | <div class="literalblock"> |
| 6767 | <div class="content"> |
| 6768 | <pre>permission.close()</pre> |
| 6769 | </div> |
| 6770 | </div> |
| 6771 | <div class="paragraph"> |
| 6772 | <p>Closes the permission object and tears down any registered callbacks and |
| 6773 | dbus subscriptions.</p> |
| 6774 | </div> |
| 6775 | </div> |
| 6776 | </div> |
| 6777 | </div> |
| 6778 | <div class="sect3"> |
| 6779 | <h4 id="_cockpit_js_manifests">cockpit.js: Manifests</h4> |
| 6780 | <div class="sect4"> |
| 6781 | <h5 id="cockpit-manifest-loading">Loading Manifests</h5> |
| 6782 | <div class="paragraph"> |
| 6783 | <p>For a convenient access to all page manifests, include |
| 6784 | <code><script src="../manifests.js"></script></code> into your page to register |
| 6785 | the manifests at the <code>cockpit.manifests</code> global variable.</p> |
| 6786 | </div> |
| 6787 | <div class="paragraph"> |
| 6788 | <p>You can also load <code>../manifests.json</code> directly in your page, with |
| 6789 | <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch"><code>fetch()</code></a>.</p> |
| 6790 | </div> |
| 6791 | </div> |
| 6792 | </div> |
| 6793 | <div class="sect3"> |
| 6794 | <h4 id="_cockpit_js_metrics">cockpit.js: Metrics</h4> |
| 6795 | <div class="paragraph"> |
| 6796 | <p>Metrics about the system can be retrieved from several sources using |
| 6797 | <a href="#cockpit-metrics-function"><code>cockpit.metrics()</code></a> metrics channels. The |
| 6798 | metrics are made available as series data, and can be used with the |
| 6799 | <a href="cockpit-series-data.html#cockpit-series"><code>cockpit.series()</code></a> and |
| 6800 | <a href="cockpit-series-data.html#cockpit-grid"><code>cockpit.grid()</code></a> facilities.</p> |
| 6801 | </div> |
| 6802 | <div class="sect4"> |
| 6803 | <h5 id="cockpit-metrics-function">cockpit.metrics()</h5> |
| 6804 | <div class="literalblock"> |
| 6805 | <div class="content"> |
| 6806 | <pre>metrics = cockpit.metrics(interval, options, cache)</pre> |
| 6807 | </div> |
| 6808 | </div> |
| 6809 | <div class="paragraph"> |
| 6810 | <p>Opens a new metrics channel. The data retrieved will be available in the |
| 6811 | <a href="#cockpit-metrics-series"><code>metrics.series</code></a> series sink, and can be |
| 6812 | used together with <a href="cockpit-series-data.html#cockpit-grid"><code>cockpit.grid()</code></a> objects.</p> |
| 6813 | </div> |
| 6814 | <div class="paragraph"> |
| 6815 | <p>The <code>interval</code> is in milliseconds, and is the granularity of the |
| 6816 | series data retrieved. Any grids consuming the data must have the same |
| 6817 | interval.</p> |
| 6818 | </div> |
| 6819 | <div class="paragraph"> |
| 6820 | <p>The <code>cache</code> argument is a cache identifier. If specified, then this |
| 6821 | metrics channel will share data with other metrics channels of the same |
| 6822 | identifier. Make sure to use a globally unique string.</p> |
| 6823 | </div> |
| 6824 | <div class="paragraph"> |
| 6825 | <p>The <code>options</code> argument is either a javascript plain object, or an |
| 6826 | array of those. Each object can have the following fields.</p> |
| 6827 | </div> |
| 6828 | <div class="dlist"> |
| 6829 | <dl> |
| 6830 | <dt class="hdlist1"><code>"metrics"</code></dt> |
| 6831 | <dd> |
| 6832 | <p>An array of full metric descriptions, as javascript objects. The |
| 6833 | specifics of these, and how to determine which ones to use, can |
| 6834 | unfortunately only be found in the low-level protocol documentation. |
| 6835 | This option is required.</p> |
| 6836 | </dd> |
| 6837 | <dt class="hdlist1"><code>"source"</code></dt> |
| 6838 | <dd> |
| 6839 | <p>The source to use for real-time data. This is used by the <code>follow</code> |
| 6840 | method, see below. Set to <code>"internal"</code> to retrieve internal metrics |
| 6841 | read by the bridge. If set to <code>"direct"</code> or <code>"pmcd"</code> then data |
| 6842 | will be retrieved from <a href="https://pcp.io">PCP</a>if it is available. The |
| 6843 | default is <code>"internal"</code>.</p> |
| 6844 | </dd> |
| 6845 | <dt class="hdlist1"><code>"archive_source"</code></dt> |
| 6846 | <dd> |
| 6847 | <p>The source to use for retrieving historical data. This is used by the |
| 6848 | <code>fetch</code> method, see below. Set to <code>"pcp-archive"</code> to retrieve data |
| 6849 | from PCP archives. The default is not to try to retrieve historical |
| 6850 | data.</p> |
| 6851 | </dd> |
| 6852 | </dl> |
| 6853 | </div> |
| 6854 | <div class="paragraph"> |
| 6855 | <p>When the <code>options</code> argument is an array of javascript objects, then |
| 6856 | the metrics channel tries to use them in order until one succeeds. This |
| 6857 | way, you can prefer PCP as the source but fall back to internal metrics |
| 6858 | when PCP is not available, for example. The channel gives no indication |
| 6859 | which of the options has been used, and <code>fetch</code> and <code>follow</code> might |
| 6860 | use different entries from the list.</p> |
| 6861 | </div> |
| 6862 | </div> |
| 6863 | <div class="sect4"> |
| 6864 | <h5 id="cockpit-metrics-fetch">metrics.fetch()</h5> |
| 6865 | <div class="literalblock"> |
| 6866 | <div class="content"> |
| 6867 | <pre>metrics.fetch(beg, end)</pre> |
| 6868 | </div> |
| 6869 | </div> |
| 6870 | <div class="paragraph"> |
| 6871 | <p>Retrieve archived metrics data between <code>beg</code> and <code>end</code>. The |
| 6872 | arguments can either be numbers, in which case they are interval based |
| 6873 | offsets, or they can be javascript Date objects.</p> |
| 6874 | </div> |
| 6875 | </div> |
| 6876 | <div class="sect4"> |
| 6877 | <h5 id="cockpit-metrics-follow">metrics.follow()</h5> |
| 6878 | <div class="literalblock"> |
| 6879 | <div class="content"> |
| 6880 | <pre>metrics.follow()</pre> |
| 6881 | </div> |
| 6882 | </div> |
| 6883 | <div class="paragraph"> |
| 6884 | <p>Start retrieving live metrics data as it become available.</p> |
| 6885 | </div> |
| 6886 | </div> |
| 6887 | <div class="sect4"> |
| 6888 | <h5 id="cockpit-metrics-close">metrics.close()</h5> |
| 6889 | <div class="literalblock"> |
| 6890 | <div class="content"> |
| 6891 | <pre>metrics.close()</pre> |
| 6892 | </div> |
| 6893 | </div> |
| 6894 | <div class="paragraph"> |
| 6895 | <p>Stop the retrieval of metrics and release resources.</p> |
| 6896 | </div> |
| 6897 | </div> |
| 6898 | <div class="sect4"> |
| 6899 | <h5 id="cockpit-metrics-series">metrics.series</h5> |
| 6900 | <div class="paragraph"> |
| 6901 | <p>The series sink where data retrieved data will be processed.</p> |
| 6902 | </div> |
| 6903 | </div> |
| 6904 | <div class="sect4"> |
| 6905 | <h5 id="cockpit-metrics-meta">metrics.meta</h5> |
| 6906 | <div class="paragraph"> |
| 6907 | <p>The metrics meta data last received.</p> |
| 6908 | </div> |
| 6909 | </div> |
| 6910 | <div class="sect4"> |
| 6911 | <h5 id="cockpit-metrics-onchanged">metrics.onchanged</h5> |
| 6912 | <div class="literalblock"> |
| 6913 | <div class="content"> |
| 6914 | <pre>metrics.onchanged = function() { }</pre> |
| 6915 | </div> |
| 6916 | </div> |
| 6917 | <div class="paragraph"> |
| 6918 | <p>An event triggered when one of the properties on this metrics object |
| 6919 | changes.</p> |
| 6920 | </div> |
| 6921 | </div> |
| 6922 | </div> |
| 6923 | <div class="sect3"> |
| 6924 | <h4 id="_cockpit_js_series_data">cockpit.js: Series Data</h4> |
| 6925 | <div class="paragraph"> |
| 6926 | <p>Series data consists of values along a continuous (usually time) axis. |
| 6927 | We can place these in grids which expose a distinct subset of these |
| 6928 | values. These are the underlying mechanism for displaying metrics data |
| 6929 | in graphs.</p> |
| 6930 | </div> |
| 6931 | <div class="sect4"> |
| 6932 | <h5 id="cockpit-grid">cockpit.grid()</h5> |
| 6933 | <div class="literalblock"> |
| 6934 | <div class="content"> |
| 6935 | <pre>grid = cockpit.grid(interval, [beg, end])</pre> |
| 6936 | </div> |
| 6937 | </div> |
| 6938 | <div class="paragraph"> |
| 6939 | <p>Creates a grid object to contain series data.</p> |
| 6940 | </div> |
| 6941 | <div class="paragraph"> |
| 6942 | <p>The <code>interval</code> is the granularity of the grid. Usually this is a |
| 6943 | number of milliseconds, when used with time series data. The <code>beg</code> and |
| 6944 | <code>end</code> are the bounds of the grid. If omitted they will be set to zero |
| 6945 | for an initially empty grid.</p> |
| 6946 | </div> |
| 6947 | <div class="paragraph"> |
| 6948 | <p>If <code>beg</code> and/or <code>end</code> are negative (including negative zero) then |
| 6949 | they are interpreted in number of intervals relative to the current |
| 6950 | time. Thus cockpit.grid(1000, -300, -0) will create a grid for the most |
| 6951 | recent 5 minutes.</p> |
| 6952 | </div> |
| 6953 | </div> |
| 6954 | <div class="sect4"> |
| 6955 | <h5 id="cockpit-grid-add">grid.add()</h5> |
| 6956 | <div class="literalblock"> |
| 6957 | <div class="content"> |
| 6958 | <pre>row = grid.add(series, path) |
| 6959 | row = grid.add(callback, [early]) |
| 6960 | row = grid.add()</pre> |
| 6961 | </div> |
| 6962 | </div> |
| 6963 | <div class="paragraph"> |
| 6964 | <p>Adds a row to the grid. The returned <code>row</code> is a Javascript array that |
| 6965 | will contain series data. The arguments control how the row is populated |
| 6966 | from the series data. The <code>row</code> is a sparse array. Its <code>row.length</code> |
| 6967 | will not match the expected size of the grid, unless and until the row |
| 6968 | has been completely filled in. The first index of the <code>row</code> will |
| 6969 | contain the data from the series data at the |
| 6970 | <a href="#cockpit-grid-beg"><code>grid.beg</code></a> offset.</p> |
| 6971 | </div> |
| 6972 | <div class="paragraph"> |
| 6973 | <p>When no arguments are passed, an empty row is added, and it is not |
| 6974 | populated with data.</p> |
| 6975 | </div> |
| 6976 | <div class="paragraph"> |
| 6977 | <p>When called with a <code>series</code> and <code>path</code> argument then the row will be |
| 6978 | populated directly with series data. The <code>series</code> can either be a |
| 6979 | <a href="#cockpit-series">series object</a> or an object that has an |
| 6980 | <code>obj.series</code> property. The <a href="#cockpit-series-interval">series |
| 6981 | interval</a> must match the interval of this grid. If <code>path</code> is missing |
| 6982 | or empty, then the series data is placed into the row directly. |
| 6983 | Otherwise <code>path</code> indicates which part of the series data to place in |
| 6984 | the row. When <code>path</code> is an array, it is used as a set of property |
| 6985 | names or array indexes to follow into nested series data. When <code>path</code> |
| 6986 | is a dotted string, it is split and used the same way to locate the |
| 6987 | correct value in nested series data. The exact format of the series data |
| 6988 | depends on its producer, and relevant paths will be documented there.</p> |
| 6989 | </div> |
| 6990 | <div class="paragraph"> |
| 6991 | <p>If a <code>callback</code> function is specified, then it will be invoked to |
| 6992 | provide series data for the row. The function is invoked as |
| 6993 | <code>callback(row, index, count)</code>, where the <code>row</code> is the row to fill |
| 6994 | in, the <code>index</code> is the index to start filling in and <code>count</code> is the |
| 6995 | number of items to fill in. The <code>this</code> variable will be set to the |
| 6996 | grid while invoking the <code>callback</code>. The callback is called after other |
| 6997 | data rows for a given series have been filled in. Callbacks are called |
| 6998 | in the order added, unless the <code>early</code> argument is set to <code>true</code>, in |
| 6999 | which case the callback is called earlier than callbacks without the |
| 7000 | <code>early</code> argument set.</p> |
| 7001 | </div> |
| 7002 | <div class="paragraph"> |
| 7003 | <p>To remove the row use the <a href="#cockpit-grid-remove"><code>grid.remove()</code> |
| 7004 | method.</a></p> |
| 7005 | </div> |
| 7006 | <div class="paragraph"> |
| 7007 | <p>The row will start being populated with data when the <code>series</code> |
| 7008 | produces data. To make this happen right away, use the |
| 7009 | <a href="#cockpit-grid-sync"><code>grid.sync()</code></a> method.</p> |
| 7010 | </div> |
| 7011 | </div> |
| 7012 | <div class="sect4"> |
| 7013 | <h5 id="cockpit-grid-remove">grid.remove()</h5> |
| 7014 | <div class="literalblock"> |
| 7015 | <div class="content"> |
| 7016 | <pre>grid.remove(row)</pre> |
| 7017 | </div> |
| 7018 | </div> |
| 7019 | <div class="paragraph"> |
| 7020 | <p>Remove a previously added <code>row</code> from the grid. The row will no longer |
| 7021 | be updated with series data.</p> |
| 7022 | </div> |
| 7023 | </div> |
| 7024 | <div class="sect4"> |
| 7025 | <h5 id="cockpit-grid-sync">grid.sync()</h5> |
| 7026 | <div class="literalblock"> |
| 7027 | <div class="content"> |
| 7028 | <pre>grid.sync()</pre> |
| 7029 | </div> |
| 7030 | </div> |
| 7031 | <div class="paragraph"> |
| 7032 | <p>Load or reload data from the series into the rows. This does not clear |
| 7033 | the rows before populating them. Some data may be populated immediately, |
| 7034 | others may have to wait until data can be loaded. Internally this |
| 7035 | function calls <a href="#cockpit-series-load"><code>series.load()</code></a> for each |
| 7036 | series.</p> |
| 7037 | </div> |
| 7038 | <div class="paragraph"> |
| 7039 | <p>All rows with callbacks will be invoked to regenerate all the data. The |
| 7040 | <a href="#cockpit-grid-onnotify"><code>grid.onnotify</code></a> event will be triggered. |
| 7041 | It is not necessary to call this function after a call of the |
| 7042 | <a href="#cockpit-grid-move"><code>grid.move()</code></a> method.</p> |
| 7043 | </div> |
| 7044 | </div> |
| 7045 | <div class="sect4"> |
| 7046 | <h5 id="cockpit-grid-move">grid.move()</h5> |
| 7047 | <div class="literalblock"> |
| 7048 | <div class="content"> |
| 7049 | <pre>grid.move(beg[, end])</pre> |
| 7050 | </div> |
| 7051 | </div> |
| 7052 | <div class="paragraph"> |
| 7053 | <p>Move the grid to new <code>beg</code> and <code>end</code> range. Data will be discarded |
| 7054 | from the rows and <a href="#cockpit-grid-sync"><code>grid.sync()</code></a> will be |
| 7055 | called to load or reload series data for the new range of offsets.</p> |
| 7056 | </div> |
| 7057 | <div class="paragraph"> |
| 7058 | <p>If <code>end</code> is not specified it will be set to <code>beg</code>. If <code>beg</code> and/or |
| 7059 | <code>end</code> are negative (including negative zero) then they will be set to |
| 7060 | the number of intervals prior to the current time taken as an interval.</p> |
| 7061 | </div> |
| 7062 | <div class="paragraph"> |
| 7063 | <p>If <code>beg</code> and/or <code>end</code> are negative (including negative zero) then |
| 7064 | they are interpreted in number of intervals relative to the current |
| 7065 | time. Thus cockpit.grid(1000, -300, -0) will create a grid for the most |
| 7066 | recent 5 minutes.</p> |
| 7067 | </div> |
| 7068 | </div> |
| 7069 | <div class="sect4"> |
| 7070 | <h5 id="cockpit-grid-walk">grid.walk()</h5> |
| 7071 | <div class="literalblock"> |
| 7072 | <div class="content"> |
| 7073 | <pre>grid.walk()</pre> |
| 7074 | </div> |
| 7075 | </div> |
| 7076 | <div class="paragraph"> |
| 7077 | <p>Move the grid forward every |
| 7078 | <a href="#cockpit-grid-interval"><code>grid.interval</code></a> milliseconds. To stop |
| 7079 | moving forward, call <a href="#cockpit-grid-move"><code>grid.move()</code></a>.</p> |
| 7080 | </div> |
| 7081 | </div> |
| 7082 | <div class="sect4"> |
| 7083 | <h5 id="cockpit-grid-notify">grid.notify()</h5> |
| 7084 | <div class="literalblock"> |
| 7085 | <div class="content"> |
| 7086 | <pre>grid.notify(index, count)</pre> |
| 7087 | </div> |
| 7088 | </div> |
| 7089 | <div class="paragraph"> |
| 7090 | <p>This function is called to have rows with callbacks recalculate their |
| 7091 | data. It is not normally necessary to call this function, as it will be |
| 7092 | invoked automatically when new series data is available or has been |
| 7093 | loaded. This function triggers the |
| 7094 | <a href="#cockpit-grid-onnotify"><code>grid.onnotify</code></a> event.</p> |
| 7095 | </div> |
| 7096 | </div> |
| 7097 | <div class="sect4"> |
| 7098 | <h5 id="cockpit-grid-onnotify">grid.onnotify</h5> |
| 7099 | <div class="literalblock"> |
| 7100 | <div class="content"> |
| 7101 | <pre>grid.addEventListener("notify", function(index, count) { ... });</pre> |
| 7102 | </div> |
| 7103 | </div> |
| 7104 | <div class="paragraph"> |
| 7105 | <p>An event that is triggered when some part of the series data in grid |
| 7106 | changes. The <code>index</code> is the row index where things changed, and the |
| 7107 | <code>count</code> is the length of the data that changed.</p> |
| 7108 | </div> |
| 7109 | </div> |
| 7110 | <div class="sect4"> |
| 7111 | <h5 id="cockpit-grid-close">grid.close()</h5> |
| 7112 | <div class="literalblock"> |
| 7113 | <div class="content"> |
| 7114 | <pre>grid.close()</pre> |
| 7115 | </div> |
| 7116 | </div> |
| 7117 | <div class="paragraph"> |
| 7118 | <p>Close the grid, and stop updating the rows.</p> |
| 7119 | </div> |
| 7120 | </div> |
| 7121 | <div class="sect4"> |
| 7122 | <h5 id="cockpit-grid-interval">grid.interval</h5> |
| 7123 | <div class="paragraph"> |
| 7124 | <p>The granularity of the grid. For time series data this is an interval in |
| 7125 | milliseconds. In order to use a given <a href="#cockpit-grid">grid</a> and |
| 7126 | <a href="#cockpit-series">series</a> together, their interval properties must |
| 7127 | match.</p> |
| 7128 | </div> |
| 7129 | </div> |
| 7130 | <div class="sect4"> |
| 7131 | <h5 id="cockpit-grid-beg">grid.beg</h5> |
| 7132 | <div class="paragraph"> |
| 7133 | <p>The beginning offset of the series data in the grid. Do not set this |
| 7134 | property directly. Use the <a href="#cockpit-grid-move">grid.move()</a> method |
| 7135 | instead.</p> |
| 7136 | </div> |
| 7137 | </div> |
| 7138 | <div class="sect4"> |
| 7139 | <h5 id="cockpit-grid-end">grid.end</h5> |
| 7140 | <div class="paragraph"> |
| 7141 | <p>The ending 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-series">cockpit.series()</h5> |
| 7148 | <div class="literalblock"> |
| 7149 | <div class="content"> |
| 7150 | <pre>series = cockpit.series(interval, [cache, fetch])</pre> |
| 7151 | </div> |
| 7152 | </div> |
| 7153 | <div class="paragraph"> |
| 7154 | <p>Create a new sink of series data. This is usually done by producers of |
| 7155 | series data, and it is rare to invoke this function directly.</p> |
| 7156 | </div> |
| 7157 | <div class="paragraph"> |
| 7158 | <p>The <code>interval</code> is the granularity of the series data. For time series |
| 7159 | data this is an interval in milliseconds. If a <code>cache</code> string is |
| 7160 | specified, series data will be cached across frames for series with the |
| 7161 | same <code>cache</code> cache identifier to load and/or reload.</p> |
| 7162 | </div> |
| 7163 | <div class="paragraph"> |
| 7164 | <p>If a <code>fetch</code> callback is specified, then it will be invoked when grids |
| 7165 | request certain ranges of data. The <code>fetch</code> callback is invoked with |
| 7166 | <code>function fetch(beg, end) { ... }</code> range offsets. The |
| 7167 | <a href="#cockpit-series-input">series.input()</a> should be called with data |
| 7168 | retrieved, either immediately or at a later time. The callback may be |
| 7169 | called multiple times for the same ranges of data. It is up to the |
| 7170 | callback to determine when or whether it should retrieve the data more |
| 7171 | than once.</p> |
| 7172 | </div> |
| 7173 | <div class="paragraph"> |
| 7174 | <p>A producer of series data, usually calls this function and creates |
| 7175 | itself a <code>obj.series</code> property containing this series object.</p> |
| 7176 | </div> |
| 7177 | </div> |
| 7178 | <div class="sect4"> |
| 7179 | <h5 id="cockpit-series-input">series.input()</h5> |
| 7180 | <div class="literalblock"> |
| 7181 | <div class="content"> |
| 7182 | <pre>series.input(beg, items[, mapping])</pre> |
| 7183 | </div> |
| 7184 | </div> |
| 7185 | <div class="paragraph"> |
| 7186 | <p>Send series data into the series sink. Any grids that have added rows |
| 7187 | based on this series, will have data filled in. The <code>beg</code> is the |
| 7188 | beginning offset of <code>items</code>. The <code>items</code> are an array one or more |
| 7189 | series data items.</p> |
| 7190 | </div> |
| 7191 | <div class="paragraph"> |
| 7192 | <p>Producers may wish to provide additional properties that can be used in |
| 7193 | lookup paths that rows can pull from. This is done in the <code>mapping</code> |
| 7194 | argument. If specified it is a tree of objects. Each sub object should |
| 7195 | have a property with the name <code>""</code> empty string, which will be used as |
| 7196 | the property name or index in place of the one used in the lookup path.</p> |
| 7197 | </div> |
| 7198 | </div> |
| 7199 | <div class="sect4"> |
| 7200 | <h5 id="cockpit-series-load">series.load()</h5> |
| 7201 | <div class="literalblock"> |
| 7202 | <div class="content"> |
| 7203 | <pre>series.load(beg, end)</pre> |
| 7204 | </div> |
| 7205 | </div> |
| 7206 | <div class="paragraph"> |
| 7207 | <p>Load data from the series into any grids that have rows based on this |
| 7208 | series data. Any cached data will be filled in immediately. Any data not |
| 7209 | cached, will be requested from the producer, if possible, and may arrive |
| 7210 | at a later time.</p> |
| 7211 | </div> |
| 7212 | <div class="paragraph"> |
| 7213 | <p>The <code>beg</code> and <code>end</code> denote the range of data to load.</p> |
| 7214 | </div> |
| 7215 | </div> |
| 7216 | <div class="sect4"> |
| 7217 | <h5 id="cockpit-series-interval">series.interval</h5> |
| 7218 | <div class="paragraph"> |
| 7219 | <p>The granularity of the series. For time series data this is an interval |
| 7220 | in milliseconds. In order to use a given <a href="#cockpit-grid">grid</a> and |
| 7221 | <a href="#cockpit-series">series</a> together, their interval properties must |
| 7222 | match.</p> |
| 7223 | </div> |
| 7224 | </div> |
| 7225 | <div class="sect4"> |
| 7226 | <h5 id="cockpit-series-limit">series.limit</h5> |
| 7227 | <div class="paragraph"> |
| 7228 | <p>The maximum number of items to cache for loading and/or reloading. You |
| 7229 | can change this value to a different number. Having a number close to |
| 7230 | zero will break certain usage of grids, such as |
| 7231 | <a href="#cockpit-grid-walk"><code>grid.walk()</code></a>.</p> |
| 7232 | </div> |
| 7233 | </div> |
| 7234 | </div> |
| 7235 | <div class="sect3"> |
| 7236 | <h4 id="_cockpit_js_spawning_processes">cockpit.js: Spawning Processes</h4> |
| 7237 | <div class="paragraph"> |
| 7238 | <p>This is the API for spawning a process and receiving its output, as well |
| 7239 | as exit codes.</p> |
| 7240 | </div> |
| 7241 | <div class="sect4"> |
| 7242 | <h5 id="cockpit-spawn-spawn">cockpit.spawn()</h5> |
| 7243 | <div class="literalblock"> |
| 7244 | <div class="content"> |
| 7245 | <pre>process = cockpit.spawn(args, [options])</pre> |
| 7246 | </div> |
| 7247 | </div> |
| 7248 | <div class="paragraph"> |
| 7249 | <p>Spawns a process on the system.</p> |
| 7250 | </div> |
| 7251 | <div class="paragraph"> |
| 7252 | <p>The <code>args</code> should be an array starting with the executable and |
| 7253 | containing all the arguments to pass on the command line. If <code>args</code> is |
| 7254 | a string then it is interpreted as an executable name. The optional |
| 7255 | <code>options</code> argument is a javascript plain object and can contain any of |
| 7256 | the following fields:</p> |
| 7257 | </div> |
| 7258 | <div class="dlist"> |
| 7259 | <dl> |
| 7260 | <dt class="hdlist1"><code>"binary"</code></dt> |
| 7261 | <dd> |
| 7262 | <p>If set to <code>true</code> then handle the input and output of the process as |
| 7263 | arrays of binary bytes.</p> |
| 7264 | </dd> |
| 7265 | <dt class="hdlist1"><code>"directory"</code></dt> |
| 7266 | <dd> |
| 7267 | <p>The directory to spawn the process in.</p> |
| 7268 | </dd> |
| 7269 | <dt class="hdlist1"><code>"err"</code></dt> |
| 7270 | <dd> |
| 7271 | <p>Controls where the standard error is sent. By default it is logged to |
| 7272 | the journal. If set to <code>"out"</code> it is included in with the output |
| 7273 | data. If set to <code>"ignore"</code> then the error output is discarded. If |
| 7274 | set to <code>"message"</code>, then it will be returned as the error message. |
| 7275 | When the <code>"pty"</code> field is set, this field has no effect.</p> |
| 7276 | </dd> |
| 7277 | <dt class="hdlist1"><code>"environ"</code></dt> |
| 7278 | <dd> |
| 7279 | <p>An optional array that contains strings to be used as additional |
| 7280 | environment variables for the new process. These are <code>"NAME=VALUE"</code> |
| 7281 | strings.</p> |
| 7282 | </dd> |
| 7283 | <dt class="hdlist1"><code>"pty"</code></dt> |
| 7284 | <dd> |
| 7285 | <p>Launch the process in its own PTY terminal, and send/receive terminal |
| 7286 | input and output.</p> |
| 7287 | </dd> |
| 7288 | <dt class="hdlist1"><code>"batch"</code></dt> |
| 7289 | <dd> |
| 7290 | <p>Batch data coming from the process in blocks of at least this size. |
| 7291 | This is not a guarantee. After a short timeout the data will be sent |
| 7292 | even if the data doesn’t match the batch size. Defaults to zero.</p> |
| 7293 | </dd> |
| 7294 | <dt class="hdlist1"><code>"latency"</code></dt> |
| 7295 | <dd> |
| 7296 | <p>The timeout for flushing any cached data in milliseconds.</p> |
| 7297 | </dd> |
| 7298 | <dt class="hdlist1"><code>"superuser"</code></dt> |
| 7299 | <dd> |
| 7300 | <p>Set to <code>"require"</code> to spawn the process as root instead of the |
| 7301 | logged in user. If the currently logged in user is not permitted to |
| 7302 | become root (eg: via <code>pkexec</code>) then the <code>client</code> will immediately |
| 7303 | be <a href="cockpit-dbus.html#cockpit-dbus-onclose">closed</a> with a <code>"access-denied"</code> |
| 7304 | problem code. |
| 7305 | + |
| 7306 | Set to <code>"try"</code> to try to run the process as root, but if that fails, |
| 7307 | fall back to an unprivileged process.</p> |
| 7308 | </dd> |
| 7309 | </dl> |
| 7310 | </div> |
| 7311 | <div class="paragraph"> |
| 7312 | <p>The spawned process is a |
| 7313 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a> |
| 7314 | that will complete if the process exits successfully, or fail if there’s |
| 7315 | a problem. Some additional methods besides the standard promise methods |
| 7316 | are documented below.</p> |
| 7317 | </div> |
| 7318 | <div class="paragraph"> |
| 7319 | <p>The standard output of the process is made available via the spawned |
| 7320 | process object. Any non-UTF8 output from the process will be coerced |
| 7321 | into textual form. It is highly recommended that only textual output be |
| 7322 | produced by the command. The standard error is logged to the journal.</p> |
| 7323 | </div> |
| 7324 | </div> |
| 7325 | <div class="sect4"> |
| 7326 | <h5 id="cockpit-spawn-script">cockpit.script()</h5> |
| 7327 | <div class="literalblock"> |
| 7328 | <div class="content"> |
| 7329 | <pre>process = cockpit.script(script, [args], [options])</pre> |
| 7330 | </div> |
| 7331 | </div> |
| 7332 | <div class="paragraph"> |
| 7333 | <p>Run a shell script on the system.</p> |
| 7334 | </div> |
| 7335 | <div class="paragraph"> |
| 7336 | <p>This function <a href="#cockpit-spawn-spawn">spawns</a> a Bourne shell script |
| 7337 | process. The full text of the <code>/bin/sh</code> shell script should be passed |
| 7338 | in as the first argument. The <code>args</code> can be an array of arguments, not |
| 7339 | including the executable, which are passed to the script as <code>$1</code>, |
| 7340 | <code>$2</code> and so on. Shebang options are not used or respected.</p> |
| 7341 | </div> |
| 7342 | <div class="paragraph"> |
| 7343 | <p>The <code>options</code> is an optional javascript plain object and can include |
| 7344 | any of the fields listed for the |
| 7345 | <a href="#cockpit-spawn-spawn"><code>cockpit.spawn()</code></a> function.</p> |
| 7346 | </div> |
| 7347 | <div class="paragraph"> |
| 7348 | <p>The spawned process is a |
| 7349 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a> |
| 7350 | that will complete if the script exits successfully, or fail if there’s |
| 7351 | a problem. Some additional methods besides the standard promise methods |
| 7352 | are documented below.</p> |
| 7353 | </div> |
| 7354 | <div class="paragraph"> |
| 7355 | <p>The standard output of the process is made available via the spawned |
| 7356 | process object. Any non-UTF8 output from the process will be coerced |
| 7357 | into textual form. It is highly recommended that only textual output be |
| 7358 | produced by the command. The standard error is logged to the journal by |
| 7359 | default.</p> |
| 7360 | </div> |
| 7361 | </div> |
| 7362 | <div class="sect4"> |
| 7363 | <h5 id="cockpit-spawn-then">process.then()</h5> |
| 7364 | <div class="literalblock"> |
| 7365 | <div class="content"> |
| 7366 | <pre>process.then((data[, message]) => { ... })</pre> |
| 7367 | </div> |
| 7368 | </div> |
| 7369 | <div class="paragraph"> |
| 7370 | <p>This is a standard |
| 7371 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">promise</a> |
| 7372 | method. It sets up a handler to be called when the process finishes |
| 7373 | successfully.</p> |
| 7374 | </div> |
| 7375 | <div class="paragraph"> |
| 7376 | <p>The <code>data</code> argument contains the standard output of the process. If it |
| 7377 | a string, unless the process was opened in binary mode, in which case |
| 7378 | the <code>data</code> is an array of bytes. If a <code>process.stream()</code> handler is |
| 7379 | set up, then any standard output data consumed by the handler will not |
| 7380 | be included in the <code>data</code> argument.</p> |
| 7381 | </div> |
| 7382 | <div class="paragraph"> |
| 7383 | <p>If the process was spawned with the <code>"err"</code> option set to |
| 7384 | <code>"message"</code> then the second argument will contain the standard error |
| 7385 | output of the process.</p> |
| 7386 | </div> |
| 7387 | </div> |
| 7388 | <div class="sect4"> |
| 7389 | <h5 id="cockpit-spawn-catch">process.catch()</h5> |
| 7390 | <div class="literalblock"> |
| 7391 | <div class="content"> |
| 7392 | <pre>process.catch((exception[, data]) => { ... })</pre> |
| 7393 | </div> |
| 7394 | </div> |
| 7395 | <div class="paragraph"> |
| 7396 | <p>This is a standard |
| 7397 | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a> |
| 7398 | method. It sets up a handler to be called when the process fails, |
| 7399 | terminates or exits.</p> |
| 7400 | </div> |
| 7401 | <div class="paragraph"> |
| 7402 | <p>The <code>exception</code> object passed to the handler can have the following |
| 7403 | fields:</p> |
| 7404 | </div> |
| 7405 | <div class="dlist"> |
| 7406 | <dl> |
| 7407 | <dt class="hdlist1"><code>message</code></dt> |
| 7408 | <dd> |
| 7409 | <p>A message describing the exception. If the process was spawned with |
| 7410 | the <code>"err"</code> option set to <code>"message"</code> then the second argument |
| 7411 | will contain the standard error output of the process.</p> |
| 7412 | </dd> |
| 7413 | <dt class="hdlist1"><code>problem</code></dt> |
| 7414 | <dd> |
| 7415 | <p>A <a href="cockpit-error.html#cockpit-problems">problem code</a> string when a problem occurred |
| 7416 | starting or communicating with the process. This is <code>null</code> if the |
| 7417 | process exited or was terminated.</p> |
| 7418 | </dd> |
| 7419 | <dt class="hdlist1"><code>exit_status</code></dt> |
| 7420 | <dd> |
| 7421 | <p>The numeric exit status of the process. This is <code>null</code> if the |
| 7422 | process did not exit.</p> |
| 7423 | </dd> |
| 7424 | <dt class="hdlist1"><code>exit_signal</code></dt> |
| 7425 | <dd> |
| 7426 | <p>A string representing a unix signal that caused the process to |
| 7427 | terminate. This is <code>null</code> if the process did not terminate because |
| 7428 | of a signal.</p> |
| 7429 | </dd> |
| 7430 | </dl> |
| 7431 | </div> |
| 7432 | <div class="paragraph"> |
| 7433 | <p>If the process actually ran and produced output before failing, it will |
| 7434 | be available in the <code>data</code> argument. Otherwise this argument will be |
| 7435 | <code>undefined</code>.</p> |
| 7436 | </div> |
| 7437 | </div> |
| 7438 | <div class="sect4"> |
| 7439 | <h5 id="cockpit-spawn-stream">process.stream()</h5> |
| 7440 | <div class="literalblock"> |
| 7441 | <div class="content"> |
| 7442 | <pre>process.stream(data => { ... })</pre> |
| 7443 | </div> |
| 7444 | </div> |
| 7445 | <div class="paragraph"> |
| 7446 | <p>This sets up a handler to be called when the process has standard |
| 7447 | output. The handler will be called multiple times. The handler will be |
| 7448 | called regardless of whether the process ends up exiting successfully or |
| 7449 | not.</p> |
| 7450 | </div> |
| 7451 | <div class="paragraph"> |
| 7452 | <p>Only one handler may be registered at a time. Registering an additional |
| 7453 | handler replaces the previous one. The handler receives either string |
| 7454 | <code>data</code> or an array of binary bytes as its argument. A stream handler |
| 7455 | may return a number, which indicates the number of characters or bytes |
| 7456 | consumed from <code>data</code>. Any data not consumed will be included again the |
| 7457 | next time the handler is called.</p> |
| 7458 | </div> |
| 7459 | <div class="paragraph"> |
| 7460 | <p>If a <code>process.stream()</code> handler is set up, then the <code>process.then()</code> |
| 7461 | handlers will only get any remaining data not consumed by the stream |
| 7462 | handler.</p> |
| 7463 | </div> |
| 7464 | </div> |
| 7465 | <div class="sect4"> |
| 7466 | <h5 id="cockpit-spawn-input">process.input()</h5> |
| 7467 | <div class="literalblock"> |
| 7468 | <div class="content"> |
| 7469 | <pre>process.input(data, [stream])</pre> |
| 7470 | </div> |
| 7471 | </div> |
| 7472 | <div class="paragraph"> |
| 7473 | <p>This method writes <code>data</code> to the standard input of the process. If |
| 7474 | <code>data</code> is <code>null</code> or <code>undefined</code> it is not sent. The <code>data</code> |
| 7475 | should be a string or an array of bytes if the process was opened in |
| 7476 | binary mode.</p> |
| 7477 | </div> |
| 7478 | <div class="paragraph"> |
| 7479 | <p>If <code>stream</code> is set to <code>true</code> then this function may be called again |
| 7480 | with further input. Otherwise the standard input of the process is |
| 7481 | closed.</p> |
| 7482 | </div> |
| 7483 | </div> |
| 7484 | <div class="sect4"> |
| 7485 | <h5 id="cockpit-spawn-close">process.close()</h5> |
| 7486 | <div class="literalblock"> |
| 7487 | <div class="content"> |
| 7488 | <pre>process.close([problem])</pre> |
| 7489 | </div> |
| 7490 | </div> |
| 7491 | <div class="paragraph"> |
| 7492 | <p>Close the process by closing its standard input and output. If |
| 7493 | <code>problem</code> is specified it should be a standard |
| 7494 | <a href="cockpit-error.html#cockpit-problems">problem code</a> string. In this case the process |
| 7495 | will be terminated with a signal.</p> |
| 7496 | </div> |
| 7497 | </div> |
| 7498 | </div> |
| 7499 | <div class="sect3"> |
| 7500 | <h4 id="_cockpit_js_utilities">cockpit.js: Utilities</h4> |
| 7501 | <div class="paragraph"> |
| 7502 | <p>Various utility functions</p> |
| 7503 | </div> |
| 7504 | <div class="sect4"> |
| 7505 | <h5 id="cockpit-format">cockpit.format()</h5> |
| 7506 | <div class="literalblock"> |
| 7507 | <div class="content"> |
| 7508 | <pre>string = cockpit.format(template, args) |
| 7509 | string = cockpit.format(template, [arg, ...])</pre> |
| 7510 | </div> |
| 7511 | </div> |
| 7512 | <div class="paragraph"> |
| 7513 | <p>Format a string interpolating <code>args</code> into <code>template</code> using shell |
| 7514 | like syntax. The <code>args</code> may be either an array or javascript object. |
| 7515 | The <code>template</code> can contain fields that look like <code>$name</code> or |
| 7516 | <code>${name}</code> or <code>$0</code>. Numeric fields are used with array <code>args</code> and |
| 7517 | start at zero.</p> |
| 7518 | </div> |
| 7519 | <div class="paragraph"> |
| 7520 | <p>In the second form, multiple <code>arg</code> arguments may be passed directly, |
| 7521 | and interpolated as as numeric fields in the <code>template</code>.</p> |
| 7522 | </div> |
| 7523 | <div class="paragraph"> |
| 7524 | <p>All falsy arguments except the numbers <code>0</code> and `0.0`are replaced by |
| 7525 | an empty string.</p> |
| 7526 | </div> |
| 7527 | </div> |
| 7528 | <div class="sect4"> |
| 7529 | <h5 id="cockpit-format-number">cockpit.format_number()</h5> |
| 7530 | <div class="literalblock"> |
| 7531 | <div class="content"> |
| 7532 | <pre>string = cockpit.format_number(number, [precision])</pre> |
| 7533 | </div> |
| 7534 | </div> |
| 7535 | <div class="paragraph"> |
| 7536 | <p>Formats <code>number</code> into a displayable <code>string</code>. If the number is not |
| 7537 | an integer, it is rounded to the given number of decimal places, |
| 7538 | defaulting to 3. If the number is near zero, but not quite zero it is |
| 7539 | rounded to the smallest non-zero value of the given precision; i.e. |
| 7540 | ±0.001 for default precision 3.</p> |
| 7541 | </div> |
| 7542 | <div class="paragraph"> |
| 7543 | <p>If <code>number</code> is <code>null</code> or <code>undefined</code> an empty string will be |
| 7544 | returned.</p> |
| 7545 | </div> |
| 7546 | </div> |
| 7547 | <div class="sect4"> |
| 7548 | <h5 id="cockpit-format-bytes">cockpit.format_bytes()</h5> |
| 7549 | <div class="literalblock"> |
| 7550 | <div class="content"> |
| 7551 | <pre>string = cockpit.format_bytes(number, [options])</pre> |
| 7552 | </div> |
| 7553 | </div> |
| 7554 | <div class="paragraph"> |
| 7555 | <p>Formats <code>number</code> into a displayable <code>string</code> with a suffix, such as |
| 7556 | <em>kB</em> or <em>MB</em>.</p> |
| 7557 | </div> |
| 7558 | <div class="paragraph"> |
| 7559 | <p>By default, SI units are used. IEC units (1024-based) can be requested |
| 7560 | by including <code>base2: true</code> in <code>options</code>.</p> |
| 7561 | </div> |
| 7562 | <div class="paragraph"> |
| 7563 | <p>By default, non-integer numbers will be formatted with 3 digits of |
| 7564 | precision. This can be changed with <code>options.precision</code>.</p> |
| 7565 | </div> |
| 7566 | <div class="paragraph"> |
| 7567 | <p>If <code>number</code> is <code>null</code> or <code>undefined</code> an empty string will be |
| 7568 | returned.</p> |
| 7569 | </div> |
| 7570 | </div> |
| 7571 | <div class="sect4"> |
| 7572 | <h5 id="cockpit-format-bytes-per-sec">cockpit.format_bytes_per_sec()</h5> |
| 7573 | <div class="literalblock"> |
| 7574 | <div class="content"> |
| 7575 | <pre>string = cockpit.format_bytes_per_sec(number, [options])</pre> |
| 7576 | </div> |
| 7577 | </div> |
| 7578 | <div class="paragraph"> |
| 7579 | <p>Format <code>number</code> of bytes into a displayable speed <code>string</code>.</p> |
| 7580 | </div> |
| 7581 | <div class="paragraph"> |
| 7582 | <p>This function is mostly equivalent to <code>cockpit.format_bytes()</code> but the |
| 7583 | returned value contains a unit like <em>kB/s</em> or <em>MB/s</em>.</p> |
| 7584 | </div> |
| 7585 | </div> |
| 7586 | <div class="sect4"> |
| 7587 | <h5 id="cockpit-format-bits-per-sec">cockpit.format_bits_per_sec()</h5> |
| 7588 | <div class="literalblock"> |
| 7589 | <div class="content"> |
| 7590 | <pre>string = cockpit.format_bits_per_sec(number, [options])</pre> |
| 7591 | </div> |
| 7592 | </div> |
| 7593 | <div class="paragraph"> |
| 7594 | <p>Format <code>number</code> of bits into a displayable speed <code>string</code>.</p> |
| 7595 | </div> |
| 7596 | <div class="paragraph"> |
| 7597 | <p>This function is mostly equivalent to <code>cockpit.format_bytes()</code> but the |
| 7598 | returned value contains a unit like <em>kbps</em> or <em>Mbps</em>.</p> |
| 7599 | </div> |
| 7600 | <div class="paragraph"> |
| 7601 | <p>This function does not support IEC units. <code>base2</code> may not be passed as |
| 7602 | part of <code>options</code>.</p> |
| 7603 | </div> |
| 7604 | </div> |
| 7605 | <div class="sect4"> |
| 7606 | <h5 id="cockpit-init">cockpit.init()</h5> |
| 7607 | <div class="literalblock"> |
| 7608 | <div class="content"> |
| 7609 | <pre>await cockpit.init(); |
| 7610 | |
| 7611 | cockpit.init().then(() => { ... });</pre> |
| 7612 | </div> |
| 7613 | </div> |
| 7614 | <div class="paragraph"> |
| 7615 | <p>Requests initialization of the Cockpit client library. This will ensure |
| 7616 | that the transport is connected and we are ready to create channels. It |
| 7617 | also populates the <code>cockpit.info</code> field.</p> |
| 7618 | </div> |
| 7619 | <div class="paragraph"> |
| 7620 | <p>This function returns a promise. Initialization isn’t complete until the |
| 7621 | promise has resolved. You can either <code>await</code> it or call <code>.then()</code> on |
| 7622 | it.</p> |
| 7623 | </div> |
| 7624 | </div> |
| 7625 | <div class="sect4"> |
| 7626 | <h5 id="cockpit-info">cockpit.info</h5> |
| 7627 | <div class="literalblock"> |
| 7628 | <div class="content"> |
| 7629 | <pre>cockpit.info.channels[payload] |
| 7630 | |
| 7631 | cockpit.info.os_release[field] |
| 7632 | |
| 7633 | cockpit.info.user |
| 7634 | |
| 7635 | cockpit.info.ws.version</pre> |
| 7636 | </div> |
| 7637 | </div> |
| 7638 | <div class="paragraph"> |
| 7639 | <p>This object contains information about Cockpit itself. It is only |
| 7640 | available after cockpit.init() has been called and awaited.</p> |
| 7641 | </div> |
| 7642 | <div class="dlist"> |
| 7643 | <dl> |
| 7644 | <dt class="hdlist1"><code>channels</code></dt> |
| 7645 | <dd> |
| 7646 | <p>This is a mapping of channel payload types (keys, strings) supported |
| 7647 | by the bridge to capabilities advertised by those channels (values, |
| 7648 | lists of strings). Channels are listed even if they don’t advertise |
| 7649 | any capabilities, making this useful as a way to determine which |
| 7650 | channel types are supported by the bridge.</p> |
| 7651 | </dd> |
| 7652 | <dt class="hdlist1"><code>os_release</code></dt> |
| 7653 | <dd> |
| 7654 | <p>This is the data from the <code>/etc/os-release</code> or |
| 7655 | <code>/usr/lib/os-release</code> on the system that the bridge is running on. |
| 7656 | It is a mapping from the key names to their values. See the |
| 7657 | <a href="https://www.freedesktop.org/software/systemd/man/latest/os-release.html">os-release |
| 7658 | Specification</a> for information about the available keys.</p> |
| 7659 | </dd> |
| 7660 | <dt class="hdlist1"><code>user</code></dt> |
| 7661 | <dd> |
| 7662 | <p>Contains information about the user we’re logged in as.</p> |
| 7663 | <div class="dlist"> |
| 7664 | <dl> |
| 7665 | <dt class="hdlist1"><code>uid</code></dt> |
| 7666 | <dd> |
| 7667 | <p>This is unix user id as an integer.</p> |
| 7668 | </dd> |
| 7669 | <dt class="hdlist1"><code>gid</code></dt> |
| 7670 | <dd> |
| 7671 | <p>This is unix user group id as an integer.</p> |
| 7672 | </dd> |
| 7673 | <dt class="hdlist1"><code>name</code></dt> |
| 7674 | <dd> |
| 7675 | <p>This is the unix user name like <code>"root"</code>.</p> |
| 7676 | </dd> |
| 7677 | <dt class="hdlist1"><code>fullname</code></dt> |
| 7678 | <dd> |
| 7679 | <p>This is a readable name for the user, from the GECOS field.</p> |
| 7680 | </dd> |
| 7681 | <dt class="hdlist1"><code>group</code></dt> |
| 7682 | <dd> |
| 7683 | <p>This is the primary group name of the user.</p> |
| 7684 | </dd> |
| 7685 | <dt class="hdlist1"><code>groups</code></dt> |
| 7686 | <dd> |
| 7687 | <p>This is an array of group names to which the user belongs. The first |
| 7688 | item in this list is the primary group.</p> |
| 7689 | </dd> |
| 7690 | <dt class="hdlist1"><code>home</code></dt> |
| 7691 | <dd> |
| 7692 | <p>This is user’s home directory.</p> |
| 7693 | </dd> |
| 7694 | <dt class="hdlist1"><code>shell</code></dt> |
| 7695 | <dd> |
| 7696 | <p>This is unix user shell.</p> |
| 7697 | </dd> |
| 7698 | </dl> |
| 7699 | </div> |
| 7700 | </dd> |
| 7701 | <dt class="hdlist1"><code>ws</code></dt> |
| 7702 | <dd> |
| 7703 | <p>Contains information about the webserver Cockpit is being served with.</p> |
| 7704 | <div class="dlist"> |
| 7705 | <dl> |
| 7706 | <dt class="hdlist1"><code>version</code></dt> |
| 7707 | <dd> |
| 7708 | <p>The version of the webserver.</p> |
| 7709 | </dd> |
| 7710 | </dl> |
| 7711 | </div> |
| 7712 | </dd> |
| 7713 | </dl> |
| 7714 | </div> |
| 7715 | </div> |
| 7716 | <div class="sect4"> |
| 7717 | <h5 id="cockpit-event-target">cockpit.event_target</h5> |
| 7718 | <div class="literalblock"> |
| 7719 | <div class="content"> |
| 7720 | <pre>cockpit.event_target(object, [handlers])</pre> |
| 7721 | </div> |
| 7722 | </div> |
| 7723 | <div class="paragraph"> |
| 7724 | <p>Adds an |
| 7725 | <a href="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget">EventTarget</a> |
| 7726 | implementation to the <code>object</code>. Optionally store the handlers in |
| 7727 | <code>handlers</code> if its specified.</p> |
| 7728 | </div> |
| 7729 | </div> |
| 7730 | </div> |
| 7731 | </div> |
| 7732 | <div class="sect2"> |
| 7733 | <h3 id="_api_shell">API: shell</h3> |
| 7734 | <div class="paragraph"> |
| 7735 | <p>This package contains the shell that loads other components.</p> |
| 7736 | </div> |
| 7737 | <div class="sect3"> |
| 7738 | <h4 id="_index_html">index.html</h4> |
| 7739 | <div class="literalblock"> |
| 7740 | <div class="content"> |
| 7741 | <pre><iframe src="http://127.0.0.1:9090/cockpit+app/@localhost/shell/index.html" |
| 7742 | width="600" height="400"></iframe></pre> |
| 7743 | </div> |
| 7744 | </div> |
| 7745 | <div class="paragraph"> |
| 7746 | <p>This is a Cockpit component that provides an interface to configure a |
| 7747 | single machine. It loads other components on demand to make that happen.</p> |
| 7748 | </div> |
| 7749 | <div class="dlist"> |
| 7750 | <dl> |
| 7751 | <dt class="hdlist1">Component URL</dt> |
| 7752 | <dd> |
| 7753 | <p><code>/cockpit+app/@localhost/shell/index.html</code></p> |
| 7754 | </dd> |
| 7755 | </dl> |
| 7756 | </div> |
| 7757 | </div> |
| 7758 | </div> |
| 7759 | <div class="sect2"> |
| 7760 | <h3 id="_api_system">API: system</h3> |
| 7761 | <div class="paragraph"> |
| 7762 | <p>This package contains general components for basic control of a system.</p> |
| 7763 | </div> |
| 7764 | <div class="sect3"> |
| 7765 | <h4 id="_logs_html">logs.html</h4> |
| 7766 | <div class="paragraph"> |
| 7767 | <p>System log component</p> |
| 7768 | </div> |
| 7769 | <div class="sect4"> |
| 7770 | <h5 id="api-logs-html-description">Description</h5> |
| 7771 | <div class="literalblock"> |
| 7772 | <div class="content"> |
| 7773 | <pre><iframe src="http://127.0.0.1:9090/cockpit+app/@localhost/system/logs.html" |
| 7774 | width="600" height="400"></iframe></pre> |
| 7775 | </div> |
| 7776 | </div> |
| 7777 | <div class="paragraph"> |
| 7778 | <p>This is a Cockpit component that brings up system log viewer, with |
| 7779 | filtering capabilities. On systemd based systems this displays the |
| 7780 | entries from journal.</p> |
| 7781 | </div> |
| 7782 | <div class="dlist"> |
| 7783 | <dl> |
| 7784 | <dt class="hdlist1">Component URL</dt> |
| 7785 | <dd> |
| 7786 | <p><code>/cockpit+app/@localhost/system/logs.html</code></p> |
| 7787 | </dd> |
| 7788 | <dt class="hdlist1">Filter by priority</dt> |
| 7789 | <dd> |
| 7790 | <p><code>#?prio=notice</code><br> |
| 7791 | <br> |
| 7792 | Filters the log to show entries below the specific priority, |
| 7793 | inclusive. These |
| 7794 | <a href="https://en.wikipedia.org/wiki/Syslog#Severity_levels">priorities are |
| 7795 | syslog level keywords</a>. Specifying <code>*</code> as a priority will show all |
| 7796 | available entries. The default priority is <code>err</code>.</p> |
| 7797 | </dd> |
| 7798 | <dt class="hdlist1">Filter by service</dt> |
| 7799 | <dd> |
| 7800 | <p><code>#?service=sshd.service</code><br> |
| 7801 | <br> |
| 7802 | Filters the log to show entries related to the specific service. The |
| 7803 | format of the service is specific to the logging implementation. For |
| 7804 | journald these are systemd service unit names.</p> |
| 7805 | </dd> |
| 7806 | <dt class="hdlist1">Filter by tag</dt> |
| 7807 | <dd> |
| 7808 | <p><code>#?tag=kernel</code><br> |
| 7809 | <br> |
| 7810 | Filters the log to show entries related to the specific syslog |
| 7811 | identifier.</p> |
| 7812 | </dd> |
| 7813 | <dt class="hdlist1">Filter by message</dt> |
| 7814 | <dd> |
| 7815 | <p><code>#?grep=</code><br> |
| 7816 | <br> |
| 7817 | Filters the log to show entries where the <code>MESSAGE=</code> field matches |
| 7818 | the specified regular expression. PERL-compatible regular expressions |
| 7819 | are used. If the pattern is all lowercase, matching is case |
| 7820 | insensitive. Otherwise, matching is case sensitive.</p> |
| 7821 | </dd> |
| 7822 | <dt class="hdlist1">Filter by any field</dt> |
| 7823 | <dd> |
| 7824 | <p><code>#?FIELD=VALUE</code><br> |
| 7825 | <br> |
| 7826 | A field is referring to the components of a structured journal entry. |
| 7827 | The match must be exact. Value can be comma separated list in which |
| 7828 | case they are automatically matched as alternatives.</p> |
| 7829 | </dd> |
| 7830 | <dt class="hdlist1">Start at point</dt> |
| 7831 | <dd> |
| 7832 | <p><code>#?start=boot</code><br> |
| 7833 | <br> |
| 7834 | Filters the log to show entries after the specific point in time. |
| 7835 | Valid values are <code>boot</code> (since last boot), <code>last-24h</code> (last 24 |
| 7836 | hours), <code>last-week</code> (last seven days) and <code>previous-boot</code> |
| 7837 | (previous boot).</p> |
| 7838 | </dd> |
| 7839 | <dt class="hdlist1">Follow the journal</dt> |
| 7840 | <dd> |
| 7841 | <p><code>#?follow=true</code><br> |
| 7842 | <br> |
| 7843 | Keep listening on new entries. Valid values are <code>true</code> (follow) and |
| 7844 | <code>false</code> (do not follow).</p> |
| 7845 | </dd> |
| 7846 | <dt class="hdlist1">Show log entry</dt> |
| 7847 | <dd> |
| 7848 | <p><code>#/6e272d82993c4e0d...</code><br> |
| 7849 | <br> |
| 7850 | To show a specific log entry, put the log entry cursor in a path after |
| 7851 | the hash above. Note that cursors are logging system specific, and |
| 7852 | journal cursors are subject to change.</p> |
| 7853 | </dd> |
| 7854 | </dl> |
| 7855 | </div> |
| 7856 | </div> |
| 7857 | </div> |
| 7858 | <div class="sect3"> |
| 7859 | <h4 id="_terminal_html">terminal.html</h4> |
| 7860 | <div class="paragraph"> |
| 7861 | <p>Server terminal component</p> |
| 7862 | </div> |
| 7863 | <div class="sect4"> |
| 7864 | <h5 id="api-terminal-html-description">Description</h5> |
| 7865 | <div class="literalblock"> |
| 7866 | <div class="content"> |
| 7867 | <pre><iframe src="http://127.0.0.1:9090/cockpit+app/@localhost/system/terminal.html" |
| 7868 | width="600" height="400"></iframe></pre> |
| 7869 | </div> |
| 7870 | </div> |
| 7871 | <div class="paragraph"> |
| 7872 | <p>This is a Cockpit component that brings up a web-based terminal for the |
| 7873 | logged in user.</p> |
| 7874 | </div> |
| 7875 | <div class="dlist"> |
| 7876 | <dl> |
| 7877 | <dt class="hdlist1">Component URL</dt> |
| 7878 | <dd> |
| 7879 | <p><code>/cockpit+app/@localhost/system/terminal.html</code></p> |
| 7880 | </dd> |
| 7881 | </dl> |
| 7882 | </div> |
| 7883 | </div> |
| 7884 | </div> |
| 7885 | </div> |
| 7886 | </div> |
| 7887 | </div> |
| 7888 | </div> |
| 7889 | <div id="footer"> |
| 7890 | <div id="footer-text"> |
| 7891 | Last updated 2026-08-27 09:37:18 UTC |
| 7892 | </div> |
| 7893 | </div> |
| 7894 | </body> |
| 7895 | </html> |