
| Current Path : /var/www/web-klick.de/dsh/50_dev2017/1300__perllib/DivBasicF/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/web-klick.de/dsh/50_dev2017/1300__perllib/DivBasicF/AutoMakePackage.pm |
package DivBasicF::AutoMakePackage;
use strict;
use Cwd;
use File::Copy;
use File::Path;
use DivBasicF::Recursive;
use Crypt::Blowfish;
use Crypt::CBC;
use MIME::Base64;
sub new {
my $class = shift;
my $self = {};
my $key = shift;
if ($key) {
$self->{'GLOBALKEY'} = $key;
$self->{'CIPHER'} = Crypt::CBC->new( -key => $key, -cipher => 'Blowfish' );
}
bless($self,$class);
return($self);
}
#*****************************************************************
#
# This function has been tested under Ubuntu
#
# To make a package from the git autotest directory,
# change into the main directory of autotest (where
# AutoQX, DivBasicF, ... are subdirectories of it.
#
#
# PREREQUISITES:
#
# Installed Qooxdoo SDK
# Crypt::Blowfish
# Crypt::CBC
# Module::Crypt
# CGI
# CGI::Session
# DBI
# DBD::SQLite
# Time::HiRes
# MIME::Base64
# Cwd
# File::Copy
# File::Path
#
#
# 1. Then call (under Ubuntu):
#
# perl DivBasicF/perl_caller <secret_key> DivBasicF::AutoMakePackage::make_package <label>
#
# to build a new build package <label>.zip of autotest, and:
#
# perl DivBasicF/perl_caller <secret_key> DivBasicF::AutoMakePackage::make_package .<label>
#
# to build a new source package <label>.zip of autotest
# (only for development purposes.
#
# 2. Find the new package as /tmp/<label>.zip
#
# Each module under DivBasicF which contains the function
# sub DELIVER { 2 }
# is Blowfish-encrypted via the <secret-key>.
#
# Each module under DivBasicF which contains the function
# sub DELIVER { 3 }
# is NOT stored with ending .pm but .xs. It shall be converted
# in a system dependend dynamic library with step 3.
# THIS MODE IS MANDATORY FOR IfTProgramReader.pm !!!
#
# Each module under DivBasicF which contains the function
# sub DELIVER { -1 }
# is skipped and NOT part of the deployment package <label>.zip.
#
# All other modules under DivBasicF stay unencrypted and are parts
# of the deployment package <label>.zip.
#
# 3. To make the deployment package <label>.zip runnable under different
# perl environments, put the <label>.zip in an empty directory onto a
# machine which contains the perl environment that shall be supported.
# Then call:
#
# unzip <label>.zip *pl
# perl ver_<label>.pl
#
# After that, the deployment package <label>.zip contains system dependent
# dynamic libraries which are constructed from the .xs-Files in DivBasicF
# and the secret key.
#
# Repeat this on all machines and 'perl's you want to support.
#
# PREREQUSITE FOR STEP 3: Module::Crypt has to be installed.
# HINT for Windows: This only works with Strawberry. but only if you
# skip the tests during installing Module::Crypt. For that, make:
# cpan; cpan> notest install Module::Crypt
# Then search the installed file Crypt.pm under
# \<strawberry-directory>\perl\site\Module\Crypt.pm,
# look for the line containig the string:
# foreach qw([bs a bundle so]) {
# and change it to:
# foreach qw([bs a bundle so dll]) {
# (Reason: Otherwise the recently built dll's will be instantly deleted!)
#
#
# 4. Purifying the deployment package
# For nobody to make see the source code of the .xs-files, purify at the
# end the <label>.zip via:
#
# unzip <label>.zip *pl
# perl ver_<label>.pl 1
#
# After that generation of dynamic libraries as been done in
# step 3 is NO MORE POSSIBLE: The remaining .xs-files are deleted now.
#
# 5. Installation
#
# Now the install package <label>.zip is ready and can be installed
# on all supported systems belonging to step 3. Even Strawberry is used
# in Step 3, ActiveState should be then supported, too.
#
# If you unzip the <label>.zip, there are scripts install.bat (install.sh)
# and deinstall.bat (deinstall.sh) which contain explications.
sub make_package {
my $self = shift;
my $project1 = shift;
my $qooxdoo_dir = shift;
my $source = 0;
$source = 1 if ($qooxdoo_dir =~ s/^\.//);
$source = 1 if ($project1 =~ s/^\.//);
$qooxdoo_dir = "/opt/qooxdoo-3.0.1-sdk" if (!$qooxdoo_dir);
$project1 = "autotest" if (!$project1);
my $project = "autotest";
my $git_dir = `pwd`;
$git_dir =~ s/\n//gs;
my $text; my $o; my $o1; my $o2; my $text1; my $text9;
my $keys; my $cipher; my $text_original;
my $git_log = `git log`;
if (!(-d("$git_dir/AutoQX"))) {
print("start this script from the root directory of the autotest git repository $git_dir\n");
return();
}
system("rm -rf /tmp/$project");
system("rm -rf /tmp/$project1");
# system("rm -f /tmp/$project1.zip");
chdir("/tmp");
system("$qooxdoo_dir/tool/bin/create-application.py -n $project");
system("rm -rf /tmp/$project/source/class/$project/*");
system("ln -s $git_dir/AutoQX/*.js /tmp/$project/source/class/$project/");
system("ln -s $git_dir/AutoQX/theme /tmp/$project/source/class/$project/");
system("ln -s $git_dir/AutoQX/translation /tmp/$project/source/class/$project/");
system("ln -s $git_dir/AutoQX/resource/$project/* /tmp/$project/source/resource/$project/");
chdir($project);
mkdir("/tmp/$project/htdocs");
mkdir("/tmp/$project/cgi-bin");
mkdir("/tmp/$project/htdocs/$project1");
mkdir("/tmp/$project/cgi-bin/$project1");
if ($source) {
system("./generate.py source");
system("mv source/* /tmp/$project/htdocs/$project1");
system("ln -s $qooxdoo_dir/framework /tmp/$project/htdocs/$project1");
open(FFILE,"/tmp/$project/htdocs/$project1/script/$project.js");
$text = join("",<FFILE>);
close(FFILE);
$text =~ s/\"(resourceUri|sourceUri)\"\:\"\.\.\/source\//\"$1\"\:\"/g;
$text =~ s/\"(resourceUri|sourceUri)\"\:\"([^\"]*?)framework/\"$1\"\:\"framework/g;
open(FFILE,">htdocs/$project1/script/$project.js");
print FFILE $text;
close(FFILE);
} else {
system("./generate.py build");
system("mv build/* /tmp/$project/htdocs/$project1");
system("ln -s $git_dir/AutoQX/resource/$project/* /tmp/$project/htdocs/$project1/resource/$project");
}
system("cp -r $git_dir/AutoQX/index.html /tmp/$project/htdocs/$project1");
mkdir("/tmp/$project/cgi-bin/$project1/DivBasicF");
mkdir("/tmp/$project/cgi-bin/$project1/Spreadsheet");
mkdir("/tmp/$project/cgi-bin/$project1/Spreadsheet/WriteExcel");
mkdir("/tmp/$project/cgi-bin/$project1/Qooxdoo");
system("cp $git_dir/DivBasicF/perl_caller /tmp/$project/cgi-bin/$project1/DivBasicF");
system("cp $git_dir/Spreadsheet/* /tmp/$project/cgi-bin/$project1/Spreadsheet");
system("cp $git_dir/Spreadsheet/WriteExcel/* /tmp/$project/cgi-bin/$project1/Spreadsheet/WriteExcel");
system("cp $git_dir/Qooxdoo/* /tmp/$project/cgi-bin/$project1/Qooxdoo");
system("cp $git_dir/index.cgi /tmp/$project/cgi-bin/$project1");
system("cp $git_dir/bin/* /tmp/$project/cgi-bin/$project1");
# system("cp $git_dir/AutoSkript.pm /tmp/$project/cgi-bin/$project1");
unshift(@INC,$git_dir);
opendir(DDIR,"$git_dir/DivBasicF");
while (0 == 0) {
$o = readdir(DDIR);
last if (!$o);
next if ($o !~ /^(.*)(\.pm)$/);
$o = $1;
eval("use DivBasicF::$o");
$o1 = 0;
# eval("\$o1 = DivBasicF::$o->DELIVER()"); # wird diese zeile auskommentiert, wird Verschluesselung ausgeschaltet
if ($o1 == 3) {
system("cp $git_dir/DivBasicF/$o.pm /tmp/$project/cgi-bin/$project1/DivBasicF/$o.xs");
if ($o eq "IfTProgramReader") {
open(FFILE,"</tmp/$project/cgi-bin/$project1/DivBasicF/$o.xs");
$o1 = join("",<FFILE>);
close(FFILE);
$o1 =~ s/(\-key *\=\> *\')(.*?)(\' *, *\-cipher)/$1$self->{'GLOBALKEY'}$3/;
open(FFILE,">/tmp/$project/cgi-bin/$project1/DivBasicF/$o.xs");
print FFILE $o1;
close(FFILE);
}
}
elsif ($o1 == 2 or !$o1) { # mit Blowfish verschluesselt oder keine Verschluesselung
open(FFILE,"<"."$git_dir/DivBasicF/$o.pm");
if ($o1 and (!($self->{'CIPHER'}))) {
print "CIPHER has to be given! ...\n\n"; exit;
}
$text1 = join("",<FFILE>);
close(FFILE);
$text9 = $text1; # Umverschluesseln
if ($text1 =~ s/^use +DivBasicF::IfTProgramReader\;\n *\n//s) {
while (0 == 0) {
last if ($text9 =~ /package /);
$text9 = "___WRONG_KEY___";
if (!(ref($keys))) {
$keys = [split(/[,\:\;]/,$ENV{'cryptkeys'})];
} else {
shift(@$keys);
}
last if (!@$keys);
$cipher = Crypt::CBC->new( -key => $keys->[0], -cipher => 'Blowfish' );
$text9 = $cipher->decrypt( decode_base64($text1) );
}
}
if ($text9 =~ /___WRONG_KEY___/ and $text9 !~ /package/) {
print "Decryption of $o.pm not possible...\n";
$o1 = 0;
$text1 = "use DivBasicF::IfTProgramReader\;\n\n" . $text1;
} else {
$text1 = $text9;
}
$text_original = $text1;
if ($text1 =~ s/(sub +autoitem\_)(py|pm|version)( +\{.*?CODE_ENDE[^\n]*\n)(.*?)(CODE_ENDE)/$1$2$3---AUTOITEM-$2---$5/gas) {
foreach $cipher ("py","pm","version") {
if ($cipher eq "version") {
$text9 = $text1;
$text9 =~ s/---AUTOITEM-version---/\nGit version of AutoTest\n\n/;
open(FFILE,">"."$git_dir/DivBasicF/$o.pm");
print FFILE $text9;
close(FFILE);
$o2 = $git_log;
$o2 =~ s/^(.*?)(commit.*?)(commit.*)$/$2/s;
} else {
open(FFILE,"<$git_dir/autoitem.$cipher"); # include the autoitem.py
$o2 = join("",<FFILE>);
close(FFILE);
}
$o2 =~ s/ +$//s;
if ($o2) {
$text1 =~ s/---AUTOITEM-$cipher---/$o2/i;
}
}
} else {
$text_original = "";
}
$text1 = "use DivBasicF::IfTProgramReader;\n\n" .
encode_base64 ( $self->{'CIPHER'}->encrypt($text1) ) if ($o1);
open(FFILE,">$git_dir/DivBasicF/$o.ENCRYPT.pm");
print FFILE $text1;
close(FFILE);
system("cp $git_dir/DivBasicF/$o.ENCRYPT.pm /tmp/$project/cgi-bin/$project1/DivBasicF/$o.pm");
unlink("$git_dir/DivBasicF/$o.ENCRYPT.pm");
if ($text_original) {
open(FFILE,">$git_dir/DivBasicF/$o.pm");
print FFILE $text_original;
close(FFILE);
}
}
# elsif (!$o1) { # keine Verschluesselung
# system("cp $git_dir/DivBasicF/$o.pm /tmp/$project/cgi-bin/$project1/DivBasicF/$o.pm");
# }
}
chdir("/tmp");
$text = <<"TEXT_ENDE" . "perl DivBasicF/perl_caller DivBasicF::AutoInstall::install $project1";
install script takes as a single parameter: an Apache Configuration file,
# for example: /etc/apache2/sites-available/default.
#
# The htdocs and cgi-bin entries will be made (resp. deinstalled).
#
# The site then is reachable under: <apache-site>/$project1
#
# OR:
# one parameter which is the directory of the backend and
# an optional second parameter which is the directory of the
# frontend (this is only tested under Ubuntu).
#
# If the directory in which this script is located is renamed,
# for example to: foo, a renamed installation in htdocs and
# cgi-bin is made, and the autotest-site is then reachable under
# <apache-site>/foo
#
# The parent directory of the directory containing this
# script will be choosen as the general test project directory.
#
#
# If you want to use only the backend via the concosle commands
# ot and ox, then search the installtion directory of the
# backend, there call: env_autotest (Windows) / source env_autotest (Ubuntu)
#
#
# PREREQUSITES:
# -------------
# You have to be installed Perl (Ubuntu native Perl, or Strawberry or ActiveState
# under Windows), and a running Apache Server which config file location
# is known.
#
# Be sure that you have the following perl modules installed:
# CGI, CGI::Session, DBI, DBD::SQLite, Crypt::Blowfish; Crypt:CBC, Time::HiRes,
# MIME::Base64, Cwd, File::Copy, File::Path. If not, install them by running
#
# cpan install <package> or ppm install <package>
cd cgi-bin
cd $project1
export PERL5LIB=.
TEXT_ENDE
$o1 = "cd ..\ncd ..\n";
mkdir($project1);
open(FFILE,">$project1/install.sh");
print FFILE "\# This " . $text . " \$1 \$2\n";
close(FFILE);
open(FFILE,">$project1/deinstall.sh");
print FFILE "\# This de" . $text . " \$1 ___DEINSTALL___\n";
close(FFILE);
$text =~ s/\#/REM/gs;
$text =~ s/\nexport /\nset /gs;
open(FFILE,">$project1/install.bat");
print FFILE "\@echo off\nREM This " . $text . " \%1 \%2\n" . $o1;
close(FFILE);
open(FFILE,">$project1/deinstall.bat");
print FFILE "\@echo off\nREM This de" . $text . " \%1 ___DEINSTALL___\n" . $o1;
close(FFILE);
open(FFILE,">$project1/README.TXT");
print FFILE <<'TEXT_ENDE';
Installation for Windows:
1. Open a command shell (Ausfuehren -> cmd -> Enter). Be sure to open it as Administrator under Windows 7.
2. Go into the directory where the file READE.TXT (this file!) is inside, then execute:
install.bat C: C: <enter>
3. Copy the file C:\<autotestdir>\shell_autotest.bat onto your Desktop.
4. Click on shell_autotest.bat on your Desktop. A shell opens where all
functionalities of AutoTest are available (e.g. the or command).
TEXT_ENDE
close(FFILE);
system("chmod a+rwx $project1/*install.*");
system("chmod a+rwx $project1/README.*");
if ($project ne $project1) {
system("mv $project/htdocs $project1/htdocs");
system("mv $project/cgi-bin $project1/cgi-bin");
# system("rm -rf /tmp/$project");
}
if ($git_log =~ /\S/) {
open(FFILE,">$project1/CHANGELOG.txt");
print FFILE $git_log;
close(FFILE);
system("chmod a+rwx $project1/CHANGELOG.txt");
}
system("zip -r $project1 $project1") if (!(-f("$project1.zip")));
open(FFILE,">ver_$project1.pl");
$o = <<'TEXT_ENDE';
use File::Path;
my $ver = `perl -v`;
$ver =~ s/^(.*?)\((.*?)\) +built +for +(.*?)\n(.*)$/$2\_\_$3/si;
if (!@ARGV) {
system("unzip ---PROJECT1---.zip ---PROJECT1---/cgi-bin/---PROJECT1---/auto_$ver/*");
if (!(-d("---PROJECT1---"))) {
system("unzip ---PROJECT1---.zip ---PROJECT1---/cgi-bin/---PROJECT1---/DivBasicF/*");
chdir("---PROJECT1---/cgi-bin/---PROJECT1---");
system("perl DivBasicF/perl_caller DivBasicF/AutoMakePackage make_obj $ver");
chdir("../../..");
system("zip -r ---PROJECT1--- ---PROJECT1---/cgi-bin/---PROJECT1---/auto_$ver/*");
system("zip -ur ---PROJECT1--- ---PROJECT1---/cgi-bin/---PROJECT1---/DivBasicF/*");
}
rmtree("---PROJECT1---");
} else {
system("zip -d ---PROJECT1--- ---PROJECT1---/cgi-bin/---PROJECT1---/DivBasicF/*.xs");
system("zip -d ---PROJECT1--- ver_*");
}
unlink("ver_---PROJECT1---.pl");
TEXT_ENDE
$o =~ s/---PROJECT1---/$project1/g;
print FFILE $o;
close(FFILE);
system("zip -r $project1 ver_$project1.pl");
system("chmod a+rwx ver_$project1.pl");
return("Install package $project1.zip generated.");
}
#*****************************************************************
# needed for encryption of DELIVER-3-modules. That modules
# will be transformed into system dependent library files
sub make_obj {
my $self = shift;
my $ver = shift;
my $o;
my @modules = ();
opendir(DDIR,"DivBasicF");
while (0 == 0) {
$o = readdir(DDIR);
last if (!$o);
next if ($o !~ /^(.*)\.xs$/);
push(@modules,$1);
}
closedir(DDIR);
my $key = "";
open(FFILE,"<DivBasicF/IfTProgramReader.xs");
$o = join("",<FFILE>);
close(FFILE);
if ($o =~ /\-key *\=\> *\'(.*?)\' *, *\-cipher/) {
$key = $1;
}
eval("use Module::Crypt");
foreach $o (@modules) {
copy("DivBasicF/$o.xs","DivBasicF/$o.pm");
CryptModule( file => "DivBasicF/$o.pm", install_base => "_auto_$ver", password => $key );
unlink("DivBasicF/$o.pm");
copy("_auto_$ver/DivBasicF/$o.pm","DivBasicF/$o.pm");
unlink("_auto_$ver/DivBasicF/$o.pm");
}
DivBasicF::Recursive::dirmove("_auto_$ver/auto","auto_$ver");
rmdir("_auto_$ver/DivBasicF");
rmdir("_auto_$ver");
}
1;