/* * read a essid config file and generate an interface config file */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include #include #include int main (int argc, char **argv) { char dline[64], func[12], value[64]; FILE *incfg,*outfile; char essid[64],pathname[255]; char wepkey[255], keyname[32]; char ipmethod[10]; int default_key=0,security=0; sprintf(essid,argv[1]); sprintf(pathname,"/etc/wifi/%s.cfg",essid); sprintf(keyname,"key_none"); incfg=fopen(pathname, "r"); if (! incfg) fprintf(stderr, "problem opening config file\n"); else { outfile=fopen("/tmp/interfaces.tmp", "w"); if (! outfile) fprintf(stderr, "problem opening config file\n"); else{ fprintf(outfile,"# /etc/network/interfaces - automatically generated by net-interfaces\n\n"); fprintf(outfile,"# Loopback Interface\nauto lo\niface lo inet loopback\n\n"); while(fgets(dline,sizeof(dline),incfg)) { if (sscanf(dline,"%s = %s", func, value) == 2) { printf("func: %s value:%s\n",func,value); if (strcmp(func, "ipmethod")==0) { if(strcmp(value,"DHCP")==0) sprintf(ipmethod,"%s","dhcp"); else sprintf(ipmethod,"%s","static"); } if (strcmp(func, "security")==0) { if(strcmp(value,"NONE")==0) security=0; else if(strcmp(value,"WEP")==0) security=1; else if(strcmp(value,"WPA-PSK")==0) security=2; else if(strcmp(value,"WPA-EAP")==0) security=3; } if (strcmp(func, "default_key")==0) { default_key=atoi(value); sprintf(keyname,"key_%d",default_key); printf("setting keyname: %s\n",keyname); } if (strcmp(func, keyname)==0) { printf("got value: %s\n",value); sprintf(wepkey,"%s",value); } } } fprintf(outfile,"# Wireless Interface\nauto eth0\niface eth0 inet %s\n",ipmethod); fprintf(outfile,"\twireless-essid %s\n",essid); if(security==0) fprintf(outfile,"\twireless-enc off\n"); else if (security==1) fprintf(outfile,"\twireless-key %s [%d] key [%d] key restricted\n",wepkey,(default_key+1),(default_key+1)); fprintf(outfile,"\twireless-mode managed\n\n"); fclose(outfile); } fclose(incfg); } system("/bin/mv /tmp/interfaces.tmp /etc/network/interfaces"); return 0; }