{{error}}
{{(quickSearchResults.length>10)?'10+':(quickSearchResults.length)}} {{(quickSearchResults.length==1)?'result':'results'}}
{{result.title}} {{result.timeStamp | mysql2ymd }}
I am sorry, no such article was written yet.
How to parse in PHP the cPanel mime type configuration, and how to filter the files using the .htaccess
Hosting more sites on a single IP and with an economic entry-level support from ISP (but still, allowed to process requests from more domains through the same PHP engine) leads to a long series of challanges.
One of them is that even though each site has its own files structured in its own folder, in case that a file was not found or there were conflicting files, the server seemed to pick randomly a file from another domain's folder.
Problem looked solved with the following configuration:
#Resources to their folders
RewriteCond %{REQUEST_URI} \.(pdf|doc|xml|pem|crx|apk|svg)$
RewriteCond %{DOCUMENT_ROOT}/%{HTTP_HOST}%{REQUEST_URI} -f
#RewriteCond %{DOCUMENT_ROOT}/%{HTTP_HOST}%{REQUEST_URI} !-d
RewriteRule ^(.+)$ %{HTTP_HOST}%{REQUEST_URI}
But it does not do what it should obviously do (due to whatever small detail, mistake, or misunderstanding from my side), so I found myself in need to filter the files through PHP code (yes, I know, let the web server deliver the static file contents). But until this will happen, I had to urgently improvise the code below.
The problem got solved by .htaccess-routing all the txt|png|jpeg|... to .mimeDelivery.php code (mentioned below).
The principle is that the script picks all the htaccessed mime types (as saved by cPanel in Perl store (serialized form). Perl deserialization algorithm is mentioned below.
1 files attached: Algorithm.php
Algorithm.php
Android - how to find the physical size of a display - using the DPI/PPI scale
Most of solutions found on internet compute the diagonal of the display by dividing the number of pixels to the DPI resolution. The capital mistake is that the DPI returns the dots per inch, and not the pixels. For this, you may use the scaledDensity to convert from DPI to PPI.
		float x=outMetrics.widthPixels/outMetrics.xdpi;
		float y=outMetrics.heightPixels/outMetrics.ydpi;
		double diag=Math.hypot(x, y);
		double physicalDiagonal=diag/outMetrics.scaledDensity;
		s+="Diag. logică: "+diag+";\n";
		s+="Diag. fizică: "+diag/physicalDiagonal+"\"";
Simple universal HTML client filter
A simple JS script for HTML client-side filtering of nodes:
function filterNodes(jQuerySet,value){
	value=(""+value).toUpperCase();
	var values=value.split(" ");
	var signs=[];
	for(var i=0;i<values.length;i++){
		if(values[i].charAt(0)=='!'){
			signs[i]=1;
			values[i]=values[i].substr(1);
		}
		values[i]=unescape(values[i]);
	}
	var nodes=jQuerySet;
	for(var i=0;i<nodes.length;i++){
		var nodeValue=nodes[i].innerHTML.toUpperCase();
		try{
			nodeValue=nodeValue.replace(/<[^>]+>/g, '');
		}catch(e){}
		$temporaryValue=1;
		if(value!='')
			for(var j=0;j<values.length;j++)
				if(values[j])
					if(signs[j]^(nodeValue.indexOf(values[j])<0)){
						$temporaryValue=false;
						break;
					}
		if($temporaryValue)
			$(nodes[i]).show();
		else
			$(nodes[i]).hide();
	}
}
How to request and generate authentication nonces via emails
Some clues on how to implement a fast ad-hoc authentication mechanism based on the email of the user.
  1. Publish a page where the user may request the ad-hoc token;
  2. On the ad-hoc page request the user to input the email address;
    • To avoid bot spamming you may generate the form field name based on a secret name stored on the server-side session;
    • As a consequence, the submitted form must always come as a response to a pre-exising server session, session that is not preserved using the classical curl libraries used by bots;
  3. An email with the nonce will be sent to the given address;
    • The nonce will be stored only on the server side, so the only way to know it is to open the email - which means that the user has access to the given mail;
  4. The user will put the nonce from mail in form; together with the nonce, the server will keep in session also the generation time;
Advantages:
  • nonce may be short, it does not have to be long and secure;
  • only the server side and the email address owner have access to nonce;
  • nonce cannot be reused if another one has been generated for that given session;
  • the mechanism guarantees that the owner of the mail address is the user of the page;
  • the user does not need any 3rd party credentials authority supplier.
Menu sample:
1 files attached: OpenIdAuthenticationProvider
OpenIdAuthenticationProvider
Emgu.CV video surveillance - part 2: how to keep only relevant images
One big issue in video surveillance is disseminating between relevant images and irrelevant images. For such comparison we need to compute the distance between two images, and for this a first step would be to bring images to only one relevant chanel, as example being:
  • luminosity channel - for comparing high resolution noiseless images;
  • crominance channel - when we have goot luminosity, but it changes over time;
Once we decide on the relevant channel for comparison, the next step is to filter the image (remove the noise). For this task I used the simple erode/dilate method mixed with median smoothing.
Once images are softened, I just compute the norm of the binary difference.
As seen in this code, I do run differences between thumbnails of images (which is much faster than the full image comparison.
Very important is that the value of threshold which is in my case 24 was not chosen randomly, but it is the one that gives best results on images both on day and night time.
To reach this value of 24 I ran tests on samples as following:
  • night time similar images;
  • night time small-difference images;
  • day time similar images;
  • day time small-difference images.
Even though the algorithm seems quite simple, it took me around one week to reach to it, as before I used various much more complex adaptive algorithms depending on other properties of images (including median luminance and noise quantity in image). At the end I reached to this very simple solution that brings the same quality but with much less code and much less complexity.
1 files attached: Campture.cs
Campture.cs
C#-Selenium bridge to automate browser application testing
Depending on the application under test and the technical restrictions you may need to test applications on different platforms. One solution is to use Selenium. However, a huge limitation of Selenium is that windows cannot be reused. In order to automate various browsers my recommended way is to plug Selenium in a host (C#, Java, Python, or whatever else).
Attached is a scripting engine I used to automate with Selenium over C#. As a precondition, you need to import in the project the browser connectors:
  • chromedriver.exe
  • IEDriverServer.exe
The Firefox connector comes out of the box with Selenium.
Another important component is the attached test set class.
This second class is the big thing in application, which will be able to parse files as in main.dms. Or, sample1.dms, and sample2.dms.
5 files attached: SeleniumWrapper.cs TestSet.cs test.dms sample1.dms sample2.dms
SeleniumWrapper.cs TestSet.cs test.dms
#browser ie
#on step.before step_before.js

#timeout 20
#include login.dms

#include client_sim_add-remove.dms
#include client_people.dms
sample1.dms
window.location="http://betalogin.mdmconsole.com";
UNTIL => (''+window.location).match('^http://hidden-url.com/')

##Login > input email, password
$('input#email') <= 'secret@example.com'
$('input#password') <= 'secret-password'
##Login > click Login
$CLICK => $('button:contains(\"Login\")')
##Console > Wait for "Logout" button to appear
UNTIL => $('button:contains(\"Logout\")').length==1
##Console > Log in as
$CLICK => $('button:contains("Log in as")')
##Console > Log in as > roles := client; userId:=SecretUser*
$CLICK => $('input#roles').siblings("img")
$CLICK => $('.x-combo-list-item:contains("Client")')
$CLICK => $('input[name="userID"]').siblings('input[value^="Akela"]')
##Console > Click "Log in"
$CLICK => $('#btnLogin button:contains("Log in")')
sample2.dms
##People
$CLICK => $('#nav-Endusers button:contains("People")')
##People > Add
$CLICK => $('table:contains("Export to CSV") button:contains("Add")')
##People > Add > first_name, last_name, email, owner language, pass1, pass2, Active:=true, Save
$(':contains("Person details") input[name="first_name"]') <= d2a('%EXECUTION_ID%FirstName')
$(':contains("Person details") input[name="last_name"]') <= d2a('%EXECUTION_ID%LastName')
$(':contains("Person details") input[name="email"]') <= d2a('e%EXECUTION_ID%@example.com')
$('#EditPersonWindow input#ownerLanguage') <= 'English'
$('#EditPersonWindow input#pass1') <= d2a('%EXECUTION_ID%')
$('#EditPersonWindow input#pass2') <= d2a('%EXECUTION_ID%')
$('#EditPersonWindow label:contains("Active:")').siblings().find("input") <= true
$CLICK => $('#EditPersonWindow button:contains("Save")')
UNTIL => $('#EditPersonWindow').length==0
C# Emgu.CV video surveillance - part 1: how to capture snapshots every few seconds
A sample application to capture every two seconds a photo with the video camera using Emgu.CV on C#.
1 files attached: EmguCapture.cs
EmguCapture.cs
using Emgu.CV;
using System.Collections;
using Emgu.CV.CvEnum;
using Emgu.CV.Util;
using Emgu.CV.Structure;
using Emgu.CV.Features2D;
using System;
using System.Drawing.Imaging;
using System.IO;
using System.Threading;

namespace ConsoleApplication2
{
	class Program
	{
		static void Main(string[] args)
		{
			if (args.Length!=0){
				if (args[0] == "start")
					CaptureStart();
				if (args[0] == "stop")
					CaptureStop();
			}
			Console.WriteLine("Capture start | stop");
		}
		public static void CaptureStart()
		{
			var signature = "" + new Random().Next();
			Config.set("capture-session", signature);
			Capture c = new Capture();
			c.SetCaptureProperty(CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 1024);
			c.SetCaptureProperty(CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 768);
			for (;;)
			{
				if (Config.get("capture-session") != signature) return;
				try
				{
					Thread.Sleep(3000);
					var thumbnail = c.QueryGrayFrame();
						Storage.Save(c.QueryFrame());
				}
				catch (Exception e)
				{
					Console.WriteLine(e.StackTrace);
				}
			}
		}
		public static void CaptureStop()
		{
			Config.set("capture-session", "");
		}
	}
}
How to put in Windows the timestamp (year, month, day, hour, and minute) in an environment variable
(for /f "tokens=2,3,4 delims=/ " %i in ('date /t') do set _YMDHM=%k-%j-%i)
(for /f "eol=P tokens=1,2 delims=: " %i in ('time /t') do set _YMDHM=%_YMDHM%-%i-%j)
The final result should be similar to:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\dsorescu>clear

C:\Users\dsorescu>(for /f "tokens=2,3,4 delims=/ " %i in ('date /t') do set _YMD
HM=%k-%j-%i)

C:\Users\dsorescu>set _YMDHM=2013-15-03

C:\Users\dsorescu>(for /f "eol=P tokens=1,2 delims=: " %i in ('time /t') do set
_YMDHM=%_YMDHM%-%i-%j)

C:\Users\dsorescu>set _YMDHM=2013-15-03-04-10

C:\Users\dsorescu>
SSL installation on Apache, and why SSL compression is A SECURITY HOLE
Some examples of how to install on Apache the certificates:
SSLCertificateFile /home/dsorescu/private/html/ssl/sorescu.eu.crt
SSLCertificateChainFile /home/dsorescu/private/html/ssl/sorescu.eu.pem #the CA file
SSLCertificateKeyFile /home/dsorescu/private/html/ssl/sorescu.eu.key
Most of people will also be tempted to enable the SSL comprssion as following:
SSLCompression on
Using compressed SSL poses a security leak very easy to understand and to exploit; the explaination is as following (all entities mentioned below are fictional and meant to ease the understanding of the method):
  1. your internet operator (or the IT department from your work) can listen to your compressed SSL requests (obviously they cannot decrypt them);
  2. the operator will modify your HTTP (non-secure) pages to include a small invisible image as following: <img src='https://dragos-matei.sorescu.eu/scrambled-image-name-freaky-url.png'/>;
  3. the network operator will measure the length of the browser request (the request will contain the cookies and the image fake url in a compressed and encrypted version);
  4. the network operator knows that once the url will contain repeating keywords (including passwords), the compressed SSL request will be shorter.
For this task to be successful, the operator (or your employer) should know a bit about which cookies the target site is using (this is not protected), and they have to use your browser to make lots of requests based on various possible passwords.
A way to ameliorate the speed of detection is to give up the brute force, but use orthogonal and white-noise techniques, which allows the attacker to send few very long requests with random information and see which of the requests is "closer" to your cookie values.
This works on the principle that the size of the compressed text decreases with the similarity of its components.
More details on: Short explanation from TheRegister.co.uk and Security.StackExchange.com.
Easy tool to query for IP details http://whois.net/ip-address-lookup/[IP_VALUE]
Often I was in need to know who is accessing my site. Aside the IP, I needed further information (like country or company owning the IP), and I found the following site very useful: http://whois.net/ip-address-lookup/[IP_VALUE] link.