Просмотр исходного кода

Add stupid simple api processor

Andy Baugh 5 лет назад
Родитель
Сommit
3edf5924c1
4 измененных файлов с 24 добавлено и 2 удалено
  1. 3 0
      Makefile
  2. 12 1
      cgi/api.cgi
  3. 5 1
      lib/Troglodyne/CGI.pm
  4. 4 0
      plugin/troglodyne_api.conf

+ 3 - 0
Makefile

@@ -4,9 +4,12 @@ all: install
 install:
 	/usr/local/cpanel/3rdparty/bin/perl install/install.pl
 	chmod +x /usr/local/cpanel/whostmgr/docroot/cgi/troglodyne/pgupgrade.cgi
+	chmod +x /usr/local/cpanel/whostmgr/docroot/cgi/troglodyne/api.cgi
 	/usr/local/cpanel/bin/register_appconfig ./plugin/better_postgres.conf
+	/usr/local/cpanel/bin/register_appconfig ./plugin/troglodyne_api.conf
 
 uninstall:
+	/usr/local/cpanel/bin/unregister_appconfig troglodyne_api
 	/usr/local/cpanel/bin/unregister_appconfig better_postgres
 	rm -rf /var/cpanel/perl/Troglodyne
 	rm -rf /var/cpanel/templates/troglodyne

+ 12 - 1
cgi/api.cgi

@@ -10,11 +10,22 @@ use Cpanel::LoadModule::Custom ();
 use JSON::XS                   ();
 
 run() unless caller();
- 
+
 sub run {
+    # Load up CGI processing modules
+    Cpanel::LoadModule::Custom::load_perl_module("Troglodyne::CGI");
+
     # Process the args
+    my $args = Troglodyne::CGI::get_args();
 
     # Get back the datastruct from the called module.
+    my $ret = {
+        'metadata' => {
+            'input_args' => $args,
+        },
+        'data' => {},
+        'result' => 1,
+    };
 
     # Emit the JSON
     print "Content-type: application/json\r\n\r\n";

+ 5 - 1
lib/Troglodyne/CGI.pm

@@ -3,6 +3,10 @@ package Troglodyne::CGI;
 use strict;
 use warnings;
 
-
+# Need to also get POST args, etc.
+sub get_args {
+    my $args_hr = { map { split( /=/, $_ ) } split( /&/, $ENV{'QUERY_STRING'} ) };
+    return $args_hr;
+}
 
 1;

+ 4 - 0
plugin/troglodyne_api.conf

@@ -0,0 +1,4 @@
+service=whostmgr
+user=root
+url=/cgi/troglodyne/api.cgi
+acls=all