venerdì 24 agosto 2012

ANDROID - Remount Android rootfs RW via (ADB) Shell

To remount your root fs on android device as RW (read write) for any purpose without software to install on your devices, connect to your android phone via ADB or do it from internal Shell and type:

For RW roofs:

mount -o rw,remount -t rootfs rootfs /
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system


For RO rootfs:

mount -o ro,remount -t rootfs rootfs /
mount -o ro,remount -t yaffs2 /dev/block/mtdblock3 /system


Working on Samsung Galaxy S5570 (Mini/Next) and SonyEricsson Xperia X8.

Reference:
http://chuacw.ath.cx/blogs/chuacw/archive/2011/02/25/remounting-android-rootfs.aspx

giovedì 10 maggio 2012

UBUNTU - Shell converting a list of images to one pdf

This is one example of why I love Ubuntu , and generally Linux.
I have to convert a bounch of high resolution Jpeg files to a lower resolution and I suppose to convert them to pdf and I know that via shell I can do it really quickly avoiding installing programs and dealing with complex graphical interface for doing a so simple task.

In Ubuntu (or Linux) I need ONE COMMAND in shell!!!!

This is what to do: I must have 'convert' command working

convert Man Page


File to convert are File_001.JPEG,File_002.JPEG,......File_050.JPEG





fem@rodizio:~$ convert File_0*.JPEG Single_pdf.pdf  


That's all, I have in a simple pdf 50 pages (one for every image I had) in that case, ready to print.

giovedì 15 marzo 2012

Midori Web browser - Using SOCK5 proxy server

If you need to use a ssh secure tunnel (as explained here for example)you have to set the correct proxy SOCK5 server in your browser.
Unfortunately Midori web browser lacks of this feature out of the box, but as mentioned on the official faqs we can found a workaround.

Install tsocks:


user@user-laptop:~$ sudo apt-get install tsocks


Edit the /etc/tsocks.conf file:


user@user-laptop:~$ sudo vi /etc/tsocks.conf


Edit in this way :


# Default server
# For connections that aren't to the local subnets or to 150.0.0.0/255.255.0.0
# the server at 192.168.0.1 should be used (again, hostnames could be used
# too, see note above)

server = 127.0.0.1
# Server type defaults to 4 so we need to specify it as 5 for this one
server_type = 5
# The port defaults to 1080 but I've stated it here for clarity
server_port = 1080


In this example configuration the proxy server is the localhost, the proxy server is a Sock5 and the localhost port is 1080 (you can change port number how you prefer)

Then launch midori in this way from terminal:


user@user-laptop:~$tsocks midori


Thats all

sabato 10 marzo 2012

Vim - How to set TAB key to 4 spaces

To use Vim as editor (for python in my case) is better to set the tab space to 4 spaces instead the default 8 spaces.
Its pretty simple to do.
In Ubuntu 10.10 and similar simple add this 4 lines to /etc/vim/vimrc :


Open the file..

user@box:~$ sudo vi /etc/vim/vimrc


append these lines:

"--------Setting for 4 spaces TAB key------
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
"---------End of setting -----------------


Save and restart Vim and it should work.

venerdì 9 marzo 2012

wxPython - Sum 2 numbers tool



I modified a little example found on this nice website :

http://zetcode.com/wxpython/events/
The structure is simple, 2 input boxes and a button the get the result of the sum.
Obiouvsly you need wxPython installed to make it work.









This is the code:

 #!/usr/bin/python  
 # Sum of 2 numbers   
 import wx  
 class Sum_2_numbers(wx.Frame):  
     def __init__(self, parent, id, title ):  
         wx.Frame.__init__(self, parent, id, title, size=(320, 230))  
         wx.StaticText(self, -1, 'Number 1:', (30,25))  
         wx.StaticText(self, -1, 'Number 2:', (30,65))  
         wx.StaticText(self, -1, 'Sum:', (30,180))  
         self.in1 = wx.TextCtrl(self, -1, 'put a number', (100,20),size=(100,30))  
         self.in2 = wx.TextCtrl(self, -1, 'put a number', (100,60),size=(100,30))  
         self.st3 = wx.StaticText(self, -1, '', (100, 180))  
         self.Button = wx.Button(self, -1, "Sum !", wx.Point(80,120),size = (120,30))  
         self.Bind(wx.EVT_BUTTON, self.OnClick)  
         self.Centre()  
         self.Show(True)  
     def OnClick(self, event):  
         a = float(self.in1.GetValue())  
         b = float(self.in2.GetValue())  
         self.st3.SetLabel(str(a+b))  
 app = wx.App()  
 Sum_2_numbers(None, -1, 'Tool for summing 2 numbers...')  
 app.MainLoop()  

