Gradle enable daemon

for all project append "org.gradle.daemon=true" into file ~/.gradle/gradle.properties

echo "org.gradle.daemon=true" >> ~/.gradle/gradle.properties

 for each project append "org.gradle.daemon=true" into file gradle.properties on your project


Parallel compile module

append "org.gradle.parallel=true" on your  gradle.properties

[Facebook Bug Bounty] Graph API can change published photo

Impact :

The impact of vulnerability. it can change  any photo of my own that was already published (without lost like and comment).

Description :
1. replace PHOTO_ID with photo you need to change https://graph.facebook.com/[PHOTO_ID]

2. attach photo you want to change on parameter url (https://developers.facebook.com/docs/graph-api/reference/photo#Updating)

3. use access_token from Facebook for Android to change photo

4. Done.


Timeline

May 5, 2015 at 3:51am – Report Sent
May 5, 2015 at 11:23am – Clarification by Facebook
May 5, 2015 at 11:35am – Clarification sent with video
May 5, 2015 at 12:29pm – Escalation by Facebook
June 12, 2015 – Ask progress to Facebook
June 12, 2015 – Response from Facebook (still discuss with team)
Sep 24, 2015 – Ask progress to Facebook
Sep 29, 2015 – Response from Facebook (The team is still working on this)
Oct 23, 2015 – Patched by Facebook
Nov 5, 2015 – Bounty Awarded of $1000 by Facebook

วิธี Compile PHP จาก Source ด้วย Ubuntu 14.04

วิธี Compile PHP จาก Source code (https://github.com/php/php-src) ด้วย  Ubuntu 14.04

Download code PHP


git clone https://github.com/php/php-src.git

Install dependency package ที่ใช้ในการ Compile

ติดตั้ง header file ที่ใช้ในการ Compile ด้วยคำสั่ง

apt-get build-dep php5 php5-cgi php5-cli php5-fpm php5-curl php5-gd php5-gmp php5-json php5-mysql php5-pspell php5-recode php5-mcrypt php5-memcached php5-imagick 
ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h 

Compile PHP


ไปที่ folder sourcecode  ที่เราโหลดมาแล้วสั่งดังนี้


รอสักครู่เพื่อทำการ compile sourcecode  เมื่อเรา  compile และติดตั้งไปยัง  path ที่เรากำหนด (--prefix=$HOME/php/usr) เรียบร้อยแล้ว ก็มาลองรันตัว php command line กันดู

ให้ไปที่

cd ~/php/usr/bin/
./php -v

ก็จะได้ PHP ตัวล่าสุดมาแล้วครับ



เป็นอันเสร็จสิ้นการ Compile PHP เบื้องต้นครับผม

Ref:
https://wiki.php.net/phpng

ทำ Continuous Integration ด้วย Gitlab

หลังจาก Blog ที่แล้วได้เล่าถึง วิธีการติดตั้ง Gitlab ไปแบบคร่าวๆ คราวนี้เราจะใช้เจ้า Gitlab ทำ Continuous Integration กันดู โดยในที่นี้จะใช้โปรเจคนี้เป็นตัวอย่างในการทำ (https://github.com/kittinan/thailandpost-track) ซึ่งเราจะทำกับภาษา PHP นั้นเอง

สมมุติว่าเจ้าโปรเจค https://github.com/kittinan/thailandpost-track อยู่บน Gitlab ของเราเรียบร้อยแล้วนะครับ



สิ่งที่เราต้องทำอันดับแรกก็คือ เราต้องติดตั้งเจ้า Gitlab Runner (https://gitlab.com/gitlab-org/gitlab-ci-multi-runner) ซึ่งเจ้าตัวนี้มีหน้าที่ทำการ Build และรันทดสอบ  Code ของเราตามที่เราต้องการ

ติดตั้ง Gitlab Runner


มาติดตั้งเจ้า  Gitlab Runner กันเลย
https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/docs/install/linux-repository.md

วิธีการติดตั้งก็ง่ายๆเหมือนติดตั้งเจ้า Gitlab นั้นแหละ

curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.deb.sh | sudo bash

sudo apt-get install gitlab-ci-multi-runner

เปิดการใช้งาน Continuous Integration


เราจะต้องทำการเปิดการใช้งาน Continuous Integration ในแต่ละโปรเจคก่อน โดยให้เราไปที่ Gitlab Dashboard > Continuous Integration ดังภาพ



คลิก Add Project to CI



ให้เราเข้าไปที่เมนู Runner



เมื่อเข้ามาในหน้า Runner แล้ว เจ้า  Gitlab ก็จะมีให้เลือกว่าเราจะใช้ Sepecific runners หรือ Shared runners

Sepecific runners - private server ของเราเอง
Shared runners - server ฟรีของ gitlab

ให้กลับไปที่ Server ที่เราเพิ่งลง Gitlab Runner ไว้ รันคำสั่ง

sudo gitlab-ci-multi-runner register

ให้เรานำ url ที่อยู่ในหน้าเวปมาใส่ ในที่นี้ก็คือ http://gitlab.kittinan.domain/ci
หลังจากใส่  url แล้วก็ใส่ token ต่อ หลังจากนั้นจะมีให้ใส่ Description กับ tag จะใส่ไม่ใส่ก็แล้วแต่
แล้ว Gitlab Runner จะถามว่าจะใช้ executor ตัวไหน ซึ่ง Gitlab Runner ก็สามารถใช้ได้หลายอย่างเช่น docker, docker-ssh, ssh, shell, parallels ในที่นี้ใช้ shell ดังภาพ



เมื่อเรา Refresh หน้าเวป Runner ก็จะมี Runner ที่ Activate แล้วขึ้นมา



เตรียม Server ให้พร้อมรัน Test (PHP)


ทำการติดตั้ง Package ต่างๆที่จะใช้ในการรัน Test ซึ่งในที่นี้เราจะทำการติดตั้ง Package PHP ต่างๆที่จำเป็นต้องใช้สำหรับโปรเจคนี้

sudo apt-get install php5-cli php5-curl

ติดตั้ง composer

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/bin/composer

เสร็จสิ้นการเตรียม environment สำหรับการรัน Test โปรเจคนี้

สร้างไฟล์ .gitlab-ci.yml


เราต้องทำการสร้างไฟล์ .gitlab-ci.yml ขึ้นมาใน Root Path โปรเจคของเรา ซึ่งไฟล์นี้จะทำหน้าที่ประมวลผลตามที่เราต้องการ เช่น ก่อนที่เราจะ Test เราต้องการให้ composer โหลด  library ต่างๆก่อน


สำหรับคำสั่งในไฟล์ .gitlab-ci.yml

before_script คือ ก่อนจะเริ่มทำงานตาม job ต่างๆ ให้ทำอะไรก่อนบ้าง ในที่นี้สั่งให้ composer โหลด library ต่างๆ
 
job1: <--- ชื่องาน ในที่นี้คือ job1 เราจะตั้งเป็นอะไรก็ได้เช่น TestModel
    script:
        - vendor/bin/phpunit tests/    <-- สั่งให้รัน test ใน directory tests

สามารถดูคำสั่งที่ใช้ใน .gitlab-ci.yml เพิ่มเติม ได้ที่ http://doc.gitlab.com/ci/yaml/README.html

เมื่อเพิ่มไฟล์ .gitlab-ci.yml ให้ทำการ commit และ push

ดูผลลัพท์ใน Gitlab


หลังจากที่เราได้ push code เข้า Gitlab เรียบร้อย เจ้า  Gitlab ก็จะไปบอก Gitlab Runner ให้ทำการทดสอบ Code ของเราตาม คำสั่งที่เราได้สั่งไว้ในไฟล์ .gitlab-ci.yml

เข้าหน้าเวป Gitlab ของเรา ดูที่  commit ก็จะเห็นสถานะของการรัน Test ดังภาพ


ภาพขณะตัว Runner กำลังรัน composer เพื่อโหลด library ต่างๆ


ภาพเมื่อรัน Test เสร็จแล้ว


พอเรากลับมาดูที่หน้า  Commit ก็จะเป็นว่า Run Test  ผ่านเรียบร้อย Success เขียวๆ ดังภาพ



เป็นอันเสร็จสิ้นการทำ Continuous Integration ด้วย Gitlab  (PHP) แบบคร่าวๆแล้วครับ


REF:
https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/docs/install/linux-repository.md
https://about.gitlab.com/gitlab-ci/
http://doc.gitlab.com/ci/yaml/README.html


วิธีการติดตั้ง Gitlab Ubuntu 14.04

จาก Document (https://about.gitlab.com/downloads/#ubuntu1404) ของ Gitlab นั้นใช้เพียงไม่กี่คำสั่งก็สามารถลงได้แล้วครับ

sudo apt-get install curl openssh-server ca-certificates postfix
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
sudo apt-get install gitlab-ce
หลังจากลง Package  ต่างๆครบแล้ว ก็ทำการ Config ตัว Gitlab

sudo gitlab-ctl reconfigure

 เสร็จแล้วต้องทำการ Config domain ให้ Gitlab

nano /etc/gitlab/gitlab.rb

ใส่ domain ตรงบรรทัด external_url ดังภาพ



แก้ไขเสร็จทำการ restart เจ้า Gitlab

sudo gitlab-ctl restart

เมื่อเข้าไปที่  domain ที่เราเซตไว้ก็จะเจอเจ้าตัว Gitlab แล้วจ้าาา ในที่นี่ก็คือ http://gitlab.kittinan.domain/



สำหรับรหัสผ่าน default ก็คือ

Username: root
Password: 5iveL!fe



REF:
https://about.gitlab.com/
http://doc.gitlab.com/omnibus/gitlab-ci/README.html

วิธีการเซต Timezone Ubuntu

ใช้คำสั่ง
sudo dpkg-reconfigure tzdata



Remove files that are listed in the .gitignore

command

git rm --cached `git ls-files -i --exclude-from=.gitignore`

Ref: http://stackoverflow.com/a/13541721