"Fossies" - the Fresh Open Source Software Archive 
Member "vnstat-2.9/src/cfgoutput.c" (3 Jan 2022, 14501 Bytes) of package /linux/misc/vnstat-2.9.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "cfgoutput.c" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
2.8_vs_2.9.
1 #include "common.h"
2 #include "cfgoutput.h"
3
4 void printcfgfile(void)
5 {
6 ibwnode *p = ifacebw;
7
8 /* common / vnstat section */
9 printf("# vnStat %s configuration file\n", getversion());
10 printf("#\n");
11 printf("# lines starting with # or ; are comments, everything has default\n");
12 printf("# values, remove ; before each option to change its value\n\n\n");
13
14 if (cfg.experimental) {
15 printf("Experimental %d\n\n", cfg.experimental);
16 }
17
18 printf("# default interface (leave empty for automatic selection)\n");
19 defaultcomment(strcmp(cfg.iface, DEFIFACE) == 0);
20 printf("Interface \"%s\"\n\n", cfg.iface);
21
22 printf("# location of the database directory\n");
23 defaultcomment(strcmp(cfg.dbdir, DATABASEDIR) == 0);
24 printf("DatabaseDir \"%s\"\n\n", cfg.dbdir);
25
26 printf("# locale (LC_ALL) (\"-\" = use system locale)\n");
27 defaultcomment(strcmp(cfg.locale, LOCALE) == 0);
28 printf("Locale \"%s\"\n\n", cfg.locale);
29
30 printf("# date output formats for -d, -m, -t and -w\n");
31 defaultcomment(strcmp(cfg.dformat, DFORMAT) == 0);
32 printf("DayFormat \"%s\"\n", cfg.dformat);
33 defaultcomment(strcmp(cfg.mformat, MFORMAT) == 0);
34 printf("MonthFormat \"%s\"\n", cfg.mformat);
35 defaultcomment(strcmp(cfg.tformat, TFORMAT) == 0);
36 printf("TopFormat \"%s\"\n\n", cfg.tformat);
37
38 printf("# characters used for visuals\n");
39 defaultcomment(strcmp(cfg.rxchar, RXCHAR) == 0);
40 printf("RXCharacter \"%c\"\n", cfg.rxchar[0]);
41 defaultcomment(strcmp(cfg.txchar, TXCHAR) == 0);
42 printf("TXCharacter \"%c\"\n", cfg.txchar[0]);
43 defaultcomment(strcmp(cfg.rxhourchar, RXHOURCHAR) == 0);
44 printf("RXHourCharacter \"%c\"\n", cfg.rxhourchar[0]);
45 defaultcomment(strcmp(cfg.txhourchar, TXHOURCHAR) == 0);
46 printf("TXHourCharacter \"%c\"\n\n", cfg.txhourchar[0]);
47
48 printf("# how units are prefixed when traffic is shown\n");
49 printf("# 0 = IEC standard prefixes (KiB/MiB/GiB...)\n");
50 printf("# 1 = old style binary prefixes (KB/MB/GB...)\n");
51 printf("# 2 = SI decimal prefixes (kB/MB/GB...)\n");
52 defaultcomment(cfg.unitmode == UNITMODE);
53 printf("UnitMode %d\n\n", cfg.unitmode);
54
55 printf("# used rate unit (0 = bytes, 1 = bits)\n");
56 defaultcomment(cfg.rateunit == RATEUNIT);
57 printf("RateUnit %d\n\n", cfg.rateunit);
58
59 printf("# how units are prefixed when traffic rate is shown in bits\n");
60 printf("# 0 = IEC binary prefixes (Kibit/s...)\n");
61 printf("# 1 = SI decimal prefixes (kbit/s...)\n");
62 defaultcomment(cfg.rateunitmode == RATEUNITMODE);
63 printf("RateUnitMode %d\n\n", cfg.rateunitmode);
64
65 printf("# output style\n");
66 printf("# 0 = minimal & narrow, 1 = bar column visible\n");
67 printf("# 2 = same as 1 except rate in summary\n");
68 printf("# 3 = rate column visible\n");
69 defaultcomment(cfg.ostyle == OSTYLE);
70 printf("OutputStyle %d\n", cfg.ostyle);
71 defaultcomment(cfg.estimatebarvisible == ESTIMATEBARVISIBLE);
72 printf("EstimateBarVisible %d\n\n", cfg.estimatebarvisible);
73
74 printf("# number of decimals to use in outputs\n");
75 defaultcomment(cfg.defaultdecimals == DEFAULTDECIMALS);
76 printf("DefaultDecimals %d\n", cfg.defaultdecimals);
77 defaultcomment(cfg.hourlydecimals == HOURLYDECIMALS);
78 printf("HourlyDecimals %d\n\n", cfg.hourlydecimals);
79
80 printf("# spacer for separating hourly sections (0 = none, 1 = '|', 2 = '][', 3 = '[ ]')\n");
81 defaultcomment(cfg.hourlystyle == HOURLYSTYLE);
82 printf("HourlySectionStyle %d\n\n", cfg.hourlystyle);
83
84 printf("# how many seconds should sampling for -tr take by default\n");
85 defaultcomment(cfg.sampletime == DEFSAMPTIME);
86 printf("Sampletime %d\n\n", cfg.sampletime);
87
88 printf("# default query mode\n");
89 printf("# 0 = normal, 1 = days, 2 = months, 3 = top, 5 = short\n");
90 printf("# 7 = hours, 8 = xml, 9 = one line, 10 = json\n");
91 defaultcomment(cfg.qmode == DEFQMODE);
92 printf("QueryMode %d\n\n", cfg.qmode);
93
94 printf("# default list output entry limits (0 = all)\n");
95 defaultcomment(cfg.listfivemins == LISTFIVEMINS);
96 printf("List5Mins %2d\n", cfg.listfivemins);
97 defaultcomment(cfg.listhours == LISTHOURS);
98 printf("ListHours %2d\n", cfg.listhours);
99 defaultcomment(cfg.listdays == LISTDAYS);
100 printf("ListDays %2d\n", cfg.listdays);
101 defaultcomment(cfg.listmonths == LISTMONTHS);
102 printf("ListMonths %2d\n", cfg.listmonths);
103 defaultcomment(cfg.listyears == LISTYEARS);
104 printf("ListYears %2d\n", cfg.listyears);
105 defaultcomment(cfg.listtop == LISTTOP);
106 printf("ListTop %2d\n\n", cfg.listtop);
107
108 printf("# how to match interface given for query to interface in database\n");
109 printf("# 0 = case sensitive exact match to interface name\n");
110 printf("# 1 = method 0 followed by case sensitive exact match of alias\n");
111 printf("# 2 = method 1 followed by case insensitive exact match of alias\n");
112 printf("# 3 = method 2 followed by case insensitive beginning match of alias\n");
113 defaultcomment(cfg.ifacematchmethod == IFACEMATCHMETHOD);
114 printf("InterfaceMatchMethod %d\n\n", cfg.ifacematchmethod);
115
116 printf("\n");
117
118 /* vnstatd section */
119 printf("# vnstatd\n##\n\n");
120
121 printf("# switch to given user when started as root (leave empty to disable)\n");
122 defaultcomment(strlen(cfg.daemonuser) == 0);
123 printf("DaemonUser \"%s\"\n\n", cfg.daemonuser);
124
125 printf("# switch to given group when started as root (leave empty to disable)\n");
126 defaultcomment(strlen(cfg.daemongroup) == 0);
127 printf("DaemonGroup \"%s\"\n\n", cfg.daemongroup);
128
129 printf("# try to detect interface maximum bandwidth, 0 = disable feature\n");
130 printf("# MaxBandwidth will be used as fallback value when enabled\n");
131 defaultcomment(cfg.bwdetection == BWDETECT);
132 printf("BandwidthDetection %d\n\n", cfg.bwdetection);
133
134 printf("# maximum bandwidth (Mbit) for all interfaces, 0 = disable feature\n# (unless interface specific limit is given)\n");
135 defaultcomment(cfg.maxbw == DEFMAXBW);
136 printf("MaxBandwidth %d\n\n", cfg.maxbw);
137
138 printf("# interface specific limits\n");
139 printf("# example 8Mbit limit for eth0 (remove # to activate):\n");
140 printf("#MaxBWeth0 8\n");
141
142 while (p != NULL) {
143 printf("MaxBW%s %u\n", p->interface, p->limit);
144 p = p->next;
145 }
146
147 printf("\n");
148
149 printf("# data retention durations (-1 = unlimited, 0 = feature disabled)\n");
150 defaultcomment(cfg.fiveminutehours == FIVEMINUTEHOURS);
151 printf("5MinuteHours %2d\n", cfg.fiveminutehours);
152 defaultcomment(cfg.hourlydays == HOURLYDAYS);
153 printf("HourlyDays %2d\n", cfg.hourlydays);
154 defaultcomment(cfg.dailydays == DAILYDAYS);
155 printf("DailyDays %2d\n", cfg.dailydays);
156 defaultcomment(cfg.monthlymonths == MONTHLYMONTHS);
157 printf("MonthlyMonths %2d\n", cfg.monthlymonths);
158 defaultcomment(cfg.yearlyyears == YEARLYYEARS);
159 printf("YearlyYears %2d\n", cfg.yearlyyears);
160 defaultcomment(cfg.topdayentries == TOPDAYENTRIES);
161 printf("TopDayEntries %2d\n\n", cfg.topdayentries);
162
163 printf("# how often (in seconds) interface data is updated\n");
164 defaultcomment(cfg.updateinterval == UPDATEINTERVAL);
165 printf("UpdateInterval %d\n\n", cfg.updateinterval);
166
167 printf("# how often (in seconds) interface status changes are checked\n");
168 defaultcomment(cfg.pollinterval == POLLINTERVAL);
169 printf("PollInterval %d\n\n", cfg.pollinterval);
170
171 printf("# how often (in minutes) data is saved to database\n");
172 defaultcomment(cfg.saveinterval == SAVEINTERVAL);
173 printf("SaveInterval %d\n\n", cfg.saveinterval);
174
175 printf("# how often (in minutes) data is saved when all interface are offline\n");
176 defaultcomment(cfg.offsaveinterval == OFFSAVEINTERVAL);
177 printf("OfflineSaveInterval %d\n\n", cfg.offsaveinterval);
178
179 printf("# rescan database after save for new interfaces to be monitored (1 = enabled, 0 = disabled)\n");
180 defaultcomment(cfg.rescanonsave == RESCANONSAVE);
181 printf("RescanDatabaseOnSave %d\n\n", cfg.rescanonsave);
182
183 printf("# automatically start monitoring all interfaces not found in the database\n");
184 printf("# (1 = enabled, 0 = disabled)\n");
185 defaultcomment(cfg.alwaysadd == ALWAYSADD);
186 printf("AlwaysAddNewInterfaces %d\n\n", cfg.alwaysadd);
187
188 printf("# on which day should months change\n");
189 defaultcomment(cfg.monthrotate == MONTHROTATE);
190 printf("MonthRotate %d\n", cfg.monthrotate);
191 defaultcomment(cfg.monthrotateyears == MONTHROTATEYEARS);
192 printf("MonthRotateAffectsYears %d\n\n", cfg.monthrotateyears);
193
194 printf("# filesystem disk space check (1 = enabled, 0 = disabled)\n");
195 defaultcomment(cfg.spacecheck == USESPACECHECK);
196 printf("CheckDiskSpace %d\n\n", cfg.spacecheck);
197
198 printf("# how much the boot time can variate between updates (seconds)\n");
199 defaultcomment(cfg.bvar == BVAR);
200 printf("BootVariation %d\n\n", cfg.bvar);
201
202 printf("# create database entries even when there is no traffic (1 = enabled, 0 = disabled)\n");
203 defaultcomment(cfg.trafficlessentries == TRAFFICLESSENTRIES);
204 printf("TrafficlessEntries %d\n\n", cfg.trafficlessentries);
205
206 printf("# how many minutes to wait during daemon startup for system clock to\n");
207 printf("# sync time if most recent database update appears to be in the future\n");
208 defaultcomment(cfg.timesyncwait == TIMESYNCWAIT);
209 printf("TimeSyncWait %d\n\n", cfg.timesyncwait);
210
211 printf("# how often (in minutes) bandwidth detection is done when\n");
212 printf("# BandwidthDetection is enabled (0 = disabled)\n");
213 defaultcomment(cfg.bwdetectioninterval == BWDETECTINTERVAL);
214 printf("BandwidthDetectionInterval %d\n\n", cfg.bwdetectioninterval);
215
216 printf("# force data save when interface status changes (1 = enabled, 0 = disabled)\n");
217 defaultcomment(cfg.savestatus == SAVESTATUS);
218 printf("SaveOnStatusChange %d\n\n", cfg.savestatus);
219
220 printf("# enable / disable logging (0 = disabled, 1 = logfile, 2 = syslog)\n");
221 defaultcomment(cfg.uselogging == USELOGGING);
222 printf("UseLogging %d\n\n", cfg.uselogging);
223
224 printf("# create dirs if needed (1 = enabled, 0 = disabled)\n");
225 defaultcomment(cfg.createdirs == CREATEDIRS);
226 printf("CreateDirs %d\n\n", cfg.createdirs);
227
228 printf("# update ownership of files if needed (1 = enabled, 0 = disabled)\n");
229 defaultcomment(cfg.updatefileowner == UPDATEFILEOWNER);
230 printf("UpdateFileOwner %d\n\n", cfg.updatefileowner);
231
232 printf("# file used for logging if UseLogging is set to 1\n");
233 defaultcomment(strcmp(cfg.logfile, LOGFILE) == 0);
234 printf("LogFile \"%s\"\n\n", cfg.logfile);
235
236 printf("# file used as daemon pid / lock file\n");
237 defaultcomment(strcmp(cfg.pidfile, PIDFILE) == 0);
238 printf("PidFile \"%s\"\n\n", cfg.pidfile);
239
240 printf("# 1 = 64-bit, 0 = 32-bit, -1 = old style logic, -2 = automatic detection\n");
241 defaultcomment(cfg.is64bit == IS64BIT);
242 printf("64bitInterfaceCounters %d\n\n", cfg.is64bit);
243
244 printf("# use SQLite Write-Ahead Logging mode (1 = enabled, 0 = disabled)\n");
245 defaultcomment(cfg.waldb == WALDB);
246 printf("DatabaseWriteAheadLogging %d\n\n", cfg.waldb);
247
248 printf("# change the setting of the SQLite \"synchronous\" flag\n");
249 printf("# (-1 = auto, 0 = off, 1, = normal, 2 = full, 3 = extra)\n");
250 defaultcomment(cfg.dbsynchronous == DBSYNCHRONOUS);
251 printf("DatabaseSynchronous %d\n\n", cfg.dbsynchronous);
252
253 printf("# database uses UTC instead of local timezone (1 = enabled, 0 = disabled)\n");
254 defaultcomment(cfg.useutc == USEUTC);
255 printf("UseUTC %d\n\n", cfg.useutc);
256
257 printf("\n");
258
259 /* vnstati section */
260 printf("# vnstati\n##\n\n");
261
262 printf("# title timestamp format\n");
263 defaultcomment(strcmp(cfg.hformat, HFORMAT) == 0);
264 printf("HeaderFormat \"%s\"\n\n", cfg.hformat);
265
266 printf("# show hours with rate (1 = enabled, 0 = disabled)\n");
267 defaultcomment(cfg.hourlyrate == HOURLYRATE);
268 printf("HourlyRate %d\n\n", cfg.hourlyrate);
269
270 printf("# show rate in summary (1 = enabled, 0 = disabled)\n");
271 defaultcomment(cfg.summaryrate == SUMMARYRATE);
272 printf("SummaryRate %d\n\n", cfg.summaryrate);
273
274 printf("# transparent background (1 = enabled, 0 = disabled)\n");
275 defaultcomment(cfg.transbg == TRANSBG);
276 printf("TransparentBg %d\n\n", cfg.transbg);
277
278 printf("# image size control\n");
279 defaultcomment(cfg.largefonts == LARGEFONTS);
280 printf("LargeFonts %d\n", cfg.largefonts);
281 defaultcomment(cfg.linespaceadjust == LINESPACEADJUST);
282 printf("LineSpacingAdjustment %d\n", cfg.linespaceadjust);
283 defaultcomment(cfg.imagescale == IMAGESCALE);
284 printf("ImageScale %d\n\n", cfg.imagescale);
285
286 printf("# 5 minutes graph size control\n");
287 defaultcomment(cfg.fivegresultcount == FIVEGRESULTCOUNT);
288 printf("5MinuteGraphResultCount %d\n", cfg.fivegresultcount);
289 defaultcomment(cfg.fivegheight == FIVEGHEIGHT);
290 printf("5MinuteGraphHeight %d\n\n", cfg.fivegheight);
291
292 printf("# hourly graph mode (0 = 24 hour sliding window, 1 = begins from midnight)\n");
293 defaultcomment(cfg.hourlygmode == HOURLYGMODE);
294 printf("HourlyGraphMode %d\n\n", cfg.hourlygmode);
295
296 printf("# horizontal/vertical summary graph (0 = hours, 1 = 5 minutes)\n");
297 defaultcomment(cfg.summarygraph == SUMMARYGRAPH);
298 printf("SummaryGraph %d\n\n", cfg.summarygraph);
299
300 printf("# traffic estimate bar style\n");
301 printf("# (0 = not shown, 1 = continuation of existing bar, 2 = separate bar)\n");
302 defaultcomment(cfg.estimatestyle == ESTIMATESTYLE);
303 printf("EstimateStyle %d\n\n", cfg.estimatestyle);
304
305 printf("# bar column in list outputs shows rate if OutputStyle is 3\n");
306 printf("# (1 = enabled, 0 = disabled)\n");
307 defaultcomment(cfg.barshowsrate == BARSHOWSRATE);
308 printf("BarColumnShowsRate %d\n\n", cfg.barshowsrate);
309
310 printf("# image colors\n");
311 defaultcomment(strcmp(cfg.cbg, CBACKGROUND) == 0);
312 printf("CBackground \"%s\"\n", cfg.cbg);
313 defaultcomment(strcmp(cfg.cedge, CEDGE) == 0);
314 printf("CEdge \"%s\"\n", cfg.cedge);
315 defaultcomment(strcmp(cfg.cheader, CHEADER) == 0);
316 printf("CHeader \"%s\"\n", cfg.cheader);
317 defaultcomment(strcmp(cfg.cheadertitle, CHEADERTITLE) == 0);
318 printf("CHeaderTitle \"%s\"\n", cfg.cheadertitle);
319 defaultcomment(strcmp(cfg.cheaderdate, CHEADERDATE) == 0);
320 printf("CHeaderDate \"%s\"\n", cfg.cheaderdate);
321 defaultcomment(strcmp(cfg.ctext, CTEXT) == 0);
322 printf("CText \"%s\"\n", cfg.ctext);
323 defaultcomment(strcmp(cfg.cline, CLINE) == 0);
324 printf("CLine \"%s\"\n", cfg.cline);
325 defaultcomment(strcmp(cfg.clinel, CLINEL) == 0);
326 printf("CLineL \"%s\"\n", cfg.clinel);
327 defaultcomment(strcmp(cfg.crx, CRX) == 0);
328 printf("CRx \"%s\"\n", cfg.crx);
329 defaultcomment(strcmp(cfg.ctx, CTX) == 0);
330 printf("CTx \"%s\"\n", cfg.ctx);
331 defaultcomment(strcmp(cfg.crxd, CRXD) == 0);
332 printf("CRxD \"%s\"\n", cfg.crxd);
333 defaultcomment(strcmp(cfg.ctxd, CTXD) == 0);
334 printf("CTxD \"%s\"\n", cfg.ctxd);
335 }
336
337 void defaultcomment(const int isdefault)
338 {
339 if (isdefault) {
340 printf(";");
341 }
342 }