/usr/sbin/mono-xsp4-update is in mono-xsp4 2.10-1build1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | #!/usr/bin/perl -w
# Automatic mono-server file generator
#
# With this script the user can update the host files
# that are installed in /etc/mono-server/conf.d/package and create a
# 'big' host file (/etc/mono-server/mono-server4-hosts) that will be used
# by mono-server to setup the virtual hosts needed by
# the user.
#
# Under GPL, please read:
# http://www.gnu.org/copyleft/gpl.html
#
# Written by: Pablo Fischer
=head1 NAME
mono-xsp4-update - creates .webapp needed by xsp4
=head1 SYNOPSIS
mono-xsp4-update
=head1 DESCRIPTION
mono-xsp4-update is a perl tool to update/create a .webapp in /etc/xsp4
This file is needed by xsp4 cause it has all each ASP.NET application with a path and alias, needed
by xsp4 to setup these applications.
The .webapp is created with other host configuration files that are in /etc/xsp4/conf.d
For more information read the README.Debian of this package (/usr/share/doc/mono-xsp4/README.Debian).
=head1 AUTHOR
Pablo Fischer <pablo@pablo.com.mx>
=cut
use strict;
use Digest::MD5;
#Main vars..
my ($monoxsp4_dir, $monoxsp4_confd, $monoxsp4_hostfile, $monoxsp4_webapp,
$daemon, $daemon_pid, $default_file,
$applications, $libs);
#Setup main vars
$monoxsp4_dir = "/etc/xsp4";
$monoxsp4_confd = "$monoxsp4_dir/conf.d";
$monoxsp4_webapp = "$monoxsp4_dir/debian.webapp";
$daemon = "/etc/init.d/mono-xsp4";
$daemon_pid = "/var/run/mono-xsp4.pid";
$applications = "";
$default_file = "/etc/default/mono-xsp4";
my $restart = "yes";
my $first_file = "yes";
my ($orig_md5, $new_md5);
#Check write access to $monoxsp4_hostfile
if( ( -e "$monoxsp4_webapp" && ! -w "$monoxsp4_webapp" ) || ! -w "$monoxsp4_dir" ) {
print "mono-xsp4-update requires write access to $monoxsp4_webapp or
be executed by root\n" ;
exit 1 ;
}
#Read the default file
&read_default_file;
#Orig md5
$orig_md5 = &get_md5;
#Read directory..
&read_dir;
#The tail
&write_tempdefault_end;
#Prepare the application string
$applications =~ s/,$//;
#Final md5
$new_md5 = &get_md5;
#Equal?
if(("$new_md5" ne "$orig_md5") && ($restart eq "yes")) {
if(( -f $daemon ) && ( -f $daemon_pid )) {
system("$daemon restart");
}
}
sub get_md5 {
if( -e $monoxsp4_webapp ) {
open(WEBAPP, $monoxsp4_webapp);
binmode(WEBAPP);
return Digest::MD5->new->addfile(*WEBAPP)->hexdigest;
}
else {
return "";
}
}
sub read_default_file {
if(-e $default_file) {
open(DEFAULT_FILE, "$default_file");
while(my $line = <DEFAULT_FILE>) {
if($line =~ /start_boot/i) {
if($line =~ /true/i) {
$restart = "yes";
}
else {
$restart = "no";
}
}
}
close(DEFAULT_FILE);
}
}
sub read_dir {
opendir(DIR, $monoxsp4_confd);
my @host_dirs = sort (grep { -d "$monoxsp4_confd/$_" } readdir(DIR));
closedir(DIR);
system("rm -Rf $monoxsp4_webapp");
system("touch $monoxsp4_webapp");
#How many dirs?
if($#host_dirs ne "0") {
#The head
&write_tempdefault_start;
foreach my $dir (@host_dirs) {
if(($dir ne "..") && ($dir ne ".")) {
#Ok, in the dir.. we have more files, so read them
opendir(DIR, "$monoxsp4_confd/$dir");
my @host_files = sort (readdir(DIR));
closedir(DIR);
#Is it empty?
if($#host_files ne "0") {
#So, read it..
foreach my $hostfile (@host_files) {
#Just remember.. we don't like directories inside directories!
if(($hostfile ne "..") && ($hostfile ne ".")) {
$hostfile = "$monoxsp4_confd/$dir/$hostfile";
write_tempxsp4hostfile($hostfile);
}
}
}
}
}
}
}
sub write_tempdefault_start {
open(TEMPWEBAPP, ">> $monoxsp4_webapp");
print TEMPWEBAPP "<apps>\n";
close(TEMPWEBAPP);
}
sub write_tempdefault_end {
open(TEMPWEBAPP, ">> $monoxsp4_webapp");
print TEMPWEBAPP "</apps>\n";
close(TEMPWEBAPP);
}
sub write_tempxsp4hostfile {
my $hostfile = shift;
#Write the content to a temp file..
open(TEMPWEBAPP, ">> $monoxsp4_webapp");
#And open the hostfile..
open(HOSTFILE, "$hostfile");
#Read it..
my @content_hostfile = <HOSTFILE>;
#Close it..
close(HOSTFILE);
#Write the header to the monoxsp4_hostfile
my ($path, $alias, $name);
foreach my $line (@content_hostfile) {
if($line =~ /path/i) {
#Ok, the directory exists?
my $dir = (split /\=/, $line)[1];
#Remove blank spaces
$dir =~ tr/\ //d;
#remove that \n
$dir =~ s/\n//;
if ( ! -d "$dir" ) {
$dir = "";
last;
}
else {
$path = $dir;
}
}
if($line =~ /alias/i) {
$alias = (split /\=/, $line)[1];
#Blank Spaces
$alias =~ tr/\ //d;
#New lines..
$alias =~ s/\n//;
#The name
$name = $alias;
$name =~ s|/*||;
}
}
if($path) {
$applications = "$applications$alias:$path,";
$libs = "$libs:";
print TEMPWEBAPP " <web-application>\n";
print TEMPWEBAPP " <name>$name</name>\n";
print TEMPWEBAPP " <vpath>$alias</vpath>\n";
print TEMPWEBAPP " <path>$path</path>\n";
print TEMPWEBAPP " </web-application>\n";
}
close(TEMPWEBAPP);
}
|