Friday, August 20, 2010

Migration from MSSQL to MySQL

1. Fetch table schema from MSSQL

Script


#!/usr/bin/env ruby
require 'rubygems'
require 'dbi'
db = DBI.connect('dbi:ODBC:dbintegration', 'epres_amir', 'epres_amir8899')
select = db.prepare("select * from information_schema.columns where table_name = 'ref_course' order by ordinal_position")
select.execute
while rec = select.fetch do
puts rec.to_s
end
db.disconnect

Output:

["DBIntegration", "dbo", "REF_COURSE", "COURSEID", "1", nil, "No ", "varchar", 15, 15, nil, nil, nil, nil, nil, nil, "iso_1", nil, nil, "SQL_Latin1_General_CP1_CI_AS", nil, nil, nil]
["DBIntegration", "dbo", "REF_COURSE", "COURSE_CODE", "2", nil, "YES", "varchar", 15, 15, nil, nil, nil, nil, nil, nil, "iso_1", nil, nil, "SQL_Latin1_General_CP1_CI_AS", nil, nil, nil]
["DBIntegration", "dbo", "REF_COURSE", "COURSE_DESCBM", "3", nil, "YES", "varchar", 200, 200, nil, nil, nil, nil, nil, nil, "iso_1", nil, nil, "SQL_Latin1_General_CP1_CI_AS", nil, nil, nil]
["DBIntegration", "dbo", "REF_COURSE", "COURSE_DESCBI", "4", nil, "YES", "varchar", 200, 200, nil, nil, nil, nil, nil, nil, "iso_1", nil, nil, "SQL_Latin1_General_CP1_CI_AS", nil, nil, nil]
["DBIntegration", "dbo", "REF_COURSE", "CREDIT_HR", "5", nil, "YES", "numeric", nil, nil, true, "10", 2, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
["DBIntegration", "dbo", "REF_COURSE", "EXAM_COURSE", "6", nil, "YES", "varchar", 15, 15, nil, nil, nil, nil, nil, nil, "iso_1", nil, nil, "SQL_Latin1_General_CP1_CI_AS", nil, nil, nil]
["DBIntegration", "dbo", "REF_COURSE", "FACULTYID", "7", nil, "YES", "varchar", 15, 15, nil, nil, nil, nil, nil, nil, "iso_1", nil, nil, "SQL_Latin1_General_CP1_CI_AS", nil, nil, nil]
["DBIntegration", "dbo", "REF_COURSE", "ACTIVE", "8", nil, "YES", "varchar", 15, 15, nil, nil, nil, nil, nil, nil, "iso_1", nil, nil, "SQL_Latin1_General_CP1_CI_AS", nil, nil, nil]
["DBIntegration", "dbo", "REF_COURSE", "OWNERID", "9", nil, "YES", "varchar", 15, 15, nil, nil, nil, nil, nil, nil, "iso_1", nil, nil, "SQL_Latin1_General_CP1_CI_AS", nil, nil, nil]
["DBIntegration", "dbo", "REF_COURSE", "PROJECT_COURSE", "10", nil, "YES", "varchar", 15, 15, nil, nil, nil, nil, nil, nil, "iso_1", nil, nil, "SQL_Latin1_General_CP1_CI_AS", nil, nil, nil]
["DBIntegration", "dbo", "REF_COURSE", "FINAL_EXAM", "11", nil, "YES", "varchar", 15, 15, nil, nil, nil, nil, nil, nil, "iso_1", nil, nil, "SQL_Latin1_General_CP1_CI_AS", nil, nil, nil]
["DBIntegration", "dbo", "REF_COURSE", "EXAM_DURATION", "12", nil, "YES", "varchar", 15, 15, nil, nil, nil, nil, nil, nil, "iso_1", nil, nil, "SQL_Latin1_General_CP1_CI_AS", nil, nil, nil]
["DBIntegration", "dbo", "REF_COURSE", "COMMON_COURSE", "13", nil, "YES", "varchar", 15, 15, nil, nil, nil, nil, nil, nil, "iso_1", nil, nil, "SQL_Latin1_General_CP1_CI_AS", nil, nil, nil]
["DBIntegration", "dbo", "REF_COURSE", "COURSETYPE", "14", nil, "YES", "varchar", 15, 15, nil, nil, nil, nil, nil, nil, "iso_1", nil, nil, "SQL_Latin1_General_CP1_CI_AS", nil, nil, nil]
["DBIntegration", "dbo", "REF_COURSE", "COURSE_CATEGORY", "15", nil, "YES", "varchar", 1, 1, nil, nil, nil, nil, nil, nil, "iso_1", nil, nil, "SQL_Latin1_General_CP1_CI_AS", nil, nil, nil]
["DBIntegration", "dbo", "REF_COURSE", "COMMON_FAC", "16", nil, "YES", "varchar", 10, 10, nil, nil, nil, nil, nil, nil, "iso_1", nil, nil, "SQL_Latin1_General_CP1_CI_AS", nil, nil, nil]
["DBIntegration", "dbo", "REF_COURSE", "DATE_RELOAD", "17", nil, "YES", "datetime", nil, nil, true, nil, 3, "3", nil, nil, nil, nil, nil, nil, nil, nil, nil]

2. Create table in MySQL DB base on MSSQL schema

Script

require 'rubygems'
require 'active_record'

ActiveRecord::Base.establish_connection(
:adapter=> "mysql",
:host => "localhost",
:username => "sub_integration",
:password => "sub_integration",
:database=> "skt"
)

ActiveRecord::Schema.define do
create_table :subjects do |table|
table.string :COURSEID
table.string :COURSE_CODE
table.string :COURSE_DESCBM
table.string :COURSE_DESCBI
table.integer:CREDIT_HR
table.string :EXAM_COURSE
table.string :FACULTYID
table.string :ACTIVE
table.string :OWNERID
table.string :PROJECT_COURSE
table.string :FINAL_EXAM
table.string :EXAM_DURATION
table.string :COMMON_COURSE
table.string :COURSETYPE
table.string :COURSE_CATEGORY
table.string :COMMON_FAC
table.string :DATE_RELOAD
table.timestamps
end
end

3. Migration

Script:

#!/usr/bin/env ruby
require 'rubygems'
require 'dbi'
require 'active_record'


ActiveRecord::Base.establish_connection(
:adapter=> "mysql",
:host => "localhost",
:username => "sub_integration",
:password => "sub_integration",
:database=> "skt"
)

class Subject < db =" DBI.connect('dbi:ODBC:dbintegration'," select =" db.prepare('SELECT" rec =" select.fetch" subject =" Subject.new("> rec[0],
"COURSE_CODE" => rec[1],
"COURSE_DESCBM" => rec[2],
"COURSE_DESCBI" => rec[3],
"CREDIT_HR" => rec[4],
"EXAM_COURSE" => rec[5],
"FACULTYID" => rec[6],
"ACTIVE" => rec[7],
"OWNERID" => rec[8],
"PROJECT_COURSE" => rec[10],
"FINAL_EXAM" => rec[11],
"EXAM_DURATION" => rec[12],
"COMMON_COURSE" => rec[13],
"COURSETYPE" => rec[14],
"COURSE_CATEGORY" => rec[15],
"COMMON_FAC" => rec[15],
"DATE_RELOAD" => rec[16]
)
subject.save
end
db.disconnect

