/usr/sbin/mono-server2-update is in mono-apache-server2 3.8-2.1.
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 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | #!/usr/bin/perl -w
# Automatic mono-server2 file generator
#
# With this script the user can update the host files
# that are installed in /etc/mono-server2/conf.d/package and create a
# 'big' host file (/etc/mono-server2/mono-server2*-hosts.conf) that will be used
# by mono-server2 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-server2-update - creates .webapp and .host file for mod_mono and mono-server2
=head1 SYNOPSIS
mono-server2-update
=head1 DESCRIPTION
mono-server2-update is a perl tool to update/create a .webapp and a .host file in
/etc/mono-server2.
These two files are needed by mod_mono (apache), they setup the alias, directory permissions,
and ASP.NET applications.
Both files are created with other host configuration files that are in /etc/mono-server2/conf.d
For more information read the README.Debian of this package (/usr/share/doc/mono-server2/README.Debian).
=head1 AUTHOR
Pablo Fischer <pablo@pablo.com.mx>
=cut
use strict;
use Digest::MD5;
#Main vars..
my ($monoserver2_dir, $monoserver2_confd, $monoserver2_hostfile, $monoserver2_webapp,
$daemon, $daemon_pid, $default_file,
$applications, $libs, $daemon2, $daemon2_pid);
#Setup main vars
$monoserver2_dir = "/etc/mono-server2";
$monoserver2_confd = "$monoserver2_dir/conf.d";
$monoserver2_webapp = "$monoserver2_dir/debian.webapp";
$monoserver2_hostfile = "$monoserver2_dir/mono-server2-hosts.conf";
$daemon = "/etc/init.d/apache";
$daemon_pid = "/var/run/apache.pid";
$daemon2 = "/etc/init.d/apache2";
$daemon2_pid = "/var/run/apache2.pid";
$applications = "";
$default_file = "/etc/default/mono-apache-server2";
$libs = "";
my $restart = "yes";
my $first_file = "yes";
my ($orig_md5, $new_md5);
#Check write access to $monoserver2_hostfile
if( ( -e "$monoserver2_hostfile" && ! -w "$monoserver2_hostfile" ) || ! -w "$monoserver2_dir" ) {
print "mono-xsp-update requires write access to $monoserver2_hostfile 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;
if(-f "$monoserver2_hostfile.tmp") {
#Prepare the application string
$applications =~ s/,$//;
#and the libs..
$libs = "/usr/lib/mono/2.0:/usr/lib:$libs";
$libs =~ s/:$//;
#sed the $monoserver2_hostfile to replace the Applications
# &replace_applications;
#Replace the MONOPATH
&replace_monopath;
&write_tempdefault_end;
#cp the temp file to the original one..
system("cp -f $monoserver2_hostfile.tmp $monoserver2_hostfile");
#rm the temp
system("rm -Rf $monoserver2_hostfile.tmp");
#Final md5
$new_md5 = &get_md5;
#Equal?
if(("$new_md5" ne "$orig_md5") && ($restart eq "yes")) {
if(( -f $daemon ) && ( -f $daemon_pid )) {
system("$daemon reload");
system("$daemon restart");
}
if(( -f $daemon2 ) && ( -f $daemon2_pid )) {
system("$daemon2 reload");
system("$daemon2 restart");
}
}
}
sub get_md5 {
if( -e $monoserver2_hostfile ) {
open(HOSTFILE, $monoserver2_hostfile);
binmode(HOSTFILE);
return Digest::MD5->new->addfile(*HOSTFILE)->hexdigest;
}
else {
return "";
}
}
sub read_default_file {
if(-e $default_file) {
open(DEFAULT_FILE, "$default_file");
while(my $line = <DEFAULT_FILE>) {
if($line =~ /start_apache/i) {
if($line =~ /true/i) {
$restart = "yes";
}
else {
$restart = "no";
}
}
}
close(DEFAULT_FILE);
}
}
sub read_dir {
opendir(DIR, $monoserver2_confd);
my @host_dirs = sort (grep { -d "$monoserver2_confd/$_" } readdir(DIR));
closedir(DIR);
#to verify that the cfg file is new.. we should create a new one
system("rm -Rf $monoserver2_hostfile");
system("touch $monoserver2_hostfile");
#also to the debian.webapp
system("rm -Rf $monoserver2_webapp");
system("touch $monoserver2_webapp");
#How many dirs?
if($#host_dirs ne "0") {
#Write default content
&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, "$monoserver2_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 = "$monoserver2_confd/$dir/$hostfile";
write_tempxsphostfile($hostfile);
}
}
}
}
}
}
}
sub replace_applications {
local $/;
open(TEMPHOST, "$monoserver2_hostfile.tmp");
my $content = <TEMPHOST>;
close(TEMPHOST);
if($applications) {
$content =~ s/MonoApplications .*/MonoApplications $applications/gi;
}
else {
$content =~ s/MonoApplications//gi;
}
open(TEMPHOST, "> $monoserver2_hostfile.tmp");
print TEMPHOST $content;
close(TEMPHOST);
}
sub replace_monopath {
local $/;
open(TEMPHOST, "$monoserver2_hostfile.tmp");
my $content = <TEMPHOST>;
close(TEMPHOST);
if($libs) {
$content =~ s/MonoPath .*/MonoPath default $libs/gi;
}
else {
$content =~ s/MonoPath default//gi;
}
open(TEMPHOST, "> $monoserver2_hostfile.tmp");
print TEMPHOST $content;
close(TEMPHOST);
}
sub write_tempdefault_start {
open(TEMPHOST, ">> $monoserver2_hostfile.tmp");
print TEMPHOST "# Default configuration, don't edit it!\n";
print TEMPHOST "<IfModule mod_mono.c>\n";
print TEMPHOST " MonoUnixSocket default /tmp/.mod_mono_server2\n";
print TEMPHOST " MonoServerPath default /usr/bin/mod-mono-server2\n";
print TEMPHOST " AddType application/x-asp-net .aspx .ashx .asmx .ascx .asax .config .ascx\n";
print TEMPHOST " MonoApplicationsConfigDir default /etc/mono-server2\n";
print TEMPHOST " MonoPath default \n";
close(TEMPHOST);
open(TEMPWEBAPP, ">> $monoserver2_webapp");
print TEMPWEBAPP "<apps>\n";
close(TEMPWEBAPP);
}
sub write_tempdefault_end {
open(TEMPHOST, ">> $monoserver2_hostfile.tmp");
print TEMPHOST "</IfModule>\n";
close(TEMPHOST);
#Now the debian.webapp
open(TEMPWEBAPP, ">> $monoserver2_webapp");
print TEMPWEBAPP "</apps>\n";
close(TEMPWEBAPP);
}
sub write_tempxsphostfile {
my $hostfile = shift;
#Write the content to a temp file..
open(TEMPHOST, ">> $monoserver2_hostfile.tmp");
open(TEMPWEBAPP, ">> $monoserver2_webapp");
#And open the hostfile..
open(HOSTFILE, "$hostfile");
#Read it..
my @content_hostfile = <HOSTFILE>;
#Close it..
close(HOSTFILE);
#Write the header to the monoserver2_hostfile
my ($path, $alias, $vhost, $port, $name);
$vhost = "localhost";
$port = "80";
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($line =~ /lib/i) {
$libs = (split /\=/, $line)[1];
#Blank spaces
$libs =~ tr/\ //d;
#New lines..
$libs =~ s/\n//;
#And remove the last and first ':'..
$libs =~ s/:$//;
}
if($line =~ /vhost/i) {
$vhost = (split /\=/, $line)[1];
#Blank spaces
$vhost =~ tr/\ //d;
#New lines..
$vhost =~ s/\n//;
#And remove the last and first ':'..
$vhost =~ s/:$//;
}
if($line =~ /port/i) {
$port = (split /\=/, $line)[1];
#Blank spaces
$port =~ tr/\ //d;
#New lines..
$port =~ s/\n//;
#And remove the last and first ':'..
$port =~ s/:$//;
}
if($line =~ /name/i) {
$name = (split /\=/, $line)[1];
#Blank spaces
$name =~ tr/\ //d;
#New lines..
$name =~ s/\n//;
#And remove the last and first ':'..
$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 " <vhost>$vhost</vhost>\n";
print TEMPWEBAPP " <port>$port</port>\n";
print TEMPWEBAPP " </web-application>\n";
print TEMPHOST "# start $hostfile\n";
print TEMPHOST " Alias $alias \"$path\"\n";
print TEMPHOST " AddMonoApplications default \"$alias:$path\"\n";
print TEMPHOST " <Directory $path>\n";
print TEMPHOST " SetHandler mono\n";
print TEMPHOST " <IfModule mod_dir.c>\n";
print TEMPHOST " DirectoryIndex index.aspx\n";
print TEMPHOST " </IfModule>\n";
print TEMPHOST " </Directory>\n";
print TEMPHOST "# end $hostfile\n";
}
close(TEMPHOST);
close(TEMPWEBAPP);
}
|