Minggu, 27 Maret 2011

Using MongoDB and CodeIgniter On Windows


Installing MongoDB


First of all, you need to download MongoDB binary file for windows. You can get these from here. After the download is completed, create a new directory 'C:\data\db'. It is needed as default to store your database. Then, call the command prompt. If you are using Windows 7 as you OS, don't forget to run cmd as administrator. If you don't do this, then the installation won't start.

Type command "fullpath_to_your_mongod.exe_file --install --logpath path_to_log". For example, I have all extracted files on D:\data\installer\mongodb\, so I type "D:\data\installer\mongodb\bin\mongod --install --logpath C:\data\log". I used 'C:\data' directory for the logpath and 'log' as the file name.

At this point, you have successfully installed mongoDB on your machine. Now, you need to get it started. Get the service start by typing 'net start "MongoDB"'. Or alternatively, you can just start the service from services.msc. Find Mongo DB and start the service.

Congratulations ! You have properly installed MongoDB on your computer. To test the database, you can run mongoDB client. Run from command prompt "D:\data\installer\mongodb\mongo". This time, it's okay if you don't run command prompt as administrator. Test any mongodb command there. Here you can get references for MongoDB shell command.

Setting PHP driver

After things with MongoDB are settled, it's time to set MongoDB driver for PHP. Don't worry, this is simple. First, you have to download driver here. Download the correct driver for your environment. At the time this article is created, I downloaded mongo-1.1.4.zip. You will see a lot of file when you extract the file. I'll help you to choose the correct file :
1. VC6 is for Apache (VC9 is for IIS)
2. Thread safe(ts) is for running PHP as an Apache module, non thread safe is for CGI
For me, I'm using apache with php 5.3 installed. Therefore, I'm using 'mongo-1.1.4-php5.3vc6ts'.
Simply copy 'php_mongo.dll' to your 'xampp/php/ext' directory and add 'extension=php_mongo.dll' to your php.ini file. Restart the server and there you go.

Test MongoDB with CodeIgniter

Now, let's take a look on how using MongoDB with CodeIgniter. First, create a controller file and add these lines to your controller's constructor :
// Connect to Mongo
$connection = new Mongo('localhost:27017');

// Select a database
$db = $connection->db_name;

// Select a collection
$books = $db->books;

Now, your controller file should look like this :

class Test extends Controller {

function __construct()
{
parent::Controller();
// Connect to Mongo
$connection = new Mongo('localhost:27017');

// Select a database
$db = $connection->db_name;

// Select a collection
$books = $db->books;
}

function index()
{

}
}

Now, save the file and type 'http://servername/index.php/test' on your browser.
If you see nothing, then it works !
Congratulations ! I'll add more on updating data on my other post.
Enjoy, and thank you guys!

Rabu, 28 April 2010

[II3062]Mencari identitas

Dikisahkan Anda diteror oleh seseorang di rekening Facebook Anda. Misalnya Anda menerima message dari orang yang tidak dikenal secara berulang-ulang, atau orang tersebut menuliskan pesan yang tidak bertanggung jawab. Bagaimana Anda mengetahui siapa orang ini?

Dalam kasus lain, Anda diminta untuk mencari tahu siapa yang membuat sebuah group tanpa ikut menjadi anggota dari group tersebut. Bagaimana caranya?

Singkatnya Anda diminta untuk melakukan investigasi terhadap rekening facebook. Uraikan ide-ide Anda.

Selasa, 13 April 2010

Using xampp 1.7.1 with Oracle 10g on Windows XP

I successfully set XAMPP 1.7.1 with Oracle 10g Express Edition.
These are the configurations :
- open php.ini
- register_global ON
- short_open_tag = On
- uncomment extension=php_oci8.dll
- uncomment extension=php_oracle.dll
At this point you might get an error :
httpd.exe Entry Point Not Found
the procedure entry point nzssGEBV_GetEntryByValue could not be located in the dynamic link library orannzsbb10.dll
To fix this, simply delete the files oci.dll, ociw32.dll and orannzsbb10.dll in \xampp\php and \xampp\apache\bin.

Hope this helps and saves somebody's time.

Minggu, 11 April 2010

[II3062]Latihan Menyadap Jaringan

Kembali lagi dengan tugas kuliah Keamanan Informasi. Tugas kali ini berhubungan dengan sadap-menyadap :

Anda diminta untuk menggunakan program sniffer (penyadap) seperti wireshark, tcpdump, atau sejenisnya untuk melakukan salah satu dari hal di bawah ini:

  1. mengukur jumlah data yang digunakan untuk membuka satu sesi gmail atau facebook;
  2. memantau serangan dari port scanning yang dilakukan dengan menggunakan program nmap.
Kali ini saya akan coba menyelesaikan tugas yang pertama menggunakan program wireshark.
Apa itu wireshark? Wireshark digunakan untuk menganalisis paket-paket yang keluar masuk dalam jaringan. Pada kesempatan kali ini saya kana mencoba mengukur jumlah data yang digunakan untuk membuka satu sesi account gmail saya.
Pertama-tama, buka wireshark kemudian pilih capture->options. Untuk interface saya pilih fast ethernet adapter kemudian masukkan capture filter :
host 192.168.1.2 and host www.gmail.com

Saya memasukkan 192.168.1.2 sebagai ip address saya dan www.gmail.com sebagai situs yang ingin saya pantau paketnya. Klik start setelah melakukan konfigurasi. Pertama-tama, layar wireshark akan berisi paket seperti ini.



Ketika saya mulai mengetikkan username dan password, entri-entri paket pada wireshark langsung bertambah. Hal ini berarti gmail melakukan pengecekan username dan password bahkan sebelum user mengeklik tombol login.


Setelah berhasil login, saya pun melakukan logout terhadap account gmail saya. Saya tunggu sampai paket berhenti mengalir dan klik statistics -> summary. Hasilnya :


Bisa kita lihat jumlah paket data dalam satu sesi sebanyak 758 paket sebesar 525 kB dengan rata-rata 3,863 paket per detik dengan ukuran 693,871 bytes per paket.
Semoga bermanfaat!

Jumat, 09 April 2010

Uninstall Oracle 10g Secara Manual

Wew, pengalaman dapet proyek PHP-Oracle dimulai dengan pengalaman buruk.. Begini kronologisnya :
Saya menginstall Oracle 10G XE pada Windows XP tapi hang di tengah-tengah proses. Saya mencoba menghapus tapi tidak bisa. Mau install ulang keluar warning :
default database listener port, 5521, currently in use.
Saya coba googling-googling untuk mencari solusi.. Akhirnya ketemu beberapa potong kalimat :
Early versions of the XE installer had various cases where it would do nothing, or would hang, or just exit without messages part way through, so it's possible you've hit one of these.
Kesimpulannya : banyak yang mengalami kejadian seperti saya :|

Usut punya usut, Oracle tidak bisa dihapus karena menyebarkan 'tentakel-tentakel'-nya di banyak registry dan port. Jadi, untuk bisa di-uninstall,, harus dimatikan dulu. Berikut langkah-langkahnya :

1. Stop service Oracle yang sedang berjalan. Klik start->run->services.msc. Stop semua service yang berbau-bau Oracle (namanya dimulai dengan 'Oracle')
2. Jalankan regedit dan hapus(mungkin nama sedikit berbeda, tapi yang jelas hapus yang berbau-bau Oracle) :
HKEY_CURRENT_USER\SOFTWARE\ORACLE
HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet Services\EventLog\Application\Oracle.oracle
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet Services\OracleDBConsole
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet Services\Oracle10g_home
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet Services\OraclService
3. Sampai tahap ini, kita sudah bisa menghapus Oracle secara manual di direktori Oracle di-install.

4. Buka c:/windows/assembly dan hapus Oracle.DataAccess serta Polic.Oracle

Simsalabim! Oracle pun terhapus secara sempurna dari Windows XP Anda... Semoga bermanfaat!

Rabu, 17 Maret 2010

[II3062]Steganografi

Tugas kali ini bercerita mengenai steganografi. Apa tuh steganografi ? Steganografi prinsipnya adalah menyembunyikan pesan inti dalam pesan lain. Tugas kali ini adalah "Buatlah sebuah steganografi".

Oke, untuk tugas kali ini saya meminjam artikel dari http://en.wikipedia.org/wiki/Miyamoto_Musashi yang bercerita tentang samurai terkenal bernama Miyamoto Musashi. Berikut steganografi sederhana kreasi saya :

The details of Miyamoto Musashi's early life are difficult to verify. Musashi himself simply states in Gorin no Sho that he was born in Harima Province.[2] Niten Ki (an early biography of Musashi) supports the theory that Musashi was born in 1584: "[He] was born in Banshū, in Tenshō 12 [1584], the Year of the Monkey."[3] The historian Kamiko Tadashi, commenting on Musashi's text, notes: "[...]Munisai was Musashi's father...he lived in Miyamoto village, in the Yoshino district [of Mimasaka Province]. Musashi was most probably born here."[4] His childhood name was Bennosuke 弁之助.

Musashi gives his full name and title in Gorin no Sho as "Shinmen Musashi no Kami Fujiwara no Genshin."[5] His father, Shinmen Munisai 新免無二斎, was an accomplished martial artist and master of the sword and jutte (also jitte).[6] Munisai, in turn, was the son of Hirata Shōgen 平田将監, a vassal of Shinmen Iga no Kami, the lord of Takeyama Castle, in the Yoshino district of Mimasaka Province.[7] Hirata was relied upon by Lord Shinmen, and so was allowed to use the Shinmen name. As for "Musashi," Musashi no Kami was a court title, making him the nominal governor of Musashi province. "Fujiwara" was the lineage from which Musashi claimed nominal descent.

[edit] Munisai and Musashi's birth date

Mysteriously, Munisai's tomb says he died in 1580, which obviously conflicts with the accepted birth date of 1584 for Musashi. Further muddying the waters, according to the genealogy of the extant Miyamoto family, Musashi was born in 1582. Kenji Tokitsu has suggested that the accepted birth date of 1584 for Musashi is wrong, as it is primarily based on a literal reading of the introduction to the Go Rin No Sho where Musashi states that the years of his life "add up to 60" (yielding the twelfth year of the Tensho era, or 1584, when working backwards from the well-documented date of composition), when it should be taken in a more literary and imprecise sense, indicating not a specific age but merely that Musashi was in his sixties when he wrote it.

Because of the uncertainty centering on Munisai (when he died, whether he was truly Musashi's father, etc.), Musashi's mother is known with even less confidence. Here are a few possibilities:

  1. Munisai's tomb was correct. He died in 1580, leaving two daughters; his wife adopted a recently born child, from the Akamatsu clan, intended to succeed Munisai at his jitte school. Omasa, Munisai's widow, was not truly Musashi's mother.
  2. The tomb was wrong. Munisai lived a good deal longer, later than 1590 possibly. Musashi, then, was born to Munisai's first wife, Yoshiko (daughter to Bessho Shigeharu, who formerly controlled Hirafuku village until he lost a battle in 1578 to Yamanaka Shikanosuke). Munisai divorced her after Musashi's birth, whereupon she decamped for her father's house, leaving Musashi with Munisai. Musashi grew up treating Munisai's second wife, Omasa (daughter to Lord Shinmen) as his mother. This second scenario is laid out in an entry to the Tasumi family's genealogy.
The daughter of Bessho Shigeharu first married Hirata Muni and was divorced from him a few years later. After that she married Tasumi Masahisa. The second wife of Tasumi Masahisa was the mother of Miyamoto Musashi. Musashi's childhood name was Hirata Den. He later became famous on account of his swordsmanship. During his childhood, he went to Hirafuku to find his real mother. He moved in with the Tasumi family.
[8]
  1. A variant of this second theory is based on the fact that the tombstone states that Omasa gave birth to Musashi on 4 March 1584, and died of it. Munisai then remarried to Yoshiko. They divorced, as in the second theory, but Yoshiko took Musashi, which was 7 at the time, with her, and married Tasumi Masahisa.
  2. Kenji Tokitsu prefers to assume a birth date of 1581, which avoids the necessity of assuming the tombstone to be erroneous (although this poses the problem of from whom then Musashi received the transmission of the family martial art).
Dapatkah Anda menebak isi pesannya?

Senin, 15 Maret 2010

[II3062]Self Generating Code

Wow, dari judulnya sudah terlihat kalau tugas kali ini aneh bin ajaib! Bagaimana tidak, kali ini kami diminta untuk membuat sebuah kode yang menghasilkan dirinya sendiri. Setelah bergoogling-googling ria, akhirnya saya menemukan sebuah situs Setelah baca-baca setengah paham, saya pun mencari-cari lagi implementasi self generating code ini.
Setelah menggabung-gabungkan beberapa sumber, akhirnya saya menemukan inti dari permasalahan ini, yaitu : program terdiri dari 2 bagian, yaitu bagian untuk meng-output program, dan bagian 2 adalah bagian yang dituliskan yang merepresentasikan kode itu sendiri. Saya memutuskan untuk menggunakan bahasa pemrograman PHP untuk tugas kali ini.

Berikut kodenya :
Hasilnya adalah :

Rincian kode :

- $babagenerator adalah sebuah variabel yang digunakan untuk menyimpan string yang ingin ditulis.
- %c adalah formatting berupa karakter dan %s adalah formatting berupa string. Dalam kasus di atas, %c diassign dengan 34, ASCII character yang berarti tanda """ (kutip dua) dan string diassign dengan $babagenerator yang berisi
Karena dalam variabel babagenerator ada variabel itu juga, maka terjadi proses rekursif dimana dia memanggil dirinya sendiri.

Yang terjadi ketika proses ini dipanggil adalah, %c akan digantikan dengan 34 dan $s akan digantikan dengan isi dari variabel babagenerator sehingga terciptalah proses rekursif yang menghasilkan output seperti source code yang kita tulis sebelumnya.