Tuesday, July 20, 2010

Accessing MSSQL with Ruby

1. unixODBC
wget http://www.unixodbc.org/unixODBC-2.3.0.tar.gz
tar vxfz unixODBC-2.3.0.tar.gz;cd unixODBC-2.3.0
./configure; make; make install
2. freedts
wget http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
tar vxfz freetds-stable.tgz; cd freetds-0.82
./configure --with-unixodbc=/usr/local ; make; make install
Database information
Server: 10.0.1.70
Database Type: MSSQL 2000
Database Name: dbintegration
Username: epres_amir
Password: epres_amir8899
Configuration File
1. /usr/local/etc/freetds.conf
[dbintegration]
host = 10.0.10.73
tds version = 7.0
port = 1433
2 /usr/local/etc/odbcinst.ini
[FreeTDS]
Description = FreeTDS unixODBC Driver
Driver = /usr/local/lib/libtdsodbc.so
Setup = /usr/local/lib/libtdsodbc.so
UsageCount = 1
3. /usr/local/etc/odbc.ini
[dbintegration]
Driver = FreeTDS
Description = ODBC connection via FreeTDS
Trace = No
Servername = dbintegration
Database = dbintegration
Testing Connection to DB
isql -v dbintegration epres_amir epre_amir8899
or
TDSVER=7.0 tsql -H 10.0.1.70 -p 1433 -U epres_amir -P epres_amir8899


Getting ruby to work with freeTDS

Install dbi & dbd-odbc/unixODBC
gem install dbi
gem install dbd-odbc
Sample ruby code
#!/usr/bin/env ruby
require 'rubygems'
require 'dbi'
db = DBI.connect('dbi:ODBC:dbintegration', 'epres_amir', 'epres_amir8899')
select = db.prepare('SELECT TOP 100 * FROM ref_course')
#return schema select * from information_schema.columns where table_name = 'ref_course' order by ordinal_position

