Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Inject code to all websites?

Discussion in 'cPanel Developers' started by Pawel Lorenc, Jun 22, 2018.

Tags:
  1. Pawel Lorenc

    Pawel Lorenc Registered

    Joined:
    Jun 22, 2018
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Poland
    cPanel Access Level:
    Root Administrator
    Hello,
    I would like to write a plugin which allows me to inject a small part of code to all my websites in cPanel. I believe it is possible to Apache, I don't know how to communicate with it via the custom plugin.

    Did anyone try something similar?

    Any comments could be helpful.

    I don't know how to via plugin (PHP file) edit httpd.conf file (root permission). Any help?
     
    #1 Pawel Lorenc, Jun 22, 2018
    Last edited by a moderator: Jun 22, 2018
  2. CloudNexus

    CloudNexus Member

    Joined:
    May 18, 2018
    Messages:
    16
    Likes Received:
    2
    Trophy Points:
    3
    Location:
    Netherlands
    cPanel Access Level:
    Root Administrator
    What kind of code are you looking to include? If you don't want to break the sites of your customers you'll need to inject the code in a specific part of their pages (in the HEAD or BODY , but not AFTER the closing HTML statement).
     
  3. sparek-3

    sparek-3 Well-Known Member

    Joined:
    Aug 10, 2002
    Messages:
    1,772
    Likes Received:
    119
    Trophy Points:
    343
    cPanel Access Level:
    Root Administrator
    You might look at mod_layout. Although I suspect it is no longer being developed, but there may be a successor to it. Or at least give you a starting point to look for something.
     
  4. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,142
    Likes Received:
    1,932
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello @Pawel Lorenc,

    You can find some solutions discussed on the following StackOverflow thread:

    How to inject HTML code into every delivered HTML page?

    As far as turning it into a WHM plugin, are you sure that's needed over simply creating a custom bash script that runs as root? Or, are you looking to integrate it with the WHM interface in some way?

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Pawel Lorenc

    Pawel Lorenc Registered

    Joined:
    Jun 22, 2018
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Poland
    cPanel Access Level:
    Root Administrator
    I would like to inject some JS script in the HEAD section. For now it would be some statistics code. Maybe another one in the future.

    I am thinking about using ext_filter_module of Apache. I would need to edit httpd.conf file. I need to be root to do that.

    I wrote a cPanel plugin, but there I exec scripts as cPanel user. If I create a WHM plugin, will I run script as root?
    Is this the best solution?

    This is only part of information I would like to get. I will also use an API to get another information. That's why I would like to use plugin.
     
  6. rpvw

    rpvw Well-Known Member

    Joined:
    Jul 18, 2013
    Messages:
    905
    Likes Received:
    347
    Trophy Points:
    113
    Location:
    Spain
    cPanel Access Level:
    Root Administrator
    Have you considered using htaccess to prepend your JS as a php file?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,142
    Likes Received:
    1,932
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

    Are you sure a WHM plugin is necessary for this script as opposed to writing a custom bash script that runs from the command line? Generally, a WHM plugin is utilized if you want to allow a WHM user to perform certain actions from the UI. In the scenario you described, it seems like the server administrator could simply run the script via the command line.

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    sparek-3 likes this.
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice