Tuesday, July 29, 2014

PPT on web using Flexslider

Setting up FlexSlider on your server.
 
Step 1: Download Flexslider from its website.http://www.woothemes.com/flexslider/

Step 2: Extract the flexslider tar file (woothemes-FlexSlider-version-2.2.2-0-gce5441b.zip) on your Linux server. Prefer to keep flexslider under a common path.

$ cd /var/www/html/sen/jquery/
$ unzip woothemes-FlexSlider-version-2.2.2-0-gce5441b.zip

This would a directory name woothemes-FlexSlider-ce5441b

Step 3: Create a directory under which you would host the presentation.

$ mkdir /var/www/html/sen/training

Step 4: Create sub directories

$ mkdir /var/www/html/sen/training/{themes,lib,material}

Step 5: Change to the base directory

$ cd /var/www/html/sen/training

Step 6: Create the file slides.css under themes directory

$ cat > themes/slides.css
* {
  margin: 0;
  padding: 0;
}

html {
  background: #222 ;
}

body {
  _width: 80%;
  color: #888;
  margin: 20px auto 0;
  max-width: 60%;
  text-align: center;
  text-shadow: 0 -2px 1px #000;
  -webkit-font-smoothing: antialiased;
  }

<Ctrl-D>

Step 7: Now we setup the html page view to show the slides. Create a file  slide_container.php under the themes directory. 

$ cat > themes/slide_container.php
<!doctype html>
<html>
<head>
        <link rel="stylesheet" href="flexslider/flexslider.css">
        <link rel="stylesheet" href="themes/slides.css">
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script src="flexslider/jquery.flexslider.js"></script>

        <script>
                $(window).load(function(){
                  $('#carousel').flexslider({
                        animation: "slide",
                        controlNav: false,
                        animationLoop: false,
                        slideshow: false,
                        itemWidth: 210,
                        itemMargin: 5,
                        asNavFor: '#slider'
                  });

                  $('#slider').flexslider({
                        animation: "slide",
                        controlNav: false,
                        animationLoop: false,
                        slideshow: false,
                        sync: "#carousel",
                        start: function(slider){
                          $('body').removeClass('loading');
                        }
                  });
                });
        </script>
</head>

<body>
        <div id="slider" class="flexslider">
                <ul class="slides">
                        <?php foreach ($images as $img) { ?>
                                <li><img src="<?php echo $img;?>" /></li>
                        <?php } ?>
                </ul>
        </div>
        <div id="carousel" class="flexslider">
                <ul class="slides">
                        <?php foreach ($images as $img) { ?>
                                <li><img src="<?php echo $img;?>" /></li>
                        <?php } ?>
                </ul>
        </div>
</body>

</html>

<Ctrl-D>
 
Step 8: The PPT slide image files would be placed under the "material" directory. Create the file get_img_files.php under lib directory.


$ cat > lib/get_img_files.php
<?php
$tot_digits=strlen((string) $tot_files);
$file_midix="?";
$pattern=$file_prefix . $file_midix . $file_suffix;

while (--$tot_digits > 0)
{
        $file_midix .= "?";
        $pattern .= "," . $file_prefix . $file_midix . $file_suffix;
}

// eg. $images = glob($thumbsPath.'*.{jpg,jpeg,png,gif}', GLOB_BRACE);
//
$images = glob($path . "/{" . $pattern . "}", GLOB_BRACE);

?>

<Ctrl-D>


Step 9: Create a softlink to the Flexslider directory. This would help easily change to new version of FlexSlider in future.

$ ln -s /var/www/html/sen/jquery/woothemes-FlexSlider-7ecc526/ ./flexslider
Step 10: Create a softlink to themes/slide_container.php. This would help you to try different layout for your page without disturbing your original work. Once a new container is ready you can just change the softlink to point to the new container.php.

$ ln -s themes/slide_container.php ./

With this we finish the setup of FlexSlider. The base directory shall now contain the following files and directories.

$ pwd
/var/www/html/sen/training/