select.execute
while rec = select.fetch do
puts rec.to_s
end
db.disconnect
Sample output
["OAD011", "OAD011", "MENAIP", "KEYBOARDING", #, "Y", nil, "1", "OM", "N", "Y", "60", "160", "KI", nil, "PEP", #]
["MAT225", "MAT225", "KEJURUTERAAN MATEMATIK III", "ENGINEERING MATHEMATICS III", #, "Y", nil, "1", "EM", "N", "Y", "180", "0", "KI", nil, nil, #]
["HRM551", "HRM551", "PENGURUSAN PERUBAHAN", "MANAGEMENT OF CHANGE", #, "Y", nil, "1", "BM", "N", "Y", "180", "160", "KI", nil, "PEP", #]
["ICM358", "ICM358", "INST FOOD SERVICE MGMT", "INST FOOD SERVICE MGMT", #, nil, nil, "0", "HM", "N", "N", nil, nil, "KI", nil, nil, #]
["IDE256-2", "IDE256", "STUDIO PRESENT .II", "STUDIO PRESENT .II", #, nil, nil, "0", "AD", "N", "N", nil, nil, "KI", nil, nil, #]
["IDE256-3", "IDE256", "STUDIO PRESENT.II", "STUDIO PRESENT.II", #, nil, nil, "0", "AD", "N", "N", nil, nil, "KI", nil, nil, #]
["LAW333", "LAW333", "SUPERVISED RESEARCH", "SUPERVISED RESEARCH", #, nil, nil, "0", "AL", "N", "N", nil, nil, "KI", nil, nil, #]
["LAW354", "LAW354", "CIV PROC DRAFTING II", "CIV PROC DRAFTING II", #, nil, nil, "0", "AL", "N", "N", nil, nil, "KI", nil, nil, #]

Saturday, July 03, 2010

Rails on windows

1. Installing ruby

http://rubyforge.org/frs/download.php/71078/rubyinstaller-1.9.1-p378.exe

2. Installing rails

C:\Users\amir>gem install rails
Successfully installed rake-0.8.7
Successfully installed activesupport-2.3.8
Successfully installed activerecord-2.3.8
Successfully installed rack-1.1.0
Successfully installed actionpack-2.3.8
Successfully installed actionmailer-2.3.8
Successfully installed activeresource-2.3.8
Successfully installed rails-2.3.8
8 gems installed
Installing ri documentation for rake-0.8.7...
Installing ri documentation for activesupport-2.3.8...
Installing ri documentation for activerecord-2.3.8...
Installing ri documentation for rack-1.1.0...
Installing ri documentation for actionpack-2.3.8...
Installing ri documentation for actionmailer-2.3.8...
Installing ri documentation for activeresource-2.3.8...
Installing ri documentation for rails-2.3.8...
Updating class cache with 0 classes...
Installing RDoc documentation for rake-0.8.7...
Installing RDoc documentation for activesupport-2.3.8...
Installing RDoc documentation for activerecord-2.3.8...
Installing RDoc documentation for rack-1.1.0...
Installing RDoc documentation for actionpack-2.3.8...
Installing RDoc documentation for actionmailer-2.3.8...
Installing RDoc documentation for activeresource-2.3.8...
Installing RDoc documentation for rails-2.3.8...

3. Installing SQLite3

First you will need to download two files from the Sqlite web site http://www.sqlite.org/download.html:

- http://www.sqlite.org/sqlite-3_6_23_1.zip
- http://www.sqlite.org/sqlitedll-3_6_23_1.zip

The first file is the Sqlite command line program used for modifing the Sqlite database. You may or may not use this.

The second file is the Windows DLL library file and Ruby uses this when Rails makes Sqlite database calls.

When both these ZIP files have been extracted you should have the following files:

  • sqlite3.exe
  • sqlite3.def
  • sqlite3.dll
Copy these file to the bin directory of your Ruby installation

gem install sqlite3-ruby

4. create a project

rails test
cd test
ruby script/server

Now you test page running on http://127.0.0.1:3000

Yeah

Monday, March 15, 2010

Diet in progress

Hi I'm on my diet program

15/03/2010 - exercise 7:40 p.m cycling, skipping

Tuesday, November 24, 2009

Well it was quite pain (as a newbie) installing Pico on FreeBSD, but heres how to do that quick.

Login to SSH as root.

Sometimes, direct root login is disabled. Do this then,

# su -
# password: [Enter your WHM root pass]
# [Hostname]: [Ready to work ]

To Download ports:
# /stand/sysinstall
- Go to Configure (post install)
- Go to Distributions
- Select 'ports'
- Select 'ok'
From there select FTP transfer (ftp.freebsd.org is ok) and it should download the ports into /usr/ports. When it's done, just exist sysinstall and run the commands I stated earlier.

It'll take a while to download.

after its finished downloading, do this:

# cd /usr/ports/editors/pico
# make install

and it'd install it for you.

DONE!!

Monday, November 02, 2009

Problem install rails with gem (debian)
============================

debian:~/rubygems-1.3.5# /usr/local/bin/gem install rails

/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/package.rb:10:in `require': no such file to load -- zlib (LoadError)

from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/package.rb:10:in `'

from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/format.rb:9:in `require'

from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/format.rb:9:in `'

from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:11:in `require'

from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:11:in `


Solution

=======

apt-get install libzlib-devel


then recompile your ruby and gems



Enjoy!!

Friday, October 23, 2009

Perl openSSL module installation problem
--------------------------------------------------
debian:/home/amir/Net-DNS-SEC-0.15# perl Makefile.PL
Warning: prerequisite Crypt::OpenSSL::Bignum 0.03 not found.
Warning: prerequisite Crypt::OpenSSL::DSA 0.1 not found.
Warning: prerequisite Crypt::OpenSSL::RSA 0.19 not found.
Writing Makefile for Net::DNS::SEC

I need to install all the dependencies.

Solution
======
sudo apt-get install libssl-dev
sudo perl -MCPAN -e "Crypt::OpenSSL::Bignum"

Below is the problem
==============
cpan[1]> install Crypt::OpenSSL::Bignum
CPAN: Storable loaded ok (v2.15)
Going to read '/root/.cpan/Metadata'
Database was generated on Fri, 23 Oct 2009 11:27:06 GMT
Running install for module 'Crypt::OpenSSL::Bignum'
Running make for I/IR/IROBERTS/Crypt-OpenSSL-Bignum-0.04.tar.gz
CPAN: Digest::SHA loaded ok (v5.47)
CPAN: Compress::Zlib loaded ok (v2.022)
Checksum for /root/.cpan/sources/authors/id/I/IR/IROBERTS/Crypt-OpenSSL-Bignum-0.04.tar.gz ok
Scanning cache /root/.cpan/build for sizes
............................................................................DONE
CPAN: Archive::Tar loaded ok (v1.54)
Crypt-OpenSSL-Bignum-0.04/
Crypt-OpenSSL-Bignum-0.04/Bignum/
Crypt-OpenSSL-Bignum-0.04/Bignum/CTX.pm
Crypt-OpenSSL-Bignum-0.04/LICENSE
Crypt-OpenSSL-Bignum-0.04/README
Crypt-OpenSSL-Bignum-0.04/Changes
Crypt-OpenSSL-Bignum-0.04/test.pl
Crypt-OpenSSL-Bignum-0.04/Makefile.PL
Crypt-OpenSSL-Bignum-0.04/META.yml
Crypt-OpenSSL-Bignum-0.04/typemap
Crypt-OpenSSL-Bignum-0.04/Bignum.pm
Crypt-OpenSSL-Bignum-0.04/Bignum.xs
Crypt-OpenSSL-Bignum-0.04/MANIFEST
CPAN: File::Temp loaded ok (v0.22)
CPAN: YAML loaded ok (v0.70)

CPAN.pm: Going to build I/IR/IROBERTS/Crypt-OpenSSL-Bignum-0.04.tar.gz

Checking if your kit is complete...
Looks good
Writing Makefile for Crypt::OpenSSL::Bignum
cp Bignum.pm blib/lib/Crypt/OpenSSL/Bignum.pm
cp Bignum/CTX.pm blib/lib/Crypt/OpenSSL/Bignum/CTX.pm
/usr/bin/perl /usr/share/perl/5.8/ExtUtils/xsubpp -typemap /usr/share/perl/5.8/ExtUtils/typemap -typemap typemap Bignum.xs > Bignum.xsc && mv Bignum.xsc Bignum.c
cc -c -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -DVERSION=\"0.04\" -DXS_VERSION=\"0.04\" -fPIC "-I/usr/lib/perl/5.8/CORE" -DPERL5 -DOPENSSL_NO_KRB5 Bignum.c
Bignum.xs:5:25: error: openssl/ssl.h: No such file or directory
Bignum.xs:6:24: error: openssl/bn.h: No such file or directory
Bignum.xs:21: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum__free_BN’:
Bignum.c:48: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:48: error: (Each undeclared identifier is reported only once
Bignum.c:48: error: for each function it appears in.)
Bignum.c:48: error: ‘self’ undeclared (first use in this function)
Bignum.c:51: error: expected expression before ‘)’ token
Bignum.xs: In function ‘XS_Crypt__OpenSSL__Bignum_new_from_word’:
Bignum.xs:46: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.xs:46: error: ‘bn’ undeclared (first use in this function)
Bignum.c:72: error: ‘RETVAL’ undeclared (first use in this function)
Bignum.xs: In function ‘XS_Crypt__OpenSSL__Bignum_new_from_decimal’:
Bignum.xs:59: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.xs:59: error: ‘bn’ undeclared (first use in this function)
Bignum.c:97: error: ‘RETVAL’ undeclared (first use in this function)
Bignum.xs: In function ‘XS_Crypt__OpenSSL__Bignum_new_from_hex’:
Bignum.xs:72: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.xs:72: error: ‘bn’ undeclared (first use in this function)
Bignum.c:122: error: ‘RETVAL’ undeclared (first use in this function)
Bignum.xs: In function ‘XS_Crypt__OpenSSL__Bignum_new_from_bin’:
Bignum.xs:85: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.xs:85: error: ‘bn’ undeclared (first use in this function)
Bignum.c:149: error: ‘RETVAL’ undeclared (first use in this function)
Bignum.xs: In function ‘XS_Crypt__OpenSSL__Bignum_zero’:
Bignum.xs:99: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.xs:99: error: ‘bn’ undeclared (first use in this function)
Bignum.c:173: error: ‘RETVAL’ undeclared (first use in this function)
Bignum.xs: In function ‘XS_Crypt__OpenSSL__Bignum_one’:
Bignum.xs:111: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.xs:111: error: ‘bn’ undeclared (first use in this function)
Bignum.c:197: error: ‘RETVAL’ undeclared (first use in this function)
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_to_decimal’:
Bignum.c:217: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:217: error: ‘self’ undeclared (first use in this function)
Bignum.c:222: error: expected expression before ‘)’ token
Bignum.xs:125: warning: assignment makes pointer from integer without a cast
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_to_hex’:
Bignum.c:242: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:242: error: ‘self’ undeclared (first use in this function)
Bignum.c:247: error: expected expression before ‘)’ token
Bignum.xs:136: warning: assignment makes pointer from integer without a cast
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_to_bin’:
Bignum.c:267: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:267: error: ‘self’ undeclared (first use in this function)
Bignum.c:275: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_get_word’:
Bignum.c:297: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:297: error: ‘self’ undeclared (first use in this function)
Bignum.c:302: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_add’:
Bignum.c:319: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:319: error: ‘a’ undeclared (first use in this function)
Bignum.c:320: error: ‘b’ undeclared (first use in this function)
Bignum.xs:168: error: ‘bn’ undeclared (first use in this function)
Bignum.c:327: error: expected expression before ‘)’ token
Bignum.c:330: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_sub’:
Bignum.c:353: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:353: error: ‘a’ undeclared (first use in this function)
Bignum.c:354: error: ‘b’ undeclared (first use in this function)
Bignum.xs:182: error: ‘bn’ undeclared (first use in this function)
Bignum.c:361: error: expected expression before ‘)’ token
Bignum.c:364: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_mul’:
Bignum.c:387: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:387: error: ‘a’ undeclared (first use in this function)
Bignum.c:388: error: ‘b’ undeclared (first use in this function)
Bignum.c:389: error: ‘BN_CTX’ undeclared (first use in this function)
Bignum.c:389: error: ‘ctx’ undeclared (first use in this function)
Bignum.xs:197: error: ‘bn’ undeclared (first use in this function)
Bignum.c:396: error: expected expression before ‘)’ token
Bignum.c:399: error: expected expression before ‘)’ token
Bignum.c:402: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_div’:
Bignum.c:425: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:425: error: ‘a’ undeclared (first use in this function)
Bignum.c:426: error: ‘b’ undeclared (first use in this function)
Bignum.c:427: error: ‘BN_CTX’ undeclared (first use in this function)
Bignum.c:427: error: ‘ctx’ undeclared (first use in this function)
Bignum.xs:212: error: ‘quotient’ undeclared (first use in this function)
Bignum.c:435: error: expected expression before ‘)’ token
Bignum.c:438: error: expected expression before ‘)’ token
Bignum.c:441: error: expected expression before ‘)’ token
Bignum.xs:218: error: invalid lvalue in assignment
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_sqr’:
Bignum.c:465: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:465: error: ‘a’ undeclared (first use in this function)
Bignum.c:466: error: ‘BN_CTX’ undeclared (first use in this function)
Bignum.c:466: error: ‘ctx’ undeclared (first use in this function)
Bignum.xs:229: error: ‘bn’ undeclared (first use in this function)
Bignum.c:471: error: ‘RETVAL’ undeclared (first use in this function)
Bignum.c:474: error: expected expression before ‘)’ token
Bignum.c:477: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_mod’:
Bignum.c:499: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:499: error: ‘a’ undeclared (first use in this function)
Bignum.c:500: error: ‘b’ undeclared (first use in this function)
Bignum.c:501: error: ‘BN_CTX’ undeclared (first use in this function)
Bignum.c:501: error: ‘ctx’ undeclared (first use in this function)
Bignum.xs:245: error: ‘bn’ undeclared (first use in this function)
Bignum.c:508: error: expected expression before ‘)’ token
Bignum.c:511: error: expected expression before ‘)’ token
Bignum.c:514: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_mod_mul’:
Bignum.c:536: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:536: error: ‘a’ undeclared (first use in this function)
Bignum.c:537: error: ‘b’ undeclared (first use in this function)
Bignum.c:538: error: ‘m’ undeclared (first use in this function)
Bignum.c:539: error: ‘BN_CTX’ undeclared (first use in this function)
Bignum.c:539: error: ‘ctx’ undeclared (first use in this function)
Bignum.xs:261: error: ‘bn’ undeclared (first use in this function)
Bignum.c:544: error: ‘RETVAL’ undeclared (first use in this function)
Bignum.c:547: error: expected expression before ‘)’ token
Bignum.c:550: error: expected expression before ‘)’ token
Bignum.c:553: error: expected expression before ‘)’ token
Bignum.c:556: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_exp’:
Bignum.c:577: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:577: error: ‘a’ undeclared (first use in this function)
Bignum.c:578: error: ‘p’ undeclared (first use in this function)
Bignum.c:579: error: ‘BN_CTX’ undeclared (first use in this function)
Bignum.c:579: error: ‘ctx’ undeclared (first use in this function)
Bignum.xs:277: error: ‘bn’ undeclared (first use in this function)
Bignum.c:584: error: ‘RETVAL’ undeclared (first use in this function)
Bignum.c:587: error: expected expression before ‘)’ token
Bignum.c:590: error: expected expression before ‘)’ token
Bignum.c:593: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_mod_exp’:
Bignum.c:614: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:614: error: ‘a’ undeclared (first use in this function)
Bignum.c:615: error: ‘p’ undeclared (first use in this function)
Bignum.c:616: error: ‘m’ undeclared (first use in this function)
Bignum.c:617: error: ‘BN_CTX’ undeclared (first use in this function)
Bignum.c:617: error: ‘ctx’ undeclared (first use in this function)
Bignum.xs:294: error: ‘bn’ undeclared (first use in this function)
Bignum.c:622: error: ‘RETVAL’ undeclared (first use in this function)
Bignum.c:625: error: expected expression before ‘)’ token
Bignum.c:628: error: expected expression before ‘)’ token
Bignum.c:631: error: expected expression before ‘)’ token
Bignum.c:634: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_mod_inverse’:
Bignum.c:655: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:655: error: ‘a’ undeclared (first use in this function)
Bignum.c:656: error: ‘n’ undeclared (first use in this function)
Bignum.c:657: error: ‘BN_CTX’ undeclared (first use in this function)
Bignum.c:657: error: ‘ctx’ undeclared (first use in this function)
Bignum.xs:310: error: ‘bn’ undeclared (first use in this function)
Bignum.c:662: error: ‘RETVAL’ undeclared (first use in this function)
Bignum.c:665: error: expected expression before ‘)’ token
Bignum.c:668: error: expected expression before ‘)’ token
Bignum.c:671: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_gcd’:
Bignum.c:692: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:692: error: ‘a’ undeclared (first use in this function)
Bignum.c:693: error: ‘b’ undeclared (first use in this function)
Bignum.c:694: error: ‘BN_CTX’ undeclared (first use in this function)
Bignum.c:694: error: ‘ctx’ undeclared (first use in this function)
Bignum.xs:326: error: ‘bn’ undeclared (first use in this function)
Bignum.c:699: error: ‘RETVAL’ undeclared (first use in this function)
Bignum.c:702: error: expected expression before ‘)’ token
Bignum.c:705: error: expected expression before ‘)’ token
Bignum.c:708: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_cmp’:
Bignum.c:729: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:729: error: ‘a’ undeclared (first use in this function)
Bignum.c:730: error: ‘b’ undeclared (first use in this function)
Bignum.c:735: error: expected expression before ‘)’ token
Bignum.c:738: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_is_zero’:
Bignum.c:754: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:754: error: ‘a’ undeclared (first use in this function)
Bignum.c:759: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_is_one’:
Bignum.c:775: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:775: error: ‘a’ undeclared (first use in this function)
Bignum.c:780: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_is_odd’:
Bignum.c:796: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:796: error: ‘a’ undeclared (first use in this function)
Bignum.c:801: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_copy’:
Bignum.c:817: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:817: error: ‘a’ undeclared (first use in this function)
Bignum.c:821: error: ‘RETVAL’ undeclared (first use in this function)
Bignum.c:824: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum_pointer_copy’:
Bignum.c:843: error: ‘BIGNUM’ undeclared (first use in this function)
Bignum.c:843: error: ‘a’ undeclared (first use in this function)
Bignum.c:850: error: expected expression before ‘)’ token
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum__CTX_new’:
Bignum.c:868: error: ‘BN_CTX’ undeclared (first use in this function)
Bignum.c:868: error: ‘RETVAL’ undeclared (first use in this function)
Bignum.c: In function ‘XS_Crypt__OpenSSL__Bignum__CTX__free_BN_CTX’:
Bignum.c:885: error: ‘BN_CTX’ undeclared (first use in this function)
Bignum.c:885: error: ‘self’ undeclared (first use in this function)
Bignum.c:888: error: expected expression before ‘)’ token
make: *** [Bignum.o] Error 1
IROBERTS/Crypt-OpenSSL-Bignum-0.04.tar.gz
/usr/bin/make -- NOT OK
Running make test
Can't test without successful make
Running make install
Make had returned bad status, install seems impossible
Failed during this command:
IROBERTS/Crypt-OpenSSL-Bignum-0.04.tar.gz : make NO

Monday, October 12, 2009

I wrote a module to get information about a domain(.my) in array.

run: ruby whoisex.rb opensource.my
will return i section in array:
Amir Haris Ahmad
OPENSOURCE DOTCOM
PT 72, SEKSYEN 65, TAMAN JELUTONG,
WAKAF CHE YEH
15100 KOTA BHARU
Kelantan
Malaysia
amirharis@yahoo.com
(Tel) 012-9522020
(Fax) -


script: whoisex.rb
============
require "whois"

whois = %x{whois #{ARGV}}

a = WHOIS::Get.new


r = a.record(whois, "i")

r.each_index do |i|
puts r[i].strip
end


The module
========
module WHOIS
class Get
def record(whois, type)
st = whois =~ /#{type} \[/
en = whois =~ /#{type.next} \[/
cut= whois.slice(st..en).split("\n")
cut.pop
cut.pop
cut.shift
cut.each_index do |i|
cut[i].chomp!
end
return cut
end
end
end

Enjoy!!!!

Sunday, September 13, 2009

Installing pine in Debian.

1) w3m ftp://ftp.cac.washington.edu/pine/pine_4.64_i386.deb

if you find any error e.g: pine: error while loading shared libraries: libssl.so.0.9.7: cannot open shared object file: No such file or directory

Just execute these commands:

$ sudo -s
# cd /usr/lib
# ln -s libcrypto.so.0.9.8 libcrypto.so.0.9.7
# ln -s libssl.so.0.9.8 libssl.so.0.9.7

rgds
Amir Haris

Tuesday, September 08, 2009

Xtool missing after upgrading to Snow Leopard.

After upgrading form Leopard to Snow Leopard, i cant use my gcc and other Xtool packages.

Solution:

First remove the old Xtool

sudo /Developer/Library/uninstall-dev --mode=all

Start time: Tue Sep 8 18:57:10 MYT 2009
Started uninstalling versioned non-relocatable developer tools content.
Shutting down distcc...
Shutting down dnbvolunteer...
Shutting down dnbobserver...
Shutting down recruiter...
Removing DNB files...
2009-09-08 18:57:12.458 pkgutil[841:903] PackageKit: *** Missing bundle identifier: /Library/Receipts/Flip4Mac QuickTime Components.pkg
2009-09-08 18:57:12.475 pkgutil[841:903] PackageKit: *** Missing bundle identifier: /Library/Receipts/Flip4Mac Web Plugins.pkg
2009-09-08 18:57:13.485 pkgutil[841:903] PackageKit: *** Missing bundle identifier: /Library/Receipts/Office2008_en_automator.pkg

