1
0
forked from cockpit/cockpit
cockpit/fix-docker-path.patch

35 lines
155 KiB
Diff

diff -wruN -x '*~' -x '*.o' -x '*.a' -x '*.so' -x '*.so.[0-9]' -x autom4te.cache -x .deps -x .libs ../orig-cockpit-0.38/pkg/shell/cockpit-docker.js ./pkg/shell/cockpit-docker.js
--- ../orig-cockpit-0.38/pkg/shell/cockpit-docker.js 2015-01-28 13:35:16.000000000 +0100
+++ ./pkg/shell/cockpit-docker.js 2015-02-07 17:41:48.753807824 +0100
@@ -1810,7 +1810,7 @@
if (watch && watch.valid)
watch.close();
- watch = cockpit.channel({ payload: "fsdir1", path: "/var/lib/docker" });
+ watch = cockpit.channel({ payload: "fsdir1", path: "/usr/bin/docker" });
$(watch).on("message", function(event, data) {
trigger_event();
});
diff -wruN -x '*~' -x '*.o' -x '*.a' -x '*.so' -x '*.so.[0-9]' -x autom4te.cache -x .deps -x .libs ../orig-cockpit-0.38/shell.js ./shell.js
--- ../orig-cockpit-0.38/shell.js 2015-01-28 13:35:22.000000000 +0100
+++ ./shell.js 2015-02-07 17:42:24.427286289 +0100
@@ -16383,7 +16383,7 @@
if (watch && watch.valid)
watch.close();
- watch = cockpit.channel({ payload: "fsdir1", path: "/var/lib/docker" });
+ watch = cockpit.channel({ payload: "fsdir1", path: "/usr/bin/docker" });
$(watch).on("message", function(event, data) {
trigger_event();
});
diff -wruN -x '*~' -x '*.o' -x '*.a' -x '*.so' -x '*.so.[0-9]' -x autom4te.cache -x .deps -x .libs ../orig-cockpit-0.38/shell.min.js ./shell.min.js
--- ../orig-cockpit-0.38/shell.min.js 2015-01-28 13:35:22.000000000 +0100
+++ ./shell.min.js 2015-02-07 18:29:46.885202429 +0100
@@ -5,4 +5,4 @@
var u=this._other_devices[0].childNodes;var f=null;var p,h;for(var g=0;g<u.length;g++){p=u[g];h=p.getAttribute("sort");if(parseInt(h,10)>c){f=p;break}}this._other_devices[0].insertBefore(l[0],f);this._other_devices.closest(".panel").show();d(e("#storage-spinner-"+r));y(e("#storage-spinner-"+r),i)},_addMount:function(i){var a=i.lookup("com.redhat.Cockpit.Storage.Block");if(a.IdUsage!="filesystem"||a.HintIgnore)return;var o=s(i.objectPath.substr(i.objectPath.lastIndexOf("/")+1));var r=o;var c=null;var l=e('<td style="text-align:right">');if(a.MountedAt&&a.MountedAt.length>0){c=n.BarRow();for(var d=0;d<a.MountedAt.length;d++){this.mount_bar_rows[a.MountedAt[d]]=c;this.mount_texts[a.MountedAt[d]]=l}}else l.text(t.format_bytes(a.Size,1024));var u=e("<tr>",{Sort:r}).click(function(){I(a)}).append(e("<td>").text(a.IdLabel||a.Device),e("<td>").text(a.MountedAt||"-"),e("<td>").append(c),l);var f=this._mounts[0].childNodes;var p=null;var h,g;for(var _=0;_<f.length;_++){h=f[_];g=h.getAttribute("sort");if(g>r){p=h;break}}this._mounts[0].insertBefore(u[0],p)}};function M(){this._init()}n.pages.push(new M);function R(e){var i;if(e.Type=="pool")i=_("Pool for Thin Logical Volumes");else if(e.ThinPool!="/")i=_("Thin Logical Volume");else if(e.Origin!="/")i=_("Logical Volume (Snapshot)");else i=_("Logical Volume");return t.format('$type "$name"',{type:i,name:n.esc(e.Name)})}function P(i,o,r){var s,c;if(i.IdUsage=="filesystem"){s=e("<span>").text(t.format(C_("storage-id-desc","$0 File System"),i.IdType))}else if(i.IdUsage=="raid"){if(i.IdType=="linux_raid_member"){s=e("<span>").text(C_("storage-id-desc","Linux MD-RAID Component"))}else if(i.IdType=="LVM2_member"){s=e("<span>").text(C_("storage-id-desc","LVM2 Physical Volume"))}else{s=e("<span>").text(C_("storage-id-desc","RAID Member"))}if(i.PvGroup!="/"){var l=i._client.get(i.PvGroup,"com.redhat.Cockpit.Storage.VolumeGroup");s.append(" of ",e("<a>").text(l.Name).click(function(){t.location.go("storage-detail",{type:"vg",id:l.Name})}))}else if(i.MDRaidMember!="/"){var d=i.MDRaidMember.substr(i.MDRaidMember.lastIndexOf("/")+1);var u=i._client.get(i.MDRaidMember,"com.redhat.Cockpit.Storage.MDRaid");s.append(" of ",e("<a>").text(z(u)).click(function(){t.location.go("storage-detail",{type:"mdraid",id:d})}))}}else if(i.IdUsage=="crypto"){if(i.IdType=="crypto_LUKS"){s=e("<span>").text(C_("storage-id-desc","LUKS Encrypted"))}else{s=e("<span>").text(C_("storage-id-desc","Encrypted"))}}else if(i.IdUsage=="other"){if(i.IdType=="swap"){s=e("<span>").text(C_("storage-id-desc","Swap Space"))}else{s=e("<span>").text(C_("storage-id-desc","Other Data"))}}else{s=e("<span>").text(C_("storage-id-desc","Unrecognized Data"))}if(i.PartitionNumber>0){s=e("<span>").append(t.format(_("$size $partition"),{size:a(i.Size),partition:o})," (",s,")")}if(i.LogicalVolume!="/"){c=i._client.lookup(i.LogicalVolume,"com.redhat.Cockpit.Storage.LogicalVolume");s=e("<span>").append(t.format(_("$size $partition"),{size:a(i.Size),partition:R(c)})," (",s,")")}s.append(e("<br/>"),n.esc(i.Device));if(i.IdUsage=="filesystem"){s.append(", ");if(i.MountedAt.length>0)s.append(t.format(_("mounted on $0"),n.esc(i.MountedAt[0])));else s.append(_("not mounted"))}else if(i.IdUsage=="crypto"){s.append(", ");if(r)s.append(_("unlocked"));else s.append(_("locked"))}return s}function A(e){if(e.PartitionNumber>0)return"Partition";else if(e.LogicalVolume!="/"){var t=e._client.lookup(e.LogicalVolume,"com.redhat.Cockpit.Storage.LogicalVolume");return R(t)}else if(e.Drive!="/"){var i=e._client.lookup(e.Drive,"com.redhat.Cockpit.Storage.Drive");return i?n.esc(i.Name):e.Device}else return"Block Device"}function I(e){var n,i,a,o;while(true){if(e.PartitionTable&&e.PartitionTable!="/")e=e._client.get(e.PartitionTable,"com.redhat.Cockpit.Storage.Block");else if(e.CryptoBackingDevice&&e.CryptoBackingDevice!="/")e=e._client.get(e.CryptoBackingDevice,"com.redhat.Cockpit.Storage.Block");else break}if(e.Drive!="/"){n=e.Drive.substr(e.Drive.lastIndexOf("/")+1);t.location.go("storage-detail",{type:"drive",id:n})}else if(e.MDRaid!="/"){n=e.MDRaid.substr(e.MDRaid.lastIndexOf("/")+1);t.location.go("storage-detail",{type:"mdraid",id:n})}else if(e.LogicalVolume!="/"){i=e._client.get(e.LogicalVolume,"com.redhat.Cockpit.Storage.LogicalVolume");if(i.VolumeGroup!="/"){a=i._client.get(i.VolumeGroup,"com.redhat.Cockpit.Storage.VolumeGroup");t.location.go("storage-detail",{type:"vg",id:a.Name})}}else{o=e.getObject().objectPath;n=o.substr(o.lastIndexOf("/")+1);t.location.go("storage-detail",{type:"block",id:n})}}function T(n){var i=false;var a=false;var o=null;while(true){if(n.PartitionTable&&n.PartitionTable!="/"){n=n._client.get(n.PartitionTable,"com.redhat.Cockpit.Storage.Block");i=true}else if(n.CryptoBackingDevice&&n.CryptoBackingDevice!="/"){n=n._client.get(n.CryptoBackingDevice,"com.redhat.Cockpit.Storage.Block");a=true}else break}if(n.Drive!="/"){var r=n._client.get(n.Drive,"com.redhat.Cockpit.Storage.Drive");o=e("<a>").text(r.Name||n.Device).click(function(){var e=n.Drive.substr(n.Drive.lastIndexOf("/")+1);t.location.go("storage-detail",{type:"drive",id:e})})}else if(n.MDRaid!="/"){var s=n._client.get(n.MDRaid,"com.redhat.Cockpit.Storage.MDRaid");o=e("<span>").append(_("RAID Device")," ",e("<a>").text(z(s)).click(function(){var e=n.MDRaid.substr(n.MDRaid.lastIndexOf("/")+1);t.location.go("storage-detail",{type:"mdraid",id:e})}))}else if(n.LogicalVolume!="/"){var c=n._client.get(n.LogicalVolume,"com.redhat.Cockpit.Storage.LogicalVolume");if(c.VolumeGroup!="/"){var l=c._client.get(c.VolumeGroup,"com.redhat.Cockpit.Storage.VolumeGroup");o=e("<span>").append(R(c)," of ",e("<a>").text(l.Name).click(function(){t.location.go("storage-detail",{type:"vg",id:l.Name})}))}else{o=e("<span>").text(R(c))}}else{o=e("<a>").text(n.Device).click(function(){var e=n.getObject().objectPath;var i=e.substr(e.lastIndexOf("/")+1);t.location.go("storage-detail",{type:"block",id:i})})}var d=o;if(i)d=e("<span>").append(_("Partition of "),d);if(a)d=e("<span>").append(d,_(", encrypted"));return d}function O(e){var t=e.getObject().objectPath;var n=e._client.getObjectsFrom("/com/redhat/Cockpit/Storage/block_devices/");for(var i=0;i<n.length;i++){var a=n[i];var o=a.lookup("com.redhat.Cockpit.Storage.Block");if(o&&o.CryptoBackingDevice==t)return o}return null}function z(e){if(!e.Name)return"";var n=e.Name.split(":");if(n.length!=2)return e.Name;var i=e._client.lookup("/com/redhat/Cockpit/Manager","com.redhat.Cockpit.Manager");if(i&&n[0]==i.StaticHostname)return n[1];else return t.format(_("$name (on $host)"),{name:n[1],host:n[0]})}function L(e,t){function n(t){var n=t.getObject().objectPath;var i,a;var o;if(t.PartitionTable)i=e.lookup(t.PartitionTable,"com.redhat.Cockpit.Storage.Block");if(i)a=i.Partitions;if(a){for(o=0;o<a.length;o++){if(a[o][0]==n)return a[o][3]=="x"}}return false}function i(e){return e.IdUsage!==""&&(e.IdType!="LVM2_member"||e.PvGroup!="/")}var a=[];var o=e.getObjectsFrom("/com/redhat/Cockpit/Storage/block_devices/");for(var r=0;r<o.length;r++){var s=o[r];var c=s.lookup("com.redhat.Cockpit.Storage.Block");if(c&&!c.HintIgnore&&c.Size>0&&!i(c)&&!c.PartitionTableType&&!n(c)&&!(t&&t(c)))a.push(c)}return a}U.prototype={_init:function(){this.id="storage-detail";this.section_id="storage";this.watched_objects=[]},getTitle:function(){return C_("page-title","Storage")},get_page_title:function(){var e;if(this._drive){if(this._drive.Vendor&&this._drive.Vendor.length>0)e=this._drive.Vendor+" "+this._drive.Model;else e=this._drive.Model}else if(this._mdraid){e=z(this._mdraid)}else if(this._vg){e=this._vg.Name}else e=this._block.Device;return e||"?"},show:function(){},watch_object:function(t){if(t){this.watched_objects.push(t);e(t).on("notify.storage-details",e.proxy(this,"_update"))}},unwatch_all_objects:function(){for(var t=0;t<this.watched_objects.length;t++)e(this.watched_objects[t]).off(".storage-details");this.watched_objects=[]},leave:function(){this.unwatch_all_objects();this.job_box.stop();if(this.log_box)this.log_box.stop();this.log_box=null;this.stop_vg_polling();p(this.client);e(this.client).off(".storage-details");this.client.release();this.client=null},setup:function(){var t=this;t.raid_action_btn=n.action_btn(function(e){t.action(e)},[{title:_("Start"),action:"start"},{title:_("Stop"),action:"stop"},{title:_("Format"),action:"format"},{title:_("Start Scrubbing"),action:"start-scrub"},{title:_("Stop Scrubbing"),action:"stop-scrub"},{title:_("Delete"),action:"delete"}]);e("#raid_action_btn").html(t.raid_action_btn);e("#raid-disks-add").on("click",e.proxy(this,"raid_disk_add"));function i(e){t._mdraid.call("SetBitmapLocation",e?"internal":"none",function(e,i){if(e){t._update();n.show_unexpected_error(e)}})}this.bitmap_onoff=n.OnOff(false,i,undefined,function(){return n.check_admin()});e("#raid_detail_bitmap").append(this.bitmap_onoff);e("#drive_format").on("click",function(){t.action("format")});var a=n.action_btn(function(e){t.volume_group_action(e)},[{title:_("Rename"),action:"rename",is_default:true},{title:_("Delete"),action:"delete"}]);e("#vg_action_btn").html(a);e("#vg-pv-add").on("click",e.proxy(this,"add_physical_volume"));e("#block_format").on("click",function(){t.action("format")})},enter:function(){var t=this;var i=n.get_page_param("type");var a=n.get_page_param("id");this.address=n.get_page_machine();this.client=n.dbus(this.address);f(this.client);this._drive=null;this._mdraid=null;this._vg=null;this._block=null;e("#disk_detail_list").hide();e("#raid_detail_list").hide();e("#vg_detail_list").hide();e("#block_detail_list").hide();if(i=="drive"){this._drive=this.client.get("/com/redhat/Cockpit/Storage/drives/"+a,"com.redhat.Cockpit.Storage.Drive");e("#disk_detail_list").show()}else if(i=="mdraid"){this._mdraid=this.client.get("/com/redhat/Cockpit/Storage/raids/"+a,"com.redhat.Cockpit.Storage.MDRaid");e("#raid_detail_list").show()}else if(i=="vg"){this._vg=this.client.get("/com/redhat/Cockpit/Storage/lvm/"+a,"com.redhat.Cockpit.Storage.VolumeGroup");e("#vg_detail_list").show()}else{this._block=this.client.get("/com/redhat/Cockpit/Storage/block_devices/"+a,"com.redhat.Cockpit.Storage.Block");e("#block_detail_list").show()}this.job_box=w(this.client,e("#storage-detail-jobs"));this.log_box=x(e("#storage-detail-log"));this._update();e("#storage-detail-title").text(this.get_page_title());e(this.client).on("objectAdded.storage-details",e.proxy(this._update,this));e(this.client).on("objectRemoved.storage-details",e.proxy(this._update,this));e(this.client).on("propertiesChanged.storage-details",e.proxy(this._onPropertiesChanged,this))},_onPropertiesChanged:function(e,t,n){if(t.objectPath.indexOf("/com/redhat/Cockpit/Storage/")!==0)return;this._update()},_update:function(){this.unwatch_all_objects();if(this._drive)this._updateDrive();else if(this._mdraid)this._updateMDRaid();else if(this._vg)this._updateVG();else if(this._block)this._updateBlock();e("#storage-detail .breadcrumb .active").text(this.get_page_title())},_updateBlock:function(){var t;var i=this._block;this.watch_object(i);this._updateContent(i);t=n.esc(i.Device);e("#block_detail_device").html(t);t=i.Size>0?o(i.Size):C_("storage","No Media Inserted");e("#block_detail_capacity").html(t)},_updateContent:function(i){var o=this;var r=0;function s(e){return function(t){o.block_action(e,t)}}function c(e,t,i){var a;var r=[{title:_("Mount"),action:"mount"},{title:_("Unmount"),action:"unmount"},{title:_("Filesystem Options"),action:"fsys-options"}];var s=[{title:_("Lock"),action:"lock"},{title:_("Unlock"),action:"unlock"},{title:_("Encryption Options"),action:"crypto-options"}];var c=[{title:_("Resize"),action:"resize"},{title:_("Rename"),action:"rename"}];var l=[{title:_("Create Snapshot"),action:"create-snapshot"},{title:_("Activate"),action:"activate"},{title:_("Deactivate"),action:"deactivate"}];var d=[{title:_("Create Thin Volume"),action:"create-thin-volume"}];var u=[{title:_("Format"),action:"format"}];var f=[{title:_("Delete"),action:"delete"}];var p=e.IdUsage=="filesystem";var h=e.MountedAt&&e.MountedAt.length!==0;var g=e.IdUsage=="crypto";var m=e._iface_name=="com.redhat.Cockpit.Storage.LogicalVolume"||e.LogicalVolume!="/";var v=e.Type=="pool";var b=e._iface_name=="com.redhat.Cockpit.Storage.Block"||e.Active;var k=e._iface_name=="com.redhat.Cockpit.Storage.Block"&&!e.ReadOnly;var y=null;var w=[];if(p){w=w.concat(r);y=h?"unmount":"mount"}else if(g){w=w.concat(s);y=t?"unlock":"lock"}if(k){w=w.concat(u);if(!y)y="format"}if(m){w=w.concat(c);if(v){w=w.concat(d);y="create-thin-volume"}else{w=w.concat(l);if(!y)y=b?"deactivate":"activate"}}if(i||m){w=w.concat(f);if(!y)y="delete"}if(w.length>0){a=n.action_btn(function(t){o.block_action(e,t)},w);n.action_btn_select(a,y);n.action_btn_enable(a,"mount",!h);n.action_btn_enable(a,"unmount",h);n.action_btn_enable(a,"lock",!t);n.action_btn_enable(a,"unlock",t);n.action_btn_enable(a,"activate",!b);n.action_btn_enable(a,"deactivate",b)}return a}function l(t,n){return e("<button>",{"class":"btn btn-default",on:{click:n}}).text(t)}function f(t,n,i,a){r+=1;if(a===true)a=null;var o=e("<tr>");if(t>0)o.append(e("<td>",{Width:30*t}));o.append(e("<td>",{style:"width:50%"}).html(i));if(n)o.append(e("<td>",{style:"text-align:left"}).html(n));if(a)o.append(e("<td>",{style:"float:right"}).append(a));o.append(e("<td>",{style:"float:right"}).append(e("<div>",{id:"entry-spinner-"+r,"class":"waiting"})));v.append(e("<li>",{"class":"list-group-item"}).append(e("<table>",{style:"width:100%"}).append(o)));d("#entry-spinner-"+r);return r}function p(e,t,i){var a,r,s,l;var d;if(t.IdUsage=="crypto")d=O(t);l=c(t,!d,!!i);if(t.IdLabel.length>0)r=n.esc(t.IdLabel);else if(!l)r=null;else r="—";s=P(t,i,d);a=f(e,r,s,l);u("#entry-spinner-"+a,t.getObject().objectPath);o.watch_object(t);if(d)g(e+1,d)}function h(n,i){var r=n;var s=i.PartitionTableType=="dos";var d=i.Partitions.sort(function(e,t){return e[1]-t[1]});function u(n,c,d){var u;var p=(Math.floor(c/(1024*1024))+1)*1024*1024;var h=false;if(c+d-p>=1024*1024){if(s){if(n>r){u=t.format(_("$0 Free Space for Logical Partitions"),a(d))}else{u=t.format(_("$0 Free Space for Primary Partitions"),a(d));h=true}}else{u=t.format(_("$0 Free Space"),a(d))}f(n,null,u,l(_("Create Partition"),e.proxy(o,"create_partition",i,c,d,h)))}}function h(e,n,i,r){var s=t.format(_("$0 Extended Partition"),a(r));var l=c(n,false,true);f(e,null,s,l);o.watch_object(n);g(e+1,i,r)}function g(e,t,n){var i;var a=t;var c=t+n;var l,f,g,m,v;for(i=0;i<d.length;i++){l=o.client.lookup(d[i][0],"com.redhat.Cockpit.Storage.Block");f=d[i][1];g=d[i][2];m=d[i][3];if(l===null)continue;if(e===r&&m=="l")continue;if(e==r+1&&m!="l")continue;if(f<t||f+g>t+n)continue;u(e,a,f-a);if(m=="x")h(e,l,f,g);else{if(s){if(e>r)v=_("Logical Partition");else v=_("Primary Partition")}else v=_("Partition");p(e,l,v)}a=f+g}u(e,a,c-a)}g(r,0,i.Size)}function g(e,t,n){var i=!!t.PartitionTableType;if(t.PartitionTableType)h(e,t);else p(e,t,null)}function m(e,i){var r,s,l,d,u,g,m,v;function b(e,i,o){var r,s,l;if(i.PartitionTableType){l=t.format(_("$size $desc"),{desc:R(o),size:a(i.Size)});l+="<br/>"+n.esc(i.Device);r=c(i,false,false);s=f(e,null,l,r);h(e+1,i)}else p(e,i,null)}function y(e,n){var i,r,s,l,d;var u,p,h,g;if(n.Type=="pool"){d=Math.max(n.DataAllocatedRatio,n.MetadataAllocatedRatio);r=t.format(_("$size $desc<br/>${percent}% full"),{size:a(n.Size),desc:R(n),percent:(d*100).toFixed(0)});s=c(n,false,false);l=f(e,null,r,s);u=n.getObject();p=o.client.getObjectsFrom(n.VolumeGroup);p.sort(function(e,t){return e.objectPath.localeCompare(t.objectPath)});for(h=0;h<p.length;h++){g=p[h].lookup("com.redhat.Cockpit.Storage.LogicalVolume");if(g&&g.ThinPool==u.objectPath){y(e+1,g)}}}else{i=k(n);if(i)b(e,i,n);else{r=t.format(_("$size $desc<br/>($state)"),{size:a(n.Size),desc:R(n),state:n.Active?_("active, but unsupported"):_("inactive")});s=c(n,false,false);l=f(e,null,r,s)}}}l=[];m=i.getObject();d=o.client.getObjectsFrom(m.objectPath);d.sort(function(e,t){return e.objectPath.localeCompare(t.objectPath)});for(r=0;r<d.length;r++){g=d[r].lookup("com.redhat.Cockpit.Storage.LogicalVolume");if(g&&g.VolumeGroup==m.objectPath&&g.ThinPool=="/"){y(e,g)}}if(i.FreeSize>0){v=t.format(_("$0 Free Space for Logical Volumes"),a(i.FreeSize));var w=n.action_btn(function(e){o.volume_group_action(e)},[{title:_("Create Plain Logical Volume"),action:"create-plain",is_default:true},{title:_("Create RAID Logical Volume"),action:"create-raid"},{title:_("Create Pool for Thin Logical Volumes"),action:"create-thin-pool"}]);s=f(e,null,v,w)}}if(!i){e("#storage_detail_content").hide();return}e("#storage_detail_content").show();var v=e("#storage_detail_partition_list");v.empty();if(i._iface_name=="com.redhat.Cockpit.Storage.Block"){e("#storage_detail_content_title").text(_("Content"));g(0,i)}else if(i._iface_name=="com.redhat.Cockpit.Storage.VolumeGroup"){e("#storage_detail_content_title").text(_("Logical Volumes"));m(0,i)}},_updateDrive:function(){var t;var i=this._drive;var a=g(i);var s=a.length>0?a[0]:undefined;this.watch_object(i);this.watch_object(s);this._updateContent(s);if(i.Vendor&&i.Vendor.length>0)t=n.esc(i.Vendor)+" "+n.esc(i.Model);else t=n.esc(i.Model);e("#disk_detail_model").html(t);t=i.Revision?n.esc(i.Revision):"—";e("#disk_detail_firmware_version").html(t);t=i.Serial?n.esc(i.Serial):"—";e("#disk_detail_serial_number").html(t);t=i.WWN?n.esc(i.WWN):"—";e("#disk_detail_world_wide_name").html(t);t=i.Size>0?o(i.Size):C_("disk-drive","No Media Inserted");e("#disk_detail_capacity").html(t);if(i.FailingValid){if(i.Failing){t='<div class="cockpit-disk-failing">'+C_("disk-drive","DISK IS FAILING")+"</div>"}else{t=C_("disk-drive","Disk is OK")}}else{t="—"}if(i.Temperature>0){t+=" ("+r(i.Temperature)+")"}e("#disk_detail_assessment").html(t);t="";for(var c=0;c<a.length;c++){var l=a[c];if(c>0){t+=" "}t+=n.esc(l.Device)}e("#disk_detail_device_file").html(t);if(i.Classification==="optical")e("#drive_format").hide();else e("#drive_format").show()},_updateMDRaid:function(){function i(e){return{raid0:_("RAID 0"),raid1:_("RAID 1"),raid4:_("RAID 4"),raid5:_("RAID 5"),raid6:_("RAID 6"),raid10:_("RAID 10")}[e]||t.format(_("RAID ($level)"),e)}var r=this._mdraid;var s=b(r);this.watch_object(r);this.watch_object(s);this._updateContent(s);if(s)e("#raid_detail_device").html(n.esc(s.Device));else e("#raid_detail_device").html("--");var c=r.Size>0?o(r.Size):"--";e("#raid_detail_capacity").html(c);e("#raid_detail_name").text(z(r));e("#raid_detail_uuid").html(n.esc(r.UUID));var l=i(r.Level);if(r.NumDevices>0)l+=", "+t.format(_("$0 Disks"),r.NumDevices);if(r.ChunkSize>0)l+=", "+t.format(_("%0 Chunk Size"),a(r.ChunkSize));e("#raid_detail_level").html(n.esc(l));var d,u="",f;var p,h,g,m;var v=null;var k=r.BitmapLocation;if(k){this.bitmap_onoff.set(k!="none");e("#raid_detail_bitmap_row").show()}else{e("#raid_detail_bitmap_row").hide()}f=!!s;if(r.Degraded>0){v='<span style="color:red">'+_("ARRAY IS DEGRADED")+"</span> -- "+t.format(_("%0 disks are missing"),r.Degraded)}if(!r.SyncAction){if(s){d=_("Running")}else{d=_("Not running")}}else{if(v)d=v;else d=_("Running");p={idle:"",check:_("Data Scrubbing"),repair:_("Data Scrubbing and Repair"),resync:_("Resyncing"),recover:_("Recovering "),frozen:_("Frozen")}[r.SyncAction]||r.SyncAction;if(p&&p!="idle"){h=Math.round(r.SyncCompleted*100).toString();if(r.SyncRate>0){u=t.format(_("$action, ${percent}% complete at $rate"),{action:p,percent:h,rate:a(r.SyncRate)+"/s"})}else{u=t.format(_("$action, ${percent}% complete"),{action:p,percent:h})}d=d+"<br/>"+u;if(r.SyncRemainingTime>0){m=t.format(_("$0 remaining"),n.format_delay(r.SyncRemainingTime/1e3));d=d+"<br/>"+m}}}e("#raid_detail_state").html(d);n.action_btn_select(this.raid_action_btn,f?"stop":"start");n.action_btn_enable(this.raid_action_btn,"stop",f);n.action_btn_enable(this.raid_action_btn,"start",!f);e("#raid-disks").closest(".panel").toggle(f);function y(e,n){if(n=="faulty")return'<span style="color:red">'+_("FAILED")+"</span>";else if(n=="in_sync")return _("In Sync");else if(n=="spare")return e<0?_("Spare"):_("Recovering");else if(n=="write_mostly")return _("Write-mostly");else if(n=="blocked")return _("Blocked");else return t.format(_("Unknown ($0)"),n)}e("#raid-disks-add").css("visibility",r.Level==="raid0"?"hidden":"visible");var w=e("#raid-disks");var x=this._mdraid.ActiveDevices||[];var C,S,D,j,N,M,R;w.empty();for(C=0;C<x.length;C++){D=x[C][1];s=this.client.lookup(x[C][0],"com.redhat.Cockpit.Storage.Block");N=x[C][2];R=x[C][3];M="";for(S=0;S<N.length;S++){if(S>0)M+="<br/>";M+=y(D,N[S])}if(R>0){if(N.length>0)M+="<br/>";M+='<span style="color:red">'+t.format(_("$0 Read Errors"),R)+"</span>"}w.append(e('<li class="list-group-item">').append(e('<table style="width:100%">').append(e("<tr>").append(e('<td style="width:20px;text-align:center">').text(D<0?"--":D),e("<td>").append(T(s)),e('<td style="width:100px;text-align:right">').html(M),e('<td style="text-align:right">').append(e("<button>",{"class":"btn btn-default",on:{click:e.proxy(this,"raid_disk_remove",s)}}).text(_("Remove")).css("visibility",r.Level==="raid0"?"hidden":"visible"))))))}},_updateVG:function(){var i=this;var r=this._vg;var s=r.getObject();var c,l,d,u,f,p,h,g,m,v;this.watch_object(r);if(r.NeedsPolling)this.start_vg_polling();else this.stop_vg_polling();l=r.Size>0?o(r.Size):"--";e("#vg_detail_capacity").html(l);e("#vg_detail_name").text(r.Name);e("#vg_detail_uuid").text(r.UUID);p=e("#vg-physical-volumes");h=[];f=this.client.getObjectsFrom("/com/redhat/Cockpit/Storage/block_devices/");for(c=0;c<f.length;c++){d=f[c].lookup("com.redhat.Cockpit.Storage.Block");if(d&&d.PvGroup==s.objectPath){h.push(d)}}h.sort(function(e,t){return e.DeviceNumber-t.DeviceNumber});function b(e){return function(t){i.physical_volume_action(e,t)}}var k=[{title:_("Remove"),action:"remove",is_default:true},{title:_("Empty"),action:"empty"}];p.empty();for(c=0;c<h.length;c++){d=h[c];u=d&&d.PartitionNumber===0&&this.client.lookup(d.Drive,"com.redhat.Cockpit.Storage.Drive");p.append(e('<li class="list-group-item">').append(e('<table style="width:100%">').append(e("<tr>").append(e("<td>").append(T(d),e("<br>"),t.format(_("$size, $free free"),{size:a(d.PvSize),free:a(d.PvFreeSize)})),e('<td style="text-align:right">').html(n.action_btn(b(d),k))))))}this._updateContent(r)},action:function(e){if(!n.check_admin())return;if(e=="format")this.format_disk();else if(e=="delete")this.delete_raid();else if(e=="start")this.start();else if(e=="stop")this.stop();else if(e=="start-scrub")this.start_scrub();else if(e=="stop-scrub")this.stop_scrub();else console.log("Unknown op %s",e)},block_action:function(e,t){function i(e){return e._iface_name=="com.redhat.Cockpit.Storage.LogicalVolume"||e.LogicalVolume!="/"}function a(e){if(e._iface_name=="com.redhat.Cockpit.Storage.LogicalVolume")return e;else return e._client.lookup(e.LogicalVolume,"com.redhat.Cockpit.Storage.LogicalVolume")}if(!n.check_admin())return;if(t=="format")this.format(e);else if(t=="delete"){if(i(e)){this.delete_logical_volume(a(e))}else this.delete_partition(e)}else if(t=="mount")this.mount(e);else if(t=="unmount")this.unmount(e);else if(t=="lock")this.lock(e);else if(t=="unlock")this.unlock(e);else if(t=="fsys-options")this.fsys_options(e);else if(t=="crypto-options")this.crypto_options(e);else if(t=="resize")this.resize_logical_volume(a(e));else if(t=="rename")this.rename_logical_volume(a(e));else if(t=="activate")this.activate_logical_volume(a(e));else if(t=="deactivate")this.deactivate_logical_volume(a(e));else if(t=="create-thin-volume")this.create_thin_volume(a(e));else if(t=="create-snapshot")this.create_snapshot(a(e));else console.log("Unknown block op %s",t)},raid_action:function(){if(!n.check_admin())return;this.action(this.raid_op)},start:function(){this._mdraid.call("Start",function(e,t){if(e)n.show_unexpected_error(e)})},stop:function(){this._mdraid.call("Stop",function(e,t){if(e)n.show_unexpected_error(e)})},delete_raid:function(){var e=this;var i=t.location;n.confirm(t.format(_("Please confirm deletion of $0"),z(this._mdraid)),_("Deleting a RAID Device will erase all data on it."),_("Delete")).done(function(){e._mdraid.call("Delete",function(e,t){if(e)n.show_unexpected_error(e);else i.go("storage")})})},start_scrub:function(){this._mdraid.call("RequestSyncAction","repair",function(e,t){if(e)n.show_unexpected_error(e)})},stop_scrub:function(){this._mdraid.call("RequestSyncAction","idle",function(e,t){if(e)n.show_unexpected_error(e)})},format_disk:function(t){if(!n.check_admin())return;B.block=null;if(this._drive)B.block=v(this._drive);else if(this._mdraid)B.block=b(this._mdraid);else if(this._block)B.block=this._block;if(B.block)e("#storage_format_disk_dialog").modal("show")},format:function(t){G.mode="format";G.block=t;e("#storage_format_dialog").modal("show")},delete_partition:function(e){n.confirm(t.format(_("Please confirm deletion of $0"),e.Device),_("Deleting a partition will delete all data in it."),_("Delete")).done(function(){e.call("DeletePartition",function(e){if(e)n.show_unexpected_error(e)})})},create_partition:function(t,i,a,o){if(!n.check_admin())return;G.block=t;G.mode="create-partition";G.start=i;G.size=a;G.enable_dos_extended=o;e("#storage_format_dialog").modal("show")},mount:function(e){e.call("Mount",function(e){if(e)n.show_unexpected_error(e)})},unmount:function(e){e.call("Unmount",function(e){if(e)n.show_unexpected_error(e)})},lock:function(e){e.call("Lock",function(e){if(e)n.show_unexpected_error(e)})},unlock:function(t){et.block=t;e("#storage_unlock_dialog").modal("show")},fsys_options:function(t){K.block=t;e("#filesystem_options_dialog").modal("show")},crypto_options:function(t){Z.block=t;e("#crypto_options_dialog").modal("show")},raid_disk_remove:function(e){if(!n.check_admin())return;this._mdraid.call("RemoveDevices",[e.getObject().objectPath],function(e){if(e)n.show_unexpected_error(e)})},raid_disk_add:function(){if(!n.check_admin())return;tt.mdraid=this._mdraid;e("#raid_disk_add_dialog").modal("show")},start_vg_polling:function(){var e=this;function t(){if(e._vg)e._vg.call("Poll",function(e){if(e)console.log(e.message)})}if(!this.vg_polling_id){t();this.vg_polling_id=window.setInterval(t,5e3)}},stop_vg_polling:function(){if(this.vg_polling_id){window.clearInterval(this.vg_polling_id);this.vg_polling_id=null}},volume_group_action:function(e){if(e=="delete")this.delete_volume_group();else if(e=="rename")this.rename_volume_group();else if(e=="create-plain")this.create_plain_volume(this._vg);else if(e=="create-thin-pool")this.create_thin_pool(this._vg);else if(e=="create-raid")this.create_raid_volume(this._vg);else console.log("Unknown volume group op %s",e)},delete_volume_group:function(){var e=this;var i=t.location;if(!n.check_admin())return;n.confirm(t.format(_("Please confirm deletion of $0"),e._vg.Name),_("Deleting a volume group will erase all data on it."),_("Delete")).done(function(){e._vg.call("Delete",function(e,t){if(e)n.show_unexpected_error(e);else i.go("storage")})})},physical_volume_action:function(e,t){if(t=="remove")this.remove_physical_volume(e);else if(t=="empty")this.empty_physical_volume(e);else console.log("Unknown physical volume action %s",t)},remove_physical_volume:function(e){if(!n.check_admin())return;if(e.PvFreeSize!=e.PvSize){n.show_error_dialog("Error","Volume is in use.");return}var t=0;var i=this.client.getObjectsFrom("/com/redhat/Cockpit/Storage/block_devices/");for(var a=0;a<i.length;a++){var o=i[a].lookup("com.redhat.Cockpit.Storage.Block");if(o&&o.PvGroup==this._vg.getObject().objectPath){t+=1}}if(t==1){n.show_error_dialog("Error","Can't remove the last physical volume.");return}this._vg.call("RemoveDevice",e.getObject().objectPath,function(e){if(e)n.show_unexpected_error(e)})},empty_physical_volume:function(e){if(!n.check_admin())return;var t=e.PvSize-e.PvFreeSize;if(t===0){n.show_error_dialog("Dude","Volume is already empty.");return}if(t>this._vg.FreeSize){n.show_error_dialog("Error","Not enough free space.");return}this._vg.call("EmptyDevice",e.getObject().objectPath,function(e){if(e)n.show_unexpected_error(e)})},add_physical_volume:function(){if(!n.check_admin())return;nt.volume_group=this._vg;e("#vg_disk_add_dialog").modal("show")},create_plain_volume:function(t){if(!n.check_admin())return;H.volume_group=t;e("#storage_create_plain_volume_dialog").modal("show")},create_thin_pool:function(t){if(!n.check_admin())return;W.volume_group=t;e("#storage_create_thin_pool_dialog").modal("show")},create_thin_volume:function(t){if(!n.check_admin())return;J.pool=t;e("#storage_create_thin_volume_dialog").modal("show")},create_raid_volume:function(e){if(!n.check_admin())return;n.show_error_dialog("Sorry","Not yet.")},create_snapshot:function(t){if(!n.check_admin())return;if(t.Origin!="/"){n.show_error_dialog("Error","Can't take a snapshot of a snapshot.");return}Q.origin=t;e("#storage_create_snapshot_dialog").modal("show")},delete_logical_volume:function(e){var i=this;if(!n.check_admin())return;n.confirm(t.format(_("Please confirm deletion of $0"),i._vg.Name+"/"+e.Name),_("Deleting a logical volume will erase all data in it."),_("Delete")).done(function(){e.call("Delete",function(e,t){if(e)n.show_unexpected_error(e)})})},resize_logical_volume:function(t){if(!n.check_admin())return;q.volume=t;e("#storage_resize_volume_dialog").modal("show")},rename_volume_group:function(){if(!n.check_admin())return;X.group=this._vg;e("#storage_rename_group_dialog").modal("show")},rename_logical_volume:function(t){if(!n.check_admin())return;Y.volume=t;e("#storage_rename_volume_dialog").modal("show")},activate_logical_volume:function(e){if(!n.check_admin())return;e.call("Activate",function(e,t){if(e)n.show_unexpected_error(e)})},deactivate_logical_volume:function(e){if(!n.check_admin())return;e.call("Deactivate",function(e,t){if(e)n.show_unexpected_error(e)})}};function U(){this._init()}n.pages.push(new U);$.prototype={_init:function(){this.id="create-raid-dialog"},show:function(){},leave:function(){},setup:function(){e("#create-raid-create").on("click",e.proxy(this,"create"));e("#create-raid-level").on("change",e.proxy(this,"update"))},enter:function(){this.client=$.client;this.blocks=E(this.client,"create-raid-drives",null);e("#create-raid-drives input").on("change",e.proxy(this,"update"));e("#create-raid-name").val("");e("#create-raid-level").selectpicker("val","raid5");e("#create-raid-chunk").selectpicker("val","512");e("#accounts-create-locked").prop("checked",false);this.update()},update:function(){var n=this;var i,o,r,s,c;var l,d,u;var f=F(e("#create-raid-drives"),n.blocks);i=f.length;o=Infinity;for(u=0;u<f.length;u++){d=this.client.lookup(f[u],"com.redhat.Cockpit.Storage.Block");if(d.Size<o)o=d.Size}e("#create-raid-chunk").parents("tr").toggle(e("#create-raid-level").val()!=="raid1");switch(e("#create-raid-level").val()){case"raid0":c=2;r=o*i;break;case"raid1":c=2;r=o;break;case"raid4":c=2;r=o*(i-1);break;case"raid5":c=2;r=o*(i-1);break;case"raid6":c=4;r=o*(i-2);break;case"raid10":c=2;var p=1;var h=2;r=o/p;r*=i;r/=h;break;default:console.log("Unexpected RAID level %s",e("#create-raid-level").val());c=0;r=0;break}if(i>=c){e("#create-raid-summary-drives").text(t.format(_("$n disks of $size each"),{n:i,size:a(o)}));e("#create-raid-summary-size").text(a(r));e("#create-raid-create").prop("disabled",false)}else{e("#create-raid-summary-drives").text(t.format(_("$0 more disks needed"),c-i));e("#create-raid-summary-size").text("--");e("#create-raid-create").prop("disabled",true)}},create:function(){var t=this;var i=e("#create-raid-level").val();var a=i==="raid1"?0:e("#create-raid-chunk").val();var o=e("#create-raid-name").val();var r=F(e("#create-raid-drives"),t.blocks);var s=this.client.lookup("/com/redhat/Cockpit/Storage/Manager","com.redhat.Cockpit.Storage.Manager");s.call("MDRaidCreate",r,i,o,a*1024,function(t){e("#create-raid-dialog").modal("hide");if(t)n.show_unexpected_error(t)})}};function $(){this._init()}n.dialogs.push(new $);function E(n,i,o){var r;var s=e("#"+i);r=L(n,o);r.sort(function(e,t){return e.DeviceNumber-t.DeviceNumber});var c=e("<ul/>",{"class":"list-group available-disks-group"});
for(var l=0;l<r.length;l++){var d=r[l];var u=t.format("$size $desc $dev",{size:a(d.Size),desc:A(d),dev:d.Device});var f=i+"-"+l;c.append(e("<li>",{"class":"list-group-item"}).append(e("<div>",{"class":"checkbox",style:"margin:0px"}).append(e("<input/>",{type:"checkbox",name:f,id:f,"data-index":l}),e("<label/>",{"for":f}).text(u))))}s.html(c);return r}function F(t,n){var i=[];t.find("input").each(function(t,a){if(a.checked){var o=e(a).attr("data-index");i.push(n[o].getObject().objectPath)}});return i}V.prototype={_init:function(){this.id="create-volume-group-dialog"},show:function(){if(this.blocks.length>0){e("#create-vg-name").prop("disabled",false);e("#create-vg-name").focus()}else{e("#create-vg-name").prop("disabled",true)}},leave:function(){},setup:function(){e("#create-vg-create").on("click",e.proxy(this,"create"))},enter:function(){var t=-1;this.client=V.client;this.blocks=E(this.client,"create-vg-drives",null);e("#disks-not-found .close").on("click",function(){e("#disks-not-found").hide()});e("#create-vg-name").on("input",i);e("#create-vg-name").on("input change focus",n);e('#create-vg-drives [type = "checkbox"]').on("change",r);e('#create-vg-drives [type = "checkbox"]').on("click change",n);e("#create-vg-name").val("");e("#create-vg-create").prop("disabled",true);e("#create-vg-drives").prop("checked",false);c(this.blocks);function n(){j("#create-vg-error");if(a()){if(s()){e("#create-vg-create").prop("disabled",false);j("#create-vg-error")}else{if(t===-1)return;e("#create-vg-create").prop("disabled",true);D("#create-vg-error",_("At least one disk needed."))}}else{e("#create-vg-create").prop("disabled",true)}}function i(){if(t===0)t=-1}function a(){function t(e,t){var n=e.match(t);if(n){var i=n[n.length-1];return i[i.length-1]}else{return null}}var n=e("#create-vg-name").val();if(n===""){S("#creat-vg-name-cell");j("#create-vg-error");return false}else if(n.length>127){C("#creat-vg-name-cell");D("#create-vg-error",_("Name length cannot exceed 127 characters."));return false}else{var i=new RegExp("[^a-zA-Z0-9+._-]+","g");var a=t(n,i);if(!a){S("#creat-vg-name-cell");j("#create-vg-error");return true}else{C("#creat-vg-name-cell");if(a.search(/\s+/)===-1)D("#create-vg-error",_("Name cannot contain '"+a+"'."));else D("#create-vg-error",_("Name cannot contain whitespace."));return false}}}function o(t){var n=e(t);var i=0;for(var a=0;a<n.length;a++){if(n[a].checked)i++}return i}function r(){t=o()}function s(){var e=o('#create-vg-drives [type = "checkbox"]');if(e>0)return true;else return false}function c(t){if(t.length>0){e("#disks-not-found span.alert-message").text("");e("#disks-not-found").hide()}else{e("#disks-not-found span.alert-message").text(_("No available disks"));e("#disks-not-found").show()}}},create:function(){var t=this;var i=e("#create-vg-name").val();if(i.trim()===""){C("#creat-vg-name-cell");D("#create-vg-error",_("Name cannot contain whitespace."));return}var a=F(e("#create-vg-drives"),t.blocks);var o=t.client.lookup("/com/redhat/Cockpit/Storage/Manager","com.redhat.Cockpit.Storage.Manager");o.call("VolumeGroupCreate",i,a,function(t){e("#create-volume-group-dialog").modal("hide");if(t)n.show_unexpected_error(t)})}};function V(){this._init()}n.dialogs.push(new V);B.prototype={_init:function(){this.id="storage_format_disk_dialog"},show:function(){},leave:function(){},setup:function(){e("#format-disk-format").on("click",e.proxy(this,"format"))},enter:function(){e("#format-disk-title").text(t.format(_("Format Disk $0"),B.block.Device));e("#format-disk-type").selectpicker("val","gpt");e("#format-disk-erase").selectpicker("val","no")},format:function(){B.block.call("Format",e("#format-disk-type").val(),e("#format-disk-erase").val(),"","","","","","",function(t){e("#storage_format_disk_dialog").modal("hide");if(t)n.show_unexpected_error(t)})}};function B(){this._init()}n.dialogs.push(new B);G.prototype={_init:function(){this.id="storage_format_dialog"},show:function(){},leave:function(){},setup:function(){e("#format-format").on("click",e.proxy(this,"format"));e("#format-type").on("change",e.proxy(this,"update"));e("#format-custom").on("keyup change",e.proxy(this,"update"));e("#format-passphrase").on("keyup change",e.proxy(this,"update"));e("#format-passphrase-2").on("keyup change",e.proxy(this,"update"));e("#format-mounting").on("change",e.proxy(this,"update"));e("#format-mount-point").on("keyup change",e.proxy(this,"update"))},enter:function(){e("#format-size-row").toggle(G.mode=="create-partition");function n(t){e('#format-type option[value="dos-extended"]').toggle(t);e("#format-type").selectpicker("refresh")}if(G.mode=="format"){e("#format-title").text(t.format(_("Format $0"),G.block.Device));e("#format-warning").text(_("Formatting a storage device will erase all data on it."));e("#format-format").text(_("Format"));e("#format-format").addClass("btn-danger").removeClass("btn-primary");e("#format-mounting").selectpicker("val",G.block.MountPoint?"custom":"default");e("#format-mount-point").val(G.block.MountPoint);e("#format-mount-options").val(G.block.MountOptions);n(false)}else{e("#format-title").text(t.format(_("Create Partition on $0"),G.block.Device));e("#format-warning").text("");e("#format-format").text(_("Create partition"));e("#format-format").addClass("btn-primary").removeClass("btn-danger");e("#format-mounting").selectpicker("val","default");e("#format-mount-point").val("");e("#format-mount-options").val("");n(G.enable_dos_extended)}e("#format-size").val("");e("#format-erase").selectpicker("val","no");e("#format-type").selectpicker("val","xfs");e("#format-name").val("");e("#format-custom").val("");e("#format-crpyto-options").val("");e("#format-passphrase").val("");e("#format-passphrase-2").val("");e("#format-store-passphrase").prop("checked",false);this.update()},update:function(){var t=e("#format-type").val();var n=t!="empty"&&t!="dos-extended";var i=t=="luks+xfs"||t=="luks+ext4";var a=!n||e("#format-mounting").val()=="default";e("#format-custom-row").toggle(t=="custom");e("#format-name-row").toggle(n);e("#format-passphrase-row, #format-passphrase-row-2, #format-store-passphrase-row, #format-crypto-options-row").toggle(i);e("#format-mounting-row").toggle(n);e("#format-mount-point-row, #format-mount-options-row").toggle(!a);if(t=="custom"&&!e("#format-custom").val()||i&&(!e("#format-passphrase").val()||e("#format-passphrase").val()!=e("#format-passphrase-2").val())||!a&&!e("#format-mount-point").val()){e("#format-format").prop("disabled",true)}else{e("#format-format").prop("disabled",false)}},format:function(){var t=e("#format-size").val();if(!t)t=G.size;else t=t*1024*1024;var i=e("#format-type").val();var a=i=="luks+xfs"||i=="luks+ext4";if(i=="custom")i=e("#format-custom").val();var o=e("#format-erase").val();var r=e("#format-name").val();var s=i!="empty"&&i!="dos-extended";var c=!s||e("#format-mounting").val()=="default";var l="";var d="";if(a){l=e("#format-passphrase").val();if(i=="luks+ext4")i="ext4";else if(i=="luks+xfs")i="xfs";else throw new Error("Unhandled filesystem type "+i);if(e("#format-store-passphrase").prop("checked"))d=l}var u="";var f="";if(!c){u=e("#format-mount-point").val();f=e("#format-mount-options").val()}var p=e("#format-crypto-options").val();if(G.mode=="create-partition")G.block.call("CreatePartition",G.start,t,i,o,r,l,u,f,d,p,function(t){e("#storage_format_dialog").modal("hide");if(t)n.show_unexpected_error(t)});else G.block.call("Format",i,o,r,l,u,f,d,p,function(t){e("#storage_format_dialog").modal("hide");if(t)n.show_unexpected_error(t)})}};function G(){this._init()}n.dialogs.push(new G);H.prototype={_init:function(){this.id="storage_create_plain_volume_dialog"},show:function(){},leave:function(){},setup:function(){e("#create-pvol-create").on("click",e.proxy(this,"create"))},enter:function(){e("#create-pvol-name").val("");e("#create-pvol-size").val("")},create:function(){var t=e("#create-pvol-size").val();var i=e("#create-pvol-name").val();t=t*1024*1024;H.volume_group.call("CreatePlainVolume",i,t,function(t){e("#storage_create_plain_volume_dialog").modal("hide");if(t)n.show_unexpected_error(t)})}};function H(){this._init()}n.dialogs.push(new H);W.prototype={_init:function(){this.id="storage_create_thin_pool_dialog"},show:function(){},leave:function(){},setup:function(){e("#create-tpool-create").on("click",e.proxy(this,"create"))},enter:function(){e("#create-tpool-name").val("");e("#create-tpool-size").val("")},create:function(){var t=e("#create-tpool-size").val();var i=e("#create-tpool-name").val();t=t*1024*1024;W.volume_group.call("CreateThinPoolVolume",i,t,function(t){e("#storage_create_thin_pool_dialog").modal("hide");if(t)n.show_unexpected_error(t)})}};function W(){this._init()}n.dialogs.push(new W);J.prototype={_init:function(){this.id="storage_create_thin_volume_dialog"},show:function(){},leave:function(){},setup:function(){e("#create-tvol-create").on("click",e.proxy(this,"create"))},enter:function(){e("#create-tvol-name").val("");e("#create-tvol-size").val("")},create:function(){var t=e("#create-tvol-size").val();var i=e("#create-tvol-name").val();t=t*1024*1024;var a=J.pool._client.lookup(J.pool.VolumeGroup,"com.redhat.Cockpit.Storage.VolumeGroup");a.call("CreateThinVolume",i,t,J.pool.getObject().objectPath,function(t){e("#storage_create_thin_volume_dialog").modal("hide");if(t)n.show_unexpected_error(t)})}};function J(){this._init()}n.dialogs.push(new J);Q.prototype={_init:function(){this.id="storage_create_snapshot_dialog"},show:function(){},leave:function(){},setup:function(){e("#create-svol-create").on("click",e.proxy(this,"create"))},enter:function(){e("#create-svol-name").val("");e("#create-svol-size").val("");e("#create-svol-size-row").toggle(Q.origin.ThinPool=="/")},create:function(){var t=e("#create-svol-name").val();var i=e("#create-svol-size").val();i=i*1024*1024;if(Q.origin.ThinPool!="/")i=0;Q.origin.call("CreateSnapshot",t,i,function(t){e("#storage_create_snapshot_dialog").modal("hide");if(t)n.show_unexpected_error(t)})}};function Q(){this._init()}n.dialogs.push(new Q);q.prototype={_init:function(){this.id="storage_resize_volume_dialog"},show:function(){},leave:function(){},setup:function(){e("#resize-lvol-resize").on("click",e.proxy(this,"resize"))},enter:function(){var t=k(q.volume);e("#resize-lvol-size").val((q.volume.Size/(1024*1024)).toFixed(0));e("#resize-lvol-resize-fsys").prop("checked",t&&t.IdUsage=="filesystem");e("#resize-lvol-resize-fsys").parents("tr").toggle(q.volume.Type=="block")},resize:function(){var t=e("#resize-lvol-size").val();var i=e("#resize-lvol-resize-fsys").prop("checked");t=t*1024*1024;q.volume.call("Resize",t,{resize_fsys:i},function(t){e("#storage_resize_volume_dialog").modal("hide");if(t)n.show_unexpected_error(t)})}};function q(){this._init()}n.dialogs.push(new q);Y.prototype={_init:function(){this.id="storage_rename_volume_dialog"},show:function(){},leave:function(){},setup:function(){e("#rename-lvol-rename").on("click",e.proxy(this,"rename"))},enter:function(){e("#rename-lvol-name").val(Y.volume.Name)},rename:function(){var t=e("#rename-lvol-name").val();Y.volume.call("Rename",t,function(t){e("#storage_rename_volume_dialog").modal("hide");if(t)n.show_unexpected_error(t)})}};function Y(){this._init()}n.dialogs.push(new Y);X.prototype={_init:function(){this.id="storage_rename_group_dialog"},show:function(){},leave:function(){},setup:function(){e("#rename-vg-rename").on("click",e.proxy(this,"rename"))},enter:function(){e("#rename-vg-name").val(X.group.Name)},rename:function(){var i=e("#rename-vg-name").val();X.group.call("Rename",i,function(i){e("#storage_rename_group_dialog").modal("hide");t.location="storage";if(i)n.show_unexpected_error(i)})}};function X(){this._init()}n.dialogs.push(new X);K.prototype={_init:function(){this.id="filesystem_options_dialog"},show:function(){},leave:function(){},setup:function(){e("#fsysopts-apply").on("click",e.proxy(this,"apply"));e("#fsysopts-mounting").on("change",e.proxy(this,"update"));e("#fsysopts-mount-point").on("change keyup",e.proxy(this,"update"))},enter:function(){e("#fsysopts-name").val(K.block.IdLabel);e("#fsysopts-mounting").selectpicker("val",K.block.MountPoint?"custom":"default");e("#fsysopts-mount-point").val(K.block.MountPoint);e("#fsysopts-mount-options").val(K.block.MountOptions);this.update()},update:function(){var t=e("#fsysopts-mounting").val()=="default";e("#fsysopts-mount-point-row, #fsysopts-mount-options-row").toggle(!t);e("#fsysopts-apply").prop("disabled",!t&&!e("#fsysopts-mount-point").val())},apply:function(){var t=e("#fsysopts-name").val();var i=e("#fsysopts-mounting").val()=="default";var a="";var o="";if(!i){a=e("#fsysopts-mount-point").val();o=e("#fsysopts-mount-options").val()}K.block.call("SetFilesystemOptions",t,a,o,function(t){e("#filesystem_options_dialog").modal("hide");if(t)n.show_unexpected_error(t)})}};function K(){this._init()}n.dialogs.push(new K);Z.prototype={_init:function(){this.id="crypto_options_dialog"},show:function(){},leave:function(){},setup:function(){e("#crypto-options-apply").on("click",e.proxy(this,"apply"))},enter:function(){e("#crypto-options-passphrase").val("");e("#crypto-options-options").val(Z.block.CryptoOptions);Z.block.call("GetCryptoPassphrase",function(t,n){if(n)e("#crypto-options-passphrase").val(n)})},apply:function(){var t=e("#crypto-options-passphrase").val();var i=e("#crypto-options-options").val();Z.block.call("SetCryptoOptions",t,i,function(t){e("#crypto_options_dialog").modal("hide");if(t)n.show_unexpected_error(t)})}};function Z(){this._init()}n.dialogs.push(new Z);et.prototype={_init:function(){this.id="storage_unlock_dialog"},show:function(){},leave:function(){},setup:function(){e("#unlock-unlock").on("click",e.proxy(this,"unlock"))},enter:function(){e("#unlock-passphrase").val("")},unlock:function(){var t=e("#unlock-passphrase").val();et.block.call("Unlock",t,function(t){e("#storage_unlock_dialog").modal("hide");if(t)n.unexpected_error(t)})}};function et(){this._init()}n.dialogs.push(new et);tt.prototype={_init:function(){this.id="raid_disk_add_dialog"},show:function(){},leave:function(){},setup:function(){e("#raid-disk-add-add").on("click",e.proxy(this,"add"))},enter:function(){function t(e){var t=e._client.lookup(e.MDRaid,"com.redhat.Cockpit.Storage.MDRaid");return e.MDRaid==tt.mdraid.getObject().objectPath}this.blocks=E(tt.mdraid._client,"raid-disk-add-drives",t);e("#raid-disk-add-drives input").on("change",e.proxy(this,"update"));this.update()},update:function(){var t=F(e("#raid-disk-add-drives"),this.blocks).length;e("#raid-disk-add-add").prop("disabled",t===0)},add:function(){var t=this;var i=F(e("#raid-disk-add-drives"),this.blocks);tt.mdraid.call("AddDevices",i,function(t){e("#raid_disk_add_dialog").modal("hide");if(t)n.show_unexpected_error(t)})}};function tt(){this._init()}n.dialogs.push(new tt);nt.prototype={_init:function(){this.id="vg_disk_add_dialog"},show:function(){},leave:function(){},setup:function(){e("#vg-disk-add-add").on("click",e.proxy(this,"add"))},enter:function(){function t(e){var t=e._client.lookup(e.LogicalVolume,"com.redhat.Cockpit.Storage.LogicalVolume");return t&&t.VolumeGroup==nt.volume_group.getObject().objectPath}this.blocks=E(nt.volume_group._client,"vg-disk-add-drives",t);e("#vg-disk-add-drives input").on("change",e.proxy(this,"update"));this.update()},update:function(){var t=F(e("#vg-disk-add-drives"),this.blocks).length;e("#vg-disk-add-add").prop("disabled",t===0)},add:function(){var t=this;var i=F(e("#vg-disk-add-drives"),this.blocks);function a(t){if(t<i.length)nt.volume_group.call("AddDevice",i[t],function(i){if(i){e("#vg_disk_add_dialog").modal("hide");n.show_unexpected_error(i)}else{a(t+1)}});else e("#vg_disk_add_dialog").modal("hide")}a(0)}};function nt(){this._init()}n.dialogs.push(new nt)})(jQuery,cockpit,shell,modules);var shell=shell||{};(function(e,t,n){n.realms_op_set_parameters=function a(e,t,n,o){i.manager=e;i.op=t;i.realm=n;i.details=o};i.prototype={_init:function(){this.id="realms-op"},show:function(){},setup:function(){var t=this;e("#realms-op-apply").on("click",function(e){t.apply()});e("#realms-op-cancel").on("click",function(e){t.cancel()});e("#realms-op-address").on("keyup",function(e){t.maybe_check_realm()});e("#realms-op-address").on("change",function(e){t.maybe_check_realm()});e(".realms-op-field").on("keydown",function(e){if(e.which==13)t.apply()});e("#realms-op-auth").on("change",function(e){t.update_cred_fields()});e("#realms-op-software").on("change",function(e){t.update_auth_methods()})},enter:function(){var t=this;e("#realms-op-diagnostics").hide();t.realm_manager=i.manager;t.op=i.op;t.realm=i.realm;t.given_details=i.details;e(t.realm_manager).on("notify:Busy.realms-op",function(){t.update_busy()});if(t.op=="join"){t.never_show_software_choice=1;t.title=C_("page-title","Join a Domain");e("#realms-op-apply").text(_("Join"));e(".realms-op-join-only-row").show()}else if(t.op=="leave"){t.never_show_software_choice=1;t.title=C_("page-title","Leave Domain");e("#realms-op-apply").text(_("Leave"));e(".realms-op-join-only-row").hide()}else{e("#realms-op").modal("hide");return}e("#realms-op-title").empty().append(t.title);e("#realms-op-spinner").hide();e("#realms-op-wait-message").hide();e("#realms-op-address-spinner").hide();e("#realms-op-address-error").hide();e("#realms-op-error").empty();e("#realms-op-diagnostics").empty();e(".realms-op-field").val("");t.checking=0;t.checked="";t.discovered_details=[];if(t.op=="join"){t.check_default_realm();t.maybe_check_realm();t.update_discovered_details()}else{t.update_auth_methods()}t.update_busy()},leave:function(){},update_discovered_details:function(){var t=this;var i=e("#realms-op-software");i.empty();for(var a=0;a<t.discovered_details.length;a++){var o=t.discovered_details[a];var r=o["client-software"]+" / "+o["server-software"];i.append('<option value="'+a+'">'+n.esc(r)+"</option>")}t.update_auth_methods();if(t.never_show_software_choice||t.discovered_details.length<2){e("#realms-op-software-row").hide()}else{e("#realms-op-software-row").show()}},update_auth_methods:function(){var t=this;var i={};function a(e){if(e){var t=e["supported-join-credentials"];if(t){for(var n=0;n<t.length;n++)i[t[n]]=1}}}if(t.op=="leave"){a(t.given_details)}else if(t.never_show_software_choice){for(var o=0;o<t.discovered_details.length;o++)a(t.discovered_details[o])}else{var r=e("#realms-op-software").val();a(t.discovered_details[r])}var s=0;var c=e("#realms-op-auth");function l(e,t){if(e in i){c.append('<option value="'+e+'">'+n.esc(t)+"</option>");s=1}}c.empty();l("admin",_("Administrator Password"));l("user",_("User Password"));l("otp",_("One Time Password"));l("none",_("Automatic"));if(!s)c.append('<option value="admin">'+_("Administrator Password")+"</option>");if(e('[data-id="realms-op-auth"]').length<=1)e("#realms-authentification-row").hide();else e("#realms-authentification-row").show();e("#realms-op-auth").selectpicker();t.update_cred_fields()},update_cred_fields:function(){var t=this;var n=e("#realms-op-auth").val();e("#realms-op-admin-row").hide();e("#realms-op-admin-password-row").hide();e("#realms-op-user-row").hide();e("#realms-op-user-password-row").hide();e("#realms-op-otp-row").hide();if(n=="admin"){e("#realms-op-admin-row").show();e("#realms-op-admin-password-row").show();var i;if(t.op=="join"){var a=e("#realms-op-software").val();var o=a&&t.discovered_details[a];i=o&&o["suggested-administrator"]}else{i=t.given_details["suggested-administrator"]}if(i&&!e("#realms-op-admin").val())e("#realms-op-admin")[0].placeholder=_('e.g. "'+i+'"')}else if(n=="user"){e("#realms-op-user-row").show();e("#realms-op-user-password-row").show()}else if(n=="otp"){e("#realms-op-otp-row").show()}},update_busy:function(){var t=this;var n=t.realm_manager.Busy;if(n&&n[0]){e("#realms-op-spinner").show();e("#realms-op-wait-message").show();e(".realms-op-field").prop("disabled",true);e("#realms-op-apply").prop("disabled",true);e("#realms-op-software").prop("disabled",true);e('[data-id="realms-op-auth"]').prop("disabled",true)}else{e("#realms-op-spinner").hide();e("#realms-op-wait-message").hide();e(".realms-op-field").prop("disabled",false);e('[data-id="realms-op-auth"]').prop("disabled",false);e("#realms-op-apply").prop("disabled",false);e("#realms-op-software").prop("disabled",false)}},check_default_realm:function(){var n=this;n.realm_manager.call("Discover","",{},function(n,i,a){if(i){e("#realms-op-address")[0].placeholder=t.format(_("e.g. $0"),i)}})},maybe_check_realm:function(){var t=this;if(e("#realms-op-address").val()!=t.checked){e("#realms-op-address-error").hide();if(t.timeout)window.clearTimeout(t.timeout);t.timeout=window.setTimeout(function(){t.check_realm()},1e3)}},check_realm:function(){var i=this;var a=e("#realms-op-address").val();if(i.checking||!a||i.checked==a){return}e("#realms-op-address-spinner").show();i.checking=1;i.checked=a;i.realm_manager.call("Discover",a,{},function(o,r,s){if(e("#realms-op-address").val()!=i.checked){i.checking=0;i.check_realm()}else{e("#realms-op-address-spinner").hide();i.checking=0;i.discovered_details=[];if(o)e("#realms-op-error").empty().append(o.message);else if(!r){e("#realms-op-address-error").show();e("#realms-op-address-error").attr("title",t.format(_("Domain $0 could not be contacted"),n.esc(a)))}else{i.discovered_details=s}i.update_discovered_details()}})},apply:function(){var t=this;function n(n,i){t.working=false;if(n&&n.name!="com.redhat.Cockpit.Error.Cancelled"){e("#realms-op-error").empty().append(n.message);e("#realms-op-error").append(' <button id="realms-op-more-diagnostics" data-inline="true">'+_("More")+"</button>");e("#realms-op-more-diagnostics").click(function(n){t.realm_manager.call("GetDiagnostics",function(t,n){e("#realms-op-more-diagnostics").hide();e("#realms-op-diagnostics").show();e("#realms-op-diagnostics").empty().append(n)})})}else{e("#realms-op").modal("hide")}}e("#realms-op-error").empty();e("#realms-op-diagnostics").empty();var i=e("#realms-op-auth").val();var a;if(i=="user")a=["user",e("#realms-op-user").val(),e("#realms-op-user-password").val()];else if(i=="admin")a=["admin",e("#realms-op-admin").val(),e("#realms-op-admin-password").val()];else if(i=="otp")a=["otp","",e("#realms-op-ot-password").val()];else a=["none","",""];var o;if(t.op=="join"){var r;if(t.never_show_software_choice)r={};else{var s=e("#realms-join-software").val();r=t.discovered_details[s]}o={"computer-ou":e("#realms-join-computer-ou").val()};if(r["client-software"])o["client-software"]=r["client-software"];if(r["server-software"])o["server-software"]=r["server-software"];t.working=true;t.realm_manager.call("Join",e("#realms-op-address").val(),a,o,n)}else if(t.op=="leave"){o={"server-software":t.given_details["server-software"],"client-software":t.given_details["client-software"]};t.working=true;t.realm_manager.call("Leave",t.realm,a,o,n)}},cancel:function(){var t=this;if(t.working){t.realm_manager.call("Cancel",function(e,t){})}else{e("#realms-op").modal("hide")}e("#realms-op-spinner").hide();e("#realms-op-wait-message").hide()}};function i(){this._init()}n.dialogs.push(new i)})(jQuery,cockpit,shell);var shell=shell||{};(function(e,t,n){i.prototype={_init:function(){this.id="shutdown-dialog"},setup:function(){e("#shutdown-restart").click(e.proxy(this,"restart"));e("#shutdown-poweroff").click(e.proxy(this,"poweroff"));e("#shutdown-delay").html(this.delay_btn=n.select_btn(e.proxy(this,"update"),[{choice:"1",title:_("1 Minute")},{choice:"5",title:_("5 Minutes")},{choice:"20",title:_("20 Minutes")},{choice:"40",title:_("40 Minutes")},{choice:"60",title:_("60 Minutes")},{choice:"0",title:_("No Delay")},{choice:"x",title:_("Specific Time")}]).css("display","inline"));e("#shutdown-time input").change(e.proxy(this,"update"))},enter:function(){this.address=n.get_page_machine();this.cockpitd=n.dbus(this.address);this.cockpitd_manager=this.cockpitd.get("/com/redhat/Cockpit/Manager","com.redhat.Cockpit.Manager");e(this.cockpitd_manager).on("notify.shutdown",e.proxy(this,"update"));e("#shutdown-message").val("").attr("placeholder",_("Message to logged in users"));n.select_btn_select(this.delay_btn,"1");this.update()},show:function(){},leave:function(){e(this.cockpitd_manager).off(".shutdown");this.cockpitd.release();this.cockpitd=null;this.cockpitd_manager=null},update:function(){var i=false;if(this.cockpitd){var a=n.util.hostname_for_display(this.cockpitd_manager);e("#shutdown-dialog .modal-title").text(t.format(_("Shutdown $0"),a))}var o=n.select_btn_selected(this.delay_btn);e("#shutdown-time").toggle(o=="x");if(o=="x"){var r=parseInt(e("#shutdown-time input:nth-child(1)").val(),10);var s=parseInt(e("#shutdown-time input:nth-child(3)").val(),10);var c=r>=0&&r<24&&(s>=0&&s<60);e("#shutdown-time").toggleClass("has-error",!c);if(!c)i=true}e("#shutdown-dialog button.btn-primary").prop("disabled",i)},shutdown:function(t){var i=n.select_btn_selected(this.delay_btn);var a=e("#shutdown-message").val();var o;if(i=="x")o=e("#shutdown-time input:nth-child(1)").val()+":"+e("#shutdown-time input:nth-child(3)").val();else o="+"+i;this.cockpitd_manager.call("Shutdown",t,o,a,function(t){e("#shutdown-dialog").modal("hide");if(t&&t.name!="Disconnected")n.show_unexpected_error(t)})},restart:function(){this.shutdown("restart")},poweroff:function(){this.shutdown("shutdown")}};function i(){this._init()}n.dialogs.push(new i)})(jQuery,cockpit,shell);var shell=shell||{};var modules=modules||{};(function(e,t,n,i){function a(){if(window.debugging=="all"||window.debugging=="resource"||true)console.debug.apply(console,arguments)}function o(e){if(e===undefined||isNaN(e))return"";return Math.round(e)+"%"}function r(e){var t=/[0-9a-zA-Z:-_.\\]/;var n="";var i;for(i=0;i<e.length;i++){var a=e[i];if(a=="/")n+="-";else if(a=="-"||a=="\\"||!t.test(a)){n+="\\x";var o=a.charCodeAt(0).toString(16);while(o.length<2)o="0"+o;n+=o}else n+=a}return n}function s(e){e=e.replace(/\/+/g,"/");if(e.length>1)e=e.replace(/\/$/,"").replace(/^\//,"");return e}function c(e){e=s(e);if(e=="/")return"-";else return r(e)}function l(e){if(e.length>0&&e[0]=="/")return c(e);else return r(e)}N_("loaded");N_("error");N_("masked");N_("not-found");N_("active");N_("reloading");N_("inactive");N_("failed");N_("activating");N_("deactivating");N_("running");N_("dead");N_("listening");N_("exited");N_("waiting");N_("elapsed");N_("enabled");N_("enabled-runtime");N_("linked");N_("linked-runtime");N_("masked");N_("masked-runtime");N_("static");N_("disabled");N_("invalid");function d(i,a,o,r,s,c,l){var d,u,f;if(!o)o="";if(!r)r="";if(!s)s="";if(r=="failed"||o=="error")f=";color:red";else f="";if(o=="loaded")o="";d=r=="activating"||r=="deactivating"||r=="reloading";u=r=="active"||r=="reloading";o=_(o);r=_(r);s=_(s);c=_(c);if(s!==""&&s!=r)r=r+" ("+s+")";if(o!=="")r=o+" / "+r;var p=e("<tr>",{"data-unit":i}).click(function(){t.location.go("service",{s:i})}).append(e('<td style="font-weight:bold">').text(a),e("<td>").text(i),e("<td>",{style:"text-align:right;white-space:nowrap"+f}).text(r));if(l){var h=e('<div class="waiting">');var g=e('<button class="btn btn-default btn-control btn-play">').on("click",function(){l.call("ServiceAction",i,"start",function(e){if(e)n.show_unexpected_error(e)});return false});var m=e('<button class="btn btn-default btn-control btn-stop">').on("click",function(){l.call("ServiceAction",i,"stop",function(e){if(e)n.show_unexpected_error(e)});return false});h.toggle(d);g.toggle(!d&&!u);m.toggle(!d&&u);p.append(e('<td class="cell-buttons" style="padding-left:20px;padding-right:5px">').append(g,m,h));var v=l._client.target;var b=i.match(/ctr-(.*)\.service/);if(b){var k=e('<button class="btn btn-default btn-control btn-eject">').on("click",function(){t.spawn(["gear","delete",b[1]],{host:v}).fail(n.show_unexpected_error);return false});p.append(e('<td class="cell-buttons" style="padding-left:5px;padding-right:5px">').append(k))}}return p}u.prototype={_init:function(){this.id="services";this.geard_check_done=false;this.geard_present=false},getTitle:function(){return C_("page-title","Services")},setup:function(){var t=this;e("#services-add").click(function(){f.address=t.address;e("#service-add-dialog").modal("show")})},enter:function(){var i=this;i.address=n.get_page_machine();if(!i.geard_check_done){i.geard_check_done=true;t.spawn(["which","gear"],{host:i.address,error:"output"}).done(function(){i.geard_present=true;n.content_refresh()})}function a(t,n,i,a,o){var r=e('<label class="btn btn-default">').append(t,e("<input>",e.extend({id:n,type:"radio",name:"services-filter",value:i,checked:a?"checked":undefined},o)));if(a)r.addClass("active");return r}var r=null;if(i.geard_present){r=a(_("Services"),"services-filter-my-services","^ctr-.*\\.service$",true,{"data-show-graphs":true,"data-include-buttons":true})}e("#shell-header-extra").append(e('<div class="btn-group" data-toggle="buttons">').append(r,a(_("Targets"),"services-filter-targets","\\.target$",false),a(_("System Services"),"services-filter-services","\\.service$",!r),a(_("Sockets"),"services-filter-sockets","\\.socket$",false),a(_("Timers"),"services-filter-timers","\\.timer$",false),a(_("Paths"),"services-filter-paths","\\.path$",false)));e("#shell-header-extra input").on("change",function(e){i.update()});i.client=n.dbus(i.address);i.manager=i.client.get("/com/redhat/Cockpit/Services","com.redhat.Cockpit.Services");e(i.manager).on("ServiceUpdate.services",function(e,t){i.update_service(t[0],t[1],t[2],t[3],t[4],t[5])});e(i.manager).on("ServiceUpdateAll.services",function(e){i.update()});var s=["#006bb4","#008ff0","#2daaff","#69c2ff","#a5daff","#e1f3ff","#00243c","#004778"];i.monitor=i.client.get("/com/redhat/Cockpit/LxcMonitor","com.redhat.Cockpit.MultiResourceMonitor");function c(e){return e&&!!e.match("ctr-.*\\.service$")}function l(t,i){e("#services .list-group-item").removeClass("highlight");if(i){i=i.split("/").pop();e('[data-unit="'+n.esc(i)+'"]').addClass("highlight")}}this.cpu_plot=n.setup_multi_plot("#services-cpu-graph",i.monitor,4,s.concat(s),c);e(this.cpu_plot).on("update-total",function(t,n){e("#services-cpu-text").text(o(n))});e(this.cpu_plot).on("highlight",l);this.mem_plot=n.setup_multi_plot("#services-mem-graph",i.monitor,0,s.concat(s),c);e(this.mem_plot).on("update-total",function(n,i){e("#services-mem-text").text(t.format_bytes(i,1024))});e(this.mem_plot).on("highlight",l);e("#services-list-enabled, #services-list-disabled, #services-list-static").parents(".panel").hide();e("#services-list-enabled, #services-list-disabled, #services-list-static").empty();i.items={};i.update()},show:function(){if(e("#services-graphs").is(":visible")){this.cpu_plot.start();this.mem_plot.start()}},leave:function(){var t=this;this.cpu_plot.destroy();this.mem_plot.destroy();e(t.manager).off(".services");t.client.release();t.client=null;t.manager=null},update_service:function(t,n,i,a,o,r){var s=e('input[name="services-filter"]:checked').val();var c=e('input[name="services-filter"]:checked').attr("data-include-buttons")!==undefined;if(s&&t.match(s)){if(!c||i!="not-found"){var l=e(d(t,n,i,a,o,r,c?this.manager:null));if(this.items[t])this.items[t].replaceWith(l);else{if(r=="enabled"){l.appendTo(e("#services-list-enabled"));e("#services-list-enabled").parents(".panel").show()}else if(r=="disabled"){l.appendTo(e("#services-list-disabled"));e("#services-list-disabled").parents(".panel").show()}else{l.appendTo(e("#services-list-static"));e("#services-list-static").parents(".panel").show()}}this.items[t]=l}else{if(this.items[t])this.items[t].remove();delete this.items[t]}}},update:function(){var t=this;if(e('input[name="services-filter"]:checked').attr("data-show-graphs")!==undefined){e("#services-graphs").show();e("#services-add").show();if(e("#services-graphs").is(":visible")){this.cpu_plot.start();this.mem_plot.start()}}else{e("#services-graphs").hide();e("#services-add").hide();this.cpu_plot.stop();this.mem_plot.stop()}function n(e,t){return e[1].localeCompare(t[1])}function i(e){t.manager.call("GetServiceInfo",e,function(e,n){if(n){t.update_service(n.Id,n.Description,n.LoadState,n.ActiveState,n.SubState,n.UnitFileState)
}})}t.manager.call("ListServices",function(a,o){var r;var s;var c;if(a){console.log("error %s",a.message)}else{var l=e("#services-list-enabled"),u;var f=e("#services-list-disabled"),p;var h=e("#services-list-static"),g;var _;l.empty();u=false;f.empty();p=false;h.empty();g=false;t.items={};o.sort(n);r=e('input[name="services-filter"]:checked').val();c=e('input[name="services-filter"]:checked').attr("data-include-buttons")!==undefined;for(_=0;_<o.length;_++){s=o[_];if(!r||s[0].match(r)&&(s[2]!="not-found"||!c)){if(s[1]=="Unknown"&&t.manager)i(s[0]);var m=e(d(s[0],s[1],s[2],s[3],s[4],s[5],c?t.manager:null));if(t.items[s[0]]){t.items[s[0]].replaceWith(m)}else if(s[5]=="enabled"){m.appendTo(l);u=true}else if(s[5]=="disabled"){m.appendTo(f);p=true}else{m.appendTo(h);g=true}t.items[s[0]]=m}}l.parents(".panel").toggle(u);f.parents(".panel").toggle(p);h.parents(".panel").toggle(g)}})}};function u(){this._init()}n.pages.push(new u);f.prototype={_init:function(){this.id="service-add-dialog"},setup:function(){e("#service-add-add").click(e.proxy(this,"add"))},enter:function(){this.docker=n.docker(f.address);e(this.docker).on("image.services",e.proxy(this,"update"));e("#service-add-image, #service-add-name").val("");this.update()},show:function(){},leave:function(){e(n.docker).off(".services");this.docker.release();this.docker=null},update:function(){var t=e("#service-add-images");var n=[];for(var i in this.docker.images){var a=this.docker.images[i];if(a&&a.RepoTags&&a.RepoTags[0]!="<none>:<none>")n.push(a)}n.sort(function(e,t){var n=e.RepoTags[0];var i=t.RepoTags[0];return n>i?1:n<i?-1:0});t.html(n.map(function(t){return e('<a class="list-group-item">').text(t.RepoTags[0]).click(function(){e("#service-add-image").val(t.RepoTags[0])})}))},add:function(){e("#service-add-dialog").modal("hide");t.spawn(["gear","install","--has-foreground",e("#service-add-image").val(),e("#service-add-name").val()],{host:f.address}).fail(n.show_unexpected_error)}};function f(){this._init()}n.dialogs.push(new f);p.prototype={_init:function(){this.id="service";this.section_id="services"},getTitle:function(){return C_("page-title","Services")},setup:function(){var i=this;var a=[{title:_("Start"),action:"start",is_default:true},{title:_("Stop"),action:"stop"},{title:_("Restart"),action:"restart"},{title:_("Reload"),action:"reload"},{title:_("Reload or Restart"),action:"reload-or-restart"},{title:_("Try Restart"),action:"try-restart"},{title:_("Reload or Try Restart"),action:"reload-or-try-restart"},{title:_("Isolate"),action:"isolate"}];i.unit_action_btn=n.action_btn(function(e){i.action(e)},a);e("#service-unit-action-btn").html(i.unit_action_btn);var o=[{title:_("Enable"),action:"enable",is_default:true},{title:_("Enable Forcefully"),action:"force-enable"},{title:_("Disable"),action:"disable"},{title:_("Preset"),action:"preset"},{title:_("Preset Forcefully"),action:"force-preset"},{title:_("Mask"),action:"mask"},{title:_("Mask Forcefully"),action:"force-mask"},{title:_("Unmask"),action:"unmask"}];i.file_action_btn=n.action_btn(function(e){i.action(e)},o);e("#service-file-action-btn").html(i.file_action_btn);e("#service-refresh").on("click",function(){i.update()});e("#service-instantiate").on("click",function(){var n=i.service.indexOf("@");var a=i.service.lastIndexOf(".");if(n!=-1){var o=i.service.substring(0,n+1);o=o+l(e("#service-parameter").val());if(a!=-1)o=o+i.service.substring(a);t.location.go("service",{s:o})}})},enter:function(){var i=this;i.address=n.get_page_machine();i.client=n.dbus(i.address);i.manager=i.client.get("/com/redhat/Cockpit/Services","com.redhat.Cockpit.Services");e(i.manager).on("ServiceUpdate",function(e,t){if(t[0]==i.service)i.update()});e(i.manager).on("ServiceUpdateAll",function(){i.update()});i.service=n.get_page_param("s")||"";i.update();i.watch_journal();var a=["#006bb4","#008ff0","#2daaff","#69c2ff","#a5daff","#e1f3ff","#00243c","#004778"];i.monitor=i.client.get("/com/redhat/Cockpit/LxcMonitor","com.redhat.Cockpit.MultiResourceMonitor");function r(e){return e&&e.endsWith(i.service)}this.cpu_plot=n.setup_multi_plot("#service-cpu-graph",i.monitor,4,a.concat(a),r);e(this.cpu_plot).on("update-total",function(t,n){e("#service-cpu-text").text(o(n))});this.mem_plot=n.setup_multi_plot("#service-mem-graph",i.monitor,0,a.concat(a),r);e(this.mem_plot).on("update-total",function(n,i){e("#service-mem-text").text(t.format_bytes(i,1024))})},show:function(){this.cpu_plot.start();this.mem_plot.start()},leave:function(){this.cpu_plot.destroy();this.mem_plot.destroy();if(this.journal_watcher)this.journal_watcher.stop();delete this.journal_watcher;this.client.release();this.client=null},watch_journal:function(){this.journal_watcher=i.server.logbox(["_SYSTEMD_UNIT="+this.service,"+","COREDUMP_UNIT="+this.service,"+","UNIT="+this.service],10);e("#service-log").empty().append(this.journal_watcher)},update:function(){var i=this;var a=i.service.indexOf("@");var o=i.service.lastIndexOf(".");i.template=undefined;if(a!=-1&&a+1!=o&&a+1!=i.service.length){i.template=i.service.substring(0,a+1);if(o!=-1)i.template=i.template+i.service.substring(o)}e("#service .breadcrumb .active").text(i.service);function r(e,t,i){var a;if(i>0)e.append('<div class="list-group-item">'+n.esc(t[0])+"</div>");for(a=1;a<t.length;a++){if(true){e.append('<div class="list-group-item">'+n.esc(t[a].Pid)+" "+n.esc(t[a].CmdLine)+"</div>")}else{r(t[a],i+1)}}}i.manager.call("GetServiceInfo",i.service,function(a,o){if(a){e("#service-unknown").show();e("#service-known").hide();e("#service-name").text(i.service);return}e("#service-unknown").hide();e("#service-known").show();e("#service-name").text(o.Description||o.Id||"--");if(o.IsTemplate){e("#service-unit-row").hide();e("#service-instantiate-row").show()}else{e("#service-unit-row").show();e("#service-instantiate-row").hide();var s=o.ActiveState;var c=o.SubState;e("#service-active-state").text(_(s));e("#service-sub-state").text(_(c));var l;if(s=="active"||s=="reloading")l=o.ActiveEnterTimestamp;else if(s=="inactive"||s=="failed")l=o.InactiveEnterTimestamp;else if(s=="activating")l=o.InactiveExitTimestamp;else l=o.ActiveExitTimestamp;if(s=="active"||s=="reloading"||s=="activating")i.set_unit_action("stop");else i.set_unit_action("start");e("#service-since").text(new Date(l/1e3).toLocaleString())}if(i.template){e("#service-template-row").show();var d=t.format(_("This service is an instance of the $template service template."),{template:t.format('<a class="cockpit-link" onclick="${cmd}">$title</a>',{cmd:n.esc("cockpit.location.go('service', "+JSON.stringify({s:i.template})+");"),title:n.esc(i.template)})});e("#service-template-link").html(d)}else e("#service-template-row").hide();var u=o.LoadState;var f=o.UnitFileState;e("#service-load-state").text(_(u));e("#service-file-row").show();e("#service-load-error-box").hide();e("#service-template-box").hide();e("#service-file-box").hide();if(o.IsTemplate){e("#service-template-box").show();e("#service-template-state").text(_(f))}else if(u=="error"){e("#service-load-error-box").show();e("#service-load-error").text(n.esc(o.LoadError[1]))}else{var p=o.SourcePath||o.FragmentPath;if(p||f){e("#service-file-box").show();e("#service-file").text(n.esc(p));e("#service-file-state").text(_(f))}else e("#service-file-row").hide()}if(u=="masked")i.set_file_action("unmask");else if(f=="static")i.set_file_action("mask");else if(f=="enabled")i.set_file_action("disable");else i.set_file_action("enable");var h=e("#service-processes");if(o.Processes){h.closest(".panel").show();h.empty();h.append('<div class="list-group-item"> '+_("CGroup")+": "+n.esc(o.DefaultControlGroup)+"</div>");r(h,o.Processes,0)}else{h.closest(".panel").hide()}})},set_unit_action:function(e){n.action_btn_select(this.unit_action_btn,e)},set_file_action:function(e){n.action_btn_select(this.file_action_btn,e)},action:function(e){if(!n.check_admin())return;this.manager.call("ServiceAction",this.service,e,function(e){if(e)n.show_error_dialog(_("Error"),e.message)})}};function p(){this._init()}n.pages.push(new p)})(jQuery,cockpit,shell,modules);var shell=shell||{};(function(e,t,n){function i(e){var t={};for(var n=0;n<e.length;n++)t[e[n]]=true;return t}var a=t.permission({group:"wheel"});n.check_admin=function b(e){if(!e)e=a;if(e.allowed===true){return true}else if(e.allowed===false){n.show_error_dialog(_("Not authorized"),_("You are not authorized for this operation."));return false}else{return true}};function o(e,t){var n=t.getObjectsFrom("/com/redhat/Cockpit/Accounts/");var i,a;for(i=0;i<n.length;i++){a=n[i].lookup("com.redhat.Cockpit.Account");if(a&&a.UserName==e)return a}return null}function r(e,t,i,a,o){var r=new window.Image;r.onerror=function(){n.show_error_dialog(_("Can't use this file"),_("Can't read it."))};r.onload=function(){e.width=a;e.height=e.width*(r.height/r.width);t.width=e.width;t.height=e.height;var n=e.getContext("2d");n.clearRect(0,0,e.width,e.height);n.drawImage(r,0,0,e.width,e.height);o()};r.src=i}function s(t,n,i,a,o,r,s,c){var l=e("<canvas/>")[0];l.width=r;l.height=s;var d,u;var f=a-n,p=o-i;if(f>p){d=r;u=d*(p/f)}else{u=s;d=u*(f/p)}var h=l.getContext("2d");h.drawImage(t,n,i,f,p,(r-d)/2,(s-u)/2,d,u);return l.toDataURL(c)}n.show_change_avatar_dialog=function k(t,i){var a,o,s;a=e(t)[0].files;if(a.length!=1)return;o=a[0];if(!o.type.match("image.*")){n.show_error_dialog(_("Can't upload this file"),_("It's not an image."));return}s=new window.FileReader;s.onerror=function(){n.show_error_dialog(_("Can't upload this file"),_("Can't read it."))};s.onload=function(){var t=e("#account-change-avatar-canvas")[0];var n=e("#account-change-avatar-overlay")[0];r(t,n,s.result,256,function(){h.callback=i;e("#account-change-avatar-dialog").modal("show")})};s.readAsDataURL(o)};function c(t,n,i){function a(e,t){if(t.objectPath.indexOf("/com/redhat/Cockpit/Accounts/")===0)i()}function o(e,t){if(t.objectPath.indexOf("/com/redhat/Cockpit/Accounts/")===0)i()}function r(e,t){if(t.objectPath.indexOf("/com/redhat/Cockpit/Accounts/")===0)i()}function s(e,t,n,a){if(t.getObject().objectPath.indexOf("/com/redhat/Cockpit/Accounts/")===0&&n=="Changed")i()}e(t).on("objectAdded."+n,a);e(t).on("objectRemoved."+n,o);e(t).on("propertiesChanged."+n,r);e(t).on("signalEmitted."+n,s)}function l(t,n){e(t).off("."+n)}d.prototype={_init:function(){this.id="accounts"},getTitle:function(){return C_("page-title","Accounts")},show:function(){},setup:function(){e("#accounts-create").on("click",e.proxy(this,"create"))},enter:function(){this.address=n.get_page_machine();this.client=n.dbus(this.address);c(this.client,"accounts",e.proxy(this,"update"));this.update()},leave:function(){l(this.client,"accounts");this.client.release();this.client=null},update:function(){var t=e("#accounts-list");var n=this.client.getObjectsFrom("/com/redhat/Cockpit/Accounts/");var i,a;this.accounts=[];for(i=0;i<n.length;i++){a=n[i].lookup("com.redhat.Cockpit.Account");if(a)this.accounts.push(a)}this.accounts.sort(function(e,t){return e.RealName.localeCompare(t.RealName)});function o(e,t){e.call("GetIconDataURL",function(e,n){if(n)t.attr("src",n)})}t.empty();for(i=0;i<this.accounts.length;i++){a=this.accounts[i];var r=e("<img/>",{"class":"cockpit-account-pic",width:"48",height:"48",src:"/cockpit/@@shell@@/images/avatar-default-48.png"});var s=e("<div/>",{"class":"cockpit-account"}).append(r,e("<div/>",{"class":"cockpit-account-real-name"}).text(a.RealName),e("<div/>",{"class":"cockpit-account-user-name"}).text(a.UserName));s.on("click",e.proxy(this,"go",a.UserName));o(a,r);t.append(s)}},create:function(){if(n.check_admin()){u.client=this.client;e("#accounts-create-dialog").modal("show")}},go:function(e){t.location.go("account",{id:e})}};function d(){this._init()}n.pages.push(new d);u.prototype={_init:function(){this.error_timeout=null;this.id="accounts-create-dialog"},show:function(){},setup:function(){e("#accounts-create-cancel").on("click",e.proxy(this,"cancel"));e("#accounts-create-create").on("click",e.proxy(this,"create"));e("#accounts-create-dialog .check-passwords").on("keydown",e.proxy(this,"update","keydown"));e("#accounts-create-dialog .check-passwords").on("input",e.proxy(this,"update","input"));e("#accounts-create-dialog input").on("focusout change",e.proxy(this,"update","changeFocus"))},enter:function(){e("#accounts-create-user-name").val("");e("#accounts-create-real-name").val("");e("#accounts-create-pw1").val("");e("#accounts-create-pw2").val("");e("#accounts-create-locked").prop("checked",false);e("#accounts-create-message-password-mismatch").css("visibility","hidden");e("#account-set-password-dialog .check-passwords").removeClass("has-error");this.update()},leave:function(){},update:function(t){function n(){return e("#accounts-create-user-name").val()!==""&&e("#accounts-create-real-name").val()!==""&&e("#accounts-create-pw1").val()!==""&&e("#accounts-create-pw2").val()==e("#accounts-create-pw1").val()}function i(){e("#accounts-create-dialog .check-passwords").addClass("has-error");e("#accounts-create-message-password-mismatch").css("visibility","visible")}function a(){e("#accounts-create-dialog .check-passwords").removeClass("has-error");e("#accounts-create-message-password-mismatch").css("visibility","hidden")}function o(){if(e("#accounts-create-pw2").val()!==""&&e("#accounts-create-pw1").val()!==e("#accounts-create-pw2").val())i();else a()}window.clearTimeout(this.error_timeout);this.error_timeout=null;if(t=="changeFocus"){if(e("#accounts-create-pw2").val()!==""&&e("#accounts-create-pw1").val()!==e("#accounts-create-pw2").val())i();else a()}else if(t=="input"){if(e("#accounts-create-pw2").val()!==""&&!e("#accounts-create-pw1").val().startsWith(e("#accounts-create-pw2").val()))i();else a();this.error_timeout=window.setTimeout(o,2e3);this.setTimeout=null}e("#accounts-create-create").prop("disabled",!n())},cancel:function(){e("#accounts-create-dialog").modal("hide")},create:function(){e("#accounts-create-dialog").modal("hide");var t=u.client.get("/com/redhat/Cockpit/Accounts","com.redhat.Cockpit.Accounts");t.call("CreateAccount",e("#accounts-create-user-name").val(),e("#accounts-create-real-name").val(),e("#accounts-create-pw1").val(),e("#accounts-create-locked").prop("checked"),function(e){if(e)n.show_unexpected_error(e)})}};function u(){this._init()}n.dialogs.push(new u);f.prototype={_init:function(){this.id="account";this.section_id="accounts"},getTitle:function(){return C_("page-title","Accounts")},show:function(){},setup:function(){e("#account-pic").on("click",e.proxy(this,"trigger_change_avatar"));e("#account-avatar-uploader").on("change",e.proxy(this,"change_avatar"));e("#account-real-name").on("change",e.proxy(this,"change_real_name"));e("#account-real-name").on("keydown",e.proxy(this,"real_name_edited"));e("#account-set-password").on("click",e.proxy(this,"set_password"));e("#account-delete").on("click",e.proxy(this,"delete_account"));e("#account-logout").on("click",e.proxy(this,"logout_account"));e("#account-change-roles").on("click",e.proxy(this,"change_roles"));e("#account-locked").on("change",e.proxy(this,"change_locked"))},enter:function(){this.address=n.get_page_machine();this.client=n.dbus(this.address);c(this.client,"account",e.proxy(this,"update"));this.real_name_dirty=false;this.update()},leave:function(){l(this.client,"account");this.client.release();this.client=null},update:function(){this.account=o(n.get_page_param("id"),this.client);if(this.account){var t=this.client.get("/com/redhat/Cockpit/Accounts","com.redhat.Cockpit.Accounts");this.sys_roles=t.Roles||[];this.account.call("GetIconDataURL",function(t,n){if(n)e("#account-pic").attr("src",n)});e("#account-pic").attr("src","/cockpit/@@shell@@/images/avatar-default-128.png");if(!this.real_name_dirty)e("#account-real-name").val(this.account.RealName);e("#account-user-name").text(this.account.UserName);if(this.account.LoggedIn)e("#account-last-login").text(_("Logged In"));else if(this.account.LastLogin===0)e("#account-last-login").text(_("Never"));else e("#account-last-login").text(new Date(this.account.LastLogin*1e3).toLocaleString());e("#account-locked").prop("checked",this.account.Locked);var a=i(this.account.Groups);var r="";for(var s=0;s<this.sys_roles.length;s++){if(this.sys_roles[s][0]in a){if(r!=="")r+="<br/>";r+=n.esc(this.sys_roles[s][1])}}e("#account-roles").html(r);e("#account .breadcrumb .active").text(this.account.RealName)}else{e("#account-pic").attr("src",null);e("#account-real-name").val("");e("#account-user-name").text("");e("#account-last-login").text("");e("#account-locked").prop("checked",false);e("#account-roles").text("");e("#account .breadcrumb .active").text("?")}},trigger_change_avatar:function(){if(!this.check_role_for_self_mod())return;if(window.File&&window.FileReader)e("#account-avatar-uploader").trigger("click")},change_avatar:function(){var e=this;n.show_change_avatar_dialog("#account-avatar-uploader",function(t){e.account.call("SetIconDataURL",t,function(e){if(e)n.show_unexpected_error(e)})})},real_name_edited:function(){this.real_name_dirty=true},check_role_for_self_mod:function(){return this.account.UserName==t.user["user"]||n.check_admin()},change_real_name:function(){var t=this;this.real_name_dirty=false;if(!t.check_role_for_self_mod()){t.update();return}this.account.call("SetRealName",e("#account-real-name").val(),function(e){if(e){n.show_unexpected_error(e);t.update()}})},change_locked:function(){var t=this;if(!n.check_admin()){t.update();return}this.account.call("SetLocked",e("#account-locked").prop("checked"),function(e){if(e){n.show_unexpected_error(e);t.update()}})},set_password:function(){if(!this.check_role_for_self_mod())return;v.account=this.account;v.user_name=null;e("#account-set-password-dialog").modal("show")},delete_account:function(){if(!n.check_admin())return;m.account=this.account;e("#account-confirm-delete-dialog").modal("show")},logout_account:function(){var e=this;if(!n.check_admin())return;this.account.call("KillSessions",function(t){if(t){n.show_unexpected_error(t);e.update()}})},change_roles:function(){if(!n.check_admin())return;g.account=this.account;e("#account-change-roles-dialog").modal("show")}};function f(){this._init()}n.pages.push(new f);var p=20;h.prototype={_init:function(){this.id="account-change-avatar-dialog"},show:function(){},setup:function(){var t=this;e("#account-change-avatar-cancel").on("click",e.proxy(this,"cancel"));e("#account-change-avatar-apply").on("click",e.proxy(this,"apply"));var n=e("#account-change-avatar-overlay");this.canvas=n[0];this.canvas2d=this.canvas.getContext("2d");n.on("mousedown",function(i){var a=n.offset();var o=i.pageX-a.left-t.crop_x;var r=i.pageY-a.top-t.crop_y;var s=t.crop_x;var c=t.crop_y;var l=t.crop_s;var d,u,f,h;var g=p;if(o>0&&r>0&&o<t.crop_s&&r<t.crop_s){if(o<g&&r<g){d=1;u=1;f=1;h=-1}else if(o>t.crop_s-g&&r<g){d=-1;u=0;f=-1;h=1}else if(o<g&&r>t.crop_s-g){d=-1;u=1;f=0;h=-1}else if(o>t.crop_s-g&&r>t.crop_s-g){d=1;u=0;f=0;h=1}else{d=0}e("body").on("mousemove",function(e){var n=e.pageX-a.left-o;var i=e.pageY-a.top-r;if(d===0)t.set_crop(n,i,l,true);else{var p=Math.floor((n-s+d*(i-c))/2);t.set_crop(s+u*p,c+f*p,l+h*p,false)}});e("body").on("mouseup",function(t){e("body").off("mouseup");e("body").off("mousemove")})}})},enter:function(){var e=this;var t=Math.min(this.canvas.width,this.canvas.height);this.set_crop((this.canvas.width-t)/2,(this.canvas.height-t)/2,t,true)},leave:function(){},set_crop:function(e,t,n,i){function a(e,t,n){if(t<e)return e;if(t>n)return n;return t}e=Math.floor(e);t=Math.floor(t);n=Math.floor(n);var o=2*p;if(i){n=a(o,n,Math.min(this.canvas.width,this.canvas.height));e=a(0,e,this.canvas.width-n);t=a(0,t,this.canvas.height-n)}else if(e<0||t<0||e+n>this.canvas.width||t+n>this.canvas.height||n<o)return;this.crop_x=e;this.crop_y=t;this.crop_s=n;this.draw_crop(e,t,e+n,t+n)},draw_crop:function(e,t,n,i){var a;function o(e,t,n,i){a.strokeStyle="black";a.strokeRect(e+.5,t+.5,n-e-1,i-t-1);a.strokeStyle="white";a.strokeRect(e+1.5,t+1.5,n-e-3,i-t-3)}a=this.canvas2d;a.clearRect(0,0,this.canvas.width,this.canvas.height);a.fillStyle="rgba(0,0,0,0.8)";a.fillRect(0,0,this.canvas.width,this.canvas.height);a.clearRect(e,t,n-e,i-t);var r=p;o(e,t,e+r,t+r);o(n-r,t,n,t+r);o(e,i-r,e+r,i);o(n-r,i-r,n,i);o(e,t,n,i)},cancel:function(){e("#account-change-avatar-dialog").modal("hide")},apply:function(){var t=s(e("#account-change-avatar-canvas")[0],this.crop_x,this.crop_y,this.crop_x+this.crop_s,this.crop_y+this.crop_s,128,128,"image/png");e("#account-change-avatar-dialog").modal("hide");h.callback(t)}};function h(){this._init()}n.dialogs.push(new h);g.prototype={_init:function(){this.id="account-change-roles-dialog"},show:function(){},setup:function(){e("#account-change-roles-apply").on("click",e.proxy(this,"apply"))},enter:function(){var t,n,a,o;this.client=g.account._client;var r=this.client.get("/com/redhat/Cockpit/Accounts","com.redhat.Cockpit.Accounts");this.sys_roles=r.Roles||[];var s=e("<ul/>",{"class":"list-group"});for(o=0;o<this.sys_roles.length;o++){n=this.sys_roles[o][0];s.append(e("<li>",{"class":"list-group-item"}).append(e("<div>",{"class":"checkbox",style:"margin:0px"}).append(e("<input/>",{type:"checkbox",name:"account-role-checkbox-"+n,id:"account-role-checkbox-"+n}),e("<label/>",{"for":"account-role-checkbox-"+n}).text(this.sys_roles[o][1]))))}var c=e("#account-change-roles-roles");c.empty();c.append(s);t=i(g.account.Groups);this.roles={};for(o=0;o<this.sys_roles.length;o++){n=this.sys_roles[o][0];if(n in t)this.roles[n]=true;e("#account-role-checkbox-"+n).prop("checked",this.roles[n]?true:false)}},leave:function(){},apply:function(){var t,i,a;var o=[];var r=[];for(t=0;t<this.sys_roles.length;t++){i=this.sys_roles[t][0];a=e("#account-role-checkbox-"+i).prop("checked");if(a&&!this.roles[i])o.push(i);else if(!a&&this.roles[i])r.push(i)}g.account.call("ChangeGroups",o,r,function(e){if(e)n.show_unexpected_error(e)});e("#account-change-roles-dialog").modal("hide")}};function g(){this._init()}n.dialogs.push(new g);m.prototype={_init:function(){this.id="account-confirm-delete-dialog"},show:function(){},setup:function(){e("#account-confirm-delete-apply").on("click",e.proxy(this,"apply"))},enter:function(){e("#account-confirm-delete-files").prop("checked",false);e("#account-confirm-delete-title").text(t.format(_("Delete $0"),m.account.UserName))},leave:function(){},apply:function(){m.account.call("Delete",e("#account-confirm-delete-files").prop("checked"),function(e){if(e)n.show_unexpected_error(e)});e("#account-confirm-delete-dialog").modal("hide");t.location="accounts"}};function m(){this._init()}n.dialogs.push(new m);v.prototype={_init:function(){this.error_timeout=null;this.id="account-set-password-dialog"},show:function(){e("#account-set-password-pw1").focus()},setup:function(){e("#account-set-password-apply").on("click",e.proxy(this,"apply"));e("#account-set-password-dialog .check-passwords").on("keydown",e.proxy(this,"update","keydown"));e("#account-set-password-dialog .check-passwords").on("input",e.proxy(this,"update","input"));e("#account-set-password-dialog input").on("focusout change",e.proxy(this,"update","changeFocus"))},enter:function(){e("#account-set-password-pw1").val("");e("#account-set-password-pw2").val("");e("#account-set-password-message-password-mismatch").css("visibility","hidden");e("#account-set-password-dialog .check-passwords").removeClass("has-error");this.update()},leave:function(){},update:function(t){function n(){return e("#account-set-password-pw1").val()!==""&&e("#account-set-password-pw2").val()==e("#account-set-password-pw1").val()}function i(){e("#account-set-password-dialog .check-passwords").addClass("has-error");e("#account-set-password-message-password-mismatch").css("visibility","visible")}function a(){e("#account-set-password-dialog .check-passwords").removeClass("has-error");e("#account-set-password-message-password-mismatch").css("visibility","hidden")}function o(){if(e("#account-set-password-pw2").val()!==""&&e("#account-set-password-pw1").val()!==e("#account-set-password-pw2").val())i();else a()}window.clearTimeout(this.error_timeout);this.error_timeout=null;if(t=="changeFocus"){if(e("#account-set-password-pw2").val()!==""&&e("#account-set-password-pw1").val()!==e("#account-set-password-pw2").val())i();else a()}else if(t=="input"){if(e("#account-set-password-pw2").val()!==""&&!e("#account-set-password-pw1").val().startsWith(e("#account-set-password-pw2").val()))i();else a();this.error_timeout=window.setTimeout(o,2e3);this.setTimeout=null}e("#account-set-password-apply").prop("disabled",!n())},apply:function(){e("#account-set-password-dialog").modal("hide");if(v.account){v.account.call("SetPassword",e("#account-set-password-pw1").val(),function(e){if(e)n.show_unexpected_error(e)})}else if(v.user_name){t.spawn(["passwd","--stdin",v.user_name]).write(e("#account-set-password-pw1").val()).fail(n.show_unexpected_error)}}};function v(){this._init()}n.dialogs.push(new v);n.change_password=function y(){v.account=null;v.user_name=t.user["user"];e("#account-set-password-dialog").modal("show")}})(jQuery,cockpit,shell);var shell=shell||{};var modules=modules||{};(function(e,t,n,i){function a(){if(window.debugging=="all"||window.debugging=="resource")console.debug.apply(console,arguments)}function o(){if(window.debugging=="all"||window.debugging=="docker")console.debug.apply(console,arguments)}var r=n.util.make_resource_cache();n.docker=s;function s(e){return r.get(e,function(){return new A(e)})}function c(e){return i.docker.quote_cmdline(e||[])}function l(e){return i.docker.unquote_cmdline(e)}function d(e){if(e.Config)return c((e.Config.Entrypoint||[]).concat(e.Config.Cmd||[]));else return e.Command}function u(e){if(e.length>0&&e[0]=="/")return e.slice(1);else return e}function f(e){if(e.Running)return t.format(_("Up since $StartedAt"),e);else return t.format(_("Exited $ExitCode"),e)}function p(e){return e.map(n.esc).join("<br/>")}function h(e){if(!e)return _("default");return t.format(_("$0 shares"),Math.round(e))}function g(e){if(e===undefined||isNaN(e))return"";return Math.round(e)+"%"}function m(t,n,i){var a=[n];if(i)a.push(i);e(t).attr("value",a.join("/")).toggleClass("bar-row-danger",!!(i&&n>.9*i))}function v(e,n){var i="";var a=1024;var o;if(n){o=t.format_bytes(n,a,true);i=" / "+o.join(" ");a=o[1]}if(e){o=t.format_bytes(e,a,true);if(i)return o[0]+i;else return o.join(" ")}else{return"?"+i}}function b(e,t){k(e,t,function(e,t){return e.text().localeCompare(t.text())})}function k(t,n,i){var a=e(t).find("tbody tr");for(var o=0;o<a.length;o++){if(i(e(a[o]),n)>0){e(n).insertBefore(a[o]);n=null;break}}if(n!==null)e(t).find("tbody").append(n)}function y(n,i,a){var o=this;var r,s;var c;function l(){if(r.disabled){c=undefined;return _("unlimited")}c=Math.round(r.value*a);if(c<i)c=i;return t.format_bytes(c,1024)}r=n.find("div.slider").on("change",function(){e(s).text(l())})[0];s=n.find("span")[0];var d=n.find("input[type='checkbox']").on("change",function(){e(r).attr("disabled",!this.checked);e(s).toggleClass("disabled",!this.checked);e(s).text(l())})[0];Object.defineProperty(this,"value",{get:function(){return c},set:function(t){if(t!==undefined){e(r).prop("value",t/a).trigger("change")}e(d).prop("checked",t!==undefined).trigger("change")}});Object.defineProperty(this,"max",{get:function(){return a},set:function(t){var n=a;a=t;e(r).prop("value",r.value*n/a).trigger("change")}});return this}function w(t,n,i){var a=this;var o,r;var s;var c=Math.log(n);var l=Math.log(i);var d=l-c;function u(){if(o.disabled)s=undefined;else s=Math.round(Math.exp(c+d*o.value));return h(s)}o=t.find("div.slider").on("change",function(){e(r).text(u())})[0];r=t.find("span")[0];var f=t.find("input[type='checkbox']").on("change",function(){e(o).attr("disabled",!this.checked);e(r).toggleClass("disabled",!this.checked);e(r).text(u())});Object.defineProperty(this,"value",{get:function(){return s},set:function(t){if(t!==undefined){e(o).prop("value",(Math.log(t)-c)/d).trigger("change")}e(f).prop("checked",t!==undefined).trigger("change")}});return this}function x(n,i,a){var o=e("#containers-failure");var r=e("#"+n.id);function s(n){var i;var a=false;console.warn(n);if(typeof n=="string")i=n;else if(n.problem=="not-found"){i=_("Docker is not installed or activated on the system");a=true}else if(n.problem=="not-authorized")i=_("Not authorized to access Docker on this system");else i=t.format(_("Can't connect to Docker: $0"),n.toString());e("#containers-failure-message").text(i);e("#containers-failure-start").toggle(a);e("#containers-failure-retry").toggle(!a);r.children().hide();o.show()}function c(){r.children().show();o.hide()}e(i).on("failure.failure",function(e,t){if(t.problem!="disconnected")s(t,n)});e("#containers-failure-retry").on("click.failure",function(){i.close();i.connect().done(function(){c();n.show()})});e("#containers-failure-start").on("click.failure",function(){t.spawn(["systemctl","start","docker.socket"],{host:a,superuser:true}).done(function(){i.close();i.connect().done(function(){c();n.show()})}).fail(function(e){s(t.format(_("Failed to start Docker: $0"),e))})});r.prepend(o);c();i.maybe_reconnect()}function C(t){e(t).off(".failure");e("#containers-failure-start").off(".failure")}function S(i,a,o,r,s,c,l){var f=e("#"+r+s);if(!c){f.remove();if(!a.find("table > tbody > tr").length){a.find("button.enable-danger").toggle(false)}return}var p;var h,k;var y,w,x;var C;if(c.State&&c.State.Running){p=g(c.CpuUsage);h=c.MemoryUsage||0;k=c.MemoryLimit||0;w=v(h,k);y=true;x={color:"inherit"}}else{p="";y=false;w=_("Stopped");x={color:"grey","text-align":"right"}}var S=false;if(!f.length){a.find("button.enable-danger").toggle(true);var D=e('<div class="waiting">');var j=e('<button class="btn btn-danger pficon pficon-delete btn-delete">').on("click",function(){var t=this;e(t).hide().siblings("div.waiting").show();i.rm(s,true).fail(function(i){n.show_unexpected_error(i);e(t).show().siblings("div.waiting").hide()});return false});var N=e('<button class="btn btn-default btn-control btn-play">').on("click",function(){e(this).hide().siblings("div.waiting").show();i.start(s).fail(function(e){n.show_unexpected_error(e)});return false});var M=e('<button class="btn btn-default btn-control btn-stop">').on("click",function(){e(this).hide().siblings("div.waiting").show();i.stop(s).fail(function(e){n.show_unexpected_error(e)});return false});f=e('<tr id="'+r+s+'">').append(e('<td class="container-col-name">'),e('<td class="container-col-image">'),e('<td class="container-col-command">'),e('<td class="container-col-cpu">'),e('<td class="container-col-memory-graph">').append(n.BarRow("containers-containers")),e('<td class="container-col-memory-text">'),e('<td class="container-col-danger cell-buttons">').append(j,D),e('<td class="container-col-actions cell-buttons">').append(N,M,D.clone()));f.on("click",function(e){t.location.go("container-details",{id:s})});S=true}var R=f.children("td");e(R[0]).text(u(c.Name));e(R[1]).text(c.Image);e(R[2]).text(d(c));e(R[3]).text(p);m(e(R[4]).children("div").toggle(y),h,k);e(R[5]).css(x).text(w);var P=s in i.waiting;e(R[6]).children("div.waiting").toggle(P);e(R[6]).children("button.btn-delete").toggle(!P).toggleClass("disabled",c.State.Running);var A=P||c.State.Running?"You can only delete<br/> stopped containers":"Delete immediately";e(R[6]).children("button.btn-delete").tooltip("destroy").attr("title",A).tooltip({html:true});e(R[7]).children("div.waiting").toggle(P);e(R[7]).children("button.btn-play").toggle(!P&&!c.State.Running);e(R[7]).children("button.btn-stop").toggle(!P&&c.State.Running);e(R[6]).toggle(l);e(R[7]).toggle(!l);if(o){var I=n.select_btn_selected(o);f.toggleClass("unimportant",!c.State.Running)}if(S)b(a.find("table"),f)}function D(t,n,i){var a=e('<button class="btn btn-default btn-control fa fa-check enable-danger">').toggle(false).on("click",i);e(t+" th.container-col-actions").append(a);e(n)[0].addEventListener("click",function(n){if(e(n.target).parents(t).length===0&&e(t+" button.enable-danger").hasClass("active"))i()},true)}j.prototype={_init:function(){this.id="containers";
-this.danger_enabled=false},getTitle:function(){return C_("page-title","Containers")},toggle_danger:function(t){var n=this;n.danger_enabled=t;e("#containers-containers button.enable-danger").toggleClass("active",n.danger_enabled);e("#containers-containers td.container-col-actions").toggle(!n.danger_enabled);e("#containers-containers td.container-col-danger").toggle(n.danger_enabled)},setup:function(){var t=this;D("#containers-containers","#"+this.id,function(){t.toggle_danger(!t.danger_enabled)});this.container_filter_btn=n.select_btn(e.proxy(this,"filter"),[{title:_("All"),choice:"all",is_default:true},{title:_("Running"),choice:"running"}]);e("#containers-containers .panel-heading span").append(this.container_filter_btn);e("#containers-images-search").on("click",function(){M.display();return false})},enter:function(){var i=this;this.address=n.get_page_machine();this.client=n.docker(this.address);this.dbus_client=n.dbus(this.address);var a=["#250304","#5c080c","#970911","#ce0e15","#ef2930","#f36166","#f7999c","#fbd1d2"];var o=["#006bb4","#008ff0","#2daaff","#69c2ff","#a5daff","#e1f3ff","#00243c","#004778"];function r(t,n){n=i.client.container_from_cgroup(n)||n;e("#containers-containers tr").removeClass("highlight");e("#"+n).addClass("highlight")}this.cpu_plot=this.client.setup_cgroups_plot("#containers-cpu-graph",4,o.concat(o));e(this.cpu_plot).on("update-total",function(t,n){e("#containers-cpu-text").text(g(n))});e(this.cpu_plot).on("highlight",r);this.mem_plot=this.client.setup_cgroups_plot("#containers-mem-graph",0,o.concat(o));e(this.mem_plot).on("update-total",function(n,i){e("#containers-mem-text").text(t.format_bytes(i,1024))});e(this.mem_plot).on("highlight",r);e("#containers-containers table tbody tr").remove();e("#containers-images table tbody tr").remove();e(this.client).on("container.containers",function(e,t,n){i.render_container(t,n)});e(this.client).on("image.containers",function(e,t,n){i.render_image(t,n)});var s;e("#containers-containers button.enable-danger").toggle(false);for(s in this.client.containers){this.render_container(s,this.client.containers[s])}for(s in this.client.images){this.render_image(s,this.client.images[s])}x(i,i.client,i.address)},show:function(){this.cpu_plot.start();this.mem_plot.start()},leave:function(){C(this.client);this.dbus_client.release();this.dbus_client=null;this.cpu_plot.destroy();this.mem_plot.destroy();e(this.client).off(".containers");this.client.release();this.client=null},render_container:function(t,n){S(this.client,e("#containers-containers"),this.container_filter_btn,"",t,n,this.danger_enabled)},render_image:function(n,i){var a=this;var o=e("#"+n);if(!i||!i.RepoTags||i.RepoTags[0]=="<none>:<none>"){o.remove();return}var r=false;if(!o.length){var s=e('<button class="btn btn-default btn-control btn-play">').on("click",function(){N.display(a.client,n);return false});o=e('<tr id="'+n+'">').append(e('<td class="image-col-tags">'),e('<td class="image-col-created">'),e('<td class="image-col-size-graph">'),e('<td class="image-col-size-text">'),e('<td class="cell-buttons">').append(s));o.on("click",function(e){t.location.go("image-details",{id:n})});r=true}var c=o.children("td");e(c[0]).html(p(i.RepoTags));var l=new Date(i.Created*1e3);l.setDate(l.getDate()+2);if(l>new Date){e(c[1]).text(new Date(i.Created*1e3).toLocaleString())}else{var d=new Date(i.Created*1e3);e(c[1]).text(d.toLocaleDateString()).attr("title",d.toLocaleString())}e(c[2]).children("div").attr("value",i.VirtualSize);e(c[3]).text(t.format_bytes(i.VirtualSize,1024));if(r){b(e("#containers-images table"),o)}},filter:function(){var t=n.select_btn_selected(this.container_filter_btn);e("#containers-containers table").toggleClass("filter-unimportant",t==="running")}};function j(){this._init()}n.pages.push(new j);N.prototype={_init:function(){this.id="containers_run_image_dialog"},show:function(){},leave:function(){},setup:function(){e("#containers-run-image-run").on("click",e.proxy(this,"run"));this.memory_slider=new y(e("#containers-run-image-memory"),10*1024*1024,2*1024*1024*1024);this.cpu_slider=new w(e("#containers-run-image-cpu"),2,1e6);var t=e("#containers_run_image_dialog .modal-body table");this.run_portmapping=e('<div class="containers-run-portmapping">');this.portmapping_checkbox=e('<input type="checkbox" checked>');t.append(e("<tr>").append(e("<td>").text("Ports")).append(e('<td colspan="3">').append(this.portmapping_checkbox).append("Expose container ports").append(this.run_portmapping)));this.portmapping_checkbox.on("click",function(){if(e(this).prop("checked"))e(".containers-run-portmapping").show();else e(".containers-run-portmapping").hide()})},enter:function(){var t=this;var n=N.image_info;o("run-image",n);var i;var a;N.client.machine_info().done(function(e){t.memory_slider.max=e.memory});if(n.container_config.Memory){this.memory_slider.value=n.config_container.Memory}else{this.memory_slider.value=512*1024*1024;this.memory_slider.value=undefined}if(n.container_config.CpuShares){this.cpu_slider.value=n.container_config.CpuShares}else{this.cpu_slider.value=1024;this.cpu_slider.value=undefined}var r=["happy","jolly","dreamy","sad","angry","pensive","focused","sleepy","grave","distracted","determined","stoic","stupefied","sharp","agitated","cocky","tender","goofy","furious","desperate","hopeful","compassionate","silly","lonely","condescending","naughty","kickass","drunk","boring","nostalgic","ecstatic","insane","cranky","mad","jovial","sick","hungry","thirsty","elegant","backstabbing","clever","trusting","loving","suspicious","berserk","high","romantic","prickly","evil"];var s=["lovelace","franklin","tesla","einstein","bohr","davinci","pasteur","nobel","curie","darwin","turing","ritchie","torvalds","pike","thompson","wozniak","galileo","euclid","newton","fermat","archimedes","poincare","heisenberg","feynman","hawking","fermi","pare","mccarthy","engelbart","babbage","albattani","ptolemy","bell","wright","lumiere","morse","mclean","brown","bardeen","brattain","shockley"];function l(){function e(e){return e[Math.round(Math.random()*(e.length-1))]}return e(r)+"_"+e(s)}e("#containers-run-image").text(N.image_info.RepoTags[0]);e("#containers-run-image-name").val(l());e("#containers-run-image-command").val(c(N.image_info.config.Cmd));function d(t,n,i,a){if(t===undefined)t="";if(n===undefined)n="TCP";if(i===undefined)i=true;if(a===undefined)a="";var o=e('<input type="text" class="form-control">');var r=e('<input type="text" class="form-control">');var s=e('<select class="form-control selectpicker" data-width="60px">').append(e("<option>").text(_("TCP"))).append(e("<option>").text(_("UDP")));var c=e('<button type="button" class="btn btn-default fa fa-plus">');var l=e('<button type="button" class="btn btn-default pficon-close">');if(i){l.on("click",function(){var t=e(this).closest("form");if(t.parent().children().length>1){t.remove()}else{t.find("input").each(function(){e(this).val("")});t.find("select").selectpicker("val",_("TCP"))}})}else{o.prop("disabled",true);s.prop("disabled",true);l.prop("disabled",true)}var d={};d.html=e('<form class="form-inline">').append(e('<div class="form-group">').append(o)).append(s).append(e('<div class="form-group">').append(e("<label>").html(" &nbsp;to host port")).append(r)).append(c).append(l);o.attr("placeholder",_("none"));o.val(t);s.selectpicker("refresh");if(n.toUpperCase()===_("UDP"))s.selectpicker("val",_("UDP"));else s.selectpicker("val",_("TCP"));r.attr("placeholder",_("none"));r.val(a);d.elements={add:c};return d}function u(t,n,i,a,o,r){var s=d(i,a,o,r);if(n===undefined||n.length<1)t.append(s.html);else s.html.insertAfter(n);s.elements.add.on("click",function(){u(t,e(this).closest("form"))})}this.run_portmapping.empty();for(var f in N.image_info.config.ExposedPorts){u(this.run_portmapping,undefined,parseInt(f),f.slice(-3),false)}if(this.run_portmapping.children().length<1)u(this.run_portmapping);this.portmapping_checkbox.prop("checked",true)},run:function(){var t=e("#containers-run-image-name").val();var i=e("#containers-run-image-command").val();var a={};var o,r;var s,c,d;var u={};if(this.portmapping_checkbox.prop("checked")){this.run_portmapping.children("form").each(function(){var t=e(this).find("input").map(function(t,n){return e(n).val()}).get();s=t[0];c=t[1];d=e(this).find("select").val().toLowerCase();if(s===""||c==="")return;a[s+"/"+d]=[{HostPort:c}];u[s+"/"+d]={}})}e("#containers_run_image_dialog").modal("hide");var f=e("#containers-run-image-with-terminal").prop("checked");var p={Cmd:l(i),Image:N.image_info.id,Memory:this.memory_slider.value||0,MemorySwap:this.memory_slider.value*2||0,CpuShares:this.cpu_slider.value||0,Tty:f,ExposedPorts:u};if(f){e.extend(p,{AttachStderr:true,AttachStdin:true,AttachStdout:true,OpenStdin:true,StdinOnce:true})}N.client.create(t,p).fail(function(e){n.show_unexpected_error(e)}).done(function(e){N.client.start(e.Id,{PortBindings:a}).fail(function(e){n.show_unexpected_error(e)})})}};N.display=function(t,n){N.image_info=t.images[n];N.client=t;e("#containers_run_image_dialog").modal("show")};function N(){this._init()}n.dialogs.push(new N);M.prototype={_init:function(){this.id="containers-search-image-dialog"},show:function(){e("#containers-search-image-search").focus()},leave:function(){this.cancel_search();e(this.client).off(".containers-search-image-dialog");this.client.release();this.client=null},setup:function(){e("#containers-search-image-search").on("keypress",e.proxy(this,"input"));e("#containers-search-image-search").attr("placeholder","search by name, namespace or description");e("#containers-search-download").on("click",e.proxy(this,"start_download"));e("#containers-search-tag").prop("disabled",true);e("#containers-search-download").prop("disabled",true);this.search_timeout=null;this.search_request=null},enter:function(){this.address=n.get_page_machine();this.client=n.docker(this.address);e("#containers-search-image-results tbody tr").remove();e("#containers-search-image-results").hide();e("#containers-search-image-no-results").hide();e("#containers-search-image-search")[0].value=""},input:function(e){this.cancel_search();if(e.target.value.length<3&&e.which!=13)return;var t=this;this.search_timeout=window.setTimeout(function(){t.perform_search(t.client)},e.which==13?0:2e3)},start_download:function(t){var n=e("#containers-search-download").data("repo");var a=e("#containers-search-tag").val();e("#containers-search-tag").prop("disabled",true);e("#containers-search-download").data("repo","");e("#containers-search-download").prop("disabled",true);var o=e('<tr id="imagedl_'+n.replace("/","_")+'">').append(e('<td class="container-col-tags">').text(n+":"+a),e('<td class="container-col-created">').text("Downloading"),e('<td class="image-col-size-graph">').append(e('<div class="progress progress-striped active">').append(e('<div class="progress-bar" role="progressbar" aria-valuenow="1" aria-valuemin="0" aria-valuemax="1" style="width: 100%">'))),e('<td class="image-col-size-text">'),e('<td class="cell-buttons">'));b(e("#containers-images table"),o);var r=o.children("td").eq(1);var s=o.children("td").eq(2);var c=false;var l={};var d="";this.client.pull(n,a).stream(function(e){d+=e;var t=i.docker.json_skip(d,0);if(t===0)return;var n=JSON.parse(d.substring(0,t));d=d.substring(t);if("error"in n){c=true;r.text="Error downloading";s.text("Error downloading: "+n["errorDetail"]["message"]);o.on("click",function(){o.remove()})}else if("status"in n){if("id"in n){var a=n["status"];if(n["status"]=="Downloading"){a+=": "+n["progressDetail"]["current"]+"/"+n["progressDetail"]["total"]}l[n["id"]]=a;if(n["status"]=="Download complete"){delete l[n["id"]]}}var u="";for(var f in l){u+=f+": "+l[f]+"&nbsp;&nbsp;&nbsp;&nbsp;"}s.html(u)}}).done(function(){if(!c){o.remove()}});e("#containers-search-image-dialog").modal("hide")},perform_search:function(t){var n=e("#containers-search-image-search")[0].value;e("#containers-search-image-waiting").addClass("waiting");e("#containers-search-image-no-results").hide();e("#containers-search-image-results").hide();e("#containers-search-image-results tbody tr").remove();this.search_request=t.search(n).done(function(t){var i=t&&JSON.parse(t);e("#containers-search-image-waiting").removeClass("waiting");if(i&&i.length>0){e("#containers-search-image-results").show();i.forEach(function(t){var n=e("<tr>").append(e("<td>").text(t.name),e("<td>").text(t.description));n.on("click",function(i){e("#containers-search-image-results tr").each(function(){e(this).removeClass("active")});n.addClass("active");e("#containers-search-tag").val("latest");e("#containers-search-tag").prop("disabled",false);e("#containers-search-download").data("repo",t.name);e("#containers-search-download").prop("disabled",false)});n.data("entry",t);k(e("#containers-search-image-results"),n,function(e,t){if(e.data("entry").is_official&&!t.data("entry").is_official)return-1;if(!e.data("entry").is_official&&t.data("entry").is_official)return 1;if(e.data("entry").is_trusted&&!t.data("entry").is_trusted)return-1;if(!e.data("entry").is_trusted&&t.data("entry").is_trusted)return 1;if(e.data("entry").star_count!=t.data("entry").star_count)return t.data("entry").star_count-e.data("entry").star_count;return e.data("entry").name.localeCompare(t.data("entry").name)})})}else{e("#containers-search-image-no-results").html("No results for "+n+"<br />Please try another term");e("#containers-search-image-no-results").show()}})},cancel_search:function(){window.clearTimeout(this.search_timeout);e("#containers-search-image-no-results").hide();e("#containers-search-image-results").hide();e("#containers-search-image-results tbody tr").remove();if(this.search_request!==null){this.search_request.close();this.search_request=null}e("#containers-search-image-waiting").removeClass("waiting");e("#containers-search-tag").prop("disabled",true);e("#containers-search-download").prop("disabled",true)}};M.display=function(t){e("#containers-search-image-dialog").modal("show")};function M(){this._init()}n.dialogs.push(new M);R.prototype={_init:function(){this.id="container-details";this.section_id="containers";this.terminal=null},getTitle:function(){return C_("page-title","Containers")},show:function(){},leave:function(){C(this.client);this.dbus_client.release();this.dbus_client=null;e(this.client).off(".container-details");this.client.release();this.client=null;if(this.terminal){this.terminal.close();this.terminal=null}e("#container-terminal").hide()},setup:function(){var t=this;e("#container-details-start").on("click",e.proxy(this,"start_container"));e("#container-details-stop").on("click",e.proxy(this,"stop_container"));e("#container-details-restart").on("click",e.proxy(this,"restart_container"));e("#container-details-delete").on("click",e.proxy(this,"delete_container"));t.memory_limit=new y(e("#container-resources-dialog .memory-slider"),10*1024*1024,2*1024*1024*1024);t.cpu_priority=new w(e("#container-resources-dialog .cpu-slider"),2,1e6);t.memory_usage=e("#container-details-memory .bar-row");e("#container-resources-dialog").on("show.bs.modal",function(){var n=t.client.containers[t.container_id];e(this).find(".container-name").text(t.name);t.memory_limit.value=n.MemoryLimit||undefined;t.cpu_priority.value=n.CpuPriority||undefined}).find(".btn-primary").on("click",function(){t.client.change_memory_limit(t.container_id,t.memory_limit.value);var e=t.memory_limit.value;if(!isNaN(e))e*=2;t.client.change_swap_limit(t.container_id,e);t.client.change_cpu_priority(t.container_id,t.cpu_priority.value)})},enter:function(){var i=this;var a=e("#container-commit-dialog")[0];e(a).on("show.bs.modal",function(){var n=i.client.containers[i.container_id];e(a).find(".container-name").text(i.name);var o=i.client.images[n.Config.Image];var r="";if(o&&o.RepoTags)r=o.RepoTags[0].split(":",1)[0];e(a).find(".container-repository").attr("value",r);e(a).find(".container-tag").attr("value","");var s=t.user["name"]||t.user["user"];e(a).find(".container-author").attr("value",s);var l="";if(n.Config)l=c(n.Config.Cmd);if(!l)l=n.Command;e(a).find(".container-command").attr("value",l)}).find(".btn-primary").on("click",function(){var o=t.location;var r={Cmd:l(e(a).find(".container-command").val())};var s={author:e(a).find(".container-author").val()};var c=e(a).find(".container-tag").val();if(c)s["tag"]=c;var d=e(a).find(".container-repository").val();i.client.commit(i.container_id,d,s,r).fail(function(e){n.show_unexpected_error(e)}).done(function(){o.go("containers")})});this.address=n.get_page_machine();this.client=n.docker(this.address);this.container_id=n.get_page_param("id");this.name=this.container_id.slice(0,12);this.client.machine_info().done(function(e){i.memory_limit.max=e.memory});this.dbus_client=n.dbus(this.address);e(this.client).on("container.container-details",function(e,t,n){if(t==i.container_id)i.update()});x(this,this.client,this.address);this.update()},maybe_show_terminal:function(t){if(!this.terminal){this.terminal=i.docker.console(this.container_id,t.Config.Tty);e("#container-terminal").empty().append(this.terminal)}if(this.terminal.connected)this.terminal.typeable(t.State.Running);e("#container-terminal").show()},maybe_reconnect_terminal:function(){if(this.terminal&&!this.terminal.connected){this.terminal.connect();this.terminal.typeable(true)}},update:function(){e("#container-details-names").text("");e("#container-details-id").text("");e("#container-details-created").text("");e("#container-details-image").text("");e("#container-details-command").text("");e("#container-details-state").text("");e("#container-details-ports-row").hide();e("#container-details-resource-row").hide();var i=this.client.containers[this.container_id];o("container-details",this.container_id,i);if(!i){e("#container-details-names").text(_("Not found"));return}var a=!!this.client.waiting[this.container_id];e("#container-details div.waiting").toggle(a);e("#container-details button").toggle(!a);e("#container-details-start").prop("disabled",i.State.Running);e("#container-details-stop").prop("disabled",!i.State.Running);e("#container-details-restart").prop("disabled",!i.State.Running);e("#container-details-delete").prop("disabled",i.State.Running);e("#container-details-commit").prop("disabled",!!i.State.Running);e("#container-details-memory-row").toggle(!!i.State.Running);e("#container-details-cpu-row").toggle(!!i.State.Running);e("#container-details-resource-row").toggle(!!i.State.Running);this.name=u(i.Name);e("#container-details .breadcrumb .active").text(this.name);var r=[];if(i.NetworkSettings){for(var s in i.NetworkSettings.Ports){var c=i.NetworkSettings.Ports[s];if(!c)continue;for(var l=0;l<c.length;l++){r.push(t.format(_("${hip}:${hport} -> $cport"),{hip:c[l].HostIp,hport:c[l].HostPort,cport:s}))}}}e("#container-details-id").text(i.ID);e("#container-details-names").text(u(i.Name));e("#container-details-created").text(i.Created);e("#container-details-image").text(i.Image);e("#container-details-command").text(d(i));e("#container-details-state").text(f(i.State));e("#container-details-ports-row").toggle(r.length>0);e("#container-details-ports").html(r.map(n.esc).join("<br/>"));m(this.memory_usage,i.MemoryUsage,i.MemoryLimit);e("#container-details-memory-text").text(v(i.MemoryUsage,i.MemoryLimit));e("#container-details .cpu-usage").text(g(i.CpuUsage));e("#container-details .cpu-shares").text(h(i.CpuPriority));this.maybe_show_terminal(i)},start_container:function(){var e=this;this.client.start(this.container_id).fail(function(e){n.show_unexpected_error(e)}).done(function(){e.maybe_reconnect_terminal()})},stop_container:function(){this.client.stop(this.container_id).fail(function(e){n.show_unexpected_error(e)})},restart_container:function(){var e=this;this.client.restart(this.container_id).fail(function(e){n.show_unexpected_error(e)}).done(function(){e.maybe_reconnect_terminal()})},delete_container:function(){var e=this;var i=t.location;n.confirm(t.format(_("Please confirm deletion of $0"),e.name),_("Deleting a container will erase all data in it."),_("Delete")).done(function(){e.client.rm(e.container_id).fail(function(e){n.show_unexpected_error(e)}).done(function(){i.go("containers")})})}};function R(){this._init()}n.pages.push(new R);P.prototype={_init:function(){this.id="image-details";this.section_id="containers";this.danger_enabled=false},getTitle:function(){return C_("page-title","Containers")},show:function(){},leave:function(){C(this.client);this.dbus_client.release();this.dbus_client=null;e(this.client).off(".image-details");this.client.release();this.client=null},toggle_danger:function(t){var n=this;n.danger_enabled=t;e("#image-details-containers button.enable-danger").toggleClass("active",n.danger_enabled);e("#image-details-containers td.container-col-actions").toggle(!n.danger_enabled);e("#image-details-containers td.container-col-danger").toggle(n.danger_enabled)},setup:function(){var t=this;D("#image-details-containers","#"+this.id,function(){t.toggle_danger(!t.danger_enabled)});e("#image-details-run").on("click",e.proxy(this,"run_image"));e("#image-details-delete").on("click",e.proxy(this,"delete_image"))},enter:function(){var i=this;this.address=n.get_page_machine();this.client=n.docker(this.address);this.image_id=n.get_page_param("id");this.name=t.format(_("Image $0"),this.image_id.slice(0,12));this.dbus_client=n.dbus(this.address);e("#image-details-containers table tbody tr").remove();e("#image-details-containers button.enable-danger").toggle(false);e(this.client).on("image.image-details",function(e,t,n){if(t==i.image_id)i.update()});e(this.client).on("container.image-details",function(e,t,n){if(!n||n.Config&&n.Config.Image==i.image_id)i.render_container(t,n)});for(var a in this.client.containers){var o=this.client.containers[a];if(o.Config&&o.Config.Image==i.image_id)i.render_container(o.Id,o)}x(this,this.client,this.address);this.update()},update:function(){e("#image-details-id").text("");e("#image-details-entrypoint").text("");e("#image-details-command").text("");e("#image-details-created").text("");e("#image-details-author").text("");e("#image-details-ports").text("");var t=this.client.images[this.image_id];o("image-details",this.image_id,t);if(!t){e("#image-details-id").text(_("Not found"));return}var n=!!this.client.waiting[this.image_id];e("#image-details-buttons div.waiting").toggle(n);e("#image-details-buttons button").toggle(!n);if(t.RepoTags&&t.RepoTags.length>0)this.name=t.RepoTags[0];e("#image-details .breadcrumb .active").text(this.name);e("#image-details-id").text(t.id);e("#image-details-tags").html(p(t.RepoTags));e("#image-details-created").text(t.created);e("#image-details-author").text(t.author);var i=t.config;if(i){var a=[];for(var r in i.ExposedPorts){a.push(r)}e("#image-details-entrypoint").text(c(i.Entrypoint));e("#image-details-command").text(c(i.Cmd));e("#image-details-ports").text(a.join(", "))}},render_container:function(t,n){S(this.client,e("#image-details-containers"),null,"I",t,n,this.danger_enabled)},run_image:function(){N.display(this.client,this.image_id)},delete_image:function(){var e=this;var i=t.location;n.confirm(t.format(_("Please confirm deletion of $0"),e.name),_("Deleting an image will delete it, but you can probably download it again if you need it later. Unless this image has never been pushed to a repository, that is, in which case you probably can't download it again."),_("Delete")).done(function(){e.client.rmi(e.image_id).fail(function(e){n.show_unexpected_error(e)}).done(function(){i.go("containers")})})}};function P(){this._init()}n.pages.push(new P);function A(i){var r=this;var s;var c;var l;var d;var u;var f=true;var p;function h(){if(!p){p=window.setTimeout(function(){p=null;e(r).trigger("event")},300)}}function g(){s=l.get("/v1.10/events");s.stream(function(e){o("event:",e);if(d.state()=="pending")d.resolve();h()}).always(function(){window.setTimeout(function(){if(f&&s){g();f=false}},1e3)})}this.containers={};this.images={};this.waiting={};var _={};var m={};var v={};var b;var k;function y(e){if(!e.Name)return null;var t=e.Name;if(t[0]==="/")t=t.substring(1);return t}function w(t,n){if(n.State===undefined)n.State={};if(n.Config===undefined)n.Config={};e.extend(n,_[t]);var i=y(n);if(i)m[i]=t}function x(t){var n=r.containers[t];if(n){var i=y(n);if(i&&m[i]==t)delete m[i];delete r.containers[t];e(r).trigger("container",[t,undefined])}}function C(){l.get("/v1.10/containers/json",{all:1}).done(function(t){var n=JSON.parse(t);if(d.state()=="pending")d.resolve();f=true;var i={};e(n).each(function(t,n){var a=n.Id;if(!a)return;i[a]=a;_[a]=n;l.get("/v1.10/containers/"+encodeURIComponent(a)+"/json").done(function(t){var n=JSON.parse(t);w(a,n);r.containers[a]=n;e(r).trigger("container",[a,n])})});var a=[];e.each(r.containers,function(e){if(!i[e])a.push(e)});e.each(a,function(e,t){x(t)})}).fail(function(t){if(d.state()=="pending")d.reject(t);u=true;e(r).trigger("failure",[t])})}function S(t,n){if(n.config===undefined){if(n.container_config)n.config=n.container_config;else n.config={}}e.extend(n,v[t]);if(n.RepoTags)n.RepoTags.sort()}function D(t){if(r.images[t]){delete r.images[t];e(r).trigger("image",[t,undefined])}}function j(){l.get("/v1.10/images/json").done(function(t){var n=JSON.parse(t);if(d.state()=="pending")d.resolve();f=true;var i={};e.each(n,function(t,n){var a=n.Id;if(!a)return;i[a]=a;v[a]=n;l.get("/v1.10/images/"+encodeURIComponent(a)+"/json").done(function(t){var n=JSON.parse(t);S(a,n);r.images[a]=n;e(r).trigger("image",[a,n])})});var a=[];e.each(r.images,function(e){if(!i[e])a.push(e)});e.each(a,function(e,t){D(t)})}).fail(function(t){if(d.state()=="pending")d.reject(t);u=true;e(r).trigger("failure",[t])})}e(r).on("event",function(){C();j()});function N(){u=false;d=e.Deferred();l=t.http("/var/run/docker.sock");g();if(c&&c.valid)c.close();c=t.channel({payload:"fsdir1",path:"/var/lib/docker"});e(c).on("message",function(e,t){h()});e(c).on("close",function(e,t){if(t.problem)console.warn("monitor for docker directory failed: "+t.problem)});e(r).triggerHandler("event");b=n.dbus(i);k=b.get("/com/redhat/Cockpit/LxcMonitor","com.redhat.Cockpit.MultiResourceMonitor");e(k).on("NewSample",A)}var M=/docker-([A-Fa-f0-9]{64})\.scope/;var R=/.*\/ctr-(.+).service/;this.container_from_cgroup=P;function P(e){var t=M.exec(e);if(t)return t[1];t=R.exec(e);if(t)return m[t[1]];return null}this.pull=function L(e,t){o("pulling: "+e+", tag: "+t);var n={fromImage:e};if(t)n["tag"]=t;return l.request({method:"POST",path:"/v1.10/images/create",params:n,body:""})};function A(t,n,i){a("samples",n,i);for(var o in i){var s=P(o);if(!s)continue;var c=r.containers[s];if(!c)continue;var l=i[o];c.CGroup=o;var d=l[0];var u=l[1];var f=l[4];var p=l[5];if(d!=c.MemoryUsage||u!=c.MemoryLimit||f!=c.CpuUsage||p!=c.CpuPriority){c.MemoryUsage=d;c.MemoryLimit=u;c.CpuUsage=f;c.CpuPriority=p;e(r).trigger("container",[s,c])}}}function I(t){if(t in r.containers)e(r).trigger("container",[t,r.containers[t]]);else if(t in r.images)e(r).trigger("image",[t,r.images[t]])}function T(e,t){if(e in r.waiting){r.waiting[e]++}else{r.waiting[e]=1;I(e)}}function O(e){r.waiting[e]--;if(r.waiting[e]===0){delete r.waiting[e];I(e)}}N();this.start=function U(e,t){T(e);o("starting:",e);return l.request({method:"POST",path:"/v1.10/containers/"+encodeURIComponent(e)+"/start",headers:{"Content-Type":"application/json"},body:JSON.stringify(t||{})}).fail(function(t){o("start failed:",e,t)}).done(function(t){o("started:",e,t)}).always(function(){O(e)})};this.stop=function $(e,t){T(e);if(t===undefined)t=10;o("stopping:",e,t);return l.request({method:"POST",path:"/v1.10/containers/"+encodeURIComponent(e)+"/stop",params:{t:t},body:""}).fail(function(t){o("stop failed:",e,t)}).done(function(t){o("stopped:",e,t)}).always(function(){O(e)})};this.restart=function E(e){T(e);o("restarting:",e);return l.post("/v1.10/containers/"+encodeURIComponent(e)+"/restart").fail(function(t){o("restart failed:",e,t)}).done(function(t){o("restarted:",e,t)}).always(function(){O(e)})};this.create=function F(e,t){o("creating:",e);return l.request({method:"POST",path:"/v1.10/containers/create",params:{name:e},headers:{"Content-Type":"application/json"},body:JSON.stringify(t||{})}).fail(function(t){o("create failed:",e,t)}).done(function(t){o("created:",e,t)}).then(JSON.parse)};this.search=function V(e){o("searching:",e);return l.get("/v1.10/images/search",{term:e}).fail(function(t){o("search failed:",e,t)}).done(function(t){o("searched:",e,t)})};this.commit=function B(t,n,i,a){var r={container:t,repo:n};e.extend(r,i);T(t);o("committing:",t,n,i,a);return l.request({method:"POST",path:"/v1.10/commit",params:r,headers:{"Content-Type":"application/json"},body:JSON.stringify(a||{})}).fail(function(e){o("commit failed:",n,e)}).done(function(e){o("committed:",n)}).always(function(){O(t)}).then(JSON.parse)};this.rm=function G(e){T(e);o("deleting:",e);return l.request({method:"DELETE",path:"/v1.10/containers/"+encodeURIComponent(e),body:""}).fail(function(t){o("delete failed:",e,t)}).done(function(t){o("deleted:",e,t);x(e)}).always(function(){O(e)})};this.rmi=function H(e){T(e);o("deleting:",e);return l.request({method:"DELETE",path:"/v1.10/images/"+encodeURIComponent(e),body:""}).fail(function(t){o("delete failed:",e,t)}).done(function(t){o("deleted:",e,t);D(e)}).always(function(){O(e)})};function z(e,i,a,r){var s="/sys/fs/cgroup/"+e+"/"+i+"/"+a;var c="echo '"+r.toFixed(0)+"' > "+s;o("changing cgroup:",c);var l={host:n.get_page_machine()};t.spawn(["sh","-c",c],l).fail(function(e){console.warn(e)})}this.change_memory_limit=function W(e,t){if(t===undefined||t<=0)t=-1;return z("memory",this.containers[e].CGroup,"memory.limit_in_bytes",t)};this.change_swap_limit=function J(e,t){if(t===undefined||t<=0)t=-1;return z("memory",this.containers[e].CGroup,"memory.memsw.limit_in_bytes",t)};this.change_cpu_priority=function Q(e,t){if(t===undefined||t<=0)t=1024;return z("cpuacct",this.containers[e].CGroup,"cpu.shares",t)};this.setup_cgroups_plot=function q(e,t,i){function a(e){return!!P(e)}return n.setup_multi_plot(e,k,t,i,a)};this.machine_info=function Y(){return n.util.machine_info(i)};this.close=function X(){e(k).off("NewSample",A);k=null;if(b)b.release();b=null;d=null};this.connect=function K(){if(!d)N();return d.promise()};this.maybe_reconnect=function Z(){if(u){this.close();N()}return d.promise()}}})(jQuery,cockpit,shell,modules);
\ No newline at end of file
+this.danger_enabled=false},getTitle:function(){return C_("page-title","Containers")},toggle_danger:function(t){var n=this;n.danger_enabled=t;e("#containers-containers button.enable-danger").toggleClass("active",n.danger_enabled);e("#containers-containers td.container-col-actions").toggle(!n.danger_enabled);e("#containers-containers td.container-col-danger").toggle(n.danger_enabled)},setup:function(){var t=this;D("#containers-containers","#"+this.id,function(){t.toggle_danger(!t.danger_enabled)});this.container_filter_btn=n.select_btn(e.proxy(this,"filter"),[{title:_("All"),choice:"all",is_default:true},{title:_("Running"),choice:"running"}]);e("#containers-containers .panel-heading span").append(this.container_filter_btn);e("#containers-images-search").on("click",function(){M.display();return false})},enter:function(){var i=this;this.address=n.get_page_machine();this.client=n.docker(this.address);this.dbus_client=n.dbus(this.address);var a=["#250304","#5c080c","#970911","#ce0e15","#ef2930","#f36166","#f7999c","#fbd1d2"];var o=["#006bb4","#008ff0","#2daaff","#69c2ff","#a5daff","#e1f3ff","#00243c","#004778"];function r(t,n){n=i.client.container_from_cgroup(n)||n;e("#containers-containers tr").removeClass("highlight");e("#"+n).addClass("highlight")}this.cpu_plot=this.client.setup_cgroups_plot("#containers-cpu-graph",4,o.concat(o));e(this.cpu_plot).on("update-total",function(t,n){e("#containers-cpu-text").text(g(n))});e(this.cpu_plot).on("highlight",r);this.mem_plot=this.client.setup_cgroups_plot("#containers-mem-graph",0,o.concat(o));e(this.mem_plot).on("update-total",function(n,i){e("#containers-mem-text").text(t.format_bytes(i,1024))});e(this.mem_plot).on("highlight",r);e("#containers-containers table tbody tr").remove();e("#containers-images table tbody tr").remove();e(this.client).on("container.containers",function(e,t,n){i.render_container(t,n)});e(this.client).on("image.containers",function(e,t,n){i.render_image(t,n)});var s;e("#containers-containers button.enable-danger").toggle(false);for(s in this.client.containers){this.render_container(s,this.client.containers[s])}for(s in this.client.images){this.render_image(s,this.client.images[s])}x(i,i.client,i.address)},show:function(){this.cpu_plot.start();this.mem_plot.start()},leave:function(){C(this.client);this.dbus_client.release();this.dbus_client=null;this.cpu_plot.destroy();this.mem_plot.destroy();e(this.client).off(".containers");this.client.release();this.client=null},render_container:function(t,n){S(this.client,e("#containers-containers"),this.container_filter_btn,"",t,n,this.danger_enabled)},render_image:function(n,i){var a=this;var o=e("#"+n);if(!i||!i.RepoTags||i.RepoTags[0]=="<none>:<none>"){o.remove();return}var r=false;if(!o.length){var s=e('<button class="btn btn-default btn-control btn-play">').on("click",function(){N.display(a.client,n);return false});o=e('<tr id="'+n+'">').append(e('<td class="image-col-tags">'),e('<td class="image-col-created">'),e('<td class="image-col-size-graph">'),e('<td class="image-col-size-text">'),e('<td class="cell-buttons">').append(s));o.on("click",function(e){t.location.go("image-details",{id:n})});r=true}var c=o.children("td");e(c[0]).html(p(i.RepoTags));var l=new Date(i.Created*1e3);l.setDate(l.getDate()+2);if(l>new Date){e(c[1]).text(new Date(i.Created*1e3).toLocaleString())}else{var d=new Date(i.Created*1e3);e(c[1]).text(d.toLocaleDateString()).attr("title",d.toLocaleString())}e(c[2]).children("div").attr("value",i.VirtualSize);e(c[3]).text(t.format_bytes(i.VirtualSize,1024));if(r){b(e("#containers-images table"),o)}},filter:function(){var t=n.select_btn_selected(this.container_filter_btn);e("#containers-containers table").toggleClass("filter-unimportant",t==="running")}};function j(){this._init()}n.pages.push(new j);N.prototype={_init:function(){this.id="containers_run_image_dialog"},show:function(){},leave:function(){},setup:function(){e("#containers-run-image-run").on("click",e.proxy(this,"run"));this.memory_slider=new y(e("#containers-run-image-memory"),10*1024*1024,2*1024*1024*1024);this.cpu_slider=new w(e("#containers-run-image-cpu"),2,1e6);var t=e("#containers_run_image_dialog .modal-body table");this.run_portmapping=e('<div class="containers-run-portmapping">');this.portmapping_checkbox=e('<input type="checkbox" checked>');t.append(e("<tr>").append(e("<td>").text("Ports")).append(e('<td colspan="3">').append(this.portmapping_checkbox).append("Expose container ports").append(this.run_portmapping)));this.portmapping_checkbox.on("click",function(){if(e(this).prop("checked"))e(".containers-run-portmapping").show();else e(".containers-run-portmapping").hide()})},enter:function(){var t=this;var n=N.image_info;o("run-image",n);var i;var a;N.client.machine_info().done(function(e){t.memory_slider.max=e.memory});if(n.container_config.Memory){this.memory_slider.value=n.config_container.Memory}else{this.memory_slider.value=512*1024*1024;this.memory_slider.value=undefined}if(n.container_config.CpuShares){this.cpu_slider.value=n.container_config.CpuShares}else{this.cpu_slider.value=1024;this.cpu_slider.value=undefined}var r=["happy","jolly","dreamy","sad","angry","pensive","focused","sleepy","grave","distracted","determined","stoic","stupefied","sharp","agitated","cocky","tender","goofy","furious","desperate","hopeful","compassionate","silly","lonely","condescending","naughty","kickass","drunk","boring","nostalgic","ecstatic","insane","cranky","mad","jovial","sick","hungry","thirsty","elegant","backstabbing","clever","trusting","loving","suspicious","berserk","high","romantic","prickly","evil"];var s=["lovelace","franklin","tesla","einstein","bohr","davinci","pasteur","nobel","curie","darwin","turing","ritchie","torvalds","pike","thompson","wozniak","galileo","euclid","newton","fermat","archimedes","poincare","heisenberg","feynman","hawking","fermi","pare","mccarthy","engelbart","babbage","albattani","ptolemy","bell","wright","lumiere","morse","mclean","brown","bardeen","brattain","shockley"];function l(){function e(e){return e[Math.round(Math.random()*(e.length-1))]}return e(r)+"_"+e(s)}e("#containers-run-image").text(N.image_info.RepoTags[0]);e("#containers-run-image-name").val(l());e("#containers-run-image-command").val(c(N.image_info.config.Cmd));function d(t,n,i,a){if(t===undefined)t="";if(n===undefined)n="TCP";if(i===undefined)i=true;if(a===undefined)a="";var o=e('<input type="text" class="form-control">');var r=e('<input type="text" class="form-control">');var s=e('<select class="form-control selectpicker" data-width="60px">').append(e("<option>").text(_("TCP"))).append(e("<option>").text(_("UDP")));var c=e('<button type="button" class="btn btn-default fa fa-plus">');var l=e('<button type="button" class="btn btn-default pficon-close">');if(i){l.on("click",function(){var t=e(this).closest("form");if(t.parent().children().length>1){t.remove()}else{t.find("input").each(function(){e(this).val("")});t.find("select").selectpicker("val",_("TCP"))}})}else{o.prop("disabled",true);s.prop("disabled",true);l.prop("disabled",true)}var d={};d.html=e('<form class="form-inline">').append(e('<div class="form-group">').append(o)).append(s).append(e('<div class="form-group">').append(e("<label>").html(" &nbsp;to host port")).append(r)).append(c).append(l);o.attr("placeholder",_("none"));o.val(t);s.selectpicker("refresh");if(n.toUpperCase()===_("UDP"))s.selectpicker("val",_("UDP"));else s.selectpicker("val",_("TCP"));r.attr("placeholder",_("none"));r.val(a);d.elements={add:c};return d}function u(t,n,i,a,o,r){var s=d(i,a,o,r);if(n===undefined||n.length<1)t.append(s.html);else s.html.insertAfter(n);s.elements.add.on("click",function(){u(t,e(this).closest("form"))})}this.run_portmapping.empty();for(var f in N.image_info.config.ExposedPorts){u(this.run_portmapping,undefined,parseInt(f),f.slice(-3),false)}if(this.run_portmapping.children().length<1)u(this.run_portmapping);this.portmapping_checkbox.prop("checked",true)},run:function(){var t=e("#containers-run-image-name").val();var i=e("#containers-run-image-command").val();var a={};var o,r;var s,c,d;var u={};if(this.portmapping_checkbox.prop("checked")){this.run_portmapping.children("form").each(function(){var t=e(this).find("input").map(function(t,n){return e(n).val()}).get();s=t[0];c=t[1];d=e(this).find("select").val().toLowerCase();if(s===""||c==="")return;a[s+"/"+d]=[{HostPort:c}];u[s+"/"+d]={}})}e("#containers_run_image_dialog").modal("hide");var f=e("#containers-run-image-with-terminal").prop("checked");var p={Cmd:l(i),Image:N.image_info.id,Memory:this.memory_slider.value||0,MemorySwap:this.memory_slider.value*2||0,CpuShares:this.cpu_slider.value||0,Tty:f,ExposedPorts:u};if(f){e.extend(p,{AttachStderr:true,AttachStdin:true,AttachStdout:true,OpenStdin:true,StdinOnce:true})}N.client.create(t,p).fail(function(e){n.show_unexpected_error(e)}).done(function(e){N.client.start(e.Id,{PortBindings:a}).fail(function(e){n.show_unexpected_error(e)})})}};N.display=function(t,n){N.image_info=t.images[n];N.client=t;e("#containers_run_image_dialog").modal("show")};function N(){this._init()}n.dialogs.push(new N);M.prototype={_init:function(){this.id="containers-search-image-dialog"},show:function(){e("#containers-search-image-search").focus()},leave:function(){this.cancel_search();e(this.client).off(".containers-search-image-dialog");this.client.release();this.client=null},setup:function(){e("#containers-search-image-search").on("keypress",e.proxy(this,"input"));e("#containers-search-image-search").attr("placeholder","search by name, namespace or description");e("#containers-search-download").on("click",e.proxy(this,"start_download"));e("#containers-search-tag").prop("disabled",true);e("#containers-search-download").prop("disabled",true);this.search_timeout=null;this.search_request=null},enter:function(){this.address=n.get_page_machine();this.client=n.docker(this.address);e("#containers-search-image-results tbody tr").remove();e("#containers-search-image-results").hide();e("#containers-search-image-no-results").hide();e("#containers-search-image-search")[0].value=""},input:function(e){this.cancel_search();if(e.target.value.length<3&&e.which!=13)return;var t=this;this.search_timeout=window.setTimeout(function(){t.perform_search(t.client)},e.which==13?0:2e3)},start_download:function(t){var n=e("#containers-search-download").data("repo");var a=e("#containers-search-tag").val();e("#containers-search-tag").prop("disabled",true);e("#containers-search-download").data("repo","");e("#containers-search-download").prop("disabled",true);var o=e('<tr id="imagedl_'+n.replace("/","_")+'">').append(e('<td class="container-col-tags">').text(n+":"+a),e('<td class="container-col-created">').text("Downloading"),e('<td class="image-col-size-graph">').append(e('<div class="progress progress-striped active">').append(e('<div class="progress-bar" role="progressbar" aria-valuenow="1" aria-valuemin="0" aria-valuemax="1" style="width: 100%">'))),e('<td class="image-col-size-text">'),e('<td class="cell-buttons">'));b(e("#containers-images table"),o);var r=o.children("td").eq(1);var s=o.children("td").eq(2);var c=false;var l={};var d="";this.client.pull(n,a).stream(function(e){d+=e;var t=i.docker.json_skip(d,0);if(t===0)return;var n=JSON.parse(d.substring(0,t));d=d.substring(t);if("error"in n){c=true;r.text="Error downloading";s.text("Error downloading: "+n["errorDetail"]["message"]);o.on("click",function(){o.remove()})}else if("status"in n){if("id"in n){var a=n["status"];if(n["status"]=="Downloading"){a+=": "+n["progressDetail"]["current"]+"/"+n["progressDetail"]["total"]}l[n["id"]]=a;if(n["status"]=="Download complete"){delete l[n["id"]]}}var u="";for(var f in l){u+=f+": "+l[f]+"&nbsp;&nbsp;&nbsp;&nbsp;"}s.html(u)}}).done(function(){if(!c){o.remove()}});e("#containers-search-image-dialog").modal("hide")},perform_search:function(t){var n=e("#containers-search-image-search")[0].value;e("#containers-search-image-waiting").addClass("waiting");e("#containers-search-image-no-results").hide();e("#containers-search-image-results").hide();e("#containers-search-image-results tbody tr").remove();this.search_request=t.search(n).done(function(t){var i=t&&JSON.parse(t);e("#containers-search-image-waiting").removeClass("waiting");if(i&&i.length>0){e("#containers-search-image-results").show();i.forEach(function(t){var n=e("<tr>").append(e("<td>").text(t.name),e("<td>").text(t.description));n.on("click",function(i){e("#containers-search-image-results tr").each(function(){e(this).removeClass("active")});n.addClass("active");e("#containers-search-tag").val("latest");e("#containers-search-tag").prop("disabled",false);e("#containers-search-download").data("repo",t.name);e("#containers-search-download").prop("disabled",false)});n.data("entry",t);k(e("#containers-search-image-results"),n,function(e,t){if(e.data("entry").is_official&&!t.data("entry").is_official)return-1;if(!e.data("entry").is_official&&t.data("entry").is_official)return 1;if(e.data("entry").is_trusted&&!t.data("entry").is_trusted)return-1;if(!e.data("entry").is_trusted&&t.data("entry").is_trusted)return 1;if(e.data("entry").star_count!=t.data("entry").star_count)return t.data("entry").star_count-e.data("entry").star_count;return e.data("entry").name.localeCompare(t.data("entry").name)})})}else{e("#containers-search-image-no-results").html("No results for "+n+"<br />Please try another term");e("#containers-search-image-no-results").show()}})},cancel_search:function(){window.clearTimeout(this.search_timeout);e("#containers-search-image-no-results").hide();e("#containers-search-image-results").hide();e("#containers-search-image-results tbody tr").remove();if(this.search_request!==null){this.search_request.close();this.search_request=null}e("#containers-search-image-waiting").removeClass("waiting");e("#containers-search-tag").prop("disabled",true);e("#containers-search-download").prop("disabled",true)}};M.display=function(t){e("#containers-search-image-dialog").modal("show")};function M(){this._init()}n.dialogs.push(new M);R.prototype={_init:function(){this.id="container-details";this.section_id="containers";this.terminal=null},getTitle:function(){return C_("page-title","Containers")},show:function(){},leave:function(){C(this.client);this.dbus_client.release();this.dbus_client=null;e(this.client).off(".container-details");this.client.release();this.client=null;if(this.terminal){this.terminal.close();this.terminal=null}e("#container-terminal").hide()},setup:function(){var t=this;e("#container-details-start").on("click",e.proxy(this,"start_container"));e("#container-details-stop").on("click",e.proxy(this,"stop_container"));e("#container-details-restart").on("click",e.proxy(this,"restart_container"));e("#container-details-delete").on("click",e.proxy(this,"delete_container"));t.memory_limit=new y(e("#container-resources-dialog .memory-slider"),10*1024*1024,2*1024*1024*1024);t.cpu_priority=new w(e("#container-resources-dialog .cpu-slider"),2,1e6);t.memory_usage=e("#container-details-memory .bar-row");e("#container-resources-dialog").on("show.bs.modal",function(){var n=t.client.containers[t.container_id];e(this).find(".container-name").text(t.name);t.memory_limit.value=n.MemoryLimit||undefined;t.cpu_priority.value=n.CpuPriority||undefined}).find(".btn-primary").on("click",function(){t.client.change_memory_limit(t.container_id,t.memory_limit.value);var e=t.memory_limit.value;if(!isNaN(e))e*=2;t.client.change_swap_limit(t.container_id,e);t.client.change_cpu_priority(t.container_id,t.cpu_priority.value)})},enter:function(){var i=this;var a=e("#container-commit-dialog")[0];e(a).on("show.bs.modal",function(){var n=i.client.containers[i.container_id];e(a).find(".container-name").text(i.name);var o=i.client.images[n.Config.Image];var r="";if(o&&o.RepoTags)r=o.RepoTags[0].split(":",1)[0];e(a).find(".container-repository").attr("value",r);e(a).find(".container-tag").attr("value","");var s=t.user["name"]||t.user["user"];e(a).find(".container-author").attr("value",s);var l="";if(n.Config)l=c(n.Config.Cmd);if(!l)l=n.Command;e(a).find(".container-command").attr("value",l)}).find(".btn-primary").on("click",function(){var o=t.location;var r={Cmd:l(e(a).find(".container-command").val())};var s={author:e(a).find(".container-author").val()};var c=e(a).find(".container-tag").val();if(c)s["tag"]=c;var d=e(a).find(".container-repository").val();i.client.commit(i.container_id,d,s,r).fail(function(e){n.show_unexpected_error(e)}).done(function(){o.go("containers")})});this.address=n.get_page_machine();this.client=n.docker(this.address);this.container_id=n.get_page_param("id");this.name=this.container_id.slice(0,12);this.client.machine_info().done(function(e){i.memory_limit.max=e.memory});this.dbus_client=n.dbus(this.address);e(this.client).on("container.container-details",function(e,t,n){if(t==i.container_id)i.update()});x(this,this.client,this.address);this.update()},maybe_show_terminal:function(t){if(!this.terminal){this.terminal=i.docker.console(this.container_id,t.Config.Tty);e("#container-terminal").empty().append(this.terminal)}if(this.terminal.connected)this.terminal.typeable(t.State.Running);e("#container-terminal").show()},maybe_reconnect_terminal:function(){if(this.terminal&&!this.terminal.connected){this.terminal.connect();this.terminal.typeable(true)}},update:function(){e("#container-details-names").text("");e("#container-details-id").text("");e("#container-details-created").text("");e("#container-details-image").text("");e("#container-details-command").text("");e("#container-details-state").text("");e("#container-details-ports-row").hide();e("#container-details-resource-row").hide();var i=this.client.containers[this.container_id];o("container-details",this.container_id,i);if(!i){e("#container-details-names").text(_("Not found"));return}var a=!!this.client.waiting[this.container_id];e("#container-details div.waiting").toggle(a);e("#container-details button").toggle(!a);e("#container-details-start").prop("disabled",i.State.Running);e("#container-details-stop").prop("disabled",!i.State.Running);e("#container-details-restart").prop("disabled",!i.State.Running);e("#container-details-delete").prop("disabled",i.State.Running);e("#container-details-commit").prop("disabled",!!i.State.Running);e("#container-details-memory-row").toggle(!!i.State.Running);e("#container-details-cpu-row").toggle(!!i.State.Running);e("#container-details-resource-row").toggle(!!i.State.Running);this.name=u(i.Name);e("#container-details .breadcrumb .active").text(this.name);var r=[];if(i.NetworkSettings){for(var s in i.NetworkSettings.Ports){var c=i.NetworkSettings.Ports[s];if(!c)continue;for(var l=0;l<c.length;l++){r.push(t.format(_("${hip}:${hport} -> $cport"),{hip:c[l].HostIp,hport:c[l].HostPort,cport:s}))}}}e("#container-details-id").text(i.ID);e("#container-details-names").text(u(i.Name));e("#container-details-created").text(i.Created);e("#container-details-image").text(i.Image);e("#container-details-command").text(d(i));e("#container-details-state").text(f(i.State));e("#container-details-ports-row").toggle(r.length>0);e("#container-details-ports").html(r.map(n.esc).join("<br/>"));m(this.memory_usage,i.MemoryUsage,i.MemoryLimit);e("#container-details-memory-text").text(v(i.MemoryUsage,i.MemoryLimit));e("#container-details .cpu-usage").text(g(i.CpuUsage));e("#container-details .cpu-shares").text(h(i.CpuPriority));this.maybe_show_terminal(i)},start_container:function(){var e=this;this.client.start(this.container_id).fail(function(e){n.show_unexpected_error(e)}).done(function(){e.maybe_reconnect_terminal()})},stop_container:function(){this.client.stop(this.container_id).fail(function(e){n.show_unexpected_error(e)})},restart_container:function(){var e=this;this.client.restart(this.container_id).fail(function(e){n.show_unexpected_error(e)}).done(function(){e.maybe_reconnect_terminal()})},delete_container:function(){var e=this;var i=t.location;n.confirm(t.format(_("Please confirm deletion of $0"),e.name),_("Deleting a container will erase all data in it."),_("Delete")).done(function(){e.client.rm(e.container_id).fail(function(e){n.show_unexpected_error(e)}).done(function(){i.go("containers")})})}};function R(){this._init()}n.pages.push(new R);P.prototype={_init:function(){this.id="image-details";this.section_id="containers";this.danger_enabled=false},getTitle:function(){return C_("page-title","Containers")},show:function(){},leave:function(){C(this.client);this.dbus_client.release();this.dbus_client=null;e(this.client).off(".image-details");this.client.release();this.client=null},toggle_danger:function(t){var n=this;n.danger_enabled=t;e("#image-details-containers button.enable-danger").toggleClass("active",n.danger_enabled);e("#image-details-containers td.container-col-actions").toggle(!n.danger_enabled);e("#image-details-containers td.container-col-danger").toggle(n.danger_enabled)},setup:function(){var t=this;D("#image-details-containers","#"+this.id,function(){t.toggle_danger(!t.danger_enabled)});e("#image-details-run").on("click",e.proxy(this,"run_image"));e("#image-details-delete").on("click",e.proxy(this,"delete_image"))},enter:function(){var i=this;this.address=n.get_page_machine();this.client=n.docker(this.address);this.image_id=n.get_page_param("id");this.name=t.format(_("Image $0"),this.image_id.slice(0,12));this.dbus_client=n.dbus(this.address);e("#image-details-containers table tbody tr").remove();e("#image-details-containers button.enable-danger").toggle(false);e(this.client).on("image.image-details",function(e,t,n){if(t==i.image_id)i.update()});e(this.client).on("container.image-details",function(e,t,n){if(!n||n.Config&&n.Config.Image==i.image_id)i.render_container(t,n)});for(var a in this.client.containers){var o=this.client.containers[a];if(o.Config&&o.Config.Image==i.image_id)i.render_container(o.Id,o)}x(this,this.client,this.address);this.update()},update:function(){e("#image-details-id").text("");e("#image-details-entrypoint").text("");e("#image-details-command").text("");e("#image-details-created").text("");e("#image-details-author").text("");e("#image-details-ports").text("");var t=this.client.images[this.image_id];o("image-details",this.image_id,t);if(!t){e("#image-details-id").text(_("Not found"));return}var n=!!this.client.waiting[this.image_id];e("#image-details-buttons div.waiting").toggle(n);e("#image-details-buttons button").toggle(!n);if(t.RepoTags&&t.RepoTags.length>0)this.name=t.RepoTags[0];e("#image-details .breadcrumb .active").text(this.name);e("#image-details-id").text(t.id);e("#image-details-tags").html(p(t.RepoTags));e("#image-details-created").text(t.created);e("#image-details-author").text(t.author);var i=t.config;if(i){var a=[];for(var r in i.ExposedPorts){a.push(r)}e("#image-details-entrypoint").text(c(i.Entrypoint));e("#image-details-command").text(c(i.Cmd));e("#image-details-ports").text(a.join(", "))}},render_container:function(t,n){S(this.client,e("#image-details-containers"),null,"I",t,n,this.danger_enabled)},run_image:function(){N.display(this.client,this.image_id)},delete_image:function(){var e=this;var i=t.location;n.confirm(t.format(_("Please confirm deletion of $0"),e.name),_("Deleting an image will delete it, but you can probably download it again if you need it later. Unless this image has never been pushed to a repository, that is, in which case you probably can't download it again."),_("Delete")).done(function(){e.client.rmi(e.image_id).fail(function(e){n.show_unexpected_error(e)}).done(function(){i.go("containers")})})}};function P(){this._init()}n.pages.push(new P);function A(i){var r=this;var s;var c;var l;var d;var u;var f=true;var p;function h(){if(!p){p=window.setTimeout(function(){p=null;e(r).trigger("event")},300)}}function g(){s=l.get("/v1.10/events");s.stream(function(e){o("event:",e);if(d.state()=="pending")d.resolve();h()}).always(function(){window.setTimeout(function(){if(f&&s){g();f=false}},1e3)})}this.containers={};this.images={};this.waiting={};var _={};var m={};var v={};var b;var k;function y(e){if(!e.Name)return null;var t=e.Name;if(t[0]==="/")t=t.substring(1);return t}function w(t,n){if(n.State===undefined)n.State={};if(n.Config===undefined)n.Config={};e.extend(n,_[t]);var i=y(n);if(i)m[i]=t}function x(t){var n=r.containers[t];if(n){var i=y(n);if(i&&m[i]==t)delete m[i];delete r.containers[t];e(r).trigger("container",[t,undefined])}}function C(){l.get("/v1.10/containers/json",{all:1}).done(function(t){var n=JSON.parse(t);if(d.state()=="pending")d.resolve();f=true;var i={};e(n).each(function(t,n){var a=n.Id;if(!a)return;i[a]=a;_[a]=n;l.get("/v1.10/containers/"+encodeURIComponent(a)+"/json").done(function(t){var n=JSON.parse(t);w(a,n);r.containers[a]=n;e(r).trigger("container",[a,n])})});var a=[];e.each(r.containers,function(e){if(!i[e])a.push(e)});e.each(a,function(e,t){x(t)})}).fail(function(t){if(d.state()=="pending")d.reject(t);u=true;e(r).trigger("failure",[t])})}function S(t,n){if(n.config===undefined){if(n.container_config)n.config=n.container_config;else n.config={}}e.extend(n,v[t]);if(n.RepoTags)n.RepoTags.sort()}function D(t){if(r.images[t]){delete r.images[t];e(r).trigger("image",[t,undefined])}}function j(){l.get("/v1.10/images/json").done(function(t){var n=JSON.parse(t);if(d.state()=="pending")d.resolve();f=true;var i={};e.each(n,function(t,n){var a=n.Id;if(!a)return;i[a]=a;v[a]=n;l.get("/v1.10/images/"+encodeURIComponent(a)+"/json").done(function(t){var n=JSON.parse(t);S(a,n);r.images[a]=n;e(r).trigger("image",[a,n])})});var a=[];e.each(r.images,function(e){if(!i[e])a.push(e)});e.each(a,function(e,t){D(t)})}).fail(function(t){if(d.state()=="pending")d.reject(t);u=true;e(r).trigger("failure",[t])})}e(r).on("event",function(){C();j()});function N(){u=false;d=e.Deferred();l=t.http("/var/run/docker.sock");g();if(c&&c.valid)c.close();c=t.channel({payload:"fsdir1",path:"/usr/bin/docker"});e(c).on("message",function(e,t){h()});e(c).on("close",function(e,t){if(t.problem)console.warn("monitor for docker directory failed: "+t.problem)});e(r).triggerHandler("event");b=n.dbus(i);k=b.get("/com/redhat/Cockpit/LxcMonitor","com.redhat.Cockpit.MultiResourceMonitor");e(k).on("NewSample",A)}var M=/docker-([A-Fa-f0-9]{64})\.scope/;var R=/.*\/ctr-(.+).service/;this.container_from_cgroup=P;function P(e){var t=M.exec(e);if(t)return t[1];t=R.exec(e);if(t)return m[t[1]];return null}this.pull=function L(e,t){o("pulling: "+e+", tag: "+t);var n={fromImage:e};if(t)n["tag"]=t;return l.request({method:"POST",path:"/v1.10/images/create",params:n,body:""})};function A(t,n,i){a("samples",n,i);for(var o in i){var s=P(o);if(!s)continue;var c=r.containers[s];if(!c)continue;var l=i[o];c.CGroup=o;var d=l[0];var u=l[1];var f=l[4];var p=l[5];if(d!=c.MemoryUsage||u!=c.MemoryLimit||f!=c.CpuUsage||p!=c.CpuPriority){c.MemoryUsage=d;c.MemoryLimit=u;c.CpuUsage=f;c.CpuPriority=p;e(r).trigger("container",[s,c])}}}function I(t){if(t in r.containers)e(r).trigger("container",[t,r.containers[t]]);else if(t in r.images)e(r).trigger("image",[t,r.images[t]])}function T(e,t){if(e in r.waiting){r.waiting[e]++}else{r.waiting[e]=1;I(e)}}function O(e){r.waiting[e]--;if(r.waiting[e]===0){delete r.waiting[e];I(e)}}N();this.start=function U(e,t){T(e);o("starting:",e);return l.request({method:"POST",path:"/v1.10/containers/"+encodeURIComponent(e)+"/start",headers:{"Content-Type":"application/json"},body:JSON.stringify(t||{})}).fail(function(t){o("start failed:",e,t)}).done(function(t){o("started:",e,t)}).always(function(){O(e)})};this.stop=function $(e,t){T(e);if(t===undefined)t=10;o("stopping:",e,t);return l.request({method:"POST",path:"/v1.10/containers/"+encodeURIComponent(e)+"/stop",params:{t:t},body:""}).fail(function(t){o("stop failed:",e,t)}).done(function(t){o("stopped:",e,t)}).always(function(){O(e)})};this.restart=function E(e){T(e);o("restarting:",e);return l.post("/v1.10/containers/"+encodeURIComponent(e)+"/restart").fail(function(t){o("restart failed:",e,t)}).done(function(t){o("restarted:",e,t)}).always(function(){O(e)})};this.create=function F(e,t){o("creating:",e);return l.request({method:"POST",path:"/v1.10/containers/create",params:{name:e},headers:{"Content-Type":"application/json"},body:JSON.stringify(t||{})}).fail(function(t){o("create failed:",e,t)}).done(function(t){o("created:",e,t)}).then(JSON.parse)};this.search=function V(e){o("searching:",e);return l.get("/v1.10/images/search",{term:e}).fail(function(t){o("search failed:",e,t)}).done(function(t){o("searched:",e,t)})};this.commit=function B(t,n,i,a){var r={container:t,repo:n};e.extend(r,i);T(t);o("committing:",t,n,i,a);return l.request({method:"POST",path:"/v1.10/commit",params:r,headers:{"Content-Type":"application/json"},body:JSON.stringify(a||{})}).fail(function(e){o("commit failed:",n,e)}).done(function(e){o("committed:",n)}).always(function(){O(t)}).then(JSON.parse)};this.rm=function G(e){T(e);o("deleting:",e);return l.request({method:"DELETE",path:"/v1.10/containers/"+encodeURIComponent(e),body:""}).fail(function(t){o("delete failed:",e,t)}).done(function(t){o("deleted:",e,t);x(e)}).always(function(){O(e)})};this.rmi=function H(e){T(e);o("deleting:",e);return l.request({method:"DELETE",path:"/v1.10/images/"+encodeURIComponent(e),body:""}).fail(function(t){o("delete failed:",e,t)}).done(function(t){o("deleted:",e,t);D(e)}).always(function(){O(e)})};function z(e,i,a,r){var s="/sys/fs/cgroup/"+e+"/"+i+"/"+a;var c="echo '"+r.toFixed(0)+"' > "+s;o("changing cgroup:",c);var l={host:n.get_page_machine()};t.spawn(["sh","-c",c],l).fail(function(e){console.warn(e)})}this.change_memory_limit=function W(e,t){if(t===undefined||t<=0)t=-1;return z("memory",this.containers[e].CGroup,"memory.limit_in_bytes",t)};this.change_swap_limit=function J(e,t){if(t===undefined||t<=0)t=-1;return z("memory",this.containers[e].CGroup,"memory.memsw.limit_in_bytes",t)};this.change_cpu_priority=function Q(e,t){if(t===undefined||t<=0)t=1024;return z("cpuacct",this.containers[e].CGroup,"cpu.shares",t)};this.setup_cgroups_plot=function q(e,t,i){function a(e){return!!P(e)}return n.setup_multi_plot(e,k,t,i,a)};this.machine_info=function Y(){return n.util.machine_info(i)};this.close=function X(){e(k).off("NewSample",A);k=null;if(b)b.release();b=null;d=null};this.connect=function K(){if(!d)N();return d.promise()};this.maybe_reconnect=function Z(){if(u){this.close();N()}return d.promise()}}})(jQuery,cockpit,shell,modules);