Merging another web.php file in config/web.php of yii2 - web

We are two groups developing a project made in Yii2 basic. The problem we are facing right now is we have different web.php under config. Our group would like to include our web.php (which was renamed to extras.php) inside the web.php of another group. The difference is we added variables under components of $config of web.php. Yes, we can manually add our new variables under components of $config from the other team but we prefer to use separate files that is why we renamed the other web.php to extras.php.
A small preview of web.php looks like this
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'language'=> isset($_SESSION['language_local']) ? $_SESSION['language_local']:'en',
'components' => [
'nagios' => [
'class' => 'app\components\nagios',
],
'hostlistsql' => [
'class' => 'app\components\hostlistsql',
],
'request' => [empty) - this is required by cookie validation
'cookieValidationKey' => 'nYwdMpu-dw004qwFRZmqZOzzC3xdnL8b',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
],
'params' => $params,
];
extras.php looks like this
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'language'=> isset($_SESSION['language_local']) ? $_SESSION['language_local']:'en',
'components' => [
'user_functions' => [
'class' => 'app\components\UserFunctions',
],
'user_extras' => [
'class' => 'app\components\UserExtras',
],
'request' => [empty) - this is required by cookie validation
'cookieValidationKey' => 'nYwdMpu-dw004qwFRZmqZOzzC3xdnL8b',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
],
'params' => $params,
];
What approach should we take to include extras.php inside web.php?
EDIT:
SOLUTION:
Inside web/index.php has
$config = require(__DIR__ . '/../config/web.php');
I changed it instead to
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../config/web.php'),
require(__DIR__ . '/../config/extras.php')
);

Why would you want to include extras.php inside web.php instead of just merging them?
Here is how the same thing is handled in yii2 advanced https://github.com/yiisoft/yii2-app-advanced/blob/master/environments/dev/frontend/web/index.php
As you can see common..main.php is merged with common..main-local.php is merged with frontend..main.php is merged with frontend..main-local.php
There are 4 files that are merged to get to the end 1 single config file. Eazy as pie.
If you really want to merge things inside web.php do a
$config = [....];
return yii\helpers\ArrayHelper::merge(
$config,
require(__DIR__ . 'extras.php'),
);

Do you guys have any version control system (like git, Bitbucket, etc...) ?
You could let only the things you have in common in the web.php file and the rest coming from a external file.
Since each group will have a different file, i would recommend create a constant that decides which file is being used. Following your example:
web.php:
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'language'=> isset($_SESSION['language_local']) ? $_SESSION['language_local']:'en',
'components' => EXTRAS ? require(__DIR__ . '/components2.php') : require(__DIR__ . '/components1.php'),
'params' => require(__DIR__ . '/params.php')
];
Example of components2.php:
return [
'user_functions' => [
'class' => 'app\components\UserFunctions',
],
'user_extras' => [
'class' => 'app\components\UserExtras',
],
'request' => [empty) - this is required by cookie validation
'cookieValidationKey' => 'nYwdMpu-dw004qwFRZmqZOzzC3xdnL8b',
],
'cache' => [
'class' => 'yii\caching\FileCache',
]
]
And EXTRAS is a constant defined elsewhere. You could do that in web/index.php (follow the YII_DEBUG and YII_ENV samples) and add it in your ignored files, if you didn't already.

Related

Yii2 routing problems,don't recognise parameters

Every time a make request to http://localhost/users?username="john.doe", I get 404 error.
The following code is Controller code to control routes.
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => [ 'users'],
'rules' => [
[
'actions' => ['users'],
'allow' => true,
'roles' => ['#'],
]
]
],
];
}
Controller action code.
public function actionUsers($username)
{
if (Yii::$app->request->isAjax) {
return Users::find()->where('username', $username)->one();
}
}
PS: I'm make ajax request.
Assuming you action actionUsers is inside a controller name MyuserController then your link should be
http://localhost/myuser/users?username="john.doe"
Your link must contain also the name of the controller (not only the name of the action)

Grep and Replace a string in a particular pattern

I want to add/replace a string in a file with in a particular pattern. Please refer below
"dont_search_this" => {
-tag => "qwerty",
-abc_asd => [ "q/rg/dfg.txt",],
-dependent_fcv => ["me_lib", "you_lib",],
-vlog_opts => (($ENV{ABC_PROJECT}) eq "xuv")
? [ "-error=AMR", "-error=GHJ", "-error=TYU", "-error=IJK", ]
: [] ,
},
"search_this" => {
-tag => "qwerty",
-abc_asd => [ "q/rg/dfg.txt",],
-dependent_fcv => ["me_lib", "you_lib",],
-vlog_opts => (($ENV{ABC_PROJECT}) eq "xuv")
? [ "-error=AMR", "-error=GHJ", "-error=TYU", "-error=IJK", ]
:[],
},
In above data, I want to add string "-error=all", in the line -vlog_opts in search_this paragraph only. Modified should be as follows
"dont_search_this" => {
-tag => "qwerty",
-abc_asd => [ "q/rg/dfg.txt",],
-dependent_fcv => ["me_lib", "you_lib",],
-vlog_opts => (($ENV{ABC_PROJECT}) eq "xuv")
? [ "-error=AMR", "-error=GHJ", "-error=TYU", "-error=IJK", ]
:[],
},
"search_this" => {
-tag => "qwerty",
-abc_asd => [ "q/rg/dfg.txt",],
-dependent_fcv => ["me_lib", "you_lib",],
-vlog_opts => (($ENV{ABC_PROJECT}) eq "xuv")
? [ "-error=AMR", "-error=GHJ", "-error=TYU", "-error=IJK", "-error=all" ]
:[],
},
Please help me in this.
Using perl is also fine.
Thank You very much!
I can't help it but think that there's got to be a better way than editing the source code ... ?
Read the whole script file into a string and then follow the trail to identify the place to change
perl -0777 -wpe'
s/"search_this"\s+=>\s+\{.*?\-vlog_opts\s+=>\s+[^\]]+\K/ADD_THIS/s;
' file
(broken over lines for readability)
Notes
0777 switch unsets the input record separator, so the file is "slurped" whole as one "line"
the /s modifier makes it so that . matches the newline as well
the \K makes it so that all matches up to that point are dropped (not consumed) so they don't have to be (captured and) entered in the replacement part. So we literally add ADD_THIS
Good information about \K is under "Lookaround Assertions" in Extended Patterns in perlre but keep in mind that it subtly differs from other lookarounds
That looks like a perl data structure.
Any reason why can't just push "-error=all" into $hash{search_this}{-vlog_opts}->#*

HTML button to revbeal password input field

I have a table with 7 columns. One of them contains passwords (pw).
I dont want to show the passwords on my website: I would like to have some kind of "click to expand" in the table to show it.
Here is a part of the script that contains the table:
...
push #certlist, {
state => $cert[0],
'expire' => $date,
'subject' => $cert[5],
'cn' => $cn,
'ip' => $ccd_ips->{$cn},
'dl' => '',
're' => '',
'pw' => $password->{$cn}
};
...
return $q->table(
{ 'class' => 'certs' },
$q->Tr(
[
$q->th(
[ 'Status', 'Common Name', 'D', 'Password',
'Date', 'Subject', 'IP-Adress', 'R'
]
) . "\n",
map {
$q->td( { 'class' => $_->{'state'} }, $states{ $_->{'state'} } ) .
$q->td( [ #$_{qw(cn dl pw expire subject ip re)} ] ) . "\n"
} #certlist
]
)
) . "\n";
...
You should only add a class, say password-container to elements that contain passwords. Set the initial content to masked.
That is:
push #certlist, {
state => $cert[0],
'expire' => $date,
'subject' => $cert[5],
'cn' => $cn,
'ip' => $ccd_ips->{$cn},
'dl' => '',
're' => '',
'pw' => '*' x 8,
};
Add a bit of JavaScript to the page to add an onclick handler for all elements with the password-container class which handles the toggling.
return $q->table(
{ 'class' => 'certs' },
$q->Tr(
[
$q->th(
[ 'Status', 'Common Name', 'D', 'Password',
'Date', 'Subject', 'IP-Adress', 'R'
]
) . "\n",
map {
$q->td( { 'class' => $_->{'state'} }, $states{ $_->{'state'} } ) .
$q->td( [ #$_{qw(cn dl)} ]) .
$q->td( { 'class' => 'password_container' }, $_->{pw} ) .
$q->td( [ #$_{qw(expire subject ip re)} ] ) . "\n"
} #certlist
]
)
) . "\n";
or some similar garbage.
This, once again, shows the value of not generating HTML using CGI.pm. Instead use templates. That's just advice for the future, I am assuming you can't fix the existing codebase.
BTW, here is a relevant bit from CGI.pm documentation:
All HTML generation functions within CGI.pm are no longer being maintained. Any issues, bugs, or patches will be rejected unless they relate to fundamentally broken page rendering.
The rationale for this is that the HTML generation functions of CGI.pm are an obfuscation at best and a maintenance nightmare at worst. You should be using a template engine for better separation of concerns. See CGI::Alternatives for an example of using CGI.pm with the Template::Toolkit module.
These functions, and perldoc for them, are considered deprecated, they are no longer being maintained and no fixes or features for them will be accepted. They will, however, continue to exist in CGI.pm without any deprecation warnings ("soft" deprecation) so you can continue to use them if you really want to. All documentation for these functions has been moved to CGI::HTML::Functions.

Logstash not adding fields

I am using Logstash 1.4.2 and I have the following conf file.
I would expect to see in Kibana in the "Fields" section on the left the options for "received_at" and "received_from" and "description", but I don't.
I see
#timestamp
#version
_id
_index
_type host path
I do see in the _source section on the right side the following...
received_at:2015-05-11 14:19:40 UTC received_from:PGP02 descriptionError1!
So home come these don't appear in the list of "Popular Fields"?
I'd like to filter the right side to not show EVERY field in the _source section on the right. Excuse the redaction blocks.
input
{
file {
path => "C:/ServerErrlogs/office-log.txt"
start_position => "beginning"
sincedb_path => "c:/tools/logstash-1.4.2/office-log.sincedb"
tags => ["product_qa", "office"]
}
file {
path => "C:/ServerErrlogs/dis-log.txt"
start_position => "beginning"
sincedb_path => "c:/tools/logstash-1.4.2/dis-log.sincedb"
tags => ["product_qa", "dist"]
}
}
filter {
grok {
match => ["path","%{GREEDYDATA}/%{GREEDYDATA:filename}\.log"]
match => [ "message", "%{TIMESTAMP_ISO8601:logdate}: %{LOGLEVEL:loglevel} (?<logmessage>.*)" ]
add_field => [ "received_at", "%{#timestamp}" ]
add_field => [ "received_from", "%{host}" ]
}
date {
match => [ "logdate", "ISO8601", "yyyy-MM-dd HH:mm:ss,SSSSSSSSS" ]
}
#logdate is now parsed into timestamp, remove original log message too
mutate {
remove_field => ['message', 'logdate' ]
add_field => [ "description", "Error1!" ]
}
}
output {
elasticsearch {
protocol => "http"
host => "0.0.0.x"
}
}
Update:
I have tired searching with a query like:
tags: data AND loglevel : INFO
then saving this query, and then reloading the page.
But still I don't see loglevel appearing as 'Popular Fields'
If the fields don't appear on the left side, it's probably a kibana caching problem. Go to Settings->Indices, select your index, and click the orange Refresh button.
I had the same issue with logstash not adding fields and after quite a lot of searching and testing other things, suddenly I had the solution (but I´am using the logstash-logback-encoder, so I have JSON already - if you don´t, then you need to transform things into JSON in the logstash "input"-phase).
I added a "json" plugin-filter, that did the magic for me:
filter {
json {
source => "message"
}
}

Docusign API - prefilling tab values on envelope created from template

I was able to successfully generate and send an envelope from template using the Docusign API. The only problem is that the tab values and not pre-populating as expected (they remain blank). Here is the relevant code based on DocuSign-REST-API-Webinar-April2013:
/////////////////////////////////////////////
// STEP 2 - Create an envelope
////////////////////////////////////////////
$data = array(
"accountId" => $accountId,
"emailSubject" => "DocuSign API - Signature Request from Template",
"templateId" => $templateId,
"templateRoles" => array(
array(
"email" => $email,
"name" => $recipientName,
"inPersonSignerName" => "Some Customer",
"roleName" => "Customer",
"routingOrder" => 2,
"tabs" => array(
"textTabs" => array(
array(
"tabLabel"=> "mmr",
"value" => "29.95"
)
)
)
),
array(
"email" => $email,
"name" => $recipientName,
"inPersonSignerName" => "Some Tech",
"roleName" => "Tech",
"routingOrder" => 1,
"tabs" => array(
"textTabs" => array (
array (
"tabLabel" => "\\*state",
"value" => "North Carolina"),
array (
"tabLabel" => "\\*city",
"value" => "Raleigh")
)
)
)
),
"status" => "sent");
All my searches for answers on support forums, documentation, etc seem to point to what I have. I have double-checked the tabLabels and they are correct and assigned to the correct role. The template contains three roles - Tech (Sign In Person), Customer (Sign In Person), Data Entry (Receive a Copy).
Can anybody spot the problem? I also tried with just "tabLabel" => "state" and "tabLabel" => "city" (i.e. without the wildcard) but same problem. Let me know if you need more info. Thanks!
Have you verified in the template that the tags are assigned to the expected recipient? Based on your code above, it looks like the tag labeled "mmr" should be assigned to the Customer role and the tags labeled "state" and "city" are assigned to the Tech. Is that correct?

Resources