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