1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | var CodeGradX = require('codegradxagent');
|
32 | var _ = require('lodash');
|
33 |
|
34 |
|
35 | module.exports = CodeGradX;
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | CodeGradX.VMauthorAgent = function () {
|
41 | function initializer (agent) {
|
42 |
|
43 | agent.configuration.push(['', 'ip=[IP]', 'VMauthor host name or IP']);
|
44 | return agent;
|
45 | }
|
46 | CodeGradX.Agent.call(this, initializer);
|
47 | };
|
48 | Object.setPrototypeOf(CodeGradX.VMauthorAgent.prototype,
|
49 | CodeGradX.Agent.prototype);
|
50 |
|
51 |
|
52 | CodeGradX.VMauthorAgent.vmhostname = 'vmauthor.codegradx.org';
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | CodeGradX.VMauthorAgent.prototype.adaptToVMauthor = function () {
|
60 | var agent = this;
|
61 | var vmhostname = CodeGradX.VMauthorAgent.vmhostname;
|
62 | if ( agent.commands &&
|
63 | agent.commands.options.ip ) {
|
64 | vmhostname = agent.commands.options.ip;
|
65 | }
|
66 | agent.state.servers = {
|
67 | names: ['a', 'e', 'x', 's'],
|
68 | domain: vmhostname,
|
69 | a: {
|
70 | suffix: '/alive',
|
71 | 0: {
|
72 | host: vmhostname + '/a'
|
73 | }
|
74 | },
|
75 | e: {
|
76 | suffix: '/alive',
|
77 | 0: {
|
78 | host: vmhostname + '/e',
|
79 | }
|
80 | },
|
81 | x: {
|
82 | suffix: '/dbalive',
|
83 | 0: {
|
84 | host: vmhostname + '/x',
|
85 | }
|
86 | },
|
87 | s: {
|
88 | suffix: '/index.html',
|
89 | protocol: 'http',
|
90 | 0: {
|
91 | host: vmhostname + '/s',
|
92 | }
|
93 | }
|
94 | };
|
95 | if ( CodeGradX.checkIfHTTPS() ) {
|
96 | var protocol = 'https';
|
97 | var ss = agent.state.servers;
|
98 | ss.protocol = protocol;
|
99 | ss.a.protocol = ss.a.protocol || protocol;
|
100 | ss.e.protocol = ss.e.protocol || protocol;
|
101 | ss.s.protocol = ss.s.protocol || protocol;
|
102 | ss.x.protocol = ss.x.protocol || protocol;
|
103 | process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
104 | }
|
105 | return agent;
|
106 | };
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 | CodeGradX.VMauthorAgent.prototype.process = function (strings) {
|
116 | var agent = this;
|
117 | return agent.parseOptions(strings).adaptToVMauthor().run();
|
118 | };
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | if ( _.endsWith(process.argv[1], 'codegradxvmauthor.js') ) {
|
126 |
|
127 | var agent = new CodeGradX.VMauthorAgent();
|
128 | function failure (exc) {
|
129 | console.log('Failure: ' + exc);
|
130 | CodeGradX.getCurrentState().log.show();
|
131 | process.exit(1);
|
132 | }
|
133 | try {
|
134 | return agent.process(process.argv.slice(2))
|
135 | .then(function () { process.exit(0) })
|
136 | .catch(failure);
|
137 | } catch (exc) {
|
138 | failure(exc);
|
139 | };
|
140 | }
|
141 |
|
142 |
|