-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.c
164 lines (144 loc) · 3.95 KB
/
template.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
/*
* vQadmin Virtual Administration Interface
* Copyright (C) 2000-2002 Inter7 Internet Technologies, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include "global.h"
#include "config.h"
/* undefine vaiables conflicting with analog vpopmail vars imported from vpopmail config.h */
#undef VERSION
#undef QMAILDIR
#undef PACKAGE_VERSION
#undef PACKAGE_TARNAME
#undef PACKAGE_STRING
#undef PACKAGE_NAME
#undef PACKAGE
#include "vpopmail_config.h"
extern char vqa_error[],
vqa_user[],
vqa_group[],
vqa_warning[];
void t_code(char code)
{
switch(code) {
case 'V':
printf("<a href=\"https://notes.sagredo.eu/en/qmail-notes-185/vqadmin-26.html\" target=\"_blank\">%s</a> %s ~ ", VQA_PACKAGE, VQA_VERSION);
printf("<a href=\"https://notes.sagredo.eu/en/qmail-notes-185/installing-and-configuring-vpopmail-81.html\">%s</a> %s", PACKAGE, VERSION);
break;
case 'E':
t_printf(vqa_error);
break;
case 'W':
global_f_warning();
break;
case 'U':
t_printf(vqa_user);
break;
case 'G':
t_printf(vqa_group);
break;
default:
break;
}
}
void g_code(char *id)
{
char *r = NULL;
r = f_global_par(id);
t_printf(r);
}
void t_printf(char *str)
{
if ((str) && (str[0])) printf("%s", str);
}
void t_open(char *filename, int exit_when_done)
{
FILE *stream = NULL;
char *p = NULL, b[MAX_TEMPLATE_LINE_LENGTH], t = 0;
struct stat mystat;
if ( lstat( filename, &mystat ) == -1 || S_ISLNK(mystat.st_mode) ) {
printf("Unable to retrieve file informations: %s\n",filename);
vclose();
exit(-1);
}
stream = fopen(filename, "r");
if (stream == NULL) {
printf("Dag Nabit\n");
tfatal();
}
while(1) {
memset((char *)b, 0, MAX_TEMPLATE_LINE_LENGTH);
fgets(b, MAX_TEMPLATE_LINE_LENGTH, stream);
if (feof(stream)) break;
for (p = b; *p; p++) {
if ((*p == '$') && (*(p + 1) == '-')) {
t = *(p + 4);
*(p + 4) = '\0';
g_code(p + 2);
*(p + 4) = t;
p += 3;
} else if ((*p == '%') && (*(p + 1) == '-')) {
t_code(*(p + 2));
p += 2;
} else if ((*p == '#') && (*(p + 1) == '-')) {
put_lang_code((p+2));
p += 4;
} else {
putchar(*p);
}
}
}
fclose(stream);
if ( exit_when_done == 1 ) {
vclose();
exit(0);
}
}
/* internal page template */
void t_page(char *filename, int exit_when_done) {
char tmpbuf[256];
snprintf(tmpbuf, sizeof(tmpbuf), "%s/vqadmin/%s", CGIBINDIR, T_HEADER);
t_open(tmpbuf,0);
memset(tmpbuf,0,sizeof(tmpbuf));
snprintf(tmpbuf, sizeof(tmpbuf), "%s/vqadmin/%s", CGIBINDIR, filename);
t_open(tmpbuf,0);
memset(tmpbuf,0,sizeof(tmpbuf));
if ( strcmp(filename, T_MAIN) != 0 ) {
snprintf(tmpbuf, sizeof(tmpbuf), "%s/vqadmin/%s", CGIBINDIR, T_COL);
t_open(tmpbuf,0);
memset(tmpbuf,0,sizeof(tmpbuf));
}
snprintf(tmpbuf, sizeof(tmpbuf), "%s/vqadmin/%s", CGIBINDIR, T_FOOTER);
if ( exit_when_done == 1 ) {
t_open(tmpbuf,1);
vclose();
exit(0);
}
else t_open(tmpbuf,0);
}
/* home page template (no side menu) */
void t_main(int exit_when_done) {
t_page(T_MAIN, exit_when_done);
}