[SCRIPTS] Customization of Ubuntu - "Fog Service" for Ubuntu
-
@Junkhacker said:
is there a reason you chose to use a mysql query instead of using the built in mechanism of an http request to
<fog-ip>/fog/service/hostname.php?mac=f8:bc:12:6e:67:78&newService=0
using the http request, you wouldn’t need to utilize database credentials
Maybe he likes to live dangerously.
-
@cspence When I’ve wrote that script I only used FOG Database… But to minimize security problem I’ve created a read only mysql user.
If you can help me than @Junkhacker to optimize my script or create a FOG client for Linux, you are welcome lol.@Junkhacker I’m trying to optimize security (I’ve discover service/class files on fog since 2/3 months), I’ll post a “FOG client” for linux (Redhat/Debian based during this month)
-
@ch3i Wow you have been busy, very nice work!
-
@Junkhacker said:
is there a reason you chose to use a mysql query instead of using the built in mechanism of an http request to
<fog-ip>/fog/service/hostname.php?mac=f8:bc:12:6e:67:78&newService=0
using the http request, you wouldn’t need to utilize database credentials
Hi,
I’ve tested with hostname.php it’s functional but very long…
Why there is a sleep during 10 seconds ?
sleep(10); // Make system wait ten seconds before sending data
-
@ch3i the sleep is an attempt to give the client system, booted into windows, a kind of delay so winmgmt has to to start up.
-
@Tom-Elliott Ok
-
@Tom-Elliott said:
@ch3i the sleep is an attempt to give the client system, booted into windows, a kind of delay so winmgmt has to to start up.
It’s possible to change
sleep(10)
with something like that :$_REQUEST['delay'] ? sleep($_REQUEST['delay']) : sleep(10);
To specify delay using that :
<fog-ip>/fog/service/hostname.php?mac=f8:bc:12:6e:67:78&newService=0&delay=3
-
Sleep on hostname.php is removed, I’ll try to post a version with hostname.php instead MySQL request.
-
@ch3i said:
Sleep on hostname.php is removed, I’ll try to post a version with hostname.php instead MySQL request.
IMHO, I’d say leave it as a request to MySQL. FOG 2.0 will not use PHP, it’ll use nodeJS and any PHP-based scripts out there will then stop working with FOG 2.0.
-
@Wayne-Workman said:
@ch3i said:
Sleep on hostname.php is removed, I’ll try to post a version with hostname.php instead MySQL request.
IMHO, I’d say leave it as a request to MySQL. FOG 2.0 will not use PHP, it’ll use nodeJS and any PHP-based scripts out there will then stop working with FOG 2.0.
I know But I think in FOG 2.0 we have a linux client
-
@ch3i True, true. @Jbob says that the client complies and runs fine on Linux… which is pretty amazing.
-
@Jbob said:
2.0? At the rate I’m going I’ll have Linux and Mac released for 1.3.0
Cool, with 2.0 we have an Android/iOS client ?
-
Update host_rename_fog :
- Add the “dots” function used in FOG scripts like the installer (more sexy lol)
- Checking Mysql status
- Update MAC/Hostname checking (a better compatibility with multiple eth cards)
To use that script please create a user in mysql database with select right only on tables : hosts and hostMAC !
-
@ch3i said:
Sleep on hostname.php is removed, I’ll try to post a version with hostname.php instead MySQL request.
@Tom-Elliott It seem to be back
-
Below the version without using mysql :
#!/bin/bash ######################################################### # Rename services with FoG, need mysql-client installed ######################################################### # ch3i - 09/11/2015 ######################################################### ### BEGIN INIT INFO # Provides: rename_host_fog # Required-Start: $all # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Rename host at boot-shutdown # Description: Rename host using FoG ### END INIT INFO ######################################################### # Functions ######################################################### FUNC_DOTS() { max=65 if [ -n "$1" ]; then n=`expr $max - ${#1}` echo -n " * ${1:0:max}" if [ "$n" -gt 0 ]; then for i in $(seq $n); do printf %s . done fi fi } ######################################################### # Configuration ######################################################### FOG_SERVER="ip_of_server" FOG_WEBROOT="fog" ######################################################### # Check FOG Server Status ######################################################### FUNC_DOTS "Check FOG web service Status" wget "http://$FOG_SERVER/$FOG_WEBROOT/index.php" -t 1 2>/dev/null if [ $? -eq 0 ] then echo "Done" ######################################################### # Get interfaces ######################################################### NETWORK_CARDS=($(ls /sys/class/net | grep eth)) ######################################################### # Get host name and domain from FoG database ######################################################### FUNC_DOTS "Checking hostname/domain configurations" for ETH in ${NETWORK_CARDS[*]} do # read mac address MAC=$(cat /sys/class/net/$ETH/address) # get mac address information from fog web server wget http://$FOG_SERVER/$FOG_WEBROOT/service/hostname.php?mac=$MAC -O /tmp/hostname_check 2>/dev/null HOST_NAME="$(grep 'ok=' /tmp/hostname_check | cut -d "=" -f2)" HOST_DOMAIN_NAME="$(grep 'ADDom' /tmp/hostname_check | cut -d "=" -f2)" if [ "$HOST_NAME" != "" ] then echo "Done ($HOST_NAME.$HOST_DOMAIN_NAME)" sleep 3 # A hostname is found - quit the loop break else echo "Error" FUNC_DOTS "Host not found in FOG database" echo "exiting" sleep 3 exit fi done ######################################################### # Check host configuration ######################################################### ACTUAL_FQDN=$(hostname --fqdn) if [ "$HOST_NAME.$HOST_DOMAIN_NAME" != "$ACTUAL_FQDN" -a "$HOST_NAME" != "" -a "$HOST_DOMAIN_NAME" != "" ] then ######################################################### # Update hostname file ######################################################### FUNC_DOTS "Updating /etc/hostname" echo $HOST_NAME >/etc/hostname echo "Done" ######################################################### # Update hosts file ######################################################### FUNC_DOTS "Updating /etc/hosts" echo "127.0.0.1 localhost" > /etc/hosts echo "127.0.1.1 $HOST_NAME.$HOST_DOMAIN_NAME $HOST_NAME " >> /etc/hosts echo "# The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts" >> /etc/hosts echo "Done" ######################################################### # Update interfaces file ######################################################### FUNC_DOTS "Updating /etc/network/interfaces" echo "# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback" > /etc/network/interfaces for ETH in ${NETWORK_CARDS[*]} do if [ "$ETH" != "lo" ] then echo "# $ETH Interface allow-hotplug $ETH iface $ETH inet dhcp" >> /etc/network/interfaces fi done echo "Done" ######################################################### # Clear persistent network cards ######################################################### FUNC_DOTS "Clearing persistent networks cards" if [ -f /etc/udev/rules.d/70-persistent-net.rules ] then rm /etc/udev/rules.d/70-persistent-net.rules fi echo "Done" ######################################################### # Logs and Reboot machine ######################################################### FUNC_DOTS "Building rename logs" echo "$(date) ::: Update successful with Hostname : $HOST_NAME and Domain : $HOST_DOMAIN_NAME" >> /var/log/rename_host_fog.log echo "Done" grub-reboot 0 /sbin/init 6 exit fi if [ "$HOST_NAME" == "" -a "$HOST_DOMAIN_NAME" == "" ] then echo "$(date) ::: Update failed : Failed to connect to Mysql Server" >> /var/log/rename_host_fog.log fi if [ "$HOST_NAME" != "" -a "$HOST_DOMAIN_NAME" == "" ] then echo "$(date) ::: Update failed : Domain name is missing" >> /var/log/rename_host_fog.log fi else echo "Error" FUNC_DOTS "Failed to connect to server" echo "Exiting" sleep 3 exit fi exit
More slow because 10 seconds timeout in hostname.php request.