{"id":56,"date":"2009-09-23T17:45:04","date_gmt":"2009-09-23T22:45:04","guid":{"rendered":"http:\/\/blogs.wp.stage.cpanel.net\/2009\/09\/creating_cpanel_cgi_scripts\/"},"modified":"2009-09-23T17:45:04","modified_gmt":"2009-09-23T22:45:04","slug":"creating_cpanel_cgi_scripts","status":"publish","type":"post","link":"https:\/\/devel.www.cpanel.net\/blog\/products\/creating_cpanel_cgi_scripts\/","title":{"rendered":"Creating cPanel CGI Scripts"},"content":{"rendered":"
One of the most flexible ways of working within cPanel is by creating CGI applications.\u00a0 Of course, this isn\u2019t the most efficient method, however sometimes efficiency isn\u2019t your best bet when you\u2019re in a rush.\u00a0 You can use a standard CGI script within cPanel, you are limited by our APIs, such as what perl version to use.<\/p>\n
First thing to note, is that these CGI scripts\u00a0 have to be placed in \/usr\/local\/cpanel\/base\/3rdparty\/ with normal CGI permissions (have to be executable by the user, cannot be globally writable, etc).\u00a0 Once placed here it can be accessed via $IP:2083\/3rdparty\/scriptnamed.cgi.\u00a0 If you place them anywhere else within the cPanel document root, they will be offered up for download rather than executable.<\/p>\n
When these CGI scripts are executed, they are executed as the user, so limited permissions apply.<\/p>\n
What if you want to actually access cPanel\u2019s APIs from within this CGI script?\u00a0 What do you do?\u00a0 There are a few different ways of handling this.\u00a0 First you can use the JSON API<\/a> if you just want to handle the interaction via javascript (you\u2019re already authenticated, why not?).\u00a0 The other option is using the Cpanel::XML module to make XML-API calls without the HTTP interface at all.\u00a0 With the introduction of XML API\u2019s Fast Mode<\/a> we included a function called cpanel_fast_exec.\u00a0 This is essentially a perl interface into API1 and API2 that can be accessed outside of cPanel.\u00a0 The data passed into this is the same as the parameters used inside of fast mode.\u00a0 For example, if you wanted to get a list of email accounts, you would call the following: $xml = XMLin($xml);<\/p>\n Now $xml is a hash reference containing all the information returned by the call.<\/p>\n To download the example of this in use, click here.<\/p>\n","protected":false},"excerpt":{"rendered":" One of the most flexible ways of working within cPanel is by creating CGI applications.\u00a0 Of course, this isn\u2019t the most efficient method, however sometimes efficiency isn\u2019t your best bet when you\u2019re in a rush.\u00a0 You can use a standard CGI script within cPanel, you are limited by our APIs, such as what perl version […]<\/p>\n","protected":false},"author":77,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[49],"tags":[],"class_list":["post-56","post","type-post","status-publish","format-standard","hentry","category-products"],"acf":[],"yoast_head":"\n
\nmy $xml = Cpanel::XML::cpanel_exec_fast(
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'cpanel_xmlapi_module' => 'Email',
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 'cpanel_xmlapi_func' => 'listpopswithdisk',
\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }
\n);<\/code><\/p>\n