From: Dietmar Maurer Date: Thu, 5 Apr 2012 06:04:06 +0000 (+0200) Subject: cleanup subscription code X-Git-Url: https://git.proxmox.com/?p=pve-manager.git;a=commitdiff_plain;h=00a93a4bef0bd07e8890de4ae486d0d7c33e0bcb cleanup subscription code --- diff --git a/PVE/API2/Subscription.pm b/PVE/API2/Subscription.pm index 9e9a7a47..f85cfeb8 100644 --- a/PVE/API2/Subscription.pm +++ b/PVE/API2/Subscription.pm @@ -66,6 +66,7 @@ my $saved_fields = { key => 1, checktime => 1, status => 1, + message => 0, validdirectory => 1, productname => 1, regdate => 1, @@ -96,6 +97,7 @@ sub check_fields { return undef if $info->{status} ne 'Active'; foreach my $f (keys %$saved_fields) { + next if !$saved_fields->{$f}; if (!$info->{$f}) { die "Missing field '$f'\n"; } @@ -191,7 +193,7 @@ sub write_etc_pve_subscription { sub check_subscription { my ($key) = @_; - my $whmcsurl = "http://shop2.maurer-it.com"; + my $whmcsurl = "https://shop.maurer-it.com"; my $uri = "$whmcsurl/modules/servers/licensing/verify.php"; @@ -222,10 +224,10 @@ sub check_subscription { $req->header('Content-Length' => length($content)); $req->content($content); - my $ua = LWP::UserAgent->new(protocols_allowed => ['http'], timeout => 30); + my $ua = LWP::UserAgent->new(protocols_allowed => ['https'], timeout => 30); if ($proxy) { - $ua->proxy(['http'], $proxy); + $ua->proxy(['http', 'https'], $proxy); } else { $ua->env_proxy; } @@ -243,12 +245,16 @@ sub check_subscription { my $subinfo = {}; while ($raw =~ m/<(.*?)>([^<]+)<\/\1>/g) { my ($k, $v) = ($1, $2); - next if !($k eq 'md5hash' || $saved_fields->{$k}); + next if !($k eq 'md5hash' || defined($saved_fields->{$k})); $subinfo->{$k} = $v; } $subinfo->{checktime} = time(); $subinfo->{key} = $key; + if ($subinfo->{message}) { + $subinfo->{message} =~ s/^Directory Invalid$/Invalid Server ID/; + } + my $emd5sum = md5_hex($shared_key_data . $check_token); if ($subinfo->{status} && $subinfo->{status} eq 'Active') { if (!$subinfo->{md5hash} || ($subinfo->{md5hash} ne $emd5sum)) { @@ -279,13 +285,20 @@ __PACKAGE__->register_method ({ code => sub { my ($param) = @_; + my $server_id = get_hwaddress(); + my $info = PVE::INotify::read_file('subscription'); if (!$info) { return { status => "NotFound", message => "There is no subscription key", + serverid => $server_id, } } + + $info->{serverid} = $server_id; + $info->{sockets} = get_sockets(); + return $info }}); diff --git a/www/manager/Makefile b/www/manager/Makefile index 3158fe33..ce5deb10 100644 --- a/www/manager/Makefile +++ b/www/manager/Makefile @@ -80,6 +80,7 @@ JSSRC= \ node/NetworkEdit.js \ node/NetworkView.js \ node/Tasks.js \ + node/Subscription.js \ node/Config.js \ qemu/StatusView.js \ window/Migrate.js \ @@ -134,6 +135,7 @@ JSSRC= \ dc/AuthEdit.js \ dc/Backup.js \ dc/HAConfig.js \ + dc/Support.js \ dc/Config.js \ Workspace.js diff --git a/www/manager/StateProvider.js b/www/manager/StateProvider.js index cd30203a..60974e9b 100644 --- a/www/manager/StateProvider.js +++ b/www/manager/StateProvider.js @@ -49,6 +49,8 @@ Ext.define('PVE.StateProvider', { hprefix: 'v1', compDict: { + ha: 28, + support: 27, pool: 26, syslog: 25, ubc: 24, diff --git a/www/manager/dc/Config.js b/www/manager/dc/Config.js index 7a953c35..5b891520 100644 --- a/www/manager/dc/Config.js +++ b/www/manager/dc/Config.js @@ -63,6 +63,11 @@ Ext.define('PVE.dc.Config', { xtype: 'pveDcHAConfig', title: 'HA', itemId: 'ha' + }, + { + xtype: 'pveDcSupport', + title: gettext('Support'), + itemId: 'support' } ] }); diff --git a/www/manager/dc/Support.js b/www/manager/dc/Support.js new file mode 100644 index 00000000..55492367 --- /dev/null +++ b/www/manager/dc/Support.js @@ -0,0 +1,78 @@ +Ext.define('PVE.dc.Support', { + extend: 'Ext.panel.Panel', + alias: 'widget.pveDcSupport', + + invalidHtml: '

No valid subscription

You do not have a valid subscription for this server. Please visit www.proxmox.com to get a list of available options.', + + communityHtml: 'Please use the public community forum for any questions.', + + activeHtml: 'Please use our support portal for any questions. You can also use the public community forum to get additional information.', + + bugzillaHtml: '

Bug Tracking

Our bug tracking system is available here.', + + docuHtml: '

Documentation

Complete documentation, tutorials, videos and more is available at our wiki.', + + updateActive: function(data) { + var me = this; + + var html = '

' + data.productname + '

' + me.activeHtml; + html += '

' + me.docuHtml; + html += '

' + me.bugzillaHtml; + + me.update(html); + }, + + updateCommunity: function(data) { + var me = this; + + var html = '

' + data.productname + '

' + me.communityHtml; + html += '

' + me.docuHtml; + html += '

' + me.bugzillaHtml; + + me.update(html); + }, + + updateInactive: function(data) { + var me = this; + me.update(me.invalidHtml); + }, + + initComponent: function() { + var me = this; + + var reload = function() { + PVE.Utils.API2Request({ + url: '/nodes/localhost/subscription', + method: 'GET', + waitMsgTarget: me, + failure: function(response, opts) { + Ext.Msg.alert('Error', response.htmlStatus); + me.update("Unable to load subscription status: " + response.htmlStatus); + }, + success: function(response, opts) { + var data = response.result.data; + + if (data.status === 'Active') { + if (data.level === 'c') { + me.updateCommunity(data); + } else { + me.updateActive(data); + } + } else { + me.updateInactive(data); + } + } + }); + }; + + Ext.apply(me, { + autoScroll: true, + bodyStyle: 'padding:10px', + listeners: { + show: reload + } + }); + + me.callParent(); + } +}); \ No newline at end of file diff --git a/www/manager/node/Config.js b/www/manager/node/Config.js index 92af5279..fbd4a5c3 100644 --- a/www/manager/node/Config.js +++ b/www/manager/node/Config.js @@ -102,6 +102,12 @@ Ext.define('PVE.node.Config', { title: 'UBC', itemId: 'ubc', xtype: 'pveNodeBCFailCnt' + }, + { + title: 'Subscription', + itemId: 'support', + xtype: 'pveNodeSubscription', + nodename: nodename } ] }); diff --git a/www/manager/node/Subscription.js b/www/manager/node/Subscription.js new file mode 100644 index 00000000..150af418 --- /dev/null +++ b/www/manager/node/Subscription.js @@ -0,0 +1,126 @@ +Ext.define('PVE.node.SubscriptionKeyEdit', { + extend: 'PVE.window.Edit', + + initComponent : function() { + var me = this; + + Ext.apply(me, { + title: gettext('Upload Subscription Key'), + width: 300, + items: { + xtype: 'textfield', + name: 'key', + value: '', + fieldLabel: gettext('Subscription Key') + } + }); + + me.callParent(); + + me.load(); + } +}); + +Ext.define('PVE.node.Subscription', { + extend: 'PVE.grid.ObjectGrid', + + alias: ['widget.pveNodeSubscription'], + + features: [ {ftype: 'selectable'}], + + initComponent : function() { + var me = this; + + if (!me.nodename) { + throw "no node name specified"; + } + + var reload = function() { + me.rstore.load(); + }; + + var baseurl = '/nodes/' + me.nodename + '/subscription'; + + var render_status = function(value) { + + var message = me.getObjectValue('message'); + + if (message) { + return value + ": " + message; + } + return value; + }; + + var rows = { + productname: { + header: gettext('Type') + }, + key: { + header: gettext('Subscription Key') + }, + status: { + header: gettext('Status'), + renderer: render_status + }, + message: { + visible: false + }, + serverid: { + header: gettext('Server ID') + }, + sockets: { + header: 'Sockets' + }, + checktime: { + header: 'Last checked', + renderer: PVE.Utils.render_timestamp + } + }; + + Ext.applyIf(me, { + url: '/api2/json' + baseurl, + cwidth1: 170, + tbar: [ + { + text: gettext('Upload Subscription Key'), + handler: function() { + var win = Ext.create('PVE.node.SubscriptionKeyEdit', { + url: '/api2/extjs/' + baseurl + }); + win.show(); + win.on('destroy', reload); + } + }, + { + text: gettext('Check'), + handler: function() { + PVE.Utils.API2Request({ + params: { force: 1 }, + url: baseurl, + method: 'POST', + waitMsgTarget: me, + failure: function(response, opts) { + Ext.Msg.alert('Error', response.htmlStatus); + }, + callback: reload + }); + } + } + ], + rows: rows, + listeners: { + show: reload + } + }); + + me.callParent(); + } +}, function() { + + Ext.define('pve-services', { + extend: 'Ext.data.Model', + fields: [ 'service', 'name', 'desc', 'state' ], + idProperty: 'service' + }); + +});