Share It

Tuesday, December 22, 2009

SSH to iPhone via USB

 I found a few other tutorials about SSH to iphone using USB cable. A few of them work but some guys are having problems. Here I will gather the working items/solutions and the stuff which worked for me and for some other users (downloadables / solution to errors).

So we will start with the required softwares...
As described by many others you will obviously need iTunnel to make connection. Some guys are having problems because of using wrong itunnel for wrong iTunes version. I have added link for itunnel for both iTunes 8 and iTunes9. Download accordingly.

For iTunes 8 http://www.ziddu.com/download/7854833/iTunnel3.zip.html

For iTunes 9 http://www.ziddu.com/download/7854834/itunnel9.zip.html

Now we can use Putty for SSH and WinSCP for FTP. These are the simplest one. Another Good Tool is Tunnelier Portable. This can perform a hell lot of other functions. Link for this is below..

Tunnelier Portable http://www.ziddu.com/download/7854877/TunnelierPortablev2.0.4.30.zip.html

For simple use I will recommend using Putty or WinSCP.

Now extract itunnel.

Now open up CMD, navigate to the itunnel folder we just extracted.
We actually need to Run this::: itunnel.exe 22 22
But there is Batchfile in the folder i.e. RunTunnel.bat
This will run the required command. So just execute it...

Now open WinSCP,
Enter HOST name: 127.0.0.1
Port: 22
File Protocol should be SFTP

Username: root
Password: alpine     (it is the default pwd for iphone SSH, I recommend changing it)

Hit login and you are done.

Now coming to Solutions to problems which people are facing..

First of all use relevent itunnel for iTunes.

(oh and DO INSTALL iTUNES if you do not have it installed :P)

If you are getting something similar to this:::
AMDeviceNotificationSubscribe = 0
iPhone attached !
AMDeviceConnect = 0
AMDeviceIsPaired = 0
MobileDevice: AMDeviceValidatePairing: Could not load pairing record C:\Documents and Settings\abstract\Application Data\Apple Computer\Lockdown\670e0bxfa852168e1e74a6b78c3f73619dca1ba1.plist
AMDeviceValidatePairing = -402653147
AMDeviceStartSession = -402653147
AMDeviceStartService = -402653154
AFCConnectionOpen = 0

This is because it is not able to find the plist file. To solve this go to  ::
C:\Documents and Settings\All Users\Application Data\Apple\
Now from here copy the Lockdown folder
and
Paste it at
C:\Documents and Settings\abstract\Application Data\Apple Computer\

(You will have a different folder in place of abstract :p)

Also some people are still having the same error after copying the Lockdown folder. It is because, either their plist file is different from specified in the error. To solve this just connect to iphone via iTunes and sync it. After sync try again. It should solve the issue.


Friday, December 11, 2009

Rounded Corners Compatible with All Browsers


Example text


To have the above effect, we will use some CSS and Nested Div. For this we will also require images of corners only, like the square image of top left corner etc..

We will start with our CSS.

First all we will need a class which will have a border. It will be bounding box of rounded block.
.rounded {
border: 1px solid #ffffff; /* border in white color */
background-color: #ffffff; /* background color */
zoom:1; /* for IE to work properly */
}
As our initial step, we will have the following stuff.
<div class="rounded" style="width: 200px;">  <div style="padding: 20px;">Example text</div> </div>
This will display a box with straight border in white with white background. Our surrounding is black. Now for corners, we will make a separate class which will have its respective image as background in CSS and positioned at its respective place.
.tl {background: url(tl.gif) no-repeat top left;
margin:-1px; } /* the margin -1 aligns borders with corner images*/
.tr {background: url(tr.gif) no-repeat top right;}
.br {background: url(br.gif) no-repeat bottom right;}
.bl {background: url(bl.gif) no-repeat bottom left;}
For each corner we have a class ready with respective corner image. Now we will just create divs for each corner and apply its class to it as follows:
<div class="tl"><div class="tr"><div class="br"><div class="bl">
     <div style="padding: 20px;"> Example text </div>
