fix bug that dispaly blog im...
|
1 |
#!/usr/bin/env perl |
2 | ||
3 |
use strict; |
|
4 |
use warnings; |
|
5 |
use utf8; |
|
6 |
use FindBin; |
|
7 |
use lib "$FindBin::Bin/../lib"; |
|
8 |
use lib "$FindBin::Bin/../extlib/lib/perl5"; |
|
9 |
use Gitprep; |
|
10 | ||
Complete gitprep-shell
|
11 |
my $debug = 0; |
12 | ||
write gitprep-shell
|
13 |
# Project name pattern |
14 |
my $project_re = qr/[a-zA-Z0-9_\-\.]+$/; |
|
fix bug that dispaly blog im...
|
15 | |
write gitprep-shell
|
16 |
# User |
fix gitprep-shell
|
17 |
my $session_user_id = shift; |
18 |
die "User not specifed" unless defined $session_user_id; |
|
fix bug that dispaly blog im...
|
19 | |
write gitprep-shell
|
20 |
# Application |
cleanup ->rep_home
|
21 |
my $app = Mojo::Server->new->load_app("$FindBin::Bin/gitprep"); |
write gitprep-shell
|
22 | |
23 |
# Git |
|
24 |
my $git = $app->git; |
|
25 | ||
26 |
# DBI |
|
fix bug that dispaly blog im...
|
27 |
my $dbi = $app->dbi; |
28 | ||
write gitprep-shell
|
29 |
# SSH connection |
30 |
my $ssh_connection = $ENV{SSH_CONNECTION}; |
|
Complete gitprep-shell
|
31 |
warn "ssh_connection: $ssh_connection" if $debug; |
add collaboration feature to...
|
32 |
die "who the *heck* are you?\n" unless defined $ssh_connection; |
write gitprep-shell
|
33 | |
34 |
# SSH original command |
|
35 |
my $ssh_original_command = $ENV{SSH_ORIGINAL_COMMAND} || ''; |
|
fix ssh key authentication b...
|
36 |
warn "ssh_original_command: $ssh_original_command" if $debug; |
write gitprep-shell
|
37 | |
38 |
# IP address |
|
39 |
my $ip = $ssh_connection || '(no-IP)'; |
|
fix ssh key authentication b...
|
40 |
warn "ip: $ip" if $debug; |
write gitprep-shell
|
41 |
$ip =~ s/ .*//; |
42 | ||
43 |
# Check new line of SSH original command |
|
44 |
my $ssh_original_command_tmp = $ssh_original_command; |
|
45 |
$ssh_original_command_tmp =~ s/[\n\r]+/<<newline>>/g; |
|
46 |
die "I don't like newlines in the command: $ssh_original_command\n" |
|
47 |
if $ssh_original_command ne $ssh_original_command_tmp; |
|
48 | ||
add collaboration feature to...
|
49 |
# Project |
fix gitprep-shell
|
50 |
my ($verb, $user_id, $project_id) = parse_ssh_original_command($ssh_original_command); |
51 |
sanity($project_id); |
|
write gitprep-shell
|
52 | |
add collaboration feature to...
|
53 |
# Can access |
54 |
my $can_access; |
|
fix gitprep-shell
|
55 |
if ($session_user_id eq $user_id) { |
add collaboration feature to...
|
56 |
$can_access = 1; |
57 |
} |
|
58 |
else { |
|
change is_collaborator argum...
|
59 |
$can_access = $app->gitprep_api->is_collaborator($session_user_id, $user_id, $project_id); |
add collaboration feature to...
|
60 |
} |
fix gitprep-shell
|
61 |
die qq|User "$session_user_id" can't access repository "$user_id/$project_id.git"\n| |
add collaboration feature to...
|
62 |
unless $can_access; |
63 | ||
64 |
# Command |
|
fix gitprep-shell
|
65 |
my $rep_info = $app->rep_info($user_id, $project_id); |
remove rep_path
|
66 |
my $rep_git_dir = $rep_info->{git_dir}; |
67 |
my $repository = "'$rep_git_dir'"; |
|
write gitprep-shell
|
68 |
my @git_shell_cmd = ("git", "shell", "-c", "$verb $repository"); |
Complete gitprep-shell
|
69 |
warn "@git_shell_cmd" if $debug; |
70 |
unless ($debug) { |
|
71 |
system(@git_shell_cmd) == 0 |
|
add collaboration feature to...
|
72 |
or die "Can't execute command: @git_shell_cmd\n" ; |
Complete gitprep-shell
|
73 |
} |
write gitprep-shell
|
74 | |
75 |
sub parse_ssh_original_command { |
|
76 |
my $ssh_original_command = shift; |
|
77 | ||
Complete gitprep-shell
|
78 |
$ssh_original_command ||= ''; |
write gitprep-shell
|
79 | |
80 |
my $git_commands = "git-upload-pack|git-receive-pack|git-upload-archive"; |
|
Fix regex to allow usernames...
|
81 |
if ($ssh_original_command =~ m(^($git_commands) '.*/([a-zA-Z0-9_]+)/([^\/]+?)\.git'$)) { |
fix gitprep-shell
|
82 |
my ($verb, $user_id, $project_id) = ($1, $2, $3); |
83 |
warn "User:$user_id, Project:$project_id" if $debug; |
|
84 |
die "invalid repo name: '$project_id'\n" if $project_id !~ $project_re; |
|
85 |
return ($verb, $user_id, $project_id); |
|
write gitprep-shell
|
86 |
} |
87 |
else { |
|
add collaboration feature to...
|
88 |
die "Invalid command: $ssh_original_command\n"; |
write gitprep-shell
|
89 |
} |
90 |
} |
|
91 | ||
92 |
sub sanity { |
|
fix gitprep-shell
|
93 |
my $project_id = shift; |
94 |
die "'$project_id' contains bad characters\n" if $project_id !~ $project_re; |
|
95 |
die "'$project_id' ends with a '/'\n" if $project_id =~ m(/$); |
|
96 |
die "'$project_id' contains '..'\n" if $project_id =~ m(\.\.); |
|
write gitprep-shell
|
97 |
} |
fix bug that dispaly blog im...
|
98 | |
99 |
=head1 NAME |
|
100 | ||
write gitprep-shell
|
101 |
gitprep-shell - AuthorizedKeysCommand for sshd |
fix bug that dispaly blog im...
|
102 | |
103 |
=head1 USAGE |
|
104 | ||
add gitprep-shell wrappter s...
|
105 |
./gitprep-shell-raw kimoto |
fix bug that dispaly blog im...
|
106 | |
107 |
This command return user public_key |
|
108 |