[Tails-dev] Proposed changes to tails-starter-i2p && my firs…

Delete this message

Reply to this message
Autor: Cryptkiddy
Data:  
Para: The Tails public development discussion list
Assunto: [Tails-dev] Proposed changes to tails-starter-i2p && my first contribution to OSS
Hi,

I would like to contribute a fix in "./config/chroot_local-
includes/usr/local/bin/tails-start-i2p".
Now it should be possible to get the actual i2pWebInterface port instead of
always using the default one (7657).

I was however wondering what to use to output nonfatal error messages. I used
warn" ";
in this case but am not sure whether that is alright?


As this is my first contribution to OSS I'd greatly appreciate any feedback.

Git-diff is attached.


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..3c372a4 100755
--- a/config/chroot_local-includes/usr/local/bin/tails-start-i2p
+++ b/config/chroot_local-includes/usr/local/bin/tails-start-i2p
@@ -32,9 +32,63 @@ 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 (default 7657) from /etc/i2p/clients.config
+  
+  {
+      if(! open(CONFFILE, "/etc/i2p/clients.config")) 
+      {
+    warn "Can not open i2p config file."; 
+    last; #goto Errorhandling
+      }
+      my @client_config = <CONFFILE>;
+      close(CONFFILE);
+      chomp(@client_config);
+
+
+      my $ClientAppNo = -1;
+      my $string;
+      foreach $string (@client_config)
+      {
+    if($string =~ m/^clientApp\.([0-9]+)\.main=net\.i2p\.router\.web\.RouterConsoleRunner$/)
+        #we are trying to get $NUMBER$ from >>clientApp.$NUMBER$.main=net.i2p.router.web.RouterConsoleRunner<<
+    {
+        $ClientAppNo = $1;
+        last;
+    }   
+      }
+      if($ClientAppNo == -1)
+      {
+    warn "Check wheather i2p config includes"
+          ." 'clientApp.[0-9].main=net.i2p.router.web.RouterConsoleRunner' .";
+    last; #goto Errorhandling
+      }
+
+
+      my $regex = '^clientApp\.' . $ClientAppNo . '\.args=([0-9]{1,5})\ [0-9s\:\,\.\-\ ]+\/webapps\/';
+    #      '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.
+      foreach $string (@client_config)
+      {
+      if ($string =~ m/$regex/)
+      {
+        my $routerPort = $1;
+        return $routerPort;
+      }
+      }
+      warn "RegEx checking 'clientApp.".$ClientAppNo.".args=[...]' didn't match.";
+      last; #goto Errorhandling
+  }
+#Errorhandling:
+  ###Errorhandling - Under normal conditions we should already have returned###
+  warn "Can not find port in '/etc/i2p/client.config'." .
+       " Using default port 7657 for I2P webinterface instead.";
+  return 7657; #Default port; when we are here something went wrong.
+
 }


# TODO: more perlish way to do below?