venerdì 17 febbraio 2012

Comandi vi

Comandi base vi

Comandi avanzati vi

UBUNTU - Add an entry to fstab (fat32 rw partition)

Quite simple task, anyway:
First of all give a look to your mounted filesystems, ok I want automatically at boot to mount the fat32 partition /dev/sda7 in the /media/DATA mount point.

fem@rodizio:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 206626768 33899652 162231052 18% /
none 1854844 304 1854540 1% /dev
none 1862524 284 1862240 1% /dev/shm
none 1862524 356 1862168 1% /var/run
none 1862524 0 1862524 0% /var/lock
none 1862524 0 1862524 0% /lib/init/rw
/dev/sda7 102348272 15804064 86544208 16% /media/DATA

create a mount point (in this case /media/DATA/ )

fem@rodizio:~$ sudo mkdir /media/DATA

generate the uuid number for the partition /dev/sda7

fem@rodizio:~$ sudo ls -l /dev/disk/by-uuid
total 0
lrwxrwxrwx 1 root root 10 2012-02-17 09:46 429CA4729CA461E1 -> ../../sda3
lrwxrwxrwx 1 root root 10 2012-02-17 09:46 7830198a-6c13-4b13-99ac-c6fe1eb15e80 -> ../../sda5
lrwxrwxrwx 1 root root 10 2012-02-17 09:46 9cf45b4e-2b01-4e70-806b-be488e4ebe59 -> ../../sda6
lrwxrwxrwx 1 root root 10 2012-02-17 09:46 C2C0A2A6C0A29FE1 -> ../../sda2
lrwxrwxrwx 1 root root 10 2012-02-17 09:46 C8D6A22CD6A21AA8 -> ../../sda1
lrwxrwxrwx 1 root root 10 2012-02-17 09:46 E9ED-DDA3 -> ../../sda7

So the uuid for the partition /dev/sda7 is E9ED-DDA3
Then edit /etc/fstab with vi or another editor.

fem@rodizio:~$ sudo vi /etc/fstab

and add this line:

UUID=E9ED-DDA3 /media/DATA/ vfat auto,umask=000 0 0

Note that "auto,umask=000 0 0" let you gain read/write permission on fat32 filesystem for the normal user.
Then reboot or give this command

fem@rodizio:~$ sudo mount -a

that's all

giovedì 9 febbraio 2012

iPhone 4 - How to pass AT Commands (and make a voice call)

My goal is to send a call via iPhone shell using AT commands.

I installed minicom from Cydia (but I think you could use other programs to "speak" with the serial interface of the phone).
I refer to this page
for more infos.
I found problems on serial port setup, i tryed these interfaces with no luck :

/dev/debug
/dev/dlci.spi-baseband.extra_13

I had a look in /dev folder and I found these interfaces:

iPhone4:/dev root# ls /dev
aes_0 io8logmt tty.highland-park
bpf0 klog tty.iap
bpf1 mux.spi-baseband tty.umts
bpf2 null ttyp0
bpf3 pf ttyp1
btreset ptmx ttyp2
btwake ptyp0 ttyp3
console ptyp1 ttyp4
cu.bluetooth ptyp2 ttyp5
cu.debug ptyp3 ttyp6
cu.gas-gauge ptyp4 ttyp7
cu.gps ptyp5 ttyp8
cu.highland-park ptyp6 ttyp9
cu.iap ptyp7 ttypa
cu.umts ptyp8 ttypb
disk0 ptyp9 ttypc
disk0s1 ptypa ttypd
disk0s2 ptypb ttype
disk0s2s1 ptypc ttypf
dlci.spi-baseband.call ptypd ttys000
dlci.spi-baseband.chatty ptype uart.bluetooth
dlci.spi-baseband.cl1 ptypf uart.debug
dlci.spi-baseband.extra_0 random uart.gas-gauge
dlci.spi-baseband.iq rdisk0 uart.gps
dlci.spi-baseband.low rdisk0s1 uart.highland-park
dlci.spi-baseband.pdp_0 rdisk0s2 uart.iap
dlci.spi-baseband.pdp_1 rdisk0s2s1 uart.umts
dlci.spi-baseband.pdp_2 sha1_0 urandom
dlci.spi-baseband.pdp_3 tty vn0
dlci.spi-baseband.pdp_ctl tty.bluetooth vn1
dlci.spi-baseband.reg tty.debug zero
dlci.spi-baseband.sms tty.gas-gauge
io8log tty.gps


I found /dev/dlci.spi-baseband.extra_0 working fine but honestly I cannot ensure it work for you too.

You have to setup minicom to work properly,

iPhone4:/dev root# minicom -s

then chose "Serial port setup" and press A and edit the line of the serial device (for me was that):

A - Serial Device : /dev/dlci.spi-baseband.extra_0

Type esc and "Save setup as dfl", then exit and type

iPhone4:/dev root# minicom -w

to connect to the phone.
Then type AT, if you receive an "OK" answer all is fine otherwise check "serial port setup" setting.
To make a call to the 3931111111 number simply type:

atd3931111111;

and to hang call

ath

To get iccid number (sim serial number)
type:

at+ccid

To get imei number.

at+cgsn


That's all.

mercoledì 8 febbraio 2012

iPhone 4 - How to automatically launch a script every fixed time. (Plist)

The goal is: launch my own script on my iphone every 300 seconds (5 minutes) for example.

Since the iPhone has no working cron deamon since 3.0 you can achieve it with the launchd deamon.
Launchd on Apple manpages
You have to have a running script, I suggest you to test it on iphone shell before going forward.
For example the script to launch could be this:

/var/root/scripts/hello


You have to create a .plist file in /System/Library/LaunchDaemons/ , I called it org.me.hello.plist
The hello.plist should be like this:

 <?xml version="1.0" encoding="UTF-8"?>  
 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">  
 <plist version="1.0">  
 <dict>  
 <key>Label</key>  
 <string>org.me.hello</string>  
 <key>ProgramArguments</key>  
 <array>  
 <string>/var/root/scripts/hello</string>  
 </array>  
 <key>RunAtLoad</key>  
 <true/>  
 <key>StartInterval</key>  
 <integer>300</integer>  
 </dict>  
 </plist>  

After that, you have to tell the system to load this new service hello.plist


iPhone4:~ root# launchctl load /System/Library/LaunchDaemons/org.me.hello.plist

Now your script should be launched automatically every 300 seconds (5 minutes) by the iPhone.

That's all.

mercoledì 1 febbraio 2012

Resizing (a lot of) images with a command.

I have to resize few pictures for a website, if you use Ubuntu you can use this command line tool called "mogrify" included in the "imagemagick" package.

To install it:

fem@rodizio:~$ sudo apt-get install imagemagick


Then, resize...

fem@rodizio:~$ cd /path/to/pictures/
fem@rodizio:~$ mogrify -resize 450x338 -format jpg *.jpg


Here I resize all jpg images I have in the folder to the 450x338 resolution, but you can change parameters how you prefer.


Note that this command will overwrite the previous pictures.
That's all

martedì 24 gennaio 2012

UBUNTU 10.04 - Hiding users at grafic login screen

I had a problem since I created some additional users for particular tasks but I didnt want they were shown in the login screen.
Edit this file

fem@rodizio:~$ sudo vi /etc/gdm/custom.conf


adding this lines

[greeter]
Exclude=user1,user2,user3,nobody

where user1, user2 and user3 are users to hide at login screen; nobody must be added otherwise it will be shown.
Then reboot..

lunedì 23 gennaio 2012

SOCKS5 Proxy for secure browsing

If you use to connect from open access internet points and you have a valid account on a SSH server , in my case I can use a simple modified router a Pirelli AGA (mounting linux and a valid SSH server) to do so.

From the shell of the client

fem@rodizio:~$ ssh USER_SERVERSSH@SERVERSSH -p 1022 -D 2100

"-p 1022" since my ssh service listen on this port (the default one is 22)
"-D 2100" tells the SSH client (localhost) to listen at this port to listen our browser requests.

We have only to go on browser settings (ie, opera, firefox ,chrome etc) and indicate that we use a socks5 proxy indicating as ip "localhost" and as port "2100"

that's all

OPENWRT - Reverse tunnel with SSH

I want to reach a router that is connected to the net using like gateway a USB dongle, the problem is that my network provider use a NAT that doesn't allow to reach the dongle with a public ip.
The solution is a "reverse tunnel" (in this case with SSH) that is initiate from the remote host we want to reach (the OpenWRT router) to a SSH server that in my case is an Ubuntu 10.04 box.
OPENWRT use as SSH client dropbear, a lightweight version that is compatible with public key authentication of the standard openSSH.


