Tampilkan postingan dengan label Unix. Tampilkan semua postingan
Tampilkan postingan dengan label Unix. Tampilkan semua postingan

17 Oktober 2017

Resize Partition di FreeBSD

Kita cek partisi yang ada di OS kita.
root:~# gpart show ada0
=>       34  312581741  ada0  GPT  (149G)
         34        128     1  freebsd-boot  (64K)
        162  304086912     2  freebsd-ufs  (145G)
  304087074    8388608     3  freebsd-swap  (4.0G)
  312475682     106093        - free -  (52M)
Kita akan menghapus free-space dan meresize ada0p2/ada0p3. deaktifkan dahulu swap-nya.
root:~# swapoff /dev/ada0p3
Matikan dahulu GEOM Safety variable lewat sysctl(8).
root:~# sysctl kern.geom.debugflags=16
Hapus partisi freebsd-swap (/dev/ada0p3) dahulu. Partisi ini hanya penyimpanan sementara saja, jd aman untuk dihapus.
root:~# gpart delete -i 3 ada0
Sekarang kita lakukan resize untuk partisi freebsd-ufs (/dev/ada0p2) dari 145G ke 147G. Untuk swap dikurangi 2G.
root:~# gpart resize -i 2 -a 4k -s 147G ada0
Bikin kembali swap-nya & aktifkan kembali partisinya.
root:~# gpart add -t freebsd-swap ada0
root:~# swapon /dev/ada0p3
Cek ulang partisi akhirnya & aktifkan kembali GEOM Safety variable.
root:~# gpart show ada0
=>       34  312581741  ada0  GPT  (149G)
         34        128     1  freebsd-boot  (64K)
        162  308281342     2  freebsd-ufs  (147G)
  308281504    4300271     3  freebsd-swap  (2.0G)

root:~# sysctl kern.geom.debugflags=0
kern.geom.debugflags: 16 -> 0
Agar size baru (/dev/ada0p2 - freebsd-ufs) dapat digunakan sesuai dengan size yang baru dibikin.
root:~# growfs /dev/ada0p2
Device is mounted read-write; resizing will result in temporary write suspension for /.
It's strongly recommended to make a backup before growing the file system.
OK to grow filesystem on /dev/ada0p2, mounted on /, from 145GB to 147GB? [Yes/No] yes
super-block backups (for fsck_ffs -b #) at:
 305234240, 306516736, 307799232

11 Oktober 2017

Recovery Bad-Sector Hardisk di FreeBSD

Terlebih dahulu backup data penting!
Cek bad sector hardisk.
root:~# smartctl -t long /dev/ada0
root:~# smartctl -l selftest /dev/ada0 | awk 'NR==7'
# 1  Extended offline    Completed: read failure       90%     36067         27292160
                                                                             ^^^^^^^^ (L)
Cek UFS file system.
root:~# dumpfs /dev/ada0p2 | egrep '^bsize'
bsize   32768   shift   15      mask    0xffff8000
        ^^^^^ (B)
Cari sector pertama partisi yg digunakan dalam hardisk.
root:~# fdisk -s /dev/ada0
/dev/ada0: 310101 cyl 16 hd 63 sec
Part        Start        Size Type Flags
   1:           1   312581807 0xee 0x00
                ^ (S)
Cari sector-size hardisk.
root:~# gpart list ada0 | tail -n 5
1. Name: ada0
   Mediasize: 160041885696 (149G)
   Sectorsize: 512
               ^^^ (M) 
   Mode: r2w2e3
Gunakan formula dibawah ini.
b = ((L - S) * M) / B)
L = 27292160
S = 1
M = 512
B = 32768

b = ((27292160 - 1) * 512) / 32768
b = 426439.984375 ~ 426439 (int)
Rubah permission agar bisa mode write.
root:~# sysctl kern.geom.debugflags=0x10
Untuk sector 426439 (bad sector) tidak akan digunakan oleh sistem untuk menyimpan data.
root:~# dd if=/dev/zero of=/dev/ada0 bs=32768 count=1 seek=426439
Untuk diagnosa isi sector 426439 (bad sector) bisa diredirect outputnya ke file.
root:~# dd if=/dev/ada0 of=hasil.txt bs=32768 count=1 skip=426439
Kembalikan permission ke semula.
root:~# sysctl kern.geom.debugflags=0
Cek kembali bad sector.
root:~# smartctl -t long /dev/ada0
Pastikan hasilnya -. Ini sample outputnya:
root:~# smartctl -l selftest /dev/ada0 | awk 'NR==7'
# 1  Extended offline    Completed without error       00%     36073         -
                                                                             ^
Jangan lupa setelah yakin tidak ada bad sector, recovery semua file lewat make world & restore file backup.

15 Juli 2017

FreeBSD: make buildworld failure in libllvmsupport

Saya mendapat error yg cukup mengesalkan ketika Rebuild FreeBSD dari source , cukup lama googling mencari referensi error yang terjadi, ternyata solusinya cukup simple meskipun dengan nebak2 library clang(1) yg digunakan. Seperti kita ketahui bahwa FreeBSD 10.0-RELEASE sudah merubah untuk default compilernya dari GCC ke clang(1). Berikut saya post error yang terjadi:
c++  -O2 -pipe -I/usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include -I/usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/tools/clang/include -I/usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/lib/Support -I. -I/usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/../../lib/clang/include -DLLVM_ON_UNIX -DLLVM_ON_FREEBSD -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -DNDEBUG -fno-strict-aliasing -DLLVM_DEFAULT_TARGET_TRIPLE=\"i386-unknown-freebsd10.3\" -DLLVM_HOST_TRIPLE=\"i386-unknown-freebsd10.3\" -DDEFAULT_SYSROOT=\"\" -ffunction-sections -fdata-sections -I/usr/obj/usr/src/tmp/legacy/usr/include  -fno-exceptions -fno-rtti  -c /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/lib/Support/APFloat.cpp -o APFloat.o
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/lib/Support/APFloat.cpp:15:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include/llvm/ADT/APFloat.h:20:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include/llvm/ADT/APInt.h:19:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include/llvm/ADT/ArrayRef.h:14:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include/llvm/ADT/SmallVector.h:17:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include/llvm/Support/AlignOf.h:19:
In file included from /usr/include/c++/v1/cstddef:38:
In file included from /usr/include/c++/v1/stddef.h:51:
/usr/include/c++/v1/__nullptr:24:29: error: variable has incomplete type 'struct _LIBCPP_TEMPLATE_VIS'
struct _LIBCPP_TEMPLATE_VIS nullptr_t
                            ^
/usr/include/c++/v1/__nullptr:24:8: note: forward declaration of 'std::__1::_LIBCPP_TEMPLATE_VIS'
struct _LIBCPP_TEMPLATE_VIS nullptr_t
       ^
/usr/include/c++/v1/__nullptr:24:38: error: expected ';' after top level declarator
struct _LIBCPP_TEMPLATE_VIS nullptr_t
                                     ^
/usr/include/c++/v1/__nullptr:47:48: error: unknown type name 'nullptr_t'
inline _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);}
                                               ^
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/lib/Support/APFloat.cpp:15:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include/llvm/ADT/APFloat.h:20:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include/llvm/ADT/APInt.h:19:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include/llvm/ADT/ArrayRef.h:14:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include/llvm/ADT/SmallVector.h:19:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include/llvm/Support/MathExtras.h:18:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include/llvm/Support/SwapByteOrder.h:18:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/../../lib/clang/include/llvm/Support/DataTypes.h:36:
In file included from /usr/include/c++/v1/cmath:301:
In file included from /usr/include/c++/v1/math.h:309:
/usr/include/c++/v1/type_traits:472:114: error: expected class name
    : public integral_constant(nullptr)) == 1> {};
                                                                                                                 ^
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/lib/Support/APFloat.cpp:15:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include/llvm/ADT/APFloat.h:20:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include/llvm/ADT/APInt.h:19:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include/llvm/ADT/ArrayRef.h:14:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include/llvm/ADT/SmallVector.h:19:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include/llvm/Support/MathExtras.h:18:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/include/llvm/Support/SwapByteOrder.h:18:
In file included from /usr/src/lib/clang/libllvmsupport/../../../contrib/llvm/../../lib/clang/include/llvm/Support/DataTypes.h:36:
/usr/include/c++/v1/cmath:679:46: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY float       acos(float __lcpp_x) _NOEXCEPT       {return acosf(__lcpp_x);}
                                             ^
/usr/include/c++/v1/math.h:654:46: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY float       acos(float __lcpp_x) _NOEXCEPT       {return acosf(__lcpp_x);}
                                             ^
/usr/include/c++/v1/cmath:675:9: note: using declaration
using ::acos;
        ^
/usr/include/c++/v1/cmath:680:46: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __lcpp_x) _NOEXCEPT {return acosl(__lcpp_x);}
                                             ^
/usr/include/c++/v1/math.h:655:46: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __lcpp_x) _NOEXCEPT {return acosl(__lcpp_x);}
                                             ^
/usr/include/c++/v1/cmath:675:9: note: using declaration
using ::acos;
        ^
/usr/include/c++/v1/cmath:686:1: error: declaration conflicts with target of using declaration already in scope
acos(_A1 __lcpp_x) _NOEXCEPT {return acos((double)__lcpp_x);}
^
/usr/include/c++/v1/math.h:661:1: note: target of using declaration
acos(_A1 __lcpp_x) _NOEXCEPT {return acos((double)__lcpp_x);}
^
/usr/include/c++/v1/cmath:675:9: note: using declaration
using ::acos;
        ^
/usr/include/c++/v1/cmath:694:46: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY float       asin(float __lcpp_x) _NOEXCEPT       {return asinf(__lcpp_x);}
                                             ^
/usr/include/c++/v1/math.h:666:46: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY float       asin(float __lcpp_x) _NOEXCEPT       {return asinf(__lcpp_x);}
                                             ^
/usr/include/c++/v1/cmath:690:9: note: using declaration
using ::asin;
        ^
/usr/include/c++/v1/cmath:695:46: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __lcpp_x) _NOEXCEPT {return asinl(__lcpp_x);}
                                             ^
/usr/include/c++/v1/math.h:667:46: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __lcpp_x) _NOEXCEPT {return asinl(__lcpp_x);}
                                             ^
/usr/include/c++/v1/cmath:690:9: note: using declaration
using ::asin;
        ^
/usr/include/c++/v1/cmath:701:1: error: declaration conflicts with target of using declaration already in scope
asin(_A1 __lcpp_x) _NOEXCEPT {return asin((double)__lcpp_x);}
^
/usr/include/c++/v1/math.h:673:1: note: target of using declaration
asin(_A1 __lcpp_x) _NOEXCEPT {return asin((double)__lcpp_x);}
^
/usr/include/c++/v1/cmath:690:9: note: using declaration
using ::asin;
        ^
/usr/include/c++/v1/cmath:709:46: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY float       atan(float __lcpp_x) _NOEXCEPT       {return atanf(__lcpp_x);}
                                             ^
