• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    [SCRIPTS] Customization of Ubuntu - "Fog Service" for Ubuntu

    Scheduled Pinned Locked Moved
    General
    5
    20
    10.8k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JunkhackerJ
      Junkhacker Developer
      last edited by Junkhacker

      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

      signature:
      Junkhacker
      We are here to help you. If you are unresponsive to our questions, don't expect us to be responsive to yours.

      cspenceC ch3iC 2 Replies Last reply Reply Quote 1
      • cspenceC
        cspence Developer @Junkhacker
        last edited by

        @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. 😎

        ch3iC 1 Reply Last reply Reply Quote 1
        • ch3iC
          ch3i Moderator @cspence
          last edited by

          @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)

          Wayne WorkmanW 1 Reply Last reply Reply Quote 1
          • Wayne WorkmanW
            Wayne Workman @ch3i
            last edited by

            @ch3i Wow you have been busy, very nice work!

            Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
            Daily Clean Installation Results:
            https://fogtesting.fogproject.us/
            FOG Reporting:
            https://fog-external-reporting-results.fogproject.us/

            1 Reply Last reply Reply Quote 0
            • ch3iC
              ch3i Moderator @Junkhacker
              last edited by

              @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
              
              Tom ElliottT 1 Reply Last reply Reply Quote 0
              • Tom ElliottT
                Tom Elliott @ch3i
                last edited by

                @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.

                Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

                Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                ch3iC 2 Replies Last reply Reply Quote 0
                • ch3iC
                  ch3i Moderator @Tom Elliott
                  last edited by

                  @Tom-Elliott Ok

                  1 Reply Last reply Reply Quote 0
                  • ch3iC
                    ch3i Moderator @Tom Elliott
                    last edited by

                    @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
                    
                    1 Reply Last reply Reply Quote 0
                    • ch3iC
                      ch3i Moderator
                      last edited by

                      Sleep on hostname.php is removed, I’ll try to post a version with hostname.php instead MySQL request.

                      Wayne WorkmanW ch3iC 2 Replies Last reply Reply Quote 0
                      • Wayne WorkmanW
                        Wayne Workman @ch3i
                        last edited by

                        @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.

                        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                        Daily Clean Installation Results:
                        https://fogtesting.fogproject.us/
                        FOG Reporting:
                        https://fog-external-reporting-results.fogproject.us/

                        ch3iC 1 Reply Last reply Reply Quote 0
                        • ch3iC
                          ch3i Moderator @Wayne Workman
                          last edited by

                          @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 😄 😄

                          Wayne WorkmanW 1 Reply Last reply Reply Quote 0
                          • Wayne WorkmanW
                            Wayne Workman @ch3i
                            last edited by

                            @ch3i True, true. @Jbob says that the client complies and runs fine on Linux… which is pretty amazing.

                            Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG!
                            Daily Clean Installation Results:
                            https://fogtesting.fogproject.us/
                            FOG Reporting:
                            https://fog-external-reporting-results.fogproject.us/

                            1 Reply Last reply Reply Quote 0
                            • ch3iC
                              ch3i Moderator
                              last edited by

                              @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 ? 😛

                              1 Reply Last reply Reply Quote 1
                              • ch3iC
                                ch3i Moderator
                                last edited by

                                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 !

                                1 Reply Last reply Reply Quote 1
                                • ch3iC
                                  ch3i Moderator @ch3i
                                  last edited by ch3i

                                  @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

                                  1 Reply Last reply Reply Quote 0
                                  • ch3iC
                                    ch3i Moderator
                                    last edited by

                                    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.

                                    1 Reply Last reply Reply Quote 0
                                    • 1 / 1
                                    • First post
                                      Last post

                                    172

                                    Online

                                    12.0k

                                    Users

                                    17.3k

                                    Topics

                                    155.2k

                                    Posts
                                    Copyright © 2012-2024 FOG Project