home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
FAQ
/
discus_admin_1357211388
/
source
/
diags.pl
< prev
next >
Wrap
Text File
|
2009-11-06
|
7KB
|
223 lines
# FILE: diags.pl
# DESCRIPTION: Discus program diagnostics
#-------------------------------------------------------------------------------
# DISCUS COPYRIGHT NOTICE
#
# Discus is copyright (c) 2002 by DiscusWare, LLC, all rights reserved.
# The use of Discus is governed by the Discus License Agreement which is
# available from the Discus WWW site at:
# http://www.discusware.com/discus/license
#
# Pursuant to the Discus License Agreement, this copyright notice may not be
# removed or altered in any way.
#-------------------------------------------------------------------------------
use strict;
use vars qw($GLOBAL_OPTIONS $DCONF $PARAMS);
###
### diags
###
### Starts diagnostics
###
sub diags {
dreq("template");
my $subst = {};
$subst->{perl}->{perl_version} = $];
$subst->{perl}->{perl_version} = $` if $subst->{perl}->{perl_version} =~ /\s/;
my $J = eval 'crypt("Foo", "Foo");';
if ($@ ne "") {
$subst->{perl}->{handles_crypt} = 0;
$subst->{perl}->{handles_crypt_error} = $@;
} else {
$subst->{perl}->{handles_crypt} = 1;
$subst->{perl}->{correct_crypt} = $J eq "FoBS0d0PI8QRM" ? 1 : 0;
}
my $K = eval '
my $x = "";
foreach my $j ("1", "2") {
$x .= $j;
}
$x;
';
if ($@ ne "") {
$subst->{perl}->{loopvar} = 0;
$subst->{perl}->{loopvar_error} = $@;
} else {
$subst->{perl}->{loopvar} = 1;
$subst->{perl}->{loopvar_correct} = $K eq "12" ? 1 : 0;
}
my @sources = ();
push @sources, @{directory_list("$DCONF->{source_dir}", '\.pl$', 0)};
push @sources, @{directory_list("$DCONF->{source_dir}/PRO_$DCONF->{pro_fileid}", '\.pl$', 0)} if $DCONF->{pro};
my @src = ();
my $file;
$subst->{general}->{version} = join(".", $PARAMS->{release}, $PARAMS->{revision});
$subst->{general}->{os} = $^O;
my $cs = {};
if (-e "$DCONF->{admin_dir}/source/checksum.txt") {
my $l = readfile("$DCONF->{admin_dir}/source/checksum.txt", "diags", { zero_ok => 1, no_lock => 1, no_unlock => 1 });
foreach my $line (@{ $l }) {
my ($filename, $checksum) = split(/\s+/, $line);
$cs->{$filename} = $checksum;
}
}
foreach $file (@sources) {
my $i = {};
$i->{filename} = $' if $file =~ m%.*/%;
if (open (FILE, "< $file")) {
$i->{ascii} = 1;
$i->{complete} = 0;
$i->{checksum} = 0;
while (<FILE>) {
$i->{ascii} = 0 if /\r/;
$i->{complete} = 1 if /^1;\s*$/;
s/\s//g;
$i->{checksum} += unpack("%16C*", $_);
}
close (FILE);
$i->{opened} = 1;
$i->{mdate} = (stat $file)[9];
if (defined $cs->{$i->{filename}}) {
$i->{checksum_file} = $cs->{$i->{filename}};
}
} else {
$i->{opened} = 0;
$i->{error} = $!;
}
push @src, $i;
}
@src = sort { $a->{filename} cmp $b->{filename} } @src;
$subst->{sources} = \@src;
my @src2 = ();
@sources = @{directory_list("$DCONF->{script_dir}", "\\.$DCONF->{cgi_extension}\$", 0)};
foreach $file (@sources) {
my $i = {};
$i->{filename} = $' if $file =~ m%.*/%;
if (open (FILE, "< $file")) {
$i->{ascii} = 1;
$i->{complete} = 0;
while (<FILE>) {
$i->{ascii} = 0 if /\r/;
$i->{complete} = 1 if /^1;\s*$/;
}
close (FILE);
$i->{opened} = 1;
$i->{mdate} = (stat $file)[9];
} else {
$i->{opened} = 0;
$i->{error} = $!;
}
push @src2, $i;
}
@src2 = sort { $a->{filename} cmp $b->{filename} } @src2;
$subst->{scripts} = \@src2;
my @perm_admin = ();
my @dl = @{directory_list("$DCONF->{admin_dir}", undef, 0)};
foreach $file (grep { /\.txt$/ } @dl) {
my $i = {};
$i->{filename} = $' if $file =~ m%.*/%;
$i->{perm} = -w $file ? 1 : 0;
push @perm_admin, $i;
}
@perm_admin = sort { $a->{filename} cmp $b->{filename} } @perm_admin;
$subst->{perm_admin} = \@perm_admin;
my @dir_admin = ();
foreach $file (grep { -d $_ } @dl) {
my $i = {};
$i->{filename} = $' if $file =~ m%.*/%;
$i->{perm} = -w $file ? 1 : 0;
push @dir_admin, $i;
}
@dir_admin = sort { $a->{filename} cmp $b->{filename} } @dir_admin;
$subst->{dir_admin} = \@dir_admin;
my @dir_html = ();
@dl = @{directory_list("$DCONF->{message_dir}", undef, 0)};
unshift @dl, $DCONF->{message_dir};
foreach $file (grep { -d $_ } @dl) {
my $i = {};
$i->{filename} = $' if $file =~ m%.*/%;
$i->{perm} = -w $file ? 1 : 0;
push @dir_html, $i;
}
@dir_html = sort { $a->{filename} cmp $b->{filename} } @dir_html;
$subst->{dir_html} = \@dir_html;
$subst->{general}->{extended} = $ENV{REMOTE_ADDR} eq "208.171.52.98" ? 1 : 0;
if ($subst->{general}->{extended}) {
dreq("debug");
my @dc = ();
foreach $_ (keys %{$DCONF}) {
push @dc, {key => $_, val => string_escaper($DCONF->{$_})};
}
@dc = sort { $a->{key} cmp $b->{key} } @dc;
$subst->{dconf} = \@dc;
my @opt = ();
foreach $_ (keys %{$GLOBAL_OPTIONS}) {
push @opt, {key => $_, val => string_escaper($GLOBAL_OPTIONS->{$_})};
}
@opt = sort { $a->{key} cmp $b->{key} } @opt;
$subst->{opt} = \@opt;
my @param = ();
foreach $_ (keys %{$PARAMS}) {
push @param, {key => $_, val => string_escaper($PARAMS->{$_})};
}
@param = sort { $a->{key} cmp $b->{key} } @param;
$subst->{param} = \@param;
}
## Environment variables
my @env = ();
foreach my $key (sort { lc($a) cmp lc($b) } keys %ENV) {
push @env, { key => $key, val => $ENV{$key} };
}
$subst->{environment} = \@env;
## Template integrity checks
my @dirs = ('custom', 'pro', 'admin', 'ui', 'mailmesg');
my %templates = ();
foreach my $dir (@dirs) {
if (opendir(DIR, "$DCONF->{admin_dir}/template/$dir")) {
$subst->{templdir}->{$dir} = "";
my @files = grep { /\.tmpl$/ } readdir(DIR);
closedir(DIR);
foreach my $file (@files) {
next if defined $templates{$file};
$templates{$file}{dir} = $dir;
if (open (FILE, "< $DCONF->{admin_dir}/template/$dir/$file")) {
my @code = <FILE>;
close (FILE);
$templates{$file}{begin} = 0 + scalar grep { /^\s*<!--BEGIN-->\s*$/ } @code;
$templates{$file}{end} = 0 + scalar grep { /^\s*<!--END-->\s*$/ } @code;
} else {
$templates{$file}{error} = $!;
}
}
} else {
$subst->{templdir}->{$dir} = $!;
}
}
my @templ_keys = sort { $templates{$a}{dir} cmp $templates{$b}{dir} || $a cmp $b } keys %templates;
my @templ_out = ();
foreach my $file (@templ_keys) {
push @templ_out, { file => $file, dir => $templates{$file}{dir}, error => $templates{$file}{error}, begin => $templates{$file}{begin}, end => $templates{$file}{end} };
}
$subst->{templ_out} = \@templ_out;
my @templ_dir = ();
foreach my $dir (sort @dirs) {
push @templ_dir, { dir => $dir, error => $subst->{templdir}->{$dir} };
}
$subst->{templ_dir} = \@templ_dir;
## Print out details
print templ_int("diagnost", $subst);
program_exit(0);
}
1;