Adding new language into MyReview

  • A translation file is tree-structured, with a first level (namespaces), a second (text codes) and a third one which present the text content in two languages: English (the reference for translation) and the target language chosen in the export form (available from the Configuration menu).
  • If  you want to add a language in your interface, this is pretty simple:
  • Export the entries of english language (reference for translation) from zmax_text table.
  • Translate these entries into the target language with the help of translator.
  • Create the language <lang> in the zmax_lang table, using the edit from the configuration menu; this will show the language in the list of available translations.
  • Import the translation file that corresponds to the new language.
Posted in MyReview | Leave a comment

Showing relationship among database tables

  • SchemaSpy software is used for showing relationship among different tables. It is free software.
  • SchemaSpy is a Java-based tool that analyzes the metadata of a schema in a database and generates a visual representation of it in a browser-displayable format. It lets you click through the hierarchy of database tables via child and parent table relationships as represented by both HTML links and entity-relationship diagrams. It’s also designed to help resolve the obtuse errors that a database sometimes gives related to failures due to constraints.
  • SchemaSpy uses the dot executable from Graphviz to generate graphical representations of the table/view relationships.
  • Install Graphviz by running following command:

sudo apt-get install graphviz

  • SchemaSpy uses JDBC’s database metadata extraction services to gather the majority of its information.
  • Run following commands to install java :

    apt-cache search jdk

    sudo apt-get install openjdk-7-jdk openjdk-7-jre

 cd Download

mv SchemaSpy_5.0.0.jar SchemaSpy.jar

  • Run SchemaSpy from the command line:
java -jar schemaSpy.jar -t mysql -o library -host localhost -db library -u user -p password -dp /usr/share/java/mysql-connector-java.jar
  • Give username and password and database name which have you want to gernate the dfd.
  • After this library Directory is gernate automatically and in this index.html file is gernate.
  • Open this index.html in browser and see output on your Browser.
Posted in Uncategorized | 2 Comments

Making a simple form in Zend framework

  • Firstally define the directory structure of zend framework.
  • Create index.php file inside the project/ directory and write the following code:
<?php
define('ROOT_DIR', dirname(__FILE__));
set_include_path('.'
. PATH_SEPARATOR . ROOT_DIR . '/library'
. PATH_SEPARATOR . ROOT_DIR . '/application/models'
. PATH_SEPARATOR . ROOT_DIR . '/application/forms'
. PATH_SEPARATOR . get_include_path()
);
require_once "Zend/Loader/Autoloader.php";
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);
$config = new Zend_Config_Ini(ROOT_DIR.'/application/config.ini', 'general');
$db = Zend_Db::factory($config->db);
Zend_Db_Table::setDefaultAdapter($db);
$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setControllerDirectory(ROOT_DIR.'/application/controllers');
$frontController->dispatch();
?>
  • Now create a form named CustomForm.php inside project/application/forms/ directory and write the following code to create a form for Data Entry:
<?php
class CustomForm extends Zend_Form
{
public function init()
{
    $this->setMethod('post');
    $id = $this->createElement('hidden','id'); 
    $username = new Zend_Form_Element_Text('username');
    $username->setLabel('Username:')
    ->setAttrib('maxlength',75);
    $firstname = $this->createElement('text','firstname');
    $firstname->setLabel('FirstName:')
    ->setAttrib('maxlength',75);
    $lastname = $this->createElement('text','lastname');
    $lastname->setLabel('LastName:')
    ->setAttrib('maxlength',75);
    $email = $this->createElement('text','email');
    $email->setLabel('Email:')
    ->setAttrib('maxlength',75);        
    $comment = new Zend_Form_Element_Textarea('comment');
    $comment->setLabel('Comment:')
    ->setOptions(array(
    'id' => 'comment',
    'rows' => '5',
    'cols' => '30',
    )); 
    $password = $this->createElement('password','password');
    $password->setLabel('password:')
    ->setAttrib('maxlength',75);    
    $captcha = new Zend_Form_Element_Captcha('captcha', array(
    'captcha' => array(
    'captcha' => 'Figlet',
    'wordLen' => 4,
    'timeout' => 200,
    )
    ));
    $captcha->setLabel('Verification:');  
    $signin = $this->createElement('submit','signin');
    $signin->setLabel("sign Up")
    ->setIgnore(true);
    $reset = new Zend_Form_Element_Reset('reset');
    $reset->setLabel('Cancel');  
    $this->addElements(array(
    $username,
    $firstname,
    $lastname,
    $email,
    $password,
    $captcha,
    $signin,
    $id,
   $reset
));
}}
?>
  • Create a Database and note down the name you created. Create table by executing the following query :
 CREATE TABLE IF NOT EXISTS `users` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `username` varchar(75) NOT NULL,
 `firstname` varchar(75) NOT NULL,
 `lastname` varchar(75) NOT NULL,
 `email` varchar(15) NOT NULL,
 `password` varchar(75) NOT NULL,
  'captcha' varchar(75) NOT NULL,
PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
  • Now configure the database settings. Create a file config.ini inside the /project/application/ directory, write the following code, fill in your details and save the file.
[general]
 db.adapter = "PDO_MYSQL"
 db.params.host = "localhost"
 db.params.username = "root"
 db.params.password = ""
 db.params.dbname = "project"
  • Create the IndexController.php inside project/application/controllers/ and write the following code in it:
<?php
class IndexController extends Zend_Controller_Action
{
        public function addAction()
   {
       $users  = new Users();
       $form = new CustomForm();
       $this->view->form = $form;
       if ($this->getRequest()->isPost()) 
    {
           $formData  = $this->_request->getPost();
           if ($form->isValid($formData)) 
        {
           unset($formData['signin']);
           $users->insert($formData);
       echo "your data has been successfully stored";
               }
       }  }} ?>
  • We have to setup a model for the Database table which we are using, which is also used in indexAction() of IndexController.php file so, create a file Users.php which resides in /project/application/models/ directory and write the corresponding code.y
<?php class Users extends Zend_Db_Table {    protected $_name = “users”; } ?>
  • Create add.phtml file in project/application/views/scripts/index/ and write the following code in it.
    <center><h4>Contact Form</h4>
    <?php
     echo $this->form;
    ?></center>
  • Now type in browser : http://localhost/project/index/add
Posted in Uncategorized | 1 Comment

Different namespaces in MyReview

  • namespace is a mean to group texts.
  • MyReview uses several groups, or “namespaces”. These are given below:
  • db namespace contains the translation of all the database fields; such translations are useful for instance as header of HTML tables, or as labels of form fields. For instance, the database attribute email appears in the db namespace as a text code email, and translations Email address in English, Addresse de courrier électronique in French, etc.
  • form namespace is specifically dedicated to the labels of form fields, when then are not found in the db namespace. For instance: the text code email, in the namespace form, would be translated as Enter your email in English, and Entrez votre adresse électronique in French.
  • author, reviewer, and admin namespaces contain texts specific to, repectively, the Author, Reviewer, and Admin controllers (a controller is a set of functions).
  • Finally, a text of general interest which does not belong to one of the above is put in the def namespace.
  • The mail namespace manage all the message texts.
Posted in MyReview | Leave a comment

tmux in Ubuntu

  • tmux is a terminal multiplexer. It enables a number of terminals to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattached.
  • Install tmux by running following command:

sudo apt-get install tmux

  • Open it by typing tmux in terminal and then hit enter.
  • Basic tmux handling
    Ctrl-b n (Move to the next window)
    Ctrl-b p (Move to the previous window)
    Ctrl-b l (Move to the previously selected window)
    Ctrl-b w (List all windows / window numbers)
    Ctrl-b % (Split the window vertically)
    Ctrl-b : “split-window” (Split window horizontally)
    Ctrl-b o (Goto next pane)
    Ctrl-b q (Show pane numbers, when the numbers show up type the key to
    goto that pane)
    Ctrl-b { (Move the current pane left)
    Ctrl-b } (Move the current pane right)
Posted in Uncategorized | Leave a comment

Run multiple sites instances with one MyReview Installation

You can run many sites with a single MyReview installation. The MyReview directory organization makes it easy to separate the application part from the site-specific files. Here is a short list of the actions that must be carried out to enable a new site named, say, newConf:

  • Create new directory ‘newconf’ in /var/www and paste ‘application’, ‘config’, ‘files’, ‘library’, ‘themes’, ‘www’  directories from myreview into it.
  • Create a new MySQL database, named newConf, and import the myreview.sql script to this database.
  • Create a virtualhost as mentioned in the following:
  • Change the ‘Document Root’ directive to /var/www/newconf/www/
    Also change the ‘Directory’ directive to /var/www/newconf/www/
    Under the line that begins ‘ServerAdmin’, add the following line:
    ServerName newconf
    In
    \<Directory /var/www/newconf/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    \</Directory>
    change AllowOverride None to Allow Override All
  • Save changes and then exit
  • Add the following to the host file located in /etc/hosts

127.0.0.1 newconf

  • Enable the new site with the command:

sudo a2ensite newconf

  • Restart the apache server:

 sudo /etc/init.d/ apache2 reload

  • In /var/www/newconf/config/default/application.ini, set the app.document_root parameter to /var/www/newconf/www/
  • Edit newconf/config/default/database.ini and change database name to newconf.
  • Edit newconf/www/index.php and change the $configDir value to “config”. It should contain the path to the configuration directory.
  • Now type in terminal:

http://newconf

Posted in MyReview | Leave a comment

Changing layout of MyReview

  • In the Configuration form of admin menu, three inbuilt layouts are provided. Layout selection option is provided to select these. We can even make changes in these by modifying their respective CSS files located at myreview/www/css directory.
  • We can also use a CSS template of our own choice.
  • In particular, you can get any of the numerous HTML layout found on the Web (see the FreeCssTemplates site for instance). Specifically:
  • Put the your Layout.xml file in the themes subdirectory; add the content entity references where appropriate in the layout and change the menu to refer to the MyReview actions;
  • Copy the necessary CSS, Javascript and image associated to your layout in, respectively, css, js and images sub directories of www edit the config/application.ini configuration file, and change the layout parameter to yourLayout.
  • That‘s all. MyReview will use your layout.
  • Example:

Posted in MyReview | Leave a comment

sed command and slang replacer

  • Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline).
  • sed command is used to replace text.
  • Example: Create file in which replace words are defined like
s/gne/Guru Nanak Dev Engineering College/g
s/gr8/great/g
s/yrs /years /g
s/yr /year /g
s/C /see /g
s/U /you /g
  • Create text file shortHand.txt written text like
I C U at gne, which is gr8 college. gne is 56 yr old. U need to C me  at that gr8 college, called gne.
  • Now, run the following command:
sed -f sedData shortHand.txt > longHand.txt
  • This command output the longHand.txt file in which all words written in shorthand are replace with longhand words.
I see you at Guru Nanak Dev Engineering College, which is great college. Guru Nanak Dev Engineering College is 56 year old. you need to see me
at that great college, called Guru Nanak Dev Engineering College.
Posted in Uncategorized | Leave a comment

Writing a simple document in Latex

  • LATEX input files can be created with any text  editor . It contains the LATEX commands and the contents you want to add in your document. The input for LaTeX is a plain ASCII text file.  The commands used in it tells LaTeX how to typeset the text.
  • LaTeX files usually have a .tex extension.
  • Simple example:
\documentclass [12pt] {article} 
\begin{document}
This is  my first document prepared in Latex. 
\end{document}
  • Another example:
\documentclass[12pt]{article} 
\title{\LaTeX} \date{} 
\begin{document} 
\maketitle 
\LaTeX{} is a document preparation system for the \TeX{} typesetting program. It offers programmable desktop publishing features and extensive facilities for automating most aspects of typesetting and desktop publishing, including numbering and cross-referencing, tables and figures, page layout, bibliographies,and much more. 
\end{document}
  • Save this file with extension .tex
  • In order to create the pdf of your file, go to terminal and run the following command :

     pdflatex filename.tex

  • The document environment: After the document class declaration, the text of your document is enclosed between two commands which identify the beginning and end of the actual document:
  • \documentclass[11pt,a4paper,oneside]{report}\begin{document}\end{document}You would put your text where the dots are.
  • Top Matter: At the beginning of most documents there will be information about the document itself, such as the title and date, and also information about the authors, such as name, address, email etc. All of this type of information within LaTeX is collectively referred to as top matter. A simple example:
  • \documentclass[11pt,a4paper,oneside]{report}
    \begin{document}
    \title{How to Structure a LaTeX Document}
    \author{Parveen Kaur}
    \date{December 2004}
    \maketitle
    \end{document}
  • If there are two authors separate them with the \and command:

\author{Jane Doe \and John Doe}

  • Abstract: As most research papers have an abstract, there are predefined commands for telling LaTeX which part of the content makes up the abstract. This command is available for the document classes article and report, but not book.
  • \documentclass{article}\begin{document}\begin{abstract}Your abstract goes here…\end{abstract}

    \end{document}

Posted in LaTex | Leave a comment

