MariaDB Sequence Storage Engine

Posted on Tuesday, April 14, 2020 by Nicki

Learnt today that MariaDB has this great feature called a Sequence Storage Engine.

Ever needed to repeat something couple of times but don't want to write a loop? Just write a query that joins to a sequence table, for example:

set @date = date(now());
select 
date(date_add(@date, interval seq day)) as date, 
dayname(date_add(@date, interval seq day)) as dayname, 
week(date_add(@date, interval seq day)) as weeknum, 
mod(dayofweek(date_add(@date, interval seq day))+5, 7) dayofweek, 
case when mod(dayofweek(date_add(@date, interval seq day))+5, 7) < 5 then 1 else 0 end workday
from seq_0_to_21

It produces the following listing(forgive the formatting):

+------------+-----------+---------+-----------+---------+
| date | dayname | weeknum | dayofweek | workday |
+------------+-----------+---------+-----------+---------+
| 2020-04-14 | Tuesday | 15 | 1 | 1 |
| 2020-04-15 | Wednesday | 15 | 2 | 1 |
| 2020-04-16 | Thursday | 15 | 3 | 1 |
| 2020-04-17 | Friday | 15 | 4 | 1 |
| 2020-04-18 | Saturday | 15 | 5 | 0 |
| 2020-04-19 | Sunday | 16 | 6 | 0 |
| 2020-04-20 | Monday | 16 | 0 | 1 |
| 2020-04-21 | Tuesday | 16 | 1 | 1 |
| 2020-04-22 | Wednesday | 16 | 2 | 1 |
| 2020-04-23 | Thursday | 16 | 3 | 1 |
| 2020-04-24 | Friday | 16 | 4 | 1 |
| 2020-04-25 | Saturday | 16 | 5 | 0 |
| 2020-04-26 | Sunday | 17 | 6 | 0 |
| 2020-04-27 | Monday | 17 | 0 | 1 |
| 2020-04-28 | Tuesday | 17 | 1 | 1 |
| 2020-04-29 | Wednesday | 17 | 2 | 1 |
| 2020-04-30 | Thursday | 17 | 3 | 1 |
| 2020-05-01 | Friday | 17 | 4 | 1 |
| 2020-05-02 | Saturday | 17 | 5 | 0 |
| 2020-05-03 | Sunday | 18 | 6 | 0 |
| 2020-05-04 | Monday | 18 | 0 | 1 |
| 2020-05-05 | Tuesday | 18 | 1 | 1 |
+------------+-----------+---------+-----------+---------+
22 rows in set (0.01 sec)

The sequence table name is dynamic, so to get a sequence from 1 to 5 use the table name seq_1_to_5. It has a column called seq that contains the sequence number

Link:  https://mariadb.com/kb/en/sequence-storage-engine/



Help, my QuickAccess in Windows 10 is broken

Posted on Friday, November 15, 2019 by Nicki

QuickAccess in Windows10 Explorer is quite handy for pinning often-used folders. Recently mine stopped working for some reason. It would not show the items previously pinned, nor would it accept new pins.

After a bit of searching, the fix is:

Integrating to legacy temperature monitoring device

Posted on Thursday, October 26, 2017 by Nicki

Below is sample code of a proxy ASP.Net page that queries a TempageR 4E realtime temperature monitor and exposes the temperature to PRTG in order to report and escalate out of range values.

public partial class FetchTemp : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient(System.Configuration.ConfigurationManager.AppSettings["ip"], 80);
            NetworkStream ns = client.GetStream();
            byte[] request = System.Text.Encoding.ASCII.GetBytes("GET /getData.htm HTTP/1.1\r\n\r\n");

            ns.Write(request, 0, request.Length);

            byte[] resp = new byte[2048];
            int bytes = -1;

            StringBuilder sb = new StringBuilder(); 

            while (bytes != 0)
            {
                bytes = ns.Read(resp, 0, resp.Length);
                sb.Append(System.Text.Encoding.ASCII.GetString(resp, 0, bytes));
            }

            dynamic obj = JsonConvert.DeserializeObject(sb.ToString());
            Response.Write("[" + obj.sensor[0].tempc + "]");
        }
    }

It calls the getData.htm page, which exposes the device info, sensors and their values as a JSON object. This gets parsed, and the value of the first sensor is written to the Response in blockquotes. The PRTG HTTP Content sensor is configured with the URL of the page (FetchTemp.aspx).

The code uses a TcpClient instance to retrieve the data. The getData.htm page does not return HTTP response headers, which causes HttpWebRequest as well as the built-in PRTG HTTP XML/REST sensor to fail with "The underlying connection was closed unexpectedly", using TcpClient solves this issue.

Using TLS 1.1, 1.2 in .Net 4.0 Application

Posted on Thursday, August 3, 2017 by Nicki

One of our partners stopped support for SSL3.0 and TLS1.0 on a service that we connect to with a .Net 4.0 application.

Using WireShark we determined that the application was attempting connections using SSL3.0 and TLS1.0 only. Digging into this we found a link mentioning that a registry value needs to be configured for .Net4.0 to be able to use TLS1.0 and above.

Once we configured the registry value and restarted the application, it was able to connect to the remote service.


How to generate a GUID in XSLT transformations

Posted on Wednesday, May 10, 2017 by Nicki

A recent task involved migrating tens of jobs from Control M to VisualCron. I 'm never in the mood for manual repetitive tasks, so the approach was taken to do it with XSLT, since both Control M and VisualCron support XML config schemas.

VisualCron expects various Ids to be GUIDs, and XSL has no built-in functionality to generate GUIDs, so a plan had to be made. I queried Google and found that one can write extension objects in C# and use them during the translation.

The code for to generate a GUID is very simple:

    public class TransformUtils
    {
        public string GenerateGuid()
        {
            return Guid.NewGuid().ToString();
        }
    }

This is then plugged into the transformation code like this:
            string xmlPath = txtXMLSource.Text;
            string xslPath = txtXSLSource.Text;
            StringBuilder output = new StringBuilder();

            
            XsltArgumentList arguments = new XsltArgumentList();
            arguments.AddExtensionObject("EPS:TransformUtils", new TransformUtils());
            
            using (StringWriter writer = new StringWriter(output))
            {
                XslCompiledTransform transform = new XslCompiledTransform();
                transform.Load(xslPath);
                transform.Transform(xmlPath, arguments, writer);
            }
Inside the xslt stylesheet the extension function can now be called:
<xsl:value-of select="TransformUtils:GenerateGuid()" />

I found a good sample and guide here

DNS Unlocker ads #2

Posted on Thursday, September 17, 2015 by Nicki

In my quest to find the cause(s) for these DNS Unlocker ads, I found Steve Gibson's DNS Nameserver Spoofability Test to test my DNS.

This can identify any DNS issues that could cause these DNS Unlocker ads to be injected into sites you visit.

DNS Unlocker ads

Posted on by Nicki

It seems like DNS Unlocker ads injected into websites you visit is a big issue at the moment. I've seen them on site I visited, some other people I know have also experienced them.

All the resolution links I've seen seems to have the same procedure, and if none of the first couple detection methods work they have a tool to download. Now I've not tried any of those so-called tools, but I have a suspicion that these 'tools' might actually put you in a worse position than what you were in.

How do you get the ads? 
They seem to be injected by a rogue google analytics script. From looking at other sources on the web it looks like DNS poisoning takes place somewhere upstream from my pc, which causes a DNS lookup for www.google-analytics.com to return the address of a rogue server posing as the real thing. This script injects another script from hosts on the dnsqa.me domain, which injects scripts which injects the ads into the page you are viewing.

How do you get rid of it? 
On my machine no actual DNS Unlocker software got installed, and my DNS settings were also not changed. I ran Malware Bytes as well as AdwCleaner to scan for malware, they found a few cookies and cached pages but no actual installed malware that had to be removed. I also did a Reset in Chrome, which clears cache, disables extensions and clears history. After this I still got the ads from time to time. Installing Malware Bytes and activating the 14day Premium trial certainly picks up these rogue scripts and prevents them from being injected. I also installed AdBlock in Chrome and configured it to block all access to *.dnsqa.me and *.google-analytics.com, to prevent the malware from being injected by any of those two avenues.

Other possibilities
If you router still has the default password, it is possible that some application you installed could connect to the router and change the DNS settings. It is also possible that an application can change the DNS settings on your machine itself. Check both these locations to make sure that the DNS settings are configured to use automatic provided values, or if you manually configured DNS servers like OpenDNS, etc that they are still intact. If the DNS on your router was changed, make sure to change the default admin password on your router.

Different Ways to prevent the injection
Install Malware Bytes and active the 14-day Premium trial
Install the AdBlock extension in Chrome
Configure OpenDNS as DNS provider.