]> git.proxmox.com Git - pve-manager.git/commitdiff
cleanup subscription code
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 5 Apr 2012 06:04:06 +0000 (08:04 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 5 Apr 2012 06:04:06 +0000 (08:04 +0200)
PVE/API2/Subscription.pm
www/manager/Makefile
www/manager/StateProvider.js
www/manager/dc/Config.js
www/manager/dc/Support.js [new file with mode: 0644]
www/manager/node/Config.js
www/manager/node/Subscription.js [new file with mode: 0644]

index 9e9a7a47eef70a1ad5a2a07f58e7cee74d9142b6..f85cfeb8f604ea6e51e095661ea2be7f357e2c56 100644 (file)
@@ -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
     }});
 
index 3158fe33e5b2b662b1478ddd53a9aa5849527572..ce5deb10153d772bb6908c060d087379868bd7e5 100644 (file)
@@ -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
 
index cd30203abdc15f2c08ef0b3cc93b7f681167f02a..60974e9bb5273b4a0fb4d0a838f6262ed7ea0ecb 100644 (file)
@@ -49,6 +49,8 @@ Ext.define('PVE.StateProvider', {
     hprefix: 'v1',
 
     compDict: {
+       ha: 28,
+       support: 27,
        pool: 26,
        syslog: 25,
        ubc: 24,
index 7a953c350ec10cbb5f97b749c5335b43427aad17..5b891520bde2b6513e263ddb2a552cee0cc46bfa 100644 (file)
@@ -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 (file)
index 0000000..5549236
--- /dev/null
@@ -0,0 +1,78 @@
+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
index 92af5279e78dce7aa58b9f85112153dcc7906d25..fbd4a5c3b4a4288d6295d8b30a2c57d03d95c905 100644 (file)
@@ -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 (file)
index 0000000..150af41
--- /dev/null
@@ -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'
+    });
+
+});