newtComponent statictyperadio;
newtComponent dhcptyperadio;
newtComponent pppoetyperadio;
-newtComponent pptptyperadio;
newtComponent dhcphostnameentry;
/* acceptable character filter for IP and netmaks entry boxes */
int startstatictype = 0;
int startdhcptype = 0;
int startpppoetype = 0;
- int startpptptype = 0;
/* Build some key strings. */
sprintf(addressfield, "%s_ADDRESS", colour);
if (strcmp(temp, "STATIC") == 0) startstatictype = 1;
if (strcmp(temp, "DHCP") == 0) startdhcptype = 1;
if (strcmp(temp, "PPPOE") == 0) startpppoetype = 1;
- if (strcmp(temp, "PPTP") == 0) startpptptype = 1;
statictyperadio = newtRadiobutton(2, 4, ctr[TR_STATIC], startstatictype, NULL);
dhcptyperadio = newtRadiobutton(2, 5, "DHCP", startdhcptype, statictyperadio);
pppoetyperadio = newtRadiobutton(2, 6, "PPPOE", startpppoetype, dhcptyperadio);
- pptptyperadio = newtRadiobutton(2, 7, "PPTP", startpptptype, pppoetyperadio);
newtFormAddComponents(networkform, statictyperadio, dhcptyperadio,
- pppoetyperadio, pptptyperadio, NULL);
+ pppoetyperadio, NULL);
newtComponentAddCallback(statictyperadio, networkdialogcallbacktype, NULL);
newtComponentAddCallback(dhcptyperadio, networkdialogcallbacktype, NULL);
newtComponentAddCallback(pppoetyperadio, networkdialogcallbacktype, NULL);
- newtComponentAddCallback(pptptyperadio, networkdialogcallbacktype, NULL);
dhcphostnamelabel = newtTextbox(2, 9, 18, 1, 0);
newtTextboxSetText(dhcphostnamelabel, ctr[TR_DHCP_HOSTNAME]);
strcpy(temp, defaultdhcphostname);
findkey(kv, addressfield, temp);
addressentry = newtEntry(20, (typeflag ? 11 : 4) + 0, temp, 20, &addressresult, 0);
newtEntrySetFilter(addressentry, ip_input_filter, NULL);
- if (typeflag == 1 && startstatictype == 0 && startpptptype == 0 )
+ if (typeflag == 1 && startstatictype == 0)
newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
newtFormAddComponent(networkform, addresslabel);
newtFormAddComponent(networkform, addressentry);
strcpy(temp, "255.255.255.0"); findkey(kv, netmaskfield, temp);
netmaskentry = newtEntry(20, (typeflag ? 11 : 4) + 1, temp, 20, &netmaskresult, 0);
newtEntrySetFilter(netmaskentry, ip_input_filter, NULL);
- if (typeflag == 1 && startstatictype == 0 && startpptptype == 0 )
+ if (typeflag == 1 && startstatictype == 0)
newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
newtFormAddComponent(networkform, netmasklabel);
strcpy(type, "STATIC");
if (typeflag)
gettype(type);
- if (strcmp(type, "STATIC") == 0 || strcmp(type, "PPTP") == 0 )
+ if (strcmp(type, "STATIC") == 0)
{
if (inet_addr(addressresult) == INADDR_NONE)
{
if (typeflag)
{
replacekeyvalue(kv, dhcphostnamefield, dhcphostnameresult);
- if (strcmp(type, "STATIC") != 0 && strcmp(type, "PPTP") != 0)
+ if (strcmp(type, "STATIC") != 0)
{
replacekeyvalue(kv, addressfield, "0.0.0.0");
replacekeyvalue(kv, netmaskfield, "0.0.0.0");
strcpy(type, "DHCP");
else if (selected == pppoetyperadio)
strcpy(type, "PPPOE");
- else if (selected == pptptyperadio)
- strcpy(type, "PPTP");
else
strcpy(type, "ERROR");
gettype(type);
- if (strcmp(type, "STATIC") != 0 && strcmp(type, "PPTP") != 0 )
+ if (strcmp(type, "STATIC") != 0)
{
newtEntrySetFlags(addressentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
newtEntrySetFlags(netmaskentry, NEWT_FLAG_DISABLED, NEWT_FLAGS_SET);
return 0;
}
-/* ### alter strupper ###
-char *strupper(char *s)
-{
- int n;
- for (n=0;s[n];n++) s[n]=toupper(s[n]);
- return s;
-}
-*/
-
-/* neuer StringUpper, wird zur Zeit nicht benutzt da UTF-8 nicht geht.
-void strupper(unsigned char *string)
-{
- unsigned char *str;
- for (str = string; *str != '\0'; str++)
- if (!(*str & 0x80) && islower(*str))
- *str = toupper(*str);
-}
-*/
-
-/* int ismacaddr(char *ismac)
-{
- char *a;
- fprintf(flog,"Check is MAC true\n"); // #### Debug ####
- for (a = ismac; *a; a++) {
- sprintf(flog,"%c\n", *a); // #### Debug ####
- if (*a != ':' && !isxdigit(*a)) return 0; // is int != ':' or not hexdigit then exit
- }
- return 1;
-}
-*/
-
int get_knic(int card) //returns "0" for zero cards or error and "1" card is found.
{
struct keyvalue *kv = initkeyvalues();
return found;
}
+int fmt_exists(const char *fname) { /* Check if it is any file or directory */
+ struct stat st;
+ if (stat(fname, &st) == -1) return 0;
+ else return 1;
+}
+
+int is_interface_up(char *card) { /* Check if the interface is UP */
+ char temp[STRING_SIZE];
+
+ sprintf(temp,"ip link show dev %s | grep -q UP", card);
+ if (mysystem(temp)) return 0; else return 1;
+}
+
+int rename_device(char *old_name, char *new_name) {
+ char temp[STRING_SIZE];
+
+ sprintf(temp,SYSDIR "/%s", old_name);
+ if (!(fmt_exists(temp))) {
+ fprintf(flog,"Device not found: %s\n",old_name);
+ return 0;
+ }
+ sprintf(temp,"/sbin/ip link set dev %s name %s",old_name ,new_name );
+ mysystem(temp);
+
+ return 1;
+}
+
+char g_temp[STRING_SIZE]="";
+char* readmac(char *card) {
+ FILE *fp;
+ char temp[STRING_SIZE], mac[20];
+
+ sprintf(temp,"/sys/class/net/%s/address",card);
+ if( (fp = fopen(temp, "r")) == NULL ) {
+ fprintf(flog,"Couldn't open: %s\n",temp);
+ return NULL;
+ }
+ fgets(mac, 18, fp);
+ strtok(mac,"\n");
+ fclose(fp);
+ strcpy(g_temp, mac);
+ return g_temp;
+}
+
+char* find_nic4mac(char *findmac) {
+ DIR *dir;
+ struct dirent *dirzeiger;
+ char temp[STRING_SIZE], temp2[STRING_SIZE];
+
+ if((dir=opendir(SYSDIR)) == NULL) {
+ fprintf(flog,"Fehler bei opendir (find_name4nic) ...\n");
+ return NULL;
+ }
+
+ sprintf(temp, "");
+ while((dirzeiger=readdir(dir)) != NULL) {
+ if(*((*dirzeiger).d_name) != '.' & strcmp(((*dirzeiger).d_name), "lo") != 0) {
+ sprintf(temp2, "%s", readmac((*dirzeiger).d_name) );
+ if (strcmp(findmac, temp2) == 0) {
+ sprintf(temp,"%s", (*dirzeiger).d_name);
+ break;
+ }
+ }
+ }
+
+ if(closedir(dir) == -1) fprintf(flog,"Fehler beim schliessen von %s\n", SYSDIR);
+ strcpy(g_temp, temp);
+ return g_temp;
+}
+
+int nic_shutdown(char *nic) {
+ char temp[STRING_SIZE];
+
+ sprintf(temp,"ip link set %s down", nic);
+ mysystem(temp);
+}
+
+int nic_startup(char *nic) {
+ char temp[STRING_SIZE];
+
+ sprintf(temp,"ip link set %s up", nic);
+ mysystem(temp);
+
+}
+
+int rename_nics(void) {
+ int i, j, k;
+ int fnics = scan_network_cards();
+ char nic2find[STRING_SIZE], temp[STRING_SIZE];
+
+ for(i=0; i<4; i++)
+ if (strcmp(knics[i].macaddr, ""))
+ for(j=0; j<fnics; j++)
+ if(strcmp(knics[i].macaddr, nics[j].macaddr) == 0) {
+ sprintf(nic2find,"%s0",lcolourcard[i]);
+ if(strcmp(nic2find, nics[j].nic)) {
+ if(is_interface_up(nics[j].nic)) {
+ nic_shutdown(nics[j].nic);
+ }
+ sprintf(temp,SYSDIR "/%s", nic2find);
+ if(fmt_exists(temp)) {
+ for(k=0; k<fnics; k++)
+ if (strcmp(nics[k].nic, nic2find) == 0 ) {
+ if(is_interface_up(nics[k].nic)) {
+ nic_shutdown(nics[k].nic);
+ }
+ sprintf(temp,"dummy%i",k);
+ if (rename_device(nics[k].nic, temp)) strcpy(nics[k].nic, temp);
+ }
+ }
+ if (rename_device(nics[j].nic, nic2find)) strcpy(nics[j].nic, nic2find);
+ }
+ }
+}
+
int create_udev(void)
{
#define UDEV_NET_CONF "/etc/udev/rules.d/30-persistent-network.rules"
FILE *fp;
int i;
- fprintf(flog,"Enter create_udev: "UDEV_NET_CONF"\n"); // #### Debug ####
if ( (fp = fopen(UDEV_NET_CONF, "w")) == NULL ) {
fprintf(stderr,"Couldn't open" UDEV_NET_CONF);
return 1;
{
if (strcmp(knics[i].macaddr, "")) {
fprintf(fp,"ACTION==\"add\", SUBSYSTEM==\"net\", SYSFS{address}==\"%s\", NAME=\"%s0\" # %s\n", knics[i].macaddr, lcolourcard[i], knics[i].description);
- fprintf(flog,"Write %s\n",lcolourcard[i]); // #### Debug ####
}
}
fclose(fp);
if (!(scanned_nics_read_done))
{
- fprintf(flog,"Enter scan_network_cards\n"); // #### Debug ####
mysystem("/bin/probenic.sh");
- // Read our scanned nics
if( (fp = fopen(SCANNED_NICS, "r")) == NULL )
{
fprintf(stderr,"Couldn't open "SCANNED_NICS);
if ( strncmp(temp_line, _driver, strlen(_driver)) == 0 ) sprintf(nics[count].driver, "%s", temp_line+strlen(_driver));
if ( strncmp(temp_line, _desc, strlen(_desc)) == 0 ) sprintf(nics[count].description, "%s", temp_line+strlen(_desc));
if ( strncmp(temp_line, _network_hwaddr, strlen(_network_hwaddr)) == 0 ) sprintf(nics[count].macaddr, "%s", temp_line+strlen(_network_hwaddr));
- if (strlen(nics[count].macaddr) > 15 ) count++;
+ if (strlen(nics[count].macaddr) > 15 ) {
+ sprintf(nics[count].nic, "%s", find_nic4mac(nics[count].macaddr));
+ count++;
+ }
}
fclose(fp);
scanned_nics_read_done = count;
char MenuInhalt[20][180];
char *pMenuInhalt[20];
-// strcpy( message , pnics[count].macaddr);
-// while (strcmp(message, "")) {
-// count++;
-// strcpy( message , pnics[count].macaddr);
-// }
-
while (strcmp(nics[count].macaddr, "")) count++; // 2 find how many nics in system
for ( i=0 ; i<4;i++) if (strcmp(knics[i].macaddr, "")) kcount++; // loop to find all knowing nics
- fprintf(flog, "Enter NicMenu\n"); // #### Debug ####
- fprintf(flog, "count nics %i\ncount knics %i\n", count, kcount); // #### Debug ####
// If new nics are found...
if (count > kcount) {
for (j=0 ; j <= kcount ; j++) {
if (strcmp(nics[ i ].macaddr, knics[ j ].macaddr) == 0 ) {
nic_in_use = 1;
- fprintf(flog,"NIC \"%s\" is in use.\n", nics[ i ].macaddr); // #### Debug ####
break;
}
}
if (!(nic_in_use)) {
- fprintf(flog,"NIC \"%s\" is free.\n", nics[ i ].macaddr); // #### Debug ####
if ( strlen(nics[i].description) < 55 )
sprintf(MenuInhalt[mcount], "%.*s", strlen(nics[i].description)-2, nics[i].description+1);
else {
pMenuInhalt[mcount] = NULL;
-// sprintf(message, "Es wurde(n) %d freie Netzwerkkarte(n) in Ihrem System gefunden.\nBitte waehlen Sie im naechsten Dialog eine davon aus.\n", count);
-// newtWinMessage("NetcardMenu", ctr[TR_OK], message);
-
- sprintf(message, "(TR) Bitte wählen Sie eine der untenstehenden Netzwerkkarten fuer die Schnittstelle \"%s\" aus.\n", ucolourcard[colour]);
- rc = newtWinMenu("(TR) NetcardMenu2", message, 50, 5, 5, 6, pMenuInhalt, &choise, ctr[TR_OK], ctr[TR_SELECT], ctr[TR_CANCEL], NULL);
+ sprintf(message, ctr[TR_CHOOSE_NETCARD], ucolourcard[colour]);
+ rc = newtWinMenu( ctr[TR_NETCARDMENU2], message, 50, 5, 5, 6, pMenuInhalt, &choise, ctr[TR_OK], ctr[TR_SELECT], ctr[TR_CANCEL], NULL);
if ( rc == 0 || rc == 1) {
write_configs_netudev(found_NIC_as_Card[choise], colour);
- } else if (rc == 2) {
-// manualdriver("pcnet32","");
- }
+ }
return 0;
} else {
// We have to add here that you can manually add a device
- errorbox("(TR) Es wurden leider keine freien Netzwerkkarten fuer die Schnittstelle in ihrem System gefunden.");
+ errorbox( ctr[TR_ERROR_INTERFACES]);
return 1;
}
}
writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
freekeyvalues(kv);
- fprintf(flog,"Card \"%s\" cleared\n",ucolourcard[card]); // #### Debug ####
return 0;
}
char message[STRING_SIZE];
int rc;
- sprintf(message, "(TR) Soll die Zuordnung der Netzwerkkarte \"%s\" entfernt werden ?\n", ucolourcard[card]);
+ sprintf(message, ctr[TR_REMOVE_CARD], ucolourcard[card]);
rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message);
if ( rc = 0 || rc == 1) {
clear_card_entry(card);
-// sprintf(temp1, "%s_DEV", ucolour);
-// sprintf(temp2, "%s_MACADDR", ucolour);
-// replacekeyvalue(kv, temp1, "");
-// replacekeyvalue(kv, temp2, "");
-// sprintf(temp1, "%s_DESCRIPTION", ucolour);
-// replacekeyvalue(kv, temp1, "");
-
-// writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
} else return 1;
return 0;