X-Git-Url: https://git.sesse.net/?p=itkacl;a=blobdiff_plain;f=itkacl-web-1.0%2Fweb%2Faddnode.pl;fp=itkacl-web-1.0%2Fweb%2Faddnode.pl;h=d0f1ddd7271e6f4f13eb068128eb507f4b1e80bf;hp=0000000000000000000000000000000000000000;hb=e7130e30ca2a76082de68a72fb2a52b4510f7bf1;hpb=b9014762b8051b457c68d8de11a08d64401026fa diff --git a/itkacl-web-1.0/web/addnode.pl b/itkacl-web-1.0/web/addnode.pl new file mode 100755 index 0000000..d0f1ddd --- /dev/null +++ b/itkacl-web-1.0/web/addnode.pl @@ -0,0 +1,38 @@ +#! /usr/bin/perl -T +use strict; +use warnings; +use utf8; + +use lib '../include'; +use itkaclcommon; + +itkaclcommon::init(); + +my $parent = $itkaclcommon::cgi->param('parent'); +my $name = $itkaclcommon::cgi->param('name'); +my $description = $itkaclcommon::cgi->param('description'); + +if ($name !~ /^[a-zA-Z0-9-]+$/) { + die "Illegal characters in name"; +} +if (length($name) > 64) { + die "Name too long"; +} + +$itkaclcommon::dbh->do('INSERT INTO objects (name,description,parent) VALUES (?,?,?)', undef, + $name, $description, $parent) + or die "Couldn't insert new object"; + +# Let sync-itkacl know there's updates +utime(time(), time(), '/etc/itkacl/updated'); + +# +# Redirect to the newly created node (a little touch: make sure the node +# is opened so the new node is visible in the tree -- this won't catch all +# cases, but at least most of them). +# +my $ref = $itkaclcommon::dbh->selectrow_hashref('SELECT id FROM objects WHERE name=? AND parent=?', + undef, $name, $parent); + +print $itkaclcommon::cgi->redirect("view.pl?entry=$ref->{'id'}&open=$parent"); +