mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-09 18:45:54 +02:00
Neue Netzwerkerkennung-Beta
git-svn-id: http://svn.ipfire.org/svn/ipfire/trunk@471 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8
This commit is contained in:
@@ -1,3 +1,62 @@
|
||||
------------------------------------------------------------------------
|
||||
r470 | ms | 2007-03-28 20:59:56 +0200 (Wed, 28 Mar 2007) | 2 lines
|
||||
|
||||
Devel Version immer bauen lassen...
|
||||
|
||||
------------------------------------------------------------------------
|
||||
r469 | maniacikarus | 2007-03-28 19:33:12 +0200 (Wed, 28 Mar 2007) | 3 lines
|
||||
|
||||
kleine fixes in den firewalllogs
|
||||
neues feature in der dhcp.cgi
|
||||
|
||||
------------------------------------------------------------------------
|
||||
r468 | ms | 2007-03-28 17:48:45 +0200 (Wed, 28 Mar 2007) | 2 lines
|
||||
|
||||
Mal die von Maniac geloeschten Aenderungen wieder in die status.cgi gepackt.
|
||||
|
||||
------------------------------------------------------------------------
|
||||
r467 | maniacikarus | 2007-03-27 20:52:07 +0200 (Tue, 27 Mar 2007) | 2 lines
|
||||
|
||||
Korrekturen im Code, es wird langsam ....
|
||||
|
||||
------------------------------------------------------------------------
|
||||
r466 | ms | 2007-03-27 16:33:09 +0200 (Tue, 27 Mar 2007) | 2 lines
|
||||
|
||||
Sambaa-Konfigurations-Fixes
|
||||
|
||||
------------------------------------------------------------------------
|
||||
r465 | ms | 2007-03-26 21:59:37 +0200 (Mon, 26 Mar 2007) | 5 lines
|
||||
|
||||
Added whatmask
|
||||
Netzwerkscripts erweitert.
|
||||
upnp.cgi gefixt.
|
||||
Installer schreibt die Spracheinstellungen wieder.
|
||||
|
||||
------------------------------------------------------------------------
|
||||
r464 | maniacikarus | 2007-03-26 21:16:19 +0200 (Mon, 26 Mar 2007) | 2 lines
|
||||
|
||||
kleiner Zwischenfix
|
||||
|
||||
------------------------------------------------------------------------
|
||||
r463 | maniacikarus | 2007-03-26 20:38:15 +0200 (Mon, 26 Mar 2007) | 5 lines
|
||||
|
||||
colours.txt ins Theme Verzeichnis geschoben,
|
||||
daher auch Anpassungen an den Firewall*.cgi
|
||||
kleinere Fixes an der samba.cgi
|
||||
default Config Dateien für Samba ins SVN gestellt
|
||||
|
||||
------------------------------------------------------------------------
|
||||
r462 | ms | 2007-03-25 21:58:37 +0200 (Sun, 25 Mar 2007) | 4 lines
|
||||
|
||||
Erste Teile der neuen Netzwerkscripte.
|
||||
Installer-Fix.
|
||||
SCSI+SATA-Module zum Kernel hinzugefuegt
|
||||
|
||||
------------------------------------------------------------------------
|
||||
r461 | ms | 2007-03-25 09:47:42 +0200 (Sun, 25 Mar 2007) | 2 lines
|
||||
|
||||
Kleiner Fix...
|
||||
|
||||
------------------------------------------------------------------------
|
||||
r460 | ms | 2007-03-25 08:43:08 +0200 (Sun, 25 Mar 2007) | 3 lines
|
||||
|
||||
|
||||
@@ -1,18 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
MODULES=$(/bin/kudzu -qps -t 30 -c NETWORK | grep driver | cut -d ' ' -f 2 | sort)
|
||||
|
||||
if [ "$1" == "count" ]; then
|
||||
/bin/kudzu -qps -t 30 -c NETWORK | grep driver | wc -l | awk '{ print $1 }' > /tmp/drivercount
|
||||
exit 0
|
||||
else
|
||||
NUMBER=$1
|
||||
fi
|
||||
|
||||
if [ "$NUMBER" ]; then
|
||||
echo "$(echo $MODULES | grep -n $NUMBER | cut -c 1-2 )" > /tmp/nicdriver
|
||||
else
|
||||
echo "$MODULES" > /tmp/nicdriver
|
||||
fi
|
||||
|
||||
# kudzu -qps -c NETWORK | egrep "desc|network.hwaddr|driver" | awk -F': ' '{print $2}' | sed -e '/..:..:..:..:..:../a\\' -e "s/$/\;/g" | tr "\n" "XX" | sed -e "s/XX/\n/g" -e "s/\;X/\;/g"
|
||||
hwinfo --netcard | egrep "Model|HW Address" | \
|
||||
awk -F": " '{ print $2 }' | sed -e '/..:..:..:..:..:../a\\' -e "s/$/\;/g" | \
|
||||
tr "\n" "XX" | sed -e "s/XX/\n/g" -e "s/\;X/\;/g" | \
|
||||
sort > /tmp/scanned_nics 2>/dev/null
|
||||
|
||||
162
tmp/nic.c
Normal file
162
tmp/nic.c
Normal file
@@ -0,0 +1,162 @@
|
||||
#include <newt.h> /* Fenster */
|
||||
#include <stdio.h> /* File IO */
|
||||
#include <stdlib.h> /* exit() */
|
||||
#include <string.h> /* Strings */
|
||||
|
||||
#define STRING_SIZE 256
|
||||
|
||||
#define KNOWN_NICS "/var/ipfire/ethernet/known_nics"
|
||||
#define SCANNED_NICS "/tmp/scanned_nics"
|
||||
|
||||
struct nic
|
||||
{
|
||||
char description[256];
|
||||
char macaddr[20];
|
||||
};
|
||||
|
||||
struct knic
|
||||
{
|
||||
char macaddr[20];
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
FILE *fp;
|
||||
char temp_line[STRING_SIZE];
|
||||
struct nic nics[20], *pnics;
|
||||
struct knic knics[20];
|
||||
pnics = nics;
|
||||
int rc, choise, count = 0, kcount = 0, i, found;
|
||||
char macaddr[STRING_SIZE], description[STRING_SIZE];
|
||||
char message[STRING_SIZE];
|
||||
|
||||
char MenuInhalt[20][80];
|
||||
char *pMenuInhalt[20];
|
||||
|
||||
newtComponent form;
|
||||
|
||||
// Read the nics we already use
|
||||
if( (fp = fopen(KNOWN_NICS, "r")) == NULL )
|
||||
{
|
||||
fprintf(stderr,"Couldn't open " KNOWN_NICS);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while ( fgets(temp_line, STRING_SIZE, fp) != NULL)
|
||||
{
|
||||
strcpy( knics[kcount].macaddr , strtok(temp_line,";") );
|
||||
if (strlen(knics[kcount].macaddr) > 5 ) kcount++;
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
// Read our scanned nics
|
||||
if( (fp = fopen(SCANNED_NICS, "r")) == NULL )
|
||||
{
|
||||
fprintf(stderr,"Couldn't open "SCANNED_NICS);
|
||||
return 1;
|
||||
}
|
||||
while ( fgets(temp_line, STRING_SIZE, fp) != NULL)
|
||||
{
|
||||
strcpy(description, strtok(temp_line,";") );
|
||||
strcpy(macaddr, strtok(NULL,";") );
|
||||
found = 0;
|
||||
if (strlen(macaddr) > 5 ) {
|
||||
for (i=0; i < kcount; i++)
|
||||
{
|
||||
// Check if the nic is already in use
|
||||
if ( strcmp(knics[i].macaddr, macaddr) == NULL )
|
||||
{
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
strcpy( pnics[count].description , description );
|
||||
strcpy( pnics[count].macaddr , macaddr );
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
// If new nics are found...
|
||||
if (count > 0) {
|
||||
newtInit();
|
||||
newtCls();
|
||||
|
||||
char cMenuInhalt[STRING_SIZE];
|
||||
for (i=0 ; i < count ; i++)
|
||||
{
|
||||
if ( strlen(nics[i].description) < 52 )
|
||||
strncpy(MenuInhalt[i], nics[i].description + 1, strlen(nics[i].description)- 2);
|
||||
else
|
||||
{
|
||||
strncpy(cMenuInhalt, nics[i].description + 1, 50);
|
||||
strncpy(MenuInhalt[i], cMenuInhalt,(strrchr(cMenuInhalt,' ') - cMenuInhalt));
|
||||
strcat (MenuInhalt[i], "...");
|
||||
}
|
||||
while ( strlen(MenuInhalt[i]) < 50)
|
||||
// Fill with space.
|
||||
strcat( MenuInhalt[i], " ");
|
||||
|
||||
strcat(MenuInhalt[i], " (");
|
||||
strcat(MenuInhalt[i], nics[i].macaddr);
|
||||
strcat(MenuInhalt[i], ")");
|
||||
pMenuInhalt[i] = MenuInhalt[i];
|
||||
}
|
||||
|
||||
form = newtForm(NULL, NULL, 0);
|
||||
|
||||
sprintf(message, "Es wurde(n) %d Netzwerkkarte(n)\nin Ihrem System gefunden.\nBitte waehlen Sie eine aus:\n", count);
|
||||
|
||||
rc = newtWinMenu("NetcardMenu", message, 50, 5, 5, 6, pMenuInhalt, &choise, "OK", "Cancel", NULL);
|
||||
|
||||
newtFormDestroy(form);
|
||||
newtFinished();
|
||||
|
||||
if ( rc == 0 || rc == 1) {
|
||||
write_configs_netudev(pnics[choise].macaddr, "green");
|
||||
} else {
|
||||
printf("BREAK\n");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
printf("Es wurden keine ungenutzen Netzwerkschnittstellen gefunden.\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int write_configs_netudev(char *macaddr, char *colour) {
|
||||
|
||||
#define UDEV_NET_CONF "/etc/udev/rules.d/30-persistent-network.rules"
|
||||
|
||||
FILE *fp;
|
||||
char commandstring[STRING_SIZE];
|
||||
|
||||
if( (fp = fopen(KNOWN_NICS, "a")) == NULL )
|
||||
{
|
||||
fprintf(stderr,"Couldn't open "KNOWN_NICS);
|
||||
return 1;
|
||||
}
|
||||
fprintf(fp,"%s;\n", macaddr);
|
||||
fclose(fp);
|
||||
|
||||
// Make sure that there is no conflict
|
||||
snprintf(commandstring, STRING_SIZE, "/usr/bin/touch "UDEV_NET_CONF" >/dev/null 2>&1");
|
||||
system(commandstring);
|
||||
snprintf(commandstring, STRING_SIZE, "/bin/cat "UDEV_NET_CONF"| /bin/grep -v \"%s\" > "UDEV_NET_CONF" 2>/dev/null", macaddr);
|
||||
system(commandstring);
|
||||
snprintf(commandstring, STRING_SIZE, "/bin/cat "UDEV_NET_CONF"| /bin/grep -v \"%s\" > "UDEV_NET_CONF" 2>/dev/null", colour);
|
||||
system(commandstring);
|
||||
|
||||
if( (fp = fopen(UDEV_NET_CONF, "a")) == NULL )
|
||||
{
|
||||
fprintf(stderr,"Couldn't open" UDEV_NET_CONF);
|
||||
return 1;
|
||||
}
|
||||
fprintf(fp,"ACTION==\"add\", SUBSYSTEM==\"net\", SYSFS{address}==\"%s\", NAME=\"%s0\"\n", macaddr, colour);
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user