UtilFunctions - Additional shared functions


This module provides an interface to utility type functions that are used by all or some of the other Luci library modules. These functions are grouped together here for easy usage and maintainabitlity instead of duplicated in each module that requires the functionality.

Even though these are only utility functions, a utility object must be created first which stores data that is required for some of the fuctions to operate. This is done because a calling module might not have access to the required information to pass into the utility function.


First, a UtilFunctions object must be created to store the needed member data required by the functions. Create the object while providing a reference to the system configuration as the only constructor parameter:

 my $utils = UtilFunctions->new($config);

Then, give the object some addtional data to work with:

 # notice that @allowlist, @denylist and @list_of_file_extensions are
 # lists/arrays containing the allowed/deny urls/file extensions
 # that are normally grabbed from the config.
 $utils->{_allowlist} = @allowlist;
 $utils->{_denylist} = @denylist;
 $utils->{_extensions} = @list_of_file_extensions;

Next call a member function of this $utils object like so:

 if( $utils->is_parsable("http*://") ){ 
        echo "We can use luci to simplify this page!!!"; 



Determines if the given URL is allowed wrt the list of allow/deny lists (defined in the _(allow|deny)list member variables.)

 is_allowed(string url)

returns true if url is allowed, false otherwise.


 if( $utils->is_allowed("http*://") ){
        echo "We might be able to parse this page!";
 } else {
        echo "Outsider!";


Determines if the given URL is an internal page as compared to the app_root_url configuration setting

note: and differ, and so will not be flagged as internal

 is_internal(string url)

returns true if url is internal, false otherwise.


 if( $utils->is_internal("http*://") ){
        echo "is internal";
 } else {
        echo "is external";


Determines if the given URL is a document that we are able to parse (parsable extensions are defined in the _extensions member variable.)

 is_parsable(string url)

returns true if url is parsable, false otherwise.


 if( $utils->is_parsable("http*://") ){
         echo "Luci is capable of parsing this page!";
 } else {
         echo "What a farce, we can't parse!";


Takes a URL and provides a Luci parseable link:

 create_app_url(string document_url, string url_from_html);
 # document_url = the URL of the document that contains the link
 # url_from_html = the link URL as presented in the document

returns the url to be displayed in the browser


 my $url = $utils->create_app_url("http*://", 
 # if is internal, $url will hold
 # [luci_script_url]http*://
 # if is not internal, $url will hold
 # http*://


Given an absolute URL, abs_url transforms a potentially relative URL into an absolute URL with respect to the given known absolute URL. Keep in mind that the potentially relative URL may actually be absolute, in which case it would remain unchanged.

 abs_url(string absolute_url, string url_to_resolve)

returns the absolute version of url_to_resolve


 $url = $utils->abs_url("http*://", "test/script.cgi");
 # $url contains http*://
 $url = $utils->abs_url("http*://",
 # $url contains http*://


This is the main error reporting fuction. It should be noted that this function is not a member function, and should not be used by calling it with a UtilFunctions object. error puts the error message into a standard Luci error html template that can be displayed to the user.

 error(hashref config, string error_msg [, integer error_code])
 # config is a hash reference to the configuration variables for Luci
 # (optional) error_code is an integer representing a fatal error

returns the html that contains the error message and should be displayed to the user.


dies with provided error_msg


 # $config is a hash reference to a previously created hash of
 # configuration variables
 $html = UtilFunctions::error($config, "You can't view this page.");
 echo $html;
 UtilFunctions::error($config, "bad url sructure", 12);
 # this will kill the application with fatal error 12


Version of quotemeta that ignores escape of specific characters that are required to perform the regex as is necessary on allow/deny urls.


 	# will return url as http\:\/\/www\.yourdomain\.com(\/.*?|)
 	$escaped = qmeta('*>');


See Luci Documentation for more information.