Teknober Blog

Blog

Follow me on TwitterRSS Feeds

  • Home
  • About
  • Updates

OpenSSL loading openssl.cnf

Feb 8th

Posted by editor in ASP.Net

since the openssl.cnf path is hardcoded in binaries. to alter it on windows set environmental variable (as written):

OPENSSLDIR=C:\PATH\TO\OpenSSL\bin
OPENSSL_CONF=C:\PATH\TO\OpenSSL\bin\openssl.cnf

OPENSSL_CONF doesn’t work without OPENSSLDIR even if it is set.

settings these options will allow you to use your custom configuration files when creating certificates.

batch file i use to create certificate

GenCERT.bat [save this file to OpenSSL bin directory]

@echo off 

md %1

openssl genrsa -des3 -out %1/%1.key 1024

openssl req -new -key %1/%1.key -out %1/%1.csr

copy %1/%1.key %1/%1.key.org

openssl rsa -in %1/%1.key.org -out %1/%1.key

openssl x509 -req -days 365 -in %1/%1.csr -signkey %1/%1.key -out %1/%1.crt

openssl x509 -outform der -in %1/%1.crt -out %1/%1.der

Sample

:: Start command line and cd to C:\PATH\TO\OpenSSL\bin
::
:: usage: GenCERT.bat domain.com
::

GenCERT.bat teknober.com

Batch file I use to create SSL certificate for Web etc server

GenPEM.bat [save this file to OpenSSL bin directory]

@echo off

mkdir %1

openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout %1/%1.pem -out %1/%1.pem -config "%1/%1.cfg"

Sample

:: Start command line and cd to C:\PATH\TO\OpenSSL\bin
::
:: usage: GenPEM.bat domain.com
::

GenPEM.bat teknober.com

for sample ssl configuration file see the bottom of the page: http://www.openssl.org/docs/apps/ca.html

openssl, openssl config, openssl generate certificate, unable to load openssl.cnf

PDO PDOStatement with Select Find, Skip, Take

Jan 13th

Posted by editor in C

Currently working on extending PDOStatement at C level which will allow to use select, join, where, order, group, find, skip, take commands in chain.

the usage will be like:

/* Extended PDO */
$pdo = new PDO(/* dsn */);

$pdo->select('table_x')->find(array('id' => 1));

/* using alias */
$pdo->select('table_x as a')->find(array('a.id = ?'))->bind(array(1));

$pdo->select('table_x', array('table_x.id', 'table_y.name', 'table_y.description')->join_left('table_y', array('table_x.id = table_y.id'))->findAll();

/*
--output type (single)
-- find()          => PDORow
-- findToCSV()     => comma seperated values
-- findToTDV()     => tab delimeted values
-- findToJSON()    => json string
-- findToXML()     => xml string

--output types (multiple)
-- findAll()       => array
-- findAllToCSV()  => comma separated values
-- findAllToTDV()  => tab delimited values
-- findAllToJSON() => json string
-- findAllToXML()  => xml string
*/

$pdo->select('table_x', array('table_x.id', 'table_y.name', 'table_y.description')->join_left('table_y', array('table_x.id = table_y.id'))->findAllToCSV();
$pdo->select('table_x', array('table_x.id', 'table_y.name', 'table_y.description')->join_left('table_y', array('table_x.id = table_y.id'))->findAllToTDV();
$pdo->select('table_x', array('table_x.id', 'table_y.name', 'table_y.description')->join_left('table_y', array('table_x.id = table_y.id'))->findAllToJSON();
$pdo->select('table_x', array('table_x.id', 'table_y.name', 'table_y.description')->join_left('table_y', array('table_x.id = table_y.id'))->findAllToXML();

If you have any suggestions  on adding more commands please let me know

extented pdo, pdo, pdo select skip take, pdo select where, pdo statement, PHP PDO

VMWare on Debian 6 with Linux-Kernel-2.6.32-5

Jan 7th

Posted by editor in Administration

Installing VMware WorkStation 8 on Debian 6 with Linux-Kernel-2.6.32-5 AMD64

error log: Can’t locate linux headers

apt-get install linux-headers-2.6.32-5-all
apt-get install linux-headers-2.6.32-5-all-amd64
apt-get install linux-headers-2.6.32-5-common

error log: Can’t get required utilities make, tar, echo, grep, rmmod, insmod

apt-get install dpkg-dev

Compile vmware modules before running.

vmware, vmware 8 on debian, vmware linux kernel

JavaScript Object Push method

Dec 12th

Posted by editor in Development

here is object.push or json.setNode method i implemented for my needs. the name of the function is not ‘push’ because push method used in Array which is a subset of Object.

Sample:

var test = { };

test.setNode("path.to.your.variable", "my value");

// result:
// alert(test.path.to.your.variable);
//
// will return 'my value'

Code:

Object.prototype.setNode = function(_key, _value) {
	var module = this;
	var spaceArray = _key ? _key.split('.') : [];
	var subSpace = null;
	var ndx = null;

	for (ndx = 0; ndx < spaceArray.length - 1 && (subSpace = spaceArray[ndx]); ++ndx) {
		if (subSpace) {
			if (!module[subSpace]) {
				module[subSpace] = {};
			}

			module = module[subSpace];
		}
	}

	subSpace = spaceArray[ndx];
	module[subSpace] = _value;

	return this;
};
javascript, json, json set node, object push method

PHP PDO using Transactions with TModel::GenerateStatement functions

Sep 9th

Posted by editor in Administration

Only have an example to show using the TModel::GenerateInsertStatement, TModel::GenerateUpdateStatement, TModel::GenerateReplaceStatement

In database driver settings for mysql innodb engine, mariadb aria engine: SET AUTOCOMMIT=0;

sample:

public function panel_set_category_enabled($id_category) {
	/* start a transaction */
	$this->model->beginTransaction();

	/* set: populate related columns */
	$columns = array();

	$columns[] = new TModelColumn("enabled", 1, PDO::PARAM_INT);
	$columns[] = new TModelColumn("date_update", TDate::getDATE_MYSQL(time()), PDO::PARAM_STR);

	/* execute and return result */
	$result = TModel::generateUpdateSet("tc_category", $columns, new TModelWhere("id", $id_category, PDO::PARAM_INT, null, "="), true);

	if ($result) {
		$this->model->commit();
		return $result;
	} else {
		$this->model->rollBack();
		return $result;
	}
}

related articles on this blog:

PHP PDO Generate Insert Statement:

http://blog.teknober.com/2011/03/06/php-pdo-generate-insert-statement/

PHP PDO Generate Update Statement:

http://blog.teknober.com/2011/03/06/php-pdo-generate-update-statement/

PHP PDO Generate Replace Statement:

http://blog.teknober.com/2011/04/13/php-pdo-generate-replace-statement/

mysql start transaction, PHP PDO, php pdo begin transaction

PHP TNullClass using IteratorAggregate

Sep 8th

Posted by editor in Development

This class implemented to return null especially when the variable does not exists to avoid exceptions

Sample:

if (TRequest::inPost(array("category", "product")) == true) {
	$post_category = $this->validate_category(TRequest::fromPostObject("category"));
	$post_product  = $this->validate_product(TRequest::fromPostObject("product"));

	/* your code here to */
	//print $post_category->name;
}

to use this with GET/POST/COOKIE/SERVER etc, you need to transform the array into TNullClass object using the following function

/**
 * Transforms Array to stdClass
 * @param mixed $object
 * @return stdClass
 */
function array_to_nullclass($object) {
	$result = new TNullClass();

	if (is_array($object) === true) {
		foreach ($object as $key => $value) {
			$result->{$key} = $value;
		}
	}

	return $result;
}

TNullClass.php

<?php
/* ----------------------------------------------------------------------------
 * Teknober Web Services - All rights reserved
 * ----------------------------------------------------------------------------
 * File Name    : TNullClass.php
 * Section      : TNullClass
 * Dependicies  :
 * Description  : Implements TNullClass class
 *              : Special class implemented to return null when the variable
 *                does not exists to avoid exceptions
 * ----------------------------------------------------------------------------
 * Author       : Fatih Piristine
 * Company      : Teknober Web Services
 * E-mail       : v-fpiris@teknober.com
 * Web          : http://www.teknober.com
 * ----------------------------------------------------------------------------
 * $LastChangedBy$
 * $LastChangedDate$
 * $LastChangedRevision$
 * $HeadURL$
 * -------------------------------------------------------------------------- */

/**
 * TNullClass Class
 */
class TNullClass implements IteratorAggregate {
    public function getIterator () {
        return new ArrayIterator($this);
    }

    public function __get($index) {
        if ($this->exists($index) == false) {
            $this->{$index} = null;
        }

        return $this->{$index};
    }

    public function __set($index, $value) {
        $this->{$index} = $value;
    }

    public function exists($index) {
        return isset($this->{$index});
    }

    public function extend(TNullClass $object) {
        foreach ($object as $key => $value) {
            $this->{$key} = $value;
        }

        return $this;
    }

    public function isnull($index) {
        return is_null($this->{$index});
    }

    public function validate($index, $pattern) {
        return preg_match($pattern, $this->{$index});
    }

    public function length($index) {
        return strlen($this->{$index});
    }

}
php get object, php IteratorAggregate, php post object, php server object

PHP Validating HTML Class using regular expression

Sep 7th

Posted by editor in Development

Validating HTML Class on the fly to pass W3C validation to get valid html.

W3C format for HTML Classes: abc or a12 or a_1 [first character is always required to be letter, no commas, semi-colons are allowed]

if (preg_match("/(^[a-z]{1}([a-z0-9_-\s])+)$/", $html_class)) {
    $tag->setAttribute("class", $html_class);
}
php html class validation, php html validation, w3c html class format

PHP Validate HTML ID using regular expression

Sep 6th

Posted by editor in Development

Validating HTML ID on the fly to pass W3C validation to get valid html.

W3C format for HTML IDs: abc or a12 or a_1 [first character is always required to be letter, no spaces, commas, semi-colons are allowed]

if (preg_match("/(^[a-z]{1}[a-z0-9_]+)$/", $html_id)) {
    $tag->setAttribute("id", $html_id);
}
php html id validation, php html validation, w3c html id format

PHP PDO Using reserved words as column names

Jun 25th

Posted by editor in Development

Using reserved words as columns names causes problems on insert/update/replace while there is no problem with select.

/* this will not work and will throw no exception */
$result = $model->prepare("update mytable set default = 1");
$result->execute();

/* this will work */
$result = $model->prepare("update mytable set `default` = 1");
$result->execute();
pdo sql reserved words in columns, pdo statement reserved words, PHP PDO

PHP PDO Statement Object with CSV and JSON

Jun 25th

Posted by editor in Development

Implements generic object for PHP PDO

sample:

class TableModel {
    private $model = null;

    public function __construct($model) {
        $this->model = &$model;
    }

    public function get_table($id = null) {
        $result = $this->registry->model->prepare("select a.* from table as a where a.id = ?");
        $result->bindParam(1, $id, PDO::PARAM_INT);
        $result->setFetchMode(PDO::FETCH_CLASS, 'TModelRow');
        $result->execute();
        return $result->fetchAll();
    }
}

$model = new PDO(...);
$table_model = new TableModel($model);
$rows = $table_model->get_table(93);

foreach ($rows as $row) {
   print_r($row->toArray());
   echo $row; // is equivalent to $row->toJSON();
   echo $row->toJSON();
   echo $row->toTSV();
   echo $row->toCSV(); // triggers error because not implemented!
}

(more…)

csv, json, pdo statement, pdo statement fetch class, pdo statement fetch object, pdo statement generic object, PHP PDO, TModelRow
12345»
    • Recent comments
    • Popular posts
    • Archives
    • Tags
    • Categories
    • Administration (16)
      • Database Servers (3)
        • Cassandar NoSQL (1)
        • MariaDB Server (2)
        • Micsoft SQL Server (1)
        • MySQL Server (3)
      • DNS Servers (1)
        • Bind (1)
        • Microsoft DNS (1)
      • GIT (1)
      • OpenSSL (1)
      • SVN (2)
      • VMWare (1)
      • Web Servers (10)
        • Apache HTTPd (9)
        • Internet Information Services (4)
      • Windows Servers (3)
    • Development (39)
      • ASP.Net (5)
      • C (3)
      • CSharp (1)
      • CSS (2)
      • HTML (6)
      • JavaScript (7)
        • JSON (1)
      • PHP (27)
        • PDO (8)
      • SQL (7)
      • VBScript (2)
    apache array array_keys backup builder class clear collection configuration cookies dns dom element enabled error eventlogs file generic get header html http iis ip javascript json log mysql object pdo pdo statement php php html validation PHP PDO port select size skip startup statement stdClass string take vbscript windows
    • February 2012 (1)
    • January 2012 (2)
    • December 2011 (1)
    • September 2011 (4)
    • June 2011 (4)
    • May 2011 (3)
    • April 2011 (5)
    • March 2011 (6)
    • February 2011 (1)
    • January 2011 (20)
    • PHP PDO Statement Object with CSV and JSON (0)
    • PHP PDO Using reserved words as column names (0)
    • PHP Validate HTML ID using regular expression (0)
    • PHP Validating HTML Class using regular expression (0)
    • PHP TNullClass using IteratorAggregate (0)
    • PHP PDO using Transactions with TModel::GenerateStatement functions (0)
    • JavaScript Object Push method (0)
    • Windows EventLogs Backup (0)
    • Windows EventLogs Clear (0)
    • VMWare on Debian 6 with Linux-Kernel-2.6.32-5 (0)
  • Partners

    • AcemCity Turizm Taşımacılık Organizasyon
    • Acemoglu Tur – Personel Tasimaciligi ve Servis Hizmetleri
    • Piristine KFT
    • Teknober Web Services
Copyright © Teknober
LinkedIn LinkedIn Twitter Twitter Skype Skype
grab this