Tuesday, November 23, 2021

How to disable attachments in chatter module of odoo?



The reason to disable attachment may be anything like
 1. There is no actual need from client for attachment
 2. Server Space constraint/restriction
 3. Avoiding malicious file upload (security reson -  VAPT observation) etc.,

To remove add attachment option from chatter module
File : /<your_path_to_odoo>/addons/portal/static/src/xml/portal_chatter.xml
Comment the following line: (In odoo14 - to be precise at line no - 55 )
    <button class="o_portal_chatter_attachment_btn btn btn-secondary" type="button" title="Add attachment">
           <i class="fa fa-paperclip"/>
        </button>
        
       <!-- <button class="o_portal_chatter_attachment_btn btn btn-secondary" type="button" title="Add attachment">
           <i class="fa fa-paperclip"/>
        </button> -->


For your reference and perusal screenshots before and after the code block comment.

Before commenting attachment code block
 
chatter module after attachment comment

 

 

Wednesday, November 17, 2021

Modify/Implement session expiration in odoo (version - 14)


    The internet deployments of odoo is vulnarable in terms of auto session expiration.
    
    It is indeed the auto session expiration is implemented in odoo(version-14).  But, the session expiration will  happen if and only if the inactivity is 7 days (A full week - 60*68*24*7) long.  Which is realllly a huge time to auto
 expire a session. The following code is responsible for auto session expiration.
 

 File -> /<your_path_to_odoo_source>/odoo-14/odoo/http.py
 Search for "def session_gc" - (to be precise line number 1164 of odoo-14 version)
 
 def session_gc(session_store):
    if random.random() < 0.001:
        # we keep session one week
        #last_week = time.time() - 60*60*24*7 #- old code with 1 week implementation
        last_10min = time.time() - 60*10 #- new code with 10 min implementation
        for fname in os.listdir(session_store.path):
            path = os.path.join(session_store.path, fname)
            try:
                #if os.path.getmtime(path) < last_week: #- old code with 1 week implementation
                if os.path.getmtime(path) < last_10min: #- new code with 10 min implementation
                    os.unlink(path)
            except OSError:
                pass

The above code changed from the actual implementation of 7 days to new implementation of 10 minutes auto session expiry.

Now, restart the odoo for changes to get effect (python3 odoo-bin -c /<your_odoo_odoo-14_path/debian/odoo.conf).

Friday, November 12, 2021

How to redirect http requests to https?


Add the following lines to the /etc/apache2/sites-enabled/000-default.conf file in side <VirtualHost *:80> </VirtualHost> block (In debian based linux)

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Tuesday, August 24, 2021

How to attach and detach your drive files to google colab?

To attach execute the following

from google.colab import drive
drive.mount('/content/drive') 
   

To Detach execute the following,

from google.colab import drive
drive.flush_and_unmount()

Tuesday, March 12, 2019

How to make Brother HL 2040 printer working under Linux?


Go to this link -> https://www.openprinting.org/printer/Brother/Brother-HL-2040

Click on the link "directly download PPD" which is underlined in green colour
PPD for Brother-HL-2040


Now in your linux machine (Debian based)
goto printer settings -> Select the "provide PPD" option -> Browse to the downloaded PPD file and "apply"

Check with the test print.

Friday, March 1, 2019

how to do math operations inside Django template?

1. Install "django-mathfilters" package using pip
   pip install django-mathfilters

2. Open settings.py file of your Django project and add  'mathfilters' in INSTALLED_APPS section.
   After this your settings.py file's INSTALLED_APPS section will look as follows
   INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'mathfilters',
   ]

3. Now you can do the basic math operations like add, sub, mul, div etc., like as follows
    add - {{ 8|add:4 }}
    mul - {{ your_var|mul:2 }}

For more details please refer -> https://pypi.org/project/django-mathfilters/

Thursday, February 28, 2019

How to import csv data into mongodb?

How to import large amount of csv data to mongodb
mongoimport -d <dbname> -c <collection_name> --type csv --file </path/to/actual/file.csv> --headerline

