From 676f7bdc633a40904115a5bc801e9d910ac810c0 Mon Sep 17 00:00:00 2001 From: Nicolas MASSE Date: Fri, 10 Apr 2020 18:43:57 +0200 Subject: [PATCH] initial commit --- .gitignore | 2 + backup-mails-and-documents.pl | 255 +++++++++++++++++++++ certificates/auto-enroll.bat | 19 ++ certificates/auto-enroll.vbs | 91 ++++++++ certificates/cleanup-store.vbs | 23 ++ dump-sn.cmd | 15 ++ file-conversion/convert-all-ppt-to-pdf.cmd | 3 + file-conversion/convert-all-ppt-to-pdf.vbs | 71 ++++++ file-conversion/convert-all-xls-to-csv.cmd | 3 + file-conversion/convert-all-xls-to-csv.vbs | 68 ++++++ file-conversion/ppt-to-pdf.vbs | 21 ++ ldap/DB_CONFIG | 7 + ldap/gen_ldif_users.pl | 44 ++++ ldap/ldap.sh | 15 ++ ldap/slapd.conf | 29 +++ ldap/users.csv | 8 + list-tcp-connections-count.sh | 3 + msi/include_config.vbs | 158 +++++++++++++ pap/papdb.pl | 83 +++++++ soap_testbed/index.html | 49 ++++ stress-test/stress-test.sh | 59 +++++ sync.pl | 175 ++++++++++++++ testbed_js/index.html | 41 ++++ 23 files changed, 1242 insertions(+) create mode 100644 .gitignore create mode 100755 backup-mails-and-documents.pl create mode 100755 certificates/auto-enroll.bat create mode 100755 certificates/auto-enroll.vbs create mode 100755 certificates/cleanup-store.vbs create mode 100644 dump-sn.cmd create mode 100755 file-conversion/convert-all-ppt-to-pdf.cmd create mode 100755 file-conversion/convert-all-ppt-to-pdf.vbs create mode 100755 file-conversion/convert-all-xls-to-csv.cmd create mode 100755 file-conversion/convert-all-xls-to-csv.vbs create mode 100755 file-conversion/ppt-to-pdf.vbs create mode 100644 ldap/DB_CONFIG create mode 100755 ldap/gen_ldif_users.pl create mode 100755 ldap/ldap.sh create mode 100644 ldap/slapd.conf create mode 100644 ldap/users.csv create mode 100644 list-tcp-connections-count.sh create mode 100644 msi/include_config.vbs create mode 100755 pap/papdb.pl create mode 100755 soap_testbed/index.html create mode 100644 stress-test/stress-test.sh create mode 100755 sync.pl create mode 100644 testbed_js/index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..94f1119 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +.vscode diff --git a/backup-mails-and-documents.pl b/backup-mails-and-documents.pl new file mode 100755 index 0000000..cf16475 --- /dev/null +++ b/backup-mails-and-documents.pl @@ -0,0 +1,255 @@ +#!/usr/bin/perl -w + +use strict; +#use IO::Socket::SSL qw/debug3/; # SSL Debug +use Mail::IMAPClient; +use Data::Dumper; +use File::Temp; +use POSIX qw/ strftime /; +use POSIX ":sys_wait_h"; +use Getopt::Long; + +my $target; +my $mail = 1; +my $docs = 0; +my $svn = 0; +GetOptions("to=s" => \$target, + "mail" => \$mail, + "docs" => \$docs); + +die "Wrong target directory" + unless defined $target and -d $target; + +# Slup SAMBA Credentials File... +open SMB_FILE, '<', $ENV{HOME}."/.smbpasswd-z" + or die "open: .smbpasswd-z: $!"; +my $holdTerminator = $/; +undef $/; +my $credentials = ; +$/ = $holdTerminator; +my ($username, $password); +($username) = $credentials =~ m/username\s*=\s*(\S+)\s*\n/; +($password) = $credentials =~ m/password\s*=\s*(\S+)\s*\n/; +close SMB_FILE; +die "missing username in ~/.smbpasswd-z" + unless defined $username; +die "missing password in ~/.smbpasswd-z" + unless defined $password; + +# Create temp folder to store data +my $tmp = File::Temp->newdir(CLEANUP => 0); # So that childs do not try to remove temp dir while the father is still using it... +print "Using '$tmp' as temp dir...\n"; +my $imap_dir = "Backup Mails"; + +my $target_filename = "mail-backup-".strftime("%Y%m%d-%H%M%S", localtime).".cpio.bz2"; +print "Storing backup to '$target/$target_filename'...\n"; + +open BACKUP, ">", "$target/$target_filename" + or die "open: $target/$target_filename: $!"; + +# Launch CPIO to store data +pipe FROM_FATHER, TO_CPIO0; +pipe FROM_CPIO2, TO_DELETE; +pipe FROM_CPIO1, TO_ZIP; +my $pid_cpio = fork(); +die "fork: $!" unless defined $pid_cpio; +if ($pid_cpio == 0) { # Child: CPIO + close TO_CPIO0; + close FROM_CPIO1; + close FROM_CPIO2; + close BACKUP; + + open STDIN, '<&', \*FROM_FATHER; + open STDOUT, '>&', \*TO_ZIP; + open STDERR, '>&', \*TO_DELETE; + + chdir $tmp + or die "chdir: $tmp: $!"; + + exec "cpio", "-ov" + or die "exec: cpio: $!"; + + # Child stops here +} # The father continues... + +my $pid_zip = fork(); +die "fork: $!" unless defined $pid_zip; +if ($pid_zip == 0) { # Child: ZIP + close TO_ZIP; + close TO_DELETE; + close FROM_FATHER; + close TO_CPIO0; + close FROM_CPIO2; + + open STDIN, '<&', \*FROM_CPIO1; + open STDOUT, '>&', \*BACKUP; + + exec "bzip2", "--compress", "--force", "--stdout" + or die "exec: bzip2: $!"; + # Child stops here +} # The father continues... + +my $pid_delete = fork(); +die "fork: $!" unless defined $pid_delete; +if ($pid_delete == 0) { # Child: DELETE + close TO_ZIP; + close TO_DELETE; + close FROM_FATHER; + close TO_CPIO0; + close FROM_CPIO1; + close BACKUP; + + chdir $tmp + or die "chdir: $tmp: $!"; + + while () { + chomp; + + # The goal is to free space, so we do not delete directories... + if (-e $_) { + if ($_ =~ m/^$imap_dir\// and -f $_) { + print "CLEANUP: Removing useless file '$_'...\n"; + unlink $_; + } + } else { + print "CPIO: $_\n"; + } + } + + # Child stops here + exit 0; +} # The father continues... + +# Clean up... +close TO_ZIP; +close TO_DELETE; +close FROM_FATHER; +close FROM_CPIO2; +close FROM_CPIO1; +close BACKUP; + +# Childs will not clean up the temp folder. The father has to do it ! +$tmp->unlink_on_destroy(1); + +# Avoid warning of File::Temp cleanup process... +END { + chdir $ENV{'HOME'}; +} + +chdir $tmp + or die "chdir: $tmp: $!"; + +# Backup mails +if ($mail) { + my $imap = Mail::IMAPClient->new; + $imap->Server('zimbra.example.test'); + $imap->Port(993); + $imap->Ssl(1); + $imap->Uid(1); + $imap->Peek(1); + $imap->connect or die "IMAP: Could not connect: $@"; + print "IMAP: Logging in as $username\n"; + $imap->User($username); + $imap->Password($password); + $imap->login or die "IMAP: Could not login: $@"; + + my $folders = $imap->folders + or die "IMAP: Could not list folders: $@"; + + mkdir $imap_dir + or die "mkdir: $imap_dir: $!"; + print "IMAP: Using '$tmp/$imap_dir' to backup mails...\n"; + + foreach my $folder (@$folders) { + my @components = split /\//, $folder; + my $mbox_name = delete $components[$#components]; + my $mbox_path = "$imap_dir/"; + foreach my $component (@components) { + unless (-e "$mbox_path$component") { + mkdir "$mbox_path$component" + or die "mkdir: $mbox_path$component: $!" + } + $mbox_path .= "$component/"; + } + + $imap->select($folder) + or die "IMAP: Could not select $folder: $@"; + + my $msgcount = $imap->message_count($folder); + die "IMAP: Could not message_count: $@" + if not defined $msgcount; + + if ($msgcount == 0) { + print "IMAP: Skipping empty folder '$folder'...\n"; + next; + } + + print "IMAP: Backing up $msgcount messages in '$folder'...\n"; + my @msgs = $imap->messages + or die "IMAP: Could not messages: $@"; + + my $mbox_file = "$mbox_path$mbox_name.mbox"; + my $mbox_fh; + $imap->message_to_file($mbox_file, @msgs) + or die "IMAP: Could not backup messages of folder '$folder': $@"; + + # Remove \r to have a valid MBOX file. + system("fromdos", "$mbox_file") == 0 # fromdos = dos2unix + or warn "system: fromdos: $?"; + + # Backup this file ! + print TO_CPIO0 "$mbox_file\n"; + } + $imap->disconnect() + or die "IMAP: Could not logout: $@"; +} + +# Sends filenames to CPIO +sub compress_files { + my ($dir) = @_; + + my $pid = fork(); + die "fork: $!" unless defined $pid; + if ($pid == 0) { # Child: FIND + open STDOUT, '>&', \*TO_CPIO0; + + exec "find", "$dir", "-print" + or die "exec: find: $!"; + } + + waitpid $pid, 0; +} + +# Backup Own Data +if ($docs) { + my @files = + ( + ".ssh/", + ".bashrc", + ".bash_aliases", + ".vimrc", + ".mozilla/", + "Documents/", + ); + @files = map { "home/$_" } @files; + symlink $ENV{'HOME'}, "home" + or die "symlink: home: $!"; + + foreach my $file (@files) { + compress_files $file; + } +} + +# No more file to backup, notify CPIO... +close TO_CPIO0; + +print "FINISH: Waiting for CPIO (pid = $pid_cpio) to complete...\n"; +waitpid $pid_cpio, 0; + +print "FINISH: Waiting for BZIP2 (pid = $pid_zip) to complete...\n"; +waitpid $pid_zip, 0; + +print "FINISH: Waiting for the cleanup process (pid = $pid_delete) to complete...\n"; +waitpid $pid_delete, 0; + + diff --git a/certificates/auto-enroll.bat b/certificates/auto-enroll.bat new file mode 100755 index 0000000..3221d6d --- /dev/null +++ b/certificates/auto-enroll.bat @@ -0,0 +1,19 @@ +@ECHO OFF +C: +CD \ +ECHO. >> C:\auto-enroll.log +ECHO ------------------------------------------------------------------ >> C:\auto-enroll.log +ECHO AUTO ENROLLMENT LOGS >> C:\auto-enroll.log +ECHO ------------------------------------------------------------------ >> C:\auto-enroll.log +ECHO. >> C:\auto-enroll.log + +ECHO CURRENT DATE: >> C:\auto-enroll.log +DATE /T >> C:\auto-enroll.log +TIME /T >> C:\auto-enroll.log + +ECHO. >> C:\auto-enroll.log +ECHO CURRENT USER: >> C:\auto-enroll.log +WHOAMI >> C:\auto-enroll.log + +ECHO. >> C:\auto-enroll.log +CSCRIPT C:\auto-enroll.vbs >> c:\auto-enroll.log diff --git a/certificates/auto-enroll.vbs b/certificates/auto-enroll.vbs new file mode 100755 index 0000000..a319172 --- /dev/null +++ b/certificates/auto-enroll.vbs @@ -0,0 +1,91 @@ +' +' Download CAPICOM from http://www.microsoft.com/downloads/en/details.aspx?FamilyID=860ee43a-a843-462f-abb5-ff88ea5896f6&displaylang=en +' Install it +' Register it (regsrv32 capicom.dll) +' + +Const CAPICOM_LOCAL_MACHINE_STORE = 1 +Const CAPICOM_MY_STORE = "My" +Const CAPICOM_STORE_OPEN_READ_ONLY = 0 +Const CAPICOM_CERTIFICATE_FIND_TEMPLATE_NAME = 4 +Const CRYPT_EXPORTABLE = 1 +Const CR_IN_BASE64 = &H1 +Const CR_IN_PKCS10 = &H100 +Const CR_OUT_BASE64 = &H1 +Const CR_OUT_CHAIN = &H100 +Const CERT_SYSTEM_STORE_LOCAL_MACHINE = &H20000 +Const CRYPT_MACHINE_KEYSET = &H20 + +Const strTemplate = "Machine" +Const strProviderName = "Microsoft Enhanced Cryptographic Provider v1.0" +Const intKeySize = 1024 +Const strTargetCA = "adcs-trial.acme.tld\Root CA" + +Dim objStore +Set objStore = CreateObject("CAPICOM.Store") +objStore.Open CAPICOM_LOCAL_MACHINE_STORE, CAPICOM_MY_STORE, CAPICOM_STORE_OPEN_READ_ONLY + +Dim bFoundCert : bFoundCert = vbFalse + +WScript.Echo "Begin Cert Store enumeration" +WScript.Echo + +Dim objCerts : Set objCert = objStore.Certificates +Set objCerts = objCert.Find(CAPICOM_CERTIFICATE_FIND_TEMPLATE_NAME, strTemplate, vbTrue) + +Dim objCert +For Each objCert in objCerts + If objCert.HasPrivateKey And Not IsNull(objCert.PrivateKey) Then + WScript.Echo "Found certificate " & objCert.SerialNumber & ":" + WSCript.Echo " Issuer DN: " & objCert.IssuerName + WScript.Echo " Subject DN: " & objCert.SubjectName + WSCript.Echo " Not Before: " & objCert.ValidFromDate + WSCript.Echo " Not After: " & objCert.ValidToDate + WScript.Echo + bFoundCert = vbTrue + End If +Next + +WScript.Echo "End of Cert Store enumeration: found = " & bFoundCert + +If Not bFoundCert Then + WScript.Echo "Starting Auto-Enrollment" + WScript.Echo + + Dim objCEnroll + Set objCEnroll = CreateObject("CEnroll.CEnroll") + + objCEnroll.GenKeyFlags = intKeySize * (256*256) + CRYPT_EXPORTABLE + objCEnroll.UseExistingKeySet = 0 + objCEnroll.addCertTypeToRequest(strTemplate) + objCEnroll.ProviderName = strProviderName + objCEnroll.MyStoreFlags = CERT_SYSTEM_STORE_LOCAL_MACHINE + objCEnroll.RequestStoreFlags = CERT_SYSTEM_STORE_LOCAL_MACHINE + objCEnroll.ProviderFlags = CRYPT_MACHINE_KEYSET + + Dim strP10 + strP10 = objCEnroll.createPKCS10("CN=Dummy", "1.3.6.1.5.5.7.3.2") + WScript.Echo "PKCS#10 Request:" + WScript.Echo strP10 + + Dim objCARequest + Set objCARequest = CreateObject("CertificateAuthority.Request") + + Dim intReqFlags + intReqFlags = CR_IN_BASE64 OR CR_IN_PKCS10 + + Dim intReqStatus + intReqStatus = objCARequest.Submit(intReqFlags, strP10, "", strTargetCA) + WScript.Echo "Request Sent. Status = " & intReqStatus + + Dim strCertificate + strCertificate = objCARequest.GetCertificate(CR_OUT_BASE64 Or CR_OUT_CHAIN) + WScript.Echo "Issued Certificate:" + WScript.Echo strCertificate + + objCEnroll.acceptPKCS7(strCertificate) + + WScript.Echo + WScript.Echo "End of Auto-Enrollment" +End If + diff --git a/certificates/cleanup-store.vbs b/certificates/cleanup-store.vbs new file mode 100755 index 0000000..f7211a5 --- /dev/null +++ b/certificates/cleanup-store.vbs @@ -0,0 +1,23 @@ +' +' http://www.microsoft.com/downloads/en/details.aspx?FamilyID=860ee43a-a843-462f-abb5-ff88ea5896f6&displaylang=en +' + +Dim store +Set store = CreateObject("CAPICOM.Store") +store.Open ,,2 + +MsgBox "Begin Cert Store cleanup" + +Dim cert +For Each cert in store.Certificates + If cert.HasPrivateKey And Not IsNull(cert.PrivateKey) Then + Dim privateKey + Set privateKey = cert.PrivateKey + If privateKey.IsHardwareDevice And privateKey.IsRemovable And Not privateKey.IsAccessible Then + cert.Display + ' store.Remove cert + End If + End If +Next + +MsgBox "End of Cert Store cleanup" diff --git a/dump-sn.cmd b/dump-sn.cmd new file mode 100644 index 0000000..7cf281e --- /dev/null +++ b/dump-sn.cmd @@ -0,0 +1,15 @@ +@ECHO OFF + +setlocal enableDelayedExpansion +set SN="c:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\sn.exe" + +echo. > sn_dump.txt +for /F %%x in ('dir /B/D *.DLL') do ( + echo. >> sn_dump.txt + echo ==================================================================== >> sn_dump.txt + echo. >> sn_dump.txt + echo Working on %%x >> sn_dump.txt + echo. >> sn_dump.txt + %SN% -Tp %%x >> sn_dump.txt +) + diff --git a/file-conversion/convert-all-ppt-to-pdf.cmd b/file-conversion/convert-all-ppt-to-pdf.cmd new file mode 100755 index 0000000..4fd6657 --- /dev/null +++ b/file-conversion/convert-all-ppt-to-pdf.cmd @@ -0,0 +1,3 @@ +@ECHO OFF +CSCRIPT.EXE convert-all-ppt-to-pdf.vbs +PAUSE \ No newline at end of file diff --git a/file-conversion/convert-all-ppt-to-pdf.vbs b/file-conversion/convert-all-ppt-to-pdf.vbs new file mode 100755 index 0000000..6babc15 --- /dev/null +++ b/file-conversion/convert-all-ppt-to-pdf.vbs @@ -0,0 +1,71 @@ +Option Explicit + +Const ppWindowMinimized = 2 +Const ppSaveAsPDF = 32 +Const msoTrue = -1 + +Dim CurrentDir, Files, File, FsObj + +' Get the Current Folder +Set FsObj = CreateObject("Scripting.FileSystemObject") +Set CurrentDir = FsObj.GetFolder(FsObj.GetAbsolutePathName(".")) + +' Process all files in the current dir +Set Files = CurrentDir.Files +For Each File in Files + Dim inputFile : inputFile = File.Path + Dim Ext : Ext = FsObj.GetExtensionName(inputFile) + + ' Process only supported files + If Ext = "pptx" Or Ext = "ppt" Or Ext = "pps" Then + Dim outputFile : outputFile = FsObj.BuildPath(FsObj.GetParentFolderName(inputFile), FsObj.GetBaseName(inputFile) & ".pdf") + + If Not FsObj.FileExists(outputFile) Then + WScript.Echo "Processing file '" & File.Name & "..." + + ' Launch PowerPoint + Dim PowerPointApp : Set PowerPointApp = CreateObject("PowerPoint.Application") + PowerPointApp.Visible = vbTrue + PowerPointApp.WindowState = ppWindowMinimized + + ' Custom Error Handler + On Error Resume Next + Dim PowerPointPres : Set PowerPointPres = PowerPointApp.Presentations.Open(inputFile) + If Err <> 0 Then + WScript.Echo "ERR: Cannot open '" & File.Name & "' !" + Else + PowerPointPres.SaveAs outputFile, ppSaveAsPDF, msoTrue + If Err <> 0 Then + WScript.Echo "ERR: Cannot save PDF version of '" & File.Name & "' !" + End If + PowerPointPres.Close + End If + + ' Standard Error Handler + On Error Goto 0 + + ' Wait a little bit and close PowerPoint + Wscript.Sleep 500 + PowerPointApp.Quit + Wscript.Sleep 1000 + + ' Kill remaining instances of PowerPoint + Dim strComputer : strComputer = "." + Dim objWMIService, colProcessList, objProcess + Set objWMIService = GetObject("winmgmts:" _ + & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") + Set colProcessList = objWMIService.ExecQuery _ + ("SELECT * FROM Win32_Process WHERE Name = 'powerpnt.exe'") + For Each objProcess in colProcessList + WScript.Echo "Killing remaining PowerPoint process !" + objProcess.Terminate() + Next + + Else + WScript.Echo "Skipping file '" & File.Name & "' since the PDF version already exists !" + End If + Else + WScript.Echo "Skipping unsupported file '" & File.Name & " !" + End If +Next + diff --git a/file-conversion/convert-all-xls-to-csv.cmd b/file-conversion/convert-all-xls-to-csv.cmd new file mode 100755 index 0000000..9fbe350 --- /dev/null +++ b/file-conversion/convert-all-xls-to-csv.cmd @@ -0,0 +1,3 @@ +@ECHO OFF +CSCRIPT.EXE convert-all-xls-to-csv.vbs +PAUSE \ No newline at end of file diff --git a/file-conversion/convert-all-xls-to-csv.vbs b/file-conversion/convert-all-xls-to-csv.vbs new file mode 100755 index 0000000..ee1c0e7 --- /dev/null +++ b/file-conversion/convert-all-xls-to-csv.vbs @@ -0,0 +1,68 @@ +Option Explicit + +Const xlWindowMinimized = 2 +Const xlCSV = 6 +Const msoTrue = -1 + +Dim CurrentDir, Files, File, FsObj + +' Get the Current Folder +Set FsObj = CreateObject("Scripting.FileSystemObject") +Set CurrentDir = FsObj.GetFolder(FsObj.GetAbsolutePathName(".")) + +' Process all files in the current dir +Set Files = CurrentDir.Files +For Each File in Files + Dim inputFile : inputFile = File.Path + Dim Ext : Ext = FsObj.GetExtensionName(inputFile) + + ' Process only supported files + If Ext = "xlsx" Or Ext = "xls" Then + WScript.Echo "Processing file '" & File.Name & "..." + Dim outputFile : outputFile = FsObj.BuildPath(FsObj.GetParentFolderName(inputFile), FsObj.GetBaseName(inputFile) & ".csv") + + ' Launch Excel + Dim ExcelApp : Set ExcelApp = CreateObject("Excel.Application") + ExcelApp.Visible = vbTrue + ExcelApp.DisplayAlerts = False + ExcelApp.WindowState = xlWindowMinimized + + ' Custom Error Handler + On Error Resume Next + Dim ExcelWB : Set ExcelWB = ExcelApp.Workbooks.Open(inputFile) + If Err <> 0 Then + WScript.Echo "ERR: Cannot open '" & File.Name & "' !" + Else + WScript.Echo "Saving CSV copy to '" & outputFile & "'..." + ExcelWB.ActiveSheet.SaveAs outputFile, xlCSV + If Err <> 0 Then + WScript.Echo "ERR: Cannot save '" & outputFile & "' !" + End If + ExcelWB.Close + End If + + ' Standard Error Handler + On Error Goto 0 + + ' Wait a little bit and close Excel + Wscript.Sleep 500 + ExcelApp.Application.Quit + ExcelApp.Quit + Wscript.Sleep 1000 + + ' Kill remaining instances of Excel + Dim strComputer : strComputer = "." + Dim objWMIService, colProcessList, objProcess + Set objWMIService = GetObject("winmgmts:" _ + & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") + Set colProcessList = objWMIService.ExecQuery _ + ("SELECT * FROM Win32_Process WHERE Name = 'excel.exe'") + For Each objProcess in colProcessList + WScript.Echo "Killing remaining Excel process !" + objProcess.Terminate() + Next + Else + WScript.Echo "Skipping unsupported file '" & File.Name & " !" + End If +Next + diff --git a/file-conversion/ppt-to-pdf.vbs b/file-conversion/ppt-to-pdf.vbs new file mode 100755 index 0000000..8fa98df --- /dev/null +++ b/file-conversion/ppt-to-pdf.vbs @@ -0,0 +1,21 @@ +Option Explicit + +Const ppWindowMinimized = 2 +Const ppSaveAsPDF = 32 +Const msoTrue = -1 + +Dim FsObj : Set FsObj = CreateObject("Scripting.FileSystemObject") + +Dim inputFile : inputFile = WScript.Arguments.Item(0) +inputFile = FsObj.GetAbsolutePathName(inputFile) +Dim outputFile : outputFile = FsObj.BuildPath(FsObj.GetParentFolderName(inputFile), FsObj.GetBaseName(inputFile) & ".pdf") + +Dim PowerPointApp : Set PowerPointApp = CreateObject("PowerPoint.Application") +PowerPointApp.Visible = vbTrue +PowerPointApp.WindowState = ppWindowMinimized + +Dim PowerPointPres : Set PowerPointPres = PowerPointApp.Presentations.Open(inputFile) +PowerPointPres.SaveAs outputFile, ppSaveAsPDF, msoTrue +PowerPointPres.Close + +PowerPointApp.Quit diff --git a/ldap/DB_CONFIG b/ldap/DB_CONFIG new file mode 100644 index 0000000..8b5d24e --- /dev/null +++ b/ldap/DB_CONFIG @@ -0,0 +1,7 @@ +# one 0.25 GB cache +set_cachesize 0 268435456 1 + +# Transaction Log settings +set_lg_regionmax 262144 +set_lg_bsize 2097152 + diff --git a/ldap/gen_ldif_users.pl b/ldap/gen_ldif_users.pl new file mode 100755 index 0000000..43f2e7c --- /dev/null +++ b/ldap/gen_ldif_users.pl @@ -0,0 +1,44 @@ +#!/usr/bin/perl -w + +use strict; + +my %o = (); + +while (<>) { + chomp; + my ($cn, $short_uid, $long_uid, $ou, $org) = split /;/; + my ($first_name, $family_name) = split / /, $cn; + if (not exists $o{$org}) { + print <{$ou}) { + print <{$ou} = 1; + } + print < data.ldif +if [ -f slapd.pid ] ; then + kill `cat slapd.pid` ; +fi + +mkdir -p /tmp/ldap_data +rm -f /tmp/ldap_data/* +cp DB_CONFIG /tmp/ldap_data/ +/usr/sbin/slapadd -f slapd.conf -l data.ldif +/usr/sbin/slapd -h ldap://0.0.0.0:12345 -f slapd.conf + diff --git a/ldap/slapd.conf b/ldap/slapd.conf new file mode 100644 index 0000000..165290c --- /dev/null +++ b/ldap/slapd.conf @@ -0,0 +1,29 @@ +include /etc/ldap/schema/core.schema +include /etc/ldap/schema/cosine.schema +include /etc/ldap/schema/inetorgperson.schema +include /etc/ldap/schema/nis.schema +include /etc/ldap/schema/misc.schema +include /etc/ldap/schema/openldap.schema + +moduleload back_bdb.so +modulepath /usr/lib/ldap + +pidfile slapd.pid +argsfile slapd.args + +defaultsearchbase "" + +logfile /tmp/ldap.log +loglevel 256 + +database bdb +suffix "" +rootdn "CN=admin,O=ACME,C=FR" +rootpw changeme +directory /tmp/ldap_data + +index objectClass,uid,uidNumber,gidNumber,memberUid eq +index mail,surname,givenname eq,subinitial +index cn pres,eq,sub + + diff --git a/ldap/users.csv b/ldap/users.csv new file mode 100644 index 0000000..cc16c27 --- /dev/null +++ b/ldap/users.csv @@ -0,0 +1,8 @@ +Kate DAVIES;kdavies;kate.davies;Administrators;ACME +Bill EVANS;bevans;bill.evans;Accounting;ACME +Jane GREEN;jgreen;jane.green;Accounting;ACME +Jack ROBERTS;jroberts;jack.roberts;Marketing;GoodTimes Inc. +John SMITH;jsmith;john.smith;Administration;ACME +Jim WALKER;jwalker;jim.walker;Marketing;GoodTimes Inc. +Olivia WILSON;owilson;olivia.wilson;Accounting;GoodTimes Inc. +Pamella WRIGHT;pwright;pamella.wright;Administration;ACME diff --git a/list-tcp-connections-count.sh b/list-tcp-connections-count.sh new file mode 100644 index 0000000..6998eaa --- /dev/null +++ b/list-tcp-connections-count.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +netstat -tnp |tail -n +3 | tr -s " " |cut -d " " -f 6 |sort |uniq -c diff --git a/msi/include_config.vbs b/msi/include_config.vbs new file mode 100644 index 0000000..d340442 --- /dev/null +++ b/msi/include_config.vbs @@ -0,0 +1,158 @@ +' +---------------------------------------------------------------------+ +' | Requirements | +' +---------------------------------------------------------------------+ +' +' - CScript.exe +' - Windows Installer +' - Microsoft Cabinet Software Development Kit (See KB 310618) +' + +' Safe coding +Option Explicit + +' +---------------------------------------------------------------------+ +' | Adjust the following settings to your needs | +' +---------------------------------------------------------------------+ + +' The MSI file to modify +Dim databasePath : databasePath = "installer.msi" + +' The Properties to set +Dim Properties : Set Properties = CreateObject("Scripting.Dictionary") +Properties.Add "PROPERTY1", "FOO" +Properties.Add "PROPERTY2", "BAR" + +' MSI Release (numeric value) +Dim Release : Release = "1" + +' Machine Install ? +Dim machineInstall : machineInstall = vbTrue + +' ======================================================================= +' +' WARNING ! WARNING ! WARNING ! WARNING ! WARNING ! +' +' +' -= DO NOT MODIFY ANYTHING BELOW ! =- +' +' ======================================================================= + +' Custom Error Handling (see below) +On Error Resume Next + +' Machine installation needs the "ALLUSERS" property +If machineInstall Then + Properties.Add "ALLUSERS", "1" +End If + +' Update Product Version +Properties.Add "ProductVersion", "1.2.3." & Release + +Const msiOpenDatabaseModeTransact = 1 +Dim openMode : openMode = msiOpenDatabaseModeTransact + +' Connect to Windows installer object +Dim installer : Set installer = Nothing +Set installer = Wscript.CreateObject("WindowsInstaller.Installer") : CheckError "Cannot instanciate WindowsInstaller.Installer. Check the script's requirements !" + +' Open database +Dim database +Set database = installer.OpenDatabase(databasePath, openMode) : CheckError "Unable to open the MSI database '" & databasePath & "'" + +' Process SQL statements +Dim query, view, prop, value, record, errMessage +For Each prop in Properties + value = Properties.Item(prop) + errMessage = "Cannot create/update property '" & prop & "'" + query = "SELECT Property, Value FROM Property" + Set record = installer.CreateRecord(2) : CheckError errMessage + record.StringData(1) = prop + record.StringData(2) = value + InsertOrUpdate database, query, record, errMessage +Next + +Dim Dialogs(4) +Dialogs(1) = "ExitDialog" +Dialogs(2) = "PrepareDlg" +Dialogs(3) = "ProgressDlg" +Dialogs(4) = "WelcomeEulaDlg" + +Dim Dialog +For Each Dialog in Dialogs + errMessage = "Cannot disable UI Dialog '" & Dialog & "'" + + query = "UPDATE InstallUISequence SET Condition = 0 WHERE Action = ?" + Set record = installer.CreateRecord(1) : CheckError errMessage + record.StringData(1) = Dialog + Set view = database.OpenView(query) : CheckError errMessage + view.Execute record : CheckError errMessage + view.Close : CheckError errMessage +Next + +' Handle Machine Install +If machineInstall Then + ' Update the Word Count Property of the Summary Information Stream + Dim infoStream, wordCount + errMessage = "Cannot update the Word Count Property of the Summary Information Stream" + Set infoStream = database.SummaryInformation(1) : CheckError errMessage ' we will modify 1 property... + Const PID_WORDCOUNT = 15 + wordCount = infoStream.Property(PID_WORDCOUNT) : CheckError errMessage + wordCount = wordCount And Not 8 + infoStream.Property(PID_WORDCOUNT) = wordCount : CheckError errMessage + infoStream.Persist : CheckError errMessage +End If + +' Final Step: Commit ! +database.Commit : CheckError "Cannot commit !" +MsgBox "Successfully updated the MSI file '" & databasePath & "' !" & vbLf & "You can now deploy '" & databasePath & "' to Workstations.", 64, "Status" +Wscript.Quit 0 + +' +' Helper functions +' +Sub InsertOrUpdate(db, query, record, errorMessage) + Const msiViewModifyAssign = 3 + Dim view + + Set view = db.OpenView(query) : CheckError errorMessage + view.Modify msiViewModifyAssign, record : CheckError errorMessage + view.Close : CheckError errorMessage +End Sub + +' +' Error Handling +' +Sub Error(userMessage) + Dim message, msiErr + + message = "" + + ' VB Errors + If Err <> 0 Then + message = Err.Source & " " & Hex(Err) & ": " & Err.Description & vbLf + End If + + ' MSI Errors + If Not installer Is Nothing Then + Set msiErr = installer.LastErrorRecord + If Not msiErr Is Nothing Then message = message & msiErr.FormatText & vbLf End If + End If + + ' Optional Error message + If userMessage = "" Then + Fail "Unexpected Error. Details Follow: " & vbLf & message + Else + Fail userMessage & vbLf & "Error: " & message + End If +End Sub + +Sub CheckError(userMessage) + If Err <> 0 Then + Error userMessage + End If +End Sub + +Sub Fail(message) + MsgBox message, 48, "Status" + Wscript.Quit 2 +End Sub \ No newline at end of file diff --git a/pap/papdb.pl b/pap/papdb.pl new file mode 100755 index 0000000..948b844 --- /dev/null +++ b/pap/papdb.pl @@ -0,0 +1,83 @@ +#!/usr/bin/perl -w + +use strict; +use XML::LibXML; +use Data::Dumper; +use LWP::UserAgent; +use File::Temp qw/tempdir/; +use DBI; + +binmode(STDOUT, ":utf8"); +binmode(STDERR, ":utf8"); + +my $tmp = tempdir(DIR => "tmp"); +my $parser = XML::LibXML->new; +my $dbh = DBI->connect("dbi:Pg:dbname=immodb;host=/var/run/postgresql/", "john", "", {'RaiseError' => 1}); + +sub slurp_p2p_db { + my $filename = shift; + + my %data; + my $dom = $parser->parse_file($filename); + my $root = $dom->getDocumentElement(); + my @placemarks = $root->getElementsByTagNameNS("http://www.opengis.net/kml/2.2", "Placemark"); + foreach my $placemark (@placemarks) { + my $desc = $placemark->getElementsByTagNameNS("http://www.opengis.net/kml/2.2", "description")->[0]->firstChild->data; + my $name = $placemark->getElementsByTagNameNS("http://www.opengis.net/kml/2.2", "name")->[0]->firstChild->data; + my $gps = $placemark->getElementsByTagNameNS("http://www.opengis.net/kml/2.2", "coordinates")->[0]->firstChild->data; + + my $id = "$name|$gps"; + my ($prix_appartement) = $desc =~ m/Appartement<\/span> ([^<]+)<\/span>/g; + $prix_appartement =~ tr/ //d + if defined $prix_appartement; + my ($prix_maison) = $desc =~ m/Maison<\/span> ([^<]+)<\/span>/g; + $prix_maison =~ tr/ //d + if defined $prix_maison; + unless (defined $prix_appartement or defined $prix_maison) { + warn "no price for '$id'"; + next; + } + $data{$id} = { appartement => $prix_appartement, maison => $prix_maison }; + } + return \%data; +} + +warn "Parsing XML files"; +my $ventes = slurp_p2p_db("tmp/kml-vente.xml"); +my $locations = slurp_p2p_db("tmp/kml-location.xml"); + +warn "Updating database"; +my $sth_update = $dbh->prepare('UPDATE ville SET pap_prix_vente_appartement_m2 = ?, pap_prix_vente_maison_m2 = ? WHERE nom = ? AND coordonnees_gps = ?') + or die "could not prepare: ".$dbh->errstr; +my $sth_insert = $dbh->prepare('INSERT INTO ville (nom, coordonnees_gps) VALUES (?, ?)') + or die "could not prepare: ".$dbh->errstr; +foreach my $id (sort keys %{$ventes}) { + my ($nom, $gps) = split /[|]/, $id; + my $prix = $ventes->{$id}; + my $nb = $sth_update->execute($prix->{appartement}, $prix->{maison}, $nom, $gps); + unless ($nb > 0) { + $sth_insert->execute($nom, $gps) + or warn "could not insert $id: ".$sth_insert->errstr; + $sth_update->execute($prix->{appartement}, $prix->{maison}, $nom, $gps) + or warn "could not update $id: ".$sth_update->errstr; + } +} + +$sth_update = $dbh->prepare('UPDATE ville SET pap_prix_location_appartement_m2 = ?, pap_prix_location_maison_m2 = ? WHERE nom = ? AND coordonnees_gps = ?') + or die "could not prepare: ".$dbh->errstr; +foreach my $id (sort keys %{$locations}) { + my ($nom, $gps) = split /[|]/, $id; + my $prix = $locations->{$id}; + my $nb = $sth_update->execute($prix->{appartement}, $prix->{maison}, $nom, $gps); + unless ($nb > 0) { + $sth_insert->execute($nom, $gps) + or warn "could not insert $id: ".$sth_insert->errstr; + $sth_update->execute($prix->{appartement}, $prix->{maison}, $nom, $gps) + or warn "could not update $id: ".$sth_update->errstr; + } +} + +$dbh->commit() + or die "could not commit: ".$dbh->errstr; +$dbh->disconnect(); + diff --git a/soap_testbed/index.html b/soap_testbed/index.html new file mode 100755 index 0000000..243d7bb --- /dev/null +++ b/soap_testbed/index.html @@ -0,0 +1,49 @@ + + + + Web Services TestBed + + + + + + + + + + + + +
Web Service URL:
Login:Password:Domain:
+ + +
Request:
Response:
+ + + diff --git a/stress-test/stress-test.sh b/stress-test/stress-test.sh new file mode 100644 index 0000000..8fc4bda --- /dev/null +++ b/stress-test/stress-test.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +# In case of problem with TIME_WAIT connections +# echo -n 1 > /proc/sys/net/ipv4/tcp_tw_recycle + +P=10 +N=5 + +function do_job { + echo "$(date -R): Worker $i forked..." + + if [ $(($1 % 2)) -eq 0 ]; then + url="http://urla/" + else + url="http://urlb/" + fi + + # rendez-vous ! + read line < "$target/rdv" + echo "$(date -R): Worker $i started on $url..." + + for ((j=0;j "$target/$i/out.log" 2> "$target/$i/err.log" & +done + +wait_time=30 +echo "Waiting $wait_time sec for all childs to initialize..." +sleep $wait_time + +echo "Starting workers for $N requests..." +echo -n > "$target/rdv" + +echo "Waiting for childs..." +wait + +for file in "$target"/*/wrk-*.err; do + exec < $file + read prot code resp + echo $code +done | sort |uniq -c | ( sum=0; while read amount code; do + sum=$((sum + amount)) + echo "$code $amount" +done; echo "total $sum" ) + +exit 0 + diff --git a/sync.pl b/sync.pl new file mode 100755 index 0000000..67c2a30 --- /dev/null +++ b/sync.pl @@ -0,0 +1,175 @@ +#!/usr/bin/perl -w + +use strict; +use Data::Dumper; +use File::Temp; +use POSIX qw/ strftime /; +use POSIX ":sys_wait_h"; + +my $sync_dir = $ENV{HOME}."/sync/"; +my $doclib_path = "/path/to/products"; +my $homes = "rsync.server.example.test"; + +sub version_compare { + my ($a, $b) = @_; + + my @left = split( /\./, $a ); + my @right = split( /\./, $b ); + + my $i = 0; + while ((defined $left[$i]) and (defined $right[$i])) { + my $cmp = $left[$i] <=> $right[$i]; + return $cmp if $cmp; + $i++; + } + return ($left[$i] || 0) <=> ($right[$i] || 0); +} + +sub split_path_with_prefix { + my ($path, $prefix) = @_; + my ($product, $version, $file); + + if (($product, $version, $file) = $path =~ m#^${prefix}([A-Z]+)/(?:[-a-z]+[- ])?\1[- v]([0-9]+\.[0-9]+(?:\.[0-9]+)?)(/.+)?$#i) { + return ($product, $version, $file); + } + return; +} + +print "\n+".("-"x76)."+\n"; +print "|".(" "x31)."ACME Data Sync".(" "x31)."|\n"; +print "+".("-"x76)."+\n\n"; + + +open FIND_PRODUCTS, "-|", "ssh $homes find $doclib_path -maxdepth 2 -type d" + or die "open: ssh: $!"; + +my %keep = map { $_ => 1 } qw/PRODUCTA PRODUCTB PRODUCTC/; +my %available_products; + +while (my $path = ) { + chomp $path; + my ($product, $version, $file) = split_path_with_prefix($path, $doclib_path); + next unless defined $product and $keep{$product}; + $path = substr $path, length $doclib_path; + $available_products{$product}->{$version} = $path; +} + +close FIND_PRODUCTS; + +my %remote_major_versions; +while (my ($product, $versions) = each(%available_products)) { + my @versions = keys %{$versions}; + + # Compute major versions + @versions = sort {version_compare($a, $b)} @versions; + my %versions = map { m/^([0-9]+\.[0-9]+)/; $1 => $_ } @versions; + $remote_major_versions{$product} = \%versions; +} + +my %local_versions; +open FIND_LOCAL_PRODUCTS, "-|", "find $sync_dir -maxdepth 2 -type d" + or die "open: find: $!"; +while (my $path = ) { + chomp $path; + my ($product, $version, $file) = split_path_with_prefix($path, $sync_dir); + next unless defined $product; + $path = substr $path, length $sync_dir; + push @{$local_versions{$product}}, { version => $version, path => $path }; +} +close FIND_LOCAL_PRODUCTS; + +my %local_major_versions; +while (my ($product, $versions) = each(%local_versions)) { + my @versions = sort {version_compare($a, $b)} map { $_->{version} } @{$versions}; + my %versions = map { m/^([0-9]+\.[0-9]+)/; $1 => $_ } @versions; + $local_major_versions{$product} = \%versions; +} + +my %upgrades; +my %new_versions; +while (my ($product, $versions) = each(%remote_major_versions)) { + # Upgrade already fetched major versions + while (my ($major_version, $minor_version) = each(%{$versions})) { + if (exists $local_major_versions{$product} and exists $local_major_versions{$product}->{$major_version}) { + # Upgrade ? + if (version_compare($remote_major_versions{$product}->{$major_version}, $local_major_versions{$product}->{$major_version}) > 0) { + # Upgrade needed + $upgrades{$product}->{$local_major_versions{$product}->{$major_version}} = $minor_version; + } + } + } + + # Fetch the last version of new products + my @sorted_versions = sort {-version_compare($a, $b)} keys %{$versions}; + unless (defined $local_major_versions{$product}) { + push @{$new_versions{$product}}, $remote_major_versions{$product}->{$sorted_versions[0]}; + next; + } + + # Fetch new major versions of existing products + foreach my $version (@sorted_versions) { + last if exists $local_major_versions{$product}->{$version}; + push @{$new_versions{$product}}, $remote_major_versions{$product}->{$version}; + } +} + +unless ((scalar keys %new_versions) + (scalar keys %upgrades)) { + print "Nothing to do !\n"; + exit; +} + +print "New Versions: \n"; +foreach my $product (sort keys %keep) { + if (exists $upgrades{$product}) { + while (my ($major, $minor) = each(%{$upgrades{$product}})) { + print " $product".(" "x(16 - length $product))."$minor\n"; + } + } + if (exists $new_versions{$product}) { + foreach my $version (@{$new_versions{$product}}) { + print " $product".(" "x(16 - length $product))."$version\n"; + } + } +} + +print "\nSync is starting...\n\n"; + +# Start RSYNC +pipe FROM_FATHER, TO_RSYNC0; +my $pid_rsync = fork(); +die "fork: $!" unless defined $pid_rsync; +if ($pid_rsync == 0) { # Child: RSYNC + close TO_RSYNC0; + + open STDIN, '<&', \*FROM_FATHER; + + exec "rsync", "-aizy", "--progress", "--filter=. -", "$homes:$doclib_path", $sync_dir + or die "exec: rsync: $!"; + # Child stops here +} # The father continues... + +# Clean up... +close FROM_FATHER; + +# Dump files to sync +my %seen_product_path; +while (my ($product, $versions) = each(%new_versions)) { + foreach my $version (@{$versions}) { + my $path = $available_products{$product}->{$version}; + my ($product_path, @remaining_items) = split "/", $path; + unless (defined $seen_product_path{$product_path}) { + print TO_RSYNC0 "+ /$product_path\n"; + $seen_product_path{$product_path} = 1; + } + print TO_RSYNC0 "+ /$path\n"; + print TO_RSYNC0 "+ /$path/**\n"; + } +} +print TO_RSYNC0 "- *\n"; + +# No more file to sync, notify RSYNC... +close TO_RSYNC0; + +# Wait for RSYNC +waitpid $pid_rsync, 0; + diff --git a/testbed_js/index.html b/testbed_js/index.html new file mode 100644 index 0000000..dc21770 --- /dev/null +++ b/testbed_js/index.html @@ -0,0 +1,41 @@ + + + +Dojo Testbed + + + + + +

Your code

+ +
+ +

Screen:

+
+ +

Stacktrace (if any):

+

+
+
+