]> git.sesse.net Git - itkacl/blob - itkacl-web-1.0/web/addnode.pl
Add the bare minimum of what is required for the web interface to work (but be butt...
[itkacl] / itkacl-web-1.0 / web / addnode.pl
1 #! /usr/bin/perl -T
2 use strict;
3 use warnings;
4 use utf8;
5
6 use lib '../include';
7 use itkaclcommon;
8
9 itkaclcommon::init();
10
11 my $parent = $itkaclcommon::cgi->param('parent');
12 my $name = $itkaclcommon::cgi->param('name');
13 my $description = $itkaclcommon::cgi->param('description');
14
15 if ($name !~ /^[a-zA-Z0-9-]+$/) {
16         die "Illegal characters in name";
17 }
18 if (length($name) > 64) {
19         die "Name too long";
20 }
21         
22 $itkaclcommon::dbh->do('INSERT INTO objects (name,description,parent) VALUES (?,?,?)', undef,
23     $name, $description, $parent)
24         or die "Couldn't insert new object";
25
26 # Let sync-itkacl know there's updates
27 utime(time(), time(), '/etc/itkacl/updated');
28
29 #
30 # Redirect to the newly created node (a little touch: make sure the node
31 # is opened so the new node is visible in the tree -- this won't catch all
32 # cases, but at least most of them).
33
34 my $ref = $itkaclcommon::dbh->selectrow_hashref('SELECT id FROM objects WHERE name=? AND parent=?',
35         undef, $name, $parent);
36         
37 print $itkaclcommon::cgi->redirect("view.pl?entry=$ref->{'id'}&open=$parent");
38