commit
676f7bdc63
23 changed files with 1242 additions and 0 deletions
@ -0,0 +1,2 @@ |
|||||
|
.DS_Store |
||||
|
.vscode |
||||
@ -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 = <SMB_FILE>; |
||||
|
$/ = $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 (<FROM_CPIO2>) { |
||||
|
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; |
||||
|
|
||||
|
|
||||
@ -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 |
||||
@ -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 |
||||
|
|
||||
@ -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" |
||||
@ -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 |
||||
|
) |
||||
|
|
||||
@ -0,0 +1,3 @@ |
|||||
|
@ECHO OFF |
||||
|
CSCRIPT.EXE convert-all-ppt-to-pdf.vbs |
||||
|
PAUSE |
||||
@ -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 |
||||
|
|
||||
@ -0,0 +1,3 @@ |
|||||
|
@ECHO OFF |
||||
|
CSCRIPT.EXE convert-all-xls-to-csv.vbs |
||||
|
PAUSE |
||||
@ -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 |
||||
|
|
||||
@ -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 |
||||
@ -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 |
||||
|
|
||||
@ -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 <<LDIF; |
||||
|
dn: o=$org |
||||
|
o: $org |
||||
|
objectClass: organization |
||||
|
|
||||
|
LDIF |
||||
|
$o{$org} = {}; |
||||
|
} |
||||
|
if (not exists $o{$org}->{$ou}) { |
||||
|
print <<LDIF; |
||||
|
dn: ou=$ou, o=$org |
||||
|
ou: $ou |
||||
|
objectClass: organizationalUnit |
||||
|
|
||||
|
LDIF |
||||
|
$o{$org}->{$ou} = 1; |
||||
|
} |
||||
|
print <<LDIF; |
||||
|
dn: cn=$cn,ou=$ou,o=$org |
||||
|
givenName: $first_name |
||||
|
sn: $family_name |
||||
|
userPassword: changem |
||||
|
mail: $long_uid\@example.test |
||||
|
telephoneNumber: 123456 |
||||
|
objectClass: top |
||||
|
objectClass: inetOrgPerson |
||||
|
objectClass: pkiUser |
||||
|
uid: $short_uid |
||||
|
cn: $cn |
||||
|
|
||||
|
LDIF |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,15 @@ |
|||||
|
#!/bin/sh |
||||
|
|
||||
|
cd ~/bin/ldap || exit 1 |
||||
|
|
||||
|
./gen_ldif_users.pl < users.csv > 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 |
||||
|
|
||||
@ -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 |
||||
|
|
||||
|
|
||||
@ -0,0 +1,3 @@ |
|||||
|
#!/bin/bash |
||||
|
|
||||
|
netstat -tnp |tail -n +3 | tr -s " " |cut -d " " -f 6 |sort |uniq -c |
||||
@ -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 |
||||
@ -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/<span class='label'>Appartement<\/span> <span class='prix'>([^<]+)<\/span>/g; |
||||
|
$prix_appartement =~ tr/ //d |
||||
|
if defined $prix_appartement; |
||||
|
my ($prix_maison) = $desc =~ m/<span class='label'>Maison<\/span> <span class='prix'>([^<]+)<\/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(); |
||||
|
|
||||
@ -0,0 +1,49 @@ |
|||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
||||
|
<html> |
||||
|
<head> |
||||
|
<title>Web Services TestBed</title> |
||||
|
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.4/dojo/dojo.xd.js" |
||||
|
type="text/javascript"></script> |
||||
|
<script type="text/javascript"> |
||||
|
dojo.addOnLoad(function () { |
||||
|
dojo.connect(dojo.byId("test"), "onclick", null, function() { |
||||
|
try { |
||||
|
if (window.XMLHttpRequest) { |
||||
|
httpRequest = new XMLHttpRequest(); |
||||
|
} else if (window.ActiveXObject) { |
||||
|
httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); |
||||
|
} |
||||
|
httpRequest.open("POST", dojo.attr(dojo.byId("ws_url"), "value"), true); |
||||
|
if (httpRequest.overrideMimeType) { |
||||
|
httpRequest.overrideMimeType("text/xml"); |
||||
|
} |
||||
|
httpRequest.onreadystatechange = function () { if (httpRequest.readyState == 4) { dojo.byId("ws_response").innerHTML = httpRequest.responseText; } }; |
||||
|
httpRequest.setRequestHeader("MessageType", "CALL"); |
||||
|
httpRequest.setRequestHeader("Content-Type", "text/xml"); |
||||
|
|
||||
|
httpRequest.send(dojo.attr(dojo.byId("ws_request")); |
||||
|
} catch (err) { |
||||
|
dojo.byId("ws_response").innerHTML = err; |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
</script> |
||||
|
</head> |
||||
|
<body> |
||||
|
<table> |
||||
|
<tr> |
||||
|
<td colspan='3'>Web Service URL:<input type='text' id='ws_url' value='http://server.example.test' size='120'></td> |
||||
|
</tr><tr> |
||||
|
<td>Login:<input type='text' id='login' value='john'></td> |
||||
|
<td>Password:<input type='password' id='password' value='changeme'></td> |
||||
|
<td>Domain:<input type='text' id='domain' value='test'></td> |
||||
|
</tr> |
||||
|
</table> |
||||
|
<table> |
||||
|
<tr><td>Request:<br><textarea id='ws_request' cols='80' rows='25'> |
||||
|
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Header></soapenv:Header><soapenv:Body></soapenv:Body></soapenv:Envelope> |
||||
|
</textarea></td><td>Response:<br><textarea id='ws_response' cols='80' rows='25'></textarea></td></tr> |
||||
|
</table> |
||||
|
<input type='button' value='Test !' id='test' name='test'> |
||||
|
</body> |
||||
|
</html> |
||||
@ -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<N; j++)); do |
||||
|
wget -q -O /dev/null -o "$2/wrk-$j.err" --server-response "$url" |
||||
|
done |
||||
|
echo "$(date -R): Worker $i stopping..." |
||||
|
} |
||||
|
|
||||
|
echo "Forking $P workers..." |
||||
|
|
||||
|
target="$(date "+%Y-%m-%d_%H-%M-%S")" |
||||
|
mkdir "$target" |
||||
|
mkfifo "$target/rdv" |
||||
|
|
||||
|
for ((i=0;i<P; i++)); do |
||||
|
mkdir -p "$target/$i" |
||||
|
(do_job $i "$target/$i") > "$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 |
||||
|
|
||||
@ -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 = <FIND_PRODUCTS>) { |
||||
|
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 = <FIND_LOCAL_PRODUCTS>) { |
||||
|
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; |
||||
|
|
||||
@ -0,0 +1,41 @@ |
|||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
||||
|
<html> |
||||
|
<head> |
||||
|
<title>Dojo Testbed</title> |
||||
|
<script type="text/javascript" |
||||
|
src="dojo-release-1.3.3/dojo/dojo.js.uncompressed.js" |
||||
|
djConfig="parseOnLoad: true, isDebug: true"></script> |
||||
|
<script type="text/javascript"> |
||||
|
function process() { |
||||
|
dojo.byId("stacktrace").innerHTML = ""; |
||||
|
var code = dojo.byId('code').value; |
||||
|
try { |
||||
|
eval(code); |
||||
|
} catch (x) { |
||||
|
dojo.byId("stacktrace").innerHTML = x; |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
|
<style type="text/javascript"> |
||||
|
#screen { |
||||
|
background-color: #AAAAAA; |
||||
|
} |
||||
|
</style> |
||||
|
</head> |
||||
|
<body> |
||||
|
<p>Your code</p> |
||||
|
<textarea rows="25" cols="80" id="code"> |
||||
|
dojo.byId("screen").innerHTML = ""; |
||||
|
dojo.require("dijit.form.TextBox"); |
||||
|
new dijit.form.TextBox({style: "width: 100px"}, dojo.create("input", {}, dojo.byId("screen"))); |
||||
|
</textarea> |
||||
|
<br><input type="button" onclick="process();" value="Execute !"> |
||||
|
|
||||
|
<p>Screen:</p> |
||||
|
<div id='screen'></div> |
||||
|
|
||||
|
<p>Stacktrace (if any):</p> |
||||
|
<pre id='stacktrace'></pre> |
||||
|
|
||||
|
</body> |
||||
|
</html> |
||||
Loading…
Reference in new issue