Skip to content

Commit

Permalink
fix ssh key authentication bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gitprep committed May 20, 2014
1 parent d47bea3 commit 73ae380
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 48 deletions.
2 changes: 1 addition & 1 deletion lib/Gitprep.pm
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ sub startup {
# Model
my $models = [
{table => 'user', primary_key => 'id'},
{table => 'ssh_public_key', primary_key => ['user_id', 'key']},
{table => 'ssh_public_key', primary_key => 'key'},
{table => 'project', primary_key => ['user_id', 'name']},
{table => 'number', primary_key => 'key'},
{table => 'collaboration', primary_key => ['user_id', 'project_name', 'collaborator_id']}
Expand Down
9 changes: 4 additions & 5 deletions lib/Gitprep/Manager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -333,17 +333,16 @@ EOS
my $sql = <<"EOS";
create table ssh_public_key (
row_id integer primary key autoincrement,
user_id not null default '',
key not null default '',
unique(user_id, key)
key not null unique default ''
);
EOS
$dbi->execute($sql);
};

# Create ssh_public_key columns
my $ssh_public_key_columns = [
"title not null default ''",
"user_id not null default ''",
"title not null default ''"
];
for my $column (@$ssh_public_key_columns) {
eval { $dbi->execute("alter table ssh_public_key add column $column") };
Expand Down Expand Up @@ -555,7 +554,7 @@ sub _parse_authorized_keys_file {
}
}
elsif ($line =~ /^$end_symbol/) {
if ($end_symbol > 0) {
if ($end_symbol_count > 0) {
croak qq/$error_prefix "$end_symbol" is found more than one/;
}
else {
Expand Down
7 changes: 4 additions & 3 deletions script/gitprep-shell
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ die "who the *heck* are you?" unless defined $ssh_connection;

# SSH original command
my $ssh_original_command = $ENV{SSH_ORIGINAL_COMMAND} || '';
warn "ssh_original_command: $ssh_original_command";
warn "ssh_original_command: $ssh_original_command" if $debug;

# IP address
my $ip = $ssh_connection || '(no-IP)';
warn "ip: $ip";
warn "ip: $ip" if $debug;
$ip =~ s/ .*//;

# Check new line of SSH original command
Expand Down Expand Up @@ -67,8 +67,9 @@ sub parse_ssh_original_command {
$ssh_original_command ||= '';

my $git_commands = "git-upload-pack|git-receive-pack|git-upload-archive";
if ($ssh_original_command =~ m(^($git_commands) '/([a-zA-Z_]+)/?(.*?)(?:\.git)?'$)) {
if ($ssh_original_command =~ m(^($git_commands) '.*/([a-zA-Z_]+)/([^\/]+?)\.git'$)) {
my ($verb, $user, $project) = ($1, $2, $3);
warn "User:$user, Project:$project" if $debug;
die "invalid repo name: '$project'" if $project !~ $project_re;
return ($verb, $user, $project);
}
Expand Down
43 changes: 5 additions & 38 deletions templates/project.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@
my $ssh_port = config->{basic}{ssh_port};
my $rep_home = app->git->rep_home;
my $execute_user = getpwuid($>);
my $ssh_rep_url_deprected = "ssh://$execute_user\@" . $url->host
. ($ssh_port ? ":$ssh_port" : '') . "$rep_home/$user/$project.git";
my $ssh_rep_url = "ssh://$execute_user\@" . $url->host
. ($ssh_port ? ":$ssh_port" : '') . "/$user/$project.git";
. ($ssh_port ? ":$ssh_port" : '') . "$rep_home/$user/$project.git";

%>

Expand All @@ -69,9 +67,8 @@
% my $ssh_port = config->{basic}{ssh_port} || '';

var logined = <%= $logined ? 'true' : 'false' %>;
var ssh_rep_url_deprecated = '';
var ssh_rep_url = '';
if (logined) {
ssh_rep_url_deprecated = '<%= $ssh_rep_url_deprected %>';
ssh_rep_url = '<%= $ssh_rep_url %>';
}

Expand All @@ -81,17 +78,11 @@
$('#access').text('Read-write');
});

// Click SSH button
// Click SSH(old) button
$('#btn_ssh').on('click', function () {
$('#rep_url').val(ssh_rep_url);
$('#access').text('Read-write');
});

// Click SSH(old) button
$('#btn_ssh_deprecated').on('click', function () {
$('#rep_url').val(ssh_rep_url_deprecated);
$('#access').text('Read-write');
});

// Initialize
$('#btn_http').trigger('click');
Expand Down Expand Up @@ -129,7 +120,6 @@
<button class="btn" id="btn_http" style="margin-left:5px;padding:3px 6px;border-top-right-radius:0px; border-bottom-right-radius:0px"><%= $self->req->is_secure ? 'HTTPS' : 'HTTP' %></button>
% if ($logined) {
<button class="btn" id="btn_ssh" style="padding:3px 7px;border-radius:0">SSH</button>
<button class="btn" id="btn_ssh_deprecated" style="padding:3px 7px;border-radius:0">SSH(old)</button>
% }
</div>
<input id="rep_url" type="text" style="width:635px;border-radius:0;padding:3px 7px;border-top-right-radius:3px;border-bottom-right-radius:3px">
Expand Down Expand Up @@ -169,42 +159,19 @@ touch README
git init
git add README
git commit -m "first commit"
git remote add origin <%= $ssh_rep_url_deprected %>
git remote add origin <%= $ssh_rep_url %>
git push -u origin master</pre>

<div class="text-center" style="margin-bottom:10px">
<b>Push an existing repository from the command line via ssh</b>
</div>

<pre style="margin-bottom:30px">
git remote add origin <%= $ssh_rep_url_deprected %>
git remote add origin <%= $ssh_rep_url %>
git push -u origin master</pre>

<hr>

<h4>SSH(deprecated)</h4>

<div class="text-center" style="margin-bottom:10px">
<b>Create a new repository on the command line via ssh</b>
</div>

<pre style="margin-bottom:30px">
touch README
git init
git add README
git commit -m "first commit"
git remote add origin <%= $ssh_rep_url_deprected %>
git push -u origin master</pre>

<div class="text-center" style="margin-bottom:10px">
<b>Push an existing repository from the command line via ssh</b>
</div>

<pre style="margin-bottom:30px">
git remote add origin <%= $ssh_rep_url_deprected %>
git push -u origin master</pre>

<hr>
% my $http_rep_url = url_for("$user/$project.git")->to_abs;
<h4><%= uc url_for->to_abs->scheme %></h4>

Expand Down
2 changes: 1 addition & 1 deletion templates/user-settings/ssh.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
if ($vc->constraints->{ascii}->($original_key_edit)) {
my $key = "$type $original_key_edit";

my $row = app->dbi->model('ssh_public_key')->select(id => [$user, $key])->one;
my $row = app->dbi->model('ssh_public_key')->select(id => $key)->one;

if ($row) {
return {result => 0, message => 'Key already exists'};
Expand Down

0 comments on commit 73ae380

Please sign in to comment.