Generate a valid public key on the OpenWRT router with dropbear in .ssh folder . NO PUBLIC KEY FILES HAVE TO BE INSIDE THIS FOLDER OTHERWISE DROPBEARKEY WILL GENERATE AN ERROR!!

root@OpenWrt:~/.ssh# cd /root/.ssh/
root@OpenWrt:~/.ssh# dropbearkey -t rsa -f id_rsa


The output shold be something like that

root@OpenWrt:~/.ssh# dropbearkey -t rsa -f id_rsa
Will output 1024 bit rsa secret key to 'id_rsa'
Generating key, this may take a while...
Public key portion is:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgwCZfO3SRHCmekstO+tLRS4Yj3a0/8tCeWgXbQLI+3dv+wqZKS1wfOlLviRA9yj124CoAAAAB3NzaC1yc2EAAAADAQABAAAAgwCZfO3SRHCmekstO+tLRS4Yj3a0/8tCeWgXbQLI+3dv+wqZKS1wfOlLviRA9yj124Co
V6GRZbzPmJ+b root@OpenWrt
Fingerprint: md5 ac:a4:aa:f8:a2:a7:e8:ae:b9:ad:aa:2e:a4:eb:a0:a7


Copy the string of the generated public key in authorized_keys in the .ssh folder of the SSH server (ssh-rsa ..... root@OpenWrt) , I used scp command but you can do it in every way , by hand for example.


root@OpenWrt:~/.ssh# cd /root/.ssh/
root@OpenWrt:~/.ssh# scp -P 1022 authorized_keys USER_SERVER@SERVERSSH:/home/USER_SERVER/.ssh/

Now it should be possible to authenticate with the public key and without password

Note that this 2 commands are equivalent with the dropbear client

root@OpenWrt:~/.ssh# dbclient -i ~/.ssh/id_rsa -y -p 1022 USER_SERVER@SERVERSSH #equivalent to
root@OpenWrt:~/.ssh# ssh -i ~/.ssh/id_rsa -y -p 1022 USER_SERVER@SERVERSSH


This is the command to make the tunnel ssh run in background (this is necessary if you want to put it in a script)


/usr/bin/dbclient -f -N -R 1500:localhost:22 -p 1022 USER_SERVER@SERVERSSH -i /root/.ssh/id_rsa -y


Now logging in the SSH server shell with this command we will be able to reach the OpenWRT shell using port 1500 of the SSH server and using the tunnel we have create.


USER_SERVER@SERVERSSH:~/ssh root@localhost -p 1500

SSH automatic authentication without inserting password

We start with 2 ubuntu box's 10.04 , one is the server (SERVER_SSH) the other is the client (CLIENT_SSH).
Both box's have not .ssh folder in their home directory.

On the CLIENT_SSH:
make .ssh folder in the home directory

user@CLIENT_SSH:~$ mkdir ~/.ssh

generating id_rsa.pub public key

user@CLIENT_SSH:~$ cd ~/.ssh
user@CLIENT_SSH:~$ ssh-keygen -t rsa

copying content of id_rsa.pub in the authorized_keys file using cat command (can do it also by hand copying and pasting)

user@CLIENT_SSH:~$ cd ~/.ssh
user@CLIENT_SSH:~$ cat ~/.ssh/id_rsa.pub >> authorized_keys

add the ssh client

user@CLIENT_SSH:~$ssh-add




On the SERVER_SSH:

make sure the /etc/ssh/sshd_config file allow this kind of authentication

otheruser@SERVER_SSH:~$ vi /etc/ssh/sshd_config

the following parameters must be set on 'yes'

RSAAuthentication yes
PubkeyAuthentication yes


make .ssh folder in the home directory

otheruser@SERVER_SSH:~$ mkdir ~/.ssh

copying the client authorized_keys file to the server (-P 1022 its only for me since the ssh service is listening on this port, otherwise put 22 here)

restarting ssh server

otheruser@SERVER_SSH:~$ /etc/init.d/ssh restart

Now, should be possible authentication without inserting password at prompt.

sabato 21 gennaio 2012

Blocking websites on OpenWRT

If you have an openwrt router that is your gateway and you dont want to let users access some websites, you must edit the file dnsmasq.conf:


root@OpenWrt:~# vi /etc/dnsmasq.conf


adding this line:


#### Blocked website internet.tre.it ####
address=/internet.tre.it/127.0.0.1


then restarting dnsmasq service


root@OpenWrt:~# /etc/init.d/dnsmasq restart


that's all.