<blah> - Replace with your respective values

-d <dbname> - Tells to your mongo server into which database you want to import
-c <collection_name> - Tells to your mongo server in <dbname> into which collection you want to import
--type csv - Says it is a csv file
--file <path> - Give full path to your csv file
--headerline - if given, uses the first line as field names.

Monday, November 12, 2018

How to fix "Use gi.require_version('Gtk', '3.0') before import" error

Error:

gi.require_version error









Solution:

Replace the line
"from gi.repository import Gtk"

with

"import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk "

Wednesday, July 19, 2017

How to get the serial number of your network device in linux?


1. sudo lshw -C network | grep -i serial
    lshw    - Command used to list the details of all available hardware in a system.
    -C      - Option used to specify hardware "class".
        network - We asked "lshw" to list only the network devices.

    grep    - Command used to print lines that matches the given pattern
    -i    - Option used to ignore case sensitivity
    serial    - Pattern used to fetch the lines that contains the word "serial"

Example:
$sudo lshw -C network | grep -i serial
[sudo] password for :
       serial: 78:f2:9e:f3:88:e7

   
2. /sbin/ifconfig | grep -i hwaddr or sudo ifconfig | grep -i hwaddr
    ifconfig-Command used to configure network devices.
    grep    - Command used to print lines that matches the given pattern
    -i    - Option used to ignore case sensitivity
    serial    - Pattern used to fetch the lines that contains the word "serial"


Example:
$/sbin/ifconfig | grep -i hwaddr
eth0      Link encap:Ethernet  HWaddr 78:f2:9e:f3:88:e7  


3. GUI Way
Applications -> System Tools -> Settings

                                  You will land in the following screen
Settings panel



Click on Network the following window will be open


Network settings panel


The green highlighted part is our interest.




Friday, May 5, 2017

6 often needed sed scripts for string processing

1. How to remove all empty lines in a file
  sed -e '/^$/d' filename.txt

2. How to remove the leading empty spaces
  (whitespace only) -> sed -e 's/^[ ]*//' /file/path/filename.txt
  (whitespace and tab \t) -> sed -e 's/^[ \t]*//' /file/path/filename.txt

3. How to add some string to starting of all lines of a file
  sed -e 's/^/string-to-add-at-starting/g' /file/path/filename.txt

4. How to add date to starting of all lines
  sed -e "s/^/$(date) /g" /file/path/filename.txt  - Note: The Double quotes.
  Before    ->    line in a file
  After    ->    Thu May  4 17:31:58 IST 2017 line in a file

5. How to add formatted date to starting of all lines
  sed -e "s/^/$(date '+%m\/%d\/%Y %H:%M:%S') /g" /file/path/filename.txt
  Example:
   Before    ->    line in a file
   After    ->    05/04/2017 17:30:50 line in a file

6. How to do multiple replace at one go
  sed -e 's/string-to-find1/string-to-replace1/g' -e 's/string-to-find2/string-to-replace2/g' /file/path/filename.txt

Some More scripts:
7. How to remove all contents after pattern match
  sed -e '/pattern/,$d' /path-to/file/filename.txt
  For Ex: To remove all contents after first empty line -> sed -e '/^$/,$d'


8. How to remove all contents before pattern match
  sed -e '0,/pattern/d' /path-to/file/filename.txt
  For Ex: To remove all contents before first empty line -> sed -e '0,/^$/d'

Wednesday, May 3, 2017

How to create printable version of a man page..?

Most of us are always feel boring to read man pages in terminal window. what if we have a printable version of a particular command's manpage.? Nice isn't it.. so, how we can create a printable version of a manpage...

Step 1: Issue the following command in terminal
$man -t > destination_file_path.ps

Ex:$man -t mkdir > ~/Desktop/mkdir_manpage_printableversion.ps

Now you got a file named " mkdir_manpage_printableversion.ps " in your Desktop :). you can now print and use it..

Note: .ps(Postscript) is the default file type used to print.  It can be opened with any PDF viewer and can be printed.

Tuesday, March 14, 2017

How to edit/Modify/Delete Bookmarks in vinagre?


Vinagre bookmarks are stored in the file vinagre-bookmarks.xml file under /home//.local/share/vinagre directory.

As all the bookmarks are stored in single line be bit more cautious before editing, otherwise you will endup mess.
(I Recommend to keep a backup of the file before editing)

All the bookmarks are starts and ends with & xml node.  So as per your wish do edit/modify the Bookmarks.

Example entry in vinagre-bookmarks.xml file: <item><item><protocol>vnc</protocol><name>Asset-Mgmt-Client-1</name> <host>10.184.48.82</host><username></username><port>5915</port> <fullscreen>0</fullscreen><width>800</width><height>600</height> <view_only>0</view_only><scaling>0</scaling><keep_ratio>1</keep_ratio> <depth_profile>0</depth_profile><lossy_encoding>0</lossy_encoding></item>

Monday, January 16, 2017

How to fix/suppress "apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1." warning message?



Warning message Before the fix:

"apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message"


Fix: 
execute the following command in terminal

echo "ServerName localhost" | sudo tee -a /etc/apache2/apache2.conf

Now restart apache server by executing the following command

sudo /etc/init.d/apache2 restart


Message after the fix:
[ ok ] Restarting web server: apache2.

Monday, January 9, 2017

How to resolve "no suitable module for running kernel found" error in virtualbox instalation in debian linux?

1. Check wheather you machine is installed with "linux-headers-, linux-image-"
by issueing the follwing command in terminal.

  $dpkg -l | grep linux

In my case my kernel version is "3.16.0-4-686-pae" so the output of the above command would be something like as follows, 


missing-linux-headers
Missing linux headers package







If you don't find any linux-headers or linux-images then you must install them first.

2. To find the your kernel version use the following command
  $uname -a

[ My output -> Linux hostname 3.16.0-4-686-pae #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19) i686 GNU/Linux ]

now install the required packages specified in step 1.

3.  Uninstall your previous virutalbox package and reinstall it.

  $sudo apt-get remove --purge virtualbox
  $sudo apt-get instlal virtualbox

4.  Restart you machine.

Wednesday, October 19, 2016

How to find filesystem type in linux machine?

There are many ways to find the filesystem of a partition in linux (provided the partition mounted)
Following are the command line tools run these commands as is in terminal.

1.  cat /etc/fstab

2.  cat /etc/mtab

3.  mount

4.  df -T

Note:  You should know the partition number (like /dev/sda2, /dev/sda4 etc.,) or the partition label (Like mypendrive, 8GB_drive etc.,) or the UUID number.

Tuesday, October 18, 2016

Youtube videos not working asking for flash plugin | How to install adobe-flash player in (Debian based)Linux?


1.  Download the adobe-flash player from -> https://get.adobe.com/flashplayer/

2.  Select ".tar.gz for other linux" then click on "Download now"
        Note:  If you are using debian or rpm based linux then select your option accordingly.

3.  Unpack the download file (Right-click on the file and select -> "Extract here")
        (Note:  There will be a readme.txt file inside the extracted directory (like install_flash_player_11_linux.i386).  This file contains the detailed instructions for installation for all the flavours of Linux.)

4.  copy the "libflashplayer.so" file into following directories

        a. /usr/lib/flashplugin-nonfree/
        b. /usr/lib/mozilla/plugins/
        If you have chromium browser then copy the file into
        c. /usr/lib/chromium/plugins/
       
5.    Test the flash plugin -> Close the browsers (if already opened) then start again.
        Now, open youtube and check the videos will play like charm.

Wednesday, October 5, 2016

How to enable ssh access for root user in Linux (debian based)?

1. Edit the /etc/ssh/sshd_config file as sudo(or root) user
        $sudo vim /etc/ssh/sshd_config
2. Modify the "PermitRootLogin" value as "yes" under "Authenticaton" Section
        After editing your sshd_config file's Authentication section will look like

sshd_config screen shot "PermitRootLogin yes"

PermitRootLogin yes

3. Save the changes (esc :wq)
4. Restart the ssh service
        $sudo /etc/init.d/ssh restart
       
5.  Now check root login via ssh from a remote machine
        (From a another/remote machine)
        $ssh root@
       
Note:
The parameter PermitRootLogin can take any of the following values namely,
    yes, without-password, forced-commands-only, no
   
   
PermitRootLogin
 "yes"                                    =    ssh root login allowed

 "without-password"         = password authentication is disabled for root.

 "forced-commands-only" = root login with public key authentication will be allowed,
                                                     but only if the command option has been specified. All
                                                     other authentication methods are disabled for root.

 "no"                                        = root is not allowed to log in.




Wednesday, July 8, 2015

How to fix "nickname is already in use" error in irc?

What causes IRC to throw "nickname is already in use":
1.  You are not closed your previous session of IRC chat
     a) Trying to login with same nickname in another place/application with 
          existing active connection.
2.  You are internet connectivity disconnected & IRC server not released 
      your session.

How to fix:
a) /msg nickserv ghost <your_nickname> <password>
b) /msg nickserv <your_nickname>
b) /msg NickServ identify <password>

Tuesday, July 7, 2015

Migrate Postgresql 9.1 to 9.4 in 4 steps

Postgresql elephant
By Jeff MacDonald [BSD], via Wikimedia Commons


$pg_lsclusters - Shows the currently running (online/down) postgres DB

$sudo pg_ctlcluster 9.1 main stop - Stops the running postgres 9.1

$sudo pg_upgradecluster 9.1 main - Upgrades(migrates) postgres to newer version(upgrade time depends on the amount of data).

Check whether the upgrade went fine and the newer version of postgres works fine by
$su postgres
postgres@xyz:/$ psql
psql (9.4.3)                       Now postgresql upgraded to new version
Type "help" for help.
postgres=#\l                     -   Check all your databases are available or not
postgres=#\c <your_database_name>  - Connects to your database
postgres=#select * from <your_table_name> - Check the content is same.

Optional:
$sudo pg_dropcluster 9.1 main  -  Do this only, If you really want to drop your old postgres cluster.

Monday, June 29, 2015

How to dist-upgrade BOSS GNU/Linux?

I am user of BOSS GNU/Linux version 5.0(code name: anokha) since a few years and i am content with it.  It's been about a year that the next version 6.0 (code name: anoop) is out there for public usage, I am bit afraid to upgrade my machine.  There are two reasons for my hesitation,

1.  I am completely adapted(/addicted) to BOSS 5.0, and pretty much comfortable with it.  I don't want to lose my comfortableness.

2.  I afraid to dist-upgrade, which many a time leads to -> at minimum inconsistency & at maximum machine crash.

So, what made me to upgrade my linux box?
It's been about 2 years since my last bug-fix to LibreOffice office suite.  And that FOSS contribution itch starts now again.  So, I decide to download & compile the source code LibreOffice in my Linux box.  But, Unfortunately when I to do so I end up with the error

"libo/sal/qa/rtl/strings/test_oustring_stringliterals.cxx: In member function ‘void test::oustring::StringLiterals::checkOUStringLiteral1()"
libo/sal/qa/rtl/strings/test_oustring_stringliterals.cxx:195:48: internal compiler error: Segmentation fault

As the reason pointed out by the LibreOffice developers, I have to use gcc-4.8 or higher version to compile the LibreOffice source.  But, It's not available with BOSS 5.0 (which derived from Debian release wheezy) and the same is with debian also (even backports also don't have gcc-4.8).  This leads to only one solution i.e upgrading the machine.
BOSS GNU/Linux Logo

Now, The steps to dist-upgrade your BOSS GNU/Linux machine.
(Note: 
* First backup all your (important)data, configuration files before proceeding the upgrade your machine.
* Ensure you have active internet connection throughout the following process.
* The process data consuming, it needs about 2.0 GB of data transfer) 

