Chapter 2: Understanding and Avoiding Security Risks
Identifying the Sources of Risk
Minimizing User-Input Risks
Not Revealing Sensitive Information
Summary
Chapter 3: PHP Best Practices
Best Practices for Naming Variables and Functions
Best Practices for Function/Method
Best Practices for Database
Best Practices for User Interface
Best Practices for Documentation
Best Practices for Web Security
Best Practices for Source Configuration Management
Summary
Part II
Chapter 4: Architecture of an Intranet Application
Understanding Intranet Requirements
Building an Intranet Application Framework
Creating a Database Abstraction Class
Creating an Error Handler Class
Creating a Built-In Debugger Class
Creating an Abstract Application Class
Creating a Sample Application
Summary
Chapter 5: Central Authentication System
How the System Works
Creating an Authentication Class
Creating the Central Login Application
Creating the Central Logout Application
Creating the Central Authentication Database
Testing Central Login and Logout
Making Persistent Logins in Web Server Farms
Summary
Chapter 6: Central User Management System
Identifying the Functionality Requirements
Creating a User Class
User Interface Templates
Creating a User Administration Application
Creating a User Password Application
Creating a Forgotten-Password Recovery Application
Summary
Chapter 7: Intranet System
Identifying Functionality Requirements
Designing the Database
Designing and Implementing the Intranet Classes
Setting Up Application Configuration Files
Setting Up the Application Templates
Intranet Home Application
Installing Intranet Applications from the CD- ROM
Testing the Intranet Home Application
Summary
Chapter 8: Intranet Simple Document Publisher
Identifying the Functionality Requirements
The Prerequisites
Designing the Database
The Intranet Document Application Classes
Setting up Application Configuration Files
Setting Up the Application Templates
The Document Publisher Application
Installing Intranet Document Application
Testing Intranet Document Application
Summary
Chapter 9: Intranet Contact Manager
Functionality Requirements
Understanding Prerequisites
The Database
The Intranet Contact Manager Application Classes
The Application Configuration Files
The Application Templates
The Contact Category Manager Application
The Contact Manager Application
Installing Intranet Contract Manager
Testing Contract Manager
Summary
Chapter 10: Intranet Calendar Manager
Identifying Functionality Requirements
Understanding Prerequisites
Designing the Database
The Intranet Calendar Application Event Class
The Application Configuration Files
The Application Templates
The Calendar Manager Application
The Calendar Event Manager Application
Installing the Event Calendar on Your Intranet
Testing the Event Calendar
Summary
Chapter 11: Internet Resource Manager
Functionality Requirements
Understanding the Prerequisites
Designing the Database
Designing and Implementing the Internet Resource Manager Application Classes
Creating Application Configuration Files
Creating Application Templates
Creating a Category Manager Application
Creating a Resource Manager Application
Creating a Resource Tracking Application
Creating a Search Manager Application
Installing an IRM on Your Intranet
Testing IRM
Security Concerns
Summary
Chapter 12: Online Help System
Functionality Requirements
Understanding the Prerequisites
Designing and Implementing the Help Application Classes
Creating Application Configuration Files
Creating Application Templates
Creating the Help Indexing Application
Creating the Help Application
Installing Help Applications
Testing the Help System
Security Considerations
Summary
Part III
Chapter 13: Tell-a-Friend System
Functionality Requirements
Understanding Prerequisites
Designing the Database
Designing and Implementing the Tell- a- Friend Application Classes
Creating Application Configuration Files
Creating Application Templates
Creating the Tell-a-Friend Main Menu Manager Application
Creating a Tell-a-Friend Form Manager Application
Creating a Tell-a-Friend Message Manager Application
Creating a Tell-a-Friend Form Processor Application
Creating a Tell-a-Friend Subscriber Application
Creating a Tell-a-Friend Reporter Application
Installing a Tell-a-Friend System
Testing the Tell-a-Friend System
Security Considerations
Summary
Chapter 14: E-mail Survey System
Functionality Requirements
Architecture of the Survey System
Designing the Database
Designing and Implementing the Survey Classes
Designing and Implementing the Survey Applications
Developing Survey Execution Manager
Setting Up the Central Survey Configuration File
Setting Up the Interface Template Files
Testing the Survey System
Security Considerations
Summary
Chapter 15: E-campaign System
Features of an E-campaign System
Architecting an E-campaign System
Designing an E-campaign Database
Understanding Customer Database Requirements
Designing E-campaign Classes
Creating Common Configuration and Resource Files
Creating Interface Template Files
Creating an E-campaign User Interface Application
Creating a List Manager Application
Creating a URL Manager Application
Creating a Message Manager Application
Creating a Campaign Manager Application
Creating a Campaign Execution Application
Creating a URL Tracking and Redirection Application
Creating an Unsubscription Tracking Application
Creating a Campaign Reporting Application
Testing the E-Campaign System
Security Considerations
Summary
Part IV
Chapter 16: Command-Line PHP Utilities
Working with the Command-Line Interpreter
Building a Simple Reminder Tool
Building a Geo Location Finder Tool for IP
Building a Hard Disk Usage Monitoring Utility
Building a CPU Load Monitoring Utility
Summary
Chapter 17: Apache Virtual Host Maker
Understanding an Apache Virtual Host
Defining Configuration Tasks
Creating a Configuration Script
Developing makesite
Installing makesite on Your System
Testing makesite
Summary
Chapter 18: BIND Domain Manager
Features of makezone
Creating the Configuration File
Understanding makezone
Installing makezone
Testing makezone
Summary
Part V
Chapter 19: Web Forms Manager
Functionality Requirements
Understanding Prerequisites
Designing the Database
Designing and Implementing the Web Forms Manager Application Classes
Creating the Application Configuration Files
Creating Application Templates
Creating the Web Forms Submission Manager Application
Creating the Web Forms Reporter Application
Creating the CSV Data Exporter Application
Installing the Web Forms Manager
Testing the Web Forms Manager
Security Considerations
Summary
Chapter 20: Web Site Tools
Functionality Requirements
Understanding Prerequisites
Designing the Database
Designing and Implementing the Voting Tool Application Class
Creating the Application Configuration Files
Creating the Application Templates
Creating the Vote Application
Installing the Voting Tool
Testing the Voting Tool
Summary
Part VI
Chapter 21: Speeding Up PHP Applications
Benchmarking Your PHP Application
Buffering Your PHP Application Output
Compressing Your PHP Application Output
Caching Your PHP Applications
Summary
Chapter 22: Securing PHP Applications
Controlling Access to Your PHP Applications
Securely Uploading Files
Using Safe Database Access
Recommended php.ini Settings for a Production Environment
Limiting File System Access for PHP Scripts
Running PHP Applications in Safe Mode
Summary
Part VII
Appendix A: What's on the CD-ROM
System Requirements
What's on the CD
Troubleshooting
Appendix B: PHP Primer
Object-Oriented PHP
Appendix C: MySQL Primer
Using MySQL from the Command- Line
Using phpMyAdmin to Manage MySQL Database
Appendix D: Linux Primer
Installing and Configuring Apache 2.0
Installing and Configuring MySQL Server
Installing and Configuring PHP for Apache 2.0
Common File/Directory Commands
Index
Wiley Publishing, Inc. End-User License Agreement
Nội dung
4. It determines whether the named user account in the command line already exists, using the userExists() function. If the user account does not exists, it creates the account using the createUser() function. 5. Similarly, the script determines whether the user-supplied group name exists, using the groupExists() function. Note that if the user does not supply a group name using the group option, the username is assumed as the default group name. This is possible because in popular Linux sys- tems such as Red Hat Linux, each user is assigned to his or her own group when the user account is created using a standard account-creation tool like useradd. If your system does not create a group corresponding to the username, you should supply the group option with an appropriate group name. 6. Once usernames and groups are checked and/or created as needed, the script calls addSite() to create the virtual site configuration along with the actual directory structure of the site on the disk. 7. Once the configuration is created, the script checks to see if the user wants to restart Apache ( restart) or test ( test) the configuration. If either case is true, the Web server is restarted using the restartApache() function. 8. If the test option ( test) was provided in the command line, the testNewSite() function is called to test the new site. The test is per- formed by adding a test.txt file in the site and retrieving it as an HTTL get request. If the test.txt can be retrieved via an HTTP get request, the site is assumed to be installed and operating properly. 9. If DEFAULT_SYMLINK_USER_TO_WEBSITE is set to TRUE, a symbolic soft link is created from the user’s home directory to the new Web site using the createSymLink() function. 10. Next, the addContents() function is called to optionally add any con- tents using the master_content template for the current account type. 11 . Finally, if the notify_email option was provided with an e-mail address, the sendMail() function is called to send an e-mail message to the given e-mail address using the mail template specified for the current account type. Installing makesite on Your System The complete makesite package is provided in the CDROM/ch17 directory in make- site.tar.gz . Extract this package on your Linux system and modify the configu- ration files as needed. The makesite.conf file has two path settings that are likely to differ from your system: $PEAR_DIR = ‘/example/intranet/htdocs/pear’ ; 636 Part IV: Using PHP for Sysadmin Tasks 22 549669 ch17.qxd 4/4/03 9:27 AM Page 636 The $PEAR_DIR must point to the directory in which you installed PEAR, or at least the Console/Getopt.php package from PEAR: $APACHE_INFO[path] = ‘/usr/local/apache’, The preceding path should point to the top directory of your Apache Web server. For example, if you have installed Apache in /home/httpd, you should change it. The makesite script assumes that your Apache directory structure is as follows: Top Apache Directory: /usr/local/apache Apache Binary Directory: /usr/local/apache/bin Apache Configuration Directory: /usr/local/apache/conf Apache Virtual Host Configuration Directory: /usr/local/apache/conf/vhosts You will have to create the virtual host configuration directory manually, as it is not standard in the Apache installer. In addition, the makesite.conf file has a few other system-dependent configura- tions, such as server_ip and www_partition, in $SYSTEM_INFO. You should review all the configurations in makesite.conf to ensure that the paths and values reflect your system as closely as possible. The www_partition should point to the top directory of your system, where you want to create the actual virtual host sites. For example, the sample configuration assumes /www as the www_partition, and therefore a –virtual host www.exam- ple.com is created as follows: /www Site directory: /www/www.example.com Site’s document root: /www/www.example.com/htdocs Site’s log directory: /www/www.example.com/logs If this is now the directory structure you want to implement, you have to change www_partition to reflect the top directory, and then you have to change each account’s vhost_template code to reflect your requirements. For example, the std_vhost.conf file (used for standard account) creates the following: $serverRoot = sprintf(“%s/%s”, $www, $server); $docRoot = sprintf(“%s/%s/htdocs”, $www, $server); $logDir = sprintf(“%s/%s/logs”, $www, $server); These can be changed to reflect your directory structure. Chapter 17: Apache Virtual Host Maker 637 22 549669 ch17.qxd 4/4/03 9:27 AM Page 637 Testing makesite Once you have installed and configured makesite in a directory, you can run it as root from the script directory. For example: ./makesite add user mrfrog -p 12345 -v r2d2.exampleexample.com type gold –test Here, the makesite script is asked to create a virtual host configuration for a host called r2d2.exampleexample.com using the account type of gold. The script also indicates that the host will be owned by the user mrfrog, with the password 12345. Here is the sample output: Creating user account: mrfrog with password 12345 shell=/bin/tcsh Creating r2d2.exampleexample.com configuration Checking syntax: /usr/local/apache/conf/vhosts/r2d2.examplexample.com Syntax OK Appending Include /usr/local/apache/conf/vhosts/r2d2.exampleexample.com in /usr/local/apache/conf/httpd.conf Restarting Apache: /usr/local/apache/bin/httpd -k restart Writing test page: /www/r2d2.exampleexample.com/htdocs/test.txt Testing: requesting http://r2d2.exampleexample.com/test.txt successful. Creating symbolic link using /bin/ln -s /www/r2d2.exampleexample.com ~mrfrog/r2d2.exampleexample.com The actual virtual host configuration used by Apache is stored in the conf/vhosts/r2d2.exampleexample.com file, which looks like the following: # # Automated virtual host configuration for r2d2.exampleexample.com # # Account Type: standard # <VirtualHost 192.168.0.11> ServerName r2d2.exampleexample.com DocumentRoot “/www/r2d2.exampleexample.com/htdocs” ErrorLog “/www/r2d2.exampleexample.com/logs/errors.log” CustomLog “/www/r2d2.exampleexample.com/logs/access.log” common 638 Part IV: Using PHP for Sysadmin Tasks 22 549669 ch17.qxd 4/4/03 9:27 AM Page 638 <Directory /> <Files “*.conf”> deny from all </Files> </Directory> </VirtualHost> The httpd.conf file is appended with the following lines: # # # Following line loads configuration # for the r2d2.exampleexample.com virtual host Include /usr/local/apache/conf/vhosts/r2d2.exampleexample.com When the Apache server restarts, it loads the virtual host configuration for r2d2.exampleexample.com host from /usr/local/apache/conf/vhosts/r2d2.example- example.com. This ensures that your httpd.conf file is not cluttered with numerous virtual host configurations, as the Include directive enables you to keep the virtual host con- figuration outside the main httpd.conf file. You must have a NameVirtualHost directive specified in httpd.conf before any “name virtual hosts” configurations are added. For example: NameVirtualHost * Include /usr/local/apache/conf/vhosts/ r2d2.exampleexample.com Include /usr/local/apache/conf/vhosts/ diablo.exampleexample.com To better understand the tasks that are performed by makesite, you can set DEBUG to TRUE in makesite.conf to see what gets done. For example: ./makesite add user mrfrog vhost r2d2.exampleexample.com -p 12345 notify_email=kabir Chapter 17: Apache Virtual Host Maker 639 22 549669 ch17.qxd 4/4/03 9:27 AM Page 639 Here is a sample output: Creating user account: mrfrog with password 12345 shell=/bin/true Creating r2d2.example.com configuration Create directories /bin/mkdir -m 0755 -p /www/r2d2.example.com /bin/chown -R mrfrog:mrfrog /www/r2d2.example.com /bin/chmod -R 0755 /www/r2d2.example.com /bin/mkdir -m 0755 -p /www/r2d2.example.com/htdocs /bin/chown -R mrfrog:mrfrog /www/r2d2.example.com/htdocs /bin/chmod -R 0755 /www/r2d2.example.com/htdocs /bin/mkdir -m 0755 -p /www/r2d2.example.com/logs /bin/chown -R mrfrog:mrfrog /www/r2d2.example.com/logs /bin/chmod -R 0755 /www/r2d2.example.com/logs Checking syntax: /usr/local/apache/conf/vhosts/r2d2.example.com Syntax OK Appending Include /usr/local/apache/conf/vhosts/r2d2.example.com in /usr/local/apache/conf/httpd.conf # # # Following line loads configuration # for the r2d2.example.com virtual host Include /usr/local/apache/conf/vhosts/r2d2.example.com Creating symbolic link using /bin/ln -s /www/r2d2.example.com /home/mrfrog/r2d2.example.com /bin/cp -r vhosts/standard/htdocs/* /www/r2d2.example.com/htdocs Sending mail to using vhosts/std_vhost.mail Summary In this chapter, you learned how to develop a command-line PHP script that helps you manage Apache virtual hosts on your Linux system. Using this script creating, changing, and removing virtual servers becomes almost easy. Remember to visit www.apache.org for documentation on Apache and more directives for use with virtual hosts. 640 Part IV: Using PHP for Sysadmin Tasks 22 549669 ch17.qxd 4/4/03 9:27 AM Page 640 . Part IV: Using PHP for Sysadmin Tasks 22 549669 ch17.qxd 4/4/03 9:27 AM Page 636 The $PEAR_DIR must point to the directory in which you installed PEAR, or at least the Console/Getopt .php package. “/www/r2d2.exampleexample.com/htdocs” ErrorLog “/www/r2d2.exampleexample.com/logs/errors.log” CustomLog “/www/r2d2.exampleexample.com/logs/access.log” common 638 Part IV: Using PHP for Sysadmin Tasks 22 549669 ch17.qxd 4/4/03 9:27 AM Page 638 <Directory /> <Files. using vhosts/std_vhost.mail Summary In this chapter, you learned how to develop a command-line PHP script that helps you manage Apache virtual hosts on your Linux system. Using this script creating, changing,