Tuesday, April 12, 2011

Steps to do SSH Login from Remote Server without the password

Steps to do SSH Login from Remote Server without the password

Open 2 terminal screens - 1 for local and one for remote

1. ~/.ssh$ ssh-keygen -t rsa
    Press enter for the rest of the steps below
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/localadmin/.ssh/id_rsa):
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:

    You will get 2 files generated .pub is the public key and other one is the private key.
    :~/.ssh$ ls
    id_rsa  id_rsa.pub

2 :~/.ssh$ vi id_rsa.pub
 Now right click and copy the key

3. Go to remote server terminal screen
  Create a user using useradd -m "name of the user same as the user on your localhost"

 a. Now go to /home/youruser and create a directory .ssh
    remotehost:/home/youruser/.ssh# ls
    remotehost:/home/youruser/.ssh# nano authorized_keys

 Now paste the key which you copied in previous step
 b.
    remotehost:/home/youruser/.ssh# chmod 600 authorized_keys
    remotehost:/home/youruser/.ssh# cd ..
    remotehost:/home/youruser/# chmod 755 .ssh
    remotehost:/home/youruser# cd ..
    remotehost:/home# chown -R youruser youruser
    remotehost:/home# chgrp -R youruser youruser


4. Now come back to your localhost screen

    localhost:~/.ssh$ ssh usercreatedonremoteserver(Step 3 a)@remoteserveripaddress

     You should be able to login from the localhost

     Tip : change of owner and change of group is required. Step 3 b.

Wednesday, March 23, 2011

Access database in php

<?php
error_reporting(-1);

$man_db = db_query("SELECT DISTINCT manufacture_name FROM {drup_deductible} WHERE drup_deductible.carrier_name LIKE '%Verizon%' ORDER BY manufacture_name");
$model_db = db_query("SELECT DISTINCT model_name FROM {drup_deductible} WHERE manufacture_name LIKE '%".$_REQUEST['manufacturer']."%' ORDER BY model_name");
$deduct_db = db_query("SELECT drup_deductible.tier_name, drup_tier.tier_name, drup_tier.tier_amount, drup_tier.tier_premium FROM {drup_tier},{drup_deductible} WHERE drup_tier.tier_name = drup_deductible.tier_name AND drup_deductible.carrier_name = 'Verizon' LIMIT 1");

$today = date('m/d/Y');
if($today >= "06/01/2011"){
    $effectiveDate = "05/17/2009";
} else {
    $effectiveDate = "02/01/11";
}

function dropdownfunc($name, $rowname, $source){
    foreach($source as $row) {
        if ($row->$rowname == $_REQUEST[$name])
        {
            $s = " SELECTED";
        } else {
            $s = "";
        }
        echo '<option value="'.$row->$rowname.'"'. $s.'>'.$row->$rowname.'</option>';
    }
}
?>
<div id="newwrapper">
    <div style="margin-top: -23px; margin-left: -22px; /margin-left: -15px; width: 975px; position: relative;">
        <div style="float:left; width:648px; margin-right: 5px;">
            <div id="vz-redesign-top"></div>
            <div style="padding-left: 25px; margin-top: 20px; /margin-top: 0px; position: relative; min-height: 200px;">
                <p style="font-size: 16px;">Select your manufacturer and model</p>
                <form method="POST" action="lookup">
                    <div style="float:left;width:160px;padding-right:15px; margin-top: 0px;">
                        <span style="font-size: 16px !important;">Manufacturer</span><br/>
                        <select name="manufacturer" onchange="this.form.submit();">
                            <option value="">Select a manufacturer</option>
                            <?php dropdownfunc('manufacturer', 'manufacture_name', $man_db); ?>
                        </select>
                    </div>
                    <input type="hidden" name="_submit" value="1">
                    <div style="float:left;width:150px;">
                        <span style="font-size:16px !important; margin-bottom: 10px;">Model</span><br/>
                        <select name="model" onchange="this.form.submit();"><br/>
                            <option value="">Select a model</option>
                            <?php dropdownfunc('model', 'model_name', $model_db); ?>
                        </select>
                    </div>
               </form>

               </form>
               </div>
               </div>
               </div>
               </div>

Sunday, March 20, 2011

JQuery Dialog Box capture input

JQuery Dialog Box capture input

<html lang="en">
<head>
  <title></title>
  <link type="text/css" href="js/themes/base/ui.all.css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
  <script type="text/javascript" src="js/jquery-ui-1.8.7.custom.min.js"></script>
   <link type="text/css" href="js/demos.css" rel="stylesheet" />
  <script type="text/javascript">
    $(function() {
        var cancel = function() {
            $("#myDialog").dialog("close");
        }
        var getResponse = function(){
          var answer;
          $("input").each(function(){
            (this.checked == true) ? answer = $(this).val() : null;
          });
          $("<p>").text(answer).insertAfter($("#poll"));
          $("#myDialog").dialog("close");
        }
        var dialogOpts = {
          modal: true,
          buttons: {
            "Done": getResponse,
            "Cancel": cancel
          },
          autoOpen: false
        };
        $("#myDialog").dialog(dialogOpts);
        $("#poll").click(function() {
          $("#myDialog").dialog("open");
        }); 
    });
  </script>
</head>
<body>
    <button id="poll">Poll</button>
    <div id="myDialog" class="flora" title="This is the title">
      <p>Question?</p>
      <label for="yes">Yes!</label><input type="radio" id="yes" value="yes" name="question"><br>
      <label for="no">No!</label><input type="radio" id="no" value="no" name="question">
    </div>
</body>
</html>