Adding YAML Variable to Userdata file

mtylerb

Well-Known Member
Nov 10, 2007
57
0
56
Warburg, AB, Canada
cPanel Access Level
Root Administrator
As the title suggests. I'm putting a temporary fix in place to handle IPv6 until cPanel finally gets around to supporting it. My current solution isn't working and is a general pain in the rear. It works fine for non-SSL vhosts, but SSL vhosts are causing issues. What I'd like to do is add, say, an ehip6 variable with the account's IPv6 address as the value. I say something like "ehip6" just because I know it won't interfere, in the future, with something cPanel throws in. I'm using .local vhost files, so that I can just delete them when the time comes for cPanel to support it.

What I'm not 100% on, is how to add such a line to the Userdata file in /var/cpane/userdata/[username]/[domain]. Can anyone break down the YAML::Syck command for me? I'd like to understand it a little better. Documentation suggests I can't just go an put a
Code:
ehip6: 2607:5300:1:2:dead:beef:cafe:2
line or something of the sort in there in case it accidentally damages the YAML format.
 

mtylerb

Well-Known Member
Nov 10, 2007
57
0
56
Warburg, AB, Canada
cPanel Access Level
Root Administrator
Seems it's easier than I thought. Used something similar to the following command in SSH:

Code:
perl -MYAML::Syck -e \ 'my $hr = YAML::Syck::LoadFile($ARGV[0]);$hr->{$ARGV[1]} = $ARGV[2];YAML::Syck::DumpFile($ARGV[0],$hr);' \/var/cpanel/userdata/user/user-domain.com ehip6 2607:5300:1:2:dead:beef:cafe:5
perl -MYAML::Syck -e \ 'my $hr = YAML::Syck::LoadFile($ARGV[0]);$hr->{$ARGV[1]} = $ARGV[2];YAML::Syck::DumpFile($ARGV[0],$hr);' \/var/cpanel/userdata/user/user-domain.com_SSL ehip6 2607:5300:1:2:dead:beef:cafe:5
Note, one is for the SSL file and the other is for the standard domain file. Then in the template vhost.local, I modified the VirtualHost line to show:

Code:
<VirtualHost[% FOREACH ipblock IN vhost.ips %] [% ipblock.ip %]:[% ipblock.port %][% END %] [% IF !vhost.ehip6 -%] [2607:5300:1:2:dead:beef:cafe:2]:80 [% ELSE -%] [[% vhost.ehip6 %]]:80[% END -%]>
and in the ssl_vhost.local file, I used:

Code:
<VirtualHost[% FOREACH ipblock IN vhost.ips %] [% ipblock.ip %]:[% ipblock.port %][% END %] [% IF !vhost.ehip6 -%] [2607:5300:1:2:dead:beef:cafe:2]:443 [% ELSE -%] [[% vhost.ehip6 %]]:443[% END -%]>
The IP address is a shared IP in the IF statement and is in there JUST in case I forgot to put one in their userdata files. Just to hold it over long enough for me to put it in place. I realize the SSL one will cause problems, being that it's a shared IP and all, but I figured something was better than nothing.

Now whenever cPanel rebuilds the httpd.conf file, it includes the IPv6 addresses in the VirtualHost declarations.