</div> </div> </div> </div> </div>
This way we will have a rounded cornered block. It will work in all browsers.

Complete code is as follow::::<style type="text/css"> 
.rounded {  
border: 1px solid #ffffff;  
background-color: #ffffff;  
color: #000000;  
zoom:1; /* causes IE to behave properly */  
}  

.tl {background: url(tl.gif) no-repeat top left;  
margin:-1px; } /* the margin -1 aligns borders with corner images*/  
.tr {background: url(tr.gif) no-repeat top right;}  
.br {background: url(br.gif) no-repeat bottom right;}  
.bl {background: url(bl.gif) no-repeat bottom left;}  

.tr, .tl, .bl, .br {zoom:1;position:relative;} /* for relative positioning of div */

</style>  

<div class="rounded" style="width: 200px;"> 
<div class="tl"><div class="tr"><div class="br"><div class="bl"> 
<div style="padding: 20px;"> Example text </div> 
</div> </div> </div> </div> 
</div>

Wednesday, December 9, 2009

POST data using cURL

This is about posting some data to a page via cURL. We already know the other and common method to post data, i.e. using a form and setting its method to POST. Sometimes we need to POST data using php without any form. So for this we can use cURL. 


Scenario: In our case we will send a user id along with a status and a message to our other page to process it and return it's result. We assume that we have a function called currentUserId() which will give us ID of current user and we will set status to 1. 


Explanation with code:

First we will get the ID of the user. We may use any method set the variable.

$id = currentUserId(); ////get user id
$status = 1; ///just a variable
$msg = 'Hello! I am here.';
 Now we will make an array of the fields which we are going to send
$fields = array(
    'id'=>$id,
    'status'=>$status, 
'msg'=>urlencode($msg)
);

Using urlencode will help to avoid problems because of html tags and stuff. Do include this when sending strings. It will convert spaces and other entities to url format like space is represented as %20 etc..

Now, to send data to external source we will need to convert our data to query string format. In query string, each different variable is separated by & sign and having 2 entities each, 1 for variable name and other for its value. In our case it should be like id=123&status=1&msg=Hello!%20I%20am%20here.
So for this we will use a foreach loop to convert our fields to query string.
foreach($fields as $key=>$value)  

    $fields_string .= $key.'='.$value.'&';  ///all elements to send with & sign in between as standard of query string
}  
rtrim($fields_string,'&'); ////remove extra & sign at the end ,,, we can use substr too


Now we will initiate the connection for curl and set options like url, number of vars and vars.

$con = curl_init(); //set options url, number of POST vars, POST vars  
curl_setopt($con ,CURLOPT_URL,$url);  
curl_setopt($con ,CURLOPT_POST,count($fields));  
curl_setopt($con ,CURLOPT_POSTFIELDS,$fields_string);

Now to send the vars, we need to execute curl using following function
$response= curl_exec($con);
The response from the page will in $response.

At the end we will close the connection.
curl_close($con);
COMPLETE CODE:::

$id = currentUserId(); ////get user id
$status = 1;
$msg = 'Hello! I am here.';  
$url = 'http://example.com/process-post.php'; ///URL where we are sending our data 
$fields = array(
    'id'=>$id,  
    'status'=>$status,  
    'msg'=>urlencode($msg)  
);  
//making query string for POST 
foreach($fields as $key=>$value) 
$fields_string .= $key.'='.$value.'&';  ///all elements to send with & sign in between as standard of query string
rtrim($fields_string,'&'); ////remove extra & sign at the end  
//initiate connection 
$con = curl_init();  
//set options url, number of POST vars, POST vars 
curl_setopt($con ,CURLOPT_URL,$url); 
curl_setopt($con ,CURLOPT_POST,count($fields)); 
curl_setopt($con ,CURLOPT_POSTFIELDS,$fields_string);  
//execute curl
$response= curl_exec($con);  
//close connection 
curl_close($con);

