File: admin-save.pl

package info (click to toggle)
courier 1.0.6-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 49,084 kB
  • sloc: ansic: 126,176; cpp: 24,278; sh: 8,957; perl: 4,127; makefile: 3,192; sed: 16
file content (112 lines) | stat: -rw-r--r-- 2,416 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#
#
# Copyright 2001 Double Precision, Inc.  See COPYING for
# distribution information.

my $fh=new FileHandle;

my $pid;

die $cgi->header("text/plain") . "Cannot start process: $!\n"
    unless (defined $fh) && (defined ($pid=open($fh, "-|")));

if (! $pid)
{
    my $errflag=0;

    open(STDERR, ">&STDOUT");

    foreach (ReadDirList("added"))
    {

	my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
	    $atime,$mtime,$ctime,$blksize,$blocks)
	    = stat("$sysconfdir/webadmin/added/$_");

	next unless $mode;

	print "Creating $_...\n";
	mkdir("$sysconfdir/$_", $mode);
    }
    unlink("$sysconfdir/webadmin/subdirs-added");

    foreach (ReadConfigFiles())
    {
	if ( -f "$sysconfdir/webadmin/added/$_" )
	{
	    print "Installing $_...\n";

	    my $newfilename="$sysconfdir/$_";

	    $newfilename=$authdaemonrc if $newfilename eq "$sysconfdir/authdaemonrc";
	    $newfilename=$authldaprc if $newfilename eq "$sysconfdir/authldaprc";
	    $newfilename=$authmysqlrc if $newfilename eq "$sysconfdir/authmysqlrc";
	    $newfilename=$authpgsqlrc if $newfilename eq "$sysconfdir/authpgsqlrc";

	    my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
		$atime,$mtime,$ctime,$blksize,$blocks)
		= stat($newfilename);

	    if ($mode)
	    {
		chmod ($mode, "$sysconfdir/webadmin/added/$_");
		chown ($uid, $gid, "$sysconfdir/webadmin/added/$_");
	    }
	    ($errflag=1, print "ERROR: $!\n")
		if ! rename ("$sysconfdir/webadmin/added/$_", $newfilename);
	}

	if ( -f "$sysconfdir/webadmin/removed/$_" )
	{
	    print "Deleting $_...\n";
	    ($errflag=1, print "ERROR: $!\n")
		if ! unlink ("$sysconfdir/webadmin/removed/$_",
			     "$sysconfdir/$_");
	}
    }

    foreach (ReadDirList("removed"))
    {
	print "Removing $_...\n";
	rmdir("$sysconfdir/$_");
    }
    unlink("$sysconfdir/webadmin/subdirs-removed");

    $fh=new FileHandle "$sysconfdir/webadmin/changed";

    if (defined $fh)
    {
	my $line;

	while (defined($line=<$fh>))
	{
	    next if $errflag;

	    chomp $line;
	    next unless $line =~ /(.+)/;

	    $line=$1;

	    print "Executing $line...\n";
	    $errflag=1 if system($line) != 0;
	}
	close($fh);
    }

    my @leftovers=ReadConfigFiles();

    unlink ("$sysconfdir/webadmin/changed")
	if $#leftovers < 0 && $errflag == 0;

    exit 0;
}

my $output=htmlescape(join("", <$fh>));
close($fh);

display_form("admin-save.html",
	     {
		 "OUTPUT" => $output
		 }
	     );
exit 0