update.sh: do nothing if .nofetch exists
[girocco/readme.git] / cgi / tagproj.cgi
blobc90f2e29e118af012a1de0788cffa8992788cab2
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib ".";
9 use Girocco::Config;
10 use Girocco::CGI;
11 use Girocco::Project;
12 use Girocco::Util;
13 use CGI;
15 our $cgi = CGI->new;
16 $cgi->charset('UTF-8');
18 my $pname = to_utf8($cgi->param('p'), 1);
19 my $ctags = to_utf8($cgi->param('t'), 1);
20 defined $pname or $pname = '';
21 defined $ctags or $ctags = '';
22 $pname =~ s/\.git$//;
24 if ($cgi->request_method ne 'POST' || $pname eq '') {
25 print $cgi->header(-status=>403);
26 print "<p>Invalid data. Go away, sorcerer.</p>\n";
27 exit;
30 my $proj = Girocco::Project::does_exist($pname, 1) && Girocco::Project->load($pname);
31 if (not $proj) {
32 print $cgi->header(-status=>404);
33 print "<p>Project \"".html_esc($pname)."\" does not exist.</p>";
34 exit;
37 if ($ctags =~ /[^ a-zA-Z0-9:.+#_-]/) {
38 print $cgi->header(-status=>403);
39 print "<p>Content tag(s) '".html_esc($ctags)."' contain evil characters.</p>";
40 exit;
43 foreach my $ctag (split(/ /, $ctags)) {
44 # Locking is not important
45 valid_tag($ctag) or next;
46 my $val = 0;
47 my $ct;
48 if (open $ct, '<', $proj->{path}."/ctags/$ctag") {
49 my $count = <$ct>;
50 close $ct;
51 defined $count or $count = '';
52 chomp $count;
53 $val = $count =~ /^[1-9]\d*$/ ? $count : 1;
55 my $oldmask = umask();
56 umask($oldmask & ~0060);
57 open $ct, '>', $proj->{path}."/ctags/$ctag" and print $ct ($val+1)."\n" and close $ct;
58 $proj->_set_changed;
59 $proj->_set_forkchange;
60 umask($oldmask);
63 print $cgi->header(-status=>303, -location=>"@{[url_path($Girocco::Config::gitweburl)]}/$pname.git");