[Tails-dev] ***SPAM*** Re: Proposed changes to tails-starter…

Delete this message

Reply to this message
Autor: Cryptkiddy
Data:  
A: tails-dev
Assumptes vells: Re: [Tails-dev] Proposed changes to tails-starter-i2p && my first contribution to OSS
Assumpte: [Tails-dev] ***SPAM*** Re: Proposed changes to tails-starter-i2p &&my first contribution to OSS
Hi,

the git-diff with the new patch is attached. I think I managed to fix
everything you told me to. I am still not sure about the errorhandling part
(Do you think it is OK to inline that the way I did?) .



If there is anything else I can do to make it better just let me know.

Cheers,
    Cryptkiddy

diff --git a/config/chroot_local-includes/usr/local/bin/tails-start-i2p b/config/chroot_local-includes/usr/local/bin/tails-start-i2p
index 716d05d..9ec2c61 100755
--- a/config/chroot_local-includes/usr/local/bin/tails-start-i2p
+++ b/config/chroot_local-includes/usr/local/bin/tails-start-i2p
@@ -25,6 +25,7 @@ See https://tails.boum.org/.
use Desktop::Notify;
use Locale::gettext;
use POSIX;
+use feature "state";

### initialization
setlocale(LC_MESSAGES, "");
@@ -32,11 +33,56 @@ textdomain("tails-i2p-notify-user");

### helper subs

-# TODO: get router port (default 7657) from /etc/i2p/clients.config
 sub get_router_port {
-    return 7657;
+    # gets router port from /etc/i2p/clients.config . If this fails we return I2P default port (7657).
+    my $i2p_default_port = 7657;
+    state $router_port = 0;
+
+
+    if($router_port) {
+    # If we found the Port before there should be no need to recheck it.
+        return $router_port;
+    }
+
+
+    my $conffile;
+    if(! open($conffile, "<", "/etc/i2p/clients.config")) {
+        warn "Can not open i2p config file '/etc/i2p/client.config'.".
+        " Using default port ".$i2p_default_port." for I2P webinterface instead.";
+        $router_port = $i2p_default_port;
+        return $router_port;
+    }
+    my $client_config = join("", <$conffile>);
+    close($conffile);
+
+    my $client_app_no;
+    my $regex = '\nclientApp\.([0-9]+)\.main=net\.i2p\.router\.web\.RouterConsoleRunner\n';
+    #we are trying to get $NUMBER$ from >>clientApp.$NUMBER$.main=net.i2p.router.web.RouterConsoleRunner<<
+    if(! (($client_app_no) = ($client_config =~ m/$regex/))) {
+        warn "RegEx checking 'clientApp.[0-9].main=net.i2p.router.web.RouterConsoleRunner' didn't match.".
+        "Can not find port in '/etc/i2p/client.config'." .
+        " Using default port ".$i2p_default_port." for I2P webinterface instead.";
+        $router_port = $i2p_default_port;
+        return $router_port;
+    }
+
+    $regex = '\nclientApp\.' . $client_app_no . '\.args=([0-9]{1,5})\ [0-9s:,. \-]+ \.\/webapps\/[\s]*\n';
+    #      'clientApp.$NUMBER$.args=$PORT$ ::1,127.0.0.1 ./webapps/'
+    #                               $PORT$ ::1 ./webapps/
+    #                               $PORT$ ::1,127.0.0.1 -s 7667 ::1,127.0.0.1 ./webapps/
+    #here $NUMBER$ is the one we obtained above and $PORT$ is what we want to get
+    #doesn't match if only https port is given.
+    if (! (($router_port) = ($client_config =~ m/$regex/))) {
+        warn "RegEx checking 'clientApp.".$client_app_no.".args= [...]' didn't match.".
+        "Can not find port in '/etc/i2p/client.config'." .
+        " Using default port ".$i2p_default_port." for I2P webinterface instead.";
+        $router_port = $i2p_default_port;
+        return $router_port;
+    }
+    return $router_port;
 }


+
# TODO: more perlish way to do below?
# TODO: use netstat -p, check that a child of i2psvc runs the router console
sub router_status {