Friday, December 23, 2016

Enable the MUC (Multi User Chat) in Prosody

Enabling Components in prosody server



In the XMPP world, many services are provided in components, which allows for greater ease of customization within a basic framework. A common example of this is the MUC or multi-user chat functionality. To enable MUC services in Prosody you need to add a line like the following to your
/etc/prosody/prosody.cfg.lua file.

/etc/prosody/prosody.cfg.lua

Component "conference.example.com" "muc"

In this example, conference.example.com is the domain where the MUC rooms are located, and will require an “DNS A record,” that points to the IP Address where the Prosody instance is running. MUCs will be identified as JIDs (Jabber IDs) at this hostname, so for instance the “rabbits” MUC hosted by this server would be located at rabbits@conference.example.com.

MUC, in contrast to many other common components in the XMPP world, is provided internally by Prosody. Other components, like transports to other services, run on an external interface. Each external component has its own host name, and provides a secret key which allows the central server to authenticate to it. See the following “aim.example.com” component as an example.

/etc/prosody/prosody.cfg.lua

Component "aim.example.com"
component_secret = "mysecretcomponentpassword"
Note that external components will need to be installed and configured independently of Prosody.

Typically, Prosody listens for connections from components on the localhost interface (i.e. on the 127.0.0.1 interface;). If you’re connected to external resources that are running on an alternate interface, specify the following variables as appropriate in the global section of the configuration file before the first VirtualHost declaration.

/etc/prosody/prosody.cfg.lua

component_interface = "192.168.0.10"
component_ports = { 8888, 8887 }

Using prosodyctl


The XMPP protocol supports “in-band” registration, where users can register for accounts with your server via the XMPP interface. However, this is often an undesirable function as it doesn’t permit the server administrator the ability to moderate the creation of new accounts and can lead to spam-related problems. As a result, Prosody has this functionality disabled by default. While you can enable in-band registration, we recommend using the prosodyctl interface at the terminal prompt.

If you’re familiar with the ejabberdctl interface from ejabberd, prosodyctl mimics its counterpart as much as possible.

To use prosodyctl to register a user, in this case username@example.com, issue the following command:


prosodyctl adduser username@example.com
To set the password for this account, issue the following command and enter the password as requested:


prosodyctl passwd username@example.com
To remove this user, issue the following command:

prosodyctl deluser username@example.com
Additionally, prosodyctl can provide a report on the status of the server in response to the following command:


prosodyctl status
Note that all of the prosodyctl commands require root privileges, unless you’ve logged in as the same user that Prosody runs under (not recommended).

Configure Prosody Server

The configuration file for Prosody is located in /etc/prosody/prosody.cfg.lua, and is written in Lua syntax.


Note that in the Lua programing language, comments (lines that are ignored by the interpreter) are preceded by two hyphen characters (e.g. --). The default config has some basic instructions in Lua syntax, which can be helpful if you’re unfamiliar with the language.

To allow Prosody to provide XMPP/jabber services for more than one domain, insert a line in the following form into the configuration file. This example defines three virtual hosts.

/etc/prosody/prosody.cfg.lua

VirtualHost "example.com"
VirtaulHost "example.com"
VirtualHost "staff.example.com"
VirtualHost "192.153.36.78"

Following a VirtualHost line there are generally a series of host-specific configuration options. If you want to set options for all hosts, add these options before the first VirtualHost declaration in your configuration file. For instance, to ensure that Prosody behaves like a proper Linux server daemon make sure that the posix; option is included in the modules_enabled = { } table.

/etc/prosody/prosody.cfg.lua

modules_enabled = {
                  -- [...]
                  "posix";
                  -- [...]
                  }
Note that there should be a number of global modules included in this table to provide basic functionality.

To disable a virtual host without removing it from your configuration file, add the following line to its section of the file:

/etc/prosody/prosody.cfg.lua
enabled = false

To specify administrators for your server, add a line in the following format to your prosody.cfg.lua file.

/etc/prosody/prosody.cfg.lua

admins = { "admin1@example.com"}
To add server-wide administrators, add entries to the admins section, as above, in the global section of the configuration file. To grant specific users more granular control to administer particular hosts, you can add an admins line, or more properly tables in Lua, to specific hosts.

If you need to enable the legacy SSL/TLS support, ensure that the following entry in the modules_enabled is enabled:

/etc/prosody/prosody.cfg.lua
modules_enabled = {
                  -- [...]
                  "legacyauth";
                  -- [...]
                  }

legacy_ssl_ports = { 5223 }
Do not forget to reload the configuration for the Prosody server after making any changes to your /etc/prosody/prosody.cfg.lua file, by issuing the following command:


/etc/init.d/prosody restart

Installing Prosody Server on Ubuntu

Install Prosody

Prosody

Prosody is a XMPP/Jabber server programmed in Lua that is simple and lightweight. Prosody uses fewer resources than its counterparts and is designed to be easy to configure and run. Ejabberd or OpenFire may be better suited for larger applications, but for most independent and small-scale uses Prosody is a more resource-efficient solution. Prosody is a very good candidate for running an XMPP server for a very small base of users, or for XMPP development.


Adding Software Repositories in ubuntu


The developers of Prosody provide software repositories for Debian and Ubuntu to more effectively distribute current versions of the software to users. In order to make these repositories accessible to your system we must append the following line to the /etc/apt/sources.list file:
/etc/apt/sources.list
deb http://packages.prosody.im/debian precise main

Now, to download the public key for the Prosody package repository, issue the following wget command. You may need to install wget first by running apt-get install wget. This will allow you to authenticate and verify packages:
wget http://prosody.im/files/prosody-debian-packages.key -O- | apt-key add -

Issue the following command to refresh the package database:
apt-get update
apt-get upgrade

Install Prosody


With the proper repository enabled, we’re now ready to install the Prosody server. Use the following command:

apt-get install prosody lua-sec-prosody

When apt finishes, the Prosody server will have been successfully installed (with support for TLS/SSL), and will be ready for configuration. Prosody provides an init script that allows you to reload the configuration file, start, stop, or restart the XMPP server. Issue one of the following commands as appropriate:
/etc/init.d/prosody reload
/etc/init.d/prosody start
 /etc/init.d/prosody stop
/etc/init.d/prosody restart

service prosody start
service prosody stop
service prosody restart

Tuesday, November 22, 2016

Codeigniter Transaction queries creation


Introduction on Transaction


A transaction is a logical unit of work that contains one or more SQL statements.
Transactions are atomic units of work that can be committed or rolled back.
When a transaction makes multiple changes to the database, either all the changes succeed
when the transaction is committed, or all the changes are undone when the transaction is rolled back.

A transaction begins with the first executable SQL statement.
A transaction ends when it is committed or rolled back, either explicitly
with a COMMIT or ROLLBACK statement or implicitly when a DDL (Data Definition Language (DDL) is used to manage table and index structure and CREATE, ALTER, RENAME, DROP and TRUNCATE statements are to name a few data definition elements) statement is issued.

Achieve the same in codeigniter using below code


$this->db->trans_begin();


//insert transaction
$i_data = array(
      'user_id'     => $app['opp_id']
    , 'amount'      => $app['total']
    , 'type'        => 1
    , 'feb_bal'     => 1
    , 'note'        => 'Earnings'
);

$this->db->insert('transaction', $i_data);
$tran_id = $this->db->insert_id();

//insert 2
$c_data = array(
      'oppt_opp_id' => $app['id']
    , 'status'      => 0 //closed
);
$this->db->insert('progress', $c_data);

//insert 3
$e_data = array(
      'tran_id' => $tran_id
    , 'app_id'  => $app['id']
    , 'type'    => 1
    , 'status'  => 2
);
$this->db->insert('earn_spend', $e_data);


