904N/A#!/bin/bash
904N/A#
904N/A# CDDL HEADER START
904N/A#
904N/A# The contents of this file are subject to the terms of the
904N/A# Common Development and Distribution License (the "License").
904N/A# You may not use this file except in compliance with the License.
904N/A#
904N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
904N/A# or http://www.opensolaris.org/os/licensing.
904N/A# See the License for the specific language governing permissions
904N/A# and limitations under the License.
904N/A#
904N/A# When distributing Covered Code, include this CDDL HEADER in each
904N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
904N/A# If applicable, add the following below this CDDL HEADER, with the
904N/A# fields enclosed by brackets "[]" replaced with your own identifying
904N/A# information: Portions Copyright [yyyy] [name of copyright owner]
904N/A#
904N/A# CDDL HEADER END
904N/A#
904N/A# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
904N/A#
904N/A
904N/A# Helper functions
904N/Afunction usage {
904N/A echo ""
904N/A echo "Usage: This script will update a given Web Server 7 instance's configuration"
904N/A echo " files to be able to execute PHP scripts."
904N/A echo ""
904N/A echo "This script recognizes following arguments:"
904N/A echo " --installroot : Top level Sun Web Server 7 installation location. "
904N/A echo ""
904N/A echo " --instancename : Name of Web Server instance (https-php) which should"
904N/A echo " be configured to execute PHP scripts. "
904N/A echo ""
904N/A echo " --sapi : How should PHP runtime be loaded within Web Server 7"
904N/A echo " fastcgi (Default) or NSAPI (Optional). "
904N/A echo ""
904N/A exit 1
904N/A}
904N/A
904N/Afunction parse_arguments
904N/A{
904N/A until [ $# -eq 0 ]
904N/A do
904N/A cur_arg=$1
904N/A case $cur_arg in
904N/A --installroot=*)
904N/A install_root="`echo $cur_arg | cut -d= -f2-`"
904N/A ;;
904N/A --instancename=*)
904N/A instance_name="`echo $cur_arg | cut -d= -f2-`"
904N/A ;;
904N/A --sapi=*)
904N/A sapi="`echo $cur_arg | cut -d= -f2-`"
904N/A ;;
904N/A *)
904N/A usage
904N/A ;;
904N/A esac
904N/A shift;
904N/A done
904N/A}
904N/A
904N/Afunction try_interactive
904N/A{
904N/A # Get user response on Web Server 7 installation location and instance name.
904N/A echo -n "Enter your Web Server installation location : "
904N/A read input
904N/A if [ -n "$input" ]; then
904N/A install_root="$input"
904N/A fi
904N/A
904N/A echo -n "Enter your Web Server instance name to configure with PHP runtime: "
904N/A read input
904N/A if [ -n "$input" ]; then
904N/A instance_name="$input"
904N/A fi
904N/A
904N/A while [ 0 ]; do
904N/A echo -n "How you would like Sun Web Server 7 to load PHP engine (fastcgi|nsapi) [fastcgi]: "
904N/A read input
904N/A if [ -z "$input" ]; then
904N/A sapi="fastcgi"
904N/A else
904N/A sapi=$input
904N/A fi
904N/A if [ -n "$sapi" ] && [ $sapi = "fastcgi" -o $sapi = "nsapi" ]; then
904N/A break
904N/A fi
904N/A done
904N/A return 1;
904N/A}
904N/A
904N/Afunction validate_arguments
904N/A{
904N/A if [ ! -d "$install_root" ] || [ ! -x "$install_root/lib/webservd" ]; then
904N/A echo ""
904N/A echo "Warning: Unable to find valid Web Server installation under $install_root"
904N/A echo "Please try again by providing a valid Web Server 7 installation location."
904N/A usage
904N/A fi
904N/A
904N/A if [ ! -d "$install_root" ] || [ ! -x "$install_root/lib/webservd" ]; then
904N/A echo ""
904N/A echo "Warning: Unable to find valid Web Server installation under $install_root"
904N/A echo "Please try again by providing a valid Web Server 7 installation location."
904N/A usage
904N/A fi
904N/A
904N/A if [ -n "$sapi" ] && [ $sapi != "fastcgi" -a $sapi != "nsapi" ]; then
904N/A echo ""
904N/A echo "Error: Invalid SAPI option is provided.Valid SAPI argument is either 'fastcgi' or 'nsapi'"
904N/A echo "Please try again by providing a valid SAPI as argument."
904N/A usage
904N/A fi
904N/A
904N/A return 1;
904N/A}
904N/A
904N/Afunction generate_tempfile
904N/A{
904N/A template="tmp.XXXXXXXXXX";
904N/A if [ -x "/bin/mktemp" ]; then
904N/A temp_file="`/bin/mktemp`"
904N/A elif [ -x "/usr/bin/mktemp" ]; then
904N/A temp_file="`/usr/bin/mktemp`"
904N/A fi
904N/A if [ ! -f $temp_file ]; then
904N/A temp_file="/tmp/ws7_php_configure.$$"
904N/A touch $temp_file
904N/A chmod 600 $temp_file
904N/A fi
904N/A
904N/A return 1;
904N/A}
904N/A
904N/Afunction generate_configure
904N/A{
904N/A if [ "$OSNAME" = "SunOS" ]; then
904N/A tail +${perl_start_line} $PROGRAM_NAME > $temp_file
904N/A elif [ "$OSNAME" = "Linux" ]; then
904N/A start_line=${perl_start_line}
904N/A total_line=`wc -l $PROGRAM_NAME | awk '{print $1}' 2>/dev/null`
904N/A few_lines=$(($total_line - $start_line))
904N/A tail -${few_lines} $PROGRAM_NAME > $temp_file
904N/A fi
904N/A chmod 500 $temp_file
904N/A}
904N/A
904N/Afunction invoke_configure
904N/A{
904N/A # Setup environment
904N/A if [ -f "$install_root/lib/wsenv" ]; then
904N/A source $install_root/lib/wsenv
904N/A if [ ! -d "${WS_INSTANCEROOT}/${instance_name}" ]; then
904N/A echo "Warning: Unable to find instance:'$instance_name' under $WS_INSTANCEROOT"
904N/A echo " Please try again by providing a valid instance name."
904N/A exit 1;
904N/A fi
904N/A fi
904N/A
904N/A # Special case, if it is NSAPI
904N/A if [ "$sapi" = "nsapi" ]; then
904N/A mkdir -p "$install_root/plugins/webstack-php"
904N/A ln -sf "<<INSTALL_DIR>>/nsapi/libphp5.so" "$install_root/plugins/webstack-php/libphp5.so"
904N/A fi
904N/A
904N/A # Invoke script to configure PHP runtime.
904N/A if [ "$sapi" = "nsapi" ]; then
904N/A PHPROOT="<<INSTALL_DIR>>"
904N/A PHPCONFROOT="<<NSAPI_CONF_DIR>>"
904N/A PHPCONFROOT_SCANDIR="<<ZTS_MODULES_CONF_DIR>>"
904N/A else
904N/A PHPROOT="<<INSTALL_DIR>>"
904N/A PHPCONFROOT="<<CONF_DIR>>"
904N/A PHPCONFROOT_SCANDIR="<<MODULES_CONF_DIR>>"
904N/A fi
904N/A
904N/A ${WS_PERL}/perl -I ${WS_PERL} -I ${WS_PERL}/lib -I ${WS_PERL}/lib/site_perl $temp_file \
904N/A -installroot=${WS_INSTALLROOT} -instanceroot=${WS_INSTANCEROOT} -instancename=$instance_name \
904N/A -sapi=$sapi -phproot="${PHPROOT}" \
904N/A -phpconfroot="${PHPCONFROOT}" -phpmodulesconfroot="${PHPCONFROOT_SCANDIR}"
904N/A
904N/A status=$?
904N/A if [ $status -eq 0 ]; then
904N/A if [ -f $temp_file ]; then
904N/A rm -f $temp_file
904N/A fi
904N/A elif [ $status -ne 0 ]; then
904N/A echo "Unable to successfully setup PHP within Web Server 7"
904N/A exit 1
904N/A fi
904N/A}
904N/A
904N/A#-------------------------------------------------------------------------------
904N/A#####
904N/A# Main
904N/A#####
904N/APATH=/bin:/usr/bin:/usr/gnu/bin:/usr/sfw/bin
904N/Aexport PATH
904N/A
904N/A# Global variables.
904N/AOSNAME="`uname -s`"
904N/APHPROOT="<<INSTALL_DIR>>"
904N/APHPCONFROOT="<<CONF_DIR>>"
904N/APHPCONFROOT_SCANDIR="<<MODULES_CONF_DIR>>"
904N/APROGRAM_NAME="$0"
904N/Ainstall_root=""
904N/Ainstance_name=""
904N/Asapi="fastcgi"
904N/Atemp_file=""
904N/A
904N/A# This below line need to point to the start of embedded perl script.
904N/Aperl_start_line=245
904N/A
904N/Aecho "This script will update a given Web Server 7 instance's configuration"
904N/Aecho "files to be able to execute PHP scripts."
904N/Aecho ""
904N/A
904N/A# Verify if the program is called with necessary arguments.
904N/Aif [ -n "$1" ]; then
904N/A parse_arguments $@;
904N/Aelse
904N/A # Invoked with no arguments. Try interactive.
904N/A try_interactive
904N/Afi
904N/A
904N/Avalidate_arguments
904N/A
904N/Agenerate_tempfile
904N/A
904N/Agenerate_configure
904N/A
904N/Ainvoke_configure
904N/A
904N/Aexit 0
904N/A
904N/A#---------------------EOF-------------------------------------------------------
904N/A
904N/A# Helper Script to configure PHP runtime environment within Web Server 7
904N/A
904N/Ause XML::Simple;
904N/Ause File::Basename;
904N/Ause English;
904N/Ause strict;
904N/A
904N/Aour $INSTANCE_ROOT = undef;
904N/Aour $INSTALL_ROOT = undef;
904N/Aour $INSTANCE_NAME = undef;
904N/Aour $PHP_ROOT = "";
904N/Aour $PHP_CONF_ROOT = "";
904N/Aour $PHP_MODULES_CONF_ROOT = "";
904N/Aour $SAPI = undef;
904N/Aour $MIME_TYPES_FILES = [];
904N/Aour $OBJ_CONF_FILES = [];
904N/Aour $SERVER_64BIT_MODE = undef;
904N/A
904N/Amy $phpSoName;
904N/Aif (isWindows()) {
904N/A $phpSoName = "php5nsapi.dll";
904N/A} else {
904N/A $phpSoName = "libphp5.so";
904N/A}
904N/A
904N/Amy $fastCGISoName;
904N/Aif (isWindows()) {
904N/A $fastCGISoName = "fastcgi.dll";
904N/A} else {
904N/A $fastCGISoName = "libfastcgi.so";
904N/A}
904N/A
904N/Amain();
904N/A
904N/Asub main {
904N/A getCommandOptions();
904N/A processServerXml();
904N/A checkFilesWritable();
904N/A processMagnusConf();
904N/A processObjConf();
904N/A processMimeTypes();
904N/A printResult();
904N/A}
904N/A
904N/A# -----------------------------------------------------------------------------
904N/A# getCommandOptions
904N/A# Process the command line options
904N/A# -----------------------------------------------------------------------------
904N/A
904N/Asub getCommandOptions {
904N/A for (my $counter=0; $#ARGV >= $counter; $counter++) {
904N/A my $argument = $ARGV[$counter];
904N/A
904N/A if ($argument =~ /^-installroot=/i) {
904N/A $INSTALL_ROOT = substr($argument, length("-installroot="));
904N/A }
904N/A if ($argument =~ /^-instanceroot=/i) {
904N/A $INSTANCE_ROOT = substr($argument, length("-instanceroot="));
904N/A }
904N/A if ($argument =~ /^-phproot=/i) {
904N/A $PHP_ROOT = substr($argument, length("-phproot="));
904N/A }
904N/A if ($argument =~ /^-phpconfroot=/i) {
904N/A $PHP_CONF_ROOT = substr($argument, length("-phpconfroot="));
904N/A }
904N/A if ($argument =~ /^-phpmodulesconfroot=/i) {
904N/A $PHP_MODULES_CONF_ROOT = substr($argument, length("-phpmodulesconfroot="));
904N/A }
904N/A if ($argument =~ /^-instancename=/i) {
904N/A $INSTANCE_NAME = substr($argument, length("-instancename="));
904N/A }
904N/A if ($argument =~ /^-sapi=/i) {
904N/A $SAPI = substr($argument, length("-sapi="));
904N/A }
904N/A }
904N/A if ((!defined $PHP_CONF_ROOT) || ($PHP_CONF_ROOT eq "")) {
904N/A $PHP_CONF_ROOT = $PHP_ROOT;
904N/A }
904N/A
904N/A if ((not defined $INSTANCE_NAME) or ($INSTANCE_NAME !~ m/\S+/)) {
904N/A printUsage();
904N/A }
904N/A
904N/A exit 1 unless defined isValidFile("$INSTANCE_ROOT/$INSTANCE_NAME/config");
904N/A}
904N/A
904N/A# -----------------------------------------------------------------------------
904N/A# migrateObjConf
904N/A# Migrate obj.conf file to php 1.1
904N/A# -----------------------------------------------------------------------------
904N/A
904N/Asub migrateObjConf {
904N/A my $objConfFile = shift;
904N/A my $pContents = shift;
904N/A my $tmpObjConfStatus = 1;
904N/A
904N/A return undef unless ($objConfFile);
904N/A if ((not -f $objConfFile or ref($pContents) != "ARRAY")) {
904N/A return undef;
904N/A }
904N/A
904N/A my $tmpObjConfFile = "$objConfFile"."tmp";
904N/A my $update_reqd = undef;
904N/A local *TMPOBJ;
904N/A
904N/A my $newLibPath = "$PHP_ROOT/lib";
904N/A my $newLibPath64 = "$PHP_ROOT/lib/64";
904N/A
904N/A for (my $i = 0; $i < $#{@{$pContents}}; $i++) {
904N/A my $pLine = \$pContents->[$i];
904N/A next if ($$pLine =~ /^\#/); #ignore comments;
904N/A next if (isWindows());
904N/A if ($$pLine =~ m@(.*\s+app-path=['"])(\S+)\s*(['"].*)@) {
904N/A my ($tmp, $tmp1, $tmp2, $tmp3);
904N/A $tmp1 = $1; $tmp2 = $2; $tmp3 = $3;
904N/A
904N/A $tmp2 =~ s@$PHP_ROOT/bin/php@$PHP_ROOT/bin/php-cgi@;
904N/A $tmp = $tmp1.$tmp2.$tmp3."\n";
904N/A $pContents->[$i] = $tmp;
904N/A $update_reqd = 1;
904N/A }
904N/A elsif ($$pLine =~ m@(.*\s+app-env=['"])(\S+)(=)(\S+)(['"].*)@) {
904N/A my ($tmp, $tmp1, $tmp2, $tmp3, $tmp4, $tmp5);
904N/A $tmp1 = $1; $tmp2 = $2; $tmp3 = $3; $tmp4 = $4; $tmp5 = $5;
904N/A
904N/A if (($tmp2 =~ m@LD_LIBRARY_PATH@) or ($tmp2 =~ m@LD_LIBRARY_PATH_64@)) {
904N/A if ($tmp4 =~ m@$PHP_ROOT/64@) {
904N/A $tmp4 =~ s@$PHP_ROOT/64@$newLibPath64@g;
904N/A }
904N/A elsif ($tmp4 =~ m@$PHP_ROOT/64([:].*)@) {
904N/A $tmp4 =~ s@$PHP_ROOT/64(:.*)@$newLibPath64$1@g;
904N/A }
904N/A elsif ($tmp4 =~ m@$PHP_ROOT([:].*)@) {
904N/A $tmp4 =~ s@$PHP_ROOT(:.*)@$newLibPath$1@g;
904N/A }
904N/A elsif ($tmp4 =~ m@$PHP_ROOT@) {
904N/A $tmp4 =~ s@$PHP_ROOT@$newLibPath@g;
904N/A }
904N/A }
904N/A elsif ($tmp2 =~ m@PHP_FCGI_MAX_REQUEST@) {
904N/A $tmp2 =~ s@PHP_FCGI_MAX_REQUEST@PHP_FCGI_MAX_REQUESTS@g;
904N/A $tmp4 =~ s@200@2000@;
904N/A }
904N/A $tmp = $tmp1.$tmp2.$tmp3.$tmp4.$tmp5."\n";
904N/A $pContents->[$i] = $tmp;
904N/A $update_reqd = 1;
904N/A }
904N/A }
904N/A
904N/A if ($update_reqd) {
904N/A open(TMPOBJ,">$tmpObjConfFile") or $tmpObjConfStatus = undef;
904N/A if (defined $tmpObjConfStatus) {
904N/A for (my $i = 0; $i < $#{@{$pContents}}; $i++) {
904N/A my $line = $pContents->[$i];
904N/A print TMPOBJ $line;
904N/A }
904N/A print "UPDATED: $objConfFile \n";
904N/A close(TMPOBJ);
904N/A unlink("$objConfFile");
904N/A rename("$tmpObjConfFile", "$objConfFile");
904N/A chmod(0600, "$objConfFile");
904N/A return 2;
904N/A }
904N/A }
904N/A
904N/A return 1;
904N/A}
904N/A
904N/A# -----------------------------------------------------------------------------
904N/A# processServerXml
904N/A# Parse the server.xml and get all the mime files and object files
904N/A# -----------------------------------------------------------------------------
904N/A
904N/Asub processServerXml {
904N/A my $file = undef;
904N/A my $serverXml = "$INSTANCE_ROOT/$INSTANCE_NAME/config/server.xml";
904N/A
904N/A my $config = eval{XMLin("$serverXml", forcearray=>1, keyattr=>[])};
904N/A if ($@) {
904N/A print("\nERROR: Problem parsing the $serverXml. Not a valid xml file. \n\n");
904N/A exit 1;
904N/A }
904N/A
904N/A #get the server level mime file
904N/A $file = $config->{"mime-file"}->[0];
904N/A if (defined $file) {
904N/A $file = getValidAbsoluteFilePath($file);
904N/A if (defined $file) {
904N/A push (@$MIME_TYPES_FILES, $file);
904N/A }
904N/A }
904N/A
904N/A # get the server platform mode
904N/A my $mode = $config->{"platform"}->[0];
904N/A if (defined $mode) {
904N/A if ($mode == "64") {
904N/A $SERVER_64BIT_MODE = "64";
904N/A }
904N/A }
904N/A
904N/A for (my $vsCounter = 0; ${config}->{"virtual-server"}->[$vsCounter]; $vsCounter++) {
904N/A my $virutalServerElement = ${config}->{"virtual-server"}->[$vsCounter];
904N/A #get the virtual server level mime files
904N/A for (my $mimeTypescounter = 0; ${virutalServerElement}->{"mime-file"}->[$mimeTypescounter]; $mimeTypescounter++) {
904N/A $file = ${virutalServerElement}->{"mime-file"}->[$mimeTypescounter];
904N/A $file = getValidAbsoluteFilePath($file);
904N/A if (defined $file) {
904N/A push (@$MIME_TYPES_FILES, $file);
904N/A }
904N/A }
904N/A #get the virtual server level object files
904N/A for (my $objectFilecounter = 0; ${virutalServerElement}->{"object-file"}->[$objectFilecounter]; $objectFilecounter++) {
904N/A $file = ${virutalServerElement}->{"object-file"}->[$objectFilecounter];
904N/A $file = getValidAbsoluteFilePath($file);
904N/A if (defined $file) {
904N/A push (@$OBJ_CONF_FILES, $file);
904N/A }
904N/A }
904N/A }
904N/A
904N/A #Default is mime.types
904N/A if (@$MIME_TYPES_FILES < 1) {
904N/A push (@$MIME_TYPES_FILES, "$INSTANCE_ROOT/$INSTANCE_NAME/config/mime.types");
904N/A }
904N/A
904N/A #Default is obj.conf
904N/A if (@$OBJ_CONF_FILES < 1) {
904N/A push (@$OBJ_CONF_FILES, "$INSTANCE_ROOT/$INSTANCE_NAME/config/obj.conf");
904N/A }
904N/A}
904N/A
904N/A# -----------------------------------------------------------------------------
904N/A# processMagnusConf
904N/A# Append the MAGNUS_CONF_APPEND_STRING value at the end of magnus.conf file.
904N/A# -----------------------------------------------------------------------------
904N/A
904N/Asub processMagnusConf {
904N/A my $magnusConfFile = "$INSTANCE_ROOT/$INSTANCE_NAME/config/magnus.conf";
904N/A my $magnusConfStatus = 1;
904N/A
904N/A if (defined isValidFile($magnusConfFile))
904N/A {
904N/A # Get the current File Stat.
904N/A my @statInfo = stat $magnusConfFile;
904N/A
904N/A # Verify if the changes already exist.
904N/A if (open(MAGNUS_R,"<$magnusConfFile")) {
904N/A my @contents = <MAGNUS_R>;
904N/A foreach (@contents) {
904N/A next if (/^\#/); #ignore comments;
904N/A if ((isNSAPI()) and (/shlib(.*)$phpSoName(.*)/g)) {
904N/A close(MAGNUS_R);
904N/A return 1;
904N/A } elsif ((not isNSAPI()) and (/shlib(.*)$fastCGISoName(.*)/g)) {
904N/A close(MAGNUS_R);
904N/A return 1;
904N/A }
904N/A }
904N/A close(MAGNUS_R);
904N/A }
904N/A open(MAGNUS,">>$magnusConfFile") or $magnusConfStatus = 0;
904N/A
904N/A if ($magnusConfStatus == 1) {
904N/A addToMagnusConf(\*MAGNUS);
904N/A print "\n\nUPDATED: $magnusConfFile \n";
904N/A } else {
904N/A print "\nERROR: Unable to write $magnusConfFile. \n\n";
904N/A close(MAGNUS);
904N/A exit 1;
904N/A }
904N/A close(MAGNUS);
904N/A chown $statInfo[4], $statInfo[5], $magnusConfFile;
904N/A }
904N/A}
904N/A
904N/A# -----------------------------------------------------------------------------
904N/A# processObjConf
904N/A# Append the OBJ_CONF_APPEND_STRING value after the <object name="default"
904N/A# directive in all object files.
904N/A# -----------------------------------------------------------------------------
904N/A
904N/Asub processObjConf {
904N/A while(scalar(@$OBJ_CONF_FILES) > 0) {
904N/A my $objConfFile = pop(@$OBJ_CONF_FILES);
904N/A my $objConfStatus = 1;
904N/A my $tmpObjConfStatus = 1;
904N/A
904N/A if (defined isValidFile($objConfFile))
904N/A {
904N/A # Get the current File Stat.
904N/A my @statInfo = stat $objConfFile;
904N/A
904N/A # Verify if the changes already exist.
904N/A open(OBJ,"<$objConfFile") or $objConfStatus = undef;
904N/A if (defined $objConfStatus) {
904N/A my @lines = <OBJ>;
904N/A my $escape_path = $PHP_ROOT;
904N/A $escape_path =~ s/\/(\w)/\\\/$1/g;
904N/A $escape_path =~ s/\\(\w)/\/$1/g;
904N/A my $contents = join("",@lines);
904N/A my $already_configured = undef;
904N/A if ((isNSAPI()) and ($contents =~ m/
904N/A \s*Service\s+type="magnus-internal\/php"\s+fn="php5_execute"
904N/A /mx)) {
904N/A close(OBJ);
904N/A $already_configured = 1;
904N/A }
904N/A if ((not isNSAPI()) and (($contents =~ m/
904N/A \s*Service\s+type=[\"]magnus-internal\/php[\"]
904N/A [\r\n]+
904N/A \s*fn=[\"]responder-fastcgi[\"]
904N/A [\r\n]+
904N/A \s*app-path=[\"](.*)[\"]
904N/A [\r\n]+
904N/A /mx) and ($1 =~ m@$escape_path@))) {
904N/A close(OBJ);
904N/A $already_configured = 1;
904N/A # migrate existing obj.conf configurations.
904N/A &migrateObjConf($objConfFile, \@lines);
904N/A }
904N/A
904N/A next if ($already_configured);
904N/A
904N/A # Create a new obj.conf
904N/A my $tmpObjConfFile = "$objConfFile"."tmp";
904N/A open(TMPOBJ,">$tmpObjConfFile") or $tmpObjConfStatus = undef;
904N/A if (defined $tmpObjConfStatus) {
904N/A if (@lines) {
904N/A foreach my $line (@lines) {
904N/A if (($line =~ /^<Object/i) &&
904N/A (($line =~ /name=default>/i) ||
904N/A ($line =~ /name=default\s/i) ||
904N/A ($line =~ /name="default"/i))) {
904N/A print TMPOBJ $line;
904N/A addToObjConf(\*TMPOBJ);
904N/A print "UPDATED: $objConfFile \n";
904N/A } elsif ($line =~ /PathCheck\s+fn\s*=\s*(\S+)\s+(\S+)\s*=\s*(\S+)$/) {
904N/A my $funcName = $1;
904N/A my $valueName = $2;
904N/A my $values = $3;
904N/A if (($funcName =~ /find-index/) and ($valueName =~ /index-names/)) {
904N/A $values =~ s/[\"](\S+)[\"]/$1/;
904N/A $values = "$1".",index.php";
904N/A my $newLine = <<__UP_TO_THIS_POINT_;
904N/APathCheck fn=$funcName $valueName=\"$values\"
904N/A__UP_TO_THIS_POINT_
904N/A print TMPOBJ $newLine;
904N/A }
904N/A else {
904N/A print TMPOBJ $line;
904N/A }
904N/A } else {
904N/A print TMPOBJ $line;
904N/A }
904N/A }
904N/A }
904N/A } else {
904N/A print "\nERROR: Unable to write $objConfFile \n\n";
904N/A close(TMPOBJ);
904N/A close(OBJ);
904N/A unlink("$tmpObjConfFile");
904N/A exit 1;
904N/A }
904N/A close(TMPOBJ);
904N/A close(OBJ);
904N/A unlink("$objConfFile");
904N/A rename("$tmpObjConfFile", "$objConfFile");
904N/A chmod(0600, "$objConfFile");
904N/A chown $statInfo[4], $statInfo[5], $objConfFile;
904N/A }
904N/A }
904N/A }
904N/A}
904N/A
904N/A# -----------------------------------------------------------------------------
904N/A# processMimeTypes
904N/A# Append the MIME_TYPES_APPEND_STRING value at the end of
904N/A# all the mime types file.
904N/A# -----------------------------------------------------------------------------
904N/A
904N/Asub processMimeTypes {
904N/A while(scalar(@$MIME_TYPES_FILES) > 0) {
904N/A my $mimeTypesFile = pop(@$MIME_TYPES_FILES);
904N/A my $mimeTypesStatus = 1;
904N/A
904N/A if (defined isValidFile($mimeTypesFile)) {
904N/A
904N/A # Get the current File Stat.
904N/A my @statInfo = stat $mimeTypesFile;
904N/A
904N/A # Verify if the changes already exist.
904N/A if (open(MIME_R,"<$mimeTypesFile")) {
904N/A my @contents = <MIME_R>;
904N/A for (my $i = $#contents; $i > 0; $i--) {
904N/A if ($contents[$i] =~ /magnus-internal\/php/g) {
904N/A close(MIME_R);
904N/A return 1;
904N/A }
904N/A }
904N/A close(MIME_R);
904N/A }
904N/A open(MIME,">>$mimeTypesFile") or $mimeTypesStatus = undef;
904N/A if (defined $mimeTypesStatus) {
904N/A addToMimeTypes(\*MIME);
904N/A print "UPDATED: $mimeTypesFile \n";
904N/A } else {
904N/A print "\nERROR: Unable to write $mimeTypesFile. \n\n";
904N/A close(MIME);
904N/A exit 1;
904N/A }
904N/A close(MIME);
904N/A chown $statInfo[4], $statInfo[5], $mimeTypesFile;
904N/A }
904N/A }
904N/A}
904N/A
904N/A# -----------------------------------------------------------------------------
904N/A# addMagnusConfEntry
904N/A# Add the required magnus conf entry
904N/A# -----------------------------------------------------------------------------
904N/Asub addToMagnusConf {
904N/A
904N/A my $entry;
904N/A my $FILENAME = shift;
904N/A my $phpNsapi = $phpSoName;
904N/A
904N/A if (isNSAPI()) {
904N/A
904N/A $entry = <<__UP_TO_THIS_POINT_;
904N/A
904N/AInit fn="load-modules" shlib="$phpNsapi" shlib_flags="global|now"
904N/A funcs="php5_init,php5_close,php5_execute,php5_auth_trans"
904N/AInit fn="php5_init"
904N/A php_ini="$PHP_CONF_ROOT"
904N/A php_ini_scandir="$PHP_MODULES_CONF_ROOT"
904N/A errorString="PHP failed to initialize."
904N/A
904N/A__UP_TO_THIS_POINT_
904N/A
904N/A } else { # fastcgi
904N/A
904N/A $entry = <<__UP_TO_THIS_POINT_;
904N/A
904N/AInit fn="load-modules" shlib="$fastCGISoName"
904N/A
904N/A__UP_TO_THIS_POINT_
904N/A
904N/A }
904N/A
904N/A print $FILENAME $entry;
904N/A}
904N/A
904N/A# -----------------------------------------------------------------------------
904N/A# addMimeTypesEntry
904N/A# Add the required mime types entry
904N/A# -----------------------------------------------------------------------------
904N/Asub addToMimeTypes {
904N/A my $FILENAME = shift;
904N/A my $entry = <<__UP_TO_THIS_POINT_;
904N/A
904N/Atype=magnus-internal/php exts=php,php3,php4,php5
904N/A__UP_TO_THIS_POINT_
904N/A print $FILENAME $entry;
904N/A}
904N/A
904N/A# -----------------------------------------------------------------------------
904N/A# addObjConfEntry
904N/A# Add the required obj conf entry
904N/A# -----------------------------------------------------------------------------
904N/Asub addToObjConf {
904N/A # setup
904N/A my $FILENAME = shift;
904N/A # On windows, replace \ with / in paths
904N/A my $l_php_root = $PHP_ROOT;
904N/A if (isWindows()) {
904N/A $l_php_root =~ s/\\/\//g;
904N/A }
904N/A
904N/A my $newLibPath = "$l_php_root/lib";
904N/A my $newLibPath64 = "$l_php_root/lib/64";
904N/A my $childs = &detectDefaultChildren();
904N/A
904N/A my $unixFastCGIEntry = <<__UNIX_FASTCGI_ENTRY_
904N/A<If -f \$path>
904N/AService type="magnus-internal/php"
904N/A fn="responder-fastcgi"
904N/A app-path="$l_php_root/bin/php-cgi"
904N/A bind-path="localhost:3101"
904N/A app-env="PHPRC=$PHP_CONF_ROOT"
904N/A app-env="PHP_INI_SCANDIR=$PHP_MODULES_CONF_ROOT"
904N/A app-env="PHP_FCGI_CHILDREN=$childs"
904N/A app-env="PHP_FCGI_MAX_REQUESTS=2000"
904N/A app-env="FCGI_WEB_SERVER_ADDRS=127.0.0.1"
904N/A bucket="php-bucket"
904N/A</If>
904N/A<Else>
904N/AService type="magnus-internal/php" fn="set-variable" error="404"
904N/A</Else>
904N/A
904N/A__UNIX_FASTCGI_ENTRY_
904N/A;
904N/A
904N/A my $windowsFastCGIEntry = <<__WINDOWS_FASTCGI_ENTRY_
904N/A
904N/AService type="magnus-internal/php"
904N/A fn="responder-fastcgi"
904N/A app-path="$l_php_root/php-cgi.exe"
904N/A bind-path="$INSTANCE_NAME--php_cgi"
904N/A app-env="PHPRC=$l_php_root"
904N/A app-env="PHP_FCGI_CHILDREN=$childs"
904N/A app-env="PHP_FCGI_MAX_REQUESTS=2000"
904N/A bucket="php-bucket"
904N/A
904N/A__WINDOWS_FASTCGI_ENTRY_
904N/A;
904N/A
904N/A my $nsapiEntry = <<__NSAPI_ENTRY_
904N/A
904N/AService type="magnus-internal/php" fn="php5_execute"
904N/A
904N/A__NSAPI_ENTRY_
904N/A;
904N/A
904N/A my $entry;
904N/A
904N/A if (isNSAPI()) {
904N/A $entry = $nsapiEntry;
904N/A } else {
904N/A if (isWindows()) {
904N/A $entry = $windowsFastCGIEntry;
904N/A } else {
904N/A $entry = $unixFastCGIEntry;
904N/A }
904N/A }
904N/A
904N/A print $FILENAME $entry;
904N/A}
904N/A
904N/A# -----------------------------------------------------------------------------
904N/A# isNSAPI
904N/A# Check if SAPI is nsapi
904N/A# -----------------------------------------------------------------------------
904N/A
904N/Asub isNSAPI() {
904N/A if ($SAPI =~ m/nsapi/i) {
904N/A return 1;
904N/A }
904N/A return 0;
904N/A}
904N/A
904N/A# -----------------------------------------------------------------------------
904N/A# isWindows
904N/A# Check platform
904N/A# -----------------------------------------------------------------------------
904N/A
904N/Asub isWindows() {
904N/A if ($OSNAME =~ m/WIN/i) {
904N/A return 1;
904N/A }
904N/A return 0;
904N/A}
904N/A
904N/A# -----------------------------------------------------------------------------
904N/A# checkFilesWritable
904N/A# Check all the necessary files writable before adding the entries
904N/A# -----------------------------------------------------------------------------
904N/A
904N/Asub checkFilesWritable {
904N/A exit 1 unless defined isValidFile("$INSTANCE_ROOT/$INSTANCE_NAME/config/magnus.conf");
904N/A my @TMP_OBJ_CONF_FILES = @$OBJ_CONF_FILES;
904N/A my @TMP_MIME_TYPES_FILES = @$MIME_TYPES_FILES;
904N/A
904N/A while(scalar(@TMP_OBJ_CONF_FILES) > 0) {
904N/A my $objConfFile = pop(@TMP_OBJ_CONF_FILES);
904N/A exit 1 unless defined isValidFile("$objConfFile");
904N/A }
904N/A while(scalar(@TMP_MIME_TYPES_FILES) > 0) {
904N/A my $mimeTypesFile = pop(@TMP_MIME_TYPES_FILES);
904N/A exit 1 unless defined isValidFile("$mimeTypesFile");
904N/A }
904N/A}
904N/A
904N/A# -----------------------------------------------------------------------------
904N/A# getValidAbsoluteFilePath
904N/A# To get the valid absolute file path
904N/A# -----------------------------------------------------------------------------
904N/A
904N/Asub getValidAbsoluteFilePath {
904N/A my ($file) = @_;
904N/A
904N/A if (defined $file) {
904N/A my ($fileName,$filePath,$fileNameSuffix) = fileparse("$file");
904N/A if ($fileName eq $file) {
904N/A $file = "$INSTANCE_ROOT/$INSTANCE_NAME/config/$fileName";
904N/A }
904N/A
904N/A $file = undef unless defined isValidFile($file);
904N/A }
904N/A
904N/A return $file;
904N/A}
904N/A
904N/A# -----------------------------------------------------------------------------
904N/A# getValidAbsoluteFilePath
904N/A# Valid file check
904N/A# -----------------------------------------------------------------------------
904N/A
904N/Asub isValidFile {
904N/A my ($file) = @_;
904N/A my $status = undef;
904N/A
904N/A if (-e "$file") {
904N/A if (-w "$file") {
904N/A $status = 1;
904N/A } else {
904N/A print "\nERROR: $file is not writable. \n\n";
904N/A exit 1;
904N/A }
904N/A } else {
904N/A print "\nERROR: $file not found, $! \n\n";
904N/A exit 1;
904N/A }
904N/A
904N/A return $status;
904N/A}
904N/A
904N/A# -----------------------------------------------------------------------------
904N/A# detectDefaultChildren
904N/A# detect current architecture and come up with default values.
904N/A# set default value to a higher value on Niagara based servers.
904N/A# -----------------------------------------------------------------------------
904N/Asub detectDefaultChildren {
904N/A my $default = 2;
904N/A if ($OSNAME =~ /SOLARIS/i) {
904N/A if (-x "/bin/uname") {
904N/A my $type = qx(/bin/uname -m);
904N/A chomp($type);
904N/A $default *= 3 if ($type =~ /sun4u/i);
904N/A $default *= 6 if ($type =~ /sun4v/);
904N/A }
904N/A }
904N/A return $default;
904N/A}
904N/A
904N/A# -----------------------------------------------------------------------------
904N/A# printUsage
904N/A# print the usage command
904N/A# -----------------------------------------------------------------------------
904N/A
904N/Asub printUsage {
904N/A print "This script will configure a web server instance to run PHP scripts\n" .
904N/A "either as FastCGI or NSAPI \n".
904N/A "usage : \n" .
904N/A " setupPHP -instancename=<instance name> [-sapi=fastcgi|nsapi]\n" .
904N/A "Examples:\n" .
904N/A "\n".
904N/A "This below example configures Web Server to run PHP in FastCGI mode (Default)\n".
904N/A " setupPHP -instancename=https-php\n" .
904N/A "\n".
904N/A "This below example configures Web Server to run PHP in NSAPI mode\n".
904N/A " setupPHP -instancename=https-php -sapi=nsapi\n";
904N/A exit 1;
904N/A}
904N/A
904N/A# -----------------------------------------------------------------------------
904N/A# printResult
904N/A# print the post setup steps
904N/A# -----------------------------------------------------------------------------
904N/A
904N/Asub printResult {
904N/A #remove "https-" from the instance name and use it as the config name
904N/A my $configName = undef;
904N/A $configName = $INSTANCE_NAME;
904N/A $configName = substr($INSTANCE_NAME, 6) if ($INSTANCE_NAME =~ /^https/);
904N/A my $result = <<__UP_TO_THIS_POINT_;
904N/A
904N/ASetup was sucessful.
904N/A--------------------
904N/A
904N/AThe following steps are necessary to make the changes to all the nodes.
904N/A
904N/A(1) Start the admin server
904N/A
904N/A $INSTALL_ROOT/admin-server/bin/startserv
904N/A
904N/A(2) Connect to the admin server using wadm command
904N/A
904N/A $INSTALL_ROOT/bin/wadm [--user=admin-user] [--password-file=admin-pswd-file] [--host=admin-host] [--port=admin-port]
904N/A
904N/A(3) Pull the modified config from the node to config store
904N/A using the following command in wadm console:
904N/A
904N/A pull-config --config=$configName nodehost
904N/A
904N/A For Example: If the host name for the node is xyz.com then enter the command like,
904N/A
904N/A pull-config --config=$configName xyz.com
904N/A
904N/A(4) Deploy the new changes to all nodes using
904N/A the following command in wadm console:
904N/A
904N/A deploy-config $configName
904N/A
904N/A
904N/A__UP_TO_THIS_POINT_
904N/A print $result;
904N/A}