Pawel Lorenc

Registered
Jun 22, 2018
2
0
1
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?
 
Last edited by a moderator:

CloudNexus

Member
May 18, 2018
20
2
3
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).
 

sparek-3

Well-Known Member
Aug 10, 2002
2,126
258
388
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.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,883
2,256
463
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.
 

Pawel Lorenc

Registered
Jun 22, 2018
2
0
1
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.
 

rpvw

Well-Known Member
Jul 18, 2013
1,101
472
113
UK
cPanel Access Level
Root Administrator
Have you considered using htaccess to prepend your JS as a php file?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,883
2,256
463
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?
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.
 
  • Like
Reactions: sparek-3