]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/Parser.js
1 // Some configuration values are complex strings -
2 // so we need parsers/generators for them.
4 Ext
.define('PVE.Parser', { statics
: {
6 // this class only contains static functions
8 parseACME: function(value
) {
16 Ext
.Array
.each(value
.split(','), function(p
) {
17 if (!p
|| p
.match(/^\s*$/)) {
22 if ((match_res
= p
.match(/^(?:domains=)?((?:[a-zA-Z0-9\-\.]+[;, ]?)+)$/)) !== null) {
23 res
.domains
= match_res
[1].split(/[;, ]/);
37 parseBoolean: function(value
, default_value
) {
38 if (!Ext
.isDefined(value
)) {
41 value
= value
.toLowerCase();
42 return value
=== '1' ||
48 parsePropertyString: function(value
, defaultKey
) {
52 Ext
.Array
.each(value
.split(','), function(p
) {
53 var kv
= p
.split('=', 2);
54 if (Ext
.isDefined(kv
[1])) {
56 } else if (Ext
.isDefined(defaultKey
)) {
57 if (Ext
.isDefined(res
[defaultKey
])) {
58 error
= 'defaultKey may be only defined once in propertyString';
59 return false; // break
61 res
[defaultKey
] = kv
[0];
63 error
= 'invalid propertyString, not a key=value pair and no defaultKey defined';
64 return false; // break
68 if (error
!== undefined) {
76 printPropertyString: function(data
, defaultKey
) {
79 Ext
.Object
.each(data
, function(key
, value
) {
80 if (defaultKey
!== undefined && key
=== defaultKey
) {
81 stringparts
.unshift(value
);
83 stringparts
.push(key
+ '=' + value
);
87 return stringparts
.join(',');
90 parseQemuNetwork: function(key
, value
) {
91 if (!(key
&& value
)) {
98 Ext
.Array
.each(value
.split(','), function(p
) {
99 if (!p
|| p
.match(/^\s*$/)) {
105 if ((match_res
= p
.match(/^(ne2k_pci|e1000|e1000-82540em|e1000-82544gc|e1000-82545em|vmxnet3|rtl8139|pcnet|virtio|ne2k_isa|i82551|i82557b|i82559er)(=([0-9a-f]{2}(:[0-9a-f]{2}){5}))?$/i)) !== null) {
106 res
.model
= match_res
[1].toLowerCase();
108 res
.macaddr
= match_res
[3];
110 } else if ((match_res
= p
.match(/^bridge=(\S+)$/)) !== null) {
111 res
.bridge
= match_res
[1];
112 } else if ((match_res
= p
.match(/^rate=(\d+(\.\d+)?)$/)) !== null) {
113 res
.rate
= match_res
[1];
114 } else if ((match_res
= p
.match(/^tag=(\d+(\.\d+)?)$/)) !== null) {
115 res
.tag
= match_res
[1];
116 } else if ((match_res
= p
.match(/^firewall=(\d+)$/)) !== null) {
117 res
.firewall
= match_res
[1];
118 } else if ((match_res
= p
.match(/^link_down=(\d+)$/)) !== null) {
119 res
.disconnect
= match_res
[1];
120 } else if ((match_res
= p
.match(/^queues=(\d+)$/)) !== null) {
121 res
.queues
= match_res
[1];
122 } else if ((match_res
= p
.match(/^trunks=(\d+(?:-\d+)?(?:;\d+(?:-\d+)?)*)$/)) !== null) {
123 res
.trunks
= match_res
[1];
126 return false; // break
130 if (errors
|| !res
.model
) {
137 printQemuNetwork: function(net
) {
139 var netstr
= net
.model
;
141 netstr
+= "=" + net
.macaddr
;
144 netstr
+= ",bridge=" + net
.bridge
;
146 netstr
+= ",tag=" + net
.tag
;
149 netstr
+= ",firewall=" + net
.firewall
;
153 netstr
+= ",rate=" + net
.rate
;
156 netstr
+= ",queues=" + net
.queues
;
158 if (net
.disconnect
) {
159 netstr
+= ",link_down=" + net
.disconnect
;
162 netstr
+= ",trunks=" + net
.trunks
;
167 parseQemuDrive: function(key
, value
) {
168 if (!(key
&& value
)) {
174 var match_res
= key
.match(/^([a-z]+)(\d+)$/);
178 res
['interface'] = match_res
[1];
179 res
.index
= match_res
[2];
182 Ext
.Array
.each(value
.split(','), function(p
) {
183 if (!p
|| p
.match(/^\s*$/)) {
186 var match_res
= p
.match(/^([a-z_]+)=(\S+)$/);
188 if (!p
.match(/\=/)) {
193 return false; // break
195 var k
= match_res
[1];
196 if (k
=== 'volume') {
200 if (Ext
.isDefined(res
[k
])) {
202 return false; // break
205 var v
= match_res
[2];
207 if (k
=== 'cache' && v
=== 'off') {
214 if (errors
|| !res
.file
) {
221 printQemuDrive: function(drive
) {
223 var drivestr
= drive
.file
;
225 Ext
.Object
.each(drive
, function(key
, value
) {
226 if (!Ext
.isDefined(value
) || key
=== 'file' ||
227 key
=== 'index' || key
=== 'interface') {
230 drivestr
+= ',' + key
+ '=' + value
;
236 parseIPConfig: function(key
, value
) {
237 if (!(key
&& value
)) {
244 Ext
.Array
.each(value
.split(','), function(p
) {
245 if (!p
|| p
.match(/^\s*$/)) {
250 if ((match_res
= p
.match(/^ip=(\S+)$/)) !== null) {
251 res
.ip
= match_res
[1];
252 } else if ((match_res
= p
.match(/^gw=(\S+)$/)) !== null) {
253 res
.gw
= match_res
[1];
254 } else if ((match_res
= p
.match(/^ip6=(\S+)$/)) !== null) {
255 res
.ip6
= match_res
[1];
256 } else if ((match_res
= p
.match(/^gw6=(\S+)$/)) !== null) {
257 res
.gw6
= match_res
[1];
260 return false; // break
271 printIPConfig: function(cfg
) {
275 str
+= "ip=" + cfg
.ip
;
279 str
+= c
+ "gw=" + cfg
.gw
;
283 str
+= c
+ "ip6=" + cfg
.ip6
;
287 str
+= c
+ "gw6=" + cfg
.gw6
;
293 parseOpenVZNetIf: function(value
) {
301 Ext
.Array
.each(value
.split(';'), function(item
) {
302 if (!item
|| item
.match(/^\s*$/)) {
307 Ext
.Array
.each(item
.split(','), function(p
) {
308 if (!p
|| p
.match(/^\s*$/)) {
311 var match_res
= p
.match(/^(ifname|mac|bridge|host_ifname|host_mac|mac_filter)=(\S+)$/);
314 return false; // break
316 if (match_res
[1] === 'bridge'){
317 var bridgevlanf
= match_res
[2];
318 var bridge_res
= bridgevlanf
.match(/^(vmbr(\d+))(v(\d+))?(f)?$/);
321 return false; // break
323 data
.bridge
= bridge_res
[1];
324 data
.tag
= bridge_res
[4];
325 /*jslint confusion: true*/
326 data
.firewall
= bridge_res
[5] ? 1 : 0;
327 /*jslint confusion: false*/
329 data
[match_res
[1]] = match_res
[2];
333 if (errors
|| !data
.ifname
) {
335 return false; // break
340 res
[data
.ifname
] = data
;
343 return errors
? undefined: res
;
346 printOpenVZNetIf: function(netif
) {
349 Ext
.Object
.each(netif
, function(iface
, data
) {
351 Ext
.Array
.each(['ifname', 'mac', 'bridge', 'host_ifname' , 'host_mac', 'mac_filter', 'tag', 'firewall'], function(key
) {
352 var value
= data
[key
];
353 if (key
=== 'bridge'){
355 value
= value
+ 'v' + data
.tag
;
362 tmparray
.push(key
+ '=' + value
);
366 netarray
.push(tmparray
.join(','));
369 return netarray
.join(';');
372 parseLxcNetwork: function(value
) {
378 Ext
.Array
.each(value
.split(','), function(p
) {
379 if (!p
|| p
.match(/^\s*$/)) {
382 var match_res
= p
.match(/^(bridge|hwaddr|mtu|name|ip|ip6|gw|gw6|tag|rate)=(\S+)$/);
384 data
[match_res
[1]] = match_res
[2];
385 } else if ((match_res
= p
.match(/^firewall=(\d+)$/)) !== null) {
386 data
.firewall
= PVE
.Parser
.parseBoolean(match_res
[1]);
388 // todo: simply ignore errors ?
396 printLxcNetwork: function(data
) {
398 Ext
.Array
.each(['bridge', 'hwaddr', 'mtu', 'name', 'ip',
399 'gw', 'ip6', 'gw6', 'firewall', 'tag'], function(key
) {
400 var value
= data
[key
];
402 tmparray
.push(key
+ '=' + value
);
406 /*jslint confusion: true*/
408 tmparray
.push('rate=' + data
.rate
);
410 /*jslint confusion: false*/
411 return tmparray
.join(',');
414 parseLxcMountPoint: function(value
) {
422 Ext
.Array
.each(value
.split(','), function(p
) {
423 if (!p
|| p
.match(/^\s*$/)) {
426 var match_res
= p
.match(/^([a-z_]+)=(.+)$/);
428 if (!p
.match(/\=/)) {
433 return false; // break
435 var k
= match_res
[1];
436 if (k
=== 'volume') {
440 if (Ext
.isDefined(res
[k
])) {
442 return false; // break
445 var v
= match_res
[2];
450 if (errors
|| !res
.file
) {
454 var m
= res
.file
.match(/^([a-z][a-z0-9\-\_\.]*[a-z0-9]):/i);
458 } else if (res
.file
.match(/^\/dev\//)) {
467 printLxcMountPoint: function(mp
) {
468 var drivestr
= mp
.file
;
470 Ext
.Object
.each(mp
, function(key
, value
) {
471 if (!Ext
.isDefined(value
) || key
=== 'file' ||
472 key
=== 'type' || key
=== 'storage') {
475 drivestr
+= ',' + key
+ '=' + value
;
481 parseStartup: function(value
) {
482 if (value
=== undefined) {
489 Ext
.Array
.each(value
.split(','), function(p
) {
490 if (!p
|| p
.match(/^\s*$/)) {
496 if ((match_res
= p
.match(/^(order)?=(\d+)$/)) !== null) {
497 res
.order
= match_res
[2];
498 } else if ((match_res
= p
.match(/^up=(\d+)$/)) !== null) {
499 res
.up
= match_res
[1];
500 } else if ((match_res
= p
.match(/^down=(\d+)$/)) !== null) {
501 res
.down
= match_res
[1];
504 return false; // break
515 printStartup: function(startup
) {
517 if (startup
.order
!== undefined && startup
.order
!== '') {
518 arr
.push('order=' + startup
.order
);
520 if (startup
.up
!== undefined && startup
.up
!== '') {
521 arr
.push('up=' + startup
.up
);
523 if (startup
.down
!== undefined && startup
.down
!== '') {
524 arr
.push('down=' + startup
.down
);
527 return arr
.join(',');
530 parseQemuSmbios1: function(value
) {
533 Ext
.Array
.each(value
.split(','), function(p
) {
534 var kva
= p
.split('=', 2);
535 res
[kva
[0]] = kva
[1];
541 printQemuSmbios1: function(data
) {
545 Ext
.Object
.each(data
, function(key
, value
) {
546 if (value
=== '') { return; }
547 datastr
+= (datastr
!== '' ? ',' : '') + key
+ '=' + value
;
553 parseTfaConfig: function(value
) {
556 Ext
.Array
.each(value
.split(','), function(p
) {
557 var kva
= p
.split('=', 2);
558 res
[kva
[0]] = kva
[1];
564 parseTfaType: function(value
) {
565 /*jslint confusion: true*/
567 if (!value
|| !value
.length
) {
569 } else if (value
=== 'x!oath') {
571 } else if (!!(match
= value
.match(/^x!(.+)$/))) {
578 parseQemuCpu: function(value
) {
586 Ext
.Array
.each(value
.split(','), function(p
) {
587 if (!p
|| p
.match(/^\s*$/)) {
591 if (!p
.match(/\=/)) {
592 if (Ext
.isDefined(res
.cpu
)) {
594 return false; // break
600 var match_res
= p
.match(/^([a-z_]+)=(\S+)$/);
603 return false; // break
606 var k
= match_res
[1];
607 if (Ext
.isDefined(res
[k
])) {
609 return false; // break
612 res
[k
] = match_res
[2];
615 if (errors
|| !res
.cputype
) {
622 printQemuCpu: function(cpu
) {
623 var cpustr
= cpu
.cputype
;
626 Ext
.Object
.each(cpu
, function(key
, value
) {
627 if (!Ext
.isDefined(value
) || key
=== 'cputype') {
630 optstr
+= ',' + key
+ '=' + value
;
635 return 'kvm64' + optstr
;
640 return cpustr
+ optstr
;
643 parseSSHKey: function(key
) {
644 // |--- options can have quotes--| type key comment
645 var keyre
= /^(?:((?:[^\s"]|\"(?:\\.|[^"\\])*")+)\s+)?(\S+)\s+(\S+)(?:\s+(.*))?$/;
646 var typere
= /^(?:ssh-(?:dss|rsa|ed25519)|ecdsa-sha2-nistp\d+)$/;
648 var m
= key
.match(keyre
);
652 if (m
.length
< 3 || !m
[2]) { // [2] is always either type or key
655 if (m
[1] && m
[1].match(typere
)) {
662 if (m
[2].match(typere
)) {