Jump to content

AdminDB ( Administrative Database )


themax90
 Share

Recommended Posts

Here is just a little history of AutoIt ITS :

http://www.autoit-its.com/autoit-its/forum...wtopic.php?t=29

AutoIt ITS is a TCP/IP project based on AutoIt and the original file-based originals that were rough hardcode by Nuffilein805 whos real name is Marten Zimmermann.

http://www.autoitscript.com/forum/index.ph...topic=17275&hl=

Since the original idea came to my notice I was immediatly facinated at the possiblities in front of me and I set out to work. AutoIt ITS has been through MANY MANY changes, from experimental files, to HUGE lists of changes, additions, and fixes on file-based versions, and now an ALL INTERNAL version.

INTRODUCING ........ Administrative Database ( AdminDB ) !!!!!!!!!!!!!!!!

Project Name : Adminstrative DataBase (AdminDB)
Author : Max Gardner (AutoIt Smith;king.of.all@comcast.net)

The original idea was too make a linked database too control passwords and usernames, authentication codes and UID strings. The goal in this is too make a program like MySQL, that operates on a TCP interface, that allows queries too an all internal memory database. The idea behind a memory database is simple. In the event someone hacks your server, they cannot retreive passwords or data simply because it is stored INSIDE the excutable mainframe and can only be retreived by an adminstrative dump or authorized query.

In the actual event of a crash all memory and data is encrypted too a preset admin password allowing recovery of the data. This ensures that the database cannot be hacked, and the data cannot be retreived by ANYONE but the operator/administrator.

AdminDB receives strings from an Authorized client and saves it as a variable, so it cannot be recovered through files. In the event of a crash a pre-set Administrative Password will encrypt all data to a .dat file so it cannot be retreived except for by the Executable program and Administrators Only.

I am not sure this is perfect, but here is the files.

AdminDB v1.0

How it is utilized :

; ================================================
; This database server will interface with the actual server to store data
; and variable values that must be kept private from other sources. All data
; sent within the stream functions is mirrored back to the connection. Below
; is a list of stream functions to interface with AdminDB. You can log into it at
; port 3346 on the host ipaddress and converse with it using Hex.
; ================================================
; Server Stream Functions ( Documented only for building a client ) :
; ~login-admin-PASS - Login under user Admin with the proper password
; ~createvalue-VarName-Value - Creates a variable with the value
; ~setvalue-VarName-Value - Sets a created variable with a new value
; ~getvalue-VarName - Retreives and sends the created variables value
; ================================================

Here is the code. Very IMPORTANT. Converse with this server using HEX.

; ============================================================================
; AutoIt Version : 3.1.1.98
; Author :      Max Gardner(AutoIt Smith;king.of.all@comcast.net)
; Description :
;   This is the AutoIt ITS AdminDB v1.0 which is it's very first release!
; This database server will interface with the actual server to store data
; and variable values that must be kept private from other sources. All data
; sent within the stream functions is mirrored back to the connection. Below
; is a list of stream functions to interface with AdminDB.
; ============================================================================
#Include <Array.au3>
#Include <File.au3>
#Include <String.au3>
Global $SpoolValues[1]
Global $SpoolNames[1]
Global $SpoolFile = "Spool.dat"
Global Const $AdminPassword = "Password"
If FileExists($SpoolFile) = 1 Then
    Local $Lines = _FileCountLines($SpoolFile)
    Local $Track = 1
    For $Track = 1 To $Lines Step 1
        $Data = _HexToString(FileReadLine($SpoolFile, $Track))
        $Data = StringSplit($Data, " = ", 1)
        Assign($Data[1], $Data[2])
        _ArrayAdd($SpoolNames, $Data[1])
        _ArrayAdd($SpoolValues, $Data[2])
    Next
    FileDelete("Spool.txt")
EndIf
Global Const $Port = 3346
Global $MaxConc = 100
Global $MainSocket = TCPStartServer ($Port, $MaxConc)
If @error <> 0 Then Exit MsgBox(16, "Error", "Server unable to initialize.")
Global Const $MaxLength = 512
Global $ConnectedSocket[$MaxConc]
Global $Authority[$MaxConc]
Global $CurrentSocket = 0
If IsDeclared("Track") = 0 Then Local $Track = 0
Global Const $MaxConnection = ($MaxConc - 1)
For $Track = 0 To $MaxConnection Step 1
    $ConnectedSocket[$Track] = -1
    $Authority[$Track] = -1
