Categories
Coding Websites

Stop CloudFlare from injecting beacon

I have a client that uses CloudFlare, which I recommend, not only because I approve of their service, having been using it since they started up, but I love how they are fighting patent trolls!

So where was I? Oh, right! The client turned on Web Analytics which started causing a ruckus with some pages that provided API-like responses to certain automated functions by injecting a link of code to the rendered html output.

So in this case we turned off “automatic setup” for that site using CF dashboard -> analytics & logs -> web analytics -> manage site link

Now I bet there is another more elegant solution like making sure the page outputs a different content-type or something that would prevent this, but for a quick fix on this issue, doing the above works.

Categories
Coding Unix

Perl – SSL connection error: Validation of SSL server certificate failed

I have a VM running Rocky Linux release 8.7 (Green Obsidian) and have some Perl programs that use DBI/DBD for mysql connections to a Google Cloud database that requires a SSL connection.

All the parameters (i.e., ssl cert/key/server-ca) work fine when running the mysql command line to connect to the database. However, when running the Perl programs, they fail with that error.

So it is NOT a bad certificate on the server side (at least in my case), but instead something with the Perl libraries.

Some resources talk about how mariadb is the culprit, but I was running mysql-community server and still had an issue, and I even downgraded MySQL to 5.7 from 8.0 with no luck. It turns out however that when I installed Perl libraries for perl-DBD-MySQL and perl-DBI those did a dependency install of a mariadb connector!

So basically I removed all mariadb packages, and then made sure we had the packages for:

  • mysql-community-common
  • mysql-community-devel
  • mysql-community-libs

And then used CPAN to install the DBI and DBD::mysql packages

Then things worked! So the key I believe is to not use the yum/dnf versions for DBI/DBD that tie to mariadb, and instead install those via CPAN.

Hope this helps someone out there, because I really went through a lot of attempts on this to get it going.

Categories
Coding Unix

Stopping vim8 from auto inserting on paste

After updating my linux system I found that when I went to do a mouse-paste in VIM that instead of just interpreting the characters, it went right into insert mode. This is a problem when I want to paste in a bunch of vim commands, which can be helpful if you need to re-do a series of actions multiple times.

It turns out the fix has to do with “xterm-bracketed-paste” and I had to put this in the .vimrc:

set t_BE=

I hope this helps someone who got surprised by vim version 8 functionality!

 

Categories
Coding

Having trouble accessing your Alexa skill

We have done a number of Alexa skills for clients and recently one of them would give this message to users: “Sorry, I’m having trouble accessing your {} skill right now”

Not much to go on! It turns out the problem was the content that was getting delivered for Alexa to say had some non-ASCII characters in it. The skill has dynamic content the client would update, and apparently they pasted from a Word doc which then translated a quote character into one of those annoying double wide Word characters which Alexa does not like!

So basically run your content through an ASCII-only parse before delivering it and you’re good.

Categories
Coding Websites

Applying callback to grecaptcha

We were having some troubles with some users rushing to click the submit button on a form immediately after clicking the good ‘ole “I’m not a robot” checkbox, instead of waiting nicely for the captcha to verify. By the way, that is TOTALLY what a robot would do, so it’s probably good that it fails the verification.

But to get the submit button to only enable after the checkbox turns green, you need to provide a “callback” routine for the grecaptcha. And, you can also provide a “expired-callback” routine for if the captcha box sits around too long after a check and then turns red. Note that you need to put the defined callbacks without quotes.

Also to add some complexity, we had two separate captchas in our page, so we had to define two of them. Some people have reported troubles doing so, but our final solution worked.

We had a problem where the callback routines were not being called, but everything else was working — it turns out we have the callback functions defined AFTER the render, and moving them before that section made everything work. So, the final layout:

<script src=”https://www.google.com/recaptcha/api.js?onload=myCaptInit&render=explicit” async defer></script>
<script>
var myCaptInit = function() {
var buton11 = function() {
$(“#mainsubmit”).removeAttr(“disabled”);
};
var butoff11 = function() {
$(“#mainsubmit”).attr(“disabled”, “disabled”);
};
grecaptcha.render(‘recaptcha11’, {
‘sitekey’: ‘xxxx’,
‘callback’: buton11,
‘expired-callback’: butoff11,
‘size’: ‘compact’
});
grecaptcha.render(‘recaptcha10’, {
‘sitekey’ : ‘xxxx’,
‘size’ : ‘compact’
});
};
</script>

Categories
Coding Unix

SFTP in Perl Connecting to Legacy Server

We had a client that had a need to do automated SFTPs to various sites. It turns out that some of the sites had an older SSHD that would generate an error like “DH Group Exchange reply out of range”, and that required this parameter if you were using SFTP from the command line:

-oKexAlgorithms=diffie-hellman-group1-sha1

Now in Perl we were using Net::SFTP and it took some finagling (yes, that’s really a word) to figure out the proper settings, so here they were in case you were having trouble. And we had to add the warn flag otherwise we would get this warning:

Couldn’t fsetstat: Permission denied

Another oddity was that when we were putting files, the SFTP server allowed multiple files with the same name! Very odd, so we had to make sure to add a $sftp->do_remove command prior to the put command.

Here is what we used for the function call:

%sftp_args =
( “user” => “myuser”,
“password” => “mypass”,
“debug” => 0,
“warn” => 0,
“ssh_args” => [ options => [ “KexAlgorithms diffie-hellman-group1-sha1” ] ]
);

$sftp = Net::SFTP->new($sftp_host,%sftp_args);

Categories
Coding Unix

Installing Node.js4 in Centos7 with Yum

A quick summary that may help people who are installing AngularJS v2 and need to make sure they have the latest stuff.

First off, CentOS does not use a recent version of Node,js or NPM due to, well, lots of reasons! In fact the version the repo has for Nodejs is ZERO and it is already up to 4, 5 and 6. So that’s pretty damn old. When I’m in the software store and the guy asks “hey, do you want version 6 of that software?”, I rarely find myself saying, “Nah, please hit me with version zero.” What software store do I speak of? Well, this one of course!

All your software needs conveniently located at the shopping mall

Anyway, here is what you do to get the version 4 for nodejs etc:

curl –silent –location https://rpm.nodesource.com/setup_4.x | bash –

yum install -y nodejs

Categories
Coding

PHP is unable to retrieve information via $_POST on my localhost but $_GET works

I encountered this odd problem where FORM POSTs would not work! Other peoples comments on this were along the lines of server misconfiguration, which is sort of true — the reason for me was that I had some rewrite rules so I could leave .php extensions off the path — and I had forgotten to put ACTION in the form to leave off the extension!

Once I fixed that it all worked.

Categories
Coding

Automatically insert Current Date and Time in MySQL table

I was trying to recall how to create a field in a MYSQL table that will auto timestamp on inserts or updates, and surprisingly google did not give any direct and easy results! Seriously, the results were either off topic or packed with ads and off topic.

Here it is, simple and to the point:

`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP

Categories
Coding Websites

http AJAX fails in Internet Explorer

I ran across an interesting bug recently where I had an AJAX routine failing when I viewed the page in IE8. When you clicked the little warning icon in the lower left, it gave a message of “Object doesn’t support this property or method”!

It was failing around code that looks like:

function parseCalcResponse() {
if (http.readyState == 4 && http.status == 200) {
results = http.responseText;
results = results.split(“|||”);
document.getElementById(‘test’).innerHTML = results;
}
}

It turns out, the fix was to declare “results” at the top of the function code with:

var results=”;

And that fixed it!