CI 3 to CI 4 Encryption Compability - codeigniter-4

I have 1 app for SSO, use CI 3. Now i am creating new app with CI 4.
code in CI 3 for encryption :
$otp = 123;
$this->encryption->initialize(array(
'cipher' => 'aes-256',
'mode' => 'ctr',
'key' => '12345678901234567890123456789012'
));
echo $this->encryption->encrypt($otp);
//result 54322c75199be967a78c4d65906dd1d6a41c54027ddb2ff1a295c5646728f435cf4c3b5e793b57b6a6ecef34de7b7c1ed809632adeb02c5fabdf5f76befe4440PFRX6XAktE/jZXJKjL8fhCcqQw==
code in CI 4 for decryption :
$otp = '54322c75199be967a78c4d65906dd1d6a41c54027ddb2ff1a295c5646728f435cf4c3b5e793b57b6a6ecef34de7b7c1ed809632adeb02c5fabdf5f76befe4440PFRX6XAktE/jZXJKjL8fhCcqQw==';
$config = new \Config\Encryption();
$config->key = '12345678901234567890123456789012';
$config->driver = 'OpenSSL';
$encrypter = \Config\Services::encrypter($config);
echo $encrypter->decrypt($otp);
//result CodeIgniter\Encryption\Exceptions\EncryptionException Decrypting: authentication failed.
i have try with different option :
$config = new \Config\Encryption();
$config->key = '12345678901234567890123456789012';
$config->driver = 'OpenSSL';
$config->digest = 'sha256' or 'sha512';
Still getting message authentication failed. but in this documentation states that my CI 3 configuration it same with CI 4 even with default.