Secure your SSH server with Public/Private key authentification

  • Open SSH is the most widely used SSH server on Linux. Using SSH, one can connect to a remote host and gain a shell access on it in a secure manner .
  • Instead of logging in to SSH using a traditional password, you can also authenticate yourself without a password using a technique called public key authentication.
  • A neat feature of open SSH is to authenticate a user using a public/private key pair to log into the remote host. By doing so, you won’t be prompted for the remote user’s password.
  • How does public key cryptography work? Two keys are generated on the client computer: the public key and the private key. What makes the two keys special is that a message encrypted with one can only be decrypted with the other.
  • You give your public key to the server, which stores it in a list. Your private key stays hidden. When you attempt to log in, the server encrypts a message with your public key and sends it to you. Only your matching private key can decrypt the message. Your computer proves to the server that it has successfully decrypted the message. The server then logs you in.
  •  Public key authentication for SSH has many security advantages: a password is never transmitted in any form over the network, the key needed to decrypt the server’s message is much harder to guess compared to a password because it is much longer, and the server does not need to store your private key to know you have it.
  • Firstally, install it by running following command

sudo apt-get install openssh-server

  • Now you need to generate the key pair on the client system unless you already have. You can find if you have a key pair by checking for for these two files:

~/.ssh/id_rsa (your private key)

~/.ssh/id_rsa.pub (your public key)

  •  If you don’t have them (you will be warned if you do), generate a new key pair on your local computer (run this as your normal user):

ssh-keygen

  •  You will be asked two questions. Press enter to accept the default location for the keys. Then you will be asked for a passphrase. If you choose to use a passphrase, then you will be required to enter it whenever you use the private key. If you are doing this for extra security, you will want one. If you want convenience, leave it blank.
  • By now, you should have id_rsa and id_rsa.pub in ~/.ssh directory. id_rsa is the so called private key. id_rsa.pub is the public key, the one you are going to upload on your server in order to be able to gain access to the remote machine using key authetication.
  • Now that we have our public/private key pair ready, we need to upload it to the remote machine and enable access with it.

Adding the public key to the authorized key

  • In the first place, we need to upload the key to the remote machine:

scp ~/.ssh/id_rsa.pub remoteuser@remotehost:~/

  • Now, the public key is uploaded, let’s add it to the authorized keys. To do so, we are going to connect to remotehost as remoteuser and add the key at the end of file ~/.ssh/authorized_keys and delete it once added:
  • ssh remoteuser@remotehost
    remoteuser@remotehost’s password:
    remoteuser@remotehost:~$ cat id_rsa.pub >> ~/.ssh/authorized_keys
    remoteuser@remotehost:~$ rm id_rsa.pub
    remoteuser@remotehost:~$ exit
  • Now, we need to configure the remote SSH server to accept authentication by key pair. This is usually enabled by default

ssh root@remotehost
or by connecting to the remote machine with a normal user:
ssh remoteuser@remotehost

  • Now open and edit /etc/ssh/sshd_config and make sure you have the following line:
  • RSAAuthentication yes
    PubkeyAuthentication yes
  • Reload the configuration:

sudo /etc/init.d/ssh reload

  • now you should be able to connect to remoteuser@remotehost without supplying a password (but the passphrase of you private key if you supplied any) by simply typing the following:

ssh remoteuser@remotehost

  • if your private key file is not the standard ~/.ssh/id_rsa, you can inform ssh by using the -i switch as follow:

ssh -i /path/to/private/key remoteuser@remotehost

  • Once you are sure that you can log into the remote host using your private key, we can safely disable the username/password authentication.

Disabling Authentication by password

  • In order to disable authentication by password, we need to connect as root on the remote machine. On connected, go and edit /etc/ssh/sshd_config and make sure you have the following setting:

….
ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no

  • Reload SSH configuration file:

/etc/init.d/ssh reload

  • Now, open a new shell and connect the remote host using your private key:

ssh remoteuser@remotehost

  • Check that you can’t connect without a key anymore:
  • $ cd ~/.ssh
    $ mv id_rsa id_rsa.bck
    $ ssh remoteuser@remotehost
    Permission denied (publickey).
    $ mv id_rsa.bck id_rsa
  • If you get rejected with Permission denied (publickey). it means it is all good and your ssh server is protected against attacks.
  • By authenticating yourself using a public/private key pair and by disabling authentication by password you will considerably reduce the chance an attacker gain access to your remote machine. It is wise to provide a passphrase when creating your key pair, this way, even if somebody get a copy of your private key, you will reduce the risk of having him gaining access to your remote machine.

Visit the link for more details: http://www.debuntu.org/ssh-key-based-authentication

Posted in Uncategorized | Leave a comment