/usr/include/c++/v1/math.h:678:46: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY float       atan(float __lcpp_x) _NOEXCEPT       {return atanf(__lcpp_x);}
                                             ^
/usr/include/c++/v1/cmath:705:9: note: using declaration
using ::atan;
        ^
/usr/include/c++/v1/cmath:710:46: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __lcpp_x) _NOEXCEPT {return atanl(__lcpp_x);}
                                             ^
/usr/include/c++/v1/math.h:679:46: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __lcpp_x) _NOEXCEPT {return atanl(__lcpp_x);}
                                             ^
/usr/include/c++/v1/cmath:705:9: note: using declaration
using ::atan;
        ^
/usr/include/c++/v1/cmath:716:1: error: declaration conflicts with target of using declaration already in scope
atan(_A1 __lcpp_x) _NOEXCEPT {return atan((double)__lcpp_x);}
^
/usr/include/c++/v1/math.h:685:1: note: target of using declaration
atan(_A1 __lcpp_x) _NOEXCEPT {return atan((double)__lcpp_x);}
^
/usr/include/c++/v1/cmath:705:9: note: using declaration
using ::atan;
        ^
/usr/include/c++/v1/cmath:724:46: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY float       atan2(float __lcpp_y, float __lcpp_x) _NOEXCEPT             {return atan2f(__lcpp_y, __lcpp_x);}
                                             ^
/usr/include/c++/v1/math.h:690:46: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY float       atan2(float __lcpp_y, float __lcpp_x) _NOEXCEPT             {return atan2f(__lcpp_y, __lcpp_x);}
                                             ^
/usr/include/c++/v1/cmath:720:9: note: using declaration
using ::atan2;
        ^
/usr/include/c++/v1/cmath:725:46: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __lcpp_y, long double __lcpp_x) _NOEXCEPT {return atan2l(__lcpp_y, __lcpp_x);}
                                             ^
/usr/include/c++/v1/math.h:691:46: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __lcpp_y, long double __lcpp_x) _NOEXCEPT {return atan2l(__lcpp_y, __lcpp_x);}
                                             ^
/usr/include/c++/v1/cmath:720:9: note: using declaration
using ::atan2;
        ^
/usr/include/c++/v1/cmath:736:1: error: declaration conflicts with target of using declaration already in scope
atan2(_A1 __lcpp_y, _A2 __lcpp_x) _NOEXCEPT
^
/usr/include/c++/v1/math.h:702:1: note: target of using declaration
atan2(_A1 __lcpp_y, _A2 __lcpp_x) _NOEXCEPT
^
/usr/include/c++/v1/cmath:720:9: note: using declaration
using ::atan2;
        ^
/usr/include/c++/v1/cmath:750:46: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY float       ceil(float __lcpp_x) _NOEXCEPT       {return ceilf(__lcpp_x);}
                                             ^
/usr/include/c++/v1/math.h:713:46: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY float       ceil(float __lcpp_x) _NOEXCEPT       {return ceilf(__lcpp_x);}
                                             ^
/usr/include/c++/v1/cmath:746:9: note: using declaration
using ::ceil;
        ^
/usr/include/c++/v1/cmath:751:46: error: declaration conflicts with target of using declaration already in scope
inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __lcpp_x) _NOEXCEPT {return ceill(__lcpp_x);}
                                             ^
/usr/include/c++/v1/math.h:714:46: note: target of using declaration
inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __lcpp_x) _NOEXCEPT {return ceill(__lcpp_x);}
                                             ^
/usr/include/c++/v1/cmath:746:9: note: using declaration
using ::ceil;
        ^
/usr/include/c++/v1/cmath:757:1: error: declaration conflicts with target of using declaration already in scope
ceil(_A1 __lcpp_x) _NOEXCEPT {return ceil((double)__lcpp_x);}
^
/usr/include/c++/v1/math.h:720:1: note: target of using declaration
ceil(_A1 __lcpp_x) _NOEXCEPT {return ceil((double)__lcpp_x);}
^
/usr/include/c++/v1/cmath:746:9: note: using declaration
using ::ceil;
        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
*** Error code 1

Stop.
make[3]: stopped in /usr/src/lib/clang/libllvmsupport
*** Error code 1

Stop.
make[2]: stopped in /usr/src
*** Error code 1

Stop.
make[1]: stopped in /usr/src
*** Error code 1

Stop.
make: stopped in /usr/src
Solusi yang saya lakukan adalah sbb:
Keyword ada di /usr/include/c++/v1/cmath:746, error itu kurang lebih seputar header declaration konflik dengan header yang sudah terinstall sebelomnya. Tipe data long double sepertinya tidak dapat didefinisikan di scope ketika proses build object file. Temukan file cmath di /usr dengan perintah:
root:/usr# find . -type f -name "cmath"
./src/contrib/libstdc++/include/tr1/cmath
./src/contrib/libc++/include/cmath (cmath dari source SVN)
./include/c++/v1/cmath (cmath yang bermasalah)
./local/lib/gcc5/include/c++/ext/cmath
./local/lib/gcc5/include/c++/tr1/cmath
./local/lib/gcc5/include/c++/cmath
OK, kita liat susunan direktori & filenya banyak kemiripan antara /usr/include/c++/v1/ dengan /usr/src/contrib/libc++/include/. Kita tinggal copykan saja tapi sebelomnya kita backup terlebih dahulu.
root:~# cd /usr/include/c++
root:/usr/include/c++# mv v1 v1.old
root:/usr/include/c++# cp -rp /usr/src/contrib/libc++/include .
root:/usr/include/c++# mv include v1
Silahkan dicoba kembali proses make buildworld, saya mengalami kekurangan dua file header yg dibutuhkan yaitu cxxabi.h dan unwind.h, silahkan kita cari lagi kedua file ini di /usr/src dan kopikan saja:
root:/usr/include/c++/v1# find /usr/src -type f -name "cxxabi.h"
/usr/src/contrib/libstdc++/libsupc++/cxxabi.h
/usr/src/contrib/libcxxrt/cxxabi.h (Kita ambil yang ini)
root:/usr/include/c++/v1# cp /usr/src/contrib/libcxxrt/cxxabi.h .
root:/usr/include/c++/v1# find /usr/src -type f -name "unwind.h"
/usr/src/sys/ia64/include/unwind.h
/usr/src/contrib/libcxxrt/unwind.h
/usr/src/contrib/llvm/tools/clang/lib/Headers/unwind.h (Kita ambil yang ini)
/usr/src/contrib/libexecinfo/unwind.h
/usr/src/include/unwind.h
root:/usr/include/c++/v1# cp /usr/src/contrib/llvm/tools/clang/lib/Headers/unwind.h .
Silahkan make buildworld kembali, jika ada error coba teliti stderr di consolenya. Dan silahkan tebak2 lagi seperti contoh langkah diatas :-).

15 Mei 2017

Instalasi SSL Gratis Dari Let's Encrypt

