Giter VIP home page Giter VIP logo

apacheconfigparser's Introduction

ApacheConfigParser

A simple parser for Apache HTTP server config files.

Build status


This project was ported from Stackify's Java-based apache-config package.


Overview

The parser iterates through the config file and builds out a tree of the various settings.

Usage

The code below parses the httpd.conf file and outputs the contents of the ServerName directive in the main body of the file in addition to the ServerName directives within the VirtualHost tags.

httpd.conf:

Listen 80

ServerName localhost:80

DocumentRoot "C:/xampp/htdocs"

<VirtualHost *:443>
        ServerAdmin [email protected]
        ServerName www.foo.com
		
        DocumentRoot /home/www/www.foo.com/htdocs/

        # Logfiles
        ErrorLog  /home/www/www.foo.com/logs/error.log
        CustomLog /home/www/www.foo.com/logs/access.log combined
</VirtualHost>

<VirtualHost *>
        ServerAdmin [email protected]
        ServerName www.bar.com

        DocumentRoot /home/www/www.bar.com/htdocs/
		
        # Logfiles
        ErrorLog  /home/www/www.bar.com/logs/error.log
        CustomLog /home/www/www.bar.com/logs/access.log combined
</VirtualHost>

Code:

var httpdConfPath = @"C:\xampp\apache\conf\httpd.conf";

ConfigParser p = new ConfigParser();
ConfigNode root = p.Parse(httpdConfPath);

foreach (var child1 in root.GetChildren())
{
    if (child1.GetName().Equals("ServerName"))
        Console.WriteLine(child1.GetContent());
    if (child1.GetName().Equals("VirtualHost"))
    {
        foreach (var child2 in child1.GetChildren())
        {
            if (child2.GetName().Equals("ServerName"))
            {
                Console.WriteLine(child2.GetContent());
            }
        }
    }
}

Output:

localhost:80
www.foo.com
www.bar.com

apacheconfigparser's People

Contributors

ndouthit avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.