config: make the /w/ prefix optional for gitweb URLs
[girocco.git] / Girocco / Project.pm
blob6d732b89661c3efaae8b63da6b6c019595cfe792
1 package Girocco::Project;
3 use strict;
4 use warnings;
6 BEGIN {
7 use Girocco::CGI;
8 use Girocco::User;
9 use Girocco::Util;
10 use Girocco::HashUtil;
11 use Girocco::ProjPerm;
12 use Girocco::Config;
13 use base ('Girocco::ProjPerm::'.$Girocco::Config::permission_control); # mwahaha
16 BEGIN {
17 eval {
18 require Digest::SHA;
19 Digest::SHA->import(
20 qw(sha1_hex)
21 );1} ||
22 eval {
23 require Digest::SHA1;
24 Digest::SHA1->import(
25 qw(sha1_hex)
26 );1} ||
27 eval {
28 require Digest::SHA::PurePerl;
29 Digest::SHA::PurePerl->import(
30 qw(sha1_hex)
31 );1} ||
32 die "One of Digest::SHA or Digest::SHA1 or Digest::SHA::PurePerl "
33 . "must be available\n";
36 our $metadata_fields = {
37 homepage => ['Homepage URL', 'hp', 'text'],
38 shortdesc => ['Short description', 'desc', 'text'],
39 README => ['README (HTML, lt 8kb)', 'README', 'textarea'],
40 notifymail => ['Commit notify - mail to', 'notifymail', 'text'],
41 notifyjson => ['Commit notify - <a href="http://help.github.com/post-receive-hooks/">POST JSON</a> at', 'notifyjson', 'text'],
42 notifycia => ['Commit notify - <a href="http://cia.vc/doc/">CIA project</a> name', 'notifycia', 'text'],
45 sub _mkdir_forkees {
46 my $self = shift;
47 my @pelems = split('/', $self->{name});
48 pop @pelems; # do not create dir for the project itself
49 my $path = $self->{base_path};
50 foreach my $pelem (@pelems) {
51 $path .= "/$pelem";
52 (-d "$path") or mkdir $path or die "mkdir $path: $!";
53 chmod 02775, $path; # ok if fails (dir may already exist and be owned by someone else)
57 our %propmap = (
58 url => ':baseurl',
59 email => ':owner',
60 desc => 'description',
61 README => 'README.html',
62 hp => ':homepage',
63 notifymail => '%hooks.mailinglist',
64 notifytag => '%hooks.announcelist',
65 notifyjson => '%hooks.jsonurl',
66 notifycia => '%hooks.cianame',
69 our %propmapro = (
70 lastchange => ':lastchange',
71 lastactivity => 'info/lastactivity',
74 sub _update_index {
75 system($Girocco::Config::basedir . '/gitweb/genindex.sh');
78 sub _property_path {
79 my $self = shift;
80 my ($name) = @_;
81 $self->{path}.'/'.$name;
84 sub _property_fget {
85 my $self = shift;
86 my ($name) = @_;
87 my $pname = $propmap{$name};
88 $pname = $propmapro{$name} unless $pname;
89 $pname or die "unknown property: $name";
90 if ($pname =~ s/^://) {
91 my $val = `"$Girocco::Config::git_bin" --git-dir="$self->{path}" config "gitweb.$pname"`;
92 chomp $val;
93 return $val;
94 } elsif ($pname =~ s/^%//) {
95 my $val = `"$Girocco::Config::git_bin" --git-dir="$self->{path}" config "$pname"`;
96 chomp $val;
97 return $val;
100 open P, '<', $self->_property_path($pname) or return undef;
101 my @value = <P>;
102 close P;
103 my $value = join('', @value); chomp $value;
104 $value;
107 sub _property_fput {
108 my $self = shift;
109 my ($name, $value) = @_;
110 my $pname = $propmap{$name};
111 $pname or die "unknown property: $name";
112 $value ||= '';
113 if ($pname =~ s/^://) {
114 system($Girocco::Config::git_bin, '--git-dir='.$self->{path}, 'config', "gitweb.$pname", $value);
115 return;
116 } elsif ($pname =~ s/^%//) {
117 system($Girocco::Config::git_bin, '--git-dir='.$self->{path}, 'config', $pname, $value);
118 return;
121 my $P = lock_file($self->_property_path($pname));
122 $value ne '' and print $P "$value\n";
123 close $P;
124 unlock_file($self->_property_path($pname));
127 sub _properties_load {
128 my $self = shift;
129 foreach my $prop (keys %propmap) {
130 $self->{$prop} = $self->_property_fget($prop);
132 foreach my $prop (keys %propmapro) {
133 $self->{$prop} = $self->_property_fget($prop);
135 my $val = `"$Girocco::Config::git_bin" --git-dir="$self->{path}" config --bool "gitweb.statusupdates" 2>/dev/null`;
136 chomp $val;
137 $val = ($val eq 'false') ? 0 : 1;
138 $self->{statusupdates} = $val;
139 delete $self->{auth};
140 $val = `"$Girocco::Config::git_bin" --git-dir="$self->{path}" config "gitweb.delauth"`;
141 chomp $val;
142 if ($val =~ /^# DELAUTH ([0-9a-f]+) (\d+)/) {
143 my $expire = $2;
144 $self->{auth} = $1 unless (time >= $expire);
148 sub _properties_save {
149 my $self = shift;
150 foreach my $prop (keys %propmap) {
151 $self->_property_fput($prop, $self->{$prop});
153 $self->{statusupdates} = 1
154 unless defined($self->{statusupdates}) && $self->{statusupdates} =~ /^\d+$/;
155 system($Girocco::Config::git_bin, '--git-dir='.$self->{path}, 'config', '--bool',
156 "gitweb.statusupdates", $self->{statusupdates});
159 sub _nofetch_path {
160 my $self = shift;
161 $self->_property_path('.nofetch');
164 sub _nofetch {
165 my $self = shift;
166 my ($nofetch) = @_;
167 my $nf = $self->_nofetch_path;
168 if ($nofetch) {
169 open X, '>', $nf or die "nofetch failed: $!";
170 close X;
171 } else {
172 unlink $nf or die "yesfetch failed: $!";
176 sub _clonelog_path {
177 my $self = shift;
178 $self->_property_path('.clonelog');
181 sub _clonefail_path {
182 my $self = shift;
183 $self->_property_path('.clone_failed');
186 sub _clonep_path {
187 my $self = shift;
188 $self->_property_path('.clone_in_progress');
191 sub _clonep {
192 my $self = shift;
193 my ($nofetch) = @_;
194 my $np = $self->_clonep_path;
195 if ($nofetch) {
196 open X, '>', $np or die "clonep failed: $!";
197 close X;
198 } else {
199 unlink $np or die "clonef failed: $!";
202 sub _alternates_setup {
203 my $self = shift;
204 return unless $self->{name} =~ m#/#;
205 my $forkee_name = get_forkee_name($self->{name});
206 my $forkee_path = get_forkee_path($self->{name});
207 return unless -d $forkee_path;
208 mkdir $self->{path}.'/refs'; chmod 02775, $self->{path}.'/refs';
209 mkdir $self->{path}.'/objects'; chmod 02775, $self->{path}.'/objects';
210 mkdir $self->{path}.'/objects/info'; chmod 02775, $self->{path}.'/objects/info';
212 # We set up both alternates and http_alternates since we cannot use
213 # relative path in alternates - that doesn't work recursively.
215 my $filename = $self->{path}.'/objects/info/alternates';
216 open X, '>', $filename or die "alternates failed: $!";
217 print X "$forkee_path/objects\n";
218 close X;
219 chmod 0664, $filename or warn "cannot chmod $filename: $!";
221 if ($Girocco::Config::httppullurl) {
222 $filename = $self->{path}.'/objects/info/http-alternates';
223 open X, '>', $filename or die "http-alternates failed: $!";
224 my $upfork = $forkee_name;
225 do { print X "$Girocco::Config::httppullurl/$upfork.git/objects\n"; } while ($upfork =~ s#/?.+?$## and $upfork); #
226 close X;
227 chmod 0664, $filename or warn "cannot chmod $filename: $!";
230 # The symlink is problematic since git remote prune will traverse it.
231 #symlink "$forkee_path/refs", $self->{path}.'/refs/forkee';
233 # copy refs from parent project
234 # ownership information is changed by a root cronjob
235 system("cp -pR $forkee_path/refs $self->{path}/");
236 # initialize HEAD, hacky version
237 system("cp $forkee_path/HEAD $self->{path}/HEAD");
240 sub _ctags_setup {
241 my $self = shift;
242 my $perms = $Girocco::Config::permission_control eq 'Hooks' ? 02777 : 02775;
243 mkdir $self->{path}.'/ctags'; chmod $perms, $self->{path}.'/ctags';
246 sub _group_add {
247 my $self = shift;
248 my ($xtra) = @_;
249 $xtra .= join(',', @{$self->{users}});
250 filedb_atomic_append(jailed_file('/etc/group'),
251 join(':', $self->{name}, $self->{crypt}, '\i', $xtra));
254 sub _group_update {
255 my $self = shift;
256 my $xtra = join(',', @{$self->{users}});
257 filedb_atomic_edit(jailed_file('/etc/group'),
258 sub {
259 $_ = $_[0];
260 chomp;
261 if ($self->{name} eq (split /:/)[0]) {
262 # preserve readonly flag
263 s/::([^:]*)$/:$1/ and $xtra = ":$xtra";
264 return join(':', $self->{name}, $self->{crypt}, $self->{gid}, $xtra)."\n";
265 } else {
266 return "$_\n";
272 sub _group_remove {
273 my $self = shift;
274 filedb_atomic_edit(jailed_file('/etc/group'),
275 sub {
276 $self->{name} ne (split /:/)[0] and return $_;
281 sub _hook_path {
282 my $self = shift;
283 my ($name) = @_;
284 $self->{path}.'/hooks/'.$name;
287 sub _hook_install {
288 my $self = shift;
289 my ($name) = @_;
290 open SRC, '<', "$Girocco::Config::basedir/hooks/$name" or die "cannot open hook $name: $!";
291 open DST, '>', $self->_hook_path($name) or die "cannot open hook $name for writing: $!";
292 while (<SRC>) { print DST $_; }
293 close DST;
294 close SRC;
295 chmod 0775, $self->_hook_path($name) or die "cannot chmod hook $name: $!";
298 sub _hooks_install {
299 my $self = shift;
300 foreach my $hook ('post-receive', 'update', 'post-update') {
301 $self->_hook_install($hook);
305 # private constructor, do not use
306 sub _new {
307 my $class = shift;
308 my ($name, $base_path, $path) = @_;
309 does_exist($name,1) || valid_name($name) or die "refusing to create project with invalid name ($name)!";
310 $path ||= "$base_path/$name.git";
311 my $proj = { name => $name, base_path => $base_path, path => $path };
313 bless $proj, $class;
316 # public constructor #0
317 # creates a virtual project not connected to disk image
318 # you can conjure() it later to disk
319 sub ghost {
320 my $class = shift;
321 my ($name, $mirror) = @_;
322 my $self = $class->_new($name, $Girocco::Config::reporoot);
323 $self->{users} = [];
324 $self->{mirror} = $mirror;
325 $self->{email} = $self->{orig_email} = '';
326 $self;
329 # public constructor #1
330 sub load {
331 my $class = shift;
332 my $name = shift || '';
334 open F, '<', jailed_file("/etc/group") or die "project load failed: $!";
335 while (<F>) {
336 chomp;
337 @_ = split /:+/;
338 next unless (shift eq $name);
340 my $self = $class->_new($name, $Girocco::Config::reporoot);
341 (-d $self->{path}) or die "invalid path (".$self->{path}.") for project ".$self->{name};
343 my $ulist;
344 ($self->{crypt}, $self->{gid}, $ulist) = @_;
345 $ulist ||= '';
346 $self->{users} = [split /,/, $ulist];
347 $self->{HEAD} = $self->get_HEAD;
348 $self->{orig_HEAD} = $self->{HEAD};
349 $self->{orig_users} = [@{$self->{users}}];
350 $self->{mirror} = ! -e $self->_nofetch_path;
351 $self->{clone_in_progress} = -e $self->_clonep_path;
352 $self->{clone_logged} = -e $self->_clonelog_path;
353 $self->{clone_failed} = -e $self->_clonefail_path;
354 $self->{ccrypt} = $self->{crypt};
356 $self->_properties_load;
357 $self->{orig_email} = $self->{email};
358 return $self;
360 close F;
361 undef;
364 # $proj may not be in sane state if this returns false!
365 sub cgi_fill {
366 my $self = shift;
367 my ($gcgi) = @_;
368 my $cgi = $gcgi->cgi;
370 my ($pwd, $pwd2) = ($cgi->param('pwd'), $cgi->param('pwd2'));
371 $pwd ||= ''; $pwd2 ||= ''; # in case passwords are disabled
372 if ($pwd or not $self->{crypt}) {
373 $self->{crypt} = scrypt_sha1($pwd);
376 if ($pwd2 and $pwd ne $pwd2) {
377 $gcgi->err("Our high-paid security consultants have determined that the admin passwords you have entered do not match each other.");
380 $self->{cpwd} = $cgi->param('cpwd');
382 if ($Girocco::Config::project_owners eq 'email') {
383 $self->{email} = $gcgi->wparam('email');
384 valid_email($self->{email})
385 or $gcgi->err("Your email sure looks weird...?");
388 $self->{url} = $gcgi->wparam('url');
389 if ($self->{url}) {
390 valid_repo_url($self->{url})
391 or $gcgi->err("Invalid URL. Note that only HTTP and Git protocol is supported. If the URL contains funny characters, contact me.");
394 $self->{desc} = $gcgi->wparam('desc');
395 length($self->{desc}) <= 1024
396 or $gcgi->err("<b>Short</b> description length &gt; 1kb!");
398 $self->{README} = $gcgi->wparam('README');
399 length($self->{README}) <= 8192
400 or $gcgi->err("README length &gt; 8kb!");
402 $self->{hp} = $gcgi->wparam('hp');
403 if ($self->{hp}) {
404 valid_web_url($self->{hp})
405 or $gcgi->err("Invalid homepage URL. Note that only HTTP protocol is supported. If the URL contains funny characters, contact me.");
408 $self->{users} = [grep { Girocco::User::valid_name($_) && Girocco::User::does_exist($_) } $cgi->param('user')];
410 $self->{HEAD} = $cgi->param('HEAD') if $cgi->param('HEAD');
412 # schedule deletion of tags (will be committed by update() after auth)
413 $self->{tags_to_delete} = [$cgi->param('tags')];
415 $self->{notifymail} = $gcgi->wparam('notifymail');
416 if ($self->{notifymail}) {
417 (valid_email_multi($self->{notifymail}) and length($self->{notifymail}) <= 512)
418 or $gcgi->err("Invalid notify e-mail address. Use mail,mail to specify multiple addresses; total length must not exceed 512 characters, however.");
421 $self->{notifyjson} = $gcgi->wparam('notifyjson');
422 if ($self->{notifyjson}) {
423 valid_web_url($self->{notifyjson})
424 or $gcgi->err("Invalid JSON notify URL. Note that only HTTP protocol is supported. If the URL contains funny characters, contact me.");
427 $self->{notifycia} = $gcgi->wparam('notifycia');
428 if ($self->{notifycia}) {
429 $self->{notifycia} =~ /^[a-zA-Z0-9._-]+$/
430 or $gcgi->err("Overly suspicious CIA notify project name. If it is actually valid, contact me.");
433 if ($cgi->param('setstatusupdates')) {
434 my $val = $gcgi->wparam('statusupdates') || '0';
435 $self->{statusupdates} = $val ? 1 : 0;
438 not $gcgi->err_check;
441 sub form_defaults {
442 my $self = shift;
444 name => $self->{name},
445 email => $self->{email},
446 url => $self->{url},
447 desc => html_esc($self->{desc}),
448 README => html_esc($self->{README}),
449 hp => $self->{hp},
450 users => $self->{users},
451 notifymail => html_esc($self->{notifymail}),
452 notifyjson => html_esc($self->{notifyjson}),
453 notifycia => html_esc($self->{notifycia}),
457 # return true if $enc_passwd is a match for $plain_passwd
458 my $_check_passwd_match = sub {
459 my $enc_passwd = shift || '';
460 my $plain_passwd = shift || '';
461 # $enc_passwd may be crypt or crypt_sha1
462 if ($enc_passwd =~ m(^\$sha1\$(\d+)\$([./0-9A-Za-z]{1,64})\$[./0-9A-Za-z]{28}$)) {
463 # It's using sha1-crypt
464 return $enc_passwd eq crypt_sha1($plain_passwd, $2, -(0+$1));
465 } else {
466 # It's using crypt
467 return $enc_passwd eq crypt($plain_passwd, $enc_passwd);
471 sub authenticate {
472 my $self = shift;
473 my ($gcgi) = @_;
475 $self->{ccrypt} or die "Can't authenticate against a project with no password";
476 $self->{cpwd} ||= '';
477 unless ($_check_passwd_match->($self->{ccrypt}, $self->{cpwd})) {
478 $gcgi->err("Your admin password does not match!");
479 return 0;
481 return 1;
484 sub _setup {
485 my $self = shift;
486 my ($pushers) = @_;
488 $self->_mkdir_forkees;
490 mkdir($self->{path}) or die "mkdir $self->{path} failed: $!";
491 if ($Girocco::Config::owning_group) {
492 my $gid = scalar(getgrnam($Girocco::Config::owning_group));
493 chown(-1, $gid, $self->{path}) or die "chgrp $gid $self->{path} failed: $!";
494 chmod(02775, $self->{path}) or die "chmod 02775 $self->{path} failed: $!";
495 } else {
496 chmod(02777, $self->{path}) or die "chmod 02777 $self->{path} failed: $!";
498 system($Girocco::Config::git_bin, '--git-dir='.$self->{path}, 'init', '--bare', '--shared='.$self->shared_mode()) == 0
499 or die "git init $self->{path} failed: $?";
500 system($Girocco::Config::git_bin, '--git-dir='.$self->{path}, 'config', 'receive.denyNonFastforwards', 'false') == 0
501 or die "disabling receive.denyNonFastforwards failed: $?";
502 system($Girocco::Config::git_bin, '--git-dir='.$self->{path}, 'config', 'gc.auto', '0') == 0
503 or die "disabling gc.auto failed: $?";
505 # /info must have right permissions,
506 # and git init didn't do it for some reason.
507 if ($Girocco::Config::owning_group) {
508 chmod(02775, $self->{path}."/info") or die "chmod 02775 $self->{path}/info failed: $!";
509 } else {
510 chmod(02777, $self->{path}."/info") or die "chmod 02777 $self->{path}/info failed: $!";
513 $self->_properties_save;
514 $self->_alternates_setup;
515 $self->_ctags_setup;
516 $self->_group_remove;
517 $self->_group_add($pushers);
518 $self->_hooks_install;
519 #$self->perm_initialize;
520 $self->_update_index;
523 sub premirror {
524 my $self = shift;
526 $self->_setup(':');
527 $self->_clonep(1);
528 $self->perm_initialize;
531 sub conjure {
532 my $self = shift;
534 $self->_setup;
535 $self->_nofetch(1);
536 if ($Girocco::Config::mob && $Girocco::Config::mob eq "mob") {
537 system("$Girocco::Config::basedir/bin/create-personal-mob-area", $self->{name}) == 0
538 or die "create-personal-mob-area $self->{name} failed";
540 $self->perm_initialize;
543 sub clone {
544 my $self = shift;
546 unlink ($self->_clonefail_path()); # Ignore EEXIST error
547 unlink ($self->_clonelog_path()); # Ignore EEXIST error
549 use IO::Socket;
550 my $sock = IO::Socket::UNIX->new($Girocco::Config::chroot.'/etc/taskd.socket') or die "cannot connect to taskd.socket: $!";
551 $sock->print("clone ".$self->{name}."\n");
552 # Just ignore reply, we are going to succeed anyway and the I/O
553 # would apparently get quite hairy.
554 $sock->flush();
555 sleep 2; # *cough*
556 $sock->close();
559 sub update {
560 my $self = shift;
562 $self->_properties_save;
563 $self->_group_update;
565 if (exists($self->{tags_to_delete})) {
566 $self->delete_ctag($_) foreach(@{$self->{tags_to_delete}});
569 $self->set_HEAD($self->{HEAD}) unless $self->{orig_HEAD} eq $self->{HEAD};
571 my @users_add = grep { $a = $_; not scalar grep { $a eq $_ } $self->{orig_users} } $self->{users};
572 my @users_del = grep { $a = $_; not scalar grep { $a eq $_ } $self->{users} } $self->{orig_users};
573 $self->perm_user_add($_, Girocco::User::resolve_uid($_)) foreach (@users_add);
574 $self->perm_user_del($_, Girocco::User::resolve_uid($_)) foreach (@users_del);
576 $self->_update_index if $self->{email} ne $self->{orig_email};
577 $self->{orig_email} = $self->{email};
582 sub update_password {
583 my $self = shift;
584 my ($pwd) = @_;
586 $self->{crypt} = scrypt_sha1($pwd);
587 $self->_group_update;
590 # You can explicitly do this just on a ghost() repository too.
591 sub delete {
592 my $self = shift;
594 if (-d $self->{path}) {
595 system('rm', '-rf', $self->{path}) == 0
596 or die "rm -rf $self->{path} failed: $?";
598 # attempt to clean up any empty fork directories by removing them
599 my @pelems = split('/', $self->{name});
600 while (@pelems > 1) {
601 pop @pelems;
602 # okay to fail
603 rmdir join('/', $Girocco::Config::reporoot, @pelems) or last;
605 $self->_group_remove;
606 $self->_update_index;
609 sub _contains_files {
610 my $dir = shift;
611 (-d $dir) or return 0;
612 opendir(my $dh, $dir) or die "opendir $dir failed: $!";
613 while (my $entry = readdir($dh)) {
614 next if $entry eq '' || $entry eq '.' || $entry eq '..';
615 closedir($dh), return 1
616 if -f "$dir/$entry" ||
617 -d "$dir/$entry" && _contains_files("$dir/$entry");
619 closedir($dh);
620 return 0;
623 sub has_forks {
624 my $self = shift;
626 return _contains_files($Girocco::Config::reporoot.'/'.$self->{name});
629 sub is_empty {
630 # A project is considered empty if the git repository does not
631 # have any refs. This means packed-refs does not exist or is
632 # empty or only has lines starting with '#' AND there are no
633 # files in the refs subdirectory hierarchy (no matter how deep).
635 my $self = shift;
637 (-d $self->{path}) or return 0;
638 if (-e $self->{path}.'/packed-refs') {
639 open(my $pr, '<', $self->{path}.'/packed-refs')
640 or die "open $self->{path}./packed-refs failed: $!";
641 my $foundref = 0;
642 while (my $ref = <$pr>) {
643 next if $ref =~ /^#/;
644 $foundref = 1;
645 last;
647 close($pr);
648 return 0 if $foundref;
650 (-d $self->{path}.'/refs') or return 1;
651 return !_contains_files($self->{path}.'/refs');
654 sub delete_ctag {
655 my $self = shift;
656 my ($ctag) = @_;
658 # sanity check, disallow filenames starting with . .. or /
659 unlink($self->{path}.'/ctags/'.$ctag) if($ctag !~ m|^(\.\.?)/|);
662 sub get_ctag_names {
663 my $self = shift;
664 my @ctags = ();
665 opendir(my $dh, $self->{path}.'/ctags')
666 or return @ctags;
667 @ctags = grep { -f "$self->{path}/ctags/$_" } readdir($dh);
668 closedir($dh);
669 return @ctags;
672 sub get_heads {
673 my $self = shift;
674 my $fh;
675 open($fh, '-|', "$Girocco::Config::git_bin --git-dir=$self->{path} show-ref --heads") or die "could not get list of heads";
676 my @res;
677 while (<$fh>) {
678 chomp;
679 next if !m#^[0-9a-f]{40}\s+refs/heads/(.+)$ #x;
680 push @res, $1;
682 close $fh;
683 @res;
686 sub get_HEAD {
687 my $self = shift;
688 my $HEAD = `$Girocco::Config::git_bin --git-dir=$self->{path} symbolic-ref HEAD`;
689 chomp $HEAD;
690 die "could not get HEAD" if ($HEAD !~ m{^refs/heads/(.+)$});
691 return $1;
694 sub set_HEAD {
695 my $self = shift;
696 my $newHEAD = shift;
697 # Cursory checks only -- if you want to break your HEAD, be my guest
698 if ($newHEAD =~ /^\/|['<>]|\.\.|\/$/) {
699 die "grossly invalid new HEAD: $newHEAD";
701 system($Girocco::Config::git_bin, "--git-dir=$self->{path}", 'symbolic-ref', 'HEAD', "refs/heads/$newHEAD");
702 die "could not set HEAD" if ($? >> 8);
703 ! -d "$self->{path}/mob" || $Girocco::Config::mob ne 'mob'
704 or system('cp', '-p', '-f', "$self->{path}/HEAD", "$self->{path}/mob/HEAD") == 0;
707 sub gen_auth {
708 my $self = shift;
711 no warnings;
712 $self->{auth} = sha1_hex(time . $$ . rand() . join(':',%$self));
714 my $expire = time + 24 * 3600;
715 my $propval = "# DELAUTH $self->{auth} $expire";
716 system($Girocco::Config::git_bin, '--git-dir='.$self->{path}, 'config', 'gitweb.delauth', $propval);
717 $self->{auth};
720 sub del_auth {
721 my $self = shift;
723 delete $self->{auth};
724 system($Girocco::Config::git_bin, '--git-dir='.$self->{path}, 'config', '--unset', 'gitweb.delauth');
727 sub remove_user {
728 my $self = shift;
729 my ($username) = @_;
731 my $before_count = @{$self->{users}};
732 $self->{users} = [grep { $_ ne $username } @{$self->{users}}];
733 return @{$self->{users}} != $before_count;
736 ### static methods
738 sub get_forkee_name {
739 local $_ = $_[0];
740 (m#^(.*)/.*?$#)[0]; #
743 sub get_forkee_path {
744 no warnings; # avoid silly 'unsuccessful stat on filename with \n' warning
745 my $forkee = $Girocco::Config::reporoot.'/'.get_forkee_name($_[0]).'.git';
746 -d $forkee ? $forkee : '';
749 sub _valid_name_characters {
750 local $_ = $_[0];
751 (not m#^/#)
752 and (not m#//#)
753 and (not m#\./#)
754 and (not m#/$#)
755 and m#^[a-zA-Z0-9+./_-]+$#;
758 sub valid_name {
759 no warnings; # avoid silly 'unsuccessful stat on filename with \n' warning
760 local $_ = $_[0];
761 _valid_name_characters($_)
762 and ((not m#/#) or -d get_forkee_path($_)); # will also catch ^/
765 # It's possible that some forks have been kept but the forkee is gone.
766 # In this case the standard valid_name check is too strict.
767 sub does_exist {
768 no warnings; # avoid silly 'unsuccessful stat on filename with \n' warning
769 my ($name, $nodie) = @_;
770 my $okay = (
771 _valid_name_characters($name)
772 and ((not $name =~ m#/#)
773 or -d get_forkee_path($name)
774 or -d $Girocco::Config::reporoot.'/'.get_forkee_name($name)));
775 (!$okay && $nodie) and return undef;
776 !$okay and die "tried to query for project with invalid name $name!";
777 (-d $Girocco::Config::reporoot."/$name.git");
780 sub get_full_list {
781 my $class = shift;
782 my @projects;
784 open F, '<', jailed_file("/etc/group") or die "getting project list failed: $!";
785 while (<F>) {
786 chomp;
787 @_ = split /:+/;
788 next if ($_[2] < 65536);
790 push @projects, $_[0];
792 close F;
793 @projects;