Steps to do in current version with the current repository (in our case BOSS 5.0 anokha)
1.  update the machine
     $sudo apt-get update 
2.  upgrade the machine
     $sudo apt-get upgrade
3.  dist-upgrade the machine
     $sudo apt-get dist-upgrade
     The steps 2 & 3 must be finished successfully without any errors.  If you end-up with errors first fix it, without you can't proceed.  And importantly
check each time what are the packages going to be removed.  If you find anything important shown as going to be removed, be ensure twice with double cautions is it ok to you and then proceed.

Steps to do in current version with the target repository (in our case BOSS 6.0 anoop)
1.  Modify the "/etc/apt/sources.list" to point to the new version's repository.  For our case open & edit the file "/etc/apt/sources.list" file as follows.

$sudo gedit /etc/apt/sources.list

existing:
deb http://packages.bosslinux.in/boss anokha main contrib non-free
deb-src http://packages.bosslinux.in/boss anokha main contrib non-free


After modification:
deb http://packages.bosslinux.in/boss anoop main contrib non-free
deb-src http://packages.bosslinux.in/boss anoop main contrib non-free


save and exit.

2. update the machine
   $sudo apt-get update

3. Upgrade the machine
   $sudo apt-get upgrade

4.  Upgrade the machine
   $sudo apt-get dist-upgrade

  In the 3 & 4 th steps be in & around your machine, as the new versions of the packages installed it will prompt for configuration file changes.  For example let's take "postgresql" configuration file.  You may be modified it for your previous needs.  As the newer version going to be installed you will be prompted with options to keep older configuration file, replace with new etc., give your option accordingly (default & recommended is keeping your old configuration file).  Once you crossed all the said steps successfully, machine will prompt for "reboot", after which you could be landed into newer version of BOSS GNU/Linux.

How to check the upgraded version?
$hostnamectl
output will be something like

    Static hostname: boss
              Icon name: computer-desktop
                  Chassis: desktop
            Machine ID: 62c6fd7923f0953d60
                  Boot ID: 5449ccd6794947cc8309fdff20546b0b
Operating System: BOSS GNU/Linux 6 (anoop)
                   Kernel: Linux 3.2.0-4-686-pae

Kernel Upgrade:
From the above output we are sure that the machine is i686 arch so we have to install the newer kernel of same architecture.  So, we will find the newer/latest linux kernel available in our repository and install.  First let us check the available linux kernels using
$apt-cache search linux-image  - outputs something like follows
linux-image-3.16.0-4-586 - Linux 3.16 for older PCs
linux-image-3.16.0-4-686-pae - Linux 3.16 for modern PCs
linux-image-3.16.0-4-686-pae-dbg - Debugging symbols for Linux  \ 3.16.0-4-686-pae
linux-image-3.16.0-4-amd64 - Linux 3.16 for 64-bit PCs
linux-image-486 - Linux for older PCs (dummy package)
linux-image-586 - Linux for older PCs (meta-package)
linux-image-686-pae - Linux for modern PCs (meta-package)
linux-image-686-pae-dbg - Debugging symbols for Linux 686-pae configuration (meta-package)
linux-image-amd64 - Linux for 64-bit PCs (meta-package)
linux-image-3.2.0-4-686-pae - Linux 3.2 for modern PCs
linux-headers-3.2.0-4-686-pae - Header files for Linux 3.2.0-4-686-pae

The existing kernle is linux-3.2 and we have linux-3.16 in our repository for i686 architecture.  So, we could proceed with installation of new kernel
$sudo apt-get install linux-image-3.16.0-4-686-pae

Now, your machine will prompt you for rebooting.  Before rebooting you may consider purging removed packages(optional but recommended).


Purging removed packages:
Purge = (In Linux) Complete removal of a package including configuration files.  Many a time a package removed but its configuration files may stay with the machine.  To remove those unnecessary configuration files we purging.

$ dpkg -l | awk '/^rc/ { print $2 }'  - Lists all the removed packages
$sudo apt-get purge $(dpkg -l | awk '/^rc/ { print $2 }') - purge the removed packages.