Since no one seem interesting to the subject. i have figure it out hot to resolve this problem.
so. what i am doing is. take / copy Codeigniter 3 encryption class from system/libraries/Encryption.php and make it third party Library in Codeigniter 4 and put it in app/libraries/Ci3encrypt.php (i rename it to this because i'm afraid the class name be the same with ci4 class)
<?php
namespace App\Libraries;
class Ci3encrypt
{
//and the rest is still the same
to call new class. in CI4 on the controller i put
namespace App\Controllers;
use App\Libraries\Ci3encrypt;
and on the function in controller ci4
$ci3 = new Ci3encrypt();
$ci3->initialize(array(
'cipher' => 'aes-256',
'mode' => 'ctr',
'driver' => 'openssl',
'key' => '12345678901234567890123456789012'
));
$plain_text=$ci3->decrypt($ciphertext);
and my problem is resolve. finally
for more information visit :
https://github.com/codeigniter4/CodeIgniter4/pull/6277
https://forum.codeigniter.com/showthread.php?tid=82494

Related

Codeigniter 4: authfilter filter must have a matching alias defined

I'm new to Codeigniter 4.
I'm developing something localy (Win10/XAMPP) and everything works fine. I uploaded code to linux hosting and suddenly I got error: authfilter filter must have a matching alias defined. 'authfilter' was an allias name in Config/Filters file. Than I noticed that allias is lowercased filter class name, so I changed allias to authfil and now I am getting error: Class 'App\Filters\AuthFilter' not found (SYSTEMPATH/Filters/Filters.php at line 167).
Can anyone explain to me what makes the difference; same code, Windows vs. Linux.
My App/Config/Filters contains following code:
namespace Config;
use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Filters\CSRF;
use CodeIgniter\Filters\DebugToolbar;
use CodeIgniter\Filters\Honeypot;
use CodeIgniter\Filters\InvalidChars;
use CodeIgniter\Filters\SecureHeaders;
use App\Filters\FilterInterface;
use App\Filters\AuthFilter;
class Filters extends BaseConfig
{
/**
* Configures aliases for Filter classes to
* make reading things nicer and simpler.
*
* #var array
*/
public $aliases = [
'csrf' => CSRF::class,
'toolbar' => DebugToolbar::class,
'honeypot' => Honeypot::class,
'invalidchars' => InvalidChars::class,
'secureheaders' => SecureHeaders::class,
'authfil' => \App\Filters\AuthFilter::class,
];
/**
* List of filter aliases that are always
* applied before and after every request.
*
* #var array
*/
public $globals = [
'before' => [
// 'honeypot',
// 'csrf',
// 'invalidchars',
'authfil' ///=> ['except' => 'auth/login']
],
'after' => [
'toolbar',
// 'honeypot',
// 'secureheaders',
],
];
My routes looks like:
$routes->group('auth', ['filter' => 'authfil'],['namespace' => 'IonAuth\Controllers'], function ($routes) {
$routes->get('/', 'Auth::index');
$routes->add('login', 'Auth::login');
$routes->get('logout', 'Auth::logout');
...
}
Thanx in advance,
Siniša
P.S. I put: use App\Filters\AuthFilter to SYSTEMPATH/Filters/Filters.php but with no success. I also tried to add filter to the route, and all combinations that I can think of before I post the question.
The fact is, my project is quite large and today, after few months of working, I find out that I should use filters for login check instead of put login check inside initController function... InitController function is a strange approach to me, instead of using standard OOP concepts (constructors). However, there is a reason for everything, even if it's not obvious to me :).

Automapper walking down relationships

I'm still trying to wrap my head around how automapper works. I have the EF Core query below, which I'd like to change to using automapper.
var query = from t in Context.Tririga.AsNoTracking()
let l = t.Building
let m = t.Owner
let o = m.Organization
where o.Active
select new MetricBadLabManagerByOrganizationDTO {
CampusName = l.CampusName,
Email = m.Email,
Name = m.Name,
OrgLevel3 = o.ThreeName,
OrgLevel4 = o.FourName,
OrgLevel5 = o.FiveName,
OrgLevel6 = o.SixName,
OrgLevel7 = o.SevenName,
Reason = m.Active == false ? "Inactive Employee" : "Invalid Employee",
SiteName = l.SiteName,
Wwid = m.Wwid
};
return await query.ToArrayAsync();
I'm not sure how to setup a mapper configuration to the DTO type because I can't just go from Tririga to MetricBadLabManagerByOrganizationDTO as it doesn't know how to go down the relationships.
Here is the Getting Started Guide from AutoMapper if you haven't gone through the documentation.
I've recently got a chance to work on a project that uses AutoMapper to translate between persistence models and domain models, and here would be how I set things up:
There are many ways to configure your mappings. I like the Profile Instances method:
using AutoMapper;
namespace Company.Product.Infrastructure.Mapping.AutoMapper
{
public class MappingProfile : Profile
{
public MappingProfile()
{
CreateMap<Tririga, MetricBadLabManagerByOrganizationDTO>()
.ForMember(dest => dest.CampusName,
opts => opts.MapFrom(src => src.Building.CampusName))
.ForMember(dest => dest.Email,
opts => opts.MapFrom(src => src.Owner.Email))
.ForMember(dest => dest.Name,
opts => opts.MapFrom(src => src.Owner.Name))
...
}
}
}
There is a whole section about flattening on AutoMapper documentation.
Just a note,
When you configure a source/destination type pair in AutoMapper, the configurator attempts to match properties and methods on the source type to properties on the destination type. If for any property on the destination type a property, method, or a method prefixed with “Get” does not exist on the source type, AutoMapper splits the destination member name into individual words (by PascalCase conventions).
So you might not need to define the rule for each single property you want to map, otherwise what's the point of using AutoMapper.
For example, if your MetricBadLabManagerByOrganizationDTO campus name were named as BuildingCampusName, AutoMapper would be smart enough to look for Building property on your source and see if there is a property called CampusName inside.
There are just lots of valuable information in AutoMapper documentation you can find and learn from, which is what I like!

Overload puppet default parameter in module

I want to use my own Jenkins plugin server to source plugins from. I'm using the puppet-jenkins module, but I can't seem to change the default plugin host value
The code on github has this in manifests/params:
class jenkins::params {
..
$default_plugins_host = 'https://updates.jenkins-ci.org'
..
}
So when I use this class, if I say:
class { 'jenkins':
default_plugins_host => "https://myhost.local"
}
I get Puppet (err): Invalid parameter
Or, if I try to define the value using capscase:
Jenkins::Params {
default_plugins_host => "https://specificallybrokenhost.com"
}
it isn't used by puppet. I tested this by giving it a plugin host that didn't exist, expecting the plugin installation to fail; but it was able to get plugins successfully (my assumption is that it still used jenkins-ci.org)
I was able to get this working by coping the entire module locally within library-jenkins/puppet-jenkins and changing the value, but i'd prefer not to have to resort to that
I'm using puppet-librarian and Puppet 3.3, if that helps.
the params.pp file stores private variables. This cannot be overridden.
Looking over the module is appears you can change the url from lines 67-82 of plugin.pp
if $version {
$plugins_host = $update_url ? {
undef => $::jenkins::default_plugins_host,
default => $update_url,
}
$base_url = "${plugins_host}/download/plugins/${name}/${version}/"
$search = "^${name} ${version}$"
}
else {
$plugins_host = $update_url ? {
undef => $::jenkins::default_plugins_host,
default => $update_url,
}
$base_url = "${plugins_host}/latest/"
$search = "${name} "
}
$plugins_host will use update_url if it's defined instead of default_plugins_host. if you make a default on the plugin define type you can change the default_plugins_host to update_url like so;
Jenkins::Plugin {
source_url => 'mycompany.jenkins.com',
}
I haven't tested this myself. So, let me know if it works.

Puppet; Call another .pp

So I am using the https://forge.puppetlabs.com/pdxcat/nrpe module to try to figure out automation of NRPE across hosts.
One of the available usages is
nrpe::command {
'check_users':
ensure => present,
command => 'check_users -w 5 -c 10';
}
Is there anyway to make a "group" of these commands and have them called on specific nodes?
For example:
you have 5 different nrpe:command each defining a different check, and then call those specific checks?
I am basically trying to figure out if I could group certain checks/commands together instead of setting up a ton of text in the main sites.pp file. This would also allow for customized templates/configurations across numerous nodes.
Thanks!
EDIT:
This is the command and what it's supposed to do when called on with the 'check_users' portion. If I could have a class with a set of "nrpe:command" and just call on that class THROUGH the module, it should work. Sorry, though. Still new at puppet. Thanks again.
define nrpe::command (
$command,
$ensure = present,
$include_dir = $nrpe::params::nrpe_include_dir,
$libdir = $nrpe::params::libdir,
$package_name = $nrpe::params::nrpe_packages,
$service_name = $nrpe::params::nrpe_service,
$file_group = $nrpe::params::nrpe_files_group,
) {
file { "${include_dir}/${title}.cfg":
ensure => $ensure,
content => template('nrpe/command.cfg.erb'),
owner => root,
group => $file_group,
mode => '0644',
require => Package[$package_name],
notify => Service[$service_name],
}
}
What version are you talking about? In puppet latest versions, inheritance is deprecated, then you shouldn't use it.
The easiest way would be to use "baselines".
Assuming you are using a manifests directory (manifest = $confdir/manifests inside your puppet.conf), simply create a $confdir/manifests/minimal.pp (or $confdir/manifests/nrpe_config.pp or whatever class name you want to use) with the content below:
class minimal {
nrpe::command { 'check_users':
ensure => present,
command => 'check_users -w 5 -c 10',
}
}
Then just call this class inside your node definitions (let's say in $confdir/manifests/my_node.pp) :
node 'my_node.foo.bar' {
include minimal
}

Instantiating a class for each item in an array

Puppet Version: 3.2.4 (Puppet Enterprise 3.0.1)
In order to better support nagios cfg_dir and cfg_file directives in the config file, I've created the following class(es), one for each option:
# Class to add a cfg_dir to the nagios configuration file
class nagios::server::cfg_dir (
$config_dir,
$nagios_user,
$nagios_group,
$nagios_config_file = '/etc/nagios3/nagios.cfg',
)
{
# Build the config dir
file {$config_dir:
ensure => directory,
owner => $nagios_user,
group => $nagios_group,
mode => '0750',
}
# Append cfg_dir=$config_dir path to nagios.cfg file
augeas { "cfg_dir=$config_dir in $nagios_config_file":
incl => "$nagios_config_file",
lens => 'NagiosCfg.lns',
changes => "set cfg_dir/[last()+1] ${config_dir}",
require => File[$nagios_config_file],
}
}
Trying to use this construct inside nagios::server, I have this:
# Set up config directories
each($cfg_dir) |$x| {
class { 'nagios::server::cfg_dir':
config_dir => $x,
nagios_user => $nagios_user,
nagios_group => $nagios_group,
nagios_config_file => $nagios_config_file,
}
}
Which should, in theory, execute the class instantiation for each path passed in to the nagios::server class like so:
class{'::nagios::server': cfg_dir => ['/etc/nagios.d','/etc/nagios/objects'] }
However, I run into this issue:
Error: Could not match |$x| at /tmp/vagrant-puppet-1/modules-2/nagios/manifests/server.pp:181 on node localhost.localdomain
Can someone provide a working example of each in use? Am I expecting too much from this built-in puppet function?
Aside from a few of the code grammar issues above, I've found that this construct is only evaluated in the future parser:
puppet apply --parser=future --modulepath ...
http://docs.puppetlabs.com/puppet/latest/reference/experiments_lambdas.html
Still getting past other dependency issues. What pattern would I use to support this with the current parser instead of future? A custom function?
The answer to my follow-up question is to use defined types:
http://docs.puppetlabs.com/learning/definedtypes.html
Simply changing the above code from a class to a define and assign $config_dir the value from $target,
define nagios::server::cfg_dir (
$config_dir = $target,
$nagios_user,
$nagios_group,
$nagios_config_file = '/etc/nagios3/nagios.cfg',
){...
you can use constructs such as:
nagios::server::cfg_dir { '/etc/nagios.d/', '/etc/nagios/objects':
nagios_user => 'nagios',
nagios_group => 'nagios'
}
This solves the issue for me.

Resources