Saturday, November 21, 2009

vi Basics - How to edit a file

To edit using vi, type vi along with file name
say:
vi abc.c
vi works like a console app. Now to start editing press i

To use any command like save or quit etc. press " : " (colon without quotes)
From edit mode, press ESC to go to normal mode and press :

Enter w to save/write the changes to file.
Enter q to quit vi

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/ffmpeg.so'


While Installing FFMPEG, when I was installing ffmpeg-php, I got this warning and it didn't work any further.
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/modules/ffmpeg.so' - /usr/lib/php/modules/ffmpeg.so: undefined symbol: le_ffmpeg_frame in Unknown on line 0


Tried to find the solution but didn't get any help. So I ended up reinstalling with different changes and using different guides. Following changes helped:::

First of all get 0.6.0 version, i.e ffmpeg-php-0.6.0.

Now after download: use vi to edit the ffmpeg_frame.c and search and replace PIX_FMT_RGBA32 with PIX_FMT_RGB32
To do this run the following commands:


cd ../ffmpeg-php-0.6.0
vi ffmpeg_frame.c
Now run this command:
:%s/PIX_FMT_RGBA32/PIX_FMT_RGB32

Now run ./configure && make && make install

This should solve the problem. Worked for me.


Installing FFMPEG on Centos

This is a bit troublesome work. I spent around 9 hours banging my head with ffmpeg and did many tries to install this. And there are alot of guides for this and ***I was honored*** to install using a few of them :P. I am compiling here the set of commands that worked for me and I will also include a few alternatives in some cases and solutions to some problem which may arise.

/*********Only for beginners***********/
First of all a very little introduction to installing FFMPEG. We will be follow these procedures:
  1. We will first download the required packages (different libs and extensions). These include::: mplayer, flvtool2, lame, libogg, libvorbis, ffmpeg-php etc.
  2. The above packages are in compressed form so we will uncompress those.
  3. The uncompressed set of files are source for those, so we will compile and build them.
  4. At the end we will configure these with our apache.

To download wget is used.
e.g. wget --no-check-certificate https://rubyforge.org/frs/download.php/17497/flvtool2-1.0.6.tgz
To extract, we use:
tar -xjf amrwb-7.0.0.3.tar.bz2 etc
To compile we use:
./configure
make
make install
This will make its binaries.
/******end of Only for beginners******/

/******Real stuff starts here*********/

