Commit 15392924 authored by Dietmar Maurer's avatar Dietmar Maurer

cleanup subscription code

parent dcea6074
......@@ -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
}});
......
......@@ -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
......
......@@ -49,6 +49,8 @@ Ext.define('PVE.StateProvider', {
hprefix: 'v1',
compDict: {
ha: 28,
support: 27,
pool: 26,
syslog: 25,
ubc: 24,
......
......@@ -63,6 +63,11 @@ Ext.define('PVE.dc.Config', {
xtype: 'pveDcHAConfig',
title: 'HA',
itemId: 'ha'
},
{
xtype: 'pveDcSupport',
title: gettext('Support'),
itemId: 'support'
}
]
});
......
Ext.define('PVE.dc.Support', {
extend: 'Ext.panel.Panel',
alias: 'widget.pveDcSupport',
invalidHtml: '<h1>No valid subscription</h1>You do not have a valid subscription for this server. Please visit <a target="_blank" href="https://www.proxmox.com/products/proxmox-ve/subscription-service-plans">www.proxmox.com</a> to get a list of available options.',
communityHtml: 'Please use the public community <a target="_blank" href="http://forum.proxmox.com">forum</a> for any questions.',
activeHtml: 'Please use our <a target="_blank" href="http://my.proxmox.com">support portal</a> for any questions. You can also use the public community <a target="_blank" href="http://forum.proxmox.com">forum</a> to get additional information.',
bugzillaHtml: '<h1>Bug Tracking</h1>Our bug tracking system is available <a target="_blank" href="https://bugzilla.proxmox.com">here</a>.',
docuHtml: '<h1>Documentation</h1>Complete documentation, tutorials, videos and more is available at our <a target="_blank" href="https://pve.proxmox.com/wiki/Documentation">wiki</a>.',
updateActive: function(data) {
var me = this;
var html = '<h1>' + data.productname + '</h1>' + me.activeHtml;
html += '<br><br>' + me.docuHtml;
html += '<br><br>' + me.bugzillaHtml;
me.update(html);
},
updateCommunity: function(data) {
var me = this;
var html = '<h1>' + data.productname + '</h1>' + me.communityHtml;
html += '<br><br>' + me.docuHtml;
html += '<br><br>' + 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
......@@ -102,6 +102,12 @@ Ext.define('PVE.node.Config', {
title: 'UBC',
itemId: 'ubc',
xtype: 'pveNodeBCFailCnt'
},
{
title: 'Subscription',
itemId: 'support',
xtype: 'pveNodeSubscription',
nodename: nodename
}
]
});
......
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'
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment