~ubuntu-branches/ubuntu/quantal/wvdial/quantal

« back to all changes in this revision

Viewing changes to src/wvdialconf.cc

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-10-06 11:05:06 UTC
  • mfrom: (0.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20041006110506-138x19fe4q0iu46e
Tags: 1.54.0-1ubuntu1
postinst: Disable command-line configuration to not disturb installation;
the script just exits early, so the postinst code is not completely lost
(Warty bug #2069)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Worldvisions Weaver Software:
3
 
 *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4
 
 *
5
 
 * WvDial configuration utility.  Generates a basic wvdial.conf file.
6
 
 */
7
 
#include "wvmodemscan.h"
8
 
#include "wvfile.h"
9
 
#include "wvconf.h"
10
 
#include <ctype.h>
11
 
 
12
 
 
13
 
void check_ppp_options()
14
 
{
15
 
    WvFile file("/etc/ppp/options", O_RDONLY);
16
 
    char *line;
17
 
    
18
 
    while ((line = file.getline(0)) != NULL)
19
 
    {
20
 
        line = trim_string(line);
21
 
        
22
 
        // comments and blank lines are ignored
23
 
        if (line[0] == '#'  ||  !line[0])
24
 
            continue;
25
 
        
26
 
        // IP addresses are allowed
27
 
        if (strchr(line, '.') || strchr(line, ':'))
28
 
            continue;
29
 
        
30
 
        // but baud rates and tty names are not!
31
 
        // a 'connect' line is usually bad too.
32
 
        if (isdigit(line[0])
33
 
            || !strncmp(line, "/dev", 4)
34
 
            || !strncmp(line, "tty",  3) 
35
 
            || !strncmp(line, "cua",  3)
36
 
            || !strncmp(line, "connect", 7))
37
 
        {
38
 
            wvcon->print("\n*** WARNING!  Line \"%s\"\n"
39
 
                "   in /etc/ppp/options may conflict with wvdial!\n\n", line);
40
 
        }
41
 
    }
42
 
}
43
 
 
44
 
 
45
 
int main(int argc, char **argv)
46
 
{
47
 
#if DEBUG
48
 
    free(malloc(1));    // for electric fence
49
 
#endif  
50
 
    
51
 
    if (argc != 2 || argv[1][0]=='-')
52
 
    {
53
 
        wvcon->print("Usage: %s <configfile-name>\n"
54
 
                "\t(create/update a wvdial.conf file automatically)\n",
55
 
                argv[0]);
56
 
        return 1;
57
 
    }
58
 
    
59
 
    wvcon->print("Scanning your serial ports for a modem.\n\n");
60
 
    
61
 
    WvModemScanList l;
62
 
    while (!l.isdone()) {
63
 
        l.execute();
64
 
        if (l.isready())
65
 
                break;
66
 
    }
67
 
    
68
 
    if (l.count() < 1)
69
 
    {
70
 
        wvcon->print("\n\n"
71
 
          "Sorry, no modem was detected!  "
72
 
            "Is it in use by another program?\n"
73
 
          "Did you configure it properly with setserial?\n\n"
74
 
                
75
 
          "Please read the FAQ at http://open.nit.ca/wvdial/\n\n"
76
 
                
77
 
          "If you still have problems, send mail to "
78
 
            "wvdial-list@lists.nit.ca.\n");
79
 
        return 1;
80
 
    }
81
 
    
82
 
    WvModemScanList::Iter i(l);
83
 
    
84
 
    i.rewind(); i.next();
85
 
    WvModemScan &m = i;
86
 
    WvString fn = m.filename(), init = m.initstr();
87
 
    
88
 
    wvcon->print("\nFound %s on %s",
89
 
        m.is_isdn() ? "an ISDN TA" :
90
 
        strncmp("/dev/ttyACM",fn,11) ? "a modem" : "an USB modem", (const char *)fn);
91
 
    if (m.use_modem_link) {
92
 
        wvcon->print(", using link /dev/modem in config.\n");
93
 
        fn = "/dev/modem";
94
 
    } else {
95
 
        wvcon->print(".\n");    
96
 
    }
97
 
    WvConf cfg(argv[1],660); // 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");  
107
 
 
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]);
112
 
 
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>");
120
 
    
121
 
    check_ppp_options();
122
 
    
123
 
    return 0;
124
 
}