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