Code Monkey home page Code Monkey logo

dns-zone-tokenizer's Introduction

Php dns-zone-tokenizer

Latest Stable Version Total Downloads Scrutinizer Code Quality Code Coverage Build Status Documentation Documentation License MIT

Tokenize dns zone files and that's all, folks.

Installation

composer require ltd-beget/dns-zone-tokenizer

Usage

<?php
    use LTDBeget\dns\Tokenizer;
    
    require(__DIR__ . '/vendor/autoload.php');
    
    $config_path = realpath(__DIR__."/zone/exampleZone"); // path to your dns zone file
    $plain_config = file_get_contents($config_path);
    
    $tokenized = Tokenizer::tokenize($plain_config); // that's all, folks. All is done =)

Developers

Regenerate documentation

$ ./vendor/bin/phpdox

Run tests

$ wget https://phar.phpunit.de/phpunit.phar
$ php phpunit.phar --coverage-html coverage
$ php phpunit.phar --coverage-clover coverage.xml

License

released under the MIT License. See the bundled LICENSE file for details.

dns-zone-tokenizer's People

Contributors

booggmz avatar tomas8 avatar vladqa avatar w1nns avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dns-zone-tokenizer's Issues

Information about tokeniser (use of root zone character, etc)

Hi!

I'd like to ask a quick question about your tokeniser.

Imagine that I have something like this (simplified) example:

$ORIGIN typefish.co.uk.

@                                   3600 IN A     127.0.0.1
a                                   3600 IN A     127.0.0.2
a.typefish.co.uk                    3600 IN A     127.0.0.3
a.typefish.co.uk.                   3600 IN A     127.0.0.4

We end up with output from named-compilezone similar to:

typefish.co.uk.                     3600 IN A     127.0.0.1
a.typefish.co.uk.                   3600 IN A     127.0.0.2
a.typefish.co.uk.a.typefish.co.uk.  3600 IN A     127.0.0.3
a.typefish.co.uk.                   3600 IN A     127.0.0.4

However, the output from your tokeniser is:

@                                   3600 IN A     127.0.0.1
a.typefish.co.uk.                   3600 IN A     127.0.0.2
a.typefish.co.uk.a.typefish.co.uk.  3600 IN A     127.0.0.3
a.typefish.co.uk.                   3600 IN A     127.0.0.4

Now, the code - and its tests, imply that the root zone is tokenised as @ as opposed to typefish.co.uk. - should this be the case?

(I personally think it should match named-compilezone)

I've changed the code on my machine to match the output of named-compilezone but I don't want to change any tests nor proceed further with any merging of code until I know why this has been done in this manner.

Regards,
David Weston

Падает в бесконечный цикл

;
; BIND reverse data file for BEGET-NEW-NET1 5.101.159.0/24 zone
;
$TTL 3600
@   IN  SOA ns1.beget.ru.   hostmaster.beget.ru. (
    2014070701  ; Serial
    3600        ; Refresh
    600         ; Retry
    86400       ; Expire
    3600        ; Negative Cache TTL
)

;; NS
@   IN  NS      ns1.beget.ru.
@   IN  NS      ns2.beget.ru.

;; SYSTEM
1   IN  PTR     rt01.beget.ru.
3   IN  PTR     ns3.beget.ru.
5   IN  PTR     ns5.beget.ru.
11  IN  PTR     ns1.beget.ru.
12  IN  PTR     ns2.beget.com.ua.

не зацикливается без комментариев в начале

Parsing a zone file without a trailing newline results in an infinite loop

$this->tokens[$tokenName] = trim($this->tokens[$tokenName]);

In RData.php, line 205, we have:

                    if($this->stream->isEnd()) {
                        $this->tokens[$tokenName] = trim($this->tokens[$tokenName]);
                    }
                    goto start;

The problem is that isEnd() returns true, but the code still goes back to start:.

On line 155, the code should check for isEnd() as well as AsciiChar::NULL to prevent the infinite loop.

Parser nodename

WTF
@ 600 IN MX 10 mx1.beget.ru.

This will be parsed as WTF\n@ in nodename

Tabs in whitespace of multiline txt record

If there are tabs at the beginning of the second (or subsequent) lines in a multi line TXT record, the tokenizer only returns the first line of text. It correctly ignores space and newline, but currently doesn't ignore tab.

While this may not be too widespread, the functions that DirectAdmin (server management software) uses to create TXT records inserts tabs at the beginning of the second (and subsequent) lines of a multi line TXT record, and as DirectAdmin is widely used it would be nice to be able to support this.

I've created a fix and a pull request for this: #23

I appreciate your fantastic script - thanks!

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.