Next
While 1
    $ConnectedSocket[$CurrentSocket] = TCPAccept($MainSocket)
    If $ConnectedSocket[$CurrentSocket] <> - 1 Then $CurrentSocket = SocketSearch()
    $Track = 0
    For $Track = 0 To $MaxConnection Step 1
        Select
        Case $ConnectedSocket[$Track] <> - 1
            $Data = TCPRecv($ConnectedSocket[$Track], $MaxLength)
            If $Data <> "" Then $Data = _HexToString ($Data)
            Select
                Case $Authority[$Track] = 1
                Select
                    Case $Data = "~bye"
                        TCPCloseSocket($ConnectedSocket[$Track])
                        $ConnectedSocket[$Track] = -1
                        $CurrentSocket = SocketSearch ()
                    Case $Data = "~update"
                        Sleep(1000)
                        $Track2 = 1
                        For $Track2 = 1 To (UBound($SpoolNames) - 1) Step 1
                            TCPSendMessage ($ConnectedSocket[$Track], $SpoolNames[$Track2] & " = " & $SpoolValues[$Track2])
                            Sleep(100)
                        Next
                    Case StringInStr($Data, "~createvalue") >= 1
                        $String = StringSplit($Data, "-")
                        Select
                            Case $String[0] = 3
                                Select
                                    Case _ArraySearch ($SpoolNames, $String[2]) = -1
                                        Assign($String[2], $String[3])
                                        _ArrayAdd($SpoolNames, $String[2])
                                        _ArrayAdd($SpoolValues, $String[3])
                                        TCPSendMessage ($ConnectedSocket[$Track], $String[2] & " = " & Eval($String[2]))
                                    Case Else
                                        TCPSendMessage ($ConnectedSocket[$Track], "Variable " & $String[2] & " has already been created.")
                                EndSelect
                            Case Else
                                TCPSendMessage ($ConnectedSocket[$Track], "Invalid Syntax.")
                        EndSelect
                    Case StringInStr($Data, "~getvalue") >= 1
                        $String = StringSplit($Data, "-")
                        $Search = _ArraySearch ($SpoolNames, $String[2])
                        Select
                            Case $String[0] = 2 And $Search <> - 1
                                TCPSendMessage ($ConnectedSocket[$Track], $String[2] & " = " & Eval($String[2]))
                            Case $String[0] <> 2
                                TCPSendMessage ($ConnectedSocket[$Track], "Invalid Syntax.")
                            Case Else
                                TCPSendMessage ($ConnectedSocket[$Track], "Variable " & $String[2] & " is not a created variable.")
                        EndSelect
                    Case StringInStr($Data, "~setvalue") >= 1
                        $String = StringSplit($Data, "-")
                        Select
                        Case $String[0] = 3
                            $Search = _ArraySearch ($SpoolNames, $String[2])
                                Select
                                    Case $Search <> - 1
                                        $SpoolValues[$Search] = $String[3]
                                        Assign($String[2], $String[3])
                                        TCPSendMessage ($ConnectedSocket[$Track], $String[2] & " = " & $String[3])
                                    Case Else
                                        TCPSendMessage ($ConnectedSocket[$Track], $String[2] & " is not a created variable.")
                                EndSelect
                            Case Else
                                TCPSendMessage ($ConnectedSocket[$Track], "Invalid Syntax.")
                        EndSelect
                    Case $Data <> ""
                        TCPSendMessage ($ConnectedSocket[$Track], "Unknown Function/Syntax")
                    EndSelect
                Case StringInStr($Data, "~login") >= 1
                    $String = StringSplit($Data, "-")
                    Select
                    Case $String[2] = "admin" And $String[3] = $AdminPassword
                        $Authority[$Track] = 1
                        TCPSendMessage($ConnectedSocket[$Track], "Connection Authorized.")
                    Case Else
                        TCPSendMessage($ConnectedSocket[$Track], "Connection Not Authorized.")
                    EndSelect
                Case $Data <> ""
                    TCPSendMessage($ConnectedSocket[$Track], "You do not have authority.")
                EndSelect
        EndSelect
    Next
