backup
[lcr.git] / genext.c
1 /*****************************************************************************\
2 **                                                                           **
3 ** PBX4Linux                                                                 **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** generate extension                                                        **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <stdarg.h>
16 #include <sys/file.h>
17 #include <sys/stat.h>
18 #include <sys/types.h>
19 #include <errno.h>
20 #include "main.h"
21
22 int memuse = 0;
23 int mmemuse = 0;
24 int cmemuse = 0;
25 int ememuse = 0;
26 int pmemuse = 0;
27 int classuse = 0;
28 int fduse = 0;
29 int fhuse = 0;
30 struct isdn_cause isdn_cause[128];
31 struct isdn_location isdn_location[16];
32
33 void _printdebug(const char *function, int line, unsigned long mask, const char *fmt, ...)
34 {
35 }
36
37 void _printerror(const char *function, int line, const char *fmt, ...)
38 {
39         char buffer[4096];
40         va_list args;
41
42         va_start(args,fmt);
43         VUNPRINT(buffer,sizeof(buffer)-1,fmt,args);
44         buffer[sizeof(buffer)-1]=0;
45         va_end(args);
46
47         fprintf(stderr, "%s", buffer);
48 }
49
50 int main(int argc, char *argv[])
51 {
52         struct extension ext;
53         char pathname[256];
54         FILE *fp;
55
56         if (!read_options())
57         {
58                 PERROR("Failed to read options.conf\n");
59                 return(-1);
60         }
61
62         if (argc != 4)
63         {
64                 printf("Usage: %s <extension> <interfaces> <callerid>\n\n", argv[0]);
65                 printf("extension: any number for the extension (e.g 200)\n");
66                 printf("interfaces: internal interface(es) to reach extension (seperated by commas. e.g Int1,Int2)\n");
67                 printf("callerid: normal undefined called is (use what your telco assigned you)\n");
68                 return(0);
69         }
70
71         SPRINT(pathname, "%s/%s/%s", INSTALL_DATA, options.extensions_dir, argv[1]);
72         if (mkdir(pathname, 0755) < 0)
73         {
74                 if (errno == EEXIST)
75                         PERROR("Extension's directory already exists. Nothing done!\n");
76                 else    PERROR("Cannot open extension's directory '%s'.\n", pathname);
77                 return(-1);
78         }
79
80         memset(&ext, 0, sizeof(ext));
81         ext.rights = 4;
82         ext.tout_setup = 120;
83         ext.tout_dialing = 120;
84         ext.tout_proceeding = 120;
85         ext.tout_alerting = 120;
86         ext.tout_disconnect = 120;
87 //      ext.tout_hold = 900;
88 //      ext.tout_park = 900;
89         ext.cfnr_delay = 20;
90         ext.vbox_codec = CODEC_MONO;
91         UCPY(ext.interfaces, argv[2]);
92         UCPY(ext.callerid, argv[3]);
93         ext.callerid_present = INFO_PRESENT_ALLOWED;
94         ext.callerid_type = INFO_NTYPE_UNKNOWN;
95         ext.change_forward = 1;
96         ext.facility = 1;
97         write_extension(&ext, argv[1]);
98
99         SPRINT(pathname, "%s/%s/%s/phonebook", INSTALL_DATA, options.extensions_dir, argv[1]);
100         if (!(fp = fopen(pathname, "w")))
101         {
102                 PERROR("Failed to write phonebook example '%s'.\n", pathname);
103                 return(-1);
104         } else
105         {
106                 fprintf(fp, "# fromat: <shortcut> <phone number> [<Name>]\n");
107                 fprintf(fp, "# The shotcut may have any number of digits. \n");
108                 fprintf(fp, "# The phone number must include the dialing code for external, internal or\n");
109                 fprintf(fp, "# other type of dialing. \n");
110                 fprintf(fp, "# The name must not be in quotes. All 2 or 3 attributes must be seperated by\n");
111                 fprintf(fp, "# white space(s) and/or tab(s)\n");
112                 fprintf(fp, "# Empty lines and lines starting with '#' will be ignored.\n");
113                 fprintf(fp, "\n");
114                 fprintf(fp, "0   008003301000             German Telekom Service\n");
115                 fprintf(fp, "10  011880                   Directory Service Telegate\n");
116                 fprintf(fp, "11  011833                   Directory Service DTAG\n");
117                 fprintf(fp, "12  011811                   Directory Service Fred\n");
118                 fclose(fp);
119         }
120
121         SPRINT(pathname, "%s/%s/%s/secrets", INSTALL_DATA, options.extensions_dir, argv[1]);
122         if (!(fp = fopen(pathname, "w")))
123         {
124                 PERROR("Failed to write secrets example '%s'.\n", pathname);
125                 return(-1);
126         } else
127         {
128                 fprintf(fp, "# Format: <remote number> <key exchange> <cypher> [<key>]\n");
129                 fprintf(fp, "# The remote number must match the dialed number for outgoing calls.\n");
130                 fprintf(fp, "# The remote number must match the caller id for incoming calls.\n");
131                 fprintf(fp, "# The caller id must include the prefix digits as received.\n");
132                 fprintf(fp, "# The key exchange method must be given: e.g 'manual'\n");
133                 fprintf(fp, "# The cypher method must be given: e.g 'blowfish'\n");
134                 fprintf(fp, "# The key must be a string of characters (ASCII) or 0xXXXXXX...\n");
135                 fprintf(fp, "# All 2 or 3 attributes must be seperated by white space(s) and/or tab(s)\n");
136                 fprintf(fp, "# Empty lines and lines starting with '#' will be ignored.\n\n");
137                 fprintf(fp, "###############################################################################\n");
138                 fprintf(fp, "##       REFER TO THE DOCUMENTATION FOR DETAILS ON ENCRYPTION AND KEYS!      ##\n");
139                 fprintf(fp, "###############################################################################\n");
140                 fprintf(fp, "\n");
141                 fprintf(fp, "# This examples explains the format, NEVER USE IT, it would be dumb!\n");
142                 fprintf(fp, "021250993               manual  blowfish        0x012345678\n");
143                 fclose(fp);
144         }
145         printf("Extension %s created at %s/%s/%s/.\n", argv[1], INSTALL_DATA, options.extensions_dir, argv[1]);
146
147         return(0);
148 }