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.
Related
I am getting the following error in the event viewer on my node during a puppet run. I suspect the issue is with incorrect lookup function in my profile.
Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Scconfig::Coserveradmin[SomeSettings]:
parameter 'parameterA' expects a String value, got Undef
parameter 'parameterB' expects a String value, got Undef
parameter 'parameterC' expects a String value, got Undef
parameter 'parameterD' expects a String value, got Undef
coserveradmin is a define resource with all string parameters. I would like to do lookup of values from a Json file
{
"SASettings" : {
"Watchdog" : {
"ParameterA" : "somevalue",
"ParameterB" : "somevalue"
},
"Serversettings" : {
"ParameterC" : "somevalue",
"ParameterD" : "somevalue",
},
"GeneralSettings" : {
"ParameterE" : "somevalue",
"ParameterF" : "somevalue",
},
"customsettings_prod" : {
"ParameterG" :"somevalue",
"ParameterH" : "%{facts.hostname}.example-cloud.com"
},
"customsettings_dev" : {
"ParameterI" :"",
"ParameterK" : "%{facts.hostname}.example.net"
}
}
}
In my hiera.yaml file I have defined the name and path to the json file.
- name: "Desired Some Settings"
path: "default/serveradmin.json"
In profile I have the following code .
class profile::scconfig_someprofile_a {
.
.
.
$hname= $::facts['hostname']
$mac= "${facts['macaddress'].delete(':')}"
$adminpropeties = lookup('SASettings')
if $hname=~someregex {
scconfig::coserveradmin{ 'SomeSettings':
property1 => $adminpropeties['customsettings_prod.ParameterG'],
property2 => $adminproperties['Watchdog.ParameterA'],
property3 => $adminproperties['Watchdog.ParameterB'],
property4 => $adminproperties['Serversettings.ParameterC'],
.
.
.
.
and so on
.
macaddress => $mac,
}
elsif $hname=~someregex {
scconfig::coserveradmin{ 'SomeSettings':
property1 => $adminpropeties['customsettings_dev.ParameterI'],
property2 => $adminproperties['Watchdog.ParameterA'],
property3 => $adminproperties['Watchdog.ParameterB'],
property4 => $adminproperties['Serversettings.ParameterC'],
.
.
.
.
and so on
.
macaddress => $mac,
}
Also adding the code for the "define" resource as requested.
define scconfig::coserveradmin(
String $Property1,
String $Property2,
String $Property3,
String $Property4,
.
.
.
String $macaddress,
) {
$dscmoduleversion = lookup('requires.modules.codsc.version')
if $dscmoduleversion != '' {
$module = {
'name' => 'codsc',
'version' => $dscmoduleversion,
}
}else{
$module = 'codsc'
}
$configname1='someconfig1'
$configname2='someconfig2'
$configname3='someconfig3'
dsc { 'someconfig1':
require => lookup('requires.cloudopssoftware'),
resource_name => 'Someresourcename',
module => $module,
properties => {
configname => $configname1,
Prop1 => $Property1,
Prop2 => $Property2,
Prop3 =>$Property3,
},
}
dsc { 'someconfig2':
require => lookup('requires.cloudopssoftware'),
resource_name => 'someresourcename2',
module => $module,
properties => {
configname => $configname2,
Prop1 => $Property4,
Prop2 => $Property5,
Prop3 =>$Property6,
},
}
dsc { 'someconfig3':
require => lookup('requires.cloudopssoftware'),
resource_name => 'someresourcename3',
module => $module,
properties => {
configname => $configname3,
Prop1 => $Property6,
Prop2 => $Property7,
Prop3 =>$Property8,
.
.
.
Propn => $macaddress
},
}
Please note that the last property which is the macaddress is evaluated within the profile class therefore I don't see any error for it.
Any ideas what could be the issue.
I suspect the issue is with incorrect lookup function in my profile.
That does not appear to be the case. If your lookup() call were not successfully looking up and returning a hash then you would get a different error when you tried to extract values.
I guess it's possible that you're retrieving the wrong hash -- which would be a matter of your hiera configuration and / or data, not the lookup() call itself -- but whether it's the right hash or the wrong one, the syntax you are trying to use to extract the data from it is not matched to the hash structure presented in the question. For example, this expression
$adminpropeties['customsettings_prod.ParameterG']
attempts to retrieve the value whose key is 'customsettings_prod.ParameterG', but the data presented contain no such key.
What you seem to want is
$adminpropeties['customsettings_prod']['ParameterG']
That extracts the value having key 'customsettings_prod', and, that value being a hash itself, extracts its value associated with key 'ParameterG'.
Alternatively, you may find the dig() function convenient for extracting data from nested data structures such as yours:
dig($adminpropeties, 'customsettings_prod', 'ParameterG')
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}->#*
I have a Issue with docusign attachment through REST API. It was perfectly worked previously but the following error message coming,
{
"errorCode": "UNABLE_TO_CONVERT_DOCUMENT",
"message": "System was unable to convert this document to a PDF. Unab (truncated...)
If you can please help me on this
Bellow is the code segment which I'm using for attach image file to the docusign.
if(isset($this->attachments['NIC_Rear']))
{
array_push($dataArray['compositeTemplates'],
[
'inlineTemplates' => array(
[
'sequence' => '3',
'recipients' => array(
'signers' => array([
'email' => $this->issuerEmail,
'name' => $this->issuerName,
'recipientId' => '1',
'roleName' => $this->roleName,
'tabs' => $this->tabs,
])
)
]
),
'document' => array('documentId' => '3',
'name' => 'Attachment11',
'fileExtension' => get_file_extension_from_file($this->attachments['NIC_Rear']),
'width' => 100,
'height' => 100,
'documentBase64' => isset($this->attachments['NIC_Rear']) ? base64_encode($this->attachments['NIC_Rear']) : '',
),
]
);
}
This error you're getting:
{ "errorCode": "UNABLE_TO_CONVERT_DOCUMENT", "message": "System was unable to convert this document to a PDF. Unab (truncated...)
is indicative of any situation where the bits being passed to the DocuSign system cannot be converted into a flat pdf file representing the document.
It could be that it's not any document format that is supported, the document is password locked, empty or have any invalid macros or other bad stuff in it. Can you try a simple text document first just to isolate the issue?
I want to subdue some sensu checks outside working hours and weekends. The documentation is not clear on how it works. Sensu subdue documentation
'subdue' => {
'days' => {
'all' => [
{
'begin' => '8:00 PM',
'end' => '10:00 AM'
}
],
'saturday' => [
{
'begin' => '12:00 AM',
'end' => '11:59 PM'
}
],
'sunday' => [
{
'begin' => '12:00 AM',
'end' => '11:59 PM'
}
]
}
}
My question is: will the specific day override the all attribute?
Also: is there a better way to do this check?
Thanks!
Yes, Specific day override all attribute. We should add subdue configurations in our client.json file.
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.