The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

OptMod loadfile method

Discussion in 'cPanel Developers' started by deth4uall, Jan 25, 2013.

  1. deth4uall

    deth4uall Well-Known Member

    Joined:
    Sep 30, 2011
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    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.
     
  2. cPanelKenneth

    cPanelKenneth cPanel Development
    Staff Member

    Joined:
    Apr 7, 2006
    Messages:
    4,458
    Likes Received:
    22
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    Could you provide a simple example of what you are trying to accomplish?
     
  3. deth4uall

    deth4uall Well-Known Member

    Joined:
    Sep 30, 2011
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    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?
     
    #3 deth4uall, Jan 25, 2013
    Last edited: Jan 26, 2013
  4. cPanelKenneth

    cPanelKenneth cPanel Development
    Staff Member

    Joined:
    Apr 7, 2006
    Messages:
    4,458
    Likes Received:
    22
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    Let me pass this question on to the EasyApache team; they are in the best position to answer it.
     
  5. ScottTh

    ScottTh Well-Known Member

    Joined:
    Jan 28, 2013
    Messages:
    157
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    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!
     
  6. deth4uall

    deth4uall Well-Known Member

    Joined:
    Sep 30, 2011
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    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'
     
    #6 deth4uall, Jan 29, 2013
    Last edited: Jan 29, 2013
  7. ScottTh

    ScottTh Well-Known Member

    Joined:
    Jan 28, 2013
    Messages:
    157
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Please let me know if the solution from the EasyApache team has worked.

    Have a good day and thank you for the post!
     
  8. cPanelKurtN

    cPanelKurtN Well-Known Member
    Staff Member

    Joined:
    Jan 29, 2013
    Messages:
    95
    Likes Received:
    1
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    Hi deth4uall.

    If you were to manually run apxs on the command-line, what output do you get?
     
    #8 cPanelKurtN, Jan 29, 2013
    Last edited: Jan 29, 2013
  9. deth4uall

    deth4uall Well-Known Member

    Joined:
    Sep 30, 2011
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    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.
     
    #9 deth4uall, Jan 30, 2013
    Last edited: Jan 30, 2013
  10. cPanelKurtN

    cPanelKurtN Well-Known Member
    Staff Member

    Joined:
    Jan 29, 2013
    Messages:
    95
    Likes Received:
    1
    Trophy Points:
    8
    cPanel Access Level:
    Root Administrator
    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.
     
    #10 cPanelKurtN, Jan 30, 2013
    Last edited: Jan 30, 2013
  11. deth4uall

    deth4uall Well-Known Member

    Joined:
    Sep 30, 2011
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    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:

    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:

    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. :)
     
    #11 deth4uall, Jan 30, 2013
    Last edited: Jan 30, 2013
  12. cPanelKurtN

    cPanelKurtN Well-Known Member
    Staff Member

    Joined:
    Jan 29, 2013
    Messages:
    95
    Likes Received:
    1
    Trophy Points:
    8
    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.
     
  13. cPanelKurtN

    cPanelKurtN Well-Known Member
    Staff Member

    Joined:
    Jan 29, 2013
    Messages:
    95
    Likes Received:
    1
    Trophy Points:
    8
    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
     
  14. deth4uall

    deth4uall Well-Known Member

    Joined:
    Sep 30, 2011
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Austin, Texas, United States
    cPanel Access Level:
    Root Administrator
    Perfect that was exactly what I needed! I have the latest version up on GitHub if you guys want to use it. :)
     
  15. deth4uall

    deth4uall Well-Known Member

    Joined:
    Sep 30, 2011
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Austin, Texas, United States
    cPanel Access Level:
    Root Administrator
    Is there a way that I can make this into a package to easily install?
     
  16. cPanelKurtN

    cPanelKurtN Well-Known Member
    Staff Member

    Joined:
    Jan 29, 2013
    Messages:
    95
    Likes Received:
    1
    Trophy Points:
    8
    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.
     
  17. deth4uall

    deth4uall Well-Known Member

    Joined:
    Sep 30, 2011
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    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.
     

Share This Page