copy gitweblite soruce code
|
1 |
use 5.008007; |
renamed gitpub to gitprep
|
2 |
package Gitprep; |
copy gitweblite soruce code
|
3 |
use Mojo::Base 'Mojolicious'; |
cleanup
|
4 | |
5 |
use Carp 'croak'; |
|
added start page
|
6 |
use DBIx::Custom; |
little more secure login
|
7 |
use Gitprep::API; |
cleanup
|
8 |
use Gitprep::Git; |
fixed tags page paging bug a...
|
9 |
use Gitprep::Manager; |
added RepManager rename feat...
|
10 |
use Scalar::Util 'weaken'; |
cleanup
|
11 |
use Validator::Custom; |
fix bug that forst . is not ...
|
12 |
use Mojolicious::Plugin::AutoRoute::Util 'template'; |
copy gitweblite soruce code
|
13 | |
fix bug that in CGI reposito...
|
14 | |
Digest::SHA loading to Mojo:...
|
15 |
# Digest::SHA loading to Mojo::Util if not loaded |
16 |
{ |
|
17 |
package Mojo::Util; |
|
18 |
eval {require Digest::SHA; import Digest::SHA qw(sha1 sha1_hex)}; |
|
19 |
} |
|
20 | ||
add Mojolicious::Plugin::DBV...
|
21 |
our $VERSION = 'v2.00_dev'; |
cleanup
|
22 | |
added start page
|
23 |
has 'dbi'; |
revert encoding support
|
24 |
has 'git'; |
added RepManager rename feat...
|
25 |
has 'manager'; |
rename validator to vc to up...
|
26 |
has 'vc'; |
revert encoding support
|
27 | |
28 |
use constant BUFFER_SIZE => 8192; |
|
add /info/refs request
|
29 | |
copy gitweblite soruce code
|
30 |
sub startup { |
31 |
my $self = shift; |
|
32 |
|
|
cleanup
|
33 |
# Config file |
update Mojolicious and added...
|
34 |
$self->plugin('INIConfig', {ext => 'conf'}); |
35 |
|
|
cleanup
|
36 |
# Config file for developper |
add need_login_always_option
|
37 |
unless ($ENV{GITPREP_NO_MYCONFIG}) { |
38 |
my $my_conf_file = $self->home->rel_file('gitprep.my.conf'); |
|
39 |
$self->plugin('INIConfig', {file => $my_conf_file}) if -f $my_conf_file; |
|
40 |
} |
|
update Mojolicious and added...
|
41 |
|
cleanup
|
42 |
# Listen |
copy gitweblite soruce code
|
43 |
my $conf = $self->config; |
cleanup
|
44 |
my $listen = $conf->{hypnotoad}{listen} ||= ['http://*:10020']; |
45 |
$listen = [split /,/, $listen] unless ref $listen eq 'ARRAY'; |
|
fixed listen bug
|
46 |
$conf->{hypnotoad}{listen} = $listen; |
copy gitweblite soruce code
|
47 |
|
revert encoding support
|
48 |
# Git |
renamed gitpub to gitprep
|
49 |
my $git = Gitprep::Git->new; |
cleanup
|
50 |
my $git_bin |
51 |
= $conf->{basic}{git_bin} ? $conf->{basic}{git_bin} : $git->search_bin; |
|
fix mini bug
|
52 |
if (!$git_bin || ! -e $git_bin) { |
53 |
$git_bin ||= ''; |
|
cleanup
|
54 |
my $error = "Can't detect or found git command ($git_bin)." |
55 |
. " set git_bin in gitprep.conf"; |
|
fixed git_bin not found bug
|
56 |
$self->log->error($error); |
57 |
croak $error; |
|
58 |
} |
|
improve code structures
|
59 |
$git->bin($git_bin); |
revert encoding support
|
60 |
|
Supported specific character...
|
61 |
# Encoding suspects list for Git |
62 |
my $encoding_suspects |
|
63 |
= $conf->{basic}{encoding_suspects} ||= 'utf8'; |
|
64 |
$encoding_suspects = [split /,/, $encoding_suspects] unless ref $encoding_suspects eq 'ARRAY'; |
|
65 |
$git->encoding_suspects($encoding_suspects); |
|
66 | ||
revert encoding support
|
67 |
# Repository Manager |
68 |
my $manager = Gitprep::Manager->new(app => $self); |
|
69 |
weaken $manager->{app}; |
|
70 |
$self->manager($manager); |
|
71 |
|
|
add key delete feature and u...
|
72 |
# authorized_keys file |
fix authorized_keys_file bug
|
73 |
my $authorized_keys_file = $conf->{basic}{authorized_keys_file}; |
add key delete feature and u...
|
74 |
unless (defined $authorized_keys_file) { |
75 |
if (defined $ENV{HOME}) { |
|
fix update_authorized_keys_f...
|
76 |
$authorized_keys_file = "$ENV{HOME}/.ssh/authorized_keys"; |
add key delete feature and u...
|
77 |
} |
78 |
} |
|
79 |
if (defined $authorized_keys_file) { |
|
80 |
$self->manager->authorized_keys_file($authorized_keys_file); |
|
81 |
} |
|
82 |
else { |
|
83 |
$self->app->log->warn(qq/Config "authorized_keys_file" can't be detected/); |
|
84 |
} |
|
85 |
|
|
fixed git_bin not found bug
|
86 |
# Repository home |
cleanup
|
87 |
my $rep_home = $ENV{GITPREP_REP_HOME} || $self->home->rel_file('data/rep'); |
revert encoding support
|
88 |
$git->rep_home($rep_home); |
added create repository feat...
|
89 |
unless (-d $rep_home) { |
90 |
mkdir $rep_home |
|
91 |
or croak "Can't create directory $rep_home: $!"; |
|
92 |
} |
|
cleanup
|
93 |
|
add time zone system
|
94 |
# Time Zone |
95 |
if (my $time_zone = $conf->{basic}{time_zone}) { |
|
96 |
|
|
97 |
if ($time_zone =~ /^([\+-])?([0-9]?[0-9]):([0-9][0-9])$/) { |
|
98 |
my $sign = $1 || ''; |
|
99 |
my $hour = $2; |
|
100 |
my $min = $3; |
|
101 |
|
|
102 |
my $time_zone_second = $sign . ($hour * 60 * 60) + ($min * 60); |
|
103 |
$git->time_zone_second($time_zone_second); |
|
104 |
} |
|
105 |
else { |
|
106 |
$self->log->warn("Bad time zone $time_zone. Time zone become GMT"); |
|
107 |
} |
|
108 |
} |
|
109 |
$self->git($git); |
|
cleanup
|
110 |
|
improved create repository f...
|
111 |
# DBI |
added test
|
112 |
my $db_file = $ENV{GITPREP_DB_FILE} |
113 |
|| $self->home->rel_file('data/gitprep.db'); |
|
improved create repository f...
|
114 |
my $dbi = DBIx::Custom->connect( |
115 |
dsn => "dbi:SQLite:database=$db_file", |
|
116 |
connector => 1, |
|
added original_pid column
|
117 |
option => {sqlite_unicode => 1, sqlite_use_immediate_transaction => 1} |
improved create repository f...
|
118 |
); |
119 |
$self->dbi($dbi); |
|
120 |
|
|
cleanup
|
121 |
# Database file permision |
fixed database file permissi...
|
122 |
if (my $user = $self->config->{hypnotoad}{user}) { |
123 |
my $uid = (getpwnam $user)[2]; |
|
124 |
chown $uid, -1, $db_file; |
|
125 |
} |
|
126 |
if (my $group = $self->config->{hypnotoad}{group}) { |
|
127 |
my $gid = (getgrnam $group)[2]; |
|
128 |
chown -1, $gid, $db_file; |
|
129 |
} |
|
130 |
|
|
added tab_index columns
|
131 |
# Setup database |
132 |
$self->manager->setup_database; |
|
improved create repository f...
|
133 |
|
134 |
# Model |
|
135 |
my $models = [ |
|
136 |
{table => 'user', primary_key => 'id'}, |
|
fix ssh key authentication b...
|
137 |
{table => 'ssh_public_key', primary_key => 'key'}, |
added original_pid column
|
138 |
{table => 'project', primary_key => ['user_id', 'name']}, |
add collaborator register lo...
|
139 |
{table => 'number', primary_key => 'key'}, |
140 |
{table => 'collaboration', primary_key => ['user_id', 'project_name', 'collaborator_id']} |
|
improved create repository f...
|
141 |
]; |
142 |
$dbi->create_model($_) for @$models; |
|
143 | ||
144 |
# Validator |
|
rename validator to vc to up...
|
145 |
my $vc = Validator::Custom->new; |
146 |
$self->vc($vc); |
|
147 |
$vc->register_constraint( |
|
added project delete feature
|
148 |
user_name => sub { |
149 |
my $value = shift; |
|
150 |
|
|
allow . as project name
|
151 |
return ($value || '') =~ /^[a-zA-Z0-9_\-]+$/; |
added project delete feature
|
152 |
}, |
153 |
project_name => sub { |
|
154 |
my $value = shift; |
|
allow . as project name
|
155 |
return 0 unless defined $value; |
156 |
return 0 if $value eq '.' || $value eq '..'; |
|
157 | ||
158 |
return ($value || '') =~ /[a-zA-Z0-9_\-\.]+$/; |
|
added project delete feature
|
159 |
} |
160 |
); |
|
improved create repository f...
|
161 |
|
cleanup setting validation
|
162 |
$vc->add_check(project_name => sub { |
163 |
my ($vc, $value) = @_; |
|
164 |
|
|
165 |
return 0 unless defined $value; |
|
166 |
return 0 if $value eq '.' || $value eq '..'; |
|
167 |
|
|
168 |
return ($value || '') =~ /[a-zA-Z0-9_\-\.]+$/; |
|
169 |
}); |
|
cleanup create user validati...
|
170 |
$vc->add_check(user_name => sub { |
171 |
my ($vc, $value) = @_; |
|
172 |
|
|
173 |
return ($value || '') =~ /^[a-zA-Z0-9_\-]+$/; |
|
174 |
}); |
|
cleanup setting validation
|
175 |
|
fixed receive pack bug and a...
|
176 |
# Basic auth plugin |
177 |
$self->plugin('BasicAuth'); |
|
added admin user tests
|
178 | |
added login page
|
179 |
{ |
cleanup
|
180 |
my $r = $self->routes; |
181 | ||
182 |
# DBViewer(only development) |
|
add Mojolicious::Plugin::DBV...
|
183 |
# /dbviewer |
cleanup
|
184 |
if ($self->mode eq 'development') { |
185 |
eval { |
|
186 |
$self->plugin( |
|
187 |
'DBViewer', |
|
188 |
dsn => "dbi:SQLite:database=$db_file" |
|
189 |
); |
|
190 |
}; |
|
added reset password feature
|
191 |
} |
added AutoRoute plugin
|
192 |
|
cleanup
|
193 |
# Auto route |
cleanup many pages
|
194 |
{ |
cleanup
|
195 |
my $r = $r->under(sub { |
196 |
my $self = shift; |
|
197 |
|
|
198 |
my $api = $self->gitprep_api; |
|
199 |
|
|
add need_login_always_option
|
200 |
# Authentication |
cleanup
|
201 |
{ |
202 |
my $path = $self->req->url->path->parts->[0] || ''; |
|
add need_login_always_option
|
203 |
|
204 |
# Admin |
|
cleanup
|
205 |
if ($path eq '_admin' && !$api->logined_admin) { |
206 |
$self->redirect_to('/'); |
|
207 |
return; |
|
208 |
} |
|
209 |
} |
|
210 |
|
|
211 |
return 1; |
|
212 |
}); |
|
add need_login_always_option
|
213 |
|
214 |
# Auto routes |
|
cleanup
|
215 |
$self->plugin('AutoRoute', route => $r); |
fix bug that forst . is not ...
|
216 |
|
add need_login_always_option
|
217 |
# Custom routes |
cleanup
|
218 |
{ |
add ssh key add feature
|
219 |
# Show ssh keys |
do success xt tests
|
220 |
$r->get('/(:user).keys' => template '/user-keys'); |
add ssh key add feature
|
221 |
|
add need_login_always_option
|
222 |
# User |
allow . as project name
|
223 |
my $r = $r->route('/:user'); |
add need_login_always_option
|
224 |
{ |
225 |
# Home |
|
fix bug that forst . is not ...
|
226 |
$r->get('/' => [format => 0] => template '/user'); |
add need_login_always_option
|
227 |
|
228 |
# Settings |
|
229 |
$r->get('/_settings' => template '/user-settings'); |
|
add ssh keys page design
|
230 |
|
231 |
# SSH keys |
|
add ssh key add feature
|
232 |
$r->any('/_settings/ssh' => template '/user-settings/ssh'); |
add need_login_always_option
|
233 |
} |
add /info/refs request
|
234 | |
235 |
# Smart HTTP |
|
236 |
{ |
|
allow . as project name
|
237 |
my $r = $r->route('/(#project).git'); |
add /info/refs request
|
238 |
|
fixed receive pack bug and a...
|
239 |
{ |
240 |
my $r = $r->under(sub { |
|
241 |
my $self = shift; |
|
242 |
|
|
cleanup
|
243 |
my $api = $self->gitprep_api; |
complete private repository ...
|
244 |
my $user = $self->param('user'); |
245 |
my $project = $self->param('project'); |
|
246 |
my $private = $self->app->manager->is_private_project($user, $project); |
|
cleanup
|
247 |
|
fixed receive pack bug and a...
|
248 |
# Basic auth when push request |
249 |
my $service = $self->param('service') || ''; |
|
complete private repository ...
|
250 |
if ($service eq 'git-receive-pack' || $private) { |
fixed receive pack bug and a...
|
251 |
|
252 |
$self->basic_auth("Git Area", sub { |
|
complete private repository ...
|
253 |
my ($auth_user, $auth_password) = @_; |
add warnings when authentica...
|
254 |
|
255 |
if (!defined $auth_user || !length $auth_user) { |
|
256 |
$self->app->log->warn("Authentication: User name is empty"); |
|
257 |
} |
|
258 |
|
|
fix warnings
|
259 |
$auth_user = '' unless defined $auth_user; |
260 |
$auth_password = '' unless defined $auth_password; |
|
fixed receive pack bug and a...
|
261 |
|
complete collaborator featur...
|
262 |
my $is_valid = |
263 |
($user eq $auth_user || $api->is_collaborator($user, $project, $auth_user)) |
|
264 |
&& $api->check_user_and_password($auth_user, $auth_password); |
|
fixed receive pack bug and a...
|
265 |
|
266 |
return $is_valid; |
|
267 |
}); |
|
268 |
} |
|
269 |
else { |
|
270 |
return 1; |
|
271 |
} |
|
272 |
}); |
|
273 |
|
|
redirect .git access to /use...
|
274 |
# / |
275 |
$r->get('/')->to(cb => sub { |
|
276 |
my $self = shift; |
|
277 |
|
|
278 |
my $user = $self->param('user'); |
|
279 |
my $project = $self->param('project'); |
|
280 |
|
|
281 |
$self->redirect_to("/$user/$project"); |
|
282 |
}); |
|
283 |
|
|
fixed receive pack bug and a...
|
284 |
# /info/refs |
285 |
$r->get('/info/refs' => template 'smart-http/info-refs'); |
|
286 |
|
|
287 |
# /git-upload-pack or /git-receive-pack |
|
288 |
$r->any('/git-(:service)' |
|
289 |
=> [service => qr/(?:upload-pack|receive-pack)/] |
|
290 |
=> template 'smart-http/service' |
|
291 |
); |
|
292 |
|
|
293 |
# Static file |
|
294 |
$r->get('/(*Path)' => template 'smart-http/static'); |
|
295 |
} |
|
add /info/refs request
|
296 |
} |
297 |
|
|
add need_login_always_option
|
298 |
# Project |
299 |
{ |
|
allow . as project name
|
300 |
my $r = $r->route('/#project'); |
add need_login_always_option
|
301 |
|
add private reporitory featu...
|
302 |
{ |
303 |
my $r = $r->under(sub { |
|
304 |
my $self = shift; |
|
305 |
|
|
cleanup
|
306 |
# API |
307 |
my $api = $self->gitprep_api; |
|
improve code structures
|
308 |
|
309 |
# Private |
|
revert encoding support
|
310 |
my $user = $self->param('user'); |
311 |
my $project = $self->param('project'); |
|
add private reporitory featu...
|
312 |
my $private = $self->app->manager->is_private_project($user, $project); |
313 |
if ($private) { |
|
complete collaborator featur...
|
314 |
if ($api->can_access_private_project($user, $project)) { |
add private reporitory featu...
|
315 |
return 1; |
316 |
} |
|
317 |
else { |
|
318 |
$self->render('private'); |
|
319 |
return 0; |
|
320 |
} |
|
321 |
} |
|
322 |
else { |
|
323 |
return 1; |
|
324 |
} |
|
325 |
}); |
|
326 |
|
|
327 |
# Home |
|
improve commits header desig...
|
328 |
$r->get('/' => template '/tree'); |
add private reporitory featu...
|
329 |
|
330 |
# Commit |
|
331 |
$r->get('/commit/*diff' => template '/commit'); |
|
add atom feed part
|
332 | |
add private reporitory featu...
|
333 |
# Commits |
334 |
$r->get('/commits/*rev_file' => template '/commits'); |
|
335 |
|
|
336 |
# Branches |
|
improve some branches page
|
337 |
$r->any('/branches/:display' => {display => undef} => template '/branches'); |
added feature that you see p...
|
338 | |
add private reporitory featu...
|
339 |
# Tags |
340 |
$r->get('/tags' => template '/tags'); |
|
improved network page
|
341 | |
add private reporitory featu...
|
342 |
# Tree |
343 |
$r->get('/tree/*rev_dir' => template '/tree'); |
|
344 |
|
|
345 |
# Blob |
|
346 |
$r->get('/blob/*rev_file' => template '/blob'); |
|
347 |
|
|
348 |
# Sub module |
|
349 |
$r->get('/submodule/*rev_file' => template '/submodule'); |
|
add blame method
|
350 | |
add private reporitory featu...
|
351 |
# Raw |
352 |
$r->get('/raw/*rev_file' => template '/raw'); |
|
add blame method
|
353 | |
add private reporitory featu...
|
354 |
# Blame |
355 |
$r->get('/blame/*rev_file' => template '/blame'); |
|
356 |
|
|
357 |
# Archive |
|
358 |
$r->get('/archive/(*rev).tar.gz' => template '/archive')->to(archive_type => 'tar'); |
|
359 |
$r->get('/archive/(*rev).zip' => template '/archive')->to(archive_type => 'zip' ); |
|
360 |
|
|
361 |
# Compare |
|
362 |
$r->get('/compare/(*rev1)...(*rev2)' => template '/compare'); |
|
363 |
|
|
364 |
# Settings |
|
improve tab design
|
365 |
{ |
366 |
my $r = $r->route('/settings')->to(tab => 'settings'); |
|
367 |
|
|
368 |
# Settings |
|
369 |
$r->any('/' => template '/settings'); |
|
370 |
|
|
371 |
# Collaboration |
|
372 |
$r->any('/collaboration' => template '/settings/collaboration'); |
|
373 |
} |
|
add collaboration page
|
374 |
|
add private reporitory featu...
|
375 |
# Fork |
376 |
$r->any('/fork' => template '/fork'); |
|
improve tab design
|
377 |
|
add private reporitory featu...
|
378 |
# Network |
improve tab design
|
379 |
{ |
380 |
my $r = $r->route('/network')->to(tab => 'graph'); |
|
381 |
|
|
382 |
# Network |
|
383 |
$r->get('/' => template '/network'); |
|
cleanup
|
384 | |
improve tab design
|
385 |
# Network Graph |
386 |
$r->get('/graph/(*rev1)...(*rev2_abs)' => template '/network/graph'); |
|
387 |
} |
|
add pull page design
|
388 | |
add private reporitory featu...
|
389 |
# Import branch |
390 |
$r->any('/import-branch/:remote_user/:remote_project' => template '/import-branch'); |
|
391 |
|
|
392 |
# Get branches and tags |
|
393 |
$r->get('/api/revs' => template '/api/revs'); |
|
394 |
} |
|
add need_login_always_option
|
395 |
} |
cleanup
|
396 |
} |
added AutoRoute plugin
|
397 |
} |
398 |
} |
|
added admin user tests
|
399 | |
400 |
# Helper |
|
401 |
{ |
|
402 |
# API |
|
403 |
$self->helper(gitprep_api => sub { Gitprep::API->new(shift) }); |
|
404 |
} |
|
added reverse proxy path_dep...
|
405 |
|
added AutoRoute plugin
|
406 |
# Reverse proxy support |
added reverse proxy path_dep...
|
407 |
my $reverse_proxy_on = $self->config->{reverse_proxy}{on}; |
408 |
my $path_depth = $self->config->{reverse_proxy}{path_depth}; |
|
409 |
if ($reverse_proxy_on) { |
|
410 |
$ENV{MOJO_REVERSE_PROXY} = 1; |
|
411 |
if ($path_depth) { |
|
412 |
$self->hook('before_dispatch' => sub { |
|
413 |
my $self = shift; |
|
414 |
for (1 .. $path_depth) { |
|
415 |
my $prefix = shift @{$self->req->url->path->parts}; |
|
416 |
push @{$self->req->url->base->path->parts}, $prefix; |
|
417 |
} |
|
418 |
}); |
|
added AutoRoute plugin
|
419 |
} |
added reverse proxy path_dep...
|
420 |
} |
cleanup
|
421 |
|
422 |
# Smart HTTP Buffer size |
|
fix bug that lerge repositor...
|
423 |
$ENV{GITPREP_SMART_HTTP_BUFFER_SIZE} ||= 16384; |
copy gitweblite soruce code
|
424 |
} |
425 | ||
426 |
1; |