{"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:
\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

$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":"\nCreating cPanel CGI Scripts | cPanel<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/devel.www.cpanel.net\/blog\/products\/creating_cpanel_cgi_scripts\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Creating cPanel CGI Scripts | cPanel\" \/>\n<meta property=\"og:description\" content=\"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 […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/devel.www.cpanel.net\/blog\/products\/creating_cpanel_cgi_scripts\/\" \/>\n<meta property=\"og:site_name\" content=\"cPanel\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cpanel\/\" \/>\n<meta property=\"article:published_time\" content=\"2009-09-23T22:45:04+00:00\" \/>\n<meta name=\"author\" content=\"cPanel Community\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cPanel\" \/>\n<meta name=\"twitter:site\" content=\"@cPanel\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"cPanel Community\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/devel.www.cpanel.net\/blog\/products\/creating_cpanel_cgi_scripts\/\",\"url\":\"https:\/\/devel.www.cpanel.net\/blog\/products\/creating_cpanel_cgi_scripts\/\",\"name\":\"Creating cPanel CGI Scripts | cPanel\",\"isPartOf\":{\"@id\":\"https:\/\/devel.www.cpanel.net\/#website\"},\"datePublished\":\"2009-09-23T22:45:04+00:00\",\"dateModified\":\"2009-09-23T22:45:04+00:00\",\"author\":{\"@id\":\"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/8cf97408aad4fb70cf55d11a1d4f57f8\"},\"breadcrumb\":{\"@id\":\"https:\/\/devel.www.cpanel.net\/blog\/products\/creating_cpanel_cgi_scripts\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/devel.www.cpanel.net\/blog\/products\/creating_cpanel_cgi_scripts\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/devel.www.cpanel.net\/blog\/products\/creating_cpanel_cgi_scripts\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/devel.www.cpanel.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Creating cPanel CGI Scripts\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/devel.www.cpanel.net\/#website\",\"url\":\"https:\/\/devel.www.cpanel.net\/\",\"name\":\"cPanel\",\"description\":\"Hosting Platform of Choices\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/devel.www.cpanel.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/8cf97408aad4fb70cf55d11a1d4f57f8\",\"name\":\"cPanel Community\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e1949945083b5526bb95711bd3d616b3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e1949945083b5526bb95711bd3d616b3?s=96&d=mm&r=g\",\"caption\":\"cPanel Community\"},\"description\":\"The web hosting industry's most reliable management solution since 1997. With our first-class support and rich feature set, it's easy to see why our customers and partners make cPanel & WHM their hosting platform of choice. For more information, visit cPanel.net.\",\"sameAs\":[\"https:\/\/cpanel.net\"],\"url\":\"https:\/\/devel.www.cpanel.net\/blog\/author\/cpadmin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Creating cPanel CGI Scripts | cPanel","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/devel.www.cpanel.net\/blog\/products\/creating_cpanel_cgi_scripts\/","og_locale":"en_US","og_type":"article","og_title":"Creating cPanel CGI Scripts | cPanel","og_description":"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 […]","og_url":"https:\/\/devel.www.cpanel.net\/blog\/products\/creating_cpanel_cgi_scripts\/","og_site_name":"cPanel","article_publisher":"https:\/\/www.facebook.com\/cpanel\/","article_published_time":"2009-09-23T22:45:04+00:00","author":"cPanel Community","twitter_card":"summary_large_image","twitter_creator":"@cPanel","twitter_site":"@cPanel","twitter_misc":{"Written by":"cPanel Community","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/devel.www.cpanel.net\/blog\/products\/creating_cpanel_cgi_scripts\/","url":"https:\/\/devel.www.cpanel.net\/blog\/products\/creating_cpanel_cgi_scripts\/","name":"Creating cPanel CGI Scripts | cPanel","isPartOf":{"@id":"https:\/\/devel.www.cpanel.net\/#website"},"datePublished":"2009-09-23T22:45:04+00:00","dateModified":"2009-09-23T22:45:04+00:00","author":{"@id":"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/8cf97408aad4fb70cf55d11a1d4f57f8"},"breadcrumb":{"@id":"https:\/\/devel.www.cpanel.net\/blog\/products\/creating_cpanel_cgi_scripts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/devel.www.cpanel.net\/blog\/products\/creating_cpanel_cgi_scripts\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/devel.www.cpanel.net\/blog\/products\/creating_cpanel_cgi_scripts\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/devel.www.cpanel.net\/"},{"@type":"ListItem","position":2,"name":"Creating cPanel CGI Scripts"}]},{"@type":"WebSite","@id":"https:\/\/devel.www.cpanel.net\/#website","url":"https:\/\/devel.www.cpanel.net\/","name":"cPanel","description":"Hosting Platform of Choices","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/devel.www.cpanel.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/8cf97408aad4fb70cf55d11a1d4f57f8","name":"cPanel Community","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/devel.www.cpanel.net\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e1949945083b5526bb95711bd3d616b3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e1949945083b5526bb95711bd3d616b3?s=96&d=mm&r=g","caption":"cPanel Community"},"description":"The web hosting industry's most reliable management solution since 1997. With our first-class support and rich feature set, it's easy to see why our customers and partners make cPanel & WHM their hosting platform of choice. For more information, visit cPanel.net.","sameAs":["https:\/\/cpanel.net"],"url":"https:\/\/devel.www.cpanel.net\/blog\/author\/cpadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/posts\/56"}],"collection":[{"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/users\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/comments?post=56"}],"version-history":[{"count":0,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/posts\/56\/revisions"}],"wp:attachment":[{"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/media?parent=56"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/categories?post=56"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devel.www.cpanel.net\/wp-json\/wp\/v2\/tags?post=56"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}