Skip to content

Commit

Permalink
1.0.7-rc release
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkDHamill committed Sep 7, 2019
1 parent bad0990 commit 31994d0
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 57 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -10,6 +10,6 @@ Go to "ACP" > "Customise" > "Extensions" and enable the "Filter by country" exte

This product includes GeoLite2 data created by MaxMind, available from <a href="https://www.maxmind.com">https://www.maxmind.com</a>. GeoLite software is included in the /vendor directory. After installation, the GeoLite2 Country database is placed in the /store/phppbbservices/filterbycountry directory. This database is updated approximately once a week using phpBB's cron feature.

The following license applies to the remaining software:
The following license applies to the remaining software in this extension:

[GPLv2](license.txt)
13 changes: 9 additions & 4 deletions adm/style/acp_filterbycountry_body.html
Expand Up @@ -9,15 +9,15 @@ <h3>{{ lang('WARNING') }}</h3>
</div>
{% endif %}


<form id="phpbbservices_filterbycountry_acp" name="phpbbservices_filterbycountry_acp" method="post" action="{{ U_ACTION }}">
<fieldset>
{% if S_SETTINGS %}
<legend>{{ lang('SETTINGS') }}</legend>
<dl>
<dt><label>{{ lang('ACP_FBC_ALLOW_RESTRICT') ~ lang('COLON') }}</label><br>{{ lang('ACP_FBC_ALLOW_RESTRICT_EXPLAIN') }}</dt>
<dd><label><input type="radio" class="radio" name="phpbbservices_filterbycountry_allow" value="1"{% if FBC_ALLOW_RESTRICT %} checked="checked"{% endif %} /> {{ lang('ACP_FBC_ALLOW') }}</label>
<label><input type="radio" class="radio" name="phpbbservices_filterbycountry_allow" value="0"{% if not FBC_ALLOW_RESTRICT %} checked="checked"{% endif %} /> {{ lang('ACP_FBC_RESTRICT') }}</label></dd>
<dd><label><input type="radio" class="radio" name="phpbbservices_filterbycountry_allow" value="1"{% if FBC_ALLOW_RESTRICT == 1 %} checked="checked"{% endif %} /> {{ lang('ACP_FBC_ALLOW') }}</label>
<label><input type="radio" class="radio" name="phpbbservices_filterbycountry_allow" value="0"{% if FBC_ALLOW_RESTRICT == 0 %} checked="checked"{% endif %} /> {{ lang('ACP_FBC_RESTRICT') }}</label>
<label><input type="radio" class="radio" id="ignore" name="phpbbservices_filterbycountry_allow" value="2"{% if FBC_ALLOW_RESTRICT == 2 %} checked="checked"{% endif %} /> {{ lang('ACP_FBC_IGNORE') }}</label></dd>
</dl>
<dl>
<dt><label for="phpbbservices_filterbycountry_country_codes">{{ lang('ACP_FBC_COUNTRIES') ~ lang('COLON') }}</label><br>{{ lang('ACP_FBC_COUNTRIES_EXPLAIN') }}</dt>
Expand All @@ -38,6 +38,11 @@ <h3>{{ lang('WARNING') }}</h3>
<dd><label><input type="radio" class="radio" name="phpbbservices_filterbycountry_allow_out_of_country_logins" value="1"{% if FBC_ALLOW_OUT_OF_COUNTRY_LOGINS %} checked="checked"{% endif %} /> {{ lang('YES') }}</label>
<label><input type="radio" class="radio" name="phpbbservices_filterbycountry_allow_out_of_country_logins" value="0"{% if not FBC_ALLOW_OUT_OF_COUNTRY_LOGINS %} checked="checked"{% endif %} /> {{ lang('NO') }}</label></dd>
</dl>
<dl>
<dt><label>{{ lang('ACP_FBC_IGNORE_BOTS') ~ lang('COLON') }}</label><br>{{ lang('ACP_FBC_IGNORE_BOTS_EXPLAIN') }}</dt>
<dd><label><input type="radio" class="radio" name="phpbbservices_filterbycountry_ignore_bots" value="1"{% if FBC_IGNORE_BOTS %} checked="checked"{% endif %} /> {{ lang('YES') }}</label>
<label><input type="radio" class="radio" name="phpbbservices_filterbycountry_ignore_bots" value="0"{% if not FBC_IGNORE_BOTS %} checked="checked"{% endif %} /> {{ lang('NO') }}</label></dd>
</dl>
<dl>
<dt><label>{{ lang('ACP_FBC_LOG_ACCESS_ERRORS') ~ lang('COLON') }}</label><br>{{ lang('ACP_FBC_LOG_ACCESS_ERRORS_EXPLAIN') }}</dt>
<dd><label><input type="radio" class="radio" name="phpbbservices_filterbycountry_log_access_errors" value="1"{% if FBC_LOG_ACCESS_ERRORS %} checked="checked"{% endif %} /> {{ lang('YES') }}</label>
Expand Down Expand Up @@ -82,7 +87,7 @@ <h2>{{ lang('ACP_FBC_CURRENT_RANGE') ~ lang('COLON') }} {{ CURRENT_RANGE }}</h2>
<tbody>
{% for country in countries %}
<tr>
<td headers="country">{% if country.S_SHOW_FLAG %}{{ country.FLAG }} {% endif %}<span>{{ country.TEXT }}</span></td><td headers="allowed" class="center">{{ country.ALLOWED }}</td><td headers="restricted" class="center">{{ country.RESTRICTED }}</td>
<td headers="country">{{ country.FLAG }} <span>{{ country.TEXT }}</span></td><td headers="allowed" class="center">{{ country.ALLOWED }}</td><td headers="restricted" class="center">{{ country.RESTRICTED }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
16 changes: 15 additions & 1 deletion adm/style/event/acp_overall_footer_after.html
Expand Up @@ -6,11 +6,17 @@
var countryCodes = "{{ COUNTRY_CODES }}";
var countryCodesArray = countryCodes.split(',');
$( document ).ready(function() {
// Mark options in the country code options selected if they were set previously
$("#phpbbservices_filterbycountry_country_codes option").each(function() {
// Mark options in the country code options selected if they were set previously
if (countryCodesArray.indexOf($(this).val()) != -1) {
$(this).prop('selected', true);
};
// If the setting is to ignore country codes, disable the select control too
if ($('input[name=phpbbservices_filterbycountry_allow]:checked', '#phpbbservices_filterbycountry_acp').val() == 2) {
$('#phpbbservices_filterbycountry_country_codes').prop('disabled', 'disabled');
} else {
$('#phpbbservices_filterbycountry_country_codes').prop('disabled', false);
}
});
// When reset button is pressed, this logic will unselect all country codes
$("#unselect_options").click(function() {
Expand All @@ -26,6 +32,14 @@
changeYear: true
});
} );
// Disable the country code options selected when the ignore setting is enabled
$('#phpbbservices_filterbycountry_acp input').on('change', function() {
if ($('input[name=phpbbservices_filterbycountry_allow]:checked', '#phpbbservices_filterbycountry_acp').val() == 2) {
$('#phpbbservices_filterbycountry_country_codes').prop('disabled', 'disabled');
} else {
$('#phpbbservices_filterbycountry_country_codes').prop('disabled', false);
}
});
</script>
{% endif %}
{% endif %}
7 changes: 4 additions & 3 deletions composer.json
Expand Up @@ -3,8 +3,8 @@
"type": "phpbb-extension",
"description": "Allows admins to control access by the country code associated with the user's IP",
"homepage": "https://www.phpbbservices.com",
"version": "1.0.6-rc",
"time": "2019-08-06",
"version": "1.0.7-rc",
"time": "2019-09-07",
"license": "GPL-2.0-only",
"authors": [
{
Expand All @@ -27,7 +27,8 @@
"version-check": {
"host": "www.phpbbservices.com",
"directory": "/other/filterbycountry/updatecheck/",
"filename": "3.2.json"
"filename": "3.2.json",
"ssl": true
}
}
}
3 changes: 2 additions & 1 deletion constants/constants.php
Expand Up @@ -12,7 +12,7 @@

class constants {

const ACP_FBC_COUNTRY_NOT_FOUND = '??';
const ACP_FBC_COUNTRY_NOT_FOUND = 'WO'; // World, so unknown
const ACP_FBC_NO_LIMIT_VALUE = 1;
const ACP_FBC_LAST_QUARTER_VALUE = 2;
const ACP_FBC_LAST_MONTH_VALUE = 3;
Expand All @@ -26,5 +26,6 @@ class constants {
const ACP_FBC_LAST_30_MINUTES_VALUE = 11;
const ACP_FBC_LAST_15_MINUTES_VALUE = 12;
const ACP_FBC_STATS_TABLE = 'fbc_stats';
const ACP_FBC_VPN_ONLY = 2;

}
31 changes: 24 additions & 7 deletions controller/acp_controller.php
Expand Up @@ -124,6 +124,10 @@ public function display_options()
$save_statistics = $this->request->variable('phpbbservices_filterbycountry_keep_statistics', 0);
$this->config->set('phpbbservices_filterbycountry_keep_statistics', $save_statistics);

// Save the ignore bots setting
$ignore_bots = $this->request->variable('phpbbservices_filterbycountry_ignore_bots', 0);
$this->config->set('phpbbservices_filterbycountry_ignore_bots', $ignore_bots);

if ($save_statistics)
{
// Set the statistics start date to the current time
Expand All @@ -148,8 +152,20 @@ public function display_options()
// Add option settings change action to the admin log
$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_ACP_FBC_FILTERBYCOUNTRY_SETTINGS');

// Option settings have been updated and logged
// Confirm this to the user and provide link back to previous page
// Allow (1), restrict (0) or ignore(2) country codes?
$allow = (int) $this->config['phpbbservices_filterbycountry_allow'];

// VPN services allowed? If an IP is not found in the database, it is assumed to be a VPN IP.
$vpn_allowed = ($this->config['phpbbservices_filterbycountry_ip_not_found_allow'] == 1) ? true : false;

if (!$vpn_allowed && ((count($country_codes) == 0) || $allow == constants::ACP_FBC_VPN_ONLY))
{
// User is always allowed in if no countries were selected by admin or the extension ignores countries AND
// the VPN feature is not wanted. Otherwise, the board is effectively disabled. We need to warn the administrator
// about this behavior.
@trigger_error($this->language->lang('ACP_FBC_EFFECTIVELY_DISABLED'). adm_back_link($this->u_action),E_USER_WARNING);
}

trigger_error($this->language->lang('ACP_FBC_SETTING_SAVED') . adm_back_link($this->u_action));
}
}
Expand All @@ -167,7 +183,7 @@ public function display_options()
// function returns false. In this case, we draw attention to the issue so the underlying problem can be fixed.
if (!$this->helper->download_maxmind())
{
trigger_error($this->language->lang('ACP_FBC_CREATE_DATABASE_ERROR'));
@trigger_error($this->language->lang('ACP_FBC_CREATE_DATABASE_ERROR'), E_USER_WARNING);
}
}

Expand All @@ -178,7 +194,8 @@ public function display_options()
'COUNTRY_CODES' => $this->config_text->get('phpbbservices_filterbycountry_country_codes'), // Processed by the Javascript
'ERROR_MSG' => $s_errors ? implode('<br />', $errors) : '',
'FBC_ALLOW_OUT_OF_COUNTRY_LOGINS' => (bool) $this->config['phpbbservices_filterbycountry_allow_out_of_country_logins'],
'FBC_ALLOW_RESTRICT' => (bool) $this->config['phpbbservices_filterbycountry_allow'],
'FBC_ALLOW_RESTRICT' => (int) $this->config['phpbbservices_filterbycountry_allow'],
'FBC_IGNORE_BOTS' => (bool) $this->config['phpbbservices_filterbycountry_ignore_bots'],
'FBC_IP_NOT_FOUND_ALLOW_RESTRICT' => (bool) $this->config['phpbbservices_filterbycountry_ip_not_found_allow'],
'FBC_KEEP_STATISTICS' => (bool) $this->config['phpbbservices_filterbycountry_keep_statistics'],
'FBC_LOG_ACCESS_ERRORS' => (bool) $this->config['phpbbservices_filterbycountry_log_access_errors'],
Expand Down Expand Up @@ -296,6 +313,7 @@ public function display_options()

