Tải bản đầy đủ (.pdf) (5 trang)

Secure PHP Development- P6 potx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (77.6 KB, 5 trang )

authorize() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537
displayAddMessageMenu() . . . . . . . . . . . . . . . . . . . . . . . . . . 537
displayModMessageMenu() . . . . . . . . . . . . . . . . . . . . . . . . . 537
updateMessage() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537
deleteMessage() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537
addMessage() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538
getMsgPreviewInput() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538
doPreview() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538
showMsgPreview() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538
appendHashes() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538
Creating a Campaign Manager Application . . . . . . . . . . . . 538
run() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
createCampaign() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
delCampaign() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
modifyCampaign() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
authorize() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
displayCampaignMenu() . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
addCampaign() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
updateCampaign() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
Creating a Campaign Execution Application . . . . . . . . . . . 541
run() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
executeCampaign() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542
authorize() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
Creating a URL Tracking and Redirection Application . . . . 544
run() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544
computeCheckSum() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545
keepTrackAndRedirect() . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545
redirectTest() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545
Creating an Unsubscription Tracking Application . . . . . . . 545
run() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545
computeCheckSum() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546


askForConfirmation() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
unsubUser() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
Creating a Campaign Reporting Application . . . . . . . . . . . 547
run() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
showEcampaignReport() . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
authorize() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
toggleDescField() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
Testing the E-Campaign System . . . . . . . . . . . . . . . . . . . . 549
Creating a list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
Creating a target URL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550
Creating a message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
Creating a campaign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
xxiv Contents
01549669 FM.qxd 4/4/03 9:23 AM Page xxiv
Executing a campaign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554
Viewing a campaign report . . . . . . . . . . . . . . . . . . . . . . . . . 554
Security Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 555
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 555
Part IV Using PHP for Sysadmin Tasks
Chapter 16 Command-Line PHP Utilities . . . . . . . . . . . . . . . . . . . 559
Working with the Command-Line Interpreter . . . . . . . . . . 560
Reading standard input . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562
Getting into arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
Building a Simple Reminder Tool . . . . . . . . . . . . . . . . . . . 569
Features of the reminder tool . . . . . . . . . . . . . . . . . . . . . . . . 570
Implementing the reminder tool . . . . . . . . . . . . . . . . . . . . . . 570
Installing the reminder tool as a cron job . . . . . . . . . . . . . . . . 582
Building a Geo Location Finder Tool for IP . . . . . . . . . . . 583
Building a Hard Disk Usage Monitoring Utility . . . . . . . . . 587
Installing the hdmonitor tool as a cron job . . . . . . . . . . . . . . 594

Building a CPU Load Monitoring Utility . . . . . . . . . . . . . . 595
Installing the loadmonitor tool as a cron job . . . . . . . . . . . . . 605
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606
Chapter 17 Apache Virtual Host Maker . . . . . . . . . . . . . . . . . . . . . 607
Understanding an Apache Virtual Host . . . . . . . . . . . . . . . 607
Defining Configuration Tasks . . . . . . . . . . . . . . . . . . . . . . 609
Creating a Configuration Script . . . . . . . . . . . . . . . . . . . . . 611
Developing makesite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612
Creating the makesite.conf file . . . . . . . . . . . . . . . . . . . . . . . 612
Creating the virtual host configuration . . . . . . . . . . . . . . . . . 615
Creating the contents configuration file . . . . . . . . . . . . . . . . . 617
Creating the e-mail template . . . . . . . . . . . . . . . . . . . . . . . . 618
Creating the makesite script . . . . . . . . . . . . . . . . . . . . . . . . . 619
Installing makesite on Your System . . . . . . . . . . . . . . . . . . 636
Testing makesite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640
Chapter 18 BIND Domain Manager . . . . . . . . . . . . . . . . . . . . . . . . 641
Features of makezone . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641
Creating the Configuration File . . . . . . . . . . . . . . . . . . . . . 642
Understanding makezone . . . . . . . . . . . . . . . . . . . . . . . . . . 647
The makezone Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 653
Installing makezone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655
Testing makezone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 656
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658
Contents xxv
01549669 FM.qxd 4/4/03 9:23 AM Page xxv
Part V Internet Applications
Chapter 19 Web Forms Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . 661
Functionality Requirements . . . . . . . . . . . . . . . . . . . . . . . . 661
Understanding Prerequisites . . . . . . . . . . . . . . . . . . . . . . . 662

