-
Notifications
You must be signed in to change notification settings - Fork 2
/
mxsetsec.c
415 lines (372 loc) · 10 KB
/
mxsetsec.c
1
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
#include "nport.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#define ER_ARG -10
typedef struct _CONINFO
{
int idx;
char ipaddr[40];
char data[10];
char cmd[10];
char fifo[10];
int secure;
char tty[10];
char cout[10];
int num;
char scope_id[10];
int mode; /* mode : 0 RealCOM Mode, 1 Reduntant Mode*/
char ipaddr2[40];
}
CONINFO;
char svrList[256][40];
int total[256];
int idx, change_flag;
CONINFO info[256];
int SetSecure(int index);
int SelectNPort();
char* GetIP(unsigned long ip, char *ret)
{
struct in_addr ad;
ad.s_addr = ip;
sprintf(ret, "%s", inet_ntoa(ad));
return;
}
int SetSecure(int index)
{
int i, j, s, start, ret, page=0;
struct in_addr ad;
unsigned long ip;
char c[5];
for (i = 0; i < 256; i++)
{
if (!strcmp(info[i].ipaddr, svrList[index]))
break;
}
while (1)
{
int tot=0;
system("clear");
printf("Set Security Parameter ...\n");
printf("<<Port Selection>>\n");
printf("\n[Index]\t%-40s\t[Port]\t[Security]\n", "[Server IP]");
s = 0;
while (!strcmp(svrList[index], info[s+i].ipaddr))
{
tot++;
if (info[s+i].num > (page+1)*16 || info[s+i].num <= page*16)
{
s++;
continue;
}
if (info[s+i].secure)
printf(" (%d)\t%-40s\t %d\t Yes", s+1, info[s+i].ipaddr, info[s+i].num);
else
printf(" (%d)\t%-40s\t %d\t No", s+1, info[s+i].ipaddr, info[s+i].num);
printf("\n");
s++;
}
if(info[i].secure == 0)
printf(" (a)\tEnable all port\n");
else
printf(" (a)\tDisable all port\n");
if (tot > 16)
{
if (page == 0)
printf(" (n)\tnext page\n");
if (page == 1)
printf(" (p)\tprevious page\n");
}
printf(" (q)\tback to model selection\n");
printf("\nPlease select a port you want to change security setting: ");
scanf("%s", c);
if ((c[0] == 'q') || (c[0] == 'Q'))
{
break;
}
if ((c[0] == 'n') || (c[0] == 'N'))
{
if (page == 0 && tot>16)
page++;
}
if ((c[0] == 'p') || (c[0] == 'P'))
{
if (page == 1 && tot>16)
page--;
}
else if ((c[0] == 'a') || (c[0] == 'A'))
{
int secure = !info[i].secure;
for(j=0; j<tot; j++)
{
info[i+j].secure = secure;
}
change_flag = 1;
}
else if ((atoi(c) > 0) && (atoi(c) <= s))
{
j = atoi(c) - 1;
change_flag = 1;
if (info[i+j].secure)
info[i+j].secure = 0;
else
info[i+j].secure = 1;
}
}
return 1;
}
int SelectNPort()
{
int i, ret;
struct in_addr ad;
char c[5];
system("clear");
printf("Set Security Parameter ...\n");
printf("<<Model Selection>>\n");
printf("\n[Index]\t%-40s\t[Port(s)]\n", "[Server IP]");
for (i=0; i<idx; i++)
{
printf(" (%d)\t%-40s\t %d\n", i+1, svrList[i], total[i]);
}
printf(" (q)\tExit \n");
printf("\nPlease select a model you want to set up: ");
scanf("%s", c);
if ((c[0] == 'q') || (c[0] == 'Q'))
return -1;
if (atoi(c)<=0 || atoi(c)>idx)
return 0;
else
{
ret = SetSecure(atoi(c)-1);
// SelectNPort();
}
return 0;
}
int main(int arg, char *argv[])
{
int i, j;
int len, daemon, num, ret;
char *tmpstr, *tmp, *os;
char token[40], tty[10], cout[10], major[20], del[16], sec[10], index[10];
char data[10], cmd[10], fifo[10], scope[10];
char token2[40];
char mode[10];
FILE *f, *ft;
idx = 0;
daemon = 0;
change_flag = 0;
tmpstr = (char *)malloc(1024);
len = 1024;
tmp = (char *)malloc(20);
memset(scope, 0x0, sizeof(scope));
memset(svrList, 0x0, 256*40);
memset(total, 0x0, 256*sizeof(int));
memset(info, 0x0, 256*sizeof(CONINFO));
sprintf(tmpstr, "%s/mxcfmat", DRIVERPATH);
system(tmpstr);
sprintf(tmpstr, "%s/npreal2d.cf", DRIVERPATH);
f = fopen (tmpstr, "r");
if (f == NULL)
{
printf("file open error\n");
free(tmpstr);
free(tmp);
return(0);
}
/* print the list of installed server */
for (;;)
{
if (getline (&tmpstr, &len, f) < 0)
{
break;
}
if (strstr(tmpstr, "#") != NULL)
{
continue;
}
memset(major, '\0', 20);
sscanf(tmpstr, "%s", major);
if (strstr(major, "ttymajor") != NULL ||
strstr(major, "calloutmajor") != NULL )
{
continue;
}
sscanf(tmpstr, "%s%s%s%s%s%s%s%s%s%s%s", index, token, data, cmd, fifo, sec, tty, cout, scope, mode, token2);
num = atoi(index);
for (i=0; i<idx; i++)
{
if (!strcmp(svrList[i],token))
{
total[i]++;
info[num].idx = num;
strcpy(info[num].ipaddr, token);
strcpy(info[num].data, data);
strcpy(info[num].cmd, cmd);
strcpy(info[num].fifo, fifo);
info[num].secure = atoi(sec);
strcpy(info[num].tty, tty);
strcpy(info[num].cout, cout);
info[num].num = total[i];
strcpy(info[num].scope_id, scope);
info[num].mode = atoi(mode);
strcpy(info[num].ipaddr2, token2);
break;
}
}
if (i == idx)
{
strcpy(svrList[idx], token);
total[idx]++;
info[num].idx = num;
strcpy(info[num].ipaddr, token);
strcpy(info[num].data, data);
strcpy(info[num].cmd, cmd);
strcpy(info[num].fifo, fifo);
info[num].secure = atoi(sec);
strcpy(info[num].tty, tty);
strcpy(info[num].cout, cout);
info[num].num = total[i];
strcpy(info[num].scope_id, scope);
info[num].mode = atoi(mode);
strcpy(info[num].ipaddr2, token2);
idx++;
}
}
fclose (f);
if (idx == 0)
{
printf("No NPort server is installed.\n\n");
free(tmpstr);
free(tmp);
return 0;
}
while(SelectNPort() == 0)
{}
printf("Exit!!\n\n");
sprintf(tmpstr, "%s/npreal2d.cf", DRIVERPATH);
f = fopen (tmpstr, "r");
if (f == NULL)
{
printf("file open error\n");
free(tmpstr);
free(tmp);
return(0);
}
ft = fopen ("/tmp/nprtmp_cf", "w");
if (ft == NULL)
{
printf("file open error\n");
free(tmpstr);
free(tmp);
return(0);
}
for (;;)
{
if (getline (&tmpstr, &len, f) < 0)
{
break;
}
if (strstr(tmpstr, "#") != NULL)
{
fputs (tmpstr, ft);
continue;
}
memset(major, '\0', 20);
sscanf(tmpstr, "%s", major);
if (strstr(major, "ttymajor") != NULL ||
strstr(major, "calloutmajor") != NULL )
{
fputs (tmpstr, ft);
continue;
}
for (i=0; i<256; i++)
{
if (strlen(info[i].ipaddr) > 0)
{
#if 1
sprintf (tmpstr, "%d\t%s\t%s\t%s\t%s\t%d %s\t%s\t%s\t%d\t%s\n", info[i].idx, info[i].ipaddr,
info[i].data, info[i].cmd, info[i].fifo, info[i].secure, info[i].tty, info[i].cout, info[i].scope_id,
info[i].mode, info[i].ipaddr2);
#else
sprintf (tmpstr, "%d\t%s\t%s\t%s\t%s\t%d %s\t%s\t%s\n", info[i].idx, info[i].ipaddr,
info[i].data, info[i].cmd, info[i].fifo, info[i].secure, info[i].tty, info[i].cout, info[i].scope_id);
#endif
fputs (tmpstr, ft);
/* daemon is a flag which is used to delete the */
/* daemon start string in /etc/rc.d/rc.local */
if (change_flag)
daemon = 1;
}
}
break;
}
fclose(ft);
fclose (f);
os = "linux";
f = fopen ("/etc/redhat-release", "r");
if (f != NULL)
{
fclose(f);
os = "linux";
}
else
{
f = fopen ("/etc/SuSE-release", "r");
if (f != NULL)
{
fclose(f);
os = "SuSE";
}
else
{
f = fopen ("/etc/debian_version", "r");
if (f != NULL)
{
os = "debian";
}
}
}
if (!daemon)
{
if (os == "linux")
{
system("grep -v mxloadsvr /etc/rc.d/rc.local > /tmp/nprtmp_rclocal");
system("cp -f /tmp/nprtmp_rclocal /etc/rc.d/rc.local > /dev/null 2>&1");
system("rm -f /tmp/nprtmp_rclocal");
}
else if (os == "debian")
{
system("grep -v mxloadsvr /etc/init.d/npreals > /tmp/nprtmp_rclocal");
system("cp -f /tmp/nprtmp_rclocal /etc/init.d/npreals > /dev/null 2>&1");
system("rm -f /tmp/nprtmp_rclocal");
system("update-rc.d npreals defaults 90");
}
else if (os == "SuSE")
{
system("grep -v mxloadsvr /etc/rc.d/boot.local > /tmp/nprtmp_rclocal");
system("cp -f /tmp/nprtmp_rclocal /etc/rc.d/boot.local > /dev/null 2>&1");
system("rm -f /tmp/nprtmp_rclocal");
}
}
sprintf(tmpstr, "cp -f /tmp/nprtmp_cf %s/npreal2d.cf", DRIVERPATH);
system(tmpstr);
system("rm -f /tmp/nprtmp_cf");
sprintf(tmpstr, "%s/mxloadsvr", DRIVERPATH);
system(tmpstr);
if (os == "linux")
{
system("chmod +x /etc/rc.d/rc.local");
}
else if (os == "debian")
{
system("chmod +x /etc/init.d/npreals");
}
else if (os == "SuSE")
{
system("chmod +x /etc/rc.d/boot.local");
}
free(tmpstr);
free(tmp);
return 0;
}