summaryrefslogtreecommitdiffstats
path: root/install.php
blob: 482a8d0be8442cf720ec267d5cd5189aa7e872c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php

// This is an helper function returning an html table row to avoid code duplication
function installStatus($str, $msg, $result) {
    $class = ($result) ? 'ok' : 'fail';
    return '<tr><td>' . $str . '</td><td class="' . $class . '">' . $msg . '</td></tr>';
}

// If the password and config files exist, moonmoon is already installed
if (file_exists(dirname(__FILE__) . '/custom/config.yml')
    && file_exists(dirname(__FILE__) . '/admin/inc/pwd.inc.php')) {
    $status = 'installed';
} elseif (isset($_REQUEST['url'])) {
    require_once dirname(__FILE__) . '/app/app.php';
    $save = array();
    //Save config file
    $config = array(
        'url'           => filter_var($_REQUEST['url'],   FILTER_SANITIZE_ENCODED),
        'name'          => filter_var($_REQUEST['title'], FILTER_SANITIZE_SPECIAL_CHARS),
        'items'         => 10,
        'shuffle'       => 0,
        'refresh'       => 240,
        'cache'         => 10,
        'nohtml'        => 0,
        'postmaxlength' => 0,
        'cachedir'      => './cache'
    );

    $CreatePlanetConfig = new PlanetConfig($config);
    $save['config'] = file_put_contents(dirname(__FILE__).'/custom/config.yml', $CreatePlanetConfig->toYaml());

    //Save password
    $save['password'] = file_put_contents(dirname(__FILE__).'/admin/inc/pwd.inc.php', '<?php $login="admin"; $password="'.md5($_REQUEST['password']).'"; ?>');

    if (0 != ($save['config'] + $save['password'])) {
        $status = 'installed';
    }
} else {

    // Server requirements with advices in case there is something wrong
    $tests = array(
        'php5' => array(
            'file'       => false,
            'label'      => 'Server is running PHP5',
            'solution'   => 'Check your server documentation to activate PHP5.',
        ),
        'custom' => array(
            'file'       => '/custom',
            'label'      => '<code>./custom</code> is writable',
            'solution'   => 'Change the access rights for <code>./custom</code> with CHMOD'
        ),
        'opml' => array(
            'file'       => '/custom/people.opml',
            'label'      => '<code>./custom/people.opml</code> is writable',
            'solution'   => 'Change the access rights for <code>./custom/people.opml</code> with CHMOD'
        ),
        'changepassword' => array(
            'file'       => '/admin/inc/pwd.inc.php',
            'label'      => 'Administrator password can be changed',
            'solution'   => 'Change the access right for <code>./admin/inc/pwd.inc.php</code> with CHMOD'
        ),
        'cache' => array(
            'file'       => '/cache',
            'label'      => '<code>./cache</code> is writable',
            'solution'   => 'Make <code>./cache</code> writable with CHMOD'
        ),
    );

    // We start by malking sure we have PHP5 as a base requirement
    if(phpversion() >= 5) {
        $strInstall = installStatus($tests['php5']['label'], 'OK',true);
        $strRecommendation = '';
    } else {
        $strInstall = installStatus($tests['php5']['label'], 'FAIL',false);
        $strRecommendation = '<li>' . $tests['php5']['solution'] . '</li>';
    }

    // We now test that all required files are writable
    foreach ($tests as $k => $v) {
        if ($tests[$k]['file']) {
            if(is_writable(dirname(__FILE__) . $tests[$k]['file'])) {
                $strInstall .= installStatus($tests[$k]['label'], 'OK', true);
            } else {
                $strInstall .= installStatus($tests[$k]['label'], 'FAIL',false);
                $strRecommendation .= '<li>' . $tests[$k]['solution'] . '</li>';
             }
        }
    }

    // We can now decide if we install moonmoon or not
    $status = ($strRecommendation != '') ? 'error' : 'install';

}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>moonmoon install</title>
    <style>
    body {
        font: normal 1em sans-serif;
        width: 500px;
        margin: 0 auto;
    }

    /* Error */
    td.ok {
        color: #090;
    }

    td.fail {
        color: #900;
        font-weight: bold;
    }
    th {
        text-align: left;
    }

    /* Install */
    .field label {
        display: block;
    }

    .submit {
        font-size: 2em;
    }

    </style>
</head>

<body>
    <h1>moonmoon installation</h1>

    <?php if ($status == 'error') : ?>
    <div id="compatibility">
        <h2>Sorry, your server is not compatible with moonmoon.</h2>

        <h3>Your server does not fulfill the requirements</h3>
        <table>
            <thead>
                <tr>
                    <th>Test</th>
                    <th>Result</th>
                </tr>
            </thead>
            <tbody>
                <?php echo $strInstall ?>
            </tbody>
        </table>

        <h3>Troubleshooting</h3>
        <p>To install moonmoon, try the following changes:</p>
        <ul>
            <?php echo $strRecommendation; ?>
        </ul>
    </div>

    <?php elseif ($status == 'install') : ?>
    <div>
        <form method="post" action="">
            <fieldset>
                <input type="hidden" id="url" name="url" value="" readonly="readonly"/>
                <script>
                <!--
                document.forms[0].elements[1].value = document.URL.replace('install.php','');
                -->
                </script>

                <p class="field">
                    <label for="title">Title:</label>
                    <input type="text" id="title" name="title" value="My website"/>
                </p>
                <!--
                <p class="field">
                    <label>Administrator login:</label> <code>admin</code>
                </p>
                -->
                <p class="field">
                    <label for="password">Administrator password:</label>
                    <input type="text" id="password" name="password" class="text password" value="admin" />
                </p>
                <p>
                    <input type="submit" class="submit" value="Install"/>
                </p>
            </fieldset>
        </form>
    </div>

    <?php elseif ($status =='installed'): ?>

    <p>Congratulations! Your moonmoon is ready.</p>
    <h3>What's next?</h3>
    <ol>
        <li>
            <strong>Delete</strong> <code>install.php</code> with your FTP software.
        </li>
        <li>
            Use your password to go to the
            <a href="./admin/">administration panel</a>
        </li>
    </ol>
    <?php endif; ?>
</body>
</html>