Monday, June 30, 2014

OpenWRT - Mount rootfs on External Storage

Unable to install more software on OpenWRT ? Below is how to extend the storage using USB drive.

1. What is need :
-OpenWRT Router with USB port
-Any USB Storage

2. opkg update
opkg install kmod-fs-ext4 kmod-usb-storage-extras block-mount

3. Create new partition on USB storage using gparted, 1st partition is Swap partition 64M ( size is depend on your router model, usually mem size x2), 2nd partition is ext3 partition.

4. Duplicate the rootfs to USB storage
root@OpenWrt:/etc/config# mkdir /mnt/usb
root@OpenWrt:/etc/config# mount /dev/sda2 /mnt/usb/
root@OpenWrt:/etc/config# mkdir /tmp/root
root@OpenWrt:/etc/config# mount -o bind / /tmp/root
root@OpenWrt:/etc/config# cp /tmp/root/* /mnt/usb -a
root@OpenWrt:/etc/config# umount /tmp/root/
root@OpenWrt:/etc/config# ls /mnt/usb/


5. Edit the fstab using ssh terminal / putty and add configs below.
# vi /etc/config/fstab
config 'mount'
        option 'target' '/mnt/usb'
        option 'device' '/dev/sda2'
        option 'fstype' 'ext3'
        option 'options' 'rw,sync'
        option 'enabled' '1'
        option 'is_rootfs' '1'
        option 'enabled_fsck' '1'
           
config 'swap'                    
        option 'device' '/dev/sda1'
        option 'enabled' '1'


6. reboot & verify


Friday, June 27, 2014

OpenVPN Server with ACS SmartCard

This is note on how to configure OpenVPN server with smartcard (PKCS11), with window client.

1. Install OpenVPN server, please refer HERE

2. Generate cert for client :
# ./build-key-pkcs12 client2
Generating a 1024 bit RSA private key
........................++++++
....................................++++++
writing new private key to 'client2.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [MY]:
State or Province Name (full name) [KL]:
Locality Name (eg, city) [Petaling Jaya]:
Organization Name (eg, company) [Test]:
Organizational Unit Name (eg, section) [server]:
Common Name (eg, your name or your server's hostname) [client2]:
Name [server]:
Email Address [me@test.com]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /etc/openvpn/easy-rsa/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'MY'
stateOrProvinceName   :PRINTABLE:'KL'
localityName          :PRINTABLE:'Petaling Jaya'
organizationName      :PRINTABLE:'Test'
organizationalUnitName:PRINTABLE:'server'
commonName            :PRINTABLE:'client2'
name                  :PRINTABLE:'server'
emailAddress          :IA5STRING:'me@test.com'
Certificate is to be certified until Jun 21 13:06:42 2024 GMT (3650 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
Enter Export Password:
Verifying - Enter Export Password:

copy all client2* file to window that installed ACS Cert Management Utility.

3. Import the client cert
3.1 plug the smartcard reader and login
3.2 Action  > Certificate Manager
3.3 Click import , select file that you copy just now. e.g client2.p12
3.4 When prompt to enter export password, enter the password enter during generate the cert, DO NOT LEAVE BLANK.


4. Install and Configure OpenVPN client.(without install gui)
4.1 download http://ovpnppc.ziggurat29.com/files/openvpn-gui-1.0.3-pkcs11.src.zip gui, this version will prompt  the pkcs11 pin where the official site verion won't.

4.2 Locate the middleware by the smartcard provider, my case is :
"C:\Program Files\Advanced Card Systems Ltd\ACOS5-CryptoMate Admin Client Kit\Mid dleware\x86\PKCS\>acospkcs11.dll"

4.2 Find the Serialized id.
openvpn --show-pkcs11-ids C:\Program Files\Advanced Card Systems Ltd\ACOS5-CryptoMate Admin Client Kit\Mid
dleware\x86\PKCS\acospkcs11.dll

The following objects are available for use.
Each object shown below may be used as parameter to
--pkcs11-id option please remember to use single quote mark.

Certificate
       DN:             C=MY, ST=KL, L=Petaling Jaya, O=Test, OU=server, CN=xp3,
name=server, emailAddress=me@test.com
       Serial:         04
       Serialized id:  Advanced\x20Card\x20Systems\x20Ltd\x2E/CTM64/603868942
/ACS\x20Card\x20OS\x205/F8892A3678F75A7E586BFBEF805F3CA80DD2



4.3  Add PKCS provider to openvpn config file

pkcs11-providers C:\Program Files\Advanced Card Systems Ltd\ACOS5-CryptoMate Admin Client Kit\Mid
dleware\x86\PKCS\acospkcs11.dll
pkcs11-id     'Advanced\x20Card\x20Systems\x20Ltd\x2E/CTM64/603868942
/ACS\x20Card\x20OS\x205/F8892A3678F75A7E586BFBEF805F3CA80DD2'


5. Run openvpn-gui and connect.



Wednesday, June 25, 2014

FB Invite all friends js script


elms=document.getElementById('fbpage_invite_audience_action_finch').getElementsByTagName('button');for(var fid in elms){if(typeof elms[fid] === 'object'){(elms[fid]).click();}}


Steps:

1. Launch Mozilla and load the Pages.

2.  Under invite friend click "See all friends"

3. Press F12 on keyboard > click on "Console" tab.

4. Paste the script above to console >>

5. Scroll down the friends list and repeat step 4.

Wednesday, June 11, 2014

Bluetooth module for old multimedia speaker


This is about how to adding Bluetooth feature to your old multimedia speaker.


Old phone charger with 5v output.


This AC-DC converter

Connect the phone charger board to 220AC on the speaker board

USB Bluetooth module


Connect the 5v output to Bluetooth USB input (pin 1(+) and pin 4 (-).

Connect the Bluetooth Aux out to speaker Aux input, above is Edifier R202 board.


Manually iron the AC input to phone charger board


Wrap the high voltage circuit for safely!!


Glue the charger board to panel


Glue the Bluetooth beside the charger board

Bluetooth speaker!!


Note: your speaker aux will not function properly because the bluetooth module will draw the power from it, if you want have both work you need extra switch to switch between Aux or bluetooth.

NiMh Charger Disassemble


This post is to dissemble NiMH charger to inspect the build quality, I only have 3 units, 2 from GP and 1 from unknown china brand. 

GP Fast Charge

China brand cheap charger

China brand cheap charger overview



Below 3 pictures is GP 4 position charger. 





Tuesday, June 10, 2014

Bash script to adjust laptop LCD backlight

##!/bin/bash

export blval=`sudo intel_backlight |awk '{print $4}' |sed 's/%//g'`
if  test "$1" = "up"
then
        echo "currrent val : $blval"
        export blval=`expr $blval + 10`
        echo "increase to $blval"
elif test "$1" = "down"
then
        echo "currrent val : $blval"
        export blval=`expr $blval - 10`
        echo "decrease to $blval"


else
        echo  "e.g adj_backlight.sh [ up | down ]"
fi

sudo intel_backlight $blval
exit