How to Password Protect a Directory on Your Website running on Linux? Only allow certain users or members to access portions of your site

Requirements

1. website must be running on an Apache web server.

2.  Your web host must have enabled .htaccess processing — that is, they allow you to customize your web server environment using localized configuration files called .htaccess files.

3. You must have Secure Shell (SSH) access.

Steps to Protecting a Directory with a Password Using .htaccess on Apache

1.Login to server using SSH

2. Add the following lines to the start of your .htaccess file

        AuthName “<Your website name> Members Area”
        AuthType Basic
        AuthUserFile /path/to/your/directory/.htpasswd
        require valid-user

Please note that you will have to modify the above according to your situation. Lets understand what all are those attributes

i. AuthName
Change “Members Area” to any name that you like. This name will be displayed when the browser prompts for a password.

ii. AuthType
You do not have to modify this line.

iii. AuthUserFile
You will later create a file containing passwords named .htpasswd. The “AuthUserFile” line tells the Apache web server where it can locate this password file. Full path to the file is to be used here

iv. require
The line “require valid-user” means that any user specified in your .htpasswd (ie, password) file will be able to access that directory.

4. Create .htpasswd file using the below given command

htpasswd -c .htpasswd your-user-name

It will prompt you for password and confirm password. Enter those, a file called .htaccess would be created. And you can review the content of the file using the command

cat .htpasswd

5. Restart apache server

service httpd restart (for centos/fedora/redhat)

service apache2 restart (for Ubuntu)

6. Now access your website on browser, it will prompt you for username and password.

Now you have completed the setup. enjoy!

Solution for adding SendGrid CNAME record in GoDaddy

I managed to solve this problem with adding SendGrid Sender Authentication CNAME to any domain on Godaddy DNS.

Go to your DNS manager to add CNAME provided by SendGrid

However, for each the Host*- Enter their individual name only

For example:

Sendgrid will provide the host value like s1._domainkey.domain.com, and you just need to use the value `s1._domainkey` as the host for your CNAME record

url0007 and not url0007.domain.com or s1._domainkey and not s1._domainkey.domain.com and subsequently the rest of the Host*.

Points to* – Enter exactly complete value as provided by SendGrid

WordPress Contact Form 7 hook for Salesforce lead creation

Few days back I was asked to write a php method which send information to Salesorce from contact form7 form. Initially I thought of adding my custom function to the functions.php file of contact-form7 plugin. But I understood that its not a good idea to write custom methods to the core file of any plugin as it may get overwritten when the plugin is updated. To avoid this I have decided to write my own custom plugin hooks the contact form7 and do the job

Here I will explain you how to write a simple wordpress plugin.

Creating a WordPress plugin

Create a file with extension .php, for example ContactForm7-Salesforce-plugin.php. Add the following to the beginning of the file, which will tell what the plugin does and who is the owner..etc

/*
Plugin Name: ContactForm7- Saleforce-Plugin
Plugin URI: https://kunjans.wordpress.com
Description: Custom plugin which send info to create leads in Salesforce
Author: Aneesh Kunjan @kunjans.wordpress.com
Version: 1.0
Website: https://kunjans.wordpress.com
*/

We have to write our own custom php functions below the plugin info, and the plugin needs to be uploaded to the path /wp-content/plugins/

Understanding the CF7 object

Lets have a look at CF7 object. CF7 objects are arrays so you always need to call the CF7 object like object->object['array']. Also, returning the object at the end of the function is not required but a good practice.

Contact Form 7 action hook examples

So that’s pretty much it, creating a WordPress action hook to the wpcf7_before_send_mail and understanding how to traverse the object should allow any PHP developer to do pretty much anything with it. Let’s see some the below example which pushes contactform7 data to salesforce.

Lets do some coding

/* define your custom method and hook */

add_action( ‘wpcf7_before_send_mail’, ‘sendtosalesforce’ );

/*your custom method*/
function sendtosalesforce($cf7) {

$submission = WPCF7_Submission::get_instance();
if($submission) {
//featch post data
$posted_data = $submission->get_posted_data();
$email = $posted_data[“your-email”];
$company = $posted_data[“your-subject”];
$lastname = $posted_data[“your-name”];
$firstname = $posted_data[“your-firstName”];
$url = ‘https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8&#8217;;        $fields = array(
‘last_name’=>urlencode($lastname),
‘first_name’=>urlencode($firstname),
‘company’=>urlencode($company),
’email’=>urlencode($email),
‘oid’ => “”, //Org Id
//’retURL’ => urlencode(‘http://google.com/&#8217;), // sending this just in case
‘debugEmail’ => urlencode(“”),
‘lead_source’=>’Website’,        );

//url-ify the data for the POST

$fields_string = “”;

foreach($fields as $key=>$value) { $fields_string .= $key.’=’.$value.’&’; }        rtrim($fields_string,’&’);

if($posted_data[“your-phone”] && $posted_data[“text-form”])
{
$phone =$posted_data[“your-phone”];
$desc = $posted_data[“text-form”];
$fields_string .= ‘phone=’.urlencode($phone).’&’.’description=’.urlencode($desc);
}
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));        curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);        curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);        curl_setopt($ch,CURLOPT_FOLLOWLOCATION, TRUE);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);

}//post data ends

}

