1 | #ifndef INADYN_H |
---|
2 | #define INADYN_H |
---|
3 | |
---|
4 | int readinadyn(const char* filename, char** user, char** pw, char** host) |
---|
5 | { |
---|
6 | debug(1000, "in"); |
---|
7 | FILE *fd = NULL; |
---|
8 | char *fileline = NULL, *tmpstr = NULL; |
---|
9 | int len = 0; |
---|
10 | |
---|
11 | fileline = malloc(MINMALLOC); |
---|
12 | if(fileline == NULL) |
---|
13 | { |
---|
14 | err("no memory"); |
---|
15 | return 1; |
---|
16 | } |
---|
17 | |
---|
18 | fd = fopen(filename, "r"); |
---|
19 | if(fd == NULL) |
---|
20 | { |
---|
21 | perr("can't open %s", filename); |
---|
22 | free(fileline); |
---|
23 | return 1; |
---|
24 | } |
---|
25 | |
---|
26 | while(fgets(fileline, MINMALLOC, fd) != NULL) |
---|
27 | { |
---|
28 | if(fileline[0] == '#' || fileline[0] == '\n') |
---|
29 | continue; |
---|
30 | len = strlen(fileline) - 1; |
---|
31 | if(len >= 0 && fileline[len] == '\n') |
---|
32 | fileline[len] = '\0'; |
---|
33 | len--; |
---|
34 | if(len >= 0 && fileline[len] == '\r') |
---|
35 | fileline[len] = '\0'; |
---|
36 | |
---|
37 | tmpstr = ostrstrcase(fileline, "--username "); |
---|
38 | if(tmpstr != NULL) |
---|
39 | { |
---|
40 | tmpstr += 11; |
---|
41 | if(tmpstr != NULL) |
---|
42 | { |
---|
43 | tmpstr[strlen(tmpstr)] = '\0'; |
---|
44 | free(*user); *user = NULL; |
---|
45 | *user = ostrcat(tmpstr, NULL, 0, 0); |
---|
46 | } |
---|
47 | } |
---|
48 | tmpstr = ostrstrcase(fileline, "--password "); |
---|
49 | if(tmpstr != NULL) |
---|
50 | { |
---|
51 | tmpstr += 11; |
---|
52 | if(tmpstr != NULL) |
---|
53 | { |
---|
54 | tmpstr[strlen(tmpstr)] = '\0'; |
---|
55 | free(*pw); *pw = NULL; |
---|
56 | *pw = ostrcat(tmpstr, NULL, 0, 0); |
---|
57 | } |
---|
58 | } |
---|
59 | tmpstr = ostrstrcase(fileline, "--alias "); |
---|
60 | if(tmpstr != NULL) |
---|
61 | { |
---|
62 | tmpstr += 8; |
---|
63 | if(tmpstr != NULL) |
---|
64 | { |
---|
65 | tmpstr[strlen(tmpstr)] = '\0'; |
---|
66 | free(*host); *host = NULL; |
---|
67 | *host = ostrcat(tmpstr, NULL, 0, 0); |
---|
68 | } |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | free(fileline); |
---|
73 | fclose(fd); |
---|
74 | return 0; |
---|
75 | } |
---|
76 | |
---|
77 | int writeinadyn(const char* filename, char* user, char* pw, char* host) |
---|
78 | { |
---|
79 | char* savesettings = NULL; |
---|
80 | |
---|
81 | savesettings = ostrcat(savesettings, "--username ", 1, 0); |
---|
82 | savesettings = ostrcat(savesettings, user, 1, 0); |
---|
83 | savesettings = ostrcat(savesettings, "\n", 1, 0); |
---|
84 | |
---|
85 | savesettings = ostrcat(savesettings, "--password ", 1, 0); |
---|
86 | savesettings = ostrcat(savesettings, pw, 1, 0); |
---|
87 | savesettings = ostrcat(savesettings, "\n", 1, 0); |
---|
88 | |
---|
89 | savesettings = ostrcat(savesettings, "--alias ", 1, 0); |
---|
90 | savesettings = ostrcat(savesettings, host, 1, 0); |
---|
91 | savesettings = ostrcat(savesettings, "\n", 1, 0); |
---|
92 | |
---|
93 | savesettings = ostrcat(savesettings, "update_period 60000\n", 1, 0); |
---|
94 | |
---|
95 | FILE* fd = fopen(filename, "w"); |
---|
96 | if(fd) |
---|
97 | { |
---|
98 | fprintf(fd, "%s\n", savesettings); |
---|
99 | fclose(fd); |
---|
100 | } |
---|
101 | free(savesettings); savesettings = NULL; |
---|
102 | |
---|
103 | return 0; |
---|
104 | } |
---|
105 | |
---|
106 | void screennetwork_inadyn() |
---|
107 | { |
---|
108 | int rcret = -1, ret = 0; |
---|
109 | struct skin* inadyn = getscreen("inadynsettings"); |
---|
110 | struct skin* listbox = getscreennode(inadyn, "listbox"); |
---|
111 | struct skin* startmode = getscreennode(inadyn, "startmode"); |
---|
112 | struct skin* user = getscreennode(inadyn, "user"); |
---|
113 | struct skin* pw = getscreennode(inadyn, "pw"); |
---|
114 | struct skin* host = getscreennode(inadyn, "host"); |
---|
115 | struct skin* tmp = NULL; |
---|
116 | |
---|
117 | char* iuser = NULL, *ipw = NULL, *ihost = NULL; |
---|
118 | |
---|
119 | readinadyn("/var/etc/inadyn.conf", &iuser, &ipw, &ihost); |
---|
120 | |
---|
121 | addchoicebox(startmode, "n", _("no")); |
---|
122 | addchoicebox(startmode, "y", _("yes")); |
---|
123 | setchoiceboxselection(startmode, getownconfig("inadyn")); |
---|
124 | |
---|
125 | changeinput(user, iuser); |
---|
126 | free(iuser); iuser = NULL; |
---|
127 | |
---|
128 | changeinput(pw, ipw); |
---|
129 | free(ipw); ipw = NULL; |
---|
130 | |
---|
131 | changeinput(host, ihost); |
---|
132 | free(ihost); ihost = NULL; |
---|
133 | |
---|
134 | drawscreen(inadyn, 0, 0); |
---|
135 | addscreenrc(inadyn, listbox); |
---|
136 | |
---|
137 | tmp = listbox->select; |
---|
138 | while(1) |
---|
139 | { |
---|
140 | addscreenrc(inadyn, tmp); |
---|
141 | rcret = waitrc(inadyn, 0, 0); |
---|
142 | tmp = listbox->select; |
---|
143 | |
---|
144 | if(rcret == getrcconfigint("rcexit", NULL)) break; |
---|
145 | |
---|
146 | if(rcret == getrcconfigint("rcok", NULL) || rcret == getrcconfigint("rcgreen", NULL)) |
---|
147 | { |
---|
148 | writeinadyn("/var/etc/inadyn.conf", user->ret, pw->ret, host->ret); |
---|
149 | if(startmode->ret != NULL) addownconfig("inadyn", startmode->ret); |
---|
150 | if(rcret == getrcconfigint("rcok", NULL)) break; |
---|
151 | if(rcret == getrcconfigint("rcgreen", NULL)) |
---|
152 | { |
---|
153 | system("killall inadyn; sleep 2; killall -9 inadyn"); |
---|
154 | ret = system("inadyn --input_file /var/etc/inadyn.conf &"); |
---|
155 | if(ret == 0) |
---|
156 | textbox(_("Message"), _("DYNDNS started."), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 10, 0); |
---|
157 | else |
---|
158 | textbox(_("Message"), _("DYNDNS not started,\nPlease check your config."), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 10, 0); |
---|
159 | drawscreen(inadyn, 0, 0); |
---|
160 | } |
---|
161 | } |
---|
162 | |
---|
163 | if(rcret == getrcconfigint("rcyellow", NULL)) |
---|
164 | { |
---|
165 | system("killall inadyn; sleep 2; killall -9 inadyn"); |
---|
166 | textbox(_("Message"), _("DYNDNS now stopped"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 10, 0); |
---|
167 | drawscreen(inadyn, 0, 0); |
---|
168 | } |
---|
169 | } |
---|
170 | |
---|
171 | delownerrc(inadyn); |
---|
172 | clearscreen(inadyn); |
---|
173 | } |
---|
174 | |
---|
175 | #endif |
---|