2016-07-11

Customizing Firefox Search Engines

Being very annoyed by not having a POST search engine by default, I dug a bit into FF's search engine configurations. Some online articles/posts were somehow not working for FF 47, noting how I got this done here, for future reference.

Ref 1 2 3

Why

You can surely easily add search engines in FF addons markets, but unfortunately the POST version of my favorite search engine is somehow not working for me. If you are unlike me and happy with what you have, don't bother continuing.

How

  1. First, quit FF.
  2. Then check in the FF profile folder, there should be one or more files named starting with search. In my case, there were search.json.mozlz4, search.json, search-meta.json.
  3. Delete all of them, so that FF could recheck all available search plugins in searchplugins folder.
  4. Create searchplugins if you don't have one.
  5. Create an XML file with a sensible name, and create the search engine specs in this file with OpenSearch format.
  6. If an existing plugin is available for reference that's great. Otherwise, try using a tool to build from scratch, e.g. with mycroft project tool.
  7. Make sure the XML file is valid. Start up FF.
  8. Go to about:preferences#search, and the new search plugin should be visible in the list.


Update 20190131


Updated prior ref pointed to this comment, which does not require touching anything in FF folder. What worked for me was:
  1. Go to about:config
  2. Open JS console
  3. Run Services.search.addEngine("file:///path/to/your/opensearch.xml", null, null, false);
Startpage's OpenSearch XML could serve as a template, and a prior ref could serve as a reference for how to add POST parameters. XML that I used was:

<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/" xmlns:os="http://a9.com/-/spec/opensearch/1.1/">
<os:ShortName>Startpage</os:ShortName>
<os:Description>Startpage Search</os:Description>
<os:InputEncoding>UTF-8</os:InputEncoding>
<os:Image width="16" height="16" type="image/x-icon">https://www.startpage.com/assets/images/logo-16x16.png</os:Image>
<os:Url type="text/html" method="POST" template="https://www.startpage.com/do/dsearch">
  <Param name="query" value="{searchTerms}"/>
  <Param name="prfe" value="36c84513558a2d34bf0d89ea505333adb92ef6e4f6ab17dad119096d3b428afa984abfd0db70840b"/>
</os:Url>
<SearchForm>http://startpage.com/</SearchForm>
</SearchPlugin>

2016-06-13

Misc settings with Tomcat

Force HTTPS connections

In conf/web.xml:
<security-constraint>
    <web-resource-collection>
        <web-resource-name>SSL Content</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

Disable JSESSIONID/CSRF URL rewrite

In conf/web.xml:
<session-config>
   <tracking-mode>COOKIE</tracking-mode>
</session-config>

Tomcat with Let's Encrypt cert on Ubuntu 16.04

Ref

Goal

To get Let's Encrypt's cert work with Tomcat container.

How

Install and get a LE cert

sudo apt install letsencrypt
sudo letsencrypt certonly
It should ask for email, the domain this machine is at.

Converting LE's certs to PKCS12 format

Get root, cd into letsencrypt's cert folder indicated by last command, and run:
openssl pkcs12 -export -in cert.pem -inkey privkey.pem -out sslcert.p12 -name tomcat -CAfile chain.pem -caname root
Move the p12 cert to a place tomcat can see.

Configure Tomcat to use the cert

Edit conf/server.xml, enable the 443 connector.
Add the attributes in this connector:

keystoreFile="sslcert.p12" keystoreType="PKCS12" keystorePass="[change_to_your_password]"
Restart Tomcat, and the https should be working.

Tomcat 8, authbind on port 80/443, systemd with Ubuntu 16.04

Ref 1
Ref 2
Ref 3

Goal

I'd like to be able to use the upstream/downloaded Tomcat, running as a standalone, serving 80/443 ports, and starting automatically with system boot.
Below is based on vanilla Ubuntu 16.04 image from Google Compute Engine.

How

Install Java

sudo apt install default-jdk-headless

Add tomcat user and group

With --system so that this user could not sign in system.
sudo addgroup --system tomcat
sudo adduser --system --ingroup tomcat tomcat

Unpack Tomcat installation

Download apache-tomcat-8.0.35.tar.gz. Then:
tar xf apache-tomcat-8.0.35.tar.gz
sudo mv apache-tomcat-8.0.35 /home/tomcat/
sudo chown tomcat:tomcat -R /home/tomcat/apache-tomcat-8.0.35

Install and configure authbind

sudo apt install authbind
sudo touch /etc/authbind/byport/{443,80}
sudo chmod 500 /etc/authbind/byport/{443,80}
sudo chown tomcat:tomcat /etc/authbind/byport/{443,80}

Configure Tomcat

sudo sed -i 's/8080/80/g' /home/tomcat/apache-tomcat-8.0.35/conf/server.xml
sudo sed -i 's/8443/443/g' /home/tomcat/apache-tomcat-8.0.35/conf/server.xml

Configure authbind

sudo vim /etc/systemd/system/tomcat.service
Then paste in the content:

[Unit]
Description=Tomcat Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre
Environment=CATALINA_PID=/home/tomcat/tmp/tomcat.pid
Environment=CATALINA_HOME=/home/tomcat/apache-tomcat-8.0.35
Environment=CATALINA_BASE=/home/tomcat/apache-tomcat-8.0.35

ExecStart=/home/tomcat/apache-tomcat-8.0.35/bin/startup.sh
ExecStop=/home/tomcat/apache-tomcat-8.0.35/bin/shutdown.sh

User=tomcat
Group=tomcat
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target
After saving:
sudo systemctl daemon-reload
sudo systemctl enable tomcat.service
sudo systemctl restart tomcat.service