Sign in to follow this  
Followers 0
WiSp

IQN Generator

1 post in this topic

Here's a small simple script to generate proper iSCSI targets. There is nothing fancy in here, pretty basic stuff.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.6.1
 Author:         WiSp (See forum for contact info)

 Script Function: Generate IQN for iscsi targets

#ce ----------------------------------------------------------------------------

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

$iniFile="IQNGen.ini"

#Region ### START Koda GUI section ### Form=g:\docs\wps\docs and articles\autoit\guis\iqngen.kxf
$IQNGENGUI = GUICreate("IQN Gen", 419, 371, -1, -1)
$IQNTextBox = GUICtrlCreateInput("", 8, 24, 401, 21)
$DateTextBox = GUICtrlCreateInput("", 8, 72, 401, 21)
$DomainNameTextBox = GUICtrlCreateInput("", 8, 120, 401, 21)
$Target1Name = GUICtrlCreateInput("", 8, 168, 401, 21)
$Target2Name = GUICtrlCreateInput("", 8, 216, 401, 21)
$ResultTextBox = GUICtrlCreateInput("Press Generate IQN Button", 8, 344, 401, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))
$GenerateButton = GUICtrlCreateButton("Generate IQN", 8, 248, 401, 65, $WS_GROUP)
$ResultsLabel = GUICtrlCreateLabel("Your Generated IQN:", 8, 320, 104, 17)
$Label1 = GUICtrlCreateLabel("IQN (Don't Change This unless you know what you are doing):", 8, 7, 298, 17)
$Label2 = GUICtrlCreateLabel("Date You Took Control of This Domain (YYYY-MM):", 8, 54, 248, 17)
$Label3 = GUICtrlCreateLabel("Domain Name:", 8, 102, 74, 17)
$Label4 = GUICtrlCreateLabel("Target Name or OU Name:", 8, 150, 131, 17)
$Label5 = GUICtrlCreateLabel("Target Name if not Specified Above, otherwise leave blank:", 8, 198, 285, 17)

_InitINI()

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GenerateButton
            GUICtrlSetData($ResultTextBox,_GenerateIQN())
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd


Func _GenerateIQN()

    $TempArray = StringSplit(GuiCtrlRead($DomainNameTextBox),".")

    $ReverseDomain = ""

    For $i=$TempArray[0] to 1 Step -1
        $ReverseDomain = $ReverseDomain & "." & $TempArray[$i]
    Next

    If GUICtrlRead($Target2Name) == "" then
        $StringVar = GuiCtrlRead($IQNTextBox) & "." & GuiCtrlRead($DateTextBox) & $ReverseDomain & ":" & GuiCtrlRead($Target1Name)
    Else
        $StringVar = GuiCtrlRead($IQNTextBox) & "." & GuiCtrlRead($DateTextBox) & $ReverseDomain & ":" & GuiCtrlRead($Target1Name) & ":" & GuiCtrlRead($Target2Name)
    EndIf

    Return $StringVar

EndFunc


Func _InitINI()

    $TempIniVar = IniReadSection($iniFile,"Defaults")

    If @error Then
        MsgBox(4096, "", "Error occurred, probably no INI file.")
    Else
        For $i = 1 To $TempIniVar[0][0]
            Select
                Case $TempIniVar[$i][0] = "iqn"
                    If $TempIniVar[$i][1] == "" Then
                        GUICtrlSetData($IQNTextBox,"iqn")
                    Else
                        GUICtrlSetData($IQNTextBox,$TempIniVar[$i][1])
                    EndIf
                Case $TempIniVar[$i][0] = "DomainDate"
                    If $TempIniVar[$i][1] == "" Then
                        GUICtrlSetData($DateTextBox,@YEAR & "-" & @MON)
                    Else
                        GUICtrlSetData($DateTextBox,$TempIniVar[$i][1])
                    EndIf
                Case $TempIniVar[$i][0] = "DomainName"
                    If $TempIniVar[$i][1] == "" Then
                        GUICtrlSetData($DomainNameTextBox,"SAN.EXAMPLE.COM")
                    Else
                        GUICtrlSetData($DomainNameTextBox,$TempIniVar[$i][1])
                    EndIf
                Case $TempIniVar[$i][0] = "TargetName1"
                    If $TempIniVar[$i][1] == "" Then
                        GUICtrlSetData($Target1Name,"IT")
                    Else
                        GUICtrlSetData($Target1Name,$TempIniVar[$i][1])
                    EndIf
                Case $TempIniVar[$i][0] = "TargetName2"
                    If $TempIniVar[$i][1] == "" Then
                        GUICtrlSetData($Target2Name,"iSCSI-Target1")
                    Else
                        GUICtrlSetData($Target2Name,$TempIniVar[$i][1])
                    EndIf

            EndSelect
        Next
    EndIf


    If $TempIniVar == "" Then
        IniRead($iniFile,"Default","iqn","iqn")
    Else
        IniRead($iniFile,"Default","iqn","iqn")
    EndIf


EndFunc

IQNGenerator.zip

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0