From a9ebb89daaeb4e36e01577f5fc86dcd7411e8070 Mon Sep 17 00:00:00 2001 From: cypherbits Date: Mon, 27 May 2019 10:21:47 +0200 Subject: [PATCH] init --- acp/main_info.php | 37 ++++ acp/main_module.php | 70 +++++++ adm/style/acp_onionbb_checks.html | 38 ++++ adm/style/acp_onionbb_settings.html | 49 +++++ composer.json | 27 +++ config/parameters.yml | 2 + config/routing.yml | 3 + config/services.yml | 37 ++++ controller/acp_controller.php | 151 +++++++++++++++ controller/main_controller.php | 56 ++++++ event/main_listener.php | 138 +++++++++++++ ext.php | 21 ++ language/en/common.php | 50 +++++ language/en/info_acp_onionbb.php | 43 ++++ license.txt | 280 +++++++++++++++++++++++++++ migrations/install_acp_module.php | 62 ++++++ migrations/install_sample_data.php | 107 ++++++++++ migrations/install_sample_schema.php | 77 ++++++++ service.php | 46 +++++ 19 files changed, 1294 insertions(+) create mode 100644 acp/main_info.php create mode 100644 acp/main_module.php create mode 100644 adm/style/acp_onionbb_checks.html create mode 100644 adm/style/acp_onionbb_settings.html create mode 100644 composer.json create mode 100644 config/parameters.yml create mode 100644 config/routing.yml create mode 100644 config/services.yml create mode 100644 controller/acp_controller.php create mode 100644 controller/main_controller.php create mode 100644 event/main_listener.php create mode 100644 ext.php create mode 100644 language/en/common.php create mode 100644 language/en/info_acp_onionbb.php create mode 100644 license.txt create mode 100644 migrations/install_acp_module.php create mode 100644 migrations/install_sample_data.php create mode 100644 migrations/install_sample_schema.php create mode 100644 service.php diff --git a/acp/main_info.php b/acp/main_info.php new file mode 100644 index 0000000..950a06d --- /dev/null +++ b/acp/main_info.php @@ -0,0 +1,37 @@ + '\cypherbits\onionbb\acp\main_module', + 'title' => 'ACP_ONIONBB_TITLE', + 'modes' => array( + 'settings' => array( + 'title' => 'ACP_ONIONBB', + 'auth' => 'ext_cypherbits/onionbb && acl_a_board', + 'cat' => array('ACP_ONIONBB_TITLE') + ), + 'checks' => array( + 'title' => 'ACP_ONIONBB_CHECKS', + 'auth' => 'ext_cypherbits/onionbb && acl_a_board', + 'cat' => array('ACP_ONIONBB_TITLE') + ), + ), + ); + } +} diff --git a/acp/main_module.php b/acp/main_module.php new file mode 100644 index 0000000..fcd404a --- /dev/null +++ b/acp/main_module.php @@ -0,0 +1,70 @@ +get('cypherbits.onionbb.controller.acp'); + + /** @var \phpbb\language\language $language */ + $language = $phpbb_container->get('language'); + + switch($mode){ + case "settings": + // Load a template from adm/style for our ACP page + $this->tpl_name = 'acp_onionbb_settings'; + + // Set the page title for our ACP page + $this->page_title = $language->lang('ACP_ONIONBB_TITLE'); + + // Make the $u_action url available in our ACP controller + $acp_controller->set_page_url($this->u_action); + + // Load the display options handle in our ACP controller + $acp_controller->display_settings(); + break; + case "checks": + // Load a template from adm/style for our ACP page + $this->tpl_name = 'acp_onionbb_checks'; + + // Set the page title for our ACP page + $this->page_title = $language->lang('ACP_ONIONBB_TITLE'); + + // Make the $u_action url available in our ACP controller + $acp_controller->set_page_url($this->u_action); + + // Load the display options handle in our ACP controller + $acp_controller->display_checks(); + break; + } + + + } +} diff --git a/adm/style/acp_onionbb_checks.html b/adm/style/acp_onionbb_checks.html new file mode 100644 index 0000000..8078787 --- /dev/null +++ b/adm/style/acp_onionbb_checks.html @@ -0,0 +1,38 @@ +{% include 'overall_header.html' %} + +

{{ lang('ACP_ONIONBB_TITLE') }}

+ +{% if S_ERROR %} +
+

{{ lang('WARNING') }}

+

{{ ERROR_MSG }}

+
+{% endif %} + + + + ++ + + + + + + + + + + + + + + + + + + + +
Hardening checks
SettingCurrent valueRecommended
Min password lenght: {{ CYPHERBITS_ONIONBB_CHECK_PASSWORDLENGHT }}10
Min username lenght: {{ CYPHERBITS_ONIONBB_CHECK_USERNAMELENGHT }}8
+ +{% include 'overall_footer.html' %} diff --git a/adm/style/acp_onionbb_settings.html b/adm/style/acp_onionbb_settings.html new file mode 100644 index 0000000..3eb604c --- /dev/null +++ b/adm/style/acp_onionbb_settings.html @@ -0,0 +1,49 @@ +{% include 'overall_header.html' %} + +

{{ lang('ACP_ONIONBB_TITLE') }}

+ +{% if S_ERROR %} +
+

{{ lang('WARNING') }}

+

{{ ERROR_MSG }}

+
+{% endif %} + +
+ +
+ {{ lang('SETTINGS') }} +
+
+
INFO: current IP is {{ CURRENT_IP }}
+
+
+
+
+

+ +
+
+
+
+
INFO: current Host header is {{ CURRENT_HOST }}
+
+
+
+
+
INFO: current User-Agent is {{ HTTP_USER_AGENT }}
+ +
+
+ +
+ +
+ + + {{ S_FORM_TOKEN }} +
+ +
+ + {% include 'overall_footer.html' %} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..8d4a902 --- /dev/null +++ b/composer.json @@ -0,0 +1,27 @@ +{ + "name": "cypherbits/onionbb", + "type": "phpbb-extension", + "description": "Help phpBB on Tor Hidden Services prevent attacks", + "homepage": "", + "version": "1.0.0-dev", + "time": "2019-05-22", + "license": "GPL-2.0-only", + "authors": [ + { + "name": "cypherbits", + "email": "", + "homepage": "", + "role": "" + } + ], + "require": { + "php": ">=7.3", + "composer/installers": "~1.0" + }, + "extra": { + "display-name": "Onionbb: Tor hardening", + "soft-require": { + "phpbb/phpbb": ">=3.2.0,<3.3.0@dev" + } + } +} diff --git a/config/parameters.yml b/config/parameters.yml new file mode 100644 index 0000000..829d538 --- /dev/null +++ b/config/parameters.yml @@ -0,0 +1,2 @@ +parameters: + cypherbits.onionbb.tables.onionbb_table: '%core.table_prefix%cypherbits_onionbb_table' diff --git a/config/routing.yml b/config/routing.yml new file mode 100644 index 0000000..b04fef9 --- /dev/null +++ b/config/routing.yml @@ -0,0 +1,3 @@ +cypherbits_onionbb_controller: + path: /demo/{name} + defaults: { _controller: cypherbits.onionbb.controller.main:handle } diff --git a/config/services.yml b/config/services.yml new file mode 100644 index 0000000..163f275 --- /dev/null +++ b/config/services.yml @@ -0,0 +1,37 @@ +imports: + - { resource: parameters.yml } + +services: + cypherbits.onionbb.controller.main: + class: cypherbits\onionbb\controller\main_controller + arguments: + - '@config' + - '@controller.helper' + - '@template' + - '@language' + + cypherbits.onionbb.controller.acp: + class: cypherbits\onionbb\controller\acp_controller + arguments: + - '@config' + - '@language' + - '@log' + - '@request' + - '@template' + - '@user' + + cypherbits.onionbb.service: + class: cypherbits\onionbb\service + arguments: + - '@user' + - '%cypherbits.onionbb.tables.onionbb_table%' + + cypherbits.onionbb.listener: + class: cypherbits\onionbb\event\main_listener + arguments: + - '@language' + - '@controller.helper' + - '@template' + - '%core.php_ext%' + tags: + - { name: event.listener } diff --git a/controller/acp_controller.php b/controller/acp_controller.php new file mode 100644 index 0000000..98d0889 --- /dev/null +++ b/controller/acp_controller.php @@ -0,0 +1,151 @@ +config = $config; + $this->language = $language; + $this->log = $log; + $this->request = $request; + $this->template = $template; + $this->user = $user; + } + + /** + * Display the options a user can configure for this extension. + * + * @return void + */ + public function display_settings() + { + // Add our common language file + $this->language->add_lang('common', 'cypherbits/onionbb'); + + // Create a form key for preventing CSRF attacks + add_form_key('cypherbits_onionbb_acp'); + + // Create an array to collect errors that will be output to the user + $errors = array(); + + // Is the form being submitted to us? + if ($this->request->is_set_post('submit')) + { + // Test if the submitted form is valid + if (!check_form_key('cypherbits_onionbb_acp')) + { + $errors[] = $this->language->lang('FORM_INVALID'); + } + + // If no errors, process the form data + if (empty($errors)) + { + // Set the options the user configured + $this->config->set('cypherbits_onionbb_checkIP', $this->request->variable('cypherbits_onionbb_checkIP', 0)); + $this->config->set('cypherbits_onionbb_checkIP_list', $this->request->variable('cypherbits_onionbb_checkIP_list', "")); + $this->config->set('cypherbits_onionbb_blockTor2Web', $this->request->variable('cypherbits_onionbb_blockTor2Web', 0)); + $this->config->set('cypherbits_onionbb_blockTor2Web_DNT', $this->request->variable('cypherbits_onionbb_blockTor2Web_DNT', 0)); + $this->config->set('cypherbits_onionbb_host', $this->request->variable('cypherbits_onionbb_host', 0)); + $this->config->set('cypherbits_onionbb_host_list', $this->request->variable('cypherbits_onionbb_host_list', "")); + $this->config->set('cypherbits_onionbb_userAgents', $this->request->variable('cypherbits_onionbb_userAgents', 0)); + $this->config->set('cypherbits_onionbb_userAgentsTB8', $this->request->variable('cypherbits_onionbb_userAgentsTB8', 0)); + + // Add option settings change action to the admin log + $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_ACP_ONIONBB_SETTINGS'); + + // Option settings have been updated and logged + // Confirm this to the user and provide link back to previous page + trigger_error($this->language->lang('ACP_ONIONBB_SETTING_SAVED') . adm_back_link($this->u_action)); + } + } + + $s_errors = !empty($errors); + + // Set output variables for display in the template + $this->template->assign_vars(array( + 'S_ERROR' => $s_errors, + 'ERROR_MSG' => $s_errors ? implode('
', $errors) : '', + + 'U_ACTION' => $this->u_action, + + strtoupper('current_ip') => (string) $this->request->server('REMOTE_ADDR','empty?'), + strtoupper('current_host') => (string) $this->request->server('HTTP_HOST','empty?'), + strtoupper('http_user_agent') => (string) $this->request->server('HTTP_USER_AGENT','empty?'), + strtoupper('cypherbits_onionbb_checkIP') => (bool) $this->config['cypherbits_onionbb_checkIP'], + strtoupper('cypherbits_onionbb_checkIP_list') => (string) $this->config['cypherbits_onionbb_checkIP_list'], + strtoupper('cypherbits_onionbb_blockTor2Web') => (bool) $this->config['cypherbits_onionbb_blockTor2Web'], + strtoupper('cypherbits_onionbb_blockTor2Web_DNT') => (bool) $this->config['cypherbits_onionbb_blockTor2Web_DNT'], + strtoupper('cypherbits_onionbb_host') => (bool) $this->config['cypherbits_onionbb_host'], + strtoupper('cypherbits_onionbb_host_list') => (string) $this->config['cypherbits_onionbb_host_list'], + strtoupper('cypherbits_onionbb_userAgents') => (bool) $this->config['cypherbits_onionbb_userAgents'], + strtoupper('cypherbits_onionbb_userAgentsTB8') => (bool) $this->config['cypherbits_onionbb_userAgentsTB8'], + )); + } + + public function display_checks(){ + $this->template->assign_vars(array( + 'S_ERROR' => $s_errors, + 'ERROR_MSG' => $s_errors ? implode('
', $errors) : '', + + 'U_ACTION' => $this->u_action, + + 'CYPHERBITS_ONIONBB_CHECK_PASSWORDLENGHT' => (int) $this->config['min_pass_chars'], + 'CYPHERBITS_ONIONBB_CHECK_USERNAMELENGHT' => (int) $this->config['min_name_chars'], + )); + } + + /** + * Set custom form action. + * + * @param string $u_action Custom form action + * @return void + */ + public function set_page_url($u_action) + { + $this->u_action = $u_action; + } +} diff --git a/controller/main_controller.php b/controller/main_controller.php new file mode 100644 index 0000000..3be031a --- /dev/null +++ b/controller/main_controller.php @@ -0,0 +1,56 @@ +config = $config; + $this->helper = $helper; + $this->template = $template; + $this->language = $language; + } + + /** + * Controller handler for route /demo/{name} + * + * @param string $name + * + * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object + */ + public function handle($name) + { + } +} diff --git a/event/main_listener.php b/event/main_listener.php new file mode 100644 index 0000000..ff8219c --- /dev/null +++ b/event/main_listener.php @@ -0,0 +1,138 @@ + 'onionbb_load', + ); + } + + /* @var \phpbb\language\language */ + protected $language; + + /* @var \phpbb\controller\helper */ + protected $helper; + + /* @var \phpbb\template\template */ + protected $template; + + /** @var string phpEx */ + protected $php_ext; + + /** + * Constructor + * + * @param \phpbb\language\language $language Language object + * @param \phpbb\controller\helper $helper Controller helper object + * @param \phpbb\template\template $template Template object + * @param string $php_ext phpEx + */ + public function __construct(\phpbb\language\language $language, \phpbb\controller\helper $helper, \phpbb\template\template $template, $php_ext) + { + $this->language = $language; + $this->helper = $helper; + $this->template = $template; + $this->php_ext = $php_ext; + } + + /** + * + * @param \phpbb\event\data $event Event object + */ + public function onionbb_load($event){ + + global $config; + global $request; + + $tor2web = "X-Tor2web"; + $tor2web = strtoupper($tor2web); + $tor2web = str_replace("-", "_",$tor2web); + + $checkIP = (bool) $config['cypherbits_onionbb_checkIP']; + $checkIPList = explode(',',(string)$config['cypherbits_onionbb_checkIP_list']); + $checkTor2Web = (bool) $config['cypherbits_onionbb_blockTor2Web']; + $checkTor2WebDNT = (bool) $config['cypherbits_onionbb_blockTor2Web_DNT']; + $checkHostHeader = (bool) $config['cypherbits_onionbb_host']; + $checkHostHeaderList = explode(',',(string) $config['cypherbits_onionbb_host_list']); + $checkUserAgents = (bool) $config['cypherbits_onionbb_userAgents']; + $checkUserAgentsTB8 = (bool) $config['cypherbits_onionbb_userAgentsTB8']; + + $currentIP = $request->server('REMOTE_ADDR',''); + $currentTor2Web = $request->server('HTTP_'.$tor2web,''); + $currentTor2WebDNT = $request->server('HTTP_DNT',''); + $currentHostHeader = $request->server('HTTP_HOST',''); + $currentUserAgent = $request->server('HTTP_USER_AGENT',''); + + if ($checkIP){ + if (!in_array($currentIP, $checkIPList, true)){ + http_response_code(403); + die('Forbidden'); + } + } + + + if ($checkTor2Web){ + + if ($currentTor2Web !== ""){ + http_response_code(403); + die('Forbidden'); + } + + if ($checkTor2WebDNT && $currentTor2WebDNT !== ""){ + http_response_code(403); + die('Forbidden'); + } + } + + if ($checkHostHeader){ + if (!in_array($currentHostHeader, $checkHostHeaderList, true)){ + http_response_code(403); + die('Forbidden'); + } + } + + if($checkUserAgents){ + if ($checkUserAgentsTB8){ + $useragentok = [ + "Mozilla/5.0 (Windows NT 6.1; rv:60.0) Gecko/20100101 Firefox/60.0", + "Mozilla/5.0 (Android 6.0; Mobile; rv:60.0) Gecko/20100101 Firefox/60.0", + "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0" + ]; + + if (!in_array($currentUserAgent, $useragentok, true)){ + http_response_code(403); + die('Forbidden'); + } + }else{ + //TODO: check with regex. + if (strpos($currentUserAgent, "Mozilla/5.0") !== 0){ + http_response_code(403); + die('Forbidden'); + } + } + } + + } + +} diff --git a/ext.php b/ext.php new file mode 100644 index 0000000..d4fe93d --- /dev/null +++ b/ext.php @@ -0,0 +1,21 @@ + 'Hello %s!', + 'ONIONBB_GOODBYE' => 'Goodbye %s!', + + 'ONIONBB_EVENT' => ' :: Onionbb Event :: ', + + 'ACP_ONIONBB_GOODBYE' => 'Should say goodbye?', + 'ACP_ONIONBB_SETTING_SAVED' => 'Settings have been saved successfully!', + + 'ONIONBB_PAGE' => 'Onionbb Page', + 'VIEWING_CYPHERBITS_ONIONBB' => 'Viewing Onionbb: Tor hardening page', + +)); diff --git a/language/en/info_acp_onionbb.php b/language/en/info_acp_onionbb.php new file mode 100644 index 0000000..e0b2372 --- /dev/null +++ b/language/en/info_acp_onionbb.php @@ -0,0 +1,43 @@ + 'Onionbb: Tor hardening Module', + 'ACP_ONIONBB' => 'OnionBB settings', +'ACP_ONIONBB_CHECKS' => 'Hardening checks', + + 'LOG_ACP_ONIONBB_SETTINGS' => 'Onionbb: Tor hardening settings updated', +)); diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..b9f6fc2 --- /dev/null +++ b/license.txt @@ -0,0 +1,280 @@ +GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 675 Mass Ave, Cambridge, MA 02139, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS diff --git a/migrations/install_acp_module.php b/migrations/install_acp_module.php new file mode 100644 index 0000000..2ae6ac9 --- /dev/null +++ b/migrations/install_acp_module.php @@ -0,0 +1,62 @@ +config['cypherbits_onionbb_installed']); + } + + public static function depends_on() + { + return array('\phpbb\db\migration\data\v320\v320'); + } + + public function update_data() + { +global $request; + $currentIP = $request->server('REMOTE_ADDR',''); + + $currentHost = $request->server('HTTP_HOST',''); + + return array( + array('config.add', array('cypherbits_onionbb_installed', 1)), + + array('config.add', array('cypherbits_onionbb_checkIP', 1)), + array('config.add', array('cypherbits_onionbb_checkIP_list', '127.0.0.1,'.$currentIP)), + + array('config.add', array('cypherbits_onionbb_blockTor2Web', 1)), + array('config.add', array('cypherbits_onionbb_blockTor2Web_DNT', 0)), + + array('config.add', array('cypherbits_onionbb_host', 1)), + array('config.add', array('cypherbits_onionbb_host_list', $currentHost)), + + array('config.add', array('cypherbits_onionbb_userAgents', 1)), + array('config.add', array('cypherbits_onionbb_userAgentsTB8', 0)), + + array('module.add', array( + 'acp', + 'ACP_CAT_DOT_MODS', + 'ACP_ONIONBB_TITLE' + )), + array('module.add', array( + 'acp', + 'ACP_ONIONBB_TITLE', + array( + 'module_basename' => '\cypherbits\onionbb\acp\main_module', + 'modes' => array('settings', 'checks'), + ), + )), + ); + } +} diff --git a/migrations/install_sample_data.php b/migrations/install_sample_data.php new file mode 100644 index 0000000..9e852b4 --- /dev/null +++ b/migrations/install_sample_data.php @@ -0,0 +1,107 @@ +config->offsetExists('cypherbits_onionbb_sample_int'); + } + + public static function depends_on() + { + return array('\phpbb\db\migration\data\v320\v320'); + } + + /** + * Add, update or delete data stored in the database during extension installation. + * + * https://area51.phpbb.com/docs/dev/3.2.x/migrations/data_changes.html + * config.add: Add config data. + * config.update: Update config data. + * config.remove: Remove config. + * config_text.add: Add config_text data. + * config_text.update: Update config_text data. + * config_text.remove: Remove config_text. + * module.add: Add a new CP module. + * module.remove: Remove a CP module. + * permission.add: Add a new permission. + * permission.remove: Remove a permission. + * permission.role_add: Add a new permission role. + * permission.role_update: Update a permission role. + * permission.role_remove: Remove a permission role. + * permission.permission_set: Set a permission to Yes or Never. + * permission.permission_unset: Set a permission to No. + * custom: Run a callable function to perform more complex operations. + * + * @return array Array of data update instructions + */ + public function update_data() + { + return array( + + ); + } + + /** + * Add, update or delete data stored in the database during extension un-installation (purge step). + * + * IMPORTANT: Under normal circumstances, the changes performed in update_data will + * automatically be reverted during un-installation. This revert_data method is optional + * and only needs to be used to perform custom un-installation changes, such as to revert + * changes made by custom functions called in update_data. + * + * https://area51.phpbb.com/docs/dev/3.2.x/migrations/data_changes.html + * config.add: Add config data. + * config.update: Update config data. + * config.remove: Remove config. + * config_text.add: Add config_text data. + * config_text.update: Update config_text data. + * config_text.remove: Remove config_text. + * module.add: Add a new CP module. + * module.remove: Remove a CP module. + * permission.add: Add a new permission. + * permission.remove: Remove a permission. + * permission.role_add: Add a new permission role. + * permission.role_update: Update a permission role. + * permission.role_remove: Remove a permission role. + * permission.permission_set: Set a permission to Yes or Never. + * permission.permission_unset: Set a permission to No. + * custom: Run a callable function to perform more complex operations. + * + * @return array Array of data update instructions + */ + public function revert_data() + { + return array( + array('custom', array(array($this, 'sample_callable_uninstall'))), + ); + } + + /** + * A custom function for making more complex database changes + * during extension installation. Must be declared as public. + */ + public function sample_callable_install() + { + // Run some SQL queries on the database + } + + /** + * A custom function for making more complex database changes + * during extension un-installation. Must be declared as public. + */ + public function sample_callable_uninstall() + { + // Run some SQL queries on the database + } +} diff --git a/migrations/install_sample_schema.php b/migrations/install_sample_schema.php new file mode 100644 index 0000000..6a0370c --- /dev/null +++ b/migrations/install_sample_schema.php @@ -0,0 +1,77 @@ +db_tools->sql_column_exists($this->table_prefix . 'users', 'user_onionbb'); + } + + public static function depends_on() + { + return array('\phpbb\db\migration\data\v320\v320'); + } + + /** + * Update database schema. + * + * https://area51.phpbb.com/docs/dev/3.2.x/migrations/schema_changes.html + * add_tables: Add tables + * drop_tables: Drop tables + * add_columns: Add columns to a table + * drop_columns: Removing/Dropping columns + * change_columns: Column changes (only type, not name) + * add_primary_keys: adding primary keys + * add_unique_index: adding an unique index + * add_index: adding an index (can be column:index_size if you need to provide size) + * drop_keys: Dropping keys + * + * This sample migration adds a new column to the users table. + * It also adds an example of a new table that can hold new data. + * + * @return array Array of schema changes + */ + public function update_schema() + { + return array( + + ); + } + + /** + * Revert database schema changes. This method is almost always required + * to revert the changes made above by update_schema. + * + * https://area51.phpbb.com/docs/dev/3.2.x/migrations/schema_changes.html + * add_tables: Add tables + * drop_tables: Drop tables + * add_columns: Add columns to a table + * drop_columns: Removing/Dropping columns + * change_columns: Column changes (only type, not name) + * add_primary_keys: adding primary keys + * add_unique_index: adding an unique index + * add_index: adding an index (can be column:index_size if you need to provide size) + * drop_keys: Dropping keys + * + * This sample migration removes the column that was added the users table in update_schema. + * It also removes the table that was added in update_schema. + * + * @return array Array of schema changes + */ + public function revert_schema() + { + return array( + + ); + } +} diff --git a/service.php b/service.php new file mode 100644 index 0000000..c9e4e15 --- /dev/null +++ b/service.php @@ -0,0 +1,46 @@ +user = $user; + $this->table_name = $table_name; + } + + /** + * Get user object + * + * @return \phpbb\user $user User object + */ + public function get_user() + { + var_dump($this->table_name); + return $this->user; + } +}