First of all get all the packages we need:
//Better make a separate folder for this stuff here:::
wget http://www3.mplayerhq.hu/MPlayer/releases/codecs/essential-20071007.tar.bz2
wget --no-check-certificate https://rubyforge.org/frs/download.php/17497/flvtool2-1.0.6.tgz
wget http://biznetnetworks.dl.sourceforge.net/sourceforge/lame/lame-398-2.tar.gz
wget http://jaist.dl.sourceforge.net/sourceforge/ffmpeg-php/ffmpeg-php-0.6.0.tbz2
wget http://downloads.xiph.org/releases/ogg/libogg-1.1.4.tar.gz
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.2.3.tar.gz
wget http://ftp.penguin.cz/pub/users/utx/amr/amrwb-7.0.0.3.tar.bz2
(If any of the above links are expired, you may just search google for these, but prefer using the latest version. An IMPORTANT note, use ffmpeg-php-0.6.0. Older version will make problems. This solves most of the issues.

Now extract them all.
tar -xjf amrwb-7.0.0.3.tar.bz2
tar -xjf essential-20071007.tar.bz2
tar -xjf ffmpeg-php-0.6.0.tbz2
tar -xzf flvtool2-1.0.6.tgz
tar -xzf lame-398-2.tar.gz
tar -xzf libogg-1.1.4.tar.gz
tar -xzf libvorbis-1.2.3.tar.gz
Now make directory for codecs and move them there.
mkdir /usr/local/lib/codecs
mv essential-20071007/* /usr/local/lib/codecs/
chmod -R 755 /usr/local/lib/codecs/
We will now download MPlayer and FFMPEG using SVN and update.
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk mplayer
cd mplayer/
svn update
IMPORTANT: Download these both from SVN, by other ways it will give error (I got them).

If you do not have SVN, you can install it using:
yum install subversion
yum install ruby
yum install ncurses-devel
or you can use apt-get too
Some guides asked to update configuration file too. But for me it worked without it. To update libs use vi
vi /etc/ld.so.conf
It will open up vi editor. Add the following line:
/usr/local/lib
and then load config file using
ldconfig -v
Now make all other libs

cd amrwb-7.0.0.3
./configure
make
make install

cd ../flvtool2-1.0.6
ruby setup.rb config && ruby setup.rb setup && ruby setup.rb install

cd ../lame-398-2
./configure
make
make install

cd ../libogg-1.1.4
./configure
make
make install

ldconfig -v

cd ../libvorbis-1.2.3
./configure
make
make install

cd ../mplayer/
./configure
make
make install

cd ../ffmpeg
./configure --enable-libmp3lame --enable-libvorbis --disable-mmx --enable-shared
make
make install
Here, you may have problem with ffmpeg. I was having some issues with libvorbis. I first tried it by removing this. It works but you may need libvorbis. You may try using other version of vorbis we downloaded above. FFMPEG will take some time too on ./configure and make.
Also some of the guides used
echo '#define HAVE_LRINTF 1' >> config.h
after configure. I didn't use it but I think it will help.

Now add links to codecs:
ln -s /usr/local/lib/libavformat.so.52 /usr/lib/libavformat.so.52
ln -s /usr/local/lib/libavcodec.so.52 /usr/lib/libavcodec.so.52
ln -s /usr/local/lib/libavutil.so.50 /usr/lib/libavutil.so.50
ln -s /usr/local/lib/libmp3lame.so.0 /usr/lib/libmp3lame.so.0
ln -s /usr/local/lib/libavformat.so.52 /usr/lib/libavformat.so.52
ln -s /usr/local/lib/libamrwb.so.3 /usr/lib/libamrwb.so.3
Now here comes an IMPORTANT part. This is a must do, it solved my all issues :P
Goto ffmpeg-php and edit ffmpeg_frame.c

cd ../ffmpeg-php-0.6.0
vi ffmpeg_frame.c
Now run this command:
:%s/PIX_FMT_RGBA32/PIX_FMT_RGB32
save and quit. Use :wq for this.

Now in the same folder (i.e. ffmpeg-php-0.6.0) do the following.
phpize
./configure
make
make install
Now major stuff is done. We just have to add the php extension to php.ini file. You will first need to locate php.ini. You may find it in /etc/
vi /etc/php.ini
Add this line at the end
extension=ffmpeg.so
Ok, all done now. Just restart the server and check phpinfo for ffmpeg extension.
To restart use:
/etc/init.d/httpd restart
You can also use your server's cpanel/plesk for restarting the service.

Now to test you may run php command for phpinfo. Use this:
php -r 'phpinfo();' | grep ffmpeg
You should get version info and build date etc.
ffmpeg
ffmpeg-php version => 0.6.0-svn
ffmpeg-php built on => Nov 21 2009 23:35:23
ffmpeg-php gd support => enabled
ffmpeg libavcodec version => Lavc52.32.0
ffmpeg libavformat version => Lavf52.36.0
ffmpeg swscaler version => SwS0.7.1
ffmpeg.allow_persistent => 0 => 0
ffmpeg.show_warnings => 0 => 0
PWD => /usr/src/ffmpeg-php-0.6.0
_SERVER["PWD"] => /usr/src/ffmpeg-php-0.6.0
_ENV["PWD"] => /usr/src/ffmpeg-php-0.6.0
I will discuss a serious error in another post.

Share It

Developer Instincts