Designing the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . 662
WEBFORMS_DL_TBL table . . . . . . . . . . . . . . . . . . . . . . . . . 663
X_TBL table (a sample form table) . . . . . . . . . . . . . . . . . . . . 663
Designing and Implementing the Web Forms Manager
Application Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 664
Designing and implementing the ACL class . . . . . . . . . . . . . . 665
Designing and implementing the DataCleanup class . . . . . . . . 666
Designing and implementing the DataValidator class . . . . . . . . 667
Designing and implementing the FormSubmission class . . . . . . 669
Designing and implementing the FormData class . . . . . . . . . . 672
Creating the Application Configuration Files . . . . . . . . . . . 674
Creating the main configuration file . . . . . . . . . . . . . . . . . . . 674
Creating a sample form configuration file . . . . . . . . . . . . . . . 677
Creating the errors file . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678
Creating Application Templates . . . . . . . . . . . . . . . . . . . . . 679
Creating the Web Forms Submission
Manager Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679
run() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680
showPage() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680
authorize() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681
Creating the Web Forms Reporter Application . . . . . . . . . . 681
run() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681
showReport() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681
Creating the CSV Data Exporter Application . . . . . . . . . . . 682
run() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 682
processRequest() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683
Installing the Web Forms Manager . . . . . . . . . . . . . . . . . . 683
Testing the Web Forms Manager . . . . . . . . . . . . . . . . . . . . 685
Security Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 693
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695

Chapter 20 Web Site Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 697
Functionality Requirements . . . . . . . . . . . . . . . . . . . . . . . . 697
Understanding Prerequisites . . . . . . . . . . . . . . . . . . . . . . . 698
Designing the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . 698
VOTES Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 698
Designing and Implementing the Voting Tool
Application Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 699
Designing and implementing the Vote class . . . . . . . . . . . . . . 699
xxvi Contents
01549669 FM.qxd 4/4/03 9:23 AM Page xxvi
Creating the Application Configuration Files . . . . . . . . . . . 701
Creating the main configuration file . . . . . . . . . . . . . . . . . . . 701
Creating an errors file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703
Creating the Application Templates . . . . . . . . . . . . . . . . . . 703
Creating the Vote Application . . . . . . . . . . . . . . . . . . . . . . 703
run() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704
setPollID() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704
getPollID() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704
addVote() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704
displayVoteResult() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704
Installing the Voting Tool . . . . . . . . . . . . . . . . . . . . . . . . . 705
Testing the Voting Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . 706
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710
Part VI Tuning and Securing PHP Applications
Chapter 21 Speeding Up PHP Applications . . . . . . . . . . . . . . 713
Benchmarking Your PHP Application . . . . . . . . . . . . . . . . 714
Benchmarking your code . . . . . . . . . . . . . . . . . . . . . . . . . . . 714
Avoiding bad loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 718
Stress-testing your PHP applications using ApacheBench . . . . 722
Buffering Your PHP Application Output . . . . . . . . . . . . . . 723

Compressing Your PHP Application Output . . . . . . . . . . . . 725
Caching Your PHP Applications . . . . . . . . . . . . . . . . . . . . 727
Caching PHP contents using the jpcache cache . . . . . . . . . . . . 727
Caching PHP contents using the PEAR cache . . . . . . . . . . . . . 729
Using PHP opcode caching techniques . . . . . . . . . . . . . . . . . . 734
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 736
Chapter 22 Securing PHP Applications . . . . . . . . . . . . . . . . . . . . . 737
Controlling Access to Your PHP Applications . . . . . . . . . . 737
Restricting access to your PHP application-related files . . . . . . 738
Using Web server–based authentication . . . . . . . . . . . . . . . . 739
Using the MD5 message digest for login . . . . . . . . . . . . . . . . 740
Using Web server–based authorization . . . . . . . . . . . . . . . . . 743
Restricting write access to directories . . . . . . . . . . . . . . . . . . 744
Securely Uploading Files . . . . . . . . . . . . . . . . . . . . . . . . . . 744
Using Safe Database Access . . . . . . . . . . . . . . . . . . . . . . . . 747
Recommended php.ini Settings for a
Production Environment . . . . . . . . . . . . . . . . . . . . . . . . . 748
Limiting File System Access for PHP Scripts . . . . . . . . . . . 748
Running PHP Applications in Safe Mode . . . . . . . . . . . . . 749
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 750
Contents xxvii
01549669 FM.qxd 4/4/03 9:23 AM Page xxvii
Part VII Appendixes
Appendix A What’s on the CD-ROM . . . . . . . . . . . . . . . . . . . . . . . . 753
Appendix B PHP Primer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 757
Appendix C MySQL Primer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763
Appendix D Linux Primer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 781
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 833
Wiley Publishing, Inc. End-User
License Agreement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 881

xxviii Contents
01549669 FM.qxd 4/4/03 9:23 AM Page xxviii

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×