3 ### URL shortening userv interface for Odin
5 ### (c) 2015 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the `odin.gg' service, `odin-cgi'.
12 ### `odin-cgi' is free software; you can redistribute it and/or modify
13 ### it under the terms of the GNU Affero General Public License as
14 ### published by the Free Software Foundation; either version 3 of the
15 ### License, or (at your option) any later version.
17 ### `odin-cgi' is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ### GNU Affero General Public License for more details.
22 ### You should have received a copy of the GNU Affero General Public
23 ### License along with `odin-cgi'; if not, see
24 ### <http://www.gnu.org/licenses/>.
33 my $op = shift(@ARGV) // "help";
44 } elsif ($op eq "list") {
45 @ARGV == 0 or Odin::fail "usage: list";
46 my $db = Odin::open_db;
47 for my $r (@{$db->selectall_arrayref
48 ("SELECT tag, stamp, url
49 FROM odin_shorturl WHERE owner = ?
50 ORDER BY stamp", undef, $Odin::WHO)}) {
51 my ($tag, $stamp, $url) = @$r;
52 Odin::print_columns Odin::fmt_time $stamp => 25, $tag => 12, $url =>0;
54 } elsif ($op eq "new") {
55 @ARGV == 1 or Odin::fail "usage: new URL";
57 my $tag = Odin::new_shorturl $url;
58 print "$Odin::SHORTURL/$tag\n";
59 } elsif ($op eq "get") {
60 @ARGV >= 0 or Odin::fail "usage: get TAG ...";
61 if (@ARGV == 1) { print Odin::get_shorturl $ARGV[0], "\n"; }
64 { printf "%-12s %s\n", $tag, Odin::get_shorturl $tag; }
66 } elsif ($op eq "del") {
67 @ARGV >= 0 or Odin::fail "usage: del TAG ...";
68 Odin::delete_shorturl @ARGV;
70 Odin::fail "unknown operation `$op'";