Daily chess puzzle

Play chess online

my little experience in Information Tecnology.

17 marzo 2006

sgcop - the ipcop porting for Toshiba SGxx Magnia series

SGCop is the IPCop porting for the Toshiba SGxx Magnia computers. When I planned my LAN at home i was looking for an embedded SOHO firewall/router for Internet ADSL sharing. Buying a Toshiba SG30 Magna on ebay was the best choice for me but the Magnia's operative system is far to have the "security" i have in mind so i've decided to install IPCop instead. Installing IPCop on SG30 is hard due to lack of a graphic interface and CD-ROM and besides it's desined for old-computers deployment. This porting is 100% IPCop compatible. On this table you will find the main differences:
Diff. IPCopSGCop
CFLAGS-O2 -mcpu=i386 -march=i386 -pipe -fomit-frame-pointer-O2 -mcpu=i686 -march=pentium3 -pipe -fomit-frame-pointer
Serial ConsoleNoYes
LCD supportNoYes
Install from PendriveNoYes
Installation:
You can install SGCop in several ways.
  1. You can put the SGxx HD on another pc and make an install like IPCop does.
  2. You can temporary add a CD-ROM and/or a graphic card on the SGxx and make an install like IPCop does.
  3. You can use 'syslinux' to make a pendrive bootable from the sgcop ISO and use the serial console from the SGxx.

Install from usb:
First of all you need a serial connection to the SGxx (ex: Windows Hyper Terminal) and a Pendrive with 64MB free.

During SGxx boot enter the BIOS and change the "boot sequence" then select usb device instead of IDE hard disk.

To make the pendrive bootable you need to run some commands in your linux box.

Use cfdisk to make a new partition on the pendrive:

cfdisk /dev/sda

Select only "ext3" or "vfat" file system type only.

mkfs.msdos /dev/sda1

Now mount the pendrive and the iso image:

mkdir /mnt/usb mkdir /mnt/iso
mount -o loop sgcop-1.4.10.i686.iso /mnt/iso
mount -t vfat /dev/sda1 /mnt/usb

Copy the content of the iso image to the pendrive:

cp -ra /mnt/iso/* /mnt/usb

The -r argument specifies a recursive copy including every directory, and the -a preserves as much as possible the structure of the data in the USB. Now you need to copy some files in the folder /boot/isolinux of the mounted pendrive to the root of the pendrive so you can boot from it:

cd /mnt/usb/boot/isolinux
cp vmlinuz /mnt/usb/
cp isntroot.gz /mnt/usb/
cp isolinux.cfg /mnt/usb/syslinux.cfg

finally make the pendrive bootable with the following command:

syslinux -s /dev/usb

If everything was right you can now plug the pendrive in the SGxx and boot.

Installation notes:
If you're running the installation from a serial console beware because you can't redirect on /dev/ttyX (you can't manage virtual consoles)
If you don't need a detailed output during installation use the command "install /dev/null"

If you are running the install from floppy and you want to use a SCSI device remember this: you "must" use a 2.88 MB compatible floppy.

IPCop compatibility:
You can use any add-in/modification made for IPCop but remember that IPCop is compiled to run on a generic "i386".

SGCop theme:
SGCop replaces the original IPCop's theme.
Thanks to Mariane for his "elegant 2005 IPCop theme."
If you want to contact the author email to: schneider.mariane@gmx.de

Downloads:

sgcop-install-1.4.10.i686.iso
sgcop-sources.1.4.10.tar.bz2
md5sum.txt

01 marzo 2006

tR1 WinRar Server Backups (vbscript)

L'utilizzo di WinRar per le operazioni di backup può essere utile anche nell'ambito di un dominio Active Directory al fine di centralizzare tutti i files in un solo punto.

A tale scopo presento qui una variante di tR1 Winrar Backup che consente di fare i backup in remoto di cartelle condivise in rete.

Per prima cosa, non si fa uso in WinRar del parametro '@' ma di un file esterno che contiene le cartelle su cui eseguire i backup.

Lo script accetta alcuni parametri a riga di comando: -C: (Indica un backup completo) -LOG: (indica il file di log) -L: (indica il file di elenco delle cartelle soggette a backup) -P:<Password> (specifica una password da dare a WinRar)


'tR1 WinRar Backup 'Copyright (C) 2005-2006 vittorio benintende <vittorio@lucullo.it> 'This file is distributed under the GPL license ' Option Explicit 'params Const WORK_DIR="c:\backups\install" Const DEST_DIR="c:\backups\data" const ForReading=1 const ForWriting=2 Const ForAppending=8 const SUFF_COMPLETO="completo" CONST SUFF_GIORNALIERO="incrementale" const SUFF_EXT=".rar" Const TEMP=".tmp" const PASSWORD=" -hp" Const FILE_NOT_FOUND="File Not Found" Const MAX_LOG_SIZE=1000000 Const TITLE="tR1 Server Backup" Const VER="1.42" 'files Const DEF_LOG_FILE="backup.log" Const DEF_LIST_FILE="myBackups.txt" 'logging Const SUCCESS =0 Const ERROR =1 Const WARNING=2 Const INFORMATION=4 Const AUDIT_SUCCESS=8 Const AUDIT_FAILURE=16 Const DEF_NUM=5 Const REPLACE_CHAR="+" Const ALT_REPLACE_CHAR="-" Dim f, WshShell, FSO,fListFile,fTemp Dim lngResult Dim strWinRarCmd Dim blCompleto,blWarning,blPassword Dim lngPos,lngCiclo Dim WIN_RAR_CMD, WIN_RAR_CMD2 Dim objArgs Dim strArgs Dim strcurrent, strCurrentCMD Dim aryCampi,aryFiles Dim strLogFile,strListFile Dim strPassword Dim lngLogSize 'network Dim objNet strWinRarCmd=WIN_RAR_CMD2 strLogFile=WORK_DIR & "\" &amp; DEF_LOG_FILE strListFile=WORK_DIR & "\" &amp; DEF_LIST_FILE strPassword="" Set objArgs = WScript.Arguments For lngPos = 0 to objArgs.Count - 1 blPassword=FALSE Select Case UCase(objArgs(lngPos)) Case "-C" strWinRarCmd=WIN_RAR_CMD blCompleto=TRUE End Select If UCase(Left(objArgs(lngPos),5))="-LOG:" Then strLogFile=Right(objArgs(lngPos),Len(objArgs(lngPos))-5) End If If UCase(Left(objArgs(lngPos),3))="-L:" Then strListFile=Right(objArgs(lngPos),Len(objArgs(lngPos))-3) End If If UCase(Left(objArgs(lngPos),3))="-P:" Then strPassword=PASSWORD & Right(objArgs(lngPos),Len(objArgs(lngPos))-3) blPassword=True End If If blPassword Then strArgs=strArgs & " -P:" Else strargs=strArgs & " " &amp; objArgs(lngPos) End If Next 'argomenti WIN_RAR_CMD = """c:\program files\winrar\winrar.exe"" a -ac -ag -dh " & strPASSWORD &amp; " -inul -ibck -ilog" & strLogFile &amp; " -m5 -os -ow -r -t -ts " & DEST_DIR &amp; "\*" & SUFF_COMPLETO &amp; SUFF_EXT & " ""?""" WIN_RAR_CMD2= """c:\program files\winrar\winrar.exe"" a -ac -ao -ag -dh " &amp; strPASSWORD & " -inul -ibck -ilog" &amp; strLogFile & " -m5 -os -ow -r -t -ts " &amp; DEST_DIR & "\*" &amp; SUFF_GIORNALIERO & SUFF_EXT &amp; " ""?""" If blCompleto Then strWinRarCmd=WIN_RAR_CMD Else strWinRarCmd=WIN_RAR_CMD2 End If blWarning=FALSE Set WshShell = WScript.CreateObject( "WScript.Shell" ) Set FSO = CreateObject("Scripting.FileSystemObject") If Trim(strArgs)="" Then strArgs ="no" WshShell.LogEvent INFORMATION, TITLE & " starting with " &amp; strArgs & " options." 'prendiamo le dimensioni del log On Error Resume Next Set f = fso.getfile(strLogFile) lnglogsize=CLng(f.Size) 'grezzo tail del log If lngLogSize>MAX_LOG_SIZE Then f.copy strlogfile & ".old", TRUE Set f = Nothing fso.deletefile (strLogFile) Else Set f = Nothing End If On Error GoTo 0 'inizio Set f = fso.OpenTextFile(strLogFile , ForAppending, True) f.writeline "--------------------------------------------------------------------" f.writeline "(" & Now &amp; ") Starting program..." f.writeline TITLE & " v." &amp; VER f.writeline "starting with " & strArgs &amp; " options." f.writeline "Environment:" On Error Resume Next Set objNet = CreateObject("WScript.NetWork") If Err.Number <> SUCCESS Then 'If error occured then display notice f.writeline "(" & Now &amp; ") Error getting network info." Else f.writeline "User " & objNet.UserName &amp; vbCRLF & _ "Computer " & objNet.ComputerName &amp; vbCRLF & _ "Domain " & objNet.UserDomain End if On Error GoTo 0 Set objNet = Nothing f.writeline "Reading from file '" &amp; strListFile & "'" On Error Resume Next Set fListFile = fso.OpenTextFile(strListFile, ForReading, FALSE) If err.number<>SUCCESS Then f.writeline "(" & Now &amp; ") Error opening list file." WshShell.LogEvent Error, TITLE & " Error opening file." f.close WScript.Quit (1) End If On Error GoTo 0 f.close Set f = Nothing Do While not fListFile.AtEndOfStream strCurrent = Trim(fListFile.ReadLine) if strCurrent="" then strCurrent=";" If Left(strCurrent,1)=";" Then 'commento Else aryCampi= Split(strCurrent, "*", -1, 1) lngPos=DEF_NUM If UBound(aryCampi)>0 Then If not IsNumeric(aryCampi(1)) Then aryCampi(1)=DEF_NUM Else aryCampi(1)=CLng(aryCampi(1)) If aryCampi(1)<1>10 Then aryCampi(1)=DEF_NUM End If End If lngPos=aryCampi(1) End If If arycampi(0)<>"" Then Set f = fso.OpenTextFile( strLogFile, ForAppending, True) strCurrentCMD=replace(replace(strWinRarCmd,"*",replace(replace(aryCampi(0),":",ALT_REPLACE_CHAR),"\",REPLACE_CHAR)),"?",aryCampi(0)) f.writeline vbcrlf & "###" &amp; aryCampi(0) & "###" f.writeline "(" & Now &amp; ") [WinRAR] Creating " & replace(replace(aryCampi(0),":",ALT_REPLACE_CHAR),"\",REPLACE_CHAR) &amp; " file..." 'consentiamo a rar di scrivere nel logv f.close Set f = Nothing lngResult=WshShell.Run (strCurrentCMD ,0,true) Set f = fso.OpenTextFile(strLogFile , ForAppending, True) Select Case lngResult Case SUCCESS f.writeline "(" & Now &amp; ") [WinRAR] Done." Case 1 f.writeline vbcrlf & "(" &amp; Now & ") [WinRAR] Cannot create empty file." case 6 f.writeline "(" & Now &amp; ") [WinRAR] Cannot find source." blWarning=TRUE Case 255 f.writeline "(" & Now &amp; ") [WinRAR] Aborted by user." blWarning=TRUE Case Else f.writeline vbcrlf & "(" &amp; Now & ") [WinRAR] Error (" &amp; lngResult & ")." 'aggiungo un ritorno a capo perché winrar non lo mette. blWarning=TRUE End Select 'controlliamo l'eliminazione If lngResult=SUCCESS Then If blCompleto Then 'cancelliamo tutti i gionalieri f.writeline "(" & Now &amp; ") Checking old files deletion..." lngResult=WshShell.Run ("cmd.exe /c dir /B /O:D """ & DEST_DIR &amp; "\" & replace(replace(aryCampi(0),":",ALT_REPLACE_CHAR),"\",REPLACE_CHAR) &amp; SUFF_GIORNALIERO & "*" &amp; SUFF_EXT & """ > " &amp; strListFile & TEMP ,0,true) 'f.writeline ("cmd.exe /c dir /B /O:D """ & DEST_DIR &amp; "\" & replace(aryCampi(0),"\",REPLACE_CHAR) &amp; SUFF_GIORNALIERO & "*" &amp; SUFF_EXT & """ > " &amp; strListFile & TEMP &amp; " 2 > c:\errore.txt") On Error Resume Next Set fTemp = fso.OpenTextFile(strListFile & TEMP, ForReading) lngResult=Err.number On Error GoTo 0 If lngResult=SUCCESS Then On Error Resume Next aryFiles= Split(fTemp.ReadAll, vbcrlf, -1, 1) lngResult=Err.number On Error GoTo 0 If lngResult=SUCCESS Then f.writeline "(" & Now &amp; ") Deleting " & CLng(UBound (aryFiles)) &amp; " incremental files..." For lngCiclo=0 to CLng(UBound (aryFiles)) If aryFiles(lngCiclo)<>"" and aryFiles(lngCiclo)<>FILE_NOT_FOUND Then On Error Resume Next fso.DeleteFile (DEST_DIR & "\" &amp; aryFiles(lngCiclo)) If err<>SUCCESS Then f.write "(" & Now &amp; ") [Delete] Error (" & err &amp; ") deleting file " End If On Error GoTo 0 f.writeline (DEST_DIR & "\" &amp; aryFiles(lngCiclo)) End If Next f.writeline "(" & Now &amp; ") Done." End If 'lngResult Else f.writeline "(" & Now &amp; ") [Delete] Error (" & lngResult &amp; ") opening temp file." End If Set aryFiles= Nothing 'prendiamo i bkp completi ed eliminiamo quelli in eccesso lngResult=WshShell.Run ("cmd.exe /c dir /B /O:D """ & DEST_DIR &amp; "\" & replace(replace(aryCampi(0),":",ALT_REPLACE_CHAR),"\",REPLACE_CHAR) &amp; SUFF_COMPLETO & "*" &amp; SUFF_EXT & """ > " &amp; strListFile & TEMP ,0,true) On Error Resume Next Set fTemp = fso.OpenTextFile(strListFile & TEMP, ForReading) lngResult=Err.number On Error GoTo 0 If lngResult=SUCCESS Then On Error Resume Next aryFiles= Split(fTemp.ReadAll, vbcrlf, -1, 1) lngResult=Err.number On Error GoTo 0 If lngResult=SUCCESS Then If UBound (aryFiles) > lngPos Then f.writeline "(" & Now &amp; ") Deleting " & CLng(UBound (aryFiles) - lngPos) &amp; " complete files..." For lngCiclo=1 to CLng(UBound (aryFiles) - lngPos) If aryFiles(lngCiclo)<>FILE_NOT_FOUND Then On Error Resume Next fso.DeleteFile (DEST_DIR & "\" &amp; aryFiles(lngCiclo)) If err<>SUCCESS Then f.write "(" & Now &amp; ") [Delete] Error (" & err &amp; ") deleting file " End If On Error GoTo 0 f.writeline (DEST_DIR & "\" &amp; aryFiles(lngCiclo)) End If Next f.writeline "(" & Now &amp; ") Done." End If End If 'lngResult Else f.writeline "(" & Now &amp; ") [Delete] Error (" & lngResult &amp; ") opening temp file." End If fTemp.close Set fTemp = Nothing On Error Resume Next fso.DeleteFile( strListFile & TEMP) On Error GoTo 0 End If End If f.writeline "(" & Now &amp; ") Backup complete." f.close Set f=Nothing End If End If '; Loop fListFile.close Set fListFile = Nothing If blWarning Then WshShell.LogEvent WARNING, TITLE & " Done. Some errors occurred during backup (See log file in '" &amp; strLogFile & "')." Else WshShell.LogEvent SUCCESS, TITLE & " Done." End If 'ESCI Set FSO=Nothing Set WshShell=Nothing 'WScript.Quit (SUCCESS)


Per utilizzare correttamente lo script è necessario creare un list file contenente i percorsi da sottoporre a backup. Se non diversamente specificato il file sarà "c:\backups\install\myBackups.txt".

di seguito un esempio di file valido:


; Server 1 \\192.168.0.1\DIR_1 \\192.168.0.1\DIR_1 \\192.168.0.1\DIR_1 \\192.168.0.1\DIR_1 ; Server 2 \\mioserver\DIR_2\*3 ; Locale c:\Winnt\system32\*1 ; commento


Alcuni path sono seguiti da un '*' (separatore) ed un numero. Tale numero indica quanti backup completi conservare nel repository. Se non specificato il programma conserva gli ultimi 5 completi creati.

Ogni volta che un completo viene creato, tutti i backup incrementali vengono eliminati.

Ricordate che il carattere "\" alla fine del path è fondamentale per il corretto funzionamento dello script.

Anche in questo caso è possibile schedulare un job per avviare le operazioni senza l'intervento di un operatore. (attenzione ai permessi di lettura/scrittura).