shlib.sh: Add new bang_eval function
[girocco.git] / cgi / tagproj.cgi
blob89022754b9067925c203d87cf3581a0552210d3d
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::Project;
11 use Girocco::Util;
12 use CGI;
14 our $cgi = CGI->new;
16 my $pname = $cgi->param('p')||'';
17 my $ctags = $cgi->param('t')||'';
18 $pname =~ s/\.git$//;
20 if ($cgi->request_method ne 'POST') {
21 print $cgi->header(-status=>403);
22 print "<p>Invalid data. Go away, sorcerer.</p>\n";
23 exit;
26 my $proj = Girocco::Project->load($pname);
27 if (not $proj) {
28 print $cgi->header(-status=>404);
29 print "<p>Project $pname does not exist.</p>";
30 exit;
33 if ($ctags =~ /[^ a-zA-Z0-9:.+#_-]/) {
34 print $cgi->header(-status=>403);
35 print "<p>Content tag(s) '$ctags' contain evil characters.</p>";
36 exit;
39 foreach my $ctag (split(/ /, $ctags)) {
40 # Locking is not important
41 valid_tag($ctag) or next;
42 my $val = 0;
43 open CT, '<', $proj->{path}."/ctags/$ctag" and $val = <CT> and close CT;
44 chomp $val;
45 open CT, '>', $proj->{path}."/ctags/$ctag" and print CT ($val+1)."\n" and close CT;
48 print $cgi->header(-status=>303, -location=>"@{[url_path($Girocco::Config::gitweburl)]}/$pname.git");