That’s it!

You should now have total control over the Contact Form 7 plugin. For any other examples or questions on the code please feel free to comment below, for other issues please visit the Contact Form 7 official WordPress forum.

WebRTC: Sipml5 with Asterisk 13 on Centos 6.6

I was trying to setup a web sip client for last one week with Sipml5 and Asterisk-13 on Ubuntu 14.04. But got stuck with lot of sip errors such as 403 forbidden, 603:failed to get local sdp..etc. So tried my Asterisk installation on Centos 6.6 and compiled Asterisk with necessary libraries for webrtc. Steps which i followed are explained below. Hope this may help  someone

Here are the components I am using

  1. Centos 6.6
  2. Asterisk 13
  3. sipML5 (Thanks to Dubango Telekom http://www.doubango.org/)

First, you need a working Asterisk 13.1.0 installation. Before doing the Asterisk installation, we have to update our system so that we have everything needed to compile plus the packages we need.

  1. yum update
  2. yum install gcc-c++ make gnutls-devel kernel-devel libxml2-devel ncurses-devel subversion doxygen texinfo curl-devel net-snmp-devel neon-devel
  3. yum install uuid-devel libuuid-devel sqlite-devel sqlite git speex-devel gsm-devel

Next step is to add the libsrtp library support. Do the following from your terminal CLI

[root@asterisk13-build /]# cd /usr/src/
[root@asterisk13-build /]# wget http://srtp.sourceforge.net/srtp-1.4.2.tgz
[root@asterisk13-build /]# tar zxvf srtp-1.4.2.tgz
[root@asterisk13-build /]# cd srtp
[root@asterisk13-build /]# autoconf
[root@asterisk13-build /]# ./configure
[root@asterisk13-build /]# make
[root@asterisk13-build /]# make install
[root@asterisk13-build /]# cp /usr/local/lib/libsrtp.a /lib
[root@asterisk13-build /]# cd ..


Compile another library  Jansson – it is available in the CentOS repos, but it’s an old version. Note: Try to set –prefix=/usr/  if  compile fails

[root@asterisk13-build /]#cd /usr/src/

[root@asterisk13-build /]# wget http://www.digip.org/jansson/releases/jansson-2.5.tar.gz

[root@asterisk13-build /]# tar zxvf jansson-2.5.tar.gz
[root@asterisk13-build /]# cd jansson-2.5
[root@asterisk13-build /]# ./configure –prefix=/
[root@asterisk13-build /]# make
[root@asterisk13-build /]# make install
[root@asterisk13-build /]# cd ..


Now it’s time for Asterisk itself:

[root@asterisk13-build /]# cd /usr/src/
[root@asterisk13-build /]# wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-13-current.tar.gz
[root@asterisk13-build /]# tar –xzvf asterisk-13-current.tar.gz
[root@asterisk13-build /]# cd /usr/src/asterisk-13.1.0 && make clean
[root@asterisk13-build /]# ./configure –with-crypto –with-ssl –with-srtp=/usr/local/lib
[root@asterisk13-build /]# contrib/scripts/get_mp3_source.sh
[root@asterisk13-build /]# make menuselect.makeopts
[root@asterisk13-build /]# menuselect/menuselect –enable format_mp3 –enable res_config_mysql –enable app_mysql –enable app_saycountpl –enable cdr_mysql –enable EXTRA-SOUNDS-EN-GSM

Now time to reconfigure and recompile Asterisk with SRTP etc

[root@asterisk13-build /]# make && make install

Note: WARNING, do not make samples if you have working configurations or use FreePBX etc

[root@asterisk13-build /]# make samples
[root@asterisk13-build /]# sudo make config
[root@asterisk13-build /]# chkconfig asterisk on


Follow the below link to enable secure calling support

https://wiki.asterisk.org/wiki/display/AST/Secure+Calling+Tutorial

First, let’s make a place for our keys.

# mkdir /etc/asterisk/keys
# cd /usr/src/asterisk-13.1.0/contrib/scripts
# /ast_tls_cert -C pbx.mycompany.com -O "My Super Company" -d /etc/asterisk/keys

Next, we generate a client certificate for our SIP device.

# ./ast_tls_cert -m client -c /etc/asterisk/keys/ca.crt -k /etc/asterisk/keys/ca.key -C phone1.mycompany.com -O "My Super Company" -d /etc/asterisk/keys -o malcolm



Now do some stuff on the asterisk conf files => sip.conf, http.conf,  rtp.conf,  extensions.conf


sip.conf

Edit the /etc/asterisk/sip.conf (or modify Asterisk SIP Settings in FreePBX), add/modify the following settings, in [general]. Notice we add transport ws and wss, these are websocket and websocket secure

udpbindaddr=0.0.0.0:5060
realm=<ip address of the server where asterisk is installed > e.g. 192.168.1.115
transport=udp,ws

Add test accounts

Note:  Parameters such as  encryption, avpf, icesupport, transport , disallow,  allow , dtlsenable, dtlsverify, dtlscertfile, dtlscertfile, dtlscafile, dtlssetup are to be configured same as in the below sample extensions

;extension to use on web client
[6001]
host=dynamic
secret=6001
context=outgoing
type=peer
encryption=yes
avpf=yes
icesupport=yes
transport=ws,wss,udp
directmedia=no
disallow=all
allow=all
dtlsenable=yes
dtlsverify=fingerprint
dtlscertfile=/etc/asterisk/keys/asterisk.pem
dtlscafile=/etc/asterisk/keys/ca.crt
dtlssetup=actpass

;extension to use on web client
[6000]
host=dynamic
secret=6000
context=outgoing
type=peer
encryption=yes
avpf=yes
icesupport=yes
transport=ws,wss,udp
directmedia=no
disallow=all
allow=all
dtlsenable=yes
dtlsverify=fingerprint
dtlscertfile=/etc/asterisk/keys/asterisk.pem
dtlscafile=/etc/asterisk/keys/ca.crt
dtlssetup=actpass

;extension to use on softphones such as twinkle, linphone,ekiga..etc
[6002]
host=dynamic
secret=6002
context=outgoing
type=peer
transport=ws,wss,udp
directmedia=no
disallow=all
allow=all


 http.conf

Make the following settings on /etc/asterisk/http.conf  file

[general]
enabled=yes
bindaddr=0.0.0.0
bindport=8088


rtp.conf

Make the following settings on /etc/asterisk/rtp.conf  file

[general]
rtpstart=10000
rtpend=20000
icesupport=yes
stunaddr=stun.l.google.com:19302


extensions.conf

Add the same context which we applied for the extensions we created on sip.conf

[outgoing]

exten => _X.,1,Dial(SIP/${EXTEN})
;exten => _X.,n,Answer()
exten => _X.,n,Hangup()


 Lets setup sipml5

Assuming your web (http) directory is in /var/www

# svn checkout http://sipml5.googlecode.com/svn/trunk/ /var/www/myphone (note, some systems it may be /var/www/html/myphone)
# chown -R asterisk:asterisk /var/www/myphone/ (or /var/www/html/myphone)
Now, head on to your Google Chrome browser and type
http://<yourIP>/myphone/demos/call.htm (e.g. http://192.168.1.115/myphone/call.htm)
Click on Expert Mode, select to Disable Video.
Enter the information like below except change the part where it says the IP, of course, enter your own IP there

sipML5   Expert mode

NATting, be sure to have a stun entry like shown above: [{ url: ‘stun:stun.l.google.com:19302’}].

If you’re not NATting, then just put two [] like that and the ICE/STUN will not be used to manage RTP and you call will be connected faster as well. Be sure the stun you use on your server side is the same used on SIPML5 as well.

Websocket URL: ws://192.168.1.115:8088/ws

Click on Save

Go back to the other tab which the webphone is on, enter the SIP extension detailed you created above, or follow and modify per example below

sipML5 live demo

Do the same above steps and configure your other web sip extension say 6001 on other browser. Register both extensions on your asterisk by simply hitting the ‘Login’ button on your screen.

You should be connected to your asterisk server if you have followed above steps.Now you should be able to make call between your test extensions.

subclipse: Unable to load default SVN Client

Some eclipse users may get this error frequently.Here is a simple solution for it.

Solution:

On your eclipse go to
Windows->Preferences->Team->Svn
Check the status of the SVN interface. That can be JavaHL or SVNKit(Pure Java).Both might not be compatible with your eclipse version.That could be the issue
preferences                         

 

 

 

 

 

 

Follow the below steps and enjoy coding

1) Goto Help menu on your eclipse

Help->Install New Software->What is already installed?

Uninstall current subeclipse and everything related to that

eclipse will get restarted after uninstall

2) On eclipse restart go to Install New Software screen again
      use the following link to  install subeclipse 1.6

http://subclipse.tigris.org/update_1.6.x

install subeclipse. after installation eclipse will get restarted

3) If issue still exists, update your subeclipse with version 1.8.Below link can be used to upgrade your subeclipse

http://subclipse.tigris.org/update_1.8.x

4)  Finally change the svn client to SvnKit.
Go to Windows->Preferences->Team->Svn

Change client to SvnKit(Pure Java)

2

 

 

 

 

 

 

 

 

Hope this helps..!