Javascript Encryption

jCryption, is simply Javascript Encryption. “j” stands for jQuery as core framework. And as always, everybody likes jQuery.

Normally if you submit a form and you don’t use SSL, your data will be sent in plain text.
But SSL is neither supported by every webhost nor it’s easy to install/apply sometimes.
So I created this plug-in in order that you are able to encrypt your data fast and simple.
jCryption uses the public-key algorithm of RSA for the encryption.

Author’s site had a good documentation on usage.

Quick and Dirty, and yet Tidy

I just got the title from the source, read it yourself :)

This options worked for me! I’ve been having trouble trying tidy on my CMS. But it only renders tidy’ed the content inside <body> and worst, everything outside it are stripped off – no title, and meta’s neither opening and closing html

$config = array(
  'indent'      => true,
  'output-xml'  => true,
  'input-xml'   => true,
  'wrap'        => '1000'
);

For detailed options and their uses, look at their quickref

Quickie OOP

Just dropping quickly here, and wanting to share a little and yet important part of software development, in web or in any platform.

I believe it is always nice to have a property in your object (or class) to hold the latest error encountered or latest command executed. Sort of like this

class test1
{
  var $last_error;
  var $last_cmd;
  // some other properties here
  function test1()
  {
    // other codes here
  }
  /**
   * the "why" for this class
   */
  function execute()
  {
    $command = $this->get_command();
    $this->last_cmd = $command;
    system($command, $res);
    if ($res)
    {
      $this->last_error = $res;
      return false;
    }
    return true;
  }
}

I realize the need for these two properties when I was debugging the CMS I was working on. It involved GraphicsMagick to process resizing, cropping and sharpening image, and executed thru PHP exec or system functions. I forgot why I arrived at using exec over the other. What I did was include these two properties in the log thru a logger method of another class in the system, which indeed, helped me get back to my sanity :D .

Fix for pidgin not connecting to Yahoo

update: scsa.msg.yahoo.com seems to work now. This is the default address in 2.5.8 for Ubuntu and Windows versions.

After a few search terms finding what’s going on recently with pidgin that it’s unable to connect to Yahoo. I found a correct temporary fix

using the page server: cn.scs.msg.yahoo.com instead of scs.msg.yahoo.com did the trick.


Basic and efficient MySQL statement

Update only columns that has changed.

Its tedious to compare old column values against the new being submitted before adding the column in the query statement. But, most of the articles I read says its the most efficient.

+---------------+--------------------------+-----------------+
| username      | email                    | lastip          |
+---------------+--------------------------+-----------------+
| admin         | admin@google.com.ph      | 127.0.0.1       |
+---------------+--------------------------+-----------------+

In this example, current $row["email"] is compared to request $email value

/* repeat this test in every column in your table */
if ($row["email"] != $email)
{
  $columns[] = "email = '$email'";
}
/* constructed sql statement would be */
$sql = "update customer set email = '$email' where username = 'admin'";

Another advantage following this convention is when there are multiple users accessing the same row. Though it sounds impossible that same row is updated at an exact same time, unless your site tops google on ranking. And even so, your SQL operation would have saved a little less resource than usual.

On-the-fly Blueprint CSS

Ok, I think there’s more to Blueprint CSS than fixed width designs. Somebody already came up with the liquid version.

So I think I’d spend some time adapting this generator and pass the four parameters needed to calculate the grid.

<script src="/getblueprint.php?width=950&cols=24&colwidth=30&margin=10"></script>

or perhaps a mode parameter to set px or percent as values

<script src="/getblueprint.php?mode=px&width=950&cols=24&colwidth=30&margin=10"></script>

Breaking the silence

So, I haven’t really got time posting stuff here. Its because I’ve been trying to finish my new site after my day job. It is called swerteka.com, and I’m gonna give it as free ad posting service.

But it’s still a long way to go, and it will be loaded by the CMS script I’ve been working on.

Zone Update Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
 * ipupdate.php
 *
 * @author marvin@marvinmarcelo.com
 *
 * Update script zoneedit.com
 */
$lookupserv = array(
  "http://www.whatismyip.com/tools/ip-address-lookup.asp",
  "http://www.hostip.info/",
  "http://www.tracemyip.org/index.php",
  "http://www.kloth.net/services/dig.php",
  "http://www.ip2location.com/"
);
// file where html source from wget
$tmpfile = "/home/youraccountpath/.updatezone/html";
// IP lookup site
$iplookupurl = $lookupserv[rand(0, 4)];
// file to hold current IP
$ipfile = "/home/youraccountpath/.updatezone/ip";
// logging
$logfile = "/home/youraccountpath/.updatezone/log";
 
$log = fopen($logfile, "a");
 
fwrite($log, "[" . date("Y-m-d H:i:s") . "] " . __FILE__ . " started \n");
 
exec("/usr/bin/wget -O - $iplookupurl > $tmpfile");
 
fwrite($log, "[" . date("Y-m-d H:i:s") . "] wget $iplookupurl \n");
 
$html = join("", file($tmpfile));
 
if(preg_match('/\b(?:\d{1,3}\.){3}\d{1,3}\b/', $html, $matches))
{
  $ip = $matches[0];
  fwrite($log, "[" . date("Y-m-d H:i:s") . "] QUERY $ip\n");
  if(!file_exists($ipfile))
  {
    file_put_contents($ipfile, "[nothing]");
  }
  $oldip = trim(join("", file($ipfile)));
  if($ip != $oldip)
  {
    $fp = fopen($ipfile, "w");
    fwrite($fp, $ip);
    fclose($fp);
    $u = base64_decode("hashedusername"); /* username */
    $p = base64_decode("hashedpassword"); /* password */
    exec("/usr/bin/lynx -source -auth=$u:$p 'http://dynamic.zoneedit.com/auth/dynamic.html?host=mydomain.com'");
    fwrite($log, "[" . date("Y-m-d H:i:s") . "] UPDATED from $oldip to $ip\n");
  }
  fclose($log);
}

ZoneEdit is free. I think, that’s 5 zones for free account.

You might also need to install lynx and php5-cli, just type this in the shell, if you’re privileged to do so.

sudo apt-get install lynx php-cli