10 April 2020

Convert all MyISAM tables into InnoDB

InnoDB has become the default Storage Engine for mysql tables, which offers more features and better performance than MyISAM.

If you have website created in or around the year 2009-2010 then your website still be using MyISAM based tables even if you have already upgraded your mysql server version to the superior or latest, like i had one.


Here are the steps to convert all MyISAM tables into InnoDB.

login into SSH terminal and run the commands and queries.
step 1:
mysql -u root -p database_name

you will be asked to enter password, then you will see mysql console where you can execute queries.

step 2:
SELECT CONCAT('ALTER TABLE ',TABLE_NAME,' ENGINE=InnoDB;')
FROM INFORMATION_SCHEMA.TABLES
WHERE ENGINE='MyISAM'
AND table_schema = 'database_name';


now you will all table names that has MyISAM as storage engine with query format to convert into InnoDB.
example
ALTER TABLE table_name ENGINE=InnoDB;


step 3: now copy all the alter queries and paste in the mysql console. you can copy paste one by one or all at once.
be aware of | and +------------------------------------------------------+ around the list. you can use text/code editor like notepad, notepad++ , vs code to remove those characters.


Thanks & Credits to https://computingforgeeks.com/how-to-convert-all-mysql-tables-from-myisam-into-innodb-storage-engine/


28 March 2020

get access token from google oauth2 service account json file using jwt token

Here is a simple code snippet that takes google service account .json file as input and gives you access token with the specified scope.



Hope it helps somebody who is in need of , or been searching for it.

22 January 2020

Install latest linux kernel on Ubuntu server

Sometimes upgrading linux kernel may increase overall performance of your server (including network and task processing).

You can download any version of kernel from here
https://kernel.ubuntu.com/~kernel-ppa/mainline/

Latest Stable Kernel: 5.4.13 https://kernel.org

so we install kernel 5.4.13

cd /tmp/

wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.4.13/linux-headers-5.4.13-050413_5.4.13-050413.202001171431_all.deb

wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.4.13/linux-headers-5.4.13-050413-generic_5.4.13-050413.202001171431_amd64.deb

wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.4.13/linux-image-unsigned-5.4.13-050413-generic_5.4.13-050413.202001171431_amd64.deb

wget -c https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.4.13/linux-modules-5.4.13-050413-generic_5.4.13-050413.202001171431_amd64.deb

sudo dpkg -i *.deb


if your Ubuntu version is old you may need to install additional dependency packages

You can search any missing packages here https://packages.ubuntu.com/search and get their download links and install using dpkg -i .deb

3 November 2019

Telegram bot file_id parser

function base64url_decode($data) {
  return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
 function rle_decode($string)
    {
        $new = '';
        $last = '';
        $null = chr(0);
        foreach (str_split($string) as $cur) {
            if ($last === $null) {
                $new .= str_repeat($last, ord($cur));
                $last = '';
            } else {
                $new .= $last;
                $last = $cur;
            }
        }
        $string = $new.$last;
        return $string;
    }
function parse($s)
{
$s = base64url_decode($s);
$s=rle_decode($s);
   $r=unpack("ifile_type/idc_id/qfile_id/qaccess_hash",$s);
    return $r;
}

var_dump(parse('AgADBAADZbMxG7cJAVGXAeNiLWOiH5lPqBsABAEAAwIAA3kAAzcYAwABFgQ'));

possbible file_type list

0 = thumbnail
2 = photo
3 = voice
4 = video
5 = document
8 = sticker
9 = audio
10 = gif
13 = video_note (round video)

Setup Network File System(NFS) Client and Server on Ubuntu

server side run the following commands.


apt install nfs-kernel-server

vi /etc/exports

add /path/you/want/to/share/with/client 10.0.0.0/16(rw,sync,no_root_squash,no_subtree_check)

save it

run exportfs -v
run exportfs -ra


client side commands


apt install nfs-common

mount -t nfs -o vers=3 10.0.0.4:/remote/path /local/path

for persistent mount, add entry in fstab.
vi /etc/fstab

10.0.0.4:/remote/path /local/path nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0

4 February 2019

TANGEDCO TNEB AE 2018 Results, Cut-off, Question papers and Answers

TANGEDCO TNEB AE 2018 exam which was conducted on 30/12/2018 its result was released today 04/02/2019 around 7pm-8pm.

i have collected question papers from their unstable website for all department with answers.

You can view or download questions and answer from google drive link https://drive.google.com/drive/folders/1cGjvM3tdMk0AaDKbS5fVTSVR9TC3Xx_B

Check your marks here  https://drive.google.com/open?id=1i40-NM-Pt4TxJc7sW-wakJzpG3yLsK5M
Cutt-off marks https://drive.google.com/open?id=1rLtPFxX9UTL76pljY8ehs1Qp-H0AavM-

better luck next time.


8 September 2018

execute root commands via php

Solution using a binary wrapper (with suid bit)

1) Create a script (preferrably .sh) that contains what you want to be ran as root.
# cat > php_shell.sh <<CONTENT
  #!/bin/sh
  /sbin/service sshd restart
CONTENT
2) This file should be owned by root, and since it will later run with root permissions make sure that only root has permission to write to the file.
# chown root php_shell.sh
# chmod u=rwx,go=xr php_shell.sh
3) To run the script as root no matter what user that executes it, we will need a binary wrapper. Create one that will execute our php_shell.sh.
# cat > wrapper.c <<CONTENT
  #include <stdlib.h>
  #include <sys/types.h>
  #include <unistd.h>

  int
  main (int argc, char *argv[])
  {
     setuid (0);

     /* WARNING: Only use an absolute path to the script to execute,
      *          a malicious user might fool the binary and execute
      *          arbitary commands if not.
      * */

     system ("/bin/sh /path/to/php_shell.sh");

     return 0;
   }
CONTENT
4) Compile and set proper permissions, including the suid bit (saying that it should run with root privileges):
# gcc wrapper.c -o php_root
# chown root php_root
# chmod u=rwx,go=xr,+s php_root
php_root will now run with root permissions, and execute the commands specified in php_root.sh.

If you don't need to the option to easily change what commands that will be executed I'd recommend you to write the commands directly in wrapper.c under step 4. Then you don't need to have a binary executing a external script executing the commands in question.
In wrapper.c, use system ("your shell command here"); to specify what commands you'd like to execute

source https://stackoverflow.com/a/8532448