TaskEstimate now uses the FogBugz object stuff. Wow, is the code ever
[wvapps.git] / wvdial / wvdialconf.cc
blob02ea1464645fe69f990bcab1fcd49c20efab9bdd
1 /*
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2003 Net Integration Technologies, Inc.
5 * WvDial configuration utility. Generates a basic wvdial.conf file.
6 */
7 #include "uniconfroot.h"
8 #include "wvconfemu.h"
9 #include "wvfile.h"
10 #include "wvmodemscan.h"
11 #include "wvstrutils.h"
12 #include <ctype.h>
15 void check_ppp_options()
17 WvFile file("/etc/ppp/options", O_RDONLY);
18 char *line;
20 while ((line = file.getline()) != NULL)
22 line = trim_string(line);
24 // comments and blank lines are ignored
25 if (line[0] == '#' || !line[0])
26 continue;
28 // IP addresses are allowed
29 if (strchr(line, '.') || strchr(line, ':'))
30 continue;
32 // but baud rates and tty names are not!
33 // a 'connect' line is usually bad too.
34 if (isdigit(line[0])
35 || !strncmp(line, "/dev", 4)
36 || !strncmp(line, "tty", 3)
37 || !strncmp(line, "cua", 3)
38 || !strncmp(line, "connect", 7))
40 wvcon->print("\n*** WARNING! Line \"%s\"\n"
41 " in /etc/ppp/options may conflict with wvdial!\n\n", line);
47 int main(int argc, char **argv)
49 #if DEBUG
50 free(malloc(1)); // for electric fence
51 #endif
53 if (argc != 2 || argv[1][0]=='-')
55 wvcon->print("Usage: %s <configfile-name>\n"
56 "\t(create/update a wvdial.conf file automatically)\n",
57 argv[0]);
58 return 1;
61 wvcon->print("Scanning your serial ports for a modem.\n\n");
63 WvModemScanList l;
64 while (!l.isdone())
65 l.execute();
67 if (l.count() < 1)
69 wvcon->print("\n\n"
70 "Sorry, no modem was detected! "
71 "Is it in use by another program?\n"
72 "Did you configure it properly with setserial?\n\n"
74 "Please read the FAQ at http://open.nit.ca/wvdial/\n\n"
76 "If you still have problems, send mail to "
77 "wvdial-list@lists.nit.ca.\n");
78 return 1;
81 WvModemScanList::Iter i(l);
83 i.rewind(); i.next();
84 WvModemScan &m = *i;
85 WvString fn = m.filename(), init = m.initstr();
87 wvcon->print("\nFound %s on %s",
88 m.is_isdn() ? "an ISDN TA" :
89 strncmp("/dev/ttyACM",fn,11) ? "a modem" : "an USB modem", (const char *)fn);
90 if (m.use_modem_link) {
91 wvcon->print(", using link /dev/modem in config.\n");
92 fn = "/dev/modem";
93 } else {
94 wvcon->print(".\n");
96 UniConfRoot uni(WvString("ini:%s", argv[1]), 0660);
97 WvConfEmu cfg(uni); // Create it read/write owner and group only
98 static char s[]="Dialer Defaults";
99 cfg.set(s, "Modem", fn);
100 cfg.setint(s, "Baud", m.maxbaud());
101 cfg.set(s, "Init1", m.is_isdn() ? "AT&F" : "ATZ");
102 cfg.set(s, "Init2", init);
103 cfg.set(s, "ISDN", m.use_default_asyncmap() ? "1" : "0");
104 cfg.set(s, "Modem Name", m.modem_name ? (const char *)m.modem_name : "");
105 cfg.set(s, "Modem Type", m.is_isdn() ? "ISDN Terminal Adapter" :
106 strncmp("/dev/ttyACM",fn,11) ? "Analog Modem" : "USB Modem");
108 if (m.modem_name)
109 wvcon->print("Config for %s written to %s.\n", (const char *)m.modem_name, argv[1]);
110 else
111 wvcon->print("Modem configuration written to %s.\n", argv[1]);
113 // insert some entries to let people know what they need to edit
114 if (!cfg.get(s, "Phone"))
115 cfg.set(s, "; Phone", "<Target Phone Number>");
116 if (!cfg.get(s, "Username"))
117 cfg.set(s, "; Username", "<Your Login Name>");
118 if (!cfg.get(s, "Password"))
119 cfg.set(s, "; Password", "<Your Password>");
121 check_ppp_options();
123 return 0;