Category: tagged

  • Vim: paste indent problems

    On one of my boxes I came across this weird behaviour when pasting code into Vim at the terminal. All indentation was broken in a stepped way. Every line indented more and more creating a real mess to work with. This only happened when actually pasting content into the terminal. Typing worked as normal.

    I initially thought that it had something to do with Putty‘s way of interacting with this specific box e.g. some configuration that was missing. Issues exist with carriage return (CR) and line feed (LF) handling across platforms. Nevertheless this was a dead end.

    Digging around Vim’s extensive wiki provided some clues as to what was going on. Having ‘autoindent‘ or ‘smartindent‘ on creates havoc when pasting into Vim and therefore should be disabled. The problem is that these are nice features to have on when simply typing.

    Vim has an alternative mode called ‘paste‘ that does not modify the pasted input in any way and therefore code looks just as in the original source. To enable ‘paste‘ mode during insert simply type ‘:set paste‘ and you are ready to paste. When finished pasting you probably want to leave ‘paste‘ mode by typing ‘:set nopaste‘.

    As I am too lazy to type this every time I need to paste something I have now added the ‘pastetoggle‘ key into my profile’s .vimrc file as follows: ‘set pastetoggle=<F12>

    From now on simply hit F12 on the keyboard and you will be in ‘paste‘ mode. Press F12 again to leave it.

  • Wget, HTTPS & ignoring robots.txt

    Wget has many usages as you probably are aware of. One of them being an easy method of mirroring parts of or even entire sites.

    Lately I am working on a project which required an exact copy including all dependent media files to be mirrored from another site. Working server side it is much easier to simply retrieve the files via Wget directly to the server instead of downloading them to the local machine and from there upload them to the server in question. Wget simply saves me from doing all this extra work.

    The Man page of Wget is extensive and includes all kind of options to quickly get around the most quirky tasks.

    Specifically with this task I experienced trouble. I did not get all files requested and different combinations of options and parameters did not accomplish what I was after. Several failed attempts made me even consider copying the files over one by one manually…!

    As the pages in question were served as HTTPS I started suspecting Wget having issues with secure connections. After enabling the debug switch (‘-d‘) as suggested I realised that Wget was actually encountering a robots.txt file that excluded all the directories and files I was trying to retrieve. Wget follows the Robot Exclusion Standard but it can easily be circumvented by using the ‘-e‘ switch:

    wget -e robots=off url
    

    If you wish to turn off the robot exclusion permanently, set the robots variable to ‘off‘ in your profile’s ‘.wgetrc‘ file.

  • Apache: DocumentRoot does not exist. Why SELinux?

    Once more SELinux has been playing up with the normal operations of a box. During the installation and set up of an Apache instance and a few virtual hosts I simply could not get around the dreaded error message:

    Starting httpd: Warning: DocumentRoot [/home/www/myhost] does not exist
    

    No matter which permissions and owners were given to the directories or files related the error still came up hindering the Apache httpd service to start. Obviously the path was correct, copied and pasted, to exclude any spelling issues.

    After experiencing similar conundrums in the past I had a slight suspicion regarding SELinux, which comes enabled by default on Fedora, may have been blocking access to the directory somehow.

    A bit of searching did confirm that SELinux indeed also intervened at this level blocking Apache’s normal operations. I fully understand and agree with the goal of SELinux, but it is simply too big a compromise between security and usability. As Theodore Tso pretty much summarises it:

    SELINUX is so horrible to use, that after wasting a large amount of time enabling it and then watching all of my applications die a horrible death since they didn’t have the appropriate hand-crafted security policy, caused me to swear off of it. For me, given my threat model and how much my time is worth, life is too short for SELinux.

    SELinux stays disabled again…