deth4uall

Well-Known Member
Sep 30, 2011
45
0
56
Austin, Texas, United States
cPanel Access Level
Root Administrator
I am trying to create an OptMod for EasyApache however I need add a LoadFile tag. I know that EasyApache has the $self->ensure_loadmodule_into_httpdconf('proxy', 'mod_proxy.so'); method for LoadModule, however because you do not have an API documentation for EasyApache I was unable to find out if you had an equivalent method for LoadFile conf tag.

Any information is appreciated.
 

deth4uall

Well-Known Member
Sep 30, 2011
45
0
56
Austin, Texas, United States
cPanel Access Level
Root Administrator
Sure, I am currently trying to create a OptMod for the mod_proxy_html. The package Cpanel::Easy::ModProxyHTML is available online for review: https://github.com/Necromnius/Cpanel-Easy-ModProxyHTML/blob/master/ModProxyHTML.pm I am using " $self->ensure_loadmodule_in_httpdconf('proxy_html', 'mod_proxy_html.so');" to add "LoadModule proxy_html_module modules/mod_proxy_html.so" to the httpd.conf. I would like to add a "LoadFile /opt/xml2/lib/libxml2.so" before the other two loaded modules. What is the best way to include that? Is there a method that can be used?

Also do you guys have an API Documentation available? I couldn't find any documentation on all of the available methods. EDIT: I would like to see some perldocs for the Cpanel packages someday if you can pass that onto the dev team?
 
Last edited:

cPanelKenneth

cPanel Development
Staff member
Apr 7, 2006
4,607
80
458
cPanel Access Level
Root Administrator
Let me pass this question on to the EasyApache team; they are in the best position to answer it.
 

ScottTh

Well-Known Member
Jan 28, 2013
157
2
18
Houston, TX
cPanel Access Level
Root Administrator
Hello,

Here is some guidance for this issue from the EasyApache team:

For better or for worse, we do not currently have a 'LoadFile' API (like we do with LoadModule). To ensure that the LoadFile directive is in a particular place within httpd.conf, we effectively search and replace, much like one would do with 'sed' on the command-line.

Traditionally, we use Cpanel::FileUtils::regex_rep_file() to search for a location, then stab in the information we want to place.
An example of this would be:

use Cpanel::FileUtils ();
my $conf = '/path/to/conf';
my %rep = ( qr{^(Insert\s+After\s+This)} => q{$1\n# Added this to next line} );
my %err;
my $rc = Cpanel::FileUtils::regex_rep_file( $conf, \%rep, \%err );
if( $rc ) {
# do success stuff
} else {
# do failed open file stuff
}

NOTE: "Success" determines that the file could be opened AND the regex itself didn't have a compile error. It does not ensure that the match was successful. The file will be left as-is if the regex in qr{} didn't match anything in the file.

Have a good day!
 

deth4uall

Well-Known Member
Sep 30, 2011
45
0
56
Austin, Texas, United States
cPanel Access Level
Root Administrator
Okay, I added the `use Cpanel::FileUtils ();` outside of the `our $easyconfig` and it's not showing up in EasyApache anymore.

You can see how I utilized what you gave me here: https://github.com/Necromnius/Cpanel-Easy-ModProxyHTML/blob/master/ModProxyHTML.pm

EDIT: I have corrected that issue, and am now clearing up the rest of the code however I am not able to get past this issue.

'/usr/local/apache/bin/apxs -aic -I/opt/xml2/lib/libxml2 /home/cpeasyapache/src/mod_xml2enc/mod_xml2enc.c' failed with exit code '256'
 
Last edited:

deth4uall

Well-Known Member
Sep 30, 2011
45
0
56
Austin, Texas, United States
cPanel Access Level
Root Administrator
I have created a pastbin which you can view the result of what I get there: http://pastebin.com/EPWjWsze

EDIT: Figured out that I needed to use /usr/include/libxml2 in the command not the /opt/xml2/lib/libxml2 http://pastebin.com/sP8Npgs6 which was successful but now I need to make sure that the libxml2 gets inserted correctly.
 
Last edited:

KurtN.

Well-Known Member
Jan 29, 2013
95
1
83
cPanel Access Level
Root Administrator
I have created a pastbin which you can view the result of what I get there: apxs result - Pastebin.com

EDIT: Figured out that I needed to use /usr/include/libxml2 in the command not the /opt/xml2/lib/libxml2
Well, from the pastebin, it looks like you can continue using /opt for libxml2.
The apxs command being used is pointing to the wrong directory.

The pastebin shows:
/usr/local/apache/bin/apxs -aic -I/opt/xml2/lib/libxml2 /usr/src/Cpanel-Easy-ModProxyHTML/mod_xml2enc/mod_xml2enc.c

It should be:
/usr/local/apache/bin/apxs -aic -I/opt/xml2/include/libxml2 /usr/src/Cpanel-Easy-ModProxyHTML/mod_xml2enc/mod_xml2enc.c

EDIT:

Additionally, by using the /opt version of libxml2, you're more likely to receive faster turn-around times for security updates provided by cPanel.
 
Last edited:

deth4uall

Well-Known Member
Sep 30, 2011
45
0
56
Austin, Texas, United States
cPanel Access Level
Root Administrator
Okay thanks, unfortunately I am having trouble inserting the LoadFile into the httpd.conf and get this every time:

Output was:
---
httpd: Syntax error on line 33 of /usr/local/apache/conf/httpd.conf.1359569054: Cannot load /usr/local/apache/modules/mod_proxy_html.so into server: /usr/local/apache/modules/mod_proxy_html.so: undefined symbol: htmlFreeParserCtxt
---
!
I am guessing that I should be trying to figure out what is being stored as temporary file eg. `/usr/local/apache/conf/httpd.conf.1359569054` instead of `/usr/local/apache/conf/httpd.conf`? How can I determine the proper extension before it is moved to the default space?

I am currently using this step:

'4' => {
'name' => 'Loading libxml2 into httpd.conf',
'command' => sub {
my ($self) = @_;
my $conf = '/usr/local/apache/conf/httpd.conf';
my %rep = ( qr{^(LoadModule\s+proxy_html_module\s+modules/mod_proxy_html[.]so)} => q{LoadFile /opt/xml2/lib/libxml2.so\n$1} );
my %err;
my $rc = Cpanel::FileUtils::regex_rep_file( $conf, \%rep, \%err );
if ($rc) {
return ($rc, %err);
} else {
$self->print_alert( q{Could not add '[_1]' to '[_2]'}, 'libxml2 LoadFile', $conf );
}
},
},

Source: https://github.com/Necromnius/Cpanel-Easy-ModProxyHTML/blob/master/ModProxyHTML.pm Line: 61
I am currently using this to insert the `LoadFile /opt/xml2/lib/libxml2.so` before the `LoadModule proxy_html_module modules/mod_proxy_html.so` however I just realized that EasyApache doesn't add to the main .conf but to a temporary one it tests before using. What is the best way to find the right file to modify?

BTW, Thanks for all the help! You are all welcome to use and/or contribute to this project for users who will be using Apache 2.2 for the current duration but want these modules. :)
 
Last edited:

KurtN.

Well-Known Member
Jan 29, 2013
95
1
83
cPanel Access Level
Root Administrator
Deleted this duplicate post.

EDIT: For some reason this didn't show up when I submitted it. So, I thought I fat-fingered and lost the submit. The following post contains the proper info.
 

KurtN.

Well-Known Member
Jan 29, 2013
95
1
83
cPanel Access Level
Root Administrator
Hi deth4uall.

It seems like the issue you're having has to do with apache_conf_distiller removing the 'LoadFile' directive.
To get around this issue, I went ahead and quickly modified your code.
The changes are as follows:
  • Now ensures Apache 2.2 is selected. This is important because Apache 2.4 will have both mod_proxy_html and mod_xml2enc support. Though, the current dev version of easyapache doesn't expose that functionality yet.
  • Now places all the LoadModule and LoadFile directives into a single mod_proxy_html.conf file.
  • apxs no longer adds LoadModule to httpd.conf
  • The module now places an 'Include' directive to ensure these custom modules are loaded
  • Expects all files (source code and config) to be in a tarball with a directory named 'mod_proxy_html'. If this doesn't work for you, feel free to change the paths in each of the apxs and install steps.


mod_proxy_html.conf
Code:
LoadFile /opt/xml2/lib/libxml2.so
LoadModule xml2enc_module modules/mod_xml2enc.so
LoadModule proxy_html_module modules/mod_proxy_html.so
ModProxyHTML.pm
Pastebin Link to ModProxyHTML.pm
 

KurtN.

Well-Known Member
Jan 29, 2013
95
1
83
cPanel Access Level
Root Administrator
Well, afaik, the only kind of "package" that optmods come in, is a tarball that contains the dependency files, and the associated perl module(s) that EasyApache picks up.

If I were trying to release my own easily installable package, I'd likely create a self-extracting shell script that contains the tarball. There are lot's of examples of this on the Internet.
 

deth4uall

Well-Known Member
Sep 30, 2011
45
0
56
Austin, Texas, United States
cPanel Access Level
Root Administrator
Alright, I just wasn't sure if you guys did anything like actual Perl does with building of Perl Packages and Modules etc. I had looked into this but I could only find a way to build them and have them create a tar.gz package not to have them install or even have them create the appropriate tarball and move the files etc during the install of the package. Thanks for info, I will just leave the shell script that is there as is.