Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Using Vb To create .htaccess , Should be simple

NygodNygod Member Posts: 20
[b][red]This message was edited by Nygod at 2002-10-28 7:16:11[/red][/b][hr]
a friend of mine has some problems with .htaccess files for his site so i thought it
would be a good idea if i made something simple that will just add an ip to an existing list
After giving it some thought, there are some things i dont know.

First question
How would i open an existing file into a listbox (listbox1)

Second question
How would i Take listbox2 and add "deny from " before all of the Ip addresses on export?
i.e.

deny from bad person 1
deny from bad person 2
deny from bad person 3

i would expect it to be similar to exporting .html files from VB. However i wanted to get some advice from people who know what they are doing before attempting this project


Comments

  • DarQDarQ Member Posts: 1,625
    : [b][red]This message was edited by Nygod at 2002-10-28 7:16:11[/red][/b][hr]
    I use .HTACCESS in my professional hours with PHP. And it should NOT be loaded into a listbox at all. Simply because the format is not suitable for that.
    But hey, i don't see the problem at all? I never use that in my .HTACCESS files??

    BTW: those files are just plain text files and can be loaded very simple by using open for input and line input #1,string



    :
    : First question
    : How would i open an existing file into a listbox (listbox1)
    :
    : Second question
    : How would i Take listbox2 and add "deny from " before all of the Ip addresses on export?
    : i.e.
    :
    : deny from bad person 1
    : deny from bad person 2
    : deny from bad person 3
    :
    : i would expect it to be similar to exporting .html files from VB. However i wanted to get some advice from people who know what they are doing before attempting this project
    :
    :
    :

    [HR]
    Gadver, ik wot ha'k hjir no wr?
    [HR]

    [GREEN]Anyone cares to translate?[/GREEN]

  • DjSpiritDjSpirit Member Posts: 371
    [CODE]Enum enPLErr
    [No Error] = 0
    [File Not Found] = 1
    [File Empty] = 2
    End Enum

    Function PopulateList(obList as ListBox, ByVal stFileName As String) As enPLErr
    Dim inFNum As integer, inFLen as integer, stFCont
    Dim vaList As Variant, vaTmp As Variant
    PopulateList = [No Error]

    'Check if the file exist
    If (Dir(stFileName) <> stFileName Then
    PopulateList = [File Not Found]
    Exit Function
    End If

    'Open the file and get the contents
    inFNum = FreeFile
    Open stFileName For Binary As inFNum
    'check if file is empty
    inFLen = FileLen("MyFile.lst")
    If inFLen = 0 Then
    PopulateList = [File Empty]
    Close inFNum
    Exit Function
    End If
    Get inFNum, inFLen, stFCont
    'close the file
    Close inFLen

    'split the contents of the file and add them to the list
    vaList = Split(stFCont, vbCrLf)
    If IsArray(vaList) Then
    For Each vaTmp In vaList
    obList.AddItem vaTmp
    Next
    Else
    obList.AddItem vaList
    End If
    End Function[/CODE][GREY]I think this should work to read a CrLf delimited list and stuff it in a listbox, but I don't have Visual Basic on this computer so I'm not sure if it works, anyway, I don't have time to write the code for writing the file from the listbox to the disk but I can tell you that you have to loop through the listbox and add each item and a vbCrLf to a string and then open the file for output and Print # the string to the file.

    DjSpirit, feeling helpful today, probably inspired by a LAN party and 80Gb of extra diskspace[/GREY]

    : a friend of mine has some problems with .htaccess files for his site so i thought it
    : would be a good idea if i made something simple that will just add an ip to an existing list
    : After giving it some thought, there are some things i dont know.
    :
    : First question
    : How would i open an existing file into a listbox (listbox1)
    :
    : Second question
    : How would i Take listbox2 and add "deny from " before all of the Ip addresses on export?
    : i.e.
    :
    : deny from bad person 1
    : deny from bad person 2
    : deny from bad person 3
    :
    : i would expect it to be similar to exporting .html files from VB. However i wanted to get some advice from people who know what they are doing before attempting this project
    :

  • DarQDarQ Member Posts: 1,625
    1. Nice solution.
    2. Variants are slow and take memory. Consult Microshit themselves and they will agree. Variants should be replaced at ALL times.


    : [CODE]Enum enPLErr
    : [No Error] = 0
    : [File Not Found] = 1
    : [File Empty] = 2
    : End Enum
    :
    : Function PopulateList(obList as ListBox, ByVal stFileName As String) As enPLErr
    : Dim inFNum As integer, inFLen as integer, stFCont
    : Dim vaList As Variant, vaTmp As Variant
    : PopulateList = [No Error]
    :
    : 'Check if the file exist
    : If (Dir(stFileName) <> stFileName Then
    : PopulateList = [File Not Found]
    : Exit Function
    : End If
    :
    : 'Open the file and get the contents
    : inFNum = FreeFile
    : Open stFileName For Binary As inFNum
    : 'check if file is empty
    : inFLen = FileLen("MyFile.lst")
    : If inFLen = 0 Then
    : PopulateList = [File Empty]
    : Close inFNum
    : Exit Function
    : End If
    : Get inFNum, inFLen, stFCont
    : 'close the file
    : Close inFLen
    :
    : 'split the contents of the file and add them to the list
    : vaList = Split(stFCont, vbCrLf)
    : If IsArray(vaList) Then
    : For Each vaTmp In vaList
    : obList.AddItem vaTmp
    : Next
    : Else
    : obList.AddItem vaList
    : End If
    : End Function[/CODE][GREY]I think this should work to read a CrLf delimited list and stuff it in a listbox, but I don't have Visual Basic on this computer so I'm not sure if it works, anyway, I don't have time to write the code for writing the file from the listbox to the disk but I can tell you that you have to loop through the listbox and add each item and a vbCrLf to a string and then open the file for output and Print # the string to the file.
    :
    : DjSpirit, feeling helpful today, probably inspired by a LAN party and 80Gb of extra diskspace[/GREY]
    :
    : : a friend of mine has some problems with .htaccess files for his site so i thought it
    : : would be a good idea if i made something simple that will just add an ip to an existing list
    : : After giving it some thought, there are some things i dont know.
    : :
    : : First question
    : : How would i open an existing file into a listbox (listbox1)
    : :
    : : Second question
    : : How would i Take listbox2 and add "deny from " before all of the Ip addresses on export?
    : : i.e.
    : :
    : : deny from bad person 1
    : : deny from bad person 2
    : : deny from bad person 3
    : :
    : : i would expect it to be similar to exporting .html files from VB. However i wanted to get some advice from people who know what they are doing before attempting this project
    : :
    :
    :

    [HR]
    Gadver, ik wot ha'k hjir no wr?
    [HR]

    [GREEN]Anyone cares to translate?[/GREEN]

  • DjSpiritDjSpirit Member Posts: 371
    [grey]I guess the vaTmp could be exchanged with a string, but the problem is that the Split function returns a Variant containing an array, so I whould have to rewrite the whole split function to get it fast.

    I could, while I'm at it, access the string through an array of integers or bytes and then split it by finding the right numbers, thereby avoiding strings alltogether. But that code would be really long and I couldn't event start thinking of it without a proper debugger at hand.

    DjSpirit[/grey]
  • DarQDarQ Member Posts: 1,625
    right, but hey, the previous version is bound to work properly but there is no need for changing it all. As long as we all remember it when trying to use variants is NEW projects. Thats the moment when replacing them with other types is the best.


    : [grey]I guess the vaTmp could be exchanged with a string, but the problem is that the Split function returns a Variant containing an array, so I whould have to rewrite the whole split function to get it fast.
    :
    : I could, while I'm at it, access the string through an array of integers or bytes and then split it by finding the right numbers, thereby avoiding strings alltogether. But that code would be really long and I couldn't event start thinking of it without a proper debugger at hand.
    :
    : DjSpirit[/grey]
    :

    [HR]
    Gadver, ik wot ha'k hjir no wr?
    [HR]

    [GREEN]Anyone cares to translate?[/GREEN]

  • Andre YoungAndre Young USAMember Posts: 0

    ____ || http://forcoder.org || free video tutorials and ebooks about [ C, Perl, Ruby, JavaScript, Visual Basic .NET, PL/SQL, C#, Go, Python, Visual Basic, Delphi, Objective-C, Java, C++, Swift, Scratch, R, PHP, Assembly, MATLAB Scheme, Crystal, Alice, Rust, Hack, Logo, Erlang, Prolog, LabVIEW, VBScript, ABAP, Lua, Julia, COBOL, D, Awk, Scala, Dart, Ada, SAS, Lisp, Fortran, FoxPro, Clojure, Kotlin, Bash, Apex, ML, Transact-SQL, F# ] ____

Sign In or Register to comment.