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