source: src/router/services/services/chillispot.c @ 17266

Last change on this file since 17266 was 17266, checked in by BrainSlayer, 23 months ago

hotspotsystems adjustments

File size: 10.5 KB
Line 
1/*
2 * chillispot.c
3 *
4 * Copyright (C) 2007 Sebastian Gottschall <gottschall@dd-wrt.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 *
20 * $Id:
21 */
22#include <unistd.h>
23#include <string.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <sys/types.h>
27#include <bcmnvram.h>
28#include <shutils.h>
29#include <nvparse.h>
30#include "snmp.h"
31#include <signal.h>
32#include <utils.h>
33#include <syslog.h>
34#include <wlutils.h>
35#include <errno.h>
36#include <md5.h>
37#include <services.h>
38
39#ifdef HAVE_CHILLI
40
41#ifdef HAVE_HOTSPOT
42void hotspotsys_config(void);
43#endif
44void chilli_config(void);
45void stop_chilli(void);
46
47void start_chilli(void)
48{
49        int ret = 0;
50        char ssid[128];
51
52        stop_chilli();          //ensure that its stopped
53
54        if (!strlen(nvram_safe_get("chilli_interface")))
55                nvram_set("chilli_interface", get_wdev());
56        if (!strlen(nvram_safe_get("hotss_interface")))
57                nvram_set("hotss_interface", get_wdev());
58
59#ifdef HAVE_HOTSPOT
60
61        if (nvram_match("chilli_enable", "1")
62            && nvram_match("chilli_def_enable", "0")
63            && !nvram_match("hotss_enable", "1")) {
64                nvram_unset("chilli_def_enable");
65                nvram_set("chilli_enable", "0");
66                return;
67        }
68
69        if (!nvram_match("chilli_enable", "1")
70            && !nvram_match("hotss_enable", "1")) {
71                nvram_unset("chilli_def_enable");
72                return;
73        }
74
75        if (nvram_match("hotss_enable", "1")) {
76                stop_cron();
77                if (!nvram_match("chilli_enable", "1")) {
78                        nvram_set("chilli_enable", "1");        // to get care of firewall, network, etc.
79                        nvram_set("chilli_def_enable", "0");
80                }
81                if (!nvram_match("hotss_preconfig", "1")) {
82                        nvram_set("hotss_preconfig", "1");
83                        sprintf(ssid, "HotSpotSystem.com-%s_%s",
84                                nvram_get("hotss_operatorid"),
85                                nvram_get("hotss_locationid"));
86                        nvram_set("wl0_ssid", ssid);
87                        nvram_set("time_zone", "+00");
88                        nvram_set("daylight_time", "1");
89                }
90                hotspotsys_config();
91                start_cron();
92        } else if (nvram_match("chilli_enable", "1")) {
93                nvram_unset("chilli_def_enable");
94                chilli_config();
95        }
96#else
97        if (!nvram_match("chilli_enable", "1"))
98                return;
99
100        chilli_config();
101
102#endif
103
104        ret = killall("chilli", SIGTERM);
105        ret = killall("chilli", SIGKILL);
106        if (f_exists("/tmp/hotss.conf")) {
107                ret = eval("chilli", "-c", "/tmp/hotss.conf");
108                dd_syslog(LOG_INFO,
109                          "hotspotsystem : chilli daemon successfully started\n");
110        } else {
111                ret = eval("chilli", "-c", "/tmp/chilli.conf");
112                dd_syslog(LOG_INFO,
113                          "chilli : chilli daemon successfully started\n");
114        }
115
116        cprintf("done\n");
117        return;
118}
119
120void stop_chilli(void)
121{
122        if (stop_process("chilli", "chilli daemon")) {
123                unlink("/tmp/chilli.conf");
124                unlink("/tmp/hotss.conf");
125        }
126        cprintf("done\n");
127        return;
128}
129
130void chilli_config(void)
131{
132        FILE *fp;
133        int i;
134
135#ifdef HAVE_CHILLILOCAL
136
137        if (!(fp = fopen("/tmp/fonusers.local", "w"))) {
138                perror("/tmp/fonusers.local");
139                return;
140        }
141        char *users = nvram_safe_get("fon_userlist");
142        char *u = (char *)malloc(strlen(users) + 1);
143        char *o = u;
144
145        strcpy(u, users);
146        char *sep = strsep(&u, "=");
147
148        while (sep != NULL) {
149                fprintf(fp, "%s ", sep);
150                char *pass = strsep(&u, " ");
151
152                fprintf(fp, "%s \n", pass != NULL ? pass : "");
153                sep = strsep(&u, "=");
154        }
155        free(o);
156        fclose(fp);
157#endif
158
159        if (!(fp = fopen("/tmp/chilli.conf", "w"))) {
160                perror("/tmp/chilli.conf");
161                return;
162        }
163
164        fprintf(fp, "radiusserver1 %s\n", nvram_get("chilli_radius"));
165        fprintf(fp, "radiusserver2 %s\n", nvram_get("chilli_backup"));
166        fprintf(fp, "radiussecret %s\n", nvram_get("chilli_pass"));
167
168        fprintf(fp, "dhcpif %s\n", nvram_safe_get("chilli_interface"));
169
170        fprintf(fp, "uamserver %s\n", nvram_get("chilli_url"));
171        if (nvram_invmatch("chilli_dns1", "0.0.0.0")
172            && nvram_invmatch("chilli_dns1", "")) {
173                fprintf(fp, "dns1 %s\n", nvram_get("chilli_dns1"));
174                if (nvram_invmatch("sv_localdns", "0.0.0.0")
175                    && nvram_invmatch("sv_localdns", ""))
176                        fprintf(fp, "dns2 %s\n", nvram_get("sv_localdns"));
177        } else if (nvram_invmatch("sv_localdns", "0.0.0.0")
178                   && nvram_invmatch("sv_localdns", ""))
179                fprintf(fp, "dns1 %s\n", nvram_get("sv_localdns"));
180
181        if (nvram_invmatch("chilli_uamsecret", ""))
182                fprintf(fp, "uamsecret %s\n", nvram_get("chilli_uamsecret"));
183        if (nvram_invmatch("chilli_uamanydns", "0"))
184                fprintf(fp, "uamanydns\n");
185        if (nvram_invmatch("chilli_uamallowed", ""))
186                fprintf(fp, "uamallowed %s\n", nvram_get("chilli_uamallowed"));
187        if (nvram_invmatch("chilli_net", ""))
188                fprintf(fp, "net %s\n", nvram_get("chilli_net"));
189        if (nvram_match("chilli_macauth", "1"))
190                fprintf(fp, "macauth\n");
191#ifndef HAVE_FON
192        if (nvram_match("fon_enable", "1")) {
193#endif
194                char hyp[32];
195
196                strcpy(hyp, nvram_safe_get("wl0_hwaddr"));
197                for (i = 0; i < strlen(hyp); i++)
198                        if (hyp[i] == ':')
199                                hyp[i] = '-';
200                if (i > 0)
201                        fprintf(fp, "radiusnasid %s\n", hyp);
202                nvram_set("chilli_radiusnasid", hyp);
203                fprintf(fp, "interval 300\n");
204#ifndef HAVE_FON
205        } else {
206                if (nvram_invmatch("chilli_radiusnasid", ""))
207                        fprintf(fp, "radiusnasid %s\n",
208                                nvram_get("chilli_radiusnasid"));
209        }
210#endif
211
212        if (nvram_invmatch("chilli_additional", "")) {
213                char *add = nvram_safe_get("chilli_additional");
214
215                i = 0;
216                do {
217                        if (add[i] != 0x0D)
218                                fprintf(fp, "%c", add[i]);
219                }
220                while (add[++i]);
221                i = 0;
222                int a = 0;
223                char *filter = strdup(add);
224
225                do {
226                        if (add[i] != 0x0D)
227                                filter[a++] = add[i];
228                }
229                while (add[++i]);
230
231                filter[a] = 0;
232                if (strcmp(filter, add)) {
233                        nvram_set("chilli_additional", filter);
234                        nvram_commit();
235                }
236                free(filter);
237        }
238        fflush(fp);
239        fclose(fp);
240
241        return;
242}
243
244#ifdef HAVE_HOTSPOT
245
246void hotspotsys_config(void)
247{
248        FILE *fp;
249        char *next;
250        char var[64];
251        char *dnslist;
252        int i;
253
254        md5_ctx_t MD;
255
256        if (strlen(nvram_safe_get("hotss_remotekey")) != 12) {
257                unsigned char hash[32];
258                char *et0 = nvram_safe_get("et0macaddr");
259
260                md5_begin(&MD);
261                md5_hash(et0, 17, &MD);
262                md5_end((unsigned char *)hash, &MD);
263                char idkey[16];
264                int i;
265
266                for (i = 0; i < 6; i++)
267                        sprintf(&idkey[2 * i], "%02d",
268                                (hash[i] + hash[i + 1]) % 100);
269                idkey[12] = '\0';
270                nvram_set("hotss_remotekey", idkey);
271                nvram_commit();
272                char sendid[256];
273                sprintf(sendid,
274                        "/usr/bin/wget http://tech.hotspotsystem.com/up.php?mac=`nvram get wl0_hwaddr|sed s/:/-/g`\\&operator=%s\\&location=%s\\&remotekey=%s",
275                        nvram_get("hotss_operatorid"),
276                        nvram_get("hotss_locationid"),
277                        nvram_get("hotss_remotekey"));
278                system2(sendid);
279        }
280
281        if (!(fp = fopen("/tmp/hotss.conf", "w"))) {
282                perror("/tmp/hotss.conf");
283                return;
284        }
285
286        fprintf(fp, "radiusserver1 radius.hotspotsystem.com\n");
287        fprintf(fp, "radiusserver2 radius2.hotspotsystem.com\n");
288        fprintf(fp, "radiussecret hotsys123\n");
289
290        fprintf(fp, "dhcpif %s\n", nvram_safe_get("hotss_interface"));
291        if (nvram_invmatch("hotss_net", ""))
292                fprintf(fp, "net %s\n", nvram_get("hotss_net"));
293
294        char *uamdomain = "customer.hotspotsystem.com";
295        if (!nvram_match("hotss_customuam", "")) {
296                uamdomain = nvram_safe_get("hotss_customuam");
297        }
298        fprintf(fp,
299                "uamserver %s://%s/customer/hotspotlogin.php\n",
300                nvram_default_get("hotss_customuamproto", "https"), uamdomain);
301
302        if (nvram_invmatch("wan_get_dns", "0.0.0.0")
303            && nvram_invmatch("wan_get_dns", "")) {
304                dnslist = nvram_safe_get("wan_get_dns");
305                i = 1;
306                foreach(var, dnslist, next) {
307                        if (i > 2)
308                                break;
309                        fprintf(fp, "dns%d %s\n", i, var);
310                        i++;
311                }
312        } else if (nvram_invmatch("wan_dns", "0.0.0.0")
313                   && nvram_invmatch("wan_dns", "")) {
314                dnslist = nvram_safe_get("wan_dns");
315                i = 1;
316                foreach(var, dnslist, next) {
317                        if (i > 2)
318                                break;
319                        fprintf(fp, "dns%d %s\n", i, var);
320                        i++;
321                }
322        } else if (nvram_invmatch("sv_localdns", "0.0.0.0")
323                   && nvram_invmatch("sv_localdns", "")) {
324                fprintf(fp, "dns1 %s\n", nvram_get("sv_localdns"));
325        }
326
327        fprintf(fp, "uamsecret hotsys123\n");
328        fprintf(fp, "uamanydns\n");
329
330        fprintf(fp, "radiusnasid %s_%s\n", nvram_get("hotss_operatorid"),
331                nvram_get("hotss_locationid"));
332        if (!nvram_match("hotss_loginonsplash", "1")) {
333                fprintf(fp,
334                        "uamhomepage %s://%s/customer/index.php?operator=%s&location=%s%s\n",
335                        nvram_safe_get("hotss_customuamproto"), uamdomain,
336                        nvram_get("hotss_operatorid"),
337                        nvram_get("hotss_locationid"),
338                        nvram_match("hotss_customsplash",
339                                    "1") ? "&forward=1" : "");
340        }
341        fprintf(fp, "coaport 3799\n");
342        fprintf(fp, "coanoipcheck\n");
343        fprintf(fp, "domain key.chillispot.info\n");
344
345        if (nvram_invmatch("hotss_uamallowed", "")
346            && nvram_match("hotss_uamenable", "1"))
347                fprintf(fp, "uamallowed %s\n", nvram_get("hotss_uamallowed"));
348
349        fprintf(fp,
350                "uamallowed hotspotsystem.com,%s,www.hotspotsystem.com,tech.hotspotsystem.com\n",
351                uamdomain);
352        fprintf(fp, "uamallowed 66.211.128.0/17,216.113.128.0/17\n");
353        fprintf(fp, "uamallowed 70.42.128.0/17,128.242.125.0/24\n");
354        fprintf(fp,
355                "uamallowed 62.249.232.74,155.136.68.77,155.136.66.34,66.4.128.0/17,66.211.128.0/17,66.235.128.0/17\n");
356        fprintf(fp,
357                "uamallowed 88.221.136.146,195.228.254.149,195.228.254.152,203.211.140.157,203.211.150.204\n");
358        fprintf(fp, "uamallowed 82.199.90.0/24,91.212.42.0/24\n");
359        fprintf(fp, "uamallowed live.adyen.com\n");
360        fprintf(fp, "uamallowed www.paypal.com,www.paypalobjects.com\n");
361        fprintf(fp,
362                "uamallowed www.worldpay.com,select.worldpay.com,secure.ims.worldpay.com,www.rbsworldpay.com,secure.wp3.rbsworldpay.com\n");
363        fprintf(fp,
364                "uamallowed a1.hotspotsystem.com,a2.hotspotsystem.com,a3.hotspotsystem.com,a4.hotspotsystem.com,a5.hotspotsystem.com,a6.hotspotsystem.com\n");
365        fprintf(fp,
366                "uamallowed a7.hotspotsystem.com,a8.hotspotsystem.com,a9.hotspotsystem.com,a10.hotspotsystem.com,a11.hotspotsystem.com,a12.hotspotsystem.com\n");
367        fprintf(fp,
368                "uamallowed a13.hotspotsystem.com,a14.hotspotsystem.com,a15.hotspotsystem.com,a16.hotspotsystem.com,a17.hotspotsystem.com,a18.hotspotsystem.com\n");
369        fprintf(fp,
370                "uamallowed a19.hotspotsystem.com,a20.hotspotsystem.com,a21.hotspotsystem.com,a22.hotspotsystem.com,a23.hotspotsystem.com,a24.hotspotsystem.com\n");
371        fprintf(fp,
372                "uamallowed a25.hotspotsystem.com,a26.hotspotsystem.com,a27.hotspotsystem.com,a28.hotspotsystem.com,a29.hotspotsystem.com,a30.hotspotsystem.com\n");
373
374        fprintf(fp, "interval 300\n");
375
376        fflush(fp);
377        fclose(fp);
378
379        return;
380}
381
382#endif                          /* HAVE_HOTSPOT */
383#endif                          /* HAVE_CHILLI */
Note: See TracBrowser for help on using the repository browser.