Score:0

Custom protocol handler for Firefox can't start gnome-terminal

ne flag

I want to open ssh:// links from Firefox with script that opens gnome-terminal and initiates SSH connection. Script works as intended when run manually but not if run from Firefox.

I use script found here: https://gist.github.com/jnaskali/104cc00d8e9dfc63cac1d9534ebc00a2 Here's my version:

#!/bin/bash
# Script that opens ssh:// links from Firefox - CC0 by Juhani, www.naskali.fi
{

# extract the protocol
proto="$(echo $1 | grep -oP '^[a-z]*')" # first letters
# extract the user (if any)
user="$(echo $1 | grep -oP '(?<=:\/\/)(.*)(?=@)')" # text in between :// and @
# extract the host
host="$(echo $1 | grep -oP '(?<=:\/\/|@)([a-z0-9\.]+)(?!.*@)')" # alphanumerals preceded by :// or @, not followed by text@
# extract the port
port="$(echo $1 | grep -oP '(?<=:)\d*')" # numbers after :

command="$proto "
if [ -n "$port" ]
then
    command="${command}-p $port "
fi
if [ -n "$user" ]
then
    command="${command}${user}@"
fi
command="${command}$host"

echo $PATH

gnome-terminal -- bash -c "$command"

} > sshtest 2>&1

# You also need the boolean 'network.protocol-handler.expose.ssh':false in Firefox's about:config

The script works as intended when run from terminal:

user@machine:~$ ./firefox_ssh_handler.sh ssh://admin@*.*.*.*

opens a new window and initiates SSH connection.

The problem: If I use the script as protocol handler in Firefox to open ssh:// link, the script runs, but does not open gnome-terminal. I get error gnome-terminal: command not found on stderr.

I suppose this might be some security measure to prevent custom protocol handlers from opening terminal windows?

I'm running Ubuntu 22.04.1 LTS and Firefox 108.0.2

Some more information to rule out possible causes:

  1. gnome-terminal is installed in /usr/bin, which is in $PATH, even if run from Firefox. If I use /usr/bin/gnome-terminal in script, I get /usr/bin/gnome-terminal: No such file or directory on stderr.

  2. Firefox runs under the user that owns the script file. File permissions are -rwxrwxr-x.

  1. network.protocol-handler.expose.ssh is set to "false".
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.