After everything has been done. You can find Xtool package installer in Snow Leopard DVD, click to install latest version of Xtool..


cheers


rgds
Amir Haris Ahmad

Sunday, August 09, 2009

Reset MySQL root password


Step 1
root@amir:~# /etc/init.d/mysql stop

Step 2
root@amir:~# /usr/bin/mysqld_safe --skip-grant-tables &
[1] 6709
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6763]: started

Step 3
root@amir:~$ mysql --user=root mysql
Enter password:

mysql> update user set Password=PASSWORD('new-password') WHERE User='root';
Query OK, 2 rows affected (0.04 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

mysql> exit
Bye

Step 4
root@amir:~# /etc/init.d/mysql start
Starting MySQL database server: mysqld.

Step 5
root@amir:~# mysql --user=root --pass=new-password
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 5.0.24a-Debian_4-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> exit
Bye




Saturday, August 08, 2009

Installing rails in FreeBSD

I installed the following via the ports tree:

  • devel/subversion
  • devel/ruby-gems
  • databases/rubygem-activerecord
  • lang/ruby18
  • converters/ruby-iconv
gem18 install rails
For security reason, FreeBSD only allows su to root user,
if user is member of wheel group. Wheel group is a special group for administration purpose. Add your normal user to this group using pw command using following:
# pw user mod username -G wheel

So to add user amir to group wheel run command as follows:
# pw user mod amir -G wheel
# groups amir

amir wheel

Now su will work for amir.


You can disable this behavior complete for all users (not recommended until and unless you trust ALL of users):
1) Open pam configuration file for su using text editor:
# vi /etc/pam.d/su

