Saturday, 16 September 2017

Downloading A Zip File Using Javascript Is Not Rocket Science! Learn Them Now!

Initially, the prerequisite for downloading a simple text file in javascript requires FileSaver.js. This can be downloaded from here.


Next step would be the creation of zip file.

1. Download jSZip and load it in your html.

2. Here comes the core part where we initalize jSZip and download a zip file.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
     var zip = new JSZip();         

    //skip this step if you don't want your files in a folder.
    var folder = zip.folder("example");
    folder.file("myfile1.txt", "HELLO WORLD IN 1ST FILE"); //requires filesaver.js
    folder.file("myfile2.txt", "HELLO WORLD IN 2ND FILE");

    //...so on until you have completed adding files

    zip.generateAsync({type:"blob"})
               .then(function(content) {
                //see FileSaver.js
                saveAs(content, "example.zip");
      });

Thursday, 14 September 2017

All You Need To Know About Scp, Ssh And Rsync Without Prompting For Password.

Whenever you need to use scp to copy files, it asks for passwords. Same with rsync as it (by default) uses ssh as well. Usually scp and rsync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying when the password is asked every time.


Lets say you want to copy between two hosts user_src and user_dest.user_src is the host where you would run the scp, ssh or rsync command, irrespective of the direction of the file copy!

  1. On user_src,
    run this command as the user that runs scp/ssh/rsync

     $ ssh-keygen -t rsa
    

    This will prompt for a passphrase. Just press the enter key. It'll then generate an identification (private key) and a public key. Do not ever share the private key with anyone! ssh-keygen shows where it saved the public key. This is by default ~/.ssh/id_rsa.pub: Your public key has been saved in <your_home_dir>/.ssh/id_rsa.pub
  1. Transfer the id_rsa.pubfile to user_dest by either ftp, scp, rsync or any other method.
  1. On user_dest, login as the remote user which you plan to use when you run scp, ssh or rsync on user_src.
  2. Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys
    $ cat id_rsa.pub >>~/.ssh/authorized_keys
    $ chmod 700 ~/.ssh/authorized_keys
    
    If this file does not exists, then the above command will create it. Make sure you remove permission for others to read this file. If its a public key, why
    prevent others from reading this file? Probably, the owner of the
    key has distributed it to a few trusted users and has not placed any
    additional security measures to check if its really a trusted user.

  1. Note that ssh by default does not allow root to log in. This has to be explicitly enabled on user_dest. This can be done by editing /etc/ssh/sshd_config and changing the option of PermitRootLogin
    from no to yes. Don't forget to restart sshd so that it reads the modified config file. Do this only if you want to use the root login.
Well, thats it. Now you can run scp, ssh and rsync on user_src connecting to user_dest and it won't prompt for the password. Note that this will still prompt for the password if you are running the commands on user_dest connecting to user_src. You can reverse the steps above (generate the public key on user_dest and copy it to user_src) and you have a two way transfer ready without prompting for password!

Credits: blogs.oracle.com

Starter Guide to Set up Plone on Linux

1. Link to Download Plone

https://plone.org/download/releases/5.0.6

2. Type the command below in terminal to install plone dependencies on Linux


sudo apt-get install python-setuptools python-dev build-essential libssl-dev libxml2-dev libxslt1-dev libbz2-dev libjpeg62-dev


3. You will probably also want these optional system packages for handling of PDF and Office files:

sudo apt-get install libreadline-dev wv poppler-utils

4. Untar the downloaded file and cd to Plone directory and type the command below to initiate the plone setup

./install.sh

Follow the onscreen instructions to finish the setup.

5. The default admin credentials will be printed to the console, and saved in the file adminPassword.txt in the resulting install. You can change this password after logging in to the Zope Management Interface.



6. Start Plone - If you're developing, start Plone in foreground mode for a test run (you'll see potential errors in the console):

$ cd ~/Plone/zinstance
$ bin/plonectl fg

This will list the hostserver and port number on which plone is running(Have these details noted for future use)

When you start Plone in the foreground, it runs in debug mode, which is much slower than production mode since it reloads templates for every request.

7. For evaluation, instead use:

$ cd ~/Plone/zinstance
$ bin/plonectl start

8. Stop plone - To stop the plone, use:

$ cd ~/Plone/zinstance
$ bin/plonectl stop

By default, Plone will listen to port 8080 on available network interfaces. The port may be changed by editing buildout.cfg and re-running buildout.


9. Now take a look at your Plone site by visiting the following address in your webbrowser:

http://yourserver:8080(mention the hostserver and port number noted in step 6)

Install the Plone developer tools
If you're using this Plone install for development, add the common development tool set.

$ cd ~/Plone/zinstance
$ bin/buildout -c develop.cfg

NOTE : When you start Plone in the foreground, it runs in debug mode, which is much slower than production mode since it reloads templates for every request.



Ref link : http://docs.plone.org/manage/installing/installation.html

Set up PHP mailer on Go Daddy

Popular hosting provider GoDaddy imposes very strict (to the point of becoming almost useless) constraints on sending an email. They block outbound SMTP to ports 25, 465 and 587 to all servers except their own.

If you find your script works on your local machine, but not when you upload it to GoDaddy, then you'll have to refrain from using SMTP attributes in your PHP mail script. Instead, you can simply use Go Daddy's web mailer to configure PHP mailer and provide the hostname, username and password to enable sending  mails on your script. Use the following code after configuring your webmailer:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$mail = new PHPMailer;

$mail->Host = 'localhost';              // Specify this option as localhost
$mail->Username = 'info@yourdomain.com';// webmailer username
$mail->Password = 'your pwd';           // webmailer password
$mail->Port = 587;                      // TCP port to connect to

  
$mail->setFrom('your from mail address', 'From name');

$mail->addAddress(recipientemail);      // Add a recipient in $email


PS : You might get following errors while trying to run PHP mailer with SMTP on Go Daddy :

Error : PHPMailer- Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting