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
|
<?php
class FreshRSS_update_Controller extends Minz_ActionController {
public function firstAction() {
$current_user = Minz_Session::param('currentUser', '');
if (!$this->view->loginOk && Minz_Configuration::isAdmin($current_user)) {
Minz_Error::error(
403,
array('error' => array(_t('access_denied')))
);
}
Minz_View::prependTitle(_t('update_system') . ' · ');
$this->view->last_update_time = 'unknown'; // TODO
}
public function indexAction() {
if (file_exists(UPDATE_FILENAME)) {
// There is an update file to apply!
$this->view->message = array(
'status' => 'good',
'title' => _t('ok'),
'body' => _t('update_can_apply', _url('update', 'apply'))
);
return;
}
}
public function checkAction() {
$this->view->change_view('update', 'index');
if (file_exists(UPDATE_FILENAME)) {
// There is already an update file to apply: we don't need to check
// the webserver!
$this->view->message = array(
'status' => 'good',
'title' => _t('ok'),
'body' => _t('update_can_apply', _url('update', 'apply'))
);
return;
}
$c = curl_init(FRESHRSS_UPDATE_WEBSITE);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($c);
$c_status = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);
if ($c_status !== 200) {
$this->view->message = array(
'status' => 'bad',
'title' => _t('damn'),
'body' => _t('update_server_not_found', FRESHRSS_UPDATE_WEBSITE)
);
return;
}
$res_array = explode("\n", $result, 2);
$status = $res_array[0];
if (strpos($status, 'UPDATE') !== 0) {
$this->view->message = array(
'status' => 'bad',
'title' => _t('damn'),
'body' => _t('no_update')
);
return;
}
$script = $res_array[1];
if (file_put_contents(UPDATE_FILENAME, $script) !== false) {
$this->view->message = array(
'status' => 'good',
'title' => _t('ok'),
'body' => _t('update_can_apply', _url('update', 'apply'))
);
} else {
$this->view->message = array(
'status' => 'bad',
'title' => _t('damn'),
'body' => _t('update_problem', 'Cannot save the update script')
);
}
}
public function applyAction() {
if (!file_exists(UPDATE_FILENAME)) {
Minz_Request::forward(array('c' => 'update'), true);
}
require(UPDATE_FILENAME);
if (Minz_Request::isPost()) {
save_info_update();
}
if (!need_info_update()) {
$res = apply_update();
if ($res === true) {
@unlink(UPDATE_FILENAME);
// TODO: record last update
Minz_Session::_param('notification', array(
'type' => 'good',
'content' => Minz_Translate::t('update_finished')
));
Minz_Request::forward(array(), true);
} else {
Minz_Session::_param('notification', array(
'type' => 'bad',
'content' => Minz_Translate::t('update_problem', $res)
));
Minz_Request::forward(array('c' => 'update'), true);
}
}
}
}
|