Beberapa waktu lalu saya sempat membahasa tentang pemasangan fitur SSL dengan metode Self-Signing. Sekarang, saya coba menggunakan Let's Encrypt. Caranya cukup sederhana karena semua dikerjakan secara auto.
• Download atau copy-paste acme.sh di https://github.com/Neilpang/acme.sh.
• Copykan di root folder, usahakan menggunakan root akses karena kita perlu merestart daemon nginx webserver dan menempatkan sertifikat di /etc/ssl/certs. Buat folder .acme.sh di root folder dan download acme.sh script.
# mkdir .acme.sh
# cd .acme.sh && fetch https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh
# chmod 700 acme.sh
Kita mulai mengkonfigurasi dan menginstal sertifikatnya. Saya asumsikan anda sudah mempunyai sebuah domain yang valid dan terinstall webserver.
# cd .acme.sh
# ./acme.sh --issue -d domainanda.com -w /path/to/root/webserver/document
[Mon May 15 19:28:12 WIB 2017] Registering account
[Mon May 15 19:28:15 WIB 2017] Registered
[Mon May 15 19:28:16 WIB 2017] Update success.
[Mon May 15 19:28:16 WIB 2017] ACCOUNT_THUMBPRINT='MINkdh3CiCitr1h4YesQSO2azn7bs3NIFwJOLbTSpug'
[Mon May 15 19:28:16 WIB 2017] Creating domain key
[Mon May 15 19:28:17 WIB 2017] Single domain='domainanda.com'
[Mon May 15 19:28:17 WIB 2017] Getting domain auth token for each domain
[Mon May 15 19:28:17 WIB 2017] Getting webroot for domain='domainanda.com'
[Mon May 15 19:28:17 WIB 2017] Getting new-authz for domain='domainanda.com'
[Mon May 15 19:28:19 WIB 2017] The new-authz request is ok.
[Mon May 15 19:28:19 WIB 2017] Verifying:domainanda.com
[Mon May 15 19:28:24 WIB 2017] Success
[Mon May 15 19:28:24 WIB 2017] Verify finished, start to sign.
[Mon May 15 19:28:26 WIB 2017] Cert success.
-----BEGIN CERTIFICATE-----
MIIE/DCCA+SgAwIBAgISBAb5KVD8Z+F2hCdzvVfK0cp6MA0GCSqGSIb3DQEBCwUA
MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD
ExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMzAeFw0xNzA1MTUxMTI4MDBaFw0x
NzA4MTMxMTI4MDBaMBcxFTATBgNVBAMTDHduLnNseWlwLm5ldDCCASIwDQYJKoZI
hvcNAQEBBQADggEPADCCAQoCggEBALtbiMysoSdf+7VfuiL+6vc5qscn6DPd2j2f
YbWVIki3PdsJUmr66/oj3wRXRMbzflhfVgLfnFvj9mUb+44pIChRSc5R4AboqIFo
vngilTgDAjtbpceCmeTj3DNpa1sJN9BVmrfRazLBgzg0dPQ6QJpixtKcRiwbOJsx
k5XM7SOeq1hFpNef3NPc6wyIhcv+h+e1Id8WJPWGaJgNq+QnC7AnnIRRcjuaCZsl
SKeenGBUcpHKNUKOY7AADZ2hHR74Eg7IGcbOt+LrnljE/613BXi2U8GYbL28LoIq
YrNFAxjqoKPXZtfWuIHYYxfAbiejGhnmzPPKlKsZ2rRTAREZJUMCAwEAAaOCAg0w
ggIJMA4GA1UdDwEB/wQEAwIFoDAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUH
AwIwDAYDVR0TAQH/BAIwADAdBgNVHQ4EFgQUbBO4xZOZeedw10ZZYg083IAcnqgw
HwYDVR0jBBgwFoAUqEpqYwR93brm0Tm3pkVl7/Oo7KEwcAYIKwYBBQUHAQEEZDBi
MC8GCCsGAQUFBzABhiNodHRwOi8vb2NzcC5pbnQteDMubGV0c2VuY3J5cHQub3Jn
LzAvBggrBgEFBQcwAoYjaHR0cDovL2NlcnQuaW50LXgzLmxldHNlbmNyeXB0Lm9y
Zy8wFwYDVR0RBBAwDoIMd24uc2x5aXAubmV0MIH+BgNVHSAEgfYwgfMwCAYGZ4EM
AQIBMIHmBgsrBgEEAYLfEwEBATCB1jAmBggrBgEFBQcCARYaaHR0cDovL2Nwcy5s
ZXRzZW5jcnlwdC5vcmcwgasGCCsGAQUFBwICMIGeDIGbVGhpcyBDZXJ0aWZpY2F0
ZSBtYXkgb25seSBiZSByZWxpZWQgdXBvbiBieSBSZWx5aW5nIFBhcnRpZXMgYW5k
IG9ubHkgaW4gYWNjb3JkYW5jZSB3aXRoIHRoZSBDZXJ0aWZpY2F0ZSBQb2xpY3kg
Zm91bmQgYXQgaHR0cHM6Ly9sZXRzZW5jcnlwdC5vcmcvcmVwb3NpdG9yeS8wDQYJ
KoZIhvcNAQELBQADggEBAJad1Nm5x62oMmMNy2zsCe6bckLQaW5MhqXzez13Uz2A
DnaUTgpYC6+AIJmCaPjNkozSOcb8KDXPx2Mmdt16ZB0wjgBqcMJfcrm9EjTXafQZ
SlIXQYQuB0hsoJIXWQacAXjNlFnRUSEk9DSCBy7Xnq55qbFPrrqj3L51qjlGE6zE
s+Fbt0BIKpybBy0JGltMJtAQaVkFgYnAXj1mvKSnf3FYwBySNBciumyKDr9cSlkQ
CyjduyR7HB3GgeIlndYvPnkT0x5PEdWoiqh8ACMAWqJyfwEXWGOTxBNdtMdbGV37
zDyK/nDHeWd2LP3dXxCxaSxrhFHD0hnRv+krOzHguXU=
-----END CERTIFICATE-----
[Mon May 15 19:28:26 WIB 2017] Your cert is in  /root/.acme.sh/domainanda.com/domainanda.com.cer
[Mon May 15 19:28:26 WIB 2017] Your cert key is in  /root/.acme.sh/domainanda.com/domainanda.com.key
[Mon May 15 19:28:26 WIB 2017] The intermediate CA cert is in  /root/.acme.sh/domainanda.com/ca.cer
[Mon May 15 19:28:26 WIB 2017] And the full chain certs is there:  /root/.acme.sh/domainanda.com/fullchain.cer
# ls -laF
drwxr-xr-x   4 root  wheel     512 May 15 19:28:39 2017 .
drwxr-xr-x  12 root  wheel    1024 May 15 19:25:13 2017 ..
-rw-r--r--   1 root  wheel     196 May 15 19:28:26 2017 account.conf
-rwxr-xr-x   1 root  wheel  142712 May  3 21:04:02 2017 acme.sh
drwxr-xr-x   3 root  wheel     512 May 15 19:28:09 2017 ca
-rw-r--r--   1 root  wheel     448 May 15 19:28:26 2017 http.header
drwxr-xr-x   2 root  wheel     512 May 15 19:28:26 2017 domainanda.com
Selanjutkan kita lakukan proses instalasi sertifikatnya.
# cd .acme.sh && ./acme.sh --install-cert -d domainanda.com --key-file /etc/ssl/certs/domainanda.com.key --fullchain-file /etc/ssl/certs/domainanda.com.pem
# vim /usr/local/etc/nginx/nginx.conf
server {
    listen  domainanda.com:443 ssl default_server;
    root   /usr/local/www/data;
    add_header X-Powered-By "domainanda.com";
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-XSS-Protection "1; mode=block" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header Referrer-Policy no-referrer;
    add_header Strict-Transport-Security "max-age=31536000;" always;
    add_header Content-Security-Policy "default-src 'self'; script-src 'self' domainanda.com";
    ssl_certificate      /etc/ssl/certs/domainanda.com.pem;
    ssl_certificate_key  /etc/ssl/certs/domainanda.com.key;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;
    ssl_ecdh_curve secp384r1;
    ssl_session_tickets off;
    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
    ssl_prefer_server_ciphers  on;
    ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
}
# /usr/local/etc/rc.d/nginx restart
Karena sertifikat ini berlaku maksimal cuma 3 bulan, maka kita harus merenew sebelom expired:
# cd /root/.acme.sh/ && ./acme.sh --renew -d domainanda.com --force
# cd /root/.acme.sh/ && ./acme.sh --install-cert -d domainanda.com --key-file /etc/ssl/certs/domainanda.com.key --fullchain-file /etc/ssl/certs/domainanda.com.pem
# /usr/local/etc/rc.d/nginx restart
Lakukan secara simultan dengan menggunakan crontab(5) setiap 2 bulan sekali:
# crontab -l
0       1       1       */2     *       cd /root/.acme.sh/ && ./acme.sh --renew -d domainanda.com --force && ./acme.sh --install-cert -d domainanda.com --key-file /etc/ssl/certs/domainanda.com.key --fullchain-file /etc/ssl/certs/domainanda.com.pem --reloadcmd "/usr/local/etc/rc.d/nginx reload"

05 Juni 2015

Transparent Proxy Squid SSL/HTTPS Support

Setelah mentok gara² certificate error akhirnya bisa sukses juga menggunakan transparent proxy untuk protocol HTTPS. Saya coba jelaskan secara garis besar dan singkat yah :-).

1. Update koleksi ports di FreeBSD untuk mendapatkan versi terbaru dan terupdate:
# portsnap fetch
# portsnap extract
# portsnap update
atau via SVN
# svn checkout svn://svn.freebsd.org/ports/head /usr/ports
2. Install squid seri versi 3.x yang sudah medukung SSLBump:
# cd /usr/ports/www/squid
# make menu
Pastikan opsi untuk SSL dan ssl_crtd support dicentang!
# make install clean
3. Konfigurasi post-install untuk direktori, permission etc:
# mkdir /usr/local/squid/ssl_db (Untuk penyimpanan cert-cache)
# chown -R squid:squid /usr/local/squid/ssl_db
# mkdir /usr/local/etc/squid/certs (Untuk penyimpanan cert self-signing)
# chown -R squid:squid /usr/local/etc/squid/certs
4. Pembuatan ceritificate self-signing yang akan digunakan oleh squid:
# cd /usr/local/etc/squid/certs
# openssl req -new -newkey rsa:1024 -days 1365 -nodes -x509 -keyout squid.pem -out squid.pem
# openssl x509 -in squid.pem -outform DER -out squid.der (DER Format)
# openssl x509 -in squid.pem -outform DER -out squid.crt (CRT Format)
5. Konfigurasi squid.conf:
# grep ssl /usr/local/etc/squid/squid.conf        
https_port yyy.yyy.yyy.yyy:xxxx transparent ssl-bump generate-host-certificates=on dynamic_cert_mem_cache_size=4MB cert=/usr/local/etc/squid/certs/squid.pem 
ssl_bump splice localhost        
ssl_bump server-first all        
ssl_bump bump all        
sslproxy_cert_error deny all        
sslproxy_flags DONT_VERIFY_PEER        
sslcrtd_program /usr/local/libexec/squid/ssl_crtd -s /usr/local/squid/ssl_db -M 4MB    
sslcrtd_children 32 startup=5 idle=1     

# /usr/local/libexec/squid/ssl_crtd -c -s /usr/local/etc/squid/certs/ssl_db  (Initialized SSLdb)     
# /usr/local/etc/rc.d/squid start
6. Redirect semua traffic port HTTP/HTTPS ke port squid:
# vim /etc/rc.firewall
${fwcmd} add 10 fwd ${ipproxy},${porthttpsproxy} tcp from ${ipclient} to any dst-port ${porthttps} in via ${ifint0}
ipproxy="ip_proxy_server"
porthttpsproxy="port_squid_for_https"   // See squid.conf.manual for detail
ipclient="ip_client"                    // For example: 192.168.0.0/24
porthttps="443"                         // HTTPS port default
ifint0="LAN_eth"                        // Ethernet connected to LAN directly
Atau jika menggunakan packet filter OpenBSD:
# vim /etc/pf.conf
rdr pass on $ifint0 proto tcp from $ipclient to any port 443 -> $ipproxy port $porthttpsproxy
7. Import sertifikat squid.der (Windows aja) atau squid.crt (untuk format Android/Windows):
C:\> certmgr.msc (Simpan di bagian CA certificate, klik2 aja deh sendiri...)
8. DONE!

22 April 2014

Self Signing SSL Certificate

Banyak bertebaran tentang tutorial ini di Google, Inc tapi saya ingin merangkumnya agak lebih efesien dan efektif. Awalnya saya menggunakan protocol HTTP untuk link download karena banyaknya app yg beredar bisa nge-sniff `clear URL
', maka saya harus bermigrasi ke protocol HTTPS yg pastinya di-encrypt, tapi untuk menggunakan protocol HTTPS ini sudah dipastikan harus ada verifikasi dari public SSL provider spt DigiCert, Verisign dsb, berupa sertifikat yg valid. Tapi berhubung saya cuma UKM so pasti keberatan kalo beli hehe...
Maka saya coba dengan metode Self-Sign Certificate meski tidak sesempurna sertifikat beli ya lumayan lah... OK, langkah awal pastikan webserver support dgn SSL, saya menggunakan Lighttpd + OpenSSL, saya tidak menjelaskan instalasinya yah...
root:~# lighttpd -v
lighttpd/1.4.35 (ssl) - a light and fast webserver
Build-Date: Apr 22 2014 13:54:26
root:~# cat /usr/local/etc/lighttpd/lighttpd.conf
1. Konfigurasi webserver agar support HTTPS.
$SERVER["socket"] == "xxx.xxx.xxx.xxx:443" {
        ssl.engine  = "enable"
        ssl.pemfile = "/etc/ssl/certs/server.pem"
        ssl.ca-file = "/etc/ssl/certs/server.crt"
        ssl.honor-cipher-order = "enable"
        ssl.use-sslv2 = "disable"
        ssl.use-sslv3 = "disable"
}
Redirect semua HTTP ke HTTPS
$HTTP["scheme"] == "http" {
        $HTTP["host"] =~ "domain.tld" {
            url.redirect = ( "/.*" => "https://%0$0" )
        }
}
2. Pembikinan sertifikat.
2.1 Pembikin sertifikat CA (Certificate Authority)
root:~# cd /etc/ssl
root:/etc/ssl# mkdir certs
root:/etc/ssl/certs# openssl genrsa -out ca.key 4096
root:/etc/ssl/certs# openssl req -x509 -new -sha256 -nodes -key ca.key -days 2555 -out ca.pem
root:/etc/ssl/certs# openssl x509 -outform der -in ca.pem -out ca.crt
2.2 Pembikinan sertifikat untuk server/site
root:/etc/ssl/certs# openssl genrsa -out server.key 4096
root:/etc/ssl/certs# openssl req -new -sha256 -key server.key -out server.csr
2.3 Pembikinan CRT dan PEM sertifikat
root:/etc/ssl/certs# cat v3.ext
authorityKeyIdentifier = keyid,issuer
basicConstraints = CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
root:/etc/ssl/certs# openssl x509 -req -sha256 -days 730 -extfile v3.ext -in server.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out server.crt
root:/etc/ssl/certs# cat server.key server.crt > server.pem
root:/etc/ssl/certs# chmod 600 *
root:/etc/ssl/certs# /usr/local/etc/rc.d/lighttpd restart
Agar ter-verify silahkan dishare *.crt filenya, kalo client/browser kita sudah install *.crt pasti status Verified.

13 Maret 2014

Setup DNSSEC-BIND di FreeBSD

Untuk menambah keamanan Bind sebagai resolver saya coba implementasikan DNSSEC di FreeBSD
1. Buat direktori untuk key & private file:
# mkdir /etc/namedb/key
# cd /etc/namedb/key
# dnssec-keygen -f KSK -a RSASHA1 -b2048 -n ZONE example.com
# dnssec-keygen -a RSASHA1 -b 768 -n ZONE example.com
2. Append isi dari kedua file *.key ke file db domain zone:
# cd /etc/namedb/
# cat key/Kexample.com.+005+*.key >> master/example.com.db 
3. Sign untuk db domain zone, sehingga terbetuk file example.com.db.signed di direktori master
# dnssec-signzone -o example.com -k Kexample.com.+005+15439.key ../master/example.com.db Kexample.com.+005+26382.key
4. Edit named.conf untuk menggunakan db domain yang telah di signed
zone "example.com" {
     type master;
     file "master/example.com.db.signed"
}
5. Untuk fingerprint bisa dicoba dengan command
# cd /etc/namedb/master/
# dnssec-dsfromkey -1 -f example.com.db.signed example.com example.com. IN DS 51367 5 1 527EE9DED3B1DC3F7FE9C7F3CE08E8E56674D6A8
6. Silahkan ditest outputnya kurang lebih seperti ini
# dig +dnssec +short example.com
A 5 2 3600 20140411175317 20140312175317 26382 example.com. hmBbAz1245O6tVLuXjnlKLqCH0JKguISPn3vTPI+ju8Kp8aBcgTI10tTQ7gtm5Xe7KJn60ggLnPIpnQN0GpVD5APbnOnsXi4QL0YKxJDp+yVcXbryG0svDaYaGtixhEp

14 Agustus 2013

Make World FreeBSD

1. Install cvsup binary dan buat file stable-file.
# cd /usr/ports/net/cvsup-without-gui (Asumsi anda tidak running X system)
# make ; make install ; make clean
# cd /root/
# mkdir cvsup
# cd cvsup
# vim stable-file
# cat stable-file
*default host=cvsup3.FreeBSD.org
*default base=/usr
*default prefix=/usr
*default release=cvs tag=RELENG_4
*default delete use-rel-suffix
 src-all
Catatan: Untuk tag=RELENG_4, artinya anda melakukan upgrade last-version untuk FreeBSD 4.X, untuk tag bisa dilihat di http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/cvs-tags.html, sedangkan src-all artinya anda melakukan upgrade untuk seluruh source /usr/src. anda bisa customize untuk ini sesuai kebutuhan anda.
# cvsup -g -L 2 stable-file (Tunggu sampe selesai)
2. Prepare untuk file/config yg diperlukan, buat file make.conf:
# vim /etc/make.conf
# cat /etc/make.conf
CFLAGS= -O -pipe
COPTFLAGS= -O -pipe
NOPROFILE=      true
USA_RESIDENT= YES
IPFW2=true
COMPAT22= YES
COMPAT3X= YES
Catatan: Untuk keperluan ini "sangat relatif" silahkan mengacu ke /etc/defaults/make.conf untuk detailnya. Jika mesin yang anda pake standalone atau PC jangkrik tentunya ada baiknya kita masuk ke single user mode, tapi kalo mesin anda sbg server yg musti operational tidak usah masuk single user pun no problem dng konsekwensi makan waktu pengerjaan lebih lama. Skip langkah ini kalo anda tidak mengehendaki masuk single user.
# shutdown now 
# fsck -p
# mount -a -t ufs
# swapon -a
Hapus file object kalo2 sebelomnya anda telah melakukan proses ini.
# cd /usr/
# chflags -R noschg obj/*
# cd obj
# rm -rf *
Catatan: Hilangkan flag schg agar bisa anda hapus, anda bisa view dengan perintah ls -loFa untuk jelasnya.

3 Kita mulai build keseluruhan /usr/src dan meletakan file2 preinstall di /usr/obj secara otomatis biasanya file object.
# cd /usr/src
# make buildworld
# make buildkernel KERNCONF=NAMA_KERNEL_ANDA_SEKARANG
# make installkernel KERNCONF=NAMA_KERNEL_ANDA_SEKARANG
# make installworld
# make delete-old (Optional)
# make delete-old-libs (Optional)
Jika anda gagal dan berniat untuk mengulanginya anda bisa lakukan.
# chflags -R noschg /usr/obj/*
# cd /usr/obj
# rm -rf *
# cd /usr/src
# make cleandir (2X)
# cvsup -g -L 2 stable-file (Ulang sekali lagi)
4. Update semua file configurasi system /etc, /dev /stand.
# cd /
# cp -Rp /etc /etc.old
# mkdir /var/tmp/root (Untuk FreeBSD 4.X only)
# cd /usr/src/etc (Untuk FreeBSD 4.X only)
# make DESTDIR=/var/tmp/root distrib-dirs distribution (Untuk FreeBSD 4.X only)
Catatan: Kita buat direktori sementara untuk menyimpan file2 yang baru, kita tempatkan di /var/tmp/root.
Update /dev.
# cp /var/tmp/root/dev/MAKEDEV /dev (Untuk FreeBSD 4.X only)
# cd /dev ; sh MAKEDEV all (Untuk FreeBSD 4.X only)
Update stand.
# cd /usr/src/release/sysinstall ; make all install (Untuk FreeBSD 4.X only)
5. Update file² yg diperlukan.
# mergemaster -s
Catatan: Anda akan dihadapkan beberapa options dan perbandingan 'file yang lama' dan 'file yang baru', untuk [merge] anda pijit 'm', di layar anda ada 2 bagian yaitu bagian kiri dan bagian kanan, dimana bagian kiri adalah file config lama, bagian kanan file config baru, anda tinggal pilih 'l' (left) untuk file lama (bisa berkali-kali), pijit 'r' untuk file baru (bisa berkali-kali), jika ada option tampil anda pilih 'i' untuk install, proses ini terus menerus sampe semua file dibandingkan sistem. *HATI HATI UNTUK PROSES INI* Semua file baru disalin di direktori "/var/tmp/temproot/" ketika "mergemaster -s". Jika kelak diperlukan bisa ngebrowse kembali ke direktori ini.

6. Reboot.

08 Juli 2013

ipfw_WF2Q+

1. Jika anda ingin menimplementasikan WF2Q+ dengan ipfw di mesin dengan tujuan:
- Sharing bandwidth antar client misalnya untuk ratio 1:4.
- Sharing bandwidth evenly/rata diantara client tersebut (Tapi bukan garansi/CIR).
- Adanya bandwidth peak/burst diantara client jika client yg lain idle.
2. Untuk sharing bandwidth dengan ratio 1:4 bisa anda kelompokan client anda dalam satu group misalnya:
- Host A, B, C, D diberi bandwidth rebutan/sharing sebesar 128 Kbit/s, dengan IP Address:
* Host A : 192.168.0.1/32
* Host B : 192.168.0.2/32
* Host C : 192.168.0.3/32
* Host D : 192.168.0.4/32
Asumsi subnet yg anda pilih /24 atau 255.255.255.0, jika anda ingin menggunakan subnetting juga itu lebih bagus.

3. Bikin rule di /etc/rc.firewall dan letakan sebelom rule permit/deny:
ipcl_grup01="192.168.0.0/24{1,2,3,4}"
bw_share01="128Kbit/s"
bw_down_share01="128Kbit/s"
bw_up_share01="64Kbit/s"
ifint="inside_interface"

# Sample format 1 - Limiting downstream saja.
${fwcmd} add 1 queue 1 ip from any to ${ipcl_group01} out via ${ifint} // Downstream
${fwcmd} queue 1 config weight 50 queue 4 pipe 1 mask dst-ip 0xffffffff
${fwcmd} pipe 1 config queue 4 bw ${bw_down_share01}

# Sampel format 2 - Limiting upstream saja.
${fwcmd} add 1 queue 1 ip from ${ipcl_group01} to any in  via ${ifint} // Upstream
${fwcmd} queue 1 config weight 50 queue 4 pipe 1 mask src-ip 0xffffffff
${fwcmd} pipe 1 config queue 4 bw ${bw_up_share01}

# Sample format 3 - Limiting downstream/upstream menjadi satu flow.
${fwcmd} add 1 queue 1 ip from any to ${ipcl_group01} out via ${ifint} // Downstream
${fwcmd} add 2 queue 1 ip from ${ipcl_group01} to any in  via ${ifint} // Upstream
${fwcmd} queue 1 config weight 50 queue 4 pipe 1 mask all
${fwcmd} pipe 1 config queue 4 bw ${bw_share01}

# Sample format 4 - Limiting upstream/downstream dengan masing2 flow terpisah.
${fwcmd} add 1 queue 1 ip from any to ${ipcl_group01} out via ${ifint} // Downstream
${fwcmd} add 2 queue 2 ip from ${ipcl_group01} to any in  via ${ifint} // Upstream
${fwcmd} queue 1 config weight 50 queue 4 pipe 1 mask dst-ip 0xffffffff
${fwcmd} queue 2 config weight 50 queue 4 pipe 2 mask src-ip 0xffffffff
${fwcmd} pipe 1 config queue 4 bw ${bw_down_share01}
${fwcmd} pipe 2 config queue 4 bw ${bw_up_share01}
WF2Q+ merupakan varian dari sistem quering policy, dan jangan lupa setelah di assign via queue mesti terhubung ke pipe.
Keterangan:
- queue [Dibagian rule : ${fwcmd} add 1 queue...] : Assign untuk rule WF2Q+.
- weight                                          : Nilei pembanding flow quering (Bukan priority).
                                                    Default 1, allow [1 s/d 100].
- queue [Dibagian rule : ${fwcmd} queue 1 config weight 50 queue...] : Ukuran/jumlah dari "queue/slot" sbg pembanding terhadap jumlah bandwidth. Default 50.
- queue [Dibagian rule : ${fwcmd} pipe 1 config queue...] : Ukuran/jumlah dari "queue/slot" sbg pembanding terhadap jumlah bandwidth. Default 50
- pipe : Assign rule untuk ukuran bandwidth yg terkoneksi.
- mask dst-ip/src-ip : Digunakan untuk masking IP Address/subneting dan port. "dst-ip" digunakan untuk "downstream", "src-ip" digunakan untuk "upstream" dari sample rule diatas (Tergantung dari posisi IP client/port). 0xffffffff adalah value subnet, sama dengan "0.0.0.0/0" (Match all IP Address). Untuk port default "0x0000" artinya tidak menspesifikan/pembatasan port.
4. Perhitungan:
bw_perclient = (w_client / w_jumlah_) * bw_total
Sample diatas perclient mempunyai weight masing2 50, total bw 128 Kbit/s. Katakanlah untuk host A bisa dikalkulasikan sbb:
bw_host_A = (50 / (50*4)) * 128 Kbit/s
          = (50 / 200) * 128 Kbit/s
          = 32 Kbit/s
Jika semua host aktif maka dummynet akan berusaha membagi rata sejumlah 32 Kbit/s per hostnya. Nah contoh diatas mempunyai weight yg sama besarnya, gimana kalo contohnya begini:
w_host_A = 30
w_host_B = 50
w_host_C = 50
w_host_D = 50
Maka bisa kita kalkulasikan bw yg didapat oleh host A dan host B sbb:
bw_host_A = (30 / (30+50+50+50)) * 128 Kbit/s
          = (30 / 180) * 128 Kbit/s
          = 21.333 Kbit/s

bw_host_B = (50 / (30+50+50+50)) * 128 Kbit/s
          = (50 / 180) * 128 Kbit/s
          = 35.55 Kbit/s
Contoh lain:
w_host_A = 10
w_host_B = 20
w_host_C = 30
w_host_D = 40

bw_host_A = (10 / (10+20+30+40)) * 128 Kbit/s
          = (10 / 100) * 128 Kbit/s
          = 12.8 Kbit/s

bw_host_B = (20 / (10+20+30+40)) * 128 Kbit/s
          = (20 / 100) * 128 Kbit/s
          = 25.6 Kbit/s
Perhitungan queue slot. Dalam hal ini queue di rule diatas adalah 4, maka bisa dikalkulasikan:
bw_perclient = bw_total/slot_queue
Dari sample diatas bisa dihitung untuk host A sbb:
bw_host_A = 128 Kbit/s / 4 
          = 32 Kbit/s
Jika semua host aktif maka dummynet akan berusaha membagi rata bandwidth 32 Kbit/s per slot-nya (1 slot = 32 Kbit/s). IMHO, queue slot mendingan disesuaikan dengan jumlah client yg share, contoh diatas 1:4 berarti queue slot-nya

4. Jika kita rubah misalnya queue slot menjadi 8 slot maka ada kemungkinan host A akan menggunakan lebih dari 1 slot, artinya bisa cenderung ngerebut slot jatah host lain.
root:~# uname -srnm
FreeBSD gw-core-introuter.kumprang.com 4.10-STABLE i386
root:~# ipfw queue show
00001:  24.000 Kbit/s    0 ms   50 sl. 1 queues (1 buckets) droptail
   mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
BKT Prot ___Source IP/port____ ____Dest. IP/port____ Tot_pkt/bytes Pkt/Byte Drp
  0 tcp      74.6.68.227/42040   202.146.228.9/80    5535  3192733  0   0   0
00002:  68.000 Kbit/s    0 ms    6 sl. 0 queues (1 buckets) droptail
   mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
00003:  36.000 Kbit/s    0 ms    6 sl. 0 queues (1 buckets) droptail
   mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
q00001: weight 50 pipe 2    6 sl. 6 queues (64 buckets) droptail
   mask: 0x00 0x00000000/0x0000 -> 0xffffffff/0x0000
BKT Prot ___Source IP/port____ ____Dest. IP/port____ Tot_pkt/bytes Pkt/Byte Drp
 17 ip           0.0.0.0/0         192.168.1.1/0     81105 53885327  0   0  2960
 26 ip           0.0.0.0/0        192.168.1.10/0     121939 96279102  0  0  3719
 27 ip           0.0.0.0/0        192.168.1.11/0     134476 96276870  0  0  6141
 28 ip           0.0.0.0/0        192.168.1.12/0     35325 17986730  0   0  1243
 29 ip           0.0.0.0/0        192.168.1.13/0     43479 35034555  0   0  1247
 34 ip           0.0.0.0/0        192.168.1.50/0     154963 152289033  0  0 8521
q00002: weight 50 pipe 3    6 sl. 6 queues (64 buckets) droptail
   mask: 0x00 0xffffffff/0x0000 -> 0x00000000/0x0000
BKT Prot ___Source IP/port____ ____Dest. IP/port____ Tot_pkt/bytes Pkt/Byte Drp
 12 ip      192.168.1.50/0             0.0.0.0/0     128724 17526438  0  0  211
 42 ip       192.168.1.1/0             0.0.0.0/0     71625  8097141  0   0  592
 48 ip      192.168.1.12/0             0.0.0.0/0     28546  2747603  0   0  131
 50 ip      192.168.1.13/0             0.0.0.0/0     32582  3594117  0   0  29
 60 ip      192.168.1.10/0             0.0.0.0/0     102737 10325047  0  0  73
 62 ip      192.168.1.11/0             0.0.0.0/0     89624  8851578  0   0  100
Kolom paling kanan pertanda paket yg sudah didrop, uji gampangnya lihat saja jika kita download gede2an (pake getright/flashget) pasti banyak yg didrop sesuai dengan perhitungan diatas. Dan silahkan coba download dengan cara dilimit di client (pake getright/flashget misalnya) sesuei dengan perhitungan diatas, nah gimana hasilnya tuh :-).

Sistem kerjanya, andaikata host A menggunakan bandwidth melebihi kapasitas sharing bandwidth bedasarkan perhitungan diatas dan host B pada saat bersamaan mulai ngeload bandwidth (katakanlah mulai ngeclick browser) maka host A akan didrop secara random untuk memberikan kesempatan kepada host B sampai kedudukannya seimbang (katakanlah jika bandwidth 128 Kbit/s maka host A akan mendapatkan 64 Kbit/s dan host B akan mendapatkan 64 Kbit/s), dan ketika host B tidak ngeload bandwidth (idle) maka host A akan mendapatkan bandwidth 128 Kbit/s kembali.

04 Juni 2013

Merubah Tipe File Windows Ke UNIX

1. Caranya beginoh:
# perl -i.bak -npe 's/\r\n/\n/g' file ...
2. Atau bisa kita pake:
# tr -d '\r' < dos-text-file > unix-file
3. Atau bisa juga:
# col -b < dos-text-file > unix-text-file

26 Mei 2013

Console UNIX Berwarna

1. Silahkan porting:
# cd /usr/ports/misc/gnuls/
# make ; make install
2. Bikin alias di ~/, kalo root pake .bashrc, sedangkan user pake .bash_profile.
# cat .bashrc
alias ls='gnuls --color=auto -a'
$ cat .bash_profile
alias ls='gnuls --color=auto -a'

07 Maret 2013

ARCHIVER dan COMPRESSION di UNIX

Untuk create archiver di UNIX menggunakan perintah tar, untuk aplikasi kompresi menggunakan gzip/gunzip.

1. Misalnya kita akan bikin archive file maka:
  $ tar cvf file.tar .
Note: c=[c]reate, v=[v]erbose, f=[f]ile, titik[.] menunjukan current directory atau direktori aktif sekarang. Jadi jika anda pengen bikin archive dng nama direktori "coba", anda bikin dulu direktori "coba" setelah itu anda masukan file2 yg hendak anda archiving ke direktori itu (coba), selanjutnya anda masuk ke direktori "coba" lalu lakukan perintah diatas. karena defaultnya tar ngebackup (melihat) device (tape) /dev/sa0, padahal kita sebenernya ingin bikin archive di darektori aktif sehingga otomatis proses kita akan gagal dengan itu maka kita perlu pake option [f]ile untuk mengarahkan archive kita. output errornya: tar: can't open /dev/sa0 : Device not configured

2. Setelah terbentuk file.tar maka kita lakukan pengecekan:
  $ tar tf file.tar atau $tar tf file.tar | more
Note: Untuk option [f]ile sama halnya dng kejadian diatas, kalo nggak maka akan nampilin error yg sama persis.

3. Nah sekarang archive kita ingin kita kompres sbg contoh:
  $ gzip -c9v file.tar > file.tar.gz
4. Sebetulnya tar juga sudah membawa untuk "filtering" direct ke bentuk file compression cuma untuk customize kompresi tidak selengkap jika kita pisah dng 2 proses (proses tar dan proses gzip). Misalnya untuk proses tar langsung difilter thd kompresi:
  $ tar zcvf foo.tgz * atau
  $ tar zcvf foo.tar.gz *
Secara otomatis foo.tgz dan foo.tar.gz akan terbentuk, jangan lupa untuk mengecheck kalo2 archivenya rusak. dengan cara mirip dengan langkah diatas:
  $ tar ztvf foo.tgz atau
  $ tar ztvf foo.tar.gz
5. Untuk mengecheck apakah proses yg kita lakukan benar, kita check dng cara:
  $ tar tfzv file.tar.gz atau $tar tfzv file.tar.gz | more
Note: Kita lakukan kompresi dng menggunakan gzip/gunzip. untuk options c=[c]reate, 9=kompresi paling baik, v=[v]erbose, z=untuk nampilin kompresi, untuk f sama keterangannya ama yg diatas.

6. Jika anda menggunakan archiver sekaligus kompresi model *.zip, maka di UNIX telah disediakan toolnya yaitu zip dan unzip untuk sebaliknya. Misalnya kita akan create test.zip di direktori /etc maka:
  $ cd /etc
  $ zip -r -v -9 test.zip *
Jika anda ingin menencrypt isi arsip bisa gunakan -e [encrypt]
  $ zip -r -v -e -9 test.zip *
Note: Opsi -r[ecrusive], -v[erbose], -9 [Best Compression], dan untuk Asterik (*) menunjukan "current directory". Untuk membuka anda bisa gunakan "unzip" misalanya:
  $ cd /tmp
  $ unzip test.zip
Jika anda ingin membuat archive "hanya untuk file tertentu", anda bisa gunakan beberapa options, sebagai contoh:
  $ zip -c -v -9 /hasil/file/foo.zip -j /target/config/source.conf
Dengan perintah diatas maka kita akan meletakan foo.zip di dalam direktori /hasil/file/ dengan mengambil source.conf (file yang mau dizip) di direktori /target/config/, dengan option -j maka "full path dari source.conf direktori tidak akan di zip".

7. Menggunakan compresi bzip/bzip2, Anda bisa menggunakan ekstensi *.tar.bz, *.tar.bz2, *.tbz sebagai contoh.
  $ tar -cvf backup.tar *
  $ bzip -cvf backup.tar > backup.tar.bz atau
  $ bzip2 -cvf backup.tar > backup.tar.bz2
Untuk bzip hasil akhir berekstensi *.bz, sedangkan untuk bzip2 hasil akhir berekstensi *.bz2, nah selain itu ada beberapa contoh dengan fasilitas "filtering" via kompresi misalnya:
  $ tar -ycvf backup.tbz * atau
  $ tar -ycvf backup.tar.bz *
Dan untuk bzip2:
  $ tar -ycvf backup.tar.bz2 *
Untuk pengechekan kita bisa gunakan perintah spt:
  $ tar ytvf backup.tbz
  $ tar ytvf backup.tar.bz
  $ tar ytvf backup.tar.bz2
Untuk pengekstrakan *.tbz, *.bz, *.bz2 lakukan spt:
  $ tar yxvf backup.tbz
  $ tar yxvf backup.tar.bz
  $ tar yxvf backup.tar.bz2
PS: Untuk options dan keterangan lebih lanjut anda bisa baca manual gzip/gunzip, bzip/bzip2, zip, unzip dan tar.

09 Januari 2013

Intisari IPFILTER

ipf melihat rule yg dilist secara berurutan dari atas ke bawah. Misalnya:
block in all....(1)
pass in all.....(2)
Pertama akan dijalankan rule (1), setelah itu rule (2). Jadi otomatis hasilnya rule (2) alias paket boleh masuk. Rule2 yg bertumpuk seperti. Misalnya:
block in all....(1)
block in all....(2)
block in all....(3)
block in all....(4)
block in all....(5)
pass in all.....(6)
Rule (1) s/d (4) tidak ada faedahnya. Dengan quick kita dapat meyederhanakan rule2 kita. Misalnya:
block in quick all...(1)
pass in all..........(2)
Bisa kita artikan rule (1) akan dilihat pertama, selanjutnya ipf melaksanakan ketentuan semua rule tsb sampe selesai baru rule (2). Penulisan subnet IP yg diperbolehkan adalah 255.255.0.0 atau /16. Misalnya:
block in quick from 192.168.0.0/16 to any
atau
block in quick from 192.168.0.0/255.255.0.0 to any
Kita dapat mengunakan keyword on untuk menspesifikan interface yg kita pake. Misalnya:
block in quick on xl0 all
atau
block in quick on xl0 from 192.168.0.0/16 to any
Kita dapat menentukan juga outgoing paket dng nama keyword out. Misalnya:
pass out quick on xl0 from 192.168.0.0/16 to any
Jika kita ingin melogkan apa yg terjadi, maka ada baiknya kita gunakan keyword log. Misalnya:
block in log quick on xl0 from 192.168.0.0/24 to any
Keyword proto dapat kita gunakan untuk menspesifikan protocol yg kita pake berikut dengan tipe protocolnya. Backslash (\) dapat kita pake untuk menyambung perintah pada line berikutnya. Misalnya:
block in log quick on xl0 proto icmp from any to any
atau
pass in quick on xl0 proto icmp from any to 192.168.0.0/24 \
icmp-type 0
Pengunaan keyword port lebih menitik beratkan kepada port yg dilalui. Misalnya:
block in log quick on tun0 proto tcp from any to \
192.168.0.0/24 port = 22
Untuk membangun rule2 yg sangat kuat ada baiknya kita kompile kernel dengan default deny all, shg kita list rule yg kita perlu (This my fav). Kita mulai dengan rule deny kayak gini. Misalnya:
block in all
block out all
Nah baru kita listing rule2 yg diperbolehkan. Misalnya:
pass in quick on xl0 proto tcp from any to 192.168.0.1/24 \
port = 80
Arti rule tsb adalah membolehkan paket yg masuk di ethernet xl0 dengan jenis protocol tcp dari mana saja ke 192.168.0.1/24 lewat port 80 (www). Jika ada respon dari 192.168.0.1/24 akan tetep ditolak juga, maka agar terjadi komunikasi (tidak pincang) maka kita listing juga rule sebaliknya. Misalnya:
pass out quick on tun0 proto tcp from 20.20.20.1/32 \
port = 80 to any
Ada keyword yg sangat menarik disini yaitu keep-state, jika rule kita dibubuhi keep-state ini berati rule tersebut dah masuk ke state table ipf, sehingga ipf tidak perlu lagi mengecek ulang validasi rule tersebut alias jika terjadi handshake di kemudian hari ipf akan langsung mengijinkan masuk. Misalnya:
pass out quick on xl0 proto tcp from 192.168.0.1/24 to any \
keep state
Artinya adalah mengijinkan paket yg keluar di xl0 dengan protocol tcp dari 192.168.0.1/24 ke mana saja, dengan keep-state ini rule yg bersangkutan langsung di apply ke state table dan ipf tidak akan ikut campur nggak akan ngecheck ulang lagi validasi. ini terjadi pas pertama kali SYN paket menyentuh hand shake server kita. Sangat delematis kita menggunakan keep-state, coba kita pikirkan baik2 akan muncul pertanyaan dibenak kita "Oh..kalo gitu ipf hanya mengenal SYN yg dulu dung, dengan kata lain SYN pas entry ke state table pertama kali..?", yups memang benar meski ipf akan close (idle)selama 60 detik (1 menit) tapi bukan refresh. dengan kata lain paket SYN-nya basi. ini pun berlaku untuk koneksi TCP selanjutnya misalnya yg lainya (FIN, XMAS etc) setelah handshake terjadi. Untuk masalah diatas tentunya ada solusi tersendiri. dengan penambahan keyword flags alias menspesifikan flags untuk TCP. Misalnya:
pass in quick on tun0 proto tcp from any to 192.168.0.1/24 \
port = 23 flags S keep state
Artinya rule diatas akan hanya melihat flags TCP SYN saja untuk flags lainya (FIN, XMAS etc) tentunya akan keblock.
 Berikut 6 flags TCP:
  +----------------------------------+--------------+
  |Singkatan dari koneksi TCP/IP     |     Flags    |
  +----------------------------------+--------------+
  |         SYN                      |       S      |
  |         URG                      |       U      |
  |         PUSH                     |       P      |
  |         FIN                      |       F      |
  |         RST                      |       R      |
  |         ACK                      |       A      |
  +----------------------------------+--------------+
Jika kita menulis flags S bisa kita tulis S/SUPFRA. dengan kata lain paket hanya cocok flags S. Misalnya: Jika kita tulis flags S/SA artinya match dengan S dan
flags "UPFR"...(1)
Jika kita tulis flags S/SAUP artinya match dengan S dan
flags "FR".....(2)
Dalam perjalan paket tersebut tidak jarang terpecah-pecah (fragmention) Untuk mengatisipasi tentunya ipf telah menyediakan, yaitu dengan keyword keep frags (tanpa tanda '-'). Misalnya:
pass in quick on xl0 proto tcp from any to 192.168.0.1/32 \
port = 23 flags S keep state keep frags
Keyword return-rst berguna untuk merespon jika service tidak tersedia. return-rst hanya berlaku untuk jenis protocol TCP. Misalnya:
block return-rst in log proto tcp from any to 192.168.0.0/24 \
port = 23
Hasilnya untuk rule diatas adalah connection refused. Ada keyword return-icmp(jenis_error). Misalnya:
block return-icmp(port-unr) in log quick on tun0 proto udp \
from any to 192.168.0.0/24 port = 111
Untuk jenis_error kita pake port-unr (port unreachable). Selain respone block paket spt diatas ipf menyediakan keyword return-icmp-as-desta. Misalnya:
block return-icmp-as-dest(port-unr) in log on tun0 proto udp \
from any to 192.168.0.1/24 port = 111
Jika anda ingin mengatur log, kita bisa gabungkan dengan Syslog. ada keyword log level. Misalnya:
block in log level auth.info quick on xl0 from 192.168.0.1/24 to 
any port = 22
Jika anda mau mendapatkan informasi log header gunakan keyword log body pada proses ini ipf akan memberikan 128 bytes pertama dari paket. Untuk mempersingkat/efesiensi rule, kita bisa bikin kelas2 nah dengan mengunakan pasangan keyword head dan group. Misalnya:
block out quick on xl0 all head 10 ...(1)
pass out quick proto tcp from any to 192.168.0.1/24 port = \
80 flags S keep state group 10 .......(2)
Jika paket bukan untuk xl0, make nggak akan match dengan rule (1) dan rule (2) dan sebaliknya jika match maka akan dieksekusi rule (2) dan rule2 lainya yg mempunyai keyword group 10. artinya jika kita mempunyai network yg cukup besar dengan macam2 rule tentunya kita sedikit kewalahan dengan head dan group kita bisa membagi rule tersebut menjadi tree style. Misalnya:
block out quick on xl0 all head 1 ...(1a)
pass out quick proto tcp from any to 192.168.0.1/24 port = \
80 flags S keep state group 1 .......(2a)

block out quick on xl1 all head 2 ...(1b)
pass out quick proto tcp from any to 192.168.0.2/24 port = \
80 flags S keep state group 2 .......(2b)
Jika ada paket dengan cocok dengan rule (xa) make untuk kelompok rule (xb) akan diabaikan, dan sebaliknya tentunya ini akan menambah efesiensi kerja ipf kita. Jika kita lakukan traceroute dari mesin luar ke mesin kita secara default kita mendapatkan hop2 routing tersebut, ada yg menarik dari ipf ini salah satunya keyword fastroute, dengan keyword ini kita bisa menyembunyikan informasi2 hop tersebut. Misalnya:
block in quick on xl0 fastroute proto udp from any to any \
port 33434 >< 33465
Hal ini terjadi karena ada proses penurunan Time To Live (TTL) dari paket Acknowledging (ACK). Catatan:
<     : Lebih kecil
>     : Lebih besar
=     : Sama dengan
<=    : Lebih kecil sama dengan
>=    : Lebih besar sama dengan
!=    : Tidak sama dengan
<>    : Kurang dari X, lebih dari X
><    : Lebih besar dari X, kurang dari X

25 September 2012

Twitter Webbase Client

Bermula dari permintaan si cinta @DiahEstiani yg meminta via/from custom dari apps twitter, maka yang terpikir oleh saya adalah bagaimana menyajikan bentuk webbase yang kompatibel dan mudah digunakan. Sebelomnya saya sudah membikinnya tapi hanya posting saja tentunya ini bikin ribet dan sulit untuk pemakai.

Maka saya iseng-iseng mencari webbase untuk client webbase dan tentunya bertajuk Open Source, setelah berhari-hari saya mendapatkan Dabr, untuknya bukan cuma webbase untuk digunakan di Desktop saja, featurenya bisa untuk mobile juga. Setup Dabr ini tidaklah terlalu sulit, hanya 3 langkah saja (Register Apps di dev.twitter.com, setup webserver di hostingan, dan Dabr itu sendiri).

Yang dibutuhkan untuk register API Twitter:
  • Name: (yg selanjutnya menjadi nama app anda, via/from di twitter)
  • Website: (Jika diklik di apps via/from akan dilinkan kemana)
  • Application type: Read, Write and Access direct messages
  • Consumer key:
  • Consumer secret:
Selanjutnya kita siapkan hostingan, Dabr tidak menyimpan Username/Password, melainkan langsung diproses oleh Oauth twitter. System yang dibikin oleh dev Twitter untuk keamanan dan menghindari pihak ke 3 untuk mencuri data-data yang bersifat privasi. Beberapa persyaratan yg harus dipenuhi untuk ngehosting Dabr adalah:
dsb) Setup Dabr, yg diperlukan hanya Consumer key dan Consumer secret, kita letakan di config.php.
budsz:~/a$ fetch http://dabr.googlecode.com/files/dabr-r430.zip dabr-r430.zip
budsz:~/a$ ls -l
total 88
drwxr-xr-x   3 budsz  poison    512 Sep 25 14:31:38 2012 .
drwxr-xr-x  26 budsz  poison   1536 Sep 25 14:30:47 2012 ..
drwxr-xr-x   5 budsz  poison    512 Sep 25 14:31:34 2012 dabr
-rw-r--r--   1 budsz  poison  82709 Aug 16 19:15:20 2011 dabr-r430.zip
budsz:~/a$ unzip dabr-r430.zip
Archive:  dabr-r430.zip
d dabr
extracting: dabr/.htaccess
extracting: dabr/.project
extracting: dabr/about.html
d dabr/browsers
extracting: dabr/browsers/bigtouch.css
extracting: dabr/browsers/bigtouch.php
extracting: dabr/browsers/blackberry.php
extracting: dabr/browsers/desktop.php
extracting: dabr/browsers/list.csv
extracting: dabr/browsers/text.php
extracting: dabr/browsers/touch.css
extracting: dabr/browsers/touch.js
extracting: dabr/browsers/touch.php
extracting: dabr/browsers/worksafe.php
d dabr/common
extracting: dabr/common/advert.php
extracting: dabr/common/Autolink.php
extracting: dabr/common/browser.php
extracting: dabr/common/Embedly.php
extracting: dabr/common/Extractor.php
extracting: dabr/common/HitHighlighter.php
extracting: dabr/common/lists.php
extracting: dabr/common/menu.php
extracting: dabr/common/OAuth.php
extracting: dabr/common/Regex.php
extracting: dabr/common/settings.php
extracting: dabr/common/theme.php
extracting: dabr/common/twitter.php
extracting: dabr/common/user.php
extracting: dabr/config.sample.php
d dabr/images
extracting: dabr/images/dabr.png
extracting: dabr/images/dm.png
extracting: dabr/images/dmL.png
extracting: dabr/images/map.png
extracting: dabr/images/mapL.png
extracting: dabr/images/q.png
extracting: dabr/images/qL.png
extracting: dabr/images/reply.png
extracting: dabr/images/replyall.png
extracting: dabr/images/replyallL.png
extracting: dabr/images/replyL.png
extracting: dabr/images/retweet.png
extracting: dabr/images/retweeted.png
extracting: dabr/images/retweetedL.png
extracting: dabr/images/retweetL.png
extracting: dabr/images/star.png
extracting: dabr/images/starL.png
extracting: dabr/images/star_grey.png
extracting: dabr/images/star_greyL.png
extracting: dabr/images/trash.gif
extracting: dabr/images/trashL.png
extracting: dabr/images/twitter_button_2_lo.gif
extracting: dabr/index.php
Rubah permission untuk setiap filenya dulu:
budsz:~/a/$ cd dabr
budsz:~/a/dabr$ find . -type f -exec chmod 644 *.* {} \;
budsz:~/a/dabr$ cp config.sample.php config.php
Edit file config.php, isi dengan data-data yg sudah didapatkan ketika kita registrasi apps di Twitter:
// OAuth consumer and secret keys. Available from http://twitter.com/oauth_clients
define('OAUTH_CONSUMER_KEY', 'Isi_dengan_Consumer_key_anda');
define('OAUTH_CONSUMER_SECRET', 'Isi_dengan_Consumer_secret_anda');
Sisanya bisa anda setting sesuai dengan kebutuhan anda seperti
// API key for Twitpic - sign up at http://dev.twitpic.com/
define('TWITPIC_API_KEY', '');
// bit.ly login and API key for URL shortening
define('BITLY_LOGIN', '');
define('BITLY_API_KEY', '');
Setelah itu kita perlu melakukan Rewrite dari webserver kita, tergantung webserver apa yang anda pake, saya menggunakan Lighttpd dengan syntax sbb:
$HTTP["host"] =~ "subdomain\.domain\.tld" {
    dir-listing.exclude = ( "favicon.ico" )
    server.document-root = "/path/to/wwwdir"
    url.rewrite-if-not-file = (
                                "^/w/(.*)\?(.*)$"   => "/w/index.php?q=$1&$2",
                                "^/w/(.*)$"         => "/w/index.php?q=$1",
    )
}
DONE!

22 Juli 2012

Shell Scripting Twitter's Bot

Iseng-iseng gak ada kerjaan, saya coba untuk ngetwit auto dengan menggunakan scripting sederhana digabung dengan Python Twitter Tools, ujungnya menghasilkan kinerja yang lumayan memuaskan. Berikut deskripsinya: "The Minimalist Twitter API for Python is a Python API for Twitter, everyone's favorite Web 2.0 Facebook-style status updater for people on the go".

Pertama login di shell lalu lakukan download dan pengekstrakan:
budsz:~$ fetch http://pypi.python.org/packages/source/t/twitter/twitter-1.8.0.tar.gz
budsz:~$ tar zxvf  twitter-1.8.0.tar.gz
Sehingga terbentuk direktori twitter-1.8.0
budsz:~$ ls -ld twitter-*
drwxr-xr-x  6 budsz  poison  512 Jul 22 15:27:08 2012 twitter-1.8.0
Ada beberapa hal yang perlu anda edit, jika anda menggunakan Twitter API, yaitu file-file yang digunakan untuk autentifikasi Oauth twitter. Disini saya tidak akan menjelaskan pembuatan Twitter API, silahkan ngerefer ke site Twitter Developers. Pertama silahkan edit file:
budsz:~$ vim twitter-1.8.0/twitter/cmdline.py
Edit bagian CONSUMER_KEY dan CONSUMER_SECRET, isi nilainya dengan Apps yang sudah anda buat sebelomnya.
CONSUMER_KEY='your_consumer_key'
CONSUMER_SECRET='your_consumer_secret'
Untuk penginstallan dibutuhkan SetupTools, silahkan sesuaikan dengan kebutuhan anda. Selanjutnya tinggal lakukan proses penginstalan dengan root access untuk SetupTools/twitter-1.8.0.tar.gz:
root:~# cd /usr/ports/devel/py-setuptools
root:~# make install clean
root:~# pkg_info | grep py26
py26-setuptools-0.6c11_3 Download, build, install, upgrade, and uninstall Python packages
root:~# easy_install ~budsz/twitter-1.8.0
Note: Jika anda tidak mempunyai Apps silahkan langsung loncat proses instalasi saja yang anda kerjakan.

Uji coba, login kembali menggunakan user biasa:
budsz:~$ twitter -h (Untuk command line help)
budsz:~$ twitter (Login spt diweb, masukan user/password, setelah itu exit maka akan diminta PIN cukup tekan enter saja, defaultnya disimpan di ~$HOME/$USER/.twitter_oauth)
Untuk menggunakan di console/shell:
budsz:~$ twitter set "Hello World!" (Posting new twit)
budsz:~$ twitter search "cinta" (Seaching keyworld di public)
budsz:~$ twitter rate
Remaining API requests: 350 / 350 (hourly limit)
Next reset in 3544s (Sun Jul 22 17:38:01 2012)
Implementasi untuk auto posting anda tinggal gabungin dengan fasilitas cron(8) dan Shell scripting.

18 Maret 2012

H264 Streaming Dengan Lighttpd

Selama ini saya menggunakan file-file yang berformat FLV untuk streaming video LAN. Sayangnya ada beberapa video bagus tapi berformat MP4, nah permasalahannya bagaimana jika ingin menggunakan file berformat MP4. Berikut saya akan share beberapa caranya, seperti biasa saya bertanya ke Google, akhirnya dapet juga trik jitu. Saya menggunakan Lighttpd H264 untuk streaming MP4-nya. Untuk mempercepat produktifitas saya menggunakan ports saja. Install Lighttpd via ports (Cukup dibuild saja).
root:~# cd /usr/ports/www/lighttpd
root:/usr/ports/www/lighttpd# make
Download module versi terakhir:
root:~# fetch http://h264.code-shop.com/download/lighttpd-1.4.18_mod_h264_streaming-2.2.9.tar.gz
root:~# tar zxvf lighttpd-1.4.18_mod_h264_streaming-2.2.9.tar.gz
root:~# cd lighttpd-1.4.18/src/
root:~# cp mod_h264_streaming.c /usr/ports/www/lighttpd/work/lighttpd-1.4.30/src/
root:~# cp mod_streaming_export.h /usr/ports/www/lighttpd/work/lighttpd-1.4.30/src/
root:~# cp moov.c /usr/ports/www/lighttpd/work/lighttpd-1.4.30/src/
root:~# cp moov.h /usr/ports/www/lighttpd/work/lighttpd-1.4.30/src/
root:~# cp mp4_io.c /usr/ports/www/lighttpd/work/lighttpd-1.4.30/src/
root:~# cp mp4_io.h /usr/ports/www/lighttpd/work/lighttpd-1.4.30/src/
root:~# cp mp4_reader.c /usr/ports/www/lighttpd/work/lighttpd-1.4.30/src/
root:~# cp mp4_reader.h /usr/ports/www/lighttpd/work/lighttpd-1.4.30/src/
root:~# cp mp4_writer.c /usr/ports/www/lighttpd/work/lighttpd-1.4.30/src/
root:~# cp mp4_writer.h /usr/ports/www/lighttpd/work/lighttpd-1.4.30/src/
root:~# cp mp4_process.c /usr/ports/www/lighttpd/work/lighttpd-1.4.30/src/
root:~# cp mp4_process.h /usr/ports/www/lighttpd/work/lighttpd-1.4.30/src/
root:~# cp output_bucket.c /usr/ports/www/lighttpd/work/lighttpd-1.4.30/src/
root:~# cp output_bucket.h /usr/ports/www/lighttpd/work/lighttpd-1.4.30/src/
root:~# cp output_mp4.c /usr/ports/www/lighttpd/work/lighttpd-1.4.30/src/
root:~# cp output_mp4.h /usr/ports/www/lighttpd/work/lighttpd-1.4.30/src/
Tambahkan Makefile.am di /usr/ports/www/lighttpd/work/lighttpd-1.4.30/src/
lib_LTLIBRARIES += mod_h264_streaming.la
mod_h264_streaming_la_SOURCES = mod_h264_streaming.c \
mod_streaming_export.h \
moov.c moov.h \
mp4_io.c mp4_io.h \
mp4_reader.c mp4_reader.h \
mp4_writer.c mp4_writer.h \
mp4_process.c mp4_process.h \
output_bucket.c output_bucket.h \
output_mp4.c output_mp4.h
mod_h264_streaming_la_CFLAGS = $(AM_CFLAGS) -DBUILDING_H264_STREAMING
mod_h264_streaming_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined
mod_h264_streaming_la_LIBADD = $(common_libadd)
Lakukan penginstalan Lighttpd
root:/usr/ports/www/lighttpd# make install clean
Edit/tambahkan option yang diperlukan untuk lighttpd.conf
root:~# vim /usr/local/etc/lighttpd/lighttpd.conf
server.modules              = (....................
                              "mod_h264_streaming",
                               ....................
)

# MP4 streaming
h264-streaming.extensions = ( ".mp4" )
Edit dan jalankan startup script
root:~# vim /usr/local/etc/rc.d/lighttpd
Edit : ${lighttpd_enable="NO"} menjadi : ${lighttpd_enable="YES"}
root:~# /usr/local/etc/rc.d/lighttpd start
root:~# ps ax | grep lighttpd
72915  ??  S       0:00.74 /usr/local/sbin/lighttpd -f /usr/local/etc/lighttpd/lighttpd.conf
9444  p0  S+     0:00.00 grep lighttpd

02 Februari 2012

Bikin Mirror Update Kaspersky Antivirus

Sering kali kita direpotkan dengan update Kaspersky Antivirus yang cukup makan waktu, ditambah koneksi yang lemot mungkin bikin anda pegel-pegel. Banyak aplikasi yang memudahkan untuk kebutuhan ini, tapi saya mencoba dengan cara lain ( Yang ada di otak saya.baca ) dan terbilang cara ini manual, tapi cukup ampuh dan sederhana. Pertama-tama untuk kebutuhan ini perlu anda siapkan:
  • Webserver local.
  • Scripting.
  • Otomatis update per satuan waktu dengan cron.
Diasumsikan webserver sudah ready ( Saya menggunakan Lighttpd under FreeBSD ), saya coba memonitor path file apa saja yang diperlukan untuk update Kaspersky Antivirus 2011, anda bisa menggunakan bitanalyzer, tcpdump, URLSnooper, Wireshark dsb. Setelah itu saya coba bikin script sederhana:
budsz:~$ mkdir kav ; cd kav
budsz:~/kav$ cat kav.sh
#!/bin/sh
WGETBIN="wget -m -nH -N -R *.html"
BASEURL="ftp://dnl-00.geo.kaspersky.com"
CURDIR="/home/budsz/kav"
cd $CURDIR
for LISTDIR in \
        AutoPatches/kav11 \
        bases/apu \
        bases/av/ark \
        bases/av/emu \
        bases/av/kdb/i386 \
        bases/av/qscan \
        bases/av/wa \
        bases/blst \
        bases/dnscln \
        bases/ids \
        bases/info \
        bases/klifppcfg \
        bases/ksn \
        bases/pdm \
        bases/sco/i386/win \
        bases/ssa \
        bases/sw2 \
        bases/uds \
        bases/upd \
        bases/vlns \
        bases/wmuf \
        diffs/bases/apu \
        diffs/bases/av/emu/i386 \
        diffs/bases/av/kdb/i386 \
        diffs/bases/blst \
        diffs/bases/dnscln \
        diffs/bases/klifppcfg \
        diffs/bases/ksn \
        diffs/bases/pdm \
        diffs/bases/sco/i386/win \
        diffs/bases/uds \
        diffs/bases/wmuf \
        index
do

# Looping untuk downloading
$WGETBIN $BASEURL/$LISTDIR
        echo "----------------------------------"
        echo " Mirroring beres untuk: "$LISTDIR
        echo "----------------------------------"
done

# Hapus file '.listing'
find . -name ".listing" -delete
Script itu diberi nama kav.sh, lalu disimpan di directory kav. Setelah itu dijalankan secara automatic dengan menggunakan cron:
budsz:~$ crontab -l
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/root/
SHELL=/bin/sh
MAILTO=""
HOME=/var/log
0      7        *      *      *      /home/budsz/kav/kav.sh > /dev/null
Setiap jam 7.00 melakukan update dengan main server. Biar lebih enak dilihat, anda bisa bikin virtual domain/host di lighttpd.conf:
$HTTP["host"] =~ "av\.example\.net" {
     dir-listing.exclude = ( "favicon.ico" )
     server.document-root = "/home/budsz/kav"
}
Dan A Record atau CNAME di Bind:
budsz:~$ host av.example.net
av.example.net has address 172.16.135.145
Setelah selesai tinggal arahkan setting update server pada Kaspersky Antivirus:
  • Setting.
  • Update Setting.
  • Update Source.
  • Isikan http://av.example.net/ ( Checklist ).
  • Jangan lupa unchecklist Kaspersky Lab Update Server.
Nah, sudah deh beres -;)

15 Januari 2012

PF Dilema Rules

Saya mempunyai PF rules spt ini di /etc/pf.conf:
porthttp = "80"           # HTTP Port
portsquid = "7080"        # Squid Port
ifint0 = "rl0"            # Ethernet ke LAN
rdr pass on $ifint0 proto tcp from 192.168.0.0/24 to any port $porthttp -> $ipproxy port $portsquid
Rules diatas berguna untuk Redirection (RDR)/Transparent Proxy. Lalu saya mempunyai rules spt ini:
ipwebmodem = "{ 10.0.0.1/32, 10.1.0.1/32 }"
block  in     quick on $ifint0 proto tcp from 192.168.0.0/24 to $ipwebmodem port = 80
Hasil: block rules ke 2 tidak akan bekerja alias tidak akan keblock. Jika rules diatas dituker tentu tidak akan bisa karena Statement Order tidak valid. Cara ini bisa diakali dengan menambahkan Exception (Pengecualian) menggunakan table unproxy pada RDR rules, sehingga rules menjadi:
table  { 0.0.0.0/0, !10.0.0.0/30, !10.1.0.0/30 }
porthttp = "80"              # HTTP Port
portsquid = "7080"           # Squid Port
ifint0 = "rl0"               # Ethernet ke LAN

rdr pass on $ifint0 proto tcp from 192.168.0.0/24 to  port $porthttp -> $ipproxy port $portsquid

ipwebmodem = "{ 10.0.0.1/32, 10.1.0.1/32 }"
block in quick on $ifint0 proto tcp from 192.168.0.0/24 to $ipwebmodem port = 80
Terus terang dengan sistem seperti ini lumayan agak repot juga, jika ingin ngeblock site tertentu harus meng-unproxy dulu site tersebut. Lebih fleksible menggunakan IPFW untuk kepentingan spt ini, saya belum menemukan cara yg simple dengan menggunakan PF.

08 Januari 2012

Malas memahami ipfw(8)

Setelah otak atik, bahkan sampe switch untuk redirect packet untuk proxy-squid via packet filter OpenBSD, akhirnya ketemu juga cara yg lebih efesien/efektif, intinya "Terlalu malas untuk memahami man page ipfw(8)" :-(. Berikut salah satu study-casenya:
${fwcmd} add 30 fwd ${ipproxy},${portproxy} tcp from ${ipclproxy} to any dst-port ${porthttp} in via ${ifint0}
${fwcmd} add 52 pipe 2 ip from any to ${ipclient} via ${ifint0}
${fwcmd} add 53 pipe 3 ip from ${ipclient} to any via ${ifint0}
${fwcmd} pipe 2 config bw ${bwcldown} mask dst-ip 0xffffffff
${fwcmd} pipe 3 config bw ${bwclup} mask src-ip 0xffffffff
Kendala dengan ruleset spt diatas adalah traffic control loss artinya traffic yg lewat transparent proxy gak kena limit. Jika saya tuker ruleset diatas menjadi:
${fwcmd} add 52 pipe 2 ip from any to ${ipclient} via ${ifint0}
${fwcmd} add 53 pipe 3 ip from ${ipclient} to any via ${ifint0}
${fwcmd} pipe 2 config bw ${bwcldown} mask dst-ip 0xffffffff
${fwcmd} pipe 3 config bw ${bwclup} mask src-ip 0xffffffff
${fwcmd} add 70 fwd ${ipproxy},${portproxy} tcp from ${ipclproxy} to any dst-port ${porthttp} in via ${ifint0}
Kendalanya adalah traffic yg lewat kena limit tetapi transparent proxynya tidak jalan. Nah, dilematis memang jika running dalam satu masin yang sama. Cara yg ampuh adalah ngeset sysctl variable net.inet.ip.fw.one_pass=0, dengan ini artinya "paket yg masuk melalui dummynet/pipe
akan diterukan ke rule berikutnya.", jadi tetep rule dummynet harus sebelom rule transparent proxy ( Ruleset no 2 ). ( Big Thank To: Ian Smith ).

05 Januari 2012

DNS dan MRTG

Kalo lagi melamun kadang kebiasaan saya demen monitoring ini itu :-). Sekarang saya coba nambahin DNS request dan successful query. Pertama-tama ada perbedaan generate log stats untuk beberapa versi dari Bind. Disini saya menggunakan versi BIND 9.8.1-P1.
Di named.conf bagian options pastikan ada entry spt ini:
statistics-file "/var/stats/named.stats";
Setelah itu bikin sedikit script sederhana kurang lebih seperti ini:
#!/bin/sh
STATSTMP="/tmp/dnsstats"
STATSFILE="/var/named/var/stats/named.stats"
OLDQ=`grep QUERY $STATSFILE | awk '{print $1}'`
OLDS=`grep successful $STATSFILE | awk '{print $1}'`
rm -f /var/named/var/stats/named.stats
rndc stats
NEWQ=`grep QUERY $STATSFILE | awk '{print $1}'`
NEWS=`grep successful $STATSFILE | awk '{print $1}'`
DIFFQ=$(($NEWQ-$OLDQ))
DIFFS=$(($NEWS-$OLDS))
echo $DIFFQ
echo $DIFFS
Lalu, save file tersebut dan chmod 755. Bikin entry di file CFG MRTG anda kurang lebih spt ini:
Target[dnsstat]: `/usr/local/bin/dnsstat`
Title[dnsstat]: DNS Query/Success Answer
Colours[dnsstat]: DODGERBLUE#1E90FF,BLUE#0000FF,DODGERBLUE#1E90FF,BLUE#0000FF
RouterUptime[dnsstat]: local@localhost
MaxBytes[dnsstat]: 800
AbsMax[dnsstat]: 800
YTics[dnsstat]: 10
PageTop[dnsstat]: DNS Query/Success Answer
YLegend[dnsstat]: Query/Answer
ShortLegend[dnsstat]: Query/5 Min
LegendI[dnsstat]: Query
LegendO[dnsstat]: Answer
Options[dnsstat]: gauge, growright, avgpeak, integer, absolute, pngdate

Silahkan dicoba - Semoga berhasil :)