1. Trang chủ
  2. » Công Nghệ Thông Tin

Secure PHP Development- P129 pps

5 69 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 99,13 KB

Nội dung

3. Create all the necessary Web and user account configurations and copy appropriate contents based on account type “gold.” In other words, all the “gold” account features will be implemented. This may include enabling PHP, CGI, SSI, and other Web features, or the installation of custom soft- ware such as phpMyAdmin, and so on. 4. Automatically restart Apache server. 5. Automatically test the new Web site by making requests to see if the site is operational. 6. Automatically notify the account owner via e-mail that the site is opera- tional, and provide necessary instructions to access and manage the Web site. Clearly, this script reduces quite a bit of work for a Web administrator, and therefore it is well worth developing. However, before we can make such an inter- esting script, we need to define a set of standard account types for the system. Creating a Configuration Script The makesite script uses the -type=account_type command-line argument to determine numerous tasks that need to be performed in the virtual host setup process. For example, we can define the following accounts: $ACCOUNT_TYPE[‘standard’] = array( vhost_template => ‘std_vhost.conf’, master_contents =>’std_contents.conf’, mail_template => ‘std_vhost.mail’, shell => ‘/bin/true’ ); $ACCOUNT_TYPE[‘gold’] = array( vhost_template => ‘gold_vhost.conf’, master_contents =>’gold_contents.conf’, mail_template => ‘gold_vhost.mail’, shell => ‘/bin/tcsh’ ); $ACCOUNT_TYPE[‘platinum’] = array( vhost_template => ‘platinum_vhost.conf’, master_contents =>’platinum_contents.conf’, mail_template => ‘platinum_vhost.mail’, shell => ‘/bin/bash’, ); Chapter 17: Apache Virtual Host Maker 611 22 549669 ch17.qxd 4/4/03 9:27 AM Page 611 This script defines three types of Web site accounts: standard, gold, and plat- inum. These names are arbitrary, of course. You can choose whatever names you like. For example, a university administrator might choose: coursesite, deptsite, stu- dentsite, and so on, as account types. Now let’s examine one of the account config- urations. The standard account type defines that the virtual host configuration (vhost_template) template is std_vhost.conf. This is a PHP-based virtual host con- figuration generator script. The std_contents.conf script is another PHP-based con- tents configuration script. The mail template is simply a text file with special tags that are replaced before it is sent to the account owner. When creating a standard account, the makesite script does the following: 1. It uses the vhost_template (std_vhost.conf) to create the Apache configuration. 2. It uses the master_contents (std_contents.conf) to do content-specific configuration. 3. Optionally (if told to do so), it uses the mail_template (std_vhost.mail) to send an e-mail to the account owner. Note that there is no restriction governing how many types of accounts you can define as long as you also create the necessary configuration templates. Developing makesite As you have seen, the makesite script has several pieces that must be created and fit together for the script to operate. The following sections will cover the development of the various pieces. Creating the makesite.conf file The makesite script uses the makesite.conf file, as shown in Listing 17-1. The make- site configuration file is the central configuration file for the application. Listing 17-1: makesite.conf <?php // Set this to the PEAR directory $PEAR_DIR = ‘/example/intranet/htdocs/pear’ ; ini_set( ‘include_path’, ‘:’ . $PEAR_DIR . ‘:’ . ini_get(‘include_path’)); require_once “Console/Getopt.php”; define(DEBUG, FALSE); 612 Part IV: Using PHP for Sysadmin Tasks 22 549669 ch17.qxd 4/4/03 9:27 AM Page 612 $APACHE_INFO = array( ‘user’ => ‘httpd’, ‘group’ => ‘httpd’, ‘path’ => ‘/usr/local/apache’, ‘bin_dir’ => ‘bin’, ‘conf_dir’ => ‘conf’, ‘conf_flie’ => ‘httpd.conf’, ‘server_bin’ => ‘httpd’, ‘config_chk_opt’ => ‘-t -f’, ‘restart_opt’ => ‘-k restart’, ‘vhost_conf_dir’ => ‘conf/vhosts’ ); $SYSTEM_INFO = array( ‘passwd_file’ => ‘/etc/passwd’, ‘home_dir’ => ‘/home’, ‘min_passwd_length’ => 5, ‘group_file’ => ‘/etc/group’, ‘server_ip’ => ‘192.168.0.11’, ‘useradd_bin’ => ‘/usr/sbin/useradd’, ‘www_partition’ => ‘/www’, ‘permission’ => ‘0755’, ‘symlink_bin’ => ‘/bin/ln’, ‘symlink_opt’ => ‘-s’, ‘cp_bin’ => ‘/bin/cp’, ‘cp_opt’ => ‘-r’, ‘mkdir_bin’ => ‘/bin/mkdir’, ‘chmod_bin’ => ‘/bin/chmod’, ‘chown_bin’ => ‘/bin/chown’ ); define(DEFAULT_ACCOUNT_TYPE , ‘standard’); define(DEFAULT_SYMLINK_USER_TO_WEBSITE , TRUE); //$TEMPLATE_DIR = ‘/www/vhosts’; $TEMPLATE_DIR = ‘vhosts’; $ACCOUNT_TYPE[‘standard’] = array( vhost_template => ‘std_vhost.conf’, master_contents =>’std_contents.conf’, mail_template => ‘std_vhost.mail’, shell => ‘/bin/true’ ); Continued Chapter 17: Apache Virtual Host Maker 613 22 549669 ch17.qxd 4/4/03 9:27 AM Page 613 Listing 17-1 (Continued) $ACCOUNT_TYPE[‘gold’] = array( vhost_template => ‘gold_vhost.conf’, master_contents =>’gold_contents.conf’, mail_template => ‘gold_vhost.mail’, shell => ‘/bin/tcsh’ ); $ACCOUNT_TYPE[‘platinum’] = array( vhost_template => ‘platinum_vhost.conf’, master_contents =>’platinum_contents.conf’, mail_template => ‘platinum_vhost.mail’, shell => ‘/bin/bash’, ); ?> This configuration file defines a set of the $ACCOUNT_TYPE associative array as discussed previously and also defines the following: ◆ $APACHE_INFO is an associative array that holds information about vari- ous Apache-specific configurations. For example, the sample configura- tion indicates that the Apache server is run as the ‘httpd’ user, as $APACHE_INFO[user] is set to ‘httpd’. Similarly, it indicates that Apache is installed in $APACHE_INFO[path], which is set to /usr/local/apache. Numerous other configuration parameters specify options to check, options for restarting the server, and locations of configuration files. ◆ $SYSTEM_INFO is an associative array that holds information specific to the system on which the Apache server is running. For example, $SYSTEM_INFO[passwd_file] points to the password file used by the system, which is /etc/passwd. Similarly, it defines $SYSTEM_INFO [server_ip] , the IP address Apache server listens on. Numerous other configuration parameters specify paths to system commands, the main path to the www directory, and the value of various options to be set by the script. ◆ The DEFAULT_ACCOUNT_TYPE constant defines the default account type. ◆ The DEFAULT_SYMLINK_USER_TO_WEBSITE constant is set to TRUE if a symbolic soft link is to be created from the user’s home directory to his or her Web server’s directory. ◆ The $TEMPLATE_DIR constant points to the subdirectory in the makesite script directory, which holds the account-specific templates. For example, the standard account templates (std_vhost.conf, std_contents.conf, and std_vhost.mail) are stored in the vhosts directory. 614 Part IV: Using PHP for Sysadmin Tasks 22 549669 ch17.qxd 4/4/03 9:27 AM Page 614 The makesite script uses the Console/Getopt.php class from PEAR;therefore, the makesite.conf script loads this script in the beginning of the configura- tion file. Make sure that the $PEAR_DIR variable in makesite.conf is set properly to point to your PEAR installation. Creating the virtual host configuration Listing 17-2 shows the standard account’s virtual host configuration, std_vhosts.conf. This is loaded by the makesite script and processed by calling the makeVirtualHost() function within the configuration file. Listing 17-2: vhosts/std_vhost.conf <?php function makeVirtualHost() { $www = $GLOBALS[SYSTEM_INFO][www_partition]; $ipAddr = $GLOBALS[SYSTEM_INFO][server_ip]; $server = $GLOBALS[SERVER_NAME]; $serverRoot = sprintf(“%s/%s”, $www, $server); $docRoot = sprintf(“%s/%s/htdocs”, $www, $server); $logDir = sprintf(“%s/%s/logs”, $www, $server); $vhostConfig = <<<STD_VHOST_CONF # # Automated virtual host configuration for $GLOBALS[SERVER_NAME] # # Account Type: standard # <VirtualHost $ipAddr> ServerName $server DocumentRoot “$docRoot” ErrorLog “$logDir/errors.log” CustomLog “$logDir/access.log” common Continued Chapter 17: Apache Virtual Host Maker 615 22 549669 ch17.qxd 4/4/03 9:27 AM Page 615 . features will be implemented. This may include enabling PHP, CGI, SSI, and other Web features, or the installation of custom soft- ware such as phpMyAdmin, and so on. 4. Automatically restart Apache. configuration (vhost_template) template is std_vhost.conf. This is a PHP- based virtual host con- figuration generator script. The std_contents.conf script is another PHP- based con- tents configuration script. The. makesite.conf < ?php // Set this to the PEAR directory $PEAR_DIR = ‘/example/intranet/htdocs/pear’ ; ini_set( ‘include_path’, ‘:’ . $PEAR_DIR . ‘:’ . ini_get(‘include_path’)); require_once “Console/Getopt .php ; define(DEBUG,

Ngày đăng: 07/07/2014, 07:20

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN