Changeset 8947
- Timestamp:
- 02/06/08 15:39:03 (5 years ago)
- File:
-
- 1 edited
-
src/router/services/services/anchorfree.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/router/services/services/anchorfree.c
r8944 r8947 93 93 hint.ai_socktype = SOCK_STREAM; 94 94 rc = getaddrinfo (name, NULL, &hint, &result); 95 if (!result) //give it a second try96 rc = getaddrinfo (name, NULL, &hint, &result);97 95 if (!result) //give it a second try 96 rc = getaddrinfo (name, NULL, &hint, &result); 97 98 98 if (result) 99 99 { … … 121 121 for (i = 0; i < 16; i++) 122 122 { 123 unsigned int k = key[i];124 sprintf (output, "%s%X", output, k&0xff);123 unsigned int k = key[i]; 124 sprintf (output, "%s%X", output, k & 0xff); 125 125 } 126 126 // fprintf (stderr, "final hash = %s\n", output); … … 128 128 unsigned char ctable[16] = { "0123456789ABCDEF" }; 129 129 void 130 toURL (unsigned char *text, char *output) 131 { 130 toURL (char *t, char *output) 131 { 132 unsigned char *text = (unsigned char *) t; 132 133 char *p = output; 133 134 int i; 134 135 int n = 0; 135 for (i = 0; i < strlen (t ext); i++)136 for (i = 0; i < strlen (t); i++) 136 137 { 137 138 p[n++] = '%'; … … 145 146 start_anchorfree (void) 146 147 { 147 int need_commit =0;148 int need_commit = 0; 148 149 nvram_set ("af_dnathost", "0"); 149 150 nvram_set ("af_dnatport", "0"); … … 173 174 char ssid[128]; 174 175 if (nvram_match ("af_ssid", "1")) 175 {176 toURL (nvram_safe_get ("af_ssid_name"), ssid);177 }176 { 177 toURL (nvram_safe_get ("af_ssid_name"), ssid); 178 } 178 179 else 179 180 { … … 184 185 #endif 185 186 } 186 187 if (nvram_match ("af_ssid", "1") && !nvram_match("af_ssid_created","1")) 188 { 189 nvram_set("af_ssid_created","1"); 190 #ifndef HAVE_MADWIFI 191 nvram_set("wl0_vifs","wl0.1"); 192 nvram_set("wl_vifs","wl0.1"); 193 nvram_set("wl0.1_ssid",nvram_safe_get("af_ssid_name")); 194 nvram_set("wl0.1_bridged","0"); 195 nvram_set("wl0.1_ipaddr","172.45.0.1"); 196 nvram_set("wl0.1_netmask","255.255.255.0"); 197 nvram_set("mdhcpd_count","1"); 198 nvram_set("mdhcpd","wl0.1>On>100>50>3600"); 199 #else 200 nvram_set("ath0_vifs","ath0.1"); 201 nvram_set("ath0.1_ssid",nvram_safe_get("af_ssid_name")); 202 nvram_set("ath0.1_bridged","0"); 203 nvram_set("ath0.1_ipaddr","172.45.0.1"); 204 nvram_set("ath0.1_netmask","255.255.255.0"); 205 nvram_set("mdhcpd_count","1"); 206 nvram_set("mdhcpd","ath0.1>On>100>50>3600"); 207 #endif 208 nvram_commit(); 209 stop_lan(); 210 start_lan(); 211 stop_dnsmasq(); 212 start_dnsmasq(); 213 start_firewall(); 214 stop_firewall(); 215 start_firewall(); 216 }else if (nvram_match ("af_ssid", "0") && nvram_match("af_ssid_created","1")) 217 { 218 nvram_set("af_ssid_created","0"); 219 #ifndef HAVE_MADWIFI 220 nvram_set("wl0_vifs",""); 221 nvram_set("wl_vifs",""); 222 nvram_set("mdhcpd_count","0"); 223 nvram_set("mdhcpd",""); 224 #else 225 nvram_set("ath0_vifs",""); 226 nvram_set("mdhcpd_count","0"); 227 nvram_set("mdhcpd",""); 228 #endif 229 nvram_commit(); 230 stop_lan(); 231 start_lan(); 232 stop_dnsmasq(); 233 start_dnsmasq(); 234 stop_firewall(); 235 start_firewall(); 236 } 237 187 188 if (nvram_match ("af_ssid", "1") 189 && !nvram_match ("af_ssid_created", "1")) 190 { 191 nvram_set ("af_ssid_created", "1"); 192 #ifndef HAVE_MADWIFI 193 nvram_set ("wl0_vifs", "wl0.1"); 194 nvram_set ("wl_vifs", "wl0.1"); 195 nvram_set ("wl0.1_ssid", nvram_safe_get ("af_ssid_name")); 196 nvram_set ("wl0.1_bridged", "0"); 197 nvram_set ("wl0.1_ipaddr", "172.45.0.1"); 198 nvram_set ("wl0.1_netmask", "255.255.255.0"); 199 nvram_set ("mdhcpd_count", "1"); 200 nvram_set ("mdhcpd", "wl0.1>On>100>50>3600"); 201 #else 202 nvram_set ("ath0_vifs", "ath0.1"); 203 nvram_set ("ath0.1_ssid", nvram_safe_get ("af_ssid_name")); 204 nvram_set ("ath0.1_bridged", "0"); 205 nvram_set ("ath0.1_ipaddr", "172.45.0.1"); 206 nvram_set ("ath0.1_netmask", "255.255.255.0"); 207 nvram_set ("mdhcpd_count", "1"); 208 nvram_set ("mdhcpd", "ath0.1>On>100>50>3600"); 209 #endif 210 need_commit = 1; 211 stop_lan (); 212 start_lan (); 213 stop_dnsmasq (); 214 start_dnsmasq (); 215 start_firewall (); 216 stop_firewall (); 217 start_firewall (); 218 } 219 else if (nvram_match ("af_ssid", "0") 220 && nvram_match ("af_ssid_created", "1")) 221 { 222 nvram_set ("af_ssid_created", "0"); 223 #ifndef HAVE_MADWIFI 224 nvram_set ("wl0_vifs", ""); 225 nvram_set ("wl_vifs", ""); 226 nvram_set ("mdhcpd_count", "0"); 227 nvram_set ("mdhcpd", ""); 228 #else 229 nvram_set ("ath0_vifs", ""); 230 nvram_set ("mdhcpd_count", "0"); 231 nvram_set ("mdhcpd", ""); 232 #endif 233 need_commit = 1; 234 stop_lan (); 235 start_lan (); 236 stop_dnsmasq (); 237 start_dnsmasq (); 238 stop_firewall (); 239 start_firewall (); 240 } 241 else if (nvram_match ("af_ssid_created", "1")) 242 { 243 #ifndef HAVE_MADWIFI 244 if (!nvram_match ("af_ssid_name", nvram_safe_get ("wl0.1_ssid"))) 245 #else 246 if (!nvram_match ("af_ssid_name", nvram_safe_get ("wl0.1_ssid"))) 247 #endif 248 nvram_set ("wl0.1_ssid", nvram_safe_get ("wl0.1_ssid")); 249 need_commit = 1; 250 stop_lan (); 251 start_lan (); 252 stop_dnsmasq (); 253 start_dnsmasq (); 254 stop_firewall (); 255 start_firewall (); 256 257 } 258 259 238 260 char addr[256]; 239 261 toURL (nvram_safe_get ("af_address"), addr); … … 247 269 toURL (nvram_safe_get ("af_state"), state); 248 270 char country[64]; 249 strcpy (country,getIsoName(nvram_safe_get ("af_country")));271 strcpy (country, getIsoName (nvram_safe_get ("af_country"))); 250 272 char cat[64]; 251 273 toURL (nvram_safe_get ("af_category"), cat); … … 261 283 if (response == NULL) 262 284 { 263 fprintf (stderr, "error while registration (cannot reach registration site)!\n"); 264 nvram_set ("af_servicestatus", "cannot reach registration site!"); 265 nvram_set ("af_registered", "0"); 266 nvram_commit(); 285 fprintf (stderr, 286 "error while registration (cannot reach registration site)!\n"); 287 nvram_set ("af_servicestatus", "cannot reach registration site!"); 288 nvram_set ("af_registered", "0"); 289 nvram_commit (); 267 290 return; 268 291 } … … 272 295 { 273 296 fprintf (stderr, "registration failed (bad status)\n"); 274 nvram_set ("af_servicestatus", "registration failed (bad status)");297 nvram_set ("af_servicestatus", "registration failed (bad status)"); 275 298 fclose (response); 276 nvram_set ("af_registered", "0");277 nvram_commit ();299 nvram_set ("af_registered", "0"); 300 nvram_commit (); 278 301 return; 279 302 } … … 284 307 fprintf (stderr, "registration failed\n"); 285 308 fclose (response); 286 nvram_set ("af_registered", "0");287 nvram_commit ();309 nvram_set ("af_registered", "0"); 310 nvram_commit (); 288 311 return; 289 312 } … … 293 316 { 294 317 fprintf (stderr, "registration failed (bad sid)\n"); 295 nvram_set ("af_servicestatus", "registration failed (bad sid)");318 nvram_set ("af_servicestatus", "registration failed (bad sid)"); 296 319 fclose (response); 297 nvram_set ("af_registered", "0");298 nvram_commit ();320 nvram_set ("af_registered", "0"); 321 nvram_commit (); 299 322 return; 300 323 } … … 308 331 nvram_set ("af_dnatport", status); 309 332 fclose (response); 310 need_commit=1; 311 }else if (nvram_match("af_ssid_created","1")) 312 { 313 nvram_set("af_ssid_created","0"); 314 #ifndef HAVE_MADWIFI 315 nvram_set("wl0_vifs",""); 316 nvram_set("wl_vifs",""); 317 nvram_set("mdhcpd_count","0"); 318 nvram_set("mdhcpd",""); 319 #else 320 nvram_set("ath0_vifs",""); 321 nvram_set("mdhcpd_count","0"); 322 nvram_set("mdhcpd",""); 323 #endif 324 need_commit=1; 325 stop_lan(); 326 start_lan(); 327 stop_dnsmasq(); 328 start_dnsmasq(); 329 } 330 333 need_commit = 1; 334 } 335 else if (nvram_match ("af_ssid_created", "1")) 336 { 337 nvram_set ("af_ssid_created", "0"); 338 #ifndef HAVE_MADWIFI 339 nvram_set ("wl0_vifs", ""); 340 nvram_set ("wl_vifs", ""); 341 nvram_set ("mdhcpd_count", "0"); 342 nvram_set ("mdhcpd", ""); 343 #else 344 nvram_set ("ath0_vifs", ""); 345 nvram_set ("mdhcpd_count", "0"); 346 nvram_set ("mdhcpd", ""); 347 #endif 348 need_commit = 1; 349 stop_lan (); 350 start_lan (); 351 stop_dnsmasq (); 352 start_dnsmasq (); 353 } 354 331 355 if (need_commit) 332 nvram_commit();356 nvram_commit (); 333 357 return; 334 358 } … … 348 372 349 373 getIPFromName (nvram_safe_get ("af_dnathost"), host); 350 if (!strcmp(host,"0.0.0.0")) 351 { 352 fprintf(stderr,"cannot resolve %s\n",nvram_safe_get ("af_dnathost")); 353 return; 374 if (!strcmp (host, "0.0.0.0")) 375 { 376 fprintf (stderr, "cannot resolve %s\n", 377 nvram_safe_get ("af_dnathost")); 378 return; 354 379 } 355 380 sprintf (dest, "%s:%s", host, nvram_safe_get ("af_dnatport")); 356 381 // sprintf (source, "%d/%d", nvram_safe_get ("lan_ipaddr"), 357 // getmask (nvram_safe_get ("lan_netmask")));382 // getmask (nvram_safe_get ("lan_netmask"))); 358 383 sprintf (source, "0.0.0.0/0"); 359 384 if (nvram_match ("af_ssid", "1")) 360 sprintf (source, "%s/%d", nvram_safe_get (IFPREFIX "0.1_ipaddr"),361 getmask (nvram_safe_get (IFPREFIX "0.1_netmask")));385 sprintf (source, "%s/%d", nvram_safe_get (IFPREFIX "0.1_ipaddr"), 386 getmask (nvram_safe_get (IFPREFIX "0.1_netmask"))); 362 387 363 388 eval ("iptables", "-t", "nat", "-D", "PREROUTING", "-s", source, "-p", … … 377 402 stop_anchorfree_unregister (void) 378 403 { 379 char url[1024];380 sprintf (url, "wget -q -O- \"http://afhrp.anchorfree.com/unregister.php?"381 "uid=%s&"382 "sid=%s\"", nvram_safe_get ("af_hash"),383 nvram_safe_get ("af_serviceid"));384 eval ("rm", "-f", "/tmp/.anchorfree");385 system (url);404 char url[1024]; 405 sprintf (url, "wget -q -O- \"http://afhrp.anchorfree.com/unregister.php?" 406 "uid=%s&" 407 "sid=%s\"", nvram_safe_get ("af_hash"), 408 nvram_safe_get ("af_serviceid")); 409 eval ("rm", "-f", "/tmp/.anchorfree"); 410 system (url); 386 411 } 387 412 … … 400 425 sprintf (dest, "%s:%s", host, nvram_safe_get ("af_dnatport")); 401 426 // sprintf (source, "%s/%d", nvram_safe_get ("lan_ipaddr"), 402 // getmask (nvram_safe_get ("lan_netmask")));427 // getmask (nvram_safe_get ("lan_netmask"))); 403 428 sprintf (source, "0.0.0.0/0"); 404 429 if (nvram_match ("af_ssid", "1")) 405 sprintf (source, "%s/%d", nvram_safe_get (IFPREFIX "0.1_ipaddr"), 406 getmask (nvram_safe_get (IFPREFIX "0.1_netmask"))); 407 408 eval ("iptables", "-t", "nat", "-D", "PREROUTING", "-s", source, "-p","tcp", "--dport", "80", "-j", "DNAT", "--to", dest); 409 eval ("iptables", "-t", "nat", "-D", "PREROUTING", "-s", source, "-p","tcp", "-d", nvram_safe_get ("lan_ipaddr"), "-j", "DNAT", "--to",nvram_safe_get ("lan_ipaddr")); 430 sprintf (source, "%s/%d", nvram_safe_get (IFPREFIX "0.1_ipaddr"), 431 getmask (nvram_safe_get (IFPREFIX "0.1_netmask"))); 432 433 eval ("iptables", "-t", "nat", "-D", "PREROUTING", "-s", source, "-p", 434 "tcp", "--dport", "80", "-j", "DNAT", "--to", dest); 435 eval ("iptables", "-t", "nat", "-D", "PREROUTING", "-s", source, "-p", 436 "tcp", "-d", nvram_safe_get ("lan_ipaddr"), "-j", "DNAT", "--to", 437 nvram_safe_get ("lan_ipaddr")); 410 438 eval ("rm", "-f", "/tmp/.anchorfree"); 411 if (nvram_match ("af_enable","0"))412 stop_anchorfree_unregister();413 nvram_commit ();439 if (nvram_match ("af_enable", "0")) 440 stop_anchorfree_unregister (); 441 nvram_commit (); 414 442 } 415 443 return; 416 444 } 417
Note: See TracChangeset
for help on using the changeset viewer.