if (count($distinct_countries) > 0)
{

// To present a report by country, we need to put the information in tabular form. Since country names
// could vary based on language, it's not viable to put them in a database (otherwise we'd have a ready
// option available for sorting). So we'll parse the language string ACP_FBC_OPTIONS for country codes and
Expand Down Expand Up @@ -325,9 +343,9 @@ public function display_options()
$rowset = $this->db->sql_fetchrowset($result);

// Add to $rowset a column representing the textual country name, in the user's language
foreach ($rowset as $row)
for ($i=0; $i < count($rowset); $i++)
{
$row['country_name'] = $countries[$row['country_code']];
$rowset[$i]['country_name'] = $countries[$rowset[$i]['country_code']];
}

// The $rowset array must be ordered outside of SQL because the country name is localized and is not stored in the database
Expand Down Expand Up @@ -378,7 +396,6 @@ public function display_options()
'ALLOWED' => $allowed_count,
'FLAG' => '<img src="' . $flag_path. '" alt="' . $countries[$row['country_code']]. '" title="' . $countries[$row['country_code']]. '">',
'RESTRICTED' => $not_allowed_count,
'S_SHOW_FLAG' => (file_exists($flag_path)) ? true : false,
'TEXT' => $countries[$row['country_code']],
));

Expand Down

0 comments on commit 31994d0

Please sign in to comment.