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
■ The template file includes a Web form that takes the input for a new event to be added or an old event to be modified. ■ When the method is called with mode modify, it loads the Web form using the getEventTitle(), getEventDesc(), getViewers(), getRepeatMode(), and getEventReminder() methods of the Event class. ■ After setting appropriate blocks and variables of the template, showContents() is called to render the output using the proper theme for the user. ◆ deleteEvent(): This method is responsible for deleting events when requested. This works in the following manner: ■ It creates objects for the Event and Message classes. ■ The message ID (MOTD ID) for the event is retrieved using the getEventReminder() method of the Event class, and fed into the deleteMessage() and deleteViewers() methods of the Message class to delete the message. ■ All entries related to this event are eliminated from the CALENDAR_EVENT_VIEWER and CALENDAR_REPETITIVE_EVENTS tables using the deleteViewers() and deleteRepeatMode() methods of the Event class. ■ After deleting all the related data, the event itself is deleted using the deleteEvent() method of the Event class. ■ Depending on the outcome of the deletion process, a success or fail message is shown to the user. ◆ modifyEvent(): This event modifies a given event. Its functionalities are as follows: ■ It checks whether the option to show the event to other users is turned on. If it’s not, it takes only the current user’s ID to add to the viewer table. ■ It validates the user inputs by checking if the publish date and event title have been supplied. If not, it shows an alert message and returns null. ■ If the event’s reminder option is turned on, it checks for previous mes- sages related to the event ID. If it finds a message, the message is mod- ified using the modifyMessage() method of the Message class. Otherwise, the new message is added using addMessage() and addViewer(). Chapter 10: Intranet Calendar Manager 351 13 549669 ch10.qxd 4/4/03 9:25 AM Page 351 ■ If the event’s reminder option is turned off, all the messages and mes- sage viewers related to the event are deleted using deleteMessage() and deleteViewers(). ■ The event attributes are modified using the modifyEvent() method of the Event class. ■ If the status of the modifyEvent() is successful, the new viewers and repeat mode (if any) are added for the event after deleting the previous ones. ■ The user is shown the appropriate confirmation message on the basis of success or failure of the modification operation. ◆ addEvent(): This method adds a new event to the calendar. It works in the following way: ■ It checks whether the option to show the event to other users is turned on. If it’s not, it takes only the current user’s ID to add to the viewer table. ■ It validates the user inputs by checking if the publish date and event title have been supplied or not. If not, it shows an alert message and returns null. ■ If the event’s reminder option is turned on, a new message is added using the addMessage() and addViewer() methods of the Message class. ■ The event attributes are added into the event table using the addEvent() method of the Event class. ■ If the status of addEvent() is successful, the viewers and repeat mode (if any) are added for the event. ■ The user is shown an appropriate confirmation message on the basis of the success or failure of the insertion operation. ◆ showContents(): This method displays the given contents according to the theme preferences of the user. This is how it works: ■ The user’s preferred theme template is loaded in a template object called $themeTemplate. ■ The template contains a contentBlock that is to be filled by the para- meter to this method. ■ After the passed content is set into the contentBlock, it is rendered to the user. 352 Part II: Developing Intranet Solutions 13 549669 ch10.qxd 4/4/03 9:25 AM Page 352 Installing the Event Calendar on Your Intranet The event calendar installation process assumes the following: ◆ You’re using a Linux system with MySQL and Apache server installed. ◆ Your intranet web server document root directory is /evoknow/intranet/ htdocs . Of course, if you have a different path, which is likely, you should change this path whenever you see it in a configuration file or instruction in this chapter. During the installation process, I refer to this directory as %DocumentRoot%. ◆ You’ve installed the PHPLIB and PEAR library. Normally, these get installed during PHP installation. For your convenience, I’ve provided these in the lib/phplib.tar.gz and lib/pear.tar.gz directories on the CD-ROM. In the example installation steps, I assume that these are installed in the /%DocumentRoot%/phplib and / %DocumentRoot%/pear directories. Because your installation location for these libraries is likely to differ, make sure you replace these paths in the configuration files. ◆ You’ve installed the base intranet user home application, the messaging system, and the INTRANET database (see Chapter 7 for details). Here is how you can get your intranet calendar applications up and running: 1. Install intranet calendar database tables. You need to create the CALEN- DAR database. The ch10/sql/calendar.sql file in the CDROM has all the create table scripts needed for the CALENDAR database. The quickest way to create the database is to run the following commands: mysqladmin –u root –p create CALENDAR mysql –u root –p –D CALENDAR < calendar.sql 2. Install intranet calendar applications. Now from the ch10 directory of the CD-ROM, extract ch10.tar.gz in %DocumentRoot%. This will create calendar_mngr in your document root. Configure %DocumentRoot%/cal- endar_mngr/apps/calendar.conf for path and database settings. The applications are installed in the %DocumentRoot%/calendar_mngr/apps directory and the templates are stored in %DocumentRoot%/calendar_mngr/apps/templates. Chapter 10: Intranet Calendar Manager 353 13 549669 ch10.qxd 4/4/03 9:25 AM Page 353 Your MySQL server is hosted on the intranet web server and can be accessed via localhost. However, if this is not the case, you can easily modify the database URLs in each application’s configuration files. For example, the home.conf file has MySQL database access URLs such as $INTRANET_DB_URL = ‘mysql://root:foobar@localhost/INTRANET’; $CALENDAR_DB_URL = ‘mysql://root:foobar@localhost/CALENDAR’; $USER_DB_URL = ‘mysql://root:foobar@localhost/auth’; Say your database server is called db.domain.com and the user name and password to access the INTRANET and auth databases (which you will cre- ate during this installation process) are admin and db123. You would modify the database access URLs throughout each configuration file as $INTRANET_DB_URL = ‘mysql://admin:db123@db.domain.com/INTRANET’; $CALENDAR_DB_URL = ‘mysql://admin:db123@db.domain.com/CALENDAR’; $USER_DB_URL = ‘mysql://admin:db123@db.domain.com/auth’; 3. Adding the calendar to theme navigation bar. You need to update your theme navigation bar files stored in %DocumentRoot%/themes/%theme%/ home_left_nav.html whenever you add a new application. For example, to update the std_blue theme, you need to update the %DocumentRoot%/ themes/std_blue/ home_left_nav.html file to include the following line in the HTML table: <tr><td width=”100%”><font size=2><a href=”/calendar_mngr/apps/calendar_mngr.php”>Calendar</a></fo nt></td> </tr> This creates a new HTML table row in the left navigation bar. 4. Set file/directory permissions. Make sure you’ve changed file and direc- tory permissions such that your intranet web server can access all the files. After you’ve performed these steps, you’re ready to test your calendar applications. Testing the Event Calendar Log in to your intranet via http://yourserver/index.php or http://yourserver/ home/home.php using the user name and password you created in Chapter 6 and tested in Chapter 7. 354 Part II: Developing Intranet Solutions 13 549669 ch10.qxd 4/4/03 9:25 AM Page 354 Click on the Calendar link in the left navigation bar of your intranet home page or point your web browser to http://yourserver/calendar_mngr/apps/ calendar_mngr.php . This shows you the current month, like the example shown in Figure 10-3. Figure 10-3: The current month calendar. The current day (October 16, in my example) is shown is its own color (orange by default), weekends are shown in gray, and a global event (October 22) is shown in cream color. You can configure these colors using calendar.conf parameters such as define(‘TODAY_COLOR’, ‘FF8800’); define(‘WEEKEND_COLOR’, ‘CCCCCC’); define(‘HOLIDAY_COLOR’, ‘ABCDEF’); define(‘GLOBAL_EVENT_COLOR’, ‘FFCC99’); define(‘PERSONAL_EVENT_COLOR’, ‘dfefcf’); The colors are stored in standard RGB format in hex numbers ranging from 000000 (black) to FFFFFF (white). Adding a new event To add an event, find the appropriate month using the Next or Previous links on the top, and then click on the day of the event. For example, to add an event on July 7, 2003, move forward to July 2003 using the Next button and click on the day (7). After you’ve clicked on a date, a screen similar to the one in Figure 10-4 displays. Chapter 10: Intranet Calendar Manager 355 13 549669 ch10.qxd 4/4/03 9:25 AM Page 355 . directory as %DocumentRoot%. ◆ You’ve installed the PHPLIB and PEAR library. Normally, these get installed during PHP installation. For your convenience, I’ve provided these in the lib/phplib.tar.gz. the CD-ROM. In the example installation steps, I assume that these are installed in the /%DocumentRoot%/phplib and / %DocumentRoot%/pear directories. Because your installation location for these libraries. the ch10 directory of the CD-ROM, extract ch10.tar.gz in %DocumentRoot%. This will create calendar_mngr in your document root. Configure %DocumentRoot%/cal- endar_mngr/apps/calendar.conf for path