if( if ($this->db->trans_status() === FALSE) {){
$this->db->trans_rollback();
}else{
  $this->db->trans_commit();
}

Note: To achieve the transaction statements all tables engine should be in innodb

How To Control WordPress User Permissions Effectively

To Get the access for external plugins such as AccessPress Social Share, Contact Db for a Wordpress Editor Role User

 we could get this feature by combining below plugins
1. Members Plugin : To create different Roles
2. Adminimize Plugin : To Disable Settings tab


Creating a new Role  Using Member Plugin


  • Enable the Member Plugin in Plugins tab
  • Under Users Tab > Click on the Add New Role link
  • Enter Role name text box
  • Grant the "manage_options" Capability to given role name
  • Save the Role
  • Create One user under this Role.

Member Plugin


To Disable the unwanted links under above created user, Need to follow the below steps


  • Enable the Adminimize Plugin in Plugins tab
  • Click the Adminimize Plugin settings link. (Tab Settings > Adminimize).
  • Under MiniMenu > Menu Option > check the settings tab related Url names.


Adminimize Plugin

Friday, November 18, 2016

Get magento session variable in php page

Mage::app('admin'); //get the admin session
Mage::getSingleton('core/session', array('name'=>'adminhtml')); //verify if the user is logged in to the backend
if(Mage::getSingleton('admin/session')->isLoggedIn()){
echo "logged in";
}else{
$url = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
header('Location: '.$url."index.php/admin");
exit;
}

Thursday, November 17, 2016

How to Add Disqus Comment System in WordPress


Disqus

Disqus, pronounced "discuss", is a service and tool for web comments and discussions. Disqus makes commenting easier and more interactive, while connecting websites and commenters across a thriving discussion community.
The Disqus for WordPress plugin seamlessly integrates using the Disqus API and by syncing with WordPress comments.

Disqus for WordPress

  • Uses the Disqus API
  • Comments indexable by search engines (SEO-friendly)
  • Support for importing existing comments
  • Auto-sync (backup) of comments with Disqus and WordPress database

Adding Disqus Commenting System in WordPress

Adding Disqus commenting system to WordPress is very easy. 
First thing you need to do is go to Disqus website and login or signup for a new account. 
Once you are logged in, click on For Websites link next to the Disqus logo.

On the next screen, you need to click on Add Disqus to Your Site button next to your profile pic on the top right corner of the screen.

This will take you to a signup form where you need to provide your website information. Provide the title of your blog or website and then choose a unique URL for your website on the disqus commenting system. This unique URL will be the place where you can access all your comments after you have installed Disqus on your site. Lastly choose a category for your website. Once you are done, hit the Finish Registration button.




Now that you have registered your site for Disqus commenting system, it is time to connect your WordPress site to the Disqus platform. To do this, you need to install and activate the Disqus Comment System plugin. Upon activation, go to Comments » Settings and sign in with your Disqus account.


disqus-wordpress-signin

Once you are logged in, you will be shown the site you registered for Disqus commenting system. Select the site and click on the next button to finish the set up. That’s all. You have successfully added Disqus comment system to your site.

mongodb install windows

mongodb install windows

Download the latest production release of MongoDB from the MongoDB downloads page.

Click on .msi file and follow the instructions.

mongo Db

To Start the Mongodb server

Open an Administrator command prompt. Press the Win key, type cmd.exe, and press Ctrl + Shift + Enter to run the Command Prompt as Administrator. Go to Mongo db installed directory.
sy: mongod --dbpath="path to db" --port=27017
 Example: mongod --dbpath=d:\mongodb\ --port=27017

mongod ------ Command
dbpath  --- specify the database storeing path
port --- port number default port (27017)




Connect to the Mongo Db server using command prompt

Using below command we will able to connect to mongo server from command prompt in windows

sy : mongo --port=27017
Example: "C:\Program Files\MongoDB\Server\3.2\bin\mongo.exe

Friday, November 4, 2016

MySQL to export and import an .sql file from command line

 
 

To Export & Import Mysql data using Command Line

To export

If it's an entire DB, then:
$ mysqldump -u [uname] -p[pass] db_name > db_backup.sql
If it's all DBs, then:
$ mysqldump -u [uname] -p[pass] --all-databases > all_db_backup.sql
If it's specific tables within a DB, then:
$ mysqldump -u [uname] -p[pass] db_name table1 table2 > table_backup.sql
You can even go as far as auto-compressing the output using gzip (if your DB is very big):
$ mysqldump -u [uname] -p[pass] db_name | gzip > db_backup.sql.gz
If you want to do this remotely and you have the access to the server in question, then the following would work (presuming the MySQL server is on port 3306):
$ mysqldump -P 3306 -h [ip_address] -u [uname] -p[pass] db_name > db_backup.sql

To import

Type the following command to import sql data file:
$ mysql -u username -p -h localhost DATA-BASE-NAME < data.sql
In this example, import 'data.sql' file into 'blog' database using Anil as username:
$ mysql -u anil -p -h localhost blog < data.sql
If you have a dedicated database server, replace localhost hostname with with actual server name or IP address as follows:
$ mysql -u username -p -h 202.54.1.10 databasename < data.sql
OR use hostname such as mysql.cyberciti.biz
$ mysql -u username -p -h mysql.cyberciti.biz database-name < data.sql
If you do not know the database name or database name is included in sql dump you can try out something as follows:
$ mysql -u username -p -h 202.54.1.10 < data.sql

Friday, August 12, 2016

Mysql Interview Questions



  • What are the different tables present in mysql

           ---Myisam, isam, innodb, heap, merge


  • Types of index in mysql 

           --unique index, index

  • How to create Indx

           --sy: CREATE  INDEX AUTHOR_INDEX ON tutorials_tbl (tutorial_author)


  • Table have multiple index which order query will follow



  • Explain keyword 

Thursday, August 11, 2016

Linux Commands


1. To remove files in current directory

rm -rf ./*


2.To change the file permissions

Why is Magento 1.4 including javascript files by filesystem path?
  
 chmod -R 777 var/ media/
-R --recusively
777 --- Full permissions to all users
var/media --- directory path


3. Add svn repositry in server

svn co  
 svn co https://acd.svn.beanstalkapp.com/ekr-tbp/trunk test2/


4. To start the apache server

service httpd start
service httpd stop

5. To see the error log

tail
tail -f  
cat  

6.To Rename the folde name
mv old-file-name  new-file-name

7. Zip the files on current directory
tar -cvf aws6-9-16.tar
tar -czf aws6-9-16.tar.gz . --exclude=./*.gz

mv testfile testfile2

8. To set number in vim editor
:set nu

9. To remove all content of  a file using vim editor
:1,$d
dgg
10. Download a file using curl
curl -OL http://pear.php.net/go-pear.phar

11. To unzip specific file on current directory
unzip agf-stage.zip -d .
. ---current directory
agf-stage.zip ---file name


Mysql adding user for remote access or workbench



In order to connect remotely you have to have MySQL bind port: 3306 to your machines IP in my.cnf. Then you have to have created the user in both localhost and '%' wildcard and grant permissions on all DB's as such . See below:


path : /etc/mysql/my.cnf

my.cnf
#Replace xxx with your IP Address 
bind-address        = xxx.xxx.xxx.xxx
Creating the user
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass';
CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypass';
And granting permissions to the user
GRANT ALL ON *.* TO 'myuser'@'localhost';
GRANT ALL ON *.* TO 'myuser'@'%';
FLUSH PRIVILEGES;

To get the user list and there permissions in mysql db
mysql> SELECT user, host FROM mysql.user;
+------------+---------------------+
| user       | host                |
+------------+---------------------+
| adadmin    | %                   |
| tbpmagento | %                   |
| wpuser_agf | %                   |
| root       | 127.0.0.1           |
| root       | ::1                 |
| ces        | localhost           |
| root       | localhost           |
| tbp        | localhost           |
| tbpmagento | localhost           |
+------------+---------------------+

Tuesday, July 12, 2016

Website Payments Pro Payflow Edition


How do I set up Payflow Pro with PayPal Sandbox?



1.Log in to PayPal Manager.

2.Enter your Partner, Merchant Login, User (if applicable) and Password, and click Log In.




3.From the main navigation select Service Settings | Setup.


4.The third heading from the top titled PayPal Express Checkout you'll see PayPal Sandbox email address.  Enter your PayPal Sandbox Seller email into this field, scroll to the bottom of the page and click on Save.


Your Payflow Manager has now been synced with your PayPal Sandbox account and is ready to begin accepting Test/Sandbox transactions.

NOTE:  If you do not see the PayPal Express Checkout section on the Set Up page,
you will need to contact Merchant Technical Support and request that PayPal Express Checkout be added to your Payflow account for testing purposes. 

Please provide your PayPal Sandbox email address and your Payflow Merchant login 
when creating the ticket with Merchant Technical Support.

configure php 5.x apache 2.4 windows 7



httpd.conf Edit



Download php-5.6.23-Win32-VC11-x86.zip from http://windows.php.net/download/ . Extract the zip file to c:\php.


Edit Apache’s config file, c:\Apache\conf\httpd.conf and add the following lines to the bottom of the file.

Method 1

  • LoadModule php5_module "c:/php/php5apache2_4.dll"
  • AddHandler application/x-httpd-php .php
  • PHPIniDir "c:/php"
  • Set the environment variable append this text : "c:/php"
  • Find Directory index and add index.php add below line
    • "DirectoryIndex index.html index.php"


save the conf file. Restart your Apache server.

Method 2

In this method we Configuring Apache to Use PHP as CGI on Windows Systems. which best suitable for Higher versions of php like (above php5.3 on Apache 2.2). we will configure below steps.


1. Assuming that your Apache server is installed at C:\Apache2.2

2. Assuming that your PHP engine is installed at c:/php/

3. Use "notepad" to open C:\Apache2.2\conf\httpd.conf

4. Go to alias_module section and define a script directory call /php/ as:


...
   ScriptAlias /php/ "c:/php/"
5. Add an access control section for this directory as:


    AllowOverride None
    Options None
    Order allow,deny
    Allow from all

6. Go to mime_module section and define a mime type as:


...  
    AddType application/x-httpd-php .php

7. At the root level below the LoadModule section, define an "Action" entry:

#LoadModule ssl_module modules/mod_ssl.so

Action application/x-httpd-php "/php/php-cgi.exe"
This "Action" entry tells Apache to run "php-cgi.exe" from the script directory "/php/" for any "application/x-httpd-php" mime files.

8. Restart your Apache server.

save the conf file. Restart your Apache server.

PHP INI Edit

Now we have to do a few edits to the php.ini file to tell it to load support for mysql and the location for the extensions. Since there is not a already set php.ini file we need to rename one of the two examples to php.ini.
Rename c:\php\php.ini-development to php.ini
Now let’s edit php.ini
Uncomment extension directory.
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "ext"

Uncomment mysql modules
extension=php_mysql.dll
extension=php_mysqli.dll

save the .ini file changes. Restart your Apache server.

Tuesday, March 1, 2016

Git Merge

git checkout 2.3
git pull origin 2.3
so that u have all 2.3 changes.
then git checkout 2.4
git pull origin 2.4
so that u have all 2.4 changes
i mean locally u have both branches updated
now to merge 2.3 to 2.4
we should be on 2.4 branch
in brackets git show current branch if u using cmd line.
now for merging just do this
git merge 2.3
this would bring all 2.3 changes to 2.4
it would show merge conflict issues if any
 on cmd line
resolve issues
you need to do this manually or using some diff checker

then to commit all these local changes to 2.4
git add .
git commit -am "merge 2.3 to 2.4"
git push origin 2.4
 it would push all merged code to 2.4 branch



Git Process Commands


To change from one branch to other brach

git checkout -b  
ex:  git checkout -b 3.3 



To Undo the last commit or stash the last commit
git stash    -- Do the merge, and than pull the stash:
git stash pop --get the commited files to current branch


Reset the last commit in local
To discard the local changes using
sy: git reset --hard



To change the Last commit message in git



git commit --amend

will open your editor, allowing you to change the commit message of the most recent commit. Additionally, you can set the commit message directly in the command line with:

git commit --amend -m "New commit message"



To get the patch to file (all changes to specified file)


Git diff > sample.txt

Monday, February 22, 2016

Add text at the beginning of a line in vim

The substitute command can be used to insert (or replace) text. Some examples:

:s/^/new text / Insert "new text " at the beginning of the line.
:s/$/ new text/ Append " new text" to the end of the line.
:s/green/bright &/g Replace each "green" with "bright green" in the line.
By default, each command operates on the current line. If you visually select some text before entering the command, it will operate on each line in the visual selection. See Search and replace for details.
Or you can insert a range immediately after the colon, for instance :.-5,$s/ etc. to substitute from 5 lines above the cursor to the end of the file.

:s/^/test /  ----insert "test" at the beginning of each line.
:%s/^/test / --- insert "test" at the end of each line .

Saturday, February 6, 2016

Delete Files Older Than x Days on Linux

find /path/to/files* -mtime +5 -exec rm {} \;
ex: find /opt/test/patch/* -mtime +7 -exec rm {} \;

The first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.
The second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days.
The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required to end the command.

How to convert PPK file to ssh remote server in ubuntu


1.sudo apt-get install putty
2.puttygen private.ppk -o private-key -O private-openssh (Where “private.ppk” is the PuTTY .ppk file to convert, and “private-key” is the name of the converted key file.)
3.ssh -i private-key username@remote-server-ip
Now, you can easily access the remote server using the openssh standard private key:

refurl: https://rbgeek.wordpress.com/2012/11/14/how-to-convert-ppk-file-to-ssh-remote-server-in-ubuntu/