2) Look for following line and comment it out:
Line:
auth requisite pam_wheel.so no_warn auth_as_self noroot_ok exempt_if_empty
Replace with:
#auth requisite pam_wheel.so no_warn auth_as_self noroot_ok exempt_if_empty

3) Now all users can use su command.

Sunday, May 10, 2009

Fix mysql database permission on OSX

just run

chmod -Rf 775 *

it will fix the mysql db permission
Compiling bind dlz
=============

I got problem when compiling bind with dlz + openssl

./configure --prefix=/usr/local/bind-zs/ --with-openssl=/usr/local/bind-zs/ --enable-threads=no --with-dlz-mysql=/Applicatioampp/xamppfiles/

Its return these errors during make:

gcc -g -O2 -I/usr/include/libxml2 -o named \
builtin.o client.o config.o control.o controlconf.o interfacemgr.o listenlist.o log.o logconf.o main.o notify.o query.o server.o sortlist.o statschannel.o tkeyconf.o tsigconf.o update.o xfrout.o zoneconf.o lwaddr.o lwresd.o lwdclient.o lwderror.o lwdgabn.o lwdgnba.o lwdgrbn.o lwdnoop.o lwsearch.o dlz_drivers.o sdlz_helper.o dlz_mysql_driver.o unix/os.o ../../lib/lwres/liblwres.a ../../lib/dns/libdns.a /usr/local/bind-zs//lib/libcrypto.a ../../lib/bind9/libbind9.a ../../lib/isccfg/libisccfg.a ../../lib/isccc/libisccc.a ../../lib/isc/libisc.a -L/Applications/xampp/xamppfiles//lib/mysql -lmysqlclient -lz -lcrypt -lm -L/usr/lib -lxml2 -lz -lpthread -licucore -lm
ld: library not found for -lcrypt
collect2: ld returned 1 exit status
make[2]: *** [named] Error 1
make[1]: *** [subdirs] Error 1
make: *** [subdirs] Error 1


The solution, compile with this command first:

./configure --prefix=/usr/local/bind-zs/ --with-openssl=/usr/local/bind-zs/ --enable-threads=no

without --with-dlz-mysql=/Applicatioampp/xamppfiles/

do make

than

reconfigure with

./configure --prefix=/usr/local/bind-zs/ --with-openssl=/usr/local/bind-zs/ --enable-threads=no --with-dlz-mysql=/Applicatioampp/xamppfiles/

rgds
Amir Haris@domainregistry.my

Thursday, April 23, 2009

I already test the usb random number generator Araneus Alea I with OSX (unix bsd).

After compiling the i found errors as below:

root:/Users/amir/linux$ make
cc randomfile.c -lusb -o randomfile
randomfile.c:16:17: error: usb.h: No such file or directory
randomfile.c: In function 'main':
randomfile.c:74: error: 'usb_busses' undeclared (first use in this function)
randomfile.c:74: error: (Each undeclared identifier is reported only once
randomfile.c:74: error: for each function it appears in.)
randomfile.c:74: error: dereferencing pointer to incomplete type
randomfile.c:75: error: dereferencing pointer to incomplete type
randomfile.c:75: error: dereferencing pointer to incomplete type
randomfile.c:76: error: dereferencing pointer to incomplete type
randomfile.c:77: error: dereferencing pointer to incomplete type
randomfile.c:84: warning: assignment makes pointer from integer without a cast
make: *** [randomfile] Error 1

I need to configure libusb to generate usb.h and other related header files.

I edit the Makefile and alter the parameter as below:
randomfile: randomfile.c
cc -I/opt/local/include -L/opt/local/lib \
randomfile.c -lusb -o randomfile

After that make it again:

cc -I/opt/local/include -L/opt/local/lib \
randomfile.c -lusb -o randomfile
randomfile.c: In function 'main':
randomfile.c:99: warning: pointer targets in passing argument 3 of 'usb_bulk_read' differ in signedness

Phew, ignore the error. Basically its no error, but warning. After successcully compile the .c file, one binary file generated called randomfile

Let test the tools:

./randomfile 1000 > random.hex

one file generated random.hex with these:

4968550d1a5de37609488a881d8252
1bbb383cc5505e8fff079bf9544f810da2a91e949c1980e70609de23d7296d0fdf51c602c08cba2e2badc91a3584516f40bfdc22c63776b1526be3ee6efe04
104671ad00e778778e652943d2bbb6969bce1fbfa72d68d3418e0ff6e331c105f6363bfa7db2c2d37f38000e31ccd332f646586f5f94d0ec87c050febe143f1e3403ed3133458950354f271475b6
ecde36645bfd64d4f9e9fdd86a2ebe2c317604bc8c10932f7fb18818443e110fd7411a20a0a474065f6b87ea3da8aace8879c2a036f18dc1562084f509c432e7aa550a433743f36632c51af83264
9569cff8b3ab2176763d72ae3b5a4086eff4066c3f006a3cfe20597e5d69825f34a25a0a56c1535582dc4ad7e9645b39b70f59e39514a27cc07fb9695d10f3bc11d82be107857691ce9605d0b1f0
c7098540611067253ea2cef2ef047594ca57b5aeda1a2e14d5586af6f1833bc7b8c4b7567029817b51bdc08467dc5ae0d35d91f449ad9da481b4a901e8d1500156e8a8541085773588694d8e4339
de635f5af7176f49cabe700ef516a2d5c7b7446e85c0736da35b9bd2eab4ef5817d5a3e17bb8ca0f1af89a27c2b45e229f3797561424fa69aba463864aafc1a68c5f3e6631b262ab613a6af615d4
990ced11a45f316e89c1c5d76210a01dfa93a9ebea3c447176757b43032abab7963a101dc0a8b668b173ae69e3c92f6d2ca0e6748b9e43e9e33953877813b8ff30989e5bfad3df86790ab49441ed
1ff02581a88b769af61f453d8055dd565c9279d4bd040b6e1d903461c39fe8c5c65f9c5d160245351f8f63c346dc0350a8a35a99e4a7d9e0b7a16f13631896f394533895fbc2412f5917642377bf
9ee741a231b796a3455d38b539089448cdac66c538f751f44edc28b64a70e5fbe0539a3f65877394c81298d194881f964858e8c6ac220e69cc1a057ebf7d6aaa3e4abe2f786151ca77a7c9ebfe3e
8a56a6e2fbe33e981905ef071f564157318a9304b3b42d4cdf1a8bf5f55bc7363f0000690fc7b43b829891d4fa31a9ace36701f92b3ddbd4342937d2376c9e74fcb6b8e0221e9e6d5b6bfce1de7a
d6a1b398e8b90ae4907d7bca30e1a33bed715573074325107d24d8dda122c631d4f7eaf16571c6ee30a18a62abfbbcfd8311229671e4fac2341e9a00526c39576967349ae2238f170f1647d88851
ae691d968c1acaac4997c124bf24e33ccaa248506f901003d5e549c01b16d9ac0a4e330d2f6f767ffabb2a488f294e7698f4c62d7995f766ef2efdff1eff96eaecb27b22eddbcb7a61af4cb2df4d
b19f6f91b71003bbe9ff3316300bb76bcf679e02dfd9b3aa37c2720f9bb51275ca157faef5e0302748ebb0d34f7d5573343dd23b5cdce514becf26bc8f862723

rgds
Amir Haris Ahmad

Monday, April 20, 2009



The simplest way to integrate the Alea I with dnssec-keygen is to use the "randomfile" program which is provided as C source on the Alea I driver CD, and pipe its output into the standard input of the dnssec-keygen program. For example, this command will generate a 2048-bit RSA zone key for the "my" TLD:

sudo randomfile -b | dnssec-keygen -r /dev/fd/0 -a RSASHA1 -b 2048 my.

Here, the "-b" causes the randomfile program to output the randomness in binary form (which is what dnssec-keygen expects), and the "-r /dev/fd/0" causes dnssec-keygen to read randomness from standard input instead of /dev/random. Note that the randomfile program needs to be run as root unless you set up specific udev rules to give non-root users permission to access the Alea I USB device.

amir@domainregistry.my

Friday, April 17, 2009

After a while:

Next week(24 April 2009 until 1 May 2009) I will be in Sabah & Sarawak. I will represent MyNIC BHD. as presenter to talk about Domain Name System Security Extention (DNSSEC). The audiences will be government and educational institution. See you all there. For more info please visit http://rnd.domainregistry.my

Monday, April 13, 2009

Command to check duplicate entries in mysql

SELECT DISTINCT(cource_code) AS cource, COUNT(cource_code) AS Count FROM kursus_psmb GROUP BY cource_code HAVING Count > 1

Thursday, April 09, 2009

Remove all .svn folders in a directory

find
. -name ".svn" -type d -exec rm -rf {} \;