Showing 3 changed files with 50 additions and 13 deletions
+5 -3
lib/Gitprep/Manager.pm
... ...
@@ -469,7 +469,9 @@ sub update_authorized_keys_file {
469 469
     # Create authorized_keys_file
470 470
     unless (-f $authorized_keys_file) {
471 471
       open my $fh, '>', $authorized_keys_file
472
-        or croak "Can't create $authorized_keys_file";
472
+        or croak "Can't create authorized_keys file: $authorized_keys_file";
473
+      chmod 0600, $authorized_keys_file
474
+        or croak "Can't chmod authorized_keys file: $authorized_keys_file";
473 475
     }
474 476
     
475 477
     # Parse file
... ...
@@ -500,7 +502,7 @@ sub update_authorized_keys_file {
500 502
     }
501 503
     
502 504
     # Output tmp file
503
-    my $output = "$before_part\n\n$start_symbol\n\n$ssh_public_keys_str$end_symbol\n\n$after_part";
505
+    my $output = "$before_part$start_symbol\n\n$ssh_public_keys_str$end_symbol$after_part";
504 506
     my $output_file = "$authorized_keys_file.gitprep.tmp";
505 507
     open my $out_fh, '>', $output_file
506 508
       or croak "Can't create authorized_keys tmp file $output_file";
... ...
@@ -555,7 +557,7 @@ sub _parse_authorized_keys_file {
555 557
         croak qq/$error_prefix "$end_symbol" is found more than one/;
556 558
       }
557 559
       else {
558
-        $end_symbol++;
560
+        $end_symbol_count++;
559 561
       }
560 562
     }
561 563
     elsif ($start_symbol_count == 0 && $end_symbol_count == 0) {
+5 -4
script/gitprep-shell
... ...
@@ -47,7 +47,8 @@ $ssh_original_command_tmp =~ s/[\n\r]+/<<newline>>/g;
47 47
 die "I don't like newlines in the command: $ssh_original_command\n"
48 48
   if $ssh_original_command ne $ssh_original_command_tmp;
49 49
 
50
-my ($verb, $project) = parse_ssh_original_command($ssh_original_command);
50
+my ($verb, $user_url, $project) = parse_ssh_original_command($ssh_original_command);
51
+die "User don't match" if $user ne $user_url;
51 52
 sanity($project);
52 53
 
53 54
 my $rep_home = $git->rep_home;
... ...
@@ -66,10 +67,10 @@ sub parse_ssh_original_command {
66 67
   $ssh_original_command ||= '';
67 68
 
68 69
   my $git_commands = "git-upload-pack|git-receive-pack|git-upload-archive";
69
-  if ($ssh_original_command =~ m(^($git_commands) '/?(.*?)(?:\.git)?'$)) {
70
-    my ($verb, $project) = ($1, $2);
70
+  if ($ssh_original_command =~ m(^($git_commands) '/([a-zA-Z_]+)/?(.*?)(?:\.git)?'$)) {
71
+    my ($verb, $user, $project) = ($1, $2, $3);
71 72
     die "invalid repo name: '$project'" if $project !~ $project_re;
72
-    return ($verb, $project);
73
+    return ($verb, $user, $project);
73 74
   }
74 75
   else {
75 76
     die "Invalid command: $ssh_original_command";
+40 -6
templates/project.html.ep
... ...
@@ -51,8 +51,11 @@
51 51
   my $ssh_port = config->{basic}{ssh_port};
52 52
   my $rep_home = app->git->rep_home;
53 53
   my $execute_user = getpwuid($>);
54
-  my $ssh_rep_url = "ssh://$execute_user\@" . $url->host
54
+  my $ssh_rep_url_deprected = "ssh://$execute_user\@" . $url->host
55 55
     . ($ssh_port ? ":$ssh_port" : '') . "$rep_home/$user/$project.git";
56
+  my $ssh_rep_url = "ssh://$execute_user\@" . $url->host
57
+    . ($ssh_port ? ":$ssh_port" : '') . "/$user/$project.git";
58
+
56 59
 %>
57 60
 
58 61
 % layout 'common', title => "$user/$project";
... ...
@@ -66,8 +69,9 @@
66 69
       % my $ssh_port = config->{basic}{ssh_port} || '';
67 70
       
68 71
       var logined = <%= $logined ? 'true' : 'false' %>;
69
-      var ssh_rep_url = '';
72
+      var ssh_rep_url_deprecated = '';
70 73
       if (logined) {
74
+        ssh_rep_url_deprecated = '<%= $ssh_rep_url_deprected %>';
71 75
         ssh_rep_url = '<%= $ssh_rep_url %>';
72 76
       }
73 77
       
... ...
@@ -76,12 +80,18 @@
76 80
         $('#rep_url').val(http_rep_url);
77 81
         $('#access').text('Read-write');
78 82
       });
79
-      
83
+
80 84
       // Click SSH button
81 85
       $('#btn_ssh').on('click', function () {
82 86
         $('#rep_url').val(ssh_rep_url);
83 87
         $('#access').text('Read-write');
84 88
       });
89
+            
90
+      // Click SSH(old) button
91
+      $('#btn_ssh_deprecated').on('click', function () {
92
+        $('#rep_url').val(ssh_rep_url_deprecated);
93
+        $('#access').text('Read-write');
94
+      });
85 95
 
86 96
       // Initialize
87 97
       $('#btn_http').trigger('click');
... ...
@@ -119,6 +129,7 @@
119 129
             <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>
120 130
             % if ($logined) {
121 131
               <button class="btn" id="btn_ssh" style="padding:3px 7px;border-radius:0">SSH</button>
132
+              <button class="btn" id="btn_ssh_deprecated" style="padding:3px 7px;border-radius:0">SSH(old)</button>
122 133
             % }
123 134
           </div>
124 135
           <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">
... ...
@@ -158,7 +169,7 @@ touch README
158 169
 git init
159 170
 git add README
160 171
 git commit -m "first commit"
161
-git remote add origin <%= $ssh_rep_url %>
172
+git remote add origin <%= $ssh_rep_url_deprected %>
162 173
 git push -u origin master</pre>
163 174
       
164 175
       <div class="text-center" style="margin-bottom:10px">
... ...
@@ -166,12 +177,35 @@ git push -u origin master</pre>
166 177
       </div>
167 178
       
168 179
       <pre style="margin-bottom:30px">
169
-git remote add origin <%= $ssh_rep_url %>
180
+git remote add origin <%= $ssh_rep_url_deprected %>
170 181
 git push -u origin master</pre>
171 182
 
172 183
       <hr>
173
-      % my $http_rep_url = url_for("$user/$project.git")->to_abs;
174 184
 
185
+      <h4>SSH(deprecated)</h4>
186
+      
187
+      <div class="text-center" style="margin-bottom:10px">
188
+        <b>Create a new repository on the command line via ssh</b>
189
+      </div>
190
+      
191
+      <pre style="margin-bottom:30px">
192
+touch README
193
+git init
194
+git add README
195
+git commit -m "first commit"
196
+git remote add origin <%= $ssh_rep_url_deprected %>
197
+git push -u origin master</pre>
198
+      
199
+      <div class="text-center" style="margin-bottom:10px">
200
+        <b>Push an existing repository from the command line via ssh</b>
201
+      </div>
202
+      
203
+      <pre style="margin-bottom:30px">
204
+git remote add origin <%= $ssh_rep_url_deprected %>
205
+git push -u origin master</pre>
206
+
207
+      <hr>
208
+      % my $http_rep_url = url_for("$user/$project.git")->to_abs;
175 209
       <h4><%= uc url_for->to_abs->scheme %></h4>
176 210
 
177 211
       <div class="text-center" style="margin-bottom:10px">