Use serial number as hostname in Fog
-
@xinzo Sorry it was late in the day yesterday and I was only running on a few brain cells.
OK for #3 yes fog.man.reg is the manual registration script. That script is actually embedded into the FOS Linux OS that gets transferred to the target computer during imaging. But don’t worry about that. I have a tutorial here that kind of is the answer: https://forums.fogproject.org/topic/14278/creating-custom-hostname-default-for-fog-man-reg The script
fog.customhostname
is actually where most of the magic happens. There is more in this script than what you need because it first tries to determine where the computer is being installed at and prepends the site LUN code to the system name, second it also determines if the computer is a laptop or desktop and finally it reads the chassis serial number and then adds all of the strings together to make thehost_default_name
variable. That value then gets passed back to fog.man.reg to repopulate the system name in the field. You can still change it while you are in registration mode. But the default will be set to the formula I provided above. For your use case all you need to change is one line.this:
# default host name is returned to the fog.man.reg script host_default_name="$zsitecode$zchtype$zserialno";
to this
# default host name is returned to the fog.man.reg script host_default_name="$zserialno";
As for #2 you can find out more about that while reviewing these tutorials
https://forums.fogproject.org/topic/11126/using-fog-postinstall-scripts-for-windows-driver-injection-2017-ed
https://forums.fogproject.org/topic/8889/fog-post-install-script-for-win-driver-injection/2 -
I’ve try the #3 it works !
Thanks a lot
If I want to do this with Quick registration how to “fix” the fog.auto.reg ? -
@xinzo I have not looked into it but in theory its possible.
If we look at fog.man.reg: https://github.com/FOGProject/fos/blob/master/Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.man.reg at line 342 we see this registration.
while [[ -z $res ]]; do res=$(curl -Lks --data "sysuuid=${sysuuid}&mac=$mac&advanced=$(echo -n 1 | base64)&host=$host&imageid=$imageid&primaryuser=$primaryuser&other1=$other1&other2=$other2&doimage=$realdoimage&doad=$blDoAD&location=$location64&username=$user64&groupid=$group64&snapinid=$snapin64&productKey=$productKey" ${web}service/auto.register.php 2>/dev/null) echo "$res" usleep 2000000 done
If we look at fogl.auto.reg in line 76 we see this call for registration.
res=$(curl -Lks --data "sysserial=${sysserial}&sysuuid=${sysuuid}&mac=$mac&productKey=${productKey}" ${web}service/auto.register.php 2>/dev/null)
It looks like both are calling the same script on the fog server.
So one might wonder what would happen if we just passed the host variable to that script?
making it look like this:
res=$(curl -Lks --data "host=$host_default_name&sysserial=${sysserial}&sysuuid=${sysuuid}&mac=$mac&productKey=${productKey}" ${web}service/auto.register.php 2>/dev/null)
Then of course we need to set the variable
host_default_name
to something using ourfog.customhostname
script.Where we might want to call it here before the host is registered
productKey="" host_default_name="" if [[ -f "/bin/fog.customhostname" ]]; then . /bin/fog.customhostname fi if [[ -f /sys/firmware/acpi/tables/MSDM ]]; then productKey=$(tail -c+57 /sys/firmware/acpi/tables/MSDM | base64) fi
Understand I have not tested or debugged this at all. I only glued some code together to make spaghetti.
-
@george1421
I’ve try your solution but it’s not working.
I can’t understand why thefog.customhostname
only send thehost_default_name
to thefog.man.reg
Your proposition seems good to me. Maybe thehost
is not recognize for the quick registraton ?
Thanks for your help -
@xinzo I did see a small type-o in what I told you.
"host=$host_default_name&sysserial=${sysserial}&sysuuid=${sysuuid}
should have been
"host=${host_default_name}&sysserial=${sysserial}&sysuuid=${sysuuid}
Note the appropriate use of the curly braces.
What is it giving you for a host name a mac address or a sequential number like if you enabled auto numbering?
I did give you a caveat that I did no debugging or testing. This might not work, but once we know what its doing we can look.
-
@george1421 I did it too but nothing change.
I have the auto numbering as hostname (PC-*)@george1421 said in Use serial number as hostname in Fog:
I did give you a caveat that I did no debugging or testing. This might not work, but once we know what its doing we can look.
Yes no problem, always a pleasure to fix some issue and (try to) add some feature to this project.
-
@xinzo Looking into the FOG programming code. I see here: https://github.com/FOGProject/fogproject/blob/171d63724131c396029992730660497d48410842/packages/web/lib/reg-task/registration.class.php#L328
OK lets hack our way into a possible solution. Again the caveat here is I have not tried this so I have no clue if it works.
But at this location: https://github.com/FOGProject/fogproject/blob/171d63724131c396029992730660497d48410842/packages/web/lib/reg-task/registration.class.php#L328 Line #328 there is this section of code.
$autoRegSysName = trim($autoRegSysName); if (strtoupper($autoRegSysName) == 'MAC') { $hostname = $this->macsimple; } else { $hostname = $autoRegSysName; } $hostname = trim($hostname); if (!self::getClass('Host')->isHostnameSafe($hostname)) {
I wonder if we can tweak it to look like this
$autoRegSysName = trim($autoRegSysName); if (strtoupper($autoRegSysName) == 'MAC') { $hostname = $this->macsimple; } elseif (strtoupper($autoRegSysName) == 'SYSSERIAL') { $hostname = base64_decode($_REQUEST['host']); } else { $hostname = $autoRegSysName; } $hostname = trim($hostname); if (!self::getClass('Host')->isHostnameSafe($hostname)) {
Inserting this code
} elseif (strtoupper($autoRegSysName) == 'SYSSERIAL') { $hostname = base64_decode($_REQUEST['host']);
The file can be found here.
/var/www/html/fog/fog/lib/reg-task/registration.class.phpSo now if we turn on autoprop and set sys name to SYSSERIAL would it insert the hostname value we configured in the fog.auto.reg file?
-
@george1421
I have the MAC adress of the computer instead of the ‘PC-*’.
TheSYSSERIAL
is defined somewhere in the php script ? -
@xinzo said in Use serial number as hostname in Fog:
The SYSSERIAL is defined somewhere in the php script ?
I made that variable up for the hack to the script.
In this specific code section I look for the word
SYSSERIAL
} elseif (strtoupper($autoRegSysName) == 'SYSSERIAL') { $hostname = base64_decode($_REQUEST['host']);
So if the autoRegSysName (the field where you have MAC now or PC*) equals SYSSERIAL then remember in the previous steps you added the value
host
to the curl call in fog.auto.reg?, It will take the value ofhost
and assign it to the variable $hostname. Its a similar concept to the line above that looks for the word MAC and then assigns the mac address of the target computer to the $hostname variable. In the fog.auto.reg file you adjusted earlier the $host variable is created by the fog.customhost script, right. Its a bit of a complicated path but when all of the bits are in place it should give you the autonaming function as with the full registration process. -
@george1421
Okay I understand.
In myfog.auto.reg
the curl is sending to this script :${web}service/auto.register.php 2>/dev/null)
Maybe there’s something to do with this file ? -
@xinzo said in Use serial number as hostname in Fog:
auto.register.php
Yes that is the file you will edit on the FOG server itself. It should be in the path I provided previously. Now that I think about it I might want to change the auto prop value to CUSTOM instead of SYSSERIAL and then make a write up on this for those fog admins that want to create a custom auto name value. I always use the full registration on my campus so I never thought about the auto naming process. I think you are onto something that will be useful to other fog admins.
-
@george1421
I’ve done it !
The “old” fog.auto.reg is :if [[ -f "/bin/fog.customhostname" ]]; then . /bin/fog.customhostname fi if [[ -f /sys/firmware/acpi/tables/MSDM ]]; then productKey=$(tail -c+57 /sys/firmware/acpi/tables/MSDM | base64) fi while [[ -z $res ]]; do res=$(curl -Lks --data "host=${host_default_name}&sysserial=${sysserial}&sysuuid=${sysuuid}&mac=$mac&productKey=${productKey}" ${web}service/auto.register.php 2>/dev/null)
Here is the trick :
while [[ -z $res ]]; do host=${host_default_name} host=$(echo $host | base64) res=$(curl -Lks --data "host=$host&sysserial=${sysserial}&sysuuid=${sysuuid}&mac=$mac&productKey=${productKey}" ${web}service/auto.register.php 2>/dev/null)
We have to convert to base64 and then send to the script. It works like a charm.
I suceeded when I inspected the fog.man.reg.fix Here is what helped me :while [[ $res != "#!ok" ]]; do if [[ $host_default_name != "" ]]; then read -p " * Enter hostname for this computer [$host_default_name]: " host else read -p " * Enter hostname for this computer: " host fi host=${host:-$host_default_name} if [[ ${#host} -gt 15 ]]; then host=${host:0:15} echo " | Truncated to 15 characters: $host" usleep 2000000 fi host=$(echo $host | base64) res=$(curl -Lks --data "host=$host" ${web}service/hostnameloop.php 2>/dev/null) [[ $res != "#!ok" ]] && echo "$res" done
Those line
host=${host:-$host_default_name}
host=$(echo $host | base64)
res=$(curl -Lks --data "host=$host" ${web}service/hostnameloop.php 2>/dev/null)
Thank you very much for your help
-
@xinzo well done! Now just make sure you backup everything since you hacked the fog environment. That way when/if you upgrade you don’t lose your hacks. But really nice. I’m really more than willing to help someone help themselves success with FOG. This way you can get exactly what works for your situation.
-
Thanks
For people who want to do this. Don’t forget to set the QUICKREG SYS NAME in the FOG SETTINGS toSYSSERIAL
.
@george1421 Can I upload my file somewere for the people who want to implement the feature ? -
@xinzo If you want to post them here, I’ll rewrite the instructions as a tutorial and then provide a link to this thread. You might need to change the extension of the files to .txt so they can be uploaded. I can see other wanting this feature too. I know I personally missed it since the FOG v0.30 days.
-
@george1421
Here are my files, I’ve upload all the content of my postinitscripts folder:
fog.postinit.txt
fog.patch.customhostname.txt
fog.man.reg.fix.txt
fog.customhostname.txt
fog.auto.reg.txt@george1421 said in Use serial number as hostname in Fog:
I can see other wanting this feature too. I know I personally missed it since the FOG v0.30 days.
Without you, impossible to implement this feature. Thanks a lot