WEnd
Func OnAutoItExit ()
    Local $Track = 0
    For $Track = 0 To ($MaxConc - 1) Step 1
        If Eval("ConnectedSocket[" & $Track & "]") <> - 1 And @error = 0 Then TCPCloseSocket($ConnectedSocket[$Track])
    Next
    TCPCloseSocket($MainSocket)
    TCPShutdown()
    FileDelete($SpoolFile)
    Local $Track = 1
    For $Track = 1 To (UBound($SpoolValues) - 1) Step 1
        FileWriteLine($SpoolFile, _StringToHex($SpoolNames[$Track] & " = " & $SpoolValues[$Track]))
    Next
EndFunc ;==>OnAutoItExit
Func SocketSearch ()
    Local $Track = 0
    For $Track = 0 To $MaxConnection Step 1
        Select
            Case $ConnectedSocket[$Track] = -1
                Return $Track
            Case Else
        ; Socket In Use
        EndSelect
    Next
EndFunc ;==>SocketSearch
Func TCPSendMessage ($Socket, $String)
    TCPSend($Socket, _StringToHex ($String))
EndFunc ;==>TCPSendMessage
Func TCPStartServer ($Port, $MaxConnect = 1)
    Local $Socket
    $Socket = TCPStartup()
    Select
        Case $Socket = 0
            SetError(@error)
            Return -1
    EndSelect
    $Socket = TCPListen(@IPAddress1, $Port, $MaxConnect)
    Select
        Case $Socket = -1
            SetError(@error)
            Return 0
    EndSelect
    SetError(0)
    Return $Socket
EndFunc ;==>TCPStartServer

You can use this to communicate:

; ----------------------------------------------------------------------------
; AutoIt Version: 3.1.1.98
; Author:       Max Gardner(AutoIt Smith;king.of.all@comcast.net)
; Script Function:
;   Manual (non-automated) AdminDB Client
; ----------------------------------------------------------------------------
#include <GuiConstants.au3>
#include <GuiEdit.au3>
#include <Misc.au3>
#Include <String.au3>
TCPStartup()
$MainSocket = TCPConnect(@IpAddress1, 3346)
If $MainSocket = -1 Then Exit MsgBox(0, "Error", "Could Not Connect or Bad Connection")
GUICreate("Server Client", 390, 210)
$Send = GUICtrlCreateEdit("", 10, 10, 175, 150, $WS_VSCROLL)
Local $History = GUICtrlCreateEdit("Server Messages:", 200, 10, 175, 150, BitOR($WS_VSCROLL, $ES_READONLY))
$SButton = GUICtrlCreateButton("Send", 145, 165, 100, 35)
GUISetState()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then
        Exit
    ElseIf $msg = $SButton Or _IsPressed ("0D") = 1 Then
        $Text = GUICtrlRead($Send)
        $TCPSent = TCPSend($MainSocket, _StringToHex ($Text))
        GUICtrlSetData($Send, "")
    EndIf
    $Recv = TCPRecv($MainSocket, 512)
    If $Recv <> "" Then $Recv = _HexToString ($Recv)
    If $Recv <> "" Then
        GUICtrlSetData($History, GUICtrlRead($History) & @CRLF & $Recv)
        _GUICtrlEditLineScroll ($History, 0, _GUICtrlEditGetLineCount ($History))
    EndIf
WEnd
Func OnAutoItExit()
    TCPCloseSocket($MainSocket)
    TCPShutdown()
EndFunc  ;==>OnAutoItExit

This is to be revamped and user-oriented into a GUI.

I hope you all will like this.

- AutoIt Smith

Edited by AutoIt Smith
Link to comment
Share on other sites

  • 11 months later...
  • 6 months later...

I'm surprised no one replied to this. This is brilliant!

I just found it! Over 6 months later...

I am a bit worried if on the server the power is shutdown immediately. AutoIt will have no time to write the data into a file, does that mean it is lost forever? Because for a big server, losing all data forever is not an option.

You know, I was just thinking that and I had 2 thoughts.

1. You could randomly or at set intervals write to disk in the same fashion as the emergency shutdown procedure does.

However, I guess that defeats the purpose of it being stored as a variable. Which brings me to my next point...

2. This is not suitable for a large-scale application. It is a marvelous little utility, but would not work inside of a user-heavy network. Or hell, it might, but it could not be depended upon.

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