commit 68883bd92e7804cae8b5c9e1343b956ef80f35e5
Author: spesk1 <spesk@pm.me>
Date: Mon Jun 10 17:31:14 2019 -0400
WIP: Adding port knocking features for git servers that use port knocking
diff --git a/example.config b/example.config
index da9d15f..f5ac5c7 100644
--- a/example.config
+++ b/example.config
@@ -2,3 +2,7 @@
UserWarn = "true"
user.name = "spesk1"
user.email = "spesk@pm.me"
+
+# Use if your git server requires port knocking
+Knock = "true"
+ports = [ "1111", "2222" ]
diff --git a/lib/SimplyGit/Git.pm b/lib/SimplyGit/Git.pm
index 7212b49..3033f3a 100644
--- a/lib/SimplyGit/Git.pm
+++ b/lib/SimplyGit/Git.pm
@@ -39,6 +39,9 @@ sub warnOnUser($$$) {
}
+# https://perlmaven.com/trim
+sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
+
sub parseSGConfig($$) {
my $config = shift;
@@ -55,12 +58,20 @@ sub parseSGConfig($$) {
if ( $line =~ m/^(.*)\ =\ "(.*)"$/ ) {
$configHash{$1} = $2;
}
- }
- if ( defined $configHash{'UserWarn'} ) {
- warnOnUser($configHash{'user.name'},$configHash{'user.email'},$logger);
+ if ( $line =~ m/^(.*)\ =\ \[(.*)\]/ ) {
+ my @trimmedPorts;
+ my @ports = split(",",$2);
+ foreach my $port (@ports) {
+ $port =~ /(\d{1,5})/;
+ push(@trimmedPorts,trim($1));
+ }
+ $configHash{$1} = \@trimmedPorts;
+ }
}
+ return %configHash;
+
}
sub returnConfigPath($$) {
diff --git a/lib/SimplyGit/Shellex.pm b/lib/SimplyGit/Shellex.pm
index 0f35969..fc80700 100644
--- a/lib/SimplyGit/Shellex.pm
+++ b/lib/SimplyGit/Shellex.pm
@@ -3,7 +3,16 @@ use strict;
use warnings;
use Log::Log4perl qw(:easy);
use Exporter qw(import);
-our @EXPORT_OK = qw(shellex findBin);
+our @EXPORT_OK = qw(shellex findBin knocker);
+
+sub knocker($$) {
+
+ my $portRef = shift;
+ my $logger = shift;
+ foreach my $port (@$portRef) {
+ print "Would knock on $portRef";
+ }
+}
sub shellex {
diff --git a/sg b/sg
index e80bf00..a4f075d 100755
--- a/sg
+++ b/sg
@@ -204,7 +204,16 @@ sub parseArgs {
}
parseArgs();
-parseSGConfig($args{'config-file'},$logger);
+my %sgConfig = parseSGConfig($args{'config-file'},$logger);
+if ( defined $sgConfig{'UserWarn'} ) {
+ warnOnUser($sgConfig{'user.name'},$sgConfig{'user.email'},$logger);
+}
+if ( defined $sgConfig{'Knock'} ) {
+ foreach my $port ( @{$sgConfig{'ports'}} ) {
+ print "Would knock $port\n";
+ }
+}
+
# TODO: This sub could be more concise with a sub to print array refs
if ( defined $args{'view'} ) {