$ ls -l
total 12
lrwxrwxrwx 1 root root   54 Jul 29 11:49 flexslider -> /var/www/html/sen/jquery/woothemes-FlexSlider-7ecc526/
drwxr-xr-x 2 root root 4096 Jul 29 12:07 lib
drwxr-xr-x 2 root root 4096 Jul 29 12:07 material
lrwxrwxrwx 1 root root   26 Jul 29 12:20 slide_container.php -> themes/slide_container.php
drwxr-xr-x 2 root root 4096 Jul 29 11:56 themes
 

The themes directory contain:

$ ls -l themes/*
-rw-r--r-- 1 root root 1736 Jul 29 11:56 themes/slide_container.php
-rw-r--r-- 1 root root  241 Jul 29 11:53 themes/slides.css
 

The lib directory contains:
$ ls -l lib
total 4
-rw-r--r-- 1 root root 206 Jul 29 13:29 get_img_files.php

 
Setting up a PPT slide

Step 1: Open your PPT in MS Power Point and save as JPEG format









 Step 2: Upload the folder created by Power Point to the "material" directory on your server. You may use WinSCP tool to upload the folder. If there are spaces in the folder name then delete or replace them with hypen or underscore character.
$ ls -l material/
total 4
drwxr-xr-x 2 root root 4096 Jul 29 13:37 Networking-01-Introduction

Step 3: Create a PHP script for the newly uploaded presentation slide. Let's name the file as chapter01.php. The content of this file shall be as follows:

<?php
$path="material/Networking-01-Introduction";
$file_prefix="Slide";
$file_suffix=".JPG";
$tot_files=38;

include "lib/get_img_files.php";

include "slide_container.php";

?>

The content marked in yellow needs your input. The $path should match the directory name of your slide, whereas the $tot_files need to match the number of image files present in that directory.
Now your slide is ready to be viewed using a web browser. Open the URL to the php file you created in step 3 above. The below snaps are from the URL http://172.19.1.224/sen/training/chapter01.php




Friday, May 2, 2014

L2TP

L2TP server:
http://linuxexplore.com/how-tos/l2tp-vpn-using-xl2tpd/

L2TP client:
http://www.softether.org/4-docs/2-howto/9.L2TPIPsec_Setup_Guide_for_SoftEther_VPN_Server/4.Windows_L2TP_Client_Setup
https://pandapow.co/how-to/win-l2tp-setup/

Wednesday, March 19, 2014

Authenticate Linux sshd with TACACS+ server

Step 1: Download and install the pam_tacplus module using the source code from git repository
            Go to the URL https://github.com/jeroennijhof/pam_tacplus/
            Click on the "Download ZIP" button and save the file.
            unzip pam_tacplus-master.zip;
            cd pam_tacplus-master;
            autoreconf --install
            autoconf
            automake --add-missing
            make;
            make install

Step 2: Add the following line in /etc/pam.d/sshd
            auth       include      tacacs

Step 3: Create and edit the file "/etc/pam.d/tacacs". Set the server and secret to match your TACACS+ server.
            #%PAM-1.0
            auth       sufficient   /usr/local/lib/security/pam_tacplus.so  debug   server=172.19.1.206 secret=MYKEY
            account    sufficient   /usr/local/lib/security/pam_tacplus.so  debug   server=172.19.1.206  secret=MYKEY    service=shell   protocol=ssh
session    sufficient   /usr/local/lib/security/pam_tacplus.so  debug   server=172.19.1.206 secret=MYKEY    service=shell   protocol=ssh

Step 4: Create a local users. You may set password for local login to fall back if the TACACS server is unavailable.

Reference: http://serverfault.com/questions/425020/authenticate-linux-sshd-with-tacacs-cisco-acs


Tuesday, February 18, 2014

Serial Console setup

/boot/grub/menu.lst

serial --unit=0 --speed=115200
terminal --timeout=5 serial console
title Red Hat Enterprise Linux (2.6.32-358.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=UUID=364ec31d-8027-4aac-ab2c-5daa9dc854b5 rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD  KEYTABLE=us SYSFONT=latarcyrheb-sun16 crashkernel=auto console=ttyS0,115200n8 rd_NO_LVM rd_NO_DM
        initrd /initramfs-2.6.32-358.el6.x86_64.img

/etc/securetty
ttyS0

/etc/init/ttyS0.conf
# ttyS0 - agetty
#
# This service maintains a agetty on ttyS0.

stop on runlevel [S016]
start on runlevel [23]

respawn
exec agetty -h -L -w /dev/ttyS0 115200 vt102
 

Sunday, December 1, 2013

Linux Bridge

file: ifcfg-br0


DEVICE=br0
TYPE=Bridge
IPADDR=10.1.0.58
NETMASK=255.255.255.0
ONBOOT=yes
BOOTPROTO=none
file: ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
HWADDR=00:11:25:6E:E3:43
ONBOOT=yes
BOOTPROTO=none
BRIDGE=br0
file: ifcfg-eth2
DEVICE=eth2
TYPE=Ethernet
NM_CONTROLLED=no
ONBOOT=yes
BOOTPROTO=none
BRIDGE=br0
ebtables:
ebtables -t broute -A BROUTING -p 8847 -j redirect --redirect-target ACCEPT
ebtables -t broute -A BROUTING -p IPv4 --ip-protocol 6  --ip-destination-port 80 -j redirect --redirect-target ACCEPT
 sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 1
 

Thursday, December 6, 2012

A PHP script to send custom HTTP response

With the following php script one could request for a response with specific content-type, size and content-disposition.

Copy the below content to /var/www/html/askme.php and access http://server/askme.php?help

<?php


if(isset($_GET['help']))
{
    header("Content-type: text/html");
    echo "<h2>usage: http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"] . "?size=&lt;num>&lt;K|M|G>&type=&lt;content-type>&filename=&lt;name>" ;
    echo "<h2>example: http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"] . "?size=10K&type=image/png" ;
    exit;
}

if(isset($_GET['size'])) $size=$_GET['size']; else $size=0;
if(isset($_GET['type'])) $type=$_GET['type']; else $type="application/octet-stream";

header("Content-type: $type");
if(isset($_GET['filename']))
{
    header('Content-Disposition: attachment; filename="'. $_GET['filename'] .'"');
}

system ("dd if=/dev/zero bs=$size count=1");
?>

Monday, October 1, 2012

Simple Mail service using Sendmail + Dovecot

Background:
Tools like Reviewboard, Hudson, STAF/STAX has the capability for sending email notification. Most often the office mail server would not accept emails from such tool for security reason. So whats the way out ?

Can we make use of the Linux sendmail service for this purpose ?

Solution:

Step 1:  Sendmail configuration to accept SMTP request on non-localhost address

Sendmail by default listens on 127.0.0.1:25. Configure it to listen on 0.0.0.0 in /etc/mail/sendmail.mc as follows:
Modify the line
      DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
as
     DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl

Then restart the sendmail service
    bash$ service sendmail restart

Step 2: Setup Dovecot Service
Configure /etc/dovecot/dovecot.conf with the following

       login_trusted_networks = 172.19.0.0/16
where 172.19.0.0/16 is your LAN

Configure /etc/dovecot/conf.d/10-mail.conf with the following
       mail_location = mbox:~/mail:INBOX=/var/mail/%u
       mail_privileged_group = mail

Then restart the dovecot service
       bash$ service dovecot restart

Step 3: Setup users
Just create normal Linux users using "useradd" command.

Step 4: Setup Outlook to send and receive mails
Open the menu "Tools" - "Account Setting"

In the Add New E-mail Account window, select "Microsoft Exchange, POP3, IMAP, or HTTP" and then click Next.

Check the box "Manually configure server settings or additional server types" and click next.

Configure similar to the one below. Note dev.dmp.com is the hostname of local server where sendmail+dovecot is setup.