mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-09 18:45:54 +02:00
Neuer Installer eingefügt...
git-svn-id: http://svn.ipfire.org/svn/ipfire/1.4/source@37 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8
This commit is contained in:
@@ -1,36 +1,36 @@
|
||||
/* SmoothWall install program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* CDROM menu. Get "misc" driver name etc.
|
||||
*
|
||||
* $Id: cdrom.c,v 1.6.2.1 2004/04/14 22:05:39 gespinasse Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
|
||||
extern FILE *flog;
|
||||
extern char *mylog;
|
||||
|
||||
extern char **ctr;
|
||||
|
||||
/* Ejects the CDROM. returns 0 for failure, 1 for success. */
|
||||
int ejectcdrom(char *dev)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if ((fd = open(dev, O_RDONLY|O_NONBLOCK)) == -1)
|
||||
return 0;
|
||||
|
||||
if (ioctl(fd, CDROMEJECT) == -1)
|
||||
{
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/* SmoothWall install program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* CDROM menu. Get "misc" driver name etc.
|
||||
*
|
||||
* $Id: cdrom.c,v 1.6.2.1 2004/04/14 22:05:39 gespinasse Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
|
||||
extern FILE *flog;
|
||||
extern char *mylog;
|
||||
|
||||
extern char **ctr;
|
||||
|
||||
/* Ejects the CDROM. returns 0 for failure, 1 for success. */
|
||||
int ejectcdrom(char *dev)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if ((fd = open(dev, O_RDONLY|O_NONBLOCK)) == -1)
|
||||
return 0;
|
||||
|
||||
if (ioctl(fd, CDROMEJECT) == -1)
|
||||
{
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,125 +1,125 @@
|
||||
/* SmoothWall install program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Write the config and get password stuff.
|
||||
*
|
||||
* $Id: config.c,v 1.6.2.3 2005/12/07 20:42:48 franck78 Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
extern char **ctr; // text translation table
|
||||
|
||||
/* called to write out all config files using the keyvalue interface. */
|
||||
int write_disk_configs(struct devparams *dp)
|
||||
{
|
||||
char devnode[STRING_SIZE];
|
||||
char partition[STRING_SIZE];
|
||||
char *messages[5] = { NULL,
|
||||
ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK1],
|
||||
ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK2],
|
||||
ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK3],
|
||||
ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK4]
|
||||
};
|
||||
/* dev node links. */
|
||||
sprintf(devnode, "%s", dp->devnode_disk_run);
|
||||
if (symlink(devnode, "/harddisk/dev/harddisk"))
|
||||
{
|
||||
errorbox(ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int j;
|
||||
for (j=1; j<5; j++) {
|
||||
sprintf(devnode, "%s%d", dp->devnode_part_run,j);
|
||||
sprintf(partition,"/harddisk/dev/harddisk%d",j);
|
||||
if (symlink(devnode, partition))
|
||||
{
|
||||
errorbox( messages[j] );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add /dev/root symlink linking to the root filesystem to
|
||||
* keep updfstab happy */
|
||||
sprintf(devnode, "%s4", dp->devnode_part_run);
|
||||
if (symlink(devnode, "/harddisk/dev/root"))
|
||||
{
|
||||
errorbox(ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_ROOT]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int write_lang_configs( char *lang)
|
||||
{
|
||||
struct keyvalue *kv = initkeyvalues();
|
||||
|
||||
/* default stuff for main/settings. */
|
||||
replacekeyvalue(kv, "LANGUAGE", lang);
|
||||
replacekeyvalue(kv, "HOSTNAME", SNAME);
|
||||
writekeyvalues(kv, "/harddisk" CONFIG_ROOT "/main/settings");
|
||||
freekeyvalues(kv);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int write_ethernet_configs(struct keyvalue *ethernetkv)
|
||||
{
|
||||
/* Write out the network settings we got from a few mins ago. */
|
||||
writekeyvalues(ethernetkv, "/harddisk" CONFIG_ROOT "/ethernet/settings");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Taken from the cdrom one. */
|
||||
int getpassword(char *password, char *text)
|
||||
{
|
||||
char *values[] = { NULL, NULL, NULL }; /* pointers for the values. */
|
||||
struct newtWinEntry entries[] =
|
||||
{
|
||||
{ ctr[TR_PASSWORD_PROMPT], &values[0], 2 },
|
||||
{ ctr[TR_AGAIN_PROMPT], &values[1], 2 },
|
||||
{ NULL, NULL, 0 }
|
||||
};
|
||||
char title[STRING_SIZE];
|
||||
int rc;
|
||||
int done;
|
||||
|
||||
do
|
||||
{
|
||||
done = 1;
|
||||
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
|
||||
rc = newtWinEntries(title, text,
|
||||
50, 5, 5, 20, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
|
||||
|
||||
if (rc != 2)
|
||||
{
|
||||
if (strlen(values[0]) == 0 || strlen(values[1]) == 0)
|
||||
{
|
||||
errorbox(ctr[TR_PASSWORD_CANNOT_BE_BLANK]);
|
||||
done = 0;
|
||||
strcpy(values[0], "");
|
||||
strcpy(values[1], "");
|
||||
}
|
||||
else if (strcmp(values[0], values[1]) != 0)
|
||||
{
|
||||
errorbox(ctr[TR_PASSWORDS_DO_NOT_MATCH]);
|
||||
done = 0;
|
||||
strcpy(values[0], "");
|
||||
strcpy(values[1], "");
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!done);
|
||||
|
||||
strncpy(password, values[0], STRING_SIZE);
|
||||
|
||||
if (values[0]) free(values[0]);
|
||||
if (values[1]) free(values[1]);
|
||||
|
||||
return rc;
|
||||
}
|
||||
/* SmoothWall install program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Write the config and get password stuff.
|
||||
*
|
||||
* $Id: config.c,v 1.6.2.3 2005/12/07 20:42:48 franck78 Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
extern char **ctr; // text translation table
|
||||
|
||||
/* called to write out all config files using the keyvalue interface. */
|
||||
int write_disk_configs(struct devparams *dp)
|
||||
{
|
||||
char devnode[STRING_SIZE];
|
||||
char partition[STRING_SIZE];
|
||||
char *messages[5] = { NULL,
|
||||
ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK1],
|
||||
ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK2],
|
||||
ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK3],
|
||||
ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK4]
|
||||
};
|
||||
/* dev node links. */
|
||||
sprintf(devnode, "%s", dp->devnode_disk_run);
|
||||
if (symlink(devnode, "/harddisk/dev/harddisk"))
|
||||
{
|
||||
errorbox(ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_HARDDISK]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int j;
|
||||
for (j=1; j<5; j++) {
|
||||
sprintf(devnode, "%s%d", dp->devnode_part_run,j);
|
||||
sprintf(partition,"/harddisk/dev/harddisk%d",j);
|
||||
if (symlink(devnode, partition))
|
||||
{
|
||||
errorbox( messages[j] );
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Add /dev/root symlink linking to the root filesystem to
|
||||
* keep updfstab happy */
|
||||
sprintf(devnode, "%s4", dp->devnode_part_run);
|
||||
if (symlink(devnode, "/harddisk/dev/root"))
|
||||
{
|
||||
errorbox(ctr[TR_UNABLE_TO_MAKE_SYMLINK_DEV_ROOT]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int write_lang_configs( char *lang)
|
||||
{
|
||||
struct keyvalue *kv = initkeyvalues();
|
||||
|
||||
/* default stuff for main/settings. */
|
||||
replacekeyvalue(kv, "LANGUAGE", lang);
|
||||
replacekeyvalue(kv, "HOSTNAME", SNAME);
|
||||
writekeyvalues(kv, "/harddisk" CONFIG_ROOT "/main/settings");
|
||||
freekeyvalues(kv);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int write_ethernet_configs(struct keyvalue *ethernetkv)
|
||||
{
|
||||
/* Write out the network settings we got from a few mins ago. */
|
||||
writekeyvalues(ethernetkv, "/harddisk" CONFIG_ROOT "/ethernet/settings");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Taken from the cdrom one. */
|
||||
int getpassword(char *password, char *text)
|
||||
{
|
||||
char *values[] = { NULL, NULL, NULL }; /* pointers for the values. */
|
||||
struct newtWinEntry entries[] =
|
||||
{
|
||||
{ ctr[TR_PASSWORD_PROMPT], &values[0], 2 },
|
||||
{ ctr[TR_AGAIN_PROMPT], &values[1], 2 },
|
||||
{ NULL, NULL, 0 }
|
||||
};
|
||||
char title[STRING_SIZE];
|
||||
int rc;
|
||||
int done;
|
||||
|
||||
do
|
||||
{
|
||||
done = 1;
|
||||
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
|
||||
rc = newtWinEntries(title, text,
|
||||
50, 5, 5, 20, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
|
||||
|
||||
if (rc != 2)
|
||||
{
|
||||
if (strlen(values[0]) == 0 || strlen(values[1]) == 0)
|
||||
{
|
||||
errorbox(ctr[TR_PASSWORD_CANNOT_BE_BLANK]);
|
||||
done = 0;
|
||||
strcpy(values[0], "");
|
||||
strcpy(values[1], "");
|
||||
}
|
||||
else if (strcmp(values[0], values[1]) != 0)
|
||||
{
|
||||
errorbox(ctr[TR_PASSWORDS_DO_NOT_MATCH]);
|
||||
done = 0;
|
||||
strcpy(values[0], "");
|
||||
strcpy(values[1], "");
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!done);
|
||||
|
||||
strncpy(password, values[0], STRING_SIZE);
|
||||
|
||||
if (values[0]) free(values[0]);
|
||||
if (values[1]) free(values[1]);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1,61 +1,61 @@
|
||||
/* SmoothWall install program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Contains some functs for scanning /proc for ide info on CDROMS and
|
||||
* harddisks.
|
||||
*
|
||||
* $Id: ide.c,v 1.4 2003/12/11 11:25:53 riddles Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
|
||||
/* checkide(). Scans the named drive letter and returns the IDE_??? type. */
|
||||
int checkide(char letter)
|
||||
{
|
||||
FILE *f = NULL;
|
||||
char filename[STRING_SIZE];
|
||||
char buffer[STRING_SIZE];
|
||||
|
||||
sprintf(filename, "/proc/ide/hd%c/media", letter);
|
||||
|
||||
if (!(f = fopen(filename, "r")))
|
||||
return IDE_EMPTY;
|
||||
|
||||
if (!(fgets(buffer, STRING_SIZE, f)))
|
||||
{
|
||||
printf("Couldn't read from %s\n", filename);
|
||||
fclose(f);
|
||||
return IDE_EMPTY;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
stripnl(buffer);
|
||||
|
||||
if (strcmp(buffer, "cdrom") == 0)
|
||||
return IDE_CDROM;
|
||||
else if (strcmp(buffer, "disk") == 0)
|
||||
return IDE_HD;
|
||||
else
|
||||
return IDE_UNKNOWN;
|
||||
}
|
||||
|
||||
/* findidetype(). Finds the first ide deveice of the given IDE_?? type. */
|
||||
char findidetype(int type)
|
||||
{
|
||||
char letter;
|
||||
|
||||
for (letter = 'a'; letter <= 'z'; letter++)
|
||||
{
|
||||
if ((checkide(letter)) == type)
|
||||
{
|
||||
return letter;
|
||||
}
|
||||
}
|
||||
return '\0';
|
||||
}
|
||||
|
||||
/* SmoothWall install program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Contains some functs for scanning /proc for ide info on CDROMS and
|
||||
* harddisks.
|
||||
*
|
||||
* $Id: ide.c,v 1.4 2003/12/11 11:25:53 riddles Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
|
||||
/* checkide(). Scans the named drive letter and returns the IDE_??? type. */
|
||||
int checkide(char letter)
|
||||
{
|
||||
FILE *f = NULL;
|
||||
char filename[STRING_SIZE];
|
||||
char buffer[STRING_SIZE];
|
||||
|
||||
sprintf(filename, "/proc/ide/hd%c/media", letter);
|
||||
|
||||
if (!(f = fopen(filename, "r")))
|
||||
return IDE_EMPTY;
|
||||
|
||||
if (!(fgets(buffer, STRING_SIZE, f)))
|
||||
{
|
||||
printf("Couldn't read from %s\n", filename);
|
||||
fclose(f);
|
||||
return IDE_EMPTY;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
stripnl(buffer);
|
||||
|
||||
if (strcmp(buffer, "cdrom") == 0)
|
||||
return IDE_CDROM;
|
||||
else if (strcmp(buffer, "disk") == 0)
|
||||
return IDE_HD;
|
||||
else
|
||||
return IDE_UNKNOWN;
|
||||
}
|
||||
|
||||
/* findidetype(). Finds the first ide deveice of the given IDE_?? type. */
|
||||
char findidetype(int type)
|
||||
{
|
||||
char letter;
|
||||
|
||||
for (letter = 'a'; letter <= 'z'; letter++)
|
||||
{
|
||||
if ((checkide(letter)) == type)
|
||||
{
|
||||
return letter;
|
||||
}
|
||||
}
|
||||
return '\0';
|
||||
}
|
||||
|
||||
|
||||
@@ -1,92 +1,92 @@
|
||||
/* SmoothWall install program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Main include file.
|
||||
*
|
||||
* $Id: install.h,v 1.10.2.4 2006/01/11 01:01:38 franck78 Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../libsmooth/libsmooth.h"
|
||||
|
||||
#define IDE_EMPTY 0
|
||||
#define IDE_CDROM 1
|
||||
#define IDE_HD 2
|
||||
#define IDE_UNKNOWN 3
|
||||
|
||||
/* CDROMS and harddisks. */
|
||||
struct devparams
|
||||
{
|
||||
char devnode_disk[30]; // when single partition is addressed
|
||||
char devnode_part[30]; // when the RAID partition is addressed
|
||||
char devnode_disk_run[30]; // the same dev but after installation
|
||||
char devnode_part_run[30];
|
||||
char modulename[STRING_SIZE];
|
||||
char options[STRING_SIZE];
|
||||
// int module;
|
||||
};
|
||||
|
||||
/* ide.c */
|
||||
int checkide(char letter);
|
||||
char findidetype(int type);
|
||||
|
||||
/* cdrom.c */
|
||||
int ejectcdrom(char *dev);
|
||||
|
||||
/* nic.c */
|
||||
int networkmenu(struct keyvalue *ethernetkv);
|
||||
|
||||
/* net.c */
|
||||
int checktarball(char *);
|
||||
|
||||
/* config.c */
|
||||
int write_disk_configs(struct devparams *dp);
|
||||
int write_lang_configs( char *lang);
|
||||
int write_ethernet_configs(struct keyvalue *ethernetkv);
|
||||
|
||||
/* pcmcia.c */
|
||||
char * initialize_pcmcia (void);
|
||||
|
||||
/* upgrade_v12_v13.c */
|
||||
int upgrade_v12_v13();
|
||||
|
||||
/* upgrade_v130_v131.c */
|
||||
int upgrade_v130_v140();
|
||||
|
||||
/* usb.c */
|
||||
int initialize_usb();
|
||||
int write_usb_modules_conf();
|
||||
int checkusb (char *partition);
|
||||
|
||||
/* scsi.c */
|
||||
int try_scsi(char *dev);
|
||||
int get_boot(char *dev);
|
||||
|
||||
/*main.c */
|
||||
int modprobe (char *mod);
|
||||
int rmmod (char *mod);
|
||||
|
||||
extern char *bz_tr[];
|
||||
extern char *cs_tr[];
|
||||
extern char *da_tr[];
|
||||
extern char *en_tr[];
|
||||
extern char *es_tr[];
|
||||
extern char *fi_tr[];
|
||||
extern char *fr_tr[];
|
||||
extern char *hu_tr[];
|
||||
extern char *la_tr[];
|
||||
extern char *nl_tr[];
|
||||
extern char *de_tr[];
|
||||
extern char *tr_tr[];
|
||||
extern char *it_tr[];
|
||||
extern char *el_tr[];
|
||||
extern char *pl_tr[];
|
||||
extern char *pt_tr[];
|
||||
extern char *sk_tr[];
|
||||
extern char *so_tr[];
|
||||
extern char *sv_tr[];
|
||||
extern char *no_tr[];
|
||||
extern char *vi_tr[];
|
||||
/* SmoothWall install program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Main include file.
|
||||
*
|
||||
* $Id: install.h,v 1.10.2.4 2006/01/11 01:01:38 franck78 Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../libsmooth/libsmooth.h"
|
||||
|
||||
#define IDE_EMPTY 0
|
||||
#define IDE_CDROM 1
|
||||
#define IDE_HD 2
|
||||
#define IDE_UNKNOWN 3
|
||||
|
||||
/* CDROMS and harddisks. */
|
||||
struct devparams
|
||||
{
|
||||
char devnode_disk[30]; // when single partition is addressed
|
||||
char devnode_part[30]; // when the RAID partition is addressed
|
||||
char devnode_disk_run[30]; // the same dev but after installation
|
||||
char devnode_part_run[30];
|
||||
char modulename[STRING_SIZE];
|
||||
char options[STRING_SIZE];
|
||||
// int module;
|
||||
};
|
||||
|
||||
/* ide.c */
|
||||
int checkide(char letter);
|
||||
char findidetype(int type);
|
||||
|
||||
/* cdrom.c */
|
||||
int ejectcdrom(char *dev);
|
||||
|
||||
/* nic.c */
|
||||
int networkmenu(struct keyvalue *ethernetkv);
|
||||
|
||||
/* net.c */
|
||||
int checktarball(char *);
|
||||
|
||||
/* config.c */
|
||||
int write_disk_configs(struct devparams *dp);
|
||||
int write_lang_configs( char *lang);
|
||||
int write_ethernet_configs(struct keyvalue *ethernetkv);
|
||||
|
||||
/* pcmcia.c */
|
||||
char * initialize_pcmcia (void);
|
||||
|
||||
/* upgrade_v12_v13.c */
|
||||
int upgrade_v12_v13();
|
||||
|
||||
/* upgrade_v130_v131.c */
|
||||
int upgrade_v130_v140();
|
||||
|
||||
/* usb.c */
|
||||
int initialize_usb();
|
||||
int write_usb_modules_conf();
|
||||
int checkusb (char *partition);
|
||||
|
||||
/* scsi.c */
|
||||
int try_scsi(char *dev);
|
||||
int get_boot(char *dev);
|
||||
|
||||
/*main.c */
|
||||
int modprobe (char *mod);
|
||||
int rmmod (char *mod);
|
||||
|
||||
extern char *bz_tr[];
|
||||
extern char *cs_tr[];
|
||||
extern char *da_tr[];
|
||||
extern char *en_tr[];
|
||||
extern char *es_tr[];
|
||||
extern char *fi_tr[];
|
||||
extern char *fr_tr[];
|
||||
extern char *hu_tr[];
|
||||
extern char *la_tr[];
|
||||
extern char *nl_tr[];
|
||||
extern char *de_tr[];
|
||||
extern char *tr_tr[];
|
||||
extern char *it_tr[];
|
||||
extern char *el_tr[];
|
||||
extern char *pl_tr[];
|
||||
extern char *pt_tr[];
|
||||
extern char *sk_tr[];
|
||||
extern char *so_tr[];
|
||||
extern char *sv_tr[];
|
||||
extern char *no_tr[];
|
||||
extern char *vi_tr[];
|
||||
|
||||
@@ -1,424 +1,413 @@
|
||||
/* IPCop install2 program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* (c) Franck Bourdonnec, 2006
|
||||
* Contains update/restore code
|
||||
*
|
||||
* $Id: install2.c,v 1.1.2.3 2006/01/31 00:51:50 franck78 Exp $
|
||||
*
|
||||
*/
|
||||
#include "install.h"
|
||||
|
||||
FILE *flog = NULL;
|
||||
char *mylog;
|
||||
char **ctr;
|
||||
|
||||
/*
|
||||
To include a translated string in the final installer, you must reference
|
||||
it here with a simplr comment. This save a lot a space in the installer
|
||||
*/
|
||||
|
||||
/* TR_BUILDING_INITRD */
|
||||
/* TR_HELPLINE */
|
||||
/* TR_SKIP */
|
||||
/* TR_RESTORE_CONFIGURATION */
|
||||
/* TR_RESTORE */
|
||||
/* TR_OK */
|
||||
/* TR_CANCEL */
|
||||
/* TR_ERROR */
|
||||
/* TR_INSTALLING_FILES */
|
||||
/* TR_FAILED_TO_FIND */
|
||||
/* TR_UNABLE_TO_INSTALL_FILES */
|
||||
/* TR_LOADING_PCMCIA */
|
||||
|
||||
//libsmooth
|
||||
/* TR_INTERFACE */
|
||||
/* TR_ENTER_THE_IP_ADDRESS_INFORMATION */
|
||||
/* TR_STATIC */
|
||||
/* TR_DHCP_HOSTNAME */
|
||||
/* TR_IP_ADDRESS_PROMPT */
|
||||
/* TR_NETMASK_PROMPT */
|
||||
/* TR_INVALID_FIELDS */
|
||||
/* TR_IP_ADDRESS_CR */
|
||||
/* TR_NETWORK_MASK_CR */
|
||||
/* TR_DHCP_HOSTNAME_CR */
|
||||
/* TR_LOOKING_FOR_NIC */
|
||||
/* TR_MANUAL */
|
||||
/* TR_SELECT_NETWORK_DRIVER */
|
||||
/* TR_SELECT_NETWORK_DRIVER_LONG */
|
||||
/* TR_UNABLE_TO_LOAD_DRIVER_MODULE */
|
||||
/* TR_THIS_DRIVER_MODULE_IS_ALREADY_LOADED */
|
||||
/* TR_MODULE_PARAMETERS */
|
||||
/* TR_LOADING_MODULE */
|
||||
/* TR_MODULE_NAME_CANNOT_BE_BLANK */
|
||||
|
||||
//upgrade 120
|
||||
/* TR_UNABLE_TO_OPEN_SETTINGS_FILE */
|
||||
/* TR_DOMAINNAME */
|
||||
/* TR_ENTER_DOMAINNAME */
|
||||
/* TR_DOMAINNAME_CANNOT_CONTAIN_SPACES */
|
||||
/* TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM */
|
||||
/* TR_UNABLE_TO_WRITE_ETC_FSTAB */
|
||||
|
||||
// dir to find files, chrooted or not...
|
||||
#define TMP_EXTRACT_CH "/tmp/ipcop"
|
||||
#define TMP_EXTRACT "/harddisk" TMP_EXTRACT_CH
|
||||
#define MOUNT_BACKUP_CH "/mnt/usb"
|
||||
#define MOUNT_BACKUP "/harddisk" MOUNT_BACKUP_CH
|
||||
/*
|
||||
return 0 when dev contains a backup set
|
||||
leave dev mounted
|
||||
*/
|
||||
int try_mount (char *dev, char *testfile) {
|
||||
char commandstring[STRING_SIZE];
|
||||
mysystem("/bin/umount " MOUNT_BACKUP);
|
||||
sprintf(commandstring, "/bin/mount -t vfat -o ro %s " MOUNT_BACKUP, dev);
|
||||
mysystem(commandstring);
|
||||
|
||||
/*verify it's what we want */
|
||||
sprintf(commandstring, MOUNT_BACKUP "/%s.dat", testfile);
|
||||
FILE *handle = fopen(commandstring, "r");
|
||||
if (handle == NULL) {
|
||||
return 1; /* bad disk ! */
|
||||
}
|
||||
fclose(handle);
|
||||
|
||||
handle = fopen(MOUNT_BACKUP "/backup.key", "r");
|
||||
if (handle == NULL) {
|
||||
return 1; /* bad disk ! */
|
||||
}
|
||||
fclose(handle);
|
||||
return 0; //success
|
||||
}
|
||||
|
||||
/* try to mount usb device until backup.tgz is found except the
|
||||
destination device (scsi names are identical with usb key)
|
||||
check "sda sdb sdc sdd"
|
||||
*/
|
||||
int mountbackup (char *testfile, char *destination_device) {
|
||||
char sourcedev[30];
|
||||
char i,j;
|
||||
for (i = 'a'; i < 'e'; i++) {
|
||||
sprintf (sourcedev,"/dev/sd%c ",i);
|
||||
if (strcmp (destination_device, sourcedev) != 0) {
|
||||
if (!try_mount (sourcedev, testfile)) return 0;
|
||||
}
|
||||
for (j = '1'; j < '5'; j++) {
|
||||
sourcedev[8] = j;
|
||||
if (strcmp (destination_device, sourcedev) != 0) {
|
||||
if (!try_mount (sourcedev, testfile)) return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int floppy_locate() {
|
||||
/* Temporarily mount /proc under /harddisk/proc,
|
||||
run updfstab to locate the floppy, and unmount /harddisk/proc
|
||||
again. This should be run each time the user tries to restore
|
||||
so it can properly detect removable devices */
|
||||
if (mysystem("/bin/mount -n -t proc /proc /harddisk/proc")) {
|
||||
errorbox(ctr[TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM]);
|
||||
return 1;
|
||||
}
|
||||
if (mysystem("/bin/chroot /harddisk /usr/sbin/updfstab")) {
|
||||
errorbox(ctr[TR_UNABLE_TO_WRITE_ETC_FSTAB]);
|
||||
return 1;
|
||||
}
|
||||
mysystem("/bin/umount /harddisk/proc");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Check the SQUID acl file exists, if not use our 1.4 copy */
|
||||
void fixup_squidacl() {
|
||||
FILE *aclreadfile;
|
||||
if ((aclreadfile = fopen ("/harddisk" CONFIG_ROOT "/proxy/acl", "r"))) {
|
||||
unlink ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4");
|
||||
fclose(aclreadfile);
|
||||
} else {
|
||||
rename ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4",
|
||||
"/harddisk" CONFIG_ROOT "/proxy/acl");
|
||||
}
|
||||
chown ("/harddisk" CONFIG_ROOT "/proxy/acl", 99, 99);
|
||||
}
|
||||
/* if we detected SCSI then fixup */
|
||||
void fixup_initrd() {
|
||||
FILE *handle;
|
||||
char line[STRING_SIZE];
|
||||
char commandstring[STRING_SIZE];
|
||||
|
||||
if (!(handle = fopen("/scsidriver", "r")))
|
||||
return;
|
||||
|
||||
char *driver;
|
||||
fgets(line, STRING_SIZE-1, handle);
|
||||
fclose(handle);
|
||||
line[strlen(line) - 1] = 0;
|
||||
driver = strtok(line, ".");
|
||||
fprintf(flog, "Detected SCSI driver %s\n", driver);
|
||||
if (!strlen(driver) > 1)
|
||||
return;
|
||||
|
||||
fprintf(flog, "Fixing up ipcoprd.img\n");
|
||||
mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
|
||||
mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO);
|
||||
sprintf(commandstring, "/bin/chroot /harddisk /sbin/mkinitrd"
|
||||
" --with=scsi_mod --with=%s --with=sd_mod"
|
||||
" --with=sr_mod --with=libata"
|
||||
" --with=ataraid /boot/ipcoprd.img "KERNEL_VERSION,
|
||||
driver );
|
||||
runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
|
||||
#ifdef __i386__
|
||||
sprintf(commandstring, "/bin/chroot /harddisk /sbin/mkinitrd"
|
||||
" --with=scsi_mod --with=%s --with=sd_mod"
|
||||
" --with=sr_mod --with=libata"
|
||||
" --with=ataraid /boot/ipcoprd-smp.img "KERNEL_VERSION"-smp",
|
||||
driver );
|
||||
runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
|
||||
mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
|
||||
#endif
|
||||
#ifdef __alpha__
|
||||
runcommandwithstatus("/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf", ctr[TR_BUILDING_INITRD]);
|
||||
#endif
|
||||
}
|
||||
/* when backup is ready in tmpdir, move files to definitive location */
|
||||
void do_copy_files(int upgrade_level) {
|
||||
mysystem("/bin/chroot /harddisk /bin/cp -af "TMP_EXTRACT_CH"/. /");
|
||||
/* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
|
||||
switch (upgrade_level) {
|
||||
case 1:
|
||||
upgrade_v12_v13();
|
||||
upgrade_v130_v140();
|
||||
case 2: //some 1.4 files format changed
|
||||
//between 1.4.0 & 1.4.11 If possible de determine backup/version
|
||||
//the update code should go here
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
#define LANG argv[1]
|
||||
#define DEST_DEV argv[2]
|
||||
#define WGET argv[3]
|
||||
|
||||
#ifdef LANG_EN_ONLY
|
||||
char **langtrs[] = { en_tr, NULL };
|
||||
#else
|
||||
char **langtrs[] = { bz_tr, cs_tr, da_tr, de_tr, en_tr, es_tr, fr_tr, el_tr, it_tr, la_tr, hu_tr, nl_tr, no_tr, pl_tr, pt_tr, sk_tr, so_tr, fi_tr, sv_tr, tr_tr, vi_tr, NULL };
|
||||
#endif
|
||||
char message[1000];
|
||||
char title[STRING_SIZE];
|
||||
char commandstring[STRING_SIZE];
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
/* Log file/terminal stuff. */
|
||||
mylog = "/dev/tty2";
|
||||
ctr = langtrs[ atoi(LANG) ];
|
||||
|
||||
if (!(flog = fopen(mylog, "w+")))
|
||||
{
|
||||
printf("Couldn't open log terminal\n");
|
||||
return 0;
|
||||
}
|
||||
fprintf(flog, "Install2 program started.\n");
|
||||
newtInit();
|
||||
newtCls();
|
||||
strcpy (title, NAME " v" VERSION " - " SLOGAN);
|
||||
newtDrawRootText(14, 0, title);
|
||||
newtPushHelpLine(ctr[TR_HELPLINE]);
|
||||
/*
|
||||
// build now the device node
|
||||
runcommandwithstatus("echo 'cd /dev; ./make_devices'>/harddisk/X;"
|
||||
"chroot /harddisk chmod +x /X;"
|
||||
"chroot /harddisk /X;"
|
||||
"chroot /harddisk rm /X"
|
||||
, ctr[TR_INSTALLING_FILES]);
|
||||
*/
|
||||
/* working dirs... */
|
||||
mkdir(MOUNT_BACKUP, S_IRWXU|S_IRWXG|S_IRWXO);
|
||||
|
||||
//create the GUI screen and objects
|
||||
newtComponent form, header, labelfile, labelkey, file, key, radio0, radio1, radio2, radio3, radio4, ok;
|
||||
|
||||
newtCenteredWindow (55,20,ctr[TR_RESTORE]);
|
||||
form = newtForm (NULL, NULL,0);
|
||||
|
||||
sprintf(message, ctr[TR_RESTORE_CONFIGURATION], NAME);
|
||||
header = newtTextboxReflowed (2,1,message,51,0,0,0);
|
||||
newtFormAddComponent(form, header);
|
||||
|
||||
// The four method of restauration
|
||||
int start1=1, start2=0, start3=0, start4=0;
|
||||
radio1 = newtRadiobutton (17, 5, ctr[TR_SKIP], start1, NULL);
|
||||
radio2 = newtRadiobutton (17, 6, "Floppy (legacy)", start2, radio1);
|
||||
radio3 = newtRadiobutton (17, 7, "Usb-storage/CDROM", start3, radio2);
|
||||
if (strcmp(WGET,"none"))
|
||||
radio4 = newtRadiobutton (17, 8, "HTTP/FTP", start4, radio3);
|
||||
else
|
||||
radio4 = NULL;
|
||||
newtFormAddComponents(form, radio1, radio2, radio3, radio4, NULL);
|
||||
|
||||
// The optionnal filename for 'backup'
|
||||
labelfile=newtTextbox(12, 10, 35, 1, 0);
|
||||
newtTextboxSetText (labelfile, "Filename");
|
||||
newtFormAddComponent(form, labelfile);
|
||||
char *filevalue;
|
||||
char fileinit[STRING_SIZE] = "backup";
|
||||
file = newtEntry (17, 11, fileinit, 20, &filevalue, 0);
|
||||
newtFormAddComponent(form, file);
|
||||
|
||||
// The optionnal password for the key
|
||||
labelkey=newtTextbox(12, 13, 35, 1, 0);
|
||||
newtTextboxSetText (labelkey, "Backup key password");
|
||||
newtFormAddComponent(form, labelkey);
|
||||
char *keyvalue;
|
||||
char keyinit[STRING_SIZE] = "";
|
||||
key = newtEntry (17, 14, keyinit, 20, &keyvalue, 0);
|
||||
newtFormAddComponent(form, key);
|
||||
|
||||
// The OK button
|
||||
ok=newtButton (23, 16, ctr[TR_OK]);
|
||||
newtFormAddComponent(form, ok);
|
||||
|
||||
/* loop until succeeds or user skips out */
|
||||
int retcode = -1;
|
||||
while ( retcode<0 ) {
|
||||
|
||||
// run the windows
|
||||
struct newtExitStruct reponse;
|
||||
newtFormRun (form, &reponse);
|
||||
radio0 = newtRadioGetCurrent(radio1);
|
||||
int radio;
|
||||
radio = radio0 == radio1 ? 1 : radio0 == radio2 ? 2 : radio0 == radio3 ? 3 : radio0 == radio4 ? 4 : 0;
|
||||
strcpy(keyinit,keyvalue); //reuse actual value
|
||||
strcpy(fileinit,filevalue);
|
||||
|
||||
if (radio==1) {
|
||||
retcode = 1; // no restore: nothing special
|
||||
break; // out of the while loop
|
||||
}
|
||||
|
||||
mkdir(TMP_EXTRACT, S_IRWXU|S_IRWXG|S_IRWXO);
|
||||
statuswindow(45, 4, title, ctr[TR_INSTALLING_FILES]);
|
||||
switch (radio) {
|
||||
case 4: // network
|
||||
sprintf(commandstring,"/bin/wget -P " TMP_EXTRACT " %s/%s.dat", WGET, filevalue);
|
||||
mysystem (commandstring);
|
||||
sprintf(commandstring,"/bin/wget -P " TMP_EXTRACT " %s/%s.key", WGET, filevalue);
|
||||
if (mysystem (commandstring)) {
|
||||
errorbox(ctr[TR_FAILED_TO_FIND]);
|
||||
break;
|
||||
};
|
||||
goto COMMON;
|
||||
case 3: // normal backup
|
||||
if (mountbackup( filevalue, DEST_DEV )) {
|
||||
errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);//mess=no device with backup found
|
||||
break;
|
||||
};
|
||||
// link files to a COMMON location
|
||||
sprintf (commandstring, "chroot /harddisk ln -s "MOUNT_BACKUP_CH"/%s.dat " TMP_EXTRACT_CH "/%s.dat", filevalue, filevalue);
|
||||
mysystem (commandstring);
|
||||
sprintf (commandstring, "chroot /harddisk ln -s "MOUNT_BACKUP_CH"/%s.key " TMP_EXTRACT_CH "/%s.key", filevalue, filevalue);
|
||||
mysystem (commandstring);
|
||||
|
||||
COMMON: // DECRYPT THE TARBALL
|
||||
// Copy the key to a new location because we decrypt it!
|
||||
if (strcmp(keyvalue, "")) { // password provided: decrypt the key
|
||||
sprintf(commandstring, "/bin/chroot /harddisk /usr/bin/openssl enc"
|
||||
" -a -d -aes256 -salt"
|
||||
" -pass pass:%s"
|
||||
" -in " TMP_EXTRACT_CH "/%s.key"
|
||||
" -out " TMP_EXTRACT_CH "/__tmp.key",
|
||||
keyvalue, filevalue);
|
||||
} else { //just copy to new name
|
||||
sprintf(commandstring, "/bin/chroot /harddisk cp"
|
||||
" " TMP_EXTRACT_CH "/%s.key"
|
||||
" " TMP_EXTRACT_CH "/__tmp.key",
|
||||
filevalue);
|
||||
}
|
||||
mysystem (commandstring);
|
||||
|
||||
sprintf(commandstring, "/bin/chroot /harddisk /usr/bin/openssl des3"
|
||||
" -d -salt"
|
||||
" -in " TMP_EXTRACT_CH "/%s.dat"
|
||||
" -out " TMP_EXTRACT_CH "/backup.tgz"
|
||||
" -kfile " TMP_EXTRACT_CH "/__tmp.key",
|
||||
filevalue);
|
||||
|
||||
if (mysystem (commandstring)) {
|
||||
errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);//mess=decrypt error:invalid key?
|
||||
break;
|
||||
}
|
||||
strcpy(commandstring, "/bin/chroot /harddisk /bin/tar"
|
||||
" -X " CONFIG_ROOT "/backup/exclude.system"
|
||||
" -C " TMP_EXTRACT_CH
|
||||
" -xzf " TMP_EXTRACT_CH "/backup.tgz");
|
||||
|
||||
if (mysystem(commandstring)) {
|
||||
errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
|
||||
break;
|
||||
}
|
||||
sprintf(commandstring, TMP_EXTRACT "/%s.dat", filevalue);
|
||||
unlink(commandstring ); //dont need them anymore
|
||||
unlink( TMP_EXTRACT "/backup.tgz");
|
||||
sprintf(commandstring, TMP_EXTRACT "/%s.key", filevalue);
|
||||
unlink(commandstring );
|
||||
unlink( TMP_EXTRACT "/__tmp.key");
|
||||
|
||||
/* Now copy to correct location */
|
||||
do_copy_files(0);
|
||||
retcode = 0; /* successfully restored */
|
||||
break;
|
||||
case 2:
|
||||
// diskette change
|
||||
if (floppy_locate()) {
|
||||
retcode = 2; // this an error!
|
||||
break;
|
||||
}
|
||||
|
||||
/* Always extract to /tmp/ipcop for temporary extraction
|
||||
just in case floppy fails.
|
||||
try a compressed backup first because it's quicker to fail.
|
||||
In exclude.system, files name must be without leading / or
|
||||
on extraction, name will never match
|
||||
*/
|
||||
sprintf(commandstring,
|
||||
"/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C "TMP_EXTRACT_CH" -xvzf /dev/floppy > %s 2> /dev/null", mylog);
|
||||
if (system(commandstring)) {
|
||||
/* if it's not compressed, try uncompressed first before failing*/
|
||||
sprintf(commandstring,
|
||||
"/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C "TMP_EXTRACT_CH" -xvf /dev/floppy > %s 2> /dev/null", mylog);
|
||||
if (system(commandstring)) {
|
||||
/* command failed trying to read from floppy */
|
||||
errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Now copy to correct location */
|
||||
do_copy_files(1);
|
||||
retcode = 0; /* successfully restored */
|
||||
}//switch
|
||||
/* remove possible badly restored files */
|
||||
mysystem("/bin/chroot /harddisk /bin/rm -rf " TMP_EXTRACT_CH );
|
||||
newtPopWindow(); // close windows
|
||||
}//while
|
||||
newtFormDestroy(form);
|
||||
|
||||
/* cleanup */
|
||||
mysystem("/bin/umount " MOUNT_BACKUP);
|
||||
mysystem("/bin/chroot /harddisk /bin/rmdir " MOUNT_BACKUP_CH);
|
||||
|
||||
/* others operations moved from install to install2 */
|
||||
fixup_squidacl();
|
||||
fixup_initrd();
|
||||
|
||||
fprintf(flog, "Install2 program ended.\n");
|
||||
fflush(flog);
|
||||
fclose(flog);
|
||||
newtFinished();
|
||||
return retcode;
|
||||
}
|
||||
|
||||
/* IPCop install2 program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* (c) Franck Bourdonnec, 2006
|
||||
* Contains update/restore code
|
||||
*
|
||||
* $Id: install2.c,v 1.1.2.5 2006/02/10 06:53:57 gespinasse Exp $
|
||||
*
|
||||
*/
|
||||
#include "install.h"
|
||||
|
||||
FILE *flog = NULL;
|
||||
char *mylog;
|
||||
char **ctr;
|
||||
|
||||
/*
|
||||
To include a translated string in the final installer, you must reference
|
||||
it here with a simplr comment. This save a lot a space in the installer
|
||||
*/
|
||||
|
||||
/* TR_BUILDING_INITRD */
|
||||
/* TR_HELPLINE */
|
||||
/* TR_SKIP */
|
||||
/* TR_RESTORE_CONFIGURATION */
|
||||
/* TR_RESTORE */
|
||||
/* TR_OK */
|
||||
/* TR_CANCEL */
|
||||
/* TR_ERROR */
|
||||
/* TR_INSTALLING_FILES */
|
||||
/* TR_FAILED_TO_FIND */
|
||||
/* TR_UNABLE_TO_INSTALL_FILES */
|
||||
/* TR_LOADING_PCMCIA */
|
||||
|
||||
//libsmooth
|
||||
/* TR_INTERFACE */
|
||||
/* TR_ENTER_THE_IP_ADDRESS_INFORMATION */
|
||||
/* TR_STATIC */
|
||||
/* TR_DHCP_HOSTNAME */
|
||||
/* TR_IP_ADDRESS_PROMPT */
|
||||
/* TR_NETMASK_PROMPT */
|
||||
/* TR_INVALID_FIELDS */
|
||||
/* TR_IP_ADDRESS_CR */
|
||||
/* TR_NETWORK_MASK_CR */
|
||||
/* TR_DHCP_HOSTNAME_CR */
|
||||
/* TR_LOOKING_FOR_NIC */
|
||||
/* TR_MANUAL */
|
||||
/* TR_SELECT_NETWORK_DRIVER */
|
||||
/* TR_SELECT_NETWORK_DRIVER_LONG */
|
||||
/* TR_UNABLE_TO_LOAD_DRIVER_MODULE */
|
||||
/* TR_THIS_DRIVER_MODULE_IS_ALREADY_LOADED */
|
||||
/* TR_MODULE_PARAMETERS */
|
||||
/* TR_LOADING_MODULE */
|
||||
/* TR_MODULE_NAME_CANNOT_BE_BLANK */
|
||||
|
||||
//upgrade 120
|
||||
/* TR_UNABLE_TO_OPEN_SETTINGS_FILE */
|
||||
/* TR_DOMAINNAME */
|
||||
/* TR_ENTER_DOMAINNAME */
|
||||
/* TR_DOMAINNAME_CANNOT_CONTAIN_SPACES */
|
||||
/* TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM */
|
||||
/* TR_UNABLE_TO_WRITE_ETC_FSTAB */
|
||||
|
||||
// dir to find files, chrooted or not...
|
||||
#define TMP_EXTRACT_CH "/tmp/ipcop"
|
||||
#define TMP_EXTRACT "/harddisk" TMP_EXTRACT_CH
|
||||
#define MOUNT_BACKUP_CH "/mnt/usb"
|
||||
#define MOUNT_BACKUP "/harddisk" MOUNT_BACKUP_CH
|
||||
/*
|
||||
return 0 when dev contains a backup set
|
||||
leave dev mounted
|
||||
*/
|
||||
int try_mount (char *dev, char *testfile) {
|
||||
char commandstring[STRING_SIZE];
|
||||
mysystem("/bin/umount " MOUNT_BACKUP);
|
||||
sprintf(commandstring, "/bin/mount -t vfat -o ro %s " MOUNT_BACKUP, dev);
|
||||
mysystem(commandstring);
|
||||
|
||||
/*verify it's what we want */
|
||||
sprintf(commandstring, MOUNT_BACKUP "/%s.dat", testfile);
|
||||
FILE *handle = fopen(commandstring, "r");
|
||||
if (handle == NULL) {
|
||||
return 1; /* bad disk ! */
|
||||
}
|
||||
fclose(handle);
|
||||
|
||||
handle = fopen(MOUNT_BACKUP "/backup.key", "r");
|
||||
if (handle == NULL) {
|
||||
return 1; /* bad disk ! */
|
||||
}
|
||||
fclose(handle);
|
||||
return 0; //success
|
||||
}
|
||||
|
||||
/* try to mount usb device until backup.tgz is found except the
|
||||
destination device (scsi names are identical with usb key)
|
||||
check "sda sdb sdc sdd"
|
||||
*/
|
||||
int mountbackup (char *testfile, char *destination_device) {
|
||||
char sourcedev[30];
|
||||
char i,j;
|
||||
for (i = 'a'; i < 'e'; i++) {
|
||||
sprintf (sourcedev,"/dev/sd%c ",i);
|
||||
if (strcmp (destination_device, sourcedev) != 0) {
|
||||
if (!try_mount (sourcedev, testfile)) return 0;
|
||||
}
|
||||
for (j = '1'; j < '5'; j++) {
|
||||
sourcedev[8] = j;
|
||||
if (strcmp (destination_device, sourcedev) != 0) {
|
||||
if (!try_mount (sourcedev, testfile)) return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int floppy_locate() {
|
||||
/* Temporarily mount /proc under /harddisk/proc,
|
||||
run updfstab to locate the floppy, and unmount /harddisk/proc
|
||||
again. This should be run each time the user tries to restore
|
||||
so it can properly detect removable devices */
|
||||
if (mysystem("/bin/mount -n -t proc /proc /harddisk/proc")) {
|
||||
errorbox(ctr[TR_UNABLE_TO_MOUNT_PROC_FILESYSTEM]);
|
||||
return 1;
|
||||
}
|
||||
if (mysystem("/bin/chroot /harddisk /usr/sbin/updfstab")) {
|
||||
errorbox(ctr[TR_UNABLE_TO_WRITE_ETC_FSTAB]);
|
||||
return 1;
|
||||
}
|
||||
mysystem("/bin/umount /harddisk/proc");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Check the SQUID acl file exists, if not use our 1.4 copy */
|
||||
void fixup_squidacl() {
|
||||
FILE *aclreadfile;
|
||||
if ((aclreadfile = fopen ("/harddisk" CONFIG_ROOT "/proxy/acl", "r"))) {
|
||||
unlink ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4");
|
||||
fclose(aclreadfile);
|
||||
} else {
|
||||
rename ("/harddisk" CONFIG_ROOT "/proxy/acl-1.4",
|
||||
"/harddisk" CONFIG_ROOT "/proxy/acl");
|
||||
}
|
||||
chown ("/harddisk" CONFIG_ROOT "/proxy/acl", 99, 99);
|
||||
}
|
||||
/* if we detected SCSI then fixup */
|
||||
void fixup_initrd() {
|
||||
FILE *handle;
|
||||
char line[STRING_SIZE];
|
||||
char commandstring[STRING_SIZE];
|
||||
|
||||
if (!(handle = fopen("/scsidriver", "r")))
|
||||
return;
|
||||
|
||||
char *driver;
|
||||
fgets(line, STRING_SIZE-1, handle);
|
||||
fclose(handle);
|
||||
line[strlen(line) - 1] = 0;
|
||||
driver = strtok(line, ".");
|
||||
fprintf(flog, "Detected SCSI driver %s\n", driver);
|
||||
if (!strlen(driver) > 1)
|
||||
return;
|
||||
|
||||
fprintf(flog, "Fixing up ipcoprd.img\n");
|
||||
mysystem("/bin/chroot /harddisk /sbin/modprobe loop");
|
||||
mkdir("/harddisk/initrd", S_IRWXU|S_IRWXG|S_IRWXO);
|
||||
sprintf(commandstring, "/bin/chroot /harddisk /sbin/mkinitrd"
|
||||
" --with=scsi_mod --with=%s --with=sd_mod"
|
||||
" --with=sr_mod --with=libata"
|
||||
" --with=ataraid /boot/ipcoprd.img "KERNEL_VERSION,
|
||||
driver );
|
||||
runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
|
||||
#ifdef __i386__
|
||||
sprintf(commandstring, "/bin/chroot /harddisk /sbin/mkinitrd"
|
||||
" --with=scsi_mod --with=%s --with=sd_mod"
|
||||
" --with=sr_mod --with=libata"
|
||||
" --with=ataraid /boot/ipcoprd-smp.img "KERNEL_VERSION"-smp",
|
||||
driver );
|
||||
runcommandwithstatus(commandstring, ctr[TR_BUILDING_INITRD]);
|
||||
mysystem("/bin/chroot /harddisk /bin/mv /boot/grub/scsigrub.conf /boot/grub/grub.conf");
|
||||
#endif
|
||||
#ifdef __alpha__
|
||||
runcommandwithstatus("/bin/chroot /harddisk /bin/mv /boot/etc/scsiaboot.conf /boot/etc/aboot.conf", ctr[TR_BUILDING_INITRD]);
|
||||
#endif
|
||||
}
|
||||
/* when backup is ready in tmpdir, move files to definitive location */
|
||||
void do_copy_files() {
|
||||
mysystem("/bin/chroot /harddisk /bin/cp -af "TMP_EXTRACT_CH"/. /");
|
||||
/* Upgrade necessary files from v1.2 to v1.3 to v1.4 */
|
||||
upgrade_v12_v13();
|
||||
upgrade_v130_v140();
|
||||
/* Upgrade configuration files starting from 1.4.11 */
|
||||
mysystem("/bin/chroot /harddisk /usr/local/bin/upgrade");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
#define LANG argv[1]
|
||||
#define DEST_DEV argv[2]
|
||||
#define WGET argv[3]
|
||||
|
||||
#ifdef LANG_EN_ONLY
|
||||
char **langtrs[] = { en_tr, NULL };
|
||||
#else
|
||||
char **langtrs[] = { bz_tr, cs_tr, da_tr, de_tr, en_tr, es_tr, fr_tr, el_tr, it_tr, la_tr, hu_tr, nl_tr, no_tr, pl_tr, pt_tr, sk_tr, so_tr, fi_tr, sv_tr, tr_tr, vi_tr, NULL };
|
||||
#endif
|
||||
char message[1000];
|
||||
char title[STRING_SIZE];
|
||||
char commandstring[STRING_SIZE];
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
/* Log file/terminal stuff. */
|
||||
mylog = "/dev/tty2";
|
||||
ctr = langtrs[ atoi(LANG) ];
|
||||
|
||||
if (!(flog = fopen(mylog, "w+")))
|
||||
{
|
||||
printf("Couldn't open log terminal\n");
|
||||
return 0;
|
||||
}
|
||||
fprintf(flog, "Install2 program started.\n");
|
||||
newtInit();
|
||||
newtCls();
|
||||
strcpy (title, NAME " v" VERSION " - " SLOGAN);
|
||||
newtDrawRootText(14, 0, title);
|
||||
newtPushHelpLine(ctr[TR_HELPLINE]);
|
||||
|
||||
/* working dirs... */
|
||||
mkdir(MOUNT_BACKUP, S_IRWXU|S_IRWXG|S_IRWXO);
|
||||
|
||||
//create the GUI screen and objects
|
||||
newtComponent form, header, labelfile, labelkey, file, key, radio0, radio1, radio2, radio3, radio4, ok;
|
||||
|
||||
newtCenteredWindow (55,20,ctr[TR_RESTORE]);
|
||||
form = newtForm (NULL, NULL,0);
|
||||
|
||||
sprintf(message, ctr[TR_RESTORE_CONFIGURATION], NAME);
|
||||
header = newtTextboxReflowed (2,1,message,51,0,0,0);
|
||||
newtFormAddComponent(form, header);
|
||||
|
||||
// The four method of restauration
|
||||
int start1=1, start2=0, start3=0, start4=0;
|
||||
radio1 = newtRadiobutton (17, 5, ctr[TR_SKIP], start1, NULL);
|
||||
radio2 = newtRadiobutton (17, 6, "Floppy (legacy)", start2, radio1);
|
||||
radio3 = newtRadiobutton (17, 7, "Usb-storage/CDROM", start3, radio2);
|
||||
if (strcmp(WGET,"none"))
|
||||
radio4 = newtRadiobutton (17, 8, "HTTP/FTP", start4, radio3);
|
||||
else
|
||||
radio4 = NULL;
|
||||
newtFormAddComponents(form, radio1, radio2, radio3, radio4, NULL);
|
||||
|
||||
// The optionnal filename for 'backup'
|
||||
labelfile=newtTextbox(12, 10, 35, 1, 0);
|
||||
newtTextboxSetText (labelfile, "Filename");
|
||||
newtFormAddComponent(form, labelfile);
|
||||
char *filevalue;
|
||||
char fileinit[STRING_SIZE] = "backup";
|
||||
file = newtEntry (17, 11, fileinit, 20, &filevalue, 0);
|
||||
newtFormAddComponent(form, file);
|
||||
|
||||
// The optionnal password for the key
|
||||
labelkey=newtTextbox(12, 13, 35, 1, 0);
|
||||
newtTextboxSetText (labelkey, "Backup key password");
|
||||
newtFormAddComponent(form, labelkey);
|
||||
char *keyvalue;
|
||||
char keyinit[STRING_SIZE] = "";
|
||||
key = newtEntry (17, 14, keyinit, 20, &keyvalue, 0);
|
||||
newtFormAddComponent(form, key);
|
||||
|
||||
// The OK button
|
||||
ok=newtButton (23, 16, ctr[TR_OK]);
|
||||
newtFormAddComponent(form, ok);
|
||||
|
||||
/* loop until succeeds or user skips out */
|
||||
int retcode = -1;
|
||||
while ( retcode<0 ) {
|
||||
|
||||
// run the windows
|
||||
struct newtExitStruct reponse;
|
||||
newtFormRun (form, &reponse);
|
||||
radio0 = newtRadioGetCurrent(radio1);
|
||||
int radio;
|
||||
radio = radio0 == radio1 ? 1 : radio0 == radio2 ? 2 : radio0 == radio3 ? 3 : radio0 == radio4 ? 4 : 0;
|
||||
strcpy(keyinit,keyvalue); //reuse actual value
|
||||
strcpy(fileinit,filevalue);
|
||||
|
||||
if (radio==1) {
|
||||
retcode = 1; // no restore: nothing special
|
||||
break; // out of the while loop
|
||||
}
|
||||
|
||||
mkdir(TMP_EXTRACT, S_IRWXU|S_IRWXG|S_IRWXO);
|
||||
statuswindow(45, 4, title, ctr[TR_INSTALLING_FILES]);
|
||||
switch (radio) {
|
||||
case 4: // network
|
||||
sprintf(commandstring,"/bin/wget -P " TMP_EXTRACT " %s/%s.dat", WGET, filevalue);
|
||||
mysystem (commandstring);
|
||||
sprintf(commandstring,"/bin/wget -P " TMP_EXTRACT " %s/%s.key", WGET, filevalue);
|
||||
if (mysystem (commandstring)) {
|
||||
errorbox(ctr[TR_FAILED_TO_FIND]);
|
||||
break;
|
||||
};
|
||||
goto COMMON;
|
||||
case 3: // normal backup
|
||||
if (mountbackup( filevalue, DEST_DEV )) {
|
||||
errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);//mess=no device with backup found
|
||||
break;
|
||||
};
|
||||
// link files to a COMMON location
|
||||
sprintf (commandstring, "chroot /harddisk ln -s "MOUNT_BACKUP_CH"/%s.dat " TMP_EXTRACT_CH "/%s.dat", filevalue, filevalue);
|
||||
mysystem (commandstring);
|
||||
sprintf (commandstring, "chroot /harddisk ln -s "MOUNT_BACKUP_CH"/%s.key " TMP_EXTRACT_CH "/%s.key", filevalue, filevalue);
|
||||
mysystem (commandstring);
|
||||
|
||||
COMMON: // DECRYPT THE TARBALL
|
||||
// Copy the key to a new location because we decrypt it!
|
||||
if (strcmp(keyvalue, "")) { // password provided: decrypt the key
|
||||
sprintf(commandstring, "/bin/chroot /harddisk /usr/bin/openssl enc"
|
||||
" -a -d -aes256 -salt"
|
||||
" -pass pass:%s"
|
||||
" -in " TMP_EXTRACT_CH "/%s.key"
|
||||
" -out " TMP_EXTRACT_CH "/__tmp.key",
|
||||
keyvalue, filevalue);
|
||||
} else { //just copy to new name
|
||||
sprintf(commandstring, "/bin/chroot /harddisk cp"
|
||||
" " TMP_EXTRACT_CH "/%s.key"
|
||||
" " TMP_EXTRACT_CH "/__tmp.key",
|
||||
filevalue);
|
||||
}
|
||||
mysystem (commandstring);
|
||||
|
||||
sprintf(commandstring, "/bin/chroot /harddisk /usr/bin/openssl des3"
|
||||
" -d -salt"
|
||||
" -in " TMP_EXTRACT_CH "/%s.dat"
|
||||
" -out " TMP_EXTRACT_CH "/backup.tgz"
|
||||
" -kfile " TMP_EXTRACT_CH "/__tmp.key",
|
||||
filevalue);
|
||||
|
||||
if (mysystem (commandstring)) {
|
||||
errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);//mess=decrypt error:invalid key?
|
||||
break;
|
||||
}
|
||||
strcpy(commandstring, "/bin/chroot /harddisk /bin/tar"
|
||||
" -X " CONFIG_ROOT "/backup/exclude.system"
|
||||
" -C " TMP_EXTRACT_CH
|
||||
" -xzf " TMP_EXTRACT_CH "/backup.tgz");
|
||||
|
||||
if (mysystem(commandstring)) {
|
||||
errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
|
||||
break;
|
||||
}
|
||||
sprintf(commandstring, TMP_EXTRACT "/%s.dat", filevalue);
|
||||
unlink(commandstring ); //dont need them anymore
|
||||
unlink( TMP_EXTRACT "/backup.tgz");
|
||||
sprintf(commandstring, TMP_EXTRACT "/%s.key", filevalue);
|
||||
unlink(commandstring );
|
||||
unlink( TMP_EXTRACT "/__tmp.key");
|
||||
|
||||
/* Now copy to correct location */
|
||||
do_copy_files();
|
||||
retcode = 0; /* successfully restored */
|
||||
break;
|
||||
case 2:
|
||||
// diskette change
|
||||
if (floppy_locate()) {
|
||||
retcode = 2; // this an error!
|
||||
break;
|
||||
}
|
||||
|
||||
/* Always extract to /tmp/ipcop for temporary extraction
|
||||
just in case floppy fails.
|
||||
try a compressed backup first because it's quicker to fail.
|
||||
In exclude.system, files name must be without leading / or
|
||||
on extraction, name will never match
|
||||
*/
|
||||
sprintf(commandstring,
|
||||
"/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C "TMP_EXTRACT_CH" -xvzf /dev/floppy > %s 2> /dev/null", mylog);
|
||||
if (system(commandstring)) {
|
||||
/* if it's not compressed, try uncompressed first before failing*/
|
||||
sprintf(commandstring,
|
||||
"/bin/chroot /harddisk /bin/tar -X " CONFIG_ROOT "/backup/exclude.system -C "TMP_EXTRACT_CH" -xvf /dev/floppy > %s 2> /dev/null", mylog);
|
||||
if (system(commandstring)) {
|
||||
/* command failed trying to read from floppy */
|
||||
errorbox(ctr[TR_UNABLE_TO_INSTALL_FILES]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Now copy to correct location */
|
||||
do_copy_files();
|
||||
retcode = 0; /* successfully restored */
|
||||
}//switch
|
||||
/* remove possible badly restored files */
|
||||
mysystem("/bin/chroot /harddisk /bin/rm -rf " TMP_EXTRACT_CH );
|
||||
newtPopWindow(); // close windows
|
||||
}//while
|
||||
newtFormDestroy(form);
|
||||
|
||||
/* cleanup */
|
||||
mysystem("/bin/umount " MOUNT_BACKUP);
|
||||
mysystem("/bin/chroot /harddisk /bin/rmdir " MOUNT_BACKUP_CH);
|
||||
|
||||
/* others operations moved from install to install2 */
|
||||
fixup_squidacl();
|
||||
fixup_initrd();
|
||||
|
||||
fprintf(flog, "Install2 program ended.\n");
|
||||
fflush(flog);
|
||||
fclose(flog);
|
||||
newtFinished();
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,77 +1,77 @@
|
||||
/* SmoothWall install program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Stuff for downloading the smoothwall tarball using wget.
|
||||
*
|
||||
* $Id: net.c,v 1.8.2.2 2004/04/14 22:05:40 gespinasse Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
|
||||
extern FILE *flog;
|
||||
extern char *mylog;
|
||||
|
||||
extern char **ctr;
|
||||
|
||||
static int got_url = 0;
|
||||
|
||||
char url[STRING_SIZE];
|
||||
|
||||
static int gettarballurl();
|
||||
|
||||
int checktarball(char *file)
|
||||
{
|
||||
int done;
|
||||
int tries = 0;
|
||||
char commandstring[STRING_SIZE];
|
||||
|
||||
done = 0;
|
||||
while (!done)
|
||||
{
|
||||
if (!got_url && gettarballurl() != 1)
|
||||
return 0;
|
||||
|
||||
/* remove any successive /'s */
|
||||
while (url[strlen(url)-1] == '/') { url[strlen(url)-1] = '\0'; }
|
||||
|
||||
snprintf(commandstring, STRING_SIZE, "/bin/wget -s -O /dev/null %s/%s", url, file);
|
||||
if (!(runcommandwithstatus(commandstring, ctr[TR_CHECKING])))
|
||||
{
|
||||
done = 1;
|
||||
got_url = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorbox(ctr[TR_FAILED_TO_FIND]);
|
||||
got_url = 0;
|
||||
if (tries == 3)
|
||||
return 0;
|
||||
}
|
||||
tries++;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int gettarballurl()
|
||||
{
|
||||
char *values[] = { NULL, NULL }; /* pointers for the values. */
|
||||
struct newtWinEntry entries[] =
|
||||
{ { "", &values[0], 0,}, { NULL, NULL, 0 } };
|
||||
char title[STRING_SIZE];
|
||||
char message[1000];
|
||||
int rc;
|
||||
|
||||
sprintf(message, ctr[TR_ENTER_URL]);
|
||||
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
|
||||
rc = newtWinEntries(title, message,
|
||||
60, 5, 5, 50, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
|
||||
|
||||
strncpy(url, values[0], STRING_SIZE);
|
||||
|
||||
return rc;
|
||||
}
|
||||
/* SmoothWall install program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Stuff for downloading the smoothwall tarball using wget.
|
||||
*
|
||||
* $Id: net.c,v 1.8.2.2 2004/04/14 22:05:40 gespinasse Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
|
||||
extern FILE *flog;
|
||||
extern char *mylog;
|
||||
|
||||
extern char **ctr;
|
||||
|
||||
static int got_url = 0;
|
||||
|
||||
char url[STRING_SIZE];
|
||||
|
||||
static int gettarballurl();
|
||||
|
||||
int checktarball(char *file)
|
||||
{
|
||||
int done;
|
||||
int tries = 0;
|
||||
char commandstring[STRING_SIZE];
|
||||
|
||||
done = 0;
|
||||
while (!done)
|
||||
{
|
||||
if (!got_url && gettarballurl() != 1)
|
||||
return 0;
|
||||
|
||||
/* remove any successive /'s */
|
||||
while (url[strlen(url)-1] == '/') { url[strlen(url)-1] = '\0'; }
|
||||
|
||||
snprintf(commandstring, STRING_SIZE, "/bin/wget -s -O /dev/null %s/%s", url, file);
|
||||
if (!(runcommandwithstatus(commandstring, ctr[TR_CHECKING])))
|
||||
{
|
||||
done = 1;
|
||||
got_url = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
errorbox(ctr[TR_FAILED_TO_FIND]);
|
||||
got_url = 0;
|
||||
if (tries == 3)
|
||||
return 0;
|
||||
}
|
||||
tries++;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int gettarballurl()
|
||||
{
|
||||
char *values[] = { NULL, NULL }; /* pointers for the values. */
|
||||
struct newtWinEntry entries[] =
|
||||
{ { "", &values[0], 0,}, { NULL, NULL, 0 } };
|
||||
char title[STRING_SIZE];
|
||||
char message[1000];
|
||||
int rc;
|
||||
|
||||
sprintf(message, ctr[TR_ENTER_URL]);
|
||||
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
|
||||
rc = newtWinEntries(title, message,
|
||||
60, 5, 5, 50, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
|
||||
|
||||
strncpy(url, values[0], STRING_SIZE);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1,98 +1,98 @@
|
||||
/* SmoothWall install program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Contains stuff related to firing up the network card, including a crude
|
||||
* autodector.
|
||||
*
|
||||
* $Id: nic.c,v 1.8.2.2 2005/12/24 09:08:26 franck78 Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
extern FILE *flog;
|
||||
extern char *mylog;
|
||||
extern char **ctr;
|
||||
extern struct nic nics[];
|
||||
|
||||
int networkmenu(struct keyvalue *ethernetkv)
|
||||
{
|
||||
int rc;
|
||||
char driver[STRING_SIZE] = "";
|
||||
char driveroptions[STRING_SIZE] = "";
|
||||
int result = 0;
|
||||
char commandstring[STRING_SIZE];
|
||||
char address[STRING_SIZE], netmask[STRING_SIZE];
|
||||
int done;
|
||||
char description[1000];
|
||||
char message[1000];
|
||||
char title[STRING_SIZE];
|
||||
done = 0;
|
||||
|
||||
while (!done)
|
||||
{
|
||||
rc = newtWinTernary(ctr[TR_CONFIGURE_NETWORKING], ctr[TR_PROBE],
|
||||
ctr[TR_SELECT], ctr[TR_CANCEL], ctr[TR_CONFIGURE_NETWORKING_LONG]);
|
||||
|
||||
if (rc == 0 || rc == 1)
|
||||
{
|
||||
probecards(driver, driveroptions);
|
||||
if (!strlen(driver))
|
||||
errorbox(ctr[TR_PROBE_FAILED]);
|
||||
else
|
||||
{
|
||||
findnicdescription(driver, description);
|
||||
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
|
||||
sprintf(message, ctr[TR_FOUND_NIC], NAME, description);
|
||||
newtWinMessage(title, ctr[TR_OK], message);
|
||||
}
|
||||
}
|
||||
else if (rc == 2)
|
||||
choosecards(driver, driveroptions);
|
||||
else
|
||||
done = 1;
|
||||
|
||||
if (strlen(driver))
|
||||
done = 1;
|
||||
}
|
||||
|
||||
if (!strlen(driver))
|
||||
goto EXIT;
|
||||
|
||||
/* Default is a GREEN nic only. */
|
||||
/* Smoothie is not untarred yet, so we have to delay actually writing the
|
||||
* settings till later. */
|
||||
replacekeyvalue(ethernetkv, "CONFIG_TYPE", "0");
|
||||
replacekeyvalue(ethernetkv, "GREEN_DRIVER", driver);
|
||||
replacekeyvalue(ethernetkv, "GREEN_DRIVER_OPTIONS", driveroptions);
|
||||
replacekeyvalue(ethernetkv, "GREEN_DEV", "eth0");
|
||||
replacekeyvalue(ethernetkv, "GREEN_DISPLAYDRIVER", driver);
|
||||
|
||||
if (!(changeaddress(ethernetkv, "GREEN", 0, "")))
|
||||
goto EXIT;
|
||||
|
||||
strcpy(address, ""); findkey(ethernetkv, "GREEN_ADDRESS", address);
|
||||
strcpy(netmask, ""); findkey(ethernetkv, "GREEN_NETMASK", netmask);
|
||||
|
||||
snprintf(commandstring, STRING_SIZE, "/bin/ifconfig eth0 %s netmask %s up",
|
||||
address, netmask);
|
||||
if (mysystem(commandstring))
|
||||
{
|
||||
errorbox(ctr[TR_INTERFACE_FAILED_TO_COME_UP]);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
result = 1;
|
||||
|
||||
EXIT:
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* SmoothWall install program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Lawrence Manning, 2001
|
||||
* Contains stuff related to firing up the network card, including a crude
|
||||
* autodector.
|
||||
*
|
||||
* $Id: nic.c,v 1.8.2.2 2005/12/24 09:08:26 franck78 Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
extern FILE *flog;
|
||||
extern char *mylog;
|
||||
extern char **ctr;
|
||||
extern struct nic nics[];
|
||||
|
||||
int networkmenu(struct keyvalue *ethernetkv)
|
||||
{
|
||||
int rc;
|
||||
char driver[STRING_SIZE] = "";
|
||||
char driveroptions[STRING_SIZE] = "";
|
||||
int result = 0;
|
||||
char commandstring[STRING_SIZE];
|
||||
char address[STRING_SIZE], netmask[STRING_SIZE];
|
||||
int done;
|
||||
char description[1000];
|
||||
char message[1000];
|
||||
char title[STRING_SIZE];
|
||||
done = 0;
|
||||
|
||||
while (!done)
|
||||
{
|
||||
rc = newtWinTernary(ctr[TR_CONFIGURE_NETWORKING], ctr[TR_PROBE],
|
||||
ctr[TR_SELECT], ctr[TR_CANCEL], ctr[TR_CONFIGURE_NETWORKING_LONG]);
|
||||
|
||||
if (rc == 0 || rc == 1)
|
||||
{
|
||||
probecards(driver, driveroptions);
|
||||
if (!strlen(driver))
|
||||
errorbox(ctr[TR_PROBE_FAILED]);
|
||||
else
|
||||
{
|
||||
findnicdescription(driver, description);
|
||||
sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
|
||||
sprintf(message, ctr[TR_FOUND_NIC], NAME, description);
|
||||
newtWinMessage(title, ctr[TR_OK], message);
|
||||
}
|
||||
}
|
||||
else if (rc == 2)
|
||||
choosecards(driver, driveroptions);
|
||||
else
|
||||
done = 1;
|
||||
|
||||
if (strlen(driver))
|
||||
done = 1;
|
||||
}
|
||||
|
||||
if (!strlen(driver))
|
||||
goto EXIT;
|
||||
|
||||
/* Default is a GREEN nic only. */
|
||||
/* Smoothie is not untarred yet, so we have to delay actually writing the
|
||||
* settings till later. */
|
||||
replacekeyvalue(ethernetkv, "CONFIG_TYPE", "0");
|
||||
replacekeyvalue(ethernetkv, "GREEN_DRIVER", driver);
|
||||
replacekeyvalue(ethernetkv, "GREEN_DRIVER_OPTIONS", driveroptions);
|
||||
replacekeyvalue(ethernetkv, "GREEN_DEV", "eth0");
|
||||
replacekeyvalue(ethernetkv, "GREEN_DISPLAYDRIVER", driver);
|
||||
|
||||
if (!(changeaddress(ethernetkv, "GREEN", 0, "")))
|
||||
goto EXIT;
|
||||
|
||||
strcpy(address, ""); findkey(ethernetkv, "GREEN_ADDRESS", address);
|
||||
strcpy(netmask, ""); findkey(ethernetkv, "GREEN_NETMASK", netmask);
|
||||
|
||||
snprintf(commandstring, STRING_SIZE, "/bin/ifconfig eth0 %s netmask %s up",
|
||||
address, netmask);
|
||||
if (mysystem(commandstring))
|
||||
{
|
||||
errorbox(ctr[TR_INTERFACE_FAILED_TO_COME_UP]);
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
result = 1;
|
||||
|
||||
EXIT:
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,332 +1,332 @@
|
||||
/*
|
||||
* PCMCIA bridge device probe
|
||||
*
|
||||
* This file is part of the IPCop Firewall.
|
||||
*
|
||||
* IPCop 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.
|
||||
*
|
||||
* IPCop 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 IPCop; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* The initial developer of the original code is David A. Hinds
|
||||
* <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
|
||||
* are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
|
||||
*
|
||||
* $Id: pcmcia.c,v 1.6.2.4 2005/12/08 02:12:28 franck78 Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
#include "pcmcia.h"
|
||||
|
||||
#ifdef __GLIBC__
|
||||
#include <sys/io.h>
|
||||
#else
|
||||
#include <asm/io.h>
|
||||
#endif
|
||||
|
||||
extern FILE *flog;
|
||||
extern int modprobe(char *);
|
||||
|
||||
/*====================================================================*/
|
||||
|
||||
typedef struct {
|
||||
u_short vendor, device;
|
||||
char *modname;
|
||||
char *name;
|
||||
} pci_id_t;
|
||||
|
||||
pci_id_t pci_id[] = {
|
||||
{ 0x1013, 0x1100, "i82365", "Cirrus Logic CL 6729" },
|
||||
{ 0x1013, 0x1110, "yenta_socket", "Cirrus Logic PD 6832" },
|
||||
{ 0x10b3, 0xb106, "yenta_socket", "SMC 34C90" },
|
||||
{ 0x1180, 0x0465, "yenta_socket", "Ricoh RL5C465" },
|
||||
{ 0x1180, 0x0466, "yenta_socket", "Ricoh RL5C466" },
|
||||
{ 0x1180, 0x0475, "yenta_socket", "Ricoh RL5C475" },
|
||||
{ 0x1180, 0x0476, "yenta_socket", "Ricoh RL5C476" },
|
||||
{ 0x1180, 0x0477, "yenta_socket", "Ricoh RL5C477" },
|
||||
{ 0x1180, 0x0478, "yenta_socket", "Ricoh RL5C478" },
|
||||
{ 0x104c, 0xac12, "yenta_socket", "Texas Instruments PCI1130" },
|
||||
{ 0x104c, 0xac13, "yenta_socket", "Texas Instruments PCI1031" },
|
||||
{ 0x104c, 0xac15, "yenta_socket", "Texas Instruments PCI1131" },
|
||||
{ 0x104c, 0xac1a, "yenta_socket", "Texas Instruments PCI1210" },
|
||||
{ 0x104c, 0xac1e, "yenta_socket", "Texas Instruments PCI1211" },
|
||||
{ 0x104c, 0xac17, "yenta_socket", "Texas Instruments PCI1220" },
|
||||
{ 0x104c, 0xac19, "yenta_socket", "Texas Instruments PCI1221" },
|
||||
{ 0x104c, 0xac1c, "yenta_socket", "Texas Instruments PCI1225" },
|
||||
{ 0x104c, 0xac16, "yenta_socket", "Texas Instruments PCI1250" },
|
||||
{ 0x104c, 0xac1d, "yenta_socket", "Texas Instruments PCI1251A" },
|
||||
{ 0x104c, 0xac1f, "yenta_socket", "Texas Instruments PCI1251B" },
|
||||
{ 0x104c, 0xac50, "yenta_socket", "Texas Instruments PCI1410" },
|
||||
{ 0x104c, 0xac51, "yenta_socket", "Texas Instruments PCI1420" },
|
||||
{ 0x104c, 0xac1b, "yenta_socket", "Texas Instruments PCI1450" },
|
||||
{ 0x104c, 0xac52, "yenta_socket", "Texas Instruments PCI1451" },
|
||||
{ 0x104c, 0xac56, "yenta_socket", "Texas Instruments PCI1510" },
|
||||
{ 0x104c, 0xac55, "yenta_socket", "Texas Instruments PCI1520" },
|
||||
{ 0x104c, 0xac54, "yenta_socket", "Texas Instruments PCI1620" },
|
||||
{ 0x104c, 0xac41, "yenta_socket", "Texas Instruments PCI4410" },
|
||||
{ 0x104c, 0xac40, "yenta_socket", "Texas Instruments PCI4450" },
|
||||
{ 0x104c, 0xac42, "yenta_socket", "Texas Instruments PCI4451" },
|
||||
{ 0x104c, 0xac44, "yenta_socket", "Texas Instruments PCI4510" },
|
||||
{ 0x104c, 0xac46, "yenta_socket", "Texas Instruments PCI4520" },
|
||||
{ 0x104c, 0xac49, "yenta_socket", "Texas Instruments PCI7410" },
|
||||
{ 0x104c, 0xac47, "yenta_socket", "Texas Instruments PCI7510" },
|
||||
{ 0x104c, 0xac48, "yenta_socket", "Texas Instruments PCI7610" },
|
||||
{ 0x1217, 0x6729, "i82365", "O2 Micro 6729" },
|
||||
{ 0x1217, 0x673a, "i82365", "O2 Micro 6730" },
|
||||
{ 0x1217, 0x6832, "yenta_socket", "O2 Micro 6832/6833" },
|
||||
{ 0x1217, 0x6836, "yenta_socket", "O2 Micro 6836/6860" },
|
||||
{ 0x1217, 0x6872, "yenta_socket", "O2 Micro 6812" },
|
||||
{ 0x1217, 0x6925, "yenta_socket", "O2 Micro 6922" },
|
||||
{ 0x1217, 0x6933, "yenta_socket", "O2 Micro 6933" },
|
||||
{ 0x1217, 0x6972, "yenta_socket", "O2 Micro 6912" },
|
||||
{ 0x1179, 0x0603, "i82365", "Toshiba ToPIC95-A" },
|
||||
{ 0x1179, 0x060a, "yenta_socket", "Toshiba ToPIC95-B" },
|
||||
{ 0x1179, 0x060f, "yenta_socket", "Toshiba ToPIC97" },
|
||||
{ 0x1179, 0x0617, "yenta_socket", "Toshiba ToPIC100" },
|
||||
{ 0x119b, 0x1221, "i82365", "Omega Micro 82C092G" },
|
||||
{ 0x8086, 0x1221, "i82092", "Intel 82092AA_0" },
|
||||
{ 0x8086, 0x1222, "i82092", "Intel 82092AA_1" },
|
||||
{ 0x1524, 0x1211, "yenta_socket", "ENE 1211" },
|
||||
{ 0x1524, 0x1225, "yenta_socket", "ENE 1225" },
|
||||
{ 0x1524, 0x1410, "yenta_socket", "ENE 1410" },
|
||||
{ 0x1524, 0x1420, "yenta_socket", "ENE 1420" },
|
||||
};
|
||||
#define PCI_COUNT (sizeof(pci_id)/sizeof(pci_id_t))
|
||||
|
||||
static char * pci_probe()
|
||||
{
|
||||
char s[256], *modname = NULL;
|
||||
u_int device, vendor, i;
|
||||
FILE *f;
|
||||
|
||||
if ((f = fopen("/proc/bus/pci/devices", "r")) != NULL) {
|
||||
while (fgets(s, 256, f) != NULL) {
|
||||
u_int n = strtoul(s+5, NULL, 16);
|
||||
vendor = (n >> 16); device = (n & 0xffff);
|
||||
for (i = 0; i < PCI_COUNT; i++)
|
||||
if ((vendor == pci_id[i].vendor) &&
|
||||
(device == pci_id[i].device)) break;
|
||||
|
||||
if (i < PCI_COUNT) {
|
||||
modname = pci_id[i].modname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return modname;
|
||||
}
|
||||
|
||||
/*====================================================================*/
|
||||
|
||||
#ifndef __alpha__
|
||||
typedef u_short ioaddr_t;
|
||||
|
||||
static ioaddr_t i365_base = 0x03e0;
|
||||
|
||||
static u_char i365_get(u_short sock, u_short reg)
|
||||
{
|
||||
u_char val = I365_REG(sock, reg);
|
||||
outb(val, i365_base); val = inb(i365_base+1);
|
||||
return val;
|
||||
}
|
||||
|
||||
#if 0 // the following code do nothing usefull, it ends with return 0 anyway
|
||||
|
||||
static void i365_set(u_short sock, u_short reg, u_char data)
|
||||
{
|
||||
u_char val = I365_REG(sock, reg);
|
||||
outb(val, i365_base); outb(data, i365_base+1);
|
||||
}
|
||||
|
||||
static void i365_bset(u_short sock, u_short reg, u_char mask)
|
||||
{
|
||||
u_char d = i365_get(sock, reg);
|
||||
d |= mask;
|
||||
i365_set(sock, reg, d);
|
||||
}
|
||||
|
||||
static void i365_bclr(u_short sock, u_short reg, u_char mask)
|
||||
{
|
||||
u_char d = i365_get(sock, reg);
|
||||
d &= ~mask;
|
||||
i365_set(sock, reg, d);
|
||||
}
|
||||
#endif
|
||||
|
||||
int i365_probe()
|
||||
{
|
||||
int val, slot, sock, done;
|
||||
// char *name = "i82365sl";
|
||||
|
||||
ioperm(i365_base, 4, 1);
|
||||
ioperm(0x80, 1, 1);
|
||||
for (slot = 0; slot < 2; slot++) {
|
||||
for (sock = done = 0; sock < 2; sock++) {
|
||||
val = i365_get(sock, I365_IDENT);
|
||||
switch (val) {
|
||||
case 0x82:
|
||||
// name = "i82365sl A step";
|
||||
// break;
|
||||
case 0x83:
|
||||
// name = "i82365sl B step";
|
||||
// break;
|
||||
case 0x84:
|
||||
// name = "VLSI 82C146";
|
||||
// break;
|
||||
case 0x88: case 0x89: case 0x8a:
|
||||
// name = "IBM Clone";
|
||||
// break;
|
||||
case 0x8b: case 0x8c:
|
||||
break;
|
||||
default:
|
||||
done = 1;
|
||||
}
|
||||
if (done) break;
|
||||
}
|
||||
if (done && sock) break;
|
||||
i365_base += 2;
|
||||
}
|
||||
|
||||
if (sock == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 0 // the following code do nothing usefull, it ends with return 0 anyway
|
||||
if ((sock == 2) && (strcmp(name, "VLSI 82C146") == 0))
|
||||
name = "i82365sl DF";
|
||||
|
||||
/* Check for Vadem chips */
|
||||
outb(0x0e, i365_base);
|
||||
outb(0x37, i365_base);
|
||||
i365_bset(0, VG468_MISC, VG468_MISC_VADEMREV);
|
||||
val = i365_get(0, I365_IDENT);
|
||||
if (val & I365_IDENT_VADEM) {
|
||||
if ((val & 7) < 4)
|
||||
name = "Vadem VG-468";
|
||||
else
|
||||
name = "Vadem VG-469";
|
||||
i365_bclr(0, VG468_MISC, VG468_MISC_VADEMREV);
|
||||
}
|
||||
|
||||
/* Check for Cirrus CL-PD67xx chips */
|
||||
i365_set(0, PD67_CHIP_INFO, 0);
|
||||
val = i365_get(0, PD67_CHIP_INFO);
|
||||
if ((val & PD67_INFO_CHIP_ID) == PD67_INFO_CHIP_ID) {
|
||||
val = i365_get(0, PD67_CHIP_INFO);
|
||||
if ((val & PD67_INFO_CHIP_ID) == 0) {
|
||||
if (val & PD67_INFO_SLOTS)
|
||||
name = "Cirrus CL-PD672x";
|
||||
else {
|
||||
name = "Cirrus CL-PD6710";
|
||||
sock = 1;
|
||||
}
|
||||
i365_set(0, PD67_EXT_INDEX, 0xe5);
|
||||
if (i365_get(0, PD67_EXT_INDEX) != 0xe5)
|
||||
name = "VIA VT83C469";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
} /* i365_probe */
|
||||
#endif
|
||||
|
||||
/*====================================================================*/
|
||||
|
||||
#ifndef __alpha__
|
||||
static u_short tcic_getw(ioaddr_t base, u_char reg)
|
||||
{
|
||||
u_short val = inw(base+reg);
|
||||
return val;
|
||||
}
|
||||
|
||||
static void tcic_setw(ioaddr_t base, u_char reg, u_short data)
|
||||
{
|
||||
outw(data, base+reg);
|
||||
}
|
||||
|
||||
int tcic_probe_at(ioaddr_t base)
|
||||
{
|
||||
int i;
|
||||
u_short old;
|
||||
|
||||
/* Anything there?? */
|
||||
for (i = 0; i < 0x10; i += 2)
|
||||
if (tcic_getw(base, i) == 0xffff)
|
||||
return -1;
|
||||
|
||||
/* Try to reset the chip */
|
||||
tcic_setw(base, TCIC_SCTRL, TCIC_SCTRL_RESET);
|
||||
tcic_setw(base, TCIC_SCTRL, 0);
|
||||
|
||||
/* Can we set the addr register? */
|
||||
old = tcic_getw(base, TCIC_ADDR);
|
||||
tcic_setw(base, TCIC_ADDR, 0);
|
||||
if (tcic_getw(base, TCIC_ADDR) != 0) {
|
||||
tcic_setw(base, TCIC_ADDR, old);
|
||||
return -2;
|
||||
}
|
||||
|
||||
tcic_setw(base, TCIC_ADDR, 0xc3a5);
|
||||
if (tcic_getw(base, TCIC_ADDR) != 0xc3a5)
|
||||
return -3;
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
int tcic_probe(ioaddr_t base)
|
||||
{
|
||||
int sock;
|
||||
|
||||
ioperm(base, 16, 1);
|
||||
ioperm(0x80, 1, 1);
|
||||
sock = tcic_probe_at(base);
|
||||
|
||||
if (sock <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
} /* tcic_probe */
|
||||
#endif
|
||||
|
||||
/*====================================================================*/
|
||||
char * initialize_pcmcia (void)
|
||||
{
|
||||
#ifndef __alpha__
|
||||
ioaddr_t tcic_base = TCIC_BASE;
|
||||
#endif
|
||||
char* pcmcia;
|
||||
|
||||
if ((pcmcia = pci_probe()))
|
||||
return pcmcia; /* we're all done */
|
||||
#ifndef __alpha__
|
||||
else if (i365_probe() == 0)
|
||||
return "i82365";
|
||||
else if (tcic_probe(tcic_base) == 0)
|
||||
return "tcic";
|
||||
#endif
|
||||
else {
|
||||
/* Detect ISAPNP based i82365 controllers */
|
||||
FILE *f;
|
||||
modprobe("i82365");
|
||||
if ((f = fopen("/proc/bus/pccard/00/info", "r"))) {
|
||||
fclose(f);
|
||||
return "i82365";
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
/*
|
||||
* PCMCIA bridge device probe
|
||||
*
|
||||
* This file is part of the IPCop Firewall.
|
||||
*
|
||||
* IPCop 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.
|
||||
*
|
||||
* IPCop 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 IPCop; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* The initial developer of the original code is David A. Hinds
|
||||
* <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
|
||||
* are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
|
||||
*
|
||||
* $Id: pcmcia.c,v 1.6.2.4 2005/12/08 02:12:28 franck78 Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
#include "pcmcia.h"
|
||||
|
||||
#ifdef __GLIBC__
|
||||
#include <sys/io.h>
|
||||
#else
|
||||
#include <asm/io.h>
|
||||
#endif
|
||||
|
||||
extern FILE *flog;
|
||||
extern int modprobe(char *);
|
||||
|
||||
/*====================================================================*/
|
||||
|
||||
typedef struct {
|
||||
u_short vendor, device;
|
||||
char *modname;
|
||||
char *name;
|
||||
} pci_id_t;
|
||||
|
||||
pci_id_t pci_id[] = {
|
||||
{ 0x1013, 0x1100, "i82365", "Cirrus Logic CL 6729" },
|
||||
{ 0x1013, 0x1110, "yenta_socket", "Cirrus Logic PD 6832" },
|
||||
{ 0x10b3, 0xb106, "yenta_socket", "SMC 34C90" },
|
||||
{ 0x1180, 0x0465, "yenta_socket", "Ricoh RL5C465" },
|
||||
{ 0x1180, 0x0466, "yenta_socket", "Ricoh RL5C466" },
|
||||
{ 0x1180, 0x0475, "yenta_socket", "Ricoh RL5C475" },
|
||||
{ 0x1180, 0x0476, "yenta_socket", "Ricoh RL5C476" },
|
||||
{ 0x1180, 0x0477, "yenta_socket", "Ricoh RL5C477" },
|
||||
{ 0x1180, 0x0478, "yenta_socket", "Ricoh RL5C478" },
|
||||
{ 0x104c, 0xac12, "yenta_socket", "Texas Instruments PCI1130" },
|
||||
{ 0x104c, 0xac13, "yenta_socket", "Texas Instruments PCI1031" },
|
||||
{ 0x104c, 0xac15, "yenta_socket", "Texas Instruments PCI1131" },
|
||||
{ 0x104c, 0xac1a, "yenta_socket", "Texas Instruments PCI1210" },
|
||||
{ 0x104c, 0xac1e, "yenta_socket", "Texas Instruments PCI1211" },
|
||||
{ 0x104c, 0xac17, "yenta_socket", "Texas Instruments PCI1220" },
|
||||
{ 0x104c, 0xac19, "yenta_socket", "Texas Instruments PCI1221" },
|
||||
{ 0x104c, 0xac1c, "yenta_socket", "Texas Instruments PCI1225" },
|
||||
{ 0x104c, 0xac16, "yenta_socket", "Texas Instruments PCI1250" },
|
||||
{ 0x104c, 0xac1d, "yenta_socket", "Texas Instruments PCI1251A" },
|
||||
{ 0x104c, 0xac1f, "yenta_socket", "Texas Instruments PCI1251B" },
|
||||
{ 0x104c, 0xac50, "yenta_socket", "Texas Instruments PCI1410" },
|
||||
{ 0x104c, 0xac51, "yenta_socket", "Texas Instruments PCI1420" },
|
||||
{ 0x104c, 0xac1b, "yenta_socket", "Texas Instruments PCI1450" },
|
||||
{ 0x104c, 0xac52, "yenta_socket", "Texas Instruments PCI1451" },
|
||||
{ 0x104c, 0xac56, "yenta_socket", "Texas Instruments PCI1510" },
|
||||
{ 0x104c, 0xac55, "yenta_socket", "Texas Instruments PCI1520" },
|
||||
{ 0x104c, 0xac54, "yenta_socket", "Texas Instruments PCI1620" },
|
||||
{ 0x104c, 0xac41, "yenta_socket", "Texas Instruments PCI4410" },
|
||||
{ 0x104c, 0xac40, "yenta_socket", "Texas Instruments PCI4450" },
|
||||
{ 0x104c, 0xac42, "yenta_socket", "Texas Instruments PCI4451" },
|
||||
{ 0x104c, 0xac44, "yenta_socket", "Texas Instruments PCI4510" },
|
||||
{ 0x104c, 0xac46, "yenta_socket", "Texas Instruments PCI4520" },
|
||||
{ 0x104c, 0xac49, "yenta_socket", "Texas Instruments PCI7410" },
|
||||
{ 0x104c, 0xac47, "yenta_socket", "Texas Instruments PCI7510" },
|
||||
{ 0x104c, 0xac48, "yenta_socket", "Texas Instruments PCI7610" },
|
||||
{ 0x1217, 0x6729, "i82365", "O2 Micro 6729" },
|
||||
{ 0x1217, 0x673a, "i82365", "O2 Micro 6730" },
|
||||
{ 0x1217, 0x6832, "yenta_socket", "O2 Micro 6832/6833" },
|
||||
{ 0x1217, 0x6836, "yenta_socket", "O2 Micro 6836/6860" },
|
||||
{ 0x1217, 0x6872, "yenta_socket", "O2 Micro 6812" },
|
||||
{ 0x1217, 0x6925, "yenta_socket", "O2 Micro 6922" },
|
||||
{ 0x1217, 0x6933, "yenta_socket", "O2 Micro 6933" },
|
||||
{ 0x1217, 0x6972, "yenta_socket", "O2 Micro 6912" },
|
||||
{ 0x1179, 0x0603, "i82365", "Toshiba ToPIC95-A" },
|
||||
{ 0x1179, 0x060a, "yenta_socket", "Toshiba ToPIC95-B" },
|
||||
{ 0x1179, 0x060f, "yenta_socket", "Toshiba ToPIC97" },
|
||||
{ 0x1179, 0x0617, "yenta_socket", "Toshiba ToPIC100" },
|
||||
{ 0x119b, 0x1221, "i82365", "Omega Micro 82C092G" },
|
||||
{ 0x8086, 0x1221, "i82092", "Intel 82092AA_0" },
|
||||
{ 0x8086, 0x1222, "i82092", "Intel 82092AA_1" },
|
||||
{ 0x1524, 0x1211, "yenta_socket", "ENE 1211" },
|
||||
{ 0x1524, 0x1225, "yenta_socket", "ENE 1225" },
|
||||
{ 0x1524, 0x1410, "yenta_socket", "ENE 1410" },
|
||||
{ 0x1524, 0x1420, "yenta_socket", "ENE 1420" },
|
||||
};
|
||||
#define PCI_COUNT (sizeof(pci_id)/sizeof(pci_id_t))
|
||||
|
||||
static char * pci_probe()
|
||||
{
|
||||
char s[256], *modname = NULL;
|
||||
u_int device, vendor, i;
|
||||
FILE *f;
|
||||
|
||||
if ((f = fopen("/proc/bus/pci/devices", "r")) != NULL) {
|
||||
while (fgets(s, 256, f) != NULL) {
|
||||
u_int n = strtoul(s+5, NULL, 16);
|
||||
vendor = (n >> 16); device = (n & 0xffff);
|
||||
for (i = 0; i < PCI_COUNT; i++)
|
||||
if ((vendor == pci_id[i].vendor) &&
|
||||
(device == pci_id[i].device)) break;
|
||||
|
||||
if (i < PCI_COUNT) {
|
||||
modname = pci_id[i].modname;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return modname;
|
||||
}
|
||||
|
||||
/*====================================================================*/
|
||||
|
||||
#ifndef __alpha__
|
||||
typedef u_short ioaddr_t;
|
||||
|
||||
static ioaddr_t i365_base = 0x03e0;
|
||||
|
||||
static u_char i365_get(u_short sock, u_short reg)
|
||||
{
|
||||
u_char val = I365_REG(sock, reg);
|
||||
outb(val, i365_base); val = inb(i365_base+1);
|
||||
return val;
|
||||
}
|
||||
|
||||
#if 0 // the following code do nothing usefull, it ends with return 0 anyway
|
||||
|
||||
static void i365_set(u_short sock, u_short reg, u_char data)
|
||||
{
|
||||
u_char val = I365_REG(sock, reg);
|
||||
outb(val, i365_base); outb(data, i365_base+1);
|
||||
}
|
||||
|
||||
static void i365_bset(u_short sock, u_short reg, u_char mask)
|
||||
{
|
||||
u_char d = i365_get(sock, reg);
|
||||
d |= mask;
|
||||
i365_set(sock, reg, d);
|
||||
}
|
||||
|
||||
static void i365_bclr(u_short sock, u_short reg, u_char mask)
|
||||
{
|
||||
u_char d = i365_get(sock, reg);
|
||||
d &= ~mask;
|
||||
i365_set(sock, reg, d);
|
||||
}
|
||||
#endif
|
||||
|
||||
int i365_probe()
|
||||
{
|
||||
int val, slot, sock, done;
|
||||
// char *name = "i82365sl";
|
||||
|
||||
ioperm(i365_base, 4, 1);
|
||||
ioperm(0x80, 1, 1);
|
||||
for (slot = 0; slot < 2; slot++) {
|
||||
for (sock = done = 0; sock < 2; sock++) {
|
||||
val = i365_get(sock, I365_IDENT);
|
||||
switch (val) {
|
||||
case 0x82:
|
||||
// name = "i82365sl A step";
|
||||
// break;
|
||||
case 0x83:
|
||||
// name = "i82365sl B step";
|
||||
// break;
|
||||
case 0x84:
|
||||
// name = "VLSI 82C146";
|
||||
// break;
|
||||
case 0x88: case 0x89: case 0x8a:
|
||||
// name = "IBM Clone";
|
||||
// break;
|
||||
case 0x8b: case 0x8c:
|
||||
break;
|
||||
default:
|
||||
done = 1;
|
||||
}
|
||||
if (done) break;
|
||||
}
|
||||
if (done && sock) break;
|
||||
i365_base += 2;
|
||||
}
|
||||
|
||||
if (sock == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 0 // the following code do nothing usefull, it ends with return 0 anyway
|
||||
if ((sock == 2) && (strcmp(name, "VLSI 82C146") == 0))
|
||||
name = "i82365sl DF";
|
||||
|
||||
/* Check for Vadem chips */
|
||||
outb(0x0e, i365_base);
|
||||
outb(0x37, i365_base);
|
||||
i365_bset(0, VG468_MISC, VG468_MISC_VADEMREV);
|
||||
val = i365_get(0, I365_IDENT);
|
||||
if (val & I365_IDENT_VADEM) {
|
||||
if ((val & 7) < 4)
|
||||
name = "Vadem VG-468";
|
||||
else
|
||||
name = "Vadem VG-469";
|
||||
i365_bclr(0, VG468_MISC, VG468_MISC_VADEMREV);
|
||||
}
|
||||
|
||||
/* Check for Cirrus CL-PD67xx chips */
|
||||
i365_set(0, PD67_CHIP_INFO, 0);
|
||||
val = i365_get(0, PD67_CHIP_INFO);
|
||||
if ((val & PD67_INFO_CHIP_ID) == PD67_INFO_CHIP_ID) {
|
||||
val = i365_get(0, PD67_CHIP_INFO);
|
||||
if ((val & PD67_INFO_CHIP_ID) == 0) {
|
||||
if (val & PD67_INFO_SLOTS)
|
||||
name = "Cirrus CL-PD672x";
|
||||
else {
|
||||
name = "Cirrus CL-PD6710";
|
||||
sock = 1;
|
||||
}
|
||||
i365_set(0, PD67_EXT_INDEX, 0xe5);
|
||||
if (i365_get(0, PD67_EXT_INDEX) != 0xe5)
|
||||
name = "VIA VT83C469";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
} /* i365_probe */
|
||||
#endif
|
||||
|
||||
/*====================================================================*/
|
||||
|
||||
#ifndef __alpha__
|
||||
static u_short tcic_getw(ioaddr_t base, u_char reg)
|
||||
{
|
||||
u_short val = inw(base+reg);
|
||||
return val;
|
||||
}
|
||||
|
||||
static void tcic_setw(ioaddr_t base, u_char reg, u_short data)
|
||||
{
|
||||
outw(data, base+reg);
|
||||
}
|
||||
|
||||
int tcic_probe_at(ioaddr_t base)
|
||||
{
|
||||
int i;
|
||||
u_short old;
|
||||
|
||||
/* Anything there?? */
|
||||
for (i = 0; i < 0x10; i += 2)
|
||||
if (tcic_getw(base, i) == 0xffff)
|
||||
return -1;
|
||||
|
||||
/* Try to reset the chip */
|
||||
tcic_setw(base, TCIC_SCTRL, TCIC_SCTRL_RESET);
|
||||
tcic_setw(base, TCIC_SCTRL, 0);
|
||||
|
||||
/* Can we set the addr register? */
|
||||
old = tcic_getw(base, TCIC_ADDR);
|
||||
tcic_setw(base, TCIC_ADDR, 0);
|
||||
if (tcic_getw(base, TCIC_ADDR) != 0) {
|
||||
tcic_setw(base, TCIC_ADDR, old);
|
||||
return -2;
|
||||
}
|
||||
|
||||
tcic_setw(base, TCIC_ADDR, 0xc3a5);
|
||||
if (tcic_getw(base, TCIC_ADDR) != 0xc3a5)
|
||||
return -3;
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
int tcic_probe(ioaddr_t base)
|
||||
{
|
||||
int sock;
|
||||
|
||||
ioperm(base, 16, 1);
|
||||
ioperm(0x80, 1, 1);
|
||||
sock = tcic_probe_at(base);
|
||||
|
||||
if (sock <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
} /* tcic_probe */
|
||||
#endif
|
||||
|
||||
/*====================================================================*/
|
||||
char * initialize_pcmcia (void)
|
||||
{
|
||||
#ifndef __alpha__
|
||||
ioaddr_t tcic_base = TCIC_BASE;
|
||||
#endif
|
||||
char* pcmcia;
|
||||
|
||||
if ((pcmcia = pci_probe()))
|
||||
return pcmcia; /* we're all done */
|
||||
#ifndef __alpha__
|
||||
else if (i365_probe() == 0)
|
||||
return "i82365";
|
||||
else if (tcic_probe(tcic_base) == 0)
|
||||
return "tcic";
|
||||
#endif
|
||||
else {
|
||||
/* Detect ISAPNP based i82365 controllers */
|
||||
FILE *f;
|
||||
modprobe("i82365");
|
||||
if ((f = fopen("/proc/bus/pccard/00/info", "r"))) {
|
||||
fclose(f);
|
||||
return "i82365";
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,64 +1,64 @@
|
||||
#!/bin/sh
|
||||
OLDDIR=`pwd`
|
||||
cd /lib/modules/*/kernel/drivers/scsi
|
||||
/bin/modprobe scsi_mod.o.gz > /dev/null 2>&1
|
||||
/bin/modprobe sd_mod.o.gz > /dev/null 2>&1
|
||||
/bin/modprobe sr_mod.o.gz > /dev/null 2>&1
|
||||
/bin/modprobe sg.o.gz > /dev/null 2>&1
|
||||
/bin/modprobe libata.o.gz > /dev/null 2>&1
|
||||
echo "Trying cpqarray";
|
||||
if /bin/modprobe cpqarray > /dev/null 2>&1; then
|
||||
echo "cpqarray.o.gz" > /scsidriver;
|
||||
exit 0;
|
||||
fi
|
||||
echo "Trying cciss";
|
||||
if /bin/modprobe cciss > /dev/null 2>&1; then
|
||||
echo "cciss.o.gz" > /scsidriver;
|
||||
exit 0;
|
||||
fi
|
||||
echo "Trying DAC960";
|
||||
if /bin/modprobe DAC960 > /dev/null 2>&1; then
|
||||
echo "DAC960.o.gz" > /scsidriver;
|
||||
exit 0;
|
||||
fi
|
||||
/bin/modprobe ataraid.o.gz > /dev/null 2>&1
|
||||
echo "Trying medley";
|
||||
if /bin/modprobe medley > /dev/null 2>&1; then
|
||||
echo "medley.o.gz" > /scsidriver;
|
||||
exit 0;
|
||||
fi
|
||||
echo "Trying hptraid";
|
||||
if /bin/modprobe hptraid > /dev/null 2>&1; then
|
||||
echo "hptraid.o.gz" > /scsidriver;
|
||||
exit 0;
|
||||
fi
|
||||
echo "Trying pdcraid";
|
||||
if /bin/modprobe pdcraid > /dev/null 2>&1; then
|
||||
echo "pdcraid.o.gz" > /scsidriver;
|
||||
exit 0;
|
||||
fi
|
||||
echo "Trying silraid";
|
||||
if /bin/modprobe silraid > /dev/null 2>&1; then
|
||||
echo "silraid.o.gz" > /scsidriver;
|
||||
exit 0;
|
||||
fi
|
||||
for i in * message/fusion/mptscsih.o.gz ;
|
||||
do
|
||||
# Skip the generic scsi modules and ancillary support modules
|
||||
# Added eata_dma to skip list because it crashes some machines. Probe last.
|
||||
if [ $i != "scsi_mod.o.gz" -a $i != "sd_mod.o.gz" -a $i != "sg.o.gz" -a $i != "sr_mod.o.gz" -a $i != "53c700.o.gz" -a $i != "NCR53C9x.o.gz" -a $i != "eata_dma.o.gz" -a $i != "libata.o.gz" ]; then
|
||||
DRIVER=`echo $i | sed 's/.o.gz//'`
|
||||
echo "Trying $DRIVER";
|
||||
if /bin/modprobe $DRIVER > /dev/null 2>&1; then
|
||||
echo $i > /scsidriver;
|
||||
/bin/cat /proc/scsi/scsi;
|
||||
exit 0;
|
||||
fi;
|
||||
fi;
|
||||
done
|
||||
echo "Trying eata_dma";
|
||||
if /bin/modprobe eata_dma > /dev/null 2>&1; then
|
||||
echo "eata_dma.o.gz" > /scsidriver;
|
||||
exit 0;
|
||||
fi
|
||||
cd $OLDDIR
|
||||
#!/bin/sh
|
||||
OLDDIR=`pwd`
|
||||
cd /lib/modules/*/kernel/drivers/scsi
|
||||
/bin/modprobe scsi_mod.o.gz > /dev/null 2>&1
|
||||
/bin/modprobe sd_mod.o.gz > /dev/null 2>&1
|
||||
/bin/modprobe sr_mod.o.gz > /dev/null 2>&1
|
||||
/bin/modprobe sg.o.gz > /dev/null 2>&1
|
||||
/bin/modprobe libata.o.gz > /dev/null 2>&1
|
||||
echo "Trying cpqarray";
|
||||
if /bin/modprobe cpqarray > /dev/null 2>&1; then
|
||||
echo "cpqarray.o.gz" > /scsidriver;
|
||||
exit 0;
|
||||
fi
|
||||
echo "Trying cciss";
|
||||
if /bin/modprobe cciss > /dev/null 2>&1; then
|
||||
echo "cciss.o.gz" > /scsidriver;
|
||||
exit 0;
|
||||
fi
|
||||
echo "Trying DAC960";
|
||||
if /bin/modprobe DAC960 > /dev/null 2>&1; then
|
||||
echo "DAC960.o.gz" > /scsidriver;
|
||||
exit 0;
|
||||
fi
|
||||
/bin/modprobe ataraid.o.gz > /dev/null 2>&1
|
||||
echo "Trying medley";
|
||||
if /bin/modprobe medley > /dev/null 2>&1; then
|
||||
echo "medley.o.gz" > /scsidriver;
|
||||
exit 0;
|
||||
fi
|
||||
echo "Trying hptraid";
|
||||
if /bin/modprobe hptraid > /dev/null 2>&1; then
|
||||
echo "hptraid.o.gz" > /scsidriver;
|
||||
exit 0;
|
||||
fi
|
||||
echo "Trying pdcraid";
|
||||
if /bin/modprobe pdcraid > /dev/null 2>&1; then
|
||||
echo "pdcraid.o.gz" > /scsidriver;
|
||||
exit 0;
|
||||
fi
|
||||
echo "Trying silraid";
|
||||
if /bin/modprobe silraid > /dev/null 2>&1; then
|
||||
echo "silraid.o.gz" > /scsidriver;
|
||||
exit 0;
|
||||
fi
|
||||
for i in * message/fusion/mptscsih.o.gz ;
|
||||
do
|
||||
# Skip the generic scsi modules and ancillary support modules
|
||||
# Added eata_dma to skip list because it crashes some machines. Probe last.
|
||||
if [ $i != "scsi_mod.o.gz" -a $i != "sd_mod.o.gz" -a $i != "sg.o.gz" -a $i != "sr_mod.o.gz" -a $i != "53c700.o.gz" -a $i != "NCR53C9x.o.gz" -a $i != "eata_dma.o.gz" -a $i != "libata.o.gz" ]; then
|
||||
DRIVER=`echo $i | sed 's/.o.gz//'`
|
||||
echo "Trying $DRIVER";
|
||||
if /bin/modprobe $DRIVER > /dev/null 2>&1; then
|
||||
echo $i > /scsidriver;
|
||||
/bin/cat /proc/scsi/scsi;
|
||||
exit 0;
|
||||
fi;
|
||||
fi;
|
||||
done
|
||||
echo "Trying eata_dma";
|
||||
if /bin/modprobe eata_dma > /dev/null 2>&1; then
|
||||
echo "eata_dma.o.gz" > /scsidriver;
|
||||
exit 0;
|
||||
fi
|
||||
cd $OLDDIR
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
/* IPCop install program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Alan Hourihane, 2003 <alanh@fairlite.demon.co.uk>
|
||||
*
|
||||
* $Id: scsi.c
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
|
||||
int
|
||||
try_scsi(char *disk_device)
|
||||
{
|
||||
int fd;
|
||||
char dev[10];
|
||||
|
||||
sprintf(dev, "/dev/%s", disk_device);
|
||||
|
||||
if ((fd = open(dev, O_RDONLY)) < 0)
|
||||
return 0;
|
||||
|
||||
close(fd);
|
||||
// remove usb scsi
|
||||
return ( checkusb(disk_device) ? 0:1 );
|
||||
}
|
||||
/* IPCop install program.
|
||||
*
|
||||
* This program is distributed under the terms of the GNU General Public
|
||||
* Licence. See the file COPYING for details.
|
||||
*
|
||||
* (c) Alan Hourihane, 2003 <alanh@fairlite.demon.co.uk>
|
||||
*
|
||||
* $Id: scsi.c
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
|
||||
int
|
||||
try_scsi(char *disk_device)
|
||||
{
|
||||
int fd;
|
||||
char dev[10];
|
||||
|
||||
sprintf(dev, "/dev/%s", disk_device);
|
||||
|
||||
if ((fd = open(dev, O_RDONLY)) < 0)
|
||||
return 0;
|
||||
|
||||
close(fd);
|
||||
// remove usb scsi
|
||||
return ( checkusb(disk_device) ? 0:1 );
|
||||
}
|
||||
|
||||
@@ -1,340 +1,340 @@
|
||||
/*
|
||||
* This file is part of the IPCop Firewall.
|
||||
*
|
||||
* IPCop 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.
|
||||
*
|
||||
* IPCop 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 IPCop; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Copyright 2002: Mark Wormgoor <mark@wormgoor.com>
|
||||
*
|
||||
* $Id: upgrade-v12-v13.c,v 1.2.2.3 2004/11/11 09:39:25 alanh Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
|
||||
void _convert_ppp_settings() {
|
||||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
char filename[STRING_SIZE];
|
||||
|
||||
dirp = opendir( "/harddisk/var/ipcop/ppp" );
|
||||
while ( (dp = readdir( dirp )) != NULL ) {
|
||||
if ( strstr( dp->d_name, "settings" ) == dp->d_name ) {
|
||||
snprintf (filename, STRING_SIZE-1, "%s/%s",
|
||||
"/harddisk/var/ipcop/ppp", dp->d_name);
|
||||
|
||||
/* reduce furthur replacements from commands below */
|
||||
replace (filename, "TYPE=modem", "");
|
||||
replace (filename, "COMPORT=ttyS0", "TYPE=modem\nCOMPORT=ttyS0");
|
||||
replace (filename, "COMPORT=ttyS1", "TYPE=modem\nCOMPORT=ttyS1");
|
||||
replace (filename, "COMPORT=ttyS2", "TYPE=modem\nCOMPORT=ttyS2");
|
||||
replace (filename, "COMPORT=ttyS3", "TYPE=modem\nCOMPORT=ttyS3");
|
||||
/* reduce furthur replacements from commands below */
|
||||
replace (filename, "TYPE=isdn", "");
|
||||
replace (filename, "COMPORT=isdn1", "TYPE=isdn\nCOMPORT=isdn1");
|
||||
replace (filename, "COMPORT=isdn2", "TYPE=isdn\nCOMPORT=isdn2");
|
||||
replace (filename, "COMPORT=pppoe", "TYPE=pppoe");
|
||||
replace (filename, "COMPORT=pptp", "TYPE=pptp");
|
||||
replace (filename, "COMPORT=usbadsl", "TYPE=alcatelusb");
|
||||
replace (filename, "COMPORT=pppoa", "TYPE=pulsardsl");
|
||||
|
||||
chown (filename, 99, 99);
|
||||
}
|
||||
}
|
||||
(void) closedir( dirp );
|
||||
}
|
||||
|
||||
int _convert_xtaccess() {
|
||||
int count=1, count2=0;
|
||||
FILE *portfw1, *portfw2;
|
||||
char portsrctemp[STRING_SIZE], portdsttemp[STRING_SIZE];
|
||||
char *portproto, *portsrcip, *portsrcport, *portdstip, *portdstport, *portenabled, *portremip;
|
||||
|
||||
FILE *xtaccess1, *xtaccess2;
|
||||
char xtsrctemp[STRING_SIZE], xtdsttemp[STRING_SIZE];
|
||||
char *xtproto, *xtsrcip, *xtdstip, *xtdstport, *xtenabled;
|
||||
|
||||
if (!(portfw1 = fopen ("/harddisk/var/ipcop/portfw/config", "r"))) return 1;
|
||||
if (!(portfw2 = fopen ("/harddisk/var/ipcop/portfw/config.new", "w")))
|
||||
{
|
||||
fclose(portfw1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (fgets (portsrctemp, STRING_SIZE, portfw1) != NULL) {
|
||||
count2 = 0;
|
||||
portproto = NULL;
|
||||
portsrcip = NULL;
|
||||
portsrcport = NULL;
|
||||
portdstip = NULL;
|
||||
portdstport = NULL;
|
||||
portremip = NULL;
|
||||
portenabled = NULL;
|
||||
|
||||
if (!(xtaccess1 = fopen ("/harddisk/var/ipcop/xtaccess/config", "r")))
|
||||
{
|
||||
fclose(portfw1);
|
||||
fclose(portfw2);
|
||||
return 1;
|
||||
}
|
||||
if (!(xtaccess2 = fopen ("/harddisk/var/ipcop/xtaccess/config.new", "w")))
|
||||
{
|
||||
fclose(portfw1);
|
||||
fclose(portfw2);
|
||||
fclose(xtaccess1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (isdigit (portsrctemp[0])) {
|
||||
/* Already converted to new format */
|
||||
fputs(portsrctemp, portfw2);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (portsrctemp[strlen(portsrctemp) - 1] == '\n')
|
||||
portsrctemp[strlen(portsrctemp) - 1] = '\0';
|
||||
portproto = strtok (portsrctemp, ",");
|
||||
portsrcport = strtok (NULL, ",");
|
||||
portdstip = strtok (NULL, ",");
|
||||
portdstport = strtok (NULL, ",");
|
||||
portenabled = strtok (NULL, ",");
|
||||
portsrcip = strtok (NULL, ",");
|
||||
portremip = strtok (NULL, ",");
|
||||
if (!(portproto && portsrcport && portdstip &&
|
||||
portdstport && portenabled ))
|
||||
continue;
|
||||
|
||||
if (portsrcip == NULL) portsrcip = strdup ("0.0.0.0");
|
||||
|
||||
while (fgets (xtsrctemp, STRING_SIZE, xtaccess1)) {
|
||||
xtproto = NULL;
|
||||
xtsrcip = NULL;
|
||||
xtdstip = NULL;
|
||||
xtdstport = NULL;
|
||||
xtenabled = NULL;
|
||||
|
||||
if (xtsrctemp[strlen(xtsrctemp) - 1] == '\n')
|
||||
xtsrctemp[strlen(xtsrctemp) - 1] = '\0';
|
||||
xtproto = strtok (xtsrctemp, ",");
|
||||
xtsrcip = strtok (NULL, ",");
|
||||
xtdstport = strtok (NULL, ",");
|
||||
xtenabled = strtok (NULL, ",");
|
||||
xtdstip = strtok (NULL, ",");
|
||||
if (!(xtproto && xtsrcip && xtdstport && xtenabled)) continue;
|
||||
|
||||
if (xtdstip == NULL) xtdstip = strdup ("0.0.0.0");
|
||||
|
||||
if (strcmp (portproto, xtproto) == 0 &&
|
||||
strcmp (portsrcport, xtdstport) == 0 &&
|
||||
strcmp (portsrcip, xtdstip) == 0) {
|
||||
portremip = strdup (xtsrcip);
|
||||
if ((strcmp (portremip, "0.0.0.0/0") == 0) && (count2 == 0)) {
|
||||
sprintf (portdsttemp, "%d,%d,%s,%s,%s,%s,%s,%s,%s\n",
|
||||
count, count2, portproto, portsrcport, portdstip,
|
||||
portdstport, portenabled, portsrcip, portremip);
|
||||
fputs(portdsttemp, portfw2);
|
||||
} else {
|
||||
if (count2 == 0) {
|
||||
sprintf (portdsttemp, "%d,%d,%s,%s,%s,%s,%s,%s,%d\n",
|
||||
count,count2,portproto, portsrcport, portdstip,
|
||||
portdstport, portenabled, portsrcip, 0);
|
||||
fputs(portdsttemp, portfw2);
|
||||
count2++;
|
||||
}
|
||||
sprintf (portdsttemp, "%d,%d,%s,%d,%s,%s,%s,%d,%s\n",
|
||||
count,count2,portproto, 0, portdstip,
|
||||
portdstport, portenabled, 0, portremip);
|
||||
fputs(portdsttemp, portfw2);
|
||||
}
|
||||
count2++;
|
||||
} else {
|
||||
sprintf (xtdsttemp, "%s,%s,%s,%s,%s\n",
|
||||
xtproto, xtsrcip, xtdstport, xtenabled, xtdstip);
|
||||
fputs(xtdsttemp, xtaccess2);
|
||||
}
|
||||
}
|
||||
|
||||
/* Close source and destination xtaccess files */
|
||||
fclose (xtaccess1);
|
||||
fclose (xtaccess2);
|
||||
|
||||
/* Move the new xtaccess file */
|
||||
rename ("/harddisk/var/ipcop/xtaccess/config.new",
|
||||
"/harddisk/var/ipcop/xtaccess/config");
|
||||
|
||||
/* If no external access line existed, add a no access line */
|
||||
if (count2 == 0) {
|
||||
if (portremip == NULL) portremip = strdup ("127.0.0.1/32");
|
||||
|
||||
/* Print new port forwarding line to file */
|
||||
sprintf (portdsttemp, "%d,%d,%s,%s,%s,%s,%s,%s,%s\n",
|
||||
count, count2, portproto, portsrcport, portdstip,
|
||||
portdstport, portenabled, portsrcip, portremip);
|
||||
fputs(portdsttemp, portfw2);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
||||
/* Close source and destination portfw files */
|
||||
fclose (portfw1);
|
||||
fclose (portfw2);
|
||||
|
||||
/* Move the new portfw file */
|
||||
rename ("/harddisk/var/ipcop/portfw/config.new",
|
||||
"/harddisk/var/ipcop/portfw/config");
|
||||
chown ("/harddisk/var/ipcop/xtaccess/config", 99, 99);
|
||||
chown ("/harddisk/var/ipcop/portfw/config", 99, 99);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _convert_pulsardsl() {
|
||||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
char filename[STRING_SIZE];
|
||||
FILE *settings, *pulsardsl;
|
||||
char line[STRING_SIZE];
|
||||
|
||||
if (!(pulsardsl = fopen ("/harddisk/var/ipcop/pciadsl/settings", "r"))) return 1;
|
||||
|
||||
dirp = opendir( "/harddisk/var/ipcop/ppp" );
|
||||
while ( (dp = readdir( dirp )) != NULL ) {
|
||||
if ( strstr( dp->d_name, "settings" ) == dp->d_name ) {
|
||||
snprintf (filename, STRING_SIZE-1, "%s/%s",
|
||||
"/harddisk/var/ipcop/ppp", dp->d_name);
|
||||
if (!(settings = fopen (filename, "r+"))) {
|
||||
closedir(dirp);
|
||||
fclose(pulsardsl);
|
||||
return 1;
|
||||
}
|
||||
while (fgets (line, STRING_SIZE, settings) != NULL) {
|
||||
if (strstr (line, "TYPE=pulsardsl") == line) {
|
||||
fseek(settings,0,SEEK_END);
|
||||
rewind(pulsardsl);
|
||||
while (fgets(line, STRING_SIZE, pulsardsl) != NULL) {
|
||||
fputs (line, settings);
|
||||
}
|
||||
fclose (settings);
|
||||
chown (filename, 99, 99);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(pulsardsl);
|
||||
(void) closedir( dirp );
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _convert_pulsardsl_ethernet() {
|
||||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
FILE *ethernet, *settings;
|
||||
char line[STRING_SIZE];
|
||||
char type[STRING_SIZE];
|
||||
char ip[STRING_SIZE];
|
||||
char filename[STRING_SIZE];
|
||||
|
||||
if (!(ethernet = fopen ("/harddisk/var/ipcop/ethernet/settings", "r"))) return 1;
|
||||
|
||||
while (fgets (line, STRING_SIZE, ethernet) != NULL) {
|
||||
if (strstr (line, "RED_DRIVER=pciadsl") == line) {
|
||||
rewind (ethernet);
|
||||
while (fgets (line, STRING_SIZE, ethernet) != NULL) {
|
||||
if (strstr (line, "RED_TYPE") == line) {
|
||||
strcpy (type, line + 9*sizeof(char));
|
||||
if (type[strlen(type) - 1] == '\n')
|
||||
type[strlen(type) - 1] = '\0';
|
||||
}
|
||||
if (strstr (line, "RED_ADDRESS") == line) {
|
||||
strcpy (ip, line + 12*sizeof(char));
|
||||
if (ip[strlen(ip) - 1] == '\n')
|
||||
type[strlen(ip) - 1] = '\0';
|
||||
}
|
||||
fclose (ethernet);
|
||||
|
||||
replace ("/harddisk/var/ipcop/ethernet/settings", "RED_DEV=eth1", "RED_DEV=");
|
||||
replace ("/harddisk/var/ipcop/ethernet/settings", "CONFIG_TYPE=2", "CONFIG_TYPE=0");
|
||||
replace ("/harddisk/var/ipcop/ethernet/settings", "CONFIG_TYPE=3", "CONFIG_TYPE=1");
|
||||
replace ("/harddisk/var/ipcop/ethernet/settings", "RED_DEV=eth2", "RED_DEV=");
|
||||
chown ("/harddisk/var/ipcop/ethernet/settings", 99, 99);
|
||||
|
||||
dirp = opendir( "/harddisk/var/ipcop/ppp" );
|
||||
while ( (dp = readdir( dirp )) != NULL ) {
|
||||
if ( strstr( dp->d_name, "settings-" ) == dp->d_name ) {
|
||||
snprintf (filename, STRING_SIZE-1, "%s/%s",
|
||||
"/harddisk/var/ipcop/ppp", dp->d_name);
|
||||
if (!(settings = fopen (filename, "r+")))
|
||||
{
|
||||
closedir(dirp);
|
||||
return 1;
|
||||
}
|
||||
while (fgets (line, STRING_SIZE, settings) != NULL) {
|
||||
if (strstr (line, "TYPE=pulsardsl") == line) {
|
||||
fseek(settings,0,SEEK_END);
|
||||
fprintf (settings, "METHOD=%s\n", type);
|
||||
fprintf (settings, "IP=%s\n", ip);
|
||||
fclose (settings);
|
||||
chown (filename, 99, 99);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(void) closedir( dirp );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int upgrade_v12_v13() {
|
||||
struct stat s;
|
||||
replace ("/harddisk/var/ipcop/ethernet/settings", "rtl8139", "8139too");
|
||||
replace ("/harddisk/var/ipcop/vpn/ipsec.conf", "auto=add", "auto=start");
|
||||
chown ("/harddisk/var/ipcop/vpn/ipsec.conf", 99, 99);
|
||||
chown ("/harddisk/var/ipcop/ethernet/settings", 99, 99);
|
||||
chown ("/harddisk/var/ipcop/main/settings", 99, 99);
|
||||
_convert_ppp_settings();
|
||||
_convert_xtaccess();
|
||||
_convert_pulsardsl();
|
||||
_convert_pulsardsl_ethernet();
|
||||
|
||||
/* Rename usbadsl directory */
|
||||
stat ("/harddisk/var/ipcop/usbadsl", &s);
|
||||
if (S_ISDIR(s.st_mode)) {
|
||||
remove ("/harddisk/var/ipcop/usbadsl/settings");
|
||||
if (! system("/bin/chroot /harddisk /bin/rm -rf /var/ipcop/alcatelusb"))
|
||||
rename ("/harddisk/var/ipcop/usbadsl", "/harddisk/var/ipcop/alcatelusb");
|
||||
}
|
||||
|
||||
/* Rename pciadsl module and directory */
|
||||
remove ("/harddisk/var/ipcop/pulsar/settings");
|
||||
rename ("/harddisk/var/ipcop/pciadsl/pciadsl.o", "/harddisk/var/ipcop/pciadsl/pulsar.o");
|
||||
stat ("/harddisk/var/ipcop/pciadsl", &s);
|
||||
if (S_ISDIR(s.st_mode)) {
|
||||
if (! system("/bin/chroot /harddisk /bin/rm -rf /var/ipcop/pulsardsl"))
|
||||
rename ("/harddisk/var/ipcop/pciadsl", "/harddisk/var/ipcop/pulsardsl");
|
||||
}
|
||||
|
||||
/* Change squid cache directory */
|
||||
replace ("/harddisk/var/ipcop/proxy/squid.conf", "/var/spool/squid", "/var/log/cache");
|
||||
chown ("/harddisk/var/ipcop/proxy/squid.conf", 99, 99);
|
||||
|
||||
/* Change setup user shell */
|
||||
replace ("/harddisk/etc/passwd", ":/usr/local/sbin/setup", ":/bin/bash -c /usr/local/sbin/setup");
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* This file is part of the IPCop Firewall.
|
||||
*
|
||||
* IPCop 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.
|
||||
*
|
||||
* IPCop 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 IPCop; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Copyright 2002: Mark Wormgoor <mark@wormgoor.com>
|
||||
*
|
||||
* $Id: upgrade-v12-v13.c,v 1.2.2.3 2004/11/11 09:39:25 alanh Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
|
||||
void _convert_ppp_settings() {
|
||||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
char filename[STRING_SIZE];
|
||||
|
||||
dirp = opendir( "/harddisk/var/ipcop/ppp" );
|
||||
while ( (dp = readdir( dirp )) != NULL ) {
|
||||
if ( strstr( dp->d_name, "settings" ) == dp->d_name ) {
|
||||
snprintf (filename, STRING_SIZE-1, "%s/%s",
|
||||
"/harddisk/var/ipcop/ppp", dp->d_name);
|
||||
|
||||
/* reduce furthur replacements from commands below */
|
||||
replace (filename, "TYPE=modem", "");
|
||||
replace (filename, "COMPORT=ttyS0", "TYPE=modem\nCOMPORT=ttyS0");
|
||||
replace (filename, "COMPORT=ttyS1", "TYPE=modem\nCOMPORT=ttyS1");
|
||||
replace (filename, "COMPORT=ttyS2", "TYPE=modem\nCOMPORT=ttyS2");
|
||||
replace (filename, "COMPORT=ttyS3", "TYPE=modem\nCOMPORT=ttyS3");
|
||||
/* reduce furthur replacements from commands below */
|
||||
replace (filename, "TYPE=isdn", "");
|
||||
replace (filename, "COMPORT=isdn1", "TYPE=isdn\nCOMPORT=isdn1");
|
||||
replace (filename, "COMPORT=isdn2", "TYPE=isdn\nCOMPORT=isdn2");
|
||||
replace (filename, "COMPORT=pppoe", "TYPE=pppoe");
|
||||
replace (filename, "COMPORT=pptp", "TYPE=pptp");
|
||||
replace (filename, "COMPORT=usbadsl", "TYPE=alcatelusb");
|
||||
replace (filename, "COMPORT=pppoa", "TYPE=pulsardsl");
|
||||
|
||||
chown (filename, 99, 99);
|
||||
}
|
||||
}
|
||||
(void) closedir( dirp );
|
||||
}
|
||||
|
||||
int _convert_xtaccess() {
|
||||
int count=1, count2=0;
|
||||
FILE *portfw1, *portfw2;
|
||||
char portsrctemp[STRING_SIZE], portdsttemp[STRING_SIZE];
|
||||
char *portproto, *portsrcip, *portsrcport, *portdstip, *portdstport, *portenabled, *portremip;
|
||||
|
||||
FILE *xtaccess1, *xtaccess2;
|
||||
char xtsrctemp[STRING_SIZE], xtdsttemp[STRING_SIZE];
|
||||
char *xtproto, *xtsrcip, *xtdstip, *xtdstport, *xtenabled;
|
||||
|
||||
if (!(portfw1 = fopen ("/harddisk/var/ipcop/portfw/config", "r"))) return 1;
|
||||
if (!(portfw2 = fopen ("/harddisk/var/ipcop/portfw/config.new", "w")))
|
||||
{
|
||||
fclose(portfw1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (fgets (portsrctemp, STRING_SIZE, portfw1) != NULL) {
|
||||
count2 = 0;
|
||||
portproto = NULL;
|
||||
portsrcip = NULL;
|
||||
portsrcport = NULL;
|
||||
portdstip = NULL;
|
||||
portdstport = NULL;
|
||||
portremip = NULL;
|
||||
portenabled = NULL;
|
||||
|
||||
if (!(xtaccess1 = fopen ("/harddisk/var/ipcop/xtaccess/config", "r")))
|
||||
{
|
||||
fclose(portfw1);
|
||||
fclose(portfw2);
|
||||
return 1;
|
||||
}
|
||||
if (!(xtaccess2 = fopen ("/harddisk/var/ipcop/xtaccess/config.new", "w")))
|
||||
{
|
||||
fclose(portfw1);
|
||||
fclose(portfw2);
|
||||
fclose(xtaccess1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (isdigit (portsrctemp[0])) {
|
||||
/* Already converted to new format */
|
||||
fputs(portsrctemp, portfw2);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (portsrctemp[strlen(portsrctemp) - 1] == '\n')
|
||||
portsrctemp[strlen(portsrctemp) - 1] = '\0';
|
||||
portproto = strtok (portsrctemp, ",");
|
||||
portsrcport = strtok (NULL, ",");
|
||||
portdstip = strtok (NULL, ",");
|
||||
portdstport = strtok (NULL, ",");
|
||||
portenabled = strtok (NULL, ",");
|
||||
portsrcip = strtok (NULL, ",");
|
||||
portremip = strtok (NULL, ",");
|
||||
if (!(portproto && portsrcport && portdstip &&
|
||||
portdstport && portenabled ))
|
||||
continue;
|
||||
|
||||
if (portsrcip == NULL) portsrcip = strdup ("0.0.0.0");
|
||||
|
||||
while (fgets (xtsrctemp, STRING_SIZE, xtaccess1)) {
|
||||
xtproto = NULL;
|
||||
xtsrcip = NULL;
|
||||
xtdstip = NULL;
|
||||
xtdstport = NULL;
|
||||
xtenabled = NULL;
|
||||
|
||||
if (xtsrctemp[strlen(xtsrctemp) - 1] == '\n')
|
||||
xtsrctemp[strlen(xtsrctemp) - 1] = '\0';
|
||||
xtproto = strtok (xtsrctemp, ",");
|
||||
xtsrcip = strtok (NULL, ",");
|
||||
xtdstport = strtok (NULL, ",");
|
||||
xtenabled = strtok (NULL, ",");
|
||||
xtdstip = strtok (NULL, ",");
|
||||
if (!(xtproto && xtsrcip && xtdstport && xtenabled)) continue;
|
||||
|
||||
if (xtdstip == NULL) xtdstip = strdup ("0.0.0.0");
|
||||
|
||||
if (strcmp (portproto, xtproto) == 0 &&
|
||||
strcmp (portsrcport, xtdstport) == 0 &&
|
||||
strcmp (portsrcip, xtdstip) == 0) {
|
||||
portremip = strdup (xtsrcip);
|
||||
if ((strcmp (portremip, "0.0.0.0/0") == 0) && (count2 == 0)) {
|
||||
sprintf (portdsttemp, "%d,%d,%s,%s,%s,%s,%s,%s,%s\n",
|
||||
count, count2, portproto, portsrcport, portdstip,
|
||||
portdstport, portenabled, portsrcip, portremip);
|
||||
fputs(portdsttemp, portfw2);
|
||||
} else {
|
||||
if (count2 == 0) {
|
||||
sprintf (portdsttemp, "%d,%d,%s,%s,%s,%s,%s,%s,%d\n",
|
||||
count,count2,portproto, portsrcport, portdstip,
|
||||
portdstport, portenabled, portsrcip, 0);
|
||||
fputs(portdsttemp, portfw2);
|
||||
count2++;
|
||||
}
|
||||
sprintf (portdsttemp, "%d,%d,%s,%d,%s,%s,%s,%d,%s\n",
|
||||
count,count2,portproto, 0, portdstip,
|
||||
portdstport, portenabled, 0, portremip);
|
||||
fputs(portdsttemp, portfw2);
|
||||
}
|
||||
count2++;
|
||||
} else {
|
||||
sprintf (xtdsttemp, "%s,%s,%s,%s,%s\n",
|
||||
xtproto, xtsrcip, xtdstport, xtenabled, xtdstip);
|
||||
fputs(xtdsttemp, xtaccess2);
|
||||
}
|
||||
}
|
||||
|
||||
/* Close source and destination xtaccess files */
|
||||
fclose (xtaccess1);
|
||||
fclose (xtaccess2);
|
||||
|
||||
/* Move the new xtaccess file */
|
||||
rename ("/harddisk/var/ipcop/xtaccess/config.new",
|
||||
"/harddisk/var/ipcop/xtaccess/config");
|
||||
|
||||
/* If no external access line existed, add a no access line */
|
||||
if (count2 == 0) {
|
||||
if (portremip == NULL) portremip = strdup ("127.0.0.1/32");
|
||||
|
||||
/* Print new port forwarding line to file */
|
||||
sprintf (portdsttemp, "%d,%d,%s,%s,%s,%s,%s,%s,%s\n",
|
||||
count, count2, portproto, portsrcport, portdstip,
|
||||
portdstport, portenabled, portsrcip, portremip);
|
||||
fputs(portdsttemp, portfw2);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
||||
/* Close source and destination portfw files */
|
||||
fclose (portfw1);
|
||||
fclose (portfw2);
|
||||
|
||||
/* Move the new portfw file */
|
||||
rename ("/harddisk/var/ipcop/portfw/config.new",
|
||||
"/harddisk/var/ipcop/portfw/config");
|
||||
chown ("/harddisk/var/ipcop/xtaccess/config", 99, 99);
|
||||
chown ("/harddisk/var/ipcop/portfw/config", 99, 99);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _convert_pulsardsl() {
|
||||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
char filename[STRING_SIZE];
|
||||
FILE *settings, *pulsardsl;
|
||||
char line[STRING_SIZE];
|
||||
|
||||
if (!(pulsardsl = fopen ("/harddisk/var/ipcop/pciadsl/settings", "r"))) return 1;
|
||||
|
||||
dirp = opendir( "/harddisk/var/ipcop/ppp" );
|
||||
while ( (dp = readdir( dirp )) != NULL ) {
|
||||
if ( strstr( dp->d_name, "settings" ) == dp->d_name ) {
|
||||
snprintf (filename, STRING_SIZE-1, "%s/%s",
|
||||
"/harddisk/var/ipcop/ppp", dp->d_name);
|
||||
if (!(settings = fopen (filename, "r+"))) {
|
||||
closedir(dirp);
|
||||
fclose(pulsardsl);
|
||||
return 1;
|
||||
}
|
||||
while (fgets (line, STRING_SIZE, settings) != NULL) {
|
||||
if (strstr (line, "TYPE=pulsardsl") == line) {
|
||||
fseek(settings,0,SEEK_END);
|
||||
rewind(pulsardsl);
|
||||
while (fgets(line, STRING_SIZE, pulsardsl) != NULL) {
|
||||
fputs (line, settings);
|
||||
}
|
||||
fclose (settings);
|
||||
chown (filename, 99, 99);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(pulsardsl);
|
||||
(void) closedir( dirp );
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _convert_pulsardsl_ethernet() {
|
||||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
FILE *ethernet, *settings;
|
||||
char line[STRING_SIZE];
|
||||
char type[STRING_SIZE];
|
||||
char ip[STRING_SIZE];
|
||||
char filename[STRING_SIZE];
|
||||
|
||||
if (!(ethernet = fopen ("/harddisk/var/ipcop/ethernet/settings", "r"))) return 1;
|
||||
|
||||
while (fgets (line, STRING_SIZE, ethernet) != NULL) {
|
||||
if (strstr (line, "RED_DRIVER=pciadsl") == line) {
|
||||
rewind (ethernet);
|
||||
while (fgets (line, STRING_SIZE, ethernet) != NULL) {
|
||||
if (strstr (line, "RED_TYPE") == line) {
|
||||
strcpy (type, line + 9*sizeof(char));
|
||||
if (type[strlen(type) - 1] == '\n')
|
||||
type[strlen(type) - 1] = '\0';
|
||||
}
|
||||
if (strstr (line, "RED_ADDRESS") == line) {
|
||||
strcpy (ip, line + 12*sizeof(char));
|
||||
if (ip[strlen(ip) - 1] == '\n')
|
||||
type[strlen(ip) - 1] = '\0';
|
||||
}
|
||||
fclose (ethernet);
|
||||
|
||||
replace ("/harddisk/var/ipcop/ethernet/settings", "RED_DEV=eth1", "RED_DEV=");
|
||||
replace ("/harddisk/var/ipcop/ethernet/settings", "CONFIG_TYPE=2", "CONFIG_TYPE=0");
|
||||
replace ("/harddisk/var/ipcop/ethernet/settings", "CONFIG_TYPE=3", "CONFIG_TYPE=1");
|
||||
replace ("/harddisk/var/ipcop/ethernet/settings", "RED_DEV=eth2", "RED_DEV=");
|
||||
chown ("/harddisk/var/ipcop/ethernet/settings", 99, 99);
|
||||
|
||||
dirp = opendir( "/harddisk/var/ipcop/ppp" );
|
||||
while ( (dp = readdir( dirp )) != NULL ) {
|
||||
if ( strstr( dp->d_name, "settings-" ) == dp->d_name ) {
|
||||
snprintf (filename, STRING_SIZE-1, "%s/%s",
|
||||
"/harddisk/var/ipcop/ppp", dp->d_name);
|
||||
if (!(settings = fopen (filename, "r+")))
|
||||
{
|
||||
closedir(dirp);
|
||||
return 1;
|
||||
}
|
||||
while (fgets (line, STRING_SIZE, settings) != NULL) {
|
||||
if (strstr (line, "TYPE=pulsardsl") == line) {
|
||||
fseek(settings,0,SEEK_END);
|
||||
fprintf (settings, "METHOD=%s\n", type);
|
||||
fprintf (settings, "IP=%s\n", ip);
|
||||
fclose (settings);
|
||||
chown (filename, 99, 99);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(void) closedir( dirp );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int upgrade_v12_v13() {
|
||||
struct stat s;
|
||||
replace ("/harddisk/var/ipcop/ethernet/settings", "rtl8139", "8139too");
|
||||
replace ("/harddisk/var/ipcop/vpn/ipsec.conf", "auto=add", "auto=start");
|
||||
chown ("/harddisk/var/ipcop/vpn/ipsec.conf", 99, 99);
|
||||
chown ("/harddisk/var/ipcop/ethernet/settings", 99, 99);
|
||||
chown ("/harddisk/var/ipcop/main/settings", 99, 99);
|
||||
_convert_ppp_settings();
|
||||
_convert_xtaccess();
|
||||
_convert_pulsardsl();
|
||||
_convert_pulsardsl_ethernet();
|
||||
|
||||
/* Rename usbadsl directory */
|
||||
stat ("/harddisk/var/ipcop/usbadsl", &s);
|
||||
if (S_ISDIR(s.st_mode)) {
|
||||
remove ("/harddisk/var/ipcop/usbadsl/settings");
|
||||
if (! system("/bin/chroot /harddisk /bin/rm -rf /var/ipcop/alcatelusb"))
|
||||
rename ("/harddisk/var/ipcop/usbadsl", "/harddisk/var/ipcop/alcatelusb");
|
||||
}
|
||||
|
||||
/* Rename pciadsl module and directory */
|
||||
remove ("/harddisk/var/ipcop/pulsar/settings");
|
||||
rename ("/harddisk/var/ipcop/pciadsl/pciadsl.o", "/harddisk/var/ipcop/pciadsl/pulsar.o");
|
||||
stat ("/harddisk/var/ipcop/pciadsl", &s);
|
||||
if (S_ISDIR(s.st_mode)) {
|
||||
if (! system("/bin/chroot /harddisk /bin/rm -rf /var/ipcop/pulsardsl"))
|
||||
rename ("/harddisk/var/ipcop/pciadsl", "/harddisk/var/ipcop/pulsardsl");
|
||||
}
|
||||
|
||||
/* Change squid cache directory */
|
||||
replace ("/harddisk/var/ipcop/proxy/squid.conf", "/var/spool/squid", "/var/log/cache");
|
||||
chown ("/harddisk/var/ipcop/proxy/squid.conf", 99, 99);
|
||||
|
||||
/* Change setup user shell */
|
||||
replace ("/harddisk/etc/passwd", ":/usr/local/sbin/setup", ":/bin/bash -c /usr/local/sbin/setup");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,141 +1,141 @@
|
||||
/*
|
||||
* This file is part of the IPCop Firewall.
|
||||
*
|
||||
* IPCop 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.
|
||||
*
|
||||
* IPCop 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 IPCop; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Copyright 2002: Mark Wormgoor <mark@wormgoor.com>
|
||||
*
|
||||
* $Id: usb.c,v 1.9.2.8 2005/12/10 00:18:23 franck78 Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
|
||||
int usbuhci = 0;
|
||||
int usbohci = 0;
|
||||
int ehcihcd = 0;
|
||||
|
||||
int initialize_usb() {
|
||||
modprobe("sd_mod");
|
||||
modprobe("sr_mod");
|
||||
modprobe("usb-storage");
|
||||
|
||||
if (ehcihcd) {
|
||||
rmmod("ehci-hcd");
|
||||
ehcihcd = 0;
|
||||
}
|
||||
if (usbohci) {
|
||||
rmmod("usb-ohci");
|
||||
usbohci = 0;
|
||||
}
|
||||
if (usbuhci) {
|
||||
rmmod("usb-uhci");
|
||||
usbuhci = 0;
|
||||
}
|
||||
|
||||
if (modprobe("ehci-hcd") == 0) ehcihcd = 1;
|
||||
if (modprobe("usb-ohci") == 0) usbohci = 1;
|
||||
if (modprobe("usb-uhci") == 0) usbuhci = 1;
|
||||
|
||||
modprobe("hid");
|
||||
modprobe("keybdev");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int write_usb_modules_conf() {
|
||||
int index = 0;
|
||||
FILE *handle;
|
||||
|
||||
if (!(handle = fopen("/harddisk/etc/modules.conf", "a")))
|
||||
return 0;
|
||||
|
||||
#if 0 /* we don't do this yet, because one of the drivers has a problem
|
||||
* with it */
|
||||
if (ehcihcd) {
|
||||
fprintf(handle,"alias usb-controller");
|
||||
if (index)
|
||||
fprintf(handle,"%d",index);
|
||||
fprintf(handle," ehci-hcd\n");
|
||||
index++;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (usbohci) {
|
||||
fprintf(handle,"alias usb-controller");
|
||||
if (index)
|
||||
fprintf(handle,"%d",index);
|
||||
fprintf(handle," usb-ohci\n");
|
||||
index++;
|
||||
}
|
||||
|
||||
if (usbuhci) {
|
||||
fprintf(handle,"alias usb-controller");
|
||||
if (index)
|
||||
fprintf(handle,"%d",index);
|
||||
fprintf(handle," usb-uhci\n");
|
||||
index++;
|
||||
}
|
||||
fclose(handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* checkusb().
|
||||
Scans the named partitions and returns true if USB-removable.
|
||||
a bug? in "cat /proc/partitions" with superfloppy scheme device
|
||||
make them appearing always with four 'false' partitions:
|
||||
sda and sda1 sda2 sda3 sda4.
|
||||
No easy way to decide if /dev/sda1 exists or not.
|
||||
*/
|
||||
int checkusb(char *partition)
|
||||
{
|
||||
FILE *f = NULL;
|
||||
char filename[STRING_SIZE];
|
||||
char buffer[STRING_SIZE];
|
||||
char *pchar = &buffer[0];
|
||||
if (!(f = fopen("/proc/partitions", "r")))
|
||||
return 0;
|
||||
|
||||
short int major = 0, minor = 0;
|
||||
while (fgets(buffer, STRING_SIZE, f)) {
|
||||
/* look for partition*/
|
||||
if (strstr (buffer, partition)) {
|
||||
major = atoi (buffer);
|
||||
if (major != 8) break ; /* not scsi */
|
||||
//get minor
|
||||
while (*pchar != '8') pchar++;
|
||||
minor = atoi (++pchar);
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
if (major != 8) return 0; /* nothing found */
|
||||
|
||||
//now check for usb-storage-MINOR
|
||||
minor >>= 4; // get index from minor
|
||||
sprintf (filename, "/proc/scsi/usb-storage-%d/%d", minor,minor);
|
||||
|
||||
if (!(f = fopen(filename, "r")))
|
||||
return 0;
|
||||
int count = 0;
|
||||
while (fgets(buffer, STRING_SIZE, f)) {
|
||||
if (strstr(buffer,"usb-storage")) count++;
|
||||
if (strstr(buffer,"SCSI")) count++;
|
||||
if (strstr(buffer,"Attached: Yes")) count++;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
return (count==3 ? 1 : 0);
|
||||
}
|
||||
/*
|
||||
* This file is part of the IPCop Firewall.
|
||||
*
|
||||
* IPCop 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.
|
||||
*
|
||||
* IPCop 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 IPCop; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Copyright 2002: Mark Wormgoor <mark@wormgoor.com>
|
||||
*
|
||||
* $Id: usb.c,v 1.9.2.8 2005/12/10 00:18:23 franck78 Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include "install.h"
|
||||
|
||||
int usbuhci = 0;
|
||||
int usbohci = 0;
|
||||
int ehcihcd = 0;
|
||||
|
||||
int initialize_usb() {
|
||||
modprobe("sd_mod");
|
||||
modprobe("sr_mod");
|
||||
modprobe("usb-storage");
|
||||
|
||||
if (ehcihcd) {
|
||||
rmmod("ehci-hcd");
|
||||
ehcihcd = 0;
|
||||
}
|
||||
if (usbohci) {
|
||||
rmmod("usb-ohci");
|
||||
usbohci = 0;
|
||||
}
|
||||
if (usbuhci) {
|
||||
rmmod("usb-uhci");
|
||||
usbuhci = 0;
|
||||
}
|
||||
|
||||
if (modprobe("ehci-hcd") == 0) ehcihcd = 1;
|
||||
if (modprobe("usb-ohci") == 0) usbohci = 1;
|
||||
if (modprobe("usb-uhci") == 0) usbuhci = 1;
|
||||
|
||||
modprobe("hid");
|
||||
modprobe("keybdev");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int write_usb_modules_conf() {
|
||||
int index = 0;
|
||||
FILE *handle;
|
||||
|
||||
if (!(handle = fopen("/harddisk/etc/modules.conf", "a")))
|
||||
return 0;
|
||||
|
||||
#if 0 /* we don't do this yet, because one of the drivers has a problem
|
||||
* with it */
|
||||
if (ehcihcd) {
|
||||
fprintf(handle,"alias usb-controller");
|
||||
if (index)
|
||||
fprintf(handle,"%d",index);
|
||||
fprintf(handle," ehci-hcd\n");
|
||||
index++;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (usbohci) {
|
||||
fprintf(handle,"alias usb-controller");
|
||||
if (index)
|
||||
fprintf(handle,"%d",index);
|
||||
fprintf(handle," usb-ohci\n");
|
||||
index++;
|
||||
}
|
||||
|
||||
if (usbuhci) {
|
||||
fprintf(handle,"alias usb-controller");
|
||||
if (index)
|
||||
fprintf(handle,"%d",index);
|
||||
fprintf(handle," usb-uhci\n");
|
||||
index++;
|
||||
}
|
||||
fclose(handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* checkusb().
|
||||
Scans the named partitions and returns true if USB-removable.
|
||||
a bug? in "cat /proc/partitions" with superfloppy scheme device
|
||||
make them appearing always with four 'false' partitions:
|
||||
sda and sda1 sda2 sda3 sda4.
|
||||
No easy way to decide if /dev/sda1 exists or not.
|
||||
*/
|
||||
int checkusb(char *partition)
|
||||
{
|
||||
FILE *f = NULL;
|
||||
char filename[STRING_SIZE];
|
||||
char buffer[STRING_SIZE];
|
||||
char *pchar = &buffer[0];
|
||||
if (!(f = fopen("/proc/partitions", "r")))
|
||||
return 0;
|
||||
|
||||
short int major = 0, minor = 0;
|
||||
while (fgets(buffer, STRING_SIZE, f)) {
|
||||
/* look for partition*/
|
||||
if (strstr (buffer, partition)) {
|
||||
major = atoi (buffer);
|
||||
if (major != 8) break ; /* not scsi */
|
||||
//get minor
|
||||
while (*pchar != '8') pchar++;
|
||||
minor = atoi (++pchar);
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
if (major != 8) return 0; /* nothing found */
|
||||
|
||||
//now check for usb-storage-MINOR
|
||||
minor >>= 4; // get index from minor
|
||||
sprintf (filename, "/proc/scsi/usb-storage-%d/%d", minor,minor);
|
||||
|
||||
if (!(f = fopen(filename, "r")))
|
||||
return 0;
|
||||
int count = 0;
|
||||
while (fgets(buffer, STRING_SIZE, f)) {
|
||||
if (strstr(buffer,"usb-storage")) count++;
|
||||
if (strstr(buffer,"SCSI")) count++;
|
||||
if (strstr(buffer,"Attached: Yes")) count++;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
return (count==3 ? 1 : 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user