source: gsdl/trunk/runtime-src/src/w32server/settings.cpp@ 19210

Last change on this file since 19210 was 19210, checked in by davidb, 15 years ago

Local Library Server can now either be configured to connects from anywhere or be restricted to only allow local connections. The option is controlled by setting 'externalaccess' to 1 or 0 appropriately. A widget for this is provided under File/Settings

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 28.0 KB
Line 
1/**********************************************************************
2 *
3 * settings.cpp
4 * Copyright (C) 1996
5 *
6 * A component of the fnord webserver written by [email protected].
7 *
8 * Altered for use with the Greenstone digital library software by the
9 * New Zealand Digital Library Project at the University of Waikato,
10 * New Zealand.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *
26 *********************************************************************/
27
28#include "text_t.h"
29#include "fileutil.h"
30
31#if defined(GSDL_USE_OBJECTSPACE)
32# include <ospace\std\fstream>
33#elif defined(GSDL_USE_IOS_H)
34# include <fstream.h>
35#else
36# include <fstream>
37#endif
38
39#include <windows.h>
40#include "httpsrv.h"
41#include "settings.h"
42#include "locate.h"
43#include "resource.h"
44#include "cgiwrapper.h"
45
46// library settings
47text_t gsdl_enterlib;
48text_t gsdl_gsdlhome;
49text_t gsdl_collecthome;
50text_t gsdl_dbhome;
51text_t gsdl_collections;
52colinfo_tmap gsdl_collectinfo;
53
54char gsdl_staticpages[MAX_FILENAME_SIZE];
55
56// debug settings
57char gsdl_log_name[MAX_FILENAME_SIZE] = "c:\\gsdl.log";
58int gsdl_keep_log = 0;
59int gsdl_show_console = 0;
60
61// general settings
62int gsdl_port_num = 80;
63int gsdl_external_access = 0;
64int gsdl_auto_enter = 0;
65int gsdl_browser = GS_DEFAULT;
66char gsdl_browser_exe[MAX_FILENAME_SIZE] = "";
67text_t gsdl_url;
68text_t gsdl_conffile;
69int gsdl_start_browser = 1;
70int gsdl_address_resolution_method = 2; // use localhost since users may switch between computers
71// The resolution method was previously on 1: Get an IP, but don't resolve to a name
72
73// private data
74
75// pathnames of the latest installed versions of netscape and
76// internet explorer
77static char netscape_exe[MAX_FILENAME_SIZE]="";
78static char iexplore_exe[MAX_FILENAME_SIZE]="";
79
80// pathname of the default browser
81static char default_browser_exe[MAX_FILENAME_SIZE]="";
82
83// whether netscape is needed (used in the settings dialog box)
84static int gsdl_netscapeneeded = 0;
85
86static void remove_end_slashes(char *str) {
87 int len = strlen (str);
88 while ((len > 0) && ((str[len-1] == '\\') || (str[len-1] == '/'))) {
89 --len;
90 }
91 str[len] = '\0';
92}
93
94static void remove_end_slashes (text_t &str) {
95 char *cstr = str.getcstr();
96 remove_end_slashes (cstr);
97 str = cstr;
98 delete []cstr;
99}
100
101// returns 1 if successful, 0 otherwise
102// checks for a file's existence
103static int check_program_exe (char *path) {
104 UINT curerrormode;
105 OFSTRUCT reOpenBuff;
106 int retvalue = 0;
107
108 reOpenBuff.cBytes = sizeof (OFSTRUCT);
109
110 curerrormode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
111 if (OpenFile(path, &reOpenBuff, OF_EXIST) != HFILE_ERROR) retvalue = 1;
112 SetErrorMode(curerrormode);
113
114 return retvalue;
115}
116
117
118// returns 1 if successful, 0 otherwise
119static int get_default_browser_path (char *providedhtmltype, char *path, int maxsize) {
120 HKEY hk1, hk2;
121 char htmltype[256];
122 long size;
123 int retval = 0;
124
125 htmltype[0] = '\0';
126 path[0] = '\0';
127
128 // try and get information about the default browser from the
129 // registry
130
131 if (providedhtmltype != NULL) strcpy (htmltype, providedhtmltype);
132
133 else if (RegOpenKey(HKEY_CLASSES_ROOT, ".htm", &hk1) == ERROR_SUCCESS) {
134 size = 256;
135 RegQueryValue(hk1, NULL, htmltype, &size);
136 RegCloseKey(hk1);
137 }
138
139 if (RegOpenKey(HKEY_CLASSES_ROOT, htmltype, &hk1) == ERROR_SUCCESS) {
140 if (RegOpenKey(hk1, "shell\\open", &hk2) == ERROR_SUCCESS) {
141 // look for the command to start the browser
142 size = maxsize;
143 if (RegQueryValue(hk2,"command",path,&size) == ERROR_SUCCESS) {
144 // strip all excess stuff off the command
145 char endchar = ' ';
146 int i = 0, len = 0;
147 int state = 0; // 0=strip initial white-space and quotes, 1=grab path
148 while (path[i] != '\0') {
149 if (state == 0) {
150 if (path[i] == ' ') {
151 // do nothing
152 } else if (path[i] == '"') {
153 endchar = '"';
154 state = 1;
155 } else {
156 state = 1;
157 path[len] = path[i];
158 ++len;
159 }
160 } else {
161 if (path[i] == endchar) break;
162 path[len] = path[i];
163 ++len;
164 }
165 ++i;
166 }
167 path[len] = '\0';
168
169 // check the resulting pathname
170 if (check_program_exe (path)) {
171 retval = 1; // succeeded
172 } else {
173 path[0] = '\0'; // failed (must have been deleted or something...)
174 }
175 }
176 RegCloseKey(hk2);
177 }
178 RegCloseKey(hk1);
179 }
180
181 return retval;
182}
183
184
185// returns 1 if successful, 0 otherwise
186// note that appname should include .exe (e.g. netscape.exe)
187static int registry_get_app_paths (char *appname, char *path, int maxsize) {
188 HKEY hk1;
189 long size;
190 int retval = 0;
191
192 path[0] = '\0';
193
194 if (RegOpenKey(HKEY_LOCAL_MACHINE,
195 "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths",
196 &hk1) == ERROR_SUCCESS) {
197 size = maxsize;
198 if (RegQueryValue (hk1, appname, path, &size) == ERROR_SUCCESS &&
199 check_program_exe (path));
200 retval = 1;
201
202 RegCloseKey(hk1);
203 }
204
205 return retval;
206}
207
208static void check_installed_browsers (int netscapeneeded) {
209 netscape_exe[0] = '\0';
210 iexplore_exe[0] = '\0';
211 default_browser_exe[0] = '\0';
212
213 // update the default browser information (if netscape isn't needed)
214 if (!netscapeneeded) {
215 get_default_browser_path (NULL, default_browser_exe, MAX_FILENAME_SIZE);
216 _strlwr (default_browser_exe);
217 }
218
219 // look for netscape
220
221 // first look for netscape in the registry
222 if (!registry_get_app_paths("netscape.exe", netscape_exe, MAX_FILENAME_SIZE)) {
223 // next look for "NetscapeMarkup"
224 if (get_default_browser_path ("NetscapeMarkup", netscape_exe, MAX_FILENAME_SIZE)) {
225 _strlwr (netscape_exe);
226 if (!strstr (netscape_exe, "netscape.exe")) {
227 netscape_exe[0] = '\0';
228
229 // next look for \netscape\netscape.exe
230
231 // get drive letter of the windows directory
232 GetWindowsDirectory(netscape_exe, MAX_FILENAME_SIZE);
233 netscape_exe[1] = '\0';
234 strcat (netscape_exe, ":\\netscape\\netscape.exe");
235
236 if (!check_program_exe (netscape_exe)) {
237 // lastly look for \netscape\program\netscape.exe
238 netscape_exe[1] = '\0';
239 strcat (netscape_exe, ":\\netscape\\program\\netscape.exe");
240
241 }
242 }
243 }
244 }
245 _strlwr (netscape_exe);
246 if ((strlen (netscape_exe) > 0) && !check_program_exe (netscape_exe)) {
247 netscape_exe[0] = '\0'; // couldn't find netscape
248 }
249
250 // look for internet explorer (if netscape isn't needed)
251
252 // first look for iexplore in the registry
253 if (!netscapeneeded && !registry_get_app_paths("iexplore.exe",
254 iexplore_exe, MAX_FILENAME_SIZE)) {
255 // next look for "htmlfile"
256 if (get_default_browser_path ("htmlfile", iexplore_exe, MAX_FILENAME_SIZE)) {
257 _strlwr (iexplore_exe);
258 if (!strstr (iexplore_exe, "iexplore.exe")) {
259 iexplore_exe[0] = '\0';
260
261 // next look for \iexplore\iexplore.exe
262
263 // get drive letter of the windows directory
264 GetWindowsDirectory(iexplore_exe, MAX_FILENAME_SIZE);
265 iexplore_exe[1] = '\0';
266 strcat (iexplore_exe, ":\\iexplore\\iexplore.exe");
267 }
268 }
269 }
270 _strlwr (iexplore_exe);
271 if ((strlen (iexplore_exe) > 0) && !check_program_exe (iexplore_exe)) {
272 iexplore_exe[0] = '\0'; // couldn't find internet explorer
273 }
274}
275
276void write_settings (const text_t url) {
277
278 if (gsdl_conffile.empty()) {
279 find_location();
280 gsdl_conffile = filename_cat(data_location, "llssite.cfg");
281 }
282
283 char *conffile_c = gsdl_conffile.getcstr();
284 ofstream fout (conffile_c);
285 delete []conffile_c;
286 if (fout) {
287
288 outconvertclass text_t2ascii;
289
290 // top (gsdl) level stuff
291 fout << "[gsdl]\n";
292
293 if (!url.empty()) {
294 // url entry should only be written to llssite.cfg when the
295 // server is actually running, not when it's stopped (since we
296 // can't be sure what the url is at that stage). That is,
297 // write_settings() is called with the url argument set when the
298 // server first starts up, it's then called without url set as
299 // the server shuts down.
300 write_ini_line(fout, "url", url);
301 }
302
303 write_ini_line(fout, "enterlib", gsdl_enterlib);
304 write_ini_line(fout, "gsdlhome", gsdl_gsdlhome);
305 write_ini_line(fout, "collecthome", gsdl_collecthome);
306 write_ini_line(fout, "gdbmhome", gsdl_dbhome);
307
308 write_ini_line(fout, "logfilename", gsdl_log_name);
309 write_ini_line(fout, "keeplog", text_t(gsdl_keep_log));
310 write_ini_line(fout, "consolelog", text_t(gsdl_show_console));
311
312 write_ini_line(fout, "portnumber", text_t(gsdl_port_num));
313 write_ini_line(fout, "externalaccess", text_t(gsdl_external_access));
314 write_ini_line(fout, "autoenter", text_t(gsdl_auto_enter));
315 write_ini_line(fout, "browser", text_t(gsdl_browser));
316 write_ini_line(fout, "browserexe", gsdl_browser_exe);
317 write_ini_line(fout, "collections", gsdl_collections);
318 write_ini_line(fout, "start_browser", text_t(gsdl_start_browser));
319 write_ini_line(fout, "address_resolution_method", text_t(gsdl_address_resolution_method));
320
321 // collection levels
322 colinfo_tmap::iterator here = gsdl_collectinfo.begin();
323 colinfo_tmap::iterator end = gsdl_collectinfo.end();
324 while (here != end) {
325 fout << text_t2ascii << "[" << (*here).first << "]\n";
326 if (!(*here).second.gsdl_gsdlhome.empty())
327 write_ini_line(fout, "gsdlhome", (*here).second.gsdl_gsdlhome);
328 if (!(*here).second.gsdl_collecthome.empty())
329 write_ini_line(fout, "collecthome", (*here).second.gsdl_collecthome);
330 if (!(*here).second.gsdl_dbhome.empty())
331 write_ini_line(fout, "gdbmhome", (*here).second.gsdl_dbhome);
332
333 ++here;
334 }
335 fout.close();
336 }
337}
338
339
340// browser_compare assumes that check_exe is in lowercase
341static int browser_compare (char *browser_exe_path, char *check_exe) {
342 char tmp_exe[MAX_FILENAME_SIZE];
343 strcpy (tmp_exe, browser_exe_path);
344 _strlwr (tmp_exe);
345 return (strstr (tmp_exe, check_exe) != NULL);
346}
347
348// This function assumes that check_installed_browsers
349// has been recently called
350// It also assumes that browser_exe is large
351// enough to receive any path names to any browser
352static void check_browser_settings (int &browser, char *browser_exe,
353 int netscapeneeded) {
354 // sort out which browser to use
355 if ((browser == GS_NETSCAPE) && (netscape_exe[0] == '\0'))
356 browser = GS_IEXPLORE;
357 if ((browser == GS_IEXPLORE) && (netscapeneeded || (iexplore_exe[0] == '\0'))) {
358 if (netscape_exe[0] != '\0') browser = GS_NETSCAPE;
359 else browser = GS_OTHER;
360 }
361 if ((browser == GS_OTHER) && netscapeneeded &&
362 !browser_compare (browser_exe, "netscape.exe") && (netscape_exe[0] != '\0')) {
363 // this other browser isn't netscape and netscape is available
364 browser = GS_NETSCAPE;
365 }
366
367
368 // get the browser's executable
369 if (browser == GS_DEFAULT) {
370 strcpy (browser_exe, default_browser_exe);
371 } else if (browser == GS_NETSCAPE) {
372 strcpy (browser_exe, netscape_exe);
373 } else if (browser == GS_IEXPLORE) {
374 strcpy (browser_exe, iexplore_exe);
375 } else {
376 browser = GS_OTHER;
377
378 // if the browser should be netscape then check to
379 // make sure it is
380 if (netscapeneeded && !browser_compare (browser_exe, "netscape.exe")) {
381 // not netscape, set to no browser
382 browser_exe[0] = '\0';
383 }
384 }
385}
386
387
388static void revert_defaults (int netscapeneeded) {
389 find_location();
390
391 // library settings
392 gsdl_enterlib = "/gsdl";
393 gsdl_gsdlhome = data_location;
394 gsdl_collecthome = filename_cat(data_location,"collect");
395 gsdl_dbhome = data_location;
396
397 // debug settings
398 gsdl_keep_log = 0;
399 char *cstr_value = filename_cat(data_location,"gsdl.log").getcstr();
400 strcpy (gsdl_log_name, cstr_value); //strcpy (gsdl_log_name, "c:\\gsdl.log");
401 delete []cstr_value;
402 gsdl_show_console = 0;
403
404 // general settings
405 gsdl_port_num = 80;
406 gsdl_external_access = 0;
407 gsdl_auto_enter = 0;
408 gsdl_start_browser = 1;
409
410 check_installed_browsers (netscapeneeded);
411 gsdl_browser = GS_DEFAULT;
412 strcpy (gsdl_browser_exe, default_browser_exe);
413 check_browser_settings (gsdl_browser, gsdl_browser_exe, netscapeneeded);
414}
415
416void read_settings (int netscapeneeded) {
417
418 if (gsdl_conffile.empty()) {
419 find_location();
420 gsdl_conffile = filename_cat(data_location, "llssite.cfg");
421 }
422
423 // set up defaults
424 revert_defaults (netscapeneeded);
425
426 text_t key, value, section;
427 char *cstr_value;
428 char *conffile_c = gsdl_conffile.getcstr();
429#if defined (GSDL_USE_IOS_H)
430 ifstream conf (conffile_c, ios::nocreate);
431#else
432 ifstream conf (conffile_c);
433#endif
434 delete []conffile_c;
435 if (conf) {
436 while (read_ini_line(conf, key, value) >= 0) {
437 if (key.empty()) continue;
438 if (value.empty()) {
439 // should be a section title
440 section = key;
441 // remove square brackets
442 section.erase (section.begin());
443 section.erase (section.end()-1);
444
445 } else {
446
447 cstr_value = value.getcstr ();
448
449 if (section == "gsdl") {
450
451 if (key == "enterlib") {
452 gsdl_enterlib = value;
453
454 // 'logfilename' should occur in the configuration file
455 // before 'keeplog'
456 } else if (key == "logfilename") {
457 strcpy (gsdl_log_name, cstr_value);
458
459 } else if (key == "keeplog") {
460 gsdl_keep_log = value.getint();
461 if (gsdl_keep_log) open_log_file();
462
463 } else if (key == "consolelog") {
464 if (value.getint()) activate_console();
465 else deactivate_console();
466
467 } else if (key == "portnumber") {
468 gsdl_port_num = value.getint();
469
470 } else if (key == "externalaccess") {
471 gsdl_external_access = value.getint();
472
473 } else if (key == "autoenter") {
474 gsdl_auto_enter = value.getint();
475
476 } else if (key == "start_browser") {
477 gsdl_start_browser = value.getint();
478
479 } else if (key == "browser") {
480 gsdl_browser = value.getint();
481
482 } else if (key == "browserexe") {
483 strcpy (gsdl_browser_exe, cstr_value);
484
485 } else if (key == "address_resolution_method") {
486 gsdl_address_resolution_method = value.getint();
487
488 } else if (key == "collections") {
489 gsdl_collections = value;
490 }
491 // gsdlhome must occur in file before dbhome
492 else if (key == "gsdlhome") {
493 gsdl_gsdlhome = value;
494 gsdl_collecthome = filename_cat(value,"collect");
495 gsdl_dbhome = value;
496 }
497 else if (key == "collecthome") {
498 gsdl_collecthome = value;
499 }
500 else if (key == "gdbmhome") {
501 gsdl_dbhome = value;
502 }
503 } else {
504
505 // gsdlhome must occur in file before dbhome
506 if (key == "gsdlhome") {
507 gsdl_collectinfo[section].gsdl_gsdlhome = value;
508 gsdl_collectinfo[section].gsdl_collecthome = filename_cat(value,"collect");
509 gsdl_collectinfo[section].gsdl_dbhome = value;
510 }
511 else if (key == "collecthome") {
512 gsdl_collectinfo[section].gsdl_collecthome = value;
513 }
514 else if (key == "gdbmhome") {
515 gsdl_collectinfo[section].gsdl_dbhome = value;
516 }
517 }
518 delete []cstr_value;
519 }
520 }
521 conf.close();
522 }
523
524 // check the homes to make sure they don't contain
525 // extra slashes at the end
526 remove_end_slashes (gsdl_gsdlhome);
527 remove_end_slashes (gsdl_collecthome);
528 remove_end_slashes (gsdl_dbhome);
529 colinfo_tmap::iterator here = gsdl_collectinfo.begin();
530 colinfo_tmap::iterator end = gsdl_collectinfo.end();
531 while (here != end) {
532 remove_end_slashes ((*here).second.gsdl_gsdlhome);
533 remove_end_slashes ((*here).second.gsdl_collecthome);
534 remove_end_slashes ((*here).second.gsdl_dbhome);
535 ++here;
536 }
537
538 // check the browser settings
539 check_browser_settings (gsdl_browser, gsdl_browser_exe, netscapeneeded);
540}
541
542void gsdl_check_browser_settings (int netscapeneeded) {
543 check_installed_browsers (netscapeneeded);
544 check_browser_settings (gsdl_browser, gsdl_browser_exe, netscapeneeded);
545}
546
547
548static void dialog_update_enables (HWND hwndDlg) {
549 int res;
550
551 // if they want to use another browser, they should be able
552 // edit its filename
553 res = SendDlgItemMessage(hwndDlg, ID_RADIO_OTHER, BM_GETCHECK,0,0);
554 SendDlgItemMessage(hwndDlg, ID_OTHER_NAME, WM_ENABLE, (res == 1), 0);
555}
556
557
558static int read_dialog_browser_field (HWND hwndDlg) {
559 if (SendDlgItemMessage(hwndDlg, ID_RADIO_DEFAULT,
560 BM_GETCHECK, 0, 0) == 1) return GS_DEFAULT;
561 if (SendDlgItemMessage(hwndDlg, ID_RADIO_NETSCAPE,
562 BM_GETCHECK, 0, 0) == 1) return GS_NETSCAPE;
563 if (SendDlgItemMessage(hwndDlg, ID_RADIO_IE,
564 BM_GETCHECK, 0, 0) == 1) return GS_IEXPLORE;
565 if (SendDlgItemMessage(hwndDlg, ID_RADIO_OTHER,
566 BM_GETCHECK, 0, 0) == 1) return GS_OTHER;
567 return GS_NETSCAPE;
568}
569
570
571static void set_dialog_browser_field (HWND hwndDlg, int browser, char *othername) {
572 // if we are trying to set the browser to default, netscape or
573 // internet explorer and we can't find them, set the browser
574 // to 'other'
575 if ((browser == GS_DEFAULT) && (default_browser_exe[0] == '\0'))
576 browser = GS_NETSCAPE;
577 if ((browser == GS_NETSCAPE) && (netscape_exe[0] == '\0'))
578 browser = GS_IEXPLORE;
579 if ((browser == GS_IEXPLORE) && (iexplore_exe[0] == '\0')) {
580 if (netscape_exe[0] != '\0') browser = GS_NETSCAPE;
581 else browser = GS_OTHER;
582 }
583
584 // update the radio buttons
585 SendDlgItemMessage(hwndDlg, ID_RADIO_DEFAULT, BM_SETCHECK,
586 (browser == GS_DEFAULT) ? BST_CHECKED : BST_UNCHECKED, 0);
587 SendDlgItemMessage(hwndDlg, ID_RADIO_NETSCAPE, BM_SETCHECK,
588 (browser == GS_NETSCAPE) ? BST_CHECKED : BST_UNCHECKED, 0);
589 SendDlgItemMessage(hwndDlg, ID_RADIO_IE, BM_SETCHECK,
590 (browser == GS_IEXPLORE) ? BST_CHECKED : BST_UNCHECKED, 0);
591 SendDlgItemMessage(hwndDlg, ID_RADIO_OTHER, BM_SETCHECK,
592 (browser == GS_OTHER) ? BST_CHECKED : BST_UNCHECKED, 0);
593
594 // update the other name field
595 if (browser == GS_DEFAULT) {
596 SetDlgItemText(hwndDlg, ID_OTHER_NAME, default_browser_exe);
597 } else if (browser == GS_NETSCAPE) {
598 SetDlgItemText(hwndDlg, ID_OTHER_NAME, netscape_exe);
599 } else if (browser == GS_IEXPLORE) {
600 SetDlgItemText(hwndDlg, ID_OTHER_NAME, iexplore_exe);
601 } else if (othername != NULL) {
602 SetDlgItemText(hwndDlg, ID_OTHER_NAME, othername);
603 }
604}
605
606
607static void read_browser_exe_field (HWND hwndDlg, char *filename, int maxsize) {
608 filename[0] = '\0';
609 GetDlgItemText(hwndDlg, ID_OTHER_NAME, filename, maxsize);
610}
611
612static int read_address_resolution_field (HWND hwndDlg) {
613 if (SendDlgItemMessage(hwndDlg, ID_ARM_NAME,
614 BM_GETCHECK, 0, 0) == 1) return ARM_NAME;
615 if (SendDlgItemMessage(hwndDlg, ID_ARM_IP,
616 BM_GETCHECK, 0, 0) == 1) return ARM_IP;
617 if (SendDlgItemMessage(hwndDlg, ID_ARM_LOCALHOST,
618 BM_GETCHECK, 0, 0) == 1) return ARM_LOCALHOST;
619 if (SendDlgItemMessage(hwndDlg, ID_ARM_127_0_0_1,
620 BM_GETCHECK, 0, 0) == 1) return ARM_127_0_0_1;
621 return ARM_NAME;
622}
623
624static void set_address_resolution_field (HWND hwndDlg,
625 int address_res_method) {
626 // update the radio buttons
627 SendDlgItemMessage(hwndDlg, ID_ARM_NAME, BM_SETCHECK,
628 (address_res_method == ARM_NAME) ? BST_CHECKED : BST_UNCHECKED, 0);
629 SendDlgItemMessage(hwndDlg, ID_ARM_IP, BM_SETCHECK,
630 (address_res_method == ARM_IP) ? BST_CHECKED : BST_UNCHECKED, 0);
631 SendDlgItemMessage(hwndDlg, ID_ARM_LOCALHOST, BM_SETCHECK,
632 (address_res_method == ARM_LOCALHOST) ? BST_CHECKED : BST_UNCHECKED, 0);
633 SendDlgItemMessage(hwndDlg, ID_ARM_127_0_0_1, BM_SETCHECK,
634 (address_res_method == ARM_127_0_0_1) ? BST_CHECKED : BST_UNCHECKED, 0);
635
636}
637
638static void read_dialog_fields (HWND hwndDlg) {
639 int res; BOOL bres;
640
641 // port number
642 gsdl_port_num = GetDlgItemInt(hwndDlg, SERVER_PORT_EDIT_BOX, &bres, 0);
643 if (!bres) gsdl_port_num = 80;
644
645 // whether to allow external access or not
646 res = SendDlgItemMessage(hwndDlg, ID_EXTERNAL_ACCESS, BM_GETCHECK, 0, 0);
647 gsdl_external_access = (res == 1);
648
649 // whether to enter the library automatically on startup
650 res = SendDlgItemMessage(hwndDlg, ID_AUTO_ENTER_LIBRARY, BM_GETCHECK, 0, 0);
651 gsdl_auto_enter = (res == 1);
652
653 // which browser to use
654 gsdl_browser = read_dialog_browser_field (hwndDlg);
655
656 // find out where the browser exe lives
657 read_browser_exe_field (hwndDlg, gsdl_browser_exe, MAX_FILENAME_SIZE);
658
659 // which address resolution method
660 gsdl_address_resolution_method = read_address_resolution_field(hwndDlg);
661}
662
663
664
665
666static BOOL CALLBACK dialog_proc(HWND hwndDlg, UINT uMsg,
667 WPARAM wParam,LPARAM lParam) {
668 int wNotifyCode = HIWORD(wParam);
669 int wID = LOWORD(wParam);
670 char *filefilter = "Program Files (*.exe)\0*.exe\0All Files (*.*)\0*.*\0\0";
671 OPENFILENAME fname;
672 char filename[MAX_FILENAME_SIZE];
673
674 switch (uMsg) {
675 case WM_INITDIALOG:
676 // set current values
677 SetDlgItemInt(hwndDlg, SERVER_PORT_EDIT_BOX, gsdl_port_num, FALSE);
678 SendDlgItemMessage(hwndDlg, ID_EXTERNAL_ACCESS, BM_SETCHECK,
679 gsdl_external_access ? 1 : 0, 0);
680 SendDlgItemMessage(hwndDlg, ID_AUTO_ENTER_LIBRARY, BM_SETCHECK,
681 gsdl_auto_enter ? 1 : 0, 0);
682 set_dialog_browser_field (hwndDlg, gsdl_browser, gsdl_browser_exe);
683 set_address_resolution_field(hwndDlg, gsdl_address_resolution_method);
684 dialog_update_enables(hwndDlg);
685
686 // make sure that the default browser, netscape and internet explorer
687 // radio buttons are only enabled if they could be found
688 if (default_browser_exe[0] == '\0')
689 EnableWindow (GetDlgItem (hwndDlg, ID_RADIO_DEFAULT), FALSE);
690 if (netscape_exe[0] == '\0')
691 EnableWindow (GetDlgItem (hwndDlg, ID_RADIO_NETSCAPE), FALSE);
692 if (iexplore_exe[0] == '\0')
693 EnableWindow (GetDlgItem (hwndDlg, ID_RADIO_IE), FALSE);
694
695 return 1;
696
697 case WM_COMMAND:
698 if (wNotifyCode == BN_CLICKED) {
699 switch (wID) {
700 case ID_CANCEL_BUTTON:
701 EndDialog(hwndDlg, 0);
702 return 1;
703
704 case ID_OK_BUTTON:
705 // check to make sure we can find the browser
706 filename[0] = '\0';
707 read_browser_exe_field (hwndDlg, filename, MAX_FILENAME_SIZE);
708 if (check_program_exe (filename)) {
709 // the file exists
710 // if netscape is needed, make sure the browser is netscape
711 _strlwr(filename);
712 if (!gsdl_netscapeneeded || strstr (filename, "netscape.exe") != NULL) {
713 // everything is ok
714 read_dialog_fields(hwndDlg);
715 EndDialog(hwndDlg, 1);
716
717 } else {
718 // message: must use netscape with this version
719 MessageBox(hwndDlg,
720 "You are using this software on a machine which\n"
721 "currently does not have a working TCP/IP network layer.\n"
722 "To allow the Greenstone Digital Library software to use\n"
723 "its own TCP/IP network layer you must use a Netscape\n"
724 "web browser.",
725 "Greenstone Digital Library Software",
726 MB_OK|MB_APPLMODAL);
727 }
728 } else {
729 // message: the file did not exist
730 MessageBox(hwndDlg,
731 "Could not find the selected browser. You must have a\n"
732 "web browser installed to use the Greenstone Digital\n"
733 "Library software.",
734 "Greenstone Digital Library Software",
735 MB_OK|MB_APPLMODAL);
736 }
737 return 1;
738
739 case ID_RADIO_DEFAULT:
740 set_dialog_browser_field (hwndDlg, GS_DEFAULT, NULL);
741 dialog_update_enables(hwndDlg);
742 return 1;
743
744 case ID_RADIO_NETSCAPE:
745 set_dialog_browser_field (hwndDlg, GS_NETSCAPE, NULL);
746 dialog_update_enables(hwndDlg);
747 return 1;
748
749 case ID_RADIO_IE:
750 set_dialog_browser_field (hwndDlg, GS_IEXPLORE, NULL);
751 dialog_update_enables(hwndDlg);
752 return 1;
753
754 case ID_RADIO_OTHER:
755 set_dialog_browser_field (hwndDlg, GS_OTHER, NULL);
756 dialog_update_enables(hwndDlg);
757 return 1;
758
759 case ID_BROWSE_BUTTON:
760 filename[0] = '\0';
761 memset(&fname, 0, sizeof(OPENFILENAME));
762 fname.lStructSize = sizeof(OPENFILENAME);
763 fname.hwndOwner = hwndDlg;
764 fname.hInstance = NULL;
765 fname.lpstrFilter = filefilter;
766 fname.lpstrCustomFilter = NULL;
767 fname.nMaxCustFilter = 0;
768 fname.nFilterIndex = 1;
769 fname.lpstrFile = filename;
770 fname.nMaxFile = MAX_FILENAME_SIZE-1;
771 fname.lpstrFileTitle = NULL;
772 fname.nMaxFileTitle = 0;
773 fname.lpstrInitialDir = NULL;
774 fname.lpstrTitle = "Choose Web Browser";
775 fname.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
776
777 if(GetOpenFileName(&fname)) {
778 set_dialog_browser_field (hwndDlg, GS_OTHER, filename);
779 dialog_update_enables(hwndDlg);
780 }
781 return 1;
782
783 case ID_ARM_NAME:
784 set_address_resolution_field (hwndDlg, ARM_NAME);
785 dialog_update_enables(hwndDlg);
786 return 1;
787 case ID_ARM_IP:
788 set_address_resolution_field (hwndDlg, ARM_IP);
789 dialog_update_enables(hwndDlg);
790 return 1;
791 case ID_ARM_LOCALHOST:
792 set_address_resolution_field (hwndDlg, ARM_LOCALHOST);
793 dialog_update_enables(hwndDlg);
794 return 1;
795 case ID_ARM_127_0_0_1:
796 set_address_resolution_field (hwndDlg, ARM_127_0_0_1);
797 dialog_update_enables(hwndDlg);
798 return 1;
799
800 }
801 }
802 return 0;
803
804 case WM_CLOSE:
805 case WM_DESTROY:
806 EndDialog(hwndDlg, 0);
807 return 1;
808 }
809
810 return 0;
811}
812
813static void dialog_debug_update_enables (HWND hwndDlg) {
814 int res;
815
816 // if they want a log of program use allow them to
817 // edit its filename
818 res = SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_GETCHECK,0,0);
819 SendDlgItemMessage(hwndDlg, LOG_NAME_BOX, WM_ENABLE, (res == 1), 0);
820}
821
822
823static void read_dialog_debug_fields (HWND hwndDlg) {
824 int res;
825
826 // whether to log program use
827 res = SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_GETCHECK,0,0);
828 gsdl_keep_log = (res == 1);
829
830 // log filename
831 res = SendDlgItemMessage(hwndDlg, LOG_NAME_BOX, EM_GETMODIFY,0,0);
832 if (res != 0) {
833 res = GetDlgItemText(hwndDlg, LOG_NAME_BOX, gsdl_log_name, MAX_FILENAME_SIZE);
834 }
835
836 // whether to display log information on console
837 res = SendDlgItemMessage(hwndDlg, CONSOLE_CHECK, BM_GETCHECK,0,0);
838 gsdl_show_console = (res == 1);
839}
840
841
842static BOOL CALLBACK dialog_debug_proc(HWND hwndDlg, UINT uMsg,
843 WPARAM wParam,LPARAM lParam) {
844 int wNotifyCode = HIWORD(wParam);
845 int wID = LOWORD(wParam);
846
847 switch (uMsg) {
848 case WM_INITDIALOG:
849 // set current values
850 SendDlgItemMessage(hwndDlg, LOG_CHECK, BM_SETCHECK,
851 gsdl_keep_log ? 1 : 0, 0);
852 SetDlgItemText(hwndDlg, LOG_NAME_BOX, gsdl_log_name);
853 SendDlgItemMessage(hwndDlg, CONSOLE_CHECK, BM_SETCHECK,
854 gsdl_show_console ? 1 : 0, 0);
855 dialog_debug_update_enables(hwndDlg);
856 return 1;
857
858 case WM_COMMAND:
859 if (wNotifyCode == BN_CLICKED) {
860 switch (wID) {
861 case ID_CANCEL_BUTTON:
862 EndDialog(hwndDlg, 0);
863 return 1;
864
865 case ID_OK_BUTTON:
866 read_dialog_debug_fields(hwndDlg);
867 EndDialog(hwndDlg, 1);
868 return 1;
869
870 case LOG_CHECK:
871 dialog_debug_update_enables(hwndDlg);
872 return 1;
873 }
874 }
875 return 0;
876
877 case WM_CLOSE:
878 case WM_DESTROY:
879 EndDialog(hwndDlg, 0);
880 return 1;
881 }
882
883 return 0;
884}
885
886
887void Settings_Dialog(HWND window, int netscapeneeded)
888{
889 int old_gsdl_show_console = gsdl_show_console;
890 int old_gsdl_port_num = gsdl_port_num;
891 int old_gsdl_external_access = gsdl_external_access;
892
893 int res = 0;
894
895 gsdl_netscapeneeded = netscapeneeded;
896
897 if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) &&
898 (GetAsyncKeyState(VkKeyScan('d')) & 0x8000)) {
899 // control-D was pressed, display debug settings
900 // dialog box
901 res = DialogBox (NULL, MAKEINTRESOURCE(COMMS_DIALOG_DEBUG),
902 window, (DLGPROC)dialog_debug_proc);
903
904 if (res == 1) {
905 // only update if exited via the OK button
906 if (gsdl_keep_log) open_log_file();
907 else close_log_file();
908
909 // turn the console on/off if we need to
910 if (gsdl_show_console != old_gsdl_show_console) {
911 if (gsdl_show_console) activate_console ();
912 else deactivate_console ();
913 }
914 }
915
916 } else {
917 // display normal settings dialog box
918
919 // make sure everything is up-to-date
920 gsdl_check_browser_settings (netscapeneeded);
921
922 res = DialogBox (NULL, MAKEINTRESOURCE(COMMS_DIALOG2),
923 window, (DLGPROC)dialog_proc);
924
925 if (res == 1) {
926 // only update if exited via the OK button
927 if ((gsdl_port_num != old_gsdl_port_num)
928 || (gsdl_external_access != old_gsdl_external_access)) {
929 EndHTTPServer();
930 StartHTTPServer(window);
931 }
932 }
933 }
934
935 // save the settings if we exited via the ok button
936 if (res == 1) {
937 write_settings(gsdl_url);
938 // reset httpprefix in case port number was changed
939 // configure_httpprefix ();
940 }
941}
Note: See TracBrowser for help on using the repository browser.