-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtauthorize.c
757 lines (659 loc) · 19.8 KB
/
tauthorize.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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
/*
FILE
tAuthorize source code of unxsVZ.cgi
Built by mysqlRAD2.cgi (C) Gary Wallis and Hugo Urquiza 2001-2009
(C) 2010-2016 Gary Wallis for Unixservice, LLC.
PURPOSE
Schema dependent RAD generated file.
Program app functionality in tauthorizefunc.h while
RAD is still to be used.
*/
#include "mysqlrad.h"
//Table Variables
//uAuthorize: Primary Key
static unsigned uAuthorize=0;
//cLabel: Short label
static char cLabel[33]={""};
//cIPMask: Allow user from this IP
static char cIPMask[21]={"0.0.0.0/0"};
//uPerm: User permission level
static unsigned uPerm=0;
//uCertClient: User uClient
static unsigned uCertClient=0;
//cPasswd: Encrypted cgi login password
static char cPasswd[101]={""};
//cClrPasswd: Optionally used non encrypted login password
static char cClrPasswd[33]={""};
//uOwner: Record owner
static unsigned uOwner=0;
//uCreatedBy: uClient for last insert
static unsigned uCreatedBy=0;
//uCreatedDate: Unix seconds date last insert
static time_t uCreatedDate=0;
//uModBy: uClient for last update
static unsigned uModBy=0;
//uModDate: Unix seconds date last update
static time_t uModDate=0;
//cOTPSecret: OATH TOPT or HOPT key
static char cOTPSecret[65]={""};
//uOTPExpire: Unix seconds date last when cOTPSecret is no longer valid. If 0 do not
//require OTP
static time_t uOTPExpire=0;
//git describe version info
static char *cGitVersion="GitVersion:"GitVersion;
#define VAR_LIST_tAuthorize "tAuthorize.uAuthorize,tAuthorize.cLabel,tAuthorize.cIPMask,tAuthorize.uPerm,tAuthorize.uCertClient,tAuthorize.cPasswd,tAuthorize.cClrPasswd,tAuthorize.uOwner,tAuthorize.uCreatedBy,tAuthorize.uCreatedDate,tAuthorize.uModBy,tAuthorize.uModDate,tAuthorize.cOTPSecret,tAuthorize.uOTPExpire"
//Local only
void Insert_tAuthorize(void);
void Update_tAuthorize(char *cRowid);
void ProcesstAuthorizeListVars(pentry entries[], int x);
//In tAuthorizefunc.h file included below
void ExtProcesstAuthorizeVars(pentry entries[], int x);
void ExttAuthorizeCommands(pentry entries[], int x);
void ExttAuthorizeButtons(void);
void ExttAuthorizeNavBar(void);
void ExttAuthorizeGetHook(entry gentries[], int x);
void ExttAuthorizeSelect(void);
void ExttAuthorizeSelectRow(void);
void ExttAuthorizeListSelect(void);
void ExttAuthorizeListFilter(void);
void ExttAuthorizeAuxTable(void);
//
char *cOATHOneTimePasswd(const char *cOTPSecret);
#include "tauthorizefunc.h"
//Table Variables Assignment Function
void ProcesstAuthorizeVars(pentry entries[], int x)
{
register int i;
for(i=0;i<x;i++)
{
if(!strcmp(entries[i].name,"uAuthorize"))
sscanf(entries[i].val,"%u",&uAuthorize);
else if(!strcmp(entries[i].name,"cLabel"))
sprintf(cLabel,"%.32s",entries[i].val);
else if(!strcmp(entries[i].name,"cIPMask"))
sprintf(cIPMask,"%.20s",entries[i].val);
else if(!strcmp(entries[i].name,"uPerm"))
sscanf(entries[i].val,"%u",&uPerm);
else if(!strcmp(entries[i].name,"uCertClient"))
sscanf(entries[i].val,"%u",&uCertClient);
else if(!strcmp(entries[i].name,"cPasswd"))
sprintf(cPasswd,"%.100s",entries[i].val);
else if(!strcmp(entries[i].name,"cClrPasswd"))
sprintf(cClrPasswd,"%.32s",entries[i].val);
else if(!strcmp(entries[i].name,"uOwner"))
sscanf(entries[i].val,"%u",&uOwner);
else if(!strcmp(entries[i].name,"uCreatedBy"))
sscanf(entries[i].val,"%u",&uCreatedBy);
else if(!strcmp(entries[i].name,"uCreatedDate"))
sscanf(entries[i].val,"%lu",&uCreatedDate);
else if(!strcmp(entries[i].name,"uModBy"))
sscanf(entries[i].val,"%u",&uModBy);
else if(!strcmp(entries[i].name,"uModDate"))
sscanf(entries[i].val,"%lu",&uModDate);
else if(!strcmp(entries[i].name,"cOTPSecret"))
sprintf(cOTPSecret,"%.64s",entries[i].val);
else if(!strcmp(entries[i].name,"uOTPExpire"))
sscanf(entries[i].val,"%lu",&uOTPExpire);
}
//After so we can overwrite form data if needed.
ExtProcesstAuthorizeVars(entries,x);
}//ProcesstAuthorizeVars()
void ProcesstAuthorizeListVars(pentry entries[], int x)
{
register int i;
for(i=0;i<x;i++)
{
if(!strncmp(entries[i].name,"ED",2))
{
sscanf(entries[i].name+2,"%u",&uAuthorize);
guMode=2002;
tAuthorize("");
}
}
}//void ProcesstAuthorizeListVars(pentry entries[], int x)
int tAuthorizeCommands(pentry entries[], int x)
{
ProcessControlVars(entries,x);
ExttAuthorizeCommands(entries,x);
if(!strcmp(gcFunction,"tAuthorizeTools"))
{
if(!strcmp(gcFind,LANG_NB_LIST))
{
tAuthorizeList();
}
//Default
ProcesstAuthorizeVars(entries,x);
tAuthorize("");
}
else if(!strcmp(gcFunction,"tAuthorizeList"))
{
ProcessControlVars(entries,x);
ProcesstAuthorizeListVars(entries,x);
tAuthorizeList();
}
return(0);
}//tAuthorizeCommands()
void tAuthorize(const char *cResult)
{
MYSQL_RES *res;
MYSQL_RES *res2;
MYSQL_ROW field;
//Internal skip reloading
if(!cResult[0])
{
if(guMode)
ExttAuthorizeSelectRow();
else
ExttAuthorizeSelect();
mysql_query(&gMysql,gcQuery);
if(mysql_errno(&gMysql))
{
if(strstr(mysql_error(&gMysql)," doesn't exist"))
{
CreatetAuthorize();
unxsVZ("New tAuthorize table created");
}
else
{
htmlPlainTextError(mysql_error(&gMysql));
}
}
res=mysql_store_result(&gMysql);
if((guI=mysql_num_rows(res)))
{
if(guMode==6)
{
sprintf(gcQuery,"SELECT _rowid FROM tAuthorize WHERE uAuthorize=%u"
,uAuthorize);
macro_mySQLRunAndStore(res2);
field=mysql_fetch_row(res2);
sscanf(field[0],"%lu",&gluRowid);
gluRowid++;
}
PageMachine("",0,"");
if(!guMode) mysql_data_seek(res,gluRowid-1);
field=mysql_fetch_row(res);
sscanf(field[0],"%u",&uAuthorize);
sprintf(cLabel,"%.32s",field[1]);
sprintf(cIPMask,"%.20s",field[2]);
sscanf(field[3],"%u",&uPerm);
sscanf(field[4],"%u",&uCertClient);
sprintf(cPasswd,"%.100s",field[5]);
sprintf(cClrPasswd,"%.32s",field[6]);
sscanf(field[7],"%u",&uOwner);
sscanf(field[8],"%u",&uCreatedBy);
sscanf(field[9],"%lu",&uCreatedDate);
sscanf(field[10],"%u",&uModBy);
sscanf(field[11],"%lu",&uModDate);
sprintf(cOTPSecret,"%.64s",field[12]);
sscanf(field[13],"%lu",&uOTPExpire);
}
}//Internal Skip
Header_ism3(":: tAuthorize",0);
printf("<table width=100%% cellspacing=0 cellpadding=0>\n");
printf("<tr><td colspan=2 align=right valign=center>");
printf("<input type=hidden name=gcFunction value=tAuthorizeTools>");
printf("<input type=hidden name=gluRowid value=%lu>",gluRowid);
if(guI)
{
if(guMode==6)
//printf(" Found");
printf(LANG_NBR_FOUND);
else if(guMode==5)
//printf(" Modified");
printf(LANG_NBR_MODIFIED);
else if(guMode==4)
//printf(" New");
printf(LANG_NBR_NEW);
printf(LANG_NBRF_SHOWING,gluRowid,guI);
}
else
{
if(!cResult[0])
//printf(" No records found");
printf(LANG_NBR_NORECS);
}
if(cResult[0]) printf("%s",cResult);
printf("</td></tr>");
printf("<tr><td valign=top width=25%%>");
ExttAuthorizeButtons();
printf("</td><td valign=top>");
//
OpenFieldSet("tAuthorize Record Data",100);
if(guMode==2000 || guMode==2002)
tAuthorizeInput(1);
else
tAuthorizeInput(0);
//
CloseFieldSet();
//Bottom table
printf("<tr><td colspan=2>");
ExttAuthorizeAuxTable();
Footer_ism3();
}//end of tAuthorize();
void tAuthorizeInput(unsigned uMode)
{
//uAuthorize
OpenRow(LANG_FL_tAuthorize_uAuthorize,"black");
printf("<input title='%s' type=text name=uAuthorize value=%u size=16 maxlength=10 "
,LANG_FT_tAuthorize_uAuthorize,uAuthorize);
if(guPermLevel>=20 && uMode)
{
printf("></td></tr>\n");
}
else
{
printf("disabled></td></tr>\n");
printf("<input type=hidden name=uAuthorize value=%u >\n",uAuthorize);
}
//cLabel
OpenRow(LANG_FL_tAuthorize_cLabel,"black");
printf("<input title='%s' type=text name=cLabel value=\"%s\" size=40 maxlength=32 "
,LANG_FT_tAuthorize_cLabel,EncodeDoubleQuotes(cLabel));
if(guPermLevel>=0 && uMode)
{
printf("></td></tr>\n");
}
else
{
printf("disabled></td></tr>\n");
printf("<input type=hidden name=cLabel value=\"%s\">\n",EncodeDoubleQuotes(cLabel));
}
//cIPMask
OpenRow(LANG_FL_tAuthorize_cIPMask,"black");
printf("<input title='%s' type=text name=cIPMask value=\"%s\" size=40 maxlength=20 "
,LANG_FT_tAuthorize_cIPMask,EncodeDoubleQuotes(cIPMask));
if(guPermLevel>=0 && uMode)
{
printf("></td></tr>\n");
}
else
{
printf("disabled></td></tr>\n");
printf("<input type=hidden name=cIPMask value=\"%s\">\n",EncodeDoubleQuotes(cIPMask));
}
//uPerm
OpenRow(LANG_FL_tAuthorize_uPerm,"black");
printf("<input title='%s' type=text name=uPerm value=%u size=16 maxlength=10 "
,LANG_FT_tAuthorize_uPerm,uPerm);
if(guPermLevel>=0 && uMode)
{
printf("> %s</td></tr>\n",cUserLevel(uPerm));
}
else
{
printf("disabled> %s</td></tr>\n",cUserLevel(uPerm));
printf("<input type=hidden name=uPerm value=%u >\n",uPerm);
}
//uCertClient
OpenRow(LANG_FL_tAuthorize_uCertClient,"black");
printf("<input title='%s' type=text name=uCertClient value=%u size=16 maxlength=10 "
,LANG_FT_tAuthorize_uCertClient,uCertClient);
if(guPermLevel>=0 && uMode)
{
printf("></td></tr>\n");
}
else
{
printf("disabled></td></tr>\n");
printf("<input type=hidden name=uCertClient value=%u >\n",uCertClient);
}
//cPasswd
OpenRow(LANG_FL_tAuthorize_cPasswd,"black");
if(guPermLevel<12 && uPerm>10)
{
printf("private");
}
else
{
printf("<input title='%s' type=text name=cPasswd value=\"%s\" size=40 maxlength=100 "
,LANG_FT_tAuthorize_cPasswd,EncodeDoubleQuotes(cPasswd));
if(guPermLevel>=0 && uMode)
{
printf("></td></tr>\n");
}
else
{
printf("disabled></td></tr>\n");
printf("<input type=hidden name=cPasswd value=\"%s\">\n",EncodeDoubleQuotes(cPasswd));
}
}
//cClrPasswd
OpenRow(LANG_FL_tAuthorize_cClrPasswd,"black");
if(guPermLevel<12 && uPerm>10)
{
printf("private");
}
else
{
printf("<input title='%s' type=text name=cClrPasswd value=\"%s\" size=40 maxlength=32 "
,LANG_FT_tAuthorize_cClrPasswd,EncodeDoubleQuotes(cClrPasswd));
if(guPermLevel>=0 && uMode)
{
printf("></td></tr>\n");
}
else
{
printf("disabled></td></tr>\n");
printf("<input type=hidden name=cClrPasswd value=\"%s\">\n",EncodeDoubleQuotes(cClrPasswd));
}
}
//uOwner
OpenRow(LANG_FL_tAuthorize_uOwner,"black");
if(guPermLevel>=20 && uMode)
{
printf("%s<input type=hidden name=uOwner value=%u >\n",ForeignKey("tClient","cLabel",uOwner),uOwner);
}
else
{
printf("%s<input type=hidden name=uOwner value=%u >\n",ForeignKey("tClient","cLabel",uOwner),uOwner);
}
//uCreatedBy
OpenRow(LANG_FL_tAuthorize_uCreatedBy,"black");
if(guPermLevel>=20 && uMode)
{
printf("%s<input type=hidden name=uCreatedBy value=%u >\n",ForeignKey("tClient","cLabel",uCreatedBy),uCreatedBy);
}
else
{
printf("%s<input type=hidden name=uCreatedBy value=%u >\n",ForeignKey("tClient","cLabel",uCreatedBy),uCreatedBy);
}
//uCreatedDate
OpenRow(LANG_FL_tAuthorize_uCreatedDate,"black");
if(uCreatedDate)
printf("%s\n\n",ctime(&uCreatedDate));
else
printf("---\n\n");
printf("<input type=hidden name=uCreatedDate value=%lu >\n",uCreatedDate);
//uModBy
OpenRow(LANG_FL_tAuthorize_uModBy,"black");
if(guPermLevel>=20 && uMode)
{
printf("%s<input type=hidden name=uModBy value=%u >\n",ForeignKey("tClient","cLabel",uModBy),uModBy);
}
else
{
printf("%s<input type=hidden name=uModBy value=%u >\n",ForeignKey("tClient","cLabel",uModBy),uModBy);
}
//uModDate
OpenRow(LANG_FL_tAuthorize_uModDate,"black");
if(uModDate)
printf("%s\n\n",ctime(&uModDate));
else
printf("---\n\n");
printf("<input type=hidden name=uModDate value=%lu >\n",uModDate);
//cOTPSecret
OpenRow("cOTPSecret","black");
if(guPermLevel<12 && uPerm>10)
{
printf("private");
}
else
{
printf("<input title='%s' type=text name=cOTPSecret value=\"%s\" size=40 maxlength=64 ",
"liboath TOTP or HTOP base32 key",cOTPSecret);
if(guPermLevel>=0 && uMode)
{
printf("></td></tr>\n");
}
else
{
printf("disabled>");
if(cOTPSecret[0] && cLabel[0])
{
char *cp;
if((cp=strchr(cLabel,' ')))
*cp=0;
printf(" <img src=\"https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl="
"otpauth://totp/%.31s%%3Fsecret%%3D%.20s\"/>",
cLabel,cOTPSecret);
printf(" Validation code: %s",cOATHOneTimePasswd(cOTPSecret));
}
printf("</td></tr>\n");
printf("<input type=hidden name=cOTPSecret value=\"%s\">\n",cOTPSecret);
}
}
//uOTPExpire
OpenRow("uOTPExpire","black");
if(uOTPExpire)
{
time_t timeNow=time(NULL);
printf("%s %lus left\n\n",ctime(&uOTPExpire),(uOTPExpire-timeNow));
}
else
printf("---\n\n");
printf("<input type=hidden name=uOTPExpire value=%lu >\n",uOTPExpire);
printf("</tr>\n");
}//void tAuthorizeInput(unsigned uMode)
void NewtAuthorize(unsigned uMode)
{
register int i=0;
MYSQL_RES *res;
sprintf(gcQuery,"SELECT uAuthorize FROM tAuthorize WHERE uAuthorize=%u"
,uAuthorize);
macro_mySQLRunAndStore(res);
i=mysql_num_rows(res);
if(i)
//tAuthorize("<blink>Record already exists");
tAuthorize(LANG_NBR_RECEXISTS);
//insert query
Insert_tAuthorize();
//sprintf(gcQuery,"New record %u added");
uAuthorize=mysql_insert_id(&gMysql);
uCreatedDate=luGetCreatedDate("tAuthorize",uAuthorize);
unxsVZLog(uAuthorize,"tAuthorize","New");
if(!uMode)
{
sprintf(gcQuery,LANG_NBR_NEWRECADDED,uAuthorize);
tAuthorize(gcQuery);
}
}//NewtAuthorize(unsigned uMode)
void DeletetAuthorize(void)
{
sprintf(gcQuery,"DELETE FROM tAuthorize WHERE uAuthorize=%u AND ( uOwner=%u OR %u>9 )"
,uAuthorize,guLoginClient,guPermLevel);
macro_mySQLQueryHTMLError;
//tAuthorize("Record Deleted");
if(mysql_affected_rows(&gMysql)>0)
{
unxsVZLog(uAuthorize,"tAuthorize","Del");
tAuthorize(LANG_NBR_RECDELETED);
}
else
{
unxsVZLog(uAuthorize,"tAuthorize","DelError");
tAuthorize(LANG_NBR_RECNOTDELETED);
}
}//void DeletetAuthorize(void)
void Insert_tAuthorize(void)
{
//insert query
sprintf(gcQuery,"INSERT INTO tAuthorize SET uAuthorize=%u,cLabel='%s',cIPMask='%s',uPerm=%u,uCertClient=%u,cPasswd='%s',cClrPasswd='%s',uOwner=%u,uCreatedBy=%u,uCreatedDate=UNIX_TIMESTAMP(NOW())",
uAuthorize
,TextAreaSave(cLabel)
,TextAreaSave(cIPMask)
,uPerm
,uCertClient
,TextAreaSave(cPasswd)
,TextAreaSave(cClrPasswd)
,uOwner
,uCreatedBy
);
macro_mySQLQueryHTMLError;
}//void Insert_tAuthorize(void)
void Update_tAuthorize(char *cRowid)
{
//update query
sprintf(gcQuery,"UPDATE tAuthorize SET uAuthorize=%u,cLabel='%s',cIPMask='%s',uPerm=%u,uCertClient=%u,cPasswd='%s',cClrPasswd='%s',uModBy=%u,uModDate=UNIX_TIMESTAMP(NOW()),cOTPSecret='%s',uOTPExpire=%lu WHERE _rowid=%s",
uAuthorize
,TextAreaSave(cLabel)
,TextAreaSave(cIPMask)
,uPerm
,uCertClient
,TextAreaSave(cPasswd)
,TextAreaSave(cClrPasswd)
,uModBy
,TextAreaSave(cOTPSecret)
,uOTPExpire
,cRowid);
macro_mySQLQueryHTMLError;
}//void Update_tAuthorize(void)
void ModtAuthorize(void)
{
register int i=0;
MYSQL_RES *res;
MYSQL_ROW field;
unsigned uPreModDate=0;
//Mod select gcQuery
if(guPermLevel<10)
sprintf(gcQuery,"SELECT tAuthorize.uAuthorize,\
tAuthorize.uModDate\
FROM tAuthorize,tClient\
WHERE tAuthorize.uAuthorize=%u\
AND tAuthorize.uOwner=tClient.uClient\
AND (tClient.uOwner=%u OR tClient.uClient=%u)"
,uAuthorize,guLoginClient,guLoginClient);
else
sprintf(gcQuery,"SELECT uAuthorize,uModDate FROM tAuthorize\
WHERE uAuthorize=%u"
,uAuthorize);
macro_mySQLRunAndStore(res);
i=mysql_num_rows(res);
//if(i<1) tAuthorize("<blink>Record does not exist");
if(i<1) tAuthorize(LANG_NBR_RECNOTEXIST);
//if(i>1) tAuthorize("<blink>Multiple rows!");
if(i>1) tAuthorize(LANG_NBR_MULTRECS);
field=mysql_fetch_row(res);
sscanf(field[1],"%u",&uPreModDate);
if(uPreModDate!=uModDate) tAuthorize(LANG_NBR_EXTMOD);
Update_tAuthorize(field[0]);
if(mysql_errno(&gMysql)) htmlPlainTextError(mysql_error(&gMysql));
//sprintf(query,"record %s modified",field[0]);
sprintf(gcQuery,LANG_NBRF_REC_MODIFIED,field[0]);
uModDate=luGetModDate("tAuthorize",uAuthorize);
unxsVZLog(uAuthorize,"tAuthorize","Mod");
tAuthorize(gcQuery);
}//ModtAuthorize(void)
void tAuthorizeList(void)
{
MYSQL_RES *res;
MYSQL_ROW field;
ExttAuthorizeListSelect();
macro_mySQLRunAndStore(res);
guI=mysql_num_rows(res);
PageMachine("tAuthorizeList",1,"");//1 is auto header list guMode. Opens table!
//Filter select drop down
ExttAuthorizeListFilter();
printf("<input type=text size=16 name=gcCommand maxlength=98 value=\"%s\" >",gcCommand);
printf("</table>\n");
printf("<table bgcolor=#9BC1B3 border=0 width=100%%>\n");
printf("<tr bgcolor=black>"
"<td><font face=arial,helvetica color=white>uAuthorize"
"<td><font face=arial,helvetica color=white>cLabel"
"<td><font face=arial,helvetica color=white>cIPMask"
"<td><font face=arial,helvetica color=white>uPerm"
"<td><font face=arial,helvetica color=white>uCertClient"
"<td><font face=arial,helvetica color=white>cPasswd"
"<td><font face=arial,helvetica color=white>cClrPasswd"
"<td><font face=arial,helvetica color=white>uOwner"
"<td><font face=arial,helvetica color=white>uCreatedBy"
"<td><font face=arial,helvetica color=white>uCreatedDate"
"<td><font face=arial,helvetica color=white>uModBy"
"<td><font face=arial,helvetica color=white>uModDate"
"<td><font face=arial,helvetica color=white>cOTPSecret"
"<td><font face=arial,helvetica color=white>uOTPExpire"
"</tr>");
mysql_data_seek(res,guStart-1);
for(guN=0;guN<(guEnd-guStart+1);guN++)
{
field=mysql_fetch_row(res);
if(!field)
{
printf("<tr><td><font face=arial,helvetica>End of data</table>");
Footer_ism3();
}
if(guN % 2)
printf("<tr bgcolor=#BBE1D3>");
else
printf("<tr>");
time_t luTime9=strtoul(field[9],NULL,10);
char cBuf9[32];
if(luTime9)
ctime_r(&luTime9,cBuf9);
else
sprintf(cBuf9,"---");
time_t luTime11=strtoul(field[11],NULL,10);
char cBuf11[32];
if(luTime11)
ctime_r(&luTime11,cBuf11);
else
sprintf(cBuf11,"---");
time_t luTime13=strtoul(field[13],NULL,10);
char cBuf13[32];
if(luTime13)
ctime_r(&luTime13,cBuf13);
else
sprintf(cBuf13,"---");
printf("<td><a class=darkLink href=unxsVZ.cgi?gcFunction=tAuthorize&uAuthorize=%s>%s"
"<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s<td>%s</tr>"
,field[0]
,field[0]
,field[1]
,field[2]
,field[3]
,field[4]
,field[5]
,field[6]
,ForeignKey("tClient","cLabel",strtoul(field[7],NULL,10))
,ForeignKey("tClient","cLabel",strtoul(field[8],NULL,10))
,cBuf9
,ForeignKey("tClient","cLabel",strtoul(field[10],NULL,10))
,cBuf11
,field[12]
,cBuf13
);
}
printf("</table></form>\n");
Footer_ism3();
}//tAuthorizeList()
void CreatetAuthorize(void)
{
sprintf(gcQuery,"CREATE TABLE IF NOT EXISTS tAuthorize ( "
"uAuthorize INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,"
"cLabel VARCHAR(32) NOT NULL DEFAULT '',"
"UNIQUE (cLabel,uOwner),"
"uOwner INT UNSIGNED NOT NULL DEFAULT 0,"
"INDEX (uOwner),"
"uCreatedBy INT UNSIGNED NOT NULL DEFAULT 0,"
"uCreatedDate INT UNSIGNED NOT NULL DEFAULT 0,"
"uModBy INT UNSIGNED NOT NULL DEFAULT 0,"
"uModDate INT UNSIGNED NOT NULL DEFAULT 0,"
"cIPMask VARCHAR(20) NOT NULL DEFAULT '',"
"uPerm INT UNSIGNED NOT NULL DEFAULT 0,"
"uCertClient INT UNSIGNED NOT NULL DEFAULT 0,"
"cPasswd VARCHAR(100) NOT NULL DEFAULT '',"
"cClrPasswd VARCHAR(32) NOT NULL DEFAULT '',"
"cOTPSecret VARCHAR(64) NOT NULL DEFAULT '',"
"uOTPExpire INT UNSIGNED NOT NULL DEFAULT 0 )");
macro_mySQLQueryHTMLError;
}//CreatetAuthorize()
char *cOATHOneTimePasswd(const char *cOTPSecret)
{
char *secret;
size_t secretlen=0;
int rc;
static char otp[10]="error";
time_t now=time(NULL);
rc=oath_init();
if(rc==OATH_OK)
{
rc=oath_base32_decode(cOTPSecret,strlen(cOTPSecret),&secret,&secretlen);
if(rc==OATH_OK)
{
rc=oath_totp_generate(secret,secretlen,now,30,0,6,otp);
if(rc==OATH_OK)
sprintf(otp,"%.9s",otp);
}
}
return(otp);
}//char *cOATHOneTimePasswd(const char *cOTPSecret)