]> git.sesse.net Git - itkacl/blobdiff - 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
diff --git a/itkacl-web-1.0/web/addnode.pl b/itkacl-web-1.0/web/addnode.pl
new file mode 100755 (executable)
index 0000000..d0f1ddd
--- /dev/null
@@ -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");
+