First commit

This commit is contained in:
ebassi -
commit e3597abe8e
35 changed files with 2401 additions and 0 deletions

108
migrations/release_1_0_0.php Executable file
View file

@ -0,0 +1,108 @@
<?php
namespace pedodev\linkprotection\migrations;
class release_1_0_0 extends \phpbb\db\migration\migration
{
public function effectively_installed()
{
return isset($this->config['pedodev_linkprotection']);
}
static public function depends_on()
{
return ['\phpbb\db\migration\data\v330\v330'];
}
public function update_data()
{
// openssl_cipher_key_length requires PHP >= 8.2
if (function_exists('openssl_cipher_key_length'))
{
$key_length = openssl_cipher_key_length('aes-128-cbc');
}
else
{
$key_length = 16;
}
$random_key = base64_encode(random_bytes($key_length));
return [
// A simple config variable so we know the migration is already completed
['config.add', ['pedodev_linkprotection', 1]],
/* Add the ACP modules */
['module.add', [
'acp',
'ACP_CAT_DOT_MODS',
'ACP_LINKPROTECTION_TITLE'
]],
['module.add', [
'acp',
'ACP_LINKPROTECTION_TITLE',
[
'module_basename' => '\pedodev\linkprotection\acp\link_replacement_module',
'modes' => ['settings'],
],
]],
['module.add', [
'acp',
'ACP_LINKPROTECTION_TITLE',
[
'module_basename' => '\pedodev\linkprotection\acp\protected_page_module',
'modes' => ['settings'],
],
]],
/* Add our configuration variables (with sane defaults) */
// Link replacement
['config.add', ['pedodev_linkprotection_maxlinks', 100]],
['config.add', ['pedodev_linkprotection_key', $random_key]],
['config.add', ['pedodev_linkprotection_cipher', 'aes-128-cbc']],
['config.add', ['pedodev_linkprotection_manualenabled', 1]],
['config.add', ['pedodev_linkprotection_manualtitle', 'Protected']],
['config.add', ['pedodev_linkprotection_strictmanual', 0]],
['config.add', ['pedodev_linkprotection_manuallength', 255]],
['config.add', ['pedodev_linkprotection_manualtags', 'dl,download']],
['config.add', ['pedodev_linkprotection_automaticenabled', 1]],
['config.add', ['pedodev_linkprotection_automaticlength', 255]],
['config.add', ['pedodev_linkprotection_automaticlinks', '{"1fichier.com":"1fichier"}']],
// Protected link page
['config.add', ['pedodev_linkprotection_protectedprefix', 'protected']],
['config.add', ['pedodev_linkprotection_captcha', 'core.captcha.plugins.nogd']],
['config.add', ['pedodev_linkprotection_solvetime', 60]],
['config.add', ['pedodev_linkprotection_showsubmit', 1]],
['config.add', ['pedodev_linkprotection_multiplelinks', 1]],
['config.add', ['pedodev_linkprotection_solveduration', 120]],
['config.add', ['pedodev_linkprotection_grouplinks', '']],
/* Configure our permissions and setup sane defaults for roles*/
['permission.add', ['u_pedodev_linkprotection_canprotectlinks']],
['permission.permission_set', ['ROLE_USER_LIMITED', 'u_pedodev_linkprotection_canprotectlinks']],
['permission.permission_set', ['ROLE_USER_STANDARD', 'u_pedodev_linkprotection_canprotectlinks']],
['permission.permission_set', ['ROLE_USER_FULL', 'u_pedodev_linkprotection_canprotectlinks']],
['permission.add', ['u_pedodev_linkprotection_canviewlinks']],
['permission.permission_set', ['ROLE_USER_LIMITED', 'u_pedodev_linkprotection_canviewlinks']],
['permission.permission_set', ['ROLE_USER_STANDARD', 'u_pedodev_linkprotection_canviewlinks']],
['permission.permission_set', ['ROLE_USER_FULL', 'u_pedodev_linkprotection_canviewlinks']],
['permission.add', ['m_pedodev_linkprotection_canbypasscaptcha']],
['permission.permission_set', ['ROLE_MOD_STANDARD', 'm_pedodev_linkprotection_canbypasscaptcha']],
['permission.permission_set', ['ROLE_MOD_FULL', 'm_pedodev_linkprotection_canbypasscaptcha']],
['permission.add', ['m_pedodev_linkprotection_vieworiginallinks']],
['permission.permission_set', ['ROLE_MOD_STANDARD', 'm_pedodev_linkprotection_vieworiginallinks']],
['permission.permission_set', ['ROLE_MOD_FULL', 'm_pedodev_linkprotection_vieworiginallinks']],
];
}
}

40
migrations/release_1_1_0.php Executable file
View file

@ -0,0 +1,40 @@
<?php
namespace pedodev\linkprotection\migrations;
class release_1_1_0 extends \phpbb\db\migration\migration
{
public function effectively_installed()
{
return isset($this->config['pedodev_linkprotection_fileprefix']);
}
static public function depends_on()
{
return ['\phpbb\db\migration\data\v330\v330'];
}
public function update_data()
{
$file_prefix = bin2hex(random_bytes(8));
return [
// The prefix we will add to our automatic links JSON file
['config.add', ['pedodev_linkprotection_fileprefix', $file_prefix]],
];
}
public function revert_data()
{
$filepath = __DIR__ . "/../automatic_links_{$this->config['pedodev_linkprotection_fileprefix']}.json";
if (file_exists($filepath))
{
unlink($filepath);
}
return [];
}
}