1212
Merge remote-tracking branch 'origin/development' into development · featherbb/featherbb@adf7cbc · GitHub
Skip to content

Commit adf7cbc

Browse files
committed
Merge remote-tracking branch 'origin/development' into development
2 parents 7f91fab + 8c02790 commit adf7cbc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+4854
-34
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
featherbb/config.php
1+
/featherbb/config.php
2+
/config.php
23
.idea/
34
nbproject/
45
.htaccess

.htaccess.dist

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1+
# Remove index.php from URL
2+
13
RewriteEngine On
24
RewriteCond %{REQUEST_FILENAME} !-f
35
RewriteRule ^ index.php [QSA,L]
46
Options -Indexes
7+
8+
# Disable access to config.php file
9+
# (it should not return any content, but just in case.)
10+
11+
<Files "config.php">
12+
Order Allow,Deny
13+
Deny from all
14+
</Files>

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"slim/slim": "~3.1",
2828
"statical/statical": "^1.1",
2929
"slim/flash": "^0.1.0",
30-
"firebase/php-jwt": "^3.0"
30+
"firebase/php-jwt": "^3.0",
31+
"vierbergenlars/php-semver": "^3.0"
3132
},
3233
"support": {
3334
"email": "[email protected]",
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<?php
2+
3+
/**
4+
* Copyright (C) 2015-2016 FeatherBB
5+
* based on code by (C) 2008-2015 FluxBB
6+
* and Rickard Andersson (C) 2002-2008 PunBB
7+
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
8+
*/
9+
10+
namespace FeatherBB\Controller\Admin;
11+
12+
use FeatherBB\Core\AutoUpdater;
13+
use FeatherBB\Core\PluginAutoUpdater;
14+
use FeatherBB\Core\CoreAutoUpdater;
15+
use FeatherBB\Core\AdminUtils;
16+
use FeatherBB\Core\Error;
17+
use FeatherBB\Core\Url;
18+
use FeatherBB\Core\Utils;
19+
use FeatherBB\Core\Lister;
20+
use FeatherBB\Core\Database;
21+
22+
class Updates
23+
{
24+
public function __construct()
25+
{
26+
translate('admin/index');
27+
translate('admin/updates');
28+
translate('admin/plugins');
29+
}
30+
31+
public function display($req, $res, $args)
32+
{
33+
Container::get('hooks')->fire('controller.admin.updates.display');
34+
35+
$coreUpdates = false;
36+
$coreUpdatesMessage = __('FeatherBB core up to date');
37+
38+
$pluginUpdates = array();
39+
$allPlugins = Lister::getPlugins();
40+
41+
// Check FeatherBB core updates
42+
$coreUpdater = new CoreAutoUpdater();
43+
if ($coreUpdater->checkUpdate() === false) {
44+
$coreUpdatesMessage = join('<br>', $coreUpdater->getErrors());
45+
} else {
46+
// If update available
47+
if ($coreUpdater->newVersionAvailable()) {
48+
$coreUpdates = true;
49+
$coreUpdatesMessage = sprintf(__('FeatherBB core updates available'), ForumSettings::get('o_cur_version'), $coreUpdater->getLatestVersion());
50+
$coreUpdatesMessage .= '<a href="https://github.com/featherbb/featherbb/releases/tag/'.$coreUpdater->getLatestVersion().'" target="_blank">'.__('View changelog').'</a>';
51+
}
52+
}
53+
54+
// Check plugins uavailable versions
55+
foreach ($allPlugins as $plugin) {
56+
// If plugin isn't well formed or doesn't want to be auto-updated, skip it
57+
if (!isset($plugin->name) || !isset($plugin->version) || (isset($plugin->skip_update) && $plugin->skip_update == true)) {
58+
continue;
59+
}
60+
$pluginsUpdater = new PluginAutoUpdater($plugin);
61+
// If check fails, add errors to display in view
62+
if ($pluginsUpdater->checkUpdate() === false) {
63+
$plugin->errors = join('<br>', $pluginsUpdater->getErrors());
64+
$pluginUpdates[] = $plugin;
65+
}
66+
// If update available, add plugin to display in view
67+
if ($pluginsUpdater->newVersionAvailable()) {
68+
$plugin->last_version = $pluginsUpdater->getLatestVersion();
69+
$pluginUpdates[] = $plugin;
70+
}
71+
}
72+
73+
AdminUtils::generateAdminMenu('updates');
74+
75+
return View::setPageInfo(array(
76+
'title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Updates')),
77+
'active_page' => 'admin',
78+
'admin_console' => true,
79+
'plugin_updates' => $pluginUpdates,
80+
'core_updates' => $coreUpdates,
81+
'core_updates_message' => $coreUpdatesMessage
82+
)
83+
)->addTemplate('admin/updates.php')->display();
84+
}
85+
86+
public function upgradePlugins($req, $res, $args)
87+
{
88+
Container::get('hooks')->fire('controller.admin.updates.upgradePlugins');
89+
90+
// Check submit button has been clicked
91+
if (!Input::post('upgrade-plugins')) {
92+
throw new Error(__('Wrong form values'), 500);
93+
}
94+
95+
$upgrade_results = [];
96+
97+
foreach (Input::post('plugin_updates') as $plugin => $version) {
98+
if ($plugin = Lister::loadPlugin($plugin)) {
99+
// If plugin isn't well formed or doesn't want to be auto-updated, skip it
100+
if (!isset($plugin->name) || !isset($plugin->version) || (isset($plugin->skip_update) && $plugin->skip_update == true)) {
101+
continue;
102+
}
103+
$upgrade_results[$plugin->title] = [];
104+
$pluginsUpdater = new PluginAutoUpdater($plugin);
105+
$result = $pluginsUpdater->update();
106+
if ($result !== true) {
107+
$upgrade_results[$plugin->title]['message'] = sprintf(__('Failed upgrade message'), $plugin->version, $pluginsUpdater->getLatestVersion());
108+
$upgrade_results[$plugin->title]['errors'] = $pluginsUpdater->getErrors();
109+
} else {
110+
$upgrade_results[$plugin->title]['message'] = sprintf(__('Successful upgrade message'), $plugin->version, $pluginsUpdater->getLatestVersion());
111+
}
112+
// Will not be empty if upgrade has warnings (zip archive or _upgrade.php file could not be deleted)
113+
$upgrade_results[$plugin->title]['warnings'] = $pluginsUpdater->getWarnings();
114+
} else {
115+
continue;
116+
}
117+
}
118+
119+
// Reset cache
120+
Container::get('cache')->flush();
121+
122+
// Display upgrade results
123+
AdminUtils::generateAdminMenu('updates');
124+
125+
return View::setPageInfo(array(
126+
'title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Updates')),
127+
'active_page' => 'admin',
128+
'admin_console' => true,
129+
'upgrade_results' => $upgrade_results
130+
)
131+
)->addTemplate('admin/updates.php')->display();
132+
}
133+
134+
public function upgradeCore($req, $res, $args)
135+
{
136+
Container::get('hooks')->fire('controller.admin.updates.upgradeCore');
137+
138+
// Check submit button has been clicked
139+
if (!Input::post('upgrade-core')) {
140+
throw new Error(__('Wrong form values'), 500);
141+
}
142+
143+
$key = __('FeatherBB core');
144+
$upgrade_results = [$key => []];
145+
$coreUpdater = new CoreAutoUpdater();
146+
$result = $coreUpdater->update();
147+
if ($result !== true) {
148+
$upgrade_results[$key]['message'] = sprintf(__('Failed upgrade message'), ForumEnv::get('FORUM_VERSION'), $coreUpdater->getLatestVersion());
149+
$upgrade_results[$key]['errors'] = $coreUpdater->getErrors();
150+
} else {
151+
$upgrade_results[$key]['message'] = sprintf(__('Successful upgrade message'), ForumEnv::get('FORUM_VERSION'), $coreUpdater->getLatestVersion());
152+
// Reset cache and update core version in database
153+
Container::get('cache')->flush();
154+
if (!Database::for_table('config')->raw_execute('UPDATE `'.ForumSettings::get('db_prefix').'config` SET `conf_value` = :value WHERE `conf_name` = "o_cur_version"', array('value' => ForumEnv::get('FORUM_VERSION')))) {
155+
$coreUpdater->_warnings[] = __('Could not update core version in database');
156+
}
157+
}
158+
// Will not be empty if upgrade has warnings (zip archive or _upgrade.php file could not be deleted)
159+
$upgrade_results[$key]['warnings'] = $coreUpdater->getWarnings();
160+
161+
// Display upgrade results
162+
AdminUtils::generateAdminMenu('updates');
163+
164+
return View::setPageInfo(array(
165+
'title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Admin'), __('Updates')),
166+
'active_page' => 'admin',
167+
'admin_console' => true,
168+
'upgrade_results' => $upgrade_results
169+
)
170+
)->addTemplate('admin/updates.php')->display();
171+
}
172+
}

featherbb/Core/AdminUtils.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,13 @@ public static function get_content($url)
104104
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
105105

106106
$content = curl_exec($ch);
107+
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
107108

108109
curl_close($ch);
109110

111+
if ($http_status != 200)
112+
return false;
113+
110114
return $content;
111115
}
112116
}

0 commit comments

Comments
 (0)