projects
/
bak-git.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
make bak grep same as git grep, bak log-grep to filter logs
[bak-git.git]
/
bak-git-server.pl
diff --git
a/bak-git-server.pl
b/bak-git-server.pl
index
d3a69d9
..
3bd5f63
100755
(executable)
--- a/
bak-git-server.pl
+++ b/
bak-git-server.pl
@@
-27,6
+27,8
@@
bak command, overview:
bak diff [host:][/path]
bak status [/path]
bak log [/path]
bak diff [host:][/path]
bak status [/path]
bak log [/path]
+ bak log-grep pattern
+ bak grep pattern
bak show
bak ch[anges]
bak show
bak ch[anges]
@@
-34,6
+36,7
@@
bak command, overview:
bak cat [host:]/path
bak grep pattern
bak cat [host:]/path
bak grep pattern
+ bak find filename-pattern
bak - push all changed files to server
bak - push all changed files to server
@@
-75,8
+78,10
@@
while(<$ssh_fd>) {
$host = $1;
} elsif ( /^\s+(\S+)\s+(.+)/ ) {
$ssh_tunnel->{$host}++ if lc($1) eq 'remoteforward' && $2 =~ m/9001/;
$host = $1;
} elsif ( /^\s+(\S+)\s+(.+)/ ) {
$ssh_tunnel->{$host}++ if lc($1) eq 'remoteforward' && $2 =~ m/9001/;
+ } elsif ( /^\s+$/ ) {
+ # nop
} else {
} else {
-
die "can't parse $_
";
+
warn "can't parse [$_]
";
}
}
}
}
@@
-97,7
+102,7
@@
warn "# ssh_client $hostname $server";
sub _kill_ssh {
while ( my($host,$pid) = each %$ssh_tunnel ) {
warn "$host kill TERM $pid";
sub _kill_ssh {
while ( my($host,$pid) = each %$ssh_tunnel ) {
warn "$host kill TERM $pid";
-
kill 15, $pid;
# TERM
+
eval { kill 15, $pid; }
# TERM
}
}
}
}
@@
-177,7
+182,14
@@
sub mkbasedir {
while (my $client = $server->accept()) {
my $line = <$client>;
chomp($line);
while (my $client = $server->accept()) {
my $line = <$client>;
chomp($line);
- warn "<<< $line\n";
+
+ my $peerhost = $client->peerhost;
+ if ( $peerhost !~ m/^(10\.13\.37\.|10\.60\.0\.|10\.200\.100\.)/ ) {
+ print $client "$peerhost not allowed\n";
+ next;
+ }
+
+ warn "<<< $peerhost $line\n";
my ($user,$hostname,$pwd,$command,$rel_path,$message) = split(/\s+/,$line,6);
$hostname =~ s/\..+$//;
my ($user,$hostname,$pwd,$command,$rel_path,$message) = split(/\s+/,$line,6);
$hostname =~ s/\..+$//;
@@
-270,11
+282,16
@@
while (my $client = $server->accept()) {
print $client "ERROR: $file_path: $!\n";
}
} elsif ( $command eq 'ls' ) {
print $client "ERROR: $file_path: $!\n";
}
} elsif ( $command eq 'ls' ) {
- print $client `ls $backup_path`;
+ my $file_path = ( $on_host ? $on_host : $hostname ) . "/$path";
+ print $client `ls $file_path 2>&1`;
} elsif ( $command eq 'show' ) {
print $client `git show $rel_path`;
} elsif ( $command eq 'show' ) {
print $client `git show $rel_path`;
+ } elsif ( $command eq 'log-grep' ) {
+ #print $client `git log -g --grep=$rel_path`;
} elsif ( $command eq 'grep' ) {
} elsif ( $command eq 'grep' ) {
- print $client `git log -g --grep=$rel_path`;
+ print $client `git grep $rel_path`;
+ } elsif ( $command eq 'find' ) {
+ print $client `find . -iname '*$rel_path*' | sed -e 's,^./,,' -e 's,/,:/,'`
} elsif ( $command eq 'link' ) {
if ( $on_host ) {
mkbasedir "$on_host/$path";
} elsif ( $command eq 'link' ) {
if ( $on_host ) {
mkbasedir "$on_host/$path";