Subversion Repositories Applications.papyrus

Rev

Rev 1688 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
831 florian 1
<?php
2
 
3
////////////////////////////////////////////////////////////////////////////////
4
//                                                                            //
5
//   Copyright (C) 2006  Phorum Development Team                              //
6
//   http://www.phorum.org                                                    //
7
//                                                                            //
8
//   This program is free software. You can redistribute it and/or modify     //
9
//   it under the terms of either the current Phorum License (viewable at     //
10
//   phorum.org) or the Phorum License that was distributed with this file    //
11
//                                                                            //
12
//   This program is distributed in the hope that it will be useful,          //
13
//   but WITHOUT ANY WARRANTY, without even the implied warranty of           //
14
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     //
15
//                                                                            //
16
//   You should have received a copy of the Phorum License                    //
17
//   along with this program.                                                 //
18
////////////////////////////////////////////////////////////////////////////////
19
 
20
    // Check if the cache directory is available and if
21
    // files and directories can be created in it. Also
22
    // do a basic check on Phorums caching API.
23
 
24
    $phorum_check = "Phorum cache";
25
 
26
    function phorum_check_cache(){
27
        $PHORUM = $GLOBALS["PHORUM"];
28
        $dir = $PHORUM["cache"];
29
 
30
        // Some general solution descriptions.
31
        $solution_1 = "Change the Cache Directory setting under
32
                       General Settings.";
33
        $solution_2 = "Change the Cache Directory setting under General
34
                       Settings or give your webserver more permissions
35
                       for the current cache directory.";
36
 
37
        // Check if the cache directory exists.
38
        if (! file_exists($dir) || ! is_dir($dir)) return array(
39
            PHORUM_SANITY_CRIT,
40
            "The system is unable to find the cache
41
             directory \"".htmlspecialchars($dir)."\" on
42
             your system.",
43
            $solution_1
44
        );
45
 
46
        // Check if we can create files in the cache directory.
47
        $fp = @fopen ("$dir/sanity_check_dummy_file", "w");
48
        if (! $fp) return array (
49
            PHORUM_SANITY_CRIT,
50
            "The system is unable to write files
51
             to your cache directory \"".htmlspecialchars($dir)."\".
52
             The system error was:<br/><br/>".
53
             htmlspecialchars($php_errormsg).".",
54
            $solution_2
55
        );
56
        fclose($fp);
57
 
58
        // Some very unusual thing might happen. On Windows2000 we have seen
59
        // that the webserver can write a message to the cache directory,
60
        // but that it cannot read it afterwards. Probably due to
61
        // specific NTFS file permission settings. So here we have to make
62
        // sure that we can open the file that we just wrote.
63
        $checkfp = fopen("$dir/sanity_check_dummy_file", "r");
64
        if (! $checkfp) return array(
65
            PHORUM_SANITY_CRIT,
66
            "The system was able to write a file to your cache directory
67
             \"".htmlspecialchars($dir)."\", but afterwards the created
68
             file could not be read by the webserver. This is probably
69
             caused by the file permissions on your cache directory.",
70
            $solution_2
71
        );
72
 
73
        unlink("$dir/sanity_check_dummy_file");
74
 
75
        // Check if we can create directories in the cache directory.
76
        if (! @mkdir("$dir/sanity_check_dummy_dir")) return array(
77
            PHORUM_SANITY_CRIT,
78
            "The system is unable to create directories
79
             in your cache directory \"".htmlspecialchars($dir)."\".
80
             The system error was:<br/><br/>".htmlspecialchars($php_errormsg).".",
81
            $solution_2
82
        );
83
        rmdir("$dir/sanity_check_dummy_dir");
84
 
85
        // All seems OK. Do a final system check where we check
86
        // the caching system like the Phorum system will do.
87
        phorum_cache_put('sanity_checks', 'dummy', 'dummy');
88
        $entry = phorum_cache_get('sanity_checks', 'dummy');
89
        phorum_cache_remove('sanity_checks', 'dummy');
90
        if ($entry != 'dummy') return array(
91
            PHORUM_SANITY_WARN,
92
            "There might be a problem in Phorum's caching system.
93
             Storing and retrieving a dummy key failed. If you
94
             experience problems with your Phorum installation,
95
             it might me because of this.",
96
            "As a work around, you can disable the caching facilities
97
             in the admin interface. Please contact the Phorum
98
             developers to find out what the problem is.",
99
        );
100
 
101
        return array (PHORUM_SANITY_OK, NULL);
102
    }
103
?>