Philip continues to play devil’s advocate / script kiddie for my telnet URL handler. My input checker allowed host/port definitions to begin with a hyphen character. That’s an invalid domain name, so I ignored the possibility that someone might try it. Philip used it to pass a switch to the telnet/ssh command.
Here is attempt number 3, now with more complicated regular expressions:
#!/usr/bin/perl
# parse URL
($protocol,$host) = split /:\/\//, $ARGV[0];
($host,$port) = split /:/, $host;
# validate input
if ( $protocol !~ /^(telnet|ssh)$/ ||
$host !~ /^[a-zA-Z0-9][a-zA-Z0-9.-]*$/ ||
$port !~ /(^[a-zA-Z0-9][a-zA-Z0-9_-]*$|^$)/ ) {
warn "Invalid URL";
exit 1;
}
# if SSH, add -p argument
if ( $protocol eq "ssh" && $port != '' ) { $port = "-p $port" ; }
# call terminal emulator
exec("konsole --hold -e $protocol $host $port");
exit;
Your move, sir.
You can download an updated url-terminal script here. You can read the post that started this here.
Leave a Reply