Jump to content

Redirect Page Creator


nf67
 Share

Recommended Posts

Posted Image

Click the image to download the .exe (32-bit)

Source:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FTPEx.au3>

$GUI = GUICreate("RD", 150, 160, @DesktopWidth/2 - 75, @DesktopHeight/2 - 80)
$FileNameInput = GUICtrlCreateInput("Filename", 0, 0, 150, 20)
$TitleInput = GUICtrlCreateInput("Page Title", 0, 20, 150, 20)
$URLInput = GUICtrlCreateInput("URL", 0, 40, 150, 20)

$ServerInput = GUICtrlCreateInput("FTP Server   (optional)", 0, 60, 150, 20)
$AccountInput = GUICtrlCreateInput("FTP Username    (optional)", 0, 80, 150, 20)
$PasswordInput = GUICtrlCreateInput("FTP Password   (optional)", 0, 100, 150, 20)
$DirInput = GUICtrlCreateInput("Directory   (optional)", 0, 120, 150, 20)

$GenerateButton = GUICtrlCreateButton("Generate", 0, 140, 75, 20)
$ResetButton = GUICtrlCreateButton("Reset", 75, 140, 38, 20)
$HelpButton = GUICtrlCreateButton("Help", 113, 140, 37, 20)
GUISetState(@SW_SHOW)

$EmptyCount = 0
$HelpGUI = ""

While 1
    $MSG = GUIGetMsg(1)
    Switch $MSG[1]
        Case $GUI
            Switch $MSG[0]
            Case $GUI_EVENT_CLOSE
                Exit
            Case $GenerateButton
                Generate()
            Case $ResetButton
                ResetFields()
            Case $HelpButton
                Help()
            EndSwitch
        Case $HelpGUI
            Switch $MSG[0]
            Case $GUI_EVENT_CLOSE
                GUIDelete($HelpGUI)
            EndSwitch
    EndSwitch
WEnd

Func Generate()
    If GUICtrlRead($FileNameInput) = "" Then
        $EmptyCount=$EmptyCount+1
    EndIf
    If GUICtrlRead($TitleInput) = "" Then
        $EmptyCount=$EmptyCount+1
    EndIf
    If GUICtrlRead($URLInput) = "" Then
        $EmptyCount=$EmptyCount+1
    EndIf

    If $EmptyCount <> 0 Then
        MsgBox(0,"Error","You need to fill in the first 3 fields concerning the (local) file.")
        $EmptyCount = 0
    Else

        If FileExists(@DesktopDir & "\" & GUICtrlRead($FileNameInput))=1 Then
            $AlreadyExists = MsgBox(4,"File already exists","Overwrite?")
                If $AlreadyExists=6 Then
                    $FileDelete = FileDelete(@DesktopDir & "\" & GUICtrlRead($FileNameInput))
                    If $FileDelete = 0 Then
                        MsgBox(0,"Error","The file could not be deleted, therefore no new file can be created.")
                    Else
                        CreateFile()
                    EndIf
                EndIf
        Else
                CreateFile()
        EndIf
    EndIf
EndFunc

Func CreateFile()
    $File = @DesktopDir & "\" & GUICtrlRead($FileNameInput)
    $FileWrite = FileWriteLine($File, "<html><head>")
    If $FileWrite = 0 Then
        MsgBox(0,"Error","The file could not be created.")
    Else
        FileWriteLine($File, "<title>" & GUICtrlRead($TitleInput) & "</title>")
        FileWriteLine($File, "<meta http-equiv=""Refresh"" content=""0; url=" & GUICtrlRead($URLInput) & """>")
        FileWriteLine($File, "</head><body>")
        FileWriteLine($File, "</body></html>")

        $FTPquestion = MsgBox(4,"File Created","The file has been added to your desktop." & @CRLF &"Do you wish to upload the file to your server via FTP? If the file already exists in the directory you specified then it will be overwritten.")
        If $FTPquestion = 6 Then
            Upload()
        EndIf
    EndIf
EndFunc

Func Upload()
    $FTPOpen = _FTP_Open("Redirect FTP")
    $FTPConnect = _Ftp_Connect($FTPOpen,GUICtrlRead($ServerInput),GUICtrlRead($AccountInput),GUICtrlRead($PasswordInput))
    If $FTPConnect = 0 Then
        MsgBox(0,"Error","Couldn't connect.")
    Else
        $DirCreate = _FTP_DirCreate($FTPConnect, "/httpdocs/" & GUICtrlRead($DirInput))
        If $DirCreate = 0 Then
            MsgBox(0,"Error","Despite a succesful connection, the directory you specified couldn't be created, therefore the file couldn't be put on the server.")
        Else
            $FilePut = _FTP_FilePut($FTPConnect,@DesktopDir & "\" & GUICtrlRead($FileNameInput), "/httpdocs/" & GUICtrlRead($DirInput) & "/" & GUICtrlRead($FileNameInput))
            If $FilePut = 0 Then
                MsgBox(0,"Error", "Despite a succesful connection and the creation of the directory you specified, the file couldn't be put in there.")
            Else
                _FTP_Close($FTPOpen)
                MsgBox(0,"Success","Upload complete.")
            EndIf
        EndIf
    EndIf
EndFunc

Func ResetFields()
    GUICtrlSetData($FileNameInput, "Filename")
    GUICtrlSetData($TitleInput, "Page Title")
    GUICtrlSetData($URLInput, "URL")

    GUICtrlSetData($ServerInput, "FTP Server    (optional)")
    GUICtrlSetData($AccountInput, "FTP Username (optional)")
    GUICtrlSetData($PasswordInput, "FTP Password    (optional)")
    GUICtrlSetData($DirInput, "Directory    (optional)")
EndFunc

Func Help()
    $MainGUILoc = WinGetPos("RD")
    $HelpGUI = GUICreate("Help", 300, 160, $MainGUILoc[0] + 150 + 20, $MainGUILoc[1])
    $TextBox = GUICtrlCreateEdit("", 0, 0, 300, 160, $WS_VSCROLL + $ES_ReadOnly)
    GUICtrlSetData($TextBox, "RD can create redirect pages which will take the user from your page to another. If you want, they can be uploaded to your server via FTP and placed in a folder in /httpdocs/ right away. " & _
            "As a result, users will be redirected to the page you specify when they visit www.yoursite.com/folder . The input fields will be explained below, followed by an (example) between brackets." & @CRLF & @CRLF & _
            "FILENAME: The name of the redirecting file which will be created and placed on your desktop. (index.html)" & @CRLF & @CRLF & _
            "PAGE TITLE: The title of of your redirecting page, this will only be visible while the user is being redirected, which should take less than half a second. (Redirecting...)" & @CRLF & @CRLF & _
            "URL: The page to redirect the user to. (http://www.google.com)" &@CRLF &@CRLF &@CRLF &@CRLF & _
            "The following information is only required if you want to upload your file to your server using this program:" & @CRLF &@CRLF & _
            "FTP SERVER: The server to connect to. (ftp.example.com)" & @CRLF & @CRLF & _
            "FTP USERNAME: Your account name, the server will verify if your account details are valid. (yourname)" & @CRLF & @CRLF & _
            "FTP PASSWORD: The password of your FTP account. (password123)" & @CRLF & @CRLF & _
            "DIRECTORY: The folder in /httpdocs/ on the server where your file will be placed, exclude slashes.")
    GUISetState(@SW_SHOW)
EndFunc
Link to comment
Share on other sites

nf67,

I see where this is going, but there are a couple of things wrong with it.

The folder in /httpdocs/

Actually, the folders are usually called /htdocs or /public_html on most servers, mainly Linux, however XAMPP uses htdocs, likewise so does Abyss.

To redirect pages your using a META tag. If you want your site to remain SEO friendly, then using .htaccess with a 301 redirection is preferred by search engines.

Other than that? Not bad!

James

Link to comment
Share on other sites

Thank you for your reply, I might add a radio or something to select what the default folder is. However, since this was for personal use, I didn't (yet) include any options which I wouldn't use myself :(

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...