How To Create A Patch For Updated Script

Recently I had to make few changes on a freely distributed CGI script. We do these changes to fix bugs or add useful features.

We use patch files to share those changes with other developers and those patches are useful to re-apply them to new versions of the script.

The package we use for this is ‘diff’. You can learn more about it from ‘man diff’ and play with it.

This is the command I use to generate patch files:

diff -crB original_file updated_file > file.patch

 

How to get a mysqldump by selecting data

Its just simple as follows,

mysqldump -p<password> <user> <database> –where=”<where condition>” > <mysqldump file name>.sql

 

example :

mysqldump -ppassword root test_db –where=”name LIKE ‘A%’ age between ’20’ and ’30’ ” > a20to30.sql

 

Secure RTP with Asterisk

Normal asterisk servers use RTP for deliver audio over the internet. Any one can capture this RTP streams by using Packet Sniffer tools, and can listen to  the call content. So VoIP calls are not secure for confidential communications until using a secure VoIP system.

Therefore we can use advance protocol called SRTP (Secure Real-time Transport Protocol) which provide encryption for RTP stream. So no one can listen to the VoIP conversations while using SRTP. If someone try to capture the SRTP stream, it will play only a noise (even it was a empty conversation).

But it will not complete the secure VoIP system. You MUST secure the signalling (SIP) because SRTP keys are exchanged in plaintext with SDES(http://en.wikipedia.org/wiki/SDES). To do that we have to use Asterisk TLS (Transport Layer Security). It provides encryption for call signaling.

Asterisk 1.8 has native support for SRTP. So you can easily try this with a Asterisk 1.8.x server. The normal SIP phones are not support for this system. You need to find SRTP supported and TLS supported IP/soft phones for setup this. Use blink soft-phone for this (http://www.icanblink.com). I followed following article to setup secure VoIP system.

For SRTP : http://www.remiphilippe.fr/2011/01/16/asterisk-srtp-with-1-8/
For TLS : https://wiki.asterisk.org/wiki/display/AST/Secure+Calling+Tutorial, ( You can find ast_tls_cert script from here : https://reviewboard.asterisk.org/r/979/diff/)

Posted in asterisk, voip. Tags: , , , . 1 Comment »

Important thing should do when we delete large number of records from a MySQL table

When you deleting large number of records from a MySQL table, remember to execute following command after deleting the records.

OPTIMIZE TABLE tablename;

By executing this command we can improve performance of the table queries and save storage space.

You can find detail explanation from : http://dev.mysql.com/doc/refman/5.1/en/optimize-table.html

Date/Time addition in PHP

Using PHP ‘strtotime()’ function, we can add time in our PHP programs.
Example:

$date = strtotime(“+10 minute”, strtotime(“2007-02-28 23:55:05”));
echo date(“Y-m-d H:i:s”, $date);     //gives 2007-03-01 00:05:05

Try following:

$date = strtotime(“+3 day”, strtotime(“2007-02-28 23:55:05”));
echo date(“Y-m-d H:i:s”, $date);

Get URL GET values using javascript

I had a situation of getting URL GET values to my web page without using server side scripting language like PHP, JSP or ASP.

So this is a simple way to get URL GET value to your web page using javaScript. When you don’t have any facilities to code server side scripts, you can use this technique to make your website more dynamic.

Simple example :

<html>
  <head>
     <script>// Import GET Vars
        (function(){
           document.$_GET = [];
           var getVarsString = String(document.location).split('?');
           if(getVarsString[1]){
              var getVars = getVarsString[1].split('&');
              for(var i=0; i<=(getVars.length); i++){
                 if(getVars[i]){
                    var getVarPair = getVars[i].split('=');
                    document.$_GET[getVarPair[0]] = getVarPair[1];
                 }
              }
           }
         })();
         function updateView(){
            document.getElementById("view").innerHTML=document.$_GET['i'];
         }
     </script>
  </head>
  <body>
      <input id="txt" type="button" value="click" onclick="updateView();" />
      <div id="view"></div>
  </body>
</html>

Send emails using PHP

In PHP there is a function called “mail” for send emails from our web applications. To use this this function, we have to do some configurations in php.ini file of our web server. If you are using PHP-equipped web host, you don’t need to worry about this mail function setup configuration because all required configurations are done by the hosting providers.

 

Setting up mail function in PHP

=====================

step 1> Goto “php.ini” file in your web server.

step 2> Find “[mail function]” part in the php.ini file.

step 3 for window mail server> Give the mail servers address to “SMTP”, give the port of the SMTP to “smtp_port” (default is 25) and set “sendmail_from” to sender’s email address.

eg:

[mail function]

SMTP = smtp.my.isp.net

smtp_port = 25

sendmail_from = you@yourdomain

step 3 for unix mail server> Give the path of the mail program on your server and set “sendmail_from” to sender’s email address.

eg:

[mail function]

sendmail_path = /usr/sbin/sendmail -t

sendmail_from = you@yourdomain

 

PHP mail function sample code

======================

<?php

// The message

$message = “Line 1\nLine 2\nLine 3”;

// In case any of our lines are larger than 70 characters, we should use wordwrap()

$message = wordwrap($message, 70);

// Send

mail(‘first_user@example.com,second_user@example.com‘, ‘The Subject’, $message);

?>

refer :http://php.net/manual/en/function.mail.php

%d bloggers like this: