diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 0000000000..4a9a223532 --- /dev/null +++ b/.codespellrc @@ -0,0 +1,6 @@ +[codespell] +skip=./.git,./po,./resources/js/*.min.js,./resources/css/*.min.css +check-hidden= +check-filenames= +builtin=clear,rare,informal,usage,code,names +ignore-words-list=master,thead,referer,cros,hastable,musl,stdio diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000000..34f1e704ee --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,12 @@ +# These are supported funding model platforms + +github: allinurl +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 0000000000..6fd275ff86 --- /dev/null +++ b/.github/workflows/build-test.yml @@ -0,0 +1,70 @@ +name: C build and Test + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + config_params: ["", "--enable-debug", "--enable-debug", "--with-getline --enable-asan", "--enable-utf8 --enable-debug --with-getline", "--enable-utf8 --with-getline --enable-asan"] + os: [ubuntu-latest, macos-latest, macos-14] + include: + - os: ubuntu-latest + setup-env: sudo apt-get update && sudo apt-get install -y build-essential autoconf gettext autopoint libncursesw5-dev libssl-dev git libmaxminddb-dev jq + - os: macos-latest + setup-env: brew install ncurses gettext autoconf automake libmaxminddb openssl@3 jq + - os: macos-14 + setup-env: brew update && brew install ncurses gettext autoconf automake openssl@3 libmaxminddb jq + + steps: + - name: Setup env. + run: ${{ matrix.setup-env }} + + - uses: actions/checkout@v3 + + - name: Check Architecture + run: | + echo "Running on $(uname -m) architecture" + + - name: autoreconf + run: autoreconf -fiv + + - name: Configure + run: ./configure ${{ matrix.config_params }} + + - name: Make + run: sudo make + + - name: Make Check + run: sudo make check + + - name: Make Distcheck + run: sudo make distcheck + + - name: Define log + run: | + echo -e 'localhost:80 192.168.0.1 - - [01/Jul/2013:06:20:38 -0500] "GET / HTTP/1.1" 200 3829 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0"\ + google.com:80 ::1 - - [01/Jul/2013:06:25:11 -0500] "OPTIONS * HTTP/1.0" 200 136 "-" "Apache (internal dummy connection)"\ + bing.com:80 142.250.190.142 - - [01/Jul/2013:06:41:31 -0500] "-" 408 0 "-" "-"\ + yahoo.com:80 74.6.143.25 - - [01/Jul/2013:07:20:02 -0500] "HEAD / HTTP/1.1" 200 213 "-" "Wget/1.14 (linux-gnu)"' > access.log + cat access.log + + - name: Run goaccess single thread + run: ./goaccess access.log --log-format=VCOMBINED -o report.html + + - name: Run goaccess multi-thread + run: ./goaccess access.log --log-format='%v:%^ %h %^[%x] "%r" %s %b "%R" "%u"' --datetime-format='%d/%b/%Y:%H:%M:%S %z' -o report.html -j 2 -a --tz="Europe/Berlin" + + - name: Run goaccess multi-thread JSON output + run: | + ./goaccess access.log --log-format=VCOMBINED -o report.json -j 2 -a --json-pretty-print + cat report.json | jq . + + - name: Make distclean + run: sudo make distclean diff --git a/.github/workflows/deb-packaging.yml b/.github/workflows/deb-packaging.yml new file mode 100644 index 0000000000..7c16949e5c --- /dev/null +++ b/.github/workflows/deb-packaging.yml @@ -0,0 +1,139 @@ +name: .deb packaging + +on: + workflow_dispatch: + +jobs: + build_job: + # The host should always be linux + runs-on: ubuntu-latest + name: Build on ${{ matrix.distro }} ${{ matrix.arch }} + + # Run steps on a matrix of 3 arch/distro combinations + strategy: + matrix: + include: + - arch: arm32v7 + distro: ubuntu16.04 + - arch: arm32v7 + distro: ubuntu18.04 + - arch: arm32v7 + distro: ubuntu22.04 + - arch: arm32v7 + distro: ubuntu23.04 + - arch: arm32v7 + distro: ubuntu23.10 + - arch: arm32v7 + distro: ubuntu24.04 + - arch: arm32v7 + distro: bullseye + - arch: arm32v7 + distro: bookworm + - arch: aarch64 + distro: ubuntu16.04 + - arch: aarch64 + distro: ubuntu18.04 + - arch: aarch64 + distro: ubuntu20.04 + - arch: aarch64 + distro: ubuntu22.04 + - arch: aarch64 + distro: ubuntu23.04 + - arch: aarch64 + distro: ubuntu23.10 + - arch: aarch64 + distro: ubuntu24.04 + - arch: aarch64 + distro: buster + - arch: aarch64 + distro: bullseye + - arch: aarch64 + distro: bookworm + - arch: amd64 + distro: buster + - arch: i386 + distro: buster + - arch: amd64 + distro: bullseye + - arch: amd64 + distro: bookworm + - arch: i386 + distro: bullseye + - arch: i386 + distro: bookworm + - arch: amd64 + distro: ubuntu16.04 + - arch: i386 + distro: ubuntu16.04 + - arch: amd64 + distro: ubuntu18.04 + - arch: i386 + distro: ubuntu18.04 + - arch: amd64 + distro: ubuntu20.04 + - arch: amd64 + distro: ubuntu22.04 + - arch: amd64 + distro: ubuntu23.04 + - arch: amd64 + distro: ubuntu23.10 + - arch: amd64 + distro: ubuntu24.04 + + steps: + - uses: actions/checkout@v2.1.0 + - uses: allinurl/run-on-arch-action@master + name: Build artifact + id: build + with: + arch: ${{ matrix.arch }} + distro: ${{ matrix.distro }} + + # Not required, but speeds up builds + githubToken: ${{ github.token }} + + # Create an artifacts directory + setup: | + mkdir -p "${PWD}/artifacts" + + # Mount the artifacts directory as /artifacts in the container + dockerRunArgs: | + --volume "${PWD}/artifacts:/artifacts" + + # The shell to run commands with in the container + shell: /bin/bash + + # Install some dependencies in the container. This speeds up builds if + # you are also using githubToken. Any dependencies installed here will + # be part of the container image that gets cached, so subsequent + # builds don't have to re-install them. The image layer is cached + # publicly in your project's package repository, so it is vital that + # no secrets are present in the container state or logs. + install: | + case "${{ matrix.distro }}" in + ubuntu*|jessie|stretch|buster|bullseye|bookworm) + apt-get update && apt-get install -y ca-certificates wget curl lsb-release && apt-get clean all + ;; + esac + + # Produce a binary artifact and place it in the mounted volume + run: | + ls -lath "/artifacts" + curl -O https://deb.goaccess.io/provision/provision.sh + chmod +x ./provision.sh + ./provision.sh + echo "Success!!" + + - name: Show the artifact + # Items placed in /artifacts in the container will be in + # ${PWD}/artifacts on the host. + run: | + pwd + ls -lath "${PWD}/artifacts" + + - name: 'Upload deb package' + uses: actions/upload-artifact@v3 + with: + name: deb-package + path: 'artifacts/*.deb' + retention-days: 1 diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000000..5eced49ff1 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,69 @@ +name: Docker +on: + push: + # Publish `master` as Docker `latest` image. + branches: + - master + # Publish `v1.2.3` tags as releases. + tags: + - v* + # Run tests for any PRs. + pull_request: +env: + IMAGE_NAME: ${{ github.repository }} +jobs: + # Run tests. + # See also https://docs.docker.com/docker-hub/builds/automated-testing/ + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run tests + run: | + if [ -f docker-compose.test.yml ]; then + docker-compose --file docker-compose.test.yml build + docker-compose --file docker-compose.test.yml run sut + else + docker build . --file Dockerfile + fi + # Push image to Docker Hub. + # See also https://docs.docker.com/docker-hub/builds/ + push: + # Ensure test job passes before pushing image. + needs: test + runs-on: ubuntu-latest + if: github.event_name == 'push' + + steps: + - uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build image + run: docker build . --file Dockerfile --tag $IMAGE_NAME + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Push image + run: | + # Change all uppercase to lowercase + IMAGE_ID=$(echo "${{ github.repository }}" | tr '[A-Z]' '[a-z]') + + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + # Use Docker `latest` tag convention + [ "$VERSION" == "master" ] && VERSION=latest + + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + + docker buildx create --use + docker buildx build --platform linux/amd64,linux/arm64 -t $IMAGE_ID:$VERSION --push . + diff --git a/.github/workflows/semgrep.yml b/.github/workflows/semgrep.yml new file mode 100644 index 0000000000..bdac4f3aa0 --- /dev/null +++ b/.github/workflows/semgrep.yml @@ -0,0 +1,24 @@ +on: + workflow_dispatch: {} + pull_request: {} + push: + branches: + - main + - master + paths: + - .github/workflows/semgrep.yml + schedule: + # random HH:MM to avoid a load spike on GitHub Actions at 00:00 + - cron: 16 18 * * * +name: Semgrep +jobs: + semgrep: + name: Scan + runs-on: ubuntu-20.04 + env: + SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }} + container: + image: returntocorp/semgrep + steps: + - uses: actions/checkout@v3 + - run: semgrep ci diff --git a/.github/workflows/spelling.yml b/.github/workflows/spelling.yml new file mode 100644 index 0000000000..dd8fdd5476 --- /dev/null +++ b/.github/workflows/spelling.yml @@ -0,0 +1,38 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow + +name: "Spelling" + +on: + workflow_dispatch: +# Add [skip ci] to commit message to skip CI. + +permissions: + contents: "read" + +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + +jobs: + spell_check: + name: "文A Spell check" + runs-on: "ubuntu-22.04" + timeout-minutes: 1 + steps: + - + name: "Checkout repository" + uses: "actions/checkout@v3" + - + name: "Cache pip" + uses: "actions/cache@v3" + with: + path: "~/.cache/pip" + key: "${{ runner.os }}-pip-codespell" + - + name: "Install codespell" + run: | + pip install --user 'codespell>=2.2' + - + name: "Search for misspellings" + run: | + "$(python -m site --user-base)/bin/codespell" diff --git a/.gitignore b/.gitignore index ca50e25205..2c6f8f6446 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,24 @@ #custom section +config.status +config.guess +config.sub +config.rpath +configure~ +**/.deps/ /INSTALL -/config.h.in -/config.log -/config.status -/stamp-h1 -/.deps /Makefile -/config.h +src/.dirstamp +src/config.h +src/config.h.in +src/config.h.in~ +src/config.log +src/config.status +src/.deps/ +src/stamp-h1 goaccess +bin2c +# font selection +selection.json #merged from https://raw.github.com/github/gitignore/master/Autotools.gitignore # http://www.gnu.org/software/automake @@ -23,15 +34,25 @@ Makefile.in /install-sh /missing -#merged from https://raw.github.com/github/gitignore/master/C.gitignore +# VIM +*.*.swp +*.log + # Object files *.o *.ko *.obj +*.elf + +# Precompiled Headers +*.gch +*.pch # Libraries *.lib *.a +*.la +*.lo # Shared objects (inc. Windows DLLs) *.dll @@ -43,9 +64,50 @@ Makefile.in *.exe *.out *.app +*.i*86 +*.x86_64 +*.hex -# VIM -*.*.swp +# Vagrant +.vagrant -# VIM -*.log +# M4 macros +/m4/* + +# I18n stuff +/ABOUT-NLS +/po/*.gmo +/po/*.header +/po/*.mo +/po/*.sed +/po/*.sin +/po/Makefile.in.in +/po/Makevars.template +/po/POTFILES +/po/Rules-quot +/po/Makefile +/po/stamp-po + +# compiled resources +/src/appcss.h +/src/appjs.h +/src/bootstrapcss.h +/src/chartsjs.h +/src/d3js.h +/src/facss.h +/src/hoganjs.h +/src/tpls.h +/src/countries110m.h +/src/topojsonjs.h + +# intermediate resources +/resources/css/app.css.tmp +/resources/css/bootstrap.min.css.tmp +/resources/css/fa.min.css.tmp +/resources/js/app.js.tmp +/resources/js/charts.js.tmp +/resources/js/d3.v?.min.js.tmp +/resources/js/hogan.min.js.tmp +/resources/tpls.html.tmp +/resources/countries-110m.json.tmp +/resources/js/topojson.v3.min.js.tmp diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9fd3e38bac..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -language: c -compiler: - - clang - - gcc -before_install: - - sudo apt-get update -qq - - sudo apt-get install -qq libglib2.0-dev libncurses5-dev libgeoip-dev autoconf autotools-dev libtokyocabinet-dev -install: - - autoreconf -fiv - - ./configure --enable-geoip --enable-utf8 - - make - - make distclean - - autoreconf -fiv - - ./configure --enable-geoip --enable-utf8 --enable-tcb=btree --disable-bzip --disable-zlib - - make - - make distclean - - autoreconf -fiv - - ./configure --enable-geoip --enable-utf8 --enable-tcb=memhash --disable-bzip --disable-zlib - - make - - make distclean - - autoreconf -fiv - - ./configure - - make -branches: - only: - - master -script: "echo done" diff --git a/AUTHORS b/AUTHORS index 2fcf3c02e1..956ef65a07 100644 --- a/AUTHORS +++ b/AUTHORS @@ -2,16 +2,159 @@ GoAccess was designed and developed by Gerardo Orellana + * Aaditya Bagga + * abgit + * Adam Monsen + * Adam Števko + * Adam Weinberger + * Adrian + * aishikoyo + * Alan Placidina + * Alexander Eifler + * Alexandre GUIOT--VALENTIN + * Alexandre Perrin + * Amos Hayes + * A. Nackov + * Anders Johansson <47452862+tellustheguru@users.noreply.github.com> + * Andreas Sommer + * Andreas Weigel + * Andrew Kvalheim + * Andrew Minion + * Antonio Terceiro + * Arnaud Rebillout + * Arnie97 * as0n + * Aslak Raanes + * Axel Wehner + * bbbboom + * Bbertatum + * Benjamin Bach + * Bjørnar Hansen + * Bob Black + * Bo Cai + * Brandon Coleman + * Carlos Duelo + * Celso Providelo + * ChangMo Yang + * Chang Zhao * Chilledheart + * Chris Downs + * Christian Göttsche + * Christian Hermann + * Christian Moelders + * Christopher Meng + * Clément Hermann + * cristianpb + * Cthulhux + * Daniel Aleksandersen + * Daniel Aleksandersen * Daniel (dmilith) Dettlaff + * Danila Vershinin + * Danny Kirkham + * Darek Kay + * David Carlier + * David Geistert + * d_dandrew + * ElXreno + * Enrique Becerra + * evitalis + * Felix Häberle <34959078+felixhaeberle@users.noreply.github.com> * Florian Forster - * Francisco Azevedo + * forDream + * fqbuild + * Frederic Cambus + * gemmaro + * Genki Sugawara + * Gerald Combs + * Geraldo Alves + * gitqlt + * Hiroki Kamino <46459949+err931@users.noreply.github.com> * holys + * Izzy + * JackDesBwa + * Jannes Blobel <72493222+jannesblobel@users.noreply.github.com> + * Jeffery Wilkins + * Jeremy Burks + * Jeremy Lin + * Joaquín de la Zerda + * Joe Groocock + * Joe Winett + * Jonas Kittner + * Joona + * Jordan Trask + * Julian Xhokaxhiu + * Justin Mills + * Kamino Hiroki <37243867+4f8p@users.noreply.github.com> * Kit Westneat + * kokke + * kyle sloan + * LeoAttn + * Magnus Groß + * Maksim Losev + * mario-donnarumma + * markiewb * Mark J. Berger + * Martins Polakovs + * Massimiliano Torromeo + * Mathieu Aubin + * Mathieu Thoretton + * Max Christian Pohle + * metrix78 + * Michael Vetter + * Mika Raunio + * Moritz Schott * m-r-r + * mynameiscfed + * Newbe36524 + * Nicolas Le Manchet + * Nicolas + * Ophir LOJKINE + * Otto Kekäläinen + * Panos Stavrianos + * pitilux + * Pixelcode <52963327+realpixelcode@users.noreply.github.com> + * Placidina + * pravdomil + * rachid-debu * radoslawc + * rahra + * Ramires Viana <59319979+ramiresviana@users.noreply.github.com> + * rgriebl + * Roy Marples + * rtmkrlv + * Ryow + * schoonc + * Sean Cross + * Sean Wei + * Sebastian Wiedenroth + * Simon Gardling + * SjonHortensius + * Steely Wing * Stéphane Péchard + * Stephen Wade + * Stoyan Dimov + * Stuart Henderson + * Sveinbjorn Thordarson + * Tatsuyuki Ishi + * Thomas Gläßle + * Thomas Jost + * Thomas Lange + * throwaway1037 + * Tim Gates + * Timothy Quilling + * Tom Samstag + * ugola + * Ulrich Schwarz + * Viktor Szépe + * Viktor Szépe * Ville Skyttä + * Vincent Bernat + * Vladimir Pavljuchenkov + * William Muir + * Wladimir Palant + * wodev * woobee + * Yuri D'Elia + * Yuriy M. Kaminskiy + * zeke diff --git a/COPYING b/COPYING index d159169d10..a378b8bc25 100644 --- a/COPYING +++ b/COPYING @@ -1,339 +1,21 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. +The MIT License (MIT) + +Copyright (c) 2009-2022 Gerardo Orellana + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/ChangeLog b/ChangeLog index 4b87a79cad..cfbcea496a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,222 +1,1176 @@ +Changes to GoAccess 1.9.3 - Friday, May 31, 2024 + + - Added additional common bots to the list. + - Added Address Sanitizer via '--enable-asan' to the configure options for + debugging purposes. + - Fixed inability to parse JSON keys containing dots. + - Fixed out-of-bounds access for invalid HTTP status codes. + - Fixed out-of-bounds access when parsing a log in serial processing mode. + - Fixed regression introduced in 8f570c, which caused duplicate counts upon + restoring from disk via '--restore'. + +Changes to GoAccess 1.9.2 - Friday, April 12, 2024 + + - Added World Map to the Geo Location panel on the HTML report. + - Added additional non-official/standard HTTP status codes such as Caddy's 0 + HTTP status among others. + - Added support for '%z' on strptime for non-glibc systems, such as musl libc + in Alpine Linux (Docker container), enabling the use of '--tz' + - Changed the '--hide/ignore-referrer' options to filter by hostname directly + without the use of wildcards, e.g., '--ignore-referrer=wiki.google.com'. + - Fixed inability to parse duplicate specifiers during log format parsing. + - Fixed regression which previously hindered the ability to modify log, date, + and time formats within the TUI dialog. i.e., '# goaccess access.log -c'. + - Replaced 'remote_ip' with 'client_ip' for Caddy's JSON format, allowing the + use of trusted proxies. + - Updated Caddy JSON example log format to handle headers correctly. + - Updated Swedish i18n. + +Changes to GoAccess 1.9.1 - Tuesday, February 05, 2024 + + - Added support for macOS to the OS detection. + - Fixed C99 mode issue with initial declarations [CentOS7]. + - Fixed minor typographical, orthographic, and grammatical errors in the + German translation. + - Fixed a regression issue wherein parsing would halt at the first empty log + file. + +Changes to GoAccess 1.9 - Tuesday, January 30, 2024 + + - Added multi-threaded log processing with '--jobs=' for a boost in + parsing speed, achieving an improvement ranging from 1.26 to 3.65x faster. + - Added the 'SEARCH' method to the list of HTTP request methods. + - Added compatibility to include the Traefik log format. + - Added the ability to gracefully handle SIGQUIT as a signal for shutdown. + - Altered WebSocket server initialization, ensuring it takes place after + log-format checks. + - Deprecated '--output-format'; now, only the '--output' option is + permissible. + - Implemented mutex locking to prevent a TZ environment race condition. + - Fixed a potential heap overflow when checking a request for bots. + - Fixed sorting of child items on HTML panels when sorting a column via the + UI. + - Fixed an issue where, in some cases, the referer host wouldn't be extracted + properly + - Fixed the miscategorization of Android 12.1 under operating systems. + - Fixed TUI and temporarily ignored SIGINT during subdialog execution via + Ctrl+C. + - Updated the list of browsers/bots. + +Changes to GoAccess 1.8.1 - Tuesday, October 31, 2023 + + - Added latest Android and macOS versions to the list of OSs. + - Fixed issue when trying to apply a regex on an invalid value (HTML report). + - Fixed issue with D3.js xScale.domain() going out of boundaries in certain + cases. + - Prevent setting default static files when no static-file options are + defined in config file. + +Changes to GoAccess 1.8 - Saturday, September 30, 2023 + + - Added dual-stack support to the WebSocket server. + - Added Debian Bookworm to the official deb repo. + - Added Ubuntu Lunar to the official deb repo. + - Fixed compiler error on macOS 10.12. + - Updated bootstrap to v3.4. + - Updated FontAwesome with additional icons for upcoming major release. + - Updated Japanese translation. + - Updated OS display from Macintosh to macOS. + - Updated to D3.js v7 (latest) including charts.js code. + +Changes to GoAccess 1.7.2 - Friday, March 31, 2023 + + - Added a color-coding scheme to HTTP status codes. + - Added '--external-assets' command line option to output external JS+CSS + files. Great when used with Content Security Policy (CSP). + - Ensure there's a fallback for 'Windows' if it appears on the user-agent. + - Ensure we construct the WebSocket URL in a way that supports multiple use + cases when used along '--ws-url' and '--port'. + - Fixed a segfault due to a null pointer exception on FreeBSD. + - Fixed build with '--disable-nls'. + - Fixed invalid read (heap-buffer-overflow) when parsing an XFF spec via + JSON. + - Fixed segfault when parsing a specific XFF specifier. + +Changes to GoAccess 1.7.1 - Tuesday, February 28, 2023 + + - Added 'inlang' for easy localization (i18n) updates. + https://inlang.com/editor/github.com/allinurl/goaccess + - Added nanosecond parsing option via the '%n' specifier. Great for parsing + 'Traefik' JSON logs duration field. + - Changed Docker workflow to build a docker image on different architectures + {'arm64' & 'amd64'}. + - Fixed issue with '--unknowns-as-crawlers' where it did not process them as + such. + +Changes to GoAccess 1.7 - Saturday, December 31, 2022 + + - Added an option to classify unknown OS and browsers as crawlers using + `--unknowns-as-crawlers`. + - Added highlighting to certain metrics on the HTML report for readability. + - Added a new panel that displays ASN data for GeoIP2 and legacy databases. + Great for detecting malicious traffic and blocking accordingly. + - Added an ASN metric per IP/host. + - Changed and prioritize user's browsers list over heuristics. + - Ensure `--geoip-database=` can be used multiple times to support + different databases. + - Fixed invalid read when loading the list of agents for an IP. + - Fixed issue where a file containing a NUL `\0` character would crash the + program. + - Updated Swedish i18n. + +Changes to GoAccess 1.6.5 - Monday, October 31, 2022 + + - Updated Dockerfile build stage to use alpine:3. + - Updated deb build to use the right libncursesw6 dependency. + +Changes to GoAccess 1.6.4 - Friday, September 30, 2022 + + - Added Korean translation (i18n). + - Added the ability to use filenames as virtualhosts using + '--fname-as-vhost='. + - Enabled crawlers/bots under the OSs panel instead of being shown as + 'Unknown'. + - Updated the format on the command-line help output. + +Changes to GoAccess 1.6.3 - Thursday, August 31, 2022 + + - Enabled DNS thread when resolving a host and outputting real-time HTML. + This helps avoid stalling the WS server on busy connections. + - Fixed issue where it would not properly parse an XFF if the '%h' specifier + was already set. + - Fixed possible XSS issues when using '--html-custom-css' and + '--html-custom-js' by allowing valid filenames. + +Changes to GoAccess 1.6.2 - Thursday, July 14, 2022 + + - Added `Android 12` to the list of OSs. + - Added `macOS 12 Ventura` to the list of OSs. + - Fixed implicit declaration build issue due to `timegm(3)` on `BSDs` and `macOS`. + - Fixed issue where timezone conversion would be performed twice on a given + date. + +Changes to GoAccess 1.6.1 - Thursday, June 30, 2022 + + - Added a `--ping-interval=` in an attempt to keep the WebSocket + connection opened. + - Added support for timezone conversion via `--datetime-format=` and + `--tz=`. + - Added the ability to reconnect to the WebSocket server after 1 sec with + exponential backoff (x20). + - Fixed issue where an invalid client connection would stall data out to + clients via the WebSocket server. + - Fixed an issue where real-time data would be parsed multiple times under `Cygwin`. + +Changes to GoAccess 1.6 - Tuesday, May 31, 2022 + + - Changed slightly how the XFF field is specified. See man page for details. + - Ensure city is displayed with the DBIP City Lite database. + - Ensure no 'cleaning up resources' message is displayed if `--no-progress` + is passed. + - Ensure the maximum number of items per panel defaults to 1440 (24hrs) when + passing `--date-spec=min`. + - Fixed issue when parsing a delimited XFF field followed by a host IP. + - Fixed issue where some data was buffered on the WebSocket server before it + was sent to each client. + - Fixed issue where the WebSocket server would fail with POLLNVAL consuming + 100% CPU. + - Fixed segfault when attempting to open an unresolved IP on mac/BSDs. + +Changes to GoAccess 1.5.7 - Thursday, April 28, 2022 + + - Updated Caddy's JSON format. This should address CADDY's v2.5.0 change. + - Updated Chinese translation (i18n). + - Updated GeoIP module so it defaults to native language name (i18n) or + fall-back to English. + - Updated Russian translation (i18n). + - Updated Ukrainian translation (i18n). + +Changes to GoAccess 1.5.6 - Wednesday, March 30, 2022 + + - Added `--anonymize-level=<1|2|3>` option to specify IP anonymization level. + - Added minute specificity to the Visitors panel via `--date-spec=min`. + - Added the ability to toggle on/off panels on the HTML report. + - Changed stderr to stdout on non-error output when exiting goaccess. + +Changes to GoAccess 1.5.5 - Monday, January 31, 2022 + + - Added mechanism to automatically parse additional bots. + - Changed area chart interpolation to 'monotone'. This should avoid the issue + where the interpolated curve has a bend into the negative space. + - Changed build to use debugging symbols even for release builds. + - Changed order on which we verify bots to be the first thing we check. This + adds a slight improvement on parsing time. + - Ensure we initialize DNS resolver conditions and mutexes before they're used. + - Fixed possible buffer over-read for cases where a '\0' could be reached + early when parsing a log line. + - Fixed possible data race on UI spinner thread. + - Fixed regression where a lot of robots were not detected by GoAccess. + +Changes to GoAccess 1.5.4 - Saturday, December 25, 2021 + + - Added AWS ALB to the predefined logs format list --log-format=AWSALB. + - Ensure we lock our pipe/websocket writer before broadcasting message. + - Ensure we require a valid host token even when we're not validating the IP. + - Ensure we simply update the TUI once after tailing multiple files. + - Ensure we simply update the UI once after tailing multiple files. + - Fixed buffer overflow when checking if an HTTP code was a 404 on an empty + status code. + - Optimized terminal and HTML UI output when tailing multiple files. + - Updated DB PATH error message to be more descriptive. + +Changes to GoAccess 1.5.3 - Thursday, November 25, 2021 + + - Added additional crawlers to the default list. + - Added Italian translation (i18n). + - Added 'macOS 12' to the list of OS. + - Fixed buffer overflow caused by an excessive number of invalid requests + with multiple logs. + - Fixed visualization issue on the HTML report for panels with disabled + chart. + +Changes to GoAccess 1.5.2 - Tuesday, September 28, 2021 + + - Added .avi to the list of static requests/extensions. + - Changed label from 'Init. Proc. Time' to 'Log Parsing Time'. + - Fixed issue where lengthy static-file extension wouldn't account certain + valid requests. + - Fixed possible buffer underflow when checking static-file extension. + - Fixed segfault when attempting to parse an invalid JSON log while using a + JSON log format. + - Fixed segfault when ignoring a status code and processing a line > '4096' + chars. + +Changes to GoAccess 1.5.1 - Wednesday, June 30, 2021 + + - Changed official deb repo so it now builds '--with-getline' in order to + support request lines longer than 4096. + - Ensure there's no tail delay if the log file hasn't changed. + - Fixed data race when writing to a self-pipe and attempting to stop the WS server. + - Fixed inability to close expanded panel when pressing 'q' on TUI. + - Fixed possible data race during parsing spinner label assignment. + - Increased the maximum number of files to monitor from '512' to '3072'. + +Changes to GoAccess 1.5 - Wednesday, May 26, 2021 + + - Added a Docker container based isolated build environment (Debian). + - Added Dark Mode detection to the HTML report. + - Added the ability for the WebSocket server to bind to a Unix-domain socket. + - Added the ability to parse IPs enclosed within brackets (e.g., IPv6). + - Changed categorization of requests containing 'CFNetwork' to 'iOS' when + applicable. + - Changed command line option from '--hide-referer' to '--hide-referrer'. + - Changed command line option from '--ignore-referer' to '--ignore-referrer'. + - Fixed a potential division by zero. + - Fixed inability to parse IPv6 when using a 'CADDY' log format. + - Fixed issue where a 'BSD' OS could be displayed as Linux with certain + user-agents. + - Fixed memory leak when a JSON value contained an empty string (e.g., + JSON/CADDY format). + - Fixed possible buffer overflow on a WS packet coming from the browser. + - Refactored a substantial part of the storage codebase for upcoming + filtering/search capabilities (issue #117). + - Refactored DB storage to minimize memory consumption up to '35%'. + - Updated default 'AWS Elastic Load Balancing' log format. + - Updated German translation. + - Updated page size to 24 on the HTML report. + - Updated UNIX OS categories. + +Changes to GoAccess 1.4.6 - Sunday, February 28, 2021 + + - Added additional feed reader clients. + - Added additional browsers and bots to the main list. + - Added command line option '--unknowns-log' to log unknown browsers and + OSs. + - Added 'Referer' to the pre-defined 'Caddy JSON' log format. + - Added support for real-time piping as non-root user. + - Added the ability to Handle case when IPv4 is encoded as IPv6 in + GeoIP1/legacy. + - Ensure we capture linux (lowercase) when extracting an OS. + - Fixed a regression in parsing Google Cloud Storage or possibly other + non-JSON formats. + - Fixed inability to parse escaped formats. + - Fixed issue when using '%s' with 'strptime(3)' under musl libc. This + addresses mostly the Docker image. + - Fixed possible buffer over-read for certain log-format patterns. + - Fixed segfault when attempting to process a malformed JSON string. + - Fixed segfault when setting an empty log-format from the TUI dialog. + - Fixed sorting on hits and visitors when larger than INT_MAX. + - Updated CloudFront pre-defined log-format to reflect the latest fields. + - Updated 'Dockerfile' image to use 'alpine:3.13' instead of edge due to + compatibility issue with the GNU coreutils. + +Changes to GoAccess 1.4.5 - Tuesday, January 26, 2021 + + - Fixed build issue due to initial declarations only allowed in C99 mode + (e.g., CentOS7). + +Changes to GoAccess 1.4.4 - Monday, January 25, 2021 + + - Added 'Caddy' to the list of pre-defined log formats. + - Added command line option '--no-strict-status' to disable status validation. + - Added native support to parse JSON logs. + - Added the ability to process timestamps in milliseconds using '%*'. + - Ensure TUI/CSV/HTML reports are able to output 'uint64_t' data. + - Ensure we allow UI render if the rate at which data is being read is + greater than '8192' req/s. + - Ensure we don't re-render Term/HTML output if no data was read/piped. + - Fixed build configure to work on NetBSD. + - Fixed issue where it would send data via socket each second when managed + by systemd. + - Fixed issue where parser was unable to parse syslog date with padding. + - Fixed issue where some items under browsers.list were not tab separated. + - Fixed issue where the format parser was unable to properly parse logs + delimited by a pipe. + - Fixed issue where T.X. Amount metrics were not shown when data was piped. + - Fixed issue where XFF parser could swallow an additional field. + - Fixed memory leak when using '%x' as date/time specifier. + - Replaced select(2) with poll(2) as it is more efficient and a lot faster + than select(2). + - Updated Swedish i18n. + +Changes to GoAccess 1.4.3 - Friday, December 04, 2020 + + - Added the ability to set how often goaccess will parse data and output to + the HTML report via '--html-refresh='. + - Changed how TLS is parsed so the Cypher uses a separate specifier. + It now uses '%K' for the TLS version and '%k' for the Cypher. + - Fixed issue where real-time output would double count a rotated log. This + was due to the change of inode upon rotating the log. + - Updated man page to reflect proper way of 'tail -f' a remote access log. + +Changes to GoAccess 1.4.2 - Monday, November 16, 2020 + + - Added the ability to show 'Encryption Settings' such as 'TLSv1.2' and + Cipher Suites on its own panel. + - Added the ability to show 'MIME Types' such as 'application/javascript' on + its own panel. + - Changed Debian build to use mmdb instead of libgeoip (legacy). + - Ensure the HTML report defaults to widescreen if viewport is larger than + '2560px'. + - Fixed inability to properly process multiple logs in real-time. + - Fixed issue where named PIPEs were not properly seed upon generating + filename. + - Fixed issue where served time metrics were not shown when data was piped. + - Removed unnecessary padding from SVG charts. Improves readability on mobile. + +Changes to GoAccess 1.4.1 - Monday, November 09, 2020 + + - Added additional browsers and bots to the main list. + - Added 'Android 11' to the list of OSs. + - Added 'macOS 11.0 Big Sur' to the list of OSs. + - Added 'average' to each panel overall metrics. + - Added '.dmg', '.xz', and '.zst' to the static list. + - Added extra check to ensure restoring from disk verifies the content of the + log against previous runs. + - Added Russian translation (i18n). + - Added Ukrainian translation (i18n). + - Added support for HTTP status code '308'. + - Added the ability for 'get_home ()' to return NULL on error, instead of + terminating the process. Great if using through systemd. + - Added the ability to read lowercase predefined log formats. For instance, + '--log-format=COMBINED' or '--log-format=combined'. + - Changed how FIFOs are created and avoid using predictable filenames under + '/tmp'. + - Changed '--ignore-referer' to use whole referrer instead of referring site. + - Ensure Cache Status can be parsed without sensitivity to case. + - Ensure restored data enforces '--keep-last' if used by truncating + accordingly. + - Fixed a few memory leaks when restoring from disk. + - Fixed blank time distribution panel when using timestamps. + - Fixed build issue due to lack of 'mmap' on 'Win'/'Cygwin'/'MinGW'. + - Fixed crash in mouse enabled mode. + - Fixed double free on data restore. + - Fixed inability to keep processing a log when using '--keep-last'. + - Fixed inability to properly parse truncated logs. + - Fixed inability to properly count certain requests when restoring from + disk. + - Fixed issue where it would not parse subsequent requests coming from stdin (tail). + - Fixed issue where log truncation could prevent accurate number counting. + - Fixed issue where parsed date range was not rendered with '--date-spec'. + - Fixed issue where parser would stop regardless of a valid '--num-test' value. + - Fixed issue where restoring from disk would increment 'MAX.TS'. + - Fixed possible incremental issue when log rotation occurs. + - Fixed possible XSS when getting real-time data into the HTML report. + - Fixed potential memory leak when failing to get root node. + - Fixed real-time hits count issue for certain scenarios. + - Fixed segfault in 'Docker' due to a bad allocation when generating FIFOs. + - Fixed 'Unknown' Operating Systems with 'W3C' format. + - Removed unnecessary include from parser.c so it builds in macOS. + - Updated each panel overall UI to be more streamlined. + - Updated French translation. + - Updated German translation. + - Updated Spanish translation. + - Updated sigsegv handler. + +Changes to GoAccess 1.4 - Monday, May 18, 2020 + + - Added a caching storage mechanism to improve parsing raw data and data + rendering. + - Added a mechanism to avoid counting duplicate data when restoring persisted + data from disk. + - Added additional option to the HTML report to set a maximum number of items + per page to 3. + - Added a list of podcast-related user agents under '%sysconfdir%'. + - Added 'Android 10' to the list of Android codenames. + - Added a 'widescreen' layout to the HTML report (e.g., 4K TV/KPI Dashboard). + - Added 'Beaker', 'Brave', and 'Firefox Focus' to the list of browsers + - Added command line option --user-name=username to avoid running GoAccess as + root when outputting a real-time report. + - Added 'DuckDuckGo' and 'MSNBot' browsers to the browsers.list. + - Added 'facebookexternalhit' to the default crawler list. + - Added German translation (DE). + - Added Kubernetes Nginx Ingress Log Format to the default config file. + - Added 'macOS Catalina' to the list of OSX codenames. + - Added minor CSS updates to HTML report. + - Added missing header '' to fix FreeBSD build + - Added new 'Edg' token to the list of browsers. + - Added '--no-ip-validation' command line to disable client IP validation + - Added '--persist' and '--restore' options to persist to disk and restore a + dump from disk. + - Added Portuguese translation (pt-BR) + - Added Swedish translation (SV) + - Added the ability to parse server cache status and a new panel to display + those metrics. + - Changed accumulated time to work by default on '--persist' and '--restore'. + - Changed back how the hits and visitors percentage is calculated to be more + intuitive. + - Changed Geo Location panel display default to show only if database file is + provided ('LIBMAXMINDDB'). + - Changed initial processing time from secs to HH:MM:SS in HTML output. + - Changed '--max-items' for the static HTML report to allow no limit on + output entries. + - Changed required 'gettext' version to 0.19 + - Changed to ignore 'SIGPIPE' with 'SIG_IGN' + - Changed version to 10.15 for 'macOS Catalina'. + - Ensure proper escaping on default AWSELB log format. + - Ensure valid requests counter is not affected on duplicate entries when + restoring data. + - Fixed issue preventing Ctrl-C (SIGINT) for the curses interface to stop the + program. + - Fixed issue where HTML report wouldn't update the tables when changing per + page option. + - Fixed issue where it wouldn't find either the user's or global config file. + - Fixed issue where changing the number of items per page in the HTML report + would not automatically refresh the tables. + - Fixed issue where last updated label was not updated in real-time. + - Fixed issue where overall date range wasn't showing the right start/end parse + dates. + - Fixed issue where tailing a file could potentially re-parse part of the log. + - Fixed memory leak when fetching country/continent while using 'LIBMAXMINDDB'. + - Fixed several '-Wcast-qual' warnings. + - Fixed unwanted added characters to the HTML output. + - Fixed websocket issue returning a 400 due to request header size. + - Increased 'MAX_LINE_CONF' so a JSON string can be properly parsed from the + config file. + - Removed deprecated option '--geoip-city-data' from config file. + - Removed unnecessary dependency from snapcraft.yaml. + - Removed Vagrantfile per #1410 + - Removed some old browsers from the default curated list. + - Replaced TokyoCabinet storage for a non-dependency in-memory persistent + storage. + - Updated Dockerfile. + +Changes to GoAccess 1.3 - Friday, November 23, 2018 + + - Added ability to store accumulated processing time into DB_GEN_STATS tcb + file via '--accumulated-time' command line option. + - Added additional Apache status codes to the list. + - Added a few feed readers to the list. + - Added 'Android 8 Oreo' to the list of OSs. + - Added 'Android Pie 9' to the list of OSs. + - Added --anonymize-ip command line option to anonymize ip addresses. + - Added --browsers-file command line option to load a list of crawlers from a + text file. + - Added byte unit (PiB) to C formatter and refactored code. + - Added byte unit (PiB) to JS formatter. + - Added Chinese translation (i18n). + - Added French translation (i18n). + - Added '%h' date specifier to the allowed date character specifiers. + - Added "HeadlessChrome" to the list of browsers. + - Added --hide-referer command line option to hide referrers from report. + - Added HTTP status code 429 (TOO MANY REQUESTS). + - Added IGNORE_LEVEL_PANEL and IGNORE_LEVEL_REQ definitions. + - Added Japanese translation (i18n). + - Added macOS 10.14 Mojave to the list of OSs. + - Added "Mastodon" user-agent to the list of crawlers/unix-like. + - Added new fontawesome icons and use angle arrows in HTML paging. + - Added new purple theme to HTML report and default to it. + - Added --no-parsing-spinner command line option to switch off parsing + spinner. + - Added .ogv and ogg static file extension (ogg video, Ogg Vorbis audio). + - Added OS X version numbers when outputting with --real-os. + - Added parsing mechanism in an attempt capture more bots and to include + unspecified bots/crawlers. + - Added --pidfile command line option to the default config file. + - Added Spanish translation (i18n). + - Added SSL support for Docker goaccess build. + - Added support to the WebSocket server for openssl-1.1*. + - Added the ability to show/hide a chart per panel in the HTML report. + - Added transparency to the navigation bar of the HTML report. + - Added "WhatsApp" user-agent to the list of crawlers. + - Changed default db folder so it adds the process id (PID). --db-path is + required now when using --load-from-disk. + - Changed Dockerfile to build from the current source. + - Changed 'hits' to be right-aligned on TUI. + - Changed to use faster slide animations on HTML report. + - Changed wording from 'Bandwidth' to the proper term 'Tx. Amount'. + - Ensure database filenames used by btree are less predictable. + - Ensure HTML templates, CSS and JS files are minified when outputting + report. + - Ensure key phrases from Google are added even when https is used. + - Ensure live report updates data & charts if tab/document has focus. + - Ensure multiple 'Yandex' crawlers are properly parsed. + - Ensure Safari has priority over most crawlers except the ones that are + known to have it. + - Ensure the request protocol on its own is properly parsed. + - Ensure the right number of tests are performed against the given log. + - Ensure user configuration is parsed first when available. + - Ensure wss:// is used when connecting via HTTPS. + - Ensure XFF parser takes into account escaped braces. + - Fixed a regression where fifo-in/out would fail with ENXIO. + - Fixed a regression where it would return EXIT_FAILURE on an empty log. + - Fixed a (ssh) pipeline problem with fgetline()/fgets() when there is a race + for data on stdin. + - Fixed broken X-Forwarded-For (XFF) %~ specifier in certain parsing cases. + - Fixed conf.filenames duplication problem if logs are via pipe. + - Fixed float percent value on JSON/HTML output for locales using decimal comma. + - Fixed issue where it was not possible to establish a Web Socket connection + when attempting to parse and extract HTTP method. + - Fixed issue where log formats with pipe delimiter were not properly parsed. + - Fixed memory leak after config file path has been set (housekeeping). + - Fixed memory leak when adding host to holder introduced in c052d1ea. + - Fixed possible memory leak when hiding specific referrers. + - Fixed several JS jshint warnings. + - Fixed sudo installs on TravisCI. + - Fixed UNDEFINED time range in HTML report when VISITORS panel was ignored. + - Fixed unnecessary closing span tags from template. + - Fixed use-after-free when two color items were found on color_list. + +Changes to GoAccess 1.2 - Tuesday, March 07, 2017 + + - Added a Dockerfile. + - Added Amazon S3 bucket name as a VirtualHost (server block). + - Added a replacement for GNU getline() to dynamically expand line buffer + while maintaining real-time output. + - Added --daemonize command line option to run GoAccess as daemon. + - Added several improvements to the HTML report on small-screen devices. + - Added option to the HTML report to auto-hide tables on small-screen + devices. + - Added --process-and-exit command line option to parse log and exit. + - Added several feed readers to the list of browsers. + - Added "-" single dash per convention to read from the standard input. + - Added support for MaxMind GeoIP2. + - Added the ability to read and follow from a pipe such as + "tail -f access.log | goaccess -" + - Added the ability to specify multiple logs as input sources, e.g.: + "goaccess access.log access.log.1" while maintaining real-time output. + - Added time unit (seconds) to the processed time label in the HTML/terminal + output. + - Added visitors' percent column to the terminal dashboard. + - Changed D3 charts to dim Y-axis on mouseover. + - Changed D3 charts to reflect HTML column sort. + - Changed D3 charts to render only if within the viewport. This improves the + overall real-time HTML performance. + - Changed HTML report tables to render only if within the viewport. + - Changed percentage calculation to be based on the total within each panel. + - Ensure start/end dates are updated real-time in the HTML output. + - Ensure "window.location.hostname" is used as the default WS server host. + In most cases, this should avoid the need for specifying "--ws-url=host". + Simply using "--real-time-html" should suffice. + - Fixed issue on HTML report to avoid outputting scientific notation for all + byte sizes. + - Fixed integer overflow when calculating bar graph length on terminal + output. + - Fixed issue where global config file would override command line arguments. + - Fixed issue where it wouldn't allow loading from disk without specifying a + file when executed from the cron. + - Fixed issue where parser couldn't read some X-Forwarded-For (XFF) formats. + Note that this breaks compatibility with the original implementation of + parsing XFF, but at the same time it gives much more flexibility on different + formats. + - Fixed issue where specifying fifo-in/out wouldn't allow HTML real-time + output. + - Fixed issue where the wrong number of parsed lines upon erroring out was + displayed. + - Fixed issue where the WebSocket server prevented to establish a connection + with a client due to invalid UTF-8 sequences. + - Fixed percent issue when calculating visitors field. + - Updated the list of crawlers. + +Changes to GoAccess 1.1.1 - Wednesday, November 23, 2016 + + - Added data metric's "unique" count on each panel to the JSON/HTML outputs. + - Changed D3 bar charts to use .rangeBands and avoid extra outer padding. + - Fixed mouseover offset position issue on D3 bar charts. + - Fixed possible heap overflow when an invalid status code was parsed and + processed. This also ensures that only valid HTTP status codes are parsed + >=100 or <= 599. + - Fixed sluggish D3 chart re-rendering by changing how x-axis labels are + displayed in the HTML report. + +Changes to GoAccess 1.1 - Tuesday, November 08, 2016 + + - Added a new layout to the HTML report and additional settings and changes. + - Added --crawlers-only command line option to display crawlers/bots only. + - Added --fifo-in and --fifo-out command line options to set websocket FIFO + reader/writer. + - Added --no-html-last-updated command line option. + - Added --num-tests command line option. + - Added --html-prefs command line option to to set default preferences for + the HTML report. + - Added "Amazon S3" Log Format to the list of predefined options. + - Added "Android 7.1 Nougat" to the list of OSs. + - Added "Android Marshmallow 6.0.1" to the list of OSs. + - Added "Android Nougat 7.0" to the list of OSs. + - Added "Feed Wrangler" to the list of feeds. + - Added "Go-http-client" to the list of browsers. + - Added "MicroMessenger" (WeChat) to the list of browsers. + - Added "SemrushBot" to the list of crawlers. + - Added "Remote User" panel to capture HTTP authentication requests. Use %e + within the log-format variable to enable this panel. + - Added tebibyte unit to the byte to string function converter. + - Added the ability to parse reverse proxy logs that have multiple IPs. This + adds the ability to parse the "X-Forwarded-For" field in a reverse proxy + setup. + - Added the ability to show which token didn't match log/date/time pattern. + This also ensures that in the absence of data, its output is not treated as + error but instead it produces an empty report. + - Added the ability to specify a WebSocket protocol (ws|wss) through + --ws-url. + - Added the request query string to the W3C format. + - Added TLS/SSL support to the HTML real-time report. + - Changed browser classification for Google Cloud Clients. + - Changed how "Darwin" OS was reported to display AppName instead. + - Changed default W3C log format to use the URL path instead of full request. + - Changed HTML default number of items on each table to 7. + - Changed request parser to allow empty query strings. + - Changed default HTML output theme to darkBlue. + - Ensure every version of iOS is broken down under the OS panel. + - Ensure latest JSON data is fast-forwarded when connection is opened. + GoAccess now sends the latest JSON data to the client as soon as the + WebSocket connection is opened. + - Ensure localStorage is supported and enabled in the HTML report + - Ensure unknown countries/continents are listed. + - Fixed D3 chart width overflow issue on Edge. + - Fixed integer to string key conversion for unique visitors. This fixes the + issue where resulting keys would collide with existing keys and thus not + keeping the right visitors count on certain panels. + - Fixed memory leak when unable to URL decode %q specifier. + - Fixed memory leak when unable to URL decode %U specifier. + - Fixed month name abbreviation on app.js. + - Fixed percentage integer overflow with large numbers on 32bits platforms. + - Fixed percent calculation due to integer division rounding to zero. + - Fixed possible code injection when outputting an HTML report. + - Fixed segfault when using options -H or -M without an argument. + - Removed timestamp from the HTML report title tag. + +Changes to GoAccess 1.0.2 - Tuesday, July 05, 2016 + + - Added minor changes to the HTML report stylesheet. + - Added the ability to specify the WebSocket port within --ws-url. + - Added the proper byte swap functions used by Sun Solaris. + - Added the proper default --http-method/protocol values on the config file. + - Changed bar transition to scale delay dynamically to the length of the + dataset. + - Fixed build issue on platforms lacking of open_memstream() by refactoring + the JSON module to use its own memory buffer. + - Fixed issue where the server wouldn't send cached buffer to slow clients. + - Fixed OS X build check of ncursesw. + - Implemented a throttle mechanism for slow clients to avoid caching too much + data on the server-side. + - Removed flickering on D3 line and bar chart redraw. + +Changes to GoAccess 1.0.1 - Friday, June 17, 2016 + + - Added Android version number along with the codename when using --real-os, + e.g., "Lollipop 5.1". + - Added some missing headers and function checks to configure.ac. + - Fixed a regression where it wouldn't allow abbreviated date and time + formats such as %F or %T. + - Fixed build issues on systems running GLIBC older than 2.9, such as RHEL <= 5. + - Fixed issue where it wouldn't send the whole buffer to a socket causing the + real-time-html WebSocket server to progressively consume a lot more memory. + - Fixed memory leak when using getline and follow mode enabled. + - Fixed some buffer initialization issues on read_line() and + perform_tail_follow(). + - Fixed uint types in sha1 files. + +Changes to GoAccess 1.0 - Thursday, June 09, 2016 + + - Added --enable-panel= command line option to display the given + module. + - Added --json-pretty-print command line option to output pretty json. + - Added --log-format= command-line shortcuts for standard log + formats. + - Added --origin command line option to match the origin WebSocket header. + - Added --output= as a shortcut to --output-format. + - Added a complete real-time functionality to the HTML output. + - Added an option to set the max number of items to show per panel. + - Added D3 Visualziations to the HTML dashboard. + - Added metadata metrics to the each of the panels (JSON output) + - Added option to specify time distribution specificity. + - Added the ability to download a JSON file from the HTML report. + - Added the ability to output multiple formats on a single log parse. + - Added the ability to set the date specificity in hours. + - Added the ability to sort all HTML tables on all panels. + - Added the ability to specify a custom CSS and JS file to the HTML report. + - Added user-agents to the JSON output per each host. + - Added "Vivaldi" to the list of browsers. + - Bootstrapify the HTML dashboard. + - Changed configure.ac to use LDFLAGS instead of CFLAGS where applicable. + - Changed default terminal color scheme to 256 Monokai if terminal supports 256 colors. + - Changed GoAccess license to The MIT License (MIT) + - Changed the visitors panel to display its dates continuously instead of top. + - Default to 256 Monokai color scheme if terminal supports 256 colors. + - Default to display HTTP method/protocol (if applicable). + - Display the children's Max. T.S. as the parent's top Max. T.S. + - Ensure the parent's Avg. T.S. displays parent's Cum. T.S. over parent's Hits. + - Fixed color issue when switching from the color scheme dialog. + - Fixed cross platform build issue when ncurses is built with and without + termlib=tinfo. + - Fixed curses header window issue where it wouldn't clear out on small + window sizes. + - Fixed issue where tail mode wouldn't parse full lines using getline(). + - Fixed minor background color issue when using ncurses 6. + - Fixed possible division by zero when calculating percentage. + - Fixed singly link list node removal. + - Fixed still reachable memory leak on GeoIP cleanup (geoip legacy >= 1.4.7). + - Fixed various Valgrind's still reachable memory leaks. + - Removed -Wredundant-decls. + +Changes to GoAccess 0.9.8 - Monday, February 29, 2016 + + - Added a more complete list of static extensions to the config file. + - Added "Android 6.0 Marshmallow" to the list of OSs. + - Added --no-tab-scroll command line option to disable scroll through panels + on TAB. + - Added the first and last log dates to the overall statistics panel. + - Ensure GoAccess links correctly against libtinfo. + - Ensure static content is case-insensitive verified. + - Fixed bandwidth overflow issue (numbers > 2GB on non-x86_64 arch). + - Fixed broken HTML layout when html-method/protocol is missing in config file. + - Refactored parsing and display of available modules/panels. + +Changes to GoAccess 0.9.7 - Monday, December 21, 2015 + + - Added "Squid native" log format to the config file. + - Fixed integer overflow when getting total bandwidth using the on-disk + storage. + - Fixed issue where a timestamp was stored as date under the visitors panel. + - Fixed issue where config dialog fields were not cleared out on select. + - Fixed issue where "Virtual Hosts" menu item wasn't shown in the HTML sidebar. + +Changes to GoAccess 0.9.6 - Tuesday, October 27, 2015 + + - Added --dcf command line option to view the default config file path. + - Added --ignore-status the ability to ignore parsing status codes. + - Added "Darwin" to the list of OSs. + - Fixed segfault when appending data to a log (follow) without virtualhosts. + +Changes to GoAccess 0.9.5 - Thursday, October 22, 2015 + + - Added major performance improvements to the default storage when parsing and + storing data (~%44 less memory, ~37% faster). + - Added the ability to parse virtual hosts and a new panel to display metrics + per virtual host. + - Added the ability to parse HTTP/2 requests. + - Added the ability to use GNU getline() to parse full line requests. + - Added the ability to output debug info if a log file is specified, even + without --enable-debug. + - Added OS X "El Capitan". + - Added WebDav HTTP methods and HTTP status from RFC 2518 and RFC 3253. + - Fixed detection of some Googlebots. + - Fixed issue where time served metrics were not shown when loading persisted + data. + - Fixed linker error on OSX: ld: library not found for -lrt. + - Fixed percentage on the HTML output when excluding IPs. + - Removed GLib dependency and refactored storage functionality. By removing + this dependency, GoAccess is able to store data in a more efficient manner, + for instance, it avoids storing integer data as void* (generic typing), thus + greatly improving memory consumption for integers. + +Changes to GoAccess 0.9.4 - Tuesday, September 08, 2015 + + - Added --all-static-files command line option to parse static files + containing a query string. + - Added --invalid-requests command line option to log invalid requests to a file. + - Added additional overall metric - total valid requests. + - Added "%~" specifier to move forward through a log string until a non-space + char is found. + - Added the ability to parse native Squid access.log format. + - Fixed a few issues in the configuration script. + - Fixed inability to parse color due to a missing POSIX extension. + "ERR:Invalid bg/fg color pairs" + +Changes to GoAccess 0.9.3 - Wednesday, August 26, 2015 + + - Added --no-column-names command line option to disable column name metrics. + - Added a default color palette (Monokai) to the config file. + - Added AWS Elastic Load Balancing to the list of predefined log/date/time + formats. + - Added CloudFlare status codes. + - Added column headers for every enabled metric on each panel. + - Added cumulative time served metric. + - Added "DragonFly" BSD to the list of OSs. + - Added maximum time served metric (slowest running requests). + - Added "Slackbot" to the list of crawlers/browsers. + - Added the ability to parse the query string specifier "%q" from a log file. + - Added the ability to process logs incrementally. + - Added the ability to set custom colors on the terminal output. + - Disabled REFERRERS by default. + - Ensure bandwidth metric is displayed only if %b specifier is parsed. + - Fixed issue where the --sort-panel option wouldn't sort certain panels. + - Fixed several compiler warnings. + - Set predefined static files when no config file is used. + - Updated "Windows 10" user agent from 6.4 (wrong) to 10.0.(actual) + +Changes to GoAccess 0.9.2 - Monday, July 06, 2015 + + - Added ability to fully parse browsers that contain spaces within a token. + - Added multiple user agents to the list of browsers. + - Added the ability to handle time served in milliseconds as a decimal number + `%L`. + - Added the ability to parse a timestamp in microseconds. + - Added the ability to parse Google Cloud Storage access logs. + - Added the ability to set a custom title and header in the HTML report. + - Added "%x" as timestamp log-format specifier. + - Ensure agents" hash table is destroyed upon exiting the program. + - Ensure "Game Systems" are processed correctly. + - Ensure visitors panel header is updated depending if crawlers are parsed or + not. + - Fixed issue where the date value was set as time value in the config + dialog. + - Fixed memory leak in the hits metrics when using the in-memory storage + (GLib). + +Changes to GoAccess 0.9.1 - Tuesday, May 26, 2015 + + - Added --hl-header command line option to highlight active panel. + - Added "Applebot" to the list of web crawlers. + - Added "Microsoft Edge" to the list of browsers. + - Added additional Nginx-specific status codes. + - Ensure dump_struct is used only if using __GLIBC__. + - Ensure goaccess image has an alt attribute on the HTML output for valid + HTML5. + - Ensure the config file path is displayed when something goes wrong (FATAL). + - Ensure there is a character indicator to see which panel is active. + - Fixed Cygwin compile issue attempting to use -rdynamic. + - Fixed issue where a single IP did not get excluded after an IP range. + - Fixed issue where requests showed up in the wrong view even when + --no-query-string was used. + - Fixed issue where some browsers were not recognized or marked as "unknown". + - Fixed memory leak when excluding an IP range. + - Fixed overflows on sort comparison functions. + - Fixed segfault when using on-disk storage and loading persisted data with -a. + - Removed keyphrases menu item from HTML output. + - Split iOS devices from Mac OS X. + +Changes to GoAccess 0.9 - Thursday, March 19, 2015 + + - Added --geoip-database command line option for GeoIP Country/City IPv6. + - Added "Windows 10 (v6.4)" to the real windows user agents. + - Added ability to double decode an HTTP referer and agent. + - Added ability to sort views through the command line on initial load. + - Added additional data values to the backtrace report. + - Added additional graph to represent the visitors metric on the HTML output. + - Added AM_PROG_CC_C_O to configure.ac + - Added "Android Lollipop" to the list of operating systems. + - Added "average time served" metric to all panels. + - Added "bandwidth" metric to all panels. + - Added command line option to disable summary metrics on the CSV output. + - Added numeric formatting to the HTML output to improve readability. + - Added request method specifier to the default W3C log format. + - Added the ability to ignore parsing and displaying given panel(s). + - Added the ability to ignore referer sites from being counted. A good case + scenario is to ignore own domains. i.e., owndomain.tld. This also allows + ignoring hosts using wildcards. For instance, *.mydomain.tld or www.mydomain.* + or www?.mydomain.tld + - Added time/hour distribution module. e.g., 00-23. + - Added "visitors" metrics to all panels. + - Changed AC_PREREQ macro version so it builds on old versions of autoconf. + - Changed GEOIP database load to GEOIP_MEMORY_CACHE for faster lookups. + - Changed maximum number of choices to display per panel to 366 from 300. + - Ensure config file is read from home dir if unable to open it from + %sysconfdir% path. + - Fixed array overflows when exceeding MAX_* limits on command line options. + - Fixed a SEGFAULT where sscanf could not handle special chars within the + referer. + - Fixed character encoding on geolocation output (ISO-8859 to UTF8). + - Fixed issue on wild cards containing "?" at the end of the string. + - Fixed issue where a "Nothing valid to process" error was triggered when the + number of invalid hits was equal to the number of valid hits. + - Fixed issue where outputting to a file left a zero-byte file in pwd. + - Improved parsing of operating systems. + - Refactored log parser so it allows with ease the addition of new modules. + This also attempts to decouple the core functionality from the rendering + functions. It also gives the flexibility to add children metrics to root + metrics for any module. e.g., Request A was visited by IP1, IP2, IP3, etc. + - Restyled HTML output. + +Changes to GoAccess 0.8.5 - Sunday, September 14, 2014 + + - Fixed SEGFAULT when parsing a malformed request that doesn't have HTTP + status. + +Changes to GoAccess 0.8.4 - Monday, September 08, 2014 + + - Added --444-as-404 command line option to handle nginx non-standard status + code 444 as 404. + - Added --4xx-to-unique-count command line option to count client errors (4xx) + to the unique visitors count. Now by default it omits client errors (4xx) + from being added to the unique visitors count as they are probably not welcomed + visitors. 4xx errors are always counted in panels other than visitors, OS & + browsers. + - Added and updated operating systems, and browsers. + - Added excluded IP hits count to the general statistics panel on all reports. + - Added HTTP nonstandard code "444" to the status code list. + - Fixed compile error due to missing include for type + off_t (gcc 4.1). + - Fixed issue when excluding IPv4/v6 ranges. + - Removed request status field restriction. This allows parsing logs that + contain only a valid date, IPv4/6 and host. + +Changes to GoAccess 0.8.3 - Monday, July 28, 2014 + + - Fixed SEGFAULT when parsing a CLF log format and using --ignore-crawlers. + - Fixed parsing conflict between some Opera browsers and Chrome. + - Fixed parsing of several feed readers that are Firefox/Safari-based. + - Fixed Steam detection. + - Added Huawei to the browser's list and removed it from the OS's list. + +Changes to GoAccess 0.8.2 - Monday, July 20, 2014 + + - Added --version command line option. + - Added --ignore-crawlers command line option to ignore crawlers. + - Added ability to parse dates containing whitespaces in between, + e.g., "Jul 15 20:13:59" (syslog format). + - Added a variety of browsers, game systems, feed readers, and podcasts. + - Added missing up/down arrows to the help section. + - Added the ability to ignore multiple IPv4/v6 and IP ranges. + - Added the PATCH method according to RFC 5789. + - Fixed GeoLocation percent issue for the JSON, CSV and HTML outputs. + - Fixed memory leak when excluding one or multiple IPs. + +Changes to GoAccess 0.8.1 - Monday, June 16, 2014 + + - Added ability to add/remove static files by extension through the config + file. + - Added ability to print backtrace on segmentation fault. + - Escaped JSON strings correctly according to [RFC4627]. + - Fixed encoding issue when extracting keyphrases for some HTTP referrers. + - Fixed issue where HTML bar graphs were not shown due to numeric locale. + - Fixed issue with URIs containing "\r?\n" thus breaking the corresponding + output. + - Make sure request string is URL decoded on all outputs. + Changes to GoAccess 0.8 - Tuesday, May 20, 2014 - * Added APT-HTTP to the list of browsers. - * Added data persistence and ability to load data from disk. - * Added IE11 to the list of browsers. - * Added IEMobile to the list of browsers. - * Added multiple command line options. - * Added Nagios check_http to the list of browsers. - * Added parsing progress metrics - total requests / requests per second. - * Added the ability to parse a GeoLiteCity.dat to get the city given an IPv4. - * Change the way the configuration file is parsed. - This will parse all configuration options under ~/.goaccessrc or the - specified config file and will feed getopt_long with the extracted - key/value pairs. This also allows the ability to have comments on the config - file which won't be overwritten. - * Ensure autoconf determines the location of ncurses headers. - * Fixed issue where geo_location_data was NULL. - * Fixed issue where GoAccess did not run without a tty allocated to it. - * Fixed potential memory leak on --log-file realpath(). - * Fixed Solaris build errors. - * Implemented an on-memory hash database using Tokyo Cabinet. - This implementation allows GoAccess not to rely on GLib's hash table - if one is needed. - * Implemented large file support using an on-disk B+ Tree database. - This implementation allows GoAccess not to hold everything in memory - but instead it uses an on-disk B+ Tree database. - * Trimmed leading and trailing whitespaces from keyphrases module. + + - Added APT-HTTP to the list of browsers. + - Added data persistence and ability to load data from disk. + - Added IE11 to the list of browsers. + - Added IEMobile to the list of browsers. + - Added multiple command line options. + - Added Nagios check_http to the list of browsers. + - Added parsing progress metrics - total requests / requests per second. + - Added the ability to parse a GeoLiteCity.dat to get the city given an IPv4. + - Changed the way the configuration file is parsed. This will parse all + configuration options under ~/.goaccessrc or the specified config file and + will feed getopt_long with the extracted key/value pairs. This also allows the + ability to have comments on the config file which won't be overwritten. + - Ensure autoconf determines the location of ncurses headers. + - Fixed issue where geo_location_data was NULL. + - Fixed issue where GoAccess did not run without a tty allocated to it. + - Fixed potential memory leak on --log-file realpath(). + - Fixed Solaris build errors. + - Implemented an on-memory hash database using Tokyo Cabinet. This + implementation allows GoAccess not to rely on GLib's hash table if one is + needed. + - Implemented large file support using an on-disk B+ Tree database. This + implementation allows GoAccess not to hold everything in memory but instead + it uses an on-disk B+ Tree database. + - Trimmed leading and trailing whitespaces from keyphrases module. Changes to GoAccess 0.7.1 - Monday, February 17, 2014 - * Added ability to get real OS names using --real-os. (Android, Windows, Mac) - * Added ability to log debug messages to a file. - * Added ability to parse tab-separated log format strings. - * Added ability to support terminals without colors. - * Added ability to turn off color output by using --no-color flag. - * Added command line option to append HTTP method to request. - * Added command line option to append HTTP protocol to request. - * Added long options to command-line. - * Added missing Win 9x 4.90 (Windows Me) user-agent. - * Added missing Windows RT user-agent. - * Ensure mouse click does not reset expanded module if it is the same. - * Fixed Amazon CloudFront tab-separated log format. - * Fixed "FreeBSD style" ncursesw built into system. - * Fixed HTML report issue where data cell would not wrap. - * Fixed issue when isatty() could not find a valid file descriptor. - * Fixed SymbianOS user-agent and retrieve its version. + - Added --no-color command line option to turn off color output. + - Added --real-os command line option to get real OS names, e.g., + "Android, Windows, Mac". + - Added ability to log debug messages to a file. + - Added ability to parse tab-separated log format strings. + - Added ability to support terminals without colors. + - Added command line option to append HTTP method to request. + - Added command line option to append HTTP protocol to request. + - Added long options to command-line. + - Added missing "Win 9x 4.90" (Windows Me) user-agent. + - Added missing Windows RT user-agent. + - Ensure mouse click does not reset expanded module if it is the same. + - Fixed Amazon CloudFront tab-separated log format. + - Fixed "FreeBSD style" ncursesw built into system. + - Fixed HTML report issue where data cell would not wrap. + - Fixed issue when isatty() could not find a valid file descriptor. + - Fixed SymbianOS user-agent and retrieve its version. Changes to GoAccess 0.7 - Monday, December 15, 2013 - * Added a command line option to ignore request query strings. - * Added additional compiler flags & fixed several warnings. - * Added additional static file extensions. - * Added country per IP to HOSTS module (HTML & JSON). - * Added DEBUG mode to Makefile & -O2 to default release. - * Added GEOLOCATION report to all outputs - includes continents/countries. - * Added IP resolver to HTML and JSON output. - * Added module numbers to each module header. - * Added the ability to output JSON and CSV. - * Added Windows NT 6.3 (Win 8.1) to the list. - * Fixed buffer overflow issue with realpath. - * New HTML report - HTML5 + CSS styles. - * Properly split request line into the three request modules. + - Added a command line option to ignore request query strings. + - Added additional compiler flags & fixed several warnings. + - Added additional static file extensions. + - Added country per IP to HOSTS module (HTML & JSON). + - Added DEBUG mode to Makefile & -O2 to default release. + - Added GEOLOCATION report to all outputs - includes continents/countries. + - Added IP resolver to HTML and JSON output. + - Added module numbers to each module header. + - Added the ability to output JSON and CSV. + - Added Windows NT 6.3 (Win 8.1) to the list. + - Fixed buffer overflow issue with realpath. + - New HTML report - HTML5 + CSS styles. + - Properly split request line into the three request modules. Changes to GoAccess 0.6.1 - Monday, October 07, 2013 - * Added active module indication by name. - * Added additional crawlers to the list. - * Added custom configuration file option. - * Added human-readable string when unable to open log. - * Added missing include when compiling on OSX 10.6. - * Added optional mouse support to the main dashboard. - * Added the ability to select active module by number (keys). - * Added the rest of HTTP methods according to RFC2616. - * Changed referring site sscanf format to process multiple URLs. - * Changed the default color scheme to monochrome. - * Fixed issue where %T was not processing floating-point numbers. - * Fixed percentage issue for browsers and os modules. - * Fixed SIGSEGV when reading from stdin to stdout. - * Improved performance when expanding a module. - * Reduced memory consumption by decreasing number of dns threads. - * Removed ^UP/^DOWN due to a key mapping conflict. + - Added active module indication by name. + - Added additional crawlers to the list. + - Added custom configuration file option. + - Added human-readable string when unable to open log. + - Added missing include when compiling on OSX 10.6. + - Added optional mouse support to the main dashboard. + - Added the ability to select active module by number (keys). + - Added the rest of HTTP methods according to RFC2616. + - Changed referring site sscanf format to process multiple URLs. + - Changed the default color scheme to monochrome. + - Fixed issue where %T was not processing floating-point numbers. + - Fixed percentage issue for browsers and os modules. + - Fixed SIGSEGV when reading from stdin to stdout. + - Improved performance when expanding a module. + - Reduced memory consumption by decreasing number of dns threads. + - Removed ^UP/^DOWN due to a key mapping conflict. Changes to GoAccess 0.6 - Monday, July 15, 2013 - * Moved away from the original pop-up UI to a new expandable - dashboard allowing data to be processed in real-time. - * Added the ability to search across the whole dashboard with the - option to use regular expressions. - * Added the ability to independently sort each module. - * Implemented the ability to parse the time taken to serve the - request, in microseconds and seconds. - * Added a predefined log format/date for the Amazon CloudFront - (Download Distribution). - * Config window now accepts [ENTER] to continue or F10. - * Added parsing/processing indicators. - * Updated the hosts module so it shows the reverse DNS as a - sub node. - * Sanitized HTML output with html entities for special chars. - * Fixed issue where Opera +15 was identified as Chrome. - * Fixed a bunch of minor fixes and changes. - * Added and updated list of browsers and operating systems. - * Improved memory usage and better performance in general. + - Added a bunch of minor fixes and changes. + - Added and updated list of browsers and operating systems. + - Added a predefined log format/date for the Amazon CloudFront (Download + Distribution). + - Added parsing/processing indicators. + - Added the ability to independently sort each module. + - Added the ability to search across the whole dashboard with the option to + use regular expressions. + - Config window now accepts [ENTER] to continue or F10. + - Fixed issue where Opera +15 was identified as Chrome. + - Implemented the ability to parse the time taken to serve the request, in + microseconds and seconds. + - Improved memory usage and better performance in general. + - Moved away from the original pop-up UI to a new expandable dashboard + allowing data to be processed in real-time. + - Sanitized HTML output with html entities for special chars. + - Updated the hosts module so it shows the reverse DNS as a sub node. Changes to GoAccess 0.5 - Monday, June 04, 2012 - * Added the ability to parse a custom format string. - * Added ability to output a full stats report to a file. - * Added support for IPv6 - * Fixed issue on Opera agents where version was not recognized correctly. - * Fixed issue on empty Google query strings. - * Fixed google cache key-phrases. - * Added a new include sys/socket.h - BSD - * Added a key shortcut to scroll top/bottom. - * Fixed other minor fixes and changes. + - Added ability to output a full stats report to a file. + - Added a key shortcut to scroll top/bottom. + - Added a new include sys/socket.h - BSD + - Added support for IPv6 + - Added the ability to parse a custom format string. + - Fixed google cache key-phrases. + - Fixed issue on empty Google query strings. + - Fixed issue on Opera agents where version was not recognized correctly. + - Fixed other minor fixes and changes. Changes to GoAccess 0.4.2 - Monday, January 03, 2011 - * Fixed a minor bug when adding monthly totals on visitors subwin. - * UTF-8 support has been implemented. Now it should handle properly - wide-character/UTF-8. Run ./configure --enable-utf8 - * Since GoAccess does not link to librt, -lrt has been removed. - (OS X doesn't include librt) + - Added UTF-8 support. Now it should handle properly wide-character/UTF-8. + Run ./configure --enable-utf8 + - Fixed a minor bug when adding monthly totals on visitors subwin. + - Removed -lrt since GoAccess does not link to librt. (OS X doesn't include + librt) Changes to GoAccess 0.4.1 - Monday, December 13, 2010 - * Ability to pass a flag to ./configure so GeoIP can be enabled if - needed. - * More flexibility when resizing the terminal. Should work fine with - the standard 80x24. - * Implemented a pipeline from stdin, so the input doesn't have to be - only a file. + - Added more flexibility when resizing the terminal. Should work fine with + the standard 80x24. + - Added the ability to pass a flag to ./configure so GeoIP can be enabled if + needed. + - Implemented a pipeline from stdin, so the input doesn't have to be only a + file. Changes to GoAccess 0.4 - Tuesday, November 30, 2010 - * Rewrote hash tables iterative code to avoid the use of GHashTableIter, - this way it works with all GLib > 2.0.0. - * Implemented list of agents for specific hosts. - * Added graphs to the unique_visitors subwin. - * Various bug fixes and code cleanups (mainly in the subwin modules). - * Bandwidth per day, and host was implemented as well. + - Added graphs to the unique_visitors subwin. + - Implemented bandwidth per day, and host. + - Implemented list of agents for specific hosts. + - Rewrote hash tables iterative code to avoid the use of GHashTableIter, this + way it works with all GLib > 2.0.0. + - Various bug fixes and code cleanups (mainly in the subwin modules). Changes to GoAccess 0.3.3 - Monday, September 27, 2010 - * Fixed a request size parsing issue. Due to malformed syntax on the - HTTP protocol, bandwidth was reset to 0. - Ex. "HEAD /" 400 20392 - * Fixed a segfault when goaccess was executed without any options but - with an additional unknown argument. - * Tarball's filename was changed. + - Changed tarball's filename. + - Fixed a request size parsing issue. Due to malformed syntax on the HTTP + protocol, bandwidth was reset to 0. Ex. "HEAD /" 400 20392 + - Fixed a segfault when goaccess was executed without any options but with an + additional unknown argument. Changes to GoAccess 0.3.2 - Thursday, September 09, 2010 - * Fixed an agent parsing issue. As a result, operating systems were - not properly counted. + - Fixed an agent parsing issue. As a result, operating systems were not + properly counted. Changes to GoAccess 0.3.1 - Friday, September 03, 2010 - * Added a color scheme implementation + - Added a color scheme implementation Changes to GoAccess 0.3 - Sunday, August 29, 2010 - * Fixed invalid entries when parsing status codes - * Implemented a real support for LFS - Handles files larger than - 2 GiB on 32-bit systems - * Added a more detailed and comprehensive browser and os report - * Fixed a segmentation fault on pop-up window search if haystack was null - * Added bandwidth details for requested files - * Added percentage details on modules 2, 3, 4, 5, 10, 11 - * Implemented support for 'vhost_combined' log format - * Fixed a potential segmentation fault when resizing main window - * Position of data/graphs will change depending on # of hits - * A counter for total requests since initial parse was implemented - * Code cleanups + - Added a counter for total requests since initial parse was implemented + - Added a more detailed and comprehensive browser and os report + - Added bandwidth details for requested files + - Added percentage details on modules 2, 3, 4, 5, 10, 11 + - Code cleanups + - Fixed a potential segmentation fault when resizing main window + - Fixed a segmentation fault on pop-up window search if haystack was null + - Fixed invalid entries when parsing status codes + - Implemented a real support for LFS - Handles files larger than 2 GiB on + 32-bit systems + - Implemented support for "vhost_combined" log format + - Changed position of data/graphs depending on # of hits Changes to GoAccess 0.2 - Sunday, July 25, 2010 - * Implemented real-time statistics (RTS). Data will be appended as the - log file grows. Equivalent to 'tail -f' on Unix systems - * Added a keyphrases report coming from Google search engine. - This includes, raw, cache, and translation queries. - * Implemented screen resize functionality - * Various small speed increases & code cleanup - * Fixed a memory leak when invalid entries were parsed - * Simplify the "process_unique_data" function - (Thanks to Florian Forster contribution) - * Simplify creation of the "unique visitors" hash-key. - (Thanks to Florian Forster contribution) - * Fix a potential buffer overflow. - (Thanks to Florian Forster contribution) - -Changes to GoAccess 0.1.2 - Monday, July 12 2010 - - * Fixed a segmentation fault when parsing logs with unusual request type. - Ex. "GET HTTP/1.1 HTTP/1.1" - -Changes to GoAccess 0.1.1 - Saturday, July 10 2010 - - * Added an enhanced error handling - * Added Glibc LFS - * Added an extra macro on configure.ac to check against GHashTableIter. - ./configure might not check for glib 2.16 that introduced 'GHashTableIter'. - * Clean up code a little bit - * Fixed a segmentation fault when displaying the help text on x86_64. - (Thanks to Florian Forster contribution) - * Fixed casts associated with "g_hash_table_iter_next". - (Thanks to Florian Forster contribution) - * Fixed two format strings. (If the error was ever triggered, it'd most - likely lead to a segfault.) - (Thanks to Florian Forster contribution) - * Fixed assignments in conditions. In case the assignment is actually - intended, put extra parenthesis around it. This will shut GCC - (and others) up. - (Thanks to Florian Forster contribution) - * Fixed comparison between signed and unsigned integer types. - (Thanks to Florian Forster contribution) - * Fixed includes. - (Thanks to Florian Forster contribution) - * Fixed function declarations. - (Thanks to Florian Forster contribution) - -Tuesday, July 06, 21:12:29 2010 Gerardo Orellana (goaccess at prosoftcorp.com) - - * Initial release 0.1 + - Added a keyphrases report coming from Google search engine. This includes, + raw, cache, and translation queries. + - Fixed a memory leak when invalid entries were parsed + - Fixed a potential buffer overflow. + - Implemented real-time statistics (RTS). Data will be appended as the log + file grows. Equivalent to "tail -f" on Unix systems + - Implemented screen resize functionality + - Simplified creation of the "unique visitors" hash-key. + - Simplified the "process_unique_data" function + - Various small speed increases & code cleanup + +Changes to GoAccess 0.1.2 - Monday, July 12, 2010 + + - Fixed a segmentation fault when parsing logs with unusual request type. Ex. + "GET HTTP/1.1 HTTP/1.1" + +Changes to GoAccess 0.1.1 - Saturday, July 10, 2010 + + - Added an enhanced error handling + - Added an extra macro on configure.ac to check against GHashTableIter. + ./configure might not check for glib 2.16 that introduced "GHashTableIter". + - Added Glibc LFS + - Cleaned up code a little bit + - Fixed a segmentation fault when displaying the help text on x86_64. + - Fixed assignments in conditions. In case the assignment is actually intended + put extra parenthesis around it. This will shut GCC (and others) up. + - Fixed casts associated with "g_hash_table_iter_next". + - Fixed comparison between signed and unsigned integer types. + - Fixed function declarations. + - Fixed includes. + - Fixed two format strings. (If the error was ever triggered, it'd most + likely lead to a segfault) + +Changes to GoAccess 0.1 - Tuesday, July 06, 2010 + + - Initial release 0.1 diff --git a/DOCKER.md b/DOCKER.md new file mode 100644 index 0000000000..e5414af2e4 --- /dev/null +++ b/DOCKER.md @@ -0,0 +1,31 @@ + +# Docker image features + +* This command uses the language set for this system. If that does not support it will be output in English. [**Supported Language**](https://github.com/allinurl/goaccess/raw/master/po/LINGUAS) + +* This image supports building on the ARM architecture (e.g. Raspberry Pi) + +* Do you want to change the timezone? Use the `-e` option to pass the time-zone setting to Docker. (e.g. `-e TZ="America/New_York"`) + +* The container is built with geo-location support (see [the manual](https://goaccess.io/man#options)). To enable the respective panel, mount the geolocation database using `-v /path/to/GeoLite2-City.mmdb:/GeoLite2-City.mmdb` and specify `--geoip-database /GeoLite2-City.mmdb` when running GoAccess. + +* If you made changes to the config file after building the image, you don't have to rebuild from scratch. Simply restart the container: + +``` + docker restart goaccess +``` + +* If you had already run the container, you may have to stop and remove it first: + +``` + docker stop goaccess + docker rm goaccess +``` + +* The container and image can be completely removed as follows: + +``` + docker stop goaccess + docker rm goaccess + docker rmi allinurl/goaccess +``` diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..e59373d4fc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM alpine:3 AS builds +RUN apk add --no-cache \ + autoconf \ + automake \ + build-base \ + clang \ + clang-static \ + gettext-dev \ + gettext-static \ + git \ + libmaxminddb-dev \ + libmaxminddb-static \ + libressl-dev \ + linux-headers \ + ncurses-dev \ + ncurses-static \ + tzdata + +# GoAccess +COPY . /goaccess +WORKDIR /goaccess +RUN autoreconf -fiv +RUN CC="clang" CFLAGS="-O3 -static" LIBS="$(pkg-config --libs openssl)" ./configure --prefix="" --enable-utf8 --with-openssl --enable-geoip=mmdb +RUN make && make DESTDIR=/dist install + +# Container +FROM busybox:musl +COPY --from=builds /dist / +COPY --from=builds /usr/share/zoneinfo /usr/share/zoneinfo +VOLUME /var/www/goaccess +EXPOSE 7890 +ENTRYPOINT ["/bin/goaccess"] +CMD ["--help"] diff --git a/Dockerfile.debian-12 b/Dockerfile.debian-12 new file mode 100644 index 0000000000..f811e0f105 --- /dev/null +++ b/Dockerfile.debian-12 @@ -0,0 +1,17 @@ +# Used to have all compile dependencies isolated in a container image. +FROM debian:12 + +RUN apt update -qqq +RUN apt install -y \ + libncurses-dev \ + libssl-dev \ + libmaxminddb-dev \ + build-essential \ + autoconf \ + gettext \ + autopoint + +# GoAccess +WORKDIR /goaccess + +ENTRYPOINT ["./build-dynamic.sh"] diff --git a/Makefile.am b/Makefile.am index 23b0691164..5c3cb02439 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,73 +1,262 @@ #AUTOMAKE_OPTIONS = foreign bin_PROGRAMS = goaccess +AUTOMAKE_OPTIONS = subdir-objects -confdir = $(sysconfdir) +dist_noinst_DATA = \ + resources/tpls.html \ + resources/css/app.css \ + resources/css/bootstrap.min.css \ + resources/css/fa.min.css \ + resources/js/app.js \ + resources/js/charts.js \ + resources/countries-110m.json \ + resources/js/d3.v7.min.js \ + resources/js/topojson.v3.min.js \ + resources/js/hogan.min.js + +noinst_PROGRAMS = bin2c +bin2c_SOURCES = src/bin2c.c + +BUILT_SOURCES = \ + src/tpls.h \ + src/bootstrapcss.h \ + src/facss.h \ + src/appcss.h \ + src/d3js.h \ + src/topojsonjs.h \ + src/hoganjs.h \ + src/countries110m.h \ + src/chartsjs.h \ + src/appjs.h + +CLEANFILES = \ + src/tpls.h \ + src/bootstrapcss.h \ + src/facss.h \ + src/appcss.h \ + src/d3js.h \ + src/topojsonjs.h \ + src/hoganjs.h \ + src/countries110m.h \ + src/chartsjs.h \ + src/appjs.h \ + resources/tpls.html.tmp \ + resources/countries-110m.json.tmp \ + resources/css/bootstrap.min.css.tmp \ + resources/css/fa.min.css.tmp \ + resources/css/app.css.tmp \ + resources/js/d3.v7.min.js.tmp \ + resources/js/topojson.v3.min.js.tmp \ + resources/js/hogan.min.js.tmp \ + resources/js/charts.js.tmp \ + resources/js/app.js.tmp + +# Tpls +src/tpls.h: bin2c$(EXEEXT) $(srcdir)/resources/tpls.html +if HAS_SEDTR + cat $(srcdir)/resources/tpls.html | sed "s/^[[:space:]]*//" | sed "/^$$/d" | tr -d "\r\n" > $(srcdir)/resources/tpls.html.tmp + ./bin2c $(srcdir)/resources/tpls.html.tmp src/tpls.h tpls +else + ./bin2c $(srcdir)/resources/tpls.html src/tpls.h tpls +endif +# countries.json +src/countries110m.h: bin2c$(EXEEXT) $(srcdir)/resources/countries-110m.json +if HAS_SEDTR + cat $(srcdir)/resources/countries-110m.json | sed "s/^[[:space:]]*//" | sed "/^$$/d" | tr -d "\r\n" > $(srcdir)/resources/countries-110m.json.tmp + ./bin2c $(srcdir)/resources/countries-110m.json.tmp src/countries110m.h countries_json +else + ./bin2c $(srcdir)/resources/countries-110m.json src/countries110m.h countries_json +endif +# Bootstrap +src/bootstrapcss.h: bin2c$(EXEEXT) $(srcdir)/resources/css/bootstrap.min.css +if HAS_SEDTR + cat $(srcdir)/resources/css/bootstrap.min.css | sed "s/^[[:space:]]*//" | sed "/^$$/d" | tr -d "\r\n" > $(srcdir)/resources/css/bootstrap.min.css.tmp + ./bin2c $(srcdir)/resources/css/bootstrap.min.css.tmp src/bootstrapcss.h bootstrap_css +else + ./bin2c $(srcdir)/resources/css/bootstrap.min.css src/bootstrapcss.h bootstrap_css +endif +# Font Awesome +src/facss.h: bin2c$(EXEEXT) $(srcdir)/resources/css/fa.min.css +if HAS_SEDTR + cat $(srcdir)/resources/css/fa.min.css | sed "s/^[[:space:]]*//" | sed "/^$$/d" | tr -d "\r\n" > $(srcdir)/resources/css/fa.min.css.tmp + ./bin2c $(srcdir)/resources/css/fa.min.css.tmp src/facss.h fa_css +else + ./bin2c $(srcdir)/resources/css/fa.min.css src/facss.h fa_css +endif +# App.css +src/appcss.h: bin2c$(EXEEXT) $(srcdir)/resources/css/app.css +if HAS_SEDTR + cat $(srcdir)/resources/css/app.css | sed "s/^[[:space:]]*//" | sed "/^$$/d" | tr -d "\r\n" > $(srcdir)/resources/css/app.css.tmp + ./bin2c $(srcdir)/resources/css/app.css.tmp src/appcss.h app_css +else + ./bin2c $(srcdir)/resources/css/app.css src/appcss.h app_css +endif +# D3.js +src/d3js.h: bin2c$(EXEEXT) $(srcdir)/resources/js/d3.v7.min.js +if HAS_SEDTR + cat $(srcdir)/resources/js/d3.v7.min.js | sed "s/^[[:space:]]*//" | sed "/^$$/d" | tr -d "\r\n" > $(srcdir)/resources/js/d3.v7.min.js.tmp + ./bin2c $(srcdir)/resources/js/d3.v7.min.js.tmp src/d3js.h d3_js +else + ./bin2c $(srcdir)/resources/js/d3.v7.min.js src/d3js.h d3_js +endif +# topojson.js +src/topojsonjs.h: bin2c$(EXEEXT) $(srcdir)/resources/js/topojson.v3.min.js +if HAS_SEDTR + cat $(srcdir)/resources/js/topojson.v3.min.js | sed "s/^[[:space:]]*//" | sed "/^$$/d" | tr -d "\r\n" > $(srcdir)/resources/js/topojson.v3.min.js.tmp + ./bin2c $(srcdir)/resources/js/topojson.v3.min.js.tmp src/topojsonjs.h topojson_js +else + ./bin2c $(srcdir)/resources/js/topojson.v3.min.js src/topojsonjs.h topojson_js +endif +# Hogan.js +src/hoganjs.h: bin2c$(EXEEXT) $(srcdir)/resources/js/hogan.min.js +if HAS_SEDTR + cat $(srcdir)/resources/js/hogan.min.js | sed "s/^[[:space:]]*//" | sed "/^$$/d" | tr -d "\r\n" > $(srcdir)/resources/js/hogan.min.js.tmp + ./bin2c $(srcdir)/resources/js/hogan.min.js.tmp src/hoganjs.h hogan_js +else + ./bin2c $(srcdir)/resources/js/hogan.min.js src/hoganjs.h hogan_js +endif +# Charts.js +src/chartsjs.h: bin2c$(EXEEXT) $(srcdir)/resources/js/charts.js +if HAS_SEDTR + cat $(srcdir)/resources/js/charts.js | sed -E "s@(,|;)[[:space:]]*//..*@\1@g" | sed -E "s@^[[:space:]]*//..*@@g" | sed "s/^[[:space:]]*//" | sed "/^$$/d" | tr -d "\r\n" > $(srcdir)/resources/js/charts.js.tmp + ./bin2c $(srcdir)/resources/js/charts.js.tmp src/chartsjs.h charts_js +else + ./bin2c $(srcdir)/resources/js/charts.js src/chartsjs.h charts_js +endif +if DEBUG + ./bin2c $(srcdir)/resources/js/charts.js src/chartsjs.h charts_js +endif +# App.js +src/appjs.h: bin2c$(EXEEXT) $(srcdir)/resources/js/app.js +if HAS_SEDTR + cat $(srcdir)/resources/js/app.js | sed -E "s@(,|;)[[:space:]]*//..*@\1@g" | sed -E "s@^[[:space:]]*//..*@@g" | sed "s/^[[:space:]]*//" | sed "/^$$/d" | tr -d "\r\n" > $(srcdir)/resources/js/app.js.tmp + ./bin2c $(srcdir)/resources/js/app.js.tmp src/appjs.h app_js +else + ./bin2c $(srcdir)/resources/js/app.js src/appjs.h app_js +endif +if DEBUG + ./bin2c $(srcdir)/resources/js/app.js src/appjs.h app_js +endif + +confdir = $(sysconfdir)/goaccess dist_conf_DATA = config/goaccess.conf +dist_conf_DATA += config/browsers.list +dist_conf_DATA += config/podcast.list goaccess_SOURCES = \ - browsers.c \ - browsers.h \ - commons.c \ - commons.h \ - csv.c \ - csv.h \ - error.c \ - error.h \ - gdashboard.c \ - gdashboard.h \ - gdns.c \ - gdns.h \ - gmenu.c \ - gmenu.h \ - goaccess.c \ - goaccess.h \ - json.c \ - json.h \ - opesys.c \ - opesys.h \ - options.c \ - options.h \ - output.c \ - output.h \ - parser.c \ - parser.h \ - settings.c \ - settings.h \ - ui.c \ - ui.h \ - util.c \ - util.h \ - xmalloc.c \ - xmalloc.h - -if TCB -goaccess_SOURCES += \ - tcabinet.c \ - tcabinet.h -else -goaccess_SOURCES += \ - glibht.c \ - glibht.h + src/base64.c \ + src/base64.h \ + src/browsers.c \ + src/browsers.h \ + src/color.c \ + src/color.h \ + src/commons.c \ + src/commons.h \ + src/csv.c \ + src/csv.h \ + src/error.c \ + src/error.h \ + src/gdashboard.c \ + src/gdashboard.h \ + src/gdns.c \ + src/gdns.h \ + src/gholder.c \ + src/gholder.h \ + src/gkhash.c \ + src/gkhash.h \ + src/gkmhash.c \ + src/gkmhash.h \ + src/gmenu.c \ + src/gmenu.h \ + src/goaccess.c \ + src/goaccess.h \ + src/gslist.c \ + src/gslist.h \ + src/gstorage.c \ + src/gstorage.h \ + src/gwsocket.c \ + src/gwsocket.h \ + src/json.c \ + src/json.h \ + src/khash.h \ + src/labels.h \ + src/opesys.c \ + src/opesys.h \ + src/options.c \ + src/options.h \ + src/output.c \ + src/output.h \ + src/parser.c \ + src/parser.h \ + src/persistence.c \ + src/persistence.h \ + src/pdjson.c \ + src/pdjson.h \ + src/settings.c \ + src/settings.h \ + src/sort.c \ + src/sort.h \ + src/tpl.c \ + src/tpl.h \ + src/ui.c \ + src/ui.h \ + src/util.c \ + src/util.h \ + src/websocket.c \ + src/websocket.h \ + src/xmalloc.c \ + src/xmalloc.h + +if USE_SHA1 +goaccess_SOURCES += \ + src/sha1.c \ + src/sha1.h +endif + +if USE_MMAP +goaccess_SOURCES += \ + src/win/mman.h \ + src/win/mmap.c endif -if GEOLOCATION -goaccess_SOURCES += \ - geolocation.c \ - geolocation.h +if GEOIP_LEGACY +goaccess_SOURCES += \ + src/geoip1.c \ + src/geoip1.h +endif + +if GEOIP_MMDB +goaccess_SOURCES += \ + src/geoip2.c \ + src/geoip1.h endif if DEBUG -AM_CFLAGS = -DDEBUG -O0 -g -DSYSCONFDIR=\"$(sysconfdir)\" +AM_CFLAGS = -DDEBUG -O0 -DSYSCONFDIR=\"$(sysconfdir)\" else AM_CFLAGS = -O2 -DSYSCONFDIR=\"$(sysconfdir)\" endif -AM_CFLAGS += @GLIB2_CFLAGS@ -AM_CFLAGS += -Wno-long-long -Wall -W -Wnested-externs -Wformat=2 +if WITH_RDYNAMIC +AM_LDFLAGS = -rdynamic +endif + +AM_CFLAGS += -Wall -Wextra -Wnested-externs -Wformat=2 -g AM_CFLAGS += -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations AM_CFLAGS += -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare -AM_CFLAGS += -Wredundant-decls -Wbad-function-cast -Winline -Wcast-align -Wextra -AM_CFLAGS += -Wdeclaration-after-statement -Wno-missing-field-initializers +AM_CFLAGS += -Wbad-function-cast -Wcast-align +AM_CFLAGS += -Wdeclaration-after-statement -Wshadow -Wold-style-definition + +if WITH_ASAN +AM_CFLAGS += -fsanitize=address +endif -goaccess_LDADD = -lm dist_man_MANS = goaccess.1 + +SUBDIRS = po + +ACLOCAL_AMFLAGS = -I m4 + +DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ + +EXTRA_DIST = config.rpath diff --git a/NEWS b/NEWS index 580122b3df..1f8ecb13b7 100644 --- a/NEWS +++ b/NEWS @@ -1,7 +1,113 @@ -Copyright (C) 2009-2013 +Copyright (C) 2009-2024 Gerardo Orellana * Version history: + - 1.9.3 [Friday, May 31, 2024] + . GoAccess 1.9.3 Released. See ChangeLog for new features/bug-fixes. + - 1.9.2 [Friday, April 12, 2024] + . GoAccess 1.9.2 Released. See ChangeLog for new features/bug-fixes. + - 1.9.1 [Tuesday, February 05, 2024] + . GoAccess 1.9.1 Released. See ChangeLog for new features/bug-fixes. + - 1.9 [Tuesday, January 30, 2024] + . GoAccess 1.9 Released. See ChangeLog for new features/bug-fixes. + - 1.8.1 [Tuesday, October 31, 2023] + . GoAccess 1.8.1 Released. See ChangeLog for new features/bug-fixes. + - 1.8 [Saturday, September 30, 2023] + . GoAccess 1.8 Released. See ChangeLog for new features/bug-fixes. + - 1.7.2 [Friday, March 31, 2023] + . GoAccess 1.7.2 Released. See ChangeLog for new features/bug-fixes. + - 1.7.1 [Tuesday, February 28, 2023] + . GoAccess 1.7.1 Released. See ChangeLog for new features/bug-fixes. + - 1.7 [Saturday, December 31 , 2022] + . GoAccess 1.7 Released. See ChangeLog for new features/bug-fixes. + - 1.6.5 [Monday, October 31 , 2022] + . GoAccess 1.6.5 Released. See ChangeLog for new features/bug-fixes. + - 1.6.4 [Friday, September 30 , 2022] + . GoAccess 1.6.4 Released. See ChangeLog for new features/bug-fixes. + - 1.6.3 [Thursday, August 31 , 2022] + . GoAccess 1.6.3 Released. See ChangeLog for new features/bug-fixes. + - 1.6.2 [Thursday, July 14 , 2022] + . GoAccess 1.6.2 Released. See ChangeLog for new features/bug-fixes. + - 1.6.1 [Thursday, June 30 , 2022] + . GoAccess 1.6.1 Released. See ChangeLog for new features/bug-fixes. + - 1.6 [Tuesday, May 31 , 2022] + . GoAccess 1.6 Released. See ChangeLog for new features/bug-fixes. + - 1.5.7 [Thursday, April 28 , 2022] + . GoAccess 1.5.7 Released. See ChangeLog for new features/bug-fixes. + - 1.5.6 [Wednesday, March 30, 2022] + . GoAccess 1.5.6 Released. See ChangeLog for new features/bug-fixes. + - 1.5.5 [Monday, January 31, 2022] + . GoAccess 1.5.5 Released. See ChangeLog for new features/bug-fixes. + - 1.5.4 [Saturday, December 25, 2021] + . GoAccess 1.5.4 Released. See ChangeLog for new features/bug-fixes. + - 1.5.3 [Thursday, November 25, 2021] + . GoAccess 1.5.3 Released. See ChangeLog for new features/bug-fixes. + - 1.5.2 [Tuesday, Sep 28, 2021] + . GoAccess 1.5.2 Released. See ChangeLog for new features/bug-fixes. + - 1.5.1 [Wednesday, Jun 30, 2021] + . GoAccess 1.5.1 Released. See ChangeLog for new features/bug-fixes. + - 1.5 [Wednesday, May 26, 2021] + . GoAccess 1.5 Released. See ChangeLog for new features/bug-fixes. + - 1.4.6 [Sunday, February 28, 2021] + . GoAccess 1.4.6 Released. See ChangeLog for new features/bug-fixes. + - 1.4.5 [Tuesday, January 26, 2021] + . GoAccess 1.4.5 Released. See ChangeLog for new features/bug-fixes. + - 1.4.4 [Monday, January 25, 2021] + . GoAccess 1.4.4 Released. See ChangeLog for new features/bug-fixes. + - 1.4.3 [Friday, December 04, 2020] + . GoAccess 1.4.3 Released. See ChangeLog for new features/bug-fixes. + - 1.4.2 [Monday, November 16, 2020] + . GoAccess 1.4.2 Released. See ChangeLog for new features/bug-fixes. + - 1.4.1 [Monday, November 09, 2020] + . GoAccess 1.4.1 Released. See ChangeLog for new features/bug-fixes. + - 1.4 [Monday, May 18, 2020] + . GoAccess 1.4 Released. See ChangeLog for new features/bug-fixes. + - 1.3 [Friday, November 23, 2018] + . GoAccess 1.3 Released. See ChangeLog for new features/bug-fixes. + - 1.2 [Tuesday, March 07, 2017] + . GoAccess 1.2 Released. See ChangeLog for new features/bug-fixes. + - 1.1.1 [Wednesday, November 23, 2016] + . GoAccess 1.1.1 Released. See ChangeLog for new features/bug-fixes. + - 1.1 [Tuesday, November 08, 2016] + . GoAccess 1.1 Released. See ChangeLog for new features/bug-fixes. + - 1.0.2 [Tuesday, July 05, 2016] + . GoAccess 1.0.2 Released. See ChangeLog for new features/bug-fixes. + - 1.0.1 [Friday, June 17, 2016] + . GoAccess 1.0.1 Released. See ChangeLog for new features/bug-fixes. + - 1.0 [Thursday, June 09, 2016] + . GoAccess 1.0 Released. See ChangeLog for new features/bug-fixes. + - 0.9.8 [Monday, February 29, 2016] + . GoAccess 0.9.8 Released. See ChangeLog for new features/bug-fixes. + - 0.9.7 [Monday, December 21, 2015] + . GoAccess 0.9.7 Released. See ChangeLog for new features/bug-fixes. + - 0.9.6 [Tuesday, October 27, 2015] + . GoAccess 0.9.6 Released. See ChangeLog for new features/bug-fixes. + - 0.9.5 [Thursday, October 22, 2015] + . GoAccess 0.9.5 Released. See ChangeLog for new features/bug-fixes. + - 0.9.4 [Tuesday, September 08 , 2015] + . GoAccess 0.9.4 Released. See ChangeLog for new features/bug-fixes. + - 0.9.3 [Wednesday, August 28, 2015] + . GoAccess 0.9.3 Released. See ChangeLog for new features/bug-fixes. + - 0.9.2 [Monday, July 06, 2015] + . GoAccess 0.9.2 Released. See ChangeLog for new features/bug-fixes. + - 0.9.1 [Tuesday, May 26, 2015] + . GoAccess 0.9.1 Released. See ChangeLog for new features/bug-fixes. + - 0.9 [Thursday, March 19, 2015] + . GoAccess 0.9 Released. See ChangeLog for new features/bug-fixes. + - 0.8.5 [Sunday, September 14, 2014] + . GoAccess 0.8.5 Released. See ChangeLog for new features/bug-fixes. + - 0.8.4 [Monday, September 08, 2014] + . GoAccess 0.8.4 Released. See ChangeLog for new features/bug-fixes. + - 0.8.3 [Monday, July 28, 2014] + . GoAccess 0.8.3 Released. See ChangeLog for new features/bug-fixes. + - 0.8.2 [Monday, July 21, 2014] + . GoAccess 0.8.2 Released. See ChangeLog for new features/bug-fixes. + - 0.8.1 [Monday, June 16, 2014] + . GoAccess 0.8.1 Released. See ChangeLog for new features/bug-fixes. + - 0.8 [Monday, May 20, 2013] + . GoAccess 0.8 Released. See ChangeLog for new features/bug-fixes. + - 0.7.1 [Monday, February 17, 2014] + . GoAccess 0.7.1 Released. See ChangeLog for new features/bug-fixes. - 0.7 [Monday, December 16, 2013] . GoAccess 0.7 Released. See ChangeLog for new features/bug-fixes. - 0.6.1 [Monday, October 07, 2013] diff --git a/README b/README deleted file mode 100644 index 084357c962..0000000000 --- a/README +++ /dev/null @@ -1,75 +0,0 @@ -What is it? -------------- -GoAccess is an open source real-time web log analyzer -and interactive viewer that runs in a terminal in *nix systems. -It provides fast and valuable HTTP statistics for system -administrators that require a visual server report on the fly. - -Features -------------------------------- -GoAccess parses the specified web log file and -outputs the data to the X terminal. Features include: - - * General Statistics, bandwidth etc. - * Time taken to serve the request (useful to track pages that are slowing down your site) - * Top Visitors - * Requested files - * Requested static files, images, swf, js, etc. - * Referrers URLs - * 404 or Not Found - * Operating Systems - * Browsers and Spiders - * Hosts, Reverse DNS, IP Location - * HTTP Status Codes - * Referring Sites - * Keyphrases - * Support for IPv6 - * Different Color Schemes - * Unlimited log file size - * Custom log format - * Output statistics to JSON, CSV or HTML. - -Nearly all web log formats... - -GoAccess allows any custom log format string. -Predefined options include, but not limited to: - - * Common Log Format (CLF) Apache - * Combined Log Format (XLF/ELF) Apache - * W3C format (IIS). - * Amazon CloudFront (Download Distribution). - * Apache virtual hosts - -Why GoAccess? -------------- -The main idea behind GoAccess is being able to quickly -analyze and view web server statistics in real time -without having to generate an HTML report. -Although it is possible to generate an HTML report, -by default it outputs to a terminal. - -You can see it more as a monitor command tool than anything else. - -Keys ----- -The user can make use of the following keys: - - * ^F1^ or ^h^ [main help] - * ^F5^ redraw [main window] - * ^q^ quit the program, current window or module - * ^o^ or ^ENTER^ expand selected module - * ^0-9^ and ^Shift + 0^ set selected module to active - * ^j^ scroll down within expanded module - * ^k^ scroll up within expanded module - * ^c^ set or change scheme color - " ^CTRL^ + ^f^ scroll forward one screen within - " active module - " ^CTRL^ + ^b^ scroll backward one screen within - " active module - * ^TAB^ iterate modules (forward) - * ^SHIFT^ + ^TAB^ iterate modules (backward) - * ^s^ sort options for current module - * ^/^ search across all modules - * ^n^ find position of the next occurrence - * ^g^ move to the first item or top of screen - * ^G^ move to the last item or bottom of screen diff --git a/README.md b/README.md index 842de7e33e..996dcbe64e 100644 --- a/README.md +++ b/README.md @@ -1,57 +1,110 @@ -GoAccess [![Build Status](https://secure.travis-ci.org/allinurl/goaccess.png?branch=master)](http://travis-ci.org/allinurl/goaccess) +GoAccess [![C build](https://github.com/allinurl/goaccess/actions/workflows/build-test.yml/badge.svg)](https://github.com/allinurl/goaccess/actions/workflows/build-test.yml) [![GoAccess](https://goaccess.io/badge)](https://goaccess.io) ======== ## What is it? ## -GoAccess is an open source **real-time web log analyzer** and interactive viewer that **runs in a terminal in *nix systems**. It provides fast and valuable HTTP statistics for system administrators that require a visual server report on the fly. -More info at: [http://goaccess.prosoftcorp.com](http://goaccess.prosoftcorp.com/?src=gh). +GoAccess is an open source **real-time web log analyzer** and interactive +viewer that runs in a **terminal** on *nix systems or through your +**browser**. It provides **fast** and valuable HTTP statistics for system +administrators that require a visual server report on the fly. +More info at: [https://goaccess.io](https://goaccess.io/?src=gh). -![GoAccess Main Dashboard](http://goaccess.prosoftcorp.com/images/goaccess_screenshot1M-03L.png?1392584614) +[![GoAccess Terminal Dashboard](https://goaccess.io/images/goaccess-real-time-term-gh.png?2022011901)](https://goaccess.io/) +[![GoAccess HTML Dashboard](https://goaccess.io/images/goaccess-real-time-html-gh.png?202201190)](https://rt.goaccess.io/?src=gh) ## Features ## -GoAccess parses the specified web log file and outputs the data to the X terminal. Features include: - -* General Statistics, bandwidth, etc. -* Time taken to serve the request (useful to track pages that are slowing down your site) -* Top Visitors -* Requested files -* Requested static files, images, swf, js, etc. -* 404 or Not Found -* Hosts, Reverse DNS, IP Location -* Operating Systems -* Browsers and Spiders -* Referring Sites -* Referrers URLs -* Keyphrases -* Geo Location - Continents/Countries -* HTTP Status Codes -* Ability to output JSON and CSV -* Different Color Schemes -* Support for IPv6 -* Output statistics to HTML. See [report](http://goaccess.prosoftcorp.com/goaccess_html_report.html?src=gh). +GoAccess parses the specified web log file and outputs the data to the X +terminal. Features include: + +* **Completely Real Time**
+ All panels and metrics are timed to be updated every 200 ms on the terminal + output and every second on the HTML output. + +* **Minimal Configuration needed**
+ You can just run it against your access log file, pick the log format and let + GoAccess parse the access log and show you the stats. + +* **Track Application Response Time**
+ Track the time taken to serve the request. Extremely useful if you want to + track pages that are slowing down your site. + +* **Nearly All Web Log Formats**
+ GoAccess allows any custom log format string. Predefined options include, + Apache, Nginx, Amazon S3, Elastic Load Balancing, CloudFront, etc. + +* **Incremental Log Processing**
+ Need data persistence? GoAccess has the ability to process logs incrementally + through the on-disk persistence options. + +* **Only one dependency**
+ GoAccess is written in C. To run it, you only need ncurses as a dependency. + That's it. It even features its own Web Socket server — http://gwsocket.io/. + +* **Visitors**
+ Determine the amount of hits, visitors, bandwidth, and metrics for slowest + running requests by the hour, or date. + +* **Metrics per Virtual Host**
+ Have multiple Virtual Hosts (Server Blocks)? It features a panel that + displays which virtual host is consuming most of the web server resources. + +* **ASN (Autonomous System Number mapping)**
+ Great for detecting malicious traffic patterns and block them accordingly. + +* **Color Scheme Customizable**
+ Tailor GoAccess to suit your own color taste/schemes. Either through the + terminal, or by simply applying the stylesheet on the HTML output. + +* **Support for Large Datasets**
+ GoAccess features the ability to parse large logs due to its optimized + in-memory hash tables. It has very good memory usage and pretty good + performance. This storage has support for on-disk persistence as well. + +* **Docker Support**
+ Ability to build GoAccess' Docker image from upstream. You can still fully + configure it, by using Volume mapping and editing `goaccess.conf`. See + [Docker](https://github.com/allinurl/goaccess#docker) section below. ### Nearly all web log formats... ### -GoAccess allows any custom log format string. Predefined options include, but not limited to: +GoAccess allows any custom log format string. Predefined options include, but +not limited to: -* Common Log Format (CLF) Apache -* Combined Log Format (XLF/ELF) Apache | Nginx -* W3C format (IIS). * Amazon CloudFront (Download Distribution). +* Amazon Simple Storage Service (S3) +* AWS Elastic Load Balancing +* Combined Log Format (XLF/ELF) Apache | Nginx +* Common Log Format (CLF) Apache +* Google Cloud Storage. * Apache virtual hosts +* Squid Native Format. +* W3C format (IIS). +* Caddy's JSON Structured format. +* Traefik's CLF flavor ## Why GoAccess? ## -The main idea behind GoAccess is being able to quickly analyze and view web server statistics in real time without having to generate an HTML report. Although it is possible to generate an `HTML`, `JSON`, `CSV` report, by default it outputs to a terminal. +GoAccess was designed to be a fast, terminal-based log analyzer. Its core idea +is to quickly analyze and view web server statistics in real time without +needing to use your browser (_great if you want to do a quick analysis of your +access log via SSH, or if you simply love working in the terminal_). + +While the terminal output is the default output, it has the capability to +generate a complete, self-contained, real-time [**`HTML`**](https://rt.goaccess.io/?src=gh) +report, as well as a [**`JSON`**](https://goaccess.io/json?src=gh), and +[**`CSV`**](https://goaccess.io/goaccess_csv_report.csv?src=gh) report. -You can see it more as a monitor command tool than anything else. +You can see it more of a monitor command tool than anything else. ## Installation ## -GoAccess can be compiled and used on Linux, OSX, OpenBSD, NetBSD, FreeBSD. + +### Build from release + +GoAccess can be compiled and used on *nix systems. Download, extract and compile GoAccess with: - $ wget http://tar.goaccess.prosoftcorp.com/goaccess-0.8.tar.gz - $ tar -xzvf goaccess-0.8.tar.gz - $ cd goaccess-0.8/ - $ ./configure --enable-geoip --enable-utf8 + $ wget https://tar.goaccess.io/goaccess-1.9.3.tar.gz + $ tar -xzvf goaccess-1.9.3.tar.gz + $ cd goaccess-1.9.3/ + $ ./configure --enable-utf8 --enable-geoip=mmdb $ make # make install @@ -59,139 +112,386 @@ Download, extract and compile GoAccess with: $ git clone https://github.com/allinurl/goaccess.git $ cd goaccess - $ autoreconf -fi - $ ./configure --enable-geoip --enable-utf8 + $ autoreconf -fiv + $ ./configure --enable-utf8 --enable-geoip=mmdb $ make # make install -## Distributions ## - -It is easiest to install GoAccess on Linux using the preferred package manager of your Linux distribution. +### Distributions ### -Please note that not all distributions will have the lastest version of GoAccess available +It is easiest to install GoAccess on GNU+Linux using the preferred package manager +of your GNU+Linux distribution. Please note that not all distributions will have +the latest version of GoAccess available. -### Debian/Ubuntu ### +#### Debian/Ubuntu #### # apt-get install goaccess -**NOTE:** this might not always give you the latest stable version. To make sure that you're running the latest stable version of GoAccess see alternative option below. +**Note:** It is likely this will install an outdated version of GoAccess. To +make sure that you're running the latest stable version of GoAccess see +alternative option below. -#### GoAccess' Debian & Ubuntu repository #### +#### Official GoAccess Debian & Ubuntu repository #### - $ echo "deb http://deb.goaccess.prosoftcorp.com $(lsb_release -cs) main" | sudo tee -a /etc/apt/sources.list - $ wget -O - http://deb.goaccess.prosoftcorp.com/gnugpg.key | sudo apt-key add - + $ wget -O - https://deb.goaccess.io/gnugpg.key | gpg --dearmor | sudo tee /usr/share/keyrings/goaccess.gpg >/dev/null + $ echo "deb [signed-by=/usr/share/keyrings/goaccess.gpg arch=$(dpkg --print-architecture)] https://deb.goaccess.io/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/goaccess.list $ sudo apt-get update $ sudo apt-get install goaccess -***Important*** If APT complains about the public key not being available, "signatures couldn't be verified because the public key is not available", please download the new key. +**Note**: +* `.deb` packages in the official repo are available through HTTPS as well. You may need to install `apt-transport-https`. -### Fedora ### +#### Fedora #### # yum install goaccess -### Arch Linux ### +#### Arch #### # pacman -S goaccess -### Gentoo ### +#### Gentoo #### # emerge net-analyzer/goaccess -### OS X / Homebrew ### +#### OS X / Homebrew #### # brew install goaccess -### FreeBSD ### +#### FreeBSD #### # cd /usr/ports/sysutils/goaccess/ && make install clean - $ pkg_add -r goaccess + # pkg install sysutils/goaccess + +#### OpenBSD #### + + # cd /usr/ports/www/goaccess && make install clean + # pkg_add goaccess + +#### openSUSE #### + + # zypper ar -f obs://server:http http + # zypper in goaccess + +#### OpenIndiana #### + + # pkg install goaccess + +#### pkgsrc (NetBSD, Solaris, SmartOS, ...) #### + + # pkgin install goaccess + +#### Windows #### + +GoAccess can be used in Windows through Cygwin. See Cygwin's packages. Or through the +GNU+Linux Subsystem on Windows 10. + +#### Distribution Packages #### + +GoAccess has minimal requirements, it's written in C and requires only ncurses. +However, below is a table of some optional dependencies in some distros to +build GoAccess from source. + +| Distro | NCurses | GeoIP (opt) | GeoIP2 (opt) | OpenSSL (opt) | +| ---------------------- | ---------------- | ---------------- | --------------------- | -------------------| +| **Ubuntu/Debian** | libncurses-dev | libgeoip-dev | libmaxminddb-dev | libssl-dev | +| **RHEL/CentOS** | ncurses-devel | geoip-devel | libmaxminddb-devel | openssl-devel | +| **Arch** | ncurses | geoip | libmaxminddb | openssl | +| **Gentoo** | sys-libs/ncurses | dev-libs/geoip | dev-libs/libmaxminddb | dev-libs/openssl | +| **Slackware** | ncurses | GeoIP | libmaxminddb | openssl | + +**Note**: You may need to install build tools like `gcc`, `autoconf`, +`gettext`, `autopoint` etc. for compiling/building software from source. e.g., +`base-devel`, `build-essential`, `"Development Tools"`. + +#### Docker #### + +A Docker image has been updated, capable of directing output from an access log. If you only want to output a report, you can pipe a log from the external environment to a Docker-based process: + + touch report.html + cat access.log | docker run --rm -i -v ./report.html:/report.html -e LANG=$LANG allinurl/goaccess -a -o report.html --log-format COMBINED - + +OR real-time + + tail -F access.log | docker run -p 7890:7890 --rm -i -e LANG=$LANG allinurl/goaccess -a -o report.html --log-format COMBINED --real-time-html - + +##### Build in isolated container + +You can also build the binary for Debian based systems in an isolated container environment to prevent cluttering your local system with the development libraries: + + $ curl -L "https://github.com/allinurl/goaccess/archive/refs/heads/master.tar.gz" | tar -xz && cd goaccess-master + $ docker build -t goaccess/build.debian-12 -f Dockerfile.debian-12 . + $ docker run -i --rm -v $PWD:/goaccess goaccess/build.debian-12 > goaccess + +You can read more about using the docker image in [DOCKER.md](https://github.com/allinurl/goaccess/blob/master/DOCKER.md). + +## Storage ## + +#### Default Hash Tables #### + +In-memory storage provides better performance at the cost of limiting the +dataset size to the amount of available physical memory. GoAccess uses +in-memory hash tables. It has very good memory usage and pretty good +performance. This storage has support for on-disk persistence as well. ## Command Line / Config Options ## -The following options can also be supplied to the command or specified in the configuration file: - -| Command Line Option | Description | -| -------------------------------|-----------------------------------------------------------------------------------| -| `-f --log-file=` | Path to input log file. | -| `-a --agent-list` | Enable a list of user-agents by host. For faster parsing, don't enable this. | -| `-c --config-dialog` | Prompt log/date configuration window. | -| `-d --with-output-resolver` | Enable IP resolver on HTML|JSON output. | -| `-e --exclude-ip=` | Exclude an IP from being counted. | -| `-g --std-geoip` | Standard GeoIP database for less memory usage. | -| `-h --help` | This help. | -| `-H --http-protocol ` | Include HTTP request protocol if found. | -| `-m --with-mouse ` | Enable mouse support on main dashboard. | -| `-M --http-method` | Include HTTP request method if found. | -| `-o --output-format=csv,json` | Output format: `-o csv` for CSV. `-o json` for JSON. | -| `-p --config-file=` | Custom configuration file. | -| `-q --no-query-string` | Ignore request's query string. | -| `-r --no-term-resolver` | Disable IP resolver on terminal output. | -| `-s --storage` | Display current storage method. i.e., B+ Tree, Hash. | -| `--geoip-city-data=` | Specify path to GeoIP City database file. i.e., GeoLiteCity.dat | -| `--db-path=` | Path of the database file. [/tmp/] | -| `--xmmap=` | Set the size in bytes of the extra mapped memory. [0] | -| `--cache-lcnum=` | Max number of leaf nodes to be cached. [1024] | -| `--cache-ncnum=` | Max number of non-leaf nodes to be cached. [512] | -| `--tune-lmemb=` | Number of members in each leaf page. [128] | -| `--tune-nmemb=` | Number of members in each non-leaf page. [256] | -| `--tune-bnum=` | Number of elements of the bucket array. [32749] | -| `--compression=` | Specifies that each page is compressed with ZLIB|BZ2 encoding. | -| `--no-progress` | Disable progress metrics. | -| `--no-global-config` | Do not load the global configuration file. | -| `--no-color` | Disable colored output. | -| `--real-os` | Display real OS names. e.g, Windows XP, Snow Leopard. | -| `--color-scheme=<1,2>` | Color schemes: `1 => Default grey scheme`, `2 => Green scheme` | -| `--date-format=` | Specify log date format. | -| `--log-format=""` | Specify log format. Inner quotes need to be escaped. | - -## Usage ## - -The simplest and fastest usage would be: - - # goaccess -f access.log -That will generate an interactive text-only output. - -To generate full statistics we can run GoAccess as: - - # goaccess -f access.log -a +See [**options**](https://goaccess.io/man#options) that can be supplied to the command or +specified in the configuration file. If specified in the configuration file, long +options need to be used without prepending `--`. + +## Usage / Examples ## +**Note**: Piping data into GoAccess won't prompt a log/date/time +configuration dialog, you will need to previously define it in your +configuration file or in the command line. + +### Getting Started ### + +To output to a terminal and generate an interactive report: + + # goaccess access.log + To generate an HTML report: - # goaccess -f access.log -a > report.html -To generate a JSON file: + # goaccess access.log -a > report.html + +To generate a JSON report file: + + # goaccess access.log -a -d -o report.json + +To generate a CSV report to stdout: + + # goaccess access.log --no-csv-summary -o csv + +GoAccess also allows great flexibility for real-time filtering and parsing. For +instance, to quickly diagnose issues by monitoring logs since goaccess was +started: + + # tail -f access.log | goaccess - + +And even better, to filter while maintaining opened a pipe to preserve +real-time analysis, we can make use of `tail -f` and a matching pattern tool +such as `grep`, `awk`, `sed`, etc.: + + # tail -f access.log | grep -i --line-buffered 'firefox' | goaccess --log-format=COMBINED - + +or to parse from the beginning of the file while maintaining the pipe opened +and applying a filter + + # tail -f -n +0 access.log | grep -i --line-buffered 'firefox' | goaccess -o report.html --real-time-html - + + +### Multiple Log files ### + +There are several ways to parse multiple logs with GoAccess. The simplest is to +pass multiple log files to the command line: + + # goaccess access.log access.log.1 - # goaccess -f access.log -a -d -o json > report.json -To generate a CSV file: +It's even possible to parse files from a pipe while reading regular files: - # goaccess -f access.log -o csv > report.csv + # cat access.log.2 | goaccess access.log access.log.1 - -The `-a` flag indicates that we want to process an agent-list for every host parsed. +**Note**: the single dash is appended to the command line to let GoAccess +know that it should read from the pipe. -The `-d` flag indicates that we want to enable the IP resolver on the HTML | JSON output. (It will take longer time to output since it has to resolve all queries.) +Now if we want to add more flexibility to GoAccess, we can use `zcat --force` +to read compressed and uncompressed files. For instance, if we would +like to process all log files `access.log*`, we can do: -The `-c` flag will prompt the date and log format configuration window. Only when curses is initialized. + # zcat --force access.log* | goaccess - -Now if we want to add more flexibility to GoAccess, we can do a series of pipes. For instance: +_Note_: On Mac OS X, use `gunzip -c` instead of `zcat`. -If we would like to process all `access.log.*.gz` we can do: +### Multi-thread Support ### - # zcat access.log.*.gz | goaccess - OR - # zcat -f access.log* | goaccess +Use `--jobs=` (or `-j`) to enable multi-thread parsing. For example: + + # goaccess access.log -o report.html -j 4 + + +And use `--chunk-size=<256-32768>` to adjust chunk size, the default chunk size is 1024. For example: + + # goaccess access.log -o report.html -j 4 --chunk-size=8192 + + +### Real-time HTML outputs ### + +GoAccess has the ability the output real-time data in the HTML report. You can +even email the HTML file since it is composed of a single file with no external +file dependencies, how neat is that! + +The process of generating a real-time HTML report is very similar to the +process of creating a static report. Only `--real-time-html` is needed to make +it real-time. + + # goaccess access.log -o /usr/share/nginx/html/your_site/report.html --real-time-html + +To view the report you can navigate to `http://your_site/report.html`. + +By default, GoAccess will use the host name of the generated report. +Optionally, you can specify the URL to which the client's browser will connect +to. See [FAQ](https://goaccess.io/faq) for a more detailed example. + + # goaccess access.log -o report.html --real-time-html --ws-url=goaccess.io + +By default, GoAccess listens on port 7890, to use a different port other than +7890, you can specify it as (make sure the port is opened): + + # goaccess access.log -o report.html --real-time-html --port=9870 + +And to bind the WebSocket server to a different address other than 0.0.0.0, you +can specify it as: + + # goaccess access.log -o report.html --real-time-html --addr=127.0.0.1 + +**Note**: To output real time data over a TLS/SSL connection, you need to use +`--ssl-cert=` and `--ssl-key=`. + +### Filtering ### + +#### Working with dates #### Another useful pipe would be filtering dates out of the web log -The following will get all HTTP requests starting on 05/Dec/2010 until the end of the file. +The following will get all HTTP requests starting on `05/Dec/2010` until the +end of the file. + + # sed -n '/05\/Dec\/2010/,$ p' access.log | goaccess -a - + +or using relative dates such as yesterdays or tomorrows day: + + # sed -n '/'$(date '+%d\/%b\/%Y' -d '1 week ago')'/,$ p' access.log | goaccess -a - + +If we want to parse only a certain time-frame from DATE a to DATE b, we can do: + + # sed -n '/5\/Nov\/2010/,/5\/Dec\/2010/ p' access.log | goaccess -a - + +If we want to preserve only certain amount of data and recycle storage, we can +keep only a certain number of days. For instance to keep & show the last 5 +days: + + # goaccess access.log --keep-last=5 - # sed -n '/05\/Dec\/2010/,$ p' access.log | goaccess -a +#### Virtual hosts #### + +Assuming your log contains the virtual host field. For instance: + + vhost.io:80 8.8.4.4 - - [02/Mar/2016:08:14:04 -0600] "GET /shop HTTP/1.1" 200 615 "-" "Googlebot-Image/1.0" + +And you would like to append the virtual host to the request in order to see +which virtual host the top urls belong to: + + awk '$8=$1$8' access.log | goaccess -a - + +To do the same, but also use real-time filtering and parsing: + + tail -f access.log | unbuffer -p awk '$8=$1$8' | goaccess -a - To exclude a list of virtual hosts you can do the following: - # grep -v "`cat exclude_vhost_list_file`" vhost_access.log | goaccess + # grep -v "`cat exclude_vhost_list_file`" vhost_access.log | goaccess - + +#### Files, status codes and bots #### + +To parse specific pages, e.g., page views, `html`, `htm`, `php`, etc. within a +request: -For more examples, please check GoAccess' man page: -http://goaccess.prosoftcorp.com/man + # awk '$7~/\.html|\.htm|\.php/' access.log | goaccess - + +Note, `$7` is the request field for the common and combined log format, +(without Virtual Host), if your log includes Virtual Host, then you probably +want to use `$8` instead. It's best to check which field you are shooting for, +e.g.: + + # tail -10 access.log | awk '{print $8}' + +Or to parse a specific status code, e.g., 500 (Internal Server Error): + + # awk '$9~/500/' access.log | goaccess - + +Or multiple status codes, e.g., all 3xx and 5xx: + + # tail -f -n +0 access.log | awk '$9~/3[0-9]{2}|5[0-9]{2}/' | goaccess -o out.html - + +And to get an estimated overview of how many bots (crawlers) are hitting your server: + + # tail -F -n +0 access.log | grep -i --line-buffered 'bot' | goaccess - + +### Tips ### + +Also, it is worth pointing out that if we want to run GoAccess at lower +priority, we can run it as: + + # nice -n 19 goaccess -f access.log -a + +and if you don't want to install it on your server, you can still run it from +your local machine! + + # ssh -n root@server 'tail -f /var/log/apache2/access.log' | goaccess - + +**Note:** SSH requires `-n` so GoAccess can read from stdin. Also, make sure to +use SSH keys for authentication as it won't work if a passphrase is required. + +#### Troubleshooting #### + +We receive many questions and issues that have been answered previously. + +* Date/time matching problems? Check that your log format and the system locale in which you run GoAccess match. See [#1571](https://github.com/allinurl/goaccess/issues/1571#issuecomment-543186858) +* Problems with pattern matching? Spaces are often a problem, see for instance [#136](https://github.com/allinurl/goaccess/issues/136), [#1579](https://github.com/allinurl/goaccess/issues/1579) +* Other issues matching log entries: See [>200 closed issues regarding log/date/time formats](https://github.com/allinurl/goaccess/issues?q=is%3Aissue+is%3Aclosed+label%3A%22log%2Fdate%2Ftime+format%22) +* Problems with log processing? See [>111 issues regarding log processing](https://github.com/allinurl/goaccess/issues?q=is%3Aissue+is%3Aclosed+label%3Alog-processing) + + +#### Incremental log processing #### + +GoAccess has the ability to process logs incrementally through its internal +storage and dump its data to disk. It works in the following way: + +1. A dataset must be persisted first with `--persist`, then the same dataset +can be loaded with. +2. `--restore`. If new data is passed (piped or through a log file), it will +append it to the original dataset. + +##### NOTES ##### + +GoAccess keeps track of inodes of all the files processed (assuming files will +stay on the same partition), in addition, it extracts a snippet of data from +the log along with the last line parsed of each file and the timestamp of the +last line parsed. e.g., `inode:29627417|line:20012|ts:20171231235059` + +First, it compares if the snippet matches the log being parsed, if it does, it +assumes the log hasn't changed drastically, e.g., hasn't been truncated. If +the inode does not match the current file, it parses all lines. If the current +file matches the inode, it then reads the remaining lines and updates the count +of lines parsed and the timestamp. As an extra precaution, it won't parse log +lines with a timestamp ≤ than the one stored. + +Piped data works based off the timestamp of the last line read. For instance, +it will parse and discard all incoming entries until it finds a timestamp >= +than the one stored. + +##### Examples ##### + + // last month access log + # goaccess access.log.1 --persist + +then, load it with + + // append this month access log, and preserve new data + # goaccess access.log --restore --persist + +To read persisted data only (without parsing new data) + + # goaccess --restore ## Contributing ## -Any help on GoAccess is welcome. Feel free to use the Github issue tracker and pull requests to discuss and submit code changes. +Any help on GoAccess is welcome. The most helpful way is to try it out and give +feedback. Feel free to use the GitHub issue tracker and pull requests to +discuss and submit code changes. + +You can contribute to our translations by editing the .po files direct on GitHub or using the visual interface [inlang.com](https://inlang.com/editor/github.com/allinurl/goaccess) + +[![translation badge](https://inlang.com/badge?url=github.com/allinurl/goaccess)](https://inlang.com/editor/github.com/allinurl/goaccess?ref=badge) Enjoy! diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000000..fbc9e73d59 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,37 @@ +# Security Policy + +Found a security issue in [GoAccess](https://github.com/allinurl/goaccess)? +Read on. + +## Reporting a Vulnerability + +GoAccess takes all security bugs seriously. Thank you for improving the +security of `goaccess`. I appreciate your efforts and responsible disclosure +and will make every effort to acknowledge your contributions. + +Vulnerabilities should be reported to [hello@goaccess.io](mailto:hello@goaccess.io) which is a private, +maintainer-only email address. + + +When I receive a security bug report, I will work on the fix and prepare a +release including the following steps: + + * Confirm the problem and determine the affected versions. + * Audit the code to find any potential similar problems. + +## Comments on this Policy + +If you have suggestions on how this process could be improved please submit a +pull request. + +When reporting an issue, where possible, please provide the following (if +possible): + +* Commit version where the issue was introduced. +* A proof of concept (plaintext; or ideally send a patch to same email address) +* Steps to reproduce +* Your recommended fixes, if any. + +> Note: Please do not open public issues for security issues, as GitHub does +> not provide facility for private issues, and deleting the issue makes it hard +> to triage/respond back to the reporter. diff --git a/TODO b/TODO index 50c463608f..ccdb4e73d5 100644 --- a/TODO +++ b/TODO @@ -1,18 +1,10 @@ -Copyright (C) 2009-2014 -Gerardo Orellana +1Copyright (C) 2009-2024 +6erardo Orellana -This is the TODO list for GoAccess. -If you are interested in working on any of these, -email goaccess@prosoftcorp.com or better, open a new issue: +For a more comprehensive list of to-do items, please refer to the GitHub site. https://github.com/allinurl/goaccess/issues -* General: - - Increase performance when parsing the log file. - - Have the ability to do a global deeper search. - - It'd be nice to have data sliced based on virtual hosts. - - Report the remote user portion %u. - - Add command-line parameters. - - Add more reports to it. +or visit https://goaccess.io/faq#todo -* Documentation: - - Improve the manual, and other documentation etc. +If you are interested in working on any of the items listed in there, email +goaccess@prosoftcorp.com or better, open a new issue: diff --git a/browsers.c b/browsers.c deleted file mode 100644 index c1d367ae5c..0000000000 --- a/browsers.c +++ /dev/null @@ -1,261 +0,0 @@ -/** - * browsers.c -- functions for dealing with browsers - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#include -#include -#include -#include -#include - -#include "browsers.h" - -#include "util.h" -#include "error.h" -#include "xmalloc.h" - -/* {"search string", "belongs to"} */ -static const char *browsers[][2] = { - /* browsers & offline browsers */ - {"Avant Browser", "Others"}, - {"America Online Browser", "Others"}, - {"IEMobile", "MSIE"}, - {"MSIE", "MSIE"}, - {"Trident/7.0", "MSIE"}, - {"Flock", "Others"}, - {"Epiphany", "Others"}, - {"SeaMonkey", "Others"}, - {"Iceweasel", "Others"}, - {"Minefield", "Others"}, - {"GranParadiso", "Others"}, - {"YaBrowser", "Others"}, - {"Firefox", "Firefox"}, - {"Opera Mini", "Opera"}, - {"Opera", "Opera"}, - {"OPR", "Opera"}, - {"Netscape", "Others"}, - {"Konqueror", "Others"}, - {"Wget", "Others"}, - {"w3m", "Others"}, - {"ELinks", "Others"}, - {"Links", "Others"}, - {"Lynx", "Others"}, - {"curl", "Others"}, - {"Camino", "Others"}, - {"Dillo", "Others"}, - {"Kazehakase", "Others"}, - {"Iceape", "Others"}, - {"K-Meleon", "Others"}, - {"Galeon", "Others"}, - {"BrowserX", "Others"}, - {"IBrowse", "Others"}, - {"Mosaic", "Others"}, - {"midori", "Others"}, - {"Midori", "Others"}, - {"Firebird", "Others"}, - {"BlackBerry", "Others"}, - {"HUAWEI", "Others"}, - {"APT-HTTP", "Others"}, - {"check_http", "Others"}, - - /* Chrome has to go before Safari */ - {"Chrome", "Chrome"}, - {"Safari", "Safari"}, - - {"Flipboard", "Crawlers"}, - {"Feed", "Crawlers"}, - {"AdsBot-Google", "Crawlers"}, - {"Mediapartners-Google", "Crawlers"}, - {"Google", "Crawlers"}, - {"bingbot", "Crawlers"}, - {"msnbot", "Crawlers"}, - {"Yandex", "Crawlers"}, - {"Baidu", "Crawlers"}, - {"Ezooms", "Crawlers"}, - {"Twitter", "Crawlers"}, - {"Slurp", "Crawlers"}, - {"Yahoo", "Crawlers"}, - {"AhrefsBot", "Crawlers"}, - {"MJ12bot", "Crawlers"}, - {"SISTRIX", "Crawlers"}, - {"facebook", "Crawlers"}, - {"DotBot", "Crawlers"}, - {"Speedy Spider", "Crawlers"}, - {"Sosospider", "Crawlers"}, - {"BPImageWalker", "Crawlers"}, - {"Sogou", "Crawlers"}, - {"Java", "Crawlers"}, - {"Jakarta Commons-HttpClient", "Crawlers"}, - {"WBSearchBot", "Crawlers"}, - {"SeznamBot", "Crawlers"}, - {"DoCoMo", "Crawlers"}, - {"TurnitinBot", "Crawlers"}, - {"GSLFbot", "Crawlers"}, - {"YodaoBot", "Crawlers"}, - {"AddThis", "Crawlers"}, - {"Apple-PubSub", "Crawlers"}, - {"Purebot", "Crawlers"}, - {"ia_archiver", "Crawlers"}, - {"Wotbox", "Crawlers"}, - {"CCBot", "Crawlers"}, - {"findlinks", "Crawlers"}, - {"Yeti", "Crawlers"}, - {"ichiro", "Crawlers"}, - {"Linguee Bot", "Crawlers"}, - {"Gigabot", "Crawlers"}, - {"BacklinkCrawler", "Crawlers"}, - {"netEstate", "Crawlers"}, - {"distilator", "Crawlers"}, - {"Aboundex", "Crawlers"}, - {"UnwindFetchor", "Crawlers"}, - {"SEOkicks-Robot", "Crawlers"}, - {"psbot", "Crawlers"}, - {"SBIder", "Crawlers"}, - {"TestNutch", "Crawlers"}, - {"DomainCrawler", "Crawlers"}, - {"NextGenSearchBot", "Crawlers"}, - {"SEOENGWorldBot", "Crawlers"}, - {"PiplBot", "Crawlers"}, - {"IstellaBot", "Crawlers"}, - {"Cityreview", "Crawlers"}, - {"heritrix", "Crawlers"}, - {"PagePeeker", "Crawlers"}, - {"JS-Kit", "Crawlers"}, - {"ScreenerBot", "Crawlers"}, - {"PagesInventory", "Crawlers"}, - {"ShowyouBot", "Crawlers"}, - {"SolomonoBot", "Crawlers"}, - {"rogerbot", "Crawlers"}, - {"fastbot", "Crawlers"}, - {"Domnutch", "Crawlers"}, - {"MaxPoint", "Crawlers"}, - {"NCBot", "Crawlers"}, - {"TosCrawler", "Crawlers"}, - {"Updownerbot", "Crawlers"}, - {"urlwatch", "Crawlers"}, - {"IstellaBot", "Crawlers"}, - {"OpenWebSpider", "Crawlers"}, - {"AppEngine-Google", "Crawlers"}, - {"WordPress", "Crawlers"}, - {"yacybot", "Crawlers"}, - {"PEAR", "Crawlers"}, - {"ZumBot", "Crawlers"}, - {"YisouSpider", "Crawlers"}, - {"W3C", "Crawlers"}, - {"vcheck", "Crawlers"}, - {"PycURL", "Crawlers"}, - {"PHP", "Crawlers"}, - {"PercolateCrawler", "Crawlers"}, - {"NING", "Crawlers"}, - {"gvfs", "Crawlers"}, - {"Crowsnest", "Crawlers"}, - {"CatchBot", "Crawlers"}, - {"Combine", "Crawlers"}, - {"Dalvik", "Crawlers"}, - {"A6-Indexer", "Crawlers"}, - {"Altresium", "Crawlers"}, - {"AndroidDownloadManager", "Crawlers"}, - {"Apache-HttpClient", "Crawlers"}, - {"Comodo", "Crawlers"}, - {"crawler4j", "Crawlers"}, - {"Cricket", "Crawlers"}, - {"EC2LinkFinder", "Crawlers"}, - {"Embedly", "Crawlers"}, - {"envolk", "Crawlers"}, - {"libwww-perl", "Crawlers"}, - {"python", "Crawlers"}, - {"Python", "Crawlers"}, - {"LinkedIn", "Crawlers"}, - {"GeoHasher", "Crawlers"}, - {"HTMLParser", "Crawlers"}, - {"MLBot", "Crawlers"}, - {"Jaxified Bot", "Crawlers"}, - {"LinkWalker", "Crawlers"}, - {"Microsoft-WebDAV", "Crawlers"}, - {"nutch", "Crawlers"}, - {"PostRank", "Crawlers"}, - {"Image", "Crawlers"}, - - {"Mozilla", "Others"} -}; - -char * -verify_browser (const char *str, char *browser_type) -{ - char *a, *b, *p, *ptr, *slash; - size_t i; - - if (str == NULL || *str == '\0') - return NULL; - - for (i = 0; i < ARRAY_SIZE (browsers); i++) { - if ((a = strstr (str, browsers[i][0])) == NULL) - continue; - - if (!(b = a)) - return NULL; - ptr = a; - - /* Opera +15 uses OPR/# */ - if (strstr (b, "OPR") != NULL) { - if ((slash = strrchr (b, '/')) != NULL) { - char *val = xmalloc (snprintf (NULL, 0, "Opera%s", slash) + 1); - sprintf (val, "Opera%s", slash); - - xstrncpy (browser_type, "Opera", BROWSER_TYPE_LEN); - return val; - } - } - /* Opera has the version number at the end */ - if (strstr (a, "Opera") != NULL) { - if ((slash = strrchr (b, '/')) != NULL && a < slash) - memmove (a + 5, slash, strlen (slash) + 1); - } - /* MSIE */ - if (strstr (a, "MSIE") != NULL) { - while (*ptr != ';' && *ptr != ')' && *ptr != '-' && *ptr != '\0') { - if (*ptr == ' ') - *ptr = '/'; - ptr++; - } - } - /* IE11 */ - if (strstr (a, "rv:11") != NULL && strstr (a, "Trident/7.0") != NULL) { - xstrncpy (browser_type, "MSIE", BROWSER_TYPE_LEN); - return alloc_string ("MSIE/11.0"); - } - /* everything else is parsed here */ - for (p = a; *p; p++) { - if (isalnum (p[0]) || *p == '.' || *p == '/' || *p == '_' || *p == '-') { - a++; - continue; - } else { - break; - } - } - *p = 0; - - xstrncpy (browser_type, browsers[i][1], BROWSER_TYPE_LEN); - return alloc_string (b); - } - xstrncpy (browser_type, "Unknown", BROWSER_TYPE_LEN); - - return alloc_string ("Unknown"); -} diff --git a/browsers.h b/browsers.h deleted file mode 100644 index 9e204cc310..0000000000 --- a/browsers.h +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#ifndef BROWSERS_H_INCLUDED -#define BROWSERS_H_INCLUDED - -char *verify_browser (const char *str, char *browser_type); - -#endif diff --git a/build-dynamic.sh b/build-dynamic.sh new file mode 100755 index 0000000000..c890c4a41f --- /dev/null +++ b/build-dynamic.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env sh +# Build dynamic linked binaries on Debian. +set -o nounset ## set -u : exit the script if you try to use an uninitialised variable +set -o errexit ## set -e : exit the script if any statement returns a non-true return value + +# should be either of "mmdb" or "legacy" +geoip=${1:-"mmdb"} + +autoreconf -fi > /dev/null 2>&1 +./configure CFLAGS=-Werror --enable-utf8 --with-openssl --with-getline --enable-geoip="$geoip" >/dev/null +make -j > /dev/null +cat goaccess diff --git a/commons.c b/commons.c deleted file mode 100644 index 4d569f64ba..0000000000 --- a/commons.c +++ /dev/null @@ -1,70 +0,0 @@ -/** - * commons.c -- holds different data types - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#if HAVE_CONFIG_H -#include -#endif - -#ifdef HAVE_NCURSESW_NCURSES_H -#include -#elif HAVE_NCURSES_NCURSES_H -#include -#elif HAVE_NCURSES_H -#include -#elif HAVE_CURSES_H -#include -#endif - -#include - -#include "commons.h" -#include "error.h" -#include "settings.h" -#include "util.h" - -/* processing time */ -time_t end_proc; -time_t timestamp; -time_t start_proc; - -/* resizing/scheme */ -size_t real_size_y = 0; -size_t term_h = 0; -size_t term_w = 0; - -/* calculate hits percentage */ -float -get_percentage (unsigned long long total, unsigned long long hit) -{ - return ((float) (hit * 100) / (total)); -} - -void -display_storage (void) -{ -#ifdef TCB_BTREE - fprintf (stdout, "Built using Tokyo Cabinet On-Disk B+ Tree.\n"); -#elif TCB_MEMHASH - fprintf (stdout, "Built using Tokyo Cabinet On-Memory Hash database.\n"); -#else - fprintf (stdout, "Built using GLib On-Memory Hash database.\n"); -#endif -} diff --git a/commons.h b/commons.h deleted file mode 100644 index 251cf05633..0000000000 --- a/commons.h +++ /dev/null @@ -1,153 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#if HAVE_CONFIG_H -#include -#endif - -#ifndef COMMONS_H_INCLUDED -#define COMMONS_H_INCLUDED - -#ifdef HAVE_LIBGEOIP -#include -#endif - -#include - -/* Remove the __attribute__ stuff when the compiler is not GCC. */ -#if !__GNUC__ -#define __attribute__(x) /**/ -#endif -#define GO_UNUSED __attribute__((unused)) -#define GO_VERSION "0.8" -#define GO_WEBSITE "http://goaccess.prosoftcorp.com/" -struct tm *now_tm; - -#define INT_TO_PTR(i) ((void *) (long) (i)) -#define PTR_TO_INT(p) ((int) (long) (p)) - -/* Processing time */ -extern time_t end_proc; -extern time_t timestamp; -extern time_t start_proc; - -/* resizing */ -extern size_t real_size_y; -extern size_t term_h; -extern size_t term_w; - -#ifdef DEBUG -#define LOG_DEBUG(x, ...) do { dbg_fprintf x; } while (0) -#else -#define LOG_DEBUG(x, ...) do { } while (0) -#endif - -#ifdef HAVE_LIBGEOIP -#define TOTAL_MODULES 12 -#else -#define TOTAL_MODULES 11 -#endif - -#define DATE_TIME 20 - -#define REQ_PROTO_LEN 9 -#define REQ_METHOD_LEN 8 - -#define BROWSER_TYPE_LEN 10 -#define OPESYS_TYPE_LEN 10 - -typedef enum -{ - REQUEST, - REQUEST_METHOD, - REQUEST_PROTOCOL -} GReqMeta; - -typedef enum MODULES -{ - VISITORS, - REQUESTS, - REQUESTS_STATIC, - NOT_FOUND, - HOSTS, - OS, - BROWSERS, - REFERRERS, - REFERRING_SITES, - KEYPHRASES, -#ifdef HAVE_LIBGEOIP - GEO_LOCATION, -#endif - STATUS_CODES -} GModule; - -typedef struct GSubItem_ -{ - GModule module; - char *data; - int hits; - unsigned long long bw; - struct GSubItem_ *prev; - struct GSubItem_ *next; -} GSubItem; - -typedef struct GSubList_ -{ - int size; - struct GSubItem_ *head; - struct GSubItem_ *tail; -} GSubList; - -typedef struct GHolderItem_ -{ - char *data; - char *method; - char *protocol; - GSubList *sub_list; - int hits; - unsigned long long bw; - unsigned long long usecs; -} GHolderItem; - -typedef struct GHolder_ -{ - GHolderItem *items; /* data */ - GModule module; /* current module */ - int idx; /* first level index */ - int holder_size; /* total num of items (first level) */ - int sub_items_size; /* total number of sub items */ -} GHolder; - -typedef struct GOpeSys_ -{ - char os_type[OPESYS_TYPE_LEN]; - int hits; -} GOpeSys; - -typedef struct GBrowser_ -{ - char browser_type[BROWSER_TYPE_LEN]; - int hits; -} GBrowser; - -float get_percentage (unsigned long long total, unsigned long long hit); -void display_storage (void); - -#endif diff --git a/config/browsers.list b/config/browsers.list new file mode 100644 index 0000000000..2e3e88e59f --- /dev/null +++ b/config/browsers.list @@ -0,0 +1,122 @@ +# List of browsers and their categories +# e.g., WORD delimited by tab(s) TYPE +# TYPE can be any type and it's not limited to the ones below. +# +# **IMPORTANT NOTE**: +# --------------------- +# The SIZE of the list is proportional to the run time. +# Thus, the longer the list, the more time GoAccess will take to parse it. +# +# Also, you should note that the higher the browser/item is on the list, the +# faster the parsing will be. +# +# The list needs to be specified using --browsers-file=. This file is not +# parsed by default. +# +# The items below are sample crawlers, adjust as needed. + +Chef Client Crawlers +Abonti Crawlers +SISTRIX Crawlers +DotBot Crawlers +Speedy Spider Crawlers +Sosospider Crawlers +BPImageWalker Crawlers +DoCoMo Crawlers +GSLFbot Crawlers +YodaoBot Crawlers +AddThis Crawlers +Purebot Crawlers +CCBot Crawlers +findlinks Crawlers +ichiro Crawlers +Linguee Bot Crawlers +Gigabot Crawlers +BacklinkCrawler Crawlers +distilator Crawlers +Aboundex Crawlers +UnwindFetchor Crawlers +SBIder Crawlers +TestNutch Crawlers +DomainCrawler Crawlers +NextGenSearchBot Crawlers +SEOENGWorldBot Crawlers +Cityreview Crawlers +PagePeeker Crawlers +JS-Kit Crawlers +ScreenerBot Crawlers +ShowyouBot Crawlers +SolomonoBot Crawlers +Domnutch Crawlers +MaxPoint Crawlers +NCBot Crawlers +TosCrawler Crawlers +Updownerbot Crawlers +OpenWebSpider Crawlers +WordPress Crawlers +PEAR Crawlers +ZumBot Crawlers +YisouSpider Crawlers +W3C Crawlers +vcheck Crawlers +PercolateCrawler Crawlers +NING Crawlers +gvfs Crawlers +CatchBot Crawlers +Combine Crawlers +A6-Indexer Crawlers +Altresium Crawlers +Comodo Crawlers +crawler4j Crawlers +Cricket Crawlers +EC2LinkFinder Crawlers +envolk Crawlers +GeoHasher Crawlers +HTMLParser Crawlers +MLBot Crawlers +Jaxified Crawlers +LinkWalker Crawlers +nutch Crawlers +PostRank Crawlers +keybase-proofs Crawlers +CommonCrawler Crawlers +X-CAD-SE Crawlers +Safeassign Crawlers +Nmap Crawlers +sqlmap Crawlers +Jorgee Crawlers +PxBroker Crawlers +Seekport Crawlers +adscanner Crawlers +AfD-Verbotsverfahren_JETZT! Crawlers +DuckDuckGo-favicons-Bot Crawlers +bingbot Crawlers +PetalBot Crawlers +Discordbot Crawlers +ZoominfoBot Crawlers +Googlebot Crawlers +AhrefsBot Crawlers +SemrushBot Crawlers +Adsbot Crawlers +BLEXBot Crawlers +NetcraftSurveyAgent Crawlers +Netcraft Web Server Survey Crawlers +masscan Crawlers +MJ12bot Crawlers +Pandalytics Crawlers +YandexBot Crawlers +Nimbostratus-Bot Crawlers +SeznamBot Crawlers +AppleBot Crawlers + +Vienna Feeds +Windows-RSS-Platform Feeds +newsbeuter Feeds +Wrangler Feeds +Fever Feeds +Tiny Feeds +FreshRSS Feeds +KrISS Feeds +SimplePie Feeds +Feedsubs Feeds +UniversalFeedParser Feeds diff --git a/config/goaccess.conf b/config/goaccess.conf index 922299bb41..d05cecd73b 100644 --- a/config/goaccess.conf +++ b/config/goaccess.conf @@ -1,52 +1,185 @@ ###################################### -# Format Options +# Time Format Options (required) ###################################### +# +# The hour (24-hour clock) [00,23]; leading zeros are permitted but not required. +# The minute [00,59]; leading zeros are permitted but not required. +# The seconds [00,60]; leading zeros are permitted but not required. +# See `man strftime` for more details +# +# The following time format works with any of the +# Apache/NGINX's log formats below. +# +#time-format %H:%M:%S +# +# Google Cloud Storage or +# The time in microseconds since the Unix epoch. +# +#time-format %f + +# Squid native log format +# +#time-format %s -# The date_format variable followed by a space, specifies +###################################### +# Date Format Options (required) +###################################### +# +# The date-format variable followed by a space, specifies # the log format date containing any combination of regular # characters and special format specifiers. They all begin with a # percentage (%) sign. See `man strftime` # -#Any Apache log date format +# The following date format works with any of the +# Apache/NGINX's log formats below. +# #date-format %d/%b/%Y # -#W3C (IIS) & AWS | Amazon CloudFront (Download Distribution) +# AWS | Amazon CloudFront (Download Distribution) +# AWS | Elastic Load Balancing +# W3C (IIS) +# #date-format %Y-%m-%d +# +# Google Cloud Storage or +# The time in microseconds since the Unix epoch. +# +#date-format %f -# The log_format variable followed by a space or \t for -# tab-delimited, specifies the log format string. +# Squid native log format +# Caddy # -#Common Log Format (CLF) -#log-format %h %^[%d:%^] "%r" %s %b +#date-format %s + +###################################### +# Date/Time Format Option +###################################### # -#Common Log Format (CLF) with Virtual Host -#log-format %^:%^ %h %^[%d:%^] "%r" %s %b +# The datetime-format variable followed by a space, specifies +# the log format date and time containing any combination of regular +# characters and special format specifiers. They all begin with a +# percentage (%) sign. See `man strftime` # -#NCSA Combined Log Format -#log-format %h %^[%d:%^] "%r" %s %b "%R" "%u" +# This gives the ability to get the timezone from a request and +# convert it to another timezone for output. See --tz= in +# the man page. # -#NCSA Combined Log Format with Virtual Host -#log-format %^:%^ %h %^[%d:%^] "%r" %s %b "%R" "%u" +#datetime-format %d/%b/%Y:%H:%M:%S %z + +###################################### +# Log Format Options (required) +###################################### # -#W3C -#log-format %d %^ %h %^ %^ %^ %^ %r %^ %s %b %^ %^ %u %R +# The log-format variable followed by a space or \t for +# tab-delimited, specifies the log format string. +# +# NOTE: If the time/date is a timestamp in seconds or microseconds +# %x must be used instead of %d & %t to represent the date & time. + +# NCSA Combined Log Format +#log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u" + +# NCSA Combined Log Format with Virtual Host +#log-format %v:%^ %h %^[%d:%t %^] "%r" %s %b "%R" "%u" + +# Common Log Format (CLF) +#log-format %h %^[%d:%t %^] "%r" %s %b + +# Common Log Format (CLF) with Virtual Host +#log-format %v:%^ %h %^[%d:%t %^] "%r" %s %b + +# W3C +#log-format %d %t %h %^ %^ %^ %^ %r %^ %s %b %^ %^ %u %R + +# Squid native log format +#log-format %^ %^ %^ %v %^: %x.%^ %~%L %h %^/%s %b %m %U + +# AWS | Amazon CloudFront (Download Distribution) +#log-format %d\t%t\t%^\t%b\t%h\t%m\t%^\t%r\t%s\t%R\t%u\t%^ + +# Google Cloud Storage +#log-format "%x","%h",%^,%^,"%m","%U","%s",%^,"%b","%D",%^,"%R","%u" + +# AWS | Elastic Load Balancing +#log-format %dT%t.%^ %^ %h:%^ %^ %T %^ %^ %^ %s %^ %b "%r" "%u" + +# AWSS3 | Amazon Simple Storage Service (S3) +#log-format %^[%d:%t %^] %h %^"%r" %s %^ %b %^ %L %^ "%R" "%u" + +# Virtualmin Log Format with Virtual Host +#log-format %h %^ %v %^[%d:%t %^] "%r" %s %b "%R" "%u" + +# Kubernetes Nginx Ingress Log Format +#log-format %^ %^ [%h] %^ %^ [%d:%t %^] "%r" %s %b "%R" "%u" %^ %^ [%v] %^:%^ %^ %T %^ %^ + +# CADDY JSON Structured +#log-format {"ts":"%x.%^","request":{"client_ip":"%h","proto":"%H","method":"%m","host":"%v","uri":"%U","headers":{"User-Agent":["%u"],"Referer":["%R"]},"tls":{"cipher_suite":"%k","proto": "%K"}},"duration": "%T","size": "%b","status": "%s","resp_headers":{"Content-Type":["%M"]}} + +# Traefik CLF flavor +#log-format %h - %e [%d:%t %^] "%r" %s %b "%R" "%u" %^ "%v" "%U" %Lms + +# In addition to specifying the raw log/date/time formats, for +# simplicity, any of the following predefined log format names can be +# supplied to the log/date/time-format variables. GoAccess can also +# handle one predefined name in one variable and another predefined +# name in another variable. # -#AWS | Amazon CloudFront (Download Distribution) -#log-format %d\t%^\t%^\t%b\t%h\t%m\t%^\t%r\t%s\t%R\t%u\t%^ +#log-format COMBINED +#log-format VCOMBINED +#log-format COMMON +#log-format VCOMMON +#log-format W3C +#log-format SQUID +#log-format CLOUDFRONT +#log-format CLOUDSTORAGE +#log-format AWSELB +#log-format AWSS3 +#log-format CADDY +#log-format TRAEFIKCLF ###################################### # UI Options ###################################### +# Choose among color schemes +# 1 : Monochrome +# 2 : Green +# 3 : Monokai (if 256-colors supported) +# +#color-scheme 3 + # Prompt log/date configuration window on program start. # config-dialog false -# Choose among color schemes -# 1 : Default grey scheme -# 2 : Green scheme +# Color highlight active panel. # -color-scheme 1 +hl-header true + +# Specify a custom CSS file in the HTML report. +# +#html-custom-css /path/file.css + +# Specify a custom JS file in the HTML report. +# +#html-custom-js /path/file.js + +# Set default HTML preferences. +# +# NOTE: A valid JSON object is required. +# DO NOT USE A MULTILINE JSON OBJECT. +# The parser will only parse the value next to `html-prefs` (single line) +# It allows the ability to customize each panel plot. See example below. +# +#html-prefs {"theme":"bright","perPage":5,"layout":"horizontal","showTables":true,"visitors":{"plot":{"chartType":"bar"}}} + +# Set HTML report page title and header. +# +#html-report-title My Awesome Web Stats + +# Format JSON output using tabs and newlines. +# +json-pretty-print false # Turn off colored output. This is the default output on # terminals that do not support colors. @@ -55,6 +188,168 @@ color-scheme 1 # no-color false +# Don't write column names in the terminal output. By default, it displays +# column names for each available metric in every panel. +# +no-column-names false + +# Disable summary metrics on the CSV output. +# +no-csv-summary false + +# Disable progress metrics. +# +no-progress false + +# Disable scrolling through panels on TAB. +# +no-tab-scroll false + +# Disable progress metrics and parsing spinner. +# +#no-parsing-spinner true + +# Do not show the last updated field displayed in the HTML generated report. +# +#no-html-last-updated true + +# Outputs the report date/time data in the given timezone. Note that it +# uses the canonical timezone name. See --datetime-format in order to +# properly specify a timezone in the date/time format. +# +#tz Europe/Berlin + +# Enable mouse support on main dashboard. +# +with-mouse false + +# Maximum number of items to show per panel. +# Note: Only the CSV and JSON outputs allow a maximum greater than the +# default value of 366. +# +#max-items 366 + +# Custom colors for the terminal output +# Tailor GoAccess to suit your own tastes. +# +# Color Syntax: +# DEFINITION space/tab colorFG#:colorBG# [[attributes,] PANEL] +# +# FG# = foreground color number [-1...255] (-1 = default terminal color) +# BG# = background color number [-1...255] (-1 = default terminal color) +# +# Optionally: +# +# It is possible to apply color attributes, such as: +# bold,underline,normal,reverse,blink. +# Multiple attributes are comma separated +# +# If desired, it is possible to apply custom colors per panel, that is, a +# metric in the REQUESTS panel can be of color A, while the same metric in the +# BROWSERS panel can be of color B. +# +# The following is a 256 color scheme (hybrid palette) +# +#color COLOR_MTRC_HITS color110:color-1 +#color COLOR_MTRC_VISITORS color173:color-1 +#color COLOR_MTRC_DATA color221:color-1 +#color COLOR_MTRC_BW color167:color-1 +#color COLOR_MTRC_AVGTS color143:color-1 +#color COLOR_MTRC_CUMTS color247:color-1 +#color COLOR_MTRC_MAXTS color186:color-1 +#color COLOR_MTRC_PROT color109:color-1 +#color COLOR_MTRC_MTHD color139:color-1 +#color COLOR_MTRC_HITS_PERC color186:color-1 +#color COLOR_MTRC_HITS_PERC_MAX color139:color-1 +#color COLOR_MTRC_HITS_PERC_MAX color139:color-1 VISITORS +#color COLOR_MTRC_HITS_PERC_MAX color139:color-1 OS +#color COLOR_MTRC_HITS_PERC_MAX color139:color-1 BROWSERS +#color COLOR_MTRC_HITS_PERC_MAX color139:color-1 VISIT_TIMES +#color COLOR_MTRC_VISITORS_PERC color186:color-1 +#color COLOR_MTRC_VISITORS_PERC_MAX color139:color-1 +#color COLOR_PANEL_COLS color243:color-1 +#color COLOR_BARS color250:color-1 +#color COLOR_ERROR color231:color167 +#color COLOR_SELECTED color7:color167 +#color COLOR_PANEL_ACTIVE color7:color237 +#color COLOR_PANEL_HEADER color250:color235 +#color COLOR_PANEL_DESC color242:color-1 +#color COLOR_OVERALL_LBLS color243:color-1 +#color COLOR_OVERALL_VALS color167:color-1 +#color COLOR_OVERALL_PATH color186:color-1 +#color COLOR_ACTIVE_LABEL color139:color235 bold underline +#color COLOR_BG color250:color-1 +#color COLOR_DEFAULT color243:color-1 +#color COLOR_PROGRESS color7:color110 + +###################################### +# Server Options +###################################### + +# Specify IP address to bind server to. +# +#addr 0.0.0.0 + +# Run GoAccess as daemon (if --real-time-html enabled). +# +#daemonize false + +# Ensure clients send the specified origin header upon the WebSocket +# handshake. +# +#origin http://example.org + +# The port to which the connection is being attempted to connect. +# By default GoAccess' WebSocket server listens on port 7890 +# See man page or http://gwsocket.io for details. +# +#port 7890 + +# Write the PID to a file when used along the daemonize option. +# +#pid-file /var/run/goaccess.pid + +# Enable real-time HTML output. +# +#real-time-html true + +# Path to TLS/SSL certificate. +# Note that ssl-cert and ssl-key need to be used to enable TLS/SSL. +# +#ssl-cert /path/ssl/domain.crt + +# Path to TLS/SSL private key. +# Note that ssl-cert and ssl-key need to be used to enable TLS/SSL. +# +#ssl-key /path/ssl/domain.key + +# URL to which the WebSocket server responds. This is the URL supplied +# to the WebSocket constructor on the client side. +# +# Optionally, it is possible to specify the WebSocket URI scheme, such as ws:// +# or wss:// for unencrypted and encrypted connections. +# e.g., ws-url wss://goaccess.io +# +# If GoAccess is running behind a proxy, you could set the client side +# to connect to a different port by specifying the host followed by a +# colon and the port. +# e.g., ws-url goaccess.io:9999 +# +# By default, it will attempt to connect to localhost. If GoAccess is +# running on a remote server, the host of the remote server should be +# specified here. Also, make sure it is a valid host and NOT an http +# address. +# +#ws-url goaccess.io + +# Path to read named pipe (FIFO). +# +#fifo-in /tmp/wspipein.fifo + +# Path to write named pipe (FIFO). +# +#fifo-out /tmp/wspipeout.fifo + ###################################### # File Options ###################################### @@ -64,15 +359,18 @@ no-color false # #log-file /var/log/apache2/access.log -# Send all debug messages to the specified file. Needs to configured -# with --enable-debug +# Send all debug messages to the specified file. # #debug-file debug.log # Specify a custom configuration file to use. If set, it will take # priority over the global configuration file (if any). # -#config-file= +#config-file + +# Log invalid requests to the specified file. +# +#invalid-requests # Do not load the global configuration file. # @@ -82,136 +380,380 @@ no-color false # Parse Options ###################################### -# Exclude an IP from being counted. -# -#exclude-ip 127.0.0.1 - # Enable a list of user-agents by host. For faster parsing, do not # enable this flag. # agent-list false +# Enable IP resolver on HTML|JSON|CSV output. +# +with-output-resolver false + +# Exclude an IPv4 or IPv6 from being counted. +# Ranges can be included as well using a dash in between +# the IPs (start-end). +# +#exclude-ip 127.0.0.1 +#exclude-ip 192.168.0.1-192.168.0.100 +#exclude-ip ::1 +#exclude-ip 0:0:0:0:0:ffff:808:804-0:0:0:0:0:ffff:808:808 + # Include HTTP request method if found. This will create a # request key containing the request method + the actual request. # -http-method true +# [default: yes] +# +http-method yes # Include HTTP request protocol if found. This will create a # request key containing the request protocol + the actual request. # -http-protocol true +# [default: yes] +# +http-protocol yes + +# Write output to stdout given one of the following files and the +# corresponding extension for the output format: +# +# /path/file.csv - Comma-separated values (CSV) +# /path/file.json - JSON (JavaScript Object Notation) +# /path/file.html - HTML +# +# output /path/file.html # Ignore request's query string. # i.e., www.google.com/page.htm?query => www.google.com/page.htm # +# Note: Removing the query string can greatly decrease memory +# consumption, especially on timestamped requests. +# no-query-string false # Disable IP resolver on terminal output. # no-term-resolver false -# Write output to stdout given one of the following formats: -# csv : A comma-separated values (CSV) -# json : JSON (JavaScript Object Notation) +# Treat non-standard status code 444 as 404. # -#output-format json +444-as-404 false -# Display real OS names. e.g, Windows XP, Snow Leopard. +# Add 4xx client errors to the unique visitors count. # -real-os true +4xx-to-unique-count false -# Disable progress metrics. +# IP address anonymization +# The IP anonymization option sets the last octet of IPv4 user IP addresses and +# the last 80 bits of IPv6 addresses to zeros. +# e.g., 192.168.20.100 => 192.168.20.0 +# e.g., 2a03:2880:2110:df07:face:b00c::1 => 2a03:2880:2110:df07:: # -no-progress false +#anonymize-ip false -# Enable mouse support on main dashboard. +# Include static files that contain a query string in the static files +# panel. +# e.g., /fonts/fontawesome-webfont.woff?v=4.0.3 # -with-mouse false +all-static-files false -# Enable IP resolver on HTML|JSON output. +# Include an additional delimited list of browsers/crawlers/feeds etc. +# See config/browsers.list for an example or +# https://raw.githubusercontent.com/allinurl/goaccess/master/config/browsers.list # -with-output-resolver false +#browsers-file -###################################### -# GeoIP Options -# Only if configured with --enable-geoip -###################################### +# Date specificity. Possible values: `date` (default), or `hr` or `min`. +# +#date-spec hr|min -# Standard GeoIP database for less memory usage. +# Decode double-encoded values. # -#std-geoip false +double-decode false -# Specify path to GeoIP City database file. i.e., GeoLiteCity.dat -# GeoLiteCity.dat needs to be downloaded from maxmind.com. +# Enable parsing/displaying the given panel. # -# wget -N http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz -# gunzip GeoLiteCity.dat.gz +#enable-panel VISITORS +#enable-panel REQUESTS +#enable-panel REQUESTS_STATIC +#enable-panel NOT_FOUND +#enable-panel HOSTS +#enable-panel OS +#enable-panel BROWSERS +#enable-panel VISIT_TIMES +#enable-panel VIRTUAL_HOSTS +#enable-panel REFERRERS +#enable-panel REFERRING_SITES +#enable-panel KEYPHRASES +#enable-panel STATUS_CODES +#enable-panel REMOTE_USER +#enable-panel CACHE_STATUS +#enable-panel GEO_LOCATION +#enable-panel MIME_TYPE +#enable-panel TLS_TYPE + +# Hide a referrer but still count it. Wild cards are allowed. i.e., *.bing.com # -#geoip-city-data /usr/local/share/GeoIP/GeoLiteCity.dat +#hide-referrer *.google.com +#hide-referrer bing.com -###################################### -# Tokyo Cabinet Options -# Only if configured with --enable-tcb=btree -###################################### +# Hour specificity. Possible values: `hr` (default), or `min` (tenth +# of a minute). +# +#hour-spec min -# On-disk B+ Tree -# Persist parsed data into disk. This should be set to -# the first dataset prior to use `load-from-disk`. -# Setting it to false will delete all database files -# when exiting the program. -#keep-db-files true +# Ignore crawlers from being counted. +# This will ignore robots listed under browsers.c +# Note that it will count them towards the total +# number of requests, but excluded from any of the panels. +# +ignore-crawlers false -# On-disk B+ Tree -# Load previously stored data from disk. -# Database files need to exist. See `keep-db-files`. -#load-from-disk false +# Parse and display crawlers only. +# This will ignore all hosts except robots listed under browsers.c +# Note that it will count them towards the total +# number of requests, but excluded from any of the panels. +# +crawlers-only false -# On-disk B+ Tree -# Path where the on-disk database files are stored. -# The default value is the /tmp directory. +# Unknown browsers and OS are considered as crawlers # -#db-path /tmp +unknowns-as-crawlers false + +# Ignore static file requests. +# req : Only ignore request from valid requests +# panels : Ignore request from panels. +# Note that it will count them towards the total number of requests +# ignore-statics req + +# Ignore parsing and displaying the given panel. +# +#ignore-panel VISITORS +#ignore-panel REQUESTS +#ignore-panel REQUESTS_STATIC +#ignore-panel NOT_FOUND +#ignore-panel HOSTS +#ignore-panel OS +#ignore-panel BROWSERS +#ignore-panel VISIT_TIMES +#ignore-panel VIRTUAL_HOSTS +ignore-panel REFERRERS +#ignore-panel REFERRING_SITES +ignore-panel KEYPHRASES +#ignore-panel STATUS_CODES +#ignore-panel REMOTE_USER +#ignore-panel CACHE_STATUS +#ignore-panel GEO_LOCATION +#ignore-panel MIME_TYPE +#ignore-panel TLS_TYPE + +# Ignore referrers from being counted. +# This supports wild cards. For instance, +# '*' matches 0 or more characters (including spaces) +# '?' matches exactly one character +# +#ignore-referrer *.domain.com +#ignore-referrer ww?.domain.* + +# Ignore parsing and displaying one or multiple status code(s) +# +#ignore-status 400 +#ignore-status 502 + +# Keep the last specified number of days in storage. This will recycle the +# storage tables. e.g., keep & show only the last 7 days. +# +# keep-last 7 + +# Disable client IP validation. Useful if IP addresses have been +# obfuscated before being logged. +# +# no-ip-validation true + +# Number of lines from the access log to test against the provided +# log/date/time format. By default, the parser is set to test 10 +# lines. If set to 0, the parser won't test any lines and will parse +# the whole access log. +# +#num-tests 10 -# On-disk B+ Tree -# Set the size in bytes of the extra mapped memory. -# The default value is 0. +# Parse log and exit without outputting data. # -#xmmap 0 +#process-and-exit false -# On-disk B+ Tree -# Max number of leaf nodes to be cached. -# Specifies the maximum number of leaf nodes to be cached. -# If it is not more than 0, the default value is specified. -# The default value is 1024. +# Display real OS names. e.g, Windows XP, Snow Leopard. # -#cache-lcnum 1024 +real-os true + +# Sort panel on initial load. +# Sort options are separated by comma. +# Options are in the form: PANEL,METRIC,ORDER +# +# Available metrics: +# BY_HITS - Sort by hits +# BY_VISITORS - Sort by unique visitors +# BY_DATA - Sort by data +# BY_BW - Sort by bandwidth +# BY_AVGTS - Sort by average time served +# BY_CUMTS - Sort by cumulative time served +# BY_MAXTS - Sort by maximum time served +# BY_PROT - Sort by http protocol +# BY_MTHD - Sort by http method +# Available orders: +# ASC +# DESC +# +#sort-panel VISITORS,BY_DATA,ASC +#sort-panel REQUESTS,BY_HITS,ASC +#sort-panel REQUESTS_STATIC,BY_HITS,ASC +#sort-panel NOT_FOUND,BY_HITS,ASC +#sort-panel HOSTS,BY_HITS,ASC +#sort-panel OS,BY_HITS,ASC +#sort-panel BROWSERS,BY_HITS,ASC +#sort-panel VISIT_TIMES,BY_DATA,DESC +#sort-panel VIRTUAL_HOSTS,BY_HITS,ASC +#sort-panel REFERRERS,BY_HITS,ASC +#sort-panel REFERRING_SITES,BY_HITS,ASC +#sort-panel KEYPHRASES,BY_HITS,ASC +#sort-panel STATUS_CODES,BY_HITS,ASC +#sort-panel REMOTE_USER,BY_HITS,ASC +#sort-panel CACHE_STATUS,BY_HITS,ASC +#sort-panel GEO_LOCATION,BY_HITS,ASC +#sort-panel MIME_TYPE,BY_HITS,ASC +#sort-panel TLS_TYPE,BY_HITS,ASC + +# Consider the following extensions as static files +# The actual '.' is required and extensions are case sensitive +# For a full list, uncomment the less common static extensions below. +# +static-file .css +static-file .js +static-file .jpg +static-file .png +static-file .gif +static-file .ico +static-file .jpeg +static-file .pdf +static-file .csv +static-file .mpeg +static-file .mpg +static-file .swf +static-file .woff +static-file .woff2 +static-file .xls +static-file .xlsx +static-file .doc +static-file .docx +static-file .ppt +static-file .pptx +static-file .txt +static-file .zip +static-file .ogg +static-file .mp3 +static-file .mp4 +static-file .exe +static-file .iso +static-file .gz +static-file .rar +static-file .svg +static-file .bmp +static-file .tar +static-file .tgz +static-file .tiff +static-file .tif +static-file .ttf +static-file .flv +static-file .dmg +static-file .xz +static-file .zst +#static-file .less +#static-file .ac3 +#static-file .avi +#static-file .bz2 +#static-file .class +#static-file .cue +#static-file .dae +#static-file .dat +#static-file .dts +#static-file .ejs +#static-file .eot +#static-file .eps +#static-file .img +#static-file .jar +#static-file .map +#static-file .mid +#static-file .midi +#static-file .ogv +#static-file .webm +#static-file .mkv +#static-file .odp +#static-file .ods +#static-file .odt +#static-file .otf +#static-file .pict +#static-file .pls +#static-file .ps +#static-file .qt +#static-file .rm +#static-file .svgz +#static-file .wav +#static-file .webp -# On-disk B+ Tree -# Specifies the maximum number of non-leaf nodes to be cached. -# If it is not more than 0, the default value is specified. -# The default value is 512. +###################################### +# GeoIP Options +# Only if configured with --enable-geoip +###################################### + +# To feed a database either through GeoIP Legacy or GeoIP2, you need to use the +# geoip-database flag below. +# +# === GeoIP Legacy +# Legacy GeoIP has been discontinued. If your GNU+Linux distribution does not ship +# with the legacy databases, you may still be able to find them through +# different sources. Make sure to download the .dat files. # -#cache-ncnum 512 +# Distributed with Creative Commons Attribution-ShareAlike 4.0 International License. +# https://mailfud.org/geoip-legacy/ -# On-disk B+ Tree -# Specifies the number of members in each leaf page. -# If it is not more than 0, the default value is specified. -# The default value is 128. +# IPv4 Country database: +# Download the GeoIP.dat.gz +# gunzip GeoIP.dat.gz # -#tune-lmemb 128 +# IPv4 City database: +# Download the GeoIPCity.dat.gz +# gunzip GeoIPCity.dat.gz -# On-disk B+ Tree -# Specifies the number of members in each non-leaf page. -# If it is not more than 0, the default value is specified. -# The default value is 256. +# Standard GeoIP database for less memory usage (GeoIP Legacy). # -#tune-nmemb 256 +#std-geoip false + +# === GeoIP2 +# For GeoIP2 databases, you can use DB-IP Lite databases. +# DB-IP is licensed under a Creative Commons Attribution 4.0 International License. +# https://db-ip.com/db/lite.php -# On-disk B+ Tree -# Specifies the number of elements of the bucket array. -# If it is not more than 0, the default value is specified. -# The default value is 32749. -# Suggested size of the bucket array is about from 1 to 4 -# times of the number of all pages to be stored. +# Or you can download them from MaxMind +# https://dev.maxmind.com/geoip/geoip2/geolite2/ + +# For GeoIP2 City database: +# Download the GeoLite2-City.mmdb.gz +# gunzip GeoLite2-City.mmdb.gz +# +# For GeoIP2 Country database: +# Download the GeoLite2-Country.mmdb.gz +# gunzip GeoLite2-Country.mmdb.gz # -#tune-bnum 32749 +#geoip-database /usr/local/share/GeoIP/GeoLiteCity.dat + +###################################### +# Persistence Options +###################################### + +# Path where the persisted database files are stored on disk. +# The default value is the /tmp directory. +#db-path /tmp + +# Persist parsed data into disk. +#persist true + +# Load previously stored data from disk. +# Database files need to exist. See `persist`. +#restore true diff --git a/config/podcast.list b/config/podcast.list new file mode 100644 index 0000000000..49fb092b80 --- /dev/null +++ b/config/podcast.list @@ -0,0 +1,64 @@ +# vim: set noexpandtab: +#1 This file is a user agent list of various podcast-related agents (but not +#2 limited to). It was distilled from the user agents of a web page which hosts +#3 a Wordpress blog and a podcast. +#4 \author Bernhard R. Fischer, +#5 \date 2019/09/26 +AntennaPod Podcasts +AppleCoreMedia Mediaplayer +atc Podcasts +BacklinkCrawler Crawlers +Baiduspider Crawlers +Bullhorn Server PodCrawlers +Castbox Podcasts +CastBox Podcasts +Castro Podcasts +CCBot Crawlers +com.evolve.podcast Podcasts +cortex Facebook +ExoPlayerLib Mediaplayer +facebookexternalhit Facebook +fyyd image poller PodCrawlers +fyyd-poll PodCrawlers +icatcher Podcasts +iCatcher! Podcasts +iTMS PodCrawlers +itunesstored PodCrawlers +Kodi Mediaplayer +Lavf Mediaplayer +LCC Crawlers +Luminary Podcasts +Mediatoolkitbot Crawlers +mindUpBot Crawlers +msnbot Crawlers +NSPlayer Mediaplayer +Overcast Podcasts +Photon Crawlers +Player FM Podcasts +PlayerFM Podcasts +Plex Mediaplayer +Podbean Podcasts +podcast Podcasts +Podcast Podcasts +PodcastRepublic Podcasts +Podcasts Podcasts +Podchaser PodCrawlers +Podchaser-Parser PodCrawlers +Podnews.net PodCrawlers +PodParadise PodCrawlers +Procast Podcasts +ProCast Podcasts +Procast (iOS) Podcasts +ProcastProCast Podcasts +radio.at PodCrawlers +RadioPublic PodCrawlers +RadioPublicImageResizer PodCrawlers +RSSRadio Podcasts +Sonos Mediaplayer +Spotify PodCrawlers +stagefright Mediaplayer +Stitcher PodCrawlers +UniversalFeedParser Feeds +WinampMPEG Mediaplayer +XING FeedReader Feeds +XING-contenttabreceiver Feeds diff --git a/configure.ac b/configure.ac index 59a53541cb..ad869944f3 100644 --- a/configure.ac +++ b/configure.ac @@ -1,50 +1,124 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_PREREQ(2.61) -AC_INIT([goaccess], [0.8], [goaccess@prosoftcorp.com], [], - [http://goaccess.prosoftcorp.com]) -AM_INIT_AUTOMAKE -AC_CONFIG_SRCDIR([goaccess.c]) -AC_CONFIG_HEADERS([config.h]) +AC_PREREQ([2.69]) +AC_INIT([goaccess],[1.9.3],[hello@goaccess.io],[],[https://goaccess.io]) +AM_INIT_AUTOMAKE([foreign]) +AC_CONFIG_SRCDIR([src/goaccess.c]) +AC_CONFIG_HEADERS([src/config.h]) # Use empty CFLAGS by default so autoconf does not add # CFLAGS="-O2 -g" +# NOTE: Needs to go after AC_INIT and before AC_PROG_CC to select an +# empty default instead. : ${CFLAGS=""} -# Checks for programs. -AC_PROG_CC +# Prefer host default compiler +AC_PROG_CC([cc gcc clang]) +AM_PROG_CC_C_O + +# Check for programs +AM_GNU_GETTEXT([external]) +AM_GNU_GETTEXT_VERSION([0.19]) +# Fix `undefined reference to `libintl_gettext'` on docker: +AC_CHECK_LIB([intl], [libintl_dgettext]) +# Fix undefined reference to dgettext on NetBSD +AC_CHECK_LIB([intl], [dgettext]) # pthread AC_CHECK_LIB([pthread], [pthread_create], [], [AC_MSG_ERROR([pthread is missing])]) CFLAGS="$CFLAGS -pthread" # DEBUG -AC_ARG_ENABLE(debug, [ --enable-debug Create a debug build. Default is disabled], - [debug="$enableval"], debug=no) +AC_ARG_ENABLE([debug],[AS_HELP_STRING([--enable-debug],[Create a debug build. Default is disabled])],[debug="$enableval"],[debug=no]) if test "$debug" = "yes"; then AC_DEFINE([_DEBUG], 1, [Debug option]) fi AM_CONDITIONAL([DEBUG], [test "x$debug" = "xyes"]) +# Handle rdynamic only on systems using GNU ld +AC_CANONICAL_HOST +AC_MSG_CHECKING([whether to build with rdynamic for GNU ld]) +with_rdyanimc=yes +case "$host_os" in + *darwin*|*cygwin*|*aix*|*mingw*) with_rdyanimc=no + ;; +esac +AC_MSG_RESULT([$with_rdyanimc]) +AM_CONDITIONAL([WITH_RDYNAMIC], [test "x$with_rdyanimc" = "xyes"]) + +# Add ASAN +AC_CANONICAL_HOST +AC_ARG_ENABLE([asan], + [AS_HELP_STRING([--enable-asan], [Enable address sanitizer])], + [with_asan=$enableval], [with_asan=no]) +AC_MSG_CHECKING([whether to build with address sanitizer]) +case "$host_os" in + *cygwin*|*aix*|*mingw*) with_asan=no + ;; +esac +AC_MSG_RESULT([$with_asan]) +AM_CONDITIONAL([WITH_ASAN], [test "x$with_asan" = "xyes"]) + +# Check for libc implementation on NetBSD +AC_CHECK_HEADERS([sha.h sha1.h]) +AC_CHECK_FUNCS([SHA1Init]) +AM_CONDITIONAL([USE_SHA1], [test "x$ac_cv_func_SHA1Init" != "xyes"]) + +# Build with OpenSSL +AC_ARG_WITH([openssl],[AS_HELP_STRING([--with-openssl],[Build with OpenSSL support. Default is disabled])],[openssl="$withval"],[openssl="no"]) + +if test "$openssl" = 'yes'; then + AC_CHECK_LIB([ssl], [SSL_CTX_new],,[AC_MSG_ERROR([ssl library missing])]) + AC_CHECK_LIB([crypto], [CRYPTO_free],,[AC_MSG_ERROR([crypto library missing])]) + AC_CHECK_LIB([ssl], [SSL_CIPHER_standard_name], [AC_DEFINE([HAVE_CIPHER_STD_NAME], 1, [HAVE_CIPHER_STD_NAME])]) +fi + # GeoIP -AC_ARG_ENABLE(geoip, [ --enable-geoip Enable GeoIP country lookup. Default is disabled], - [geoip="$enableval"], geoip=no) +AC_ARG_ENABLE([geoip],[AS_HELP_STRING([--enable-geoip],[Enable GeoIP country lookup. Supported types: mmdb, legacy. Default is disabled])],[geoip="$enableval"],[geoip=no]) + +geolocation="N/A" +if test "$geoip" = "mmdb"; then + AC_CHECK_LIB([maxminddb], [MMDB_open], [], [AC_MSG_ERROR([ + *** Missing development files for libmaxminddb library. + ])]) + geolocation="GeoIP2" + AC_DEFINE([HAVE_GEOLOCATION], 1, [Build using GeoIP.]) +elif test "$geoip" = "legacy"; then + AC_CHECK_LIB([GeoIP], [GeoIP_new], [], [AC_MSG_ERROR([ + *** Missing development files for the GeoIP library + ])]) + geolocation="GeoIP Legacy" + AC_DEFINE([HAVE_GEOLOCATION], 1, [Build using GeoIP.]) +elif test "$geoip" != "no"; then + AC_MSG_ERROR([*** Invalid argument for GeoIP: $geoip]) +fi +AM_CONDITIONAL([GEOIP_LEGACY], [test "x$geoip" = "xlegacy"]) +AM_CONDITIONAL([GEOIP_MMDB], [test "x$geoip" = "xmmdb"]) + +# GNU getline / POSIX.1-2008 +AC_ARG_WITH([getline],[AS_HELP_STRING([--with-getline],[Build using dynamic line buffer. Default is disabled])],[with_getline=$withval],[with_getline=no]) -if test "$geoip" = "yes"; then - AC_CHECK_LIB([GeoIP], [GeoIP_new], [], - [AC_MSG_ERROR([*** Missing development files for the GeoIP library])]) +if test "$with_getline" = "yes"; then + AC_DEFINE([WITH_GETLINE], 1, [Build using GNU getline.]) fi -AM_CONDITIONAL([GEOLOCATION], [test "x$geoip" = "xyes"]) # UTF8 -AC_ARG_ENABLE(utf8, [ --enable-utf8 Enable ncurses library that handles wide characters], - [utf8="$enableval"], utf8=no) +AC_ARG_ENABLE([utf8],[AS_HELP_STRING([--enable-utf8],[Enable ncurses library that handles wide characters. Default is disabled])],[utf8="$enableval"],[utf8=no]) if test "$utf8" = "yes"; then - AC_CHECK_LIB([ncursesw], [mvaddwstr], [], - [AC_MSG_ERROR([*** Missing development libraries for ncursesw])]) + libncursesw=ncursesw + # Simply called libncurses on OS X + case "$host_os" in + *darwin*) libncursesw=ncurses + ;; + esac + + AC_CHECK_LIB([$libncursesw], [mvaddwstr], [], + [AC_MSG_ERROR([*** Missing development libraries for ncursesw])]) + AC_SEARCH_LIBS([tputs], [tinfow], ,[AC_MSG_ERROR([Cannot find a library providing tputs])]) + AC_DEFINE([HAVE_LIBNCURSESW], [1], ["ncursesw is present."]) have_ncurses="yes" AC_CHECK_HEADERS([ncursesw/ncurses.h],[have_ncurses=yes], [], [ @@ -64,7 +138,9 @@ if test "$utf8" = "yes"; then fi else AC_CHECK_LIB([ncurses], [refresh], [], - [AC_MSG_ERROR([*** Missing development libraries for ncurses])]) + [AC_CHECK_LIB([curses], [refresh], [], + [AC_MSG_ERROR([*** Missing development libraries for ncurses])])]) + AC_SEARCH_LIBS([tputs], [tinfo], ,[AC_MSG_ERROR([Cannot find a library providing tputs])]) have_ncurses="yes" AC_CHECK_HEADERS([ncurses/ncurses.h],[have_ncurses=yes], [], [ @@ -86,157 +162,120 @@ else ]) if test "$have_ncurses" != "yes"; then - AC_MSG_ERROR([Missing ncursesw header file]) + AC_MSG_ERROR([Missing ncurses header file]) fi fi -# Tokyo Cabinet -AC_ARG_ENABLE(tcb, [ --enable-tcb Enable TokyoCabinet database. Default is disabled], - [tcb="$enableval"], tcb=no) - -WITH_TC=no -if test "$tcb" = "memhash"; then - WITH_TC=yes - AC_DEFINE([TCB_MEMHASH], [1], ["Build using on-memory hash database"]) -elif test "$tcb" = "btree"; then - AC_DEFINE([TCB_BTREE], [1], ["Build using on-disk B+ Tree database"]) - WITH_TC=yes -fi - -if test "$WITH_TC" = "yes"; then - AC_CHECK_LIB([tokyocabinet], [tchdbnew], [], - [AC_MSG_ERROR([*** Missing development libraries for Tokyo Cabinet Database])]) - - AC_ARG_ENABLE([zlib], [ --disable-zlib Build without ZLIB compression], - [zlib="$enableval"], zlib=yes) - - if test "$zlib" = "yes"; then - AC_CHECK_LIB(z, gzread, [Z_FLAG=-lz], AC_MSG_ERROR([ - *** zlib is required. If zlib compression is not needed - *** you can use --disable-zlib. - *** Debian based distributions zlib1g-dev - *** Red Hat based distributions zlib-devel - ])) - AC_DEFINE([HAVE_ZLIB], [1], ["Build using ZLIB"]) - CFLAGS="$CFLAGS $Z_FLAG" - fi +# Default Hash +storage="In-Memory with On-Disk Persistent Storage" - AC_ARG_ENABLE([bzip], [ --disable-bzip Build without BZIP2 compression], - [bz2="$enableval"], bz2=yes) - - if test "$bz2" = "yes"; then - AC_CHECK_LIB(bz2, BZ2_bzopen, [BZ2_FLAG=-lbz2], AC_MSG_ERROR([ - *** BZIP2 is required. If BZIP2 compression is not needed - *** you can use --disable-bzip. - *** Debian based distributions libbz2-dev - *** Red Hat based distributions bzip2-devel - ])) - AC_DEFINE([HAVE_BZ2], [1], ["Build using BZ2"]) - CFLAGS="$CFLAGS $BZ2_FLAG" +HAS_SEDTR=no +AC_CHECK_PROG([SED_CHECK],[sed],[yes],[no]) +if test x"$SED_CHECK" = x"yes" ; then + AC_CHECK_PROG([TR_CHECK],[tr],[yes],[no]) + if test x"$TR_CHECK" = x"yes" ; then + HAS_SEDTR=yes fi - - CFLAGS="$CFLAGS -ltokyocabinet -lrt -lc" - -# GLib otherwise -else - # Check for pkg-config program, used for configuring some libraries. - m4_define_default([PKG_PROG_PKG_CONFIG], - [AC_MSG_CHECKING([pkg-config]) - AC_MSG_RESULT([no])]) - - PKG_PROG_PKG_CONFIG - - # If pkg-config autoconf support isn't installed, define its autoconf macro. - m4_define_default([PKG_CHECK_MODULES], - [AC_MSG_CHECKING([$1]) - AC_MSG_RESULT([no]) - $4]) - - AC_PATH_PROG([PKG_CONFIG], [pkg-config], [no]) - - AS_IF([test "x$PKG_CONFIG" = "xno"],[ - AC_MSG_ERROR([ - *** pkg-config script could not be found. Make sure it is - *** in your path, or set the PKG_CONFIG environment variable - *** to the full path to pkg-config. Otherwise, reinstall glib2 - *** development files (libglib2.0-dev)]) - ]) - - PKG_CHECK_MODULES(GLIB2, glib-2.0, [], AC_MSG_ERROR([*** Missing development libraries for GLib])) - AC_SUBST(GLIB2_CFLAGS) - AC_SUBST(GLIB2_LIBS) - AC_CHECK_LIB([glib-2.0], [g_list_append], [], [AC_MSG_ERROR([*** Missing development libraries for GLib])]) -fi -AM_CONDITIONAL([TCB], [test "$WITH_TC" = "yes"]) - -if test "$tcb" = "memhash"; then - storage="On-memory Hash Database (Tokyo Cabinet)" -elif test "$tcb" = "btree"; then - storage="On-disk B+ Tree Database (Tokyo Cabinet)" -else - storage="On-memory Hash Database (GLib)" fi +AM_CONDITIONAL([HAS_SEDTR], [test "x$HAS_SEDTR" = xyes]) + +# detect Cygwin or MinGW and use mmap family replacements +USE_MMAP=no +case $host in + *-*-mingw32* | *-*-cygwin* | *-*-windows*) + USE_MMAP=yes + AC_MSG_NOTICE([using custom mmap for Cygwin/MinGW]) + ;; +esac +AM_CONDITIONAL([USE_MMAP], [test "x$USE_MMAP" = xyes]) # Solaris -AC_CHECK_LIB([socket], [socket]) AC_CHECK_LIB([nsl], [gethostbyname]) +AC_CHECK_LIB([socket], [socket]) # Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS([netinet/in.h]) -AC_CHECK_HEADERS([sys/socket.h]) AC_CHECK_HEADERS([arpa/inet.h]) +AC_CHECK_HEADERS([fcntl.h]) +AC_CHECK_HEADERS([inttypes.h]) +AC_CHECK_HEADERS([limits.h]) AC_CHECK_HEADERS([locale.h]) AC_CHECK_HEADERS([netdb.h]) +AC_CHECK_HEADERS([netinet/in.h]) +AC_CHECK_HEADERS([stddef.h]) AC_CHECK_HEADERS([stdint.h]) AC_CHECK_HEADERS([stdlib.h]) AC_CHECK_HEADERS([string.h]) +AC_CHECK_HEADERS([strings.h]) +AC_CHECK_HEADERS([sys/socket.h]) +AC_CHECK_HEADERS([sys/time.h]) AC_CHECK_HEADERS([unistd.h]) -AC_CHECK_HEADERS([stddef.h]) # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST +AC_CHECK_TYPES([ptrdiff_t]) +AC_STRUCT_TM +AC_TYPE_INT64_T +AC_TYPE_INT8_T AC_TYPE_OFF_T AC_TYPE_SIZE_T -AC_STRUCT_TM -AC_CHECK_TYPES([ptrdiff_t]) +AC_TYPE_UINT32_T +AC_TYPE_UINT64_T +AC_TYPE_UINT8_T # Checks for library functions. -AC_FUNC_STRTOD AC_FUNC_FSEEKO AC_FUNC_MEMCMP +AC_FUNC_MKTIME AC_FUNC_STAT AC_FUNC_STRFTIME -AC_CHECK_FUNCS([regcomp]) -AC_CHECK_FUNCS([strtoull]) -AC_CHECK_FUNCS([memmove]) +AC_FUNC_STRTOD AC_CHECK_FUNCS([floor]) AC_CHECK_FUNCS([gethostbyaddr]) AC_CHECK_FUNCS([gethostbyname]) +AC_CHECK_FUNCS([gettimeofday]) +AC_CHECK_FUNCS([malloc]) +AC_CHECK_FUNCS([memmove]) AC_CHECK_FUNCS([memset]) +AC_CHECK_FUNCS([mkfifo]) +AC_CHECK_FUNCS([poll]) +AC_CHECK_FUNCS([realloc]) +AC_CHECK_FUNCS([realpath]) +AC_CHECK_FUNCS([regcomp]) AC_CHECK_FUNCS([setlocale]) +AC_CHECK_FUNCS([socket]) +AC_CHECK_FUNCS([strcasecmp]) AC_CHECK_FUNCS([strchr]) +AC_CHECK_FUNCS([strcspn]) AC_CHECK_FUNCS([strdup]) AC_CHECK_FUNCS([strerror]) +AC_CHECK_FUNCS([strncasecmp]) +AC_CHECK_FUNCS([strpbrk]) AC_CHECK_FUNCS([strrchr]) +AC_CHECK_FUNCS([strspn]) AC_CHECK_FUNCS([strstr]) AC_CHECK_FUNCS([strtol]) -AC_CHECK_FUNCS([realpath]) -AC_CHECK_FUNCS([malloc]) -AC_CHECK_FUNCS([realloc]) +AC_CHECK_FUNCS([strtoull]) +AC_CHECK_FUNCS([timegm]) -AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([Makefile po/Makefile.in]) AC_OUTPUT cat << EOF Your build configuration: - CFLAGS = $CFLAGS - storage: $storage - prefix: $prefix - package: $PACKAGE_NAME - version: $VERSION - bugs: $PACKAGE_BUGREPORT + Prefix : $prefix + Package : $PACKAGE_NAME + Version : $VERSION + Compiler flags : $CFLAGS + Linker flags : $LIBS $LDFLAGS + UTF-8 support : $utf8 + Dynamic buffer : $with_getline + ASan : $with_asan + Geolocation : $geolocation + Storage method : $storage + TLS/SSL : $openssl + Bugs : $PACKAGE_BUGREPORT EOF diff --git a/csv.c b/csv.c deleted file mode 100644 index 772d729723..0000000000 --- a/csv.c +++ /dev/null @@ -1,308 +0,0 @@ -/** - * output.c -- output csv to the standard output stream - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#define _LARGEFILE_SOURCE -#define _LARGEFILE64_SOURCE -#define _FILE_OFFSET_BITS 64 - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "csv.h" - -#ifdef HAVE_LIBTOKYOCABINET -#include "tcabinet.h" -#else -#include "glibht.h" -#endif - -#include "commons.h" -#include "error.h" -#include "ui.h" -#include "util.h" -#include "xmalloc.h" - -static void -escape_cvs_output (FILE * fp, char *s) -{ - while (*s) { - switch (*s) { - case '"': - fprintf (fp, "\"\""); - break; - default: - fputc (*s, fp); - break; - } - s++; - } -} - -static void -print_csv_sub_items (FILE * fp, GSubList * sub_list, int process, - const char *id, int *idx) -{ - char *data; - float percent; - GSubItem *iter; - int hits, i = 0; - - for (iter = sub_list->head; iter; iter = iter->next) { - hits = iter->hits; - data = (char *) iter->data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - - fprintf (fp, "\"%d\",", i); /* idx */ - fprintf (fp, "\"%d\",", (*idx)); /* parent idx */ - fprintf (fp, "\"%s\",", id); - fprintf (fp, "\"%d\",", hits); - fprintf (fp, "\"%4.2f%%\",", percent); - fprintf (fp, "\""); - escape_cvs_output (fp, data); - fprintf (fp, "\","); - fprintf (fp, "\r\n"); /* parent idx */ - i++; - } -} - -/** - * Generate CSV on partial fields for the following modules: - * OS, BROWSERS, REFERRERS, REFERRING_SITES, KEYPHRASES, STATUS_CODES - */ -static void -print_csv_generic (FILE * fp, const GHolder * h, int process) -{ - char *data; - const char *id = NULL; - float percent; - int i, idx, hits; - - if (h->module == BROWSERS) - id = BROWS_ID; - else if (h->module == OS) - id = OPERA_ID; - else if (h->module == REFERRERS) - id = REFER_ID; - else if (h->module == REFERRING_SITES) - id = SITES_ID; - else if (h->module == KEYPHRASES) - id = KEYPH_ID; - else if (h->module == STATUS_CODES) - id = CODES_ID; -#ifdef HAVE_LIBGEOIP - else if (h->module == GEO_LOCATION) - id = GEOLO_ID; -#endif - - for (i = 0, idx = 0; i < h->idx; i++, idx++) { - hits = h->items[i].hits; - data = h->items[i].data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - - fprintf (fp, "\"%d\",", idx); /* idx */ - fprintf (fp, ","); /* parent idx */ - fprintf (fp, "\"%s\",", id); - fprintf (fp, "\"%d\",", hits); - fprintf (fp, "\"%4.2f%%\",", percent); - fprintf (fp, "\""); - escape_cvs_output (fp, data); - fprintf (fp, "\","); - fprintf (fp, "\r\n"); /* parent idx */ - - if (h->module == OS || h->module == BROWSERS || h->module == STATUS_CODES -#ifdef HAVE_LIBGEOIP - || h->module == GEO_LOCATION -#endif - ) - print_csv_sub_items (fp, h->items[i].sub_list, process, id, &idx); - } -} - -/** - * Generate CSV on complete fields for the following modules: - * REQUESTS, REQUESTS_STATIC, NOT_FOUND, HOSTS - */ -static void -print_csv_complete (FILE * fp, GHolder * holder, int process) -{ - char *data, *method = NULL, *protocol = NULL; - const char *id = NULL; - float percent; - GHolder *h; - int i, j, hits; - unsigned long long bw, usecs; - - for (i = 0; i < 4; i++) { - switch (i) { - case 0: - h = holder + REQUESTS; - id = REQUE_ID; - break; - case 1: - h = holder + REQUESTS_STATIC; - id = STATI_ID; - break; - case 2: - h = holder + NOT_FOUND; - id = FOUND_ID; - break; - case 3: - h = holder + HOSTS; - id = HOSTS_ID; - break; - } - - for (j = 0; j < h->idx; j++) { - hits = h->items[j].hits; - data = h->items[j].data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - bw = h->items[j].bw; - usecs = h->items[j].usecs; - method = h->items[j].method; - protocol = h->items[j].protocol; - - fprintf (fp, "\"%d\",", j); /* idx */ - fprintf (fp, ","); /* parent idx */ - fprintf (fp, "\"%s\",", id); - fprintf (fp, "\"%d\",", hits); - fprintf (fp, "\"%4.2f%%\",", percent); - fprintf (fp, "\""); - escape_cvs_output (fp, data); - fprintf (fp, "\","); - fprintf (fp, "\"%lld\"", bw); - - if (conf.serve_usecs) - fprintf (fp, ",\"%lld\"", usecs); - if (conf.append_protocol && protocol) - fprintf (fp, ",\"%s\"", protocol); - if (conf.append_method && method) - fprintf (fp, ",\"%s\"", method); - fprintf (fp, "\r\n"); - } - } -} - -/* generate CSV unique visitors stats */ -static void -print_csv_visitors (FILE * fp, GHolder * h) -{ - char *data, buf[DATE_LEN]; - float percent; - int hits, bw, i, process = get_ht_size (ht_unique_visitors); - - /* make compiler happy */ - memset (buf, 0, sizeof (buf)); - - for (i = 0; i < h->idx; i++) { - hits = h->items[i].hits; - data = h->items[i].data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - bw = h->items[i].bw; - convert_date (buf, data, "%Y%m%d", "%d/%b/%Y", DATE_LEN); - - fprintf (fp, "\"%d\",", i); /* idx */ - fprintf (fp, ","); /* parent idx */ - fprintf (fp, "\"%s\",", VISIT_ID); - fprintf (fp, "\"%d\",", hits); - fprintf (fp, "\"%4.2f%%\",", percent); - fprintf (fp, "\"%s\",", buf); - fprintf (fp, "\"%d\"\r\n", bw); - } -} - -/* generate overview stats */ -static void -print_csv_summary (FILE * fp, GLog * logger) -{ - int i = 0; - off_t log_size = 0; - char now[DATE_TIME]; - - generate_time (); - strftime (now, DATE_TIME, "%Y-%m-%d %H:%M:%S", now_tm); - - /* general statistics info */ - fprintf (fp, "\"%d\",,\"%s\",\"date_time\",\"%s\"\r\n", i++, GENER_ID, now); - fprintf (fp, "\"%d\",,\"%s\",\"total_requests\",\"%d\"\r\n", i++, GENER_ID, - logger->process); - fprintf (fp, "\"%d\",,\"%s\",\"unique_visitors\",\"%d\"\r\n", i++, GENER_ID, - get_ht_size (ht_unique_visitors)); - fprintf (fp, "\"%d\",,\"%s\",\"referrers\",\"%d\"\r\n", i++, GENER_ID, - get_ht_size (ht_referrers)); - - if (!logger->piping) - log_size = file_size (conf.ifile); - - fprintf (fp, "\"%d\",,\"%s\",\"log_size\",\"%jd\"\r\n", i++, GENER_ID, - (intmax_t) log_size); - fprintf (fp, "\"%d\",,\"%s\",\"failed_requests\",\"%d\"\r\n", i++, GENER_ID, - logger->invalid); - fprintf (fp, "\"%d\",,\"%s\",\"unique_files\",\"%d\"\r\n", i++, GENER_ID, - get_ht_size (ht_requests)); - fprintf (fp, "\"%d\",,\"%s\",\"unique_404\",\"%d\"\r\n", i++, GENER_ID, - get_ht_size (ht_not_found_requests)); - - fprintf (fp, "\"%d\",,\"%s\",\"bandwidth\",\"%lld\"\r\n", i++, GENER_ID, - logger->resp_size); - fprintf (fp, "\"%d\",,\"%s\",\"generation_time\",\"%llu\"\r\n", i++, - GENER_ID, (long long) end_proc - start_proc); - fprintf (fp, "\"%d\",,\"%s\",\"static_files\",\"%d\"\r\n", i++, GENER_ID, - get_ht_size (ht_requests_static)); - - if (conf.ifile == NULL) - conf.ifile = (char *) "STDIN"; - - fprintf (fp, "\"%d\",,\"%s\",\"log_file\",\"%s\"\r\n", i, GENER_ID, - conf.ifile); -} - -/* entry point to generate a a csv report writing it to the fp */ -void -output_csv (GLog * logger, GHolder * holder) -{ - FILE *fp = stdout; - - print_csv_summary (fp, logger); - print_csv_visitors (fp, holder + VISITORS); - print_csv_complete (fp, holder, logger->process); - print_csv_generic (fp, holder + OS, get_ht_size (ht_unique_visitors)); - print_csv_generic (fp, holder + BROWSERS, get_ht_size (ht_unique_visitors)); - print_csv_generic (fp, holder + REFERRERS, logger->process); - print_csv_generic (fp, holder + REFERRING_SITES, logger->process); - print_csv_generic (fp, holder + KEYPHRASES, logger->process); -#ifdef HAVE_LIBGEOIP - print_csv_generic (fp, holder + GEO_LOCATION, logger->process); -#endif - print_csv_generic (fp, holder + STATUS_CODES, logger->process); - - fclose (fp); -} diff --git a/csv.h b/csv.h deleted file mode 100644 index 33aa0bdd11..0000000000 --- a/csv.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#if HAVE_CONFIG_H -#include -#endif - -#ifndef CSV_H_INCLUDED -#define CSV_H_INCLUDED - -#include "commons.h" -#include "parser.h" -#include "settings.h" - -void output_csv (GLog * logger, GHolder * holder); - -#endif diff --git a/error.c b/error.c deleted file mode 100644 index a9dbb8d90b..0000000000 --- a/error.c +++ /dev/null @@ -1,102 +0,0 @@ -/** - * error.c -- error handling - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#if HAVE_CONFIG_H -#include -#endif - -#ifdef HAVE_NCURSESW_NCURSES_H -#include -#elif HAVE_NCURSES_NCURSES_H -#include -#elif HAVE_NCURSES_H -#include -#elif HAVE_CURSES_H -#include -#endif - -#include -#include - -#include "error.h" -#include "commons.h" - -static FILE *log_file; - -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -void -error_handler (const char *func, const char *file, int line, const char *msg, - ...) -{ - va_list args; - - (void) endwin (); - - fprintf (stderr, "\nGoAccess - version %s - %s %s\n", GO_VERSION, - __DATE__, __TIME__); - fprintf (stderr, "\nAn error has occurred"); - fprintf (stderr, "\nError occured at: %s - %s - %d", file, func, line); - fprintf (stderr, "\nMessage: "); - - va_start (args, msg); - vfprintf (stderr, msg, args); - va_end (args); - - fprintf (stderr, "\n\n"); - - exit (EXIT_FAILURE); -} - -#pragma GCC diagnostic warning "-Wformat-nonliteral" - -void -dbg_log_open (const char *path) -{ - if (path != NULL) { - log_file = fopen (path, "w"); - if (log_file == NULL) - return; - } -} - -void -dbg_log_close (void) -{ - if (log_file != NULL) - fclose (log_file); -} - -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -void -dbg_fprintf (const char *fmt, ...) -{ - va_list args; - - if (!log_file) - return; - - va_start (args, fmt); - vfprintf (log_file, fmt, args); - fflush (log_file); - va_end (args); -} - -#pragma GCC diagnostic warning "-Wformat-nonliteral" diff --git a/error.h b/error.h deleted file mode 100644 index d9d7ebac3e..0000000000 --- a/error.h +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#ifndef ERROR_H_INCLUDED -#define ERROR_H_INCLUDED - -#ifndef COMMONS -#include "commons.h" -#endif - -void dbg_fprintf (const char *fmt, ...); -void dbg_log_close (void); -void dbg_log_open (const char *file); -void error_handler (const char *func, const char *file, int line, - const char *msg, ...); - -#endif diff --git a/gdashboard.c b/gdashboard.c deleted file mode 100644 index 97913d918d..0000000000 --- a/gdashboard.c +++ /dev/null @@ -1,1492 +0,0 @@ -/** - * gmenu.c -- goaccess main dashboard - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#define _XOPEN_SOURCE 700 - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "gdashboard.h" - -#ifdef HAVE_LIBTOKYOCABINET -#include "tcabinet.h" -#else -#include "glibht.h" -#endif - -#ifdef HAVE_LIBGEOIP -#include "geolocation.h" -#endif - -#include "error.h" -#include "gdns.h" -#include "parser.h" -#include "settings.h" -#include "util.h" -#include "xmalloc.h" - -/* *INDENT-OFF* */ - -static GFind find_t; -/* module's styles */ -static const GDashStyle module_style[TOTAL_MODULES] = { - {COL_WHITE, COL_WHITE, COL_BLACK, COL_RED, COL_WHITE, -1, -1, -1}, /* VISITORS */ - {COL_WHITE, COL_WHITE, COL_BLACK, COL_BLACK, -1, COL_BLACK, COL_BLACK, COL_WHITE}, /* REQUESTS */ - {COL_WHITE, COL_WHITE, COL_BLACK, COL_BLACK, -1, COL_BLACK, COL_BLACK, COL_WHITE}, /* REQUESTS_STATIC */ - {COL_WHITE, COL_WHITE, COL_BLACK, COL_BLACK, -1, COL_BLACK, COL_BLACK, COL_WHITE}, /* NOT FOUND */ - {COL_WHITE, COL_WHITE, COL_BLACK, COL_BLACK, COL_WHITE, COL_BLACK, -1, -1}, /* HOSTS */ - {COL_WHITE, COL_WHITE, -1, COL_RED, COL_WHITE, -1, -1, -1}, /* OS */ - {COL_WHITE, COL_WHITE, -1, COL_RED, COL_WHITE, -1, -1, -1}, /* BROWSERS */ - {COL_WHITE, COL_WHITE, -1, COL_BLACK, -1, -1, -1, -1}, /* REFERRERS */ - {COL_WHITE, COL_WHITE, -1, COL_BLACK, -1, -1, -1, -1}, /* REFERRING_SITES */ - {COL_WHITE, COL_WHITE, -1, COL_BLACK, -1, -1, -1, -1}, /* KEYPHRASES */ -#ifdef HAVE_LIBGEOIP - {COL_WHITE, COL_WHITE, -1, COL_BLACK, -1, -1, -1, -1}, /* GEO_LOCATION */ -#endif - {COL_WHITE, COL_WHITE, -1, COL_BLACK, -1, -1, -1, -1}, /* STATUS CODES */ -}; -/* *INDENT-ON* */ - -/* reset find indices */ -void -reset_find (void) -{ - if (find_t.pattern != NULL && *find_t.pattern != '\0') - free (find_t.pattern); - - find_t.look_in_sub = 0; - find_t.module = 0; - find_t.next_idx = 0; /* next total index */ - find_t.next_parent_idx = 0; /* next parent index */ - find_t.next_sub_idx = 0; /* next sub item index */ - find_t.pattern = NULL; -} - -/* allocate memory for dash */ -GDash * -new_gdash (void) -{ - GDash *dash = xmalloc (sizeof (GDash)); - memset (dash, 0, sizeof *dash); - dash->total_alloc = 0; - - return dash; -} - -/* allocate memory for dash elements */ -GDashData * -new_gdata (uint32_t size) -{ - GDashData *data = xcalloc (size, sizeof (GDashData)); - return data; -} - -/* free dash and its elements */ -void -free_dashboard (GDash * dash) -{ - int i, j; - for (i = 0; i < TOTAL_MODULES; i++) { - for (j = 0; j < dash->module[i].alloc_data; j++) { - free (dash->module[i].data[j].data); - free (dash->module[i].data[j].bandwidth); - if (conf.serve_usecs) - free (dash->module[i].data[j].serve_time); - } - free (dash->module[i].data); - } - free (dash); -} - -/* allocate memory for holder */ -GHolder * -new_gholder (uint32_t size) -{ - GHolder *holder = xmalloc (size * sizeof (GHolder)); - memset (holder, 0, size * sizeof *holder); - - return holder; -} - -/* allocate memory for holder items */ -static GHolderItem * -new_gholder_item (uint32_t size) -{ - GHolderItem *item = xcalloc (size, sizeof (GHolderItem)); - return item; -} - -/* allocate memory for a sub list */ -static GSubList * -new_gsublist (void) -{ - GSubList *sub_list = xmalloc (sizeof (GSubList)); - sub_list->head = NULL; - sub_list->tail = NULL; - sub_list->size = 0; - return sub_list; -} - -/* allocate memory for a sub list item */ -static GSubItem * -new_gsubitem (GModule module, char *data, int hits, uint64_t bw) -{ - GSubItem *sub_item = xmalloc (sizeof (GSubItem)); - sub_item->data = data; - sub_item->hits = hits; - sub_item->bw = bw; - sub_item->module = module; - sub_item->prev = NULL; - sub_item->next = NULL; - return sub_item; -} - -/* add an item to the end of a given sub list */ -static void -add_sub_item_back (GSubList * sub_list, GModule module, char *data, int hits, - uint64_t bw) -{ - GSubItem *sub_item = new_gsubitem (module, data, hits, bw); - if (sub_list->tail) { - sub_list->tail->next = sub_item; - sub_item->prev = sub_list->tail; - sub_list->tail = sub_item; - } else { - sub_list->head = sub_item; - sub_list->tail = sub_item; - } - sub_list->size++; -} - -/* delete entire given sub list */ -static void -delete_sub_list (GSubList * sub_list) -{ - GSubItem *item = item; - GSubItem *next = next; - - if (sub_list != NULL && sub_list->size == 0) - goto clear; - if (sub_list->size == 0) - return; - - for (item = sub_list->head; item; item = next) { - next = item->next; - free (item->data); - free (item); - } -clear: - sub_list->head = NULL; - sub_list->size = 0; - free (sub_list); -} - -/* dynamically allocated holder fields */ -static void -free_holder_data (GHolderItem item) -{ - if (item.data != NULL) - free (item.data); - if (item.method != NULL) - free (item.method); - if (item.protocol != NULL) - free (item.protocol); -} - -/* free memory allocated in holder for specific module */ -void -free_holder_by_module (GHolder ** holder, GModule module) -{ - GSubList *sub_list; - int j; - - if ((*holder) == NULL) - return; - - for (j = 0; j < (*holder)[module].holder_size; j++) { - sub_list = (*holder)[module].items[j].sub_list; - /* free the sub list */ - if (sub_list != NULL) - delete_sub_list (sub_list); - free_holder_data ((*holder)[module].items[j]); - } - free ((*holder)[module].items); - (*holder)[module].holder_size = 0; - (*holder)[module].idx = 0; - (*holder)[module].sub_items_size = 0; -} - -/* free memory allocated in holder */ -void -free_holder (GHolder ** holder) -{ - GSubList *sub_list; - int i, j; - - if ((*holder) == NULL) - return; - - for (i = 0; i < TOTAL_MODULES; i++) { - for (j = 0; j < (*holder)[i].holder_size; j++) { - sub_list = (*holder)[i].items[j].sub_list; - /* free the sub list */ - if (sub_list != NULL) - delete_sub_list (sub_list); - free_holder_data ((*holder)[i].items[j]); - } - free ((*holder)[i].items); - } - free (*holder); - (*holder) = NULL; -} - -/** - * Determine which module should be expanded given the - * current mouse position. - */ -int -set_module_from_mouse_event (GScrolling * scrolling, GDash * dash, int y) -{ - int module = 0, i; - int offset = y - MAX_HEIGHT_HEADER - MAX_HEIGHT_FOOTER + 1; - if (scrolling->expanded) { - for (i = 0; i < TOTAL_MODULES; i++) { - /* set current module */ - if (dash->module[i].pos_y == offset) { - module = i; - break; - } - /* we went over by one module, set current - 1 */ - if (dash->module[i].pos_y > offset) { - module = i - 1; - break; - } - } - } else { - offset += scrolling->dash; - module = offset / DASH_COLLAPSED; - } - - if (module >= TOTAL_MODULES) - module = TOTAL_MODULES - 1; - else if (module < 0) - module = 0; - - if ((int) scrolling->current == module) - return 1; - - scrolling->current = module; - return 0; -} - -/* render child nodes */ -static char * -render_child_node (const char *data) -{ - char *buf; - int len = 0; - -#ifdef HAVE_LIBNCURSESW - const char *bend = "\xe2\x94\x9c"; - const char *horz = "\xe2\x94\x80"; -#else - const char *bend = "|"; - const char *horz = "`-"; -#endif - - if (data == NULL || *data == '\0') - return NULL; - - len = snprintf (NULL, 0, " %s%s %s", bend, horz, data); - buf = xmalloc (len + 3); - sprintf (buf, " %s%s %s", bend, horz, data); - - return buf; -} - -/* get a string of bars given current hits, maximum hit & xpos */ -static char * -get_bars (int n, int max, int x) -{ - int w, h, len; - - getmaxyx (stdscr, h, w); - (void) h; /* avoid lint warning */ - - if ((len = (n * (w - x) / max)) < 1) - len = 1; - return char_repeat (len, '|'); -} - -/*get largest data's length */ -static int -get_max_data_len (GDashData * data, int size) -{ - int i, max = 0, len; - for (i = 0; i < size; i++) { - if (data[i].data == NULL) - continue; - len = strlen (data[i].data); - if (len > max) - max = len; - } - return max; -} - -/*get largest hit's length */ -static int -get_max_hit_len (GDashData * data, int size) -{ - int i, max = 0; - for (i = 0; i < size; i++) { - int len = intlen (data[i].hits); - if (len > max) - max = len; - } - return max; -} - -/* get largest hit */ -static int -get_max_hit (GDashData * data, int size) -{ - int i, max = 0; - for (i = 0; i < size; i++) { - int cur = 0; - if ((cur = data[i].hits) > max) - max = cur; - } - return max; -} - -/* set item's percent in GDashData */ -static float -set_percent_data (GDashData * data, int n, int process) -{ - float max = 0.0; - int i; - for (i = 0; i < n; i++) { - data[i].percent = get_percentage (process, data[i].hits); - if (data[i].percent > max) - max = data[i].percent; - } - return max; -} - -/* render module's total */ -static void -render_total_label (WINDOW * win, GDashModule * module_data, int y) -{ - char *s; - int win_h, win_w, total, ht_size; - - total = module_data->holder_size; - ht_size = module_data->ht_size; - - s = xmalloc (snprintf (NULL, 0, "Total: %d/%d", total, ht_size) + 1); - getmaxyx (win, win_h, win_w); - (void) win_h; - - sprintf (s, "Total: %d/%d", total, ht_size); - draw_header (win, s, "%s", y, win_w - strlen (s) - 2, win_w, HIGHLIGHT); - free (s); -} - -/* render dashboard bars (graph) */ -static void -render_bars (WINDOW * win, GDashModule * module_data, int y, int *x, int idx, - int w, int selected) -{ - const GDashStyle *style = module_style; - GModule module = module_data->module; - char *bar; - - if (style[module].color_bars == -1) - return; - - bar = get_bars (module_data->data[idx].hits, module_data->max_hits, *x); - if (selected) - draw_header (win, bar, "%s", y, *x, w, HIGHLIGHT); - else - mvwprintw (win, y, *x, "%s", bar); - free (bar); -} - -/* render dashboard data */ -static void -render_data (WINDOW * win, GDashModule * module_data, int y, int *x, int idx, - int w, int selected) -{ - char buf[DATE_LEN]; - char *data, *padded_data; - - const GDashStyle *style = module_style; - GModule module = module_data->module; - - data = substring (module_data->data[idx].data, 0, w - *x); - if (module == VISITORS) - convert_date (buf, data, "%Y%m%d", "%d/%b/%Y", DATE_LEN); - - if (selected) { - if (module_data->module == HOSTS && module_data->data[idx].is_subitem) { - padded_data = left_pad_str (data, *x); - draw_header (win, padded_data, "%s", y, 0, w, HIGHLIGHT); - free (padded_data); - } else { - draw_header (win, module == VISITORS ? buf : data, "%s", y, *x, w, - HIGHLIGHT); - } - } else { - wattron (win, COLOR_PAIR (style[module].color_hits)); - mvwprintw (win, y, *x, "%s", module == VISITORS ? buf : data); - wattroff (win, COLOR_PAIR (style[module].color_hits)); - } - *x += module == VISITORS ? DATE_LEN - 1 : module_data->data_len; - *x += DASH_SPACE; - free (data); -} - -/* render dashboard request method */ -static void -render_method (WINDOW * win, GDashModule * module_data, int y, int *x, - int idx, int w, int selected) -{ - const char *method = module_data->data[idx].method; - const GDashStyle *style = module_style; - GModule module = module_data->module; - - if (style[module].color_method == -1) - return; - - if (method == NULL || *method == '\0') - return; - - if (selected) { - draw_header (win, method, "%s", y, *x, w, HIGHLIGHT); - } else { - wattron (win, A_BOLD | COLOR_PAIR (style[module].color_method)); - mvwprintw (win, y, *x, "%s", method); - wattroff (win, A_BOLD | COLOR_PAIR (style[module].color_method)); - } - *x += strlen (module_data->data[idx].method) + DASH_SPACE; -} - -/* render dashboard request protocol */ -static void -render_protocol (WINDOW * win, GDashModule * module_data, int y, int *x, - int idx, int w, int selected) -{ - const char *protocol = module_data->data[idx].protocol; - const GDashStyle *style = module_style; - GModule module = module_data->module; - - if (style[module].color_protocol == -1) - return; - - if (protocol == NULL || *protocol == '\0') - return; - - if (selected) { - draw_header (win, protocol, "%s", y, *x, w, HIGHLIGHT); - } else { - wattron (win, COLOR_PAIR (style[module].color_protocol)); - mvwprintw (win, y, *x, "%s", protocol); - wattroff (win, COLOR_PAIR (style[module].color_protocol)); - } - *x += REQ_PROTO_LEN - 1 + DASH_SPACE; -} - -/* render dashboard usecs */ -static void -render_usecs (WINDOW * win, GDashModule * module_data, int y, int *x, int idx, - int w, int selected) -{ - const GDashStyle *style = module_style; - GModule module = module_data->module; - - if (module_data->module == HOSTS && module_data->data[idx].is_subitem) - goto inc; - if (style[module].color_usecs == -1) - return; - - if (selected) { - draw_header (win, module_data->data[idx].serve_time, "%9s", y, *x, w, - HIGHLIGHT); - } else { - wattron (win, A_BOLD | COLOR_PAIR (style[module].color_usecs)); - mvwprintw (win, y, *x, "%9s", module_data->data[idx].serve_time); - wattroff (win, A_BOLD | COLOR_PAIR (style[module].color_usecs)); - } -inc: - *x += DASH_SRV_TM_LEN + DASH_SPACE; -} - -/* render dashboard bandwidth */ -static void -render_bandwidth (WINDOW * win, GDashModule * module_data, int y, int *x, - int idx, int w, int selected) -{ - const GDashStyle *style = module_style; - GModule module = module_data->module; - - if (module_data->module == HOSTS && module_data->data[idx].is_subitem) - goto inc; - if (style[module].color_bw == -1) - return; - - if (selected) { - draw_header (win, module_data->data[idx].bandwidth, "%11s", y, *x, w, - HIGHLIGHT); - } else { - wattron (win, A_BOLD | COLOR_PAIR (style[module].color_bw)); - mvwprintw (win, y, *x, "%11s", module_data->data[idx].bandwidth); - wattroff (win, A_BOLD | COLOR_PAIR (style[module].color_bw)); - } -inc: - *x += DASH_BW_LEN + DASH_SPACE; -} - -/* render dashboard percent */ -static void -render_percent (WINDOW * win, GDashModule * module_data, int y, int *x, - int idx, int w, int selected) -{ - int max_hit = 0; - const GDashStyle *style = module_style; - GModule module = module_data->module; - - if (module_data->module == HOSTS && module_data->data[idx].is_subitem) - goto inc; - if (style[module].color_percent == -1) - return; - - if (module_data->max_hits == module_data->data[idx].hits) - max_hit = 1; - - if (selected) { - char *percent = float_to_str (module_data->data[idx].percent); - draw_header (win, percent, "%s%%", y, *x, w, HIGHLIGHT); - free (percent); - } else { - wattron (win, A_BOLD | COLOR_PAIR (style[module].color_percent)); - if (max_hit) - wattron (win, A_BOLD | COLOR_PAIR (COL_YELLOW)); - if (style[module].color_percent == COL_BLACK) - wattron (win, A_BOLD | COLOR_PAIR (style[module].color_percent)); - - mvwprintw (win, y, *x, "%.2f%%", module_data->data[idx].percent); - - if (style[module].color_percent == COL_BLACK) - wattroff (win, A_BOLD | COLOR_PAIR (style[module].color_percent)); - if (max_hit) - wattroff (win, A_BOLD | COLOR_PAIR (COL_YELLOW)); - wattroff (win, A_BOLD | COLOR_PAIR (style[module].color_percent)); - } -inc: - *x += module_data->perc_len + DASH_SPACE; -} - -/* render dashboard hits */ -static void -render_hits (WINDOW * win, GDashModule * module_data, int y, int *x, int idx, - int w, int selected) -{ - const GDashStyle *style = module_style; - char *hits; - GModule module = module_data->module; - - if (module_data->module == HOSTS && module_data->data[idx].is_subitem) - goto inc; - - if (selected) { - hits = int_to_str (module_data->data[idx].hits); - draw_header (win, hits, " %s", y, 0, w, HIGHLIGHT); - free (hits); - } else { - wattron (win, COLOR_PAIR (style[module].color_hits)); - mvwprintw (win, y, *x, "%d", module_data->data[idx].hits); - wattroff (win, COLOR_PAIR (style[module].color_hits)); - } -inc: - *x += module_data->hits_len + DASH_SPACE; -} - -/* render dashboard content */ -static void -render_content (WINDOW * win, GDashModule * module_data, int *y, int *offset, - int *total, GScrolling * scrolling) -{ - char *hd; - GModule module = module_data->module; - int expanded = 0, sel = 0, host_bars = 0, size; - int i, k, j, x = 0, w, h; - - if (!conf.skip_term_resolver) - host_bars = 1; - -#ifdef HAVE_LIBGEOIP - host_bars = 1; -#endif - - getmaxyx (win, h, w); - - if (scrolling->expanded && module == scrolling->current) - expanded = 1; - - size = module_data->dash_size; - for (i = *offset, j = 0; i < size; i++) { - /* header */ - if ((i % size) == DASH_HEAD_POS) { - k = module + 1; - hd = xmalloc (snprintf (NULL, 0, "%d - %s", k, module_data->head) + 1); - sprintf (hd, "%d - %s", k, module_data->head); - - draw_header (win, hd, " %s", (*y), 0, w, 1); - free (hd); - - render_total_label (win, module_data, (*y)); - module_data->pos_y = (*y); - (*y)++; - } - /* description */ - else if ((i % size) == DASH_DESC_POS) - draw_header (win, module_data->desc, " %s", (*y)++, 0, w, 2); - /* blank lines */ - else if ((i % size) == DASH_EMPTY_POS || (i % size) == size - 1) - (*y)++; - /* actual data */ - else if ((i % size) >= DASH_DATA_POS || (i % size) <= size - 2) { - x = DASH_INIT_X; - /* account for 2 lines at the header and 2 blank lines */ - j = ((i % size) - DASH_DATA_POS) + scrolling->module[module].offset; - - if (j < module_data->idx_data) { - sel = expanded && j == scrolling->module[module].scroll ? 1 : 0; - render_hits (win, module_data, *y, &x, j, w, sel); - render_percent (win, module_data, *y, &x, j, w, sel); - render_bandwidth (win, module_data, *y, &x, j, w, sel); - - /* render usecs if available */ - if (conf.serve_usecs) - render_usecs (win, module_data, *y, &x, j, w, sel); - /* render request method if available */ - if (conf.append_protocol) - render_protocol (win, module_data, *y, &x, j, w, sel); - /* render request method if available */ - if (conf.append_method) - render_method (win, module_data, *y, &x, j, w, sel); - render_data (win, module_data, *y, &x, j, w, sel); - - /* skip graph bars if module is expanded and we have sub nodes */ - if (module == HOSTS && expanded && host_bars); - else - render_bars (win, module_data, *y, &x, j, w, sel); - } - (*y)++; - } - /* everything else should be empty */ - else - (*y)++; - (*total)++; - if (*y >= h) - break; - } -} - -/* entry point to render dashboard */ -void -display_content (WINDOW * win, GLog * logger, GDash * dash, - GScrolling * scrolling) -{ - float max_percent = 0.0; - int i, j, n = 0, process = 0; - - int y = 0, offset = 0, total = 0; - int dash_scroll = scrolling->dash; - - werase (win); - - for (i = 0; i < TOTAL_MODULES; i++) { - n = dash->module[i].idx_data; - offset = 0; - for (j = 0; j < dash->module[i].dash_size; j++) { - if (dash_scroll > total) { - offset++; - total++; - } - } - - /* Every module other than VISITORS, GEO_LOCATION, BROWSERS and OS - * will use total req as base - */ - switch (i) { -#ifdef HAVE_LIBGEOIP - case GEO_LOCATION: -#endif - case VISITORS: - case BROWSERS: - case OS: - process = get_ht_size (ht_unique_visitors); - break; - default: - process = logger->process; - } - max_percent = set_percent_data (dash->module[i].data, n, process); - dash->module[i].module = i; - dash->module[i].max_hits = get_max_hit (dash->module[i].data, n); - dash->module[i].hits_len = get_max_hit_len (dash->module[i].data, n); - dash->module[i].data_len = get_max_data_len (dash->module[i].data, n); - dash->module[i].perc_len = intlen ((int) max_percent) + 4; - - render_content (win, &dash->module[i], &y, &offset, &total, scrolling); - } - wrefresh (win); -} - -/* reset scroll and offset for each module */ -void -reset_scroll_offsets (GScrolling * scrolling) -{ - int i; - for (i = 0; i < TOTAL_MODULES; i++) { - scrolling->module[i].scroll = 0; - scrolling->module[i].offset = 0; - } -} - -/* compile the regular expression and see if it's valid */ -static int -regexp_init (regex_t * regex, const char *pattern) -{ - int y, x, rc; - char buf[REGEX_ERROR]; - - getmaxyx (stdscr, y, x); - rc = regcomp (regex, pattern, REG_EXTENDED | (find_t.icase ? REG_ICASE : 0)); - /* something went wrong */ - if (rc != 0) { - regerror (rc, regex, buf, sizeof (buf)); - draw_header (stdscr, buf, "%s", y - 1, 0, x, WHITE_RED); - refresh (); - return 1; - } - return 0; -} - -/* set search scrolling */ -static void -perform_find_dash_scroll (GScrolling * scrolling, GModule module) -{ - int *scrll, *offset; - int exp_size = DASH_EXPANDED - DASH_NON_DATA; - - /* reset scrolling offsets if we are changing module */ - if (scrolling->current != module) - reset_scroll_offsets (scrolling); - - scrll = &scrolling->module[module].scroll; - offset = &scrolling->module[module].offset; - - (*scrll) = find_t.next_idx; - if (*scrll >= exp_size && *scrll >= *offset + exp_size) - (*offset) = (*scrll) < exp_size - 1 ? 0 : (*scrll) - exp_size + 1; - - scrolling->current = module; - scrolling->dash = module * DASH_COLLAPSED; - scrolling->expanded = 1; - find_t.module = module; -} - -/* find item within the given sub_list */ -static int -find_next_sub_item (GSubList * sub_list, regex_t * regex) -{ - GSubItem *iter; - int i = 0, rc; - - if (sub_list == NULL) - goto out; - - for (iter = sub_list->head; iter; iter = iter->next) { - if (i >= find_t.next_sub_idx) { - rc = regexec (regex, iter->data, 0, NULL, 0); - if (rc == 0) { - find_t.next_idx++; - find_t.next_sub_idx = (1 + i); - return 0; - } - find_t.next_idx++; - } - i++; - } -out: - find_t.next_parent_idx++; - find_t.next_sub_idx = 0; - find_t.look_in_sub = 0; - - return 1; -} - -/* perform a forward search across all modules */ -int -perform_next_find (GHolder * h, GScrolling * scrolling) -{ - int y, x, j, n, rc; - char buf[REGEX_ERROR]; - char *data; - regex_t regex; - GModule module; - GSubList *sub_list; - - getmaxyx (stdscr, y, x); - - if (find_t.pattern == NULL || *find_t.pattern == '\0') - return 1; - - /* compile and initialize regexp */ - if (regexp_init (®ex, find_t.pattern)) - return 1; - - /* use last find_t.module and start search */ - for (module = find_t.module; module < TOTAL_MODULES; module++) { - n = h[module].idx; - for (j = find_t.next_parent_idx; j < n; j++, find_t.next_idx++) { - data = h[module].items[j].data; - - rc = regexec (®ex, data, 0, NULL, 0); - if (rc != 0 && rc != REG_NOMATCH) { - regerror (rc, ®ex, buf, sizeof (buf)); - draw_header (stdscr, buf, "%s", y - 1, 0, x, WHITE_RED); - refresh (); - regfree (®ex); - return 1; - } else if (rc == 0 && !find_t.look_in_sub) { - find_t.look_in_sub = 1; - goto found; - } else { - sub_list = h[module].items[j].sub_list; - if (find_next_sub_item (sub_list, ®ex) == 0) - goto found; - } - } - /* reset find */ - find_t.next_idx = 0; - find_t.next_parent_idx = 0; - find_t.next_sub_idx = 0; - if (find_t.module != module) { - reset_scroll_offsets (scrolling); - scrolling->expanded = 0; - } - if (module == TOTAL_MODULES - 1) { - find_t.module = 0; - goto out; - } - } - -found: - perform_find_dash_scroll (scrolling, module); -out: - regfree (®ex); - return 0; -} - -/* render find dialog */ -int -render_find_dialog (WINDOW * main_win, GScrolling * scrolling) -{ - int y, x, valid = 1; - int w = FIND_DLG_WIDTH; - int h = FIND_DLG_HEIGHT; - char *query = NULL; - WINDOW *win; - - getmaxyx (stdscr, y, x); - - win = newwin (h, w, (y - h) / 2, (x - w) / 2); - keypad (win, TRUE); - wborder (win, '|', '|', '-', '-', '+', '+', '+', '+'); - draw_header (win, FIND_HEAD, " %s", 1, 1, w - 2, 1); - draw_header (win, FIND_DESC, " %s", 2, 1, w - 2, 2); - - find_t.icase = 0; - query = input_string (win, 4, 2, w - 3, "", 1, &find_t.icase); - if (query != NULL && *query != '\0') { - reset_scroll_offsets (scrolling); - reset_find (); - find_t.pattern = xstrdup (query); - valid = 0; - } - if (query != NULL) - free (query); - touchwin (main_win); - close_win (win); - wrefresh (main_win); - - return valid; -} - -/* iterate over holder and get the key index. - * return -1 if not found */ -static int -get_item_idx_in_holder (GHolder * holder, const char *k) -{ - int i; - if (holder == NULL) - return -1; - if (holder->idx == 0) - return -1; - - for (i = 0; i < holder->idx; i++) { - if (strcmp (k, holder->items[i].data) == 0) - return i; - } - - return -1; -} - -/* add an item from a sub_list to the dashboard */ -static void -add_sub_item_to_dash (GDash ** dash, GHolderItem item, GModule module, int *i) -{ - GSubList *sub_list = item.sub_list; - GSubItem *iter; - - char *entry; - int *idx; - idx = &(*dash)->module[module].idx_data; - - for (iter = sub_list->head; iter; iter = iter->next) { - entry = render_child_node (iter->data); - if (entry) { - (*dash)->module[module].data[(*idx)].bandwidth = filesize_str (iter->bw); - (*dash)->module[module].data[(*idx)].bw = iter->bw; - (*dash)->module[module].data[(*idx)].data = xstrdup (entry); - (*dash)->module[module].data[(*idx)].hits = iter->hits; - (*dash)->module[module].data[(*idx)++].is_subitem = 1; - free (entry); - } - (*i)++; - } -} - -/* add a host item to holder */ -static void -add_host_node (GHolder * h, char *key, int hits) -{ - GSubList *sub_list = new_gsublist (); - char *ip = xstrdup (key), *hostname = NULL; - int found = 0; - uint64_t bw = 0, usecs = 0; - void *value_ptr; - -#ifdef HAVE_LIBGEOIP - const char *addr = key; - char country[COUNTRY_LEN] = ""; - char city[CITY_LEN] = ""; -#endif - - /* serve time in usecs */ - if (conf.serve_usecs) - usecs = get_serve_time (key, h->module) / hits; - bw = get_bandwidth (key, h->module); - - h->items[h->idx].bw += bw; - h->items[h->idx].hits += hits; - h->items[h->idx].data = key; - if (conf.serve_usecs) - h->items[h->idx].usecs = usecs; - h->items[h->idx].sub_list = sub_list; - -#ifdef HAVE_LIBGEOIP - geoip_get_country (addr, country); - add_sub_item_back (sub_list, h->module, xstrdup (country), hits, bw); - h->items[h->idx].sub_list = sub_list; - h->sub_items_size++; - - /* add city */ - if (conf.geoip_city_data) { - geoip_get_city (addr, city); - add_sub_item_back (sub_list, h->module, xstrdup (city), hits, bw); - h->items[h->idx].sub_list = sub_list; - h->sub_items_size++; - } -#endif - - pthread_mutex_lock (&gdns_thread.mutex); -#ifdef HAVE_LIBTOKYOCABINET - value_ptr = tc_db_get_str (ht_hostnames, ip); - if (value_ptr) { - found = 1; - hostname = value_ptr; - } -#else - found = g_hash_table_lookup_extended (ht_hostnames, ip, NULL, &value_ptr); - if (found && value_ptr) - hostname = xstrdup (value_ptr); -#endif - pthread_mutex_unlock (&gdns_thread.mutex); - - if (!found) { - dns_resolver (ip); - } else if (hostname) { - add_sub_item_back (sub_list, h->module, hostname, hits, bw); - h->items[h->idx].sub_list = sub_list; - h->sub_items_size++; - } - free (ip); - - h->idx++; -} - -static void -add_os_node (GHolder * h, char *key, GOpeSys * opesys) -{ - GSubList *sub_list; - int type_idx = -1, bw = 0; - - type_idx = get_item_idx_in_holder (h, opesys->os_type); - if (type_idx == -1) { - /*h->items[h->idx].bw += bw; */ - h->items[h->idx].hits += opesys->hits; - h->items[h->idx].data = xstrdup (opesys->os_type); - - /* data (child) */ - sub_list = new_gsublist (); - add_sub_item_back (sub_list, h->module, key, opesys->hits, bw); - h->items[h->idx++].sub_list = sub_list; - h->sub_items_size++; - } else { - sub_list = h->items[type_idx].sub_list; - add_sub_item_back (sub_list, h->module, key, opesys->hits, bw); - - h->items[type_idx].sub_list = sub_list; - /*h->items[type_idx].bw += bw; */ - h->items[type_idx].hits += opesys->hits; - h->sub_items_size++; - } -} - -static void -add_browser_node (GHolder * h, char *key, GBrowser * browser) -{ - GSubList *sub_list; - int type_idx = -1, bw = 0; - - type_idx = get_item_idx_in_holder (h, browser->browser_type); - if (type_idx == -1) { - h->items[h->idx].hits += browser->hits; - h->items[h->idx].data = xstrdup (browser->browser_type); - - /* data (child) */ - sub_list = new_gsublist (); - add_sub_item_back (sub_list, h->module, key, browser->hits, bw); - h->items[h->idx++].sub_list = sub_list; - h->sub_items_size++; - } else { - sub_list = h->items[type_idx].sub_list; - add_sub_item_back (sub_list, h->module, key, browser->hits, bw); - - h->items[type_idx].sub_list = sub_list; - h->items[type_idx].hits += browser->hits; - h->sub_items_size++; - } -} - -/* add request items (e.g., method, protocol, request) to holder */ -static void -add_request_node (GHolder * h, char *key, int hits) -{ - uint64_t usecs = 0, bw = 0; - char *request = NULL, *method = NULL, *protocol = NULL; - - if (conf.serve_usecs) - usecs = get_serve_time (key, h->module) / hits; - bw = get_bandwidth (key, h->module); - request = get_request_meta (key, REQUEST); - method = get_request_meta (key, REQUEST_METHOD); - protocol = get_request_meta (key, REQUEST_PROTOCOL); - - if (request == NULL) - return; - - h->items[h->idx].bw = bw; - h->items[h->idx].data = xstrdup (request); - h->items[h->idx].hits = hits; - - if (conf.append_method && method) - h->items[h->idx].method = xstrdup (method); - if (conf.append_protocol && protocol) - h->items[h->idx].protocol = xstrdup (protocol); - if (conf.serve_usecs) - h->items[h->idx].usecs = usecs; - h->idx++; - - if (method) - free (method); - if (protocol) - free (protocol); - free (request); - free (key); -} - -/* add a geolocation item to holder */ -#ifdef HAVE_LIBGEOIP -static void -add_geolocation_node (GHolder * h, char *key, GLocation * loc) -{ - GSubList *sub_list; - int type_idx = -1; - uint64_t bw = 0; - - type_idx = get_item_idx_in_holder (h, loc->continent); - if (type_idx == -1) { - h->items[h->idx].hits += loc->hits; - h->items[h->idx].data = xstrdup (loc->continent); - - /* data (child) */ - sub_list = new_gsublist (); - add_sub_item_back (sub_list, h->module, key, loc->hits, bw); - h->items[h->idx++].sub_list = sub_list; - h->sub_items_size++; - } else { - sub_list = h->items[type_idx].sub_list; - add_sub_item_back (sub_list, h->module, key, loc->hits, bw); - - h->items[type_idx].sub_list = sub_list; - h->items[type_idx].bw += bw; - h->items[type_idx].hits += loc->hits; - h->sub_items_size++; - } -} -#endif - -/* add a status code item to holder */ -static void -add_status_code_node (GHolder * h, char *key, int hits) -{ - GSubList *sub_list; - const char *type = NULL, *status = NULL; - int type_idx = -1; - uint64_t bw = 0; - - type = verify_status_code_type (key); - status = verify_status_code (key); - - type_idx = get_item_idx_in_holder (h, type); - if (type_idx == -1) { - h->items[h->idx].hits += hits; - h->items[h->idx].data = xstrdup (type); - - /* data (child) */ - sub_list = new_gsublist (); - add_sub_item_back (sub_list, h->module, xstrdup (status), hits, bw); - h->items[h->idx++].sub_list = sub_list; - h->sub_items_size++; - } else { - sub_list = h->items[type_idx].sub_list; - add_sub_item_back (sub_list, h->module, xstrdup (status), hits, bw); - - h->items[type_idx].sub_list = sub_list; - h->items[type_idx].hits += hits; - h->sub_items_size++; - } - free (key); -} - -/* add a first level item to dashboard */ -static void -add_item_to_dash (GDash ** dash, GHolderItem item, GModule module) -{ - int *idx = &(*dash)->module[module].idx_data; - - (*dash)->module[module].data[(*idx)].bandwidth = filesize_str (item.bw); - (*dash)->module[module].data[(*idx)].bw = item.bw; - (*dash)->module[module].data[(*idx)].data = xstrdup (item.data); - (*dash)->module[module].data[(*idx)].hits = item.hits; - if (conf.append_method && item.method) - (*dash)->module[module].data[(*idx)].method = item.method; - if (conf.append_protocol && item.protocol) - (*dash)->module[module].data[(*idx)].protocol = item.protocol; - if (conf.serve_usecs) { - (*dash)->module[module].data[(*idx)].usecs = item.usecs; - (*dash)->module[module].data[(*idx)].serve_time = usecs_to_str (item.usecs); - } - (*idx)++; -} - -/* load holder's data into dashboard */ -void -load_data_to_dash (GHolder * h, GDash * dash, GModule module, - GScrolling * scrolling) -{ - int alloc_size = 0; - int i, j; - - alloc_size = dash->module[module].alloc_data; - if (scrolling->expanded && module == scrolling->current) { - if (module == OS || module == BROWSERS || module == HOSTS || - module == STATUS_CODES -#ifdef HAVE_LIBGEOIP - || module == GEO_LOCATION -#endif - ) - alloc_size += h->sub_items_size; - } - dash->module[module].alloc_data = alloc_size; - dash->module[module].data = new_gdata (alloc_size); - dash->module[module].holder_size = h->holder_size; - - for (i = 0, j = 0; i < alloc_size; i++) { - if (j < dash->module[module].ht_size && h->items[j].data != NULL) { - add_item_to_dash (&dash, h->items[j], module); - if (scrolling->expanded && module == scrolling->current) { - if (module == OS || module == BROWSERS || module == HOSTS || - module == STATUS_CODES -#ifdef HAVE_LIBGEOIP - || module == GEO_LOCATION -#endif - ) - add_sub_item_to_dash (&dash, h->items[j], module, &i); - } - j++; - } - } -} - -/* apply user defined sort */ -static void -sort_holder_items (GHolderItem * items, int size, GSort sort) -{ - switch (sort.field) { - case SORT_BY_HITS: - if (sort.sort == SORT_DESC) - qsort (items, size, sizeof (GHolderItem), cmp_num_desc); - else - qsort (items, size, sizeof (GHolderItem), cmp_num_asc); - break; - case SORT_BY_DATA: - if (sort.sort == SORT_DESC) - qsort (items, size, sizeof (GHolderItem), cmp_data_desc); - else - qsort (items, size, sizeof (GHolderItem), cmp_data_asc); - break; - case SORT_BY_BW: - if (sort.sort == SORT_DESC) - qsort (items, size, sizeof (GHolderItem), cmp_bw_desc); - else - qsort (items, size, sizeof (GHolderItem), cmp_bw_asc); - break; - case SORT_BY_USEC: - if (sort.sort == SORT_DESC) - qsort (items, size, sizeof (GHolderItem), cmp_usec_desc); - else - qsort (items, size, sizeof (GHolderItem), cmp_usec_asc); - break; - case SORT_BY_PROT: - if (sort.sort == SORT_DESC) - qsort (items, size, sizeof (GHolderItem), cmp_proto_desc); - else - qsort (items, size, sizeof (GHolderItem), cmp_proto_asc); - break; - case SORT_BY_MTHD: - if (sort.sort == SORT_DESC) - qsort (items, size, sizeof (GHolderItem), cmp_mthd_desc); - else - qsort (items, size, sizeof (GHolderItem), cmp_mthd_asc); - break; - } -} - -/* Copy linked-list items to an array, sort, and move them back - * to the list should be faster than sorting the list - */ -static void -sort_sub_list (GHolder * h, GSort sort) -{ - int i, j, k; - GHolderItem *arr_items; - - for (i = 0; i < h->idx; i++) { - GSubList *sub_list = h->items[i].sub_list; - GSubItem *iter; - arr_items = new_gholder_item (sub_list->size); - - /* copy items from the linked-list into an rray */ - for (j = 0, iter = sub_list->head; iter; iter = iter->next) { - arr_items[j].data = xstrdup ((char *) iter->data); - arr_items[j++].hits = iter->hits; - } - sort_holder_items (arr_items, j, sort); - delete_sub_list (sub_list); - - sub_list = new_gsublist (); - for (k = 0; k < j; k++) { - if (k > 0) - sub_list = h->items[i].sub_list; - add_sub_item_back (sub_list, h->module, arr_items[k].data, - arr_items[k].hits, 0); - h->items[i].sub_list = sub_list; - } - free (arr_items); - } -} - -uint32_t -get_ht_size_by_module (GModule module) -{ -#ifdef TCB_BTREE - TCBDB *ht = NULL; -#elif TCB_MEMHASH - TCMDB *ht = NULL; -#else - GHashTable *ht; -#endif - - switch (module) { - case VISITORS: - ht = ht_unique_vis; - break; - case REQUESTS: - ht = ht_requests; - break; - case REQUESTS_STATIC: - ht = ht_requests_static; - break; - case NOT_FOUND: - ht = ht_not_found_requests; - break; - case HOSTS: - ht = ht_hosts; - break; - case OS: - ht = ht_os; - break; - case BROWSERS: - ht = ht_browsers; - break; - case REFERRERS: - ht = ht_referrers; - break; - case REFERRING_SITES: - ht = ht_referring_sites; - break; - case KEYPHRASES: - ht = ht_keyphrases; - break; -#ifdef HAVE_LIBGEOIP - case GEO_LOCATION: - ht = ht_countries; - break; -#endif - case STATUS_CODES: - ht = ht_status_code; - break; - default: - return 0; - } - - return get_ht_size (ht); -} - -/* Load raw data into our holder structure. - * - * Note: the key from raw data needs to be allocated as well as - * the pointer value since they are free'd after the data gets into - * the holder structure. - */ -void -load_data_to_holder (GRawData * raw_data, GHolder * h, GModule module, - GSort sort) -{ - char *key; - int hits; - int i, size = 0; - uint64_t bw = 0; - uint64_t usecs = 0; - - size = raw_data->size; - h->holder_size = size > MAX_CHOICES ? MAX_CHOICES : size; - h->idx = 0; - h->module = module; - h->sub_items_size = 0; - h->items = new_gholder_item (h->holder_size); - - for (i = 0; i < h->holder_size; i++) { - key = xstrdup (raw_data->items[i].key); /* key */ - - switch (module) { - case REQUESTS: - case REQUESTS_STATIC: - case NOT_FOUND: - hits = (*(int *) raw_data->items[i].value); - add_request_node (h, key, hits); - break; - case OS: - add_os_node (h, key, raw_data->items[i].value); - break; - case BROWSERS: - add_browser_node (h, key, raw_data->items[i].value); - break; - case HOSTS: - hits = (*(int *) raw_data->items[i].value); - add_host_node (h, key, hits); - break; - case STATUS_CODES: - hits = (*(int *) raw_data->items[i].value); - add_status_code_node (h, key, hits); - break; -#ifdef HAVE_LIBGEOIP - case GEO_LOCATION: - add_geolocation_node (h, key, raw_data->items[i].value); - break; -#endif - default: - bw = get_bandwidth (key, module); - hits = (*(int *) raw_data->items[i].value); - /* serve time in usecs */ - if (conf.serve_usecs) - usecs = get_serve_time (key, module) / hits; - h->items[h->idx].bw = bw; - h->items[h->idx].data = key; - h->items[h->idx].hits = hits; - if (conf.serve_usecs) - h->items[h->idx].usecs = usecs; - h->idx++; - } - } - sort_holder_items (h->items, h->idx, sort); - /* HOSTS module does not have "real" sub items, thus we don't include it */ - if (module == OS || module == BROWSERS || module == STATUS_CODES -#ifdef HAVE_LIBGEOIP - || module == GEO_LOCATION -#endif - ) - sort_sub_list (h, sort); - - free_raw_data (raw_data); -} diff --git a/gdashboard.h b/gdashboard.h deleted file mode 100644 index 5a0c77ab48..0000000000 --- a/gdashboard.h +++ /dev/null @@ -1,118 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#if HAVE_CONFIG_H -#include -#endif - -#ifndef GDASHBOARD_H_INCLUDED -#define GDASHBOARD_H_INCLUDED - -#include - -#include "commons.h" -#include "ui.h" -#include "parser.h" - -/* *INDENT-OFF* */ -#define DASH_HEAD_POS 0 /* header line pos */ -#define DASH_DESC_POS 1 /* description line pos */ -#define DASH_EMPTY_POS 2 /* empty line pos */ -#define DASH_DATA_POS 3 /* empty line pos */ - -#define DASH_COLLAPSED 11 /* total lines per module */ -#define DASH_EXPANDED 32 /* total lines when expanded */ -#define DASH_NON_DATA 4 /* items without stats */ - -#define DASH_INIT_X 2 /* x-axis offset */ -#define DASH_BW_LEN 11 /* max bandwidth length */ -#define DASH_SRV_TM_LEN 9 /* max served time length */ -#define DASH_SPACE 1 /* space between data */ - -typedef struct GDashStyle_ -{ - const int color_hits; - const int color_data; - const int color_bw; - const int color_percent; - const int color_bars; - const int color_usecs; - const int color_method; - const int color_protocol; -} GDashStyle; - -typedef struct GDashData_ -{ - char *bandwidth; - char *data; - char *method; - char *protocol; - char *serve_time; - float percent; - int hits; - short is_subitem; - unsigned long long bw; - unsigned long long usecs; -} GDashData; - -typedef struct GDashModule_ -{ - GDashData *data; - GModule module; - const char *desc; - const char *head; - int alloc_data; /* alloc data items */ - int dash_size; /* dashboard size */ - int data_len; - int hits_len; - int holder_size; /* hash table size */ - int ht_size; /* hash table size */ - int idx_data; /* idx data */ - int max_hits; - int perc_len; - unsigned short pos_y; -} GDashModule; - -typedef struct GDash_ -{ - int total_alloc; - GDashModule module[TOTAL_MODULES]; -} GDash; - -GDashData * new_gdata (uint32_t size); -GDash *new_gdash (void); -GHolder *new_gholder (uint32_t size); -int perform_next_find (GHolder * h, GScrolling * scrolling); -int render_find_dialog (WINDOW * main_win, GScrolling * scrolling); -int set_module_from_mouse_event (GScrolling *scrolling, GDash *dash, int y); -uint32_t get_ht_size_by_module (GModule module); -void *add_hostname_node (void *ptr_holder); -void display_content (WINDOW * win, GLog * logger, GDash * dash, GScrolling * scrolling); -void free_dashboard (GDash * dash); -void free_holder_by_module (GHolder ** holder, GModule module); -void free_holder (GHolder ** holder); -void load_data_to_dash (GHolder * h, GDash * dash, GModule module, GScrolling * scrolling); -void load_data_to_holder (GRawData * raw_data, GHolder * h, GModule module, GSort sort); -void load_host_to_holder (GHolder * h, char *ip); -void reset_find (void); -void reset_scroll_offsets (GScrolling * scrolling); -/* *INDENT-ON* */ - -#endif diff --git a/gdns.c b/gdns.c deleted file mode 100644 index cf9f8c48fd..0000000000 --- a/gdns.c +++ /dev/null @@ -1,268 +0,0 @@ -/** - * gdns.c -- hosts resolver - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#define _MULTI_THREADED -#ifdef __FreeBSD__ -#include -#endif - -#if HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "gdns.h" - -#ifdef HAVE_LIBTOKYOCABINET -#include "tcabinet.h" -#else -#include "glibht.h" -#endif - -#include "error.h" -#include "goaccess.h" -#include "util.h" -#include "xmalloc.h" - -GDnsThread gdns_thread; -static GDnsQueue *gdns_queue; - -/* initialize queue */ -void -gqueue_init (GDnsQueue * q, int capacity) -{ - q->head = 0; - q->tail = -1; - q->size = 0; - q->capacity = capacity; -} - -/* get current size of queue */ -int -gqueue_size (GDnsQueue * q) -{ - return q->size; -} - -/* is the queue empty */ -int -gqueue_empty (GDnsQueue * q) -{ - return q->size == 0; -} - -/* is the queue full */ -int -gqueue_full (GDnsQueue * q) -{ - return q->size == q->capacity; -} - -/* destroy queue */ -void -gqueue_destroy (GDnsQueue * q) -{ - free (q); -} - -/* add item to the queue */ -int -gqueue_enqueue (GDnsQueue * q, char *item) -{ - if (gqueue_full (q)) - return -1; - - q->tail = (q->tail + 1) % q->capacity; - strcpy (q->buffer[q->tail], item); - q->size++; - return 0; -} - -int -gqueue_find (GDnsQueue * q, const char *item) -{ - int i; - if (gqueue_empty (q)) - return 0; - - for (i = 0; i < q->size; i++) { - if (strcmp (item, q->buffer[i]) == 0) - return 1; - } - return 0; -} - -/* remove an item from the queue */ -char * -gqueue_dequeue (GDnsQueue * q) -{ - char *item; - if (gqueue_empty (q)) - return NULL; - - item = q->buffer[q->head]; - q->head = (q->head + 1) % q->capacity; - q->size--; - return item; -} - -/* get the corresponding host given an address */ -static char * -reverse_host (const struct sockaddr *a, socklen_t length) -{ - char h[H_SIZE]; - int flags, st; - - flags = NI_NAMEREQD; - st = getnameinfo (a, length, h, H_SIZE, NULL, 0, flags); - if (!st) - return alloc_string (h); - return alloc_string (gai_strerror (st)); -} - -/* determine if IPv4 or IPv6 and resolve */ -char * -reverse_ip (char *str) -{ - union - { - struct sockaddr addr; - struct sockaddr_in6 addr6; - struct sockaddr_in addr4; - } a; - - if (str == NULL || *str == '\0') - return NULL; - - memset (&a, 0, sizeof (a)); - if (1 == inet_pton (AF_INET, str, &a.addr4.sin_addr)) { - a.addr4.sin_family = AF_INET; - return reverse_host (&a.addr, sizeof (a.addr4)); - } else if (1 == inet_pton (AF_INET6, str, &a.addr6.sin6_addr)) { - a.addr6.sin6_family = AF_INET6; - return reverse_host (&a.addr, sizeof (a.addr6)); - } - return NULL; -} - -/* producer */ -void -dns_resolver (char *addr) -{ - pthread_mutex_lock (&gdns_thread.mutex); - if (!gqueue_full (gdns_queue) && !gqueue_find (gdns_queue, addr)) { -#ifndef HAVE_LIBTOKYOCABINET - g_hash_table_replace (ht_hostnames, g_strdup (addr), NULL); -#endif - gqueue_enqueue (gdns_queue, addr); - pthread_cond_broadcast (&gdns_thread.not_empty); - } - pthread_mutex_unlock (&gdns_thread.mutex); -} - -/* consumer */ -static void -dns_worker (void GO_UNUSED (*ptr_data)) -{ - char *ip = NULL, *host = NULL; - - while (1) { - pthread_mutex_lock (&gdns_thread.mutex); - /* wait until an item has been added to the queue */ - while (gqueue_empty (gdns_queue)) - pthread_cond_wait (&gdns_thread.not_empty, &gdns_thread.mutex); - - ip = gqueue_dequeue (gdns_queue); - - pthread_mutex_unlock (&gdns_thread.mutex); - host = reverse_ip (ip); - pthread_mutex_lock (&gdns_thread.mutex); - - if (!active_gdns) { - if (host) - free (host); - break; - } -#ifdef HAVE_LIBTOKYOCABINET - tc_db_put_str (ht_hostnames, ip, host); - free (host); -#else - if (host != NULL && active_gdns) - g_hash_table_replace (ht_hostnames, g_strdup (ip), host); -#endif - - pthread_cond_signal (&gdns_thread.not_full); - pthread_mutex_unlock (&gdns_thread.mutex); - } -} - -/* init queue and dns thread */ -void -gdns_init (void) -{ - gdns_queue = xmalloc (sizeof (GDnsQueue)); - gqueue_init (gdns_queue, QUEUE_SIZE); - - if (pthread_cond_init (&(gdns_thread.not_empty), NULL)) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, "Failed cond"); - - if (pthread_cond_init (&(gdns_thread.not_full), NULL)) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, "Failed cond"); - - if (pthread_mutex_init (&(gdns_thread.mutex), NULL)) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, "Failed mutex"); -} - -/* destroy queue */ -void -gdns_free_queue (void) -{ - gqueue_destroy (gdns_queue); -} - -/* create a dns thread */ -void -gdns_thread_create (void) -{ - int thread; - - active_gdns = 1; - thread = - pthread_create (&(gdns_thread.thread), NULL, (void *) &dns_worker, NULL); - if (thread) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Return code from pthread_create(): %d", thread); - pthread_detach (gdns_thread.thread); -} diff --git a/gdns.h b/gdns.h deleted file mode 100644 index 8f14cd7c6f..0000000000 --- a/gdns.h +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#ifndef GDNS_H_INCLUDED -#define GDNS_H_INCLUDED - -#define H_SIZE 256 -#define QUEUE_SIZE 400 - -typedef struct GDnsThread_ -{ - pthread_cond_t not_empty; - pthread_cond_t not_full; - pthread_mutex_t mutex; - pthread_t thread; -} GDnsThread; - -typedef struct GDnsQueue_ -{ - int head; - int tail; - int size; - int capacity; - char buffer[QUEUE_SIZE][H_SIZE]; -} GDnsQueue; - -extern GDnsThread gdns_thread; - -char *gqueue_dequeue (GDnsQueue * q); -char *reverse_ip (char *str); -int gqueue_empty (GDnsQueue * q); -int gqueue_enqueue (GDnsQueue * q, char *item); -int gqueue_find (GDnsQueue * q, const char *item); -int gqueue_full (GDnsQueue * q); -int gqueue_size (GDnsQueue * q); -void dns_resolver (char *addr); -void gdns_free_queue (void); -void gdns_init (void); -void gdns_queue_free (void); -void gdns_thread_create (void); -void gqueue_destroy (GDnsQueue * q); -void gqueue_init (GDnsQueue * q, int capacity); - -#endif diff --git a/geolocation.c b/geolocation.c deleted file mode 100644 index 1e18eb0eb0..0000000000 --- a/geolocation.c +++ /dev/null @@ -1,170 +0,0 @@ -/** - * geolocation.c -- GeoLocation related functions - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#if HAVE_CONFIG_H -#include -#endif - -#ifdef HAVE_LIBGEOIP -#include -#include -#endif - -#include "geolocation.h" - -#include "error.h" -#include "settings.h" - -GeoIP *geo_location_data; - -/* Get continent name concatenated with code */ -const char * -get_continent_name_and_code (const char *continentid) -{ - if (memcmp (continentid, "NA", 2) == 0) - return "NA North America"; - else if (memcmp (continentid, "OC", 2) == 0) - return "OC Oceania"; - else if (memcmp (continentid, "EU", 2) == 0) - return "EU Europe"; - else if (memcmp (continentid, "SA", 2) == 0) - return "SA South America"; - else if (memcmp (continentid, "AF", 2) == 0) - return "AF Africa"; - else if (memcmp (continentid, "AN", 2) == 0) - return "AN Antarctica"; - else if (memcmp (continentid, "AS", 2) == 0) - return "AS Asia"; - else - return "-- Location Unknown"; -} - -/* Geolocation data */ -GeoIP * -geoip_open_db (const char *db) -{ - GeoIP *geoip; - geoip = GeoIP_open (db, GEOIP_INDEX_CACHE); - if (geoip == NULL) { - LOG_DEBUG (("Unable to open GeoIP City database: %s\n", db)); - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Unable to open GeoIP City database."); - } - LOG_DEBUG (("Opened GeoIP City database: %s\n", db)); - - return geoip; -} - -static void -geoip_set_country (const char *country, const char *code, char *loc) -{ - if (country && code) - sprintf (loc, "%s %s", code, country); - else - sprintf (loc, "%s", "Country Unknown"); -} - -void -geoip_get_country (const char *ip, char *location) -{ - GeoIPRecord *rec = NULL; - const char *country = NULL, *code = NULL, *addr = ip; - int geoid = 0; - - /* Custom GeoIP database */ - if (conf.geoip_city_data != NULL && geo_location_data != NULL) { - rec = GeoIP_record_by_name (geo_location_data, addr); - if (rec) { - code = rec->country_code; - country = rec->country_name; - } - } - /* Legacy GeoIP database */ - else if (geo_location_data != NULL) { - geoid = GeoIP_id_by_name (geo_location_data, addr); - country = GeoIP_country_name_by_name (geo_location_data, addr); - code = GeoIP_code_by_id (geoid); - } - - geoip_set_country (country, code, location); - if (rec != NULL) - GeoIPRecord_delete (rec); -} - -static void -geoip_set_continent (const char *continent, char *loc) -{ - if (continent) - sprintf (loc, "%s", get_continent_name_and_code (continent)); - else - sprintf (loc, "%s", "Continent Unknown"); -} - -void -geoip_get_continent (const char *ip, char *location) -{ - GeoIPRecord *rec = NULL; - const char *continent = NULL, *addr = ip; - int geoid = 0; - - /* Custom GeoIP database */ - if (conf.geoip_city_data != NULL && geo_location_data != NULL) { - rec = GeoIP_record_by_name (geo_location_data, addr); - if (rec) - continent = rec->continent_code; - } - /* Legacy GeoIP database */ - else if (geo_location_data != NULL) { - geoid = GeoIP_id_by_name (geo_location_data, addr); - continent = GeoIP_continent_by_id (geoid); - } - - if (rec != NULL) - GeoIPRecord_delete (rec); - geoip_set_continent (continent, location); -} - -static void -geoip_set_city (const char *city, const char *region, char *loc) -{ - sprintf (loc, "%s, %s", city ? city : "N/A City", - region ? region : "N/A Region"); -} - -/* Custom GeoIP database - i.e., GeoLiteCity.dat */ -void -geoip_get_city (const char *ip, char *location) -{ - GeoIPRecord *rec = NULL; - const char *city = NULL, *region = NULL, *addr = ip; - - if (geo_location_data != NULL) - rec = GeoIP_record_by_name (geo_location_data, addr); - - if (rec != NULL) { - city = rec->city; - region = rec->region; - } - - geoip_set_city (city, region, location); - if (rec != NULL) - GeoIPRecord_delete (rec); -} diff --git a/geolocation.h b/geolocation.h deleted file mode 100644 index 4418558715..0000000000 --- a/geolocation.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#if HAVE_CONFIG_H -#include -#endif - -#ifndef GEOLOCATION_H_INCLUDED -#define GEOLOCATION_H_INCLUDED - -#ifdef HAVE_LIBGEOIP -#include -#endif - -#define CITY_LEN 28 -#define CONTINENT_LEN 48 -#define COUNTRY_LEN 48 + 3 /* Country + two-letter Code */ - -typedef struct GLocation_ -{ - char city[CITY_LEN]; - char continent[CONTINENT_LEN]; - int hits; -} GLocation; - -extern GeoIP *geo_location_data; - -char *geoip_get_country_code (const char *ip); -const char *get_continent_name_and_code (const char *continentid); -GeoIP *geoip_open_db (const char *db); -void geoip_get_city (const char *ip, char *location); -void geoip_get_continent (const char *ip, char *location); -void geoip_get_country (const char *ip, char *country); - -#endif diff --git a/glibht.c b/glibht.c deleted file mode 100644 index 5a1c036341..0000000000 --- a/glibht.c +++ /dev/null @@ -1,531 +0,0 @@ -/** - * glibc.c -- GLib functions - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#if HAVE_CONFIG_H -#include -#endif - -#ifdef HAVE_LIBGLIB_2_0 -#include -#endif - -#include -#include -#include -#include - -#include "glibht.h" - -#ifdef HAVE_LIBGEOIP -#include "geolocation.h" -#endif - -#include "error.h" -#include "parser.h" -#include "settings.h" -#include "util.h" -#include "xmalloc.h" - -GHashTable *ht_browsers = NULL; -GHashTable *ht_countries = NULL; -GHashTable *ht_date_bw = NULL; -GHashTable *ht_file_bw = NULL; -GHashTable *ht_file_serve_usecs = NULL; -GHashTable *ht_host_bw = NULL; -GHashTable *ht_hostnames = NULL; -GHashTable *ht_hosts_agents = NULL; -GHashTable *ht_host_serve_usecs = NULL; -GHashTable *ht_hosts = NULL; -GHashTable *ht_keyphrases = NULL; -GHashTable *ht_monthly = NULL; -GHashTable *ht_not_found_requests = NULL; -GHashTable *ht_os = NULL; -GHashTable *ht_referrers = NULL; -GHashTable *ht_referring_sites = NULL; -GHashTable *ht_request_keys = NULL; -GHashTable *ht_request_methods = NULL; -GHashTable *ht_request_protocols = NULL; -GHashTable *ht_requests = NULL; -GHashTable *ht_requests_static = NULL; -GHashTable *ht_status_code = NULL; -GHashTable *ht_unique_visitors = NULL; -GHashTable *ht_unique_vis = NULL; - -/* Initialize GLib hash tables */ -void -init_storage (void) -{ - ht_date_bw = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_file_bw = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_file_serve_usecs = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_host_bw = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_hostnames = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_hosts_agents = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_host_serve_usecs = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_not_found_requests = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_request_keys = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_request_methods = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_request_protocols = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_requests = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_requests_static = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - - ht_keyphrases = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_referring_sites = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_status_code = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_hosts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_unique_vis = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_referrers = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - ht_unique_visitors = - g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - - /* The following tables contain a structure as their value, thus we - use a special iterator to free its value */ - ht_browsers = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - ht_countries = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - ht_os = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); -} - -#ifdef HAVE_LIBGEOIP -void -free_countries (GO_UNUSED gpointer old_key, gpointer old_value, - GO_UNUSED gpointer user_data) -{ - GLocation *loc = old_value; - free (loc); -} -#endif - -void -free_os (GO_UNUSED gpointer old_key, gpointer old_value, - GO_UNUSED gpointer user_data) -{ - GOpeSys *opesys = old_value; - free (opesys); -} - -void -free_browser (GO_UNUSED gpointer old_key, gpointer old_value, - GO_UNUSED gpointer user_data) -{ - GBrowser *browser = old_value; - free (browser); -} - -/* free memory allocated by g_hash_table_new_full() function */ -void -free_key_value (gpointer old_key, GO_UNUSED gpointer old_value, - GO_UNUSED gpointer user_data) -{ - g_free (old_key); -} - -uint32_t -get_ht_size (GHashTable * ht) -{ - return g_hash_table_size (ht); -} - -int -process_request_meta (GHashTable * ht, char *key, uint64_t size) -{ - gpointer value_ptr; - uint64_t add_value; - uint64_t *ptr_value; - - if ((ht == NULL) || (key == NULL)) - return (EINVAL); - - value_ptr = g_hash_table_lookup (ht, key); - if (value_ptr != NULL) { - ptr_value = (uint64_t *) value_ptr; - add_value = *ptr_value + size; - } else { - add_value = 0 + size; - } - - ptr_value = xmalloc (sizeof (uint64_t)); - *ptr_value = add_value; - - g_hash_table_replace (ht, g_strdup (key), ptr_value); - - return 0; -} - -int -process_opesys (GHashTable * ht, const char *key, const char *os_type) -{ - GOpeSys *opesys; - if (ht == NULL) - return (EINVAL); - - opesys = g_hash_table_lookup (ht, key); - if (opesys != NULL) { - opesys->hits++; - } else { - opesys = xcalloc (1, sizeof (GOpeSys)); - strcpy (opesys->os_type, os_type); - opesys->hits = 1; - } - - /* replace the entry. old key will be freed by "free_os" */ - g_hash_table_replace (ht, g_strdup (key), opesys); - - return 0; -} - -int -process_browser (GHashTable * ht, const char *key, const char *browser_type) -{ - GBrowser *browser; - if (ht == NULL) - return (EINVAL); - - browser = g_hash_table_lookup (ht, key); - if (browser != NULL) { - browser->hits++; - } else { - browser = xcalloc (1, sizeof (GBrowser)); - strcpy (browser->browser_type, browser_type); - browser->hits = 1; - } - - /* replace the entry. old key will be freed by "free_browser" */ - g_hash_table_replace (ht, g_strdup (key), browser); - - return 0; -} - -static void -process_request_protocol (const char *key, const char *protocol) -{ - g_hash_table_replace (ht_request_protocols, g_strdup (key), - g_strdup (protocol)); -} - -static void -process_request_method (const char *key, const char *method) -{ - g_hash_table_replace (ht_request_methods, g_strdup (key), g_strdup (method)); -} - -static void -process_request_keys (const char *key, const char *request) -{ - g_hash_table_replace (ht_request_keys, g_strdup (key), g_strdup (request)); -} - -int -process_request (GHashTable * ht, const char *key, const GLogItem * glog) -{ - if ((ht == NULL) || (key == NULL)) - return (EINVAL); - - process_generic_data (ht, key); - if (conf.append_protocol && glog->protocol) - process_request_protocol (key, glog->protocol); - if (conf.append_method && glog->method) - process_request_method (key, glog->method); - process_request_keys (key, glog->req); - - return 0; -} - -#ifdef HAVE_LIBGEOIP -int -process_geolocation (GHashTable * ht, const char *ctry, const char *cont, - const char *city) -{ - GLocation *location; - if (ht == NULL) - return (EINVAL); - - location = g_hash_table_lookup (ht, ctry); - if (location != NULL) { - location->hits++; - } else { - location = xcalloc (1, sizeof (GLocation)); - xstrncpy (location->continent, cont, CONTINENT_LEN); - if (city[0] != '\0') - xstrncpy (location->city, city, CITY_LEN); - location->hits = 1; - } - - /* replace the entry. old key will be freed by "free_countries" */ - g_hash_table_replace (ht, g_strdup (ctry), location); - - return 0; -} -#endif - -/* store generic data into the given hash table */ -int -process_generic_data (GHashTable * ht, const char *key) -{ - gpointer value_ptr; - int add_value, first = 0; - int *ptr_value; - - if ((ht == NULL) || (key == NULL)) - return (EINVAL); - - value_ptr = g_hash_table_lookup (ht, key); - if (value_ptr != NULL) { - ptr_value = (int *) value_ptr; - add_value = *ptr_value + 1; - } else { - first = add_value = 1; - } - - ptr_value = xmalloc (sizeof (int)); - *ptr_value = add_value; - - /* replace the entry. old key will be freed by "free_key_value" */ - g_hash_table_replace (ht, g_strdup (key), ptr_value); - - return first ? KEY_NOT_FOUND : KEY_FOUND; -} - -GHashTable * -get_ht_by_module (GModule module) -{ - GHashTable *ht; - - switch (module) { - case VISITORS: - ht = ht_unique_vis; - break; - case REQUESTS: - ht = ht_requests; - break; - case REQUESTS_STATIC: - ht = ht_requests_static; - break; - case NOT_FOUND: - ht = ht_not_found_requests; - break; - case HOSTS: - ht = ht_hosts; - break; - case OS: - ht = ht_os; - break; - case BROWSERS: - ht = ht_browsers; - break; - case REFERRERS: - ht = ht_referrers; - break; - case REFERRING_SITES: - ht = ht_referring_sites; - break; - case KEYPHRASES: - ht = ht_keyphrases; - break; -#ifdef HAVE_LIBGEOIP - case GEO_LOCATION: - ht = ht_countries; - break; -#endif - case STATUS_CODES: - ht = ht_status_code; - break; - default: - return NULL; - } - - return ht; -} - -/* process host agent strings */ -int -process_host_agents (char *host, char *agent) -{ - char *ptr_value, *tmp, *a; - GHashTable *ht = ht_hosts_agents; - gpointer value_ptr; - size_t len1, len2; - - if ((ht == NULL) || (host == NULL) || (agent == NULL)) - return (EINVAL); - - a = xstrdup (agent); - - value_ptr = g_hash_table_lookup (ht, host); - if (value_ptr != NULL) { - ptr_value = (char *) value_ptr; - if (strstr (ptr_value, a)) { - if (a != NULL) - free (a); - return 0; - } - - len1 = strlen (ptr_value); - len2 = strlen (a); - - tmp = xmalloc (len1 + len2 + 2); - memcpy (tmp, ptr_value, len1); - tmp[len1] = '|'; - /* - * NUL-terminated - */ - memcpy (tmp + len1 + 1, a, len2 + 1); - } else - tmp = alloc_string (a); - - g_hash_table_replace (ht, g_strdup (host), tmp); - if (a != NULL) - free (a); - return 0; -} - -char * -get_request_meta (const char *k, GReqMeta meta) -{ - GHashTable *ht = NULL; - gpointer value_ptr; - - switch (meta) { - case REQUEST: - ht = ht_request_keys; - break; - case REQUEST_METHOD: - ht = ht_request_methods; - break; - case REQUEST_PROTOCOL: - ht = ht_request_protocols; - break; - default: - ht = NULL; - } - - if (ht == NULL) - return 0; - - value_ptr = g_hash_table_lookup (ht, k); - if (value_ptr != NULL) - return xstrdup ((char *) value_ptr); - - return alloc_string ("---"); -} - -uint64_t -get_bandwidth (const char *k, GModule module) -{ - gpointer value_ptr; - GHashTable *ht = NULL; - - /* bandwidth modules */ - switch (module) { - case VISITORS: - ht = ht_date_bw; - break; - case REQUESTS: - case REQUESTS_STATIC: - case NOT_FOUND: - ht = ht_file_bw; - break; - case HOSTS: - ht = ht_host_bw; - break; - default: - ht = NULL; - } - - if (ht == NULL) - return 0; - - value_ptr = g_hash_table_lookup (ht, k); - if (value_ptr != NULL) - return (*(uint64_t *) value_ptr); - return 0; -} - -/* get time taken to serve the request, in microseconds for given key */ -uint64_t -get_serve_time (const char *key, GModule module) -{ - gpointer value_ptr; - - /* bandwidth modules */ - GHashTable *ht = NULL; - switch (module) { - case HOSTS: - ht = ht_host_serve_usecs; - break; - case REQUESTS: - case REQUESTS_STATIC: - case NOT_FOUND: - ht = ht_file_serve_usecs; - break; - default: - ht = NULL; - } - - if (ht == NULL) - return 0; - - value_ptr = g_hash_table_lookup (ht, key); - if (value_ptr != NULL) - return *(uint64_t *) value_ptr; - return 0; -} - -/* iterate over the key/value pairs in the hash table */ -static void -raw_data_iter (gpointer k, gpointer v, gpointer data_ptr) -{ - GRawData *raw_data = data_ptr; - raw_data->items[raw_data->idx].key = (gchar *) k; - raw_data->items[raw_data->idx].value = v; - raw_data->idx++; -} - -/* store the key/value pairs from a hash table into raw_data */ -GRawData * -parse_raw_data (GHashTable * ht, int ht_size, GModule module) -{ - GRawData *raw_data; - raw_data = new_grawdata (); - - raw_data->size = ht_size; - raw_data->module = module; - raw_data->idx = 0; - raw_data->items = new_grawdata_item (ht_size); - - g_hash_table_foreach (ht, (GHFunc) raw_data_iter, raw_data); - sort_raw_data (raw_data, module, ht_size); - - return raw_data; -} diff --git a/glibht.h b/glibht.h deleted file mode 100644 index aa58e75050..0000000000 --- a/glibht.h +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#ifndef GLIBHT_H_INCLUDED -#define GLIBHT_H_INCLUDED - -#ifdef HAVE_LIBGLIB_2_0 -#include -#endif - -#include -#include "parser.h" - -extern GHashTable *ht_browsers; -extern GHashTable *ht_countries; -extern GHashTable *ht_date_bw; -extern GHashTable *ht_file_bw; -extern GHashTable *ht_file_serve_usecs; -extern GHashTable *ht_host_bw; -extern GHashTable *ht_hostnames; -extern GHashTable *ht_hosts; -extern GHashTable *ht_hosts_agents; -extern GHashTable *ht_host_serve_usecs; -extern GHashTable *ht_keyphrases; -extern GHashTable *ht_monthly; -extern GHashTable *ht_not_found_requests; -extern GHashTable *ht_os; -extern GHashTable *ht_referrers; -extern GHashTable *ht_referring_sites; -extern GHashTable *ht_request_keys; -extern GHashTable *ht_request_methods; -extern GHashTable *ht_request_protocols; -extern GHashTable *ht_requests; -extern GHashTable *ht_requests_static; -extern GHashTable *ht_status_code; -extern GHashTable *ht_unique_vis; -extern GHashTable *ht_unique_visitors; - -char *get_request_meta (const char *k, GReqMeta meta); -GHashTable *get_ht_by_module (GModule module); -GRawData *parse_raw_data (GHashTable * ht, int ht_size, GModule module); -int process_browser (GHashTable * ht, const char *key, - const char *browser_type); -int process_generic_data (GHashTable * ht, const char *key); -int process_geolocation (GHashTable * ht, const char *ctry, const char *cont, - const char *city); -int process_host_agents (char *host, char *agent); -int process_opesys (GHashTable * ht, const char *key, const char *os_type); -int process_request (GHashTable * ht, const char *key, const GLogItem * glog); -int process_request_meta (GHashTable * ht, char *key, uint64_t size); -uint32_t get_ht_size (GHashTable * ht); -uint64_t get_bandwidth (const char *k, GModule module); -uint64_t get_serve_time (const char *key, GModule module); -void free_browser (GO_UNUSED gpointer old_key, gpointer old_value, - GO_UNUSED gpointer user_data); -void free_countries (GO_UNUSED gpointer old_key, gpointer old_value, - GO_UNUSED gpointer user_data); -void free_key_value (gpointer old_key, GO_UNUSED gpointer old_value, - GO_UNUSED gpointer user_data); -void free_os (GO_UNUSED gpointer old_key, gpointer old_value, - GO_UNUSED gpointer user_data); -void init_storage (void); - -#endif diff --git a/gmenu.c b/gmenu.c deleted file mode 100644 index 75042b1fe5..0000000000 --- a/gmenu.c +++ /dev/null @@ -1,132 +0,0 @@ -/** - * gmenu.c -- goaccess menus - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#include -#include -#include -#include - -#include "gmenu.h" - -#include "error.h" -#include "xmalloc.h" -#include "settings.h" -#include "util.h" -#include "ui.h" - -/* allocate memory for a new GMenu instance */ -GMenu * -new_gmenu (WINDOW * parent, int h, int w, int y, int x) -{ - GMenu *menu = xmalloc (sizeof (GMenu)); - - memset (menu, 0, sizeof *menu); - menu->count = 0; - menu->idx = 0; - menu->multiple = 0; - menu->selectable = 0; - menu->start = 0; - menu->status = 0; - - menu->h = h; - menu->w = w; - menu->x = x; - menu->y = y; - menu->win = derwin (parent, menu->h, menu->w, menu->y, menu->x); - - return menu; -} - -/* render an actual menu item */ -static void -draw_menu_item (GMenu * menu, char *s, int x, int y, int w, int color, - int checked) -{ - char check, *lbl = NULL; - if (menu->selectable) { - check = checked ? 'x' : ' '; - lbl = xmalloc (snprintf (NULL, 0, "[%c] %s", check, s) + 1); - sprintf (lbl, "[%c] %s", check, s); - draw_header (menu->win, lbl, "%s", y, x, w, color); - free (lbl); - } else { - draw_header (menu->win, s, "%s", y, x, w, color); - } -} - -/* displays a menu to its associated window */ -int -post_gmenu (GMenu * menu) -{ - int i = 0, j = 0, k = 0, start, end, height, total, checked = 0; - if (menu == NULL) - return 1; - - werase (menu->win); - - height = menu->h; - start = menu->start; - total = menu->size; - end = height < total ? start + height : total; - for (i = start; i < end; i++, j++) { - k = i == menu->idx ? 1 : 0; - checked = menu->items[i].checked ? 1 : 0; - draw_menu_item (menu, menu->items[i].name, 0, j, menu->w, k, checked); - } - wrefresh (menu->win); - return 0; -} - -/* main work horse of the menu system processing input events */ -void -gmenu_driver (GMenu * menu, int c) -{ - int i; - switch (c) { - case REQ_DOWN: - if (menu->idx >= menu->size - 1) - break; - ++menu->idx; - if (menu->idx >= menu->h && menu->idx >= menu->start + menu->h) - menu->start++; - post_gmenu (menu); - break; - case REQ_UP: - if (menu->idx <= 0) - break; - --menu->idx; - if (menu->idx < menu->start) - --menu->start; - post_gmenu (menu); - break; - case REQ_SEL: - if (!menu->multiple) { - for (i = 0; i < menu->size; i++) - menu->items[i].checked = 0; - } - if (menu->items[menu->idx].checked) - menu->items[menu->idx].checked = 0; - else - menu->items[menu->idx].checked = 1; - post_gmenu (menu); - break; - } -} diff --git a/gmenu.h b/gmenu.h deleted file mode 100644 index c3eca1394a..0000000000 --- a/gmenu.h +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#if HAVE_CONFIG_H -#include -#endif - -#ifdef HAVE_NCURSESW_NCURSES_H -#include -#elif HAVE_NCURSES_NCURSES_H -#include -#elif HAVE_NCURSES_H -#include -#elif HAVE_CURSES_H -#include -#endif - -#ifndef GMENU_H_INCLUDED -#define GMENU_H_INCLUDED - -enum ACTION -{ - REQ_DOWN, - REQ_UP, - REQ_SEL -}; - -typedef struct GMenu_ GMenu; -typedef struct GItem_ GItem; - -struct GItem_ -{ - char *name; - int checked; -}; - -struct GMenu_ -{ - WINDOW *win; - - int count; - int size; - int idx; - int start; - int h; - int w; - int x; - int y; - unsigned short multiple; - unsigned short selectable; - unsigned short status; - GItem *items; -}; - -GMenu *new_gmenu (WINDOW * parent, int h, int w, int y, int x); -int post_gmenu (GMenu * menu); -void gmenu_driver (GMenu * menu, int c); - -#endif diff --git a/goaccess.1 b/goaccess.1 index 8abd00bf90..ca7887d0b1 100644 --- a/goaccess.1 +++ b/goaccess.1 @@ -1,85 +1,148 @@ -.TH goaccess 1 "MAY 2014" Linux "User Manuals" +.TH goaccess 1 "MAY 2024" GNU+Linux "User Manuals" .SH NAME goaccess \- fast web log analyzer and interactive viewer. .SH SYNOPSIS .LP -.B goaccess [-f input-file][\-c][\-r][\-d][\-m][\-q][\-o][\-h][...] +.B goaccess [filename] [options...] [-c][-M][-H][-q][-d][...] .SH DESCRIPTION .B goaccess -is a free (GPL) real-time web log analyzer and interactive viewer that runs in a -terminal in *nix systems. It provides fast and valuable HTTP statistics for -system administrators that require a visual server report on the fly. GoAccess -parses the specified web log file and outputs the data to the X terminal. -Features include: +GoAccess is an open source real-time web log analyzer and interactive viewer +that runs in a +.I terminal +in *nix systems or through your +.I browser. +.P +It provides fast and valuable HTTP statistics for system administrators that +require a visual server report on the fly. +.P +GoAccess parses the specified web log file and outputs the data to the X +terminal. Features include: .IP "General Statistics:" -Number of valid requests, number of invalid requests, time to analyze the data, -unique visitors, unique requested files, unique static files (css, ico, jpg, js, -swf, gif, png) unique HTTP referrers (URLs), unique 404s (not found), size of -the parsed log file, bandwidth consumption. -.IP "Unique visitors:" -HTTP requests having the same IP, same date and same agent will be considered a -unique visit. This includes crawlers. +This panel gives a summary of several metrics, such as the number of valid and +invalid requests, time taken to analyze the dataset, unique visitors, requested +files, static files (CSS, ICO, JPG, etc) HTTP referrers, 404s, size of the +parsed log file and bandwidth consumption. +.IP "Unique visitors" +This panel shows metrics such as hits, unique visitors and cumulative bandwidth +per date. HTTP requests containing the same IP, the same date, and the same +user agent are considered a unique visitor. By default, it includes web +crawlers/spiders. +.IP +Optionally, date specificity can be set to the hour level using +.I --date-spec=hr +which will display dates such as 05/Jun/2016:16, or to the minute level +producing 05/Jun/2016:16:59. This is great if you want to track your daily +traffic at the hour or minute level. .IP "Requested files" -Hit totals are based on total requests. This module will display hits, percent, -bandwidth [time served], [protocol] and [method]. +This panel displays the most requested (non-static) files on your web server. +It shows hits, unique visitors, and percentage, along with the cumulative +bandwidth, protocol, and the request method used. .IP "Requested static files" -Hit totals are based on total requests. Includes files such as: jpg, css, swf, -js, gif, png etc. This module will display hits, percent, bandwidth, [time -served], [protocol] and [method]. +Lists the most frequently static files such as: JPG, CSS, SWF, JS, GIF, and PNG +file types, along with the same metrics as the last panel. Additional static +files can be added to the configuration file. .IP "404 or Not Found" -Hit totals are based on total requests. This module will display hits, percent, -bandwidth, [time served], [protocol] and [method]. +Displays the same metrics as the previous request panels, however, its data +contains all pages that were not found on the server, or commonly known as 404 +status code. .IP "Hosts" -Hit totals are based on total requests. This module will display hits, percent, -[bandwidth, time served]. The expanded module can display extra information such -as reverse DNS and country. If -a is enabled, a list of user agents will be -displayed by selecting the IP and hitting the return key. +This panel has detailed information on the hosts themselves. This is great for +spotting aggressive crawlers and identifying who's eating your bandwidth. + +Expanding the panel can display more information such as host's reverse DNS +lookup result, country of origin and city. If the +.I -a +argument is enabled, a list of user agents can be displayed by selecting the +desired IP address, and then pressing ENTER. .IP "Operating Systems" -Hit totals are based on unique visitors. This module will display hits and -percent. The expanded module shows all available versions of the parent node. +This panel will report which operating system the host used when it hit the +server. It attempts to provide the most specific version of each operating +system. .IP "Browsers" -Hit totals are based on unique visitors. This module will display hits and -percent. The expanded module shows all available versions of the parent node. +This panel will report which browser the host used when it hit the server. It +attempts to provide the most specific version of each browser. +.IP "Visit Times" +This panel will display an hourly report. This option displays 24 data points, +one for each hour of the day. +.IP +Optionally, hour specificity can be set to the tenth of an hour level using +.I --hour-spec=min +which will display hours as 16:4 This is great if you want to spot peaks of +traffic on your server. +.IP "Virtual Hosts" +This panel will display all the different virtual hosts parsed from the access +log. This panel is displayed if +.I %v +is used within the log-format string. .IP "Referrers URLs" -The URL where the request came from. Hit totals are based on total requests. -This module will display hits and percent. +If the host in question accessed the site via another resource, or was +linked/diverted to you from another host, the URL they were referred from will +be provided in this panel. See `--ignore-panel` in your configuration file to +enable it. +.I disabled +by default. .IP "Referring Sites" -This module will display only the host but not the whole URL. The URL where the -request came from. Hit totals are based on total requests. This module will -display hits and percent. +This panel will display only the host part but not the whole URL. The URL where +the request came from. .IP "Keyphrases" -This module will report keyphrases used on Google search, Google cache, and -Google translate. Hit totals are based on total requests. This module will -display hits and percent. +It reports keyphrases used on Google search, Google cache, and Google translate +that have lead to your web server. At present, it only supports Google search +queries via HTTP. See `--ignore-panel` in your configuration file to enable it. +.I disabled +by default. .IP "Geo Location" -Determines where an IP address is geographically located. It outputs the -continent and country. If it's unable to determine the country, location will be -marked as unknown. +Determines where an IP address is geographically located. Statistics are broken +down by continent and country. It needs to be compiled with GeoLocation +support. .IP "HTTP Status Codes" -The values of the numeric status code to HTTP requests. Hit totals are based on -total requests. This module will display hits and percent. +The values of the numeric status code to HTTP requests. +.IP "ASN" +This panel displays ASN (Autonomous System Numbers) data for GeoIP2 and legacy +databases. Great for detecting malicious traffic and blocking accordingly. +.IP "Remote User (HTTP authentication)" +This is the userid of the person requesting the document as determined by HTTP +authentication. If the document is not password protected, this part will be +"-" just like the previous one. This panel is not enabled unless +.I %e +is given within the log-format variable. +.IP "Cache Status" +If you are using caching on your server, you may be at the point where you +want to know if your request is being cached and served from the cache. This +panel shows the cache status of the object the server served. This panel is not +enabled unless +.I %C +is given within the log-format variable. The status can be either + `MISS`, `BYPASS`, `EXPIRED`, `STALE`, `UPDATING`, `REVALIDATED` or `HIT` +.IP "MIME Types" +This panel specifies Media Types (formerly known as MIME types) and Media +Subtypes which will be assigned and listed underneath. This panel is not +enabled unless +.I %M +is given within the log-format variable. See +https://www.iana.org/assignments/media-types/media-types.xhtml for more +details. +.IP "Encryption Settings" +This panel shows the SSL/TLS protocol used along the Cipher Suites. This panel +is not enabled unless +.I %K +is given within the log-format variable. + +.P +.I NOTE: +Optionally and if configured, all panels can display the average time taken to +serve the request. + .SH STORAGE .P There are three storage options that can be used with GoAccess. Choosing one will depend on your environment and needs. .TP -GLib Hash Tables -By default GoAccess uses GLib Hash Tables. If your dataset can fit in memory, -then this will perform fine. It has average memory usage and pretty good -performance. For better performance with memory trade-off see Tokyo Cabinet -on-memory hash database. -.TP -Tokyo Cabinet On-Disk B+ Tree -Use this storage method for large datasets where is not possible to fit -everything in memory. The B+ tree database is slower than any of the hash -databases since it has to hit the disk. However, using an SSD greatly increases -the performance. You may also use this storage method if you need data -persistence to quickly load statistics at a later date. -.TP -Tokyo Cabinet On-Memory Hash Database -Although this may vary across different systems, in general the on-memory hash -database should perform slightly better than GLib Hash Tables. +Default Hash Tables +In-memory storage provides better performance at the cost of limiting the +dataset size to the amount of available physical memory. GoAccess uses +in-memory hash tables. It has very good memory usage and pretty good +performance. This storage has support for on-disk persistence. .SH CONFIGURATION .P Multiple options can be used to configure GoAccess. For a complete up-to-date @@ -92,192 +155,726 @@ Compile with debugging symbols and turn off compiler optimizations. \fB\-\-enable-utf8 Compile with wide character support. Ncursesw is required. .TP -\fB\-\-enable-geoip +\fB\-\-enable-geoip= Compile with GeoLocation support. MaxMind's GeoIP is required. +.I legacy +will utilize the original GeoIP databases. +.I mmdb +will utilize the enhanced GeoIP2 databases. .TP -\fB\-\-enable-tcb= -Compile with Tokyo Cabinet storage support. -.I memhash -will utilize Tokyo Cabinet's on-memory hash database. -.I btree -will utilize Tokyo Cabinet's on-disk B+ Tree database. -.TP -\fB\-\-disable-zlib -Disable zlib compression on B+ Tree database. +\fB\-\-with-getline +Dynamically expands line buffer in order to parse full line requests instead of +using a fixed size buffer of 4096. .TP -\fB\-\-disable-bzip -Disable bzip2 compression on B+ Tree database. +\fB\-\-with-openssl +Compile GoAccess with OpenSSL support for its WebSocket server. .SH OPTIONS .P -The following options can be supplied via the command line or the long options -through the configuration file. +The following options can be supplied to the command or specified in the +configuration file. If specified in the configuration file, long options need +to be used without prepending -- and without using the equal sign =. +.SS +LOG/DATE/TIME FORMAT +.TP +\fB\-\-time-format= +The time-format variable followed by a space, specifies the log format time +containing either a name of a predefined format (see options below) or any +combination of regular characters and special format specifiers. +.IP +They all begin with a percentage (%) sign. See `man strftime`. +.I %T or %H:%M:%S. +.IP +Note that if a timestamp is given in microseconds, +.I %f +must be used as time-format. +If the timestamp is given in milliseconds +.I %* +must be used as time-format. .TP \fB\-\-date-format= -The date_format variable followed by a space, specifies the log format date -containing any combination of regular characters and special format specifiers. +The date-format variable followed by a space, specifies the log format time +containing either a name of a predefined format (see options below) or any +combination of regular characters and special format specifiers. +.IP They all begin with a percentage (%) sign. See `man strftime`. - -Note that there is no need to use time specifiers since they are not used by -GoAccess. It's recommended to use only date specifiers, i.e., .I %Y-%m-%d. +.IP +Note that if a timestamp is given in microseconds, +.I +%f +must be used as date-format. +If the timestamp is given in milliseconds +.I %* +must be used as date-format. +.TP +\fB\-\-datetime-format= +The date and time format combines the two variables into a single option. This +gives the ability to get the timezone from a request and convert it to another +timezone for output. See +.I --tz= +.IP +They all begin with a percentage (%) sign. See `man strftime`. e.g., +.I %d/%b/%Y:%H:%M:%S %z. +.IP +Note that if --datetime-format is used, +.I %x +must be passed in the log-format variable to represent the date and time field. .TP \fB\-\-log-format= -The log_format variable followed by a space or +The log-format variable followed by a space or .I \\\\t for tab-delimited, specifies the log format string. Note that if there are spaces within the format, the string needs to be -enclosed in double quotes. Inner quotes need to be escaped. +enclosed in single/double quotes. Inner quotes need to be escaped. +.IP +In addition to specifying the raw log/date/time formats, for simplicity, any of +the following predefined log format names can be supplied to the +log/date/time-format variables. GoAccess can also handle one predefined name in +one variable and another predefined name in another variable. +.IP + COMBINED - Combined Log Format, + VCOMBINED - Combined Log Format with Virtual Host, + COMMON - Common Log Format, + VCOMMON - Common Log Format with Virtual Host, + W3C - W3C Extended Log File Format, + SQUID - Native Squid Log Format, + CLOUDFRONT - Amazon CloudFront Web Distribution, + CLOUDSTORAGE - Google Cloud Storage, + AWSELB - Amazon Elastic Load Balancing, + AWSS3 - Amazon Simple Storage Service (S3) + AWSALB - Amazon Application Load Balancer + CADDY - Caddy's JSON Structured format (local/info format) + TRAEFIKCLF - Traefik's CLF flavor +.IP +.I Note: +Generally, you need quotes around values that include white spaces, commas, +pipes, quotes, and/or brackets. Inner quotes must be escaped. +.IP +.I Note: +Piping data into GoAccess won't prompt a log/date/time configuration dialog, +you will need to previously define it in your configuration file or in the +command line. +.IP +.I Note: +The default GoAccess format for CADDY is the 'local/info' format. Nevertheless, +if needed, you have the option to utilize a custom GoAccess log format to match +your particular configuration. +.SS +USER INTERFACE OPTIONS .TP \fB\-c \-\-config-dialog -Prompt log/date configuration window on program start. +Prompt log/time/date configuration window on program start. Only when curses is +initialized. +.TP +\fB\-i \-\-hl-header +Color highlight active terminal panel. +.TP +\fB\-m \-\-with-mouse +Enable mouse support on main terminal dashboard. .TP -\fB\-\-color-scheme<1|2> +\fB\-\-\-color= +Specify custom colors for the terminal output. + +.I Color Syntax + DEFINITION space/tab colorFG#:colorBG# [attributes,PANEL] + + FG# = foreground color [-1...255] (-1 = default term color) + BG# = background color [-1...255] (-1 = default term color) + +Optionally, it is possible to apply color attributes (multiple attributes are +comma separated), such as: +.I bold, +.I underline, +.I normal, +.I reverse, +.I blink + +If desired, it is possible to apply custom colors per panel, that is, a metric +in the REQUESTS panel can be of color A, while the same metric in the BROWSERS +panel can be of color B. + +.I Available color definitions: + COLOR_MTRC_HITS + COLOR_MTRC_VISITORS + COLOR_MTRC_DATA + COLOR_MTRC_BW + COLOR_MTRC_AVGTS + COLOR_MTRC_CUMTS + COLOR_MTRC_MAXTS + COLOR_MTRC_PROT + COLOR_MTRC_MTHD + COLOR_MTRC_HITS_PERC + COLOR_MTRC_HITS_PERC_MAX + COLOR_MTRC_VISITORS_PERC + COLOR_MTRC_VISITORS_PERC_MAX + COLOR_PANEL_COLS + COLOR_BARS + COLOR_ERROR + COLOR_SELECTED + COLOR_PANEL_ACTIVE + COLOR_PANEL_HEADER + COLOR_PANEL_DESC + COLOR_OVERALL_LBLS + COLOR_OVERALL_VALS + COLOR_OVERALL_PATH + COLOR_ACTIVE_LABEL + COLOR_BG + COLOR_DEFAULT + COLOR_PROGRESS + +See configuration file for a sample color scheme. +.TP +\fB\-\-color-scheme=<1|2|3> Choose among color schemes. .I 1 for the default grey scheme. .I 2 for the green scheme. +.I 3 +for the Monokai scheme (shown only if terminal supports 256 colors). +.TP +\fB\-\-crawlers-only +Parse and display only crawlers (bots). +.TP +\fB\-\-html-custom-css= +Specifies a custom CSS file path to load in the HTML report. +.TP +\fB\-\-html-custom-js= +Specifies a custom JS file path to load in the HTML report. +.TP +\fB\-\-html-report-title= +Set HTML report page title and header. +.TP +\fB\-\-html-refresh=<secs> +Refresh the HTML report every X seconds. The value has to be between 1 and 60 +seconds. The default is set to refresh the HTML report every 1 second. +.TP +\fB\-\-html-prefs=<JSON> +Set HTML report default preferences. Supply a valid JSON object containing the +HTML preferences. It allows the ability to customize each panel plot. See +example below. +.IP +.I Note: +The JSON object passed needs to be a one line JSON string. For instance, +.IP +.nf +\-\-html-prefs='{"theme":"bright","perPage":5,"layout":"horizontal","showTables":true,"visitors":{"plot":{"chartType":"bar"}}}' +.fi +.TP +\fB\-\-json-pretty-print +Format JSON output using tabs and newlines. +.IP +.I Note: +This is not recommended when outputting a real-time HTML report since the +WebSocket payload will much much larger. +.TP +\fB\-\-max-items=<number> +The maximum number of items to display per panel. The maximum can be a number +between 1 and n. +.IP +.I Note: +Only the CSV and JSON output allow a maximum number greater than the default +value of 366 (or 50 in the real-time HTML output) items per panel. .TP \fB\-\-no-color -Turn off colored output. This is the default output on terminals that do not +Turn off colored output. This is the default output on terminals that do not support colors. .TP +\fB\-\-no-column-names +Don't write column names in the terminal output. By default, it displays column +names for each available metric in every panel. +.TP +\fB\-\-no-csv-summary +Disable summary metrics on the CSV output. +.TP +\fB\-\-no-progress +Disable progress metrics [total requests/requests per second]. +.TP +\fB\-\-no-tab-scroll +Disable scrolling through panels when TAB is pressed or when a panel is +selected using a numeric key. +.TP +\fB\-\-no-html-last-updated +Do not show the last updated field displayed in the HTML generated report. +.TP +\fB\-\-no-parsing-spinner +Do now show the progress metrics and parsing spinner. +.TP +\fB\-\-tz=<timezone> +Outputs the report date/time data in the given timezone. Note that it uses the +canonical timezone name. e.g., +.I Europe/Berlin +or +.I America/Chicago +or +.I Africa/Cairo +If an invalid timezone name is given, the output will be in GMT. See +.I --datetime-format +in order to properly specify a timezone in the date/time format. +.SS +SERVER OPTIONS +.P +.I Note +This is just a WebSocket server to provide the raw real-time data. +It is not a WebServer itself. To access your reports html file, you will +still need your own HTTP server, place the generated report in it's document +root dir and open the html file in your browser. The browser will then open +another WebSocket-connection to the ws-server you may setup here, +to keep the dashboard up-to-date. +.TP +\fB\-\-addr +Specify IP address to bind the server to. Otherwise it binds to 0.0.0.0. +.IP +Usually there is no need to specify the address, unless you intentionally would +like to bind the server to a different address within your server. +.TP +\fB\-\-daemonize +Run GoAccess as daemon (only if \fB\-\-real-time-html enabled). +.IP +Note: It's important to make use of absolute paths across GoAccess' +configuration. +.TP +\fB\-\-user-name=<username> +Run GoAccess as the specified user. +.IP +Note: It's important to ensure the user or the users' group can access the +input and output files as well as any other files needed. +Other groups the user belongs to will be ignored. +As such it's advised to run GoAccess behind a SSL proxy as it's unlikely this +user can access the SSL certificates. +.TP +\fB\-\-origin=<url> +Ensure clients send the specified origin header upon the WebSocket handshake. +.TP +\fB\-\-pid-file=<path/goaccess.pid> +Write the daemon PID to a file when used along the --daemonize option. +.TP +\fB\-\-port=<port> +Specify the port to use. By default GoAccess' WebSocket server listens on port +7890. +.TP +\fB\-\-real-time-html +Enable real-time HTML output. +.IP +GoAccess uses its own WebSocket server to push the data from the server to the +client. See http://gwsocket.io for more details how the WebSocket server works. +.TP +\fB\-\-ws-url=<[scheme://]url[:port]> +URL to which the WebSocket server responds. This is the URL supplied to the +WebSocket constructor on the client side. +.IP +Optionally, it is possible to specify the WebSocket URI scheme, such as +.I ws:// +or +.I wss:// +for unencrypted and encrypted connections. e.g., +.I +wss://goaccess.io +.IP +If GoAccess is running behind a proxy, you could set the client side to connect +to a different port by specifying the host followed by a colon and the port. +e.g., +.I goaccess.io:9999 +.IP +By default, it will attempt to connect to the generated report's hostname. If +GoAccess is running on a remote server, the host of the remote server should be +specified here. Also, make sure it is a valid host and NOT an http address. +.TP +\fB\-\-ping-interval=<secs> +Enable WebSocket ping with specified interval in seconds. This helps prevent +idle connections getting disconnected. +.TP +\fB\-\-fifo-in=<path/file> +Creates a named pipe (FIFO) that reads from on the given path/file. +.TP +\fB\-\-fifo-out=<path/file> +Creates a named pipe (FIFO) that writes to the given path/file. +.TP +\fB\-\-ssl-cert=<cert.crt> +Path to TLS/SSL certificate. In order to enable TLS/SSL support, GoAccess +requires that \-\-ssl-cert and \-\-ssl-key are used. + +Only if configured using --with-openssl +.TP +\fB\-\-ssl-key=<priv.key> +Path to TLS/SSL private key. In order to enable TLS/SSL support, GoAccess +requires that \-\-ssl-cert and \-\-ssl-key are used. + +Only if configured using --with-openssl +.SS +FILE OPTIONS +.TP +\fB\- +The log file to parse is read from stdin. +.TP \fB\-f \-\-log-file=<logfile> Specify the path to the input log file. If set in the config file, it will take priority over -f from the command line. .TP -\fB\-\-debug-file=<debugfile> -Send all debug messages to the specified file. Needs to be configured with ---enable-debug +\fB\-S \-\-log-size=<bytes> +Specify the log size in bytes. This is useful when piping in logs for +processing in which the log size can be explicitly set. .TP -\fB\-\-config-file=<configfile> +\fB\-l \-\-debug-file=<debugfile> +Send all debug messages to the specified file. +.TP +\fB\-p \-\-config-file=<configfile> Specify a custom configuration file to use. If set, it will take priority over the global configuration file (if any). .TP +\fB\-\-external-assets +Output HTML assets to external JS/CSS files. Great if you are setting up +Content Security Policy (CSP). This will create two separate files, +.I goaccess.js +and +.I goaccess.css +, in the same directory as your report.html file. +.TP +\fB\-\-invalid-requests=<filename> +Log invalid requests to the specified file. +.TP +\fB\-\-unknowns-log=<filename> +Log unknown browsers and OSs to the specified file. +.TP \fB\-\-no-global-config Do not load the global configuration file. This directory should normally be /usr/local/etc, unless specified with .I --sysconfdir=/dir. -.TP -\fB\-e \-\-exclude-ip=<IP> -Exclude an IP from being counted. +See --dcf option for finding the default configuration file. +.SS +PARSE OPTIONS .TP \fB\-a \-\-agent-list Enable a list of user-agents by host. For faster parsing, do not enable this flag. .TP -\fB\-M \-\-http-method -Include HTTP request method if found. This will create a request key containing -the request method + the actual request. +\fB\-d \-\-with-output-resolver +Enable IP resolver on HTML|JSON output. +.TP +\fB\-e \-\-exclude-ip=<IP|IP-range> +Exclude an IPv4 or IPv6 from being counted. Applicable solely during access log +data processing, it does not exclude persisted data. +Ranges can be included as well using a dash in between the IPs (start-end). +.IP +.I Examples: + exclude-ip 127.0.0.1 + exclude-ip 192.168.0.1-192.168.0.100 + exclude-ip ::1 + exclude-ip 0:0:0:0:0:ffff:808:804-0:0:0:0:0:ffff:808:808 +.TP +\fB\-j \-\-jobs=<1-6> +This specifies the number of parallel processing threads to be used during the +execution of the program. It determines the degree of concurrency when +analyzing log data, allowing for parallel processing of multiple tasks +simultaneously. It defaults to 1 thread. It's common to set the number of jobs +based on the available hardware resources, such as the number of CPU cores. +.TP +\fB\-H \-\-http-protocol=<yes|no> +Set/unset HTTP request protocol. This will create a request key containing the +request protocol + the actual request. .TP -\fB\-H \-\-http-protocol -Include HTTP request protocol if found. This will create a request key -containing the request protocol + the actual request. +\fB\-M \-\-http-method=<yes|no> +Set/unset HTTP request method. This will create a request key containing the +request method + the actual request. +.TP +\fB\-o \-\-output=<path/file.[json|csv|html]> +Write output to stdout given one of the following files and the corresponding +extension for the output format: +.IP + /path/file.csv - Comma-separated values (CSV) + /path/file.json - JSON (JavaScript Object Notation) + /path/file.html - HTML .TP \fB\-q \-\-no-query-string -Ignore request's query string. i.e., www.google.com/page.htm?query => -www.google.com/page.htm +Ignore request's query string. i.e., www.google.com/page.htm?query => +www.google.com/page.htm. +.IP +.I Note: +Removing the query string can greatly decrease memory consumption, especially +on timestamped requests. .TP \fB\-r \-\-no-term-resolver Disable IP resolver on terminal output. .TP -\fB\-o \-\-output-format=<json|csv> -Write output to stdout given one of the following formats: -.I csv -: Comma-separated values (CSV) -.I json -: JSON (JavaScript Object Notation) +\fB\-\-444-as-404 +Treat non-standard status code 444 as 404. .TP -\fB\-\-real-os -Display real OS names. e.g, Windows XP, Snow Leopard. +\fB\-\-4xx-to-unique-count +Add 4xx client errors to the unique visitors count. .TP -\fB\-\-no-progress -Disable progress metrics [total requests/requests per second]. +\fB\-\-anonymize-ip +Anonymize the client IP address. The IP anonymization option sets the last +octet of IPv4 user IP addresses and the last 80 bits of IPv6 addresses to +zeros. +e.g., 192.168.20.100 => 192.168.20.0 +e.g., 2a03:2880:2110:df07:face:b00c::1 => 2a03:2880:2110:df07:: +.IP +.I Note: +This deactivates -a. .TP -\fB\-m \-\-with-mouse -Enable mouse support on main dashboard. +\fB\-\-chunk-size=<256-32768> +This determines the number of lines that form a chunk. This parameter +influences the size of the data processed concurrently by each thread, allowing +for parallelization of the file reading and processing tasks. The value of +chunk-size affects the efficiency of the parallel processing and can be +adjusted based on factors such as system resources and the characteristics of +the input data. + +.IP +Low Values: If chunk-size is set too low, it might result in inefficient +processing. For instance, if each chunk contains a very small number of lines, +the overhead of managing and coordinating parallel processing might outweigh +the benefits. + +.IP +Large Values: Conversely, if chunk-size is set too high, it could lead to +resource exhaustion. Each chunk represents a portion of data that a thread +processes in parallel. Setting chunk-size to an excessively large value might +cause memory issues, particularly if there are many parallel threads running +simultaneously. .TP -\fB\-d \-\-with-output-resolver -Enable IP resolver on HTML|JSON output. +\fB\-\-anonymize-level +Specifies the anonymization levels: 1 => default, 2 => strong, 3 => pedantic. +.TS +allbox; +lb lb lb lb +l l l l. +Bits-hidden Level 1 Level 2 Level 3 +T{ +.BR IPv4 +T} 8 16 24 +T{ +.BR IPv6 +T} 64 80 96 +.TE + .TP -\fB\-g \-\-std-geoip -Standard GeoIP database for less memory usage. +\fB\-\-all-static-files +Include static files that contain a query string. e.g., +/fonts/fontawesome-webfont.woff?v=4.0.3 .TP -\fB\-\-geoip-city-data=<geocityfile> -Specify path to GeoIP City database file. i.e., GeoLiteCity.dat. File needs to -be downloaded from maxmind.com. +\fB\-\-browsers-file=<path> +By default GoAccess parses an "essential/basic" curated list of browsers & +crawlers. If you need to add additional browsers, use this option. +Include an additional delimited list of browsers/crawlers/feeds etc. +See config/browsers.list for an example or +https://raw.githubusercontent.com/allinurl/goaccess/master/config/browsers.list .TP -\fB\-\-keep-db-files -Persist parsed data into disk. This should be set to the first dataset prior to -use `load-from-disk`. Setting it to false will delete all database files when -exiting the program. - -Only if configured with --enable-tcb=btree +\fB\-\-date-spec=<date|hr|min> +Set the date specificity to either date (default), hr to display hours or min +to display minutes appended to the date. +.IP +This is used in the visitors panel. It's useful for tracking visitors at the +hour level. For instance, an hour specificity would yield to display traffic as +18/Dec/2010:19 or minute specificity 18/Dec/2010:19:59. .TP -\fB\-\-load-from-disk -Load previously stored data from disk. Database files need to exist. See -.I keep-db-files. - -Only if configured with --enable-tcb=btree +\fB\-\-double-decode +Decode double-encoded values. This includes, user-agent, request, and referrer. .TP -\fB\-\-db-path=<dir> -Path where the on-disk database files are stored. The default value is the -.I /tmp -directory. - -Only if configured with --enable-tcb=btree +\fB\-\-enable-panel=<PANEL> +Enable parsing and displaying the given panel. +.IP +.I Available panels: + VISITORS + REQUESTS + REQUESTS_STATIC + NOT_FOUND + HOSTS + OS + BROWSERS + VISIT_TIMES + VIRTUAL_HOSTS + REFERRERS + REFERRING_SITES + KEYPHRASES + STATUS_CODES + REMOTE_USER + CACHE_STATUS + GEO_LOCATION + MIME_TYPE + TLS_TYPE .TP -\fB\-\-xmmap=<num> -Set the size in bytes of the extra mapped memory. The default value is 0. - -Only if configured with --enable-tcb=btree +\fB\-\-fname-as-vhost=<regex> +Use log filename(s) as virtual host(s). POSIX regex is passed to extract +the virtual host from the filename. e.g., +.I --fname-as-vhost='[a-z]*\.[a-z]*' +can be used to extract awesome.com.log => awesome.com. .TP -\fB\-\-cache-lcnum=<num> -Specifies the maximum number of leaf nodes to be cached. If it is not more than -0, the default value is specified. The default value is 1024. Setting a larger -value will increase speed performance, however, memory consumption will -increase. Lower value will decrease memory consumption. - -Only if configured with --enable-tcb=btree +\fB\-\-hide-referrer=<NEEDLE> +Hide a referrer but still count it. Wild cards are allowed in the needle. i.e., +*.bing.com. .TP -\fB\-\-cache-ncnum=<num> -Specifies the maximum number of non-leaf nodes to be cached. If it is not more -than 0, the default value is specified. The default value is 512. - -Only if configured with --enable-tcb=btree +\fB\-\-hour-spec=<hr|min> +Set the time specificity to either hour (default) or min to display the tenth +of an hour appended to the hour. +.IP +This is used in the time distribution panel. It's useful for tracking peaks of +traffic on your server at specific times. .TP -\fB\-\-tune-lmemb=<num> -Specifies the number of members in each leaf page. If it is not more than 0, -the default value is specified. The default value is 128. - -Only if configured with --enable-tcb=btree +\fB\-\-ignore-crawlers +Ignore crawlers from being counted. +.TP +\fB\-\-unknowns-as-crawlers +Classify unknown OS and browsers as crawlers. .TP -\fB\-\-tune-nmemb=<num> -Specifies the number of members in each non-leaf page. If it is not more than -0, the default value is specified. The default value is 256. +\fB\-\-ignore-panel=<PANEL> +Ignore parsing and displaying the given panel. +.IP +.I Available panels: + VISITORS + REQUESTS + REQUESTS_STATIC + NOT_FOUND + HOSTS + OS + BROWSERS + VISIT_TIMES + VIRTUAL_HOSTS + REFERRERS + REFERRING_SITES + KEYPHRASES + STATUS_CODES + REMOTE_USER + CACHE_STATUS + GEO_LOCATION + MIME_TYPE + TLS_TYPE +.TP +\fB\-\-ignore-referrer=<referrer> +Ignore referrers from being counted. Wildcards allowed. e.g., +.I +*.domain.com +.I +ww?.domain.* +.TP +\fB\-\-ignore-statics=<req|panel> +Ignore static file requests. + +.I req + Only ignore request from valid requests -Only if configured with --enable-tcb=btree +.I panels + Ignore request from panels. + + Note that it will count them towards the total number of requests +.TP +\fB\-\-ignore-status=<CODE> +Ignore parsing and displaying one or multiple status code(s). For multiple +status codes, use this option multiple times. +.TP +\fB\-\-keep-last=<num_days> +Keep the last specified number of days in storage. This will recycle the storage tables. e.g., keep & show only the last 7 days. +.TP +\fB\-\-no-ip-validation +Disable client IP validation. Useful if IP addresses have been obfuscated before +being logged. +The log still needs to contain a placeholder for +.I %h +usually it's a resolved IP. e.g. +.I ord37s19-in-f14.1e100.net. +.TP +\fB\-\-no-strict-status +Disable HTTP status code validation. Some servers would record this value only +if a connection was established to the target and the target sent a response. +Otherwise, it could be recorded as -. +.TP +\fB\-\-num-tests=<number> +Number of lines from the access log to test against the provided log/date/time +format. By default, the parser is set to test 10 lines. If set to 0, the parser +won't test any lines and will parse the whole access log. If a line matches the +given log/date/time format before it reaches +.I <number>, +the parser will consider the log to be valid, otherwise GoAccess will return +EXIT_FAILURE and display the relevant error messages. +.TP +\fB\-\-process-and-exit +Parse log and exit without outputting data. Useful if we are looking to only +add new data to the on-disk database without outputting to a file or a +terminal. +.TP +\fB\-\-real-os +Display real OS names. e.g, Windows XP, Snow Leopard. +.TP +\fB\-\-sort-panel=<PANEL,FIELD,ORDER> +Sort panel on initial load. Sort options are separated by comma. Options are in +the form: PANEL,METRIC,ORDER +.IP +.I Available metrics: + BY_HITS - Sort by hits + BY_VISITORS - Sort by unique visitors + BY_DATA - Sort by data + BY_BW - Sort by bandwidth + BY_AVGTS - Sort by average time served + BY_CUMTS - Sort by cumulative time served + BY_MAXTS - Sort by maximum time served + BY_PROT - Sort by http protocol + BY_MTHD - Sort by http method +.IP +.I Available orders: + ASC + DESC +.TP +\fB\-\-static-file=<extension> +Add static file extension. e.g.: +.I .mp3 +Extensions are case sensitive. +.SS +GEOLOCATION OPTIONS +.TP +\fB\-g \-\-std-geoip +Standard GeoIP database for less memory usage. .TP -\fB\-\-tune-bnum=<num> -Specifies the number of elements of the bucket array. If it is not more than 0, -the default value is specified. The default value is 32749. Suggested size of -the bucket array is about from 1 to 4 times of the number of all pages to be -stored. +\fB\-\-geoip-database=<geofile> +Specify path to GeoIP database file. i.e., GeoLiteCity.dat. -Only if configured with --enable-tcb=btree +If using GeoIP2, you will need to download the GeoLite2 City or Country +database from MaxMind.com and use the option --geoip-database to specify the +database. You can also get updated database files for GeoIP legacy, you can +find these as GeoLite Legacy Databases from MaxMind.com. IPv4 and IPv6 files +are supported as well. For updated DB URLs, please see the default GoAccess +configuration file. + +.I Note: +--geoip-city-data is an alias of --geoip-database. +.SS +OTHER OPTIONS .TP \fB\-h \-\-help The help. .TP \fB\-s \-\-storage Display current storage method. i.e., B+ Tree, Hash. +.TP +\fB\-V \-\-version +Display version information and exit. +.TP +\fB\-\-dcf +Display the path of the default config file when `-p` is not used. +.SS +PERSISTENCE STORAGE OPTIONS +.TP +\fB\-\-persist +Persist parsed data into disk. If database files exist, files will be +overwritten. This should be set to the first dataset. See examples below. +.TP +\fB\-\-restore +Load previously stored data from disk. If reading persisted data only, the +database files need to exist. See +.I --persist +and examples below. +.TP +\fB\-\-db-path=<dir> +Path where the on-disk database files are stored. The default value is the +.I /tmp +directory. + .SH CUSTOM LOG/DATE FORMAT GoAccess can parse virtually any web log format. .P Predefined options include, Common Log Format (CLF), Combined Log Format -(XLF/ELF), including virtual host, Amazon CloudFront (Download Distribution) and -W3C format (IIS). +(XLF/ELF), including virtual host, Amazon CloudFront (Download Distribution), +Google Cloud Storage and W3C format (IIS). .P GoAccess allows any custom format string as well. .P @@ -285,37 +882,93 @@ There are two ways to configure the log format. The easiest is to run GoAccess with .I -c to prompt a configuration window. Otherwise, it can be configured under -~/.goaccessrc. -.IP "date_format" +~/.goaccessrc or the %sysconfdir%. +.IP "time-format" +The +.I time-format +variable followed by a space, specifies the log format time +containing any combination of regular characters and special format specifiers. +They all begin with a percentage (%) sign. See `man strftime`. +.I %T or %H:%M:%S. +.IP +.I Note: +If a timestamp is given in microseconds, +.I +%f +must be used as +.I +time-format +or +.I +%* +if the timestamp is given in milliseconds. +.IP "date-format" The -.I date_format +.I date-format variable followed by a space, specifies the log format date containing any combination of regular characters and special format specifiers. They all begin -with a percentage (%) sign. See http://linux.die.net/man/3/strftime - -Note that there is no need to use time specifiers since they are not used by -GoAccess. It's recommended to use only date specifiers, i.e., +with a percentage (%) sign. See `man strftime`. e.g., .I %Y-%m-%d. -.IP "log_format" +.IP +.I Note: +If a timestamp is given in microseconds, +.I +%f +must be used as +.I +date-format +or +.I +%* +if the timestamp is given in milliseconds. +.IP "log-format" The -.I log_format +.I log-format variable followed by a space or .I \\\\t , specifies the log format string. +.IP %x +A date and time field matching the +.I time-format +and +.I date-format +variables. This is used when given a timestamp or the date & time are +concatenated as a single string (e.g., 1501647332 or 20170801235000) instead of +the date and time being in two separated variables. +.IP %t +time field matching the +.I time-format +variable. .IP %d date field matching the -.I date_format +.I date-format variable. +.IP %v +The canonical Server Name of the server serving the request (Virtual Host). +.IP %e +This is the userid of the person requesting the document as determined by HTTP +authentication. +.IP %C +The cache status of the object the server served. .IP %h host (the client IP address, either IPv4 or IPv6) .IP %r The request line from the client. This requires specific delimiters around the request (as single quotes, double quotes, or anything else) to be parsable. If not, we have to use a combination of special format specifiers as %m %U %H. +.IP %q +The query string. .IP %m The request method. .IP %U -The URL path requested (including any query string). +The URL path requested. + +.I Note: +If the query string is in %U, there is no need to use +.I %q. +However, if the URL path, does not include any query string, you may use +.I %q +and the query string will be appended to the request. .IP %H The request protocol. .IP %s @@ -323,17 +976,70 @@ The status code that the server sends back to the client. .IP %b The size of the object returned to the client. .IP %R -The "Referer" HTTP request header. +The "Referrer" HTTP request header. .IP %u The user-agent HTTP request header. +.IP %K +The TLS encryption settings chosen for the connection. (In Apache LogFormat: %{SSL_PROTOCOL}x) +.IP %k +The TLS encryption settings chosen for the connection. (In Apache LogFormat: %{SSL_CIPHER}x) +.IP %M +The MIME-type of the requested resource. (In Apache LogFormat: %{Content-Type}o) .IP %D -The time taken to serve the request, in microseconds. +The time taken to serve the request, in microseconds as a decimal number. .IP %T -The time taken to serve the request, in seconds or milliseconds. -.I Note: -%D will take priority over %T if both are used. +The time taken to serve the request, in seconds with milliseconds resolution. +.IP %L +The time taken to serve the request, in milliseconds as a decimal number. +.IP %n +The time taken to serve the request, in nanoseconds. .IP %^ Ignore this field. +.IP %~ +Move forward through the log string until a non-space (!isspace) char is found. +.IP ~h +The host (the client IP address, either IPv4 or IPv6) in a X-Forwarded-For (XFF) field. + +It uses a special specifier which consists of a tilde before the host +specifier, followed by the character(s) that delimit the XFF field, which are +enclosed by curly braces. i.e., "~h{, } + +For example, "~h{, }" is used in order to parse "11.25.11.53, 17.68.33.17" field +which is delimited by a comma and a space (enclosed by double quotes). + +.TS +allbox; +lb lb +l l. +XFF field specifier +T{ +.BR \[dq]192.1.2.3, \~192.68.33.17,\~192.1.1.2\[dq] +T} \[dq]~h{, }\[dq] +T{ +.BR \[dq]192.1.2.12\[dq],\~\[dq]192.68.33.17\[dq] +T} ~h{\[dq], } +T{ +.BR 192.1.2.12,\~192.68.33.17 +T} ~h{, } +T{ +.BR 192.1.2.14\~192.68.33.17\~192.1.1.2 +T} ~h{ } +.TE + + +.P +.I Note: +In order to get the average, cumulative and maximum time served in GoAccess, +you will need to start logging response times in your web server. In Nginx you +can add +.I $request_time +to your log format, or +.I %D +in Apache. +.P +.I Important: +If multiple time served specifiers are used at the same time, the first option +specified in the format string will take priority over the other specifiers. .P GoAccess .I requires @@ -345,9 +1051,6 @@ a valid IPv4/6 .I %d a valid date .IP -.I %s -server status code -.IP .I %r the request .SH INTERACTIVE MENU @@ -357,7 +1060,7 @@ Main help. Redraw main window. .IP "q" Quit the program, current window or collapse active module -.IP "o or ENTER" +.IP "o or ENTER" Expand selected module or open window .IP "0-9 and Shift + 0" Set selected module to active @@ -371,9 +1074,9 @@ Set or change scheme color. Forward iteration of modules. Starts from current active module. .IP "SHIFT + TAB" Backward iteration of modules. Starts from current active module. -.IP "^ f" +.IP "^f" Scroll forward one screen within an active module. -.IP "^ b" +.IP "^b" Scroll backward one screen within an active module. .IP "s" Sort options for active module @@ -386,95 +1089,266 @@ Move to the first item or top of screen. .IP "G" Move to the last item or bottom of screen. .SH EXAMPLES -The simplest and fastest usage would be: -.IP -# goaccess -f access.log -.P -That will generate an interactive text-only output. +.I Note: +Piping data into GoAccess won't prompt a log/date/time configuration dialog, +you will need to previously define it in your configuration file or in the +command line. + +.SS +DIFFERENT OUTPUTS .P -To generate full statistics we can run GoAccess as: +To output to a terminal and generate an interactive report: .IP -# goaccess -f access.log -a +# goaccess access.log .P To generate an HTML report: .IP -# goaccess -f access.log -a > report.html +# goaccess access.log -a -o report.html .P -To generate a JSON file: +To generate a JSON report: .IP -# goaccess -f access.log -a -d -o json > report.json +# goaccess access.log -a -d -o report.json .P To generate a CSV file: .IP -# goaccess -f access.log -o csv > report.csv +# goaccess access.log --no-csv-summary -o report.csv .P -The -.I -a -flag indicates that we want to process an agent-list for every host parsed. +GoAccess also allows great flexibility for real-time filtering and parsing. For +instance, to quickly diagnose issues by monitoring logs since goaccess was +started: +.IP +# tail -f access.log | goaccess - .P -The -.I -d -flag indicates that we want to enable the IP resolver on the HTML | JSON output. -(It will take longer time to output since it has to resolve all queries.) +And even better, to filter while maintaining opened a pipe to preserve +real-time analysis, we can make use of +.I tail -f +and +a matching pattern tool such as +.I grep, awk, sed, +etc: +.IP +# tail -f access.log | grep -i --line-buffered 'firefox' | goaccess --log-format=COMBINED - .P -The -.I -c -flag will prompt the date and log format configuration window. Only when -curses is initialized. +or to parse from the beginning of the file while maintaining the pipe opened +and applying a filter +.IP +# tail -f -n +0 access.log | grep -i --line-buffered 'firefox' | goaccess --log-format=COMBINED -o report.html --real-time-html - .P -Now if we want to add more flexibility to GoAccess, we can do a series of pipes. -For instance: +or to convert the log date timezone to a different timezone, e.g., Europe/Berlin +.IP +# goaccess access.log --log-format='%h %^[%x] "%r" %s %b "%R" "%u"' --datetime-format='%d/%b/%Y:%H:%M:%S %z' --tz=Europe/Berlin --date-spec=min +.SS +MULTIPLE LOG FILES +.P +There are several ways to parse multiple logs with GoAccess. The simplest is to +pass multiple log files to the command line: +.IP +# goaccess access.log access.log.1 .P -If we would like to process all +It's even possible to parse files from a pipe while reading regular files: +.IP +# cat access.log.2 | goaccess access.log access.log.1 - +.P +.I Note +that the single dash is appended to the command line to let GoAccess know that +it should read from the pipe. +.P +Now if we want to add more flexibility to GoAccess, we can do a series of +pipes. For instance, if we would like to process all compressed log files .I access.log.*.gz -we can do: +in addition to the current log file, we can do: +.IP +# zcat access.log.*.gz | goaccess access.log - +.P +.I Note: +On Mac OS X, use gunzip -c instead of zcat. +.SS +REAL TIME HTML OUTPUT +.P +GoAccess has the ability to output real-time data in the HTML report. You can +even email the HTML file since it is composed of a single file with no external +file dependencies, how neat is that! +.P +The process of generating a real-time HTML report is very similar to the +process of creating a static report. Only --real-time-html is needed to make it +real-time. .IP -# zcat access.log.*.gz | goaccess +# goaccess access.log -o /usr/share/nginx/html/site/report.html --real-time-html .P -OR +By default, GoAccess will use the host name of the generated report. +Optionally, you can specify the URL to which the client's browser will connect +to. See https://goaccess.io/faq for a more detailed example. .IP -# zcat -f access.log* | goaccess +# goaccess access.log -o report.html --real-time-html --ws-url=goaccess.io +.P +By default, GoAccess listens on port 7890, to use a different port other than +7890, you can specify it as (make sure the port is opened): +.IP +# goaccess access.log -o report.html --real-time-html --port=9870 +.P +And to bind the WebSocket server to a different address other than 0.0.0.0, you +can specify it as: +.IP +# goaccess access.log -o report.html --real-time-html --addr=127.0.0.1 +.P +.I Note: +To output real time data over a TLS/SSL connection, you need to use +.I --ssl-cert=<cert.crt> +and +.I --ssl-key=<priv.key>. +.SS +WORKING WITH DATES .P Another useful pipe would be filtering dates out of the web log .P -The following will get all HTTP requests starting on 05/Dec/2010 until -the end of the file. +The following will get all HTTP requests starting on 05/Dec/2010 until the end +of the file. +.IP +# sed -n '/05\/Dec\/2010/,$ p' access.log | goaccess -a - +.P +or using relative dates such as yesterdays or tomorrows day: .IP -# sed -n '/05\\/Dec\\/2010/,$ p' access.log | goaccess -a +# sed -n '/'$(date '+%d\/%b\/%Y' -d '1 week ago')'/,$ p' access.log | goaccess -a - .P If we want to parse only a certain time-frame from DATE a to DATE b, we can do: .IP -sed -n '/5\\/Nov\\/2010/,/5\\/Dec\\/2010/ p' access.log | goaccess -a +# sed -n '/5\/Nov\/2010/,/5\/Dec\/2010/ p' access.log | goaccess -a - +.P +If we want to preserve only certain amount of data and recycle storage, we can +keep only a certain number of days. For instance to keep & show the last 5 +days: +.IP +# goaccess access.log --keep-last=5 +.SS +VIRTUAL HOSTS +.P +Assuming your log contains the virtual host (server blocks) field. For +instance: +.IP +vhost.com:80 10.131.40.139 - - [02/Mar/2016:08:14:04 -0600] "GET /shop/bag-p-20 +HTTP/1.1" 200 6715 "-" "Apache (internal dummy connection)" .P -.I Note that this could take longer time to parse depending on the speed of sed. +And you would like to append the virtual host to the request in order to see +which virtual host the top urls belong to +.IP +awk '$8=$1$8' access.log | goaccess -a - .P To exclude a list of virtual hosts you can do the following: .IP -grep -v "`cat exclude_vhost_list_file`" vhost_access.log | goaccess +# grep -v "`cat exclude_vhost_list_file`" vhost_access.log | goaccess - +.SS +FILES & STATUS CODES +.P +To parse specific pages, e.g., page views, html, htm, php, etc. within a +request: +.IP +# awk '$7~/\.html|\.htm|\.php/' access.log | goaccess - .P -.B Also, -it is worth pointing out that if we want to run GoAccess at lower priority, we -can run it as: +Note, +.I $7 +is the request field for the common and combined log format, (without Virtual +Host), if your log includes Virtual Host, then you probably want to use +.I $8 +instead. It's best to check which field you are shooting for, e.g.: +.IP +# tail -10 access.log | awk '{print $8}' +.P +Or to parse a specific status code, e.g., 500 (Internal Server Error): +.IP +# awk '$9~/500/' access.log | goaccess - +.SS +SERVER +.P +Also, it is worth pointing out that if we want to run GoAccess at lower +priority, we can run it as: .IP # nice -n 19 goaccess -f access.log -a .P -and if you don't want to install it on your server, you can still run it -from your local machine: +and if you don't want to install it on your server, you can still run it from +your local machine: .IP -# ssh root@server 'cat /var/log/apache2/access.log' | goaccess -a +# ssh -n root@server 'tail -f /var/log/apache2/access.log' | goaccess - +.P +Note: SSH requires +.I -n +so GoAccess can read from stdin. Also, make sure to use SSH keys for +authentication as it won't work if a passphrase is required. +.SS +INCREMENTAL LOG PROCESSING +.P +GoAccess has the ability to process logs incrementally through its internal +storage and dump its data to disk. It works in the following way: + +.nr step 1 1 +.IP \n[step] 3 +A dataset must be persisted first with +.I --persist, +then the same dataset can be loaded with +.IP \n+[step] +.I --restore. +If new data is passed (piped or through a log file), it will append it to the +original dataset. + +.P +NOTES + +GoAccess keeps track of inodes of all the files processed (assuming files will +stay on the same partition), in addition, it extracts a snippet of data from +the log along with the last line parsed of each file and the timestamp of the +last line parsed. e.g., +inode:29627417|line:20012|ts:20171231235059 + +First it compares if the snippet matches the log being parsed, if it does, it +assumes the log hasn't changed dramatically, e.g., hasn't been truncated. If +the inode does not match the current file, it parses all lines. If the current +file matches the inode, it then reads the remaining lines and updates the count +of lines parsed and the timestamp. As an extra precaution, it won't parse log +lines with a timestamp ≤ than the one stored. + +Piped data works based off the timestamp of the last line read. For instance, +it will parse and discard all incoming entries until it finds a timestamp >= +than the one stored. + +.P +For instance: +.IP +// last month access log +.br +# goaccess access.log.1 --persist +.P +then, load it with +.IP +// append this month access log, and preserve new data +.br +# goaccess access.log --restore --persist +.P +To read persisted data only (without parsing new data) +.IP +# goaccess --restore .P .SH NOTES -For now, each active window has a total of 300 items. Eventually this will be -customizable. +Each active panel has a total of 366 items or 50 in the real-time HTML report. +The number of items is customizable using +.I max-items +Note that HTML, CSV and JSON output allow a maximum number greater than the +default value of 366 items per panel. +.P +A hit is a request (line in the access log), e.g., 10 requests = 10 hits. HTTP +requests with the same IP, date, and user agent are considered a unique visit. +.P + +If you want to enable dual-stack support, please use +.I --addr=:: +instead of the default +.I --addr=0.0.0.0. .P -Piping a log to GoAccess will disable the real-time functionality. This is due -to the portability issue on determining the actual size of STDIN. However, a -future release *might* include this feature. +The generated report will attempt to reconnect to the WebSocket server after 1 +second with exponential backoff. It will attempt to connect 20 times. .SH BUGS If you think you have found a bug, please send me an email to .I goaccess@prosoftcorp.com or use the issue tracker in https://github.com/allinurl/goaccess/issues .SH AUTHOR -Gerardo Orellana <goaccess@prosoftcorp.com> +Gerardo Orellana <hello@goaccess.io> For more details about it, or new releases, please visit -http://goaccess.prosoftcorp.com +https://goaccess.io diff --git a/goaccess.c b/goaccess.c deleted file mode 100644 index 9ed0db3318..0000000000 --- a/goaccess.c +++ /dev/null @@ -1,908 +0,0 @@ -/** - * goaccess.c -- main log analyzer - * Copyright (C) 2009-2014 by Gerardo Orellana <goaccess@prosoftcorp.com> - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#define _LARGEFILE_SOURCE -#define _LARGEFILE64_SOURCE -#define _FILE_OFFSET_BITS 64 - -#include <assert.h> -#include <ctype.h> -#include <errno.h> - -#include <locale.h> - -#if HAVE_CONFIG_H -#include <config.h> -#endif - -#include <pthread.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <unistd.h> - -#ifdef HAVE_LIBTOKYOCABINET -#include "tcabinet.h" -#else -#include "glibht.h" -#endif - -#ifdef HAVE_LIBGEOIP -#include "geolocation.h" -#endif - -#include "commons.h" -#include "csv.h" -#include "error.h" -#include "gdashboard.h" -#include "gdns.h" -#include "json.h" -#include "options.h" -#include "output.h" -#include "parser.h" -#include "settings.h" -#include "ui.h" -#include "util.h" - -static WINDOW *header_win, *main_win; - -GConf conf = { 0 }; - -int active_gdns = 0; -static GDash *dash; -static GHolder *holder; -static GLog *logger; -GSpinner *parsing_spinner; - -/* *INDENT-OFF* */ -static GSort sort[TOTAL_MODULES] = { - {VISITORS , SORT_BY_DATA, SORT_DESC}, - {REQUESTS , SORT_BY_HITS, SORT_DESC}, - {REQUESTS_STATIC , SORT_BY_HITS, SORT_DESC}, - {NOT_FOUND , SORT_BY_HITS, SORT_DESC}, - {HOSTS , SORT_BY_HITS, SORT_DESC}, - {OS , SORT_BY_HITS, SORT_DESC}, - {BROWSERS , SORT_BY_HITS, SORT_DESC}, - {REFERRERS , SORT_BY_HITS, SORT_DESC}, - {REFERRING_SITES , SORT_BY_HITS, SORT_DESC}, - {KEYPHRASES , SORT_BY_HITS, SORT_DESC}, -#ifdef HAVE_LIBGEOIP - {GEO_LOCATION , SORT_BY_HITS, SORT_DESC}, -#endif - {STATUS_CODES , SORT_BY_HITS, SORT_DESC}, -}; - -static GScrolling scrolling = { - { - {0, 0}, /* visitors {scroll, offset} */ - {0, 0}, /* requests {scroll, offset} */ - {0, 0}, /* req static {scroll, offset} */ - {0, 0}, /* not found {scroll, offset} */ - {0, 0}, /* hosts {scroll, offset} */ - {0, 0}, /* os {scroll, offset} */ - {0, 0}, /* browsers {scroll, offset} */ - {0, 0}, /* referrers {scroll, offset} */ - {0, 0}, /* ref sites {scroll, offset} */ - {0, 0}, /* keywords {scroll, offset} */ -#ifdef HAVE_LIBGEOIP - {0, 0}, /* geolocation {scroll, offset} */ -#endif - {0, 0}, /* status {scroll, offset} */ - }, - 0, /* current module */ - 0, /* main dashboard scroll */ - 0, /* expanded flag */ -}; -/* *INDENT-ON* */ - -static void -house_keeping (void) -{ - /* REVERSE DNS THREAD */ - pthread_mutex_lock (&gdns_thread.mutex); - /* kill dns pthread */ - active_gdns = 0; - free_holder (&holder); - gdns_free_queue (); - if (ht_hostnames != NULL) { -#ifdef HAVE_LIBTOKYOCABINET - tc_db_close (ht_hostnames, DB_HOSTNAMES); -#else - g_hash_table_destroy (ht_hostnames); -#endif - } - pthread_mutex_unlock (&gdns_thread.mutex); - - /* DASHBOARD */ - if (dash && !conf.output_html) { - free_dashboard (dash); - reset_find (); - } - - /* GEOLOCATION */ -#ifdef HAVE_LIBGEOIP - if (geo_location_data != NULL) - GeoIP_delete (geo_location_data); -#endif - - /* STORAGE */ -#ifdef HAVE_LIBTOKYOCABINET -#ifdef HAVE_LIBGEOIP - tc_db_close (ht_countries, DB_COUNTRIES); -#endif -#ifdef TCB_BTREE - tc_db_close (ht_general_stats, DB_GENERAL_STATS); -#endif - tc_db_close (ht_browsers, DB_BROWSERS); - tc_db_close (ht_date_bw, DB_DATE_BW); - tc_db_close (ht_file_bw, DB_FILE_BW); - tc_db_close (ht_file_serve_usecs, DB_FILE_SERVE_USECS); - tc_db_close (ht_host_bw, DB_HOST_BW); - tc_db_close (ht_hosts_agents, DB_HOST_AGENTS); - tc_db_close (ht_hosts, DB_HOSTS); - tc_db_close (ht_host_serve_usecs, DB_HOST_SERVE_USECS); - tc_db_close (ht_keyphrases, DB_KEYPHRASES); - tc_db_close (ht_not_found_requests, DB_NOT_FOUND_REQUESTS); - tc_db_close (ht_os, DB_OS); - tc_db_close (ht_referrers, DB_REFERRERS); - tc_db_close (ht_referring_sites, DB_REFERRING_SITES); - tc_db_close (ht_request_keys, DB_REQUEST_KEYS); - tc_db_close (ht_request_methods, DB_REQUEST_METHODS); - tc_db_close (ht_request_protocols, DB_REQUEST_PROTOCOLS); - tc_db_close (ht_requests, DB_REQUESTS); - tc_db_close (ht_requests_static, DB_REQUESTS_STATIC); - tc_db_close (ht_status_code, DB_STATUS_CODE); - tc_db_close (ht_unique_vis, DB_UNIQUE_VIS); - tc_db_close (ht_unique_visitors, DB_UNIQUE_VISITORS); -#else -#ifdef HAVE_LIBGEOIP - g_hash_table_foreach (ht_countries, free_countries, NULL); -#endif - g_hash_table_foreach (ht_os, free_os, NULL); - g_hash_table_foreach (ht_browsers, free_browser, NULL); - - g_hash_table_destroy (ht_browsers); - g_hash_table_destroy (ht_countries); - g_hash_table_destroy (ht_date_bw); - g_hash_table_destroy (ht_file_bw); - g_hash_table_destroy (ht_host_bw); - g_hash_table_destroy (ht_hosts); - g_hash_table_destroy (ht_keyphrases); - g_hash_table_destroy (ht_not_found_requests); - g_hash_table_destroy (ht_os); - g_hash_table_destroy (ht_referrers); - g_hash_table_destroy (ht_referring_sites); - g_hash_table_destroy (ht_requests); - g_hash_table_destroy (ht_requests_static); - g_hash_table_destroy (ht_status_code); - g_hash_table_destroy (ht_unique_vis); - g_hash_table_destroy (ht_unique_visitors); -#endif - - /* LOGGER */ - free (logger); - - /* CONFIGURATION */ - if (conf.debug_log) { - LOG_DEBUG (("Bye.\n")); - dbg_log_close (); - } - free_cmd_args (); -} - -/* allocate memory for an instance of holder */ -static void -allocate_holder_by_module (GModule module) -{ -#ifdef TCB_BTREE - TCBDB *ht = NULL; -#elif TCB_MEMHASH - TCMDB *ht = NULL; -#else - GHashTable *ht; -#endif - - GRawData *raw_data; - unsigned int ht_size = 0; - - /* extract data from the corresponding hash table */ - ht = get_ht_by_module (module); - ht_size = get_ht_size_by_module (module); - raw_data = parse_raw_data (ht, ht_size, module); - load_data_to_holder (raw_data, holder + module, module, sort[module]); -} - -/* allocate memory for an instance of holder */ -static void -allocate_holder (void) -{ -#ifdef TCB_BTREE - TCBDB *ht = NULL; -#elif TCB_MEMHASH - TCMDB *ht = NULL; -#else - GHashTable *ht; -#endif - - GModule module; - GRawData *raw_data; - int i; - unsigned int ht_size = 0; - - holder = new_gholder (TOTAL_MODULES); - for (i = 0; i < TOTAL_MODULES; i++) { - module = i; - - /* extract data from the corresponding hash table */ - ht = get_ht_by_module (module); - ht_size = get_ht_size_by_module (module); - raw_data = parse_raw_data (ht, ht_size, module); - load_data_to_holder (raw_data, holder + module, module, sort[module]); - } -} - -/* allocate memory for an instance of dashboard */ -static void -allocate_data (void) -{ - int col_data = DASH_COLLAPSED - DASH_NON_DATA; - int size = 0, ht_size = 0; - - int i; - GModule module; - - dash = new_gdash (); - for (i = 0; i < TOTAL_MODULES; i++) { - module = i; - - switch (module) { - case VISITORS: - dash->module[module].head = VISIT_HEAD; - dash->module[module].desc = VISIT_DESC; - break; - case REQUESTS: - dash->module[module].head = REQUE_HEAD; - dash->module[module].desc = REQUE_DESC; - break; - case REQUESTS_STATIC: - dash->module[module].head = STATI_HEAD; - dash->module[module].desc = STATI_DESC; - break; - case NOT_FOUND: - dash->module[module].head = FOUND_HEAD; - dash->module[module].desc = FOUND_DESC; - break; - case HOSTS: - dash->module[module].head = HOSTS_HEAD; - dash->module[module].desc = HOSTS_DESC; - break; - case OS: - dash->module[module].head = OPERA_HEAD; - dash->module[module].desc = OPERA_DESC; - break; - case BROWSERS: - dash->module[module].head = BROWS_HEAD; - dash->module[module].desc = BROWS_DESC; - break; - case REFERRERS: - dash->module[module].head = REFER_HEAD; - dash->module[module].desc = REFER_DESC; - break; - case REFERRING_SITES: - dash->module[module].head = SITES_HEAD; - dash->module[module].desc = SITES_DESC; - break; - case KEYPHRASES: - dash->module[module].head = KEYPH_HEAD; - dash->module[module].desc = KEYPH_DESC; - break; -#ifdef HAVE_LIBGEOIP - case GEO_LOCATION: - dash->module[module].head = GEOLO_HEAD; - dash->module[module].desc = GEOLO_DESC; - break; -#endif - case STATUS_CODES: - dash->module[module].head = CODES_HEAD; - dash->module[module].desc = CODES_DESC; - break; - } - - ht_size = get_ht_size_by_module (module); - size = ht_size > col_data ? col_data : ht_size; - if ((size > MAX_CHOICES) || - (scrolling.expanded && module == scrolling.current)) - size = MAX_CHOICES; - - dash->module[module].alloc_data = size; /* data allocated */ - dash->module[module].ht_size = ht_size; /* hash table size */ - dash->module[module].idx_data = 0; - dash->module[module].pos_y = 0; - - if (scrolling.expanded && module == scrolling.current) - dash->module[module].dash_size = DASH_EXPANDED; - else - dash->module[module].dash_size = DASH_COLLAPSED; - dash->total_alloc += dash->module[module].dash_size; - - pthread_mutex_lock (&gdns_thread.mutex); - load_data_to_dash (&holder[module], dash, module, &scrolling); - pthread_mutex_unlock (&gdns_thread.mutex); - } -} - -/* render all windows */ -static void -render_screens (void) -{ - int row, col, chg = 0; - - getmaxyx (stdscr, row, col); - term_size (main_win); - - generate_time (); - chg = logger->process - logger->offset; - - draw_header (stdscr, "", "%s", row - 1, 0, col, 0); - wattron (stdscr, COLOR_PAIR (COL_WHITE)); - mvaddstr (row - 1, 1, "[F1]Help [O]pen detail view"); - mvprintw (row - 1, 30, "%d - %s", chg, asctime (now_tm)); - mvaddstr (row - 1, col - 21, "[Q]uit GoAccess"); - mvprintw (row - 1, col - 5, "%s", GO_VERSION); - wattroff (stdscr, COLOR_PAIR (COL_WHITE)); - refresh (); - - /* call general stats header */ - display_general (header_win, conf.ifile, logger->piping, logger->process, - logger->invalid, logger->resp_size); - wrefresh (header_win); - - /* display active label based on current module */ - update_active_module (header_win, scrolling.current); - - display_content (main_win, logger, dash, &scrolling); -} - -/* collapse the current expanded module */ -static void -collapse_current_module (void) -{ - if (scrolling.expanded) { - scrolling.expanded = 0; - reset_scroll_offsets (&scrolling); - free_dashboard (dash); - allocate_data (); - render_screens (); - } -} - -static void -set_module_to (GScrolling * scrll, GModule module) -{ - /* reset expanded module */ - collapse_current_module (); - scrll->current = module; - render_screens (); -} - -static void -get_keys (void) -{ - int search; - int c, quit = 1, scrll, offset, ok_mouse; - int *scroll_ptr, *offset_ptr; - int exp_size = DASH_EXPANDED - DASH_NON_DATA; - MEVENT event; - - char buf[LINE_BUFFER]; - FILE *fp = NULL; - unsigned long long size1 = 0, size2 = 0; - - if (!logger->piping) - size1 = file_size (conf.ifile); - while (quit) { - c = wgetch (stdscr); - switch (c) { - case 'q': /* quit */ - if (!scrolling.expanded) { - quit = 0; - break; - } - collapse_current_module (); - break; - case KEY_F (1): - case '?': - case 'h': - load_help_popup (main_win); - render_screens (); - break; - case 49: /* 1 */ - /* reset expanded module */ - set_module_to (&scrolling, VISITORS); - break; - case 50: /* 2 */ - /* reset expanded module */ - set_module_to (&scrolling, REQUESTS); - break; - case 51: /* 3 */ - /* reset expanded module */ - set_module_to (&scrolling, REQUESTS_STATIC); - break; - case 52: /* 4 */ - /* reset expanded module */ - set_module_to (&scrolling, NOT_FOUND); - break; - case 53: /* 5 */ - /* reset expanded module */ - set_module_to (&scrolling, HOSTS); - break; - case 54: /* 6 */ - /* reset expanded module */ - set_module_to (&scrolling, OS); - break; - case 55: /* 7 */ - /* reset expanded module */ - set_module_to (&scrolling, BROWSERS); - break; - case 56: /* 8 */ - /* reset expanded module */ - set_module_to (&scrolling, REFERRERS); - break; - case 57: /* 9 */ - /* reset expanded module */ - set_module_to (&scrolling, REFERRING_SITES); - break; - case 48: /* 0 */ - /* reset expanded module */ - set_module_to (&scrolling, KEYPHRASES); - break; - case 33: /* Shift+1 */ - /* reset expanded module */ -#ifdef HAVE_LIBGEOIP - set_module_to (&scrolling, GEO_LOCATION); -#else - set_module_to (&scrolling, STATUS_CODES); -#endif - break; -#ifdef HAVE_LIBGEOIP - case 64: /* Shift+2 */ - /* reset expanded module */ - set_module_to (&scrolling, STATUS_CODES); - break; -#endif - case 9: /* TAB */ - /* reset expanded module */ - collapse_current_module (); - scrolling.current++; - if (scrolling.current == TOTAL_MODULES) - scrolling.current = 0; - render_screens (); - break; - case 353: /* Shift TAB */ - /* reset expanded module */ - collapse_current_module (); - if (scrolling.current == 0) - scrolling.current = TOTAL_MODULES - 1; - else - scrolling.current--; - render_screens (); - break; - case 'g': /* g = top */ - if (!scrolling.expanded) - scrolling.dash = 0; - else { - scrolling.module[scrolling.current].scroll = 0; - scrolling.module[scrolling.current].offset = 0; - } - display_content (main_win, logger, dash, &scrolling); - break; - case 'G': /* G = down */ - if (!scrolling.expanded) - scrolling.dash = dash->total_alloc - real_size_y; - else { - scrll = offset = 0; - scrll = dash->module[scrolling.current].idx_data - 1; - if (scrll >= exp_size && scrll >= offset + exp_size) - offset = scrll < exp_size - 1 ? 0 : scrll - exp_size + 1; - scrolling.module[scrolling.current].scroll = scrll; - scrolling.module[scrolling.current].offset = offset; - } - display_content (main_win, logger, dash, &scrolling); - break; - /* expand dashboard module */ - case KEY_RIGHT: - case 0x0a: - case 0x0d: - case 32: /* ENTER */ - case 79: /* o */ - case 111: /* O */ - case KEY_ENTER: - if (scrolling.expanded && scrolling.current == HOSTS) { - /* make sure we have a valid IP */ - int sel = scrolling.module[scrolling.current].scroll; - if (!invalid_ipaddr (dash->module[HOSTS].data[sel].data)) - load_agent_list (main_win, dash->module[HOSTS].data[sel].data); - break; - } - if (scrolling.expanded) - break; - reset_scroll_offsets (&scrolling); - scrolling.expanded = 1; - - free_holder_by_module (&holder, scrolling.current); - free_dashboard (dash); - allocate_holder_by_module (scrolling.current); - allocate_data (); - - display_content (main_win, logger, dash, &scrolling); - break; - case KEY_DOWN: /* scroll main dashboard */ - if ((scrolling.dash + real_size_y) < (unsigned) dash->total_alloc) { - scrolling.dash++; - display_content (main_win, logger, dash, &scrolling); - } - break; - case KEY_MOUSE: /* handles mouse events */ - ok_mouse = getmouse (&event); - if (conf.mouse_support && ok_mouse == OK) { - if (event.bstate & BUTTON1_CLICKED) { - /* ignore header/footer clicks */ - if (event.y < MAX_HEIGHT_HEADER || event.y == LINES - 1) - break; - - if (set_module_from_mouse_event (&scrolling, dash, event.y)) - break; - reset_scroll_offsets (&scrolling); - scrolling.expanded = 1; - - free_holder_by_module (&holder, scrolling.current); - free_dashboard (dash); - allocate_holder_by_module (scrolling.current); - allocate_data (); - - render_screens (); - } - } - break; - case 106: /* j - DOWN expanded module */ - scroll_ptr = &scrolling.module[scrolling.current].scroll; - offset_ptr = &scrolling.module[scrolling.current].offset; - - if (!scrolling.expanded) - break; - if (*scroll_ptr >= dash->module[scrolling.current].idx_data - 1) - break; - ++(*scroll_ptr); - if (*scroll_ptr >= exp_size && *scroll_ptr >= *offset_ptr + exp_size) - ++(*offset_ptr); - display_content (main_win, logger, dash, &scrolling); - break; - /* scroll up main_win */ - case KEY_UP: - if (scrolling.dash > 0) { - scrolling.dash--; - display_content (main_win, logger, dash, &scrolling); - } - break; - case 2: /* ^ b - page up */ - case 339: /* ^ PG UP */ - scroll_ptr = &scrolling.module[scrolling.current].scroll; - offset_ptr = &scrolling.module[scrolling.current].offset; - - if (!scrolling.expanded) - break; - /* decrease scroll and offset by exp_size */ - *scroll_ptr -= exp_size; - if (*scroll_ptr < 0) - *scroll_ptr = 0; - - if (*scroll_ptr < *offset_ptr) - *offset_ptr -= exp_size; - if (*offset_ptr <= 0) - *offset_ptr = 0; - display_content (main_win, logger, dash, &scrolling); - break; - case 6: /* ^ f - page down */ - case 338: /* ^ PG DOWN */ - scroll_ptr = &scrolling.module[scrolling.current].scroll; - offset_ptr = &scrolling.module[scrolling.current].offset; - - if (!scrolling.expanded) - break; - - *scroll_ptr += exp_size; - if (*scroll_ptr >= dash->module[scrolling.current].idx_data - 1) - *scroll_ptr = dash->module[scrolling.current].idx_data - 1; - if (*scroll_ptr >= exp_size && *scroll_ptr >= *offset_ptr + exp_size) - *offset_ptr += exp_size; - if (*offset_ptr + exp_size >= - dash->module[scrolling.current].idx_data - 1) - *offset_ptr = dash->module[scrolling.current].idx_data - exp_size; - if (*scroll_ptr < exp_size - 1) - *offset_ptr = 0; - - display_content (main_win, logger, dash, &scrolling); - break; - case 107: /* k - UP expanded module */ - scroll_ptr = &scrolling.module[scrolling.current].scroll; - offset_ptr = &scrolling.module[scrolling.current].offset; - - if (!scrolling.expanded) - break; - if (*scroll_ptr <= 0) - break; - --(*scroll_ptr); - if (*scroll_ptr < *offset_ptr) - --(*offset_ptr); - display_content (main_win, logger, dash, &scrolling); - break; - case 'n': - pthread_mutex_lock (&gdns_thread.mutex); - search = perform_next_find (holder, &scrolling); - pthread_mutex_unlock (&gdns_thread.mutex); - if (search == 0) { - free_dashboard (dash); - allocate_data (); - render_screens (); - } - break; - case '/': - if (render_find_dialog (main_win, &scrolling)) - break; - pthread_mutex_lock (&gdns_thread.mutex); - search = perform_next_find (holder, &scrolling); - pthread_mutex_unlock (&gdns_thread.mutex); - if (search == 0) { - free_dashboard (dash); - allocate_data (); - render_screens (); - } - break; - case 99: /* c */ - if (conf.no_color) - break; - load_schemes_win (main_win); - free_dashboard (dash); - allocate_data (); - render_screens (); - break; - case 115: /* s */ - load_sort_win (main_win, scrolling.current, &sort[scrolling.current]); - pthread_mutex_lock (&gdns_thread.mutex); - free_holder (&holder); - pthread_cond_broadcast (&gdns_thread.not_empty); - pthread_mutex_unlock (&gdns_thread.mutex); - free_dashboard (dash); - allocate_holder (); - allocate_data (); - render_screens (); - break; - case 269: - case KEY_RESIZE: - endwin (); - refresh (); - werase (header_win); - werase (main_win); - werase (stdscr); - term_size (main_win); - refresh (); - render_screens (); - break; - default: - if (logger->piping) - break; - size2 = file_size (conf.ifile); - - /* file has changed */ - if (size2 != size1) { - if (!(fp = fopen (conf.ifile, "r"))) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Unable to read log file."); - if (!fseeko (fp, size1, SEEK_SET)) - while (fgets (buf, LINE_BUFFER, fp) != NULL) - parse_log (&logger, buf, -1); - fclose (fp); - - size1 = size2; - pthread_mutex_lock (&gdns_thread.mutex); - free_holder (&holder); - pthread_cond_broadcast (&gdns_thread.not_empty); - pthread_mutex_unlock (&gdns_thread.mutex); - - free_dashboard (dash); - allocate_holder (); - allocate_data (); - - term_size (main_win); - render_screens (); - usleep (200000); /* 0.2 seconds */ - } - break; - } - } -} - -static void -set_general_stats (void) -{ - logger->process = logger->invalid = 0; -#ifdef TCB_BTREE - logger->invalid = tc_db_get_int (ht_general_stats, "failed_requests"); - logger->process = tc_db_get_int (ht_general_stats, "total_requests"); - logger->resp_size = tc_db_get_uint64 (ht_general_stats, "bandwidth"); - if (logger->resp_size > 0) - conf.bandwidth = 1; - if (get_ht_size (ht_file_serve_usecs) > 0) - conf.serve_usecs = 1; -#endif -} - -#ifdef HAVE_LIBGEOIP -static void -init_geoip (void) -{ - /* open custom GeoIP database */ - if (conf.geoip_city_data != NULL) - geo_location_data = geoip_open_db (conf.geoip_city_data); - /* fall back to legacy GeoIP database */ - else - geo_location_data = GeoIP_new (conf.geo_db); -} -#endif - -static void -set_locale (void) -{ - char *loc_ctype; - - loc_ctype = getenv ("LC_CTYPE"); - if (loc_ctype != NULL) - setlocale (LC_CTYPE, loc_ctype); - else if ((loc_ctype = getenv ("LC_ALL"))) - setlocale (LC_CTYPE, loc_ctype); - else - setlocale (LC_CTYPE, ""); - setlocale (LC_NUMERIC, ""); -} - -static void -parse_cmd_line (int argc, char **argv) -{ - read_option_args (argc, argv); - - if (!isatty (STDOUT_FILENO) || conf.output_format != NULL) - conf.output_html = 1; - if (conf.ifile != NULL && !isatty (STDIN_FILENO) && !conf.output_html) - cmd_help (); - if (conf.ifile == NULL && isatty (STDIN_FILENO) && conf.output_format == NULL) - cmd_help (); -} - -int -main (int argc, char **argv) -{ - int quit = 0; - - /* command line/config options */ - verify_global_config (argc, argv); - parse_conf_file (&argc, &argv); - parse_cmd_line (argc, argv); - - /* initialize storage */ - init_storage (); - /* setup to use the current locale */ - set_locale (); - -#ifdef HAVE_LIBGEOIP - init_geoip (); -#endif - - /* init logger */ - logger = init_log (); - /* init parsing spinner */ - parsing_spinner = new_gspinner (); - parsing_spinner->process = &logger->process; - - /* outputting to stdout */ - if (conf.output_html) { - ui_spinner_create (parsing_spinner); - goto out; - } - - /* init curses */ - set_input_opts (); - if (conf.no_color || has_colors () == FALSE) { - conf.color_scheme = NO_COLOR; - conf.no_color = 1; - } else { - start_color (); - } - init_colors (); - init_windows (&header_win, &main_win); - set_curses_spinner (parsing_spinner); - - /* configuration dialog */ - if (isatty (STDIN_FILENO) && (conf.log_format == NULL || conf.load_conf_dlg)) { - refresh (); - quit = verify_format (logger, parsing_spinner); - } - /* straight parsing */ - else { - ui_spinner_create (parsing_spinner); - } - -out: - - /* main processing event */ - time (&start_proc); - if (conf.load_from_disk) - set_general_stats (); - else if (!quit && parse_log (&logger, NULL, -1)) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Error while processing file"); - - logger->offset = logger->process; - - /* no valid entries to process from the log */ - if ((logger->process == 0) || (logger->process == logger->invalid)) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Nothing valid to process."); - - /* init reverse lookup thread */ - gdns_init (); - allocate_holder (); - - end_spinner (); - time (&end_proc); - - /* stdout */ - if (conf.output_html) { - /* CSV */ - if (conf.output_format && strcmp ("csv", conf.output_format) == 0) - output_csv (logger, holder); - /* JSON */ - else if (conf.output_format && strcmp ("json", conf.output_format) == 0) - output_json (logger, holder); - /* HTML */ - else - output_html (logger, holder); - } - /* curses */ - else { - allocate_data (); - if (!conf.skip_term_resolver) - gdns_thread_create (); - - render_screens (); - get_keys (); - - attroff (COLOR_PAIR (COL_WHITE)); - /* restore tty modes and reset - * terminal into non-visual mode */ - endwin (); - } - /* clean */ - house_keeping (); - - return EXIT_SUCCESS; -} diff --git a/goaccess.h b/goaccess.h deleted file mode 100644 index 3883ca3059..0000000000 --- a/goaccess.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana <goaccess@prosoftcorp.com> - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#ifndef GOACCESS_H_INCLUDED -#define GOACCESS_H_INCLUDED - -#include "ui.h" - -extern GSpinner *parsing_spinner; -extern int active_gdns; /* kill dns pthread flag */ -void render_screens (void); - -#endif diff --git a/inlang.config.js b/inlang.config.js new file mode 100644 index 0000000000..23b93e0a9e --- /dev/null +++ b/inlang.config.js @@ -0,0 +1,46 @@ +// init the inlang.config + +/** + * @type {import("@inlang/core/config").DefineConfig} + */ +export async function defineConfig(env) { + // importing plugin from local file for testing purposes + const plugin = await env.$import( + "https://cdn.jsdelivr.net/gh/jannesblobel/inlang-plugin-po@1/dist/index.js" + ); + const pluginConfig = { + // language mean the name of you file + pathPattern: "./po/{language}.po", + referenceResourcePath: "./po/goaccess.pot", + }; + + return { + // if your project use a pot file use the pot as the reference Language + // !! do not add the pot file in the Languages array + /** + * @example + * example files: en.pot, de.po, es.po, fr.po + * referenceLanguage: "en", + languages: ["de","es","fr"], + */ + referenceLanguage: "en", + languages: await getLanguages(env), + readResources: (args) => + plugin.readResources({ ...args, ...env, pluginConfig }), + writeResources: (args) => + plugin.writeResources({ ...args, ...env, pluginConfig }), + }; +} + +/** + * Automatically derives the languages in this repository. + */ +async function getLanguages(env) { + const files = await env.$fs.readdir("./po"); + // files that end with .json + // remove the .json extension to only get language name + const languages = files + .filter((name) => name.endsWith(".po")) + .map((name) => name.replace(".po", "")); + return languages; +} diff --git a/json.c b/json.c deleted file mode 100644 index 411e6df79e..0000000000 --- a/json.c +++ /dev/null @@ -1,396 +0,0 @@ -/** - * output.c -- output json to the standard output stream - * Copyright (C) 2009-2014 by Gerardo Orellana <goaccess@prosoftcorp.com> - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ -#define _LARGEFILE_SOURCE -#define _LARGEFILE64_SOURCE -#define _FILE_OFFSET_BITS 64 - -#include <ctype.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/stat.h> -#include <time.h> -#include <unistd.h> -#include <inttypes.h> - -#include "json.h" - -#ifdef HAVE_LIBTOKYOCABINET -#include "tcabinet.h" -#else -#include "glibht.h" -#endif - -#ifdef HAVE_LIBGEOIP -#include "geolocation.h" -#endif - -#include "commons.h" -#include "error.h" -#include "gdns.h" -#include "settings.h" -#include "ui.h" -#include "util.h" -#include "xmalloc.h" - -static void -escape_json_output (FILE * fp, char *s) -{ - while (*s) { - switch (*s) { - case '"': - fprintf (fp, "\\\""); - break; - case '\\': - fprintf (fp, "\\\\"); - break; - /* unusual to be on a log */ - case '\b': - fprintf (fp, "\\\b"); - break; - case '\f': - fprintf (fp, "\\\f"); - break; - case '\n': - fprintf (fp, "\\\n"); - break; - case '\r': - fprintf (fp, "\\\r"); - break; - case '\t': - fprintf (fp, "\\\t"); - break; - /* TODO: escape four-hex-digits, \u */ - default: - fputc (*s, fp); - break; - } - s++; - } -} - -static void -print_json_sub_items (FILE * fp, GSubList * sub_list, int process) -{ - char *data; - float percent; - GSubItem *iter; - int hits, i = 0; - - fprintf (fp, ",\n\t\t\t\"items\": [\n"); - for (iter = sub_list->head; iter; iter = iter->next) { - hits = iter->hits; - data = (char *) iter->data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - - fprintf (fp, "\t\t\t\t{\n"); - fprintf (fp, "\t\t\t\t\t\"hits\": \"%d\",\n", hits); - fprintf (fp, "\t\t\t\t\t\"percent\": \"%4.2f%%\",\n", percent); - fprintf (fp, "\t\t\t\t\t\"data\": \""); - escape_json_output (fp, data); - fprintf (fp, "\"\n"); - fprintf (fp, "\t\t\t\t}"); - - if (i != sub_list->size - 1) - fprintf (fp, ",\n"); - else - fprintf (fp, "\n"); - i++; - } - fprintf (fp, "\t\t\t]"); -} - -/** - * Generate JSON on partial fields for the following modules: - * OS, BROWSERS, REFERRERS, REFERRING_SITES, KEYPHRASES, STATUS_CODES - */ -static void -print_json_generic (FILE * fp, const GHolder * h, int process) -{ - char *data; - const char *id = NULL; - float percent; - int i, hits; - - if (h->module == BROWSERS) - id = BROWS_ID; - else if (h->module == OS) - id = OPERA_ID; - else if (h->module == REFERRERS) - id = REFER_ID; - else if (h->module == REFERRING_SITES) - id = SITES_ID; - else if (h->module == KEYPHRASES) - id = KEYPH_ID; - else if (h->module == STATUS_CODES) - id = CODES_ID; -#ifdef HAVE_LIBGEOIP - else if (h->module == GEO_LOCATION) - id = GEOLO_ID; -#endif - - fprintf (fp, "\t\"%s\": [\n", id); - - for (i = 0; i < h->idx; i++) { - hits = h->items[i].hits; - data = h->items[i].data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - - fprintf (fp, "\t\t{\n"); - fprintf (fp, "\t\t\t\"hits\": \"%d\",\n", hits); - fprintf (fp, "\t\t\t\"percent\": \"%4.2f%%\",\n", percent); - fprintf (fp, "\t\t\t\"data\": \""); - escape_json_output (fp, data); - fprintf (fp, "\""); - - if (h->module == OS || h->module == BROWSERS || h->module == STATUS_CODES -#ifdef HAVE_LIBGEOIP - || h->module == GEO_LOCATION -#endif - ) - print_json_sub_items (fp, h->items[i].sub_list, process); - - fprintf (fp, "\n\t\t}"); - - if (i != h->idx - 1) - fprintf (fp, ",\n"); - else - fprintf (fp, "\n"); - } - fprintf (fp, "\n\t]"); -} - -/** - * Generate JSON on complete fields for the following modules: - * REQUESTS, REQUESTS_STATIC, NOT_FOUND, HOSTS - */ -static void -print_json_complete (FILE * fp, GHolder * holder, int process) -{ -#ifdef HAVE_LIBGEOIP - char country[COUNTRY_LEN] = ""; - char city[CITY_LEN] = ""; -#endif - - char *data, *host, *method = NULL, *protocol = NULL; - float percent; - GHolder *h; - int i, j, hits; - unsigned long long bw, usecs; - - for (i = 0; i < 4; i++) { - switch (i) { - case 0: - h = holder + REQUESTS; - fprintf (fp, "\t\"%s\": [\n", REQUE_ID); - break; - case 1: - h = holder + REQUESTS_STATIC; - fprintf (fp, "\t\"%s\": [\n", STATI_ID); - break; - case 2: - h = holder + NOT_FOUND; - fprintf (fp, "\t\"%s\": [\n", FOUND_ID); - break; - case 3: - h = holder + HOSTS; - fprintf (fp, "\t\"%s\": [\n", HOSTS_ID); - break; - } - - for (j = 0; j < h->idx; j++) { - hits = h->items[j].hits; - data = h->items[j].data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - bw = h->items[j].bw; - usecs = h->items[j].usecs; - method = h->items[j].method; - protocol = h->items[j].protocol; - - fprintf (fp, "\t\t{\n"); - fprintf (fp, "\t\t\t\"hits\": \"%d\",\n", hits); - fprintf (fp, "\t\t\t\"percent\": \"%4.2f%%\",\n", percent); - fprintf (fp, "\t\t\t\"data\": \""); - escape_json_output (fp, data); - fprintf (fp, "\",\n"); - fprintf (fp, "\t\t\t\"bytes\": \"%lld\"", bw); - - if (h->module == HOSTS) { - if (conf.enable_html_resolver) { - host = reverse_ip (data); - fprintf (fp, ",\n\t\t\t\"host\": \""); - escape_json_output (fp, host); - fprintf (fp, "\""); - free (host); - } -#ifdef HAVE_LIBGEOIP - geoip_get_country (data, country); - fprintf (fp, ",\n\t\t\t\"country\": \""); - escape_json_output (fp, country); - fprintf (fp, "\""); - - if (conf.geoip_city_data) { - geoip_get_city (data, city); - fprintf (fp, ",\n\t\t\t\"city\": \""); - escape_json_output (fp, city); - fprintf (fp, "\""); - } -#endif - } - if (conf.serve_usecs) - fprintf (fp, ",\n\t\t\t\"time_served\": \"%lld\"", usecs); - if (conf.append_protocol && protocol) - fprintf (fp, ",\n\t\t\t\"protocol\": \"%s\"", protocol); - if (conf.append_method && method) - fprintf (fp, ",\n\t\t\t\"method\": \"%s\"", method); - - fprintf (fp, "\n\t\t}"); - - if (j != h->idx - 1) - fprintf (fp, ",\n"); - else - fprintf (fp, "\n"); - } - if (i != 3) - fprintf (fp, "\t],\n"); - else - fprintf (fp, "\t]\n"); - } -} - -/* generate JSON unique visitors stats */ -static void -print_json_visitors (FILE * fp, GHolder * h) -{ - char *data, buf[DATE_LEN]; - float percent; - int hits, bw, i, process = get_ht_size (ht_unique_visitors); - - /* make compiler happy */ - memset (buf, 0, sizeof (buf)); - fprintf (fp, "\t\"%s\": [\n", VISIT_ID); - for (i = 0; i < h->idx; i++) { - hits = h->items[i].hits; - data = h->items[i].data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - bw = h->items[i].bw; - convert_date (buf, data, "%Y%m%d", "%d/%b/%Y", DATE_LEN); - fprintf (fp, "\t\t{\n\t\t\t\"hits\": \"%d\",\n", hits); - fprintf (fp, "\t\t\t\"percent\": \"%4.2f%%\",\n", percent); - fprintf (fp, "\t\t\t\"date\": \"%s\",\n", buf); - fprintf (fp, "\t\t\t\"bytes\": \"%d\"\n", bw); - fprintf (fp, "\t\t}"); - - if (i != h->idx - 1) - fprintf (fp, ",\n"); - else - fprintf (fp, "\n"); - } - fprintf (fp, "\t]"); -} - -/* generate overview stats */ -static void -print_json_summary (FILE * fp, GLog * logger) -{ - off_t log_size = 0; - char now[DATE_TIME]; - - generate_time (); - strftime (now, DATE_TIME, "%Y-%m-%d %H:%M:%S", now_tm); - - fprintf (fp, "\t\"%s\": {\n", GENER_ID); - /* general statistics info */ - fprintf (fp, "\t\t\"date_time\": \"%s\",\n", now); - fprintf (fp, "\t\t\"total_requests\": %d,\n", logger->process); - fprintf (fp, "\t\t\"unique_visitors\": %d,\n", - get_ht_size (ht_unique_visitors)); - fprintf (fp, "\t\t\"referrers\": %d,\n", get_ht_size (ht_referrers)); - - if (!logger->piping) - log_size = file_size (conf.ifile); - - fprintf (fp, "\t\t\"log_size\": %jd,\n", (intmax_t) log_size); - fprintf (fp, "\t\t\"failed_requests\": %d,\n", logger->invalid); - fprintf (fp, "\t\t\"unique_files\": %d,\n", get_ht_size (ht_requests)); - fprintf (fp, "\t\t\"unique_404\": %d,\n", - get_ht_size (ht_not_found_requests)); - - fprintf (fp, "\t\t\"bandwidth\": %lld,\n", logger->resp_size); - fprintf (fp, "\t\t\"generation_time\": %llu,\n", - ((long long) end_proc - start_proc)); - fprintf (fp, "\t\t\"static_files\": %d,\n", get_ht_size (ht_requests_static)); - - if (conf.ifile == NULL) - conf.ifile = (char *) "STDIN"; - - fprintf (fp, "\t\t\"log_file\": \"%s\"\n", conf.ifile); - fprintf (fp, "\t}"); -} - -/* entry point to generate a a json report writing it to the fp */ -/* follow the JSON style similar to http://developer.github.com/v3/ */ -void -output_json (GLog * logger, GHolder * holder) -{ - FILE *fp = stdout; - fprintf (fp, "{\n"); /* open */ - - print_json_summary (fp, logger); - fprintf (fp, ",\n"); - - print_json_visitors (fp, holder + VISITORS); - fprintf (fp, ",\n"); - - print_json_complete (fp, holder, logger->process); - fprintf (fp, ",\n"); - - print_json_generic (fp, holder + OS, get_ht_size (ht_unique_visitors)); - fprintf (fp, ",\n"); - - print_json_generic (fp, holder + BROWSERS, get_ht_size (ht_unique_visitors)); - fprintf (fp, ",\n"); - - print_json_generic (fp, holder + REFERRERS, logger->process); - fprintf (fp, ",\n"); - - print_json_generic (fp, holder + REFERRING_SITES, logger->process); - fprintf (fp, ",\n"); - - print_json_generic (fp, holder + KEYPHRASES, logger->process); - fprintf (fp, ",\n"); - -#ifdef HAVE_LIBGEOIP - print_json_generic (fp, holder + GEO_LOCATION, logger->process); - fprintf (fp, ",\n"); -#endif - - print_json_generic (fp, holder + STATUS_CODES, logger->process); - fprintf (fp, "\n"); - - fprintf (fp, "\n}\n"); /* close */ - - fclose (fp); -} diff --git a/json.h b/json.h deleted file mode 100644 index ea51c5b348..0000000000 --- a/json.h +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana <goaccess@prosoftcorp.com> - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#if HAVE_CONFIG_H -#include <config.h> -#endif - -#ifndef JSON_H_INCLUDED -#define JSON_H_INCLUDED - -#include "commons.h" -#include "parser.h" - -void output_json (GLog * logger, GHolder * holder); - -#endif diff --git a/opesys.c b/opesys.c deleted file mode 100644 index 96206a4da7..0000000000 --- a/opesys.c +++ /dev/null @@ -1,231 +0,0 @@ -/** - * opesys.c -- functions for dealing with operating systems - * Copyright (C) 2009-2014 by Gerardo Orellana <goaccess@prosoftcorp.com> - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#include <ctype.h> -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "opesys.h" - -#include "error.h" -#include "settings.h" -#include "util.h" -#include "xmalloc.h" - -/* {"search string", "belongs to"} */ -static const char *os[][2] = { - {"Windows NT 6.3", "Windows"}, - {"Windows NT 6.2; ARM", "Windows"}, - {"Windows NT 6.2", "Windows"}, - {"Windows NT 6.1", "Windows"}, - {"Windows NT 6.0", "Windows"}, - {"Windows NT 5.2", "Windows"}, - {"Windows NT 5.1", "Windows"}, - {"Windows NT 5.01", "Windows"}, - {"Windows NT 5.0", "Windows"}, - {"Windows NT 4.0", "Windows"}, - {"Win 9x 4.90", "Windows"}, - {"Windows 98", "Windows"}, - {"Windows 95", "Windows"}, - {"Windows CE", "Windows"}, - {"Android", "Android"}, - {"Debian", "Linux"}, - {"Ubuntu", "Linux"}, - {"Fedora", "Linux"}, - {"Mint", "Linux"}, - {"SUSE", "Linux"}, - {"Mandriva", "Linux"}, - {"Red Hat", "Linux"}, - {"Gentoo", "Linux"}, - {"CentOS", "Linux"}, - {"PCLinuxOS", "Linux"}, - {"Linux", "Linux"}, - {"iPad", "Macintosh"}, - {"iPod", "Macintosh"}, - {"iPhone", "Macintosh"}, - {"iTunes", "Macintosh"}, - {"OS X", "Macintosh"}, - {"FreeBSD", "BSD"}, - {"NetBSD", "BSD"}, - {"OpenBSD", "BSD"}, - {"SunOS", "Others"}, - {"AmigaOS", "Others"}, - {"BlackBerry", "Others"}, - {"SymbianOS", "Others"}, - {"Sony", "Others"}, - {"Xbox", "Others"}, - {"Nokia", "Others"}, - {"HUAWEI", "Others"}, - {"PlayStation", "Others"} -}; - -/* get Android Codename */ -static char * -get_real_android (const char *droid) -{ - if (strstr (droid, "4.4")) - return alloc_string ("KitKat"); - else if (strstr (droid, "4.3") || strstr (droid, "4.2") || - strstr (droid, "4.1")) - return alloc_string ("Jelly Bean"); - else if (strstr (droid, "4.0")) - return alloc_string ("Ice Cream Sandwich"); - else if (strstr (droid, "3.")) - return alloc_string ("Honeycomb"); - else if (strstr (droid, "2.3")) - return alloc_string ("Gingerbread"); - else if (strstr (droid, "2.2")) - return alloc_string ("Froyo"); - else if (strstr (droid, "2.0") || strstr (droid, "2.1")) - return alloc_string ("Eclair"); - else if (strstr (droid, "1.6")) - return alloc_string ("Donut"); - else if (strstr (droid, "1.5")) - return alloc_string ("Cupcake"); - return alloc_string (droid); -} - -/* get Windows marketing name */ -static char * -get_real_win (const char *win) -{ - if (strstr (win, "6.3")) - return alloc_string ("Windows 8.1"); - else if (strstr (win, "6.2; ARM")) - return alloc_string ("Windows RT"); - else if (strstr (win, "6.2")) - return alloc_string ("Windows 8"); - else if (strstr (win, "6.1")) - return alloc_string ("Windows 7"); - else if (strstr (win, "6.0")) - return alloc_string ("Windows Vista"); - else if (strstr (win, "5.2")) - return alloc_string ("Windows XP x64"); - else if (strstr (win, "5.1")) - return alloc_string ("Windows XP"); - else if (strstr (win, "5.0")) - return alloc_string ("Windows 2000"); - return NULL; -} - -/* get Mac OS X Codename */ -static char * -get_real_mac_osx (const char *osx) -{ - if (strstr (osx, "10.9")) - return alloc_string ("OS X Mavericks"); - else if (strstr (osx, "10.8")) - return alloc_string ("OS X Mountain Lion"); - else if (strstr (osx, "10.7")) - return alloc_string ("OS X Lion"); - else if (strstr (osx, "10.6")) - return alloc_string ("OS X Snow Leopard"); - else if (strstr (osx, "10.5")) - return alloc_string ("OS X Leopard"); - else if (strstr (osx, "10.4")) - return alloc_string ("OS X Tiger"); - else if (strstr (osx, "10.3")) - return alloc_string ("OS X Panther"); - else if (strstr (osx, "10.2")) - return alloc_string ("OS X Jaguar"); - else if (strstr (osx, "10.1")) - return alloc_string ("OS X Puma"); - else if (strstr (osx, "10.0")) - return alloc_string ("OS X Cheetah"); - return alloc_string (osx); -} - -char * -verify_os (const char *str, char *os_type) -{ - char *a, *b, *p; - const char *lookfor; - int space = 0; - size_t i; - - if (str == NULL || *str == '\0') - return NULL; - - for (i = 0; i < ARRAY_SIZE (os); i++) { - if ((a = strstr (str, os[i][0])) == NULL) - continue; - - /* windows */ - if ((lookfor = "Windows", strstr (str, lookfor)) != NULL) { - xstrncpy (os_type, os[i][1], OPESYS_TYPE_LEN); - return conf.real_os && - (b = get_real_win (a)) ? b : alloc_string (os[i][0]); - } - /* agents w/ space in between */ - if ((lookfor = "iPhone OS", strstr (str, lookfor)) != NULL || - (lookfor = "Red Hat", strstr (str, lookfor)) != NULL || - (lookfor = "Win", strstr (str, lookfor)) != NULL) { - xstrncpy (os_type, os[i][1], OPESYS_TYPE_LEN); - return alloc_string (os[i][0]); - } - /* parse mac os x */ - if ((lookfor = "OS X", strstr (a, lookfor)) != NULL) { - p = a; - while (*p != ';' && *p != ')' && *p != '(' && *p != '\0') { - if (*p == '_') - *p = '.'; - if (*p == ' ') - space++; - if (space > 3) - break; - p++; - } - *p = 0; - - xstrncpy (os_type, os[i][1], OPESYS_TYPE_LEN); - return conf.real_os ? get_real_mac_osx (a) : alloc_string (a); - } - /* parse android */ - if ((lookfor = "Android", strstr (a, lookfor)) != NULL) { - p = a; - while (*p != ';' && *p != ')' && *p != '(' && *p != '\0') - p++; - *p = 0; - - xstrncpy (os_type, os[i][1], OPESYS_TYPE_LEN); - return conf.real_os ? get_real_android (a) : alloc_string (a); - } - if (!(b = a)) - return NULL; - /* all others */ - for (p = a; *p; p++) { - if (*p != ' ' && isalnum (p[0]) && *p != '\0') { - a++; - continue; - } else - break; - } - *p = 0; - - xstrncpy (os_type, os[i][1], OPESYS_TYPE_LEN); - return alloc_string (b); - } - xstrncpy (os_type, "Unknown", OPESYS_TYPE_LEN); - - return alloc_string ("Unknown"); -} diff --git a/opesys.h b/opesys.h deleted file mode 100644 index 3c7a17728f..0000000000 --- a/opesys.h +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana <goaccess@prosoftcorp.com> - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#ifndef OPESYS_H_INCLUDED -#define OPESYS_H_INCLUDED - -char *verify_os (const char *str, char *os_type); - -#endif diff --git a/options.c b/options.c deleted file mode 100644 index 5479c3a3b4..0000000000 --- a/options.c +++ /dev/null @@ -1,376 +0,0 @@ -/** - * options.c -- functions related to parsing program options - * Copyright (C) 2009-2014 by Gerardo Orellana <goaccess@prosoftcorp.com> - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#if HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <getopt.h> -#include <errno.h> - -#ifdef HAVE_LIBTOKYOCABINET -#include "tcabinet.h" -#endif - -#include "options.h" - -#include "error.h" -#include "settings.h" -#include "util.h" - -static char short_options[] = "f:e:p:o:" -#ifdef DEBUG - "l:" -#endif -#ifdef HAVE_LIBGEOIP - "g" -#endif - "acrmMhHqds"; - -/* *INDENT-OFF* */ -struct option long_opts[] = { - {"log-file" , required_argument , 0 , 'f' } , - {"agent-list" , no_argument , 0 , 'a' } , - {"config-dialog" , no_argument , 0 , 'c' } , - {"config-file" , required_argument , 0 , 'p' } , - {"exclude-ip" , required_argument , 0 , 'e' } , - {"help" , no_argument , 0 , 'h' } , - {"http-method" , no_argument , 0 , 'M' } , - {"http-protocol" , no_argument , 0 , 'H' } , -#ifdef DEBUG - {"debug-file" , required_argument , 0 , 'l' } , -#endif - {"no-query-string" , no_argument , 0 , 'q' } , - {"no-term-resolver" , no_argument , 0 , 'r' } , - {"output-format" , required_argument , 0 , 'o' } , - {"color-scheme" , required_argument , 0 , 0 } , - {"date-format" , required_argument , 0 , 0 } , - {"log-format" , required_argument , 0 , 0 } , - {"real-os" , no_argument , 0 , 0 } , - {"no-color" , no_argument , 0 , 0 } , - {"no-global-config" , no_argument , 0 , 0 } , - {"storage" , no_argument , 0 , 's' } , - {"no-progress" , no_argument , 0 , 0 } , - {"with-mouse" , no_argument , 0 , 'm' } , - {"with-output-resolver" , no_argument , 0 , 'd' } , -#ifdef HAVE_LIBGEOIP - {"std-geoip" , no_argument , 0 , 'g' } , - {"geoip-city-data" , required_argument , 0 , 0 } , -#endif -#ifdef TCB_BTREE - {"keep-db-files" , no_argument , 0 , 0 } , - {"load-from-disk" , no_argument , 0 , 0 } , - {"db-path" , required_argument , 0 , 0 } , - {"compression" , required_argument , 0 , 0 } , - {"xmmap" , required_argument , 0 , 0 } , - {"cache-lcnum" , required_argument , 0 , 0 } , - {"cache-ncnum" , required_argument , 0 , 0 } , - {"tune-lmemb" , required_argument , 0 , 0 } , - {"tune-nmemb" , required_argument , 0 , 0 } , - {"tune-bnum" , required_argument , 0 , 0 } , -#endif - {0, 0, 0, 0} -}; -/* *INDENT-ON* */ - -void -cmd_help (void) -{ - printf ("\nGoAccess - %s\n\n", GO_VERSION); - printf ("Usage: "); - printf ("goaccess [ options ... ] -f log_file [-c][-M][-H][-q][-d][...]\n"); - printf ("The following options can also be supplied to the command:\n\n"); - - /* Log & Date Format Options */ - printf ("Log & Date Format Options\n\n"); - printf (" --date-format=<dateformat> - "); - printf ("Specify log date format.\n"); - printf (" --log-format=<logformat> - "); - printf ("Specify log format. Inner quotes need to be escaped.\n\n"); - - /* User Interface Options */ - printf ("User Interface Options\n\n"); - printf (" -c --config-dialog - "); - printf ("Prompt log/date configuration window.\n"); - printf (" --color-scheme=<1|2> - "); - printf ("Color schemes: 1 => Grey scheme, 2 => Green scheme.\n"); - printf (" --no-color - "); - printf ("Disable colored output.\n\n"); - - /* File Options */ - printf ("File Options\n\n"); - printf (" -f --log-file=<filename> - "); - printf ("Path to input log file.\n"); - printf (" -p --config-file=<filename> - "); - printf ("Custom configuration file.\n"); -#ifdef DEBUG - printf (" -l --debug-file=<filename> - "); - printf ("Send all debug messages to the specified file.\n"); -#endif - printf (" --no-global-config - "); - printf ("Do not load the global configuration file.\n\n"); - - /* Parse Options */ - printf ("Parse Options\n\n"); - printf (" -e --exclude-ip=<IP> - "); - printf ("Exclude an IP from being counted.\n"); - printf (" -a --agent-list - "); - printf ("Enable a list of user-agents by host.\n"); - printf (" -M --http-method - "); - printf ("Include HTTP request method if found.\n"); - printf (" -H --http-protocol - "); - printf ("Include HTTP request protocol if found.\n"); - printf (" -q --no-query-string - "); - printf ("Ignore request's query string.\n"); - printf (" -r --no-term-resolver - "); - printf ("Disable IP resolver on terminal output.\n"); - printf (" -o --output-format=csv|json - "); - printf ("Output either a JSON or a CSV file.\n"); - printf (" -m --with-mouse - "); - printf ("Enable mouse support on main dashboard.\n"); - printf (" -d --with-output-resolver - "); - printf ("Enable IP resolver on HTML|JSON output.\n"); - printf (" --real-os - "); - printf ("Display real OS names. e.g, Windows XP, Snow Leopard.\n"); - printf (" --no-progress - "); - printf ("Disable progress metrics.\n\n"); - - /* GeoIP Options */ -#ifdef HAVE_LIBGEOIP - printf ("GeoIP Options\n\n"); - printf (" -g --std-geoip - "); - printf ("Standard GeoIP database for less memory usage.\n"); - printf (" --geoip-city-data=<path> - "); - printf - ("Specify path to GeoIP City database file. i.e., GeoLiteCity.dat\n\n"); -#endif - - /* On-Disk Database Options */ -#ifdef TCB_BTREE - printf ("On-Disk Database Options\n\n"); - printf (" --keep-db-files - "); - printf ("Persist parsed data into disk.\n"); - printf (" --load-from-disk - "); - printf ("Load previously stored data from disk.\n"); - printf (" --db-path=<path> - "); - printf ("Path of the database file. [%s]\n", TC_DBPATH); - printf (" --xmmap=<number> - "); - printf ("Set the size in bytes of the extra mapped memory. [%d]\n", TC_MMAP); - printf (" --cache-lcnum=<number> - "); - printf ("Max number of leaf nodes to be cached. [%d]\n", TC_LCNUM); - printf (" --cache-ncnum=<number> - "); - printf ("Max number of non-leaf nodes to be cached. [%d]\n", TC_NCNUM); - printf (" --tune-lmemb=<number> - "); - printf ("Number of members in each leaf page. [%d]\n", TC_LMEMB); - printf (" --tune-nmemb=<number> - "); - printf ("Number of members in each non-leaf page. [%d]\n", TC_NMEMB); - printf (" --tune-bnum=<number> - "); - printf ("Number of elements of the bucket array. [%d]\n", TC_BNUM); -#if defined(HAVE_ZLIB) || defined(HAVE_BZ2) - printf (" --compression=<zlib|bz2> - "); - printf ("Specifies that each page is compressed with ZLIB|BZ2 encoding.\n\n"); -#endif -#endif - - /* Other Options */ - printf ("Other Options\n\n"); - printf (" -h --help - "); - printf ("This help.\n"); - printf (" -s --storage - "); - printf ("Display current storage method. i.e., B+ Tree, Hash.\n\n"); - - printf ("Examples can be found by running `man goaccess`.\n\n"); - printf ("For more details visit: http://goaccess.prosoftcorp.com\n"); - printf ("GoAccess Copyright (C) 2009-2014 GNU GPL'd, by Gerardo Orellana"); - printf ("\n\n"); - exit (EXIT_FAILURE); -} - -void -verify_global_config (int argc, char **argv) -{ - int o, idx = 0; - - conf.load_global_config = 1; - while ((o = getopt_long (argc, argv, short_options, long_opts, &idx)) >= 0) { - if (-1 == o || EOF == o) - break; - - switch (o) { - case 'p': - conf.iconfigfile = optarg; - break; - case 0: - if (!strcmp ("no-global-config", long_opts[idx].name)) - conf.load_global_config = 0; - break; - case '?': - exit (EXIT_FAILURE); - } - } - for (idx = optind; idx < argc; idx++) - cmd_help (); - - /* reset it to 1 */ - optind = 1; -} - -void -read_option_args (int argc, char **argv) -{ - int o, idx = 0; - -#ifdef HAVE_LIBGEOIP - conf.geo_db = GEOIP_MEMORY_CACHE; -#endif - - while ((o = getopt_long (argc, argv, short_options, long_opts, &idx)) >= 0) { - if (-1 == o || EOF == o) - break; - switch (o) { - case 'f': - conf.ifile = optarg; - break; - case 'p': - /* ignore it */ - break; -#ifdef HAVE_LIBGEOIP - case 'g': - conf.geo_db = GEOIP_STANDARD; - break; -#endif - case 'e': - conf.ignore_host = optarg; - break; - case 'a': - conf.list_agents = 1; - break; - case 'c': - conf.load_conf_dlg = 1; - break; - case 'q': - conf.ignore_qstr = 1; - break; - case 'o': - conf.output_format = optarg; - case 'l': - conf.debug_log = optarg; - dbg_log_open (conf.debug_log); - break; - case 'r': - conf.skip_term_resolver = 1; - break; - case 'd': - conf.enable_html_resolver = 1; - break; - case 'm': - conf.mouse_support = 1; - break; - case 'M': - conf.append_method = 1; - break; - case 'h': - cmd_help (); - break; - case 'H': - conf.append_protocol = 1; - break; - case 0: - - if (!strcmp ("no-global-config", long_opts[idx].name)) - break; /* ignore it */ - - if (!strcmp ("color-scheme", long_opts[idx].name)) - conf.color_scheme = atoi (optarg); - if (!strcmp ("log-format", long_opts[idx].name)) - conf.log_format = unescape_str (optarg); - if (!strcmp ("date-format", long_opts[idx].name)) - conf.date_format = unescape_str (optarg); - - if (!strcmp ("real-os", long_opts[idx].name)) - conf.real_os = 1; - if (!strcmp ("no-color", long_opts[idx].name)) - conf.no_color = 1; - if (!strcmp ("no-progress", long_opts[idx].name)) - conf.no_progress = 1; - - /* specifies the path of the GeoIP City database file */ - if (!strcmp ("geoip-city-data", long_opts[idx].name)) - conf.geoip_city_data = optarg; - - /* load data from disk */ - if (!strcmp ("load-from-disk", long_opts[idx].name)) - conf.load_from_disk = 1; - /* keep database files */ - if (!strcmp ("keep-db-files", long_opts[idx].name)) - conf.keep_db_files = 1; - - /* specifies the path of the database file */ - if (!strcmp ("db-path", long_opts[idx].name)) - conf.db_path = optarg; - /* set the size in bytes of the extra mapped memory */ - if (!strcmp ("xmmap", long_opts[idx].name)) - conf.xmmap = atoi (optarg); - /* specifies the maximum number of leaf nodes to be cached */ - if (!strcmp ("cache-lcnum", long_opts[idx].name)) - conf.cache_lcnum = atoi (optarg); - /* specifies the maximum number of non-leaf nodes to be cached */ - if (!strcmp ("cache-ncnum", long_opts[idx].name)) - conf.cache_ncnum = atoi (optarg); - /* number of members in each leaf page */ - if (!strcmp ("tune-lmemb", long_opts[idx].name)) - conf.tune_lmemb = atoi (optarg); - /* number of members in each non-leaf page */ - if (!strcmp ("tune-nmemb", long_opts[idx].name)) - conf.tune_nmemb = atoi (optarg); - /* number of elements of the bucket array */ - if (!strcmp ("tune-bnum", long_opts[idx].name)) - conf.tune_bnum = atoi (optarg); - - /* specifies that each page is compressed with X encoding */ - if (!strcmp ("compression", long_opts[idx].name)) { -#ifdef HAVE_ZLIB - if (!strcmp ("zlib", optarg)) - conf.compression = TC_ZLIB; -#endif -#ifdef HAVE_BZ2 - if (!strcmp ("bz2", optarg)) - conf.compression = TC_BZ2; -#endif - } - - break; - case 's': - display_storage (); - exit (EXIT_SUCCESS); - case '?': - exit (EXIT_FAILURE); - default: - exit (EXIT_FAILURE); - } - } - - for (idx = optind; idx < argc; idx++) - cmd_help (); -} diff --git a/options.h b/options.h deleted file mode 100644 index 6d0c4c989e..0000000000 --- a/options.h +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana <goaccess@prosoftcorp.com> - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#ifndef OPTIONS_H_INCLUDED -#define OPTIONS_H_INCLUDED - -void cmd_help (void); -void read_option_args (int argc, char **argv); -void verify_global_config (int argc, char **argv); - -#endif diff --git a/output.c b/output.c deleted file mode 100644 index 0e630ee87a..0000000000 --- a/output.c +++ /dev/null @@ -1,1319 +0,0 @@ -/** - * output.c -- output to the standard output stream - * Copyright (C) 2009-2014 by Gerardo Orellana <goaccess@prosoftcorp.com> - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#define _LARGEFILE_SOURCE -#define _LARGEFILE64_SOURCE -#define _FILE_OFFSET_BITS 64 - -#include <ctype.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/stat.h> -#include <time.h> -#include <unistd.h> -#include <inttypes.h> - -#include "output.h" - -#ifdef HAVE_LIBTOKYOCABINET -#include "tcabinet.h" -#else -#include "glibht.h" -#endif - -#ifdef HAVE_LIBGEOIP -#include "geolocation.h" -#endif - -#include "commons.h" -#include "error.h" -#include "gdns.h" -#include "settings.h" -#include "ui.h" -#include "util.h" -#include "xmalloc.h" - -/* sanitize output with html entities for special chars */ -static void -clean_output (FILE * fp, char *s) -{ - while (*s) { - switch (*s) { - case '\'': - fprintf (fp, "'"); - break; - case '"': - fprintf (fp, """); - break; - case '&': - fprintf (fp, "&"); - break; - case '<': - fprintf (fp, "<"); - break; - case '>': - fprintf (fp, ">"); - break; - case ' ': - fprintf (fp, " "); - break; - default: - fputc (*s, fp); - break; - } - s++; - } -} - -/* *INDENT-OFF* */ -static void -print_html_header (FILE * fp, char *now) -{ - fprintf (fp, "<!DOCTYPE html>\n"); - fprintf (fp, "<html lang=\"en\"><head>\n"); - fprintf (fp, "<title>Server Statistics - %s\n", now); - fprintf (fp, ""); - fprintf (fp, ""); - - fprintf (fp, "\n"); - - fprintf (fp, "\n"); - fprintf (fp, "\n"); - fprintf (fp, "\n"); - - fprintf (fp, "
"); -} -/* *INDENT-ON* */ - -static void -print_html_footer (FILE * fp) -{ - fprintf (fp, "
\n"); - fprintf (fp, " \n"); - fprintf (fp, " \n"); - fprintf (fp, "\n"); - fprintf (fp, ""); -} - -static void -print_html_h2 (FILE * fp, const char *title, const char *id) -{ - if (id) - fprintf (fp, "

%s

", id, title); - else - fprintf (fp, "

%s

", title); -} - -static void -print_p (FILE * fp, const char *paragraph) -{ - fprintf (fp, "

%s

", paragraph); -} - -static void -print_html_begin_table (FILE * fp) -{ - fprintf (fp, "\n"); -} - -static void -print_html_end_table (FILE * fp) -{ - fprintf (fp, "
\n"); -} - -static void -print_html_begin_thead (FILE * fp) -{ - fprintf (fp, "\n"); -} - -static void -print_html_end_thead (FILE * fp) -{ - fprintf (fp, "\n"); -} - -static void -print_html_begin_tbody (FILE * fp) -{ - fprintf (fp, "\n"); -} - -static void -print_html_end_tbody (FILE * fp) -{ - fprintf (fp, "\n"); -} - -static void -print_html_begin_tr (FILE * fp, int hide) -{ - if (hide) - fprintf (fp, ""); - else - fprintf (fp, ""); -} - -static void -print_html_end_tr (FILE * fp) -{ - fprintf (fp, ""); -} - -#ifdef HAVE_LIBGEOIP -static void -print_html_sub_geolocation (FILE * fp, GSubList * sub_list, int process) -{ - char *data, *name = NULL; - float percent; - GSubItem *iter; - int hits; - - for (iter = sub_list->head; iter; iter = iter->next) { - hits = iter->hits; - data = (char *) iter->data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - - name = xmalloc (snprintf (NULL, 0, "— %s", data) + 1); - sprintf (name, "— %s", data); - - print_html_begin_tr (fp, 1); - fprintf (fp, "%d", hits); - fprintf (fp, "%4.2f%%", percent); - - fprintf (fp, "%s", name); - - print_html_end_tr (fp); - free (name); - } -} -#endif - -#ifdef HAVE_LIBGEOIP -static void -print_html_geolocation (FILE * fp, GHolder * h, int process) -{ - char *data; - float percent; - int hits; - int i; - GSubList *sub_list; - - if (h->idx == 0) - return; - - print_html_h2 (fp, GEOLO_HEAD, GEOLO_ID); - print_p (fp, GEOLO_DESC); - print_html_begin_table (fp); - print_html_begin_thead (fp); - - fprintf (fp, ""); - fprintf (fp, "Visitors"); - fprintf (fp, "%%"); - fprintf (fp, ""); - fprintf (fp, "Location"); - fprintf (fp, ""); - fprintf (fp, ""); - fprintf (fp, ""); - - print_html_end_thead (fp); - print_html_begin_tbody (fp); - - for (i = 0; i < h->idx; i++) { - hits = h->items[i].hits; - data = h->items[i].data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - - print_html_begin_tr (fp, 0); - fprintf (fp, "%d", hits); - fprintf (fp, "%4.2f%%", percent); - fprintf (fp, "%s", data); - print_html_end_tr (fp); - - sub_list = h->items[i].sub_list; - print_html_sub_geolocation (fp, sub_list, process); - } - print_html_end_tbody (fp); - print_html_end_table (fp); -} -#endif - -static void -print_html_sub_status (FILE * fp, GSubList * sub_list, int process) -{ - char *data, *name = NULL; - float percent; - GSubItem *iter; - int hits; - - for (iter = sub_list->head; iter; iter = iter->next) { - hits = iter->hits; - data = (char *) iter->data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - - name = xmalloc (snprintf (NULL, 0, "— %s", data) + 1); - sprintf (name, "— %s", data); - - print_html_begin_tr (fp, 1); - fprintf (fp, "%d", hits); - fprintf (fp, "%4.2f%%", percent); - - fprintf (fp, "%s", name); - - print_html_end_tr (fp); - free (name); - } -} - -static void -print_html_status (FILE * fp, GHolder * h, int process) -{ - char *data; - float percent; - int hits; - int i; - GSubList *sub_list; - - if (h->idx == 0) - return; - - print_html_h2 (fp, CODES_HEAD, CODES_ID); - print_p (fp, CODES_DESC); - print_html_begin_table (fp); - print_html_begin_thead (fp); - - fprintf (fp, ""); - fprintf (fp, "Hits"); - fprintf (fp, "%%"); - fprintf (fp, "Code"); - fprintf (fp, ""); - - print_html_end_thead (fp); - print_html_begin_tbody (fp); - - for (i = 0; i < h->idx; i++) { - hits = h->items[i].hits; - data = h->items[i].data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - - print_html_begin_tr (fp, 0); - fprintf (fp, "%d", hits); - fprintf (fp, "%4.2f%%", percent); - fprintf (fp, "%s", data); - print_html_end_tr (fp); - - sub_list = h->items[i].sub_list; - print_html_sub_status (fp, sub_list, process); - } - print_html_end_tbody (fp); - print_html_end_table (fp); -} - -static void -print_html_generic (FILE * fp, GHolder * h, int process) -{ - char *data; - const char *desc = REFER_DESC; - const char *head = REFER_HEAD; - const char *id = REFER_ID; - float percent; - int hits, i, until = 0; - - if (h->idx == 0) - return; - - if (h->module == NOT_FOUND) { - head = FOUND_HEAD; - id = FOUND_ID; - desc = FOUND_DESC; - } else if (h->module == REFERRING_SITES) { - head = SITES_HEAD; - id = SITES_ID; - desc = SITES_DESC; - } else if (h->module == KEYPHRASES) { - head = KEYPH_HEAD; - id = KEYPH_ID; - desc = KEYPH_DESC; - } - - print_html_h2 (fp, head, id); - print_p (fp, desc); - print_html_begin_table (fp); - print_html_begin_thead (fp); - - fprintf (fp, ""); - fprintf (fp, "Hits"); - fprintf (fp, "%%"); - fprintf (fp, "URL"); - fprintf (fp, ""); - - print_html_end_thead (fp); - print_html_begin_tbody (fp); - - until = h->idx < MAX_CHOICES ? h->idx : MAX_CHOICES; - for (i = 0; i < until; i++) { - hits = h->items[i].hits; - data = h->items[i].data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - - print_html_begin_tr (fp, i > OUTPUT_N ? 1 : 0); - - fprintf (fp, "%d", hits); - fprintf (fp, "%4.2f%%", percent); - fprintf (fp, ""); - clean_output (fp, data); - fprintf (fp, ""); - - print_html_end_tr (fp); - } - - print_html_end_tbody (fp); - print_html_end_table (fp); -} - -static void -print_html_sub_browser_os (FILE * fp, GSubList * sub_list, int process) -{ - char *data, *name = NULL; - int hits; - float percent, l; - GSubItem *iter; - - for (iter = sub_list->head; iter; iter = iter->next) { - hits = iter->hits; - data = (char *) iter->data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - - l = get_percentage (process, hits); - l = l < 1 ? 1 : l; - - name = xmalloc (snprintf (NULL, 0, "— %s", data) + 1); - sprintf (name, "— %s", data); - - print_html_begin_tr (fp, 1); - fprintf (fp, "%d", hits); - fprintf (fp, "%4.2f%%", percent); - fprintf (fp, "%s", name); - fprintf (fp, ""); - fprintf (fp, "
", l); - fprintf (fp, ""); - print_html_end_tr (fp); - free (name); - } -} - -static void -print_html_browser_os (FILE * fp, GHolder * h) -{ - char *data; - const char *desc = OPERA_DESC; - const char *head = OPERA_HEAD; - const char *id = OPERA_ID; - float percent, l; - GSubList *sub_list; - int hits, i, max, process = get_ht_size (ht_unique_visitors); - - if (h->idx == 0) - return; - - if (h->module == BROWSERS) { - head = BROWS_HEAD; - id = BROWS_ID; - desc = BROWS_DESC; - } - - print_html_h2 (fp, head, id); - print_p (fp, desc); - print_html_begin_table (fp); - print_html_begin_thead (fp); - - fprintf (fp, ""); - fprintf (fp, "Visitors"); - fprintf (fp, "%%"); - fprintf (fp, "Name"); - fprintf (fp, ""); - fprintf (fp, ""); - fprintf (fp, ""); - fprintf (fp, ""); - - print_html_end_thead (fp); - print_html_begin_tbody (fp); - - max = 0; - for (i = 0; i < h->idx; i++) { - if (h->items[i].hits > max) - max = h->items[i].hits; - } - - for (i = 0; i < h->idx; i++) { - hits = h->items[i].hits; - data = h->items[i].data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - - l = get_percentage (max, hits); - l = l < 1 ? 1 : l; - - print_html_begin_tr (fp, 0); - fprintf (fp, "%d", hits); - fprintf (fp, "%4.2f%%", percent); - - /* data */ - fprintf (fp, ""); - clean_output (fp, data); - fprintf (fp, ""); - - fprintf (fp, ""); - fprintf (fp, "
", l); - fprintf (fp, ""); - print_html_end_tr (fp); - - sub_list = h->items[i].sub_list; - print_html_sub_browser_os (fp, sub_list, process); - } - - print_html_end_tbody (fp); - print_html_end_table (fp); -} - -static void -print_html_hosts (FILE * fp, GHolder * h, int process) -{ - GAgents *agents; - - char *data, *bandwidth, *usecs, *ag, *ptr_value, *host; - float percent, l; - int hits; - int i, j, max, until = 0, delims = 0, colspan = 6; - size_t alloc = 0; - -#ifdef HAVE_LIBGEOIP - char country[COUNTRY_LEN] = ""; - char city[CITY_LEN] = ""; -#endif - - if (h->idx == 0) - return; - - print_html_h2 (fp, HOSTS_HEAD, HOSTS_ID); - print_p (fp, HOSTS_DESC); - print_html_begin_table (fp); - print_html_begin_thead (fp); - - fprintf (fp, ""); - fprintf (fp, ""); - fprintf (fp, "Hits"); - fprintf (fp, "%%"); - fprintf (fp, "Bandwidth"); - if (conf.serve_usecs) { - colspan++; - fprintf (fp, "Time served"); - } - fprintf (fp, "IP"); -#ifdef HAVE_LIBGEOIP - fprintf (fp, "Country"); - colspan++; - if (conf.geoip_city_data) { - fprintf (fp, "City"); - colspan++; - } -#endif - if (conf.enable_html_resolver) { - colspan++; - fprintf (fp, "Hostname"); - } - - fprintf (fp, ""); - fprintf (fp, ""); - fprintf (fp, ""); - fprintf (fp, ""); - - print_html_end_thead (fp); - print_html_begin_tbody (fp); - - until = h->idx < MAX_CHOICES ? h->idx : MAX_CHOICES; - max = 0; - for (i = 0; i < until; i++) { - if (h->items[i].hits > max) - max = h->items[i].hits; - } - - for (i = 0; i < until; i++) { - hits = h->items[i].hits; - data = h->items[i].data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - bandwidth = filesize_str (h->items[i].bw); - l = get_percentage (max, hits); - l = l < 1 ? 1 : l; - -#ifdef HAVE_LIBTOKYOCABINET - ag = tc_db_get_str (ht_hosts_agents, data); -#else - ag = g_hash_table_lookup (ht_hosts_agents, data); -#endif - - print_html_begin_tr (fp, i > OUTPUT_N ? 1 : 0); - fprintf (fp, ""); - if (ag != NULL) - fprintf (fp, ""); - else - fprintf (fp, "-"); - fprintf (fp, ""); - - fprintf (fp, "%d", hits); - fprintf (fp, "%4.2f%%", percent); - - fprintf (fp, ""); - clean_output (fp, bandwidth); - fprintf (fp, ""); - - /* usecs */ - if (conf.serve_usecs) { - usecs = usecs_to_str (h->items[i].usecs); - fprintf (fp, ""); - clean_output (fp, usecs); - fprintf (fp, ""); - free (usecs); - } - - fprintf (fp, "%s", data); - -#ifdef HAVE_LIBGEOIP - geoip_get_country (data, country); - fprintf (fp, "%s", country); - if (conf.geoip_city_data) { - geoip_get_city (data, city); - fprintf (fp, "%s", city); - } -#endif - - if (conf.enable_html_resolver) { - host = reverse_ip (data); - fprintf (fp, "%s", host); - free (host); - } - - fprintf (fp, ""); - fprintf (fp, "
", l); - fprintf (fp, ""); - print_html_end_tr (fp); - - /* render agents for each host */ - if (ag != NULL) { - ptr_value = (char *) ag; - - delims = count_occurrences (ptr_value, '|'); - /* round-up + padding */ - alloc = ((strlen (ptr_value) + 300 - 1) / 300) + delims + 1; - agents = xmalloc (alloc * sizeof (GAgents)); - memset (agents, 0, alloc * sizeof (GAgents)); - - /* split agents into struct */ - split_agent_str (ptr_value, agents, 300); - - fprintf (fp, "\n"); - fprintf (fp, "\n", colspan); - fprintf (fp, "
"); - fprintf (fp, ""); - - /* output agents from struct */ - for (j = 0; (j < 10) && (agents[j].agents != NULL); j++) { - print_html_begin_tr (fp, 0); - fprintf (fp, ""); - print_html_end_tr (fp); - } - - fprintf (fp, "
"); - clean_output (fp, agents[j].agents); - fprintf (fp, "
\n"); - fprintf (fp, "
\n"); - fprintf (fp, "\n"); - print_html_end_tr (fp); - - for (j = 0; (agents[j].agents != NULL); j++) - free (agents[j].agents); - free (agents); -#ifdef HAVE_LIBTOKYOCABINET - if (ag) - free (ag); -#endif - } - - free (bandwidth); - } - - print_html_end_tbody (fp); - print_html_end_table (fp); -} - -static void -print_html_request_report (FILE * fp, GHolder * h, int process) -{ -#ifdef TCB_BTREE - TCBDB *ht = NULL; -#elif TCB_MEMHASH - TCMDB *ht = NULL; -#else - GHashTable *ht; -#endif - - char *data, *bandwidth, *usecs; - const char *desc = REQUE_DESC; - const char *head = REQUE_HEAD; - const char *id = REQUE_ID; - float percent; - int hits; - int i, until = 0; - - if (h->idx == 0) - return; - - ht = get_ht_by_module (h->module); - - if (ht == ht_requests_static) { - head = STATI_HEAD; - id = STATI_ID; - desc = STATI_DESC; - } else if (ht == ht_not_found_requests) { - head = FOUND_HEAD; - id = FOUND_ID; - desc = FOUND_DESC; - } - - print_html_h2 (fp, head, id); - print_p (fp, desc); - print_html_begin_table (fp); - print_html_begin_thead (fp); - - fprintf (fp, ""); - fprintf (fp, "Hits"); - fprintf (fp, "%%"); - fprintf (fp, "Bandwidth"); - if (conf.serve_usecs) - fprintf (fp, "Time served"); - if (conf.append_protocol) - fprintf (fp, "Protocol"); - if (conf.append_method) - fprintf (fp, "Method"); - fprintf (fp, "URL"); - fprintf (fp, ""); - fprintf (fp, ""); - - print_html_end_thead (fp); - print_html_begin_tbody (fp); - - until = h->idx < MAX_CHOICES ? h->idx : MAX_CHOICES; - for (i = 0; i < until; i++) { - hits = h->items[i].hits; - data = h->items[i].data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - bandwidth = filesize_str (h->items[i].bw); - - print_html_begin_tr (fp, i > OUTPUT_N ? 1 : 0); - - /* hits */ - fprintf (fp, "%d", hits); - /* percent */ - fprintf (fp, "%4.2f%%", percent); - /* bandwidth */ - fprintf (fp, ""); - clean_output (fp, bandwidth); - fprintf (fp, ""); - - /* usecs */ - if (conf.serve_usecs) { - usecs = usecs_to_str (h->items[i].usecs); - fprintf (fp, ""); - clean_output (fp, usecs); - fprintf (fp, ""); - free (usecs); - } - /* protocol */ - if (conf.append_protocol) { - fprintf (fp, ""); - clean_output (fp, h->items[i].protocol); - fprintf (fp, ""); - } - /* method */ - if (conf.append_method) { - fprintf (fp, ""); - clean_output (fp, h->items[i].method); - fprintf (fp, ""); - } - - /* data */ - fprintf (fp, ""); - clean_output (fp, data); - fprintf (fp, ""); - - print_html_end_tr (fp); - - free (bandwidth); - } - - print_html_end_tbody (fp); - print_html_end_table (fp); -} - -static void -print_html_visitors_report (FILE * fp, GHolder * h) -{ - char *data, *bandwidth, buf[DATE_LEN]; - float percent, l; - int hits, i, max, process = get_ht_size (ht_unique_visitors); - - /* make compiler happy */ - memset (buf, 0, sizeof (buf)); - - print_html_h2 (fp, VISIT_HEAD, VISIT_ID); - print_p (fp, VISIT_DESC); - print_html_begin_table (fp); - print_html_begin_thead (fp); - - fprintf (fp, ""); - fprintf (fp, "Visitors"); - fprintf (fp, "%%"); - fprintf (fp, "Date"); - fprintf (fp, "Bandwidth"); - fprintf (fp, ""); - fprintf (fp, ""); - fprintf (fp, ""); - fprintf (fp, ""); - - print_html_end_thead (fp); - - print_html_begin_tbody (fp); - - max = 0; - for (i = 0; i < h->idx; i++) { - if (h->items[i].hits > max) - max = h->items[i].hits; - } - for (i = 0; i < h->idx; i++) { - hits = h->items[i].hits; - data = h->items[i].data; - percent = get_percentage (process, hits); - percent = percent < 0 ? 0 : percent; - bandwidth = filesize_str (h->items[i].bw); - - l = get_percentage (max, hits); - l = l < 1 ? 1 : l; - - print_html_begin_tr (fp, i > OUTPUT_N ? 1 : 0); - - /* hits */ - fprintf (fp, "%d", hits); - if (hits == max) - fprintf (fp, "%4.2f%%", percent); - else - fprintf (fp, "%4.2f%%", percent); - - /* date */ - convert_date (buf, data, "%Y%m%d", "%d/%b/%Y", DATE_LEN); - fprintf (fp, "%s", buf); - - /* bandwidth */ - fprintf (fp, ""); - clean_output (fp, bandwidth); - fprintf (fp, ""); - - /* bars */ - fprintf (fp, ""); - fprintf (fp, "
", l); - fprintf (fp, "\n"); - - print_html_end_tr (fp); - - free (bandwidth); - } - - print_html_end_tbody (fp); - print_html_end_table (fp); -} - -static void -print_html_summary_field (FILE * fp, int hits, const char *field) -{ - fprintf (fp, "%s%d", field, hits); -} - -static void -print_html_summary (FILE * fp, GLog * logger) -{ - char *bw, *size; - off_t log_size; - - print_html_h2 (fp, T_HEAD, 0); - print_html_begin_table (fp); - print_html_begin_tbody (fp); - - print_html_begin_tr (fp, 0); - print_html_summary_field (fp, logger->process, T_REQUESTS); - print_html_summary_field (fp, get_ht_size (ht_unique_visitors), T_UNIQUE_VIS); - print_html_summary_field (fp, get_ht_size (ht_referrers), T_REFERRER); - - if (!logger->piping) { - log_size = file_size (conf.ifile); - size = filesize_str (log_size); - } else { - size = alloc_string ("N/A"); - } - - bw = filesize_str ((float) logger->resp_size); - if (conf.ifile == NULL) - conf.ifile = (char *) "STDIN"; - - fprintf (fp, "%s%s", T_LOG, size); - print_html_end_tr (fp); - - print_html_begin_tr (fp, 0); - print_html_summary_field (fp, logger->invalid, T_F_REQUESTS); - print_html_summary_field (fp, get_ht_size (ht_requests), T_UNIQUE_FIL); - print_html_summary_field (fp, get_ht_size (ht_not_found_requests), - T_UNIQUE404); - fprintf (fp, "%s%s", T_BW, bw); - print_html_end_tr (fp); - - print_html_begin_tr (fp, 0); - fprintf (fp, "%s", T_GEN_TIME); - fprintf (fp, "%llu", ((long long) end_proc - start_proc)); - - print_html_summary_field (fp, get_ht_size (ht_requests_static), T_STATIC_FIL); - fprintf (fp, "%s", conf.ifile); - - print_html_end_tr (fp); - print_html_end_tbody (fp); - print_html_end_table (fp); - free (bw); - free (size); -} - -static void -print_pure_menu (FILE * fp, char *now) -{ - fprintf (fp, "
"); - fprintf (fp, "
"); - fprintf (fp, "", GO_WEBSITE); - fprintf (fp, "«./GoAccess»"); - fprintf (fp, ""); - fprintf (fp, ""); - fprintf (fp, "

Generated by
GoAccess %s

%s

", - GO_VERSION, now); - fprintf (fp, "
"); - fprintf (fp, "
"); - - fprintf (fp, "
"); - fprintf (fp, "
"); -} - -/* entry point to generate a report writing it to the fp */ -void -output_html (GLog * logger, GHolder * holder) -{ - FILE *fp = stdout; - char now[DATE_TIME]; - - generate_time (); - strftime (now, DATE_TIME, "%Y-%m-%d %H:%M:%S", now_tm); - - print_html_header (fp, now); - print_pure_menu (fp, now); - - print_html_summary (fp, logger); - print_html_visitors_report (fp, holder + VISITORS); - print_html_request_report (fp, holder + REQUESTS, logger->process); - print_html_request_report (fp, holder + REQUESTS_STATIC, logger->process); - print_html_request_report (fp, holder + NOT_FOUND, logger->process); - print_html_hosts (fp, holder + HOSTS, logger->process); - print_html_browser_os (fp, holder + OS); - print_html_browser_os (fp, holder + BROWSERS); - print_html_generic (fp, holder + REFERRERS, logger->process); - print_html_generic (fp, holder + REFERRING_SITES, logger->process); - print_html_generic (fp, holder + KEYPHRASES, logger->process); -#ifdef HAVE_LIBGEOIP - print_html_geolocation (fp, holder + GEO_LOCATION, logger->process); -#endif - print_html_status (fp, holder + STATUS_CODES, logger->process); - - print_html_footer (fp); -} diff --git a/output.h b/output.h deleted file mode 100644 index 241adfa13e..0000000000 --- a/output.h +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#if HAVE_CONFIG_H -#include -#endif - -#ifndef OUTPUT_H_INCLUDED -#define OUTPUT_H_INCLUDED - -#define OUTPUT_N 10 -#define REF_LEN 20 - -#include "commons.h" -#include "parser.h" - -void output_html (GLog * logger, GHolder * holder); - -#endif diff --git a/parser.c b/parser.c deleted file mode 100644 index bfbd865d2d..0000000000 --- a/parser.c +++ /dev/null @@ -1,1119 +0,0 @@ -/** - * parser.c -- web log parsing - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -/* - * "_XOPEN_SOURCE" is required for the GNU libc to export "strptime(3)" - * correctly. - */ -#define _LARGEFILE_SOURCE -#define _LARGEFILE64_SOURCE -#define _FILE_OFFSET_BITS 64 - -#define _XOPEN_SOURCE 700 - -#include -#include - -#if HAVE_CONFIG_H -#include -#endif - -#ifdef HAVE_NCURSESW_NCURSES_H -#include -#elif HAVE_NCURSES_NCURSES_H -#include -#elif HAVE_NCURSES_H -#include -#elif HAVE_CURSES_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_LIBTOKYOCABINET -#include "tcabinet.h" -#else -#include "glibht.h" -#endif - -#ifdef HAVE_LIBGEOIP -#include "geolocation.h" -#endif - -#include "parser.h" - -#include "browsers.h" -#include "commons.h" -#include "goaccess.h" -#include "error.h" -#include "opesys.h" -#include "settings.h" -#include "util.h" -#include "xmalloc.h" - -/* sort data ascending */ -int -cmp_data_asc (const void *a, const void *b) -{ - const GHolderItem *ia = a; - const GHolderItem *ib = b; - return strcmp (ia->data, ib->data); -} - -/* sort data descending */ -int -cmp_data_desc (const void *a, const void *b) -{ - const GHolderItem *ia = a; - const GHolderItem *ib = b; - return strcmp (ib->data, ia->data); -} - -/* sort raw data descending */ -int -cmp_raw_data_desc (const void *a, const void *b) -{ - const GRawDataItem *ia = a; - const GRawDataItem *ib = b; - return strcmp ((const char *) ib->key, (const char *) ia->key); -} - -/* sort numeric descending */ -int -cmp_num_desc (const void *a, const void *b) -{ - const GHolderItem *ia = a; - const GHolderItem *ib = b; - return (int) (ib->hits - ia->hits); -} - -/* sort raw numeric descending */ -int -cmp_raw_num_desc (const void *a, const void *b) -{ - const GRawDataItem *ia = a; - const GRawDataItem *ib = b; - return (int) (*(int *) ib->value - *(int *) ia->value); -} - -/* sort raw numeric descending */ -int -cmp_raw_os_num_desc (const void *a, const void *b) -{ - const GRawDataItem *ia = a; - const GRawDataItem *ib = b; - GOpeSys *aos = ia->value; - GOpeSys *bos = ib->value; - return (int) (bos->hits - aos->hits); -} - -/* sort raw numeric descending */ -int -cmp_raw_browser_num_desc (const void *a, const void *b) -{ - const GRawDataItem *ia = a; - const GRawDataItem *ib = b; - GBrowser *abro = ia->value; - GBrowser *bbro = ib->value; - return (int) (bbro->hits - abro->hits); -} - -/* sort raw numeric descending */ -#ifdef HAVE_LIBGEOIP -int -cmp_raw_geo_num_desc (const void *a, const void *b) -{ - const GRawDataItem *ia = a; - const GRawDataItem *ib = b; - GLocation *aloc = ia->value; - GLocation *bloc = ib->value; - return (int) (bloc->hits - aloc->hits); -} -#endif - -/* sort numeric ascending */ -int -cmp_num_asc (const void *a, const void *b) -{ - const GHolderItem *ia = a; - const GHolderItem *ib = b; - return (int) (ia->hits - ib->hits); -} - -/* sort bandwidth descending */ -int -cmp_bw_desc (const void *a, const void *b) -{ - const GHolderItem *ia = a; - const GHolderItem *ib = b; - return (unsigned long long) (ib->bw - ia->bw); -} - -/* sort bandwidth ascending */ -int -cmp_bw_asc (const void *a, const void *b) -{ - const GHolderItem *ia = a; - const GHolderItem *ib = b; - return (unsigned long long) (ia->bw - ib->bw); -} - -/* sort usec descending */ -int -cmp_usec_desc (const void *a, const void *b) -{ - const GHolderItem *ia = a; - const GHolderItem *ib = b; - return (unsigned long long) (ib->usecs - ia->usecs); -} - -/* sort usec ascending */ -int -cmp_usec_asc (const void *a, const void *b) -{ - const GHolderItem *ia = a; - const GHolderItem *ib = b; - return (unsigned long long) (ia->usecs - ib->usecs); -} - -/* sort protocol ascending */ -int -cmp_proto_asc (const void *a, const void *b) -{ - const GHolderItem *ia = a; - const GHolderItem *ib = b; - return strcmp (ia->protocol, ib->protocol); -} - -/* sort protocol descending */ -int -cmp_proto_desc (const void *a, const void *b) -{ - const GHolderItem *ia = a; - const GHolderItem *ib = b; - return strcmp (ib->protocol, ia->protocol); -} - -/* sort method ascending */ -int -cmp_mthd_asc (const void *a, const void *b) -{ - const GHolderItem *ia = a; - const GHolderItem *ib = b; - return strcmp (ia->method, ib->method); -} - -/* sort method descending */ -int -cmp_mthd_desc (const void *a, const void *b) -{ - const GHolderItem *ia = a; - const GHolderItem *ib = b; - return strcmp (ib->method, ia->method); -} - -/* allocate memory for ht raw data */ -GRawData * -new_grawdata (void) -{ - GRawData *raw_data = xmalloc (sizeof (GRawData)); - memset (raw_data, 0, sizeof *raw_data); - - return raw_data; -} - -/* allocate memory for raw data items */ -GRawDataItem * -new_grawdata_item (unsigned int size) -{ - GRawDataItem *item = xcalloc (size, sizeof (GRawDataItem)); - return item; -} - -/* free memory allocated in raw data */ -void -free_raw_data (GRawData * raw_data) -{ -#ifdef HAVE_LIBTOKYOCABINET - int i; - for (i = 0; i < raw_data->size; i++) { - if (raw_data->items[i].key != NULL) - free (raw_data->items[i].key); - if (raw_data->items[i].value != NULL) - free (raw_data->items[i].value); - } -#endif - free (raw_data->items); - free (raw_data); -} - -void -reset_struct (GLog * logger) -{ - logger->invalid = 0; - logger->process = 0; - logger->resp_size = 0LL; -} - -GLog * -init_log (void) -{ - GLog *glog = xmalloc (sizeof (GLog)); - memset (glog, 0, sizeof *glog); - - return glog; -} - -GLogItem * -init_log_item (GLog * logger) -{ - GLogItem *glog; - logger->items = xmalloc (sizeof (GLogItem)); - glog = logger->items; - memset (glog, 0, sizeof *glog); - - glog->agent = NULL; - glog->date = NULL; - glog->host = NULL; - glog->ref = NULL; - glog->method = NULL; - glog->protocol = NULL; - glog->req = NULL; - glog->status = NULL; - glog->resp_size = 0LL; - glog->serve_time = 0; - - return glog; -} - -static void -free_logger (GLogItem * glog) -{ - if (glog->agent != NULL) - free (glog->agent); - if (glog->date != NULL) - free (glog->date); - if (glog->host != NULL) - free (glog->host); - if (glog->ref != NULL) - free (glog->ref); - if (glog->method != NULL) - free (glog->method); - if (glog->protocol != NULL) - free (glog->protocol); - if (glog->req != NULL) - free (glog->req); - if (glog->status != NULL) - free (glog->status); - free (glog); -} - -#define SPC_BASE16_TO_10(x) (((x) >= '0' && (x) <= '9') ? ((x) - '0') \ - : (toupper((x)) - 'A' + 10)) -static char * -spc_decode_url (char *url) -{ - char *out, *ptr; - const char *c; - - if (!(out = ptr = xstrdup (url))) - return 0; - for (c = url; *c; c++) { - if (*c != '%' || !isxdigit (c[1]) || !isxdigit (c[2])) - *ptr++ = *c; - else { - *ptr++ = (SPC_BASE16_TO_10 (c[1]) * 16) + (SPC_BASE16_TO_10 (c[2])); - c += 2; - } - } - *ptr = 0; - return trim_str (out); -} - -/* process keyphrases used on Google search, Google cache, and - * Google translate. */ -static int -process_keyphrases (char *ref) -{ - char *r, *ptr, *p, *dec, *pch; - - if (!(strstr (ref, "http://www.google.")) && - !(strstr (ref, "http://webcache.googleusercontent.com/")) && - !(strstr (ref, "http://translate.googleusercontent.com/"))) - return 1; - - if ((r = strstr (ref, "/+&")) != NULL) - return 1; - else if ((r = strstr (ref, "/+")) != NULL) - r += 2; - else if ((r = strstr (ref, "q=cache:")) != NULL) { - pch = strchr (r, '+'); - if (pch) - r += pch - r + 1; - } else if ((r = strstr (ref, "&q=")) != NULL || - (r = strstr (ref, "?q=")) != NULL) - r += 3; - else if ((r = strstr (ref, "%26q%3D")) != NULL || - (r = strstr (ref, "%3Fq%3D")) != NULL) - r += 7; - else - return 1; - dec = spc_decode_url (r); - if ((ptr = strstr (dec, "%26")) != NULL || (ptr = strchr (dec, '&')) != NULL) - *ptr = '\0'; - - p = dec; - if (p[0] == '\0') { - if (dec != NULL) - free (dec); - return 1; - } - p = char_replace (p, '+', ' '); - process_generic_data (ht_keyphrases, trim_str (dec)); - if (dec != NULL) - free (dec); - - return 0; -} - -/* process referer */ -static void -process_referrers (char *referrer) -{ - char *ref; - char url[512] = ""; - - if (referrer == NULL) - return; - - ref = spc_decode_url (referrer); - /* extract the host part, i.e., www.foo.com */ - if (sscanf (ref, "%*[^/]%*[/]%[^/]", url) == 1) - process_generic_data (ht_referring_sites, url); - process_generic_data (ht_referrers, ref); - process_keyphrases (referrer); - free (ref); -} - -/* process data based on a unique key, this includes the following - * modules, VISITORS, BROWSERS, OS */ -static void -process_unique_data (char *host, char *date, char *agent) -{ -#ifdef HAVE_LIBGEOIP - char city[CITY_LEN] = ""; - char continent[CONTINENT_LEN] = ""; - char country[COUNTRY_LEN] = ""; -#endif - - char *a = NULL; - char *browser_key = NULL, *browser = NULL; - char *os_key = NULL, *opsys = NULL; - - char visitor_key[UKEY_BUFFER]; - char os_type[OPESYS_TYPE_LEN], browser_type[BROWSER_TYPE_LEN]; - - a = deblank (xstrdup (agent)); - snprintf (visitor_key, sizeof (visitor_key), "%s|%s|%s", host, date, a); - (visitor_key)[sizeof (visitor_key) - 1] = '\0'; - free (a); - - /* - * Check if the unique visitor key exists, if not, - * process hit as unique visitor. Includes, BROWSERS, OSs, VISITORS. - */ - if (process_generic_data (ht_unique_visitors, visitor_key) == -1) { - browser_key = xstrdup (agent); - os_key = xstrdup (agent); - - /* extract browser & OS from agent */ - browser = verify_browser (browser_key, browser_type); - if (browser != NULL) - process_browser (ht_browsers, browser, browser_type); - - opsys = verify_os (os_key, os_type); - if (opsys != NULL) - process_opesys (ht_os, opsys, os_type); - -#ifdef HAVE_LIBGEOIP - if (geo_location_data != NULL) { - if (conf.geoip_city_data) - geoip_get_city (host, city); - - geoip_get_country (host, country); - geoip_get_continent (host, continent); - process_geolocation (ht_countries, country, continent, city); - } -#endif - - if ((date = strchr (visitor_key, '|')) != NULL) { - char *tmp_date = NULL; - tmp_date = clean_date (++date); - if (tmp_date != NULL) { - process_generic_data (ht_unique_vis, tmp_date); - free (tmp_date); - } - } - } - - if (browser != NULL) - free (browser); - if (browser_key != NULL) - free (browser_key); - if (os_key != NULL) - free (os_key); - if (opsys != NULL) - free (opsys); -} - -/** - * Append HTTP method to the request - * ###NOTE: the whole string will serve as a key - */ -static void -append_method_to_request (char **key, const char *method) -{ - char *s = NULL; - - if (*key == NULL || **key == '\0') - return; - - if (method == NULL || *method == '\0') - return; - - s = xmalloc (snprintf (NULL, 0, "%s %s", method, *key) + 1); - sprintf (s, "%s %s", method, *key); - - free (*key); - *key = s; -} - -/** - * Append HTTP protocol to the request - * ###NOTE: the whole string will serve as a key - */ -static void -append_protocol_to_request (char **key, const char *protocol) -{ - char *s = NULL; - - if (*key == NULL || **key == '\0') - return; - - if (protocol == NULL || *protocol == '\0') - return; - - s = xmalloc (snprintf (NULL, 0, "%s %s", protocol, *key) + 1); - sprintf (s, "%s %s", protocol, *key); - - free (*key); - *key = s; -} - -/* returns 1 if the request seems to be a static file */ -static int -verify_static_content (char *req) -{ - char *nul = req + strlen (req); - - if (strlen (req) < 5) - return 0; - if (!memcmp (nul - 4, ".jpg", 4) || !memcmp (nul - 4, ".JPG", 4) || - !memcmp (nul - 4, ".png", 4) || !memcmp (nul - 4, ".PNG", 4) || - !memcmp (nul - 4, ".pdf", 4) || !memcmp (nul - 4, ".PDF", 4) || - !memcmp (nul - 3, ".js", 3) || !memcmp (nul - 3, ".JS", 3) || - !memcmp (nul - 4, ".map", 4) || !memcmp (nul - 4, ".MAP", 4) || - !memcmp (nul - 4, ".gif", 4) || !memcmp (nul - 4, ".GIF", 4) || - !memcmp (nul - 4, ".css", 4) || !memcmp (nul - 4, ".CSS", 4) || - !memcmp (nul - 4, ".ico", 4) || !memcmp (nul - 4, ".ICO", 4) || - !memcmp (nul - 4, ".txt", 4) || !memcmp (nul - 4, ".TXT", 4) || - !memcmp (nul - 4, ".swf", 4) || !memcmp (nul - 4, ".SWF", 4) || - !memcmp (nul - 5, ".jpeg", 5) || !memcmp (nul - 5, ".JPEG", 5) || - !memcmp (nul - 5, ".woff", 5) || !memcmp (nul - 5, ".WOFF", 5) || - !memcmp (nul - 4, ".eot", 4) || !memcmp (nul - 4, ".EOT", 4) || - !memcmp (nul - 4, ".svg", 4) || !memcmp (nul - 4, ".SVG", 4) || - !memcmp (nul - 4, ".ttf", 4) || !memcmp (nul - 4, ".TTF", 4) || - !memcmp (nul - 4, ".dae", 4) || !memcmp (nul - 4, ".DAE", 4)) - return 1; - return 0; -} - -static char * -parse_req (char *line, GLogItem * glog) -{ - const char *lookfor = NULL; - char *reqs, *req_l = NULL, *req_r = NULL; - char *method = NULL, *protocol = NULL; - ptrdiff_t req_len; - - if ((lookfor = "OPTIONS ", req_l = strstr (line, lookfor)) != NULL || - (lookfor = "GET ", req_l = strstr (line, lookfor)) != NULL || - (lookfor = "HEAD ", req_l = strstr (line, lookfor)) != NULL || - (lookfor = "POST ", req_l = strstr (line, lookfor)) != NULL || - (lookfor = "PUT ", req_l = strstr (line, lookfor)) != NULL || - (lookfor = "DELETE ", req_l = strstr (line, lookfor)) != NULL || - (lookfor = "TRACE ", req_l = strstr (line, lookfor)) != NULL || - (lookfor = "CONNECT ", req_l = strstr (line, lookfor)) != NULL || - (lookfor = "options ", req_l = strstr (line, lookfor)) != NULL || - (lookfor = "get ", req_l = strstr (line, lookfor)) != NULL || - (lookfor = "head ", req_l = strstr (line, lookfor)) != NULL || - (lookfor = "post ", req_l = strstr (line, lookfor)) != NULL || - (lookfor = "put ", req_l = strstr (line, lookfor)) != NULL || - (lookfor = "delete ", req_l = strstr (line, lookfor)) != NULL || - (lookfor = "trace ", req_l = strstr (line, lookfor)) != NULL || - (lookfor = "connect ", req_l = strstr (line, lookfor)) != NULL) { - - /* didn't find it - weird */ - if ((req_r = strstr (line, " HTTP/1.0")) == NULL && - (req_r = strstr (line, " HTTP/1.1")) == NULL) - return alloc_string ("-"); - - req_l += strlen (lookfor); - req_len = req_r - req_l; - - /* make sure we don't have some weird requests */ - if (req_len <= 0) - return alloc_string ("-"); - - reqs = xmalloc (req_len + 1); - strncpy (reqs, req_l, req_len); - reqs[req_len] = 0; - - if (conf.append_method) { - method = trim_str (xstrdup (lookfor)); - str_to_upper (method); - glog->method = method; - } - - if (conf.append_protocol) { - protocol = xstrdup (++req_r); - str_to_upper (protocol); - glog->protocol = protocol; - } - } else - reqs = alloc_string (line); - - return reqs; -} - -static int -invalid_method (const char *token) -{ - const char *lookfor = NULL; - - return !((lookfor = "OPTIONS", !memcmp (token, lookfor, 7)) || - (lookfor = "GET", !memcmp (token, lookfor, 3)) || - (lookfor = "HEAD", !memcmp (token, lookfor, 4)) || - (lookfor = "POST", !memcmp (token, lookfor, 4)) || - (lookfor = "PUT", !memcmp (token, lookfor, 3)) || - (lookfor = "DELETE", !memcmp (token, lookfor, 6)) || - (lookfor = "TRACE", !memcmp (token, lookfor, 5)) || - (lookfor = "CONNECT", !memcmp (token, lookfor, 7)) || - (lookfor = "options", !memcmp (token, lookfor, 7)) || - (lookfor = "get", !memcmp (token, lookfor, 3)) || - (lookfor = "head", !memcmp (token, lookfor, 4)) || - (lookfor = "post", !memcmp (token, lookfor, 4)) || - (lookfor = "put", !memcmp (token, lookfor, 3)) || - (lookfor = "delete", !memcmp (token, lookfor, 6)) || - (lookfor = "trace", !memcmp (token, lookfor, 5)) || - (lookfor = "connect", !memcmp (token, lookfor, 7))); -} - -static int -invalid_protocol (const char *token) -{ - const char *lookfor = NULL; - - return !((lookfor = "HTTP/1.0", !memcmp (token, lookfor, 8)) || - (lookfor = "HTTP/1.1", !memcmp (token, lookfor, 8))); -} - -static char * -parse_string (char **str, char end) -{ - char *pch = *str, *p; - do { - if (*pch == end || *pch == '\0') { - size_t len = (pch - *str + 1); - p = xmalloc (len); - memcpy (p, *str, (len - 1)); - p[len - 1] = '\0'; - *str += len - 1; - return trim_str (p); - } - /* advance to the first unescaped delim */ - if (*pch == '\\') - pch++; - } while (*pch++); - return NULL; -} - -static int -parse_format (GLogItem * glog, const char *fmt, const char *date_format, - char *str) -{ - const char *p; - double serve_secs; - int special = 0; - struct tm tm; - unsigned long long bandw, serve_time; - - if (str == NULL || *str == '\0') - return 1; - - memset (&tm, 0, sizeof (tm)); - - /* iterate over the log format */ - for (p = fmt; *p; p++) { - if (*p == '%') { - special++; - continue; - } - if (special && *p != '\0') { - char *pch, *sEnd, *bEnd, *tkn = NULL, *end = NULL; - errno = 0; - bandw = 0; - serve_time = 0; - serve_secs = 0; - - switch (*p) { - /* date */ - case 'd': - if (glog->date) - return 1; - tkn = parse_string (&str, p[1]); - if (tkn == NULL) - return 1; - end = strptime (tkn, date_format, &tm); - if (end == NULL || *end != '\0') { - free (tkn); - return 1; - } - glog->date = tkn; - break; - /* remote hostname (IP only) */ - case 'h': - if (glog->host) - return 1; - tkn = parse_string (&str, p[1]); - if (tkn == NULL) - return 1; - if (invalid_ipaddr (tkn)) { - free (tkn); - return 1; - } - glog->host = tkn; - break; - /* request method */ - case 'm': - if (glog->method) - return 1; - tkn = parse_string (&str, p[1]); - if (tkn == NULL) - return 1; - if (invalid_method (tkn)) { - free (tkn); - return 1; - } - glog->method = tkn; - break; - /* request not including method or protocol */ - case 'U': - if (glog->req) - return 1; - tkn = parse_string (&str, p[1]); - if (tkn == NULL) - return 1; - glog->req = tkn; - break; - /* request protocol */ - case 'H': - if (glog->protocol) - return 1; - tkn = parse_string (&str, p[1]); - if (tkn == NULL) - return 1; - if (invalid_protocol (tkn)) { - free (tkn); - return 1; - } - glog->protocol = tkn; - break; - /* request, including method + protocol */ - case 'r': - if (glog->req) - return 1; - tkn = parse_string (&str, p[1]); - if (tkn == NULL) - return 1; - glog->req = parse_req (tkn, glog); - free (tkn); - break; - /* Status Code */ - case 's': - if (glog->status) - return 1; - tkn = parse_string (&str, p[1]); - if (tkn == NULL) - return 1; - strtol (tkn, &sEnd, 10); - if (tkn == sEnd || *sEnd != '\0' || errno == ERANGE) { - free (tkn); - return 1; - } - glog->status = tkn; - break; - /* size of response in bytes - excluding HTTP headers */ - case 'b': - if (glog->resp_size) - return 1; - tkn = parse_string (&str, p[1]); - if (tkn == NULL) - return 1; - bandw = strtol (tkn, &bEnd, 10); - if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE) - bandw = 0; - glog->resp_size = bandw; - conf.bandwidth = 1; - free (tkn); - break; - /* referrer */ - case 'R': - if (glog->ref) - return 1; - tkn = parse_string (&str, p[1]); - if (tkn == NULL) - tkn = alloc_string ("-"); - if (tkn != NULL && *tkn == '\0') { - free (tkn); - tkn = alloc_string ("-"); - } - glog->ref = tkn; - break; - /* user agent */ - case 'u': - if (glog->agent) - return 1; - tkn = parse_string (&str, p[1]); - if (tkn != NULL && *tkn != '\0') { - /* - * Make sure the user agent is decoded (i.e.: CloudFront) - * and replace all '+' with ' ' (i.e.: w3c) - */ - glog->agent = char_replace (spc_decode_url (tkn), '+', ' '); - free (tkn); - break; - } else if (tkn != NULL && *tkn == '\0') { - free (tkn); - tkn = alloc_string ("-"); - } - /* must be null */ - else { - tkn = alloc_string ("-"); - } - glog->agent = tkn; - break; - /* time taken to serve the request, in seconds */ - case 'T': - if (glog->serve_time) - return 1; - /* ignore seconds if we have microseconds */ - if (strstr (fmt, "%D") != NULL) - break; - - tkn = parse_string (&str, p[1]); - if (tkn == NULL) - return 1; - if (strchr (tkn, '.') != NULL) - serve_secs = strtod (tkn, &bEnd); - else - serve_secs = strtoull (tkn, &bEnd, 10); - - if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE) - serve_secs = 0; - /* convert it to microseconds */ - if (serve_secs > 0) - glog->serve_time = serve_secs * SECS; - else - glog->serve_time = 0; - conf.serve_usecs = 1; - free (tkn); - break; - /* time taken to serve the request, in microseconds */ - case 'D': - if (glog->serve_time) - return 1; - tkn = parse_string (&str, p[1]); - if (tkn == NULL) - return 1; - serve_time = strtoull (tkn, &bEnd, 10); - if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE) - serve_time = 0; - glog->serve_time = serve_time; - conf.serve_usecs = 1; - free (tkn); - break; - /* everything else skip it */ - default: - if ((pch = strchr (str, p[1])) != NULL) - str += pch - str; - } - if ((str == NULL) || (*str == '\0')) - return 0; - special = 0; - } else if (special && isspace (p[0])) { - return 1; - } else - str++; - } - return 0; -} - -/* process a line from the log and store it accordingly */ -static int -process_log (GLog * logger, char *line, int test) -{ - GLogItem *glog; - char buf[DATE_LEN]; - char *qmark = NULL, *req_key = NULL; - int not_found = 0; /* 404s */ - - /* make compiler happy */ - memset (buf, 0, sizeof (buf)); - - if ((line == NULL) || (*line == '\0')) { - logger->invalid++; - return 0; - } - - /* ignore comments */ - if (*line == '#' || *line == '\n') - return 0; - - if (parsing_spinner != NULL && parsing_spinner->state == SPN_RUN) - pthread_mutex_lock (&parsing_spinner->mutex); - - logger->process++; - -#ifdef TCB_BTREE - process_generic_data (ht_general_stats, "total_requests"); -#endif - - if (parsing_spinner != NULL && parsing_spinner->state == SPN_RUN) - pthread_mutex_unlock (&parsing_spinner->mutex); - - glog = init_log_item (logger); - if (parse_format (glog, conf.log_format, conf.date_format, line) == 1) { - free_logger (glog); - logger->invalid++; - -#ifdef TCB_BTREE - process_generic_data (ht_general_stats, "failed_requests"); -#endif - return 0; - } - - /* must have the following fields */ - if (glog->host == NULL || glog->date == NULL || glog->status == NULL || - glog->req == NULL) { - free_logger (glog); - logger->invalid++; - return 0; - } - - if (test) { - free_logger (glog); - return 0; - } - - convert_date (buf, glog->date, conf.date_format, "%Y%m%d", DATE_LEN); - if (buf == NULL) - return 0; - - /* ignore host */ - if (conf.ignore_host != NULL && strcmp (glog->host, conf.ignore_host) == 0) - return 0; - - /* agent will be null in cases where %u is not specified */ - if (glog->agent == NULL) - glog->agent = alloc_string ("-"); - /* process visitors, browsers, and OS */ - process_unique_data (glog->host, buf, glog->agent); - - /* process agents that are part of a host */ - if (conf.list_agents) - process_host_agents (glog->host, glog->agent); - - /* is this a 404? */ - if (!memcmp (glog->status, "404", 3)) { - not_found = 1; - } - /* check if we need to remove the request's query string */ - else if (conf.ignore_qstr) { - if ((qmark = strchr (glog->req, '?')) != NULL) { - if ((qmark - glog->req) > 0) - *qmark = '\0'; - } - } - - req_key = xstrdup (glog->req); - /* include HTTP method/protocol to request */ - if (conf.append_method && glog->method) { - str_to_upper (glog->method); - append_method_to_request (&req_key, glog->method); - } - if (conf.append_protocol && glog->protocol) { - str_to_upper (glog->protocol); - append_protocol_to_request (&req_key, glog->protocol); - } - if ((conf.append_method) || (conf.append_protocol)) - req_key = deblank (req_key); - - /* process 404s */ - if (not_found) - process_request (ht_not_found_requests, req_key, glog); - /* process static files */ - else if (verify_static_content (glog->req)) - process_request (ht_requests_static, req_key, glog); - /* process regular files */ - else - process_request (ht_requests, req_key, glog); - - /* process referrers */ - process_referrers (glog->ref); - /* process status codes */ - process_generic_data (ht_status_code, glog->status); - /* process hosts */ - process_generic_data (ht_hosts, glog->host); - /* process bandwidth */ - process_request_meta (ht_date_bw, buf, glog->resp_size); - process_request_meta (ht_file_bw, req_key, glog->resp_size); - process_request_meta (ht_host_bw, glog->host, glog->resp_size); - /* process time taken to serve the request, in microseconds */ - process_request_meta (ht_file_serve_usecs, req_key, glog->serve_time); - process_request_meta (ht_host_serve_usecs, glog->host, glog->serve_time); - logger->resp_size += glog->resp_size; -#ifdef TCB_BTREE - process_request_meta (ht_general_stats, "bandwidth", glog->resp_size); -#endif - - free_logger (glog); - free (req_key); - return 0; -} - -/* entry point to parse the log line by line */ -int -parse_log (GLog ** logger, char *tail, int n) -{ - FILE *fp = NULL; - char line[LINE_BUFFER]; - int i = 0, test = -1 == n ? 0 : 1; - - if (conf.date_format == NULL || *conf.date_format == '\0') - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "No date format was found on your conf file."); - - if (conf.log_format == NULL || *conf.log_format == '\0') - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "No log format was found on your conf file."); - - if (tail != NULL) { - if (process_log ((*logger), tail, test)) - return 1; - return 0; - } - - if (conf.ifile == NULL) { - fp = stdin; - (*logger)->piping = 1; - } - - /* make sure we can open the log (if not reading from stdin) */ - if (!(*logger)->piping && (fp = fopen (conf.ifile, "r")) == NULL) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, strerror (errno)); - - while (fgets (line, LINE_BUFFER, fp) != NULL) { - if (n >= 0 && i++ == n) - break; - if (process_log ((*logger), line, test)) { - if (!(*logger)->piping) - fclose (fp); - return 1; - } - } - /* definitely not portable! */ - if ((*logger)->piping) - freopen ("/dev/tty", "r", stdin); - - if (!(*logger)->piping) - fclose (fp); - return 0; -} - -/* make sure we have valid hits */ -int -test_format (GLog * logger) -{ - if (parse_log (&logger, NULL, 20)) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Error while processing file"); - - if ((logger->process == 0) || (logger->process == logger->invalid)) - return 1; - return 0; -} - -/* sort raw data for the first run (default sort) */ -GRawData * -sort_raw_data (GRawData * raw_data, GModule module, int ht_size) -{ - switch (module) { - case VISITORS: - qsort (raw_data->items, ht_size, sizeof (GRawDataItem), cmp_raw_data_desc); - break; - case OS: - qsort (raw_data->items, ht_size, sizeof (GRawDataItem), - cmp_raw_os_num_desc); - break; - case BROWSERS: - qsort (raw_data->items, ht_size, sizeof (GRawDataItem), - cmp_raw_browser_num_desc); - break; -#ifdef HAVE_LIBGEOIP - case GEO_LOCATION: - qsort (raw_data->items, ht_size, sizeof (GRawDataItem), - cmp_raw_geo_num_desc); - break; -#endif - default: - qsort (raw_data->items, ht_size, sizeof (GRawDataItem), cmp_raw_num_desc); - } - - return raw_data; -} diff --git a/parser.h b/parser.h deleted file mode 100644 index 786039fe47..0000000000 --- a/parser.h +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#ifndef PARSER_H_INCLUDED -#define PARSER_H_INCLUDED - -#define UKEY_BUFFER 2048 -#define LINE_BUFFER 4096 -#define BW_HASHTABLES 3 -#define KEY_FOUND 1 -#define KEY_NOT_FOUND -1 - -#include "commons.h" - -typedef struct GLogItem_ -{ - char *agent; - char *date; - char *host; - char *ref; - char *method; - char *protocol; - char *req; - char *status; - unsigned long long resp_size; - unsigned long long serve_time; -} GLogItem; - -typedef struct GLog_ -{ - unsigned int invalid; - unsigned int offset; - unsigned int process; - unsigned long long resp_size; - unsigned short piping; - GLogItem *items; -} GLog; - -typedef struct GRawDataItem_ -{ - void *key; - void *value; -} GRawDataItem; - -typedef struct GRawData_ -{ - GRawDataItem *items; /* data */ - GModule module; /* current module */ - int idx; /* first level index */ - int size; /* total num of items on ht */ -} GRawData; - -GLog *init_log (void); -GLogItem *init_log_item (GLog * logger); -GRawData *new_grawdata (void); -GRawData *sort_raw_data (GRawData * raw_data, GModule module, int ht_size); -GRawDataItem *new_grawdata_item (unsigned int size); -int cmp_bw_asc (const void *a, const void *b); -int cmp_bw_desc (const void *a, const void *b); -int cmp_data_asc (const void *a, const void *b); -int cmp_data_desc (const void *a, const void *b); -int cmp_mthd_asc (const void *a, const void *b); -int cmp_mthd_desc (const void *a, const void *b); -int cmp_num_asc (const void *a, const void *b); -int cmp_num_desc (const void *a, const void *b); -int cmp_proto_asc (const void *a, const void *b); -int cmp_proto_desc (const void *a, const void *b); -int cmp_raw_browser_num_desc (const void *a, const void *b); -int cmp_raw_data_desc (const void *a, const void *b); -int cmp_raw_geo_num_desc (const void *a, const void *b); -int cmp_raw_num_desc (const void *a, const void *b); -int cmp_raw_os_num_desc (const void *a, const void *b); -int cmp_usec_asc (const void *a, const void *b); -int cmp_usec_desc (const void *a, const void *b); -int parse_log (GLog ** logger, char *tail, int n); -int test_format (GLog * logger); -void free_raw_data (GRawData * raw_data); -void reset_struct (GLog * logger); - -#endif diff --git a/po/LINGUAS b/po/LINGUAS new file mode 100644 index 0000000000..11e42e312f --- /dev/null +++ b/po/LINGUAS @@ -0,0 +1,12 @@ +de +es +fr +ja +ko +sv +zh_CN +pt_BR +ru +uk +it + diff --git a/po/Makevars b/po/Makevars new file mode 100644 index 0000000000..a3908fd89c --- /dev/null +++ b/po/Makevars @@ -0,0 +1,79 @@ +# Makefile variables for PO directory in any package using GNU gettext. + +# Usually the message domain is the same as the package name. +DOMAIN = $(PACKAGE) + +# These two variables depend on the location of this directory. +subdir = po +top_builddir = .. +AM_CPPFLAGS = -I. -I$(srcdir) + +# These options get passed to xgettext. +XGETTEXT_OPTIONS = --from-code=UTF-8 --keyword=_ --keyword=N_ + +# This is the copyright holder that gets inserted into the header of the +# $(DOMAIN).pot file. Set this to the copyright holder of the surrounding +# package. (Note that the msgstr strings, extracted from the package's +# sources, belong to the copyright holder of the package.) Translators are +# expected to transfer the copyright for their translations to this person +# or entity, or to disclaim their copyright. The empty string stands for +# the public domain; in this case the translators are expected to disclaim +# their copyright. +COPYRIGHT_HOLDER = Free Software Foundation, Inc. + +# This tells whether or not to prepend "GNU " prefix to the package +# name that gets inserted into the header of the $(DOMAIN).pot file. +# Possible values are "yes", "no", or empty. If it is empty, try to +# detect it automatically by scanning the files in $(top_srcdir) for +# "GNU packagename" string. +PACKAGE_GNU = + +# This is the email address or URL to which the translators shall report +# bugs in the untranslated strings: +# - Strings which are not entire sentences, see the maintainer guidelines +# in the GNU gettext documentation, section 'Preparing Strings'. +# - Strings which use unclear terms or require additional context to be +# understood. +# - Strings which make invalid assumptions about notation of date, time or +# money. +# - Pluralisation problems. +# - Incorrect English spelling. +# - Incorrect formatting. +# It can be your email address, or a mailing list address where translators +# can write to without being subscribed, or the URL of a web page through +# which the translators can contact you. +MSGID_BUGS_ADDRESS = hello@goaccess.io + +# This is the list of locale categories, beyond LC_MESSAGES, for which the +# message catalogs shall be used. It is usually empty. +EXTRA_LOCALE_CATEGORIES = + +# This tells whether the $(DOMAIN).pot file contains messages with an 'msgctxt' +# context. Possible values are "yes" and "no". Set this to yes if the +# package uses functions taking also a message context, like pgettext(), or +# if in $(XGETTEXT_OPTIONS) you define keywords with a context argument. +USE_MSGCTXT = no + +# These options get passed to msgmerge. +# Useful options are in particular: +# --previous to keep previous msgids of translated messages, +# --quiet to reduce the verbosity. +MSGMERGE_OPTIONS = + +# These options get passed to msginit. +# If you want to disable line wrapping when writing PO files, add +# --no-wrap to MSGMERGE_OPTIONS, XGETTEXT_OPTIONS, and +# MSGINIT_OPTIONS. +MSGINIT_OPTIONS = + +# This tells whether or not to regenerate a PO file when $(DOMAIN).pot +# has changed. Possible values are "yes" and "no". Set this to no if +# the POT file is checked in the repository and the version control +# program ignores timestamps. +PO_DEPENDS_ON_POT = yes + +# This tells whether or not to forcibly update $(DOMAIN).pot and +# regenerate PO files on "make dist". Possible values are "yes" and +# "no". Set this to no if the POT file and PO files are maintained +# externally. +DIST_DEPENDS_ON_UPDATE_PO = yes diff --git a/po/POTFILES.in b/po/POTFILES.in new file mode 100644 index 0000000000..99bde5c285 --- /dev/null +++ b/po/POTFILES.in @@ -0,0 +1,2 @@ +# List of source files which contain translatable strings. +src/labels.h diff --git a/po/de.po b/po/de.po new file mode 100644 index 0000000000..38184ed738 --- /dev/null +++ b/po/de.po @@ -0,0 +1,1101 @@ +msgid "" +msgstr "" +"Project-Id-Version: \n" +"Report-Msgid-Bugs-To: hello@goaccess.io\n" +"POT-Creation-Date: 2024-04-11 20:17-0500\n" +"PO-Revision-Date: 2019-05-05 16:03+0200\n" +"Last-Translator: Axel Wehner \n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.2.1\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: src/labels.h:45 +msgid "en" +msgstr "de" + +#: src/labels.h:48 +msgid "Exp. Panel" +msgstr "Kachel öffnen" + +#: src/labels.h:49 +msgid "Help" +msgstr "Hilfe" + +#: src/labels.h:50 +msgid "Quit" +msgstr "Schließen" + +#: src/labels.h:51 +msgid "Total" +msgstr "Gesamt" + +#: src/labels.h:54 +msgid "[x] ASC [ ] DESC" +msgstr "[x] Aufsteigend [ ] Absteigend" + +#: src/labels.h:55 +msgid "[ ] ASC [x] DESC" +msgstr "[ ] Aufsteigend [x] Absteigend" + +#: src/labels.h:58 +#, c-format +msgid "[Active Panel: %1$s]" +msgstr "[Aktive Kachel: %1$s]" + +#: src/labels.h:59 +msgid "[q]uit GoAccess" +msgstr "[q] GoAccess schließen" + +#: src/labels.h:60 +msgid "[?] Help [Enter] Exp. Panel" +msgstr "[?] Hilfe [Eingabe] Kachel öffnen" + +#: src/labels.h:61 +msgid "Dashboard" +msgstr "Übersicht" + +#: src/labels.h:62 +msgid "Dashboard - Overall Analyzed Requests" +msgstr "Übersicht – Analysierte Anfragen gesamt" + +#: src/labels.h:63 +msgid "Overall Analyzed Requests" +msgstr "Analysierte Anfragen gesamt" + +#: src/labels.h:65 src/labels.h:86 +msgid "Tx. Amount" +msgstr "Tx. Menge" + +#: src/labels.h:66 +msgid "Date/Time" +msgstr "Datum/Zeit" + +#: src/labels.h:67 +msgid "Excl. IP Hits" +msgstr "Ausgeschl. IP-Treffer" + +#: src/labels.h:68 +msgid "Failed Requests" +msgstr "Fehlgeschlagene Anfragen" + +#: src/labels.h:69 +msgid "Log Parsing Time" +msgstr "Loggen der Übertragungszeit " + +#: src/labels.h:70 +msgid "Log Size" +msgstr "Log-Größe" + +#: src/labels.h:71 +msgid "Log Source" +msgstr "Log-Quelle" + +#: src/labels.h:72 src/labels.h:187 +msgid "Referrers" +msgstr "Verweise" + +#: src/labels.h:73 +msgid "Total Requests" +msgstr "Anfragen gesamt" + +#: src/labels.h:74 +msgid "Static Files" +msgstr "Statische Dateien" + +#: src/labels.h:75 src/labels.h:159 +msgid "Not Found" +msgstr "Nicht gefunden" + +#: src/labels.h:76 +msgid "Requested Files" +msgstr "Angefragte Dateien" + +#: src/labels.h:77 +msgid "Unique Visitors" +msgstr "Eindeutige Besucher" + +#: src/labels.h:78 +msgid "Valid Requests" +msgstr "Gültige Anfragen" + +#: src/labels.h:81 +msgid "Hits" +msgstr "Zugriffe" + +#: src/labels.h:82 +msgid "h%" +msgstr "h%" + +#: src/labels.h:83 src/labels.h:110 +msgid "Visitors" +msgstr "Besucher" + +#: src/labels.h:84 +msgid "Vis." +msgstr "Bes." + +#: src/labels.h:85 +msgid "v%" +msgstr "v%" + +# T.S. = Time Serve (The time taken to serve the request) +# Vz = Verarbeitungszeit +# Wer hier Rat weiß, bitte verfeinern. +#: src/labels.h:87 +#, fuzzy +msgid "Avg. T.S." +msgstr "Durchschn. Vz." + +#: src/labels.h:88 +#, fuzzy +msgid "Cum. T.S." +msgstr "Kum. Vz." + +#: src/labels.h:89 +#, fuzzy +msgid "Max. T.S." +msgstr "Max. Vz." + +#: src/labels.h:90 +msgid "Method" +msgstr "Methode" + +#: src/labels.h:91 +msgid "Mtd" +msgstr "Meth" + +#: src/labels.h:92 +msgid "Protocol" +msgstr "Protokoll" + +#: src/labels.h:93 +msgid "Proto" +msgstr "Prot" + +#: src/labels.h:94 +msgid "City" +msgstr "Stadt" + +#: src/labels.h:95 src/labels.h:211 src/labels.h:215 +msgid "ASN" +msgstr "ASN" + +#: src/labels.h:96 +msgid "Country" +msgstr "Land" + +#: src/labels.h:97 +msgid "Hostname" +msgstr "Hostname" + +#: src/labels.h:98 +msgid "Data" +msgstr "Daten" + +#: src/labels.h:100 +msgid "Hits/Visitors" +msgstr "Zugriffe/Besucher" + +#: src/labels.h:104 +msgid "Unique visitors per day" +msgstr "Eindeutige Besucher pro Tag" + +#: src/labels.h:106 +msgid "Unique visitors per day - Including spiders" +msgstr "Eindeutige Besucher pro Tag – inklusive Spiders/Bots" + +#: src/labels.h:108 +msgid "Hits having the same IP, date and agent are a unique visit." +msgstr "" +"Zugriffe mit derselben IP, Datum und User-Agent sind ein eindeutiger Besuch." + +#: src/labels.h:113 +msgid "Requested Files (URLs)" +msgstr "Angefragte Dateien (URLs)" + +#: src/labels.h:115 +msgid "Top requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Häufigste Anfragen sortiert nach Zugriffen [, avgts, cumts, maxts, mthd, " +"proto]" + +#: src/labels.h:117 +msgid "Requests" +msgstr "Anfragen" + +#: src/labels.h:120 src/labels.h:124 +msgid "Static Requests" +msgstr "Statische Anfragen" + +#: src/labels.h:122 +msgid "Top static requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Häufigste statische Anfragen sortiert nach Zugriffen [, avgts, cumts, maxts, " +"mthd, proto]" + +#: src/labels.h:127 +msgid "Time Distribution" +msgstr "Zeitverteilung" + +#: src/labels.h:129 +msgid "Data sorted by hour [, avgts, cumts, maxts]" +msgstr "Daten sortiert nach Stunde [, avgts, cumts, maxts]" + +#: src/labels.h:131 +msgid "Time" +msgstr "Zeit" + +#: src/labels.h:134 src/labels.h:138 +msgid "Virtual Hosts" +msgstr "Virtuelle Hosts" + +#: src/labels.h:136 src/labels.h:143 src/labels.h:150 +msgid "Data sorted by hits [, avgts, cumts, maxts]" +msgstr "Daten sortiert nach Zugriffen [, avgts, cumts, maxts]" + +#: src/labels.h:141 +msgid "Remote User (HTTP authentication)" +msgstr "Entfernter Nutzer (HTTP-Authentifizierung)" + +#: src/labels.h:145 +msgid "Remote User" +msgstr "Entfernter Nutzer" + +#: src/labels.h:148 +msgid "The cache status of the object served" +msgstr "Cache-Status des übertragenen Objekts" + +#: src/labels.h:152 +msgid "Cache Status" +msgstr "Cache-Status" + +#: src/labels.h:155 +msgid "Not Found URLs (404s)" +msgstr "Nicht gefundene URLs (404er)" + +#: src/labels.h:157 +msgid "Top not found URLs sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Häufigste nicht gefundene URLs sortiert nach Zugriffen [, avgts, cumts, " +"maxts, mthd, proto]" + +#: src/labels.h:162 +msgid "Visitor Hostnames and IPs" +msgstr "Besucher-Hostnamen und -IPs" + +#: src/labels.h:164 +msgid "Top visitor hosts sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Häufigste Besucher-Hosts sortiert nach Zugriffen [, avgts, cumts, maxts]" + +#: src/labels.h:166 +msgid "Hosts" +msgstr "Hosts" + +#: src/labels.h:169 +msgid "Operating Systems" +msgstr "Betriebssysteme" + +#: src/labels.h:171 +msgid "Top Operating Systems sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Häufigste Betriebssysteme sortiert nach Zugriffen [, avgts, cumts, maxts]" + +#: src/labels.h:173 +msgid "OS" +msgstr "OS" + +#: src/labels.h:176 src/labels.h:180 +msgid "Browsers" +msgstr "Browser" + +#: src/labels.h:178 +msgid "Top Browsers sorted by hits [, avgts, cumts, maxts]" +msgstr "Häufigste Browser sortiert nach Zugriffen [, avgts, cumts, maxts]" + +#: src/labels.h:183 +#, fuzzy +msgid "Referrer URLs" +msgstr "Verweis-URLs" + +#: src/labels.h:185 +#, fuzzy +msgid "Top Requested Referrers sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Häufigste ausgehende Verweise sortiert nach Zugriffen [, avgts, cumts, maxts]" + +#: src/labels.h:190 src/labels.h:194 +msgid "Referring Sites" +msgstr "Verweisende Seiten" + +#: src/labels.h:192 +msgid "Top Referring Sites sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Häufigste eingehende Verweise sortiert nach Zugriffen [, avgts, cumts, maxts]" + +#: src/labels.h:197 +msgid "Keyphrases from Google's search engine" +msgstr "Schlüsselwörter von Googles Suchmaschine" + +#: src/labels.h:199 +msgid "Top Keyphrases sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Häufigste Schlüsselwörter sortiert nach Zugriffen [, avgts, cumts, maxts]" + +#: src/labels.h:201 +msgid "Keyphrases" +msgstr "Schlüsselwörter" + +#: src/labels.h:204 src/labels.h:208 +msgid "Geo Location" +msgstr "Geo-Standort" + +#: src/labels.h:206 +msgid "Continent > Country sorted by unique hits [, avgts, cumts, maxts]" +msgstr "" +"Kontinent > Land sortiert nach eindeutigen Zugriffen [, avgts, cumts, maxts]" + +#: src/labels.h:213 +msgid "Autonomous System Numbers/Organizations (ASNs)" +msgstr "Autonome Systemnummern / Organisationen (ASNs)" + +#: src/labels.h:218 +msgid "HTTP Status Codes" +msgstr "HTTP-Statuscodes" + +#: src/labels.h:220 +msgid "Top HTTP Status Codes sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Häufigste HTTP-Status-Codes sortiert nach Zugriffen [, avgts, cumts, maxts]" + +#: src/labels.h:222 +msgid "Status Codes" +msgstr "Statuscodes" + +#: src/labels.h:225 src/labels.h:229 +msgid "MIME Types" +msgstr "MIME-Typen" + +#: src/labels.h:227 +msgid "File types shipped out" +msgstr "Versendete Dateitypen" + +#: src/labels.h:232 +msgid "Encryption settings" +msgstr "Verschlüsselungsoptionen" + +#: src/labels.h:234 +msgid "TLS version and picked algorithm" +msgstr "TLS-Version und gewählter Algorithmus" + +#: src/labels.h:236 +msgid "TLS Settings" +msgstr "TLS-Optionen" + +#: src/labels.h:240 +msgid "[ ] case sensitive" +msgstr "[ ] Groß- und Kleinschreibung" + +#: src/labels.h:242 +msgid "[x] case sensitive" +msgstr "[x] Groß- und Kleinschreibung" + +#: src/labels.h:244 +msgid "Regex allowed - ^g to cancel - TAB switch case" +msgstr "" +"Regex erlaubt – ^g zum Abbrechen – TAB zum Wechseln zwischen Groß-/" +"Kleinschreibung" + +#: src/labels.h:246 +msgid "Find pattern in all views" +msgstr "Finde Muster in allen Ansichten" + +#: src/labels.h:250 +msgid "Log Format Configuration" +msgstr "Log-Format Konfiguration" + +#: src/labels.h:252 +msgid "[SPACE] to toggle - [ENTER] to proceed - [q] to quit" +msgstr "[LEERTASTE] auswählen – [EINGABE] weiter – [q] schließen" + +#: src/labels.h:254 +msgid "Log Format - [c] to add/edit format" +msgstr "Log-Format – [c] zum Hinzufügen/Bearbeiten des Formats" + +#: src/labels.h:256 +msgid "Date Format - [d] to add/edit format" +msgstr "Datumsformat – [d] zum Hinzufügen/Bearbeiten des Formats" + +#: src/labels.h:258 +msgid "Time Format - [t] to add/edit format" +msgstr "Zeitformat – [t] zum Hinzufügen/Bearbeiten des Formats" + +#: src/labels.h:260 src/labels.h:264 +msgid "[UP/DOWN] to scroll - [q] to close window" +msgstr "[HOCH/RUNTER] zum Scrollen – [q] zum Schließen des Fensters" + +#: src/labels.h:266 +#, c-format +msgid "User Agents for %1$s" +msgstr "User-Agents für %1$s" + +#: src/labels.h:270 +msgid "Scheme Configuration" +msgstr "Schema-Konfiguration" + +#: src/labels.h:272 +msgid "[ENTER] to use scheme - [q]uit" +msgstr "[EINGABE] Schema verwenden – [q] schließen" + +#: src/labels.h:276 +msgid "Sort active module by" +msgstr "Aktives Modul sortieren nach" + +#: src/labels.h:278 +msgid "[ENTER] select - [TAB] sort - [q]uit" +msgstr "[EINGABE] auswählen – [TAB] sortieren – [q] schließen" + +#: src/labels.h:282 +msgid "GoAccess Quick Help" +msgstr "GoAccess' schnelle Hilfe" + +#: src/labels.h:284 +msgid "[UP/DOWN] to scroll - [q] to quit" +msgstr "[HOCH/RUNTER] zum Scrollen – [q] zum Schließen" + +#: src/labels.h:288 +msgid "In-Memory with On-Disk Persistent Storage." +msgstr "Arbeitsspeicherintern mit persistentem Festplattenspeicher" + +#: src/labels.h:292 +msgid "Format Errors - Verify your log/date/time format" +msgstr "Formatfehler – prüfen Sie das Log-/Datums-/Zeitformat" + +#: src/labels.h:294 +msgid "No date format was found on your conf file." +msgstr "Es wurde kein Datumsformat in der Konfigurationsdatei gefunden." + +#: src/labels.h:296 +msgid "No log format was found on your conf file." +msgstr "Es wurde kein Log-Format in der Konfigurationsdatei gefunden." + +#: src/labels.h:298 +msgid "No time format was found on your conf file." +msgstr "Es wurde kein Zeitformat in der Konfigurationsdatei gefunden." + +#: src/labels.h:300 +msgid "No default config file found." +msgstr "Keine Standard-Konfigurationsdatei gefunden." + +#: src/labels.h:302 +msgid "You may specify one with" +msgstr "Sie übergeben eine mit" + +#: src/labels.h:304 +msgid "producing the following errors" +msgstr "führen zu folgenden Fehlern" + +#: src/labels.h:306 +#, c-format +msgid "Parsed %1$d lines" +msgstr "%1$d Zeilen analysiert" + +#: src/labels.h:308 +msgid "Please report it by opening an issue on GitHub" +msgstr "Bitte melden Sie den Vorfall und erstatten Sie Bericht auf GitHub" + +#: src/labels.h:310 +msgid "Select a time format." +msgstr "Wählen Sie ein Zeitformat." + +#: src/labels.h:312 +msgid "Select a date format." +msgstr "Wählen Sie ein Datumsformat." + +#: src/labels.h:314 +msgid "Select a log format." +msgstr "Wählen Sie ein Log-Format." + +#: src/labels.h:316 +#, c-format +msgid "'%1$s' panel is disabled" +msgstr "Kachel „'%1$s'“ ist deaktiviert" + +#: src/labels.h:318 +msgid "No input data was provided nor there's data to restore." +msgstr "Keine Eingabedaten übergeben und keine wiederherzustellende Daten" + +#: src/labels.h:320 +msgid "Unable to allocate memory for a log instance." +msgstr "" + +#: src/labels.h:322 +msgid "Unable to find the given log." +msgstr "" + +#: src/labels.h:326 +msgid "For more details visit" +msgstr "Für mehr Details besuche" + +#: src/labels.h:328 +msgid "Last Updated" +msgstr "Zuletzt aktualisiert" + +#: src/labels.h:330 +msgid "WebSocket server ready to accept new client connections" +msgstr "WebSocket-Server bereit, um neue Client-Verbindungen anzunehmen" + +#: src/labels.h:333 +msgid "The following options can also be supplied to the command" +msgstr "Dem Befehl können auch folgende Optionen mitgegeben werden" + +#: src/labels.h:335 +msgid "Examples can be found by running" +msgstr "Beispiele können gefunden werden über" + +#: src/labels.h:338 +msgid "Server Statistics" +msgstr "Serverstatistik" + +#: src/labels.h:340 +msgid "Theme" +msgstr "Design (Theme)" + +#: src/labels.h:342 +msgid "Dark Gray" +msgstr "Dunkelgrau (Dark Gray)" + +#: src/labels.h:344 +msgid "Bright" +msgstr "Hell (Bright)" + +#: src/labels.h:346 +msgid "Dark Blue" +msgstr "Dunkelblau (Dark Blue)" + +#: src/labels.h:348 +msgid "Dark Purple" +msgstr "Dunkelviolett (Dark Purple)" + +#: src/labels.h:350 +msgid "Panels" +msgstr "Kacheln" + +#: src/labels.h:352 +msgid "Items per Page" +msgstr "Einträge pro Seite" + +#: src/labels.h:354 +msgid "Tables" +msgstr "Tabellen" + +#: src/labels.h:356 +msgid "Display Tables" +msgstr "Zeige Tabellen" + +#: src/labels.h:358 +msgid "Auto-Hide on Small Devices" +msgstr "Auf kleinen Geräten automatisch verstecken" + +#: src/labels.h:360 +msgid "Automatically hide tables on small screen devices" +msgstr "Tabellen auf kleinen Bildschirmen automatisch verstecken" + +#: src/labels.h:362 +msgid "Toggle Panel" +msgstr "Kachel umschalten" + +#: src/labels.h:364 +msgid "Layout" +msgstr "Layout" + +#: src/labels.h:366 +msgid "Horizontal" +msgstr "Horizontal" + +#: src/labels.h:368 +msgid "Vertical" +msgstr "Vertikal" + +#: src/labels.h:370 +msgid "WideScreen" +msgstr "Breitbild" + +#: src/labels.h:372 +msgid "File Options" +msgstr "Dateioptionen" + +#: src/labels.h:374 +msgid "Export as JSON" +msgstr "Als JSON exportieren" + +#: src/labels.h:376 +msgid "Panel Options" +msgstr "Kachel-Optionen" + +#: src/labels.h:378 +msgid "Previous" +msgstr "Vorherige" + +#: src/labels.h:380 +msgid "Next" +msgstr "Nächste" + +#: src/labels.h:382 +msgid "First" +msgstr "Erste" + +#: src/labels.h:384 +msgid "Last" +msgstr "Letzte" + +#: src/labels.h:386 +msgid "Chart Options" +msgstr "Diagrammoptionen" + +#: src/labels.h:388 +msgid "Chart" +msgstr "Diagramm" + +#: src/labels.h:390 +msgid "Type" +msgstr "Typ" + +#: src/labels.h:392 +msgid "Area Spline" +msgstr "Spline-Kurve" + +#: src/labels.h:394 +msgid "Bar" +msgstr "Balken" + +#: src/labels.h:396 +msgid "World Map" +msgstr "" + +#: src/labels.h:398 +msgid "Plot Metric" +msgstr "Plot-Metrik" + +#: src/labels.h:400 +msgid "Table Columns" +msgstr "Tabellenspalten" + +#: src/labels.h:404 +msgid "0xx Unofficial Codes" +msgstr "" + +#: src/labels.h:406 +msgid "1xx Informational" +msgstr "1xx informativ" + +#: src/labels.h:408 +msgid "2xx Success" +msgstr "2xx Erfolg" + +#: src/labels.h:410 +msgid "3xx Redirection" +msgstr "3xx Umleitung" + +#: src/labels.h:412 +msgid "4xx Client Errors" +msgstr "4xx Client-Fehler" + +#: src/labels.h:414 +msgid "5xx Server Errors" +msgstr "5xx Serverfehler" + +#: src/labels.h:417 +msgid "0 - Caddy: Unhandled - No configured routes" +msgstr "" + +#: src/labels.h:419 +msgid "100 - Continue: Server received the initial part of the request" +msgstr "" +"100 – weitermachen: Der Server hat den ersten Teil der Anfrage erhalten" + +#: src/labels.h:421 +msgid "101 - Switching Protocols: Client asked to switch protocols" +msgstr "101 – Protokollwechsel: Client gebeten, die Protokolle zu wechseln" + +#: src/labels.h:423 +msgid "200 - OK: The request sent by the client was successful" +msgstr "200 – OK: Die vom Client gesendete Anfrage war erfolgreich" + +#: src/labels.h:425 +msgid "201 - Created: The request has been fulfilled and created" +msgstr "201 –eErstellt: Die Anforderung wurde erfüllt und angelegt" + +#: src/labels.h:427 +msgid "202 - Accepted: The request has been accepted for processing" +msgstr "202 – akzeptiert: Die Anfrage wurde zur Bearbeitung angenommen" + +#: src/labels.h:429 +msgid "203 - Non-authoritative Information: Response from a third party" +msgstr "203 – nicht autorisierte Informationen: Antwort eines Dritten" + +#: src/labels.h:431 +msgid "204 - No Content: Request did not return any content" +msgstr "204 – kein Inhalt: Die Anfrage hat keinen Inhalt zurückgegeben" + +#: src/labels.h:433 +msgid "205 - Reset Content: Server asked the client to reset the document" +msgstr "" +"205 – Inhalt zurücksetzen: Der Server hat den Client gebeten, das Dokument " +"zurückzusetzen" + +#: src/labels.h:435 +msgid "206 - Partial Content: The partial GET has been successful" +msgstr "206 – Teilinhalt: Der partielle GET war erfolgreich" + +#: src/labels.h:437 +msgid "207 - Multi-Status: WebDAV; RFC 4918" +msgstr "207 – Mehrfach-Status: WebDAV; RFC 4918" + +#: src/labels.h:439 +msgid "208 - Already Reported: WebDAV; RFC 5842" +msgstr "208 - bereits gemeldet: WebDAV; RFC 5842" + +#: src/labels.h:441 +msgid "218 - This is fine: Apache servers. A catch-all error condition" +msgstr "" + +#: src/labels.h:443 +msgid "300 - Multiple Choices: Multiple options for the resource" +msgstr "300 – Mehrfachauswahl: mehrere Optionen für die Ressource" + +#: src/labels.h:445 +msgid "301 - Moved Permanently: Resource has permanently moved" +msgstr "301 – dauerhaft verschoben: Ressource wurde dauerhaft verschoben" + +#: src/labels.h:447 +msgid "302 - Moved Temporarily (redirect)" +msgstr "302 – vorübergehend verschoben (Umleitung)" + +#: src/labels.h:449 +msgid "303 - See Other Document: The response is at a different URI" +msgstr "303 – siehe anderes Dokument: Die Antwort ist unter einem anderen URI" + +#: src/labels.h:451 +msgid "304 - Not Modified: Resource has not been modified" +msgstr "304 – nicht geändert: Die Ressource wurde nicht verändert" + +#: src/labels.h:453 +msgid "305 - Use Proxy: Can only be accessed through the proxy" +msgstr "305 – Proxy verwenden: Zugriff nur über den Proxy möglich" + +#: src/labels.h:455 +msgid "307 - Temporary Redirect: Resource temporarily moved" +msgstr "307 – temporäre Umleitung: Ressource vorübergehend verschoben" + +#: src/labels.h:457 +#, fuzzy +msgid "308 - Permanent Redirect" +msgstr "402 – dauerhafte Umleitung" + +#: src/labels.h:459 +msgid "400 - Bad Request: The syntax of the request is invalid" +msgstr "400 – fehlerhafte Anfrage: Die Syntax der Anfrage ist ungültig" + +#: src/labels.h:461 +msgid "401 - Unauthorized: Request needs user authentication" +msgstr "" +"401 – nicht autorisiert: Anforderung erfordert Benutzerauthentifizierung" + +#: src/labels.h:463 +msgid "402 - Payment Required" +msgstr "402 – Zahlung erforderlich" + +#: src/labels.h:465 +msgid "403 - Forbidden: Server is refusing to respond to it" +msgstr "403 – verboten: Der Server weigert sich, darauf zu reagieren" + +#: src/labels.h:467 +msgid "404 - Not Found: Requested resource could not be found" +msgstr "" +"404 – nicht gefunden: Angefragte Ressource konnte nicht gefunden werden" + +#: src/labels.h:469 +msgid "405 - Method Not Allowed: Request method not supported" +msgstr "405 – Methode nicht erlaubt: Anforderungsmethode nicht unterstützt" + +#: src/labels.h:471 +msgid "406 - Not Acceptable" +msgstr "406 – nicht zulässig" + +#: src/labels.h:473 +msgid "407 - Proxy Authentication Required" +msgstr "407 – Proxy-Authentifizierung erforderlich" + +#: src/labels.h:475 +msgid "408 - Request Timeout: Server timed out waiting for the request" +msgstr "" +"408 – Zeitüberschreitung der Anfrage: Zeitüberschreitung des Server beim " +"Warten auf die Anfrage" + +#: src/labels.h:477 +msgid "409 - Conflict: Conflict in the request" +msgstr "409 – Konflikt: Konflikt in der Anfrage" + +#: src/labels.h:479 +msgid "410 - Gone: Resource requested is no longer available" +msgstr "410 – verschwunden: Angeforderte Ressource ist nicht mehr verfügbar" + +#: src/labels.h:481 +msgid "411 - Length Required: Invalid Content-Length" +msgstr "411 – erforderliche Länge: ungültige Inhaltslänge" + +#: src/labels.h:483 +msgid "412 - Precondition Failed: Server does not meet preconditions" +msgstr "" +"412 – Vorbedingung fehlgeschlagen: Server erfüllt nicht die Voraussetzungen" + +#: src/labels.h:485 +msgid "413 - Payload Too Large" +msgstr "413 – Nutzdaten zu groß" + +#: src/labels.h:487 +msgid "414 - Request-URI Too Long" +msgstr "414 – Anfrage-URI zu lang" + +#: src/labels.h:489 +msgid "415 - Unsupported Media Type: Media type is not supported" +msgstr "" +"415 – nicht unterstützter Medientyp: Der Medientyp wird nicht unterstützt" + +#: src/labels.h:491 +msgid "416 - Requested Range Not Satisfiable: Cannot supply that portion" +msgstr "" +"416 – angeforderter Bereich nicht erfüllbar: Dieser Teil kann nicht " +"geliefert werden" + +#: src/labels.h:493 +msgid "417 - Expectation Failed" +msgstr "417 – Erwartung fehlgeschlagen" + +#: src/labels.h:495 +#, fuzzy +msgid "418 - I'm a teapot" +msgstr "418 – Ich bin ein Teekännchen" + +#: src/labels.h:497 +msgid "419 - Page Expired: Laravel Framework when a CSRF Token is missing" +msgstr "" + +#: src/labels.h:499 +msgid "420 - Method Failure: Spring Framework when a method has failed" +msgstr "" + +#: src/labels.h:501 +msgid "421 - Misdirected Request" +msgstr "421 – fehlgesteuerte Anfrage" + +#: src/labels.h:503 +msgid "422 - Unprocessable Entity due to semantic errors: WebDAV" +msgstr "" +"422 – nicht verarbeitbare Entität aufgrund von semantischen Fehlern: WebDAV" + +#: src/labels.h:505 +msgid "423 - The resource that is being accessed is locked" +msgstr "423 – die Ressource, auf die zugegriffen wird, ist gesperrt" + +#: src/labels.h:507 +msgid "424 - Failed Dependency: WebDAV" +msgstr "424 – fehlgeschlagene Abhängigkeit: WebDAV" + +#: src/labels.h:509 +msgid "426 - Upgrade Required: Client should switch to a different protocol" +msgstr "" +"426 – Upgrade erforderlich: Der Client sollte zu einem anderen Protokoll " +"wechseln" + +#: src/labels.h:511 +msgid "428 - Precondition Required" +msgstr "428 – erforderliche Vorraussetzung" + +#: src/labels.h:513 +msgid "429 - Too Many Requests: The user has sent too many requests" +msgstr "429 – zu viele Anfragen: Der Benutzer hat zu viele Anfragen gesendet" + +#: src/labels.h:515 +msgid "" +"430 - Request Header Fields Too Large: Too many URLs are requested within a " +"certain time frame" +msgstr "" + +#: src/labels.h:517 +msgid "431 - Request Header Fields Too Large" +msgstr "431 – Header-Felder der Anfrage zu groß" + +#: src/labels.h:519 +msgid "440 - Login Time-out: The client's session has expired" +msgstr "" + +#: src/labels.h:521 +#, fuzzy +msgid "449 - Retry With: The server cannot honour the request" +msgstr "" +"408 – Zeitüberschreitung der Anfrage: Zeitüberschreitung des Server beim " +"Warten auf die Anfrage" + +#: src/labels.h:523 +msgid "" +"450 - Blocked by Windows Parental Controls: The Microsoft extension code " +"indicated" +msgstr "" + +#: src/labels.h:525 +msgid "451 - Unavailable For Legal Reasons" +msgstr "451 – aus rechtlichen Gründen nicht verfügbar" + +#: src/labels.h:527 +msgid "444 - (Nginx) Connection closed without sending any headers" +msgstr "444 – (Nginx) Verbindung geschlossen, ohne Header zu senden" + +#: src/labels.h:529 +msgid "460 - AWS Elastic Load Balancing: Client closed the connection " +msgstr "" + +#: src/labels.h:531 +msgid "" +"463 - AWS Elastic Load Balancing: The load balancer received more than 30 IP " +"addresses" +msgstr "" + +#: src/labels.h:533 +msgid "464 - AWS Elastic Load Balancing: Incompatible protocol versions" +msgstr "" + +#: src/labels.h:535 +msgid "494 - (Nginx) Request Header Too Large" +msgstr "494 – (Nginx) Anfrage-Kopf zu groß" + +#: src/labels.h:537 +msgid "495 - (Nginx) SSL client certificate error" +msgstr "495 – (Nginx) SSL-Client-Zertifikatsfehler" + +#: src/labels.h:539 +msgid "496 - (Nginx) Client didn't provide certificate" +msgstr "496 – (Nginx) Client hat kein Zertifikat zur Verfügung gestellt" + +#: src/labels.h:541 +msgid "497 - (Nginx) HTTP request sent to HTTPS port" +msgstr "497 – (Nginx) HTTP-Anfrage an HTTPS-Port gesendet" + +#: src/labels.h:543 +msgid "498 - Invalid Token: an expired or otherwise invalid token" +msgstr "" + +#: src/labels.h:545 +msgid "499 - (Nginx) Connection closed by client while processing request" +msgstr "" +"499 – (Nginx) Verbindung vom Client während der Bearbeitung der Anfrage " +"geschlossen" + +#: src/labels.h:547 +msgid "500 - Internal Server Error" +msgstr "500 – interner Serverfehler" + +#: src/labels.h:549 +msgid "501 - Not Implemented" +msgstr "501 – nicht implementiert" + +#: src/labels.h:551 +msgid "502 - Bad Gateway: Received an invalid response from the upstream" +msgstr "" +"502 – Fehlerhaftes Gateway: Eine ungültige Antwort vom Upstream erhalten" + +#: src/labels.h:553 +msgid "503 - Service Unavailable: The server is currently unavailable" +msgstr "503 – Dienst nicht verfügbar: Der Server ist zurzeit nicht ansprechbar" + +#: src/labels.h:555 +msgid "504 - Gateway Timeout: The upstream server failed to send request" +msgstr "" +"504 – Gateway-Zeitüberschreitung: Der Upstream-Server konnte keine Anfrage " +"senden" + +#: src/labels.h:557 +msgid "505 - HTTP Version Not Supported" +msgstr "505 – HTTP-Version wird nicht unterstützt" + +#: src/labels.h:559 +msgid "509 - Bandwidth Limit Exceeded: The server has exceeded the bandwidth" +msgstr "" + +#: src/labels.h:561 +msgid "520 - CloudFlare - Web server is returning an unknown error" +msgstr "520 – CloudFlare – der Webserver gibt einen unbekannten Fehler zurück" + +#: src/labels.h:563 +msgid "521 - CloudFlare - Web server is down" +msgstr "521 – CloudFlare – Webserver ist ausgefallen" + +#: src/labels.h:565 +msgid "522 - CloudFlare - Connection timed out" +msgstr "522 – CloudFlare – Zeitüberschreitung der Verbindung" + +#: src/labels.h:567 +msgid "523 - CloudFlare - Origin is unreachable" +msgstr "523 – CloudFlare – Herkunft ist unerreichbar" + +#: src/labels.h:569 +msgid "524 - CloudFlare - A timeout occurred" +msgstr "524 – CloudFlare – Zeitüberschreitung aufgetreten" + +#: src/labels.h:571 +msgid "" +"525 - SSL Handshake Failed: Cloudflare could not negotiate a SSL/TLS " +"handshake" +msgstr "" + +#: src/labels.h:573 +msgid "" +"526 - Invalid SSL Certificate: Cloudflare could not validate the SSL " +"certificate" +msgstr "" + +#: src/labels.h:575 +msgid "527 - Railgun Error: An interrupted connection" +msgstr "" + +#: src/labels.h:577 +msgid "529 - Site is overloaded: A site can not process the request" +msgstr "" + +#: src/labels.h:579 +msgid "530 - Site is frozen: A site has been frozen due to inactivity" +msgstr "" + +#: src/labels.h:581 +msgid "" +"540 - Temporarily Disabled: The requested endpoint has been temporarily " +"disabled" +msgstr "" + +#: src/labels.h:583 +#, fuzzy +msgid "561 - Unauthorized: An error around authentication" +msgstr "" +"401 – nicht autorisiert: Anforderung erfordert Benutzerauthentifizierung" + +#: src/labels.h:585 +msgid "" +"598 - Network read timeout error: some HTTP proxies to signal a network read " +"timeout" +msgstr "" + +#: src/labels.h:587 +msgid "599 - Network Connect Timeout Error: An error used by some HTTP proxies" +msgstr "" + +#: src/labels.h:589 +msgid "783 - Unexpected Token: The request includes a JSON syntax error" +msgstr "" + +#, fuzzy +#~ msgid "Referers" +#~ msgstr "Verweise" diff --git a/po/es.po b/po/es.po new file mode 100644 index 0000000000..fc5570a94e --- /dev/null +++ b/po/es.po @@ -0,0 +1,1068 @@ +msgid "" +msgstr "" +"Project-Id-Version: Goaccess\n" +"Report-Msgid-Bugs-To: hello@goaccess.io\n" +"POT-Creation-Date: 2024-04-11 20:17-0500\n" +"PO-Revision-Date: 2017-08-04 13:00-0300\n" +"Last-Translator: Enrique Becerra \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.4\n" + +#: src/labels.h:45 +msgid "en" +msgstr "es" + +#: src/labels.h:48 +msgid "Exp. Panel" +msgstr "Exp. Panel" + +#: src/labels.h:49 +msgid "Help" +msgstr "Ayuda" + +#: src/labels.h:50 +msgid "Quit" +msgstr "Salir" + +#: src/labels.h:51 +msgid "Total" +msgstr "Total" + +#: src/labels.h:54 +msgid "[x] ASC [ ] DESC" +msgstr "[x] ASC [ ] DESC" + +#: src/labels.h:55 +msgid "[ ] ASC [x] DESC" +msgstr "[ ] ASC [x] DESC" + +#: src/labels.h:58 +#, c-format +msgid "[Active Panel: %1$s]" +msgstr "[Panel Activo: %1$s]" + +#: src/labels.h:59 +msgid "[q]uit GoAccess" +msgstr "[q]Salir GoAccess" + +#: src/labels.h:60 +msgid "[?] Help [Enter] Exp. Panel" +msgstr "[?] Ayuda [Enter] Exp. Panel" + +#: src/labels.h:61 +msgid "Dashboard" +msgstr "Panel de Control" + +#: src/labels.h:62 +msgid "Dashboard - Overall Analyzed Requests" +msgstr "Panel de Control - Peticiones Analizadas En General" + +#: src/labels.h:63 +msgid "Overall Analyzed Requests" +msgstr "Peticiones Analizadas en General" + +#: src/labels.h:65 src/labels.h:86 +msgid "Tx. Amount" +msgstr "" + +#: src/labels.h:66 +msgid "Date/Time" +msgstr "Fecha/Hora" + +#: src/labels.h:67 +msgid "Excl. IP Hits" +msgstr "Accesos IP Excl." + +#: src/labels.h:68 +msgid "Failed Requests" +msgstr "Peticiones Fallidas" + +#: src/labels.h:69 +msgid "Log Parsing Time" +msgstr "" + +#: src/labels.h:70 +msgid "Log Size" +msgstr "Tamaño Log" + +#: src/labels.h:71 +msgid "Log Source" +msgstr "Origen de Log" + +#: src/labels.h:72 src/labels.h:187 +msgid "Referrers" +msgstr "Referidos" + +#: src/labels.h:73 +msgid "Total Requests" +msgstr "Peticiones Totales" + +#: src/labels.h:74 +msgid "Static Files" +msgstr "Archivos Estaticos" + +#: src/labels.h:75 src/labels.h:159 +msgid "Not Found" +msgstr "No Encontrado" + +#: src/labels.h:76 +#, fuzzy +msgid "Requested Files" +msgstr "Archivos Requeridos (URLs)" + +#: src/labels.h:77 +msgid "Unique Visitors" +msgstr "Visitantes Unicos" + +#: src/labels.h:78 +msgid "Valid Requests" +msgstr "Peticiones Validas" + +#: src/labels.h:81 +msgid "Hits" +msgstr "Hits" + +#: src/labels.h:82 +msgid "h%" +msgstr "h%" + +#: src/labels.h:83 src/labels.h:110 +msgid "Visitors" +msgstr "Visitantes" + +#: src/labels.h:84 +msgid "Vis." +msgstr "Vis." + +#: src/labels.h:85 +msgid "v%" +msgstr "v%" + +#: src/labels.h:87 +msgid "Avg. T.S." +msgstr "Prom. T.S." + +#: src/labels.h:88 +msgid "Cum. T.S." +msgstr "Cum. T.S." + +#: src/labels.h:89 +msgid "Max. T.S." +msgstr "Max. T.S." + +#: src/labels.h:90 +msgid "Method" +msgstr "Metodo" + +#: src/labels.h:91 +msgid "Mtd" +msgstr "Mtd" + +#: src/labels.h:92 +msgid "Protocol" +msgstr "Protocolo" + +#: src/labels.h:93 +msgid "Proto" +msgstr "Proto" + +#: src/labels.h:94 +msgid "City" +msgstr "Ciudad" + +#: src/labels.h:95 src/labels.h:211 src/labels.h:215 +msgid "ASN" +msgstr "" + +#: src/labels.h:96 +msgid "Country" +msgstr "Pais" + +#: src/labels.h:97 +msgid "Hostname" +msgstr "Hostname" + +#: src/labels.h:98 +msgid "Data" +msgstr "Datos" + +#: src/labels.h:100 +msgid "Hits/Visitors" +msgstr "Hits/Visitas" + +#: src/labels.h:104 +msgid "Unique visitors per day" +msgstr "Visitantes unicos por dia" + +#: src/labels.h:106 +msgid "Unique visitors per day - Including spiders" +msgstr "Visitantes unicos por dia - Incluyendo M.Busqueda" + +#: src/labels.h:108 +msgid "Hits having the same IP, date and agent are a unique visit." +msgstr "Hits con el mismo IP, fecha y agente son unica visita" + +#: src/labels.h:113 +msgid "Requested Files (URLs)" +msgstr "Archivos Requeridos (URLs)" + +#: src/labels.h:115 +msgid "Top requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "Peticiones Top ordenadas por hits [, avgts, cumts, maxts, mthd, proto]" + +#: src/labels.h:117 +msgid "Requests" +msgstr "Peticiones" + +#: src/labels.h:120 src/labels.h:124 +msgid "Static Requests" +msgstr "Peticiones Estaticas" + +#: src/labels.h:122 +msgid "Top static requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Peticiones estaticas top ordenadas por hits [, avgts, cumts, maxts, mthd, " +"proto]" + +#: src/labels.h:127 +msgid "Time Distribution" +msgstr "Distribucion Horaria" + +#: src/labels.h:129 +msgid "Data sorted by hour [, avgts, cumts, maxts]" +msgstr "Datos ordenados por hora [, avgts, cumts, maxts]" + +#: src/labels.h:131 +msgid "Time" +msgstr "Hora" + +#: src/labels.h:134 src/labels.h:138 +msgid "Virtual Hosts" +msgstr "Hosts Virtuales" + +#: src/labels.h:136 src/labels.h:143 src/labels.h:150 +msgid "Data sorted by hits [, avgts, cumts, maxts]" +msgstr "Datos ordenados por hits [, avgts, cumts, maxts]" + +#: src/labels.h:141 +msgid "Remote User (HTTP authentication)" +msgstr "Usuario Remoto (Autenticacion HTTP)" + +#: src/labels.h:145 +msgid "Remote User" +msgstr "Usuario Remoto" + +#: src/labels.h:148 +msgid "The cache status of the object served" +msgstr "" + +#: src/labels.h:152 +msgid "Cache Status" +msgstr "Estado de Caché" + +#: src/labels.h:155 +msgid "Not Found URLs (404s)" +msgstr "URLs no encontradas (404)" + +#: src/labels.h:157 +msgid "Top not found URLs sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"URLs no encontradas top ordenadas por hits [, avgts, cumts, maxts, mthd, " +"proto]" + +#: src/labels.h:162 +msgid "Visitor Hostnames and IPs" +msgstr "Hosts e IPs de los Visitantes" + +#: src/labels.h:164 +msgid "Top visitor hosts sorted by hits [, avgts, cumts, maxts]" +msgstr "Hosts de visitante top ordenado por hits [, avgts, cumts, maxts]" + +#: src/labels.h:166 +msgid "Hosts" +msgstr "Hosts" + +#: src/labels.h:169 +msgid "Operating Systems" +msgstr "Sistemas Operativos" + +#: src/labels.h:171 +msgid "Top Operating Systems sorted by hits [, avgts, cumts, maxts]" +msgstr "Sistemas Operativos top ordenados por hits [, avgts, cumts, maxts]" + +#: src/labels.h:173 +msgid "OS" +msgstr "SO" + +#: src/labels.h:176 src/labels.h:180 +msgid "Browsers" +msgstr "Navegadores" + +#: src/labels.h:178 +msgid "Top Browsers sorted by hits [, avgts, cumts, maxts]" +msgstr "Navegadores top ordenados por hits [, avgts, cumts, maxts]" + +#: src/labels.h:183 +#, fuzzy +msgid "Referrer URLs" +msgstr "URLs Referidos" + +#: src/labels.h:185 +#, fuzzy +msgid "Top Requested Referrers sorted by hits [, avgts, cumts, maxts]" +msgstr "Peticiones top de referidos ordenadas por hits [, avgts, cumts, maxts]" + +#: src/labels.h:190 src/labels.h:194 +msgid "Referring Sites" +msgstr "Sitios Referidos" + +#: src/labels.h:192 +msgid "Top Referring Sites sorted by hits [, avgts, cumts, maxts]" +msgstr "Sitios Referidos top ordenados por hits [, avgts, cumts, maxts]" + +#: src/labels.h:197 +msgid "Keyphrases from Google's search engine" +msgstr "Frases de busqueda de motor de busqueda Google" + +#: src/labels.h:199 +msgid "Top Keyphrases sorted by hits [, avgts, cumts, maxts]" +msgstr "Frases de busqueda top ordenadas por hits [, avgts, cumts, maxts]" + +#: src/labels.h:201 +msgid "Keyphrases" +msgstr "Frases Clave" + +#: src/labels.h:204 src/labels.h:208 +msgid "Geo Location" +msgstr "Geo Localizacion" + +#: src/labels.h:206 +msgid "Continent > Country sorted by unique hits [, avgts, cumts, maxts]" +msgstr "Continente > Pais ordenado por hits unicos [, avgts, cumts, maxts]" + +#: src/labels.h:213 +msgid "Autonomous System Numbers/Organizations (ASNs)" +msgstr "" + +#: src/labels.h:218 +msgid "HTTP Status Codes" +msgstr "Codigos de Estado HTTP" + +#: src/labels.h:220 +msgid "Top HTTP Status Codes sorted by hits [, avgts, cumts, maxts]" +msgstr "Codigos de Estado HTTP top ordenados por hits [, avgts, cumts, maxts]" + +#: src/labels.h:222 +msgid "Status Codes" +msgstr "Codigos de Estado" + +#: src/labels.h:225 src/labels.h:229 +msgid "MIME Types" +msgstr "" + +#: src/labels.h:227 +msgid "File types shipped out" +msgstr "" + +#: src/labels.h:232 +msgid "Encryption settings" +msgstr "" + +#: src/labels.h:234 +msgid "TLS version and picked algorithm" +msgstr "" + +#: src/labels.h:236 +msgid "TLS Settings" +msgstr "" + +#: src/labels.h:240 +msgid "[ ] case sensitive" +msgstr "[ ] distinguir mayusculas" + +#: src/labels.h:242 +msgid "[x] case sensitive" +msgstr "[x] distinguir mayusculas" + +#: src/labels.h:244 +msgid "Regex allowed - ^g to cancel - TAB switch case" +msgstr "Permitido Regex - ^g para cancelar - TAB cambiar case" + +#: src/labels.h:246 +msgid "Find pattern in all views" +msgstr "Encontrar patron en todas las vistas" + +#: src/labels.h:250 +msgid "Log Format Configuration" +msgstr "Configuracion de Formato de Log" + +#: src/labels.h:252 +msgid "[SPACE] to toggle - [ENTER] to proceed - [q] to quit" +msgstr "[ESPACIO] para alternar - [ENTER] para proceder - [q] para salir" + +#: src/labels.h:254 +msgid "Log Format - [c] to add/edit format" +msgstr "Formato de Log - [c] para agregar/editar formato" + +#: src/labels.h:256 +msgid "Date Format - [d] to add/edit format" +msgstr "Formato de Fecha - [d] para agregar/editar formato" + +#: src/labels.h:258 +msgid "Time Format - [t] to add/edit format" +msgstr "Formato de Hora - [t] para agregar/editar formato" + +#: src/labels.h:260 src/labels.h:264 +msgid "[UP/DOWN] to scroll - [q] to close window" +msgstr "[ARRIBA/ABAJO] para scrollear - [q] para cerrar ventana" + +#: src/labels.h:266 +#, c-format +msgid "User Agents for %1$s" +msgstr "Agentes de Usuario para %1$s" + +#: src/labels.h:270 +msgid "Scheme Configuration" +msgstr "Configuracion de Esquema" + +#: src/labels.h:272 +msgid "[ENTER] to use scheme - [q]uit" +msgstr "[ENTER] para usar esquema - [q]Salir" + +#: src/labels.h:276 +msgid "Sort active module by" +msgstr "Ordenar modulo activo por" + +#: src/labels.h:278 +msgid "[ENTER] select - [TAB] sort - [q]uit" +msgstr "[ENTER] seleccionar - [TAB] ordenar - [q]Salir" + +#: src/labels.h:282 +msgid "GoAccess Quick Help" +msgstr "Ayuda Rapida de GoAccess" + +#: src/labels.h:284 +msgid "[UP/DOWN] to scroll - [q] to quit" +msgstr "[ARRIBA/ABAJO] para scrollear - [q] para salir" + +#: src/labels.h:288 +msgid "In-Memory with On-Disk Persistent Storage." +msgstr "" + +#: src/labels.h:292 +msgid "Format Errors - Verify your log/date/time format" +msgstr "Errores de Formato - Verifique su formato de log/fecha/hora" + +#: src/labels.h:294 +msgid "No date format was found on your conf file." +msgstr "No se encontro formato de fecha en su archivo de configuracion" + +#: src/labels.h:296 +msgid "No log format was found on your conf file." +msgstr "No se encontro formato de log en su archivo de configuracion" + +#: src/labels.h:298 +msgid "No time format was found on your conf file." +msgstr "No se encontro formato de hora en su archivo de configuracion" + +#: src/labels.h:300 +msgid "No default config file found." +msgstr "No se encontro archivo de configuracion por defecto." + +#: src/labels.h:302 +msgid "You may specify one with" +msgstr "Ud. puede especificar un ancho" + +#: src/labels.h:304 +msgid "producing the following errors" +msgstr "produciendo los siguientes errores" + +#: src/labels.h:306 +#, c-format +msgid "Parsed %1$d lines" +msgstr "Analizadas %1$d lineas" + +#: src/labels.h:308 +msgid "Please report it by opening an issue on GitHub" +msgstr "Por favor avise abriendo un issue en GitHub" + +#: src/labels.h:310 +msgid "Select a time format." +msgstr "Elija un formato de hora." + +#: src/labels.h:312 +msgid "Select a date format." +msgstr "Elija un formato de fecha." + +#: src/labels.h:314 +msgid "Select a log format." +msgstr "Elija un formato de log." + +#: src/labels.h:316 +#, c-format +msgid "'%1$s' panel is disabled" +msgstr "'%1$s' panel esta desactivado" + +#: src/labels.h:318 +msgid "No input data was provided nor there's data to restore." +msgstr "" + +#: src/labels.h:320 +msgid "Unable to allocate memory for a log instance." +msgstr "" + +#: src/labels.h:322 +msgid "Unable to find the given log." +msgstr "" + +#: src/labels.h:326 +msgid "For more details visit" +msgstr "Para mas detalles visite" + +#: src/labels.h:328 +msgid "Last Updated" +msgstr "Ultima actualizacion" + +#: src/labels.h:330 +msgid "WebSocket server ready to accept new client connections" +msgstr "Servidor WebSocket listo para aceptar nuevas conexiones de clientes" + +#: src/labels.h:333 +msgid "The following options can also be supplied to the command" +msgstr "Las siguientes opciones pueden ser ademas suplirse en el comando" + +#: src/labels.h:335 +msgid "Examples can be found by running" +msgstr "Ejemplos pueden encontrarse ejecutando" + +#: src/labels.h:338 +msgid "Server Statistics" +msgstr "Estadisticas de Servidor" + +#: src/labels.h:340 +msgid "Theme" +msgstr "Skin" + +#: src/labels.h:342 +msgid "Dark Gray" +msgstr "Gris Oscuro" + +#: src/labels.h:344 +msgid "Bright" +msgstr "Clara" + +#: src/labels.h:346 +msgid "Dark Blue" +msgstr "Azul Oscuro" + +#: src/labels.h:348 +#, fuzzy +msgid "Dark Purple" +msgstr "Morado Oscuro" + +#: src/labels.h:350 +msgid "Panels" +msgstr "Paneles" + +#: src/labels.h:352 +msgid "Items per Page" +msgstr "Items por pagina" + +#: src/labels.h:354 +msgid "Tables" +msgstr "Tablas" + +#: src/labels.h:356 +msgid "Display Tables" +msgstr "Mostrar Tablas" + +#: src/labels.h:358 +msgid "Auto-Hide on Small Devices" +msgstr "Auto-ocultar en Pequeños Dispositivos" + +#: src/labels.h:360 +msgid "Automatically hide tables on small screen devices" +msgstr "Automaticamente ocultar tablas en pequeños dispositivos" + +#: src/labels.h:362 +msgid "Toggle Panel" +msgstr "" + +#: src/labels.h:364 +msgid "Layout" +msgstr "Diseño" + +#: src/labels.h:366 +msgid "Horizontal" +msgstr "Horizontal" + +#: src/labels.h:368 +msgid "Vertical" +msgstr "Vertical" + +#: src/labels.h:370 +msgid "WideScreen" +msgstr "Panorama" + +#: src/labels.h:372 +msgid "File Options" +msgstr "Opciones de Archivo" + +#: src/labels.h:374 +msgid "Export as JSON" +msgstr "Exportar como JSON" + +#: src/labels.h:376 +msgid "Panel Options" +msgstr "Opciones de Panel" + +#: src/labels.h:378 +msgid "Previous" +msgstr "Anterior" + +#: src/labels.h:380 +msgid "Next" +msgstr "Siguiente" + +#: src/labels.h:382 +msgid "First" +msgstr "Primero" + +#: src/labels.h:384 +msgid "Last" +msgstr "Ultimo" + +#: src/labels.h:386 +msgid "Chart Options" +msgstr "Opciones de Grafico" + +#: src/labels.h:388 +msgid "Chart" +msgstr "Grafico" + +#: src/labels.h:390 +msgid "Type" +msgstr "Tipo" + +#: src/labels.h:392 +msgid "Area Spline" +msgstr "Area Ranura" + +#: src/labels.h:394 +msgid "Bar" +msgstr "Bar" + +#: src/labels.h:396 +msgid "World Map" +msgstr "" + +#: src/labels.h:398 +msgid "Plot Metric" +msgstr "Trazado" + +#: src/labels.h:400 +msgid "Table Columns" +msgstr "Columnas de Tabla" + +#: src/labels.h:404 +msgid "0xx Unofficial Codes" +msgstr "" + +#: src/labels.h:406 +msgid "1xx Informational" +msgstr "1xx Informativo" + +#: src/labels.h:408 +msgid "2xx Success" +msgstr "2xx Exito" + +#: src/labels.h:410 +msgid "3xx Redirection" +msgstr "3xx Redireccion" + +#: src/labels.h:412 +msgid "4xx Client Errors" +msgstr "4xx Errores de Cliente" + +#: src/labels.h:414 +msgid "5xx Server Errors" +msgstr "5xx Errores de Servidor" + +#: src/labels.h:417 +msgid "0 - Caddy: Unhandled - No configured routes" +msgstr "" + +#: src/labels.h:419 +msgid "100 - Continue: Server received the initial part of the request" +msgstr "100 - Continuar: Servidor recibio la parte inicial de la peticion" + +#: src/labels.h:421 +msgid "101 - Switching Protocols: Client asked to switch protocols" +msgstr "101 - Cambiando Protocolos: Cliente pidio cambiar protocolos" + +#: src/labels.h:423 +msgid "200 - OK: The request sent by the client was successful" +msgstr "200 - OK: La peticion enviada por el cliente fue exitosa" + +#: src/labels.h:425 +msgid "201 - Created: The request has been fulfilled and created" +msgstr "201 - Creada: La peticion ha sido completada y creada" + +#: src/labels.h:427 +msgid "202 - Accepted: The request has been accepted for processing" +msgstr "202 - Aceptada: La peticion fue aceptada para procesar" + +#: src/labels.h:429 +msgid "203 - Non-authoritative Information: Response from a third party" +msgstr "203 - No-autoritario Informativo: Respuesta de una 3er. parte" + +#: src/labels.h:431 +msgid "204 - No Content: Request did not return any content" +msgstr "204 - Sin Contenido: Peticion no retorno ningun contenido" + +#: src/labels.h:433 +msgid "205 - Reset Content: Server asked the client to reset the document" +msgstr "" +"205 - Resetear Contenido: Servidor pidio al cliente resetear el documento" + +#: src/labels.h:435 +msgid "206 - Partial Content: The partial GET has been successful" +msgstr "206 - Contenido Parcial: el GET parcial fue exitoso" + +#: src/labels.h:437 +msgid "207 - Multi-Status: WebDAV; RFC 4918" +msgstr "207 - Multi-Estado: WebDAV; RFC 4918" + +#: src/labels.h:439 +msgid "208 - Already Reported: WebDAV; RFC 5842" +msgstr "208 - Ya Reportado: WebDAV; RFC 5842" + +#: src/labels.h:441 +msgid "218 - This is fine: Apache servers. A catch-all error condition" +msgstr "" + +#: src/labels.h:443 +msgid "300 - Multiple Choices: Multiple options for the resource" +msgstr "300 - Multiples Opciones: Multiples opciones para el recurso" + +#: src/labels.h:445 +msgid "301 - Moved Permanently: Resource has permanently moved" +msgstr "301 - Movido Permanente: Recurso ha sido permanentemente movido" + +#: src/labels.h:447 +msgid "302 - Moved Temporarily (redirect)" +msgstr "302 - Movido Temporalmente (redireccion)" + +#: src/labels.h:449 +msgid "303 - See Other Document: The response is at a different URI" +msgstr "303 - Ver Otro Documento: La respuesta es en una URI diferente" + +#: src/labels.h:451 +msgid "304 - Not Modified: Resource has not been modified" +msgstr "304 - No Modificado: Recurso no ha sido modificado" + +#: src/labels.h:453 +msgid "305 - Use Proxy: Can only be accessed through the proxy" +msgstr "305 - Usar Proxy: Puede ser accedido solo a traves de proxy" + +#: src/labels.h:455 +msgid "307 - Temporary Redirect: Resource temporarily moved" +msgstr "307 - Redireccion Temporal: Recurso movido temporalmente" + +#: src/labels.h:457 +#, fuzzy +msgid "308 - Permanent Redirect" +msgstr "402 - Pago Requerido" + +#: src/labels.h:459 +msgid "400 - Bad Request: The syntax of the request is invalid" +msgstr "400 - Peticion Mala: La sintaxis de la peticion es invalida" + +#: src/labels.h:461 +msgid "401 - Unauthorized: Request needs user authentication" +msgstr "401 - Sin Autorizacion: Peticion necesita autenticacion de usuario" + +#: src/labels.h:463 +msgid "402 - Payment Required" +msgstr "402 - Pago Requerido" + +#: src/labels.h:465 +msgid "403 - Forbidden: Server is refusing to respond to it" +msgstr "403 - Prohibido: Servidor esta rechazando respuesta" + +#: src/labels.h:467 +msgid "404 - Not Found: Requested resource could not be found" +msgstr "404 - No Encontrado: Peticion de recurso no pudo encontrarse" + +#: src/labels.h:469 +msgid "405 - Method Not Allowed: Request method not supported" +msgstr "405 - Metodo No Permitido: Metodo de Peticion no soportado" + +#: src/labels.h:471 +msgid "406 - Not Acceptable" +msgstr "406 - No Aceptable" + +#: src/labels.h:473 +msgid "407 - Proxy Authentication Required" +msgstr "407 - Autenticacion de Proxy Requerida" + +#: src/labels.h:475 +msgid "408 - Request Timeout: Server timed out waiting for the request" +msgstr "408 - Timeout de Peticion: Tiempo agotado de espera para la solicitud" + +#: src/labels.h:477 +msgid "409 - Conflict: Conflict in the request" +msgstr "409 - Conflicto: Conflicto en la peticion" + +#: src/labels.h:479 +msgid "410 - Gone: Resource requested is no longer available" +msgstr "410 - Fue: Recurso requerido no esta mas disponible" + +#: src/labels.h:481 +msgid "411 - Length Required: Invalid Content-Length" +msgstr "411 - Longitud Requerida: Content-Length Invalido" + +#: src/labels.h:483 +msgid "412 - Precondition Failed: Server does not meet preconditions" +msgstr "412 - Precondicion Fallida: Servidor no cumple precondiciones" + +#: src/labels.h:485 +msgid "413 - Payload Too Large" +msgstr "413 - Carga Util Demasiado larga" + +#: src/labels.h:487 +msgid "414 - Request-URI Too Long" +msgstr "414 - Request-URI demasiado larga" + +#: src/labels.h:489 +msgid "415 - Unsupported Media Type: Media type is not supported" +msgstr "415 - Tipo de medios no soportado: El tipo de medios no es soportado" + +#: src/labels.h:491 +msgid "416 - Requested Range Not Satisfiable: Cannot supply that portion" +msgstr "416 - Rango requerido no satisfacible: No puede proveer esa porcion" + +#: src/labels.h:493 +msgid "417 - Expectation Failed" +msgstr "417 - Expectativa Fallida" + +#: src/labels.h:495 +#, fuzzy +msgid "418 - I'm a teapot" +msgstr "418 - Soy una tetera" + +#: src/labels.h:497 +msgid "419 - Page Expired: Laravel Framework when a CSRF Token is missing" +msgstr "" + +#: src/labels.h:499 +msgid "420 - Method Failure: Spring Framework when a method has failed" +msgstr "" + +#: src/labels.h:501 +msgid "421 - Misdirected Request" +msgstr "421 - Peticion mal dirigida" + +#: src/labels.h:503 +msgid "422 - Unprocessable Entity due to semantic errors: WebDAV" +msgstr "422 - Peticion fue imposible seguirla debido a errores semánticos" + +#: src/labels.h:505 +msgid "423 - The resource that is being accessed is locked" +msgstr "423 - El recurso al que se está teniendo acceso está bloqueado" + +#: src/labels.h:507 +msgid "424 - Failed Dependency: WebDAV" +msgstr "424 - La solicitud falló debido a una falla en la solicitud previa" + +#: src/labels.h:509 +msgid "426 - Upgrade Required: Client should switch to a different protocol" +msgstr "426 - El cliente debería cambiarse a TLS/1.0" + +#: src/labels.h:511 +#, fuzzy +msgid "428 - Precondition Required" +msgstr "402 - Pago Requerido" + +#: src/labels.h:513 +msgid "429 - Too Many Requests: The user has sent too many requests" +msgstr "429 - Hay muchas conexiones desde esta dirección de internet" + +#: src/labels.h:515 +msgid "" +"430 - Request Header Fields Too Large: Too many URLs are requested within a " +"certain time frame" +msgstr "" + +#: src/labels.h:517 +#, fuzzy +msgid "431 - Request Header Fields Too Large" +msgstr "494 - (Nginx) Cabecera de Peticion demasiada larga" + +#: src/labels.h:519 +msgid "440 - Login Time-out: The client's session has expired" +msgstr "" + +#: src/labels.h:521 +#, fuzzy +msgid "449 - Retry With: The server cannot honour the request" +msgstr "408 - Timeout de Peticion: Tiempo agotado de espera para la solicitud" + +#: src/labels.h:523 +msgid "" +"450 - Blocked by Windows Parental Controls: The Microsoft extension code " +"indicated" +msgstr "" + +#: src/labels.h:525 +msgid "451 - Unavailable For Legal Reasons" +msgstr "" + +#: src/labels.h:527 +msgid "444 - (Nginx) Connection closed without sending any headers" +msgstr "444 - (Nginx) Conexion cerrada sin enviar cabeceras" + +#: src/labels.h:529 +msgid "460 - AWS Elastic Load Balancing: Client closed the connection " +msgstr "" + +#: src/labels.h:531 +msgid "" +"463 - AWS Elastic Load Balancing: The load balancer received more than 30 IP " +"addresses" +msgstr "" + +#: src/labels.h:533 +msgid "464 - AWS Elastic Load Balancing: Incompatible protocol versions" +msgstr "" + +#: src/labels.h:535 +msgid "494 - (Nginx) Request Header Too Large" +msgstr "494 - (Nginx) Cabecera de Peticion demasiada larga" + +#: src/labels.h:537 +msgid "495 - (Nginx) SSL client certificate error" +msgstr "495 - (Nginx) Cliente SSL certificado erroneo" + +#: src/labels.h:539 +msgid "496 - (Nginx) Client didn't provide certificate" +msgstr "496 - (Nginx) Client no proveyo certificado" + +#: src/labels.h:541 +msgid "497 - (Nginx) HTTP request sent to HTTPS port" +msgstr "497 - (Nginx) Peticion HTTP enviada a puerto HTTPS" + +#: src/labels.h:543 +msgid "498 - Invalid Token: an expired or otherwise invalid token" +msgstr "" + +#: src/labels.h:545 +msgid "499 - (Nginx) Connection closed by client while processing request" +msgstr "499 - (Nginx) Conexion cerrada por cliente mientras procesaba peticion" + +#: src/labels.h:547 +msgid "500 - Internal Server Error" +msgstr "500 - Error Interno de Servidor" + +#: src/labels.h:549 +msgid "501 - Not Implemented" +msgstr "501 - No Implementado" + +#: src/labels.h:551 +msgid "502 - Bad Gateway: Received an invalid response from the upstream" +msgstr "502 - Entrada Erronea: Recibio respuesta invalida" + +#: src/labels.h:553 +msgid "503 - Service Unavailable: The server is currently unavailable" +msgstr "" +"503 - Servicio no disponible: El servidor actualmente no esta disponible" + +#: src/labels.h:555 +msgid "504 - Gateway Timeout: The upstream server failed to send request" +msgstr "" +"504 - Timeout de Gateway: El servidor upstream fallo al enviar peticion" + +#: src/labels.h:557 +msgid "505 - HTTP Version Not Supported" +msgstr "505 - Version HTTP no soportada" + +#: src/labels.h:559 +msgid "509 - Bandwidth Limit Exceeded: The server has exceeded the bandwidth" +msgstr "" + +#: src/labels.h:561 +msgid "520 - CloudFlare - Web server is returning an unknown error" +msgstr "520 - CloudFlare - El servidor esta retornando un error desconocido" + +#: src/labels.h:563 +msgid "521 - CloudFlare - Web server is down" +msgstr "521 - CloudFlare - Servidor Web caido" + +#: src/labels.h:565 +msgid "522 - CloudFlare - Connection timed out" +msgstr "522 - CloudFlare - Tiempo de espera de conexion agotado " + +#: src/labels.h:567 +msgid "523 - CloudFlare - Origin is unreachable" +msgstr "523 - CloudFlare - Origen es inaccesible" + +#: src/labels.h:569 +msgid "524 - CloudFlare - A timeout occurred" +msgstr "524 - CloudFlare - Ocurrio cese de tiempo" + +#: src/labels.h:571 +msgid "" +"525 - SSL Handshake Failed: Cloudflare could not negotiate a SSL/TLS " +"handshake" +msgstr "" + +#: src/labels.h:573 +msgid "" +"526 - Invalid SSL Certificate: Cloudflare could not validate the SSL " +"certificate" +msgstr "" + +#: src/labels.h:575 +msgid "527 - Railgun Error: An interrupted connection" +msgstr "" + +#: src/labels.h:577 +msgid "529 - Site is overloaded: A site can not process the request" +msgstr "" + +#: src/labels.h:579 +msgid "530 - Site is frozen: A site has been frozen due to inactivity" +msgstr "" + +#: src/labels.h:581 +msgid "" +"540 - Temporarily Disabled: The requested endpoint has been temporarily " +"disabled" +msgstr "" + +#: src/labels.h:583 +#, fuzzy +msgid "561 - Unauthorized: An error around authentication" +msgstr "401 - Sin Autorizacion: Peticion necesita autenticacion de usuario" + +#: src/labels.h:585 +msgid "" +"598 - Network read timeout error: some HTTP proxies to signal a network read " +"timeout" +msgstr "" + +#: src/labels.h:587 +msgid "599 - Network Connect Timeout Error: An error used by some HTTP proxies" +msgstr "" + +#: src/labels.h:589 +msgid "783 - Unexpected Token: The request includes a JSON syntax error" +msgstr "" + +#, fuzzy +#~ msgid "Referers" +#~ msgstr "Referidos" diff --git a/po/fr.po b/po/fr.po new file mode 100644 index 0000000000..d23fed0592 --- /dev/null +++ b/po/fr.po @@ -0,0 +1,1080 @@ +msgid "" +msgstr "" +"Project-Id-Version: goaccess 1.4\n" +"Report-Msgid-Bugs-To: hello@goaccess.io\n" +"POT-Creation-Date: 2024-04-11 20:17-0500\n" +"PO-Revision-Date: 2020-07-10 11:44+0200\n" +"Last-Translator: Coban L. \n" +"Language-Team: français\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: src/labels.h:45 +msgid "en" +msgstr "fr" + +#: src/labels.h:48 +msgid "Exp. Panel" +msgstr "Dév. Panneau" + +#: src/labels.h:49 +msgid "Help" +msgstr "Aide" + +#: src/labels.h:50 +msgid "Quit" +msgstr "Quitter" + +#: src/labels.h:51 +msgid "Total" +msgstr "Total" + +#: src/labels.h:54 +msgid "[x] ASC [ ] DESC" +msgstr "[x] ASC [ ] DESC" + +#: src/labels.h:55 +msgid "[ ] ASC [x] DESC" +msgstr "[ ] ASC [x] DESC" + +#: src/labels.h:58 +#, c-format +msgid "[Active Panel: %1$s]" +msgstr "[Panneau Actif: %1$s]" + +#: src/labels.h:59 +msgid "[q]uit GoAccess" +msgstr "[q]uitter GoAccess" + +#: src/labels.h:60 +msgid "[?] Help [Enter] Exp. Panel" +msgstr "[?] Aide [Enter] Dév. Panneau" + +#: src/labels.h:61 +msgid "Dashboard" +msgstr "Tableau de bord" + +#: src/labels.h:62 +msgid "Dashboard - Overall Analyzed Requests" +msgstr "Tableau de bord - Requêtes analysées, vue d'ensemble" + +#: src/labels.h:63 +msgid "Overall Analyzed Requests" +msgstr "Requêtes analysées, vue d'ensemble" + +#: src/labels.h:65 src/labels.h:86 +msgid "Tx. Amount" +msgstr "Tx. Montant" + +#: src/labels.h:66 +msgid "Date/Time" +msgstr "Date/Heure" + +#: src/labels.h:67 +msgid "Excl. IP Hits" +msgstr "Excl. IP Hits" + +#: src/labels.h:68 +msgid "Failed Requests" +msgstr "Requêtes échouées" + +#: src/labels.h:69 +msgid "Log Parsing Time" +msgstr "" + +#: src/labels.h:70 +msgid "Log Size" +msgstr "Taille log" + +#: src/labels.h:71 +msgid "Log Source" +msgstr "Fichier log" + +#: src/labels.h:72 src/labels.h:187 +msgid "Referrers" +msgstr "Origine" + +#: src/labels.h:73 +msgid "Total Requests" +msgstr "Requêtes totales" + +#: src/labels.h:74 +msgid "Static Files" +msgstr "Fichiers statiques" + +#: src/labels.h:75 src/labels.h:159 +msgid "Not Found" +msgstr "Non Trouvé" + +#: src/labels.h:76 +#, fuzzy +msgid "Requested Files" +msgstr "Fichiers demandés (URLs)" + +#: src/labels.h:77 +msgid "Unique Visitors" +msgstr "Visiteurs uniques" + +#: src/labels.h:78 +msgid "Valid Requests" +msgstr "Requêtes valides" + +#: src/labels.h:81 +msgid "Hits" +msgstr "Hits" + +#: src/labels.h:82 +msgid "h%" +msgstr "h%" + +#: src/labels.h:83 src/labels.h:110 +msgid "Visitors" +msgstr "Visiteurs" + +#: src/labels.h:84 +msgid "Vis." +msgstr "Vis." + +#: src/labels.h:85 +msgid "v%" +msgstr "v%" + +#: src/labels.h:87 +msgid "Avg. T.S." +msgstr "Avg. T.S." + +#: src/labels.h:88 +msgid "Cum. T.S." +msgstr "Cum. T.S." + +#: src/labels.h:89 +msgid "Max. T.S." +msgstr "Max. T.S." + +#: src/labels.h:90 +msgid "Method" +msgstr "Méthode" + +#: src/labels.h:91 +msgid "Mtd" +msgstr "Mtd" + +#: src/labels.h:92 +msgid "Protocol" +msgstr "Protocole" + +#: src/labels.h:93 +msgid "Proto" +msgstr "Proto" + +#: src/labels.h:94 +msgid "City" +msgstr "Ville" + +#: src/labels.h:95 src/labels.h:211 src/labels.h:215 +msgid "ASN" +msgstr "" + +#: src/labels.h:96 +msgid "Country" +msgstr "Pays" + +#: src/labels.h:97 +msgid "Hostname" +msgstr "Nom d'hôte" + +#: src/labels.h:98 +msgid "Data" +msgstr "Données" + +#: src/labels.h:100 +#, fuzzy +msgid "Hits/Visitors" +msgstr "Visiteurs" + +#: src/labels.h:104 +msgid "Unique visitors per day" +msgstr "Visiteurs uniques par jour" + +#: src/labels.h:106 +msgid "Unique visitors per day - Including spiders" +msgstr "Visiteurs uniques/jour - Y compris bots" + +#: src/labels.h:108 +msgid "Hits having the same IP, date and agent are a unique visit." +msgstr "" +"Les hits depuis la même IP, date et user-agent comptent comme visite unique" + +#: src/labels.h:113 +msgid "Requested Files (URLs)" +msgstr "Fichiers demandés (URLs)" + +#: src/labels.h:115 +msgid "Top requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "Top des requêtes triées par hits [, avgts, cumts, maxts, mthd, proto]" + +#: src/labels.h:117 +msgid "Requests" +msgstr "Requêtes" + +#: src/labels.h:120 src/labels.h:124 +msgid "Static Requests" +msgstr "Requêtes statiques" + +#: src/labels.h:122 +msgid "Top static requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Top des requêtes statiques trié par hits [, avgts, cumts, maxts, mthd, proto]" + +#: src/labels.h:127 +msgid "Time Distribution" +msgstr "Distribution temporelle" + +#: src/labels.h:129 +msgid "Data sorted by hour [, avgts, cumts, maxts]" +msgstr "Données triées par heure [, avgts, cumts, maxts]" + +#: src/labels.h:131 +msgid "Time" +msgstr "Temps" + +#: src/labels.h:134 src/labels.h:138 +msgid "Virtual Hosts" +msgstr "Hôtes virtuels" + +#: src/labels.h:136 src/labels.h:143 src/labels.h:150 +msgid "Data sorted by hits [, avgts, cumts, maxts]" +msgstr "Données triées par hits [, avgts, cumts, maxts]" + +#: src/labels.h:141 +msgid "Remote User (HTTP authentication)" +msgstr "Utilisateur distant (authentification HTTP)" + +#: src/labels.h:145 +msgid "Remote User" +msgstr "Remote Utilisateur" + +#: src/labels.h:148 +msgid "The cache status of the object served" +msgstr "L'état du cache de l'objet servi" + +#: src/labels.h:152 +msgid "Cache Status" +msgstr "Etat du cache" + +#: src/labels.h:155 +msgid "Not Found URLs (404s)" +msgstr "URLs Non trouvées (404s)" + +#: src/labels.h:157 +msgid "Top not found URLs sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Top des URLs non trouvées trié par hits [, avgts, cumts, maxts, mthd, proto]" + +#: src/labels.h:162 +msgid "Visitor Hostnames and IPs" +msgstr "Nom de machine et IPs des visiteurs" + +#: src/labels.h:164 +msgid "Top visitor hosts sorted by hits [, avgts, cumts, maxts]" +msgstr "Top des visiteurs trié par hits [, avgts, cumts, maxts]" + +#: src/labels.h:166 +msgid "Hosts" +msgstr "Hôtes" + +#: src/labels.h:169 +msgid "Operating Systems" +msgstr "Systèmes d'exploitation" + +#: src/labels.h:171 +msgid "Top Operating Systems sorted by hits [, avgts, cumts, maxts]" +msgstr "Top des systèmes d'exploitation trié par hits [, avgts, cumts, maxts]" + +#: src/labels.h:173 +msgid "OS" +msgstr "SE" + +#: src/labels.h:176 src/labels.h:180 +msgid "Browsers" +msgstr "Navigateurs" + +#: src/labels.h:178 +msgid "Top Browsers sorted by hits [, avgts, cumts, maxts]" +msgstr "Top des Navigateurs trié par hits [, avgts, cumts, maxts]" + +#: src/labels.h:183 +#, fuzzy +msgid "Referrer URLs" +msgstr "URLs d'origine" + +#: src/labels.h:185 +#, fuzzy +msgid "Top Requested Referrers sorted by hits [, avgts, cumts, maxts]" +msgstr "Top des URLs d'origine trié par hits [, avgts, cumts, maxts]" + +#: src/labels.h:190 src/labels.h:194 +msgid "Referring Sites" +msgstr "Sites d'origine" + +#: src/labels.h:192 +msgid "Top Referring Sites sorted by hits [, avgts, cumts, maxts]" +msgstr "Top des sites d'origine trié par hits [, avgts, cumts, maxts]" + +#: src/labels.h:197 +msgid "Keyphrases from Google's search engine" +msgstr "Mot-clés du moteur de recherche Google" + +#: src/labels.h:199 +msgid "Top Keyphrases sorted by hits [, avgts, cumts, maxts]" +msgstr "Top des Mot-clés trié par hits [, avgts, cumts, maxts]" + +#: src/labels.h:201 +msgid "Keyphrases" +msgstr "Mot-clés" + +#: src/labels.h:204 src/labels.h:208 +msgid "Geo Location" +msgstr "Géo Localisation" + +#: src/labels.h:206 +msgid "Continent > Country sorted by unique hits [, avgts, cumts, maxts]" +msgstr "Continent > Pays trié par hits unique [, avgts, cumts, maxts]" + +#: src/labels.h:213 +msgid "Autonomous System Numbers/Organizations (ASNs)" +msgstr "" + +#: src/labels.h:218 +msgid "HTTP Status Codes" +msgstr "Status HTTP" + +#: src/labels.h:220 +msgid "Top HTTP Status Codes sorted by hits [, avgts, cumts, maxts]" +msgstr "Top des status HTTP trié par hits [, avgts, cumts, maxts]" + +#: src/labels.h:222 +msgid "Status Codes" +msgstr "Status HTTP" + +#: src/labels.h:225 src/labels.h:229 +msgid "MIME Types" +msgstr "" + +#: src/labels.h:227 +msgid "File types shipped out" +msgstr "" + +#: src/labels.h:232 +msgid "Encryption settings" +msgstr "" + +#: src/labels.h:234 +msgid "TLS version and picked algorithm" +msgstr "" + +#: src/labels.h:236 +msgid "TLS Settings" +msgstr "" + +#: src/labels.h:240 +msgid "[ ] case sensitive" +msgstr "[ ] sensible à la casse" + +#: src/labels.h:242 +msgid "[x] case sensitive" +msgstr "[x] sensible à la casse" + +#: src/labels.h:244 +msgid "Regex allowed - ^g to cancel - TAB switch case" +msgstr "Regex OK - ^g pour annuler - TAB pour changer la casse" + +#: src/labels.h:246 +msgid "Find pattern in all views" +msgstr "Trouver tous les motifs dans toutes les vues" + +#: src/labels.h:250 +msgid "Log Format Configuration" +msgstr "Configuration format des logs" + +#: src/labels.h:252 +msgid "[SPACE] to toggle - [ENTER] to proceed - [q] to quit" +msgstr "[SPACE] pour basculer - [ENTREE] pour procéder - [q] pour quitter" + +#: src/labels.h:254 +msgid "Log Format - [c] to add/edit format" +msgstr "Format des logs - [c] pour ajouter/éditer le format" + +#: src/labels.h:256 +msgid "Date Format - [d] to add/edit format" +msgstr "Format de la date - [d] pour ajouter/éditer le format" + +#: src/labels.h:258 +msgid "Time Format - [t] to add/edit format" +msgstr "Format temporel - [t] pour ajouter/éditer le format" + +#: src/labels.h:260 src/labels.h:264 +msgid "[UP/DOWN] to scroll - [q] to close window" +msgstr "[HAUT/BAS] pour faire défiler - [q] pour fermer la fenêtre" + +#: src/labels.h:266 +#, c-format +msgid "User Agents for %1$s" +msgstr "User Agents pour %1$s" + +#: src/labels.h:270 +msgid "Scheme Configuration" +msgstr "Configuration programme" + +#: src/labels.h:272 +msgid "[ENTER] to use scheme - [q]uit" +msgstr "[ENTREE] pour utiliser le programme - [q]uitter" + +#: src/labels.h:276 +msgid "Sort active module by" +msgstr "Trier le module actif par" + +#: src/labels.h:278 +msgid "[ENTER] select - [TAB] sort - [q]uit" +msgstr "[ENTREE] sélectionner - [TAB] trier - [q]uitter" + +#: src/labels.h:282 +msgid "GoAccess Quick Help" +msgstr "GoAccess aide rapide" + +#: src/labels.h:284 +msgid "[UP/DOWN] to scroll - [q] to quit" +msgstr "[HAUT/BAS] pour faire défiler - [q] pour quitter" + +#: src/labels.h:288 +#, fuzzy +msgid "In-Memory with On-Disk Persistent Storage." +msgstr "En mémoire avec le stockage de disque persistant." + +#: src/labels.h:292 +msgid "Format Errors - Verify your log/date/time format" +msgstr "Erreurs de format - Vérifiez votre format de journal / date / heure" + +#: src/labels.h:294 +msgid "No date format was found on your conf file." +msgstr "Aucun format de date n'a été trouvé sur votre fichier conf." + +#: src/labels.h:296 +msgid "No log format was found on your conf file." +msgstr "Aucun format de journal n'a été trouvé sur votre fichier conf." + +#: src/labels.h:298 +msgid "No time format was found on your conf file." +msgstr "Aucun format de journal n'a été trouvé sur votre fichier conf." + +#: src/labels.h:300 +msgid "No default config file found." +msgstr "Aucun fichier de configuration par défaut trouvé." + +#: src/labels.h:302 +msgid "You may specify one with" +msgstr "Vous pouvez en préciser un avec" + +#: src/labels.h:304 +msgid "producing the following errors" +msgstr "produisant les erreurs suivantes" + +#: src/labels.h:306 +#, c-format +msgid "Parsed %1$d lines" +msgstr "Analysé %1$d lignes" + +#: src/labels.h:308 +msgid "Please report it by opening an issue on GitHub" +msgstr "Si vous plaît, rapporter cela en ouvrant un probleme sur GitHub" + +#: src/labels.h:310 +msgid "Select a time format." +msgstr "Sélectionner un format temporel." + +#: src/labels.h:312 +msgid "Select a date format." +msgstr "Sélectionner un format de date." + +#: src/labels.h:314 +msgid "Select a log format." +msgstr "Sélectionner un format de log." + +#: src/labels.h:316 +#, c-format +msgid "'%1$s' panel is disabled" +msgstr "'%1$s' panneau désactivé" + +#: src/labels.h:318 +msgid "No input data was provided nor there's data to restore." +msgstr "" + +#: src/labels.h:320 +msgid "Unable to allocate memory for a log instance." +msgstr "" + +#: src/labels.h:322 +msgid "Unable to find the given log." +msgstr "" + +#: src/labels.h:326 +msgid "For more details visit" +msgstr "Pour plus de détails, visitez" + +#: src/labels.h:328 +msgid "Last Updated" +msgstr "Dernière mise à jour" + +#: src/labels.h:330 +msgid "WebSocket server ready to accept new client connections" +msgstr "WebSocket serveur prêt à accepter les nouvelles connexions client" + +#: src/labels.h:333 +msgid "The following options can also be supplied to the command" +msgstr "Les options suivantes peuvent également être fournies à la commande" + +#: src/labels.h:335 +msgid "Examples can be found by running" +msgstr "Des exemples peuvent être trouvés en cours d'exécution" + +#: src/labels.h:338 +msgid "Server Statistics" +msgstr "Statistiques du serveur" + +#: src/labels.h:340 +msgid "Theme" +msgstr "Thème" + +#: src/labels.h:342 +msgid "Dark Gray" +msgstr "Gris foncé" + +#: src/labels.h:344 +msgid "Bright" +msgstr "Brillant" + +#: src/labels.h:346 +msgid "Dark Blue" +msgstr "Bleu foncé" + +#: src/labels.h:348 +#, fuzzy +msgid "Dark Purple" +msgstr "Violet foncé" + +#: src/labels.h:350 +msgid "Panels" +msgstr "Panneaux" + +#: src/labels.h:352 +msgid "Items per Page" +msgstr "Objets par page" + +#: src/labels.h:354 +msgid "Tables" +msgstr "Tableaux" + +#: src/labels.h:356 +msgid "Display Tables" +msgstr "Afficher les tableaux" + +#: src/labels.h:358 +msgid "Auto-Hide on Small Devices" +msgstr "Masquage-auto/Petits appareils" + +#: src/labels.h:360 +msgid "Automatically hide tables on small screen devices" +msgstr "" +"Masquer automatiquement les tableaux sur les appareils avec un petit écran" + +#: src/labels.h:362 +msgid "Toggle Panel" +msgstr "" + +#: src/labels.h:364 +msgid "Layout" +msgstr "Disposition" + +#: src/labels.h:366 +msgid "Horizontal" +msgstr "Horizontal" + +#: src/labels.h:368 +msgid "Vertical" +msgstr "Verticale" + +#: src/labels.h:370 +msgid "WideScreen" +msgstr "Grand écran" + +#: src/labels.h:372 +msgid "File Options" +msgstr "Options de fichier" + +#: src/labels.h:374 +msgid "Export as JSON" +msgstr "Exporter en tant que JSON" + +#: src/labels.h:376 +msgid "Panel Options" +msgstr "Options du panneau" + +#: src/labels.h:378 +msgid "Previous" +msgstr "Précédent" + +#: src/labels.h:380 +msgid "Next" +msgstr "Suivant" + +#: src/labels.h:382 +msgid "First" +msgstr "Premier" + +#: src/labels.h:384 +msgid "Last" +msgstr "Dernier" + +#: src/labels.h:386 +msgid "Chart Options" +msgstr "Options du graphique" + +#: src/labels.h:388 +msgid "Chart" +msgstr "Graphique" + +#: src/labels.h:390 +msgid "Type" +msgstr "Type" + +#: src/labels.h:392 +msgid "Area Spline" +msgstr "Courbe vectorielle" + +#: src/labels.h:394 +msgid "Bar" +msgstr "Barre" + +#: src/labels.h:396 +msgid "World Map" +msgstr "" + +#: src/labels.h:398 +msgid "Plot Metric" +msgstr "Tracé métrique" + +#: src/labels.h:400 +msgid "Table Columns" +msgstr "Colonnes de tableau" + +#: src/labels.h:404 +msgid "0xx Unofficial Codes" +msgstr "" + +#: src/labels.h:406 +msgid "1xx Informational" +msgstr "1xx Informationnel" + +#: src/labels.h:408 +msgid "2xx Success" +msgstr "2xx Succès" + +#: src/labels.h:410 +msgid "3xx Redirection" +msgstr "3xx Redirection" + +#: src/labels.h:412 +msgid "4xx Client Errors" +msgstr "4xx Erreurs Client" + +#: src/labels.h:414 +msgid "5xx Server Errors" +msgstr "5xx Erreurs Serveur" + +#: src/labels.h:417 +msgid "0 - Caddy: Unhandled - No configured routes" +msgstr "" + +#: src/labels.h:419 +msgid "100 - Continue: Server received the initial part of the request" +msgstr "100 - Continue: Le serveur a reçu la partie initiale de la requête" + +#: src/labels.h:421 +msgid "101 - Switching Protocols: Client asked to switch protocols" +msgstr "" +"101 - Echange de Protocoles: Le client a demandé à changer de protocole" + +#: src/labels.h:423 +msgid "200 - OK: The request sent by the client was successful" +msgstr "200 - OK: La requête envoyée par le client a réussie" + +#: src/labels.h:425 +msgid "201 - Created: The request has been fulfilled and created" +msgstr "201 - Created: La requête a été aboutie et créée" + +#: src/labels.h:427 +msgid "202 - Accepted: The request has been accepted for processing" +msgstr "202 - Accepté: La requête a été acceptée pour être traité" + +#: src/labels.h:429 +msgid "203 - Non-authoritative Information: Response from a third party" +msgstr "203 - Information sans autorité: Réponse d'un tiers" + +#: src/labels.h:431 +msgid "204 - No Content: Request did not return any content" +msgstr "204 - Aucun contenu: La requête ne renvoie aucun contenu" + +#: src/labels.h:433 +msgid "205 - Reset Content: Server asked the client to reset the document" +msgstr "" +"205 - Contenu réinitialisé: Le serveur a demandé au client de réinitialiser " +"le document" + +#: src/labels.h:435 +msgid "206 - Partial Content: The partial GET has been successful" +msgstr "206 - Contenu partiel: Le GET partiel a réussi" + +#: src/labels.h:437 +msgid "207 - Multi-Status: WebDAV; RFC 4918" +msgstr "207 - Status-multiples: WebDAV; RFC 4918" + +#: src/labels.h:439 +msgid "208 - Already Reported: WebDAV; RFC 5842" +msgstr "208 - Déjà signalé: WebDAV; RFC 5842" + +#: src/labels.h:441 +msgid "218 - This is fine: Apache servers. A catch-all error condition" +msgstr "" + +#: src/labels.h:443 +msgid "300 - Multiple Choices: Multiple options for the resource" +msgstr "300 - Choix multiples: Options multiples pour la ressource" + +#: src/labels.h:445 +msgid "301 - Moved Permanently: Resource has permanently moved" +msgstr "" +"301 - Déplacement permanent: La ressource a été déplacée de façon permanente" + +#: src/labels.h:447 +msgid "302 - Moved Temporarily (redirect)" +msgstr "302 - Temporairement déplacé (redirigé)" + +#: src/labels.h:449 +msgid "303 - See Other Document: The response is at a different URI" +msgstr "303 - Voir autre document: La réponse se situe sur une URI différente" + +#: src/labels.h:451 +msgid "304 - Not Modified: Resource has not been modified" +msgstr "304 - Non modifié: La ressource n'a pas été modifiée" + +#: src/labels.h:453 +msgid "305 - Use Proxy: Can only be accessed through the proxy" +msgstr "305 - Utiliser un Proxy : Accessible seulement depuis le proxy" + +#: src/labels.h:455 +msgid "307 - Temporary Redirect: Resource temporarily moved" +msgstr "307 - Redirection temporaire: Ressource temporairement déplacée" + +#: src/labels.h:457 +#, fuzzy +msgid "308 - Permanent Redirect" +msgstr "402 - Paiement requis" + +#: src/labels.h:459 +msgid "400 - Bad Request: The syntax of the request is invalid" +msgstr "400 - Mauvaise requête: Syntaxe de la requête invalide" + +#: src/labels.h:461 +msgid "401 - Unauthorized: Request needs user authentication" +msgstr "" +"401 - Non autorisé: La requête nécessite une authentification utilisateur" + +#: src/labels.h:463 +msgid "402 - Payment Required" +msgstr "402 - Paiement requis" + +#: src/labels.h:465 +msgid "403 - Forbidden: Server is refusing to respond to it" +msgstr "403 - Interdit: Le serveur refuse d'y répondre" + +#: src/labels.h:467 +msgid "404 - Not Found: Requested resource could not be found" +msgstr "404 - Non trouvé: La ressource demandée ne peut pas être trouvée" + +#: src/labels.h:469 +msgid "405 - Method Not Allowed: Request method not supported" +msgstr "405 - Méthode non autorisée: Méthode de requête non supportée" + +#: src/labels.h:471 +msgid "406 - Not Acceptable" +msgstr "406 - Pas Acceptable" + +#: src/labels.h:473 +msgid "407 - Proxy Authentication Required" +msgstr "407 - Authentification au proxy requise" + +#: src/labels.h:475 +msgid "408 - Request Timeout: Server timed out waiting for the request" +msgstr "" +"408 - Requête expirée: Délai d'attente du serveur dépassé pour la requête" + +#: src/labels.h:477 +msgid "409 - Conflict: Conflict in the request" +msgstr "409 - Conflit: Conflit dans la requête" + +#: src/labels.h:479 +msgid "410 - Gone: Resource requested is no longer available" +msgstr "410 - Disparue: La ressource demandée n'est plus disponible" + +#: src/labels.h:481 +msgid "411 - Length Required: Invalid Content-Length" +msgstr "411 - Longueur requise: Longueur du contenu invalide" + +#: src/labels.h:483 +msgid "412 - Precondition Failed: Server does not meet preconditions" +msgstr "412 - Pré-requis échoué: Le serveur ne rempli pas les pré-requis" + +#: src/labels.h:485 +msgid "413 - Payload Too Large" +msgstr "413 - Charge utile trop importante" + +#: src/labels.h:487 +msgid "414 - Request-URI Too Long" +msgstr "414 - URI requête trop longue" + +#: src/labels.h:489 +msgid "415 - Unsupported Media Type: Media type is not supported" +msgstr "415 - Type de média non supporté : Type de media non pris en charge" + +#: src/labels.h:491 +msgid "416 - Requested Range Not Satisfiable: Cannot supply that portion" +msgstr "" +"416 - Plage de requête non satisfaisante: ne peut pas fournir cette partie" + +#: src/labels.h:493 +msgid "417 - Expectation Failed" +msgstr "417 - Attente échouée" + +#: src/labels.h:495 +#, fuzzy +msgid "418 - I'm a teapot" +msgstr "418 - Je suis une théière" + +#: src/labels.h:497 +msgid "419 - Page Expired: Laravel Framework when a CSRF Token is missing" +msgstr "" + +#: src/labels.h:499 +msgid "420 - Method Failure: Spring Framework when a method has failed" +msgstr "" + +#: src/labels.h:501 +msgid "421 - Misdirected Request" +msgstr "421 - Requête mal orientée" + +#: src/labels.h:503 +msgid "422 - Unprocessable Entity due to semantic errors: WebDAV" +msgstr "422 - Entité non traitable à cause des erreurs sémantiques: WebDAV" + +#: src/labels.h:505 +msgid "423 - The resource that is being accessed is locked" +msgstr "423 - L'accès à la ressource est verrouillé" + +#: src/labels.h:507 +msgid "424 - Failed Dependency: WebDAV" +msgstr "424 - Dépendance échouée: WebDAV" + +#: src/labels.h:509 +msgid "426 - Upgrade Required: Client should switch to a different protocol" +msgstr "" +"426 - Amélioration requise: Le client devrait changer pour un protocole " +"différent" + +#: src/labels.h:511 +msgid "428 - Precondition Required" +msgstr "428 - Condition préalable requise" + +#: src/labels.h:513 +msgid "429 - Too Many Requests: The user has sent too many requests" +msgstr "429 : Trop de requêtes: L'utilisateur a envoyé trop de requêtes" + +#: src/labels.h:515 +msgid "" +"430 - Request Header Fields Too Large: Too many URLs are requested within a " +"certain time frame" +msgstr "" + +#: src/labels.h:517 +msgid "431 - Request Header Fields Too Large" +msgstr "431 - Le champ en-tête de requête est trop large" + +#: src/labels.h:519 +msgid "440 - Login Time-out: The client's session has expired" +msgstr "" + +#: src/labels.h:521 +#, fuzzy +msgid "449 - Retry With: The server cannot honour the request" +msgstr "" +"408 - Requête expirée: Délai d'attente du serveur dépassé pour la requête" + +#: src/labels.h:523 +msgid "" +"450 - Blocked by Windows Parental Controls: The Microsoft extension code " +"indicated" +msgstr "" + +#: src/labels.h:525 +msgid "451 - Unavailable For Legal Reasons" +msgstr "451 - Indisponible pour des raisons légales" + +#: src/labels.h:527 +msgid "444 - (Nginx) Connection closed without sending any headers" +msgstr "444 - (Nginx) Connexion fermée sans envoyer d'en-têtes" + +#: src/labels.h:529 +msgid "460 - AWS Elastic Load Balancing: Client closed the connection " +msgstr "" + +#: src/labels.h:531 +msgid "" +"463 - AWS Elastic Load Balancing: The load balancer received more than 30 IP " +"addresses" +msgstr "" + +#: src/labels.h:533 +msgid "464 - AWS Elastic Load Balancing: Incompatible protocol versions" +msgstr "" + +#: src/labels.h:535 +msgid "494 - (Nginx) Request Header Too Large" +msgstr "494 - (Nginx) En-tête de requête trop large" + +#: src/labels.h:537 +msgid "495 - (Nginx) SSL client certificate error" +msgstr "495 - (Nginx) Erreur de certificat SSL client" + +#: src/labels.h:539 +msgid "496 - (Nginx) Client didn't provide certificate" +msgstr "496 - (Nginx) Le client ne fournit pas de certificat" + +#: src/labels.h:541 +msgid "497 - (Nginx) HTTP request sent to HTTPS port" +msgstr "497 - (Nginx) Requête HTTP envoyée sur le port HTTPS" + +#: src/labels.h:543 +msgid "498 - Invalid Token: an expired or otherwise invalid token" +msgstr "" + +#: src/labels.h:545 +msgid "499 - (Nginx) Connection closed by client while processing request" +msgstr "" +"499 - (Nginx) Connexion fermée par le client durant le traitement de la " +"requête" + +#: src/labels.h:547 +msgid "500 - Internal Server Error" +msgstr "500 - Erreur serveur interne" + +#: src/labels.h:549 +msgid "501 - Not Implemented" +msgstr "501 - Non implémenté" + +#: src/labels.h:551 +msgid "502 - Bad Gateway: Received an invalid response from the upstream" +msgstr "502 - Mauvaise passerelle: Réponse invalide reçue en amont" + +#: src/labels.h:553 +msgid "503 - Service Unavailable: The server is currently unavailable" +msgstr "503 - Service indisponible: Le serveur est actuellement indisponible" + +#: src/labels.h:555 +msgid "504 - Gateway Timeout: The upstream server failed to send request" +msgstr "" +"504 - Attente passerelle dépassé: l'envoi de la requête en amont par le " +"serveur a échoué" + +#: src/labels.h:557 +msgid "505 - HTTP Version Not Supported" +msgstr "505 - Version HTTP non supportée" + +#: src/labels.h:559 +msgid "509 - Bandwidth Limit Exceeded: The server has exceeded the bandwidth" +msgstr "" + +#: src/labels.h:561 +msgid "520 - CloudFlare - Web server is returning an unknown error" +msgstr "520 - CloudFlare - Le serveur Web renvoi une erreur inconnue" + +#: src/labels.h:563 +msgid "521 - CloudFlare - Web server is down" +msgstr "521 - CloudFlare - Serveur Web en panne" + +#: src/labels.h:565 +msgid "522 - CloudFlare - Connection timed out" +msgstr "522 - CloudFlare - Délai de connexion dépassé" + +#: src/labels.h:567 +msgid "523 - CloudFlare - Origin is unreachable" +msgstr "523 - CloudFlare - L'Origin n'est pas joignable" + +#: src/labels.h:569 +msgid "524 - CloudFlare - A timeout occurred" +msgstr "524 - CloudFlare - Un dépassement du délai s'est produit" + +#: src/labels.h:571 +msgid "" +"525 - SSL Handshake Failed: Cloudflare could not negotiate a SSL/TLS " +"handshake" +msgstr "" + +#: src/labels.h:573 +msgid "" +"526 - Invalid SSL Certificate: Cloudflare could not validate the SSL " +"certificate" +msgstr "" + +#: src/labels.h:575 +msgid "527 - Railgun Error: An interrupted connection" +msgstr "" + +#: src/labels.h:577 +msgid "529 - Site is overloaded: A site can not process the request" +msgstr "" + +#: src/labels.h:579 +msgid "530 - Site is frozen: A site has been frozen due to inactivity" +msgstr "" + +#: src/labels.h:581 +msgid "" +"540 - Temporarily Disabled: The requested endpoint has been temporarily " +"disabled" +msgstr "" + +#: src/labels.h:583 +#, fuzzy +msgid "561 - Unauthorized: An error around authentication" +msgstr "" +"401 - Non autorisé: La requête nécessite une authentification utilisateur" + +#: src/labels.h:585 +msgid "" +"598 - Network read timeout error: some HTTP proxies to signal a network read " +"timeout" +msgstr "" + +#: src/labels.h:587 +msgid "599 - Network Connect Timeout Error: An error used by some HTTP proxies" +msgstr "" + +#: src/labels.h:589 +msgid "783 - Unexpected Token: The request includes a JSON syntax error" +msgstr "" + +#, fuzzy +#~ msgid "Referers" +#~ msgstr "Origine" diff --git a/po/goaccess.pot b/po/goaccess.pot new file mode 100644 index 0000000000..287b4d72a3 --- /dev/null +++ b/po/goaccess.pot @@ -0,0 +1,1052 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR Free Software Foundation, Inc. +# This file is distributed under the same license as the goaccess package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: goaccess 1.9.2\n" +"Report-Msgid-Bugs-To: hello@goaccess.io\n" +"POT-Creation-Date: 2024-04-11 20:17-0500\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: src/labels.h:45 +msgid "en" +msgstr "" + +#: src/labels.h:48 +msgid "Exp. Panel" +msgstr "" + +#: src/labels.h:49 +msgid "Help" +msgstr "" + +#: src/labels.h:50 +msgid "Quit" +msgstr "" + +#: src/labels.h:51 +msgid "Total" +msgstr "" + +#: src/labels.h:54 +msgid "[x] ASC [ ] DESC" +msgstr "" + +#: src/labels.h:55 +msgid "[ ] ASC [x] DESC" +msgstr "" + +#: src/labels.h:58 +#, c-format +msgid "[Active Panel: %1$s]" +msgstr "" + +#: src/labels.h:59 +msgid "[q]uit GoAccess" +msgstr "" + +#: src/labels.h:60 +msgid "[?] Help [Enter] Exp. Panel" +msgstr "" + +#: src/labels.h:61 +msgid "Dashboard" +msgstr "" + +#: src/labels.h:62 +msgid "Dashboard - Overall Analyzed Requests" +msgstr "" + +#: src/labels.h:63 +msgid "Overall Analyzed Requests" +msgstr "" + +#: src/labels.h:65 src/labels.h:86 +msgid "Tx. Amount" +msgstr "" + +#: src/labels.h:66 +msgid "Date/Time" +msgstr "" + +#: src/labels.h:67 +msgid "Excl. IP Hits" +msgstr "" + +#: src/labels.h:68 +msgid "Failed Requests" +msgstr "" + +#: src/labels.h:69 +msgid "Log Parsing Time" +msgstr "" + +#: src/labels.h:70 +msgid "Log Size" +msgstr "" + +#: src/labels.h:71 +msgid "Log Source" +msgstr "" + +#: src/labels.h:72 src/labels.h:187 +msgid "Referrers" +msgstr "" + +#: src/labels.h:73 +msgid "Total Requests" +msgstr "" + +#: src/labels.h:74 +msgid "Static Files" +msgstr "" + +#: src/labels.h:75 src/labels.h:159 +msgid "Not Found" +msgstr "" + +#: src/labels.h:76 +msgid "Requested Files" +msgstr "" + +#: src/labels.h:77 +msgid "Unique Visitors" +msgstr "" + +#: src/labels.h:78 +msgid "Valid Requests" +msgstr "" + +#: src/labels.h:81 +msgid "Hits" +msgstr "" + +#: src/labels.h:82 +msgid "h%" +msgstr "" + +#: src/labels.h:83 src/labels.h:110 +msgid "Visitors" +msgstr "" + +#: src/labels.h:84 +msgid "Vis." +msgstr "" + +#: src/labels.h:85 +msgid "v%" +msgstr "" + +#: src/labels.h:87 +msgid "Avg. T.S." +msgstr "" + +#: src/labels.h:88 +msgid "Cum. T.S." +msgstr "" + +#: src/labels.h:89 +msgid "Max. T.S." +msgstr "" + +#: src/labels.h:90 +msgid "Method" +msgstr "" + +#: src/labels.h:91 +msgid "Mtd" +msgstr "" + +#: src/labels.h:92 +msgid "Protocol" +msgstr "" + +#: src/labels.h:93 +msgid "Proto" +msgstr "" + +#: src/labels.h:94 +msgid "City" +msgstr "" + +#: src/labels.h:95 src/labels.h:211 src/labels.h:215 +msgid "ASN" +msgstr "" + +#: src/labels.h:96 +msgid "Country" +msgstr "" + +#: src/labels.h:97 +msgid "Hostname" +msgstr "" + +#: src/labels.h:98 +msgid "Data" +msgstr "" + +#: src/labels.h:100 +msgid "Hits/Visitors" +msgstr "" + +#: src/labels.h:104 +msgid "Unique visitors per day" +msgstr "" + +#: src/labels.h:106 +msgid "Unique visitors per day - Including spiders" +msgstr "" + +#: src/labels.h:108 +msgid "Hits having the same IP, date and agent are a unique visit." +msgstr "" + +#: src/labels.h:113 +msgid "Requested Files (URLs)" +msgstr "" + +#: src/labels.h:115 +msgid "Top requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" + +#: src/labels.h:117 +msgid "Requests" +msgstr "" + +#: src/labels.h:120 src/labels.h:124 +msgid "Static Requests" +msgstr "" + +#: src/labels.h:122 +msgid "Top static requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" + +#: src/labels.h:127 +msgid "Time Distribution" +msgstr "" + +#: src/labels.h:129 +msgid "Data sorted by hour [, avgts, cumts, maxts]" +msgstr "" + +#: src/labels.h:131 +msgid "Time" +msgstr "" + +#: src/labels.h:134 src/labels.h:138 +msgid "Virtual Hosts" +msgstr "" + +#: src/labels.h:136 src/labels.h:143 src/labels.h:150 +msgid "Data sorted by hits [, avgts, cumts, maxts]" +msgstr "" + +#: src/labels.h:141 +msgid "Remote User (HTTP authentication)" +msgstr "" + +#: src/labels.h:145 +msgid "Remote User" +msgstr "" + +#: src/labels.h:148 +msgid "The cache status of the object served" +msgstr "" + +#: src/labels.h:152 +msgid "Cache Status" +msgstr "" + +#: src/labels.h:155 +msgid "Not Found URLs (404s)" +msgstr "" + +#: src/labels.h:157 +msgid "Top not found URLs sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" + +#: src/labels.h:162 +msgid "Visitor Hostnames and IPs" +msgstr "" + +#: src/labels.h:164 +msgid "Top visitor hosts sorted by hits [, avgts, cumts, maxts]" +msgstr "" + +#: src/labels.h:166 +msgid "Hosts" +msgstr "" + +#: src/labels.h:169 +msgid "Operating Systems" +msgstr "" + +#: src/labels.h:171 +msgid "Top Operating Systems sorted by hits [, avgts, cumts, maxts]" +msgstr "" + +#: src/labels.h:173 +msgid "OS" +msgstr "" + +#: src/labels.h:176 src/labels.h:180 +msgid "Browsers" +msgstr "" + +#: src/labels.h:178 +msgid "Top Browsers sorted by hits [, avgts, cumts, maxts]" +msgstr "" + +#: src/labels.h:183 +msgid "Referrer URLs" +msgstr "" + +#: src/labels.h:185 +msgid "Top Requested Referrers sorted by hits [, avgts, cumts, maxts]" +msgstr "" + +#: src/labels.h:190 src/labels.h:194 +msgid "Referring Sites" +msgstr "" + +#: src/labels.h:192 +msgid "Top Referring Sites sorted by hits [, avgts, cumts, maxts]" +msgstr "" + +#: src/labels.h:197 +msgid "Keyphrases from Google's search engine" +msgstr "" + +#: src/labels.h:199 +msgid "Top Keyphrases sorted by hits [, avgts, cumts, maxts]" +msgstr "" + +#: src/labels.h:201 +msgid "Keyphrases" +msgstr "" + +#: src/labels.h:204 src/labels.h:208 +msgid "Geo Location" +msgstr "" + +#: src/labels.h:206 +msgid "Continent > Country sorted by unique hits [, avgts, cumts, maxts]" +msgstr "" + +#: src/labels.h:213 +msgid "Autonomous System Numbers/Organizations (ASNs)" +msgstr "" + +#: src/labels.h:218 +msgid "HTTP Status Codes" +msgstr "" + +#: src/labels.h:220 +msgid "Top HTTP Status Codes sorted by hits [, avgts, cumts, maxts]" +msgstr "" + +#: src/labels.h:222 +msgid "Status Codes" +msgstr "" + +#: src/labels.h:225 src/labels.h:229 +msgid "MIME Types" +msgstr "" + +#: src/labels.h:227 +msgid "File types shipped out" +msgstr "" + +#: src/labels.h:232 +msgid "Encryption settings" +msgstr "" + +#: src/labels.h:234 +msgid "TLS version and picked algorithm" +msgstr "" + +#: src/labels.h:236 +msgid "TLS Settings" +msgstr "" + +#: src/labels.h:240 +msgid "[ ] case sensitive" +msgstr "" + +#: src/labels.h:242 +msgid "[x] case sensitive" +msgstr "" + +#: src/labels.h:244 +msgid "Regex allowed - ^g to cancel - TAB switch case" +msgstr "" + +#: src/labels.h:246 +msgid "Find pattern in all views" +msgstr "" + +#: src/labels.h:250 +msgid "Log Format Configuration" +msgstr "" + +#: src/labels.h:252 +msgid "[SPACE] to toggle - [ENTER] to proceed - [q] to quit" +msgstr "" + +#: src/labels.h:254 +msgid "Log Format - [c] to add/edit format" +msgstr "" + +#: src/labels.h:256 +msgid "Date Format - [d] to add/edit format" +msgstr "" + +#: src/labels.h:258 +msgid "Time Format - [t] to add/edit format" +msgstr "" + +#: src/labels.h:260 src/labels.h:264 +msgid "[UP/DOWN] to scroll - [q] to close window" +msgstr "" + +#: src/labels.h:266 +#, c-format +msgid "User Agents for %1$s" +msgstr "" + +#: src/labels.h:270 +msgid "Scheme Configuration" +msgstr "" + +#: src/labels.h:272 +msgid "[ENTER] to use scheme - [q]uit" +msgstr "" + +#: src/labels.h:276 +msgid "Sort active module by" +msgstr "" + +#: src/labels.h:278 +msgid "[ENTER] select - [TAB] sort - [q]uit" +msgstr "" + +#: src/labels.h:282 +msgid "GoAccess Quick Help" +msgstr "" + +#: src/labels.h:284 +msgid "[UP/DOWN] to scroll - [q] to quit" +msgstr "" + +#: src/labels.h:288 +msgid "In-Memory with On-Disk Persistent Storage." +msgstr "" + +#: src/labels.h:292 +msgid "Format Errors - Verify your log/date/time format" +msgstr "" + +#: src/labels.h:294 +msgid "No date format was found on your conf file." +msgstr "" + +#: src/labels.h:296 +msgid "No log format was found on your conf file." +msgstr "" + +#: src/labels.h:298 +msgid "No time format was found on your conf file." +msgstr "" + +#: src/labels.h:300 +msgid "No default config file found." +msgstr "" + +#: src/labels.h:302 +msgid "You may specify one with" +msgstr "" + +#: src/labels.h:304 +msgid "producing the following errors" +msgstr "" + +#: src/labels.h:306 +#, c-format +msgid "Parsed %1$d lines" +msgstr "" + +#: src/labels.h:308 +msgid "Please report it by opening an issue on GitHub" +msgstr "" + +#: src/labels.h:310 +msgid "Select a time format." +msgstr "" + +#: src/labels.h:312 +msgid "Select a date format." +msgstr "" + +#: src/labels.h:314 +msgid "Select a log format." +msgstr "" + +#: src/labels.h:316 +#, c-format +msgid "'%1$s' panel is disabled" +msgstr "" + +#: src/labels.h:318 +msgid "No input data was provided nor there's data to restore." +msgstr "" + +#: src/labels.h:320 +msgid "Unable to allocate memory for a log instance." +msgstr "" + +#: src/labels.h:322 +msgid "Unable to find the given log." +msgstr "" + +#: src/labels.h:326 +msgid "For more details visit" +msgstr "" + +#: src/labels.h:328 +msgid "Last Updated" +msgstr "" + +#: src/labels.h:330 +msgid "WebSocket server ready to accept new client connections" +msgstr "" + +#: src/labels.h:333 +msgid "The following options can also be supplied to the command" +msgstr "" + +#: src/labels.h:335 +msgid "Examples can be found by running" +msgstr "" + +#: src/labels.h:338 +msgid "Server Statistics" +msgstr "" + +#: src/labels.h:340 +msgid "Theme" +msgstr "" + +#: src/labels.h:342 +msgid "Dark Gray" +msgstr "" + +#: src/labels.h:344 +msgid "Bright" +msgstr "" + +#: src/labels.h:346 +msgid "Dark Blue" +msgstr "" + +#: src/labels.h:348 +msgid "Dark Purple" +msgstr "" + +#: src/labels.h:350 +msgid "Panels" +msgstr "" + +#: src/labels.h:352 +msgid "Items per Page" +msgstr "" + +#: src/labels.h:354 +msgid "Tables" +msgstr "" + +#: src/labels.h:356 +msgid "Display Tables" +msgstr "" + +#: src/labels.h:358 +msgid "Auto-Hide on Small Devices" +msgstr "" + +#: src/labels.h:360 +msgid "Automatically hide tables on small screen devices" +msgstr "" + +#: src/labels.h:362 +msgid "Toggle Panel" +msgstr "" + +#: src/labels.h:364 +msgid "Layout" +msgstr "" + +#: src/labels.h:366 +msgid "Horizontal" +msgstr "" + +#: src/labels.h:368 +msgid "Vertical" +msgstr "" + +#: src/labels.h:370 +msgid "WideScreen" +msgstr "" + +#: src/labels.h:372 +msgid "File Options" +msgstr "" + +#: src/labels.h:374 +msgid "Export as JSON" +msgstr "" + +#: src/labels.h:376 +msgid "Panel Options" +msgstr "" + +#: src/labels.h:378 +msgid "Previous" +msgstr "" + +#: src/labels.h:380 +msgid "Next" +msgstr "" + +#: src/labels.h:382 +msgid "First" +msgstr "" + +#: src/labels.h:384 +msgid "Last" +msgstr "" + +#: src/labels.h:386 +msgid "Chart Options" +msgstr "" + +#: src/labels.h:388 +msgid "Chart" +msgstr "" + +#: src/labels.h:390 +msgid "Type" +msgstr "" + +#: src/labels.h:392 +msgid "Area Spline" +msgstr "" + +#: src/labels.h:394 +msgid "Bar" +msgstr "" + +#: src/labels.h:396 +msgid "World Map" +msgstr "" + +#: src/labels.h:398 +msgid "Plot Metric" +msgstr "" + +#: src/labels.h:400 +msgid "Table Columns" +msgstr "" + +#: src/labels.h:404 +msgid "0xx Unofficial Codes" +msgstr "" + +#: src/labels.h:406 +msgid "1xx Informational" +msgstr "" + +#: src/labels.h:408 +msgid "2xx Success" +msgstr "" + +#: src/labels.h:410 +msgid "3xx Redirection" +msgstr "" + +#: src/labels.h:412 +msgid "4xx Client Errors" +msgstr "" + +#: src/labels.h:414 +msgid "5xx Server Errors" +msgstr "" + +#: src/labels.h:417 +msgid "0 - Caddy: Unhandled - No configured routes" +msgstr "" + +#: src/labels.h:419 +msgid "100 - Continue: Server received the initial part of the request" +msgstr "" + +#: src/labels.h:421 +msgid "101 - Switching Protocols: Client asked to switch protocols" +msgstr "" + +#: src/labels.h:423 +msgid "200 - OK: The request sent by the client was successful" +msgstr "" + +#: src/labels.h:425 +msgid "201 - Created: The request has been fulfilled and created" +msgstr "" + +#: src/labels.h:427 +msgid "202 - Accepted: The request has been accepted for processing" +msgstr "" + +#: src/labels.h:429 +msgid "203 - Non-authoritative Information: Response from a third party" +msgstr "" + +#: src/labels.h:431 +msgid "204 - No Content: Request did not return any content" +msgstr "" + +#: src/labels.h:433 +msgid "205 - Reset Content: Server asked the client to reset the document" +msgstr "" + +#: src/labels.h:435 +msgid "206 - Partial Content: The partial GET has been successful" +msgstr "" + +#: src/labels.h:437 +msgid "207 - Multi-Status: WebDAV; RFC 4918" +msgstr "" + +#: src/labels.h:439 +msgid "208 - Already Reported: WebDAV; RFC 5842" +msgstr "" + +#: src/labels.h:441 +msgid "218 - This is fine: Apache servers. A catch-all error condition" +msgstr "" + +#: src/labels.h:443 +msgid "300 - Multiple Choices: Multiple options for the resource" +msgstr "" + +#: src/labels.h:445 +msgid "301 - Moved Permanently: Resource has permanently moved" +msgstr "" + +#: src/labels.h:447 +msgid "302 - Moved Temporarily (redirect)" +msgstr "" + +#: src/labels.h:449 +msgid "303 - See Other Document: The response is at a different URI" +msgstr "" + +#: src/labels.h:451 +msgid "304 - Not Modified: Resource has not been modified" +msgstr "" + +#: src/labels.h:453 +msgid "305 - Use Proxy: Can only be accessed through the proxy" +msgstr "" + +#: src/labels.h:455 +msgid "307 - Temporary Redirect: Resource temporarily moved" +msgstr "" + +#: src/labels.h:457 +msgid "308 - Permanent Redirect" +msgstr "" + +#: src/labels.h:459 +msgid "400 - Bad Request: The syntax of the request is invalid" +msgstr "" + +#: src/labels.h:461 +msgid "401 - Unauthorized: Request needs user authentication" +msgstr "" + +#: src/labels.h:463 +msgid "402 - Payment Required" +msgstr "" + +#: src/labels.h:465 +msgid "403 - Forbidden: Server is refusing to respond to it" +msgstr "" + +#: src/labels.h:467 +msgid "404 - Not Found: Requested resource could not be found" +msgstr "" + +#: src/labels.h:469 +msgid "405 - Method Not Allowed: Request method not supported" +msgstr "" + +#: src/labels.h:471 +msgid "406 - Not Acceptable" +msgstr "" + +#: src/labels.h:473 +msgid "407 - Proxy Authentication Required" +msgstr "" + +#: src/labels.h:475 +msgid "408 - Request Timeout: Server timed out waiting for the request" +msgstr "" + +#: src/labels.h:477 +msgid "409 - Conflict: Conflict in the request" +msgstr "" + +#: src/labels.h:479 +msgid "410 - Gone: Resource requested is no longer available" +msgstr "" + +#: src/labels.h:481 +msgid "411 - Length Required: Invalid Content-Length" +msgstr "" + +#: src/labels.h:483 +msgid "412 - Precondition Failed: Server does not meet preconditions" +msgstr "" + +#: src/labels.h:485 +msgid "413 - Payload Too Large" +msgstr "" + +#: src/labels.h:487 +msgid "414 - Request-URI Too Long" +msgstr "" + +#: src/labels.h:489 +msgid "415 - Unsupported Media Type: Media type is not supported" +msgstr "" + +#: src/labels.h:491 +msgid "416 - Requested Range Not Satisfiable: Cannot supply that portion" +msgstr "" + +#: src/labels.h:493 +msgid "417 - Expectation Failed" +msgstr "" + +#: src/labels.h:495 +msgid "418 - I'm a teapot" +msgstr "" + +#: src/labels.h:497 +msgid "419 - Page Expired: Laravel Framework when a CSRF Token is missing" +msgstr "" + +#: src/labels.h:499 +msgid "420 - Method Failure: Spring Framework when a method has failed" +msgstr "" + +#: src/labels.h:501 +msgid "421 - Misdirected Request" +msgstr "" + +#: src/labels.h:503 +msgid "422 - Unprocessable Entity due to semantic errors: WebDAV" +msgstr "" + +#: src/labels.h:505 +msgid "423 - The resource that is being accessed is locked" +msgstr "" + +#: src/labels.h:507 +msgid "424 - Failed Dependency: WebDAV" +msgstr "" + +#: src/labels.h:509 +msgid "426 - Upgrade Required: Client should switch to a different protocol" +msgstr "" + +#: src/labels.h:511 +msgid "428 - Precondition Required" +msgstr "" + +#: src/labels.h:513 +msgid "429 - Too Many Requests: The user has sent too many requests" +msgstr "" + +#: src/labels.h:515 +msgid "" +"430 - Request Header Fields Too Large: Too many URLs are requested within a " +"certain time frame" +msgstr "" + +#: src/labels.h:517 +msgid "431 - Request Header Fields Too Large" +msgstr "" + +#: src/labels.h:519 +msgid "440 - Login Time-out: The client's session has expired" +msgstr "" + +#: src/labels.h:521 +msgid "449 - Retry With: The server cannot honour the request" +msgstr "" + +#: src/labels.h:523 +msgid "" +"450 - Blocked by Windows Parental Controls: The Microsoft extension code " +"indicated" +msgstr "" + +#: src/labels.h:525 +msgid "451 - Unavailable For Legal Reasons" +msgstr "" + +#: src/labels.h:527 +msgid "444 - (Nginx) Connection closed without sending any headers" +msgstr "" + +#: src/labels.h:529 +msgid "460 - AWS Elastic Load Balancing: Client closed the connection " +msgstr "" + +#: src/labels.h:531 +msgid "" +"463 - AWS Elastic Load Balancing: The load balancer received more than 30 IP " +"addresses" +msgstr "" + +#: src/labels.h:533 +msgid "464 - AWS Elastic Load Balancing: Incompatible protocol versions" +msgstr "" + +#: src/labels.h:535 +msgid "494 - (Nginx) Request Header Too Large" +msgstr "" + +#: src/labels.h:537 +msgid "495 - (Nginx) SSL client certificate error" +msgstr "" + +#: src/labels.h:539 +msgid "496 - (Nginx) Client didn't provide certificate" +msgstr "" + +#: src/labels.h:541 +msgid "497 - (Nginx) HTTP request sent to HTTPS port" +msgstr "" + +#: src/labels.h:543 +msgid "498 - Invalid Token: an expired or otherwise invalid token" +msgstr "" + +#: src/labels.h:545 +msgid "499 - (Nginx) Connection closed by client while processing request" +msgstr "" + +#: src/labels.h:547 +msgid "500 - Internal Server Error" +msgstr "" + +#: src/labels.h:549 +msgid "501 - Not Implemented" +msgstr "" + +#: src/labels.h:551 +msgid "502 - Bad Gateway: Received an invalid response from the upstream" +msgstr "" + +#: src/labels.h:553 +msgid "503 - Service Unavailable: The server is currently unavailable" +msgstr "" + +#: src/labels.h:555 +msgid "504 - Gateway Timeout: The upstream server failed to send request" +msgstr "" + +#: src/labels.h:557 +msgid "505 - HTTP Version Not Supported" +msgstr "" + +#: src/labels.h:559 +msgid "509 - Bandwidth Limit Exceeded: The server has exceeded the bandwidth" +msgstr "" + +#: src/labels.h:561 +msgid "520 - CloudFlare - Web server is returning an unknown error" +msgstr "" + +#: src/labels.h:563 +msgid "521 - CloudFlare - Web server is down" +msgstr "" + +#: src/labels.h:565 +msgid "522 - CloudFlare - Connection timed out" +msgstr "" + +#: src/labels.h:567 +msgid "523 - CloudFlare - Origin is unreachable" +msgstr "" + +#: src/labels.h:569 +msgid "524 - CloudFlare - A timeout occurred" +msgstr "" + +#: src/labels.h:571 +msgid "" +"525 - SSL Handshake Failed: Cloudflare could not negotiate a SSL/TLS " +"handshake" +msgstr "" + +#: src/labels.h:573 +msgid "" +"526 - Invalid SSL Certificate: Cloudflare could not validate the SSL " +"certificate" +msgstr "" + +#: src/labels.h:575 +msgid "527 - Railgun Error: An interrupted connection" +msgstr "" + +#: src/labels.h:577 +msgid "529 - Site is overloaded: A site can not process the request" +msgstr "" + +#: src/labels.h:579 +msgid "530 - Site is frozen: A site has been frozen due to inactivity" +msgstr "" + +#: src/labels.h:581 +msgid "" +"540 - Temporarily Disabled: The requested endpoint has been temporarily " +"disabled" +msgstr "" + +#: src/labels.h:583 +msgid "561 - Unauthorized: An error around authentication" +msgstr "" + +#: src/labels.h:585 +msgid "" +"598 - Network read timeout error: some HTTP proxies to signal a network read " +"timeout" +msgstr "" + +#: src/labels.h:587 +msgid "599 - Network Connect Timeout Error: An error used by some HTTP proxies" +msgstr "" + +#: src/labels.h:589 +msgid "783 - Unexpected Token: The request includes a JSON syntax error" +msgstr "" diff --git a/po/it.po b/po/it.po new file mode 100644 index 0000000000..ec564d6b07 --- /dev/null +++ b/po/it.po @@ -0,0 +1,1074 @@ +msgid "" +msgstr "" +"Project-Id-Version: Goaccess\n" +"Report-Msgid-Bugs-To: hello@goaccess.io\n" +"POT-Creation-Date: 2024-04-11 20:17-0500\n" +"PO-Revision-Date: 2017-08-04 13:00-0300\n" +"Last-Translator: Mario Donnarumma \n" +"Language-Team: \n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.4\n" + +#: src/labels.h:45 +msgid "en" +msgstr "it" + +#: src/labels.h:48 +msgid "Exp. Panel" +msgstr "Exp. Panel" + +#: src/labels.h:49 +msgid "Help" +msgstr "Aiuto" + +#: src/labels.h:50 +msgid "Quit" +msgstr "Esci" + +#: src/labels.h:51 +msgid "Total" +msgstr "Totale" + +#: src/labels.h:54 +msgid "[x] ASC [ ] DESC" +msgstr "[x] ASC [ ] DESC" + +#: src/labels.h:55 +msgid "[ ] ASC [x] DESC" +msgstr "[ ] ASC [x] DESC" + +#: src/labels.h:58 +#, c-format +msgid "[Active Panel: %1$s]" +msgstr "[Pannello Attivo: %1$s]" + +#: src/labels.h:59 +msgid "[q]uit GoAccess" +msgstr "[q] chiudi GoAccess" + +#: src/labels.h:60 +msgid "[?] Help [Enter] Exp. Panel" +msgstr "[?] Aiuto [Enter] Exp. Panel" + +#: src/labels.h:61 +msgid "Dashboard" +msgstr "Pannello di Controllo" + +#: src/labels.h:62 +msgid "Dashboard - Overall Analyzed Requests" +msgstr "Pannello di Controllo - Richieste Complessive Analizzate" + +#: src/labels.h:63 +msgid "Overall Analyzed Requests" +msgstr "Richieste Complessive Analizzate" + +#: src/labels.h:65 src/labels.h:86 +msgid "Tx. Amount" +msgstr "Tx. Totale" + +#: src/labels.h:66 +msgid "Date/Time" +msgstr "Data/Ora" + +#: src/labels.h:67 +msgid "Excl. IP Hits" +msgstr "Accessi IP Esclusi" + +#: src/labels.h:68 +msgid "Failed Requests" +msgstr "Richieste Fallite" + +#: src/labels.h:69 +msgid "Log Parsing Time" +msgstr "Tempo Parsing Log" + +#: src/labels.h:70 +msgid "Log Size" +msgstr "Dimensioni Log" + +#: src/labels.h:71 +msgid "Log Source" +msgstr "Sorgente Log" + +#: src/labels.h:72 src/labels.h:187 +msgid "Referrers" +msgstr "Referrer" + +#: src/labels.h:73 +msgid "Total Requests" +msgstr "Richieste Totali" + +#: src/labels.h:74 +msgid "Static Files" +msgstr "File Statici" + +#: src/labels.h:75 src/labels.h:159 +msgid "Not Found" +msgstr "Non Trovato" + +#: src/labels.h:76 +msgid "Requested Files" +msgstr "File Richiesti" + +#: src/labels.h:77 +msgid "Unique Visitors" +msgstr "Visitatori Unici" + +#: src/labels.h:78 +msgid "Valid Requests" +msgstr "Richieste Valide" + +#: src/labels.h:81 +msgid "Hits" +msgstr "Accessi" + +#: src/labels.h:82 +msgid "h%" +msgstr "h%" + +#: src/labels.h:83 src/labels.h:110 +msgid "Visitors" +msgstr "Visitatori" + +#: src/labels.h:84 +msgid "Vis." +msgstr "Vis." + +#: src/labels.h:85 +msgid "v%" +msgstr "v%" + +#: src/labels.h:87 +msgid "Avg. T.S." +msgstr "Media T.S." + +#: src/labels.h:88 +msgid "Cum. T.S." +msgstr "Cum. T.S." + +#: src/labels.h:89 +msgid "Max. T.S." +msgstr "Max. T.S." + +#: src/labels.h:90 +msgid "Method" +msgstr "Metodo" + +#: src/labels.h:91 +msgid "Mtd" +msgstr "Mtd" + +#: src/labels.h:92 +msgid "Protocol" +msgstr "Protocollo" + +#: src/labels.h:93 +msgid "Proto" +msgstr "Proto" + +#: src/labels.h:94 +msgid "City" +msgstr "Città" + +#: src/labels.h:95 src/labels.h:211 src/labels.h:215 +msgid "ASN" +msgstr "" + +#: src/labels.h:96 +msgid "Country" +msgstr "Paese" + +#: src/labels.h:97 +msgid "Hostname" +msgstr "Hostname" + +#: src/labels.h:98 +msgid "Data" +msgstr "Dati" + +#: src/labels.h:100 +msgid "Hits/Visitors" +msgstr "Acessi/Visitatori" + +#: src/labels.h:104 +msgid "Unique visitors per day" +msgstr "Visitatori unici al giorno" + +#: src/labels.h:106 +msgid "Unique visitors per day - Including spiders" +msgstr "Visitatori unici al giorno - Inclusi spider" + +#: src/labels.h:108 +msgid "Hits having the same IP, date and agent are a unique visit." +msgstr "Accessi con lo stesso IP, data e agent sono una visita unica." + +#: src/labels.h:113 +msgid "Requested Files (URLs)" +msgstr "File Richiesti (URL)" + +#: src/labels.h:115 +msgid "Top requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Principali richieste ordinate per accessi [, avgts, cumts, maxts, mthd, " +"proto]" + +#: src/labels.h:117 +msgid "Requests" +msgstr "Richieste" + +#: src/labels.h:120 src/labels.h:124 +msgid "Static Requests" +msgstr "Richieste Statiche" + +#: src/labels.h:122 +msgid "Top static requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Principali richieste statiche ordinate per accessi [, avgts, cumts, maxts, " +"mthd, proto]" + +#: src/labels.h:127 +msgid "Time Distribution" +msgstr "Distribuzione Oraria" + +#: src/labels.h:129 +msgid "Data sorted by hour [, avgts, cumts, maxts]" +msgstr "Dati ordinati per ore [, avgts, cumts, maxts]" + +#: src/labels.h:131 +msgid "Time" +msgstr "Ora" + +#: src/labels.h:134 src/labels.h:138 +msgid "Virtual Hosts" +msgstr "Host Virtuali" + +#: src/labels.h:136 src/labels.h:143 src/labels.h:150 +msgid "Data sorted by hits [, avgts, cumts, maxts]" +msgstr "Dati ordinati per accessi [, avgts, cumts, maxts]" + +#: src/labels.h:141 +msgid "Remote User (HTTP authentication)" +msgstr "Utente Remoto (Autenticazione HTTP)" + +#: src/labels.h:145 +msgid "Remote User" +msgstr "Utente Remoto" + +#: src/labels.h:148 +msgid "The cache status of the object served" +msgstr "Lo stato della cache dell'oggetto servito" + +#: src/labels.h:152 +msgid "Cache Status" +msgstr "Stato Della Cache" + +#: src/labels.h:155 +msgid "Not Found URLs (404s)" +msgstr "URL Non Trovati (404)" + +#: src/labels.h:157 +msgid "Top not found URLs sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Principali URL non trovati ordinati per accesso [, avgts, cumts, maxts, " +"mthd, proto]" + +#: src/labels.h:162 +msgid "Visitor Hostnames and IPs" +msgstr "Hostname e IP dei Visitatori" + +#: src/labels.h:164 +msgid "Top visitor hosts sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Principali host dei visitatori ordinati per accessi [, avgts, cumts, maxts]" + +#: src/labels.h:166 +msgid "Hosts" +msgstr "Host" + +#: src/labels.h:169 +msgid "Operating Systems" +msgstr "Sistemi Operativi" + +#: src/labels.h:171 +msgid "Top Operating Systems sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Principali Sistemi Operativi ordinati per accessi [, avgts, cumts, maxts]" + +#: src/labels.h:173 +msgid "OS" +msgstr "SO" + +#: src/labels.h:176 src/labels.h:180 +msgid "Browsers" +msgstr "Browser" + +#: src/labels.h:178 +msgid "Top Browsers sorted by hits [, avgts, cumts, maxts]" +msgstr "Principali Browser ordinati per accessi [, avgts, cumts, maxts]" + +#: src/labels.h:183 +#, fuzzy +msgid "Referrer URLs" +msgstr "URL Referrer" + +#: src/labels.h:185 +#, fuzzy +msgid "Top Requested Referrers sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Principali Referrer Richiesti ordinati per accessi [, avgts, cumts, maxts]" + +#: src/labels.h:190 src/labels.h:194 +msgid "Referring Sites" +msgstr "Siti Referrer" + +#: src/labels.h:192 +msgid "Top Referring Sites sorted by hits [, avgts, cumts, maxts]" +msgstr "Principali Siti Referrer ordinati per accessi [, avgts, cumts, maxts]" + +#: src/labels.h:197 +msgid "Keyphrases from Google's search engine" +msgstr "Frasi chiave dal motore di ricerca di Google" + +#: src/labels.h:199 +msgid "Top Keyphrases sorted by hits [, avgts, cumts, maxts]" +msgstr "Principali Frasi Chiave ordinate per accessi [, avgts, cumts, maxts]" + +#: src/labels.h:201 +msgid "Keyphrases" +msgstr "Frasi Chiave" + +#: src/labels.h:204 src/labels.h:208 +msgid "Geo Location" +msgstr "Posizione Geografica" + +#: src/labels.h:206 +msgid "Continent > Country sorted by unique hits [, avgts, cumts, maxts]" +msgstr "Continente > Paese ordinati per accessi unici [, avgts, cumts, maxts]" + +#: src/labels.h:213 +msgid "Autonomous System Numbers/Organizations (ASNs)" +msgstr "" + +#: src/labels.h:218 +msgid "HTTP Status Codes" +msgstr "Codici Di Stato HTTP" + +#: src/labels.h:220 +msgid "Top HTTP Status Codes sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Principali Codici Di Stato HTTP ordinati per accessi [, avgts, cumts, maxts]" + +#: src/labels.h:222 +msgid "Status Codes" +msgstr "Codici Di Stato" + +#: src/labels.h:225 src/labels.h:229 +msgid "MIME Types" +msgstr "Tipi MIME" + +#: src/labels.h:227 +msgid "File types shipped out" +msgstr "Tipi di file spediti" + +#: src/labels.h:232 +msgid "Encryption settings" +msgstr "Impostazioni di crittografia" + +#: src/labels.h:234 +msgid "TLS version and picked algorithm" +msgstr "Versione TLS e algoritmo scelto" + +#: src/labels.h:236 +msgid "TLS Settings" +msgstr "Impostazioni TLS" + +#: src/labels.h:240 +msgid "[ ] case sensitive" +msgstr "[ ] case sensitive" + +#: src/labels.h:242 +msgid "[x] case sensitive" +msgstr "[x] case sensitive" + +#: src/labels.h:244 +msgid "Regex allowed - ^g to cancel - TAB switch case" +msgstr "Regex permesse - ^g per annullare - TAB cambia case" + +#: src/labels.h:246 +msgid "Find pattern in all views" +msgstr "Trova pattern in tutte le viste" + +#: src/labels.h:250 +msgid "Log Format Configuration" +msgstr "Configurazione Formato Log" + +#: src/labels.h:252 +msgid "[SPACE] to toggle - [ENTER] to proceed - [q] to quit" +msgstr "[SPAZIO] per alternare - [INVIO] per procedere - [q] per uscire" + +#: src/labels.h:254 +msgid "Log Format - [c] to add/edit format" +msgstr "Formato Log - [c] per aggiungere/modificare formato" + +#: src/labels.h:256 +msgid "Date Format - [d] to add/edit format" +msgstr "Formato Data - [d] per aggiungere/modificare formato" + +#: src/labels.h:258 +msgid "Time Format - [t] to add/edit format" +msgstr "Formato Ora - [t] per aggiungere/modificare formato" + +#: src/labels.h:260 src/labels.h:264 +msgid "[UP/DOWN] to scroll - [q] to close window" +msgstr "[SU/GIU] per scorrere - [q] per chiudere la finestra" + +#: src/labels.h:266 +#, c-format +msgid "User Agents for %1$s" +msgstr "User Agent per %1$s" + +#: src/labels.h:270 +msgid "Scheme Configuration" +msgstr "Configurazione Schema" + +#: src/labels.h:272 +msgid "[ENTER] to use scheme - [q]uit" +msgstr "[INVIO] per usare lo schema - [q] esci" + +#: src/labels.h:276 +msgid "Sort active module by" +msgstr "Ordina moduli attivi per" + +#: src/labels.h:278 +msgid "[ENTER] select - [TAB] sort - [q]uit" +msgstr "[INVIO] seleziona - [TAB] ordina - [q] esci" + +#: src/labels.h:282 +msgid "GoAccess Quick Help" +msgstr "Aiuto Rapido di GoAccess" + +#: src/labels.h:284 +msgid "[UP/DOWN] to scroll - [q] to quit" +msgstr "[SU/GIU] per scorrere - [q] per uscire" + +#: src/labels.h:288 +msgid "In-Memory with On-Disk Persistent Storage." +msgstr "In Memoria con Archiviazione Persistente Su Disco." + +#: src/labels.h:292 +msgid "Format Errors - Verify your log/date/time format" +msgstr "Errori Formato - Verifica il tuo formato di log/data/ora" + +#: src/labels.h:294 +msgid "No date format was found on your conf file." +msgstr "Nessun formato di data trovato nel tuo file di configurazione." + +#: src/labels.h:296 +msgid "No log format was found on your conf file." +msgstr "Nessun formato di log trovato nel tuo file di configurazione." + +#: src/labels.h:298 +msgid "No time format was found on your conf file." +msgstr "Nessun formato di ora trovato nel tuo file di configurazione." + +#: src/labels.h:300 +msgid "No default config file found." +msgstr "Nessuna file di configurazione predefinito trovato." + +#: src/labels.h:302 +msgid "You may specify one with" +msgstr "Puoi specificarne uno con" + +#: src/labels.h:304 +msgid "producing the following errors" +msgstr "producendo i seguenti errori" + +#: src/labels.h:306 +#, c-format +msgid "Parsed %1$d lines" +msgstr "Analizzate %1$d righe" + +#: src/labels.h:308 +msgid "Please report it by opening an issue on GitHub" +msgstr "Per favore segnalalo aprendo un issue su GitHub" + +#: src/labels.h:310 +msgid "Select a time format." +msgstr "Seleziona un formato di ora." + +#: src/labels.h:312 +msgid "Select a date format." +msgstr "Seleziona un formato di data." + +#: src/labels.h:314 +msgid "Select a log format." +msgstr "Seleziona un formato di log." + +#: src/labels.h:316 +#, c-format +msgid "'%1$s' panel is disabled" +msgstr "il pannello '%1$s' è disattivato" + +#: src/labels.h:318 +msgid "No input data was provided nor there's data to restore." +msgstr "Non sono stati forniti dati in input né ci sono dati da ripristinare." + +#: src/labels.h:320 +msgid "Unable to allocate memory for a log instance." +msgstr "" + +#: src/labels.h:322 +msgid "Unable to find the given log." +msgstr "" + +#: src/labels.h:326 +msgid "For more details visit" +msgstr "Per maggiori dettagli visita" + +#: src/labels.h:328 +msgid "Last Updated" +msgstr "Ultimo Aggiornamento" + +#: src/labels.h:330 +msgid "WebSocket server ready to accept new client connections" +msgstr "Server WebSocket pronto ad accettare nuove connessioni dai client" + +#: src/labels.h:333 +msgid "The following options can also be supplied to the command" +msgstr "Le seguenti opzioni possono anche essere fornite al comando" + +#: src/labels.h:335 +msgid "Examples can be found by running" +msgstr "Esempi possono trovati eseguendo" + +#: src/labels.h:338 +msgid "Server Statistics" +msgstr "Statistiche Server" + +#: src/labels.h:340 +msgid "Theme" +msgstr "Tema" + +#: src/labels.h:342 +msgid "Dark Gray" +msgstr "Grigio Scuro" + +#: src/labels.h:344 +msgid "Bright" +msgstr "Chiaro" + +#: src/labels.h:346 +msgid "Dark Blue" +msgstr "Blu Scuro" + +#: src/labels.h:348 +msgid "Dark Purple" +msgstr "Viola Scuro" + +#: src/labels.h:350 +msgid "Panels" +msgstr "Pannelli" + +#: src/labels.h:352 +msgid "Items per Page" +msgstr "Elementi per Pagina" + +#: src/labels.h:354 +msgid "Tables" +msgstr "Tabelle" + +#: src/labels.h:356 +msgid "Display Tables" +msgstr "Mostra Tabelle" + +#: src/labels.h:358 +msgid "Auto-Hide on Small Devices" +msgstr "Nascondi su Schermi Piccoli" + +#: src/labels.h:360 +msgid "Automatically hide tables on small screen devices" +msgstr "Nascondi automaticamente le tabelle su Schermi Piccoli" + +#: src/labels.h:362 +msgid "Toggle Panel" +msgstr "" + +#: src/labels.h:364 +msgid "Layout" +msgstr "Layout" + +#: src/labels.h:366 +msgid "Horizontal" +msgstr "Orizzontale" + +#: src/labels.h:368 +msgid "Vertical" +msgstr "Verticale" + +#: src/labels.h:370 +msgid "WideScreen" +msgstr "Panoramico" + +#: src/labels.h:372 +msgid "File Options" +msgstr "Opzioni File" + +#: src/labels.h:374 +msgid "Export as JSON" +msgstr "Esporta come JSON" + +#: src/labels.h:376 +msgid "Panel Options" +msgstr "Opzioni Pannello" + +#: src/labels.h:378 +msgid "Previous" +msgstr "Precedente" + +#: src/labels.h:380 +msgid "Next" +msgstr "Successivo" + +#: src/labels.h:382 +msgid "First" +msgstr "Primo" + +#: src/labels.h:384 +msgid "Last" +msgstr "Ultimo" + +#: src/labels.h:386 +msgid "Chart Options" +msgstr "Opzioni Grafico" + +#: src/labels.h:388 +msgid "Chart" +msgstr "Grafico" + +#: src/labels.h:390 +msgid "Type" +msgstr "Tipo" + +#: src/labels.h:392 +msgid "Area Spline" +msgstr "Area Spline" + +#: src/labels.h:394 +msgid "Bar" +msgstr "Barre" + +#: src/labels.h:396 +msgid "World Map" +msgstr "" + +#: src/labels.h:398 +msgid "Plot Metric" +msgstr "Metriche Grafico" + +#: src/labels.h:400 +msgid "Table Columns" +msgstr "Colonne Tabella" + +#: src/labels.h:404 +msgid "0xx Unofficial Codes" +msgstr "" + +#: src/labels.h:406 +msgid "1xx Informational" +msgstr "1xx Informativo" + +#: src/labels.h:408 +msgid "2xx Success" +msgstr "2xx Successo" + +#: src/labels.h:410 +msgid "3xx Redirection" +msgstr "3xx Reindirizzamento" + +#: src/labels.h:412 +msgid "4xx Client Errors" +msgstr "4xx Errori Client" + +#: src/labels.h:414 +msgid "5xx Server Errors" +msgstr "5xx Errori Server" + +#: src/labels.h:417 +msgid "0 - Caddy: Unhandled - No configured routes" +msgstr "" + +#: src/labels.h:419 +msgid "100 - Continue: Server received the initial part of the request" +msgstr "" +"100 - Continue: Il server ha ricevuto la parte iniziale della richiesta" + +#: src/labels.h:421 +msgid "101 - Switching Protocols: Client asked to switch protocols" +msgstr "" +"101 - Switching Protocols: Il client ha richiesto di cambiare protocolli" + +#: src/labels.h:423 +msgid "200 - OK: The request sent by the client was successful" +msgstr "200 - OK: La richiesta inviata dal client ha avuto successo" + +#: src/labels.h:425 +msgid "201 - Created: The request has been fulfilled and created" +msgstr "201 - Created: La richiesta è stata soddisfatta e creata" + +#: src/labels.h:427 +msgid "202 - Accepted: The request has been accepted for processing" +msgstr "202 - Accepted: La richiesta è stata accettata per essere elaborata" + +#: src/labels.h:429 +msgid "203 - Non-authoritative Information: Response from a third party" +msgstr "203 - Non-authoritative Information: Risposta da terzi" + +#: src/labels.h:431 +msgid "204 - No Content: Request did not return any content" +msgstr "204 - No Content: La richiesta non ha restituito nessun contenuto" + +#: src/labels.h:433 +msgid "205 - Reset Content: Server asked the client to reset the document" +msgstr "" +"205 - Reset Content: Il server ha richiesto al client di ripristinare il " +"documento" + +#: src/labels.h:435 +msgid "206 - Partial Content: The partial GET has been successful" +msgstr "206 - Partial Content: La GET parziale ha avuto successo" + +#: src/labels.h:437 +msgid "207 - Multi-Status: WebDAV; RFC 4918" +msgstr "207 - Multi-Status: WebDAV; RFC 4918" + +#: src/labels.h:439 +msgid "208 - Already Reported: WebDAV; RFC 5842" +msgstr "208 - Already Reported: WebDAV; RFC 5842" + +#: src/labels.h:441 +msgid "218 - This is fine: Apache servers. A catch-all error condition" +msgstr "" + +#: src/labels.h:443 +msgid "300 - Multiple Choices: Multiple options for the resource" +msgstr "300 - Multiple Choices: Opzioni multiple per la risorsa" + +#: src/labels.h:445 +msgid "301 - Moved Permanently: Resource has permanently moved" +msgstr "301 - Moved Permanently: La risorsa è stata spostata permanentemente" + +#: src/labels.h:447 +msgid "302 - Moved Temporarily (redirect)" +msgstr "302 - Moved Temporarily (redirect)" + +#: src/labels.h:449 +msgid "303 - See Other Document: The response is at a different URI" +msgstr "303 - See Other Document: La risposta si trova ad un URI diverso" + +#: src/labels.h:451 +msgid "304 - Not Modified: Resource has not been modified" +msgstr "304 - Not Modified: La risorsa non è stata modificata" + +#: src/labels.h:453 +msgid "305 - Use Proxy: Can only be accessed through the proxy" +msgstr "305 - Use Proxy: Può essere acceduta solo tramite proxy" + +#: src/labels.h:455 +msgid "307 - Temporary Redirect: Resource temporarily moved" +msgstr "307 - Temporary Redirect: Risorsa spostata temporaneamente" + +#: src/labels.h:457 +msgid "308 - Permanent Redirect" +msgstr "308 - Permanent Redirect" + +#: src/labels.h:459 +msgid "400 - Bad Request: The syntax of the request is invalid" +msgstr "400 - Bad Request: La sintassi della richiesta non è valida" + +#: src/labels.h:461 +msgid "401 - Unauthorized: Request needs user authentication" +msgstr "401 - Unauthorized: La richiesta richiede l'autenticazione dell'utente" + +#: src/labels.h:463 +msgid "402 - Payment Required" +msgstr "402 - Payment Required" + +#: src/labels.h:465 +msgid "403 - Forbidden: Server is refusing to respond to it" +msgstr "403 - Forbidden: Il server si sta rifiutando di rispondere" + +#: src/labels.h:467 +msgid "404 - Not Found: Requested resource could not be found" +msgstr "404 - Not Found: La risorsa richiesta non è stata trovata" + +#: src/labels.h:469 +msgid "405 - Method Not Allowed: Request method not supported" +msgstr "405 - Method Not Allowed: Il metodo della richiesta non è supportato" + +#: src/labels.h:471 +msgid "406 - Not Acceptable" +msgstr "406 - Not Acceptable" + +#: src/labels.h:473 +msgid "407 - Proxy Authentication Required" +msgstr "407 - Proxy Authentication Required" + +#: src/labels.h:475 +msgid "408 - Request Timeout: Server timed out waiting for the request" +msgstr "408 - Request Timeout: Il tempo per inviare la richiesta è scaduto" + +#: src/labels.h:477 +msgid "409 - Conflict: Conflict in the request" +msgstr "409 - Conflict: Conflitto nella richiesta" + +#: src/labels.h:479 +msgid "410 - Gone: Resource requested is no longer available" +msgstr "410 - Gone: La risorsa richiesta non è più disponibile" + +#: src/labels.h:481 +msgid "411 - Length Required: Invalid Content-Length" +msgstr "411 - Length Required: Content-Length non valido" + +#: src/labels.h:483 +msgid "412 - Precondition Failed: Server does not meet preconditions" +msgstr "412 - Precondition Failed: Il server non soddisfa le precondizioni" + +#: src/labels.h:485 +msgid "413 - Payload Too Large" +msgstr "413 - Payload Too Large" + +#: src/labels.h:487 +msgid "414 - Request-URI Too Long" +msgstr "414 - Request-URI Too Long" + +#: src/labels.h:489 +msgid "415 - Unsupported Media Type: Media type is not supported" +msgstr "415 - Unsupported Media Type: Tipo media non supportato" + +#: src/labels.h:491 +msgid "416 - Requested Range Not Satisfiable: Cannot supply that portion" +msgstr "" +"416 - Requested Range Not Satisfiable: Impossibile fornire quel frammento" + +#: src/labels.h:493 +msgid "417 - Expectation Failed" +msgstr "417 - Expectation Failed" + +#: src/labels.h:495 +#, fuzzy +msgid "418 - I'm a teapot" +msgstr "418 - I’m a teapot" + +#: src/labels.h:497 +msgid "419 - Page Expired: Laravel Framework when a CSRF Token is missing" +msgstr "" + +#: src/labels.h:499 +msgid "420 - Method Failure: Spring Framework when a method has failed" +msgstr "" + +#: src/labels.h:501 +msgid "421 - Misdirected Request" +msgstr "421 - Misdirected Request" + +#: src/labels.h:503 +msgid "422 - Unprocessable Entity due to semantic errors: WebDAV" +msgstr "422 - Unprocessable Entity" + +#: src/labels.h:505 +msgid "423 - The resource that is being accessed is locked" +msgstr "423 - Locked" + +#: src/labels.h:507 +msgid "424 - Failed Dependency: WebDAV" +msgstr "424 - Failed Dependency: WebDAV" + +#: src/labels.h:509 +msgid "426 - Upgrade Required: Client should switch to a different protocol" +msgstr "" +"426 - Upgrade Required: Il cliente dovrebbe utilizzare un protocollo diverso" + +#: src/labels.h:511 +msgid "428 - Precondition Required" +msgstr "402 - Precondition Required" + +#: src/labels.h:513 +msgid "429 - Too Many Requests: The user has sent too many requests" +msgstr "429 - Too Many Requests: L'utente ha inviato troppe richieste" + +#: src/labels.h:515 +msgid "" +"430 - Request Header Fields Too Large: Too many URLs are requested within a " +"certain time frame" +msgstr "" + +#: src/labels.h:517 +msgid "431 - Request Header Fields Too Large" +msgstr "431 - Request Header Fields Too Large" + +#: src/labels.h:519 +msgid "440 - Login Time-out: The client's session has expired" +msgstr "" + +#: src/labels.h:521 +#, fuzzy +msgid "449 - Retry With: The server cannot honour the request" +msgstr "408 - Request Timeout: Il tempo per inviare la richiesta è scaduto" + +#: src/labels.h:523 +msgid "" +"450 - Blocked by Windows Parental Controls: The Microsoft extension code " +"indicated" +msgstr "" + +#: src/labels.h:525 +msgid "451 - Unavailable For Legal Reasons" +msgstr "451 - Unavailable For Legal Reasons" + +#: src/labels.h:527 +msgid "444 - (Nginx) Connection closed without sending any headers" +msgstr "444 - (Nginx) Connection closed without sending any headers" + +#: src/labels.h:529 +msgid "460 - AWS Elastic Load Balancing: Client closed the connection " +msgstr "" + +#: src/labels.h:531 +msgid "" +"463 - AWS Elastic Load Balancing: The load balancer received more than 30 IP " +"addresses" +msgstr "" + +#: src/labels.h:533 +msgid "464 - AWS Elastic Load Balancing: Incompatible protocol versions" +msgstr "" + +#: src/labels.h:535 +msgid "494 - (Nginx) Request Header Too Large" +msgstr "494 - (Nginx) Request Header Too Large" + +#: src/labels.h:537 +msgid "495 - (Nginx) SSL client certificate error" +msgstr "495 - (Nginx) SSL client certificate error" + +#: src/labels.h:539 +msgid "496 - (Nginx) Client didn't provide certificate" +msgstr "496 - (Nginx) Client didn't provide certificate" + +#: src/labels.h:541 +msgid "497 - (Nginx) HTTP request sent to HTTPS port" +msgstr "497 - (Nginx) HTTP request sent to HTTPS port" + +#: src/labels.h:543 +msgid "498 - Invalid Token: an expired or otherwise invalid token" +msgstr "" + +#: src/labels.h:545 +msgid "499 - (Nginx) Connection closed by client while processing request" +msgstr "499 - (Nginx) Connection closed by client while processing request" + +#: src/labels.h:547 +msgid "500 - Internal Server Error" +msgstr "500 - Internal Server Error" + +#: src/labels.h:549 +msgid "501 - Not Implemented" +msgstr "501 - Not Implemented" + +#: src/labels.h:551 +msgid "502 - Bad Gateway: Received an invalid response from the upstream" +msgstr "502 - Bad Gateway: Risposta non valida dal server di upstream" + +#: src/labels.h:553 +msgid "503 - Service Unavailable: The server is currently unavailable" +msgstr "503 - Service Unavailable: Il server non è attualmente disponibile" + +#: src/labels.h:555 +msgid "504 - Gateway Timeout: The upstream server failed to send request" +msgstr "" +"504 - Gateway Timeout: Il server di upstream non è riuscito ad inviare la " +"richiesta" + +#: src/labels.h:557 +msgid "505 - HTTP Version Not Supported" +msgstr "505 - HTTP Version Not Supported" + +#: src/labels.h:559 +msgid "509 - Bandwidth Limit Exceeded: The server has exceeded the bandwidth" +msgstr "" + +#: src/labels.h:561 +msgid "520 - CloudFlare - Web server is returning an unknown error" +msgstr "520 - CloudFlare - Web server is returning an unknown error" + +#: src/labels.h:563 +msgid "521 - CloudFlare - Web server is down" +msgstr "521 - CloudFlare - Web server is down" + +#: src/labels.h:565 +msgid "522 - CloudFlare - Connection timed out" +msgstr "522 - CloudFlare - Connection timed out" + +#: src/labels.h:567 +msgid "523 - CloudFlare - Origin is unreachable" +msgstr "523 - CloudFlare - Origin is unreachable" + +#: src/labels.h:569 +msgid "524 - CloudFlare - A timeout occurred" +msgstr "524 - CloudFlare - A timeout occurred" + +#: src/labels.h:571 +msgid "" +"525 - SSL Handshake Failed: Cloudflare could not negotiate a SSL/TLS " +"handshake" +msgstr "" + +#: src/labels.h:573 +msgid "" +"526 - Invalid SSL Certificate: Cloudflare could not validate the SSL " +"certificate" +msgstr "" + +#: src/labels.h:575 +msgid "527 - Railgun Error: An interrupted connection" +msgstr "" + +#: src/labels.h:577 +msgid "529 - Site is overloaded: A site can not process the request" +msgstr "" + +#: src/labels.h:579 +msgid "530 - Site is frozen: A site has been frozen due to inactivity" +msgstr "" + +#: src/labels.h:581 +msgid "" +"540 - Temporarily Disabled: The requested endpoint has been temporarily " +"disabled" +msgstr "" + +#: src/labels.h:583 +#, fuzzy +msgid "561 - Unauthorized: An error around authentication" +msgstr "401 - Unauthorized: La richiesta richiede l'autenticazione dell'utente" + +#: src/labels.h:585 +msgid "" +"598 - Network read timeout error: some HTTP proxies to signal a network read " +"timeout" +msgstr "" + +#: src/labels.h:587 +msgid "599 - Network Connect Timeout Error: An error used by some HTTP proxies" +msgstr "" + +#: src/labels.h:589 +msgid "783 - Unexpected Token: The request includes a JSON syntax error" +msgstr "" + +#, fuzzy +#~ msgid "Referers" +#~ msgstr "Referrer" diff --git a/po/ja.po b/po/ja.po new file mode 100644 index 0000000000..e1239f7f3f --- /dev/null +++ b/po/ja.po @@ -0,0 +1,1082 @@ +# Copyright © 2020 Kamino <67395018+err931@users.noreply.github.com> +# Copyright © 2023 gemmaro +msgid "" +msgstr "" +"Project-Id-Version: goaccess 1.3\n" +"Report-Msgid-Bugs-To: hello@goaccess.io\n" +"POT-Creation-Date: 2024-04-11 20:17-0500\n" +"PO-Revision-Date: 2023-07-15 17:20+0900\n" +"Last-Translator: gemmaro \n" +"Language-Team: Japanese\n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#: src/labels.h:45 +msgid "en" +msgstr "ja" + +#: src/labels.h:48 +msgid "Exp. Panel" +msgstr "詳細表示" + +#: src/labels.h:49 +msgid "Help" +msgstr "ヘルプ" + +#: src/labels.h:50 +msgid "Quit" +msgstr "終了" + +#: src/labels.h:51 +msgid "Total" +msgstr "合計" + +#: src/labels.h:54 +msgid "[x] ASC [ ] DESC" +msgstr "[x] 昇順 [ ] 降順" + +#: src/labels.h:55 +msgid "[ ] ASC [x] DESC" +msgstr "[ ] 昇順 [x] 降順" + +#: src/labels.h:58 +#, c-format +msgid "[Active Panel: %1$s]" +msgstr "[表示中のパネル: %1$s]" + +#: src/labels.h:59 +msgid "[q]uit GoAccess" +msgstr "[q] GoAccessを閉じる" + +#: src/labels.h:60 +msgid "[?] Help [Enter] Exp. Panel" +msgstr "[?] ヘルプ [Enter] 詳細表示" + +#: src/labels.h:61 +msgid "Dashboard" +msgstr "ダッシュボード" + +#: src/labels.h:62 +msgid "Dashboard - Overall Analyzed Requests" +msgstr "ダッシュボード - 解析済みリクエスト全体" + +#: src/labels.h:63 +msgid "Overall Analyzed Requests" +msgstr "解析済みリクエスト全体" + +#: src/labels.h:65 src/labels.h:86 +msgid "Tx. Amount" +msgstr "データ転送量" + +#: src/labels.h:66 +msgid "Date/Time" +msgstr "日付/時刻" + +#: src/labels.h:67 +msgid "Excl. IP Hits" +msgstr "除外対象数" + +#: src/labels.h:68 +msgid "Failed Requests" +msgstr "無効リクエスト数" + +#: src/labels.h:69 +msgid "Log Parsing Time" +msgstr "ログの解析時間" + +#: src/labels.h:70 +msgid "Log Size" +msgstr "ログファイルサイズ" + +#: src/labels.h:71 +msgid "Log Source" +msgstr "ログ取得元" + +#: src/labels.h:72 src/labels.h:187 +msgid "Referrers" +msgstr "リファラ数" + +#: src/labels.h:73 +msgid "Total Requests" +msgstr "合計リクエスト数" + +#: src/labels.h:74 +msgid "Static Files" +msgstr "静的ファイル数" + +#: src/labels.h:75 src/labels.h:159 +msgid "Not Found" +msgstr "404エラー数" + +#: src/labels.h:76 +msgid "Requested Files" +msgstr "要求されたファイル数" + +#: src/labels.h:77 +msgid "Unique Visitors" +msgstr "ユニークユーザー数" + +#: src/labels.h:78 +msgid "Valid Requests" +msgstr "有効リクエスト数" + +#: src/labels.h:81 +msgid "Hits" +msgstr "ヒット数" + +#: src/labels.h:82 +msgid "h%" +msgstr "ヒット率(%)" + +#: src/labels.h:83 src/labels.h:110 +msgid "Visitors" +msgstr "ユーザー数" + +#: src/labels.h:84 +msgid "Vis." +msgstr "ユーザー数" + +#: src/labels.h:85 +msgid "v%" +msgstr "訪問率(%)" + +#: src/labels.h:87 +msgid "Avg. T.S." +msgstr "平均処理時間" + +#: src/labels.h:88 +msgid "Cum. T.S." +msgstr "合計処理時間" + +#: src/labels.h:89 +msgid "Max. T.S." +msgstr "最大処理時間" + +#: src/labels.h:90 +msgid "Method" +msgstr "要求" + +#: src/labels.h:91 +msgid "Mtd" +msgstr "要求" + +#: src/labels.h:92 +msgid "Protocol" +msgstr "プロトコル" + +#: src/labels.h:93 +msgid "Proto" +msgstr "プロトコル" + +#: src/labels.h:94 +msgid "City" +msgstr "地域" + +#: src/labels.h:95 src/labels.h:211 src/labels.h:215 +msgid "ASN" +msgstr "ASN" + +#: src/labels.h:96 +msgid "Country" +msgstr "国名" + +#: src/labels.h:97 +msgid "Hostname" +msgstr "ホスト名" + +#: src/labels.h:98 +msgid "Data" +msgstr "データ" + +#: src/labels.h:100 +msgid "Hits/Visitors" +msgstr "ヒット数/ユーザー数" + +#: src/labels.h:104 +msgid "Unique visitors per day" +msgstr "一日あたりのユニークユーザー数" + +#: src/labels.h:106 +msgid "Unique visitors per day - Including spiders" +msgstr "一日あたりのユニークユーザー数(クローラも含める)" + +#: src/labels.h:108 +msgid "Hits having the same IP, date and agent are a unique visit." +msgstr "" +"IPアドレス、日付、ユーザーエージェントが全て同一だった場合、ユニークユーザー" +"として扱われます。" + +#: src/labels.h:113 +msgid "Requested Files (URLs)" +msgstr "リクエストされたファイル(URL)" + +#: src/labels.h:115 +msgid "Top requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"上位のリクエスト [ヒット数、平均処理時間、合計処理時間、最大処理時間、メソッ" +"ド、プロトコル]" + +#: src/labels.h:117 +msgid "Requests" +msgstr "リクエスト数" + +#: src/labels.h:120 src/labels.h:124 +msgid "Static Requests" +msgstr "静的ファイルリクエスト数" + +#: src/labels.h:122 +msgid "Top static requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"上位の静的ファイルリクエスト [ヒット数、平均処理時間、合計処理時間、最大処理" +"時間、メソッド、プロトコル]" + +#: src/labels.h:127 +msgid "Time Distribution" +msgstr "時間分布" + +#: src/labels.h:129 +msgid "Data sorted by hour [, avgts, cumts, maxts]" +msgstr "上位のデータ [時刻、平均処理時間、合計処理時間、最大処理時間]" + +#: src/labels.h:131 +msgid "Time" +msgstr "時刻" + +#: src/labels.h:134 src/labels.h:138 +msgid "Virtual Hosts" +msgstr "バーチャルホスト" + +#: src/labels.h:136 src/labels.h:143 src/labels.h:150 +msgid "Data sorted by hits [, avgts, cumts, maxts]" +msgstr "上位のデータ [ヒット数、平均処理時間、合計処理時間、最大処理時間]" + +#: src/labels.h:141 +msgid "Remote User (HTTP authentication)" +msgstr "認証されたユーザー(HTTP認証)" + +#: src/labels.h:145 +msgid "Remote User" +msgstr "認証されたユーザー" + +#: src/labels.h:148 +msgid "The cache status of the object served" +msgstr "サーブされるオブジェクトのキャッシュ状態" + +#: src/labels.h:152 +msgid "Cache Status" +msgstr "キャッシュの状態" + +#: src/labels.h:155 +msgid "Not Found URLs (404s)" +msgstr "404エラーが返されたURL" + +#: src/labels.h:157 +msgid "Top not found URLs sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"上位のnot foundなURL [ヒット数、平均処理時間、合計処理時間、最大処理時間、メ" +"ソッド、プロトコル]" + +#: src/labels.h:162 +msgid "Visitor Hostnames and IPs" +msgstr "ユーザーのホスト名とIPアドレス" + +#: src/labels.h:164 +msgid "Top visitor hosts sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"上位のユーザーホスト [ヒット数、平均処理時間、合計処理時間、最大処理時間]" + +#: src/labels.h:166 +msgid "Hosts" +msgstr "ホスト名" + +#: src/labels.h:169 +msgid "Operating Systems" +msgstr "オペレーティングシステム" + +#: src/labels.h:171 +msgid "Top Operating Systems sorted by hits [, avgts, cumts, maxts]" +msgstr "上位のOS [ヒット数、平均処理時間、合計処理時間、最大処理時間]" + +#: src/labels.h:173 +msgid "OS" +msgstr "OS" + +#: src/labels.h:176 src/labels.h:180 +msgid "Browsers" +msgstr "ブラウザ" + +#: src/labels.h:178 +msgid "Top Browsers sorted by hits [, avgts, cumts, maxts]" +msgstr "上位のブラウザ [ヒット数、平均処理時間、合計処理時間、最大処理時間]" + +#: src/labels.h:183 +msgid "Referrer URLs" +msgstr "リファラのURL" + +#: src/labels.h:185 +msgid "Top Requested Referrers sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"上位の要求元のリファラ [ヒット数、平均処理時間、合計処理時間、最大処理時間]" + +#: src/labels.h:190 src/labels.h:194 +msgid "Referring Sites" +msgstr "参照元サイト" + +#: src/labels.h:192 +msgid "Top Referring Sites sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"上位の参照元サイト [ヒット数、平均処理時間、合計処理時間、最大処理時間]" + +#: src/labels.h:197 +msgid "Keyphrases from Google's search engine" +msgstr "キーフレーズ(Google検索から)" + +#: src/labels.h:199 +msgid "Top Keyphrases sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"上位のキーフレーズ [ヒット数、平均処理時間、合計処理時間、最大処理時間]" + +#: src/labels.h:201 +msgid "Keyphrases" +msgstr "キーフレーズ" + +#: src/labels.h:204 src/labels.h:208 +msgid "Geo Location" +msgstr "位置情報" + +#: src/labels.h:206 +msgid "Continent > Country sorted by unique hits [, avgts, cumts, maxts]" +msgstr "地理区分 > 国別 [ヒット数、平均処理時間、合計処理時間、最大処理時間]" + +#: src/labels.h:213 +msgid "Autonomous System Numbers/Organizations (ASNs)" +msgstr "Autonomous System Numbers/Organizations (ASNs)" + +#: src/labels.h:218 +msgid "HTTP Status Codes" +msgstr "HTTPステータスコード" + +#: src/labels.h:220 +msgid "Top HTTP Status Codes sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"上位のHTTPステータスコード [ヒット数、平均処理時間、合計処理時間、最大処理時" +"間]" + +#: src/labels.h:222 +msgid "Status Codes" +msgstr "ステータスコード" + +#: src/labels.h:225 src/labels.h:229 +msgid "MIME Types" +msgstr "MIMEタイプ" + +#: src/labels.h:227 +msgid "File types shipped out" +msgstr "送出されたファイル種別" + +#: src/labels.h:232 +msgid "Encryption settings" +msgstr "暗号化設定" + +#: src/labels.h:234 +msgid "TLS version and picked algorithm" +msgstr "TLSのバージョンと選択されたアルゴリズム" + +#: src/labels.h:236 +msgid "TLS Settings" +msgstr "TLSの設定" + +#: src/labels.h:240 +msgid "[ ] case sensitive" +msgstr "[ ] 大文字と小文字を区別する" + +#: src/labels.h:242 +msgid "[x] case sensitive" +msgstr "[x] 大文字と小文字を区別する" + +#: src/labels.h:244 +msgid "Regex allowed - ^g to cancel - TAB switch case" +msgstr "正規表現が有効 - [^g] キャンセル - [TAB] 切り替え" + +#: src/labels.h:246 +msgid "Find pattern in all views" +msgstr "すべてのビューでパターン検索を行う" + +#: src/labels.h:250 +msgid "Log Format Configuration" +msgstr "ログ形式設定" + +#: src/labels.h:252 +msgid "[SPACE] to toggle - [ENTER] to proceed - [q] to quit" +msgstr "[SPACE] 切り替え - [ENTER] 決定 - [q] 終了" + +#: src/labels.h:254 +msgid "Log Format - [c] to add/edit format" +msgstr "ログ形式 - [c] 追加/編集" + +#: src/labels.h:256 +msgid "Date Format - [d] to add/edit format" +msgstr "日付形式 - [d] 追加/編集" + +#: src/labels.h:258 +msgid "Time Format - [t] to add/edit format" +msgstr "時刻形式 - [t] 追加/編集" + +#: src/labels.h:260 src/labels.h:264 +msgid "[UP/DOWN] to scroll - [q] to close window" +msgstr "[↑/↓] スクロール - [q] ウィンドウを閉じる" + +#: src/labels.h:266 +#, c-format +msgid "User Agents for %1$s" +msgstr "%1$s のユーザーエージェント" + +#: src/labels.h:270 +msgid "Scheme Configuration" +msgstr "スキーム設定" + +#: src/labels.h:272 +msgid "[ENTER] to use scheme - [q]uit" +msgstr "[ENTER] スキーム選択 - [q] 終了" + +#: src/labels.h:276 +msgid "Sort active module by" +msgstr "選択したカラムで並び替え" + +#: src/labels.h:278 +msgid "[ENTER] select - [TAB] sort - [q]uit" +msgstr "[ENTER] 選択 - [TAB] ソート - [q] 終了" + +#: src/labels.h:282 +msgid "GoAccess Quick Help" +msgstr "GoAccessクイックヘルプ" + +#: src/labels.h:284 +msgid "[UP/DOWN] to scroll - [q] to quit" +msgstr "[↑/↓] スクロール - [q] 終了" + +#: src/labels.h:288 +msgid "In-Memory with On-Disk Persistent Storage." +msgstr "ディスク上の永続化ストレージ付きのインメモリ。" + +#: src/labels.h:292 +msgid "Format Errors - Verify your log/date/time format" +msgstr "" +"解析に失敗しました - ログ/日付/時刻のフォーマット設定を確認してください" + +#: src/labels.h:294 +msgid "No date format was found on your conf file." +msgstr "設定ファイル内で日付形式がセットされていません。" + +#: src/labels.h:296 +msgid "No log format was found on your conf file." +msgstr "設定ファイル内でログ形式がセットされていません。" + +#: src/labels.h:298 +msgid "No time format was found on your conf file." +msgstr "設定ファイル内で時刻形式がセットされていません。" + +#: src/labels.h:300 +msgid "No default config file found." +msgstr "デフォルトの設定ファイルが見つかりません。" + +#: src/labels.h:302 +msgid "You may specify one with" +msgstr "いずれか指定してください" + +#: src/labels.h:304 +msgid "producing the following errors" +msgstr "エラーが発生しました" + +#: src/labels.h:306 +#, c-format +msgid "Parsed %1$d lines" +msgstr "解析済み: %1$d 行" + +#: src/labels.h:308 +msgid "Please report it by opening an issue on GitHub" +msgstr "GitHub上のIssueから問題を報告してください" + +#: src/labels.h:310 +msgid "Select a time format." +msgstr "時刻形式を選択します。" + +#: src/labels.h:312 +msgid "Select a date format." +msgstr "日付形式を選択します。" + +#: src/labels.h:314 +msgid "Select a log format." +msgstr "ログ形式を選択します。" + +#: src/labels.h:316 +#, c-format +msgid "'%1$s' panel is disabled" +msgstr "'%1$s' パネルは無効化されています" + +#: src/labels.h:318 +msgid "No input data was provided nor there's data to restore." +msgstr "入力データが与えられておらず、復元データもありません。" + +#: src/labels.h:320 +msgid "Unable to allocate memory for a log instance." +msgstr "ログインスタンスのためのメモリを割り当てられません。" + +#: src/labels.h:322 +msgid "Unable to find the given log." +msgstr "与えられたログを見付けられません。" + +#: src/labels.h:326 +msgid "For more details visit" +msgstr "詳細はこちら" + +#: src/labels.h:328 +msgid "Last Updated" +msgstr "最終更新日時" + +#: src/labels.h:330 +msgid "WebSocket server ready to accept new client connections" +msgstr "クライアントからのWebSocket接続を待っています" + +#: src/labels.h:333 +msgid "The following options can also be supplied to the command" +msgstr "次のオプションはコマンドで指定することもできます" + +#: src/labels.h:335 +msgid "Examples can be found by running" +msgstr "実行例" + +#: src/labels.h:338 +msgid "Server Statistics" +msgstr "サーバー統計" + +#: src/labels.h:340 +msgid "Theme" +msgstr "テーマ" + +#: src/labels.h:342 +msgid "Dark Gray" +msgstr "ダークグレー" + +#: src/labels.h:344 +msgid "Bright" +msgstr "ライト" + +#: src/labels.h:346 +msgid "Dark Blue" +msgstr "ダークブルー" + +#: src/labels.h:348 +msgid "Dark Purple" +msgstr "ダークパープル" + +#: src/labels.h:350 +msgid "Panels" +msgstr "パネル" + +#: src/labels.h:352 +msgid "Items per Page" +msgstr "ページあたりの表示数" + +#: src/labels.h:354 +msgid "Tables" +msgstr "テーブル" + +#: src/labels.h:356 +msgid "Display Tables" +msgstr "テーブル表示" + +#: src/labels.h:358 +msgid "Auto-Hide on Small Devices" +msgstr "自動非表示設定(小型端末用)" + +#: src/labels.h:360 +msgid "Automatically hide tables on small screen devices" +msgstr "画面が小さい場合に自動でテーブルを非表示にする" + +#: src/labels.h:362 +msgid "Toggle Panel" +msgstr "パネルを切り替える" + +#: src/labels.h:364 +msgid "Layout" +msgstr "レイアウト" + +#: src/labels.h:366 +msgid "Horizontal" +msgstr "水平" + +#: src/labels.h:368 +msgid "Vertical" +msgstr "垂直" + +#: src/labels.h:370 +msgid "WideScreen" +msgstr "ワイドスクリーン" + +#: src/labels.h:372 +msgid "File Options" +msgstr "ファイルオプション" + +#: src/labels.h:374 +msgid "Export as JSON" +msgstr "JSON形式でエクスポート" + +#: src/labels.h:376 +msgid "Panel Options" +msgstr "パネルオプション" + +#: src/labels.h:378 +msgid "Previous" +msgstr "前へ" + +#: src/labels.h:380 +msgid "Next" +msgstr "次へ" + +#: src/labels.h:382 +msgid "First" +msgstr "最初へ" + +#: src/labels.h:384 +msgid "Last" +msgstr "最後へ" + +#: src/labels.h:386 +msgid "Chart Options" +msgstr "グラフ設定" + +#: src/labels.h:388 +msgid "Chart" +msgstr "グラフ" + +#: src/labels.h:390 +msgid "Type" +msgstr "タイプ" + +#: src/labels.h:392 +msgid "Area Spline" +msgstr "平滑面グラフ" + +#: src/labels.h:394 +msgid "Bar" +msgstr "棒グラフ" + +#: src/labels.h:396 +msgid "World Map" +msgstr "" + +#: src/labels.h:398 +msgid "Plot Metric" +msgstr "表示するデータ" + +#: src/labels.h:400 +msgid "Table Columns" +msgstr "テーブルカラム" + +#: src/labels.h:404 +msgid "0xx Unofficial Codes" +msgstr "" + +#: src/labels.h:406 +msgid "1xx Informational" +msgstr "1xx 情報" + +#: src/labels.h:408 +msgid "2xx Success" +msgstr "2xx 成功" + +#: src/labels.h:410 +msgid "3xx Redirection" +msgstr "3xx リダイレクション" + +#: src/labels.h:412 +msgid "4xx Client Errors" +msgstr "4xx クライアントエラー" + +#: src/labels.h:414 +msgid "5xx Server Errors" +msgstr "5xx サーバーエラー" + +#: src/labels.h:417 +msgid "0 - Caddy: Unhandled - No configured routes" +msgstr "" + +#: src/labels.h:419 +msgid "100 - Continue: Server received the initial part of the request" +msgstr "100 - 継続: リクエストヘッダーを受理しました" + +#: src/labels.h:421 +msgid "101 - Switching Protocols: Client asked to switch protocols" +msgstr "" +"101 - プロトコル変更: HTTPヘッダーでリクエストされたプロトコルに切り替えます" + +#: src/labels.h:423 +msgid "200 - OK: The request sent by the client was successful" +msgstr "200 - 成功: リクエストに成功しました" + +#: src/labels.h:425 +msgid "201 - Created: The request has been fulfilled and created" +msgstr "201 - 作成: リクエストが成功して新たなリソースの作成が完了しました" + +#: src/labels.h:427 +msgid "202 - Accepted: The request has been accepted for processing" +msgstr "202 - 受理: リクエストを受け取ったが処理されていません" + +#: src/labels.h:429 +msgid "203 - Non-authoritative Information: Response from a third party" +msgstr "" +"203 - 認証されていない情報: リクエストを正常に処理しましたが、返される情報は" +"別の送信元から来る可能性があります" + +#: src/labels.h:431 +msgid "204 - No Content: Request did not return any content" +msgstr "" +"204 - コンテンツ無し: リクエストを正常に処理しましたが、返すべき情報がありま" +"せん" + +#: src/labels.h:433 +msgid "205 - Reset Content: Server asked the client to reset the document" +msgstr "" +"205 - リセット要求: クライアントに対してドキュメントビューのリセットを行うよ" +"う要求しました" + +#: src/labels.h:435 +msgid "206 - Partial Content: The partial GET has been successful" +msgstr "206 - 部分応答: コンテンツの一部のみレスポンスを返しました" + +#: src/labels.h:437 +msgid "207 - Multi-Status: WebDAV; RFC 4918" +msgstr "207 - 複数ステータス: (WebDAV拡張) RFC 4918" + +#: src/labels.h:439 +msgid "208 - Already Reported: WebDAV; RFC 5842" +msgstr "208 - 報告済み: (WebDAV拡張) RFC 5842" + +#: src/labels.h:441 +msgid "218 - This is fine: Apache servers. A catch-all error condition" +msgstr "" + +#: src/labels.h:443 +msgid "300 - Multiple Choices: Multiple options for the resource" +msgstr "300 - 選択が必要: リダイレクト先が複数指定されています" + +#: src/labels.h:445 +msgid "301 - Moved Permanently: Resource has permanently moved" +msgstr "301 - 恒久的な移動: リクエストされたリソースは完全に移動されました" + +#: src/labels.h:447 +msgid "302 - Moved Temporarily (redirect)" +msgstr "302 - 一時的な移動: リクエストされたリソースは一時的に移動されました" + +#: src/labels.h:449 +msgid "303 - See Other Document: The response is at a different URI" +msgstr "" +"303 - 別コンテンツ: リクエストされたリソースは別のURLで提供されています" + +#: src/labels.h:451 +msgid "304 - Not Modified: Resource has not been modified" +msgstr "304 - 更新無し: リクエストされたリソースは更新されていません" + +#: src/labels.h:453 +msgid "305 - Use Proxy: Can only be accessed through the proxy" +msgstr "" +"305 - プロキシ使用: リクエストされたリソースはプロキシを使用して取得できます" + +#: src/labels.h:455 +msgid "307 - Temporary Redirect: Resource temporarily moved" +msgstr "307 - 一時的な移動: リクエストされたリソースは一時的に移動されました" + +#: src/labels.h:457 +msgid "308 - Permanent Redirect" +msgstr "308 - 恒久的なリダイレクト" + +#: src/labels.h:459 +msgid "400 - Bad Request: The syntax of the request is invalid" +msgstr "400 - 不正なリクエスト: リクエストを処理できません" + +#: src/labels.h:461 +msgid "401 - Unauthorized: Request needs user authentication" +msgstr "401 - 認証が必要: このリクエストを処理するには認証が必要です" + +#: src/labels.h:463 +msgid "402 - Payment Required" +msgstr "402 - 課金が必要なコンテンツ" + +#: src/labels.h:465 +msgid "403 - Forbidden: Server is refusing to respond to it" +msgstr "403 - アクセス禁止: このリクエストへのアクセスは禁止されています" + +#: src/labels.h:467 +msgid "404 - Not Found: Requested resource could not be found" +msgstr "404 - リソース不明: リクエストされたリソースは存在しません" + +#: src/labels.h:469 +msgid "405 - Method Not Allowed: Request method not supported" +msgstr "" +"405 - 許可されていない: リクエストされたメソッドでのアクセスは禁止されていま" +"す" + +#: src/labels.h:471 +msgid "406 - Not Acceptable" +msgstr "406 - リクエストを受理できません" + +#: src/labels.h:473 +msgid "407 - Proxy Authentication Required" +msgstr "407 - プロキシ認証が必要です" + +#: src/labels.h:475 +msgid "408 - Request Timeout: Server timed out waiting for the request" +msgstr "408 - タイムアウト: リクエストがタイムアウトしました" + +#: src/labels.h:477 +msgid "409 - Conflict: Conflict in the request" +msgstr "409 - 衝突: リクエストが衝突しました" + +#: src/labels.h:479 +msgid "410 - Gone: Resource requested is no longer available" +msgstr "410 - 消滅: リクエストされたリソースは完全に削除されました" + +#: src/labels.h:481 +msgid "411 - Length Required: Invalid Content-Length" +msgstr "411 - Content-Lengthヘッダーが必要です" + +#: src/labels.h:483 +msgid "412 - Precondition Failed: Server does not meet preconditions" +msgstr "412 - サーバーに与えられた前提条件を満たしていません" + +#: src/labels.h:485 +msgid "413 - Payload Too Large" +msgstr "413 - ペイロードが長すぎます" + +#: src/labels.h:487 +msgid "414 - Request-URI Too Long" +msgstr "414 - リクエストされたURIが長すぎます" + +#: src/labels.h:489 +msgid "415 - Unsupported Media Type: Media type is not supported" +msgstr "415 - サポートされていないメディアタイプ" + +#: src/labels.h:491 +msgid "416 - Requested Range Not Satisfiable: Cannot supply that portion" +msgstr "" +"416 - リクエストされたContent-Lengthヘッダーの範囲がリソースより超過していま" +"す" + +#: src/labels.h:493 +msgid "417 - Expectation Failed" +msgstr "417 - 拡張ステータスコードが使えません" + +#: src/labels.h:495 +msgid "418 - I'm a teapot" +msgstr "418 - 私はティーポットです" + +#: src/labels.h:497 +msgid "419 - Page Expired: Laravel Framework when a CSRF Token is missing" +msgstr "" + +#: src/labels.h:499 +msgid "420 - Method Failure: Spring Framework when a method has failed" +msgstr "" + +#: src/labels.h:501 +msgid "421 - Misdirected Request" +msgstr "421 - 不明なリクエスト" + +#: src/labels.h:503 +msgid "422 - Unprocessable Entity due to semantic errors: WebDAV" +msgstr "422 - (WebDAV拡張) 処理できないエンティティ" + +#: src/labels.h:505 +msgid "423 - The resource that is being accessed is locked" +msgstr "423 - このリソースはロックされています" + +#: src/labels.h:507 +msgid "424 - Failed Dependency: WebDAV" +msgstr "424 - (WebDAV拡張) 依存関係でエラーが発生しました" + +#: src/labels.h:509 +msgid "426 - Upgrade Required: Client should switch to a different protocol" +msgstr "" +"426 - アップグレードが必要: プロトコルが古すぎてリクエストを処理できません" + +#: src/labels.h:511 +msgid "428 - Precondition Required" +msgstr "428 - リクエストを条件付きにする必要があります" + +#: src/labels.h:513 +msgid "429 - Too Many Requests: The user has sent too many requests" +msgstr "429 - 過重リクエスト: 制限されたリクエスト数を超えたので処理できません" + +#: src/labels.h:515 +msgid "" +"430 - Request Header Fields Too Large: Too many URLs are requested within a " +"certain time frame" +msgstr "" + +#: src/labels.h:517 +msgid "431 - Request Header Fields Too Large" +msgstr "431 - HTTPヘッダーが長すぎます" + +#: src/labels.h:519 +msgid "440 - Login Time-out: The client's session has expired" +msgstr "" + +#: src/labels.h:521 +#, fuzzy +msgid "449 - Retry With: The server cannot honour the request" +msgstr "408 - タイムアウト: リクエストがタイムアウトしました" + +#: src/labels.h:523 +msgid "" +"450 - Blocked by Windows Parental Controls: The Microsoft extension code " +"indicated" +msgstr "" + +#: src/labels.h:525 +msgid "451 - Unavailable For Legal Reasons" +msgstr "451 - 法的理由により利用不可" + +#: src/labels.h:527 +msgid "444 - (Nginx) Connection closed without sending any headers" +msgstr "444 - (nginx) 接続を遮断しました" + +#: src/labels.h:529 +msgid "460 - AWS Elastic Load Balancing: Client closed the connection " +msgstr "" + +#: src/labels.h:531 +msgid "" +"463 - AWS Elastic Load Balancing: The load balancer received more than 30 IP " +"addresses" +msgstr "" + +#: src/labels.h:533 +msgid "464 - AWS Elastic Load Balancing: Incompatible protocol versions" +msgstr "" + +#: src/labels.h:535 +msgid "494 - (Nginx) Request Header Too Large" +msgstr "494 - (nginx) HTTPヘッダーが長すぎます" + +#: src/labels.h:537 +msgid "495 - (Nginx) SSL client certificate error" +msgstr "495 - (nginx) SSLクライアント証明書エラー" + +#: src/labels.h:539 +msgid "496 - (Nginx) Client didn't provide certificate" +msgstr "496 - (nginx) クライアントが証明書を提供しませんでした" + +#: src/labels.h:541 +msgid "497 - (Nginx) HTTP request sent to HTTPS port" +msgstr "497 - (nginx) HTTPリクエストをHTTPSポートに送信しました" + +#: src/labels.h:543 +msgid "498 - Invalid Token: an expired or otherwise invalid token" +msgstr "" + +#: src/labels.h:545 +msgid "499 - (Nginx) Connection closed by client while processing request" +msgstr "" +"499 - (nginx) リクエストを処理中にクライアントによって接続を閉じられました" + +#: src/labels.h:547 +msgid "500 - Internal Server Error" +msgstr "500 - 内部サーバーエラー" + +#: src/labels.h:549 +msgid "501 - Not Implemented" +msgstr "501 - 実装されていません" + +#: src/labels.h:551 +msgid "502 - Bad Gateway: Received an invalid response from the upstream" +msgstr "" +"502 - 不正なゲートウェイ: 上位サーバーから不正なレスポンスを受信しました" + +#: src/labels.h:553 +msgid "503 - Service Unavailable: The server is currently unavailable" +msgstr "503 - サービス利用不可: サーバーがダウンしました" + +#: src/labels.h:555 +msgid "504 - Gateway Timeout: The upstream server failed to send request" +msgstr "504 - ゲートウェイタイムアウト: 上位サーバーがリクエストを返しません" + +#: src/labels.h:557 +msgid "505 - HTTP Version Not Supported" +msgstr "505 - HTTPバージョンがサポートされていません" + +#: src/labels.h:559 +msgid "509 - Bandwidth Limit Exceeded: The server has exceeded the bandwidth" +msgstr "" + +#: src/labels.h:561 +msgid "520 - CloudFlare - Web server is returning an unknown error" +msgstr "520 - CloudFlare - Webサーバーが未知のエラーを返しています" + +#: src/labels.h:563 +msgid "521 - CloudFlare - Web server is down" +msgstr "521 - CloudFlare - Webサーバーがダウンしています" + +#: src/labels.h:565 +msgid "522 - CloudFlare - Connection timed out" +msgstr "522 - CloudFlare - 接続がタイムアウトしました" + +#: src/labels.h:567 +msgid "523 - CloudFlare - Origin is unreachable" +msgstr "523 - CloudFlare - Originに到達できません" + +#: src/labels.h:569 +msgid "524 - CloudFlare - A timeout occurred" +msgstr "524 - CloudFlare - タイムアウトが発生しました" + +#: src/labels.h:571 +msgid "" +"525 - SSL Handshake Failed: Cloudflare could not negotiate a SSL/TLS " +"handshake" +msgstr "" + +#: src/labels.h:573 +msgid "" +"526 - Invalid SSL Certificate: Cloudflare could not validate the SSL " +"certificate" +msgstr "" + +#: src/labels.h:575 +msgid "527 - Railgun Error: An interrupted connection" +msgstr "" + +#: src/labels.h:577 +msgid "529 - Site is overloaded: A site can not process the request" +msgstr "" + +#: src/labels.h:579 +msgid "530 - Site is frozen: A site has been frozen due to inactivity" +msgstr "" + +#: src/labels.h:581 +msgid "" +"540 - Temporarily Disabled: The requested endpoint has been temporarily " +"disabled" +msgstr "" + +#: src/labels.h:583 +#, fuzzy +msgid "561 - Unauthorized: An error around authentication" +msgstr "401 - 認証が必要: このリクエストを処理するには認証が必要です" + +#: src/labels.h:585 +msgid "" +"598 - Network read timeout error: some HTTP proxies to signal a network read " +"timeout" +msgstr "" + +#: src/labels.h:587 +msgid "599 - Network Connect Timeout Error: An error used by some HTTP proxies" +msgstr "" + +#: src/labels.h:589 +msgid "783 - Unexpected Token: The request includes a JSON syntax error" +msgstr "" diff --git a/po/ko.po b/po/ko.po new file mode 100644 index 0000000000..180fa0c40a --- /dev/null +++ b/po/ko.po @@ -0,0 +1,1076 @@ +msgid "" +msgstr "" +"Project-Id-Version: goaccess 1.6.3\n" +"Report-Msgid-Bugs-To: hello@goaccess.io\n" +"POT-Creation-Date: 2024-04-11 20:17-0500\n" +"PO-Revision-Date: 2022-09-06 21:27+0900\n" +"Last-Translator: David 창모 Yang \n" +"Language-Team: Korean \n" +"Language: ko\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0\n" +"X-Generator: Gtranslator 40.0\n" + +#: src/labels.h:45 +msgid "en" +msgstr "ko" + +#: src/labels.h:48 +msgid "Exp. Panel" +msgstr "패널 펼치기" + +#: src/labels.h:49 +msgid "Help" +msgstr "도움말" + +#: src/labels.h:50 +msgid "Quit" +msgstr "종료" + +#: src/labels.h:51 +msgid "Total" +msgstr "합계" + +#: src/labels.h:54 +msgid "[x] ASC [ ] DESC" +msgstr "[x] 오름차순 [ ] 내림차순" + +#: src/labels.h:55 +msgid "[ ] ASC [x] DESC" +msgstr "[ ] 오름차순 [x] 내림차순" + +#: src/labels.h:58 +#, c-format +msgid "[Active Panel: %1$s]" +msgstr "[표시 중인 패널: %1$s]" + +#: src/labels.h:59 +msgid "[q]uit GoAccess" +msgstr "[q] GoAccess 종료" + +#: src/labels.h:60 +msgid "[?] Help [Enter] Exp. Panel" +msgstr "[?] 도움말 [Enter] 패널 펼치기" + +#: src/labels.h:61 +msgid "Dashboard" +msgstr "대시보드" + +#: src/labels.h:62 +msgid "Dashboard - Overall Analyzed Requests" +msgstr "대시보드 - 기록 분석 개요" + +#: src/labels.h:63 +msgid "Overall Analyzed Requests" +msgstr "기록 분석 개요" + +#: src/labels.h:65 src/labels.h:86 +msgid "Tx. Amount" +msgstr "전송량" + +#: src/labels.h:66 +msgid "Date/Time" +msgstr "날짜/시간" + +#: src/labels.h:67 +msgid "Excl. IP Hits" +msgstr "제외된 IP 방문" + +#: src/labels.h:68 +msgid "Failed Requests" +msgstr "무효 요청 수" + +#: src/labels.h:69 +msgid "Log Parsing Time" +msgstr "로그 분석 시간" + +#: src/labels.h:70 +msgid "Log Size" +msgstr "로그 용량" + +#: src/labels.h:71 +msgid "Log Source" +msgstr "로그 출처" + +#: src/labels.h:72 src/labels.h:187 +msgid "Referrers" +msgstr "참조자 수" + +#: src/labels.h:73 +msgid "Total Requests" +msgstr "요청 수 합계" + +#: src/labels.h:74 +msgid "Static Files" +msgstr "정적 파일 수" + +#: src/labels.h:75 src/labels.h:159 +msgid "Not Found" +msgstr "찾을 수 없음" + +#: src/labels.h:76 +msgid "Requested Files" +msgstr "요청된 파일 수" + +#: src/labels.h:77 +msgid "Unique Visitors" +msgstr "순 방문자" + +#: src/labels.h:78 +msgid "Valid Requests" +msgstr "유효 요청 수" + +#: src/labels.h:81 +msgid "Hits" +msgstr "방문 수" + +#: src/labels.h:82 +msgid "h%" +msgstr "h%" + +#: src/labels.h:83 src/labels.h:110 +msgid "Visitors" +msgstr "방문자 수" + +#: src/labels.h:84 +msgid "Vis." +msgstr "방문자 수" + +#: src/labels.h:85 +msgid "v%" +msgstr "v%" + +#: src/labels.h:87 +msgid "Avg. T.S." +msgstr "평균 처리시간" + +#: src/labels.h:88 +msgid "Cum. T.S." +msgstr "누적 처리시간" + +#: src/labels.h:89 +msgid "Max. T.S." +msgstr "최대 처리시간" + +#: src/labels.h:90 +msgid "Method" +msgstr "접속 방법" + +#: src/labels.h:91 +msgid "Mtd" +msgstr "접속 방법" + +#: src/labels.h:92 +msgid "Protocol" +msgstr "프로토콜" + +#: src/labels.h:93 +msgid "Proto" +msgstr "프로토콜" + +#: src/labels.h:94 +msgid "City" +msgstr "도시" + +#: src/labels.h:95 src/labels.h:211 src/labels.h:215 +msgid "ASN" +msgstr "" + +#: src/labels.h:96 +msgid "Country" +msgstr "국가" + +#: src/labels.h:97 +msgid "Hostname" +msgstr "호스트명" + +#: src/labels.h:98 +msgid "Data" +msgstr "데이터" + +#: src/labels.h:100 +msgid "Hits/Visitors" +msgstr "방문 수/방문자 수" + +#: src/labels.h:104 +msgid "Unique visitors per day" +msgstr "일일 순 방문자" + +#: src/labels.h:106 +msgid "Unique visitors per day - Including spiders" +msgstr "일일 순 방문자 - 크롤러 포함" + +#: src/labels.h:108 +msgid "Hits having the same IP, date and agent are a unique visit." +msgstr "동일한 IP주소, 날짜, 에이전트를 가진 방문은 순 방문으로 간주됩니다." + +#: src/labels.h:113 +msgid "Requested Files (URLs)" +msgstr "요청된 파일 (URL)" + +#: src/labels.h:115 +msgid "Top requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"방문 수 순으로 정렬한 요청 수 [, 평균 처리시간, 누적 처리시간, 최대 처리시" +"간, 접속 방법, 프로토콜]" + +#: src/labels.h:117 +msgid "Requests" +msgstr "요청 수" + +#: src/labels.h:120 src/labels.h:124 +msgid "Static Requests" +msgstr "정적 파일 요청 수" + +#: src/labels.h:122 +msgid "Top static requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"방문 수 순으로 정렬한 정적 파일 요청 수 [, 평균 처리시간, 누적 처리시간, 최" +"대 처리시간, 접속 방법, 프로토콜]" + +#: src/labels.h:127 +msgid "Time Distribution" +msgstr "시간 분포" + +#: src/labels.h:129 +msgid "Data sorted by hour [, avgts, cumts, maxts]" +msgstr "시간별로 정렬한 데이터 [, 평균 처리시간, 누적 처리시간, 최대 처리시간]" + +#: src/labels.h:131 +msgid "Time" +msgstr "시간" + +#: src/labels.h:134 src/labels.h:138 +msgid "Virtual Hosts" +msgstr "가상 호스트" + +#: src/labels.h:136 src/labels.h:143 src/labels.h:150 +msgid "Data sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"방문 수로 정렬한 데이터 [, 평균 처리시간, 누적 처리시간, 최대 처리시간]" + +#: src/labels.h:141 +msgid "Remote User (HTTP authentication)" +msgstr "원격 사용자 (HTTP 인증)" + +#: src/labels.h:145 +msgid "Remote User" +msgstr "원격 사용자" + +#: src/labels.h:148 +msgid "The cache status of the object served" +msgstr "로드되는 개체의 캐시 상태" + +#: src/labels.h:152 +msgid "Cache Status" +msgstr "캐시 상태" + +#: src/labels.h:155 +msgid "Not Found URLs (404s)" +msgstr "찾을 수 없는 URL (404)" + +#: src/labels.h:157 +msgid "Top not found URLs sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"방문 수로 정렬한 찾을 수 없는 URL [, 평균 처리시간, 누적 처리시간, 최대 처리" +"시간, 접속 방법, 프로토콜]" + +#: src/labels.h:162 +msgid "Visitor Hostnames and IPs" +msgstr "방문자 호스트명 및 IP" + +#: src/labels.h:164 +msgid "Top visitor hosts sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"방문 수로 정렬한 방문자 호스트 [, 평균 처리시간, 누적 처리시간, 최대 처리시" +"간]" + +#: src/labels.h:166 +msgid "Hosts" +msgstr "호스트명" + +#: src/labels.h:169 +msgid "Operating Systems" +msgstr "운영체제" + +#: src/labels.h:171 +msgid "Top Operating Systems sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"방문 수로 정렬한 운영체제 [, 평균 처리시간, 누적 처리시간, 최대 처리시간]" + +#: src/labels.h:173 +msgid "OS" +msgstr "OS" + +#: src/labels.h:176 src/labels.h:180 +msgid "Browsers" +msgstr "브라우저" + +#: src/labels.h:178 +msgid "Top Browsers sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"방문 수로 정렬한 브라우저 [, 평균 처리시간, 누적 처리시간, 최대 처리시간]" + +#: src/labels.h:183 +#, fuzzy +msgid "Referrer URLs" +msgstr "참조자 URL" + +#: src/labels.h:185 +#, fuzzy +msgid "Top Requested Referrers sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"방문 수로 정렬한 요청 참조자 [, 평균 처리시간, 누적 처리시간, 최대 처리시간]" + +#: src/labels.h:190 src/labels.h:194 +msgid "Referring Sites" +msgstr "출발 사이트" + +#: src/labels.h:192 +msgid "Top Referring Sites sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"방문 수로 정렬한 출발 사이트 [, 평균 처리시간, 누적 처리시간, 최대 처리시간]" + +#: src/labels.h:197 +msgid "Keyphrases from Google's search engine" +msgstr "구글로 검색된 관건문구" + +#: src/labels.h:199 +msgid "Top Keyphrases sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"방문 수로 정렬한 관건문구 [, 평균 처리시간, 누적 처리시간, 최대 처리시간]" + +#: src/labels.h:201 +msgid "Keyphrases" +msgstr "관건문구" + +#: src/labels.h:204 src/labels.h:208 +msgid "Geo Location" +msgstr "지리적 위치" + +#: src/labels.h:206 +msgid "Continent > Country sorted by unique hits [, avgts, cumts, maxts]" +msgstr "" +"순 방문 수로 정렬한 대륙 > 국가 [, 평균 처리시간, 누적 처리시간, 최대 처리시" +"간]" + +#: src/labels.h:213 +msgid "Autonomous System Numbers/Organizations (ASNs)" +msgstr "" + +#: src/labels.h:218 +msgid "HTTP Status Codes" +msgstr "HTTP 상태 코드" + +#: src/labels.h:220 +msgid "Top HTTP Status Codes sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"방문 수로 정렬한 HTTP 상태 코드 [, 평균 처리시간, 누적 처리시간, 최대 처리시" +"간]" + +#: src/labels.h:222 +msgid "Status Codes" +msgstr "상태 코드" + +#: src/labels.h:225 src/labels.h:229 +msgid "MIME Types" +msgstr "MIME 유형" + +#: src/labels.h:227 +msgid "File types shipped out" +msgstr "로드된 파일 유형" + +#: src/labels.h:232 +msgid "Encryption settings" +msgstr "암호화 설정사항" + +#: src/labels.h:234 +msgid "TLS version and picked algorithm" +msgstr "TLS 버전 및 선택한 알고리즘" + +#: src/labels.h:236 +msgid "TLS Settings" +msgstr "TLS 설정사항" + +#: src/labels.h:240 +msgid "[ ] case sensitive" +msgstr "[ ] 대소문자 구분" + +#: src/labels.h:242 +msgid "[x] case sensitive" +msgstr "[x] 대소문자 구분" + +#: src/labels.h:244 +msgid "Regex allowed - ^g to cancel - TAB switch case" +msgstr "정규표현식 허용 - 취소하려면 ^g - 대소문자 전환은 TAB" + +#: src/labels.h:246 +msgid "Find pattern in all views" +msgstr "모든 보기에서 패턴을 찾기" + +#: src/labels.h:250 +msgid "Log Format Configuration" +msgstr "로그 형식 구성" + +#: src/labels.h:252 +msgid "[SPACE] to toggle - [ENTER] to proceed - [q] to quit" +msgstr "토글(똑딱)은 [SPACE] - 진행은 [ENTER] - 종료는 [q]" + +#: src/labels.h:254 +msgid "Log Format - [c] to add/edit format" +msgstr "로그 형식 - 형식 추가/편집은 [c]" + +#: src/labels.h:256 +msgid "Date Format - [d] to add/edit format" +msgstr "날짜 형식 - 형식 추가/편집은 [d]" + +#: src/labels.h:258 +msgid "Time Format - [t] to add/edit format" +msgstr "시간 형식 - 형식 추가/편집은 [t]" + +#: src/labels.h:260 src/labels.h:264 +msgid "[UP/DOWN] to scroll - [q] to close window" +msgstr "스크롤은 [↑/↓] - 창 닫기는 [q]" + +#: src/labels.h:266 +#, c-format +msgid "User Agents for %1$s" +msgstr "%1$s 의 사용자 에이전트" + +#: src/labels.h:270 +msgid "Scheme Configuration" +msgstr "스킴 구성" + +#: src/labels.h:272 +msgid "[ENTER] to use scheme - [q]uit" +msgstr "스킴을 사용하려면 [ENTER] - [q] 종료" + +#: src/labels.h:276 +msgid "Sort active module by" +msgstr "활성화된 모듈의 정렬 기준" + +#: src/labels.h:278 +msgid "[ENTER] select - [TAB] sort - [q]uit" +msgstr "[ENTER] 선택 - [TAB] 정렬 - [q] 종료" + +#: src/labels.h:282 +msgid "GoAccess Quick Help" +msgstr "GoAccess 빠른 도움말" + +#: src/labels.h:284 +msgid "[UP/DOWN] to scroll - [q] to quit" +msgstr "스크롤은 [↑/↓] - 종료는 [q]" + +#: src/labels.h:288 +msgid "In-Memory with On-Disk Persistent Storage." +msgstr "디스크상의 지속적 저장공간과 함께 메모리 기억." + +#: src/labels.h:292 +msgid "Format Errors - Verify your log/date/time format" +msgstr "형식 오류 - 로그/날짜/시간 형식을 확인하세요" + +#: src/labels.h:294 +msgid "No date format was found on your conf file." +msgstr "conf 파일에 날짜 형식이 발견되지 않았습니다." + +#: src/labels.h:296 +msgid "No log format was found on your conf file." +msgstr "conf 파일에 로그 형식이 발견되지 않았습니다." + +#: src/labels.h:298 +msgid "No time format was found on your conf file." +msgstr "conf 파일에 시간 형식이 발견되지 않았습니다." + +#: src/labels.h:300 +msgid "No default config file found." +msgstr "기본 제공 config 파일을 찾을 수 없습니다." + +#: src/labels.h:302 +msgid "You may specify one with" +msgstr "별도로 지정하시려면" + +#: src/labels.h:304 +msgid "producing the following errors" +msgstr "다음과 같은 오류 메시지 발생" + +#: src/labels.h:306 +#, c-format +msgid "Parsed %1$d lines" +msgstr "%1$d 개의 행을 식별" + +#: src/labels.h:308 +msgid "Please report it by opening an issue on GitHub" +msgstr "GitHub에서 Issue를 열어 신고해 주세요" + +#: src/labels.h:310 +msgid "Select a time format." +msgstr "시간 형식을 선택하세요." + +#: src/labels.h:312 +msgid "Select a date format." +msgstr "날짜 형식을 선택하세요." + +#: src/labels.h:314 +msgid "Select a log format." +msgstr "로그 형식을 선택하세요." + +#: src/labels.h:316 +#, c-format +msgid "'%1$s' panel is disabled" +msgstr "'%1$s' 패널은 비활성 상태입니다" + +#: src/labels.h:318 +msgid "No input data was provided nor there's data to restore." +msgstr "입력 데이터가 주어지지 않았고 복원할 데이터도 없음" + +#: src/labels.h:320 +msgid "Unable to allocate memory for a log instance." +msgstr "" + +#: src/labels.h:322 +msgid "Unable to find the given log." +msgstr "" + +#: src/labels.h:326 +msgid "For more details visit" +msgstr "자세한 사항은 다음을 방문하세요" + +#: src/labels.h:328 +msgid "Last Updated" +msgstr "최근 업데이트" + +#: src/labels.h:330 +msgid "WebSocket server ready to accept new client connections" +msgstr "WebSocket 서버가 새로운 클라이언트 접속을 받을 준비가 되었습니다" + +#: src/labels.h:333 +msgid "The following options can also be supplied to the command" +msgstr "명령어에 다음과 같은 옵션을 추가할 수 있습니다" + +#: src/labels.h:335 +msgid "Examples can be found by running" +msgstr "다음을 실행하여 예시를 볼 수 있습니다" + +#: src/labels.h:338 +msgid "Server Statistics" +msgstr "서버 통계" + +#: src/labels.h:340 +msgid "Theme" +msgstr "테마" + +#: src/labels.h:342 +msgid "Dark Gray" +msgstr "짙은 회색" + +#: src/labels.h:344 +msgid "Bright" +msgstr "밝은 색" + +#: src/labels.h:346 +msgid "Dark Blue" +msgstr "짙은 파란색" + +#: src/labels.h:348 +msgid "Dark Purple" +msgstr "짙은 보라색" + +#: src/labels.h:350 +msgid "Panels" +msgstr "패널" + +#: src/labels.h:352 +msgid "Items per Page" +msgstr "페이지에 표시할 항목 수" + +#: src/labels.h:354 +msgid "Tables" +msgstr "표" + +#: src/labels.h:356 +msgid "Display Tables" +msgstr "표 표시" + +#: src/labels.h:358 +msgid "Auto-Hide on Small Devices" +msgstr "소형 기기에서는 자동 숨김" + +#: src/labels.h:360 +msgid "Automatically hide tables on small screen devices" +msgstr "작은 화면의 기기에서는 표를 자동으로 숨깁니다" + +#: src/labels.h:362 +msgid "Toggle Panel" +msgstr "패널 토글" + +#: src/labels.h:364 +msgid "Layout" +msgstr "레이아웃" + +#: src/labels.h:366 +msgid "Horizontal" +msgstr "가로" + +#: src/labels.h:368 +msgid "Vertical" +msgstr "세로" + +#: src/labels.h:370 +msgid "WideScreen" +msgstr "와이드스크린" + +#: src/labels.h:372 +msgid "File Options" +msgstr "파일 옵션" + +#: src/labels.h:374 +msgid "Export as JSON" +msgstr "JSON 형태로 내보내기" + +#: src/labels.h:376 +msgid "Panel Options" +msgstr "패널 옵션" + +#: src/labels.h:378 +msgid "Previous" +msgstr "이전" + +#: src/labels.h:380 +msgid "Next" +msgstr "다음" + +#: src/labels.h:382 +msgid "First" +msgstr "처음" + +#: src/labels.h:384 +msgid "Last" +msgstr "마지막" + +#: src/labels.h:386 +msgid "Chart Options" +msgstr "도표 옵션" + +#: src/labels.h:388 +msgid "Chart" +msgstr "도표" + +#: src/labels.h:390 +msgid "Type" +msgstr "유형" + +#: src/labels.h:392 +msgid "Area Spline" +msgstr "활면곡선" + +#: src/labels.h:394 +msgid "Bar" +msgstr "막대그래프" + +#: src/labels.h:396 +msgid "World Map" +msgstr "" + +#: src/labels.h:398 +msgid "Plot Metric" +msgstr "표시할 데이터" + +#: src/labels.h:400 +msgid "Table Columns" +msgstr "표의 열" + +#: src/labels.h:404 +msgid "0xx Unofficial Codes" +msgstr "" + +#: src/labels.h:406 +msgid "1xx Informational" +msgstr "1xx 참고사항" + +#: src/labels.h:408 +msgid "2xx Success" +msgstr "2xx 성공" + +#: src/labels.h:410 +msgid "3xx Redirection" +msgstr "3xx 넘겨주기" + +#: src/labels.h:412 +msgid "4xx Client Errors" +msgstr "4xx 클라이언트 오류" + +#: src/labels.h:414 +msgid "5xx Server Errors" +msgstr "5xx 서버 오류" + +#: src/labels.h:417 +msgid "0 - Caddy: Unhandled - No configured routes" +msgstr "" + +#: src/labels.h:419 +msgid "100 - Continue: Server received the initial part of the request" +msgstr "" +"100 - 계속: 서버는 요청의 첫 번째 부분을 받았으며 나머지를 기다리고 있음" + +#: src/labels.h:421 +msgid "101 - Switching Protocols: Client asked to switch protocols" +msgstr "101 - 프로토콜 전환: 클라이언트가 서버에 프로토콜 전환을 요청" + +#: src/labels.h:423 +msgid "200 - OK: The request sent by the client was successful" +msgstr "200 - 성공: 요청이 제대로 처리되었음" + +#: src/labels.h:425 +msgid "201 - Created: The request has been fulfilled and created" +msgstr "201 - 작성됨: 성공적으로 요청되었으며 서버가 새 리소스를 작성함" + +#: src/labels.h:427 +msgid "202 - Accepted: The request has been accepted for processing" +msgstr "202 - 허용됨: 서버가 요청을 접수했지만 아직 처리하지 않았음" + +#: src/labels.h:429 +msgid "203 - Non-authoritative Information: Response from a third party" +msgstr "203 - 신뢰할 수 없는 정보: 제3자에게서 온 담신" + +#: src/labels.h:431 +msgid "204 - No Content: Request did not return any content" +msgstr "204 - 내용 없음: 요청이 공백의 데이터를 반환하였음" + +#: src/labels.h:433 +msgid "205 - Reset Content: Server asked the client to reset the document" +msgstr "205 - 내용 재설정: 서버가 클라이언트에게 문서를 재설정할 것을 요청함" + +#: src/labels.h:435 +msgid "206 - Partial Content: The partial GET has been successful" +msgstr "206 - 부분적 내용: GET 요청의 일부만 성공적으로 처리됨" + +#: src/labels.h:437 +msgid "207 - Multi-Status: WebDAV; RFC 4918" +msgstr "207 - 다중 상태: WebDAV; RFC 4918" + +#: src/labels.h:439 +msgid "208 - Already Reported: WebDAV; RFC 5842" +msgstr "208 - 이미 보고됨: WebDAV; RFC 5842" + +#: src/labels.h:441 +msgid "218 - This is fine: Apache servers. A catch-all error condition" +msgstr "" + +#: src/labels.h:443 +msgid "300 - Multiple Choices: Multiple options for the resource" +msgstr "300 - 여러 선택지: 리소스가 실행할 수 있는 옵션이 다수 있음" + +#: src/labels.h:445 +msgid "301 - Moved Permanently: Resource has permanently moved" +msgstr "301 - 영구 이동: 리소스가 영구적으로 이동함" + +#: src/labels.h:447 +msgid "302 - Moved Temporarily (redirect)" +msgstr "302 - 임시 이동: (넘겨주기)" + +#: src/labels.h:449 +msgid "303 - See Other Document: The response is at a different URI" +msgstr "303 - 다른 문서 조회: 답신이 다른 URI에 존재함" + +#: src/labels.h:451 +msgid "304 - Not Modified: Resource has not been modified" +msgstr "304 - 수정 안함: 리소스가 수정되지 않았음" + +#: src/labels.h:453 +msgid "305 - Use Proxy: Can only be accessed through the proxy" +msgstr "305 - 프록시 이용: 프록시를 통해서만 접근 가능" + +#: src/labels.h:455 +msgid "307 - Temporary Redirect: Resource temporarily moved" +msgstr "307 - 임시적 넘겨주기: 리소스가 임시적으로 이동함" + +#: src/labels.h:457 +msgid "308 - Permanent Redirect" +msgstr "308 - 영구적 넘겨주기" + +#: src/labels.h:459 +msgid "400 - Bad Request: The syntax of the request is invalid" +msgstr "400 - 잘못된 요청: 요청의 구문이 잘못됨" + +#: src/labels.h:461 +msgid "401 - Unauthorized: Request needs user authentication" +msgstr "401 - 권한 없음: 요청에 사용자 인증이 필요함" + +#: src/labels.h:463 +msgid "402 - Payment Required" +msgstr "402 - 결제 필요" + +#: src/labels.h:465 +msgid "403 - Forbidden: Server is refusing to respond to it" +msgstr "403 - 금지됨: 서버가 답신을 거부함" + +#: src/labels.h:467 +msgid "404 - Not Found: Requested resource could not be found" +msgstr "404 - 찾을 수 없음: 요청한 리소스가 발견되지 않음" + +#: src/labels.h:469 +msgid "405 - Method Not Allowed: Request method not supported" +msgstr "405 - 허용되지 않는 메소드: 요청의 메소드가 지원되지 않음" + +#: src/labels.h:471 +msgid "406 - Not Acceptable" +msgstr "406 - 허용되지 않음" + +#: src/labels.h:473 +msgid "407 - Proxy Authentication Required" +msgstr "407 - 프록시 인증 필요" + +#: src/labels.h:475 +msgid "408 - Request Timeout: Server timed out waiting for the request" +msgstr "408 - 요청 시간초과: 서버의 요청 대기 시간이 초과됨" + +#: src/labels.h:477 +msgid "409 - Conflict: Conflict in the request" +msgstr "409 - 충돌: 요청에 충돌 사항이 포함됨" + +#: src/labels.h:479 +msgid "410 - Gone: Resource requested is no longer available" +msgstr "410 - 사라짐: 요청한 리소스가 삭제됨" + +#: src/labels.h:481 +msgid "411 - Length Required: Invalid Content-Length" +msgstr "411 - 길이 필요: 유효하지 않은 내용의 길이" + +#: src/labels.h:483 +msgid "412 - Precondition Failed: Server does not meet preconditions" +msgstr "412 - 사전조건 실패: 요청된 사전조건을 서버가 만족시키지 않음" + +#: src/labels.h:485 +msgid "413 - Payload Too Large" +msgstr "413 - 요청의 본문이 너무 큼" + +#: src/labels.h:487 +msgid "414 - Request-URI Too Long" +msgstr "414 - 요청의 URI가 너무 긺" + +#: src/labels.h:489 +msgid "415 - Unsupported Media Type: Media type is not supported" +msgstr "415 - 지원되지 않는 미디어 유형: 미디어 유형이 지원되지 않음" + +#: src/labels.h:491 +msgid "416 - Requested Range Not Satisfiable: Cannot supply that portion" +msgstr "" +"416 - 처리할 수 없는 요청범위: 서버가 제공할 수 있는 범위를 넘어선 요청" + +#: src/labels.h:493 +msgid "417 - Expectation Failed" +msgstr "417 - 예상 실패" + +#: src/labels.h:495 +msgid "418 - I'm a teapot" +msgstr "418 - 저는 주전자인데요" + +#: src/labels.h:497 +msgid "419 - Page Expired: Laravel Framework when a CSRF Token is missing" +msgstr "" + +#: src/labels.h:499 +msgid "420 - Method Failure: Spring Framework when a method has failed" +msgstr "" + +#: src/labels.h:501 +msgid "421 - Misdirected Request" +msgstr "421 - 오도된 요청" + +#: src/labels.h:503 +msgid "422 - Unprocessable Entity due to semantic errors: WebDAV" +msgstr "422 - 구문 오류로 인해 처리할 수 없는 엔티티: WebDAV" + +#: src/labels.h:505 +msgid "423 - The resource that is being accessed is locked" +msgstr "423 - 접근하려는 리소스가 잠겨 있음" + +#: src/labels.h:507 +msgid "424 - Failed Dependency: WebDAV" +msgstr "424 - 의존사항 실패: WebDAV" + +#: src/labels.h:509 +msgid "426 - Upgrade Required: Client should switch to a different protocol" +msgstr "426 - 업그레이드 필요: 클라이언트는 다른 프로토콜을 이용해야 함" + +#: src/labels.h:511 +msgid "428 - Precondition Required" +msgstr "428 - 전제조건 필요" + +#: src/labels.h:513 +msgid "429 - Too Many Requests: The user has sent too many requests" +msgstr "429 - 요청 과다: 사용자가 너무 많은 요청을 보냄" + +#: src/labels.h:515 +msgid "" +"430 - Request Header Fields Too Large: Too many URLs are requested within a " +"certain time frame" +msgstr "" + +#: src/labels.h:517 +msgid "431 - Request Header Fields Too Large" +msgstr "431 - 요청 헤더란이 너무 큼" + +#: src/labels.h:519 +msgid "440 - Login Time-out: The client's session has expired" +msgstr "" + +#: src/labels.h:521 +#, fuzzy +msgid "449 - Retry With: The server cannot honour the request" +msgstr "408 - 요청 시간초과: 서버의 요청 대기 시간이 초과됨" + +#: src/labels.h:523 +msgid "" +"450 - Blocked by Windows Parental Controls: The Microsoft extension code " +"indicated" +msgstr "" + +#: src/labels.h:525 +msgid "451 - Unavailable For Legal Reasons" +msgstr "451 - 법적인 이유로 인해 이용 불가" + +#: src/labels.h:527 +msgid "444 - (Nginx) Connection closed without sending any headers" +msgstr "444 - (Nginx) 헤더를 보내지 않고 연결이 끊어짐" + +#: src/labels.h:529 +msgid "460 - AWS Elastic Load Balancing: Client closed the connection " +msgstr "" + +#: src/labels.h:531 +msgid "" +"463 - AWS Elastic Load Balancing: The load balancer received more than 30 IP " +"addresses" +msgstr "" + +#: src/labels.h:533 +msgid "464 - AWS Elastic Load Balancing: Incompatible protocol versions" +msgstr "" + +#: src/labels.h:535 +msgid "494 - (Nginx) Request Header Too Large" +msgstr "494 - (Nginx) 요청 헤더가 너무 큼" + +#: src/labels.h:537 +msgid "495 - (Nginx) SSL client certificate error" +msgstr "495 - (Nginx) SSL 클라이언트 인증서 오류" + +#: src/labels.h:539 +msgid "496 - (Nginx) Client didn't provide certificate" +msgstr "496 - (Nginx) 클라이언트가 인증서를 제공하지 않음" + +#: src/labels.h:541 +msgid "497 - (Nginx) HTTP request sent to HTTPS port" +msgstr "497 - (Nginx) HTTP 요청이 HTTPS 포트로 보내짐" + +#: src/labels.h:543 +msgid "498 - Invalid Token: an expired or otherwise invalid token" +msgstr "" + +#: src/labels.h:545 +msgid "499 - (Nginx) Connection closed by client while processing request" +msgstr "499 - (Nginx) 요청을 처리하는 도중 클라이언트가 연결을 해제함" + +#: src/labels.h:547 +msgid "500 - Internal Server Error" +msgstr "500 - 내부 서버 오류" + +#: src/labels.h:549 +msgid "501 - Not Implemented" +msgstr "501 - 구현되지 않음" + +#: src/labels.h:551 +msgid "502 - Bad Gateway: Received an invalid response from the upstream" +msgstr "502 - 불량 게이트웨이: 상위 서버에서 잘못된 응답을 받음" + +#: src/labels.h:553 +msgid "503 - Service Unavailable: The server is currently unavailable" +msgstr "503 - 서비스 이용 불가: 서버를 현재 이용할 수 없음" + +#: src/labels.h:555 +msgid "504 - Gateway Timeout: The upstream server failed to send request" +msgstr "504 - 게이트웨이 시간초과: 상위 서버가 요청을 보내는데 실패함" + +#: src/labels.h:557 +msgid "505 - HTTP Version Not Supported" +msgstr "505 - HTTP 버전이 지원되지 않음" + +#: src/labels.h:559 +msgid "509 - Bandwidth Limit Exceeded: The server has exceeded the bandwidth" +msgstr "" + +#: src/labels.h:561 +msgid "520 - CloudFlare - Web server is returning an unknown error" +msgstr "520 - CloudFlare - 웹서버가 알 수 없는 오류를 반환함" + +#: src/labels.h:563 +msgid "521 - CloudFlare - Web server is down" +msgstr "521 - CloudFlare - 웹서버 다운" + +#: src/labels.h:565 +msgid "522 - CloudFlare - Connection timed out" +msgstr "522 - CloudFlare - 연결 시간초과" + +#: src/labels.h:567 +msgid "523 - CloudFlare - Origin is unreachable" +msgstr "523 - CloudFlare - 요청의 근원에 도달할 수 없음" + +#: src/labels.h:569 +msgid "524 - CloudFlare - A timeout occurred" +msgstr "524 - CloudFlare - 시간초과 발생" + +#: src/labels.h:571 +msgid "" +"525 - SSL Handshake Failed: Cloudflare could not negotiate a SSL/TLS " +"handshake" +msgstr "" + +#: src/labels.h:573 +msgid "" +"526 - Invalid SSL Certificate: Cloudflare could not validate the SSL " +"certificate" +msgstr "" + +#: src/labels.h:575 +msgid "527 - Railgun Error: An interrupted connection" +msgstr "" + +#: src/labels.h:577 +msgid "529 - Site is overloaded: A site can not process the request" +msgstr "" + +#: src/labels.h:579 +msgid "530 - Site is frozen: A site has been frozen due to inactivity" +msgstr "" + +#: src/labels.h:581 +msgid "" +"540 - Temporarily Disabled: The requested endpoint has been temporarily " +"disabled" +msgstr "" + +#: src/labels.h:583 +#, fuzzy +msgid "561 - Unauthorized: An error around authentication" +msgstr "401 - 권한 없음: 요청에 사용자 인증이 필요함" + +#: src/labels.h:585 +msgid "" +"598 - Network read timeout error: some HTTP proxies to signal a network read " +"timeout" +msgstr "" + +#: src/labels.h:587 +msgid "599 - Network Connect Timeout Error: An error used by some HTTP proxies" +msgstr "" + +#: src/labels.h:589 +msgid "783 - Unexpected Token: The request includes a JSON syntax error" +msgstr "" + +#, fuzzy +#~ msgid "Referers" +#~ msgstr "참조자 수" diff --git a/po/pt_BR.po b/po/pt_BR.po new file mode 100644 index 0000000000..ff42fd56e6 --- /dev/null +++ b/po/pt_BR.po @@ -0,0 +1,1083 @@ +msgid "" +msgstr "" +"Project-Id-Version: Goaccess\n" +"Report-Msgid-Bugs-To: hello@goaccess.io\n" +"POT-Creation-Date: 2024-04-11 20:17-0500\n" +"PO-Revision-Date: 2019-04-25 20:34-0300\n" +"Last-Translator: Alan Placidina Maria \n" +"Language-Team: \n" +"Language: pt_BR\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.5.4\n" + +#: src/labels.h:45 +msgid "en" +msgstr "pt-BR" + +#: src/labels.h:48 +msgid "Exp. Panel" +msgstr "Exp. Panel" + +#: src/labels.h:49 +msgid "Help" +msgstr "Ajuda" + +#: src/labels.h:50 +msgid "Quit" +msgstr "Sair" + +#: src/labels.h:51 +msgid "Total" +msgstr "Total" + +#: src/labels.h:54 +msgid "[x] ASC [ ] DESC" +msgstr "[x] ASC [ ] DESC" + +#: src/labels.h:55 +msgid "[ ] ASC [x] DESC" +msgstr "[ ] ASC [x] DESC" + +#: src/labels.h:58 +#, c-format +msgid "[Active Panel: %1$s]" +msgstr "[Painel Ativo: %1$s]" + +#: src/labels.h:59 +msgid "[q]uit GoAccess" +msgstr "[q]Sair GoAccess" + +#: src/labels.h:60 +msgid "[?] Help [Enter] Exp. Panel" +msgstr "[?] Ajuda [Enter] Exp. Panel" + +#: src/labels.h:61 +msgid "Dashboard" +msgstr "Painel de Controle" + +#: src/labels.h:62 +msgid "Dashboard - Overall Analyzed Requests" +msgstr "Painel de Controle - Análise geral das requisições" + +#: src/labels.h:63 +msgid "Overall Analyzed Requests" +msgstr "Análise geral das requisições" + +#: src/labels.h:65 src/labels.h:86 +msgid "Tx. Amount" +msgstr "Tx. Total" + +#: src/labels.h:66 +msgid "Date/Time" +msgstr "Data/Hora" + +#: src/labels.h:67 +msgid "Excl. IP Hits" +msgstr "Accesos IP Excl." + +#: src/labels.h:68 +msgid "Failed Requests" +msgstr "Req. Inválidas" + +#: src/labels.h:69 +msgid "Log Parsing Time" +msgstr "" + +#: src/labels.h:70 +msgid "Log Size" +msgstr "Tamanho do Log" + +#: src/labels.h:71 +msgid "Log Source" +msgstr "Origem do Log" + +#: src/labels.h:72 src/labels.h:187 +msgid "Referrers" +msgstr "Referenciadores" + +#: src/labels.h:73 +msgid "Total Requests" +msgstr "Requisições" + +#: src/labels.h:74 +msgid "Static Files" +msgstr "Arquivos Estáticos" + +#: src/labels.h:75 src/labels.h:159 +msgid "Not Found" +msgstr "Não Encontrado" + +#: src/labels.h:76 +msgid "Requested Files" +msgstr "Req. Arquivos" + +#: src/labels.h:77 +msgid "Unique Visitors" +msgstr "Visitantes Únicos" + +#: src/labels.h:78 +msgid "Valid Requests" +msgstr "Req. Válidas" + +#: src/labels.h:81 +msgid "Hits" +msgstr "Requisições" + +#: src/labels.h:82 +msgid "h%" +msgstr "h%" + +#: src/labels.h:83 src/labels.h:110 +msgid "Visitors" +msgstr "Visitantes" + +#: src/labels.h:84 +msgid "Vis." +msgstr "Vis." + +#: src/labels.h:85 +msgid "v%" +msgstr "v%" + +#: src/labels.h:87 +msgid "Avg. T.S." +msgstr "Méd. T.S." + +#: src/labels.h:88 +msgid "Cum. T.S." +msgstr "Cum. T.S." + +#: src/labels.h:89 +msgid "Max. T.S." +msgstr "Máx. T.S." + +#: src/labels.h:90 +msgid "Method" +msgstr "Método" + +#: src/labels.h:91 +msgid "Mtd" +msgstr "Mtd" + +#: src/labels.h:92 +msgid "Protocol" +msgstr "Protocolo" + +#: src/labels.h:93 +msgid "Proto" +msgstr "Proto" + +#: src/labels.h:94 +msgid "City" +msgstr "Cidade" + +#: src/labels.h:95 src/labels.h:211 src/labels.h:215 +msgid "ASN" +msgstr "" + +#: src/labels.h:96 +msgid "Country" +msgstr "Pais" + +#: src/labels.h:97 +msgid "Hostname" +msgstr "Hostname" + +#: src/labels.h:98 +msgid "Data" +msgstr "Dados" + +#: src/labels.h:100 +msgid "Hits/Visitors" +msgstr "Requisições/Visitas" + +#: src/labels.h:104 +msgid "Unique visitors per day" +msgstr "Visitantes únicos por dia" + +#: src/labels.h:106 +msgid "Unique visitors per day - Including spiders" +msgstr "Visitantes únicos por dia" + +#: src/labels.h:108 +msgid "Hits having the same IP, date and agent are a unique visit." +msgstr "Requisições com o mesmo IP, data e agente são uma visita única." + +#: src/labels.h:113 +msgid "Requested Files (URLs)" +msgstr "Requisições" + +#: src/labels.h:115 +msgid "Top requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Requisições ordenadas por requisições [, avgts, cumts, maxts, mthd, proto]" + +#: src/labels.h:117 +msgid "Requests" +msgstr "Requisições" + +#: src/labels.h:120 src/labels.h:124 +msgid "Static Requests" +msgstr "Requisições Estáticas" + +#: src/labels.h:122 +msgid "Top static requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Requisições estáticas ordenadas por requisições [, avgts, cumts, maxts, " +"mthd, proto]" + +#: src/labels.h:127 +msgid "Time Distribution" +msgstr "Requisições Por Hora" + +#: src/labels.h:129 +msgid "Data sorted by hour [, avgts, cumts, maxts]" +msgstr "Dados ordenados por hora [, avgts, cumts, maxts]" + +#: src/labels.h:131 +msgid "Time" +msgstr "Hora" + +#: src/labels.h:134 src/labels.h:138 +msgid "Virtual Hosts" +msgstr "Hosts Virtuais" + +#: src/labels.h:136 src/labels.h:143 src/labels.h:150 +msgid "Data sorted by hits [, avgts, cumts, maxts]" +msgstr "Dados ordenados por requisições [, avgts, cumts, maxts]" + +#: src/labels.h:141 +msgid "Remote User (HTTP authentication)" +msgstr "Usuário Remoto (Autenticação HTTP)" + +#: src/labels.h:145 +msgid "Remote User" +msgstr "Usuário Remoto" + +#: src/labels.h:148 +msgid "The cache status of the object served" +msgstr "" + +#: src/labels.h:152 +msgid "Cache Status" +msgstr "" + +#: src/labels.h:155 +msgid "Not Found URLs (404s)" +msgstr "URLs Não Encontradas (404)" + +#: src/labels.h:157 +msgid "Top not found URLs sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"URLs não encontradas ordenadas por requisições [, avgts, cumts, maxts, mthd, " +"proto]" + +#: src/labels.h:162 +msgid "Visitor Hostnames and IPs" +msgstr "Endereços IPv4" + +#: src/labels.h:164 +msgid "Top visitor hosts sorted by hits [, avgts, cumts, maxts]" +msgstr "Hosts de visitantes ordenados por requisições [, avgts, cumts, maxts]" + +#: src/labels.h:166 +msgid "Hosts" +msgstr "Hosts" + +#: src/labels.h:169 +msgid "Operating Systems" +msgstr "Sistemas Operacionais" + +#: src/labels.h:171 +msgid "Top Operating Systems sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Sistemas Operacionais ordenados por requisições [, avgts, cumts, maxts]" + +#: src/labels.h:173 +msgid "OS" +msgstr "SO" + +#: src/labels.h:176 src/labels.h:180 +msgid "Browsers" +msgstr "Navegadores" + +#: src/labels.h:178 +msgid "Top Browsers sorted by hits [, avgts, cumts, maxts]" +msgstr "Navegadores ordenados por requisições [, avgts, cumts, maxts]" + +#: src/labels.h:183 +#, fuzzy +msgid "Referrer URLs" +msgstr "URLs Referenciadas" + +#: src/labels.h:185 +#, fuzzy +msgid "Top Requested Referrers sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Requisições referenciadas ordenadas por requisições [, avgts, cumts, maxts]" + +#: src/labels.h:190 src/labels.h:194 +msgid "Referring Sites" +msgstr "Sites Referenciados" + +#: src/labels.h:192 +msgid "Top Referring Sites sorted by hits [, avgts, cumts, maxts]" +msgstr "Sites referenciados ordenados por requisições [, avgts, cumts, maxts]" + +#: src/labels.h:197 +msgid "Keyphrases from Google's search engine" +msgstr "Mecanismo de pesquisa do Google" + +#: src/labels.h:199 +msgid "Top Keyphrases sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Frases-chave de busca ordenadas por requisições [, avgts, cumts, maxts]" + +#: src/labels.h:201 +msgid "Keyphrases" +msgstr "Frases-chave" + +#: src/labels.h:204 src/labels.h:208 +msgid "Geo Location" +msgstr "Geo Localização" + +#: src/labels.h:206 +msgid "Continent > Country sorted by unique hits [, avgts, cumts, maxts]" +msgstr "" +"Continente/Pais ordenado por requisições únicas [, avgts, cumts, maxts]" + +#: src/labels.h:213 +msgid "Autonomous System Numbers/Organizations (ASNs)" +msgstr "" + +#: src/labels.h:218 +msgid "HTTP Status Codes" +msgstr "Codigos de Status HTTP" + +#: src/labels.h:220 +msgid "Top HTTP Status Codes sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Codigos de Status HTTP ordenados por requisições [, avgts, cumts, maxts]" + +#: src/labels.h:222 +msgid "Status Codes" +msgstr "Codigos de Status" + +#: src/labels.h:225 src/labels.h:229 +msgid "MIME Types" +msgstr "" + +#: src/labels.h:227 +msgid "File types shipped out" +msgstr "" + +#: src/labels.h:232 +msgid "Encryption settings" +msgstr "" + +#: src/labels.h:234 +msgid "TLS version and picked algorithm" +msgstr "" + +#: src/labels.h:236 +msgid "TLS Settings" +msgstr "" + +#: src/labels.h:240 +msgid "[ ] case sensitive" +msgstr "[ ] distinguir maiúsculas" + +#: src/labels.h:242 +msgid "[x] case sensitive" +msgstr "[x] distinguir maiúsculas" + +#: src/labels.h:244 +msgid "Regex allowed - ^g to cancel - TAB switch case" +msgstr "Regex Permitidos - ^g para cancelar - TAB mudar caso" + +#: src/labels.h:246 +msgid "Find pattern in all views" +msgstr "Encontrar padrão em todas as vistas" + +#: src/labels.h:250 +msgid "Log Format Configuration" +msgstr "Configuração do Formato de Log" + +#: src/labels.h:252 +msgid "[SPACE] to toggle - [ENTER] to proceed - [q] to quit" +msgstr "[SPACE] para alternar - [ENTER] para prosseguir - [q] para sair" + +#: src/labels.h:254 +msgid "Log Format - [c] to add/edit format" +msgstr "Formato de Log - [c] para adicionar/editar formato" + +#: src/labels.h:256 +msgid "Date Format - [d] to add/edit format" +msgstr "Formato da Data - [d] para adicionar/editar formato" + +#: src/labels.h:258 +msgid "Time Format - [t] to add/edit format" +msgstr "Formato da Hora - [t] para adicionar/editar formato" + +#: src/labels.h:260 src/labels.h:264 +msgid "[UP/DOWN] to scroll - [q] to close window" +msgstr "[UP/DOWN] para rolar - [q] para fechar a janela" + +#: src/labels.h:266 +#, c-format +msgid "User Agents for %1$s" +msgstr "Agentes de Usuário para %1$s" + +#: src/labels.h:270 +msgid "Scheme Configuration" +msgstr "Configuração de Esquema" + +#: src/labels.h:272 +msgid "[ENTER] to use scheme - [q]uit" +msgstr "[ENTER] para usar esquema - [q]Sair" + +#: src/labels.h:276 +msgid "Sort active module by" +msgstr "Ordenar modulo ativo por" + +#: src/labels.h:278 +msgid "[ENTER] select - [TAB] sort - [q]uit" +msgstr "[ENTER] selecionar - [TAB] ordenar - [q]Sair" + +#: src/labels.h:282 +msgid "GoAccess Quick Help" +msgstr "Ajuda Rápida de GoAccess" + +#: src/labels.h:284 +msgid "[UP/DOWN] to scroll - [q] to quit" +msgstr "[UP/DOWN] para rolar - [q] para sair" + +#: src/labels.h:288 +msgid "In-Memory with On-Disk Persistent Storage." +msgstr "" + +#: src/labels.h:292 +msgid "Format Errors - Verify your log/date/time format" +msgstr "Formato de Erros - Verifique seu formato de log/data/hora" + +#: src/labels.h:294 +msgid "No date format was found on your conf file." +msgstr "Nenhum formato de data encontrado no seu arquivo de configuração" + +#: src/labels.h:296 +msgid "No log format was found on your conf file." +msgstr "Nenhum formato de log encontrado no seu arquivo de configuração" + +#: src/labels.h:298 +msgid "No time format was found on your conf file." +msgstr "Formato de hora não foi encontrado no seu arquivo de configuração" + +#: src/labels.h:300 +msgid "No default config file found." +msgstr "Nenhum arquivo de configuração padrão foi encontrado." + +#: src/labels.h:302 +msgid "You may specify one with" +msgstr "Você pode especificar uma largura" + +#: src/labels.h:304 +msgid "producing the following errors" +msgstr "produzindo os seguintes erros" + +#: src/labels.h:306 +#, c-format +msgid "Parsed %1$d lines" +msgstr "Analizadas %1$d linhas" + +#: src/labels.h:308 +msgid "Please report it by opening an issue on GitHub" +msgstr "Por favor, informe abrindo um problema no GitHub" + +#: src/labels.h:310 +msgid "Select a time format." +msgstr "Selecione um formato de hora." + +#: src/labels.h:312 +msgid "Select a date format." +msgstr "Selecione um formato de data." + +#: src/labels.h:314 +msgid "Select a log format." +msgstr "Selecione um formato de log." + +#: src/labels.h:316 +#, c-format +msgid "'%1$s' panel is disabled" +msgstr "'%1$s' painel está desativado" + +#: src/labels.h:318 +msgid "No input data was provided nor there's data to restore." +msgstr "" + +#: src/labels.h:320 +msgid "Unable to allocate memory for a log instance." +msgstr "" + +#: src/labels.h:322 +msgid "Unable to find the given log." +msgstr "" + +#: src/labels.h:326 +msgid "For more details visit" +msgstr "Para mais detalhes visite" + +#: src/labels.h:328 +msgid "Last Updated" +msgstr "Última atualização" + +#: src/labels.h:330 +msgid "WebSocket server ready to accept new client connections" +msgstr "Servidor WebSocket pronto para aceitar novas conexões de clientes" + +#: src/labels.h:333 +msgid "The following options can also be supplied to the command" +msgstr "As seguintes opções também podem ser fornecidas para o comando" + +#: src/labels.h:335 +msgid "Examples can be found by running" +msgstr "Exemplos podem ser encontrados executando" + +#: src/labels.h:338 +msgid "Server Statistics" +msgstr "Estatísticas do servidor" + +#: src/labels.h:340 +msgid "Theme" +msgstr "Tema" + +#: src/labels.h:342 +msgid "Dark Gray" +msgstr "Cinza Escuro" + +#: src/labels.h:344 +msgid "Bright" +msgstr "Claro" + +#: src/labels.h:346 +msgid "Dark Blue" +msgstr "Azul Escuro" + +#: src/labels.h:348 +#, fuzzy +msgid "Dark Purple" +msgstr "Roxo Escuro" + +#: src/labels.h:350 +msgid "Panels" +msgstr "Painéis" + +#: src/labels.h:352 +msgid "Items per Page" +msgstr "Itens por página" + +#: src/labels.h:354 +msgid "Tables" +msgstr "Tabelas" + +#: src/labels.h:356 +msgid "Display Tables" +msgstr "Mostrar Tabelas" + +#: src/labels.h:358 +msgid "Auto-Hide on Small Devices" +msgstr "Ocultar em Dispositivos Pequenos" + +#: src/labels.h:360 +msgid "Automatically hide tables on small screen devices" +msgstr "Ocultar tabelas em dispositivos pequenos" + +#: src/labels.h:362 +msgid "Toggle Panel" +msgstr "" + +#: src/labels.h:364 +msgid "Layout" +msgstr "Layout" + +#: src/labels.h:366 +msgid "Horizontal" +msgstr "Horizontal" + +#: src/labels.h:368 +msgid "Vertical" +msgstr "Vertical" + +#: src/labels.h:370 +msgid "WideScreen" +msgstr "" + +#: src/labels.h:372 +msgid "File Options" +msgstr "Opções de Arquivo" + +#: src/labels.h:374 +msgid "Export as JSON" +msgstr "Exportar como JSON" + +#: src/labels.h:376 +msgid "Panel Options" +msgstr "Opções do Painel" + +#: src/labels.h:378 +msgid "Previous" +msgstr "Anterior" + +#: src/labels.h:380 +msgid "Next" +msgstr "Próximo" + +#: src/labels.h:382 +msgid "First" +msgstr "Primeiro" + +#: src/labels.h:384 +msgid "Last" +msgstr "Último" + +#: src/labels.h:386 +msgid "Chart Options" +msgstr "Opções de Gráfico" + +#: src/labels.h:388 +msgid "Chart" +msgstr "Gráfico" + +#: src/labels.h:390 +msgid "Type" +msgstr "Tipo" + +#: src/labels.h:392 +msgid "Area Spline" +msgstr "Área Spline" + +#: src/labels.h:394 +msgid "Bar" +msgstr "Barra" + +#: src/labels.h:396 +msgid "World Map" +msgstr "" + +#: src/labels.h:398 +msgid "Plot Metric" +msgstr "Métrica de Plotagem" + +#: src/labels.h:400 +msgid "Table Columns" +msgstr "Colunas da Tabela" + +#: src/labels.h:404 +msgid "0xx Unofficial Codes" +msgstr "" + +#: src/labels.h:406 +msgid "1xx Informational" +msgstr "1xx Informativo" + +#: src/labels.h:408 +msgid "2xx Success" +msgstr "2xx Exito" + +#: src/labels.h:410 +msgid "3xx Redirection" +msgstr "3xx Redirecionamento" + +#: src/labels.h:412 +msgid "4xx Client Errors" +msgstr "4xx Erros do cliente" + +#: src/labels.h:414 +msgid "5xx Server Errors" +msgstr "5xx Erros do servidor" + +#: src/labels.h:417 +msgid "0 - Caddy: Unhandled - No configured routes" +msgstr "" + +#: src/labels.h:419 +msgid "100 - Continue: Server received the initial part of the request" +msgstr "100 - Continuar: o servidor recebeu a parte inicial da requisição" + +#: src/labels.h:421 +msgid "101 - Switching Protocols: Client asked to switch protocols" +msgstr "101 - Protocolos de comutação: cliente pediu para alternar protocolos" + +#: src/labels.h:423 +msgid "200 - OK: The request sent by the client was successful" +msgstr "200 - OK: A requisição feita pelo cliente foi bem-sucedida" + +#: src/labels.h:425 +msgid "201 - Created: The request has been fulfilled and created" +msgstr "201 - Criado: A requisição foi concluída e criada" + +#: src/labels.h:427 +msgid "202 - Accepted: The request has been accepted for processing" +msgstr "202 - Aceito: A requisição foi aceita para processar" + +#: src/labels.h:429 +msgid "203 - Non-authoritative Information: Response from a third party" +msgstr "203 - Informações não autorizadas: resposta de terceiros" + +#: src/labels.h:431 +msgid "204 - No Content: Request did not return any content" +msgstr "204 - Nenhum conteúdo: A requisição não retornou nenhum conteúdo" + +#: src/labels.h:433 +msgid "205 - Reset Content: Server asked the client to reset the document" +msgstr "" +"205 - Redefinir conteúdo: O servidor pediu ao cliente para redefinir o " +"documento" + +#: src/labels.h:435 +msgid "206 - Partial Content: The partial GET has been successful" +msgstr "206 - Conteúdo Parcial: O GET parcial foi bem-sucedido" + +#: src/labels.h:437 +msgid "207 - Multi-Status: WebDAV; RFC 4918" +msgstr "207 - Mútiplos-Status: WebDAV; RFC 4918" + +#: src/labels.h:439 +msgid "208 - Already Reported: WebDAV; RFC 5842" +msgstr "208 - Já Relatado: WebDAV; RFC 5842" + +#: src/labels.h:441 +msgid "218 - This is fine: Apache servers. A catch-all error condition" +msgstr "" + +#: src/labels.h:443 +msgid "300 - Multiple Choices: Multiple options for the resource" +msgstr "300 - Múltiplas Opções: Múltiplas alternativas para o recurso" + +#: src/labels.h:445 +msgid "301 - Moved Permanently: Resource has permanently moved" +msgstr "301 - Movido Permanentemente: Recurso foi movido permanentemente" + +#: src/labels.h:447 +msgid "302 - Moved Temporarily (redirect)" +msgstr "302 - Movido Temporariamente (redirecionar)" + +#: src/labels.h:449 +msgid "303 - See Other Document: The response is at a different URI" +msgstr "303 - Consulte Outro Documento: A resposta está em uma URI diferente" + +#: src/labels.h:451 +msgid "304 - Not Modified: Resource has not been modified" +msgstr "304 - Não Modificado: O recurso não foi modificado" + +#: src/labels.h:453 +msgid "305 - Use Proxy: Can only be accessed through the proxy" +msgstr "305 - Usar Proxy: Só pode ser acessado através do proxy" + +#: src/labels.h:455 +msgid "307 - Temporary Redirect: Resource temporarily moved" +msgstr "307 - Redirecionamento Temporário: Recurso temporariamente movido" + +#: src/labels.h:457 +#, fuzzy +msgid "308 - Permanent Redirect" +msgstr "402 - Pagamento Exigido" + +#: src/labels.h:459 +msgid "400 - Bad Request: The syntax of the request is invalid" +msgstr "400 - Solicitação Incorreta: A sintaxe da solicitação é inválida" + +#: src/labels.h:461 +msgid "401 - Unauthorized: Request needs user authentication" +msgstr "401 - Não Autorizado: Solicitação precisa de autenticação de usuário" + +#: src/labels.h:463 +msgid "402 - Payment Required" +msgstr "402 - Pagamento Exigido" + +#: src/labels.h:465 +msgid "403 - Forbidden: Server is refusing to respond to it" +msgstr "403 - Proibido: Servidor está se recusando a responder" + +#: src/labels.h:467 +msgid "404 - Not Found: Requested resource could not be found" +msgstr "404 - Não Encontrado: Recurso solicitado não pôde ser encontrado" + +#: src/labels.h:469 +msgid "405 - Method Not Allowed: Request method not supported" +msgstr "405 - Método Não Permitido: Método de solicitação não suportado" + +#: src/labels.h:471 +msgid "406 - Not Acceptable" +msgstr "406 - Não Aceitável" + +#: src/labels.h:473 +msgid "407 - Proxy Authentication Required" +msgstr "407 - Autenticação de Proxy Necessária" + +#: src/labels.h:475 +msgid "408 - Request Timeout: Server timed out waiting for the request" +msgstr "" +"408 - Tempo Limite da Solicitação: O servidor expirou aguardando a " +"solicitação" + +#: src/labels.h:477 +msgid "409 - Conflict: Conflict in the request" +msgstr "409 - Conflito: Conflito no pedido" + +#: src/labels.h:479 +msgid "410 - Gone: Resource requested is no longer available" +msgstr "410 - Foi: Recurso solicitado não está mais disponível" + +#: src/labels.h:481 +msgid "411 - Length Required: Invalid Content-Length" +msgstr "411 - Comprimento Necessário: Comprimento de conteúdo inválido" + +#: src/labels.h:483 +msgid "412 - Precondition Failed: Server does not meet preconditions" +msgstr "" +"412 - Falha na Pré-Condição: O servidor não atende às condições prévias" + +#: src/labels.h:485 +msgid "413 - Payload Too Large" +msgstr "413 - Payload Muito Grande" + +#: src/labels.h:487 +msgid "414 - Request-URI Too Long" +msgstr "414 - Requisição-URI muito longa" + +#: src/labels.h:489 +msgid "415 - Unsupported Media Type: Media type is not supported" +msgstr "415 - Tipo de Mídia Sem Suporte: Tipo de mídia não é suportado" + +#: src/labels.h:491 +msgid "416 - Requested Range Not Satisfiable: Cannot supply that portion" +msgstr "" +"416 - Intervalo da Requisição Não Satisfatório: Não é possível fornecer essa " +"parte" + +#: src/labels.h:493 +msgid "417 - Expectation Failed" +msgstr "417 - Falha na Expectativa" + +#: src/labels.h:495 +msgid "418 - I'm a teapot" +msgstr "" + +#: src/labels.h:497 +msgid "419 - Page Expired: Laravel Framework when a CSRF Token is missing" +msgstr "" + +#: src/labels.h:499 +msgid "420 - Method Failure: Spring Framework when a method has failed" +msgstr "" + +#: src/labels.h:501 +msgid "421 - Misdirected Request" +msgstr "421 - Requisição Misdirected" + +#: src/labels.h:503 +msgid "422 - Unprocessable Entity due to semantic errors: WebDAV" +msgstr "422 - Entidade Não Processável devido a erros semânticos: WebDAV" + +#: src/labels.h:505 +msgid "423 - The resource that is being accessed is locked" +msgstr "423 - O recurso que está sendo acessado está bloqueado" + +#: src/labels.h:507 +msgid "424 - Failed Dependency: WebDAV" +msgstr "424 - Falha na Dependência: WebDAV" + +#: src/labels.h:509 +msgid "426 - Upgrade Required: Client should switch to a different protocol" +msgstr "" +"426 - Atualização Necessária: O cliente deve alternar para um protocolo " +"diferente" + +#: src/labels.h:511 +#, fuzzy +msgid "428 - Precondition Required" +msgstr "428 - Pré-Requisito Obrigatório" + +#: src/labels.h:513 +msgid "429 - Too Many Requests: The user has sent too many requests" +msgstr "" +"429 - Requisições Demasiadas: O utilizador enviou requisições demasiadamente" + +#: src/labels.h:515 +msgid "" +"430 - Request Header Fields Too Large: Too many URLs are requested within a " +"certain time frame" +msgstr "" + +#: src/labels.h:517 +#, fuzzy +msgid "431 - Request Header Fields Too Large" +msgstr "431 - Campos de Cabeçalho de requisição muito grande" + +#: src/labels.h:519 +msgid "440 - Login Time-out: The client's session has expired" +msgstr "" + +#: src/labels.h:521 +#, fuzzy +msgid "449 - Retry With: The server cannot honour the request" +msgstr "" +"408 - Tempo Limite da Solicitação: O servidor expirou aguardando a " +"solicitação" + +#: src/labels.h:523 +msgid "" +"450 - Blocked by Windows Parental Controls: The Microsoft extension code " +"indicated" +msgstr "" + +#: src/labels.h:525 +msgid "451 - Unavailable For Legal Reasons" +msgstr "451 - Indisponível Por Razões Legais" + +#: src/labels.h:527 +msgid "444 - (Nginx) Connection closed without sending any headers" +msgstr "444 - (Nginx) Conexão fechada sem enviar cabeçalhos" + +#: src/labels.h:529 +msgid "460 - AWS Elastic Load Balancing: Client closed the connection " +msgstr "" + +#: src/labels.h:531 +msgid "" +"463 - AWS Elastic Load Balancing: The load balancer received more than 30 IP " +"addresses" +msgstr "" + +#: src/labels.h:533 +msgid "464 - AWS Elastic Load Balancing: Incompatible protocol versions" +msgstr "" + +#: src/labels.h:535 +msgid "494 - (Nginx) Request Header Too Large" +msgstr "494 - (Nginx) Cabeçalho da Requisição Muito Grande" + +#: src/labels.h:537 +msgid "495 - (Nginx) SSL client certificate error" +msgstr "495 - (Nginx) Erro de certificado de cliente SSL" + +#: src/labels.h:539 +msgid "496 - (Nginx) Client didn't provide certificate" +msgstr "496 - (Nginx) O cliente não forneceu certificado" + +#: src/labels.h:541 +msgid "497 - (Nginx) HTTP request sent to HTTPS port" +msgstr "497 - (Nginx) Requisição HTTP enviada para a porta HTTPS" + +#: src/labels.h:543 +msgid "498 - Invalid Token: an expired or otherwise invalid token" +msgstr "" + +#: src/labels.h:545 +msgid "499 - (Nginx) Connection closed by client while processing request" +msgstr "" +"499 - (Nginx) Conexão fechada pelo cliente durante o processamento da " +"requisição" + +#: src/labels.h:547 +msgid "500 - Internal Server Error" +msgstr "500 - Error Interno do Servidor" + +#: src/labels.h:549 +msgid "501 - Not Implemented" +msgstr "501 - Não Implementado" + +#: src/labels.h:551 +msgid "502 - Bad Gateway: Received an invalid response from the upstream" +msgstr "502 - Gateway Inválido: Recebeu uma resposta inválida do upstream" + +#: src/labels.h:553 +msgid "503 - Service Unavailable: The server is currently unavailable" +msgstr "503 - Serviço Indisponível: O servidor está indisponível no momento" + +#: src/labels.h:555 +msgid "504 - Gateway Timeout: The upstream server failed to send request" +msgstr "504 - Gateway timeout: O servidor upstream falhou ao enviar pedido" + +#: src/labels.h:557 +msgid "505 - HTTP Version Not Supported" +msgstr "505 - Versão HTTP Não Suportada" + +#: src/labels.h:559 +msgid "509 - Bandwidth Limit Exceeded: The server has exceeded the bandwidth" +msgstr "" + +#: src/labels.h:561 +msgid "520 - CloudFlare - Web server is returning an unknown error" +msgstr "520 - CloudFlare - Servidor Web está retornando um erro desconhecido" + +#: src/labels.h:563 +msgid "521 - CloudFlare - Web server is down" +msgstr "521 - CloudFlare - Servidor Web está offline" + +#: src/labels.h:565 +msgid "522 - CloudFlare - Connection timed out" +msgstr "522 - CloudFlare - A conexão expirou" + +#: src/labels.h:567 +msgid "523 - CloudFlare - Origin is unreachable" +msgstr "523 - CloudFlare - A origem está inacessível" + +#: src/labels.h:569 +msgid "524 - CloudFlare - A timeout occurred" +msgstr "524 - CloudFlare - Ocorreu tempo limite" + +#: src/labels.h:571 +msgid "" +"525 - SSL Handshake Failed: Cloudflare could not negotiate a SSL/TLS " +"handshake" +msgstr "" + +#: src/labels.h:573 +msgid "" +"526 - Invalid SSL Certificate: Cloudflare could not validate the SSL " +"certificate" +msgstr "" + +#: src/labels.h:575 +msgid "527 - Railgun Error: An interrupted connection" +msgstr "" + +#: src/labels.h:577 +msgid "529 - Site is overloaded: A site can not process the request" +msgstr "" + +#: src/labels.h:579 +msgid "530 - Site is frozen: A site has been frozen due to inactivity" +msgstr "" + +#: src/labels.h:581 +msgid "" +"540 - Temporarily Disabled: The requested endpoint has been temporarily " +"disabled" +msgstr "" + +#: src/labels.h:583 +#, fuzzy +msgid "561 - Unauthorized: An error around authentication" +msgstr "401 - Não Autorizado: Solicitação precisa de autenticação de usuário" + +#: src/labels.h:585 +msgid "" +"598 - Network read timeout error: some HTTP proxies to signal a network read " +"timeout" +msgstr "" + +#: src/labels.h:587 +msgid "599 - Network Connect Timeout Error: An error used by some HTTP proxies" +msgstr "" + +#: src/labels.h:589 +msgid "783 - Unexpected Token: The request includes a JSON syntax error" +msgstr "" + +#, fuzzy +#~ msgid "Referers" +#~ msgstr "Referenciadores" diff --git a/po/ru.po b/po/ru.po new file mode 100644 index 0000000000..4998cd7c0d --- /dev/null +++ b/po/ru.po @@ -0,0 +1,1084 @@ +msgid "" +msgstr "" +"Project-Id-Version: goaccess 1.5.6\n" +"Report-Msgid-Bugs-To: hello@goaccess.io\n" +"POT-Creation-Date: 2024-04-11 20:17-0500\n" +"PO-Revision-Date: 2022-04-21 10:17+0300\n" +"Last-Translator: Artyom Karlov \n" +"Language-Team: \n" +"Language: ru\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.3.1\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && " +"n%10<=4 && (n%100<12 || n%100>14) ? 1 : 2);\n" + +#: src/labels.h:45 +msgid "en" +msgstr "ru" + +#: src/labels.h:48 +msgid "Exp. Panel" +msgstr "Разв. панель" + +#: src/labels.h:49 +msgid "Help" +msgstr "Помощь" + +#: src/labels.h:50 +msgid "Quit" +msgstr "Выход" + +#: src/labels.h:51 +msgid "Total" +msgstr "Всего" + +#: src/labels.h:54 +msgid "[x] ASC [ ] DESC" +msgstr "[x] ВОЗР [ ] УБЫВ" + +#: src/labels.h:55 +msgid "[ ] ASC [x] DESC" +msgstr "[ ] ВОЗР [x] УБЫВ" + +#: src/labels.h:58 +#, c-format +msgid "[Active Panel: %1$s]" +msgstr "[Активная панель: %1$s]" + +#: src/labels.h:59 +msgid "[q]uit GoAccess" +msgstr "[q] Выйти из GoAccess" + +#: src/labels.h:60 +msgid "[?] Help [Enter] Exp. Panel" +msgstr "[?] Помощь [Enter] Разв. панель" + +#: src/labels.h:61 +msgid "Dashboard" +msgstr "Дашборд" + +#: src/labels.h:62 +msgid "Dashboard - Overall Analyzed Requests" +msgstr "Дашборд - Проанализированные запросы" + +#: src/labels.h:63 +msgid "Overall Analyzed Requests" +msgstr "Проанализированные запросы" + +#: src/labels.h:65 src/labels.h:86 +msgid "Tx. Amount" +msgstr "Исх. трафик" + +#: src/labels.h:66 +msgid "Date/Time" +msgstr "Дата/время" + +#: src/labels.h:67 +msgid "Excl. IP Hits" +msgstr "Хитов с искл. IP" + +#: src/labels.h:68 +msgid "Failed Requests" +msgstr "Неудачных запросов" + +#: src/labels.h:69 +msgid "Log Parsing Time" +msgstr "Время парсинга лога" + +#: src/labels.h:70 +msgid "Log Size" +msgstr "Размер лога" + +#: src/labels.h:71 +msgid "Log Source" +msgstr "Источник лога" + +#: src/labels.h:72 src/labels.h:187 +msgid "Referrers" +msgstr "Ссыл. страниц" + +#: src/labels.h:73 +msgid "Total Requests" +msgstr "Всего запросов" + +#: src/labels.h:74 +msgid "Static Files" +msgstr "Статических файлов" + +#: src/labels.h:75 src/labels.h:159 +msgid "Not Found" +msgstr "Не найдено" + +#: src/labels.h:76 +msgid "Requested Files" +msgstr "Запрошенных файлов" + +#: src/labels.h:77 +msgid "Unique Visitors" +msgstr "Уникальных посетителей" + +#: src/labels.h:78 +msgid "Valid Requests" +msgstr "Валидных запросов" + +#: src/labels.h:81 +msgid "Hits" +msgstr "Хиты" + +#: src/labels.h:82 +msgid "h%" +msgstr "х%" + +#: src/labels.h:83 src/labels.h:110 +msgid "Visitors" +msgstr "Посетители" + +#: src/labels.h:84 +msgid "Vis." +msgstr "Пос." + +#: src/labels.h:85 +msgid "v%" +msgstr "п%" + +#: src/labels.h:87 +msgid "Avg. T.S." +msgstr "Ср. в. о." + +#: src/labels.h:88 +msgid "Cum. T.S." +msgstr "Общ. в.о." + +#: src/labels.h:89 +msgid "Max. T.S." +msgstr "Макс. в.о." + +#: src/labels.h:90 +msgid "Method" +msgstr "Метод" + +#: src/labels.h:91 +msgid "Mtd" +msgstr "Мтд" + +#: src/labels.h:92 +msgid "Protocol" +msgstr "Протокол" + +#: src/labels.h:93 +msgid "Proto" +msgstr "Прот." + +#: src/labels.h:94 +msgid "City" +msgstr "Город" + +#: src/labels.h:95 src/labels.h:211 src/labels.h:215 +msgid "ASN" +msgstr "" + +#: src/labels.h:96 +msgid "Country" +msgstr "Страна" + +#: src/labels.h:97 +msgid "Hostname" +msgstr "Имя хоста" + +#: src/labels.h:98 +msgid "Data" +msgstr "Данные" + +#: src/labels.h:100 +msgid "Hits/Visitors" +msgstr "Хиты/посетители" + +#: src/labels.h:104 +msgid "Unique visitors per day" +msgstr "Уникальные посетители по дням" + +#: src/labels.h:106 +msgid "Unique visitors per day - Including spiders" +msgstr "Уникальные посетители по дням - Включая пауков" + +#: src/labels.h:108 +msgid "Hits having the same IP, date and agent are a unique visit." +msgstr "" +"Хиты, имеющие одинаковые IP, дату и юзер-агента, считаются уникальным " +"посещением." + +#: src/labels.h:113 +msgid "Requested Files (URLs)" +msgstr "Запрошенные файлы (URL'ы)" + +#: src/labels.h:115 +msgid "Top requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Топ запросов, отсортированных по хитам [, ср., общ, макс. вр. обсл., методу, " +"протоколу]" + +#: src/labels.h:117 +msgid "Requests" +msgstr "Запросы" + +#: src/labels.h:120 src/labels.h:124 +msgid "Static Requests" +msgstr "Статические запросы" + +#: src/labels.h:122 +msgid "Top static requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Топ статических запросов, отсортированных по хитам [, ср., общ, макс. вр. " +"обсл., методу, протоколу]" + +#: src/labels.h:127 +msgid "Time Distribution" +msgstr "Распределение по времени" + +#: src/labels.h:129 +msgid "Data sorted by hour [, avgts, cumts, maxts]" +msgstr "Данные, отсортированные по часам [, ср., общ, макс. вр. обсл.]" + +#: src/labels.h:131 +msgid "Time" +msgstr "Время" + +#: src/labels.h:134 src/labels.h:138 +msgid "Virtual Hosts" +msgstr "Виртуальные хосты" + +#: src/labels.h:136 src/labels.h:143 src/labels.h:150 +msgid "Data sorted by hits [, avgts, cumts, maxts]" +msgstr "Данные, отсортированные по хитам [, ср., общ, макс. вр. обсл.]" + +#: src/labels.h:141 +msgid "Remote User (HTTP authentication)" +msgstr "Удалённый пользователь (HTTP-аутентификация)" + +#: src/labels.h:145 +msgid "Remote User" +msgstr "Удалённый пользователь" + +#: src/labels.h:148 +msgid "The cache status of the object served" +msgstr "Статус кеша обслуживаемого объекта" + +#: src/labels.h:152 +msgid "Cache Status" +msgstr "Статус кеша" + +#: src/labels.h:155 +msgid "Not Found URLs (404s)" +msgstr "Ненайденные URL'ы (404-е)" + +#: src/labels.h:157 +msgid "Top not found URLs sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Топ ненайденных URL'ов, отсортированных по хитам [, ср., общ, макс. вр. " +"обсл., методу, протоколу]" + +#: src/labels.h:162 +msgid "Visitor Hostnames and IPs" +msgstr "Имена хостов и IP посетителей" + +#: src/labels.h:164 +msgid "Top visitor hosts sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Топ хостов посетителей, отсортированных по хитам [, ср., общ, макс. вр. " +"обсл.]" + +#: src/labels.h:166 +msgid "Hosts" +msgstr "Хосты" + +#: src/labels.h:169 +msgid "Operating Systems" +msgstr "Операционные системы" + +#: src/labels.h:171 +msgid "Top Operating Systems sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Топ операционных систем, отсортированных по хитам [, ср., общ, макс. вр. " +"обсл.]" + +#: src/labels.h:173 +msgid "OS" +msgstr "ОС" + +#: src/labels.h:176 src/labels.h:180 +msgid "Browsers" +msgstr "Браузеры" + +#: src/labels.h:178 +msgid "Top Browsers sorted by hits [, avgts, cumts, maxts]" +msgstr "Топ браузеров, отсортированных по хитам [, ср., общ, макс. вр. обсл.]" + +#: src/labels.h:183 +#, fuzzy +msgid "Referrer URLs" +msgstr "Ссылающиеся страницы" + +#: src/labels.h:185 +#, fuzzy +msgid "Top Requested Referrers sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Топ ссылающихся страниц, отсортированных по хитам [, ср., общ, макс. вр. " +"обсл.]" + +#: src/labels.h:190 src/labels.h:194 +msgid "Referring Sites" +msgstr "Ссылающиеся сайты" + +#: src/labels.h:192 +msgid "Top Referring Sites sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Топ ссылающихся сайтов, отсортированных по хитам [, ср., общ, макс. вр. " +"обсл.]" + +#: src/labels.h:197 +msgid "Keyphrases from Google's search engine" +msgstr "Ключевые слова из поисковой системы Google" + +#: src/labels.h:199 +msgid "Top Keyphrases sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Топ ключевых слов, отсортированных по хитам [, ср., общ, макс. вр. обсл.]" + +#: src/labels.h:201 +msgid "Keyphrases" +msgstr "Ключевые слова" + +#: src/labels.h:204 src/labels.h:208 +msgid "Geo Location" +msgstr "Географическое расположение" + +#: src/labels.h:206 +msgid "Continent > Country sorted by unique hits [, avgts, cumts, maxts]" +msgstr "" +"Континенты > страны, отсортированные по уникальным хитам [, ср., общ, макс. " +"вр. обсл.]" + +#: src/labels.h:213 +msgid "Autonomous System Numbers/Organizations (ASNs)" +msgstr "" + +#: src/labels.h:218 +msgid "HTTP Status Codes" +msgstr "Коды ответов HTTP" + +#: src/labels.h:220 +msgid "Top HTTP Status Codes sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Топ кодов ответов HTTP, отсортированных по хитам [, ср., общ, макс. вр. " +"обсл.]" + +#: src/labels.h:222 +msgid "Status Codes" +msgstr "Коды ответов" + +#: src/labels.h:225 src/labels.h:229 +msgid "MIME Types" +msgstr "MIME-типы" + +#: src/labels.h:227 +msgid "File types shipped out" +msgstr "Типы отправленных файлов" + +#: src/labels.h:232 +msgid "Encryption settings" +msgstr "Настройки шифрования" + +#: src/labels.h:234 +msgid "TLS version and picked algorithm" +msgstr "Версия TLS и выбранный алгоритм" + +#: src/labels.h:236 +msgid "TLS Settings" +msgstr "Настройки TLS" + +#: src/labels.h:240 +msgid "[ ] case sensitive" +msgstr "[ ] учитывать регистр" + +#: src/labels.h:242 +msgid "[x] case sensitive" +msgstr "[x] учитывать регистр" + +#: src/labels.h:244 +msgid "Regex allowed - ^g to cancel - TAB switch case" +msgstr "Разрешены рег. выражения - ^g отмена - TAB учёт регистра" + +#: src/labels.h:246 +msgid "Find pattern in all views" +msgstr "Поиск шаблона во всех панелях" + +#: src/labels.h:250 +msgid "Log Format Configuration" +msgstr "Настройка формата лога" + +#: src/labels.h:252 +msgid "[SPACE] to toggle - [ENTER] to proceed - [q] to quit" +msgstr "[ПРОБЕЛ] переключение - [ENTER] обработать - [q] выйти" + +#: src/labels.h:254 +msgid "Log Format - [c] to add/edit format" +msgstr "Формат лога - [c] добавить/изменить формат" + +#: src/labels.h:256 +msgid "Date Format - [d] to add/edit format" +msgstr "Формат даты - [d] добавить/изменить формат" + +#: src/labels.h:258 +msgid "Time Format - [t] to add/edit format" +msgstr "Формат времени - [t] добавить/изменить формат" + +#: src/labels.h:260 src/labels.h:264 +msgid "[UP/DOWN] to scroll - [q] to close window" +msgstr "[ВВЕРХ/ВНИЗ] прокрутка - [q] закрыть окно" + +#: src/labels.h:266 +#, c-format +msgid "User Agents for %1$s" +msgstr "Юзер-агенты для %1$s" + +#: src/labels.h:270 +msgid "Scheme Configuration" +msgstr "Настройка схемы" + +#: src/labels.h:272 +msgid "[ENTER] to use scheme - [q]uit" +msgstr "[ENTER] использовать схему - [q] выйти" + +#: src/labels.h:276 +msgid "Sort active module by" +msgstr "Сортировка активного модуля" + +#: src/labels.h:278 +msgid "[ENTER] select - [TAB] sort - [q]uit" +msgstr "[ENTER] выбрать - [TAB] порядок - [q] выйти" + +#: src/labels.h:282 +msgid "GoAccess Quick Help" +msgstr "Быстрая помощь по GoAccess" + +#: src/labels.h:284 +msgid "[UP/DOWN] to scroll - [q] to quit" +msgstr "[ВВЕРХ/ВНИЗ] прокрутка - [q] выйти" + +#: src/labels.h:288 +#, fuzzy +msgid "In-Memory with On-Disk Persistent Storage." +msgstr "В памяти с хранением на диске." + +#: src/labels.h:292 +msgid "Format Errors - Verify your log/date/time format" +msgstr "Ошибки формата - Проверьте ваш формат лога/даты/времени" + +#: src/labels.h:294 +msgid "No date format was found on your conf file." +msgstr "Формат даты в вашей конфигурационном файле не найден." + +#: src/labels.h:296 +msgid "No log format was found on your conf file." +msgstr "Формат лога в вашем конфигурационном файле не найден." + +#: src/labels.h:298 +msgid "No time format was found on your conf file." +msgstr "Формат времени в вашем конфигурационном файле не найден." + +#: src/labels.h:300 +msgid "No default config file found." +msgstr "Стандартный конфигурационный файл не найден." + +#: src/labels.h:302 +msgid "You may specify one with" +msgstr "Вы можете задать его с помощью" + +#: src/labels.h:304 +msgid "producing the following errors" +msgstr "приводит к следующим ошибкам" + +#: src/labels.h:306 +#, c-format +msgid "Parsed %1$d lines" +msgstr "Обработано %1$d строк" + +#: src/labels.h:308 +msgid "Please report it by opening an issue on GitHub" +msgstr "Пожалуйста, сообщите об этом, открыв issue на GitHub" + +#: src/labels.h:310 +msgid "Select a time format." +msgstr "Выберите формат времени." + +#: src/labels.h:312 +msgid "Select a date format." +msgstr "Выберите формат даты." + +#: src/labels.h:314 +msgid "Select a log format." +msgstr "Выберите формат лога." + +#: src/labels.h:316 +#, c-format +msgid "'%1$s' panel is disabled" +msgstr "Панель '%1$s' отключена" + +#: src/labels.h:318 +msgid "No input data was provided nor there's data to restore." +msgstr "Не предоставлено ни входных данных, ни данных для восстановления." + +#: src/labels.h:320 +msgid "Unable to allocate memory for a log instance." +msgstr "" + +#: src/labels.h:322 +msgid "Unable to find the given log." +msgstr "" + +#: src/labels.h:326 +msgid "For more details visit" +msgstr "Подробности по ссылке" + +#: src/labels.h:328 +msgid "Last Updated" +msgstr "Последнее обновление" + +#: src/labels.h:330 +msgid "WebSocket server ready to accept new client connections" +msgstr "WebSocket-сервер готов к приёму новых соединений" + +#: src/labels.h:333 +msgid "The following options can also be supplied to the command" +msgstr "Следующие опции также могут использоваться с командой" + +#: src/labels.h:335 +msgid "Examples can be found by running" +msgstr "Примеры можно найти, запустив" + +#: src/labels.h:338 +msgid "Server Statistics" +msgstr "Статистика сервера" + +#: src/labels.h:340 +msgid "Theme" +msgstr "Тема" + +#: src/labels.h:342 +msgid "Dark Gray" +msgstr "Тёмно-серая" + +#: src/labels.h:344 +msgid "Bright" +msgstr "Светлая" + +#: src/labels.h:346 +msgid "Dark Blue" +msgstr "Тёмно-синяя" + +#: src/labels.h:348 +msgid "Dark Purple" +msgstr "Тёмно-фиолетовая" + +#: src/labels.h:350 +msgid "Panels" +msgstr "Панели" + +#: src/labels.h:352 +msgid "Items per Page" +msgstr "Элементов на странице" + +#: src/labels.h:354 +msgid "Tables" +msgstr "Таблицы" + +#: src/labels.h:356 +msgid "Display Tables" +msgstr "Показывать таблицы" + +#: src/labels.h:358 +msgid "Auto-Hide on Small Devices" +msgstr "Автоскрытие на маленьких устройствах" + +#: src/labels.h:360 +msgid "Automatically hide tables on small screen devices" +msgstr "Автоматически скрывать таблицы на устройствах с маленькими экранами" + +#: src/labels.h:362 +msgid "Toggle Panel" +msgstr "Переключение панели" + +#: src/labels.h:364 +msgid "Layout" +msgstr "Расположение" + +#: src/labels.h:366 +msgid "Horizontal" +msgstr "Горизонтальное" + +#: src/labels.h:368 +msgid "Vertical" +msgstr "Вертикальное" + +#: src/labels.h:370 +msgid "WideScreen" +msgstr "Широкоэкранное" + +#: src/labels.h:372 +msgid "File Options" +msgstr "Файловые опции" + +#: src/labels.h:374 +msgid "Export as JSON" +msgstr "Экспорт в JSON" + +#: src/labels.h:376 +msgid "Panel Options" +msgstr "Настройки панели" + +#: src/labels.h:378 +msgid "Previous" +msgstr "Предыдущая" + +#: src/labels.h:380 +msgid "Next" +msgstr "Следующая" + +#: src/labels.h:382 +msgid "First" +msgstr "Первая" + +#: src/labels.h:384 +msgid "Last" +msgstr "Последняя" + +#: src/labels.h:386 +msgid "Chart Options" +msgstr "Настройки диаграммы" + +#: src/labels.h:388 +msgid "Chart" +msgstr "Диаграмма" + +#: src/labels.h:390 +msgid "Type" +msgstr "Тип" + +#: src/labels.h:392 +msgid "Area Spline" +msgstr "Сглаженные области" + +#: src/labels.h:394 +msgid "Bar" +msgstr "Столбцы" + +#: src/labels.h:396 +msgid "World Map" +msgstr "" + +#: src/labels.h:398 +msgid "Plot Metric" +msgstr "Единицы измерения" + +#: src/labels.h:400 +msgid "Table Columns" +msgstr "Колонки таблицы" + +#: src/labels.h:404 +msgid "0xx Unofficial Codes" +msgstr "" + +#: src/labels.h:406 +msgid "1xx Informational" +msgstr "1xx Информационные" + +#: src/labels.h:408 +msgid "2xx Success" +msgstr "2xx Успешные" + +#: src/labels.h:410 +msgid "3xx Redirection" +msgstr "3xx Перенаправления" + +#: src/labels.h:412 +msgid "4xx Client Errors" +msgstr "4xx Ошибки клиента" + +#: src/labels.h:414 +msgid "5xx Server Errors" +msgstr "5xx Ошибки сервера" + +#: src/labels.h:417 +msgid "0 - Caddy: Unhandled - No configured routes" +msgstr "" + +#: src/labels.h:419 +msgid "100 - Continue: Server received the initial part of the request" +msgstr "100 - Continue: Сервер получил начальную часть запроса" + +#: src/labels.h:421 +msgid "101 - Switching Protocols: Client asked to switch protocols" +msgstr "101 - Switching Protocols: Клиент запросил переключение протокола" + +#: src/labels.h:423 +msgid "200 - OK: The request sent by the client was successful" +msgstr "200 - OK: Запрос клиента выполнен успешно" + +#: src/labels.h:425 +msgid "201 - Created: The request has been fulfilled and created" +msgstr "201 - Created: Запрос клиента выполнен и создан новый ресурс" + +#: src/labels.h:427 +msgid "202 - Accepted: The request has been accepted for processing" +msgstr "202 - Accepted: Запрос принят на обработку" + +#: src/labels.h:429 +msgid "203 - Non-authoritative Information: Response from a third party" +msgstr "203 - Non-authoritative Information: Ответ не из первичного источника" + +#: src/labels.h:431 +msgid "204 - No Content: Request did not return any content" +msgstr "204 - No Content: Запрос не вернул никакого контента" + +#: src/labels.h:433 +msgid "205 - Reset Content: Server asked the client to reset the document" +msgstr "205 - Reset Content: Сервер попросил клиента сбросить документ" + +#: src/labels.h:435 +msgid "206 - Partial Content: The partial GET has been successful" +msgstr "206 - Partial Content: Частичный GET-запрос выполнен успешно" + +#: src/labels.h:437 +msgid "207 - Multi-Status: WebDAV; RFC 4918" +msgstr "207 - Multi-Status: WebDAV; RFC 4918" + +#: src/labels.h:439 +msgid "208 - Already Reported: WebDAV; RFC 5842" +msgstr "208 - Already Reported: WebDAV; RFC 5842" + +#: src/labels.h:441 +msgid "218 - This is fine: Apache servers. A catch-all error condition" +msgstr "" + +#: src/labels.h:443 +msgid "300 - Multiple Choices: Multiple options for the resource" +msgstr "" +"300 - Multiple Choices: Ресурс имеет несколько вариантов предоставления" + +#: src/labels.h:445 +msgid "301 - Moved Permanently: Resource has permanently moved" +msgstr "301 - Moved Permanently: Ресурс перемещён на постоянной основе" + +#: src/labels.h:447 +msgid "302 - Moved Temporarily (redirect)" +msgstr "302 - Moved Temporarily (временный редирект)" + +#: src/labels.h:449 +msgid "303 - See Other Document: The response is at a different URI" +msgstr "303 - See Other Document: Ответ находится по другому URI" + +#: src/labels.h:451 +msgid "304 - Not Modified: Resource has not been modified" +msgstr "304 - Not Modified: Ресурс не изменялся" + +#: src/labels.h:453 +msgid "305 - Use Proxy: Can only be accessed through the proxy" +msgstr "305 - Use Proxy: Доступ только через прокси" + +#: src/labels.h:455 +msgid "307 - Temporary Redirect: Resource temporarily moved" +msgstr "307 - Temporary Redirect: Ресурс временно перемещён" + +#: src/labels.h:457 +#, fuzzy +msgid "308 - Permanent Redirect" +msgstr "402 - Payment Required" + +#: src/labels.h:459 +msgid "400 - Bad Request: The syntax of the request is invalid" +msgstr "400 - Bad Request: Неверный синтаксис запроса" + +#: src/labels.h:461 +msgid "401 - Unauthorized: Request needs user authentication" +msgstr "401 - Unauthorized: Запрос требует аутентификации" + +#: src/labels.h:463 +msgid "402 - Payment Required" +msgstr "402 - Payment Required" + +#: src/labels.h:465 +msgid "403 - Forbidden: Server is refusing to respond to it" +msgstr "403 - Forbidden: Сервер отказался предоставить ответ" + +#: src/labels.h:467 +msgid "404 - Not Found: Requested resource could not be found" +msgstr "404 - Not Found: Запрошенный ресурс не найден" + +#: src/labels.h:469 +msgid "405 - Method Not Allowed: Request method not supported" +msgstr "405 - Method Not Allowed: Метод запроса не поддерживается" + +#: src/labels.h:471 +msgid "406 - Not Acceptable" +msgstr "406 - Not Acceptable" + +#: src/labels.h:473 +msgid "407 - Proxy Authentication Required" +msgstr "407 - Proxy Authentication Required" + +#: src/labels.h:475 +msgid "408 - Request Timeout: Server timed out waiting for the request" +msgstr "408 - Request Timeout: Сервер не дождался запроса" + +#: src/labels.h:477 +msgid "409 - Conflict: Conflict in the request" +msgstr "409 - Conflict: Конфликтный запрос" + +#: src/labels.h:479 +msgid "410 - Gone: Resource requested is no longer available" +msgstr "410 - Gone: Запрошенный ресурс больше недоступен" + +#: src/labels.h:481 +msgid "411 - Length Required: Invalid Content-Length" +msgstr "411 - Length Required: Неверный Content-Length" + +#: src/labels.h:483 +msgid "412 - Precondition Failed: Server does not meet preconditions" +msgstr "412 - Precondition Failed: Сервер не выполнил предварительные условия" + +#: src/labels.h:485 +msgid "413 - Payload Too Large" +msgstr "413 - Payload Too Large" + +#: src/labels.h:487 +msgid "414 - Request-URI Too Long" +msgstr "414 - Request-URI Too Long" + +#: src/labels.h:489 +msgid "415 - Unsupported Media Type: Media type is not supported" +msgstr "415 - Unsupported Media Type: Тип медиа не поддерживается" + +#: src/labels.h:491 +msgid "416 - Requested Range Not Satisfiable: Cannot supply that portion" +msgstr "416 - Requested Range Not Satisfiable: Часть не может быть доставлена" + +#: src/labels.h:493 +msgid "417 - Expectation Failed" +msgstr "417 - Expectation Failed" + +#: src/labels.h:495 +#, fuzzy +msgid "418 - I'm a teapot" +msgstr "418 - I’m a teapot" + +#: src/labels.h:497 +msgid "419 - Page Expired: Laravel Framework when a CSRF Token is missing" +msgstr "" + +#: src/labels.h:499 +msgid "420 - Method Failure: Spring Framework when a method has failed" +msgstr "" + +#: src/labels.h:501 +msgid "421 - Misdirected Request" +msgstr "421 - Misdirected Request" + +#: src/labels.h:503 +msgid "422 - Unprocessable Entity due to semantic errors: WebDAV" +msgstr "422 - Unprocessable Entity due to semantic errors: WebDAV" + +#: src/labels.h:505 +msgid "423 - The resource that is being accessed is locked" +msgstr "423 - The resource that is being accessed is locked" + +#: src/labels.h:507 +msgid "424 - Failed Dependency: WebDAV" +msgstr "424 - Failed Dependency: WebDAV" + +#: src/labels.h:509 +msgid "426 - Upgrade Required: Client should switch to a different protocol" +msgstr "426 - Upgrade Required: Клиент должен переключить протокол" + +#: src/labels.h:511 +msgid "428 - Precondition Required" +msgstr "428 - Precondition Required" + +#: src/labels.h:513 +msgid "429 - Too Many Requests: The user has sent too many requests" +msgstr "429 - Too Many Requests: Клиент отправил слишком много запросов" + +#: src/labels.h:515 +msgid "" +"430 - Request Header Fields Too Large: Too many URLs are requested within a " +"certain time frame" +msgstr "" + +#: src/labels.h:517 +msgid "431 - Request Header Fields Too Large" +msgstr "431 - Request Header Fields Too Large" + +#: src/labels.h:519 +msgid "440 - Login Time-out: The client's session has expired" +msgstr "" + +#: src/labels.h:521 +#, fuzzy +msgid "449 - Retry With: The server cannot honour the request" +msgstr "408 - Request Timeout: Сервер не дождался запроса" + +#: src/labels.h:523 +msgid "" +"450 - Blocked by Windows Parental Controls: The Microsoft extension code " +"indicated" +msgstr "" + +#: src/labels.h:525 +msgid "451 - Unavailable For Legal Reasons" +msgstr "451 - Unavailable For Legal Reasons" + +#: src/labels.h:527 +msgid "444 - (Nginx) Connection closed without sending any headers" +msgstr "444 - (Nginx) Connection closed without sending any headers" + +#: src/labels.h:529 +msgid "460 - AWS Elastic Load Balancing: Client closed the connection " +msgstr "" + +#: src/labels.h:531 +msgid "" +"463 - AWS Elastic Load Balancing: The load balancer received more than 30 IP " +"addresses" +msgstr "" + +#: src/labels.h:533 +msgid "464 - AWS Elastic Load Balancing: Incompatible protocol versions" +msgstr "" + +#: src/labels.h:535 +msgid "494 - (Nginx) Request Header Too Large" +msgstr "494 - (Nginx) Request Header Too Large" + +#: src/labels.h:537 +msgid "495 - (Nginx) SSL client certificate error" +msgstr "495 - (Nginx) SSL client certificate error" + +#: src/labels.h:539 +msgid "496 - (Nginx) Client didn't provide certificate" +msgstr "496 - (Nginx) Client didn't provide certificate" + +#: src/labels.h:541 +msgid "497 - (Nginx) HTTP request sent to HTTPS port" +msgstr "497 - (Nginx) HTTP request sent to HTTPS port" + +#: src/labels.h:543 +msgid "498 - Invalid Token: an expired or otherwise invalid token" +msgstr "" + +#: src/labels.h:545 +msgid "499 - (Nginx) Connection closed by client while processing request" +msgstr "499 - (Nginx) Connection closed by client while processing request" + +#: src/labels.h:547 +msgid "500 - Internal Server Error" +msgstr "500 - Internal Server Error" + +#: src/labels.h:549 +msgid "501 - Not Implemented" +msgstr "501 - Not Implemented" + +#: src/labels.h:551 +msgid "502 - Bad Gateway: Received an invalid response from the upstream" +msgstr "" +"502 - Bad Gateway: Сервер, действующий как шлюз, получил недопустимый ответ" + +#: src/labels.h:553 +msgid "503 - Service Unavailable: The server is currently unavailable" +msgstr "503 - Service Unavailable: Сервер недоступен" + +#: src/labels.h:555 +msgid "504 - Gateway Timeout: The upstream server failed to send request" +msgstr "" +"504 - Gateway Timeout: Сервер, действующий как шлюз, не дождался ответа" + +#: src/labels.h:557 +msgid "505 - HTTP Version Not Supported" +msgstr "505 - HTTP Version Not Supported" + +#: src/labels.h:559 +msgid "509 - Bandwidth Limit Exceeded: The server has exceeded the bandwidth" +msgstr "" + +#: src/labels.h:561 +msgid "520 - CloudFlare - Web server is returning an unknown error" +msgstr "520 - CloudFlare - Web server is returning an unknown error" + +#: src/labels.h:563 +msgid "521 - CloudFlare - Web server is down" +msgstr "521 - CloudFlare - Web server is down" + +#: src/labels.h:565 +msgid "522 - CloudFlare - Connection timed out" +msgstr "522 - CloudFlare - Connection timed out" + +#: src/labels.h:567 +msgid "523 - CloudFlare - Origin is unreachable" +msgstr "523 - CloudFlare - Origin is unreachable" + +#: src/labels.h:569 +msgid "524 - CloudFlare - A timeout occurred" +msgstr "524 - CloudFlare - A timeout occurred" + +#: src/labels.h:571 +msgid "" +"525 - SSL Handshake Failed: Cloudflare could not negotiate a SSL/TLS " +"handshake" +msgstr "" + +#: src/labels.h:573 +msgid "" +"526 - Invalid SSL Certificate: Cloudflare could not validate the SSL " +"certificate" +msgstr "" + +#: src/labels.h:575 +msgid "527 - Railgun Error: An interrupted connection" +msgstr "" + +#: src/labels.h:577 +msgid "529 - Site is overloaded: A site can not process the request" +msgstr "" + +#: src/labels.h:579 +msgid "530 - Site is frozen: A site has been frozen due to inactivity" +msgstr "" + +#: src/labels.h:581 +msgid "" +"540 - Temporarily Disabled: The requested endpoint has been temporarily " +"disabled" +msgstr "" + +#: src/labels.h:583 +#, fuzzy +msgid "561 - Unauthorized: An error around authentication" +msgstr "401 - Unauthorized: Запрос требует аутентификации" + +#: src/labels.h:585 +msgid "" +"598 - Network read timeout error: some HTTP proxies to signal a network read " +"timeout" +msgstr "" + +#: src/labels.h:587 +msgid "599 - Network Connect Timeout Error: An error used by some HTTP proxies" +msgstr "" + +#: src/labels.h:589 +msgid "783 - Unexpected Token: The request includes a JSON syntax error" +msgstr "" + +#, fuzzy +#~ msgid "Referers" +#~ msgstr "Ссыл. страниц" diff --git a/po/sv.po b/po/sv.po new file mode 100644 index 0000000000..d0c02bddbe --- /dev/null +++ b/po/sv.po @@ -0,0 +1,1084 @@ +msgid "" +msgstr "" +"Project-Id-Version: goaccess 1.6\n" +"Report-Msgid-Bugs-To: hello@goaccess.io\n" +"POT-Creation-Date: 2024-04-11 20:17-0500\n" +"PO-Revision-Date: 2018-12-13 22:48-0600\n" +"Last-Translator: Anders Johansson \n" +"Language-Team: none\n" +"Language: sv\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: src/labels.h:45 +msgid "en" +msgstr "sv" + +#: src/labels.h:48 +msgid "Exp. Panel" +msgstr "Exp. Panel" + +#: src/labels.h:49 +msgid "Help" +msgstr "Hjälp" + +#: src/labels.h:50 +msgid "Quit" +msgstr "Avsluta" + +#: src/labels.h:51 +msgid "Total" +msgstr "Totalt" + +#: src/labels.h:54 +msgid "[x] ASC [ ] DESC" +msgstr "[x] STIGANDE [ ] FALLANDE" + +#: src/labels.h:55 +msgid "[ ] ASC [x] DESC" +msgstr "[ ] STIGANDE [x] FALLANDE" + +#: src/labels.h:58 +#, c-format +msgid "[Active Panel: %1$s]" +msgstr "[Aktiv panel: %1$s]" + +#: src/labels.h:59 +msgid "[q]uit GoAccess" +msgstr "[q]Avsluta GoAccess" + +#: src/labels.h:60 +msgid "[?] Help [Enter] Exp. Panel" +msgstr "[?] Hjälp [Enter] Exp. Panel" + +#: src/labels.h:61 +msgid "Dashboard" +msgstr "Dashboard" + +#: src/labels.h:62 +msgid "Dashboard - Overall Analyzed Requests" +msgstr "Dashboard - generellt analyserade förfrågningar" + +#: src/labels.h:63 +msgid "Overall Analyzed Requests" +msgstr "Generellt Analyserade förfrågningar" + +#: src/labels.h:65 src/labels.h:86 +msgid "Tx. Amount" +msgstr "Skickad mängd" + +#: src/labels.h:66 +msgid "Date/Time" +msgstr "Datum/Tid" + +#: src/labels.h:67 +msgid "Excl. IP Hits" +msgstr "Exkl. IP-träffar" + +#: src/labels.h:68 +msgid "Failed Requests" +msgstr "Misslyckade förfrågningar" + +#: src/labels.h:69 +msgid "Log Parsing Time" +msgstr "Analystid av loggar" + +#: src/labels.h:70 +msgid "Log Size" +msgstr "Loggstorlek" + +#: src/labels.h:71 +msgid "Log Source" +msgstr "Loggkälla" + +#: src/labels.h:72 src/labels.h:187 +msgid "Referrers" +msgstr "Hänvisningar" + +#: src/labels.h:73 +msgid "Total Requests" +msgstr "Total antal förfrågningar" + +#: src/labels.h:74 +msgid "Static Files" +msgstr "Statiska filer" + +#: src/labels.h:75 src/labels.h:159 +msgid "Not Found" +msgstr "Hittades inte" + +#: src/labels.h:76 +msgid "Requested Files" +msgstr "Begärda filer" + +#: src/labels.h:77 +msgid "Unique Visitors" +msgstr "Unika besökare" + +#: src/labels.h:78 +msgid "Valid Requests" +msgstr "Gilltiga förfrågningar" + +#: src/labels.h:81 +msgid "Hits" +msgstr "Träffar" + +#: src/labels.h:82 +msgid "h%" +msgstr "h%" + +#: src/labels.h:83 src/labels.h:110 +msgid "Visitors" +msgstr "Besökare" + +#: src/labels.h:84 +msgid "Vis." +msgstr "Besök." + +#: src/labels.h:85 +msgid "v%" +msgstr "v%" + +#: src/labels.h:87 +msgid "Avg. T.S." +msgstr "Genomsn. tid" + +#: src/labels.h:88 +msgid "Cum. T.S." +msgstr "Kum. tid" + +#: src/labels.h:89 +msgid "Max. T.S." +msgstr "Max. tid" + +#: src/labels.h:90 +msgid "Method" +msgstr "Metod" + +#: src/labels.h:91 +msgid "Mtd" +msgstr "Mån till datum" + +#: src/labels.h:92 +msgid "Protocol" +msgstr "Protokoll" + +#: src/labels.h:93 +msgid "Proto" +msgstr "Proto" + +#: src/labels.h:94 +msgid "City" +msgstr "Stad" + +#: src/labels.h:95 src/labels.h:211 src/labels.h:215 +msgid "ASN" +msgstr "ASN" + +#: src/labels.h:96 +msgid "Country" +msgstr "Land" + +#: src/labels.h:97 +msgid "Hostname" +msgstr "Värdnamn" + +#: src/labels.h:98 +msgid "Data" +msgstr "Data" + +#: src/labels.h:100 +msgid "Hits/Visitors" +msgstr "Träffar/Besökare" + +#: src/labels.h:104 +msgid "Unique visitors per day" +msgstr "Unika besökare per dag" + +#: src/labels.h:106 +msgid "Unique visitors per day - Including spiders" +msgstr "Unika besökare per dag - inkl. nätspindlar" + +#: src/labels.h:108 +msgid "Hits having the same IP, date and agent are a unique visit." +msgstr "Träffar med samma IP, datum och agent är unika besökare" + +#: src/labels.h:113 +msgid "Requested Files (URLs)" +msgstr "Begärda filer (URLer)" + +#: src/labels.h:115 +msgid "Top requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Flest förfrågingar sorterade i träffar [, genomst. tid, kum. tid, max. tid, " +"mån-till-dag, proto]" + +#: src/labels.h:117 +msgid "Requests" +msgstr "Uppslagningar" + +#: src/labels.h:120 src/labels.h:124 +msgid "Static Requests" +msgstr "Statiska förfrågningar" + +#: src/labels.h:122 +msgid "Top static requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Toppförfrågningar sorterade i trufar [, genomst. tid, kum. tid, max. tid, " +"mån-till-dag, proto]" + +#: src/labels.h:127 +msgid "Time Distribution" +msgstr "Tidsfördelning" + +#: src/labels.h:129 +msgid "Data sorted by hour [, avgts, cumts, maxts]" +msgstr "Data sorterade i timmar [, genomst. tid, kum. tid, max. tid]" + +#: src/labels.h:131 +msgid "Time" +msgstr "Tid" + +#: src/labels.h:134 src/labels.h:138 +msgid "Virtual Hosts" +msgstr "Virtuella värdar" + +#: src/labels.h:136 src/labels.h:143 src/labels.h:150 +msgid "Data sorted by hits [, avgts, cumts, maxts]" +msgstr "Data sorterat i träffar [, genomst. tid, kum. tid, max. tid]" + +#: src/labels.h:141 +msgid "Remote User (HTTP authentication)" +msgstr "Fjärranvändare (HTTP-autentisering)" + +#: src/labels.h:145 +msgid "Remote User" +msgstr "Fjärranvändare" + +#: src/labels.h:148 +msgid "The cache status of the object served" +msgstr "Cachestatus för det visade objektet" + +#: src/labels.h:152 +msgid "Cache Status" +msgstr "Cachestatus" + +#: src/labels.h:155 +msgid "Not Found URLs (404s)" +msgstr "Hittar inte URL:en (404)" + +#: src/labels.h:157 +msgid "Top not found URLs sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Flest ej hittade URL:er sorterade i träffar [, genomst. tid, kum. tid, max. " +"tid, mån-till-dag, proto]proto]" + +#: src/labels.h:162 +msgid "Visitor Hostnames and IPs" +msgstr "Besökares Värdnamn och IP:s" + +#: src/labels.h:164 +msgid "Top visitor hosts sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Flest besökares värdnamn sorterade i träffar [, genomst. tid, kum. tid, max. " +"tid]" + +#: src/labels.h:166 +msgid "Hosts" +msgstr "Värdar" + +#: src/labels.h:169 +msgid "Operating Systems" +msgstr "Operativsystem" + +#: src/labels.h:171 +msgid "Top Operating Systems sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Flest operativsystem sorterade i träffar [, genomst. tid, kum. tid, max. tid]" + +#: src/labels.h:173 +msgid "OS" +msgstr "OS" + +#: src/labels.h:176 src/labels.h:180 +msgid "Browsers" +msgstr "Webbläsare" + +#: src/labels.h:178 +msgid "Top Browsers sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Vanligast webbläsare sorterade i träffar [, genomst. tid, kum. tid, max. tid]" + +#: src/labels.h:183 +#, fuzzy +msgid "Referrer URLs" +msgstr "Hänvisande URL:er" + +#: src/labels.h:185 +#, fuzzy +msgid "Top Requested Referrers sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Flest Hänvisningsförfrågningar sorterade i träffar [, genomst. tid, kum. " +"tid, max. tid]" + +#: src/labels.h:190 src/labels.h:194 +msgid "Referring Sites" +msgstr "Hänvisade sidor" + +#: src/labels.h:192 +msgid "Top Referring Sites sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Flest hänvisade sidor sorterade i träffar [, genomst. tid, kum. tid, max. " +"tid]" + +#: src/labels.h:197 +msgid "Keyphrases from Google's search engine" +msgstr "Nyckelord från Googles sökmotor" + +#: src/labels.h:199 +msgid "Top Keyphrases sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Flest nyckelord sorterade i träffar [, genomst. tid, kum. tid, max. tid]" + +#: src/labels.h:201 +msgid "Keyphrases" +msgstr "Nyckelord" + +#: src/labels.h:204 src/labels.h:208 +msgid "Geo Location" +msgstr "Geografisk plats" + +#: src/labels.h:206 +msgid "Continent > Country sorted by unique hits [, avgts, cumts, maxts]" +msgstr "" +"Kontinent > Land sorterad i unika träffar [, genomst. tid, kum. tid, max. " +"tid]" + +#: src/labels.h:213 +msgid "Autonomous System Numbers/Organizations (ASNs)" +msgstr "Autonoma systemnummer/organisationer (ASN)" + +#: src/labels.h:218 +msgid "HTTP Status Codes" +msgstr "HTTP Statuskod" + +#: src/labels.h:220 +msgid "Top HTTP Status Codes sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Flest HTTP Statuskod sorterade i träffar [, genomst. tid, kum. tid, max. tid]" + +#: src/labels.h:222 +msgid "Status Codes" +msgstr "Statuskoder" + +#: src/labels.h:225 src/labels.h:229 +msgid "MIME Types" +msgstr "MIME-typer" + +#: src/labels.h:227 +msgid "File types shipped out" +msgstr "Filtyper skickas ut" + +#: src/labels.h:232 +msgid "Encryption settings" +msgstr "Krypteringsinställningar" + +#: src/labels.h:234 +msgid "TLS version and picked algorithm" +msgstr "TLS-version och plockad algoritm" + +#: src/labels.h:236 +msgid "TLS Settings" +msgstr "TLS-inställningar" + +#: src/labels.h:240 +msgid "[ ] case sensitive" +msgstr "[ ] skiftlägeskänsliga" + +#: src/labels.h:242 +msgid "[x] case sensitive" +msgstr "[x] skiftlägeskänsliga" + +#: src/labels.h:244 +msgid "Regex allowed - ^g to cancel - TAB switch case" +msgstr "Regex tillåtet - ^ g för att avbryta - TAB-växla" + +#: src/labels.h:246 +msgid "Find pattern in all views" +msgstr "Hitta mönster i alla vyer" + +#: src/labels.h:250 +msgid "Log Format Configuration" +msgstr "Loggformat konfiguration" + +#: src/labels.h:252 +msgid "[SPACE] to toggle - [ENTER] to proceed - [q] to quit" +msgstr "" +"[SPACE] för att växla - [ENTER] för att fortsätta - [q] för att avsluta" + +#: src/labels.h:254 +msgid "Log Format - [c] to add/edit format" +msgstr "Logformat - [c] för att lägga till / redigera format" + +#: src/labels.h:256 +msgid "Date Format - [d] to add/edit format" +msgstr "Datumformat - [d] för att lägga till / redigera format" + +#: src/labels.h:258 +msgid "Time Format - [t] to add/edit format" +msgstr "Tidsformat - [t] för att lägga till / redigera format" + +#: src/labels.h:260 src/labels.h:264 +msgid "[UP/DOWN] to scroll - [q] to close window" +msgstr "[UPP / NER] för att bläddra - [q] för att stänga fönstret" + +#: src/labels.h:266 +#, c-format +msgid "User Agents for %1$s" +msgstr "Användaragenter %1$s" + +#: src/labels.h:270 +msgid "Scheme Configuration" +msgstr "Schemakonfiguration" + +#: src/labels.h:272 +msgid "[ENTER] to use scheme - [q]uit" +msgstr "[ENTER] för att använda schema - [q]avsluta" + +#: src/labels.h:276 +msgid "Sort active module by" +msgstr "Sortera aktiv modul med" + +#: src/labels.h:278 +msgid "[ENTER] select - [TAB] sort - [q]uit" +msgstr "[ENTER] välj - [TAB] sortera - [q] avsluta" + +#: src/labels.h:282 +msgid "GoAccess Quick Help" +msgstr "GoAccess snabbhjälp" + +#: src/labels.h:284 +msgid "[UP/DOWN] to scroll - [q] to quit" +msgstr "[UP / DOWN] för att bläddra - [q] för att avsluta" + +#: src/labels.h:288 +msgid "In-Memory with On-Disk Persistent Storage." +msgstr "In-Memory med On-Disk persistent lagring." + +#: src/labels.h:292 +msgid "Format Errors - Verify your log/date/time format" +msgstr "Fel format - Kontrollera din logg /datum/tidformat" + +#: src/labels.h:294 +msgid "No date format was found on your conf file." +msgstr "Inget datumformat hittades på din konfigurationsfil." + +#: src/labels.h:296 +msgid "No log format was found on your conf file." +msgstr "Inget loggformat hittades på din konfigurationsfil." + +#: src/labels.h:298 +msgid "No time format was found on your conf file." +msgstr "Inget tidsformat hittades i din konfigurationfil." + +#: src/labels.h:300 +msgid "No default config file found." +msgstr "Ingen standard konfiguationsfil hittades." + +#: src/labels.h:302 +msgid "You may specify one with" +msgstr "Du kan ange en med" + +#: src/labels.h:304 +msgid "producing the following errors" +msgstr "producerar följande fel" + +#: src/labels.h:306 +#, c-format +msgid "Parsed %1$d lines" +msgstr "Analyserade %1$d linjer" + +#: src/labels.h:308 +msgid "Please report it by opening an issue on GitHub" +msgstr "Var god rapportera det genom att öppna ett problem på GitHub" + +#: src/labels.h:310 +msgid "Select a time format." +msgstr "Välj ett tidsformat." + +#: src/labels.h:312 +msgid "Select a date format." +msgstr "Välj ett datumformat." + +#: src/labels.h:314 +msgid "Select a log format." +msgstr "Välj ett loggformat." + +#: src/labels.h:316 +#, c-format +msgid "'%1$s' panel is disabled" +msgstr "’%1$s’ panelen är inaktiverad" + +#: src/labels.h:318 +msgid "No input data was provided nor there's data to restore." +msgstr "Ingen ingångsdata tillhandahölls eller det finns data att återställa." + +#: src/labels.h:320 +msgid "Unable to allocate memory for a log instance." +msgstr "" + +#: src/labels.h:322 +msgid "Unable to find the given log." +msgstr "" + +#: src/labels.h:326 +msgid "For more details visit" +msgstr "För mer information besök" + +#: src/labels.h:328 +msgid "Last Updated" +msgstr "Senast uppdaterad" + +#: src/labels.h:330 +msgid "WebSocket server ready to accept new client connections" +msgstr "WebSocket-server redo att acceptera nya klientanslutningar" + +#: src/labels.h:333 +msgid "The following options can also be supplied to the command" +msgstr "Följande alternativ kan också levereras till kommandot" + +#: src/labels.h:335 +msgid "Examples can be found by running" +msgstr "Exempel kan hittas genom att köra" + +#: src/labels.h:338 +msgid "Server Statistics" +msgstr "Serverstatistik" + +#: src/labels.h:340 +msgid "Theme" +msgstr "Tema" + +#: src/labels.h:342 +msgid "Dark Gray" +msgstr "Mörkgrå" + +#: src/labels.h:344 +msgid "Bright" +msgstr "Ljus" + +#: src/labels.h:346 +msgid "Dark Blue" +msgstr "Mörkblå" + +#: src/labels.h:348 +msgid "Dark Purple" +msgstr "Mörklila" + +#: src/labels.h:350 +msgid "Panels" +msgstr "Paneler" + +#: src/labels.h:352 +msgid "Items per Page" +msgstr "Objekt per sida" + +#: src/labels.h:354 +msgid "Tables" +msgstr "Tabeller" + +#: src/labels.h:356 +msgid "Display Tables" +msgstr "Skärmtabeller" + +#: src/labels.h:358 +msgid "Auto-Hide on Small Devices" +msgstr "Automatisk dölj på små enheter" + +#: src/labels.h:360 +msgid "Automatically hide tables on small screen devices" +msgstr "Dölj automatiskt tabeller på små skärm enheter" + +#: src/labels.h:362 +msgid "Toggle Panel" +msgstr "Växla panel" + +#: src/labels.h:364 +msgid "Layout" +msgstr "Layout" + +#: src/labels.h:366 +msgid "Horizontal" +msgstr "Horisontell" + +#: src/labels.h:368 +msgid "Vertical" +msgstr "Vertikal" + +#: src/labels.h:370 +msgid "WideScreen" +msgstr "WideScreen" + +#: src/labels.h:372 +msgid "File Options" +msgstr "Filalternativ" + +#: src/labels.h:374 +msgid "Export as JSON" +msgstr "Exportera som JSON" + +#: src/labels.h:376 +msgid "Panel Options" +msgstr "Panelalternativ" + +#: src/labels.h:378 +msgid "Previous" +msgstr "Föregående" + +#: src/labels.h:380 +msgid "Next" +msgstr "Nästa" + +#: src/labels.h:382 +msgid "First" +msgstr "Första" + +#: src/labels.h:384 +msgid "Last" +msgstr "Sista" + +#: src/labels.h:386 +msgid "Chart Options" +msgstr "Diagramalternativ" + +#: src/labels.h:388 +msgid "Chart" +msgstr "Diagram" + +#: src/labels.h:390 +msgid "Type" +msgstr "Typ" + +#: src/labels.h:392 +msgid "Area Spline" +msgstr "Kurva" + +#: src/labels.h:394 +msgid "Bar" +msgstr "Stapel" + +#: src/labels.h:396 +msgid "World Map" +msgstr "" + +#: src/labels.h:398 +msgid "Plot Metric" +msgstr "Plotmetrisk" + +#: src/labels.h:400 +msgid "Table Columns" +msgstr "Tabellkolumn" + +#: src/labels.h:404 +msgid "0xx Unofficial Codes" +msgstr "" + +#: src/labels.h:406 +msgid "1xx Informational" +msgstr "1xx Informativ" + +#: src/labels.h:408 +msgid "2xx Success" +msgstr "2xx Success" + +#: src/labels.h:410 +msgid "3xx Redirection" +msgstr "3xx Omdirigering" + +#: src/labels.h:412 +msgid "4xx Client Errors" +msgstr "4xx Klientel" + +#: src/labels.h:414 +msgid "5xx Server Errors" +msgstr "5xx Serverfel" + +#: src/labels.h:417 +msgid "0 - Caddy: Unhandled - No configured routes" +msgstr "" + +#: src/labels.h:419 +msgid "100 - Continue: Server received the initial part of the request" +msgstr "100 - Fortsätt: Servern mottog den första delen av begäran" + +#: src/labels.h:421 +msgid "101 - Switching Protocols: Client asked to switch protocols" +msgstr "101 - Växlingsprotokoll: Klienten bad om att byta protokoll" + +#: src/labels.h:423 +msgid "200 - OK: The request sent by the client was successful" +msgstr "200 - OK: Förfrågan som skickades av klienten lyckades" + +#: src/labels.h:425 +msgid "201 - Created: The request has been fulfilled and created" +msgstr "201 - Skapad: Förfrågan har uppfyllts och skapats" + +#: src/labels.h:427 +msgid "202 - Accepted: The request has been accepted for processing" +msgstr "202 - Godkänd: Förfrågan har godkänts för behandling" + +#: src/labels.h:429 +msgid "203 - Non-authoritative Information: Response from a third party" +msgstr "203 - Ej auktoritativ information: Svar från en tredje part" + +#: src/labels.h:431 +msgid "204 - No Content: Request did not return any content" +msgstr "204 - Inget innehåll: Förfrågan returnerade inte något innehåll" + +#: src/labels.h:433 +msgid "205 - Reset Content: Server asked the client to reset the document" +msgstr "" +"205 - Återställ innehåll: Server bad klienten om att återställa dokumentet" + +#: src/labels.h:435 +msgid "206 - Partial Content: The partial GET has been successful" +msgstr "206 - Delvis innehåll: Den partiella GET har blivit framgångsrik" + +#: src/labels.h:437 +msgid "207 - Multi-Status: WebDAV; RFC 4918" +msgstr "207 - Multi-Status: WebDAV; RFC 4918" + +#: src/labels.h:439 +msgid "208 - Already Reported: WebDAV; RFC 5842" +msgstr "208 - Redan rapporterad: WebDAV; RFC 5842" + +#: src/labels.h:441 +msgid "218 - This is fine: Apache servers. A catch-all error condition" +msgstr "" + +#: src/labels.h:443 +msgid "300 - Multiple Choices: Multiple options for the resource" +msgstr "300 - Flera val: Multipla alternativ för resursen" + +#: src/labels.h:445 +msgid "301 - Moved Permanently: Resource has permanently moved" +msgstr "301 - Flyttade permanent: Resursen har flyttats permanent" + +#: src/labels.h:447 +msgid "302 - Moved Temporarily (redirect)" +msgstr "302 - Flyttade tillfälligt (omdirigera)" + +#: src/labels.h:449 +msgid "303 - See Other Document: The response is at a different URI" +msgstr "303 - Se annat dokument: Svaret finns på en annan URI" + +#: src/labels.h:451 +msgid "304 - Not Modified: Resource has not been modified" +msgstr "304 - Ej modifierad: Resursen har inte ändrats" + +#: src/labels.h:453 +msgid "305 - Use Proxy: Can only be accessed through the proxy" +msgstr "305 - Använd proxy: Kan endast nås via proxy" + +#: src/labels.h:455 +msgid "307 - Temporary Redirect: Resource temporarily moved" +msgstr "307 - Tillfällig omdirigering: Resurs flyttas tillfälligt" + +#: src/labels.h:457 +#, fuzzy +msgid "308 - Permanent Redirect" +msgstr "402 - Betalning krävs" + +#: src/labels.h:459 +msgid "400 - Bad Request: The syntax of the request is invalid" +msgstr "400 - Dålig begäran: Syntaxen för förfrågan är ogiltig" + +#: src/labels.h:461 +msgid "401 - Unauthorized: Request needs user authentication" +msgstr "401 - Ej auktoriserad: Begäran behöver användarautentisering" + +#: src/labels.h:463 +msgid "402 - Payment Required" +msgstr "402 - Betalning krävs" + +#: src/labels.h:465 +msgid "403 - Forbidden: Server is refusing to respond to it" +msgstr "403 - Förbud: Server vägrar att svara på det" + +#: src/labels.h:467 +msgid "404 - Not Found: Requested resource could not be found" +msgstr "404 - Ej funnen: Begärd resurs kunde inte hittas" + +#: src/labels.h:469 +msgid "405 - Method Not Allowed: Request method not supported" +msgstr "405 - Metod Ej tillåtet: Förfrågan metod stöds inte" + +#: src/labels.h:471 +msgid "406 - Not Acceptable" +msgstr "406 - Ej acceptabelt" + +#: src/labels.h:473 +msgid "407 - Proxy Authentication Required" +msgstr "407 - Proxy-autentisering krävs" + +#: src/labels.h:475 +msgid "408 - Request Timeout: Server timed out waiting for the request" +msgstr "408 - Begär tidsavbrott: Server slutade vänta på begäran" + +#: src/labels.h:477 +msgid "409 - Conflict: Conflict in the request" +msgstr "409 - Konflikt: Konflikt i begäran" + +#: src/labels.h:479 +msgid "410 - Gone: Resource requested is no longer available" +msgstr "" +"410 - Borta: Begärd resurs är inte längre tillgänglig410 - Gone: " +"Resursförfrågan är inte längre tillgänglig, Skicka feedback" + +#: src/labels.h:481 +msgid "411 - Length Required: Invalid Content-Length" +msgstr "411 - Krav längd: Ogiltigt innehållslängd" + +#: src/labels.h:483 +msgid "412 - Precondition Failed: Server does not meet preconditions" +msgstr "" +"412 - Förutsättning misslyckades: Server uppfyller inte förutsättningar" + +#: src/labels.h:485 +msgid "413 - Payload Too Large" +msgstr "413 - Belastningen för stor" + +#: src/labels.h:487 +msgid "414 - Request-URI Too Long" +msgstr "414 - Begär-URI för lång" + +#: src/labels.h:489 +msgid "415 - Unsupported Media Type: Media type is not supported" +msgstr "415 - Medietyp som inte stöds: Medietypen stöds inte" + +#: src/labels.h:491 +msgid "416 - Requested Range Not Satisfiable: Cannot supply that portion" +msgstr "" +"416 - Begärd räckvidd Ej Tillfredställande: Kan inte leverera den delen" + +#: src/labels.h:493 +msgid "417 - Expectation Failed" +msgstr "417 - Förväntning misslyckades" + +#: src/labels.h:495 +#, fuzzy +msgid "418 - I'm a teapot" +msgstr "Jag är en tekanna" + +#: src/labels.h:497 +msgid "419 - Page Expired: Laravel Framework when a CSRF Token is missing" +msgstr "" + +#: src/labels.h:499 +msgid "420 - Method Failure: Spring Framework when a method has failed" +msgstr "" + +#: src/labels.h:501 +msgid "421 - Misdirected Request" +msgstr "421 - Felriktad förfrågan" + +#: src/labels.h:503 +msgid "422 - Unprocessable Entity due to semantic errors: WebDAV" +msgstr "422 - Obearbetad entitet på grund av semantiska fel: WebDAV" + +#: src/labels.h:505 +msgid "423 - The resource that is being accessed is locked" +msgstr "423 - Resursen som nås är låst" + +#: src/labels.h:507 +msgid "424 - Failed Dependency: WebDAV" +msgstr "424 - Misslyckad beroende: WebDAV" + +#: src/labels.h:509 +msgid "426 - Upgrade Required: Client should switch to a different protocol" +msgstr "426 - Uppgradering krävs: Klienten ska byta till ett annat protokoll" + +#: src/labels.h:511 +msgid "428 - Precondition Required" +msgstr "428 - Förutsättning krävs" + +#: src/labels.h:513 +msgid "429 - Too Many Requests: The user has sent too many requests" +msgstr "" +"429 - För många förfrågningar: Användaren har skickat för många förfrågningar" + +#: src/labels.h:515 +msgid "" +"430 - Request Header Fields Too Large: Too many URLs are requested within a " +"certain time frame" +msgstr "" + +#: src/labels.h:517 +msgid "431 - Request Header Fields Too Large" +msgstr "431 - Begär headerfält för stort" + +#: src/labels.h:519 +msgid "440 - Login Time-out: The client's session has expired" +msgstr "" + +#: src/labels.h:521 +#, fuzzy +msgid "449 - Retry With: The server cannot honour the request" +msgstr "408 - Begär tidsavbrott: Server slutade vänta på begäran" + +#: src/labels.h:523 +msgid "" +"450 - Blocked by Windows Parental Controls: The Microsoft extension code " +"indicated" +msgstr "" + +#: src/labels.h:525 +msgid "451 - Unavailable For Legal Reasons" +msgstr "451 - Ej tillgänglig för juridiska skäl" + +#: src/labels.h:527 +msgid "444 - (Nginx) Connection closed without sending any headers" +msgstr "444 - (Nginx) Anslutningen är stängd utan att skicka några rubriker" + +#: src/labels.h:529 +msgid "460 - AWS Elastic Load Balancing: Client closed the connection " +msgstr "" + +#: src/labels.h:531 +msgid "" +"463 - AWS Elastic Load Balancing: The load balancer received more than 30 IP " +"addresses" +msgstr "" + +#: src/labels.h:533 +msgid "464 - AWS Elastic Load Balancing: Incompatible protocol versions" +msgstr "" + +#: src/labels.h:535 +msgid "494 - (Nginx) Request Header Too Large" +msgstr "494 - (Nginx) Begär Header För Stor" + +#: src/labels.h:537 +msgid "495 - (Nginx) SSL client certificate error" +msgstr "495 - (Nginx) SSL-klientcertifikatfel" + +#: src/labels.h:539 +msgid "496 - (Nginx) Client didn't provide certificate" +msgstr "496 - (Nginx) Klienten lämnade inte certifikat" + +#: src/labels.h:541 +msgid "497 - (Nginx) HTTP request sent to HTTPS port" +msgstr "497 - (Nginx) HTTP-begäran skickad till HTTPS-porten" + +#: src/labels.h:543 +msgid "498 - Invalid Token: an expired or otherwise invalid token" +msgstr "" + +#: src/labels.h:545 +msgid "499 - (Nginx) Connection closed by client while processing request" +msgstr "499 - (Nginx) Anslutning sluten av klienten vid bearbetningsförfrågan" + +#: src/labels.h:547 +msgid "500 - Internal Server Error" +msgstr "500 - Internt serverfel" + +#: src/labels.h:549 +msgid "501 - Not Implemented" +msgstr "501 - Inte Implementerad" + +#: src/labels.h:551 +msgid "502 - Bad Gateway: Received an invalid response from the upstream" +msgstr "502 - Dålig Gateway: Fick ett ogiltigt svar från uppströms" + +#: src/labels.h:553 +msgid "503 - Service Unavailable: The server is currently unavailable" +msgstr "503 - Service Otillgänglig: Servern är för närvarande inte tillgänglig" + +#: src/labels.h:555 +msgid "504 - Gateway Timeout: The upstream server failed to send request" +msgstr "" +"504 - Gateway Timeout: Uppströms-servern misslyckades med att skicka " +"förfrågan" + +#: src/labels.h:557 +msgid "505 - HTTP Version Not Supported" +msgstr "505 - HTTP-version stöds inte" + +#: src/labels.h:559 +msgid "509 - Bandwidth Limit Exceeded: The server has exceeded the bandwidth" +msgstr "" + +#: src/labels.h:561 +msgid "520 - CloudFlare - Web server is returning an unknown error" +msgstr "520 - CloudFlare - Webbserver returnerar ett okänt fel" + +#: src/labels.h:563 +msgid "521 - CloudFlare - Web server is down" +msgstr "521 - CloudFlare - webbservern är nere" + +#: src/labels.h:565 +msgid "522 - CloudFlare - Connection timed out" +msgstr "522 - CloudFlare - Anslutningen avbröts" + +#: src/labels.h:567 +msgid "523 - CloudFlare - Origin is unreachable" +msgstr "523 - CloudFlare - Ursprung är oåtkomligt" + +#: src/labels.h:569 +msgid "524 - CloudFlare - A timeout occurred" +msgstr "524 - CloudFlare - En timeout inträffade" + +#: src/labels.h:571 +msgid "" +"525 - SSL Handshake Failed: Cloudflare could not negotiate a SSL/TLS " +"handshake" +msgstr "" + +#: src/labels.h:573 +msgid "" +"526 - Invalid SSL Certificate: Cloudflare could not validate the SSL " +"certificate" +msgstr "" + +#: src/labels.h:575 +msgid "527 - Railgun Error: An interrupted connection" +msgstr "" + +#: src/labels.h:577 +msgid "529 - Site is overloaded: A site can not process the request" +msgstr "" + +#: src/labels.h:579 +msgid "530 - Site is frozen: A site has been frozen due to inactivity" +msgstr "" + +#: src/labels.h:581 +msgid "" +"540 - Temporarily Disabled: The requested endpoint has been temporarily " +"disabled" +msgstr "" + +#: src/labels.h:583 +#, fuzzy +msgid "561 - Unauthorized: An error around authentication" +msgstr "401 - Ej auktoriserad: Begäran behöver användarautentisering" + +#: src/labels.h:585 +msgid "" +"598 - Network read timeout error: some HTTP proxies to signal a network read " +"timeout" +msgstr "" + +#: src/labels.h:587 +msgid "599 - Network Connect Timeout Error: An error used by some HTTP proxies" +msgstr "" + +#: src/labels.h:589 +msgid "783 - Unexpected Token: The request includes a JSON syntax error" +msgstr "" + +#, fuzzy +#~ msgid "Referers" +#~ msgstr "Hänvisningar" diff --git a/po/uk.po b/po/uk.po new file mode 100644 index 0000000000..ee3a92db24 --- /dev/null +++ b/po/uk.po @@ -0,0 +1,1084 @@ +msgid "" +msgstr "" +"Project-Id-Version: goaccess 1.5.6\n" +"Report-Msgid-Bugs-To: hello@goaccess.io\n" +"POT-Creation-Date: 2024-04-11 20:17-0500\n" +"PO-Revision-Date: 2022-04-21 10:17+0300\n" +"Last-Translator: Artyom Karlov \n" +"Language-Team: \n" +"Language: uk\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.3.1\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && " +"n%10<=4 && (n%100<12 || n%100>14) ? 1 : 2);\n" + +#: src/labels.h:45 +msgid "en" +msgstr "uk" + +#: src/labels.h:48 +msgid "Exp. Panel" +msgstr "Розг. панель" + +#: src/labels.h:49 +msgid "Help" +msgstr "Допомога" + +#: src/labels.h:50 +msgid "Quit" +msgstr "Вихід" + +#: src/labels.h:51 +msgid "Total" +msgstr "Всього" + +#: src/labels.h:54 +msgid "[x] ASC [ ] DESC" +msgstr "[x] ЗБІЛ [ ] ЗМЕН" + +#: src/labels.h:55 +msgid "[ ] ASC [x] DESC" +msgstr "[ ] ЗБІЛ [x] ЗМЕН" + +#: src/labels.h:58 +#, c-format +msgid "[Active Panel: %1$s]" +msgstr "[Активна панель: %1$s]" + +#: src/labels.h:59 +msgid "[q]uit GoAccess" +msgstr "[q] Вийти з GoAccess" + +#: src/labels.h:60 +msgid "[?] Help [Enter] Exp. Panel" +msgstr "[?] Допомога [Enter] Розг. панель" + +#: src/labels.h:61 +msgid "Dashboard" +msgstr "Дашборд" + +#: src/labels.h:62 +msgid "Dashboard - Overall Analyzed Requests" +msgstr "Дашборд - Проаналізовані запити" + +#: src/labels.h:63 +msgid "Overall Analyzed Requests" +msgstr "Проаналізовані запити" + +#: src/labels.h:65 src/labels.h:86 +msgid "Tx. Amount" +msgstr "Вих. трафік" + +#: src/labels.h:66 +msgid "Date/Time" +msgstr "Дата/час" + +#: src/labels.h:67 +msgid "Excl. IP Hits" +msgstr "Хітів з викл. IP" + +#: src/labels.h:68 +msgid "Failed Requests" +msgstr "Невдалих запитів" + +#: src/labels.h:69 +msgid "Log Parsing Time" +msgstr "Час парсингу лога" + +#: src/labels.h:70 +msgid "Log Size" +msgstr "Розмір лога" + +#: src/labels.h:71 +msgid "Log Source" +msgstr "Джерело лога" + +#: src/labels.h:72 src/labels.h:187 +msgid "Referrers" +msgstr "Посил. сторінок" + +#: src/labels.h:73 +msgid "Total Requests" +msgstr "Всього запитів" + +#: src/labels.h:74 +msgid "Static Files" +msgstr "Статичних файлів" + +#: src/labels.h:75 src/labels.h:159 +msgid "Not Found" +msgstr "Не знайдено" + +#: src/labels.h:76 +msgid "Requested Files" +msgstr "Запитаних файлів" + +#: src/labels.h:77 +msgid "Unique Visitors" +msgstr "Унікальних відвідувачів" + +#: src/labels.h:78 +msgid "Valid Requests" +msgstr "Валідних запитів" + +#: src/labels.h:81 +msgid "Hits" +msgstr "Хіти" + +#: src/labels.h:82 +msgid "h%" +msgstr "х%" + +#: src/labels.h:83 src/labels.h:110 +msgid "Visitors" +msgstr "Відвідувачі" + +#: src/labels.h:84 +msgid "Vis." +msgstr "Відв." + +#: src/labels.h:85 +msgid "v%" +msgstr "в%" + +#: src/labels.h:87 +msgid "Avg. T.S." +msgstr "Сер. ч. о." + +#: src/labels.h:88 +msgid "Cum. T.S." +msgstr "Заг. ч. о." + +#: src/labels.h:89 +msgid "Max. T.S." +msgstr "Макс. ч. о." + +#: src/labels.h:90 +msgid "Method" +msgstr "Метод" + +#: src/labels.h:91 +msgid "Mtd" +msgstr "Мтд" + +#: src/labels.h:92 +msgid "Protocol" +msgstr "Протокол" + +#: src/labels.h:93 +msgid "Proto" +msgstr "Прот." + +#: src/labels.h:94 +msgid "City" +msgstr "Місто" + +#: src/labels.h:95 src/labels.h:211 src/labels.h:215 +msgid "ASN" +msgstr "" + +#: src/labels.h:96 +msgid "Country" +msgstr "Країна" + +#: src/labels.h:97 +msgid "Hostname" +msgstr "Ім'я хоста" + +#: src/labels.h:98 +msgid "Data" +msgstr "Дані" + +#: src/labels.h:100 +msgid "Hits/Visitors" +msgstr "Хіти/відвідувачі" + +#: src/labels.h:104 +msgid "Unique visitors per day" +msgstr "Унікальні відвідувачі по днях" + +#: src/labels.h:106 +msgid "Unique visitors per day - Including spiders" +msgstr "Унікальні відвідувачі по днях - Включаючи павуків" + +#: src/labels.h:108 +msgid "Hits having the same IP, date and agent are a unique visit." +msgstr "" +"Хіти, що мають однакові IP, дату та юзер-агента, вважаються унікальним " +"відвідуванням." + +#: src/labels.h:113 +msgid "Requested Files (URLs)" +msgstr "Запитані файли (URL'и)" + +#: src/labels.h:115 +msgid "Top requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Топ запитів, відсортованих за хітами [, сер., заг., макс. часом обсл., " +"методом, протоколом]" + +#: src/labels.h:117 +msgid "Requests" +msgstr "Запити" + +#: src/labels.h:120 src/labels.h:124 +msgid "Static Requests" +msgstr "Статичні запити" + +#: src/labels.h:122 +msgid "Top static requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Том статичних запитів, відсортованих за хітами [, сер., заг., макс. часом " +"обсл., методом, протоколом]" + +#: src/labels.h:127 +msgid "Time Distribution" +msgstr "Розподіл за часом" + +#: src/labels.h:129 +msgid "Data sorted by hour [, avgts, cumts, maxts]" +msgstr "Дані, відсортовані за годинами [, сер., заг., макс. часом обсл.]" + +#: src/labels.h:131 +msgid "Time" +msgstr "Час" + +#: src/labels.h:134 src/labels.h:138 +msgid "Virtual Hosts" +msgstr "Віртуальні хости" + +#: src/labels.h:136 src/labels.h:143 src/labels.h:150 +msgid "Data sorted by hits [, avgts, cumts, maxts]" +msgstr "Дані, відсортовані за хітами [, сер., заг., макс. часом обсл.]" + +#: src/labels.h:141 +msgid "Remote User (HTTP authentication)" +msgstr "Віддалений користувач (HTTP-аутентифікація)" + +#: src/labels.h:145 +msgid "Remote User" +msgstr "Віддалений користувач" + +#: src/labels.h:148 +msgid "The cache status of the object served" +msgstr "Статус кеша об'єкта, що обслуговується" + +#: src/labels.h:152 +msgid "Cache Status" +msgstr "Статус кеша" + +#: src/labels.h:155 +msgid "Not Found URLs (404s)" +msgstr "Незнайдені URL'и (404-і)" + +#: src/labels.h:157 +msgid "Top not found URLs sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"Топ незнайдених URL'ів, відсортованих за хітами [, сер., заг., макс. часом " +"обсл., методом, протоколом]" + +#: src/labels.h:162 +msgid "Visitor Hostnames and IPs" +msgstr "Імена хостів та IP відвідувачів" + +#: src/labels.h:164 +msgid "Top visitor hosts sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Топ хостів відвідувачів, відсортованих за хітами [, сер., заг., макс. часом " +"обсл.]" + +#: src/labels.h:166 +msgid "Hosts" +msgstr "Хости" + +#: src/labels.h:169 +msgid "Operating Systems" +msgstr "Операційні системи" + +#: src/labels.h:171 +msgid "Top Operating Systems sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Топ операційних систем, відсортованих за хітами [, сер., заг., макс. часом " +"обсл.]" + +#: src/labels.h:173 +msgid "OS" +msgstr "ОС" + +#: src/labels.h:176 src/labels.h:180 +msgid "Browsers" +msgstr "Браузери" + +#: src/labels.h:178 +msgid "Top Browsers sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Топ браузерів, відсортованих за хітами [, сер., заг., макс. часом обсл.]" + +#: src/labels.h:183 +#, fuzzy +msgid "Referrer URLs" +msgstr "Сторінки, що посилаються" + +#: src/labels.h:185 +#, fuzzy +msgid "Top Requested Referrers sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Топ сторінок, що посилаються, відсортованих за хітами [, сер., заг., макс. " +"часом обсл.]" + +#: src/labels.h:190 src/labels.h:194 +msgid "Referring Sites" +msgstr "Сайти, що посилаються" + +#: src/labels.h:192 +msgid "Top Referring Sites sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Топ сайтів, що посилаються, відсортованих за хітами [, сер., заг., макс. " +"часом обсл.]" + +#: src/labels.h:197 +msgid "Keyphrases from Google's search engine" +msgstr "Ключові слова з пошукової системи Google" + +#: src/labels.h:199 +msgid "Top Keyphrases sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Том ключових слів, відсортованих за хітами [, сер., заг., макс. часом обсл.]" + +#: src/labels.h:201 +msgid "Keyphrases" +msgstr "Ключові слова" + +#: src/labels.h:204 src/labels.h:208 +msgid "Geo Location" +msgstr "Географічне розташування" + +#: src/labels.h:206 +msgid "Continent > Country sorted by unique hits [, avgts, cumts, maxts]" +msgstr "" +"Континенти > країни, відсортовані за унікальними хітами [, сер., заг., макс. " +"часом обсл.]" + +#: src/labels.h:213 +msgid "Autonomous System Numbers/Organizations (ASNs)" +msgstr "" + +#: src/labels.h:218 +msgid "HTTP Status Codes" +msgstr "Коди відповідей HTTP" + +#: src/labels.h:220 +msgid "Top HTTP Status Codes sorted by hits [, avgts, cumts, maxts]" +msgstr "" +"Топ кодів відповідей HTTP, відсортованих за хітами [, сер., заг., макс. " +"часом обсл.]" + +#: src/labels.h:222 +msgid "Status Codes" +msgstr "Коди відповідей" + +#: src/labels.h:225 src/labels.h:229 +msgid "MIME Types" +msgstr "MIME-типи" + +#: src/labels.h:227 +msgid "File types shipped out" +msgstr "Типи відправлених файлів" + +#: src/labels.h:232 +msgid "Encryption settings" +msgstr "Налаштування шифрування" + +#: src/labels.h:234 +msgid "TLS version and picked algorithm" +msgstr "Версія TLS та вибраний алгоритм" + +#: src/labels.h:236 +msgid "TLS Settings" +msgstr "Налаштування TLS" + +#: src/labels.h:240 +msgid "[ ] case sensitive" +msgstr "[ ] враховувати регістр" + +#: src/labels.h:242 +msgid "[x] case sensitive" +msgstr "[x] враховувати регістр" + +#: src/labels.h:244 +msgid "Regex allowed - ^g to cancel - TAB switch case" +msgstr "Дозволені рег. вирази - ^g відміна - TAB врах. регістру" + +#: src/labels.h:246 +msgid "Find pattern in all views" +msgstr "Пошук шаблону в усіх панелях" + +#: src/labels.h:250 +msgid "Log Format Configuration" +msgstr "Налаштування формату лога" + +#: src/labels.h:252 +msgid "[SPACE] to toggle - [ENTER] to proceed - [q] to quit" +msgstr "[SPACE] переключення - [ENTER] обробити - [q] вийти" + +#: src/labels.h:254 +msgid "Log Format - [c] to add/edit format" +msgstr "Формат логу - [c] додати/змінити формат" + +#: src/labels.h:256 +msgid "Date Format - [d] to add/edit format" +msgstr "Формат дати - [d] додати/змінити формат" + +#: src/labels.h:258 +msgid "Time Format - [t] to add/edit format" +msgstr "Формат часу - [t] додати/змінити формат" + +#: src/labels.h:260 src/labels.h:264 +msgid "[UP/DOWN] to scroll - [q] to close window" +msgstr "[ВГОРУ/ВНИЗ] прокрутка - [q] закрити вікно" + +#: src/labels.h:266 +#, c-format +msgid "User Agents for %1$s" +msgstr "Юзер-агенти для %1$s" + +#: src/labels.h:270 +msgid "Scheme Configuration" +msgstr "Налаштування схеми" + +#: src/labels.h:272 +msgid "[ENTER] to use scheme - [q]uit" +msgstr "[ENTER] використовувати схему - [q] вийти" + +#: src/labels.h:276 +msgid "Sort active module by" +msgstr "Сортування активного модуля" + +#: src/labels.h:278 +msgid "[ENTER] select - [TAB] sort - [q]uit" +msgstr "[ENTER] обрати - [TAB] порядок - [q] вийти" + +#: src/labels.h:282 +msgid "GoAccess Quick Help" +msgstr "Швидка допомога по GoAccess" + +#: src/labels.h:284 +msgid "[UP/DOWN] to scroll - [q] to quit" +msgstr "[ВГОРУ/ВНИЗ] прокрутка - [q] вийти" + +#: src/labels.h:288 +#, fuzzy +msgid "In-Memory with On-Disk Persistent Storage." +msgstr "У пам'яті зі зберіганням на диску." + +#: src/labels.h:292 +msgid "Format Errors - Verify your log/date/time format" +msgstr "Помилки формату - Перевірте ваш формат лога/дати/часу" + +#: src/labels.h:294 +msgid "No date format was found on your conf file." +msgstr "Формат дати у вашому конфігураційному файлі не знайдений." + +#: src/labels.h:296 +msgid "No log format was found on your conf file." +msgstr "Формат лога у вашому конфігураційному файлі не знайдений." + +#: src/labels.h:298 +msgid "No time format was found on your conf file." +msgstr "Формат часу у вашому конфігураційному файлі не знайдений." + +#: src/labels.h:300 +msgid "No default config file found." +msgstr "Стандартний конфігураційний файл не знайдений." + +#: src/labels.h:302 +msgid "You may specify one with" +msgstr "Ви можете задати його за допомогою" + +#: src/labels.h:304 +msgid "producing the following errors" +msgstr "призводить до наступних помилок" + +#: src/labels.h:306 +#, c-format +msgid "Parsed %1$d lines" +msgstr "Оброблено %1$d рядків" + +#: src/labels.h:308 +msgid "Please report it by opening an issue on GitHub" +msgstr "Будь ласка, повідомте про це, відкривши issue на GitHub" + +#: src/labels.h:310 +msgid "Select a time format." +msgstr "Оберіть формат часу." + +#: src/labels.h:312 +msgid "Select a date format." +msgstr "Оберіть формат дати." + +#: src/labels.h:314 +msgid "Select a log format." +msgstr "Оберіть формат лога." + +#: src/labels.h:316 +#, c-format +msgid "'%1$s' panel is disabled" +msgstr "Панель '%1$s' відключена" + +#: src/labels.h:318 +msgid "No input data was provided nor there's data to restore." +msgstr "Не надано ні вхідних даних, ні даних для відновлення." + +#: src/labels.h:320 +msgid "Unable to allocate memory for a log instance." +msgstr "" + +#: src/labels.h:322 +msgid "Unable to find the given log." +msgstr "" + +#: src/labels.h:326 +msgid "For more details visit" +msgstr "Подробиці за посиланням" + +#: src/labels.h:328 +msgid "Last Updated" +msgstr "Останнє оновлення" + +#: src/labels.h:330 +msgid "WebSocket server ready to accept new client connections" +msgstr "WebSocket-сервер готовий до прийому нових з'єднань" + +#: src/labels.h:333 +msgid "The following options can also be supplied to the command" +msgstr "Наступні опції також можуть використовуватися з командою" + +#: src/labels.h:335 +msgid "Examples can be found by running" +msgstr "Приклади можна знайти, запустивши" + +#: src/labels.h:338 +msgid "Server Statistics" +msgstr "Статистика сервера" + +#: src/labels.h:340 +msgid "Theme" +msgstr "Тема" + +#: src/labels.h:342 +msgid "Dark Gray" +msgstr "Темно-сіра" + +#: src/labels.h:344 +msgid "Bright" +msgstr "Світла" + +#: src/labels.h:346 +msgid "Dark Blue" +msgstr "Темно-синя" + +#: src/labels.h:348 +msgid "Dark Purple" +msgstr "Темно-фіолетова" + +#: src/labels.h:350 +msgid "Panels" +msgstr "Панелі" + +#: src/labels.h:352 +msgid "Items per Page" +msgstr "Елементів на сторінці" + +#: src/labels.h:354 +msgid "Tables" +msgstr "Таблиці" + +#: src/labels.h:356 +msgid "Display Tables" +msgstr "Показувати таблиці" + +#: src/labels.h:358 +msgid "Auto-Hide on Small Devices" +msgstr "Автоприховування на маленьких пристроях" + +#: src/labels.h:360 +msgid "Automatically hide tables on small screen devices" +msgstr "Автоматично приховувати таблиці на пристроях з маленькими екранами" + +#: src/labels.h:362 +msgid "Toggle Panel" +msgstr "Перемикання панелі" + +#: src/labels.h:364 +msgid "Layout" +msgstr "Розташування" + +#: src/labels.h:366 +msgid "Horizontal" +msgstr "Горизонтальне" + +#: src/labels.h:368 +msgid "Vertical" +msgstr "Вертикальне" + +#: src/labels.h:370 +msgid "WideScreen" +msgstr "Широкоекранне" + +#: src/labels.h:372 +msgid "File Options" +msgstr "Файлові опції" + +#: src/labels.h:374 +msgid "Export as JSON" +msgstr "Експорт в JSON" + +#: src/labels.h:376 +msgid "Panel Options" +msgstr "Налаштування панелі" + +#: src/labels.h:378 +msgid "Previous" +msgstr "Попередня" + +#: src/labels.h:380 +msgid "Next" +msgstr "Наступна" + +#: src/labels.h:382 +msgid "First" +msgstr "Перша" + +#: src/labels.h:384 +msgid "Last" +msgstr "Остання" + +#: src/labels.h:386 +msgid "Chart Options" +msgstr "Налаштування діаграми" + +#: src/labels.h:388 +msgid "Chart" +msgstr "Диаграма" + +#: src/labels.h:390 +msgid "Type" +msgstr "Тип" + +#: src/labels.h:392 +msgid "Area Spline" +msgstr "Згладжені області" + +#: src/labels.h:394 +msgid "Bar" +msgstr "Стовпці" + +#: src/labels.h:396 +msgid "World Map" +msgstr "" + +#: src/labels.h:398 +msgid "Plot Metric" +msgstr "Одиниці виміру" + +#: src/labels.h:400 +msgid "Table Columns" +msgstr "Колонки таблиці" + +#: src/labels.h:404 +msgid "0xx Unofficial Codes" +msgstr "" + +#: src/labels.h:406 +msgid "1xx Informational" +msgstr "1xx Інформаційні" + +#: src/labels.h:408 +msgid "2xx Success" +msgstr "2xx Успішні" + +#: src/labels.h:410 +msgid "3xx Redirection" +msgstr "3xx Перенаправлення" + +#: src/labels.h:412 +msgid "4xx Client Errors" +msgstr "4xx Помилки клієнта" + +#: src/labels.h:414 +msgid "5xx Server Errors" +msgstr "5xx Помилки сервера" + +#: src/labels.h:417 +msgid "0 - Caddy: Unhandled - No configured routes" +msgstr "" + +#: src/labels.h:419 +msgid "100 - Continue: Server received the initial part of the request" +msgstr "100 - Continue: Сервер отримав початкову частину запиту" + +#: src/labels.h:421 +msgid "101 - Switching Protocols: Client asked to switch protocols" +msgstr "101 - Switching Protocols: Клієнт запросив переключення протоколу" + +#: src/labels.h:423 +msgid "200 - OK: The request sent by the client was successful" +msgstr "200 - OK: Запит клієнта виконаний успішно" + +#: src/labels.h:425 +msgid "201 - Created: The request has been fulfilled and created" +msgstr "201 - Created: Запит клієнта виконаний і створений новий ресурс" + +#: src/labels.h:427 +msgid "202 - Accepted: The request has been accepted for processing" +msgstr "202 - Accepted: Запит прийнятий на обробку" + +#: src/labels.h:429 +msgid "203 - Non-authoritative Information: Response from a third party" +msgstr "203 - Non-authoritative Information: Відповідь не з первинного джерела" + +#: src/labels.h:431 +msgid "204 - No Content: Request did not return any content" +msgstr "204 - No Content: Запит не повернув ніякого контенту" + +#: src/labels.h:433 +msgid "205 - Reset Content: Server asked the client to reset the document" +msgstr "205 - Reset Content: Сервер попросив клієнта скинути документ" + +#: src/labels.h:435 +msgid "206 - Partial Content: The partial GET has been successful" +msgstr "206 - Partial Content: Частковий GET-запит виконаний успішно" + +#: src/labels.h:437 +msgid "207 - Multi-Status: WebDAV; RFC 4918" +msgstr "207 - Multi-Status: WebDAV; RFC 4918" + +#: src/labels.h:439 +msgid "208 - Already Reported: WebDAV; RFC 5842" +msgstr "208 - Already Reported: WebDAV; RFC 5842" + +#: src/labels.h:441 +msgid "218 - This is fine: Apache servers. A catch-all error condition" +msgstr "" + +#: src/labels.h:443 +msgid "300 - Multiple Choices: Multiple options for the resource" +msgstr "300 - Multiple Choices: Ресурс має кілька варіантів надання" + +#: src/labels.h:445 +msgid "301 - Moved Permanently: Resource has permanently moved" +msgstr "301 - Moved Permanently: Ресурс переміщений на постійній основі" + +#: src/labels.h:447 +msgid "302 - Moved Temporarily (redirect)" +msgstr "302 - Moved Temporarily (тимчасовий редирект)" + +#: src/labels.h:449 +msgid "303 - See Other Document: The response is at a different URI" +msgstr "303 - See Other Document: Відповідь знаходиться за іншим URI" + +#: src/labels.h:451 +msgid "304 - Not Modified: Resource has not been modified" +msgstr "304 - Not Modified: Ресурс не змінювався" + +#: src/labels.h:453 +msgid "305 - Use Proxy: Can only be accessed through the proxy" +msgstr "305 - Use Proxy: Доступ тільки через проксі" + +#: src/labels.h:455 +msgid "307 - Temporary Redirect: Resource temporarily moved" +msgstr "307 - Temporary Redirect: Ресурс тимчасово переміщений" + +#: src/labels.h:457 +#, fuzzy +msgid "308 - Permanent Redirect" +msgstr "402 - Payment Required" + +#: src/labels.h:459 +msgid "400 - Bad Request: The syntax of the request is invalid" +msgstr "400 - Bad Request: Невірний синтаксис запиту" + +#: src/labels.h:461 +msgid "401 - Unauthorized: Request needs user authentication" +msgstr "401 - Unauthorized: Запит вимагає аутентифікації" + +#: src/labels.h:463 +msgid "402 - Payment Required" +msgstr "402 - Payment Required" + +#: src/labels.h:465 +msgid "403 - Forbidden: Server is refusing to respond to it" +msgstr "403 - Forbidden: Сервер відмовився надати відповідь" + +#: src/labels.h:467 +msgid "404 - Not Found: Requested resource could not be found" +msgstr "404 - Not Found: Запитаний ресурс не знайдений" + +#: src/labels.h:469 +msgid "405 - Method Not Allowed: Request method not supported" +msgstr "405 - Method Not Allowed: Метод запиту не підтримується" + +#: src/labels.h:471 +msgid "406 - Not Acceptable" +msgstr "406 - Not Acceptable" + +#: src/labels.h:473 +msgid "407 - Proxy Authentication Required" +msgstr "407 - Proxy Authentication Required" + +#: src/labels.h:475 +msgid "408 - Request Timeout: Server timed out waiting for the request" +msgstr "408 - Request Timeout: Сервер не дочекався запиту" + +#: src/labels.h:477 +msgid "409 - Conflict: Conflict in the request" +msgstr "409 - Conflict: Конфліктний запит" + +#: src/labels.h:479 +msgid "410 - Gone: Resource requested is no longer available" +msgstr "410 - Gone: Запитаний ресурс більше недоступний" + +#: src/labels.h:481 +msgid "411 - Length Required: Invalid Content-Length" +msgstr "411 - Length Required: Невірний Content-Length" + +#: src/labels.h:483 +msgid "412 - Precondition Failed: Server does not meet preconditions" +msgstr "412 - Precondition Failed: Сервер не виконав попередні умови" + +#: src/labels.h:485 +msgid "413 - Payload Too Large" +msgstr "413 - Payload Too Large" + +#: src/labels.h:487 +msgid "414 - Request-URI Too Long" +msgstr "414 - Request-URI Too Long" + +#: src/labels.h:489 +msgid "415 - Unsupported Media Type: Media type is not supported" +msgstr "415 - Unsupported Media Type: Тип медіа не підтримується" + +#: src/labels.h:491 +msgid "416 - Requested Range Not Satisfiable: Cannot supply that portion" +msgstr "416 - Requested Range Not Satisfiable: Частина не може бути доставлена" + +#: src/labels.h:493 +msgid "417 - Expectation Failed" +msgstr "417 - Expectation Failed" + +#: src/labels.h:495 +#, fuzzy +msgid "418 - I'm a teapot" +msgstr "418 - I’m a teapot" + +#: src/labels.h:497 +msgid "419 - Page Expired: Laravel Framework when a CSRF Token is missing" +msgstr "" + +#: src/labels.h:499 +msgid "420 - Method Failure: Spring Framework when a method has failed" +msgstr "" + +#: src/labels.h:501 +msgid "421 - Misdirected Request" +msgstr "421 - Misdirected Request" + +#: src/labels.h:503 +msgid "422 - Unprocessable Entity due to semantic errors: WebDAV" +msgstr "422 - Unprocessable Entity due to semantic errors: WebDAV" + +#: src/labels.h:505 +msgid "423 - The resource that is being accessed is locked" +msgstr "423 - The resource that is being accessed is locked" + +#: src/labels.h:507 +msgid "424 - Failed Dependency: WebDAV" +msgstr "424 - Failed Dependency: WebDAV" + +#: src/labels.h:509 +msgid "426 - Upgrade Required: Client should switch to a different protocol" +msgstr "426 - Upgrade Required: Клієнт повинен переключити протокол" + +#: src/labels.h:511 +msgid "428 - Precondition Required" +msgstr "428 - Precondition Required" + +#: src/labels.h:513 +msgid "429 - Too Many Requests: The user has sent too many requests" +msgstr "429 - Too Many Requests: Клієнт відправив занадто багато запитів" + +#: src/labels.h:515 +msgid "" +"430 - Request Header Fields Too Large: Too many URLs are requested within a " +"certain time frame" +msgstr "" + +#: src/labels.h:517 +msgid "431 - Request Header Fields Too Large" +msgstr "431 - Request Header Fields Too Large" + +#: src/labels.h:519 +msgid "440 - Login Time-out: The client's session has expired" +msgstr "" + +#: src/labels.h:521 +#, fuzzy +msgid "449 - Retry With: The server cannot honour the request" +msgstr "408 - Request Timeout: Сервер не дочекався запиту" + +#: src/labels.h:523 +msgid "" +"450 - Blocked by Windows Parental Controls: The Microsoft extension code " +"indicated" +msgstr "" + +#: src/labels.h:525 +msgid "451 - Unavailable For Legal Reasons" +msgstr "451 - Unavailable For Legal Reasons" + +#: src/labels.h:527 +msgid "444 - (Nginx) Connection closed without sending any headers" +msgstr "444 - (Nginx) Connection closed without sending any headers" + +#: src/labels.h:529 +msgid "460 - AWS Elastic Load Balancing: Client closed the connection " +msgstr "" + +#: src/labels.h:531 +msgid "" +"463 - AWS Elastic Load Balancing: The load balancer received more than 30 IP " +"addresses" +msgstr "" + +#: src/labels.h:533 +msgid "464 - AWS Elastic Load Balancing: Incompatible protocol versions" +msgstr "" + +#: src/labels.h:535 +msgid "494 - (Nginx) Request Header Too Large" +msgstr "494 - (Nginx) Request Header Too Large" + +#: src/labels.h:537 +msgid "495 - (Nginx) SSL client certificate error" +msgstr "495 - (Nginx) SSL client certificate error" + +#: src/labels.h:539 +msgid "496 - (Nginx) Client didn't provide certificate" +msgstr "496 - (Nginx) Client didn't provide certificate" + +#: src/labels.h:541 +msgid "497 - (Nginx) HTTP request sent to HTTPS port" +msgstr "497 - (Nginx) HTTP request sent to HTTPS port" + +#: src/labels.h:543 +msgid "498 - Invalid Token: an expired or otherwise invalid token" +msgstr "" + +#: src/labels.h:545 +msgid "499 - (Nginx) Connection closed by client while processing request" +msgstr "499 - (Nginx) Connection closed by client while processing request" + +#: src/labels.h:547 +msgid "500 - Internal Server Error" +msgstr "500 - Internal Server Error" + +#: src/labels.h:549 +msgid "501 - Not Implemented" +msgstr "501 - Not Implemented" + +#: src/labels.h:551 +msgid "502 - Bad Gateway: Received an invalid response from the upstream" +msgstr "" +"502 - Bad Gateway: Сервер, який діє як шлюз, отримав недійсну відповідь" + +#: src/labels.h:553 +msgid "503 - Service Unavailable: The server is currently unavailable" +msgstr "503 - Service Unavailable: Сервер недоступний" + +#: src/labels.h:555 +msgid "504 - Gateway Timeout: The upstream server failed to send request" +msgstr "" +"504 - Gateway Timeout: Сервер, який діє як шлюз, не дочекався відповіді" + +#: src/labels.h:557 +msgid "505 - HTTP Version Not Supported" +msgstr "505 - HTTP Version Not Supported" + +#: src/labels.h:559 +msgid "509 - Bandwidth Limit Exceeded: The server has exceeded the bandwidth" +msgstr "" + +#: src/labels.h:561 +msgid "520 - CloudFlare - Web server is returning an unknown error" +msgstr "520 - CloudFlare - Web server is returning an unknown error" + +#: src/labels.h:563 +msgid "521 - CloudFlare - Web server is down" +msgstr "521 - CloudFlare - Web server is down" + +#: src/labels.h:565 +msgid "522 - CloudFlare - Connection timed out" +msgstr "522 - CloudFlare - Connection timed out" + +#: src/labels.h:567 +msgid "523 - CloudFlare - Origin is unreachable" +msgstr "523 - CloudFlare - Origin is unreachable" + +#: src/labels.h:569 +msgid "524 - CloudFlare - A timeout occurred" +msgstr "524 - CloudFlare - A timeout occurred" + +#: src/labels.h:571 +msgid "" +"525 - SSL Handshake Failed: Cloudflare could not negotiate a SSL/TLS " +"handshake" +msgstr "" + +#: src/labels.h:573 +msgid "" +"526 - Invalid SSL Certificate: Cloudflare could not validate the SSL " +"certificate" +msgstr "" + +#: src/labels.h:575 +msgid "527 - Railgun Error: An interrupted connection" +msgstr "" + +#: src/labels.h:577 +msgid "529 - Site is overloaded: A site can not process the request" +msgstr "" + +#: src/labels.h:579 +msgid "530 - Site is frozen: A site has been frozen due to inactivity" +msgstr "" + +#: src/labels.h:581 +msgid "" +"540 - Temporarily Disabled: The requested endpoint has been temporarily " +"disabled" +msgstr "" + +#: src/labels.h:583 +#, fuzzy +msgid "561 - Unauthorized: An error around authentication" +msgstr "401 - Unauthorized: Запит вимагає аутентифікації" + +#: src/labels.h:585 +msgid "" +"598 - Network read timeout error: some HTTP proxies to signal a network read " +"timeout" +msgstr "" + +#: src/labels.h:587 +msgid "599 - Network Connect Timeout Error: An error used by some HTTP proxies" +msgstr "" + +#: src/labels.h:589 +msgid "783 - Unexpected Token: The request includes a JSON syntax error" +msgstr "" + +#, fuzzy +#~ msgid "Referers" +#~ msgstr "Посил. сторінок" diff --git a/po/zh_CN.po b/po/zh_CN.po new file mode 100644 index 0000000000..958a54edb2 --- /dev/null +++ b/po/zh_CN.po @@ -0,0 +1,1063 @@ +msgid "" +msgstr "" +"Project-Id-Version: goaccess 1.5.6\n" +"Report-Msgid-Bugs-To: hello@goaccess.io\n" +"POT-Creation-Date: 2024-04-11 20:17-0500\n" +"PO-Revision-Date: 2017-04-03 09:43+0200\n" +"Last-Translator: Ai\n" +"Language-Team: Ai\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Gtranslator 2.91.7\n" + +#: src/labels.h:45 +msgid "en" +msgstr "zh-CN" + +#: src/labels.h:48 +msgid "Exp. Panel" +msgstr "展开面板" + +#: src/labels.h:49 +msgid "Help" +msgstr "帮助" + +#: src/labels.h:50 +msgid "Quit" +msgstr "退出" + +#: src/labels.h:51 +msgid "Total" +msgstr "总共" + +#: src/labels.h:54 +msgid "[x] ASC [ ] DESC" +msgstr "[x] 递增 [ ] 递减" + +#: src/labels.h:55 +msgid "[ ] ASC [x] DESC" +msgstr "[ ] 递增 [x] 递减" + +#: src/labels.h:58 +#, c-format +msgid "[Active Panel: %1$s]" +msgstr "[当前面板: %1$s]" + +#: src/labels.h:59 +msgid "[q]uit GoAccess" +msgstr "[q]退出GoAccess" + +#: src/labels.h:60 +msgid "[?] Help [Enter] Exp. Panel" +msgstr "[?]帮助 [回车]展开面板" + +#: src/labels.h:61 +msgid "Dashboard" +msgstr "概览" + +#: src/labels.h:62 +msgid "Dashboard - Overall Analyzed Requests" +msgstr "概览-所有已分析的请求" + +#: src/labels.h:63 +msgid "Overall Analyzed Requests" +msgstr "所有已分析的请求" + +#: src/labels.h:65 src/labels.h:86 +msgid "Tx. Amount" +msgstr "数据传输量" + +#: src/labels.h:66 +msgid "Date/Time" +msgstr "时期/时间" + +#: src/labels.h:67 +msgid "Excl. IP Hits" +msgstr "过滤来自此IP的请求" + +#: src/labels.h:68 +msgid "Failed Requests" +msgstr "失败的请求" + +#: src/labels.h:69 +msgid "Log Parsing Time" +msgstr "日志解析耗时" + +#: src/labels.h:70 +msgid "Log Size" +msgstr "日志大小" + +#: src/labels.h:71 +msgid "Log Source" +msgstr "日志文件夹地址" + +#: src/labels.h:72 src/labels.h:187 +msgid "Referrers" +msgstr "来源地址" + +#: src/labels.h:73 +msgid "Total Requests" +msgstr "所有请求" + +#: src/labels.h:74 +msgid "Static Files" +msgstr "静态文件" + +#: src/labels.h:75 src/labels.h:159 +msgid "Not Found" +msgstr "未找到(404)" + +#: src/labels.h:76 +msgid "Requested Files" +msgstr "请求的文件" + +#: src/labels.h:77 +msgid "Unique Visitors" +msgstr "独立访客" + +#: src/labels.h:78 +msgid "Valid Requests" +msgstr "有效的请求" + +#: src/labels.h:81 +msgid "Hits" +msgstr "点击量" + +#: src/labels.h:82 +msgid "h%" +msgstr "" + +#: src/labels.h:83 src/labels.h:110 +msgid "Visitors" +msgstr "访客" + +#: src/labels.h:84 +msgid "Vis." +msgstr "访客" + +#: src/labels.h:85 +msgid "v%" +msgstr "" + +#: src/labels.h:87 +msgid "Avg. T.S." +msgstr "平均响应时" + +#: src/labels.h:88 +msgid "Cum. T.S." +msgstr "总共响应时" + +#: src/labels.h:89 +msgid "Max. T.S." +msgstr "最高响应时" + +#: src/labels.h:90 +msgid "Method" +msgstr "请求方法" + +#: src/labels.h:91 +msgid "Mtd" +msgstr "请求方法" + +#: src/labels.h:92 +msgid "Protocol" +msgstr "协议" + +#: src/labels.h:93 +msgid "Proto" +msgstr "协议" + +#: src/labels.h:94 +msgid "City" +msgstr "城市" + +#: src/labels.h:95 src/labels.h:211 src/labels.h:215 +msgid "ASN" +msgstr "" + +#: src/labels.h:96 +msgid "Country" +msgstr "国家" + +#: src/labels.h:97 +msgid "Hostname" +msgstr "主机名" + +#: src/labels.h:98 +msgid "Data" +msgstr "数据" + +#: src/labels.h:100 +msgid "Hits/Visitors" +msgstr "点击量/访客" + +#: src/labels.h:104 +msgid "Unique visitors per day" +msgstr "每日独立访客" + +#: src/labels.h:106 +msgid "Unique visitors per day - Including spiders" +msgstr "每日独立访客 - 包括网络机器人" + +#: src/labels.h:108 +msgid "Hits having the same IP, date and agent are a unique visit." +msgstr "来自同一IP、时间和Http用户代理的多次点击被视作一次访问" + +#: src/labels.h:113 +msgid "Requested Files (URLs)" +msgstr "请求的文件" + +#: src/labels.h:115 +msgid "Top requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"请求排序按 [点击量, 平均响应时, 总共响应时, 最高响应时, 请求方法, 协议]" + +#: src/labels.h:117 +msgid "Requests" +msgstr "请求" + +#: src/labels.h:120 src/labels.h:124 +msgid "Static Requests" +msgstr "静态请求" + +#: src/labels.h:122 +msgid "Top static requests sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"静态请求排序按 [点击量, 平均响应时, 总共响应时, 最高响应时, 请求方法, 协议]" + +#: src/labels.h:127 +msgid "Time Distribution" +msgstr "时间分配" + +#: src/labels.h:129 +msgid "Data sorted by hour [, avgts, cumts, maxts]" +msgstr "数据列排序按 [小时, 平均响应时, 总共响应时, 最高响应时]" + +#: src/labels.h:131 +msgid "Time" +msgstr "时间" + +#: src/labels.h:134 src/labels.h:138 +msgid "Virtual Hosts" +msgstr "虚拟主机" + +#: src/labels.h:136 src/labels.h:143 src/labels.h:150 +msgid "Data sorted by hits [, avgts, cumts, maxts]" +msgstr "数据列排序按 [点击量, 平均响应时, 总共响应时, 最高响应时]" + +#: src/labels.h:141 +msgid "Remote User (HTTP authentication)" +msgstr "已认证用户(HTTP authentication)" + +#: src/labels.h:145 +msgid "Remote User" +msgstr "已认证用户" + +#: src/labels.h:148 +msgid "The cache status of the object served" +msgstr "服务对象的缓存状态" + +#: src/labels.h:152 +msgid "Cache Status" +msgstr "缓存状态" + +#: src/labels.h:155 +msgid "Not Found URLs (404s)" +msgstr "未找到的URLs" + +#: src/labels.h:157 +msgid "Top not found URLs sorted by hits [, avgts, cumts, maxts, mthd, proto]" +msgstr "" +"未找到的URLs排序按 [点击量, 平均响应时, 总共响应时, 最高响应时, 请求方法, 协" +"议]" + +#: src/labels.h:162 +msgid "Visitor Hostnames and IPs" +msgstr "访客主机名和IP地址" + +#: src/labels.h:164 +msgid "Top visitor hosts sorted by hits [, avgts, cumts, maxts]" +msgstr "访客主机排序按 [点击量, 平均响应时, 总共响应时, 最高响应时]" + +#: src/labels.h:166 +msgid "Hosts" +msgstr "主机" + +#: src/labels.h:169 +msgid "Operating Systems" +msgstr "操作系统" + +#: src/labels.h:171 +msgid "Top Operating Systems sorted by hits [, avgts, cumts, maxts]" +msgstr "操作系统排序按 [点击量, 平均响应时, 总共响应时, 最高响应时]" + +#: src/labels.h:173 +msgid "OS" +msgstr "操作系统" + +#: src/labels.h:176 src/labels.h:180 +msgid "Browsers" +msgstr "浏览器" + +#: src/labels.h:178 +msgid "Top Browsers sorted by hits [, avgts, cumts, maxts]" +msgstr "浏览器排序按 [点击量, 平均响应时, 总共响应时, 最高响应时]" + +#: src/labels.h:183 +#, fuzzy +msgid "Referrer URLs" +msgstr "来源地址URLs" + +#: src/labels.h:185 +#, fuzzy +msgid "Top Requested Referrers sorted by hits [, avgts, cumts, maxts]" +msgstr "来源地址排序按 [点击量, 平均响应时, 总共响应时, 最高响应时]" + +#: src/labels.h:190 src/labels.h:194 +msgid "Referring Sites" +msgstr "推荐网站" + +#: src/labels.h:192 +msgid "Top Referring Sites sorted by hits [, avgts, cumts, maxts]" +msgstr "推荐网站排序按 [点击量, 平均响应时, 总共响应时, 最高响应时]" + +#: src/labels.h:197 +msgid "Keyphrases from Google's search engine" +msgstr "谷歌搜索关键字" + +#: src/labels.h:199 +msgid "Top Keyphrases sorted by hits [, avgts, cumts, maxts]" +msgstr "关键字排序按 [点击量, 平均响应时, 总共响应时, 最高响应时]" + +#: src/labels.h:201 +msgid "Keyphrases" +msgstr "关键字" + +#: src/labels.h:204 src/labels.h:208 +msgid "Geo Location" +msgstr "地理位置" + +#: src/labels.h:206 +msgid "Continent > Country sorted by unique hits [, avgts, cumts, maxts]" +msgstr "大陆 > 国家排序按 [点击量, 平均响应时, 总共响应时, 最高响应时]" + +#: src/labels.h:213 +msgid "Autonomous System Numbers/Organizations (ASNs)" +msgstr "" + +#: src/labels.h:218 +msgid "HTTP Status Codes" +msgstr "HTTP状态码" + +#: src/labels.h:220 +msgid "Top HTTP Status Codes sorted by hits [, avgts, cumts, maxts]" +msgstr "HTTP状态码排序按 [点击量, 平均响应时, 总共响应时, 最高响应时]" + +#: src/labels.h:222 +msgid "Status Codes" +msgstr "状态码" + +#: src/labels.h:225 src/labels.h:229 +msgid "MIME Types" +msgstr "MIME 类型" + +#: src/labels.h:227 +msgid "File types shipped out" +msgstr "发出的文件类型" + +#: src/labels.h:232 +msgid "Encryption settings" +msgstr "加密设置" + +#: src/labels.h:234 +msgid "TLS version and picked algorithm" +msgstr "TLS 版本和挑选算法" + +#: src/labels.h:236 +msgid "TLS Settings" +msgstr "TLS 设置" + +#: src/labels.h:240 +msgid "[ ] case sensitive" +msgstr "[ ] 区分大小写" + +#: src/labels.h:242 +msgid "[x] case sensitive" +msgstr "[x] 区分大小写" + +#: src/labels.h:244 +msgid "Regex allowed - ^g to cancel - TAB switch case" +msgstr "允许正则表达式 - ^g退出 - TAB改变大小写" + +#: src/labels.h:246 +msgid "Find pattern in all views" +msgstr "在所有界面中查找匹配模式" + +#: src/labels.h:250 +msgid "Log Format Configuration" +msgstr "日志格式设置" + +#: src/labels.h:252 +msgid "[SPACE] to toggle - [ENTER] to proceed - [q] to quit" +msgstr "[空格]切换 - [回车]继续 - [q]退出" + +#: src/labels.h:254 +msgid "Log Format - [c] to add/edit format" +msgstr "日志格式 - [c]新建/修改格式" + +#: src/labels.h:256 +msgid "Date Format - [d] to add/edit format" +msgstr "日期格式 - [d]新建/修改格式" + +#: src/labels.h:258 +msgid "Time Format - [t] to add/edit format" +msgstr "时间格式 - [t]新建/修改格式" + +#: src/labels.h:260 src/labels.h:264 +msgid "[UP/DOWN] to scroll - [q] to close window" +msgstr "[UP/DOWN]上下滚动 - [q]退出" + +#: src/labels.h:266 +#, c-format +msgid "User Agents for %1$s" +msgstr "用户代理 %1$s" + +#: src/labels.h:270 +msgid "Scheme Configuration" +msgstr "颜色方案设置" + +#: src/labels.h:272 +msgid "[ENTER] to use scheme - [q]uit" +msgstr "[回车]选取方案 - [q]退出" + +#: src/labels.h:276 +msgid "Sort active module by" +msgstr "当前选择栏目排序" + +#: src/labels.h:278 +msgid "[ENTER] select - [TAB] sort - [q]uit" +msgstr "[回车]选择 - [TAB]排序 - [q]退出" + +#: src/labels.h:282 +msgid "GoAccess Quick Help" +msgstr "GoAccess快速帮助" + +#: src/labels.h:284 +msgid "[UP/DOWN] to scroll - [q] to quit" +msgstr "[UP/DOWN]上下滚动 - [q]退出" + +#: src/labels.h:288 +msgid "In-Memory with On-Disk Persistent Storage." +msgstr "具有磁盘持久存储的内存中" + +#: src/labels.h:292 +msgid "Format Errors - Verify your log/date/time format" +msgstr "格式错误 - 请检查你的日志/日期/时间格式" + +#: src/labels.h:294 +msgid "No date format was found on your conf file." +msgstr "未在配置文件中设置日期格式" + +#: src/labels.h:296 +msgid "No log format was found on your conf file." +msgstr "未在配置文件中设置日志格式" + +#: src/labels.h:298 +msgid "No time format was found on your conf file." +msgstr "未在配置文件中设置时间格式" + +#: src/labels.h:300 +msgid "No default config file found." +msgstr "未找到默认的配置文件" + +#: src/labels.h:302 +msgid "You may specify one with" +msgstr "你可以指定配置文件" + +#: src/labels.h:304 +msgid "producing the following errors" +msgstr "出现以下错误" + +#: src/labels.h:306 +#, c-format +msgid "Parsed %1$d lines" +msgstr "已解析 %1$d 行" + +#: src/labels.h:308 +msgid "Please report it by opening an issue on GitHub" +msgstr "请在GitHub中添加一个issue来给我们反馈信息" + +#: src/labels.h:310 +msgid "Select a time format." +msgstr "选择时间格式" + +#: src/labels.h:312 +msgid "Select a date format." +msgstr "选择日期格式" + +#: src/labels.h:314 +msgid "Select a log format." +msgstr "选择日志格式" + +#: src/labels.h:316 +#, c-format +msgid "'%1$s' panel is disabled" +msgstr "'%1$s' 面板已禁用" + +#: src/labels.h:318 +msgid "No input data was provided nor there's data to restore." +msgstr "没有提供输入数据,也没有要恢复的数据" + +#: src/labels.h:320 +msgid "Unable to allocate memory for a log instance." +msgstr "" + +#: src/labels.h:322 +msgid "Unable to find the given log." +msgstr "" + +#: src/labels.h:326 +msgid "For more details visit" +msgstr "更多信息请访问" + +#: src/labels.h:328 +msgid "Last Updated" +msgstr "最近更新" + +#: src/labels.h:330 +msgid "WebSocket server ready to accept new client connections" +msgstr "WebSocket服务器已准备接收来自客户的连接" + +#: src/labels.h:333 +msgid "The following options can also be supplied to the command" +msgstr "你也可以在command中选择以下选项" + +#: src/labels.h:335 +msgid "Examples can be found by running" +msgstr "运行一下指令查看更多示例" + +#: src/labels.h:338 +msgid "Server Statistics" +msgstr "服务器统计信息" + +#: src/labels.h:340 +msgid "Theme" +msgstr "主题" + +#: src/labels.h:342 +msgid "Dark Gray" +msgstr "深黑" + +#: src/labels.h:344 +msgid "Bright" +msgstr "明亮" + +#: src/labels.h:346 +msgid "Dark Blue" +msgstr "深蓝" + +#: src/labels.h:348 +#, fuzzy +msgid "Dark Purple" +msgstr "深紫色" + +#: src/labels.h:350 +msgid "Panels" +msgstr "面板" + +#: src/labels.h:352 +msgid "Items per Page" +msgstr "每页项目" + +#: src/labels.h:354 +msgid "Tables" +msgstr "表格" + +#: src/labels.h:356 +msgid "Display Tables" +msgstr "显示表格" + +#: src/labels.h:358 +msgid "Auto-Hide on Small Devices" +msgstr "屏幕过小时自动隐藏" + +#: src/labels.h:360 +msgid "Automatically hide tables on small screen devices" +msgstr "屏幕过小时自动隐藏表格" + +#: src/labels.h:362 +msgid "Toggle Panel" +msgstr "切换面板" + +#: src/labels.h:364 +msgid "Layout" +msgstr "布局" + +#: src/labels.h:366 +msgid "Horizontal" +msgstr "横向" + +#: src/labels.h:368 +msgid "Vertical" +msgstr "纵向" + +#: src/labels.h:370 +msgid "WideScreen" +msgstr "宽屏" + +#: src/labels.h:372 +msgid "File Options" +msgstr "文件选项" + +#: src/labels.h:374 +msgid "Export as JSON" +msgstr "导出为JSON文件" + +#: src/labels.h:376 +msgid "Panel Options" +msgstr "面板选项" + +#: src/labels.h:378 +msgid "Previous" +msgstr "后退" + +#: src/labels.h:380 +msgid "Next" +msgstr "前进" + +#: src/labels.h:382 +msgid "First" +msgstr "" + +#: src/labels.h:384 +msgid "Last" +msgstr "" + +#: src/labels.h:386 +msgid "Chart Options" +msgstr "图表选项" + +#: src/labels.h:388 +msgid "Chart" +msgstr "图表" + +#: src/labels.h:390 +msgid "Type" +msgstr "类型" + +#: src/labels.h:392 +msgid "Area Spline" +msgstr "AreaSpline图表" + +#: src/labels.h:394 +msgid "Bar" +msgstr "条形图" + +#: src/labels.h:396 +msgid "World Map" +msgstr "" + +#: src/labels.h:398 +msgid "Plot Metric" +msgstr "绘制度量" + +# change +#: src/labels.h:400 +msgid "Table Columns" +msgstr "表格列" + +#: src/labels.h:404 +msgid "0xx Unofficial Codes" +msgstr "" + +#: src/labels.h:406 +msgid "1xx Informational" +msgstr "1xx 消息" + +#: src/labels.h:408 +msgid "2xx Success" +msgstr "2xx 成功" + +#: src/labels.h:410 +msgid "3xx Redirection" +msgstr "3xx Url重定向" + +#: src/labels.h:412 +msgid "4xx Client Errors" +msgstr "4xx 客户端错" + +#: src/labels.h:414 +msgid "5xx Server Errors" +msgstr "5xx 服务器错" + +#: src/labels.h:417 +msgid "0 - Caddy: Unhandled - No configured routes" +msgstr "" + +#: src/labels.h:419 +msgid "100 - Continue: Server received the initial part of the request" +msgstr "100 - 继续: 服务器已经接收到请求头" + +#: src/labels.h:421 +msgid "101 - Switching Protocols: Client asked to switch protocols" +msgstr "101 - 更改协议: 客户端被通知变更协议来完成请求" + +#: src/labels.h:423 +msgid "200 - OK: The request sent by the client was successful" +msgstr "200 - 成功: 请求成功" + +#: src/labels.h:425 +msgid "201 - Created: The request has been fulfilled and created" +msgstr "201 - 已创建: 请求成功并且服务器创建了新的资源" + +#: src/labels.h:427 +msgid "202 - Accepted: The request has been accepted for processing" +msgstr "202 - 已接收: 服务器已接受请求,但尚未处理" + +#: src/labels.h:429 +msgid "203 - Non-authoritative Information: Response from a third party" +msgstr "203 - 非授权信息: 服务器已成功处理请求 但返回的信息可能来自另一来源" + +#: src/labels.h:431 +msgid "204 - No Content: Request did not return any content" +msgstr "204 - 无内容: 没有返回任何内容" + +#: src/labels.h:433 +msgid "205 - Reset Content: Server asked the client to reset the document" +msgstr "205 - 重置内容: 服务器已成功处理请求 但没有返回任何内容" + +#: src/labels.h:435 +msgid "206 - Partial Content: The partial GET has been successful" +msgstr "206 - 部分内容: 服务器成功处理了部分GET请求" + +#: src/labels.h:437 +msgid "207 - Multi-Status: WebDAV; RFC 4918" +msgstr "207 - 多状态: WebDAV; RFC 4918" + +#: src/labels.h:439 +msgid "208 - Already Reported: WebDAV; RFC 5842" +msgstr "208 - 已报告: WebDAV; RFC 5842" + +#: src/labels.h:441 +msgid "218 - This is fine: Apache servers. A catch-all error condition" +msgstr "" + +#: src/labels.h:443 +msgid "300 - Multiple Choices: Multiple options for the resource" +msgstr "300 - 多重选择: 资源提供多种选项让客户端选择" + +#: src/labels.h:445 +msgid "301 - Moved Permanently: Resource has permanently moved" +msgstr "301 - 永久移除: 资源已被永久移动到新位置" + +#: src/labels.h:447 +msgid "302 - Moved Temporarily (redirect)" +msgstr "302 - 临时移动" + +#: src/labels.h:449 +msgid "303 - See Other Document: The response is at a different URI" +msgstr "303 - 查看其他位置: 当前请求的响应在另一个URI上被找到" + +#: src/labels.h:451 +msgid "304 - Not Modified: Resource has not been modified" +msgstr "304 - 未修改: 资源未被修改" + +#: src/labels.h:453 +msgid "305 - Use Proxy: Can only be accessed through the proxy" +msgstr "305 - 使用代理: 只能通过代理访问资源" + +#: src/labels.h:455 +msgid "307 - Temporary Redirect: Resource temporarily moved" +msgstr "307 - 临时重定向: 临时从另外的URI响应" + +#: src/labels.h:457 +#, fuzzy +msgid "308 - Permanent Redirect" +msgstr "402 - 需要支付" + +#: src/labels.h:459 +msgid "400 - Bad Request: The syntax of the request is invalid" +msgstr "400 - 错误请求: 客户端语法错误" + +#: src/labels.h:461 +msgid "401 - Unauthorized: Request needs user authentication" +msgstr "401 - 未授权: 当前请求需要用户授权" + +#: src/labels.h:463 +msgid "402 - Payment Required" +msgstr "402 - 需要支付" + +#: src/labels.h:465 +msgid "403 - Forbidden: Server is refusing to respond to it" +msgstr "403 - 禁止: 服务器拒绝响应请求" + +#: src/labels.h:467 +msgid "404 - Not Found: Requested resource could not be found" +msgstr "404 - 未找到: 找不到请求的资源" + +#: src/labels.h:469 +msgid "405 - Method Not Allowed: Request method not supported" +msgstr "405 - 方法禁用: 不支持请求中指定的方法" + +#: src/labels.h:471 +msgid "406 - Not Acceptable" +msgstr "406 - 无法接收" + +#: src/labels.h:473 +msgid "407 - Proxy Authentication Required" +msgstr "407 - 需要代理授权" + +#: src/labels.h:475 +msgid "408 - Request Timeout: Server timed out waiting for the request" +msgstr "408 - 请求超时: 服务器在等候请求时超时" + +#: src/labels.h:477 +msgid "409 - Conflict: Conflict in the request" +msgstr "409 - 冲突: 服务器在完成请求时发生冲突" + +#: src/labels.h:479 +msgid "410 - Gone: Resource requested is no longer available" +msgstr "410 - 已删除: 请求的资源已永久删除" + +#: src/labels.h:481 +msgid "411 - Length Required: Invalid Content-Length" +msgstr "411 - 需要有效长度: Content-Length无效" + +#: src/labels.h:483 +msgid "412 - Precondition Failed: Server does not meet preconditions" +msgstr "412 - 未满足前提条件: 服务器未满足请求中的前提条件" + +#: src/labels.h:485 +msgid "413 - Payload Too Large" +msgstr "413 - 请求实体过大" + +#: src/labels.h:487 +msgid "414 - Request-URI Too Long" +msgstr "414 - 请求的URI过长" + +#: src/labels.h:489 +msgid "415 - Unsupported Media Type: Media type is not supported" +msgstr "415 - 不支持的媒体类型" + +#: src/labels.h:491 +msgid "416 - Requested Range Not Satisfiable: Cannot supply that portion" +msgstr "416 - 请求范围不符合要求" + +#: src/labels.h:493 +msgid "417 - Expectation Failed" +msgstr "417 - 未满足期望值" + +#: src/labels.h:495 +msgid "418 - I'm a teapot" +msgstr "418 - 我是一个茶壶" + +#: src/labels.h:497 +msgid "419 - Page Expired: Laravel Framework when a CSRF Token is missing" +msgstr "" + +#: src/labels.h:499 +msgid "420 - Method Failure: Spring Framework when a method has failed" +msgstr "" + +#: src/labels.h:501 +msgid "421 - Misdirected Request" +msgstr "421 - 被误导的请求" + +#: src/labels.h:503 +msgid "422 - Unprocessable Entity due to semantic errors: WebDAV" +msgstr "422 - 请求格式正确但因存在语法错而无法响应" + +#: src/labels.h:505 +msgid "423 - The resource that is being accessed is locked" +msgstr "423 - 当前资源被锁定" + +#: src/labels.h:507 +msgid "424 - Failed Dependency: WebDAV" +msgstr "424 - 失败的依赖" + +#: src/labels.h:509 +msgid "426 - Upgrade Required: Client should switch to a different protocol" +msgstr "426 - 需要升级: 客户端应该切换到其他的协议" + +#: src/labels.h:511 +msgid "428 - Precondition Required" +msgstr "428 - 需要前提条件" + +#: src/labels.h:513 +msgid "429 - Too Many Requests: The user has sent too many requests" +msgstr "429 - 请求过多: 客户端发送了太多请求" + +#: src/labels.h:515 +msgid "" +"430 - Request Header Fields Too Large: Too many URLs are requested within a " +"certain time frame" +msgstr "" + +#: src/labels.h:517 +msgid "431 - Request Header Fields Too Large" +msgstr "431 - 请求头字段太长" + +#: src/labels.h:519 +msgid "440 - Login Time-out: The client's session has expired" +msgstr "" + +#: src/labels.h:521 +#, fuzzy +msgid "449 - Retry With: The server cannot honour the request" +msgstr "408 - 请求超时: 服务器在等候请求时超时" + +#: src/labels.h:523 +msgid "" +"450 - Blocked by Windows Parental Controls: The Microsoft extension code " +"indicated" +msgstr "" + +#: src/labels.h:525 +msgid "451 - Unavailable For Legal Reasons" +msgstr "451 - 因法律原因不可用" + +#: src/labels.h:527 +msgid "444 - (Nginx) Connection closed without sending any headers" +msgstr "444 - (Nginx) 未发送响应头且连接已关闭" + +#: src/labels.h:529 +msgid "460 - AWS Elastic Load Balancing: Client closed the connection " +msgstr "" + +#: src/labels.h:531 +msgid "" +"463 - AWS Elastic Load Balancing: The load balancer received more than 30 IP " +"addresses" +msgstr "" + +#: src/labels.h:533 +msgid "464 - AWS Elastic Load Balancing: Incompatible protocol versions" +msgstr "" + +#: src/labels.h:535 +msgid "494 - (Nginx) Request Header Too Large" +msgstr "494 - (Nginx) 请求头太大" + +#: src/labels.h:537 +msgid "495 - (Nginx) SSL client certificate error" +msgstr "495 - (Nginx) SSL客户端证书错" + +#: src/labels.h:539 +msgid "496 - (Nginx) Client didn't provide certificate" +msgstr "496 - (Nginx) 客户端未提供证书" + +#: src/labels.h:541 +msgid "497 - (Nginx) HTTP request sent to HTTPS port" +msgstr "497 - (Nginx) HTTP请求被发送到了HTTPS端口" + +#: src/labels.h:543 +msgid "498 - Invalid Token: an expired or otherwise invalid token" +msgstr "" + +#: src/labels.h:545 +msgid "499 - (Nginx) Connection closed by client while processing request" +msgstr "499 - (Nginx) 处理请求时连接被客户端关闭" + +#: src/labels.h:547 +msgid "500 - Internal Server Error" +msgstr "500 - 服务器内部错" + +#: src/labels.h:549 +msgid "501 - Not Implemented" +msgstr "501 - 尚未实施" + +#: src/labels.h:551 +msgid "502 - Bad Gateway: Received an invalid response from the upstream" +msgstr "502 - 错误网关: 服务器作为网关或代理, 从上游服务器收到无效响应" + +#: src/labels.h:553 +msgid "503 - Service Unavailable: The server is currently unavailable" +msgstr "503 - 服务不可用: 服务器无法使用" + +#: src/labels.h:555 +msgid "504 - Gateway Timeout: The upstream server failed to send request" +msgstr "504 - 网关超时: 服务器作为网关或代理, 未从上游服务器收到请求" + +#: src/labels.h:557 +msgid "505 - HTTP Version Not Supported" +msgstr "505 - HTTP版本不受支持" + +#: src/labels.h:559 +msgid "509 - Bandwidth Limit Exceeded: The server has exceeded the bandwidth" +msgstr "" + +#: src/labels.h:561 +msgid "520 - CloudFlare - Web server is returning an unknown error" +msgstr "520 - CloudFlare - 服务器返回一个未知错误" + +#: src/labels.h:563 +msgid "521 - CloudFlare - Web server is down" +msgstr "521 - CloudFlare - 服务器挂了" + +#: src/labels.h:565 +msgid "522 - CloudFlare - Connection timed out" +msgstr "522 - CloudFlare - 连接超时" + +#: src/labels.h:567 +msgid "523 - CloudFlare - Origin is unreachable" +msgstr "523 - CloudFlare - 服务器无法访问" + +#: src/labels.h:569 +msgid "524 - CloudFlare - A timeout occurred" +msgstr "524 - CloudFlare - 服务器响应超时" + +#: src/labels.h:571 +msgid "" +"525 - SSL Handshake Failed: Cloudflare could not negotiate a SSL/TLS " +"handshake" +msgstr "" + +#: src/labels.h:573 +msgid "" +"526 - Invalid SSL Certificate: Cloudflare could not validate the SSL " +"certificate" +msgstr "" + +#: src/labels.h:575 +msgid "527 - Railgun Error: An interrupted connection" +msgstr "" + +#: src/labels.h:577 +msgid "529 - Site is overloaded: A site can not process the request" +msgstr "" + +#: src/labels.h:579 +msgid "530 - Site is frozen: A site has been frozen due to inactivity" +msgstr "" + +#: src/labels.h:581 +msgid "" +"540 - Temporarily Disabled: The requested endpoint has been temporarily " +"disabled" +msgstr "" + +#: src/labels.h:583 +#, fuzzy +msgid "561 - Unauthorized: An error around authentication" +msgstr "401 - 未授权: 当前请求需要用户授权" + +#: src/labels.h:585 +msgid "" +"598 - Network read timeout error: some HTTP proxies to signal a network read " +"timeout" +msgstr "" + +#: src/labels.h:587 +msgid "599 - Network Connect Timeout Error: An error used by some HTTP proxies" +msgstr "" + +#: src/labels.h:589 +msgid "783 - Unexpected Token: The request includes a JSON syntax error" +msgstr "" + +#, fuzzy +#~ msgid "Referers" +#~ msgstr "来源地址" diff --git a/resources/countries-110m.json b/resources/countries-110m.json new file mode 100644 index 0000000000..e2d2b95681 --- /dev/null +++ b/resources/countries-110m.json @@ -0,0 +1 @@ +{"type":"Topology","objects":{"countries":{"type":"GeometryCollection","geometries":[{"type":"MultiPolygon","arcs":[[[0]],[[1]]],"id":"FJ","properties":{"name":"Fiji"}},{"type":"Polygon","arcs":[[2,3,4,5,6,7,8,9,10]],"id":"TZ","properties":{"name":"Tanzania"}},{"type":"Polygon","arcs":[[11,12,13,14]],"id":"EH","properties":{"name":"W. Sahara"}},{"type":"MultiPolygon","arcs":[[[15,16,17,18]],[[19]],[[20]],[[21]],[[22]],[[23]],[[24]],[[25]],[[26]],[[27]],[[28]],[[29]],[[30]],[[31]],[[32]],[[33]],[[34]],[[35]],[[36]],[[37]],[[38]],[[39]],[[40]],[[41]],[[42]],[[43]],[[44]],[[45]],[[46]],[[47]]],"id":"CA","properties":{"name":"Canada"}},{"type":"MultiPolygon","arcs":[[[-19,48,49,50]],[[51]],[[52]],[[53]],[[54]],[[55]],[[56]],[[57]],[[-17,58]],[[59]]],"id":"US","properties":{"name":"United States of America"}},{"type":"Polygon","arcs":[[60,61,62,63,64,65]],"id":"KZ","properties":{"name":"Kazakhstan"}},{"type":"Polygon","arcs":[[-63,66,67,68,69]],"id":"UZ","properties":{"name":"Uzbekistan"}},{"type":"MultiPolygon","arcs":[[[70,71]],[[72]],[[73]],[[74]]],"id":"PG","properties":{"name":"Papua New Guinea"}},{"type":"MultiPolygon","arcs":[[[-72,75]],[[76,77]],[[78]],[[79,80]],[[81]],[[82]],[[83]],[[84]],[[85]],[[86]],[[87]],[[88]],[[89]]],"id":"ID","properties":{"name":"Indonesia"}},{"type":"MultiPolygon","arcs":[[[90,91]],[[92,93,94,95,96,97]]],"id":"AR","properties":{"name":"Argentina"}},{"type":"MultiPolygon","arcs":[[[-92,98]],[[99,-95,100,101]]],"id":"CL","properties":{"name":"Chile"}},{"type":"Polygon","arcs":[[-8,102,103,104,105,106,107,108,109,110,111]],"id":"CD","properties":{"name":"Dem. Rep. Congo"}},{"type":"Polygon","arcs":[[112,113,114,115]],"id":"SO","properties":{"name":"Somalia"}},{"type":"Polygon","arcs":[[-3,116,117,118,-113,119]],"id":"KE","properties":{"name":"Kenya"}},{"type":"Polygon","arcs":[[120,121,122,123,124,125,126,127]],"id":"SD","properties":{"name":"Sudan"}},{"type":"Polygon","arcs":[[-122,128,129,130,131]],"id":"TD","properties":{"name":"Chad"}},{"type":"Polygon","arcs":[[132,133]],"id":"HT","properties":{"name":"Haiti"}},{"type":"Polygon","arcs":[[-133,134]],"id":"DO","properties":{"name":"Dominican Rep."}},{"type":"MultiPolygon","arcs":[[[135]],[[136]],[[137]],[[138]],[[139]],[[140]],[[141,142,143]],[[144]],[[145]],[[146,147,148,149,-66,150,151,152,153,154,155,156,157,158,159,160,161]],[[162]],[[163,164]]],"id":"RU","properties":{"name":"Russia"}},{"type":"MultiPolygon","arcs":[[[165]],[[166]],[[167]]],"id":"BS","properties":{"name":"Bahamas"}},{"type":"Polygon","arcs":[[168]],"id":"FK","properties":{"name":"Falkland Is."}},{"type":"MultiPolygon","arcs":[[[169]],[[-161,170,171,172]],[[173]],[[174]]],"id":"NO","properties":{"name":"Norway"}},{"type":"Polygon","arcs":[[175]],"id":"GL","properties":{"name":"Greenland"}},{"type":"Polygon","arcs":[[176]],"id":"TF","properties":{"name":"Fr. S. Antarctic Lands"}},{"type":"Polygon","arcs":[[177,-77]],"id":"TL","properties":{"name":"Timor-Leste"}},{"type":"Polygon","arcs":[[178,179,180,181,182,183,184],[185]],"id":"ZA","properties":{"name":"South Africa"}},{"type":"Polygon","arcs":[[-186]],"id":"LS","properties":{"name":"Lesotho"}},{"type":"Polygon","arcs":[[-50,186,187,188,189]],"id":"MX","properties":{"name":"Mexico"}},{"type":"Polygon","arcs":[[190,191,-93]],"id":"UY","properties":{"name":"Uruguay"}},{"type":"Polygon","arcs":[[-191,-98,192,193,194,195,196,197,198,199,200]],"id":"BR","properties":{"name":"Brazil"}},{"type":"Polygon","arcs":[[-194,201,-96,-100,202]],"id":"BO","properties":{"name":"Bolivia"}},{"type":"Polygon","arcs":[[-195,-203,-102,203,204,205]],"id":"PE","properties":{"name":"Peru"}},{"type":"Polygon","arcs":[[-196,-206,206,207,208,209,210]],"id":"CO","properties":{"name":"Colombia"}},{"type":"Polygon","arcs":[[-209,211,212,213]],"id":"PA","properties":{"name":"Panama"}},{"type":"Polygon","arcs":[[-213,214,215,216]],"id":"CR","properties":{"name":"Costa Rica"}},{"type":"Polygon","arcs":[[-216,217,218,219]],"id":"NI","properties":{"name":"Nicaragua"}},{"type":"Polygon","arcs":[[-219,220,221,222,223]],"id":"HN","properties":{"name":"Honduras"}},{"type":"Polygon","arcs":[[-222,224,225]],"id":"SV","properties":{"name":"El Salvador"}},{"type":"Polygon","arcs":[[-189,226,227,-223,-226,228]],"id":"GT","properties":{"name":"Guatemala"}},{"type":"Polygon","arcs":[[-188,229,-227]],"id":"BZ","properties":{"name":"Belize"}},{"type":"Polygon","arcs":[[-197,-211,230,231]],"id":"VE","properties":{"name":"Venezuela"}},{"type":"Polygon","arcs":[[-198,-232,232,233]],"id":"GY","properties":{"name":"Guyana"}},{"type":"Polygon","arcs":[[-199,-234,234,235]],"id":"SR","properties":{"name":"Suriname"}},{"type":"MultiPolygon","arcs":[[[-200,-236,236]],[[237,238,239,240,241,242,243,244]],[[245]]],"id":"FR","properties":{"name":"France"}},{"type":"Polygon","arcs":[[-205,246,-207]],"id":"EC","properties":{"name":"Ecuador"}},{"type":"Polygon","arcs":[[247]],"id":"PR","properties":{"name":"Puerto Rico"}},{"type":"Polygon","arcs":[[248]],"id":"JM","properties":{"name":"Jamaica"}},{"type":"Polygon","arcs":[[249]],"id":"CU","properties":{"name":"Cuba"}},{"type":"Polygon","arcs":[[-181,250,251,252]],"id":"ZW","properties":{"name":"Zimbabwe"}},{"type":"Polygon","arcs":[[-180,253,254,-251]],"id":"BW","properties":{"name":"Botswana"}},{"type":"Polygon","arcs":[[-179,255,256,257,-254]],"id":"NA","properties":{"name":"Namibia"}},{"type":"Polygon","arcs":[[258,259,260,261,262,263,264]],"id":"SN","properties":{"name":"Senegal"}},{"type":"Polygon","arcs":[[-261,265,266,267,268,269,270]],"id":"ML","properties":{"name":"Mali"}},{"type":"Polygon","arcs":[[-13,271,-266,-260,272]],"id":"MR","properties":{"name":"Mauritania"}},{"type":"Polygon","arcs":[[273,274,275,276,277]],"id":"BJ","properties":{"name":"Benin"}},{"type":"Polygon","arcs":[[-131,278,279,-277,280,-268,281,282]],"id":"NE","properties":{"name":"Niger"}},{"type":"Polygon","arcs":[[-278,-280,283,284]],"id":"NG","properties":{"name":"Nigeria"}},{"type":"Polygon","arcs":[[-130,285,286,287,288,289,-284,-279]],"id":"CM","properties":{"name":"Cameroon"}},{"type":"Polygon","arcs":[[-275,290,291,292]],"id":"TG","properties":{"name":"Togo"}},{"type":"Polygon","arcs":[[-292,293,294,295]],"id":"GH","properties":{"name":"Ghana"}},{"type":"Polygon","arcs":[[-270,296,-295,297,298,299]],"id":"CI","properties":{"name":"Côte d'Ivoire"}},{"type":"Polygon","arcs":[[-262,-271,-300,300,301,302,303]],"id":"GN","properties":{"name":"Guinea"}},{"type":"Polygon","arcs":[[-263,-304,304]],"id":"GW","properties":{"name":"Guinea-Bissau"}},{"type":"Polygon","arcs":[[-299,305,306,-301]],"id":"LR","properties":{"name":"Liberia"}},{"type":"Polygon","arcs":[[-302,-307,307]],"id":"SL","properties":{"name":"Sierra Leone"}},{"type":"Polygon","arcs":[[-269,-281,-276,-293,-296,-297]],"id":"BF","properties":{"name":"Burkina Faso"}},{"type":"Polygon","arcs":[[-108,308,-286,-129,-121,309]],"id":"CF","properties":{"name":"Central African Rep."}},{"type":"Polygon","arcs":[[-107,310,311,312,-287,-309]],"id":"CG","properties":{"name":"Congo"}},{"type":"Polygon","arcs":[[-288,-313,313,314]],"id":"GA","properties":{"name":"Gabon"}},{"type":"Polygon","arcs":[[-289,-315,315]],"id":"GQ","properties":{"name":"Eq. Guinea"}},{"type":"Polygon","arcs":[[-7,316,317,-252,-255,-258,318,-103]],"id":"ZM","properties":{"name":"Zambia"}},{"type":"Polygon","arcs":[[-6,319,-317]],"id":"MW","properties":{"name":"Malawi"}},{"type":"Polygon","arcs":[[-5,320,-184,321,-182,-253,-318,-320]],"id":"MZ","properties":{"name":"Mozambique"}},{"type":"Polygon","arcs":[[-183,-322]],"id":"SZ","properties":{"name":"eSwatini"}},{"type":"MultiPolygon","arcs":[[[-106,322,-311]],[[-104,-319,-257,323]]],"id":"AO","properties":{"name":"Angola"}},{"type":"Polygon","arcs":[[-9,-112,324]],"id":"BI","properties":{"name":"Burundi"}},{"type":"Polygon","arcs":[[325,326,327,328,329,330,331]],"id":"IL","properties":{"name":"Israel"}},{"type":"Polygon","arcs":[[-331,332,333]],"id":"LB","properties":{"name":"Lebanon"}},{"type":"Polygon","arcs":[[334]],"id":"MG","properties":{"name":"Madagascar"}},{"type":"Polygon","arcs":[[-327,335]],"id":"PS","properties":{"name":"Palestine"}},{"type":"Polygon","arcs":[[-265,336]],"id":"GM","properties":{"name":"Gambia"}},{"type":"Polygon","arcs":[[337,338,339]],"id":"TN","properties":{"name":"Tunisia"}},{"type":"Polygon","arcs":[[-12,340,341,-338,342,-282,-267,-272]],"id":"DZ","properties":{"name":"Algeria"}},{"type":"Polygon","arcs":[[-326,343,344,345,346,-328,-336]],"id":"400","properties":{"name":"Jordan"}},{"type":"Polygon","arcs":[[347,348,349,350,351]],"id":"AE","properties":{"name":"United Arab Emirates"}},{"type":"Polygon","arcs":[[352,353]],"id":"QA","properties":{"name":"Qatar"}},{"type":"Polygon","arcs":[[354,355,356]],"id":"KW","properties":{"name":"Kuwait"}},{"type":"Polygon","arcs":[[-345,357,358,359,360,-357,361]],"id":"IQ","properties":{"name":"Iraq"}},{"type":"MultiPolygon","arcs":[[[-351,362,363,364]],[[-349,365]]],"id":"OM","properties":{"name":"Oman"}},{"type":"MultiPolygon","arcs":[[[366]],[[367]]],"id":"VU","properties":{"name":"Vanuatu"}},{"type":"Polygon","arcs":[[368,369,370,371]],"id":"KH","properties":{"name":"Cambodia"}},{"type":"Polygon","arcs":[[-369,372,373,374,375,376]],"id":"TH","properties":{"name":"Thailand"}},{"type":"Polygon","arcs":[[-370,-377,377,378,379]],"id":"LA","properties":{"name":"Laos"}},{"type":"Polygon","arcs":[[-376,380,381,382,383,-378]],"id":"MM","properties":{"name":"Myanmar"}},{"type":"Polygon","arcs":[[-371,-380,384,385]],"id":"VN","properties":{"name":"Vietnam"}},{"type":"MultiPolygon","arcs":[[[386,386,386]],[[-147,387,388,389,390]]],"id":"KP","properties":{"name":"North Korea"}},{"type":"Polygon","arcs":[[-389,391]],"id":"KR","properties":{"name":"South Korea"}},{"type":"Polygon","arcs":[[-149,392]],"id":"MN","properties":{"name":"Mongolia"}},{"type":"Polygon","arcs":[[-383,393,394,395,396,397,398,399,400]],"id":"IN","properties":{"name":"India"}},{"type":"Polygon","arcs":[[-382,401,-394]],"id":"BD","properties":{"name":"Bangladesh"}},{"type":"Polygon","arcs":[[-400,402]],"id":"BT","properties":{"name":"Bhutan"}},{"type":"Polygon","arcs":[[-398,403]],"id":"NP","properties":{"name":"Nepal"}},{"type":"Polygon","arcs":[[-396,404,405,406,407]],"id":"PK","properties":{"name":"Pakistan"}},{"type":"Polygon","arcs":[[-69,408,409,-407,410,411]],"id":"AF","properties":{"name":"Afghanistan"}},{"type":"Polygon","arcs":[[-68,412,413,-409]],"id":"TJ","properties":{"name":"Tajikistan"}},{"type":"Polygon","arcs":[[-62,414,-413,-67]],"id":"KG","properties":{"name":"Kyrgyzstan"}},{"type":"Polygon","arcs":[[-64,-70,-412,415,416]],"id":"TM","properties":{"name":"Turkmenistan"}},{"type":"Polygon","arcs":[[-360,417,418,419,420,421,-416,-411,-406,422]],"id":"IR","properties":{"name":"Iran"}},{"type":"Polygon","arcs":[[-332,-334,423,424,-358,-344]],"id":"SY","properties":{"name":"Syria"}},{"type":"Polygon","arcs":[[-420,425,426,427,428]],"id":"AM","properties":{"name":"Armenia"}},{"type":"Polygon","arcs":[[-172,429,430]],"id":"SE","properties":{"name":"Sweden"}},{"type":"Polygon","arcs":[[-156,431,432,433,434]],"id":"BY","properties":{"name":"Belarus"}},{"type":"Polygon","arcs":[[-155,435,-164,436,437,438,439,440,441,442,-432]],"id":"UA","properties":{"name":"Ukraine"}},{"type":"Polygon","arcs":[[-433,-443,443,444,445,446,-142,447]],"id":"PL","properties":{"name":"Poland"}},{"type":"Polygon","arcs":[[448,449,450,451,452,453,454]],"id":"AT","properties":{"name":"Austria"}},{"type":"Polygon","arcs":[[-441,455,456,457,458,-449,459]],"id":"HU","properties":{"name":"Hungary"}},{"type":"Polygon","arcs":[[-439,460]],"id":"MD","properties":{"name":"Moldova"}},{"type":"Polygon","arcs":[[-438,461,462,463,-456,-440,-461]],"id":"RO","properties":{"name":"Romania"}},{"type":"Polygon","arcs":[[-434,-448,-144,464,465]],"id":"LT","properties":{"name":"Lithuania"}},{"type":"Polygon","arcs":[[-157,-435,-466,466,467]],"id":"LV","properties":{"name":"Latvia"}},{"type":"Polygon","arcs":[[-158,-468,468]],"id":"EE","properties":{"name":"Estonia"}},{"type":"Polygon","arcs":[[-446,469,-453,470,-238,471,472,473,474,475,476]],"id":"DE","properties":{"name":"Germany"}},{"type":"Polygon","arcs":[[-463,477,478,479,480,481]],"id":"BG","properties":{"name":"Bulgaria"}},{"type":"MultiPolygon","arcs":[[[482]],[[-480,483,484,485,486]]],"id":"GR","properties":{"name":"Greece"}},{"type":"MultiPolygon","arcs":[[[-359,-425,487,488,-427,-418]],[[-479,489,-484]]],"id":"TR","properties":{"name":"Turkey"}},{"type":"Polygon","arcs":[[-486,490,491,492,493]],"id":"AL","properties":{"name":"Albania"}},{"type":"Polygon","arcs":[[-458,494,495,496,497,498]],"id":"HR","properties":{"name":"Croatia"}},{"type":"Polygon","arcs":[[-452,499,-239,-471]],"id":"CH","properties":{"name":"Switzerland"}},{"type":"Polygon","arcs":[[-472,-245,500]],"id":"LU","properties":{"name":"Luxembourg"}},{"type":"Polygon","arcs":[[-473,-501,-244,501,502]],"id":"BE","properties":{"name":"Belgium"}},{"type":"Polygon","arcs":[[-474,-503,503]],"id":"NL","properties":{"name":"Netherlands"}},{"type":"Polygon","arcs":[[504,505]],"id":"PT","properties":{"name":"Portugal"}},{"type":"Polygon","arcs":[[-505,506,-242,507]],"id":"ES","properties":{"name":"Spain"}},{"type":"Polygon","arcs":[[508,509]],"id":"IE","properties":{"name":"Ireland"}},{"type":"Polygon","arcs":[[510]],"id":"NC","properties":{"name":"New Caledonia"}},{"type":"MultiPolygon","arcs":[[[511]],[[512]],[[513]],[[514]],[[515]]],"id":"SB","properties":{"name":"Solomon Is."}},{"type":"MultiPolygon","arcs":[[[516]],[[517]]],"id":"NZ","properties":{"name":"New Zealand"}},{"type":"MultiPolygon","arcs":[[[518]],[[519]]],"id":"AU","properties":{"name":"Australia"}},{"type":"Polygon","arcs":[[520]],"id":"LK","properties":{"name":"Sri Lanka"}},{"type":"MultiPolygon","arcs":[[[521]],[[-61,-150,-393,-148,-391,522,-385,-379,-384,-401,-403,-399,-404,-397,-408,-410,-414,-415]]],"id":"CN","properties":{"name":"China"}},{"type":"Polygon","arcs":[[523]],"id":"TW","properties":{"name":"Taiwan"}},{"type":"MultiPolygon","arcs":[[[-451,524,525,-240,-500]],[[526]],[[527]]],"id":"IT","properties":{"name":"Italy"}},{"type":"MultiPolygon","arcs":[[[-476,528]],[[529]]],"id":"DK","properties":{"name":"Denmark"}},{"type":"MultiPolygon","arcs":[[[-510,530]],[[531]]],"id":"GB","properties":{"name":"United Kingdom"}},{"type":"Polygon","arcs":[[532]],"id":"IS","properties":{"name":"Iceland"}},{"type":"MultiPolygon","arcs":[[[-152,533,-421,-429,534]],[[-419,-426]]],"id":"AZ","properties":{"name":"Azerbaijan"}},{"type":"Polygon","arcs":[[-153,-535,-428,-489,535]],"id":"GE","properties":{"name":"Georgia"}},{"type":"MultiPolygon","arcs":[[[536]],[[537]],[[538]],[[539]],[[540]],[[541]],[[542]]],"id":"PH","properties":{"name":"Philippines"}},{"type":"MultiPolygon","arcs":[[[-374,543]],[[-81,544,545,546]]],"id":"MY","properties":{"name":"Malaysia"}},{"type":"Polygon","arcs":[[-546,547]],"id":"BN","properties":{"name":"Brunei"}},{"type":"Polygon","arcs":[[-450,-459,-499,548,-525]],"id":"SI","properties":{"name":"Slovenia"}},{"type":"Polygon","arcs":[[-160,549,-430,-171]],"id":"FI","properties":{"name":"Finland"}},{"type":"Polygon","arcs":[[-442,-460,-455,550,-444]],"id":"SK","properties":{"name":"Slovakia"}},{"type":"Polygon","arcs":[[-445,-551,-454,-470]],"id":"CZ","properties":{"name":"Czechia"}},{"type":"Polygon","arcs":[[-126,551,552,553]],"id":"ER","properties":{"name":"Eritrea"}},{"type":"MultiPolygon","arcs":[[[554]],[[555]],[[556]]],"id":"JP","properties":{"name":"Japan"}},{"type":"Polygon","arcs":[[-193,-97,-202]],"id":"PY","properties":{"name":"Paraguay"}},{"type":"Polygon","arcs":[[-364,557,558]],"id":"YE","properties":{"name":"Yemen"}},{"type":"Polygon","arcs":[[-346,-362,-356,559,-354,560,-352,-365,-559,561]],"id":"SA","properties":{"name":"Saudi Arabia"}},{"type":"MultiPolygon","arcs":[[[562]],[[563]],[[564]],[[565]],[[566]],[[567]],[[568]],[[569]]],"id":"AQ","properties":{"name":"Antarctica"}},{"type":"Polygon","arcs":[[570,571]],"properties":{"name":"N. Cyprus"}},{"type":"Polygon","arcs":[[-572,572]],"id":"CY","properties":{"name":"Cyprus"}},{"type":"Polygon","arcs":[[-341,-15,573]],"id":"MA","properties":{"name":"Morocco"}},{"type":"Polygon","arcs":[[-124,574,575,-329,576]],"id":"EG","properties":{"name":"Egypt"}},{"type":"Polygon","arcs":[[-123,-132,-283,-343,-340,577,-575]],"id":"LY","properties":{"name":"Libya"}},{"type":"Polygon","arcs":[[-114,-119,578,-127,-554,579,580]],"id":"ET","properties":{"name":"Ethiopia"}},{"type":"Polygon","arcs":[[-553,581,582,-580]],"id":"DJ","properties":{"name":"Djibouti"}},{"type":"Polygon","arcs":[[-115,-581,-583,583]],"properties":{"name":"Somaliland"}},{"type":"Polygon","arcs":[[-11,584,-110,585,-117]],"id":"UG","properties":{"name":"Uganda"}},{"type":"Polygon","arcs":[[-10,-325,-111,-585]],"id":"RW","properties":{"name":"Rwanda"}},{"type":"Polygon","arcs":[[-496,586,587]],"id":"BA","properties":{"name":"Bosnia and Herz."}},{"type":"Polygon","arcs":[[-481,-487,-494,588,589]],"id":"MK","properties":{"name":"Macedonia"}},{"type":"Polygon","arcs":[[-457,-464,-482,-590,590,591,-587,-495]],"id":"RS","properties":{"name":"Serbia"}},{"type":"Polygon","arcs":[[-492,592,-497,-588,-592,593]],"id":"ME","properties":{"name":"Montenegro"}},{"type":"Polygon","arcs":[[-493,-594,-591,-589]],"properties":{"name":"Kosovo"}},{"type":"Polygon","arcs":[[594]],"id":"TT","properties":{"name":"Trinidad and Tobago"}},{"type":"Polygon","arcs":[[-109,-310,-128,-579,-118,-586]],"id":"SS","properties":{"name":"S. Sudan"}}]},"land":{"type":"GeometryCollection","geometries":[{"type":"MultiPolygon","arcs":[[[0]],[[1]],[[3,320,184,255,323,104,322,311,313,315,289,284,273,290,293,297,305,307,302,304,263,336,258,272,13,573,341,338,577,575,329,332,423,487,535,153,435,164,436,461,477,489,484,490,592,497,548,525,240,507,505,506,242,501,503,474,528,476,446,142,464,466,468,158,549,430,172,161,387,391,389,522,385,371,372,543,374,380,401,394,404,422,360,354,559,352,560,347,365,349,362,557,561,346,576,124,551,581,583,115,119],[421,416,64,150,533]],[[17,48,186,229,227,223,219,216,213,209,230,232,234,236,200,191,93,100,203,246,207,211,214,217,220,224,228,189,50,15,58]],[[19]],[[20]],[[21]],[[22]],[[23]],[[24]],[[25]],[[26]],[[27]],[[28]],[[29]],[[30]],[[31]],[[32]],[[33]],[[34]],[[35]],[[36]],[[37]],[[38]],[[39]],[[40]],[[41]],[[42]],[[43]],[[44]],[[45]],[[46]],[[47]],[[51]],[[52]],[[53]],[[54]],[[55]],[[56]],[[57]],[[59]],[[70,75]],[[72]],[[73]],[[74]],[[77,177]],[[78]],[[546,79,544,547]],[[81]],[[82]],[[83]],[[84]],[[85]],[[86]],[[87]],[[88]],[[89]],[[90,98]],[[133,134]],[[135]],[[136]],[[137]],[[138]],[[139]],[[140]],[[144]],[[145]],[[162]],[[165]],[[166]],[[167]],[[168]],[[169]],[[173]],[[174]],[[175]],[[176]],[[245]],[[247]],[[248]],[[249]],[[334]],[[366]],[[367]],[[482]],[[508,530]],[[510]],[[511]],[[512]],[[513]],[[514]],[[515]],[[516]],[[517]],[[518]],[[519]],[[520]],[[521]],[[523]],[[526]],[[527]],[[529]],[[531]],[[532]],[[536]],[[537]],[[538]],[[539]],[[540]],[[541]],[[542]],[[554]],[[555]],[[556]],[[562]],[[563]],[[564]],[[565]],[[566]],[[567]],[[568]],[[569]],[[570,572]],[[594]]]}]}},"arcs":[[[99478,40237],[69,98],[96,-171],[-46,-308],[-172,-81],[-153,73],[-27,260],[107,203],[126,-74]],[[0,41087],[57,27],[-34,-284],[-23,-32],[99822,-145],[-177,-124],[-36,220],[139,121],[88,33],[163,184],[-99999,0]],[[59417,50018],[47,-65],[1007,-1203],[19,-343],[399,-590]],[[60889,47817],[-128,-728],[16,-335],[178,-216],[8,-153],[-76,-357],[16,-180],[-18,-282],[97,-370],[115,-583],[101,-129]],[[61198,44484],[-221,-342],[-303,-230],[-167,10],[-99,-177],[-193,-16],[-73,-74],[-334,166],[-209,-48]],[[59599,43773],[-77,804],[-95,275],[-55,164],[-273,110]],[[59099,45126],[-157,177],[-177,100],[-111,99],[-116,150]],[[58538,45652],[-150,745],[-161,330],[-55,343],[27,307],[-50,544]],[[58149,47921],[115,28],[101,214],[108,308],[69,124],[-3,192],[-60,134],[-16,233]],[[58463,49154],[80,74],[16,348],[-110,333]],[[58449,49909],[98,71],[304,-7],[566,45]],[[47592,66920],[1,-40],[-6,-114]],[[47587,66766],[-1,-895],[-911,31],[9,-1512],[-261,-53],[-68,-304],[53,-853],[-1088,4],[-60,-197]],[[45260,62987],[12,249]],[[45272,63236],[5,-1],[625,48],[33,213],[114,265],[92,816],[386,637],[131,745],[86,44],[91,460],[234,63],[100,-76],[126,0],[90,134],[172,19],[-7,317],[42,0]],[[15878,79530],[-38,1],[-537,581],[-199,255],[-503,244],[-155,523],[40,363],[-356,252],[-48,476],[-336,429],[-6,304]],[[13740,82958],[154,285],[-7,373],[-473,376],[-284,674],[-173,424],[-255,266],[-187,242],[-147,306],[-279,-192],[-270,-330],[-247,388],[-194,259],[-271,164],[-273,17],[1,3364],[2,2193]],[[10837,91767],[518,-142],[438,-285],[289,-54],[244,247],[336,184],[413,-72],[416,259],[455,148],[191,-245],[207,138],[62,278],[192,-63],[470,-530],[369,401],[38,-449],[341,97],[105,173],[337,-34],[424,-248],[650,-217],[383,-100],[272,38],[374,-300],[-390,-293],[502,-127],[750,70],[236,103],[296,-354],[302,299],[-283,251],[179,202],[338,27],[223,59],[224,-141],[279,-321],[310,47],[491,-266],[431,94],[405,-14],[-32,367],[247,103],[431,-200],[-2,-559],[177,471],[223,-16],[126,594],[-298,364],[-324,239],[22,653],[329,429],[366,-95],[281,-261],[378,-666],[-247,-290],[517,-120],[-1,-604],[371,463],[332,-380],[-83,-438],[269,-399],[290,427],[202,510],[16,649],[394,-46],[411,-87],[373,-293],[17,-293],[-207,-315],[196,-316],[-36,-288],[-544,-413],[-386,-91],[-287,178],[-83,-297],[-268,-498],[-81,-259],[-322,-399],[-397,-39],[-220,-250],[-18,-384],[-323,-74],[-340,-479],[-301,-665],[-108,-466],[-16,-686],[409,-99],[125,-553],[130,-448],[388,117],[517,-256],[277,-225],[199,-279],[348,-163],[294,-248],[459,-34],[302,-58],[-45,-511],[86,-594],[201,-661],[414,-561],[214,192],[150,607],[-145,934],[-196,311],[445,276],[314,415],[154,411],[-23,395],[-188,502],[-338,445],[328,619],[-121,535],[-93,922],[194,137],[476,-161],[286,-57],[230,155],[258,-200],[342,-343],[85,-229],[495,-45],[-8,-496],[92,-747],[254,-92],[201,-348],[402,328],[266,652],[184,274],[216,-527],[362,-754],[307,-709],[-112,-371],[370,-333],[250,-338],[442,-152],[179,-189],[110,-500],[216,-78],[112,-223],[20,-664],[-202,-222],[-199,-207],[-458,-210],[-349,-486],[-470,-96],[-594,125],[-417,4],[-287,-41],[-233,-424],[-354,-262],[-401,-782],[-320,-545],[236,97],[446,776],[583,493],[415,58],[246,-289],[-262,-397],[88,-637],[91,-446],[361,-295],[459,86],[278,664],[19,-429],[180,-214],[-344,-387],[-615,-351],[-276,-239],[-310,-426],[-211,44],[-11,500],[483,488],[-445,-19],[-309,-72]],[[31350,77248],[-181,334],[0,805],[-123,171],[-187,-100],[-92,155],[-212,-446],[-84,-460],[-99,-269],[-118,-91],[-89,-30],[-28,-146],[-512,0],[-422,-4],[-125,-109],[-294,-425],[-34,-46],[-89,-231],[-255,1],[-273,-3],[-125,-93],[44,-116],[25,-181],[-5,-60],[-363,-293],[-286,-93],[-323,-316],[-70,0],[-94,93],[-31,85],[6,61],[61,207],[131,325],[81,349],[-56,514],[-59,536],[-290,277],[35,105],[-41,73],[-76,0],[-56,93],[-14,140],[-54,-61],[-75,18],[17,59],[-65,58],[-27,155],[-216,189],[-224,197],[-272,229],[-261,214],[-248,-167],[-91,-6],[-342,154],[-225,-77],[-269,183],[-284,94],[-194,36],[-86,100],[-49,325],[-94,-3],[-1,-227],[-575,0],[-951,0],[-944,0],[-833,0],[-834,0],[-819,0],[-847,0],[-273,0],[-824,0],[-789,0]],[[26668,87478],[207,273],[381,-6],[-6,-114],[-325,-326],[-196,13],[-61,160]],[[27840,93593],[-306,313],[12,213],[133,39],[636,-63],[479,-325],[25,-163],[-296,17],[-299,13],[-304,-80],[-80,36]],[[27690,87261],[107,177],[114,-13],[70,-121],[-108,-310],[-123,50],[-73,176],[13,41]],[[23996,94879],[-151,-229],[-403,44],[-337,155],[148,266],[399,159],[243,-208],[101,-187]],[[23933,96380],[-126,-17],[-521,38],[-74,165],[559,-9],[195,-109],[-33,-68]],[[23124,97116],[332,-205],[-76,-214],[-411,-122],[-226,138],[-119,221],[-22,245],[360,-24],[162,-39]],[[25514,94532],[-449,73],[-738,190],[-96,325],[-34,293],[-279,258],[-574,72],[-322,183],[104,242],[573,-37],[308,-190],[547,1],[240,-194],[-64,-222],[319,-134],[177,-140],[374,-26],[406,-50],[441,128],[566,51],[451,-42],[298,-223],[62,-244],[-174,-157],[-414,-127],[-355,72],[-797,-91],[-570,-11]],[[19093,96754],[392,-92],[-93,-177],[-518,-170],[-411,191],[224,188],[406,60]],[[19177,97139],[361,-120],[-339,-115],[-461,1],[5,84],[285,177],[149,-27]],[[34555,80899],[-148,-372],[-184,-517],[181,199],[187,-126],[-98,-206],[247,-162],[128,144],[277,-182],[-86,-433],[194,101],[36,-313],[86,-367],[-117,-520],[-125,-22],[-183,111],[60,484],[-77,75],[-322,-513],[-166,21],[196,277],[-267,144],[-298,-35],[-539,18],[-43,175],[173,208],[-121,160],[234,356],[287,941],[172,336],[241,204],[129,-26],[-54,-160]],[[26699,89048],[304,-203],[318,-184],[25,-281],[204,46],[199,-196],[-247,-186],[-432,142],[-156,266],[-275,-314],[-396,-306],[-95,346],[-377,-57],[242,292],[35,465],[95,542],[201,-49],[51,-259],[143,91],[161,-155]],[[28119,93327],[263,235],[616,-299],[383,-282],[36,-258],[515,134],[290,-376],[670,-234],[242,-238],[263,-553],[-510,-275],[654,-386],[441,-130],[400,-543],[437,-39],[-87,-414],[-487,-687],[-342,253],[-437,568],[-359,-74],[-35,-338],[292,-344],[377,-272],[114,-157],[181,-584],[-96,-425],[-350,160],[-697,473],[393,-509],[289,-357],[45,-206],[-753,236],[-596,343],[-337,287],[97,167],[-414,304],[-405,286],[5,-171],[-803,-94],[-235,203],[183,435],[522,10],[571,76],[-92,211],[96,294],[360,576],[-77,261],[-107,203],[-425,286],[-563,201],[178,150],[-294,367],[-245,34],[-219,201],[-149,-175],[-503,-76],[-1011,132],[-588,174],[-450,89],[-231,207],[290,270],[-394,2],[-88,599],[213,528],[286,241],[717,158],[-204,-382],[219,-369],[256,477],[704,242],[477,-611],[-42,-387],[550,172]],[[23749,94380],[579,-20],[530,-144],[-415,-526],[-331,-115],[-298,-442],[-317,22],[-173,519],[4,294],[145,251],[276,161]],[[15873,95551],[472,442],[570,383],[426,-9],[381,87],[-38,-454],[-214,-205],[-259,-29],[-517,-252],[-444,-91],[-377,128]],[[13136,82508],[267,47],[-84,-671],[242,-475],[-111,1],[-167,270],[-103,272],[-140,184],[-51,260],[16,188],[131,-76]],[[20696,97433],[546,-81],[751,-215],[212,-281],[108,-247],[-453,66],[-457,192],[-619,21],[268,176],[-335,142],[-21,227]],[[15692,79240],[-140,-82],[-456,269],[-84,209],[-248,207],[-50,168],[-286,107],[-107,321],[24,137],[291,-129],[171,-89],[261,-63],[94,-204],[138,-280],[277,-244],[115,-327]],[[16239,94566],[397,-123],[709,-33],[270,-171],[298,-249],[-349,-149],[-681,-415],[-344,-414],[0,-257],[-731,-285],[-147,259],[-641,312],[119,250],[192,432],[241,388],[-272,362],[939,93]],[[20050,95391],[247,99],[291,-26],[49,-289],[-169,-281],[-940,-91],[-701,-256],[-423,-14],[-35,193],[577,261],[-1255,-70],[-389,106],[379,577],[262,165],[782,-199],[493,-350],[485,-45],[-397,565],[255,215],[286,-68],[94,-282],[109,-210]],[[20410,93755],[311,-239],[175,-575],[86,-417],[466,-293],[502,-279],[-31,-260],[-456,-48],[178,-227],[-94,-217],[-503,93],[-478,160],[-322,-36],[-522,-201],[-704,-88],[-494,-56],[-151,279],[-379,161],[-246,-66],[-343,468],[185,62],[429,101],[392,-26],[362,103],[-537,138],[-594,-47],[-394,12],[-146,217],[644,237],[-428,-9],[-485,156],[233,443],[193,235],[744,359],[284,-114],[-139,-277],[618,179],[386,-298],[314,302],[254,-194],[227,-580],[140,244],[-197,606],[244,86],[276,-94]],[[22100,93536],[-306,386],[329,286],[331,-124],[496,75],[72,-172],[-259,-283],[420,-254],[-50,-532],[-455,-229],[-268,50],[-192,225],[-690,456],[5,189],[567,-73]],[[20389,94064],[372,24],[211,-130],[-244,-390],[-434,413],[95,83]],[[22639,95907],[212,-273],[9,-303],[-127,-440],[-458,-60],[-298,94],[5,345],[-455,-46],[-18,457],[299,-18],[419,201],[390,-34],[22,77]],[[23329,98201],[192,180],[285,42],[-122,135],[646,30],[355,-315],[468,-127],[455,-112],[220,-390],[334,-190],[-381,-176],[-513,-445],[-492,-42],[-575,76],[-299,240],[4,215],[220,157],[-508,-4],[-306,196],[-176,268],[193,262]],[[24559,98965],[413,112],[324,19],[545,96],[409,220],[344,-30],[300,-166],[211,319],[367,95],[498,65],[849,24],[148,-63],[802,100],[601,-38],[602,-37],[742,-47],[597,-75],[508,-161],[-12,-157],[-678,-257],[-672,-119],[-251,-133],[605,3],[-656,-358],[-452,-167],[-476,-483],[-573,-98],[-177,-120],[-841,-64],[383,-74],[-192,-105],[230,-292],[-264,-202],[-429,-167],[-132,-232],[-388,-176],[39,-134],[475,23],[6,-144],[-742,-355],[-726,163],[-816,-91],[-414,71],[-525,31],[-35,284],[514,133],[-137,427],[170,41],[742,-255],[-379,379],[-450,113],[225,229],[492,141],[79,206],[-392,231],[-118,304],[759,-26],[220,-64],[433,216],[-625,68],[-972,-38],[-491,201],[-232,239],[-324,173],[-61,202]],[[29106,90427],[-180,-174],[-312,-30],[-69,289],[118,331],[255,82],[217,-163],[3,-253],[-32,-82]],[[23262,91636],[169,-226],[-173,-207],[-374,179],[-226,-65],[-380,266],[245,183],[194,256],[295,-168],[166,-106],[84,-112]],[[32078,80046],[96,49],[365,-148],[284,-247],[8,-108],[-135,-11],[-360,186],[-258,279]],[[32218,78370],[97,-288],[202,-79],[257,16],[-137,-242],[-102,-38],[-353,250],[-69,198],[105,183]],[[31350,77248],[48,-194],[-296,-286],[-286,-204],[-293,-175],[-147,-351],[-47,-133],[-3,-313],[92,-313],[115,-15],[-29,216],[83,-131],[-22,-169],[-188,-96],[-133,11],[-205,-103],[-121,-29],[-162,-29],[-231,-171],[408,111],[82,-112],[-389,-177],[-177,-1],[8,72],[-84,-164],[82,-27],[-60,-424],[-203,-455],[-20,152],[-61,30],[-91,148],[57,-318],[69,-105],[5,-223],[-89,-230],[-157,-472],[-25,24],[86,402],[-142,225],[-33,491],[-53,-255],[59,-375],[-183,93],[191,-191],[12,-562],[79,-41],[29,-204],[39,-591],[-176,-439],[-288,-175],[-182,-346],[-139,-38],[-141,-217],[-39,-199],[-305,-383],[-157,-281],[-131,-351],[-43,-419],[50,-411],[92,-505],[124,-418],[1,-256],[132,-685],[-9,-398],[-12,-230],[-69,-361],[-83,-75],[-137,72],[-44,259],[-105,136],[-148,508],[-129,452],[-42,231],[57,393],[-77,325],[-217,494],[-108,90],[-281,-268],[-49,30],[-135,275],[-174,147],[-314,-75],[-247,66],[-212,-41],[-114,-92],[50,-157],[-5,-240],[59,-117],[-53,-77],[-103,87],[-104,-112],[-202,18],[-207,312],[-242,-73],[-202,137],[-173,-42],[-234,-138],[-253,-438],[-276,-255],[-152,-282],[-63,-266],[-3,-407],[14,-284],[52,-201]],[[23016,65864],[-108,-18],[-197,130],[-217,184],[-78,277],[-61,414],[-164,337],[-96,346],[-139,404],[-196,236],[-227,-11],[-175,-467],[-230,177],[-144,178],[-69,325],[-92,309],[-165,260],[-142,186],[-102,210],[-481,0],[0,-244],[-221,0],[-552,-4],[-634,416],[-419,287],[26,116],[-353,-64],[-316,-46]],[[17464,69802],[-46,302],[-180,340],[-130,71],[-30,169],[-156,30],[-100,159],[-258,59],[-71,95],[-33,324],[-270,594],[-231,821],[10,137],[-123,195],[-215,495],[-38,482],[-148,323],[61,489],[-10,507],[-89,453],[109,557],[34,536],[33,536],[-50,792],[-88,506],[-80,274],[33,115],[402,-200],[148,-558],[69,156],[-45,484],[-94,485]],[[6833,62443],[49,-51],[45,-79],[71,-207],[-7,-33],[-108,-126],[-89,-92],[-41,-99],[-69,84],[8,165],[-46,216],[14,65],[48,97],[-19,116],[16,55],[21,-11],[107,-100]],[[6668,62848],[-23,-71],[-94,-43],[-47,125],[-32,48],[-3,37],[27,50],[99,-56],[73,-90]],[[6456,63091],[-9,-63],[-149,17],[21,72],[137,-26]],[[6104,63411],[23,-38],[80,-196],[-15,-34],[-19,8],[-97,21],[-35,133],[-11,24],[74,82]],[[5732,63705],[5,-138],[-33,-58],[-93,107],[14,43],[43,58],[64,-12]],[[3759,86256],[220,-54],[27,-226],[-171,-92],[-182,110],[-168,161],[274,101]],[[7436,84829],[185,-40],[117,-183],[-240,-281],[-277,-225],[-142,152],[-43,277],[252,210],[148,90]],[[13740,82958],[-153,223],[-245,188],[-78,515],[-358,478],[-150,558],[-267,38],[-441,15],[-326,170],[-574,613],[-266,112],[-486,211],[-385,-51],[-546,272],[-330,252],[-309,-125],[58,-411],[-154,-38],[-321,-123],[-245,-199],[-308,-126],[-39,348],[125,580],[295,182],[-76,148],[-354,-329],[-190,-394],[-400,-420],[203,-287],[-262,-424],[-299,-248],[-278,-180],[-69,-261],[-434,-305],[-87,-278],[-325,-252],[-191,45],[-259,-165],[-282,-201],[-231,-197],[-477,-169],[-43,99],[304,276],[271,182],[296,324],[345,66],[137,243],[385,353],[62,119],[205,208],[48,448],[141,349],[-320,-179],[-90,102],[-150,-215],[-181,300],[-75,-212],[-104,294],[-278,-236],[-170,0],[-24,352],[50,216],[-179,211],[-361,-113],[-235,277],[-190,142],[-1,334],[-214,252],[108,340],[226,330],[99,303],[225,43],[191,-94],[224,285],[201,-51],[212,183],[-52,270],[-155,106],[205,228],[-170,-7],[-295,-128],[-85,-131],[-219,131],[-392,-67],[-407,142],[-117,238],[-351,343],[390,247],[620,289],[228,0],[-38,-296],[586,23],[-225,366],[-342,225],[-197,296],[-267,252],[-381,187],[155,309],[493,19],[350,270],[66,287],[284,281],[271,68],[526,262],[256,-40],[427,315],[421,-124],[201,-266],[123,114],[469,-35],[-16,-136],[425,-101],[283,59],[585,-186],[534,-56],[214,-77],[370,96],[421,-177],[302,-83]],[[2297,88264],[171,-113],[173,61],[225,-156],[276,-79],[-23,-64],[-211,-125],[-211,128],[-106,107],[-245,-34],[-66,52],[17,223]],[[74266,79657],[-212,-393],[-230,-56],[-13,-592],[-155,-267],[-551,194],[-200,-1058],[-143,-131],[-550,-236],[250,-1026],[-190,-154],[22,-337]],[[72294,75601],[-171,87],[-140,212],[-412,62],[-461,16],[-100,-65],[-396,248],[-158,-122],[-43,-349],[-457,204],[-183,-84],[-62,-259]],[[69711,75551],[-159,-109],[-367,-412],[-121,-422],[-104,-4],[-76,280],[-353,19],[-57,484],[-135,4],[21,593],[-333,431],[-476,-46],[-326,-86],[-265,533],[-227,223],[-431,423],[-52,51],[-715,-349],[11,-2178]],[[65546,74986],[-142,-29],[-195,463],[-188,166],[-315,-123],[-123,-197]],[[64583,75266],[-15,144],[68,246],[-53,206],[-322,202],[-125,530],[-154,150],[-9,192],[270,-56],[11,432],[236,96],[243,-88],[50,576],[-50,365],[-278,-28],[-236,144],[-321,-260],[-259,-124]],[[63639,77993],[-142,96],[29,304],[-177,395],[-207,-17],[-235,401],[160,448],[-81,120],[222,649],[285,-342],[35,431],[573,643],[434,15],[612,-409],[329,-239],[295,249],[440,12],[356,-306],[80,175],[391,-25],[69,280],[-450,406],[267,288],[-52,161],[266,153],[-200,405],[127,202],[1039,205],[136,146],[695,218],[250,245],[499,-127],[88,-612],[290,144],[356,-202],[-23,-322],[267,33],[696,558],[-102,-185],[355,-457],[620,-1500],[148,309],[383,-340],[399,151],[154,-106],[133,-341],[194,-115],[119,-251],[358,79],[147,-361]],[[69711,75551],[83,-58],[-234,-382],[205,-223],[198,147],[329,-311],[-355,-425],[-212,58]],[[69725,74357],[-114,-15],[-40,164],[58,274],[-371,-137],[-89,-380],[-132,-326],[-232,28],[-72,-261],[204,-140],[60,-440],[-156,-598]],[[68841,72526],[-210,124],[-154,4]],[[68477,72654],[7,362],[-369,253],[-291,289],[-181,278],[-317,408],[-137,609],[-93,108],[-301,-27],[-106,121],[-30,471],[-374,312],[-234,-343],[-237,-204],[45,-297],[-313,-8]],[[89166,49043],[482,-407],[513,-338],[192,-302],[154,-297],[43,-349],[462,-365],[68,-313],[-256,-64],[62,-393],[248,-388],[180,-627],[159,20],[-11,-262],[215,-100],[-84,-111],[295,-249],[-30,-171],[-184,-41],[-69,153],[-238,66],[-281,89],[-216,377],[-158,325],[-144,517],[-362,259],[-235,-169],[-170,-195],[35,-436],[-218,-203],[-155,99],[-288,25]],[[89175,45193],[-4,1925],[-5,1925]],[[92399,48417],[106,-189],[33,-307],[-87,-157],[-52,348],[-65,229],[-126,193],[-158,252],[-200,174],[77,143],[150,-166],[94,-130],[117,-142],[111,-248]],[[92027,47129],[-152,-144],[-142,-138],[-148,1],[-228,171],[-158,165],[23,183],[249,-86],[152,46],[42,283],[40,15],[27,-314],[158,45],[78,202],[155,211],[-30,348],[166,11],[56,-97],[-5,-327],[-93,-361],[-146,-48],[-44,-166]],[[92988,47425],[84,-134],[135,-375],[131,-200],[-39,-166],[-78,-59],[-120,227],[-122,375],[-59,450],[38,57],[30,-175]],[[89175,45193],[-247,485],[-282,118],[-69,-168],[-352,-18],[118,481],[175,164],[-72,642],[-134,496],[-538,500],[-229,50],[-417,546],[-82,-287],[-107,-52],[-63,216],[-1,257],[-212,290],[299,213],[198,-11],[-23,156],[-407,1],[-110,352],[-248,109],[-117,293],[374,143],[142,192],[446,-242],[44,-220],[78,-955],[287,-354],[232,627],[319,356],[247,1],[238,-206],[206,-212],[298,-113]],[[84713,45326],[28,-117],[5,-179]],[[84746,45030],[-181,-441],[-238,-130],[-33,71],[25,201],[119,360],[275,235]],[[87280,46506],[-27,445],[49,212],[58,200],[63,-173],[0,-282],[-143,-402]],[[82744,53024],[-158,-533],[204,-560],[-48,-272],[312,-546],[-329,-70],[-93,-403],[12,-535],[-267,-404],[-7,-589],[-107,-903],[-41,210],[-316,-266],[-110,361],[-198,34],[-139,189],[-330,-212],[-101,285],[-182,-32],[-229,68],[-43,793],[-138,164],[-134,505],[-38,517],[32,548],[165,392]],[[80461,51765],[47,-395],[190,-334],[179,121],[177,-43],[162,299],[133,52],[263,-166],[226,126],[143,822],[107,205],[96,672],[319,0],[241,-100]],[[85936,48924],[305,-172],[101,-452],[-234,244],[-232,49],[-157,-39],[-192,21],[65,325],[344,24]],[[85242,48340],[-192,108],[-54,254],[281,29],[69,-195],[-104,-196]],[[85536,51864],[20,-322],[164,-52],[26,-241],[-15,-517],[-143,58],[-42,-359],[114,-312],[-78,-71],[-112,374],[-82,755],[56,472],[92,215]],[[84146,51097],[319,25],[275,429],[48,-132],[-223,-587],[-209,-113],[-267,115],[-463,-29],[-243,-85],[-39,-447],[248,-526],[150,268],[518,201],[-22,-272],[-121,86],[-121,-347],[-245,-229],[263,-757],[-50,-203],[249,-682],[-2,-388],[-148,-173],[-109,207],[134,484],[-273,-229],[-69,164],[36,228],[-200,346],[21,576],[-186,-179],[24,-689],[11,-846],[-176,-85],[-119,173],[79,544],[-43,570],[-117,4],[-86,405],[115,387],[40,469],[139,891],[58,243],[237,439],[217,-174],[350,-82]],[[83414,44519],[-368,414],[259,116],[146,-180],[97,-180],[-17,-159],[-117,-11]],[[83705,45536],[185,45],[249,216],[-41,-328],[-417,-168],[-370,73],[0,216],[220,123],[174,-177]],[[82849,45639],[172,48],[69,-251],[-321,-119],[-193,-79],[-149,5],[95,340],[153,5],[74,209],[100,-158]],[[80134,46785],[38,-210],[533,-59],[61,244],[515,-284],[101,-383],[417,-108],[341,-351],[-317,-225],[-306,238],[-251,-16],[-288,44],[-260,106],[-322,225],[-204,59],[-116,-74],[-506,243],[-48,254],[-255,44],[191,564],[337,-35],[224,-231],[115,-45]],[[78991,49939],[47,-412],[97,-330],[204,-52],[135,-374],[-70,-735],[-11,-914],[-308,-12],[-234,494],[-356,482],[-119,358],[-210,481],[-138,443],[-212,827],[-244,493],[-81,508],[-103,461],[-250,372],[-145,506],[-209,330],[-290,652],[-24,300],[178,-24],[430,-114],[246,-577],[215,-401],[153,-246],[263,-635],[283,-9],[233,-405],[161,-495],[211,-270],[-111,-482],[159,-205],[100,-15]],[[30935,19481],[106,-274],[139,-443],[361,-355],[389,-147],[-125,-296],[-264,-29],[-141,208]],[[31400,18145],[-168,16],[-297,1],[0,1319]],[[33993,32727],[-70,-473],[-74,-607],[3,-588],[-61,-132],[-21,-382]],[[33770,30545],[-19,-308],[353,-506],[-38,-408],[173,-257],[-14,-289],[-267,-757],[-412,-317],[-557,-123],[-305,59],[59,-352],[-57,-442],[51,-298],[-167,-208],[-284,-82],[-267,216],[-108,-155],[39,-587],[188,-178],[152,186],[82,-307],[-255,-183],[-223,-367],[-41,-595],[-66,-316],[-262,-2],[-218,-302],[-80,-443],[273,-433],[266,-119],[-96,-531],[-328,-333],[-180,-692],[-254,-234],[-113,-276],[89,-614],[185,-342],[-117,30]],[[30952,19680],[-257,93],[-672,79],[-115,344],[6,443],[-185,-38],[-98,214],[-24,626],[213,260],[88,375],[-33,299],[148,504],[101,782],[-30,347],[122,112],[-30,223],[-129,118],[92,248],[-126,224],[-65,682],[112,120],[-47,720],[65,605],[75,527],[166,215],[-84,576],[-1,543],[210,386],[-7,494],[159,576],[1,544],[-72,108],[-128,1020],[171,607],[-27,572],[100,537],[182,555],[196,367],[-83,232],[58,190],[-9,985],[302,291],[96,614],[-34,148]],[[31359,37147],[231,534],[364,-144],[163,-427],[109,475],[316,-24],[45,-127]],[[32587,37434],[511,-964],[227,-89],[339,-437],[286,-231],[40,-261],[-273,-898],[280,-160],[312,-91],[220,95],[252,453],[45,521]],[[34826,35372],[138,114],[139,-341],[-6,-472],[-234,-326],[-186,-241],[-314,-573],[-370,-806]],[[31400,18145],[-92,-239],[-238,-183],[-137,19],[-164,48],[-202,177],[-291,86],[-350,330],[-283,317],[-383,662],[229,-124],[390,-395],[369,-212],[143,271],[90,405],[256,244],[198,-70]],[[30669,40193],[136,-402],[37,-426],[146,-250],[-88,-572],[150,-663],[109,-814],[200,81]],[[30952,19680],[-247,4],[-134,-145],[-250,-213],[-45,-552],[-118,-14],[-313,192],[-318,412],[-346,338],[-87,374],[79,346],[-140,393],[-36,1007],[119,568],[293,457],[-422,172],[265,522],[94,982],[309,-208],[145,1224],[-186,157],[-87,-738],[-175,83],[87,845],[95,1095],[127,404],[-80,576],[-22,666],[117,19],[170,954],[192,945],[118,881],[-64,885],[83,487],[-34,730],[163,721],[50,1143],[89,1227],[87,1321],[-20,967],[-58,832]],[[30452,39739],[143,151],[74,303]],[[58538,45652],[-109,60],[-373,-99],[-75,-71],[-79,-377],[62,-261],[-49,-699],[-34,-593],[75,-105],[194,-230],[76,107],[23,-637],[-212,5],[-114,325],[-103,252],[-213,82],[-62,310],[-170,-187],[-222,83],[-93,268],[-176,55],[-131,-15],[-15,184],[-96,15]],[[56642,44124],[-127,35],[-172,-89],[-121,15],[-68,-54],[15,703],[-93,219],[-21,363],[41,356],[-56,228],[-5,372],[-337,-5],[24,213],[-142,-2],[-15,-103],[-172,-23],[-69,-344],[-42,-148],[-154,83],[-91,-83],[-184,-47],[-106,309],[-64,191],[-80,354],[-68,440],[-820,8],[-98,-71],[-80,11],[-115,-79]],[[53422,46976],[-39,183]],[[53383,47159],[71,62],[9,258],[45,152],[101,124]],[[53609,47755],[73,-60],[95,226],[152,-6],[17,-167],[104,-105],[164,370],[161,289],[71,189],[-10,486],[121,574],[127,304],[183,285],[32,189],[7,216],[45,205],[-14,335],[34,524],[55,368],[83,316],[16,357]],[[55125,52650],[25,412],[108,300],[149,190],[229,-200],[177,-218],[203,-59],[207,-115],[83,357],[38,46],[127,-60],[309,295],[110,-125],[90,18],[41,143],[104,51],[209,-62],[178,-14],[91,63]],[[57603,53672],[169,-488],[124,-71],[75,99],[128,-39],[155,125],[66,-252],[244,-393]],[[58564,52653],[-16,-691],[111,-80],[-89,-210],[-107,-157],[-106,-308],[-59,-274],[-15,-475],[-65,-225],[-2,-446]],[[58216,49787],[-80,-165],[-10,-351],[-38,-46],[-26,-323]],[[58062,48902],[70,-268],[17,-713]],[[61551,49585],[-165,488],[-3,2152],[243,670]],[[61626,52895],[76,186],[178,11],[247,417],[362,26],[785,1773]],[[63274,55308],[194,493],[125,363],[0,308],[0,596],[1,244],[2,9]],[[63596,57321],[89,12],[128,88],[147,59],[132,202],[105,2],[6,-163],[-25,-344],[1,-310],[-59,-214],[-78,-639],[-134,-659],[-172,-755],[-238,-866],[-237,-661],[-327,-806],[-278,-479],[-415,-586],[-259,-450],[-304,-715],[-64,-312],[-63,-140]],[[59417,50018],[-3,627],[80,239],[137,391],[101,431],[-123,678],[-32,296],[-132,411]],[[59445,53091],[171,352],[188,390]],[[59804,53833],[145,-99],[0,-332],[95,-194],[193,0],[352,-502],[87,-6],[65,16],[62,-68],[185,-47],[82,247],[254,247],[112,-200],[190,0]],[[61551,49585],[-195,-236],[-68,-246],[-104,-44],[-40,-416],[-89,-238],[-54,-393],[-112,-195]],[[56824,55442],[-212,258],[-96,170],[-18,184],[45,246],[-1,241],[-160,369],[-31,253]],[[56351,57163],[3,143],[-102,174],[-3,343],[-58,228],[-98,-34],[28,217],[72,246],[-32,245],[92,181],[-58,138],[73,365],[127,435],[240,-41],[-14,2345]],[[56621,62148],[3,248],[320,2],[0,1180]],[[56944,63578],[1117,0],[1077,0],[1102,0]],[[60240,63578],[90,-580],[-61,-107],[40,-608],[102,-706],[106,-145],[152,-219]],[[60669,61213],[-141,-337],[-204,-97],[-88,-181],[-27,-393],[-120,-868],[30,-236]],[[60119,59101],[-45,-508],[-112,-582],[-168,-293],[-119,-451],[-28,-241],[-132,-166],[-82,-618],[4,-531]],[[59437,55711],[-3,460],[-39,12],[5,294],[-33,203],[-143,233],[-34,426],[34,436],[-129,41],[-19,-132],[-167,-30],[67,-173],[23,-355],[-152,-324],[-138,-426],[-144,-61],[-233,345],[-105,-122],[-29,-172],[-143,-112],[-9,-122],[-277,0],[-38,122],[-200,20],[-100,-101],[-77,51],[-143,344],[-48,163],[-200,-81],[-76,-274],[-72,-528],[-95,-111],[-85,-65],[189,-230]],[[56351,57163],[-176,-101],[-141,-239],[-201,-645],[-261,-273],[-269,36],[-78,-54],[28,-208],[-145,-207],[-118,-230],[-350,-226],[-69,134],[-46,11],[-52,-152],[-229,-44]],[[54244,54965],[43,160],[-87,407],[-39,245],[-121,100],[-164,345],[60,279],[127,-60],[78,42],[155,-6],[-151,537],[10,393],[-18,392],[-111,378]],[[54026,58177],[28,279],[-178,13],[0,380],[-115,219],[120,778],[354,557],[15,769],[107,1199],[60,254],[-116,203],[-4,188],[-104,153],[-68,919]],[[54125,64088],[280,323],[1108,-1132],[1108,-1131]],[[30080,62227],[24,-321],[-21,-228],[-68,-99],[71,-177],[-5,-161]],[[30081,61241],[-185,100],[-131,-41],[-169,43],[-130,-110],[-149,184],[24,190],[256,-82],[210,-47],[100,131],[-127,256],[2,226],[-175,92],[62,163],[170,-26],[241,-93]],[[30080,62227],[34,101],[217,-3],[165,-152],[73,15],[50,-209],[152,11],[-9,-176],[124,-21],[136,-217],[-103,-240],[-132,128],[-127,-25],[-92,28],[-50,-107],[-106,-37],[-43,144],[-92,-85],[-111,-405],[-71,94],[-14,170]],[[76049,98451],[600,133],[540,-297],[640,-572],[-69,-531],[-606,-73],[-773,170],[-462,226],[-213,423],[-379,117],[722,404]],[[78565,97421],[704,-336],[-82,-240],[-1566,-228],[507,776],[229,66],[208,-38]],[[88563,95563],[734,-26],[1004,-313],[-219,-439],[-1023,16],[-461,-139],[-550,384],[149,406],[366,111]],[[91172,95096],[697,-155],[-321,-234],[-444,53],[-516,233],[66,192],[518,-89]],[[88850,93928],[263,234],[348,54],[394,-226],[34,-155],[-421,-4],[-569,66],[-49,31]],[[62457,98194],[542,107],[422,8],[57,-160],[159,142],[262,97],[412,-129],[-107,-90],[-373,-78],[-250,-45],[-39,-97],[-324,-98],[-301,140],[158,185],[-618,18]],[[56314,82678],[-511,-9],[-342,67]],[[55461,82736],[63,260],[383,191]],[[55907,83187],[291,-103],[123,-94],[-30,-162],[23,-150]],[[64863,94153],[665,518],[-75,268],[621,312],[917,380],[925,110],[475,220],[541,76],[193,-233],[-187,-184],[-984,-293],[-848,-282],[-863,-562],[-414,-577],[-435,-568],[56,-491],[531,-484],[-164,-52],[-907,77],[-74,262],[-503,158],[-40,320],[284,126],[-10,323],[551,503],[-255,73]],[[89698,82309],[96,-569],[-7,-581],[114,-597],[280,-1046],[-411,195],[-171,-854],[271,-605],[-8,-413],[-211,356],[-182,-457],[-51,496],[31,575],[-32,638],[64,446],[13,790],[-163,581],[24,808],[257,271],[-110,274],[123,83],[73,-391]],[[86327,75524],[-39,104]],[[86288,75628],[-2,300],[142,16],[40,698],[-73,506],[238,208],[338,-104],[186,575],[96,647],[107,216],[146,532],[-459,-175],[-240,-233],[-423,1],[-112,555],[-329,420],[-483,189],[-103,579],[-97,363],[-104,254],[-172,596],[-244,217],[-415,176],[-369,-16],[-345,-106],[-229,-294],[152,-141],[4,-326],[-155,-189],[-251,-627],[3,-260],[-392,-373],[-333,223]],[[82410,80055],[-331,-49],[-146,198],[-166,63],[-407,-416],[-366,-98],[-255,-146],[-350,96],[-258,-6],[-168,302],[-272,284],[-279,78],[-351,-78],[-263,-109],[-394,248],[-53,443],[-327,152],[-252,69],[-311,244],[-288,-612],[113,-348],[-270,-411],[-402,148],[-277,22],[-186,276],[-289,8],[-242,182],[-423,-278],[-530,-509],[-292,-102]],[[74375,79706],[-109,-49]],[[63639,77993],[-127,-350],[-269,-97],[-276,-610],[252,-561],[-27,-398],[303,-696]],[[63495,75281],[-166,-238],[-48,-150],[-122,40],[-191,359],[-78,20]],[[62890,75312],[-175,137],[-85,242],[-259,124],[-169,-93],[-48,110],[-378,283],[-409,96],[-235,101],[-34,-70]],[[61098,76242],[-354,499],[-317,223],[-240,347],[202,95],[231,494],[-156,234],[410,241],[-8,129],[-249,-95]],[[60617,78409],[9,262],[143,165],[269,43],[44,197],[-62,326],[113,310],[-3,173],[-410,192],[-162,-6],[-172,277],[-213,-94],[-352,208],[6,116],[-99,256],[-222,29],[-23,183],[70,120],[-178,334],[-288,-57],[-84,30],[-70,-134],[-104,23]],[[58829,81362],[-68,379],[-66,196],[54,55],[224,-20],[108,129],[-80,157],[-187,104],[16,107],[-113,108],[-174,387],[60,159],[-27,277],[-272,141],[-146,-70],[-39,146],[-293,149]],[[57826,83766],[-89,348],[-24,287],[-134,136]],[[57579,84537],[120,187],[-83,551],[198,341],[-42,103]],[[57772,85719],[316,327],[-291,280]],[[57797,86326],[594,755],[258,341],[105,301],[-411,405],[113,385],[-250,440],[187,506],[-323,673],[256,445],[-425,394],[41,414]],[[57942,91385],[224,54],[473,237]],[[58639,91676],[286,206],[456,-358],[761,-140],[1050,-668],[213,-281],[18,-393],[-308,-311],[-454,-157],[-1240,449],[-204,-75],[453,-433],[18,-274],[18,-604],[358,-180],[217,-153],[36,286],[-168,254],[177,224],[672,-368],[233,144],[-186,433],[647,578],[256,-34],[260,-206],[161,406],[-231,352],[136,353],[-204,367],[777,-190],[158,-331],[-351,-73],[1,-328],[219,-203],[429,128],[68,377],[580,282],[970,507],[209,-29],[-273,-359],[344,-61],[199,202],[521,16],[412,245],[317,-356],[315,391],[-291,343],[145,195],[820,-179],[385,-185],[1006,-675],[186,309],[-282,313],[-8,125],[-335,58],[92,280],[-149,461],[-8,189],[512,535],[183,537],[206,116],[736,-156],[57,-328],[-263,-479],[173,-189],[89,-413],[-63,-809],[307,-362],[-120,-395],[-544,-839],[318,-87],[110,213],[306,151],[74,293],[240,281],[-162,336],[130,390],[-304,49],[-67,328],[222,593],[-361,482],[497,398],[-64,421],[139,13],[145,-328],[-109,-570],[297,-108],[-127,426],[465,233],[577,31],[513,-337],[-247,492],[-28,630],[483,119],[669,-26],[602,77],[-226,309],[321,388],[319,16],[540,293],[734,79],[93,162],[729,55],[227,-133],[624,314],[510,-10],[77,255],[265,252],[656,242],[476,-191],[-378,-146],[629,-90],[75,-292],[254,143],[812,-7],[626,-289],[223,-221],[-69,-307],[-307,-175],[-730,-328],[-209,-175],[345,-83],[410,-149],[251,112],[141,-379],[122,153],[444,93],[892,-97],[67,-276],[1162,-88],[15,451],[590,-104],[443,4],[449,-312],[128,-378],[-165,-247],[349,-465],[437,-240],[268,620],[446,-266],[473,159],[538,-182],[204,166],[455,-83],[-201,549],[367,256],[2509,-384],[236,-351],[727,-451],[1122,112],[553,-98],[231,-244],[-33,-432],[342,-168],[372,121],[492,15],[525,-116],[526,66],[484,-526],[344,189],[-224,378],[123,262],[886,-165],[578,36],[799,-282],[-99610,-258],[681,-451],[728,-588],[-24,-367],[187,-147],[-64,429],[754,-88],[544,-553],[-276,-257],[-455,-61],[-7,-578],[-111,-122],[-260,17],[-212,206],[-369,172],[-62,257],[-283,96],[-315,-76],[-151,207],[60,219],[-333,-140],[126,-278],[-158,-251],[99997,-3],[-357,-260],[-360,44],[250,-315],[166,-487],[128,-159],[32,-244],[-71,-157],[-518,129],[-777,-445],[-247,-69],[-425,-415],[-403,-362],[-102,-269],[-397,409],[-724,-464],[-126,219],[-268,-253],[-371,81],[-90,-388],[-333,-572],[10,-239],[316,-132],[-37,-860],[-258,-22],[-119,-494],[116,-255],[-486,-302],[-96,-674],[-415,-144],[-83,-600],[-400,-551],[-103,407],[-119,862],[-155,1313],[134,819],[234,353],[14,276],[432,132],[496,744],[479,608],[499,471],[223,833],[-337,-50],[-167,-487],[-705,-649],[-227,727],[-717,-201],[-696,-990],[230,-362],[-620,-154],[-430,-61],[20,427],[-431,90],[-344,-291],[-850,102],[-914,-175],[-899,-1153],[-1065,-1394],[438,-74],[136,-370],[270,-132],[178,295],[305,-38],[401,-650],[9,-503],[-217,-590],[-23,-705],[-126,-945],[-418,-855],[-94,-409],[-377,-688],[-374,-682],[-179,-349],[-370,-346],[-175,-8],[-175,287],[-373,-432],[-43,-197]],[[0,92833],[36,24],[235,-1],[402,-169],[-24,-81],[-286,-141],[-363,-36],[99694,-30],[-49,187],[-99645,247]],[[59287,77741],[73,146],[198,-127],[89,-23],[36,-117],[42,-18]],[[59725,77602],[2,-51],[136,-142],[284,35],[-55,-210],[-304,-103],[-377,-342],[-154,121],[61,277],[-304,173],[50,113],[265,197],[-42,71]],[[28061,66408],[130,47],[184,-18],[8,-153],[-303,-95],[-19,219]],[[28391,66555],[220,-265],[-48,-420],[-51,75],[4,309],[-124,234],[-1,67]],[[28280,65474],[84,-23],[97,-491],[1,-343],[-68,-29],[-70,340],[-104,171],[60,375]],[[33000,19946],[333,354],[236,-148],[167,237],[222,-266],[-83,-207],[-375,-177],[-125,207],[-236,-266],[-139,266]],[[54206,97653],[105,202],[408,20],[350,-206],[915,-440],[-699,-233],[-155,-435],[-243,-111],[-132,-490],[-335,-23],[-598,361],[252,210],[-416,170],[-541,499],[-216,463],[757,212],[152,-207],[396,8]],[[57942,91385],[117,414],[-356,235],[-431,-200],[-137,-433],[-265,-262],[-298,143],[-362,-29],[-309,312],[-167,-156]],[[55734,91409],[-172,-24],[-41,-389],[-523,95],[-74,-329],[-267,2],[-183,-421],[-278,-655],[-431,-831],[101,-202],[-97,-234],[-275,10],[-180,-554],[17,-784],[177,-300],[-92,-694],[-231,-405],[-122,-341]],[[53063,85353],[-187,363],[-548,-684],[-371,-138],[-384,301],[-99,635],[-88,1363],[256,381],[733,496],[549,609],[508,824],[668,1141],[465,444],[763,741],[610,259],[457,-31],[423,489],[506,-26],[499,118],[869,-433],[-358,-158],[305,-371]],[[57613,97879],[-412,-318],[-806,-70],[-819,98],[-50,163],[-398,11],[-304,271],[858,165],[403,-142],[281,177],[702,-148],[545,-207]],[[56867,96577],[-620,-241],[-490,137],[191,152],[-167,189],[575,119],[110,-222],[401,-134]],[[37010,99398],[932,353],[975,-27],[354,218],[982,57],[2219,-74],[1737,-469],[-513,-227],[-1062,-26],[-1496,-58],[140,-105],[984,65],[836,-204],[540,181],[231,-212],[-305,-344],[707,220],[1348,229],[833,-114],[156,-253],[-1132,-420],[-157,-136],[-888,-102],[643,-28],[-324,-431],[-224,-383],[9,-658],[333,-386],[-434,-24],[-457,-187],[513,-313],[65,-502],[-297,-55],[360,-508],[-617,-42],[322,-241],[-91,-208],[-391,-91],[-388,-2],[348,-400],[4,-263],[-549,244],[-143,-158],[375,-148],[364,-361],[105,-476],[-495,-114],[-214,228],[-344,340],[95,-401],[-322,-311],[732,-25],[383,-32],[-745,-515],[-755,-466],[-813,-204],[-306,-2],[-288,-228],[-386,-624],[-597,-414],[-192,-24],[-370,-145],[-399,-138],[-238,-365],[-4,-415],[-141,-388],[-453,-472],[112,-462],[-125,-488],[-142,-577],[-391,-36],[-410,482],[-556,3],[-269,324],[-186,577],[-481,735],[-141,385],[-38,530],[-384,546],[100,435],[-186,208],[275,691],[418,220],[110,247],[58,461],[-318,-209],[-151,-88],[-249,-84],[-341,193],[-19,401],[109,314],[258,9],[567,-157],[-478,375],[-249,202],[-276,-83],[-232,147],[310,550],[-169,220],[-220,409],[-335,626],[-353,230],[3,247],[-745,346],[-590,43],[-743,-24],[-677,-44],[-323,188],[-482,372],[729,186],[559,31],[-1188,154],[-627,241],[39,229],[1051,285],[1018,284],[107,214],[-750,213],[243,235],[961,413],[404,63],[-115,265],[658,156],[854,93],[853,5],[303,-184],[737,325],[663,-221],[390,-46],[577,-192],[-660,318],[38,253]],[[69148,21851],[179,-186],[263,-74],[9,-112],[-77,-269],[-427,-38],[-7,314],[41,244],[19,121]],[[84713,45326],[32,139],[239,133],[194,20],[87,74],[105,-74],[-102,-160],[-289,-258],[-233,-170]],[[54540,33696],[133,292],[109,-162],[47,-252],[125,-43],[175,-112],[149,43],[248,302],[0,2182]],[[55526,35946],[75,-88],[165,-562],[-26,-360],[62,-207],[199,60],[139,264],[132,177],[68,283],[135,137],[117,-71],[133,-166],[226,-29],[178,138],[28,184],[48,283],[152,47],[83,222],[93,393],[249,442],[393,435]],[[58175,37528],[113,-7],[134,-100],[94,71],[148,-59]],[[58664,37433],[133,-832],[72,-419],[-49,-659],[23,-212]],[[58843,35311],[-140,108],[-80,-42],[-26,-172],[-76,-222],[2,-204],[166,-320],[163,63],[56,263]],[[58908,34785],[211,-5]],[[59119,34780],[-70,-430],[-32,-491],[-72,-267],[-190,-298],[-54,-86],[-118,-300],[-77,-303],[-158,-424],[-314,-609],[-196,-355],[-210,-269],[-290,-229],[-141,-31],[-36,-164],[-169,88],[-138,-113],[-301,114],[-168,-72],[-115,31],[-286,-233],[-238,-94],[-171,-223],[-127,-14],[-117,210],[-94,11],[-120,264],[-13,-82],[-37,159],[2,346],[-90,396],[89,108],[-7,453],[-182,553],[-139,501],[-1,1],[-199,768]],[[58049,33472],[-121,182],[-130,-120],[-151,-232],[-148,-374],[209,-454],[99,59],[51,188],[155,93],[47,192],[85,288],[-96,178]],[[23016,65864],[-107,-518],[-49,-426],[-20,-791],[-27,-289],[48,-322],[86,-288],[56,-458],[184,-440],[65,-337],[109,-291],[295,-157],[114,-247],[244,165],[212,60],[208,106],[175,101],[176,241],[67,345],[22,496],[48,173],[188,155],[294,137],[246,-21],[169,50],[66,-125],[-9,-285],[-149,-351],[-66,-360],[51,-103],[-42,-255],[-69,-461],[-71,152],[-58,-10]],[[25472,61510],[-53,-8],[-99,-357],[-51,70],[-33,-27],[2,-87]],[[25238,61101],[-257,7],[-259,-1],[-1,-333],[-125,-1],[103,-198],[103,-136],[31,-128],[45,-36],[-7,-201],[-357,-2],[-133,-481],[39,-111],[-32,-138],[-7,-172]],[[24381,59170],[-314,636],[-144,191],[-226,155],[-156,-43],[-223,-223],[-140,-58],[-196,156],[-208,112],[-260,271],[-208,83],[-314,275],[-233,282],[-70,158],[-155,35],[-284,187],[-116,270],[-299,335],[-139,373],[-66,288],[93,57],[-29,169],[64,153],[1,204],[-93,266],[-25,235],[-94,298],[-244,587],[-280,462],[-135,368],[-238,241],[-51,145],[42,365],[-142,138],[-164,287],[-69,412],[-149,48],[-162,311],[-130,288],[-12,184],[-149,446],[-99,452],[5,227],[-201,234],[-93,-25],[-159,163],[-44,-240],[46,-284],[27,-444],[95,-243],[206,-407],[46,-139],[42,-42],[37,-203],[49,8],[56,-381],[85,-150],[59,-210],[174,-300],[92,-550],[83,-259],[77,-277],[15,-311],[134,-20],[112,-268],[100,-264],[-6,-106],[-117,-217],[-49,3],[-74,359],[-181,337],[-201,286],[-142,150],[9,432],[-42,320],[-132,183],[-191,264],[-37,-76],[-70,154],[-171,143],[-164,343],[20,44],[115,-33],[103,221],[10,266],[-214,422],[-163,163],[-102,369],[-103,388],[-129,472],[-113,531]],[[33993,32727],[180,63],[279,-457],[103,18],[286,-379],[218,-327],[160,-402],[-122,-280],[77,-334]],[[35174,30629],[-121,-372],[-313,-328],[-205,118],[-151,-63],[-256,253],[-189,-19],[-169,327]],[[34826,35372],[54,341],[38,350],[0,325],[-100,107],[-104,-96],[-103,26],[-33,228],[-26,541],[-52,177],[-187,160],[-114,-116],[-293,113],[18,802],[-82,329]],[[33842,38659],[87,122],[-27,337],[77,259],[49,465],[-66,367],[-151,166],[-30,233],[41,342],[-533,24],[-107,688],[81,10],[-3,255],[-55,172],[-12,342],[-161,175],[-175,-6],[-115,172],[-188,117],[-109,220],[-311,98],[-302,529],[23,396],[-34,227],[29,443],[-363,-100],[-147,-222],[-243,-239],[-62,-179],[-143,-13],[-206,50]],[[30686,44109],[-157,-102],[-126,68],[18,898],[-228,-348],[-245,15],[-105,315],[-184,34],[59,254],[-155,359],[-115,532],[73,108],[0,250],[168,171],[-28,319],[71,206],[20,275],[318,402],[227,114],[37,89],[251,-28]],[[30585,48040],[125,1620],[6,256],[-43,339],[-123,215],[1,430],[156,97],[56,-61],[9,226],[-162,61],[-4,370],[541,-13],[92,203],[77,-187],[55,-349],[52,73]],[[31423,51320],[153,-312],[216,38],[54,181],[206,138],[115,97],[32,250],[198,168],[-15,124],[-235,51],[-39,372],[12,396],[-125,153],[52,55],[206,-76],[221,-148],[80,140],[200,92],[310,221],[102,225],[-37,167]],[[33129,53652],[145,26],[64,-136],[-36,-259],[96,-90],[63,-274],[-77,-209],[-44,-502],[71,-299],[20,-274],[171,-277],[137,-29],[30,116],[88,25],[126,104],[90,157],[154,-50],[67,21]],[[34294,51702],[151,-48],[25,120],[-46,118],[28,171],[112,-53],[131,61],[159,-125]],[[34854,51946],[121,-122],[86,160],[62,-25],[38,-166],[133,42],[107,224],[85,436],[164,540]],[[35650,53035],[95,28],[69,-327],[155,-1033],[149,-97],[7,-408],[-208,-487],[86,-178],[491,-92],[10,-593],[211,388],[349,-212],[462,-361],[135,-346],[-45,-327],[323,182],[540,-313],[415,23],[411,-489],[355,-662],[214,-170],[237,-24],[101,-186],[94,-752],[46,-358],[-110,-977],[-142,-385],[-391,-822],[-177,-668],[-206,-513],[-69,-11],[-78,-435],[20,-1107],[-77,-910],[-30,-390],[-88,-233],[-49,-790],[-282,-771],[-47,-610],[-225,-256],[-65,-355],[-302,2],[-437,-227],[-195,-263],[-311,-173],[-327,-470],[-235,-586],[-41,-441],[46,-326],[-51,-597],[-63,-289],[-195,-325],[-308,-1040],[-244,-468],[-189,-277],[-127,-562],[-183,-337]],[[33842,38659],[-4,182],[-259,302],[-258,9],[-484,-172],[-133,-520],[-7,-318],[-110,-708]],[[30669,40193],[175,638],[-119,496],[63,199],[-49,219],[108,295],[6,503],[13,415],[60,200],[-240,951]],[[30452,39739],[-279,340],[-24,242],[-551,593],[-498,646],[-214,365],[-115,488],[46,170],[-236,775],[-274,1090],[-262,1177],[-114,269],[-87,435],[-216,386],[-198,239],[90,264],[-134,563],[86,414],[221,373]],[[27693,48568],[33,-246],[-79,-141],[8,-216],[114,47],[113,-64],[116,-298],[157,243],[53,398],[170,514],[334,233],[303,619],[86,384],[-38,449]],[[29063,50490],[74,56],[184,-280],[89,-279],[129,-152],[163,-620],[207,-74],[153,157],[101,-103],[166,51],[213,-276],[-179,-602],[83,-14],[139,-314]],[[29063,50490],[-119,140],[-137,195],[-79,-94],[-235,82],[-68,255],[-52,-10],[-278,338]],[[28095,51396],[-37,183],[103,44],[-12,296],[65,214],[138,40],[117,371],[106,310],[-102,141],[52,343],[-62,540],[59,155],[-44,500],[-112,315]],[[28366,54848],[36,287],[89,-43],[52,176],[-64,348],[34,86]],[[28513,55702],[143,-18],[209,412],[114,63],[3,195],[51,500],[159,274],[175,11],[22,123],[218,-49],[218,298],[109,132],[134,285],[98,-36],[73,-156],[-54,-199]],[[30185,57537],[-178,-99],[-71,-295],[-107,-169],[-81,-220],[-34,-422],[-77,-345],[144,-40],[35,-271],[62,-130],[21,-238],[-33,-219],[10,-123],[69,-49],[66,-207],[357,57],[161,-75],[196,-508],[112,63],[200,-32],[158,68],[99,-102],[-50,-318],[-62,-199],[-22,-423],[56,-393],[79,-175],[9,-133],[-140,-294],[100,-130],[74,-207],[85,-589]],[[28366,54848],[-93,170],[-59,319],[68,158],[-70,40],[-52,196],[-138,164],[-122,-38],[-56,-205],[-112,-149],[-61,-20],[-27,-123],[132,-321],[-75,-76],[-40,-87],[-130,-30],[-48,353],[-36,-101],[-92,35],[-56,238],[-114,39],[-72,69],[-119,-1],[-8,-128],[-32,89]],[[26954,55439],[14,117],[23,120],[-10,107],[41,70],[-58,88],[-1,238],[107,53]],[[27070,56232],[100,-212],[-6,-126],[111,-26],[26,48],[77,-145],[136,42],[119,150],[168,119],[95,176],[153,-34],[-10,-58],[155,-21],[124,-102],[90,-177],[105,-164]],[[26954,55439],[-151,131],[-56,124],[32,103],[-11,130],[-77,142],[-109,116],[-95,76],[-19,173],[-73,105],[18,-172],[-55,-141],[-64,164],[-89,58],[-38,120],[2,179],[36,187],[-78,83],[64,114]],[[26191,57131],[42,76],[183,-156],[63,77],[89,-50],[46,-121],[82,-40],[66,126]],[[26762,57043],[70,-321],[108,-238],[130,-252]],[[26191,57131],[-96,186],[-130,238],[-61,200],[-117,185],[-140,267],[31,91],[46,-88],[21,41]],[[25745,58251],[86,25],[35,135],[41,5],[-6,290],[65,14],[58,-4],[60,158],[82,-120],[29,74],[51,70],[97,163],[4,121],[27,-5],[36,141],[29,17],[47,-90],[56,-27],[61,76],[70,0],[97,77],[38,81],[95,-12]],[[26903,59440],[-24,-57],[-14,-132],[29,-216],[-64,-202],[-30,-237],[-9,-261],[15,-152],[7,-266],[-43,-58],[-26,-253],[19,-156],[-56,-151],[12,-159],[43,-97]],[[25745,58251],[-48,185],[-84,51]],[[25613,58487],[19,237],[-38,64],[-57,42],[-122,-70],[-10,79],[-84,95],[-60,118],[-82,50]],[[25179,59102],[58,150],[-22,116],[20,113],[131,166],[127,225]],[[25493,59872],[29,-23],[61,104],[79,8],[26,-48],[43,29],[129,-53],[128,15],[90,66],[32,66],[89,-31],[66,-40],[73,14],[55,51],[127,-82],[44,-13],[85,-110],[80,-132],[101,-91],[73,-162]],[[25613,58487],[-31,-139],[-161,9],[-100,57],[-115,117],[-154,37],[-79,127]],[[24973,58695],[9,86],[95,149],[52,66],[-15,69],[65,37]],[[25238,61101],[-2,-468],[-22,-667],[83,0]],[[25297,59966],[90,-107],[24,88],[82,-75]],[[24973,58695],[-142,103],[-174,11],[-127,117],[-149,244]],[[25472,61510],[1,-87],[53,-3],[-5,-160],[-45,-256],[24,-91],[-29,-212],[18,-56],[-32,-299],[-55,-156],[-50,-19],[-55,-205]],[[30185,57537],[-8,-139],[-163,-69],[91,-268],[-3,-309],[-123,-344],[105,-468],[120,38],[62,427],[-86,208],[-14,447],[346,241],[-38,278],[97,186],[100,-415],[195,-9],[180,-330],[11,-195],[249,-6],[297,61],[159,-264],[213,-74],[155,185],[4,149],[344,35],[333,9],[-236,-175],[95,-279],[222,-44],[210,-291],[45,-473],[144,13],[109,-139]],[[33400,55523],[-220,-347],[-24,-215],[95,-220],[-69,-110],[-171,-95],[5,-273],[-75,-163],[188,-448]],[[33400,55523],[183,-217],[171,-385],[8,-304],[105,-14],[149,-289],[109,-205]],[[34125,54109],[-44,-532],[-169,-154],[15,-139],[-51,-305],[123,-429],[89,-1],[37,-333],[169,-514]],[[34125,54109],[333,-119],[30,107],[225,43],[298,-159]],[[35011,53981],[-144,-508],[22,-404],[109,-351],[-49,-254],[-24,-270],[-71,-248]],[[35011,53981],[95,-65],[204,-140],[294,-499],[46,-242]],[[51718,79804],[131,-155],[400,-109],[-140,-404],[-35,-421]],[[52074,78715],[-77,-101],[-126,54],[9,-150],[-203,-332],[-5,-267],[133,92],[95,-259]],[[51900,77752],[-11,-167],[82,-222],[-97,-180],[72,-457],[151,-75],[-32,-256]],[[52065,76395],[-252,-334],[-548,160],[-404,-192],[-32,-355]],[[50829,75674],[-322,-77],[-313,267],[-101,-127],[-511,268],[-111,230]],[[49471,76235],[144,354],[53,1177],[-287,620],[-205,299],[-424,227],[-28,431],[360,129],[466,-152],[-88,669],[263,-254],[646,461],[84,484],[243,119]],[[50698,80799],[40,-207],[129,-10],[129,-237],[194,-279],[143,46],[243,-269]],[[51576,79843],[62,-52],[80,13]],[[52429,75765],[179,226],[47,-507],[-92,-456],[-126,120],[-64,398],[56,219]],[[27693,48568],[148,442],[-60,258],[-106,-275],[-166,259],[56,167],[-47,536],[97,89],[52,368],[105,381],[-20,241],[153,126],[190,236]],[[31588,61519],[142,-52],[50,-118],[-71,-149],[-209,4],[-163,-21],[-16,253],[40,86],[227,-3]],[[28453,61504],[187,-53],[147,-142],[46,-161],[-195,-11],[-84,-99],[-156,95],[-159,215],[34,135],[116,41],[64,-20]],[[27147,64280],[240,-42],[219,-7],[261,-201],[110,-216],[260,66],[98,-138],[235,-366],[173,-267],[92,8],[165,-120],[-20,-167],[205,-24],[210,-242],[-33,-138],[-185,-75],[-187,-29],[-191,46],[-398,-57],[186,329],[-113,154],[-179,39],[-96,171],[-66,336],[-157,-23],[-259,159],[-83,124],[-362,91],[-97,115],[104,148],[-273,30],[-199,-307],[-115,-8],[-40,-144],[-138,-65],[-118,56],[146,183],[60,213],[126,131],[142,116],[210,56],[67,65]],[[58175,37528],[-177,267],[-215,90],[-82,375],[0,208],[-119,64],[-315,649],[-87,342],[-56,105],[-107,473]],[[57017,40101],[311,-65],[90,-68],[94,13],[154,383],[241,486],[100,46],[33,205],[159,235],[210,81]],[[58409,41417],[18,-220],[232,12],[128,-125],[60,-146],[132,-43],[145,-190],[0,-748],[-54,-409],[-12,-442],[45,-175],[-31,-348],[-42,-53],[-74,-426],[-292,-671]],[[55526,35946],[0,1725],[274,20],[8,2105],[207,19],[428,207],[106,-243],[177,231],[85,2],[156,133]],[[56967,40145],[50,-44]],[[54540,33696],[-207,446],[-108,432],[-62,575],[-68,428],[-93,910],[-7,707],[-35,322],[-108,243],[-144,489],[-146,708],[-60,371],[-226,577],[-17,453]],[[53259,40357],[134,113],[166,100],[180,-17],[166,-267],[42,41],[1126,26],[192,-284],[673,-83],[510,241]],[[56448,40227],[228,134],[180,-34],[109,-133],[2,-49]],[[45357,58612],[-115,460],[-138,210],[122,112],[134,415],[66,304]],[[45426,60113],[96,189],[138,-51],[135,129],[155,6],[133,-173],[184,-157],[168,-435],[184,-405]],[[46619,59216],[13,-368],[54,-338],[104,-166],[24,-229],[-13,-184]],[[46801,57931],[-40,-33],[-151,47],[-21,-66],[-61,-13],[-200,144],[-134,6]],[[46194,58016],[-513,25],[-75,-67],[-92,19],[-147,-96]],[[45367,57897],[-46,453]],[[45321,58350],[253,-13],[67,83],[50,5],[103,136],[119,-124],[121,-11],[120,133],[-56,170],[-92,-99],[-86,3],[-110,145],[-88,-9],[-63,-140],[-302,-17]],[[46619,59216],[93,107],[47,348],[88,14],[194,-165],[157,117],[107,-39],[42,131],[1114,9],[62,414],[-48,73],[-134,2550],[-134,2550],[425,10]],[[48632,65335],[937,-1289],[937,-1289],[66,-277],[173,-169],[129,-96],[3,-376],[308,58]],[[51185,61897],[1,-1361],[-152,-394],[-24,-364],[-247,-94],[-379,-51],[-102,-210],[-178,-23]],[[50104,59400],[-178,-3],[-70,114],[-153,-84],[-259,-246],[-53,-184],[-216,-265],[-38,-152],[-116,-120],[-134,79],[-76,-144],[-41,-405],[-221,-490],[7,-200],[-76,-250],[18,-343]],[[48498,56707],[-114,-88],[-65,-74],[-43,253],[-80,-67],[-48,11],[-51,-172],[-215,5],[-77,89],[-36,-54]],[[47769,56610],[-85,170],[15,176],[-35,69],[-59,-58],[11,192],[57,152],[-114,248],[-33,163],[-62,130],[-55,15],[-67,-83],[-90,-79],[-76,-128],[-119,48],[-77,150],[-46,19],[-73,-78],[-44,-1],[-16,216]],[[47587,66766],[1045,-1431]],[[45426,60113],[-24,318],[78,291],[34,557],[-30,583],[-34,294],[28,295],[-72,281],[-146,255]],[[50747,54278],[-229,-69]],[[50518,54209],[-69,407],[13,1357],[-56,122],[-11,290],[-96,207],[-85,174],[35,311]],[[50249,57077],[96,67],[56,258],[136,56],[61,176]],[[50598,57634],[93,173],[100,2],[212,-340]],[[51003,57469],[-11,-197],[62,-350],[-54,-238],[29,-159],[-135,-366],[-86,-181],[-52,-372],[7,-376],[-16,-952]],[[54026,58177],[-78,-34],[-9,-188]],[[53939,57955],[-52,-13],[-188,647],[-65,24],[-217,-331],[-215,173],[-150,34],[-80,-83],[-163,18],[-164,-252],[-141,-14],[-337,305],[-131,-145],[-142,10],[-104,223],[-279,221],[-298,-70],[-72,-128],[-39,-340],[-80,-238],[-19,-527]],[[50598,57634],[6,405],[-320,134],[-9,286],[-156,386],[-37,269],[22,286]],[[51185,61897],[392,263],[804,1161],[952,1126]],[[53333,64447],[439,-255],[156,-324],[197,220]],[[53939,57955],[110,-235],[-31,-107],[-14,-196],[-234,-457],[-74,-377],[-39,-307],[-59,-132],[-56,-414],[-148,-243],[-43,-299],[-63,-238],[-26,-246],[-191,-199],[-156,243],[-105,-10],[-165,-345],[-81,-6],[-132,-570],[-71,-418]],[[52361,53399],[-289,-213],[-105,31],[-107,-132],[-222,13],[-149,370],[-91,427],[-197,389],[-209,-7],[-245,1]],[[54244,54965],[-140,-599],[-67,-107],[-21,-458],[28,-249],[-23,-176],[132,-309],[23,-212],[103,-305],[127,-190],[12,-269],[29,-172]],[[54447,51919],[-20,-319],[-220,140],[-225,156],[-350,23]],[[53632,51919],[-35,32],[-164,-76],[-169,79],[-132,-38]],[[53132,51916],[-452,13]],[[52680,51929],[40,466],[-108,391],[-127,100],[-56,265],[-72,85],[4,163]],[[50518,54209],[-224,-126]],[[50294,54083],[-62,207],[-74,375],[-22,294],[61,532],[-69,215],[-27,466],[1,429],[-116,305],[20,184]],[[50006,57090],[243,-13]],[[50294,54083],[-436,-346],[-154,-203],[-250,-171],[-248,168]],[[49206,53531],[13,233],[-121,509],[73,667],[117,496],[-74,841]],[[49214,56277],[-38,444],[7,336],[482,27],[123,-43],[90,96],[128,-47]],[[48498,56707],[125,-129],[49,-195],[125,-125],[97,149],[130,22],[190,-152]],[[49206,53531],[-126,-7],[-194,116],[-178,-7],[-329,-103],[-193,-170],[-275,-217],[-54,15]],[[47857,53158],[22,487],[26,74],[-8,233],[-118,247],[-88,40],[-81,162],[60,262],[-28,286],[13,172]],[[47655,55121],[44,0],[17,258],[-22,114],[27,82],[103,71],[-69,473],[-64,245],[23,200],[55,46]],[[47655,55121],[-78,15],[-57,-238],[-78,3],[-55,126],[19,237],[-116,362],[-73,-67],[-59,-13]],[[47158,55546],[-77,-34],[3,217],[-44,155],[9,171],[-60,249],[-78,211],[-222,1],[-65,-112],[-76,-13],[-48,-128],[-32,-163],[-148,-260]],[[46320,55840],[-122,349],[-108,232],[-71,76],[-69,118],[-32,261],[-41,130],[-80,97]],[[45797,57103],[123,288],[84,-11],[73,99],[61,1],[44,78],[-24,196],[31,62],[5,200]],[[45797,57103],[-149,247],[-117,39],[-63,166],[1,90],[-84,125],[-18,127]],[[47857,53158],[-73,-5],[-286,282],[-252,449],[-237,324],[-187,381]],[[46822,54589],[66,189],[15,172],[126,320],[129,276]],[[46822,54589],[-75,44],[-200,238],[-144,316],[-49,216],[-34,437]],[[55125,52650],[-178,33],[-188,99],[-166,-313],[-146,-550]],[[56824,55442],[152,-239],[2,-192],[187,-308],[116,-255],[70,-355],[208,-234],[44,-187]],[[53609,47755],[-104,203],[-84,-100],[-112,-255]],[[53309,47603],[-228,626]],[[53081,48229],[212,326],[-105,391],[95,148],[187,73],[23,261],[148,-283],[245,-25],[85,279],[36,393],[-31,461],[-131,350],[120,684],[-69,117],[-207,-48],[-78,305],[21,258]],[[53081,48229],[-285,596],[-184,488],[-169,610],[9,196],[61,189],[67,430],[56,438]],[[52636,51176],[94,35],[404,-6],[-2,711]],[[52636,51176],[-52,90],[96,663]],[[59099,45126],[131,-264],[71,-501],[-47,-160],[-56,-479],[53,-490],[-87,-205],[-85,-549],[147,-153]],[[59226,42325],[-843,-487],[26,-421]],[[56448,40227],[-181,369],[-188,483],[13,1880],[579,-7],[-24,203],[41,222],[-49,277],[32,286],[-29,184]],[[59599,43773],[-77,-449],[77,-768],[97,9],[100,-191],[116,-427],[24,-760],[-120,-124],[-85,-410],[-181,365],[-21,417],[59,274],[-16,237],[-110,149],[-77,-54],[-159,284]],[[61198,44484],[45,-265],[-11,-588],[34,-519],[11,-923],[49,-290],[-83,-422],[-108,-410],[-177,-366],[-254,-225],[-313,-287],[-313,-634],[-107,-108],[-194,-420],[-115,-136],[-23,-421],[132,-448],[54,-346],[4,-177],[49,29],[-8,-579],[-45,-275],[65,-101],[-41,-245],[-116,-211],[-229,-199],[-334,-320],[-122,-219],[24,-248],[71,-40],[-24,-311]],[[58908,34785],[-24,261],[-41,265]],[[53383,47159],[-74,444]],[[53259,40357],[-26,372],[38,519],[96,541],[15,254],[90,532],[66,243],[159,386],[90,263],[29,438],[-15,335],[-83,211],[-74,358],[-68,355],[15,122],[85,235],[-84,570],[-57,396],[-139,374],[26,115]],[[58062,48902],[169,-46],[85,336],[147,-38]],[[59922,69905],[-49,-186]],[[59873,69719],[-100,82],[-58,-394],[69,-66],[-71,-81],[-12,-156],[131,80]],[[59832,69184],[7,-230],[-139,-944]],[[59700,68010],[-27,153],[-155,862]],[[59518,69025],[80,194],[-19,34],[74,276],[56,446],[40,149],[8,6]],[[59757,70130],[93,-1],[25,104],[75,8]],[[59950,70241],[4,-242],[-38,-90],[6,-4]],[[59757,70130],[99,482],[138,416],[5,21]],[[59999,71049],[125,-31],[45,-231],[-151,-223],[-68,-323]],[[63761,43212],[74,-251],[69,-390],[45,-711],[72,-276],[-28,-284],[-49,-174],[-94,347],[-53,-175],[53,-438],[-24,-250],[-77,-137],[-18,-500],[-109,-689],[-137,-814],[-172,-1120],[-106,-821],[-125,-685],[-226,-140],[-243,-250],[-160,151],[-220,211],[-77,312],[-18,524],[-98,471],[-26,425],[50,426],[128,102],[1,197],[133,447],[25,377],[-65,280],[-52,372],[-23,544],[97,331],[38,375],[138,22],[155,121],[103,107],[122,7],[158,337],[229,364],[83,297],[-38,253],[118,-71],[153,410],[6,356],[92,264],[96,-254]],[[59873,69719],[0,-362],[-41,-173]],[[45321,58350],[36,262]],[[52633,68486],[-118,1061],[-171,238],[-3,143],[-227,352],[-24,445],[171,330],[65,487],[-44,563],[57,303]],[[52339,72408],[302,239],[195,-71],[-9,-299],[236,217],[20,-113],[-139,-290],[-2,-273],[96,-147],[-36,-511],[-183,-297],[53,-322],[143,-10],[70,-281],[106,-92]],[[53191,70158],[-16,-454],[-135,-170],[-86,-189],[-191,-228],[30,-244],[-24,-250],[-136,-137]],[[47592,66920],[-2,700],[449,436],[277,90],[227,159],[107,295],[324,234],[12,438],[161,51],[126,219],[363,99],[51,230],[-73,125],[-96,624],[-17,359],[-104,379]],[[49397,71358],[267,323],[300,102],[175,244],[268,180],[471,105],[459,48],[140,-87],[262,232],[297,5],[113,-137],[190,35]],[[52633,68486],[90,-522],[15,-274],[-49,-482],[21,-270],[-36,-323],[24,-371],[-110,-247],[164,-431],[11,-253],[99,-330],[130,109],[219,-275],[122,-370]],[[59922,69905],[309,-234],[544,630]],[[60775,70301],[112,-720]],[[60887,69581],[-53,-89],[-556,-296],[277,-591],[-92,-101],[-46,-197],[-212,-82],[-66,-213],[-120,-182],[-310,94]],[[59709,67924],[-9,86]],[[64327,64904],[49,29],[11,-162],[217,93],[230,-15],[168,-18],[190,400],[207,379],[176,364]],[[65575,65974],[52,-202]],[[65627,65772],[38,-466]],[[65665,65306],[-142,-3],[-23,-384],[50,-82],[-126,-117],[-1,-241],[-81,-245],[-7,-238]],[[65335,63996],[-56,-125],[-835,298],[-106,599],[-11,136]],[[64113,65205],[-18,430],[75,310],[76,64],[84,-185],[5,-346],[-61,-348]],[[64274,65130],[-77,-42],[-84,117]],[[63326,68290],[58,-261],[-25,-135],[89,-445]],[[63448,67449],[-196,-16],[-69,282],[-248,57]],[[62935,67772],[204,567],[187,-49]],[[60775,70301],[615,614],[105,715],[-26,431],[152,146],[142,369]],[[61763,72576],[119,92],[324,-77],[97,-150],[133,100]],[[62436,72541],[180,-705],[182,-177],[21,-345],[-139,-204],[-65,-461],[193,-562],[340,-324],[143,-449],[-46,-428],[89,0],[3,-314],[153,-311]],[[63490,68261],[-164,29]],[[62935,67772],[-516,47],[-784,1188],[-413,414],[-335,160]],[[65665,65306],[125,-404],[155,-214],[203,-78],[165,-107],[125,-339],[75,-196],[100,-75],[-1,-132],[-101,-352],[-44,-166],[-117,-189],[-104,-404],[-126,31],[-58,-141],[-44,-300],[34,-395],[-26,-72],[-128,2],[-174,-221],[-27,-288],[-63,-125],[-173,5],[-109,-149],[1,-238],[-134,-165],[-153,56],[-186,-199],[-128,-34]],[[64752,60417],[-91,413],[-217,975]],[[64444,61805],[833,591],[185,1182],[-127,418]],[[65575,65974],[80,201],[35,-51],[-26,-244],[-37,-108]],[[96448,41190],[175,-339],[-92,-78],[-93,259],[10,158]],[[96330,41322],[-39,163],[-6,453],[133,-182],[45,-476],[-75,74],[-58,-32]],[[78495,57780],[-66,713],[178,492],[359,112],[261,-84]],[[79227,59013],[229,-232],[126,407],[246,-217]],[[79828,58971],[64,-394],[-34,-708],[-467,-455],[122,-358],[-292,-43],[-240,-238]],[[78981,56775],[-233,87],[-112,307],[-141,611]],[[78495,57780],[-249,271],[-238,-11],[41,464],[-245,-3],[-22,-650],[-150,-863],[-90,-522],[19,-428],[181,-18],[113,-539],[50,-512],[155,-338],[168,-69],[144,-306]],[[78372,54256],[-91,-243],[-183,-71],[-22,304],[-227,258],[-48,-105]],[[77801,54399],[-110,227],[-47,292],[-148,334],[-135,280],[-45,-347],[-53,328],[30,369],[82,566]],[[77375,56448],[135,607],[152,551],[-108,539],[4,274],[-32,330],[-185,470],[-66,296],[96,109],[101,514],[-113,390],[-177,431],[-134,519],[117,107],[127,639],[196,26],[162,256],[159,137]],[[77809,62643],[120,-182],[16,-355],[188,-27],[-68,-623],[6,-530],[293,353],[83,-104],[163,17],[56,205],[210,-40],[211,-480],[18,-583],[224,-515],[-12,-500],[-90,-266]],[[77809,62643],[59,218],[237,384]],[[78105,63245],[25,-139],[148,-16],[-42,676],[144,86]],[[78380,63852],[162,-466],[125,-537],[342,-5],[108,-515],[-178,-155],[-80,-212],[333,-353],[231,-699],[175,-520],[210,-411],[70,-418],[-50,-590]],[[77375,56448],[-27,439],[86,452],[-94,350],[23,644],[-113,306],[-90,707],[-50,746],[-121,490],[-183,-297],[-315,-421],[-156,53],[-172,138],[96,732],[-58,554],[-218,681],[34,213],[-163,76],[-197,481]],[[75657,62792],[-18,476],[97,-90],[6,424]],[[75742,63602],[137,140],[-30,251],[63,201],[11,612],[217,-135],[124,487],[14,288],[153,496],[-8,338],[359,408],[199,-107],[-23,364],[97,108],[-20,224]],[[77035,67277],[162,44],[93,-348],[121,-141],[8,-452],[-11,-487],[-263,-493],[-33,-701],[293,98],[66,-544],[176,-115],[-81,-490],[206,-222],[121,-109],[203,172],[9,-244]],[[78380,63852],[149,145],[221,-3],[271,68],[236,315],[134,-222],[254,-108],[-44,-340],[132,-240],[280,-154]],[[80013,63313],[-371,-505],[-231,-558],[-61,-410],[212,-623],[260,-772],[252,-365],[169,-475],[127,-1093],[-37,-1039],[-232,-389],[-318,-381],[-227,-492],[-346,-550],[-101,378],[78,401],[-206,335]],[[86327,75524],[0,0]],[[86327,75524],[-106,36],[-120,-200],[-83,-202],[10,-424],[-143,-130],[-50,-105],[-104,-174],[-185,-97],[-121,-159],[-9,-256],[-32,-65],[111,-96],[157,-259]],[[85652,73393],[-40,-143],[-118,-39],[-197,-29],[-108,-266],[-124,21],[-17,-54]],[[85048,72883],[-135,112],[-34,-111],[-81,-49],[-10,112],[-72,54],[-75,94],[76,260],[66,69],[-25,108],[71,319],[-18,96],[-163,65],[-131,158]],[[84517,74170],[227,379],[306,318],[191,419],[131,-185],[241,-22],[-44,312],[429,254],[111,331],[179,-348]],[[85652,73393],[240,-697],[68,-383],[3,-681],[-105,-325],[-252,-113],[-222,-245],[-250,-51],[-31,322],[51,443],[-122,615],[206,99],[-190,506]],[[82410,80055],[-135,-446],[-197,-590],[72,-241],[157,74],[274,-92],[214,219],[223,-189],[251,-413],[-30,-210],[-219,66],[-404,-78],[-195,-168],[-204,-391],[-423,-229],[-277,-313],[-286,120],[-156,53],[-146,-381],[89,-227],[45,-195],[-194,-199],[-200,-316],[-324,-208],[-417,-22],[-448,-205],[-324,-318],[-123,184],[-336,-1],[-411,359],[-274,88],[-369,-82],[-574,133],[-306,-14],[-163,351],[-127,544],[-171,66],[-336,368],[-374,83],[-330,101],[-100,256],[107,690],[-192,476],[-396,222],[-233,313],[-73,413]],[[75742,63602],[-147,937],[-76,-2],[-46,-377],[-152,306],[86,336],[124,34],[128,500],[-160,101],[-257,-8],[-265,81],[-24,410],[-133,30],[-220,255],[-98,-401],[200,-313],[-173,-220],[-62,-215],[171,-159],[-47,-356],[96,-444],[43,-486]],[[74730,63611],[-39,-216],[-189,7],[-343,-122],[16,-445],[-148,-349],[-400,-398],[-311,-695],[-209,-373],[-276,-387],[-1,-271],[-138,-146],[-251,-212],[-129,-31],[-84,-450],[58,-769],[15,-490],[-118,-561],[-1,-1004],[-144,-29],[-126,-450],[84,-195],[-253,-168],[-93,-401],[-112,-170],[-263,552],[-128,827],[-107,596],[-97,279],[-148,568],[-69,739],[-48,369],[-253,811],[-115,1145],[-83,756],[1,716],[-54,553],[-404,-353],[-196,70],[-362,716],[133,214],[-82,232],[-326,501]],[[68937,64577],[185,395],[612,-2],[-56,507],[-156,300],[-31,455],[-182,265],[306,619],[323,-45],[290,620],[174,599],[270,593],[-4,421],[236,342],[-224,292],[-96,400],[-99,517],[137,255],[421,-144],[310,88],[268,496]],[[71621,71550],[298,-692],[-28,-482],[111,-303],[-9,-301],[-200,79],[78,-651],[273,-374],[386,-413]],[[72530,68413],[-176,-268],[-108,-553],[269,-224],[262,-289],[362,-332],[381,-76],[160,-301],[215,-56],[334,-138],[231,10],[32,234],[-36,375],[21,255]],[[74477,67050],[170,124],[23,-465]],[[74670,66709],[6,-119],[252,-224],[175,92],[234,-39],[227,17],[20,363],[-113,189]],[[75471,66988],[224,74],[252,439],[321,376],[233,-145],[198,249],[130,-367],[-94,-248],[300,-89]],[[75657,62792],[-79,308],[-16,301],[-53,285],[-116,344],[-256,23],[25,-243],[-87,-329],[-118,120],[-41,-108],[-78,65],[-108,53]],[[74670,66709],[184,439],[150,150],[198,-137],[147,-14],[122,-159]],[[72530,68413],[115,141],[223,-182],[280,-385],[157,-84],[93,-284],[216,-117],[225,-259],[314,-136],[324,-57]],[[68937,64577],[-203,150],[-83,424],[-215,450],[-512,-111],[-451,-11],[-391,-83]],[[67082,65396],[105,687],[400,305],[-23,272],[-133,96],[-7,520],[-266,260],[-112,357],[-137,310]],[[66909,68203],[465,-301],[278,88],[166,-75],[56,129],[194,-52],[361,246],[10,503],[154,334],[207,-1],[31,166],[212,77],[103,-55],[108,166],[-15,355],[118,356],[177,150],[-110,390],[265,-18],[76,213],[-12,227],[139,248],[-32,294],[-66,250],[163,258],[298,124],[319,68],[141,109],[162,67]],[[70877,72519],[205,-276],[82,-454],[457,-239]],[[68841,72526],[85,-72],[201,189],[93,-114],[90,271],[166,-12],[43,86],[29,239],[120,205],[150,-134],[-30,-181],[84,-28],[-26,-496],[110,-194],[97,125],[123,58],[173,265],[192,-44],[286,-1]],[[70827,72688],[50,-169]],[[66909,68203],[252,536],[-23,380],[-210,100],[-22,375],[-91,472],[119,323],[-121,87],[76,430],[113,736]],[[67002,71642],[284,-224],[209,79],[58,268],[219,89],[157,180],[55,472],[234,114],[44,211],[131,-158],[84,-19]],[[69725,74357],[-101,-182],[-303,98],[-26,-340],[301,46],[343,-192],[526,89]],[[70465,73876],[70,-546],[91,59],[169,-134],[-10,-230],[42,-337]],[[72294,75601],[-39,-134],[-438,-320],[-99,-234],[-356,-70],[-105,-378],[-294,80],[-192,-116],[-266,-279],[39,-138],[-79,-136]],[[67002,71642],[-24,498],[-207,21],[-318,523],[-221,65],[-308,299],[-197,55],[-122,-110],[-186,17],[-197,-338],[-244,-114]],[[64978,72558],[-52,417],[40,618],[-216,200],[71,405],[-184,34],[61,498],[262,-145],[244,189],[-202,355],[-80,338],[-224,-151],[-28,-433],[-87,383]],[[62436,72541],[-152,473],[55,183],[-87,678],[190,168]],[[62442,74043],[44,-223],[141,-273],[190,-78]],[[62817,73469],[101,17]],[[62918,73486],[327,436],[104,44],[82,-174],[-95,-292],[173,-309],[69,29]],[[63578,73220],[88,-436],[263,-123],[193,-296],[395,-102],[434,156],[27,139]],[[67082,65396],[-523,179],[-303,136],[-313,76],[-118,725],[-133,105],[-214,-106],[-280,-286],[-339,196],[-281,454],[-267,168],[-186,561],[-205,788],[-149,-96],[-177,196],[-104,-231]],[[59999,71049],[-26,452],[68,243]],[[60041,71744],[74,129],[75,130],[15,329],[91,-115],[306,165],[147,-112],[229,2],[320,222],[149,-10],[316,92]],[[62817,73469],[-113,342],[1,91],[-123,-2],[-82,159],[-58,-16]],[[62442,74043],[-109,172],[-207,147],[27,288],[-47,208]],[[62106,74858],[386,92]],[[62492,74950],[57,-155],[106,-103],[-56,-148],[148,-202],[-78,-189],[118,-160],[124,-97],[7,-410]],[[55734,91409],[371,-289],[433,-402],[8,-910],[93,-230]],[[56639,89578],[-478,-167],[-269,-413],[43,-361],[-441,-475],[-537,-509],[-202,-832],[198,-416],[265,-328],[-255,-666],[-289,-138],[-106,-992],[-157,-554],[-337,57],[-158,-468],[-321,-27],[-89,558],[-232,671],[-211,835]],[[58829,81362],[-239,-35],[-85,-129],[-18,-298],[-111,57],[-250,-28],[-73,138],[-104,-103],[-105,86],[-218,12],[-310,141],[-281,47],[-215,-14],[-152,-160],[-133,-23]],[[56535,81053],[-6,263],[-85,274],[166,121],[2,235],[-77,225],[-12,261]],[[56523,82432],[268,-4],[302,223],[64,333],[228,190],[-26,264]],[[57359,83438],[169,100],[298,228]],[[60617,78409],[-222,-48],[-185,-191],[-260,-31],[-239,-220],[14,-317]],[[59287,77741],[-38,64],[-432,149],[-19,221],[-257,-73],[-103,-325],[-215,-437]],[[58223,77340],[-126,101],[-131,-95],[-124,109]],[[57842,77455],[70,64],[49,203],[76,188],[-20,106],[58,47],[27,-81],[164,-18],[74,44],[-52,60],[19,88],[-97,150],[-40,247],[-101,97],[20,200],[-125,159],[-115,22],[-204,184],[-185,-58],[-66,-87]],[[57394,79070],[-118,0],[-69,-139],[-205,-56],[-95,-91],[-129,144],[-178,3],[-172,65],[-120,-127]],[[56308,78869],[-19,159],[-155,161]],[[56134,79189],[55,238],[77,154]],[[56266,79581],[60,-35],[-71,266],[252,491],[138,69],[29,166],[-139,515]],[[56266,79581],[-264,227],[-200,-84],[-131,61],[-165,-127],[-140,210],[-114,-81],[-16,36]],[[55236,79823],[-127,291],[-207,36],[-26,185],[-191,66],[-41,-153],[-151,122],[17,163],[-207,51],[-132,191]],[[54171,80775],[-114,377],[22,204],[-69,316],[-101,210],[77,158],[-64,300]],[[53922,82340],[189,174],[434,273],[350,200],[277,-100],[21,-144],[268,-7]],[[56314,82678],[142,-64],[67,-182]],[[54716,79012],[-21,-241],[-156,-2],[53,-128],[-92,-380]],[[54500,78261],[-53,-100],[-243,-14],[-140,-134],[-229,45]],[[53835,78058],[-398,153],[-62,205],[-274,-102],[-32,-113],[-169,84]],[[52900,78285],[-142,16],[-125,108],[42,145],[-10,104]],[[52665,78658],[83,33],[141,-164],[39,156],[245,-25],[199,106],[133,-18],[87,-121],[26,100],[-40,385],[100,75],[98,272]],[[53776,79457],[206,-190],[157,242],[98,44],[215,-180],[131,30],[128,-111]],[[54711,79292],[-23,-75],[28,-205]],[[56308,78869],[-170,-123],[-131,-401],[-168,-401],[-223,-111]],[[55616,77833],[-173,26],[-213,-155]],[[55230,77704],[-104,-89],[-229,114],[-208,253],[-88,73]],[[54601,78055],[-54,200],[-47,6]],[[54716,79012],[141,-151],[103,-65],[233,73],[22,118],[111,18],[135,92],[30,-38],[130,74],[66,139],[91,36],[297,-180],[59,61]],[[57842,77455],[-50,270],[30,252],[-9,259],[-160,352],[-89,249],[-86,175],[-84,58]],[[58223,77340],[6,-152],[-135,-128],[-84,56],[-78,-713]],[[57932,76403],[-163,62],[-202,215],[-327,-138],[-138,-150],[-408,31],[-213,92],[-108,-43],[-80,243]],[[56293,76715],[-51,103],[65,99],[-69,74],[-87,-133],[-162,172],[-22,244],[-169,139],[-31,188],[-151,232]],[[55907,83187],[-59,497]],[[55848,83684],[318,181],[466,-38],[273,59],[39,-123],[148,-38],[267,-287]],[[55848,83684],[10,445],[136,371],[262,202],[221,-442],[223,12],[53,453]],[[56753,84725],[237,105],[121,-73],[239,-219],[229,-1]],[[56753,84725],[32,349],[-102,-75],[-176,210],[-24,340],[351,164],[350,86],[301,-97],[287,17]],[[54171,80775],[-124,-62],[-73,68],[-70,-113],[-200,-114],[-103,-147],[-202,-129],[49,-176],[30,-249],[141,-142],[157,-254]],[[52665,78658],[-298,181],[-57,-128],[-236,4]],[[51718,79804],[16,259],[-56,133]],[[51678,80196],[32,400]],[[51710,80596],[-47,619],[167,0],[70,222],[69,541],[-51,200]],[[51918,82178],[54,125],[232,32],[52,-130],[188,291],[-63,222],[-13,335]],[[52368,83053],[210,-78],[178,90]],[[52756,83065],[4,-228],[281,-138],[-3,-210],[283,111],[156,162],[313,-233],[132,-189]],[[57932,76403],[-144,-245],[-101,-422],[89,-337]],[[57776,75399],[-239,79],[-283,-186]],[[57254,75292],[-3,-294],[-252,-56],[-196,206],[-222,-162],[-206,17]],[[56375,75003],[-20,391],[-139,189]],[[56216,75583],[46,84],[-30,70],[47,188],[105,185],[-135,255],[-24,216],[68,134]],[[57302,71436],[-35,-175],[-400,-50],[3,98],[-339,115],[52,251],[152,-199],[216,34],[207,-42],[-7,-103],[151,71]],[[57254,75292],[135,-157],[-86,-369],[-66,-67]],[[57237,74699],[-169,17],[-145,56],[-336,-154],[192,-332],[-141,-96],[-154,-1],[-147,305],[-52,-130],[62,-353],[139,-277],[-105,-129],[155,-273],[137,-171],[4,-334],[-257,157],[82,-302],[-176,-62],[105,-521],[-184,-8],[-228,257],[-104,473],[-49,393],[-108,272],[-143,337],[-18,168]],[[55597,73991],[129,287],[16,192],[91,85],[5,155]],[[55838,74710],[182,53],[106,129],[150,-12],[46,103],[53,20]],[[60041,71744],[-102,268],[105,222],[-169,-51],[-233,136],[-191,-340],[-421,-66],[-225,317],[-300,20],[-64,-245],[-192,-70],[-268,314],[-303,-11],[-165,588],[-203,328],[135,459],[-176,283],[308,565],[428,23],[117,449],[529,-78],[334,383],[324,167],[459,13],[485,-417],[399,-228],[323,91],[239,-53],[328,309]],[[61542,75120],[296,28],[268,-290]],[[57776,75399],[33,-228],[243,-190],[-51,-145],[-330,-33],[-118,-182],[-232,-319],[-87,276],[3,121]],[[55597,73991],[-48,41],[-5,130],[-154,199],[-24,281],[23,403],[38,184],[-47,93]],[[55380,75322],[-18,188],[120,291],[18,-111],[75,52]],[[55575,75742],[59,-159],[66,-60],[19,-214]],[[55719,75309],[-35,-201],[39,-254],[115,-144]],[[55230,77704],[67,-229],[89,-169],[-107,-222]],[[55279,77084],[-126,131],[-192,-8],[-239,98],[-130,-13],[-60,-123],[-99,136],[-59,-245],[136,-277],[61,-183],[127,-221],[106,-130],[105,-247],[246,-224]],[[55155,75778],[-31,-100]],[[55124,75678],[-261,218],[-161,213],[-254,176],[-233,434],[56,45],[-127,248],[-5,200],[-179,93],[-85,-255],[-82,198],[6,205],[10,9]],[[53809,77462],[194,-20],[51,100],[94,-97],[109,-11],[-1,165],[97,60],[27,239],[221,157]],[[52900,78285],[-22,-242],[-122,-100],[-206,75],[-60,-239],[-132,-19],[-48,94],[-156,-200],[-134,-28],[-120,126]],[[51576,79843],[30,331],[72,22]],[[50698,80799],[222,117]],[[50920,80916],[204,-47],[257,123],[176,-258],[153,-138]],[[50920,80916],[143,162],[244,869],[380,248],[231,-17]],[[47490,75324],[101,150],[113,86],[70,-289],[164,0],[47,75],[162,-21],[78,-296],[-129,-160],[-3,-461],[-45,-86],[-11,-280],[-120,-48],[111,-355],[-77,-388],[96,-175],[-38,-161],[-103,-222],[23,-195]],[[47929,72498],[-112,-153],[-146,83],[-143,-65],[42,462],[-26,363],[-124,55],[-67,224],[22,386],[111,215],[20,239],[58,355],[-6,250],[-56,212],[-12,200]],[[47490,75324],[14,420],[-114,257],[393,426],[340,-106],[373,3],[296,-101],[230,31],[449,-19]],[[50829,75674],[15,-344],[-263,-393],[-356,-125],[-25,-199],[-171,-327],[-107,-481],[108,-338],[-160,-263],[-60,-384],[-210,-118],[-197,-454],[-352,-9],[-265,11],[-174,-209],[-106,-223],[-136,49],[-103,199],[-79,340],[-259,92]],[[48278,82406],[46,-422],[-210,-528],[-493,-349],[-393,89],[225,617],[-145,601],[378,463],[210,276]],[[47896,83153],[57,-317],[-57,-317],[172,9],[210,-122]],[[96049,38125],[228,-366],[144,-272],[-105,-142],[-153,160],[-199,266],[-179,313],[-184,416],[-38,201],[119,-9],[156,-201],[122,-200],[89,-166]],[[95032,44386],[78,-203],[-194,4],[-106,363],[166,-142],[56,-22]],[[94910,44908],[-42,-109],[-206,512],[-57,353],[94,0],[100,-473],[111,-283]],[[94680,44747],[-108,-14],[-170,60],[-58,91],[17,235],[183,-93],[91,-124],[45,-155]],[[94344,45841],[65,-187],[12,-119],[-218,251],[-152,212],[-104,197],[41,60],[128,-142],[228,-272]],[[93649,46431],[111,-193],[-56,-33],[-121,134],[-114,243],[14,99],[166,-250]],[[99134,26908],[-105,-319],[-138,-404],[-214,-236],[-48,155],[-116,85],[160,486],[-91,326],[-299,236],[8,214],[201,206],[47,455],[-13,382],[-113,396],[8,104],[-133,244],[-218,523],[-117,418],[104,46],[151,-328],[216,-153],[78,-526],[202,-622],[5,403],[126,-161],[41,-447],[224,-192],[188,-48],[158,226],[141,-69],[-67,-524],[-85,-345],[-212,12],[-74,-179],[26,-254],[-41,-110]],[[97129,24846],[238,310],[167,306],[123,441],[106,149],[41,330],[195,273],[61,-251],[63,-244],[198,239],[80,-249],[0,-249],[-103,-274],[-182,-435],[-142,-238],[103,-284],[-214,-7],[-238,-223],[-75,-387],[-157,-597],[-219,-264],[-138,-169],[-256,13],[-180,194],[-302,42],[-46,217],[149,438],[349,583],[179,111],[200,225]],[[91024,26469],[166,-39],[20,-702],[-95,-203],[-29,-476],[-97,162],[-193,-412],[-57,32],[-171,19],[-171,505],[-38,390],[-160,515],[7,271],[181,-52],[269,-204],[151,81],[217,113]],[[85040,31546],[-294,-303],[-241,-137],[-53,-309],[-103,-240],[-236,-15],[-174,-52],[-246,107],[-199,-64],[-191,-27],[-165,-315],[-81,26],[-140,-167],[-133,-187],[-203,23],[-186,0],[-295,377],[-149,113],[6,338],[138,81],[47,134],[-10,212],[34,411],[-31,350],[-147,598],[-45,337],[12,336],[-111,385],[-7,174],[-123,235],[-35,463],[-158,467],[-39,252],[122,-255],[-93,548],[137,-171],[83,-229],[-5,303],[-138,465],[-26,186],[-65,177],[31,341],[56,146],[38,295],[-29,346],[114,425],[21,-450],[118,406],[225,198],[136,252],[212,217],[126,46],[77,-73],[219,220],[168,66],[42,129],[74,54],[153,-14],[292,173],[151,262],[71,316],[163,300],[13,236],[7,321],[194,502],[117,-510],[119,118],[-99,279],[87,287],[122,-128],[34,449],[152,291],[67,233],[140,101],[4,165],[122,-69],[5,148],[122,85],[134,80],[205,-271],[155,-350],[173,-4],[177,-56],[-59,325],[133,473],[126,155],[-44,147],[121,338],[168,208],[142,-70],[234,111],[-5,302],[-204,195],[148,86],[184,-147],[148,-242],[234,-151],[79,60],[172,-182],[162,169],[105,-51],[65,113],[127,-292],[-74,-316],[-105,-239],[-96,-20],[32,-236],[-81,-295],[-99,-291],[20,-166],[221,-327],[214,-189],[143,-204],[201,-350],[78,1],[145,-151],[43,-183],[265,-200],[183,202],[55,317],[56,262],[34,324],[85,470],[-39,286],[20,171],[-32,339],[37,445],[53,120],[-43,197],[67,313],[52,325],[7,168],[104,222],[78,-289],[19,-371],[70,-71],[11,-249],[101,-300],[21,-335],[-10,-214],[100,-464],[179,223],[92,-250],[133,-231],[-29,-262],[60,-506],[42,-295],[70,-72],[75,-505],[-27,-307],[90,-400],[301,-309],[197,-281],[186,-257],[-37,-143],[159,-371],[108,-639],[111,130],[113,-256],[68,91],[48,-626],[197,-363],[129,-226],[217,-478],[78,-475],[7,-337],[-19,-365],[132,-502],[-16,-523],[-48,-274],[-75,-527],[6,-339],[-55,-423],[-123,-538],[-205,-290],[-102,-458],[-93,-292],[-82,-510],[-107,-294],[-70,-442],[-36,-407],[14,-187],[-159,-205],[-311,-22],[-257,-242],[-127,-229],[-168,-254],[-230,262],[-170,104],[43,308],[-152,-112],[-243,-428],[-240,160],[-158,94],[-159,42],[-269,171],[-179,364],[-52,449],[-64,298],[-137,240],[-267,71],[91,287],[-67,438],[-136,-408],[-247,-109],[146,327],[42,341],[107,289],[-22,438],[-226,-504],[-174,-202],[-106,-470],[-217,243],[9,313],[-174,429],[-147,221],[52,137],[-356,358],[-195,17],[-267,287],[-498,-56],[-359,-211],[-317,-197],[-265,39]],[[72718,55024],[-42,-615],[-116,-168],[-242,-135],[-132,470],[-49,849],[126,959],[192,-328],[129,-416],[134,-616]],[[80409,61331],[-228,183],[-8,509],[137,267],[304,166],[159,-14],[62,-226],[-122,-260],[-64,-341],[-240,-284]],[[84517,74170],[-388,-171],[-204,-277],[-300,-161],[148,274],[-58,230],[220,397],[-147,310],[-242,-209],[-314,-411],[-171,-381],[-272,-29],[-142,-275],[147,-400],[227,-97],[9,-265],[220,-173],[311,422],[247,-230],[179,-15],[45,-310],[-393,-165],[-130,-319],[-270,-296],[-142,-414],[299,-325],[109,-581],[169,-541],[189,-454],[-5,-439],[-174,-161],[66,-315],[164,-184],[-43,-481],[-71,-468],[-155,-53],[-203,-640],[-225,-775],[-258,-705],[-382,-545],[-386,-498],[-313,-68],[-170,-262],[-96,192],[-157,-294],[-388,-296],[-294,-90],[-95,-624],[-154,-35],[-73,429],[66,228],[-373,189],[-131,-96]],[[83826,64992],[-167,-947],[-119,-485],[-146,499],[-32,438],[163,581],[223,447],[127,-176],[-49,-357]],[[53835,78058],[-31,-291],[67,-251]],[[53871,77516],[-221,86],[-226,-210],[15,-293],[-34,-168],[91,-301],[261,-298],[140,-488],[309,-476],[217,3],[68,-130],[-78,-118],[249,-214],[204,-178],[238,-308],[29,-111],[-52,-211],[-154,276],[-242,97],[-116,-382],[200,-219],[-33,-309],[-116,-35],[-148,-506],[-116,-46],[1,181],[57,317],[60,126],[-108,342],[-85,298],[-115,74],[-82,255],[-179,107],[-120,238],[-206,38],[-217,267],[-254,384],[-189,340],[-86,585],[-138,68],[-226,195],[-128,-80],[-161,-274],[-115,-43]],[[54100,73116],[211,51],[-100,-465],[41,-183],[-58,-303],[-213,222],[-141,64],[-387,300],[38,304],[325,-54],[284,64]],[[52419,74744],[139,183],[166,-419],[-39,-782],[-126,38],[-113,-197],[-105,156],[-11,713],[-64,338],[153,-30]],[[52368,83053],[-113,328],[-8,604],[46,159],[80,177],[244,37],[98,163],[223,167],[-9,-304],[-82,-192],[33,-166],[151,-89],[-68,-223],[-83,64],[-200,-425],[76,-288]],[[53436,83731],[88,-296],[-166,-478],[-291,333],[-39,246],[408,195]],[[47896,83153],[233,24],[298,-365],[-149,-406]],[[49140,82132],[1,0],[40,343],[-186,364],[-4,8],[-337,104],[-66,160],[101,264],[-92,163],[-149,-279],[-17,569],[-140,301],[101,611],[216,480],[222,-47],[335,49],[-297,-639],[283,81],[304,-3],[-72,-481],[-250,-530],[287,-38],[22,-62],[248,-697],[190,-95],[171,-673],[79,-233],[337,-113],[-34,-378],[-142,-173],[111,-305],[-250,-310],[-371,6],[-473,-163],[-130,116],[-183,-276],[-257,67],[-195,-226],[-148,118],[407,621],[249,127],[-2,1],[-434,98],[-79,235],[291,183],[-152,319],[52,387],[413,-54]],[[45969,89843],[-64,-382],[314,-403],[-361,-451],[-801,-405],[-240,-107],[-365,87],[-775,187],[273,261],[-605,289],[492,114],[-12,174],[-583,137],[188,385],[421,87],[433,-400],[422,321],[349,-167],[453,315],[461,-42]],[[63495,75281],[146,-311],[141,-419],[130,-28],[85,-159],[-228,-47],[-49,-459],[-48,-207],[-101,-138],[7,-293]],[[62492,74950],[68,96],[207,-169],[149,-36],[38,70],[-136,319],[72,82]],[[61542,75120],[42,252],[-70,403],[-160,218],[-154,68],[-102,181]],[[83564,58086],[-142,450],[238,-22],[97,-213],[-74,-510],[-119,295]],[[84051,56477],[70,165],[30,367],[153,35],[-44,-398],[205,570],[-26,-563],[-100,-195],[-87,-373],[-87,-175],[-171,409],[57,158]],[[85104,55551],[28,-392],[16,-332],[-94,-540],[-102,602],[-130,-300],[89,-435],[-79,-277],[-327,343],[-78,428],[84,280],[-176,280],[-87,-245],[-131,23],[-205,-330],[-46,173],[109,498],[175,166],[151,223],[98,-268],[212,162],[45,264],[196,15],[-16,457],[225,-280],[23,-297],[20,-218]],[[82917,56084],[-369,-561],[136,414],[200,364],[167,409],[146,587],[49,-482],[-183,-325],[-146,-406]],[[83982,61347],[-46,-245],[95,-423],[-73,-491],[-164,-196],[-43,-476],[62,-471],[147,-65],[123,70],[347,-328],[-27,-321],[91,-142],[-29,-272],[-216,290],[-103,310],[-71,-217],[-177,354],[-253,-87],[-138,130],[14,244],[87,151],[-83,136],[-36,-213],[-137,340],[-41,257],[-11,566],[112,-195],[29,925],[90,535],[169,-1],[171,-168],[85,153],[26,-150]],[[83899,57324],[-43,282],[166,-183],[177,1],[-5,-247],[-129,-251],[-176,-178],[-10,275],[20,301]],[[84861,57766],[78,-660],[-214,157],[5,-199],[68,-364],[-132,-133],[-11,416],[-84,31],[-43,357],[163,-47],[-4,224],[-169,451],[266,-13],[77,-220]],[[78372,54256],[64,-56],[164,-356],[116,-396],[16,-398],[-29,-269],[27,-203],[20,-349],[98,-163],[109,-523],[-5,-199],[-197,-40],[-263,438],[-329,469],[-32,301],[-161,395],[-38,489],[-100,322],[30,431],[-61,250]],[[80461,51765],[204,-202],[214,110],[56,500],[119,112],[333,128],[199,467],[137,374]],[[81723,53254],[126,-307],[58,202],[133,-19],[16,377],[13,291]],[[82069,53798],[214,411],[140,462],[112,2],[143,-299],[13,-257],[183,-165],[231,-177],[-20,-232],[-186,-29],[50,-289],[-205,-201]],[[81723,53254],[110,221],[236,323]],[[53809,77462],[62,54]],[[57797,86326],[-504,-47],[-489,-216],[-452,-125],[-161,323],[-269,193],[62,582],[-135,533],[133,345],[252,371],[635,640],[185,124],[-28,250],[-387,279]],[[54711,79292],[39,130],[123,-10],[95,61],[7,55],[54,28],[18,134],[64,26],[43,106],[82,1]],[[60669,61213],[161,-684],[77,-542],[152,-288],[379,-558],[154,-336],[151,-341],[87,-203],[136,-178]],[[61966,58083],[-83,-144],[-119,51]],[[61764,57990],[-95,191],[-114,346],[-124,190],[-71,204],[-242,237],[-191,7],[-67,124],[-163,-139],[-168,268],[-87,-441],[-323,124]],[[89411,73729],[-256,-595],[4,-610],[-104,-472],[48,-296],[-145,-416],[-355,-278],[-488,-36],[-396,-675],[-186,227],[-12,442],[-483,-130],[-329,-279],[-325,-11],[282,-435],[-186,-1004],[-179,-248],[-135,229],[69,533],[-176,172],[-113,405],[263,182],[145,371],[280,306],[203,403],[553,177],[297,-121],[291,1050],[185,-282],[408,591],[158,229],[174,723],[-47,664],[117,374],[295,108],[152,-819],[-9,-479]],[[90169,76553],[197,250],[62,-663],[-412,-162],[-244,-587],[-436,404],[-152,-646],[-308,-9],[-39,587],[138,455],[296,33],[81,817],[83,460],[326,-615],[213,-198],[195,-126]],[[86769,70351],[154,352],[158,-68],[114,248],[204,-127],[35,-203],[-156,-357],[-114,189],[-143,-137],[-73,-346],[-181,168],[2,281]],[[64752,60417],[-201,-158],[-54,-263],[-6,-201],[-277,-249],[-444,-276],[-249,-417],[-122,-33],[-83,35],[-163,-245],[-177,-114],[-233,-30],[-70,-34],[-61,-156],[-73,-43],[-43,-150],[-137,13],[-89,-80],[-192,30],[-72,345],[8,323],[-46,174],[-54,437],[-80,243],[56,29],[-29,270],[34,114],[-12,257]],[[61883,60238],[121,189],[-28,249],[74,290],[114,-153],[75,53],[321,14],[50,-59],[269,-60],[106,30],[70,-197],[130,99],[199,620],[259,266],[801,226]],[[63448,67449],[109,-510],[137,-135],[47,-207],[190,-249],[16,-243],[-27,-197],[35,-199],[80,-165],[37,-194],[41,-145]],[[64274,65130],[53,-226]],[[61883,60238],[-37,252],[-83,178],[-22,236],[-143,212],[-148,495],[-79,482],[-192,406],[-124,97],[-184,563],[-32,411],[12,350],[-159,655],[-130,231],[-150,122],[-92,339],[15,133],[-77,306],[-81,132],[-108,440],[-170,476],[-141,406],[-139,-3],[44,325],[12,206],[34,236]],[[36483,4468],[141,0],[414,127],[419,-127],[342,-255],[120,-359],[33,-254],[11,-301],[-430,-186],[-452,-150],[-522,-139],[-582,-116],[-658,35],[-365,197],[49,243],[593,162],[239,197],[174,254],[126,220],[168,209],[180,243]],[[31586,3163],[625,-23],[599,-58],[207,243],[147,208],[288,-243],[-82,-301],[-81,-266],[-582,81],[-621,-35],[-348,197],[0,23],[-152,174]],[[29468,8472],[190,70],[321,-23],[82,301],[16,219],[-6,475],[158,278],[256,93],[147,-220],[65,-220],[120,-267],[92,-254],[76,-267],[33,-266],[-49,-231],[-76,-220],[-326,-81],[-311,-116],[-364,11],[136,232],[-327,-81],[-310,-81],[-212,174],[-16,243],[305,231]],[[21575,8103],[174,104],[353,-81],[403,-46],[305,-81],[304,69],[163,-335],[-217,46],[-337,-23],[-343,23],[-376,-35],[-283,116],[-146,243]],[[15938,7061],[60,197],[332,-104],[359,-93],[332,104],[-158,-208],[-261,-151],[-386,47],[-278,208]],[[14643,7177],[202,127],[277,-139],[425,-231],[-164,23],[-359,58],[-381,162]],[[4524,4144],[169,220],[517,-93],[277,-185],[212,-209],[76,-266],[-533,-81],[-364,208],[-163,209],[-11,35],[-180,162]],[[0,529],[16,-5],[245,344],[501,-185],[32,21],[294,188],[38,-7],[32,-4],[402,-246],[352,246],[63,34],[816,104],[265,-138],[130,-71],[419,-196],[789,-151],[625,-185],[1072,-139],[800,162],[1181,-116],[669,-185],[734,174],[773,162],[60,278],[-1094,23],[-898,139],[-234,231],[-745,128],[49,266],[103,243],[104,220],[-55,243],[-462,162],[-212,209],[-430,185],[675,-35],[642,93],[402,-197],[495,173],[457,220],[223,197],[-98,243],[-359,162],[-408,174],[-571,35],[-500,81],[-539,58],[-180,220],[-359,185],[-217,208],[-87,672],[136,-58],[250,-185],[457,58],[441,81],[228,-255],[441,58],[370,127],[348,162],[315,197],[419,58],[-11,220],[-97,220],[81,208],[359,104],[163,-196],[425,115],[321,151],[397,12],[375,57],[376,139],[299,128],[337,127],[218,-35],[190,-46],[414,81],[370,-104],[381,11],[364,81],[375,-57],[414,-58],[386,23],[403,-12],[413,-11],[381,23],[283,174],[337,92],[349,-127],[331,104],[300,208],[179,-185],[98,-208],[180,-197],[288,174],[332,-220],[375,-70],[321,-162],[392,35],[354,104],[418,-23],[376,-81],[381,-104],[147,254],[-180,197],[-136,209],[-359,46],[-158,220],[-60,220],[-98,440],[213,-81],[364,-35],[359,35],[327,-93],[283,-174],[119,-208],[376,-35],[359,81],[381,116],[342,70],[283,-139],[370,46],[239,451],[224,-266],[321,-104],[348,58],[228,-232],[365,-23],[337,-69],[332,-128],[218,220],[108,209],[278,-232],[381,58],[283,-127],[190,-197],[370,58],[288,127],[283,151],[337,81],[392,69],[354,81],[272,127],[163,186],[65,254],[-32,244],[-87,231],[-98,232],[-87,231],[-71,209],[-16,231],[27,232],[130,220],[109,243],[44,231],[-55,255],[-32,232],[136,266],[152,173],[180,220],[190,186],[223,173],[109,255],[152,162],[174,151],[267,34],[174,186],[196,115],[228,70],[202,150],[157,186],[218,69],[163,-151],[-103,-196],[-283,-174],[-120,-127],[-206,92],[-229,-58],[-190,-139],[-202,-150],[-136,-174],[-38,-231],[17,-220],[130,-197],[-190,-139],[-261,-46],[-153,-197],[-163,-185],[-174,-255],[-44,-220],[98,-243],[147,-185],[229,-139],[212,-185],[114,-232],[60,-220],[82,-232],[130,-196],[82,-220],[38,-544],[81,-220],[22,-232],[87,-231],[-38,-313],[-152,-243],[-163,-197],[-370,-81],[-125,-208],[-169,-197],[-419,-220],[-370,-93],[-348,-127],[-376,-128],[-223,-243],[-446,-23],[-489,23],[-441,-46],[-468,0],[87,-232],[424,-104],[311,-162],[174,-208],[-310,-185],[-479,58],[-397,-151],[-17,-243],[-11,-232],[327,-196],[60,-220],[353,-220],[588,-93],[500,-162],[398,-185],[506,-186],[690,-92],[681,-162],[473,-174],[517,-197],[272,-278],[136,-220],[337,209],[457,173],[484,186],[577,150],[495,162],[691,12],[680,-81],[560,-139],[180,255],[386,173],[702,12],[550,127],[522,128],[577,81],[614,104],[430,150],[-196,209],[-119,208],[0,220],[-539,-23],[-571,-93],[-544,0],[-77,220],[39,440],[125,128],[397,138],[468,139],[337,174],[337,174],[251,231],[380,104],[376,81],[190,47],[430,23],[408,81],[343,116],[337,139],[305,139],[386,185],[245,197],[261,173],[82,232],[-294,139],[98,243],[185,185],[288,116],[305,139],[283,185],[217,232],[136,277],[202,163],[331,-35],[136,-197],[332,-23],[11,220],[142,231],[299,-58],[71,-220],[331,-34],[360,104],[348,69],[315,-34],[120,-243],[305,196],[283,105],[315,81],[310,81],[283,139],[310,92],[240,128],[168,208],[207,-151],[288,81],[202,-277],[157,-209],[316,116],[125,232],[283,162],[365,-35],[108,-220],[229,220],[299,69],[326,23],[294,-11],[310,-70],[300,-34],[130,-197],[180,-174],[304,104],[327,24],[315,0],[310,11],[278,81],[294,70],[245,162],[261,104],[283,58],[212,162],[152,324],[158,197],[288,-93],[109,-208],[239,-139],[289,46],[196,-208],[206,-151],[283,139],[98,255],[250,104],[289,197],[272,81],[326,116],[218,127],[228,139],[218,127],[261,-69],[250,208],[180,162],[261,-11],[229,139],[54,208],[234,162],[228,116],[278,93],[256,46],[244,-35],[262,-58],[223,-162],[27,-254],[245,-197],[168,-162],[332,-70],[185,-162],[229,-162],[266,-35],[223,116],[240,243],[261,-127],[272,-70],[261,-69],[272,-46],[277,0],[229,-614],[-11,-150],[-33,-267],[-266,-150],[-218,-220],[38,-232],[310,12],[-38,-232],[-141,-220],[-131,-243],[212,-185],[321,-58],[321,104],[153,232],[92,220],[153,185],[174,174],[70,208],[147,289],[174,58],[316,24],[277,69],[283,93],[136,231],[82,220],[190,220],[272,151],[234,115],[153,197],[157,104],[202,93],[277,-58],[250,58],[272,69],[305,-34],[201,162],[142,393],[103,-162],[131,-278],[234,-115],[266,-47],[267,70],[283,-46],[261,-12],[174,58],[234,-35],[212,-127],[250,81],[300,0],[255,81],[289,-81],[185,197],[141,196],[191,163],[348,439],[179,-81],[212,-162],[185,-208],[354,-359],[272,-12],[256,0],[299,70],[299,81],[229,162],[190,174],[310,23],[207,127],[218,-116],[141,-185],[196,-185],[305,23],[190,-150],[332,-151],[348,-58],[288,47],[218,185],[185,185],[250,46],[251,-81],[288,-58],[261,93],[250,0],[245,-58],[256,-58],[250,104],[299,93],[283,23],[316,0],[255,58],[251,46],[76,290],[11,243],[174,-162],[49,-266],[92,-244],[115,-196],[234,-105],[315,35],[365,12],[250,35],[364,0],[262,11],[364,-23],[310,-46],[196,-186],[-54,-220],[179,-173],[299,-139],[310,-151],[360,-104],[375,-92],[283,-93],[315,-12],[180,197],[245,-162],[212,-185],[245,-139],[337,-58],[321,-69],[136,-232],[316,-139],[212,-208],[310,-93],[321,12],[299,-35],[332,12],[332,-47],[310,-81],[288,-139],[289,-116],[195,-173],[-32,-232],[-147,-208],[-125,-266],[-98,-209],[-131,-243],[-364,-93],[-163,-208],[-360,-127],[-125,-232],[-190,-220],[-201,-185],[-115,-243],[-70,-220],[-28,-266],[6,-220],[158,-232],[60,-220],[130,-208],[517,-81],[109,-255],[-501,-93],[-424,-127],[-528,-23],[-234,-336],[-49,-278],[-119,-220],[-147,-220],[370,-196],[141,-244],[239,-219],[338,-197],[386,-186],[419,-185],[636,-185],[142,-289],[800,-128],[53,-45],[208,-175],[767,151],[636,-186],[479,-142],[-99999,0]],[[59092,71341],[19,3],[40,143],[200,-8],[253,176],[-188,-251],[21,-111]],[[59437,71293],[-30,21],[-53,-45],[-42,12],[-14,-22],[-5,59],[-20,37],[-54,6],[-75,-51],[-52,31]],[[59437,71293],[8,-48],[-285,-240],[-136,77],[-64,237],[132,22]],[[45272,63236],[13,274],[106,161],[91,308],[-18,200],[96,417],[155,376],[93,95],[74,344],[6,315],[100,365],[185,216],[177,603],[5,8],[139,227],[259,65],[218,404],[140,158],[232,493],[-70,735],[106,508],[37,312],[179,399],[278,270],[206,244],[186,612],[87,362],[205,-2],[167,-251],[264,41],[288,-131],[121,-6]],[[56944,63578],[0,2175],[0,2101],[-83,476],[71,365],[-43,253],[101,283]],[[56990,69231],[369,10],[268,-156],[275,-175],[129,-92],[214,188],[114,169],[245,49],[198,-75],[75,-293],[65,193],[222,-140],[217,-33],[137,149]],[[59700,68010],[-78,-238],[-60,-446],[-75,-308],[-65,-103],[-93,191],[-125,263],[-198,847],[-29,-53],[115,-624],[171,-594],[210,-920],[102,-321],[90,-334],[249,-654],[-55,-103],[9,-384],[323,-530],[49,-121]],[[53191,70158],[326,-204],[117,51],[232,-98],[368,-264],[130,-526],[250,-114],[391,-248],[296,-293],[136,153],[133,272],[-65,452],[87,288],[200,277],[192,80],[375,-121],[95,-264],[104,-2],[88,-101],[276,-70],[68,-195]],[[59804,53833],[-164,643],[-127,137],[-48,236],[-141,288],[-171,42],[95,337],[147,14],[42,181]],[[61764,57990],[-98,-261],[-94,-277],[22,-163],[4,-180],[155,-10],[67,42],[62,-106]],[[61882,57035],[-61,-209],[103,-325],[102,-285],[106,-210],[909,-702],[233,4]],[[61966,58083],[66,-183],[-9,-245],[-158,-142],[119,-161]],[[61984,57352],[-102,-317]],[[61984,57352],[91,-109],[54,-245],[125,-247],[138,-2],[262,151],[302,70],[245,184],[138,39],[99,108],[158,20]],[[58449,49909],[-166,-182],[-67,60]],[[58564,52653],[115,161],[176,-132],[224,138],[195,-1],[171,272]],[[55279,77084],[100,2],[-69,-260],[134,-227],[-41,-278],[-65,-27]],[[55338,76294],[-52,-53],[-90,-138],[-41,-325]],[[55719,75309],[35,-5],[13,121],[164,91],[62,23]],[[55993,75539],[95,35],[128,9]],[[55993,75539],[-9,44],[33,71],[31,144],[-39,-4],[-54,110],[-46,28],[-36,94],[-52,36],[-40,84],[-50,-33],[-38,-196],[-66,-43]],[[55627,75874],[22,51],[-106,123],[-91,63],[-40,82],[-74,101]],[[55380,75322],[-58,46],[-78,192],[-120,118]],[[55627,75874],[-52,-132]],[[32866,56937],[160,77],[58,-21],[-11,-440],[-232,-65],[-50,53],[81,163],[-6,233]]],"bbox":[-180,-85.60903777459771,180,83.64513000000001],"transform":{"scale":[0.0036000360003600037,0.0016925586033320105],"translate":[-180,-85.60903777459771]}} diff --git a/resources/css/app.css b/resources/css/app.css new file mode 100644 index 0000000000..90ee60b1fc --- /dev/null +++ b/resources/css/app.css @@ -0,0 +1,1162 @@ +/* GLOBAL */ +html, +body { + background: #f0f0f0; + overflow-x: hidden; +} +h1 { + font-weight: bold; + letter-spacing: -3px; +} +h3 { + font-size: 21px; + letter-spacing: -1px; +} +.h-dashboard { + text-transform: lowercase; +} +.page-header { + border-bottom: 1px solid rgba(0, 0, 0, 0.15); + margin: 25px 0 20px; + position: relative; +} +.page-header h1 { + margin: 0; +} +.pagination { + margin: 5px 0; +} +.clickable, +.expandable>td { + cursor: pointer; +} +.spinner { + color: #999; + left: 50%; + position: absolute; + top: 50%; +} +.powered { + bottom: 190px; + color: #9E9E9E; + font-size: smaller; + position: absolute; + right: 20px; + transform-origin: 100% 0; + transform: rotate(-90deg); +} +.powered a { + color: #636363; +} +.powered span { + color: #007bc3; +} +.dropdown-header { + color: #007bc3; + padding: 3px 25px; + text-transform: uppercase; +} +.gheader { + letter-spacing: -1px; + text-transform: uppercase; +} +h5.gheader { + letter-spacing: 0; +} +.panel-header h4.gheader { + margin-top: 20px; +} +.panel-header .gheader small { + font-size: 69%; +} + +/* NAVIGATION */ +nav { + -webkit-transition: left .2s; + background: #1C1C1C; + border-right: 3px solid #5bc0de; + height: 100%; + left: -236px; + overflow: hidden; + position: fixed; + top: 0; + transition: left .2s; + width: 300px; + z-index: 2; +} +nav .nav-list { + bottom: 0; + left: 0; + overflow-y: scroll; + position: absolute; + right: -17px; + top: 0; +} +nav header { + margin: 40px 20px 30px; +} +nav header a { + color: rgba(240,240,240,.7); + font-size: 2.7em; + font-weight: 300; + text-transform: uppercase; +} +nav header a:hover { + color: #eee; +} +nav.active { + display: block !important; + left: 0; + opacity: .97; +} +nav:hover ~ #content { + opacity: .3; +} +nav.active .nav-bars, +nav.active .nav-gears, +nav.active .nav-ws-status { + opacity: 0; +} +nav .nav-bars, +nav .nav-gears, +nav .nav-ws-status { + -webkit-transition: opacity .2s; + color: #9E9E9E; + cursor: pointer; + float: right; + font-size: 36px; + height: 32px; + left: 13px; + line-height: 32px; + position: fixed; + text-align: center; + top: 30px; + transition: opacity .2s; + width: 32px; +} +nav .nav-gears { + top: 100px; + opacity: 0.6; +} +nav .nav-ws-status, +.nav-ws-status.mini { + color: #6A6A6A; + cursor: help; + display: none; + font-size: 12px; +} +nav .nav-ws-status { + left: 25px; + top: 125px; +} +.nav-ws-status.mini { + top: 14px; + left: 50px; + position: absolute; +} +.nav-ws-status.connected { + color: #5DB56A; +} +nav li { + position: relative; +} +nav li .toggle-panel { + cursor: pointer; + opacity: 0; + padding: 9px 20px; + position: absolute; + right: 0; + top: 0; + transition: all .2s; + visibility: hidden; +} +nav li .toggle-panel i { + color: rgba(200,200,200,.5); + opacity: 0; +} +nav li .toggle-panel.active i { + color: #eee; + opacity: 1; +} +nav.active li .toggle-panel { + visibility: visible; + opacity: 1; +} +nav.active li:hover .toggle-panel i { + opacity: 1; +} +nav li a { + border-left: 3px solid transparent; + color: rgba(200,200,200,.5); + display: block; + font-size: smaller; + max-width: 235px; + opacity: 0; + overflow: hidden; + padding: 9px 20px; + text-overflow: ellipsis; + text-transform: uppercase; + transition: opacity .2s; + white-space: nowrap; +} +nav.active li a { + max-width: 90%; + opacity: 1; +} +nav li:hover a, +nav li.active a { + background: rgba(0,0,0,.1); + border-color: #5BC0DE; + color: #eee; +} +nav ul { + padding-left: 0; + list-style: none; +} +/* Navigation -- Icon */ +nav a, +nav a:hover { + text-decoration: none; +} +nav h3 { + color: #FFF !important; + font-size: medium; + font-weight: bold; + margin: 20px 25px 10px; + text-transform: uppercase; +} + +/* CONTAINER */ +@media screen and (max-width: 767px) { + .row-offcanvas { + -webkit-transition: all .25s ease-out; + -o-transition: all .25s ease-out; + position: relative; + transition: all .25s ease-out; + } + + .row-offcanvas-right { + right: 0; + } + + .row-offcanvas-left { + left: 0; + } + + .row-offcanvas-right + .sidebar-offcanvas { + right: -50%; + } + + .row-offcanvas-left + .sidebar-offcanvas { + left: -50%; + } + + .row-offcanvas-right.active { + right: 50%; + } + + .row-offcanvas-left.active { + left: 50%; + } + + .sidebar-offcanvas { + position: absolute; + top: 0; + width: 50%; + }; +} +@media (min-width: 768px) { + .container { + width: 750px; + }; +} +@media (max-width: 480px) { + .wrap-general h5, + .wrap-panel h5 { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + } + .wrap-general h5 { + width: 100% + } + .wrap-panel h5 { + width: 70% + } +} +.container-fluid { + margin-left: 75px; +} +@media (min-width: 1120px) { + .container { + width: 970px; + }; +} +@media (min-width: 1320px) { + .container { + width: 1170px; + }; +} +@media (max-width: 992px) { + .container-fluid { + margin-left: auto; + }; +} +@media (max-width: 768px) { + .container-fluid { + padding-left: 5px; + padding-right: 5px; + } + .page-header { + padding: 0 10px; + } +} + +/* PANEL STYLES */ +.wrap-panel .panel-header { + position: relative; +} +div.wrap-panel > div { + background: #FFF; + margin-top: 10px; + padding: 0 10px; + border-top: 1px solid rgba(0, 0, 0, 0.15); +} + +/* PANEL TABLES */ +.wrap-panel table.table-borderless tbody tr td, +.wrap-panel table.table-borderless tbody tr th, +.wrap-panel table.table-borderless thead tr th { + border: none; +} +.wrap-panel table thead tr th { + text-align: right; + border-bottom-width: 1px; +} +.wrap-panel table .string, +.wrap-panel table .date { + text-align: left; +} +.wrap-panel table .percent { + color: #898989; +} +.wrap-panel table td, +.wrap-panel table th { + white-space: nowrap; + overflow: hidden; +} +.wrap-panel table th.sortable { + cursor: pointer; +} +.wrap-panel table.table-borderless thead>tr.thead-cols th { + font-size: 78%; + text-transform: uppercase; +} +.wrap-panel table .cell-hl { + padding: 2px 3px; + color: #FFF; + border-radius: 5px; + display: block; + text-align: center; +} +.wrap-panel table .span-hl { + padding: 2px 3px; + border-radius: 3px; + color: #000; +} +.wrap-panel table .span-hl.g5 { + background: #e9ecef; +} +.wrap-panel table .cell-hl.b1 { + background: #7F669D; +} +.wrap-panel table .cell-hl.b2 { + background: #BA94D1; +} +.wrap-panel table .cell-hl.b3 { + background: #DEBACE; +} +.wrap-panel table .cell-hl.d1 { + background: #9d9d9d38; +} +.wrap-panel table .cell-hl.d2 { + background: #9d9d9d61; +} +.wrap-panel table .cell-hl.d3 { + background: #9d9d9d9c; +} +.wrap-panel table .cell-hl.d4 { + background: #9d9d9d; +} +.wrap-panel table .span-hl.lgrn { + background: #e6f4ea; + color: #137333; +} +.wrap-panel table .span-hl.lyel { + background: #fff3cd; + color: #d38a10; +} +.wrap-panel table .span-hl.lred { + background: #fce8e6; + color: #c5221f; +} +.wrap-panel table .span-hl.lgry { + background: #898989; + color: #ffffff; +} +.wrap-panel table .span-hl.lblu { + background: #cfe2ff; + color: #052c65; +} +.wrap-panel table .span-hl.lprp { + background: #cdc7ff; + color: #343150; +} + +/* thead meta */ +.wrap-panel table thead>tr.thead-min th.meta-label, +.wrap-panel table thead>tr.thead-avg th.meta-label, +.wrap-panel table tfoot>tr.tfoot-totals th.meta-label, +.wrap-panel table thead>tr.thead-max th.meta-label { + font-weight: bold; + text-transform: uppercase; +} +.wrap-panel table .thead-min, +.wrap-panel table .thead-avg, +.wrap-panel table .thead-max { + background: #F8F8F8; +} +.wrap-panel table .thead-avg { + border-bottom: 2px solid #000; +} +.wrap-panel table thead>tr.thead-min th, +.wrap-panel table thead>tr.thead-avg th, +.wrap-panel table thead>tr.thead-max th { + font-size: smaller; + font-weight: normal; + padding: 3px 8px 3px 8px; + text-transform: inherit; +} +.wrap-panel table .thead-min th, +.wrap-panel table .thead-avg th, +.wrap-panel table .thead-max th { + padding: 3px; +} +.wrap-panel table tfoot>tr>th { + border-top: 1px dotted #000; + padding: 8px; +} +/* thead data */ +.wrap-panel table tbody.tbody-data tr td { + border-right: 1px solid #F1F1F1; + font-size: smaller; +} +.wrap-panel table tbody.tbody-data td:last-child { + border-right: none; +} +.wrap-panel table tbody.tbody-data td.row-idx { + font-weight: 700; +} +.wrap-panel table>thead>tr.thead-cols { + border-bottom: 2px solid #222; +} +.wrap-panel table tbody.tbody-data tr.shaded { + background-color: #F7F7F7; +} +.wrap-panel table tbody.tbody-data tr. { + background-color: #F7F7F7; +} +.wrap-panel table tbody.tbody-data tr.child td:nth-child(1), +.wrap-panel table tbody.tbody-data tr.child td:nth-child(2) { + border-right: none; +} +.wrap-panel table.table-hover>tbody>tr:hover { + background-color: #EEE; +} +.wrap-panel .row:nth-child(2):not(.table-wrapper)>.col-md-12 { + padding: 0; +} + +/* GENERAL */ +.wrap-general { + position: relative; +} +.report-title { + background: #FFF; + border-radius: 4px; + bottom: -10px; + color: #9E9E9E; + font-size: small; + padding: 0 10px; + position: absolute; + right: 0; + z-index: 1; +} +.panel-plot-wrap { + position: absolute; + right: 0; + top: 18px; +} +.col-title { + font-size: 85%; + overflow: hidden; + text-overflow: ellipsis; + text-shadow: 1px 1px 0 #FFF; + white-space: nowrap; + width: 100%; +} +.grid-module { + background: #FFF; + color: rgb(36, 36, 36); + font-weight: normal; + margin-top: 5px; + padding: 7px; +} +.grid-module h3 { + font-size: 25px; + margin: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + width: 100%; +} +.grid-module.black { + border-top: 4px solid #0F1214; +} +.grid-module.gray { + border-top: 4px solid #9E9E9E; +} +.grid-module.red { + border-top: 4px solid #FF303E; +} +.grid-module.blue{ + border-top: 4px solid #00D4E1; +} +.grid-module.green { + border-top: 4px solid #229f75; +} +@media (max-width: 767px) { + .panel-plot-wrap { + top: 10px; + } + .powered { + bottom: 10px; + left: 25px; + transform: initial; + } +} + +/* CHARTS */ +.chart-wrap { + margin-bottom: 15px; + position: relative; +} +svg { + background-color: transparent; + display: block; +} +.axis path { + fill: transparent; + stroke: black; + shape-rendering: crispEdges; + stroke-width: 1; +} +.grid.y .tick line, +.grid.x .tick line { + shape-rendering: crispEdges; + stroke: #999; + stroke-dasharray: 3 3; + stroke-width: 1; +} +.axis.x .tick line, +.axis.y0 .tick line, +.axis.y1 .tick line, +.grid.y .tick:first-child line { + stroke: black; + stroke-width: 1; + shape-rendering: crispEdges; +} +.bars rect.bar { + shape-rendering: crispEdges; +} +.rects rect { + fill: transparent; +} +.area { + opacity: 0.2; +} +.points { + stroke: transparent; +} +line.indicator { + fill: transparent; + pointer-events: none; + shape-rendering: crispEdges; + stroke: #999; + stroke-width: 1; + display: none; +} +.area0, +.bars.y0 .bar, +.points.y0, +rect.legend.y0 { + fill: #447FB3; +} +.area1, +.bars.y1 .bar, +.points.y1, +rect.legend.y1 { + fill: #FF6854; +} +.line0, +.line1 { + fill: transparent; + stroke-width: 1; +} +.line0 { + stroke: #007BC3; +} +.line1 { + stroke: #FF303E; +} +.axis text, +.axis-label, +text.legend { + font: 10px sans-serif; +} +.axis-label.y0, +.axis-label.y1 { + text-anchor: end; +} +rect.legend { + height: 10px; + width: 10px; +} +.legend { + cursor: pointer; +} +.wrap-text text { + text-anchor: start!important; +} + +/* CHART TOOLTIP */ +.chart-tooltip-wrap { + left: 0; + pointer-events: none; + position: absolute; + top: 10px; + z-index: 10; +} +.chart-tooltip { + -moz-box-shadow: 7px 7px 12px -9px #777777; + -webkit-box-shadow: 7px 7px 12px -9px #777777; + background-color: #fff; + border-collapse: collapse; + border-spacing: 0; + box-shadow: 7px 7px 12px -9px #777777; + empty-cells: show; + opacity: 0.9; +} +.chart-tooltip tr { + border: 1px solid #CCC; +} +.chart-tooltip th { + background-color: #aaa; + color: #FFF; + font-size: 14px; + max-width: 380px; + overflow: hidden; + padding: 2px 5px; + text-align: left; + text-overflow: ellipsis; + white-space: nowrap; +} +.chart-tooltip td { + border-left: 1px dotted #999; + font-size: 13px; + padding: 3px 6px; +} +.chart-tooltip td > span { + display: inline-block; + height: 10px; + margin-right: 6px; + width: 10px; +} +.chart-tooltip td.value { + text-align: right; +} +.chart-tooltip .blue { + background-color: #007BC3; +} +.chart-tooltip .red { + background-color: #FF303E; +} + +/* DARK THEME */ +.dark h1 { + color: rgba(255, 255, 255, 0.6); +} +.dark h3, +.dark h4, +.dark h5 { + color: rgba(255,255,255,0.4); +} +.dark .table-responsive { + border: none; +} +.dark .wrap-panel > div > table { + color: #D2D2D2; +} +.dark .wrap-panel table tbody.tbody-data tr td { + border-right: none; +} +.dark .wrap-panel table.table-hover>tbody.tbody-data>tr:hover { + background-color: rgba(255, 255, 255, 0.08) !important; +} +.dark .col-title { + color: #9e9e9e; + text-shadow:none; +} +.dark .grid-module h3 { + color: #FFF; +} +.dark .dropdown-menu>li>a { + color: #FFF; +} +.dark div.wrap-panel > div { + color: #EEE; + margin-top: 10px; + padding: 0 10px; + border-top: 1px solid rgba(255, 255, 255, 0.15); +} +.dark .wrap-panel table .cell-hl.d1 { + background: #161616; +} +.dark .wrap-panel table .cell-hl.d2 { + background: #3c3c3c; +} +.dark .wrap-panel table .cell-hl.d3 { + background: #5a5a5a; +} +.dark .wrap-panel table .cell-hl.d4 { + background: #7e7e7e; +} + +/* DARK BLUE THEME */ +html.dark.blue, +.dark.blue body { + background: #252B30; +} +.dark.blue .container { + background: #252B30; +} +.dark.blue .page-header { + border-bottom: 1px solid #3B444C; +} +.dark.blue .label-info { + background-color: #252B30; +} +.dark.blue nav { + border-right: 1px solid #181B1F; + background: #1F2328; +} +.dark.blue div.wrap-panel > div { + background: #1F2328; +} +.dark.blue .wrap-panel table tfoot>tr>th { + border-top: 1px dotted #999; +} +.dark.blue .wrap-panel table .thead-min, +.dark.blue .wrap-panel table .thead-avg, +.dark.blue .wrap-panel table .thead-max { + background: #1f2328; +} +.dark.blue .wrap-panel table .thead-avg { + border-bottom: 2px solid #999; +} +.dark.blue .wrap-panel table>thead>tr.thead-cols { + border-bottom: 2px solid #999; +} +.dark.blue .wrap-panel table tbody.tbody-data tr.shaded { + background-color: #181B1F; +} +.dark.blue .gray { + border-top: 4px solid #3B444C; +} +.dark.blue .grid-module { + background: #1F2328; +} +.dark.blue .btn-default { + color: #9E9E9E; + background-color: #1F2328; + border-color: #3B444C; +} +.dark.blue .btn-default:active, +.dark.blue .btn-default:hover, +.dark.blue .btn-default.active, +.dark.blue .open>.dropdown-toggle.btn-default { + color: #3B444C; + background-color: #1F2328; + border-color: #0F1214; +} +.dark.blue .pagination>.disabled>a, +.dark.blue .pagination>.disabled>a:hover, +.dark.blue .pagination>.disabled>a:focus { + color: #777; +} +.dark.blue .pagination>li>a { + background-color: #1F2328; + border: 1px solid #3B444C; +} +.dark.blue .pagination>li>a:hover, +.dark.blue .pagination>li>a:active, +.dark.blue .pagination>li>a:focus { + color: #0370B0; + background-color: #1F2328; + border-color: #3B444C; +} +.dark.blue .dropdown-menu>li>a:hover, +.dark.blue .dropdown-menu>li>a:focus { + color: #FFF; + background-color: #3B444C; +} +.dark.blue .dropdown-menu { + background-color: #252B30; +} +.dark.blue::-webkit-scrollbar-track, +.dark.blue .table-responsive::-webkit-scrollbar-track { + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); + background-color: #9E9E9E; +} +.dark.blue::-webkit-scrollbar, +.dark.blue .table-responsive::-webkit-scrollbar { + width: 10px; + height: 10px; + background-color: #9E9E9E; +} +.dark.blue::-webkit-scrollbar-thumb, +.dark.blue .table-responsive::-webkit-scrollbar-thumb { + background-color: #3B444C; +} +.dark.blue .chart-tooltip { + background-color: #252B30; +} +.dark.blue .report-title { + background: #1F2328; +} + +/* DARK GREY THEME */ +html.dark.gray, +.dark.gray body { + background: #212121; +} +.dark.gray .container { + background: #212121; +} +.dark.gray .page-header { + border-bottom: 1px solid #303030; +} +.dark.gray .label-info { + background-color: #303030; +} +.dark.gray nav { + border-right: 1px solid #363737; + background: #1C1C1C; +} +.dark.gray div.wrap-panel > div { + background: #1C1C1C; +} +.dark.gray .wrap-panel table tfoot>tr>th { + border-top: 1px dotted #999; +} +.dark.gray .wrap-panel table .thead-min, +.dark.gray .wrap-panel table .thead-avg, +.dark.gray .wrap-panel table .thead-max { + background: #1c1c1c; +} +.dark.gray .wrap-panel table .thead-avg { + border-bottom: 2px solid #999; +} +.dark.gray .wrap-panel table>thead>tr.thead-cols { + border-bottom: 2px solid #999; +} +.dark.gray .wrap-panel table tbody.tbody-data tr.shaded { + background-color: rgba(48, 48, 48, 0.48); +} +.dark.gray .gray { + border-top: 4px solid #303030; +} +.dark.gray .grid-module { + background: #1C1C1C; +} +.dark.gray .btn-default { + color: #9E9E9E; + background-color: #212121; + border-color: #303030; +} +.dark.gray .btn-default:active, +.dark.gray .btn-default:hover, +.dark.gray .btn-default.active, +.dark.gray .open>.dropdown-toggle.btn-default { + color: #363737; + background-color: #1C1C1C; + border-color: #0F1214; +} +.dark.gray .pagination>.disabled>a, +.dark.gray .pagination>.disabled>a:hover, +.dark.gray .pagination>.disabled>a:focus { + color: #777; +} +.dark.gray .pagination>li>a { + background-color: #212121; + border: 1px solid #303030; +} +.dark.gray .pagination>li>a:hover, +.dark.gray .pagination>li>a:active, +.dark.gray .pagination>li>a:focus { + color: #0370B0; + background-color: #212121; + border-color: #303030; +} +.dark.gray .dropdown-menu>li>a { + color: #FFF; +} +.dark.gray .dropdown-menu>li>a:hover, +.dark.gray .dropdown-menu>li>a:focus { + color: #FFF; + background-color: #303030; +} +.dark.gray .dropdown-menu { + background-color: #212121; +} +.dark.gray::-webkit-scrollbar-track, +.dark.gray .table-responsive::-webkit-scrollbar-track { + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); + background-color: #9E9E9E; +} +.dark.gray::-webkit-scrollbar, +.dark.gray .table-responsive::-webkit-scrollbar { + width: 10px; + height: 10px; + background-color: #9E9E9E; +} +.dark.gray::-webkit-scrollbar-thumb, +.dark.gray .table-responsive::-webkit-scrollbar-thumb { + background-color: #303030; +} +.dark.gray .chart-tooltip { + background-color: #303030; +} +.dark.gray .report-title { + background: #303030; +} + +/* DARK CHARTS */ +.dark .area { + opacity: 0.1; +} +.dark .line0, +.dark .line1 { + stroke-width: 2; +} +.dark .area0, +.dark .bars.y0 .bar, +.dark rect.legend.y0 { + fill: #007BC3; +} +.dark .area1, +.dark .bars.y1 .bar, +.dark .points.y1, +.dark rect.legend.y1 { + fill: #FF303E; +} +.dark .points.y0 { + fill: #00D4E1; +} +.dark .line0 { + stroke: #007BC3; +} +.dark .line1 { + stroke: #FF303E; +} +.dark .grid.y .tick line, +.dark .grid.x .tick line { + stroke: #44474B; + stroke-dasharray: 1 1; +} +.dark .axis text, +.dark .axis-label, +.dark text.legend { + fill: #9E9E9E; +} +.dark .axis path { + stroke: #999999; +} +.dark .axis.x .tick line, +.dark .axis.y0 .tick line, +.dark .axis.y1 .tick line, +.dark .grid.y .tick:first-child line { + stroke: #3B444C; +} +.dark .chart-tooltip th { + background-color: #1c1c1c; +} +.dark .chart-tooltip tr { + border: 1px solid #363737; +} + +/* DARK PURPLE THEME */ +html.dark.purple, +.dark.purple body { + background: #1e1e2f; +} +.dark.purple .container { + background: #1e1e2f; +} +.dark.purple .page-header { + border-bottom: 1px solid #2b3553; +} +.dark.purple .label-info { + background-color: #181823; +} +.dark.purple nav { + border-right: 1px solid #e14eca; + background: #181823; +} +.dark.purple div.wrap-panel > div { + background: #27293d; + border-top: 1px solid #2b3553; +} +.dark.purple .wrap-panel table tbody.tbody-data tr.shaded { + background-color: #1e1e2f; +} +.dark.purple .wrap-panel table tfoot>tr>th { + border-top: 1px dotted #999; +} +.dark.purple .wrap-panel table .thead-min, +.dark.purple .wrap-panel table .thead-avg, +.dark.purple .wrap-panel table .thead-max { + background: #27293d; +} +.dark.purple .wrap-panel table .thead-avg { + border-bottom: 2px solid #999; +} +.dark.purple .wrap-panel table>thead>tr.thead-cols { + border-bottom: 2px solid #999; +} +.dark.purple .gray { + border-top: 4px solid #2b3553; +} +.dark.purple .red { + border-top: 4px solid #fd5d93; +} +.dark.purple .green { + border-top: 4px solid #00f2c3; +} +.dark.purple .blue { + border-top: 4px solid #1f8ef1; +} +.dark.purple h3, .dark.purple h4, .dark.purple h5 { + color: #9a9a9a; +} +.dark.purple .grid-module { + background: #27293d; +} +.dark.purple .grid-module h3 { + color: #FFF; +} +.dark.purple .btn-default { + color: #9E9E9E; + background-color: #1e1e2f; + border-color: #2b3553; +} +.dark.purple .btn-default:active, +.dark.purple .btn-default:hover, +.dark.purple .btn-default.active, +.dark.purple .open>.dropdown-toggle.btn-default { + color: #59595f; + background-color: #1e1e2f; + border-color: #2b3553; +} +.dark.purple .pagination>.disabled>a, +.dark.purple .pagination>.disabled>a:hover, +.dark.purple .pagination>.disabled>a:focus { + color: #777; +} +.dark.purple .pagination>li>a { + background-color: #1e1e2f; + border: 1px solid #3B444C; +} +.dark.purple .pagination>li>a:hover, +.dark.purple .pagination>li>a:active, +.dark.purple .pagination>li>a:focus { + color: #0370B0; + background-color: #181823; +} +.dark.purple .dropdown-menu>li>a:hover, +.dark.purple .dropdown-menu>li>a:focus { + color: #FFF; + background-color: #181823; +} +.dark.purple .dropdown-menu { + background-color: #1e1e2f; +} +.dark.purple::-webkit-scrollbar-track, +.dark.purple .table-responsive::-webkit-scrollbar-track { + -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); + background-color: #9E9E9E; +} +.dark.purple::-webkit-scrollbar, +.dark.purple .table-responsive::-webkit-scrollbar { + width: 10px; + height: 10px; + background-color: #9E9E9E; +} +.dark.purple::-webkit-scrollbar-thumb, +.dark.purple .table-responsive::-webkit-scrollbar-thumb { + background-color: #1e1e2f; +} +.dark.purple .chart-tooltip { + background-color: #181823; +} +.dark.purple .report-title { + background: #181823; +} +.dark.purple .area0, +.dark.purple .bars.y0 .bar, +.dark.purple rect.legend.y0 { + fill: #007BC3; +} +.dark.purple .area1, +.dark.purple .bars.y1 .bar, +.dark.purple .points.y1, +.dark.purple rect.legend.y1 { + fill: #d048b6; +} +.dark.purple .points.y0 { + fill: #00D4E1; +} +.dark.purple .line0 { + stroke: #007BC3; +} +.dark.purple .line1 { + stroke: #d048b6; +} +.country { + fill: #ccc; + stroke: #fff; + stroke-width: 0.5px; +} +.country:hover { + fill: #b3b3b3; +} +.dark .country { + fill: #ccc; + stroke: #222; + stroke-width: 0.5px; +} +.dark .legend-svg text { + fill: #FFF; +} diff --git a/resources/css/bootstrap.min.css b/resources/css/bootstrap.min.css new file mode 100644 index 0000000000..ed3905e0e0 --- /dev/null +++ b/resources/css/bootstrap.min.css @@ -0,0 +1,6 @@ +/*! + * Bootstrap v3.3.7 (http://getbootstrap.com) + * Copyright 2011-2016 Twitter, Inc. + * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE) + *//*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */html{font-family:sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:700}dfn{font-style:italic}h1{margin:.67em 0;font-size:2em}mark{color:#000;background:#ff0}small{font-size:80%}sub,sup{position:relative;font-size:75%;line-height:0;vertical-align:baseline}sup{top:-.5em}sub{bottom:-.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{height:0;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{margin:0;font:inherit;color:inherit}button{overflow:visible}button,select{text-transform:none}button,html input[type=button],input[type=reset],input[type=submit]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{padding:0;border:0}input{line-height:normal}input[type=checkbox],input[type=radio]{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:0}input[type=number]::-webkit-inner-spin-button,input[type=number]::-webkit-outer-spin-button{height:auto}input[type=search]{-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;-webkit-appearance:textfield}input[type=search]::-webkit-search-cancel-button,input[type=search]::-webkit-search-decoration{-webkit-appearance:none}fieldset{padding:.35em .625em .75em;margin:0 2px;border:1px solid silver}legend{padding:0;border:0}textarea{overflow:auto}optgroup{font-weight:700}table{border-spacing:0;border-collapse:collapse}td,th{padding:0}/*! Source: https://github.com/h5bp/html5-boilerplate/blob/master/src/css/main.css */@media print{*,:after,:before{color:#000!important;text-shadow:none!important;background:0 0!important;-webkit-box-shadow:none!important;box-shadow:none!important}a,a:visited{text-decoration:underline}a[href]:after{content:" (" attr(href) ")"}abbr[title]:after{content:" (" attr(title) ")"}a[href^="javascript:"]:after,a[href^="#"]:after{content:""}blockquote,pre{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}img,tr{page-break-inside:avoid}img{max-width:100%!important}h2,h3,p{orphans:3;widows:3}h2,h3{page-break-after:avoid}.navbar{display:none}.btn>.caret,.dropup>.btn>.caret{border-top-color:#000!important}.label{border:1px solid #000}.table{border-collapse:collapse!important}.table td,.table th{background-color:#fff!important}.table-bordered td,.table-bordered th{border:1px solid #ddd!important}}@font-face{font-family:'Glyphicons Halflings';src:url(../fonts/glyphicons-halflings-regular.eot);src:url(../fonts/glyphicons-halflings-regular.eot?#iefix) format('embedded-opentype'),url(../fonts/glyphicons-halflings-regular.woff2) format('woff2'),url(../fonts/glyphicons-halflings-regular.woff) format('woff'),url(../fonts/glyphicons-halflings-regular.ttf) format('truetype'),url(../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular) format('svg')}.glyphicon{position:relative;top:1px;display:inline-block;font-family:'Glyphicons Halflings';font-style:normal;font-weight:400;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.glyphicon-asterisk:before{content:"\002a"}.glyphicon-plus:before{content:"\002b"}.glyphicon-eur:before,.glyphicon-euro:before{content:"\20ac"}.glyphicon-minus:before{content:"\2212"}.glyphicon-cloud:before{content:"\2601"}.glyphicon-envelope:before{content:"\2709"}.glyphicon-pencil:before{content:"\270f"}.glyphicon-glass:before{content:"\e001"}.glyphicon-music:before{content:"\e002"}.glyphicon-search:before{content:"\e003"}.glyphicon-heart:before{content:"\e005"}.glyphicon-star:before{content:"\e006"}.glyphicon-star-empty:before{content:"\e007"}.glyphicon-user:before{content:"\e008"}.glyphicon-film:before{content:"\e009"}.glyphicon-th-large:before{content:"\e010"}.glyphicon-th:before{content:"\e011"}.glyphicon-th-list:before{content:"\e012"}.glyphicon-ok:before{content:"\e013"}.glyphicon-remove:before{content:"\e014"}.glyphicon-zoom-in:before{content:"\e015"}.glyphicon-zoom-out:before{content:"\e016"}.glyphicon-off:before{content:"\e017"}.glyphicon-signal:before{content:"\e018"}.glyphicon-cog:before{content:"\e019"}.glyphicon-trash:before{content:"\e020"}.glyphicon-home:before{content:"\e021"}.glyphicon-file:before{content:"\e022"}.glyphicon-time:before{content:"\e023"}.glyphicon-road:before{content:"\e024"}.glyphicon-download-alt:before{content:"\e025"}.glyphicon-download:before{content:"\e026"}.glyphicon-upload:before{content:"\e027"}.glyphicon-inbox:before{content:"\e028"}.glyphicon-play-circle:before{content:"\e029"}.glyphicon-repeat:before{content:"\e030"}.glyphicon-refresh:before{content:"\e031"}.glyphicon-list-alt:before{content:"\e032"}.glyphicon-lock:before{content:"\e033"}.glyphicon-flag:before{content:"\e034"}.glyphicon-headphones:before{content:"\e035"}.glyphicon-volume-off:before{content:"\e036"}.glyphicon-volume-down:before{content:"\e037"}.glyphicon-volume-up:before{content:"\e038"}.glyphicon-qrcode:before{content:"\e039"}.glyphicon-barcode:before{content:"\e040"}.glyphicon-tag:before{content:"\e041"}.glyphicon-tags:before{content:"\e042"}.glyphicon-book:before{content:"\e043"}.glyphicon-bookmark:before{content:"\e044"}.glyphicon-print:before{content:"\e045"}.glyphicon-camera:before{content:"\e046"}.glyphicon-font:before{content:"\e047"}.glyphicon-bold:before{content:"\e048"}.glyphicon-italic:before{content:"\e049"}.glyphicon-text-height:before{content:"\e050"}.glyphicon-text-width:before{content:"\e051"}.glyphicon-align-left:before{content:"\e052"}.glyphicon-align-center:before{content:"\e053"}.glyphicon-align-right:before{content:"\e054"}.glyphicon-align-justify:before{content:"\e055"}.glyphicon-list:before{content:"\e056"}.glyphicon-indent-left:before{content:"\e057"}.glyphicon-indent-right:before{content:"\e058"}.glyphicon-facetime-video:before{content:"\e059"}.glyphicon-picture:before{content:"\e060"}.glyphicon-map-marker:before{content:"\e062"}.glyphicon-adjust:before{content:"\e063"}.glyphicon-tint:before{content:"\e064"}.glyphicon-edit:before{content:"\e065"}.glyphicon-share:before{content:"\e066"}.glyphicon-check:before{content:"\e067"}.glyphicon-move:before{content:"\e068"}.glyphicon-step-backward:before{content:"\e069"}.glyphicon-fast-backward:before{content:"\e070"}.glyphicon-backward:before{content:"\e071"}.glyphicon-play:before{content:"\e072"}.glyphicon-pause:before{content:"\e073"}.glyphicon-stop:before{content:"\e074"}.glyphicon-forward:before{content:"\e075"}.glyphicon-fast-forward:before{content:"\e076"}.glyphicon-step-forward:before{content:"\e077"}.glyphicon-eject:before{content:"\e078"}.glyphicon-chevron-left:before{content:"\e079"}.glyphicon-chevron-right:before{content:"\e080"}.glyphicon-plus-sign:before{content:"\e081"}.glyphicon-minus-sign:before{content:"\e082"}.glyphicon-remove-sign:before{content:"\e083"}.glyphicon-ok-sign:before{content:"\e084"}.glyphicon-question-sign:before{content:"\e085"}.glyphicon-info-sign:before{content:"\e086"}.glyphicon-screenshot:before{content:"\e087"}.glyphicon-remove-circle:before{content:"\e088"}.glyphicon-ok-circle:before{content:"\e089"}.glyphicon-ban-circle:before{content:"\e090"}.glyphicon-arrow-left:before{content:"\e091"}.glyphicon-arrow-right:before{content:"\e092"}.glyphicon-arrow-up:before{content:"\e093"}.glyphicon-arrow-down:before{content:"\e094"}.glyphicon-share-alt:before{content:"\e095"}.glyphicon-resize-full:before{content:"\e096"}.glyphicon-resize-small:before{content:"\e097"}.glyphicon-exclamation-sign:before{content:"\e101"}.glyphicon-gift:before{content:"\e102"}.glyphicon-leaf:before{content:"\e103"}.glyphicon-fire:before{content:"\e104"}.glyphicon-eye-open:before{content:"\e105"}.glyphicon-eye-close:before{content:"\e106"}.glyphicon-warning-sign:before{content:"\e107"}.glyphicon-plane:before{content:"\e108"}.glyphicon-calendar:before{content:"\e109"}.glyphicon-random:before{content:"\e110"}.glyphicon-comment:before{content:"\e111"}.glyphicon-magnet:before{content:"\e112"}.glyphicon-chevron-up:before{content:"\e113"}.glyphicon-chevron-down:before{content:"\e114"}.glyphicon-retweet:before{content:"\e115"}.glyphicon-shopping-cart:before{content:"\e116"}.glyphicon-folder-close:before{content:"\e117"}.glyphicon-folder-open:before{content:"\e118"}.glyphicon-resize-vertical:before{content:"\e119"}.glyphicon-resize-horizontal:before{content:"\e120"}.glyphicon-hdd:before{content:"\e121"}.glyphicon-bullhorn:before{content:"\e122"}.glyphicon-bell:before{content:"\e123"}.glyphicon-certificate:before{content:"\e124"}.glyphicon-thumbs-up:before{content:"\e125"}.glyphicon-thumbs-down:before{content:"\e126"}.glyphicon-hand-right:before{content:"\e127"}.glyphicon-hand-left:before{content:"\e128"}.glyphicon-hand-up:before{content:"\e129"}.glyphicon-hand-down:before{content:"\e130"}.glyphicon-circle-arrow-right:before{content:"\e131"}.glyphicon-circle-arrow-left:before{content:"\e132"}.glyphicon-circle-arrow-up:before{content:"\e133"}.glyphicon-circle-arrow-down:before{content:"\e134"}.glyphicon-globe:before{content:"\e135"}.glyphicon-wrench:before{content:"\e136"}.glyphicon-tasks:before{content:"\e137"}.glyphicon-filter:before{content:"\e138"}.glyphicon-briefcase:before{content:"\e139"}.glyphicon-fullscreen:before{content:"\e140"}.glyphicon-dashboard:before{content:"\e141"}.glyphicon-paperclip:before{content:"\e142"}.glyphicon-heart-empty:before{content:"\e143"}.glyphicon-link:before{content:"\e144"}.glyphicon-phone:before{content:"\e145"}.glyphicon-pushpin:before{content:"\e146"}.glyphicon-usd:before{content:"\e148"}.glyphicon-gbp:before{content:"\e149"}.glyphicon-sort:before{content:"\e150"}.glyphicon-sort-by-alphabet:before{content:"\e151"}.glyphicon-sort-by-alphabet-alt:before{content:"\e152"}.glyphicon-sort-by-order:before{content:"\e153"}.glyphicon-sort-by-order-alt:before{content:"\e154"}.glyphicon-sort-by-attributes:before{content:"\e155"}.glyphicon-sort-by-attributes-alt:before{content:"\e156"}.glyphicon-unchecked:before{content:"\e157"}.glyphicon-expand:before{content:"\e158"}.glyphicon-collapse-down:before{content:"\e159"}.glyphicon-collapse-up:before{content:"\e160"}.glyphicon-log-in:before{content:"\e161"}.glyphicon-flash:before{content:"\e162"}.glyphicon-log-out:before{content:"\e163"}.glyphicon-new-window:before{content:"\e164"}.glyphicon-record:before{content:"\e165"}.glyphicon-save:before{content:"\e166"}.glyphicon-open:before{content:"\e167"}.glyphicon-saved:before{content:"\e168"}.glyphicon-import:before{content:"\e169"}.glyphicon-export:before{content:"\e170"}.glyphicon-send:before{content:"\e171"}.glyphicon-floppy-disk:before{content:"\e172"}.glyphicon-floppy-saved:before{content:"\e173"}.glyphicon-floppy-remove:before{content:"\e174"}.glyphicon-floppy-save:before{content:"\e175"}.glyphicon-floppy-open:before{content:"\e176"}.glyphicon-credit-card:before{content:"\e177"}.glyphicon-transfer:before{content:"\e178"}.glyphicon-cutlery:before{content:"\e179"}.glyphicon-header:before{content:"\e180"}.glyphicon-compressed:before{content:"\e181"}.glyphicon-earphone:before{content:"\e182"}.glyphicon-phone-alt:before{content:"\e183"}.glyphicon-tower:before{content:"\e184"}.glyphicon-stats:before{content:"\e185"}.glyphicon-sd-video:before{content:"\e186"}.glyphicon-hd-video:before{content:"\e187"}.glyphicon-subtitles:before{content:"\e188"}.glyphicon-sound-stereo:before{content:"\e189"}.glyphicon-sound-dolby:before{content:"\e190"}.glyphicon-sound-5-1:before{content:"\e191"}.glyphicon-sound-6-1:before{content:"\e192"}.glyphicon-sound-7-1:before{content:"\e193"}.glyphicon-copyright-mark:before{content:"\e194"}.glyphicon-registration-mark:before{content:"\e195"}.glyphicon-cloud-download:before{content:"\e197"}.glyphicon-cloud-upload:before{content:"\e198"}.glyphicon-tree-conifer:before{content:"\e199"}.glyphicon-tree-deciduous:before{content:"\e200"}.glyphicon-cd:before{content:"\e201"}.glyphicon-save-file:before{content:"\e202"}.glyphicon-open-file:before{content:"\e203"}.glyphicon-level-up:before{content:"\e204"}.glyphicon-copy:before{content:"\e205"}.glyphicon-paste:before{content:"\e206"}.glyphicon-alert:before{content:"\e209"}.glyphicon-equalizer:before{content:"\e210"}.glyphicon-king:before{content:"\e211"}.glyphicon-queen:before{content:"\e212"}.glyphicon-pawn:before{content:"\e213"}.glyphicon-bishop:before{content:"\e214"}.glyphicon-knight:before{content:"\e215"}.glyphicon-baby-formula:before{content:"\e216"}.glyphicon-tent:before{content:"\26fa"}.glyphicon-blackboard:before{content:"\e218"}.glyphicon-bed:before{content:"\e219"}.glyphicon-apple:before{content:"\f8ff"}.glyphicon-erase:before{content:"\e221"}.glyphicon-hourglass:before{content:"\231b"}.glyphicon-lamp:before{content:"\e223"}.glyphicon-duplicate:before{content:"\e224"}.glyphicon-piggy-bank:before{content:"\e225"}.glyphicon-scissors:before{content:"\e226"}.glyphicon-bitcoin:before{content:"\e227"}.glyphicon-btc:before{content:"\e227"}.glyphicon-xbt:before{content:"\e227"}.glyphicon-yen:before{content:"\00a5"}.glyphicon-jpy:before{content:"\00a5"}.glyphicon-ruble:before{content:"\20bd"}.glyphicon-rub:before{content:"\20bd"}.glyphicon-scale:before{content:"\e230"}.glyphicon-ice-lolly:before{content:"\e231"}.glyphicon-ice-lolly-tasted:before{content:"\e232"}.glyphicon-education:before{content:"\e233"}.glyphicon-option-horizontal:before{content:"\e234"}.glyphicon-option-vertical:before{content:"\e235"}.glyphicon-menu-hamburger:before{content:"\e236"}.glyphicon-modal-window:before{content:"\e237"}.glyphicon-oil:before{content:"\e238"}.glyphicon-grain:before{content:"\e239"}.glyphicon-sunglasses:before{content:"\e240"}.glyphicon-text-size:before{content:"\e241"}.glyphicon-text-color:before{content:"\e242"}.glyphicon-text-background:before{content:"\e243"}.glyphicon-object-align-top:before{content:"\e244"}.glyphicon-object-align-bottom:before{content:"\e245"}.glyphicon-object-align-horizontal:before{content:"\e246"}.glyphicon-object-align-left:before{content:"\e247"}.glyphicon-object-align-vertical:before{content:"\e248"}.glyphicon-object-align-right:before{content:"\e249"}.glyphicon-triangle-right:before{content:"\e250"}.glyphicon-triangle-left:before{content:"\e251"}.glyphicon-triangle-bottom:before{content:"\e252"}.glyphicon-triangle-top:before{content:"\e253"}.glyphicon-console:before{content:"\e254"}.glyphicon-superscript:before{content:"\e255"}.glyphicon-subscript:before{content:"\e256"}.glyphicon-menu-left:before{content:"\e257"}.glyphicon-menu-right:before{content:"\e258"}.glyphicon-menu-down:before{content:"\e259"}.glyphicon-menu-up:before{content:"\e260"}*{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}:after,:before{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}html{font-size:10px;-webkit-tap-highlight-color:rgba(0,0,0,0)}body{font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;line-height:1.42857143;color:#333;background-color:#fff}button,input,select,textarea{font-family:inherit;font-size:inherit;line-height:inherit}a{color:#337ab7;text-decoration:none}a:focus,a:hover{color:#23527c;text-decoration:underline}a:focus{outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}figure{margin:0}img{vertical-align:middle}.carousel-inner>.item>a>img,.carousel-inner>.item>img,.img-responsive,.thumbnail a>img,.thumbnail>img{display:block;max-width:100%;height:auto}.img-rounded{border-radius:6px}.img-thumbnail{display:inline-block;max-width:100%;height:auto;padding:4px;line-height:1.42857143;background-color:#fff;border:1px solid #ddd;border-radius:4px;-webkit-transition:all .2s ease-in-out;-o-transition:all .2s ease-in-out;transition:all .2s ease-in-out}.img-circle{border-radius:50%}hr{margin-top:20px;margin-bottom:20px;border:0;border-top:1px solid #eee}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0}.sr-only-focusable:active,.sr-only-focusable:focus{position:static;width:auto;height:auto;margin:0;overflow:visible;clip:auto}[role=button]{cursor:pointer}.h1,.h2,.h3,.h4,.h5,.h6,h1,h2,h3,h4,h5,h6{font-family:inherit;font-weight:500;line-height:1.1;color:inherit}.h1 .small,.h1 small,.h2 .small,.h2 small,.h3 .small,.h3 small,.h4 .small,.h4 small,.h5 .small,.h5 small,.h6 .small,.h6 small,h1 .small,h1 small,h2 .small,h2 small,h3 .small,h3 small,h4 .small,h4 small,h5 .small,h5 small,h6 .small,h6 small{font-weight:400;line-height:1;color:#777}.h1,.h2,.h3,h1,h2,h3{margin-top:20px;margin-bottom:10px}.h1 .small,.h1 small,.h2 .small,.h2 small,.h3 .small,.h3 small,h1 .small,h1 small,h2 .small,h2 small,h3 .small,h3 small{font-size:65%}.h4,.h5,.h6,h4,h5,h6{margin-top:10px;margin-bottom:10px}.h4 .small,.h4 small,.h5 .small,.h5 small,.h6 .small,.h6 small,h4 .small,h4 small,h5 .small,h5 small,h6 .small,h6 small{font-size:75%}.h1,h1{font-size:36px}.h2,h2{font-size:30px}.h3,h3{font-size:24px}.h4,h4{font-size:18px}.h5,h5{font-size:14px}.h6,h6{font-size:12px}p{margin:0 0 10px}.lead{margin-bottom:20px;font-size:16px;font-weight:300;line-height:1.4}@media (min-width:768px){.lead{font-size:21px}}.small,small{font-size:85%}.mark,mark{padding:.2em;background-color:#fcf8e3}.text-left{text-align:left}.text-right{text-align:right}.text-center{text-align:center}.text-justify{text-align:justify}.text-nowrap{white-space:nowrap}.text-lowercase{text-transform:lowercase}.text-uppercase{text-transform:uppercase}.text-capitalize{text-transform:capitalize}.text-muted{color:#777}.text-primary{color:#337ab7}a.text-primary:focus,a.text-primary:hover{color:#286090}.text-success{color:#3c763d}a.text-success:focus,a.text-success:hover{color:#2b542c}.text-info{color:#31708f}a.text-info:focus,a.text-info:hover{color:#245269}.text-warning{color:#8a6d3b}a.text-warning:focus,a.text-warning:hover{color:#66512c}.text-danger{color:#a94442}a.text-danger:focus,a.text-danger:hover{color:#843534}.bg-primary{color:#fff;background-color:#337ab7}a.bg-primary:focus,a.bg-primary:hover{background-color:#286090}.bg-success{background-color:#dff0d8}a.bg-success:focus,a.bg-success:hover{background-color:#c1e2b3}.bg-info{background-color:#d9edf7}a.bg-info:focus,a.bg-info:hover{background-color:#afd9ee}.bg-warning{background-color:#fcf8e3}a.bg-warning:focus,a.bg-warning:hover{background-color:#f7ecb5}.bg-danger{background-color:#f2dede}a.bg-danger:focus,a.bg-danger:hover{background-color:#e4b9b9}.page-header{padding-bottom:9px;margin:40px 0 20px;border-bottom:1px solid #eee}ol,ul{margin-top:0;margin-bottom:10px}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}.list-unstyled{padding-left:0;list-style:none}.list-inline{padding-left:0;margin-left:-5px;list-style:none}.list-inline>li{display:inline-block;padding-right:5px;padding-left:5px}dl{margin-top:0;margin-bottom:20px}dd,dt{line-height:1.42857143}dt{font-weight:700}dd{margin-left:0}@media (min-width:768px){.dl-horizontal dt{float:left;width:160px;overflow:hidden;clear:left;text-align:right;text-overflow:ellipsis;white-space:nowrap}.dl-horizontal dd{margin-left:180px}}abbr[data-original-title],abbr[title]{cursor:help;border-bottom:1px dotted #777}.initialism{font-size:90%;text-transform:uppercase}blockquote{padding:10px 20px;margin:0 0 20px;font-size:17.5px;border-left:5px solid #eee}blockquote ol:last-child,blockquote p:last-child,blockquote ul:last-child{margin-bottom:0}blockquote .small,blockquote footer,blockquote small{display:block;font-size:80%;line-height:1.42857143;color:#777}blockquote .small:before,blockquote footer:before,blockquote small:before{content:'\2014 \00A0'}.blockquote-reverse,blockquote.pull-right{padding-right:15px;padding-left:0;text-align:right;border-right:5px solid #eee;border-left:0}.blockquote-reverse .small:before,.blockquote-reverse footer:before,.blockquote-reverse small:before,blockquote.pull-right .small:before,blockquote.pull-right footer:before,blockquote.pull-right small:before{content:''}.blockquote-reverse .small:after,.blockquote-reverse footer:after,.blockquote-reverse small:after,blockquote.pull-right .small:after,blockquote.pull-right footer:after,blockquote.pull-right small:after{content:'\00A0 \2014'}address{margin-bottom:20px;font-style:normal;line-height:1.42857143}code,kbd,pre,samp{font-family:Menlo,Monaco,Consolas,"Courier New",monospace}code{padding:2px 4px;font-size:90%;color:#c7254e;background-color:#f9f2f4;border-radius:4px}kbd{padding:2px 4px;font-size:90%;color:#fff;background-color:#333;border-radius:3px;-webkit-box-shadow:inset 0 -1px 0 rgba(0,0,0,.25);box-shadow:inset 0 -1px 0 rgba(0,0,0,.25)}kbd kbd{padding:0;font-size:100%;font-weight:700;-webkit-box-shadow:none;box-shadow:none}pre{display:block;padding:9.5px;margin:0 0 10px;font-size:13px;line-height:1.42857143;color:#333;word-break:break-all;word-wrap:break-word;background-color:#f5f5f5;border:1px solid #ccc;border-radius:4px}pre code{padding:0;font-size:inherit;color:inherit;white-space:pre-wrap;background-color:transparent;border-radius:0}.pre-scrollable{max-height:340px;overflow-y:scroll}.container{padding-right:15px;padding-left:15px;margin-right:auto;margin-left:auto}@media (min-width:768px){.container{width:750px}}@media (min-width:992px){.container{width:970px}}@media (min-width:1200px){.container{width:1170px}}.container-fluid{padding-right:15px;padding-left:15px;margin-right:auto;margin-left:auto}.row{margin-right:-15px;margin-left:-15px}.col-lg-1,.col-lg-10,.col-lg-11,.col-lg-12,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9,.col-md-1,.col-md-10,.col-md-11,.col-md-12,.col-md-2,.col-md-3,.col-md-4,.col-md-5,.col-md-6,.col-md-7,.col-md-8,.col-md-9,.col-sm-1,.col-sm-10,.col-sm-11,.col-sm-12,.col-sm-2,.col-sm-3,.col-sm-4,.col-sm-5,.col-sm-6,.col-sm-7,.col-sm-8,.col-sm-9,.col-xs-1,.col-xs-10,.col-xs-11,.col-xs-12,.col-xs-2,.col-xs-3,.col-xs-4,.col-xs-5,.col-xs-6,.col-xs-7,.col-xs-8,.col-xs-9{position:relative;min-height:1px;padding-right:15px;padding-left:15px}.col-xs-1,.col-xs-10,.col-xs-11,.col-xs-12,.col-xs-2,.col-xs-3,.col-xs-4,.col-xs-5,.col-xs-6,.col-xs-7,.col-xs-8,.col-xs-9{float:left}.col-xs-12{width:100%}.col-xs-11{width:91.66666667%}.col-xs-10{width:83.33333333%}.col-xs-9{width:75%}.col-xs-8{width:66.66666667%}.col-xs-7{width:58.33333333%}.col-xs-6{width:50%}.col-xs-5{width:41.66666667%}.col-xs-4{width:33.33333333%}.col-xs-3{width:25%}.col-xs-2{width:16.66666667%}.col-xs-1{width:8.33333333%}.col-xs-pull-12{right:100%}.col-xs-pull-11{right:91.66666667%}.col-xs-pull-10{right:83.33333333%}.col-xs-pull-9{right:75%}.col-xs-pull-8{right:66.66666667%}.col-xs-pull-7{right:58.33333333%}.col-xs-pull-6{right:50%}.col-xs-pull-5{right:41.66666667%}.col-xs-pull-4{right:33.33333333%}.col-xs-pull-3{right:25%}.col-xs-pull-2{right:16.66666667%}.col-xs-pull-1{right:8.33333333%}.col-xs-pull-0{right:auto}.col-xs-push-12{left:100%}.col-xs-push-11{left:91.66666667%}.col-xs-push-10{left:83.33333333%}.col-xs-push-9{left:75%}.col-xs-push-8{left:66.66666667%}.col-xs-push-7{left:58.33333333%}.col-xs-push-6{left:50%}.col-xs-push-5{left:41.66666667%}.col-xs-push-4{left:33.33333333%}.col-xs-push-3{left:25%}.col-xs-push-2{left:16.66666667%}.col-xs-push-1{left:8.33333333%}.col-xs-push-0{left:auto}.col-xs-offset-12{margin-left:100%}.col-xs-offset-11{margin-left:91.66666667%}.col-xs-offset-10{margin-left:83.33333333%}.col-xs-offset-9{margin-left:75%}.col-xs-offset-8{margin-left:66.66666667%}.col-xs-offset-7{margin-left:58.33333333%}.col-xs-offset-6{margin-left:50%}.col-xs-offset-5{margin-left:41.66666667%}.col-xs-offset-4{margin-left:33.33333333%}.col-xs-offset-3{margin-left:25%}.col-xs-offset-2{margin-left:16.66666667%}.col-xs-offset-1{margin-left:8.33333333%}.col-xs-offset-0{margin-left:0}@media (min-width:768px){.col-sm-1,.col-sm-10,.col-sm-11,.col-sm-12,.col-sm-2,.col-sm-3,.col-sm-4,.col-sm-5,.col-sm-6,.col-sm-7,.col-sm-8,.col-sm-9{float:left}.col-sm-12{width:100%}.col-sm-11{width:91.66666667%}.col-sm-10{width:83.33333333%}.col-sm-9{width:75%}.col-sm-8{width:66.66666667%}.col-sm-7{width:58.33333333%}.col-sm-6{width:50%}.col-sm-5{width:41.66666667%}.col-sm-4{width:33.33333333%}.col-sm-3{width:25%}.col-sm-2{width:16.66666667%}.col-sm-1{width:8.33333333%}.col-sm-pull-12{right:100%}.col-sm-pull-11{right:91.66666667%}.col-sm-pull-10{right:83.33333333%}.col-sm-pull-9{right:75%}.col-sm-pull-8{right:66.66666667%}.col-sm-pull-7{right:58.33333333%}.col-sm-pull-6{right:50%}.col-sm-pull-5{right:41.66666667%}.col-sm-pull-4{right:33.33333333%}.col-sm-pull-3{right:25%}.col-sm-pull-2{right:16.66666667%}.col-sm-pull-1{right:8.33333333%}.col-sm-pull-0{right:auto}.col-sm-push-12{left:100%}.col-sm-push-11{left:91.66666667%}.col-sm-push-10{left:83.33333333%}.col-sm-push-9{left:75%}.col-sm-push-8{left:66.66666667%}.col-sm-push-7{left:58.33333333%}.col-sm-push-6{left:50%}.col-sm-push-5{left:41.66666667%}.col-sm-push-4{left:33.33333333%}.col-sm-push-3{left:25%}.col-sm-push-2{left:16.66666667%}.col-sm-push-1{left:8.33333333%}.col-sm-push-0{left:auto}.col-sm-offset-12{margin-left:100%}.col-sm-offset-11{margin-left:91.66666667%}.col-sm-offset-10{margin-left:83.33333333%}.col-sm-offset-9{margin-left:75%}.col-sm-offset-8{margin-left:66.66666667%}.col-sm-offset-7{margin-left:58.33333333%}.col-sm-offset-6{margin-left:50%}.col-sm-offset-5{margin-left:41.66666667%}.col-sm-offset-4{margin-left:33.33333333%}.col-sm-offset-3{margin-left:25%}.col-sm-offset-2{margin-left:16.66666667%}.col-sm-offset-1{margin-left:8.33333333%}.col-sm-offset-0{margin-left:0}}@media (min-width:992px){.col-md-1,.col-md-10,.col-md-11,.col-md-12,.col-md-2,.col-md-3,.col-md-4,.col-md-5,.col-md-6,.col-md-7,.col-md-8,.col-md-9{float:left}.col-md-12{width:100%}.col-md-11{width:91.66666667%}.col-md-10{width:83.33333333%}.col-md-9{width:75%}.col-md-8{width:66.66666667%}.col-md-7{width:58.33333333%}.col-md-6{width:50%}.col-md-5{width:41.66666667%}.col-md-4{width:33.33333333%}.col-md-3{width:25%}.col-md-2{width:16.66666667%}.col-md-1{width:8.33333333%}.col-md-pull-12{right:100%}.col-md-pull-11{right:91.66666667%}.col-md-pull-10{right:83.33333333%}.col-md-pull-9{right:75%}.col-md-pull-8{right:66.66666667%}.col-md-pull-7{right:58.33333333%}.col-md-pull-6{right:50%}.col-md-pull-5{right:41.66666667%}.col-md-pull-4{right:33.33333333%}.col-md-pull-3{right:25%}.col-md-pull-2{right:16.66666667%}.col-md-pull-1{right:8.33333333%}.col-md-pull-0{right:auto}.col-md-push-12{left:100%}.col-md-push-11{left:91.66666667%}.col-md-push-10{left:83.33333333%}.col-md-push-9{left:75%}.col-md-push-8{left:66.66666667%}.col-md-push-7{left:58.33333333%}.col-md-push-6{left:50%}.col-md-push-5{left:41.66666667%}.col-md-push-4{left:33.33333333%}.col-md-push-3{left:25%}.col-md-push-2{left:16.66666667%}.col-md-push-1{left:8.33333333%}.col-md-push-0{left:auto}.col-md-offset-12{margin-left:100%}.col-md-offset-11{margin-left:91.66666667%}.col-md-offset-10{margin-left:83.33333333%}.col-md-offset-9{margin-left:75%}.col-md-offset-8{margin-left:66.66666667%}.col-md-offset-7{margin-left:58.33333333%}.col-md-offset-6{margin-left:50%}.col-md-offset-5{margin-left:41.66666667%}.col-md-offset-4{margin-left:33.33333333%}.col-md-offset-3{margin-left:25%}.col-md-offset-2{margin-left:16.66666667%}.col-md-offset-1{margin-left:8.33333333%}.col-md-offset-0{margin-left:0}}@media (min-width:1200px){.col-lg-1,.col-lg-10,.col-lg-11,.col-lg-12,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9{float:left}.col-lg-12{width:100%}.col-lg-11{width:91.66666667%}.col-lg-10{width:83.33333333%}.col-lg-9{width:75%}.col-lg-8{width:66.66666667%}.col-lg-7{width:58.33333333%}.col-lg-6{width:50%}.col-lg-5{width:41.66666667%}.col-lg-4{width:33.33333333%}.col-lg-3{width:25%}.col-lg-2{width:16.66666667%}.col-lg-1{width:8.33333333%}.col-lg-pull-12{right:100%}.col-lg-pull-11{right:91.66666667%}.col-lg-pull-10{right:83.33333333%}.col-lg-pull-9{right:75%}.col-lg-pull-8{right:66.66666667%}.col-lg-pull-7{right:58.33333333%}.col-lg-pull-6{right:50%}.col-lg-pull-5{right:41.66666667%}.col-lg-pull-4{right:33.33333333%}.col-lg-pull-3{right:25%}.col-lg-pull-2{right:16.66666667%}.col-lg-pull-1{right:8.33333333%}.col-lg-pull-0{right:auto}.col-lg-push-12{left:100%}.col-lg-push-11{left:91.66666667%}.col-lg-push-10{left:83.33333333%}.col-lg-push-9{left:75%}.col-lg-push-8{left:66.66666667%}.col-lg-push-7{left:58.33333333%}.col-lg-push-6{left:50%}.col-lg-push-5{left:41.66666667%}.col-lg-push-4{left:33.33333333%}.col-lg-push-3{left:25%}.col-lg-push-2{left:16.66666667%}.col-lg-push-1{left:8.33333333%}.col-lg-push-0{left:auto}.col-lg-offset-12{margin-left:100%}.col-lg-offset-11{margin-left:91.66666667%}.col-lg-offset-10{margin-left:83.33333333%}.col-lg-offset-9{margin-left:75%}.col-lg-offset-8{margin-left:66.66666667%}.col-lg-offset-7{margin-left:58.33333333%}.col-lg-offset-6{margin-left:50%}.col-lg-offset-5{margin-left:41.66666667%}.col-lg-offset-4{margin-left:33.33333333%}.col-lg-offset-3{margin-left:25%}.col-lg-offset-2{margin-left:16.66666667%}.col-lg-offset-1{margin-left:8.33333333%}.col-lg-offset-0{margin-left:0}}table{background-color:transparent}caption{padding-top:8px;padding-bottom:8px;color:#777;text-align:left}th{text-align:left}.table{width:100%;max-width:100%;margin-bottom:20px}.table>tbody>tr>td,.table>tbody>tr>th,.table>tfoot>tr>td,.table>tfoot>tr>th,.table>thead>tr>td,.table>thead>tr>th{padding:8px;line-height:1.42857143;vertical-align:top;border-top:1px solid #ddd}.table>thead>tr>th{vertical-align:bottom;border-bottom:2px solid #ddd}.table>caption+thead>tr:first-child>td,.table>caption+thead>tr:first-child>th,.table>colgroup+thead>tr:first-child>td,.table>colgroup+thead>tr:first-child>th,.table>thead:first-child>tr:first-child>td,.table>thead:first-child>tr:first-child>th{border-top:0}.table>tbody+tbody{border-top:2px solid #ddd}.table .table{background-color:#fff}.table-condensed>tbody>tr>td,.table-condensed>tbody>tr>th,.table-condensed>tfoot>tr>td,.table-condensed>tfoot>tr>th,.table-condensed>thead>tr>td,.table-condensed>thead>tr>th{padding:5px}.table-bordered{border:1px solid #ddd}.table-bordered>tbody>tr>td,.table-bordered>tbody>tr>th,.table-bordered>tfoot>tr>td,.table-bordered>tfoot>tr>th,.table-bordered>thead>tr>td,.table-bordered>thead>tr>th{border:1px solid #ddd}.table-bordered>thead>tr>td,.table-bordered>thead>tr>th{border-bottom-width:2px}.table-striped>tbody>tr:nth-of-type(odd){background-color:#f9f9f9}.table-hover>tbody>tr:hover{background-color:#f5f5f5}table col[class*=col-]{position:static;display:table-column;float:none}table td[class*=col-],table th[class*=col-]{position:static;display:table-cell;float:none}.table>tbody>tr.active>td,.table>tbody>tr.active>th,.table>tbody>tr>td.active,.table>tbody>tr>th.active,.table>tfoot>tr.active>td,.table>tfoot>tr.active>th,.table>tfoot>tr>td.active,.table>tfoot>tr>th.active,.table>thead>tr.active>td,.table>thead>tr.active>th,.table>thead>tr>td.active,.table>thead>tr>th.active{background-color:#f5f5f5}.table-hover>tbody>tr.active:hover>td,.table-hover>tbody>tr.active:hover>th,.table-hover>tbody>tr:hover>.active,.table-hover>tbody>tr>td.active:hover,.table-hover>tbody>tr>th.active:hover{background-color:#e8e8e8}.table>tbody>tr.success>td,.table>tbody>tr.success>th,.table>tbody>tr>td.success,.table>tbody>tr>th.success,.table>tfoot>tr.success>td,.table>tfoot>tr.success>th,.table>tfoot>tr>td.success,.table>tfoot>tr>th.success,.table>thead>tr.success>td,.table>thead>tr.success>th,.table>thead>tr>td.success,.table>thead>tr>th.success{background-color:#dff0d8}.table-hover>tbody>tr.success:hover>td,.table-hover>tbody>tr.success:hover>th,.table-hover>tbody>tr:hover>.success,.table-hover>tbody>tr>td.success:hover,.table-hover>tbody>tr>th.success:hover{background-color:#d0e9c6}.table>tbody>tr.info>td,.table>tbody>tr.info>th,.table>tbody>tr>td.info,.table>tbody>tr>th.info,.table>tfoot>tr.info>td,.table>tfoot>tr.info>th,.table>tfoot>tr>td.info,.table>tfoot>tr>th.info,.table>thead>tr.info>td,.table>thead>tr.info>th,.table>thead>tr>td.info,.table>thead>tr>th.info{background-color:#d9edf7}.table-hover>tbody>tr.info:hover>td,.table-hover>tbody>tr.info:hover>th,.table-hover>tbody>tr:hover>.info,.table-hover>tbody>tr>td.info:hover,.table-hover>tbody>tr>th.info:hover{background-color:#c4e3f3}.table>tbody>tr.warning>td,.table>tbody>tr.warning>th,.table>tbody>tr>td.warning,.table>tbody>tr>th.warning,.table>tfoot>tr.warning>td,.table>tfoot>tr.warning>th,.table>tfoot>tr>td.warning,.table>tfoot>tr>th.warning,.table>thead>tr.warning>td,.table>thead>tr.warning>th,.table>thead>tr>td.warning,.table>thead>tr>th.warning{background-color:#fcf8e3}.table-hover>tbody>tr.warning:hover>td,.table-hover>tbody>tr.warning:hover>th,.table-hover>tbody>tr:hover>.warning,.table-hover>tbody>tr>td.warning:hover,.table-hover>tbody>tr>th.warning:hover{background-color:#faf2cc}.table>tbody>tr.danger>td,.table>tbody>tr.danger>th,.table>tbody>tr>td.danger,.table>tbody>tr>th.danger,.table>tfoot>tr.danger>td,.table>tfoot>tr.danger>th,.table>tfoot>tr>td.danger,.table>tfoot>tr>th.danger,.table>thead>tr.danger>td,.table>thead>tr.danger>th,.table>thead>tr>td.danger,.table>thead>tr>th.danger{background-color:#f2dede}.table-hover>tbody>tr.danger:hover>td,.table-hover>tbody>tr.danger:hover>th,.table-hover>tbody>tr:hover>.danger,.table-hover>tbody>tr>td.danger:hover,.table-hover>tbody>tr>th.danger:hover{background-color:#ebcccc}.table-responsive{min-height:.01%;overflow-x:auto}@media screen and (max-width:767px){.table-responsive{width:100%;margin-bottom:15px;overflow-y:hidden;-ms-overflow-style:-ms-autohiding-scrollbar;border:1px solid #ddd}.table-responsive>.table{margin-bottom:0}.table-responsive>.table>tbody>tr>td,.table-responsive>.table>tbody>tr>th,.table-responsive>.table>tfoot>tr>td,.table-responsive>.table>tfoot>tr>th,.table-responsive>.table>thead>tr>td,.table-responsive>.table>thead>tr>th{white-space:nowrap}.table-responsive>.table-bordered{border:0}.table-responsive>.table-bordered>tbody>tr>td:first-child,.table-responsive>.table-bordered>tbody>tr>th:first-child,.table-responsive>.table-bordered>tfoot>tr>td:first-child,.table-responsive>.table-bordered>tfoot>tr>th:first-child,.table-responsive>.table-bordered>thead>tr>td:first-child,.table-responsive>.table-bordered>thead>tr>th:first-child{border-left:0}.table-responsive>.table-bordered>tbody>tr>td:last-child,.table-responsive>.table-bordered>tbody>tr>th:last-child,.table-responsive>.table-bordered>tfoot>tr>td:last-child,.table-responsive>.table-bordered>tfoot>tr>th:last-child,.table-responsive>.table-bordered>thead>tr>td:last-child,.table-responsive>.table-bordered>thead>tr>th:last-child{border-right:0}.table-responsive>.table-bordered>tbody>tr:last-child>td,.table-responsive>.table-bordered>tbody>tr:last-child>th,.table-responsive>.table-bordered>tfoot>tr:last-child>td,.table-responsive>.table-bordered>tfoot>tr:last-child>th{border-bottom:0}}fieldset{min-width:0;padding:0;margin:0;border:0}legend{display:block;width:100%;padding:0;margin-bottom:20px;font-size:21px;line-height:inherit;color:#333;border:0;border-bottom:1px solid #e5e5e5}label{display:inline-block;max-width:100%;margin-bottom:5px;font-weight:700}input[type=search]{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}input[type=checkbox],input[type=radio]{margin:4px 0 0;margin-top:1px\9;line-height:normal}input[type=file]{display:block}input[type=range]{display:block;width:100%}select[multiple],select[size]{height:auto}input[type=file]:focus,input[type=checkbox]:focus,input[type=radio]:focus{outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}output{display:block;padding-top:7px;font-size:14px;line-height:1.42857143;color:#555}.form-control{display:block;width:100%;height:34px;padding:6px 12px;font-size:14px;line-height:1.42857143;color:#555;background-color:#fff;background-image:none;border:1px solid #ccc;border-radius:4px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075);box-shadow:inset 0 1px 1px rgba(0,0,0,.075);-webkit-transition:border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;-o-transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s;transition:border-color ease-in-out .15s,box-shadow ease-in-out .15s}.form-control:focus{border-color:#66afe9;outline:0;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6);box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)}.form-control::-moz-placeholder{color:#999;opacity:1}.form-control:-ms-input-placeholder{color:#999}.form-control::-webkit-input-placeholder{color:#999}.form-control::-ms-expand{background-color:transparent;border:0}.form-control[disabled],.form-control[readonly],fieldset[disabled] .form-control{background-color:#eee;opacity:1}.form-control[disabled],fieldset[disabled] .form-control{cursor:not-allowed}textarea.form-control{height:auto}input[type=search]{-webkit-appearance:none}@media screen and (-webkit-min-device-pixel-ratio:0){input[type=date].form-control,input[type=time].form-control,input[type=datetime-local].form-control,input[type=month].form-control{line-height:34px}.input-group-sm input[type=date],.input-group-sm input[type=time],.input-group-sm input[type=datetime-local],.input-group-sm input[type=month],input[type=date].input-sm,input[type=time].input-sm,input[type=datetime-local].input-sm,input[type=month].input-sm{line-height:30px}.input-group-lg input[type=date],.input-group-lg input[type=time],.input-group-lg input[type=datetime-local],.input-group-lg input[type=month],input[type=date].input-lg,input[type=time].input-lg,input[type=datetime-local].input-lg,input[type=month].input-lg{line-height:46px}}.form-group{margin-bottom:15px}.checkbox,.radio{position:relative;display:block;margin-top:10px;margin-bottom:10px}.checkbox label,.radio label{min-height:20px;padding-left:20px;margin-bottom:0;font-weight:400;cursor:pointer}.checkbox input[type=checkbox],.checkbox-inline input[type=checkbox],.radio input[type=radio],.radio-inline input[type=radio]{position:absolute;margin-top:4px\9;margin-left:-20px}.checkbox+.checkbox,.radio+.radio{margin-top:-5px}.checkbox-inline,.radio-inline{position:relative;display:inline-block;padding-left:20px;margin-bottom:0;font-weight:400;vertical-align:middle;cursor:pointer}.checkbox-inline+.checkbox-inline,.radio-inline+.radio-inline{margin-top:0;margin-left:10px}fieldset[disabled] input[type=checkbox],fieldset[disabled] input[type=radio],input[type=checkbox].disabled,input[type=checkbox][disabled],input[type=radio].disabled,input[type=radio][disabled]{cursor:not-allowed}.checkbox-inline.disabled,.radio-inline.disabled,fieldset[disabled] .checkbox-inline,fieldset[disabled] .radio-inline{cursor:not-allowed}.checkbox.disabled label,.radio.disabled label,fieldset[disabled] .checkbox label,fieldset[disabled] .radio label{cursor:not-allowed}.form-control-static{min-height:34px;padding-top:7px;padding-bottom:7px;margin-bottom:0}.form-control-static.input-lg,.form-control-static.input-sm{padding-right:0;padding-left:0}.input-sm{height:30px;padding:5px 10px;font-size:12px;line-height:1.5;border-radius:3px}select.input-sm{height:30px;line-height:30px}select[multiple].input-sm,textarea.input-sm{height:auto}.form-group-sm .form-control{height:30px;padding:5px 10px;font-size:12px;line-height:1.5;border-radius:3px}.form-group-sm select.form-control{height:30px;line-height:30px}.form-group-sm select[multiple].form-control,.form-group-sm textarea.form-control{height:auto}.form-group-sm .form-control-static{height:30px;min-height:32px;padding:6px 10px;font-size:12px;line-height:1.5}.input-lg{height:46px;padding:10px 16px;font-size:18px;line-height:1.3333333;border-radius:6px}select.input-lg{height:46px;line-height:46px}select[multiple].input-lg,textarea.input-lg{height:auto}.form-group-lg .form-control{height:46px;padding:10px 16px;font-size:18px;line-height:1.3333333;border-radius:6px}.form-group-lg select.form-control{height:46px;line-height:46px}.form-group-lg select[multiple].form-control,.form-group-lg textarea.form-control{height:auto}.form-group-lg .form-control-static{height:46px;min-height:38px;padding:11px 16px;font-size:18px;line-height:1.3333333}.has-feedback{position:relative}.has-feedback .form-control{padding-right:42.5px}.form-control-feedback{position:absolute;top:0;right:0;z-index:2;display:block;width:34px;height:34px;line-height:34px;text-align:center;pointer-events:none}.form-group-lg .form-control+.form-control-feedback,.input-group-lg+.form-control-feedback,.input-lg+.form-control-feedback{width:46px;height:46px;line-height:46px}.form-group-sm .form-control+.form-control-feedback,.input-group-sm+.form-control-feedback,.input-sm+.form-control-feedback{width:30px;height:30px;line-height:30px}.has-success .checkbox,.has-success .checkbox-inline,.has-success .control-label,.has-success .help-block,.has-success .radio,.has-success .radio-inline,.has-success.checkbox label,.has-success.checkbox-inline label,.has-success.radio label,.has-success.radio-inline label{color:#3c763d}.has-success .form-control{border-color:#3c763d;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075);box-shadow:inset 0 1px 1px rgba(0,0,0,.075)}.has-success .form-control:focus{border-color:#2b542c;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #67b168;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #67b168}.has-success .input-group-addon{color:#3c763d;background-color:#dff0d8;border-color:#3c763d}.has-success .form-control-feedback{color:#3c763d}.has-warning .checkbox,.has-warning .checkbox-inline,.has-warning .control-label,.has-warning .help-block,.has-warning .radio,.has-warning .radio-inline,.has-warning.checkbox label,.has-warning.checkbox-inline label,.has-warning.radio label,.has-warning.radio-inline label{color:#8a6d3b}.has-warning .form-control{border-color:#8a6d3b;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075);box-shadow:inset 0 1px 1px rgba(0,0,0,.075)}.has-warning .form-control:focus{border-color:#66512c;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #c0a16b;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #c0a16b}.has-warning .input-group-addon{color:#8a6d3b;background-color:#fcf8e3;border-color:#8a6d3b}.has-warning .form-control-feedback{color:#8a6d3b}.has-error .checkbox,.has-error .checkbox-inline,.has-error .control-label,.has-error .help-block,.has-error .radio,.has-error .radio-inline,.has-error.checkbox label,.has-error.checkbox-inline label,.has-error.radio label,.has-error.radio-inline label{color:#a94442}.has-error .form-control{border-color:#a94442;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075);box-shadow:inset 0 1px 1px rgba(0,0,0,.075)}.has-error .form-control:focus{border-color:#843534;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #ce8483;box-shadow:inset 0 1px 1px rgba(0,0,0,.075),0 0 6px #ce8483}.has-error .input-group-addon{color:#a94442;background-color:#f2dede;border-color:#a94442}.has-error .form-control-feedback{color:#a94442}.has-feedback label~.form-control-feedback{top:25px}.has-feedback label.sr-only~.form-control-feedback{top:0}.help-block{display:block;margin-top:5px;margin-bottom:10px;color:#737373}@media (min-width:768px){.form-inline .form-group{display:inline-block;margin-bottom:0;vertical-align:middle}.form-inline .form-control{display:inline-block;width:auto;vertical-align:middle}.form-inline .form-control-static{display:inline-block}.form-inline .input-group{display:inline-table;vertical-align:middle}.form-inline .input-group .form-control,.form-inline .input-group .input-group-addon,.form-inline .input-group .input-group-btn{width:auto}.form-inline .input-group>.form-control{width:100%}.form-inline .control-label{margin-bottom:0;vertical-align:middle}.form-inline .checkbox,.form-inline .radio{display:inline-block;margin-top:0;margin-bottom:0;vertical-align:middle}.form-inline .checkbox label,.form-inline .radio label{padding-left:0}.form-inline .checkbox input[type=checkbox],.form-inline .radio input[type=radio]{position:relative;margin-left:0}.form-inline .has-feedback .form-control-feedback{top:0}}.form-horizontal .checkbox,.form-horizontal .checkbox-inline,.form-horizontal .radio,.form-horizontal .radio-inline{padding-top:7px;margin-top:0;margin-bottom:0}.form-horizontal .checkbox,.form-horizontal .radio{min-height:27px}.form-horizontal .form-group{margin-right:-15px;margin-left:-15px}@media (min-width:768px){.form-horizontal .control-label{padding-top:7px;margin-bottom:0;text-align:right}}.form-horizontal .has-feedback .form-control-feedback{right:15px}@media (min-width:768px){.form-horizontal .form-group-lg .control-label{padding-top:11px;font-size:18px}}@media (min-width:768px){.form-horizontal .form-group-sm .control-label{padding-top:6px;font-size:12px}}.btn{display:inline-block;padding:6px 12px;margin-bottom:0;font-size:14px;font-weight:400;line-height:1.42857143;text-align:center;white-space:nowrap;vertical-align:middle;-ms-touch-action:manipulation;touch-action:manipulation;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-image:none;border:1px solid transparent;border-radius:4px}.btn.active.focus,.btn.active:focus,.btn.focus,.btn:active.focus,.btn:active:focus,.btn:focus{outline:5px auto -webkit-focus-ring-color;outline-offset:-2px}.btn.focus,.btn:focus,.btn:hover{color:#333;text-decoration:none}.btn.active,.btn:active{background-image:none;outline:0;-webkit-box-shadow:inset 0 3px 5px rgba(0,0,0,.125);box-shadow:inset 0 3px 5px rgba(0,0,0,.125)}.btn.disabled,.btn[disabled],fieldset[disabled] .btn{cursor:not-allowed;filter:alpha(opacity=65);-webkit-box-shadow:none;box-shadow:none;opacity:.65}a.btn.disabled,fieldset[disabled] a.btn{pointer-events:none}.btn-default{color:#333;background-color:#fff;border-color:#ccc}.btn-default.focus,.btn-default:focus{color:#333;background-color:#e6e6e6;border-color:#8c8c8c}.btn-default:hover{color:#333;background-color:#e6e6e6;border-color:#adadad}.btn-default.active,.btn-default:active,.open>.dropdown-toggle.btn-default{color:#333;background-color:#e6e6e6;border-color:#adadad}.btn-default.active.focus,.btn-default.active:focus,.btn-default.active:hover,.btn-default:active.focus,.btn-default:active:focus,.btn-default:active:hover,.open>.dropdown-toggle.btn-default.focus,.open>.dropdown-toggle.btn-default:focus,.open>.dropdown-toggle.btn-default:hover{color:#333;background-color:#d4d4d4;border-color:#8c8c8c}.btn-default.active,.btn-default:active,.open>.dropdown-toggle.btn-default{background-image:none}.btn-default.disabled.focus,.btn-default.disabled:focus,.btn-default.disabled:hover,.btn-default[disabled].focus,.btn-default[disabled]:focus,.btn-default[disabled]:hover,fieldset[disabled] .btn-default.focus,fieldset[disabled] .btn-default:focus,fieldset[disabled] .btn-default:hover{background-color:#fff;border-color:#ccc}.btn-default .badge{color:#fff;background-color:#333}.btn-primary{color:#fff;background-color:#337ab7;border-color:#2e6da4}.btn-primary.focus,.btn-primary:focus{color:#fff;background-color:#286090;border-color:#122b40}.btn-primary:hover{color:#fff;background-color:#286090;border-color:#204d74}.btn-primary.active,.btn-primary:active,.open>.dropdown-toggle.btn-primary{color:#fff;background-color:#286090;border-color:#204d74}.btn-primary.active.focus,.btn-primary.active:focus,.btn-primary.active:hover,.btn-primary:active.focus,.btn-primary:active:focus,.btn-primary:active:hover,.open>.dropdown-toggle.btn-primary.focus,.open>.dropdown-toggle.btn-primary:focus,.open>.dropdown-toggle.btn-primary:hover{color:#fff;background-color:#204d74;border-color:#122b40}.btn-primary.active,.btn-primary:active,.open>.dropdown-toggle.btn-primary{background-image:none}.btn-primary.disabled.focus,.btn-primary.disabled:focus,.btn-primary.disabled:hover,.btn-primary[disabled].focus,.btn-primary[disabled]:focus,.btn-primary[disabled]:hover,fieldset[disabled] .btn-primary.focus,fieldset[disabled] .btn-primary:focus,fieldset[disabled] .btn-primary:hover{background-color:#337ab7;border-color:#2e6da4}.btn-primary .badge{color:#337ab7;background-color:#fff}.btn-success{color:#fff;background-color:#5cb85c;border-color:#4cae4c}.btn-success.focus,.btn-success:focus{color:#fff;background-color:#449d44;border-color:#255625}.btn-success:hover{color:#fff;background-color:#449d44;border-color:#398439}.btn-success.active,.btn-success:active,.open>.dropdown-toggle.btn-success{color:#fff;background-color:#449d44;border-color:#398439}.btn-success.active.focus,.btn-success.active:focus,.btn-success.active:hover,.btn-success:active.focus,.btn-success:active:focus,.btn-success:active:hover,.open>.dropdown-toggle.btn-success.focus,.open>.dropdown-toggle.btn-success:focus,.open>.dropdown-toggle.btn-success:hover{color:#fff;background-color:#398439;border-color:#255625}.btn-success.active,.btn-success:active,.open>.dropdown-toggle.btn-success{background-image:none}.btn-success.disabled.focus,.btn-success.disabled:focus,.btn-success.disabled:hover,.btn-success[disabled].focus,.btn-success[disabled]:focus,.btn-success[disabled]:hover,fieldset[disabled] .btn-success.focus,fieldset[disabled] .btn-success:focus,fieldset[disabled] .btn-success:hover{background-color:#5cb85c;border-color:#4cae4c}.btn-success .badge{color:#5cb85c;background-color:#fff}.btn-info{color:#fff;background-color:#5bc0de;border-color:#46b8da}.btn-info.focus,.btn-info:focus{color:#fff;background-color:#31b0d5;border-color:#1b6d85}.btn-info:hover{color:#fff;background-color:#31b0d5;border-color:#269abc}.btn-info.active,.btn-info:active,.open>.dropdown-toggle.btn-info{color:#fff;background-color:#31b0d5;border-color:#269abc}.btn-info.active.focus,.btn-info.active:focus,.btn-info.active:hover,.btn-info:active.focus,.btn-info:active:focus,.btn-info:active:hover,.open>.dropdown-toggle.btn-info.focus,.open>.dropdown-toggle.btn-info:focus,.open>.dropdown-toggle.btn-info:hover{color:#fff;background-color:#269abc;border-color:#1b6d85}.btn-info.active,.btn-info:active,.open>.dropdown-toggle.btn-info{background-image:none}.btn-info.disabled.focus,.btn-info.disabled:focus,.btn-info.disabled:hover,.btn-info[disabled].focus,.btn-info[disabled]:focus,.btn-info[disabled]:hover,fieldset[disabled] .btn-info.focus,fieldset[disabled] .btn-info:focus,fieldset[disabled] .btn-info:hover{background-color:#5bc0de;border-color:#46b8da}.btn-info .badge{color:#5bc0de;background-color:#fff}.btn-warning{color:#fff;background-color:#f0ad4e;border-color:#eea236}.btn-warning.focus,.btn-warning:focus{color:#fff;background-color:#ec971f;border-color:#985f0d}.btn-warning:hover{color:#fff;background-color:#ec971f;border-color:#d58512}.btn-warning.active,.btn-warning:active,.open>.dropdown-toggle.btn-warning{color:#fff;background-color:#ec971f;border-color:#d58512}.btn-warning.active.focus,.btn-warning.active:focus,.btn-warning.active:hover,.btn-warning:active.focus,.btn-warning:active:focus,.btn-warning:active:hover,.open>.dropdown-toggle.btn-warning.focus,.open>.dropdown-toggle.btn-warning:focus,.open>.dropdown-toggle.btn-warning:hover{color:#fff;background-color:#d58512;border-color:#985f0d}.btn-warning.active,.btn-warning:active,.open>.dropdown-toggle.btn-warning{background-image:none}.btn-warning.disabled.focus,.btn-warning.disabled:focus,.btn-warning.disabled:hover,.btn-warning[disabled].focus,.btn-warning[disabled]:focus,.btn-warning[disabled]:hover,fieldset[disabled] .btn-warning.focus,fieldset[disabled] .btn-warning:focus,fieldset[disabled] .btn-warning:hover{background-color:#f0ad4e;border-color:#eea236}.btn-warning .badge{color:#f0ad4e;background-color:#fff}.btn-danger{color:#fff;background-color:#d9534f;border-color:#d43f3a}.btn-danger.focus,.btn-danger:focus{color:#fff;background-color:#c9302c;border-color:#761c19}.btn-danger:hover{color:#fff;background-color:#c9302c;border-color:#ac2925}.btn-danger.active,.btn-danger:active,.open>.dropdown-toggle.btn-danger{color:#fff;background-color:#c9302c;border-color:#ac2925}.btn-danger.active.focus,.btn-danger.active:focus,.btn-danger.active:hover,.btn-danger:active.focus,.btn-danger:active:focus,.btn-danger:active:hover,.open>.dropdown-toggle.btn-danger.focus,.open>.dropdown-toggle.btn-danger:focus,.open>.dropdown-toggle.btn-danger:hover{color:#fff;background-color:#ac2925;border-color:#761c19}.btn-danger.active,.btn-danger:active,.open>.dropdown-toggle.btn-danger{background-image:none}.btn-danger.disabled.focus,.btn-danger.disabled:focus,.btn-danger.disabled:hover,.btn-danger[disabled].focus,.btn-danger[disabled]:focus,.btn-danger[disabled]:hover,fieldset[disabled] .btn-danger.focus,fieldset[disabled] .btn-danger:focus,fieldset[disabled] .btn-danger:hover{background-color:#d9534f;border-color:#d43f3a}.btn-danger .badge{color:#d9534f;background-color:#fff}.btn-link{font-weight:400;color:#337ab7;border-radius:0}.btn-link,.btn-link.active,.btn-link:active,.btn-link[disabled],fieldset[disabled] .btn-link{background-color:transparent;-webkit-box-shadow:none;box-shadow:none}.btn-link,.btn-link:active,.btn-link:focus,.btn-link:hover{border-color:transparent}.btn-link:focus,.btn-link:hover{color:#23527c;text-decoration:underline;background-color:transparent}.btn-link[disabled]:focus,.btn-link[disabled]:hover,fieldset[disabled] .btn-link:focus,fieldset[disabled] .btn-link:hover{color:#777;text-decoration:none}.btn-group-lg>.btn,.btn-lg{padding:10px 16px;font-size:18px;line-height:1.3333333;border-radius:6px}.btn-group-sm>.btn,.btn-sm{padding:5px 10px;font-size:12px;line-height:1.5;border-radius:3px}.btn-group-xs>.btn,.btn-xs{padding:1px 5px;font-size:12px;line-height:1.5;border-radius:3px}.btn-block{display:block;width:100%}.btn-block+.btn-block{margin-top:5px}input[type=button].btn-block,input[type=reset].btn-block,input[type=submit].btn-block{width:100%}.fade{opacity:0;-webkit-transition:opacity .15s linear;-o-transition:opacity .15s linear;transition:opacity .15s linear}.fade.in{opacity:1}.collapse{display:none}.collapse.in{display:block}tr.collapse.in{display:table-row}tbody.collapse.in{display:table-row-group}.collapsing{position:relative;height:0;overflow:hidden;-webkit-transition-timing-function:ease;-o-transition-timing-function:ease;transition-timing-function:ease;-webkit-transition-duration:.35s;-o-transition-duration:.35s;transition-duration:.35s;-webkit-transition-property:height,visibility;-o-transition-property:height,visibility;transition-property:height,visibility}.caret{display:inline-block;width:0;height:0;margin-left:2px;vertical-align:middle;border-top:4px dashed;border-top:4px solid\9;border-right:4px solid transparent;border-left:4px solid transparent}.dropdown,.dropup{position:relative}.dropdown-toggle:focus{outline:0}.dropdown-menu{position:absolute;top:100%;left:0;z-index:1000;display:none;float:left;min-width:160px;padding:5px 0;margin:2px 0 0;font-size:14px;text-align:left;list-style:none;background-color:#fff;-webkit-background-clip:padding-box;background-clip:padding-box;border:1px solid #ccc;border:1px solid rgba(0,0,0,.15);border-radius:4px;-webkit-box-shadow:0 6px 12px rgba(0,0,0,.175);box-shadow:0 6px 12px rgba(0,0,0,.175)}.dropdown-menu.pull-right{right:0;left:auto}.dropdown-menu .divider{height:1px;margin:9px 0;overflow:hidden;background-color:#e5e5e5}.dropdown-menu>li>a{display:block;padding:3px 20px;clear:both;font-weight:400;line-height:1.42857143;color:#333;white-space:nowrap}.dropdown-menu>li>a:focus,.dropdown-menu>li>a:hover{color:#262626;text-decoration:none;background-color:#f5f5f5}.dropdown-menu>.active>a,.dropdown-menu>.active>a:focus,.dropdown-menu>.active>a:hover{color:#fff;text-decoration:none;background-color:#337ab7;outline:0}.dropdown-menu>.disabled>a,.dropdown-menu>.disabled>a:focus,.dropdown-menu>.disabled>a:hover{color:#777}.dropdown-menu>.disabled>a:focus,.dropdown-menu>.disabled>a:hover{text-decoration:none;cursor:not-allowed;background-color:transparent;background-image:none;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}.open>.dropdown-menu{display:block}.open>a{outline:0}.dropdown-menu-right{right:0;left:auto}.dropdown-menu-left{right:auto;left:0}.dropdown-header{display:block;padding:3px 20px;font-size:12px;line-height:1.42857143;color:#777;white-space:nowrap}.dropdown-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;z-index:990}.pull-right>.dropdown-menu{right:0;left:auto}.dropup .caret,.navbar-fixed-bottom .dropdown .caret{content:"";border-top:0;border-bottom:4px dashed;border-bottom:4px solid\9}.dropup .dropdown-menu,.navbar-fixed-bottom .dropdown .dropdown-menu{top:auto;bottom:100%;margin-bottom:2px}@media (min-width:768px){.navbar-right .dropdown-menu{right:0;left:auto}.navbar-right .dropdown-menu-left{right:auto;left:0}}.btn-group,.btn-group-vertical{position:relative;display:inline-block;vertical-align:middle}.btn-group-vertical>.btn,.btn-group>.btn{position:relative;float:left}.btn-group-vertical>.btn.active,.btn-group-vertical>.btn:active,.btn-group-vertical>.btn:focus,.btn-group-vertical>.btn:hover,.btn-group>.btn.active,.btn-group>.btn:active,.btn-group>.btn:focus,.btn-group>.btn:hover{z-index:2}.btn-group .btn+.btn,.btn-group .btn+.btn-group,.btn-group .btn-group+.btn,.btn-group .btn-group+.btn-group{margin-left:-1px}.btn-toolbar{margin-left:-5px}.btn-toolbar .btn,.btn-toolbar .btn-group,.btn-toolbar .input-group{float:left}.btn-toolbar>.btn,.btn-toolbar>.btn-group,.btn-toolbar>.input-group{margin-left:5px}.btn-group>.btn:not(:first-child):not(:last-child):not(.dropdown-toggle){border-radius:0}.btn-group>.btn:first-child{margin-left:0}.btn-group>.btn:first-child:not(:last-child):not(.dropdown-toggle){border-top-right-radius:0;border-bottom-right-radius:0}.btn-group>.btn:last-child:not(:first-child),.btn-group>.dropdown-toggle:not(:first-child){border-top-left-radius:0;border-bottom-left-radius:0}.btn-group>.btn-group{float:left}.btn-group>.btn-group:not(:first-child):not(:last-child)>.btn{border-radius:0}.btn-group>.btn-group:first-child:not(:last-child)>.btn:last-child,.btn-group>.btn-group:first-child:not(:last-child)>.dropdown-toggle{border-top-right-radius:0;border-bottom-right-radius:0}.btn-group>.btn-group:last-child:not(:first-child)>.btn:first-child{border-top-left-radius:0;border-bottom-left-radius:0}.btn-group .dropdown-toggle:active,.btn-group.open .dropdown-toggle{outline:0}.btn-group>.btn+.dropdown-toggle{padding-right:8px;padding-left:8px}.btn-group>.btn-lg+.dropdown-toggle{padding-right:12px;padding-left:12px}.btn-group.open .dropdown-toggle{-webkit-box-shadow:inset 0 3px 5px rgba(0,0,0,.125);box-shadow:inset 0 3px 5px rgba(0,0,0,.125)}.btn-group.open .dropdown-toggle.btn-link{-webkit-box-shadow:none;box-shadow:none}.btn .caret{margin-left:0}.btn-lg .caret{border-width:5px 5px 0;border-bottom-width:0}.dropup .btn-lg .caret{border-width:0 5px 5px}.btn-group-vertical>.btn,.btn-group-vertical>.btn-group,.btn-group-vertical>.btn-group>.btn{display:block;float:none;width:100%;max-width:100%}.btn-group-vertical>.btn-group>.btn{float:none}.btn-group-vertical>.btn+.btn,.btn-group-vertical>.btn+.btn-group,.btn-group-vertical>.btn-group+.btn,.btn-group-vertical>.btn-group+.btn-group{margin-top:-1px;margin-left:0}.btn-group-vertical>.btn:not(:first-child):not(:last-child){border-radius:0}.btn-group-vertical>.btn:first-child:not(:last-child){border-top-left-radius:4px;border-top-right-radius:4px;border-bottom-right-radius:0;border-bottom-left-radius:0}.btn-group-vertical>.btn:last-child:not(:first-child){border-top-left-radius:0;border-top-right-radius:0;border-bottom-right-radius:4px;border-bottom-left-radius:4px}.btn-group-vertical>.btn-group:not(:first-child):not(:last-child)>.btn{border-radius:0}.btn-group-vertical>.btn-group:first-child:not(:last-child)>.btn:last-child,.btn-group-vertical>.btn-group:first-child:not(:last-child)>.dropdown-toggle{border-bottom-right-radius:0;border-bottom-left-radius:0}.btn-group-vertical>.btn-group:last-child:not(:first-child)>.btn:first-child{border-top-left-radius:0;border-top-right-radius:0}.btn-group-justified{display:table;width:100%;table-layout:fixed;border-collapse:separate}.btn-group-justified>.btn,.btn-group-justified>.btn-group{display:table-cell;float:none;width:1%}.btn-group-justified>.btn-group .btn{width:100%}.btn-group-justified>.btn-group .dropdown-menu{left:auto}[data-toggle=buttons]>.btn input[type=checkbox],[data-toggle=buttons]>.btn input[type=radio],[data-toggle=buttons]>.btn-group>.btn input[type=checkbox],[data-toggle=buttons]>.btn-group>.btn input[type=radio]{position:absolute;clip:rect(0,0,0,0);pointer-events:none}.input-group{position:relative;display:table;border-collapse:separate}.input-group[class*=col-]{float:none;padding-right:0;padding-left:0}.input-group .form-control{position:relative;z-index:2;float:left;width:100%;margin-bottom:0}.input-group .form-control:focus{z-index:3}.input-group-lg>.form-control,.input-group-lg>.input-group-addon,.input-group-lg>.input-group-btn>.btn{height:46px;padding:10px 16px;font-size:18px;line-height:1.3333333;border-radius:6px}select.input-group-lg>.form-control,select.input-group-lg>.input-group-addon,select.input-group-lg>.input-group-btn>.btn{height:46px;line-height:46px}select[multiple].input-group-lg>.form-control,select[multiple].input-group-lg>.input-group-addon,select[multiple].input-group-lg>.input-group-btn>.btn,textarea.input-group-lg>.form-control,textarea.input-group-lg>.input-group-addon,textarea.input-group-lg>.input-group-btn>.btn{height:auto}.input-group-sm>.form-control,.input-group-sm>.input-group-addon,.input-group-sm>.input-group-btn>.btn{height:30px;padding:5px 10px;font-size:12px;line-height:1.5;border-radius:3px}select.input-group-sm>.form-control,select.input-group-sm>.input-group-addon,select.input-group-sm>.input-group-btn>.btn{height:30px;line-height:30px}select[multiple].input-group-sm>.form-control,select[multiple].input-group-sm>.input-group-addon,select[multiple].input-group-sm>.input-group-btn>.btn,textarea.input-group-sm>.form-control,textarea.input-group-sm>.input-group-addon,textarea.input-group-sm>.input-group-btn>.btn{height:auto}.input-group .form-control,.input-group-addon,.input-group-btn{display:table-cell}.input-group .form-control:not(:first-child):not(:last-child),.input-group-addon:not(:first-child):not(:last-child),.input-group-btn:not(:first-child):not(:last-child){border-radius:0}.input-group-addon,.input-group-btn{width:1%;white-space:nowrap;vertical-align:middle}.input-group-addon{padding:6px 12px;font-size:14px;font-weight:400;line-height:1;color:#555;text-align:center;background-color:#eee;border:1px solid #ccc;border-radius:4px}.input-group-addon.input-sm{padding:5px 10px;font-size:12px;border-radius:3px}.input-group-addon.input-lg{padding:10px 16px;font-size:18px;border-radius:6px}.input-group-addon input[type=checkbox],.input-group-addon input[type=radio]{margin-top:0}.input-group .form-control:first-child,.input-group-addon:first-child,.input-group-btn:first-child>.btn,.input-group-btn:first-child>.btn-group>.btn,.input-group-btn:first-child>.dropdown-toggle,.input-group-btn:last-child>.btn-group:not(:last-child)>.btn,.input-group-btn:last-child>.btn:not(:last-child):not(.dropdown-toggle){border-top-right-radius:0;border-bottom-right-radius:0}.input-group-addon:first-child{border-right:0}.input-group .form-control:last-child,.input-group-addon:last-child,.input-group-btn:first-child>.btn-group:not(:first-child)>.btn,.input-group-btn:first-child>.btn:not(:first-child),.input-group-btn:last-child>.btn,.input-group-btn:last-child>.btn-group>.btn,.input-group-btn:last-child>.dropdown-toggle{border-top-left-radius:0;border-bottom-left-radius:0}.input-group-addon:last-child{border-left:0}.input-group-btn{position:relative;font-size:0;white-space:nowrap}.input-group-btn>.btn{position:relative}.input-group-btn>.btn+.btn{margin-left:-1px}.input-group-btn>.btn:active,.input-group-btn>.btn:focus,.input-group-btn>.btn:hover{z-index:2}.input-group-btn:first-child>.btn,.input-group-btn:first-child>.btn-group{margin-right:-1px}.input-group-btn:last-child>.btn,.input-group-btn:last-child>.btn-group{z-index:2;margin-left:-1px}.nav{padding-left:0;margin-bottom:0;list-style:none}.nav>li{position:relative;display:block}.nav>li>a{position:relative;display:block;padding:10px 15px}.nav>li>a:focus,.nav>li>a:hover{text-decoration:none;background-color:#eee}.nav>li.disabled>a{color:#777}.nav>li.disabled>a:focus,.nav>li.disabled>a:hover{color:#777;text-decoration:none;cursor:not-allowed;background-color:transparent}.nav .open>a,.nav .open>a:focus,.nav .open>a:hover{background-color:#eee;border-color:#337ab7}.nav .nav-divider{height:1px;margin:9px 0;overflow:hidden;background-color:#e5e5e5}.nav>li>a>img{max-width:none}.nav-tabs{border-bottom:1px solid #ddd}.nav-tabs>li{float:left;margin-bottom:-1px}.nav-tabs>li>a{margin-right:2px;line-height:1.42857143;border:1px solid transparent;border-radius:4px 4px 0 0}.nav-tabs>li>a:hover{border-color:#eee #eee #ddd}.nav-tabs>li.active>a,.nav-tabs>li.active>a:focus,.nav-tabs>li.active>a:hover{color:#555;cursor:default;background-color:#fff;border:1px solid #ddd;border-bottom-color:transparent}.nav-tabs.nav-justified{width:100%;border-bottom:0}.nav-tabs.nav-justified>li{float:none}.nav-tabs.nav-justified>li>a{margin-bottom:5px;text-align:center}.nav-tabs.nav-justified>.dropdown .dropdown-menu{top:auto;left:auto}@media (min-width:768px){.nav-tabs.nav-justified>li{display:table-cell;width:1%}.nav-tabs.nav-justified>li>a{margin-bottom:0}}.nav-tabs.nav-justified>li>a{margin-right:0;border-radius:4px}.nav-tabs.nav-justified>.active>a,.nav-tabs.nav-justified>.active>a:focus,.nav-tabs.nav-justified>.active>a:hover{border:1px solid #ddd}@media (min-width:768px){.nav-tabs.nav-justified>li>a{border-bottom:1px solid #ddd;border-radius:4px 4px 0 0}.nav-tabs.nav-justified>.active>a,.nav-tabs.nav-justified>.active>a:focus,.nav-tabs.nav-justified>.active>a:hover{border-bottom-color:#fff}}.nav-pills>li{float:left}.nav-pills>li>a{border-radius:4px}.nav-pills>li+li{margin-left:2px}.nav-pills>li.active>a,.nav-pills>li.active>a:focus,.nav-pills>li.active>a:hover{color:#fff;background-color:#337ab7}.nav-stacked>li{float:none}.nav-stacked>li+li{margin-top:2px;margin-left:0}.nav-justified{width:100%}.nav-justified>li{float:none}.nav-justified>li>a{margin-bottom:5px;text-align:center}.nav-justified>.dropdown .dropdown-menu{top:auto;left:auto}@media (min-width:768px){.nav-justified>li{display:table-cell;width:1%}.nav-justified>li>a{margin-bottom:0}}.nav-tabs-justified{border-bottom:0}.nav-tabs-justified>li>a{margin-right:0;border-radius:4px}.nav-tabs-justified>.active>a,.nav-tabs-justified>.active>a:focus,.nav-tabs-justified>.active>a:hover{border:1px solid #ddd}@media (min-width:768px){.nav-tabs-justified>li>a{border-bottom:1px solid #ddd;border-radius:4px 4px 0 0}.nav-tabs-justified>.active>a,.nav-tabs-justified>.active>a:focus,.nav-tabs-justified>.active>a:hover{border-bottom-color:#fff}}.tab-content>.tab-pane{display:none}.tab-content>.active{display:block}.nav-tabs .dropdown-menu{margin-top:-1px;border-top-left-radius:0;border-top-right-radius:0}.navbar{position:relative;min-height:50px;margin-bottom:20px;border:1px solid transparent}@media (min-width:768px){.navbar{border-radius:4px}}@media (min-width:768px){.navbar-header{float:left}}.navbar-collapse{padding-right:15px;padding-left:15px;overflow-x:visible;-webkit-overflow-scrolling:touch;border-top:1px solid transparent;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.1);box-shadow:inset 0 1px 0 rgba(255,255,255,.1)}.navbar-collapse.in{overflow-y:auto}@media (min-width:768px){.navbar-collapse{width:auto;border-top:0;-webkit-box-shadow:none;box-shadow:none}.navbar-collapse.collapse{display:block!important;height:auto!important;padding-bottom:0;overflow:visible!important}.navbar-collapse.in{overflow-y:visible}.navbar-fixed-bottom .navbar-collapse,.navbar-fixed-top .navbar-collapse,.navbar-static-top .navbar-collapse{padding-right:0;padding-left:0}}.navbar-fixed-bottom .navbar-collapse,.navbar-fixed-top .navbar-collapse{max-height:340px}@media (max-device-width:480px) and (orientation:landscape){.navbar-fixed-bottom .navbar-collapse,.navbar-fixed-top .navbar-collapse{max-height:200px}}.container-fluid>.navbar-collapse,.container-fluid>.navbar-header,.container>.navbar-collapse,.container>.navbar-header{margin-right:-15px;margin-left:-15px}@media (min-width:768px){.container-fluid>.navbar-collapse,.container-fluid>.navbar-header,.container>.navbar-collapse,.container>.navbar-header{margin-right:0;margin-left:0}}.navbar-static-top{z-index:1000;border-width:0 0 1px}@media (min-width:768px){.navbar-static-top{border-radius:0}}.navbar-fixed-bottom,.navbar-fixed-top{position:fixed;right:0;left:0;z-index:1030}@media (min-width:768px){.navbar-fixed-bottom,.navbar-fixed-top{border-radius:0}}.navbar-fixed-top{top:0;border-width:0 0 1px}.navbar-fixed-bottom{bottom:0;margin-bottom:0;border-width:1px 0 0}.navbar-brand{float:left;height:50px;padding:15px 15px;font-size:18px;line-height:20px}.navbar-brand:focus,.navbar-brand:hover{text-decoration:none}.navbar-brand>img{display:block}@media (min-width:768px){.navbar>.container .navbar-brand,.navbar>.container-fluid .navbar-brand{margin-left:-15px}}.navbar-toggle{position:relative;float:right;padding:9px 10px;margin-top:8px;margin-right:15px;margin-bottom:8px;background-color:transparent;background-image:none;border:1px solid transparent;border-radius:4px}.navbar-toggle:focus{outline:0}.navbar-toggle .icon-bar{display:block;width:22px;height:2px;border-radius:1px}.navbar-toggle .icon-bar+.icon-bar{margin-top:4px}@media (min-width:768px){.navbar-toggle{display:none}}.navbar-nav{margin:7.5px -15px}.navbar-nav>li>a{padding-top:10px;padding-bottom:10px;line-height:20px}@media (max-width:767px){.navbar-nav .open .dropdown-menu{position:static;float:none;width:auto;margin-top:0;background-color:transparent;border:0;-webkit-box-shadow:none;box-shadow:none}.navbar-nav .open .dropdown-menu .dropdown-header,.navbar-nav .open .dropdown-menu>li>a{padding:5px 15px 5px 25px}.navbar-nav .open .dropdown-menu>li>a{line-height:20px}.navbar-nav .open .dropdown-menu>li>a:focus,.navbar-nav .open .dropdown-menu>li>a:hover{background-image:none}}@media (min-width:768px){.navbar-nav{float:left;margin:0}.navbar-nav>li{float:left}.navbar-nav>li>a{padding-top:15px;padding-bottom:15px}}.navbar-form{padding:10px 15px;margin-top:8px;margin-right:-15px;margin-bottom:8px;margin-left:-15px;border-top:1px solid transparent;border-bottom:1px solid transparent;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.1),0 1px 0 rgba(255,255,255,.1);box-shadow:inset 0 1px 0 rgba(255,255,255,.1),0 1px 0 rgba(255,255,255,.1)}@media (min-width:768px){.navbar-form .form-group{display:inline-block;margin-bottom:0;vertical-align:middle}.navbar-form .form-control{display:inline-block;width:auto;vertical-align:middle}.navbar-form .form-control-static{display:inline-block}.navbar-form .input-group{display:inline-table;vertical-align:middle}.navbar-form .input-group .form-control,.navbar-form .input-group .input-group-addon,.navbar-form .input-group .input-group-btn{width:auto}.navbar-form .input-group>.form-control{width:100%}.navbar-form .control-label{margin-bottom:0;vertical-align:middle}.navbar-form .checkbox,.navbar-form .radio{display:inline-block;margin-top:0;margin-bottom:0;vertical-align:middle}.navbar-form .checkbox label,.navbar-form .radio label{padding-left:0}.navbar-form .checkbox input[type=checkbox],.navbar-form .radio input[type=radio]{position:relative;margin-left:0}.navbar-form .has-feedback .form-control-feedback{top:0}}@media (max-width:767px){.navbar-form .form-group{margin-bottom:5px}.navbar-form .form-group:last-child{margin-bottom:0}}@media (min-width:768px){.navbar-form{width:auto;padding-top:0;padding-bottom:0;margin-right:0;margin-left:0;border:0;-webkit-box-shadow:none;box-shadow:none}}.navbar-nav>li>.dropdown-menu{margin-top:0;border-top-left-radius:0;border-top-right-radius:0}.navbar-fixed-bottom .navbar-nav>li>.dropdown-menu{margin-bottom:0;border-top-left-radius:4px;border-top-right-radius:4px;border-bottom-right-radius:0;border-bottom-left-radius:0}.navbar-btn{margin-top:8px;margin-bottom:8px}.navbar-btn.btn-sm{margin-top:10px;margin-bottom:10px}.navbar-btn.btn-xs{margin-top:14px;margin-bottom:14px}.navbar-text{margin-top:15px;margin-bottom:15px}@media (min-width:768px){.navbar-text{float:left;margin-right:15px;margin-left:15px}}@media (min-width:768px){.navbar-left{float:left!important}.navbar-right{float:right!important;margin-right:-15px}.navbar-right~.navbar-right{margin-right:0}}.navbar-default{background-color:#f8f8f8;border-color:#e7e7e7}.navbar-default .navbar-brand{color:#777}.navbar-default .navbar-brand:focus,.navbar-default .navbar-brand:hover{color:#5e5e5e;background-color:transparent}.navbar-default .navbar-text{color:#777}.navbar-default .navbar-nav>li>a{color:#777}.navbar-default .navbar-nav>li>a:focus,.navbar-default .navbar-nav>li>a:hover{color:#333;background-color:transparent}.navbar-default .navbar-nav>.active>a,.navbar-default .navbar-nav>.active>a:focus,.navbar-default .navbar-nav>.active>a:hover{color:#555;background-color:#e7e7e7}.navbar-default .navbar-nav>.disabled>a,.navbar-default .navbar-nav>.disabled>a:focus,.navbar-default .navbar-nav>.disabled>a:hover{color:#ccc;background-color:transparent}.navbar-default .navbar-toggle{border-color:#ddd}.navbar-default .navbar-toggle:focus,.navbar-default .navbar-toggle:hover{background-color:#ddd}.navbar-default .navbar-toggle .icon-bar{background-color:#888}.navbar-default .navbar-collapse,.navbar-default .navbar-form{border-color:#e7e7e7}.navbar-default .navbar-nav>.open>a,.navbar-default .navbar-nav>.open>a:focus,.navbar-default .navbar-nav>.open>a:hover{color:#555;background-color:#e7e7e7}@media (max-width:767px){.navbar-default .navbar-nav .open .dropdown-menu>li>a{color:#777}.navbar-default .navbar-nav .open .dropdown-menu>li>a:focus,.navbar-default .navbar-nav .open .dropdown-menu>li>a:hover{color:#333;background-color:transparent}.navbar-default .navbar-nav .open .dropdown-menu>.active>a,.navbar-default .navbar-nav .open .dropdown-menu>.active>a:focus,.navbar-default .navbar-nav .open .dropdown-menu>.active>a:hover{color:#555;background-color:#e7e7e7}.navbar-default .navbar-nav .open .dropdown-menu>.disabled>a,.navbar-default .navbar-nav .open .dropdown-menu>.disabled>a:focus,.navbar-default .navbar-nav .open .dropdown-menu>.disabled>a:hover{color:#ccc;background-color:transparent}}.navbar-default .navbar-link{color:#777}.navbar-default .navbar-link:hover{color:#333}.navbar-default .btn-link{color:#777}.navbar-default .btn-link:focus,.navbar-default .btn-link:hover{color:#333}.navbar-default .btn-link[disabled]:focus,.navbar-default .btn-link[disabled]:hover,fieldset[disabled] .navbar-default .btn-link:focus,fieldset[disabled] .navbar-default .btn-link:hover{color:#ccc}.navbar-inverse{background-color:#222;border-color:#080808}.navbar-inverse .navbar-brand{color:#9d9d9d}.navbar-inverse .navbar-brand:focus,.navbar-inverse .navbar-brand:hover{color:#fff;background-color:transparent}.navbar-inverse .navbar-text{color:#9d9d9d}.navbar-inverse .navbar-nav>li>a{color:#9d9d9d}.navbar-inverse .navbar-nav>li>a:focus,.navbar-inverse .navbar-nav>li>a:hover{color:#fff;background-color:transparent}.navbar-inverse .navbar-nav>.active>a,.navbar-inverse .navbar-nav>.active>a:focus,.navbar-inverse .navbar-nav>.active>a:hover{color:#fff;background-color:#080808}.navbar-inverse .navbar-nav>.disabled>a,.navbar-inverse .navbar-nav>.disabled>a:focus,.navbar-inverse .navbar-nav>.disabled>a:hover{color:#444;background-color:transparent}.navbar-inverse .navbar-toggle{border-color:#333}.navbar-inverse .navbar-toggle:focus,.navbar-inverse .navbar-toggle:hover{background-color:#333}.navbar-inverse .navbar-toggle .icon-bar{background-color:#fff}.navbar-inverse .navbar-collapse,.navbar-inverse .navbar-form{border-color:#101010}.navbar-inverse .navbar-nav>.open>a,.navbar-inverse .navbar-nav>.open>a:focus,.navbar-inverse .navbar-nav>.open>a:hover{color:#fff;background-color:#080808}@media (max-width:767px){.navbar-inverse .navbar-nav .open .dropdown-menu>.dropdown-header{border-color:#080808}.navbar-inverse .navbar-nav .open .dropdown-menu .divider{background-color:#080808}.navbar-inverse .navbar-nav .open .dropdown-menu>li>a{color:#9d9d9d}.navbar-inverse .navbar-nav .open .dropdown-menu>li>a:focus,.navbar-inverse .navbar-nav .open .dropdown-menu>li>a:hover{color:#fff;background-color:transparent}.navbar-inverse .navbar-nav .open .dropdown-menu>.active>a,.navbar-inverse .navbar-nav .open .dropdown-menu>.active>a:focus,.navbar-inverse .navbar-nav .open .dropdown-menu>.active>a:hover{color:#fff;background-color:#080808}.navbar-inverse .navbar-nav .open .dropdown-menu>.disabled>a,.navbar-inverse .navbar-nav .open .dropdown-menu>.disabled>a:focus,.navbar-inverse .navbar-nav .open .dropdown-menu>.disabled>a:hover{color:#444;background-color:transparent}}.navbar-inverse .navbar-link{color:#9d9d9d}.navbar-inverse .navbar-link:hover{color:#fff}.navbar-inverse .btn-link{color:#9d9d9d}.navbar-inverse .btn-link:focus,.navbar-inverse .btn-link:hover{color:#fff}.navbar-inverse .btn-link[disabled]:focus,.navbar-inverse .btn-link[disabled]:hover,fieldset[disabled] .navbar-inverse .btn-link:focus,fieldset[disabled] .navbar-inverse .btn-link:hover{color:#444}.breadcrumb{padding:8px 15px;margin-bottom:20px;list-style:none;background-color:#f5f5f5;border-radius:4px}.breadcrumb>li{display:inline-block}.breadcrumb>li+li:before{padding:0 5px;color:#ccc;content:"/\00a0"}.breadcrumb>.active{color:#777}.pagination{display:inline-block;padding-left:0;margin:20px 0;border-radius:4px}.pagination>li{display:inline}.pagination>li>a,.pagination>li>span{position:relative;float:left;padding:6px 12px;margin-left:-1px;line-height:1.42857143;color:#337ab7;text-decoration:none;background-color:#fff;border:1px solid #ddd}.pagination>li:first-child>a,.pagination>li:first-child>span{margin-left:0;border-top-left-radius:4px;border-bottom-left-radius:4px}.pagination>li:last-child>a,.pagination>li:last-child>span{border-top-right-radius:4px;border-bottom-right-radius:4px}.pagination>li>a:focus,.pagination>li>a:hover,.pagination>li>span:focus,.pagination>li>span:hover{z-index:2;color:#23527c;background-color:#eee;border-color:#ddd}.pagination>.active>a,.pagination>.active>a:focus,.pagination>.active>a:hover,.pagination>.active>span,.pagination>.active>span:focus,.pagination>.active>span:hover{z-index:3;color:#fff;cursor:default;background-color:#337ab7;border-color:#337ab7}.pagination>.disabled>a,.pagination>.disabled>a:focus,.pagination>.disabled>a:hover,.pagination>.disabled>span,.pagination>.disabled>span:focus,.pagination>.disabled>span:hover{color:#777;cursor:not-allowed;background-color:#fff;border-color:#ddd}.pagination-lg>li>a,.pagination-lg>li>span{padding:10px 16px;font-size:18px;line-height:1.3333333}.pagination-lg>li:first-child>a,.pagination-lg>li:first-child>span{border-top-left-radius:6px;border-bottom-left-radius:6px}.pagination-lg>li:last-child>a,.pagination-lg>li:last-child>span{border-top-right-radius:6px;border-bottom-right-radius:6px}.pagination-sm>li>a,.pagination-sm>li>span{padding:5px 10px;font-size:12px;line-height:1.5}.pagination-sm>li:first-child>a,.pagination-sm>li:first-child>span{border-top-left-radius:3px;border-bottom-left-radius:3px}.pagination-sm>li:last-child>a,.pagination-sm>li:last-child>span{border-top-right-radius:3px;border-bottom-right-radius:3px}.pager{padding-left:0;margin:20px 0;text-align:center;list-style:none}.pager li{display:inline}.pager li>a,.pager li>span{display:inline-block;padding:5px 14px;background-color:#fff;border:1px solid #ddd;border-radius:15px}.pager li>a:focus,.pager li>a:hover{text-decoration:none;background-color:#eee}.pager .next>a,.pager .next>span{float:right}.pager .previous>a,.pager .previous>span{float:left}.pager .disabled>a,.pager .disabled>a:focus,.pager .disabled>a:hover,.pager .disabled>span{color:#777;cursor:not-allowed;background-color:#fff}.label{display:inline;padding:.2em .6em .3em;font-size:75%;font-weight:700;line-height:1;color:#fff;text-align:center;white-space:nowrap;vertical-align:baseline;border-radius:.25em}a.label:focus,a.label:hover{color:#fff;text-decoration:none;cursor:pointer}.label:empty{display:none}.btn .label{position:relative;top:-1px}.label-default{background-color:#777}.label-default[href]:focus,.label-default[href]:hover{background-color:#5e5e5e}.label-primary{background-color:#337ab7}.label-primary[href]:focus,.label-primary[href]:hover{background-color:#286090}.label-success{background-color:#5cb85c}.label-success[href]:focus,.label-success[href]:hover{background-color:#449d44}.label-info{background-color:#5bc0de}.label-info[href]:focus,.label-info[href]:hover{background-color:#31b0d5}.label-warning{background-color:#f0ad4e}.label-warning[href]:focus,.label-warning[href]:hover{background-color:#ec971f}.label-danger{background-color:#d9534f}.label-danger[href]:focus,.label-danger[href]:hover{background-color:#c9302c}.badge{display:inline-block;min-width:10px;padding:3px 7px;font-size:12px;font-weight:700;line-height:1;color:#fff;text-align:center;white-space:nowrap;vertical-align:middle;background-color:#777;border-radius:10px}.badge:empty{display:none}.btn .badge{position:relative;top:-1px}.btn-group-xs>.btn .badge,.btn-xs .badge{top:0;padding:1px 5px}a.badge:focus,a.badge:hover{color:#fff;text-decoration:none;cursor:pointer}.list-group-item.active>.badge,.nav-pills>.active>a>.badge{color:#337ab7;background-color:#fff}.list-group-item>.badge{float:right}.list-group-item>.badge+.badge{margin-right:5px}.nav-pills>li>a>.badge{margin-left:3px}.jumbotron{padding-top:30px;padding-bottom:30px;margin-bottom:30px;color:inherit;background-color:#eee}.jumbotron .h1,.jumbotron h1{color:inherit}.jumbotron p{margin-bottom:15px;font-size:21px;font-weight:200}.jumbotron>hr{border-top-color:#d5d5d5}.container .jumbotron,.container-fluid .jumbotron{padding-right:15px;padding-left:15px;border-radius:6px}.jumbotron .container{max-width:100%}@media screen and (min-width:768px){.jumbotron{padding-top:48px;padding-bottom:48px}.container .jumbotron,.container-fluid .jumbotron{padding-right:60px;padding-left:60px}.jumbotron .h1,.jumbotron h1{font-size:63px}}.thumbnail{display:block;padding:4px;margin-bottom:20px;line-height:1.42857143;background-color:#fff;border:1px solid #ddd;border-radius:4px;-webkit-transition:border .2s ease-in-out;-o-transition:border .2s ease-in-out;transition:border .2s ease-in-out}.thumbnail a>img,.thumbnail>img{margin-right:auto;margin-left:auto}a.thumbnail.active,a.thumbnail:focus,a.thumbnail:hover{border-color:#337ab7}.thumbnail .caption{padding:9px;color:#333}.alert{padding:15px;margin-bottom:20px;border:1px solid transparent;border-radius:4px}.alert h4{margin-top:0;color:inherit}.alert .alert-link{font-weight:700}.alert>p,.alert>ul{margin-bottom:0}.alert>p+p{margin-top:5px}.alert-dismissable,.alert-dismissible{padding-right:35px}.alert-dismissable .close,.alert-dismissible .close{position:relative;top:-2px;right:-21px;color:inherit}.alert-success{color:#3c763d;background-color:#dff0d8;border-color:#d6e9c6}.alert-success hr{border-top-color:#c9e2b3}.alert-success .alert-link{color:#2b542c}.alert-info{color:#31708f;background-color:#d9edf7;border-color:#bce8f1}.alert-info hr{border-top-color:#a6e1ec}.alert-info .alert-link{color:#245269}.alert-warning{color:#8a6d3b;background-color:#fcf8e3;border-color:#faebcc}.alert-warning hr{border-top-color:#f7e1b5}.alert-warning .alert-link{color:#66512c}.alert-danger{color:#a94442;background-color:#f2dede;border-color:#ebccd1}.alert-danger hr{border-top-color:#e4b9c0}.alert-danger .alert-link{color:#843534}@-webkit-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@-o-keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}@keyframes progress-bar-stripes{from{background-position:40px 0}to{background-position:0 0}}.progress{height:20px;margin-bottom:20px;overflow:hidden;background-color:#f5f5f5;border-radius:4px;-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,.1);box-shadow:inset 0 1px 2px rgba(0,0,0,.1)}.progress-bar{float:left;width:0;height:100%;font-size:12px;line-height:20px;color:#fff;text-align:center;background-color:#337ab7;-webkit-box-shadow:inset 0 -1px 0 rgba(0,0,0,.15);box-shadow:inset 0 -1px 0 rgba(0,0,0,.15);-webkit-transition:width .6s ease;-o-transition:width .6s ease;transition:width .6s ease}.progress-bar-striped,.progress-striped .progress-bar{background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);-webkit-background-size:40px 40px;background-size:40px 40px}.progress-bar.active,.progress.active .progress-bar{-webkit-animation:progress-bar-stripes 2s linear infinite;-o-animation:progress-bar-stripes 2s linear infinite;animation:progress-bar-stripes 2s linear infinite}.progress-bar-success{background-color:#5cb85c}.progress-striped .progress-bar-success{background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent)}.progress-bar-info{background-color:#5bc0de}.progress-striped .progress-bar-info{background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent)}.progress-bar-warning{background-color:#f0ad4e}.progress-striped .progress-bar-warning{background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent)}.progress-bar-danger{background-color:#d9534f}.progress-striped .progress-bar-danger{background-image:-webkit-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:-o-linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent);background-image:linear-gradient(45deg,rgba(255,255,255,.15) 25%,transparent 25%,transparent 50%,rgba(255,255,255,.15) 50%,rgba(255,255,255,.15) 75%,transparent 75%,transparent)}.media{margin-top:15px}.media:first-child{margin-top:0}.media,.media-body{overflow:hidden;zoom:1}.media-body{width:10000px}.media-object{display:block}.media-object.img-thumbnail{max-width:none}.media-right,.media>.pull-right{padding-left:10px}.media-left,.media>.pull-left{padding-right:10px}.media-body,.media-left,.media-right{display:table-cell;vertical-align:top}.media-middle{vertical-align:middle}.media-bottom{vertical-align:bottom}.media-heading{margin-top:0;margin-bottom:5px}.media-list{padding-left:0;list-style:none}.list-group{padding-left:0;margin-bottom:20px}.list-group-item{position:relative;display:block;padding:10px 15px;margin-bottom:-1px;background-color:#fff;border:1px solid #ddd}.list-group-item:first-child{border-top-left-radius:4px;border-top-right-radius:4px}.list-group-item:last-child{margin-bottom:0;border-bottom-right-radius:4px;border-bottom-left-radius:4px}a.list-group-item,button.list-group-item{color:#555}a.list-group-item .list-group-item-heading,button.list-group-item .list-group-item-heading{color:#333}a.list-group-item:focus,a.list-group-item:hover,button.list-group-item:focus,button.list-group-item:hover{color:#555;text-decoration:none;background-color:#f5f5f5}button.list-group-item{width:100%;text-align:left}.list-group-item.disabled,.list-group-item.disabled:focus,.list-group-item.disabled:hover{color:#777;cursor:not-allowed;background-color:#eee}.list-group-item.disabled .list-group-item-heading,.list-group-item.disabled:focus .list-group-item-heading,.list-group-item.disabled:hover .list-group-item-heading{color:inherit}.list-group-item.disabled .list-group-item-text,.list-group-item.disabled:focus .list-group-item-text,.list-group-item.disabled:hover .list-group-item-text{color:#777}.list-group-item.active,.list-group-item.active:focus,.list-group-item.active:hover{z-index:2;color:#fff;background-color:#337ab7;border-color:#337ab7}.list-group-item.active .list-group-item-heading,.list-group-item.active .list-group-item-heading>.small,.list-group-item.active .list-group-item-heading>small,.list-group-item.active:focus .list-group-item-heading,.list-group-item.active:focus .list-group-item-heading>.small,.list-group-item.active:focus .list-group-item-heading>small,.list-group-item.active:hover .list-group-item-heading,.list-group-item.active:hover .list-group-item-heading>.small,.list-group-item.active:hover .list-group-item-heading>small{color:inherit}.list-group-item.active .list-group-item-text,.list-group-item.active:focus .list-group-item-text,.list-group-item.active:hover .list-group-item-text{color:#c7ddef}.list-group-item-success{color:#3c763d;background-color:#dff0d8}a.list-group-item-success,button.list-group-item-success{color:#3c763d}a.list-group-item-success .list-group-item-heading,button.list-group-item-success .list-group-item-heading{color:inherit}a.list-group-item-success:focus,a.list-group-item-success:hover,button.list-group-item-success:focus,button.list-group-item-success:hover{color:#3c763d;background-color:#d0e9c6}a.list-group-item-success.active,a.list-group-item-success.active:focus,a.list-group-item-success.active:hover,button.list-group-item-success.active,button.list-group-item-success.active:focus,button.list-group-item-success.active:hover{color:#fff;background-color:#3c763d;border-color:#3c763d}.list-group-item-info{color:#31708f;background-color:#d9edf7}a.list-group-item-info,button.list-group-item-info{color:#31708f}a.list-group-item-info .list-group-item-heading,button.list-group-item-info .list-group-item-heading{color:inherit}a.list-group-item-info:focus,a.list-group-item-info:hover,button.list-group-item-info:focus,button.list-group-item-info:hover{color:#31708f;background-color:#c4e3f3}a.list-group-item-info.active,a.list-group-item-info.active:focus,a.list-group-item-info.active:hover,button.list-group-item-info.active,button.list-group-item-info.active:focus,button.list-group-item-info.active:hover{color:#fff;background-color:#31708f;border-color:#31708f}.list-group-item-warning{color:#8a6d3b;background-color:#fcf8e3}a.list-group-item-warning,button.list-group-item-warning{color:#8a6d3b}a.list-group-item-warning .list-group-item-heading,button.list-group-item-warning .list-group-item-heading{color:inherit}a.list-group-item-warning:focus,a.list-group-item-warning:hover,button.list-group-item-warning:focus,button.list-group-item-warning:hover{color:#8a6d3b;background-color:#faf2cc}a.list-group-item-warning.active,a.list-group-item-warning.active:focus,a.list-group-item-warning.active:hover,button.list-group-item-warning.active,button.list-group-item-warning.active:focus,button.list-group-item-warning.active:hover{color:#fff;background-color:#8a6d3b;border-color:#8a6d3b}.list-group-item-danger{color:#a94442;background-color:#f2dede}a.list-group-item-danger,button.list-group-item-danger{color:#a94442}a.list-group-item-danger .list-group-item-heading,button.list-group-item-danger .list-group-item-heading{color:inherit}a.list-group-item-danger:focus,a.list-group-item-danger:hover,button.list-group-item-danger:focus,button.list-group-item-danger:hover{color:#a94442;background-color:#ebcccc}a.list-group-item-danger.active,a.list-group-item-danger.active:focus,a.list-group-item-danger.active:hover,button.list-group-item-danger.active,button.list-group-item-danger.active:focus,button.list-group-item-danger.active:hover{color:#fff;background-color:#a94442;border-color:#a94442}.list-group-item-heading{margin-top:0;margin-bottom:5px}.list-group-item-text{margin-bottom:0;line-height:1.3}.panel{margin-bottom:20px;background-color:#fff;border:1px solid transparent;border-radius:4px;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.05);box-shadow:0 1px 1px rgba(0,0,0,.05)}.panel-body{padding:15px}.panel-heading{padding:10px 15px;border-bottom:1px solid transparent;border-top-left-radius:3px;border-top-right-radius:3px}.panel-heading>.dropdown .dropdown-toggle{color:inherit}.panel-title{margin-top:0;margin-bottom:0;font-size:16px;color:inherit}.panel-title>.small,.panel-title>.small>a,.panel-title>a,.panel-title>small,.panel-title>small>a{color:inherit}.panel-footer{padding:10px 15px;background-color:#f5f5f5;border-top:1px solid #ddd;border-bottom-right-radius:3px;border-bottom-left-radius:3px}.panel>.list-group,.panel>.panel-collapse>.list-group{margin-bottom:0}.panel>.list-group .list-group-item,.panel>.panel-collapse>.list-group .list-group-item{border-width:1px 0;border-radius:0}.panel>.list-group:first-child .list-group-item:first-child,.panel>.panel-collapse>.list-group:first-child .list-group-item:first-child{border-top:0;border-top-left-radius:3px;border-top-right-radius:3px}.panel>.list-group:last-child .list-group-item:last-child,.panel>.panel-collapse>.list-group:last-child .list-group-item:last-child{border-bottom:0;border-bottom-right-radius:3px;border-bottom-left-radius:3px}.panel>.panel-heading+.panel-collapse>.list-group .list-group-item:first-child{border-top-left-radius:0;border-top-right-radius:0}.panel-heading+.list-group .list-group-item:first-child{border-top-width:0}.list-group+.panel-footer{border-top-width:0}.panel>.panel-collapse>.table,.panel>.table,.panel>.table-responsive>.table{margin-bottom:0}.panel>.panel-collapse>.table caption,.panel>.table caption,.panel>.table-responsive>.table caption{padding-right:15px;padding-left:15px}.panel>.table-responsive:first-child>.table:first-child,.panel>.table:first-child{border-top-left-radius:3px;border-top-right-radius:3px}.panel>.table-responsive:first-child>.table:first-child>tbody:first-child>tr:first-child,.panel>.table-responsive:first-child>.table:first-child>thead:first-child>tr:first-child,.panel>.table:first-child>tbody:first-child>tr:first-child,.panel>.table:first-child>thead:first-child>tr:first-child{border-top-left-radius:3px;border-top-right-radius:3px}.panel>.table-responsive:first-child>.table:first-child>tbody:first-child>tr:first-child td:first-child,.panel>.table-responsive:first-child>.table:first-child>tbody:first-child>tr:first-child th:first-child,.panel>.table-responsive:first-child>.table:first-child>thead:first-child>tr:first-child td:first-child,.panel>.table-responsive:first-child>.table:first-child>thead:first-child>tr:first-child th:first-child,.panel>.table:first-child>tbody:first-child>tr:first-child td:first-child,.panel>.table:first-child>tbody:first-child>tr:first-child th:first-child,.panel>.table:first-child>thead:first-child>tr:first-child td:first-child,.panel>.table:first-child>thead:first-child>tr:first-child th:first-child{border-top-left-radius:3px}.panel>.table-responsive:first-child>.table:first-child>tbody:first-child>tr:first-child td:last-child,.panel>.table-responsive:first-child>.table:first-child>tbody:first-child>tr:first-child th:last-child,.panel>.table-responsive:first-child>.table:first-child>thead:first-child>tr:first-child td:last-child,.panel>.table-responsive:first-child>.table:first-child>thead:first-child>tr:first-child th:last-child,.panel>.table:first-child>tbody:first-child>tr:first-child td:last-child,.panel>.table:first-child>tbody:first-child>tr:first-child th:last-child,.panel>.table:first-child>thead:first-child>tr:first-child td:last-child,.panel>.table:first-child>thead:first-child>tr:first-child th:last-child{border-top-right-radius:3px}.panel>.table-responsive:last-child>.table:last-child,.panel>.table:last-child{border-bottom-right-radius:3px;border-bottom-left-radius:3px}.panel>.table-responsive:last-child>.table:last-child>tbody:last-child>tr:last-child,.panel>.table-responsive:last-child>.table:last-child>tfoot:last-child>tr:last-child,.panel>.table:last-child>tbody:last-child>tr:last-child,.panel>.table:last-child>tfoot:last-child>tr:last-child{border-bottom-right-radius:3px;border-bottom-left-radius:3px}.panel>.table-responsive:last-child>.table:last-child>tbody:last-child>tr:last-child td:first-child,.panel>.table-responsive:last-child>.table:last-child>tbody:last-child>tr:last-child th:first-child,.panel>.table-responsive:last-child>.table:last-child>tfoot:last-child>tr:last-child td:first-child,.panel>.table-responsive:last-child>.table:last-child>tfoot:last-child>tr:last-child th:first-child,.panel>.table:last-child>tbody:last-child>tr:last-child td:first-child,.panel>.table:last-child>tbody:last-child>tr:last-child th:first-child,.panel>.table:last-child>tfoot:last-child>tr:last-child td:first-child,.panel>.table:last-child>tfoot:last-child>tr:last-child th:first-child{border-bottom-left-radius:3px}.panel>.table-responsive:last-child>.table:last-child>tbody:last-child>tr:last-child td:last-child,.panel>.table-responsive:last-child>.table:last-child>tbody:last-child>tr:last-child th:last-child,.panel>.table-responsive:last-child>.table:last-child>tfoot:last-child>tr:last-child td:last-child,.panel>.table-responsive:last-child>.table:last-child>tfoot:last-child>tr:last-child th:last-child,.panel>.table:last-child>tbody:last-child>tr:last-child td:last-child,.panel>.table:last-child>tbody:last-child>tr:last-child th:last-child,.panel>.table:last-child>tfoot:last-child>tr:last-child td:last-child,.panel>.table:last-child>tfoot:last-child>tr:last-child th:last-child{border-bottom-right-radius:3px}.panel>.panel-body+.table,.panel>.panel-body+.table-responsive,.panel>.table+.panel-body,.panel>.table-responsive+.panel-body{border-top:1px solid #ddd}.panel>.table>tbody:first-child>tr:first-child td,.panel>.table>tbody:first-child>tr:first-child th{border-top:0}.panel>.table-bordered,.panel>.table-responsive>.table-bordered{border:0}.panel>.table-bordered>tbody>tr>td:first-child,.panel>.table-bordered>tbody>tr>th:first-child,.panel>.table-bordered>tfoot>tr>td:first-child,.panel>.table-bordered>tfoot>tr>th:first-child,.panel>.table-bordered>thead>tr>td:first-child,.panel>.table-bordered>thead>tr>th:first-child,.panel>.table-responsive>.table-bordered>tbody>tr>td:first-child,.panel>.table-responsive>.table-bordered>tbody>tr>th:first-child,.panel>.table-responsive>.table-bordered>tfoot>tr>td:first-child,.panel>.table-responsive>.table-bordered>tfoot>tr>th:first-child,.panel>.table-responsive>.table-bordered>thead>tr>td:first-child,.panel>.table-responsive>.table-bordered>thead>tr>th:first-child{border-left:0}.panel>.table-bordered>tbody>tr>td:last-child,.panel>.table-bordered>tbody>tr>th:last-child,.panel>.table-bordered>tfoot>tr>td:last-child,.panel>.table-bordered>tfoot>tr>th:last-child,.panel>.table-bordered>thead>tr>td:last-child,.panel>.table-bordered>thead>tr>th:last-child,.panel>.table-responsive>.table-bordered>tbody>tr>td:last-child,.panel>.table-responsive>.table-bordered>tbody>tr>th:last-child,.panel>.table-responsive>.table-bordered>tfoot>tr>td:last-child,.panel>.table-responsive>.table-bordered>tfoot>tr>th:last-child,.panel>.table-responsive>.table-bordered>thead>tr>td:last-child,.panel>.table-responsive>.table-bordered>thead>tr>th:last-child{border-right:0}.panel>.table-bordered>tbody>tr:first-child>td,.panel>.table-bordered>tbody>tr:first-child>th,.panel>.table-bordered>thead>tr:first-child>td,.panel>.table-bordered>thead>tr:first-child>th,.panel>.table-responsive>.table-bordered>tbody>tr:first-child>td,.panel>.table-responsive>.table-bordered>tbody>tr:first-child>th,.panel>.table-responsive>.table-bordered>thead>tr:first-child>td,.panel>.table-responsive>.table-bordered>thead>tr:first-child>th{border-bottom:0}.panel>.table-bordered>tbody>tr:last-child>td,.panel>.table-bordered>tbody>tr:last-child>th,.panel>.table-bordered>tfoot>tr:last-child>td,.panel>.table-bordered>tfoot>tr:last-child>th,.panel>.table-responsive>.table-bordered>tbody>tr:last-child>td,.panel>.table-responsive>.table-bordered>tbody>tr:last-child>th,.panel>.table-responsive>.table-bordered>tfoot>tr:last-child>td,.panel>.table-responsive>.table-bordered>tfoot>tr:last-child>th{border-bottom:0}.panel>.table-responsive{margin-bottom:0;border:0}.panel-group{margin-bottom:20px}.panel-group .panel{margin-bottom:0;border-radius:4px}.panel-group .panel+.panel{margin-top:5px}.panel-group .panel-heading{border-bottom:0}.panel-group .panel-heading+.panel-collapse>.list-group,.panel-group .panel-heading+.panel-collapse>.panel-body{border-top:1px solid #ddd}.panel-group .panel-footer{border-top:0}.panel-group .panel-footer+.panel-collapse .panel-body{border-bottom:1px solid #ddd}.panel-default{border-color:#ddd}.panel-default>.panel-heading{color:#333;background-color:#f5f5f5;border-color:#ddd}.panel-default>.panel-heading+.panel-collapse>.panel-body{border-top-color:#ddd}.panel-default>.panel-heading .badge{color:#f5f5f5;background-color:#333}.panel-default>.panel-footer+.panel-collapse>.panel-body{border-bottom-color:#ddd}.panel-primary{border-color:#337ab7}.panel-primary>.panel-heading{color:#fff;background-color:#337ab7;border-color:#337ab7}.panel-primary>.panel-heading+.panel-collapse>.panel-body{border-top-color:#337ab7}.panel-primary>.panel-heading .badge{color:#337ab7;background-color:#fff}.panel-primary>.panel-footer+.panel-collapse>.panel-body{border-bottom-color:#337ab7}.panel-success{border-color:#d6e9c6}.panel-success>.panel-heading{color:#3c763d;background-color:#dff0d8;border-color:#d6e9c6}.panel-success>.panel-heading+.panel-collapse>.panel-body{border-top-color:#d6e9c6}.panel-success>.panel-heading .badge{color:#dff0d8;background-color:#3c763d}.panel-success>.panel-footer+.panel-collapse>.panel-body{border-bottom-color:#d6e9c6}.panel-info{border-color:#bce8f1}.panel-info>.panel-heading{color:#31708f;background-color:#d9edf7;border-color:#bce8f1}.panel-info>.panel-heading+.panel-collapse>.panel-body{border-top-color:#bce8f1}.panel-info>.panel-heading .badge{color:#d9edf7;background-color:#31708f}.panel-info>.panel-footer+.panel-collapse>.panel-body{border-bottom-color:#bce8f1}.panel-warning{border-color:#faebcc}.panel-warning>.panel-heading{color:#8a6d3b;background-color:#fcf8e3;border-color:#faebcc}.panel-warning>.panel-heading+.panel-collapse>.panel-body{border-top-color:#faebcc}.panel-warning>.panel-heading .badge{color:#fcf8e3;background-color:#8a6d3b}.panel-warning>.panel-footer+.panel-collapse>.panel-body{border-bottom-color:#faebcc}.panel-danger{border-color:#ebccd1}.panel-danger>.panel-heading{color:#a94442;background-color:#f2dede;border-color:#ebccd1}.panel-danger>.panel-heading+.panel-collapse>.panel-body{border-top-color:#ebccd1}.panel-danger>.panel-heading .badge{color:#f2dede;background-color:#a94442}.panel-danger>.panel-footer+.panel-collapse>.panel-body{border-bottom-color:#ebccd1}.embed-responsive{position:relative;display:block;height:0;padding:0;overflow:hidden}.embed-responsive .embed-responsive-item,.embed-responsive embed,.embed-responsive iframe,.embed-responsive object,.embed-responsive video{position:absolute;top:0;bottom:0;left:0;width:100%;height:100%;border:0}.embed-responsive-16by9{padding-bottom:56.25%}.embed-responsive-4by3{padding-bottom:75%}.well{min-height:20px;padding:19px;margin-bottom:20px;background-color:#f5f5f5;border:1px solid #e3e3e3;border-radius:4px;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.05);box-shadow:inset 0 1px 1px rgba(0,0,0,.05)}.well blockquote{border-color:#ddd;border-color:rgba(0,0,0,.15)}.well-lg{padding:24px;border-radius:6px}.well-sm{padding:9px;border-radius:3px}.close{float:right;font-size:21px;font-weight:700;line-height:1;color:#000;text-shadow:0 1px 0 #fff;filter:alpha(opacity=20);opacity:.2}.close:focus,.close:hover{color:#000;text-decoration:none;cursor:pointer;filter:alpha(opacity=50);opacity:.5}button.close{-webkit-appearance:none;padding:0;cursor:pointer;background:0 0;border:0}.modal-open{overflow:hidden}.modal{position:fixed;top:0;right:0;bottom:0;left:0;z-index:1050;display:none;overflow:hidden;-webkit-overflow-scrolling:touch;outline:0}.modal.fade .modal-dialog{-webkit-transition:-webkit-transform .3s ease-out;-o-transition:-o-transform .3s ease-out;transition:transform .3s ease-out;-webkit-transform:translate(0,-25%);-ms-transform:translate(0,-25%);-o-transform:translate(0,-25%);transform:translate(0,-25%)}.modal.in .modal-dialog{-webkit-transform:translate(0,0);-ms-transform:translate(0,0);-o-transform:translate(0,0);transform:translate(0,0)}.modal-open .modal{overflow-x:hidden;overflow-y:auto}.modal-dialog{position:relative;width:auto;margin:10px}.modal-content{position:relative;background-color:#fff;-webkit-background-clip:padding-box;background-clip:padding-box;border:1px solid #999;border:1px solid rgba(0,0,0,.2);border-radius:6px;outline:0;-webkit-box-shadow:0 3px 9px rgba(0,0,0,.5);box-shadow:0 3px 9px rgba(0,0,0,.5)}.modal-backdrop{position:fixed;top:0;right:0;bottom:0;left:0;z-index:1040;background-color:#000}.modal-backdrop.fade{filter:alpha(opacity=0);opacity:0}.modal-backdrop.in{filter:alpha(opacity=50);opacity:.5}.modal-header{padding:15px;border-bottom:1px solid #e5e5e5}.modal-header .close{margin-top:-2px}.modal-title{margin:0;line-height:1.42857143}.modal-body{position:relative;padding:15px}.modal-footer{padding:15px;text-align:right;border-top:1px solid #e5e5e5}.modal-footer .btn+.btn{margin-bottom:0;margin-left:5px}.modal-footer .btn-group .btn+.btn{margin-left:-1px}.modal-footer .btn-block+.btn-block{margin-left:0}.modal-scrollbar-measure{position:absolute;top:-9999px;width:50px;height:50px;overflow:scroll}@media (min-width:768px){.modal-dialog{width:600px;margin:30px auto}.modal-content{-webkit-box-shadow:0 5px 15px rgba(0,0,0,.5);box-shadow:0 5px 15px rgba(0,0,0,.5)}.modal-sm{width:300px}}@media (min-width:992px){.modal-lg{width:900px}}.tooltip{position:absolute;z-index:1070;display:block;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:12px;font-style:normal;font-weight:400;line-height:1.42857143;text-align:left;text-align:start;text-decoration:none;text-shadow:none;text-transform:none;letter-spacing:normal;word-break:normal;word-spacing:normal;word-wrap:normal;white-space:normal;filter:alpha(opacity=0);opacity:0;line-break:auto}.tooltip.in{filter:alpha(opacity=90);opacity:.9}.tooltip.top{padding:5px 0;margin-top:-3px}.tooltip.right{padding:0 5px;margin-left:3px}.tooltip.bottom{padding:5px 0;margin-top:3px}.tooltip.left{padding:0 5px;margin-left:-3px}.tooltip-inner{max-width:200px;padding:3px 8px;color:#fff;text-align:center;background-color:#000;border-radius:4px}.tooltip-arrow{position:absolute;width:0;height:0;border-color:transparent;border-style:solid}.tooltip.top .tooltip-arrow{bottom:0;left:50%;margin-left:-5px;border-width:5px 5px 0;border-top-color:#000}.tooltip.top-left .tooltip-arrow{right:5px;bottom:0;margin-bottom:-5px;border-width:5px 5px 0;border-top-color:#000}.tooltip.top-right .tooltip-arrow{bottom:0;left:5px;margin-bottom:-5px;border-width:5px 5px 0;border-top-color:#000}.tooltip.right .tooltip-arrow{top:50%;left:0;margin-top:-5px;border-width:5px 5px 5px 0;border-right-color:#000}.tooltip.left .tooltip-arrow{top:50%;right:0;margin-top:-5px;border-width:5px 0 5px 5px;border-left-color:#000}.tooltip.bottom .tooltip-arrow{top:0;left:50%;margin-left:-5px;border-width:0 5px 5px;border-bottom-color:#000}.tooltip.bottom-left .tooltip-arrow{top:0;right:5px;margin-top:-5px;border-width:0 5px 5px;border-bottom-color:#000}.tooltip.bottom-right .tooltip-arrow{top:0;left:5px;margin-top:-5px;border-width:0 5px 5px;border-bottom-color:#000}.popover{position:absolute;top:0;left:0;z-index:1060;display:none;max-width:276px;padding:1px;font-family:"Helvetica Neue",Helvetica,Arial,sans-serif;font-size:14px;font-style:normal;font-weight:400;line-height:1.42857143;text-align:left;text-align:start;text-decoration:none;text-shadow:none;text-transform:none;letter-spacing:normal;word-break:normal;word-spacing:normal;word-wrap:normal;white-space:normal;background-color:#fff;-webkit-background-clip:padding-box;background-clip:padding-box;border:1px solid #ccc;border:1px solid rgba(0,0,0,.2);border-radius:6px;-webkit-box-shadow:0 5px 10px rgba(0,0,0,.2);box-shadow:0 5px 10px rgba(0,0,0,.2);line-break:auto}.popover.top{margin-top:-10px}.popover.right{margin-left:10px}.popover.bottom{margin-top:10px}.popover.left{margin-left:-10px}.popover-title{padding:8px 14px;margin:0;font-size:14px;background-color:#f7f7f7;border-bottom:1px solid #ebebeb;border-radius:5px 5px 0 0}.popover-content{padding:9px 14px}.popover>.arrow,.popover>.arrow:after{position:absolute;display:block;width:0;height:0;border-color:transparent;border-style:solid}.popover>.arrow{border-width:11px}.popover>.arrow:after{content:"";border-width:10px}.popover.top>.arrow{bottom:-11px;left:50%;margin-left:-11px;border-top-color:#999;border-top-color:rgba(0,0,0,.25);border-bottom-width:0}.popover.top>.arrow:after{bottom:1px;margin-left:-10px;content:" ";border-top-color:#fff;border-bottom-width:0}.popover.right>.arrow{top:50%;left:-11px;margin-top:-11px;border-right-color:#999;border-right-color:rgba(0,0,0,.25);border-left-width:0}.popover.right>.arrow:after{bottom:-10px;left:1px;content:" ";border-right-color:#fff;border-left-width:0}.popover.bottom>.arrow{top:-11px;left:50%;margin-left:-11px;border-top-width:0;border-bottom-color:#999;border-bottom-color:rgba(0,0,0,.25)}.popover.bottom>.arrow:after{top:1px;margin-left:-10px;content:" ";border-top-width:0;border-bottom-color:#fff}.popover.left>.arrow{top:50%;right:-11px;margin-top:-11px;border-right-width:0;border-left-color:#999;border-left-color:rgba(0,0,0,.25)}.popover.left>.arrow:after{right:1px;bottom:-10px;content:" ";border-right-width:0;border-left-color:#fff}.carousel{position:relative}.carousel-inner{position:relative;width:100%;overflow:hidden}.carousel-inner>.item{position:relative;display:none;-webkit-transition:.6s ease-in-out left;-o-transition:.6s ease-in-out left;transition:.6s ease-in-out left}.carousel-inner>.item>a>img,.carousel-inner>.item>img{line-height:1}@media all and (transform-3d),(-webkit-transform-3d){.carousel-inner>.item{-webkit-transition:-webkit-transform .6s ease-in-out;-o-transition:-o-transform .6s ease-in-out;transition:transform .6s ease-in-out;-webkit-backface-visibility:hidden;backface-visibility:hidden;-webkit-perspective:1000px;perspective:1000px}.carousel-inner>.item.active.right,.carousel-inner>.item.next{left:0;-webkit-transform:translate3d(100%,0,0);transform:translate3d(100%,0,0)}.carousel-inner>.item.active.left,.carousel-inner>.item.prev{left:0;-webkit-transform:translate3d(-100%,0,0);transform:translate3d(-100%,0,0)}.carousel-inner>.item.active,.carousel-inner>.item.next.left,.carousel-inner>.item.prev.right{left:0;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0)}}.carousel-inner>.active,.carousel-inner>.next,.carousel-inner>.prev{display:block}.carousel-inner>.active{left:0}.carousel-inner>.next,.carousel-inner>.prev{position:absolute;top:0;width:100%}.carousel-inner>.next{left:100%}.carousel-inner>.prev{left:-100%}.carousel-inner>.next.left,.carousel-inner>.prev.right{left:0}.carousel-inner>.active.left{left:-100%}.carousel-inner>.active.right{left:100%}.carousel-control{position:absolute;top:0;bottom:0;left:0;width:15%;font-size:20px;color:#fff;text-align:center;text-shadow:0 1px 2px rgba(0,0,0,.6);background-color:rgba(0,0,0,0);filter:alpha(opacity=50);opacity:.5}.carousel-control.left{background-image:-webkit-linear-gradient(left,rgba(0,0,0,.5) 0,rgba(0,0,0,.0001) 100%);background-image:-o-linear-gradient(left,rgba(0,0,0,.5) 0,rgba(0,0,0,.0001) 100%);background-image:-webkit-gradient(linear,left top,right top,from(rgba(0,0,0,.5)),to(rgba(0,0,0,.0001)));background-image:linear-gradient(to right,rgba(0,0,0,.5) 0,rgba(0,0,0,.0001) 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#80000000', endColorstr='#00000000', GradientType=1);background-repeat:repeat-x}.carousel-control.right{right:0;left:auto;background-image:-webkit-linear-gradient(left,rgba(0,0,0,.0001) 0,rgba(0,0,0,.5) 100%);background-image:-o-linear-gradient(left,rgba(0,0,0,.0001) 0,rgba(0,0,0,.5) 100%);background-image:-webkit-gradient(linear,left top,right top,from(rgba(0,0,0,.0001)),to(rgba(0,0,0,.5)));background-image:linear-gradient(to right,rgba(0,0,0,.0001) 0,rgba(0,0,0,.5) 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#00000000', endColorstr='#80000000', GradientType=1);background-repeat:repeat-x}.carousel-control:focus,.carousel-control:hover{color:#fff;text-decoration:none;filter:alpha(opacity=90);outline:0;opacity:.9}.carousel-control .glyphicon-chevron-left,.carousel-control .glyphicon-chevron-right,.carousel-control .icon-next,.carousel-control .icon-prev{position:absolute;top:50%;z-index:5;display:inline-block;margin-top:-10px}.carousel-control .glyphicon-chevron-left,.carousel-control .icon-prev{left:50%;margin-left:-10px}.carousel-control .glyphicon-chevron-right,.carousel-control .icon-next{right:50%;margin-right:-10px}.carousel-control .icon-next,.carousel-control .icon-prev{width:20px;height:20px;font-family:serif;line-height:1}.carousel-control .icon-prev:before{content:'\2039'}.carousel-control .icon-next:before{content:'\203a'}.carousel-indicators{position:absolute;bottom:10px;left:50%;z-index:15;width:60%;padding-left:0;margin-left:-30%;text-align:center;list-style:none}.carousel-indicators li{display:inline-block;width:10px;height:10px;margin:1px;text-indent:-999px;cursor:pointer;background-color:#000\9;background-color:rgba(0,0,0,0);border:1px solid #fff;border-radius:10px}.carousel-indicators .active{width:12px;height:12px;margin:0;background-color:#fff}.carousel-caption{position:absolute;right:15%;bottom:20px;left:15%;z-index:10;padding-top:20px;padding-bottom:20px;color:#fff;text-align:center;text-shadow:0 1px 2px rgba(0,0,0,.6)}.carousel-caption .btn{text-shadow:none}@media screen and (min-width:768px){.carousel-control .glyphicon-chevron-left,.carousel-control .glyphicon-chevron-right,.carousel-control .icon-next,.carousel-control .icon-prev{width:30px;height:30px;margin-top:-10px;font-size:30px}.carousel-control .glyphicon-chevron-left,.carousel-control .icon-prev{margin-left:-10px}.carousel-control .glyphicon-chevron-right,.carousel-control .icon-next{margin-right:-10px}.carousel-caption{right:20%;left:20%;padding-bottom:30px}.carousel-indicators{bottom:20px}}.btn-group-vertical>.btn-group:after,.btn-group-vertical>.btn-group:before,.btn-toolbar:after,.btn-toolbar:before,.clearfix:after,.clearfix:before,.container-fluid:after,.container-fluid:before,.container:after,.container:before,.dl-horizontal dd:after,.dl-horizontal dd:before,.form-horizontal .form-group:after,.form-horizontal .form-group:before,.modal-footer:after,.modal-footer:before,.modal-header:after,.modal-header:before,.nav:after,.nav:before,.navbar-collapse:after,.navbar-collapse:before,.navbar-header:after,.navbar-header:before,.navbar:after,.navbar:before,.pager:after,.pager:before,.panel-body:after,.panel-body:before,.row:after,.row:before{display:table;content:" "}.btn-group-vertical>.btn-group:after,.btn-toolbar:after,.clearfix:after,.container-fluid:after,.container:after,.dl-horizontal dd:after,.form-horizontal .form-group:after,.modal-footer:after,.modal-header:after,.nav:after,.navbar-collapse:after,.navbar-header:after,.navbar:after,.pager:after,.panel-body:after,.row:after{clear:both}.center-block{display:block;margin-right:auto;margin-left:auto}.pull-right{float:right!important}.pull-left{float:left!important}.hide{display:none!important}.show{display:block!important}.invisible{visibility:hidden}.text-hide{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}.hidden{display:none!important}.affix{position:fixed}@-ms-viewport{width:device-width}.visible-lg,.visible-md,.visible-sm,.visible-xs{display:none!important}.visible-lg-block,.visible-lg-inline,.visible-lg-inline-block,.visible-md-block,.visible-md-inline,.visible-md-inline-block,.visible-sm-block,.visible-sm-inline,.visible-sm-inline-block,.visible-xs-block,.visible-xs-inline,.visible-xs-inline-block{display:none!important}@media (max-width:767px){.visible-xs{display:block!important}table.visible-xs{display:table!important}tr.visible-xs{display:table-row!important}td.visible-xs,th.visible-xs{display:table-cell!important}}@media (max-width:767px){.visible-xs-block{display:block!important}}@media (max-width:767px){.visible-xs-inline{display:inline!important}}@media (max-width:767px){.visible-xs-inline-block{display:inline-block!important}}@media (min-width:768px) and (max-width:991px){.visible-sm{display:block!important}table.visible-sm{display:table!important}tr.visible-sm{display:table-row!important}td.visible-sm,th.visible-sm{display:table-cell!important}}@media (min-width:768px) and (max-width:991px){.visible-sm-block{display:block!important}}@media (min-width:768px) and (max-width:991px){.visible-sm-inline{display:inline!important}}@media (min-width:768px) and (max-width:991px){.visible-sm-inline-block{display:inline-block!important}}@media (min-width:992px) and (max-width:1199px){.visible-md{display:block!important}table.visible-md{display:table!important}tr.visible-md{display:table-row!important}td.visible-md,th.visible-md{display:table-cell!important}}@media (min-width:992px) and (max-width:1199px){.visible-md-block{display:block!important}}@media (min-width:992px) and (max-width:1199px){.visible-md-inline{display:inline!important}}@media (min-width:992px) and (max-width:1199px){.visible-md-inline-block{display:inline-block!important}}@media (min-width:1200px){.visible-lg{display:block!important}table.visible-lg{display:table!important}tr.visible-lg{display:table-row!important}td.visible-lg,th.visible-lg{display:table-cell!important}}@media (min-width:1200px){.visible-lg-block{display:block!important}}@media (min-width:1200px){.visible-lg-inline{display:inline!important}}@media (min-width:1200px){.visible-lg-inline-block{display:inline-block!important}}@media (max-width:767px){.hidden-xs{display:none!important}}@media (min-width:768px) and (max-width:991px){.hidden-sm{display:none!important}}@media (min-width:992px) and (max-width:1199px){.hidden-md{display:none!important}}@media (min-width:1200px){.hidden-lg{display:none!important}}.visible-print{display:none!important}@media print{.visible-print{display:block!important}table.visible-print{display:table!important}tr.visible-print{display:table-row!important}td.visible-print,th.visible-print{display:table-cell!important}}.visible-print-block{display:none!important}@media print{.visible-print-block{display:block!important}}.visible-print-inline{display:none!important}@media print{.visible-print-inline{display:inline!important}}.visible-print-inline-block{display:none!important}@media print{.visible-print-inline-block{display:inline-block!important}}@media print{.hidden-print{display:none!important}} +/*# sourceMappingURL=bootstrap.min.css.map */ \ No newline at end of file diff --git a/resources/css/fa.min.css b/resources/css/fa.min.css new file mode 100644 index 0000000000..cec61244c6 --- /dev/null +++ b/resources/css/fa.min.css @@ -0,0 +1,407 @@ +@font-face { + font-family: 'fa'; + src: url(data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAAFxQAAsAAAAAXAQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABPUy8yAAABCAAAAGAAAABgDxIPa2NtYXAAAAFoAAACVAAAAlQ99AGXZ2FzcAAAA7wAAAAIAAAACAAAABBnbHlmAAADxAAAVBQAAFQUfRTLI2hlYWQAAFfYAAAANgAAADYfiLedaGhlYQAAWBAAAAAkAAAAJAhUBMBobXR4AABYNAAAAbQAAAG0b9oDkmxvY2EAAFnoAAAA3AAAANxLxmGqbWF4cAAAWsQAAAAgAAAAIAB4AVduYW1lAABa5AAAAUoAAAFKIhWTsnBvc3QAAFwwAAAAIAAAACAAAwAAAAMDbwGQAAUAAAKZAswAAACPApkCzAAAAesAMwEJAAAAAAAAAAAAAAAAAAAAARAAAAAAAAAAAAAAAAAAAAAAQAAA8tIDwP/AAEADwABAAAAAAQAAAAAAAAAAAAAAIAAAAAAAAwAAAAMAAAAcAAEAAwAAABwAAwABAAAAHAAEAjgAAACKAIAABgAKAAEAIOoL8AfwDfAR8BfwGfAe8CLwLPA68EHwRPBG8E3wVPBa8GfwavBx8HjwgPCF8I7wlvCj8LDwsvDB8MnwzvDa8N7w5PDz8PbxAfEF8QjxCvEM8RHxIfEm8SjxMvFC8UTxTPFc8WXxoPHJ8c7x2/He8ffx/vIA8gXyaPKM8pLynPK38tL//f//AAAAAAAg6gvwAvAJ8BHwE/AZ8B3wIfAr8DrwQPBE8EbwS/BT8FnwZ/Bp8HHwd/CA8IXwjvCW8KLwsPCy8MDwyfDO8Nfw3PDk8PPw9vEA8QTxCPEK8QzxEPEg8SbxKPEy8UHxRPFM8VzxZPGg8cnxzvHb8d7x9vH+8gDyBPJo8ovykvKc8rby0v/9//8AAf/jFfkQAxACD/8P/g/9D/oP+A/wD+MP3g/cD9sP1w/SD84Pwg/BD7sPtg+vD6sPow+cD5EPhQ+ED3cPcA9sD2QPYw9eD1APTg9FD0MPQQ9ADz8PPA8uDyoPKQ8gDxIPEQ8KDvsO9A66DpIOjg6CDoAOaQ5jDmIOXw39DdsN1g3NDbQNmgADAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAB//8ADwABAAAAAAAAAAAAAgAANzkBAAAAAAEAAAAAAAAAAAACAAA3OQEAAAAAAQAAAAAAAAAAAAIAADc5AQAAAAABAAABQAQAAkAADwAAExUUFjMhMjY9ATQmIyEiBgATDQPADRMTDfxADRMCIMANExMNwA0TEwAAAAIAAP+3A7cDbgAbAEIAAAE0Jy4BJyYjIgcOAQcGFRQXHgEXFjMyNz4BNzYBFAYjIiYvAQ4BIyInLgEnJjU0Nz4BNzYzMhceARcWFRQGBxceARUCkhQURi4vNTUuL0UVFBQVRS8uNTUvLkYUFAElKx4PGwrEMnU9U0lKbR8gIB9tSklTVElJbSAgJSLECgsB2zUvL0UUFBQURS8vNTUuL0UUFRUURS8u/loeKwsLwyMkIB9uSUlTVElJbh8gIB9uSUlUPHUzxAkbDwAAAAMAAAAABAADJQAcADcARwAAJREOAQcOAQcOASsBIiYnLgEnLgEnERQWMyEyNjURNCYjISIGFRQWFx4BFx4BOwEyNjc+ATc+ATU3ERQGIyEiJjURNDYzITIWA7cJFAs9ejwgTywCLE8gPHo9CxQJCwcDSgcLAhD8tgcLLiY6cjkXSB4CHkgXOXI6HDhJNiX8tiU2NiUDSiU2WwG3ChMIMGAyGzU1GzJgMAgTCv5JBwsLBwJZCxwLBzFTHi1bLRM6OhMtWy0WUyQV/ZIlNjYlAm4mNjYAAQAAAAAEAANuACoAACUiJicBJicuAScmNTQ3PgE3NjMyFhc+ATMyFx4BFxYVFAcOAQcGBwEOASMCAAcNBf6bARUVMBMUExJHMjNAS4IiIoJLQDMyRxITFBMxFBUC/pwFDQcABQUBWAIVFUUuLjM/MjFFEhNaIiJaExJFMTI/My4uRhUVAv6pBQUAAAABAAAAGgO3A6UALgAAARQGDwETHAEVFAYjIiYnJQUOASMiJjU0NjUTJy4BNTQ2NyUTPgEzMhYXEwUeARUDtwkGzzELDAYMBf7//wAGCwYMDAEx0AUJFQsBH4AEDwkKDwOBAR8KFgJFCA4Fy/7jAwYDCxEEA4aGAwQRCwMGAwEdywUOCA0MASoBBAgQEAj+/CoBDA0AAgAAABoDtwOlAAkAOAAAATcvAQ8BFwc3FwEUBg8BExwBFRQGIyImJyUFDgEjIiY1NDY1EycuATU0NjclEz4BMzIWFxMFHgEVAoqv8mxs8a8q2NgBBAkGzzELDAYMBf7//wAGCwYMDAEx0AUJFQsBH4AEDwkKDwOBAR8KFgF5qiPb2yOq8HFxAbwIDgXL/uMDBgMLEQQDhoYDBBELAwYDAR3LBQ4IDQwBKgEECBAQCP78KgEMDQAAAAIAAAAAAtsDbgAbADcAACUUBiMhIiY1NDc+ATc2Mx4BMzI2NzIXHgEXFhUDFAcOAQcGIyInLgEnJjU0Nz4BNzYzMhceARcWAttHMv4YMkgICColJDgjWzU0XCM4JCQqCAiSERE8KCgtLigoOxESEhE7KCguLSgoPBERlz5ZWT45OTpdHh0hKCghHR5dOjk5AfstKCg8ERERETwoKC0uKCg7ERISETsoKAAAAAAEAAAASQO3A24AEAAhADEAQQAAARUUBiMhIiY9ATQ2MyEyFhURFRQGIyEiJj0BNDYzITIWFQEVFAYjISImPQE0NjMhMhYRFRQGIyEiJj0BNDYzITIWAbcrHv7bHisrHgElHisrHv7bHisrHgElHisCACse/tseKyseASUeKyse/tseKyseASUeKwFu3B4rKx7cHisrHgG33B4rKx7cHisrHv5J3B4rKx7cHisrAZncHisrHtweKysACQAAAEkEAANuAA8AHwAvAD8ATwBfAG8AfwCPAAAlFRQGKwEiJj0BNDY7ATIWERUUBisBIiY9ATQ2OwEyFgEVFAYrASImPQE0NjsBMhYBFRQGKwEiJj0BNDY7ATIWARUUBisBIiY9ATQ2OwEyFgEVFAYrASImPQE0NjsBMhYBFRQGKwEiJj0BNDY7ATIWARUUBisBIiY9ATQ2OwEyFhEVFAYrASImPQE0NjsBMhYBJSEWtxcgIBe3FiEhFrcXICAXtxYhAW0gF7YXICAXthcg/pMhFrcXICAXtxYhAW0gF7YXICAXthcgAW4gF7cWISEWtxcg/pIgF7YXICAXthcgAW4gF7cWISEWtxcgIBe3FiEhFrcXIO5uFyAgF24WISEBDm0XICAXbRcgIP7FbhcgIBduFiEhAjNuFyAgF24XICD+xG0XICAXbRcgIP7FbhcgIBduFiEhAjNuFyAgF24XICD+xG0XICAXbRcgIAEObhcgIBduFyAgAAYAAABJBAADbgAPAB8ALwA/AE8AXwAAJRUUBisBIiY9ATQ2OwEyFhEVFAYrASImPQE0NjsBMhYBFRQGIyEiJj0BNDYzITIWARUUBisBIiY9ATQ2OwEyFgEVFAYjISImPQE0NjMhMhYRFRQGIyEiJj0BNDYzITIWASUhFrcXICAXtxYhIRa3FyAgF7cWIQLbIBf93BcgIBcCJBcg/SUhFrcXICAXtxYhAtsgF/3cFyAgFwIkFyAgF/3cFyAgFwIkFyDubhcgIBduFiEhAQ5tFyAgF20XICD+xW4XICAXbhYhIQIzbhcgIBduFyAg/sRtFyAgF20XICABDm4XICAXbhcgIAAAAQBFAFEDuwL4ACQAAAEUBgcBDgEjIiYnAS4BNTQ2PwE+ATMyFh8BAT4BMzIWHwEeARUDuwgI/hQHFQoLFQf+4wgICAhOCBQLChUIqAF2CBUKCxQITggIAnMKFQf+FAgICAgBHQcVCwoVB04ICAgIqAF3CAgICE4HFQsAAAEAPwA/AuYC5gA8AAAlFAYPAQ4BIyImLwEHDgEjIiYvAS4BNTQ2PwEnLgE1NDY/AT4BMzIWHwE3PgEzMhYfAR4BFRQGDwEXHgEVAuYJB04IFAsLFAioqAcVCwoVB04ICAgIqKgICAgITgcVCgsVB6ioCBQLCxQITgcJCQeoqAcJwwoVB04ICAgIqKgICAgITgcVCgsVB6ioCBQLCxQITgcJCQeoqAcJCQdOCBQLCxQIqKgHFQsAAAACAAAAAANuA7cAPABKAAABFAcOAQcGIyInLgEnJjU0Nz4BNzY3NhYXFgYHDgEVFBceARcWMzI3PgE3NjU0JicuATc+ARcWFx4BFxYVAREUBiMiJjURNDYzMhYDbiMieFBQWltQUHciIwwLLSEhKRk8EhIJGDc+FxdQNTU9PDY1TxcXPTgYCBISPBgqISAtDAz+kiseHisrHh4rAbdbUFB3IiMjIndQUFs0MTJaJycfEwkYGDwSKntFPTU1UBcXFxdQNTU9RXsqEjwYGAkTHycnWjIxNAG3/pIeKyseAW4eKysAAAACAAAAAANuA24ACwCSAAABNCYjIgYVFBYzMjYlFRQGDwEOAQceARceARUUBgcOASMiJi8BDgEHDgEHDgErASImLwEuAScHDgEjIiYnLgEnLgE1NDY3PgE3LgEvAS4BPQE0Nj8BPgE3LgEnLgE1NDY3PgEzMhYfAT4BNz4BNz4BOwEyFh8BHgEXNz4BMzIWFx4BFx4BFRQGBw4BBx4BHwEeARUCSVY8PVVVPTxWASUJB2oFCgcOHxACBAMDClUPBAcETwwaDgMGBwILCH8HDAEQDRoNUAMIAwQIAxY2EgICAgMOHw8IDARoCAkJBmsECwcPHhADAwMCC1UPAwgDTw0aDQMHBwILB38IDAEQDRoMUQMHBAQHAxc2EgICAwIOHw8HDAVoBwoBtzxWVjw9VVV7fwYNARAOGgwVJxMDCAMEBwMNWQMCPgYLBRo2GgcJCgdpBQoGPQIDAwMVMxgDBwQDBwMTJxQOHA8PAQwIfgcNARAOGg0UJxMDBwQEBgMOWQQCPQYLBBs2GgcJCgdqBAoHPQMDBAIVMxkDBgQEBgMUJhQOHA4QAgwHAAAAAAYAAAAAAyUDbgAPAB8ALwA6AEQAaQAAAREUBisBIiY1ETQ2OwEyFhcRFAYrASImNRE0NjsBMhYXERQGKwEiJjURNDY7ATIWExEhERQWMyEyNjUBIScuAScjDgEHBRUUBisBERQGIyEiJjURIyImPQE0NjsBNz4BOwEyFh8BMzIWFQElCwgkCAsLCCQIC5ILByUICgoIJQcLkgoIJQcLCwclCApJ/gAQAwHbAhD+gAEAGwEHArUDBQIB9wsINzUm/iUmNjcHCwsHsSgILRe3Fi0JKLAICwIS/rcICgoIAUkICwsI/rcICgoIAUkICwsI/rcICgoIAUkICwv+WwId/eMVFxcVAmZDAgQBAQQCVSQIC/3jMEVDLwIgCwgkCApgFR4eFWAKCAAAAgATAEkDpAMlABUAPAAAAREUBisBNSMVIyImNRE0NjEJATAWFTcHDgErASImJwkBDgEnIiYvASY2NwE2Mh8BNTQ2OwEyFh0BFx4BBwMlFg/bk9sPFgEBSAFJAX8jAwYDAgQGAv50/nUDBwQDBwIjBQIFAZsSMxKLCwhtCAt9BQIFAYD+7g8W3NwWDwESAQIBD/7xAgEnKgIEAgIBSv62AgMBBAIqBg8FAVYPD3RvCAsLCOloBQ8GAAMAAP+3A24DtwATABwAJgAAAR4BFREUBiMhIiY1ETQ2MyEyFhcHFTMuAS8BLgETESMiJj0BIREhA0cQFyAX/QAXICAXAgAXNxBM1wMHA7IDDtXuFyD+SQLcAt4QNxf9bhcgIBcDkhcgFxAn1wgNA7MDB/yZAkkgF+78kgADAAAAAANuA24AFQAxAE0AAAERFAYrASImPQE0NjsBNTQ2OwEyFhUXNCcuAScmIyIHDgEHBhUUFx4BFxYzMjc+ATc2NxQHDgEHBiMiJy4BJyY1NDc+ATc2MzIXHgEXFgIACwe3CAoKCIAKCCUHC+4ZGFU4OUBAOTlUGRgYGVQ5OUBAOThVGBmAIyJ3UFBbW1BQdyMiIiN3UFBbW1BQdyIjAoD/AAgKCgglBwvJCAoKCMlAOThVGBkZGFU4OUBAOTlUGRgYGVQ5OUBbUFB3IiMjIndQUFtbUFB3IiMjIndQUAAAAAAEAAAASQO3A7cACwAXADEAUQAAJTQmIyIGFRQWMzI2NzQmIyIGFRQWMzI2NxUUBiMhIiY9ATQ2MyEXHgEzMjY/ASEyFhUDFgYHAQ4BIyImJwEuATc+ATsBETQ2OwEyFhURMzIWFwLbFQ8PFhYPDxWTFg8PFRUPDxZJIBf8txcgIBcBCk0QKBUWKBBOAQkXILoEBAj/AAUOBwYOBf8ACAUFBBILkxUPkw8VkgwSBLcPFRUPDxYWDw8VFQ8PFhaPtxcgIBe3FyBODxERD04gFwFFChYI/wAGBQUGAQAIFgoKDAEADxYWD/8ADAoAAAMAAAAAA24DbgAYADQAUAAAARQGBwUOASMiJicuATURNDY3NjIXBR4BFTM0Jy4BJyYjIgcOAQcGFRQXHgEXFjMyNz4BNzY3FAcOAQcGIyInLgEnJjU0Nz4BNzYzMhceARcWAqUKCf7JBAkFBQkECQkJCQgUCAE3CQpJGRhVODlAQDk5VBkYGBlUOTlAQDk4VRgZgCMid1BQW1tQUHcjIiIjd1BQW1tQUHciIwG3ChEFtgMDAwIFEQoBbgoRBQQFtwQRCkA5OFUYGRkYVTg5QEA5OVQZGBgZVDk5QFtQUHciIyMid1BQW1tQUHciIyMid1BQAAABAAAAAANuA24ATQAAAREUBiMhIiYnJjY/AS4BIyIHDgEHBhUUFx4BFxYzMjY3PgE3MhYfARYUBwYHDgEHBiMiJy4BJyY1NDc+ATc2MzIXHgEXFhc3PgEXHgEVA24WD/8ACxIFBAQITyhnOD01NVAXFxcXUDU1PUR5KgIHBAQHA04GBCAmJlcvLzFbUFB3IiMjIndQUFsqKSlOIyMeSggWCgoNAyX/AA8WDQoKFgdPJSkXF081Njw9NTVQFxc8NgMDAQMCTwUOBiUeHSkKCyMid1BQW1tPUHgiIwkIHxYXHEkIBQUEEgsAAgAAAAADbgNuADQAZwAAATAUFQYHDgEHBiMiJy4BJyYnBw4BIyImNRE0NjMhMhYVFAYPAR4BMzI2Nz4BNz4BOwEyFhUTERQGIyEiJjU0Nj8BLgEjIgYHDgEHDgErASImPQE2Nz4BNzYzMhceARcWFzc+ATMyFhUDXxIoJ29GRU8qKSlMIyQeSgUNBw8WFg8BAA8VBgVOKGg3TIUoCg0HAgkGbggKDxYP/wAPFQUFTyhoN0yFKAsMCAIIB3EICxMnKHBGRk8qKSlNIyQeSgYNBw8WAVsDAUtAP1sZGQgIHxcWHUoFBRUPAQAPFhYPBw0GTiYpS0EQIRIGBwsIAcr/AA8WFg8HDQVPJihKQREhEQYHCwcETEA/WhoZCAkfFhccSQUGFQ8AAAAIAAAASQQAA24AEAAgADAAQQBSAGMAdACEAAATFRQGKwEiJj0BNDY7ATIWFTUVFAYrASImPQE0NjsBMhY1FRQGKwEiJj0BNDY7ATIWARUUBiMhIiY9ATQ2MyEyFhU1FRQGIyEiJj0BNDYzITIWFTUVFAYjISImPQE0NjMhMhYVExE0JiMhIgYVERQWMyEyNjUTERQGIyEiJjURNDYzITIW2wsHJAgLCwgkBwsLByQICwsIJAcLCwckCAsLCCQHCwKTCwj93AcLCwcCJAgLCwj93AcLCwcCJAgLCwj93AcLCwcCJAgLSQsH/LYHCwsHA0oHC0k2Jfy2JTY2JQNKJTYBEiQICwsIJAgLCwiTJQcLCwclBwsLiyUHCwsHJQcLC/7UJAgLCwgkCAsLCJMlBwsLByUHCwsHkiUHCwsHJQcLCwf+bgHbBwsLB/4lCAsLCAJt/ZMmNjYmAm0mNjYAAAAAAgAAAAwDYgNuAAsAJgAAATQmIyIGFRQWMzI2ARQGBwEOASMiJicBLgE9ATQ2OwEyFhcBHgEVAQArHh8qKh8eKwJiDAn+5wobDw8bCf5nFh4rHu4eSRYBmQkMArceKyseHyoq/tYPGwr+5woLCwoBmRZIH+4eKx4W/mgLGw4AAAADAAAADAQ9A24ACwAmAEQAAAE0JiMiBhUUFjMyNgEUBgcBDgEjIiYnAS4BPQE0NjsBMhYXAR4BFTMUBgcBDgEjIiYnAT4BNTQmJwEuASMzMhYXAR4BFQEAKx4fKiofHisCYgwJ/ucKGw8PGwn+ZxYeKx7uHkkWAZkJDNsLCv7nChsPFhsPAQ0KCwsK/mcVSR+AH0kVAZkKCwK3HisrHh8qKv7WDxsK/ucKCwsKAZkWSB/uHiseFv5oCxsODxsK/ucKCxMPAQwKGw8OGwsBmBYeHhb+aAsbDgAIAAAASQQAA24AEAAhADEAQgBSAGMAcwCDAAA3FRQGKwEiJj0BNDY7ATIWFTUVFAYrASImPQE0NjsBMhYVNRUUBisBIiY9ATQ2OwEyFgEVFAYjISImPQE0NjMhMhYVARUUBisBIiY9ATQ2OwEyFgEVFAYjISImPQE0NjMhMhYVNRUUBiMhIiY9ATQ2MyEyFjUVFAYjISImPQE0NjMhMhaSCwduBwsLB24HCwsHbgcLCwduBwsLB24HCwsHbgcLA24LB/0ACAsLCAMABwv8kgsHbgcLCwduBwsDbgsH/QAICwsIAwAHCwsH/QAICwsIAwAHCwsH/QAICwsIAwAHC8luBwsLB24HCwsH3G4HCwsHbgcLCwfbbgcLCwduBwsL/kJuBwsLB24HCwsHApJtCAsLCG0ICwv+Qm4HCwsHbgcLCwfbbgcLCwduBwsL1G0ICwsIbQgLCwAAAAQAAAAAA2IDYgAHABwAIQAyAAA/AScHFTMVMwE0JiMiBgcBDgEVFBYzMjY3AT4BNScXASM1ARQGDwEnNz4BMzIWHwEeARXPNIY0ST0BKwcFAwUC/soCAgcGAgUDATUCAh/u/iXuA2IMCV/uXwobDg8bCocJDEk0hjQ9SQISBgcCAv7KAgUCBgcCAgE2AgUCbu7+Je4BpA4bCl/uXgoMDAqGChsPAAAAAAIAAAAAAkkDbgALACgAAAE0JiMiBhUUFjMyNjcUBgcDDgEjIiYnAy4BNTQ3PgE3NjMyFx4BFxYVAbdWPD1WVj08VpIIC9AJJBQVJAnQCwgXF082NT08NjVPFxcCST1VVT08VlY8GjUX/kYTFhYTAboXNRo9NTVQFxcXF1A1NT0ABQAAAEkD6wNuAAcAFQBKAE8AWgAAATcnBxUzFTMTJgYPAQYUFxY2PwE+ARMVFAYjISImNRE0NjMhMhYXHgEXFgYPAQ4BJy4BIyEiBhURFBYzITI2PQE0Nj8BPgEXHgEVAxcBIzUBByc3NjIfARYUBwH7Q1dCNiD8BAsEyAQDBAsEyAQBKmFE/iVFYGBFAdsRIhAEBQEBAwMcBAoEBw0G/iUmNjYmAdsmNQMDJAQLBQUHN6T+gKQCfTSlNRAuEFYQEAESQ1ZCIDcBnAQBBMgECwQEAQTIBAv+sGxEYWFEAdtEYQcIAQcFBAkDHAQDAgICNib+JSY2NiZIAwcCJQQCAgIJBgGmpf6ApQE1NaU0EBBXEC4PAAAAAAIAAABJA6kDbgA6AFAAAAEVFAYjISImNRE0NjMhMhYXHgEXFgYPAQ4BIyImIy4BIyEiBhURFBYzITI2PQE0Nj8BPgEzMhYXHgEVEwEGIi8BJjQ/ATYyHwEBNjIfARYUBwMlYUT+JUVgYEUB2xEiEAQFAQEDAxwDBwMBAwEHDQb+JSY2NiYB2yY1AwMkAwcDAgMCBQeE/i4NJg71Dg4+DiYOlgFyDSYOPw0NAaO1RGFhRAHbRGEHCAEHBQQJAxwDAwECAjYm/iUmNjYmkQMHAiUDAwEBAgkGARj+Lw4O9Q4mDj4ODpYBcg4OPw4lDgAAAAEAAP//AxcDbgALAAAJAQYmNRE0NhcBFhQDF/0JDRMTDQL3DQGl/loHCw8DSQ8MCP5bCBUAAAAAAgAAAAADbgNuAA8AIAAAAREUBiMhIiY1ETQ2MyEyFgURFAYjISImNRE0NjMhMhYVA24WD/7cDxYWDwEkDxb+ABYP/twPFhYPASQPFgNJ/NwPFhYPAyQPFhYP/NwPFhYPAyQPFhYPAAABAAAAAANuA24ADwAAAREUBiMhIiY1ETQ2MyEyFgNuFg/83A8WFg8DJA8WA0n83A8WFg8DJA8WFgAAAAABAGMAGgKdA50AFQAACQIWFA8BBiInASY0NwE2Mh8BFhQHAp3+0QEvCwtfCh4L/lgLCwGoCx4KXwsLAwv+0P7RCx4KXwsLAagKHgsBqAsLXwoeCwABAD4AGgJ5A50AFQAACQEGIi8BJjQ3CQEmND8BNjIXARYUBwJ5/lgLHgtfCgoBMP7QCgpfCx4LAagKCgHC/lgLC18KHgsBLwEwCx4KXwsL/lgLHgoAAAAAAwAAAAADbgNuABAAQwBfAAAlNTQmKwEiBh0BFBY7ATI2NRM0Jy4BJyYjIgYHBhYfAR4BMzI2Nz4BNz4BMzIWFRQGBw4BHQEUFjsBMjY1MTQ2Nz4BNRcUBw4BBwYjIicuAScmNTQ3PgE3NjMyFx4BFxYCAAsHbggKCghuBwuSEhM8JSUlRmklBAMGSwIGAwQIAhUUCQcaEBsrGBofQQoIbgcLFxQhRtwjIndQUFtbUFB3IyIiI3dQUFtbUFB3IiOlbQgLCwhtCAsLCAGAJyEiMQ4NPD0GDgQ5AgIEAxoVBgUIHRMXGgwOQSoVBwsLBwojDBI9Qm5bUFB3IiMjIndQUFtbUFB3IiMjIndQUAAAAAADAAAAAANuA24AHwAvAEsAACU1NCYrARE0JisBIgYdARQWOwEVIyIGHQEUFjMhMjY1AzU0JisBIgYdARQWOwEyNgUUBw4BBwYjIicuAScmNTQ3PgE3NjMyFx4BFxYCSQoINwsHtwgKCgg3NwgKCggBAAgKSQsHbggKCghuBwsBbiMid1BQW1tQUHcjIiIjd1BQW1tQUHciI6VbCAoBJQgKCghcBwu3CghbCAsLCAIAWwgKCghbCAsL5ltQUHciIyMid1BQW1tQUHciIyMid1BQAAAAAAEAAABJAyUDbgAkAAABFRQGKwEVFAYrASImPQEjIiY9ATQ2OwE1NDY7ATIWHQEzMhYVAyUhFu4gF24WIO4XICAX7iAWbhcg7hYhAhJtFyDuFyAgF+4gF20XIO4XICAX7iAXAAABAE0AAANqA24ANQAAAR4BDwEOAS8BFRQGKwEiJj0BBwYmLwEmNj8BJy4BPwE+AR8BNTQ2OwEyFh0BNzYWHwEWBg8BA08aEA8lDzsamCseSR4rmBo7DyUPEBqYmBoQDyUPOxqYKx5JHiuYGjsPJQ8QGpgBXw87Gj8aEA9YsB4rKx6wWA8QGj8aOw9YWA87Gj8aEA9YsB4rKx6wWA8QGj8aOw9YAAMAAAAAA24DbgAcACwAQwAAATIXHgEXFhUUBw4BBwYjIicuAScmNTQ3PgE3NjMTNTQmKwEiBh0BFBY7ATI2JxM0JicuASsBIgYHDgEVExQWOwEyNjcBt1tQUHciIyMid1BQW1tQUHcjIiIjd1BQW0kKCG0ICwsIbQgKAQoDAwIHBH4EBwMDAgkMCGkICwEDbiMid1BQW1tQUHciIyMid1BQW1tQUHciI/03bQcMDAdtCAsLzQFjAwUCAgICAgIFA/6dBgkJBgAAAwAJAAAD9wO3AA8AJgA8AAAlNTQmKwEiBh0BFBY7ATI2JxM0JicuASsBIgYHDgEVExQWOwEyNjUDARYUBw4BIyEiJicmNDcBPgEzMhYXAkkKCG4ICgoIbggKAQoCAwMHBH4EBwMDAgkMCGoHDAgBtwkKCiIT/JITIgoKCQG3CSMUFCMJpW0HDAwHbQgLC94BBgMGAgIEBAICBwP++wYHBwYCFvzbESYRERMTEREmEQMlERUVEQAAAAEAPgBgA8ICmgAVAAAlBwYiJwkBBiIvASY0NwE2MhcBFhQHA8JfCx4L/tH+0QseC18KCgGoCx4LAagKCr5eCwsBL/7RCwteCx8KAagKCv5YCh8LAAEAPgBCA8ICewAVAAAJAQYiJwEmND8BNjIXCQE2Mh8BFhQHA8L+WAseC/5YCgpfCx4LAS8BLwseC18KCgHp/lkLCwGnCx4LXgsL/tEBLwsLXgseCwAAAAAFAAAAAASSA24AAwAIAA4AEwAYAAABESMRAREjETMBFSERMxEBESMRMzcRIxEzAW6TAW6SkgJJ+25JAtyTk9uSkgG3/tsBJQEk/bcCSf1uSQNu/NsCAP5JAbfc/W0CkwAGAAD/vwRJA64ACwAXACMApAD8AVQAAAE0JiMiBhUUFjMyNgU0JiMiBhUUFjMyNhE0JiMiBhUUFjMyNgcVFAYPAQ4BBx4BFx4BFRQGBw4BIyImLwEOAQcOAQcOASsBIiYvAS4BJwcOASMiJicuATU0Njc+ATcuAS8BLgE9ATQ2PwE+ATcuAScuATU0Njc+ATMyFh8BPgE3PgE3PgE7ATIWHwEeARc3PgEzMhYXHgEVFAYHDgEHHgEfAR4BFQEVFAYjDgEHHgEVFAYHDgEjIiYnIgYjIiYjDgEjIiYnLgE1NDY3LgEnIiY9ATQ2Nz4BNy4BNTA2Nz4BMzIWFz4BMzIWFz4BPwEyFhceATEUBgceARceARURFRQGBw4BBx4BFRQGBw4BIyImJyIGIyImIw4BIyImJy4BNTQ2Ny4BJy4BPQE0Njc+ATcuATU0Njc+ATMyFhcyNjMyFjM+AT8BMhYXHgEVFAYHHgEXHgEVAgBWPD1WVj08VgG3Kx4eKyseHisrHh4rKx4eK9wHBlgECQYMGg4CAgICCUcMBAYCQgsVDAIFBgIJBmoGCwENCxULQwIGAwQGAgxHAwENGQ0GCwNXBggIBVkDCQYMGg0CAgEDCEcNAwYDQQsWCwIGBQIKBmoGCgENCxYKQwMGAwMGAwtHAgIMGgwGCgRXBgcBbkwJAwkFBBkBAQVAAgYuBAQJBAUIBAUuBQM/BQIBGgQGCAQITU0IBAgGBBoBAgU/AwUuBQQIBQQJBAwaDgQCQAUBARkEBQkDCUxMCQMJBQQZAQEFQAIGLgQECQQFCAQFLgUDPwUCARoEBggECE1NCAQIBgQaAQIFPwMFLgUECAUECQQMGg4EAkAFAQEZBAUJAwlMAbc8VlY8PVVV6B4rKx4eKysCZx4sLB4eKyvSagULAQ4LFQsRIRACBgMDBgIMSQICMwUJBBUuFQYICAZYAwkGMwICAgILRA0DBQMQIBELGAwNAQoGagULAQ0MFQsRIBECBgMDBgIMSQICMwUJBBUuFQYICQZXBAkFMwICAgMKRQwDBQMRHxEMFwwNAQoG/s9QBgsJDgcJPggBAgEDJjwGAQEGPCYDAQIBBz8JBw4JCwZQBwoBCA8HCD8IAwECJjsHAQEBAREhDgIlAwEDCD8IBw8IAQoHAklQBgoBCA8HCT4IAQIBAyU7BgEBBjslAwECAQc/CQcPCAEKBlAHCgEIDwcIPwgBAgECJjsGAQEQIQ8BJQMBAgEIPwgHDwgBCgcAAAIAAABJBAADtwAoAEsAAAEVFAYjISImNRE0NjMhMhYdARQGIyEiBhURFBYzITI2PQE0NjsBMhYVExEUBiMiJi8BAQ4BIyImLwEuATU0NjcBJy4BNTQ2MyEyFhUDJWFE/iVFYGBFAZIICgoI/m4mNjYmAdsmNQsIJAgL2xYPBw0FZf6MAwcEAwcDQQIEBAIBdWUFBhYPASQPFgGlt0RhYUQB20RhCwgkCAo2Jv4lJjY2JrcHCwsHAe3+3A8WBgVl/osDAwMDQQMHAwQHAgF1ZQUNBw8WFg8AAAIAAABJAyUDbgAPAB8AAAEhIgYVERQWMyEyNjURNCYXERQGIyEiJjURNDYzITIWAoD+JSY2NiYB2yY1NX9hRP4lRWBgRQHbRGEDJTYm/iUmNjYmAdsmNlz+JURhYUQB20RhYQADACX/twPbA7cAEgAwAGcAAAU0JiMiJjU0JiMiBhUUFjMyNjUlISYnLgEnJjU0Jy4BJyYjIgcOAQcGFRQHDgEHBgchFAYjIRQGIyImNSEiJjU2Nz4BNzY1NDc+ATc2Ny4BNTQ2MzIWFRQGBxYXHgEXFhUUFx4BFxYXAgkFBCIwBgMEBjsqBAX+hALmJhwdJgkKDQ02Kik4OCkqNg0NCgkmHRwmA04rHv8AVjw8Vv8AHisfISA1ERARET4tLTkCAyAXFyADAjktLT4RERARNSAhHxIEBTAiBAUFBCk7BQSkLDMzdkRDTRsgIDcSExMSNyAgG01DRHYzMyweKzxWVjwrHhsnJ3FNTWgpKSpFGRkJBQsGFyAgFwYLBQkZGUUqKSloTU1xJycbAAEAAQAAA20DbABiAAABFx4BBw4BDwEXFgYHDgEvAQcOAQciBiMiJi8BBw4BJy4BLwEHBiYnLgE/AScuAScmNj8BJy4BNz4BPwEnJjY3PgEfATc+ATc2Fh8BNz4BFx4BHwE3NhYXHgEPARceARcWBgcDEk8IBgIDEAtsHwMGCAgVC2ocAhALAwUDCA8GTU0IFgoLEAIcagsVCAgGAx5rCxADAgUJTk4JBQIDEAtrHgMGCAgVC2ocAhALChYITU0IFQsLEAIcagsVCAgGAx9sCxADAgYIAbdNCBYKCxACHGoLFQgIBgMeawsQAwEHBk5OCQUCAxALax4DBggIFQtqHAIQCwoWCE1NCBULCxACHGoLFQgIBgMfbAsPAwMGCE9PCAYDAw8LbB8DBggIFQtqHAIQCwsVCAAAAAEAAwAAAyIDJQAeAAABFgYHAREUBgcOASMiJi8BLgE1EQEuATc+ATMhMhYXAyIEBAj+5gwKBAcEBw0FkwUF/uYIBAQEEgwC2wsSBQMOChYI/uf+WAwSBAECBQaSBQ4HARYBGQgWCgoNDQoAAAEAAAAAA24DbgBZAAABBxc3PgEXHgEVERQGIyEiJicmNj8BJwcXHgEHDgEjISImNRE0Njc2Fh8BNycHDgEjIiYnLgE1ETQ2MyEyFhcWBg8BFzcnLgE3PgEzITIWFREUBgcOASMiJicC3cvLUggWCgoNFg//AAsSBQQECFPLy1IIBQUEEgv/AA8WDQoKFgdTyspTBQ0HBAcDCg0WDwEACxIEBQUIUsvLUwgEBAUSCwEADxYNCgMHBAcNBgKCy8tSCAUFBBIL/wAPFg0KChYHU8rKUwcWCgoNFg8BAAsSBAUFCFLLy1MFBQEBBRILAQAPFg0KChYIUsvLUggWCgoNFg//AAsSBQEBBQUAAAAGAAD/twRJA7cAGgA2AEIAXgB4AIQAAAEOAQcjIiY1NDc+ATc2MzIWMzI2Nw4BFRQWFwEUBiMhIiY1NDc+ATc2MzIWMzI2MzIXHgEXFhUBFAYjIiY1NDYzMhYBFAcOAQcGIyInLgEnJjU0Nz4BNzYzMhceARcWBRQGKwEuASc+ATU0JiceATMyNjMyFx4BFxYDFAYjIiY1NDYzMhYBUy1OHUwrRAEBDQ4PGwlSORQmEgEBGBYCZFRF/g1FVAgHKyYnPw9oVlVpDj8nJisIB/23Vj08VlY8PVYBkhESOygoLS4oKDsSERESOygoLi0oKDsSEQFJRCtMHU4tFxgCARImFDpRCRwODg0BAUlWPD1WVj08VgG3ASYiKzARIiFDGRkwBgcKEgonSyD+lEZOTkYwOjliISFPTyEhYjk6MALaPVZWPTxWVv7oLSgoPBERERE8KCgtLigoOxESEhE7KCiuMCsiJgEgSycKEgoHBjAZGUMhIgFLPVZWPTxWVgAAAAADAAkACQOuA64AIwBIAIAAAAE0Ji8BLgEjIgYHHgEVFAYjIiYnDgEVFBYfAR4BMzI2PwE+AQE0Ji8BLgEjIgYPAQ4BFRQWHwEeATMyNjcuATU0NjMyFhc+ATUBFAYPAQ4BIyImLwEuATU0NjcnDgEjIiYvAS4BNTQ2PwE+ATMyFh8BHgEVFAYHFz4BMzIWHwEeAQNACAh3CBQLDBQJDhsgFxUcDwkJCAh1CBQLCxQIVAgI/m4ICHUIFQoLFAhUCAgICHcHFQsMFAkOGyAWFhwOCQoCABoXVBc8ISE8F3YXGRsYMxc+ISE9F3cXGRoXVBc8ISE8F3YXGBoYMhg9IiE9F3cXGQEACxQIdwcJCgkOHBYWIBsOCRQNCxQIdggICAdUBxQBngsUCHYICAgHVAgTCwsUCHcIBwgJDxwVFyAbDgkUDf5tITwXUxgYGRh2FzwhIj4XMxgbGRd3GDwhID0XUxcZGRh2Fz0gIj4YMhgaGBh2GDwAAAAAAwAAAEkDbgMlAA8AHwAvAAAlFRQGIyEiJj0BNDYzITIWERUUBiMhIiY9ATQ2MyEyFhEVFAYjISImPQE0NjMhMhYDbhYP/NwPFhYPAyQPFhYP/NwPFhYPAyQPFhYP/NwPFhYPAyQPFrdJDxYWD0kPFRUBFUkPFRUPSQ8WFgEWSQ8WFg9JDxYWAAoAAABJA7cDbgAQACAAMQBBAFEAYgByAIMAlACkAAAlNTQmKwEiBh0BFBY7ATI2NT0BNCYrASIGHQEUFjsBMjYFNTQmKwEiBh0BFBY7ATI2NQE1NCYrASIGHQEUFjsBMjYFNTQmKwEiBh0BFBY7ATI2BTU0JisBIgYdARQWOwEyNjUBNTQmKwEiBh0BFBY7ATI2BTU0JisBIgYdARQWOwEyNjU9ATQmKwEiBh0BFBY7ATI2NTcRFAYjISImNRE0NjMhMhYBJQsItwcLCwe3CAsLCLcHCwsHtwgLASQKCLcICgoItwgK/twLCLcHCwsHtwgLASQKCLcICgoItwgKASULCLYICwsItggL/tsKCLcICgoItwgKASULCLYICwsItggLCwi2CAsLCLYIC0k2Jv0AJTY2JQMAJjalbQgLCwhtCAsLCNtuBwsLB24ICgrTbQgLCwhtCAsLCAG2bggKCghuBwsL1G4HCwsHbggKCtNtCAsLCG0ICwsIAbZuCAoKCG4HCwvUbgcLCwduCAoKCNtuCAoKCG4HCwsHt/2TJjY2JgJtJjY2AAABAAABAAJJAkkAFQAAARQGBwEOASMiJicBLgE1NDYzITIWFQJJBgX/AAUNBwgNBf8ABQYWDwIADxUCJQgNBf8ABQYGBQEABQ0IDxUVDwAAAAEAAADbAkkCJQAUAAABFAYjISImNTQ2NwE+ATMyFhcBHgECSRUP/gAPFgYFAQAFDQgHDQUBAAUGAQAPFhYPBw4FAQAFBgYF/wAFDgABACUAkgFuAtsAFQAAAREUBiMiJicBLgE1NDY3AT4BMzIWFQFuFg8HDQb/AAUFBQUBAAYNBw8WArf+AA8WBgUBAAUOBwcNBgEABQUVDwAAAAEAAACSAUkC2wAVAAABFAYHAQ4BIyImNRE0NjMyFhcBHgEVAUkGBf8ABQ0HDxYWDwcNBQEABQYBtwcOBf8ABQYWDwIADxUFBf8ABg0HAAAAAgAAACUCSQNJABUAKwAAARQGBwEOASMiJicBLgE1NDYzITIWFTUUBiMhIiY1NDY3AT4BMzIWFwEeARUCSQYF/wAFDQcIDQX/AAUGFg8CAA8VFQ/+AA8WBgUBAAUNCAcNBQEABQYBSQcNBv8ABQUFBQEABg0HDxYWD9wPFhYPBw0FAQAFBgYF/wAFDQcAAAAAAQAAACUCSQFuABUAAAEUBgcBDgEjIiYnAS4BNTQ2MyEyFhUCSQYF/wAFDQcIDQX/AAUGFg8CAA8VAUkHDQb/AAUFBQUBAAYNBw8WFg8AAAABAAACAAJJA0kAFQAAARQGIyEiJjU0NjcBPgEzMhYXAR4BFQJJFQ/+AA8WBgUBAAUNCAcNBQEABQYCJQ8WFg8HDQUBAAUGBgX/AAUNBwAAAAcAAAAABAADJQALABcALQA5AEUAUQBtAAATNCYjIgYVFBYzMjYTNCYjIgYVFBYzMjYXNzYmJzEmBg8BDgEHBhYXFjY3NiYnJTQmIyIGFRQWMzI2ATQmIyIGFRQWMzI2BTQmIyIGFRQWMzI2FxQGBw4BIyEiJicuATU0Nz4BNzYzMhceARcWFdsqHx4rKx4fKm4rHh4rKx4eK/U5BA8PDhsDOiI2CQwuLCxPCwkZHAF5Kx4fKiofHiv+kiseHisrHh4rAQArHh4rKx4eK7cpKAUQCfzeCRAFKCkoKYtdXWpqXV2LKSgBJR4rKx4fKysBHx4rKx4fKyv02g8aBAMPD9oDKyMsTwsMLiwjQBQTHisrHh8rKwGMHyoqHx4rK08eKyseHysr4UqMPggJCQg9jUppXl2LKCkpKItdXmkAAAAAAgAl/7cD2wO3ABIASQAABTQmIyImNTQmIyIGFRQWMzI2NSUUBiMhFAYjIiY1ISImNTY3PgE3NjU0Nz4BNzY3LgE1NDYzMhYVFAYHFhceARcWFRQXHgEXFhcCCQUEIjAGAwQGOyoEBQHSKx7/AFY8PFb/AB4rHyEgNREQERE+LS05AgMgFxcgAwI5LS0+EREQETUgIR8SBAUwIgQFBQQpOwUEpB4rPFZWPCseGycncU1NaCkpKkUZGQkFCwYXICAXBgsFCRkZRSopKWhNTXEnJxsAAAAGAAD/twNuA7cAEwAcACYANwBHAFgAAAEeARURFAYjISImNRE0NjMhMhYXBxUzLgEvAS4BExEjIiY9ASERIQE0NjMhMhYdARQGIyEiJj0BBTIWHQEUBiMhIiY9ATQ2MwUyFh0BFAYjISImPQE0NjMhA0cQFyAX/QAXICAXAgAXNxBM1wMHA7IDDtXuFyD+SQLc/bYLCAGSCAoKCP5uCAsBpQgKCgj+bggLCwgBkggKCgj+bggLCwgBkgLeEDcX/W4XICAXA5IXIBcQJ9cIDQOzAwf8mQJJIBfu/JIB7gcLCwclCAoKCCWACwgkCAoKCCQIC5MKCCQICwsIJAgKAAAAAgAaAHUCQgKvACQASQAAJRQGDwEOASMiJicBLgE1NDY3AT4BMzIWHwEeARUUBg8BFx4BFTMUBg8BDgEjIiYnAS4BNTQ2NwE+ATMyFh8BHgEVFAYPARceARUBZgMCHQMHAwQHAv71AgMDAgELAgcEAwcDHQIDAwLh4QID3AMDHQIHBAMHA/72AwMDAwEKAwcDBAcCHQMDAwPh4QMDpQQHAxwDAwMDAQoDBwMEBwIBCwIDAwIdAggDAwgC4eADBwMEBwMcAwMDAwEKAwcDBAcCAQsCAwMCHQIIAwMIAuHgAwcDAAAAAgAHAHUCLwKvACQASQAAARQGBwEOASMiJi8BLgE1NDY/AScuATU0Nj8BPgEzMhYXAR4BFTMUBgcBDgEjIiYvAS4BNTQ2PwEnLgE1NDY/AT4BMzIWFwEeARUBVAMD/vYDBwMEBwIdAgQEAuHhAgQEAh0CBwQDBwMBCgMD2wMC/vUCBwQDBwMcAwMDA+DgAwMDAxwDBwMEBwIBCwIDAZIDBwP+9gMDAwMcAwcEAwcD4OECCAMDCAIdAgMDAv71AgcEAwcD/vYDAwMDHAMHBAMHA+DhAggDAwgCHQIDAwL+9QIHBAAAAQAaAHUBZgKvACQAAAEUBg8BFx4BFRQGDwEOASMiJicBLgE1NDY3AT4BMzIWHwEeARUBZgMC4eECAwMCHQMHAwQHAv71AgMDAgELAgcEAwcDHQIDAoADCALh4AMHAwQHAxwDAwMDAQoDBwMEBwIBCwIDAwIdAgcEAAAAAAEABwB1AVQCrwAkAAABFAYHAQ4BIyImLwEuATU0Nj8BJy4BNTQ2PwE+ATMyFhcBHgEVAVQDA/72AwcDBAcCHQIEBALh4QIEBAIdAgcEAwcDAQoDAwGSAwcD/vYDAwMDHAMHBAMHA+DhAggDAwgCHQIDAwL+9QIHBAAAAAACAAAAAARJA7cADwAuAAABETQmIyEiBhURFBYzITI2ExEUBiMhFBYVFAYjISImNTQ2NSEiJjURNDYzITIWFQQACwf8bQcLCwcDkwcLSTYl/skkFQ/+2w8VJP7JJTY2JQOTJTYBgAHbCAsLCP4lBwsLAeL9kyY2JDoPDxYWDw85JTYmAm0mNjYmAAAAAAMAAABJApIDbgAMABwALAAAJTQmIyIGFRQWMzI2NTcRNCYjISIGFREUFjMhMjYTERQGIyEiJjURNDYzITIWAW4WDw8VFQ8PFtsLB/4kBwsLBwHcBwtJNSb+JCU2NiUB3CY1kg8WFg8PFRUPXAIkCAsLCP3cCAsLAiz9kyY2NiYCbSY2NgAAAAACAAAAAANuA24AHAA5AAABIgcOAQcGFRQXHgEXFjMyNz4BNzY1NCcuAScmIwEUBw4BBwYjIicuAScmNTQ3PgE3NjMxMhceARcWAbdAOTlUGRgYGVQ5OUBAOThVGBkZGFU4OUABtyMid1BQW1tQUHcjIiIjd1BQW1tQUHciIwLuGRhVODlAQDk5VBkYGBlUOTlAQDk4VRgZ/slbUFB3IiMjIndQUFtbUFB3IiMjIndQUAAAAAAIACX/2wPbA7cACwAXACMALwA7AEcAVABhAAAlFAYjIiY1NDYzMhYFFAYjIiY1NDYzMhYBFAYjIiY1NDYzMhYBFAYjIiY1NDYzMhYBFAYjIiY1NDYzMhYBFAYjIiY1NDYzMhYBFAYjIiY1NDYzMhYVBRQGIyImNTQ2MzIWFQEtKx8eKyseHysBHCseHisrHh4r/m4rHh8qKh8eKwKvKx4fKysfHiv92TYmJTY2JSY2ApwqHx4rKx4fKv6TQS0tQUEtLUEBL0w0NkpKNjRMmh4rKx4fKiqUHysrHx4rKwF0HyoqHx4rK/7FHisrHh8qKgIaJTY2JSY2Nv6+HyoqHx4rKwF0LUFBLS5AQC52NUtLNTVLSzUAAAAAAQAAAAADbgNuABsAAAEUBw4BBwYjIicuAScmNTQ3PgE3NjMyFx4BFxYDbiMid1BQW1tQUHcjIiIjd1BQW1tQUHciIwG3W1BQdyIjIyJ3UFBbW1BQdyIjIyJ3UFAAAAAAAgANAEkDtwKqABUAJQAACQEGIi8BJjQ/AScmND8BNjIXARYUBwEVFAYjISImPQE0NjMhMhYBTv72Bg8FHQUF4eEFBR0FDwYBCgYGAmkLB/3bCAoKCAIlBwsBhf72BgYcBg8G4OEFEAUdBQX+9QUPBv77JQcLCwclCAoKAAMAHwALBCoDGgAVACYAPAAAJQcGIicBJjQ3ATYyHwEWFA8BFxYUBwEDDgEvAS4BNxM+AR8BHgEHCQEGIi8BJjQ/AScmND8BNjIXARYUBwFhHQYPBf71BQUBCwUPBh0FBeHhBQUBUdUCDQckBwcC1QINByQHBwIBeP71BQ8GHAYG4OAGBhwGDwUBCwUFlxwGBgEKBg8FAQsFBR0FEAXh4AYPBgJi/R4HBwIKAg0HAuIHCAIKAg4H/oz+9gYGHAYPBuDhBRAFHQUF/vUFDwYAAAAEAAAAAAJJA24ACwAXACMAWwAANzQmIyIGFRQWMzI2ETQmIyIGFRQWMzI2BTQmIyIGFRQWMzI2NxQGBxQHDgEHBgcOAR0BHgEVFAYjIiY1NDY3ES4BNTQ2MzIWFRQGBxE+ATc+ATcuATU0NjMyFhWlIRYXICAXFiEhFhcgIBcWIQFtIBcWICAWFyA3HhkZGUkrKiVENBgeQC0uQB4ZGR5ALi1AHhgVLhVPWAEZHkAtLkBuFiEhFhcgIAKpFyAgFxcgIDIXICAXFyAgFx8yDk0yMT4REAwVIyoODzIeLkBALh4yDwHUDjMeLUFBLR4zDv7kCw8HGT9aDjIfLUFBLQAAAgA6AEkCRwMlABAAQwAAJRUUBisBIiY9ATQ2OwEyFhUTFAYHDgEVMRQGKwEiJj0BNDY3PgE1NCYjIgYHDgEHDgEjIiYvAS4BNz4BMzIXHgEXFhUBkg0KiQkODgmJCg21VykZHg0KiQkMUiUhHjYiFCEJChoZBAkFBAcDXgcDBC+DVy4vLkoYF+mJCQ4OCYkKDQ0KAVdRTRcOMQwJEhYKGTRTEQ8hGxglCgcHGyAEBQMCRwYRCExMEhE9KioxAAAAAgAAAAAC2wNuAAkAJwAAAREhET4BNz4BNRMRFAcOAQcGBw4BIyImJyYnLgEnJjURNDYzITIWFQJu/wAWQSIuWW00NYE4NwUEBwQECAMFODeBNTUWDwKSDxUBkgFu/XYMKBskaz4Bt/5JWklIaBwdAwECAgEDHRxoSElaAbcPFhYPAAAAAwAAAW4DJQJJAA8AHwAwAAATFRQGKwEiJj0BNDY7ATIWBRUUBisBIiY9ATQ2OwEyFgUVFAYrASImPQE0NjsBMhYV2yAWbhcgIBduFiABJSAXbhYgIBZuFyABJSEWbhcgIBduFiECEm0XICAXbRcgIBdtFyAgF20XICAXbRcgIBdtFyAgFwAAAAMAAABJANsDbgAPAB8ALwAANxUUBisBIiY9ATQ2OwEyFhEVFAYrASImPQE0NjsBMhYRFRQGKwEiJj0BNDY7ATIW2yAWbhcgIBduFiAgFm4XICAXbhYgIBZuFyAgF24WIO5uFyAgF24WISEBDm0XICAXbRcgIAEObhcgIBduFyAgAAAAAAIAAAAAA24DbgAcADQAAAEyFx4BFxYVFAcOAQcGIyInLgEnJjU0Nz4BNzYzEz4BNTQmJyUmIgcOARURFBYXHgEzMjY3AbdbUFB3IiMjIndQUFtbUFB3IyIiI3dQUFvbCQoKCf7JCBQICQkJCQQJBQUJBANuIyJ3UFBbW1BQdyIjIyJ3UFBbW1BQdyIj/ikFEQoKEQS3BQQFEQr+kgoRBQIDAwMAAgAAAAADbgNuAB8ALwAAARE0JiMhIgYHBhYfAQEGFB8BFjI3ARceATMyNjc+ATUTERQGIyEiJjURNDYzITIWAtsVD/7uDBIEBAQIUv7PCws6Cx4LATFSBQ4HAwgDCgyTYUT93EVgYEUCJERhAaUBEg8VDAoKFghS/s8LHgs6CwsBMVIGBQIBBBIMAST93EVgYEUCJERhYQAFAAD/twNuA7cACAAaACsAPABNAAABHgEXIREeARcDIREUBiMhIiY1ETQ2MyERFBYTNTQmIyEiBh0BFBYzITI2NT0BNCYjISIGHQEUFjMhMjY1PQE0JiMhIgYdARQWMyEyNjUDRwQIBP7yBgoFJwE3IBf9ABcgIBcBySByCgj+bggLCwgBkggKCgj+bggLCwgBkggKCgj+bggLCwgBkggKAqcECwYBDgQIBP65/aUXICAXA5IXIP7JFyD+XCQICgoIJAgLCwiSJAgLCwgkCAoKCJIlBwsLByUICgoIAAAAAAMAAAAAA5IDbgALABwAXAAANzQmIyIGFRQWMzI2ExEUBisBIiY1ETQ2OwEyFhUhFAYHHgEVFgYHFhQHDgEHFgYHDgErASImJy4BIy4BNRE0Njc+ATc+ATc+ATc+ATc+ATMyFhUUBgcOAQczMhYVkhUPEBUVEA8VXBYPpA8WFg+kDxYCpBEOBQMBDA0FBQQQCwMPEBI5Jkk+cS4bMA8PFhUOEEITEB0NEQ0FBQ8SBQ4HYCAVCwUIBJ8sQbcPFRUPEBUVATT+kw8WFg8BbQ8WFg8WLhENGAYWJxEQIhEQHAogNBMWFyAQCRABFQ8Bbg4VAgFNGBQkDREwGRkyEgUGciEjNBYKDQ5BLQAAAAADAAD/twOSAyUADAAcAFwAABMUBiMiJjU0NjMyFhUTETQmKwEiBhURFBY7ATI2JR4BFRQGKwEeARceARUUBiMiJicuAScuAScuAScuAScuATURNDYzPgE3PgE7AR4BFx4BBx4BFxYUBx4BBxQGB5IVDxAVFRAPFVwWD6QPFhYPpA8WAoUOEUEsnwQIBQsVIGAHDgUSDwUFDRENHRATQhAOFRYPDzAbLnE+SSY5EhAPAwsQBAUFDQwBAwUCbg8WFg8PFRUP/tsBbg8VFQ/+kg8VFWQQLhcsQg0OCRY1IyFxBgUSMhkZMBENIxQZTQEBFQ8Bbg8VAQ8KDyEBFhYTNCALGxARIhARKBUGGA4AAQAAAAADXANuADsAAAEhHgEVFAcOAQcGIyInLgEnJjU0Nz4BNzYzMhceARcWFwcuASMiBw4BBwYVFBceARcWMzI3PgE3NjcjNQG3AZ4DBB4eb05NX1tQUHcjIiIjd1BQWywpKUogIR13GVZAODIxShYVFRZKMTI4QS4tOw8PBPkB9hEjFV5PT3EgICIjd1BQW1tQUHciIwgIHhUVG3MYLBYWSzIzOToyM0sWFRQVOiEhGJcABgAA/7cDbgO3ABMAHAAmADsAUABgAAABHgEVERQGIyEiJjURNDYzITIWFwcVMy4BLwEuARMRIyImPQEhESEBPgEfAR4BDwEXFgYPAQYmLwEmNDchFhQPAQ4BLwEuAT8BJyY2PwE2FhcDLgE3Ez4BHwEeAQcDDgEnA0cQFyAX/QAXICAXAgAXNxBM1wMHA7IDDtXuFyD+SQLc/e0FDwYdBgIEaGgEAgYdBg8FgQMDAkwDA4IEDwYdBgMFaGgFAwYdBg8E4QcJAU8CDAckCAkCTwEMCALeEDcX/W4XICAXA5IXIBcQJ9cIDQOzAwf8mQJJIBfu/JICAAYCBRUFDwaLiwYPBBYFAgasBQwFBQwFrAYCBRYEDwaLiwYPBRUFAgb+TQEMCAHbBwkCBQIMB/4lCAgBAAABABL/yQPuA58AOgAAARQHDgEHBiMiJy4BJyY1NDc+ATc2NxUGBw4BBwYVFBceARcWMzI3PgE3NjU0Jy4BJyYnNRYXHgEXFhUD7icnhlpaZmZaWoYnJyEgcU1NWT81Nk4WFx0dY0NCTExCQ2MdHRcWTjY1P1lNTXEgIQG3ZlpahicnJyeGWlpmXVNTgisrDYINICFfOzxCTEJDYx0dHR1jQ0JMQjw7XyEgDYINKyuCU1NdAAACAAAAAANuA24AHAA5AAABIgcOAQcGFRQXHgEXFjMyNz4BNzY1NCcuAScmIwEUBw4BBwYjIicuAScmNTQ3PgE3NjMxMhceARcWAbdMQkNjHR0dHWNDQkxLQ0NjHR0dHWNDQ0sBtyMid1BQW1tQUHcjIiIjd1BQW1tQUHciIwMlHR1jQ0NLTEJDYx0dHR1jQ0JMS0NDYx0d/pJbUFB3IiMjIndQUFtbUFB3IiMjIndQUAAAAAAJAAAAAANuAyUAAwAUABgAHAAgADEAQgBGAEoAADcVIzUlMhYdARQGKwEiJj0BNDY7ATcVITUTFSM1ARUhNQMyFh0BFAYrASImPQE0NjsBATIWHQEUBisBIiY9ATQ2OwEXFSM1ExUhNcnJAZIPFhYPkg8WFg+SXP4SgIADbv5bgA8WFg+SDxYWD5IBbg8VFQ+SDxYWD5K3gID+EpJJSUkVD5IPFhYPkg8V3ElJASRJSf23SUkCkxYPkg8WFg+SDxb+2xYPkg8VFQ+SDxZJSUkBJElJAAMADf+3BIYDtwARACQAVQAAARYXHgEXFhcUBiMhFAYjIiY1FzI2NTQmIyImNTQmIyIGFRQWMwEWFAcBBiYvASY2PwEuATU2Nz4BNzY1NDc+ATc2Ny4BNTQ2MzIWFRQGBx4BFzc2FhcDegsTEy0aGhksHv8AVT08VpIEBQUEIjAFBAQFOykCPQQG+9IFEAQwBQEFawYFHyEhNBEREBE+LS05AgMgFxcgAgNKax3vBg8FAdBAMjFNHB0VHis8VlU9ZAUEBAUwIgQFBQQpOwOSBg8F/GEFAQY3Bg8FXAgTChsnJ3FNTWgpKSpFGRkJBQsGFyAgFwYLBQtMMs8FAQYAAAAEAA3/twSGA7cAEgAlAD0AbwAABTQmIyImNTQmIyIGFRQWMzI2NQkBLgEjIgcOAQcGFRQHDgEHBgcFFAYjIRQGIyImNTchLgEnNxYXHgEXFhcTFxYUBwEGJi8BJjY/AS4BNTY3PgE3NjU0Nz4BNzY3LgE1NDYzMhYVFAYHHgEXNzYWFwJSBQQiMAUEBAU7KQQF/s0B9hZkUjgpKjYNDQUFEw8PFAMGLB7/AFU9PFZVAbEwQRE/CxMTLRoaGTEwBAb70gUQBDAFAQVrBgUfISE0EREQET4tLTkCAyAXFyACA0prHe8GDwUSBAUwIgQFBQQpOwUEAQ8Bsi1JExI3ICAbNzMyXCopJmseKzxWVT1JNoNON0AyMU0cHRUDHDcGDwX8YQUBBjcGDwVcCBMKGycncU1NaCkpKkUZGQkFCwYXICAXBgsFC0wyzwUBBgAAAAACAAAAAASSA24ABQALAAAlFSERMxEBEyERCQEEkvtuSQNukvxJAQABSUlJA2782wJJ/gABSQFK/rYAAAADAAAAAAPbA7cAFwAgACkAAAkBBgcOAQcGIyInLgEnJjU0Nz4BNzYzERchFAcOAQcGBxMhETIXHgEXFgG3ATgeIyRPKywtW1BQdyMiIiN3UFBbawG5CQkhGRgeXv5JW1BQdyIjAbr+yB4YGCIJCSMid1BQW1tQUHciI/5MAy4rK1AjIx4BgQG3IyJ3UFAAAAADAAAASQSSAyUAGwA5AFcAAAE0Jy4BJyYjIgcOAQcGFRQXHgEXFjMyNz4BNzYlNCcuAScmKwEWFx4BFxYVFAcOAQcGBzMyNz4BNzY3FAcOAQcGIyEiJy4BJyY1NDc+ATc2MyEyFx4BFxYCkhcXTzY1PD01NVAXFxcXUDU1PTw1Nk8XFwG3FxdPNjU83SEcGyYLCgoLJhscId08NTZPFxdJHB1kQkNL/klMQ0JjHR0dHWNCQ0wBt0tDQmQdHAG3PDY1TxcXFxdPNTY8PTU1UBcXFxdQNTU9PDY1TxcXGSAgSykqLS0qKksgIBkXF1A1NT1MQkNjHR0dHWNDQkxLQ0NjHR0dHWNDQwACAAAASQSSAyUAHgA6AAATNDc+ATc2MyEyFx4BFxYVFAcOAQcGIyEiJy4BJyY1ATI3PgE3NjU0Jy4BJyYjIgcOAQcGFRQXHgEXFgAdHWNCQ0wBt0tDQmQdHBwdZEJDS/5JTENCYx0dAyU8NTZPFxcXF082NTw9NTVQFxcXF1A1NQG3S0NDYx0dHR1jQ0NLTEJDYx0dHR1jQ0JM/tsXF1A1NT08NjVPFxcXF081Njw9NTVQFxcAAAAABAAA/7cEAAO3ABYAKgA9AEkAAAEyFhceARclJgcOAQcGByc2Nz4BNzYzBRMWFx4BFxY3AyYnLgEnJjU0NjcFFhcWBgcGBw4BJxM2NzYmJyYnJzIWFRQGIyImNTQ2Af5Cgz1DZiD+WC0rK0gcHA+dJS0tZjg3OP5VwRQfH0wqKy2DXE9QdCEhLCcDiyEBATs5OlNDkkjoGQsMAg8PHr1IZWVISGVlA7ciIydtQBYDCwstIiEr8y0kIzEMDej+hikfICgHCAn+/g4tLYZWVmBNjzxgV1taqEhIMCcgAwFkJisrVSkpIgNlR0hlZUhHZQAAAwAAAAADbgNuABAAIQA9AAABETQmKwEiBhURFBY7ATI2NSERNCYrASIGFREUFjsBMjY1NxQHDgEHBiMiJy4BJyY1NDc+ATc2MzIXHgEXFgGSCgiSCAsLCJIICgEACgiSCAsLCJIICtwjIndQUFtbUFB3IyIiI3dQUFtbUFB3IiMBEgFJCAsLCP63BwsLBwFJCAsLCP63BwsLB6VbUFB3IiMjIndQUFtbUFB3IiMjIndQUAAABAAAAAADbgNuABwAOABJAFkAAAEyFx4BFxYVFAcOAQcGIyInLgEnJjU0Nz4BNzYzETI3PgE3NjU0Jy4BJyYjIgcOAQcGFRQXHgEXFjciJjURNDY7ATIWFREUBisBIyImNRE0NjsBMhYVERQGIwG3W1BQdyIjIyJ3UFBbW1BQdyMiIiN3UFBbQDk4VRgZGRhVODlAQDk5VBkYGBlUOTl3CAsLCG0ICwsIbdwHCwsHbggKCggDbiMid1BQW1tQUHciIyMid1BQW1tQUHciI/0SGBlUOTlAQDk4VRgZGRhVODlAQDk5VBkYgAsHAUkICwsI/rcHCwsHAUkICwsI/rcHCwAAAAACABMAAAPtA24AAwBoAAABNyMHAQcOASsBBzMyFhceAQ8BDgErAQcOASsBIiYnLgE/ASMHDgErASImJy4BPwEjIiYnLgE/AT4BOwE3IyImJy4BPwE+ATsBNz4BOwEyFhceAQ8BMzc+ATsBMhYXHgEPATMyFhceAQcCNiWRJQJIIAIJB7olsgQHAwMCAiABCga7LgIKBoAECAMDAQEskS4CCgaBAwgDAgIBLLEFBwMCAgEgAgkHuiWyBAcDAwICIAEKBrsuAgoHgAQHAwMBASyRLgIKB4ADCAMCAgEssQUHAwICAQFukpIBIIAGCJIEAwQIBIAGCLsGCAQDAwkEsrsGCAQDAwkEsgQDAwkEgAYIkgQDAwkEgAYIuwYIBAMECASyuwYIBAMECASyBAMECAQABAAAAAADbgNuABAARABhAH4AAAEVFAYrASImPQE0NjsBMhYVExQGBw4BHQEUBisBIiY9ATQ2Nz4BNTQmIyIGBw4BBw4BIyImLwEuATc+ATMxMhceARcWFQMiBw4BBwYVFBceARcWMzI3PgE3NjU0Jy4BJyYjARQHDgEHBiMiJy4BJyY1NDc+ATc2MzEyFx4BFxYB9wsHXAgKCghcBwuSQx8WGgsHXAgKPB8ZHjMcDx4KCRQQAwcFAwUCPgYCBCNjQSMkIzkSEtJMQkNjHR0dHWNDQkxLQ0NjHR0dHWNDQ0sBtyMid1BQW1tQUHcjIiIjd1BQW1tQUHciIwEJWwgLCwhbCAoKCAEcPToSDRQNEwcLCwcnNSwODBUUGSAIBwYWEwQDAQIvBA8GNzYNDS8fICUBAB0dY0NDS0xCQ2MdHR0dY0NCTEtDQ2MdHf6SW1BQdyIjIyJ3UFBbW1BQdyIjIyJ3UFAAAAAAAgAA/7cEAAO3ABsAQgAAAREUBiMhIiY1ETQ2Nz4BNz4BMzIWFx4BFx4BFQE+ATc+AS8BLgEHDgEHDgEjIiYnLgEnJgYPAQYWFx4BFx4BMzI2NwQANiX8tiU2AwMtWuAbVCQkVBvgWi0DA/6+Q2AiBgIFFQUPBiJfQxtUJCRUG0NfIgYPBRUFAgYiYEMiZDg5ZSACQf3RJTY2JQIvBAcDJ0qjFEBAFKNKJwMHBP6yMEYaBA8GHgYCBRlGMBNAQBMxRRkFAgYeBg8EGkYwGElKFwAAAAADAAD/twQAA7cAMABHAGwAAAEXFgYHBgcOAQcGBw4BKwEiJicmJy4BJyYnLgE/AT4BFx4BFx4BOwEyNjc+ATc2FhcTES4BJy4BKwEiBgcOAQcRFBYzITI2NRMRFAYjISImNRE0Njc2Nz4BNzY3PgE7ATIWFxYXHgEXFhceARUDShcEAgUWICA9FxYDHlAsAixQHgMWFjsfIBUGAgUVBQ8GHlQ9FkkeAh5JFj9WHgYPBG0rSMYWSR4CHkkWxkgrCwcDSgcLSTYl/LYlNgwLLC4vVygnHx5QLAIsUB4dJyhZLy8rCwwBrR0GDgURGRkvERIBGTY2GQERES4YGRAFDgYeBgIFF0EvEDs7EDFCGAQCBv5lAhMnPJoQPDwQmjwn/e0HCwsHAhP97SU2NiUCEw8cCikmJkQeHhkZNjYZFx4fRSYnKAocDwAAAwAA/7cEkgO3AAMADQAnAAA3IREhKQERIRUzMhYdAQERFAYjIRUUBiMhIiY1ETQ2MyE1NDYzITIWkgG3/kkCSQEl/kk3JjUBtzUm/qQ1Jv3bJTY2JQFcNiUCJSY1SQElAbeTNSbJAe393CY2ySU2NiUCJSY1ySY2NgAAAAEAAAABAACd4j4xXw889QALBAAAAAAA3eu5mQAAAADd67mZAAD/twSSA7cAAAAIAAIAAAAAAAAAAQAAA8D/wAAABJIAAAAABJIAAQAAAAAAAAAAAAAAAAAAAG0EAAAAAAAAAAAAAAACAAAABAAAAAO3AAAEAAAABAAAAAO3AAADtwAAAtsAAAO3AAAEAAAABAAAAAQAAEUDJQA/A24AAANuAAADJQAAA7cAEwNuAAADbgAAA7cAAANuAAADbgAAA24AAAQAAAADYgAABD0AAAQAAAADYgAAAkkAAAQBAAADuwAAAykAAANuAAADbgAAAwAAYwK3AD4DbgAAA24AAAMlAAADtwBNA24AAAQAAAkEAAA+BAAAPgSSAAAESQAABAAAAAMlAAAEAAAlA24AAQMlAAMDbgAABEkAAAO3AAkDbgAAA7cAAAJJAAACSQAAAZIAJQFJAAACSQAAAkkAAAJJAAAEAAAABAAAJQNuAAACWwAaAjcABwGAABoBWwAHBEkAAAKSAAADbgAABAAAJQNuAAADvQANBEkAHwJJAAACewA6AtsAAAMlAAAA2wAAA24AAANuAAADbgAAA5IAAAOSAAADXAAAA24AAAQAABIDbgAAA24AAASSAA0EkgANBJIAAAPbAAAEkgAABJIAAAQ3AAADbgAAA24AAAQAABMDbgAABAAAAAQAAAAEkgAAAAAAAAAKABQAHgA6AKABCgFQAZoB9gJMAqgDZAPmBCQEgATyBcgGXAa4BvYHaAfeCFgIzAlgChAKUAq8C2gLvAv8DIgNAA0cDVANbg2YDcQOTA62DugPOg+eD/oQJBBQEIASWBLEEvYTihQmFFwU4hWiFl4Wohd2F54XxBfsGBQYXBiEGKwZTBm2GjYaqBsaG1gblhvcHCAceh0GHTYddB3cHlwevB7+H0IfhB/WICIgkiEYIZ4h+CKSIuwjRiOwJDAk2CT2JT4lwiYeJpYm8CdyKAoovikoKcwqCgABAAAAbQFVAAoAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAADgCuAAEAAAAAAAEAAgAAAAEAAAAAAAIABwAzAAEAAAAAAAMAAgAnAAEAAAAAAAQAAgBIAAEAAAAAAAUACwAGAAEAAAAAAAYAAgAtAAEAAAAAAAoAGgBOAAMAAQQJAAEABAACAAMAAQQJAAIADgA6AAMAAQQJAAMABAApAAMAAQQJAAQABABKAAMAAQQJAAUAFgARAAMAAQQJAAYABAAvAAMAAQQJAAoANABoZmEAZgBhVmVyc2lvbiAxLjAAVgBlAHIAcwBpAG8AbgAgADEALgAwZmEAZgBhZmEAZgBhUmVndWxhcgBSAGUAZwB1AGwAYQByZmEAZgBhRm9udCBnZW5lcmF0ZWQgYnkgSWNvTW9vbi4ARgBvAG4AdAAgAGcAZQBuAGUAcgBhAHQAZQBkACAAYgB5ACAASQBjAG8ATQBvAG8AbgAuAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==) format('woff'); + font-weight: normal; + font-style: normal; + font-display: block; +} +[class^="fa-"], [class*=" fa-"] { + font-family: 'fa' !important; + speak: never; + font-style: normal; + font-weight: normal; + font-variant: normal; + text-transform: none; + line-height: 1; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} +.fa-spin { + -webkit-animation: fa-spin 2s infinite linear; + animation: fa-spin 2s infinite linear +} +@-webkit-keyframes "fa-spin" { + 0% { + -webkit-transform: rotate(0deg); + transform: rotate(0deg); + } + + 100% { + -webkit-transform: rotate(359deg); + transform: rotate(359deg); + } +} +@keyframes "fa-spin" { + 0% { + -webkit-transform: rotate(0deg); + transform: rotate(0deg); + } + + 100% { + -webkit-transform: rotate(359deg); + transform: rotate(359deg); + } +} +.fa-asterisk:before { + content: "\f069"; +} +.fa-plus:before { + content: "\f067"; +} +.fa-question:before { + content: "\f128"; +} +.fa-search:before { + content: "\f002"; +} +.fa-envelope-o:before { + content: "\f003"; +} +.fa-heart:before { + content: "\f004"; +} +.fa-star:before { + content: "\f005"; +} +.fa-star-o:before { + content: "\f006"; +} +.fa-user:before { + content: "\f007"; +} +.fa-th-large:before { + content: "\f009"; +} +.fa-th:before { + content: "\f00a"; +} +.fa-th-list:before { + content: "\f00b"; +} +.fa-check:before { + content: "\f00c"; +} +.fa-close:before { + content: "\f00d"; +} +.fa-remove:before { + content: "\f00d"; +} +.fa-times:before { + content: "\f00d"; +} +.fa-power-off:before { + content: "\f011"; +} +.fa-cog:before { + content: "\f013"; +} +.fa-gear:before { + content: "\f013"; +} +.fa-trash-o:before { + content: "\f014"; +} +.fa-home:before { + content: "\f015"; +} +.fa-file-o:before { + content: "\f016"; +} +.fa-clock-o:before { + content: "\f017"; +} +.fa-download:before { + content: "\f019"; +} +.fa-play-circle-o:before { + content: "\f01d"; +} +.fa-repeat:before { + content: "\f01e"; +} +.fa-rotate-right:before { + content: "\f01e"; +} +.fa-refresh:before { + content: "\f021"; +} +.fa-list-alt:before { + content: "\f022"; +} +.fa-tag:before { + content: "\f02b"; +} +.fa-tags:before { + content: "\f02c"; +} +.fa-list:before { + content: "\f03a"; +} +.fa-pencil:before { + content: "\f040"; +} +.fa-map-marker:before { + content: "\f041"; +} +.fa-edit:before { + content: "\f044"; +} +.fa-pencil-square-o:before { + content: "\f044"; +} +.fa-check-square-o:before { + content: "\f046"; +} +.fa-play:before { + content: "\f04b"; +} +.fa-pause:before { + content: "\f04c"; +} +.fa-stop:before { + content: "\f04d"; +} +.fa-chevron-left:before { + content: "\f053"; +} +.fa-chevron-right:before { + content: "\f054"; +} +.fa-question-circle:before { + content: "\f059"; +} +.fa-info-circle:before { + content: "\f05a"; +} +.fa-exclamation-circle:before { + content: "\f06a"; +} +.fa-exclamation-triangle:before { + content: "\f071"; +} +.fa-warning:before { + content: "\f071"; +} +.fa-chevron-up:before { + content: "\f077"; +} +.fa-chevron-down:before { + content: "\f078"; +} +.fa-bar-chart:before { + content: "\f080"; +} +.fa-bar-chart-o:before { + content: "\f080"; +} +.fa-cogs:before { + content: "\f085"; +} +.fa-gears:before { + content: "\f085"; +} +.fa-external-link:before { + content: "\f08e"; +} +.fa-square-o:before { + content: "\f096"; +} +.fa-bell-o:before { + content: "\f0a2"; +} +.fa-certificate:before { + content: "\f0a3"; +} +.fa-filter:before { + content: "\f0b0"; +} +.fa-arrows-alt:before { + content: "\f0b2"; +} +.fa-group:before { + content: "\f0c0"; +} +.fa-users:before { + content: "\f0c0"; +} +.fa-chain:before { + content: "\f0c1"; +} +.fa-link:before { + content: "\f0c1"; +} +.fa-bars:before { + content: "\f0c9"; +} +.fa-navicon:before { + content: "\f0c9"; +} +.fa-reorder:before { + content: "\f0c9"; +} +.fa-table:before { + content: "\f0ce"; +} +.fa-caret-down:before { + content: "\f0d7"; +} +.fa-caret-up:before { + content: "\f0d8"; +} +.fa-caret-left:before { + content: "\f0d9"; +} +.fa-caret-right:before { + content: "\f0da"; +} +.fa-sort:before { + content: "\f0dc"; +} +.fa-unsorted:before { + content: "\f0dc"; +} +.fa-sort-desc:before { + content: "\f0dd"; +} +.fa-sort-down:before { + content: "\f0dd"; +} +.fa-sort-asc:before { + content: "\f0de"; +} +.fa-sort-up:before { + content: "\f0de"; +} +.fa-dashboard:before { + content: "\f0e4"; +} +.fa-tachometer:before { + content: "\f0e4"; +} +.fa-bell:before { + content: "\f0f3"; +} +.fa-file-text-o:before { + content: "\f0f6"; +} +.fa-angle-double-left:before { + content: "\f100"; +} +.fa-angle-double-right:before { + content: "\f101"; +} +.fa-angle-left:before { + content: "\f104"; +} +.fa-angle-right:before { + content: "\f105"; +} +.fa-desktop:before { + content: "\f108"; +} +.fa-tablet:before { + content: "\f10a"; +} +.fa-circle-o:before { + content: "\f10c"; +} +.fa-spinner:before { + content: "\f110"; +} +.fa-circle:before { + content: "\f111"; +} +.fa-terminal:before { + content: "\f120"; +} +.fa-code:before { + content: "\f121"; +} +.fa-code-fork:before { + content: "\f126"; +} +.fa-shield:before { + content: "\f132"; +} +.fa-ellipsis-h:before { + content: "\f141"; +} +.fa-ellipsis-v:before { + content: "\f142"; +} +.fa-play-circle:before { + content: "\f144"; +} +.fa-external-link-square:before { + content: "\f14c"; +} +.fa-file-text:before { + content: "\f15c"; +} +.fa-thumbs-up:before { + content: "\f164"; +} +.fa-thumbs-down:before { + content: "\f165"; +} +.fa-google:before { + content: "\f1a0"; +} +.fa-file-code-o:before { + content: "\f1c9"; +} +.fa-circle-o-notch:before { + content: "\f1ce"; +} +.fa-circle-thin:before { + content: "\f1db"; +} +.fa-sliders:before { + content: "\f1de"; +} +.fa-bell-slash:before { + content: "\f1f6"; +} +.fa-bell-slash-o:before { + content: "\f1f7"; +} +.fa-area-chart:before { + content: "\f1fe"; +} +.fa-pie-chart:before { + content: "\f200"; +} +.fa-toggle-off:before { + content: "\f204"; +} +.fa-toggle-on:before { + content: "\f205"; +} +.fa-chrome:before { + content: "\f268"; +} +.fa-pause-circle:before { + content: "\f28b"; +} +.fa-pause-circle-o:before { + content: "\f28c"; +} +.fa-hashtag:before { + content: "\f292"; +} +.fa-question-circle-o:before { + content: "\f29c"; +} +.fa-envelope-open:before { + content: "\f2b6"; +} +.fa-envelope-open-o:before { + content: "\f2b7"; +} +.fa-window-restore:before { + content: "\f2d2"; +} +.fa-minus:before { + content: "\ea0b"; +} diff --git a/resources/goaccess.svg b/resources/goaccess.svg new file mode 100644 index 0000000000..1db9ffb9c7 --- /dev/null +++ b/resources/goaccess.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/resources/js/app.js b/resources/js/app.js new file mode 100644 index 0000000000..ecc959792a --- /dev/null +++ b/resources/js/app.js @@ -0,0 +1,1955 @@ +/*jshint sub:true*/ +(function () { +'use strict'; + +// Syntactic sugar +function $(selector) { + return document.querySelector(selector); +} + +// Syntactic sugar & execute callback +function $$(selector, callback) { + var elems = document.querySelectorAll(selector); + for (var i = 0; i < elems.length; ++i) { + if (callback && typeof callback == 'function') + callback.call(this, elems[i]); + } +} + +var debounce = function (func, wait, now) { + var timeout; + return function debounced () { + var that = this, args = arguments; + function delayed() { + if (!now) + func.apply(that, args); + timeout = null; + } + if (timeout) { + clearTimeout(timeout); + } else if (now) { + func.apply(obj, args); + } + timeout = setTimeout(delayed, wait || 250); + }; +}; + +// global namespace +window.GoAccess = window.GoAccess || { + initialize: function (options) { + this.opts = options; + var cw = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0); + + this.AppState = {}; // current state app key-value store + this.AppTpls = {}; // precompiled templates + this.AppCharts = {}; // holds all rendered charts + this.AppUIData = (this.opts || {}).uiData || {}; // holds panel definitions + this.AppData = (this.opts || {}).panelData || {}; // hold raw data + this.AppWSConn = (this.opts || {}).wsConnection || {}; // WebSocket connection + this.i18n = (this.opts || {}).i18n || {}; // i18n report labels + this.AppPrefs = { + 'autoHideTables': true, + 'layout': cw > 2560 ? 'wide' : 'horizontal', + 'perPage': 7, + 'theme': (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) ? 'darkPurple' : 'bright', + 'hiddenPanels': [], + }; + this.AppPrefs = GoAccess.Util.merge(this.AppPrefs, this.opts.prefs); + + // WebSocket reconnection + this.wsDelay = this.currDelay = 1E3; + this.maxDelay = 20E3; + this.retries = 0; + this.maxRetries = 20; + + if (GoAccess.Util.hasLocalStorage()) { + var ls = JSON.parse(localStorage.getItem('AppPrefs')); + this.AppPrefs = GoAccess.Util.merge(this.AppPrefs, ls); + } + if (Object.keys(this.AppWSConn).length) + this.setWebSocket(this.AppWSConn); + + }, + + getPanelUI: function (panel) { + return panel ? this.AppUIData[panel] : this.AppUIData; + }, + + getPrefs: function (panel) { + return panel ? this.AppPrefs[panel] : this.AppPrefs; + }, + + setPrefs: function () { + if (GoAccess.Util.hasLocalStorage()) { + localStorage.setItem('AppPrefs', JSON.stringify(GoAccess.getPrefs())); + } + }, + + getPanelData: function (panel) { + return panel ? this.AppData[panel] : this.AppData; + }, + + reconnect: function (wsConn) { + if (this.retries >= this.maxRetries) + return window.clearTimeout(this.wsTimer); + + this.retries++; + if (this.currDelay < this.maxDelay) + this.currDelay *= 2; // Exponential backoff + this.setWebSocket(wsConn); + }, + + buildWSURI: function (wsConn) { + var url = null; + if (!wsConn.url || !wsConn.port) + return null; + url = /^wss?:\/\//i.test(wsConn.url) ? wsConn.url : window.location.protocol === "https:" ? 'wss://' + wsConn.url : 'ws://' + wsConn.url; + return new URL(url).protocol + '//' + new URL(url).hostname + ':' + wsConn.port + new URL(url).pathname; + }, + + setWebSocket: function (wsConn) { + var host = null, pingId = null, uri = null, defURI = null, str = null; + + defURI = window.location.hostname ? window.location.hostname + ':' + wsConn.port : "localhost" + ':' + wsConn.port; + uri = wsConn.url && /^(wss?:\/\/)?[^\/]+:[0-9]{1,5}/.test(wsConn.url) ? wsConn.url : this.buildWSURI(wsConn); + + str = uri || defURI; + str = !/^wss?:\/\//i.test(str) ? (window.location.protocol === "https:" ? 'wss://' : 'ws://') + str : str; + + var socket = new WebSocket(str); + socket.onopen = function (event) { + this.currDelay = this.wsDelay; + this.retries = 0; + + // attempt to keep connection alive (e.g., ping/pong) + if (wsConn.ping_interval) + pingId = setInterval(() => { socket.send('ping'); }, wsConn.ping_interval * 1E3); + + GoAccess.Nav.WSOpen(str); + }.bind(this); + + socket.onmessage = function (event) { + this.AppState['updated'] = true; + this.AppData = JSON.parse(event.data); + this.App.renderData(); + }.bind(this); + + socket.onclose = function (event) { + GoAccess.Nav.WSClose(); + window.clearInterval(pingId); + socket = null; + this.wsTimer = setTimeout(() => { this.reconnect(wsConn); }, this.currDelay); + }.bind(this); + }, +}; + +// HELPERS +GoAccess.Util = { + months: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul","Aug", "Sep", "Oct", "Nov", "Dec"], + + // Add all attributes of n to o + merge: function (o, n) { + var obj = {}, i = 0, il = arguments.length, key; + for (; i < il; i++) { + for (key in arguments[i]) { + if (arguments[i].hasOwnProperty(key)) { + obj[key] = arguments[i][key]; + } + } + } + return obj; + }, + + // hash a string + hashCode: function (s) { + return (s.split('').reduce(function (a, b) { + a = ((a << 5) - a) + b.charCodeAt(0); + return a&a; + }, 0) >>> 0).toString(16); + }, + + // Format bytes to human-readable + formatBytes: function (bytes, decimals, numOnly) { + if (bytes == 0) + return numOnly ? 0 : '0 Byte'; + var k = 1024; + var dm = decimals + 1 || 2; + var sizes = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']; + var i = Math.floor(Math.log(bytes) / Math.log(k)); + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + (numOnly ? '' : (' ' + sizes[i])); + }, + + // Validate number + isNumeric: function (n) { + return !isNaN(parseFloat(n)) && isFinite(n); + }, + + // Format microseconds to human-readable + utime2str: function (usec) { + if (usec >= 864E8) + return ((usec) / 864E8).toFixed(2) + ' d'; + else if (usec >= 36E8) + return ((usec) / 36E8).toFixed(2) + ' h'; + else if (usec >= 6E7) + return ((usec) / 6E7).toFixed(2) + ' m'; + else if (usec >= 1E6) + return ((usec) / 1E6).toFixed(2) + ' s'; + else if (usec >= 1E3) + return ((usec) / 1E3).toFixed(2) + ' ms'; + return (usec).toFixed(2) + ' us'; + }, + + // Format date from 20120124 to 24/Jan/2012 + formatDate: function (str) { + var y = str.substr(0,4), m = str.substr(4,2) - 1, d = str.substr(6,2), + h = str.substr(8,2) || 0, i = str.substr(10, 2) || 0, s = str.substr(12, 2) || 0; + var date = new Date(y,m,d,h,i,s); + + var out = ('0' + date.getDate()).slice(-2) + '/' + this.months[date.getMonth()] + '/' + date.getFullYear(); + 10 <= str.length && (out += ":" + h); + 12 <= str.length && (out += ":" + i); + 14 <= str.length && (out += ":" + s); + return out; + }, + + shortNum: function (n) { + if (n < 1e3) return n; + if (n >= 1e3 && n < 1e6) return +(n / 1e3).toFixed(1) + "K"; + if (n >= 1e6 && n < 1e9) return +(n / 1e6).toFixed(1) + "M"; + if (n >= 1e9 && n < 1e12) return +(n / 1e9).toFixed(1) + "B"; + if (n >= 1e12) return +(n / 1e12).toFixed(1) + "T"; + }, + + // Format field value to human-readable + fmtValue: function (value, dataType, decimals, shorten, hlregex, hlvalue) { + var val = 0; + if (!dataType) + val = value; + + switch (dataType) { + case 'utime': + val = this.utime2str(+value); + break; + case 'date': + val = this.formatDate(value); + break; + case 'numeric': + if (this.isNumeric(value)) + val = shorten ? this.shortNum(value) : (+value).toLocaleString(); + break; + case 'bytes': + val = this.formatBytes(value, decimals); + break; + case 'percent': + val = value.replace(',', '.') + '%'; + break; + case 'time': + if (this.isNumeric(value)) + val = value.toLocaleString(); + break; + case 'secs': + var t = new Date(null); + t.setSeconds(value); + val = t.toISOString().substr(11, 8); + break; + default: + val = value; + } + + if (hlregex) { + let o = JSON.parse(hlregex), tmp = ''; + for (var x in o) { + if (!val) continue; + tmp = val.replace(new RegExp(x, 'gi'), o[x]); + if (tmp != val) { + val = tmp; + break; + } + val = tmp; + } + } + + return value == 0 ? String(val) : (val === undefined ? '—' : val); + }, + + isPanelHidden: function (panel) { + return GoAccess.AppPrefs.hiddenPanels.includes(panel); + }, + + isPanelValid: function (panel) { + var data = GoAccess.getPanelData(), ui = GoAccess.getPanelUI(); + return (!ui.hasOwnProperty(panel) || !data.hasOwnProperty(panel) || !ui[panel].id); + }, + + // Attempts to extract the count from either an object or a scalar. + // e.g., item = Object {count: 14351, percent: 5.79} OR item = 4824825140 + getCount: function (item) { + if (this.isObject(item) && 'count' in item) + return item.count; + return item; + }, + + getPercent: function (item) { + if (this.isObject(item) && 'percent' in item) + return this.fmtValue(item.percent, 'percent'); + return null; + }, + + isObject: function (o) { + return o === Object(o); + }, + + setProp: function (o, s, v) { + var schema = o; + var a = s.split('.'); + for (var i = 0, n = a.length; i < n-1; ++i) { + var k = a[i]; + if (!schema[k]) + schema[k] = {}; + schema = schema[k]; + } + schema[a[n-1]] = v; + }, + + getProp: function (o, s) { + s = s.replace(/\[(\w+)\]/g, '.$1'); + s = s.replace(/^\./, ''); + var a = s.split('.'); + for (var i = 0, n = a.length; i < n; ++i) { + var k = a[i]; + if (this.isObject(o) && k in o) { + o = o[k]; + } else { + return; + } + } + return o; + }, + + hasLocalStorage: function () { + try { + localStorage.setItem('test', 'test'); + localStorage.removeItem('test'); + return true; + } catch(e) { + return false; + } + }, + + isWithinViewPort: function (el) { + var elemTop = el.getBoundingClientRect().top; + var elemBottom = el.getBoundingClientRect().bottom; + return elemTop < window.innerHeight && elemBottom >= 0; + }, + + togglePanel: function(panel) { + var index = GoAccess.AppPrefs.hiddenPanels.indexOf(panel); + if (index == -1) { + GoAccess.AppPrefs.hiddenPanels.push(panel); + } else { + GoAccess.AppPrefs.hiddenPanels.splice(index, 1); + } + GoAccess.setPrefs(); + + delete GoAccess.AppCharts[panel]; + GoAccess.OverallStats.initialize(); + GoAccess.Panels.initialize(); + GoAccess.Charts.initialize(); + GoAccess.Tables.initialize(); + }, +}; + +// OVERALL STATS +GoAccess.OverallStats = { + total_requests: 0, + + // Render each overall stats box + renderBox: function (data, ui, row, x, idx) { + var wrap = $('.wrap-general-items'); + + // create a new bootstrap row every 6 elements + if (idx % 6 == 0) { + row = document.createElement('div'); + row.setAttribute('class', 'row'); + wrap.appendChild(row); + } + + var box = document.createElement('div'); + box.innerHTML = GoAccess.AppTpls.General.items.render({ + 'id': x, + 'className': ui.items[x].className, + 'label': ui.items[x].label, + 'value': GoAccess.Util.fmtValue(data[x], ui.items[x].dataType), + }); + row.appendChild(box); + + return row; + }, + + // Render overall stats + renderData: function (data, ui) { + var idx = 0, row = null; + + $('.last-updated').innerHTML = data.date_time; + $('.wrap-general').innerHTML = ''; + + if (GoAccess.Util.isPanelHidden('general')) + return false; + + $('.wrap-general').innerHTML = GoAccess.AppTpls.General.wrap.render(GoAccess.Util.merge(ui, { + 'from': data.start_date, + 'to': data.end_date, + })); + + // Iterate over general data object + for (var x in data) { + if (!data.hasOwnProperty(x) || !ui.items.hasOwnProperty(x)) + continue; + row = this.renderBox(data, ui, row, x, idx); + idx++; + } + }, + + // Render general/overall analyzed requests. + initialize: function () { + var ui = GoAccess.getPanelUI('general'); + var data = GoAccess.getPanelData('general'); + this.total_requests = data.total_requests; + + this.renderData(data, ui); + } +}; + +// RENDER PANELS +GoAccess.Nav = { + events: function () { + $('.nav-bars').onclick = function (e) { + e.stopPropagation(); + this.renderMenu(e); + }.bind(this); + + $('.nav-gears').onclick = function (e) { + e.stopPropagation(); + this.renderOpts(e); + }.bind(this); + + $('.nav-minibars').onclick = function (e) { + e.stopPropagation(); + this.renderOpts(e); + }.bind(this); + + $('body').onclick = function (e) { + $('nav').classList.remove('active'); + }.bind(this); + + $$('.export-json', function (item) { + item.onclick = function (e) { + this.downloadJSON(e); + }.bind(this); + }.bind(this)); + + $$('.theme-bright', function (item) { + item.onclick = function (e) { + this.setTheme('bright'); + }.bind(this); + }.bind(this)); + + $$('.theme-dark-blue', function (item) { + item.onclick = function (e) { + this.setTheme('darkBlue'); + }.bind(this); + }.bind(this)); + + $$('.theme-dark-gray', function (item) { + item.onclick = function (e) { + this.setTheme('darkGray'); + }.bind(this); + }.bind(this)); + + $$('.theme-dark-purple', function (item) { + item.onclick = function (e) { + this.setTheme('darkPurple'); + }.bind(this); + }.bind(this)); + + $$('.layout-horizontal', function (item) { + item.onclick = function (e) { + this.setLayout('horizontal'); + }.bind(this); + }.bind(this)); + + $$('.layout-vertical', function (item) { + item.onclick = function (e) { + this.setLayout('vertical'); + }.bind(this); + }.bind(this)); + + $$('.layout-wide', function (item) { + item.onclick = function (e) { + this.setLayout('wide'); + }.bind(this); + }.bind(this)); + + $$('[data-perpage]', function (item) { + item.onclick = function (e) { + this.setPerPage(e); + }.bind(this); + }.bind(this)); + + $$('[data-show-tables]', function (item) { + item.onclick = function (e) { + this.toggleTables(); + }.bind(this); + }.bind(this)); + + $$('[data-autohide-tables]', function (item) { + item.onclick = function (e) { + this.toggleAutoHideTables(); + }.bind(this); + }.bind(this)); + + $$('.toggle-panel', function (item) { + item.onclick = function (e) { + e.stopPropagation(); + var panel = e.currentTarget.getAttribute('data-panel'); + GoAccess.Util.togglePanel(panel); + item.classList.toggle('active'); + }.bind(this); + }.bind(this)); + }, + + downloadJSON: function (e) { + var targ = e.currentTarget; + var data = "text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(GoAccess.getPanelData())); + targ.href = 'data:' + data; + targ.download = 'goaccess-' + (+new Date()) + '.json'; + }, + + setLayout: function (layout) { + if (('horizontal' == layout || 'wide' == layout) && $('.container')) { + $('.container').classList.add('container-fluid'); + $('.container').classList.remove('container'); + } else if ('vertical' == layout && $('.container-fluid')) { + $('.container-fluid').classList.add('container'); + $('.container').classList.remove('container-fluid'); + } + + GoAccess.AppPrefs['layout'] = layout; + GoAccess.setPrefs(); + + GoAccess.Panels.initialize(); + GoAccess.Charts.initialize(); + GoAccess.Tables.initialize(); + }, + + toggleAutoHideTables: function (e) { + var autoHideTables = GoAccess.Tables.autoHideTables(); + $$('.table-wrapper', function (item) { + if (autoHideTables) { + item.classList.remove('hidden-xs'); + } else { + item.classList.add('hidden-xs'); + } + }.bind(this)); + + GoAccess.AppPrefs['autoHideTables'] = !autoHideTables; + GoAccess.setPrefs(); + }, + + toggleTables: function () { + var ui = GoAccess.getPanelUI(); + var showTables = GoAccess.Tables.showTables(); + Object.keys(ui).forEach(function (panel, idx) { + if (!GoAccess.Util.isPanelValid(panel) || GoAccess.Util.isPanelHidden(panel)) + ui[panel]['table'] = !showTables; + }.bind(this)); + + GoAccess.AppPrefs['showTables'] = !showTables; + GoAccess.setPrefs(); + + GoAccess.Panels.initialize(); + GoAccess.Charts.initialize(); + GoAccess.Tables.initialize(); + }, + + setTheme: function (theme) { + if (!theme) + return; + + $('html').className = ''; + switch(theme) { + case 'darkGray': + $('html').classList.add('dark'); + $('html').classList.add('gray'); + break; + case 'darkBlue': + $('html').classList.add('dark'); + $('html').classList.add('blue'); + break; + case 'darkPurple': + $('html').classList.add('dark'); + $('html').classList.add('purple'); + break; + } + GoAccess.AppPrefs['theme'] = theme; + GoAccess.setPrefs(); + }, + + getIcon: function (key) { + switch(key) { + case 'visitors' : return 'users'; + case 'requests' : return 'file'; + case 'static_requests' : return 'file-text'; + case 'not_found' : return 'file-o'; + case 'hosts' : return 'user'; + case 'os' : return 'desktop'; + case 'browsers' : return 'chrome'; + case 'visit_time' : return 'clock-o'; + case 'vhosts' : return 'th-list'; + case 'referrers' : return 'external-link'; + case 'referring_sites' : return 'external-link'; + case 'keyphrases' : return 'google'; + case 'status_codes' : return 'warning'; + case 'remote_user' : return 'users'; + case 'geolocation' : return 'map-marker'; + case 'asn' : return 'map-marker'; + case 'mime_type' : return 'file-o'; + case 'tls_type' : return 'warning'; + default : return 'pie-chart'; + } + }, + + getItems: function () { + var ui = GoAccess.getPanelUI(), menu = []; + for (var panel in ui) { + if (GoAccess.Util.isPanelValid(panel)) + continue; + // Push valid panels to our navigation array + menu.push({ + 'current': window.location.hash.substr(1) == panel, + 'head': ui[panel].head, + 'key': panel, + 'icon': this.getIcon(panel), + 'hidden': GoAccess.Util.isPanelHidden(panel) + }); + } + return menu; + }, + + setPerPage: function (e) { + GoAccess.AppPrefs['perPage'] = +e.currentTarget.getAttribute('data-perpage'); + GoAccess.App.renderData(); + GoAccess.setPrefs(); + + GoAccess.Tables.initialize(); + }, + + getTheme: function () { + return GoAccess.AppPrefs.theme || 'darkGray'; + }, + + getLayout: function () { + return GoAccess.AppPrefs.layout || 'horizontal'; + }, + + getPerPage: function () { + return GoAccess.AppPrefs.perPage || 7; + }, + + // Render left-hand side navigation options. + renderOpts: function () { + var o = {}; + o[this.getLayout()] = true; + o[this.getTheme()] = true; + o['perPage' + this.getPerPage()] = true; + o['autoHideTables'] = GoAccess.Tables.autoHideTables(); + o['showTables'] = GoAccess.Tables.showTables(); + o['labels'] = GoAccess.i18n; + + $('.nav-list').innerHTML = GoAccess.AppTpls.Nav.opts.render(o); + requestAnimationFrame(function () { + $('nav').classList.toggle('active'); + }); + this.events(); + }, + + // Render left-hand side navigation given the available panels. + renderMenu: function (e) { + $('.nav-list').innerHTML = GoAccess.AppTpls.Nav.menu.render({ + 'nav': this.getItems(), + 'overall_current': window.location.hash.substr(1) == '', + 'overall_hidden': GoAccess.Util.isPanelHidden('general'), + 'labels': GoAccess.i18n, + }); + requestAnimationFrame(function () { + $('nav').classList.toggle('active'); + }); + this.events(); + }, + + WSStatus: function () { + if (Object.keys(GoAccess.AppWSConn).length) + $$('.nav-ws-status', function (item) { item.style.display = 'block'; }); + }, + + WSClose: function () { + $$('.nav-ws-status', function (item) { + item.classList.remove('connected'); + item.setAttribute('title', 'Disconnected'); + }); + }, + + WSOpen: function (str) { + $$('.nav-ws-status', function (item) { + item.classList.add('connected'); + item.setAttribute('title', 'Connected to ' + str); + }); + }, + + // Render left-hand side navigation given the available panels. + renderWrap: function (nav) { + $('nav').innerHTML = GoAccess.AppTpls.Nav.wrap.render(GoAccess.i18n); + }, + + // Iterate over all available panels and render each. + initialize: function () { + this.setTheme(GoAccess.AppPrefs.theme); + this.renderWrap(); + this.WSStatus(); + this.events(); + } +}; + +// RENDER PANELS +GoAccess.Panels = { + events: function () { + $$('[data-toggle=dropdown]', function (item) { + item.onclick = function (e) { + this.openOpts(e.currentTarget); + }.bind(this); + item.onblur = function (e) { + this.closeOpts(e); + }.bind(this); + }.bind(this)); + + $$('[data-plot]', function (item) { + item.onclick = function (e) { + GoAccess.Charts.redrawChart(e.currentTarget); + }.bind(this); + }.bind(this)); + + $$('[data-chart]', function (item) { + item.onclick = function (e) { + GoAccess.Charts.toggleChart(e.currentTarget); + }.bind(this); + }.bind(this)); + + $$('[data-chart-type]', function (item) { + item.onclick = function (e) { + GoAccess.Charts.setChartType(e.currentTarget); + }.bind(this); + }.bind(this)); + + $$('[data-metric]', function (item) { + item.onclick = function (e) { + GoAccess.Tables.toggleColumn(e.currentTarget); + }.bind(this); + }.bind(this)); + }, + + openOpts: function (targ) { + var panel = targ.getAttribute('data-panel'); + targ.parentElement.classList.toggle('open'); + this.renderOpts(panel); + }, + + closeOpts: function (e) { + e.currentTarget.parentElement.classList.remove('open'); + // Trigger the click event on the target if not opening another menu + if (e.relatedTarget && e.relatedTarget.getAttribute('data-toggle') !== 'dropdown') + e.relatedTarget.click(); + }, + + setPlotSelection: function (ui, prefs) { + var chartType = ((prefs || {}).plot || {}).chartType || ui.plot[0].chartType; + var metric = ((prefs || {}).plot || {}).metric || ui.plot[0].className; + + ui[chartType] = true; + for (var i = 0, len = ui.plot.length; i < len; ++i) + if (ui.plot[i].className == metric) + ui.plot[i]['selected'] = true; + }, + + setColSelection: function (items, prefs) { + var columns = (prefs || {}).columns || {}; + for (var i = 0, len = items.length; i < len; ++i) + if ((items[i].key in columns) && columns[items[i].key]['hide']) + items[i]['hide'] = true; + }, + + setChartSelection: function (ui, prefs) { + ui['showChart'] = prefs && ('chart' in prefs) ? prefs.chart : true; + }, + + setOpts: function (panel) { + var ui = JSON.parse(JSON.stringify(GoAccess.getPanelUI(panel))), prefs = GoAccess.getPrefs(panel); + // set preferences selection upon opening panel options + this.setChartSelection(ui, prefs); + this.setPlotSelection(ui, prefs); + this.setColSelection(ui.items, prefs); + return GoAccess.Util.merge(ui, {'labels': GoAccess.i18n}); + }, + + renderOpts: function (panel) { + $('.panel-opts-' + panel).innerHTML = GoAccess.AppTpls.Panels.opts.render(this.setOpts(panel)); + this.events(); + }, + + enablePrev: function (panel) { + var $pagination = $('#panel-' + panel + ' .pagination a.panel-prev'); + if ($pagination) + $pagination.parentNode.classList.remove('disabled'); + }, + + disablePrev: function (panel) { + var $pagination = $('#panel-' + panel + ' .pagination a.panel-prev'); + if ($pagination) + $pagination.parentNode.classList.add('disabled'); + }, + + enableNext: function (panel) { + var $pagination = $('#panel-' + panel + ' .pagination a.panel-next'); + if ($pagination) + $pagination.parentNode.classList.remove('disabled'); + }, + + disableNext: function (panel) { + var $pagination = $('#panel-' + panel + ' .pagination a.panel-next'); + if ($pagination) + $pagination.parentNode.classList.add('disabled'); + }, + + enableFirst: function (panel) { + var $pagination = $('#panel-' + panel + ' .pagination a.panel-first'); + if ($pagination) + $pagination.parentNode.classList.remove('disabled'); + }, + + disableFirst: function (panel) { + var $pagination = $('#panel-' + panel + ' .pagination a.panel-first'); + if ($pagination) + $pagination.parentNode.classList.add('disabled'); + }, + + enableLast: function (panel) { + var $pagination = $('#panel-' + panel + ' .pagination a.panel-last'); + if ($pagination) + $pagination.parentNode.classList.remove('disabled'); + }, + + disableLast: function (panel) { + var $pagination = $('#panel-' + panel + ' .pagination a.panel-last'); + if ($pagination) + $pagination.parentNode.classList.add('disabled'); + }, + + enablePagination: function (panel) { + this.enablePrev(panel); + this.enableNext(panel); + this.enableFirst(panel); + this.enableLast(panel); + }, + + disablePagination: function (panel) { + this.disablePrev(panel); + this.disableNext(panel); + this.disableFirst(panel); + this.disableLast(panel); + }, + + hasSubItems: function (ui, data) { + for (var i = 0, len = data.length; i < len; ++i) { + if (!data[i].items) + return (ui['hasSubItems'] = false); + if (data[i].items.length) { + return (ui['hasSubItems'] = true); + } + } + return false; + }, + + setComputedData: function (panel, ui, data) { + this.hasSubItems(ui, data.data); + GoAccess.Charts.hasChart(panel, ui); + GoAccess.Tables.hasTable(ui); + }, + + // Render the given panel given a user interface definition. + renderPanel: function (panel, ui, col) { + // set some computed values before rendering panel structure + var data = GoAccess.getPanelData(panel); + this.setComputedData(panel, ui, data); + + // per panel wrapper + var box = document.createElement('div'); + box.id = 'panel-' + panel; + box.innerHTML = GoAccess.AppTpls.Panels.wrap.render(GoAccess.Util.merge(ui, { + 'labels': GoAccess.i18n + })); + col.appendChild(box); + + // Remove pagination if not enough data for the given panel + if (data.data.length <= GoAccess.getPrefs().perPage) + this.disablePagination(panel); + GoAccess.Tables.renderThead(panel, ui); + + return col; + }, + + createCol: function (row) { + var layout = GoAccess.AppPrefs['layout']; + var perRow = 'horizontal' == layout ? 6 : 'wide' == layout ? 3 : 12; + + // set the number of columns based on current layout + var col = document.createElement('div'); + col.setAttribute('class', 'col-md-' + perRow + ' wrap-panel'); + row.appendChild(col); + + return col; + }, + + createRow: function (row, idx) { + var wrap = $('.wrap-panels'); + var layout = GoAccess.AppPrefs['layout']; + var every = 'horizontal' == layout ? 2 : 'wide' == layout ? 4 : 1; + + // create a new bootstrap row every one or two elements depending on + // the layout + if (idx % every == 0) { + row = document.createElement('div'); + row.setAttribute('class', 'row' + (every == 2 || every == 4 ? ' equal' : '')); + wrap.appendChild(row); + } + + return row; + }, + + resetPanel: function (panel) { + var ui = GoAccess.getPanelUI(); + var ele = $('#panel-' + panel); + + if (GoAccess.Util.isPanelValid(panel) || GoAccess.Util.isPanelHidden(panel)) + return false; + + var col = ele.parentNode; + col.removeChild(ele); + // Render panel given a user interface definition + this.renderPanel(panel, ui[panel], col); + this.events(); + }, + + // Iterate over all available panels and render each panel + // structure. + renderPanels: function () { + var ui = GoAccess.getPanelUI(), idx = 0, row = null, col = null; + + $('.wrap-panels').innerHTML = ''; + for (var panel in ui) { + if (GoAccess.Util.isPanelValid(panel) || GoAccess.Util.isPanelHidden(panel)) + continue; + row = this.createRow(row, idx++); + col = this.createCol(row); + // Render panel given a user interface definition + this.renderPanel(panel, ui[panel], col); + } + }, + + initialize: function () { + this.renderPanels(); + this.events(); + } +}; + +// RENDER CHARTS +GoAccess.Charts = { + iter: function (callback) { + Object.keys(GoAccess.AppCharts).forEach(function (panel) { + // redraw chart only if it's within the viewport + if (!GoAccess.Util.isWithinViewPort($('#panel-' + panel))) + return; + if (callback && typeof callback === 'function') + callback.call(this, GoAccess.AppCharts[panel], panel); + }); + }, + + getMetricKeys: function (panel, key) { + return GoAccess.getPanelUI(panel)['items'].map(function (a) { return a[key]; }); + }, + + getPanelData: function (panel, data) { + // Grab ui plot data for the selected panel + var plot = GoAccess.Util.getProp(GoAccess.AppState, panel + '.plot'); + + // Grab the data for the selected panel + data = data || this.processChartData(GoAccess.getPanelData(panel).data); + return plot.chartReverse ? data.reverse() : data; + }, + + drawPlot: function (panel, plotUI, data) { + var chart = this.getChart(panel, plotUI, data); + if (!chart) + return; + + this.renderChart(panel, chart, data); + GoAccess.AppCharts[panel] = null; + GoAccess.AppCharts[panel] = chart; + }, + + setChartType: function (targ) { + var panel = targ.getAttribute('data-panel'); + var type = targ.getAttribute('data-chart-type'); + + GoAccess.Util.setProp(GoAccess.AppPrefs, panel + '.plot.chartType', type); + GoAccess.setPrefs(); + + var plotUI = GoAccess.Util.getProp(GoAccess.AppState, panel + '.plot'); + // Extract data for the selected panel and process it + this.drawPlot(panel, plotUI, this.getPanelData(panel)); + }, + + toggleChart: function (targ) { + var panel = targ.getAttribute('data-panel'); + var prefs = GoAccess.getPrefs(panel), + chart = prefs && ('chart' in prefs) ? prefs.chart : true; + + GoAccess.Util.setProp(GoAccess.AppPrefs, panel + '.chart', !chart); + GoAccess.setPrefs(); + + GoAccess.Panels.resetPanel(panel); + GoAccess.Charts.resetChart(panel); + GoAccess.Tables.renderFullTable(panel); + }, + + hasChart: function (panel, ui) { + var prefs = GoAccess.getPrefs(panel), + chart = prefs && ('chart' in prefs) ? prefs.chart : true; + ui['chart'] = ui.plot.length && chart && chart; + }, + + // Redraw a chart upon selecting a metric. + redrawChart: function (targ) { + var plot = targ.getAttribute('data-plot'); + var panel = targ.getAttribute('data-panel'); + var ui = GoAccess.getPanelUI(panel); + var plotUI = ui.plot; + + GoAccess.Util.setProp(GoAccess.AppPrefs, panel + '.plot.metric', plot); + GoAccess.setPrefs(); + + // Iterate over plot user interface definition + for (var x in plotUI) { + if (!plotUI.hasOwnProperty(x) || plotUI[x].className != plot) + continue; + + GoAccess.Util.setProp(GoAccess.AppState, panel + '.plot', plotUI[x]); + // Extract data for the selected panel and process it + this.drawPlot(panel, plotUI[x], this.getPanelData(panel)); + break; + } + }, + + // Iterate over the item properties and extract the count value. + extractCount: function (item) { + var o = {}; + for (var prop in item) + o[prop] = GoAccess.Util.getCount(item[prop]); + return o; + }, + + // Extract an array of objects that D3 can consume to process the chart. + // e.g., o = Object {hits: 37402, visitors: 6949, bytes: + // 505881789, avgts: 118609, cumts: 4436224010…} + processChartData: function (data) { + var out = []; + for (var i = 0; i < data.length; ++i) + out.push(this.extractCount(data[i])); + return out; + }, + + findUIItem: function (panel, key) { + var items = GoAccess.getPanelUI(panel).items; + for (var i = 0; i < items.length; ++i) { + if (items[i].key == key) + return items[i]; + } + return null; + }, + + getXKey: function (datum, key) { + var arr = []; + if (typeof key === 'string') + return datum[key]; + for (var prop in key) + arr.push(datum[key[prop]]); + return arr.join(' '); + }, + + getWMap: function (panel, plotUI, data) { + var chart = WorldMap(d3.select("#chart-" + panel)); + chart.width($("#chart-" + panel).getBoundingClientRect().width); + chart.height(400); + chart.metric(plotUI['d3']['y0']['key']); + chart.opts(plotUI); + + return chart; + }, + + getAreaSpline: function (panel, plotUI, data) { + var dualYaxis = plotUI['d3']['y1']; + + var chart = AreaChart(dualYaxis) + .labels({ + y0: plotUI['d3']['y0'].label, + y1: dualYaxis ? plotUI['d3']['y1'].label : '' + }) + .x(function (d) { + if ((((plotUI || {}).d3 || {}).x || {}).key) + return this.getXKey(d, plotUI['d3']['x']['key']); + return d.data; + }.bind(this)) + .y0(function (d) { + return +d[plotUI['d3']['y0']['key']]; + }) + .width($("#chart-" + panel).getBoundingClientRect().width) + .height(175) + .format({ + x: (this.findUIItem(panel, 'data') || {}).dataType || null, + y0: ((plotUI.d3 || {}).y0 || {}).format, + y1: ((plotUI.d3 || {}).y1 || {}).format, + }) + .opts(plotUI); + + dualYaxis && chart.y1(function (d) { + return +d[plotUI['d3']['y1']['key']]; + }); + + return chart; + }, + + getVBar: function (panel, plotUI, data) { + var dualYaxis = plotUI['d3']['y1']; + + var chart = BarChart(dualYaxis) + .labels({ + y0: plotUI['d3']['y0'].label, + y1: dualYaxis ? plotUI['d3']['y1'].label : '' + }) + .x(function (d) { + if ((((plotUI || {}).d3 || {}).x || {}).key) + return this.getXKey(d, plotUI['d3']['x']['key']); + return d.data; + }.bind(this)) + .y0(function (d) { + return +d[plotUI['d3']['y0']['key']]; + }) + .width($("#chart-" + panel).getBoundingClientRect().width) + .height(175) + .format({ + x: (this.findUIItem(panel, 'data') || {}).dataType || null, + y0: ((plotUI.d3 || {}).y0 || {}).format, + y1: ((plotUI.d3 || {}).y1 || {}).format, + }) + .opts(plotUI); + + dualYaxis && chart.y1(function (d) { + return +d[plotUI['d3']['y1']['key']]; + }); + + return chart; + }, + + getChartType: function (panel) { + var ui = GoAccess.getPanelUI(panel); + if (!ui.chart) + return ''; + + return GoAccess.Util.getProp(GoAccess.getPrefs(), panel + '.plot.chartType') || ui.plot[0].chartType; + }, + + getPlotUI: function (panel, ui) { + var metric = GoAccess.Util.getProp(GoAccess.getPrefs(), panel + '.plot.metric'); + if (!metric) + return ui.plot[0]; + return ui.plot.filter(function (v) { + return v.className == metric; + })[0]; + }, + + getChart: function (panel, plotUI, data) { + var chart = null; + + // Render given its type + switch (this.getChartType(panel)) { + case 'area-spline': + chart = this.getAreaSpline(panel, plotUI, data); + break; + case 'bar': + chart = this.getVBar(panel, plotUI, data); + break; + case 'wmap': + chart = this.getWMap(panel, plotUI, data); + break; + } + + return chart; + }, + + renderChart: function (panel, chart, data) { + // remove popup + d3.select('#chart-' + panel + '>.chart-tooltip-wrap') + .remove(); + // remove svg + d3.select('#chart-' + panel).selectAll('svg') + .remove(); + // add chart to the document + d3.select("#chart-" + panel) + .datum(data) + .call(chart) + .append("div").attr("class", "chart-tooltip-wrap"); + }, + + addChart: function (panel, ui) { + var plotUI = null, chart = null; + + // Ensure it has a plot definition + if (!ui.plot || !ui.plot.length) + return; + + plotUI = this.getPlotUI(panel, ui); + // set ui plot data + GoAccess.Util.setProp(GoAccess.AppState, panel + '.plot', plotUI); + + // Grab the data for the selected panel + var data = this.getPanelData(panel); + if (!(chart = this.getChart(panel, plotUI, data))) + return; + + this.renderChart(panel, chart, data); + GoAccess.AppCharts[panel] = chart; + }, + + // Render all charts for the applicable panels. + renderCharts: function (ui) { + for (var panel in ui) { + if (GoAccess.Util.isPanelValid(panel) || GoAccess.Util.isPanelHidden(panel)) + continue; + this.addChart(panel, ui[panel]); + } + }, + + resetChart: function (panel) { + var ui = {}; + if (GoAccess.Util.isPanelValid(panel) || GoAccess.Util.isPanelHidden(panel)) + return false; + + ui = GoAccess.getPanelUI(panel); + this.addChart(panel, ui); + }, + + // Reload (doesn't redraw) the given chart's data + reloadChart: function (chart, panel) { + var subItems = GoAccess.Tables.getSubItemsData(panel); + var data = (subItems.length ? subItems : GoAccess.getPanelData(panel).data).slice(0); + + d3.select("#chart-" + panel) + .datum(this.processChartData(this.getPanelData(panel, data))) + .call(chart.width($("#chart-" + panel).offsetWidth)) + .append("div").attr("class", "chart-tooltip-wrap"); + }, + + // Reload (doesn't redraw) all chart's data + reloadCharts: function () { + this.iter(function (chart, panel) { + this.reloadChart(chart, panel); + }.bind(this)); + GoAccess.AppState.updated = false; + }, + + // Only redraw charts with current data + redrawCharts: function () { + this.iter(function (chart, panel) { + d3.select("#chart-" + panel).call(chart.width($("#chart-" + panel).offsetWidth)); + }); + }, + + initialize: function () { + this.renderCharts(GoAccess.getPanelUI()); + + // reload on scroll & redraw on resize + d3.select(window).on('scroll.charts', debounce(function () { + this.reloadCharts(); + }, 250, false).bind(this)).on('resize.charts', function () { + this.redrawCharts(); + }.bind(this)); + } +}; + +// RENDER TABLES +GoAccess.Tables = { + chartData: {}, // holds all panel sub items data that feeds the chart + + events: function () { + $$('.panel-next', function (item) { + item.onclick = function (e) { + var panel = e.currentTarget.getAttribute('data-panel'); + this.renderTable(panel, this.nextPage(panel)); + }.bind(this); + }.bind(this)); + + $$('.panel-prev', function (item) { + item.onclick = function (e) { + var panel = e.currentTarget.getAttribute('data-panel'); + this.renderTable(panel, this.prevPage(panel)); + }.bind(this); + }.bind(this)); + + $$('.panel-first', function (item) { + item.onclick = function (e) { + var panel = e.currentTarget.getAttribute('data-panel'); + this.renderTable(panel, "FIRST_PAGE"); + }.bind(this); + }.bind(this)); + + $$('.panel-last', function (item) { + item.onclick = function (e) { + var panel = e.currentTarget.getAttribute('data-panel'); + this.renderTable(panel, "LAST_PAGE"); + }.bind(this); + }.bind(this)); + + $$('.expandable>td', function (item) { + item.onclick = function (e) { + if (!window.getSelection().toString()) + this.toggleRow(e.currentTarget); + }.bind(this); + }.bind(this)); + + $$('.row-expandable.clickable', function (item) { + item.onclick = function (e) { + this.toggleRow(e.currentTarget); + }.bind(this); + }.bind(this)); + + $$('.sortable', function (item) { + item.onclick = function (e) { + this.sortColumn(e.currentTarget); + }.bind(this); + }.bind(this)); + }, + + toggleColumn: function (targ) { + var panel = targ.getAttribute('data-panel'); + var metric = targ.getAttribute('data-metric'); + + var columns = (GoAccess.getPrefs(panel) || {}).columns || {}; + if (metric in columns) { + delete columns[metric]; + } else { + GoAccess.Util.setProp(columns, metric + '.hide', true); + } + + GoAccess.Util.setProp(GoAccess.AppPrefs, panel + '.columns', columns); + GoAccess.setPrefs(); + + GoAccess.Tables.renderThead(panel, GoAccess.getPanelUI(panel)); + GoAccess.Tables.renderFullTable(panel); + }, + + sortColumn: function (ele) { + var field = ele.getAttribute('data-key'); + var order = ele.getAttribute('data-order'); + var panel = ele.parentElement.parentElement.parentElement.getAttribute('data-panel'); + + order = order ? 'asc' == order ? 'desc' : 'asc' : 'asc'; + GoAccess.App.sortData(panel, field, order); + GoAccess.Util.setProp(GoAccess.AppState, panel + '.sort', { + 'field': field, + 'order': order, + }); + this.renderThead(panel, GoAccess.getPanelUI(panel)); + this.renderTable(panel, this.getCurPage(panel)); + + GoAccess.Charts.reloadChart(GoAccess.AppCharts[panel], panel); + }, + + getDataByKey: function (panel, key) { + var data = GoAccess.getPanelData(panel).data; + for (var i = 0, n = data.length; i < n; ++i) { + if (GoAccess.Util.hashCode(data[i].data) == key) + return data[i]; + } + return null; + }, + + getSubItemsData: function (panel) { + var out = [], items = this.chartData[panel]; + for (var x in items) { + if (!items.hasOwnProperty(x)) + continue; + out = out.concat(items[x]); + } + return out; + }, + + addChartData: function (panel, key) { + var data = this.getDataByKey(panel, key); + var path = panel + '.' + key; + + if (!data || !data.items) + return []; + GoAccess.Util.setProp(this.chartData, path, data.items); + + return this.getSubItemsData(panel); + }, + + removeChartData: function (panel, key) { + if (GoAccess.Util.getProp(this.chartData, panel + '.' + key)) + delete this.chartData[panel][key]; + + if (!this.chartData[panel] || Object.keys(this.chartData[panel]).length == 0) + return GoAccess.getPanelData(panel).data; + + return this.getSubItemsData(panel); + }, + + isExpanded: function (panel, key) { + var path = panel + '.expanded.' + key; + return GoAccess.Util.getProp(GoAccess.AppState, path); + }, + + toggleExpanded: function (panel, key) { + var path = panel + '.expanded.' + key, ret = true; + + if (this.isExpanded(panel, key)) { + delete GoAccess.AppState[panel]['expanded'][key]; + } else { + GoAccess.Util.setProp(GoAccess.AppState, path, true), ret = false; + } + + return ret; + }, + + // Toggle children rows + toggleRow: function (ele) { + var hide = false, data = []; + var row = ele.parentNode; + var panel = row.getAttribute('data-panel'), key = row.getAttribute('data-key'); + var plotUI = GoAccess.AppCharts[panel].opts(); + + hide = this.toggleExpanded(panel, key); + this.renderTable(panel, this.getCurPage(panel)); + if (!plotUI.redrawOnExpand) + return; + + if (!hide) { + data = GoAccess.Charts.processChartData(this.addChartData(panel, key)); + } else { + data = GoAccess.Charts.processChartData(this.removeChartData(panel, key)); + } + GoAccess.Charts.drawPlot(panel, plotUI, data); + }, + + // Get current panel page + getCurPage: function (panel) { + return GoAccess.Util.getProp(GoAccess.AppState, panel + '.curPage') || 0; + }, + + // Page offset. + // e.g., Return Value: 11, curPage: 2 + pageOffSet: function (panel) { + return ((this.getCurPage(panel) - 1) * GoAccess.getPrefs().perPage); + }, + + // Get total number of pages given the number of items on array + getTotalPages: function (dataItems) { + return Math.ceil(dataItems.length / GoAccess.getPrefs().perPage); + }, + + // Get a shallow copy of a portion of the given data array and the + // current page. + getPage: function (panel, dataItems, page) { + var totalPages = this.getTotalPages(dataItems); + if (page < 1) + page = 1; + if (page > totalPages) + page = totalPages; + + GoAccess.Util.setProp(GoAccess.AppState, panel + '.curPage', page); + var start = this.pageOffSet(panel); + var end = start + GoAccess.getPrefs().perPage; + + return dataItems.slice(start, end); + }, + + // Get previous page + prevPage: function (panel) { + return this.getCurPage(panel) - 1; + }, + + // Get next page + nextPage: function (panel) { + return this.getCurPage(panel) + 1; + }, + + getMetaCell: function (ui, o, key) { + var val = o && (key in o) && o[key].value ? o[key].value : null; + var perc = o && (key in o) && o[key].percent ? o[key].percent : null; + + // use metaType if exist else fallback to dataType + var vtype = ui.metaType || ui.dataType; + var className = ui.className || ''; + className += !['string'].includes(ui.dataType) ? 'text-right' : ''; + return { + 'className': className, + 'value' : val ? GoAccess.Util.fmtValue(val, vtype) : null, + 'percent' : perc, + 'title' : ui.meta, + 'label' : ui.metaLabel || null, + }; + }, + + hideColumn: function (panel, col) { + var columns = (GoAccess.getPrefs(panel) || {}).columns || {}; + return ((col in columns) && columns[col]['hide']); + }, + + showTables: function () { + return ('showTables' in GoAccess.getPrefs()) ? GoAccess.getPrefs().showTables : true; + }, + + autoHideTables: function () { + return ('autoHideTables' in GoAccess.getPrefs()) ? GoAccess.getPrefs().autoHideTables : true; + }, + + hasTable: function (ui) { + ui['table'] = this.showTables(); + ui['autoHideTables'] = this.autoHideTables(); + }, + + getMetaRows: function (panel, ui, key) { + var cells = [], uiItems = ui.items; + var data = GoAccess.getPanelData(panel).metadata; + + for (var i = 0; i < uiItems.length; ++i) { + var item = uiItems[i]; + if (this.hideColumn(panel, item.key)) + continue; + cells.push(this.getMetaCell(item, data[item.key], key)); + } + + return [{ + 'hasSubItems': ui.hasSubItems, + 'cells': cells, + 'key' : key.substring(0, 3), + }]; + }, + + renderMetaRow: function (panel, metarows, className) { + // find the table to set + var table = $('.table-' + panel + ' tr.' + className); + if (!table) + return; + + table.innerHTML = GoAccess.AppTpls.Tables.meta.render({ + row: metarows + }); + }, + + // Iterate over user interface definition properties + iterUIItems: function (panel, uiItems, dataItems, callback) { + var out = []; + for (var i = 0; i < uiItems.length; ++i) { + var uiItem = uiItems[i]; + if (this.hideColumn(panel, uiItem.key)) + continue; + // Data for the current user interface property. + // e.g., dataItem = Object {count: 13949, percent: 5.63} + var dataItem = dataItems[uiItem.key]; + // Apply the callback and push return data to output array + if (callback && typeof callback == 'function') { + var ret = callback.call(this, panel, uiItem, dataItem); + if (ret) out.push(ret); + } + } + return out; + }, + + // Return an object that can be consumed by the table template given a user + // interface definition and a cell value object. + // e.g., value = Object {count: 14351, percent: 5.79} + getObjectCell: function (panel, ui, value) { + var className = ui.className || ''; + className += !['string'].includes(ui.dataType) ? 'text-right' : ''; + return { + 'className': className, + 'percent': GoAccess.Util.getPercent(value), + 'value': GoAccess.Util.fmtValue(GoAccess.Util.getCount(value), ui.dataType, null, null, ui.hlregex, ui.hlvalue, ui.hlidx) + }; + }, + + // Given a data item object, set all the row cells and return a + // table row that the template can consume. + renderRow: function (panel, callback, ui, dataItem, idx, subItem, parentId, expanded) { + var shadeParent = ((!subItem && idx % 2 != 0) ? 'shaded' : ''); + var shadeChild = ((parentId % 2 != 0) ? 'shaded' : ''); + return { + 'panel' : panel, + 'idx' : !subItem && (String((idx + 1) + this.pageOffSet(panel))), + 'key' : !subItem ? GoAccess.Util.hashCode(dataItem.data) : '', + 'expanded' : !subItem && expanded, + 'parentId' : subItem ? String(parentId) : '', + 'className' : subItem ? 'child ' + shadeChild : 'parent ' + shadeParent, + 'hasSubItems' : ui.hasSubItems, + 'items' : dataItem.items ? dataItem.items.length : 0, + 'cells' : callback.call(this), + }; + }, + + renderRows: function (rows, panel, ui, dataItems, subItem, parentId) { + subItem = subItem || false; + // no data rows + if (dataItems.length == 0 && ui.items.length) { + rows.push({ + cells: [{ + className: 'text-center', + colspan: ui.items.length + 1, + value: 'No data on this panel.' + }] + }); + } + + // Iterate over all data items for the given panel and + // generate a table row per date item. + var cellcb = null; + for (var i = 0; i < dataItems.length; ++i) { + var dataItem = dataItems[i], data = null, expanded = false; + switch(typeof dataItem) { + case 'string': + data = dataItem; + cellcb = function () { + return { + 'colspan': ui.items.length, + 'value': data + }; + }; + break; + default: + data = dataItem.data; + cellcb = this.iterUIItems.bind(this, panel, ui.items, dataItem, this.getObjectCell.bind(this)); + } + + expanded = this.isExpanded(panel, GoAccess.Util.hashCode(data)); + rows.push(this.renderRow(panel, cellcb, ui, dataItem, i, subItem, parentId, expanded)); + if (dataItem.items && dataItem.items.length && expanded) { + this.renderRows(rows, panel, ui, dataItem.items, true, i, expanded); + } + } + }, + + // Entry point to render all data rows into the table + renderDataRows: function (panel, ui, dataItems, page) { + // find the table to set + var table = $('.table-' + panel + ' tbody.tbody-data'); + if (!table) + return; + + dataItems = this.getPage(panel, dataItems, page); + var rows = []; + this.renderRows(rows, panel, ui, dataItems); + if (rows.length == 0) + return; + + table.innerHTML = GoAccess.AppTpls.Tables.data.render({ + rows: rows + }); + }, + + togglePagination: function (panel, page, dataItems) { + GoAccess.Panels.enablePagination(panel); + // Disable pagination next button if last page is reached + if (page >= this.getTotalPages(dataItems)) { + GoAccess.Panels.disableNext(panel); + GoAccess.Panels.disableLast(panel); + } + if (page <= 1) { + GoAccess.Panels.disablePrev(panel); + GoAccess.Panels.disableFirst(panel); + } + }, + + renderTable: function (panel, page) { + var dataItems = GoAccess.getPanelData(panel).data; + var ui = GoAccess.getPanelUI(panel); + + if (page === "LAST_PAGE") { + page = this.getTotalPages(dataItems); + } else if (page === "FIRST_PAGE") { + page = 1; + } + + this.togglePagination(panel, page, dataItems); + // Render data rows + this.renderDataRows(panel, ui, dataItems, page); + this.events(); + }, + + renderFullTable: function (panel) { + var ui = GoAccess.getPanelUI(panel), page = 0; + // panel's data + var data = GoAccess.getPanelData(panel); + + // render meta data + if (data.hasOwnProperty('metadata')) { + this.renderMetaRow(panel, this.getMetaRows(panel, ui, 'min'), 'thead-min'); + this.renderMetaRow(panel, this.getMetaRows(panel, ui, 'max'), 'thead-max'); + this.renderMetaRow(panel, this.getMetaRows(panel, ui, 'avg'), 'thead-avg'); + } + + // render actual data + if (data.hasOwnProperty('data')) { + page = this.getCurPage(panel); + this.togglePagination(panel, page, data.data); + this.renderDataRows(panel, ui, data.data, page); + } + + // render meta data + if (data.hasOwnProperty('metadata')) { + this.renderMetaRow(panel, this.getMetaRows(panel, ui, 'total'), 'tfoot-totals'); + } + }, + + // Iterate over all panels and determine which ones should contain + // a data table. + renderTables: function (force) { + var ui = GoAccess.getPanelUI(); + for (var panel in ui) { + if (GoAccess.Util.isPanelValid(panel) || GoAccess.Util.isPanelHidden(panel) || !this.showTables()) + continue; + if (force || GoAccess.Util.isWithinViewPort($('#panel-' + panel))) + this.renderFullTable(panel); + } + }, + + // Given a UI panel definition, make a copy of it and assign the sort + // fields to the template object to render + sort2Tpl: function (panel, ui) { + var uiClone = JSON.parse(JSON.stringify(ui)), out = []; + var sort = GoAccess.Util.getProp(GoAccess.AppState, panel + '.sort'); + + for (var i = 0, len = uiClone.items.length; i < len; ++i) { + var item = uiClone.items[i]; + if (this.hideColumn(panel, item.key)) + continue; + + item['sort'] = false; + if (item.key == sort.field && sort.order) { + item['sort'] = true; + item[sort.order.toLowerCase()] = true; + } + out.push(item); + } + uiClone.items = out; + + return uiClone; + }, + + renderThead: function (panel, ui) { + var $thead = $('.table-' + panel + '>thead>tr.thead-cols'), + $colgroup = $('.table-' + panel + '>colgroup'); + + if ($thead && $colgroup && this.showTables()) { + ui = this.sort2Tpl(panel, ui); + + $thead.innerHTML = GoAccess.AppTpls.Tables.head.render(ui); + $colgroup.innerHTML = GoAccess.AppTpls.Tables.colgroup.render(ui); + } + }, + + reloadTables: function () { + this.renderTables(false); + this.events(); + }, + + initialize: function () { + this.renderTables(true); + this.events(); + + // redraw on scroll + d3.select(window).on('scroll.tables', debounce(function () { + this.reloadTables(); + }, 250, false).bind(this)); + }, +}; + +// Main App +GoAccess.App = { + hasFocus: true, + + tpl: function (tpl) { + return Hogan.compile(tpl); + }, + + setTpls: function () { + GoAccess.AppTpls = { + 'Nav': { + 'wrap': this.tpl($('#tpl-nav-wrap').innerHTML), + 'menu': this.tpl($('#tpl-nav-menu').innerHTML), + 'opts': this.tpl($('#tpl-nav-opts').innerHTML), + }, + 'Panels': { + 'wrap': this.tpl($('#tpl-panel').innerHTML), + 'opts': this.tpl($('#tpl-panel-opts').innerHTML), + }, + 'General': { + 'wrap': this.tpl($('#tpl-general').innerHTML), + 'items': this.tpl($('#tpl-general-items').innerHTML), + }, + 'Tables': { + 'colgroup': this.tpl($('#tpl-table-colgroup').innerHTML), + 'head': this.tpl($('#tpl-table-thead').innerHTML), + 'meta': this.tpl($('#tpl-table-row-meta').innerHTML), + 'totals': this.tpl($('#tpl-table-row-totals').innerHTML), + 'data': this.tpl($('#tpl-table-row').innerHTML), + }, + }; + }, + + sortField: function (o, field) { + var f = o[field]; + if (GoAccess.Util.isObject(f) && (f !== null)) + f = o[field].count; + return f; + }, + + sortData: function (panel, field, order) { + // panel's data + var panelData = GoAccess.getPanelData(panel).data; + + // Function to sort an array of objects + var sortArray = function(arr) { + arr.sort(function (a, b) { + a = this.sortField(a, field); + b = this.sortField(b, field); + + if (typeof a === 'string' && typeof b === 'string') + return 'asc' == order ? a.localeCompare(b) : b.localeCompare(a); + return 'asc' == order ? a - b : b - a; + }.bind(this)); + }.bind(this); + + // Sort panelData + sortArray(panelData); + + // Sort the items sub-array + panelData.forEach(function(item) { + if (item.items) { + sortArray(item.items); + } + }); + }, + + setInitSort: function () { + var ui = GoAccess.getPanelUI(); + for (var panel in ui) { + if (GoAccess.Util.isPanelValid(panel)) + continue; + GoAccess.Util.setProp(GoAccess.AppState, panel + '.sort', ui[panel].sort); + } + }, + + // Verify if we need to sort panels upon data re-entry + verifySort: function () { + var ui = GoAccess.getPanelUI(); + for (var panel in ui) { + if (GoAccess.Util.isPanelValid(panel) || GoAccess.Util.isPanelHidden(panel)) + continue; + var sort = GoAccess.Util.getProp(GoAccess.AppState, panel + '.sort'); + // do not sort panels if they still hold the same sort properties + if (JSON.stringify(sort) === JSON.stringify(ui[panel].sort)) + continue; + this.sortData(panel, sort.field, sort.order); + } + }, + + initDom: function () { + $('nav').classList.remove('hide'); + $('.container').classList.remove('hide'); + $('.spinner').classList.add('hide'); + + if (GoAccess.AppPrefs['layout'] == 'horizontal' || GoAccess.AppPrefs['layout'] == 'wide') { + $('.container').classList.add('container-fluid'); + $('.container-fluid').classList.remove('container'); + } + }, + + renderData: function () { + // update data and charts if tab/document has focus + if (!this.hasFocus) + return; + + // some panels may not have been properly rendered since no data was + // passed when bootstrapping the report, thus we do a one full + // re-render of all panels + if (GoAccess.OverallStats.total_requests == 0 && GoAccess.OverallStats.total_requests != GoAccess.AppData.general.total_requests) + GoAccess.Panels.initialize(); + GoAccess.OverallStats.total_requests = GoAccess.AppData.general.total_requests; + + this.verifySort(); + GoAccess.OverallStats.initialize(); + + // do not rerender tables/charts if data hasn't changed + if (!GoAccess.AppState.updated) + return; + + GoAccess.Charts.reloadCharts(); + GoAccess.Tables.reloadTables(); + }, + + initialize: function () { + this.setInitSort(); + this.setTpls(); + GoAccess.Nav.initialize(); + this.initDom(); + GoAccess.OverallStats.initialize(); + GoAccess.Panels.initialize(); + GoAccess.Charts.initialize(); + GoAccess.Tables.initialize(); + }, +}; + +// Adds the visibilitychange EventListener +document.addEventListener('visibilitychange', function () { + // fires when user switches tabs, apps, etc. + if (document.visibilityState === 'hidden') + GoAccess.App.hasFocus = false; + + // fires when app transitions from hidden or user returns to the app/tab. + if (document.visibilityState === 'visible') { + var hasFocus = GoAccess.App.hasFocus; + GoAccess.App.hasFocus = true; + hasFocus || GoAccess.App.renderData(); + } +}); + +// Init app +window.onload = function () { + GoAccess.initialize({ + 'i18n': window.json_i18n, + 'uiData': window.user_interface, + 'panelData': window.json_data, + 'wsConnection': window.connection || null, + 'prefs': window.html_prefs || {}, + }); + GoAccess.App.initialize(); +}; +}()); diff --git a/resources/js/charts.js b/resources/js/charts.js new file mode 100644 index 0000000000..d0eba66d3f --- /dev/null +++ b/resources/js/charts.js @@ -0,0 +1,1429 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2018 Gerardo Orellana + */ + +'use strict'; + +// This is faster than calculating the exact length of each label. +// e.g., getComputedTextLength(), slice()... +function truncate(text, width) { + text.each(function () { + var parent = this.parentNode, $d3parent = d3.select(parent); + var gw = $d3parent.node().getBBox(); + var x = (Math.min(gw.width, width) / 2) * -1; + // adjust wrapper width + if ('svg' == parent.nodeName) { + $d3parent.attr('width', width).attr('x', x); + } + // wrap within an svg + else { + $d3parent.insert('svg', function () { + return this; + }.bind(this)) + .attr('class', 'wrap-text') + .attr('width', width) + .attr('x', x) + .append(function () { + return this; + }.bind(this)); + } + }); +} + +function WorldMap() { + const maxLat = 84; + let path = null; + let projection = null; + let tlast = [0, 0]; + let slast = null; + let opts = {}; + let metric = 'hits'; + let margin = { + top: 20, + right: 50, + bottom: 40, + left: 50 + }; + let width = 760; + let height = 170; + + function innerW() { + return width - margin.left - margin.right; + } + + function mapData(data) { + return data.reduce((countryData, region) => { + if (!region.items) countryData.push(region); + else region.items.forEach(item => countryData.push({ + data: item.data, + hits: item.hits.count, + visitors: item.visitors.count, + bytes: item.bytes.count, + region: region.data + })); + return countryData; + }, []); + } + + function formatTooltip(data) { + const d = {...data}; + let out = {}; + + out[0] = GoAccess.Util.fmtValue(d['data'], 'str'); + out[1] = metric == 'bytes' ? GoAccess.Util.fmtValue(d['bytes'], 'bytes') : d3.format(',')(d['hits']); + if (metric == 'hits') + out[2] = d3.format(',')(d['visitors']); + + const template = d3.select('#tpl-chart-tooltip').html(); + return Hogan.compile(template).render({ + 'data': out + }); + } + + function mouseover(event, selection, data) { + const tooltip = selection.select('.chart-tooltip-wrap'); + tooltip.html(formatTooltip(data)) + .style('left', `${d3.pointer(event)[0] + 10}px`) + .style('top', `${d3.pointer(event)[1] + 10}px`) + .style('display', 'block'); + } + + function mouseout(selection, g) { + const tooltip = selection.select('.chart-tooltip-wrap'); + tooltip.style('display', 'none'); + } + + function drawLegend(selection, colorScale) { + const legendHeight = 10; + const legendPadding = 10; + + let svg = selection.select('.legend-svg'); + if (svg.empty()) { + svg = selection.append('svg') + .attr('class', 'legend-svg') + .attr('width', width + margin.left + margin.right) + .attr('height', legendHeight + 2 * legendPadding); + } + + let legend = svg.select('.legend'); + if (legend.empty()) { + legend = svg.append('g') + .attr('class', 'legend') + .attr('transform', `translate(${margin.left}, ${legendPadding})`); + } + + const legendData = colorScale.quantiles(); + + const legendRects = legend.selectAll('rect') + .data(legendData); + + legendRects.enter().append('rect') + .merge(legendRects) + .attr('x', (d, i) => (i * (innerW())) / legendData.length) + .attr('y', 0) + .attr('width', (innerW()) / legendData.length) + .attr('height', legendHeight) + .style('fill', d => colorScale(d)); + + legendRects.exit().remove(); + + const legendTexts = legend.selectAll('text') + .data(legendData); + + legendTexts.enter().append('text') + .merge(legendTexts) + .attr('x', (d, i) => (i * (innerW())) / legendData.length) + .attr('y', legendHeight + legendPadding) + .text(d => Math.round(d)) + .style('font-size', '10px') + .attr('text-anchor', 'middle') + .text(d => metric === 'bytes' ? GoAccess.Util.fmtValue(d, 'bytes') : d3.format(',')(d)); + + legendTexts.exit().remove(); + } + + function updateMap(selection, svg, data, countries, countryNameToGeoJson) { + data = mapData(data); + path = d3.geoPath().projection(projection); + + const colorScale = d3.scaleQuantile().domain(data.map(d => d[metric])).range(['#ffffccc9', '#c2e699', '#a1dab4c9', '#41b6c4c9', '#2c7fb8c9']); + if (data.length) + drawLegend(selection, colorScale); + + // Create a mapping from country name to data + const dataByName = {}; + data.forEach(d => { + const k = d.data.split(' ')[0]; + dataByName[k] = d; + }); + + let country = svg.select('g').selectAll('.country') + .data(countries); + + // set initial opacity to 0 for entering elements + let countryEnter = country.enter().append('path') + .attr('class', 'country') + .attr('d', path) + .attr('opacity', 0); + + country = countryEnter.merge(country) + .on('mouseover', function(event, d) { + const countryData = dataByName[d.id]; + if (countryData) + mouseover(event, selection, countryData); + }) + .on('mouseout', function(d) { + mouseout(selection); + }); + + country.transition().duration(500) + .style('fill', function(d) { + const countryData = dataByName[d.id]; + return countryData ? colorScale(countryData[metric]) : '#cccccc54'; + }) + .attr('opacity', 1); + + country.exit() + .transition().duration(500) + .attr('opacity', 0) + .remove(); + + } + + function setBounds(projection, maxLat) { + const [yaw] = projection.rotate(); + // Top left corner + const xymax = projection([-yaw + 180 - 1e-6, -maxLat]); + // Bottom right corner + const xymin = projection([-yaw - 180 + 1e-6, maxLat]); + return [xymin, xymax]; + } + + function zoomed(event, projection, path, scaleExtent, g) { + const newX = event.transform.x % width; + const newY = event.transform.y; + const scale = event.transform.k; + + if (scale != slast) { + // Adjust the scale of the projection based on the zoom level + projection.scale(scale * (innerW() / (2 * Math.PI))); + } else { + // Calculate the new longitude based on the x-coordinate + let [longitude] = projection.rotate(); + + // Use the X translation to rotate, based on the current scale + longitude += 360 * ((newX - tlast[0]) / width) * (scaleExtent[0] / scale); + projection.rotate([longitude, 0, 0]); + + // Calculate the new latitude based on the y-coordinate + const b = setBounds(projection, maxLat); + let dy = newY - tlast[1]; + if (b[0][1] + dy > 0) + dy = -b[0][1]; + else if (b[1][1] + dy < height) + dy = height - b[1][1]; + projection.translate([projection.translate()[0], projection.translate()[1] + dy]); + } + + // Redraw paths with the updated projection + g.selectAll('path').attr('d', path); + + // Save last values + slast = scale; + tlast = [newX, newY]; + } + + function createSVG(selection) { + const svg = d3.select(selection) + .append('svg') + .attr('class', 'map') + .attr('width', width) + .attr('height', height) + .lower(); + + const g = svg.append('g') + .attr('transform', `translate(${margin.left}, 0)`) + .attr('transform-origin', '50% 50%'); + + projection = d3.geoMercator() + .center([0, 15]) + .scale([(innerW()) / (2 * Math.PI)]) + .translate([(innerW()) / 2, height / 1.5]); + path = d3.geoPath().projection(projection); + + // Calculate scale extent and initial scale + const bounds = setBounds(projection, maxLat); + const s = width / (bounds[1][0] - bounds[0][0]); + // The minimum and maximum zoom scales + const scaleExtent = [s, 5 * s]; + + const zoom = d3.zoom() + .scaleExtent(scaleExtent) + .on('zoom', event => { + zoomed(event, projection, path, scaleExtent, g); + }); + svg.call(zoom); + + return svg; + } + + function chart(selection) { + selection.each(function(data) { + const worldData = window.countries110m; + const countries = topojson.feature(worldData, worldData.objects.countries).features; + + const countryNameToGeoJson = {}; + countries.forEach(country => { + countryNameToGeoJson[country.properties.name] = country; + }); + + let svg = d3.select(this).select('svg.map'); + // if the SVG element doesn't exist, create it + if (svg.empty()) + svg = createSVG(this); + + updateMap(selection, svg, data, countries, countryNameToGeoJson); + }); + } + + chart.metric = function(_) { + if (!arguments.length) return metric; + metric = _; + return chart; + }; + + chart.opts = function (_) { + if (!arguments.length) return opts; + opts = _; + return chart; + }; + + chart.width = function(_) { + if (!arguments.length) return width; + width = _; + return chart; + }; + + chart.height = function(_) { + if (!arguments.length) return height; + height = _; + return chart; + }; + + return chart; +} + +function AreaChart(dualYaxis) { + var opts = {}; + var margin = { + top : 20, + right : 50, + bottom : 40, + left : 50, + }, + height = 170, + nTicks = 10, + padding = 10, + width = 760; + var labels = { x: 'Unnamed', y0: 'Unnamed', y1: 'Unnamed' }; + var format = { x: null, y0: null, y1: null}; + + var xValue = function (d) { + return d[0]; + }, + yValue0 = function (d) { + return d[1]; + }, + yValue1 = function (d) { + return d[2]; + }; + + var xScale = d3.scaleBand(); + var yScale0 = d3.scaleLinear().nice(); + var yScale1 = d3.scaleLinear().nice(); + + var xAxis = d3.axisBottom(xScale) + .tickFormat(function(d) { + if (format.x) + return GoAccess.Util.fmtValue(d, format.x); + return d; + }); + + var yAxis0 = d3.axisLeft(yScale0) + .tickFormat(function(d) { + return d3.format('.2s')(d); + }); + + var yAxis1 = d3.axisRight(yScale1) + .tickFormat(function(d) { + if (format.y1) + return GoAccess.Util.fmtValue(d, format.y1); + return d3.format('.2s')(d); + }); + + var xGrid = d3.axisBottom(xScale); + var yGrid = d3.axisLeft(yScale0); + + var area0 = d3.area() + .curve(d3.curveMonotoneX) + .x(X) + .y0(height) + .y1(Y0); + + var area1 = d3.area() + .curve(d3.curveMonotoneX) + .x(X) + .y0(Y1) + .y1(height); + + var line0 = d3.line() + .curve(d3.curveMonotoneX) + .x(X) + .y(Y0); + + var line1 = d3.line() + .curve(d3.curveMonotoneX) + .x(X) + .y(Y1); + + // The x-accessor for the path generator; xScale ∘ xValue. + function X(d) { + return (xScale(d[0]) + xScale.bandwidth() / 2); + } + + // The x-accessor for the path generator; yScale0 yValue0. + function Y0(d) { + return yScale0(d[1]); + } + + // The x-accessor for the path generator; yScale0 yValue0. + function Y1(d) { + return yScale1(d[2]); + } + + function innerW() { + return width - margin.left - margin.right; + } + + function innerH() { + return height - margin.top - margin.bottom; + } + + function getXTicks(data) { + const domain = xScale.domain(); + if (data.length < nTicks) + return domain; + + return d3.range(0, nTicks).map(function(i) { + const index = Math.floor(i * (domain.length - 1) / (nTicks - 1)); + if (index >= 0 && index < domain.length) + return domain[index]; + return null; + }); + } + + function getYTicks(scale) { + var domain = scale.domain(); + return d3.range(domain[0], domain[1], Math.ceil(domain[1] / nTicks)); + } + + // Convert data to standard representation greedily; + // this is needed for nondeterministic accessors. + function mapData(data) { + var _datum = function (d, i) { + var datum = [xValue.call(data, d, i), yValue0.call(data, d, i)]; + dualYaxis && datum.push(yValue1.call(data, d, i)); + return datum; + }; + return data.map(function (d, i) { + return _datum(d, i); + }); + } + + function updateScales(data) { + // Update the x-scale. + xScale.domain(data.map(function (d) { + return d[0]; + })) + .range([0, innerW()]); + + // Update the y-scale. + yScale0.domain([0, d3.max(data, function (d) { + return d[1]; + })]) + .range([innerH(), 0]); + + // Update the y-scale. + dualYaxis && yScale1.domain([0, d3.max(data, function (d) { + return d[2]; + })]) + .range([innerH(), 0]); + } + + function toggleOpacity(ele, op) { + d3.select(ele.parentNode).selectAll('.' + (ele.getAttribute('data-yaxis') == 'y0' ? 'y1' : 'y0')).attr('style', op); + } + + function setLegendLabels(svg) { + // Legend Color + var rect = svg.selectAll('rect.legend.y0').data([null]); + + var rectEnter = rect.enter() + .append('rect') + .attr('class', 'legend y0') + .attr('data-yaxis', 'y0') + .on('mousemove', function(d, i) { + toggleOpacity(this, 'opacity:0.1'); + }) + .on('mouseleave', function(d, i) { + toggleOpacity(this, null); + }) + .attr('y', (height - 15)); + + rectEnter.merge(rect) + .attr('x', (width / 2) - 100); + + // Legend Labels + var text = svg.selectAll('text.legend.y0').data([null]); + + var textEnter = text.enter() + .append('text') + .attr('class', 'legend y0') + .attr('data-yaxis', 'y0') + .on('mousemove', function(d, i) { + toggleOpacity(this, 'opacity:0.1'); + }) + .on('mouseleave', function(d, i) { + toggleOpacity(this, null); + }) + .attr('y', (height - 6)); + + textEnter.merge(text) + .attr('x', (width / 2) - 85) + .text(labels.y0); + + if (!dualYaxis) + return; + + // Legend Labels + rect = svg.selectAll('rect.legend.y1').data([null]); + + var rectEnter = rect.enter() + .append('rect') + .attr('class', 'legend y1') + .attr('data-yaxis', 'y1') + .on('mousemove', function(d, i) { + toggleOpacity(this, 'opacity:0.1'); + }) + .on('mouseleave', function(d, i) { + toggleOpacity(this, null); + }) + .attr('y', (height - 15)); + + rectEnter.merge(rect) + .attr('x', (width / 2)); + + // Legend Labels + text = svg.selectAll('text.legend.y1').data([null]); + + var textEnter = text.enter() + .append('text') + .attr('class', 'legend y1') + .attr('data-yaxis', 'y1') + .on('mousemove', function(d, i) { + toggleOpacity(this, 'opacity:0.1'); + }) + .on('mouseleave', function(d, i) { + toggleOpacity(this, null); + }) + .attr('y', (height - 6)); + + textEnter.merge(text) + .attr('x', (width / 2) + 15) + .text(labels.y1); + } + + function setAxisLabels(svg) { + // Labels + svg.selectAll('text.axis-label.y0') + .data([null]) + .enter() + .append('text') + .attr('class', 'axis-label y0') + .attr('y', 10) + .attr('x', 53) + .text(labels.y0); + + if (!dualYaxis) return; + + // Labels + var tEnter = svg.selectAll('text.axis-label.y1') + .data([null]) + .enter() + .append('text') + .attr('class', 'axis-label y1') + .attr('y', 10) + .text(labels.y1); + + dualYaxis && tEnter.attr('x', width - 25); + } + + function createSkeleton(svg) { + const g = svg.append('g'); + + // Lines + g.append('g') + .attr('class', 'line line0 y0'); + dualYaxis && g.append('g') + .attr('class', 'line line1 y1'); + + // Areas + g.append('g') + .attr('class', 'area area0 y0'); + dualYaxis && g.append('g') + .attr('class', 'area area1 y1'); + + // Points + g.append('g') + .attr('class', 'points y0'); + dualYaxis && g.append('g') + .attr('class', 'points y1'); + + // Grid + g.append('g') + .attr('class', 'x grid'); + g.append('g') + .attr('class', 'y grid'); + + // Axis + g.append('g') + .attr('class', 'x axis'); + g.append('g') + .attr('class', 'y0 axis'); + dualYaxis && g.append('g') + .attr('class', 'y1 axis'); + + // Rects + g.append('g') + .attr('class', 'rects'); + + setAxisLabels(svg); + setLegendLabels(svg); + + // Mouseover line + g.append('line') + .attr('y2', innerH()) + .attr('y1', 0) + .attr('class', 'indicator'); + } + + function pathLen(d) { + return d.node().getTotalLength(); + } + + function addLine(g, data, line, cName) { + // Update the line path. + var path = g.select('g.' + cName).selectAll('path.' + cName).data([data]); + + // enter + var pathEnter = path.enter() + .append('svg:path') + .attr('d', line) + .attr('class', cName) + .attr('stroke-dasharray', function(d) { + var pl = pathLen(d3.select(this)); + return pl + ' ' + pl; + }) + .attr('stroke-dashoffset', function(d) { + return pathLen(d3.select(this)); + }); + + // update + pathEnter.merge(path) + .attr('d', line) + .transition() + .attr('stroke-dasharray', function(d) { + var pl = pathLen(d3.select(this)); + return pl + ' ' + pl; + }) + .duration(2000) + .attr('stroke-dashoffset', 0); + + // remove elements + path.exit().remove(); + + } + + function addArea(g, data, cb, cName) { + // Update the area path. + var area = g.select('g.' + cName).selectAll('path.' + cName) + .data([data]); + + var areaEnter = area.enter() + .append('svg:path') + .attr('class', cName); + + areaEnter.merge(area) + .attr('d', cb); + + // remove elements + area.exit().remove(); + } + + // Update the area path and lines. + function addAreaLines(g, data) { + // Update the area path. + addArea(g, data, area0.y0(yScale0.range()[0]), 'area0'); + // Update the line path. + addLine(g, data, line0, 'line0'); + // Update the area path. + addArea(g, data, area1.y1(yScale1.range()[0]), 'area1'); + // Update the line path. + addLine(g, data, line1, 'line1'); + } + + // Update chart points + function addPoints(g, data) { + var radius = data.length > 100 ? 1 : 2.5; + + var points = g.select('g.points.y0').selectAll('circle.point').data(data); + + var pointsEnter = points.enter() + .append('svg:circle') + .attr('r', radius) + .attr('class', 'point'); + + pointsEnter.merge(points) + .attr('cx', function(d) { + return (xScale(d[0]) + xScale.bandwidth() / 2); + }) + .attr('cy', function(d) { + return yScale0(d[1]); + }); + + // remove elements + points.exit().remove(); + + if (!dualYaxis) + return; + + points = g.select('g.points.y1').selectAll('circle.point').data(data); + + pointsEnter = points.enter() + .append('svg:circle') + .attr('r', radius) + .attr('class', 'point'); + + pointsEnter.merge(points) + .attr('cx', function(d) { + return (xScale(d[0]) + xScale.bandwidth() / 2); + }) + .attr('cy', function(d) { + return yScale1(d[2]); + }); + + // remove elements + points.exit().remove(); + } + + function addAxis(g, data) { + var xTicks = getXTicks(data); + var tickDistance = xTicks.length > 1 ? (xScale(xTicks[1]) - xScale(xTicks[0])) : innerW(); + var labelW = tickDistance - padding; + + // Update the x-axis. + g.select('.x.axis') + .attr('transform', 'translate(0,' + yScale0.range()[0] + ')') + .call(xAxis.tickValues(xTicks)) + .selectAll(".tick text") + .call(truncate, labelW > 0 ? labelW : innerW()); + + // Update the y0-axis. + g.select('.y0.axis') + .call(yAxis0.tickValues(getYTicks(yScale0))); + + if (!dualYaxis) + return; + + // Update the y1-axis. + g.select('.y1.axis') + .attr('transform', 'translate(' + innerW() + ', 0)') + .call(yAxis1.tickValues(getYTicks(yScale1))); + } + + // Update the X-Y grid. + function addGrid(g, data) { + g.select('.x.grid') + .attr('transform', 'translate(0,' + yScale0.range()[0] + ')') + .call(xGrid + .tickValues(getXTicks(data)) + .tickSize(-innerH(), 0, 0) + .tickSizeOuter(0) + .tickFormat('') + ); + + g.select('.y.grid') + .call(yGrid + .tickValues(getYTicks(yScale0)) + .tickSize(-innerW(), 0) + .tickSizeOuter(0) + .tickFormat('') + ); + } + + function formatTooltip(data) { + var d = data.slice(0); + + d[0] = (format.x) ? GoAccess.Util.fmtValue(d[0], format.x) : d[0]; + d[1] = (format.y0) ? GoAccess.Util.fmtValue(d[1], format.y0) : d3.format(',')(d[1]); + dualYaxis && (d[2] = (format.y1) ? GoAccess.Util.fmtValue(d[2], format.y1) : d3.format(',')(d[2])); + + var template = d3.select('#tpl-chart-tooltip').html(); + return Hogan.compile(template).render({ + 'data': d + }); + } + + function mouseover(event, selection, data) { + var tooltip = selection.select('.chart-tooltip-wrap'); + tooltip.html(formatTooltip(data)) + .style('left', X(data) + 'px') + .style('top', (d3.pointer(event)[1] + 10) + 'px') + .style('display', 'block'); + + selection.select('line.indicator') + .style('display', 'block') + .attr('transform', 'translate(' + X(data) + ',' + 0 + ')'); + } + + function mouseout(selection, g) { + var tooltip = selection.select('.chart-tooltip-wrap'); + tooltip.style('display', 'none'); + + g.select('line.indicator').style('display', 'none'); + } + + function addRects(selection, g, data) { + var w = (innerW() / data.length); + + var rects = g.select('g.rects').selectAll('rect').data(data); + + var rectsEnter = rects.enter() + .append('svg:rect') + .attr('height', innerH()) + .attr('class', 'point'); + + rectsEnter.merge(rects) + .attr('width', w) + .attr('x', function(d, i) { + return (w * i); + }) + .attr('y', 0) + .on('mousemove', function(event) { + mouseover(event, selection, d3.select(this).datum()); + }) + .on('mouseleave', function(event) { + mouseout(selection, g); + }); + + // remove elements + rects.exit().remove(); + } + + function chart(selection) { + selection.each(function (data) { + // normalize data + data = mapData(data); + // updates X-Y scales + updateScales(data); + + // select the SVG element, if it exists + let svg = d3.select(this).select('svg'); + + // if the SVG element doesn't exist, create it + if (svg.empty()) { + svg = d3.select(this).append('svg').attr('width', width).attr('height', height); + createSkeleton(svg); + } + + // Update the inner dimensions. + var g = svg.select('g') + .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); + + // Add grid + addGrid(g, data); + // Add chart lines and areas + addAreaLines(g, data); + // Add chart points + addPoints(g, data); + // Add axis + addAxis(g, data); + // Add rects + addRects(selection, g, data); + }); + } + + chart.opts = function (_) { + if (!arguments.length) return opts; + opts = _; + return chart; + }; + + chart.format = function (_) { + if (!arguments.length) return format; + format = _; + return chart; + }; + + chart.labels = function (_) { + if (!arguments.length) return labels; + labels = _; + return chart; + }; + + chart.margin = function (_) { + if (!arguments.length) return margin; + margin = _; + return chart; + }; + + chart.width = function (_) { + if (!arguments.length) return width; + width = _; + return chart; + }; + + chart.height = function (_) { + if (!arguments.length) return height; + height = _; + return chart; + }; + + chart.x = function (_) { + if (!arguments.length) return xValue; + xValue = _; + return chart; + }; + + chart.y0 = function (_) { + if (!arguments.length) return yValue0; + yValue0 = _; + return chart; + }; + + chart.y1 = function (_) { + if (!arguments.length) return yValue1; + yValue1 = _; + return chart; + }; + + return chart; +} + +function BarChart(dualYaxis) { + var opts = {}; + var margin = { + top : 20, + right : 50, + bottom : 40, + left : 50, + }, + height = 170, + nTicks = 10, + padding = 10, + width = 760; + var labels = { x: 'Unnamed', y0: 'Unnamed', y1: 'Unnamed' }; + var format = { x: null, y0: null, y1: null}; + + var xValue = function (d) { + return d[0]; + }, + yValue0 = function (d) { + return d[1]; + }, + yValue1 = function (d) { + return d[2]; + }; + + var xScale = d3.scaleBand() + .paddingInner(0.1) + .paddingOuter(0.1); + var yScale0 = d3.scaleLinear().nice(); + var yScale1 = d3.scaleLinear().nice(); + + var xAxis = d3.axisBottom(xScale) + .tickFormat(function (d) { + if (format.x) + return GoAccess.Util.fmtValue(d, format.x); + return d; + }); + + var yAxis0 = d3.axisLeft(yScale0) + .tickFormat(function (d) { + return d3.format('.2s')(d); + }); + + var yAxis1 = d3.axisRight(yScale1) + .tickFormat(function (d) { + if (format.y1) + return GoAccess.Util.fmtValue(d, format.y1); + return d3.format('.2s')(d); + }); + + var xGrid = d3.axisBottom(xScale); + var yGrid = d3.axisLeft(yScale0); + + function innerW() { + return width - margin.left - margin.right; + } + + function innerH() { + return height - margin.top - margin.bottom; + } + + function getXTicks(data) { + const domain = xScale.domain(); + if (data.length < nTicks) + return domain; + + return d3.range(0, nTicks).map(function(i) { + const index = Math.floor(i * (domain.length - 1) / (nTicks - 1)); + if (index >= 0 && index < domain.length) + return domain[index]; + return null; + }); + } + + function getYTicks(scale) { + var domain = scale.domain(); + return d3.range(domain[0], domain[1], Math.ceil(domain[1] / nTicks)); + } + + // The x-accessor for the path generator; xScale ∘ xValue. + function X(d) { + return (xScale(d[0]) + xScale.bandwidth() / 2); + } + + // Convert data to standard representation greedily; + // this is needed for nondeterministic accessors. + function mapData(data) { + var _datum = function (d, i) { + var datum = [xValue.call(data, d, i), yValue0.call(data, d, i)]; + dualYaxis && datum.push(yValue1.call(data, d, i)); + return datum; + }; + return data.map(function (d, i) { + return _datum(d, i); + }); + } + + function updateScales(data) { + // Update the x-scale. + xScale.domain(data.map(function (d) { + return d[0]; + })) + .range([0, innerW()]); + + // Update the y-scale. + yScale0.domain([0, d3.max(data, function (d) { + return d[1]; + })]) + .range([innerH(), 0]); + + // Update the y-scale. + // If all values are [0, 0]. This can cause issues when drawing the + // chart because all values passed to the scale will be mapped to the + // same value in the range, thus + 0.1 e.g., Not Found visitors. + dualYaxis && yScale1.domain([0, d3.max(data, function (d) { + return d[2]; + }) + 0.1]) + .range([innerH(), 0]); + } + + function toggleOpacity(ele, op) { + d3.select(ele.parentNode).selectAll('.' + (ele.getAttribute('data-yaxis') == 'y0' ? 'y1' : 'y0')).attr('style', op); + } + + function setLegendLabels(svg) { + // Legend Color + var rect = svg.selectAll('rect.legend.y0').data([null]); + + var rectEnter = rect.enter() + .append('rect') + .attr('class', 'legend y0') + .attr('data-yaxis', 'y0') + .on('mousemove', function(d, i) { + toggleOpacity(this, 'opacity:0.1'); + }) + .on('mouseleave', function(d, i) { + toggleOpacity(this, null); + }) + .attr('y', (height - 15)); + + rectEnter.merge(rect) + .attr('x', (width / 2) - 100); + + // Legend Labels + var text = svg.selectAll('text.legend.y0').data([null]); + + var textEnter = text.enter() + .append('text') + .attr('class', 'legend y0') + .attr('data-yaxis', 'y0') + .on('mousemove', function(d, i) { + toggleOpacity(this, 'opacity:0.1'); + }) + .on('mouseleave', function(d, i) { + toggleOpacity(this, null); + }) + .attr('y', (height - 6)); + + textEnter.merge(text) + .attr('x', (width / 2) - 85) + .text(labels.y0); + + if (!dualYaxis) + return; + + // Legend Labels + rect = svg.selectAll('rect.legend.y1').data([null]); + + var rectEnter = rect.enter() + .append('rect') + .attr('class', 'legend y1') + .attr('data-yaxis', 'y1') + .on('mousemove', function(d, i) { + toggleOpacity(this, 'opacity:0.1'); + }) + .on('mouseleave', function(d, i) { + toggleOpacity(this, null); + }) + .attr('y', (height - 15)); + + rectEnter.merge(rect) + .attr('x', (width / 2)); + + // Legend Labels + text = svg.selectAll('text.legend.y1').data([null]); + + var textEnter = text.enter() + .append('text') + .attr('class', 'legend y1') + .attr('data-yaxis', 'y1') + .on('mousemove', function(d, i) { + toggleOpacity(this, 'opacity:0.1'); + }) + .on('mouseleave', function(d, i) { + toggleOpacity(this, null); + }) + .attr('y', (height - 6)); + + textEnter.merge(text) + .attr('x', (width / 2) + 15) + .text(labels.y1); + } + + function setAxisLabels(svg) { + // Labels + svg.selectAll('text.axis-label.y0') + .data([null]) + .enter() + .append('text') + .attr('class', 'axis-label y0') + .attr('y', 10) + .attr('x', 53) + .text(labels.y0); + + if (!dualYaxis) return; + + // Labels + var tEnter = svg.selectAll('text.axis-label.y1') + .data([null]) + .enter() + .append('text') + .attr('class', 'axis-label y1') + .attr('y', 10) + .text(labels.y1); + + dualYaxis && tEnter.attr('x', width - 25); + } + + function createSkeleton(svg) { + const g = svg.append('g'); + + // Grid + g.append('g') + .attr('class', 'x grid'); + g.append('g') + .attr('class', 'y grid'); + + // Axis + g.append('g') + .attr('class', 'x axis'); + g.append('g') + .attr('class', 'y0 axis'); + dualYaxis && g.append('g') + .attr('class', 'y1 axis'); + + // Bars + g.append('g') + .attr('class', 'bars y0'); + dualYaxis && g.append('g') + .attr('class', 'bars y1'); + + // Rects + g.append('g') + .attr('class', 'rects'); + + setAxisLabels(svg); + setLegendLabels(svg); + + // Mouseover line + g.append('line') + .attr('y2', innerH()) + .attr('y1', 0) + .attr('class', 'indicator'); + } + + // Update the area path and lines. + function addBars(g, data) { + var bars = g.select('g.bars.y0').selectAll('rect.bar').data(data); + + // enter + var enter = bars.enter() + .append('svg:rect') + .attr('class', 'bar') + .attr('height', 0) + .attr('width', function (d, i) { return xScale.bandwidth() / 2; }) + .attr('x', function (d, i) { return xScale(d[0]); }) + .attr('y', function (d, i) { return innerH(); }); + + // update + bars.merge(enter) + .attr('width', xScale.bandwidth() / 2) + .attr('x', function (d) { return xScale(d[0]); }) + .transition() + .delay(function (d, i) { return i / data.length * 1000; }) + .duration(500) + .attr('height', function (d, i) { return innerH() - yScale0(d[1]); }) + .attr('y', function (d, i) { return yScale0(d[1]); }); + // remove elements + bars.exit().remove(); + + if (!dualYaxis) + return; + + bars = g.select('g.bars.y1').selectAll('rect.bar').data(data); + // enter + enter = bars.enter() + .append('svg:rect') + .attr('class', 'bar') + .attr('height', 0) + .attr('width', function (d, i) { return xScale.bandwidth() / 2; }) + .attr('x', function (d) { return (xScale(d[0]) + xScale.bandwidth() / 2); }) + .attr('y', function (d, i) { return innerH(); }); + // update + bars.merge(enter) + .attr('width', xScale.bandwidth() / 2) + .attr('x', function (d) { return (xScale(d[0]) + xScale.bandwidth() / 2); }) + .transition() + .delay(function (d, i) { return i / data.length * 1000; }) + .duration(500) + .attr('height', function (d, i) { return innerH() - yScale1(d[2]); }) + .attr('y', function (d, i) { return yScale1(d[2]); }); + // remove elements + bars.exit().remove(); + } + + function addAxis(g, data) { + var xTicks = getXTicks(data); + var tickDistance = xTicks.length > 1 ? (xScale(xTicks[1]) - xScale(xTicks[0])) : innerW(); + var labelW = tickDistance - padding; + + // Update the x-axis. + g.select('.x.axis') + .attr('transform', 'translate(0,' + yScale0.range()[0] + ')') + .call(xAxis.tickValues(xTicks)) + .selectAll(".tick text") + .call(truncate, labelW > 0 ? labelW : innerW()); + + // Update the y0-axis. + g.select('.y0.axis') + .call(yAxis0.tickValues(getYTicks(yScale0))); + + if (!dualYaxis) + return; + + // Update the y1-axis. + g.select('.y1.axis') + .attr('transform', 'translate(' + innerW() + ', 0)') + .call(yAxis1.tickValues(getYTicks(yScale1))); + } + + // Update the X-Y grid. + function addGrid(g, data) { + g.select('.x.grid') + .attr('transform', 'translate(0,' + yScale0.range()[0] + ')') + .call(xGrid + .tickValues(getXTicks(data)) + .tickSize(-innerH(), 0, 0) + .tickSizeOuter(0) + .tickFormat('') + ); + + g.select('.y.grid') + .call(yGrid + .tickValues(getYTicks(yScale0)) + .tickSize(-innerW(), 0) + .tickSizeOuter(0) + .tickFormat('') + ); + } + + function formatTooltip(data) { + var d = data.slice(0); + + d[0] = (format.x) ? GoAccess.Util.fmtValue(d[0], format.x) : d[0]; + d[1] = (format.y0) ? GoAccess.Util.fmtValue(d[1], format.y0) : d3.format(',')(d[1]); + dualYaxis && (d[2] = (format.y1) ? GoAccess.Util.fmtValue(d[2], format.y1) : d3.format(',')(d[2])); + + var template = d3.select('#tpl-chart-tooltip').html(); + return Hogan.compile(template).render({ + 'data': d + }); + } + + function mouseover(event, selection, data) { + var tooltip = selection.select('.chart-tooltip-wrap'); + tooltip.html(formatTooltip(data)) + .style('left', X(data) + 'px') + .style('top', (d3.pointer(event)[1] + 10) + 'px') + .style('display', 'block'); + + selection.select('line.indicator') + .style('display', 'block') + .attr('transform', 'translate(' + X(data) + ',' + 0 + ')'); + } + + function mouseout(selection, g) { + var tooltip = selection.select('.chart-tooltip-wrap'); + tooltip.style('display', 'none'); + + g.select('line.indicator').style('display', 'none'); + } + + function addRects(selection, g, data) { + var w = (innerW() / data.length); + + var rects = g.select('g.rects').selectAll('rect').data(data); + + var rectsEnter = rects.enter() + .append('svg:rect') + .attr('height', innerH()) + .attr('class', 'point'); + + rectsEnter.merge(rects) + .attr('width', w) + .attr('x', function(d, i) { + return (w * i); + }) + .attr('y', 0) + .on('mousemove', function(event) { + mouseover(event, selection, d3.select(this).datum()); + }) + .on('mouseleave', function(event) { + mouseout(selection, g); + }); + + // remove elements + rects.exit().remove(); + } + + function chart(selection) { + selection.each(function (data) { + // normalize data + data = mapData(data); + // updates X-Y scales + updateScales(data); + + // select the SVG element, if it exists + let svg = d3.select(this).select('svg'); + + // if the SVG element doesn't exist, create it + if (svg.empty()) { + svg = d3.select(this).append('svg').attr('width', width).attr('height', height); + createSkeleton(svg); + } + + // Update the inner dimensions. + var g = svg.select('g') + .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); + + // Add grid + addGrid(g, data); + // Add axis + addAxis(g, data); + // Add chart lines and areas + addBars(g, data); + // Add rects + addRects(selection, g, data); + }); + } + + chart.opts = function (_) { + if (!arguments.length) return opts; + opts = _; + return chart; + }; + + chart.format = function (_) { + if (!arguments.length) return format; + format = _; + return chart; + }; + + chart.labels = function (_) { + if (!arguments.length) return labels; + labels = _; + return chart; + }; + + chart.width = function (_) { + if (!arguments.length) return width; + width = _; + return chart; + }; + + chart.height = function (_) { + if (!arguments.length) return height; + height = _; + return chart; + }; + + chart.x = function (_) { + if (!arguments.length) return xValue; + xValue = _; + return chart; + }; + + chart.y0 = function (_) { + if (!arguments.length) return yValue0; + yValue0 = _; + return chart; + }; + + chart.y1 = function (_) { + if (!arguments.length) return yValue1; + yValue1 = _; + return chart; + }; + + return chart; +} diff --git a/resources/js/d3.v7.min.js b/resources/js/d3.v7.min.js new file mode 100644 index 0000000000..30601f0286 --- /dev/null +++ b/resources/js/d3.v7.min.js @@ -0,0 +1,2 @@ +/* https://d3js.org v7.8.4 Copyright 2010-2023 Mike Bostock */ +!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).d3=t.d3||{})}(this,(function(t){"use strict";function n(t,n){return null==t||null==n?NaN:tn?1:t>=n?0:NaN}function e(t,n){return null==t||null==n?NaN:nt?1:n>=t?0:NaN}function r(t){let r,o,a;function u(t,n,e=0,i=t.length){if(e>>1;o(t[r],n)<0?e=r+1:i=r}while(en(t(e),r),a=(n,e)=>t(n)-e):(r=t===n||t===e?t:i,o=t,a=t),{left:u,center:function(t,n,e=0,r=t.length){const i=u(t,n,e,r-1);return i>e&&a(t[i-1],n)>-a(t[i],n)?i-1:i},right:function(t,n,e=0,i=t.length){if(e>>1;o(t[r],n)<=0?e=r+1:i=r}while(e=n&&(yield n);else{let e=-1;for(let r of t)null!=(r=n(r,++e,t))&&(r=+r)>=r&&(yield r)}}const u=r(n),c=u.right,f=u.left,s=r(o).center;var l=c;const h=p(v),d=p((function(t){const n=v(t);return(t,e,r,i,o)=>{n(t,e,(r<<=2)+0,(i<<=2)+0,o<<=2),n(t,e,r+1,i+1,o),n(t,e,r+2,i+2,o),n(t,e,r+3,i+3,o)}}));function p(t){return function(n,e,r=e){if(!((e=+e)>=0))throw new RangeError("invalid rx");if(!((r=+r)>=0))throw new RangeError("invalid ry");let{data:i,width:o,height:a}=n;if(!((o=Math.floor(o))>=0))throw new RangeError("invalid width");if(!((a=Math.floor(void 0!==a?a:i.length/o))>=0))throw new RangeError("invalid height");if(!o||!a||!e&&!r)return n;const u=e&&t(e),c=r&&t(r),f=i.slice();return u&&c?(g(u,f,i,o,a),g(u,i,f,o,a),g(u,f,i,o,a),y(c,i,f,o,a),y(c,f,i,o,a),y(c,i,f,o,a)):u?(g(u,i,f,o,a),g(u,f,i,o,a),g(u,i,f,o,a)):c&&(y(c,i,f,o,a),y(c,f,i,o,a),y(c,i,f,o,a)),n}}function g(t,n,e,r,i){for(let o=0,a=r*i;o{if(!((o-=a)>=i))return;let u=t*r[i];const c=a*t;for(let t=i,n=i+c;t{if(!((a-=u)>=o))return;let c=n*i[o];const f=u*n,s=f+u;for(let t=o,n=o+f;t=n&&++e;else{let r=-1;for(let i of t)null!=(i=n(i,++r,t))&&(i=+i)>=i&&++e}return e}function b(t){return 0|t.length}function m(t){return!(t>0)}function x(t){return"object"!=typeof t||"length"in t?t:Array.from(t)}function w(t,n){let e,r=0,i=0,o=0;if(void 0===n)for(let n of t)null!=n&&(n=+n)>=n&&(e=n-i,i+=e/++r,o+=e*(n-i));else{let a=-1;for(let u of t)null!=(u=n(u,++a,t))&&(u=+u)>=u&&(e=u-i,i+=e/++r,o+=e*(u-i))}if(r>1)return o/(r-1)}function M(t,n){const e=w(t,n);return e?Math.sqrt(e):e}function T(t,n){let e,r;if(void 0===n)for(const n of t)null!=n&&(void 0===e?n>=n&&(e=r=n):(e>n&&(e=n),r=o&&(e=r=o):(e>o&&(e=o),r0){for(o=t[--i];i>0&&(n=o,e=t[--i],o=n+e,r=e-(o-n),!r););i>0&&(r<0&&t[i-1]<0||r>0&&t[i-1]>0)&&(e=2*r,n=o+e,e==n-o&&(o=n))}return o}}class InternMap extends Map{constructor(t,n=k){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:n}}),null!=t)for(const[n,e]of t)this.set(n,e)}get(t){return super.get(S(this,t))}has(t){return super.has(S(this,t))}set(t,n){return super.set(E(this,t),n)}delete(t){return super.delete(N(this,t))}}class InternSet extends Set{constructor(t,n=k){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:n}}),null!=t)for(const n of t)this.add(n)}has(t){return super.has(S(this,t))}add(t){return super.add(E(this,t))}delete(t){return super.delete(N(this,t))}}function S({_intern:t,_key:n},e){const r=n(e);return t.has(r)?t.get(r):e}function E({_intern:t,_key:n},e){const r=n(e);return t.has(r)?t.get(r):(t.set(r,e),e)}function N({_intern:t,_key:n},e){const r=n(e);return t.has(r)&&(e=t.get(r),t.delete(r)),e}function k(t){return null!==t&&"object"==typeof t?t.valueOf():t}function C(t){return t}function P(t,...n){return q(t,C,C,n)}function z(t,...n){return q(t,Array.from,C,n)}function $(t,n){for(let e=1,r=n.length;et.pop().map((([n,e])=>[...t,n,e]))));return t}function D(t,n,...e){return q(t,C,n,e)}function R(t,n,...e){return q(t,Array.from,n,e)}function F(t){if(1!==t.length)throw new Error("duplicate key");return t[0]}function q(t,n,e,r){return function t(i,o){if(o>=r.length)return e(i);const a=new InternMap,u=r[o++];let c=-1;for(const t of i){const n=u(t,++c,i),e=a.get(n);e?e.push(t):a.set(n,[t])}for(const[n,e]of a)a.set(n,t(e,o));return n(a)}(t,0)}function U(t,n){return Array.from(n,(n=>t[n]))}function I(t,...n){if("function"!=typeof t[Symbol.iterator])throw new TypeError("values is not iterable");t=Array.from(t);let[e]=n;if(e&&2!==e.length||n.length>1){const r=Uint32Array.from(t,((t,n)=>n));return n.length>1?(n=n.map((n=>t.map(n))),r.sort(((t,e)=>{for(const r of n){const n=B(r[t],r[e]);if(n)return n}}))):(e=t.map(e),r.sort(((t,n)=>B(e[t],e[n])))),U(t,r)}return t.sort(O(e))}function O(t=n){if(t===n)return B;if("function"!=typeof t)throw new TypeError("compare is not a function");return(n,e)=>{const r=t(n,e);return r||0===r?r:(0===t(e,e))-(0===t(n,n))}}function B(t,n){return(null==t||!(t>=t))-(null==n||!(n>=n))||(tn?1:0)}var Y=Array.prototype.slice;function L(t){return()=>t}const j=Math.sqrt(50),H=Math.sqrt(10),X=Math.sqrt(2);function G(t,n,e){const r=(n-t)/Math.max(0,e),i=Math.floor(Math.log10(r)),o=r/Math.pow(10,i),a=o>=j?10:o>=H?5:o>=X?2:1;let u,c,f;return i<0?(f=Math.pow(10,-i)/a,u=Math.round(t*f),c=Math.round(n*f),u/fn&&--c,f=-f):(f=Math.pow(10,i)*a,u=Math.round(t/f),c=Math.round(n/f),u*fn&&--c),c0))return[];if((t=+t)===(n=+n))return[t];const r=n=i))return[];const u=o-i+1,c=new Array(u);if(r)if(a<0)for(let t=0;t0?(t=Math.floor(t/i)*i,n=Math.ceil(n/i)*i):i<0&&(t=Math.ceil(t*i)/i,n=Math.floor(n*i)/i),r=i}}function Q(t){return Math.max(1,Math.ceil(Math.log(_(t))/Math.LN2)+1)}function J(){var t=C,n=T,e=Q;function r(r){Array.isArray(r)||(r=Array.from(r));var i,o,a,u=r.length,c=new Array(u);for(i=0;i=h)if(t>=h&&n===T){const t=W(s,h,e);isFinite(t)&&(t>0?h=(Math.floor(h/t)+1)*t:t<0&&(h=(Math.ceil(h*-t)+1)/-t))}else d.pop()}for(var p=d.length,g=0,y=p;d[g]<=s;)++g;for(;d[y-1]>h;)--y;(g||y0?d[i-1]:s,v.x1=i0)for(i=0;i=n)&&(e=n);else{let r=-1;for(let i of t)null!=(i=n(i,++r,t))&&(e=i)&&(e=i)}return e}function nt(t,n){let e,r=-1,i=-1;if(void 0===n)for(const n of t)++i,null!=n&&(e=n)&&(e=n,r=i);else for(let o of t)null!=(o=n(o,++i,t))&&(e=o)&&(e=o,r=i);return r}function et(t,n){let e;if(void 0===n)for(const n of t)null!=n&&(e>n||void 0===e&&n>=n)&&(e=n);else{let r=-1;for(let i of t)null!=(i=n(i,++r,t))&&(e>i||void 0===e&&i>=i)&&(e=i)}return e}function rt(t,n){let e,r=-1,i=-1;if(void 0===n)for(const n of t)++i,null!=n&&(e>n||void 0===e&&n>=n)&&(e=n,r=i);else for(let o of t)null!=(o=n(o,++i,t))&&(e>o||void 0===e&&o>=o)&&(e=o,r=i);return r}function it(t,n,e=0,r=1/0,i){if(n=Math.floor(n),e=Math.floor(Math.max(0,e)),r=Math.floor(Math.min(t.length-1,r)),!(e<=n&&n<=r))return t;for(i=void 0===i?B:O(i);r>e;){if(r-e>600){const o=r-e+1,a=n-e+1,u=Math.log(o),c=.5*Math.exp(2*u/3),f=.5*Math.sqrt(u*c*(o-c)/o)*(a-o/2<0?-1:1);it(t,n,Math.max(e,Math.floor(n-a*c/o+f)),Math.min(r,Math.floor(n+(o-a)*c/o+f)),i)}const o=t[n];let a=e,u=r;for(ot(t,e,n),i(t[r],o)>0&&ot(t,e,r);a0;)--u}0===i(t[e],o)?ot(t,e,u):(++u,ot(t,u,r)),u<=n&&(e=u+1),n<=u&&(r=u-1)}return t}function ot(t,n,e){const r=t[n];t[n]=t[e],t[e]=r}function at(t,e=n){let r,i=!1;if(1===e.length){let o;for(const a of t){const t=e(a);(i?n(t,o)>0:0===n(t,t))&&(r=a,o=t,i=!0)}}else for(const n of t)(i?e(n,r)>0:0===e(n,n))&&(r=n,i=!0);return r}function ut(t,n,e){if((r=(t=Float64Array.from(a(t,e))).length)&&!isNaN(n=+n)){if(n<=0||r<2)return et(t);if(n>=1)return tt(t);var r,i=(r-1)*n,o=Math.floor(i),u=tt(it(t,o).subarray(0,o+1));return u+(et(t.subarray(o+1))-u)*(i-o)}}function ct(t,n,e=o){if((r=t.length)&&!isNaN(n=+n)){if(n<=0||r<2)return+e(t[0],0,t);if(n>=1)return+e(t[r-1],r-1,t);var r,i=(r-1)*n,a=Math.floor(i),u=+e(t[a],a,t);return u+(+e(t[a+1],a+1,t)-u)*(i-a)}}function ft(t,n,e){if((r=(t=Float64Array.from(a(t,e))).length)&&!isNaN(n=+n)){if(n<=0||r<2)return rt(t);if(n>=1)return nt(t);var r,i=Math.floor((r-1)*n),o=it(Uint32Array.from(t,((t,n)=>n)),i,0,r-1,((n,e)=>B(t[n],t[e])));return at(o.subarray(0,i+1),(n=>t[n]))}}function st(t){return Array.from(function*(t){for(const n of t)yield*n}(t))}function lt(t,n){return[t,n]}function ht(t,n,e){t=+t,n=+n,e=(i=arguments.length)<2?(n=t,t=0,1):i<3?1:+e;for(var r=-1,i=0|Math.max(0,Math.ceil((n-t)/e)),o=new Array(i);++r+t(n)}function Ct(t,n){return n=Math.max(0,t.bandwidth()-2*n)/2,t.round()&&(n=Math.round(n)),e=>+t(e)+n}function Pt(){return!this.__axis}function zt(t,n){var e=[],r=null,i=null,o=6,a=6,u=3,c="undefined"!=typeof window&&window.devicePixelRatio>1?0:.5,f=t===wt||t===At?-1:1,s=t===At||t===Mt?"x":"y",l=t===wt||t===Tt?Et:Nt;function h(h){var d=null==r?n.ticks?n.ticks.apply(n,e):n.domain():r,p=null==i?n.tickFormat?n.tickFormat.apply(n,e):xt:i,g=Math.max(o,0)+u,y=n.range(),v=+y[0]+c,_=+y[y.length-1]+c,b=(n.bandwidth?Ct:kt)(n.copy(),c),m=h.selection?h.selection():h,x=m.selectAll(".domain").data([null]),w=m.selectAll(".tick").data(d,n).order(),M=w.exit(),T=w.enter().append("g").attr("class","tick"),A=w.select("line"),S=w.select("text");x=x.merge(x.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),w=w.merge(T),A=A.merge(T.append("line").attr("stroke","currentColor").attr(s+"2",f*o)),S=S.merge(T.append("text").attr("fill","currentColor").attr(s,f*g).attr("dy",t===wt?"0em":t===Tt?"0.71em":"0.32em")),h!==m&&(x=x.transition(h),w=w.transition(h),A=A.transition(h),S=S.transition(h),M=M.transition(h).attr("opacity",St).attr("transform",(function(t){return isFinite(t=b(t))?l(t+c):this.getAttribute("transform")})),T.attr("opacity",St).attr("transform",(function(t){var n=this.parentNode.__axis;return l((n&&isFinite(n=n(t))?n:b(t))+c)}))),M.remove(),x.attr("d",t===At||t===Mt?a?"M"+f*a+","+v+"H"+c+"V"+_+"H"+f*a:"M"+c+","+v+"V"+_:a?"M"+v+","+f*a+"V"+c+"H"+_+"V"+f*a:"M"+v+","+c+"H"+_),w.attr("opacity",1).attr("transform",(function(t){return l(b(t)+c)})),A.attr(s+"2",f*o),S.attr(s,f*g).text(p),m.filter(Pt).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",t===Mt?"start":t===At?"end":"middle"),m.each((function(){this.__axis=b}))}return h.scale=function(t){return arguments.length?(n=t,h):n},h.ticks=function(){return e=Array.from(arguments),h},h.tickArguments=function(t){return arguments.length?(e=null==t?[]:Array.from(t),h):e.slice()},h.tickValues=function(t){return arguments.length?(r=null==t?null:Array.from(t),h):r&&r.slice()},h.tickFormat=function(t){return arguments.length?(i=t,h):i},h.tickSize=function(t){return arguments.length?(o=a=+t,h):o},h.tickSizeInner=function(t){return arguments.length?(o=+t,h):o},h.tickSizeOuter=function(t){return arguments.length?(a=+t,h):a},h.tickPadding=function(t){return arguments.length?(u=+t,h):u},h.offset=function(t){return arguments.length?(c=+t,h):c},h}var $t={value:()=>{}};function Dt(){for(var t,n=0,e=arguments.length,r={};n=0&&(n=t.slice(e+1),t=t.slice(0,e)),t&&!r.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}}))),a=-1,u=o.length;if(!(arguments.length<2)){if(null!=n&&"function"!=typeof n)throw new Error("invalid callback: "+n);for(;++a0)for(var e,r,i=new Array(e),o=0;o=0&&"xmlns"!==(n=t.slice(0,e))&&(t=t.slice(e+1)),It.hasOwnProperty(n)?{space:It[n],local:t}:t}function Bt(t){return function(){var n=this.ownerDocument,e=this.namespaceURI;return e===Ut&&n.documentElement.namespaceURI===Ut?n.createElement(t):n.createElementNS(e,t)}}function Yt(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function Lt(t){var n=Ot(t);return(n.local?Yt:Bt)(n)}function jt(){}function Ht(t){return null==t?jt:function(){return this.querySelector(t)}}function Xt(t){return null==t?[]:Array.isArray(t)?t:Array.from(t)}function Gt(){return[]}function Vt(t){return null==t?Gt:function(){return this.querySelectorAll(t)}}function Wt(t){return function(){return this.matches(t)}}function Zt(t){return function(n){return n.matches(t)}}var Kt=Array.prototype.find;function Qt(){return this.firstElementChild}var Jt=Array.prototype.filter;function tn(){return Array.from(this.children)}function nn(t){return new Array(t.length)}function en(t,n){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=n}function rn(t,n,e,r,i,o){for(var a,u=0,c=n.length,f=o.length;un?1:t>=n?0:NaN}function fn(t){return function(){this.removeAttribute(t)}}function sn(t){return function(){this.removeAttributeNS(t.space,t.local)}}function ln(t,n){return function(){this.setAttribute(t,n)}}function hn(t,n){return function(){this.setAttributeNS(t.space,t.local,n)}}function dn(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttribute(t):this.setAttribute(t,e)}}function pn(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,e)}}function gn(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function yn(t){return function(){this.style.removeProperty(t)}}function vn(t,n,e){return function(){this.style.setProperty(t,n,e)}}function _n(t,n,e){return function(){var r=n.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,e)}}function bn(t,n){return t.style.getPropertyValue(n)||gn(t).getComputedStyle(t,null).getPropertyValue(n)}function mn(t){return function(){delete this[t]}}function xn(t,n){return function(){this[t]=n}}function wn(t,n){return function(){var e=n.apply(this,arguments);null==e?delete this[t]:this[t]=e}}function Mn(t){return t.trim().split(/^|\s+/)}function Tn(t){return t.classList||new An(t)}function An(t){this._node=t,this._names=Mn(t.getAttribute("class")||"")}function Sn(t,n){for(var e=Tn(t),r=-1,i=n.length;++r=0&&(this._names.splice(n,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var Vn=[null];function Wn(t,n){this._groups=t,this._parents=n}function Zn(){return new Wn([[document.documentElement]],Vn)}function Kn(t){return"string"==typeof t?new Wn([[document.querySelector(t)]],[document.documentElement]):new Wn([[t]],Vn)}Wn.prototype=Zn.prototype={constructor:Wn,select:function(t){"function"!=typeof t&&(t=Ht(t));for(var n=this._groups,e=n.length,r=new Array(e),i=0;i=m&&(m=b+1);!(_=y[m])&&++m=0;)(r=i[o])&&(a&&4^r.compareDocumentPosition(a)&&a.parentNode.insertBefore(r,a),a=r);return this},sort:function(t){function n(n,e){return n&&e?t(n.__data__,e.__data__):!n-!e}t||(t=cn);for(var e=this._groups,r=e.length,i=new Array(r),o=0;o1?this.each((null==n?yn:"function"==typeof n?_n:vn)(t,n,null==e?"":e)):bn(this.node(),t)},property:function(t,n){return arguments.length>1?this.each((null==n?mn:"function"==typeof n?wn:xn)(t,n)):this.node()[t]},classed:function(t,n){var e=Mn(t+"");if(arguments.length<2){for(var r=Tn(this.node()),i=-1,o=e.length;++i=0&&(n=t.slice(e+1),t=t.slice(0,e)),{type:t,name:n}}))}(t+""),a=o.length;if(!(arguments.length<2)){for(u=n?jn:Ln,r=0;r()=>t;function se(t,{sourceEvent:n,subject:e,target:r,identifier:i,active:o,x:a,y:u,dx:c,dy:f,dispatch:s}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},subject:{value:e,enumerable:!0,configurable:!0},target:{value:r,enumerable:!0,configurable:!0},identifier:{value:i,enumerable:!0,configurable:!0},active:{value:o,enumerable:!0,configurable:!0},x:{value:a,enumerable:!0,configurable:!0},y:{value:u,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:f,enumerable:!0,configurable:!0},_:{value:s}})}function le(t){return!t.ctrlKey&&!t.button}function he(){return this.parentNode}function de(t,n){return null==n?{x:t.x,y:t.y}:n}function pe(){return navigator.maxTouchPoints||"ontouchstart"in this}function ge(t,n,e){t.prototype=n.prototype=e,e.constructor=t}function ye(t,n){var e=Object.create(t.prototype);for(var r in n)e[r]=n[r];return e}function ve(){}se.prototype.on=function(){var t=this._.on.apply(this._,arguments);return t===this._?this:t};var _e=.7,be=1/_e,me="\\s*([+-]?\\d+)\\s*",xe="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",we="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",Me=/^#([0-9a-f]{3,8})$/,Te=new RegExp(`^rgb\\(${me},${me},${me}\\)$`),Ae=new RegExp(`^rgb\\(${we},${we},${we}\\)$`),Se=new RegExp(`^rgba\\(${me},${me},${me},${xe}\\)$`),Ee=new RegExp(`^rgba\\(${we},${we},${we},${xe}\\)$`),Ne=new RegExp(`^hsl\\(${xe},${we},${we}\\)$`),ke=new RegExp(`^hsla\\(${xe},${we},${we},${xe}\\)$`),Ce={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};function Pe(){return this.rgb().formatHex()}function ze(){return this.rgb().formatRgb()}function $e(t){var n,e;return t=(t+"").trim().toLowerCase(),(n=Me.exec(t))?(e=n[1].length,n=parseInt(n[1],16),6===e?De(n):3===e?new Ue(n>>8&15|n>>4&240,n>>4&15|240&n,(15&n)<<4|15&n,1):8===e?Re(n>>24&255,n>>16&255,n>>8&255,(255&n)/255):4===e?Re(n>>12&15|n>>8&240,n>>8&15|n>>4&240,n>>4&15|240&n,((15&n)<<4|15&n)/255):null):(n=Te.exec(t))?new Ue(n[1],n[2],n[3],1):(n=Ae.exec(t))?new Ue(255*n[1]/100,255*n[2]/100,255*n[3]/100,1):(n=Se.exec(t))?Re(n[1],n[2],n[3],n[4]):(n=Ee.exec(t))?Re(255*n[1]/100,255*n[2]/100,255*n[3]/100,n[4]):(n=Ne.exec(t))?je(n[1],n[2]/100,n[3]/100,1):(n=ke.exec(t))?je(n[1],n[2]/100,n[3]/100,n[4]):Ce.hasOwnProperty(t)?De(Ce[t]):"transparent"===t?new Ue(NaN,NaN,NaN,0):null}function De(t){return new Ue(t>>16&255,t>>8&255,255&t,1)}function Re(t,n,e,r){return r<=0&&(t=n=e=NaN),new Ue(t,n,e,r)}function Fe(t){return t instanceof ve||(t=$e(t)),t?new Ue((t=t.rgb()).r,t.g,t.b,t.opacity):new Ue}function qe(t,n,e,r){return 1===arguments.length?Fe(t):new Ue(t,n,e,null==r?1:r)}function Ue(t,n,e,r){this.r=+t,this.g=+n,this.b=+e,this.opacity=+r}function Ie(){return`#${Le(this.r)}${Le(this.g)}${Le(this.b)}`}function Oe(){const t=Be(this.opacity);return`${1===t?"rgb(":"rgba("}${Ye(this.r)}, ${Ye(this.g)}, ${Ye(this.b)}${1===t?")":`, ${t})`}`}function Be(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function Ye(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function Le(t){return((t=Ye(t))<16?"0":"")+t.toString(16)}function je(t,n,e,r){return r<=0?t=n=e=NaN:e<=0||e>=1?t=n=NaN:n<=0&&(t=NaN),new Ge(t,n,e,r)}function He(t){if(t instanceof Ge)return new Ge(t.h,t.s,t.l,t.opacity);if(t instanceof ve||(t=$e(t)),!t)return new Ge;if(t instanceof Ge)return t;var n=(t=t.rgb()).r/255,e=t.g/255,r=t.b/255,i=Math.min(n,e,r),o=Math.max(n,e,r),a=NaN,u=o-i,c=(o+i)/2;return u?(a=n===o?(e-r)/u+6*(e0&&c<1?0:a,new Ge(a,u,c,t.opacity)}function Xe(t,n,e,r){return 1===arguments.length?He(t):new Ge(t,n,e,null==r?1:r)}function Ge(t,n,e,r){this.h=+t,this.s=+n,this.l=+e,this.opacity=+r}function Ve(t){return(t=(t||0)%360)<0?t+360:t}function We(t){return Math.max(0,Math.min(1,t||0))}function Ze(t,n,e){return 255*(t<60?n+(e-n)*t/60:t<180?e:t<240?n+(e-n)*(240-t)/60:n)}ge(ve,$e,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:Pe,formatHex:Pe,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return He(this).formatHsl()},formatRgb:ze,toString:ze}),ge(Ue,qe,ye(ve,{brighter(t){return t=null==t?be:Math.pow(be,t),new Ue(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?_e:Math.pow(_e,t),new Ue(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new Ue(Ye(this.r),Ye(this.g),Ye(this.b),Be(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Ie,formatHex:Ie,formatHex8:function(){return`#${Le(this.r)}${Le(this.g)}${Le(this.b)}${Le(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:Oe,toString:Oe})),ge(Ge,Xe,ye(ve,{brighter(t){return t=null==t?be:Math.pow(be,t),new Ge(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?_e:Math.pow(_e,t),new Ge(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),n=isNaN(t)||isNaN(this.s)?0:this.s,e=this.l,r=e+(e<.5?e:1-e)*n,i=2*e-r;return new Ue(Ze(t>=240?t-240:t+120,i,r),Ze(t,i,r),Ze(t<120?t+240:t-120,i,r),this.opacity)},clamp(){return new Ge(Ve(this.h),We(this.s),We(this.l),Be(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=Be(this.opacity);return`${1===t?"hsl(":"hsla("}${Ve(this.h)}, ${100*We(this.s)}%, ${100*We(this.l)}%${1===t?")":`, ${t})`}`}}));const Ke=Math.PI/180,Qe=180/Math.PI,Je=.96422,tr=1,nr=.82521,er=4/29,rr=6/29,ir=3*rr*rr,or=rr*rr*rr;function ar(t){if(t instanceof cr)return new cr(t.l,t.a,t.b,t.opacity);if(t instanceof gr)return yr(t);t instanceof Ue||(t=Fe(t));var n,e,r=hr(t.r),i=hr(t.g),o=hr(t.b),a=fr((.2225045*r+.7168786*i+.0606169*o)/tr);return r===i&&i===o?n=e=a:(n=fr((.4360747*r+.3850649*i+.1430804*o)/Je),e=fr((.0139322*r+.0971045*i+.7141733*o)/nr)),new cr(116*a-16,500*(n-a),200*(a-e),t.opacity)}function ur(t,n,e,r){return 1===arguments.length?ar(t):new cr(t,n,e,null==r?1:r)}function cr(t,n,e,r){this.l=+t,this.a=+n,this.b=+e,this.opacity=+r}function fr(t){return t>or?Math.pow(t,1/3):t/ir+er}function sr(t){return t>rr?t*t*t:ir*(t-er)}function lr(t){return 255*(t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function hr(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function dr(t){if(t instanceof gr)return new gr(t.h,t.c,t.l,t.opacity);if(t instanceof cr||(t=ar(t)),0===t.a&&0===t.b)return new gr(NaN,0=1?(e=1,n-1):Math.floor(e*n),i=t[r],o=t[r+1],a=r>0?t[r-1]:2*i-o,u=r()=>t;function Pr(t,n){return function(e){return t+e*n}}function zr(t,n){var e=n-t;return e?Pr(t,e>180||e<-180?e-360*Math.round(e/360):e):Cr(isNaN(t)?n:t)}function $r(t){return 1==(t=+t)?Dr:function(n,e){return e-n?function(t,n,e){return t=Math.pow(t,e),n=Math.pow(n,e)-t,e=1/e,function(r){return Math.pow(t+r*n,e)}}(n,e,t):Cr(isNaN(n)?e:n)}}function Dr(t,n){var e=n-t;return e?Pr(t,e):Cr(isNaN(t)?n:t)}var Rr=function t(n){var e=$r(n);function r(t,n){var r=e((t=qe(t)).r,(n=qe(n)).r),i=e(t.g,n.g),o=e(t.b,n.b),a=Dr(t.opacity,n.opacity);return function(n){return t.r=r(n),t.g=i(n),t.b=o(n),t.opacity=a(n),t+""}}return r.gamma=t,r}(1);function Fr(t){return function(n){var e,r,i=n.length,o=new Array(i),a=new Array(i),u=new Array(i);for(e=0;eo&&(i=n.slice(o,i),u[a]?u[a]+=i:u[++a]=i),(e=e[0])===(r=r[0])?u[a]?u[a]+=r:u[++a]=r:(u[++a]=null,c.push({i:a,x:Lr(e,r)})),o=Xr.lastIndex;return o180?n+=360:n-t>180&&(t+=360),o.push({i:e.push(i(e)+"rotate(",null,r)-2,x:Lr(t,n)})):n&&e.push(i(e)+"rotate("+n+r)}(o.rotate,a.rotate,u,c),function(t,n,e,o){t!==n?o.push({i:e.push(i(e)+"skewX(",null,r)-2,x:Lr(t,n)}):n&&e.push(i(e)+"skewX("+n+r)}(o.skewX,a.skewX,u,c),function(t,n,e,r,o,a){if(t!==e||n!==r){var u=o.push(i(o)+"scale(",null,",",null,")");a.push({i:u-4,x:Lr(t,e)},{i:u-2,x:Lr(n,r)})}else 1===e&&1===r||o.push(i(o)+"scale("+e+","+r+")")}(o.scaleX,o.scaleY,a.scaleX,a.scaleY,u,c),o=a=null,function(t){for(var n,e=-1,r=c.length;++e=0&&n._call.call(void 0,t),n=n._next;--vi}function Pi(){wi=(xi=Ti.now())+Mi,vi=_i=0;try{Ci()}finally{vi=0,function(){var t,n,e=gi,r=1/0;for(;e;)e._call?(r>e._time&&(r=e._time),t=e,e=e._next):(n=e._next,e._next=null,e=t?t._next=n:gi=n);yi=t,$i(r)}(),wi=0}}function zi(){var t=Ti.now(),n=t-xi;n>mi&&(Mi-=n,xi=t)}function $i(t){vi||(_i&&(_i=clearTimeout(_i)),t-wi>24?(t<1/0&&(_i=setTimeout(Pi,t-Ti.now()-Mi)),bi&&(bi=clearInterval(bi))):(bi||(xi=Ti.now(),bi=setInterval(zi,mi)),vi=1,Ai(Pi)))}function Di(t,n,e){var r=new Ni;return n=null==n?0:+n,r.restart((e=>{r.stop(),t(e+n)}),n,e),r}Ni.prototype=ki.prototype={constructor:Ni,restart:function(t,n,e){if("function"!=typeof t)throw new TypeError("callback is not a function");e=(null==e?Si():+e)+(null==n?0:+n),this._next||yi===this||(yi?yi._next=this:gi=this,yi=this),this._call=t,this._time=e,$i()},stop:function(){this._call&&(this._call=null,this._time=1/0,$i())}};var Ri=Dt("start","end","cancel","interrupt"),Fi=[],qi=0,Ui=1,Ii=2,Oi=3,Bi=4,Yi=5,Li=6;function ji(t,n,e,r,i,o){var a=t.__transition;if(a){if(e in a)return}else t.__transition={};!function(t,n,e){var r,i=t.__transition;function o(t){e.state=Ui,e.timer.restart(a,e.delay,e.time),e.delay<=t&&a(t-e.delay)}function a(o){var f,s,l,h;if(e.state!==Ui)return c();for(f in i)if((h=i[f]).name===e.name){if(h.state===Oi)return Di(a);h.state===Bi?(h.state=Li,h.timer.stop(),h.on.call("interrupt",t,t.__data__,h.index,h.group),delete i[f]):+fqi)throw new Error("too late; already scheduled");return e}function Xi(t,n){var e=Gi(t,n);if(e.state>Oi)throw new Error("too late; already running");return e}function Gi(t,n){var e=t.__transition;if(!e||!(e=e[n]))throw new Error("transition not found");return e}function Vi(t,n){var e,r,i,o=t.__transition,a=!0;if(o){for(i in n=null==n?null:n+"",o)(e=o[i]).name===n?(r=e.state>Ii&&e.state=0&&(t=t.slice(0,n)),!t||"start"===t}))}(n)?Hi:Xi;return function(){var a=o(this,t),u=a.on;u!==r&&(i=(r=u).copy()).on(n,e),a.on=i}}(e,t,n))},attr:function(t,n){var e=Ot(t),r="transform"===e?ei:Qi;return this.attrTween(t,"function"==typeof n?(e.local?io:ro)(e,r,Ki(this,"attr."+t,n)):null==n?(e.local?to:Ji)(e):(e.local?eo:no)(e,r,n))},attrTween:function(t,n){var e="attr."+t;if(arguments.length<2)return(e=this.tween(e))&&e._value;if(null==n)return this.tween(e,null);if("function"!=typeof n)throw new Error;var r=Ot(t);return this.tween(e,(r.local?oo:ao)(r,n))},style:function(t,n,e){var r="transform"==(t+="")?ni:Qi;return null==n?this.styleTween(t,function(t,n){var e,r,i;return function(){var o=bn(this,t),a=(this.style.removeProperty(t),bn(this,t));return o===a?null:o===e&&a===r?i:i=n(e=o,r=a)}}(t,r)).on("end.style."+t,ho(t)):"function"==typeof n?this.styleTween(t,function(t,n,e){var r,i,o;return function(){var a=bn(this,t),u=e(this),c=u+"";return null==u&&(this.style.removeProperty(t),c=u=bn(this,t)),a===c?null:a===r&&c===i?o:(i=c,o=n(r=a,u))}}(t,r,Ki(this,"style."+t,n))).each(function(t,n){var e,r,i,o,a="style."+n,u="end."+a;return function(){var c=Xi(this,t),f=c.on,s=null==c.value[a]?o||(o=ho(n)):void 0;f===e&&i===s||(r=(e=f).copy()).on(u,i=s),c.on=r}}(this._id,t)):this.styleTween(t,function(t,n,e){var r,i,o=e+"";return function(){var a=bn(this,t);return a===o?null:a===r?i:i=n(r=a,e)}}(t,r,n),e).on("end.style."+t,null)},styleTween:function(t,n,e){var r="style."+(t+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(null==n)return this.tween(r,null);if("function"!=typeof n)throw new Error;return this.tween(r,function(t,n,e){var r,i;function o(){var o=n.apply(this,arguments);return o!==i&&(r=(i=o)&&function(t,n,e){return function(r){this.style.setProperty(t,n.call(this,r),e)}}(t,o,e)),r}return o._value=n,o}(t,n,null==e?"":e))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var n=t(this);this.textContent=null==n?"":n}}(Ki(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},textTween:function(t){var n="text";if(arguments.length<1)return(n=this.tween(n))&&n._value;if(null==t)return this.tween(n,null);if("function"!=typeof t)throw new Error;return this.tween(n,function(t){var n,e;function r(){var r=t.apply(this,arguments);return r!==e&&(n=(e=r)&&function(t){return function(n){this.textContent=t.call(this,n)}}(r)),n}return r._value=t,r}(t))},remove:function(){return this.on("end.remove",function(t){return function(){var n=this.parentNode;for(var e in this.__transition)if(+e!==t)return;n&&n.removeChild(this)}}(this._id))},tween:function(t,n){var e=this._id;if(t+="",arguments.length<2){for(var r,i=Gi(this.node(),e).tween,o=0,a=i.length;o()=>t;function Jo(t,{sourceEvent:n,target:e,selection:r,mode:i,dispatch:o}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},target:{value:e,enumerable:!0,configurable:!0},selection:{value:r,enumerable:!0,configurable:!0},mode:{value:i,enumerable:!0,configurable:!0},_:{value:o}})}function ta(t){t.preventDefault(),t.stopImmediatePropagation()}var na={name:"drag"},ea={name:"space"},ra={name:"handle"},ia={name:"center"};const{abs:oa,max:aa,min:ua}=Math;function ca(t){return[+t[0],+t[1]]}function fa(t){return[ca(t[0]),ca(t[1])]}var sa={name:"x",handles:["w","e"].map(_a),input:function(t,n){return null==t?null:[[+t[0],n[0][1]],[+t[1],n[1][1]]]},output:function(t){return t&&[t[0][0],t[1][0]]}},la={name:"y",handles:["n","s"].map(_a),input:function(t,n){return null==t?null:[[n[0][0],+t[0]],[n[1][0],+t[1]]]},output:function(t){return t&&[t[0][1],t[1][1]]}},ha={name:"xy",handles:["n","w","e","s","nw","ne","sw","se"].map(_a),input:function(t){return null==t?null:fa(t)},output:function(t){return t}},da={overlay:"crosshair",selection:"move",n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},pa={e:"w",w:"e",nw:"ne",ne:"nw",se:"sw",sw:"se"},ga={n:"s",s:"n",nw:"sw",ne:"se",se:"ne",sw:"nw"},ya={overlay:1,selection:1,n:null,e:1,s:null,w:-1,nw:-1,ne:1,se:1,sw:-1},va={overlay:1,selection:1,n:-1,e:null,s:1,w:null,nw:-1,ne:-1,se:1,sw:1};function _a(t){return{type:t}}function ba(t){return!t.ctrlKey&&!t.button}function ma(){var t=this.ownerSVGElement||this;return t.hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]}function xa(){return navigator.maxTouchPoints||"ontouchstart"in this}function wa(t){for(;!t.__brush;)if(!(t=t.parentNode))return;return t.__brush}function Ma(t){var n,e=ma,r=ba,i=xa,o=!0,a=Dt("start","brush","end"),u=6;function c(n){var e=n.property("__brush",g).selectAll(".overlay").data([_a("overlay")]);e.enter().append("rect").attr("class","overlay").attr("pointer-events","all").attr("cursor",da.overlay).merge(e).each((function(){var t=wa(this).extent;Kn(this).attr("x",t[0][0]).attr("y",t[0][1]).attr("width",t[1][0]-t[0][0]).attr("height",t[1][1]-t[0][1])})),n.selectAll(".selection").data([_a("selection")]).enter().append("rect").attr("class","selection").attr("cursor",da.selection).attr("fill","#777").attr("fill-opacity",.3).attr("stroke","#fff").attr("shape-rendering","crispEdges");var r=n.selectAll(".handle").data(t.handles,(function(t){return t.type}));r.exit().remove(),r.enter().append("rect").attr("class",(function(t){return"handle handle--"+t.type})).attr("cursor",(function(t){return da[t.type]})),n.each(f).attr("fill","none").attr("pointer-events","all").on("mousedown.brush",h).filter(i).on("touchstart.brush",h).on("touchmove.brush",d).on("touchend.brush touchcancel.brush",p).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function f(){var t=Kn(this),n=wa(this).selection;n?(t.selectAll(".selection").style("display",null).attr("x",n[0][0]).attr("y",n[0][1]).attr("width",n[1][0]-n[0][0]).attr("height",n[1][1]-n[0][1]),t.selectAll(".handle").style("display",null).attr("x",(function(t){return"e"===t.type[t.type.length-1]?n[1][0]-u/2:n[0][0]-u/2})).attr("y",(function(t){return"s"===t.type[0]?n[1][1]-u/2:n[0][1]-u/2})).attr("width",(function(t){return"n"===t.type||"s"===t.type?n[1][0]-n[0][0]+u:u})).attr("height",(function(t){return"e"===t.type||"w"===t.type?n[1][1]-n[0][1]+u:u}))):t.selectAll(".selection,.handle").style("display","none").attr("x",null).attr("y",null).attr("width",null).attr("height",null)}function s(t,n,e){var r=t.__brush.emitter;return!r||e&&r.clean?new l(t,n,e):r}function l(t,n,e){this.that=t,this.args=n,this.state=t.__brush,this.active=0,this.clean=e}function h(e){if((!n||e.touches)&&r.apply(this,arguments)){var i,a,u,c,l,h,d,p,g,y,v,_=this,b=e.target.__data__.type,m="selection"===(o&&e.metaKey?b="overlay":b)?na:o&&e.altKey?ia:ra,x=t===la?null:ya[b],w=t===sa?null:va[b],M=wa(_),T=M.extent,A=M.selection,S=T[0][0],E=T[0][1],N=T[1][0],k=T[1][1],C=0,P=0,z=x&&w&&o&&e.shiftKey,$=Array.from(e.touches||[e],(t=>{const n=t.identifier;return(t=ee(t,_)).point0=t.slice(),t.identifier=n,t}));Vi(_);var D=s(_,arguments,!0).beforestart();if("overlay"===b){A&&(g=!0);const n=[$[0],$[1]||$[0]];M.selection=A=[[i=t===la?S:ua(n[0][0],n[1][0]),u=t===sa?E:ua(n[0][1],n[1][1])],[l=t===la?N:aa(n[0][0],n[1][0]),d=t===sa?k:aa(n[0][1],n[1][1])]],$.length>1&&I(e)}else i=A[0][0],u=A[0][1],l=A[1][0],d=A[1][1];a=i,c=u,h=l,p=d;var R=Kn(_).attr("pointer-events","none"),F=R.selectAll(".overlay").attr("cursor",da[b]);if(e.touches)D.moved=U,D.ended=O;else{var q=Kn(e.view).on("mousemove.brush",U,!0).on("mouseup.brush",O,!0);o&&q.on("keydown.brush",(function(t){switch(t.keyCode){case 16:z=x&&w;break;case 18:m===ra&&(x&&(l=h-C*x,i=a+C*x),w&&(d=p-P*w,u=c+P*w),m=ia,I(t));break;case 32:m!==ra&&m!==ia||(x<0?l=h-C:x>0&&(i=a-C),w<0?d=p-P:w>0&&(u=c-P),m=ea,F.attr("cursor",da.selection),I(t));break;default:return}ta(t)}),!0).on("keyup.brush",(function(t){switch(t.keyCode){case 16:z&&(y=v=z=!1,I(t));break;case 18:m===ia&&(x<0?l=h:x>0&&(i=a),w<0?d=p:w>0&&(u=c),m=ra,I(t));break;case 32:m===ea&&(t.altKey?(x&&(l=h-C*x,i=a+C*x),w&&(d=p-P*w,u=c+P*w),m=ia):(x<0?l=h:x>0&&(i=a),w<0?d=p:w>0&&(u=c),m=ra),F.attr("cursor",da[b]),I(t));break;default:return}ta(t)}),!0),ue(e.view)}f.call(_),D.start(e,m.name)}function U(t){for(const n of t.changedTouches||[t])for(const t of $)t.identifier===n.identifier&&(t.cur=ee(n,_));if(z&&!y&&!v&&1===$.length){const t=$[0];oa(t.cur[0]-t[0])>oa(t.cur[1]-t[1])?v=!0:y=!0}for(const t of $)t.cur&&(t[0]=t.cur[0],t[1]=t.cur[1]);g=!0,ta(t),I(t)}function I(t){const n=$[0],e=n.point0;var r;switch(C=n[0]-e[0],P=n[1]-e[1],m){case ea:case na:x&&(C=aa(S-i,ua(N-l,C)),a=i+C,h=l+C),w&&(P=aa(E-u,ua(k-d,P)),c=u+P,p=d+P);break;case ra:$[1]?(x&&(a=aa(S,ua(N,$[0][0])),h=aa(S,ua(N,$[1][0])),x=1),w&&(c=aa(E,ua(k,$[0][1])),p=aa(E,ua(k,$[1][1])),w=1)):(x<0?(C=aa(S-i,ua(N-i,C)),a=i+C,h=l):x>0&&(C=aa(S-l,ua(N-l,C)),a=i,h=l+C),w<0?(P=aa(E-u,ua(k-u,P)),c=u+P,p=d):w>0&&(P=aa(E-d,ua(k-d,P)),c=u,p=d+P));break;case ia:x&&(a=aa(S,ua(N,i-C*x)),h=aa(S,ua(N,l+C*x))),w&&(c=aa(E,ua(k,u-P*w)),p=aa(E,ua(k,d+P*w)))}ht+e))}function $a(t,n){var e=0,r=null,i=null,o=null;function a(a){var u,c=a.length,f=new Array(c),s=za(0,c),l=new Array(c*c),h=new Array(c),d=0;a=Float64Array.from({length:c*c},n?(t,n)=>a[n%c][n/c|0]:(t,n)=>a[n/c|0][n%c]);for(let n=0;nr(f[t],f[n])));for(const e of s){const r=n;if(t){const t=za(1+~c,c).filter((t=>t<0?a[~t*c+e]:a[e*c+t]));i&&t.sort(((t,n)=>i(t<0?-a[~t*c+e]:a[e*c+t],n<0?-a[~n*c+e]:a[e*c+n])));for(const r of t)if(r<0){(l[~r*c+e]||(l[~r*c+e]={source:null,target:null})).target={index:e,startAngle:n,endAngle:n+=a[~r*c+e]*d,value:a[~r*c+e]}}else{(l[e*c+r]||(l[e*c+r]={source:null,target:null})).source={index:e,startAngle:n,endAngle:n+=a[e*c+r]*d,value:a[e*c+r]}}h[e]={index:e,startAngle:r,endAngle:n,value:f[e]}}else{const t=za(0,c).filter((t=>a[e*c+t]||a[t*c+e]));i&&t.sort(((t,n)=>i(a[e*c+t],a[e*c+n])));for(const r of t){let t;if(e=0))throw new Error(`invalid digits: ${t}`);if(n>15)return Ua;const e=10**n;return function(t){this._+=t[0];for(let n=1,r=t.length;nFa)if(Math.abs(s*u-c*f)>Fa&&i){let h=e-o,d=r-a,p=u*u+c*c,g=h*h+d*d,y=Math.sqrt(p),v=Math.sqrt(l),_=i*Math.tan((Da-Math.acos((p+l-g)/(2*y*v)))/2),b=_/v,m=_/y;Math.abs(b-1)>Fa&&this._append`L${t+b*f},${n+b*s}`,this._append`A${i},${i},0,0,${+(s*h>f*d)},${this._x1=t+m*u},${this._y1=n+m*c}`}else this._append`L${this._x1=t},${this._y1=n}`;else;}arc(t,n,e,r,i,o){if(t=+t,n=+n,o=!!o,(e=+e)<0)throw new Error(`negative radius: ${e}`);let a=e*Math.cos(r),u=e*Math.sin(r),c=t+a,f=n+u,s=1^o,l=o?r-i:i-r;null===this._x1?this._append`M${c},${f}`:(Math.abs(this._x1-c)>Fa||Math.abs(this._y1-f)>Fa)&&this._append`L${c},${f}`,e&&(l<0&&(l=l%Ra+Ra),l>qa?this._append`A${e},${e},0,1,${s},${t-a},${n-u}A${e},${e},0,1,${s},${this._x1=c},${this._y1=f}`:l>Fa&&this._append`A${e},${e},0,${+(l>=Da)},${s},${this._x1=t+e*Math.cos(i)},${this._y1=n+e*Math.sin(i)}`)}rect(t,n,e,r){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+n}h${e=+e}v${+r}h${-e}Z`}toString(){return this._}};function Oa(){return new Ia}Oa.prototype=Ia.prototype;var Ba=Array.prototype.slice;function Ya(t){return function(){return t}}function La(t){return t.source}function ja(t){return t.target}function Ha(t){return t.radius}function Xa(t){return t.startAngle}function Ga(t){return t.endAngle}function Va(){return 0}function Wa(){return 10}function Za(t){var n=La,e=ja,r=Ha,i=Ha,o=Xa,a=Ga,u=Va,c=null;function f(){var f,s=n.apply(this,arguments),l=e.apply(this,arguments),h=u.apply(this,arguments)/2,d=Ba.call(arguments),p=+r.apply(this,(d[0]=s,d)),g=o.apply(this,d)-Na,y=a.apply(this,d)-Na,v=+i.apply(this,(d[0]=l,d)),_=o.apply(this,d)-Na,b=a.apply(this,d)-Na;if(c||(c=f=Oa()),h>Pa&&(Ta(y-g)>2*h+Pa?y>g?(g+=h,y-=h):(g-=h,y+=h):g=y=(g+y)/2,Ta(b-_)>2*h+Pa?b>_?(_+=h,b-=h):(_-=h,b+=h):_=b=(_+b)/2),c.moveTo(p*Aa(g),p*Sa(g)),c.arc(0,0,p,g,y),g!==_||y!==b)if(t){var m=v-+t.apply(this,arguments),x=(_+b)/2;c.quadraticCurveTo(0,0,m*Aa(_),m*Sa(_)),c.lineTo(v*Aa(x),v*Sa(x)),c.lineTo(m*Aa(b),m*Sa(b))}else c.quadraticCurveTo(0,0,v*Aa(_),v*Sa(_)),c.arc(0,0,v,_,b);if(c.quadraticCurveTo(0,0,p*Aa(g),p*Sa(g)),c.closePath(),f)return c=null,f+""||null}return t&&(f.headRadius=function(n){return arguments.length?(t="function"==typeof n?n:Ya(+n),f):t}),f.radius=function(t){return arguments.length?(r=i="function"==typeof t?t:Ya(+t),f):r},f.sourceRadius=function(t){return arguments.length?(r="function"==typeof t?t:Ya(+t),f):r},f.targetRadius=function(t){return arguments.length?(i="function"==typeof t?t:Ya(+t),f):i},f.startAngle=function(t){return arguments.length?(o="function"==typeof t?t:Ya(+t),f):o},f.endAngle=function(t){return arguments.length?(a="function"==typeof t?t:Ya(+t),f):a},f.padAngle=function(t){return arguments.length?(u="function"==typeof t?t:Ya(+t),f):u},f.source=function(t){return arguments.length?(n=t,f):n},f.target=function(t){return arguments.length?(e=t,f):e},f.context=function(t){return arguments.length?(c=null==t?null:t,f):c},f}var Ka=Array.prototype.slice;function Qa(t,n){return t-n}var Ja=t=>()=>t;function tu(t,n){for(var e,r=-1,i=n.length;++rr!=d>r&&e<(h-f)*(r-s)/(d-s)+f&&(i=-i)}return i}function eu(t,n,e){var r,i,o,a;return function(t,n,e){return(n[0]-t[0])*(e[1]-t[1])==(e[0]-t[0])*(n[1]-t[1])}(t,n,e)&&(i=t[r=+(t[0]===n[0])],o=e[r],a=n[r],i<=o&&o<=a||a<=o&&o<=i)}function ru(){}var iu=[[],[[[1,1.5],[.5,1]]],[[[1.5,1],[1,1.5]]],[[[1.5,1],[.5,1]]],[[[1,.5],[1.5,1]]],[[[1,1.5],[.5,1]],[[1,.5],[1.5,1]]],[[[1,.5],[1,1.5]]],[[[1,.5],[.5,1]]],[[[.5,1],[1,.5]]],[[[1,1.5],[1,.5]]],[[[.5,1],[1,.5]],[[1.5,1],[1,1.5]]],[[[1.5,1],[1,.5]]],[[[.5,1],[1.5,1]]],[[[1,1.5],[1.5,1]]],[[[.5,1],[1,1.5]]],[]];function ou(){var t=1,n=1,e=Q,r=u;function i(t){var n=e(t);if(Array.isArray(n))n=n.slice().sort(Qa);else{const e=T(t,au);for(n=V(...K(e[0],e[1],n),n);n[n.length-1]>=e[1];)n.pop();for(;n[1]o(t,n)))}function o(e,i){const o=null==i?NaN:+i;if(isNaN(o))throw new Error(`invalid value: ${i}`);var u=[],c=[];return function(e,r,i){var o,u,c,f,s,l,h=new Array,d=new Array;o=u=-1,f=uu(e[0],r),iu[f<<1].forEach(p);for(;++o=r,iu[s<<2].forEach(p);for(;++o0?u.push([t]):c.push(t)})),c.forEach((function(t){for(var n,e=0,r=u.length;e0&&o0&&a=0&&o>=0))throw new Error("invalid size");return t=r,n=o,i},i.thresholds=function(t){return arguments.length?(e="function"==typeof t?t:Array.isArray(t)?Ja(Ka.call(t)):Ja(t),i):e},i.smooth=function(t){return arguments.length?(r=t?u:ru,i):r===u},i}function au(t){return isFinite(t)?t:NaN}function uu(t,n){return null!=t&&+t>=n}function cu(t){return null==t||isNaN(t=+t)?-1/0:t}function fu(t,n,e,r){const i=r-n,o=e-n,a=isFinite(i)||isFinite(o)?i/o:Math.sign(i)/Math.sign(o);return isNaN(a)?t:t+a-.5}function su(t){return t[0]}function lu(t){return t[1]}function hu(){return 1}const du=134217729,pu=33306690738754706e-32;function gu(t,n,e,r,i){let o,a,u,c,f=n[0],s=r[0],l=0,h=0;s>f==s>-f?(o=f,f=n[++l]):(o=s,s=r[++h]);let d=0;if(lf==s>-f?(a=f+o,u=o-(a-f),f=n[++l]):(a=s+o,u=o-(a-s),s=r[++h]),o=a,0!==u&&(i[d++]=u);lf==s>-f?(a=o+f,c=a-o,u=o-(a-c)+(f-c),f=n[++l]):(a=o+s,c=a-o,u=o-(a-c)+(s-c),s=r[++h]),o=a,0!==u&&(i[d++]=u);for(;l0!=u>0)return c;const f=Math.abs(a+u);return Math.abs(c)>=33306690738754716e-32*f?c:-function(t,n,e,r,i,o,a){let u,c,f,s,l,h,d,p,g,y,v,_,b,m,x,w,M,T;const A=t-i,S=e-i,E=n-o,N=r-o;m=A*N,h=du*A,d=h-(h-A),p=A-d,h=du*N,g=h-(h-N),y=N-g,x=p*y-(m-d*g-p*g-d*y),w=E*S,h=du*E,d=h-(h-E),p=E-d,h=du*S,g=h-(h-S),y=S-g,M=p*y-(w-d*g-p*g-d*y),v=x-M,l=x-v,bu[0]=x-(v+l)+(l-M),_=m+v,l=_-m,b=m-(_-l)+(v-l),v=b-w,l=b-v,bu[1]=b-(v+l)+(l-w),T=_+v,l=T-_,bu[2]=_-(T-l)+(v-l),bu[3]=T;let k=function(t,n){let e=n[0];for(let r=1;r=C||-k>=C)return k;if(l=t-A,u=t-(A+l)+(l-i),l=e-S,f=e-(S+l)+(l-i),l=n-E,c=n-(E+l)+(l-o),l=r-N,s=r-(N+l)+(l-o),0===u&&0===c&&0===f&&0===s)return k;if(C=_u*a+pu*Math.abs(k),k+=A*s+N*u-(E*f+S*c),k>=C||-k>=C)return k;m=u*N,h=du*u,d=h-(h-u),p=u-d,h=du*N,g=h-(h-N),y=N-g,x=p*y-(m-d*g-p*g-d*y),w=c*S,h=du*c,d=h-(h-c),p=c-d,h=du*S,g=h-(h-S),y=S-g,M=p*y-(w-d*g-p*g-d*y),v=x-M,l=x-v,Mu[0]=x-(v+l)+(l-M),_=m+v,l=_-m,b=m-(_-l)+(v-l),v=b-w,l=b-v,Mu[1]=b-(v+l)+(l-w),T=_+v,l=T-_,Mu[2]=_-(T-l)+(v-l),Mu[3]=T;const P=gu(4,bu,4,Mu,mu);m=A*s,h=du*A,d=h-(h-A),p=A-d,h=du*s,g=h-(h-s),y=s-g,x=p*y-(m-d*g-p*g-d*y),w=E*f,h=du*E,d=h-(h-E),p=E-d,h=du*f,g=h-(h-f),y=f-g,M=p*y-(w-d*g-p*g-d*y),v=x-M,l=x-v,Mu[0]=x-(v+l)+(l-M),_=m+v,l=_-m,b=m-(_-l)+(v-l),v=b-w,l=b-v,Mu[1]=b-(v+l)+(l-w),T=_+v,l=T-_,Mu[2]=_-(T-l)+(v-l),Mu[3]=T;const z=gu(P,mu,4,Mu,xu);m=u*s,h=du*u,d=h-(h-u),p=u-d,h=du*s,g=h-(h-s),y=s-g,x=p*y-(m-d*g-p*g-d*y),w=c*f,h=du*c,d=h-(h-c),p=c-d,h=du*f,g=h-(h-f),y=f-g,M=p*y-(w-d*g-p*g-d*y),v=x-M,l=x-v,Mu[0]=x-(v+l)+(l-M),_=m+v,l=_-m,b=m-(_-l)+(v-l),v=b-w,l=b-v,Mu[1]=b-(v+l)+(l-w),T=_+v,l=T-_,Mu[2]=_-(T-l)+(v-l),Mu[3]=T;const $=gu(z,xu,4,Mu,wu);return wu[$-1]}(t,n,e,r,i,o,f)}const Au=Math.pow(2,-52),Su=new Uint32Array(512);class Eu{static from(t,n=$u,e=Du){const r=t.length,i=new Float64Array(2*r);for(let o=0;o>1;if(n>0&&"number"!=typeof t[0])throw new Error("Expected coords to contain numbers.");this.coords=t;const e=Math.max(2*n-5,0);this._triangles=new Uint32Array(3*e),this._halfedges=new Int32Array(3*e),this._hashSize=Math.ceil(Math.sqrt(n)),this._hullPrev=new Uint32Array(n),this._hullNext=new Uint32Array(n),this._hullTri=new Uint32Array(n),this._hullHash=new Int32Array(this._hashSize).fill(-1),this._ids=new Uint32Array(n),this._dists=new Float64Array(n),this.update()}update(){const{coords:t,_hullPrev:n,_hullNext:e,_hullTri:r,_hullHash:i}=this,o=t.length>>1;let a=1/0,u=1/0,c=-1/0,f=-1/0;for(let n=0;nc&&(c=e),r>f&&(f=r),this._ids[n]=n}const s=(a+c)/2,l=(u+f)/2;let h,d,p,g=1/0;for(let n=0;n0&&(d=n,g=e)}let _=t[2*d],b=t[2*d+1],m=1/0;for(let n=0;nr&&(n[e++]=i,r=this._dists[i])}return this.hull=n.subarray(0,e),this.triangles=new Uint32Array(0),void(this.halfedges=new Uint32Array(0))}if(Tu(y,v,_,b,x,w)<0){const t=d,n=_,e=b;d=p,_=x,b=w,p=t,x=n,w=e}const M=function(t,n,e,r,i,o){const a=e-t,u=r-n,c=i-t,f=o-n,s=a*a+u*u,l=c*c+f*f,h=.5/(a*f-u*c),d=t+(f*s-u*l)*h,p=n+(a*l-c*s)*h;return{x:d,y:p}}(y,v,_,b,x,w);this._cx=M.x,this._cy=M.y;for(let n=0;n0&&Math.abs(f-o)<=Au&&Math.abs(s-a)<=Au)continue;if(o=f,a=s,c===h||c===d||c===p)continue;let l=0;for(let t=0,n=this._hashKey(f,s);t=0;)if(y=g,y===l){y=-1;break}if(-1===y)continue;let v=this._addTriangle(y,c,e[y],-1,-1,r[y]);r[c]=this._legalize(v+2),r[y]=v,T++;let _=e[y];for(;g=e[_],Tu(f,s,t[2*_],t[2*_+1],t[2*g],t[2*g+1])<0;)v=this._addTriangle(_,c,g,r[c],-1,r[_]),r[c]=this._legalize(v+2),e[_]=_,T--,_=g;if(y===l)for(;g=n[y],Tu(f,s,t[2*g],t[2*g+1],t[2*y],t[2*y+1])<0;)v=this._addTriangle(g,c,y,-1,r[y],r[g]),this._legalize(v+2),r[g]=v,e[y]=y,T--,y=g;this._hullStart=n[c]=y,e[y]=n[_]=c,e[c]=_,i[this._hashKey(f,s)]=c,i[this._hashKey(t[2*y],t[2*y+1])]=y}this.hull=new Uint32Array(T);for(let t=0,n=this._hullStart;t0?3-e:1+e)/4}(t-this._cx,n-this._cy)*this._hashSize)%this._hashSize}_legalize(t){const{_triangles:n,_halfedges:e,coords:r}=this;let i=0,o=0;for(;;){const a=e[t],u=t-t%3;if(o=u+(t+2)%3,-1===a){if(0===i)break;t=Su[--i];continue}const c=a-a%3,f=u+(t+1)%3,s=c+(a+2)%3,l=n[o],h=n[t],d=n[f],p=n[s];if(ku(r[2*l],r[2*l+1],r[2*h],r[2*h+1],r[2*d],r[2*d+1],r[2*p],r[2*p+1])){n[t]=p,n[a]=l;const r=e[s];if(-1===r){let n=this._hullStart;do{if(this._hullTri[n]===s){this._hullTri[n]=t;break}n=this._hullPrev[n]}while(n!==this._hullStart)}this._link(t,r),this._link(a,e[o]),this._link(o,s);const u=c+(a+1)%3;i=e&&n[t[a]]>o;)t[a+1]=t[a--];t[a+1]=r}else{let i=e+1,o=r;zu(t,e+r>>1,i),n[t[e]]>n[t[r]]&&zu(t,e,r),n[t[i]]>n[t[r]]&&zu(t,i,r),n[t[e]]>n[t[i]]&&zu(t,e,i);const a=t[i],u=n[a];for(;;){do{i++}while(n[t[i]]u);if(o=o-e?(Pu(t,n,i,r),Pu(t,n,e,o-1)):(Pu(t,n,e,o-1),Pu(t,n,i,r))}}function zu(t,n,e){const r=t[n];t[n]=t[e],t[e]=r}function $u(t){return t[0]}function Du(t){return t[1]}const Ru=1e-6;class Fu{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(t,n){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+n}`}closePath(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(t,n){this._+=`L${this._x1=+t},${this._y1=+n}`}arc(t,n,e){const r=(t=+t)+(e=+e),i=n=+n;if(e<0)throw new Error("negative radius");null===this._x1?this._+=`M${r},${i}`:(Math.abs(this._x1-r)>Ru||Math.abs(this._y1-i)>Ru)&&(this._+="L"+r+","+i),e&&(this._+=`A${e},${e},0,1,1,${t-e},${n}A${e},${e},0,1,1,${this._x1=r},${this._y1=i}`)}rect(t,n,e,r){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+n}h${+e}v${+r}h${-e}Z`}value(){return this._||null}}class qu{constructor(){this._=[]}moveTo(t,n){this._.push([t,n])}closePath(){this._.push(this._[0].slice())}lineTo(t,n){this._.push([t,n])}value(){return this._.length?this._:null}}class Uu{constructor(t,[n,e,r,i]=[0,0,960,500]){if(!((r=+r)>=(n=+n)&&(i=+i)>=(e=+e)))throw new Error("invalid bounds");this.delaunay=t,this._circumcenters=new Float64Array(2*t.points.length),this.vectors=new Float64Array(2*t.points.length),this.xmax=r,this.xmin=n,this.ymax=i,this.ymin=e,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){const{delaunay:{points:t,hull:n,triangles:e},vectors:r}=this;let i,o;const a=this.circumcenters=this._circumcenters.subarray(0,e.length/3*2);for(let r,u,c=0,f=0,s=e.length;c1;)i-=2;for(let t=2;t0){if(n>=this.ymax)return null;(i=(this.ymax-n)/r)0){if(t>=this.xmax)return null;(i=(this.xmax-t)/e)this.xmax?2:0)|(nthis.ymax?8:0)}_simplify(t){if(t&&t.length>4){for(let n=0;n2&&function(t){const{triangles:n,coords:e}=t;for(let t=0;t1e-10)return!1}return!0}(t)){this.collinear=Int32Array.from({length:n.length/2},((t,n)=>n)).sort(((t,e)=>n[2*t]-n[2*e]||n[2*t+1]-n[2*e+1]));const t=this.collinear[0],e=this.collinear[this.collinear.length-1],r=[n[2*t],n[2*t+1],n[2*e],n[2*e+1]],i=1e-8*Math.hypot(r[3]-r[1],r[2]-r[0]);for(let t=0,e=n.length/2;t0&&(this.triangles=new Int32Array(3).fill(-1),this.halfedges=new Int32Array(3).fill(-1),this.triangles[0]=r[0],o[r[0]]=1,2===r.length&&(o[r[1]]=0,this.triangles[1]=r[1],this.triangles[2]=r[1]))}voronoi(t){return new Uu(this,t)}*neighbors(t){const{inedges:n,hull:e,_hullIndex:r,halfedges:i,triangles:o,collinear:a}=this;if(a){const n=a.indexOf(t);return n>0&&(yield a[n-1]),void(n=0&&i!==e&&i!==r;)e=i;return i}_step(t,n,e){const{inedges:r,hull:i,_hullIndex:o,halfedges:a,triangles:u,points:c}=this;if(-1===r[t]||!c.length)return(t+1)%(c.length>>1);let f=t,s=Ou(n-c[2*t],2)+Ou(e-c[2*t+1],2);const l=r[t];let h=l;do{let r=u[h];const l=Ou(n-c[2*r],2)+Ou(e-c[2*r+1],2);if(l9999?"+"+Qu(n,6):Qu(n,4))+"-"+Qu(t.getUTCMonth()+1,2)+"-"+Qu(t.getUTCDate(),2)+(o?"T"+Qu(e,2)+":"+Qu(r,2)+":"+Qu(i,2)+"."+Qu(o,3)+"Z":i?"T"+Qu(e,2)+":"+Qu(r,2)+":"+Qu(i,2)+"Z":r||e?"T"+Qu(e,2)+":"+Qu(r,2)+"Z":"")}function tc(t){var n=new RegExp('["'+t+"\n\r]"),e=t.charCodeAt(0);function r(t,n){var r,i=[],o=t.length,a=0,u=0,c=o<=0,f=!1;function s(){if(c)return Xu;if(f)return f=!1,Hu;var n,r,i=a;if(t.charCodeAt(i)===Gu){for(;a++=o?c=!0:(r=t.charCodeAt(a++))===Vu?f=!0:r===Wu&&(f=!0,t.charCodeAt(a)===Vu&&++a),t.slice(i+1,n-1).replace(/""/g,'"')}for(;axc(n,e).then((n=>(new DOMParser).parseFromString(n,t)))}var Ec=Sc("application/xml"),Nc=Sc("text/html"),kc=Sc("image/svg+xml");function Cc(t,n,e,r){if(isNaN(n)||isNaN(e))return t;var i,o,a,u,c,f,s,l,h,d=t._root,p={data:r},g=t._x0,y=t._y0,v=t._x1,_=t._y1;if(!d)return t._root=p,t;for(;d.length;)if((f=n>=(o=(g+v)/2))?g=o:v=o,(s=e>=(a=(y+_)/2))?y=a:_=a,i=d,!(d=d[l=s<<1|f]))return i[l]=p,t;if(u=+t._x.call(null,d.data),c=+t._y.call(null,d.data),n===u&&e===c)return p.next=d,i?i[l]=p:t._root=p,t;do{i=i?i[l]=new Array(4):t._root=new Array(4),(f=n>=(o=(g+v)/2))?g=o:v=o,(s=e>=(a=(y+_)/2))?y=a:_=a}while((l=s<<1|f)==(h=(c>=a)<<1|u>=o));return i[h]=d,i[l]=p,t}function Pc(t,n,e,r,i){this.node=t,this.x0=n,this.y0=e,this.x1=r,this.y1=i}function zc(t){return t[0]}function $c(t){return t[1]}function Dc(t,n,e){var r=new Rc(null==n?zc:n,null==e?$c:e,NaN,NaN,NaN,NaN);return null==t?r:r.addAll(t)}function Rc(t,n,e,r,i,o){this._x=t,this._y=n,this._x0=e,this._y0=r,this._x1=i,this._y1=o,this._root=void 0}function Fc(t){for(var n={data:t.data},e=n;t=t.next;)e=e.next={data:t.data};return n}var qc=Dc.prototype=Rc.prototype;function Uc(t){return function(){return t}}function Ic(t){return 1e-6*(t()-.5)}function Oc(t){return t.x+t.vx}function Bc(t){return t.y+t.vy}function Yc(t){return t.index}function Lc(t,n){var e=t.get(n);if(!e)throw new Error("node not found: "+n);return e}qc.copy=function(){var t,n,e=new Rc(this._x,this._y,this._x0,this._y0,this._x1,this._y1),r=this._root;if(!r)return e;if(!r.length)return e._root=Fc(r),e;for(t=[{source:r,target:e._root=new Array(4)}];r=t.pop();)for(var i=0;i<4;++i)(n=r.source[i])&&(n.length?t.push({source:n,target:r.target[i]=new Array(4)}):r.target[i]=Fc(n));return e},qc.add=function(t){const n=+this._x.call(null,t),e=+this._y.call(null,t);return Cc(this.cover(n,e),n,e,t)},qc.addAll=function(t){var n,e,r,i,o=t.length,a=new Array(o),u=new Array(o),c=1/0,f=1/0,s=-1/0,l=-1/0;for(e=0;es&&(s=r),il&&(l=i));if(c>s||f>l)return this;for(this.cover(c,f).cover(s,l),e=0;et||t>=i||r>n||n>=o;)switch(u=(nh||(o=c.y0)>d||(a=c.x1)=v)<<1|t>=y)&&(c=p[p.length-1],p[p.length-1]=p[p.length-1-f],p[p.length-1-f]=c)}else{var _=t-+this._x.call(null,g.data),b=n-+this._y.call(null,g.data),m=_*_+b*b;if(m=(u=(p+y)/2))?p=u:y=u,(s=a>=(c=(g+v)/2))?g=c:v=c,n=d,!(d=d[l=s<<1|f]))return this;if(!d.length)break;(n[l+1&3]||n[l+2&3]||n[l+3&3])&&(e=n,h=l)}for(;d.data!==t;)if(r=d,!(d=d.next))return this;return(i=d.next)&&delete d.next,r?(i?r.next=i:delete r.next,this):n?(i?n[l]=i:delete n[l],(d=n[0]||n[1]||n[2]||n[3])&&d===(n[3]||n[2]||n[1]||n[0])&&!d.length&&(e?e[h]=d:this._root=d),this):(this._root=i,this)},qc.removeAll=function(t){for(var n=0,e=t.length;n1?r[0]+r.slice(2):r,+t.slice(e+1)]}function Kc(t){return(t=Zc(Math.abs(t)))?t[1]:NaN}var Qc,Jc=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function tf(t){if(!(n=Jc.exec(t)))throw new Error("invalid format: "+t);var n;return new nf({fill:n[1],align:n[2],sign:n[3],symbol:n[4],zero:n[5],width:n[6],comma:n[7],precision:n[8]&&n[8].slice(1),trim:n[9],type:n[10]})}function nf(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}function ef(t,n){var e=Zc(t,n);if(!e)return t+"";var r=e[0],i=e[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")}tf.prototype=nf.prototype,nf.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};var rf={"%":(t,n)=>(100*t).toFixed(n),b:t=>Math.round(t).toString(2),c:t=>t+"",d:function(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)},e:(t,n)=>t.toExponential(n),f:(t,n)=>t.toFixed(n),g:(t,n)=>t.toPrecision(n),o:t=>Math.round(t).toString(8),p:(t,n)=>ef(100*t,n),r:ef,s:function(t,n){var e=Zc(t,n);if(!e)return t+"";var r=e[0],i=e[1],o=i-(Qc=3*Math.max(-8,Math.min(8,Math.floor(i/3))))+1,a=r.length;return o===a?r:o>a?r+new Array(o-a+1).join("0"):o>0?r.slice(0,o)+"."+r.slice(o):"0."+new Array(1-o).join("0")+Zc(t,Math.max(0,n+o-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function of(t){return t}var af,uf=Array.prototype.map,cf=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function ff(t){var n,e,r=void 0===t.grouping||void 0===t.thousands?of:(n=uf.call(t.grouping,Number),e=t.thousands+"",function(t,r){for(var i=t.length,o=[],a=0,u=n[0],c=0;i>0&&u>0&&(c+u+1>r&&(u=Math.max(1,r-c)),o.push(t.substring(i-=u,i+u)),!((c+=u+1)>r));)u=n[a=(a+1)%n.length];return o.reverse().join(e)}),i=void 0===t.currency?"":t.currency[0]+"",o=void 0===t.currency?"":t.currency[1]+"",a=void 0===t.decimal?".":t.decimal+"",u=void 0===t.numerals?of:function(t){return function(n){return n.replace(/[0-9]/g,(function(n){return t[+n]}))}}(uf.call(t.numerals,String)),c=void 0===t.percent?"%":t.percent+"",f=void 0===t.minus?"−":t.minus+"",s=void 0===t.nan?"NaN":t.nan+"";function l(t){var n=(t=tf(t)).fill,e=t.align,l=t.sign,h=t.symbol,d=t.zero,p=t.width,g=t.comma,y=t.precision,v=t.trim,_=t.type;"n"===_?(g=!0,_="g"):rf[_]||(void 0===y&&(y=12),v=!0,_="g"),(d||"0"===n&&"="===e)&&(d=!0,n="0",e="=");var b="$"===h?i:"#"===h&&/[boxX]/.test(_)?"0"+_.toLowerCase():"",m="$"===h?o:/[%p]/.test(_)?c:"",x=rf[_],w=/[defgprs%]/.test(_);function M(t){var i,o,c,h=b,M=m;if("c"===_)M=x(t)+M,t="";else{var T=(t=+t)<0||1/t<0;if(t=isNaN(t)?s:x(Math.abs(t),y),v&&(t=function(t){t:for(var n,e=t.length,r=1,i=-1;r0&&(i=0)}return i>0?t.slice(0,i)+t.slice(n+1):t}(t)),T&&0==+t&&"+"!==l&&(T=!1),h=(T?"("===l?l:f:"-"===l||"("===l?"":l)+h,M=("s"===_?cf[8+Qc/3]:"")+M+(T&&"("===l?")":""),w)for(i=-1,o=t.length;++i(c=t.charCodeAt(i))||c>57){M=(46===c?a+t.slice(i+1):t.slice(i))+M,t=t.slice(0,i);break}}g&&!d&&(t=r(t,1/0));var A=h.length+t.length+M.length,S=A>1)+h+t+M+S.slice(A);break;default:t=S+h+t+M}return u(t)}return y=void 0===y?6:/[gprs]/.test(_)?Math.max(1,Math.min(21,y)):Math.max(0,Math.min(20,y)),M.toString=function(){return t+""},M}return{format:l,formatPrefix:function(t,n){var e=l(((t=tf(t)).type="f",t)),r=3*Math.max(-8,Math.min(8,Math.floor(Kc(n)/3))),i=Math.pow(10,-r),o=cf[8+r/3];return function(t){return e(i*t)+o}}}}function sf(n){return af=ff(n),t.format=af.format,t.formatPrefix=af.formatPrefix,af}function lf(t){return Math.max(0,-Kc(Math.abs(t)))}function hf(t,n){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(Kc(n)/3)))-Kc(Math.abs(t)))}function df(t,n){return t=Math.abs(t),n=Math.abs(n)-t,Math.max(0,Kc(n)-Kc(t))+1}t.format=void 0,t.formatPrefix=void 0,sf({thousands:",",grouping:[3],currency:["$",""]});var pf=1e-6,gf=1e-12,yf=Math.PI,vf=yf/2,_f=yf/4,bf=2*yf,mf=180/yf,xf=yf/180,wf=Math.abs,Mf=Math.atan,Tf=Math.atan2,Af=Math.cos,Sf=Math.ceil,Ef=Math.exp,Nf=Math.hypot,kf=Math.log,Cf=Math.pow,Pf=Math.sin,zf=Math.sign||function(t){return t>0?1:t<0?-1:0},$f=Math.sqrt,Df=Math.tan;function Rf(t){return t>1?0:t<-1?yf:Math.acos(t)}function Ff(t){return t>1?vf:t<-1?-vf:Math.asin(t)}function qf(t){return(t=Pf(t/2))*t}function Uf(){}function If(t,n){t&&Bf.hasOwnProperty(t.type)&&Bf[t.type](t,n)}var Of={Feature:function(t,n){If(t.geometry,n)},FeatureCollection:function(t,n){for(var e=t.features,r=-1,i=e.length;++r=0?1:-1,i=r*e,o=Af(n=(n*=xf)/2+_f),a=Pf(n),u=Wf*a,c=Vf*o+u*Af(i),f=u*r*Pf(i);us.add(Tf(f,c)),Gf=t,Vf=o,Wf=a}function ps(t){return[Tf(t[1],t[0]),Ff(t[2])]}function gs(t){var n=t[0],e=t[1],r=Af(e);return[r*Af(n),r*Pf(n),Pf(e)]}function ys(t,n){return t[0]*n[0]+t[1]*n[1]+t[2]*n[2]}function vs(t,n){return[t[1]*n[2]-t[2]*n[1],t[2]*n[0]-t[0]*n[2],t[0]*n[1]-t[1]*n[0]]}function _s(t,n){t[0]+=n[0],t[1]+=n[1],t[2]+=n[2]}function bs(t,n){return[t[0]*n,t[1]*n,t[2]*n]}function ms(t){var n=$f(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]/=n,t[1]/=n,t[2]/=n}var xs,ws,Ms,Ts,As,Ss,Es,Ns,ks,Cs,Ps,zs,$s,Ds,Rs,Fs,qs={point:Us,lineStart:Os,lineEnd:Bs,polygonStart:function(){qs.point=Ys,qs.lineStart=Ls,qs.lineEnd=js,is=new A,fs.polygonStart()},polygonEnd:function(){fs.polygonEnd(),qs.point=Us,qs.lineStart=Os,qs.lineEnd=Bs,us<0?(Zf=-(Qf=180),Kf=-(Jf=90)):is>pf?Jf=90:is<-pf&&(Kf=-90),as[0]=Zf,as[1]=Qf},sphere:function(){Zf=-(Qf=180),Kf=-(Jf=90)}};function Us(t,n){os.push(as=[Zf=t,Qf=t]),nJf&&(Jf=n)}function Is(t,n){var e=gs([t*xf,n*xf]);if(rs){var r=vs(rs,e),i=vs([r[1],-r[0],0],r);ms(i),i=ps(i);var o,a=t-ts,u=a>0?1:-1,c=i[0]*mf*u,f=wf(a)>180;f^(u*tsJf&&(Jf=o):f^(u*ts<(c=(c+360)%360-180)&&cJf&&(Jf=n)),f?tHs(Zf,Qf)&&(Qf=t):Hs(t,Qf)>Hs(Zf,Qf)&&(Zf=t):Qf>=Zf?(tQf&&(Qf=t)):t>ts?Hs(Zf,t)>Hs(Zf,Qf)&&(Qf=t):Hs(t,Qf)>Hs(Zf,Qf)&&(Zf=t)}else os.push(as=[Zf=t,Qf=t]);nJf&&(Jf=n),rs=e,ts=t}function Os(){qs.point=Is}function Bs(){as[0]=Zf,as[1]=Qf,qs.point=Us,rs=null}function Ys(t,n){if(rs){var e=t-ts;is.add(wf(e)>180?e+(e>0?360:-360):e)}else ns=t,es=n;fs.point(t,n),Is(t,n)}function Ls(){fs.lineStart()}function js(){Ys(ns,es),fs.lineEnd(),wf(is)>pf&&(Zf=-(Qf=180)),as[0]=Zf,as[1]=Qf,rs=null}function Hs(t,n){return(n-=t)<0?n+360:n}function Xs(t,n){return t[0]-n[0]}function Gs(t,n){return t[0]<=t[1]?t[0]<=n&&n<=t[1]:nyf&&(t-=Math.round(t/bf)*bf),[t,n]}function cl(t,n,e){return(t%=bf)?n||e?al(sl(t),ll(n,e)):sl(t):n||e?ll(n,e):ul}function fl(t){return function(n,e){return wf(n+=t)>yf&&(n-=Math.round(n/bf)*bf),[n,e]}}function sl(t){var n=fl(t);return n.invert=fl(-t),n}function ll(t,n){var e=Af(t),r=Pf(t),i=Af(n),o=Pf(n);function a(t,n){var a=Af(n),u=Af(t)*a,c=Pf(t)*a,f=Pf(n),s=f*e+u*r;return[Tf(c*i-s*o,u*e-f*r),Ff(s*i+c*o)]}return a.invert=function(t,n){var a=Af(n),u=Af(t)*a,c=Pf(t)*a,f=Pf(n),s=f*i-c*o;return[Tf(c*i+f*o,u*e+s*r),Ff(s*e-u*r)]},a}function hl(t){function n(n){return(n=t(n[0]*xf,n[1]*xf))[0]*=mf,n[1]*=mf,n}return t=cl(t[0]*xf,t[1]*xf,t.length>2?t[2]*xf:0),n.invert=function(n){return(n=t.invert(n[0]*xf,n[1]*xf))[0]*=mf,n[1]*=mf,n},n}function dl(t,n,e,r,i,o){if(e){var a=Af(n),u=Pf(n),c=r*e;null==i?(i=n+r*bf,o=n-c/2):(i=pl(a,i),o=pl(a,o),(r>0?io)&&(i+=r*bf));for(var f,s=i;r>0?s>o:s1&&n.push(n.pop().concat(n.shift()))},result:function(){var e=n;return n=[],t=null,e}}}function yl(t,n){return wf(t[0]-n[0])=0;--o)i.point((s=f[o])[0],s[1]);else r(h.x,h.p.x,-1,i);h=h.p}f=(h=h.o).z,d=!d}while(!h.v);i.lineEnd()}}}function bl(t){if(n=t.length){for(var n,e,r=0,i=t[0];++r=0?1:-1,E=S*T,N=E>yf,k=y*w;if(c.add(Tf(k*S*Pf(E),v*M+k*Af(E))),a+=N?T+S*bf:T,N^p>=e^m>=e){var C=vs(gs(d),gs(b));ms(C);var P=vs(o,C);ms(P);var z=(N^T>=0?-1:1)*Ff(P[2]);(r>z||r===z&&(C[0]||C[1]))&&(u+=N^T>=0?1:-1)}}return(a<-pf||a0){for(l||(i.polygonStart(),l=!0),i.lineStart(),t=0;t1&&2&c&&h.push(h.pop().concat(h.shift())),a.push(h.filter(Ml))}return h}}function Ml(t){return t.length>1}function Tl(t,n){return((t=t.x)[0]<0?t[1]-vf-pf:vf-t[1])-((n=n.x)[0]<0?n[1]-vf-pf:vf-n[1])}ul.invert=ul;var Al=wl((function(){return!0}),(function(t){var n,e=NaN,r=NaN,i=NaN;return{lineStart:function(){t.lineStart(),n=1},point:function(o,a){var u=o>0?yf:-yf,c=wf(o-e);wf(c-yf)0?vf:-vf),t.point(i,r),t.lineEnd(),t.lineStart(),t.point(u,r),t.point(o,r),n=0):i!==u&&c>=yf&&(wf(e-i)pf?Mf((Pf(n)*(o=Af(r))*Pf(e)-Pf(r)*(i=Af(n))*Pf(t))/(i*o*a)):(n+r)/2}(e,r,o,a),t.point(i,r),t.lineEnd(),t.lineStart(),t.point(u,r),n=0),t.point(e=o,r=a),i=u},lineEnd:function(){t.lineEnd(),e=r=NaN},clean:function(){return 2-n}}}),(function(t,n,e,r){var i;if(null==t)i=e*vf,r.point(-yf,i),r.point(0,i),r.point(yf,i),r.point(yf,0),r.point(yf,-i),r.point(0,-i),r.point(-yf,-i),r.point(-yf,0),r.point(-yf,i);else if(wf(t[0]-n[0])>pf){var o=t[0]0,i=wf(n)>pf;function o(t,e){return Af(t)*Af(e)>n}function a(t,e,r){var i=[1,0,0],o=vs(gs(t),gs(e)),a=ys(o,o),u=o[0],c=a-u*u;if(!c)return!r&&t;var f=n*a/c,s=-n*u/c,l=vs(i,o),h=bs(i,f);_s(h,bs(o,s));var d=l,p=ys(h,d),g=ys(d,d),y=p*p-g*(ys(h,h)-1);if(!(y<0)){var v=$f(y),_=bs(d,(-p-v)/g);if(_s(_,h),_=ps(_),!r)return _;var b,m=t[0],x=e[0],w=t[1],M=e[1];x0^_[1]<(wf(_[0]-m)yf^(m<=_[0]&&_[0]<=x)){var S=bs(d,(-p+v)/g);return _s(S,h),[_,ps(S)]}}}function u(n,e){var i=r?t:yf-t,o=0;return n<-i?o|=1:n>i&&(o|=2),e<-i?o|=4:e>i&&(o|=8),o}return wl(o,(function(t){var n,e,c,f,s;return{lineStart:function(){f=c=!1,s=1},point:function(l,h){var d,p=[l,h],g=o(l,h),y=r?g?0:u(l,h):g?u(l+(l<0?yf:-yf),h):0;if(!n&&(f=c=g)&&t.lineStart(),g!==c&&(!(d=a(n,p))||yl(n,d)||yl(p,d))&&(p[2]=1),g!==c)s=0,g?(t.lineStart(),d=a(p,n),t.point(d[0],d[1])):(d=a(n,p),t.point(d[0],d[1],2),t.lineEnd()),n=d;else if(i&&n&&r^g){var v;y&e||!(v=a(p,n,!0))||(s=0,r?(t.lineStart(),t.point(v[0][0],v[0][1]),t.point(v[1][0],v[1][1]),t.lineEnd()):(t.point(v[1][0],v[1][1]),t.lineEnd(),t.lineStart(),t.point(v[0][0],v[0][1],3)))}!g||n&&yl(n,p)||t.point(p[0],p[1]),n=p,c=g,e=y},lineEnd:function(){c&&t.lineEnd(),n=null},clean:function(){return s|(f&&c)<<1}}}),(function(n,r,i,o){dl(o,t,e,i,n,r)}),r?[0,-t]:[-yf,t-yf])}var El,Nl,kl,Cl,Pl=1e9,zl=-Pl;function $l(t,n,e,r){function i(i,o){return t<=i&&i<=e&&n<=o&&o<=r}function o(i,o,u,f){var s=0,l=0;if(null==i||(s=a(i,u))!==(l=a(o,u))||c(i,o)<0^u>0)do{f.point(0===s||3===s?t:e,s>1?r:n)}while((s=(s+u+4)%4)!==l);else f.point(o[0],o[1])}function a(r,i){return wf(r[0]-t)0?0:3:wf(r[0]-e)0?2:1:wf(r[1]-n)0?1:0:i>0?3:2}function u(t,n){return c(t.x,n.x)}function c(t,n){var e=a(t,1),r=a(n,1);return e!==r?e-r:0===e?n[1]-t[1]:1===e?t[0]-n[0]:2===e?t[1]-n[1]:n[0]-t[0]}return function(a){var c,f,s,l,h,d,p,g,y,v,_,b=a,m=gl(),x={point:w,lineStart:function(){x.point=M,f&&f.push(s=[]);v=!0,y=!1,p=g=NaN},lineEnd:function(){c&&(M(l,h),d&&y&&m.rejoin(),c.push(m.result()));x.point=w,y&&b.lineEnd()},polygonStart:function(){b=m,c=[],f=[],_=!0},polygonEnd:function(){var n=function(){for(var n=0,e=0,i=f.length;er&&(h-o)*(r-a)>(d-a)*(t-o)&&++n:d<=r&&(h-o)*(r-a)<(d-a)*(t-o)&&--n;return n}(),e=_&&n,i=(c=st(c)).length;(e||i)&&(a.polygonStart(),e&&(a.lineStart(),o(null,null,1,a),a.lineEnd()),i&&_l(c,u,n,o,a),a.polygonEnd());b=a,c=f=s=null}};function w(t,n){i(t,n)&&b.point(t,n)}function M(o,a){var u=i(o,a);if(f&&s.push([o,a]),v)l=o,h=a,d=u,v=!1,u&&(b.lineStart(),b.point(o,a));else if(u&&y)b.point(o,a);else{var c=[p=Math.max(zl,Math.min(Pl,p)),g=Math.max(zl,Math.min(Pl,g))],m=[o=Math.max(zl,Math.min(Pl,o)),a=Math.max(zl,Math.min(Pl,a))];!function(t,n,e,r,i,o){var a,u=t[0],c=t[1],f=0,s=1,l=n[0]-u,h=n[1]-c;if(a=e-u,l||!(a>0)){if(a/=l,l<0){if(a0){if(a>s)return;a>f&&(f=a)}if(a=i-u,l||!(a<0)){if(a/=l,l<0){if(a>s)return;a>f&&(f=a)}else if(l>0){if(a0)){if(a/=h,h<0){if(a0){if(a>s)return;a>f&&(f=a)}if(a=o-c,h||!(a<0)){if(a/=h,h<0){if(a>s)return;a>f&&(f=a)}else if(h>0){if(a0&&(t[0]=u+f*l,t[1]=c+f*h),s<1&&(n[0]=u+s*l,n[1]=c+s*h),!0}}}}}(c,m,t,n,e,r)?u&&(b.lineStart(),b.point(o,a),_=!1):(y||(b.lineStart(),b.point(c[0],c[1])),b.point(m[0],m[1]),u||b.lineEnd(),_=!1)}p=o,g=a,y=u}return x}}var Dl={sphere:Uf,point:Uf,lineStart:function(){Dl.point=Fl,Dl.lineEnd=Rl},lineEnd:Uf,polygonStart:Uf,polygonEnd:Uf};function Rl(){Dl.point=Dl.lineEnd=Uf}function Fl(t,n){Nl=t*=xf,kl=Pf(n*=xf),Cl=Af(n),Dl.point=ql}function ql(t,n){t*=xf;var e=Pf(n*=xf),r=Af(n),i=wf(t-Nl),o=Af(i),a=r*Pf(i),u=Cl*e-kl*r*o,c=kl*e+Cl*r*o;El.add(Tf($f(a*a+u*u),c)),Nl=t,kl=e,Cl=r}function Ul(t){return El=new A,jf(t,Dl),+El}var Il=[null,null],Ol={type:"LineString",coordinates:Il};function Bl(t,n){return Il[0]=t,Il[1]=n,Ul(Ol)}var Yl={Feature:function(t,n){return jl(t.geometry,n)},FeatureCollection:function(t,n){for(var e=t.features,r=-1,i=e.length;++r0&&(i=Bl(t[o],t[o-1]))>0&&e<=i&&r<=i&&(e+r-i)*(1-Math.pow((e-r)/i,2))pf})).map(c)).concat(ht(Sf(o/d)*d,i,d).filter((function(t){return wf(t%g)>pf})).map(f))}return v.lines=function(){return _().map((function(t){return{type:"LineString",coordinates:t}}))},v.outline=function(){return{type:"Polygon",coordinates:[s(r).concat(l(a).slice(1),s(e).reverse().slice(1),l(u).reverse().slice(1))]}},v.extent=function(t){return arguments.length?v.extentMajor(t).extentMinor(t):v.extentMinor()},v.extentMajor=function(t){return arguments.length?(r=+t[0][0],e=+t[1][0],u=+t[0][1],a=+t[1][1],r>e&&(t=r,r=e,e=t),u>a&&(t=u,u=a,a=t),v.precision(y)):[[r,u],[e,a]]},v.extentMinor=function(e){return arguments.length?(n=+e[0][0],t=+e[1][0],o=+e[0][1],i=+e[1][1],n>t&&(e=n,n=t,t=e),o>i&&(e=o,o=i,i=e),v.precision(y)):[[n,o],[t,i]]},v.step=function(t){return arguments.length?v.stepMajor(t).stepMinor(t):v.stepMinor()},v.stepMajor=function(t){return arguments.length?(p=+t[0],g=+t[1],v):[p,g]},v.stepMinor=function(t){return arguments.length?(h=+t[0],d=+t[1],v):[h,d]},v.precision=function(h){return arguments.length?(y=+h,c=Zl(o,i,90),f=Kl(n,t,y),s=Zl(u,a,90),l=Kl(r,e,y),v):y},v.extentMajor([[-180,-90+pf],[180,90-pf]]).extentMinor([[-180,-80-pf],[180,80+pf]])}var Jl,th,nh,eh,rh=t=>t,ih=new A,oh=new A,ah={point:Uf,lineStart:Uf,lineEnd:Uf,polygonStart:function(){ah.lineStart=uh,ah.lineEnd=sh},polygonEnd:function(){ah.lineStart=ah.lineEnd=ah.point=Uf,ih.add(wf(oh)),oh=new A},result:function(){var t=ih/2;return ih=new A,t}};function uh(){ah.point=ch}function ch(t,n){ah.point=fh,Jl=nh=t,th=eh=n}function fh(t,n){oh.add(eh*t-nh*n),nh=t,eh=n}function sh(){fh(Jl,th)}var lh=ah,hh=1/0,dh=hh,ph=-hh,gh=ph,yh={point:function(t,n){tph&&(ph=t);ngh&&(gh=n)},lineStart:Uf,lineEnd:Uf,polygonStart:Uf,polygonEnd:Uf,result:function(){var t=[[hh,dh],[ph,gh]];return ph=gh=-(dh=hh=1/0),t}};var vh,_h,bh,mh,xh=yh,wh=0,Mh=0,Th=0,Ah=0,Sh=0,Eh=0,Nh=0,kh=0,Ch=0,Ph={point:zh,lineStart:$h,lineEnd:Fh,polygonStart:function(){Ph.lineStart=qh,Ph.lineEnd=Uh},polygonEnd:function(){Ph.point=zh,Ph.lineStart=$h,Ph.lineEnd=Fh},result:function(){var t=Ch?[Nh/Ch,kh/Ch]:Eh?[Ah/Eh,Sh/Eh]:Th?[wh/Th,Mh/Th]:[NaN,NaN];return wh=Mh=Th=Ah=Sh=Eh=Nh=kh=Ch=0,t}};function zh(t,n){wh+=t,Mh+=n,++Th}function $h(){Ph.point=Dh}function Dh(t,n){Ph.point=Rh,zh(bh=t,mh=n)}function Rh(t,n){var e=t-bh,r=n-mh,i=$f(e*e+r*r);Ah+=i*(bh+t)/2,Sh+=i*(mh+n)/2,Eh+=i,zh(bh=t,mh=n)}function Fh(){Ph.point=zh}function qh(){Ph.point=Ih}function Uh(){Oh(vh,_h)}function Ih(t,n){Ph.point=Oh,zh(vh=bh=t,_h=mh=n)}function Oh(t,n){var e=t-bh,r=n-mh,i=$f(e*e+r*r);Ah+=i*(bh+t)/2,Sh+=i*(mh+n)/2,Eh+=i,Nh+=(i=mh*t-bh*n)*(bh+t),kh+=i*(mh+n),Ch+=3*i,zh(bh=t,mh=n)}var Bh=Ph;function Yh(t){this._context=t}Yh.prototype={_radius:4.5,pointRadius:function(t){return this._radius=t,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){0===this._line&&this._context.closePath(),this._point=NaN},point:function(t,n){switch(this._point){case 0:this._context.moveTo(t,n),this._point=1;break;case 1:this._context.lineTo(t,n);break;default:this._context.moveTo(t+this._radius,n),this._context.arc(t,n,this._radius,0,bf)}},result:Uf};var Lh,jh,Hh,Xh,Gh,Vh=new A,Wh={point:Uf,lineStart:function(){Wh.point=Zh},lineEnd:function(){Lh&&Kh(jh,Hh),Wh.point=Uf},polygonStart:function(){Lh=!0},polygonEnd:function(){Lh=null},result:function(){var t=+Vh;return Vh=new A,t}};function Zh(t,n){Wh.point=Kh,jh=Xh=t,Hh=Gh=n}function Kh(t,n){Xh-=t,Gh-=n,Vh.add($f(Xh*Xh+Gh*Gh)),Xh=t,Gh=n}var Qh=Wh;let Jh,td,nd,ed;class rd{constructor(t){this._append=null==t?id:function(t){const n=Math.floor(t);if(!(n>=0))throw new RangeError(`invalid digits: ${t}`);if(n>15)return id;if(n!==Jh){const t=10**n;Jh=n,td=function(n){let e=1;this._+=n[0];for(const r=n.length;e4*n&&g--){var m=a+h,x=u+d,w=c+p,M=$f(m*m+x*x+w*w),T=Ff(w/=M),A=wf(wf(w)-1)n||wf((v*k+_*C)/b-.5)>.3||a*h+u*d+c*p2?t[2]%360*xf:0,k()):[y*mf,v*mf,_*mf]},E.angle=function(t){return arguments.length?(b=t%360*xf,k()):b*mf},E.reflectX=function(t){return arguments.length?(m=t?-1:1,k()):m<0},E.reflectY=function(t){return arguments.length?(x=t?-1:1,k()):x<0},E.precision=function(t){return arguments.length?(a=pd(u,S=t*t),C()):$f(S)},E.fitExtent=function(t,n){return cd(E,t,n)},E.fitSize=function(t,n){return fd(E,t,n)},E.fitWidth=function(t,n){return sd(E,t,n)},E.fitHeight=function(t,n){return ld(E,t,n)},function(){return n=t.apply(this,arguments),E.invert=n.invert&&N,k()}}function bd(t){var n=0,e=yf/3,r=_d(t),i=r(n,e);return i.parallels=function(t){return arguments.length?r(n=t[0]*xf,e=t[1]*xf):[n*mf,e*mf]},i}function md(t,n){var e=Pf(t),r=(e+Pf(n))/2;if(wf(r)0?n<-vf+pf&&(n=-vf+pf):n>vf-pf&&(n=vf-pf);var e=i/Cf(kd(n),r);return[e*Pf(r*t),i-e*Af(r*t)]}return o.invert=function(t,n){var e=i-n,o=zf(r)*$f(t*t+e*e),a=Tf(t,wf(e))*zf(e);return e*r<0&&(a-=yf*zf(t)*zf(e)),[a/r,2*Mf(Cf(i/o,1/r))-vf]},o}function Pd(t,n){return[t,n]}function zd(t,n){var e=Af(t),r=t===n?Pf(t):(e-Af(n))/(n-t),i=e/r+t;if(wf(r)=0;)n+=e[r].value;else n=1;t.value=n}function Vd(t,n){t instanceof Map?(t=[void 0,t],void 0===n&&(n=Zd)):void 0===n&&(n=Wd);for(var e,r,i,o,a,u=new Jd(t),c=[u];e=c.pop();)if((i=n(e.data))&&(a=(i=Array.from(i)).length))for(e.children=i,o=a-1;o>=0;--o)c.push(r=i[o]=new Jd(i[o])),r.parent=e,r.depth=e.depth+1;return u.eachBefore(Qd)}function Wd(t){return t.children}function Zd(t){return Array.isArray(t)?t[1]:null}function Kd(t){void 0!==t.data.value&&(t.value=t.data.value),t.data=t.data.data}function Qd(t){var n=0;do{t.height=n}while((t=t.parent)&&t.height<++n)}function Jd(t){this.data=t,this.depth=this.height=0,this.parent=null}function tp(t){return null==t?null:np(t)}function np(t){if("function"!=typeof t)throw new Error;return t}function ep(){return 0}function rp(t){return function(){return t}}Ud.invert=function(t,n){for(var e,r=n,i=r*r,o=i*i*i,a=0;a<12&&(o=(i=(r-=e=(r*($d+Dd*i+o*(Rd+Fd*i))-n)/($d+3*Dd*i+o*(7*Rd+9*Fd*i)))*r)*i*i,!(wf(e)pf&&--i>0);return[t/(.8707+(o=r*r)*(o*(o*o*o*(.003971-.001529*o)-.013791)-.131979)),r]},Bd.invert=Td(Ff),Yd.invert=Td((function(t){return 2*Mf(t)})),Ld.invert=function(t,n){return[-n,2*Mf(Ef(t))-vf]},Jd.prototype=Vd.prototype={constructor:Jd,count:function(){return this.eachAfter(Gd)},each:function(t,n){let e=-1;for(const r of this)t.call(n,r,++e,this);return this},eachAfter:function(t,n){for(var e,r,i,o=this,a=[o],u=[],c=-1;o=a.pop();)if(u.push(o),e=o.children)for(r=0,i=e.length;r=0;--r)o.push(e[r]);return this},find:function(t,n){let e=-1;for(const r of this)if(t.call(n,r,++e,this))return r},sum:function(t){return this.eachAfter((function(n){for(var e=+t(n.data)||0,r=n.children,i=r&&r.length;--i>=0;)e+=r[i].value;n.value=e}))},sort:function(t){return this.eachBefore((function(n){n.children&&n.children.sort(t)}))},path:function(t){for(var n=this,e=function(t,n){if(t===n)return t;var e=t.ancestors(),r=n.ancestors(),i=null;t=e.pop(),n=r.pop();for(;t===n;)i=t,t=e.pop(),n=r.pop();return i}(n,t),r=[n];n!==e;)n=n.parent,r.push(n);for(var i=r.length;t!==e;)r.splice(i,0,t),t=t.parent;return r},ancestors:function(){for(var t=this,n=[t];t=t.parent;)n.push(t);return n},descendants:function(){return Array.from(this)},leaves:function(){var t=[];return this.eachBefore((function(n){n.children||t.push(n)})),t},links:function(){var t=this,n=[];return t.each((function(e){e!==t&&n.push({source:e.parent,target:e})})),n},copy:function(){return Vd(this).eachBefore(Kd)},[Symbol.iterator]:function*(){var t,n,e,r,i=this,o=[i];do{for(t=o.reverse(),o=[];i=t.pop();)if(yield i,n=i.children)for(e=0,r=n.length;e(t=(ip*t+op)%ap)/ap}function cp(t,n){for(var e,r,i=0,o=(t=function(t,n){let e,r,i=t.length;for(;i;)r=n()*i--|0,e=t[i],t[i]=t[r],t[r]=e;return t}(Array.from(t),n)).length,a=[];i0&&e*e>r*r+i*i}function hp(t,n){for(var e=0;e1e-6?(E+Math.sqrt(E*E-4*S*N))/(2*S):N/E);return{x:r+w+M*k,y:i+T+A*k,r:k}}function yp(t,n,e){var r,i,o,a,u=t.x-n.x,c=t.y-n.y,f=u*u+c*c;f?(i=n.r+e.r,i*=i,a=t.r+e.r,i>(a*=a)?(r=(f+a-i)/(2*f),o=Math.sqrt(Math.max(0,a/f-r*r)),e.x=t.x-r*u-o*c,e.y=t.y-r*c+o*u):(r=(f+i-a)/(2*f),o=Math.sqrt(Math.max(0,i/f-r*r)),e.x=n.x+r*u-o*c,e.y=n.y+r*c+o*u)):(e.x=n.x+e.r,e.y=n.y)}function vp(t,n){var e=t.r+n.r-1e-6,r=n.x-t.x,i=n.y-t.y;return e>0&&e*e>r*r+i*i}function _p(t){var n=t._,e=t.next._,r=n.r+e.r,i=(n.x*e.r+e.x*n.r)/r,o=(n.y*e.r+e.y*n.r)/r;return i*i+o*o}function bp(t){this._=t,this.next=null,this.previous=null}function mp(t,n){if(!(o=(t=function(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}(t)).length))return 0;var e,r,i,o,a,u,c,f,s,l,h;if((e=t[0]).x=0,e.y=0,!(o>1))return e.r;if(r=t[1],e.x=-r.r,r.x=e.r,r.y=0,!(o>2))return e.r+r.r;yp(r,e,i=t[2]),e=new bp(e),r=new bp(r),i=new bp(i),e.next=i.previous=r,r.next=e.previous=i,i.next=r.previous=e;t:for(c=3;c1&&!$p(t,n););return t.slice(0,n)}function $p(t,n){if("/"===t[n]){let e=0;for(;n>0&&"\\"===t[--n];)++e;if(0==(1&e))return!0}return!1}function Dp(t,n){return t.parent===n.parent?1:2}function Rp(t){var n=t.children;return n?n[0]:t.t}function Fp(t){var n=t.children;return n?n[n.length-1]:t.t}function qp(t,n,e){var r=e/(n.i-t.i);n.c-=r,n.s+=e,t.c+=r,n.z+=e,n.m+=e}function Up(t,n,e){return t.a.parent===n.parent?t.a:e}function Ip(t,n){this._=t,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=n}function Op(t,n,e,r,i){for(var o,a=t.children,u=-1,c=a.length,f=t.value&&(i-e)/t.value;++uh&&(h=u),y=s*s*g,(d=Math.max(h/y,y/l))>p){s-=u;break}p=d}v.push(a={value:s,dice:c1?n:1)},e}(Bp);var jp=function t(n){function e(t,e,r,i,o){if((a=t._squarify)&&a.ratio===n)for(var a,u,c,f,s,l=-1,h=a.length,d=t.value;++l1?n:1)},e}(Bp);function Hp(t,n,e){return(n[0]-t[0])*(e[1]-t[1])-(n[1]-t[1])*(e[0]-t[0])}function Xp(t,n){return t[0]-n[0]||t[1]-n[1]}function Gp(t){const n=t.length,e=[0,1];let r,i=2;for(r=2;r1&&Hp(t[e[i-2]],t[e[i-1]],t[r])<=0;)--i;e[i++]=r}return e.slice(0,i)}var Vp=Math.random,Wp=function t(n){function e(t,e){return t=null==t?0:+t,e=null==e?1:+e,1===arguments.length?(e=t,t=0):e-=t,function(){return n()*e+t}}return e.source=t,e}(Vp),Zp=function t(n){function e(t,e){return arguments.length<2&&(e=t,t=0),t=Math.floor(t),e=Math.floor(e)-t,function(){return Math.floor(n()*e+t)}}return e.source=t,e}(Vp),Kp=function t(n){function e(t,e){var r,i;return t=null==t?0:+t,e=null==e?1:+e,function(){var o;if(null!=r)o=r,r=null;else do{r=2*n()-1,o=2*n()-1,i=r*r+o*o}while(!i||i>1);return t+e*o*Math.sqrt(-2*Math.log(i)/i)}}return e.source=t,e}(Vp),Qp=function t(n){var e=Kp.source(n);function r(){var t=e.apply(this,arguments);return function(){return Math.exp(t())}}return r.source=t,r}(Vp),Jp=function t(n){function e(t){return(t=+t)<=0?()=>0:function(){for(var e=0,r=t;r>1;--r)e+=n();return e+r*n()}}return e.source=t,e}(Vp),tg=function t(n){var e=Jp.source(n);function r(t){if(0==(t=+t))return n;var r=e(t);return function(){return r()/t}}return r.source=t,r}(Vp),ng=function t(n){function e(t){return function(){return-Math.log1p(-n())/t}}return e.source=t,e}(Vp),eg=function t(n){function e(t){if((t=+t)<0)throw new RangeError("invalid alpha");return t=1/-t,function(){return Math.pow(1-n(),t)}}return e.source=t,e}(Vp),rg=function t(n){function e(t){if((t=+t)<0||t>1)throw new RangeError("invalid p");return function(){return Math.floor(n()+t)}}return e.source=t,e}(Vp),ig=function t(n){function e(t){if((t=+t)<0||t>1)throw new RangeError("invalid p");return 0===t?()=>1/0:1===t?()=>1:(t=Math.log1p(-t),function(){return 1+Math.floor(Math.log1p(-n())/t)})}return e.source=t,e}(Vp),og=function t(n){var e=Kp.source(n)();function r(t,r){if((t=+t)<0)throw new RangeError("invalid k");if(0===t)return()=>0;if(r=null==r?1:+r,1===t)return()=>-Math.log1p(-n())*r;var i=(t<1?t+1:t)-1/3,o=1/(3*Math.sqrt(i)),a=t<1?()=>Math.pow(n(),1/t):()=>1;return function(){do{do{var t=e(),u=1+o*t}while(u<=0);u*=u*u;var c=1-n()}while(c>=1-.0331*t*t*t*t&&Math.log(c)>=.5*t*t+i*(1-u+Math.log(u)));return i*u*a()*r}}return r.source=t,r}(Vp),ag=function t(n){var e=og.source(n);function r(t,n){var r=e(t),i=e(n);return function(){var t=r();return 0===t?0:t/(t+i())}}return r.source=t,r}(Vp),ug=function t(n){var e=ig.source(n),r=ag.source(n);function i(t,n){return t=+t,(n=+n)>=1?()=>t:n<=0?()=>0:function(){for(var i=0,o=t,a=n;o*a>16&&o*(1-a)>16;){var u=Math.floor((o+1)*a),c=r(u,o-u+1)();c<=a?(i+=u,o-=u,a=(a-c)/(1-c)):(o=u-1,a/=c)}for(var f=a<.5,s=e(f?a:1-a),l=s(),h=0;l<=o;++h)l+=s();return i+(f?h:o-h)}}return i.source=t,i}(Vp),cg=function t(n){function e(t,e,r){var i;return 0==(t=+t)?i=t=>-Math.log(t):(t=1/t,i=n=>Math.pow(n,t)),e=null==e?0:+e,r=null==r?1:+r,function(){return e+r*i(-Math.log1p(-n()))}}return e.source=t,e}(Vp),fg=function t(n){function e(t,e){return t=null==t?0:+t,e=null==e?1:+e,function(){return t+e*Math.tan(Math.PI*n())}}return e.source=t,e}(Vp),sg=function t(n){function e(t,e){return t=null==t?0:+t,e=null==e?1:+e,function(){var r=n();return t+e*Math.log(r/(1-r))}}return e.source=t,e}(Vp),lg=function t(n){var e=og.source(n),r=ug.source(n);function i(t){return function(){for(var i=0,o=t;o>16;){var a=Math.floor(.875*o),u=e(a)();if(u>o)return i+r(a-1,o/u)();i+=a,o-=u}for(var c=-Math.log1p(-n()),f=0;c<=o;++f)c-=Math.log1p(-n());return i+f}}return i.source=t,i}(Vp);const hg=1/4294967296;function dg(t,n){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(n).domain(t)}return this}function pg(t,n){switch(arguments.length){case 0:break;case 1:"function"==typeof t?this.interpolator(t):this.range(t);break;default:this.domain(t),"function"==typeof n?this.interpolator(n):this.range(n)}return this}const gg=Symbol("implicit");function yg(){var t=new InternMap,n=[],e=[],r=gg;function i(i){let o=t.get(i);if(void 0===o){if(r!==gg)return r;t.set(i,o=n.push(i)-1)}return e[o%e.length]}return i.domain=function(e){if(!arguments.length)return n.slice();n=[],t=new InternMap;for(const r of e)t.has(r)||t.set(r,n.push(r)-1);return i},i.range=function(t){return arguments.length?(e=Array.from(t),i):e.slice()},i.unknown=function(t){return arguments.length?(r=t,i):r},i.copy=function(){return yg(n,e).unknown(r)},dg.apply(i,arguments),i}function vg(){var t,n,e=yg().unknown(void 0),r=e.domain,i=e.range,o=0,a=1,u=!1,c=0,f=0,s=.5;function l(){var e=r().length,l=an&&(e=t,t=n,n=e),function(e){return Math.max(t,Math.min(n,e))}}(a[0],a[t-1])),r=t>2?Tg:Mg,i=o=null,l}function l(n){return null==n||isNaN(n=+n)?e:(i||(i=r(a.map(t),u,c)))(t(f(n)))}return l.invert=function(e){return f(n((o||(o=r(u,a.map(t),Lr)))(e)))},l.domain=function(t){return arguments.length?(a=Array.from(t,bg),s()):a.slice()},l.range=function(t){return arguments.length?(u=Array.from(t),s()):u.slice()},l.rangeRound=function(t){return u=Array.from(t),c=Wr,s()},l.clamp=function(t){return arguments.length?(f=!!t||xg,s()):f!==xg},l.interpolate=function(t){return arguments.length?(c=t,s()):c},l.unknown=function(t){return arguments.length?(e=t,l):e},function(e,r){return t=e,n=r,s()}}function Eg(){return Sg()(xg,xg)}function Ng(n,e,r,i){var o,a=Z(n,e,r);switch((i=tf(null==i?",f":i)).type){case"s":var u=Math.max(Math.abs(n),Math.abs(e));return null!=i.precision||isNaN(o=hf(a,u))||(i.precision=o),t.formatPrefix(i,u);case"":case"e":case"g":case"p":case"r":null!=i.precision||isNaN(o=df(a,Math.max(Math.abs(n),Math.abs(e))))||(i.precision=o-("e"===i.type));break;case"f":case"%":null!=i.precision||isNaN(o=lf(a))||(i.precision=o-2*("%"===i.type))}return t.format(i)}function kg(t){var n=t.domain;return t.ticks=function(t){var e=n();return V(e[0],e[e.length-1],null==t?10:t)},t.tickFormat=function(t,e){var r=n();return Ng(r[0],r[r.length-1],null==t?10:t,e)},t.nice=function(e){null==e&&(e=10);var r,i,o=n(),a=0,u=o.length-1,c=o[a],f=o[u],s=10;for(f0;){if((i=W(c,f,e))===r)return o[a]=c,o[u]=f,n(o);if(i>0)c=Math.floor(c/i)*i,f=Math.ceil(f/i)*i;else{if(!(i<0))break;c=Math.ceil(c*i)/i,f=Math.floor(f*i)/i}r=i}return t},t}function Cg(t,n){var e,r=0,i=(t=t.slice()).length-1,o=t[r],a=t[i];return a-t(-n,e)}function qg(n){const e=n(Pg,zg),r=e.domain;let i,o,a=10;function u(){return i=function(t){return t===Math.E?Math.log:10===t&&Math.log10||2===t&&Math.log2||(t=Math.log(t),n=>Math.log(n)/t)}(a),o=function(t){return 10===t?Rg:t===Math.E?Math.exp:n=>Math.pow(t,n)}(a),r()[0]<0?(i=Fg(i),o=Fg(o),n($g,Dg)):n(Pg,zg),e}return e.base=function(t){return arguments.length?(a=+t,u()):a},e.domain=function(t){return arguments.length?(r(t),u()):r()},e.ticks=t=>{const n=r();let e=n[0],u=n[n.length-1];const c=u0){for(;l<=h;++l)for(f=1;fu)break;p.push(s)}}else for(;l<=h;++l)for(f=a-1;f>=1;--f)if(s=l>0?f/o(-l):f*o(l),!(su)break;p.push(s)}2*p.length{if(null==n&&(n=10),null==r&&(r=10===a?"s":","),"function"!=typeof r&&(a%1||null!=(r=tf(r)).precision||(r.trim=!0),r=t.format(r)),n===1/0)return r;const u=Math.max(1,a*n/e.ticks().length);return t=>{let n=t/o(Math.round(i(t)));return n*ar(Cg(r(),{floor:t=>o(Math.floor(i(t))),ceil:t=>o(Math.ceil(i(t)))})),e}function Ug(t){return function(n){return Math.sign(n)*Math.log1p(Math.abs(n/t))}}function Ig(t){return function(n){return Math.sign(n)*Math.expm1(Math.abs(n))*t}}function Og(t){var n=1,e=t(Ug(n),Ig(n));return e.constant=function(e){return arguments.length?t(Ug(n=+e),Ig(n)):n},kg(e)}function Bg(t){return function(n){return n<0?-Math.pow(-n,t):Math.pow(n,t)}}function Yg(t){return t<0?-Math.sqrt(-t):Math.sqrt(t)}function Lg(t){return t<0?-t*t:t*t}function jg(t){var n=t(xg,xg),e=1;return n.exponent=function(n){return arguments.length?1===(e=+n)?t(xg,xg):.5===e?t(Yg,Lg):t(Bg(e),Bg(1/e)):e},kg(n)}function Hg(){var t=jg(Sg());return t.copy=function(){return Ag(t,Hg()).exponent(t.exponent())},dg.apply(t,arguments),t}function Xg(t){return Math.sign(t)*t*t}const Gg=new Date,Vg=new Date;function Wg(t,n,e,r){function i(n){return t(n=0===arguments.length?new Date:new Date(+n)),n}return i.floor=n=>(t(n=new Date(+n)),n),i.ceil=e=>(t(e=new Date(e-1)),n(e,1),t(e),e),i.round=t=>{const n=i(t),e=i.ceil(t);return t-n(n(t=new Date(+t),null==e?1:Math.floor(e)),t),i.range=(e,r,o)=>{const a=[];if(e=i.ceil(e),o=null==o?1:Math.floor(o),!(e0))return a;let u;do{a.push(u=new Date(+e)),n(e,o),t(e)}while(uWg((n=>{if(n>=n)for(;t(n),!e(n);)n.setTime(n-1)}),((t,r)=>{if(t>=t)if(r<0)for(;++r<=0;)for(;n(t,-1),!e(t););else for(;--r>=0;)for(;n(t,1),!e(t););})),e&&(i.count=(n,r)=>(Gg.setTime(+n),Vg.setTime(+r),t(Gg),t(Vg),Math.floor(e(Gg,Vg))),i.every=t=>(t=Math.floor(t),isFinite(t)&&t>0?t>1?i.filter(r?n=>r(n)%t==0:n=>i.count(0,n)%t==0):i:null)),i}const Zg=Wg((()=>{}),((t,n)=>{t.setTime(+t+n)}),((t,n)=>n-t));Zg.every=t=>(t=Math.floor(t),isFinite(t)&&t>0?t>1?Wg((n=>{n.setTime(Math.floor(n/t)*t)}),((n,e)=>{n.setTime(+n+e*t)}),((n,e)=>(e-n)/t)):Zg:null);const Kg=Zg.range,Qg=1e3,Jg=6e4,ty=60*Jg,ny=24*ty,ey=7*ny,ry=30*ny,iy=365*ny,oy=Wg((t=>{t.setTime(t-t.getMilliseconds())}),((t,n)=>{t.setTime(+t+n*Qg)}),((t,n)=>(n-t)/Qg),(t=>t.getUTCSeconds())),ay=oy.range,uy=Wg((t=>{t.setTime(t-t.getMilliseconds()-t.getSeconds()*Qg)}),((t,n)=>{t.setTime(+t+n*Jg)}),((t,n)=>(n-t)/Jg),(t=>t.getMinutes())),cy=uy.range,fy=Wg((t=>{t.setUTCSeconds(0,0)}),((t,n)=>{t.setTime(+t+n*Jg)}),((t,n)=>(n-t)/Jg),(t=>t.getUTCMinutes())),sy=fy.range,ly=Wg((t=>{t.setTime(t-t.getMilliseconds()-t.getSeconds()*Qg-t.getMinutes()*Jg)}),((t,n)=>{t.setTime(+t+n*ty)}),((t,n)=>(n-t)/ty),(t=>t.getHours())),hy=ly.range,dy=Wg((t=>{t.setUTCMinutes(0,0,0)}),((t,n)=>{t.setTime(+t+n*ty)}),((t,n)=>(n-t)/ty),(t=>t.getUTCHours())),py=dy.range,gy=Wg((t=>t.setHours(0,0,0,0)),((t,n)=>t.setDate(t.getDate()+n)),((t,n)=>(n-t-(n.getTimezoneOffset()-t.getTimezoneOffset())*Jg)/ny),(t=>t.getDate()-1)),yy=gy.range,vy=Wg((t=>{t.setUTCHours(0,0,0,0)}),((t,n)=>{t.setUTCDate(t.getUTCDate()+n)}),((t,n)=>(n-t)/ny),(t=>t.getUTCDate()-1)),_y=vy.range,by=Wg((t=>{t.setUTCHours(0,0,0,0)}),((t,n)=>{t.setUTCDate(t.getUTCDate()+n)}),((t,n)=>(n-t)/ny),(t=>Math.floor(t/ny))),my=by.range;function xy(t){return Wg((n=>{n.setDate(n.getDate()-(n.getDay()+7-t)%7),n.setHours(0,0,0,0)}),((t,n)=>{t.setDate(t.getDate()+7*n)}),((t,n)=>(n-t-(n.getTimezoneOffset()-t.getTimezoneOffset())*Jg)/ey))}const wy=xy(0),My=xy(1),Ty=xy(2),Ay=xy(3),Sy=xy(4),Ey=xy(5),Ny=xy(6),ky=wy.range,Cy=My.range,Py=Ty.range,zy=Ay.range,$y=Sy.range,Dy=Ey.range,Ry=Ny.range;function Fy(t){return Wg((n=>{n.setUTCDate(n.getUTCDate()-(n.getUTCDay()+7-t)%7),n.setUTCHours(0,0,0,0)}),((t,n)=>{t.setUTCDate(t.getUTCDate()+7*n)}),((t,n)=>(n-t)/ey))}const qy=Fy(0),Uy=Fy(1),Iy=Fy(2),Oy=Fy(3),By=Fy(4),Yy=Fy(5),Ly=Fy(6),jy=qy.range,Hy=Uy.range,Xy=Iy.range,Gy=Oy.range,Vy=By.range,Wy=Yy.range,Zy=Ly.range,Ky=Wg((t=>{t.setDate(1),t.setHours(0,0,0,0)}),((t,n)=>{t.setMonth(t.getMonth()+n)}),((t,n)=>n.getMonth()-t.getMonth()+12*(n.getFullYear()-t.getFullYear())),(t=>t.getMonth())),Qy=Ky.range,Jy=Wg((t=>{t.setUTCDate(1),t.setUTCHours(0,0,0,0)}),((t,n)=>{t.setUTCMonth(t.getUTCMonth()+n)}),((t,n)=>n.getUTCMonth()-t.getUTCMonth()+12*(n.getUTCFullYear()-t.getUTCFullYear())),(t=>t.getUTCMonth())),tv=Jy.range,nv=Wg((t=>{t.setMonth(0,1),t.setHours(0,0,0,0)}),((t,n)=>{t.setFullYear(t.getFullYear()+n)}),((t,n)=>n.getFullYear()-t.getFullYear()),(t=>t.getFullYear()));nv.every=t=>isFinite(t=Math.floor(t))&&t>0?Wg((n=>{n.setFullYear(Math.floor(n.getFullYear()/t)*t),n.setMonth(0,1),n.setHours(0,0,0,0)}),((n,e)=>{n.setFullYear(n.getFullYear()+e*t)})):null;const ev=nv.range,rv=Wg((t=>{t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)}),((t,n)=>{t.setUTCFullYear(t.getUTCFullYear()+n)}),((t,n)=>n.getUTCFullYear()-t.getUTCFullYear()),(t=>t.getUTCFullYear()));rv.every=t=>isFinite(t=Math.floor(t))&&t>0?Wg((n=>{n.setUTCFullYear(Math.floor(n.getUTCFullYear()/t)*t),n.setUTCMonth(0,1),n.setUTCHours(0,0,0,0)}),((n,e)=>{n.setUTCFullYear(n.getUTCFullYear()+e*t)})):null;const iv=rv.range;function ov(t,n,e,i,o,a){const u=[[oy,1,Qg],[oy,5,5e3],[oy,15,15e3],[oy,30,3e4],[a,1,Jg],[a,5,5*Jg],[a,15,15*Jg],[a,30,30*Jg],[o,1,ty],[o,3,3*ty],[o,6,6*ty],[o,12,12*ty],[i,1,ny],[i,2,2*ny],[e,1,ey],[n,1,ry],[n,3,3*ry],[t,1,iy]];function c(n,e,i){const o=Math.abs(e-n)/i,a=r((([,,t])=>t)).right(u,o);if(a===u.length)return t.every(Z(n/iy,e/iy,i));if(0===a)return Zg.every(Math.max(Z(n,e,i),1));const[c,f]=u[o/u[a-1][2]=12)]},q:function(t){return 1+~~(t.getMonth()/3)},Q:C_,s:P_,S:Kv,u:Qv,U:Jv,V:n_,w:e_,W:r_,x:null,X:null,y:i_,Y:a_,Z:c_,"%":k_},m={a:function(t){return a[t.getUTCDay()]},A:function(t){return o[t.getUTCDay()]},b:function(t){return c[t.getUTCMonth()]},B:function(t){return u[t.getUTCMonth()]},c:null,d:f_,e:f_,f:p_,g:A_,G:E_,H:s_,I:l_,j:h_,L:d_,m:g_,M:y_,p:function(t){return i[+(t.getUTCHours()>=12)]},q:function(t){return 1+~~(t.getUTCMonth()/3)},Q:C_,s:P_,S:v_,u:__,U:b_,V:x_,w:w_,W:M_,x:null,X:null,y:T_,Y:S_,Z:N_,"%":k_},x={a:function(t,n,e){var r=d.exec(n.slice(e));return r?(t.w=p.get(r[0].toLowerCase()),e+r[0].length):-1},A:function(t,n,e){var r=l.exec(n.slice(e));return r?(t.w=h.get(r[0].toLowerCase()),e+r[0].length):-1},b:function(t,n,e){var r=v.exec(n.slice(e));return r?(t.m=_.get(r[0].toLowerCase()),e+r[0].length):-1},B:function(t,n,e){var r=g.exec(n.slice(e));return r?(t.m=y.get(r[0].toLowerCase()),e+r[0].length):-1},c:function(t,e,r){return T(t,n,e,r)},d:$v,e:$v,f:Iv,g:kv,G:Nv,H:Rv,I:Rv,j:Dv,L:Uv,m:zv,M:Fv,p:function(t,n,e){var r=f.exec(n.slice(e));return r?(t.p=s.get(r[0].toLowerCase()),e+r[0].length):-1},q:Pv,Q:Bv,s:Yv,S:qv,u:Tv,U:Av,V:Sv,w:Mv,W:Ev,x:function(t,n,r){return T(t,e,n,r)},X:function(t,n,e){return T(t,r,n,e)},y:kv,Y:Nv,Z:Cv,"%":Ov};function w(t,n){return function(e){var r,i,o,a=[],u=-1,c=0,f=t.length;for(e instanceof Date||(e=new Date(+e));++u53)return null;"w"in o||(o.w=1),"Z"in o?(i=(r=lv(hv(o.y,0,1))).getUTCDay(),r=i>4||0===i?Uy.ceil(r):Uy(r),r=vy.offset(r,7*(o.V-1)),o.y=r.getUTCFullYear(),o.m=r.getUTCMonth(),o.d=r.getUTCDate()+(o.w+6)%7):(i=(r=sv(hv(o.y,0,1))).getDay(),r=i>4||0===i?My.ceil(r):My(r),r=gy.offset(r,7*(o.V-1)),o.y=r.getFullYear(),o.m=r.getMonth(),o.d=r.getDate()+(o.w+6)%7)}else("W"in o||"U"in o)&&("w"in o||(o.w="u"in o?o.u%7:"W"in o?1:0),i="Z"in o?lv(hv(o.y,0,1)).getUTCDay():sv(hv(o.y,0,1)).getDay(),o.m=0,o.d="W"in o?(o.w+6)%7+7*o.W-(i+5)%7:o.w+7*o.U-(i+6)%7);return"Z"in o?(o.H+=o.Z/100|0,o.M+=o.Z%100,lv(o)):sv(o)}}function T(t,n,e,r){for(var i,o,a=0,u=n.length,c=e.length;a=c)return-1;if(37===(i=n.charCodeAt(a++))){if(i=n.charAt(a++),!(o=x[i in gv?n.charAt(a++):i])||(r=o(t,e,r))<0)return-1}else if(i!=e.charCodeAt(r++))return-1}return r}return b.x=w(e,b),b.X=w(r,b),b.c=w(n,b),m.x=w(e,m),m.X=w(r,m),m.c=w(n,m),{format:function(t){var n=w(t+="",b);return n.toString=function(){return t},n},parse:function(t){var n=M(t+="",!1);return n.toString=function(){return t},n},utcFormat:function(t){var n=w(t+="",m);return n.toString=function(){return t},n},utcParse:function(t){var n=M(t+="",!0);return n.toString=function(){return t},n}}}var pv,gv={"-":"",_:" ",0:"0"},yv=/^\s*\d+/,vv=/^%/,_v=/[\\^$*+?|[\]().{}]/g;function bv(t,n,e){var r=t<0?"-":"",i=(r?-t:t)+"",o=i.length;return r+(o[t.toLowerCase(),n])))}function Mv(t,n,e){var r=yv.exec(n.slice(e,e+1));return r?(t.w=+r[0],e+r[0].length):-1}function Tv(t,n,e){var r=yv.exec(n.slice(e,e+1));return r?(t.u=+r[0],e+r[0].length):-1}function Av(t,n,e){var r=yv.exec(n.slice(e,e+2));return r?(t.U=+r[0],e+r[0].length):-1}function Sv(t,n,e){var r=yv.exec(n.slice(e,e+2));return r?(t.V=+r[0],e+r[0].length):-1}function Ev(t,n,e){var r=yv.exec(n.slice(e,e+2));return r?(t.W=+r[0],e+r[0].length):-1}function Nv(t,n,e){var r=yv.exec(n.slice(e,e+4));return r?(t.y=+r[0],e+r[0].length):-1}function kv(t,n,e){var r=yv.exec(n.slice(e,e+2));return r?(t.y=+r[0]+(+r[0]>68?1900:2e3),e+r[0].length):-1}function Cv(t,n,e){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(n.slice(e,e+6));return r?(t.Z=r[1]?0:-(r[2]+(r[3]||"00")),e+r[0].length):-1}function Pv(t,n,e){var r=yv.exec(n.slice(e,e+1));return r?(t.q=3*r[0]-3,e+r[0].length):-1}function zv(t,n,e){var r=yv.exec(n.slice(e,e+2));return r?(t.m=r[0]-1,e+r[0].length):-1}function $v(t,n,e){var r=yv.exec(n.slice(e,e+2));return r?(t.d=+r[0],e+r[0].length):-1}function Dv(t,n,e){var r=yv.exec(n.slice(e,e+3));return r?(t.m=0,t.d=+r[0],e+r[0].length):-1}function Rv(t,n,e){var r=yv.exec(n.slice(e,e+2));return r?(t.H=+r[0],e+r[0].length):-1}function Fv(t,n,e){var r=yv.exec(n.slice(e,e+2));return r?(t.M=+r[0],e+r[0].length):-1}function qv(t,n,e){var r=yv.exec(n.slice(e,e+2));return r?(t.S=+r[0],e+r[0].length):-1}function Uv(t,n,e){var r=yv.exec(n.slice(e,e+3));return r?(t.L=+r[0],e+r[0].length):-1}function Iv(t,n,e){var r=yv.exec(n.slice(e,e+6));return r?(t.L=Math.floor(r[0]/1e3),e+r[0].length):-1}function Ov(t,n,e){var r=vv.exec(n.slice(e,e+1));return r?e+r[0].length:-1}function Bv(t,n,e){var r=yv.exec(n.slice(e));return r?(t.Q=+r[0],e+r[0].length):-1}function Yv(t,n,e){var r=yv.exec(n.slice(e));return r?(t.s=+r[0],e+r[0].length):-1}function Lv(t,n){return bv(t.getDate(),n,2)}function jv(t,n){return bv(t.getHours(),n,2)}function Hv(t,n){return bv(t.getHours()%12||12,n,2)}function Xv(t,n){return bv(1+gy.count(nv(t),t),n,3)}function Gv(t,n){return bv(t.getMilliseconds(),n,3)}function Vv(t,n){return Gv(t,n)+"000"}function Wv(t,n){return bv(t.getMonth()+1,n,2)}function Zv(t,n){return bv(t.getMinutes(),n,2)}function Kv(t,n){return bv(t.getSeconds(),n,2)}function Qv(t){var n=t.getDay();return 0===n?7:n}function Jv(t,n){return bv(wy.count(nv(t)-1,t),n,2)}function t_(t){var n=t.getDay();return n>=4||0===n?Sy(t):Sy.ceil(t)}function n_(t,n){return t=t_(t),bv(Sy.count(nv(t),t)+(4===nv(t).getDay()),n,2)}function e_(t){return t.getDay()}function r_(t,n){return bv(My.count(nv(t)-1,t),n,2)}function i_(t,n){return bv(t.getFullYear()%100,n,2)}function o_(t,n){return bv((t=t_(t)).getFullYear()%100,n,2)}function a_(t,n){return bv(t.getFullYear()%1e4,n,4)}function u_(t,n){var e=t.getDay();return bv((t=e>=4||0===e?Sy(t):Sy.ceil(t)).getFullYear()%1e4,n,4)}function c_(t){var n=t.getTimezoneOffset();return(n>0?"-":(n*=-1,"+"))+bv(n/60|0,"0",2)+bv(n%60,"0",2)}function f_(t,n){return bv(t.getUTCDate(),n,2)}function s_(t,n){return bv(t.getUTCHours(),n,2)}function l_(t,n){return bv(t.getUTCHours()%12||12,n,2)}function h_(t,n){return bv(1+vy.count(rv(t),t),n,3)}function d_(t,n){return bv(t.getUTCMilliseconds(),n,3)}function p_(t,n){return d_(t,n)+"000"}function g_(t,n){return bv(t.getUTCMonth()+1,n,2)}function y_(t,n){return bv(t.getUTCMinutes(),n,2)}function v_(t,n){return bv(t.getUTCSeconds(),n,2)}function __(t){var n=t.getUTCDay();return 0===n?7:n}function b_(t,n){return bv(qy.count(rv(t)-1,t),n,2)}function m_(t){var n=t.getUTCDay();return n>=4||0===n?By(t):By.ceil(t)}function x_(t,n){return t=m_(t),bv(By.count(rv(t),t)+(4===rv(t).getUTCDay()),n,2)}function w_(t){return t.getUTCDay()}function M_(t,n){return bv(Uy.count(rv(t)-1,t),n,2)}function T_(t,n){return bv(t.getUTCFullYear()%100,n,2)}function A_(t,n){return bv((t=m_(t)).getUTCFullYear()%100,n,2)}function S_(t,n){return bv(t.getUTCFullYear()%1e4,n,4)}function E_(t,n){var e=t.getUTCDay();return bv((t=e>=4||0===e?By(t):By.ceil(t)).getUTCFullYear()%1e4,n,4)}function N_(){return"+0000"}function k_(){return"%"}function C_(t){return+t}function P_(t){return Math.floor(+t/1e3)}function z_(n){return pv=dv(n),t.timeFormat=pv.format,t.timeParse=pv.parse,t.utcFormat=pv.utcFormat,t.utcParse=pv.utcParse,pv}t.timeFormat=void 0,t.timeParse=void 0,t.utcFormat=void 0,t.utcParse=void 0,z_({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});var $_="%Y-%m-%dT%H:%M:%S.%LZ";var D_=Date.prototype.toISOString?function(t){return t.toISOString()}:t.utcFormat($_),R_=D_;var F_=+new Date("2000-01-01T00:00:00.000Z")?function(t){var n=new Date(t);return isNaN(n)?null:n}:t.utcParse($_),q_=F_;function U_(t){return new Date(t)}function I_(t){return t instanceof Date?+t:+new Date(+t)}function O_(t,n,e,r,i,o,a,u,c,f){var s=Eg(),l=s.invert,h=s.domain,d=f(".%L"),p=f(":%S"),g=f("%I:%M"),y=f("%I %p"),v=f("%a %d"),_=f("%b %d"),b=f("%B"),m=f("%Y");function x(t){return(c(t)qr(t[t.length-1]),ib=new Array(3).concat("d8b365f5f5f55ab4ac","a6611adfc27d80cdc1018571","a6611adfc27df5f5f580cdc1018571","8c510ad8b365f6e8c3c7eae55ab4ac01665e","8c510ad8b365f6e8c3f5f5f5c7eae55ab4ac01665e","8c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e","8c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e","5430058c510abf812ddfc27df6e8c3c7eae580cdc135978f01665e003c30","5430058c510abf812ddfc27df6e8c3f5f5f5c7eae580cdc135978f01665e003c30").map(X_),ob=rb(ib),ab=new Array(3).concat("af8dc3f7f7f77fbf7b","7b3294c2a5cfa6dba0008837","7b3294c2a5cff7f7f7a6dba0008837","762a83af8dc3e7d4e8d9f0d37fbf7b1b7837","762a83af8dc3e7d4e8f7f7f7d9f0d37fbf7b1b7837","762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b7837","762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b7837","40004b762a839970abc2a5cfe7d4e8d9f0d3a6dba05aae611b783700441b","40004b762a839970abc2a5cfe7d4e8f7f7f7d9f0d3a6dba05aae611b783700441b").map(X_),ub=rb(ab),cb=new Array(3).concat("e9a3c9f7f7f7a1d76a","d01c8bf1b6dab8e1864dac26","d01c8bf1b6daf7f7f7b8e1864dac26","c51b7de9a3c9fde0efe6f5d0a1d76a4d9221","c51b7de9a3c9fde0eff7f7f7e6f5d0a1d76a4d9221","c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221","c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221","8e0152c51b7dde77aef1b6dafde0efe6f5d0b8e1867fbc414d9221276419","8e0152c51b7dde77aef1b6dafde0eff7f7f7e6f5d0b8e1867fbc414d9221276419").map(X_),fb=rb(cb),sb=new Array(3).concat("998ec3f7f7f7f1a340","5e3c99b2abd2fdb863e66101","5e3c99b2abd2f7f7f7fdb863e66101","542788998ec3d8daebfee0b6f1a340b35806","542788998ec3d8daebf7f7f7fee0b6f1a340b35806","5427888073acb2abd2d8daebfee0b6fdb863e08214b35806","5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b35806","2d004b5427888073acb2abd2d8daebfee0b6fdb863e08214b358067f3b08","2d004b5427888073acb2abd2d8daebf7f7f7fee0b6fdb863e08214b358067f3b08").map(X_),lb=rb(sb),hb=new Array(3).concat("ef8a62f7f7f767a9cf","ca0020f4a58292c5de0571b0","ca0020f4a582f7f7f792c5de0571b0","b2182bef8a62fddbc7d1e5f067a9cf2166ac","b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac","b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac","b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac","67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061","67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061").map(X_),db=rb(hb),pb=new Array(3).concat("ef8a62ffffff999999","ca0020f4a582bababa404040","ca0020f4a582ffffffbababa404040","b2182bef8a62fddbc7e0e0e09999994d4d4d","b2182bef8a62fddbc7ffffffe0e0e09999994d4d4d","b2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d","b2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d","67001fb2182bd6604df4a582fddbc7e0e0e0bababa8787874d4d4d1a1a1a","67001fb2182bd6604df4a582fddbc7ffffffe0e0e0bababa8787874d4d4d1a1a1a").map(X_),gb=rb(pb),yb=new Array(3).concat("fc8d59ffffbf91bfdb","d7191cfdae61abd9e92c7bb6","d7191cfdae61ffffbfabd9e92c7bb6","d73027fc8d59fee090e0f3f891bfdb4575b4","d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4","d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4","d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4","a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695","a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695").map(X_),vb=rb(yb),_b=new Array(3).concat("fc8d59ffffbf91cf60","d7191cfdae61a6d96a1a9641","d7191cfdae61ffffbfa6d96a1a9641","d73027fc8d59fee08bd9ef8b91cf601a9850","d73027fc8d59fee08bffffbfd9ef8b91cf601a9850","d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850","d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850","a50026d73027f46d43fdae61fee08bd9ef8ba6d96a66bd631a9850006837","a50026d73027f46d43fdae61fee08bffffbfd9ef8ba6d96a66bd631a9850006837").map(X_),bb=rb(_b),mb=new Array(3).concat("fc8d59ffffbf99d594","d7191cfdae61abdda42b83ba","d7191cfdae61ffffbfabdda42b83ba","d53e4ffc8d59fee08be6f59899d5943288bd","d53e4ffc8d59fee08bffffbfe6f59899d5943288bd","d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd","d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd","9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2","9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2").map(X_),xb=rb(mb),wb=new Array(3).concat("e5f5f999d8c92ca25f","edf8fbb2e2e266c2a4238b45","edf8fbb2e2e266c2a42ca25f006d2c","edf8fbccece699d8c966c2a42ca25f006d2c","edf8fbccece699d8c966c2a441ae76238b45005824","f7fcfde5f5f9ccece699d8c966c2a441ae76238b45005824","f7fcfde5f5f9ccece699d8c966c2a441ae76238b45006d2c00441b").map(X_),Mb=rb(wb),Tb=new Array(3).concat("e0ecf49ebcda8856a7","edf8fbb3cde38c96c688419d","edf8fbb3cde38c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b").map(X_),Ab=rb(Tb),Sb=new Array(3).concat("e0f3dba8ddb543a2ca","f0f9e8bae4bc7bccc42b8cbe","f0f9e8bae4bc7bccc443a2ca0868ac","f0f9e8ccebc5a8ddb57bccc443a2ca0868ac","f0f9e8ccebc5a8ddb57bccc44eb3d32b8cbe08589e","f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe08589e","f7fcf0e0f3dbccebc5a8ddb57bccc44eb3d32b8cbe0868ac084081").map(X_),Eb=rb(Sb),Nb=new Array(3).concat("fee8c8fdbb84e34a33","fef0d9fdcc8afc8d59d7301f","fef0d9fdcc8afc8d59e34a33b30000","fef0d9fdd49efdbb84fc8d59e34a33b30000","fef0d9fdd49efdbb84fc8d59ef6548d7301f990000","fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301f990000","fff7ecfee8c8fdd49efdbb84fc8d59ef6548d7301fb300007f0000").map(X_),kb=rb(Nb),Cb=new Array(3).concat("ece2f0a6bddb1c9099","f6eff7bdc9e167a9cf02818a","f6eff7bdc9e167a9cf1c9099016c59","f6eff7d0d1e6a6bddb67a9cf1c9099016c59","f6eff7d0d1e6a6bddb67a9cf3690c002818a016450","fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016450","fff7fbece2f0d0d1e6a6bddb67a9cf3690c002818a016c59014636").map(X_),Pb=rb(Cb),zb=new Array(3).concat("ece7f2a6bddb2b8cbe","f1eef6bdc9e174a9cf0570b0","f1eef6bdc9e174a9cf2b8cbe045a8d","f1eef6d0d1e6a6bddb74a9cf2b8cbe045a8d","f1eef6d0d1e6a6bddb74a9cf3690c00570b0034e7b","fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0034e7b","fff7fbece7f2d0d1e6a6bddb74a9cf3690c00570b0045a8d023858").map(X_),$b=rb(zb),Db=new Array(3).concat("e7e1efc994c7dd1c77","f1eef6d7b5d8df65b0ce1256","f1eef6d7b5d8df65b0dd1c77980043","f1eef6d4b9dac994c7df65b0dd1c77980043","f1eef6d4b9dac994c7df65b0e7298ace125691003f","f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125691003f","f7f4f9e7e1efd4b9dac994c7df65b0e7298ace125698004367001f").map(X_),Rb=rb(Db),Fb=new Array(3).concat("fde0ddfa9fb5c51b8a","feebe2fbb4b9f768a1ae017e","feebe2fbb4b9f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a").map(X_),qb=rb(Fb),Ub=new Array(3).concat("edf8b17fcdbb2c7fb8","ffffcca1dab441b6c4225ea8","ffffcca1dab441b6c42c7fb8253494","ffffccc7e9b47fcdbb41b6c42c7fb8253494","ffffccc7e9b47fcdbb41b6c41d91c0225ea80c2c84","ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea80c2c84","ffffd9edf8b1c7e9b47fcdbb41b6c41d91c0225ea8253494081d58").map(X_),Ib=rb(Ub),Ob=new Array(3).concat("f7fcb9addd8e31a354","ffffccc2e69978c679238443","ffffccc2e69978c67931a354006837","ffffccd9f0a3addd8e78c67931a354006837","ffffccd9f0a3addd8e78c67941ab5d238443005a32","ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443005a32","ffffe5f7fcb9d9f0a3addd8e78c67941ab5d238443006837004529").map(X_),Bb=rb(Ob),Yb=new Array(3).concat("fff7bcfec44fd95f0e","ffffd4fed98efe9929cc4c02","ffffd4fed98efe9929d95f0e993404","ffffd4fee391fec44ffe9929d95f0e993404","ffffd4fee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506").map(X_),Lb=rb(Yb),jb=new Array(3).concat("ffeda0feb24cf03b20","ffffb2fecc5cfd8d3ce31a1c","ffffb2fecc5cfd8d3cf03b20bd0026","ffffb2fed976feb24cfd8d3cf03b20bd0026","ffffb2fed976feb24cfd8d3cfc4e2ae31a1cb10026","ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cb10026","ffffccffeda0fed976feb24cfd8d3cfc4e2ae31a1cbd0026800026").map(X_),Hb=rb(jb),Xb=new Array(3).concat("deebf79ecae13182bd","eff3ffbdd7e76baed62171b5","eff3ffbdd7e76baed63182bd08519c","eff3ffc6dbef9ecae16baed63182bd08519c","eff3ffc6dbef9ecae16baed64292c62171b5084594","f7fbffdeebf7c6dbef9ecae16baed64292c62171b5084594","f7fbffdeebf7c6dbef9ecae16baed64292c62171b508519c08306b").map(X_),Gb=rb(Xb),Vb=new Array(3).concat("e5f5e0a1d99b31a354","edf8e9bae4b374c476238b45","edf8e9bae4b374c47631a354006d2c","edf8e9c7e9c0a1d99b74c47631a354006d2c","edf8e9c7e9c0a1d99b74c47641ab5d238b45005a32","f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45005a32","f7fcf5e5f5e0c7e9c0a1d99b74c47641ab5d238b45006d2c00441b").map(X_),Wb=rb(Vb),Zb=new Array(3).concat("f0f0f0bdbdbd636363","f7f7f7cccccc969696525252","f7f7f7cccccc969696636363252525","f7f7f7d9d9d9bdbdbd969696636363252525","f7f7f7d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000").map(X_),Kb=rb(Zb),Qb=new Array(3).concat("efedf5bcbddc756bb1","f2f0f7cbc9e29e9ac86a51a3","f2f0f7cbc9e29e9ac8756bb154278f","f2f0f7dadaebbcbddc9e9ac8756bb154278f","f2f0f7dadaebbcbddc9e9ac8807dba6a51a34a1486","fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a34a1486","fcfbfdefedf5dadaebbcbddc9e9ac8807dba6a51a354278f3f007d").map(X_),Jb=rb(Qb),tm=new Array(3).concat("fee0d2fc9272de2d26","fee5d9fcae91fb6a4acb181d","fee5d9fcae91fb6a4ade2d26a50f15","fee5d9fcbba1fc9272fb6a4ade2d26a50f15","fee5d9fcbba1fc9272fb6a4aef3b2ccb181d99000d","fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181d99000d","fff5f0fee0d2fcbba1fc9272fb6a4aef3b2ccb181da50f1567000d").map(X_),nm=rb(tm),em=new Array(3).concat("fee6cefdae6be6550d","feeddefdbe85fd8d3cd94701","feeddefdbe85fd8d3ce6550da63603","feeddefdd0a2fdae6bfd8d3ce6550da63603","feeddefdd0a2fdae6bfd8d3cf16913d948018c2d04","fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d948018c2d04","fff5ebfee6cefdd0a2fdae6bfd8d3cf16913d94801a636037f2704").map(X_),rm=rb(em);var im=di(Ar(300,.5,0),Ar(-240,.5,1)),om=di(Ar(-100,.75,.35),Ar(80,1.5,.8)),am=di(Ar(260,.75,.35),Ar(80,1.5,.8)),um=Ar();var cm=qe(),fm=Math.PI/3,sm=2*Math.PI/3;function lm(t){var n=t.length;return function(e){return t[Math.max(0,Math.min(n-1,Math.floor(e*n)))]}}var hm=lm(X_("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725")),dm=lm(X_("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf")),pm=lm(X_("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4")),gm=lm(X_("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));function ym(t){return function(){return t}}const vm=Math.abs,_m=Math.atan2,bm=Math.cos,mm=Math.max,xm=Math.min,wm=Math.sin,Mm=Math.sqrt,Tm=1e-12,Am=Math.PI,Sm=Am/2,Em=2*Am;function Nm(t){return t>=1?Sm:t<=-1?-Sm:Math.asin(t)}function km(t){let n=3;return t.digits=function(e){if(!arguments.length)return n;if(null==e)n=null;else{const t=Math.floor(e);if(!(t>=0))throw new RangeError(`invalid digits: ${e}`);n=t}return t},()=>new Ia(n)}function Cm(t){return t.innerRadius}function Pm(t){return t.outerRadius}function zm(t){return t.startAngle}function $m(t){return t.endAngle}function Dm(t){return t&&t.padAngle}function Rm(t,n,e,r,i,o,a){var u=t-e,c=n-r,f=(a?o:-o)/Mm(u*u+c*c),s=f*c,l=-f*u,h=t+s,d=n+l,p=e+s,g=r+l,y=(h+p)/2,v=(d+g)/2,_=p-h,b=g-d,m=_*_+b*b,x=i-o,w=h*g-p*d,M=(b<0?-1:1)*Mm(mm(0,x*x*m-w*w)),T=(w*b-_*M)/m,A=(-w*_-b*M)/m,S=(w*b+_*M)/m,E=(-w*_+b*M)/m,N=T-y,k=A-v,C=S-y,P=E-v;return N*N+k*k>C*C+P*P&&(T=S,A=E),{cx:T,cy:A,x01:-s,y01:-l,x11:T*(i/x-1),y11:A*(i/x-1)}}var Fm=Array.prototype.slice;function qm(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}function Um(t){this._context=t}function Im(t){return new Um(t)}function Om(t){return t[0]}function Bm(t){return t[1]}function Ym(t,n){var e=ym(!0),r=null,i=Im,o=null,a=km(u);function u(u){var c,f,s,l=(u=qm(u)).length,h=!1;for(null==r&&(o=i(s=a())),c=0;c<=l;++c)!(c=l;--h)u.point(v[h],_[h]);u.lineEnd(),u.areaEnd()}y&&(v[s]=+t(d,s,f),_[s]=+n(d,s,f),u.point(r?+r(d,s,f):v[s],e?+e(d,s,f):_[s]))}if(p)return u=null,p+""||null}function s(){return Ym().defined(i).curve(a).context(o)}return t="function"==typeof t?t:void 0===t?Om:ym(+t),n="function"==typeof n?n:ym(void 0===n?0:+n),e="function"==typeof e?e:void 0===e?Bm:ym(+e),f.x=function(n){return arguments.length?(t="function"==typeof n?n:ym(+n),r=null,f):t},f.x0=function(n){return arguments.length?(t="function"==typeof n?n:ym(+n),f):t},f.x1=function(t){return arguments.length?(r=null==t?null:"function"==typeof t?t:ym(+t),f):r},f.y=function(t){return arguments.length?(n="function"==typeof t?t:ym(+t),e=null,f):n},f.y0=function(t){return arguments.length?(n="function"==typeof t?t:ym(+t),f):n},f.y1=function(t){return arguments.length?(e=null==t?null:"function"==typeof t?t:ym(+t),f):e},f.lineX0=f.lineY0=function(){return s().x(t).y(n)},f.lineY1=function(){return s().x(t).y(e)},f.lineX1=function(){return s().x(r).y(n)},f.defined=function(t){return arguments.length?(i="function"==typeof t?t:ym(!!t),f):i},f.curve=function(t){return arguments.length?(a=t,null!=o&&(u=a(o)),f):a},f.context=function(t){return arguments.length?(null==t?o=u=null:u=a(o=t),f):o},f}function jm(t,n){return nt?1:n>=t?0:NaN}function Hm(t){return t}Um.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2;default:this._context.lineTo(t,n)}}};var Xm=Vm(Im);function Gm(t){this._curve=t}function Vm(t){function n(n){return new Gm(t(n))}return n._curve=t,n}function Wm(t){var n=t.curve;return t.angle=t.x,delete t.x,t.radius=t.y,delete t.y,t.curve=function(t){return arguments.length?n(Vm(t)):n()._curve},t}function Zm(){return Wm(Ym().curve(Xm))}function Km(){var t=Lm().curve(Xm),n=t.curve,e=t.lineX0,r=t.lineX1,i=t.lineY0,o=t.lineY1;return t.angle=t.x,delete t.x,t.startAngle=t.x0,delete t.x0,t.endAngle=t.x1,delete t.x1,t.radius=t.y,delete t.y,t.innerRadius=t.y0,delete t.y0,t.outerRadius=t.y1,delete t.y1,t.lineStartAngle=function(){return Wm(e())},delete t.lineX0,t.lineEndAngle=function(){return Wm(r())},delete t.lineX1,t.lineInnerRadius=function(){return Wm(i())},delete t.lineY0,t.lineOuterRadius=function(){return Wm(o())},delete t.lineY1,t.curve=function(t){return arguments.length?n(Vm(t)):n()._curve},t}function Qm(t,n){return[(n=+n)*Math.cos(t-=Math.PI/2),n*Math.sin(t)]}Gm.prototype={areaStart:function(){this._curve.areaStart()},areaEnd:function(){this._curve.areaEnd()},lineStart:function(){this._curve.lineStart()},lineEnd:function(){this._curve.lineEnd()},point:function(t,n){this._curve.point(n*Math.sin(t),n*-Math.cos(t))}};class Jm{constructor(t,n){this._context=t,this._x=n}areaStart(){this._line=0}areaEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line}point(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2;default:this._x?this._context.bezierCurveTo(this._x0=(this._x0+t)/2,this._y0,this._x0,n,t,n):this._context.bezierCurveTo(this._x0,this._y0=(this._y0+n)/2,t,this._y0,t,n)}this._x0=t,this._y0=n}}class tx{constructor(t){this._context=t}lineStart(){this._point=0}lineEnd(){}point(t,n){if(t=+t,n=+n,0===this._point)this._point=1;else{const e=Qm(this._x0,this._y0),r=Qm(this._x0,this._y0=(this._y0+n)/2),i=Qm(t,this._y0),o=Qm(t,n);this._context.moveTo(...e),this._context.bezierCurveTo(...r,...i,...o)}this._x0=t,this._y0=n}}function nx(t){return new Jm(t,!0)}function ex(t){return new Jm(t,!1)}function rx(t){return new tx(t)}function ix(t){return t.source}function ox(t){return t.target}function ax(t){let n=ix,e=ox,r=Om,i=Bm,o=null,a=null,u=km(c);function c(){let c;const f=Fm.call(arguments),s=n.apply(this,f),l=e.apply(this,f);if(null==o&&(a=t(c=u())),a.lineStart(),f[0]=s,a.point(+r.apply(this,f),+i.apply(this,f)),f[0]=l,a.point(+r.apply(this,f),+i.apply(this,f)),a.lineEnd(),c)return a=null,c+""||null}return c.source=function(t){return arguments.length?(n=t,c):n},c.target=function(t){return arguments.length?(e=t,c):e},c.x=function(t){return arguments.length?(r="function"==typeof t?t:ym(+t),c):r},c.y=function(t){return arguments.length?(i="function"==typeof t?t:ym(+t),c):i},c.context=function(n){return arguments.length?(null==n?o=a=null:a=t(o=n),c):o},c}const ux=Mm(3);var cx={draw(t,n){const e=.59436*Mm(n+xm(n/28,.75)),r=e/2,i=r*ux;t.moveTo(0,e),t.lineTo(0,-e),t.moveTo(-i,-r),t.lineTo(i,r),t.moveTo(-i,r),t.lineTo(i,-r)}},fx={draw(t,n){const e=Mm(n/Am);t.moveTo(e,0),t.arc(0,0,e,0,Em)}},sx={draw(t,n){const e=Mm(n/5)/2;t.moveTo(-3*e,-e),t.lineTo(-e,-e),t.lineTo(-e,-3*e),t.lineTo(e,-3*e),t.lineTo(e,-e),t.lineTo(3*e,-e),t.lineTo(3*e,e),t.lineTo(e,e),t.lineTo(e,3*e),t.lineTo(-e,3*e),t.lineTo(-e,e),t.lineTo(-3*e,e),t.closePath()}};const lx=Mm(1/3),hx=2*lx;var dx={draw(t,n){const e=Mm(n/hx),r=e*lx;t.moveTo(0,-e),t.lineTo(r,0),t.lineTo(0,e),t.lineTo(-r,0),t.closePath()}},px={draw(t,n){const e=.62625*Mm(n);t.moveTo(0,-e),t.lineTo(e,0),t.lineTo(0,e),t.lineTo(-e,0),t.closePath()}},gx={draw(t,n){const e=.87559*Mm(n-xm(n/7,2));t.moveTo(-e,0),t.lineTo(e,0),t.moveTo(0,e),t.lineTo(0,-e)}},yx={draw(t,n){const e=Mm(n),r=-e/2;t.rect(r,r,e,e)}},vx={draw(t,n){const e=.4431*Mm(n);t.moveTo(e,e),t.lineTo(e,-e),t.lineTo(-e,-e),t.lineTo(-e,e),t.closePath()}};const _x=wm(Am/10)/wm(7*Am/10),bx=wm(Em/10)*_x,mx=-bm(Em/10)*_x;var xx={draw(t,n){const e=Mm(.8908130915292852*n),r=bx*e,i=mx*e;t.moveTo(0,-e),t.lineTo(r,i);for(let n=1;n<5;++n){const o=Em*n/5,a=bm(o),u=wm(o);t.lineTo(u*e,-a*e),t.lineTo(a*r-u*i,u*r+a*i)}t.closePath()}};const wx=Mm(3);var Mx={draw(t,n){const e=-Mm(n/(3*wx));t.moveTo(0,2*e),t.lineTo(-wx*e,-e),t.lineTo(wx*e,-e),t.closePath()}};const Tx=Mm(3);var Ax={draw(t,n){const e=.6824*Mm(n),r=e/2,i=e*Tx/2;t.moveTo(0,-e),t.lineTo(i,r),t.lineTo(-i,r),t.closePath()}};const Sx=-.5,Ex=Mm(3)/2,Nx=1/Mm(12),kx=3*(Nx/2+1);var Cx={draw(t,n){const e=Mm(n/kx),r=e/2,i=e*Nx,o=r,a=e*Nx+e,u=-o,c=a;t.moveTo(r,i),t.lineTo(o,a),t.lineTo(u,c),t.lineTo(Sx*r-Ex*i,Ex*r+Sx*i),t.lineTo(Sx*o-Ex*a,Ex*o+Sx*a),t.lineTo(Sx*u-Ex*c,Ex*u+Sx*c),t.lineTo(Sx*r+Ex*i,Sx*i-Ex*r),t.lineTo(Sx*o+Ex*a,Sx*a-Ex*o),t.lineTo(Sx*u+Ex*c,Sx*c-Ex*u),t.closePath()}},Px={draw(t,n){const e=.6189*Mm(n-xm(n/6,1.7));t.moveTo(-e,-e),t.lineTo(e,e),t.moveTo(-e,e),t.lineTo(e,-e)}};const zx=[fx,sx,dx,yx,xx,Mx,Cx],$x=[fx,gx,Px,Ax,cx,vx,px];function Dx(){}function Rx(t,n,e){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+n)/6,(t._y0+4*t._y1+e)/6)}function Fx(t){this._context=t}function qx(t){this._context=t}function Ux(t){this._context=t}function Ix(t,n){this._basis=new Fx(t),this._beta=n}Fx.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:Rx(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:Rx(this,t,n)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=n}},qx.prototype={areaStart:Dx,areaEnd:Dx,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x2,this._y2),this._context.closePath();break;case 2:this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break;case 3:this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4)}},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._x2=t,this._y2=n;break;case 1:this._point=2,this._x3=t,this._y3=n;break;case 2:this._point=3,this._x4=t,this._y4=n,this._context.moveTo((this._x0+4*this._x1+t)/6,(this._y0+4*this._y1+n)/6);break;default:Rx(this,t,n)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=n}},Ux.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var e=(this._x0+4*this._x1+t)/6,r=(this._y0+4*this._y1+n)/6;this._line?this._context.lineTo(e,r):this._context.moveTo(e,r);break;case 3:this._point=4;default:Rx(this,t,n)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=n}},Ix.prototype={lineStart:function(){this._x=[],this._y=[],this._basis.lineStart()},lineEnd:function(){var t=this._x,n=this._y,e=t.length-1;if(e>0)for(var r,i=t[0],o=n[0],a=t[e]-i,u=n[e]-o,c=-1;++c<=e;)r=c/e,this._basis.point(this._beta*t[c]+(1-this._beta)*(i+r*a),this._beta*n[c]+(1-this._beta)*(o+r*u));this._x=this._y=null,this._basis.lineEnd()},point:function(t,n){this._x.push(+t),this._y.push(+n)}};var Ox=function t(n){function e(t){return 1===n?new Fx(t):new Ix(t,n)}return e.beta=function(n){return t(+n)},e}(.85);function Bx(t,n,e){t._context.bezierCurveTo(t._x1+t._k*(t._x2-t._x0),t._y1+t._k*(t._y2-t._y0),t._x2+t._k*(t._x1-n),t._y2+t._k*(t._y1-e),t._x2,t._y2)}function Yx(t,n){this._context=t,this._k=(1-n)/6}Yx.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:Bx(this,this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2,this._x1=t,this._y1=n;break;case 2:this._point=3;default:Bx(this,t,n)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var Lx=function t(n){function e(t){return new Yx(t,n)}return e.tension=function(n){return t(+n)},e}(0);function jx(t,n){this._context=t,this._k=(1-n)/6}jx.prototype={areaStart:Dx,areaEnd:Dx,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x3,this._y3),this._context.closePath();break;case 2:this._context.lineTo(this._x3,this._y3),this._context.closePath();break;case 3:this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5)}},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._x3=t,this._y3=n;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=n);break;case 2:this._point=3,this._x5=t,this._y5=n;break;default:Bx(this,t,n)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var Hx=function t(n){function e(t){return new jx(t,n)}return e.tension=function(n){return t(+n)},e}(0);function Xx(t,n){this._context=t,this._k=(1-n)/6}Xx.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:Bx(this,t,n)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var Gx=function t(n){function e(t){return new Xx(t,n)}return e.tension=function(n){return t(+n)},e}(0);function Vx(t,n,e){var r=t._x1,i=t._y1,o=t._x2,a=t._y2;if(t._l01_a>Tm){var u=2*t._l01_2a+3*t._l01_a*t._l12_a+t._l12_2a,c=3*t._l01_a*(t._l01_a+t._l12_a);r=(r*u-t._x0*t._l12_2a+t._x2*t._l01_2a)/c,i=(i*u-t._y0*t._l12_2a+t._y2*t._l01_2a)/c}if(t._l23_a>Tm){var f=2*t._l23_2a+3*t._l23_a*t._l12_a+t._l12_2a,s=3*t._l23_a*(t._l23_a+t._l12_a);o=(o*f+t._x1*t._l23_2a-n*t._l12_2a)/s,a=(a*f+t._y1*t._l23_2a-e*t._l12_2a)/s}t._context.bezierCurveTo(r,i,o,a,t._x2,t._y2)}function Wx(t,n){this._context=t,this._alpha=n}Wx.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:this.point(this._x2,this._y2)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){if(t=+t,n=+n,this._point){var e=this._x2-t,r=this._y2-n;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(e*e+r*r,this._alpha))}switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2;break;case 2:this._point=3;default:Vx(this,t,n)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var Zx=function t(n){function e(t){return n?new Wx(t,n):new Yx(t,0)}return e.alpha=function(n){return t(+n)},e}(.5);function Kx(t,n){this._context=t,this._alpha=n}Kx.prototype={areaStart:Dx,areaEnd:Dx,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x3,this._y3),this._context.closePath();break;case 2:this._context.lineTo(this._x3,this._y3),this._context.closePath();break;case 3:this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5)}},point:function(t,n){if(t=+t,n=+n,this._point){var e=this._x2-t,r=this._y2-n;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(e*e+r*r,this._alpha))}switch(this._point){case 0:this._point=1,this._x3=t,this._y3=n;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=n);break;case 2:this._point=3,this._x5=t,this._y5=n;break;default:Vx(this,t,n)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var Qx=function t(n){function e(t){return n?new Kx(t,n):new jx(t,0)}return e.alpha=function(n){return t(+n)},e}(.5);function Jx(t,n){this._context=t,this._alpha=n}Jx.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,n){if(t=+t,n=+n,this._point){var e=this._x2-t,r=this._y2-n;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(e*e+r*r,this._alpha))}switch(this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:Vx(this,t,n)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=n}};var tw=function t(n){function e(t){return n?new Jx(t,n):new Xx(t,0)}return e.alpha=function(n){return t(+n)},e}(.5);function nw(t){this._context=t}function ew(t){return t<0?-1:1}function rw(t,n,e){var r=t._x1-t._x0,i=n-t._x1,o=(t._y1-t._y0)/(r||i<0&&-0),a=(e-t._y1)/(i||r<0&&-0),u=(o*i+a*r)/(r+i);return(ew(o)+ew(a))*Math.min(Math.abs(o),Math.abs(a),.5*Math.abs(u))||0}function iw(t,n){var e=t._x1-t._x0;return e?(3*(t._y1-t._y0)/e-n)/2:n}function ow(t,n,e){var r=t._x0,i=t._y0,o=t._x1,a=t._y1,u=(o-r)/3;t._context.bezierCurveTo(r+u,i+u*n,o-u,a-u*e,o,a)}function aw(t){this._context=t}function uw(t){this._context=new cw(t)}function cw(t){this._context=t}function fw(t){this._context=t}function sw(t){var n,e,r=t.length-1,i=new Array(r),o=new Array(r),a=new Array(r);for(i[0]=0,o[0]=2,a[0]=t[0]+2*t[1],n=1;n=0;--n)i[n]=(a[n]-i[n+1])/o[n];for(o[r-1]=(t[r]+i[r-1])/2,n=0;n1)for(var e,r,i,o=1,a=t[n[0]],u=a.length;o=0;)e[n]=n;return e}function pw(t,n){return t[n]}function gw(t){const n=[];return n.key=t,n}function yw(t){var n=t.map(vw);return dw(t).sort((function(t,e){return n[t]-n[e]}))}function vw(t){for(var n,e=-1,r=0,i=t.length,o=-1/0;++eo&&(o=n,r=e);return r}function _w(t){var n=t.map(bw);return dw(t).sort((function(t,e){return n[t]-n[e]}))}function bw(t){for(var n,e=0,r=-1,i=t.length;++r=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(t,n){switch(t=+t,n=+n,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,n):this._context.moveTo(t,n);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,n),this._context.lineTo(t,n);else{var e=this._x*(1-this._t)+t*this._t;this._context.lineTo(e,this._y),this._context.lineTo(e,n)}}this._x=t,this._y=n}};var mw=t=>()=>t;function xw(t,{sourceEvent:n,target:e,transform:r,dispatch:i}){Object.defineProperties(this,{type:{value:t,enumerable:!0,configurable:!0},sourceEvent:{value:n,enumerable:!0,configurable:!0},target:{value:e,enumerable:!0,configurable:!0},transform:{value:r,enumerable:!0,configurable:!0},_:{value:i}})}function ww(t,n,e){this.k=t,this.x=n,this.y=e}ww.prototype={constructor:ww,scale:function(t){return 1===t?this:new ww(this.k*t,this.x,this.y)},translate:function(t,n){return 0===t&0===n?this:new ww(this.k,this.x+this.k*t,this.y+this.k*n)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Mw=new ww(1,0,0);function Tw(t){for(;!t.__zoom;)if(!(t=t.parentNode))return Mw;return t.__zoom}function Aw(t){t.stopImmediatePropagation()}function Sw(t){t.preventDefault(),t.stopImmediatePropagation()}function Ew(t){return!(t.ctrlKey&&"wheel"!==t.type||t.button)}function Nw(){var t=this;return t instanceof SVGElement?(t=t.ownerSVGElement||t).hasAttribute("viewBox")?[[(t=t.viewBox.baseVal).x,t.y],[t.x+t.width,t.y+t.height]]:[[0,0],[t.width.baseVal.value,t.height.baseVal.value]]:[[0,0],[t.clientWidth,t.clientHeight]]}function kw(){return this.__zoom||Mw}function Cw(t){return-t.deltaY*(1===t.deltaMode?.05:t.deltaMode?1:.002)*(t.ctrlKey?10:1)}function Pw(){return navigator.maxTouchPoints||"ontouchstart"in this}function zw(t,n,e){var r=t.invertX(n[0][0])-e[0][0],i=t.invertX(n[1][0])-e[1][0],o=t.invertY(n[0][1])-e[0][1],a=t.invertY(n[1][1])-e[1][1];return t.translate(i>r?(r+i)/2:Math.min(0,r)||Math.max(0,i),a>o?(o+a)/2:Math.min(0,o)||Math.max(0,a))}Tw.prototype=ww.prototype,t.Adder=A,t.Delaunay=ju,t.FormatSpecifier=nf,t.InternMap=InternMap,t.InternSet=InternSet,t.Node=Jd,t.Path=Ia,t.Voronoi=Uu,t.ZoomTransform=ww,t.active=function(t,n){var e,r,i=t.__transition;if(i)for(r in n=null==n?null:n+"",i)if((e=i[r]).state>Ui&&e.name===n)return new go([[t]],Ko,n,+r);return null},t.arc=function(){var t=Cm,n=Pm,e=ym(0),r=null,i=zm,o=$m,a=Dm,u=null,c=km(f);function f(){var f,s,l=+t.apply(this,arguments),h=+n.apply(this,arguments),d=i.apply(this,arguments)-Sm,p=o.apply(this,arguments)-Sm,g=vm(p-d),y=p>d;if(u||(u=f=c()),hTm)if(g>Em-Tm)u.moveTo(h*bm(d),h*wm(d)),u.arc(0,0,h,d,p,!y),l>Tm&&(u.moveTo(l*bm(p),l*wm(p)),u.arc(0,0,l,p,d,y));else{var v,_,b=d,m=p,x=d,w=p,M=g,T=g,A=a.apply(this,arguments)/2,S=A>Tm&&(r?+r.apply(this,arguments):Mm(l*l+h*h)),E=xm(vm(h-l)/2,+e.apply(this,arguments)),N=E,k=E;if(S>Tm){var C=Nm(S/l*wm(A)),P=Nm(S/h*wm(A));(M-=2*C)>Tm?(x+=C*=y?1:-1,w-=C):(M=0,x=w=(d+p)/2),(T-=2*P)>Tm?(b+=P*=y?1:-1,m-=P):(T=0,b=m=(d+p)/2)}var z=h*bm(b),$=h*wm(b),D=l*bm(w),R=l*wm(w);if(E>Tm){var F,q=h*bm(m),U=h*wm(m),I=l*bm(x),O=l*wm(x);if(g1?0:t<-1?Am:Math.acos(t)}((B*L+Y*j)/(Mm(B*B+Y*Y)*Mm(L*L+j*j)))/2),X=Mm(F[0]*F[0]+F[1]*F[1]);N=xm(E,(l-X)/(H-1)),k=xm(E,(h-X)/(H+1))}else N=k=0}T>Tm?k>Tm?(v=Rm(I,O,z,$,h,k,y),_=Rm(q,U,D,R,h,k,y),u.moveTo(v.cx+v.x01,v.cy+v.y01),kTm&&M>Tm?N>Tm?(v=Rm(D,R,q,U,l,-N,y),_=Rm(z,$,I,O,l,-N,y),u.lineTo(v.cx+v.x01,v.cy+v.y01),N=0))throw new RangeError("invalid r");let e=t.length;if(!((e=Math.floor(e))>=0))throw new RangeError("invalid length");if(!e||!n)return t;const r=v(n),i=t.slice();return r(t,i,0,e,1),r(i,t,0,e,1),r(t,i,0,e,1),t},t.blur2=h,t.blurImage=d,t.brush=function(){return Ma(ha)},t.brushSelection=function(t){var n=t.__brush;return n?n.dim.output(n.selection):null},t.brushX=function(){return Ma(sa)},t.brushY=function(){return Ma(la)},t.buffer=function(t,n){return fetch(t,n).then(bc)},t.chord=function(){return $a(!1,!1)},t.chordDirected=function(){return $a(!0,!1)},t.chordTranspose=function(){return $a(!1,!0)},t.cluster=function(){var t=jd,n=1,e=1,r=!1;function i(i){var o,a=0;i.eachAfter((function(n){var e=n.children;e?(n.x=function(t){return t.reduce(Hd,0)/t.length}(e),n.y=function(t){return 1+t.reduce(Xd,0)}(e)):(n.x=o?a+=t(n,o):0,n.y=0,o=n)}));var u=function(t){for(var n;n=t.children;)t=n[0];return t}(i),c=function(t){for(var n;n=t.children;)t=n[n.length-1];return t}(i),f=u.x-t(u,c)/2,s=c.x+t(c,u)/2;return i.eachAfter(r?function(t){t.x=(t.x-i.x)*n,t.y=(i.y-t.y)*e}:function(t){t.x=(t.x-f)/(s-f)*n,t.y=(1-(i.y?t.y/i.y:1))*e})}return i.separation=function(n){return arguments.length?(t=n,i):t},i.size=function(t){return arguments.length?(r=!1,n=+t[0],e=+t[1],i):r?null:[n,e]},i.nodeSize=function(t){return arguments.length?(r=!0,n=+t[0],e=+t[1],i):r?[n,e]:null},i},t.color=$e,t.contourDensity=function(){var t=su,n=lu,e=hu,r=960,i=500,o=20,a=2,u=3*o,c=r+2*u>>a,f=i+2*u>>a,s=Ja(20);function l(r){var i=new Float32Array(c*f),s=Math.pow(2,-a),l=-1;for(const o of r){var d=(t(o,++l,r)+u)*s,p=(n(o,l,r)+u)*s,g=+e(o,l,r);if(g&&d>=0&&d=0&&pt*r)))(n).map(((t,n)=>(t.value=+e[n],p(t))))}function p(t){return t.coordinates.forEach(g),t}function g(t){t.forEach(y)}function y(t){t.forEach(v)}function v(t){t[0]=t[0]*Math.pow(2,a)-u,t[1]=t[1]*Math.pow(2,a)-u}function _(){return c=r+2*(u=3*o)>>a,f=i+2*u>>a,d}return d.contours=function(t){var n=l(t),e=ou().size([c,f]),r=Math.pow(2,2*a),i=t=>{t=+t;var i=p(e.contour(n,t*r));return i.value=t,i};return Object.defineProperty(i,"max",{get:()=>tt(n)/r}),i},d.x=function(n){return arguments.length?(t="function"==typeof n?n:Ja(+n),d):t},d.y=function(t){return arguments.length?(n="function"==typeof t?t:Ja(+t),d):n},d.weight=function(t){return arguments.length?(e="function"==typeof t?t:Ja(+t),d):e},d.size=function(t){if(!arguments.length)return[r,i];var n=+t[0],e=+t[1];if(!(n>=0&&e>=0))throw new Error("invalid size");return r=n,i=e,_()},d.cellSize=function(t){if(!arguments.length)return 1<=1))throw new Error("invalid cell size");return a=Math.floor(Math.log(t)/Math.LN2),_()},d.thresholds=function(t){return arguments.length?(s="function"==typeof t?t:Array.isArray(t)?Ja(Ka.call(t)):Ja(t),d):s},d.bandwidth=function(t){if(!arguments.length)return Math.sqrt(o*(o+1));if(!((t=+t)>=0))throw new Error("invalid bandwidth");return o=(Math.sqrt(4*t*t+1)-1)/2,_()},d},t.contours=ou,t.count=_,t.create=function(t){return Kn(Lt(t).call(document.documentElement))},t.creator=Lt,t.cross=function(...t){const n="function"==typeof t[t.length-1]&&function(t){return n=>t(...n)}(t.pop()),e=(t=t.map(x)).map(b),r=t.length-1,i=new Array(r+1).fill(0),o=[];if(r<0||e.some(m))return o;for(;;){o.push(i.map(((n,e)=>t[e][n])));let a=r;for(;++i[a]===e[a];){if(0===a)return n?o.map(n):o;i[a--]=0}}},t.csv=Mc,t.csvFormat=ic,t.csvFormatBody=oc,t.csvFormatRow=uc,t.csvFormatRows=ac,t.csvFormatValue=cc,t.csvParse=ec,t.csvParseRows=rc,t.cubehelix=Ar,t.cumsum=function(t,n){var e=0,r=0;return Float64Array.from(t,void 0===n?t=>e+=+t||0:i=>e+=+n(i,r++,t)||0)},t.curveBasis=function(t){return new Fx(t)},t.curveBasisClosed=function(t){return new qx(t)},t.curveBasisOpen=function(t){return new Ux(t)},t.curveBumpX=nx,t.curveBumpY=ex,t.curveBundle=Ox,t.curveCardinal=Lx,t.curveCardinalClosed=Hx,t.curveCardinalOpen=Gx,t.curveCatmullRom=Zx,t.curveCatmullRomClosed=Qx,t.curveCatmullRomOpen=tw,t.curveLinear=Im,t.curveLinearClosed=function(t){return new nw(t)},t.curveMonotoneX=function(t){return new aw(t)},t.curveMonotoneY=function(t){return new uw(t)},t.curveNatural=function(t){return new fw(t)},t.curveStep=function(t){return new lw(t,.5)},t.curveStepAfter=function(t){return new lw(t,1)},t.curveStepBefore=function(t){return new lw(t,0)},t.descending=e,t.deviation=M,t.difference=function(t,...n){t=new InternSet(t);for(const e of n)for(const n of e)t.delete(n);return t},t.disjoint=function(t,n){const e=n[Symbol.iterator](),r=new InternSet;for(const n of t){if(r.has(n))return!1;let t,i;for(;({value:t,done:i}=e.next())&&!i;){if(Object.is(n,t))return!1;r.add(t)}}return!0},t.dispatch=Dt,t.drag=function(){var t,n,e,r,i=le,o=he,a=de,u=pe,c={},f=Dt("start","drag","end"),s=0,l=0;function h(t){t.on("mousedown.drag",d).filter(u).on("touchstart.drag",y).on("touchmove.drag",v,re).on("touchend.drag touchcancel.drag",_).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function d(a,u){if(!r&&i.call(this,a,u)){var c=b(this,o.call(this,a,u),a,u,"mouse");c&&(Kn(a.view).on("mousemove.drag",p,ie).on("mouseup.drag",g,ie),ue(a.view),oe(a),e=!1,t=a.clientX,n=a.clientY,c("start",a))}}function p(r){if(ae(r),!e){var i=r.clientX-t,o=r.clientY-n;e=i*i+o*o>l}c.mouse("drag",r)}function g(t){Kn(t.view).on("mousemove.drag mouseup.drag",null),ce(t.view,e),ae(t),c.mouse("end",t)}function y(t,n){if(i.call(this,t,n)){var e,r,a=t.changedTouches,u=o.call(this,t,n),c=a.length;for(e=0;e+t,t.easePoly=Mo,t.easePolyIn=xo,t.easePolyInOut=Mo,t.easePolyOut=wo,t.easeQuad=bo,t.easeQuadIn=function(t){return t*t},t.easeQuadInOut=bo,t.easeQuadOut=function(t){return t*(2-t)},t.easeSin=So,t.easeSinIn=function(t){return 1==+t?1:1-Math.cos(t*Ao)},t.easeSinInOut=So,t.easeSinOut=function(t){return Math.sin(t*Ao)},t.every=function(t,n){if("function"!=typeof n)throw new TypeError("test is not a function");let e=-1;for(const r of t)if(!n(r,++e,t))return!1;return!0},t.extent=T,t.fcumsum=function(t,n){const e=new A;let r=-1;return Float64Array.from(t,void 0===n?t=>e.add(+t||0):i=>e.add(+n(i,++r,t)||0))},t.filter=function(t,n){if("function"!=typeof n)throw new TypeError("test is not a function");const e=[];let r=-1;for(const i of t)n(i,++r,t)&&e.push(i);return e},t.flatGroup=function(t,...n){return $(z(t,...n),n)},t.flatRollup=function(t,n,...e){return $(R(t,n,...e),e)},t.forceCenter=function(t,n){var e,r=1;function i(){var i,o,a=e.length,u=0,c=0;for(i=0;if+p||os+p||ac.index){var g=f-u.x-u.vx,y=s-u.y-u.vy,v=g*g+y*y;vt.r&&(t.r=t[n].r)}function c(){if(n){var r,i,o=n.length;for(e=new Array(o),r=0;r[u(t,n,r),t])));for(a=0,i=new Array(f);a=u)){(t.data!==n||t.next)&&(0===l&&(p+=(l=Ic(e))*l),0===h&&(p+=(h=Ic(e))*h),p(t=(jc*t+Hc)%Xc)/Xc}();function l(){h(),f.call("tick",n),e1?(null==e?u.delete(t):u.set(t,p(e)),n):u.get(t)},find:function(n,e,r){var i,o,a,u,c,f=0,s=t.length;for(null==r?r=1/0:r*=r,f=0;f1?(f.on(t,e),n):f.on(t)}}},t.forceX=function(t){var n,e,r,i=Uc(.1);function o(t){for(var i,o=0,a=n.length;o=.12&&i<.234&&r>=-.425&&r<-.214?u:i>=.166&&i<.234&&r>=-.214&&r<-.115?c:a).invert(t)},s.stream=function(e){return t&&n===e?t:(r=[a.stream(n=e),u.stream(e),c.stream(e)],i=r.length,t={point:function(t,n){for(var e=-1;++eHs(r[0],r[1])&&(r[1]=i[1]),Hs(i[0],r[1])>Hs(r[0],r[1])&&(r[0]=i[0])):o.push(r=i);for(a=-1/0,n=0,r=o[e=o.length-1];n<=e;r=i,++n)i=o[n],(u=Hs(r[1],i[0]))>a&&(a=u,Zf=i[0],Qf=r[1])}return os=as=null,Zf===1/0||Kf===1/0?[[NaN,NaN],[NaN,NaN]]:[[Zf,Kf],[Qf,Jf]]},t.geoCentroid=function(t){xs=ws=Ms=Ts=As=Ss=Es=Ns=0,ks=new A,Cs=new A,Ps=new A,jf(t,Vs);var n=+ks,e=+Cs,r=+Ps,i=Nf(n,e,r);return i=0))throw new RangeError(`invalid digits: ${t}`);i=n}return null===n&&(r=new rd(i)),a},a.projection(t).digits(i).context(n)},t.geoProjection=vd,t.geoProjectionMutator=_d,t.geoRotation=hl,t.geoStereographic=function(){return vd(Yd).scale(250).clipAngle(142)},t.geoStereographicRaw=Yd,t.geoStream=jf,t.geoTransform=function(t){return{stream:od(t)}},t.geoTransverseMercator=function(){var t=Nd(Ld),n=t.center,e=t.rotate;return t.center=function(t){return arguments.length?n([-t[1],t[0]]):[(t=n())[1],-t[0]]},t.rotate=function(t){return arguments.length?e([t[0],t[1],t.length>2?t[2]+90:90]):[(t=e())[0],t[1],t[2]-90]},e([0,0,90]).scale(159.155)},t.geoTransverseMercatorRaw=Ld,t.gray=function(t,n){return new cr(t,0,0,null==n?1:n)},t.greatest=at,t.greatestIndex=function(t,e=n){if(1===e.length)return nt(t,e);let r,i=-1,o=-1;for(const n of t)++o,(i<0?0===e(n,n):e(n,r)>0)&&(r=n,i=o);return i},t.group=P,t.groupSort=function(t,e,r){return(2!==e.length?I(D(t,e,r),(([t,e],[r,i])=>n(e,i)||n(t,r))):I(P(t,r),(([t,r],[i,o])=>e(r,o)||n(t,i)))).map((([t])=>t))},t.groups=z,t.hcl=pr,t.hierarchy=Vd,t.histogram=J,t.hsl=Xe,t.html=Nc,t.image=function(t,n){return new Promise((function(e,r){var i=new Image;for(var o in n)i[o]=n[o];i.onerror=r,i.onload=function(){e(i)},i.src=t}))},t.index=function(t,...n){return q(t,C,F,n)},t.indexes=function(t,...n){return q(t,Array.from,F,n)},t.interpolate=Vr,t.interpolateArray=function(t,n){return(Or(n)?Ir:Br)(t,n)},t.interpolateBasis=Nr,t.interpolateBasisClosed=kr,t.interpolateBlues=Gb,t.interpolateBrBG=ob,t.interpolateBuGn=Mb,t.interpolateBuPu=Ab,t.interpolateCividis=function(t){return t=Math.max(0,Math.min(1,t)),"rgb("+Math.max(0,Math.min(255,Math.round(-4.54-t*(35.34-t*(2381.73-t*(6402.7-t*(7024.72-2710.57*t)))))))+", "+Math.max(0,Math.min(255,Math.round(32.49+t*(170.73+t*(52.82-t*(131.46-t*(176.58-67.37*t)))))))+", "+Math.max(0,Math.min(255,Math.round(81.24+t*(442.36-t*(2482.43-t*(6167.24-t*(6614.94-2475.67*t)))))))+")"},t.interpolateCool=am,t.interpolateCubehelix=hi,t.interpolateCubehelixDefault=im,t.interpolateCubehelixLong=di,t.interpolateDate=Yr,t.interpolateDiscrete=function(t){var n=t.length;return function(e){return t[Math.max(0,Math.min(n-1,Math.floor(e*n)))]}},t.interpolateGnBu=Eb,t.interpolateGreens=Wb,t.interpolateGreys=Kb,t.interpolateHcl=fi,t.interpolateHclLong=si,t.interpolateHsl=ai,t.interpolateHslLong=ui,t.interpolateHue=function(t,n){var e=zr(+t,+n);return function(t){var n=e(t);return n-360*Math.floor(n/360)}},t.interpolateInferno=pm,t.interpolateLab=function(t,n){var e=Dr((t=ur(t)).l,(n=ur(n)).l),r=Dr(t.a,n.a),i=Dr(t.b,n.b),o=Dr(t.opacity,n.opacity);return function(n){return t.l=e(n),t.a=r(n),t.b=i(n),t.opacity=o(n),t+""}},t.interpolateMagma=dm,t.interpolateNumber=Lr,t.interpolateNumberArray=Ir,t.interpolateObject=jr,t.interpolateOrRd=kb,t.interpolateOranges=rm,t.interpolatePRGn=ub,t.interpolatePiYG=fb,t.interpolatePlasma=gm,t.interpolatePuBu=$b,t.interpolatePuBuGn=Pb,t.interpolatePuOr=lb,t.interpolatePuRd=Rb,t.interpolatePurples=Jb,t.interpolateRainbow=function(t){(t<0||t>1)&&(t-=Math.floor(t));var n=Math.abs(t-.5);return um.h=360*t-100,um.s=1.5-1.5*n,um.l=.8-.9*n,um+""},t.interpolateRdBu=db,t.interpolateRdGy=gb,t.interpolateRdPu=qb,t.interpolateRdYlBu=vb,t.interpolateRdYlGn=bb,t.interpolateReds=nm,t.interpolateRgb=Rr,t.interpolateRgbBasis=qr,t.interpolateRgbBasisClosed=Ur,t.interpolateRound=Wr,t.interpolateSinebow=function(t){var n;return t=(.5-t)*Math.PI,cm.r=255*(n=Math.sin(t))*n,cm.g=255*(n=Math.sin(t+fm))*n,cm.b=255*(n=Math.sin(t+sm))*n,cm+""},t.interpolateSpectral=xb,t.interpolateString=Gr,t.interpolateTransformCss=ni,t.interpolateTransformSvg=ei,t.interpolateTurbo=function(t){return t=Math.max(0,Math.min(1,t)),"rgb("+Math.max(0,Math.min(255,Math.round(34.61+t*(1172.33-t*(10793.56-t*(33300.12-t*(38394.49-14825.05*t)))))))+", "+Math.max(0,Math.min(255,Math.round(23.31+t*(557.33+t*(1225.33-t*(3574.96-t*(1073.77+707.56*t)))))))+", "+Math.max(0,Math.min(255,Math.round(27.2+t*(3211.1-t*(15327.97-t*(27814-t*(22569.18-6838.66*t)))))))+")"},t.interpolateViridis=hm,t.interpolateWarm=om,t.interpolateYlGn=Bb,t.interpolateYlGnBu=Ib,t.interpolateYlOrBr=Lb,t.interpolateYlOrRd=Hb,t.interpolateZoom=ii,t.interrupt=Vi,t.intersection=function(t,...n){t=new InternSet(t),n=n.map(_t);t:for(const e of t)for(const r of n)if(!r.has(e)){t.delete(e);continue t}return t},t.interval=function(t,n,e){var r=new Ni,i=n;return null==n?(r.restart(t,n,e),r):(r._restart=r.restart,r.restart=function(t,n,e){n=+n,e=null==e?Si():+e,r._restart((function o(a){a+=i,r._restart(o,i+=n,e),t(a)}),n,e)},r.restart(t,n,e),r)},t.isoFormat=R_,t.isoParse=q_,t.json=function(t,n){return fetch(t,n).then(Ac)},t.lab=ur,t.lch=function(t,n,e,r){return 1===arguments.length?dr(t):new gr(e,n,t,null==r?1:r)},t.least=function(t,e=n){let r,i=!1;if(1===e.length){let o;for(const a of t){const t=e(a);(i?n(t,o)<0:0===n(t,t))&&(r=a,o=t,i=!0)}}else for(const n of t)(i?e(n,r)<0:0===e(n,n))&&(r=n,i=!0);return r},t.leastIndex=dt,t.line=Ym,t.lineRadial=Zm,t.link=ax,t.linkHorizontal=function(){return ax(nx)},t.linkRadial=function(){const t=ax(rx);return t.angle=t.x,delete t.x,t.radius=t.y,delete t.y,t},t.linkVertical=function(){return ax(ex)},t.local=Jn,t.map=function(t,n){if("function"!=typeof t[Symbol.iterator])throw new TypeError("values is not iterable");if("function"!=typeof n)throw new TypeError("mapper is not a function");return Array.from(t,((e,r)=>n(e,r,t)))},t.matcher=Wt,t.max=tt,t.maxIndex=nt,t.mean=function(t,n){let e=0,r=0;if(void 0===n)for(let n of t)null!=n&&(n=+n)>=n&&(++e,r+=n);else{let i=-1;for(let o of t)null!=(o=n(o,++i,t))&&(o=+o)>=o&&(++e,r+=o)}if(e)return r/e},t.median=function(t,n){return ut(t,.5,n)},t.medianIndex=function(t,n){return ft(t,.5,n)},t.merge=st,t.min=et,t.minIndex=rt,t.mode=function(t,n){const e=new InternMap;if(void 0===n)for(let n of t)null!=n&&n>=n&&e.set(n,(e.get(n)||0)+1);else{let r=-1;for(let i of t)null!=(i=n(i,++r,t))&&i>=i&&e.set(i,(e.get(i)||0)+1)}let r,i=0;for(const[t,n]of e)n>i&&(i=n,r=t);return r},t.namespace=Ot,t.namespaces=It,t.nice=K,t.now=Si,t.pack=function(){var t=null,n=1,e=1,r=ep;function i(i){const o=up();return i.x=n/2,i.y=e/2,t?i.eachBefore(wp(t)).eachAfter(Mp(r,.5,o)).eachBefore(Tp(1)):i.eachBefore(wp(xp)).eachAfter(Mp(ep,1,o)).eachAfter(Mp(r,i.r/Math.min(n,e),o)).eachBefore(Tp(Math.min(n,e)/(2*i.r))),i}return i.radius=function(n){return arguments.length?(t=tp(n),i):t},i.size=function(t){return arguments.length?(n=+t[0],e=+t[1],i):[n,e]},i.padding=function(t){return arguments.length?(r="function"==typeof t?t:rp(+t),i):r},i},t.packEnclose=function(t){return cp(t,up())},t.packSiblings=function(t){return mp(t,up()),t},t.pairs=function(t,n=lt){const e=[];let r,i=!1;for(const o of t)i&&e.push(n(r,o)),r=o,i=!0;return e},t.partition=function(){var t=1,n=1,e=0,r=!1;function i(i){var o=i.height+1;return i.x0=i.y0=e,i.x1=t,i.y1=n/o,i.eachBefore(function(t,n){return function(r){r.children&&Sp(r,r.x0,t*(r.depth+1)/n,r.x1,t*(r.depth+2)/n);var i=r.x0,o=r.y0,a=r.x1-e,u=r.y1-e;a0&&(d+=l);for(null!=n?p.sort((function(t,e){return n(g[t],g[e])})):null!=e&&p.sort((function(t,n){return e(a[t],a[n])})),u=0,f=d?(v-h*b)/d:0;u0?l*f:0)+b,g[c]={data:a[c],index:u,value:l,startAngle:y,endAngle:s,padAngle:_};return g}return a.value=function(n){return arguments.length?(t="function"==typeof n?n:ym(+n),a):t},a.sortValues=function(t){return arguments.length?(n=t,e=null,a):n},a.sort=function(t){return arguments.length?(e=t,n=null,a):e},a.startAngle=function(t){return arguments.length?(r="function"==typeof t?t:ym(+t),a):r},a.endAngle=function(t){return arguments.length?(i="function"==typeof t?t:ym(+t),a):i},a.padAngle=function(t){return arguments.length?(o="function"==typeof t?t:ym(+t),a):o},a},t.piecewise=pi,t.pointRadial=Qm,t.pointer=ee,t.pointers=function(t,n){return t.target&&(t=ne(t),void 0===n&&(n=t.currentTarget),t=t.touches||[t]),Array.from(t,(t=>ee(t,n)))},t.polygonArea=function(t){for(var n,e=-1,r=t.length,i=t[r-1],o=0;++eu!=f>u&&a<(c-e)*(u-r)/(f-r)+e&&(s=!s),c=e,f=r;return s},t.polygonHull=function(t){if((e=t.length)<3)return null;var n,e,r=new Array(e),i=new Array(e);for(n=0;n=0;--n)f.push(t[r[o[n]][2]]);for(n=+u;n(n=1664525*n+1013904223|0,hg*(n>>>0))},t.randomLogNormal=Qp,t.randomLogistic=sg,t.randomNormal=Kp,t.randomPareto=eg,t.randomPoisson=lg,t.randomUniform=Wp,t.randomWeibull=cg,t.range=ht,t.rank=function(t,e=n){if("function"!=typeof t[Symbol.iterator])throw new TypeError("values is not iterable");let r=Array.from(t);const i=new Float64Array(r.length);2!==e.length&&(r=r.map(e),e=n);const o=(t,n)=>e(r[t],r[n]);let a,u;return(t=Uint32Array.from(r,((t,n)=>n))).sort(e===n?(t,n)=>B(r[t],r[n]):O(o)),t.forEach(((t,n)=>{const e=o(t,void 0===a?t:a);e>=0?((void 0===a||e>0)&&(a=t,u=n),i[t]=u):i[t]=NaN})),i},t.reduce=function(t,n,e){if("function"!=typeof n)throw new TypeError("reducer is not a function");const r=t[Symbol.iterator]();let i,o,a=-1;if(arguments.length<3){if(({done:i,value:e}=r.next()),i)return;++a}for(;({done:i,value:o}=r.next()),!i;)e=n(e,o,++a,t);return e},t.reverse=function(t){if("function"!=typeof t[Symbol.iterator])throw new TypeError("values is not iterable");return Array.from(t).reverse()},t.rgb=qe,t.ribbon=function(){return Za()},t.ribbonArrow=function(){return Za(Wa)},t.rollup=D,t.rollups=R,t.scaleBand=vg,t.scaleDiverging=function t(){var n=kg(j_()(xg));return n.copy=function(){return Y_(n,t())},pg.apply(n,arguments)},t.scaleDivergingLog=function t(){var n=qg(j_()).domain([.1,1,10]);return n.copy=function(){return Y_(n,t()).base(n.base())},pg.apply(n,arguments)},t.scaleDivergingPow=H_,t.scaleDivergingSqrt=function(){return H_.apply(null,arguments).exponent(.5)},t.scaleDivergingSymlog=function t(){var n=Og(j_());return n.copy=function(){return Y_(n,t()).constant(n.constant())},pg.apply(n,arguments)},t.scaleIdentity=function t(n){var e;function r(t){return null==t||isNaN(t=+t)?e:t}return r.invert=r,r.domain=r.range=function(t){return arguments.length?(n=Array.from(t,bg),r):n.slice()},r.unknown=function(t){return arguments.length?(e=t,r):e},r.copy=function(){return t(n).unknown(e)},n=arguments.length?Array.from(n,bg):[0,1],kg(r)},t.scaleImplicit=gg,t.scaleLinear=function t(){var n=Eg();return n.copy=function(){return Ag(n,t())},dg.apply(n,arguments),kg(n)},t.scaleLog=function t(){const n=qg(Sg()).domain([1,10]);return n.copy=()=>Ag(n,t()).base(n.base()),dg.apply(n,arguments),n},t.scaleOrdinal=yg,t.scalePoint=function(){return _g(vg.apply(null,arguments).paddingInner(1))},t.scalePow=Hg,t.scaleQuantile=function t(){var e,r=[],i=[],o=[];function a(){var t=0,n=Math.max(1,i.length);for(o=new Array(n-1);++t0?o[n-1]:r[0],n=i?[o[i-1],r]:[o[n-1],o[n]]},u.unknown=function(t){return arguments.length?(n=t,u):u},u.thresholds=function(){return o.slice()},u.copy=function(){return t().domain([e,r]).range(a).unknown(n)},dg.apply(kg(u),arguments)},t.scaleRadial=function t(){var n,e=Eg(),r=[0,1],i=!1;function o(t){var r=function(t){return Math.sign(t)*Math.sqrt(Math.abs(t))}(e(t));return isNaN(r)?n:i?Math.round(r):r}return o.invert=function(t){return e.invert(Xg(t))},o.domain=function(t){return arguments.length?(e.domain(t),o):e.domain()},o.range=function(t){return arguments.length?(e.range((r=Array.from(t,bg)).map(Xg)),o):r.slice()},o.rangeRound=function(t){return o.range(t).round(!0)},o.round=function(t){return arguments.length?(i=!!t,o):i},o.clamp=function(t){return arguments.length?(e.clamp(t),o):e.clamp()},o.unknown=function(t){return arguments.length?(n=t,o):n},o.copy=function(){return t(e.domain(),r).round(i).clamp(e.clamp()).unknown(n)},dg.apply(o,arguments),kg(o)},t.scaleSequential=function t(){var n=kg(B_()(xg));return n.copy=function(){return Y_(n,t())},pg.apply(n,arguments)},t.scaleSequentialLog=function t(){var n=qg(B_()).domain([1,10]);return n.copy=function(){return Y_(n,t()).base(n.base())},pg.apply(n,arguments)},t.scaleSequentialPow=L_,t.scaleSequentialQuantile=function t(){var e=[],r=xg;function i(t){if(null!=t&&!isNaN(t=+t))return r((l(e,t,1)-1)/(e.length-1))}return i.domain=function(t){if(!arguments.length)return e.slice();e=[];for(let n of t)null==n||isNaN(n=+n)||e.push(n);return e.sort(n),i},i.interpolator=function(t){return arguments.length?(r=t,i):r},i.range=function(){return e.map(((t,n)=>r(n/(e.length-1))))},i.quantiles=function(t){return Array.from({length:t+1},((n,r)=>ut(e,r/t)))},i.copy=function(){return t(r).domain(e)},pg.apply(i,arguments)},t.scaleSequentialSqrt=function(){return L_.apply(null,arguments).exponent(.5)},t.scaleSequentialSymlog=function t(){var n=Og(B_());return n.copy=function(){return Y_(n,t()).constant(n.constant())},pg.apply(n,arguments)},t.scaleSqrt=function(){return Hg.apply(null,arguments).exponent(.5)},t.scaleSymlog=function t(){var n=Og(Sg());return n.copy=function(){return Ag(n,t()).constant(n.constant())},dg.apply(n,arguments)},t.scaleThreshold=function t(){var n,e=[.5],r=[0,1],i=1;function o(t){return null!=t&&t<=t?r[l(e,t,0,i)]:n}return o.domain=function(t){return arguments.length?(e=Array.from(t),i=Math.min(e.length,r.length-1),o):e.slice()},o.range=function(t){return arguments.length?(r=Array.from(t),i=Math.min(e.length,r.length-1),o):r.slice()},o.invertExtent=function(t){var n=r.indexOf(t);return[e[n-1],e[n]]},o.unknown=function(t){return arguments.length?(n=t,o):n},o.copy=function(){return t().domain(e).range(r).unknown(n)},dg.apply(o,arguments)},t.scaleTime=function(){return dg.apply(O_(cv,fv,nv,Ky,wy,gy,ly,uy,oy,t.timeFormat).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)},t.scaleUtc=function(){return dg.apply(O_(av,uv,rv,Jy,qy,vy,dy,fy,oy,t.utcFormat).domain([Date.UTC(2e3,0,1),Date.UTC(2e3,0,2)]),arguments)},t.scan=function(t,n){const e=dt(t,n);return e<0?void 0:e},t.schemeAccent=V_,t.schemeBlues=Xb,t.schemeBrBG=ib,t.schemeBuGn=wb,t.schemeBuPu=Tb,t.schemeCategory10=G_,t.schemeDark2=W_,t.schemeGnBu=Sb,t.schemeGreens=Vb,t.schemeGreys=Zb,t.schemeOrRd=Nb,t.schemeOranges=em,t.schemePRGn=ab,t.schemePaired=Z_,t.schemePastel1=K_,t.schemePastel2=Q_,t.schemePiYG=cb,t.schemePuBu=zb,t.schemePuBuGn=Cb,t.schemePuOr=sb,t.schemePuRd=Db,t.schemePurples=Qb,t.schemeRdBu=hb,t.schemeRdGy=pb,t.schemeRdPu=Fb,t.schemeRdYlBu=yb,t.schemeRdYlGn=_b,t.schemeReds=tm,t.schemeSet1=J_,t.schemeSet2=tb,t.schemeSet3=nb,t.schemeSpectral=mb,t.schemeTableau10=eb,t.schemeYlGn=Ob,t.schemeYlGnBu=Ub,t.schemeYlOrBr=Yb,t.schemeYlOrRd=jb,t.select=Kn,t.selectAll=function(t){return"string"==typeof t?new Wn([document.querySelectorAll(t)],[document.documentElement]):new Wn([Xt(t)],Vn)},t.selection=Zn,t.selector=Ht,t.selectorAll=Vt,t.shuffle=pt,t.shuffler=gt,t.some=function(t,n){if("function"!=typeof n)throw new TypeError("test is not a function");let e=-1;for(const r of t)if(n(r,++e,t))return!0;return!1},t.sort=I,t.stack=function(){var t=ym([]),n=dw,e=hw,r=pw;function i(i){var o,a,u=Array.from(t.apply(this,arguments),gw),c=u.length,f=-1;for(const t of i)for(o=0,++f;o0)for(var e,r,i,o,a,u,c=0,f=t[n[0]].length;c0?(r[0]=o,r[1]=o+=i):i<0?(r[1]=a,r[0]=a+=i):(r[0]=0,r[1]=i)},t.stackOffsetExpand=function(t,n){if((r=t.length)>0){for(var e,r,i,o=0,a=t[0].length;o0){for(var e,r=0,i=t[n[0]],o=i.length;r0&&(r=(e=t[n[0]]).length)>0){for(var e,r,i,o=0,a=1;afunction(t){t=`${t}`;let n=t.length;$p(t,n-1)&&!$p(t,n-2)&&(t=t.slice(0,-1));return"/"===t[0]?t:`/${t}`}(t(n,e,r)))),e=n.map(zp),i=new Set(n).add("");for(const t of e)i.has(t)||(i.add(t),n.push(t),e.push(zp(t)),h.push(kp));d=(t,e)=>n[e],p=(t,n)=>e[n]}for(a=0,i=h.length;a=0&&(f=h[t]).data===kp;--t)f.data=null}if(u.parent=Ep,u.eachBefore((function(t){t.depth=t.parent.depth+1,--i})).eachBefore(Qd),u.parent=null,i>0)throw new Error("cycle");return u}return r.id=function(t){return arguments.length?(n=tp(t),r):n},r.parentId=function(t){return arguments.length?(e=tp(t),r):e},r.path=function(n){return arguments.length?(t=tp(n),r):t},r},t.style=bn,t.subset=function(t,n){return bt(n,t)},t.sum=function(t,n){let e=0;if(void 0===n)for(let n of t)(n=+n)&&(e+=n);else{let r=-1;for(let i of t)(i=+n(i,++r,t))&&(e+=i)}return e},t.superset=bt,t.svg=kc,t.symbol=function(t,n){let e=null,r=km(i);function i(){let i;if(e||(e=i=r()),t.apply(this,arguments).draw(e,+n.apply(this,arguments)),i)return e=null,i+""||null}return t="function"==typeof t?t:ym(t||fx),n="function"==typeof n?n:ym(void 0===n?64:+n),i.type=function(n){return arguments.length?(t="function"==typeof n?n:ym(n),i):t},i.size=function(t){return arguments.length?(n="function"==typeof t?t:ym(+t),i):n},i.context=function(t){return arguments.length?(e=null==t?null:t,i):e},i},t.symbolAsterisk=cx,t.symbolCircle=fx,t.symbolCross=sx,t.symbolDiamond=dx,t.symbolDiamond2=px,t.symbolPlus=gx,t.symbolSquare=yx,t.symbolSquare2=vx,t.symbolStar=xx,t.symbolTimes=Px,t.symbolTriangle=Mx,t.symbolTriangle2=Ax,t.symbolWye=Cx,t.symbolX=Px,t.symbols=zx,t.symbolsFill=zx,t.symbolsStroke=$x,t.text=xc,t.thresholdFreedmanDiaconis=function(t,n,e){const r=_(t),i=ut(t,.75)-ut(t,.25);return r&&i?Math.ceil((e-n)/(2*i*Math.pow(r,-1/3))):1},t.thresholdScott=function(t,n,e){const r=_(t),i=M(t);return r&&i?Math.ceil((e-n)*Math.cbrt(r)/(3.49*i)):1},t.thresholdSturges=Q,t.tickFormat=Ng,t.tickIncrement=W,t.tickStep=Z,t.ticks=V,t.timeDay=gy,t.timeDays=yy,t.timeFormatDefaultLocale=z_,t.timeFormatLocale=dv,t.timeFriday=Ey,t.timeFridays=Dy,t.timeHour=ly,t.timeHours=hy,t.timeInterval=Wg,t.timeMillisecond=Zg,t.timeMilliseconds=Kg,t.timeMinute=uy,t.timeMinutes=cy,t.timeMonday=My,t.timeMondays=Cy,t.timeMonth=Ky,t.timeMonths=Qy,t.timeSaturday=Ny,t.timeSaturdays=Ry,t.timeSecond=oy,t.timeSeconds=ay,t.timeSunday=wy,t.timeSundays=ky,t.timeThursday=Sy,t.timeThursdays=$y,t.timeTickInterval=fv,t.timeTicks=cv,t.timeTuesday=Ty,t.timeTuesdays=Py,t.timeWednesday=Ay,t.timeWednesdays=zy,t.timeWeek=wy,t.timeWeeks=ky,t.timeYear=nv,t.timeYears=ev,t.timeout=Di,t.timer=ki,t.timerFlush=Ci,t.transition=yo,t.transpose=yt,t.tree=function(){var t=Dp,n=1,e=1,r=null;function i(i){var c=function(t){for(var n,e,r,i,o,a=new Ip(t,0),u=[a];n=u.pop();)if(r=n._.children)for(n.children=new Array(o=r.length),i=o-1;i>=0;--i)u.push(e=n.children[i]=new Ip(r[i],i)),e.parent=n;return(a.parent=new Ip(null,0)).children=[a],a}(i);if(c.eachAfter(o),c.parent.m=-c.z,c.eachBefore(a),r)i.eachBefore(u);else{var f=i,s=i,l=i;i.eachBefore((function(t){t.xs.x&&(s=t),t.depth>l.depth&&(l=t)}));var h=f===s?1:t(f,s)/2,d=h-f.x,p=n/(s.x+h+d),g=e/(l.depth||1);i.eachBefore((function(t){t.x=(t.x+d)*p,t.y=t.depth*g}))}return i}function o(n){var e=n.children,r=n.parent.children,i=n.i?r[n.i-1]:null;if(e){!function(t){for(var n,e=0,r=0,i=t.children,o=i.length;--o>=0;)(n=i[o]).z+=e,n.m+=e,e+=n.s+(r+=n.c)}(n);var o=(e[0].z+e[e.length-1].z)/2;i?(n.z=i.z+t(n._,i._),n.m=n.z-o):n.z=o}else i&&(n.z=i.z+t(n._,i._));n.parent.A=function(n,e,r){if(e){for(var i,o=n,a=n,u=e,c=o.parent.children[0],f=o.m,s=a.m,l=u.m,h=c.m;u=Fp(u),o=Rp(o),u&&o;)c=Rp(c),(a=Fp(a)).a=n,(i=u.z+l-o.z-f+t(u._,o._))>0&&(qp(Up(u,n,r),n,i),f+=i,s+=i),l+=u.m,f+=o.m,h+=c.m,s+=a.m;u&&!Fp(a)&&(a.t=u,a.m+=l-s),o&&!Rp(c)&&(c.t=o,c.m+=f-h,r=n)}return r}(n,i,n.parent.A||r[0])}function a(t){t._.x=t.z+t.parent.m,t.m+=t.parent.m}function u(t){t.x*=n,t.y=t.depth*e}return i.separation=function(n){return arguments.length?(t=n,i):t},i.size=function(t){return arguments.length?(r=!1,n=+t[0],e=+t[1],i):r?null:[n,e]},i.nodeSize=function(t){return arguments.length?(r=!0,n=+t[0],e=+t[1],i):r?[n,e]:null},i},t.treemap=function(){var t=Lp,n=!1,e=1,r=1,i=[0],o=ep,a=ep,u=ep,c=ep,f=ep;function s(t){return t.x0=t.y0=0,t.x1=e,t.y1=r,t.eachBefore(l),i=[0],n&&t.eachBefore(Ap),t}function l(n){var e=i[n.depth],r=n.x0+e,s=n.y0+e,l=n.x1-e,h=n.y1-e;l=e-1){var s=u[n];return s.x0=i,s.y0=o,s.x1=a,void(s.y1=c)}var l=f[n],h=r/2+l,d=n+1,p=e-1;for(;d>>1;f[g]c-o){var _=r?(i*v+a*y)/r:a;t(n,d,y,i,o,_,c),t(d,e,v,_,o,a,c)}else{var b=r?(o*v+c*y)/r:c;t(n,d,y,i,o,a,b),t(d,e,v,i,b,a,c)}}(0,c,t.value,n,e,r,i)},t.treemapDice=Sp,t.treemapResquarify=jp,t.treemapSlice=Op,t.treemapSliceDice=function(t,n,e,r,i){(1&t.depth?Op:Sp)(t,n,e,r,i)},t.treemapSquarify=Lp,t.tsv=Tc,t.tsvFormat=hc,t.tsvFormatBody=dc,t.tsvFormatRow=gc,t.tsvFormatRows=pc,t.tsvFormatValue=yc,t.tsvParse=sc,t.tsvParseRows=lc,t.union=function(...t){const n=new InternSet;for(const e of t)for(const t of e)n.add(t);return n},t.unixDay=by,t.unixDays=my,t.utcDay=vy,t.utcDays=_y,t.utcFriday=Yy,t.utcFridays=Wy,t.utcHour=dy,t.utcHours=py,t.utcMillisecond=Zg,t.utcMilliseconds=Kg,t.utcMinute=fy,t.utcMinutes=sy,t.utcMonday=Uy,t.utcMondays=Hy,t.utcMonth=Jy,t.utcMonths=tv,t.utcSaturday=Ly,t.utcSaturdays=Zy,t.utcSecond=oy,t.utcSeconds=ay,t.utcSunday=qy,t.utcSundays=jy,t.utcThursday=By,t.utcThursdays=Vy,t.utcTickInterval=uv,t.utcTicks=av,t.utcTuesday=Iy,t.utcTuesdays=Xy,t.utcWednesday=Oy,t.utcWednesdays=Gy,t.utcWeek=qy,t.utcWeeks=jy,t.utcYear=rv,t.utcYears=iv,t.variance=w,t.version="7.8.4",t.window=gn,t.xml=Ec,t.zip=function(){return yt(arguments)},t.zoom=function(){var t,n,e,r=Ew,i=Nw,o=zw,a=Cw,u=Pw,c=[0,1/0],f=[[-1/0,-1/0],[1/0,1/0]],s=250,l=ii,h=Dt("start","zoom","end"),d=500,p=150,g=0,y=10;function v(t){t.property("__zoom",kw).on("wheel.zoom",T,{passive:!1}).on("mousedown.zoom",A).on("dblclick.zoom",S).filter(u).on("touchstart.zoom",E).on("touchmove.zoom",N).on("touchend.zoom touchcancel.zoom",k).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function _(t,n){return(n=Math.max(c[0],Math.min(c[1],n)))===t.k?t:new ww(n,t.x,t.y)}function b(t,n,e){var r=n[0]-e[0]*t.k,i=n[1]-e[1]*t.k;return r===t.x&&i===t.y?t:new ww(t.k,r,i)}function m(t){return[(+t[0][0]+ +t[1][0])/2,(+t[0][1]+ +t[1][1])/2]}function x(t,n,e,r){t.on("start.zoom",(function(){w(this,arguments).event(r).start()})).on("interrupt.zoom end.zoom",(function(){w(this,arguments).event(r).end()})).tween("zoom",(function(){var t=this,o=arguments,a=w(t,o).event(r),u=i.apply(t,o),c=null==e?m(u):"function"==typeof e?e.apply(t,o):e,f=Math.max(u[1][0]-u[0][0],u[1][1]-u[0][1]),s=t.__zoom,h="function"==typeof n?n.apply(t,o):n,d=l(s.invert(c).concat(f/s.k),h.invert(c).concat(f/h.k));return function(t){if(1===t)t=h;else{var n=d(t),e=f/n[2];t=new ww(e,c[0]-n[0]*e,c[1]-n[1]*e)}a.zoom(null,t)}}))}function w(t,n,e){return!e&&t.__zooming||new M(t,n)}function M(t,n){this.that=t,this.args=n,this.active=0,this.sourceEvent=null,this.extent=i.apply(t,n),this.taps=0}function T(t,...n){if(r.apply(this,arguments)){var e=w(this,n).event(t),i=this.__zoom,u=Math.max(c[0],Math.min(c[1],i.k*Math.pow(2,a.apply(this,arguments)))),s=ee(t);if(e.wheel)e.mouse[0][0]===s[0]&&e.mouse[0][1]===s[1]||(e.mouse[1]=i.invert(e.mouse[0]=s)),clearTimeout(e.wheel);else{if(i.k===u)return;e.mouse=[s,i.invert(s)],Vi(this),e.start()}Sw(t),e.wheel=setTimeout((function(){e.wheel=null,e.end()}),p),e.zoom("mouse",o(b(_(i,u),e.mouse[0],e.mouse[1]),e.extent,f))}}function A(t,...n){if(!e&&r.apply(this,arguments)){var i=t.currentTarget,a=w(this,n,!0).event(t),u=Kn(t.view).on("mousemove.zoom",(function(t){if(Sw(t),!a.moved){var n=t.clientX-s,e=t.clientY-l;a.moved=n*n+e*e>g}a.event(t).zoom("mouse",o(b(a.that.__zoom,a.mouse[0]=ee(t,i),a.mouse[1]),a.extent,f))}),!0).on("mouseup.zoom",(function(t){u.on("mousemove.zoom mouseup.zoom",null),ce(t.view,a.moved),Sw(t),a.event(t).end()}),!0),c=ee(t,i),s=t.clientX,l=t.clientY;ue(t.view),Aw(t),a.mouse=[c,this.__zoom.invert(c)],Vi(this),a.start()}}function S(t,...n){if(r.apply(this,arguments)){var e=this.__zoom,a=ee(t.changedTouches?t.changedTouches[0]:t,this),u=e.invert(a),c=e.k*(t.shiftKey?.5:2),l=o(b(_(e,c),a,u),i.apply(this,n),f);Sw(t),s>0?Kn(this).transition().duration(s).call(x,l,a,t):Kn(this).call(v.transform,l,a,t)}}function E(e,...i){if(r.apply(this,arguments)){var o,a,u,c,f=e.touches,s=f.length,l=w(this,i,e.changedTouches.length===s).event(e);for(Aw(e),a=0;a=0;c--)if(a=e[c],s=n(t,a,u),void 0!==s){o=!0;break}return o?(r||"function"!=typeof s||(s=this.mv(s,e,i)),s):r?!1:""},ls:function(t,n,e,r,s){var a=this.options.delimiters;return this.options.delimiters=s,this.b(this.ct(i(t.call(n,r)),n,e)),this.options.delimiters=a,!1},ct:function(t,n,e){if(this.options.disableLambda)throw new Error("Lambda features disabled.");return this.c.compile(t,this.options).render(n,e)},b:function(t){this.buf+=t},fl:function(){var t=this.buf;return this.buf="",t},ms:function(t,n,e,i,r,s,a){var o,u=n[n.length-1],c=t.call(u);return"function"==typeof c?i?!0:(o=this.activeSub&&this.subsText&&this.subsText[this.activeSub]?this.subsText[this.activeSub]:this.text,this.ls(c,u,e,o.substring(r,s),a)):c},mv:function(t,n,e){var r=n[n.length-1],s=t.call(r);return"function"==typeof s?this.ct(i(s.call(r)),r,e):s},sub:function(t,n,e,i){var r=this.subs[t];r&&(this.activeSub=t,r(n,e,this,i),this.activeSub=!1)}};var s=/&/g,a=//g,u=/\'/g,c=/\"/g,l=/[&<>\"\']/,f=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}}("undefined"!=typeof exports?exports:Hogan),function(t){function n(t){"}"===t.n.substr(t.n.length-1)&&(t.n=t.n.substring(0,t.n.length-1))}function e(t){return t.trim?t.trim():t.replace(/^\s*|\s*$/g,"")}function i(t,n,e){if(n.charAt(e)!=t.charAt(0))return!1;for(var i=1,r=t.length;r>i;i++)if(n.charAt(e+i)!=t.charAt(i))return!1;return!0}function r(n,e,i,o){var u=[],c=null,l=null,f=null;for(l=i[i.length-1];n.length>0;){if(f=n.shift(),l&&"<"==l.tag&&!(f.tag in k))throw new Error("Illegal content in < super tag.");if(t.tags[f.tag]<=t.tags.$||s(f,o))i.push(f),f.nodes=r(n,f.tag,i,o);else{if("/"==f.tag){if(0===i.length)throw new Error("Closing tag without opener: /"+f.n);if(c=i.pop(),f.n!=c.n&&!a(f.n,c.n,o))throw new Error("Nesting error: "+c.n+" vs. "+f.n);return c.end=f.i,u}"\n"==f.tag&&(f.last=0==n.length||"\n"==n[0].tag)}u.push(f)}if(i.length>0)throw new Error("missing closing tag: "+i.pop().n);return u}function s(t,n){for(var e=0,i=n.length;i>e;e++)if(n[e].o==t.n)return t.tag="#",!0}function a(t,n,e){for(var i=0,r=e.length;r>i;i++)if(e[i].c==t&&e[i].o==n)return!0}function o(t){var n=[];for(var e in t)n.push('"'+c(e)+'": function(c,p,t,i) {'+t[e]+"}");return"{ "+n.join(",")+" }"}function u(t){var n=[];for(var e in t.partials)n.push('"'+c(e)+'":{name:"'+c(t.partials[e].name)+'", '+u(t.partials[e])+"}");return"partials: {"+n.join(",")+"}, subs: "+o(t.subs)}function c(t){return t.replace(m,"\\\\").replace(v,'\\"').replace(b,"\\n").replace(d,"\\r").replace(x,"\\u2028").replace(w,"\\u2029")}function l(t){return~t.indexOf(".")?"d":"f"}function f(t,n){var e="<"+(n.prefix||""),i=e+t.n+y++;return n.partials[i]={name:t.n,partials:{}},n.code+='t.b(t.rp("'+c(i)+'",c,p,"'+(t.indent||"")+'"));',i}function h(t,n){n.code+="t.b(t.t(t."+l(t.n)+'("'+c(t.n)+'",c,p,0)));'}function p(t){return"t.b("+t+");"}var g=/\S/,v=/\"/g,b=/\n/g,d=/\r/g,m=/\\/g,x=/\u2028/,w=/\u2029/;t.tags={"#":1,"^":2,"<":3,$:4,"/":5,"!":6,">":7,"=":8,_v:9,"{":10,"&":11,_t:12},t.scan=function(r,s){function a(){m.length>0&&(x.push({tag:"_t",text:new String(m)}),m="")}function o(){for(var n=!0,e=y;e"==e.tag&&(e.indent=x[i].text.toString()),x.splice(i,1));else n||x.push({tag:"\n"});w=!1,y=x.length}function c(t,n){var i="="+S,r=t.indexOf(i,n),s=e(t.substring(t.indexOf("=",n)+1,r)).split(" ");return T=s[0],S=s[s.length-1],r+i.length-1}var l=r.length,f=0,h=1,p=2,v=f,b=null,d=null,m="",x=[],w=!1,k=0,y=0,T="{{",S="}}";for(s&&(s=s.split(" "),T=s[0],S=s[1]),k=0;l>k;k++)v==f?i(T,r,k)?(--k,a(),v=h):"\n"==r.charAt(k)?u(w):m+=r.charAt(k):v==h?(k+=T.length-1,d=t.tags[r.charAt(k+1)],b=d?r.charAt(k+1):"_v","="==b?(k=c(r,k),v=f):(d&&k++,v=p),w=k):i(S,r,k)?(x.push({tag:b,n:e(m),otag:T,ctag:S,i:"/"==b?w-T.length:k+S.length}),m="",k+=S.length-1,v=f,"{"==b&&("}}"==S?k++:n(x[x.length-1]))):m+=r.charAt(k);return u(w,!0),x};var k={_t:!0,"\n":!0,$:!0,"/":!0};t.stringify=function(n){return"{code: function (c,p,i) { "+t.wrapMain(n.code)+" },"+u(n)+"}"};var y=0;t.generate=function(n,e,i){y=0;var r={code:"",subs:{},partials:{}};return t.walk(n,r),i.asString?this.stringify(r,e,i):this.makeTemplate(r,e,i)},t.wrapMain=function(t){return'var t=this;t.b(i=i||"");'+t+"return t.fl();"},t.template=t.Template,t.makeTemplate=function(t,n,e){var i=this.makePartials(t);return i.code=new Function("c","p","i",this.wrapMain(t.code)),new this.template(i,n,this,e)},t.makePartials=function(t){var n,e={subs:{},partials:t.partials,name:t.name};for(n in e.partials)e.partials[n]=this.makePartials(e.partials[n]);for(n in t.subs)e.subs[n]=new Function("c","p","t","i",t.subs[n]);return e},t.codegen={"#":function(n,e){e.code+="if(t.s(t."+l(n.n)+'("'+c(n.n)+'",c,p,1),c,p,0,'+n.i+","+n.end+',"'+n.otag+" "+n.ctag+'")){t.rs(c,p,function(c,p,t){',t.walk(n.nodes,e),e.code+="});c.pop();}"},"^":function(n,e){e.code+="if(!t.s(t."+l(n.n)+'("'+c(n.n)+'",c,p,1),c,p,1,0,0,"")){',t.walk(n.nodes,e),e.code+="};"},">":f,"<":function(n,e){var i={partials:{},code:"",subs:{},inPartial:!0};t.walk(n.nodes,i);var r=e.partials[f(n,e)];r.subs=i.subs,r.partials=i.partials},$:function(n,e){var i={subs:{},code:"",partials:e.partials,prefix:n.n};t.walk(n.nodes,i),e.subs[n.n]=i.code,e.inPartial||(e.code+='t.sub("'+c(n.n)+'",c,p,i);')},"\n":function(t,n){n.code+=p('"\\n"'+(t.last?"":" + i"))},_v:function(t,n){n.code+="t.b(t.v(t."+l(t.n)+'("'+c(t.n)+'",c,p,0)));'},_t:function(t,n){n.code+=p('"'+c(t.text)+'"')},"{":h,"&":h},t.walk=function(n,e){for(var i,r=0,s=n.length;s>r;r++)i=t.codegen[n[r].tag],i&&i(n[r],e);return e},t.parse=function(t,n,e){return e=e||{},r(t,"",[],e.sectionTags||[])},t.cache={},t.cacheKey=function(t,n){return[t,!!n.asString,!!n.disableLambda,n.delimiters,!!n.modelGet].join("||")},t.compile=function(n,e){e=e||{};var i=t.cacheKey(n,e),r=this.cache[i];if(r){var s=r.partials;for(var a in s)delete s[a].instance;return r}return r=this.generate(this.parse(this.scan(n,e.delimiters),n,e),n,e),this.cache[i]=r}}("undefined"!=typeof exports?exports:Hogan); \ No newline at end of file diff --git a/resources/js/topojson.v3.min.js b/resources/js/topojson.v3.min.js new file mode 100644 index 0000000000..3e905ccb29 --- /dev/null +++ b/resources/js/topojson.v3.min.js @@ -0,0 +1,2 @@ +/* https://github.com/topojson/topojson Version 3.0.2. Copyright 2017 Mike Bostock. */ +(function(r,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(r.topojson=r.topojson||{})})(this,function(r){"use strict";function n(r,n){var e=n.id,o=n.bbox,a=null==n.properties?{}:n.properties,i=t(r,n);return null==e&&null==o?{type:"Feature",properties:a,geometry:i}:null==o?{type:"Feature",id:e,properties:a,geometry:i}:{type:"Feature",id:e,bbox:o,properties:a,geometry:i}}function t(r,n){function t(r,n){n.length&&n.pop();for(var t=f[r<0?~r:r],e=0,o=t.length;e1)e=o(r,n,t);else for(a=0,e=new Array(i=r.arcs.length);a1)for(var o,a,c=1,f=i(e[0]);cf&&(a=e[0],e[0]=e[c],e[c]=a,f=o);return e})}}function u(r,n,t,e){c(r,n,t),c(r,n,n+e),c(r,n+e,t)}function c(r,n,t){for(var e,o=n+(t---n>>1);n=1)return r[t-1];var t,e=(t-1)*n,o=Math.floor(e),a=r[o];return a+(r[o+1]-a)*(e-o)}}function x(r,n){return n-r}function w(r,n){for(var t,e,o,a=0,i=r.length,u=0,c=r[n?a++:i-1],f=c[0]*rr,s=c[1]*rr/2+$,l=er(s),h=or(s);a=0?1:-1,y=g*p,v=o*h,b=e*l+v*er(y),m=v*g*or(y);u+=tr(m,b)}return u}var k=function(r){return r},A=function(r){if(null==r)return k;var n,t,e=r.scale[0],o=r.scale[1],a=r.translate[0],i=r.translate[1];return function(r,u){u||(n=t=0);var c=2,f=r.length,s=new Array(f);for(s[0]=(n+=r[0])*e+a,s[1]=(t+=r[1])*o+i;cu&&(u=r[0]),r[1]c&&(c=r[1])}function t(r){switch(r.type){case"GeometryCollection":r.geometries.forEach(t);break;case"Point":n(r.coordinates);break;case"MultiPoint":r.coordinates.forEach(n)}}var e,o=A(r.transform),a=1/0,i=a,u=-a,c=-a;r.arcs.forEach(function(r){for(var n,t=-1,e=r.length;++tu&&(u=n[0]),n[1]c&&(c=n[1])});for(e in r.objects)t(r.objects[e]);return[a,i,u,c]},C=function(r,n){for(var t,e=r.length,o=e-n;o<--e;)t=r[o],r[o++]=r[e],r[e]=t},S=function(r,t){return"GeometryCollection"===t.type?{type:"FeatureCollection",features:t.geometries.map(function(t){return n(r,t)})}:n(r,t)},G=function(r,n){function t(n){var t,e=r.arcs[n<0?~n:n],o=e[0];return r.transform?(t=[0,0],e.forEach(function(r){t[0]+=r[0],t[1]+=r[1]})):t=e[e.length-1],n<0?[t,o]:[o,t]}function e(r,n){for(var t in r){var e=r[t];delete n[e.start],delete e.start,delete e.end,e.forEach(function(r){o[r<0?~r:r]=1}),u.push(e)}}var o={},a={},i={},u=[],c=-1;return n.forEach(function(t,e){var o,a=r.arcs[t<0?~t:t];a.length<3&&!a[1][0]&&!a[1][1]&&(o=n[++c],n[c]=t,n[e]=o)}),n.forEach(function(r){var n,e,o=t(r),u=o[0],c=o[1];if(n=i[u])if(delete i[n.end],n.push(r),n.end=c,e=a[c]){delete a[e.start];var f=e===n?n:n.concat(e);a[f.start=n.start]=i[f.end=e.end]=f}else a[n.start]=i[n.end]=n;else if(n=a[c])if(delete a[n.start],n.unshift(r),n.start=u,e=i[u]){delete i[e.end];var s=e===n?n:e.concat(n);a[s.start=e.start]=i[s.end=n.end]=s}else a[n.start]=i[n.end]=n;else a[(n=[r]).start=u]=i[n.end=c]=n}),e(i,a),e(a,i),n.forEach(function(r){o[r<0?~r:r]||u.push([r])}),u},j=function(r,n){for(var t=0,e=r.length;t>>1;r[o]u&&(u=n),tc&&(c=t)}function e(r){r.forEach(t)}function o(r){r.forEach(e)}var a=1/0,i=1/0,u=-1/0,c=-1/0,f={GeometryCollection:function(r){r.geometries.forEach(n)},Point:function(r){t(r.coordinates)},MultiPoint:function(r){r.coordinates.forEach(t)},LineString:function(r){e(r.arcs)},MultiLineString:function(r){r.arcs.forEach(e)},Polygon:function(r){r.arcs.forEach(e)},MultiPolygon:function(r){r.arcs.forEach(o)}};for(var s in r)n(r[s]);return u>=a&&c>=i?[a,i,u,c]:void 0},T=function(r,n,t,e,o){3===arguments.length&&(e=Array,o=null);for(var a=new e(r=1<=r)throw new Error("full hashset");c=a[u=u+1&i]}return a[u]=e,!0},has:function(e){for(var u=n(e)&i,c=a[u],f=0;c!=o;){if(t(c,e))return!0;if(++f>=r)break;c=a[u=u+1&i]}return!1},values:function(){for(var r=[],n=0,t=a.length;n=r)throw new Error("full hashmap");s=i[f=f+1&c]}return i[f]=e,u[f]=a,a},maybeSet:function(e,a){for(var f=n(e)&c,s=i[f],l=0;s!=o;){if(t(s,e))return u[f];if(++l>=r)throw new Error("full hashmap");s=i[f=f+1&c]}return i[f]=e,u[f]=a,a},get:function(e,a){for(var f=n(e)&c,s=i[f],l=0;s!=o;){if(t(s,e))return u[f];if(++l>=r)break;s=i[f=f+1&c]}return a},keys:function(){for(var r=[],n=0,t=i.length;n>7^q[2]^q[3])},z=function(r){function n(r,n,t,e){if(h[t]!==r){h[t]=r;var o=p[t];if(o>=0){var a=g[t];o===n&&a===e||o===e&&a===n||(++v,y[t]=1)}else p[t]=n,g[t]=e}}function t(r){return U(c[r])}function e(r,n){return N(c[r],c[n])}var o,a,i,u,c=r.coordinates,f=r.lines,s=r.rings,l=function(){for(var r=F(1.4*c.length,t,e,Int32Array,-1,Int32Array),n=new Int32Array(c.length),o=0,a=c.length;o=n}},X=function(){function r(r,n){for(;n>0;){var t=(n+1>>1)-1,o=e[t];if(M(r,o)>=0)break;e[o._=n]=o,e[r._=n=t]=r}}function n(r,n){for(;;){var t=n+1<<1,a=t-1,i=n,u=e[i];if(a0&&(r=e[o],n(e[r._=0]=r,0)),t}},t.remove=function(t){var a,i=t._;if(e[i]===t)return i!==--o&&(a=e[o],(M(a,t)<0?r:n)(e[a._=i]=a,i)),i},t},Y=Math.PI,Z=2*Y,$=Y/4,rr=Y/180,nr=Math.abs,tr=Math.atan2,er=Math.cos,or=Math.sin;r.bbox=L,r.feature=S,r.mesh=function(r){return t(r,e.apply(this,arguments))},r.meshArcs=e,r.merge=function(r){return t(r,i.apply(this,arguments))},r.mergeArcs=i,r.neighbors=function(r){function n(r,n){r.forEach(function(r){r<0&&(r=~r);var t=o[r];t?t.push(n):o[r]=[n]})}function t(r,t){r.forEach(function(r){n(r,t)})}function e(r,n){"GeometryCollection"===r.type?r.geometries.forEach(function(r){e(r,n)}):r.type in i&&i[r.type](r.arcs,n)}var o={},a=r.map(function(){return[]}),i={LineString:n,MultiLineString:t,Polygon:t,MultiPolygon:function(r,n){r.forEach(function(r){t(r,n)})}};r.forEach(e);for(var u in o)for(var c=o[u],f=c.length,s=0;s=2))throw new Error("n must be ≥2");var o,a=(f=r.bbox||L(r))[0],i=f[1],u=f[2],c=f[3];n={scale:[u-a?(u-a)/(o-1):1,c-i?(c-i)/(o-1):1],translate:[a,i]}}var f,s,l=_(n),h=r.objects,p={};for(s in h)p[s]=e(h[s]);return{type:"Topology",bbox:f,transform:n,objects:p,arcs:r.arcs.map(function(r){var n,t=0,e=1,o=r.length,a=new Array(o);for(a[0]=l(r[0],0);++t0&&a&&H(r,a,n),u=V(R(B(r))),c=u.coordinates,f=F(1.4*u.arcs.length,p,g);r=u.objects,u.bbox=a,u.arcs=u.arcs.map(function(r,n){return f.set(r,n),c.slice(r[0],r[1]+1)}),delete u.coordinates,c=null;var s={GeometryCollection:function(r){r.geometries.forEach(t)},LineString:function(r){r.arcs=e(r.arcs)},MultiLineString:function(r){r.arcs=r.arcs.map(e)},Polygon:function(r){r.arcs=r.arcs.map(e)},MultiPolygon:function(r){r.arcs=r.arcs.map(o)}};for(var l in r)t(r[l]);return i&&(u.transform=i,u.arcs=W(u.arcs)),u},r.filter=function(r,n){function t(r){var n,o;switch(r.type){case"Polygon":n=(o=e(r.arcs))?{type:"Polygon",arcs:o}:{type:null};break;case"MultiPolygon":n=(o=r.arcs.map(e).filter(v)).length?{type:"MultiPolygon",arcs:o}:{type:null};break;case"GeometryCollection":n=(o=r.geometries.map(t).filter(b)).length?{type:"GeometryCollection",geometries:o}:{type:null};break;default:return r}return null!=r.id&&(n.id=r.id),null!=r.bbox&&(n.bbox=r.bbox),null!=r.properties&&(n.properties=r.properties),n}function e(r){return r.length&&o(r[0])?[r[0]].concat(r.slice(1).filter(a)):null}function o(r){return n(r,!1)}function a(r){return n(r,!0)}var i,u=r.objects,c={};null==n&&(n=y);for(i in u)c[i]=t(u[i]);return J({type:"Topology",bbox:r.bbox,transform:r.transform,objects:c,arcs:r.arcs})},r.filterAttached=K,r.filterAttachedWeight=function(r,n,t){var e=K(r),o=Q(r,n,t);return function(r,n){return e(r,n)||o(r,n)}},r.filterWeight=Q,r.planarRingArea=d,r.planarTriangleArea=m,r.presimplify=function(r,n){function t(r){o.remove(r),r[1][2]=n(r),o.push(r)}var e=r.transform?A(r.transform):E,o=X();null==n&&(n=m);var a=r.arcs.map(function(r){var a,i,u,c=[],f=0;for(i=1,u=(r=r.map(e)).length-1;i=n&&(i[o++]=[t[0],t[1]]);return i.length=o,i});return{type:"Topology",transform:r.transform,bbox:r.bbox,objects:r.objects,arcs:t}},r.sphericalRingArea=function(r,n){var t=w(r,!0);return n&&(t*=-1),2*(t<0?Z+t:t)},r.sphericalTriangleArea=function(r){return 2*nr(w(r,!1))},Object.defineProperty(r,"__esModule",{value:!0})}); diff --git a/resources/tpls.html b/resources/tpls.html new file mode 100644 index 0000000000..e2e2eda31c --- /dev/null +++ b/resources/tpls.html @@ -0,0 +1,317 @@ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/settings.c b/settings.c deleted file mode 100644 index 14cf5a6406..0000000000 --- a/settings.c +++ /dev/null @@ -1,268 +0,0 @@ -/** - * settings.c -- goaccess configuration - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) - -#include -#include -#include -#include -#include -#include - -#include "settings.h" - -#include "commons.h" -#include "error.h" -#include "ui.h" -#include "util.h" -#include "xmalloc.h" - -static char **nargv; -static int nargc = 0; - -/* *INDENT-OFF* */ -static const GPreConfLog logs = { - "%h %^[%d:%^] \"%r\" %s %b \"%R\" \"%u\"", /* CLF */ - "%h %^[%d:%^] \"%r\" %s %b", /* CLF+VHost */ - "%^:%^ %h %^[%d:%^] \"%r\" %s %b \"%R\" \"%u\"", /* NCSA */ - "%^:%^ %h %^[%d:%^] \"%r\" %s %b", /* NCSA+VHost */ - "%d %^ %h %^ %^ %^ %^ %r %^ %s %b %^ %^ %u %R", /* W3C */ - "%d\\t%^\\t%^\\t%b\\t%h\\t%m\\t%^\\t%r\\t%s\\t%R\\t%u\\t%^" /* CloudFront */ -}; - -static const GPreConfDate dates = { - "%d/%b/%Y", /* Apache */ - "%Y-%m-%d", /* W3C */ - "%Y-%m-%d" /* CloudFront */ -}; -/* *INDENT-ON* */ - -/* Ignore the following options */ -static const char *ignore_cmd_opts[] = { - "help", - "storage", -}; - -static int -in_ignore_cmd_opts (const char *val) -{ - size_t i; - for (i = 0; i < ARRAY_SIZE (ignore_cmd_opts); i++) { - if (strstr (val, ignore_cmd_opts[i]) != NULL) - return 1; - } - return 0; -} - -static char * -get_config_file_path (void) -{ - char *path = NULL; - - /* determine which config file to open, default or custom */ - if (conf.iconfigfile != NULL) { - path = realpath (conf.iconfigfile, NULL); - if (path == NULL) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, strerror (errno)); - } else if (conf.load_global_config) - path = get_global_config (); - else - path = get_home (); - - return path; -} - -/* clean command line arguments */ -void -free_cmd_args (void) -{ - int i; - if (nargc == 0) - return; - for (i = 0; i < nargc; i++) - free (nargv[i]); - free (nargv); -} - -/* append extra value to argv */ -static void -append_to_argv (int *argc, char ***argv, char *val) -{ - char **_argv = xrealloc (*argv, (*argc + 2) * sizeof (*_argv)); - _argv[*argc] = val; - _argv[*argc + 1] = '\0'; - (*argc)++; - *argv = _argv; -} - -/* parses configuration file to feed getopt_long */ -int -parse_conf_file (int *argc, char ***argv) -{ - char line[MAX_LINE_CONF + 1]; - char *path = NULL, *val, *opt, *p; - FILE *file; - int i; - size_t idx; - - /* assumes program name is on argv[0], though, it is not guaranteed */ - append_to_argv (&nargc, &nargv, xstrdup ((char *) *argv[0])); - - /* determine which config file to open, default or custom */ - path = get_config_file_path (); - if (path == NULL) - return ENOENT; - - /* could not open conf file, if so prompt conf dialog */ - if ((file = fopen (path, "r")) == NULL) { - free (path); - return ENOENT; - } - - while (fgets (line, sizeof line, file) != NULL) { - if (line[0] == '\n' || line[0] == '\r' || line[0] == '#') - continue; - - /* key */ - idx = strcspn (line, " \t"); - if (strlen (line) == idx) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Malformed config key at line: %s", line); - - /* make old config options backwards compatible by - * substituting underscores with dashes - */ - while ((p = strpbrk (line, "_")) != NULL) - *p = '-'; - - line[idx] = '\0'; - - /* Ignore the following options when reading the config file */ - if (in_ignore_cmd_opts (line)) - continue; - - /* value */ - val = line + (idx + 1); - idx = strspn (val, " \t"); - if (strlen (line) == idx) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Malformed config value at line: %s", line); - val = val + idx; - val = trim_str (val); - - if (strcmp ("false", val) == 0) - continue; - - /* set it as command line options */ - opt = xmalloc (snprintf (NULL, 0, "--%s", line) + 1); - sprintf (opt, "--%s", line); - - append_to_argv (&nargc, &nargv, opt); - if (strcmp ("true", val) != 0) - append_to_argv (&nargc, &nargv, xstrdup (val)); - } - - /* give priority to command line arguments */ - for (i = 1; i < *argc; i++) - append_to_argv (&nargc, &nargv, xstrdup ((char *) (*argv)[i])); - - *argc = nargc; - *argv = (char **) nargv; - - fclose (file); - - free (path); - return 0; -} - -/* return the index of the matched item, or -1 if no such item exists */ -size_t -get_selected_format_idx (void) -{ - if (conf.log_format == NULL) - return -1; - if (strcmp (conf.log_format, logs.common) == 0) - return COMMON; - else if (strcmp (conf.log_format, logs.vcommon) == 0) - return VCOMMON; - else if (strcmp (conf.log_format, logs.combined) == 0) - return COMBINED; - else if (strcmp (conf.log_format, logs.vcombined) == 0) - return VCOMBINED; - else if (strcmp (conf.log_format, logs.w3c) == 0) - return W3C; - else if (strcmp (conf.log_format, logs.cloudfront) == 0) - return CLOUDFRONT; - else - return -1; -} - -/* return the string of the matched item, or NULL if no such item exists */ -char * -get_selected_format_str (size_t idx) -{ - char *fmt = NULL; - switch (idx) { - case COMMON: - fmt = alloc_string (logs.common); - break; - case VCOMMON: - fmt = alloc_string (logs.vcommon); - break; - case COMBINED: - fmt = alloc_string (logs.combined); - break; - case VCOMBINED: - fmt = alloc_string (logs.vcombined); - break; - case W3C: - fmt = alloc_string (logs.w3c); - break; - case CLOUDFRONT: - fmt = alloc_string (logs.cloudfront); - break; - } - - return fmt; -} - -char * -get_selected_date_str (size_t idx) -{ - char *fmt = NULL; - switch (idx) { - case COMMON: - case VCOMMON: - case COMBINED: - case VCOMBINED: - fmt = alloc_string (dates.apache); - break; - case W3C: - fmt = alloc_string (dates.w3c); - break; - case CLOUDFRONT: - fmt = alloc_string (dates.cloudfront); - break; - } - - return fmt; -} diff --git a/settings.h b/settings.h deleted file mode 100644 index ab3ea32c20..0000000000 --- a/settings.h +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#ifndef SETTINGS_H_INCLUDED -#define SETTINGS_H_INCLUDED - -#include - -#define MAX_LINE_CONF 512 - -typedef enum -{ - COMMON, - VCOMMON, - COMBINED, - VCOMBINED, - W3C, - CLOUDFRONT -} LOGTYPE; - -/* predefined log dates */ -typedef struct GPreConfDate_ -{ - const char *apache; - const char *w3c; - const char *cloudfront; -} GPreConfDate; - -/* predefined log formats */ -typedef struct GPreConfLog_ -{ - const char *combined; - const char *common; - const char *vcombined; - const char *vcommon; - const char *w3c; - const char *cloudfront; -} GPreConfLog; - -typedef struct GConfKeyword_ -{ - const unsigned short key_id; - const char *keyword; -} GConfKeyword; - -typedef struct GConf_ -{ - char *date_format; - char *debug_log; - char *geoip_city_data; - char *iconfigfile; - char *ifile; - char *ignore_host; - char *log_format; - char *output_format; - int append_method; - int append_protocol; - int bandwidth; - int color_scheme; - int enable_html_resolver; - int geo_db; - int ignore_qstr; - int list_agents; - int load_conf_dlg; - int mouse_support; - int no_color; - int load_global_config; - int no_progress; - int output_html; - int real_os; - int serve_usecs; - int skip_term_resolver; - - /* TokyoCabinet */ - char *db_path; - int64_t xmmap; - int cache_lcnum; - int cache_ncnum; - int compression; - int keep_db_files; - int load_from_disk; - int tune_bnum; - int tune_lmemb; - int tune_nmemb; -} GConf; - -char *get_selected_date_str (size_t idx); -char *get_selected_format_str (size_t idx); -size_t get_selected_format_idx (void); - -extern GConf conf; -extern char *tmp_log_format; -extern char *tmp_date_format; - -int parse_conf_file (int *argc, char ***argv); -void free_cmd_args (void); - -#endif diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 0000000000..659ef8e5fa --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,28 @@ +name: goaccess +version: git +summary: Real-time web log analyzer and interactive viewer +description: | + GoAccess is a real-time web log analyzer and interactive viewer that runs + in a terminal in *nix systems or through your browser. +confinement: classic +grade: devel + +apps: + goaccess: + command: bin/goaccess + +parts: + goaccess: + plugin: autotools + source: . + configflags: + - --enable-utf8 + - --enable-geoip=legacy + build-packages: + - gettext + - libncurses-dev + - libncursesw5-dev + - libgeoip-dev + stage-packages: + - libgeoip-dev + diff --git a/src/base64.c b/src/base64.c new file mode 100644 index 0000000000..029cddca22 --- /dev/null +++ b/src/base64.c @@ -0,0 +1,78 @@ +/** + * base64.c -- A basic base64 encode implementation + * _______ _______ __ __ + * / ____/ | / / ___/____ _____/ /_____ / /_ + * / / __ | | /| / /\__ \/ __ \/ ___/ //_/ _ \/ __/ + * / /_/ / | |/ |/ /___/ / /_/ / /__/ ,< / __/ /_ + * \____/ |__/|__//____/\____/\___/_/|_|\___/\__/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include + +#include "base64.h" +#include "xmalloc.h" + +/* Encodes the given data with base64. + * + * On success, the encoded nul-terminated data, as a string is returned. */ +char * +base64_encode (const void *buf, size_t size) { + static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + + char *str = (char *) xmalloc ((size + 3) * 4 / 3 + 1); + + char *p = str; + const unsigned char *q = (const unsigned char *) buf; + size_t i = 0; + + while (i < size) { + int c = q[i++]; + c *= 256; + if (i < size) + c += q[i]; + i++; + + c *= 256; + if (i < size) + c += q[i]; + i++; + + *p++ = base64[(c & 0x00fc0000) >> 18]; + *p++ = base64[(c & 0x0003f000) >> 12]; + + if (i > size + 1) + *p++ = '='; + else + *p++ = base64[(c & 0x00000fc0) >> 6]; + + if (i > size) + *p++ = '='; + else + *p++ = base64[c & 0x0000003f]; + } + + *p = 0; + + return str; +} diff --git a/src/base64.h b/src/base64.h new file mode 100644 index 0000000000..8470244e44 --- /dev/null +++ b/src/base64.h @@ -0,0 +1,37 @@ +/** + * _______ _______ __ __ + * / ____/ | / / ___/____ _____/ /_____ / /_ + * / / __ | | /| / /\__ \/ __ \/ ___/ //_/ _ \/ __/ + * / /_/ / | |/ |/ /___/ / /_/ / /__/ ,< / __/ /_ + * \____/ |__/|__//____/\____/\___/_/|_|\___/\__/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef BASE64_H_INCLUDED +#define BASE64_H_INCLUDED + +#include + +char *base64_encode (const void *buf, size_t size); + +#endif // for #ifndef BASE64_H diff --git a/src/bin2c.c b/src/bin2c.c new file mode 100644 index 0000000000..d6b23bc3de --- /dev/null +++ b/src/bin2c.c @@ -0,0 +1,154 @@ +/* + * This is bin2c program, which allows you to convert binary file to + * C language array, for use as embedded resource, for instance you can + * embed graphics or audio file directly into your program. + * This is public domain software, use it on your own risk. + * Contact Serge Fukanchik at fuxx@mail.ru if you have any questions. + * + * Some modifications were made by Gwilym Kuiper (kuiper.gwilym@gmail.com) + * I have decided not to change the licence. + */ + +#include +#include +#include + +#ifdef USE_BZ2 +#include +#endif + +int +main (int argc, char *argv[]) { + char *buf; + char *ident; + int need_comma; + long file_size_orig; + size_t file_size, i; + FILE *f_input, *f_output; + +#ifdef USE_BZ2 + int status; + char *bz2_buf; + unsigned int uncompressed_size, bz2_size; +#endif + + if (argc < 4) { + fprintf (stderr, "Usage: %s binary_file output_file array_name\n", argv[0]); + return -1; + } + + f_input = fopen (argv[1], "rb"); + if (f_input == NULL) { + fprintf (stderr, "%s: can't open %s for reading\n", argv[0], argv[1]); + return -1; + } + // Get the file length + fseek (f_input, 0, SEEK_END); + file_size_orig = ftell (f_input); + if (file_size_orig < 0) { + fprintf (stderr, "%s: can't get size of file %s\n", argv[0], argv[1]); + fclose (f_input); + return -1; + } + file_size = (size_t) file_size_orig; + fseek (f_input, 0, SEEK_SET); + + if ((buf = malloc (file_size)) == NULL) { + fprintf (stderr, "Unable to malloc bin2c.c buffer\n"); + fclose (f_input); + return -1; + } + + if (fread (buf, file_size, 1, f_input) != 1) { + fprintf (stderr, "%s: can't read from %s\n", argv[0], argv[1]); + free (buf); + fclose (f_input); + return -1; + } + + if (fgetc (f_input) != EOF) { + fprintf (stderr, "%s: can't read complete file %s\n", argv[0], argv[1]); + free (buf); + fclose (f_input); + return -1; + } + + if (ferror (f_input)) { + fprintf (stderr, "%s: error while reading from %s\n", argv[0], argv[1]); + free (buf); + fclose (f_input); + return -1; + } + + fclose (f_input); + +#ifdef USE_BZ2 + // allocate for bz2. + bz2_size = (file_size + file_size / 100 + 1) + 600; // as per the documentation + + if ((bz2_buf = malloc (bz2_size)) == NULL) { + fprintf (stderr, "Unable to malloc bin2c.c buffer\n"); + free (buf); + return -1; + } + // compress the data + status = BZ2_bzBuffToBuffCompress (bz2_buf, &bz2_size, buf, file_size, 9, 1, 0); + if (status != BZ_OK) { + fprintf (stderr, "Failed to compress data: error %i\n", status); + free (buf); + free (bz2_buf); + return -1; + } + // and be very lazy + free (buf); + uncompressed_size = file_size; + file_size = bz2_size; + buf = bz2_buf; +#endif + + f_output = fopen (argv[2], "w"); + if (f_output == NULL) { + fprintf (stderr, "%s: can't open %s for writing\n", argv[0], argv[1]); + free (buf); + return -1; + } + + ident = argv[3]; + need_comma = 0; + + fprintf (f_output, "const char %s[%lu] = {", ident, file_size); + for (i = 0; i < file_size; ++i) { + if (buf[i] == '\0') { + fprintf (stderr, + "%s: writing a null character terminates the content prematurely\n", argv[0]); + fclose (f_output); + free (buf); + return -1; + } + if (need_comma) + fprintf (f_output, ", "); + else + need_comma = 1; + if ((i % 11) == 0) + fprintf (f_output, "\n\t"); + fprintf (f_output, "0x%.2x", buf[i] & 0xff); + } + fprintf (f_output, "\n};\n\n"); + fprintf (f_output, "const int %s_length = %lu;\n", ident, file_size); + +#ifdef USE_BZ2 + fprintf (f_output, "const int %s_length_uncompressed = %u;\n", ident, uncompressed_size); +#endif + + if (ferror (f_output)) { + fprintf (stderr, "%s: error while writing to %s\n", argv[0], argv[2]); + fclose (f_output); + free (buf); + return -1; + } + + fclose (f_output); + free (buf); + + return 0; +} diff --git a/src/bitmap.c b/src/bitmap.c new file mode 100644 index 0000000000..e45271dd5b --- /dev/null +++ b/src/bitmap.c @@ -0,0 +1,173 @@ +/** + * bitmap.c -- A quick bitmap implementation + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include + +#include "error.h" +#include "xmalloc.h" + +#include "bitmap.h" + +/* + * Returns the hamming weight (i.e. the number of bits set) in a word. + * NOTE: This routine borrowed from Linux 2.4.9 . + */ +static uint32_t +hweight (uint32_t w) { + uint32_t res; + + res = (w & 0x55555555) + ((w >> 1) & 0x55555555); + res = (res & 0x33333333) + ((res >> 2) & 0x33333333); + res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F); + res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF); + res = (res & 0x0000FFFF) + ((res >> 16) & 0x0000FFFF); + + return res; +} + + +/* Returns the number of bytes required for bm->len bits. */ +inline uint32_t +bitmap_sizeof (uint32_t i) { + return bitmap_word (i) * sizeof (word_t); +} + +void +free_bitmap (bitmap *bm) { + free ((uint32_t *) bm->bmp); + free (bm); +} + +int +bitmap_set_bit (word_t *words, uint32_t n) { + words[WORD_OFFSET (n)] |= ((word_t) 1 << BIT_OFFSET (n)); + return 0; +} + +int +bitmap_get_bit (word_t *words, uint32_t n) { + word_t bit = words[WORD_OFFSET (n)] & ((word_t) 1 << BIT_OFFSET (n)); + return bit != 0; +} + +uint32_t +bitmap_count_set (const bitmap *bm) { + uint32_t i, n = 0, len = 0; + + if (!bm) + return 0; + + len = bitmap_word (bm->len); + for (i = 0; i < len; ++i) + n += hweight (bm->bmp[i]); + + return n; +} + +uint32_t +bitmap_ffs (bitmap *bm) { + uint32_t i, pos = 1, len = 0; + uint32_t __bitset; + + if (!bm) + return 0; + + len = bitmap_word (bm->len); + for (i = 0; i < len; ++i) { + __bitset = bm->bmp[i]; + if ((pos = __builtin_ffs (__bitset))) + break; + } + + return (BITS_PER_WORD * i) + pos; +} + +bitmap * +bitmap_create (uint32_t bit) { + bitmap *bm = xcalloc (1, sizeof (bitmap)); + uint32_t bytes = bitmap_sizeof (bit); + + bm->bmp = xmalloc (bytes); + memset (bm->bmp, 0, bytes); + bm->len = bit; + + return bm; +} + +int +bitmap_realloc (bitmap *bm, uint32_t bit) { + uint32_t *tmp = NULL; + uint32_t oldlen = 0, newlen = 0; + + newlen = bitmap_sizeof (bit); + oldlen = bitmap_sizeof (bm->len); + if (newlen <= oldlen) + return 1; + + tmp = realloc (bm->bmp, newlen); + if ((tmp == NULL && newlen > 0) || bit < bm->len) + FATAL ("Unable to realloc bitmap hash value %u %u", newlen, bm->len); + + LOG_DEBUG (("bit: %d, bm->len: %d, oldlen: %d, newlen: %d\n", bit, bm->len, oldlen, newlen)); + memset (tmp + bitmap_word (bm->len), 0, (newlen - oldlen)); + bm->len = bit; + bm->bmp = tmp; + + return 0; +} + +bitmap * +bitmap_copy (const bitmap *bm) { + bitmap *ret; + + if (!bm) + return NULL; + if (!(ret = bitmap_create (bm->len))) + return NULL; + + memcpy (ret->bmp, bm->bmp, bitmap_sizeof (bm->len)); + + return ret; +} + +int +bitmap_key_exists (bitmap *bm, uint32_t bit) { + if (bm->len < bit) + bitmap_realloc (bm, bit); + + /* if bit set, then it's the same visitor */ + if (bitmap_get_bit (bm->bmp, bit - 1)) + return 1; + bitmap_set_bit (bm->bmp, bit - 1); + + return 0; +} diff --git a/src/bitmap.h b/src/bitmap.h new file mode 100644 index 0000000000..651c367adc --- /dev/null +++ b/src/bitmap.h @@ -0,0 +1,76 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +#ifndef BITMAP_H_INCLUDED +#define BITMAP_H_INCLUDED + +#include /* for CHAR_BIT */ + +typedef uint32_t word_t; // I want to change this, from uint32_t to uint64_t +enum { BITS_PER_WORD = sizeof (word_t) * CHAR_BIT }; +#define WORD_OFFSET(b) ((b) / BITS_PER_WORD) +#define BIT_OFFSET(b) ((b) % BITS_PER_WORD) + +typedef struct bitmap_ { + uint32_t *bmp; + uint32_t len; /** Length of the bitmap, in bits */ +} bitmap; + +static inline uint32_t +bitmap_word (uint32_t i) { + return (((i) + (BITS_PER_WORD) - 1) / (BITS_PER_WORD)); +} + +#define BITMAP_FOREACH(bm, pos, code) { size_t __k; \ + int __r; uint32_t __bitset, __t; \ + uint32_t __len = bitmap_word(bm->len); \ + for (__k = 0; __k < __len; ++__k) { \ + __bitset = bm->bmp[__k]; \ + while (__bitset != 0) { \ + __t = __bitset & -__bitset; \ + __r = __builtin_ctzl (__bitset); \ + pos = (__k * 32) + __r + 1; \ + code; \ + __bitset ^= __t; \ + } \ + } } + +bitmap *bitmap_copy (const bitmap * bm); +bitmap *bitmap_create (uint32_t bit); +int bitmap_get_bit (word_t * words, uint32_t n); +int bitmap_key_exists (bitmap * bm, uint32_t bit); +int bitmap_realloc (bitmap * bm, uint32_t bit); +int bitmap_set_bit (word_t * words, uint32_t n); +uint32_t bitmap_count_set (const bitmap * bm); +uint32_t bitmap_ffs (bitmap * bm); +uint32_t bitmap_sizeof (uint32_t nbits); +void free_bitmap (bitmap * bm); + +#endif // for #ifndef BITMAP_H diff --git a/src/browsers.c b/src/browsers.c new file mode 100644 index 0000000000..e4e806271d --- /dev/null +++ b/src/browsers.c @@ -0,0 +1,609 @@ +/** + 6 browsers.c -- functions for dealing with browsers + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#include "browsers.h" + +#include "error.h" +#include "settings.h" +#include "util.h" +#include "xmalloc.h" + +/* ###NOTE: The size of the list is proportional to the run time, + * which makes this pretty slow */ + +static char ***browsers_hash = NULL; + +/* {"search string", "belongs to"} */ +static const char *const browsers[][2] = { + /* Game systems: most of them are based on major browsers, + * thus they need to go before. */ + {"Xbox One", "Game Systems"}, + {"Xbox", "Game Systems"}, + {"PlayStation", "Game Systems"}, + {"NintendoBrowser", "Game Systems"}, + {"Valve Steam", "Game Systems"}, + {"Origin", "Game Systems"}, + {"Raptr", "Game Systems"}, + + /* Based on Internet Explorer */ + {"Avant Browser", "Others"}, + /* Internet Explorer */ + {"IEMobile", "MSIE"}, + {"MSIE", "MSIE"}, + /* IE11 */ + {"Trident/7.0", "MSIE"}, + /* Microsoft Edge */ + {"Edg", "Edge"}, + {"Edge", "Edge"}, + + /* Surf Browser */ + {"Surf", "Surf"}, + + /* Opera */ + {"Opera Mini", "Opera"}, + {"Opera Mobi", "Opera"}, + {"Opera", "Opera"}, + {"OPR", "Opera"}, + {"OPiOS", "Opera"}, + {"Coast", "Opera"}, + + /* Others */ + {"Homebrew", "Others"}, + {"APT-", "Others"}, + {"Apt-Cacher", "Others"}, + {"Aptly", "Others"}, + {"Chef Client", "Others"}, + {"Huawei", "Others"}, + {"HUAWEI", "Others"}, + {"BlackBerry", "Others"}, + {"BrowserX", "Others"}, + {"Dalvik", "Others"}, + {"Dillo", "Others"}, + {"ELinks", "Others"}, + {"Epiphany", "Others"}, + {"Firebird", "Others"}, + {"Galeon", "Others"}, + {"google-cloud-sdk", "Others"}, + {"IBrowse", "Others"}, + {"K-Meleon", "Others"}, + {"Konqueror", "Others"}, + {"Links", "Others"}, + {"Lynx", "Others"}, + {"Midori", "Others"}, + {"Minefield", "Others"}, + {"Mosaic", "Others"}, + {"Netscape", "Others"}, + {"SeaMonkey", "Others"}, + {"UCBrowser", "Others"}, + {"Wget", "Others"}, + {"libfetch", "Others"}, + {"check_http", "Others"}, + {"Go-http-client", "Others"}, + {"curl", "Others"}, + {"midori", "Others"}, + {"w3m", "Others"}, + {"MicroMessenger", "Others"}, + {"Apache", "Others"}, + {"JOSM", "Others"}, + {"pacman", "Others"}, + {"Pamac", "Others"}, + {"libwww-perl", "Others"}, + {"python-requests", "Others"}, + {"PackageKit", "Others"}, + {"F-Droid", "Others"}, + {"okhttp", "Others"}, + {"node", "Others"}, + {"PrivacyBrowser", "Others"}, + {"Transmission", "Others"}, + {"libmpv", "Others"}, + {"aria2", "Others"}, + + /* WordPress Cron */ + {"WordPress/", "Cron"}, + + /* Feed-reader-as-a-service */ + {"AppleNewsBot", "Feeds"}, + {"Bloglines", "Feeds"}, + {"Digg Feed Fetcher", "Feeds"}, + {"Feedbin", "Feeds"}, + {"FeedHQ", "Feeds"}, + {"Feedly", "Feeds"}, + {"Flipboard", "Feeds"}, + {"inoreader.com", "Feeds"}, + {"Netvibes", "Feeds"}, + {"NewsBlur", "Feeds"}, + {"PinRSS", "Feeds"}, + {"theoldreader.com", "Feeds"}, + {"WordPress.com Reader", "Feeds"}, + {"YandexBlogs", "Feeds"}, + {"Brainstorm", "Feeds"}, + {"Mastodon", "Feeds"}, + {"Pleroma", "Feeds"}, + + /* Google crawlers (some based on Chrome, + * therefore up on the list) */ + {"AdsBot-Google", "Crawlers"}, + {"AppEngine-Google", "Crawlers"}, + {"Mediapartners-Google", "Crawlers"}, + {"Google", "Crawlers"}, + {"WhatsApp", "Crawlers"}, + + /* Based on Firefox */ + {"Camino", "Others"}, + /* Rebranded Firefox but is really unmodified + * Firefox (Debian trademark policy) */ + {"Iceweasel", "Firefox"}, + {"Waterfox", "Firefox"}, + {"PaleMoon", "Firefox"}, + {"Focus", "Firefox"}, + /* Klar is the name of Firefox Focus in the German market. */ + {"Klar", "Firefox"}, + {"Firefox", "Firefox"}, + + /* Based on Chromium */ + {"BeakerBrowser", "Beaker"}, + {"Brave", "Brave"}, + {"Vivaldi", "Vivaldi"}, + {"YaBrowser", "Yandex.Browser"}, + + /* Chrome has to go before Safari */ + {"HeadlessChrome", "Chrome"}, + {"Chrome", "Chrome"}, + {"CriOS", "Chrome"}, + + /* Crawlers/Bots (Possible Safari based) */ + {"AppleBot", "Crawlers"}, + {"facebookexternalhit", "Crawlers"}, + {"Twitter", "Crawlers"}, + + {"Safari", "Safari"}, + + /* Crawlers/Bots */ + {"Slack", "Crawlers"}, + {"Sogou", "Crawlers"}, + {"Java", "Crawlers"}, + {"Jakarta Commons-HttpClient", "Crawlers"}, + {"netEstate", "Crawlers"}, + {"PiplBot", "Crawlers"}, + {"IstellaBot", "Crawlers"}, + {"heritrix", "Crawlers"}, + {"PagesInventory", "Crawlers"}, + {"rogerbot", "Crawlers"}, + {"fastbot", "Crawlers"}, + {"yacybot", "Crawlers"}, + {"PycURL", "Crawlers"}, + {"PHP", "Crawlers"}, + {"ClaudeBot", "Crawlers"}, + {"AndroidDownloadManager", "Crawlers"}, + {"Embedly", "Crawlers"}, + {"ruby", "Crawlers"}, + {"Ruby", "Crawlers"}, + {"python", "Crawlers"}, + {"Python", "Crawlers"}, + {"LinkedIn", "Crawlers"}, + {"Microsoft-WebDAV", "Crawlers"}, + {"DuckDuckGo", "Crawlers"}, + {"bingbot", "Crawlers"}, + {"PetalBot", "Crawlers"}, + {"Discordbot", "Crawlers"}, + {"ZoominfoBot", "Crawlers"}, + {"Googlebot", "Crawlers"}, + {"DotBot", "Crawlers"}, + {"AhrefsBot", "Crawlers"}, + {"SemrushBot", "Crawlers"}, + {"Adsbot", "Crawlers"}, + {"BLEXBot", "Crawlers"}, + {"NetcraftSurveyAgent", "Crawlers"}, + {"Netcraft Web Server Survey", "Crawlers"}, + {"masscan", "Crawlers"}, + {"MJ12bot", "Crawlers"}, + {"Pandalytics", "Crawlers"}, + {"YandexBot", "Crawlers"}, + {"Nimbostratus-Bot", "Crawlers"}, + {"HTTP Banner Detection", "Crawlers"}, + {"Hakai", "Crawlers"}, + {"WinHttp.WinHttpRequest.5", "Crawlers"}, + {"NetSystemsResearch", "Crawlers"}, + {"Nextcloud Server Crawler", "Crawlers"}, + {"CFNetwork", "Crawlers"}, + {"GoScraper", "Crawlers"}, + {"Googlebot-Image", "Crawlers"}, + {"ZmEu", "Crawlers"}, + {"DowntimeDetector", "Crawlers"}, + {"MauiBot", "Crawlers"}, + {"stagefright", "Crawlers"}, + {"ImagesiftBot", "Crawlers"}, + {"Bytespider", "Crawlers"}, + {"ZoteroTranslationServer", "Cralwers"}, /* Nodeja Zotero Translation Server https://github.com/zotero/translation-server */ + + /* HTTP Library or HTTP Server User Agents - Suggest New Category */ + {"axios", "HTTP Library"}, /* NodeJS axios axios-http.com */ + {"lua-resty-http", "HTTP Library"}, /* Nginx lua-resty-http module */ + + /* Citation Services */ + {"Citoid", "Citation"}, /* MediaWiki Citoid Citation Service https://www.mediawiki.org/wiki/Citoid */ + {"EasyBib", "Citation"}, /* Easybib Citation https://easybib.com */ + + /* Podcast fetchers */ + {"Downcast", "Podcasts"}, + {"gPodder", "Podcasts"}, + {"Instacast", "Podcasts"}, + {"iTunes", "Podcasts"}, + {"Miro", "Podcasts"}, + {"Pocket Casts", "Podcasts"}, + {"BashPodder", "Podcasts"}, + + /* Feed reader clients */ + {"Akregator", "Feeds"}, + {"Apple-PubSub", "Feeds"}, + {"BTWebClient", "Feeds"}, + {"com.apple.Safari.WebFeedParser", "Feeds"}, + {"FeedDemon", "Feeds"}, + {"Feedy", "Feeds"}, + {"Fever", "Feeds"}, + {"FreshRSS", "Feeds"}, + {"Liferea", "Feeds"}, + {"NetNewsWire", "Feeds"}, + {"RSSOwl", "Feeds"}, + {"Tiny Tiny RSS", "Feeds"}, + {"Thunderbird", "Feeds"}, + {"Winds", "Feeds"}, + + /* Uptime and Monitoring clients */ + {"Pingdom.com", "Uptime"}, + {"jetmon", "Uptime"}, + {"NodeUptime", "Uptime"}, + {"NewRelicPinger", "Uptime"}, + {"StatusCake", "Uptime"}, + {"internetVista", "Uptime"}, + {"Server Density Service Monitoring v2", "Uptime"}, + {"Better Uptime Bot", "Uptime"}, + {"Site24x7", "Uptime"}, + {"Uptime-Kuma", "Uptime"}, + + /* Performance and Caching - Suggest a new category */ + {"ShortPixel", "Performance"}, /* Image Optimization */ + {"WP Rocket", "Caching"}, /* Preloading Cache for WordPress Plugin */ + + /* Security - Suggest a new category */ + {"Barracuda Sentinel", "Security"}, /* Barricuda spear fishing service */ + {"ACI Site Scanner", "Security"}, /* Can't confirm specific vendor */ + + + {"Mozilla", "Others"} +}; + +/* Free all browser entries from our array of key/value pairs. */ +void +free_browsers_hash (void) { + size_t i; + int j; + + for (i = 0; i < ARRAY_SIZE (browsers); ++i) { + free (browsers_hash[i][0]); + free (browsers_hash[i][1]); + free (browsers_hash[i]); + } + free (browsers_hash); + + + for (j = 0; j < conf.browsers_hash_idx; ++j) { + free (conf.user_browsers_hash[j][0]); + free (conf.user_browsers_hash[j][1]); + free (conf.user_browsers_hash[j]); + } + if (conf.browsers_file) { + free (conf.user_browsers_hash); + } +} + +static int +is_dup (char ***list, int len, const char *browser) { + int i; + /* check for dups */ + for (i = 0; i < len; ++i) { + if (strcmp (browser, list[i][0]) == 0) + return 1; + } + return 0; +} + +/* Set a browser/type pair into our multidimensional array of browsers. + * + * On duplicate functions returns void. + * Otherwise memory is mallo'd for our array entry. */ +static void +set_browser (char ***list, int idx, const char *browser, const char *type) { + list[idx] = xcalloc (2, sizeof (char *)); + list[idx][0] = xstrdup (browser); + list[idx][1] = xstrdup (type); +} + +/* Parse the key/value pair from the browser list file. */ +static void +parse_browser_token (char ***list, char *line, int n) { + char *val; + size_t idx = 0; + + /* key */ + idx = strcspn (line, "\t"); + if (strlen (line) == idx) + FATAL ("Malformed browser name at line: %d", n); + + line[idx] = '\0'; + + /* value */ + val = line + (idx + 1); + idx = strspn (val, "\t"); + if (strlen (val) == idx) + FATAL ("Malformed browser category at line: %d", n); + val = val + idx; + val = trim_str (val); + + if (is_dup (list, conf.browsers_hash_idx, line)) { + LOG_INVALID (("Duplicate browser entry: %s", line)); + return; + } + + set_browser (list, conf.browsers_hash_idx, line, val); + conf.browsers_hash_idx++; +} + +/* Parse our default array of browsers and put them on our hash including those + * from the custom parsed browsers file. + * + * On error functions returns void. + * Otherwise browser entries are put into the hash. */ +void +parse_browsers_file (void) { + char line[MAX_LINE_BROWSERS + 1]; + FILE *file; + int n = 0; + size_t i, len = ARRAY_SIZE (browsers); + + browsers_hash = xmalloc (ARRAY_SIZE (browsers) * sizeof (char **)); + /* load hash from the browser's array (default) */ + for (i = 0; i < len; ++i) { + set_browser (browsers_hash, i, browsers[i][0], browsers[i][1]); + } + + if (!conf.browsers_file) + return; + + /* could not open browsers file */ + if ((file = fopen (conf.browsers_file, "r")) == NULL) + FATAL ("Unable to open browser's file: %s", strerror (errno)); + + conf.user_browsers_hash = xmalloc (MAX_CUSTOM_BROWSERS * sizeof (char **)); + /* load hash from the user's given browsers file */ + while (fgets (line, sizeof line, file) != NULL) { + while (line[0] == ' ' || line[0] == '\t') + memmove (line, line + 1, strlen (line)); + n++; + + if (line[0] == '\n' || line[0] == '\r' || line[0] == '#') + continue; + if (conf.browsers_hash_idx >= MAX_CUSTOM_BROWSERS) + FATAL ("Maximum number of custom browsers has been reached"); + parse_browser_token (conf.user_browsers_hash, line, n); + } + fclose (file); +} + +/* Determine if the user-agent is a crawler. + * + * On error or is not a crawler, 0 is returned. + * If it is a crawler, 1 is returned . */ +int +is_crawler (const char *agent) { + char btype[BROWSER_TYPE_LEN]; + char *browser, *a; + + if (agent == NULL || *agent == '\0') + return 0; + + if ((a = xstrdup (agent), browser = verify_browser (a, btype)) != NULL) + free (browser); + free (a); + + return strcmp (btype, "Crawlers") == 0 ? 1 : 0; +} + +/* Return the Opera 15 and beyond. + * + * On success, the opera string and version is returned. */ +static char * +parse_opera (char *token) { + char *val = xmalloc (snprintf (NULL, 0, "Opera%s", token) + 1); + sprintf (val, "Opera%s", token); + + return val; +} + +/* Given the original user agent string, and a partial crawler match, iterate + * back until the next delimiter is found and return occurrence. + * + * On error when attempting to extract crawler, NULL is returned. + * If a possible crawler string is matched, then possible bot is returned . */ +static char * +parse_crawler (char *str, char *match, char *type) { + char *ptr = NULL; + int found = 0; + + while (match != str) { + match--; + if (*match == ' ' || *match == '+' || match == str) { + found = 1; + break; + } + } + + /* same addr */ + if (!found && match == str) + return NULL; + + /* account for the previous +|space */ + if (found && match != str) + match++; + + if ((ptr = strpbrk (match, "; "))) + *ptr = '\0'; + /* empty string after parsing it */ + if (*match == '\0') + return NULL; + + xstrncpy (type, "Crawlers", BROWSER_TYPE_LEN); + + return xstrdup (match); +} + +/* If the following string matches are found within user agent, then it's + * highly likely it's a possible crawler. + * Note that this could certainly return false positives. + * + * If no occurrences are found, NULL is returned. + * If an occurrence is found, a pointer to the match is returned . */ +static char * +check_http_crawler (const char *str) { + char *match = NULL; + + /* e.g., compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm */ + if ((match = strstr (str, "; +http"))) + return match; + /* compatible; UptimeRobot/2.0; http://www.uptimerobot.com/ */ + if ((match = strstr (str, "; http"))) + return match; + /* Slack-ImgProxy (+https://api.slack.com/robots) */ + if ((match = strstr (str, " (+http"))) + return match; + /* TurnitinBot/3.0 (http://www.turnitin.com/robot/crawlerinfo.html) */ + if ((match = strstr (str, " (http"))) + return match; + /* w3c e.g., (compatible;+Googlebot/2.1;++http://www.google.com/bot.html) */ + if ((match = strstr (str, ";++http"))) + return match; + return NULL; +} + +/* Parse the given user agent match and extract the browser string. + * + * If no match, the original match is returned. + * Otherwise the parsed browser is returned. */ +static char * +parse_browser (char *match, char *type, int i, char ***hash) { + char *b = NULL, *ptr = NULL, *slh = NULL; + size_t cnt = 0, space = 0; + + match = char_replace (match, '+', '-'); + /* Check if there are spaces in the token string, that way strpbrk + * does not stop at the first space within the token string */ + if ((cnt = count_matches (hash[i][0], ' ')) && (b = match)) { + while (space++ < cnt && (b = strchr (b, ' '))) + b++; + } else + b = match; + + xstrncpy (type, hash[i][1], BROWSER_TYPE_LEN); + /* Internet Explorer 11 */ + if (strstr (match, "rv:11") && strstr (match, "Trident/7.0")) { + return alloc_string ("MSIE/11.0"); + } + /* Opera +15 uses OPR/# */ + if (strstr (match, "OPR") != NULL && (slh = strrchr (match, '/'))) { + return parse_opera (slh); + } + /* Opera has the version number at the end */ + if (strstr (match, "Opera") && (slh = strrchr (match, '/')) && match < slh) { + memmove (match + 5, slh, strlen (slh) + 1); + } + /* IE Old */ + if (strstr (match, "MSIE") != NULL) { + if ((ptr = strpbrk (match, ";)-")) != NULL) + *ptr = '\0'; + match = char_replace (match, ' ', '/'); + } + /* all others */ + else if ((ptr = strpbrk (b ? b : match, ";) ")) != NULL) { + *ptr = '\0'; + } + + return alloc_string (match); +} + +/* Given a user agent, determine the browser used. + * + * ###NOTE: The size of the list is proportional to the run time, + * which makes this pretty slow + * + * On error, NULL is returned. + * On success, a malloc'd string containing the browser is returned. */ +char * +verify_browser (char *str, char *type) { + char *match = NULL, *token = NULL; + int i = 0; + size_t j = 0; + + if (str == NULL || *str == '\0') + return NULL; + + /* check user's list */ + for (i = 0; i < conf.browsers_hash_idx; ++i) { + if ((match = strstr (str, conf.user_browsers_hash[i][0])) == NULL) + continue; + return parse_browser (match, type, i, conf.user_browsers_hash); + } + + /* try heuristics */ + if ((match = check_http_crawler (str)) && (token = parse_crawler (str, match, type))) + return token; + + /* fallback to default browser list */ + for (j = 0; j < ARRAY_SIZE (browsers); ++j) { + if ((match = strstr (str, browsers_hash[j][0])) == NULL) + continue; + return parse_browser (match, type, j, browsers_hash); + } + + if (conf.unknowns_log) + LOG_UNKNOWNS (("%-7s%s\n", "[BR]", str)); + + if (conf.unknowns_as_crawlers && strcmp (type, "Crawlers")) + xstrncpy (type, "Crawlers", BROWSER_TYPE_LEN); + else + xstrncpy (type, "Unknown", BROWSER_TYPE_LEN); + + return alloc_string ("Unknown"); +} diff --git a/src/browsers.h b/src/browsers.h new file mode 100644 index 0000000000..6523c9d1c0 --- /dev/null +++ b/src/browsers.h @@ -0,0 +1,48 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef BROWSERS_H_INCLUDED +#define BROWSERS_H_INCLUDED + +#define BROWSER_TYPE_LEN 13 +#define MAX_LINE_BROWSERS 128 +#define MAX_CUSTOM_BROWSERS 256 + +/* Each Browser contains the number of hits and the Browser's type */ +typedef struct GBrowser_ { + char browser_type[BROWSER_TYPE_LEN]; + int hits; +} GBrowser; + +char *verify_browser (char *str, char *browser_type); +int is_crawler (const char *agent); +void free_browsers_hash (void); +void parse_browsers_file (void); + +#endif diff --git a/src/color.c b/src/color.c new file mode 100644 index 0000000000..3bfaea7d2d --- /dev/null +++ b/src/color.c @@ -0,0 +1,806 @@ +/** + * color.c -- functions related to custom color + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "color.h" + +#include "error.h" +#include "gslist.h" +#include "util.h" +#include "xmalloc.h" + +static GSLList *color_list = NULL; +static GSLList *pair_list = NULL; + +/* *INDENT-OFF* */ +static const GEnum CSTM_COLORS[] = { + {"COLOR_MTRC_HITS" , COLOR_MTRC_HITS}, + {"COLOR_MTRC_VISITORS" , COLOR_MTRC_VISITORS}, + {"COLOR_MTRC_HITS_PERC" , COLOR_MTRC_HITS_PERC}, + {"COLOR_MTRC_VISITORS_PERC" , COLOR_MTRC_VISITORS_PERC}, + {"COLOR_MTRC_BW" , COLOR_MTRC_BW}, + {"COLOR_MTRC_AVGTS" , COLOR_MTRC_AVGTS}, + {"COLOR_MTRC_CUMTS" , COLOR_MTRC_CUMTS}, + {"COLOR_MTRC_MAXTS" , COLOR_MTRC_MAXTS}, + {"COLOR_MTRC_PROT" , COLOR_MTRC_PROT}, + {"COLOR_MTRC_MTHD" , COLOR_MTRC_MTHD}, + {"COLOR_MTRC_DATA" , COLOR_MTRC_DATA}, + {"COLOR_MTRC_HITS_PERC_MAX" , COLOR_MTRC_HITS_PERC_MAX}, + {"COLOR_MTRC_VISITORS_PERC_MAX" , COLOR_MTRC_VISITORS_PERC_MAX}, + {"COLOR_PANEL_COLS" , COLOR_PANEL_COLS}, + {"COLOR_BARS" , COLOR_BARS}, + {"COLOR_ERROR" , COLOR_ERROR}, + {"COLOR_SELECTED" , COLOR_SELECTED}, + {"COLOR_PANEL_ACTIVE" , COLOR_PANEL_ACTIVE}, + {"COLOR_PANEL_HEADER" , COLOR_PANEL_HEADER}, + {"COLOR_PANEL_DESC" , COLOR_PANEL_DESC}, + {"COLOR_OVERALL_LBLS" , COLOR_OVERALL_LBLS}, + {"COLOR_OVERALL_VALS" , COLOR_OVERALL_VALS}, + {"COLOR_OVERALL_PATH" , COLOR_OVERALL_PATH}, + {"COLOR_ACTIVE_LABEL" , COLOR_ACTIVE_LABEL}, + {"COLOR_BG" , COLOR_BG}, + {"COLOR_DEFAULT" , COLOR_DEFAULT}, + {"COLOR_PROGRESS" , COLOR_PROGRESS}, +}; + +static const char *const colors256_mono[] = { + "COLOR_MTRC_HITS color7:color-1", + "COLOR_MTRC_VISITORS color8:color-1", + "COLOR_MTRC_DATA color7:color-1", + "COLOR_MTRC_BW color8:color-1", + "COLOR_MTRC_AVGTS color8:color-1", + "COLOR_MTRC_CUMTS color8:color-1", + "COLOR_MTRC_MAXTS color8:color-1", + "COLOR_MTRC_PROT color8:color-1", + "COLOR_MTRC_MTHD color7:color-1", + "COLOR_MTRC_HITS_PERC color0:color-1 bold", + "COLOR_MTRC_HITS_PERC color1:color-1 bold VISITORS", + "COLOR_MTRC_HITS_PERC color1:color-1 bold OS", + "COLOR_MTRC_HITS_PERC color1:color-1 bold BROWSERS", + "COLOR_MTRC_HITS_PERC color1:color-1 bold VISIT_TIMES", + "COLOR_MTRC_HITS_PERC_MAX color0:color-1 bold", + "COLOR_MTRC_HITS_PERC_MAX color3:color-1 bold VISITORS", + "COLOR_MTRC_HITS_PERC_MAX color3:color-1 bold OS", + "COLOR_MTRC_HITS_PERC_MAX color3:color-1 bold BROWSERS", + "COLOR_MTRC_HITS_PERC_MAX color3:color-1 bold VISIT_TIMES", + "COLOR_MTRC_VISITORS_PERC color0:color-1 bold", + "COLOR_MTRC_VISITORS_PERC_MAX color0:color-1 bold", + "COLOR_PANEL_COLS color7:color-1", + "COLOR_BARS color7:color-1", + "COLOR_ERROR color7:color1", + "COLOR_SELECTED color7:color8", + "COLOR_PANEL_ACTIVE color0:color3", + "COLOR_PANEL_HEADER color0:color7", + "COLOR_PANEL_DESC color7:color-1", + "COLOR_OVERALL_LBLS color7:color-1 bold", + "COLOR_OVERALL_VALS color6:color-1 bold", + "COLOR_OVERALL_PATH color3:color-1", + "COLOR_ACTIVE_LABEL color4:color7", + "COLOR_BG color7:color-1", + "COLOR_DEFAULT color7:color-1", + "COLOR_PROGRESS color0:color6", +}; + +static const char *const colors256_green[] = { + "COLOR_MTRC_HITS color7:color-1", + "COLOR_MTRC_VISITORS color8:color-1", + "COLOR_MTRC_DATA color7:color-1", + "COLOR_MTRC_BW color8:color-1", + "COLOR_MTRC_AVGTS color8:color-1", + "COLOR_MTRC_CUMTS color8:color-1", + "COLOR_MTRC_MAXTS color8:color-1", + "COLOR_MTRC_PROT color8:color-1", + "COLOR_MTRC_MTHD color7:color-1", + "COLOR_MTRC_HITS_PERC color0:color-1 bold", + "COLOR_MTRC_HITS_PERC color1:color-1 bold VISITORS", + "COLOR_MTRC_HITS_PERC color1:color-1 bold OS", + "COLOR_MTRC_HITS_PERC color1:color-1 bold BROWSERS", + "COLOR_MTRC_HITS_PERC color1:color-1 bold VISIT_TIMES", + "COLOR_MTRC_HITS_PERC_MAX color0:color-1 bold", + "COLOR_MTRC_HITS_PERC_MAX color3:color-1 bold VISITORS", + "COLOR_MTRC_HITS_PERC_MAX color3:color-1 bold OS", + "COLOR_MTRC_HITS_PERC_MAX color3:color-1 bold BROWSERS", + "COLOR_MTRC_HITS_PERC_MAX color3:color-1 bold VISIT_TIMES", + "COLOR_MTRC_VISITORS_PERC color0:color-1 bold", + "COLOR_MTRC_VISITORS_PERC_MAX color0:color-1 bold", + "COLOR_PANEL_COLS color7:color-1", + "COLOR_BARS color7:color-1", + "COLOR_ERROR color7:color1", + "COLOR_SELECTED color7:color8", + "COLOR_PANEL_ACTIVE color0:color3", + "COLOR_PANEL_HEADER color0:color35", + "COLOR_PANEL_DESC color7:color-1", + "COLOR_OVERALL_LBLS color7:color-1 bold", + "COLOR_OVERALL_VALS color6:color-1 bold", + "COLOR_OVERALL_PATH color3:color-1", + "COLOR_ACTIVE_LABEL color7:color35", + "COLOR_BG color7:color-1", + "COLOR_DEFAULT color7:color-1", + "COLOR_PROGRESS color0:color6", +}; + +static const char *const colors256_monokai[] = { + "COLOR_MTRC_HITS color197:color-1", + "COLOR_MTRC_VISITORS color148:color-1", + "COLOR_MTRC_DATA color7:color-1", + "COLOR_MTRC_BW color81:color-1", + "COLOR_MTRC_AVGTS color247:color-1", + "COLOR_MTRC_CUMTS color95:color-1", + "COLOR_MTRC_MAXTS color186:color-1", + "COLOR_MTRC_PROT color141:color-1", + "COLOR_MTRC_MTHD color81:color-1", + "COLOR_MTRC_HITS_PERC color186:color-1", + "COLOR_MTRC_HITS_PERC color186:color-1 VISITORS", + "COLOR_MTRC_HITS_PERC color186:color-1 OS", + "COLOR_MTRC_HITS_PERC color186:color-1 BROWSERS", + "COLOR_MTRC_HITS_PERC color186:color-1 VISIT_TIMES", + "COLOR_MTRC_HITS_PERC_MAX color208:color-1", + "COLOR_MTRC_HITS_PERC_MAX color208:color-1 VISITORS", + "COLOR_MTRC_HITS_PERC_MAX color208:color-1 OS", + "COLOR_MTRC_HITS_PERC_MAX color208:color-1 BROWSERS", + "COLOR_MTRC_HITS_PERC_MAX color208:color-1 VISIT_TIMES", + "COLOR_MTRC_VISITORS_PERC color187:color-1", + "COLOR_MTRC_VISITORS_PERC_MAX color208:color-1", + "COLOR_PANEL_COLS color242:color-1", + "COLOR_BARS color186:color-1", + "COLOR_ERROR color231:color197", + "COLOR_SELECTED color0:color215", + "COLOR_PANEL_ACTIVE color7:color240", + "COLOR_PANEL_HEADER color7:color237", + "COLOR_PANEL_DESC color242:color-1", + "COLOR_OVERALL_LBLS color251:color-1", + "COLOR_OVERALL_VALS color148:color-1", + "COLOR_OVERALL_PATH color186:color-1", + "COLOR_ACTIVE_LABEL color7:color237", + "COLOR_BG color7:color-1", + "COLOR_DEFAULT color7:color-1", + "COLOR_PROGRESS color7:color141", +}; + +static const char *const colors8_mono[] = { + "COLOR_MTRC_HITS color7:color-1", + "COLOR_MTRC_VISITORS color0:color-1 bold", + "COLOR_MTRC_DATA color7:color-1", + "COLOR_MTRC_BW color0:color-1 bold", + "COLOR_MTRC_AVGTS color0:color-1 bold", + "COLOR_MTRC_CUMTS color0:color-1 bold", + "COLOR_MTRC_MAXTS color0:color-1 bold", + "COLOR_MTRC_PROT color0:color-1 bold", + "COLOR_MTRC_MTHD color7:color-1 ", + "COLOR_MTRC_HITS_PERC color0:color-1 bold", + "COLOR_MTRC_HITS_PERC color1:color-1 bold VISITORS", + "COLOR_MTRC_HITS_PERC color1:color-1 bold OS", + "COLOR_MTRC_HITS_PERC color1:color-1 bold BROWSERS", + "COLOR_MTRC_HITS_PERC color1:color-1 bold VISIT_TIMES", + "COLOR_MTRC_HITS_PERC_MAX color0:color-1 bold", + "COLOR_MTRC_HITS_PERC_MAX color3:color-1 bold VISITORS", + "COLOR_MTRC_HITS_PERC_MAX color3:color-1 bold OS", + "COLOR_MTRC_HITS_PERC_MAX color3:color-1 bold BROWSERS", + "COLOR_MTRC_HITS_PERC_MAX color3:color-1 bold VISIT_TIMES", + "COLOR_MTRC_VISITORS_PERC color0:color-1 bold", + "COLOR_MTRC_VISITORS_PERC_MAX color0:color-1 bold", + "COLOR_PANEL_COLS color7:color-1", + "COLOR_BARS color7:color-1", + "COLOR_ERROR color7:color1", + "COLOR_SELECTED color0:color7", + "COLOR_PANEL_ACTIVE color0:color3", + "COLOR_PANEL_HEADER color0:color7", + "COLOR_PANEL_DESC color7:color-1", + "COLOR_OVERALL_LBLS color7:color-1 bold", + "COLOR_OVERALL_VALS color6:color-1", + "COLOR_OVERALL_PATH color3:color-1", + "COLOR_ACTIVE_LABEL color4:color7", + "COLOR_BG color7:color-1", + "COLOR_DEFAULT color7:color-1", + "COLOR_PROGRESS color0:color6", +}; + +static const char *const colors8_green[] = { + "COLOR_MTRC_HITS color7:color-1", + "COLOR_MTRC_VISITORS color0:color-1 bold", + "COLOR_MTRC_DATA color7:color-1", + "COLOR_MTRC_BW color0:color-1 bold", + "COLOR_MTRC_AVGTS color0:color-1 bold", + "COLOR_MTRC_CUMTS color0:color-1 bold", + "COLOR_MTRC_MAXTS color0:color-1 bold", + "COLOR_MTRC_PROT color0:color-1 bold", + "COLOR_MTRC_MTHD color7:color-1 ", + "COLOR_MTRC_HITS_PERC color0:color-1 bold", + "COLOR_MTRC_HITS_PERC color1:color-1 bold VISITORS", + "COLOR_MTRC_HITS_PERC color1:color-1 bold OS", + "COLOR_MTRC_HITS_PERC color1:color-1 bold BROWSERS", + "COLOR_MTRC_HITS_PERC color1:color-1 bold VISIT_TIMES", + "COLOR_MTRC_HITS_PERC_MAX color0:color-1 bold", + "COLOR_MTRC_HITS_PERC_MAX color3:color-1 bold VISITORS", + "COLOR_MTRC_HITS_PERC_MAX color3:color-1 bold OS", + "COLOR_MTRC_HITS_PERC_MAX color3:color-1 bold BROWSERS", + "COLOR_MTRC_HITS_PERC_MAX color3:color-1 bold VISIT_TIMES", + "COLOR_MTRC_VISITORS_PERC color0:color-1 bold", + "COLOR_MTRC_VISITORS_PERC_MAX color0:color-1 bold", + "COLOR_PANEL_COLS color7:color-1", + "COLOR_BARS color2:color-1", + "COLOR_ERROR color7:color1", + "COLOR_SELECTED color0:color7", + "COLOR_PANEL_ACTIVE color0:color3", + "COLOR_PANEL_HEADER color0:color2", + "COLOR_PANEL_DESC color7:color-1", + "COLOR_OVERALL_LBLS color7:color-1 bold", + "COLOR_OVERALL_VALS color6:color-1", + "COLOR_OVERALL_PATH color3:color-1", + "COLOR_ACTIVE_LABEL color0:color2", + "COLOR_BG color7:color-1", + "COLOR_DEFAULT color7:color-1", + "COLOR_PROGRESS color0:color6", +}; + +static const char *const nocolors[] = { + "COLOR_MTRC_HITS color0:color-1", + "COLOR_MTRC_VISITORS color0:color-1", + "COLOR_MTRC_DATA color0:color-1", + "COLOR_MTRC_BW color0:color-1", + "COLOR_MTRC_AVGTS color0:color-1", + "COLOR_MTRC_CUMTS color0:color-1", + "COLOR_MTRC_MAXTS color0:color-1", + "COLOR_MTRC_PROT color0:color-1", + "COLOR_MTRC_MTHD color0:color-1", + "COLOR_MTRC_HITS_PERC color0:color-1", + "COLOR_MTRC_HITS_PERC_MAX color0:color-1", + "COLOR_MTRC_VISITORS_PERC color0:color-1", + "COLOR_MTRC_VISITORS_PERC_MAX color0:color-1", + "COLOR_PANEL_COLS color0:color-1", + "COLOR_BARS color0:color-1", + "COLOR_ERROR color0:color-1", + "COLOR_SELECTED color0:color-1 reverse", + "COLOR_PANEL_ACTIVE color0:color-1 reverse", + "COLOR_PANEL_HEADER color0:color-1 reverse", + "COLOR_PANEL_DESC color0:color-1", + "COLOR_OVERALL_LBLS color0:color-1", + "COLOR_OVERALL_VALS color0:color-1", + "COLOR_OVERALL_PATH color0:color-1", + "COLOR_ACTIVE_LABEL color0:color-1 reverse", + "COLOR_BG color0:color-1", + "COLOR_DEFAULT color0:color-1", + "COLOR_PROGRESS color0:color-1 reverse", +}; + +/* *INDENT-ON* */ + +/* Allocate memory for color elements */ +static GColors * +new_gcolors (void) { + GColors *color = xcalloc (1, sizeof (GColors)); + color->module = -1; + + return color; +} + +/* Allocate memory for a color element properties */ +static GColorPair * +new_gcolorpair (void) { + GColorPair *pair = xcalloc (1, sizeof (GColorPair)); + /* Must be between 2 and COLOR_PAIRS-1. + * Starts at 2 since COLOR_NORMAL has already been set */ + pair->idx = 2; + + return pair; +} + +/* Free malloc'd memory for color elements */ +void +free_color_lists (void) { + if (pair_list) + list_remove_nodes (pair_list); + if (color_list) + list_remove_nodes (color_list); + color_list = NULL; + pair_list = NULL; +} + +/* Set a default color - COLOR_NORMAL, this will be used if + * no colors are supported by the terminal */ +void +set_normal_color (void) { + GColorPair *pair = new_gcolorpair (); + GColors *color = new_gcolors (); + + pair->idx = 1; + pair->fg = COLOR_WHITE; + pair->bg = -1; + + color->pair = pair; + color->item = COLOR_NORMAL; + + pair_list = list_create (pair); + color_list = list_create (color); + + init_pair (pair->idx, pair->fg, pair->bg); +} + +/* Get color properties for COLOR_OVERALL_LBLS */ +GColors * +color_overall_lbls (void) { + return get_color (COLOR_OVERALL_LBLS); +} + +/* Get color properties for COLOR_OVERALL_VALS */ +GColors * +color_overall_vals (void) { + return get_color (COLOR_OVERALL_VALS); +} + +/* Get color properties for COLOR_OVERALL_PATH */ +GColors * +color_overall_path (void) { + return get_color (COLOR_OVERALL_PATH); +} + +/* Get color properties for COLOR_PANEL_HEADER */ +GColors * +color_panel_header (void) { + return get_color (COLOR_PANEL_HEADER); +} + +/* Get color properties for COLOR_PANEL_DESC */ +GColors * +color_panel_desc (void) { + return get_color (COLOR_PANEL_DESC); +} + +/* Get color properties for COLOR_PANEL_ACTIVE*/ +GColors * +color_panel_active (void) { + return get_color (COLOR_PANEL_ACTIVE); +} + +/* Get color properties for COLOR_SELECTED */ +GColors * +color_selected (void) { + return get_color (COLOR_SELECTED); +} + +/* Get color properties for COLOR_PROGRESS */ +GColors * +color_progress (void) { + return get_color (COLOR_PROGRESS); +} + +/* Get color properties for COLOR_DEFAULT */ +GColors * +color_default (void) { + return get_color (COLOR_DEFAULT); +} + +/* Get color properties for COLOR_ERROR */ +GColors * +color_error (void) { + return get_color (COLOR_ERROR); +} + +/* Get the enumerated color given its equivalent color string. + * + * On error, -1 is returned. + * On success, the enumerated color is returned. */ +static int +get_color_item_enum (const char *str) { + return str2enum (CSTM_COLORS, ARRAY_SIZE (CSTM_COLORS), str); +} + +/* Extract color number from the given config string. + * + * On error, -2 is returned. If color is greater than max colors, it aborts. + * On success, the color number is returned. */ +static int +extract_color (char *color) { + char *sEnd; + int col = 0; + + if (strncasecmp (color, "color", 5) != 0) + return -2; + + color += 5; + col = strtol (color, &sEnd, 10); + if (color == sEnd || *sEnd != '\0' || errno == ERANGE) + return -2; + /* ensure used color is supported by the terminal */ + if (col > COLORS) + FATAL ("Terminal doesn't support color: %d - max colors: %d", col, COLORS); + + return col; +} + +/* Assign the background and foreground color number from the given + * config string to GColorPair. + * + * On error, 1 is returned. + * On success, 0 is returned. */ +static int +parse_bg_fg_color (GColorPair *pair, const char *value) { + char bgcolor[COLOR_STR_LEN] = "", fgcolor[COLOR_STR_LEN] = ""; + int ret = 0; + + if (sscanf (value, "%8[^:]:%8[^ ]", fgcolor, bgcolor) != 2) + return 1; + + if ((pair->bg = extract_color (bgcolor)) == -2) + ret = 1; + + if ((pair->fg = extract_color (fgcolor)) == -2) + ret = 1; + + return ret; +} + +/* Assign color attributes from the given config string to GColors. */ +static void +locate_attr_color (GColors *color, const char *attr) { + if (strstr (attr, "bold")) + color->attr |= A_BOLD; + if (strstr (attr, "underline")) + color->attr |= A_UNDERLINE; + if (strstr (attr, "normal")) + color->attr |= A_NORMAL; + if (strstr (attr, "reverse")) + color->attr |= A_REVERSE; + if (strstr (attr, "standout")) + color->attr |= A_REVERSE; + if (strstr (attr, "blink")) + color->attr |= A_BLINK; +} + +/* Parse color attributes from the given config string. + * + * On error, 1 is returned. + * On success, 0 is returned. */ +static int +parse_attr_color (GColors *color, const char *value) { + char *line, *ptr, *start; + int ret = 0; + + line = xstrdup (value); + + start = strchr (line, ' '); + if ((!start) || (!*(start + 1))) { + LOG_DEBUG (("attempted to parse color attr: %s\n", value)); + goto clean; + } + + start++; + while (1) { + if ((ptr = strpbrk (start, ", ")) != NULL) + *ptr = 0; + locate_attr_color (color, start); + if (ptr == NULL) + break; + start = ptr + 1; + } + +clean: + free (line); + + return ret; +} + +/* Parse color module from the given config string. + * + * On error, 1 is returned. + * On success, 0 is returned. */ +static int +parse_module_color (GColors *color, const char *value) { + char *line = xstrdup (value), *p; + + p = strrchr (line, ' '); + if (!p || !*(p + 1)) { + LOG_DEBUG (("attempted to parse color module: %s\n", value)); + goto clean; + } + + if ((color->module = get_module_enum (p + 1)) == -1) + LOG_DEBUG (("attempted to parse color module: %s\n", value)); + +clean: + free (line); + + return 0; +} + +/* Find a color by item and module attributes on the list of already + * parsed colors. + * + * If color exists, 1 is returned. + * If color does not exist, 1 is returned. */ +static int +find_color_in_list (void *data, void *color) { + GColors *new_color = color; + GColors *old_color = data; + + if (old_color->item != new_color->item) + return 0; + if (old_color->module != new_color->module) + return 0; + return 1; +} + +/* Find a color by foreground and background attributes on the list of + * already parsed colors. + * + * If color exists, 1 is returned. + * If color does not exist, 1 is returned. */ +static int +find_pair_in_list (void *data, void *color) { + GColorPair *new_color = color; + GColorPair *old_color = data; + + if (old_color->fg != new_color->fg) + return 0; + if (old_color->bg != new_color->bg) + return 0; + return 1; +} + +/* Compare a color item (GColorItem) that has no module with the given needle + * item. + * + * If the items match and with no module, 1 is returned. + * If condition is not satisfied, 0 is returned. */ +static int +find_color_item_in_list (void *data, void *needle) { + GColors *color = data; + GColorItem *item = needle; + + return color->item == (GColorItem) (*(int *) item) && color->module == -1; +} + +/* Compare a color item (GColorItem) and module with the given needle item. + * + * If the items match and with no module, 1 is returned. + * If condition is not satisfied, 0 is returned. */ +static int +find_color_item_module_in_list (void *data, void *needle) { + GColors *color = data; + GColors *item = needle; + + return color->item == item->item && color->module == item->module; +} + +/* Get color item properties given an item (enumerated). + * + * On error, it aborts. + * On success, the color item properties are returned, or NULL if no match + * found. */ +GColors * +get_color (GColorItem item) { + GColorItem normal = COLOR_NORMAL; + GSLList *match = NULL; + + if ((match = list_find (color_list, find_color_item_in_list, &item))) + return (GColors *) match->data; + + if ((match = list_find (color_list, find_color_item_in_list, &normal))) + return (GColors *) match->data; + + /* should not get here */ + FATAL ("Unable to find color item %d", item); +} + +/* Get color item properties given an item (enumerated) and its module. + * + * On error, it aborts. + * On success, the color item properties are returned, or NULL if no match + * found. */ +GColors * +get_color_by_item_module (GColorItem item, GModule module) { + GColors *needle = new_gcolors (), *color = NULL; + GSLList *match = NULL; + + needle->module = module; + needle->item = item; + + /* find color for specific item/module pair */ + if ((match = list_find (color_list, find_color_item_module_in_list, needle))) + color = match->data; + + /* attempt to find color by item (fallback) */ + if (!color) + color = get_color (item); + free (needle); + + return color; +} + +/* Parse a color definition line from the config file. + * + * On error, it aborts. + * On success, the color properties are assigned */ +static void +parse_color_line (GColorPair *pair, GColors *color, char *line) { + char *val; + int item = 0; + size_t idx; + + /* key */ + idx = strcspn (line, " \t"); + if (strlen (line) == idx) + FATAL ("Malformed color key at line: %s", line); + + line[idx] = '\0'; + if ((item = get_color_item_enum (line)) == -1) + FATAL ("Unable to find color key: %s", line); + + /* value */ + val = line + (idx + 1); + idx = strspn (val, " \t"); + if (strlen (val) == idx) + FATAL ("Malformed color value at line: %s", line); + val = val + idx; + + /* get background/foreground color */ + if (parse_bg_fg_color (pair, val) == 1) + FATAL ("Invalid bg/fg color pairs at: %s %s", line, val); + + if (parse_attr_color (color, val) == 1) + FATAL ("Invalid color attrs at: %s %s", line, val); + + if (parse_module_color (color, val) == 1) + FATAL ("Invalid color module at: %s %s", line, val); + + color->item = item; +} + +/* Attempt to prepend the given color on our color linked list. + * + * On error, or if color already exists, the given color is freed. + * On success, or if not color found, store color properties */ +static void +prepend_color (GColors **color) { + /* create a list of colors if one does not exist */ + if (color_list == NULL) { + color_list = list_create (*color); + } + /* attempt to find the given color data type (by item and attributes) in + * our color list */ + else if (list_find (color_list, find_color_in_list, *color)) { + /* if found, free the recently malloc'd color data type and use + * existing color */ + free (*color); + *color = NULL; + } else { + /* not a dup, so insert the new color in our color list */ + color_list = list_insert_prepend (color_list, *color); + } +} + +/* Parse a color definition line from the config file and store it on a single + * linked-list. + * + * On error, it aborts. + * On success, the color properties are stored */ +static void +parse_color (char *line) { + GSLList *match = NULL; + GColors *color = NULL; + GColorPair *pair = NULL; + + color = new_gcolors (); + pair = new_gcolorpair (); + + /* extract a color pair and color attributes from the given config line */ + parse_color_line (pair, color, line); + + /* create a pair color list if one doesn't exist */ + if (pair_list == NULL) { + pair_list = list_create (pair); + } + /* attempt to find the given color pair in our pair list */ + else if ((match = list_find (pair_list, find_pair_in_list, pair))) { + /* pair found, use new pair and free existing one */ + free (pair); + pair = (GColorPair *) match->data; + } + /* pair not found, use it then */ + else { + pair->idx += list_count (pair_list); + pair_list = list_insert_prepend (pair_list, pair); + } + /* set color pair */ + color->pair = pair; + prepend_color (&color); + + /* if no color pair was found, then we init the color pair */ + if (!match && color) + init_pair (color->pair->idx, color->pair->fg, color->pair->bg); + + free (line); +} + +/* Iterate over all color definitions in the config file. + * + * On error, it aborts. + * On success, the color properties are parsed and stored */ +static void +parse_colors (const char *const colors[], size_t n) { + char *line; + size_t i; + + for (i = 0; i < n; ++i) { + line = strdup (colors[i]); + /* did not find a valid format */ + if (strchr (line, ':') == NULL) { + free (line); + continue; + } + parse_color (line); + } +} + +/* Use default color definitions if necessary. */ +static void +add_default_colors (void) { + /* no colors */ + if (COLORS < 8) + parse_colors (nocolors, ARRAY_SIZE (nocolors)); + + /* 256 colors, and no color scheme set or set to monokai */ + if (COLORS == 256 && (!conf.color_scheme || conf.color_scheme == MONOKAI)) + parse_colors (colors256_monokai, ARRAY_SIZE (colors256_monokai)); + /* otherwise use 16 colors scheme */ + else if (COLORS > 16) { + if (conf.color_scheme == STD_GREEN) + parse_colors (colors256_green, ARRAY_SIZE (colors256_green)); + else + parse_colors (colors256_mono, ARRAY_SIZE (colors256_mono)); + } + + /* 8 colors */ + if (COLORS >= 8 && COLORS <= 16) { + if (conf.color_scheme == STD_GREEN) + parse_colors (colors8_green, ARRAY_SIZE (colors8_green)); + else + parse_colors (colors8_mono, ARRAY_SIZE (colors8_mono)); + } +} + +/* Entry point to parse color definitions or use default colors */ +void +set_colors (int force) { + errno = 0; + if (conf.color_idx > 0 && !force) + parse_colors (conf.colors, conf.color_idx); + else + add_default_colors (); +} diff --git a/src/color.h b/src/color.h new file mode 100644 index 0000000000..73d73dd0f1 --- /dev/null +++ b/src/color.h @@ -0,0 +1,109 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef COLOR_H_INCLUDED +#define COLOR_H_INCLUDED + +#define COLOR_STR_LEN 9 + +/* Color Items/Fields */ +typedef enum CSTM_COLORS { + COLOR_NORMAL, + COLOR_MTRC_HITS, + COLOR_MTRC_VISITORS, + COLOR_MTRC_DATA, + COLOR_MTRC_BW, + COLOR_MTRC_AVGTS, + COLOR_MTRC_CUMTS, + COLOR_MTRC_MAXTS, + COLOR_MTRC_PROT, + COLOR_MTRC_MTHD, + COLOR_MTRC_HITS_PERC, + COLOR_MTRC_HITS_PERC_MAX, + COLOR_MTRC_VISITORS_PERC, + COLOR_MTRC_VISITORS_PERC_MAX, + COLOR_PANEL_COLS, + COLOR_BARS, + COLOR_ERROR, + COLOR_SELECTED, + COLOR_PANEL_ACTIVE, + COLOR_PANEL_HEADER, + COLOR_PANEL_DESC, + COLOR_OVERALL_LBLS, + COLOR_OVERALL_VALS, + COLOR_OVERALL_PATH, + COLOR_ACTIVE_LABEL, + COLOR_BG, + COLOR_DEFAULT, + COLOR_PROGRESS, +} GColorItem; + +/* Default Color Schemes */ +typedef enum SCHEMES { + NO_COLOR, + MONOCHROME, + STD_GREEN, + MONOKAI, +} GSchemes; + +#include "commons.h" + +/* Each color properties */ +typedef struct GColorPair_ { + short idx; /* color pair index identifier */ + short fg; /* foreground color */ + short bg; /* background color */ +} GColorPair; + +/* Color */ +typedef struct GColors_ { + GColorItem item; /* screen item */ + GColorPair *pair; /* color pair */ + int attr; /* color attributes, e.g., bold */ + short module; /* panel */ +} GColors; + +GColors *color_default (void); +GColors *color_error (void); +GColors *color_overall_lbls (void); +GColors *color_overall_path (void); +GColors *color_overall_vals (void); +GColors *color_panel_active (void); +GColors *color_panel_desc (void); +GColors *color_panel_header (void); +GColors *color_progress (void); +GColors *color_selected (void); +GColors *get_color_by_item_module (GColorItem item, GModule module); +GColors *get_color (GColorItem item); +GColors *get_color_normal (void); +void free_color_lists (void); +void set_colors (int force); +void set_normal_color (void); + +#endif // for #ifndef COLOR_H diff --git a/src/commons.c b/src/commons.c new file mode 100644 index 0000000000..e82968d666 --- /dev/null +++ b/src/commons.c @@ -0,0 +1,508 @@ +/** + * commons.c -- holds different data types + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include + +#include "commons.h" + +#include "labels.h" +#include "settings.h" +#include "util.h" +#include "xmalloc.h" + +/* processing time */ +time_t end_proc; +time_t timestamp; +time_t start_proc; + +/* list of available modules/panels */ +int module_list[TOTAL_MODULES] = {[0 ... TOTAL_MODULES - 1] = -1 }; + +/* *INDENT-OFF* */ +/* String modules to enumerated modules */ +static const GEnum enum_modules[] = { + {"VISITORS" , VISITORS} , + {"REQUESTS" , REQUESTS} , + {"REQUESTS_STATIC" , REQUESTS_STATIC} , + {"NOT_FOUND" , NOT_FOUND} , + {"HOSTS" , HOSTS} , + {"OS" , OS} , + {"BROWSERS" , BROWSERS} , + {"VISIT_TIMES" , VISIT_TIMES} , + {"VIRTUAL_HOSTS" , VIRTUAL_HOSTS} , + {"REFERRERS" , REFERRERS} , + {"REFERRING_SITES" , REFERRING_SITES} , + {"KEYPHRASES" , KEYPHRASES} , + {"STATUS_CODES" , STATUS_CODES} , + {"REMOTE_USER" , REMOTE_USER} , + {"CACHE_STATUS" , CACHE_STATUS} , +#ifdef HAVE_GEOLOCATION + {"GEO_LOCATION" , GEO_LOCATION} , + {"ASN" , ASN} , +#endif + {"MIME_TYPE" , MIME_TYPE} , + {"TLS_TYPE" , TLS_TYPE} , +}; +/* *INDENT-ON* */ + +/* Get number of items per panel to parse. + * + * The number of items per panel is returned. */ +int +get_max_choices (void) { + char *csv = NULL, *json = NULL, *html = NULL; + int max = MAX_CHOICES; + + /* no max choices, return defaults */ + if (conf.max_items <= 0) + return conf.real_time_html ? MAX_CHOICES_RT : (conf.date_spec_hr == + 2 ? MAX_CHOICES_MINUTE : MAX_CHOICES); + + /* TERM */ + if (!conf.output_stdout) + return conf.max_items > MAX_CHOICES ? MAX_CHOICES : conf.max_items; + + /* REAL-TIME STDOUT */ + /* real time HTML, display max rt choices */ + if (conf.real_time_html) + return conf.max_items > MAX_CHOICES_RT ? MAX_CHOICES_RT : conf.max_items; + + /* STDOUT */ + /* CSV - allow n amount of choices */ + if (find_output_type (&csv, "csv", 1) == 0) + max = conf.max_items; + /* JSON - allow n amount of choices */ + if (find_output_type (&json, "json", 1) == 0 && conf.max_items > 0) + max = conf.max_items; + /* HTML - takes priority on cases where multiple outputs were given. Note that + * we check either for an .html extension or we assume not extension was passed + * via -o and therefore we are redirecting the output to a file. */ + if (find_output_type (&html, "html", 1) == 0 || conf.output_format_idx == 0) + max = conf.max_items; + + free (csv); + free (html); + free (json); + + return max; +} + +/* Calculate a percentage. + * + * The percentage is returned. */ +float +get_percentage (unsigned long long total, unsigned long long hit) { + return (total == 0 ? 0 : (((float) hit) / total) * 100); +} + +/* Display the storage being used. */ +void +display_storage (void) { + fprintf (stdout, "%s\n", BUILT_WITH_DEFHASH); +} + +/* Display the path of the default configuration file when `-p` is not used */ +void +display_default_config_file (void) { + char *path = get_config_file_path (); + + if (!path) { + fprintf (stdout, "%s\n", ERR_NODEF_CONF_FILE); + fprintf (stdout, "%s `-p /path/goaccess.conf`\n", ERR_NODEF_CONF_FILE_DESC); + } else { + fprintf (stdout, "%s\n", path); + free (path); + } +} + +/* Display the current version. */ +void +display_version (void) { + fprintf (stdout, "GoAccess - %s.\n", GO_VERSION); + fprintf (stdout, "%s: %s\n", INFO_MORE_INFO, GO_WEBSITE); + fprintf (stdout, "Copyright (C) 2009-2024 by Gerardo Orellana\n"); + fprintf (stdout, "\nBuild configure arguments:\n"); +#ifdef DEBUG + fprintf (stdout, " --enable-debug\n"); +#endif +#ifdef HAVE_NCURSESW_NCURSES_H + fprintf (stdout, " --enable-utf8\n"); +#endif +#ifdef HAVE_LIBGEOIP + fprintf (stdout, " --enable-geoip=legacy\n"); +#endif +#ifdef HAVE_LIBMAXMINDDB + fprintf (stdout, " --enable-geoip=mmdb\n"); +#endif +#ifdef WITH_GETLINE + fprintf (stdout, " --with-getline\n"); +#endif +#ifdef HAVE_LIBSSL + fprintf (stdout, " --with-openssl\n"); +#endif +} + +/* Get the enumerated value given a string. + * + * On error, -1 is returned. + * On success, the enumerated module value is returned. */ +int +str2enum (const GEnum map[], int len, const char *str) { + int i; + + for (i = 0; i < len; ++i) { + if (!strcmp (str, map[i].str)) + return map[i].idx; + } + + return -1; +} + +/* Get the string value given an enum. + * + * On error, -1 is returned. + * On success, the enumerated module value is returned. */ +const char * +enum2str (const GEnum map[], int len, int idx) { + int i; + + for (i = 0; i < len; ++i) { + if (idx == map[i].idx) + return map[i].str; + } + + return NULL; +} + +/* Get the enumerated module value given a module string. + * + * On error, -1 is returned. + * On success, the enumerated module value is returned. */ +int +get_module_enum (const char *str) { + return str2enum (enum_modules, ARRAY_SIZE (enum_modules), str); +} + +/* Get the module string value given a module enum value. + * + * On error, NULL is returned. + * On success, the string module value is returned. */ +const char * +get_module_str (GModule module) { + return enum2str (enum_modules, ARRAY_SIZE (enum_modules), module); +} + +/* Instantiate a new GAgents structure. + * + * On success, the newly malloc'd structure is returned. */ +GAgents * +new_gagents (uint32_t size) { + GAgents *agents = xmalloc (sizeof (GAgents)); + memset (agents, 0, sizeof *agents); + + agents->items = xcalloc (size, sizeof (GAgentItem)); + agents->size = size; + agents->idx = 0; + + return agents; +} + +/* Clean the array of agents. */ +void +free_agents_array (GAgents *agents) { + int i; + + if (agents == NULL) + return; + + /* clean stuff up */ + for (i = 0; i < agents->idx; ++i) + free (agents->items[i].agent); + if (agents->items) + free (agents->items); + free (agents); +} + +/* Determine if the given date format is a timestamp. + * + * If not a timestamp, 0 is returned. + * If it is a timestamp, 1 is returned. */ +int +has_timestamp (const char *fmt) { + if (strcmp ("%s", fmt) == 0 || strcmp ("%f", fmt) == 0) + return 1; + return 0; +} + +/* Determine if the given module is set to be enabled. + * + * If enabled, 1 is returned, else 0 is returned. */ +int +enable_panel (GModule mod) { + int i, module; + + for (i = 0; i < conf.enable_panel_idx; ++i) { + if ((module = get_module_enum (conf.enable_panels[i])) == -1) + continue; + if (mod == (unsigned int) module) { + return 1; + } + } + + return 0; +} + +/* Determine if the given module is set to be ignored. + * + * If ignored, 1 is returned, else 0 is returned. */ +int +ignore_panel (GModule mod) { + int i, module; + + for (i = 0; i < conf.ignore_panel_idx; ++i) { + if ((module = get_module_enum (conf.ignore_panels[i])) == -1) + continue; + if (mod == (unsigned int) module) { + return 1; + } + } + + return 0; +} + +/* Get the number of available modules/panels. + * + * The number of modules available is returned. */ +uint32_t +get_num_modules (void) { + size_t idx = 0; + uint32_t num = 0; + + FOREACH_MODULE (idx, module_list) { + num++; + } + + return num; +} + +/* Get the index from the module_list given a module. + * + * If the module is not within the array, -1 is returned. + * If the module is within the array, the index is returned. */ +int +get_module_index (int module) { + size_t idx = 0; + + FOREACH_MODULE (idx, module_list) { + if (module_list[idx] == module) + return idx; + } + + return -1; +} + +/* Remove the given module from the module_list array. + * + * If the module is not within the array, 1 is returned. + * If the module is within the array, it is removed from the array and + * 0 is returned. */ +int +remove_module (GModule module) { + int idx = get_module_index (module); + if (idx == -1) + return 1; + + if (idx < TOTAL_MODULES - 1) + memmove (&module_list[idx], &module_list[idx + 1], + ((TOTAL_MODULES - 1) - idx) * sizeof (module_list[0])); + module_list[TOTAL_MODULES - 1] = -1; + + return 0; +} + +/* Find the next module given the current module. + * + * The next available module in the array is returned. */ +int +get_next_module (GModule module) { + int next = get_module_index (module) + 1; + + if (next == TOTAL_MODULES || module_list[next] == -1) + return module_list[0]; + + return module_list[next]; +} + +/* Find the previous module given the current module. + * + * The previous available module in the array is returned. */ +int +get_prev_module (GModule module) { + int i; + int next = get_module_index (module) - 1; + + if (next >= 0 && module_list[next] != -1) + return module_list[next]; + + for (i = TOTAL_MODULES - 1; i >= 0; i--) { + if (module_list[i] != -1) { + return module_list[i]; + } + } + + return 0; +} + +/* Perform some additional tasks to panels before they are being + * parsed. + * + * Note: This overwrites --enable-panel since it assumes there's + * truly nothing to do with the panel */ +void +verify_panels (void) { + int ignore_panel_idx = conf.ignore_panel_idx; + + /* Remove virtual host panel if no '%v' within log format */ + if (!conf.log_format) + return; + + if (!strstr (conf.log_format, "%v") && ignore_panel_idx < TOTAL_MODULES && !conf.fname_as_vhost) { + if (str_inarray ("VIRTUAL_HOSTS", conf.ignore_panels, ignore_panel_idx) < 0) + remove_module (VIRTUAL_HOSTS); + } + if (!strstr (conf.log_format, "%e") && ignore_panel_idx < TOTAL_MODULES) { + if (str_inarray ("REMOTE_USER", conf.ignore_panels, ignore_panel_idx) < 0) + remove_module (REMOTE_USER); + } + if (!strstr (conf.log_format, "%C") && ignore_panel_idx < TOTAL_MODULES) { + if (str_inarray ("CACHE_STATUS", conf.ignore_panels, ignore_panel_idx) < 0) + remove_module (CACHE_STATUS); + } + if (!strstr (conf.log_format, "%M") && ignore_panel_idx < TOTAL_MODULES) { + if (str_inarray ("MIME_TYPE", conf.ignore_panels, ignore_panel_idx) < 0) + remove_module (MIME_TYPE); + } + if (!strstr (conf.log_format, "%K") && ignore_panel_idx < TOTAL_MODULES) { + if (str_inarray ("TLS_TYPE", conf.ignore_panels, ignore_panel_idx) < 0) + remove_module (TLS_TYPE); + } +#ifdef HAVE_GEOLOCATION +#ifdef HAVE_LIBMAXMINDDB + if (!conf.geoip_db_idx && ignore_panel_idx < TOTAL_MODULES) { + if (str_inarray ("GEO_LOCATION", conf.ignore_panels, ignore_panel_idx) < 0) + remove_module (GEO_LOCATION); + } + if (!conf.geoip_db_idx && ignore_panel_idx < TOTAL_MODULES) { + if (str_inarray ("ASN", conf.ignore_panels, ignore_panel_idx) < 0) + remove_module (ASN); + } +#endif +#endif +} + +/* Build an array of available modules (ignores listed panels). + * + * If there are no modules enabled, 0 is returned. + * On success, the first enabled module is returned. */ +int +init_modules (void) { + GModule module; + int i; + + /* init - terminating with -1 */ + for (module = 0; module < TOTAL_MODULES; ++module) + module_list[module] = -1; + + for (i = 0, module = 0; module < TOTAL_MODULES; ++module) { + if (!ignore_panel (module) || enable_panel (module)) { + module_list[i++] = module; + } + } + + return module_list[0] > -1 ? module_list[0] : 0; +} + +/* Get the logs size. + * + * If log was piped (from stdin), 0 is returned. + * On success, it adds up all log sizes and its value is returned. + * if --log-size was specified, it will be returned explicitly */ +intmax_t +get_log_sizes (void) { + int i; + off_t size = 0; + + /* --log-size */ + if (conf.log_size > 0) + return (intmax_t) conf.log_size; + + for (i = 0; i < conf.filenames_idx; ++i) { + if (conf.filenames[i][0] == '-' && conf.filenames[i][1] == '\0') + size += 0; + else + size += file_size (conf.filenames[i]); + } + + return (intmax_t) size; +} + +/* Get the log sources used. + * + * On success, a newly malloc'd string containing the log source either + * from filename(s) and/or STDIN is returned. */ +char * +get_log_source_str (int max_len) { + char *str = xstrdup (""); + int i, len = 0; + + for (i = 0; i < conf.filenames_idx; ++i) { + if (conf.filenames[i][0] == '-' && conf.filenames[i][1] == '\0') + append_str (&str, "STDIN"); + else + append_str (&str, conf.filenames[i]); + if (i != conf.filenames_idx - 1) + append_str (&str, "; "); + } + + len = strlen (str); + if (max_len > 0 && len > 0 && len > max_len) { + str[max_len - 3] = 0; + append_str (&str, "..."); + } + + return str; +} diff --git a/src/commons.h b/src/commons.h new file mode 100644 index 0000000000..4f0f4bb888 --- /dev/null +++ b/src/commons.h @@ -0,0 +1,291 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#ifndef COMMONS_H_INCLUDED +#define COMMONS_H_INCLUDED + +#include +#include +#include "gslist.h" + +/* Remove the __attribute__ stuff when the compiler is not GCC. */ +#if !__GNUC__ +#define __attribute__(x) /**/ +#endif +#define GO_UNUSED __attribute__((unused)) +#define GO_VERSION "1.9.3" +#define GO_WEBSITE "https://goaccess.io/" +extern struct tm now_tm; + +/* common char array buffer size */ +#define INIT_BUF_SIZE 1024 + +/* total number of modules */ +#ifdef HAVE_GEOLOCATION +#define TOTAL_MODULES 19 +#else +#define TOTAL_MODULES 17 +#endif + +/* maximum number of items within a panel */ +#define MAX_CHOICES 366 +/* real-time */ +#define MAX_CHOICES_RT 50 +/* max default items when date-spec = min */ +#define MAX_CHOICES_MINUTE 1440 /* 24hrs */ + +/* date and time length - e.g., 2016/12/12 12:12:12 -0600 */ +#define DATE_TIME 25 + 1 +/* date length - e.g., 2016/12/12 */ +#define DATE_LEN 10 + 1 +/* date length - e.g., 12:12:12 */ +#define TIME_LEN 8 + 1 +/* hour + ':' + min length - e.g., 12:12 */ +#define HRMI_LEN 4 + 1 + 1 + +#define YR_FMT "%Y" +#define MO_FMT "%M" +#define DT_FMT "%d" + +/* maximum protocol string length */ +#define REQ_PROTO_LEN 9 + +#define IGNORE_LEVEL_PANEL 1 +#define IGNORE_LEVEL_REQ 2 + +/* Type of IP */ +typedef enum { + TYPE_IPINV, + TYPE_IPV4, + TYPE_IPV6 +} GTypeIP; + +/* Type of Modules */ +typedef enum MODULES { + VISITORS, + REQUESTS, + REQUESTS_STATIC, + NOT_FOUND, + HOSTS, + OS, + BROWSERS, + VISIT_TIMES, + VIRTUAL_HOSTS, + REFERRERS, + REFERRING_SITES, + KEYPHRASES, + STATUS_CODES, + REMOTE_USER, + CACHE_STATUS, +#ifdef HAVE_GEOLOCATION + GEO_LOCATION, + ASN, +#endif + MIME_TYPE, + TLS_TYPE, +} GModule; + +/* Total number of storage metrics (GSMetric) */ +#define GSMTRC_TOTAL 19 + +/* Enumerated Storage Metrics */ +typedef enum GSMetric_ { + MTRC_KEYMAP, + MTRC_ROOTMAP, + MTRC_DATAMAP, + MTRC_UNIQMAP, + MTRC_ROOT, + MTRC_HITS, + MTRC_VISITORS, + MTRC_BW, + MTRC_CUMTS, + MTRC_MAXTS, + MTRC_METHODS, + MTRC_PROTOCOLS, + MTRC_AGENTS, + MTRC_METADATA, + MTRC_UNIQUE_KEYS, + MTRC_AGENT_KEYS, + MTRC_AGENT_VALS, + MTRC_CNT_VALID, + MTRC_CNT_BW, +} GSMetric; + +/* Metric totals. These are metrics that have a percent value and are + * calculated values. */ +typedef struct GPercTotals_ { + uint32_t hits; /* total valid hits */ + uint32_t visitors; /* total visitors */ + uint64_t bw; /* total bandwidth */ +} GPercTotals; + +/* Metrics within GHolder or GDashData */ +typedef struct GMetrics { + /* metric id can be used to identify + * a specific data field */ + uint8_t id; + char *data; + char *method; + char *protocol; + + float hits_perc; + float visitors_perc; + float bw_perc; + + uint64_t hits; + uint64_t visitors; + + /* holder has a numeric value, while + * dashboard has a displayable string value */ + union { + char *sbw; + uint64_t nbw; + } bw; + + /* holder has a numeric value, while + * dashboard has a displayable string value */ + union { + char *sts; + uint64_t nts; + } avgts; + + /* holder has a numeric value, while + * dashboard has a displayable string value */ + union { + char *sts; + uint64_t nts; + } cumts; + + /* holder has a numeric value, while + * dashboard has a displayable string value */ + union { + char *sts; + uint64_t nts; + } maxts; +} GMetrics; + +/* Holder sub item */ +typedef struct GSubItem_ { + GModule module; + GMetrics *metrics; + struct GSubItem_ *prev; + struct GSubItem_ *next; +} GSubItem; + +/* Double linked-list of sub items */ +typedef struct GSubList_ { + int size; + struct GSubItem_ *head; + struct GSubItem_ *tail; +} GSubList; + +/* Holder item */ +typedef struct GHolderItem_ { + GSubList *sub_list; + GMetrics *metrics; +} GHolderItem; + +/* Holder of GRawData */ +typedef struct GHolder_ { + GHolderItem *items; /* holder items */ + GModule module; /* current module */ + int idx; /* holder index */ + int holder_size; /* number of allocated items */ + uint32_t ht_size; /* size of the hash table/store */ + int sub_items_size; /* number of sub items */ +} GHolder; + +/* Enum-to-string */ +typedef struct GEnum_ { + const char *str; + int idx; +} GEnum; + +/* A metric can contain a root/data/uniq node id */ +typedef struct GDataMap_ { + int data; + int root; +} GDataMap; + +typedef struct GAgentItem_ { + char *agent; +} GAgentItem; + +typedef struct GAgents_ { + int size; + int idx; + struct GAgentItem_ *items; +} GAgents; + +#define FOREACH_MODULE(item, array) \ + for (; (item < ARRAY_SIZE(array)) && array[item] != -1; ++item) + +/* Processing time */ +extern time_t end_proc; +extern time_t timestamp; +extern time_t start_proc; + +/* list of available modules/panels */ +extern int module_list[TOTAL_MODULES]; + +/* *INDENT-OFF* */ +GAgents *new_gagents (uint32_t size); +void free_agents_array (GAgents *agents); + +const char *enum2str (const GEnum map[], int len, int idx); +const char *get_module_str (GModule module); +float get_percentage (unsigned long long total, unsigned long long hit); +int get_max_choices (void); +int get_module_enum (const char *str); +int has_timestamp (const char *fmt); +int str2enum (const GEnum map[], int len, const char *str); + +int enable_panel (GModule mod); +int get_module_index (int module); +int get_next_module (GModule module); +int get_prev_module (GModule module); +int ignore_panel (GModule mod); +int init_modules (void); +int remove_module(GModule module); +uint32_t get_num_modules (void); +void verify_panels (void); + +char *get_log_source_str (int max_len); +intmax_t get_log_sizes (void); + +void display_default_config_file (void); +void display_storage (void); +void display_version (void); +/* *INDENT-ON* */ + +#endif diff --git a/src/csv.c b/src/csv.c new file mode 100644 index 0000000000..a1dbc58094 --- /dev/null +++ b/src/csv.c @@ -0,0 +1,320 @@ +/** + * output.c -- output csv to the standard output stream + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE +#define _FILE_OFFSET_BITS 64 + +#include + +#include +#include +#include +#include +#include +#include + +#include "csv.h" + +#include "error.h" +#include "gkhash.h" +#include "ui.h" +#include "util.h" + +struct tm now_tm; + +/* Panel output */ +typedef struct GPanel_ { + GModule module; + void (*render) (FILE * fp, GHolder * h, GPercTotals totals); +} GPanel; + +static void print_csv_data (FILE * fp, GHolder * h, GPercTotals totals); + +/* *INDENT-OFF* */ +/* A function pointer for each panel */ +static const GPanel paneling[] = { + {VISITORS , print_csv_data} , + {REQUESTS , print_csv_data} , + {REQUESTS_STATIC , print_csv_data} , + {NOT_FOUND , print_csv_data} , + {HOSTS , print_csv_data} , + {OS , print_csv_data} , + {BROWSERS , print_csv_data} , + {VISIT_TIMES , print_csv_data} , + {VIRTUAL_HOSTS , print_csv_data} , + {REFERRERS , print_csv_data} , + {REFERRING_SITES , print_csv_data} , + {KEYPHRASES , print_csv_data} , + {STATUS_CODES , print_csv_data} , + {REMOTE_USER , print_csv_data} , + {CACHE_STATUS , print_csv_data} , +#ifdef HAVE_GEOLOCATION + {GEO_LOCATION , print_csv_data} , + {ASN , print_csv_data} , +#endif + {MIME_TYPE , print_csv_data} , + {TLS_TYPE , print_csv_data} , +}; +/* *INDENT-ON* */ + +/* Get a panel from the GPanel structure given a module. + * + * On error, or if not found, NULL is returned. + * On success, the panel value is returned. */ +static const GPanel * +panel_lookup (GModule module) { + int i, num_panels = ARRAY_SIZE (paneling); + + for (i = 0; i < num_panels; i++) { + if (paneling[i].module == module) + return &paneling[i]; + } + return NULL; +} + +/* Iterate over the string and escape CSV output. */ +static void +escape_cvs_output (FILE *fp, char *s) { + while (*s) { + switch (*s) { + case '"': + fprintf (fp, "\"\""); + break; + default: + fputc (*s, fp); + break; + } + s++; + } +} + +/* Output metrics. + * + * On success, outputs item value. */ +static void +print_csv_metric_block (FILE *fp, GMetrics *nmetrics) { + /* basic metrics */ + fprintf (fp, "\"%" PRIu64 "\",", nmetrics->hits); + fprintf (fp, "\"%4.2f%%\",", nmetrics->hits_perc); + fprintf (fp, "\"%" PRIu64 "\",", nmetrics->visitors); + fprintf (fp, "\"%4.2f%%\",", nmetrics->visitors_perc); + + /* bandwidth */ + if (conf.bandwidth) { + fprintf (fp, "\"%" PRIu64 "\",", nmetrics->bw.nbw); + fprintf (fp, "\"%4.2f%%\",", nmetrics->bw_perc); + } + + /* time served metrics */ + if (conf.serve_usecs) { + fprintf (fp, "\"%" PRIu64 "\",", nmetrics->avgts.nts); + fprintf (fp, "\"%" PRIu64 "\",", nmetrics->cumts.nts); + fprintf (fp, "\"%" PRIu64 "\",", nmetrics->maxts.nts); + } + + /* request method */ + if (conf.append_method && nmetrics->method) + fprintf (fp, "\"%s\"", nmetrics->method); + fprintf (fp, ","); + + /* request protocol */ + if (conf.append_protocol && nmetrics->protocol) + fprintf (fp, "\"%s\"", nmetrics->protocol); + fprintf (fp, ","); + + /* data field */ + fprintf (fp, "\""); + escape_cvs_output (fp, nmetrics->data); + fprintf (fp, "\"\r\n"); +} + +/* Output a sublist (double linked-list) items for a particular parent node. + * + * On error, it exits early. + * On success, outputs item value. */ +static void +print_csv_sub_items (FILE *fp, GHolder *h, int idx, GPercTotals totals) { + GMetrics *nmetrics; + GSubList *sub_list = h->items[idx].sub_list; + GSubItem *iter; + + int i = 0; + + if (sub_list == NULL) + return; + + for (iter = sub_list->head; iter; iter = iter->next, i++) { + set_data_metrics (iter->metrics, &nmetrics, totals); + + fprintf (fp, "\"%d\",", i); /* idx */ + fprintf (fp, "\"%d\",", idx); /* parent idx */ + fprintf (fp, "\"%s\",", module_to_id (h->module)); + + /* output metrics */ + print_csv_metric_block (fp, nmetrics); + free (nmetrics); + } +} + +/* Output first-level items. + * + * On success, outputs item value. */ +static void +print_csv_data (FILE *fp, GHolder *h, GPercTotals totals) { + GMetrics *nmetrics; + int i; + + for (i = 0; i < h->idx; i++) { + set_data_metrics (h->items[i].metrics, &nmetrics, totals); + + fprintf (fp, "\"%d\",", i); /* idx */ + fprintf (fp, ","); /* no parent */ + fprintf (fp, "\"%s\",", module_to_id (h->module)); + + /* output metrics */ + print_csv_metric_block (fp, nmetrics); + + if (h->sub_items_size) + print_csv_sub_items (fp, h, i, totals); + + free (nmetrics); + } +} + +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +/* Output general statistics information. */ +static void +print_csv_summary (FILE *fp) { + char now[DATE_TIME]; + char *source = NULL; + const char *fmt; + int i = 0; + uint64_t total = 0; + uint32_t t = 0; + + generate_time (); + strftime (now, DATE_TIME, "%Y-%m-%d %H:%M:%S %z", &now_tm); + + /* generated date time */ + fmt = "\"%d\",,\"%s\",,,,,,,,\"%s\",\"%s\"\r\n"; + fprintf (fp, fmt, i++, GENER_ID, now, OVERALL_DATETIME); + + /* total requests */ + fmt = "\"%d\",,\"%s\",,,,,,,,\"%" PRIu64 "\",\"%s\"\r\n"; + total = ht_get_processed (); + fprintf (fp, fmt, i++, GENER_ID, total, OVERALL_REQ); + + /* valid requests */ + fmt = "\"%d\",,\"%s\",,,,,,,,\"%" PRIu64 "\",\"%s\"\r\n"; + total = ht_sum_valid (); + fprintf (fp, fmt, i++, GENER_ID, total, OVERALL_VALID); + + /* invalid requests */ + total = ht_get_invalid (); + fprintf (fp, fmt, i++, GENER_ID, total, OVERALL_FAILED); + + /* generated time */ + fmt = "\"%d\",,\"%s\",,,,,,,,\"%u\",\"%s\"\r\n"; + t = ht_get_processing_time (); + fprintf (fp, fmt, i++, GENER_ID, t, OVERALL_GENTIME); + + /* visitors */ + fmt = "\"%d\",,\"%s\",,,,,,,,\"%" PRIu64 "\",\"%s\"\r\n"; + total = ht_get_size_uniqmap (VISITORS); + fprintf (fp, fmt, i++, GENER_ID, total, OVERALL_VISITORS); + + /* files */ + total = ht_get_size_datamap (REQUESTS); + fprintf (fp, fmt, i++, GENER_ID, total, OVERALL_FILES); + + /* excluded hits */ + total = ht_get_excluded_ips (); + fprintf (fp, fmt, i++, GENER_ID, total, OVERALL_EXCL_HITS); + + /* referrers */ + total = ht_get_size_datamap (REFERRERS); + fprintf (fp, fmt, i++, GENER_ID, total, OVERALL_REF); + + /* not found */ + total = ht_get_size_datamap (NOT_FOUND); + fprintf (fp, fmt, i++, GENER_ID, total, OVERALL_NOTFOUND); + + /* static files */ + total = ht_get_size_datamap (REQUESTS_STATIC); + fprintf (fp, fmt, i++, GENER_ID, total, OVERALL_STATIC); + + /* log size */ + fmt = "\"%d\",,\"%s\",,,,,,,,\"%jd\",\"%s\"\r\n"; + fprintf (fp, fmt, i++, GENER_ID, (intmax_t) get_log_sizes (), OVERALL_LOGSIZE); + + /* bandwidth */ + fmt = "\"%d\",,\"%s\",,,,,,,,\"%" PRIu64 "\",\"%s\"\r\n"; + fprintf (fp, fmt, i++, GENER_ID, ht_sum_bw (), OVERALL_BANDWIDTH); + + /* log path */ + source = get_log_source_str (0); + fmt = "\"%d\",,\"%s\",,,,,,,,\"%s\",\"%s\"\r\n"; + fprintf (fp, fmt, i++, GENER_ID, source, OVERALL_LOG); + free (source); +} + +#pragma GCC diagnostic warning "-Wformat-nonliteral" + +/* Entry point to generate a csv report writing it to the fp */ +void +output_csv (GHolder *holder, const char *filename) { + GModule module; + GPercTotals totals; + const GPanel *panel = NULL; + size_t idx = 0; + FILE *fp; + + fp = (filename != NULL) ? fopen (filename, "w") : stdout; + if (!fp) + FATAL ("Unable to open CSV file: %s.", strerror (errno)); + + if (!conf.no_csv_summary) + print_csv_summary (fp); + + set_module_totals (&totals); + + FOREACH_MODULE (idx, module_list) { + module = module_list[idx]; + + if (!(panel = panel_lookup (module))) { + continue; + } + + panel->render (fp, holder + module, totals); + } + + fclose (fp); +} diff --git a/src/csv.h b/src/csv.h new file mode 100644 index 0000000000..5cbb8928d5 --- /dev/null +++ b/src/csv.h @@ -0,0 +1,43 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#ifndef CSV_H_INCLUDED +#define CSV_H_INCLUDED + +#include +#include "parser.h" +#include "settings.h" + +void output_csv (GHolder * holder, const char *filename); + +#endif diff --git a/src/error.c b/src/error.c new file mode 100644 index 0000000000..c0c2f375c1 --- /dev/null +++ b/src/error.c @@ -0,0 +1,278 @@ +/** + * error.c -- error handling + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#if defined(__GLIBC__) +#include +#endif +#include +#include +#include + +#include "error.h" +#include "labels.h" +#include "parser.h" + +static FILE *access_log; +static FILE *log_file; +static FILE *log_invalid; +static FILE *log_unknowns; +static Logs *log_data; +static struct sigaction old_sigsegv_handler; + +/* Open a debug file whose name is specified in the given path. */ +void +dbg_log_open (const char *path) { + if (path != NULL) { + log_file = fopen (path, "w"); + if (log_file == NULL) + return; + } +} + +/* Close the debug file. */ +void +dbg_log_close (void) { + if (log_file != NULL) + fclose (log_file); +} + +/* Open the invalid requests log file whose name is specified in the + * given path. */ +void +invalid_log_open (const char *path) { + if (path != NULL) { + log_invalid = fopen (path, "w"); + if (log_invalid == NULL) + return; + } +} + +/* Close the invalid requests log file. */ +void +invalid_log_close (void) { + if (log_invalid != NULL) + fclose (log_invalid); +} + +/* Open the unknowns log file whose name is specified in the + * given path. */ +void +unknowns_log_open (const char *path) { + if (path != NULL) { + log_unknowns = fopen (path, "w"); + if (log_unknowns == NULL) + return; + } +} + +/* Close the unknowns log file. */ +void +unknowns_log_close (void) { + if (log_unknowns != NULL) + fclose (log_unknowns); +} + +/* Set current overall parsed log data. */ +void +set_signal_data (void *p) { + log_data = p; +} + +/* Open the WebSocket access log file whose name is specified in the + * given path. */ +int +access_log_open (const char *path) { + if (path == NULL) + return 0; + + access_log = fopen (path, "a"); + + if (access_log == NULL) + return 1; + + return 0; +} + +/* Close the WebSocket access log file. */ +void +access_log_close (void) { + if (access_log != NULL) + fclose (access_log); +} + +/* Set up sigsegv handler. */ +void +setup_sigsegv_handler (void) { + struct sigaction act; + + sigemptyset (&act.sa_mask); + act.sa_flags = (int) SA_RESETHAND; + act.sa_handler = sigsegv_handler; + + sigaction (SIGSEGV, &act, &old_sigsegv_handler); +} + +static void +dump_struct_data (FILE *fp, GLog *glog, int pid) { + fprintf (fp, "==%d== FILE: %s\n", pid, glog->props.filename); + fprintf (fp, "==%d== Line number: %" PRIu64 "\n", pid, glog->processed); + fprintf (fp, "==%d== Invalid data: %" PRIu64 "\n", pid, glog->invalid); + fprintf (fp, "==%d== Piping: %d\n", pid, glog->piping); + fprintf (fp, "==%d==\n", pid); +} + +/* Dump to the standard output the values of the overall parsed log + * data. */ +static void +dump_struct (FILE *fp) { + int pid = getpid (), i; + + if (!log_data) + return; + + fprintf (fp, "==%d== VALUES AT CRASH POINT\n", pid); + fprintf (fp, "==%d==\n", pid); + + for (i = 0; i < log_data->size; ++i) + dump_struct_data (fp, &log_data->glog[i], pid); + +} + +/* Custom SIGSEGV handler. */ +void +sigsegv_handler (int sig) { + FILE *fp = stderr; + int pid = getpid (); + +#if defined(__GLIBC__) + char **messages; + size_t size, i; + void *trace_stack[TRACE_SIZE]; +#endif + + (void) endwin (); + fprintf (fp, "\n"); + fprintf (fp, "==%d== GoAccess %s crashed by Sig %d\n", pid, GO_VERSION, sig); + fprintf (fp, "==%d==\n", pid); + + dump_struct (fp); + +#if defined(__GLIBC__) + size = backtrace (trace_stack, TRACE_SIZE); + messages = backtrace_symbols (trace_stack, size); + + fprintf (fp, "==%d== STACK TRACE:\n", pid); + fprintf (fp, "==%d==\n", pid); + + for (i = 0; i < size; i++) + fprintf (fp, "==%d== %zu %s\n", pid, i, messages[i]); +#endif + + fprintf (fp, "==%d==\n", pid); + fprintf (fp, "==%d== %s:\n", pid, ERR_PLEASE_REPORT); + fprintf (fp, "==%d== https://github.com/allinurl/goaccess/issues\n\n", pid); + fflush (fp); + + /* Call old sigsegv handler; may be default exit or third party one (e.g. ASAN) */ + sigaction (SIGSEGV, &old_sigsegv_handler, NULL); +} + +/* Write formatted debug log data to the logfile. */ +void +dbg_fprintf (const char *fmt, ...) { + va_list args; + + if (!log_file) + return; + + va_start (args, fmt); + vfprintf (log_file, fmt, args); + fflush (log_file); + va_end (args); +} + +/* Write formatted invalid requests log data to the logfile. */ +void +invalid_fprintf (const char *fmt, ...) { + va_list args; + + if (!log_invalid) + return; + + va_start (args, fmt); + vfprintf (log_invalid, fmt, args); + fflush (log_invalid); + va_end (args); +} + +/* Write formatted unknown browsers/OSs log data to the logfile. */ +void +unknowns_fprintf (const char *fmt, ...) { + va_list args; + + if (!log_unknowns) + return; + + va_start (args, fmt); + vfprintf (log_unknowns, fmt, args); + fflush (log_unknowns); + va_end (args); +} + +/* Debug output */ +void +dbg_printf (const char *fmt, ...) { + va_list args; + va_start (args, fmt); + vfprintf (stderr, fmt, args); + va_end (args); +} + +/* Write formatted access log data to the logfile. */ +void +access_fprintf (const char *fmt, ...) { + va_list args; + + if (!access_log) + return; + + va_start (args, fmt); + vfprintf (access_log, fmt, args); + fflush (access_log); + va_end (args); +} diff --git a/src/error.h b/src/error.h new file mode 100644 index 0000000000..e5f8d46ce7 --- /dev/null +++ b/src/error.h @@ -0,0 +1,98 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef ERROR_H_INCLUDED +#define ERROR_H_INCLUDED + +#ifndef COMMONS +#include "commons.h" +#endif + +#ifdef HAVE_NCURSESW_NCURSES_H +#include +#elif HAVE_NCURSES_NCURSES_H +#include +#elif HAVE_NCURSES_H +#include +#elif HAVE_CURSES_H +#include +#endif + +#include +#include "settings.h" + +#define TRACE_SIZE 128 + +#define FATAL(fmt, ...) do { \ + (void) endwin (); \ + fprintf (stderr, "\nGoAccess - version %s - %s %s\n", GO_VERSION, __DATE__, __TIME__); \ + fprintf (stderr, "Config file: %s\n", conf.iconfigfile ?: NO_CONFIG_FILE); \ + fprintf (stderr, "\nFatal error has occurred"); \ + fprintf (stderr, "\nError occurred at: %s - %s - %d\n", __FILE__, __FUNCTION__, __LINE__); \ + fprintf (stderr, fmt, ##__VA_ARGS__); \ + fprintf (stderr, "\n\n"); \ + LOG_DEBUG ((fmt, ##__VA_ARGS__)); \ + exit(EXIT_FAILURE); \ +} while (0) + +#ifdef DEBUG +#define DEBUG_TEST 1 +#else +#define DEBUG_TEST 0 +#endif + +/* access requests log */ +#define ACCESS_LOG(x, ...) do { access_fprintf x; } while (0) +/* debug log */ +#define LOG_DEBUG(x, ...) do { dbg_fprintf x; } while (0) +/* invalid requests log */ +#define LOG_INVALID(x, ...) do { invalid_fprintf x; } while (0) +/* unknown browser log */ +#define LOG_UNKNOWNS(x, ...) do { unknowns_fprintf x; } while (0) +/* log debug wrapper */ +#define LOG(x) do { if (DEBUG_TEST) dbg_printf x; } while (0) + +int access_log_open (const char *path); +void access_fprintf (const char *fmt, ...) __attribute__((format (printf, 1, 2))); +void access_log_close (void); +void dbg_fprintf (const char *fmt, ...) __attribute__((format (printf, 1, 2))); +void dbg_log_close (void); +void dbg_log_open (const char *file); +void dbg_printf (const char *fmt, ...) __attribute__((format (printf, 1, 2))); +void invalid_fprintf (const char *fmt, ...) __attribute__((format (printf, 1, 2))); +void unknowns_fprintf (const char *fmt, ...) __attribute__((format (printf, 1, 2))); +void invalid_log_close (void); +void invalid_log_open (const char *path); +void set_signal_data (void *p); +void setup_sigsegv_handler (void); +void sigsegv_handler (int sig); +void unknowns_log_close (void); +void unknowns_log_open (const char *path); + +#endif diff --git a/src/gdashboard.c b/src/gdashboard.c new file mode 100644 index 0000000000..bf7f19e892 --- /dev/null +++ b/src/gdashboard.c @@ -0,0 +1,1436 @@ +/** + * gdashboard.c -- goaccess main dashboard + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#define _XOPEN_SOURCE 700 + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gdashboard.h" + +#include "gkhash.h" +#include "gholder.h" +#include "color.h" +#include "error.h" +#include "gstorage.h" +#include "util.h" +#include "xmalloc.h" + +static GFind find_t; + +/* Reset find indices */ +void +reset_find (void) { + if (find_t.pattern != NULL && *find_t.pattern != '\0') + free (find_t.pattern); + + find_t.look_in_sub = 0; + find_t.module = 0; + find_t.next_idx = 0; /* next total index */ + find_t.next_parent_idx = 0; /* next parent index */ + find_t.next_sub_idx = 0; /* next sub item index */ + find_t.pattern = NULL; +} + +/* Allocate memory for a new GDash instance. + * + * On success, the newly allocated GDash is returned . */ +GDash * +new_gdash (void) { + GDash *dash = xmalloc (sizeof (GDash)); + memset (dash, 0, sizeof *dash); + dash->total_alloc = 0; + + return dash; +} + +/* Allocate memory for a new GDashData instance. + * + * On success, the newly allocated GDashData is returned . */ +GDashData * +new_gdata (uint32_t size) { + GDashData *data = xcalloc (size, sizeof (GDashData)); + + return data; +} + +/* Free memory allocated for a GDashData instance. Includes malloc'd + * strings. */ +static void +free_dashboard_data (GDashData item) { + if (item.metrics == NULL) + return; + + if (item.metrics->data) + free (item.metrics->data); + if (item.metrics->bw.sbw) + free (item.metrics->bw.sbw); + if (conf.serve_usecs && item.metrics->avgts.sts) + free (item.metrics->avgts.sts); + if (conf.serve_usecs && item.metrics->cumts.sts) + free (item.metrics->cumts.sts); + if (conf.serve_usecs && item.metrics->maxts.sts) + free (item.metrics->maxts.sts); + free (item.metrics); +} + +/* Free memory allocated for a GDash instance, and nested structure + * data. */ +void +free_dashboard (GDash *dash) { + GModule module; + int j; + size_t idx = 0; + + FOREACH_MODULE (idx, module_list) { + module = module_list[idx]; + for (j = 0; j < dash->module[module].alloc_data; j++) { + free_dashboard_data (dash->module[module].data[j]); + } + free (dash->module[module].data); + } + free (dash); +} + +/* Get the current panel/module given the `Y` offset (position) in the + * terminal dashboard. + * + * If not found, 0 is returned. + * If found, the module number is returned . */ +static GModule +get_find_current_module (GDash *dash, int offset) { + GModule module; + size_t idx = 0; + + FOREACH_MODULE (idx, module_list) { + module = module_list[idx]; + + /* set current module */ + if (dash->module[module].pos_y == offset) + return module; + /* we went over by one module, set current - 1 */ + if (dash->module[module].pos_y > offset) + return module - 1; + } + + return 0; +} + +/* Get the number of rows that a collapsed dashboard panel contains. + * + * On success, the number of rows is returned. */ +int +get_num_collapsed_data_rows (void) { + /* The default number of rows is fixed */ + int size = DASH_COLLAPSED - DASH_NON_DATA; + /* If no column names, then add the number of rows occupied by the + * column values to the default number */ + return conf.no_column_names ? size + DASH_COL_ROWS : size; +} + +/* Get the number of rows that an expanded dashboard panel contains. + * + * On success, the number of rows is returned. */ +int +get_num_expanded_data_rows (void) { + /* The default number of rows is fixed */ + int size = DASH_EXPANDED - DASH_NON_DATA; + /* If no column names, then add the number of rows occupied by the + * column values to the default number */ + return conf.no_column_names ? size + DASH_COL_ROWS : size; +} + +/* Get the Y position of the terminal dashboard where data rows + * (metrics) start. + * + * On success, the Y position is returned. */ +static int +get_data_pos_rows (void) { + return conf.no_column_names ? DASH_DATA_POS - DASH_COL_ROWS : DASH_DATA_POS; +} + +/* Get the initial X position of the terminal dashboard where metrics + * and data columns start. + * + * On success, the X position is returned. */ +static int +get_xpos (void) { + return DASH_INIT_X; +} + +/* Determine which module should be expanded given the current mouse + * position. + * + * On error, 1 is returned. + * On success, 0 is returned. */ +int +set_module_from_mouse_event (GScroll *gscroll, GDash *dash, int y) { + int module = 0; + int offset = y - MAX_HEIGHT_HEADER - MAX_HEIGHT_FOOTER + 1; + if (gscroll->expanded) { + module = get_find_current_module (dash, offset); + } else { + offset += gscroll->dash; + module = offset / DASH_COLLAPSED; + } + + if (module >= TOTAL_MODULES) + module = TOTAL_MODULES - 1; + else if (module < 0) + module = 0; + + if ((int) gscroll->current == module) + return 1; + + gscroll->current = module; + return 0; +} + +/* Allocate a new string for a sub item on the terminal dashboard. + * + * On error, NULL is returned. + * On success, the newly allocated string is returned. */ +static char * +render_child_node (const char *data) { + char *buf; + int len = 0; + + /* chars to use based on encoding used */ +#ifdef HAVE_LIBNCURSESW + const char *bend = "\xe2\x94\x9c"; + const char *horz = "\xe2\x94\x80"; +#else + const char *bend = "|"; + const char *horz = "`-"; +#endif + + if (data == NULL || *data == '\0') + return NULL; + + len = snprintf (NULL, 0, " %s%s %s", bend, horz, data); + buf = xmalloc (len + 3); + sprintf (buf, " %s%s %s", bend, horz, data); + + return buf; +} + +/* Get a string of bars given current hits, maximum hit & xpos. + * + * On success, the newly allocated string representing the chart is + * returned. */ +static char * +get_bars (int n, int max, int x) { + int w, h; + float len = 0.0; + + getmaxyx (stdscr, h, w); + (void) h; /* avoid lint warning */ + + len = ((((float) n) / max)); + len *= (w - x); + if (len < 1) + len = 1; + return char_repeat (len, '|'); +} + +/* Get largest hits metric. + * + * On error, 0 is returned. + * On success, largest hits metric is returned. */ +static void +set_max_metrics (GDashMeta *meta, GDashData *idata) { + if (meta->max_hits < idata->metrics->hits) + meta->max_hits = idata->metrics->hits; + if (meta->max_visitors < idata->metrics->visitors) + meta->max_visitors = idata->metrics->visitors; +} + +/* Set largest hits metric (length of the integer). */ +static void +set_max_hit_len (GDashMeta *meta, GDashData *idata) { + int vlen = intlen (idata->metrics->hits); + int llen = strlen (MTRC_HITS_LBL); + + if (vlen > meta->hits_len) + meta->hits_len = vlen; + + /* if outputting with column names, then determine if the value is + * longer than the length of the column name */ + if (llen > meta->hits_len) + meta->hits_len = llen; +} + +/* Get the percent integer length. */ +static void +set_max_hit_perc_len (GDashMeta *meta, GDashData *idata) { + int vlen = intlen (idata->metrics->hits_perc); + int llen = strlen (MTRC_HITS_PERC_LBL); + + if (vlen > meta->hits_perc_len) + meta->hits_perc_len = vlen; + + /* if outputting with column names, then determine if the value is + * longer than the length of the column name */ + if (llen > meta->hits_perc_len) + meta->hits_perc_len = llen; +} + +/* Set largest hits metric (length of the integer). */ +static void +set_max_visitors_len (GDashMeta *meta, GDashData *idata) { + int vlen = intlen (idata->metrics->visitors); + int llen = strlen (MTRC_VISITORS_SHORT_LBL); + + if (vlen > meta->visitors_len) + meta->visitors_len = vlen; + + /* if outputting with column names, then determine if the value is + * longer than the length of the column name */ + if (llen > meta->visitors_len) + meta->visitors_len = llen; +} + +/* Get the percent integer length. */ +static void +set_max_visitors_perc_len (GDashMeta *meta, GDashData *idata) { + int vlen = intlen (idata->metrics->visitors_perc); + int llen = strlen (MTRC_VISITORS_PERC_LBL); + + if (vlen > meta->visitors_perc_len) + meta->visitors_perc_len = vlen; + + /* if outputting with column names, then determine if the value is + * longer than the length of the column name */ + if (llen > meta->visitors_perc_len) + meta->visitors_perc_len = llen; +} + +/* Get the percent integer length. */ +static void +set_max_bw_len (GDashMeta *meta, GDashData *idata) { + int vlen = strlen (idata->metrics->bw.sbw); + int llen = strlen (MTRC_BW_LBL); + + if (vlen > meta->bw_len) + meta->bw_len = vlen; + + /* if outputting with column names, then determine if the value is + * longer than the length of the column name */ + if (llen > meta->bw_len) + meta->bw_len = llen; +} + +/* Get the percent integer length. */ +static void +set_max_avgts_len (GDashMeta *meta, GDashData *idata) { + int vlen = 0, llen = 0; + + if (!conf.serve_usecs || !idata->metrics->avgts.sts) + return; + + vlen = strlen (idata->metrics->avgts.sts); + llen = strlen (MTRC_AVGTS_LBL); + + if (vlen > meta->avgts_len) + meta->avgts_len = vlen; + + /* if outputting with column names, then determine if the value is + * longer than the length of the column name */ + if (llen > meta->avgts_len) + meta->avgts_len = llen; +} + +/* Get the percent integer length. */ +static void +set_max_cumts_len (GDashMeta *meta, GDashData *idata) { + int vlen = 0, llen = 0; + + if (!conf.serve_usecs || !idata->metrics->cumts.sts) + return; + + vlen = strlen (idata->metrics->cumts.sts); + llen = strlen (MTRC_AVGTS_LBL); + + if (vlen > meta->cumts_len) + meta->cumts_len = vlen; + + /* if outputting with column names, then determine if the value is + * longer than the length of the column name */ + if (llen > meta->cumts_len) + meta->cumts_len = llen; +} + +/* Get the percent integer length. */ +static void +set_max_maxts_len (GDashMeta *meta, GDashData *idata) { + int vlen = 0, llen = 0; + + if (!conf.serve_usecs || !idata->metrics->maxts.sts) + return; + + vlen = strlen (idata->metrics->maxts.sts); + llen = strlen (MTRC_AVGTS_LBL); + + if (vlen > meta->maxts_len) + meta->maxts_len = vlen; + + /* if outputting with column names, then determine if the value is + * longer than the length of the column name */ + if (llen > meta->maxts_len) + meta->maxts_len = llen; +} + +/* Get the percent integer length. */ +static void +set_max_method_len (GDashMeta *meta, GDashData *idata) { + int vlen = 0, llen = 0; + + if (!conf.append_method || !idata->metrics->method) + return; + + vlen = strlen (idata->metrics->method); + llen = strlen (MTRC_METHODS_SHORT_LBL); + + if (vlen > meta->method_len) + meta->method_len = vlen; + + /* if outputting with column names, then determine if the value is + * longer than the length of the column name */ + if (llen > meta->method_len) + meta->method_len = llen; +} + +/* Get the percent integer length. */ +static void +set_max_protocol_len (GDashMeta *meta, GDashData *idata) { + int vlen = 0, llen = 0; + + if (!conf.append_protocol || !idata->metrics->protocol) + return; + + vlen = strlen (idata->metrics->protocol); + llen = strlen (MTRC_PROTOCOLS_SHORT_LBL); + + if (vlen > meta->protocol_len) + meta->protocol_len = vlen; + + /* if outputting with column names, then determine if the value is + * longer than the length of the column name */ + if (llen > meta->protocol_len) + meta->protocol_len = llen; +} + +/* Get the percent integer length. */ +static void +set_max_data_len (GDashMeta *meta, GDashData *idata) { + int vlen = 0, llen = 0; + + vlen = strlen (idata->metrics->data); + llen = strlen (MTRC_DATA_LBL); + + if (vlen > meta->data_len) + meta->data_len = vlen; + + /* if outputting with column names, then determine if the value is + * longer than the length of the column name */ + if (llen > meta->data_len) + meta->data_len = llen; +} + +static void +set_metrics_len (GDashMeta *meta, GDashData *idata) { + /* integer-based length */ + set_max_hit_len (meta, idata); + set_max_hit_perc_len (meta, idata); + set_max_visitors_len (meta, idata); + set_max_visitors_perc_len (meta, idata); + + /* string-based length */ + set_max_bw_len (meta, idata); + set_max_avgts_len (meta, idata); + set_max_cumts_len (meta, idata); + set_max_maxts_len (meta, idata); + + set_max_method_len (meta, idata); + set_max_protocol_len (meta, idata); + set_max_data_len (meta, idata); +} + +/* Render host's panel selected row */ +static void +render_data_hosts (WINDOW *win, GDashRender render, char *value, int x) { + char *padded_data; + + padded_data = left_pad_str (value, x); + draw_header (win, padded_data, "%s", render.y, 0, render.w, color_selected); + free (padded_data); +} + +/* Set panel's date on the given buffer + * + * On error, '---' placeholder is returned. + * On success, the formatted date is returned. */ +static char * +set_visitors_date (const char *value) { + return get_visitors_date (value, conf.spec_date_time_num_format, conf.spec_date_time_format); +} + +static char * +get_fixed_fmt_width (int w, char type) { + char *fmt = xmalloc (snprintf (NULL, 0, "%%%d%c", w, type) + 1); + sprintf (fmt, "%%%d%c", w, type); + + return fmt; +} + +/* Render the 'total' label on each panel */ +static void +render_total_label (WINDOW *win, GDashModule *data, int y, GColors *(*func) (void)) { + char *s; + int win_h, win_w, total, ht_size; + + total = data->holder_size; + ht_size = data->ht_size; + + s = xmalloc (snprintf (NULL, 0, "%s: %d/%d", GEN_TOTAL, total, ht_size) + 1); + getmaxyx (win, win_h, win_w); + (void) win_h; + + sprintf (s, "%s: %d/%d", GEN_TOTAL, total, ht_size); + draw_header (win, s, "%s", y, win_w - strlen (s) - 2, win_w, func); + free (s); +} + +/* Render panel bar graph */ +static void +render_bars (GDashModule *data, GDashRender render, int *x) { + GColors *color = get_color (COLOR_BARS); + WINDOW *win = render.win; + char *bar; + int y = render.y, w = render.w, idx = render.idx, sel = render.sel; + + bar = get_bars (data->data[idx].metrics->hits, data->meta.max_hits, *x); + if (sel) + draw_header (win, bar, "%s", y, *x, w, color_selected); + else { + wattron (win, color->attr | COLOR_PAIR (color->pair->idx)); + mvwprintw (win, y, *x, "%s", bar); + wattroff (win, color->attr | COLOR_PAIR (color->pair->idx)); + } + free (bar); +} + +/* Render the data metric for each panel */ +static void +render_data (GDashModule *data, GDashRender render, int *x) { + GColors *color = get_color_by_item_module (COLOR_MTRC_DATA, data->module); + WINDOW *win = render.win; + + char *date = NULL, *value = NULL, *buf = NULL; + int y = render.y, w = render.w, idx = render.idx, sel = render.sel; + int date_len = 0; + + value = substring (data->data[idx].metrics->data, 0, w - *x); + if (data->module == VISITORS) { + date = set_visitors_date (value); + date_len = strlen (date); + } + + if (sel && data->module == HOSTS && data->data[idx].is_subitem) { + render_data_hosts (win, render, value, *x); + } else if (sel) { + buf = data->module == VISITORS ? date : value; + draw_header (win, buf, "%s", y, *x, w, color_selected); + } else { + wattron (win, color->attr | COLOR_PAIR (color->pair->idx)); + mvwprintw (win, y, *x, "%s", data->module == VISITORS ? date : value); + wattroff (win, color->attr | COLOR_PAIR (color->pair->idx)); + } + + *x += data->module == VISITORS ? date_len : data->meta.data_len; + *x += DASH_SPACE; + free (value); + free (date); +} + +/* Render the method metric for each panel + * + * On error, no method is rendered and it returns. + * On success, method is rendered. */ +static void +render_method (GDashModule *data, GDashRender render, int *x) { + GColors *color = get_color_by_item_module (COLOR_MTRC_MTHD, data->module); + WINDOW *win = render.win; + + int y = render.y, w = render.w, idx = render.idx, sel = render.sel; + char *method = data->data[idx].metrics->method; + + if (method == NULL || *method == '\0') + return; + + if (sel) { + /* selected state */ + draw_header (win, method, "%s", y, *x, w, color_selected); + } else { + /* regular state */ + wattron (win, color->attr | COLOR_PAIR (color->pair->idx)); + mvwprintw (win, y, *x, "%s", method); + wattroff (win, color->attr | COLOR_PAIR (color->pair->idx)); + } + + *x += data->meta.method_len + DASH_SPACE; +} + +/* Render the protocol metric for each panel + * + * On error, no protocol is rendered and it returns. + * On success, protocol is rendered. */ +static void +render_proto (GDashModule *data, GDashRender render, int *x) { + GColors *color = get_color_by_item_module (COLOR_MTRC_PROT, data->module); + WINDOW *win = render.win; + + int y = render.y, w = render.w, idx = render.idx, sel = render.sel; + char *protocol = data->data[idx].metrics->protocol; + + if (protocol == NULL || *protocol == '\0') + return; + + if (sel) { + /* selected state */ + draw_header (win, protocol, "%s", y, *x, w, color_selected); + } else { + /* regular state */ + wattron (win, color->attr | COLOR_PAIR (color->pair->idx)); + mvwprintw (win, y, *x, "%s", protocol); + wattroff (win, color->attr | COLOR_PAIR (color->pair->idx)); + } + + *x += REQ_PROTO_LEN - 1 + DASH_SPACE; +} + +/* Render the average time served metric for each panel */ +static void +render_avgts (GDashModule *data, GDashRender render, int *x) { + GColors *color = get_color_by_item_module (COLOR_MTRC_AVGTS, data->module); + WINDOW *win = render.win; + + int y = render.y, w = render.w, idx = render.idx, sel = render.sel; + char *avgts = data->data[idx].metrics->avgts.sts; + + if (data->module == HOSTS && data->data[idx].is_subitem) + goto out; + + if (sel) { + /* selected state */ + draw_header (win, avgts, "%9s", y, *x, w, color_selected); + } else { + /* regular state */ + wattron (win, color->attr | COLOR_PAIR (color->pair->idx)); + mvwprintw (win, y, *x, "%9s", avgts); + wattroff (win, color->attr | COLOR_PAIR (color->pair->idx)); + } + +out: + *x += DASH_SRV_TM_LEN + DASH_SPACE; +} + +/* Render the cumulative time served metric for each panel */ +static void +render_cumts (GDashModule *data, GDashRender render, int *x) { + GColors *color = get_color_by_item_module (COLOR_MTRC_CUMTS, data->module); + WINDOW *win = render.win; + + int y = render.y, w = render.w, idx = render.idx, sel = render.sel; + char *cumts = data->data[idx].metrics->cumts.sts; + + if (data->module == HOSTS && data->data[idx].is_subitem) + goto out; + + if (sel) { + /* selected state */ + draw_header (win, cumts, "%9s", y, *x, w, color_selected); + } else { + /* regular state */ + wattron (win, color->attr | COLOR_PAIR (color->pair->idx)); + mvwprintw (win, y, *x, "%9s", cumts); + wattroff (win, color->attr | COLOR_PAIR (color->pair->idx)); + } + +out: + *x += DASH_SRV_TM_LEN + DASH_SPACE; +} + +/* Render the maximum time served metric for each panel */ +static void +render_maxts (GDashModule *data, GDashRender render, int *x) { + GColors *color = get_color_by_item_module (COLOR_MTRC_MAXTS, data->module); + WINDOW *win = render.win; + + int y = render.y, w = render.w, idx = render.idx, sel = render.sel; + char *maxts = data->data[idx].metrics->maxts.sts; + + if (data->module == HOSTS && data->data[idx].is_subitem) + goto out; + + if (sel) { + /* selected state */ + draw_header (win, maxts, "%9s", y, *x, w, color_selected); + } else { + /* regular state */ + wattron (win, color->attr | COLOR_PAIR (color->pair->idx)); + mvwprintw (win, y, *x, "%9s", maxts); + wattroff (win, color->attr | COLOR_PAIR (color->pair->idx)); + } + +out: + *x += DASH_SRV_TM_LEN + DASH_SPACE; +} + +/* Render the bandwidth metric for each panel */ +static void +render_bw (GDashModule *data, GDashRender render, int *x) { + GColors *color = get_color_by_item_module (COLOR_MTRC_BW, data->module); + WINDOW *win = render.win; + + int y = render.y, w = render.w, idx = render.idx, sel = render.sel; + char *bw = data->data[idx].metrics->bw.sbw; + + if (data->module == HOSTS && data->data[idx].is_subitem) + goto out; + + if (sel) { + char *fw = get_fixed_fmt_width (data->meta.bw_len, 's'); + /* selected state */ + draw_header (win, bw, fw, y, *x, w, color_selected); + free (fw); + } else { + /* regular state */ + wattron (win, color->attr | COLOR_PAIR (color->pair->idx)); + mvwprintw (win, y, *x, "%*s", data->meta.bw_len, bw); + wattroff (win, color->attr | COLOR_PAIR (color->pair->idx)); + } + +out: + *x += data->meta.bw_len + DASH_SPACE; +} + +/* Render a percent metric */ +static void +render_percent (GDashRender render, GColors *color, float perc, int len, int x) { + WINDOW *win = render.win; + char *percent; + int y = render.y, w = render.w, sel = render.sel; + + if (sel) { + /* selected state */ + percent = float2str (perc, len); + draw_header (win, percent, "%s%%", y, x, w, color_selected); + free (percent); + } else { + /* regular state */ + wattron (win, color->attr | COLOR_PAIR (color->pair->idx)); + mvwprintw (win, y, x, "%*.2f%%", len, perc); + wattroff (win, color->attr | COLOR_PAIR (color->pair->idx)); + } +} + +/* Render the hits percent metric for each panel */ +static void +render_hits_percent (GDashModule *data, GDashRender render, int *x) { + GColorItem item = COLOR_MTRC_HITS_PERC; + GColors *color; + int l = data->meta.hits_perc_len + 3, idx = render.idx; + + if (data->module == HOSTS && data->data[idx].is_subitem) + goto out; + + if (data->meta.max_hits == data->data[idx].metrics->hits) + item = COLOR_MTRC_HITS_PERC_MAX; + + color = get_color_by_item_module (item, data->module); + render_percent (render, color, data->data[idx].metrics->hits_perc, l, *x); + +out: + *x += l + 1 + DASH_SPACE; +} + +/* Render the visitors percent metric for each panel */ +static void +render_visitors_percent (GDashModule *data, GDashRender render, int *x) { + GColorItem item = COLOR_MTRC_VISITORS_PERC; + GColors *color; + int l = data->meta.visitors_perc_len + 3, idx = render.idx; + + if (data->module == HOSTS && data->data[idx].is_subitem) + goto out; + + if (data->meta.max_visitors == data->data[idx].metrics->visitors) + item = COLOR_MTRC_VISITORS_PERC_MAX; + + color = get_color_by_item_module (item, data->module); + render_percent (render, color, data->data[idx].metrics->visitors_perc, l, *x); + +out: + *x += l + 1 + DASH_SPACE; +} + +/* Render the hits metric for each panel */ +static void +render_hits (GDashModule *data, GDashRender render, int *x) { + GColors *color = get_color_by_item_module (COLOR_MTRC_HITS, data->module); + WINDOW *win = render.win; + + char *hits; + int y = render.y, w = render.w, idx = render.idx, sel = render.sel; + int len = data->meta.hits_len; + + if (data->module == HOSTS && data->data[idx].is_subitem) + goto out; + + if (sel) { + /* selected state */ + hits = u642str (data->data[idx].metrics->hits, len); + draw_header (win, hits, " %s", y, 0, w, color_selected); + free (hits); + } else { + /* regular state */ + wattron (win, color->attr | COLOR_PAIR (color->pair->idx)); + mvwprintw (win, y, *x, "%*" PRIu64 "", len, data->data[idx].metrics->hits); + wattroff (win, color->attr | COLOR_PAIR (color->pair->idx)); + } + +out: + *x += len + DASH_SPACE; +} + +/* Render the visitors metric for each panel */ +static void +render_visitors (GDashModule *data, GDashRender render, int *x) { + GColors *color = get_color_by_item_module (COLOR_MTRC_VISITORS, data->module); + WINDOW *win = render.win; + + char *visitors; + int y = render.y, w = render.w, idx = render.idx, sel = render.sel; + int len = data->meta.visitors_len; + + if (data->module == HOSTS && data->data[idx].is_subitem) + goto out; + + if (sel) { + /* selected state */ + visitors = u642str (data->data[idx].metrics->visitors, len); + draw_header (win, visitors, "%s", y, *x, w, color_selected); + free (visitors); + } else { + /* regular state */ + wattron (win, color->attr | COLOR_PAIR (color->pair->idx)); + mvwprintw (win, y, *x, "%*" PRIu64 "", len, data->data[idx].metrics->visitors); + wattroff (win, color->attr | COLOR_PAIR (color->pair->idx)); + } + +out: + *x += len + DASH_SPACE; +} + +/* Render the header row for each panel */ +static void +render_header (WINDOW *win, GDashModule *data, GModule cur_module, int *y) { + GColors *(*func) (void); + char ind; + char *hd; + int k, w, h; + + getmaxyx (win, h, w); + (void) h; + + k = data->module + 1; + ind = cur_module == data->module ? '>' : ' '; + func = cur_module == data->module && conf.hl_header ? color_panel_active : color_panel_header; + hd = xmalloc (snprintf (NULL, 0, "%c %d - %s", ind, k, data->head) + 1); + sprintf (hd, "%c %d - %s", ind, k, data->head); + + draw_header (win, hd, " %s", (*y), 0, w, func); + free (hd); + + render_total_label (win, data, (*y), func); + data->pos_y = (*y); + (*y)++; +} + +/* Render the description row for each panel */ +static void +render_description (WINDOW *win, GDashModule *data, int *y) { + int w, h; + + getmaxyx (win, h, w); + (void) h; + + draw_header (win, data->desc, " %s", (*y), 0, w, color_panel_desc); + + data->pos_y = (*y); + (*y)++; + (*y)++; /* add empty line underneath description */ +} + +/* Render available metrics per panel. + * ###TODO: Have the abilitity to display metrics in specific order */ +static void +render_metrics (GDashModule *data, GDashRender render, int expanded) { + int x = get_xpos (); + GModule module = data->module; + const GOutput *output = output_lookup (module); + + /* basic metrics */ + if (output->hits) + render_hits (data, render, &x); + if (output->percent) + render_hits_percent (data, render, &x); + if (output->visitors) + render_visitors (data, render, &x); + if (output->percent) + render_visitors_percent (data, render, &x); + + /* render bandwidth if available */ + if (conf.bandwidth && output->bw) + render_bw (data, render, &x); + + /* render avgts, cumts and maxts if available */ + if (output->avgts && conf.serve_usecs) + render_avgts (data, render, &x); + if (output->cumts && conf.serve_usecs) + render_cumts (data, render, &x); + if (output->maxts && conf.serve_usecs) + render_maxts (data, render, &x); + + /* render request method if available */ + if (output->method && conf.append_method) + render_method (data, render, &x); + /* render request protocol if available */ + if (output->protocol && conf.append_protocol) + render_proto (data, render, &x); + if (output->data) + render_data (data, render, &x); + + /* skip graph bars if module is expanded and we have sub nodes */ + if ((output->graph && !expanded) || (output->sub_graph && expanded)) + render_bars (data, render, &x); +} + +/* Render a dashboard row. */ +static void +render_data_line (WINDOW *win, GDashModule *data, int *y, int j, GScroll *gscroll) { + GDashRender render; + GModule module = data->module; + int expanded = 0, sel = 0; + int w, h; + + getmaxyx (win, h, w); + (void) h; + + if (gscroll->expanded && module == gscroll->current) + expanded = 1; + + if (j >= data->idx_data) + goto out; + + sel = expanded && j == gscroll->module[module].scroll ? 1 : 0; + + render.win = win; + render.y = *y; + render.w = w; + render.idx = j; + render.sel = sel; + + render_metrics (data, render, expanded); + +out: + (*y)++; +} + +/* Render a dashed line underneath the metric label. */ +static void +print_horizontal_dash (WINDOW *win, int y, int x, int len) { + mvwprintw (win, y, x, "%.*s", len, "----------------"); +} + +/* Render left-aligned column label. */ +static void +lprint_col (WINDOW *win, int y, int *x, int len, const char *str) { + GColors *color = get_color (COLOR_PANEL_COLS); + + wattron (win, color->attr | COLOR_PAIR (color->pair->idx)); + mvwprintw (win, y, *x, "%s", str); + print_horizontal_dash (win, y + 1, *x, len); + wattroff (win, color->attr | COLOR_PAIR (color->pair->idx)); + + *x += len + DASH_SPACE; +} + +/* Render right-aligned column label. */ +static void +rprint_col (WINDOW *win, int y, int *x, int len, const char *str) { + GColors *color = get_color (COLOR_PANEL_COLS); + + wattron (win, color->attr | COLOR_PAIR (color->pair->idx)); + mvwprintw (win, y, *x, "%*s", len, str); + print_horizontal_dash (win, y + 1, *x, len); + wattroff (win, color->attr | COLOR_PAIR (color->pair->idx)); + + *x += len + DASH_SPACE; +} + +/* Render column names for available metrics. + * ###TODO: Have the abilitity to display metrics in specific order */ +static void +render_cols (WINDOW *win, GDashModule *data, int *y) { + GModule module = data->module; + const GOutput *output = output_lookup (module); + int x = get_xpos (); + + if (data->idx_data == 0 || conf.no_column_names) + return; + + if (output->hits) + lprint_col (win, *y, &x, data->meta.hits_len, MTRC_HITS_LBL); + + if (output->percent) + rprint_col (win, *y, &x, data->meta.hits_perc_len + 4, MTRC_HITS_PERC_LBL); + + if (output->visitors) + rprint_col (win, *y, &x, data->meta.visitors_len, MTRC_VISITORS_SHORT_LBL); + + if (output->percent) + rprint_col (win, *y, &x, data->meta.visitors_perc_len + 4, MTRC_VISITORS_PERC_LBL); + + if (output->bw && conf.bandwidth) + rprint_col (win, *y, &x, data->meta.bw_len, MTRC_BW_LBL); + + if (output->avgts && conf.serve_usecs) + rprint_col (win, *y, &x, DASH_SRV_TM_LEN, MTRC_AVGTS_LBL); + + if (output->cumts && conf.serve_usecs) + rprint_col (win, *y, &x, DASH_SRV_TM_LEN, MTRC_CUMTS_LBL); + + if (output->maxts && conf.serve_usecs) + rprint_col (win, *y, &x, DASH_SRV_TM_LEN, MTRC_MAXTS_LBL); + + if (output->method && conf.append_method) + lprint_col (win, *y, &x, data->meta.method_len, MTRC_METHODS_SHORT_LBL); + + if (output->protocol && conf.append_protocol) + lprint_col (win, *y, &x, 8, MTRC_PROTOCOLS_SHORT_LBL); + + if (output->data) + lprint_col (win, *y, &x, 4, MTRC_DATA_LBL); +} + +/* Iterate over all dashboard data and render its content. */ +static void +render_content (WINDOW *win, GDashModule *data, int *y, int *offset, int *total, GScroll *gscroll) { + GModule module = data->module; + int i, j, size, h, w, data_pos = get_data_pos_rows (); + + getmaxyx (win, h, w); + (void) w; + + size = data->dash_size; + for (i = *offset; i < size; i++) { + /* header */ + if ((i % size) == DASH_HEAD_POS) { + render_header (win, data, gscroll->current, y); + } else if ((i % size) == DASH_EMPTY_POS && conf.no_column_names) { + /* if no column names, print panel description */ + render_description (win, data, y); + } else if ((i % size) == DASH_EMPTY_POS || (i % size) == size - 1) { + /* blank lines */ + (*y)++; + } else if ((i % size) == DASH_DASHES_POS && !conf.no_column_names) { + /* account for already printed dash lines under columns */ + (*y)++; + } else if ((i % size) == DASH_COLS_POS && !conf.no_column_names) { + /* column headers lines */ + render_cols (win, data, y); + (*y)++; + } else if ((i % size) >= data_pos || (i % size) <= size - 2) { + /* account for 2 lines at the header and 2 blank lines */ + j = ((i % size) - data_pos) + gscroll->module[module].offset; + /* actual data */ + render_data_line (win, data, y, j, gscroll); + } else { + /* everything else should be empty */ + (*y)++; + } + (*total)++; + if (*y >= h) + break; + } +} + +/* Entry point to render the terminal dashboard. */ +void +display_content (WINDOW *win, GDash *dash, GScroll *gscroll) { + GModule module; + int j = 0; + size_t idx = 0; + + int y = 0, offset = 0, total = 0; + int dash_scroll = gscroll->dash; + + werase (win); + + FOREACH_MODULE (idx, module_list) { + module = module_list[idx]; + + offset = 0; + for (j = 0; j < dash->module[module].dash_size; j++) { + if (dash_scroll > total) { + offset++; + total++; + } + } + /* used module */ + dash->module[module].module = module; + + render_content (win, &dash->module[module], &y, &offset, &total, gscroll); + } + wrefresh (win); +} + +/* Reset the scroll and offset fields for each panel/module. */ +void +reset_scroll_offsets (GScroll *gscroll) { + GModule module; + size_t idx = 0; + + FOREACH_MODULE (idx, module_list) { + module = module_list[idx]; + + gscroll->module[module].scroll = 0; + gscroll->module[module].offset = 0; + } +} + +/* Compile the regular expression and see if it's valid. + * + * If unable to compile, an error as described in . + * Upon successful completion, function returns 0. */ +static int +regexp_init (regex_t *regex, const char *pattern) { + int y, x, rc; + char buf[REGEX_ERROR]; + + getmaxyx (stdscr, y, x); + rc = regcomp (regex, pattern, REG_EXTENDED | (find_t.icase ? REG_ICASE : 0)); + /* something went wrong */ + if (rc != 0) { + regerror (rc, regex, buf, sizeof (buf)); + draw_header (stdscr, buf, "%s", y - 1, 0, x, color_error); + refresh (); + return 1; + } + return 0; +} + +/* Set the dashboard scroll and offset based on the search index. */ +static void +perform_find_dash_scroll (GScroll *gscroll, GModule module) { + int *scrll, *offset; + int exp_size = get_num_expanded_data_rows (); + + /* reset gscroll offsets if we are changing module */ + if (gscroll->current != module) + reset_scroll_offsets (gscroll); + + scrll = &gscroll->module[module].scroll; + offset = &gscroll->module[module].offset; + + (*scrll) = find_t.next_idx; + if (*scrll >= exp_size && *scrll >= *offset + exp_size) + (*offset) = (*scrll) < exp_size - 1 ? 0 : (*scrll) - exp_size + 1; + + gscroll->current = module; + gscroll->dash = get_module_index (module) * DASH_COLLAPSED; + gscroll->expanded = 1; + find_t.module = module; +} + +/* Find the searched item within the given sub list. + * + * If not found, the GFind structure is reset and 1 is returned. + * If found, a GFind structure is set and 0 is returned. */ +static int +find_next_sub_item (GSubList *sub_list, regex_t *regex) { + GSubItem *iter; + int i = 0, rc; + + if (sub_list == NULL) + goto out; + + for (iter = sub_list->head; iter; iter = iter->next) { + if (i >= find_t.next_sub_idx) { + rc = regexec (regex, iter->metrics->data, 0, NULL, 0); + if (rc == 0) { + find_t.next_idx++; + find_t.next_sub_idx = (1 + i); + return 0; + } + find_t.next_idx++; + } + i++; + } +out: + find_t.next_parent_idx++; + find_t.next_sub_idx = 0; + find_t.look_in_sub = 0; + + return 1; +} + +/* Perform a forward search across all modules. + * + * On error or if not found, 1 is returned. + * On success or if found, a GFind structure is set and 0 is returned. */ +int +perform_next_find (GHolder *h, GScroll *gscroll) { + GModule module; + GSubList *sub_list; + regex_t regex; + char buf[REGEX_ERROR], *data; + int y, x, j, n, rc; + size_t idx = 0; + + getmaxyx (stdscr, y, x); + + if (find_t.pattern == NULL || *find_t.pattern == '\0') + return 1; + + /* compile and initialize regexp */ + if (regexp_init (®ex, find_t.pattern)) + return 1; + + /* use last find_t.module and start search */ + idx = find_t.module; + FOREACH_MODULE (idx, module_list) { + module = module_list[idx]; + + n = h[module].idx; + for (j = find_t.next_parent_idx; j < n; j++, find_t.next_idx++) { + data = h[module].items[j].metrics->data; + + rc = regexec (®ex, data, 0, NULL, 0); + /* error matching against the precompiled pattern buffer */ + if (rc != 0 && rc != REG_NOMATCH) { + regerror (rc, ®ex, buf, sizeof (buf)); + draw_header (stdscr, buf, "%s", y - 1, 0, x, color_error); + refresh (); + regfree (®ex); + return 1; + } + /* a match was found (data level) */ + else if (rc == 0 && !find_t.look_in_sub) { + find_t.look_in_sub = 1; + perform_find_dash_scroll (gscroll, module); + goto out; + } + /* look at sub list nodes */ + else { + sub_list = h[module].items[j].sub_list; + if (find_next_sub_item (sub_list, ®ex) == 0) { + perform_find_dash_scroll (gscroll, module); + goto out; + } + } + } + + /* reset find */ + find_t.next_idx = 0; + find_t.next_parent_idx = 0; + find_t.next_sub_idx = 0; + + if (find_t.module != module) { + reset_scroll_offsets (gscroll); + gscroll->expanded = 0; + } + if (module == TOTAL_MODULES - 1) { + find_t.module = 0; + goto out; + } + } + +out: + regfree (®ex); + return 0; +} + +/* Render a find dialog. + * + * On error or if no query is set, 1 is returned. + * On success, the dialog is rendered and 0 is returned. */ +int +render_find_dialog (WINDOW *main_win, GScroll *gscroll) { + int y, x, valid = 1; + int w = FIND_DLG_WIDTH; + int h = FIND_DLG_HEIGHT; + char *query = NULL; + WINDOW *win; + + getmaxyx (stdscr, y, x); + + win = newwin (h, w, (y - h) / 2, (x - w) / 2); + keypad (win, TRUE); + wborder (win, '|', '|', '-', '-', '+', '+', '+', '+'); + draw_header (win, FIND_HEAD, " %s", 1, 1, w - 2, color_panel_header); + mvwprintw (win, 2, 1, " %s", FIND_DESC); + + find_t.icase = 0; + query = input_string (win, 4, 2, w - 3, "", 1, &find_t.icase); + if (query != NULL && *query != '\0') { + reset_scroll_offsets (gscroll); + reset_find (); + find_t.pattern = xstrdup (query); + valid = 0; + } + if (query != NULL) + free (query); + touchwin (main_win); + close_win (win); + wrefresh (main_win); + + return valid; +} + +static void +set_dash_metrics (GDash **dash, GMetrics *metrics, GModule module, + GPercTotals totals, int is_subitem) { + GDashData *idata = NULL; + GDashMeta *meta = NULL; + char *data = NULL; + int *idx; + + data = is_subitem ? render_child_node (metrics->data) : metrics->data; + if (!data) + return; + + idx = &(*dash)->module[module].idx_data; + idata = &(*dash)->module[module].data[(*idx)]; + meta = &(*dash)->module[module].meta; + + idata->metrics = new_gmetrics (); + idata->is_subitem = is_subitem; + + idata->metrics->hits = metrics->hits; + idata->metrics->hits_perc = get_percentage (totals.hits, metrics->hits); + idata->metrics->visitors = metrics->visitors; + idata->metrics->visitors_perc = get_percentage (totals.visitors, metrics->visitors); + idata->metrics->bw.sbw = filesize_str (metrics->bw.nbw); + idata->metrics->data = xstrdup (data); + + if (conf.append_method && metrics->method) + idata->metrics->method = metrics->method; + if (conf.append_protocol && metrics->protocol) + idata->metrics->protocol = metrics->protocol; + + if (!conf.serve_usecs) + goto out; + + idata->metrics->avgts.sts = usecs_to_str (metrics->avgts.nts); + idata->metrics->cumts.sts = usecs_to_str (metrics->cumts.nts); + idata->metrics->maxts.sts = usecs_to_str (metrics->maxts.nts); + +out: + if (is_subitem) + free (data); + + set_metrics_len (meta, idata); + set_max_metrics (meta, idata); + + (*idx)++; +} + +/* Add an item from a sub list to the dashboard. + * + * If no items on the sub list, the function returns. + * On success, sub list data is set into the dashboard structure. */ +static void +add_sub_item_to_dash (GDash **dash, GHolderItem item, GModule module, GPercTotals totals, int *i) { + GSubList *sub_list = item.sub_list; + GSubItem *iter; + + if (sub_list == NULL) + return; + + for (iter = sub_list->head; iter; iter = iter->next, (*i)++) { + set_dash_metrics (dash, iter->metrics, module, totals, 1); + } +} + +/* Add a first level item to dashboard. + * + * On success, data is set into the dashboard structure. */ +static void +add_item_to_dash (GDash **dash, GHolderItem item, GModule module, GPercTotals totals) { + set_dash_metrics (dash, item.metrics, module, totals, 0); +} + +/* Load holder's data into the dashboard structure. */ +void +load_data_to_dash (GHolder *h, GDash *dash, GModule module, GScroll *gscroll) { + int alloc_size = 0; + int i, j; + GPercTotals totals; + + alloc_size = dash->module[module].alloc_data; + if (gscroll->expanded && module == gscroll->current) + alloc_size += h->sub_items_size; + + dash->module[module].alloc_data = alloc_size; + dash->module[module].data = new_gdata (alloc_size); + dash->module[module].holder_size = h->holder_size; + memset (&dash->module[module].meta, 0, sizeof (GDashData)); + + set_module_totals (&totals); + + for (i = 0, j = 0; i < alloc_size; i++) { + if (h->items[j].metrics->data == NULL) + continue; + + add_item_to_dash (&dash, h->items[j], module, totals); + if (gscroll->expanded && module == gscroll->current && h->sub_items_size) + add_sub_item_to_dash (&dash, h->items[j], module, totals, &i); + j++; + } +} diff --git a/src/gdashboard.h b/src/gdashboard.h new file mode 100644 index 0000000000..34c170076f --- /dev/null +++ b/src/gdashboard.h @@ -0,0 +1,134 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#ifndef GDASHBOARD_H_INCLUDED +#define GDASHBOARD_H_INCLUDED + +#include + +#include "ui.h" + +#define DASH_HEAD_POS 0 /* position of header line */ +#define DASH_EMPTY_POS 1 /* empty line position */ +#define DASH_COLS_POS 2 /* position of column names */ +#define DASH_DASHES_POS 3 /* position of dashes under column names */ +#define DASH_DATA_POS 4 /* data line position */ + +#define DASH_NON_DATA 5 /* number of rows without data stats */ +#define DASH_COL_ROWS 2 /* number of rows for column values + dashed lines */ + +#define DASH_COLLAPSED 12 /* number of rows per panel (collapsed) */ +#define DASH_EXPANDED 32 /* number of rows per panel (expanded) */ + +#define DASH_INIT_X 1 /* start position (x-axis) */ + +#define DASH_BW_LEN 11 /* max bandwidth string length, e.g., 151.69 MiB */ +#define DASH_SRV_TM_LEN 9 /* max time served length, e.g., 483.00 us */ +#define DASH_SPACE 1 /* space between columns (metrics) */ + +/* Common render data line fields */ +typedef struct GDashRender_ { + WINDOW *win; + int y; + int w; + int idx; + int sel; +} GDashRender; + +/* Dashboard panel item */ +typedef struct GDashData_ { + GMetrics *metrics; + short is_subitem; +} GDashData; + +/* Dashboard panel meta data */ +typedef struct GDashMeta_ { + uint64_t max_hits; /* maximum value on the hits column */ + uint64_t max_visitors; /* maximum value on the visitors column */ + + /* determine the maximum metric's length of these metrics */ + /* for instance, 1022 is the max value for the hits column and its length = 4 */ + int hits_len; + int hits_perc_len; + int visitors_len; + int visitors_perc_len; + int bw_len; + int avgts_len; + int cumts_len; + int maxts_len; + int method_len; + int protocol_len; + int data_len; +} GDashMeta; + +/* Dashboard panel */ +typedef struct GDashModule_ { + GDashData *data; /* data metrics */ + GModule module; /* module */ + GDashMeta meta; /* meta data */ + + const char *head; /* panel header */ + const char *desc; /* panel description */ + + int alloc_data; /* number of data items allocated. */ + /* e.g., MAX_CHOICES or holder size */ + int dash_size; /* dashboard size */ + int holder_size; /* hash table size */ + int ht_size; /* hash table size */ + int idx_data; /* idx data */ + + unsigned short pos_y; /* dashboard current Y position */ +} GDashModule; + +/* Dashboard */ +typedef struct GDash_ { + int total_alloc; /* number of allocated dashboard lines */ + GDashModule module[TOTAL_MODULES]; +} GDash; + +/* Function Prototypes */ +GDashData *new_gdata (uint32_t size); +GDash *new_gdash (void); +int get_num_collapsed_data_rows (void); +int get_num_expanded_data_rows (void); +int perform_next_find (GHolder * h, GScroll * scroll); +int render_find_dialog (WINDOW * main_win, GScroll * scroll); +int set_module_from_mouse_event (GScroll * scroll, GDash * dash, int y); +uint32_t get_ht_size_by_module (GModule module); +void display_content (WINDOW * win, GDash * dash, GScroll * scroll); +void free_dashboard (GDash * dash); +void load_data_to_dash (GHolder * h, GDash * dash, GModule module, GScroll * scroll); +void reset_find (void); +void reset_scroll_offsets (GScroll * scroll); + +#endif diff --git a/src/gdns.c b/src/gdns.c new file mode 100644 index 0000000000..6c82c2429f --- /dev/null +++ b/src/gdns.c @@ -0,0 +1,276 @@ +/** + * gdns.c -- hosts resolver + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#define _MULTI_THREADED +#ifdef __FreeBSD__ +#include +#endif + +#if HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gdns.h" + +#include "error.h" +#include "gkhash.h" +#include "goaccess.h" +#include "util.h" +#include "xmalloc.h" + +GDnsThread gdns_thread; +static GDnsQueue *gdns_queue; + +/* Initialize the queue. */ +void +gqueue_init (GDnsQueue *q, int capacity) { + q->head = 0; + q->tail = -1; + q->size = 0; + q->capacity = capacity; +} + +/* Get the current size of queue. + * + * Returns the size of the queue. */ +int +gqueue_size (GDnsQueue *q) { + return q->size; +} + +/* Determine if the queue is empty. + * + * Returns true if empty, otherwise false. */ +int +gqueue_empty (GDnsQueue *q) { + return q->size == 0; +} + +/* Determine if the queue is full. + * + * Returns true if full, otherwise false. */ +int +gqueue_full (GDnsQueue *q) { + return q->size == q->capacity; +} + +/* Free the queue. */ +void +gqueue_destroy (GDnsQueue *q) { + free (q); +} + +/* Add at the end of the queue a string item. + * + * If the queue is full, -1 is returned. + * If added to the queue, 0 is returned. */ +int +gqueue_enqueue (GDnsQueue *q, const char *item) { + if (gqueue_full (q)) + return -1; + + q->tail = (q->tail + 1) % q->capacity; + strncpy (q->buffer[q->tail], item, sizeof (q->buffer[q->tail])); + q->buffer[q->tail][sizeof (q->buffer[q->tail]) - 1] = '\0'; + q->size++; + return 0; +} + +/* Find a string item in the queue. + * + * If the queue is empty, or the item is not in the queue, 0 is returned. + * If found, 1 is returned. */ +int +gqueue_find (GDnsQueue *q, const char *item) { + int i; + if (gqueue_empty (q)) + return 0; + + for (i = 0; i < q->size; i++) { + if (strcmp (item, q->buffer[i]) == 0) + return 1; + } + return 0; +} + +/* Remove a string item from the head of the queue. + * + * If the queue is empty, NULL is returned. + * If removed, the string item is returned. */ +char * +gqueue_dequeue (GDnsQueue *q) { + char *item; + if (gqueue_empty (q)) + return NULL; + + item = q->buffer[q->head]; + q->head = (q->head + 1) % q->capacity; + q->size--; + return item; +} + +/* Get the corresponding hostname given an IP address. + * + * On error, a string error message is returned. + * On success, a malloc'd hostname is returned. */ +static char * +reverse_host (const struct sockaddr *a, socklen_t length) { + char h[H_SIZE] = { 0 }; + int flags, st; + + flags = NI_NAMEREQD; + st = getnameinfo (a, length, h, H_SIZE, NULL, 0, flags); + if (!st) { + /* BSD returns \0 while Linux . on solve lookups */ + if (*h == '\0') + return alloc_string ("."); + return alloc_string (h); + } + return alloc_string (gai_strerror (st)); +} + +/* Determine if IPv4 or IPv6 and resolve. + * + * On error, NULL is returned. + * On success, a malloc'd hostname is returned. */ +char * +reverse_ip (char *str) { + union { + struct sockaddr addr; + struct sockaddr_in6 addr6; + struct sockaddr_in addr4; + } a; + + if (str == NULL || *str == '\0') + return NULL; + + memset (&a, 0, sizeof (a)); + if (1 == inet_pton (AF_INET, str, &a.addr4.sin_addr)) { + a.addr4.sin_family = AF_INET; + return reverse_host (&a.addr, sizeof (a.addr4)); + } else if (1 == inet_pton (AF_INET6, str, &a.addr6.sin6_addr)) { + a.addr6.sin6_family = AF_INET6; + return reverse_host (&a.addr, sizeof (a.addr6)); + } + return NULL; +} + +/* Producer - Resolve an IP address and add it to the queue. */ +void +dns_resolver (char *addr) { + pthread_mutex_lock (&gdns_thread.mutex); + /* queue is not full and the IP address is not in the queue */ + if (!gqueue_full (gdns_queue) && !gqueue_find (gdns_queue, addr)) { + /* add the IP to the queue */ + gqueue_enqueue (gdns_queue, addr); + pthread_cond_broadcast (&gdns_thread.not_empty); + } + pthread_mutex_unlock (&gdns_thread.mutex); +} + +/* Consumer - Once an IP has been resolved, add it to dwithe hostnames + * hash structure. */ +static void +dns_worker (void GO_UNUSED (*ptr_data)) { + char *ip = NULL, *host = NULL; + + while (1) { + pthread_mutex_lock (&gdns_thread.mutex); + /* wait until an item has been added to the queue */ + while (gqueue_empty (gdns_queue)) + pthread_cond_wait (&gdns_thread.not_empty, &gdns_thread.mutex); + + ip = gqueue_dequeue (gdns_queue); + + pthread_mutex_unlock (&gdns_thread.mutex); + host = reverse_ip (ip); + pthread_mutex_lock (&gdns_thread.mutex); + + if (!active_gdns) { + pthread_mutex_unlock (&gdns_thread.mutex); + free (host); + return; + } + + /* insert the corresponding IP -> hostname map */ + if (host != NULL && active_gdns) { + ht_insert_hostname (ip, host); + free (host); + } + + pthread_cond_signal (&gdns_thread.not_full); + pthread_mutex_unlock (&gdns_thread.mutex); + } +} + +/* Initialize queue and dns thread */ +void +gdns_init (void) { + gdns_queue = xmalloc (sizeof (GDnsQueue)); + gqueue_init (gdns_queue, QUEUE_SIZE); + + if (pthread_cond_init (&(gdns_thread.not_empty), NULL)) + FATAL ("Failed init thread condition"); + + if (pthread_cond_init (&(gdns_thread.not_full), NULL)) + FATAL ("Failed init thread condition"); + + if (pthread_mutex_init (&(gdns_thread.mutex), NULL)) + FATAL ("Failed init thread mutex"); +} + +/* Destroy (free) queue */ +void +gdns_free_queue (void) { + gqueue_destroy (gdns_queue); +} + +/* Create a DNS thread and make it active */ +void +gdns_thread_create (void) { + int th; + + active_gdns = 1; + th = pthread_create (&(gdns_thread.thread), NULL, (void *) &dns_worker, NULL); + if (th) + FATAL ("Return code from pthread_create(): %d", th); + pthread_detach (gdns_thread.thread); +} diff --git a/src/gdns.h b/src/gdns.h new file mode 100644 index 0000000000..d84743e745 --- /dev/null +++ b/src/gdns.h @@ -0,0 +1,68 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef GDNS_H_INCLUDED +#define GDNS_H_INCLUDED + +#define H_SIZE 1025 +#define QUEUE_SIZE 400 + +typedef struct GDnsThread_ { + pthread_cond_t not_empty; /* not empty queue condition */ + pthread_cond_t not_full; /* not full queue condition */ + pthread_mutex_t mutex; + pthread_t thread; +} GDnsThread; + +typedef struct GDnsQueue_ { + int head; /* index to head of queue */ + int tail; /* index to tail of queue */ + int size; /* queue size */ + int capacity; /* length at most */ + char buffer[QUEUE_SIZE][H_SIZE]; /* data item */ +} GDnsQueue; + +extern GDnsThread gdns_thread; + +char *gqueue_dequeue (GDnsQueue * q); +char *reverse_ip (char *str); +int gqueue_empty (GDnsQueue * q); +int gqueue_enqueue (GDnsQueue * q, const char *item); +int gqueue_find (GDnsQueue * q, const char *item); +int gqueue_full (GDnsQueue * q); +int gqueue_size (GDnsQueue * q); +void dns_resolver (char *addr); +void gdns_free_queue (void); +void gdns_init (void); +void gdns_queue_free (void); +void gdns_thread_create (void); +void gqueue_destroy (GDnsQueue * q); +void gqueue_init (GDnsQueue * q, int capacity); + +#endif diff --git a/src/geoip1.c b/src/geoip1.c new file mode 100644 index 0000000000..3f8dc79d23 --- /dev/null +++ b/src/geoip1.c @@ -0,0 +1,610 @@ +/** + * geoip.c -- implementation of GeoIP (legacy) + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#ifdef HAVE_LIBGEOIP +#include +#include +#endif + +#include "geoip1.h" + +#include "error.h" +#include "util.h" + +static GeoIP **geoips = NULL; +static GeoIP *geo_location_data = NULL; +static int db_cnt = 0; +static int legacy_db = 0; + +/* Determine if we have a valid geoip resource. + * + * If the geoip resource is NULL, 0 is returned. + * If the geoip resource is valid and malloc'd, 1 is returned. */ +int +is_geoip_resource (void) { + return ((geoips && db_cnt) || (legacy_db && geo_location_data)); +} + +/* Free up GeoIP resources */ +void +geoip_free (void) { + int idx = 0; + + if (!is_geoip_resource ()) + return; + + for (idx = 0; idx < db_cnt; idx++) + GeoIP_delete (geoips[idx]); + + if (legacy_db) + GeoIP_delete (geo_location_data); + + GeoIP_cleanup (); + free (geoips); + geoips = NULL; +} + +/* Open the given GeoLocation database and set its charset. + * + * On error, it aborts. + * On success, a new geolocation structure is returned. */ +static GeoIP * +geoip_open_db (const char *db) { + GeoIP *geoip = GeoIP_open (db, GEOIP_MEMORY_CACHE); + + if (geoip == NULL) + return NULL; + + GeoIP_set_charset (geoip, GEOIP_CHARSET_UTF8); + LOG_DEBUG (("Opened legacy GeoIP database: %s\n", db)); + + return geoip; +} + +static int +set_geoip_db_by_type (GeoIP *geoip, GO_GEOIP_DB type) { + unsigned char rec = GeoIP_database_edition (geoip); + + switch (rec) { + case GEOIP_ASNUM_EDITION: + if (type != TYPE_ASN) + break; + geo_location_data = geoip; + return 0; + case GEOIP_COUNTRY_EDITION: + case GEOIP_COUNTRY_EDITION_V6: + if (type != TYPE_COUNTRY && type != TYPE_CITY) + break; + geo_location_data = geoip; + return 0; + case GEOIP_CITY_EDITION_REV0: + case GEOIP_CITY_EDITION_REV1: + case GEOIP_CITY_EDITION_REV0_V6: + case GEOIP_CITY_EDITION_REV1_V6: + if (type != TYPE_CITY) + break; + geo_location_data = geoip; + return 0; + } + + return 1; +} + +static int +set_conf_by_type (GeoIP *geoip) { + unsigned char rec = GeoIP_database_edition (geoip); + + switch (rec) { + case GEOIP_ASNUM_EDITION: + conf.has_geoasn = 1; + return 0; + case GEOIP_COUNTRY_EDITION: + case GEOIP_COUNTRY_EDITION_V6: + conf.has_geocountry = 1; + return 0; + case GEOIP_CITY_EDITION_REV0: + case GEOIP_CITY_EDITION_REV1: + case GEOIP_CITY_EDITION_REV0_V6: + case GEOIP_CITY_EDITION_REV1_V6: + conf.has_geocountry = conf.has_geocity = 1; + return 0; + } + + return 1; +} + +/* Look up for a database on our array and set it as our current handlers. + * Note: this is not ideal, for now. However, legacy will go out of support at some point. + * + * On error or if no entry is found, 1 is returned. + * On success, GeoIP struct is set as our handler and 0 is returned. */ +static int +set_geoip_db (GO_GEOIP_DB type) { + int idx = 0; + + if (!is_geoip_resource ()) + return 1; + /* in memory legacy DB */ + if (legacy_db && geo_location_data) + return 0; + + for (idx = 0; idx < db_cnt; idx++) { + if (set_geoip_db_by_type (geoips[idx], type) == 0) + return 0; + } + + return 1; +} + +static void +set_geoip (const char *db) { + GeoIP **new_geoips = NULL, *geoip = NULL; + + if (db == NULL || *db == '\0') + return; + + if (!(geoip = geoip_open_db (db))) + FATAL ("Unable to open GeoIP database %s\n", db); + + db_cnt++; + + new_geoips = realloc (geoips, sizeof (*geoips) * db_cnt); + if (new_geoips == NULL) + FATAL ("Unable to realloc GeoIP database %s\n", db); + geoips = new_geoips; + geoips[db_cnt - 1] = geoip; + + set_conf_by_type (geoip); +} + +/* Set up and open GeoIP database */ +void +init_geoip (void) { + int i; + + for (i = 0; i < conf.geoip_db_idx; ++i) + set_geoip (conf.geoip_databases[i]); + + /* fall back to legacy GeoIP database */ + if (!conf.geoip_db_idx) { + geo_location_data = GeoIP_new (conf.geo_db); + legacy_db = 1; + } +} + +static char ip4to6_out_buffer[17]; +static char * +ip4to6 (const char *ipv4) { + unsigned int b[4]; + int n = sscanf (ipv4, "%u.%u.%u.%u", b, b + 1, b + 2, b + 3); + if (n == 4) { + snprintf (ip4to6_out_buffer, sizeof (ip4to6_out_buffer), "::ffff:%02x%02x:%02x%02x", b[0], + b[1], b[2], b[3]); + return ip4to6_out_buffer; + } + return NULL; +} + +/* Get continent name concatenated with code. + * + * If continent not found, "Unknown" is returned. + * On success, the continent code & name is returned . */ +static const char * +get_continent_name_and_code (const char *continentid) { + if (memcmp (continentid, "NA", 2) == 0) + return "NA North America"; + else if (memcmp (continentid, "OC", 2) == 0) + return "OC Oceania"; + else if (memcmp (continentid, "EU", 2) == 0) + return "EU Europe"; + else if (memcmp (continentid, "SA", 2) == 0) + return "SA South America"; + else if (memcmp (continentid, "AF", 2) == 0) + return "AF Africa"; + else if (memcmp (continentid, "AN", 2) == 0) + return "AN Antarctica"; + else if (memcmp (continentid, "AS", 2) == 0) + return "AS Asia"; + else + return "-- Unknown"; +} + +/* Compose a string with the country name and code and store it in the + * given buffer. */ +static void +geoip_set_country (const char *country, const char *code, char *loc) { + if (country && code) + snprintf (loc, COUNTRY_LEN, "%s %s", code, country); + else + snprintf (loc, COUNTRY_LEN, "%s", "Unknown"); +} + +/* Compose a string with the city name and state/region and store it + * in the given buffer. */ +static void +geoip_set_city (const char *city, const char *region, char *loc) { + snprintf (loc, CITY_LEN, "%s, %s", city ? city : "N/A City", region ? region : "N/A Region"); +} + +/* Compose a string with the continent name and store it in the given + * buffer. */ +static void +geoip_set_continent (const char *continent, char *loc) { + if (continent) + snprintf (loc, CONTINENT_LEN, "%s", get_continent_name_and_code (continent)); + else + snprintf (loc, CONTINENT_LEN, "%s", "Unknown"); +} + +/* Compose a string with the continent name and store it in the given + * buffer. */ +static void +geoip_set_asn (const char *name, char *asn) { + if (name) + snprintf (asn, ASN_LEN, "%s", name); + else + snprintf (asn, ASN_LEN, "%s", "Unknown"); +} + +/* Get detailed information found in the GeoIP Database about the + * given IPv4 or IPv6. + * + * On error, NULL is returned + * On success, GeoIPRecord structure is returned */ +static GeoIPRecord * +get_geoip_record (const char *addr, GTypeIP type_ip) { + GeoIPRecord *rec = NULL; + + if (TYPE_IPV4 == type_ip) + rec = GeoIP_record_by_name (geo_location_data, addr); + else if (TYPE_IPV6 == type_ip) + rec = GeoIP_record_by_name_v6 (geo_location_data, addr); + + return rec; +} + +/* Set country data by record into the given `location` buffer based + * on the IP version. */ +static void +geoip_set_country_by_record (const char *ip, char *location, GTypeIP type_ip) { + GeoIPRecord *rec = NULL; + const char *country = NULL, *code = NULL, *addr = ip; + + if (geo_location_data == NULL) + return; + + /* Custom GeoIP database */ + if ((rec = get_geoip_record (addr, type_ip))) { + country = rec->country_name; + code = rec->country_code; + } + + geoip_set_country (country, code, location); + if (rec != NULL) { + GeoIPRecord_delete (rec); + } +} + +/* Get the GeoIP location id by name. + * + * On error, 0 is returned + * On success, the GeoIP location id is returned */ +static int +geoip_get_geoid (const char *addr, GTypeIP type_ip) { + int geoid = 0; + + if (TYPE_IPV4 == type_ip) + geoid = GeoIP_id_by_name (geo_location_data, addr); + else if (TYPE_IPV6 == type_ip) + geoid = GeoIP_id_by_name_v6 (geo_location_data, addr); + + return geoid; +} + +/* Get the country name by GeoIP location id. + * + * On error, NULL is returned + * On success, the country name is returned */ +static const char * +geoip_get_country_by_geoid (const char *addr, GTypeIP type_ip) { + const char *country = NULL; + + if (TYPE_IPV4 == type_ip) + country = GeoIP_country_name_by_name (geo_location_data, addr); + else if (TYPE_IPV6 == type_ip) + country = GeoIP_country_name_by_name_v6 (geo_location_data, addr); + + return country; +} + +/* Set country data by geoid into the given `location` buffer based on + * the IP version. */ +static void +geoip_set_country_by_geoid (const char *ip, char *location, GTypeIP type_ip) { + const char *country = NULL, *code = NULL, *addr = ip; + int geoid = 0; + + if (!is_geoip_resource ()) + return; + + if (!(country = geoip_get_country_by_geoid (addr, type_ip))) + goto out; + + /* return two letter country code */ + if (!(geoid = geoip_get_geoid (addr, type_ip))) + goto out; + code = GeoIP_code_by_id (geoid); + +out: + geoip_set_country (country, code, location); +} + +/* Set continent data by record into the given `location` buffer based + * on the IP version. */ +static void +geoip_set_continent_by_record (const char *ip, char *location, GTypeIP type_ip) { + GeoIPRecord *rec = NULL; + const char *continent = NULL, *addr = ip; + + if (geo_location_data == NULL) + return; + + /* Custom GeoIP database */ + if ((rec = get_geoip_record (addr, type_ip))) + continent = rec->continent_code; + + geoip_set_continent (continent, location); + if (rec != NULL) { + GeoIPRecord_delete (rec); + } +} + +/* Set continent data by geoid into the given `location` buffer based + * on the IP version. */ +static void +geoip_set_continent_by_geoid (const char *ip, char *location, GTypeIP type_ip) { + const char *continent = NULL, *addr = ip; + int geoid = 0; + + if (!is_geoip_resource ()) + return; + + if (!(geoid = geoip_get_geoid (addr, type_ip))) + goto out; + continent = GeoIP_continent_by_id (geoid); + +out: + geoip_set_continent (continent, location); +} + +/* Set city data by record into the given `location` buffer based on + * the IP version. */ +static void +geoip_set_city_by_record (const char *ip, char *location, GTypeIP type_ip) { + GeoIPRecord *rec = NULL; + const char *city = NULL, *region = NULL, *addr = ip; + + /* Custom GeoIP database */ + if ((rec = get_geoip_record (addr, type_ip))) { + city = rec->city; + region = rec->region; + } + + geoip_set_city (city, region, location); + if (rec != NULL) { + GeoIPRecord_delete (rec); + } +} + +/* Set city data by geoid or record into the given `location` buffer + * based on the IP version and currently used database edition. + * It uses the custom GeoIP database - i.e., GeoLiteCity.dat */ +static void +geoip_get_city (const char *ip, char *location, GTypeIP type_ip) { + unsigned char rec = 0; + + if (geo_location_data == NULL) + return; + + rec = GeoIP_database_edition (geo_location_data); + switch (rec) { + case GEOIP_CITY_EDITION_REV0: + case GEOIP_CITY_EDITION_REV1: + if (TYPE_IPV4 == type_ip) + geoip_set_city_by_record (ip, location, TYPE_IPV4); + else + geoip_set_city (NULL, NULL, location); + break; + case GEOIP_CITY_EDITION_REV0_V6: + case GEOIP_CITY_EDITION_REV1_V6: + if (TYPE_IPV6 == type_ip) + geoip_set_city_by_record (ip, location, TYPE_IPV6); + else { + char *ipv6 = ip4to6 (ip); + if (ipv6) + geoip_set_city_by_record (ipv6, location, TYPE_IPV6); + else + geoip_set_city (NULL, NULL, location); + } + break; + } +} + +/* Set country data by geoid or record into the given `location` buffer + * based on the IP version and currently used database edition. */ +void +geoip_get_country (const char *ip, char *location, GTypeIP type_ip) { + unsigned char rec = 0; + + if (set_geoip_db (TYPE_COUNTRY) && set_geoip_db (TYPE_CITY)) { + geoip_set_country (NULL, NULL, location); + return; + } + + rec = GeoIP_database_edition (geo_location_data); + switch (rec) { + case GEOIP_COUNTRY_EDITION: + if (TYPE_IPV4 == type_ip) + geoip_set_country_by_geoid (ip, location, TYPE_IPV4); + else + geoip_set_country (NULL, NULL, location); + break; + case GEOIP_COUNTRY_EDITION_V6: + if (TYPE_IPV6 == type_ip) + geoip_set_country_by_geoid (ip, location, TYPE_IPV6); + else { + char *ipv6 = ip4to6 (ip); + if (ipv6) + geoip_set_country_by_geoid (ipv6, location, TYPE_IPV6); + else + geoip_set_country (NULL, NULL, location); + } + break; + case GEOIP_CITY_EDITION_REV0: + case GEOIP_CITY_EDITION_REV1: + if (TYPE_IPV4 == type_ip) + geoip_set_country_by_record (ip, location, TYPE_IPV4); + else + geoip_set_country (NULL, NULL, location); + break; + case GEOIP_CITY_EDITION_REV0_V6: + case GEOIP_CITY_EDITION_REV1_V6: + if (TYPE_IPV6 == type_ip) + geoip_set_country_by_record (ip, location, TYPE_IPV6); + else { + char *ipv6 = ip4to6 (ip); + if (ipv6) + geoip_set_country_by_record (ipv6, location, TYPE_IPV6); + else + geoip_set_country (NULL, NULL, location); + } + break; + } +} + +/* Set continent data by geoid or record into the given `location` buffer + * based on the IP version and currently used database edition. */ +void +geoip_get_continent (const char *ip, char *location, GTypeIP type_ip) { + unsigned char rec = 0; + + if (set_geoip_db (TYPE_COUNTRY) && set_geoip_db (TYPE_CITY)) { + geoip_set_continent (NULL, location); + return; + } + + rec = GeoIP_database_edition (geo_location_data); + switch (rec) { + case GEOIP_COUNTRY_EDITION: + if (TYPE_IPV4 == type_ip) + geoip_set_continent_by_geoid (ip, location, TYPE_IPV4); + else + geoip_set_continent (NULL, location); + break; + case GEOIP_COUNTRY_EDITION_V6: + if (TYPE_IPV6 == type_ip) + geoip_set_continent_by_geoid (ip, location, TYPE_IPV6); + else { + char *ipv6 = ip4to6 (ip); + if (ipv6) + geoip_set_continent_by_geoid (ipv6, location, TYPE_IPV6); + else + geoip_set_continent (NULL, location); + } + break; + case GEOIP_CITY_EDITION_REV0: + case GEOIP_CITY_EDITION_REV1: + if (TYPE_IPV4 == type_ip) + geoip_set_continent_by_record (ip, location, TYPE_IPV4); + else + geoip_set_continent (NULL, location); + break; + case GEOIP_CITY_EDITION_REV0_V6: + case GEOIP_CITY_EDITION_REV1_V6: + if (TYPE_IPV6 == type_ip) + geoip_set_continent_by_record (ip, location, TYPE_IPV6); + else { + char *ipv6 = ip4to6 (ip); + if (ipv6) + geoip_set_continent_by_record (ipv6, location, TYPE_IPV6); + else + geoip_set_continent (NULL, location); + } + break; + } +} + +void +geoip_asn (char *host, char *asn) { + char *name = NULL; + + if (legacy_db || set_geoip_db (TYPE_ASN)) { + geoip_set_asn (NULL, asn); + return; + } + + /* Custom GeoIP database */ + name = GeoIP_org_by_name (geo_location_data, (const char *) host); + geoip_set_asn (name, asn); + free (name); +} + +/* Entry point to set GeoIP location into the corresponding buffers, + * (continent, country, city). + * + * On error, 1 is returned + * On success, buffers are set and 0 is returned */ +int +set_geolocation (char *host, char *continent, char *country, char *city, GO_UNUSED char *asn) { + int type_ip = 0; + + if (!is_geoip_resource ()) + return 1; + + if (invalid_ipaddr (host, &type_ip)) + return 1; + + /* set ASN data */ + geoip_asn (host, asn); + + /* set Country/City data */ + if (set_geoip_db (TYPE_COUNTRY) == 0 || set_geoip_db (TYPE_CITY) == 0) { + geoip_get_country (host, country, type_ip); + geoip_get_continent (host, continent, type_ip); + } + if (set_geoip_db (TYPE_CITY) == 0) + geoip_get_city (host, city, type_ip); + + return 0; +} diff --git a/src/geoip1.h b/src/geoip1.h new file mode 100644 index 0000000000..38e3e4a13d --- /dev/null +++ b/src/geoip1.h @@ -0,0 +1,65 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#ifndef GEOIP_H_INCLUDED +#define GEOIP_H_INCLUDED + +#include "commons.h" + +#define CITY_LEN 47 + 1 /* max string length for a city */ +#define CONTINENT_LEN 47 + 1 /* max string length for a country */ +#define COUNTRY_LEN 48 + 3 /* Country + two-letter Code */ +#define ASN_LEN 64 + 6 /* ASN + 5 digit/16-bit number/code */ + +/* Type of IP */ +typedef enum { + TYPE_COUNTRY, + TYPE_CITY, + TYPE_ASN +} GO_GEOIP_DB; + +typedef struct GLocation_ { + char city[CITY_LEN]; + char continent[CONTINENT_LEN]; + int hits; +} GLocation; + +int is_geoip_resource (void); +int set_geolocation (char *host, char *continent, char *country, char *city, char *asn); +void geoip_asn (char *host, char *asn); +void geoip_free (void); +void geoip_get_continent (const char *ip, char *location, GTypeIP type_ip); +void geoip_get_country (const char *ip, char *location, GTypeIP type_ip); +void init_geoip (void); + +#endif // for #ifndef GEOIP_H diff --git a/src/geoip2.c b/src/geoip2.c new file mode 100644 index 0000000000..98aee70250 --- /dev/null +++ b/src/geoip2.c @@ -0,0 +1,404 @@ +/** + * geoip2.c -- implementation of GeoIP2 + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2020 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#ifdef HAVE_LIBMAXMINDDB +#include +#endif + +#include "geoip1.h" + +#include "error.h" +#include "labels.h" +#include "util.h" +#include "xmalloc.h" + +/* should be reused across lookups */ +static int geoip_asn_type = 0; +static int geoip_city_type = 0; +static int geoip_country_type = 0; +static int mmdb_cnt = 0; +static MMDB_s *mmdbs = NULL; + +/* Determine if we have a valid geoip resource. + * + * If the geoip resource is NULL, 0 is returned. + * If the geoip resource is valid and malloc'd, 1 is returned. */ +int +is_geoip_resource (void) { + return mmdbs && mmdb_cnt; +} + +/* Free up GeoIP resources */ +void +geoip_free (void) { + int idx = 0; + if (!is_geoip_resource ()) + return; + + for (idx = 0; idx < mmdb_cnt; idx++) + MMDB_close (&mmdbs[idx]); + free (mmdbs); + mmdbs = NULL; +} + +static void +set_geoip (const char *db) { + int status = 0; + MMDB_s *new_mmdbs = NULL, mmdb; + + if (db == NULL || *db == '\0') + return; + + if ((status = MMDB_open (db, MMDB_MODE_MMAP, &mmdb)) != MMDB_SUCCESS) + FATAL ("Unable to open GeoIP2 database %s: %s\n", db, MMDB_strerror (status)); + + mmdb_cnt++; + + new_mmdbs = realloc (mmdbs, sizeof (*mmdbs) * mmdb_cnt); + if (new_mmdbs == NULL) + FATAL ("Unable to realloc GeoIP2 database %s\n", db); + mmdbs = new_mmdbs; + mmdbs[mmdb_cnt - 1] = mmdb; + + if (strstr (mmdb.metadata.database_type, "-City") != NULL) + conf.has_geocountry = conf.has_geocity = geoip_country_type = geoip_city_type = 1; + if (strstr (mmdb.metadata.database_type, "-ASN") != NULL) + conf.has_geoasn = geoip_asn_type = 1; + if (strstr (mmdb.metadata.database_type, "-Country") != NULL) + conf.has_geocountry = geoip_country_type = 1; +} + +/* Open the given GeoIP2 database. + * + * On error, it aborts. + * On success, a new geolocation structure is set. */ +void +init_geoip (void) { + int i; + + for (i = 0; i < conf.geoip_db_idx; ++i) + set_geoip (conf.geoip_databases[i]); +} + +/* Look up an IP address that is passed in as a null-terminated string. + * + * On error, it aborts. + * If no entry is found, 1 is returned. + * On success, MMDB_lookup_result_s struct is set and 0 is returned. */ +static int +geoip_lookup (MMDB_lookup_result_s *res, const char *ip, int is_asn) { + int gai_err, mmdb_err, idx = 0; + MMDB_s *mmdb = NULL; + + for (idx = 0; idx < mmdb_cnt; idx++) { + if (is_asn && (!strstr (mmdbs[idx].metadata.database_type, "ASN"))) + continue; + if (!is_asn && (strstr (mmdbs[idx].metadata.database_type, "ASN"))) + continue; + + mmdb = &mmdbs[idx]; + + *res = MMDB_lookup_string (mmdb, ip, &gai_err, &mmdb_err); + if (0 != gai_err) + return 1; + if (MMDB_SUCCESS != mmdb_err) + FATAL ("Error from libmaxminddb: %s\n", MMDB_strerror (mmdb_err)); + if (!(*res).found_entry) + return 1; + break; + } + + return 0; +} + +/* Get continent name concatenated with code. + * + * If continent not found, "Unknown" is returned. + * On success, the continent code & name is returned . */ +static const char * +get_continent_name_and_code (const char *continentid) { + if (memcmp (continentid, "NA", 2) == 0) + return "NA North America"; + else if (memcmp (continentid, "OC", 2) == 0) + return "OC Oceania"; + else if (memcmp (continentid, "EU", 2) == 0) + return "EU Europe"; + else if (memcmp (continentid, "SA", 2) == 0) + return "SA South America"; + else if (memcmp (continentid, "AF", 2) == 0) + return "AF Africa"; + else if (memcmp (continentid, "AN", 2) == 0) + return "AN Antarctica"; + else if (memcmp (continentid, "AS", 2) == 0) + return "AS Asia"; + else + return "-- Unknown"; +} + +/* Compose a string with the country name and code and store it in the + * given buffer. */ +static void +geoip_set_country (const char *country, const char *code, char *loc) { + if (country && code) + snprintf (loc, COUNTRY_LEN, "%s %s", code, country); + else + snprintf (loc, COUNTRY_LEN, "%s", "Unknown"); +} + +/* Compose a string with the ASN name and code and store it in the + * given buffer. */ +static void +geoip_set_asn (MMDB_entry_data_s name, MMDB_entry_data_s code, char *asn, int status) { + if (status == 0) + snprintf (asn, ASN_LEN, "%05u: %.*s", code.uint32, name.data_size, name.utf8_string); + else + snprintf (asn, ASN_LEN, "%s", "00000: Unknown"); +} + +/* Compose a string with the city name and state/region and store it + * in the given buffer. */ +static void +geoip_set_city (const char *city, const char *region, char *loc) { + snprintf (loc, CITY_LEN, "%s, %s", city ? city : "N/A City", region ? region : "N/A Region"); +} + +/* Compose a string with the continent name and store it in the given + * buffer. */ +static void +geoip_set_continent (const char *continent, char *loc) { + if (continent) + snprintf (loc, CONTINENT_LEN, "%s", get_continent_name_and_code (continent)); + else + snprintf (loc, CONTINENT_LEN, "%s", "Unknown"); +} + +/* A wrapper to fetch the looked up result set. + * + * On error, it aborts. + * If no data is found, NULL is returned. + * On success, the fetched value is returned. */ +static char * +get_value (MMDB_lookup_result_s res, ...) { + MMDB_entry_data_s entry_data; + char *value = NULL; + int status = 0; + va_list keys; + va_start (keys, res); + + status = MMDB_vget_value (&res.entry, &entry_data, keys); + va_end (keys); + + if (status != MMDB_SUCCESS) + return NULL; + + if (!entry_data.has_data) + return NULL; + + if (entry_data.type != MMDB_DATA_TYPE_UTF8_STRING) + FATAL ("Invalid data UTF8 GeoIP2 data %d:\n", entry_data.type); + + if ((value = strndup (entry_data.utf8_string, entry_data.data_size)) == NULL) + FATAL ("Unable to allocate buffer %s: ", strerror (errno)); + + return value; +} + +/* A wrapper to fetch the looked up result and set the city and region. + * + * If no data is found, NULL is set. + * On success, the fetched value is set. */ +static void +geoip_query_city (MMDB_lookup_result_s res, char *location) { + char *city = NULL, *region = NULL; + + if (res.found_entry) { + city = get_value (res, "city", "names", DOC_LANG, NULL); + region = get_value (res, "subdivisions", "0", "names", DOC_LANG, NULL); + if (!city) { + city = get_value (res, "city", "names", "en", NULL); + } + if (!region) { + region = get_value (res, "subdivisions", "0", "names", "en", NULL); + } + } + geoip_set_city (city, region, location); + free (city); + free (region); +} + +/* A wrapper to fetch the looked up result and set the country and code. + * + * If no data is found, NULL is set. + * On success, the fetched value is set. */ +static void +geoip_query_country (MMDB_lookup_result_s res, char *location) { + char *country = NULL, *code = NULL; + + if (res.found_entry) { + country = get_value (res, "country", "names", DOC_LANG, NULL); + code = get_value (res, "country", "iso_code", NULL); + if (!country) { + country = get_value (res, "country", "names", "en", NULL); + } + } + geoip_set_country (country, code, location); + free (code); + free (country); +} + +/* Sets the value for the given array of strings as the lookup path. + * + * On error or not found, 1 is returned. + * On success, 0 is returned and the entry data is set. */ +static int +geoip_query_asn_code (MMDB_lookup_result_s res, MMDB_entry_data_s *code) { + int status; + const char *key[] = { "autonomous_system_number", NULL }; + + if (res.found_entry) { + status = MMDB_aget_value (&res.entry, code, key); + if (status != MMDB_SUCCESS || !code->has_data) + return 1; + } + + return 0; +} + +/* Sets the value for the given array of strings as the lookup path. + * + * On error or not found, 1 is returned. + * On success, 0 is returned and the entry data is set. */ +static int +geoip_query_asn_name (MMDB_lookup_result_s res, MMDB_entry_data_s *name) { + int status; + const char *key[] = { "autonomous_system_organization", NULL }; + + if (res.found_entry) { + status = MMDB_aget_value (&res.entry, name, key); + if (status != MMDB_SUCCESS || !name->has_data) + return 1; + } + + return 0; +} + +/* A wrapper to fetch the looked up result and set the ASN organization & code. + * + * If no data is found, "Unknown" is set. + * On success, the fetched value is set. */ +void +geoip_asn (char *host, char *asn) { + MMDB_lookup_result_s res = { 0 }; + MMDB_entry_data_s name = { 0 }; + MMDB_entry_data_s code = { 0 }; + int status = 1; + + geoip_lookup (&res, host, 1); + + if (!res.found_entry) + goto out; + if ((status &= geoip_query_asn_name (res, &name))) + goto out; + if ((status |= geoip_query_asn_code (res, &code))) + goto out; + +out: + geoip_set_asn (name, code, asn, status); +} + +/* A wrapper to fetch the looked up result and set the continent code. + * + * If no data is found, NULL is set. + * On success, the fetched value is set. */ +static void +geoip_query_continent (MMDB_lookup_result_s res, char *location) { + char *code = NULL; + + if (res.found_entry) + code = get_value (res, "continent", "code", NULL); + geoip_set_continent (code, location); + free (code); +} + +/* Set country data by record into the given `location` buffer */ +void +geoip_get_country (const char *ip, char *location, GO_UNUSED GTypeIP type_ip) { + MMDB_lookup_result_s res = { 0 }; + + geoip_lookup (&res, ip, 0); + geoip_query_country (res, location); +} + +/* A wrapper to fetch the looked up result and set the continent. */ +void +geoip_get_continent (const char *ip, char *location, GO_UNUSED GTypeIP type_ip) { + MMDB_lookup_result_s res = { 0 }; + + geoip_lookup (&res, ip, 0); + geoip_query_continent (res, location); +} + +/* Entry point to set GeoIP location into the corresponding buffers, + * (continent, country, city). + * + * On error, 1 is returned + * On success, buffers are set and 0 is returned */ +int +set_geolocation (char *host, char *continent, char *country, char *city, char *asn) { + MMDB_lookup_result_s res = { 0 }; + + if (!is_geoip_resource ()) + return 1; + + /* set ASN data */ + if (geoip_asn_type) + geoip_asn (host, asn); + + if (!geoip_city_type && !geoip_country_type) + return 0; + + /* set Country/City data */ + geoip_lookup (&res, host, 0); + geoip_query_country (res, country); + geoip_query_continent (res, continent); + + if (geoip_city_type) + geoip_query_city (res, city); + + return 0; +} diff --git a/src/gholder.c b/src/gholder.c new file mode 100644 index 0000000000..856e25b302 --- /dev/null +++ b/src/gholder.c @@ -0,0 +1,684 @@ +/** + * gholder.c -- data structure to hold raw data + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include + +#include "gholder.h" + +#include "error.h" +#include "gdns.h" +#include "gkhash.h" +#include "util.h" +#include "xmalloc.h" + +#ifdef HAVE_GEOLOCATION +#include "geoip1.h" +#endif + +typedef struct GPanel_ { + GModule module; + void (*insert) (GRawDataItem item, GHolder * h, datatype type, const struct GPanel_ *); + void (*holder_callback) (GHolder * h); +} GPanel; + + +/* *INDENT-OFF* */ +static void add_data_to_holder (GRawDataItem item, GHolder * h, datatype type, const GPanel * panel); +static void add_host_to_holder (GRawDataItem item, GHolder * h, datatype type, const GPanel * panel); +static void add_root_to_holder (GRawDataItem item, GHolder * h, datatype type, const GPanel * panel); +static void add_host_child_to_holder (GHolder * h); + +static const GPanel paneling[] = { + {VISITORS , add_data_to_holder , NULL}, + {REQUESTS , add_data_to_holder , NULL}, + {REQUESTS_STATIC , add_data_to_holder , NULL}, + {NOT_FOUND , add_data_to_holder , NULL}, + {HOSTS , add_host_to_holder , add_host_child_to_holder} , + {OS , add_root_to_holder , NULL}, + {BROWSERS , add_root_to_holder , NULL}, + {VISIT_TIMES , add_data_to_holder , NULL}, + {VIRTUAL_HOSTS , add_data_to_holder , NULL}, + {REFERRERS , add_data_to_holder , NULL}, + {REFERRING_SITES , add_data_to_holder , NULL}, + {KEYPHRASES , add_data_to_holder , NULL}, + {STATUS_CODES , add_root_to_holder , NULL}, + {REMOTE_USER , add_data_to_holder , NULL}, + {CACHE_STATUS , add_data_to_holder , NULL}, +#ifdef HAVE_GEOLOCATION + {GEO_LOCATION , add_root_to_holder , NULL}, + {ASN , add_data_to_holder , NULL} , +#endif + {MIME_TYPE , add_root_to_holder , NULL} , + {TLS_TYPE , add_root_to_holder , NULL} , +}; +/* *INDENT-ON* */ + + +/* Get a panel from the GPanel structure given a module. + * + * On error, or if not found, NULL is returned. + * On success, the panel value is returned. */ +static const GPanel * +panel_lookup (GModule module) { + int i, num_panels = ARRAY_SIZE (paneling); + + for (i = 0; i < num_panels; i++) { + if (paneling[i].module == module) + return &paneling[i]; + } + return NULL; +} + +/* Allocate memory for a new GHolder instance. + * + * On success, the newly allocated GHolder is returned . */ +GHolder * +new_gholder (uint32_t size) { + GHolder *holder = xmalloc (size * sizeof (GHolder)); + memset (holder, 0, size * sizeof *holder); + + return holder; +} + +/* Allocate memory for a new GHolderItem instance. + * + * On success, the newly allocated GHolderItem is returned . */ +static GHolderItem * +new_gholder_item (uint32_t size) { + GHolderItem *item = xcalloc (size, sizeof (GHolderItem)); + + return item; +} + +/* Allocate memory for a new double linked-list GSubList instance. + * + * On success, the newly allocated GSubList is returned . */ +static GSubList * +new_gsublist (void) { + GSubList *sub_list = xmalloc (sizeof (GSubList)); + sub_list->head = NULL; + sub_list->tail = NULL; + sub_list->size = 0; + + return sub_list; +} + +/* Allocate memory for a new double linked-list GSubItem node. + * + * On success, the newly allocated GSubItem is returned . */ +static GSubItem * +new_gsubitem (GModule module, GMetrics *nmetrics) { + GSubItem *sub_item = xmalloc (sizeof (GSubItem)); + + sub_item->metrics = nmetrics; + sub_item->module = module; + sub_item->prev = NULL; + sub_item->next = NULL; + + return sub_item; +} + +/* Add an item to the end of a given sub list. */ +static void +add_sub_item_back (GSubList *sub_list, GModule module, GMetrics *nmetrics) { + GSubItem *sub_item = new_gsubitem (module, nmetrics); + if (sub_list->tail) { + sub_list->tail->next = sub_item; + sub_item->prev = sub_list->tail; + sub_list->tail = sub_item; + } else { + sub_list->head = sub_item; + sub_list->tail = sub_item; + } + sub_list->size++; +} + +/* Delete the entire given sub list. */ +static void +delete_sub_list (GSubList *sub_list) { + GSubItem *item = NULL; + GSubItem *next = NULL; + + if (sub_list->size == 0) + goto clear; + + for (item = sub_list->head; item; item = next) { + next = item->next; + free (item->metrics->data); + free (item->metrics); + free (item); + } +clear: + sub_list->head = NULL; + sub_list->size = 0; + free (sub_list); +} + +/* Free malloc'd holder fields. */ +static void +free_holder_data (GHolderItem item) { + if (item.sub_list != NULL) + delete_sub_list (item.sub_list); + free_gmetrics (item.metrics); +} + +/* Free all memory allocated in holder for a given module. */ +void +free_holder_by_module (GHolder **holder, GModule module) { + int j; + + if ((*holder) == NULL) + return; + + for (j = 0; j < (*holder)[module].idx; j++) { + free_holder_data ((*holder)[module].items[j]); + } + free ((*holder)[module].items); + + (*holder)[module].holder_size = 0; + (*holder)[module].idx = 0; + (*holder)[module].sub_items_size = 0; +} + +/* Free all memory allocated in holder for all modules. */ +void +free_holder (GHolder **holder) { + GModule module; + int j; + size_t idx = 0; + + if ((*holder) == NULL) + return; + + FOREACH_MODULE (idx, module_list) { + module = module_list[idx]; + + for (j = 0; j < (*holder)[module].idx; j++) { + free_holder_data ((*holder)[module].items[j]); + } + free ((*holder)[module].items); + } + free (*holder); + (*holder) = NULL; +} + +/* Iterate over holder and get the key index. + * + * If the key does not exist, -1 is returned. + * On success, the key in holder is returned . */ +static int +get_item_idx_in_holder (GHolder *holder, const char *k) { + int i; + if (holder == NULL) + return KEY_NOT_FOUND; + if (holder->idx == 0) + return KEY_NOT_FOUND; + if (k == NULL || *k == '\0') + return KEY_NOT_FOUND; + + for (i = 0; i < holder->idx; i++) { + if (strcmp (k, holder->items[i].metrics->data) == 0) + return i; + } + + return KEY_NOT_FOUND; +} + +/* Copy linked-list items to an array, sort, and move them back to the + * list. Should be faster than sorting the list */ +static void +sort_sub_list (GHolder *h, GSort sort) { + GHolderItem *arr; + GSubItem *iter; + GSubList *sub_list; + int i, j, k; + + /* iterate over root-level nodes */ + for (i = 0; i < h->idx; i++) { + sub_list = h->items[i].sub_list; + if (sub_list == NULL) + continue; + + arr = new_gholder_item (sub_list->size); + + /* copy items from the linked-list into an array */ + for (j = 0, iter = sub_list->head; iter; iter = iter->next, j++) { + arr[j].metrics = new_gmetrics (); + + arr[j].metrics->bw.nbw = iter->metrics->bw.nbw; + arr[j].metrics->data = xstrdup (iter->metrics->data); + arr[j].metrics->hits = iter->metrics->hits; + arr[j].metrics->id = iter->metrics->id; + arr[j].metrics->visitors = iter->metrics->visitors; + if (conf.serve_usecs) { + arr[j].metrics->avgts.nts = iter->metrics->avgts.nts; + arr[j].metrics->cumts.nts = iter->metrics->cumts.nts; + arr[j].metrics->maxts.nts = iter->metrics->maxts.nts; + } + } + sort_holder_items (arr, j, sort); + delete_sub_list (sub_list); + + sub_list = new_gsublist (); + for (k = 0; k < j; k++) { + if (k > 0) + sub_list = h->items[i].sub_list; + + add_sub_item_back (sub_list, h->module, arr[k].metrics); + h->items[i].sub_list = sub_list; + sub_list = NULL; + } + + free (arr); + if (sub_list) { + delete_sub_list (sub_list); + sub_list = NULL; + } + } +} + +/* Set the data metric field for the host panel. + * + * On success, the data field/metric is set. */ +static int +set_host_child_metrics (char *data, uint8_t id, GMetrics **nmetrics) { + GMetrics *metrics; + + metrics = new_gmetrics (); + metrics->data = xstrdup (data); + metrics->id = id; + *nmetrics = metrics; + + return 0; +} + +/* Set host panel data, including sub items. + * + * On success, the host panel data is set. */ +static void +set_host_sub_list (GHolder *h, GSubList *sub_list) { + GMetrics *nmetrics; +#ifdef HAVE_GEOLOCATION + char city[CITY_LEN] = ""; + char continent[CONTINENT_LEN] = ""; + char country[ASN_LEN] = ""; + char asn[ASN_LEN] = ""; +#endif + + char *host = h->items[h->idx].metrics->data, *hostname = NULL; +#ifdef HAVE_GEOLOCATION + /* add geolocation child nodes */ + set_geolocation (host, continent, country, city, asn); + + /* country */ + if (country[0] != '\0') { + set_host_child_metrics (country, MTRC_ID_COUNTRY, &nmetrics); + add_sub_item_back (sub_list, h->module, nmetrics); + h->items[h->idx].sub_list = sub_list; + h->sub_items_size++; + + /* flag only */ + conf.has_geocountry = 1; + } + + /* city */ + if (city[0] != '\0') { + set_host_child_metrics (city, MTRC_ID_CITY, &nmetrics); + add_sub_item_back (sub_list, h->module, nmetrics); + h->items[h->idx].sub_list = sub_list; + h->sub_items_size++; + + /* flag only */ + conf.has_geocity = 1; + } + + /* ASN */ + if (asn[0] != '\0') { + set_host_child_metrics (asn, MTRC_ID_ASN, &nmetrics); + add_sub_item_back (sub_list, h->module, nmetrics); + h->items[h->idx].sub_list = sub_list; + h->sub_items_size++; + + /* flag only */ + conf.has_geoasn = 1; + } +#endif + + /* hostname */ + if (conf.enable_html_resolver && conf.output_stdout && !conf.no_ip_validation && + !conf.real_time_html) { + hostname = reverse_ip (host); + set_host_child_metrics (hostname, MTRC_ID_HOSTNAME, &nmetrics); + add_sub_item_back (sub_list, h->module, nmetrics); + h->items[h->idx].sub_list = sub_list; + h->sub_items_size++; + free (hostname); + } +} + +/* Set host panel data, including sub items. + * + * On success, the host panel data is set. */ +static void +add_host_child_to_holder (GHolder *h) { + GMetrics *nmetrics; + GSubList *sub_list = new_gsublist (); + + char *ip = h->items[h->idx].metrics->data; + char *hostname = NULL; + int n = h->sub_items_size; + + /* add child nodes */ + set_host_sub_list (h, sub_list); + + pthread_mutex_lock (&gdns_thread.mutex); + hostname = ht_get_hostname (ip); + pthread_mutex_unlock (&gdns_thread.mutex); + + /* determine if we have the IP's hostname */ + if (!hostname) { + dns_resolver (ip); + } else if (hostname) { + set_host_child_metrics (hostname, MTRC_ID_HOSTNAME, &nmetrics); + add_sub_item_back (sub_list, h->module, nmetrics); + h->items[h->idx].sub_list = sub_list; + h->sub_items_size++; + free (hostname); + } + + /* did not add any items */ + if (n == h->sub_items_size) + free (sub_list); +} + +/* Given a GRawDataType, set the data and hits value. + * + * On error, no values are set and 1 is returned. + * On success, the data and hits values are set and 0 is returned. */ +static int +map_data (GModule module, GRawDataItem item, datatype type, char **data, uint32_t *hits) { + switch (type) { + case U32: + if (!(*data = ht_get_datamap (module, item.nkey))) + return 1; + if (!item.hits) + return 1; + *hits = item.hits; + break; + case STR: + if (!(*hits = ht_get_hits (module, item.nkey))) + return 1; + *data = xstrdup (item.data); + break; + } + return 0; +} + +/* Given a data item, store it into a holder structure. */ +static void +set_single_metrics (GRawDataItem item, GHolder *h, char *data, uint32_t hits) { + uint32_t visitors = 0; + uint64_t bw = 0, cumts = 0, maxts = 0; + + bw = ht_get_bw (h->module, item.nkey); + cumts = ht_get_cumts (h->module, item.nkey); + maxts = ht_get_maxts (h->module, item.nkey); + visitors = ht_get_visitors (h->module, item.nkey); + + h->items[h->idx].metrics = new_gmetrics (); + h->items[h->idx].metrics->hits = hits; + h->items[h->idx].metrics->data = data; + h->items[h->idx].metrics->visitors = visitors; + h->items[h->idx].metrics->bw.nbw = bw; + h->items[h->idx].metrics->avgts.nts = cumts / hits; + h->items[h->idx].metrics->cumts.nts = cumts; + h->items[h->idx].metrics->maxts.nts = maxts; + + if (bw && !conf.bandwidth) + conf.bandwidth = 1; + if (cumts && !conf.serve_usecs) + conf.serve_usecs = 1; + + if (conf.append_method) { + h->items[h->idx].metrics->method = ht_get_method (h->module, item.nkey); + } + + if (conf.append_protocol) { + h->items[h->idx].metrics->protocol = ht_get_protocol (h->module, item.nkey); + } +} + +/* Set all panel data. This will set data for panels that do not + * contain sub items. A function pointer is used for post data set. */ +static void +add_data_to_holder (GRawDataItem item, GHolder *h, datatype type, const GPanel *panel) { + char *data = NULL; + uint32_t hits = 0; + + if (map_data (h->module, item, type, &data, &hits) == 1) + return; + + set_single_metrics (item, h, data, hits); + if (panel->holder_callback) + panel->holder_callback (h); + + h->idx++; +} + +/* A wrapper to set a host item */ +static void +set_host (GRawDataItem item, GHolder *h, const GPanel *panel, char *data, uint32_t hits) { + set_single_metrics (item, h, xstrdup (data), hits); + if (panel->holder_callback) + panel->holder_callback (h); + h->idx++; +} + +/* Set all panel data. This will set data for panels that do not + * contain sub items. A function pointer is used for post data set. */ +static void +add_host_to_holder (GRawDataItem item, GHolder *h, datatype type, const GPanel *panel) { + char buf4[INET_ADDRSTRLEN]; + char buf6[INET6_ADDRSTRLEN]; + char *data = NULL; + uint32_t hits = 0; + unsigned i; + + struct in6_addr addr6, mask6, nwork6; + struct in_addr addr4, mask4, nwork4; + + const char *arr4[] = { "255.255.255.0", "255.255.0.0", "255.0.0.0" }; + const char *arr6[] = { + "ffff:ffff:ffff:ffff:0000:0000:0000:0000", + "ffff:ffff:ffff:0000:0000:0000:0000:0000", + "ffff:ffff:0000:0000:0000:0000:0000:0000" + }; + + const char *m4 = arr4[0]; + const char *m6 = arr6[0]; + + if (map_data (h->module, item, type, &data, &hits) == 1) + return; + + if (!conf.anonymize_ip) { + add_data_to_holder (item, h, type, panel); + free (data); + return; + } + + if (conf.anonymize_level == ANONYMIZE_STRONG || conf.anonymize_level == ANONYMIZE_PEDANTIC) { + m4 = arr4[conf.anonymize_level - 1]; + m6 = arr6[conf.anonymize_level - 1]; + } + + if (1 == inet_pton (AF_INET, data, &addr4)) { + if (1 == inet_pton (AF_INET, m4, &mask4)) { + memset (buf4, 0, sizeof *buf4); + nwork4.s_addr = addr4.s_addr & mask4.s_addr; + + if (inet_ntop (AF_INET, &nwork4, buf4, INET_ADDRSTRLEN) != NULL) { + set_host (item, h, panel, buf4, hits); + free (data); + } + } + } else if (1 == inet_pton (AF_INET6, data, &addr6)) { + if (1 == inet_pton (AF_INET6, m6, &mask6)) { + memset (buf6, 0, sizeof *buf6); + for (i = 0; i < 16; i++) { + nwork6.s6_addr[i] = addr6.s6_addr[i] & mask6.s6_addr[i]; + } + + if (inet_ntop (AF_INET6, &nwork6, buf6, INET6_ADDRSTRLEN) != NULL) { + set_host (item, h, panel, buf6, hits); + free (data); + } + } + } +} + +/* Set all root panel data. This will set the root nodes. */ +static int +set_root_metrics (GRawDataItem item, GModule module, datatype type, GMetrics **nmetrics) { + GMetrics *metrics; + char *data = NULL; + uint64_t bw = 0, cumts = 0, maxts = 0; + uint32_t hits = 0, visitors = 0; + + if (map_data (module, item, type, &data, &hits) == 1) + return 1; + + bw = ht_get_bw (module, item.nkey); + cumts = ht_get_cumts (module, item.nkey); + maxts = ht_get_maxts (module, item.nkey); + visitors = ht_get_visitors (module, item.nkey); + + metrics = new_gmetrics (); + metrics->avgts.nts = cumts / hits; + metrics->cumts.nts = cumts; + metrics->maxts.nts = maxts; + metrics->bw.nbw = bw; + metrics->data = data; + metrics->hits = hits; + metrics->visitors = visitors; + *nmetrics = metrics; + + return 0; +} + +/* Set all root panel data, including sub list items. */ +static void +add_root_to_holder (GRawDataItem item, GHolder *h, datatype type, GO_UNUSED const GPanel *panel) { + GSubList *sub_list; + GMetrics *metrics, *nmetrics; + char *root = NULL; + int root_idx = KEY_NOT_FOUND, idx = 0; + + if (set_root_metrics (item, h->module, type, &nmetrics) == 1) + return; + + if (!(root = ht_get_root (h->module, item.nkey))) { + free_gmetrics (nmetrics); + return; + } + + /* add data as a child node into holder */ + if (KEY_NOT_FOUND == (root_idx = get_item_idx_in_holder (h, root))) { + idx = h->idx; + sub_list = new_gsublist (); + metrics = new_gmetrics (); + + h->items[idx].metrics = metrics; + h->items[idx].metrics->data = root; + h->idx++; + } else { + sub_list = h->items[root_idx].sub_list; + metrics = h->items[root_idx].metrics; + + idx = root_idx; + free (root); + } + + add_sub_item_back (sub_list, h->module, nmetrics); + h->items[idx].sub_list = sub_list; + + h->items[idx].metrics = metrics; + h->items[idx].metrics->cumts.nts += nmetrics->cumts.nts; + h->items[idx].metrics->bw.nbw += nmetrics->bw.nbw; + h->items[idx].metrics->hits += nmetrics->hits; + h->items[idx].metrics->visitors += nmetrics->visitors; + h->items[idx].metrics->avgts.nts = h->items[idx].metrics->cumts.nts / h->items[idx].metrics->hits; + + if (nmetrics->maxts.nts > h->items[idx].metrics->maxts.nts) + h->items[idx].metrics->maxts.nts = nmetrics->maxts.nts; + + h->sub_items_size++; +} + +/* Load raw data into our holder structure */ +void +load_holder_data (GRawData *raw_data, GHolder *h, GModule module, GSort sort) { + int i; + uint32_t size = 0, max_choices = get_max_choices (); + const GPanel *panel = panel_lookup (module); + +#ifdef _DEBUG + clock_t begin = clock (); + double taken; + const char *modstr = NULL; + LOG_DEBUG (("== load_holder_data ==\n")); +#endif + + size = raw_data->size; + h->holder_size = size > max_choices ? max_choices : size; + h->ht_size = size; + h->idx = 0; + h->module = module; + h->sub_items_size = 0; + h->items = new_gholder_item (h->holder_size); + + for (i = 0; i < h->holder_size; i++) { + panel->insert (raw_data->items[i], h, raw_data->type, panel); + } + sort_holder_items (h->items, h->idx, sort); + if (h->sub_items_size) + sort_sub_list (h, sort); + free_raw_data (raw_data); + +#ifdef _DEBUG + modstr = get_module_str (module); + taken = (double) (clock () - begin) / CLOCKS_PER_SEC; + LOG_DEBUG (("== %-30s%f\n\n", modstr, taken)); +#endif +} diff --git a/src/gholder.h b/src/gholder.h new file mode 100644 index 0000000000..7616e61feb --- /dev/null +++ b/src/gholder.h @@ -0,0 +1,57 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef GHOLDER_H_INCLUDED +#define GHOLDER_H_INCLUDED + +#define MTRC_ID_COUNTRY 0 +#define MTRC_ID_CITY 1 +#define MTRC_ID_ASN 2 +#define MTRC_ID_HOSTNAME 3 + +#include "commons.h" +#include "sort.h" + +/* Default Anonymization Levels */ +typedef enum GAnonymizeLevels_ { + ANONYMIZE_DEFAULT = 1, + ANONYMIZE_STRONG, + ANONYMIZE_PEDANTIC, +} GAnonymizeLevels; + +/* Function Prototypes */ +GHolder *new_gholder (uint32_t size); +void *add_hostname_node (void *ptr_holder); +void free_holder_by_module (GHolder ** holder, GModule module); +void free_holder (GHolder ** holder); +void load_holder_data (GRawData * raw_data, GHolder * h, GModule module, GSort sort); +void load_host_to_holder (GHolder * h, char *ip); +int dup_key_list (void *val, GSLList ** user_data); + +#endif // for #ifndef GHOLDER_H diff --git a/src/gkhash.c b/src/gkhash.c new file mode 100644 index 0000000000..0fb17b5218 --- /dev/null +++ b/src/gkhash.c @@ -0,0 +1,1653 @@ +/** + * gkhash.c -- default hash table functions + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include "gkhash.h" + +#include "error.h" +#include "persistence.h" +#include "sort.h" +#include "util.h" +#include "xmalloc.h" + +/* *INDENT-OFF* */ +/* Hash table that holds DB instances */ +static khash_t (igdb) * ht_db = NULL; +/* *INDENT-ON* */ + +/* Allocate memory for a new global GKHashDB instance. + * + * On success, the newly allocated GKHashDB is returned . */ +static GKHashDB * +new_gkhdb (void) { + GKHashDB *storage = xcalloc (1, sizeof (GKHashDB)); + return storage; +} + +/* Allocate memory for a new GKDB instance. + * + * On success, the newly allocated GKHashDB is returned . */ +static GKDB * +new_gkdb (void) { + GKDB *db = xcalloc (1, sizeof (GKDB)); + return db; +} + +/* Get the module string value given a metric enum value. + * + * On error, NULL is returned. + * On success, the string module value is returned. */ +const char * +get_mtr_type_str (GSMetricType type) { + static const GEnum enum_metric_types[] = { + {"II32", MTRC_TYPE_II32}, + {"IS32", MTRC_TYPE_IS32}, + {"IU64", MTRC_TYPE_IU64}, + {"SI32", MTRC_TYPE_SI32}, + {"SI08", MTRC_TYPE_SI08}, + {"II08", MTRC_TYPE_II08}, + {"SS32", MTRC_TYPE_SS32}, + {"IGSL", MTRC_TYPE_IGSL}, + {"SU64", MTRC_TYPE_SU64}, + {"IGKH", MTRC_TYPE_IGKH}, + {"U648", MTRC_TYPE_U648}, + {"IGLP", MTRC_TYPE_IGLP}, + }; + return enum2str (enum_metric_types, ARRAY_SIZE (enum_metric_types), type); +} + +/* Initialize a new uint32_t key - GSLList value hash table */ +void * +new_igsl_ht (void) { + khash_t (igsl) * h = kh_init (igsl); + return h; +} + +/* Initialize a new string key - uint32_t value hash table */ +void * +new_ii08_ht (void) { + khash_t (ii08) * h = kh_init (ii08); + return h; +} + +/* Initialize a new uint32_t key - uint32_t value hash table */ +void * +new_ii32_ht (void) { + khash_t (ii32) * h = kh_init (ii32); + return h; +} + +/* Initialize a new uint32_t key - string value hash table */ +void * +new_is32_ht (void) { + khash_t (is32) * h = kh_init (is32); + return h; +} + +/* Initialize a new uint32_t key - uint64_t value hash table */ +void * +new_iu64_ht (void) { + khash_t (iu64) * h = kh_init (iu64); + return h; +} + +/* Initialize a new string key - uint32_t value hash table */ +void * +new_si32_ht (void) { + khash_t (si32) * h = kh_init (si32); + return h; +} + +/* Initialize a new string key - uint64_t value hash table */ +void * +new_su64_ht (void) { + khash_t (su64) * h = kh_init (su64); + return h; +} + +/* Initialize a new uint64_t key - uint8_t value hash table */ +void * +new_u648_ht (void) { + khash_t (u648) * h = kh_init (u648); + return h; +} + +/* Initialize a new uint64_t key - GLastParse value hash table */ +static void * +new_iglp_ht (void) { + khash_t (iglp) * h = kh_init (iglp); + return h; +} + +/* Initialize a new uint32_t key - GKHashStorage value hash table */ +static void * +new_igdb_ht (void) { + khash_t (igdb) * h = kh_init (igdb); + return h; +} + +/* Initialize a new uint32_t key - GKHashStorage value hash table */ +static void * +new_igkh_ht (void) { + khash_t (igkh) * h = kh_init (igkh); + return h; +} + +/* Initialize a new string key - uint32_t value hash table */ +static void * +new_si08_ht (void) { + khash_t (si08) * h = kh_init (si08); + return h; +} + +/* Initialize a new string key - string value hash table */ +static void * +new_ss32_ht (void) { + khash_t (ss32) * h = kh_init (ss32); + return h; +} + +/* Deletes all entries from the hash table and optionally frees its GSLList */ +void +del_igsl_free (void *h, uint8_t free_data) { + khint_t k; + khash_t (igsl) * hash = h; + void *list = NULL; + if (!hash) + return; + + for (k = 0; k < kh_end (hash); ++k) { + if (!kh_exist (hash, k)) + continue; + + if (free_data) { + list = kh_value (hash, k); + list_remove_nodes (list); + } + kh_del (igsl, hash, k); + } +} + +/* Deletes all entries from the hash table */ +void +del_ii08 (void *h, GO_UNUSED uint8_t free_data) { + khint_t k; + khash_t (ii08) * hash = h; + if (!hash) + return; + + for (k = 0; k < kh_end (hash); ++k) { + if (kh_exist (hash, k)) { + kh_del (ii08, hash, k); + } + } +} + +/* Deletes all entries from the hash table */ +void +del_ii32 (void *h, GO_UNUSED uint8_t free_data) { + khint_t k; + khash_t (ii32) * hash = h; + if (!hash) + return; + + for (k = 0; k < kh_end (hash); ++k) { + if (kh_exist (hash, k)) { + kh_del (ii32, hash, k); + } + } +} + +/* Deletes both the hash entry and its string values */ +void +del_is32_free (void *h, uint8_t free_data) { + khint_t k; + khash_t (is32) * hash = h; + if (!hash) + return; + + for (k = 0; k < kh_end (hash); ++k) { + if (kh_exist (hash, k)) { + if (free_data) + free ((char *) kh_value (hash, k)); + kh_del (is32, hash, k); + } + } +} + +/* Deletes all entries from the hash table */ +void +del_iu64 (void *h, GO_UNUSED uint8_t free_data) { + khint_t k; + khash_t (iu64) * hash = h; + if (!hash) + return; + + for (k = 0; k < kh_end (hash); ++k) { + if (kh_exist (hash, k)) { + kh_del (iu64, hash, k); + } + } +} + +/* Deletes an entry from the hash table and optionally the keys for a string + * key - uint32_t value hash */ +void +del_si32_free (void *h, uint8_t free_data) { + khint_t k; + khash_t (si32) * hash = h; + if (!hash) + return; + + for (k = 0; k < kh_end (hash); ++k) { + if (kh_exist (hash, k)) { + if (free_data) + free ((char *) kh_key (hash, k)); + kh_del (si32, hash, k); + } + } +} + +/* Deletes all entries from the hash table and optionally frees its string key */ +void +del_su64_free (void *h, uint8_t free_data) { + khint_t k; + khash_t (su64) * hash = h; + if (!hash) + return; + + for (k = 0; k < kh_end (hash); ++k) { + if (kh_exist (hash, k)) { + if (free_data) + free ((char *) kh_key (hash, k)); + kh_del (su64, hash, k); + } + } +} + +/* Deletes all entries from the hash table */ +void +del_u648 (void *h, GO_UNUSED uint8_t free_data) { + khint_t k; + khash_t (u648) * hash = h; + if (!hash) + return; + + for (k = 0; k < kh_end (hash); ++k) { + if (kh_exist (hash, k)) { + kh_del (u648, hash, k); + } + } +} + +/* Destroys both the hash structure and its GSLList + * values */ +void +des_igsl_free (void *h, uint8_t free_data) { + khash_t (igsl) * hash = h; + khint_t k; + void *list = NULL; + if (!hash) + return; + + if (!free_data) + goto des; + + for (k = 0; k < kh_end (hash); ++k) { + if (kh_exist (hash, k) && (list = kh_value (hash, k))) { + list_remove_nodes (list); + } + } +des: + kh_destroy (igsl, hash); +} + +/* Destroys the hash structure */ +void +des_ii08 (void *h, GO_UNUSED uint8_t free_data) { + khash_t (ii08) * hash = h; + if (!hash) + return; + kh_destroy (ii08, hash); +} + +/* Destroys the hash structure */ +void +des_ii32 (void *h, GO_UNUSED uint8_t free_data) { + khash_t (ii32) * hash = h; + if (!hash) + return; + kh_destroy (ii32, hash); +} + +/* Destroys both the hash structure and its string values */ +void +des_is32_free (void *h, uint8_t free_data) { + khint_t k; + khash_t (is32) * hash = h; + if (!hash) + return; + + if (!free_data) + goto des; + + for (k = 0; k < kh_end (hash); ++k) { + if (kh_exist (hash, k)) { + free ((char *) kh_value (hash, k)); + } + } +des: + kh_destroy (is32, hash); +} + +/* Destroys the hash structure */ +void +des_iu64 (void *h, GO_UNUSED uint8_t free_data) { + khash_t (iu64) * hash = h; + if (!hash) + return; + kh_destroy (iu64, hash); +} + +/* Destroys both the hash structure and the keys for a + * string key - uint32_t value hash */ +void +des_si32_free (void *h, uint8_t free_data) { + khint_t k; + khash_t (si32) * hash = h; + if (!hash) + return; + + if (!free_data) + goto des; + + for (k = 0; k < kh_end (hash); ++k) { + if (kh_exist (hash, k)) { + free ((char *) kh_key (hash, k)); + } + } + +des: + kh_destroy (si32, hash); +} + +/* Destroys both the hash structure and the keys for a + * string key - uint64_t value hash */ +void +des_su64_free (void *h, uint8_t free_data) { + khash_t (su64) * hash = h; + khint_t k; + if (!hash) + return; + + if (!free_data) + goto des; + + for (k = 0; k < kh_end (hash); ++k) { + if (kh_exist (hash, k)) { + free ((char *) kh_key (hash, k)); + } + } + +des: + kh_destroy (su64, hash); +} + +/* Destroys the hash structure */ +void +des_u648 (void *h, GO_UNUSED uint8_t free_data) { + khash_t (u648) * hash = h; + if (!hash) + return; + kh_destroy (u648, hash); +} + +/* Destroys both the hash structure and the keys for a + * string key - uint32_t value hash */ +static void +des_si08_free (void *h, uint8_t free_data) { + khint_t k; + khash_t (si08) * hash = h; + if (!hash) + return; + + if (!free_data) + goto des; + + for (k = 0; k < kh_end (hash); ++k) { + if (kh_exist (hash, k)) { + free ((char *) kh_key (hash, k)); + } + } + +des: + kh_destroy (si08, hash); +} + +/* Deletes an entry from the hash table and optionally the keys for a string + * key - uint32_t value hash */ +static void +del_si08_free (void *h, uint8_t free_data) { + khint_t k; + khash_t (si08) * hash = h; + if (!hash) + return; + + for (k = 0; k < kh_end (hash); ++k) { + if (kh_exist (hash, k)) { + if (free_data) + free ((char *) kh_key (hash, k)); + kh_del (si08, hash, k); + } + } +} + +/* Deletes an entry from the hash table and optionally the keys for a string + * keys and string values */ +static void +del_ss32_free (void *h, uint8_t free_data) { + khint_t k; + khash_t (ss32) * hash = h; + if (!hash) + return; + + for (k = 0; k < kh_end (hash); ++k) { + if (kh_exist (hash, k)) { + if (free_data) { + free ((char *) kh_key (hash, k)); + free ((char *) kh_value (hash, k)); + } + kh_del (ss32, hash, k); + } + } +} + +/* Destroys both the hash structure and its string + * keys and string values */ +static void +des_ss32_free (void *h, uint8_t free_data) { + khint_t k; + khash_t (ss32) * hash = h; + if (!hash) + return; + + if (!free_data) + goto des; + + for (k = 0; k < kh_end (hash); ++k) { + if (kh_exist (hash, k)) { + free ((char *) kh_key (hash, k)); + free ((char *) kh_value (hash, k)); + } + } + +des: + kh_destroy (ss32, hash); +} + +/* Destroys the hash structure */ +static void +des_iglp (void *h, GO_UNUSED uint8_t free_data) { + khash_t (iglp) * hash = h; + if (!hash) + return; + kh_destroy (iglp, hash); +} + +/* *INDENT-OFF* */ +/* Whole application */ +const GKHashMetric app_metrics[] = { + { .metric.dbm=MTRC_DATES , MTRC_TYPE_IGKH , new_igkh_ht , NULL , NULL , 1 , NULL , NULL } , + { .metric.dbm=MTRC_SEQS , MTRC_TYPE_SI32 , new_si32_ht , des_si32_free , del_si32_free , 1 , NULL , "SI32_SEQS.db" } , + { .metric.dbm=MTRC_CNT_OVERALL , MTRC_TYPE_SI32 , new_si32_ht , des_si32_free , del_si32_free , 1 , NULL , "SI32_CNT_OVERALL.db" } , + { .metric.dbm=MTRC_HOSTNAMES , MTRC_TYPE_SS32 , new_ss32_ht , des_ss32_free , del_ss32_free , 1 , NULL , NULL } , + { .metric.dbm=MTRC_LAST_PARSE , MTRC_TYPE_IGLP , new_iglp_ht , des_iglp , NULL , 1 , NULL , "IGLP_LAST_PARSE.db" } , + { .metric.dbm=MTRC_JSON_LOGFMT , MTRC_TYPE_SS32 , new_ss32_ht , des_ss32_free , del_ss32_free , 1 , NULL , NULL } , + { .metric.dbm=MTRC_METH_PROTO , MTRC_TYPE_SI08 , new_si08_ht , des_si08_free , del_si08_free , 1 , NULL , "SI08_METH_PROTO.db" } , + { .metric.dbm=MTRC_DB_PROPS , MTRC_TYPE_SI32 , new_si32_ht , des_si32_free , del_si32_free , 1 , NULL , "SI32_DB_PROPS.db" } , +}; + +const size_t app_metrics_len = ARRAY_SIZE (app_metrics); +/* *INDENT-ON* */ + +/* Destroys malloc'd module metrics */ +static void +free_app_metrics (GKHashDB *storage) { + int i, n = 0; + GKHashMetric mtrc; + + if (!storage) + return; + + n = app_metrics_len; + for (i = 0; i < n; i++) { + mtrc = storage->metrics[i]; + if (mtrc.des) { + mtrc.des (mtrc.hash, mtrc.free_data); + } + } + free (storage); +} + +/* Given a key (date), get the relevant store + * + * On error or not found, NULL is returned. + * On success, a pointer to that store is returned. */ +void * +get_db_instance (uint32_t key) { + GKDB *db = NULL; + khint_t k; + + khash_t (igdb) * hash = ht_db; + + k = kh_get (igdb, hash, key); + /* key not found, return NULL */ + if (k == kh_end (hash)) + return NULL; + + db = kh_val (hash, k); + return db; +} + +/* Get an app hash table given a DB instance and a GAMetric + * + * On success, a pointer to that store is returned. */ +void * +get_hdb (GKDB *db, GAMetric mtrc) { + return db->hdb->metrics[mtrc].hash; +} + +Logs * +get_db_logs (uint32_t instance) { + GKDB *db = get_db_instance (instance); + return db->logs; +} + + +/* Initialize a global hash structure. + * + * On success, a pointer to that hash structure is returned. */ +static GKHashDB * +init_gkhashdb (void) { + GKHashDB *storage = NULL; + + int n = 0, i; + + storage = new_gkhdb (); + n = app_metrics_len; + for (i = 0; i < n; i++) { + storage->metrics[i] = app_metrics[i]; + storage->metrics[i].hash = app_metrics[i].alloc (); + } + + return storage; +} + +/* Insert an uint32_t key and an GLastParse value + * Note: If the key exists, its value is replaced by the given value. + * + * On error, -1 is returned. + * On success 0 is returned */ +int +ins_iglp (khash_t (iglp) *hash, uint64_t key, const GLastParse *lp) { + khint_t k; + int ret; + + if (!hash) + return -1; + + k = kh_put (iglp, hash, key, &ret); + if (ret == -1) + return -1; + + kh_val (hash, k) = *lp; + + return 0; +} + +/* Create a new GKDB instance given a uint32_t key + * + * On error, -1 is returned. + * On key found, 1 is returned. + * On success 0 is returned */ +static GKDB * +new_db (khash_t (igdb) *hash, uint32_t key) { + GKDB *db = NULL; + khint_t k; + int ret; + + if (!hash) + return NULL; + + k = kh_put (igdb, hash, key, &ret); + /* operation failed */ + if (ret == -1) + return NULL; + /* the key is present in the hash table */ + if (ret == 0) + return kh_val (hash, k); + + db = new_gkdb (); + db->hdb = init_gkhashdb (); + db->cache = NULL; + db->store = NULL; + db->logs = NULL; + kh_val (hash, k) = db; + + return db; +} + +uint32_t * +get_sorted_dates (uint32_t *len) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * hash = get_hdb (db, MTRC_DATES); + khiter_t key; + uint32_t *dates = NULL; + int i = 0; + uint32_t size = 0; + + if (!hash) + return NULL; + + size = kh_size (hash); + dates = xcalloc (size, sizeof (uint32_t)); + for (key = kh_begin (hash); key != kh_end (hash); ++key) + if (kh_exist (hash, key)) + dates[i++] = kh_key (hash, key); + qsort (dates, i, sizeof (uint32_t), cmp_ui32_asc); + *len = i; + + return dates; +} + +/* Insert a string key and the corresponding uint8_t value. + * Note: If the key exists, the value is not replaced. + * + * On error, or if key exists, -1 is returned. + * On success 0 is returned */ +int +ins_si08 (khash_t (si08) *hash, const char *key, uint8_t value) { + khint_t k; + int ret; + char *dupkey = NULL; + + if (!hash) + return -1; + + dupkey = xstrdup (key); + k = kh_put (si08, hash, dupkey, &ret); + /* operation failed, or key exists */ + if (ret == -1 || ret == 0) { + free (dupkey); + return -1; + } + + kh_val (hash, k) = value; + + return 0; +} + +/* Increment a string key and with the corresponding incremental uint32_t value. + * Note: If the key exists, the value is not replaced. + * + * On error, 0 is returned. + * On success or if the key exists, the value is returned */ +static uint8_t +ins_si08_ai (khash_t (si08) *hash, const char *key) { + uint8_t size = 0, value = 0; + + if (!hash) + return 0; + + size = kh_size (hash); + /* the auto increment value starts at SIZE (hash table) + 1 */ + value = size > 0 ? size + 1 : 1; + + return ins_si08 (hash, key, value) == 0 ? value : 0; +} + +/* Insert a string key and the corresponding uint32_t value. + * Note: If the key exists, the value is not replaced. + * + * On error, or if key exists, -1 is returned. + * On success 0 is returned */ +int +ins_si32 (khash_t (si32) *hash, const char *key, uint32_t value) { + khint_t k; + int ret; + char *dupkey = NULL; + + if (!hash) + return -1; + + dupkey = xstrdup (key); + k = kh_put (si32, hash, dupkey, &ret); + /* operation failed, or key exists */ + if (ret == -1 || ret == 0) { + free (dupkey); + return -1; + } + + kh_val (hash, k) = value; + + return 0; +} + +/* Increment a string key and with the corresponding incremental uint32_t value. + * Note: If the key exists, the value is not replaced. + * + * On error, 0 is returned. + * On success or if the key exists, the value is returned */ +uint32_t +ins_si32_inc (khash_t (si32) *hash, const char *key, + uint32_t (*cb) (khash_t (si32) *, const char *), khash_t (si32) *seqs, + const char *seqk) { + khint_t k; + int ret; + uint32_t value = 0; + + if (!hash) + return 0; + + k = kh_put (si32, hash, key, &ret); + /* operation failed, or key exists */ + if (ret == -1 || ret == 0) + return 0; + + if ((value = cb (seqs, seqk)) == 0) + return 0; + kh_val (hash, k) = value; + + return value; +} + +/* Increment a uint32_t key and with the corresponding incremental uint32_t value. + * Note: If the key exists, the value is not replaced. + * + * On error, 0 is returned. + * On success or if the key exists, the value is returned */ +uint32_t +ins_ii32_inc (khash_t (ii32) *hash, uint32_t key, + uint32_t (*cb) (khash_t (si32) *, const char *), khash_t (si32) *seqs, + const char *seqk) { + khint_t k; + int ret; + uint32_t value = 0; + + if (!hash) + return 0; + + k = kh_put (ii32, hash, key, &ret); + /* operation failed, or key exists */ + if (ret == -1 || ret == 0) + return 0; + + if ((value = cb (seqs, seqk)) == 0) + return 0; + kh_val (hash, k) = value; + + return value; +} + +/* Insert an uint32_t key and the corresponding string value. + * Note: If the key exists, the value is not replaced. + * + * On error, or if key exists, -1 is returned. + * On success 0 is returned */ +int +ins_is32 (khash_t (is32) *hash, uint32_t key, char *value) { + khint_t k; + int ret; + + if (!hash) + return -1; + + k = kh_put (is32, hash, key, &ret); + if (ret == -1 || ret == 0) + return -1; + + kh_val (hash, k) = value; + + return 0; +} + +/* Insert a string key and the corresponding string value. + * Note: If the key exists, the value is not replaced. + * + * On error, -1 is returned. + * If key exists, 1 is returned. + * On success 0 is returned */ +static int +ins_ss32 (khash_t (ss32) *hash, const char *key, const char *value) { + khint_t k; + int ret; + char *dupkey = NULL; + + if (!hash) + return -1; + + dupkey = xstrdup (key); + k = kh_put (ss32, hash, dupkey, &ret); + /* operation failed */ + if (ret == -1) { + free (dupkey); + return -1; + } + /* key exists */ + if (ret == 0) { + free (dupkey); + return 1; + } + + kh_val (hash, k) = xstrdup (value); + + return 0; +} + +/* Insert an uint32_t key and an uint32_t value + * Note: If the key exists, its value is replaced by the given value. + * + * On error, -1 is returned. + * On success 0 is returned */ +int +ins_ii32 (khash_t (ii32) *hash, uint32_t key, uint32_t value) { + khint_t k; + int ret; + + if (!hash) + return -1; + + k = kh_put (ii32, hash, key, &ret); + if (ret == -1) + return -1; + + kh_val (hash, k) = value; + + return 0; +} + +/* Insert an uint32_t key and an uint8_t value + * Note: If the key exists, its value is replaced by the given value. + * + * On error, -1 is returned. + * On success 0 is returned */ +int +ins_ii08 (khash_t (ii08) *hash, uint32_t key, uint8_t value) { + khint_t k; + int ret; + + if (!hash) + return -1; + + k = kh_put (ii08, hash, key, &ret); + if (ret == -1) + return -1; + + kh_val (hash, k) = value; + + return 0; +} + +/* Insert a uint32_t key and a uint64_t value + * Note: If the key exists, its value is replaced by the given value. + * + * On error, -1 is returned. + * On success 0 is returned */ +int +ins_iu64 (khash_t (iu64) *hash, uint32_t key, uint64_t value) { + khint_t k; + int ret; + + if (!hash) + return -1; + + k = kh_put (iu64, hash, key, &ret); + if (ret == -1) + return -1; + + kh_val (hash, k) = value; + + return 0; +} + +/* Insert a string key and a uint64_t value + * Note: If the key exists, the value is not replaced. + * + * On error or key exists, -1 is returned. + * On success 0 is returned */ +int +ins_su64 (khash_t (su64) *hash, const char *key, uint64_t value) { + khint_t k; + int ret; + char *dupkey = NULL; + + if (!hash) + return -1; + + dupkey = xstrdup (key); + k = kh_put (su64, hash, dupkey, &ret); + /* operation failed, or key exists */ + if (ret == -1 || ret == 0) { + free (dupkey); + return -1; + } + + kh_val (hash, k) = value; + + return 0; +} + +/* Insert a uint64_t key and a uint8_t value + * + * On error or key exists, -1 is returned. + * On key exists, 1 is returned. + * On success 0 is returned */ +int +ins_u648 (khash_t (u648) *hash, uint64_t key, uint8_t value) { + khint_t k; + int ret; + + if (!hash) + return -1; + + k = kh_put (u648, hash, key, &ret); + if (ret == -1) + return -1; + if (ret == 0) + return 1; + + kh_val (hash, k) = value; + + return 0; +} + +/* Increase an uint32_t value given an uint32_t key. + * + * On error, 0 is returned. + * On success the increased value is returned */ +uint32_t +inc_ii32 (khash_t (ii32) *hash, uint32_t key, uint32_t inc) { + khint_t k; + int ret; + + if (!hash) + return 0; + + k = kh_get (ii32, hash, key); + /* key not found, put a new hash with val=0 */ + if (k == kh_end (hash)) { + k = kh_put (ii32, hash, key, &ret); + /* operation failed */ + if (ret == -1) + return 0; + kh_val (hash, k) = 0; + } + + return __sync_add_and_fetch (&kh_val (hash, k), inc); +} + +/* Increase a uint64_t value given a string key. + * + * On error, -1 is returned. + * On success 0 is returned */ +int +inc_su64 (khash_t (su64) *hash, const char *key, uint64_t inc) { + khint_t k; + int ret; + uint64_t value = inc; + char *dupkey = NULL; + + if (!hash) + return -1; + + k = kh_get (su64, hash, key); + /* key not found, set new value to the given `inc` */ + if (k == kh_end (hash)) { + dupkey = xstrdup (key); + k = kh_put (su64, hash, dupkey, &ret); + /* operation failed */ + if (ret == -1) { + free (dupkey); + return -1; + } + } else { + value = kh_val (hash, k) + inc; + } + + kh_val (hash, k) = value; + + return 0; +} + +/* Increase a uint64_t value given a uint32_t key. + * Note: If the key exists, its value is increased by the given inc. + * + * On error, -1 is returned. + * On success 0 is returned */ +int +inc_iu64 (khash_t (iu64) *hash, uint32_t key, uint64_t inc) { + khint_t k; + int ret; + uint64_t value = inc; + + if (!hash) + return -1; + + k = kh_get (iu64, hash, key); + /* key found, increment current value by the given `inc` */ + if (k != kh_end (hash)) + value = (uint64_t) kh_val (hash, k) + inc; + + k = kh_put (iu64, hash, key, &ret); + if (ret == -1) + return -1; + + kh_val (hash, k) = value; + + return 0; +} + +/* Increase an uint32_t value given a string key. + * + * On error, 0 is returned. + * On success the increased value is returned */ +static uint32_t +inc_si32 (khash_t (si32) *hash, const char *key, uint32_t inc) { + khint_t k; + int ret; + char *dupkey = NULL; + + if (!hash) + return 0; + + k = kh_get (si32, hash, key); + /* key not found, put a new hash with val=0 */ + if (k == kh_end (hash)) { + dupkey = xstrdup (key); + k = kh_put (si32, hash, dupkey, &ret); + /* operation failed */ + if (ret == -1) { + free (dupkey); + return 0; + } + /* concurrently added */ + if (ret == 0) + free (dupkey); + kh_val (hash, k) = 0; + } + + return __sync_add_and_fetch (&kh_val (hash, k), inc); +} + +/* Insert a string key and auto increment int value. + * + * On error, 0 is returned. + * On key found, the stored value is returned + * On success the value of the key inserted is returned */ +uint32_t +ins_ii32_ai (khash_t (ii32) *hash, uint32_t key) { + int size = 0, value = 0; + int ret; + khint_t k; + + if (!hash) + return 0; + + size = kh_size (hash); + /* the auto increment value starts at SIZE (hash table) + 1 */ + value = size > 0 ? size + 1 : 1; + + k = kh_put (ii32, hash, key, &ret); + /* operation failed */ + if (ret == -1) + return 0; + /* key exists */ + if (ret == 0) + return kh_val (hash, k); + + kh_val (hash, k) = value; + + return value; +} + +/* Compare if the given needle is in the haystack + * + * if equal, 1 is returned, else 0 */ +static int +find_int_key_in_list (void *data, void *needle) { + return (*(uint32_t *) data) == (*(uint32_t *) needle) ? 1 : 0; +} + +/* Insert an int key and the corresponding GSLList (Single linked-list) value. + * Note: If the key exists within the list, the value is not appended. + * + * On error, -1 is returned. + * On success or if key is found, 0 is returned */ +int +ins_igsl (khash_t (igsl) *hash, uint32_t key, uint32_t value) { + khint_t k; + GSLList *list; + int ret; + + if (!hash) + return -1; + + k = kh_get (igsl, hash, key); + /* key found, check if key exists within the list */ + if (k != kh_end (hash) && (list = kh_val (hash, k))) { + if (list_find (list, find_int_key_in_list, &value)) + return 0; + list = list_insert_prepend (list, i322ptr (value)); + } else { + list = list_create (i322ptr (value)); + } + + k = kh_put (igsl, hash, key, &ret); + if (ret == -1) { + list_remove_nodes (list); + return -1; + } + + kh_val (hash, k) = list; + + return 0; +} + + +/* Get the uint32_t value of a given string key. + * + * On error, 0 is returned. + * On success the uint32_t value for the given key is returned */ +uint32_t +get_si32 (khash_t (si32) *hash, const char *key) { + khint_t k; + + if (!hash) + return 0; + + k = kh_get (si32, hash, key); + /* key found, return current value */ + if (k != kh_end (hash)) + return __sync_add_and_fetch (&kh_val (hash, k), 0); + + return 0; +} + +/* Get the uint8_t value of a given string key. + * + * On error, 0 is returned. + * On success the uint8_t value for the given key is returned */ +uint8_t +get_si08 (khash_t (si08) *hash, const char *key) { + khint_t k; + + if (!hash) + return 0; + + k = kh_get (si08, hash, key); + /* key found, return current value */ + if (k != kh_end (hash)) + return kh_val (hash, k); + + return 0; +} + +/* Get the uint8_t value of a given string key. + * + * On error, 0 is returned. + * On success the uint8_t value for the given key is returned */ +uint8_t +get_ii08 (khash_t (ii08) *hash, uint32_t key) { + khint_t k; + + if (!hash) + return 0; + + k = kh_get (ii08, hash, key); + /* key found, return current value */ + if (k != kh_end (hash)) + return kh_val (hash, k); + + return 0; +} + +/* Get the string value of a given uint32_t key. + * + * On error, NULL is returned. + * On success the string value for the given key is returned */ +char * +get_is32 (khash_t (is32) *hash, uint32_t key) { + khint_t k; + char *value = NULL; + + if (!hash) + return NULL; + + k = kh_get (is32, hash, key); + /* key found, return current value */ + if (k != kh_end (hash) && (value = kh_val (hash, k))) + return xstrdup (value); + + return NULL; +} + +/* Get the string value of a given string key. + * + * On error, NULL is returned. + * On success the string value for the given key is returned */ +static char * +get_ss32 (khash_t (ss32) *hash, const char *key) { + khint_t k; + char *value = NULL; + + if (!hash) + return NULL; + + k = kh_get (ss32, hash, key); + /* key found, return current value */ + if (k != kh_end (hash) && (value = kh_val (hash, k))) + return xstrdup (value); + + return NULL; +} + +/* Get the uint32_t value of a given uint32_t key. + * + * If key is not found, 0 is returned. + * On error, -1 is returned. + * On success the uint32_t value for the given key is returned */ +uint32_t +get_ii32 (khash_t (ii32) *hash, uint32_t key) { + khint_t k; + + if (!hash) + return 0; + + k = kh_get (ii32, hash, key); + /* key found, return current value */ + if (k != kh_end (hash)) + return __sync_add_and_fetch (&kh_val (hash, k), 0); + + return 0; +} + +/* Get the uint64_t value of a given uint32_t key. + * + * On error, or if key is not found, 0 is returned. + * On success the uint64_t value for the given key is returned */ +uint64_t +get_iu64 (khash_t (iu64) *hash, uint32_t key) { + khint_t k; + uint64_t value = 0; + + if (!hash) + return 0; + + k = kh_get (iu64, hash, key); + /* key found, return current value */ + if (k != kh_end (hash) && (value = kh_val (hash, k))) + return value; + + return 0; +} + +/* Get the uint64_t value of a given string key. + * + * On error, or if key is not found, 0 is returned. + * On success the uint64_t value for the given key is returned */ +uint64_t +get_su64 (khash_t (su64) *hash, const char *key) { + khint_t k; + uint64_t val = 0; + + if (!hash) + return 0; + + k = kh_get (su64, hash, key); + /* key found, return current value */ + if (k != kh_end (hash) && (val = kh_val (hash, k))) + return val; + + return 0; +} + +/* Get the GLastParse value of a given uint32_t key. + * + * If key is not found, {0} is returned. + * On error, -1 is returned. + * On success the GLastParse value for the given key is returned */ +static GLastParse +get_iglp (khash_t (iglp) *hash, uint64_t key) { + khint_t k; + GLastParse lp = { 0 }; + + if (!hash) + return lp; + + k = kh_get (iglp, hash, key); + /* key found, return current value */ + if (k != kh_end (hash)) { + lp = kh_val (hash, k); + return lp; + } + + return lp; +} + +/* Iterate over all the key/value pairs for the given hash structure + * and set the maximum and minimum values found on an integer key and + * integer value. + * + * Note: These are expensive calls since it has to iterate over all + * key-value pairs + * + * If the hash structure is empty, no values are set. + * On success the minimum and maximum values are set. */ +void +get_ii32_min_max (khash_t (ii32) *hash, uint32_t *min, uint32_t *max) { + khint_t k; + uint32_t curvalue = 0; + int i; + + for (i = 0, k = kh_begin (hash); k != kh_end (hash); ++k) { + if (!kh_exist (hash, k)) + continue; + + curvalue = kh_value (hash, k); + if (i++ == 0) + *min = curvalue; + if (curvalue > *max) + *max = curvalue; + if (curvalue < *min) + *min = curvalue; + } +} + +/* Iterate over all the key/value pairs for the given hash structure + * and set the maximum and minimum values found on an integer key and + * a uint64_t value. + * + * Note: These are expensive calls since it has to iterate over all + * key-value pairs + * + * If the hash structure is empty, no values are set. + * On success the minimum and maximum values are set. */ +void +get_iu64_min_max (khash_t (iu64) *hash, uint64_t *min, uint64_t *max) { + khint_t k; + uint64_t curvalue = 0; + int i; + + for (i = 0, k = kh_begin (hash); k != kh_end (hash); ++k) { + if (!kh_exist (hash, k)) + continue; + + curvalue = kh_value (hash, k); + if (i++ == 0) + *min = curvalue; + if (curvalue > *max) + *max = curvalue; + if (curvalue < *min) + *min = curvalue; + } +} + +uint32_t +ht_get_excluded_ips (void) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (si32) * hash = get_hdb (db, MTRC_CNT_OVERALL); + + if (!hash) + return 0; + + return get_si32 (hash, "excluded_ip"); +} + +uint32_t +ht_get_invalid (void) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (si32) * hash = get_hdb (db, MTRC_CNT_OVERALL); + + if (!hash) + return 0; + + return get_si32 (hash, "failed_requests"); +} + +uint32_t +ht_get_processed (void) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (si32) * hash = get_hdb (db, MTRC_CNT_OVERALL); + + if (!hash) + return 0; + + return get_si32 (hash, "total_requests"); +} + +uint32_t +ht_get_processing_time (void) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (si32) * hash = get_hdb (db, MTRC_CNT_OVERALL); + + if (!hash) + return 0; + + return get_si32 (hash, "processing_time"); +} + +uint8_t +ht_insert_meth_proto (const char *key) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (si08) * hash = get_hdb (db, MTRC_METH_PROTO); + uint8_t val = 0; + + if (!hash) + return 0; + + if ((val = get_si08 (hash, key)) != 0) + return val; + + return ins_si08_ai (hash, key); +} + +uint32_t +ht_inc_cnt_overall (const char *key, uint32_t val) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (si32) * hash = get_hdb (db, MTRC_CNT_OVERALL); + + if (!hash) + return 0; + + return inc_si32 (hash, key, val); +} + +int +ht_insert_last_parse (uint64_t key, const GLastParse *lp) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (iglp) * hash = get_hdb (db, MTRC_LAST_PARSE); + + if (!hash) + return 0; + + return ins_iglp (hash, key, lp); +} + +/* Increases the unique key counter from a uint32_t key. + * + * On error, 0 is returned. + * On success the inserted key is returned */ +uint32_t +ht_ins_seq (khash_t (si32) *hash, const char *key) { + if (!hash) + return 0; + + return inc_si32 (hash, key, 1); +} + +/* Insert an IP hostname mapped to the corresponding hostname. + * + * On error, or if key exists, -1 is returned. + * On success 0 is returned */ +int +ht_insert_hostname (const char *ip, const char *host) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (ss32) * hash = get_hdb (db, MTRC_HOSTNAMES); + + if (!hash) + return -1; + + return ins_ss32 (hash, ip, host); +} + +/* Insert a JSON log format specification such as request.method => %m. + * + * On error -1 is returned. + * On success or if key exists, 0 is returned */ +int +ht_insert_json_logfmt (GO_UNUSED void *userdata, char *key, char *spec) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (ss32) * hash = get_hdb (db, MTRC_JSON_LOGFMT); + khint_t k; + int ret; + char *dupkey = NULL; + + if (!hash) + return -1; + + k = kh_get (ss32, hash, key); + /* key found, free it then to insert */ + if (k != kh_end (hash)) + free (kh_val (hash, k)); + else { + dupkey = xstrdup (key); + k = kh_put (ss32, hash, dupkey, &ret); + /* operation failed */ + if (ret == -1) { + free (dupkey); + return -1; + } + } + kh_val (hash, k) = xstrdup (spec); + + return 0; +} + +GLastParse +ht_get_last_parse (uint64_t key) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (iglp) * hash = get_hdb (db, MTRC_LAST_PARSE); + return get_iglp (hash, key); +} + +/* Get the string value from ht_hostnames given a string key (IP). + * + * On error, NULL is returned. + * On success the string value for the given key is returned */ +char * +ht_get_hostname (const char *host) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (ss32) * hash = get_hdb (db, MTRC_HOSTNAMES); + + if (!hash) + return NULL; + + return get_ss32 (hash, host); +} + +/* Get the string value from ht_json_logfmt given a JSON specifier key. + * + * On error, NULL is returned. + * On success the string value for the given key is returned */ +char * +ht_get_json_logfmt (const char *key) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (ss32) * hash = get_hdb (db, MTRC_JSON_LOGFMT); + + if (!hash) + return NULL; + + return get_ss32 (hash, key); +} + +void +init_pre_storage (Logs *logs) { + GKDB *db = NULL; + ht_db = (khash_t (igdb) *) new_igdb_ht (); + db = new_db (ht_db, DB_INSTANCE); + db->logs = logs; +} + +static void +free_igdb (khash_t (igdb) *hash, khint_t k) { + GKDB *db = NULL; + db = kh_val (hash, k); + + des_igkh (get_hdb (db, MTRC_DATES)); + free_logs (db->logs); + free_cache (db->cache); + free_app_metrics (db->hdb); + + kh_del (igdb, hash, k); + free (kh_val (hash, k)); + +} + +/* Destroys the hash structure */ +static void +des_igdb (void *h) { + khint_t k; + khash_t (igdb) * hash = h; + + if (!hash) + return; + + for (k = 0; k < kh_end (hash); ++k) { + if (kh_exist (hash, k)) + free_igdb (hash, k); + } + kh_destroy (igdb, hash); +} + +/* Destroys the hash structure and its content */ +void +free_storage (void) { + if (conf.persist) + persist_data (); + des_igdb (ht_db); + free_persisted_data (); +} diff --git a/src/gkhash.h b/src/gkhash.h new file mode 100644 index 0000000000..e32e3302d1 --- /dev/null +++ b/src/gkhash.h @@ -0,0 +1,196 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef GKHASH_H_INCLUDED +#define GKHASH_H_INCLUDED + +#include + +#include "gslist.h" +#include "gstorage.h" +#include "khash.h" +#include "parser.h" + +#include "gkmhash.h" + +#define DB_VERSION 2 +#define DB_INSTANCE 1 + +typedef struct GKDB_ GKDB; + +typedef struct GKHashStorage_ GKHashStorage; + +/* *INDENT-OFF* */ +/* uint32_t keys , GKDB payload */ +KHASH_MAP_INIT_INT (igdb , GKDB *); +/* uint32_t keys , GKHashStorage payload */ +KHASH_MAP_INIT_INT (igkh , GKHashStorage *); +/* uint32_t keys , uint32_t payload */ +KHASH_MAP_INIT_INT (ii32 , uint32_t); +/* uint32_t keys , string payload */ +KHASH_MAP_INIT_INT (is32 , char *); +/* uint32_t keys , uint64_t payload */ +KHASH_MAP_INIT_INT (iu64 , uint64_t); +/* string keys , uint32_t payload */ +KHASH_MAP_INIT_STR (si32 , uint32_t); +/* string keys , uint8_t payload */ +KHASH_MAP_INIT_STR (si08 , uint8_t); +/* uint8_t keys , uint8_t payload */ +KHASH_MAP_INIT_INT (ii08 , uint8_t); +/* string keys , string payload */ +KHASH_MAP_INIT_STR (ss32 , char *); +/* uint64_t key , GLastParse payload */ +KHASH_MAP_INIT_INT64 (iglp , GLastParse); +/* uint32_t keys , GSLList payload */ +KHASH_MAP_INIT_INT (igsl , GSLList *); +/* string keys , uint64_t payload */ +KHASH_MAP_INIT_STR (su64 , uint64_t); +/* uint64_t key , uint8_t payload */ +KHASH_MAP_INIT_INT64 (u648 , uint8_t); +/* *INDENT-ON* */ + +/* Whole App Data store */ +typedef struct GKHashDB_ { + GKHashMetric metrics[GAMTRC_TOTAL]; +} GKHashDB; + +/* DB */ +struct GKDB_ { + GKHashDB *hdb; /* app-level hash tables */ + Logs *logs; /* logs parsing per db instance */ + GKHashModule *cache; /* cache modules */ + GKHashStorage *store; /* per date OR module */ +}; + +#define HT_FIRST_VAL(h, kvar, code) { khint_t __k; \ + for (__k = kh_begin(h); __k != kh_end(h); ++__k) { \ + if (!kh_exist(h,__k)) continue; \ + (kvar) = kh_key(h,__k); \ + code; \ + } } + +#define HT_SUM_VAL(h, kvar, code) { khint_t __k; \ + for (__k = kh_begin(h); __k != kh_end(h); ++__k) { \ + if (!kh_exist(h,__k)) continue; \ + (kvar) = kh_key(h,__k); \ + code; \ + } } + +#define HT_FOREACH_KEY(h, kvar, code) { khint_t __k; \ + for (__k = kh_begin(h); __k != kh_end(h); ++__k) { \ + if (!kh_exist(h,__k)) continue; \ + (kvar) = kh_key(h,__k); \ + code; \ + } } + +extern const GKHashMetric app_metrics[]; +extern const size_t app_metrics_len; + +/* *INDENT-OFF* */ +void *new_igsl_ht (void); +void *new_ii08_ht (void); +void *new_ii32_ht (void); +void *new_is32_ht (void); +void *new_iu64_ht (void); +void *new_si32_ht (void); +void *new_su64_ht (void); +void *new_u648_ht (void); + +void del_igsl_free (void *h, uint8_t free_data); +void del_ii08 (void *h, GO_UNUSED uint8_t free_data); +void del_ii32 (void *h, GO_UNUSED uint8_t free_data); +void del_is32_free (void *h, uint8_t free_data); +void del_iu64 (void *h, GO_UNUSED uint8_t free_data); +void del_si32_free (void *h, uint8_t free_data); +void del_su64_free (void *h, uint8_t free_data); +void del_u648 (void *h, GO_UNUSED uint8_t free_data); +void des_igsl_free (void *h, uint8_t free_data); +void des_ii08 (void *h, GO_UNUSED uint8_t free_data); +void des_ii32 (void *h, GO_UNUSED uint8_t free_data); +void des_is32_free (void *h, uint8_t free_data); +void des_iu64 (void *h, GO_UNUSED uint8_t free_data); +void des_si32_free (void *h, uint8_t free_data); +void des_su64_free (void *h, uint8_t free_data); +void des_u648 (void *h, GO_UNUSED uint8_t free_data); + +int inc_iu64 (khash_t (iu64) * hash, uint32_t key, uint64_t inc); +int inc_su64 (khash_t (su64) * hash, const char *key, uint64_t inc); +int ins_iglp (khash_t (iglp) * hash, uint64_t key, const GLastParse *lp); +int ins_igsl (khash_t (igsl) * hash, uint32_t key, uint32_t value); +int ins_ii08 (khash_t (ii08) * hash, uint32_t key, uint8_t value); +int ins_ii32 (khash_t (ii32) * hash, uint32_t key, uint32_t value); +int ins_is32 (khash_t (is32) * hash, uint32_t key, char *value); +int ins_iu64 (khash_t (iu64) * hash, uint32_t key, uint64_t value); +int ins_si08 (khash_t (si08) * hash, const char *key, uint8_t value); +int ins_si32 (khash_t (si32) * hash, const char *key, uint32_t value); +int ins_su64 (khash_t (su64) * hash, const char *key, uint64_t value); +int ins_u648 (khash_t (u648) * hash, uint64_t key, uint8_t value); +uint32_t inc_ii32 (khash_t (ii32) * hash, uint32_t key, uint32_t inc); +uint32_t ins_ii32_ai (khash_t (ii32) * hash, uint32_t key); +uint32_t ins_ii32_inc (khash_t (ii32) * hash, uint32_t key, uint32_t (*cb) (khash_t (si32) *, const char *), khash_t (si32) * seqs, const char *seqk); +uint32_t ins_si32_inc (khash_t (si32) * hash, const char *key, uint32_t (*cb) (khash_t (si32) *, const char *), khash_t (si32) * seqs, const char *seqk); + +char *get_is32 (khash_t (is32) * hash, uint32_t key); +uint32_t get_ii32 (khash_t (ii32) * hash, uint32_t key); +uint32_t get_si32 (khash_t (si32) * hash, const char *key); +uint64_t get_iu64 (khash_t (iu64) * hash, uint32_t key); +uint64_t get_su64 (khash_t (su64) * hash, const char *key); +uint8_t get_ii08 (khash_t (ii08) * hash, uint32_t key); +uint8_t get_si08 (khash_t (si08) * hash, const char *key); +void get_ii32_min_max (khash_t (ii32) * hash, uint32_t * min, uint32_t * max); +void get_iu64_min_max (khash_t (iu64) * hash, uint64_t * min, uint64_t * max); + +int ht_insert_hostname (const char *ip, const char *host); +int ht_insert_json_logfmt (GO_UNUSED void *userdata, char *key, char *spec); +int ht_insert_last_parse (uint64_t key, const GLastParse *lp); +uint32_t ht_inc_cnt_overall (const char *key, uint32_t val); +uint32_t ht_ins_seq (khash_t (si32) * hash, const char *key); +uint8_t ht_insert_meth_proto (const char *key); + +char *ht_get_hostname (const char *host); +char *ht_get_json_logfmt (const char *key); +uint32_t ht_get_excluded_ips (void); +uint32_t ht_get_invalid (void); +uint32_t ht_get_processed (void); +uint32_t ht_get_processing_time (void); +uint8_t get_method_proto (const char *value); +uint32_t *get_sorted_dates (uint32_t * len); + +void free_storage (void); +void init_pre_storage (Logs *logs); + +const char *get_mtr_type_str (GSMetricType type); +void *get_db_instance (uint32_t key); +void *get_hdb (GKDB * db, GAMetric mtrc); + +GLastParse ht_get_last_parse (uint64_t key); +Logs *get_db_logs(uint32_t instance); +/* *INDENT-ON* */ + +#endif // for #ifndef GKHASH_H diff --git a/src/gkmhash.c b/src/gkmhash.c new file mode 100644 index 0000000000..dc4c657f96 --- /dev/null +++ b/src/gkmhash.c @@ -0,0 +1,1465 @@ +/** + * gkhash.c -- default hash table functions + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include + +#include "gkmhash.h" + +#include "error.h" +#include "gkhash.h" +#include "persistence.h" +#include "sort.h" +#include "util.h" +#include "xmalloc.h" + +/* *INDENT-OFF* */ +/* Per module - These metrics are not dated */ +const GKHashMetric global_metrics[] = { + { .metric.storem=MTRC_UNIQUE_KEYS , MTRC_TYPE_SI32 , new_si32_ht , des_si32_free , del_si32_free , 1 , NULL , "SI32_UNIQUE_KEYS.db" } , + { .metric.storem=MTRC_AGENT_KEYS , MTRC_TYPE_II32 , new_ii32_ht , des_ii32 , del_ii32 , 0 , NULL , "II32_AGENT_KEYS.db" } , + { .metric.storem=MTRC_AGENT_VALS , MTRC_TYPE_IS32 , new_is32_ht , des_is32_free , del_is32_free , 1 , NULL , "IS32_AGENT_VALS.db" } , + { .metric.storem=MTRC_CNT_VALID , MTRC_TYPE_II32 , new_ii32_ht , des_ii32 , del_ii32 , 1 , NULL , "II32_CNT_VALID.db" } , + { .metric.storem=MTRC_CNT_BW , MTRC_TYPE_IU64 , new_iu64_ht , des_iu64 , del_iu64 , 1 , NULL , "IU64_CNT_BW.db" } , +}; + +/* Per module & per date */ +const GKHashMetric module_metrics[] = { + { .metric.storem=MTRC_KEYMAP , MTRC_TYPE_II32 , new_ii32_ht , des_ii32 , del_ii32 , 1 , NULL , NULL } , + { .metric.storem=MTRC_ROOTMAP , MTRC_TYPE_IS32 , new_is32_ht , des_is32_free , del_is32_free , 1 , NULL , NULL } , + { .metric.storem=MTRC_DATAMAP , MTRC_TYPE_IS32 , new_is32_ht , des_is32_free , del_is32_free , 1 , NULL , NULL } , + { .metric.storem=MTRC_UNIQMAP , MTRC_TYPE_U648 , new_u648_ht , des_u648 , del_u648 , 1 , NULL , NULL } , + { .metric.storem=MTRC_ROOT , MTRC_TYPE_II32 , new_ii32_ht , des_ii32 , del_ii32 , 1 , NULL , NULL } , + { .metric.storem=MTRC_HITS , MTRC_TYPE_II32 , new_ii32_ht , des_ii32 , del_ii32 , 1 , NULL , NULL } , + { .metric.storem=MTRC_VISITORS , MTRC_TYPE_II32 , new_ii32_ht , des_ii32 , del_ii32 , 1 , NULL , NULL } , + { .metric.storem=MTRC_BW , MTRC_TYPE_IU64 , new_iu64_ht , des_iu64 , del_iu64 , 1 , NULL , NULL } , + { .metric.storem=MTRC_CUMTS , MTRC_TYPE_IU64 , new_iu64_ht , des_iu64 , del_iu64 , 1 , NULL , NULL } , + { .metric.storem=MTRC_MAXTS , MTRC_TYPE_IU64 , new_iu64_ht , des_iu64 , del_iu64 , 1 , NULL , NULL } , + { .metric.storem=MTRC_METHODS , MTRC_TYPE_II08 , new_ii08_ht , des_ii08 , del_ii08 , 0 , NULL , NULL } , + { .metric.storem=MTRC_PROTOCOLS , MTRC_TYPE_II08 , new_ii08_ht , des_ii08 , del_ii08 , 0 , NULL , NULL } , + { .metric.storem=MTRC_AGENTS , MTRC_TYPE_IGSL , new_igsl_ht , des_igsl_free , del_igsl_free , 1 , NULL , NULL } , + { .metric.storem=MTRC_METADATA , MTRC_TYPE_SU64 , new_su64_ht , des_su64_free , del_su64_free , 1 , NULL , NULL } , +}; +const size_t module_metrics_len = ARRAY_SIZE (module_metrics); +const size_t global_metrics_len = ARRAY_SIZE (global_metrics); +/* *INDENT-ON* */ + +/* Allocate memory for a new store container GKHashStorage instance. + * + * On success, the newly allocated GKHashStorage is returned . */ +static GKHashStorage * +new_gkhstorage (void) { + GKHashStorage *storage = xcalloc (1, sizeof (GKHashStorage)); + return storage; +} + +/* Allocate memory for a new module GKHashModule instance. + * + * On success, the newly allocated GKHashStorage is returned . */ +static GKHashModule * +new_gkhmodule (uint32_t size) { + GKHashModule *storage = xcalloc (size, sizeof (GKHashModule)); + return storage; +} + +/* Allocate memory for a new global GKHashGlobal instance. + * + * On success, the newly allocated GKHashGlobal is returned . */ +static GKHashGlobal * +new_gkhglobal (void) { + GKHashGlobal *storage = xcalloc (1, sizeof (GKHashGlobal)); + return storage; +} + +/* Initialize a global hash structure. + * + * On success, a pointer to that hash structure is returned. */ +static GKHashGlobal * +init_gkhashglobal (void) { + GKHashGlobal *storage = NULL; + + int n = 0, i; + + storage = new_gkhglobal (); + n = global_metrics_len; + for (i = 0; i < n; i++) { + storage->metrics[i] = global_metrics[i]; + storage->metrics[i].hash = global_metrics[i].alloc (); + } + + return storage; +} + +/* Initialize module metrics and mallocs its hash structure */ +static void +init_tables (GModule module, GKHashModule *storage) { + int n = 0, i; + + n = module_metrics_len; + for (i = 0; i < n; i++) { + storage[module].metrics[i] = module_metrics[i]; + storage[module].metrics[i].hash = module_metrics[i].alloc (); + } +} + +/* Initialize a module hash structure. + * + * On success, a pointer to that hash structure is returned. */ +static GKHashModule * +init_gkhashmodule (void) { + GKHashModule *storage = NULL; + GModule module; + size_t idx = 0; + + storage = new_gkhmodule (TOTAL_MODULES); + FOREACH_MODULE (idx, module_list) { + module = module_list[idx]; + + storage[module].module = module; + init_tables (module, storage); + } + + return storage; +} + +/* Destroys malloc'd global metrics */ +static void +free_global_metrics (GKHashGlobal *ghash) { + int i, n = 0; + GKHashMetric mtrc; + + if (!ghash) + return; + + n = global_metrics_len; + for (i = 0; i < n; i++) { + mtrc = ghash->metrics[i]; + mtrc.des (mtrc.hash, mtrc.free_data); + } +} + +/* Destroys malloc'd module metrics */ +static void +free_module_metrics (GKHashModule *mhash, GModule module, uint8_t free_data) { + int i, n = 0; + GKHashMetric mtrc; + + if (!mhash) + return; + + n = module_metrics_len; + for (i = 0; i < n; i++) { + mtrc = mhash[module].metrics[i]; + mtrc.des (mtrc.hash, free_data ? mtrc.free_data : 0); + } +} + +/* For each module metric, deletes all entries from the hash table */ +static void +del_module_metrics (GKHashModule *mhash, GModule module, uint8_t free_data) { + int i, n = 0; + GKHashMetric mtrc; + + n = module_metrics_len; + for (i = 0; i < n; i++) { + mtrc = mhash[module].metrics[i]; + mtrc.del (mtrc.hash, free_data); + } +} + +/* Destroys all hash tables and possibly all the malloc'd data within */ +static void +free_stores (GKHashStorage *store) { + GModule module; + size_t idx = 0; + + free_global_metrics (store->ghash); + FOREACH_MODULE (idx, module_list) { + module = module_list[idx]; + free_module_metrics (store->mhash, module, 1); + } + + free (store->ghash); + free (store->mhash); + free (store); +} + +/* Insert an uint32_t key (date) and a GKHashStorage payload + * + * On error, -1 is returned. + * On key found, 1 is returned. + * On success 0 is returned */ +static int +ins_igkh (khash_t (igkh) *hash, uint32_t key) { + GKHashStorage *store = NULL; + khint_t k; + int ret; + + if (!hash) + return -1; + + k = kh_put (igkh, hash, key, &ret); + /* operation failed */ + if (ret == -1) + return -1; + /* the key is present in the hash table */ + if (ret == 0) + return 1; + + store = new_gkhstorage (); + store->mhash = init_gkhashmodule (); + store->ghash = init_gkhashglobal (); + + kh_val (hash, k) = store; + + return 0; +} + +/* Given a hash and a key (date), get the relevant store + * + * On error or not found, NULL is returned. + * On success, a pointer to that store is returned. */ +static void * +get_store (khash_t (igkh) *hash, uint32_t key) { + GKHashStorage *store = NULL; + khint_t k; + + k = kh_get (igkh, hash, key); + /* key not found, return NULL */ + if (k == kh_end (hash)) + return NULL; + + store = kh_val (hash, k); + return store; +} + +/* Given a store, a module and the metric, get the hash table + * + * On error or not found, NULL is returned. + * On success, a pointer to that hash table is returned. */ +static void * +get_hash_from_store (GKHashStorage *store, int module, GSMetric metric) { + int mtrc = 0, cnt = 0; + if (!store) + return NULL; + + if (module == -1) { + mtrc = metric - MTRC_METADATA - 1; + cnt = MTRC_CNT_BW - MTRC_UNIQUE_KEYS + 1; + if (mtrc >= cnt) { + LOG_DEBUG (("Out of bounds when attempting to get hash %d\n", metric)); + return NULL; + } + } + + /* ###NOTE: BE CAREFUL here, to avoid the almost unnecessary loop, we simply + * use the index from the enum to make it O(1). The metrics array has to be + * created in the same order as the GSMetric enum */ + if (module < 0) + return store->ghash->metrics[mtrc].hash; + return store->mhash[module].metrics[metric].hash; +} + +/* Given a module a key (date) and the metric, get the hash table + * + * On error or not found, NULL is returned. + * On success, a pointer to that hash table is returned. */ +void * +get_hash (int module, uint64_t key, GSMetric metric) { + GKHashStorage *store = NULL; + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * hash = get_hdb (db, MTRC_DATES); + + if ((store = get_store (hash, key)) == NULL) + return NULL; + return get_hash_from_store (store, module, metric); +} + +/* Given a module and a metric, get the cache hash table + * + * On success, a pointer to that hash table is returned. */ +static void * +get_hash_from_cache (GModule module, GSMetric metric) { + GKDB *db = get_db_instance (DB_INSTANCE); + + return db->cache[module].metrics[metric].hash; +} + +GSLList * +ht_get_keymap_list_from_key (GModule module, uint32_t key) { + GKDB *db = get_db_instance (DB_INSTANCE); + GSLList *list = NULL; + khiter_t kv; + khint_t k; + khash_t (ii32) * hash = NULL; + + khash_t (igkh) * dates = get_hdb (db, MTRC_DATES); + + if (!dates) + return NULL; + + for (k = kh_begin (dates); k != kh_end (dates); ++k) { + if (!kh_exist (dates, k)) + continue; + if (!(hash = get_hash (module, kh_key (dates, k), MTRC_KEYMAP))) + continue; + if ((kv = kh_get (ii32, hash, key)) == kh_end (hash)) + continue; + list = list_insert_prepend (list, i322ptr (kh_val (hash, kv))); + } + + return list; +} + +/* Insert a unique visitor key string (IP/DATE/UA), mapped to an auto + * incremented value. + * + * If the given key exists, its value is returned. + * On error, 0 is returned. + * On success the value of the key inserted is returned */ +uint32_t +ht_insert_unique_key (uint32_t date, const char *key) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (si32) * seqs = get_hdb (db, MTRC_SEQS); + khash_t (si32) * hash = get_hash (-1, date, MTRC_UNIQUE_KEYS); + uint32_t val = 0; + char *dupkey = NULL; + + if (!hash) + return 0; + + if ((val = get_si32 (hash, key)) != 0) + return val; + + dupkey = xstrdup (key); + if ((val = ins_si32_inc (hash, dupkey, ht_ins_seq, seqs, "ht_unique_keys")) == 0) + free (dupkey); + return val; +} + +/* Insert a user agent key string, mapped to an auto incremented value. + * + * If the given key exists, its value is returned. + * On error, 0 is returned. + * On success the value of the key inserted is returned */ +uint32_t +ht_insert_agent_key (uint32_t date, uint32_t key) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (si32) * seqs = get_hdb (db, MTRC_SEQS); + khash_t (ii32) * hash = get_hash (-1, date, MTRC_AGENT_KEYS); + uint32_t val = 0; + + if (!hash) + return 0; + + if ((val = get_ii32 (hash, key)) != 0) + return val; + + return ins_ii32_inc (hash, key, ht_ins_seq, seqs, "ht_agent_keys"); +} + +/* Insert a user agent uint32_t key, mapped to a user agent string value. + * + * On error, -1 is returned. + * On success 0 is returned */ +int +ht_insert_agent_value (uint32_t date, uint32_t key, char *value) { + khash_t (is32) * hash = get_hash (-1, date, MTRC_AGENT_VALS); + char *dupval = NULL; + + if (!hash) + return -1; + + if ((kh_get (is32, hash, key)) != kh_end (hash)) + return 0; + + dupval = xstrdup (value); + if (ins_is32 (hash, key, dupval) != 0) + free (dupval); + return 0; +} + +/* Insert a keymap string key. + * + * If the given key exists, its value is returned. + * On error, 0 is returned. + * On success the value of the key inserted is returned */ +uint32_t +ht_insert_keymap (GModule module, uint32_t date, uint32_t key, uint32_t *ckey) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (si32) * seqs = get_hdb (db, MTRC_SEQS); + khash_t (ii32) * hash = get_hash (module, date, MTRC_KEYMAP); + khash_t (ii32) * cache = get_hash_from_cache (module, MTRC_KEYMAP); + + uint32_t val = 0; + const char *modstr; + + if (!hash) + return 0; + + if ((val = get_ii32 (hash, key)) != 0) { + *ckey = get_ii32 (cache, key); + return val; + } + + modstr = get_module_str (module); + if ((val = ins_ii32_inc (hash, key, ht_ins_seq, seqs, modstr)) == 0) { + return val; + } + *ckey = ins_ii32_ai (cache, key); + + return val; +} + +/* Insert a rootmap uint32_t key from the keymap store mapped to its string + * value. + * + * On error, -1 is returned. + * On success 0 is returned */ +int +ht_insert_rootmap (GModule module, uint32_t date, uint32_t key, const char *value, uint32_t ckey) { + khash_t (is32) * hash = get_hash (module, date, MTRC_ROOTMAP); + khash_t (is32) * cache = get_hash_from_cache (module, MTRC_ROOTMAP); + char *dupval = NULL; + int ret = 0; + + if (!hash) + return -1; + + dupval = xstrdup (value); + if ((ret = ins_is32 (hash, key, dupval)) == 0) + ins_is32 (cache, ckey, dupval); + else + free (dupval); + + return ret; +} + +/* Insert a datamap uint32_t key and string value. + * + * On error, -1 is returned. + * On success 0 is returned */ +int +ht_insert_datamap (GModule module, uint32_t date, uint32_t key, const char *value, uint32_t ckey) { + khash_t (is32) * hash = get_hash (module, date, MTRC_DATAMAP); + khash_t (is32) * cache = get_hash_from_cache (module, MTRC_DATAMAP); + char *dupval = NULL; + int ret = 0; + + if (!hash) + return -1; + + dupval = xstrdup (value); + if ((ret = ins_is32 (hash, key, dupval)) == 0) + ins_is32 (cache, ckey, dupval); + else + free (dupval); + + return ret; +} + +/* Insert a uniqmap string key. + * + * If the given key exists, 0 is returned. + * On error, 0 is returned. + * On success the value of the key inserted is returned */ +int +ht_insert_uniqmap (GModule module, uint32_t date, uint32_t key, uint32_t value) { + khash_t (u648) * hash = get_hash (module, date, MTRC_UNIQMAP); + uint64_t k = 0; + + if (!hash) + return 0; + + k = u64encode (key, value); + return ins_u648 (hash, k, 1) == 0 ? 1 : 0; +} + +/* Insert a data uint32_t key mapped to the corresponding uint32_t root key. + * + * On error, -1 is returned. + * On success 0 is returned */ +int +ht_insert_root (GModule module, uint32_t date, uint32_t key, uint32_t value, uint32_t dkey, + uint32_t rkey) { + khash_t (ii32) * hash = get_hash (module, date, MTRC_ROOT); + khash_t (ii32) * cache = get_hash_from_cache (module, MTRC_ROOT); + + if (!hash) + return -1; + + ins_ii32 (cache, dkey, rkey); + return ins_ii32 (hash, key, value); +} + +/* Increases hits counter from a uint32_t key. + * + * On error, 0 is returned. + * On success the inserted value is returned */ +uint32_t +ht_insert_hits (GModule module, uint32_t date, uint32_t key, uint32_t inc, uint32_t ckey) { + khash_t (ii32) * hash = get_hash (module, date, MTRC_HITS); + khash_t (ii32) * cache = get_hash_from_cache (module, MTRC_HITS); + + if (!hash) + return 0; + + inc_ii32 (cache, ckey, inc); + return inc_ii32 (hash, key, inc); +} + +/* Increases visitors counter from a uint32_t key. + * + * On error, 0 is returned. + * On success the inserted value is returned */ +uint32_t +ht_insert_visitor (GModule module, uint32_t date, uint32_t key, uint32_t inc, uint32_t ckey) { + khash_t (ii32) * hash = get_hash (module, date, MTRC_VISITORS); + khash_t (ii32) * cache = get_hash_from_cache (module, MTRC_VISITORS); + + if (!hash) + return 0; + + inc_ii32 (cache, ckey, inc); + return inc_ii32 (hash, key, inc); +} + +/* Increases bandwidth counter from a uint32_t key. + * + * On error, -1 is returned. + * On success 0 is returned */ +int +ht_insert_bw (GModule module, uint32_t date, uint32_t key, uint64_t inc, uint32_t ckey) { + khash_t (iu64) * hash = get_hash (module, date, MTRC_BW); + khash_t (iu64) * cache = get_hash_from_cache (module, MTRC_BW); + + if (!hash) + return -1; + + inc_iu64 (cache, ckey, inc); + return inc_iu64 (hash, key, inc); +} + +/* Increases cumulative time served counter from a uint32_t key. + * + * On error, -1 is returned. + * On success 0 is returned */ +int +ht_insert_cumts (GModule module, uint32_t date, uint32_t key, uint64_t inc, uint32_t ckey) { + khash_t (iu64) * hash = get_hash (module, date, MTRC_CUMTS); + khash_t (iu64) * cache = get_hash_from_cache (module, MTRC_CUMTS); + + if (!hash) + return -1; + + inc_iu64 (cache, ckey, inc); + return inc_iu64 (hash, key, inc); +} + +/* Insert the maximum time served counter from a uint32_t key. + * Note: it compares the current value with the given value. + * + * On error, -1 is returned. + * On success 0 is returned */ +int +ht_insert_maxts (GModule module, uint32_t date, uint32_t key, uint64_t value, uint32_t ckey) { + khash_t (iu64) * hash = get_hash (module, date, MTRC_MAXTS); + khash_t (iu64) * cache = get_hash_from_cache (module, MTRC_MAXTS); + + if (!hash) + return -1; + + if (get_iu64 (cache, ckey) < value) + ins_iu64 (cache, ckey, value); + if (get_iu64 (hash, key) < value) + ins_iu64 (hash, key, value); + + return 0; +} + +/* Insert a method given an uint32_t key and string value. + * + * On error, or if key exists, -1 is returned. + * On success 0 is returned */ +int +ht_insert_method (GModule module, uint32_t date, uint32_t key, const char *value, uint32_t ckey) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (ii08) * hash = get_hash (module, date, MTRC_METHODS); + khash_t (ii08) * cache = get_hash_from_cache (module, MTRC_METHODS); + khash_t (si08) * mtpr = get_hdb (db, MTRC_METH_PROTO); + int ret = 0; + uint8_t val = 0; + + if (!hash) + return -1; + + if (!(val = get_si08 (mtpr, value))) + return -1; + + if ((ret = ins_ii08 (hash, key, val)) == 0) + ins_ii08 (cache, ckey, val); + + return ret; +} + +/* Insert a protocol given an uint32_t key and string value. + * + * On error, or if key exists, -1 is returned. + * On success 0 is returned */ +int +ht_insert_protocol (GModule module, uint32_t date, uint32_t key, const char *value, uint32_t ckey) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (ii08) * hash = get_hash (module, date, MTRC_PROTOCOLS); + khash_t (ii08) * cache = get_hash_from_cache (module, MTRC_PROTOCOLS); + khash_t (si08) * mtpr = get_hdb (db, MTRC_METH_PROTO); + int ret = 0; + uint8_t val = 0; + + if (!hash) + return -1; + + if (!(val = get_si08 (mtpr, value))) + return -1; + + if ((ret = ins_ii08 (hash, key, val)) == 0) + ins_ii08 (cache, ckey, val); + + return ret; +} + +/* Insert an agent for a hostname given an uint32_t key and uint32_t value. + * + * On error, -1 is returned. + * On success 0 is returned */ +int +ht_insert_agent (GModule module, uint32_t date, uint32_t key, uint32_t value) { + khash_t (igsl) * hash = get_hash (module, date, MTRC_AGENTS); + + if (!hash) + return -1; + + return ins_igsl (hash, key, value); +} + +/* Insert meta data counters from a string key. + * + * On error, -1 is returned. + * On success 0 is returned */ +int +ht_insert_meta_data (GModule module, uint32_t date, const char *key, uint64_t value) { + khash_t (su64) * hash = get_hash (module, date, MTRC_METADATA); + + if (!hash) + return -1; + + return inc_su64 (hash, key, value); +} + +int +ht_insert_date (uint32_t key) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * hash = get_hdb (db, MTRC_DATES); + + if (!hash) + return -1; + + return ins_igkh (hash, key); +} + +uint32_t +ht_inc_cnt_valid (uint32_t date, uint32_t inc) { + khash_t (ii32) * hash = get_hash (-1, date, MTRC_CNT_VALID); + + if (!hash) + return 0; + + return inc_ii32 (hash, 1, inc); +} + +int +ht_inc_cnt_bw (uint32_t date, uint64_t inc) { + khash_t (iu64) * hash = get_hash (-1, date, MTRC_CNT_BW); + + if (!hash) + return 0; + + return inc_iu64 (hash, 1, inc); +} + +uint32_t +ht_sum_valid (void) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * dates = get_hdb (db, MTRC_DATES); + khash_t (ii32) * hash = NULL; + uint32_t k = 0; + uint32_t sum = 0; + + if (!dates) + return 0; + + /* *INDENT-OFF* */ + HT_SUM_VAL (dates, k, { + if ((hash = get_hash (-1, k, MTRC_CNT_VALID))) + sum += get_ii32 (hash, 1); + }); + /* *INDENT-ON* */ + + return sum; +} + +uint64_t +ht_sum_bw (void) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * dates = get_hdb (db, MTRC_DATES); + khash_t (iu64) * hash = NULL; + uint32_t k = 0; + uint64_t sum = 0; + + if (!dates) + return 0; + + /* *INDENT-OFF* */ + HT_SUM_VAL (dates, k, { + if ((hash = get_hash (-1, k, MTRC_CNT_BW))) + sum += get_iu64 (hash, 1); + }); + /* *INDENT-ON* */ + + return sum; +} + +/* Get the number of elements in a dates hash. + * + * Return 0 if the operation fails, else number of elements. */ +uint32_t +ht_get_size_dates (void) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * hash = get_hdb (db, MTRC_DATES); + + if (!hash) + return 0; + + return kh_size (hash); +} + +/* Get the number of elements in a datamap. + * + * Return -1 if the operation fails, else number of elements. */ +uint32_t +ht_get_size_datamap (GModule module) { + khash_t (is32) * cache = get_hash_from_cache (module, MTRC_DATAMAP); + + if (!cache) + return 0; + + return kh_size (cache); +} + +/* Get the number of elements in a uniqmap. + * + * On error, 0 is returned. + * On success the number of elements in MTRC_UNIQMAP is returned */ +uint32_t +ht_get_size_uniqmap (GModule module) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * dates = get_hdb (db, MTRC_DATES); + khash_t (u648) * hash = NULL; + uint32_t k = 0; + uint32_t sum = 0; + + if (!dates) + return 0; + + /* *INDENT-OFF* */ + HT_SUM_VAL (dates, k, { + if ((hash = get_hash (module, k, MTRC_UNIQMAP))) + sum += kh_size (hash); + }); + /* *INDENT-ON* */ + + return sum; +} + +/* Get the string data value of a given uint32_t key. + * + * On error, NULL is returned. + * On success the string value for the given key is returned */ +char * +ht_get_datamap (GModule module, uint32_t key) { + khash_t (is32) * cache = get_hash_from_cache (module, MTRC_DATAMAP); + + if (!cache) + return NULL; + + return get_is32 (cache, key); +} + +/* Get the string root from MTRC_ROOTMAP given an uint32_t data key. + * + * On error, NULL is returned. + * On success the string value for the given key is returned */ +char * +ht_get_root (GModule module, uint32_t key) { + int root_key = 0; + khash_t (ii32) * hashroot = get_hash_from_cache (module, MTRC_ROOT); + khash_t (is32) * hashrootmap = get_hash_from_cache (module, MTRC_ROOTMAP); + + if (!hashroot || !hashrootmap) + return NULL; + + /* not found */ + if ((root_key = get_ii32 (hashroot, key)) == 0) + return NULL; + + return get_is32 (hashrootmap, root_key); +} + + +/* Get the int visitors value from MTRC_VISITORS given an int key. + * + * If key is not found, 0 is returned. + * On error, -1 is returned. + * On success the int value for the given key is returned */ +uint32_t +ht_get_hits (GModule module, int key) { + khash_t (ii32) * cache = get_hash_from_cache (module, MTRC_HITS); + + if (!cache) + return 0; + + return get_ii32 (cache, key); +} + +/* Get the uint32_t visitors value from MTRC_VISITORS given an uint32_t key. + * + * If key is not found, 0 is returned. + * On error, -1 is returned. + * On success the uint32_t value for the given key is returned */ +uint32_t +ht_get_visitors (GModule module, uint32_t key) { + khash_t (ii32) * cache = get_hash_from_cache (module, MTRC_VISITORS); + + if (!cache) + return 0; + + return get_ii32 (cache, key); +} + +/* Get the uint64_t value from MTRC_BW given an uint32_t key. + * + * On error, or if key is not found, 0 is returned. + * On success the uint64_t value for the given key is returned */ +uint64_t +ht_get_bw (GModule module, uint32_t key) { + khash_t (iu64) * cache = get_hash_from_cache (module, MTRC_BW); + + if (!cache) + return 0; + + return get_iu64 (cache, key); +} + +/* Get the uint64_t value from MTRC_CUMTS given an uint32_t key. + * + * On error, or if key is not found, 0 is returned. + * On success the uint64_t value for the given key is returned */ +uint64_t +ht_get_cumts (GModule module, uint32_t key) { + khash_t (iu64) * cache = get_hash_from_cache (module, MTRC_CUMTS); + + if (!cache) + return 0; + + return get_iu64 (cache, key); +} + +/* Get the uint64_t value from MTRC_MAXTS given an uint32_t key. + * + * On error, or if key is not found, 0 is returned. + * On success the uint64_t value for the given key is returned */ +uint64_t +ht_get_maxts (GModule module, uint32_t key) { + khash_t (iu64) * cache = get_hash_from_cache (module, MTRC_MAXTS); + + if (!cache) + return 0; + + return get_iu64 (cache, key); +} + +uint8_t +get_method_proto (const char *value) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (si08) * mtpr = get_hdb (db, MTRC_METH_PROTO); + uint8_t val = 0; + + if (!mtpr) + return 0; + + if ((val = get_si08 (mtpr, value)) != 0) + return val; + return 0; +} + +/* Get the string value from MTRC_METHODS given an uint32_t key. + * + * On error, NULL is returned. + * On success the string value for the given key is returned */ +char * +ht_get_method (GModule module, uint32_t key) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (ii08) * cache = get_hash_from_cache (module, MTRC_METHODS); + khash_t (si08) * mtpr = get_hdb (db, MTRC_METH_PROTO); + uint8_t val = 0; + khint_t k; + + if (!(val = get_ii08 (cache, key))) + return NULL; + + for (k = kh_begin (mtpr); k != kh_end (mtpr); ++k) { + if (kh_exist (mtpr, k) && kh_val (mtpr, k) == val) + return xstrdup (kh_key (mtpr, k)); + } + return NULL; +} + +/* Get the string value from MTRC_PROTOCOLS given an uint32_t key. + * + * On error, NULL is returned. + * On success the string value for the given key is returned */ +char * +ht_get_protocol (GModule module, uint32_t key) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (ii08) * cache = get_hash_from_cache (module, MTRC_PROTOCOLS); + khash_t (si08) * mtpr = get_hdb (db, MTRC_METH_PROTO); + uint8_t val = 0; + khint_t k; + + if (!(val = get_ii08 (cache, key))) + return NULL; + + for (k = kh_begin (mtpr); k != kh_end (mtpr); ++k) { + if (kh_exist (mtpr, k) && kh_val (mtpr, k) == val) + return xstrdup (kh_key (mtpr, k)); + } + return NULL; +} + +/* Get the string value from ht_agent_vals (user agent) given an uint32_t key. + * + * On error, NULL is returned. + * On success the string value for the given key is returned */ +char * +ht_get_host_agent_val (uint32_t key) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * dates = get_hdb (db, MTRC_DATES); + khash_t (is32) * hash = NULL; + char *data = NULL; + uint32_t k = 0; + + if (!dates) + return NULL; + + /* *INDENT-OFF* */ + HT_FIRST_VAL (dates, k, { + if ((hash = get_hash (-1, k, MTRC_AGENT_VALS))) + if ((data = get_is32 (hash, key))) + return data; + }); + /* *INDENT-ON* */ + + return NULL; +} + +/* Get the list value from MTRC_AGENTS given an uint32_t key. + * + * On error, or if key is not found, NULL is returned. + * On success the GSLList value for the given key is returned */ +GSLList * +ht_get_host_agent_list (GModule module, uint32_t key) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * dates = get_hdb (db, MTRC_DATES); + + GSLList *res = NULL, *list = NULL; + khiter_t kv; + khint_t k; + khash_t (igsl) * hash = NULL; + void *data = NULL; + + if (!dates) + return NULL; + + for (k = kh_begin (dates); k != kh_end (dates); ++k) { + if (!kh_exist (dates, k)) + continue; + if (!(hash = get_hash (module, kh_key (dates, k), MTRC_AGENTS))) + continue; + if ((kv = kh_get (igsl, hash, key)) == kh_end (hash)) + continue; + + list = kh_val (hash, kv); + /* *INDENT-OFF* */ + GSLIST_FOREACH (list, data, { + res = list_insert_prepend (res, i322ptr ((*(uint32_t *) data))); + }); + /* *INDENT-ON* */ + } + + return res; +} + +uint32_t +ht_get_keymap (GModule module, const char *key) { + khash_t (si32) * cache = get_hash_from_cache (module, MTRC_KEYMAP); + + if (!cache) + return 0; + + return get_si32 (cache, key); +} + +/* Get the meta data uint64_t from MTRC_METADATA given a string key. + * + * On error, or if key is not found, 0 is returned. + * On success the uint64_t value for the given key is returned */ +uint64_t +ht_get_meta_data (GModule module, const char *key) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * dates = get_hdb (db, MTRC_DATES); + khash_t (su64) * hash = NULL; + uint32_t k = 0; + uint64_t sum = 0; + + /* *INDENT-OFF* */ + HT_SUM_VAL (dates, k, { + if ((hash = get_hash (module, k, MTRC_METADATA))) + sum += get_su64 (hash, key); + }); + /* *INDENT-ON* */ + + return sum; +} + +/* Set the maximum and minimum values found on an integer key and + * integer value found on the MTRC_VISITORS hash structure. + * + * If the hash structure is empty, no values are set. + * On success the minimum and maximum values are set. */ +void +ht_get_hits_min_max (GModule module, uint32_t *min, uint32_t *max) { + khash_t (ii32) * cache = get_hash_from_cache (module, MTRC_HITS); + + if (!cache) + return; + + get_ii32_min_max (cache, min, max); +} + +/* Set the maximum and minimum values found on an integer key and + * integer value found on the MTRC_VISITORS hash structure. + * + * If the hash structure is empty, no values are set. + * On success the minimum and maximum values are set. */ +void +ht_get_visitors_min_max (GModule module, uint32_t *min, uint32_t *max) { + khash_t (ii32) * cache = get_hash_from_cache (module, MTRC_VISITORS); + + if (!cache) + return; + + get_ii32_min_max (cache, min, max); +} + +/* Set the maximum and minimum values found on an integer key and + * a uint64_t value found on the MTRC_BW hash structure. + * + * If the hash structure is empty, no values are set. + * On success the minimum and maximum values are set. */ +void +ht_get_bw_min_max (GModule module, uint64_t *min, uint64_t *max) { + khash_t (iu64) * cache = get_hash_from_cache (module, MTRC_BW); + + if (!cache) + return; + + get_iu64_min_max (cache, min, max); +} + +/* Set the maximum and minimum values found on an integer key and + * a uint64_t value found on the MTRC_CUMTS hash structure. + * + * If the hash structure is empty, no values are set. + * On success the minimum and maximum values are set. */ +void +ht_get_cumts_min_max (GModule module, uint64_t *min, uint64_t *max) { + khash_t (iu64) * cache = get_hash_from_cache (module, MTRC_CUMTS); + + if (!cache) + return; + + get_iu64_min_max (cache, min, max); +} + +/* Set the maximum and minimum values found on an integer key and + * a uint64_t value found on the MTRC_MAXTS hash structure. + * + * If the hash structure is empty, no values are set. + * On success the minimum and maximum values are set. */ +void +ht_get_maxts_min_max (GModule module, uint64_t *min, uint64_t *max) { + khash_t (iu64) * cache = get_hash_from_cache (module, MTRC_MAXTS); + + if (!cache) + return; + + get_iu64_min_max (cache, min, max); +} + +static void +destroy_date_stores (int date) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * hash = get_hdb (db, MTRC_DATES); + khiter_t k; + + k = kh_get (igkh, hash, date); + free_stores (kh_value (hash, k)); + kh_del (igkh, hash, k); +} + +int +invalidate_date (int date) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * hash = get_hdb (db, MTRC_DATES); + GModule module; + size_t idx = 0; + + if (!hash) + return -1; + + FOREACH_MODULE (idx, module_list) { + module = module_list[idx]; + del_module_metrics (db->cache, module, 0); + } + + destroy_date_stores (date); + + return 0; +} + +static uint32_t +ins_cache_map (GModule module, GSMetric metric, uint32_t key) { + khash_t (ii32) * cache = get_hash_from_cache (module, metric); + + if (!cache) + return 0; + return ins_ii32_ai (cache, key); +} + +static int +ins_cache_ii08 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t key, uint32_t ckey) { + khash_t (ii08) * hash = get_hash_from_store (store, module, metric); + khash_t (ii08) * cache = get_hash_from_cache (module, metric); + khint_t k; + + if ((k = kh_get (ii08, hash, key)) == kh_end (hash)) + return -1; + return ins_ii08 (cache, ckey, kh_val (hash, k)); +} + +static int +ins_cache_is32 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t key, uint32_t ckey) { + khash_t (is32) * hash = get_hash_from_store (store, module, metric); + khash_t (is32) * cache = get_hash_from_cache (module, metric); + khint_t k; + + if ((k = kh_get (is32, hash, key)) == kh_end (hash)) + return -1; + return ins_is32 (cache, ckey, kh_val (hash, k)); +} + +static int +inc_cache_ii32 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t key, uint32_t ckey) { + khash_t (ii32) * hash = get_hash_from_store (store, module, metric); + khash_t (ii32) * cache = get_hash_from_cache (module, metric); + khint_t k; + + if ((k = kh_get (ii32, hash, key)) == kh_end (hash)) + return -1; + return inc_ii32 (cache, ckey, kh_val (hash, k)); +} + +static int +max_cache_iu64 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t key, uint32_t ckey) { + khash_t (iu64) * hash = get_hash_from_store (store, module, metric); + khash_t (iu64) * cache = get_hash_from_cache (module, metric); + khint_t k; + + if ((k = kh_get (iu64, hash, key)) == kh_end (hash)) + return -1; + + if (get_iu64 (cache, ckey) < kh_val (hash, k)) + return ins_iu64 (cache, ckey, kh_val (hash, k)); + return -1; +} + +static int +inc_cache_iu64 (GKHashStorage *store, GModule module, GSMetric metric, uint32_t key, uint32_t ckey) { + khash_t (iu64) * hash = get_hash_from_store (store, module, metric); + khash_t (iu64) * cache = get_hash_from_cache (module, metric); + khint_t k; + + if ((k = kh_get (iu64, hash, key)) == kh_end (hash)) + return -1; + return inc_iu64 (cache, ckey, kh_val (hash, k)); +} + +static int +ins_raw_num_data (GModule module, uint32_t date) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * hash = get_hdb (db, MTRC_DATES); + GKHashStorage *store = get_store (hash, date); + khiter_t k, kr; + uint32_t ckey = 0, rkey = 0, nrkey = 0; + char *val = NULL; + + khash_t (ii32) * kmap = get_hash_from_store (store, module, MTRC_KEYMAP); + khash_t (ii32) * root = get_hash_from_store (store, module, MTRC_ROOT); + khash_t (is32) * rmap = get_hash_from_store (store, module, MTRC_ROOTMAP); + khash_t (ii32) * cache = get_hash_from_cache (module, MTRC_ROOT); + + if (!kmap) + return -1; + + for (k = kh_begin (kmap); k != kh_end (kmap); ++k) { + if (!kh_exist (kmap, k)) + continue; + if ((ckey = ins_cache_map (module, MTRC_KEYMAP, kh_key (kmap, k))) == 0) + continue; + + if ((rkey = get_ii32 (root, kh_val (kmap, k)))) { + kr = kh_get (is32, rmap, rkey); + if (kr != kh_end (rmap) && (val = kh_val (rmap, kr))) { + nrkey = ins_cache_map (module, MTRC_KEYMAP, djb2 ((unsigned char *) val)); + ins_cache_is32 (store, module, MTRC_ROOTMAP, rkey, nrkey); + ins_ii32 (cache, ckey, nrkey); + } + } + + ins_cache_is32 (store, module, MTRC_DATAMAP, kh_val (kmap, k), ckey); + inc_cache_ii32 (store, module, MTRC_HITS, kh_val (kmap, k), ckey); + inc_cache_ii32 (store, module, MTRC_VISITORS, kh_val (kmap, k), ckey); + inc_cache_iu64 (store, module, MTRC_BW, kh_val (kmap, k), ckey); + inc_cache_iu64 (store, module, MTRC_CUMTS, kh_val (kmap, k), ckey); + max_cache_iu64 (store, module, MTRC_MAXTS, kh_val (kmap, k), ckey); + ins_cache_ii08 (store, module, MTRC_METHODS, kh_val (kmap, k), ckey); + ins_cache_ii08 (store, module, MTRC_PROTOCOLS, kh_val (kmap, k), ckey); + } + + return 0; +} + +static int +set_raw_num_data_date (GModule module) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * hash = get_hdb (db, MTRC_DATES); + khiter_t k; + + if (!hash) + return -1; + + /* iterate over the stored dates */ + for (k = kh_begin (hash); k != kh_end (hash); ++k) { + if (kh_exist (hash, k)) + ins_raw_num_data (module, kh_key (hash, k)); + } + + return 0; +} + +int +rebuild_rawdata_cache (void) { + GModule module; + size_t idx = 0; + + FOREACH_MODULE (idx, module_list) { + module = module_list[idx]; + set_raw_num_data_date (module); + } + + return 2; +} + +/* Initialize hash tables */ +void +init_storage (void) { + GKDB *db = get_db_instance (DB_INSTANCE); + db->cache = init_gkhashmodule (); + + if (conf.restore) + restore_data (); +} + +/* Destroys the hash structure */ +void +des_igkh (void *h) { + khint_t k; + khash_t (igkh) * hash = h; + + if (!hash) + return; + + for (k = kh_begin (hash); k != kh_end (hash); ++k) { + if (!kh_exist (hash, k)) + continue; + free_stores (kh_value (hash, k)); + } + kh_destroy (igkh, hash); +} + +void +free_cache (GKHashModule *cache) { + GModule module; + size_t idx = 0; + + FOREACH_MODULE (idx, module_list) { + module = module_list[idx]; + free_module_metrics (cache, module, 0); + } + free (cache); +} + +/* A wrapper to initialize a raw data structure. + * + * On success a GRawData structure is returned. */ +static GRawData * +init_new_raw_data (GModule module, uint32_t ht_size) { + GRawData *raw_data; + + raw_data = new_grawdata (); + raw_data->idx = 0; + raw_data->module = module; + raw_data->size = ht_size; + raw_data->items = new_grawdata_item (ht_size); + + return raw_data; +} + +static GRawData * +get_u32_raw_data (GModule module) { + khash_t (ii32) * hash = get_hash_from_cache (module, MTRC_HITS); + GRawData *raw_data; + khiter_t key; + uint32_t ht_size = 0; + + if (!hash) + return NULL; + + ht_size = kh_size (hash); + raw_data = init_new_raw_data (module, ht_size); + raw_data->type = U32; + + for (key = kh_begin (hash); key != kh_end (hash); ++key) { + if (!kh_exist (hash, key)) + continue; + raw_data->items[raw_data->idx].nkey = kh_key (hash, key); + raw_data->items[raw_data->idx].hits = kh_val (hash, key); + raw_data->idx++; + } + + return raw_data; +} + +/* Store the key/value pairs from a hash table into raw_data and sorts + * the hits (numeric) value. + * + * On error, NULL is returned. + * On success the GRawData sorted is returned */ +static GRawData * +get_str_raw_data (GModule module) { + khash_t (is32) * hash = get_hash_from_cache (module, MTRC_DATAMAP); + GRawData *raw_data; + khiter_t key; + uint32_t ht_size = 0; + + if (!hash) + return NULL; + + ht_size = kh_size (hash); + raw_data = init_new_raw_data (module, ht_size); + raw_data->type = STR; + + for (key = kh_begin (hash); key != kh_end (hash); ++key) { + if (!kh_exist (hash, key)) + continue; + raw_data->items[raw_data->idx].nkey = kh_key (hash, key); + raw_data->items[raw_data->idx].data = kh_val (hash, key); + raw_data->idx++; + } + + return raw_data; +} + +/* Entry point to load the raw data from the data store into our + * GRawData structure. + * + * On error, NULL is returned. + * On success the GRawData sorted is returned */ +GRawData * +parse_raw_data (GModule module) { + GRawData *raw_data = NULL; + +#ifdef _DEBUG + clock_t begin = clock (); + double taken; + const char *modstr = NULL; + LOG_DEBUG (("== parse_raw_data ==\n")); +#endif + + switch (module) { + case VISITORS: + raw_data = get_str_raw_data (module); + if (raw_data) + sort_raw_str_data (raw_data, raw_data->idx); + break; + default: + raw_data = get_u32_raw_data (module); + if (raw_data) + sort_raw_num_data (raw_data, raw_data->idx); + } + +#ifdef _DEBUG + modstr = get_module_str (module); + taken = (double) (clock () - begin) / CLOCKS_PER_SEC; + LOG_DEBUG (("== %-30s%f\n\n", modstr, taken)); +#endif + + return raw_data; +} diff --git a/src/gkmhash.h b/src/gkmhash.h new file mode 100644 index 0000000000..dc21e4783d --- /dev/null +++ b/src/gkmhash.h @@ -0,0 +1,275 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef GKMHASH_H_INCLUDED +#define GKMHASH_H_INCLUDED + +#include "gstorage.h" + +typedef struct GKHashMetric_ GKHashMetric; + +/* Data store per module */ +typedef struct GKHashModule_ { + GModule module; + GKHashMetric metrics[GSMTRC_TOTAL]; +} GKHashModule; + +/* Data store global */ +typedef struct GKHashGlobal_ { + GKHashMetric metrics[GSMTRC_TOTAL]; +} GKHashGlobal; + +struct GKHashStorage_ { + GKHashModule *mhash; /* modules */ + GKHashGlobal *ghash; /* global */ +}; + +/* Metrics Storage */ + +/* Most metrics are encapsulated within a GKHashStorage structure, which is + * conformed of a dated key and a GKHashStorage struct value. This helps to + * easily destroy the entire dated storage at any time. */ + +/* GLOBAL METRICS */ +/* ============== */ +/* Maps a string key containing an IP|DATE|UA(hash uint32_t => hex) to an + * autoincremented value. + * + * 192.168.0.1|27/Apr/2020|7E8E0E -> 1 + * 192.168.0.1|28/Apr/2020|7E8E0E -> 2 + */ +/*khash_t(si32) MTRC_UNIQUE_KEYS */ + +/* Maps string keys made out of the user agent to an autoincremented value. + * + * Debian APT-HTTP/1.3 (1.0.9.8.5) -> 1838302 -> 1 + * Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1;) -> 8723842 -> 2 + */ +/*khash_t(ii32) MTRC_AGENT_KEYS */ + +/* Maps integer keys from the autoincremented MTRC_AGENT_KEYS value to the user + * agent. + * + * 1 -> Debian APT-HTTP/1.3 (1.0.9.8.5) + * 2 -> Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0) + */ +/*khash_t(is32) MTRC_AGENT_VALS */ + +/* Maps a single numeric key (usually 1) to an autoincremented hits value. + * + * 1 -> 5 + */ +/*khash_t(is32) MTRC_CNT_VALID */ + +/* Maps a single numeric key (usually 1) to an autoincremented bw value. + * + * 1 -> 592933 + */ +/*khash_t(iu64) MTRC_CNT_BW */ + + +/* MODULE METRICS */ +/* ============== */ +/* Maps keys (string) to a hash to a numeric values (uint32_t). + * this mitigates the issue of having multiple stores + * with the same string key, and therefore, avoids unnecessary + * memory usage (in most cases). + * + * HEAD|/index.php -> 9872347 -> 1 + * POST|/index.php -> 3452345 -> 2 + * Windows XP -> 2842343 -> 3 + * Ubuntu 10.10 -> 1852342 -> 4 + * GET|Ubuntu 10.10-> 4872343 -> 5 + * GNU+Linux -> 5862347 -> 6 + * 26/Dec/2014 -> 9874347 -> 7 + * Windows -> 3875347 -> 8 + */ +/*khash_t(si32) MTRC_KEYMAP */ + +/* Maps integer keys of root elements from the keymap hash + * to actual string values. + * + * 6 -> GNU+Linux + * 8 -> Windows + */ +/*khash_t(is32) MTRC_ROOTMAP */ + +/* Maps integer keys of data elements from the keymap hash + * to actual string values. + * + * 1 -> /index.php + * 2 -> /index.php + * 3 -> Windows xp + * 4 -> Ubuntu 10.10 + * 5 -> Ubuntu 10.10 + * 7 -> 26/dec/2014 + */ +/*khash_t(is32) MTRC_DATAMAP */ + +/* Maps the unique uint32_t key of the IP/date/UA and the uint32_t key from the + * data field encoded into a uint64_t key to numeric autoincremented values. + * e.g., "1&4" => 12938238293 to ai. + * + * 201023232 -> 1 + * 202939232 -> 2 + */ +/*khash_t(si32) MTRC_UNIQMAP */ + +/* Maps integer keys made from a data key to an integer root key in + * MTRC_KEYMAP. + * + * 4 -> 6 + * 3 -> 8 + */ +/*khash_t(ii32) MTRC_ROOT */ + +/* Maps integer key from the keymap hash to the number of + * hits. + * + * 1 -> 10934 + * 2 -> 3231 + * 3 -> 500 + * 4 -> 201 + * 5 -> 206 + */ +/*khash_t(ii32) MTRC_HITS */ + +/* Maps numeric keys made from the uniqmap store to autoincremented values + * (counter). + * 10 -> 100 + * 40 -> 56 + */ +/*khash_t(ii32) MTRC_VISITORS */ + +/* Maps numeric data keys to bandwidth (in bytes). + * 1 -> 1024 + * 2 -> 2048 + */ +/*khash_t(iu64) MTRC_BW */ + +/* Maps numeric data keys to cumulative time served (in usecs/msecs). + * 1 -> 187 + * 2 -> 208 + */ +/*khash_t(iu64) MTRC_CUMTS */ + +/* Maps numeric data keys to max time served (in usecs/msecs). + * 1 -> 1287 + * 2 -> 2308 + */ +/*khash_t(iu64) MTRC_MAXTS */ + +/* Maps numeric data keys to uint8_t values. + * 1 -> 3 + * 2 -> 4 + */ +/*khash_t(is32) MTRC_METHODS */ + +/* Maps numeric data keys to uint8_t values. + * 1 -> 1 + * 2 -> 1 + */ +/*khash_t(is32) MTRC_PROTOCOLS */ + +/* Maps numeric unique data keys (e.g., 192.168.0.1 => 1) to the unique user + * agent key. Therefore, 1 IP can contain multiple user agents + * 1 -> 3,5 + * 2 -> 4,5,6,8 + */ +/*khash_t(igsl) MTRC_AGENTS */ + +/* Maps a string key counter such as sum of hits to an autoincremented value + * "sum_hits" -> 9383 + * "sum_bw" -> 3232932 + */ +/*khash_t(igsl) MTRC_METADATA */ + +/* *INDENT-OFF* */ +extern const GKHashMetric module_metrics[]; +extern const GKHashMetric global_metrics[]; +extern const size_t global_metrics_len; +extern const size_t module_metrics_len; + +char *ht_get_datamap (GModule module, uint32_t key); +char *ht_get_host_agent_val (uint32_t key); +char *ht_get_method (GModule module, uint32_t key); +char *ht_get_protocol (GModule module, uint32_t key); +char *ht_get_root (GModule module, uint32_t key); +uint32_t ht_get_hits (GModule module, int key); +uint32_t ht_get_keymap (GModule module, const char *key); +uint32_t ht_get_size_datamap (GModule module); +uint32_t ht_get_size_dates (void); +uint32_t ht_get_size_uniqmap (GModule module); +uint32_t ht_get_visitors (GModule module, uint32_t key); +uint32_t ht_sum_valid (void); +uint64_t ht_get_bw (GModule module, uint32_t key); +uint64_t ht_get_cumts (GModule module, uint32_t key); +uint64_t ht_get_maxts (GModule module, uint32_t key); +uint64_t ht_get_meta_data (GModule module, const char *key); +uint64_t ht_sum_bw (void); +void *get_hash (int module, uint64_t key, GSMetric metric); +void ht_get_bw_min_max (GModule module, uint64_t * min, uint64_t * max); +void ht_get_cumts_min_max (GModule module, uint64_t * min, uint64_t * max); +void ht_get_hits_min_max (GModule module, uint32_t * min, uint32_t * max); +void ht_get_maxts_min_max (GModule module, uint64_t * min, uint64_t * max); +void ht_get_visitors_min_max (GModule module, uint32_t * min, uint32_t * max); + +int ht_inc_cnt_bw (uint32_t date, uint64_t inc); +int ht_insert_agent (GModule module, uint32_t date, uint32_t key, uint32_t value); +int ht_insert_agent_value (uint32_t date, uint32_t key, char *value); +int ht_insert_bw (GModule module, uint32_t date, uint32_t key, uint64_t inc, uint32_t ckey); +int ht_insert_cumts (GModule module, uint32_t date, uint32_t key, uint64_t inc, uint32_t ckey); +int ht_insert_datamap (GModule module, uint32_t date, uint32_t key, const char *value, uint32_t ckey); +int ht_insert_date (uint32_t key); +int ht_insert_maxts (GModule module, uint32_t date, uint32_t key, uint64_t value, uint32_t ckey); +int ht_insert_method (GModule module, uint32_t date, uint32_t key, const char *value, uint32_t ckey); +int ht_insert_protocol (GModule module, uint32_t date, uint32_t key, const char *value, uint32_t ckey); +int ht_insert_root (GModule module, uint32_t date, uint32_t key, uint32_t value, uint32_t dkey, uint32_t rkey); +int ht_insert_rootmap (GModule module, uint32_t date, uint32_t key, const char *value, uint32_t ckey); +int ht_insert_uniqmap (GModule module, uint32_t date, uint32_t key, uint32_t value); +uint32_t ht_inc_cnt_valid (uint32_t date, uint32_t inc); +uint32_t ht_insert_agent_key (uint32_t date, uint32_t key); +uint32_t ht_insert_hits (GModule module, uint32_t date, uint32_t key, uint32_t inc, uint32_t ckey); +uint32_t ht_insert_keymap (GModule module, uint32_t date, uint32_t key, uint32_t * ckey); +uint32_t ht_insert_unique_key (uint32_t date, const char *key); +uint32_t ht_insert_visitor (GModule module, uint32_t date, uint32_t key, uint32_t inc, uint32_t ckey); +int ht_insert_meta_data (GModule module, uint32_t date, const char *key, uint64_t value); + +int invalidate_date (int date); +int rebuild_rawdata_cache (void); +void des_igkh (void *h); +void free_cache (GKHashModule * cache); +void init_storage (void); + +GRawData *parse_raw_data (GModule module); +GSLList *ht_get_host_agent_list (GModule module, uint32_t key); +GSLList *ht_get_keymap_list_from_key (GModule module, uint32_t key); +/* *INDENT-ON* */ + +#endif // for #ifndef GKMHASH_H diff --git a/src/gmenu.c b/src/gmenu.c new file mode 100644 index 0000000000..e758fdb74d --- /dev/null +++ b/src/gmenu.c @@ -0,0 +1,145 @@ +/** + * gmenu.c -- goaccess menus + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include + +#include "gmenu.h" + +#include "xmalloc.h" +#include "ui.h" + +/* Allocate memory for a new GMenu instance. + * + * On success, the newly allocated GMenu is returned . */ +GMenu * +new_gmenu (WINDOW *parent, int h, int w, int y, int x) { + GMenu *menu = xmalloc (sizeof (GMenu)); + + memset (menu, 0, sizeof *menu); + menu->count = 0; + menu->idx = 0; + menu->multiple = 0; + menu->selectable = 0; + menu->start = 0; + menu->status = 0; + + menu->h = h; + menu->w = w; + menu->x = x; + menu->y = y; + menu->win = derwin (parent, menu->h, menu->w, menu->y, menu->x); + + return menu; +} + +/* Render actual menu item */ +static void +draw_menu_item (GMenu *menu, char *s, int x, int y, int w, int checked, GColors *(*func) (void)) { + char check, *lbl = NULL; + + if (menu->selectable) { + check = checked ? 'x' : ' '; + lbl = xmalloc (snprintf (NULL, 0, "[%c] %s", check, s) + 1); + sprintf (lbl, "[%c] %s", check, s); + draw_header (menu->win, lbl, "%s", y, x, w, (*func)); + free (lbl); + } else { + draw_header (menu->win, s, "%s", y, x, w, (*func)); + } +} + +/* Displays a menu to its associated window. + * + * On error, 1 is returned. + * On success, the newly created menu is added to the window and 0 is + * returned. */ +int +post_gmenu (GMenu *menu) { + GColors *(*func) (void); + int i = 0, j = 0, start, end, height, total, checked = 0; + + if (menu == NULL) + return 1; + + werase (menu->win); + + height = menu->h; + start = menu->start; + total = menu->size; + end = height < total ? start + height : total; + + for (i = start; i < end; i++, j++) { + func = i == menu->idx ? color_selected : color_default; + checked = menu->items[i].checked ? 1 : 0; + draw_menu_item (menu, menu->items[i].name, 0, j, menu->w, checked, func); + } + wrefresh (menu->win); + + return 0; +} + +/* Main work horse of the menu system processing input events */ +void +gmenu_driver (GMenu *menu, int c) { + int i; + + switch (c) { + case REQ_DOWN: + if (menu->idx >= menu->size - 1) + break; + ++menu->idx; + if (menu->idx >= menu->h && menu->idx >= menu->start + menu->h) + menu->start++; + post_gmenu (menu); + break; + case REQ_UP: + if (menu->idx <= 0) + break; + --menu->idx; + if (menu->idx < menu->start) + --menu->start; + post_gmenu (menu); + break; + case REQ_SEL: + if (!menu->multiple) { + for (i = 0; i < menu->size; i++) + menu->items[i].checked = 0; + } + if (menu->items[menu->idx].checked) + menu->items[menu->idx].checked = 0; + else + menu->items[menu->idx].checked = 1; + post_gmenu (menu); + break; + } +} diff --git a/src/gmenu.h b/src/gmenu.h new file mode 100644 index 0000000000..8e0cb896a6 --- /dev/null +++ b/src/gmenu.h @@ -0,0 +1,84 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#ifdef HAVE_NCURSESW_NCURSES_H +#include +#elif HAVE_NCURSES_NCURSES_H +#include +#elif HAVE_NCURSES_H +#include +#elif HAVE_CURSES_H +#include +#endif + +#ifndef GMENU_H_INCLUDED +#define GMENU_H_INCLUDED + +enum ACTION { + REQ_DOWN, + REQ_UP, + REQ_SEL +}; + +typedef struct GMenu_ GMenu; +typedef struct GItem_ GItem; + +/* Menu Item */ +struct GItem_ { + char *name; + int checked; +}; + +/* Menu Panel */ +struct GMenu_ { + WINDOW *win; + + int count; + int size; + int idx; + int start; + int h; + int w; + int x; + int y; + unsigned short multiple; + unsigned short selectable; + unsigned short status; + GItem *items; +}; + +GMenu *new_gmenu (WINDOW * parent, int h, int w, int y, int x); +int post_gmenu (GMenu * menu); +void gmenu_driver (GMenu * menu, int c); + +#endif diff --git a/src/goaccess.c b/src/goaccess.c new file mode 100644 index 0000000000..f119d7501a --- /dev/null +++ b/src/goaccess.c @@ -0,0 +1,1705 @@ +/** + * goaccess.c -- main log analyzer + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE +#define _FILE_OFFSET_BITS 64 + +#include +#include +#include + +#include + +#if HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gkhash.h" + +#ifdef HAVE_GEOLOCATION +#include "geoip1.h" +#endif + +#include "browsers.h" +#include "csv.h" +#include "error.h" +#include "gdashboard.h" +#include "gdns.h" +#include "gholder.h" +#include "goaccess.h" +#include "gwsocket.h" +#include "json.h" +#include "options.h" +#include "output.h" +#include "util.h" +#include "websocket.h" +#include "xmalloc.h" + +GConf conf = { + .append_method = 1, + .append_protocol = 1, + .chunk_size = 1024, + .hl_header = 1, + .jobs = 1, + .num_tests = 10, +}; + +/* Loading/Spinner */ +GSpinner *parsing_spinner; +/* active reverse dns flag */ +int active_gdns = 0; + +/* WebSocket server - writer and reader threads */ +static GWSWriter *gwswriter; +static GWSReader *gwsreader; +/* Dashboard data structure */ +static GDash *dash; +/* Data holder structure */ +static GHolder *holder; +/* Old signal mask */ +static sigset_t oldset; +/* Curses windows */ +static WINDOW *header_win, *main_win; + +static int main_win_height = 0; + +/* *INDENT-OFF* */ +static GScroll gscroll = { + { + {0, 0}, /* VISITORS { scroll, offset} */ + {0, 0}, /* REQUESTS { scroll, offset} */ + {0, 0}, /* REQUESTS_STATIC { scroll, offset} */ + {0, 0}, /* NOT_FOUND { scroll, offset} */ + {0, 0}, /* HOSTS { scroll, offset} */ + {0, 0}, /* OS { scroll, offset} */ + {0, 0}, /* BROWSERS { scroll, offset} */ + {0, 0}, /* VISIT_TIMES { scroll, offset} */ + {0, 0}, /* VIRTUAL_HOSTS { scroll, offset} */ + {0, 0}, /* REFERRERS { scroll, offset} */ + {0, 0}, /* REFERRING_SITES { scroll, offset} */ + {0, 0}, /* KEYPHRASES { scroll, offset} */ + {0, 0}, /* STATUS_CODES { scroll, offset} */ + {0, 0}, /* REMOTE_USER { scroll, offset} */ + {0, 0}, /* CACHE_STATUS { scroll, offset} */ +#ifdef HAVE_GEOLOCATION + {0, 0}, /* GEO_LOCATION { scroll, offset} */ + {0, 0}, /* ASN { scroll, offset} */ +#endif + {0, 0}, /* MIME_TYPE { scroll, offset} */ + {0, 0}, /* TLS_TYPE { scroll, offset} */ + }, + 0, /* current module */ + 0, /* main dashboard scroll */ + 0, /* expanded flag */ +}; +/* *INDENT-ON* */ + +/* Free malloc'd holder */ +static void +house_keeping_holder (void) { + /* REVERSE DNS THREAD */ + pthread_mutex_lock (&gdns_thread.mutex); + + /* kill dns pthread */ + active_gdns = 0; + /* clear holder structure */ + free_holder (&holder); + /* clear reverse dns queue */ + gdns_free_queue (); + /* clear the whole storage */ + free_storage (); + + pthread_mutex_unlock (&gdns_thread.mutex); +} + +/* Free malloc'd data across the whole program */ +static void +house_keeping (void) { + house_keeping_holder (); + + /* DASHBOARD */ + if (dash && !conf.output_stdout) { + free_dashboard (dash); + reset_find (); + } + + /* GEOLOCATION */ +#ifdef HAVE_GEOLOCATION + geoip_free (); +#endif + + /* INVALID REQUESTS */ + if (conf.invalid_requests_log) { + LOG_DEBUG (("Closing invalid requests log.\n")); + invalid_log_close (); + } + + /* UNKNOWNS */ + if (conf.unknowns_log) { + LOG_DEBUG (("Closing unknowns log.\n")); + unknowns_log_close (); + } + + /* CONFIGURATION */ + free_formats (); + free_browsers_hash (); + if (conf.debug_log) { + LOG_DEBUG (("Bye.\n")); + dbg_log_close (); + } + if (conf.fifo_in) + free ((char *) conf.fifo_in); + if (conf.fifo_out) + free ((char *) conf.fifo_out); + + /* clear spinner */ + free (parsing_spinner); + /* free colors */ + free_color_lists (); + /* free cmd arguments */ + free_cmd_args (); + /* WebSocket writer */ + free (gwswriter); + /* WebSocket reader */ + free (gwsreader); +} + +static void +cleanup (int ret) { + /* done, restore tty modes and reset terminal into + * non-visual mode */ + if (!conf.output_stdout) + endwin (); + + if (!conf.no_progress) + fprintf (stdout, "Cleaning up resources...\n"); + + /* unable to process valid data */ + if (ret) + output_logerrors (); + + house_keeping (); +} + +/* Drop permissions to the user specified. */ +static void +drop_permissions (void) { + struct passwd *pw; + + errno = 0; + if ((pw = getpwnam (conf.username)) == NULL) { + if (errno == 0) + FATAL ("No such user %s", conf.username); + FATAL ("Unable to retrieve user %s: %s", conf.username, strerror (errno)); + } + + if (setgroups (1, &pw->pw_gid) == -1) + FATAL ("setgroups: %s", strerror (errno)); + if (setgid (pw->pw_gid) == -1) + FATAL ("setgid: %s", strerror (errno)); + if (setuid (pw->pw_uid) == -1) + FATAL ("setuid: %s", strerror (errno)); +} + +/* Open the pidfile whose name is specified in the given path and write + * the daemonized given pid. */ +static void +write_pid_file (const char *path, pid_t pid) { + FILE *pidfile; + + if (!path) + return; + + if ((pidfile = fopen (path, "w"))) { + fprintf (pidfile, "%d", pid); + fclose (pidfile); + } else { + FATAL ("Unable to open the specified pid file. %s", strerror (errno)); + } +} + +/* Set GoAccess to run as a daemon */ +static void +daemonize (void) { + pid_t pid, sid; + int fd; + + /* Clone ourselves to make a child */ + pid = fork (); + + if (pid < 0) + exit (EXIT_FAILURE); + if (pid > 0) { + write_pid_file (conf.pidfile, pid); + printf ("Daemonized GoAccess: %d\n", pid); + exit (EXIT_SUCCESS); + } + + umask (0); + /* attempt to create our own process group */ + sid = setsid (); + if (sid < 0) { + LOG_DEBUG (("Unable to setsid: %s.\n", strerror (errno))); + exit (EXIT_FAILURE); + } + + /* set the working directory to the root directory. + * requires the user to specify absolute paths */ + if (chdir ("/") < 0) { + LOG_DEBUG (("Unable to set chdir: %s.\n", strerror (errno))); + exit (EXIT_FAILURE); + } + + /* redirect fd's 0,1,2 to /dev/null */ + /* Note that the user will need to use --debug-file for log output */ + if ((fd = open ("/dev/null", O_RDWR, 0)) == -1) { + LOG_DEBUG (("Unable to open /dev/null: %s.\n", strerror (errno))); + exit (EXIT_FAILURE); + } + + dup2 (fd, STDIN_FILENO); + dup2 (fd, STDOUT_FILENO); + dup2 (fd, STDERR_FILENO); + if (fd > STDERR_FILENO) { + close (fd); + } +} + +/* Extract data from the given module hash structure and allocate + + * load data from the hash table into an instance of GHolder */ +static void +allocate_holder_by_module (GModule module) { + GRawData *raw_data; + + /* extract data from the corresponding hash table */ + raw_data = parse_raw_data (module); + if (!raw_data) { + LOG_DEBUG (("raw data is NULL for module: %d.\n", module)); + return; + } + + load_holder_data (raw_data, holder + module, module, module_sort[module]); +} + +/* Iterate over all modules/panels and extract data from hash + * structures and load it into an instance of GHolder */ +static void +allocate_holder (void) { + size_t idx = 0; + + holder = new_gholder (TOTAL_MODULES); + FOREACH_MODULE (idx, module_list) { + allocate_holder_by_module (module_list[idx]); + } +} + +/* Extract data from the modules GHolder structure and load it into + * the terminal dashboard */ +static void +allocate_data_by_module (GModule module, int col_data) { + int size = 0, max_choices = get_max_choices (); + + dash->module[module].head = module_to_head (module); + dash->module[module].desc = module_to_desc (module); + + size = holder[module].idx; + if (gscroll.expanded && module == gscroll.current) { + size = size > max_choices ? max_choices : holder[module].idx; + } else { + size = holder[module].idx > col_data ? col_data : holder[module].idx; + } + + dash->module[module].alloc_data = size; /* data allocated */ + dash->module[module].ht_size = holder[module].ht_size; /* hash table size */ + dash->module[module].idx_data = 0; + dash->module[module].pos_y = 0; + + if (gscroll.expanded && module == gscroll.current) + dash->module[module].dash_size = DASH_EXPANDED; + else + dash->module[module].dash_size = DASH_COLLAPSED; + dash->total_alloc += dash->module[module].dash_size; + + pthread_mutex_lock (&gdns_thread.mutex); + load_data_to_dash (&holder[module], dash, module, &gscroll); + pthread_mutex_unlock (&gdns_thread.mutex); +} + +/* Iterate over all modules/panels and extract data from GHolder + * structure and load it into the terminal dashboard */ +static void +allocate_data (void) { + GModule module; + int col_data = get_num_collapsed_data_rows (); + size_t idx = 0; + + dash = new_gdash (); + FOREACH_MODULE (idx, module_list) { + module = module_list[idx]; + allocate_data_by_module (module, col_data); + } +} + +static void +clean_stdscrn (void) { + int row, col; + + getmaxyx (stdscr, row, col); + draw_header (stdscr, "", "%s", row - 1, 0, col, color_default); +} + +/* A wrapper to render all windows within the dashboard. */ +static void +render_screens (uint32_t offset) { + GColors *color = get_color (COLOR_DEFAULT); + int row, col; + char time_str_buf[32]; + + getmaxyx (stdscr, row, col); + term_size (main_win, &main_win_height); + + generate_time (); + strftime (time_str_buf, sizeof (time_str_buf), "%d/%b/%Y:%T", &now_tm); + + draw_header (stdscr, "", "%s", row - 1, 0, col, color_default); + + wattron (stdscr, color->attr | COLOR_PAIR (color->pair->idx)); + mvaddstr (row - 1, 1, T_HELP_ENTER); + mvprintw (row - 1, col / 2 - 10, "%" PRIu32 "/r - %s", offset, time_str_buf); + mvaddstr (row - 1, col - 6 - strlen (T_QUIT), T_QUIT); + mvprintw (row - 1, col - 5, "%s", GO_VERSION); + wattroff (stdscr, color->attr | COLOR_PAIR (color->pair->idx)); + + refresh (); + + /* call general stats header */ + display_general (header_win, holder); + wrefresh (header_win); + + /* display active label based on current module */ + update_active_module (header_win, gscroll.current); + + display_content (main_win, dash, &gscroll); +} + +/* Collapse the current expanded module */ +static int +collapse_current_module (void) { + if (!gscroll.expanded) + return 1; + + gscroll.expanded = 0; + reset_scroll_offsets (&gscroll); + free_dashboard (dash); + allocate_data (); + + return 0; +} + +/* Display message at the bottom of the terminal dashboard that panel + * is disabled */ +static void +disabled_panel_msg (GModule module) { + const char *lbl = module_to_label (module); + int row, col; + + getmaxyx (stdscr, row, col); + draw_header (stdscr, lbl, ERR_PANEL_DISABLED, row - 1, 0, col, color_error); +} + +/* Set the current module/panel */ +static int +set_module_to (GScroll *scrll, GModule module) { + if (get_module_index (module) == -1) { + disabled_panel_msg (module); + return 1; + } + + /* scroll to panel */ + if (!conf.no_tab_scroll) + gscroll.dash = get_module_index (module) * DASH_COLLAPSED; + + /* reset expanded module */ + collapse_current_module (); + scrll->current = module; + return 0; +} + +/* Scroll expanded module or terminal dashboard to the top */ +static void +scroll_to_first_line (void) { + if (!gscroll.expanded) + gscroll.dash = 0; + else { + gscroll.module[gscroll.current].scroll = 0; + gscroll.module[gscroll.current].offset = 0; + } +} + +/* Scroll expanded module or terminal dashboard to the last row */ +static void +scroll_to_last_line (void) { + int exp_size = get_num_expanded_data_rows (); + int scrll = 0, offset = 0; + + if (!gscroll.expanded) + gscroll.dash = dash->total_alloc - main_win_height; + else { + scrll = dash->module[gscroll.current].idx_data - 1; + if (scrll >= exp_size && scrll >= offset + exp_size) + offset = scrll < exp_size - 1 ? 0 : scrll - exp_size + 1; + gscroll.module[gscroll.current].scroll = scrll; + gscroll.module[gscroll.current].offset = offset; + } +} + +/* Load the user-agent window given the selected IP */ +static void +load_ip_agent_list (void) { + int type_ip = 0; + /* make sure we have a valid IP */ + int sel = gscroll.module[gscroll.current].scroll; + GDashData item = { 0 }; + + if (dash->module[HOSTS].holder_size == 0) + return; + + item = dash->module[HOSTS].data[sel]; + if (!invalid_ipaddr (item.metrics->data, &type_ip)) + load_agent_list (main_win, item.metrics->data); +} + +/* Expand the selected module */ +static void +expand_current_module (void) { + if (gscroll.expanded && gscroll.current == HOSTS) { + load_ip_agent_list (); + return; + } + + /* expanded, nothing to do... */ + if (gscroll.expanded) + return; + + reset_scroll_offsets (&gscroll); + gscroll.expanded = 1; + + free_holder_by_module (&holder, gscroll.current); + free_dashboard (dash); + allocate_holder_by_module (gscroll.current); + allocate_data (); +} + +/* Expand the clicked module/panel given the Y event coordinate. */ +static int +expand_module_from_ypos (int y) { + /* ignore header/footer clicks */ + if (y < MAX_HEIGHT_HEADER || y == LINES - 1) + return 1; + + if (set_module_from_mouse_event (&gscroll, dash, y)) + return 1; + + reset_scroll_offsets (&gscroll); + gscroll.expanded = 1; + + free_holder_by_module (&holder, gscroll.current); + free_dashboard (dash); + allocate_holder_by_module (gscroll.current); + allocate_data (); + + return 0; +} + +/* Expand the clicked module/panel */ +static int +expand_on_mouse_click (void) { + int ok_mouse; + MEVENT event; + + ok_mouse = getmouse (&event); + if (!conf.mouse_support || ok_mouse != OK) + return 1; + + if (event.bstate & BUTTON1_CLICKED) + return expand_module_from_ypos (event.y); + return 1; +} + +/* Scroll down expanded module to the last row */ +static void +scroll_down_expanded_module (void) { + int exp_size = get_num_expanded_data_rows (); + int *scroll_ptr, *offset_ptr; + + scroll_ptr = &gscroll.module[gscroll.current].scroll; + offset_ptr = &gscroll.module[gscroll.current].offset; + + if (!gscroll.expanded) + return; + if (*scroll_ptr >= dash->module[gscroll.current].idx_data - 1) + return; + ++(*scroll_ptr); + if (*scroll_ptr >= exp_size && *scroll_ptr >= *offset_ptr + exp_size) + ++(*offset_ptr); +} + +/* Scroll up expanded module */ +static void +scroll_up_expanded_module (void) { + int *scroll_ptr, *offset_ptr; + + scroll_ptr = &gscroll.module[gscroll.current].scroll; + offset_ptr = &gscroll.module[gscroll.current].offset; + + if (!gscroll.expanded) + return; + if (*scroll_ptr <= 0) + return; + --(*scroll_ptr); + if (*scroll_ptr < *offset_ptr) + --(*offset_ptr); +} + +/* Scroll up terminal dashboard */ +static void +scroll_up_dashboard (void) { + gscroll.dash--; +} + +/* Page up expanded module */ +static void +page_up_module (void) { + int exp_size = get_num_expanded_data_rows (); + int *scroll_ptr, *offset_ptr; + + scroll_ptr = &gscroll.module[gscroll.current].scroll; + offset_ptr = &gscroll.module[gscroll.current].offset; + + if (!gscroll.expanded) + return; + /* decrease scroll and offset by exp_size */ + *scroll_ptr -= exp_size; + if (*scroll_ptr < 0) + *scroll_ptr = 0; + + if (*scroll_ptr < *offset_ptr) + *offset_ptr -= exp_size; + if (*offset_ptr <= 0) + *offset_ptr = 0; +} + +/* Page down expanded module */ +static void +page_down_module (void) { + int exp_size = get_num_expanded_data_rows (); + int *scroll_ptr, *offset_ptr; + + scroll_ptr = &gscroll.module[gscroll.current].scroll; + offset_ptr = &gscroll.module[gscroll.current].offset; + + if (!gscroll.expanded) + return; + + *scroll_ptr += exp_size; + if (*scroll_ptr >= dash->module[gscroll.current].idx_data - 1) + *scroll_ptr = dash->module[gscroll.current].idx_data - 1; + if (*scroll_ptr >= exp_size && *scroll_ptr >= *offset_ptr + exp_size) + *offset_ptr += exp_size; + if (*offset_ptr + exp_size >= dash->module[gscroll.current].idx_data - 1) + *offset_ptr = dash->module[gscroll.current].idx_data - exp_size; + if (*scroll_ptr < exp_size - 1) + *offset_ptr = 0; +} + +/* Create a new find dialog window and render it. Upon closing the + * window, dashboard is refreshed. */ +static int +render_search_dialog (int search) { + if (render_find_dialog (main_win, &gscroll)) + return 1; + + pthread_mutex_lock (&gdns_thread.mutex); + search = perform_next_find (holder, &gscroll); + pthread_mutex_unlock (&gdns_thread.mutex); + if (search != 0) + return 1; + + free_dashboard (dash); + allocate_data (); + + return 0; +} + +/* Search for the next occurrence within the dashboard structure */ +static int +search_next_match (int search) { + pthread_mutex_lock (&gdns_thread.mutex); + search = perform_next_find (holder, &gscroll); + pthread_mutex_unlock (&gdns_thread.mutex); + if (search != 0) + return 1; + + free_dashboard (dash); + allocate_data (); + return 0; +} + +/* Update holder structure and dashboard screen */ +static void +tail_term (void) { + pthread_mutex_lock (&gdns_thread.mutex); + free_holder (&holder); + pthread_cond_broadcast (&gdns_thread.not_empty); + pthread_mutex_unlock (&gdns_thread.mutex); + + free_dashboard (dash); + allocate_holder (); + allocate_data (); + + term_size (main_win, &main_win_height); +} + +static void +tail_html (void) { + char *json = NULL; + + pthread_mutex_lock (&gdns_thread.mutex); + free_holder (&holder); + pthread_cond_broadcast (&gdns_thread.not_empty); + pthread_mutex_unlock (&gdns_thread.mutex); + + allocate_holder (); + + pthread_mutex_lock (&gdns_thread.mutex); + json = get_json (holder, 1); + pthread_mutex_unlock (&gdns_thread.mutex); + + if (json == NULL) + return; + + pthread_mutex_lock (&gwswriter->mutex); + broadcast_holder (gwswriter->fd, json, strlen (json)); + pthread_mutex_unlock (&gwswriter->mutex); + free (json); +} + +/* Fast-forward latest JSON data when client connection is opened. */ +static void +fast_forward_client (int listener) { + char *json = NULL; + + pthread_mutex_lock (&gdns_thread.mutex); + json = get_json (holder, 1); + pthread_mutex_unlock (&gdns_thread.mutex); + + if (json == NULL) + return; + + pthread_mutex_lock (&gwswriter->mutex); + send_holder_to_client (gwswriter->fd, listener, json, strlen (json)); + pthread_mutex_unlock (&gwswriter->mutex); + free (json); +} + +/* Start reading data coming from the client side through the + * WebSocket server. */ +void +read_client (void *ptr_data) { + GWSReader *reader = (GWSReader *) ptr_data; + + /* check we have a fifo for reading */ + if (reader->fd == -1) + return; + + pthread_mutex_lock (&reader->mutex); + set_self_pipe (reader->self_pipe); + pthread_mutex_unlock (&reader->mutex); + + while (1) { + /* poll(2) will block */ + if (read_fifo (reader, fast_forward_client)) + break; + } + close (reader->fd); +} + +/* Parse tailed lines */ +static void +parse_tail_follow (GLog *glog, FILE *fp) { + GLogItem *logitem = NULL; +#ifdef WITH_GETLINE + char *buf = NULL; +#else + char buf[LINE_BUFFER] = { 0 }; +#endif + + glog->bytes = 0; +#ifdef WITH_GETLINE + while ((buf = fgetline (fp)) != NULL) { +#else + while (fgets (buf, LINE_BUFFER, fp) != NULL) { +#endif + pthread_mutex_lock (&gdns_thread.mutex); + if ((parse_line (glog, buf, 0, &logitem)) == 0 && logitem != NULL) + process_log (logitem); + if (logitem != NULL) { + free_glog (logitem); + logitem = NULL; + } + pthread_mutex_unlock (&gdns_thread.mutex); + glog->bytes += strlen (buf); +#ifdef WITH_GETLINE + free (buf); +#endif + /* If the ingress rate is greater than MAX_BATCH_LINES, + * then we break and allow to re-render the UI */ + if (++glog->read % MAX_BATCH_LINES == 0) + break; + } +} + +static void +verify_inode (FILE *fp, GLog *glog) { + struct stat fdstat; + + if (stat (glog->props.filename, &fdstat) == -1) + FATAL ("Unable to stat the specified log file '%s'. %s", glog->props.filename, + strerror (errno)); + + glog->props.size = fdstat.st_size; + /* Either the log got smaller, probably was truncated so start reading from 0 + * and reset snippet. + * If the log changed its inode, more likely the log was rotated, so we set + * the initial snippet for the new log for future iterations */ + if (fdstat.st_ino != glog->props.inode || glog->snippet[0] == '\0' || 0 == glog->props.size) { + glog->length = glog->bytes = 0; + set_initial_persisted_data (glog, fp, glog->props.filename); + } + glog->props.inode = fdstat.st_ino; +} + +/* Process appended log data + * + * If nothing changed, 0 is returned. + * If log file changed, 1 is returned. */ +static int +perform_tail_follow (GLog *glog) { + FILE *fp = NULL; + char buf[READ_BYTES + 1] = { 0 }; + uint16_t len = 0; + uint64_t length = 0; + + if (glog->props.filename[0] == '-' && glog->props.filename[1] == '\0') { + parse_tail_follow (glog, glog->pipe); + /* did we read something from the pipe? */ + if (0 == glog->bytes) + return 0; + + glog->length += glog->bytes; + goto out; + } + + length = file_size (glog->props.filename); + + /* file hasn't changed */ + /* ###NOTE: This assumes the log file being read can be of smaller size, e.g., + * rotated/truncated file or larger when data is appended */ + if (length == glog->length) + return 0; + + if (!(fp = fopen (glog->props.filename, "r"))) + FATAL ("Unable to read the specified log file '%s'. %s", glog->props.filename, + strerror (errno)); + + verify_inode (fp, glog); + + len = MIN (glog->snippetlen, length); + /* This is not ideal, but maybe the only reliable way to know if the + * current log looks different than our first read/parse */ + if ((fread (buf, len, 1, fp)) != 1 && ferror (fp)) + FATAL ("Unable to fread the specified log file '%s'", glog->props.filename); + + /* For the case where the log got larger since the last iteration, we attempt + * to compare the first READ_BYTES against the READ_BYTES we had since the last + * parse. If it's different, then it means the file may got truncated but grew + * faster than the last iteration (odd, but possible), so we read from 0* */ + if (glog->snippet[0] != '\0' && buf[0] != '\0' && memcmp (glog->snippet, buf, len) != 0) + glog->length = glog->bytes = 0; + + if (!fseeko (fp, glog->length, SEEK_SET)) + parse_tail_follow (glog, fp); + fclose (fp); + + glog->length += glog->bytes; + + /* insert the inode of the file parsed and the last line parsed */ + if (glog->props.inode) { + glog->lp.line = glog->read; + glog->lp.size = glog->props.size; + ht_insert_last_parse (glog->props.inode, &glog->lp); + } + +out: + + return 1; +} + +/* Loop over and perform a follow for the given logs */ +static void +tail_loop_html (Logs *logs) { + struct timespec refresh = { + .tv_sec = conf.html_refresh ? conf.html_refresh : HTML_REFRESH, + .tv_nsec = 0, + }; + int i = 0, ret = 0; + + while (1) { + if (conf.stop_processing) + break; + + for (i = 0, ret = 0; i < logs->size; ++i) + ret |= perform_tail_follow (&logs->glog[i]); /* 0.2 secs */ + + if (1 == ret) + tail_html (); + + if (nanosleep (&refresh, NULL) == -1 && errno != EINTR) + FATAL ("nanosleep: %s", strerror (errno)); + } +} + +/* Entry point to start processing the HTML output */ +static void +process_html (Logs *logs, const char *filename) { + /* render report */ + pthread_mutex_lock (&gdns_thread.mutex); + output_html (holder, filename); + pthread_mutex_unlock (&gdns_thread.mutex); + + /* not real time? */ + if (!conf.real_time_html) + return; + /* ignore loading from disk */ + if (logs->load_from_disk_only) + return; + + pthread_mutex_lock (&gwswriter->mutex); + gwswriter->fd = open_fifoin (); + pthread_mutex_unlock (&gwswriter->mutex); + + /* open fifo for write */ + if (gwswriter->fd == -1) + return; + + set_ready_state (); + tail_loop_html (logs); + close (gwswriter->fd); +} + +/* Iterate over available panels and advance the panel pointer. */ +static int +next_module (void) { + int next = -1; + + if ((next = get_next_module (gscroll.current)) == -1) + return 1; + + gscroll.current = next; + if (!conf.no_tab_scroll) + gscroll.dash = get_module_index (gscroll.current) * DASH_COLLAPSED; + + return 0; +} + +/* Iterate over available panels and rewind the panel pointer. */ +static int +previous_module (void) { + int prev = -1; + + if ((prev = get_prev_module (gscroll.current)) == -1) + return 1; + + gscroll.current = prev; + if (!conf.no_tab_scroll) + gscroll.dash = get_module_index (gscroll.current) * DASH_COLLAPSED; + + return 0; +} + +/* Perform several curses operations upon resizing the terminal. */ +static void +window_resize (void) { + endwin (); + refresh (); + werase (header_win); + werase (main_win); + werase (stdscr); + term_size (main_win, &main_win_height); + refresh (); +} + +/* Create a new sort dialog window and render it. Upon closing the + * window, dashboard is refreshed. */ +static void +render_sort_dialog (void) { + load_sort_win (main_win, gscroll.current, &module_sort[gscroll.current]); + + pthread_mutex_lock (&gdns_thread.mutex); + free_holder (&holder); + pthread_cond_broadcast (&gdns_thread.not_empty); + pthread_mutex_unlock (&gdns_thread.mutex); + + free_dashboard (dash); + allocate_holder (); + allocate_data (); +} + +static void +term_tail_logs (Logs *logs) { + struct timespec ts = {.tv_sec = 0,.tv_nsec = 200000000 }; /* 0.2 seconds */ + uint32_t offset = 0; + int i, ret; + + for (i = 0, ret = 0; i < logs->size; ++i) + ret |= perform_tail_follow (&logs->glog[i]); + + if (1 == ret) { + tail_term (); + offset = *logs->processed - logs->offset; + render_screens (offset); + } + if (nanosleep (&ts, NULL) == -1 && errno != EINTR) { + FATAL ("nanosleep: %s", strerror (errno)); + } +} + +/* Interfacing with the keyboard */ +static void +get_keys (Logs *logs) { + int search = 0; + int c, quit = 1; + uint32_t offset = 0; + + struct sigaction act, oldact; + + /* Change the action for SIGINT to SIG_IGN and block Ctrl+c + * before entering the subdialog */ + act.sa_handler = SIG_IGN; + sigemptyset (&act.sa_mask); + act.sa_flags = 0; + + while (quit) { + if (conf.stop_processing) + break; + + offset = *logs->processed - logs->offset; + c = wgetch (stdscr); + switch (c) { + case 'q': /* quit */ + if (!gscroll.expanded) { + quit = 0; + break; + } + if (collapse_current_module () == 0) + render_screens (offset); + break; + case KEY_F (1): + case '?': + case 'h': + sigaction (SIGINT, &act, &oldact); + load_help_popup (main_win); + sigaction (SIGINT, &oldact, NULL); + render_screens (offset); + break; + case 49: /* 1 */ + /* reset expanded module */ + if (set_module_to (&gscroll, VISITORS) == 0) + render_screens (offset); + break; + case 50: /* 2 */ + /* reset expanded module */ + if (set_module_to (&gscroll, REQUESTS) == 0) + render_screens (offset); + break; + case 51: /* 3 */ + /* reset expanded module */ + if (set_module_to (&gscroll, REQUESTS_STATIC) == 0) + render_screens (offset); + break; + case 52: /* 4 */ + /* reset expanded module */ + if (set_module_to (&gscroll, NOT_FOUND) == 0) + render_screens (offset); + break; + case 53: /* 5 */ + /* reset expanded module */ + if (set_module_to (&gscroll, HOSTS) == 0) + render_screens (offset); + break; + case 54: /* 6 */ + /* reset expanded module */ + if (set_module_to (&gscroll, OS) == 0) + render_screens (offset); + break; + case 55: /* 7 */ + /* reset expanded module */ + if (set_module_to (&gscroll, BROWSERS) == 0) + render_screens (offset); + break; + case 56: /* 8 */ + /* reset expanded module */ + if (set_module_to (&gscroll, VISIT_TIMES) == 0) + render_screens (offset); + break; + case 57: /* 9 */ + /* reset expanded module */ + if (set_module_to (&gscroll, VIRTUAL_HOSTS) == 0) + render_screens (offset); + break; + case 48: /* 0 */ + /* reset expanded module */ + if (set_module_to (&gscroll, REFERRERS) == 0) + render_screens (offset); + break; + case 33: /* shift + 1 */ + /* reset expanded module */ + if (set_module_to (&gscroll, REFERRING_SITES) == 0) + render_screens (offset); + break; + case 64: /* shift + 2 */ + /* reset expanded module */ + if (set_module_to (&gscroll, KEYPHRASES) == 0) + render_screens (offset); + break; + case 35: /* Shift + 3 */ + /* reset expanded module */ + if (set_module_to (&gscroll, STATUS_CODES) == 0) + render_screens (offset); + break; + case 36: /* Shift + 4 */ + /* reset expanded module */ + if (set_module_to (&gscroll, REMOTE_USER) == 0) + render_screens (offset); + break; + case 37: /* Shift + 5 */ + /* reset expanded module */ + if (set_module_to (&gscroll, CACHE_STATUS) == 0) + render_screens (offset); + break; +#ifdef HAVE_GEOLOCATION + case 94: /* Shift + 6 */ + /* reset expanded module */ + if (set_module_to (&gscroll, GEO_LOCATION) == 0) + render_screens (offset); + break; + case 38: /* Shift + 7 */ + /* reset expanded module */ + if (set_module_to (&gscroll, ASN) == 0) + render_screens (offset); + break; +#endif + case 42: /* Shift + 7 */ + /* reset expanded module */ + if (set_module_to (&gscroll, MIME_TYPE) == 0) + render_screens (offset); + break; + case 40: /* Shift + 8 */ + /* reset expanded module */ + if (set_module_to (&gscroll, TLS_TYPE) == 0) + render_screens (offset); + break; + case 9: /* TAB */ + /* reset expanded module */ + collapse_current_module (); + if (next_module () == 0) + render_screens (offset); + break; + case 353: /* Shift TAB */ + /* reset expanded module */ + collapse_current_module (); + if (previous_module () == 0) + render_screens (offset); + break; + case 'g': /* g = top */ + scroll_to_first_line (); + display_content (main_win, dash, &gscroll); + break; + case 'G': /* G = down */ + scroll_to_last_line (); + display_content (main_win, dash, &gscroll); + break; + /* expand dashboard module */ + case KEY_RIGHT: + case 0x0a: + case 0x0d: + case 32: /* ENTER */ + case 79: /* o */ + case 111: /* O */ + case KEY_ENTER: + expand_current_module (); + display_content (main_win, dash, &gscroll); + break; + case KEY_DOWN: /* scroll main dashboard */ + if ((gscroll.dash + main_win_height) < dash->total_alloc) { + gscroll.dash++; + display_content (main_win, dash, &gscroll); + } + break; + case KEY_MOUSE: /* handles mouse events */ + if (expand_on_mouse_click () == 0) + render_screens (offset); + break; + case 106: /* j - DOWN expanded module */ + scroll_down_expanded_module (); + display_content (main_win, dash, &gscroll); + break; + /* scroll up main_win */ + case KEY_UP: + if (gscroll.dash > 0) { + scroll_up_dashboard (); + display_content (main_win, dash, &gscroll); + } + break; + case 2: /* ^ b - page up */ + case 339: /* ^ PG UP */ + page_up_module (); + display_content (main_win, dash, &gscroll); + break; + case 6: /* ^ f - page down */ + case 338: /* ^ PG DOWN */ + page_down_module (); + display_content (main_win, dash, &gscroll); + break; + case 107: /* k - UP expanded module */ + scroll_up_expanded_module (); + display_content (main_win, dash, &gscroll); + break; + case 'n': + if (search_next_match (search) == 0) + render_screens (offset); + break; + case '/': + sigaction (SIGINT, &act, &oldact); + if (render_search_dialog (search) == 0) + render_screens (offset); + sigaction (SIGINT, &oldact, NULL); + break; + case 99: /* c */ + if (conf.no_color) + break; + + sigaction (SIGINT, &act, &oldact); + load_schemes_win (main_win); + sigaction (SIGINT, &oldact, NULL); + + free_dashboard (dash); + allocate_data (); + set_wbkgd (main_win, header_win); + render_screens (offset); + break; + case 115: /* s */ + sigaction (SIGINT, &act, &oldact); + render_sort_dialog (); + sigaction (SIGINT, &oldact, NULL); + + render_screens (offset); + break; + case 269: + case KEY_RESIZE: + window_resize (); + render_screens (offset); + break; + default: + if (logs->load_from_disk_only) + break; + term_tail_logs (logs); + break; + } + } +} + +/* Store accumulated processing time + * Note: As we store with time_t second resolution, + * if elapsed time == 0, we will bump it to 1. + */ +static void +set_accumulated_time (void) { + time_t elapsed = end_proc - start_proc; + elapsed = (!elapsed) ? !elapsed : elapsed; + ht_inc_cnt_overall ("processing_time", elapsed); +} + +/* Execute the following calls right before we start the main + * processing/parsing loop */ +static void +init_processing (void) { + /* perform some additional checks before parsing panels */ + verify_panels (); + /* initialize storage */ + pthread_mutex_lock (&parsing_spinner->mutex); + parsing_spinner->label = "SETTING UP STORAGE"; + pthread_mutex_unlock (&parsing_spinner->mutex); + + init_storage (); + insert_methods_protocols (); + set_spec_date_format (); + + if ((!conf.skip_term_resolver && !conf.output_stdout) || + (conf.enable_html_resolver && conf.real_time_html)) + gdns_thread_create (); +} + +/* Determine the type of output, i.e., JSON, CSV, HTML */ +static void +standard_output (Logs *logs) { + char *csv = NULL, *json = NULL, *html = NULL; + + /* CSV */ + if (find_output_type (&csv, "csv", 1) == 0) + output_csv (holder, csv); + /* JSON */ + if (find_output_type (&json, "json", 1) == 0) + output_json (holder, json); + /* HTML */ + if (find_output_type (&html, "html", 1) == 0 || conf.output_format_idx == 0) { + if (conf.real_time_html) + setup_ws_server (gwswriter, gwsreader); + process_html (logs, html); + } + + free (csv); + free (html); + free (json); +} + +/* Output to a terminal */ +static void +curses_output (Logs *logs) { + allocate_data (); + + clean_stdscrn (); + render_screens (0); + /* will loop in here */ + get_keys (logs); +} + +/* Set locale */ +static void +set_locale (void) { + char *loc_ctype; + + setlocale (LC_ALL, ""); +#ifdef ENABLE_NLS + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); +#endif + + loc_ctype = getenv ("LC_CTYPE"); + if (loc_ctype != NULL) + setlocale (LC_CTYPE, loc_ctype); + else if ((loc_ctype = getenv ("LC_ALL"))) + setlocale (LC_CTYPE, loc_ctype); + else + setlocale (LC_CTYPE, ""); +} + +/* Attempt to get the current name of a terminal or fallback to /dev/tty + * + * On error, -1 is returned + * On success, the new file descriptor is returned */ +static int +open_term (char **buf) { + const char *term = "/dev/tty"; + + if (!isatty (STDERR_FILENO) || (term = ttyname (STDERR_FILENO)) == 0) { + if (!isatty (STDOUT_FILENO) || (term = ttyname (STDOUT_FILENO)) == 0) { + if (!isatty (STDIN_FILENO) || (term = ttyname (STDIN_FILENO)) == 0) { + term = "/dev/tty"; + } + } + } + *buf = xstrdup (term); + + return open (term, O_RDONLY); +} + +/* Determine if reading from a pipe, and duplicate file descriptors so + * it doesn't get in the way of curses' normal reading stdin for + * wgetch() */ +static FILE * +set_pipe_stdin (void) { + char *term = NULL; + FILE *pipe = stdin; + int term_fd = -1; + int pipe_fd = -1; + + /* If unable to open a terminal, yet data is being piped, then it's + * probably from the cron, or when running as a user that can't open a + * terminal. In that case it's still important to set the pipe as + * non-blocking. + * + * Note: If used from the cron, it will require the + * user to use a single dash to parse piped data such as: + * cat access.log | goaccess - */ + if ((term_fd = open_term (&term)) == -1) + goto out1; + + if ((pipe_fd = dup (fileno (stdin))) == -1) + FATAL ("Unable to dup stdin: %s", strerror (errno)); + + pipe = fdopen (pipe_fd, "r"); + if (freopen (term, "r", stdin) == 0) + FATAL ("Unable to open input from TTY"); + if (fileno (stdin) != 0) + (void) dup2 (fileno (stdin), 0); + + add_dash_filename (); + +out1: + + /* no need to set it as non-blocking since we are simply outputting a + * static report */ + if (conf.output_stdout && !conf.real_time_html) + goto out2; + + /* Using select(), poll(), or epoll(), etc may be a better choice... */ + if (pipe_fd == -1) + pipe_fd = fileno (pipe); + if (fcntl (pipe_fd, F_SETFL, fcntl (pipe_fd, F_GETFL, 0) | O_NONBLOCK) == -1) + FATAL ("Unable to set fd as non-blocking: %s.", strerror (errno)); + +out2: + + free (term); + + return pipe; +} + +/* Determine if we are getting data from the stdin, and where are we + * outputting to. */ +static void +set_io (FILE **pipe) { + /* For backwards compatibility, check if we are not outputting to a + * terminal or if an output format was supplied */ + if (!isatty (STDOUT_FILENO) || conf.output_format_idx > 0) + conf.output_stdout = 1; + /* dup fd if data piped */ + if (!isatty (STDIN_FILENO)) + *pipe = set_pipe_stdin (); +} + +/* Process command line options and set some default options. */ +static void +parse_cmd_line (int argc, char **argv) { + read_option_args (argc, argv); + set_default_static_files (); +} + +static void +handle_signal_action (GO_UNUSED int sig_number) { + if (sig_number == SIGINT) + fprintf (stderr, "\nSIGINT caught!\n"); + else if (sig_number == SIGTERM) + fprintf (stderr, "\nSIGTERM caught!\n"); + else if (sig_number == SIGQUIT) + fprintf (stderr, "\nSIGQUIT caught!\n"); + else + fprintf (stderr, "\nSignal %d caught!\n", sig_number); + fprintf (stderr, "Closing GoAccess...\n"); + + if (conf.output_stdout && conf.real_time_html) + stop_ws_server (gwswriter, gwsreader); + conf.stop_processing = 1; +} + +static void +setup_thread_signals (void) { + struct sigaction act; + + act.sa_handler = handle_signal_action; + sigemptyset (&act.sa_mask); + act.sa_flags = 0; + + sigaction (SIGINT, &act, NULL); + sigaction (SIGTERM, &act, NULL); + sigaction (SIGQUIT, &act, NULL); + signal (SIGPIPE, SIG_IGN); + + /* Restore old signal mask for the main thread */ + pthread_sigmask (SIG_SETMASK, &oldset, NULL); +} + +static void +block_thread_signals (void) { + /* Avoid threads catching SIGINT/SIGPIPE/SIGTERM/SIGQUIT and handle them in + * main thread */ + sigset_t sigset; + sigemptyset (&sigset); + sigaddset (&sigset, SIGINT); + sigaddset (&sigset, SIGPIPE); + sigaddset (&sigset, SIGTERM); + sigaddset (&sigset, SIGQUIT); + pthread_sigmask (SIG_BLOCK, &sigset, &oldset); +} + +/* Initialize various types of data. */ +static Logs * +initializer (void) { + int i; + FILE *pipe = NULL; + Logs *logs; + + /* drop permissions right away */ + if (conf.username) + drop_permissions (); + + /* then initialize modules and set */ + gscroll.current = init_modules (); + /* setup to use the current locale */ + set_locale (); + + parse_browsers_file (); + +#ifdef HAVE_GEOLOCATION + init_geoip (); +#endif + + set_io (&pipe); + + /* init glog */ + if (!(logs = init_logs (conf.filenames_idx))) + FATAL (ERR_NO_DATA_PASSED); + + set_signal_data (logs); + + for (i = 0; i < logs->size; ++i) + if (logs->glog[i].props.filename[0] == '-' && logs->glog[i].props.filename[1] == '\0') + logs->glog[i].pipe = pipe; + + /* init parsing spinner */ + parsing_spinner = new_gspinner (); + parsing_spinner->processed = &(logs->processed); + parsing_spinner->filename = &(logs->filename); + + /* init reverse lookup thread */ + gdns_init (); + + /* init random number generator */ + srand (getpid ()); + init_pre_storage (logs); + + return logs; +} + +static char * +generate_fifo_name (void) { + char fname[RAND_FN]; + const char *tmp; + char *path; + size_t len; + + if ((tmp = getenv ("TMPDIR")) == NULL) + tmp = "/tmp"; + + memset (fname, 0, sizeof (fname)); + genstr (fname, RAND_FN - 1); + + len = snprintf (NULL, 0, "%s/goaccess_fifo_%s", tmp, fname) + 1; + path = xmalloc (len); + snprintf (path, len, "%s/goaccess_fifo_%s", tmp, fname); + + return path; +} + +static int +spawn_ws (void) { + gwswriter = new_gwswriter (); + gwsreader = new_gwsreader (); + + if (!conf.fifo_in) + conf.fifo_in = generate_fifo_name (); + if (!conf.fifo_out) + conf.fifo_out = generate_fifo_name (); + + /* open fifo for read */ + if ((gwsreader->fd = open_fifoout ()) == -1) { + LOG (("Unable to open FIFO for read.\n")); + return 1; + } + + if (conf.daemonize) + daemonize (); + + return 0; +} + +static void +set_standard_output (void) { + int html = 0; + + /* HTML */ + if (find_output_type (NULL, "html", 0) == 0 || conf.output_format_idx == 0) + html = 1; + + /* Spawn WebSocket server threads */ + if (html && conf.real_time_html) { + if (spawn_ws ()) + return; + } + setup_thread_signals (); + + /* Spawn progress spinner thread */ + ui_spinner_create (parsing_spinner); +} + +/* Set up curses. */ +static void +set_curses (Logs *logs, int *quit) { + const char *err_log = NULL; + + setup_thread_signals (); + set_input_opts (); + if (conf.no_color || has_colors () == FALSE) { + conf.color_scheme = NO_COLOR; + conf.no_color = 1; + } else { + start_color (); + } + init_colors (0); + init_windows (&header_win, &main_win); + set_curses_spinner (parsing_spinner); + + /* Display configuration dialog if missing formats and not piping data in */ + if (!conf.read_stdin && (verify_formats () || conf.load_conf_dlg)) { + refresh (); + *quit = render_confdlg (logs, parsing_spinner); + clear (); + } + /* Piping data in without log/date/time format */ + else if (conf.read_stdin && (err_log = verify_formats ())) { + FATAL ("%s", err_log); + } + /* straight parsing */ + else { + ui_spinner_create (parsing_spinner); + } +} + +/* Where all begins... */ +int +main (int argc, char **argv) { + Logs *logs = NULL; + int quit = 0, ret = 0; + + block_thread_signals (); + setup_sigsegv_handler (); + + /* command line/config options */ + verify_global_config (argc, argv); + parse_conf_file (&argc, &argv); + parse_cmd_line (argc, argv); + + logs = initializer (); + + /* ignore outputting, process only */ + if (conf.process_and_exit) { + } + /* set stdout */ + else if (conf.output_stdout) { + set_standard_output (); + } + /* set curses */ + else { + set_curses (logs, &quit); + } + + /* no log/date/time format set */ + if (quit) + goto clean; + + init_processing (); + + /* main processing event */ + time (&start_proc); + parsing_spinner->label = "PARSING"; + + if ((ret = parse_log (logs, 0))) { + end_spinner (); + goto clean; + } + + if (conf.stop_processing) + goto clean; + logs->offset = *logs->processed; + + pthread_mutex_lock (&parsing_spinner->mutex); + parsing_spinner->label = "RENDERING"; + pthread_mutex_unlock (&parsing_spinner->mutex); + + parse_initial_sort (); + allocate_holder (); + + end_spinner (); + time (&end_proc); + + set_accumulated_time (); + if (conf.process_and_exit) { + } + /* stdout */ + else if (conf.output_stdout) { + standard_output (logs); + } + /* curses */ + else { + curses_output (logs); + } + + /* clean */ +clean: + cleanup (ret); + + return ret ? EXIT_FAILURE : EXIT_SUCCESS; +} diff --git a/src/goaccess.h b/src/goaccess.h new file mode 100644 index 0000000000..627362388d --- /dev/null +++ b/src/goaccess.h @@ -0,0 +1,42 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef GOACCESS_H_INCLUDED +#define GOACCESS_H_INCLUDED + +#include "ui.h" + +#define RAND_FN 7 + 1 + +extern GSpinner *parsing_spinner; +extern int active_gdns; /* kill dns pthread flag */ + +void read_client (void *ptr_data); + +#endif diff --git a/src/gslist.c b/src/gslist.c new file mode 100644 index 0000000000..9698ef770c --- /dev/null +++ b/src/gslist.c @@ -0,0 +1,173 @@ +/** + * gslist.c -- A Singly link list implementation + * _______ _______ __ __ + * / ____/ | / / ___/____ _____/ /_____ / /_ + * / / __ | | /| / /\__ \/ __ \/ ___/ //_/ _ \/ __/ + * / /_/ / | |/ |/ /___/ / /_/ / /__/ ,< / __/ /_ + * \____/ |__/|__//____/\____/\___/_/|_|\___/\__/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include + +#include "gslist.h" +#include "gstorage.h" +#include "xmalloc.h" + +/* Instantiate a new Singly linked-list node. + * + * On error, aborts if node can't be malloc'd. + * On success, the GSLList node. */ +GSLList * +list_create (void *data) { + GSLList *node = xmalloc (sizeof (GSLList)); + node->data = data; + node->next = NULL; + + return node; +} + +/* Create and insert a node after a given node. + * + * On error, aborts if node can't be malloc'd. + * On success, the newly created node. */ +GSLList * +list_insert_append (GSLList *node, void *data) { + GSLList *newnode; + newnode = list_create (data); + newnode->next = node->next; + node->next = newnode; + + return newnode; +} + +/* Create and insert a node in front of the list. + * + * On error, aborts if node can't be malloc'd. + * On success, the newly created node. */ +GSLList * +list_insert_prepend (GSLList *list, void *data) { + GSLList *newnode; + newnode = list_create (data); + newnode->next = list; + + return newnode; +} + +/* Find a node given a pointer to a function that compares them. + * + * If comparison fails, NULL is returned. + * On success, the existing node is returned. */ +GSLList * +list_find (GSLList *node, int (*func) (void *, void *), void *data) { + while (node) { + if (func (node->data, data) > 0) + return node; + node = node->next; + } + + return NULL; +} + +GSLList * +list_copy (GSLList *node) { + GSLList *list = NULL; + + while (node) { + if (!list) + list = list_create (i322ptr ((*(uint32_t *) node->data))); + else + list = list_insert_prepend (list, i322ptr ((*(uint32_t *) node->data))); + node = node->next; + } + + return list; +} + +/* Remove all nodes from the list. + * + * On success, 0 is returned. */ +int +list_remove_nodes (GSLList *list) { + GSLList *tmp; + while (list != NULL) { + tmp = list->next; + if (list->data) + free (list->data); + free (list); + list = tmp; + } + + return 0; +} + +/* Remove the given node from the list. + * + * On error, 1 is returned. + * On success, 0 is returned. */ +int +list_remove_node (GSLList **list, GSLList *node) { + GSLList **current = list, *next = NULL; + for (; *current; current = &(*current)->next) { + if ((*current) != node) + continue; + + next = (*current)->next; + if ((*current)->data) + free ((*current)->data); + free (*current); + *current = next; + return 0; + } + return 1; +} + +/* Iterate over the single linked-list and call function pointer. + * + * If function pointer does not return 0, -1 is returned. + * On success, 0 is returned. */ +int +list_foreach (GSLList *node, int (*func) (void *, void *), void *user_data) { + while (node) { + if (func (node->data, user_data) != 0) + return -1; + node = node->next; + } + + return 0; +} + +/* Count the number of elements on the linked-list. + * + * On success, the number of elements is returned. */ +int +list_count (GSLList *node) { + int count = 0; + while (node != 0) { + count++; + node = node->next; + } + return count; +} diff --git a/src/gslist.h b/src/gslist.h new file mode 100644 index 0000000000..371987769c --- /dev/null +++ b/src/gslist.h @@ -0,0 +1,58 @@ +/** + * _______ _______ __ __ + * / ____/ | / / ___/____ _____/ /_____ / /_ + * / / __ | | /| / /\__ \/ __ \/ ___/ //_/ _ \/ __/ + * / /_/ / | |/ |/ /___/ / /_/ / /__/ ,< / __/ /_ + * \____/ |__/|__//____/\____/\___/_/|_|\___/\__/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef GSLIST_H_INCLUDED +#define GSLIST_H_INCLUDED + +/* Generic Single linked-list */ +typedef struct GSLList_ { + void *data; + struct GSLList_ *next; +} GSLList; + +#define GSLIST_FOREACH(node, data, code) { \ + GSLList *__tmp = node; \ + while (__tmp) { \ + (data) = __tmp->data; \ + code; \ + __tmp = __tmp->next; \ + }} + +/* single linked-list */ +GSLList *list_create (void *data); +GSLList *list_find (GSLList * node, int (*func) (void *, void *), void *data); +GSLList *list_insert_append (GSLList * node, void *data); +GSLList *list_insert_prepend (GSLList * list, void *data); +GSLList *list_copy (GSLList * node); +int list_count (GSLList * list); +int list_foreach (GSLList * node, int (*func) (void *, void *), void *user_data); +int list_remove_node (GSLList ** list, GSLList * node); +int list_remove_nodes (GSLList * list); + +#endif // for #ifndef GSLIST_H diff --git a/src/gstorage.c b/src/gstorage.c new file mode 100644 index 0000000000..e4cb9b4afc --- /dev/null +++ b/src/gstorage.c @@ -0,0 +1,1547 @@ +/** + * gstorage.c -- common storage handling + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if !defined __SUNPRO_C +#include +#endif +#include +#include + +#include "gstorage.h" + +#ifdef HAVE_GEOLOCATION +#include "geoip1.h" +#endif + +#include "browsers.h" +#include "commons.h" +#include "error.h" +#include "gkhash.h" +#include "opesys.h" +#include "ui.h" +#include "util.h" +#include "xmalloc.h" + +/* private prototypes */ +/* key/data generators for each module */ + +static int gen_visitor_key (GKeyData * kdata, GLogItem * logitem); +static int gen_404_key (GKeyData * kdata, GLogItem * logitem); +static int gen_browser_key (GKeyData * kdata, GLogItem * logitem); +static int gen_host_key (GKeyData * kdata, GLogItem * logitem); +static int gen_keyphrase_key (GKeyData * kdata, GLogItem * logitem); +static int gen_os_key (GKeyData * kdata, GLogItem * logitem); +static int gen_vhost_key (GKeyData * kdata, GLogItem * logitem); +static int gen_remote_user_key (GKeyData * kdata, GLogItem * logitem); +static int gen_cache_status_key (GKeyData * kdata, GLogItem * logitem); +static int gen_referer_key (GKeyData * kdata, GLogItem * logitem); +static int gen_ref_site_key (GKeyData * kdata, GLogItem * logitem); +static int gen_request_key (GKeyData * kdata, GLogItem * logitem); +static int gen_static_request_key (GKeyData * kdata, GLogItem * logitem); +static int gen_status_code_key (GKeyData * kdata, GLogItem * logitem); +static int gen_visit_time_key (GKeyData * kdata, GLogItem * logitem); +#ifdef HAVE_GEOLOCATION +static int gen_geolocation_key (GKeyData * kdata, GLogItem * logitem); +static int gen_asn_key (GKeyData * kdata, GLogItem * logitem); +#endif +/* UMS */ +static int gen_mime_type_key (GKeyData * kdata, GLogItem * logitem); +static int gen_tls_type_key (GKeyData * kdata, GLogItem * logitem); + +/* insertion metric routines */ +static void insert_data (GModule module, GKeyData * kdata); +static void insert_rootmap (GModule module, GKeyData * kdata); +static void insert_root (GModule module, GKeyData * kdata); +static void insert_hit (GModule module, GKeyData * kdata); +static void insert_visitor (GModule module, GKeyData * kdata); +static void insert_bw (GModule module, GKeyData * kdata, uint64_t size); +static void insert_cumts (GModule module, GKeyData * kdata, uint64_t ts); +static void insert_maxts (GModule module, GKeyData * kdata, uint64_t ts); +static void insert_method (GModule module, GKeyData * kdata, const char *data); +static void insert_protocol (GModule module, GKeyData * kdata, const char *data); +static void insert_agent (GModule module, GKeyData * kdata, uint32_t agent_nkey); + +/* *INDENT-OFF* */ +const httpmethods http_methods[] = { + { "OPTIONS" , 7 } , + { "GET" , 3 } , + { "HEAD" , 4 } , + { "POST" , 4 } , + { "PUT" , 3 } , + { "DELETE" , 6 } , + { "TRACE" , 5 } , + { "CONNECT" , 7 } , + { "PATCH" , 5 } , + { "SEARCH" , 6 } , + /* WebDav */ + { "PROPFIND" , 8 } , + { "PROPPATCH" , 9 } , + { "MKCOL" , 5 } , + { "COPY" , 4 } , + { "MOVE" , 4 } , + { "LOCK" , 4 } , + { "UNLOCK" , 6 } , + { "VERSION-CONTROL" , 15 } , + { "REPORT" , 6 } , + { "CHECKOUT" , 8 } , + { "CHECKIN" , 7 } , + { "UNCHECKOUT" , 10 } , + { "MKWORKSPACE" , 11 } , + { "UPDATE" , 6 } , + { "LABEL" , 5 } , + { "MERGE" , 5 } , + { "BASELINE-CONTROL" , 16 } , + { "MKACTIVITY" , 10 } , + { "ORDERPATCH" , 10 } , +}; +const size_t http_methods_len = ARRAY_SIZE (http_methods); + +const httpprotocols http_protocols[] = { + { "HTTP/1.0" , 8 } , + { "HTTP/1.1" , 8 } , + { "HTTP/2" , 6 } , + { "HTTP/3" , 6 } , +}; +const size_t http_protocols_len = ARRAY_SIZE (http_protocols); + +static const GParse paneling[] = { + { + VISITORS, + gen_visitor_key, + insert_data, + NULL, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + NULL, + NULL, + NULL, + }, { + REQUESTS, + gen_request_key, + insert_data, + NULL, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + insert_method, + insert_protocol, + NULL, + }, { + REQUESTS_STATIC, + gen_static_request_key, + insert_data, + NULL, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + insert_method, + insert_protocol, + NULL, + }, { + NOT_FOUND, + gen_404_key, + insert_data, + NULL, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + insert_method, + insert_protocol, + NULL, + }, { + HOSTS, + gen_host_key, + insert_data, + NULL, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + NULL, + NULL, + insert_agent, + }, { + OS, + gen_os_key, + insert_data, + insert_rootmap, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + insert_method, + insert_protocol, + NULL, + }, { + BROWSERS, + gen_browser_key, + insert_data, + insert_rootmap, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + NULL, + NULL, + NULL, + }, { + REFERRERS, + gen_referer_key, + insert_data, + NULL, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + NULL, + NULL, + NULL, + }, { + REFERRING_SITES, + gen_ref_site_key, + insert_data, + NULL, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + NULL, + NULL, + NULL, + }, { + KEYPHRASES, + gen_keyphrase_key, + insert_data, + NULL, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + NULL, + NULL, + NULL, + }, +#ifdef HAVE_GEOLOCATION + { + GEO_LOCATION, + gen_geolocation_key, + insert_data, + insert_rootmap, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + NULL, + NULL, + NULL, + }, + { + ASN, + gen_asn_key, + insert_data, + NULL, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + NULL, + NULL, + NULL, + }, +#endif + { + STATUS_CODES, + gen_status_code_key, + insert_data, + insert_rootmap, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + NULL, + NULL, + NULL, + }, { + VISIT_TIMES, + gen_visit_time_key, + insert_data, + NULL, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + NULL, + NULL, + NULL, + }, { + VIRTUAL_HOSTS, + gen_vhost_key, + insert_data, + NULL, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + NULL, + NULL, + NULL, + }, { + REMOTE_USER, + gen_remote_user_key, + insert_data, + NULL, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + NULL, + NULL, + NULL, + }, { + CACHE_STATUS, + gen_cache_status_key, + insert_data, + NULL, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + NULL, + NULL, + NULL, + }, { + MIME_TYPE, + gen_mime_type_key, + insert_data, + insert_rootmap, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + NULL, /*method*/ + NULL, /*protocol*/ + NULL, /*agent*/ + }, { + TLS_TYPE, + gen_tls_type_key, + insert_data, + insert_rootmap, + insert_hit, + insert_visitor, + insert_bw, + insert_cumts, + insert_maxts, + NULL, + NULL, + NULL, + }, +}; +/* *INDENT-ON* */ + +/* Initialize a new GKeyData instance */ +static void +new_modulekey (GKeyData *kdata) { + GKeyData key = { + .data = NULL, + .data_nkey = 0, + .root = NULL, + .dhash = 0, + .rhash = 0, + .root_nkey = 0, + .uniq_key = NULL, + .uniq_nkey = 0, + }; + *kdata = key; +} + +/* Get a panel from the GParse structure given a module. + * + * On error, or if not found, NULL is returned. + * On success, the panel value is returned. */ +static const GParse * +panel_lookup (GModule module) { + int i, num_panels = ARRAY_SIZE (paneling); + + for (i = 0; i < num_panels; i++) { + if (paneling[i].module == module) + return &paneling[i]; + } + return NULL; +} + +/* Allocate memory for a new GMetrics instance. + * + * On success, the newly allocated GMetrics is returned . */ +GMetrics * +new_gmetrics (void) { + GMetrics *metrics = xcalloc (1, sizeof (GMetrics)); + + return metrics; +} + +/* Free memory of a GMetrics object */ +void +free_gmetrics (GMetrics *metric) { + if (metric == NULL) + return; + + free (metric->data); + free (metric->method); + free (metric->protocol); + free (metric); +} + +/* Get the module string value given a metric enum value. + * + * On error, NULL is returned. + * On success, the string module value is returned. */ +const char * +get_mtr_str (GSMetric metric) { + /* String modules to enumerated modules */ + static const GEnum enum_metrics[] = { + {"MTRC_KEYMAP", MTRC_KEYMAP}, + {"MTRC_ROOTMAP", MTRC_ROOTMAP}, + {"MTRC_DATAMAP", MTRC_DATAMAP}, + {"MTRC_UNIQMAP", MTRC_UNIQMAP}, + {"MTRC_ROOT", MTRC_ROOT}, + {"MTRC_HITS", MTRC_HITS}, + {"MTRC_VISITORS", MTRC_VISITORS}, + {"MTRC_BW", MTRC_BW}, + {"MTRC_CUMTS", MTRC_CUMTS}, + {"MTRC_MAXTS", MTRC_MAXTS}, + {"MTRC_METHODS", MTRC_METHODS}, + {"MTRC_PROTOCOLS", MTRC_PROTOCOLS}, + {"MTRC_AGENTS", MTRC_AGENTS}, + {"MTRC_METADATA", MTRC_METADATA}, + {"MTRC_UNIQUE_KEYS", MTRC_UNIQUE_KEYS}, + {"MTRC_AGENT_KEYS", MTRC_AGENT_KEYS}, + {"MTRC_AGENT_VALS", MTRC_AGENT_VALS}, + {"MTRC_CNT_VALID", MTRC_CNT_VALID}, + {"MTRC_CNT_BW", MTRC_CNT_BW}, + }; + return enum2str (enum_metrics, ARRAY_SIZE (enum_metrics), metric); +} + +/* Allocate space off the heap to store a uint32_t. + * + * On success, the newly allocated pointer is returned . */ +uint32_t * +i322ptr (uint32_t val) { + uint32_t *ptr = xmalloc (sizeof (uint32_t)); + *ptr = val; + + return ptr; +} + +/* Allocate space off the heap to store a uint64_t. + * + * On success, the newly allocated pointer is returned . */ +uint64_t * +uint642ptr (uint64_t val) { + uint64_t *ptr = xmalloc (sizeof (uint64_t)); + *ptr = val; + + return ptr; +} + +/* Set the module totals to calculate percentages. */ +void +set_module_totals (GPercTotals *totals) { + totals->bw = ht_sum_bw (); + totals->hits = ht_sum_valid (); + totals->visitors = ht_get_size_uniqmap (VISITORS); +} + +/* Set numeric metrics for each request given raw data. + * + * On success, numeric metrics are set into the given structure. */ +void +set_data_metrics (GMetrics *ometrics, GMetrics **nmetrics, GPercTotals totals) { + GMetrics *metrics; + + /* determine percentages for certain fields */ + float hits_perc = get_percentage (totals.hits, ometrics->hits); + float visitors_perc = get_percentage (totals.visitors, ometrics->visitors); + float bw_perc = get_percentage (totals.bw, ometrics->bw.nbw); + + metrics = new_gmetrics (); + + /* basic fields */ + metrics->id = ometrics->id; + metrics->hits = ometrics->hits; + metrics->visitors = ometrics->visitors; + + /* percentage fields */ + metrics->hits_perc = hits_perc < 0 ? 0 : hits_perc; + metrics->bw_perc = bw_perc < 0 ? 0 : bw_perc; + metrics->visitors_perc = visitors_perc < 0 ? 0 : visitors_perc; + + /* bandwidth field */ + metrics->bw.nbw = ometrics->bw.nbw; + + /* time served fields */ + if (conf.serve_usecs && ometrics->hits > 0) { + metrics->avgts.nts = ometrics->avgts.nts; + metrics->cumts.nts = ometrics->cumts.nts; + metrics->maxts.nts = ometrics->maxts.nts; + } + + /* method field */ + if (conf.append_method && ometrics->method) + metrics->method = ometrics->method; + + /* protocol field */ + if (conf.append_protocol && ometrics->protocol) + metrics->protocol = ometrics->protocol; + + /* data field */ + metrics->data = ometrics->data; + + *nmetrics = metrics; +} + +/* Increment the overall bandwidth. */ +static void +count_bw (int numdate, uint64_t resp_size) { + ht_inc_cnt_bw (numdate, resp_size); +} + +/* Keep track of all invalid log strings. */ +static void +count_invalid (GLog *glog, GLogItem *logitem, const char *line) { + glog->invalid++; + ht_inc_cnt_overall ("failed_requests", 1); + + if (conf.invalid_requests_log) { + LOG_INVALID (("%s", line)); + } + + if (logitem->errstr && glog->log_erridx < MAX_LOG_ERRORS) { + glog->errors[glog->log_erridx++] = xstrdup (logitem->errstr); + } +} + +/* Count down the number of invalids hits. + * Note: Upon performing a log test, invalid hits are counted, since + * no valid records were found, then we count down by the number of + * tests ran. +*/ +void +uncount_invalid (GLog *glog) { + if (glog->invalid > conf.num_tests) + glog->invalid -= conf.num_tests; + else + glog->invalid = 0; +} + +/* Count down the number of processed hits. + * Note: Upon performing a log test, processed hits are counted, since + * no valid records were found, then we count down by the number of + * tests ran. +*/ +void +uncount_processed (GLog *glog) { + lock_spinner (); + if (glog->processed > conf.num_tests) + glog->processed -= conf.num_tests; + else + glog->processed = 0; + unlock_spinner (); +} + +/* Keep track of all valid log strings. */ +static void +count_valid (int numdate) { + lock_spinner (); + ht_inc_cnt_valid (numdate, 1); + unlock_spinner (); +} + +/* Keep track of all valid and processed log strings. */ +void +count_process (GLog *glog) { + __sync_add_and_fetch (&glog->processed, 1); + lock_spinner (); + ht_inc_cnt_overall ("total_requests", 1); + unlock_spinner (); +} + +void +count_process_and_invalid (GLog *glog, GLogItem *logitem, const char *line) { + count_process (glog); + count_invalid (glog, logitem, line); +} + +/* Keep track of all excluded log strings (IPs). + * + * If IP not range, 1 is returned. + * If IP is excluded, 0 is returned. */ +int +excluded_ip (GLogItem *logitem) { + if (conf.ignore_ip_idx && ip_in_range (logitem->host)) { + ht_inc_cnt_overall ("excluded_ip", 1); + return 0; + } + return 1; +} + +/* A wrapper function to insert a data keymap string key. + * + * If the given key exists, its value is returned. + * On error, 0 is returned. + * On success the value of the key inserted is returned */ +static int +insert_dkeymap (GModule module, GKeyData *kdata) { + return ht_insert_keymap (module, kdata->numdate, kdata->dhash, &kdata->cdnkey); +} + +/* A wrapper function to insert a root keymap string key. + * + * If the given key exists, its value is returned. + * On error, 0 is returned. + * On success the value of the key inserted is returned */ +static int +insert_rkeymap (GModule module, GKeyData *kdata) { + return ht_insert_keymap (module, kdata->numdate, kdata->rhash, &kdata->crnkey); +} + +/* A wrapper function to insert a datamap uint32_t key and string value. */ +static void +insert_data (GModule module, GKeyData *kdata) { + ht_insert_datamap (module, kdata->numdate, kdata->data_nkey, kdata->data, kdata->cdnkey); +} + +/* A wrapper function to insert a uniqmap string key. + * + * If the given key exists, 0 is returned. + * On error, 0 is returned. + * On success the value of the key inserted is returned */ +static int +insert_uniqmap (GModule module, GKeyData *kdata, uint32_t uniq_nkey) { + return ht_insert_uniqmap (module, kdata->numdate, kdata->data_nkey, uniq_nkey); +} + +/* A wrapper function to insert a rootmap uint32_t key from the keymap + * store mapped to its string value. */ +static void +insert_rootmap (GModule module, GKeyData *kdata) { + ht_insert_rootmap (module, kdata->numdate, kdata->root_nkey, kdata->root, kdata->crnkey); +} + +/* A wrapper function to insert a data uint32_t key mapped to the + * corresponding uint32_t root key. */ +static void +insert_root (GModule module, GKeyData *kdata) { + ht_insert_root (module, kdata->numdate, kdata->data_nkey, kdata->root_nkey, kdata->cdnkey, + kdata->crnkey); +} + +/* A wrapper function to increase hits counter from an uint32_t key. */ +static void +insert_hit (GModule module, GKeyData *kdata) { + ht_insert_hits (module, kdata->numdate, kdata->data_nkey, 1, kdata->cdnkey); + ht_insert_meta_data (module, kdata->numdate, "hits", 1); +} + +/* A wrapper function to increase visitors counter from an uint32_t + * key. */ +static void +insert_visitor (GModule module, GKeyData *kdata) { + ht_insert_visitor (module, kdata->numdate, kdata->data_nkey, 1, kdata->cdnkey); + ht_insert_meta_data (module, kdata->numdate, "visitors", 1); +} + +/* A wrapper function to increases bandwidth counter from an uint32_t + * key. */ +static void +insert_bw (GModule module, GKeyData *kdata, uint64_t size) { + ht_insert_bw (module, kdata->numdate, kdata->data_nkey, size, kdata->cdnkey); + ht_insert_meta_data (module, kdata->numdate, "bytes", size); +} + +/* A wrapper call to increases cumulative time served counter + * from an uint32_t key. */ +static void +insert_cumts (GModule module, GKeyData *kdata, uint64_t ts) { + ht_insert_cumts (module, kdata->numdate, kdata->data_nkey, ts, kdata->cdnkey); + ht_insert_meta_data (module, kdata->numdate, "cumts", ts); +} + +/* A wrapper call to insert the maximum time served counter from + * an uint32_t key. */ +static void +insert_maxts (GModule module, GKeyData *kdata, uint64_t ts) { + ht_insert_maxts (module, kdata->numdate, kdata->data_nkey, ts, kdata->cdnkey); + ht_insert_meta_data (module, kdata->numdate, "maxts", ts); +} + +static void +insert_method (GModule module, GKeyData *kdata, const char *data) { + ht_insert_method (module, kdata->numdate, kdata->data_nkey, data ? data : "---", kdata->cdnkey); +} + +/* A wrapper call to insert a method given an uint32_t key and string + * value. */ +static void +insert_protocol (GModule module, GKeyData *kdata, const char *data) { + ht_insert_protocol (module, kdata->numdate, kdata->data_nkey, data ? data : "---", kdata->cdnkey); +} + +/* A wrapper call to insert an agent for a hostname given an uint32_t + * key and uint32_t value. */ +static void +insert_agent (GModule module, GKeyData *kdata, uint32_t agent_nkey) { + ht_insert_agent (module, kdata->numdate, kdata->data_nkey, agent_nkey); +} + +/* The following generates a unique key to identity unique requests. + * The key is made out of the actual request, and if available, the + * method and the protocol. Note that for readability, doing a simple + * snprintf/sprintf should suffice, however, memcpy is the fastest + * solution + * + * On success the new unique request key is returned */ +static char * +gen_unique_req_key (GLogItem *logitem) { + char *key = NULL; + size_t s1 = 0, s2 = 0, s3 = 0, nul = 1, sep = 0; + + /* nothing to do */ + if (!conf.append_method && !conf.append_protocol) + return xstrdup (logitem->req); + /* still nothing to do */ + if (!logitem->method && !logitem->protocol) + return xstrdup (logitem->req); + + s1 = strlen (logitem->req); + if (logitem->method && conf.append_method) { + s2 = strlen (logitem->method); + nul++; + } + if (logitem->protocol && conf.append_protocol) { + s3 = strlen (logitem->protocol); + nul++; + } + + /* includes terminating null */ + key = xcalloc (s1 + s2 + s3 + nul, sizeof (char)); + /* append request */ + memcpy (key, logitem->req, s1); + + if (logitem->method && conf.append_method) { + key[s1] = '|'; + sep++; + memcpy (key + s1 + sep, logitem->method, s2 + 1); + } + if (logitem->protocol && conf.append_protocol) { + key[s1 + s2 + sep] = '|'; + sep++; + memcpy (key + s1 + s2 + sep, logitem->protocol, s3 + 1); + } + + return key; +} + +/* Append the query string to the request, and therefore, it modifies + * the original logitem->req */ +static void +append_query_string (char **req, const char *qstr) { + char *r; + size_t s1, s2, qm = 0; + + s1 = strlen (*req); + s2 = strlen (qstr); + + /* add '?' between the URL and the query string */ + if (*qstr != '?') + qm = 1; + + r = xmalloc (s1 + s2 + qm + 1); + memcpy (r, *req, s1); + if (qm) + r[s1] = '?'; + memcpy (r + s1 + qm, qstr, s2 + 1); + + free (*req); + *req = r; +} + +/* A wrapper to assign the given data key and the data item to the key + * data structure */ +static void +get_kdata (GKeyData *kdata, const char *data_key, const char *data) { + /* inserted in datamap */ + kdata->data = data; + /* inserted in keymap */ + kdata->dhash = djb2 ((const unsigned char *) data_key); +} + +/* A wrapper to assign the given data key and the data item to the key + * data structure */ +static void +get_kroot (GKeyData *kdata, const char *root_key, const char *root) { + /* inserted in datamap */ + kdata->root = root; + /* inserted in keymap */ + kdata->rhash = djb2 ((const unsigned char *) root_key); +} + +/* Generate a visitor's key given the date specificity. For instance, + * if the specificity is set to hours, then a generated key would + * look like: 03/Jan/2016:09 */ +static void +set_spec_visitor_key (char **fdate, const char *ftime) { + size_t dlen = 0, tlen = 0, idx = 0; + char *key = NULL, *tkey = NULL, *pch = NULL; + + tkey = xstrdup (ftime); + if (conf.date_spec_hr == 1 && (pch = strchr (tkey, ':')) && (pch - tkey) > 0) + *pch = '\0'; + else if (conf.date_spec_hr == 2 && (pch = strrchr (tkey, ':')) && (pch - tkey) > 0) { + *pch = '\0'; + if ((pch = strchr (tkey, ':')) && (idx = pch - tkey)) + memmove (&tkey[idx], &tkey[idx + 1], strlen (tkey) - idx); + } + + dlen = strlen (*fdate); + tlen = strlen (tkey); + + key = xmalloc (dlen + tlen + 1); + memcpy (key, *fdate, dlen); + memcpy (key + dlen, tkey, tlen + 1); + + free (*fdate); + free (tkey); + *fdate = key; +} + +/* Generate a unique key for the visitors panel from the given logitem + * structure and assign it to the output key data structure. + * + * On error, or if no date is found, 1 is returned. + * On success, the date key is assigned to our key data structure. + */ +static int +gen_visitor_key (GKeyData *kdata, GLogItem *logitem) { + if (!logitem->date || !logitem->time) + return 1; + + /* Append time specificity to date */ + if (conf.date_spec_hr) + set_spec_visitor_key (&logitem->date, logitem->time); + + get_kdata (kdata, logitem->date, logitem->date); + kdata->numdate = logitem->numdate; + + return 0; +} + +/* Generate a unique key for the requests panel from the given logitem + * structure and assign it to out key data structure. + * + * On success, the generated request key is assigned to our key data + * structure. + */ +static int +gen_req_key (GKeyData *kdata, GLogItem *logitem) { + if (!logitem->req) + return 1; + + if (logitem->qstr) + append_query_string (&logitem->req, logitem->qstr); + logitem->req_key = gen_unique_req_key (logitem); + + get_kdata (kdata, logitem->req_key, logitem->req); + kdata->numdate = logitem->numdate; + + return 0; +} + +/* A wrapper to generate a unique key for the request panel. + * + * On error, or if the request is static or a 404, 1 is returned. + * On success, the generated request key is assigned to our key data + * structure. + */ +static int +gen_request_key (GKeyData *kdata, GLogItem *logitem) { + if (!logitem->req || logitem->is_404 || logitem->is_static) + return 1; + + return gen_req_key (kdata, logitem); +} + +/* A wrapper to generate a unique key for the request panel. + * + * On error, or if the request is not a 404, 1 is returned. + * On success, the generated request key is assigned to our key data + * structure. */ +static int +gen_404_key (GKeyData *kdata, GLogItem *logitem) { + if (logitem->req && logitem->is_404) + return gen_req_key (kdata, logitem); + return 1; +} + +/* A wrapper to generate a unique key for the request panel. + * + * On error, or if the request is not a static request, 1 is returned. + * On success, the generated request key is assigned to our key data + * structure. */ +static int +gen_static_request_key (GKeyData *kdata, GLogItem *logitem) { + if (logitem->req && logitem->is_static) + return gen_req_key (kdata, logitem); + return 1; +} + +/* A wrapper to generate a unique key for the virtual host panel. + * + * On error, 1 is returned. + * On success, the generated vhost key is assigned to our key data + * structure. */ +static int +gen_vhost_key (GKeyData *kdata, GLogItem *logitem) { + if (!logitem->vhost) + return 1; + + get_kdata (kdata, logitem->vhost, logitem->vhost); + kdata->numdate = logitem->numdate; + + return 0; +} + +/* A wrapper to generate a unique key for the virtual host panel. + * + * On error, 1 is returned. + * On success, the generated userid key is assigned to our key data + * structure. */ +static int +gen_remote_user_key (GKeyData *kdata, GLogItem *logitem) { + if (!logitem->userid) + return 1; + + get_kdata (kdata, logitem->userid, logitem->userid); + kdata->numdate = logitem->numdate; + + return 0; +} + +/* A wrapper to generate a unique key for the cache status panel. + * + * On error, 1 is returned. + * On success, the generated cache status key is assigned to our key data + * structure. */ +static int +gen_cache_status_key (GKeyData *kdata, GLogItem *logitem) { + if (!logitem->cache_status) + return 1; + + get_kdata (kdata, logitem->cache_status, logitem->cache_status); + kdata->numdate = logitem->numdate; + + return 0; +} + +/* A wrapper to generate a unique key for the hosts panel. + * + * On error, 1 is returned. + * On success, the generated host key is assigned to our key data + * structure. */ +static int +gen_host_key (GKeyData *kdata, GLogItem *logitem) { + if (!logitem->host) + return 1; + + get_kdata (kdata, logitem->host, logitem->host); + kdata->numdate = logitem->numdate; + + return 0; +} + +/* Add browsers/OSs our logitem structure and reuse crawlers if applicable. */ +void +set_browser_os (GLogItem *logitem) { + char *a1 = xstrdup (logitem->agent), *a2 = xstrdup (logitem->agent); + char browser_type[BROWSER_TYPE_LEN] = ""; + char os_type[OPESYS_TYPE_LEN] = ""; + + logitem->browser = verify_browser (a1, browser_type); + logitem->browser_type = xstrdup (browser_type); + + if (!strncmp (logitem->browser_type, "Crawlers", 9)) { + logitem->os = xstrdup (logitem->browser); + logitem->os_type = xstrdup (browser_type); + } else { + logitem->os = verify_os (a2, os_type); + logitem->os_type = xstrdup (os_type); + } + + free (a1); + free (a2); +} + +/* Generate a browser unique key for the browser's panel given a user + * agent and assign the browser type/category as a root element. + * + * On error, 1 is returned. + * On success, the generated browser key is assigned to our key data + * structure. */ +static int +gen_browser_key (GKeyData *kdata, GLogItem *logitem) { + if (logitem->agent == NULL || *logitem->agent == '\0') + return 1; + if (logitem->browser == NULL || *logitem->browser == '\0') + return 1; + + /* e.g., Firefox 11.12 */ + get_kdata (kdata, logitem->browser, logitem->browser); + + /* Firefox */ + get_kroot (kdata, logitem->browser_type, logitem->browser_type); + kdata->numdate = logitem->numdate; + + return 0; +} + +/* Generate an operating system unique key for the OS' panel given a + * user agent and assign the OS type/category as a root element. + * + * On error, 1 is returned. + * On success, the generated OS key is assigned to our key data + * structure. */ +static int +gen_os_key (GKeyData *kdata, GLogItem *logitem) { + if (logitem->agent == NULL || *logitem->agent == '\0') + return 1; + if (logitem->os == NULL || *logitem->os == '\0') + return 1; + + /* e.g., GNU+Linux,Ubuntu 10.12 */ + get_kdata (kdata, logitem->os, logitem->os); + + /* GNU+Linux */ + get_kroot (kdata, logitem->os_type, logitem->os_type); + kdata->numdate = logitem->numdate; + + return 0; +} + +/* Determine if the given token starts with a valid MIME major type. + * + * If not valid, NULL is returned. + * If valid, the appropriate constant string is returned. */ +static const char * +extract_mimemajor (const char *token) { + const char *lookfor; + + /* official IANA registries as per https://www.iana.org/assignments/media-types/ */ + + if ((lookfor = "application", !strncmp (token, lookfor, 11)) || + (lookfor = "audio", !strncmp (token, lookfor, 5)) || + (lookfor = "font", !strncmp (token, lookfor, 4)) || + /* unlikely */ + (lookfor = "example", !strncmp (token, lookfor, 7)) || + (lookfor = "image", !strncmp (token, lookfor, 5)) || + /* unlikely */ + (lookfor = "message", !strncmp (token, lookfor, 7)) || + (lookfor = "model", !strncmp (token, lookfor, 5)) || + (lookfor = "multipart", !strncmp (token, lookfor, 9)) || + (lookfor = "text", !strncmp (token, lookfor, 4)) || + (lookfor = "video", !strncmp (token, lookfor, 5)) + ) + return lookfor; + return NULL; +} + +/* UMS: generate an Mime-Type unique key + * + * On error, 1 is returned. + * On success, the generated key is assigned to our key data structure. + */ +static int +gen_mime_type_key (GKeyData *kdata, GLogItem *logitem) { + const char *major = NULL; + + if (!logitem->mime_type) + return 1; + + /* redirects and the like only register as "-", ignore those */ + major = extract_mimemajor (logitem->mime_type); + if (!major) + return 1; + + get_kdata (kdata, logitem->mime_type, logitem->mime_type); + kdata->numdate = logitem->numdate; + + get_kroot (kdata, major, major); + + return 0; +} + +/* Determine if the given token starts with the usual TLS/SSL result string. + * + * If not valid, NULL is returned. + * If valid, the appropriate constant string is returned. */ +static const char * +extract_tlsmajor (const char *token) { + const char *lookfor; + + if ((lookfor = "SSLv3", !strncmp (token, lookfor, 5)) || + (lookfor = "TLSv1.1", !strncmp (token, lookfor, 7)) || + (lookfor = "TLSv1.2", !strncmp (token, lookfor, 7)) || + (lookfor = "TLSv1.3", !strncmp (token, lookfor, 7)) || + (lookfor = "TLS1.1", !strncmp (token, lookfor, 6)) || + (lookfor = "TLS1.2", !strncmp (token, lookfor, 6)) || + (lookfor = "TLS1.3", !strncmp (token, lookfor, 6)) || + /* Nope, it's not 1.0 */ + (lookfor = "TLSv1", !strncmp (token, lookfor, 5)) || + (lookfor = "TLS1", !strncmp (token, lookfor, 4))) + return lookfor; + return NULL; +} + +/* UMS: generate a TLS settings unique key + * + * On error, 1 is returned. + * On success, the generated key is assigned to our key data structure. + */ +static int +gen_tls_type_key (GKeyData *kdata, GLogItem *logitem) { + const char *tls; + size_t tlen = 0, clen = 0; + + if (!logitem->tls_type) + return 1; + + /* '-' means no TLS at all, just ignore for the panel? */ + tls = extract_tlsmajor (logitem->tls_type); + + if (!tls) + return 1; + + kdata->numdate = logitem->numdate; + if (!logitem->tls_cypher) { + get_kroot (kdata, tls, tls); + get_kdata (kdata, tls, tls); + return 0; + } + + clen = strlen (logitem->tls_cypher); + tlen = strlen (tls); + + logitem->tls_type_cypher = xmalloc (tlen + clen + 2); + memcpy (logitem->tls_type_cypher, tls, tlen); + logitem->tls_type_cypher[tlen] = '/'; + /* includes terminating null */ + memcpy (logitem->tls_type_cypher + tlen + 1, logitem->tls_cypher, clen + 1); + + get_kdata (kdata, logitem->tls_type_cypher, logitem->tls_type_cypher); + get_kroot (kdata, tls, tls); + + return 0; +} + + +/* A wrapper to generate a unique key for the referrers panel. + * + * On error, 1 is returned. + * On success, the generated referrer key is assigned to our key data + * structure. */ +static int +gen_referer_key (GKeyData *kdata, GLogItem *logitem) { + if (!logitem->ref) + return 1; + + get_kdata (kdata, logitem->ref, logitem->ref); + kdata->numdate = logitem->numdate; + + return 0; +} + +/* A wrapper to generate a unique key for the referring sites panel. + * + * On error, 1 is returned. + * On success, the generated referring site key is assigned to our key data + * structure. */ +static int +gen_ref_site_key (GKeyData *kdata, GLogItem *logitem) { + if (logitem->site[0] == '\0') + return 1; + + get_kdata (kdata, logitem->site, logitem->site); + kdata->numdate = logitem->numdate; + + return 0; +} + +/* A wrapper to generate a unique key for the keyphrases panel. + * + * On error, 1 is returned. + * On success, the generated keyphrase key is assigned to our key data + * structure. */ +static int +gen_keyphrase_key (GKeyData *kdata, GLogItem *logitem) { + if (!logitem->keyphrase) + return 1; + + get_kdata (kdata, logitem->keyphrase, logitem->keyphrase); + kdata->numdate = logitem->numdate; + + return 0; +} + +#ifdef HAVE_GEOLOCATION +/* Extract geolocation for the given host. + * + * On error, 1 is returned. + * On success, the extracted continent and country are set and 0 is + * returned. */ +static int +extract_geolocation (GLogItem *logitem, char *continent, char *country) { + if (!is_geoip_resource ()) + return 1; + + geoip_get_country (logitem->host, country, logitem->type_ip); + geoip_get_continent (logitem->host, continent, logitem->type_ip); + + return 0; +} +#endif + +/* A wrapper to generate a unique key for the geolocation panel. + * + * On error, 1 is returned. + * On success, the generated geolocation key is assigned to our key + * data structure. */ +#ifdef HAVE_GEOLOCATION +static int +gen_geolocation_key (GKeyData *kdata, GLogItem *logitem) { + char continent[CONTINENT_LEN] = ""; + char country[COUNTRY_LEN] = ""; + + if (extract_geolocation (logitem, continent, country) == 1) + return 1; + + if (country[0] != '\0') + logitem->country = xstrdup (country); + + if (continent[0] != '\0') + logitem->continent = xstrdup (continent); + + get_kdata (kdata, logitem->country, logitem->country); + get_kroot (kdata, logitem->continent, logitem->continent); + kdata->numdate = logitem->numdate; + + return 0; +} + +/* A wrapper to generate a unique key for the ASN panel. + * + * On error, 1 is returned. + * On success, the generated keyphrase key is assigned to our key data + * structure. */ +static int +gen_asn_key (GKeyData *kdata, GLogItem *logitem) { + char asn[ASN_LEN] = ""; + + if (!is_geoip_resource ()) + return 1; + + geoip_asn (logitem->host, asn); + + if (asn[0] != '\0') + logitem->asn = xstrdup (asn); + + get_kdata (kdata, logitem->asn, logitem->asn); + kdata->numdate = logitem->numdate; + + return 0; +} +#endif + +/* A wrapper to generate a unique key for the status code panel. + * + * On error, 1 is returned. + * On success, the generated status code key is assigned to our key + * data structure. */ +static int +gen_status_code_key (GKeyData *kdata, GLogItem *logitem) { + const char *status = NULL, *type = NULL; + + if (logitem->status == -1) + return 1; + + status = verify_status_code (logitem->status); + type = verify_status_code_type (logitem->status); + + get_kdata (kdata, status, status); + get_kroot (kdata, type, type); + kdata->numdate = logitem->numdate; + + return 0; +} + +/* Given a time string containing at least %H:%M, extract either the + * tenth of a minute or an hour. + * + * On error, the given string is not modified. + * On success, the conf specificity is extracted. */ +static void +parse_time_specificity_string (char *hmark, char *ftime) { + /* tenth of a minute specificity - e.g., 18:2 */ + if (conf.hour_spec_min && hmark[1] != '\0') { + hmark[2] = '\0'; + return; + } + + /* hour specificity (default) */ + if ((hmark - ftime) > 0) + *hmark = '\0'; +} + +/* A wrapper to generate a unique key for the time distribution panel. + * + * On error, 1 is returned. + * On success, the generated time key is assigned to our key data + * structure. */ +static int +gen_visit_time_key (GKeyData *kdata, GLogItem *logitem) { + char *hmark = NULL; + if (!logitem->time) + return 1; + + /* it must be a string containing the hour. */ + if ((hmark = strchr (logitem->time, ':'))) + parse_time_specificity_string (hmark, logitem->time); + + kdata->numdate = logitem->numdate; + get_kdata (kdata, logitem->time, logitem->time); + + return 0; +} + +void +insert_methods_protocols (void) { + size_t i; + for (i = 0; i < http_methods_len; ++i) + ht_insert_meth_proto (http_methods[i].method); + for (i = 0; i < http_protocols_len; ++i) + ht_insert_meth_proto (http_protocols[i].protocol); + ht_insert_meth_proto ("---"); +} + +/* Determine if 404s need to be added to the unique visitors count. + * + * If it needs to be added, 0 is returned else 1 is returned. */ +static int +include_uniq (GLogItem *logitem) { + int u = conf.client_err_to_unique_count; + + if (!logitem->status || (logitem->status / 100) != 4 || (u && (logitem->status / 100) == '4')) + return 1; + return 0; +} + +/* Determine which data metrics need to be set and set them. */ +static void +set_datamap (GLogItem *logitem, GKeyData *kdata, const GParse *parse) { + GModule module; + module = parse->module; + + /* insert data */ + parse->datamap (module, kdata); + + /* insert rootmap and root-data map */ + if (parse->rootmap && kdata->root) { + parse->rootmap (module, kdata); + insert_root (module, kdata); + } + /* insert hits */ + if (parse->hits) + parse->hits (module, kdata); + /* insert visitors */ + if (parse->visitor && kdata->uniq_nkey == 1) + parse->visitor (module, kdata); + /* insert bandwidth */ + if (parse->bw) + parse->bw (module, kdata, logitem->resp_size); + /* insert averages time served */ + if (parse->cumts) + parse->cumts (module, kdata, logitem->serve_time); + /* insert averages time served */ + if (parse->maxts) + parse->maxts (module, kdata, logitem->serve_time); + /* insert method */ + if (parse->method && conf.append_method) + parse->method (module, kdata, logitem->method); + /* insert protocol */ + if (parse->protocol && conf.append_protocol) + parse->protocol (module, kdata, logitem->protocol); + /* insert agent */ + if (parse->agent && conf.list_agents) + parse->agent (module, kdata, logitem->agent_nkey); +} + +/* Set data mapping and metrics. */ +static void +map_log (GLogItem *logitem, const GParse *parse, GModule module) { + GKeyData kdata; + + new_modulekey (&kdata); + /* set key data into out structure */ + if (parse->key_data (&kdata, logitem) == 1) + return; + + /* each module requires a data key/value */ + if (parse->datamap && kdata.data) + kdata.data_nkey = insert_dkeymap (module, &kdata); + + /* each module contains a uniq visitor key/value */ + if (parse->visitor && logitem->uniq_key && include_uniq (logitem)) + kdata.uniq_nkey = insert_uniqmap (module, &kdata, logitem->uniq_nkey); + + /* root keys are optional */ + if (parse->rootmap && kdata.root) + kdata.root_nkey = insert_rkeymap (module, &kdata); + + /* each module requires a root key/value */ + if (parse->datamap && kdata.data) + set_datamap (logitem, &kdata, parse); +} + +static void +ins_agent_key_val (GLogItem *logitem, uint32_t numdate) { + logitem->agent_nkey = ht_insert_agent_key (numdate, logitem->agent_hash); + /* insert UA key and get a numeric value */ + if (logitem->agent_nkey != 0) { + /* insert a numeric key and map it to a UA string */ + ht_insert_agent_value (numdate, logitem->agent_nkey, logitem->agent); + } +} + +static int +clean_old_data_by_date (uint32_t numdate) { + uint32_t *dates = NULL; + uint32_t idx, len = 0; + + if (ht_get_size_dates () < conf.keep_last) + return 1; + + dates = get_sorted_dates (&len); + + /* If currently parsed date is in the set of dates, keep inserting it. + * We count down since more likely the currently parsed date is at the last pos */ + for (idx = len; idx-- > 0;) { + if (dates[idx] == numdate) { + free (dates); + return 1; + } + } + + /* ignore older dates */ + if (dates[0] > numdate) { + free (dates); + return -1; + } + + /* invalidate the first date we inserted then */ + invalidate_date (dates[0]); + /* rebuild all existing dates and let new data + * be added upon existing cache */ + rebuild_rawdata_cache (); + free (dates); + + return 0; +} + +/* Process a log line and set the data into the corresponding data + * structure. */ +void +process_log (GLogItem *logitem) { + GModule module; + const GParse *parse = NULL; + size_t idx = 0; + uint32_t numdate = logitem->numdate; + + if (conf.keep_last > 0 && clean_old_data_by_date (numdate) == -1) + return; + + /* insert date and start partitioning tables */ + if (ht_insert_date (numdate) == -1) + return; + + /* Insert one unique visitor key per request to avoid the + * overhead of storing one key per module */ + if ((logitem->uniq_nkey = ht_insert_unique_key (numdate, logitem->uniq_key)) == 0) + return; + + /* If we need to store user agents per IP, then we store them and retrieve + * its numeric key. + * It maintains two maps, one for key -> value, and another + * map for value -> key*/ + if (conf.list_agents) + ins_agent_key_val (logitem, numdate); + + FOREACH_MODULE (idx, module_list) { + module = module_list[idx]; + if (!(parse = panel_lookup (module))) + continue; + map_log (logitem, parse, module); + } + + count_bw (numdate, logitem->resp_size); + /* don't ignore line but neither count as valid */ + if (logitem->ignorelevel != IGNORE_LEVEL_REQ) + count_valid (numdate); +} diff --git a/src/gstorage.h b/src/gstorage.h new file mode 100644 index 0000000000..1140f3a21e --- /dev/null +++ b/src/gstorage.h @@ -0,0 +1,162 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef GSTORAGE_H_INCLUDED +#define GSTORAGE_H_INCLUDED + +#include "commons.h" +#include "parser.h" + +#define DB_PATH "/tmp" + +#define GAMTRC_TOTAL 8 +/* Enumerated App Metrics */ +typedef enum GAMetric_ { + MTRC_DATES, + MTRC_SEQS, + MTRC_CNT_OVERALL, + MTRC_HOSTNAMES, + MTRC_LAST_PARSE, + MTRC_JSON_LOGFMT, + MTRC_METH_PROTO, + MTRC_DB_PROPS, +} GAMetric; + +/* Enumerated Storage Metrics */ +typedef enum GSMetricType_ { + /* uint32_t key - uint32_t val */ + MTRC_TYPE_II32, + /* uint32_t key - string val */ + MTRC_TYPE_IS32, + /* uint32_t key - uint64_t val */ + MTRC_TYPE_IU64, + /* string key - uint32_t val */ + MTRC_TYPE_SI32, + /* string key - uint8_t val */ + MTRC_TYPE_SI08, + /* uint32_t key - uint8_t val */ + MTRC_TYPE_II08, + /* string key - string val */ + MTRC_TYPE_SS32, + /* uint32_t key - GSLList val */ + MTRC_TYPE_IGSL, + /* string key - uint64_t val */ + MTRC_TYPE_SU64, + /* uint32_t key - GKHashStorage_ val */ + MTRC_TYPE_IGKH, + /* uint64_t key - uint32_t val */ + MTRC_TYPE_U648, + /* uint64_t key - GLastParse val */ + MTRC_TYPE_IGLP, +} GSMetricType; + +typedef struct GKHashMetric_ { + union { + GSMetric storem; + GAMetric dbm; + } metric; + GSMetricType type; + void *(*alloc) (void); + void (*des) (void *, uint8_t free_data); + void (*del) (void *, uint8_t free_data); + uint8_t free_data:1; + void *hash; + const char *filename; +} GKHashMetric; + +/* Each record contains a data value, i.e., Windows XP, and it may contain a + * root value, i.e., Windows, and a unique key which is the combination of + * date, IP and user agent */ +typedef struct GKeyData_ { + const void *data; + uint32_t dhash; + uint32_t data_nkey; + uint32_t cdnkey; /* cache data nkey */ + + uint32_t rhash; + const void *root; + const void *root_key; + uint32_t root_nkey; + uint32_t crnkey; /* cache root nkey */ + + void *uniq_key; + uint32_t uniq_nkey; + + uint32_t numdate; +} GKeyData; + +typedef struct GParse_ { + GModule module; + int (*key_data) (GKeyData * kdata, GLogItem * logitem); + + /* data field */ + void (*datamap) (GModule module, GKeyData * kdata); + void (*rootmap) (GModule module, GKeyData * kdata); + void (*hits) (GModule module, GKeyData * kdata); + void (*visitor) (GModule module, GKeyData * kdata); + void (*bw) (GModule module, GKeyData * kdata, uint64_t size); + void (*cumts) (GModule module, GKeyData * kdata, uint64_t ts); + void (*maxts) (GModule module, GKeyData * kdata, uint64_t ts); + void (*method) (GModule module, GKeyData * kdata, const char *data); + void (*protocol) (GModule module, GKeyData * kdata, const char *data); + void (*agent) (GModule module, GKeyData * kdata, uint32_t agent_nkey); +} GParse; + +typedef struct httpmethods_ { + const char *method; + int len; +} httpmethods; + +typedef struct httpprotocols_ { + const char *protocol; + int len; +} httpprotocols; + +extern const httpmethods http_methods[]; +extern const httpprotocols http_protocols[]; +extern const size_t http_methods_len; +extern const size_t http_protocols_len; + +const char *get_mtr_str (GSMetric metric); +int excluded_ip (GLogItem * logitem); +uint32_t *i322ptr (uint32_t val); +uint64_t *uint642ptr (uint64_t val); +void count_process_and_invalid (GLog * glog, GLogItem * logitem, const char *line); +void count_process (GLog * glog); +void free_gmetrics (GMetrics * metric); +void insert_methods_protocols (void); +void process_log (GLogItem * logitem); +void set_browser_os (GLogItem * logitem); +void set_data_metrics (GMetrics * ometrics, GMetrics ** nmetrics, GPercTotals totals); +void set_module_totals (GPercTotals * totals); +void uncount_invalid (GLog * glog); +void uncount_processed (GLog * glog); +GMetrics *new_gmetrics (void); + +#endif // for #ifndef GSTORAGE_H diff --git a/src/gwsocket.c b/src/gwsocket.c new file mode 100644 index 0000000000..14380b83bc --- /dev/null +++ b/src/gwsocket.c @@ -0,0 +1,390 @@ +/** + * gwsocket.c -- An interface to send/recv data from/to Web Socket Server + * _______ _______ __ __ + * / ____/ | / / ___/____ _____/ /_____ / /_ + * / / __ | | /| / /\__ \/ __ \/ ___/ //_/ _ \/ __/ + * / /_/ / | |/ |/ /___/ / /_/ / /__/ ,< / __/ /_ + * \____/ |__/|__//____/\____/\___/_/|_|\___/\__/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include + +#include "gwsocket.h" + +#include "commons.h" +#include "error.h" +#include "goaccess.h" +#include "json.h" +#include "settings.h" +#include "websocket.h" +#include "xmalloc.h" + +/* Allocate memory for a new GWSReader instance. + * + * On success, the newly allocated GWSReader is returned. */ +GWSReader * +new_gwsreader (void) { + GWSReader *reader = xmalloc (sizeof (GWSReader)); + memset (reader, 0, sizeof *reader); + + return reader; +} + +/* Allocate memory for a new GWSWriter instance. + * + * On success, the newly allocated GWSWriter is returned. */ +GWSWriter * +new_gwswriter (void) { + GWSWriter *writer = xmalloc (sizeof (GWSWriter)); + memset (writer, 0, sizeof *writer); + + return writer; +} + +/* Write the JSON data to a pipe. + * + * If unable to write bytes, -1 is returned. + * On success, the number of written bytes is returned . */ +static int +write_holder (int fd, const char *buf, int len) { + int i, ret = 0; + + for (i = 0; i < len;) { + ret = write (fd, buf + i, len - i); + if (ret < 0) { + if (errno == EINTR || errno == EAGAIN) + continue; + return -1; + } else { + i += ret; + } + } + + return i; +} + +/* Clear an incoming FIFO packet and header data. */ +static void +clear_fifo_packet (GWSReader *gwserver) { + memset (gwserver->hdr, 0, sizeof (gwserver->hdr)); + gwserver->hlen = 0; + + if (gwserver->packet == NULL) + return; + + if (gwserver->packet->data) + free (gwserver->packet->data); + free (gwserver->packet); + gwserver->packet = NULL; +} + +/* Pack the JSON data into a network byte order and writes it to a + * pipe. + * + * On success, 0 is returned . */ +int +broadcast_holder (int fd, const char *buf, int len) { + char *p = NULL, *ptr = NULL; + + p = calloc (sizeof (uint32_t) * 3, sizeof (char)); + + ptr = p; + ptr += pack_uint32 (ptr, 0); + ptr += pack_uint32 (ptr, 0x01); + ptr += pack_uint32 (ptr, len); + + write_holder (fd, p, sizeof (uint32_t) * 3); + write_holder (fd, buf, len); + free (p); + + return 0; +} + +/* Pack the JSON data into a network byte order and write it to a + * pipe. + * + * On success, 0 is returned . */ +int +send_holder_to_client (int fd, int listener, const char *buf, int len) { + char *p = NULL, *ptr = NULL; + + p = calloc (sizeof (uint32_t) * 3, sizeof (char)); + + ptr = p; + ptr += pack_uint32 (ptr, listener); + ptr += pack_uint32 (ptr, 0x01); + ptr += pack_uint32 (ptr, len); + + write_holder (fd, p, sizeof (uint32_t) * 3); + write_holder (fd, buf, len); + free (p); + + return 0; +} + +/* Attempt to read data from the named pipe on strict mode. + * Note: For now it only reads on new connections, i.e., onopen. + * + * If there's less data than requested, 0 is returned + * If the thread is done, 1 is returned */ +int +read_fifo (GWSReader *gwsreader, void (*f) (int)) { + WSPacket **pa = &gwsreader->packet; + char *ptr; + int bytes = 0, readh = 0, need = 0, fd = gwsreader->fd; + uint32_t listener = 0, type = 0, size = 0; + struct pollfd fds[] = { + {.fd = gwsreader->self_pipe[0],.events = POLLIN}, + {.fd = gwsreader->fd,.events = POLLIN,}, + }; + + if (poll (fds, sizeof (fds) / sizeof (fds[0]), -1) == -1) { + switch (errno) { + case EINTR: + break; + default: + FATAL ("Unable to poll: %s.", strerror (errno)); + } + } + /* handle self-pipe trick */ + if (fds[0].revents & POLLIN) + return 1; + if (!(fds[1].revents & POLLIN)) { + LOG (("No file descriptor set on read_message()\n")); + return 0; + } + + readh = gwsreader->hlen; /* read from header so far */ + need = HDR_SIZE - readh; /* need to read */ + if (need > 0) { + if ((bytes = ws_read_fifo (fd, gwsreader->hdr, &gwsreader->hlen, readh, need)) < 0) + return 0; + if (bytes != need) + return 0; + } + + /* unpack size, and type */ + ptr = gwsreader->hdr; + ptr += unpack_uint32 (ptr, &listener); + ptr += unpack_uint32 (ptr, &type); + ptr += unpack_uint32 (ptr, &size); + + if ((*pa) == NULL) { + (*pa) = xcalloc (1, sizeof (WSPacket)); + (*pa)->type = type; + (*pa)->size = size; + (*pa)->data = xcalloc (size + 1, sizeof (char)); + } + + readh = (*pa)->len; /* read from payload so far */ + need = (*pa)->size - readh; /* need to read */ + if (need > 0) { + if ((bytes = ws_read_fifo (fd, (*pa)->data, &(*pa)->len, readh, need)) < 0) + return 0; + if (bytes != need) + return 0; + } + clear_fifo_packet (gwsreader); + /* fast forward JSON data to the given client */ + (*f) (listener); + + return 0; +} + +/* Callback once a new connection is established + * + * It writes to a named pipe a header containing the socket, the + * message type, the payload's length and the actual payload */ +static int +onopen (WSPipeOut *pipeout, WSClient *client) { + uint32_t hsize = sizeof (uint32_t) * 3; + char *hdr = calloc (hsize, sizeof (char)); + char *ptr = hdr; + + ptr += pack_uint32 (ptr, client->listener); + ptr += pack_uint32 (ptr, WS_OPCODE_TEXT); + ptr += pack_uint32 (ptr, INET6_ADDRSTRLEN); + + ws_write_fifo (pipeout, hdr, hsize); + ws_write_fifo (pipeout, client->remote_ip, INET6_ADDRSTRLEN); + free (hdr); + + return 0; +} + +/* Done parsing, clear out line and set status message. */ +void +set_ready_state (void) { + fprintf (stderr, "\33[2K\r"); + fprintf (stderr, "%s\n", INFO_WS_READY_FOR_CONN); +} + +/* Open the named pipe where the websocket server writes to. + * + * If unable to open, -1 is returned. + * On success, return the new file descriptor is returned . */ +int +open_fifoout (void) { + const char *fifo = conf.fifo_out; + int fdfifo; + + /* open fifo for reading before writing */ + ws_setfifo (fifo); + if ((fdfifo = open (fifo, O_RDWR | O_NONBLOCK)) == -1) + return -1; + + return fdfifo; +} + +/* Open the named pipe where the websocket server reads from. + * + * If unable to open, -1 is returned. + * On success, return the new file descriptor is returned . */ +int +open_fifoin (void) { + const char *fifo = conf.fifo_in; + int fdfifo; + + if ((fdfifo = open (fifo, O_WRONLY | O_NONBLOCK)) == -1) + return -1; + + return fdfifo; +} + +/* Set the self-pipe trick to handle poll(2). */ +void +set_self_pipe (int *self_pipe) { + /* Initialize self pipe. */ + if (pipe (self_pipe) == -1) + FATAL ("Unable to create pipe: %s.", strerror (errno)); + + /* make the read and write pipe non-blocking */ + set_nonblocking (self_pipe[0]); + set_nonblocking (self_pipe[1]); +} + +/* Close the WebSocket server and clean up. */ +void +stop_ws_server (GWSWriter *gwswriter, GWSReader *gwsreader) { + pthread_t writer, reader; + WSServer *server = NULL; + + if (!gwsreader || !gwswriter) + return; + if (!(server = gwswriter->server)) + return; + + pthread_mutex_lock (&gwsreader->mutex); + if ((write (gwsreader->self_pipe[1], "x", 1)) == -1 && errno != EAGAIN) + LOG (("Unable to write to self pipe on pipeout.\n")); + pthread_mutex_unlock (&gwsreader->mutex); + + /* if it fails to write, force stop */ + pthread_mutex_lock (&gwswriter->mutex); + if ((write (server->self_pipe[1], "x", 1)) == -1 && errno != EAGAIN) + ws_stop (server); + pthread_mutex_unlock (&gwswriter->mutex); + + reader = gwsreader->thread; + if (pthread_join (reader, NULL) != 0) + LOG (("Unable to join thread gwsreader: %s\n", strerror (errno))); + + writer = gwswriter->thread; + if (pthread_join (writer, NULL) != 0) + LOG (("Unable to join thread gwswriter: %s\n", strerror (errno))); +} + +/* Start the WebSocket server and initialize default options. */ +static void +start_server (void *ptr_data) { + GWSWriter *writer = (GWSWriter *) ptr_data; + + writer->server->onopen = onopen; + pthread_mutex_lock (&writer->mutex); + set_self_pipe (writer->server->self_pipe); + pthread_mutex_unlock (&writer->mutex); + + /* poll(2) will block in here */ + ws_start (writer->server); + fprintf (stderr, "Stopping WebSocket server...\n"); + ws_stop (writer->server); +} + +/* Read and set the WebSocket config options. */ +static void +set_ws_opts (void) { + ws_set_config_strict (1); + if (conf.addr) + ws_set_config_host (conf.addr); + if (conf.unix_socket) + ws_set_config_unix_socket (conf.unix_socket); + if (conf.fifo_in) + ws_set_config_pipein (conf.fifo_in); + if (conf.fifo_out) + ws_set_config_pipeout (conf.fifo_out); + if (conf.origin) + ws_set_config_origin (conf.origin); + if (conf.port) + ws_set_config_port (conf.port); + if (conf.sslcert) + ws_set_config_sslcert (conf.sslcert); + if (conf.sslkey) + ws_set_config_sslkey (conf.sslkey); +} + +/* Setup and start the WebSocket threads. */ +int +setup_ws_server (GWSWriter *gwswriter, GWSReader *gwsreader) { + int id; + pthread_t *thread; + + if (pthread_mutex_init (&gwswriter->mutex, NULL)) + FATAL ("Failed init gwswriter mutex"); + if (pthread_mutex_init (&gwsreader->mutex, NULL)) + FATAL ("Failed init gwsreader mutex"); + + /* send WS data thread */ + thread = &gwswriter->thread; + + /* pre-init the websocket server, to ensure the FIFOs are created */ + if ((gwswriter->server = ws_init ("0.0.0.0", "7890", set_ws_opts)) == NULL) + FATAL ("Failed init websocket"); + + id = pthread_create (&(*thread), NULL, (void *) &start_server, gwswriter); + if (id) + FATAL ("Return code from pthread_create(): %d", id); + + /* read WS data thread */ + thread = &gwsreader->thread; + id = pthread_create (&(*thread), NULL, (void *) &read_client, gwsreader); + if (id) + FATAL ("Return code from pthread_create(): %d", id); + + return 0; +} diff --git a/src/gwsocket.h b/src/gwsocket.h new file mode 100644 index 0000000000..ffd29c9d44 --- /dev/null +++ b/src/gwsocket.h @@ -0,0 +1,71 @@ +/** + * _______ _______ __ __ + * / ____/ | / / ___/____ _____/ /_____ / /_ + * / / __ | | /| / /\__ \/ __ \/ ___/ //_/ _ \/ __/ + * / /_/ / | |/ |/ /___/ / /_/ / /__/ ,< / __/ /_ + * \____/ |__/|__//____/\____/\___/_/|_|\___/\__/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef GWSOCKET_H_INCLUDED +#define GWSOCKET_H_INCLUDED + +#define GW_VERSION "0.1" + +#include +#include "websocket.h" + +typedef struct GWSReader_ { + int fd; + int self_pipe[2]; /* self-pipe */ + + pthread_mutex_t mutex; /* Mutex fifo out */ + pthread_t thread; /* Thread fifo in */ + + WSPacket *packet; /* FIFO data's buffer */ + char hdr[HDR_SIZE]; /* FIFO header's buffer */ + int hlen; /* header length */ +} GWSReader; + +typedef struct GWSWriter_ { + int fd; + + pthread_mutex_t mutex; /* Mutex fifo in */ + pthread_t thread; /* Thread fifo out */ + + WSServer *server; /* WebSocket server */ +} GWSWriter; + +GWSReader *new_gwsreader (void); +GWSWriter *new_gwswriter (void); +int broadcast_holder (int fd, const char *buf, int len); +int open_fifoin (void); +int open_fifoout (void); +int read_fifo (GWSReader * gwsreader, void (*f) (int)); +int send_holder_to_client (int fd, int listener, const char *buf, int len); +int setup_ws_server (GWSWriter * gwswriter, GWSReader * gwsreader); +void set_ready_state (void); +void set_self_pipe (int *self_pipe); +void stop_ws_server (GWSWriter * gwswriter, GWSReader * gwsreader); + +#endif // for #ifndef GWSOCKET_H diff --git a/src/json.c b/src/json.c new file mode 100644 index 0000000000..920f0942d2 --- /dev/null +++ b/src/json.c @@ -0,0 +1,1187 @@ +/** + * output.c -- output json to the standard output stream + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE +#define _FILE_OFFSET_BITS 64 + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "json.h" + +#include "error.h" +#include "gkhash.h" +#include "settings.h" +#include "ui.h" +#include "util.h" +#include "websocket.h" +#include "xmalloc.h" + +typedef struct GPanel_ { + GModule module; + void (*render) (GJSON * json, GHolder * h, GPercTotals totals, const struct GPanel_ *); + void (*subitems) (GJSON * json, GHolderItem * item, GPercTotals totals, int size, int iisp); +} GPanel; + +/* number of new lines (applicable fields) */ +static int nlines = 0; +/* escape HTML in JSON data values */ +static int escape_html_output = 0; + +static void print_json_data (GJSON * json, GHolder * h, GPercTotals totals, const struct GPanel_ *); +static void print_json_host_items (GJSON * json, GHolderItem * item, + GPercTotals totals, int size, int iisp); +static void print_json_sub_items (GJSON * json, GHolderItem * item, + GPercTotals totals, int size, int iisp); + +/* *INDENT-OFF* */ +static const GPanel paneling[] = { + {VISITORS , print_json_data , NULL } , + {REQUESTS , print_json_data , NULL } , + {REQUESTS_STATIC , print_json_data , NULL } , + {NOT_FOUND , print_json_data , NULL } , + {HOSTS , print_json_data , print_json_host_items } , + {OS , print_json_data , print_json_sub_items } , + {BROWSERS , print_json_data , print_json_sub_items } , + {VISIT_TIMES , print_json_data , NULL } , + {VIRTUAL_HOSTS , print_json_data , NULL } , + {REFERRERS , print_json_data , NULL } , + {REFERRING_SITES , print_json_data , NULL } , + {KEYPHRASES , print_json_data , NULL } , + {STATUS_CODES , print_json_data , print_json_sub_items } , + {REMOTE_USER , print_json_data , NULL } , + {CACHE_STATUS , print_json_data , NULL } , +#ifdef HAVE_GEOLOCATION + {GEO_LOCATION , print_json_data , print_json_sub_items } , + {ASN , print_json_data , NULL} , +#endif + {MIME_TYPE , print_json_data , print_json_sub_items } , + {TLS_TYPE , print_json_data , print_json_sub_items } , + +}; +/* *INDENT-ON* */ + +/* Get panel output data for the given module. + * + * If not found, NULL is returned. + * On success, panel data is returned . */ +static const GPanel * +panel_lookup (GModule module) { + int i, num_panels = ARRAY_SIZE (paneling); + + for (i = 0; i < num_panels; i++) { + if (paneling[i].module == module) + return &paneling[i]; + } + return NULL; +} + +/* Allocate memory for a new GJSON instance. + * + * On success, the newly allocated GJSON is returned . */ +static GJSON * +new_gjson (void) { + GJSON *json = xcalloc (1, sizeof (GJSON)); + + return json; +} + +/* Free malloc'd GJSON resources. */ +static void +free_json (GJSON *json) { + if (!json) + return; + + free (json->buf); + free (json); +} + +/* Set number of new lines when --json-pretty-print is used. */ +void +set_json_nlines (int newline) { + nlines = newline; +} + +/* Make sure that we have enough storage to write "len" bytes at the + * current offset. */ +static void +set_json_buffer (GJSON *json, int len) { + char *tmp = NULL; + /* Maintain a null byte at the end of the buffer */ + size_t need = json->offset + len + 1, newlen = 0; + + if (need <= json->size) + return; + + if (json->size == 0) { + newlen = INIT_BUF_SIZE; + } else { + newlen = json->size; + newlen += newlen / 2; /* resize by 3/2 */ + } + + if (newlen < need) + newlen = need; + + tmp = realloc (json->buf, newlen); + if (tmp == NULL) { + free_json (json); + FATAL (("Unable to realloc JSON buffer.\n")); + } + json->buf = tmp; + json->size = newlen; +} + +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +/* A wrapper function to write a formatted string and expand the + * buffer if necessary. + * + * On success, data is outputted. */ +__attribute__((format (printf, 2, 3))) +static void +pjson (GJSON *json, const char *fmt, ...) { + int len = 0; + va_list args; + + va_start (args, fmt); + if ((len = vsnprintf (NULL, 0, fmt, args)) < 0) + FATAL (("Unable to write JSON formatted data.\n")); + va_end (args); + + /* malloc/realloc buffer as needed */ + set_json_buffer (json, len); + + va_start (args, fmt); /* restart args */ + vsprintf (json->buf + json->offset, fmt, args); + va_end (args); + json->offset += len; +} + +/* A wrapper function to output a formatted string to a file pointer. + * + * On success, data is outputted. */ +void +fpjson (FILE *fp, const char *fmt, ...) { + va_list args; + + va_start (args, fmt); + vfprintf (fp, fmt, args); + va_end (args); +} + +#pragma GCC diagnostic warning "-Wformat-nonliteral" + +/* Escape all other characters accordingly. */ +static void +escape_json_other (GJSON *json, const char **s) { + /* Since JSON data is bootstrapped into the HTML document of a report, + * then we perform the following four translations in case weird stuff + * is put into the document. + * + * Note: The following scenario assumes that the user manually makes + * the HTML report a PHP file (GoAccess doesn't allow the creation of a + * PHP file): + * + * /index.html + */ + if (escape_html_output) { + switch (**s) { + case '\'': + pjson (json, "'"); + return; + case '&': + pjson (json, "&"); + return; + case '<': + pjson (json, "<"); + return; + case '>': + pjson (json, ">"); + return; + } + } + + if ((uint8_t) ** s <= 0x1f) { + /* Control characters (U+0000 through U+001F) */ + char buf[8]; + snprintf (buf, sizeof buf, "\\u%04x", **s); + pjson (json, "%s", buf); + } else if ((uint8_t) ** s == 0xe2 && (uint8_t) * (*s + 1) == 0x80 && (uint8_t) * (*s + 2) == 0xa8) { + /* Line separator (U+2028) - 0xE2 0x80 0xA8 */ + pjson (json, "\\u2028"); + *s += 2; + } else if ((uint8_t) ** s == 0xe2 && (uint8_t) * (*s + 1) == 0x80 && (uint8_t) * (*s + 2) == 0xa9) { + /* Paragraph separator (U+2019) - 0xE2 0x80 0xA9 */ + pjson (json, "\\u2029"); + *s += 2; + } else { + char buf[2]; + snprintf (buf, sizeof buf, "%c", **s); + pjson (json, "%s", buf); + } +} + +/* Escape and write to a valid JSON buffer. + * + * On success, escaped JSON data is outputted. */ +static void +escape_json_output (GJSON *json, const char *s) { + while (*s) { + switch (*s) { + /* These are required JSON special characters that need to be escaped. */ + case '"': + pjson (json, "\\\""); + break; + case '\\': + pjson (json, "\\\\"); + break; + case '\b': + pjson (json, "\\b"); + break; + case '\f': + pjson (json, "\\f"); + break; + case '\n': + pjson (json, "\\n"); + break; + case '\r': + pjson (json, "\\r"); + break; + case '\t': + pjson (json, "\\t"); + break; + case '/': + pjson (json, "\\/"); + break; + default: + escape_json_other (json, &s); + break; + } + s++; + } +} + +/* Write to a buffer a JSON a key/value pair. */ +static void +pskeysval (GJSON *json, const char *key, const char *val, int sp, int last) { + if (!last) + pjson (json, "%.*s\"%s\": \"%s\",%.*s", sp, TAB, key, val, nlines, NL); + else + pjson (json, "%.*s\"%s\": \"%s\"", sp, TAB, key, val); +} + +/* Output a JSON string key, array value pair. */ +void +fpskeyaval (FILE *fp, const char *key, const char *val, int sp, int last) { + if (!last) + fpjson (fp, "%.*s\"%s\": %s,%.*s", sp, TAB, key, val, nlines, NL); + else + fpjson (fp, "%.*s\"%s\": %s", sp, TAB, key, val); +} + +/* Output a JSON a key/value pair. */ +void +fpskeysval (FILE *fp, const char *key, const char *val, int sp, int last) { + if (!last) + fpjson (fp, "%.*s\"%s\": \"%s\",%.*s", sp, TAB, key, val, nlines, NL); + else + fpjson (fp, "%.*s\"%s\": \"%s\"", sp, TAB, key, val); +} + +/* Output a JSON string key, int value pair. */ +void +fpskeyival (FILE *fp, const char *key, int val, int sp, int last) { + if (!last) + fpjson (fp, "%.*s\"%s\": %d,%.*s", sp, TAB, key, val, nlines, NL); + else + fpjson (fp, "%.*s\"%s\": %d", sp, TAB, key, val); +} + +/* Write to a buffer a JSON string key, uint64_t value pair. */ +static void +pskeyu64val (GJSON *json, const char *key, uint64_t val, int sp, int last) { + if (!last) + pjson (json, "%.*s\"%s\": %" PRIu64 ",%.*s", sp, TAB, key, val, nlines, NL); + else + pjson (json, "%.*s\"%s\": %" PRIu64 "", sp, TAB, key, val); +} + +/* Write to a buffer a JSON string key, int value pair. */ +static void +pskeyfval (GJSON *json, const char *key, float val, int sp, int last) { + if (!last) + pjson (json, "%.*s\"%s\": \"%05.2f\",%.*s", sp, TAB, key, val, nlines, NL); + else + pjson (json, "%.*s\"%s\": \"%05.2f\"", sp, TAB, key, val); +} + +/* Write to a buffer the open block item object. */ +static void +popen_obj (GJSON *json, int iisp) { + /* open data metric block */ + pjson (json, "%.*s{%.*s", iisp, TAB, nlines, NL); +} + +/* Output the open block item object. */ +void +fpopen_obj (FILE *fp, int iisp) { + /* open data metric block */ + fpjson (fp, "%.*s{%.*s", iisp, TAB, nlines, NL); +} + +/* Write to a buffer a JSON open object attribute. */ +static void +popen_obj_attr (GJSON *json, const char *attr, int sp) { + /* open object attribute */ + pjson (json, "%.*s\"%s\": {%.*s", sp, TAB, attr, nlines, NL); +} + +/* Output a JSON open object attribute. */ +void +fpopen_obj_attr (FILE *fp, const char *attr, int sp) { + /* open object attribute */ + fpjson (fp, "%.*s\"%s\": {%.*s", sp, TAB, attr, nlines, NL); +} + +/* Close JSON object. */ +static void +pclose_obj (GJSON *json, int iisp, int last) { + if (!last) + pjson (json, "%.*s%.*s},%.*s", nlines, NL, iisp, TAB, nlines, NL); + else + pjson (json, "%.*s%.*s}", nlines, NL, iisp, TAB); +} + +/* Close JSON object. */ +void +fpclose_obj (FILE *fp, int iisp, int last) { + if (!last) + fpjson (fp, "%.*s%.*s},%.*s", nlines, NL, iisp, TAB, nlines, NL); + else + fpjson (fp, "%.*s%.*s}", nlines, NL, iisp, TAB); +} + +/* Write to a buffer a JSON open array attribute. */ +static void +popen_arr_attr (GJSON *json, const char *attr, int sp) { + /* open object attribute */ + pjson (json, "%.*s\"%s\": [%.*s", sp, TAB, attr, nlines, NL); +} + +/* Output a JSON open array attribute. */ +void +fpopen_arr_attr (FILE *fp, const char *attr, int sp) { + /* open object attribute */ + fpjson (fp, "%.*s\"%s\": [%.*s", sp, TAB, attr, nlines, NL); +} + +/* Close the data array. */ +static void +pclose_arr (GJSON *json, int sp, int last) { + if (!last) + pjson (json, "%.*s%.*s],%.*s", nlines, NL, sp, TAB, nlines, NL); + else + pjson (json, "%.*s%.*s]", nlines, NL, sp, TAB); +} + +/* Close the data array. */ +void +fpclose_arr (FILE *fp, int sp, int last) { + if (!last) + fpjson (fp, "%.*s%.*s],%.*s", nlines, NL, sp, TAB, nlines, NL); + else + fpjson (fp, "%.*s%.*s]", nlines, NL, sp, TAB); +} + +/* Write to a buffer the date and time for the overall object. */ +static void +poverall_datetime (GJSON *json, int sp) { + char now[DATE_TIME]; + + generate_time (); + strftime (now, DATE_TIME, "%Y-%m-%d %H:%M:%S %z", &now_tm); + + pskeysval (json, OVERALL_DATETIME, now, sp, 0); +} + +/* Write to a buffer the date and time for the overall object. */ +static void +poverall_start_end_date (GJSON *json, GHolder *h, int sp) { + char *start = NULL, *end = NULL; + + if (h->idx == 0 || get_start_end_parsing_dates (&start, &end, "%d/%b/%Y")) + return; + + pskeysval (json, OVERALL_STARTDATE, start, sp, 0); + pskeysval (json, OVERALL_ENDDATE, end, sp, 0); + + free (end); + free (start); +} + +/* Write to a buffer date and time for the overall object. */ +static void +poverall_requests (GJSON *json, int sp) { + pskeyu64val (json, OVERALL_REQ, ht_get_processed (), sp, 0); +} + +/* Write to a buffer the number of valid requests under the overall + * object. */ +static void +poverall_valid_reqs (GJSON *json, int sp) { + pskeyu64val (json, OVERALL_VALID, ht_sum_valid (), sp, 0); +} + +/* Write to a buffer the number of invalid requests under the overall + * object. */ +static void +poverall_invalid_reqs (GJSON *json, int sp) { + pskeyu64val (json, OVERALL_FAILED, ht_get_invalid (), sp, 0); +} + +/* Write to a buffer the total processed time under the overall + * object. */ +static void +poverall_processed_time (GJSON *json, int sp) { + pskeyu64val (json, OVERALL_GENTIME, ht_get_processing_time (), sp, 0); +} + +/* Write to a buffer the total number of unique visitors under the + * overall object. */ +static void +poverall_visitors (GJSON *json, int sp) { + pskeyu64val (json, OVERALL_VISITORS, ht_get_size_uniqmap (VISITORS), sp, 0); +} + +/* Write to a buffer the total number of unique files under the + * overall object. */ +static void +poverall_files (GJSON *json, int sp) { + pskeyu64val (json, OVERALL_FILES, ht_get_size_datamap (REQUESTS), sp, 0); +} + +/* Write to a buffer the total number of excluded requests under the + * overall object. */ +static void +poverall_excluded (GJSON *json, int sp) { + pskeyu64val (json, OVERALL_EXCL_HITS, ht_get_excluded_ips (), sp, 0); +} + +/* Write to a buffer the number of referrers under the overall object. */ +static void +poverall_refs (GJSON *json, int sp) { + pskeyu64val (json, OVERALL_REF, ht_get_size_datamap (REFERRERS), sp, 0); +} + +/* Write to a buffer the number of not found (404s) under the overall + * object. */ +static void +poverall_notfound (GJSON *json, int sp) { + pskeyu64val (json, OVERALL_NOTFOUND, ht_get_size_datamap (NOT_FOUND), sp, 0); +} + +/* Write to a buffer the number of static files (jpg, pdf, etc) under + * the overall object. */ +static void +poverall_static_files (GJSON *json, int sp) { + pskeyu64val (json, OVERALL_STATIC, ht_get_size_datamap (REQUESTS_STATIC), sp, 0); +} + +/* Write to a buffer the size of the log being parsed under the + * overall object. */ +static void +poverall_log_size (GJSON *json, int sp) { + pjson (json, "%.*s\"%s\": %jd,%.*s", sp, TAB, OVERALL_LOGSIZE, + (intmax_t) get_log_sizes (), nlines, NL); +} + +/* Write to a buffer the total bandwidth consumed under the overall + * object. */ +static void +poverall_bandwidth (GJSON *json, int sp) { + pskeyu64val (json, OVERALL_BANDWIDTH, ht_sum_bw (), sp, 0); +} + +static void +poverall_log_path (GJSON *json, int idx, int isp) { + pjson (json, "%.*s\"", isp, TAB); + if (conf.filenames[idx][0] == '-' && conf.filenames[idx][1] == '\0') + pjson (json, "STDIN"); + else + escape_json_output (json, conf.filenames[idx]); + pjson (json, conf.filenames_idx - 1 != idx ? "\",\n" : "\""); +} + +/* Write to a buffer the path of the log being parsed under the + * overall object. */ +static void +poverall_log (GJSON *json, int sp) { + int idx, isp = 0; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + popen_arr_attr (json, OVERALL_LOG, sp); + for (idx = 0; idx < conf.filenames_idx; ++idx) + poverall_log_path (json, idx, isp); + pclose_arr (json, sp, 1); +} + +/* Write to a buffer hits data. */ +static void +phits (GJSON *json, GMetrics *nmetrics, int sp) { + int isp = 0; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + popen_obj_attr (json, "hits", sp); + /* print hits */ + pskeyu64val (json, "count", nmetrics->hits, isp, 0); + /* print hits percent */ + pskeyfval (json, "percent", nmetrics->hits_perc, isp, 1); + pclose_obj (json, sp, 0); +} + +/* Write to a buffer visitors data. */ +static void +pvisitors (GJSON *json, GMetrics *nmetrics, int sp) { + int isp = 0; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + popen_obj_attr (json, "visitors", sp); + /* print visitors */ + pskeyu64val (json, "count", nmetrics->visitors, isp, 0); + /* print visitors percent */ + pskeyfval (json, "percent", nmetrics->visitors_perc, isp, 1); + pclose_obj (json, sp, 0); +} + +/* Write to a buffer bandwidth data. */ +static void +pbw (GJSON *json, GMetrics *nmetrics, int sp) { + int isp = 0; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + if (!conf.bandwidth) + return; + + popen_obj_attr (json, "bytes", sp); + /* print bandwidth */ + pskeyu64val (json, "count", nmetrics->bw.nbw, isp, 0); + /* print bandwidth percent */ + pskeyfval (json, "percent", nmetrics->bw_perc, isp, 1); + pclose_obj (json, sp, 0); +} + +/* Write to a buffer average time served data. */ +static void +pavgts (GJSON *json, GMetrics *nmetrics, int sp) { + if (!conf.serve_usecs) + return; + pskeyu64val (json, "avgts", nmetrics->avgts.nts, sp, 0); +} + +/* Write to a buffer cumulative time served data. */ +static void +pcumts (GJSON *json, GMetrics *nmetrics, int sp) { + if (!conf.serve_usecs) + return; + pskeyu64val (json, "cumts", nmetrics->cumts.nts, sp, 0); +} + +/* Write to a buffer maximum time served data. */ +static void +pmaxts (GJSON *json, GMetrics *nmetrics, int sp) { + if (!conf.serve_usecs) + return; + pskeyu64val (json, "maxts", nmetrics->maxts.nts, sp, 0); +} + +/* Write to a buffer request method data. */ +static void +pmethod (GJSON *json, GMetrics *nmetrics, int sp) { + /* request method */ + if (conf.append_method && nmetrics->method) { + pskeysval (json, "method", nmetrics->method, sp, 0); + } +} + +/* Write to a buffer protocol method data. */ +static void +pprotocol (GJSON *json, GMetrics *nmetrics, int sp) { + /* request protocol */ + if (conf.append_protocol && nmetrics->protocol) { + pskeysval (json, "protocol", nmetrics->protocol, sp, 0); + } +} + +static void +pmeta_i64_data (GJSON *json, GHolder *h, void (*cb) (GModule, uint64_t *, uint64_t *), + const char *key, int show_perc, int sp) { + int isp = 0; + uint64_t max = 0, min = 0, total = ht_get_meta_data (h->module, key); + float avg = (total == 0 ? 0 : (((float) total) / h->ht_size)); + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + cb (h->module, &min, &max); + + popen_obj_attr (json, "total", sp); + pskeyu64val (json, "value", total, isp, 1); + pclose_obj (json, sp, 0); + + popen_obj_attr (json, "avg", sp); + pskeyu64val (json, "value", avg, isp, !show_perc); + if (show_perc) { + pskeyfval (json, "percent", get_percentage (total, avg), isp, 1); + } + pclose_obj (json, sp, 0); + + popen_obj_attr (json, "max", sp); + pskeyu64val (json, "value", max, isp, !show_perc); + if (show_perc) { + pskeyfval (json, "percent", get_percentage (total, max), isp, 1); + } + pclose_obj (json, sp, 0); + + popen_obj_attr (json, "min", sp); + pskeyu64val (json, "value", min, isp, !show_perc); + if (show_perc) { + pskeyfval (json, "percent", get_percentage (total, min), isp, 1); + } + pclose_obj (json, sp, 1); +} + +static void +pmeta_i32_data (GJSON *json, GHolder *h, void (*cb) (GModule, uint32_t *, uint32_t *), + const char *key, int show_perc, int sp) { + int isp = 0; + uint32_t max = 0, min = 0, total = ht_get_meta_data (h->module, key); + float avg = (total == 0 ? 0 : (((float) total) / h->ht_size)); + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + cb (h->module, &min, &max); + + popen_obj_attr (json, "total", sp); + pskeyu64val (json, "value", total, isp, 1); + pclose_obj (json, sp, 0); + + popen_obj_attr (json, "avg", sp); + pskeyu64val (json, "value", avg, isp, !show_perc); + if (show_perc) { + pskeyfval (json, "percent", get_percentage (total, avg), isp, 1); + } + pclose_obj (json, sp, 0); + + popen_obj_attr (json, "max", sp); + pskeyu64val (json, "value", max, isp, !show_perc); + if (show_perc) { + pskeyfval (json, "percent", get_percentage (total, max), isp, 1); + } + pclose_obj (json, sp, 0); + + popen_obj_attr (json, "min", sp); + pskeyu64val (json, "value", min, isp, !show_perc); + if (show_perc) { + pskeyfval (json, "percent", get_percentage (total, min), isp, 1); + } + pclose_obj (json, sp, 1); +} + +/* Write to a buffer the hits meta data object. */ +static void +pmeta_data_unique (GJSON *json, int ht_size, int sp) { + int isp = 0; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + popen_obj_attr (json, "data", sp); + + popen_obj_attr (json, "total", isp); + pskeyu64val (json, "value", ht_size, isp + 1, 1); + pclose_obj (json, isp, 1); + + pclose_obj (json, sp, 1); +} + +/* Write to a buffer the hits meta data object. */ +static void +pmeta_data_hits (GJSON *json, GHolder *h, int sp) { + int isp = 0; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + popen_obj_attr (json, "hits", sp); + pmeta_i32_data (json, h, ht_get_hits_min_max, "hits", 1, isp); + pclose_obj (json, sp, 0); +} + +/* Write to a buffer the visitors meta data object. */ +static void +pmeta_data_visitors (GJSON *json, GHolder *h, int sp) { + int isp = 0; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + popen_obj_attr (json, "visitors", sp); + pmeta_i32_data (json, h, ht_get_visitors_min_max, "visitors", 1, isp); + pclose_obj (json, sp, 0); +} + +/* Write to a buffer the bytes meta data object. */ +static void +pmeta_data_bw (GJSON *json, GHolder *h, int sp) { + int isp = 0; + if (!conf.bandwidth) + return; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + popen_obj_attr (json, "bytes", sp); + pmeta_i64_data (json, h, ht_get_bw_min_max, "bytes", 1, isp); + pclose_obj (json, sp, 0); +} + +/* Write to a buffer the average of the average time served meta data + * object. */ +static void +pmeta_data_avgts (GJSON *json, GHolder *h, int sp) { + int isp = 0; + uint64_t avg = 0, hits = 0, cumts = 0; + + if (!conf.serve_usecs) + return; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + cumts = ht_get_meta_data (h->module, "cumts"); + hits = ht_get_meta_data (h->module, "hits"); + if (hits > 0) + avg = cumts / hits; + + popen_obj_attr (json, "avgts", sp); + + popen_obj_attr (json, "avg", isp); + pskeyu64val (json, "value", avg, isp + 1, 1); + pclose_obj (json, isp, 1); + + pclose_obj (json, sp, 0); +} + +/* Write to a buffer the cumulative time served meta data object. */ +static void +pmeta_data_cumts (GJSON *json, GHolder *h, int sp) { + int isp = 0; + + if (!conf.serve_usecs) + return; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + popen_obj_attr (json, "cumts", sp); + pmeta_i64_data (json, h, ht_get_cumts_min_max, "cumts", 0, isp); + pclose_obj (json, sp, 0); +} + +/* Write to a buffer the maximum time served meta data object. */ +static void +pmeta_data_maxts (GJSON *json, GHolder *h, int sp) { + int isp = 0; + if (!conf.serve_usecs) + return; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + popen_obj_attr (json, "maxts", sp); + pmeta_i64_data (json, h, ht_get_maxts_min_max, "maxts", 0, isp); + pclose_obj (json, sp, 0); +} + +/* Entry point to output panel's metadata. */ +static void +print_meta_data (GJSON *json, GHolder *h, int sp) { + int isp = 0, iisp = 0; + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1, iisp = sp + 2; + + popen_obj_attr (json, "metadata", isp); + + pmeta_data_avgts (json, h, iisp); + pmeta_data_cumts (json, h, iisp); + pmeta_data_maxts (json, h, iisp); + pmeta_data_bw (json, h, iisp); + pmeta_data_visitors (json, h, iisp); + pmeta_data_hits (json, h, iisp); + pmeta_data_unique (json, h->ht_size, iisp); + + pclose_obj (json, isp, 0); +} + +/* A wrapper function to output data metrics per panel. */ +static void +print_json_block (GJSON *json, GMetrics *nmetrics, int sp) { + /* print hits */ + phits (json, nmetrics, sp); + /* print visitors */ + pvisitors (json, nmetrics, sp); + /* print bandwidth */ + pbw (json, nmetrics, sp); + + /* print time served metrics */ + pavgts (json, nmetrics, sp); + pcumts (json, nmetrics, sp); + pmaxts (json, nmetrics, sp); + + /* print protocol/method */ + pmethod (json, nmetrics, sp); + pprotocol (json, nmetrics, sp); + + /* data metric */ + pjson (json, "%.*s\"data\": \"", sp, TAB); + escape_json_output (json, nmetrics->data); + pjson (json, "\""); +} + +/* A wrapper function to output an array of user agents for each host. */ +static void +process_host_agents (GJSON *json, GHolderItem *item, int iisp) { + GAgents *agents = NULL; + int i, n = 0, iiisp = 0; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + iiisp = iisp + 1; + + /* create a new instance of GMenu and make it selectable */ + if (!(agents = load_host_agents (item->metrics->data))) + return; + + pjson (json, ",%.*s%.*s\"items\": [%.*s", nlines, NL, iisp, TAB, nlines, NL); + + n = agents->idx > 10 ? 10 : agents->idx; + for (i = 0; i < n; ++i) { + pjson (json, "%.*s\"", iiisp, TAB); + escape_json_output (json, agents->items[i].agent); + if (i == n - 1) + pjson (json, "\""); + else + pjson (json, "\",%.*s", nlines, NL); + } + + pclose_arr (json, iisp, 1); + + /* clean stuff up */ + free_agents_array (agents); +} + +/* A wrapper function to output children nodes. */ +static void +print_json_sub_items (GJSON *json, GHolderItem *item, GPercTotals totals, int size, int iisp) { + GMetrics *nmetrics; + GSubItem *iter; + GSubList *sl = item->sub_list; + int i = 0, iiisp = 0, iiiisp = 0; + + /* no sub items, nothing to output */ + if (size == 0) + return; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + iiisp = iisp + 1, iiiisp = iiisp + 1; + + if (sl == NULL) + return; + + pjson (json, ",%.*s%.*s\"items\": [%.*s", nlines, NL, iisp, TAB, nlines, NL); + for (iter = sl->head; iter; iter = iter->next, i++) { + set_data_metrics (iter->metrics, &nmetrics, totals); + + popen_obj (json, iiisp); + print_json_block (json, nmetrics, iiiisp); + pclose_obj (json, iiisp, (i == sl->size - 1)); + free (nmetrics); + } + pclose_arr (json, iisp, 1); +} + +/* A wrapper function to output geolocation fields for the given host. */ +static void +print_json_host_geo (GJSON *json, GSubList *sl, int iisp) { + GSubItem *iter; + int i; + static const char *key[] = { + "country", + "city", + "asn", + "hostname", + }; + + pjson (json, ",%.*s", nlines, NL); + + /* Iterate over child properties (country, city, asn, etc) and print them out */ + for (i = 0, iter = sl->head; iter; iter = iter->next, i++) { + pjson (json, "%.*s\"%s\": \"", iisp, TAB, key[iter->metrics->id]); + escape_json_output (json, iter->metrics->data); + pjson (json, (i != sl->size - 1) ? "\",%.*s" : "\"", nlines, NL); + } +} + +/* Output Geolocation data and the IP's hostname. */ +static void +print_json_host_items (GJSON *json, GHolderItem *item, GPercTotals totals, int size, int iisp) { + (void) totals; + /* print geolocation fields */ + if (size > 0 && item->sub_list != NULL) + print_json_host_geo (json, item->sub_list, iisp); + + /* print list of user agents */ + if (conf.list_agents) + process_host_agents (json, item, iisp); +} + +/* Output data and determine if there are children nodes. */ +static void +print_data_metrics (GJSON *json, GHolder *h, GPercTotals totals, int sp, + const struct GPanel_ *panel) { + GMetrics *nmetrics; + int i, isp = 0, iisp = 0, iiisp = 0; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1, iisp = sp + 2, iiisp = sp + 3; + + popen_arr_attr (json, "data", isp); + /* output data metrics */ + for (i = 0; i < h->idx; i++) { + set_data_metrics (h->items[i].metrics, &nmetrics, totals); + + /* open data metric block */ + popen_obj (json, iisp); + /* output data metric block */ + print_json_block (json, nmetrics, iiisp); + /* if there are children nodes, spit them out */ + if (panel->subitems) + panel->subitems (json, h->items + i, totals, h->sub_items_size, iiisp); + /* close data metric block */ + pclose_obj (json, iisp, (i == h->idx - 1)); + + free (nmetrics); + } + pclose_arr (json, isp, 1); +} + +/* Entry point to output data metrics per panel. */ +static void +print_json_data (GJSON *json, GHolder *h, GPercTotals totals, const struct GPanel_ *panel) { + int sp = 0; + /* use tabs to prettify output */ + if (conf.json_pretty_print) + sp = 1; + + /* output open panel attribute */ + popen_obj_attr (json, module_to_id (h->module), sp); + /* output panel metadata */ + print_meta_data (json, h, sp); + /* output panel data */ + print_data_metrics (json, h, totals, sp, panel); + /* output close panel attribute */ + pclose_obj (json, sp, 1); +} + +/* Get the number of available panels. + * + * On success, the total number of available panels is returned . */ +static int +num_panels (void) { + size_t idx = 0, npanels = 0; + + FOREACH_MODULE (idx, module_list) + npanels++; + + return npanels; +} + +/* Write to a buffer overall data. */ +static void +print_json_summary (GJSON *json, GHolder *holder) { + int sp = 0, isp = 0; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + sp = 1, isp = 2; + + popen_obj_attr (json, GENER_ID, sp); + /* generated start/end date */ + poverall_start_end_date (json, holder, isp); + /* generated date time */ + poverall_datetime (json, isp); + /* total requests */ + poverall_requests (json, isp); + /* valid requests */ + poverall_valid_reqs (json, isp); + /* invalid requests */ + poverall_invalid_reqs (json, isp); + /* generated time */ + poverall_processed_time (json, isp); + /* visitors */ + poverall_visitors (json, isp); + /* files */ + poverall_files (json, isp); + /* excluded hits */ + poverall_excluded (json, isp); + /* referrers */ + poverall_refs (json, isp); + /* not found */ + poverall_notfound (json, isp); + /* static files */ + poverall_static_files (json, isp); + /* log size */ + poverall_log_size (json, isp); + /* bandwidth */ + poverall_bandwidth (json, isp); + /* log path */ + poverall_log (json, isp); + pclose_obj (json, sp, num_panels () > 0 ? 0 : 1); +} + +/* Iterate over all panels and generate json output. */ +static GJSON * +init_json_output (GHolder *holder) { + GJSON *json = NULL; + GModule module; + GPercTotals totals; + const GPanel *panel = NULL; + size_t idx = 0, npanels = num_panels (), cnt = 0; + + json = new_gjson (); + + popen_obj (json, 0); + print_json_summary (json, holder); + + set_module_totals (&totals); + + FOREACH_MODULE (idx, module_list) { + module = module_list[idx]; + + if (!(panel = panel_lookup (module))) + continue; + + panel->render (json, holder + module, totals, panel); + pjson (json, (cnt++ != npanels - 1) ? ",%.*s" : "%.*s", nlines, NL); + } + + pclose_obj (json, 0, 1); + + return json; +} + +/* Open and write to a dynamically sized output buffer. + * + * On success, the newly allocated buffer is returned . */ +char * +get_json (GHolder *holder, int escape_html) { + GJSON *json = NULL; + char *buf = NULL; + + if (holder == NULL) + return NULL; + + escape_html_output = escape_html; + if ((json = init_json_output (holder)) && json->size > 0) { + buf = xstrdup (json->buf); + free_json (json); + } + + return buf; +} + +/* Entry point to generate a json report writing it to the fp */ +void +output_json (GHolder *holder, const char *filename) { + GJSON *json = NULL; + FILE *fp; + + if (filename != NULL) + fp = fopen (filename, "w"); + else + fp = stdout; + + if (!fp) + FATAL ("Unable to open JSON file: %s.", strerror (errno)); + + /* use new lines to prettify output */ + if (conf.json_pretty_print) + nlines = 1; + + /* spit it out */ + if ((json = init_json_output (holder)) && json->size > 0) { + fprintf (fp, "%s", json->buf); + free_json (json); + } + + fclose (fp); +} diff --git a/src/json.h b/src/json.h new file mode 100644 index 0000000000..0014bda3d2 --- /dev/null +++ b/src/json.h @@ -0,0 +1,64 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#ifndef JSON_H_INCLUDED +#define JSON_H_INCLUDED + +#define TAB "\t\t\t\t\t\t\t\t\t\t\t" +#define NL "\n\n\n" + +#include "parser.h" + +typedef struct GJSON_ { + char *buf; /* pointer to buffer */ + size_t size; /* size of malloc'd buffer */ + size_t offset; /* current write offset */ +} GJSON; + +char *get_json (GHolder * holder, int escape_html); + +void output_json (GHolder * holder, const char *filename); +void set_json_nlines (int nl); + +void fpskeyival (FILE * fp, const char *key, int val, int sp, int last); +void fpskeysval (FILE * fp, const char *key, const char *val, int sp, int last); +void fpskeyaval (FILE * fp, const char *key, const char *val, int sp, int last); + +void fpclose_arr (FILE * fp, int sp, int last); +void fpclose_obj (FILE * fp, int iisp, int last); +void fpjson (FILE * fp, const char *fmt, ...) __attribute__((format (printf, 2, 3))); +void fpopen_arr_attr (FILE * fp, const char *attr, int sp); +void fpopen_obj_attr (FILE * fp, const char *attr, int sp); +void fpopen_obj (FILE * fp, int iisp); + +#endif diff --git a/src/khash.h b/src/khash.h new file mode 100644 index 0000000000..a62df430db --- /dev/null +++ b/src/khash.h @@ -0,0 +1,679 @@ +/* The MIT License + + Copyright (c) 2008, 2009, 2011 by Attractive Chaos + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + An example: + +#include "khash.h" +KHASH_MAP_INIT_INT(32, char) +int main() { + int ret, is_missing; + khiter_t k; + khash_t(32) *h = kh_init(32); + k = kh_put(32, h, 5, &ret); + kh_value(h, k) = 10; + k = kh_get(32, h, 10); + is_missing = (k == kh_end(h)); + k = kh_get(32, h, 5); + kh_del(32, h, k); + for (k = kh_begin(h); k != kh_end(h); ++k) + if (kh_exist(h, k)) kh_value(h, k) = 1; + kh_destroy(32, h); + return 0; +} +*/ + +/* + 2013-05-02 (0.2.8): + + * Use quadratic probing. When the capacity is power of 2, stepping function + i*(i+1)/2 guarantees to traverse each bucket. It is better than double + hashing on cache performance and is more robust than linear probing. + + In theory, double hashing should be more robust than quadratic probing. + However, my implementation is probably not for large hash tables, because + the second hash function is closely tied to the first hash function, + which reduce the effectiveness of double hashing. + + Reference: http://research.cs.vt.edu/AVresearch/hashing/quadratic.php + + 2011-12-29 (0.2.7): + + * Minor code clean up; no actual effect. + + 2011-09-16 (0.2.6): + + * The capacity is a power of 2. This seems to dramatically improve the + speed for simple keys. Thank Zilong Tan for the suggestion. Reference: + + - http://code.google.com/p/ulib/ + - http://nothings.org/computer/judy/ + + * Allow to optionally use linear probing which usually has better + performance for random input. Double hashing is still the default as it + is more robust to certain non-random input. + + * Added Wang's integer hash function (not used by default). This hash + function is more robust to certain non-random input. + + 2011-02-14 (0.2.5): + + * Allow to declare global functions. + + 2009-09-26 (0.2.4): + + * Improve portability + + 2008-09-19 (0.2.3): + + * Corrected the example + * Improved interfaces + + 2008-09-11 (0.2.2): + + * Improved speed a little in kh_put() + + 2008-09-10 (0.2.1): + + * Added kh_clear() + * Fixed a compiling error + + 2008-09-02 (0.2.0): + + * Changed to token concatenation which increases flexibility. + + 2008-08-31 (0.1.2): + + * Fixed a bug in kh_get(), which has not been tested previously. + + 2008-08-31 (0.1.1): + + * Added destructor +*/ + + +#ifndef __AC_KHASH_H +#define __AC_KHASH_H + +/*! + @header + + Generic hash table library. + */ + +#define AC_VERSION_KHASH_H "0.2.8" + +#include +#include +#include + +/* compiler specific configuration */ + +#if UINT_MAX == 0xffffffffu +typedef unsigned int khint32_t; +#elif ULONG_MAX == 0xffffffffu +typedef unsigned long khint32_t; +#endif + +#if ULONG_MAX == ULLONG_MAX +typedef unsigned long khint64_t; +#else +typedef unsigned long long khint64_t; +#endif + +#ifndef kh_inline +#ifdef _MSC_VER +#define kh_inline __inline +#else +#define kh_inline inline +#endif +#endif /* kh_inline */ + +#ifndef klib_unused +#if (defined __clang__ && __clang_major__ >= 3) || (defined __GNUC__ && __GNUC__ >= 3) +#define klib_unused __attribute__ ((__unused__)) +#else +#define klib_unused +#endif +#endif /* klib_unused */ + +typedef khint32_t khint_t; +typedef khint_t khiter_t; + +#define __ac_isempty(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&2) +#define __ac_isdel(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&1) +#define __ac_iseither(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&3) +#define __ac_set_isdel_false(flag, i) (flag[i>>4]&=~(1ul<<((i&0xfU)<<1))) +#define __ac_set_isempty_false(flag, i) (flag[i>>4]&=~(2ul<<((i&0xfU)<<1))) +#define __ac_set_isboth_false(flag, i) (flag[i>>4]&=~(3ul<<((i&0xfU)<<1))) +#define __ac_set_isdel_true(flag, i) (flag[i>>4]|=1ul<<((i&0xfU)<<1)) + +#define __ac_fsize(m) ((m) < 16? 1 : (m)>>4) + +#ifndef kroundup32 +#define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x)) +#endif + +#ifndef kcalloc +#define kcalloc(N,Z) calloc(N,Z) +#endif +#ifndef kmalloc +#define kmalloc(Z) malloc(Z) +#endif +#ifndef krealloc +#define krealloc(P,Z) realloc(P,Z) +#endif +#ifndef kfree +#define kfree(P) free(P) +#endif + +static const double __ac_HASH_UPPER = 0.77; + +#define __KHASH_TYPE(name, khkey_t, khval_t) \ + typedef struct kh_##name##_s { \ + khint_t n_buckets, size, n_occupied, upper_bound; \ + khint32_t *flags; \ + khkey_t *keys; \ + khval_t *vals; \ + } kh_##name##_t; + +#define __KHASH_PROTOTYPES(name, khkey_t, khval_t) \ + extern kh_##name##_t *kh_init_##name(void); \ + extern void kh_destroy_##name(kh_##name##_t *h); \ + extern void kh_clear_##name(kh_##name##_t *h); \ + extern khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key); \ + extern int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets); \ + extern khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret); \ + extern void kh_del_##name(kh_##name##_t *h, khint_t x); \ + +#define __KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \ + SCOPE kh_##name##_t *kh_init_##name(void) { \ + return (kh_##name##_t*) kcalloc(1, sizeof(kh_##name##_t)); \ + } \ + SCOPE void kh_destroy_##name(kh_##name##_t *h) \ + { \ + if (h) { \ + kfree ((void *) h->keys); \ + kfree (h->flags); \ + kfree ((void *) h->vals); \ + kfree (h); \ + } \ + } \ + SCOPE void kh_clear_##name(kh_##name##_t *h) \ + { \ + if (h && h->flags) { \ + memset (h->flags, 0xaa, __ac_fsize (h->n_buckets) * sizeof (khint32_t)); \ + h->size = h->n_occupied = 0; \ + } \ + } \ + SCOPE khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key) \ + { \ + if (h->n_buckets) { \ + khint_t k, i, last, mask, step = 0; \ + mask = h->n_buckets - 1; \ + k = __hash_func (key); \ + i = k & mask; \ + last = i; \ + while (!__ac_isempty (h->flags, i) && \ + (__ac_isdel (h->flags, i) || !__hash_equal (h->keys[i], key))) { \ + i = (i + (++step)) & mask; \ + if (i == last) \ + return h->n_buckets; \ + } \ + return __ac_iseither (h->flags, i) ? h->n_buckets : i; \ + } else \ + return 0; \ + } \ + SCOPE int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \ + { \ + /* This function uses 0.25*n_buckets bytes of working space instead of */ \ + /* [sizeof(key_t+val_t)+.25]*n_buckets. */ \ + khint32_t *new_flags = 0; \ + khint_t j = 1; \ + { \ + kroundup32 (new_n_buckets); \ + if (new_n_buckets < 4) \ + new_n_buckets = 4; \ + if (h->size >= (khint_t) (new_n_buckets * __ac_HASH_UPPER + 0.5)) \ + j = 0; /* requested size is too small */ \ + else { /* hash table size to be changed (shrink or expand); rehash */ \ + new_flags = (khint32_t *) kmalloc (__ac_fsize (new_n_buckets) * sizeof (khint32_t)); \ + if (!new_flags) \ + return -1; \ + memset (new_flags, 0xaa, __ac_fsize (new_n_buckets) * sizeof (khint32_t)); \ + if (h->n_buckets < new_n_buckets) { /* expand */ \ + khkey_t *new_keys = (khkey_t *) krealloc ((void *) h->keys, new_n_buckets * sizeof (khkey_t)); \ + if (!new_keys) { \ + kfree (new_flags); \ + return -1; \ + } \ + h->keys = new_keys; \ + if (kh_is_map) { \ + khval_t *new_vals = (khval_t *) krealloc ((void *) h->vals, new_n_buckets * sizeof (khval_t)); \ + if (!new_vals) { \ + kfree (new_flags); \ + return -1; \ + } \ + h->vals = new_vals; \ + } \ + } /* otherwise shrink */ \ + } \ + } \ + if (j) { /* rehashing is needed */ \ + for (j = 0; j != h->n_buckets; ++j) { \ + if (__ac_iseither (h->flags, j) == 0) { \ + khkey_t key = h->keys[j]; \ + khval_t val; \ + khint_t new_mask; \ + new_mask = new_n_buckets - 1; \ + if (kh_is_map) \ + val = h->vals[j]; \ + __ac_set_isdel_true (h->flags, j); \ + while (1) { /* kick-out process; sort of like in Cuckoo hashing */ \ + khint_t k, i, step = 0; \ + k = __hash_func (key); \ + i = k & new_mask; \ + while (!__ac_isempty (new_flags, i)) \ + i = (i + (++step)) & new_mask; \ + __ac_set_isempty_false (new_flags, i); \ + if (i < h->n_buckets && __ac_iseither (h->flags, i) == 0) { /* kick out the existing element */ \ + { \ + khkey_t tmp = h->keys[i]; \ + h->keys[i] = key; \ + key = tmp; \ + } \ + if (kh_is_map) { \ + khval_t tmp = h->vals[i]; \ + h->vals[i] = val; \ + val = tmp; \ + } \ + __ac_set_isdel_true (h->flags, i); /* mark it as deleted in the old hash table */ \ + } else { /* write the element and jump out of the loop */ \ + h->keys[i] = key; \ + if (kh_is_map) \ + h->vals[i] = val; \ + break; \ + } \ + } \ + } \ + } \ + if (h->n_buckets > new_n_buckets) { /* shrink the hash table */ \ + h->keys = (khkey_t *) krealloc ((void *) h->keys, new_n_buckets * sizeof (khkey_t)); \ + if (kh_is_map) \ + h->vals = (khval_t *) krealloc ((void *) h->vals, new_n_buckets * sizeof (khval_t)); \ + } \ + kfree (h->flags); /* free the working space */ \ + h->flags = new_flags; \ + h->n_buckets = new_n_buckets; \ + h->n_occupied = h->size; \ + h->upper_bound = (khint_t) (h->n_buckets * __ac_HASH_UPPER + 0.5); \ + } \ + return 0; \ + } \ + SCOPE khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \ + { \ + khint_t x; \ + if (h->n_occupied >= h->upper_bound) { /* update the hash table */ \ + if (h->n_buckets > (h->size << 1)) { \ + if (kh_resize_##name (h, h->n_buckets - 1) < 0) { /* clear "deleted" elements */ \ + *ret = -1; \ + return h->n_buckets; \ + } \ + } else if (kh_resize_##name (h, h->n_buckets + 1) < 0) { /* expand the hash table */ \ + *ret = -1; \ + return h->n_buckets; \ + } \ + } /* TODO: to implement automatically shrinking; resize() already support shrinking */ \ + { \ + khint_t k, i, site, last, mask = h->n_buckets - 1, step = 0; \ + x = site = h->n_buckets; \ + k = __hash_func (key); \ + i = k & mask; \ + if (__ac_isempty (h->flags, i)) \ + x = i; /* for speed up */ \ + else { \ + last = i; \ + while (!__ac_isempty (h->flags, i) && (__ac_isdel (h->flags, i) || !__hash_equal (h->keys[i], key))) { \ + if (__ac_isdel (h->flags, i)) \ + site = i; \ + i = (i + (++step)) & mask; \ + if (i == last) { \ + x = site; \ + break; \ + } \ + } \ + if (x == h->n_buckets) { \ + if (__ac_isempty (h->flags, i) && site != h->n_buckets) \ + x = site; \ + else \ + x = i; \ + } \ + } \ + } \ + if (__ac_isempty (h->flags, x)) { /* not present at all */ \ + h->keys[x] = key; \ + __ac_set_isboth_false (h->flags, x); \ + ++h->size; \ + ++h->n_occupied; \ + *ret = 1; \ + } else if (__ac_isdel (h->flags, x)) { /* deleted */ \ + h->keys[x] = key; \ + __ac_set_isboth_false (h->flags, x); \ + ++h->size; \ + *ret = 2; \ + } else \ + *ret = 0; /* Don't touch h->keys[x] if present and not deleted */ \ + return x; \ + } \ + SCOPE void kh_del_##name(kh_##name##_t *h, khint_t x) \ + { \ + if (x != h->n_buckets && !__ac_iseither (h->flags, x)) { \ + __ac_set_isdel_true (h->flags, x); \ + --h->size; \ + } \ + } \ + +#define KHASH_DECLARE(name, khkey_t, khval_t) \ + __KHASH_TYPE(name, khkey_t, khval_t) \ + __KHASH_PROTOTYPES(name, khkey_t, khval_t) + +#define KHASH_INIT2(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \ + __KHASH_TYPE(name, khkey_t, khval_t) \ + __KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) + +#define KHASH_INIT(name, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \ + KHASH_INIT2(name, static kh_inline klib_unused, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \ + +/* --- BEGIN OF HASH FUNCTIONS --- */ + +/*! @function + @abstract Integer hash function + @param key The integer [khint32_t] + @return The hash value [khint_t] + */ +#define kh_int_hash_func(key) (khint32_t)(key) +/*! @function + @abstract Integer comparison function + */ +#define kh_int_hash_equal(a, b) ((a) == (b)) +/*! @function + @abstract 64-bit integer hash function + @param key The integer [khint64_t] + @return The hash value [khint_t] + */ +#define kh_int64_hash_func(key) (khint32_t)((key)>>33^(key)^(key)<<11) +/*! @function + @abstract 64-bit integer comparison function + */ +#define kh_int64_hash_equal(a, b) ((a) == (b)) +/*! @function + @abstract const char* hash function + @param s Pointer to a null terminated string + @return The hash value + */ +#if defined(__clang__) && defined(__clang_major__) && (__clang_major__ >= 4) +__attribute__((no_sanitize ("unsigned-integer-overflow"))) +#if (__clang_major__ >= 12) + __attribute__((no_sanitize ("unsigned-shift-base"))) +#endif +#endif +static kh_inline khint_t +__ac_X31_hash_string (const char *s) { + khint_t h = (khint_t) * s; + if (h) + for (++s; *s; ++s) + h = (h << 5) - h + (khint_t) * s; + return h; +} + +/*! @function + @abstract Another interface to const char* hash function + @param key Pointer to a null terminated string [const char*] + @return The hash value [khint_t] + */ +#define kh_str_hash_func(key) __ac_X31_hash_string(key) +/*! @function + @abstract Const char* comparison function + */ +#define kh_str_hash_equal(a, b) (strcmp(a, b) == 0) + +static kh_inline khint_t +__ac_Wang_hash (khint_t key) { + key += ~(key << 15); + key ^= (key >> 10); + key += (key << 3); + key ^= (key >> 6); + key += ~(key << 11); + key ^= (key >> 16); + return key; +} + +#define kh_int_hash_func2(k) __ac_Wang_hash((khint_t)key) + +/* --- END OF HASH FUNCTIONS --- */ + +/* Other convenient macros... */ + +/*! + @abstract Type of the hash table. + @param name Name of the hash table [symbol] + */ +#define khash_t(name) kh_##name##_t + +/*! @function + @abstract Initiate a hash table. + @param name Name of the hash table [symbol] + @return Pointer to the hash table [khash_t(name)*] + */ +#define kh_init(name) kh_init_##name() + +/*! @function + @abstract Destroy a hash table. + @param name Name of the hash table [symbol] + @param h Pointer to the hash table [khash_t(name)*] + */ +#define kh_destroy(name, h) kh_destroy_##name(h) + +/*! @function + @abstract Reset a hash table without deallocating memory. + @param name Name of the hash table [symbol] + @param h Pointer to the hash table [khash_t(name)*] + */ +#define kh_clear(name, h) kh_clear_##name(h) + +/*! @function + @abstract Resize a hash table. + @param name Name of the hash table [symbol] + @param h Pointer to the hash table [khash_t(name)*] + @param s New size [khint_t] + */ +#define kh_resize(name, h, s) kh_resize_##name(h, s) + +/*! @function + @abstract Insert a key to the hash table. + @param name Name of the hash table [symbol] + @param h Pointer to the hash table [khash_t(name)*] + @param k Key [type of keys] + @param r Extra return code: -1 if the operation failed; + 0 if the key is present in the hash table; + 1 if the bucket is empty (never used); 2 if the element in + the bucket has been deleted [int*] + @return Iterator to the inserted element [khint_t] + */ +#define kh_put(name, h, k, r) kh_put_##name(h, k, r) + +/*! @function + @abstract Retrieve a key from the hash table. + @param name Name of the hash table [symbol] + @param h Pointer to the hash table [khash_t(name)*] + @param k Key [type of keys] + @return Iterator to the found element, or kh_end(h) if the element is absent [khint_t] + */ +#define kh_get(name, h, k) kh_get_##name(h, k) + +/*! @function + @abstract Remove a key from the hash table. + @param name Name of the hash table [symbol] + @param h Pointer to the hash table [khash_t(name)*] + @param k Iterator to the element to be deleted [khint_t] + */ +#define kh_del(name, h, k) kh_del_##name(h, k) + +/*! @function + @abstract Test whether a bucket contains data. + @param h Pointer to the hash table [khash_t(name)*] + @param x Iterator to the bucket [khint_t] + @return 1 if containing data; 0 otherwise [int] + */ +#define kh_exist(h, x) (!__ac_iseither((h)->flags, (x))) + +/*! @function + @abstract Get key given an iterator + @param h Pointer to the hash table [khash_t(name)*] + @param x Iterator to the bucket [khint_t] + @return Key [type of keys] + */ +#define kh_key(h, x) ((h)->keys[x]) + +/*! @function + @abstract Get value given an iterator + @param h Pointer to the hash table [khash_t(name)*] + @param x Iterator to the bucket [khint_t] + @return Value [type of values] + @discussion For hash sets, calling this results in segfault. + */ +#define kh_val(h, x) ((h)->vals[x]) + +/*! @function + @abstract Alias of kh_val() + */ +#define kh_value(h, x) ((h)->vals[x]) + +/*! @function + @abstract Get the start iterator + @param h Pointer to the hash table [khash_t(name)*] + @return The start iterator [khint_t] + */ +#define kh_begin(h) (khint_t)(0) + +/*! @function + @abstract Get the end iterator + @param h Pointer to the hash table [khash_t(name)*] + @return The end iterator [khint_t] + */ +#define kh_end(h) ((h)->n_buckets) + +/*! @function + @abstract Get the number of elements in the hash table + @param h Pointer to the hash table [khash_t(name)*] + @return Number of elements in the hash table [khint_t] + */ +#define kh_size(h) ((h)->size) + +/*! @function + @abstract Get the number of buckets in the hash table + @param h Pointer to the hash table [khash_t(name)*] + @return Number of buckets in the hash table [khint_t] + */ +#define kh_n_buckets(h) ((h)->n_buckets) + +/*! @function + @abstract Iterate over the entries in the hash table + @param h Pointer to the hash table [khash_t(name)*] + @param kvar Variable to which key will be assigned + @param vvar Variable to which value will be assigned + @param code Block of code to execute + */ +#define kh_foreach(h, kvar, vvar, code) { khint_t __i; \ + for (__i = kh_begin(h); __i != kh_end(h); ++__i) { \ + if (!kh_exist(h,__i)) continue; \ + (kvar) = kh_key(h,__i); \ + (vvar) = kh_val(h,__i); \ + code; \ + } } + +/*! @function + @abstract Iterate over the values in the hash table + @param h Pointer to the hash table [khash_t(name)*] + @param vvar Variable to which value will be assigned + @param code Block of code to execute + */ +#define kh_foreach_value(h, vvar, code) { khint_t __i; \ + for (__i = kh_begin (h); __i != kh_end (h); ++__i) { \ + if (!kh_exist (h, __i)) \ + continue; \ + (vvar) = kh_val (h, __i); \ + code; \ + } } + +/* More convenient interfaces */ + +/*! @function + @abstract Instantiate a hash set containing integer keys + @param name Name of the hash table [symbol] + */ +#define KHASH_SET_INIT_INT(name) \ + KHASH_INIT(name, khint32_t, char, 0, kh_int_hash_func, kh_int_hash_equal) + +/*! @function + @abstract Instantiate a hash map containing integer keys + @param name Name of the hash table [symbol] + @param khval_t Type of values [type] + */ +#define KHASH_MAP_INIT_INT(name, khval_t) \ + KHASH_INIT(name, khint32_t, khval_t, 1, kh_int_hash_func, kh_int_hash_equal) + +/*! @function + @abstract Instantiate a hash map containing 64-bit integer keys + @param name Name of the hash table [symbol] + */ +#define KHASH_SET_INIT_INT64(name) \ + KHASH_INIT(name, khint64_t, char, 0, kh_int64_hash_func, kh_int64_hash_equal) + +/*! @function + @abstract Instantiate a hash map containing 64-bit integer keys + @param name Name of the hash table [symbol] + @param khval_t Type of values [type] + */ +#define KHASH_MAP_INIT_INT64(name, khval_t) \ + KHASH_INIT(name, khint64_t, khval_t, 1, kh_int64_hash_func, kh_int64_hash_equal) + +typedef const char *kh_cstr_t; +/*! @function + @abstract Instantiate a hash map containing const char* keys + @param name Name of the hash table [symbol] + */ +#define KHASH_SET_INIT_STR(name) \ + KHASH_INIT(name, kh_cstr_t, char, 0, kh_str_hash_func, kh_str_hash_equal) + +/*! @function + @abstract Instantiate a hash map containing const char* keys + @param name Name of the hash table [symbol] + @param khval_t Type of values [type] + */ +#define KHASH_MAP_INIT_STR(name, khval_t) \ + KHASH_INIT(name, kh_cstr_t, khval_t, 1, kh_str_hash_func, kh_str_hash_equal) + +#endif /* __AC_KHASH_H */ diff --git a/src/labels.h b/src/labels.h new file mode 100644 index 0000000000..b83c097f72 --- /dev/null +++ b/src/labels.h @@ -0,0 +1,591 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef LABELS_H_INCLUDED +#define LABELS_H_INCLUDED + +#ifdef ENABLE_NLS +#include + +#define _(String) dgettext (PACKAGE , String) +#else +#define _(String) (String) +#endif + +#define gettext_noop(String) String +#define N_(String) gettext_noop (String) + +/* global lang attribute */ +#define DOC_LANG _( "en") + +/* General */ +#define GEN_EXPAND_PANEL _( "Exp. Panel") +#define GEN_HELP _( "Help") +#define GEN_QUIT _( "Quit") +#define GEN_TOTAL _( "Total") + +/* Sort Labels */ +#define SORT_ASC_SEL _( "[x] ASC [ ] DESC") +#define SORT_DESC_SEL _( "[ ] ASC [x] DESC") + +/* Overall Stats Labels */ +#define T_ACTIVE_PANEL _("[Active Panel: %1$s]") +#define T_QUIT _("[q]uit GoAccess") +#define T_HELP_ENTER _("[?] Help [Enter] Exp. Panel") +#define T_DASH _( "Dashboard") +#define T_DASH_HEAD _( "Dashboard - Overall Analyzed Requests") +#define T_HEAD N_( "Overall Analyzed Requests") + +#define T_BW _( "Tx. Amount") +#define T_DATETIME _( "Date/Time") +#define T_EXCLUDE_IP _( "Excl. IP Hits") +#define T_FAILED _( "Failed Requests") +#define T_GEN_TIME _( "Log Parsing Time") +#define T_LOG _( "Log Size") +#define T_LOG_PATH _( "Log Source") +#define T_REFERRER _( "Referrers") +#define T_REQUESTS _( "Total Requests") +#define T_STATIC_FILES _( "Static Files") +#define T_UNIQUE404 _( "Not Found") +#define T_UNIQUE_FILES _( "Requested Files") +#define T_UNIQUE_VISITORS _( "Unique Visitors") +#define T_VALID _( "Valid Requests") + +/* Metric Labels */ +#define MTRC_HITS_LBL _( "Hits") +#define MTRC_HITS_PERC_LBL _( "h%") +#define MTRC_VISITORS_LBL _( "Visitors") +#define MTRC_VISITORS_SHORT_LBL _( "Vis.") +#define MTRC_VISITORS_PERC_LBL _( "v%") +#define MTRC_BW_LBL _( "Tx. Amount") +#define MTRC_AVGTS_LBL _( "Avg. T.S.") +#define MTRC_CUMTS_LBL _( "Cum. T.S.") +#define MTRC_MAXTS_LBL _( "Max. T.S.") +#define MTRC_METHODS_LBL _( "Method") +#define MTRC_METHODS_SHORT_LBL _( "Mtd") +#define MTRC_PROTOCOLS_LBL _( "Protocol") +#define MTRC_PROTOCOLS_SHORT_LBL _( "Proto") +#define MTRC_CITY_LBL _( "City") +#define MTRC_ASB_LBL _( "ASN") +#define MTRC_COUNTRY_LBL _( "Country") +#define MTRC_HOSTNAME_LBL _( "Hostname") +#define MTRC_DATA_LBL _( "Data") + +#define HTML_PLOT_HITS_VIS _( "Hits/Visitors") + +/* Panel Labels and Descriptions */ +#define VISITORS_HEAD \ + N_("Unique visitors per day") +#define VISITORS_HEAD_BOTS \ + N_("Unique visitors per day - Including spiders") +#define VISITORS_DESC \ + N_("Hits having the same IP, date and agent are a unique visit.") +#define VISITORS_LABEL \ + N_("Visitors") + +#define REQUESTS_HEAD \ + N_("Requested Files (URLs)") +#define REQUESTS_DESC \ + N_("Top requests sorted by hits [, avgts, cumts, maxts, mthd, proto]") +#define REQUESTS_LABEL \ + N_("Requests") + +#define REQUESTS_STATIC_HEAD \ + N_("Static Requests") +#define REQUESTS_STATIC_DESC \ + N_("Top static requests sorted by hits [, avgts, cumts, maxts, mthd, proto]") +#define REQUESTS_STATIC_LABEL \ + N_("Static Requests") + +#define VISIT_TIMES_HEAD \ + N_("Time Distribution") +#define VISIT_TIMES_DESC \ + N_("Data sorted by hour [, avgts, cumts, maxts]") +#define VISIT_TIMES_LABEL \ + N_("Time") + +#define VIRTUAL_HOSTS_HEAD \ + N_("Virtual Hosts") +#define VIRTUAL_HOSTS_DESC \ + N_("Data sorted by hits [, avgts, cumts, maxts]") +#define VIRTUAL_HOSTS_LABEL \ + N_("Virtual Hosts") + +#define REMOTE_USER_HEAD \ + N_("Remote User (HTTP authentication)") +#define REMOTE_USER_DESC \ + N_("Data sorted by hits [, avgts, cumts, maxts]") +#define REMOTE_USER_LABEL \ + N_("Remote User") + +#define CACHE_STATUS_HEAD \ + N_("The cache status of the object served") +#define CACHE_STATUS_DESC \ + N_("Data sorted by hits [, avgts, cumts, maxts]") +#define CACHE_STATUS_LABEL \ + N_("Cache Status") + +#define NOT_FOUND_HEAD \ + N_("Not Found URLs (404s)") +#define NOT_FOUND_DESC \ + N_("Top not found URLs sorted by hits [, avgts, cumts, maxts, mthd, proto]") +#define NOT_FOUND_LABEL \ + N_("Not Found") + +#define HOSTS_HEAD \ + N_("Visitor Hostnames and IPs") +#define HOSTS_DESC \ + N_("Top visitor hosts sorted by hits [, avgts, cumts, maxts]") +#define HOSTS_LABEL \ + N_("Hosts") + +#define OS_HEAD \ + N_("Operating Systems") +#define OS_DESC \ + N_("Top Operating Systems sorted by hits [, avgts, cumts, maxts]") +#define OS_LABEL \ + N_("OS") + +#define BROWSERS_HEAD \ + N_("Browsers") +#define BROWSERS_DESC \ + N_("Top Browsers sorted by hits [, avgts, cumts, maxts]") +#define BROWSERS_LABEL \ + N_("Browsers") + +#define REFERRERS_HEAD \ + N_("Referrer URLs") +#define REFERRERS_DESC \ + N_("Top Requested Referrers sorted by hits [, avgts, cumts, maxts]") +#define REFERRERS_LABEL \ + N_("Referrers") + +#define REFERRING_SITES_HEAD \ + N_("Referring Sites") +#define REFERRING_SITES_DESC \ + N_("Top Referring Sites sorted by hits [, avgts, cumts, maxts]") +#define REFERRING_SITES_LABEL \ + N_("Referring Sites") + +#define KEYPHRASES_HEAD \ + N_("Keyphrases from Google's search engine") +#define KEYPHRASES_DESC \ + N_("Top Keyphrases sorted by hits [, avgts, cumts, maxts]") +#define KEYPHRASES_LABEL \ + N_("Keyphrases") + +#define GEO_LOCATION_HEAD \ + N_("Geo Location") +#define GEO_LOCATION_DESC \ + N_("Continent > Country sorted by unique hits [, avgts, cumts, maxts]") +#define GEO_LOCATION_LABEL \ + N_("Geo Location") + +#define ASN_HEAD \ + N_("ASN") +#define ASN_DESC \ + N_("Autonomous System Numbers/Organizations (ASNs)") +#define ASN_LABEL \ + N_("ASN") + +#define STATUS_CODES_HEAD \ + N_("HTTP Status Codes") +#define STATUS_CODES_DESC \ + N_("Top HTTP Status Codes sorted by hits [, avgts, cumts, maxts]") +#define STATUS_CODES_LABEL \ + N_("Status Codes") + +#define MIME_TYPE_HEAD \ + N_("MIME Types") +#define MIME_TYPE_DESC \ + N_("File types shipped out") +#define MIME_TYPE_LABEL \ + N_("MIME Types") + +#define TLS_TYPE_HEAD \ + N_("Encryption settings") +#define TLS_TYPE_DESC \ + N_("TLS version and picked algorithm") +#define TLS_TYPE_LABEL \ + N_("TLS Settings") + +/* Find Labels */ +#define CISENSITIVE \ + _("[ ] case sensitive") +#define CSENSITIVE \ + _("[x] case sensitive") +#define FIND_DESC \ + _("Regex allowed - ^g to cancel - TAB switch case") +#define FIND_HEAD \ + _("Find pattern in all views") + +/* Config Dialog */ +#define CONFDLG_HEAD \ + _("Log Format Configuration") +#define CONFDLG_KEY_HINTS \ + _("[SPACE] to toggle - [ENTER] to proceed - [q] to quit") +#define CONFDLG_LOG_FORMAT \ + _("Log Format - [c] to add/edit format") +#define CONFDLG_DATE_FORMAT \ + _("Date Format - [d] to add/edit format") +#define CONFDLG_TIME_FORMAT \ + _("Time Format - [t] to add/edit format") +#define CONFDLG_DESC \ + _("[UP/DOWN] to scroll - [q] to close window") + +/* Agents Dialog */ +#define AGENTSDLG_DESC \ + _("[UP/DOWN] to scroll - [q] to close window") +#define AGENTSDLG_HEAD \ + _("User Agents for %1$s") + +/* Color Scheme Dialog */ +#define SCHEMEDLG_HEAD \ + _("Scheme Configuration") +#define SCHEMEDLG_DESC \ + _("[ENTER] to use scheme - [q]uit") + +/* Sort Dialog */ +#define SORTDLG_HEAD \ + _("Sort active module by") +#define SORTDLG_DESC \ + _("[ENTER] select - [TAB] sort - [q]uit") + +/* Help TUI Dialog */ +#define HELPDLG_HEAD \ + _("GoAccess Quick Help") +#define HELPDLG_DESC \ + _("[UP/DOWN] to scroll - [q] to quit") + +/* Storage Built-in Option */ +#define BUILT_WITH_DEFHASH \ + _("In-Memory with On-Disk Persistent Storage.") + +/* Common UI Errors */ +#define ERR_FORMAT_HEADER \ + _("Format Errors - Verify your log/date/time format") +#define ERR_FORMAT_NO_DATE_FMT \ + _("No date format was found on your conf file.") +#define ERR_FORMAT_NO_LOG_FMT \ + _("No log format was found on your conf file.") +#define ERR_FORMAT_NO_TIME_FMT \ + _("No time format was found on your conf file.") +#define ERR_NODEF_CONF_FILE \ + _("No default config file found.") +#define ERR_NODEF_CONF_FILE_DESC \ + _("You may specify one with") +#define ERR_PARSED_NLINES_DESC \ + _("producing the following errors") +#define ERR_PARSED_NLINES \ + _("Parsed %1$d lines") +#define ERR_PLEASE_REPORT \ + _("Please report it by opening an issue on GitHub") +#define ERR_FORMAT_NO_TIME_FMT_DLG \ + _("Select a time format.") +#define ERR_FORMAT_NO_DATE_FMT_DLG \ + _("Select a date format.") +#define ERR_FORMAT_NO_LOG_FMT_DLG \ + _("Select a log format.") +#define ERR_PANEL_DISABLED \ + _("'%1$s' panel is disabled") +#define ERR_NO_DATA_PASSED \ + _("No input data was provided nor there's data to restore.") +#define ERR_LOG_REALLOC_FAILURE_MSG \ + _("Unable to allocate memory for a log instance.") +#define ERR_LOG_NOT_FOUND_MSG \ + _("Unable to find the given log.") + +/* Other */ +#define INFO_MORE_INFO \ + _("For more details visit") +#define INFO_LAST_UPDATED \ + _("Last Updated") +#define INFO_WS_READY_FOR_CONN \ + _("WebSocket server ready to accept new client connections") + +#define INFO_HELP_FOLLOWING_OPTS \ + _("The following options can also be supplied to the command") +#define INFO_HELP_EXAMPLES \ + _("Examples can be found by running") + +#define HTML_REPORT_TITLE \ + _( "Server Statistics") +#define HTML_REPORT_NAV_THEME \ + N_("Theme") +#define HTML_REPORT_NAV_DARK_GRAY \ + N_("Dark Gray") +#define HTML_REPORT_NAV_BRIGHT \ + N_("Bright") +#define HTML_REPORT_NAV_DARK_BLUE \ + N_("Dark Blue") +#define HTML_REPORT_NAV_DARK_PURPLE \ + N_("Dark Purple") +#define HTML_REPORT_NAV_PANELS \ + N_("Panels") +#define HTML_REPORT_NAV_ITEMS_PER_PAGE \ + N_("Items per Page") +#define HTML_REPORT_NAV_TABLES \ + N_("Tables") +#define HTML_REPORT_NAV_DISPLAY_TABLES \ + N_("Display Tables") +#define HTML_REPORT_NAV_AH_SMALL \ + N_("Auto-Hide on Small Devices") +#define HTML_REPORT_NAV_AH_SMALL_TITLE \ + N_("Automatically hide tables on small screen devices") +#define HTML_REPORT_NAV_TOGGLE_PANEL \ + N_("Toggle Panel") +#define HTML_REPORT_NAV_LAYOUT \ + N_("Layout") +#define HTML_REPORT_NAV_HOR \ + N_("Horizontal") +#define HTML_REPORT_NAV_VER \ + N_("Vertical") +#define HTML_REPORT_NAV_WIDE \ + N_("WideScreen") +#define HTML_REPORT_NAV_FILE_OPTS \ + N_("File Options") +#define HTML_REPORT_NAV_EXPORT_JSON \ + N_("Export as JSON") +#define HTML_REPORT_PANEL_PANEL_OPTS \ + N_("Panel Options") +#define HTML_REPORT_PANEL_PREVIOUS \ + N_("Previous") +#define HTML_REPORT_PANEL_NEXT \ + N_("Next") +#define HTML_REPORT_PANEL_FIRST \ + N_("First") +#define HTML_REPORT_PANEL_LAST \ + N_("Last") +#define HTML_REPORT_PANEL_CHART_OPTS \ + N_("Chart Options") +#define HTML_REPORT_PANEL_CHART \ + N_("Chart") +#define HTML_REPORT_PANEL_TYPE \ + N_("Type") +#define HTML_REPORT_PANEL_AREA_SPLINE \ + N_("Area Spline") +#define HTML_REPORT_PANEL_BAR \ + N_("Bar") +#define HTML_REPORT_PANEL_WMAP \ + N_("World Map") +#define HTML_REPORT_PANEL_PLOT_METRIC \ + N_("Plot Metric") +#define HTML_REPORT_PANEL_TABLE_COLS \ + N_("Table Columns") + +/* Status Codes */ +#define STATUS_CODE_0XX \ + N_("0xx Unofficial Codes") +#define STATUS_CODE_1XX \ + N_("1xx Informational") +#define STATUS_CODE_2XX \ + N_("2xx Success") +#define STATUS_CODE_3XX \ + N_("3xx Redirection") +#define STATUS_CODE_4XX \ + N_("4xx Client Errors") +#define STATUS_CODE_5XX \ + N_("5xx Server Errors") + +#define STATUS_CODE_0 \ + N_("0 - Caddy: Unhandled - No configured routes") +#define STATUS_CODE_100 \ + N_("100 - Continue: Server received the initial part of the request") +#define STATUS_CODE_101 \ + N_("101 - Switching Protocols: Client asked to switch protocols") +#define STATUS_CODE_200 \ + N_("200 - OK: The request sent by the client was successful") +#define STATUS_CODE_201 \ + N_("201 - Created: The request has been fulfilled and created") +#define STATUS_CODE_202 \ + N_("202 - Accepted: The request has been accepted for processing") +#define STATUS_CODE_203 \ + N_("203 - Non-authoritative Information: Response from a third party") +#define STATUS_CODE_204 \ + N_("204 - No Content: Request did not return any content") +#define STATUS_CODE_205 \ + N_("205 - Reset Content: Server asked the client to reset the document") +#define STATUS_CODE_206 \ + N_("206 - Partial Content: The partial GET has been successful") +#define STATUS_CODE_207 \ + N_("207 - Multi-Status: WebDAV; RFC 4918") +#define STATUS_CODE_208 \ + N_("208 - Already Reported: WebDAV; RFC 5842") +#define STATUS_CODE_218 \ + N_("218 - This is fine: Apache servers. A catch-all error condition") +#define STATUS_CODE_300 \ + N_("300 - Multiple Choices: Multiple options for the resource") +#define STATUS_CODE_301 \ + N_("301 - Moved Permanently: Resource has permanently moved") +#define STATUS_CODE_302 \ + N_("302 - Moved Temporarily (redirect)") +#define STATUS_CODE_303 \ + N_("303 - See Other Document: The response is at a different URI") +#define STATUS_CODE_304 \ + N_("304 - Not Modified: Resource has not been modified") +#define STATUS_CODE_305 \ + N_("305 - Use Proxy: Can only be accessed through the proxy") +#define STATUS_CODE_307 \ + N_("307 - Temporary Redirect: Resource temporarily moved") +#define STATUS_CODE_308 \ + N_("308 - Permanent Redirect") +#define STATUS_CODE_400 \ + N_("400 - Bad Request: The syntax of the request is invalid") +#define STATUS_CODE_401 \ + N_("401 - Unauthorized: Request needs user authentication") +#define STATUS_CODE_402 \ + N_("402 - Payment Required") +#define STATUS_CODE_403 \ + N_("403 - Forbidden: Server is refusing to respond to it") +#define STATUS_CODE_404 \ + N_("404 - Not Found: Requested resource could not be found") +#define STATUS_CODE_405 \ + N_("405 - Method Not Allowed: Request method not supported") +#define STATUS_CODE_406 \ + N_("406 - Not Acceptable") +#define STATUS_CODE_407 \ + N_("407 - Proxy Authentication Required") +#define STATUS_CODE_408 \ + N_("408 - Request Timeout: Server timed out waiting for the request") +#define STATUS_CODE_409 \ + N_("409 - Conflict: Conflict in the request") +#define STATUS_CODE_410 \ + N_("410 - Gone: Resource requested is no longer available") +#define STATUS_CODE_411 \ + N_("411 - Length Required: Invalid Content-Length") +#define STATUS_CODE_412 \ + N_("412 - Precondition Failed: Server does not meet preconditions") +#define STATUS_CODE_413 \ + N_("413 - Payload Too Large") +#define STATUS_CODE_414 \ + N_("414 - Request-URI Too Long") +#define STATUS_CODE_415 \ + N_("415 - Unsupported Media Type: Media type is not supported") +#define STATUS_CODE_416 \ + N_("416 - Requested Range Not Satisfiable: Cannot supply that portion") +#define STATUS_CODE_417 \ + N_("417 - Expectation Failed") +#define STATUS_CODE_418 \ + N_("418 - I'm a teapot") +#define STATUS_CODE_419 \ + N_("419 - Page Expired: Laravel Framework when a CSRF Token is missing") +#define STATUS_CODE_420 \ + N_("420 - Method Failure: Spring Framework when a method has failed") +#define STATUS_CODE_421 \ + N_("421 - Misdirected Request") +#define STATUS_CODE_422 \ + N_("422 - Unprocessable Entity due to semantic errors: WebDAV") +#define STATUS_CODE_423 \ + N_("423 - The resource that is being accessed is locked") +#define STATUS_CODE_424 \ + N_("424 - Failed Dependency: WebDAV") +#define STATUS_CODE_426 \ + N_("426 - Upgrade Required: Client should switch to a different protocol") +#define STATUS_CODE_428 \ + N_("428 - Precondition Required") +#define STATUS_CODE_429 \ + N_("429 - Too Many Requests: The user has sent too many requests") +#define STATUS_CODE_430 \ + N_("430 - Request Header Fields Too Large: Too many URLs are requested within a certain time frame") +#define STATUS_CODE_431 \ + N_("431 - Request Header Fields Too Large") +#define STATUS_CODE_440 \ + N_("440 - Login Time-out: The client's session has expired") +#define STATUS_CODE_449 \ + N_("449 - Retry With: The server cannot honour the request") +#define STATUS_CODE_450 \ + N_("450 - Blocked by Windows Parental Controls: The Microsoft extension code indicated") +#define STATUS_CODE_451 \ + N_("451 - Unavailable For Legal Reasons") +#define STATUS_CODE_444 \ + N_("444 - (Nginx) Connection closed without sending any headers") +#define STATUS_CODE_460 \ + N_("460 - AWS Elastic Load Balancing: Client closed the connection ") +#define STATUS_CODE_463 \ + N_("463 - AWS Elastic Load Balancing: The load balancer received more than 30 IP addresses") +#define STATUS_CODE_464 \ + N_("464 - AWS Elastic Load Balancing: Incompatible protocol versions") +#define STATUS_CODE_494 \ + N_("494 - (Nginx) Request Header Too Large") +#define STATUS_CODE_495 \ + N_("495 - (Nginx) SSL client certificate error") +#define STATUS_CODE_496 \ + N_("496 - (Nginx) Client didn't provide certificate") +#define STATUS_CODE_497 \ + N_("497 - (Nginx) HTTP request sent to HTTPS port") +#define STATUS_CODE_498 \ + N_("498 - Invalid Token: an expired or otherwise invalid token") +#define STATUS_CODE_499 \ + N_("499 - (Nginx) Connection closed by client while processing request") +#define STATUS_CODE_500 \ + N_("500 - Internal Server Error") +#define STATUS_CODE_501 \ + N_("501 - Not Implemented") +#define STATUS_CODE_502 \ + N_("502 - Bad Gateway: Received an invalid response from the upstream") +#define STATUS_CODE_503 \ + N_("503 - Service Unavailable: The server is currently unavailable") +#define STATUS_CODE_504 \ + N_("504 - Gateway Timeout: The upstream server failed to send request") +#define STATUS_CODE_505 \ + N_("505 - HTTP Version Not Supported") +#define STATUS_CODE_509 \ + N_("509 - Bandwidth Limit Exceeded: The server has exceeded the bandwidth") +#define STATUS_CODE_520 \ + N_("520 - CloudFlare - Web server is returning an unknown error") +#define STATUS_CODE_521 \ + N_("521 - CloudFlare - Web server is down") +#define STATUS_CODE_522 \ + N_("522 - CloudFlare - Connection timed out") +#define STATUS_CODE_523 \ + N_("523 - CloudFlare - Origin is unreachable") +#define STATUS_CODE_524 \ + N_("524 - CloudFlare - A timeout occurred") +#define STATUS_CODE_525 \ + N_("525 - SSL Handshake Failed: Cloudflare could not negotiate a SSL/TLS handshake") +#define STATUS_CODE_526 \ + N_("526 - Invalid SSL Certificate: Cloudflare could not validate the SSL certificate") +#define STATUS_CODE_527 \ + N_("527 - Railgun Error: An interrupted connection") +#define STATUS_CODE_529 \ + N_("529 - Site is overloaded: A site can not process the request") +#define STATUS_CODE_530 \ + N_("530 - Site is frozen: A site has been frozen due to inactivity") +#define STATUS_CODE_540 \ + N_("540 - Temporarily Disabled: The requested endpoint has been temporarily disabled") +#define STATUS_CODE_561 \ + N_("561 - Unauthorized: An error around authentication") +#define STATUS_CODE_598 \ + N_("598 - Network read timeout error: some HTTP proxies to signal a network read timeout") +#define STATUS_CODE_599 \ + N_("599 - Network Connect Timeout Error: An error used by some HTTP proxies") +#define STATUS_CODE_783 \ + N_("783 - Unexpected Token: The request includes a JSON syntax error") + +#endif // for #ifndef LABELS_H diff --git a/src/opesys.c b/src/opesys.c new file mode 100644 index 0000000000..4c00442a7b --- /dev/null +++ b/src/opesys.c @@ -0,0 +1,437 @@ +/** + * opesys.c -- functions for dealing with operating systems + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include + +#include "opesys.h" + +#include "error.h" +#include "settings.h" +#include "util.h" +#include "xmalloc.h" + +/* ###NOTE: The size of the list is proportional to the run time, + * which makes this pretty slow */ + +/* {"search string", "belongs to"} */ +static const char *const os[][2] = { + {"Android", "Android"}, + {"Windows NT 10.0", "Windows"}, + {"Windows NT 6.3; ARM", "Windows"}, + {"Windows NT 6.3", "Windows"}, + {"Windows NT 6.2; ARM", "Windows"}, + {"Windows NT 6.2", "Windows"}, + {"Windows NT 6.1", "Windows"}, + {"Windows NT 6.0", "Windows"}, + {"Windows NT 5.2", "Windows"}, + {"Windows NT 5.1", "Windows"}, + {"Windows NT 5.01", "Windows"}, + {"Windows NT 5.0", "Windows"}, + {"Windows NT 4.0", "Windows"}, + {"Windows NT", "Windows"}, + {"Win 9x 4.90", "Windows"}, + {"Windows 98", "Windows"}, + {"Windows 95", "Windows"}, + {"Windows CE", "Windows"}, + {"Windows Phone 8.1", "Windows"}, + {"Windows Phone 8.0", "Windows"}, + {"Windows", "Windows"}, + + {"Googlebot", "Unix-like"}, + {"Mastodon", "Unix-like"}, + {"bingbot", "Windows"}, + + {"iPad", "iOS"}, + {"iPod", "iOS"}, + {"iPhone", "iOS"}, + {"CFNetwork", "iOS"}, + {"AppleTV", "iOS"}, + {"iTunes", "macOS"}, + {"OS X", "macOS"}, + {"macOS", "macOS"}, + {"Darwin", "Darwin"}, + + {"AlmaLinux", "Linux"}, + {"Amazon Linux", "Linux"}, + {"CloudLinux", "Linux"}, + {"Debian", "Linux"}, + {"Ubuntu", "Linux"}, + {"Fedora", "Linux"}, + {"Mint", "Linux"}, + {"SUSE", "Linux"}, + {"Mandriva", "Linux"}, + {"MIRACLE LINUX", "Linux"}, + {"Oracle Linux", "Linux"}, + {"Red Hat Enterprise Linux", "Linux"}, + {"Rocky Linux", "Linux"}, + {"Gentoo", "Linux"}, + {"CentOS Stream", "Linux"}, + {"CentOS Linux", "Linux"}, + {"PCLinuxOS", "Linux"}, + {"Arch", "Linux"}, + {"Parabola", "Linux"}, + + {"FreeBSD", "BSD"}, + {"NetBSD", "BSD"}, + {"OpenBSD", "BSD"}, + {"DragonFly", "BSD"}, + + {"PlayStation", "BSD"}, + + {"Linux", "Linux"}, + {"linux", "Linux"}, + + {"CrOS", "Chrome OS"}, + {"QNX", "Unix-like"}, + {"BB10", "Unix-like"}, + + {"AIX", "Unix"}, + {"SunOS", "Unix"}, + + {"BlackBerry", "Others"}, + {"Sony", "Others"}, + {"AmigaOS", "Others"}, + {"SymbianOS", "Others"}, + {"Nokia", "Others"}, + {"Nintendo", "Others"}, + {"Apache", "Others"}, + {"Xbox One", "Windows"}, + {"Xbox", "Windows"}, +}; + +/* Get the Android code name (if applicable). + * + * On error, the given name is allocated and returned. + * On success, the matching Android codename is allocated and + * returned. */ +static char * +get_real_android (const char *droid) { + if (strstr (droid, "14")) + return alloc_string ("Android 14"); + else if (strstr (droid, "13")) + return alloc_string ("Android 13"); + else if (strstr (droid, "12")) + return alloc_string ("Android 12"); + else if (strstr (droid, "12.1")) + return alloc_string ("Android 12.1"); + else if (strstr (droid, "11")) + return alloc_string ("Android 11"); + else if (strstr (droid, "10")) + return alloc_string ("Android 10"); + else if (strstr (droid, "9")) + return alloc_string ("Pie 9"); + else if (strstr (droid, "8.1")) + return alloc_string ("Oreo 8.1"); + else if (strstr (droid, "8.0")) + return alloc_string ("Oreo 8.0"); + else if (strstr (droid, "7.1")) + return alloc_string ("Nougat 7.1"); + else if (strstr (droid, "7.0")) + return alloc_string ("Nougat 7.0"); + else if (strstr (droid, "6.0.1")) + return alloc_string ("Marshmallow 6.0.1"); + else if (strstr (droid, "6.0")) + return alloc_string ("Marshmallow 6.0"); + else if (strstr (droid, "5.1")) + return alloc_string ("Lollipop 5.1"); + else if (strstr (droid, "5.0")) + return alloc_string ("Lollipop 5.0"); + else if (strstr (droid, "4.4")) + return alloc_string ("KitKat 4.4"); + else if (strstr (droid, "4.3")) + return alloc_string ("Jelly Bean 4.3"); + else if (strstr (droid, "4.2")) + return alloc_string ("Jelly Bean 4.2"); + else if (strstr (droid, "4.1")) + return alloc_string ("Jelly Bean 4.1"); + else if (strstr (droid, "4.0")) + return alloc_string ("Ice Cream Sandwich 4.0"); + else if (strstr (droid, "3.")) + return alloc_string ("Honeycomb 3"); + else if (strstr (droid, "2.3")) + return alloc_string ("Gingerbread 2.3"); + else if (strstr (droid, "2.2")) + return alloc_string ("Froyo 2.2"); + else if (strstr (droid, "2.0") || strstr (droid, "2.1")) + return alloc_string ("Eclair 2"); + else if (strstr (droid, "1.6")) + return alloc_string ("Donut 1.6"); + else if (strstr (droid, "1.5")) + return alloc_string ("Cupcake 1.5"); + return alloc_string (droid); +} + +/* Get the Windows marketing name (if applicable). + * + * On error, the given name is allocated and returned. + * On success, the matching Windows marketing name is allocated and + * returned. */ +static char * +get_real_win (const char *win) { + if (strstr (win, "10.0")) + return alloc_string ("Windows 10"); + else if (strstr (win, "6.3")) + return alloc_string ("Windows 8.1"); + else if (strstr (win, "6.3; ARM")) + return alloc_string ("Windows RT"); + else if (strstr (win, "6.2; ARM")) + return alloc_string ("Windows RT"); + else if (strstr (win, "6.2")) + return alloc_string ("Windows 8"); + else if (strstr (win, "6.1")) + return alloc_string ("Windows 7"); + else if (strstr (win, "6.0")) + return alloc_string ("Windows Vista"); + else if (strstr (win, "5.2")) + return alloc_string ("Windows XP x64"); + else if (strstr (win, "5.1")) + return alloc_string ("Windows XP"); + else if (strstr (win, "5.0")) + return alloc_string ("Windows 2000"); + return NULL; +} + +/* Get the Mac OS X code name (if applicable). + * + * On error, the given name is allocated and returned. + * On success, the matching Mac OS X codename is allocated and + * returned. */ +static char * +get_real_mac_osx (const char *osx) { + if (strstr (osx, "14.0")) + return alloc_string ("macOS 14 Sonoma"); + else if (strstr (osx, "13.0")) + return alloc_string ("macOS 13 Ventura"); + else if (strstr (osx, "12.0")) + return alloc_string ("macOS 12 Monterey"); + else if (strstr (osx, "11.0")) + return alloc_string ("macOS 11 Big Sur"); + else if (strstr (osx, "10.15")) + return alloc_string ("macOS 10.15 Catalina"); + else if (strstr (osx, "10.14")) + return alloc_string ("macOS 10.14 Mojave"); + else if (strstr (osx, "10.13")) + return alloc_string ("macOS 10.13 High Sierra"); + else if (strstr (osx, "10.12")) + return alloc_string ("macOS 10.12 Sierra"); + else if (strstr (osx, "10.11")) + return alloc_string ("OS X 10.11 El Capitan"); + else if (strstr (osx, "10.10")) + return alloc_string ("OS X 10.10 Yosemite"); + else if (strstr (osx, "10.9")) + return alloc_string ("OS X 10.9 Mavericks"); + else if (strstr (osx, "10.8")) + return alloc_string ("OS X 10.8 Mountain Lion"); + else if (strstr (osx, "10.7")) + return alloc_string ("OS X 10.7 Lion"); + else if (strstr (osx, "10.6")) + return alloc_string ("OS X 10.6 Snow Leopard"); + else if (strstr (osx, "10.5")) + return alloc_string ("OS X 10.5 Leopard"); + else if (strstr (osx, "10.4")) + return alloc_string ("OS X 10.4 Tiger"); + else if (strstr (osx, "10.3")) + return alloc_string ("OS X 10.3 Panther"); + else if (strstr (osx, "10.2")) + return alloc_string ("OS X 10.2 Jaguar"); + else if (strstr (osx, "10.1")) + return alloc_string ("OS X 10.1 Puma"); + else if (strstr (osx, "10.0")) + return alloc_string ("OS X 10.0 Cheetah"); + return alloc_string (osx); +} + +/* Parse all other operating systems. + * + * On error, the given name is returned. + * On success, the parsed OS is returned. */ +static char * +parse_others (char *agent, int spaces) { + char *p; + int space = 0; + p = agent; + /* assume the following chars are within the given agent */ + while (*p != ';' && *p != ')' && *p != '(' && *p != '\0') { + if (*p == ' ') + space++; + if (space > spaces) + break; + p++; + } + *p = 0; + + return agent; +} + +/* Parse iOS string including version number. + * + * On error, the matching token is returned (no version). + * On success, the parsed iOS is returned. */ +static char * +parse_ios (char *agent, int tlen) { + char *p = NULL, *q = NULL; + ptrdiff_t offset; + + if ((p = strstr (agent, " OS ")) == NULL) + goto out; + + if ((offset = p - agent) <= 0) + goto out; + + if ((q = strstr (p, " like Mac")) == NULL) + goto out; + + *q = 0; + memmove (agent + tlen, agent + offset, offset); + return char_replace (agent, '_', '.'); + +out: + agent[tlen] = 0; + return agent; +} + +/* Parse a Mac OS X string. + * + * On error, the given name is returned. + * On success, the parsed Mac OS X is returned. */ +static char * +parse_osx (char *agent) { + int space = 0; + char *p; + + p = agent; + /* assume the following chars are within the given agent */ + while (*p != ';' && *p != ')' && *p != '(' && *p != '\0') { + if (*p == '_') + *p = '.'; + if (*p == ' ') + space++; + if (space > 3) + break; + p++; + } + *p = 0; + + return agent; +} + +/* Parse an Android string. + * + * On error, the given name is returned. + * On success, the parsed Android is returned. */ +static char * +parse_android (char *agent) { + char *p; + p = agent; + /* assume the following chars are within the given agent */ + while (*p != ';' && *p != ')' && *p != '(' && *p != '\0') + p++; + *p = 0; + + return agent; +} + +/* Attempt to parse specific OS. + * + * On success, a malloc'd string containing the OS is returned. */ +static char * +parse_os (char *str, char *tkn, char *os_type, int idx) { + char *b; + int spaces = 0; + + xstrncpy (os_type, os[idx][1], OPESYS_TYPE_LEN); + /* Windows */ + if ((strstr (str, "Windows")) != NULL) + return conf.real_os && (b = get_real_win (tkn)) ? b : xstrdup (os[idx][0]); + /* Android */ + if ((strstr (tkn, "Android")) != NULL) { + tkn = parse_android (tkn); + return conf.real_os ? get_real_android (tkn) : xstrdup (tkn); + } + /* iOS */ + if ((strstr (tkn, "CFNetwork")) != NULL) { + if ((b = strchr (str, ' '))) + *b = 0; + return xstrdup (str); + } + if (strstr (tkn, "iPad") || strstr (tkn, "iPod")) + return xstrdup (parse_ios (tkn, 4)); + if (strstr (tkn, "iPhone")) + return xstrdup (parse_ios (tkn, 6)); + /* Mac OS X */ + if (strstr (tkn, "OS X") || strstr (tkn, "macOS")) { + tkn = parse_osx (tkn); + return conf.real_os ? get_real_mac_osx (tkn) : xstrdup (tkn); + } + /* Darwin - capture the first part of agents such as: + * Slack/248000 CFNetwork/808.0.2 Darwin/16.0.0 */ + if ((strstr (tkn, "Darwin")) != NULL) { + if ((b = strchr (str, ' '))) + *b = 0; + return xstrdup (str); + } + /* all others */ + spaces = count_matches (os[idx][0], ' '); + + return alloc_string (parse_others (tkn, spaces)); +} + +/* Given a user agent, determine the operating system used. + * + * ###NOTE: The size of the list is proportional to the run time, + * which makes this pretty slow + * + * On error, NULL is returned. + * On success, a malloc'd string containing the OS is returned. */ +char * +verify_os (char *str, char *os_type) { + char *a; + size_t i; + + if (str == NULL || *str == '\0') + return NULL; + + str = char_replace (str, '+', ' '); + for (i = 0; i < ARRAY_SIZE (os); i++) { + if ((a = strstr (str, os[i][0])) != NULL) + return parse_os (str, a, os_type, i); + } + + if (conf.unknowns_as_crawlers && strcmp (os_type, "Crawlers")) + xstrncpy (os_type, "Crawlers", OPESYS_TYPE_LEN); + else + xstrncpy (os_type, "Unknown", OPESYS_TYPE_LEN); + + if (conf.unknowns_log) + LOG_UNKNOWNS (("%-7s%s\n", "[OS]", str)); + + return alloc_string ("Unknown"); +} diff --git a/src/opesys.h b/src/opesys.h new file mode 100644 index 0000000000..d4ba500f06 --- /dev/null +++ b/src/opesys.h @@ -0,0 +1,43 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef OPESYS_H_INCLUDED +#define OPESYS_H_INCLUDED + +#define OPESYS_TYPE_LEN 10 + +/* Each OS contains the number of hits and the OS's type */ +typedef struct GOpeSys_ { + char os_type[OPESYS_TYPE_LEN]; + int hits; +} GOpeSys; + +char *verify_os (char *str, char *os_type); + +#endif diff --git a/src/options.c b/src/options.c new file mode 100644 index 0000000000..ec4659f17d --- /dev/null +++ b/src/options.c @@ -0,0 +1,894 @@ +/** + * options.c -- functions related to parsing program options + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +#ifdef HAVE_LIBGEOIP +#include +#endif + +#include "options.h" + +#include "error.h" +#include "labels.h" +#include "util.h" + +#include "xmalloc.h" + +static const char *short_options = "b:e:f:j:l:o:p:H:M:S:" +#ifdef HAVE_LIBGEOIP + "g" +#endif + "acdhimqrsV"; + +/* *INDENT-OFF* */ +static const struct option long_opts[] = { + {"agent-list" , no_argument , 0 , 'a' } , + {"browsers-file" , required_argument , 0 , 'b' } , + {"config-dialog" , no_argument , 0 , 'c' } , + {"config-file" , required_argument , 0 , 'p' } , + {"debug-file" , required_argument , 0 , 'l' } , + {"exclude-ip" , required_argument , 0 , 'e' } , +#ifdef HAVE_LIBGEOIP + {"std-geoip" , no_argument , 0 , 'g' } , +#endif + {"help" , no_argument , 0 , 'h' } , + {"hl-header" , no_argument , 0 , 'i' } , + {"http-method" , required_argument , 0 , 'M' } , + {"http-protocol" , required_argument , 0 , 'H' } , + {"jobs" , required_argument , 0 , 'j' } , + {"log-file" , required_argument , 0 , 'f' } , + {"log-size" , required_argument , 0 , 'S' } , + {"no-query-string" , no_argument , 0 , 'q' } , + {"no-term-resolver" , no_argument , 0 , 'r' } , + {"output" , required_argument , 0 , 'o' } , + {"storage" , no_argument , 0 , 's' } , + {"version" , no_argument , 0 , 'V' } , + {"with-mouse" , no_argument , 0 , 'm' } , + {"with-output-resolver" , no_argument , 0 , 'd' } , + {"444-as-404" , no_argument , 0 , 0 } , + {"4xx-to-unique-count" , no_argument , 0 , 0 } , + {"addr" , required_argument , 0 , 0 } , + {"unix-socket" , required_argument , 0 , 0 } , + {"all-static-files" , no_argument , 0 , 0 } , + {"anonymize-ip" , no_argument , 0 , 0 } , + {"anonymize-level" , required_argument , 0 , 0 } , + {"color" , required_argument , 0 , 0 } , + {"color-scheme" , required_argument , 0 , 0 } , + {"crawlers-only" , no_argument , 0 , 0 } , + {"chunk-size" , required_argument , 0 , 0 } , + {"daemonize" , no_argument , 0 , 0 } , + {"datetime-format" , required_argument , 0 , 0 } , + {"date-format" , required_argument , 0 , 0 } , + {"date-spec" , required_argument , 0 , 0 } , + {"db-path" , required_argument , 0 , 0 } , + {"fname-as-vhost" , required_argument , 0 , 0 } , + {"dcf" , no_argument , 0 , 0 } , + {"double-decode" , no_argument , 0 , 0 } , + {"external-assets" , no_argument , 0 , 0 } , + {"enable-panel" , required_argument , 0 , 0 } , + {"fifo-in" , required_argument , 0 , 0 } , + {"fifo-out" , required_argument , 0 , 0 } , + {"hide-referrer" , required_argument , 0 , 0 } , + {"hour-spec" , required_argument , 0 , 0 } , + {"html-custom-css" , required_argument , 0 , 0 } , + {"html-custom-js" , required_argument , 0 , 0 } , + {"html-prefs" , required_argument , 0 , 0 } , + {"html-report-title" , required_argument , 0 , 0 } , + {"ignore-crawlers" , no_argument , 0 , 0 } , + {"ignore-panel" , required_argument , 0 , 0 } , + {"ignore-referrer" , required_argument , 0 , 0 } , + {"ignore-statics" , required_argument , 0 , 0 } , + {"ignore-status" , required_argument , 0 , 0 } , + {"invalid-requests" , required_argument , 0 , 0 } , + {"unknowns-log" , required_argument , 0 , 0 } , + {"json-pretty-print" , no_argument , 0 , 0 } , + {"keep-last" , required_argument , 0 , 0 } , + {"html-refresh" , required_argument , 0 , 0 } , + {"log-format" , required_argument , 0 , 0 } , + {"max-items" , required_argument , 0 , 0 } , + {"no-color" , no_argument , 0 , 0 } , + {"no-strict-status" , no_argument , 0 , 0 } , + {"no-column-names" , no_argument , 0 , 0 } , + {"no-csv-summary" , no_argument , 0 , 0 } , + {"no-global-config" , no_argument , 0 , 0 } , + {"no-html-last-updated" , no_argument , 0 , 0 } , + {"no-ip-validation" , no_argument , 0 , 0 } , + {"no-parsing-spinner" , no_argument , 0 , 0 } , + {"no-progress" , no_argument , 0 , 0 } , + {"no-tab-scroll" , no_argument , 0 , 0 } , + {"num-tests" , required_argument , 0 , 0 } , + {"origin" , required_argument , 0 , 0 } , + {"output-format" , required_argument , 0 , 0 } , + {"persist" , no_argument , 0 , 0 } , + {"pid-file" , required_argument , 0 , 0 } , + {"port" , required_argument , 0 , 0 } , + {"process-and-exit" , no_argument , 0 , 0 } , + {"real-os" , no_argument , 0 , 0 } , + {"real-time-html" , no_argument , 0 , 0 } , + {"restore" , no_argument , 0 , 0 } , + {"sort-panel" , required_argument , 0 , 0 } , + {"static-file" , required_argument , 0 , 0 } , + {"tz" , required_argument , 0 , 0 } , + {"unknowns-as-crawlers" , no_argument , 0 , 0 } , + {"user-name" , required_argument , 0 , 0 } , +#ifdef HAVE_LIBSSL + {"ssl-cert" , required_argument , 0 , 0 } , + {"ssl-key" , required_argument , 0 , 0 } , +#endif + {"time-format" , required_argument , 0 , 0 } , + {"ws-url" , required_argument , 0 , 0 } , + {"ping-interval" , required_argument , 0 , 0 } , +#ifdef HAVE_GEOLOCATION + {"geoip-database" , required_argument , 0 , 0 } , +#endif + {0, 0, 0, 0} +}; + +/* Command line help. */ +void +cmd_help (void) +{ + printf ("\nGoAccess - %s\n\n", GO_VERSION); + printf ( + "Usage: " + "goaccess [filename] [ options ... ] [-c][-M][-H][-S][-q][-d][...]\n" + "%s:\n\n", INFO_HELP_FOLLOWING_OPTS); + + printf ( + /* Log & Date Format Options */ + CYN "LOG & DATE FORMAT OPTIONS" RESET + "\n\n" + " --log-format= - Specify log format. Inner quotes need\n" + " escaping, or use single quotes.\n" + " --date-format= - Specify log date format. e.g., %%d/%%b/%%Y\n" + " --time-format= - Specify log time format. e.g., %%H:%%M:%%S\n" + " --datetime-format= - Specify log date and time format. e.g.,\n" + " %%d/%%b/%%Y %%H:%%M:%%S %%z\n" + "\n" + /* User Interface Options */ + CYN "USER INTERFACE OPTIONS" RESET + "\n\n" + " -c --config-dialog - Prompt log/date/time configuration window.\n" + " -i --hl-header - Color highlight active panel.\n" + " -m --with-mouse - Enable mouse support on main dashboard.\n" + " --color= - Specify custom colors. See manpage for more\n" + " details.\n" + " --color-scheme=<1|2|3> - Schemes: 1 => Grey, 2 => Green, 3 =>\n" + " Monokai.\n" + " --html-custom-css= - Specify a custom CSS file in the HTML\n" + " report.\n" + " --html-custom-js= - Specify a custom JS file in the HTML\n" + " report.\n" + " --html-prefs= - Set default HTML report preferences.\n" + " --html-report-title= - Set HTML report page title and header.\n" + " --html-refresh=<secs> - Refresh HTML report every X seconds (>=1 or\n" + " <=60).\n" + " --json-pretty-print - Format JSON output w/ tabs & newlines.\n" + " --max-items - Maximum number of items to show per panel.\n" + " See man page for limits.\n" + " --no-color - Disable colored output.\n" + " --no-column-names - Don't write column names in term output.\n" + " --no-csv-summary - Disable summary metrics on the CSV output.\n" + " --no-html-last-updated - Hide HTML last updated field.\n" + " --no-parsing-spinner - Disable progress metrics and parsing\n" + " spinner.\n" + " --no-progress - Disable progress metrics.\n" + " --no-tab-scroll - Disable scrolling through panels on TAB.\n" + " --tz=<timezone> - Use the specified timezone (canonical name,\n" + " e.g., America/Chicago).\n" + "\n" + "" + /* Server Options */ + CYN "SERVER OPTIONS" RESET + "\n\n" + " --addr=<addr> - Specify IP address to bind server to.\n" + " --unix-socket=<addr> - Specify UNIX-domain socket address to bind\n" + " server to.\n" + " --daemonize - Run as daemon (if --real-time-html\n" + " enabled).\n" + " --fifo-in=<path> - Path to read named pipe (FIFO).\n" + " --fifo-out=<path> - Path to write named pipe (FIFO).\n" + " --origin=<addr> - Ensure clients send this origin header upon\n" + " the WebSocket handshake.\n" + " --pid-file=<path> - Write PID to a file when --daemonize is\n" + " used.\n" + " --port=<port> - Specify the port to use.\n" + " --real-time-html - Enable real-time HTML output.\n" + " --ssl-cert=<cert.crt> - Path to TLS/SSL certificate.\n" + " --ssl-key=<priv.key> - Path to TLS/SSL private key.\n" + " --user-name=<username> - Run as the specified user.\n" + " --ws-url=<url> - URL to which the WebSocket server responds.\n" + " --ping-interval=<secs> - Enable WebSocket ping with specified\n" + " interval in seconds.\n" + "\n" + "" + /* File Options */ + CYN "FILE OPTIONS" RESET + "\n\n" + " - - The log file to parse is read from stdin.\n" + " -f --log-file=<filename> - Path to input log file.\n" + " -l --debug-file=<filename> - Send all debug messages to the specified\n" + " file.\n" + " -p --config-file=<filename> - Custom configuration file.\n" + " -S --log-size=<number> - Specify the log size, useful when piping in\n" + " logs.\n" + " --external-assets - Output HTML assets to external JS/CSS files.\n" + " --invalid-requests=<filename> - Log invalid requests to the specified file.\n" + " --no-global-config - Don't load global configuration file.\n" + " --unknowns-log=<filename> - Log unknown browsers and OSs to the\n" + " specified file.\n" + "\n" + "" + /* Parse Options */ + CYN "PARSE OPTIONS" RESET + "\n\n" + " -a --agent-list - Enable a list of user-agents by host.\n" + " -b --browsers-file=<path> - Use additional custom list of browsers.\n" + " -d --with-output-resolver - Enable IP resolver on HTML|JSON output.\n" + " -e --exclude-ip=<IP> - Exclude one or multiple IPv4/6. Allows IP\n" + " ranges. e.g., 192.168.0.1-192.168.0.10\n" + " -j --jobs=<1-6> - Thread count for parsing log. Defaults to 1.\n" + " The use of 2-4 threads is recommended.\n" + " -H --http-protocol=<yes|no> - Set/unset HTTP request protocol if found.\n" + " -M --http-method=<yes|no> - Set/unset HTTP request method if found.\n" + " -o --output=<format|filename> - Output to stdout or the specified file.\n" + " e.g., -o csv, -o out.json, --output=report.html\n" + " -q --no-query-string - Strip request's query string. This can\n" + " decrease memory consumption.\n" + " -r --no-term-resolver - Disable IP resolver on terminal output.\n" + " --444-as-404 - Treat non-standard status code 444 as 404.\n" + " --4xx-to-unique-count - Add 4xx client errors to the unique\n" + " visitors count.\n" + " --all-static-files - Include static files with a query string.\n" + " --anonymize-ip - Anonymize IP addresses before outputting to\n" + " report.\n" + " --anonymize-level=<1|2|3> - Anonymization levels: 1 => default, 2 =>\n" + " strong, 3 => pedantic.\n" + " --chunk-size=<256-32768> - Number of lines processed in each data chunk\n" + " for parallel execution. Default is 1024.\n" + " --crawlers-only - Parse and display only crawlers.\n" + " --date-spec=<date|hr|min> - Date specificity. Possible values: `date`\n" + " (default), `hr` or `min`.\n" + " --db-path=<path> - Persist data to disk on exit to the given\n" + " path or /tmp as default.\n" + " --double-decode - Decode double-encoded values.\n" + " --enable-panel=<PANEL> - Enable parsing/displaying the given panel.\n" + " --fname-as-vhost=<regex> - Use log filename(s) as virtual host(s).\n" + " POSIX regex is passed to extract virtual\n" + " host.\n" + " --hide-referrer=<NEEDLE> - Hide a referrer but still count it. Wild\n" + " cards are allowed. i.e., *.bing.com\n" + " --hour-spec=<hr|min> - Hour specificity. Possible values: `hr`\n" + " (default) or `min` (tenth of a min).\n" + " --ignore-crawlers - Ignore crawlers.\n" + " --ignore-panel=<PANEL> - Ignore parsing/displaying the given panel.\n" + " --ignore-referrer=<NEEDLE> - Ignore a referrer from being counted. Wild\n" + " cards are allowed. i.e., *.bing.com\n" + " --ignore-statics=<req|panel> - Ignore static requests.\n" + " req => Ignore from valid requests.\n" + " panel => Ignore from valid requests and\n" + " panels.\n" + " --ignore-status=<CODE> - Ignore parsing the given status code.\n" + " --keep-last=<NDAYS> - Keep the last NDAYS in storage.\n" + " --no-ip-validation - Disable client IPv4/6 validation.\n" + " --no-strict-status - Disable HTTP status code validation.\n" + " --num-tests=<number> - Number of lines to test. >= 0 (10 default)\n" + " --persist - Persist data to disk on exit to the given\n" + " --db-path or to /tmp.\n" + " --process-and-exit - Parse log and exit without outputting data.\n" + " --real-os - Display real OS names. e.g, Windows XP,\n" + " Snow Leopard.\n" + " --restore - Restore data from disk from the given\n" + " --db-path or from /tmp.\n" + " --sort-panel=PANEL,METRIC,ORDER - Sort panel on initial load. e.g.,\n" + " --sort-panel=VISITORS,BY_HITS,ASC.\n" + " See manpage for a list of panels/fields.\n" + " --static-file=<extension> - Add static file extension. e.g.: .mp3.\n" + " Extensions are case sensitive.\n" + " --unknowns-as-crawlers - Classify unknown OS and browsers as crawlers.\n" + "\n" + +/* GeoIP Options */ +#ifdef HAVE_GEOLOCATION + CYN "GEOIP OPTIONS" RESET + "\n\n" +#ifdef HAVE_LIBGEOIP + " -g --std-geoip - Standard GeoIP database for less memory\n" + " consumption (legacy DB).\n" +#endif + " --geoip-database=<path> - Specify path to GeoIP database file.\n" + " i.e., GeoLiteCity.dat, GeoIPv6.dat ...\n" + "\n" +#endif + +/* Other Options */ + CYN "OTHER OPTIONS" RESET + "\n\n" + " -h --help - This help.\n" + " -s --storage - Display current storage method. e.g., Hash.\n" + " -V --version - Display version information and exit.\n" + " --dcf - Display the path of the default config file\n" + " when `-p` is not used.\n" + "\n" + + "%s `man goaccess`.\n\n" + "%s: %s\n" + "GoAccess Copyright (C) 2009-2020 by Gerardo Orellana" + "\n\n" + , INFO_HELP_EXAMPLES, INFO_MORE_INFO, GO_WEBSITE + ); + exit (EXIT_FAILURE); +} +/* *INDENT-ON* */ + +/* Push a command line option to the given array if within bounds and if it's + * not in the array. */ +static void +set_array_opt (const char *oarg, const char *arr[], int *size, int max) { + if (str_inarray (oarg, arr, *size) < 0 && *size < max) + arr[(*size)++] = oarg; +} + +/* Parse command line long options. */ +static void +parse_long_opt (const char *name, const char *oarg) { + if (!strcmp ("no-global-config", name)) + return; + + /* LOG & DATE FORMAT OPTIONS + * ========================= */ + + /* datetime format */ + if (!strcmp ("datetime-format", name) && !conf.date_format && !conf.time_format) { + set_date_format_str (oarg); + set_time_format_str (oarg); + } + + /* log format */ + if (!strcmp ("log-format", name)) + set_log_format_str (oarg); + + /* time format */ + if (!strcmp ("time-format", name)) + set_time_format_str (oarg); + + /* date format */ + if (!strcmp ("date-format", name)) + set_date_format_str (oarg); + + /* USER INTERFACE OPTIONS + * ========================= */ + /* colors */ + if (!strcmp ("color", name)) + set_array_opt (oarg, conf.colors, &conf.color_idx, MAX_CUSTOM_COLORS); + + /* color scheme */ + if (!strcmp ("color-scheme", name)) + conf.color_scheme = atoi (oarg); + + /* html custom CSS */ + if (!strcmp ("html-custom-css", name)) { + if (strpbrk (oarg, "&\"'<>")) + FATAL ("Invalid filename. The following chars are not allowed in filename: [\"'&<>]\n"); + conf.html_custom_css = oarg; + } + + /* html custom JS */ + if (!strcmp ("html-custom-js", name)) { + if (strpbrk (oarg, "&\"'<>")) + FATAL ("Invalid filename. The following chars are not allowed in filename: [\"'&<>]\n"); + conf.html_custom_js = oarg; + } + + /* html JSON object containing default preferences */ + if (!strcmp ("html-prefs", name)) + conf.html_prefs = oarg; + + /* html report title */ + if (!strcmp ("html-report-title", name)) + conf.html_report_title = oarg; + + /* json pretty print */ + if (!strcmp ("json-pretty-print", name)) + conf.json_pretty_print = 1; + + /* max items */ + if (!strcmp ("max-items", name)) { + char *sEnd; + int max = strtol (oarg, &sEnd, 10); + if (oarg == sEnd || *sEnd != '\0' || errno == ERANGE) + conf.max_items = 1; + else + conf.max_items = max; + } + + /* no color */ + if (!strcmp ("no-color", name)) + conf.no_color = 1; + + /* no strict status */ + if (!strcmp ("no-strict-status", name)) + conf.no_strict_status = 1; + + /* no columns */ + if (!strcmp ("no-column-names", name)) + conf.no_column_names = 1; + + /* no csv summary */ + if (!strcmp ("no-csv-summary", name)) + conf.no_csv_summary = 1; + + /* no parsing spinner */ + if (!strcmp ("no-parsing-spinner", name)) + conf.no_parsing_spinner = 1; + + /* no progress */ + if (!strcmp ("no-progress", name)) + conf.no_progress = 1; + + /* no tab scroll */ + if (!strcmp ("no-tab-scroll", name)) + conf.no_tab_scroll = 1; + + /* no html last updated field */ + if (!strcmp ("no-html-last-updated", name)) + conf.no_html_last_updated = 1; + + /* SERVER OPTIONS + * ========================= */ + /* address to bind to */ + if (!strcmp ("addr", name)) + conf.addr = oarg; + + /* unix socket to use */ + if (!strcmp ("unix-socket", name)) + conf.unix_socket = oarg; + + /* FIFO in (read) */ + if (!strcmp ("fifo-in", name)) + conf.fifo_in = oarg; + + /* FIFO out (write) */ + if (!strcmp ("fifo-out", name)) + conf.fifo_out = oarg; + + /* run program as a Unix daemon */ + if (!strcmp ("daemonize", name)) + conf.daemonize = 1; + + if (!strcmp ("user-name", name)) + conf.username = oarg; + + /* WebSocket origin */ + if (!strcmp ("origin", name)) + conf.origin = oarg; + + /* PID file to write */ + if (!strcmp ("pid-file", name)) + conf.pidfile = oarg; + + /* port to use */ + if (!strcmp ("port", name)) { + int port = strtol (oarg, NULL, 10); + if (port < 0 || port > 65535) + LOG_DEBUG (("Invalid port.")); + else + conf.port = oarg; + } + + /* real time HTML */ + if (!strcmp ("real-time-html", name)) + conf.real_time_html = 1; + + /* persist data to disk */ + if (!strcmp ("persist", name)) + conf.persist = 1; + + /* restore data from disk */ + if (!strcmp ("restore", name)) + conf.restore = 1; + + /* TLS/SSL certificate */ + if (!strcmp ("ssl-cert", name)) + conf.sslcert = oarg; + + /* TLS/SSL private key */ + if (!strcmp ("ssl-key", name)) + conf.sslkey = oarg; + + /* timezone */ + if (!strcmp ("tz", name)) + conf.tz_name = oarg; + + /* URL to which the WebSocket server responds. */ + if (!strcmp ("ws-url", name)) + conf.ws_url = oarg; + + /* WebSocket ping interval in seconds */ + if (!strcmp ("ping-interval", name)) + conf.ping_interval = oarg; + + /* FILE OPTIONS + * ========================= */ + /* invalid requests */ + if (!strcmp ("invalid-requests", name)) { + conf.invalid_requests_log = oarg; + invalid_log_open (conf.invalid_requests_log); + } + + /* unknowns */ + if (!strcmp ("unknowns-log", name)) { + conf.unknowns_log = oarg; + unknowns_log_open (conf.unknowns_log); + } + + /* output file */ + if (!strcmp ("output-format", name)) + FATAL ("The option --output-format is deprecated, please use --output instead."); + + /* PARSE OPTIONS + * ========================= */ + /* 444 as 404 */ + if (!strcmp ("444-as-404", name)) + conf.code444_as_404 = 1; + + /* 4xx to unique count */ + if (!strcmp ("4xx-to-unique-count", name)) + conf.client_err_to_unique_count = 1; + + /* anonymize ip */ + if (!strcmp ("anonymize-ip", name)) + conf.anonymize_ip = 1; + + /* anonymization level */ + if (!strcmp ("anonymize-level", name)) + conf.anonymize_level = atoi (oarg); + + /* all static files */ + if (!strcmp ("all-static-files", name)) + conf.all_static_files = 1; + + /* chunk size */ + if (!strcmp ("chunk-size", name)) { + /* Recommended chunk size is 256 - 32768, hard limit is 32 - 1048576. */ + conf.chunk_size = atoi (oarg); + if (conf.chunk_size < 32) + FATAL ("The hard lower limit of --chunk-size is 32."); + if (conf.chunk_size > 1048576) + FATAL ("The hard limit of --chunk-size is 1048576."); + } + + /* crawlers only */ + if (!strcmp ("crawlers-only", name)) + conf.crawlers_only = 1; + + /* date specificity */ + if (!strcmp ("date-spec", name) && !strcmp (oarg, "hr")) + conf.date_spec_hr = 1; + /* date specificity */ + if (!strcmp ("date-spec", name) && !strcmp (oarg, "min")) + conf.date_spec_hr = 2; + + /* double decode */ + if (!strcmp ("double-decode", name)) + conf.double_decode = 1; + + /* enable panel */ + if (!strcmp ("enable-panel", name)) + set_array_opt (oarg, conf.enable_panels, &conf.enable_panel_idx, TOTAL_MODULES); + + /* external assets */ + if (!strcmp ("external-assets", name)) + conf.external_assets = 1; + + /* hour specificity */ + if (!strcmp ("hour-spec", name) && !strcmp (oarg, "min")) + conf.hour_spec_min = 1; + + /* ignore crawlers */ + if (!strcmp ("ignore-crawlers", name)) + conf.ignore_crawlers = 1; + + /* ignore panel */ + if (!strcmp ("ignore-panel", name)) + set_array_opt (oarg, conf.ignore_panels, &conf.ignore_panel_idx, TOTAL_MODULES); + + /* ignore referrer */ + if (!strcmp ("ignore-referrer", name)) + set_array_opt (oarg, conf.ignore_referers, &conf.ignore_referer_idx, MAX_IGNORE_REF); + + /* client IP validation */ + if (!strcmp ("no-ip-validation", name)) + conf.no_ip_validation = 1; + + /* hide referrer from report (e.g. within same site) */ + if (!strcmp ("hide-referrer", name)) + set_array_opt (oarg, conf.hide_referers, &conf.hide_referer_idx, MAX_IGNORE_REF); + + /* ignore status code */ + if (!strcmp ("ignore-status", name)) + if (conf.ignore_status_idx < MAX_IGNORE_STATUS) + conf.ignore_status[conf.ignore_status_idx++] = atoi (oarg); + + /* ignore static requests */ + if (!strcmp ("ignore-statics", name)) { + if (!strcmp ("req", oarg)) + conf.ignore_statics = IGNORE_LEVEL_REQ; + else if (!strcmp ("panel", oarg)) + conf.ignore_statics = IGNORE_LEVEL_PANEL; + else + LOG_DEBUG (("Invalid statics ignore option.")); + } + + /* number of line tests */ + if (!strcmp ("num-tests", name)) { + char *sEnd; + int tests = strtol (oarg, &sEnd, 10); + if (oarg == sEnd || *sEnd != '\0' || errno == ERANGE) + return; + conf.num_tests = tests >= 0 ? tests : 0; + } + + /* number of days to keep in storage */ + if (!strcmp ("keep-last", name)) { + char *sEnd; + int keeplast = strtol (oarg, &sEnd, 10); + if (oarg == sEnd || *sEnd != '\0' || errno == ERANGE) + return; + conf.keep_last = keeplast >= 0 ? keeplast : 0; + } + + /* refresh html every X seconds */ + if (!strcmp ("html-refresh", name)) { + char *sEnd; + uint64_t ref = strtoull (oarg, &sEnd, 10); + if (oarg == sEnd || *sEnd != '\0' || errno == ERANGE) + return; + conf.html_refresh = ref >= 1 && ref <= 60 ? ref : 0; + } + + /* specifies the path of the database file */ + if (!strcmp ("db-path", name)) + conf.db_path = oarg; + + /* specifies the regex to extract the virtual host */ + if (!strcmp ("fname-as-vhost", name) && oarg && *oarg != '\0') + conf.fname_as_vhost = oarg; + + /* process and exit */ + if (!strcmp ("process-and-exit", name)) + conf.process_and_exit = 1; + + /* real os */ + if (!strcmp ("real-os", name)) + conf.real_os = 1; + + /* sort view */ + if (!strcmp ("sort-panel", name)) + set_array_opt (oarg, conf.sort_panels, &conf.sort_panel_idx, TOTAL_MODULES); + + /* static file */ + if (!strcmp ("static-file", name) && conf.static_file_idx < MAX_EXTENSIONS) { + if (conf.static_file_max_len < strlen (oarg)) + conf.static_file_max_len = strlen (oarg); + set_array_opt (oarg, conf.static_files, &conf.static_file_idx, MAX_EXTENSIONS); + } + + /* classify unknowns as crawlers */ + if (!strcmp ("unknowns-as-crawlers", name)) + conf.unknowns_as_crawlers = 1; + + /* GEOIP OPTIONS + * ========================= */ + /* specifies the path of the GeoIP City database file */ + if (!strcmp ("geoip-database", name) && conf.geoip_db_idx < MAX_GEOIP_DBS) + set_array_opt (oarg, conf.geoip_databases, &conf.geoip_db_idx, MAX_GEOIP_DBS); + + /* default config file --dwf */ + if (!strcmp ("dcf", name)) { + display_default_config_file (); + exit (EXIT_SUCCESS); + } +} + +/* Determine if the '--no-global-config' command line option needs to be + * enabled or not. */ +void +verify_global_config (int argc, char **argv) { + int o, idx = 0; + + conf.load_global_config = 1; + while ((o = getopt_long (argc, argv, short_options, long_opts, &idx)) >= 0) { + if (-1 == o || EOF == o) + break; + + switch (o) { + case 'p': + conf.iconfigfile = xstrdup (optarg); + break; + case 0: + if (!strcmp ("no-global-config", long_opts[idx].name)) + conf.load_global_config = 0; + break; + case '?': + exit (EXIT_FAILURE); + } + } + + /* reset it to 1 */ + optind = 1; +} + +/* Attempt to add - to the array of filenames if it hasn't been added it yet. */ +void +add_dash_filename (void) { + int i; + // pre-scan for '-' and don't add if already exists: github.com/allinurl/goaccess/issues/907 + for (i = 0; i < conf.filenames_idx; ++i) { + if (conf.filenames[i][0] == '-' && conf.filenames[i][1] == '\0') + return; + } + + if (conf.filenames_idx < MAX_FILENAMES && !conf.read_stdin) { + conf.read_stdin = 1; + conf.filenames[conf.filenames_idx++] = "-"; + } +} + +/* Read the user's supplied command line options. */ +void +read_option_args (int argc, char **argv) { + int o, idx = 0; + +#ifdef HAVE_LIBGEOIP + conf.geo_db = GEOIP_MEMORY_CACHE; +#endif + + while ((o = getopt_long (argc, argv, short_options, long_opts, &idx)) >= 0) { + if (-1 == o || EOF == o) + break; + switch (o) { + case 'f': + if (conf.filenames_idx < MAX_FILENAMES) + conf.filenames[conf.filenames_idx++] = optarg; + break; + case 'S': + if (strchr (optarg, '-')) { + printf ("[ERROR] log-size must be a positive integer\n"); + exit (EXIT_FAILURE); + } + conf.log_size = (uint64_t) atoll (optarg); + break; + case 'p': + /* ignore it */ + break; +#ifdef HAVE_LIBGEOIP + case 'g': + conf.geo_db = GEOIP_STANDARD; + break; +#endif + case 'e': + if (conf.ignore_ip_idx < MAX_IGNORE_IPS) + conf.ignore_ips[conf.ignore_ip_idx++] = optarg; + else + LOG_DEBUG (("Max num of (%d) IPs to ignore reached.", MAX_IGNORE_IPS)); + break; + case 'a': + conf.list_agents = 1; + break; + case 'b': + conf.browsers_file = optarg; + break; + case 'c': + conf.load_conf_dlg = 1; + break; + case 'i': + conf.hl_header = 1; + break; + case 'j': + /* Recommended 4 threads, soft limit is 6, hard limit is 12. */ + conf.jobs = atoi (optarg); + if (conf.jobs > 12) + FATAL ("The hard limit of --jobs is 12."); + break; + case 'q': + conf.ignore_qstr = 1; + break; + case 'o': + if (!valid_output_type (optarg)) + FATAL ("Invalid filename extension. It must be any of .csv, .json, or .html\n"); + if (conf.output_format_idx < MAX_OUTFORMATS) + conf.output_formats[conf.output_format_idx++] = optarg; + break; + case 'l': + conf.debug_log = optarg; + dbg_log_open (conf.debug_log); + break; + case 'r': + conf.skip_term_resolver = 1; + break; + case 'd': + conf.enable_html_resolver = 1; + break; + case 'm': + conf.mouse_support = 1; + break; + case 'M': + if (strcmp ("no", optarg) == 0) + conf.append_method = 0; + else + conf.append_method = 1; + break; + case 'h': + cmd_help (); + break; + case 'H': + if (strcmp ("no", optarg) == 0) + conf.append_protocol = 0; + else + conf.append_protocol = 1; + break; + case 'V': + display_version (); + exit (EXIT_SUCCESS); + break; + case 0: + parse_long_opt (long_opts[idx].name, optarg); + break; + case 's': + display_storage (); + exit (EXIT_SUCCESS); + case '?': + exit (EXIT_FAILURE); + default: + exit (EXIT_FAILURE); + } + } + + for (idx = optind; idx < argc; ++idx) { + /* read from standard input */ + if (!conf.read_stdin && strcmp ("-", argv[idx]) == 0) + add_dash_filename (); + /* read filenames */ + else { + if (conf.filenames_idx < MAX_FILENAMES) + conf.filenames[conf.filenames_idx++] = argv[idx]; + } + } +} diff --git a/src/options.h b/src/options.h new file mode 100644 index 0000000000..93fc1d7b7c --- /dev/null +++ b/src/options.h @@ -0,0 +1,42 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana <hello @ goaccess.io> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef OPTIONS_H_INCLUDED +#define OPTIONS_H_INCLUDED + +#define CYN "\x1B[36m" +#define RESET "\x1B[0m" +#define HTML_REFRESH 1 /* in seconds */ + +void add_dash_filename (void); +void cmd_help (void) __attribute__((noreturn)); +void read_option_args (int argc, char **argv); +void verify_global_config (int argc, char **argv); + +#endif diff --git a/src/output.c b/src/output.c new file mode 100644 index 0000000000..42bedfc08e --- /dev/null +++ b/src/output.c @@ -0,0 +1,1323 @@ +/** + * output.c -- output to the standard output stream + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana <hello @ goaccess.io> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE +#define _FILE_OFFSET_BITS 64 + +#include <errno.h> +#include <ctype.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <libgen.h> + +#include "output.h" + +#include "error.h" +#include "json.h" +#include "settings.h" +#include "ui.h" +#include "util.h" +#include "xmalloc.h" + +#include "tpls.h" +#include "bootstrapcss.h" +#include "facss.h" +#include "appcss.h" +#include "d3js.h" +#include "topojsonjs.h" +#include "hoganjs.h" +#include "countries110m.h" +#include "chartsjs.h" +#include "appjs.h" + +static void hits_bw_plot (FILE * fp, GHTMLPlot plot, int sp); +static void hits_bw_req_plot (FILE * fp, GHTMLPlot plot, int sp); +static void hits_visitors_plot (FILE * fp, GHTMLPlot plot, int sp); +static void hits_visitors_req_plot (FILE * fp, GHTMLPlot plot, int sp); + +static void print_metrics (FILE * fp, const GHTML * def, int sp); +static void print_host_metrics (FILE * fp, const GHTML * def, int sp); + +/* *INDENT-OFF* */ +static const GHTML htmldef[] = { + {VISITORS, 1, 0, print_metrics, { + {CHART_AREASPLINE, hits_visitors_plot, 1, 1, NULL, NULL} , + {CHART_AREASPLINE, hits_bw_plot, 1, 1, NULL, NULL} , + }}, + {REQUESTS, 1, 0, print_metrics, { + {CHART_VBAR, hits_visitors_req_plot, 0, 0, NULL, NULL}, + {CHART_VBAR, hits_bw_req_plot, 0, 0, NULL, NULL}, + }}, + {REQUESTS_STATIC, 1, 0, print_metrics, { + {CHART_VBAR, hits_visitors_req_plot, 0, 0, NULL, NULL}, + {CHART_VBAR, hits_bw_req_plot, 0, 0, NULL, NULL}, + }}, + {NOT_FOUND, 1, 0, print_metrics, { + {CHART_VBAR, hits_visitors_req_plot, 0, 0, NULL, NULL}, + {CHART_VBAR, hits_bw_req_plot, 0, 0, NULL, NULL}, + }}, + {HOSTS, 1, 0, print_host_metrics, { + {CHART_VBAR, hits_visitors_plot, 0, 0, NULL, NULL}, + {CHART_VBAR, hits_bw_plot, 0, 0, NULL, NULL}, + }}, + {OS, 1, 0, print_metrics, { + {CHART_VBAR, hits_visitors_plot, 0, 1, NULL, NULL}, + {CHART_VBAR, hits_bw_plot, 0, 1, NULL, NULL}, + }}, + {BROWSERS, 1, 0, print_metrics, { + {CHART_VBAR, hits_visitors_plot, 0, 1, NULL, NULL}, + {CHART_VBAR, hits_bw_plot, 0, 1, NULL, NULL}, + }}, + {VISIT_TIMES, 1, 0, print_metrics, { + {CHART_AREASPLINE, hits_visitors_plot, 0, 1, NULL, NULL}, + {CHART_AREASPLINE, hits_bw_plot, 0, 1, NULL, NULL}, + }}, + {VIRTUAL_HOSTS, 1, 0, print_metrics, { + {CHART_VBAR, hits_visitors_plot, 0, 0, NULL, NULL}, + {CHART_VBAR, hits_bw_plot, 0, 0, NULL, NULL}, + }}, + {REFERRERS, 1, 0, print_metrics, { + {CHART_VBAR, hits_visitors_plot, 0, 0, NULL, NULL}, + {CHART_VBAR, hits_bw_plot, 0, 0, NULL, NULL}, + }}, + {REFERRING_SITES, 1, 0, print_metrics, { + {CHART_VBAR, hits_visitors_plot, 0, 0, NULL, NULL}, + {CHART_VBAR, hits_bw_plot, 0, 0, NULL, NULL}, + }}, + {KEYPHRASES, 1, 0, print_metrics, { + {CHART_VBAR, hits_visitors_plot, 0, 0, NULL, NULL}, + {CHART_VBAR, hits_bw_plot, 0, 0, NULL, NULL}, + }}, + {STATUS_CODES, 1, 0, print_metrics, { + {CHART_VBAR, hits_visitors_plot, 0, 1, NULL, NULL}, + {CHART_VBAR, hits_bw_plot, 0, 1, NULL, NULL}, + }}, + {REMOTE_USER, 1, 0, print_metrics, { + {CHART_VBAR, hits_visitors_plot, 0, 0, NULL, NULL}, + {CHART_VBAR, hits_bw_plot, 0, 0, NULL, NULL}, + }}, + {CACHE_STATUS, 1, 0, print_metrics, { + {CHART_VBAR, hits_visitors_plot, 0, 0, NULL, NULL}, + {CHART_VBAR, hits_bw_plot, 0, 0, NULL, NULL}, + }}, +#ifdef HAVE_GEOLOCATION + {GEO_LOCATION, 1, 1, print_metrics, { + {CHART_WMAP, hits_visitors_plot, 0, 1, NULL, NULL}, + {CHART_VBAR, hits_bw_plot, 0, 1, NULL, NULL}, + }}, + {ASN, 1, 0, print_metrics, { + {CHART_VBAR, hits_visitors_plot, 0, 0, NULL, NULL}, + {CHART_VBAR, hits_bw_plot, 0, 0, NULL, NULL}, + }}, +#endif + {MIME_TYPE, 1, 0, print_metrics, { + {CHART_VBAR, hits_visitors_plot, 0, 1, NULL, NULL}, + {CHART_VBAR, hits_bw_plot, 0, 1, NULL, NULL}, + }}, + {TLS_TYPE, 1, 0, print_metrics, { + {CHART_VBAR, hits_visitors_plot, 0, 1, NULL, NULL}, + {CHART_VBAR, hits_bw_plot, 0, 1, NULL, NULL}, + }}, + +}; +/* *INDENT-ON* */ + +/* number of new lines (applicable fields) */ +static int nlines = 0; +static int external_assets = 0; + +/* Get the chart type for the JSON definition. + * + * On success, the chart type string is returned. */ +static const char * +chart2str (GChartType type) { + static const char *strings[] = { "null", "bar", "area-spline", "wmap" }; + return strings[type]; +} + +/* Get panel output data for the given module. + * + * If not found, NULL is returned. + * On success, panel data is returned . */ +static const GHTML * +panel_lookup (GModule module) { + int i, num_panels = ARRAY_SIZE (htmldef); + + for (i = 0; i < num_panels; i++) { + if (htmldef[i].module == module) + return &htmldef[i]; + } + return NULL; +} + +/* Sanitize output with html entities for special chars */ +static void +clean_output (FILE *fp, const char *s) { + if (!s) { + LOG_DEBUG (("NULL data on clean_output.\n")); + return; + } + + while (*s) { + switch (*s) { + case '\'': + fprintf (fp, "'"); + break; + case '"': + fprintf (fp, """); + break; + case '&': + fprintf (fp, "&"); + break; + case '<': + fprintf (fp, "<"); + break; + case '>': + fprintf (fp, ">"); + break; + case ' ': + fprintf (fp, " "); + break; + default: + fputc (*s, fp); + break; + } + s++; + } +} + +/* Set the HTML document title and the generated date/time */ +static void +print_html_title (FILE *fp) { + const char *title = conf.html_report_title ? conf.html_report_title : HTML_REPORT_TITLE; + + fprintf (fp, "<title>"); + clean_output (fp, title); + fprintf (fp, ""); +} + +static void +print_html_header_styles (FILE *fp, FILE *fcs) { + if (fcs) { + fprintf (fp, "", FILENAME_CSS); + fprintf (fcs, "%.*s\n", fa_css_length, fa_css); + fprintf (fcs, "%.*s\n", bootstrap_css_length, bootstrap_css); + fprintf (fcs, "%.*s\n", app_css_length, app_css); + } else { + fprintf (fp, "", fa_css_length, fa_css); + fprintf (fp, "", bootstrap_css_length, bootstrap_css); + fprintf (fp, "", app_css_length, app_css); + } +} + +/* *INDENT-OFF* */ +/* Output all the document head elements. */ +static void +print_html_header (FILE * fp, FILE *fcs) +{ + fprintf (fp, + "" + "" + "" + "" + "" + "" + "" + "" + "", _(DOC_LANG)); + + /* Output base64 encoded goaccess favicon.ico*/ + fprintf (fp, ""); + + /* Output base64-encoded goaccess apple-touch-icon png */ + fprintf (fp, ""); + + print_html_title (fp); + + print_html_header_styles(fp, fcs); + + /* load custom CSS file, if any */ + if (conf.html_custom_css) + fprintf (fp, "", conf.html_custom_css); + + fprintf (fp, + "" + ""); +} + +/* Output all structural elements of the HTML document. */ +static void +print_html_body (FILE * fp, const char *now) +{ + fprintf (fp, + "" + + "" + "
" + "
" + "
" + "
" + "" + "
" + "
" + "
" + "
" + "
" + "
", conf.html_report_title ? conf.html_report_title : ""); + + fprintf (fp, "%.*s", tpls_length, tpls); +} + +/* Output all the document footer elements such as script and closing + * tags. */ +static void +print_html_footer (FILE * fp, FILE *fjs) +{ + if (fjs) { + fprintf (fp, "", FILENAME_JS); + fprintf (fjs, "%.*s", d3_js_length, d3_js); + fprintf (fjs, "%.*s", hogan_js_length, hogan_js); + fprintf (fjs, "%.*s", app_js_length, app_js); + fprintf (fjs, "%.*s", charts_js_length, charts_js); + fprintf (fjs, "%.*s", topojson_js_length, topojson_js); + } else { + fprintf (fp, "", d3_js_length, d3_js); + fprintf (fp, "", hogan_js_length, hogan_js); + fprintf (fp, "", app_js_length, app_js); + fprintf (fp, "", charts_js_length, charts_js); + fprintf (fp, "", topojson_js_length, topojson_js); + } + + /* load custom JS file, if any */ + if (conf.html_custom_js) + fprintf (fp, "", conf.html_custom_js); + + fprintf (fp, ""); + fprintf (fp, ""); +} +/* *INDENT-ON* */ + +static const GChartDef ChartDefStopper = { NULL, NULL }; + +/* Get the number of chart definitions per panel. + * + * The number of chart definitions is returned . */ +static int +get_chartdef_cnt (GChart *chart) { + GChartDef *def = chart->def; + + while (memcmp (def, &ChartDefStopper, sizeof ChartDefStopper)) + ++def; + + return def - chart->def; +} + +/* Output the given JSON chart axis definition for the given panel. */ +static void +print_d3_chart_def_axis (FILE *fp, GChart *chart, size_t cnt, int isp) { + GChartDef *def = chart->def; + size_t j = 0; + + for (j = 0; j < cnt; ++j) { + if (strchr (def[j].value, '[') != NULL) + fpskeyaval (fp, def[j].key, def[j].value, isp, j == cnt - 1); + else + fpskeysval (fp, def[j].key, def[j].value, isp, j == cnt - 1); + } +} + +/* Output the given JSON chart definition for the given panel. */ +static void +print_d3_chart_def (FILE *fp, GChart *chart, size_t n, int sp) { + size_t i = 0, cnt = 0; + int isp = 0; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + for (i = 0; i < n; ++i) { + cnt = get_chartdef_cnt (chart + i); + + fpopen_obj_attr (fp, chart[i].key, sp); + print_d3_chart_def_axis (fp, chart + i, cnt, isp); + fpclose_obj (fp, sp, (i == n - 1)); + } +} + +static void +print_plot_def (FILE *fp, const GHTMLPlot plot, GChart *chart, int n, int sp) { + int isp = 0, iisp = 0; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1, iisp = sp + 2; + + fpskeysval (fp, "className", plot.chart_key, isp, 0); + fpskeysval (fp, "label", plot.chart_lbl, isp, 0); + fpskeysval (fp, "chartType", chart2str (plot.chart_type), isp, 0); + fpskeyival (fp, "chartReverse", plot.chart_reverse, isp, 0); + fpskeyival (fp, "redrawOnExpand", plot.redraw_expand, isp, 0); + + /* D3.js data */ + fpopen_obj_attr (fp, "d3", isp); + /* print chart definitions */ + print_d3_chart_def (fp, chart, n, iisp); + /* close D3 */ + fpclose_obj (fp, isp, 1); +} + +/* Output D3.js hits/visitors plot definitions. */ +static void +hits_visitors_plot (FILE *fp, GHTMLPlot plot, int sp) { + /* *INDENT-OFF* */ + GChart def[] = { + {"y0", (GChartDef[]) { + {"key", "hits"}, {"label", MTRC_HITS_LBL}, ChartDefStopper + }}, + {"y1", (GChartDef[]) { + {"key", "visitors"}, {"label", MTRC_VISITORS_LBL}, ChartDefStopper + }}, + }; + + plot.chart_key = (char[]) {"hits-visitors"}; + plot.chart_lbl = (char *) {HTML_PLOT_HITS_VIS}; + /* *INDENT-ON* */ + print_plot_def (fp, plot, def, ARRAY_SIZE (def), sp); +} + +/* Output D3.js hits/visitors plot definitions. */ +static void +hits_visitors_req_plot (FILE *fp, GHTMLPlot plot, int sp) { + /* *INDENT-OFF* */ + GChart def[] = { + {"x", (GChartDef[]) { + {"key", "[\"method\", \"data\", \"protocol\"]"}, ChartDefStopper + }}, + {"y0", (GChartDef[]) { + {"key", "hits"}, {"label", MTRC_HITS_LBL}, ChartDefStopper + }}, + {"y1", (GChartDef[]) { + {"key", "visitors"}, {"label", MTRC_VISITORS_LBL}, ChartDefStopper + }}, + }; + + plot.chart_key = (char[]) {"hits-visitors"}; + plot.chart_lbl = (char *) {HTML_PLOT_HITS_VIS}; + /* *INDENT-ON* */ + print_plot_def (fp, plot, def, ARRAY_SIZE (def), sp); +} + +/* Output C3.js bandwidth plot definitions. */ +static void +hits_bw_plot (FILE *fp, GHTMLPlot plot, int sp) { + /* *INDENT-OFF* */ + GChart def[] = { + {"y0", (GChartDef[]) { + {"key", "bytes"}, {"label", MTRC_BW_LBL}, {"format", "bytes"}, ChartDefStopper + }}, + }; + + if (!conf.bandwidth) + return; + + plot.chart_key = (char[]) {"bandwidth"}; + plot.chart_lbl = (char *) {MTRC_BW_LBL}; + /* *INDENT-ON* */ + print_plot_def (fp, plot, def, ARRAY_SIZE (def), sp); +} + +/* Output C3.js bandwidth plot definitions. */ +static void +hits_bw_req_plot (FILE *fp, GHTMLPlot plot, int sp) { + /* *INDENT-OFF* */ + GChart def[] = { + {"x", (GChartDef[]) { + {"key", "[\"method\", \"protocol\", \"data\"]"}, ChartDefStopper + }}, + {"y0", (GChartDef[]) { + {"key", "bytes"}, {"label", MTRC_BW_LBL}, {"format", "bytes"}, ChartDefStopper + }}, + }; + + if (!conf.bandwidth) + return; + + plot.chart_key = (char[]) {"bandwidth"}; + plot.chart_lbl = (char *) {MTRC_BW_LBL}; + /* *INDENT-ON* */ + print_plot_def (fp, plot, def, ARRAY_SIZE (def), sp); +} + +/* Output JSON data definitions. */ +static void +print_json_data (FILE *fp, GHolder *holder) { + char *json = NULL; + + if ((json = get_json (holder, 1)) == NULL) + return; + + fprintf (fp, external_assets ? "" : ""); + + free (json); +} + +/* Output WebSocket connection definition. */ +static void +print_conn_def (FILE *fp) { + int sp = 0; + /* use tabs to prettify output */ + if (conf.json_pretty_print) + sp += 1; + + if (!conf.real_time_html) + return; + + fprintf (fp, external_assets ? "" : ""); +} + +/* Output JSON per panel metric definitions. */ +static void +print_def_metric (FILE *fp, const GDefMetric def, int sp) { + int isp = 0; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + if (def.cname) + fpskeysval (fp, "className", def.cname, isp, 0); + if (def.cwidth) + fpskeysval (fp, "colWidth", def.cwidth, isp, 0); + if (def.metakey) + fpskeysval (fp, "meta", def.metakey, isp, 0); + if (def.metatype) + fpskeysval (fp, "metaType", def.metatype, isp, 0); + if (def.metalbl) + fpskeysval (fp, "metaLabel", def.metalbl, isp, 0); + if (def.datatype) + fpskeysval (fp, "dataType", def.datatype, isp, 0); + if (def.hlregex) + fpskeysval (fp, "hlregex", def.hlregex, isp, 0); + if (def.datakey) + fpskeysval (fp, "key", def.datakey, isp, 0); + if (def.lbl) + fpskeysval (fp, "label", def.lbl, isp, 1); +} + +/* Output JSON metric definition block. */ +static void +print_def_block (FILE *fp, const GDefMetric def, int sp, int last) { + fpopen_obj (fp, sp); + print_def_metric (fp, def, sp); + fpclose_obj (fp, sp, last); +} + +/* Output JSON overall requests definition block. */ +static void +print_def_overall_requests (FILE *fp, int sp) { + GDefMetric def = { + .lbl = T_REQUESTS, + .datatype = "numeric", + .cname = "black" + }; + fpopen_obj_attr (fp, OVERALL_REQ, sp); + print_def_metric (fp, def, sp); + fpclose_obj (fp, sp, 0); +} + +/* Output JSON overall valid requests definition block. */ +static void +print_def_overall_valid_reqs (FILE *fp, int sp) { + GDefMetric def = { + .lbl = T_VALID, + .datatype = "numeric", + .cname = "green" + }; + fpopen_obj_attr (fp, OVERALL_VALID, sp); + print_def_metric (fp, def, sp); + fpclose_obj (fp, sp, 0); +} + +/* Output JSON overall invalid requests definition block. */ +static void +print_def_overall_invalid_reqs (FILE *fp, int sp) { + GDefMetric def = { + .lbl = T_FAILED, + .datatype = "numeric", + .cname = "red" + }; + fpopen_obj_attr (fp, OVERALL_FAILED, sp); + print_def_metric (fp, def, sp); + fpclose_obj (fp, sp, 0); +} + +/* Output JSON process time definition block. */ +static void +print_def_overall_processed_time (FILE *fp, int sp) { + GDefMetric def = { + .lbl = T_GEN_TIME, + .datatype = "secs", + .cname = "gray" + }; + fpopen_obj_attr (fp, OVERALL_GENTIME, sp); + print_def_metric (fp, def, sp); + fpclose_obj (fp, sp, 0); +} + +/* Output JSON overall visitors definition block. */ +static void +print_def_overall_visitors (FILE *fp, int sp) { + GDefMetric def = { + .lbl = T_UNIQUE_VISITORS, + .datatype = "numeric", + .cname = "blue" + }; + fpopen_obj_attr (fp, OVERALL_VISITORS, sp); + print_def_metric (fp, def, sp); + fpclose_obj (fp, sp, 0); +} + +/* Output JSON overall files definition block. */ +static void +print_def_overall_files (FILE *fp, int sp) { + GDefMetric def = { + .lbl = T_UNIQUE_FILES, + .datatype = "numeric", + }; + fpopen_obj_attr (fp, OVERALL_FILES, sp); + print_def_metric (fp, def, sp); + fpclose_obj (fp, sp, 0); +} + +/* Output JSON overall excluded requests definition block. */ +static void +print_def_overall_excluded (FILE *fp, int sp) { + GDefMetric def = { + .lbl = T_EXCLUDE_IP, + .datatype = "numeric", + }; + fpopen_obj_attr (fp, OVERALL_EXCL_HITS, sp); + print_def_metric (fp, def, sp); + fpclose_obj (fp, sp, 0); +} + +/* Output JSON overall referrers definition block. */ +static void +print_def_overall_refs (FILE *fp, int sp) { + GDefMetric def = { + .lbl = T_REFERRER, + .datatype = "numeric", + }; + fpopen_obj_attr (fp, OVERALL_REF, sp); + print_def_metric (fp, def, sp); + fpclose_obj (fp, sp, 0); +} + +/* Output JSON overall not found definition block. */ +static void +print_def_overall_notfound (FILE *fp, int sp) { + GDefMetric def = { + .lbl = T_UNIQUE404, + .datatype = "numeric", + }; + fpopen_obj_attr (fp, OVERALL_NOTFOUND, sp); + print_def_metric (fp, def, sp); + fpclose_obj (fp, sp, 0); +} + +/* Output JSON overall static files definition block. */ +static void +print_def_overall_static_files (FILE *fp, int sp) { + GDefMetric def = { + .lbl = T_STATIC_FILES, + .datatype = "numeric", + }; + fpopen_obj_attr (fp, OVERALL_STATIC, sp); + print_def_metric (fp, def, sp); + fpclose_obj (fp, sp, 0); +} + +/* Output JSON log size definition block. */ +static void +print_def_overall_log_size (FILE *fp, int sp) { + GDefMetric def = { + .lbl = T_LOG, + .datatype = "bytes", + }; + fpopen_obj_attr (fp, OVERALL_LOGSIZE, sp); + print_def_metric (fp, def, sp); + fpclose_obj (fp, sp, 0); +} + +/* Output JSON overall bandwidth definition block. */ +static void +print_def_overall_bandwidth (FILE *fp, int sp) { + GDefMetric def = { + .lbl = T_BW, + .datatype = "bytes", + }; + fpopen_obj_attr (fp, OVERALL_BANDWIDTH, sp); + print_def_metric (fp, def, sp); + fpclose_obj (fp, sp, 1); +} + +/* Output JSON hits definition block. */ +static void +print_def_hits (FILE *fp, int sp) { + GDefMetric def = { + .datakey = "hits", + .lbl = MTRC_HITS_LBL, + .datatype = "numeric", + .metakey = "count", + .cwidth = "12%", + }; + print_def_block (fp, def, sp, 0); +} + +/* Output JSON visitors definition block. */ +static void +print_def_visitors (FILE *fp, int sp) { + GDefMetric def = { + .datakey = "visitors", + .lbl = MTRC_VISITORS_LBL, + .datatype = "numeric", + .metakey = "count", + .cwidth = "12%", + }; + print_def_block (fp, def, sp, 0); +} + +/* Output JSON bandwidth definition block. */ +static void +print_def_bw (FILE *fp, int sp) { + GDefMetric def = { + .datakey = "bytes", + .lbl = MTRC_BW_LBL, + .datatype = "bytes", + .metakey = "count", + .cwidth = "12%", + }; + + if (!conf.bandwidth) + return; + + print_def_block (fp, def, sp, 0); +} + +/* Output JSON Avg. T.S. definition block. */ +static void +print_def_avgts (FILE *fp, int sp) { + GDefMetric def = { + .datakey = "avgts", + .lbl = MTRC_AVGTS_LBL, + .datatype = "utime", + .metakey = "avg", + .cwidth = "8%", + }; + + if (!conf.serve_usecs) + return; + + print_def_block (fp, def, sp, 0); +} + +/* Output JSON Cum. T.S. definition block. */ +static void +print_def_cumts (FILE *fp, int sp) { + GDefMetric def = { + .datakey = "cumts", + .lbl = MTRC_CUMTS_LBL, + .datatype = "utime", + .metakey = "count", + .cwidth = "8%", + }; + + if (!conf.serve_usecs) + return; + + print_def_block (fp, def, sp, 0); +} + +/* Output JSON Max. T.S. definition block. */ +static void +print_def_maxts (FILE *fp, int sp) { + GDefMetric def = { + .datakey = "maxts", + .lbl = MTRC_MAXTS_LBL, + .datatype = "utime", + .metakey = "count", + .cwidth = "8%", + }; + + if (!conf.serve_usecs) + return; + print_def_block (fp, def, sp, 0); +} + +/* Output JSON method definition block. */ +static void +print_def_method (FILE *fp, int sp) { + GDefMetric def = { + .datakey = "method", + .lbl = MTRC_METHODS_LBL, + .datatype = "string", + .cwidth = "6%", + .hlregex = "{" + "\\\"(\\\\\\\\b[A-Z]{3}\\\\\\\\b)\\\": \\\"$1\\\"," + "\\\"(\\\\\\\\b[A-Z]{4}\\\\\\\\b)\\\": \\\"$1\\\"," + "\\\"(\\\\\\\\b[A-Z]{5,}\\\\\\\\b)\\\": \\\"$1\\\"" "}", + + }; + + if (!conf.append_method) + return; + + print_def_block (fp, def, sp, 0); +} + +/* Output JSON protocol definition block. */ +static void +print_def_protocol (FILE *fp, int sp) { + GDefMetric def = { + .datakey = "protocol", + .lbl = MTRC_PROTOCOLS_LBL, + .datatype = "string", + .cwidth = "7%", + .hlregex = "{" + "\\\"(\\\\\\\\bHTTP/1.0\\\\\\\\b)\\\": \\\"$1\\\"," + "\\\"(\\\\\\\\bHTTP/1.1\\\\\\\\b)\\\": \\\"$1\\\"," + "\\\"(\\\\\\\\bHTTP/2\\\\\\\\b)\\\": \\\"$1\\\"," + "\\\"(\\\\\\\\bHTTP/3\\\\\\\\b)\\\": \\\"$1\\\"" "}", + }; + + if (!conf.append_protocol) + return; + + print_def_block (fp, def, sp, 0); +} + +/* Output JSON city definition block. */ +static void +print_def_city (FILE *fp, int sp) { + GDefMetric def = { + .datakey = "city", + .lbl = MTRC_CITY_LBL, + .datatype = "string", + }; + + if (!conf.has_geocity) + return; + + print_def_block (fp, def, sp, 0); +} + +/* Output JSON ASN definition block. */ +static void +print_def_asn (FILE *fp, int sp) { + GDefMetric def = { + .datakey = "asn", + .lbl = MTRC_ASB_LBL, + .datatype = "string", + .hlregex = "{" + "\\\"^(\\\\\\\\d+)\\\": \\\"$1\\\"," "\\\"^(AS\\\\\\\\d+)\\\": \\\"$1\\\"" "}", + }; + + if (!conf.has_geoasn) + return; + + print_def_block (fp, def, sp, 0); +} + +/* Output JSON country definition block. */ +static void +print_def_country (FILE *fp, int sp) { + GDefMetric def = { + .datakey = "country", + .lbl = MTRC_COUNTRY_LBL, + .datatype = "string", + .hlregex = "{" "\\\"^([A-Z]{2})\\\": \\\"$1\\\"" "}", + }; + + if (!conf.has_geocountry) + return; + + print_def_block (fp, def, sp, 0); +} + +/* Output JSON hostname definition block. */ +static void +print_def_hostname (FILE *fp, int sp) { + GDefMetric def = { + .datakey = "hostname", + .lbl = MTRC_HOSTNAME_LBL, + .datatype = "string", + .cname = "light", + }; + + if (!conf.enable_html_resolver) + return; + + print_def_block (fp, def, sp, 0); +} + +/* Output JSON data definition block. */ +static void +print_def_data (FILE *fp, GModule module, int sp) { + GDefMetric def = { + .cname = "trunc", + .cwidth = "100%", + .datakey = "data", + .datatype = module == VISITORS ? "date" : "string", + .lbl = MTRC_DATA_LBL, + .metakey = "unique", + .metalbl = "Total", + .metatype = "numeric", + .hlregex = "{" "\\\"^(1\\\\\\\\d{2}|1xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 2xx Success */ + "\\\"^(2\\\\\\\\d{2}|2xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 2xx Success */ + "\\\"^(3\\\\\\\\d{2}|3xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 3xx Success */ + "\\\"^(4\\\\\\\\d{2}|4xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 4xx Success */ + "\\\"^(5\\\\\\\\d{2}|5xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 5xx Success */ + "\\\"^(0\\\\\\\\d{2}|0xx)(\\\\\\\\s.*)$\\\": \\\"$1$2\\\"," /* 5xx Success */ + "\\\"^(AS\\\\\\\\d+)\\\": \\\"$1\\\"," /* AS9823 Google */ + "\\\"^(\\\\\\\\d+:)\\\": \\\"$1\\\"," /* 01234: Data */ + "\\\"(\\\\\\\\d+)|(:\\\\\\\\d+)|(:\\\\\\\\d+:\\\\\\\\d+)\\\": \\\"$1$2\\\"," /* 12/May/2022:12:34 */ + "\\\"^([A-Z]{2})(\\\\\\\\s.*$)\\\": \\\"$1$2\\\"" /* US United States */ + "}", + }; + + print_def_block (fp, def, sp, 1); +} + +/* Get the number of plots for the given panel definition. + * + * The number of plots for the given panel is returned. */ +static int +count_plot_fp (const GHTML *def) { + int i = 0; + for (i = 0; def->chart[i].plot != 0; ++i); + return i; +} + +/* Entry function to output JSON plot definition block. */ +static void +print_def_plot (FILE *fp, const GHTML *def, int sp) { + int i, isp = 0, n = count_plot_fp (def); + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + fpopen_arr_attr (fp, "plot", sp); + + for (i = 0; i < n; ++i) { + fpopen_obj (fp, isp); + def->chart[i].plot (fp, def->chart[i], isp); + fpclose_obj (fp, isp, (i == n - 1)); + } + + fpclose_arr (fp, sp, 0); +} + +/* Output JSON host panel definitions. */ +static void +print_host_metrics (FILE *fp, const GHTML *def, int sp) { + const GOutput *output = output_lookup (def->module); + + print_def_hits (fp, sp); + print_def_visitors (fp, sp); + print_def_bw (fp, sp); + print_def_avgts (fp, sp); + print_def_cumts (fp, sp); + print_def_maxts (fp, sp); + + if (output->method) + print_def_method (fp, sp); + if (output->protocol) + print_def_protocol (fp, sp); + + print_def_city (fp, sp); + print_def_country (fp, sp); + print_def_asn (fp, sp); + print_def_hostname (fp, sp); + + print_def_data (fp, def->module, sp); +} + +/* Output JSON panel definitions. */ +static void +print_metrics (FILE *fp, const GHTML *def, int sp) { + const GOutput *output = output_lookup (def->module); + + print_def_hits (fp, sp); + print_def_visitors (fp, sp); + print_def_bw (fp, sp); + print_def_avgts (fp, sp); + print_def_cumts (fp, sp); + print_def_maxts (fp, sp); + + if (output->method) + print_def_method (fp, sp); + if (output->protocol) + print_def_protocol (fp, sp); + + print_def_data (fp, def->module, sp); +} + +/* Entry point to output JSON metric definitions. */ +static void +print_def_metrics (FILE *fp, const GHTML *def, int sp) { + int isp = 0; + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + /* open data metric data */ + fpopen_arr_attr (fp, "items", sp); + /* definition metrics */ + def->metrics (fp, def, isp); + /* close metrics block */ + fpclose_arr (fp, sp, 1); +} + +/* Output panel header and description metadata definitions. */ +static void +print_def_meta (FILE *fp, const char *head, const char *desc, int sp) { + int isp = 0; + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + fpskeysval (fp, "head", head, isp, 0); + fpskeysval (fp, "desc", desc, isp, 0); +} + +/* Output panel sort metadata definitions. */ +static void +print_def_sort (FILE *fp, const GHTML *def, int sp) { + GSort sort = module_sort[def->module]; + int isp = 0; + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + /* output open sort attribute */ + fpopen_obj_attr (fp, "sort", sp); + fpskeysval (fp, "field", get_sort_field_key (sort.field), isp, 0); + fpskeysval (fp, "order", get_sort_order_str (sort.sort), isp, 1); + /* output close sort attribute */ + fpclose_obj (fp, sp, 0); +} + +/* Output panel metadata definitions. */ +static void +print_panel_def_meta (FILE *fp, const GHTML *def, int sp) { + const char *desc = module_to_desc (def->module); + const char *head = module_to_head (def->module); + const char *id = module_to_id (def->module); + + int isp = 0; + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1; + + print_def_meta (fp, head, desc, sp); + + fpskeysval (fp, "id", id, isp, 0); + fpskeyival (fp, "table", def->table, isp, 0); + fpskeyival (fp, "hasMap", def->has_map, isp, 0); + + print_def_sort (fp, def, isp); + print_def_plot (fp, def, isp); + print_def_metrics (fp, def, isp); +} + +/* Output definitions for the given panel. */ +static void +print_json_def (FILE *fp, const GHTML *def) { + int sp = 0; + /* use tabs to prettify output */ + if (conf.json_pretty_print) + sp = 1; + + /* output open panel attribute */ + fpopen_obj_attr (fp, module_to_id (def->module), sp); + /* output panel data definitions */ + print_panel_def_meta (fp, def, sp); + /* output close panel attribute */ + fpclose_obj (fp, sp, 1); + + fpjson (fp, (def->module != TOTAL_MODULES - 1) ? ",%.*s" : "%.*s", nlines, NL); +} + +/* Output overall definitions. */ +static void +print_def_summary (FILE *fp, int sp) { + int isp = 0, iisp = 0; + /* use tabs to prettify output */ + if (conf.json_pretty_print) + isp = sp + 1, iisp = sp + 2; + + /* open metrics block */ + fpopen_obj_attr (fp, "items", isp); + + print_def_overall_requests (fp, iisp); + print_def_overall_valid_reqs (fp, iisp); + print_def_overall_invalid_reqs (fp, iisp); + print_def_overall_processed_time (fp, iisp); + print_def_overall_visitors (fp, iisp); + print_def_overall_files (fp, iisp); + print_def_overall_excluded (fp, iisp); + print_def_overall_refs (fp, iisp); + print_def_overall_notfound (fp, iisp); + print_def_overall_static_files (fp, iisp); + print_def_overall_log_size (fp, iisp); + print_def_overall_bandwidth (fp, iisp); + + /* close metrics block */ + fpclose_obj (fp, isp, 1); +} + +/* Cheap JSON internationalisation (i18n) - report labels */ +static void +print_json_i18n_def (FILE *fp) { + int sp = 0; + size_t i = 0; + + /* *INDENT-OFF* */ + static const char *json_i18n[][2] = { + {"theme" , HTML_REPORT_NAV_THEME} , + {"dark_gray" , HTML_REPORT_NAV_DARK_GRAY} , + {"bright" , HTML_REPORT_NAV_BRIGHT} , + {"dark_blue" , HTML_REPORT_NAV_DARK_BLUE} , + {"dark_purple" , HTML_REPORT_NAV_DARK_PURPLE} , + {"panels" , HTML_REPORT_NAV_PANELS} , + {"items_per_page" , HTML_REPORT_NAV_ITEMS_PER_PAGE} , + {"tables" , HTML_REPORT_NAV_TABLES} , + {"display_tables" , HTML_REPORT_NAV_DISPLAY_TABLES} , + {"ah_small" , HTML_REPORT_NAV_AH_SMALL} , + {"ah_small_title" , HTML_REPORT_NAV_AH_SMALL_TITLE} , + {"toggle_panel" , HTML_REPORT_NAV_TOGGLE_PANEL} , + {"layout" , HTML_REPORT_NAV_LAYOUT} , + {"horizontal" , HTML_REPORT_NAV_HOR} , + {"vertical" , HTML_REPORT_NAV_VER} , + {"wide" , HTML_REPORT_NAV_WIDE} , + {"file_opts" , HTML_REPORT_NAV_FILE_OPTS} , + {"export_json" , HTML_REPORT_NAV_EXPORT_JSON} , + {"panel_opts" , HTML_REPORT_PANEL_PANEL_OPTS} , + {"previous" , HTML_REPORT_PANEL_PREVIOUS} , + {"next" , HTML_REPORT_PANEL_NEXT} , + {"first" , HTML_REPORT_PANEL_FIRST} , + {"last" , HTML_REPORT_PANEL_LAST} , + {"chart_opts" , HTML_REPORT_PANEL_CHART_OPTS} , + {"chart" , HTML_REPORT_PANEL_CHART} , + {"type" , HTML_REPORT_PANEL_TYPE} , + {"area_spline" , HTML_REPORT_PANEL_AREA_SPLINE} , + {"bar" , HTML_REPORT_PANEL_BAR} , + {"wmap" , HTML_REPORT_PANEL_WMAP} , + {"plot_metric" , HTML_REPORT_PANEL_PLOT_METRIC} , + {"table_columns" , HTML_REPORT_PANEL_TABLE_COLS} , + {"thead" , T_HEAD} , + {"version" , GO_VERSION} , + }; + /* *INDENT-ON* */ + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + sp = 1; + + fpopen_obj (fp, 0); + for (i = 0; i < ARRAY_SIZE (json_i18n); ++i) { + fpskeysval (fp, json_i18n[i][0], _(json_i18n[i][1]), sp, 0); + } + fpclose_obj (fp, 0, 1); +} + +/* Output definitions for the given panel. */ +static void +print_json_def_summary (FILE *fp) { + int sp = 0; + + /* use tabs to prettify output */ + if (conf.json_pretty_print) + sp = 1; + + /* output open panel attribute */ + fpopen_obj_attr (fp, GENER_ID, sp); + print_def_meta (fp, _(T_HEAD), "", sp); + print_def_summary (fp, sp); + /* output close panel attribute */ + fpclose_obj (fp, sp, 0); +} + +/* Entry point to output definitions for all panels. */ +static void +print_json_defs (FILE *fp) { + const GHTML *def; + size_t idx = 0; + + fprintf (fp, external_assets ? "" : ""); +} + +static char * +get_asset_filepath (const char *filename, const char *asset_fname) { + char *fname = NULL, *path = NULL, *s = NULL; + + path = xstrdup (filename); + fname = xstrdup (basename (path)); + path[strlen (filename) - strlen (fname)] = '\0'; + + s = xmalloc (snprintf (NULL, 0, "%s%s", path, asset_fname) + 1); + sprintf (s, "%s%s", path, asset_fname); + free (path); + free (fname); + + return s; +} + +static FILE * +get_asset (const char *filename, const char *asset_fname) { + FILE *fp = NULL; + char *fn = NULL; + + if (!(fn = get_asset_filepath (filename, asset_fname))) + FATAL ("Invalid JS file."); + if (!(fp = fopen (fn, "w"))) + FATAL ("Unable to open file %s.", strerror (errno)); + free (fn); + + return fp; +} + +/* entry point to generate a report writing it to the fp */ +void +output_html (GHolder *holder, const char *filename) { + FILE *fp, *fjs = NULL, *fcs = NULL; + char now[DATE_TIME] = { 0 }; + + if (filename != NULL) + fp = fopen (filename, "w"); + else + fp = stdout; + + if (!fp) + FATAL ("Unable to open HTML file: %s.", strerror (errno)); + + if (filename && conf.external_assets) { + fjs = get_asset (filename, FILENAME_JS); + fcs = get_asset (filename, FILENAME_CSS); + external_assets = 1; + } + + /* use new lines to prettify output */ + if (conf.json_pretty_print) + nlines = 1; + set_json_nlines (nlines); + + generate_time (); + strftime (now, DATE_TIME, "%Y-%m-%d %H:%M:%S %z", &now_tm); + + print_html_header (fp, fcs); + + print_html_body (fp, now); + print_json_defs ((fjs ? fjs : fp)); + print_json_data ((fjs ? fjs : fp), holder); + print_conn_def ((fjs ? fjs : fp)); + + print_html_footer (fp, fjs); + + if (fjs) + fclose (fjs); + if (fcs) + fclose (fcs); + fclose (fp); +} diff --git a/src/output.h b/src/output.h new file mode 100644 index 0000000000..ac96967a0c --- /dev/null +++ b/src/output.h @@ -0,0 +1,98 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#ifndef OUTPUT_H_INCLUDED +#define OUTPUT_H_INCLUDED + +#define MAX_PLOTS 5 /* number of metrics we can plot */ +#define FILENAME_JS "goaccess.js" +#define FILENAME_CSS "goaccess.css" + +#include "commons.h" +#include "parser.h" + +/* Enumerated chart types */ +typedef enum GChartType_ { + CHART_NONE, + CHART_VBAR, + CHART_AREASPLINE, + CHART_WMAP, +} GChartType; + +/* Chart axis structure */ +typedef struct GChartDef_ { + const char *key; + const char *value; +} GChartDef; + +/* Chart axis structure */ +typedef struct GChart_ { + const char *key; + GChartDef *def; +} GChart; + +/* Chart behavior */ +typedef struct GHTMLPlot_ { + GChartType chart_type; + void (*plot) (FILE * fp, struct GHTMLPlot_ plot, int sp); + int8_t chart_reverse; + int8_t redraw_expand; + char *chart_key; + char *chart_lbl; +} GHTMLPlot; + +/* Controls HTML panel output. */ +typedef struct GHTML_ { + GModule module; + int8_t table; + int8_t has_map; + void (*metrics) (FILE * fp, const struct GHTML_ * def, int sp); + GHTMLPlot chart[MAX_PLOTS]; +} GHTML; + +/* Metric definition . */ +typedef struct GDefMetric_ { + const char *cname; /* metric class name */ + const char *cwidth; /* metric column width */ + const char *datakey; /* metric JSON data key */ + const char *datatype; /* metric data value type */ + const char *lbl; /* metric label (column name) */ + const char *metakey; /* metric JSON meta key */ + const char *metatype; /* metric meta value type */ + const char *metalbl; /* metric meta value label */ + const char *hlregex; /* highlight regex value */ +} GDefMetric; + +void output_html (GHolder * holder, const char *filename); + +#endif diff --git a/src/parser.c b/src/parser.c new file mode 100644 index 0000000000..766c812bed --- /dev/null +++ b/src/parser.c @@ -0,0 +1,2415 @@ +/** + * parser.c -- web log parsing + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * "_XOPEN_SOURCE" is required for the GNU libc to export "strptime(3)" + * correctly. + */ +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE +#define _FILE_OFFSET_BITS 64 + +#define _XOPEN_SOURCE 700 +#define _DEFAULT_SOURCE + +#include +#include + +#if HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gkhash.h" + +#include "parser.h" + +#include "browsers.h" +#include "error.h" +#include "goaccess.h" +#include "gstorage.h" +#include "util.h" +#include "websocket.h" +#include "xmalloc.h" + +/* Allocate memory for a new GRawData instance. + * + * On success, the newly allocated GRawData is returned . */ +GRawData * +new_grawdata (void) { + GRawData *raw_data = xmalloc (sizeof (*raw_data)); + memset (raw_data, 0, sizeof *raw_data); + + return raw_data; +} + +/* Allocate memory for a new GRawDataItem instance. + * + * On success, the newly allocated GRawDataItem is returned . */ +GRawDataItem * +new_grawdata_item (unsigned int size) { + GRawDataItem *item = xcalloc (size, sizeof (*item)); + return item; +} + +/* Free memory allocated for a GRawData and GRawDataItem instance. */ +void +free_raw_data (GRawData *raw_data) { + free (raw_data->items); + free (raw_data); +} + +/* Reset an instance of GLog structure. */ +void +reset_struct (Logs *logs) { + int i = 0; + + for (i = 0; i < logs->size; ++i) + logs->glog[i].invalid = logs->glog[i].processed = 0; +} + +/* Allocate memory for a new Logs and GLog instance. + * + * On success, the newly allocated Logs is returned . */ +Logs * +new_logs (int size) { + Logs *logs = xmalloc (sizeof (*logs)); + memset (logs, 0, sizeof *logs); + + logs->glog = xcalloc (size, sizeof (GLog)); + logs->size = size; + logs->idx = 0; + + return logs; +} + +/* Allocate, initialize and add the given filename to our logs structure. + * + * On error, 1 is returned. + * On success, the given filename is added to the Logs structure and 0 is + * returned. */ +int +set_glog (Logs *logs, const char *filename) { + GLog *tmp = NULL, *glog = NULL; + int newlen = 0; + char const *err; + char *fvh = NULL, *fn = NULL; + + if (logs->size - 1 < logs->idx) { + newlen = logs->size + 1; + if (!(tmp = xrealloc (logs->glog, newlen * sizeof (GLog)))) + return ERR_LOG_REALLOC_FAILURE; + + logs->glog = tmp; + + memset (logs->glog + logs->idx, 0, (logs->idx + 1 - logs->size) * sizeof *logs->glog); + logs->size = newlen; + } + + fn = xstrdup (filename); /* ensure fn is a string */ + glog = logs->glog; + glog[logs->idx].errors = xcalloc (MAX_LOG_ERRORS, sizeof (char *)); + glog[logs->idx].props.filename = xstrdup (fn); + glog[logs->idx].props.fname = xstrdup (basename (fn)); + + if (!glog->pipe && conf.fname_as_vhost) { + if (!(fvh = regex_extract_string (glog[logs->idx].props.fname, conf.fname_as_vhost, 1, &err))) + FATAL ("%s %s[%s]", err, glog[logs->idx].props.fname, conf.fname_as_vhost); + glog[logs->idx].fname_as_vhost = fvh; + } + + logs->processed = &(glog[logs->idx].processed); + logs->filename = glog[logs->idx].props.filename; + logs->idx++; + free (fn); + + return 0; +} + +/* Ensure the given filename is part of our original list of files. + * + * On error, 1 is returned. + * On success, the given filename is added to the Logs structure and 0 is + * returned. */ +int +set_log (Logs *logs, const char *value) { + if (str_inarray (value, conf.filenames, conf.filenames_idx) < 0) + return ERR_LOG_NOT_FOUND; + + return set_glog (logs, value); +} + +/* Allocate memory for a new set of Logs including a GLog instance. + * + * On success, the newly allocated Logs is returned . */ +Logs * +init_logs (int size) { + Logs *logs = NULL; + GLog *glog = NULL; + int i = 0, ret = 0; + + /* if no logs no a pipe nor restoring, nothing to do then */ + if (!size && !conf.restore) + return NULL; + + /* If no logs nor a pipe but restoring, we still need an minimal instance of + * logs and a glog */ + if (!size) { + logs = xcalloc (1, sizeof (*logs)); + logs->glog = xcalloc (1, sizeof (*glog)); + logs->processed = &(logs->glog[0].processed); + return logs; + } + + logs = new_logs (size); + logs->size = size; + + for (i = 0; i < size; ++i) { + if ((ret = set_log (logs, conf.filenames[i]))) + FATAL ("%s\n", ERR_LOG_NOT_FOUND_MSG); + } + + return logs; +} + +/* Free all log errors stored during parsing. */ +void +free_logerrors (GLog *glog) { + int i; + + if (!glog->log_erridx) + return; + + for (i = 0; i < glog->log_erridx; ++i) + free (glog->errors[i]); + glog->log_erridx = 0; +} + +/* Free all log containers. */ +void +free_logs (Logs *logs) { + GLog *glog = NULL; + int i; + + for (i = 0; i < logs->size; ++i) { + glog = &logs->glog[i]; + + free (glog->props.filename); + free (glog->props.fname); + free (glog->fname_as_vhost); + free_logerrors (glog); + free (glog->errors); + if (glog->pipe) { + fclose (glog->pipe); + } + } + + free (logs->glog); + free (logs); +} + +/* Initialize a new GLogItem instance. + * + * On success, the new GLogItem instance is returned. */ +GLogItem * +init_log_item (GLog *glog) { + GLogItem *logitem; + logitem = xmalloc (sizeof (GLogItem)); + memset (logitem, 0, sizeof *logitem); + + logitem->agent = NULL; + logitem->browser = NULL; + logitem->browser_type = NULL; + logitem->continent = NULL; + logitem->asn = NULL; + logitem->country = NULL; + logitem->date = NULL; + logitem->errstr = NULL; + logitem->host = NULL; + logitem->keyphrase = NULL; + logitem->method = NULL; + logitem->os = NULL; + logitem->os_type = NULL; + logitem->protocol = NULL; + logitem->qstr = NULL; + logitem->ref = NULL; + logitem->req_key = NULL; + logitem->req = NULL; + logitem->resp_size = 0LL; + logitem->serve_time = 0; + logitem->status = -1; + logitem->time = NULL; + logitem->uniq_key = NULL; + logitem->vhost = NULL; + logitem->userid = NULL; + logitem->cache_status = NULL; + + /* UMS */ + logitem->mime_type = NULL; + logitem->tls_type = NULL; + logitem->tls_cypher = NULL; + logitem->tls_type_cypher = NULL; + + memset (logitem->site, 0, sizeof (logitem->site)); + memset (logitem->agent_hex, 0, sizeof (logitem->agent_hex)); + logitem->dt = glog->start_time; + + return logitem; +} + +/* Free all members of a GLogItem */ +void +free_glog (GLogItem *logitem) { + if (logitem->agent != NULL) + free (logitem->agent); + if (logitem->browser != NULL) + free (logitem->browser); + if (logitem->browser_type != NULL) + free (logitem->browser_type); + if (logitem->continent != NULL) + free (logitem->continent); + if (logitem->asn != NULL) + free (logitem->asn); + if (logitem->country != NULL) + free (logitem->country); + if (logitem->date != NULL) + free (logitem->date); + if (logitem->errstr != NULL) + free (logitem->errstr); + if (logitem->host != NULL) + free (logitem->host); + if (logitem->keyphrase != NULL) + free (logitem->keyphrase); + if (logitem->method != NULL) + free (logitem->method); + if (logitem->os != NULL) + free (logitem->os); + if (logitem->os_type != NULL) + free (logitem->os_type); + if (logitem->protocol != NULL) + free (logitem->protocol); + if (logitem->qstr != NULL) + free (logitem->qstr); + if (logitem->ref != NULL) + free (logitem->ref); + if (logitem->req_key != NULL) + free (logitem->req_key); + if (logitem->req != NULL) + free (logitem->req); + if (logitem->time != NULL) + free (logitem->time); + if (logitem->uniq_key != NULL) + free (logitem->uniq_key); + if (logitem->userid != NULL) + free (logitem->userid); + if (logitem->cache_status != NULL) + free (logitem->cache_status); + if (logitem->vhost != NULL) + free (logitem->vhost); + + if (logitem->mime_type != NULL) + free (logitem->mime_type); + if (logitem->tls_type != NULL) + free (logitem->tls_type); + if (logitem->tls_cypher != NULL) + free (logitem->tls_cypher); + if (logitem->tls_type_cypher != NULL) + free (logitem->tls_type_cypher); + + free (logitem); +} + +/* Decodes the given URL-encoded string. + * + * On success, the decoded string is assigned to the output buffer. */ +#define B16210(x) (((x) >= '0' && (x) <= '9') ? ((x) - '0') : (toupper((unsigned char) (x)) - 'A' + 10)) +static void +decode_hex (char *url, char *out) { + char *ptr; + const char *c; + + for (c = url, ptr = out; *c; c++) { + if (*c != '%' || !isxdigit ((unsigned char) c[1]) || !isxdigit ((unsigned char) c[2])) { + *ptr++ = *c; + } else { + *ptr++ = (char) ((B16210 (c[1]) * 16) + (B16210 (c[2]))); + c += 2; + } + } + *ptr = 0; +} + +/* Entry point to decode the given URL-encoded string. + * + * On success, the decoded trimmed string is assigned to the output + * buffer. */ +static char * +decode_url (char *url) { + char *out, *decoded; + + if ((url == NULL) || (*url == '\0')) + return NULL; + + out = decoded = xstrdup (url); + decode_hex (url, out); + /* double encoded URL? */ + if (conf.double_decode) + decode_hex (decoded, out); + strip_newlines (out); + + return trim_str (out); +} + +/* Process keyphrases from Google search, cache, and translate. + * Note that the referer hasn't been decoded at the entry point + * since there could be '&' within the search query. + * + * On error, 1 is returned. + * On success, the extracted keyphrase is assigned and 0 is returned. */ +static int +extract_keyphrase (char *ref, char **keyphrase) { + char *r, *ptr, *pch, *referer; + int encoded = 0; + + if (!(strstr (ref, "http://www.google.")) && + !(strstr (ref, "http://webcache.googleusercontent.com/")) && + !(strstr (ref, "http://translate.googleusercontent.com/")) && + !(strstr (ref, "https://www.google.")) && + !(strstr (ref, "https://webcache.googleusercontent.com/")) && + !(strstr (ref, "https://translate.googleusercontent.com/"))) + return 1; + + /* webcache.googleusercontent */ + if ((r = strstr (ref, "/+&")) != NULL) + return 1; + /* webcache.googleusercontent */ + else if ((r = strstr (ref, "/+")) != NULL) + r += 2; + /* webcache.googleusercontent */ + else if ((r = strstr (ref, "q=cache:")) != NULL) { + pch = strchr (r, '+'); + if (pch) + r += pch - r + 1; + } + /* www.google.* or translate.googleusercontent */ + else if ((r = strstr (ref, "&q=")) != NULL || (r = strstr (ref, "?q=")) != NULL) + r += 3; + else if ((r = strstr (ref, "%26q%3D")) != NULL || (r = strstr (ref, "%3Fq%3D")) != NULL) + encoded = 1, r += 7; + else + return 1; + + if (!encoded && (ptr = strchr (r, '&')) != NULL) + *ptr = '\0'; + else if (encoded && (ptr = strstr (r, "%26")) != NULL) + *ptr = '\0'; + + referer = decode_url (r); + if (referer == NULL || *referer == '\0') { + free (referer); + return 1; + } + + referer = char_replace (referer, '+', ' '); + *keyphrase = trim_str (referer); + + return 0; +} + +/* Parse a URI and extracts the *host* part from it + * i.e., //www.example.com/path?googleguy > www.example.com + * + * On error, 1 is returned. + * On success, the extracted referer is set and 0 is returned. */ +static int +extract_referer_site (const char *referer, char *host) { + char *url, *begin, *end; + int len = 0; + + if ((referer == NULL) || (*referer == '\0')) + return 1; + + url = strdup (referer); + if ((begin = strstr (url, "//")) == NULL) + goto clean; + + begin += 2; + if ((len = strlen (begin)) == 0) + goto clean; + + if ((end = strpbrk (begin, "/?")) != NULL) + len = end - begin; + + if (len == 0) + goto clean; + + if (len >= REF_SITE_LEN) + len = REF_SITE_LEN; + + memcpy (host, begin, len); + host[len] = '\0'; + free (url); + return 0; +clean: + free (url); + + return 1; +} + +/* Determine if the given request is static (e.g., jpg, css, js, etc). + * + * On error, or if not static, 0 is returned. + * On success, the 1 is returned. */ +static int +verify_static_content (const char *req) { + const char *nul = NULL; + const char *ext = NULL, *pch = NULL; + int elen = 0, i; + + if ((req == NULL) || (*req == '\0')) + return 0; + + nul = req + strlen (req); + + for (i = 0; i < conf.static_file_idx; ++i) { + ext = conf.static_files[i]; + if (ext == NULL || *ext == '\0') + continue; + + elen = strlen (ext); + if (conf.all_static_files && (pch = strchr (req, '?')) != NULL && pch - req > elen) { + pch -= elen; + if (0 == strncasecmp (ext, pch, elen)) + return 1; + continue; + } + + if (nul - req > elen && !strncasecmp (nul - elen, ext, elen)) + return 1; + } + + return 0; +} + +/* Extract the HTTP method. + * + * On error, or if not found, NULL is returned. + * On success, the HTTP method is returned. */ +static const char * +extract_method (const char *token) { + size_t i; + for (i = 0; i < http_methods_len; i++) { + if (strncasecmp (token, http_methods[i].method, http_methods[i].len) == 0) { + return http_methods[i].method; + } + } + return NULL; +} + +static int +is_cache_hit (const char *tkn) { + if (strcasecmp ("MISS", tkn) == 0) + return 1; + else if (strcasecmp ("BYPASS", tkn) == 0) + return 1; + else if (strcasecmp ("EXPIRED", tkn) == 0) + return 1; + else if (strcasecmp ("STALE", tkn) == 0) + return 1; + else if (strcasecmp ("UPDATING", tkn) == 0) + return 1; + else if (strcasecmp ("REVALIDATED", tkn) == 0) + return 1; + else if (strcasecmp ("HIT", tkn) == 0) + return 1; + return 0; +} + +/* Determine if the given token is a valid HTTP protocol. + * + * If not valid, 1 is returned. + * If valid, 0 is returned. */ +static const char * +extract_protocol (const char *token) { + size_t i; + for (i = 0; i < http_protocols_len; i++) { + if (strncasecmp (token, http_protocols[i].protocol, http_protocols[i].len) == 0) { + return http_protocols[i].protocol; + } + } + return NULL; +} + +/* Parse a request containing the method and protocol. + * + * On error, or unable to parse, NULL is returned. + * On success, the HTTP request is returned and the method and + * protocol are assigned to the corresponding buffers. */ +static char * +parse_req (char *line, char **method, char **protocol) { + char *req = NULL, *request = NULL, *dreq = NULL, *ptr = NULL; + const char *meth, *proto; + ptrdiff_t rlen; + + meth = extract_method (line); + + /* couldn't find a method, so use the whole request line */ + if (meth == NULL) { + request = xstrdup (line); + } + /* method found, attempt to parse request */ + else { + req = line + strlen (meth); + if (!(ptr = strrchr (req, ' ')) || !(proto = extract_protocol (++ptr))) + return alloc_string ("-"); + + req++; + if ((rlen = ptr - req) <= 0) + return alloc_string ("-"); + + request = xmalloc (rlen + 1); + strncpy (request, req, rlen); + request[rlen] = 0; + + if (conf.append_method) + (*method) = strtoupper (xstrdup (meth)); + + if (conf.append_protocol) + (*protocol) = strtoupper (xstrdup (proto)); + } + + if (!(dreq = decode_url (request))) + return request; + else if (*dreq == '\0') { + free (dreq); + return request; + } + + free (request); + return dreq; +} + +#if defined(HAVE_LIBSSL) && defined(HAVE_CIPHER_STD_NAME) +static int +extract_tls_version_cipher (char *tkn, char **cipher, char **tls_version) { + SSL_CTX *ctx = NULL; + SSL *ssl = NULL; + int code = 0; + unsigned short code_be; + unsigned char cipherid[3]; + const SSL_CIPHER *c = NULL; + char *bEnd; + const char *sn = NULL; + + code = strtoull (tkn, &bEnd, 10); + if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE) { + LOG_DEBUG (("unable to convert cipher code to a valid decimal.")); + goto fail; + } + + /* ssl context */ + if (!(ctx = SSL_CTX_new (SSLv23_server_method ()))) { + LOG_DEBUG (("Unable to create a new SSL_CTX_new to extract TLS.")); + goto fail; + } + if (!(ssl = SSL_new (ctx))) { + LOG_DEBUG (("Unable to create a new instance of SSL_new to extract TLS.")); + goto fail; + } + + code_be = htobe16 (code); + memcpy (cipherid, &code_be, 2); + cipherid[2] = 0; + + if (!(c = SSL_CIPHER_find (ssl, cipherid))) { + LOG_DEBUG (("Unable to find cipher to extract TLS.")); + goto fail; + } + + if (!(sn = SSL_CIPHER_standard_name (c))) { + LOG_DEBUG (("Unable to get cipher standard name to extract TLS.")); + goto fail; + } + *cipher = xstrdup (sn); + *tls_version = xstrdup (SSL_CIPHER_get_version (c)); + + free (tkn); + SSL_free (ssl); + SSL_CTX_free (ctx); + + return 0; + +fail: + free (tkn); + if (ssl) + SSL_free (ssl); + if (ctx) + SSL_CTX_free (ctx); + return 1; +} +#endif + +/* Extract the next delimiter given a log format and copy the delimiter to the + * destination buffer. + * + * On error, the dest buffer will be empty. + * On success, the delimiter(s) are stored in the dest buffer. */ +static void +get_delim (char *dest, const char *p) { + /* done, nothing to do */ + if (p[0] == '\0' || p[1] == '\0') { + dest[0] = '\0'; + return; + } + /* add the first delim */ + dest[0] = *(p + 1); +} + +/* Extract and malloc a token given the parsed rule. + * + * On success, the malloc'd token is returned. */ +static char * +parsed_string (const char *pch, const char **str, int move_ptr) { + char *p; + size_t len = (pch - *str + 1); + + p = xmalloc (len); + memcpy (p, *str, (len - 1)); + p[len - 1] = '\0'; + if (move_ptr) + *str += len - 1; + + return trim_str (p); +} + +/* Find and extract a token given a log format rule. + * + * On error, or unable to parse it, NULL is returned. + * On success, the malloc'd token is returned. */ +static char * +parse_string (const char **str, const char *delims, int cnt) { + int idx = 0; + const char *pch = *str, *p = NULL; + char end; + + if ((*delims != 0x0) && (p = strpbrk (*str, delims)) == NULL) + return NULL; + + end = !*delims ? 0x0 : *p; + do { + /* match number of delims */ + if (*pch == end) + idx++; + /* delim found, parse string then */ + if ((*pch == end && cnt == idx) || *pch == '\0') + return parsed_string (pch, str, 1); + /* advance to the first unescaped delim */ + if (*pch == '\\') + pch++; + } while (*pch++); + + return NULL; +} + +char * +extract_by_delim (const char **str, const char *end) { + return parse_string (&(*str), end, 1); +} + +/* Move forward through the log string until a non-space (!isspace) + * char is found. */ +static void +find_alpha (const char **str) { + const char *s = *str; + while (*s) { + if (isspace ((unsigned char) *s)) + s++; + else + break; + } + *str += s - *str; +} + +/* Move forward through the log string until a non-space (!isspace) + * char is found and returns the count. */ +static int +find_alpha_count (const char *str) { + int cnt = 0; + const char *s = str; + while (*s) { + if (isspace ((unsigned char) *s)) + s++, cnt++; + else + break; + } + return cnt; +} + +/* Format the broken-down time tm to a numeric date format. + * + * On error, or unable to format the given tm, 1 is returned. + * On success, a malloc'd format is returned. */ +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +static int +set_date (char **fdate, struct tm tm) { + char buf[DATE_LEN] = ""; /* Ymd */ + + memset (buf, 0, sizeof (buf)); + if (strftime (buf, DATE_LEN, conf.date_num_format, &tm) <= 0) + return 1; + *fdate = xstrdup (buf); + + return 0; +} + +/* Format the broken-down time tm to a numeric time format. + * + * On error, or unable to format the given tm, 1 is returned. + * On success, a malloc'd format is returned. */ +static int +set_time (char **ftime, struct tm tm) { + char buf[TIME_LEN] = ""; + + memset (buf, 0, sizeof (buf)); + if (strftime (buf, TIME_LEN, "%H:%M:%S", &tm) <= 0) + return 1; + *ftime = xstrdup (buf); + + return 0; +} + +/* Determine the parsing specifier error and construct a message out + * of it. + * + * On success, a malloc'd error message is assigned to the log + * structure and 1 is returned. */ +static int +spec_err (GLogItem *logitem, int code, const char spec, const char *tkn) { + char *err = NULL; + const char *fmt = NULL; + + switch (code) { + case ERR_SPEC_TOKN_NUL: + fmt = "Token for '%%%c' specifier is NULL."; + err = xmalloc (snprintf (NULL, 0, fmt, spec) + 1); + sprintf (err, fmt, spec); + break; + case ERR_SPEC_TOKN_INV: + fmt = "Token '%s' doesn't match specifier '%%%c'"; + err = xmalloc (snprintf (NULL, 0, fmt, (tkn ? tkn : "-"), spec) + 1); + sprintf (err, fmt, (tkn ? tkn : "-"), spec); + break; + case ERR_SPEC_SFMT_MIS: + fmt = "Missing braces '%s' and ignore chars for specifier '%%%c'"; + err = xmalloc (snprintf (NULL, 0, fmt, (tkn ? tkn : "-"), spec) + 1); + sprintf (err, fmt, (tkn ? tkn : "-"), spec); + break; + case ERR_SPEC_LINE_INV: + fmt = "Incompatible format due to early parsed line ending '\\0'."; + err = xmalloc (snprintf (NULL, 0, fmt, (tkn ? tkn : "-")) + 1); + sprintf (err, fmt, (tkn ? tkn : "-")); + break; + } + logitem->errstr = err; + + return code; +} + +static void +set_tm_dt_logitem (GLogItem *logitem, struct tm tm) { + logitem->dt.tm_year = tm.tm_year; + logitem->dt.tm_mon = tm.tm_mon; + logitem->dt.tm_mday = tm.tm_mday; +} + +static void +set_tm_tm_logitem (GLogItem *logitem, struct tm tm) { + logitem->dt.tm_hour = tm.tm_hour; + logitem->dt.tm_min = tm.tm_min; + logitem->dt.tm_sec = tm.tm_sec; +} + +static void +set_numeric_date (uint32_t *numdate, const char *date) { + int res = 0; + if ((res = str2int (date)) == -1) + FATAL ("Unable to parse date to integer %s", date); + *numdate = res; +} + +static void +set_agent_hash (GLogItem *logitem) { + logitem->agent_hash = djb2 ((unsigned char *) logitem->agent); + sprintf (logitem->agent_hex, "%" PRIx32, logitem->agent_hash); +} + +static int +handle_default_case_token (const char **str, const char *p) { + char *pch = NULL; + if ((pch = strchr (*str, p[1])) != NULL) + *str += pch - *str; + return 0; +} + +#pragma GCC diagnostic warning "-Wformat-nonliteral" + +/* Parse the log string given log format rule. + * + * On error, or unable to parse it, 1 is returned. + * On success, the malloc'd token is assigned to a GLogItem member. */ +static int +parse_specifier (GLogItem *logitem, const char **str, const char *p, const char *end) { + struct tm tm; + const char *dfmt = conf.date_format; + const char *tfmt = conf.time_format; + + char *pch, *sEnd, *bEnd, *tkn = NULL; + double serve_secs = 0.0; + uint64_t bandw = 0, serve_time = 0; + int dspc = 0, fmtspcs = 0; + + errno = 0; + memset (&tm, 0, sizeof (tm)); + tm.tm_isdst = -1; + tm = logitem->dt; + + switch (*p) { + /* date */ + case 'd': + if (logitem->date) + return handle_default_case_token (str, p); + + /* Attempt to parse date format containing spaces, + * i.e., syslog date format (Jul\s15, Nov\s\s2). + * Note that it's possible a date could contain some padding, e.g., + * Dec\s\s2 vs Nov\s22, so we attempt to take that into consideration by looking + * ahead the log string and counting the # of spaces until we find an alphanum char. */ + if ((fmtspcs = count_matches (dfmt, ' ')) && (pch = strchr (*str, ' '))) + dspc = find_alpha_count (pch); + + if (!(tkn = parse_string (&(*str), end, MAX (dspc, fmtspcs) + 1))) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + + if (str_to_time (tkn, dfmt, &tm, 1) != 0 || set_date (&logitem->date, tm) != 0) { + spec_err (logitem, ERR_SPEC_TOKN_INV, *p, tkn); + free (tkn); + return 1; + } + + set_numeric_date (&logitem->numdate, logitem->date); + set_tm_dt_logitem (logitem, tm); + free (tkn); + break; + /* time */ + case 't': + if (logitem->time) + return handle_default_case_token (str, p); + if (!(tkn = parse_string (&(*str), end, 1))) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + + if (str_to_time (tkn, tfmt, &tm, 1) != 0 || set_time (&logitem->time, tm) != 0) { + spec_err (logitem, ERR_SPEC_TOKN_INV, *p, tkn); + free (tkn); + return 1; + } + + set_tm_tm_logitem (logitem, tm); + free (tkn); + break; + /* date/time as decimal, i.e., timestamps, ms/us */ + case 'x': + if (logitem->time && logitem->date) + return handle_default_case_token (str, p); + if (!(tkn = parse_string (&(*str), end, 1))) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + + if (str_to_time (tkn, tfmt, &tm, 1) != 0 || set_date (&logitem->date, tm) != 0 || + set_time (&logitem->time, tm) != 0) { + spec_err (logitem, ERR_SPEC_TOKN_INV, *p, tkn); + free (tkn); + return 1; + } + set_numeric_date (&logitem->numdate, logitem->date); + set_tm_dt_logitem (logitem, tm); + set_tm_tm_logitem (logitem, tm); + free (tkn); + break; + /* Virtual Host */ + case 'v': + if (logitem->vhost) + return handle_default_case_token (str, p); + tkn = parse_string (&(*str), end, 1); + if (tkn == NULL) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + logitem->vhost = tkn; + break; + /* remote user */ + case 'e': + if (logitem->userid) + return handle_default_case_token (str, p); + tkn = parse_string (&(*str), end, 1); + if (tkn == NULL) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + logitem->userid = tkn; + break; + /* cache status */ + case 'C': + if (logitem->cache_status) + return handle_default_case_token (str, p); + tkn = parse_string (&(*str), end, 1); + if (tkn == NULL) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + if (is_cache_hit (tkn)) + logitem->cache_status = tkn; + else + free (tkn); + break; + /* remote hostname (IP only) */ + case 'h': + if (logitem->host) + return handle_default_case_token (str, p); + /* per https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2 */ + /* square brackets are possible */ + if (*str[0] == '[' && (*str += 1) && **str) + end = "]"; + if (!(tkn = parse_string (&(*str), end, 1))) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + + if (!conf.no_ip_validation && invalid_ipaddr (tkn, &logitem->type_ip)) { + spec_err (logitem, ERR_SPEC_TOKN_INV, *p, tkn); + free (tkn); + return 1; + } + /* require a valid host token (e.g., ord38s18-in-f14.1e100.net) even when we're + * not validating the IP */ + if (conf.no_ip_validation && *tkn == '\0') { + spec_err (logitem, ERR_SPEC_TOKN_INV, *p, tkn); + free (tkn); + return 1; + } + logitem->host = tkn; + break; + /* request method */ + case 'm': + if (logitem->method) + return handle_default_case_token (str, p); + if (!(tkn = parse_string (&(*str), end, 1))) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + { + const char *meth = NULL; + if (!(meth = extract_method (tkn))) { + spec_err (logitem, ERR_SPEC_TOKN_INV, *p, tkn); + free (tkn); + return 1; + } + logitem->method = xstrdup (meth); + free (tkn); + } + break; + /* request not including method or protocol */ + case 'U': + if (logitem->req) + return handle_default_case_token (str, p); + tkn = parse_string (&(*str), end, 1); + if (tkn == NULL || *tkn == '\0') { + free (tkn); + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + } + + if ((logitem->req = decode_url (tkn)) == NULL) { + spec_err (logitem, ERR_SPEC_TOKN_INV, *p, tkn); + free (tkn); + return 1; + } + free (tkn); + break; + /* query string alone, e.g., ?param=goaccess&tbm=shop */ + case 'q': + if (logitem->qstr) + return handle_default_case_token (str, p); + tkn = parse_string (&(*str), end, 1); + if (tkn == NULL || *tkn == '\0') { + free (tkn); + return 0; + } + + if ((logitem->qstr = decode_url (tkn)) == NULL) { + spec_err (logitem, ERR_SPEC_TOKN_INV, *p, tkn); + free (tkn); + return 1; + } + free (tkn); + break; + /* request protocol */ + case 'H': + if (logitem->protocol) + return handle_default_case_token (str, p); + if (!(tkn = parse_string (&(*str), end, 1))) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + { + const char *proto = NULL; + if (!(proto = extract_protocol (tkn))) { + spec_err (logitem, ERR_SPEC_TOKN_INV, *p, tkn); + free (tkn); + return 1; + } + logitem->protocol = xstrdup (proto); + free (tkn); + } + break; + /* request, including method + protocol */ + case 'r': + if (logitem->req) + return handle_default_case_token (str, p); + if (!(tkn = parse_string (&(*str), end, 1))) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + + logitem->req = parse_req (tkn, &logitem->method, &logitem->protocol); + free (tkn); + break; + /* Status Code */ + case 's': + if (logitem->status >= 0) + return handle_default_case_token (str, p); + if (!(tkn = parse_string (&(*str), end, 1))) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + + logitem->status = strtol (tkn, &sEnd, 10); + if (tkn == sEnd || *sEnd != '\0' || errno == ERANGE || + (!conf.no_strict_status && !is_valid_http_status (logitem->status))) { + spec_err (logitem, ERR_SPEC_TOKN_INV, *p, tkn); + free (tkn); + return 1; + } + free (tkn); + break; + /* size of response in bytes - excluding HTTP headers */ + case 'b': + if (logitem->resp_size) + return handle_default_case_token (str, p); + if (!(tkn = parse_string (&(*str), end, 1))) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + + bandw = strtoull (tkn, &bEnd, 10); + if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE) + bandw = 0; + logitem->resp_size = bandw; + __sync_bool_compare_and_swap (&conf.bandwidth, 0, 1); /* set flag */ + free (tkn); + break; + /* referrer */ + case 'R': + if (logitem->ref) + return handle_default_case_token (str, p); + + if (!(tkn = parse_string (&(*str), end, 1))) + tkn = alloc_string ("-"); + if (*tkn == '\0') { + free (tkn); + tkn = alloc_string ("-"); + } + if (strcmp (tkn, "-") != 0) { + extract_keyphrase (tkn, &logitem->keyphrase); + extract_referer_site (tkn, logitem->site); + + /* hide referrers from report */ + if (hide_referer (logitem->site)) { + logitem->site[0] = '\0'; + free (tkn); + } else + logitem->ref = tkn; + break; + } + logitem->ref = tkn; + + break; + /* user agent */ + case 'u': + if (logitem->agent) + return handle_default_case_token (str, p); + + tkn = parse_string (&(*str), end, 1); + if (tkn != NULL && *tkn != '\0') { + /* Make sure the user agent is decoded (i.e.: CloudFront) */ + logitem->agent = decode_url (tkn); + + set_browser_os (logitem); + set_agent_hash (logitem); + free (tkn); + break; + } else if (tkn != NULL && *tkn == '\0') { + free (tkn); + tkn = alloc_string ("-"); + } + /* must be null */ + else { + tkn = alloc_string ("-"); + } + logitem->agent = tkn; + set_agent_hash (logitem); + break; + /* time taken to serve the request, in milliseconds as a decimal number */ + case 'L': + /* ignore it if we already have served time */ + if (logitem->serve_time) + return handle_default_case_token (str, p); + if (!(tkn = parse_string (&(*str), end, 1))) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + + serve_secs = strtoull (tkn, &bEnd, 10); + if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE) + serve_secs = 0; + /* convert it to microseconds */ + logitem->serve_time = (serve_secs > 0) ? serve_secs * MILS : 0; + + /* Determine if time-served data was stored on-disk. */ + __sync_bool_compare_and_swap (&conf.serve_usecs, 0, 1); /* set flag */ + free (tkn); + break; + /* time taken to serve the request, in seconds with a milliseconds + * resolution */ + case 'T': + /* ignore it if we already have served time */ + if (logitem->serve_time) + return handle_default_case_token (str, p); + if (!(tkn = parse_string (&(*str), end, 1))) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + + if (strchr (tkn, '.') != NULL) + serve_secs = strtod (tkn, &bEnd); + else + serve_secs = strtoull (tkn, &bEnd, 10); + + if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE) + serve_secs = 0; + /* convert it to microseconds */ + logitem->serve_time = (serve_secs > 0) ? serve_secs * SECS : 0; + + /* Determine if time-served data was stored on-disk. */ + __sync_bool_compare_and_swap (&conf.serve_usecs, 0, 1); /* set flag */ + free (tkn); + break; + /* time taken to serve the request, in microseconds */ + case 'D': + /* ignore it if we already have served time */ + if (logitem->serve_time) + return handle_default_case_token (str, p); + if (!(tkn = parse_string (&(*str), end, 1))) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + + serve_time = strtoull (tkn, &bEnd, 10); + if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE) + serve_time = 0; + logitem->serve_time = serve_time; + + /* Determine if time-served data was stored on-disk. */ + __sync_bool_compare_and_swap (&conf.serve_usecs, 0, 1); /* set flag */ + free (tkn); + break; + /* time taken to serve the request, in nanoseconds */ + case 'n': + /* ignore it if we already have served time */ + if (logitem->serve_time) + return handle_default_case_token (str, p); + if (!(tkn = parse_string (&(*str), end, 1))) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + + serve_time = strtoull (tkn, &bEnd, 10); + if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE) + serve_time = 0; + + /* convert it to microseconds */ + logitem->serve_time = (serve_time > 0) ? serve_time / MILS : 0; + + /* Determine if time-served data was stored on-disk. */ + __sync_bool_compare_and_swap (&conf.serve_usecs, 0, 1); /* set flag */ + free (tkn); + break; + /* UMS: Krypto (TLS) "ECDHE-RSA-AES128-GCM-SHA256" */ + case 'k': + /* error to set this twice */ + if (logitem->tls_cypher) + return handle_default_case_token (str, p); + if (!(tkn = parse_string (&(*str), end, 1))) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + +#if defined(HAVE_LIBSSL) && defined(HAVE_CIPHER_STD_NAME) + { + char *tmp = NULL; + for (tmp = tkn; isdigit ((unsigned char) *tmp); tmp++); + if (!strlen (tmp)) + extract_tls_version_cipher (tkn, &logitem->tls_cypher, &logitem->tls_type); + else + logitem->tls_cypher = tkn; + } +#else + logitem->tls_cypher = tkn; +#endif + + break; + + /* UMS: Krypto (TLS) parameters like "TLSv1.2" */ + case 'K': + /* error to set this twice */ + if (logitem->tls_type) + return handle_default_case_token (str, p); + if (!(tkn = parse_string (&(*str), end, 1))) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + + logitem->tls_type = tkn; + break; + + /* UMS: Mime-Type like "text/html" */ + case 'M': + /* error to set this twice */ + if (logitem->mime_type) + return handle_default_case_token (str, p); + if (!(tkn = parse_string (&(*str), end, 1))) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, *p, NULL); + + logitem->mime_type = tkn; + + break; + /* move forward through str until not a space */ + case '~': + find_alpha (&(*str)); + break; + /* everything else skip it */ + default: + handle_default_case_token (str, p); + } + + return 0; +} + +/* Parse the special host specifier and extract the characters that + * need to be rejected when attempting to parse the XFF field. + * + * If no unable to find both curly braces (boundaries), NULL is returned. + * On success, the malloc'd reject set is returned. */ +static char * +extract_braces (const char **p) { + const char *b1 = NULL, *b2 = NULL, *s = *p; + char *ret = NULL; + int esc = 0; + ptrdiff_t len = 0; + + /* iterate over the log format */ + for (; *s; s++) { + if (*s == '\\') { + esc = 1; + } else if (*s == '{' && !esc) { + b1 = s; + } else if (*s == '}' && !esc) { + b2 = s; + break; + } else { + esc = 0; + } + } + + if ((!b1) || (!b2)) + return NULL; + if ((len = b2 - (b1 + 1)) <= 0) + return NULL; + + /* Found braces, extract 'reject' character set. */ + ret = xmalloc (len + 1); + memcpy (ret, b1 + 1, len); + ret[len] = '\0'; + (*p) = b2 + 1; + + return ret; +} + +/* Attempt to extract the client IP from an X-Forwarded-For (XFF) field. + * + * If no IP is found, 1 is returned. + * On success, the malloc'd token is assigned to a GLogItem->host and + * 0 is returned. */ +static int +set_xff_host (GLogItem *logitem, const char *str, const char *skips, int out) { + const char *ptr = NULL, *tkn = NULL; + int invalid_ip = 1, len = 0, type_ip = TYPE_IPINV; + int idx = 0, skips_len = 0; + + skips_len = strlen (skips); + ptr = str; + while (*ptr != '\0') { + if ((len = strcspn (ptr, skips)) == 0) { + len++, ptr++, idx++; + goto move; + } + /* If our index does not match the number of delimiters and we have already a + * valid client IP, then we assume we have reached the length of the XFF */ + if (idx < skips_len && logitem->host) + break; + + ptr += len; + /* extract possible IP */ + if (!(tkn = parsed_string (ptr, &str, 0))) + break; + + invalid_ip = invalid_ipaddr (tkn, &type_ip); + /* done, already have IP and current token is not a host */ + if (logitem->host && invalid_ip) { + free ((void *) tkn); + break; + } + if (!logitem->host && !invalid_ip) { + logitem->host = xstrdup (tkn); + logitem->type_ip = type_ip; + } + free ((void *) tkn); + idx = 0; + + /* found the client IP, break then */ + if (logitem->host && out) + break; + + move: + str += len; + } + + return logitem->host == NULL; +} + +/* Attempt to find possible delimiters in the X-Forwarded-For (XFF) field. + * + * If no IP is found, 1 is returned. + * On success, the malloc'd token is assigned to a GLogItem->host and 0 is returned. */ +static int +find_xff_host (GLogItem *logitem, const char **str, const char **p) { + char *skips = NULL, *extract = NULL; + char pch[2] = { 0 }; + int res = 0; + + if (!(skips = extract_braces (p))) + return spec_err (logitem, ERR_SPEC_SFMT_MIS, **p, "{}"); + + /* if the log format current char is not within the braces special chars, then + * we assume the range of IPs are within hard delimiters */ + if (!strchr (skips, **p) && strchr (*str, **p)) { + *pch = **p; + *(pch + 1) = '\0'; + if (!(extract = parse_string (&(*str), pch, 1))) + goto clean; + + res = set_xff_host (logitem, extract, skips, 1); + free (extract); + (*str)++; /* move a char forward from the trailing delim */ + } else { + res = set_xff_host (logitem, *str, skips, 0); + } + +clean: + free (skips); + + return res; +} + +/* Handle special specifiers. + * + * On error, or unable to parse it, 1 is returned. + * On success, the malloc'd token is assigned to a GLogItem member and + * 0 is returned. */ +static int +special_specifier (GLogItem *logitem, const char **str, const char **p) { + switch (**p) { + /* XFF remote hostname (IP only) */ + case 'h': + if (find_xff_host (logitem, str, p)) + return spec_err (logitem, ERR_SPEC_TOKN_NUL, 'h', NULL); + break; + } + + return 0; +} + +/* Iterate over the given log format. + * + * On error, or unable to parse it, 1 is returned. + * On success, the malloc'd token is assigned to a GLogItem member and + * 0 is returned. */ +static int +parse_format (GLogItem *logitem, const char *str, const char *lfmt) { + char end[2 + 1] = { 0 }; + const char *p = NULL, *last = NULL; + int perc = 0, tilde = 0, ret = 0; + + if (str == NULL || *str == '\0') + return 1; + + /* iterate over the log format */ + last = lfmt + strlen (lfmt); + for (p = lfmt; p < last; p++) { + if (*p == '%') { + perc++; + continue; + } + if (*p == '~' && perc == 0) { + tilde++; + continue; + } + if (*str == '\0') + return spec_err (logitem, ERR_SPEC_LINE_INV, '-', NULL); + if (*str == '\n') + return 0; + + if (tilde && *p != '\0') { + if (*str == '\0') + return 0; + if (special_specifier (logitem, &str, &p) == 1) + return 1; + tilde = 0; + } + /* %h */ + else if (perc && *p != '\0') { + if (*str == '\0') + return 0; + + memset (end, 0, sizeof end); + get_delim (end, p); + /* attempt to parse format specifiers */ + if ((ret = parse_specifier (logitem, &str, p, end))) + return ret; + perc = 0; + } else if (perc && isspace ((unsigned char) p[0])) { + return 1; + } else { + str++; + } + } + + return 0; +} + +/* Determine if the log string is valid and if it's not a comment. + * + * On error, or invalid, 1 is returned. + * On success, or valid line, 0 is returned. */ +static int +valid_line (char *line) { + /* invalid line */ + if ((line == NULL) || (*line == '\0')) + return 1; + /* ignore comments */ + if (*line == '#' || *line == '\n') + return 1; + + return 0; +} + +/* Ignore request's query string. e.g., + * /index.php?timestamp=1454385289 */ +static void +strip_qstring (char *req) { + char *qmark; + if ((qmark = strchr (req, '?')) != NULL) { + if ((qmark - req) > 0) + *qmark = '\0'; + } +} + + +/* Output all log errors stored during parsing. */ +void +output_logerrors (void) { + Logs *logs = get_db_logs (DB_INSTANCE); + GLog *glog = NULL; + int pid = getpid (), i; + + for (i = 0; i < logs->size; ++i) { + glog = &logs->glog[i]; + if (!glog->log_erridx) + continue; + + fprintf (stderr, "==%d== GoAccess - version %s - %s %s\n", pid, GO_VERSION, __DATE__, __TIME__); + fprintf (stderr, "==%d== Config file: %s\n", pid, conf.iconfigfile ? : NO_CONFIG_FILE); + fprintf (stderr, "==%d== https://goaccess.io - \n", pid); + fprintf (stderr, "==%d== Released under the MIT License.\n", pid); + fprintf (stderr, "==%d==\n", pid); + fprintf (stderr, "==%d== FILE: %s\n", pid, glog->props.filename); + fprintf (stderr, "==%d== ", pid); + fprintf (stderr, ERR_PARSED_NLINES, glog->log_erridx); + fprintf (stderr, " %s:\n", ERR_PARSED_NLINES_DESC); + fprintf (stderr, "==%d==\n", pid); + for (i = 0; i < glog->log_erridx; ++i) + fprintf (stderr, "==%d== %s\n", pid, glog->errors[i]); + } + fprintf (stderr, "==%d==\n", pid); + fprintf (stderr, "==%d== %s\n", pid, ERR_FORMAT_HEADER); +} + +/* Ensure we have the following fields. */ +static int +verify_missing_fields (GLogItem *logitem) { + /* must have the following fields */ + if (logitem->host == NULL) + logitem->errstr = xstrdup ("IPv4/6 is required."); + else if (logitem->date == NULL) + logitem->errstr = xstrdup ("A valid date is required."); + else if (logitem->req == NULL) + logitem->errstr = xstrdup ("A request is required."); + + return logitem->errstr != NULL; +} + +/* Determine if the request is from a robot or spider and check if we + * need to ignore or show crawlers only. + * + * If the request line is not ignored, 0 is returned. + * If the request line is ignored, 1 is returned. */ +static int +handle_crawler (const char *agent) { + int bot = 0; + + if (!conf.ignore_crawlers && !conf.crawlers_only) + return 1; + + bot = is_crawler (agent); + return (conf.ignore_crawlers && bot) || (conf.crawlers_only && !bot) ? 0 : 1; +} + +/* A wrapper function to determine if the request is static. + * + * If the request is not static, 0 is returned. + * If the request is static, 1 is returned. */ +static int +is_static (const char *req) { + return verify_static_content (req); +} + +/* Determine if the request of the given status code needs to be + * ignored. + * + * If the status code is not within the ignore-array, 0 is returned. + * If the status code is within the ignore-array, 1 is returned. */ +static int +ignore_status_code (int status) { + int i = 0; + + if (!status || conf.ignore_status_idx == 0) + return 0; + + for (i = 0; i < conf.ignore_status_idx; i++) + if (status == conf.ignore_status[i]) + return 1; + + return 0; +} + +/* Determine if static file request should be ignored + * + * If the request line is not ignored, 0 is returned. + * If the request line is ignored, 1 is returned. */ +static int +ignore_static (const char *req) { + if (conf.ignore_statics && is_static (req)) + return 1; + return 0; +} + +/* Determine if the request status code is a 404. + * + * If the request is not a 404, 0 is returned. + * If the request is a 404, 1 is returned. */ +static int +is_404 (GLogItem *logitem) { + /* is this a 404? */ + if (logitem->status == 404) + return 1; + /* treat 444 as 404? */ + else if (logitem->status == 444 && conf.code444_as_404) + return 1; + return 0; +} + +/* A wrapper function to determine if a log line needs to be ignored. + * + * If the request line is not ignored, 0 is returned. + * If the request line is ignored, IGNORE_LEVEL_PANEL is returned. + * If the request line is only not counted as valid, IGNORE_LEVEL_REQ is returned. */ +static int +ignore_line (GLogItem *logitem) { + if (excluded_ip (logitem) == 0) + return IGNORE_LEVEL_PANEL; + if (handle_crawler (logitem->agent) == 0) + return IGNORE_LEVEL_PANEL; + if (ignore_referer (logitem->ref)) + return IGNORE_LEVEL_PANEL; + if (ignore_status_code (logitem->status)) + return IGNORE_LEVEL_PANEL; + if (ignore_static (logitem->req)) + return conf.ignore_statics; // IGNORE_LEVEL_PANEL or IGNORE_LEVEL_REQ + + /* check if we need to remove the request's query string */ + if (conf.ignore_qstr) + strip_qstring (logitem->req); + + return 0; +} + +/* The following generates a unique key to identity unique visitors. + * The key is made out of the IP, date, and user agent. + * Note that for readability, doing a simple snprintf/sprintf should + * suffice, however, memcpy is the fastest solution + * + * On success the new unique visitor key is returned */ +static char * +get_uniq_visitor_key (GLogItem *logitem) { + char *key = NULL; + size_t s1, s2, s3; + + s1 = strlen (logitem->date); + s2 = strlen (logitem->host); + s3 = strlen (logitem->agent_hex); + + /* includes terminating null */ + key = xcalloc (s1 + s2 + s3 + 3, sizeof (char)); + + memcpy (key, logitem->date, s1); + + key[s1] = '|'; + memcpy (key + s1 + 1, logitem->host, s2 + 1); + + key[s1 + s2 + 1] = '|'; + memcpy (key + s1 + s2 + 2, logitem->agent_hex, s3 + 1); + + return key; +} + +/* Determine if the current log has the content from the last time it was + * parsed. It does this by comparing READ_BYTES against the beginning of the + * log. + * + * Returns 1 if the content is likely the same or no data to compare + * Returns 0 if it has different content */ +static int +is_likely_same_log (GLog *glog, const GLastParse *lp) { + size_t size = 0; + + if (!lp->size) + return 1; + + /* Must be a LOG */ + size = MIN (glog->snippetlen, lp->snippetlen); + if (glog->snippet[0] != '\0' && lp->snippet[0] != '\0' && + memcmp (glog->snippet, lp->snippet, size) == 0) + return 1; + + return 0; +} + +/* Determine if we should insert new record or if it's a duplicate record from + * a previously persisted dataset + * + * Returns 1 if it thinks the record it's being restored from disk + * Returns 0 if we need to parse the record */ +static int +should_restore_from_disk (GLog *glog) { + GLastParse lp = { 0 }; + + if (!conf.restore) + return 0; + + lp = ht_get_last_parse (glog->props.inode); + + /* No last parse timestamp, continue parsing as we got nothing to compare + * against */ + if (!lp.ts) + return 0; + + /* If our current line is greater or equal (zero indexed) to the last parsed + * line and have equal timestamps, then keep parsing then */ + if (glog->props.inode && is_likely_same_log (glog, &lp)) { + if (glog->props.size > lp.size && glog->read >= lp.line) + return 0; + return 1; + } + + /* No inode (probably a pipe), prior or equal timestamps means restore from + * disk (exclusive) */ + if (!glog->props.inode && lp.ts >= glog->lp.ts) + return 1; + + /* If not likely the same content, then fallback to the following checks */ + /* If timestamp is greater than last parsed, read the line then */ + if (glog->lp.ts > lp.ts) + return 0; + + /* Check if current log size is smaller than the one last parsed, if it is, + * it was possibly truncated and thus it may be smaller, so fallback to + * timestamp even if they are equal to the last parsed timestamp */ + else if (glog->props.size < lp.size && glog->lp.ts == lp.ts) + return 0; + + /* Everything else we ignore it. For instance, if current log size is + * greater than the one last parsed, or the timestamp are equal, we ignore the + * request. + * + * **NOTE* We try to play safe here as we would rather miss a few lines + * than double-count a few. */ + return 1; +} + +static void +process_invalid (GLog *glog, GLogItem *logitem, const char *line) { + GLastParse lp = { 0 }; + + /* if not restoring from disk, then count entry as proceeded and invalid */ + if (!conf.restore) { + count_process_and_invalid (glog, logitem, line); + return; + } + + lp = ht_get_last_parse (glog->props.inode); + + /* If our current line is greater or equal (zero indexed) to the last parsed + * line then keep parsing then */ + if (glog->props.inode && is_likely_same_log (glog, &lp)) { + /* only count invalids if we're past the last parsed line */ + if (glog->props.size > lp.size && glog->read >= lp.line) + count_process_and_invalid (glog, logitem, line); + return; + } + + /* no timestamp to compare against, just count the invalid then */ + if (!logitem->numdate) { + count_process_and_invalid (glog, logitem, line); + return; + } + + /* if there's a valid timestamp, count only if greater than last parsed ts */ + if ((glog->lp.ts = mktime (&logitem->dt)) == -1) + return; + + /* check if we were able to at least parse the date/time, if no date/time + * then we simply don't count the entry as proceed & invalid to attempt over + * counting restored data */ + if (should_restore_from_disk (glog) == 0) + count_process_and_invalid (glog, logitem, line); +} + +static int +parse_json_specifier (void *ptr_data, char *key, char *str) { + GLogItem *logitem = (GLogItem *) ptr_data; + char *spec = NULL; + int ret = 0; + + if (!key || !str) + return 0; + /* empty JSON value, e.g., {method: ""} */ + if (0 == strlen (str)) + return 0; + if (!(spec = ht_get_json_logfmt (key))) + return 0; + + ret = parse_format (logitem, str, spec); + free (spec); + + return ret; +} + +static int +parse_json_format (GLogItem *logitem, char *str) { + return parse_json_string (logitem, str, parse_json_specifier); +} + +/* Atomically updates glog->lp.ts with the maximum timestamp value from + * logitem->dt. + * + * On error (if mktime fails), returns -1. + * On success, returns the updated timestamp value, which is also stored in + * glog->lp.ts. + */ +static int +atomic_lpts_update (GLog *glog, GLogItem *logitem) { + int64_t oldts = 0, newts = 0; + /* atomic update loop */ + newts = mktime (&logitem->dt); // Get timestamp from logitem->dt + while (!__sync_bool_compare_and_swap (&glog->lp.ts, oldts, newts)) { + oldts = glog->lp.ts; /* Reread glog->lp.ts if CAS failed */ + if (oldts >= newts) { + break; /* No need to update if oldts is already greater */ + } + } + + return newts; +} + +static int +cleanup_logitem (int ret, GLogItem *logitem) { + free_glog (logitem); + return ret; +} + +/* Process a line from the log and store it accordingly taking into + * account multiple parsing options prior to setting data into the + * corresponding data structure. + * + * On error, logitem->errstr will contains the error message. */ +int +parse_line (GLog *glog, char *line, int dry_run, GLogItem **logitem_out) { + char *fmt = conf.log_format; + int ret = 0; + GLogItem *logitem = NULL; + + /* soft ignore these lines */ + if (valid_line (line)) + return -1; + + logitem = init_log_item (glog); + + /* Parse a line of log, and fill structure with appropriate values */ + if (conf.is_json_log_format) + ret = parse_json_format (logitem, line); + else + ret = parse_format (logitem, line, fmt); + + /* invalid log line (format issue) */ + if (ret) { + process_invalid (glog, logitem, line); + return cleanup_logitem (ret, logitem); + } + + if (!glog->piping && conf.fname_as_vhost && glog->fname_as_vhost) + logitem->vhost = xstrdup (glog->fname_as_vhost); + + /* valid format but missing fields */ + if (ret || (ret = verify_missing_fields (logitem))) { + process_invalid (glog, logitem, line); + return cleanup_logitem (ret, logitem); + } + + /* From here on, valid format but possible ignoring of lines */ + if (atomic_lpts_update (glog, logitem) == -1) + return cleanup_logitem (ret, logitem); + + if (should_restore_from_disk (glog)) + return cleanup_logitem (ret, logitem); + + count_process (glog); + + /* testing log only */ + if (dry_run) + return cleanup_logitem (ret, logitem); + + /* agent will be null in cases where %u is not specified */ + if (logitem->agent == NULL) { + logitem->agent = alloc_string ("-"); + set_agent_hash (logitem); + } + + logitem->ignorelevel = ignore_line (logitem); + /* ignore line */ + if (logitem->ignorelevel == IGNORE_LEVEL_PANEL) + return cleanup_logitem (ret, logitem); + + if (is_404 (logitem)) + logitem->is_404 = 1; + else if (is_static (logitem->req)) + logitem->is_static = 1; + + logitem->uniq_key = get_uniq_visitor_key (logitem); + *logitem_out = logitem; + + return ret; +} + +/* Entry point to process the given line from the log. + * + * On error, NULL is returned. + * On success or soft ignores, GLogItem is returned. */ +static GLogItem * +read_line (GLog *glog, char *line, int *test, uint32_t *cnt, int dry_run) { + GLogItem *logitem = NULL; + int ret = 0; + + /* Begin processing the log line - in case of an invalid log format, flip + * the test only if there's at least one valid record discovered during the log + * format test. This condition applies solely when reading a log from the + * beginning, not when tailing an ongoing log. */ + if ((ret = parse_line (glog, line, dry_run, &logitem)) == 0) + *test = 0; + + /* soft ignore these lines from parse_line */ + if (ret == -1) + return NULL; + + /* reached num of lines to test and no valid records were found, log + * format is likely not matching */ + if (conf.num_tests && ++(*cnt) >= conf.num_tests && *test) { + uncount_processed (glog); + uncount_invalid (glog); + return NULL; + } + glog->read++; + + return logitem; +} + +/* Parse chunk of lines to logitems */ +static void * +read_lines_thread (void *arg) { + GJob *job = (GJob *) arg; + int i = 0; + + for (i = 0; i < job->p; i++) { + /* ensure we don't process more than we should when testing for log format, + * else free chunk and stop processing threads */ + if (!job->test || (job->test && job->cnt < conf.num_tests)) + job->logitems[i] = read_line (job->glog, job->lines[i], &job->test, &job->cnt, job->dry_run); + else + conf.stop_processing = 1; + +#ifdef WITH_GETLINE + free (job->lines[i]); +#endif + } + return (void *) 0; +} + +/* A replacement for GNU getline() to dynamically expand fgets buffer. + * + * On error, NULL is returned. + * On success, the malloc'd line is returned. */ +char * +fgetline (FILE *fp) { + char buf[LINE_BUFFER] = { 0 }; + char *line = NULL, *tmp = NULL; + size_t linelen = 0, len = 0; + + while (1) { + if (!fgets (buf, sizeof (buf), fp)) { + if (conf.process_and_exit && errno == EAGAIN) { + (void) nanosleep ((const struct timespec[]) { {0, 100000000L} }, NULL); + continue; + } else + break; + } + + if (*buf == '\0') + break; + + len = strlen (buf); + + /* overflow check */ + if (SIZE_MAX - len - 1 < linelen) + break; + + if ((tmp = realloc (line, linelen + len + 1)) == NULL) + break; + + line = tmp; + /* append */ + strcpy (line + linelen, buf); + linelen += len; + + if (feof (fp) || buf[len - 1] == '\n') + return line; + } + free (line); + + return NULL; +} + +void * +process_lines_thread (void *arg) { + GJob *job = (GJob *) arg; + int i = 0; + + for (i = 0; i < job->p; i++) { + if (job->logitems[i] != NULL && !job->dry_run && job->logitems[i]->errstr == NULL) { + process_log (job->logitems[i]); + free_glog (job->logitems[i]); + } + } + return (void *) 0; +} + +/* Initialize jobs */ +static void +init_jobs (GJob jobs[2][conf.jobs], GLog *glog, int dry_run, int test) { + int b = 0, k = 0; +#ifndef WITH_GETLINE + int i = 0; +#endif + + for (b = 0; b < 2; b++) { + for (k = 0; k < conf.jobs; k++) { + jobs[b][k].p = 0; + jobs[b][k].cnt = 0; + jobs[b][k].glog = glog; + jobs[b][k].test = test; + jobs[b][k].dry_run = dry_run; + jobs[b][k].running = 0; + jobs[b][k].logitems = xcalloc (conf.chunk_size, sizeof (GLogItem)); + jobs[b][k].lines = xcalloc (conf.chunk_size, sizeof (char *)); +#ifndef WITH_GETLINE + for (i = 0; i < conf.chunk_size; i++) + jobs[b][k].lines[i] = xcalloc (LINE_BUFFER, sizeof (char)); +#endif + } + } +} + +/* Read lines from file */ +static void +read_lines_from_file (FILE *fp, GLog *glog, GJob jobs[2][conf.jobs], int b, char **s) { + int k = 0; + + for (k = 0; k < conf.jobs; k++) { +#ifdef WITH_GETLINE + while ((*s = fgetline (fp)) != NULL) { + jobs[b][k].lines[jobs[b][k].p] = *s; +#else + while ((*s = fgets (jobs[b][k].lines[jobs[b][k].p], LINE_BUFFER, fp)) != NULL) { +#endif + glog->bytes += strlen (jobs[b][k].lines[jobs[b][k].p]); + + if (++(jobs[b][k].p) >= conf.chunk_size) + break; // goto next chunk + } + } +} + +/* Processes lines using threads from the GJob array, updating counters. */ +static void +process_lines (GJob jobs[2][conf.jobs], uint32_t *cnt, int *test, int b) { + int k = 0; + + for (k = 0; k < conf.jobs; k++) { + process_lines_thread (&jobs[b][k]); + *cnt += jobs[b][k].cnt; + jobs[b][k].cnt = 0; + *test &= jobs[b][k].test; + jobs[b][k].p = 0; + } +} + +/* Frees memory for lines and logitems in each job of the GJob array. */ +static void +free_jobs (GJob jobs[2][conf.jobs]) { + int b = 0, k = 0; +#ifndef WITH_GETLINE + int i = 0; +#endif + + for (b = 0; b < 2; b++) { + for (k = 0; k < conf.jobs; k++) { +#ifndef WITH_GETLINE + for (i = 0; i < conf.chunk_size; i++) + free (jobs[b][k].lines[i]); +#endif + free (jobs[b][k].logitems); + free (jobs[b][k].lines); + } + } +} + +/* Reads lines from the given file pointer `fp` and processes them using + * parallel threads. + * + * On error or when interrupted by a signal (SIGINT), the function returns 0. + * On success, it returns 1 if the number of processed lines is greater than or + * equal to the configured number of tests (NUM_TESTS), otherwise 0. + */ +static int +read_lines (FILE *fp, GLog *glog, int dry_run) { + int b = 0, k = 0, test = conf.num_tests > 0 ? 1 : 0; + uint32_t cnt = 0; + void *status = NULL; + char *s = NULL; + GJob jobs[2][conf.jobs]; + pthread_t threads[conf.jobs]; + + glog->bytes = 0; + + init_jobs (jobs, glog, dry_run, test); + + b = 0; + while (1) { /* b = 0 or 1 */ + read_lines_from_file (fp, glog, jobs, b, &s); + + /* if nothing was read from the log, skip it for now */ + if (!glog->bytes) { + test = 0; + break; + } + + if (conf.jobs == 1) { + read_lines_thread (&jobs[b][0]); + } else { + for (k = 0; k < conf.jobs; k++) { + jobs[b][k].running = 1; + pthread_create (&threads[k], NULL, read_lines_thread, (void *) &jobs[b][k]); + } + } + + /* flip from block A/B to B/A */ + if (conf.jobs > 1) + b = b ^ 1; + + process_lines (jobs, &cnt, &test, b); + + /* flip from block B/A to A/B */ + if (conf.jobs > 1) + b = b ^ 1; + + if (conf.jobs > 1) { + for (k = 0; k < conf.jobs; k++) { + if (jobs[b][k].running) { + pthread_join (threads[k], &status); + jobs[b][k].running = 0; + } + } + } + + if (dry_run && cnt >= NUM_TESTS) + break; + + /* handle SIGINT */ + if (conf.stop_processing) + break; + + /* check for EOF */ + if (s == NULL) + break; + + /* flip from block A/B to B/A */ + if (conf.jobs > 1) + b = b ^ 1; + } // while (1) + + /* After eof, process last data */ + for (b = 0; b < 2; b++) { + for (k = 0; k < conf.jobs; k++) { + if (conf.jobs > 1 && jobs[b][k].running) { + pthread_join (threads[k], &status); + jobs[b][k].running = 0; + } + + if (jobs[b][k].p) { + process_lines_thread (&jobs[b][k]); + cnt += jobs[b][k].cnt; + jobs[b][k].cnt = 0; + test &= jobs[b][k].test; + jobs[b][k].p = 0; + } + } + } + + free_jobs (jobs); + + /* if no data was available to read from (probably from a pipe) and still in + * test mode and still below the test count, we simply return until data + * becomes available */ + if (!s && (errno == EAGAIN || errno == EWOULDBLOCK) && test && cnt < conf.num_tests) + return 0; + + return test; +} + +/* Read the given log file and attempt to mmap a fixed number of bytes so we + * can compare its content on future runs. + * + * On error, 1 is returned. + * On success, 0 is returned. */ +int +set_initial_persisted_data (GLog *glog, FILE *fp, const char *fn) { + size_t len; + time_t now = time (0); + + /* reset the snippet */ + memset (glog->snippet, 0, sizeof (glog->snippet)); + glog->snippetlen = 0; + + if (glog->props.size == 0) + return 1; + + len = MIN (glog->props.size, READ_BYTES); + if ((fread (glog->snippet, len, 1, fp)) != 1 && ferror (fp)) + FATAL ("Unable to fread the specified log file '%s'", fn); + glog->snippetlen = len; + localtime_r (&now, &glog->start_time); + + fseek (fp, 0, SEEK_SET); + + return 0; +} + +static void +persist_last_parse (GLog *glog) { + /* insert last parsed data for the recently file parsed */ + if (glog->props.inode && glog->props.size) { + glog->lp.line = glog->read; + glog->lp.snippetlen = glog->snippetlen; + + memcpy (glog->lp.snippet, glog->snippet, glog->snippetlen); + + ht_insert_last_parse (glog->props.inode, &glog->lp); + } + /* probably from a pipe */ + else if (!glog->props.inode) { + ht_insert_last_parse (0, &glog->lp); + } +} + +/* Read the given log line by line and process its data. + * + * On error, 1 is returned. + * On success, 0 is returned. */ +static int +read_log (GLog *glog, int dry_run) { + FILE *fp = NULL; + int piping = 0; + struct stat fdstat; + + /* Ensure we have a valid pipe to read from stdin. Only checking for + * conf.read_stdin without verifying for a valid FILE pointer would certainly + * lead to issues. */ + if (glog->props.filename[0] == '-' && glog->props.filename[1] == '\0' && glog->pipe) { + fp = glog->pipe; + glog->piping = piping = 1; + } + + /* make sure we can open the log (if not reading from stdin) */ + if (!piping && (fp = fopen (glog->props.filename, "r")) == NULL) + FATAL ("Unable to open the specified log file '%s'. %s", glog->props.filename, + strerror (errno)); + + /* grab the inode of the file being parsed */ + if (!piping && stat (glog->props.filename, &fdstat) == 0) { + glog->props.inode = fdstat.st_ino; + glog->props.size = glog->lp.size = fdstat.st_size; + set_initial_persisted_data (glog, fp, glog->props.filename); + } + + /* read line by line */ + if (read_lines (fp, glog, dry_run)) { + if (!piping) + fclose (fp); + return 1; + } + + persist_last_parse (glog); + + /* close log file if not a pipe */ + if (!piping) + fclose (fp); + + return 0; +} + +static void +set_log_processing (Logs *logs, GLog *glog) { + lock_spinner (); + logs->processed = &(glog->processed); + logs->filename = glog->props.filename; + unlock_spinner (); +} + +/* Entry point to parse the log line by line. + * + * On error, 1 is returned. + * On success, 0 is returned. */ +int +parse_log (Logs *logs, int dry_run) { + GLog *glog = NULL; + const char *err_log = NULL; + int idx; + + /* verify that we have the required formats */ + if ((err_log = verify_formats ())) + FATAL ("%s", err_log); + + /* no data piped, no logs passed, load from disk only then */ + if (conf.restore && !logs->restored) + logs->restored = rebuild_rawdata_cache (); + + /* no data piped, no logs passed, load from disk only then */ + if (conf.restore && !conf.filenames_idx && !conf.read_stdin) { + logs->load_from_disk_only = 1; + return 0; + } + + for (idx = 0; idx < logs->size; ++idx) { + glog = &logs->glog[idx]; + set_log_processing (logs, glog); + + if (read_log (glog, dry_run)) + return 1; + + glog->length = glog->bytes; + } + + return 0; +} + +/* Ensure we have valid hits + * + * On error, an array of pointers containing the error strings. + * On success, NULL is returned. */ +char ** +test_format (Logs *logs, int *len) { + char **errors = NULL; + GLog *glog = NULL; + int i; + + if (parse_log (logs, 1) == 0) + return NULL; + + for (i = 0; i < logs->size; ++i) { + glog = &logs->glog[i]; + if (!glog->log_erridx) + continue; + break; + } + + errors = xcalloc (glog->log_erridx, sizeof (char *)); + *len = glog->log_erridx; + for (i = 0; i < glog->log_erridx; ++i) + errors[i] = xstrdup (glog->errors[i]); + free_logerrors (glog); + + return errors; +} diff --git a/src/parser.h b/src/parser.h new file mode 100644 index 0000000000..c911ed2c74 --- /dev/null +++ b/src/parser.h @@ -0,0 +1,217 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef PARSER_H_INCLUDED +#define PARSER_H_INCLUDED + +#define KEY_FOUND 1 +#define KEY_NOT_FOUND -1 +#define LINE_BUFFER 4096 /* read at most this num of chars */ +#define NUM_TESTS 20 /* test this many lines from the log */ +#define MAX_LOG_ERRORS 20 +#define READ_BYTES 4096u +#define MAX_BATCH_LINES 8192u /* max number of lines to read per batch before a reflow */ + +#define LINE_LEN 23 +#define ERROR_LEN 255 +#define REF_SITE_LEN 511 /* maximum length of a referring site */ +#define CACHE_STATUS_LEN 7 +#define HASH_HEX 64 + +#define ERR_SPEC_TOKN_NUL 0x1 +#define ERR_SPEC_TOKN_INV 0x2 +#define ERR_SPEC_SFMT_MIS 0x3 +#define ERR_SPEC_LINE_INV 0x4 +#define ERR_LOG_NOT_FOUND 0x5 +#define ERR_LOG_REALLOC_FAILURE 0x6 + + +#include +#include "commons.h" +#include "gslist.h" + +typedef struct GLogProp_ { + char *filename; /* filename including path */ + char *fname; /* basename(filename) */ + uint64_t inode; /* inode of the log */ + uint64_t size; /* original size of log */ +} GLogProp; + +/* Log properties. Note: This is per line parsed */ +typedef struct GLogItem_ { + char *agent; + char *browser; + char *browser_type; + char *continent; + char *country; + char *asn; + char *date; + char *host; + char *keyphrase; + char *method; + char *os; + char *os_type; + char *protocol; + char *qstr; + char *ref; + char *req; + char *req_key; + int status; + char *time; + char *uniq_key; + char *vhost; + char *userid; + char *cache_status; + + char site[REF_SITE_LEN + 1]; + char agent_hex[HASH_HEX]; + + uint64_t resp_size; + uint64_t serve_time; + + uint32_t numdate; + uint32_t agent_hash; + int ignorelevel; + int type_ip; + int is_404; + int is_static; + int uniq_nkey; + int agent_nkey; + + /* UMS */ + char *mime_type; + char *tls_type; + char *tls_cypher; + char *tls_type_cypher; + + char *errstr; + struct tm dt; +} GLogItem; + +typedef struct GLastParse_ { + uint32_t line; + int64_t ts; + uint64_t size; + uint16_t snippetlen; + char snippet[READ_BYTES + 1]; +} GLastParse; + +/* Overall parsed log properties */ +typedef struct GLog_ { + uint8_t piping:1; + uint8_t log_erridx; + uint32_t read; /* lines read/parsed */ + uint64_t bytes; /* bytes read on each iteration */ + uint64_t length; /* length read from the log so far */ + uint64_t invalid; /* invalid lines for this log */ + uint64_t processed; /* lines proceeded for this log */ + + /* file test for persisted/restored data */ + uint16_t snippetlen; + char snippet[READ_BYTES + 1]; + + GLastParse lp; + GLogProp props; + struct tm start_time; + + char *fname_as_vhost; + char **errors; + + FILE *pipe; +} GLog; + +/* Container for all logs */ +typedef struct Logs_ { + uint8_t restored:1; + uint8_t load_from_disk_only:1; + uint64_t *processed; + uint64_t offset; + int size; /* num items */ + int idx; + char *filename; + GLog *glog; +} Logs; + +/* Pthread jobs for multi-thread */ +typedef struct GJob_ { + uint32_t cnt; + int p, test, dry_run, running; + GLog *glog; + GLogItem **logitems; + char **lines; +} GJob; + +/* Raw data field type */ +typedef enum { + U32, + STR +} datatype; + +/* Raw Data extracted from table stores */ +typedef struct GRawDataItem_ { + uint32_t nkey; + union { + const char *data; + uint32_t hits; + }; +} GRawDataItem; + +/* Raw Data per module */ +typedef struct GRawData_ { + GRawDataItem *items; /* data */ + GModule module; /* current module */ + datatype type; + int idx; /* first level index */ + int size; /* total num of items on ht */ +} GRawData; + + +char *extract_by_delim (const char **str, const char *end); +char *fgetline (FILE * fp); +char **test_format (Logs * logs, int *len); +int parse_line (GLog * glog, char *line, int dry_run, GLogItem ** logitem_out); +int parse_log (Logs * logs, int dry_run); +int set_glog (Logs * logs, const char *filename); +int set_initial_persisted_data (GLog * glog, FILE * fp, const char *fn); +int set_log (Logs * logs, const char *value); +void free_glog (GLogItem * logitem); +void free_logerrors (GLog * glog); +void free_logs (Logs * logs); +void free_raw_data (GRawData * raw_data); +void output_logerrors (void); +void *process_lines_thread (void *arg); +void reset_struct (Logs * logs); + +GLogItem *init_log_item (GLog * glog); +GRawDataItem *new_grawdata_item (unsigned int size); +GRawData *new_grawdata (void); +Logs *init_logs (int size); +Logs *new_logs (int size); + +#endif diff --git a/src/pdjson.c b/src/pdjson.c new file mode 100644 index 0000000000..0b75871964 --- /dev/null +++ b/src/pdjson.c @@ -0,0 +1,967 @@ +/** + * Public Domain JSON Parser for C + * By Christopher Wellons + * https://github.com/skeeto/pdjson */ + +#ifndef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200112L +#elif _POSIX_C_SOURCE < 200112L +# error incompatible _POSIX_C_SOURCE level +#endif + +#include +#include +#include + +#ifndef PDJSON_H +# include "pdjson.h" +#endif + +#define JSON_FLAG_ERROR (1u << 0) +#define JSON_FLAG_STREAMING (1u << 1) + +#if defined(_MSC_VER) && (_MSC_VER < 1900) + +#define json_error(json, format, ...) \ + if (!(json->flags & JSON_FLAG_ERROR)) { \ + json->flags |= JSON_FLAG_ERROR; \ + _snprintf_s(json->errmsg, sizeof(json->errmsg), \ + _TRUNCATE, \ + format, \ + __VA_ARGS__); \ + } \ + +#else + +#define json_error(json, format, ...) \ + if (!(json->flags & JSON_FLAG_ERROR)) { \ + json->flags |= JSON_FLAG_ERROR; \ + snprintf(json->errmsg, sizeof(json->errmsg), \ + format, \ + __VA_ARGS__); \ + } \ + +#endif /* _MSC_VER */ + +/* See also PDJSON_STACK_MAX below. */ +#ifndef PDJSON_STACK_INC +# define PDJSON_STACK_INC 4 +#endif + +struct json_stack { + enum json_type type; + long count; +}; + +static enum json_type +push (json_stream *json, enum json_type type) { + json->stack_top++; + +#ifdef PDJSON_STACK_MAX + if (json->stack_top > PDJSON_STACK_MAX) { + json_error (json, "%s", "maximum depth of nesting reached"); + return JSON_ERROR; + } +#endif + + if (json->stack_top >= json->stack_size) { + struct json_stack *stack; + size_t size = (json->stack_size + PDJSON_STACK_INC) * sizeof (*json->stack); + stack = (struct json_stack *) json->alloc.realloc (json->stack, size); + if (stack == NULL) { + json_error (json, "%s", "out of memory"); + return JSON_ERROR; + } + + json->stack_size += PDJSON_STACK_INC; + json->stack = stack; + } + + json->stack[json->stack_top].type = type; + json->stack[json->stack_top].count = 0; + + return type; +} + +static enum json_type +pop (json_stream *json, int c, enum json_type expected) { + if (json->stack == NULL || json->stack[json->stack_top].type != expected) { + json_error (json, "unexpected byte '%c'", c); + return JSON_ERROR; + } + json->stack_top--; + return expected == JSON_ARRAY ? JSON_ARRAY_END : JSON_OBJECT_END; +} + +static int +buffer_peek (struct json_source *source) { + if (source->position < source->source.buffer.length) + return source->source.buffer.buffer[source->position]; + else + return EOF; +} + +static int +buffer_get (struct json_source *source) { + int c = source->peek (source); + source->position++; + return c; +} + +static int +stream_get (struct json_source *source) { + source->position++; + return fgetc (source->source.stream.stream); +} + +static int +stream_peek (struct json_source *source) { + int c = fgetc (source->source.stream.stream); + ungetc (c, source->source.stream.stream); + return c; +} + +static void +init (json_stream *json) { + json->lineno = 1; + json->flags = JSON_FLAG_STREAMING; + json->errmsg[0] = '\0'; + json->ntokens = 0; + json->next = (enum json_type) 0; + + json->stack = NULL; + json->stack_top = (size_t) -1; + json->stack_size = 0; + + json->data.string = NULL; + json->data.string_size = 0; + json->data.string_fill = 0; + json->source.position = 0; + + json->alloc.malloc = malloc; + json->alloc.realloc = realloc; + json->alloc.free = free; +} + +static enum json_type +is_match (json_stream *json, const char *pattern, enum json_type type) { + int c; + const char *p = NULL; + for (p = pattern; *p; p++) { + if (*p != (c = json->source.get (&json->source))) { + json_error (json, "expected '%c' instead of byte '%c'", *p, c); + return JSON_ERROR; + } + } + return type; +} + +static int +pushchar (json_stream *json, int c) { + if (json->data.string_fill == json->data.string_size) { + size_t size = json->data.string_size * 2; + char *buffer = (char *) json->alloc.realloc (json->data.string, size); + if (buffer == NULL) { + json_error (json, "%s", "out of memory"); + return -1; + } else { + json->data.string_size = size; + json->data.string = buffer; + } + } + json->data.string[json->data.string_fill++] = c; + return 0; +} + +static int +init_string (json_stream *json) { + json->data.string_fill = 0; + if (json->data.string == NULL) { + json->data.string_size = 1024; + json->data.string = (char *) json->alloc.malloc (json->data.string_size); + if (json->data.string == NULL) { + json_error (json, "%s", "out of memory"); + return -1; + } + } + json->data.string[0] = '\0'; + return 0; +} + +static int +encode_utf8 (json_stream *json, unsigned long c) { + if (c < 0x80UL) { + return pushchar (json, c); + } else if (c < 0x0800UL) { + return !((pushchar (json, (c >> 6 & 0x1F) | 0xC0) == 0) && + (pushchar (json, (c >> 0 & 0x3F) | 0x80) == 0)); + } else if (c < 0x010000UL) { + if (c >= 0xd800 && c <= 0xdfff) { + json_error (json, "invalid codepoint %06lx", c); + return -1; + } + return !((pushchar (json, (c >> 12 & 0x0F) | 0xE0) == 0) && + (pushchar (json, (c >> 6 & 0x3F) | 0x80) == 0) && + (pushchar (json, (c >> 0 & 0x3F) | 0x80) == 0)); + } else if (c < 0x110000UL) { + return !((pushchar (json, (c >> 18 & 0x07) | 0xF0) == 0) && + (pushchar (json, (c >> 12 & 0x3F) | 0x80) == 0) && + (pushchar (json, (c >> 6 & 0x3F) | 0x80) == 0) && + (pushchar (json, (c >> 0 & 0x3F) | 0x80) == 0)); + } else { + json_error (json, "unable to encode %06lx as UTF-8", c); + return -1; + } +} + +static int +hexchar (int c) { + switch (c) { + case '0': + return 0; + case '1': + return 1; + case '2': + return 2; + case '3': + return 3; + case '4': + return 4; + case '5': + return 5; + case '6': + return 6; + case '7': + return 7; + case '8': + return 8; + case '9': + return 9; + case 'a': + case 'A': + return 10; + case 'b': + case 'B': + return 11; + case 'c': + case 'C': + return 12; + case 'd': + case 'D': + return 13; + case 'e': + case 'E': + return 14; + case 'f': + case 'F': + return 15; + default: + return -1; + } +} + +static long +read_unicode_cp (json_stream *json) { + long cp = 0; + int shift = 12; + size_t i = 0; + + for (i = 0; i < 4; i++) { + int c = json->source.get (&json->source); + int hc; + + if (c == EOF) { + json_error (json, "%s", "unterminated string literal in Unicode"); + return -1; + } else if ((hc = hexchar (c)) == -1) { + json_error (json, "invalid escape Unicode byte '%c'", c); + return -1; + } + + cp += hc * (1 << shift); + shift -= 4; + } + + + return cp; +} + +static int +read_unicode (json_stream *json) { + long cp, h, l; + int c; + + if ((cp = read_unicode_cp (json)) == -1) { + return -1; + } + + if (cp >= 0xd800 && cp <= 0xdbff) { + /* This is the high portion of a surrogate pair; we need to read the + * lower portion to get the codepoint + */ + h = cp; + + c = json->source.get (&json->source); + if (c == EOF) { + json_error (json, "%s", "unterminated string literal in Unicode"); + return -1; + } else if (c != '\\') { + json_error (json, "invalid continuation for surrogate pair '%c', " "expected '\\'", c); + return -1; + } + + c = json->source.get (&json->source); + if (c == EOF) { + json_error (json, "%s", "unterminated string literal in Unicode"); + return -1; + } else if (c != 'u') { + json_error (json, "invalid continuation for surrogate pair '%c', " "expected 'u'", c); + return -1; + } + + if ((l = read_unicode_cp (json)) == -1) { + return -1; + } + + if (l < 0xdc00 || l > 0xdfff) { + json_error (json, "surrogate pair continuation \\u%04lx out " "of range (dc00-dfff)", l); + return -1; + } + + cp = ((h - 0xd800) * 0x400) + ((l - 0xdc00) + 0x10000); + } else if (cp >= 0xdc00 && cp <= 0xdfff) { + json_error (json, "dangling surrogate \\u%04lx", cp); + return -1; + } + + return encode_utf8 (json, cp); +} + +static int +read_escaped (json_stream *json) { + int c = json->source.get (&json->source); + if (c == EOF) { + json_error (json, "%s", "unterminated string literal in escape"); + return -1; + } else if (c == 'u') { + if (read_unicode (json) != 0) + return -1; + } else { + switch (c) { + case '\\': + case 'b': + case 'f': + case 'n': + case 'r': + case 't': + case '/': + case '"': + { + const char *codes = "\\bfnrt/\""; + const char *p = strchr (codes, c); + if (pushchar (json, "\\\b\f\n\r\t/\""[p - codes]) != 0) + return -1; + } + break; + default: + json_error (json, "invalid escaped byte '%c'", c); + return -1; + } + } + return 0; +} + +static int +char_needs_escaping (int c) { + if ((c >= 0) && (c < 0x20 || c == 0x22 || c == 0x5c)) { + return 1; + } + + return 0; +} + +static int +utf8_seq_length (char byte) { + unsigned char u = (unsigned char) byte; + if (u < 0x80) + return 1; + + if (0x80 <= u && u <= 0xBF) { + // second, third or fourth byte of a multi-byte + // sequence, i.e. a "continuation byte" + return 0; + } else if (u == 0xC0 || u == 0xC1) { + // overlong encoding of an ASCII byte + return 0; + } else if (0xC2 <= u && u <= 0xDF) { + // 2-byte sequence + return 2; + } else if (0xE0 <= u && u <= 0xEF) { + // 3-byte sequence + return 3; + } else if (0xF0 <= u && u <= 0xF4) { + // 4-byte sequence + return 4; + } else { + // u >= 0xF5 + // Restricted (start of 4-, 5- or 6-byte sequence) or invalid UTF-8 + return 0; + } +} + +static int +is_legal_utf8 (const unsigned char *bytes, int length) { + unsigned char a; + const unsigned char *srcptr; + + if (0 == bytes || 0 == length) + return 0; + + srcptr = bytes + length; + switch (length) { + default: + return 0; + // Everything else falls through when true. + case 4: + if ((a = (*--srcptr)) < 0x80 || a > 0xBF) + return 0; + /* FALLTHRU */ + case 3: + if ((a = (*--srcptr)) < 0x80 || a > 0xBF) + return 0; + /* FALLTHRU */ + case 2: + a = (*--srcptr); + switch (*bytes) { + case 0xE0: + if (a < 0xA0 || a > 0xBF) + return 0; + break; + case 0xED: + if (a < 0x80 || a > 0x9F) + return 0; + break; + case 0xF0: + if (a < 0x90 || a > 0xBF) + return 0; + break; + case 0xF4: + if (a < 0x80 || a > 0x8F) + return 0; + break; + default: + if (a < 0x80 || a > 0xBF) + return 0; + break; + } + /* FALLTHRU */ + case 1: + if (*bytes >= 0x80 && *bytes < 0xC2) + return 0; + } + return *bytes <= 0xF4; +} + +static int +read_utf8 (json_stream *json, int next_char) { + int i; + char buffer[4]; + int count = utf8_seq_length (next_char); + if (!count) { + json_error (json, "%s", "invalid UTF-8 character"); + return -1; + } + + buffer[0] = next_char; + for (i = 1; i < count; ++i) { + buffer[i] = json->source.get (&json->source); + } + + if (!is_legal_utf8 ((unsigned char *) buffer, count)) { + json_error (json, "%s", "invalid UTF-8 text"); + return -1; + } + + for (i = 0; i < count; ++i) { + if (pushchar (json, buffer[i]) != 0) + return -1; + } + return 0; +} + +static enum json_type +read_string (json_stream *json) { + if (init_string (json) != 0) + return JSON_ERROR; + while (1) { + int c = json->source.get (&json->source); + if (c == EOF) { + json_error (json, "%s", "unterminated string literal"); + return JSON_ERROR; + } else if (c == '"') { + if (pushchar (json, '\0') == 0) + return JSON_STRING; + else + return JSON_ERROR; + } else if (c == '\\') { + if (read_escaped (json) != 0) + return JSON_ERROR; + } else if ((unsigned) c >= 0x80) { + if (read_utf8 (json, c) != 0) + return JSON_ERROR; + } else { + if (char_needs_escaping (c)) { + json_error (json, "%s", "unescaped control character in string"); + return JSON_ERROR; + } + + if (pushchar (json, c) != 0) + return JSON_ERROR; + } + } + return JSON_ERROR; +} + +static int +is_digit (int c) { + return c >= 48 /*0 */ && c <= 57 /*9 */ ; +} + +static int +read_digits (json_stream *json) { + int c; + unsigned nread = 0; + while (is_digit (c = json->source.peek (&json->source))) { + if (pushchar (json, json->source.get (&json->source)) != 0) + return -1; + + nread++; + } + + if (nread == 0) { + json_error (json, "expected digit instead of byte '%c'", c); + return -1; + } + + return 0; +} + +static enum json_type +read_number (json_stream *json, int c) { + if (pushchar (json, c) != 0) + return JSON_ERROR; + if (c == '-') { + c = json->source.get (&json->source); + if (is_digit (c)) { + return read_number (json, c); + } else { + json_error (json, "unexpected byte '%c' in number", c); + return JSON_ERROR; + } + } else if (strchr ("123456789", c) != NULL) { + c = json->source.peek (&json->source); + if (is_digit (c)) { + if (read_digits (json) != 0) + return JSON_ERROR; + } + } + /* Up to decimal or exponent has been read. */ + c = json->source.peek (&json->source); + if (strchr (".eE", c) == NULL) { + if (pushchar (json, '\0') != 0) + return JSON_ERROR; + else + return JSON_NUMBER; + } + if (c == '.') { + json->source.get (&json->source); // consume . + if (pushchar (json, c) != 0) + return JSON_ERROR; + if (read_digits (json) != 0) + return JSON_ERROR; + } + /* Check for exponent. */ + c = json->source.peek (&json->source); + if (c == 'e' || c == 'E') { + json->source.get (&json->source); // consume e/E + if (pushchar (json, c) != 0) + return JSON_ERROR; + c = json->source.peek (&json->source); + if (c == '+' || c == '-') { + json->source.get (&json->source); // consume + if (pushchar (json, c) != 0) + return JSON_ERROR; + if (read_digits (json) != 0) + return JSON_ERROR; + } else if (is_digit (c)) { + if (read_digits (json) != 0) + return JSON_ERROR; + } else { + json_error (json, "unexpected byte '%c' in number", c); + return JSON_ERROR; + } + } + if (pushchar (json, '\0') != 0) + return JSON_ERROR; + else + return JSON_NUMBER; +} + +bool +json_isspace (int c) { + switch (c) { + case 0x09: + case 0x0a: + case 0x0d: + case 0x20: + return true; + } + + return false; +} + +/* Returns the next non-whitespace character in the stream. */ +static int +next (json_stream *json) { + int c; + while (json_isspace (c = json->source.get (&json->source))) + if (c == '\n') + json->lineno++; + return c; +} + +static enum json_type +read_value (json_stream *json, int c) { + json->ntokens++; + switch (c) { + case EOF: + json_error (json, "%s", "unexpected end of text"); + return JSON_ERROR; + case '{': + return push (json, JSON_OBJECT); + case '[': + return push (json, JSON_ARRAY); + case '"': + return read_string (json); + case 'n': + return is_match (json, "ull", JSON_NULL); + case 'f': + return is_match (json, "alse", JSON_FALSE); + case 't': + return is_match (json, "rue", JSON_TRUE); + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '-': + if (init_string (json) != 0) + return JSON_ERROR; + return read_number (json, c); + default: + json_error (json, "unexpected byte '%c' in value", c); + return JSON_ERROR; + } +} + +enum json_type +json_peek (json_stream *json) { + enum json_type next; + if (json->next) + next = json->next; + else + next = json->next = json_next (json); + return next; +} + +enum json_type +json_next (json_stream *json) { + int c; + enum json_type value; + if (json->flags & JSON_FLAG_ERROR) + return JSON_ERROR; + if (json->next != 0) { + enum json_type next = json->next; + json->next = (enum json_type) 0; + return next; + } + if (json->ntokens > 0 && json->stack_top == (size_t) -1) { + + /* In the streaming mode leave any trailing whitespaces in the stream. + * This allows the user to validate any desired separation between + * values (such as newlines) using json_source_get/peek() with any + * remaining whitespaces ignored as leading when we parse the next + * value. */ + if (!(json->flags & JSON_FLAG_STREAMING)) { + do { + c = json->source.peek (&json->source); + if (json_isspace (c)) { + c = json->source.get (&json->source); + } + } while (json_isspace (c)); + + if (c != EOF) { + json_error (json, "expected end of text instead of byte '%c'", c); + return JSON_ERROR; + } + } + + return JSON_DONE; + } + c = next (json); + if (json->stack_top == (size_t) -1) { + if (c == EOF && (json->flags & JSON_FLAG_STREAMING)) + return JSON_DONE; + + return read_value (json, c); + } + if (json->stack[json->stack_top].type == JSON_ARRAY) { + if (json->stack[json->stack_top].count == 0) { + if (c == ']') { + return pop (json, c, JSON_ARRAY); + } + json->stack[json->stack_top].count++; + return read_value (json, c); + } else if (c == ',') { + json->stack[json->stack_top].count++; + return read_value (json, next (json)); + } else if (c == ']') { + return pop (json, c, JSON_ARRAY); + } else { + json_error (json, "unexpected byte '%c'", c); + return JSON_ERROR; + } + } else if (json->stack[json->stack_top].type == JSON_OBJECT) { + if (json->stack[json->stack_top].count == 0) { + if (c == '}') { + return pop (json, c, JSON_OBJECT); + } + + /* No member name/value pairs yet. */ + value = read_value (json, c); + if (value != JSON_STRING) { + if (value != JSON_ERROR) + json_error (json, "%s", "expected member name or '}'"); + return JSON_ERROR; + } else { + json->stack[json->stack_top].count++; + return value; + } + } else if ((json->stack[json->stack_top].count % 2) == 0) { + /* Expecting comma followed by member name. */ + if (c != ',' && c != '}') { + json_error (json, "%s", "expected ',' or '}' after member value"); + return JSON_ERROR; + } else if (c == '}') { + return pop (json, c, JSON_OBJECT); + } else { + value = read_value (json, next (json)); + if (value != JSON_STRING) { + if (value != JSON_ERROR) + json_error (json, "%s", "expected member name"); + return JSON_ERROR; + } else { + json->stack[json->stack_top].count++; + return value; + } + } + } else if ((json->stack[json->stack_top].count % 2) == 1) { + /* Expecting colon followed by value. */ + if (c != ':') { + json_error (json, "%s", "expected ':' after member name"); + return JSON_ERROR; + } else { + json->stack[json->stack_top].count++; + return read_value (json, next (json)); + } + } + } + json_error (json, "%s", "invalid parser state"); + return JSON_ERROR; +} + +void +json_reset (json_stream *json) { + json->stack_top = -1; + json->ntokens = 0; + json->flags &= ~JSON_FLAG_ERROR; + json->errmsg[0] = '\0'; +} + +enum json_type +json_skip (json_stream *json) { + enum json_type type = json_next (json); + size_t cnt_arr = 0; + size_t cnt_obj = 0; + enum json_type skip; + + for (skip = type;; skip = json_next (json)) { + if (skip == JSON_ERROR || skip == JSON_DONE) + return skip; + + if (skip == JSON_ARRAY) { + ++cnt_arr; + } else if (skip == JSON_ARRAY_END && cnt_arr > 0) { + --cnt_arr; + } else if (skip == JSON_OBJECT) { + ++cnt_obj; + } else if (skip == JSON_OBJECT_END && cnt_obj > 0) { + --cnt_obj; + } + + if (!cnt_arr && !cnt_obj) + break; + } + + return type; +} + +enum json_type +json_skip_until (json_stream *json, enum json_type type) { + while (1) { + enum json_type skip = json_skip (json); + + if (skip == JSON_ERROR || skip == JSON_DONE) + return skip; + + if (skip == type) + break; + } + + return type; +} + +const char * +json_get_string (json_stream *json, size_t *length) { + if (length != NULL) + *length = json->data.string_fill; + if (json->data.string == NULL) + return ""; + else + return json->data.string; +} + +double +json_get_number (json_stream *json) { + char *p = json->data.string; + return p == NULL ? 0 : strtod (p, NULL); +} + +const char * +json_get_error (json_stream *json) { + return json->flags & JSON_FLAG_ERROR ? json->errmsg : NULL; +} + +size_t +json_get_lineno (json_stream *json) { + return json->lineno; +} + +size_t +json_get_position (json_stream *json) { + return json->source.position; +} + +size_t +json_get_depth (json_stream *json) { + return json->stack_top + 1; +} + +/* Return the current parsing context, that is, JSON_OBJECT if we are inside + an object, JSON_ARRAY if we are inside an array, and JSON_DONE if we are + not yet/anymore in either. + + Additionally, for the first two cases, also return the number of parsing + events that have already been observed at this level with json_next/peek(). + In particular, inside an object, an odd number would indicate that the just + observed JSON_STRING event is a member name. +*/ +enum json_type +json_get_context (json_stream *json, size_t *count) { + if (json->stack_top == (size_t) -1) + return JSON_DONE; + + if (count != NULL) + *count = json->stack[json->stack_top].count; + + return json->stack[json->stack_top].type; +} + +int +json_source_get (json_stream *json) { + int c = json->source.get (&json->source); + if (c == '\n') + json->lineno++; + return c; +} + +int +json_source_peek (json_stream *json) { + return json->source.peek (&json->source); +} + +void +json_open_buffer (json_stream *json, const void *buffer, size_t size) { + init (json); + json->source.get = buffer_get; + json->source.peek = buffer_peek; + json->source.source.buffer.buffer = (const char *) buffer; + json->source.source.buffer.length = size; +} + +void +json_open_string (json_stream *json, const char *string) { + json_open_buffer (json, string, strlen (string)); +} + +void +json_open_stream (json_stream *json, FILE *stream) { + init (json); + json->source.get = stream_get; + json->source.peek = stream_peek; + json->source.source.stream.stream = stream; +} + +static int +user_get (struct json_source *json) { + return json->source.user.get (json->source.user.ptr); +} + +static int +user_peek (struct json_source *json) { + return json->source.user.peek (json->source.user.ptr); +} + +void +json_open_user (json_stream *json, json_user_io get, json_user_io peek, void *user) { + init (json); + json->source.get = user_get; + json->source.peek = user_peek; + json->source.source.user.ptr = user; + json->source.source.user.get = get; + json->source.source.user.peek = peek; +} + +void +json_set_allocator (json_stream *json, json_allocator *a) { + json->alloc = *a; +} + +void +json_set_streaming (json_stream *json, bool streaming) { + if (streaming) + json->flags |= JSON_FLAG_STREAMING; + else + json->flags &= ~JSON_FLAG_STREAMING; +} + +void +json_close (json_stream *json) { + json->alloc.free (json->stack); + json->alloc.free (json->data.string); +} diff --git a/src/pdjson.h b/src/pdjson.h new file mode 100644 index 0000000000..b9893ae636 --- /dev/null +++ b/src/pdjson.h @@ -0,0 +1,110 @@ +#ifndef PDJSON_H +#define PDJSON_H + +#ifndef PDJSON_SYMEXPORT +# define PDJSON_SYMEXPORT +#endif + +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +#include +#else +#ifndef bool +#define bool int +#define true 1 +#define false 0 +#endif /* bool */ +#endif /* __STDC_VERSION__ */ + +#include + +enum json_type { + JSON_ERROR = 1, JSON_DONE, + JSON_OBJECT, JSON_OBJECT_END, JSON_ARRAY, JSON_ARRAY_END, + JSON_STRING, JSON_NUMBER, JSON_TRUE, JSON_FALSE, JSON_NULL +}; + +struct json_allocator { + void *(*malloc) (size_t); + void *(*realloc) (void *, size_t); + void (*free) (void *); +}; + +typedef int (*json_user_io) (void *user); + +typedef struct json_stream json_stream; +typedef struct json_allocator json_allocator; + +PDJSON_SYMEXPORT void json_open_buffer (json_stream * json, const void *buffer, size_t size); +PDJSON_SYMEXPORT void json_open_string (json_stream * json, const char *string); +PDJSON_SYMEXPORT void json_open_stream (json_stream * json, FILE * stream); +PDJSON_SYMEXPORT void json_open_user (json_stream * json, json_user_io get, json_user_io peek, + void *user); +PDJSON_SYMEXPORT void json_close (json_stream * json); + +PDJSON_SYMEXPORT void json_set_allocator (json_stream * json, json_allocator * a); +PDJSON_SYMEXPORT void json_set_streaming (json_stream * json, bool mode); + +PDJSON_SYMEXPORT enum json_type json_next (json_stream * json); +PDJSON_SYMEXPORT enum json_type json_peek (json_stream * json); +PDJSON_SYMEXPORT void json_reset (json_stream * json); +PDJSON_SYMEXPORT const char *json_get_string (json_stream * json, size_t *length); +PDJSON_SYMEXPORT double json_get_number (json_stream * json); + +PDJSON_SYMEXPORT enum json_type json_skip (json_stream * json); +PDJSON_SYMEXPORT enum json_type json_skip_until (json_stream * json, enum json_type type); + +PDJSON_SYMEXPORT size_t json_get_lineno (json_stream * json); +PDJSON_SYMEXPORT size_t json_get_position (json_stream * json); +PDJSON_SYMEXPORT size_t json_get_depth (json_stream * json); +PDJSON_SYMEXPORT enum json_type json_get_context (json_stream * json, size_t *count); +PDJSON_SYMEXPORT const char *json_get_error (json_stream * json); + +PDJSON_SYMEXPORT int json_source_get (json_stream * json); +PDJSON_SYMEXPORT int json_source_peek (json_stream * json); +PDJSON_SYMEXPORT bool json_isspace (int c); + +/* internal */ + +struct json_source { + int (*get) (struct json_source *); + int (*peek) (struct json_source *); + size_t position; + union { + struct { + FILE *stream; + } stream; + struct { + const char *buffer; + size_t length; + } buffer; + struct { + void *ptr; + json_user_io get; + json_user_io peek; + } user; + } source; +}; + +struct json_stream { + size_t lineno; + + struct json_stack *stack; + size_t stack_top; + size_t stack_size; + enum json_type next; + unsigned flags; + + struct { + char *string; + size_t string_fill; + size_t string_size; + } data; + + size_t ntokens; + + struct json_source source; + struct json_allocator alloc; + char errmsg[128]; +}; + +#endif diff --git a/src/persistence.c b/src/persistence.c new file mode 100644 index 0000000000..c2c47cfcef --- /dev/null +++ b/src/persistence.c @@ -0,0 +1,1226 @@ +/** + * persistence.c -- on-disk persistence functionality + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include + +#include "persistence.h" + +#include "error.h" +#include "gkhash.h" +#include "sort.h" +#include "tpl.h" +#include "util.h" +#include "xmalloc.h" + +static uint32_t *persisted_dates = NULL; +static uint32_t persisted_dates_len = 0; + +/* Determine the path for the given database file. + * + * On error, a fatal error is thrown. + * On success, the databases path string is returned. */ +static char * +set_db_path (const char *fn) { + struct stat info; + char *rpath = NULL, *path = NULL; + const char *dbpath = NULL; + + if (!conf.db_path) + dbpath = DB_PATH; + else + dbpath = conf.db_path; + + rpath = realpath (dbpath, NULL); + if (rpath == NULL) + FATAL ("Unable to open the specified db path/file '%s'. %s", dbpath, strerror (errno)); + + /* sanity check: Is db_path accessible and a directory? */ + if (stat (rpath, &info) != 0) + FATAL ("Unable to access database path: %s", strerror (errno)); + else if (!(info.st_mode & S_IFDIR)) + FATAL ("Database path is not a directory."); + + path = xmalloc (snprintf (NULL, 0, "%s/%s", rpath, fn) + 1); + sprintf (path, "%s/%s", rpath, fn); + free (rpath); + + return path; +} + +/* Given a database filename, restore a string key, uint32_t value back to the + * storage */ +static void +restore_global_si08 (khash_t (si08) *hash, const char *fn) { + tpl_node *tn; + char *key = NULL; + char fmt[] = "A(sv)"; + uint16_t val; + + tn = tpl_map (fmt, &key, &val); + tpl_load (tn, TPL_FILE, fn); + while (tpl_unpack (tn, 1) > 0) { + ins_si08 (hash, key, val); + free (key); + } + tpl_free (tn); +} + +/* Given a hash and a filename, persist to disk a string key, uint32_t value */ +static void +persist_global_si08 (khash_t (si08) *hash, const char *fn) { + tpl_node *tn; + khint_t k; + const char *key = NULL; + char fmt[] = "A(sv)"; + uint16_t val; + + if (!hash || kh_size (hash) == 0) + return; + + tn = tpl_map (fmt, &key, &val); + for (k = 0; k < kh_end (hash); ++k) { + if (!kh_exist (hash, k) || (!(key = kh_key (hash, k)))) + continue; + val = kh_value (hash, k); + tpl_pack (tn, 1); + } + + tpl_dump (tn, TPL_FILE, fn); + tpl_free (tn); +} + +/* Given a database filename, restore a string key, uint32_t value back to the + * storage */ +static void +restore_global_si32 (khash_t (si32) *hash, const char *fn) { + tpl_node *tn; + char *key = NULL; + char fmt[] = "A(su)"; + uint32_t val; + + tn = tpl_map (fmt, &key, &val); + tpl_load (tn, TPL_FILE, fn); + while (tpl_unpack (tn, 1) > 0) { + ins_si32 (hash, key, val); + free (key); + } + tpl_free (tn); +} + +/* Given a hash and a filename, persist to disk a string key, uint32_t value */ +static void +persist_global_si32 (khash_t (si32) *hash, const char *fn) { + tpl_node *tn; + khint_t k; + const char *key = NULL; + char fmt[] = "A(su)"; + uint32_t val; + + if (!hash || kh_size (hash) == 0) + return; + + tn = tpl_map (fmt, &key, &val); + for (k = 0; k < kh_end (hash); ++k) { + if (!kh_exist (hash, k) || (!(key = kh_key (hash, k)))) + continue; + val = kh_value (hash, k); + tpl_pack (tn, 1); + } + + tpl_dump (tn, TPL_FILE, fn); + tpl_free (tn); +} + +/* Given a database filename, restore a uint64_t key, GLastParse value back to + * the storage */ +static void +restore_global_iglp (khash_t (iglp) *hash, const char *fn) { + tpl_node *tn; + uint64_t key; + GLastParse val = { 0 }; + char fmt[] = "A(US(uIUvc#))"; + + tn = tpl_map (fmt, &key, &val, READ_BYTES); + tpl_load (tn, TPL_FILE, fn); + while (tpl_unpack (tn, 1) > 0) { + ins_iglp (hash, key, &val); + } + tpl_free (tn); +} + +/* Given a hash and a filename, persist to disk a uint64_t key, uint32_t value */ +static void +persist_global_iglp (khash_t (iglp) *hash, const char *fn) { + tpl_node *tn; + khint_t k; + uint64_t key; + GLastParse val = { 0 }; + char fmt[] = "A(US(uIUvc#))"; + + if (!hash || kh_size (hash) == 0) + return; + + tn = tpl_map (fmt, &key, &val, READ_BYTES); + for (k = 0; k < kh_end (hash); ++k) { + if (!kh_exist (hash, k)) + continue; + key = kh_key (hash, k); + val = kh_value (hash, k); + tpl_pack (tn, 1); + } + + tpl_dump (tn, TPL_FILE, fn); + tpl_free (tn); +} + +/* Given a filename, ensure we have a valid return path + * + * On error, NULL is returned. + * On success, the valid path is returned */ +static char * +check_restore_path (const char *fn) { + char *path = set_db_path (fn); + if (access (path, F_OK) != -1) + return path; + + LOG_DEBUG (("DB file %s doesn't exist. %s\n", path, strerror (errno))); + free (path); + return NULL; +} + +static char * +build_filename (const char *type, const char *modstr, const char *mtrstr) { + char *fn = xmalloc (snprintf (NULL, 0, "%s_%s_%s.db", type, modstr, mtrstr) + 1); + sprintf (fn, "%s_%s_%s.db", type, modstr, mtrstr); + return fn; +} + +/* Get the database filename given a module and a metric. + * + * On error, a fatal error is triggered. + * On success, the filename is returned */ +static char * +get_filename (GModule module, GKHashMetric mtrc) { + const char *mtrstr, *modstr, *type; + char *fn = NULL; + + if (!(mtrstr = get_mtr_str (mtrc.metric.storem))) + FATAL ("Unable to allocate metric name."); + if (!(modstr = get_module_str (module))) + FATAL ("Unable to allocate module name."); + if (!(type = get_mtr_type_str (mtrc.type))) + FATAL ("Unable to allocate module name."); + + fn = build_filename (type, modstr, mtrstr); + + return fn; +} + +/* Dump to disk the database file and frees its memory */ +static void +close_tpl (tpl_node *tn, const char *fn) { + tpl_dump (tn, TPL_FILE, fn); + tpl_free (tn); +} + +/* Check if the given date can be inserted based on how many dates we need to + * keep conf.keep_last. + * + * Returns -1 if it fails to insert the date. + * Returns 1 if the date exists. + * Returns 2 if the date shouldn't be inserted. + * On success or if the date is inserted 0 is returned */ +static int +insert_restored_date (uint32_t date) { + uint32_t i, len = 0; + + /* no keep last, simply insert the restored date to our storage */ + if (!conf.keep_last || persisted_dates_len < conf.keep_last) + return ht_insert_date (date); + + len = MIN (persisted_dates_len, conf.keep_last); + for (i = 0; i < len; ++i) + if (persisted_dates[i] == date) + return ht_insert_date (date); + return 2; +} + +/* Given a database filename, restore a string key, uint32_t value back to + * the storage */ +static int +restore_si32 (GSMetric metric, const char *path, int module) { + khash_t (si32) * hash = NULL; + tpl_node *tn; + char fmt[] = "A(iA(su))"; + int date = 0, ret = 0; + char *key = NULL; + uint32_t val = 0; + + if (!(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + tpl_load (tn, TPL_FILE, path); + while (tpl_unpack (tn, 1) > 0) { + if ((ret = insert_restored_date (date)) == 2) + continue; + if (ret == -1 || !(hash = get_hash (module, date, metric))) + break; + + while (tpl_unpack (tn, 2) > 0) { + ins_si32 (hash, key, val); + free (key); + } + } + tpl_free (tn); + + return 0; +} + +/* Given a database filename, restore a string key, uint32_t value back to + * the storage */ +static int +migrate_si32_to_ii32 (GSMetric metric, const char *path, int module) { + khash_t (ii32) * hash = NULL; + tpl_node *tn; + char fmt[] = "A(iA(su))"; + int date = 0, ret = 0; + char *key = NULL; + uint32_t val = 0; + + if (!(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + tpl_load (tn, TPL_FILE, path); + while (tpl_unpack (tn, 1) > 0) { + if ((ret = insert_restored_date (date)) == 2) + continue; + if (ret == -1 || !(hash = get_hash (module, date, metric))) + break; + + while (tpl_unpack (tn, 2) > 0) { + ins_ii32 (hash, djb2 ((const unsigned char *) key), val); + free (key); + } + } + tpl_free (tn); + + return 0; +} + +static char * +migrate_unique_key (const char *key) { + char *nkey = NULL, *token = NULL, *ptr = NULL; + char agent_hex[64] = { 0 }; + uint32_t delims = 0; + + if (!key || count_matches (key, '|') < 2) + return NULL; + + nkey = xstrdup (""); + while ((ptr = strchr (key, '|'))) { + if (!(token = extract_by_delim (&key, "|"))) { + free (nkey); + return NULL; + } + + append_str (&nkey, token); + append_str (&nkey, "|"); + free (token); + key++; + delims++; + } + if (delims == 2) { + sprintf (agent_hex, "%" PRIx32, djb2 ((const unsigned char *) key)); + append_str (&nkey, agent_hex); + } + + return nkey; +} + + +/* Given a database filename, restore a string key, uint32_t value back to + * the storage */ +static int +migrate_si32_to_ii32_unique_keys (GSMetric metric, const char *path, int module) { + khash_t (si32) * hash = NULL; + tpl_node *tn; + char fmt[] = "A(iA(su))"; + int date = 0, ret = 0; + char *key = NULL, *nkey = NULL; + uint32_t val = 0; + + if (!(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + tpl_load (tn, TPL_FILE, path); + while (tpl_unpack (tn, 1) > 0) { + if ((ret = insert_restored_date (date)) == 2) + continue; + if (ret == -1 || !(hash = get_hash (module, date, metric))) + break; + + while (tpl_unpack (tn, 2) > 0) { + if ((nkey = migrate_unique_key (key))) + ins_si32 (hash, nkey, val); + free (key); + free (nkey); + } + } + tpl_free (tn); + + return 0; +} + +/* Given a hash and a filename, persist to disk a string key, uint32_t value */ +static int +persist_si32 (GSMetric metric, const char *path, int module) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * dates = get_hdb (db, MTRC_DATES); + + khash_t (si32) * hash = NULL; + tpl_node *tn = NULL; + int date = 0; + char fmt[] = "A(iA(su))"; + uint32_t val = 0; + const char *key = NULL; + + if (!dates || !(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + /* *INDENT-OFF* */ + HT_FOREACH_KEY (dates, date, { + if (!(hash = get_hash (module, date, metric))) + return -1; + kh_foreach (hash, key, val, { tpl_pack (tn, 2); }); + tpl_pack (tn, 1); + }); + /* *INDENT-ON* */ + close_tpl (tn, path); + + return 0; +} + +/* Given a database filename, restore a uint32_t key, string value back to + * the storage */ +static int +migrate_is32_to_ii08 (GSMetric metric, const char *path, int module) { + khash_t (ii08) * hash = NULL; + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (si08) * mtpr = get_hdb (db, MTRC_METH_PROTO); + tpl_node *tn; + char fmt[] = "A(iA(us))"; + int date = 0, ret = 0; + uint32_t key = 0; + char *val = NULL; + khint_t k; + + if (!(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + tpl_load (tn, TPL_FILE, path); + while (tpl_unpack (tn, 1) > 0) { + if ((ret = insert_restored_date (date)) == 2) + continue; + if (ret == -1 || !(hash = get_hash (module, date, metric))) + break; + + while (tpl_unpack (tn, 2) > 0) { + k = kh_get (si08, mtpr, val); + /* key found, return current value */ + if (k == kh_end (mtpr)) { + free (val); + continue; + } + ins_ii08 (hash, key, kh_val (mtpr, k)); + free (val); + } + } + tpl_free (tn); + + return 0; +} + +/* Given a database filename, restore a uint32_t key, string value back to + * the storage */ +static int +restore_is32 (GSMetric metric, const char *path, int module) { + khash_t (is32) * hash = NULL; + tpl_node *tn; + char fmt[] = "A(iA(us))"; + int date = 0, ret = 0; + uint32_t key = 0; + char *val = NULL, *dupval = NULL; + + if (!(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + tpl_load (tn, TPL_FILE, path); + while (tpl_unpack (tn, 1) > 0) { + if ((ret = insert_restored_date (date)) == 2) + continue; + if (ret == -1 || !(hash = get_hash (module, date, metric))) + break; + + while (tpl_unpack (tn, 2) > 0) { + dupval = xstrdup (val); + if (ins_is32 (hash, key, dupval) != 0) + free (dupval); + free (val); + } + } + tpl_free (tn); + + return 0; +} + +/* Given a hash and a filename, persist to disk a uint32_t key, string value */ +static int +persist_is32 (GSMetric metric, const char *path, int module) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * dates = get_hdb (db, MTRC_DATES); + khash_t (is32) * hash = NULL; + tpl_node *tn = NULL; + int date = 0; + char fmt[] = "A(iA(us))"; + char *val = NULL; + uint32_t key = 0; + + if (!dates || !(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + /* *INDENT-OFF* */ + HT_FOREACH_KEY (dates, date, { + if (!(hash = get_hash (module, date, metric))) + return -1; + kh_foreach (hash, key, val, { tpl_pack (tn, 2); }); + tpl_pack (tn, 1); + }); + /* *INDENT-ON* */ + close_tpl (tn, path); + + return 0; +} + + +/* Given a database filename, restore a uint32_t key, uint32_t value back to + * the storage */ +static int +restore_ii08 (GSMetric metric, const char *path, int module) { + khash_t (ii08) * hash = NULL; + tpl_node *tn; + char fmt[] = "A(iA(uv))"; + int date = 0, ret = 0; + uint32_t key = 0; + uint16_t val = 0; + + if (!(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + tpl_load (tn, TPL_FILE, path); + while (tpl_unpack (tn, 1) > 0) { + if ((ret = insert_restored_date (date)) == 2) + continue; + if (ret == -1 || !(hash = get_hash (module, date, metric))) + break; + + while (tpl_unpack (tn, 2) > 0) { + ins_ii08 (hash, key, val); + } + } + tpl_free (tn); + + return 0; +} + +/* Given a database filename, restore a uint32_t key, uint32_t value back to + * the storage */ +static int +restore_ii32 (GSMetric metric, const char *path, int module) { + khash_t (ii32) * hash = NULL; + tpl_node *tn; + char fmt[] = "A(iA(uu))"; + int date = 0, ret = 0; + uint32_t key = 0, val = 0; + + if (!(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + tpl_load (tn, TPL_FILE, path); + while (tpl_unpack (tn, 1) > 0) { + if ((ret = insert_restored_date (date)) == 2) + continue; + if (ret == -1 || !(hash = get_hash (module, date, metric))) + break; + + while (tpl_unpack (tn, 2) > 0) { + ins_ii32 (hash, key, val); + } + } + tpl_free (tn); + + return 0; +} + +/* Given a hash and a filename, persist to disk a uint32_t key, uint32_t value */ +static int +persist_ii32 (GSMetric metric, const char *path, int module) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * dates = get_hdb (db, MTRC_DATES); + khash_t (ii32) * hash = NULL; + tpl_node *tn = NULL; + int date = 0; + char fmt[] = "A(iA(uu))"; + uint32_t key = 0, val = 0; + + if (!dates || !(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + /* *INDENT-OFF* */ + HT_FOREACH_KEY (dates, date, { + if (!(hash = get_hash (module, date, metric))) + return -1; + kh_foreach (hash, key, val, { tpl_pack (tn, 2); }); + tpl_pack (tn, 1); + }); + /* *INDENT-ON* */ + close_tpl (tn, path); + + return 0; +} + +/* Given a hash and a filename, persist to disk a uint32_t key, uint32_t value */ +static int +persist_ii08 (GSMetric metric, const char *path, int module) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * dates = get_hdb (db, MTRC_DATES); + khash_t (ii08) * hash = NULL; + tpl_node *tn = NULL; + int date = 0; + char fmt[] = "A(iA(uv))"; + uint32_t key = 0; + uint16_t val = 0; + + if (!dates || !(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + /* *INDENT-OFF* */ + HT_FOREACH_KEY (dates, date, { + if (!(hash = get_hash (module, date, metric))) + return -1; + kh_foreach (hash, key, val, { tpl_pack (tn, 2); }); + tpl_pack (tn, 1); + }); + /* *INDENT-ON* */ + close_tpl (tn, path); + + return 0; +} + +/* Given a database filename, restore a uint64_t key, uint8_t value back to + * the storage */ +static int +restore_u648 (GSMetric metric, const char *path, int module) { + khash_t (u648) * hash = NULL; + tpl_node *tn; + char fmt[] = "A(iA(Uv))"; + int date = 0, ret = 0; + uint64_t key; + uint16_t val = 0; + + if (!(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + tpl_load (tn, TPL_FILE, path); + while (tpl_unpack (tn, 1) > 0) { + if ((ret = insert_restored_date (date)) == 2) + continue; + if (ret == -1 || !(hash = get_hash (module, date, metric))) + break; + + while (tpl_unpack (tn, 2) > 0) { + ins_u648 (hash, key, val); + } + } + tpl_free (tn); + + return 0; +} + +/* Given a hash and a filename, persist to disk a uint64_t key, uint8_t value */ +static int +persist_u648 (GSMetric metric, const char *path, int module) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * dates = get_hdb (db, MTRC_DATES); + khash_t (u648) * hash = NULL; + tpl_node *tn = NULL; + int date = 0; + char fmt[] = "A(iA(Uv))"; + uint64_t key; + uint16_t val = 0; + + if (!dates || !(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + /* *INDENT-OFF* */ + HT_FOREACH_KEY (dates, date, { + if (!(hash = get_hash (module, date, metric))) + return -1; + kh_foreach (hash, key, val, { tpl_pack (tn, 2); }); + tpl_pack (tn, 1); + }); + /* *INDENT-ON* */ + close_tpl (tn, path); + + return 0; +} + +/* Given a database filename, restore a uint32_t key, uint64_t value back to + * the storage */ +static int +restore_iu64 (GSMetric metric, const char *path, int module) { + khash_t (iu64) * hash = NULL; + tpl_node *tn; + char fmt[] = "A(iA(uU))"; + int date = 0, ret = 0; + uint32_t key; + uint64_t val; + + if (!(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + tpl_load (tn, TPL_FILE, path); + while (tpl_unpack (tn, 1) > 0) { + if ((ret = insert_restored_date (date)) == 2) + continue; + if (ret == -1 || !(hash = get_hash (module, date, metric))) + break; + + while (tpl_unpack (tn, 2) > 0) { + ins_iu64 (hash, key, val); + } + } + tpl_free (tn); + + return 0; +} + +/* Given a hash and a filename, persist to disk a uint32_t key, uint64_t value */ +static int +persist_iu64 (GSMetric metric, const char *path, int module) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * dates = get_hdb (db, MTRC_DATES); + khash_t (iu64) * hash = NULL; + tpl_node *tn = NULL; + int date = 0; + char fmt[] = "A(iA(uU))"; + uint32_t key; + uint64_t val; + + if (!dates || !(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + /* *INDENT-OFF* */ + HT_FOREACH_KEY (dates, date, { + if (!(hash = get_hash (module, date, metric))) + return -1; + kh_foreach (hash, key, val, { tpl_pack (tn, 2); }); + tpl_pack (tn, 1); + }); + /* *INDENT-ON* */ + close_tpl (tn, path); + + return 0; +} + +/* Given a database filename, restore a string key, uint64_t value back to + * the storage */ +static int +restore_su64 (GSMetric metric, const char *path, int module) { + khash_t (su64) * hash = NULL; + tpl_node *tn; + char fmt[] = "A(iA(sU))"; + int date = 0, ret = 0; + char *key = NULL; + uint64_t val; + + if (!(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + tpl_load (tn, TPL_FILE, path); + while (tpl_unpack (tn, 1) > 0) { + if ((ret = insert_restored_date (date)) == 2) + continue; + if (ret == -1 || !(hash = get_hash (module, date, metric))) + break; + + while (tpl_unpack (tn, 2) > 0) { + ins_su64 (hash, key, val); + free (key); + } + } + tpl_free (tn); + + return 0; +} + +/* Given a hash and a filename, persist to disk a string key, uint64_t value */ +static int +persist_su64 (GSMetric metric, const char *path, int module) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * dates = get_hdb (db, MTRC_DATES); + khash_t (su64) * hash = NULL; + tpl_node *tn = NULL; + int date = 0; + char fmt[] = "A(iA(sU))"; + const char *key = NULL; + uint64_t val; + + if (!dates || !(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + /* *INDENT-OFF* */ + HT_FOREACH_KEY (dates, date, { + if (!(hash = get_hash (module, date, metric))) + return -1; + kh_foreach (hash, key, val, { tpl_pack (tn, 2); }); + tpl_pack (tn, 1); + }); + /* *INDENT-ON* */ + close_tpl (tn, path); + + return 0; +} + +/* Given a database filename, restore a uint32_t key, GSLList value back to the + * storage */ +static int +restore_igsl (GSMetric metric, const char *path, int module) { + khash_t (igsl) * hash = NULL; + tpl_node *tn; + char fmt[] = "A(iA(uu))"; + int date = 0, ret = 0; + uint32_t key, val; + + if (!(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + tpl_load (tn, TPL_FILE, path); + while (tpl_unpack (tn, 1) > 0) { + if ((ret = insert_restored_date (date)) == 2) + continue; + if (ret == -1 || !(hash = get_hash (module, date, metric))) + break; + + while (tpl_unpack (tn, 2) > 0) { + ins_igsl (hash, key, val); + } + } + tpl_free (tn); + + return 0; +} + +/* Given a hash and a filename, persist to disk a uint32_t key, GSLList value */ +static int +persist_igsl (GSMetric metric, const char *path, int module) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (igkh) * dates = get_hdb (db, MTRC_DATES); + khash_t (igsl) * hash = NULL; + GSLList *node; + tpl_node *tn = NULL; + int date = 0; + char fmt[] = "A(iA(uu))"; + uint32_t key, val; + + if (!dates || !(tn = tpl_map (fmt, &date, &key, &val))) + return 1; + + /* *INDENT-OFF* */ + HT_FOREACH_KEY (dates, date, { + if (!(hash = get_hash (module, date, metric))) + return -1; + kh_foreach (hash, key, node, { + while (node) { + val = (*(uint32_t *) node->data); + node = node->next; + } + tpl_pack (tn, 2); + }); + tpl_pack (tn, 1); + }); + /* *INDENT-ON* */ + close_tpl (tn, path); + + return 0; +} + +/* Entry function to restore hash data by type */ +static void +restore_by_type (GKHashMetric mtrc, const char *fn, int module) { + char *path = NULL; + + if (!(path = check_restore_path (fn))) + goto clean; + + switch (mtrc.type) { + case MTRC_TYPE_SI32: + restore_si32 (mtrc.metric.storem, path, module); + break; + case MTRC_TYPE_IS32: + restore_is32 (mtrc.metric.storem, path, module); + break; + case MTRC_TYPE_II08: + restore_ii08 (mtrc.metric.storem, path, module); + break; + case MTRC_TYPE_II32: + restore_ii32 (mtrc.metric.storem, path, module); + break; + case MTRC_TYPE_U648: + restore_u648 (mtrc.metric.storem, path, module); + break; + case MTRC_TYPE_IU64: + restore_iu64 (mtrc.metric.storem, path, module); + break; + case MTRC_TYPE_SU64: + restore_su64 (mtrc.metric.storem, path, module); + break; + case MTRC_TYPE_IGSL: + restore_igsl (mtrc.metric.storem, path, module); + break; + default: + break; + } +clean: + free (path); +} + +/* Entry function to restore hash data by metric type */ +static void +restore_metric_type (GModule module, GKHashMetric mtrc) { + char *fn = NULL; + + fn = get_filename (module, mtrc); + restore_by_type (mtrc, fn, module); + free (fn); +} + +static int +migrate_metric (GModule module, GKHashMetric mtrc) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (si32) * db_props = get_hdb (db, MTRC_DB_PROPS); + + int ret = 0; + char *fn = NULL, *path = NULL; + const char *modstr, *mtrstr; + khint_t k; + + k = kh_get (si32, db_props, "version"); + /* db is up-to-date, thus no need to migrate anything */ + if (k != kh_end (db_props) && kh_val (db_props, k) == DB_VERSION) + return 0; + + switch (mtrc.metric.storem) { + case MTRC_UNIQUE_KEYS: + if (!(path = check_restore_path ("SI32_UNIQUE_KEYS.db"))) + break; + if (migrate_si32_to_ii32_unique_keys (mtrc.metric.storem, path, -1) != 0) + break; + unlink (path); + ret++; + break; + case MTRC_KEYMAP: + if (!(modstr = get_module_str (module))) + FATAL ("Unable to allocate module name."); + fn = build_filename ("SI32", modstr, "MTRC_KEYMAP"); + if (!(path = check_restore_path (fn))) + break; + if (migrate_si32_to_ii32 (mtrc.metric.storem, path, module) != 0) + break; + unlink (path); + ret++; + break; + case MTRC_METHODS: + case MTRC_PROTOCOLS: + if (!(mtrstr = get_mtr_str (mtrc.metric.storem))) + FATAL ("Unable to allocate metric name."); + if (!(modstr = get_module_str (module))) + FATAL ("Unable to allocate module name."); + + fn = build_filename ("IS32", modstr, mtrstr); + if (!(path = check_restore_path (fn))) + break; + if (migrate_is32_to_ii08 (mtrc.metric.storem, path, module) != 0) + break; + unlink (path); + ret++; + break; + case MTRC_AGENT_KEYS: + if (!(path = check_restore_path ("SI32_AGENT_KEYS.db"))) + break; + if (migrate_si32_to_ii32 (mtrc.metric.storem, path, -1) != 0) + break; + unlink (path); + ret++; + break; + default: + break; + } + + free (fn); + free (path); + + return ret; +} + +static void +persist_by_type (GKHashMetric mtrc, const char *fn, int module) { + char *path = NULL; + path = set_db_path (fn); + + switch (mtrc.type) { + case MTRC_TYPE_SI32: + persist_si32 (mtrc.metric.storem, path, module); + break; + case MTRC_TYPE_IS32: + persist_is32 (mtrc.metric.storem, path, module); + break; + case MTRC_TYPE_II32: + persist_ii32 (mtrc.metric.storem, path, module); + break; + case MTRC_TYPE_II08: + persist_ii08 (mtrc.metric.storem, path, module); + break; + case MTRC_TYPE_U648: + persist_u648 (mtrc.metric.storem, path, module); + break; + case MTRC_TYPE_IU64: + persist_iu64 (mtrc.metric.storem, path, module); + break; + case MTRC_TYPE_SU64: + persist_su64 (mtrc.metric.storem, path, module); + break; + case MTRC_TYPE_IGSL: + persist_igsl (mtrc.metric.storem, path, module); + break; + default: + break; + } + free (path); +} + +static void +persist_metric_type (GModule module, GKHashMetric mtrc) { + char *fn = NULL; + fn = get_filename (module, mtrc); + persist_by_type (mtrc, fn, module); + free (fn); +} + +/* Given all the dates that we have processed, persist to disk a copy of them. */ +static void +persist_dates (void) { + tpl_node *tn; + char *path = NULL; + uint32_t *dates = NULL, len = 0, i, date = 0; + char fmt[] = "A(u)"; + + if (!(path = set_db_path ("I32_DATES.db"))) + return; + + dates = get_sorted_dates (&len); + + tn = tpl_map (fmt, &date); + for (i = 0; i < len; ++i) { + date = dates[i]; + tpl_pack (tn, 1); + } + tpl_dump (tn, TPL_FILE, path); + + tpl_free (tn); + free (path); + free (dates); +} + +/* Restore all the processed dates from our last dataset */ +static void +restore_dates (void) { + tpl_node *tn; + char *path = NULL; + uint32_t date, idx = 0; + char fmt[] = "A(u)"; + int len; + + if (!(path = check_restore_path ("I32_DATES.db"))) + return; + + tn = tpl_map (fmt, &date); + tpl_load (tn, TPL_FILE, path); + + len = tpl_Alen (tn, 1); + if (len < 0) + return; + persisted_dates_len = len; + persisted_dates = xcalloc (persisted_dates_len, sizeof (uint32_t)); + while (tpl_unpack (tn, 1) > 0) + persisted_dates[idx++] = date; + + qsort (persisted_dates, idx, sizeof (uint32_t), cmp_ui32_desc); + tpl_free (tn); + free (path); +} + +/* Entry function to restore a global hashes */ +static void +restore_global (void) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (si32) * overall = get_hdb (db, MTRC_CNT_OVERALL); + khash_t (si32) * seqs = get_hdb (db, MTRC_SEQS); + khash_t (iglp) * last_parse = get_hdb (db, MTRC_LAST_PARSE); + khash_t (si32) * db_props = get_hdb (db, MTRC_DB_PROPS); + khash_t (si08) * meth_proto = get_hdb (db, MTRC_METH_PROTO); + + char *path = NULL; + + if ((path = check_restore_path ("SI32_DB_PROPS.db"))) { + restore_global_si32 (db_props, path); + free (path); + } + + restore_dates (); + if ((path = check_restore_path ("SI32_CNT_OVERALL.db"))) { + restore_global_si32 (overall, path); + free (path); + } + if ((path = check_restore_path ("SI32_SEQS.db"))) { + restore_global_si32 (seqs, path); + free (path); + } + if ((path = check_restore_path ("SI08_METH_PROTO.db"))) { + restore_global_si08 (meth_proto, path); + free (path); + } + if ((path = check_restore_path ("IGLP_LAST_PARSE.db"))) { + restore_global_iglp (last_parse, path); + free (path); + } +} + +static void +persist_global (void) { + GKDB *db = get_db_instance (DB_INSTANCE); + khash_t (si32) * overall = get_hdb (db, MTRC_CNT_OVERALL); + khash_t (si32) * seqs = get_hdb (db, MTRC_SEQS); + khash_t (iglp) * last_parse = get_hdb (db, MTRC_LAST_PARSE); + khash_t (si32) * db_props = get_hdb (db, MTRC_DB_PROPS); + khash_t (si08) * meth_proto = get_hdb (db, MTRC_METH_PROTO); + char *path = NULL; + + ins_si32 (db_props, "version", DB_VERSION); + + persist_dates (); + if ((path = set_db_path ("SI32_CNT_OVERALL.db"))) { + persist_global_si32 (overall, path); + free (path); + } + if ((path = set_db_path ("SI32_SEQS.db"))) { + persist_global_si32 (seqs, path); + free (path); + } + if ((path = set_db_path ("IGLP_LAST_PARSE.db"))) { + persist_global_iglp (last_parse, path); + free (path); + } + if ((path = set_db_path ("SI08_METH_PROTO.db"))) { + persist_global_si08 (meth_proto, path); + free (path); + } + if ((path = set_db_path ("SI32_DB_PROPS.db"))) { + persist_global_si32 (db_props, path); + free (path); + } +} + +void +persist_data (void) { + GModule module; + int i, n = 0; + size_t idx = 0; + persist_global (); + + n = global_metrics_len; + for (i = 0; i < n; ++i) + persist_by_type (global_metrics[i], global_metrics[i].filename, -1); + + n = module_metrics_len; + FOREACH_MODULE (idx, module_list) { + module = module_list[idx]; + for (i = 0; i < n; ++i) { + persist_metric_type (module, module_metrics[i]); + } + } +} + +/* Entry function to restore hashes */ +void +restore_data (void) { + int migrated = 0; + GModule module; + int i, n = 0; + size_t idx = 0; + + restore_global (); + + n = global_metrics_len; + for (i = 0; i < n; ++i) { + migrated += migrate_metric (-1, global_metrics[i]); + restore_by_type (global_metrics[i], global_metrics[i].filename, -1); + } + + n = module_metrics_len; + FOREACH_MODULE (idx, module_list) { + module = module_list[idx]; + for (i = 0; i < n; ++i) { + migrated += migrate_metric (module, module_metrics[i]); + restore_metric_type (module, module_metrics[i]); + } + } + + if (migrated && !conf.persist) + conf.persist = 1; +} + +void +free_persisted_data (void) { + free (persisted_dates); +} diff --git a/src/persistence.h b/src/persistence.h new file mode 100644 index 0000000000..e55b534a34 --- /dev/null +++ b/src/persistence.h @@ -0,0 +1,37 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef PERSISTENCE_H_INCLUDED +#define PERSISTENCE_H_INCLUDED + +void restore_data (void); +void persist_data (void); +void free_persisted_data (void); + +#endif // for #ifndef PERSISTENCE_H diff --git a/src/settings.c b/src/settings.c new file mode 100644 index 0000000000..e653a634eb --- /dev/null +++ b/src/settings.c @@ -0,0 +1,1009 @@ +/** + * settings.c -- goaccess configuration + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) + +#include +#include +#include +#include +#include +#include + +#include "settings.h" + +#include "error.h" +#include "gkhash.h" +#include "labels.h" +#include "pdjson.h" +#include "util.h" +#include "xmalloc.h" + +static char **nargv; +static int nargc = 0; + +/* *INDENT-OFF* */ +static const GEnum LOGTYPE[] = { + {"COMBINED" , COMBINED} , + {"VCOMBINED" , VCOMBINED} , + {"COMMON" , COMMON} , + {"VCOMMON" , VCOMMON} , + {"W3C" , W3C} , + {"CLOUDFRONT" , CLOUDFRONT} , + {"CLOUDSTORAGE" , CLOUDSTORAGE} , + {"AWSELB" , AWSELB} , + {"SQUID" , SQUID} , + {"AWSS3" , AWSS3} , + {"CADDY" , CADDY} , + {"AWSALB" , AWSALB} , + {"TRAEFIKCLF" , TRAEFIKCLF} , +}; + +static const GPreConfLog logs = { + "%h %^[%d:%t %^] \"%r\" %s %b \"%R\" \"%u\"", /* NCSA */ + "%v:%^ %h %^[%d:%t %^] \"%r\" %s %b \"%R\" \"%u\"", /* NCSA + VHost */ + "%h %^[%d:%t %^] \"%r\" %s %b", /* CLF */ + "%v:%^ %h %^[%d:%t %^] \"%r\" %s %b", /* CLF+VHost */ + "%d %t %^ %m %U %q %^ %^ %h %u %R %s %^ %^ %L", /* W3C */ + "%d\\t%t\\t%^\\t%b\\t%h\\t%m\\t%v\\t%U\\t%s\\t%R\\t%u\\t%q\\t%^\\t%C\\t%^\\t%^\\t%^\\t%^\\t%T\\t%^\\t%K\\t%k\\t%^\\t%H\\t%^", /* CloudFront */ + "\"%x\",\"%h\",%^,%^,\"%m\",\"%U\",\"%s\",%^,\"%b\",\"%D\",%^,\"%R\",\"%u\"", /* Cloud Storage */ + "%^ %dT%t.%^ %^ %h:%^ %^ %^ %T %^ %s %^ %^ %b \"%r\" \"%u\" %k %K %^ \"%^\" \"%v\"", /* AWS Elastic Load Balancing */ + "%^ %^ %^ %v %^: %x.%^ %~%L %h %^/%s %b %m %U", /* Squid Native */ + "%^ %v [%d:%t %^] %h %^\"%r\" %s %^ %b %^ %L %^ \"%R\" \"%u\"", /* Amazon S3 */ + + /* Caddy JSON */ + "{ \"ts\": \"%x.%^\", \"request\": { \"client_ip\": \"%h\", \"proto\":" + "\"%H\", \"method\": \"%m\", \"host\": \"%v\", \"uri\": \"%U\", \"headers\": {" + "\"User-Agent\": [\"%u\"], \"Referer\": [\"%R\"] }, \"tls\": { \"cipher_suite\":" + "\"%k\", \"proto\": \"%K\" } }, \"duration\": \"%T\", \"size\": \"%b\"," + "\"status\": \"%s\", \"resp_headers\": { \"Content-Type\": [\"%M\"] } }", + + "%^ %dT%t.%^ %v %h:%^ %^ %^ %T %^ %s %^ %^ %b \"%r\" \"%u\" %k %K %^", /* Amazon ALB */ + + "%h - %e [%d:%t %^] \"%r\" %s %b \"%R\" \"%u\" %^ \"%v\" \"%U\" %Lms" /* Traefik's CLF flavor with header */ +}; + +static const GPreConfTime times = { + "%H:%M:%S", + "%f", /* Cloud Storage (usec) */ + "%s", /* Squid (sec) */ +}; + +static const GPreConfDate dates = { + "%d/%b/%Y", /* Apache */ + "%Y-%m-%d", /* W3C */ + "%f", /* Cloud Storage (usec) */ + "%s", /* Squid (sec) */ +}; +/* *INDENT-ON* */ + +/* Ignore the following options */ +static const char *const ignore_cmd_opts[] = { + "help", + "storage", + "version", +}; + +/* Determine if the given command line option needs to be ignored. + * + * If needs to be ignored, 1 is returned. + * If not within the list of ignored command line options, 0 is returned. */ +static int +in_ignore_cmd_opts (const char *val) { + size_t i; + for (i = 0; i < ARRAY_SIZE (ignore_cmd_opts); i++) { + if (strstr (val, ignore_cmd_opts[i]) != NULL) + return 1; + } + return 0; +} + +/* Get the location of the configuration file. + * + * By default, it attempts to read it from the user supplied path, else it will + * try to open the global config file path (sysconfdir) or from the HOME + * environment variable (~/.goaccessrc). + * + * On success, the path to the configuration file is returned. */ +char * +get_config_file_path (void) { + char *upath = NULL, *gpath = NULL, *rpath = NULL; + + /* determine which config file to open, default or custom */ + if (conf.iconfigfile != NULL) { + rpath = realpath (conf.iconfigfile, NULL); + if (rpath == NULL) + FATAL ("Unable to open the specified config file. %s", strerror (errno)); + return rpath; + } + + /* first attempt to use the user's config file, e.g., ~/.goaccessrc */ + upath = get_user_config (); + /* failure, e.g. if the file does not exist */ + if ((rpath = realpath (upath, NULL)) != NULL) { + free (upath); + return rpath; + } + LOG_DEBUG (("Unable to find user's config file %s %s", upath, strerror (errno))); + free (upath); + + /* otherwise, fallback to global config file, e.g.,%sysconfdir%/goaccess.conf */ + gpath = get_global_config (); + if ((rpath = realpath (gpath, NULL)) != NULL && conf.load_global_config) { + free (gpath); + return rpath; + } + LOG_DEBUG (("Unable to find global config file %s %s", gpath, strerror (errno))); + free (gpath); + + return NULL; +} + +/* Use predefined static files when no config file is used. Note that + * the order in which are listed is from the most to the least common + * (most cases). */ +void +set_default_static_files (void) { + size_t i; + const char *const exts[] = { + ".css", + ".js ", + ".jpg", + ".png", + ".gif", + ".ico", + ".jpeg", + ".pdf", + ".txt", + ".csv", + ".mpeg", + ".mpg", + ".swf", + ".woff", + ".woff2", + ".xls", + ".xlsx", + ".doc ", + ".docx", + ".ppt ", + ".pptx", + ".zip", + ".mp3", + ".mp4", + ".exe", + ".iso ", + ".gz ", + ".rar ", + ".svg ", + ".bmp ", + ".tar ", + ".tgz ", + ".tiff", + ".tif ", + ".ttf ", + ".flv ", + ".avi", + }; + + if (conf.static_file_idx > 0) + return; + + /* If a configuration file is used and, if no static-file extensions are provided, do not set the default static-file extensions. */ + if (conf.iconfigfile != NULL && conf.static_file_idx == 0) { + return; + } + + for (i = 0; i < ARRAY_SIZE (exts); i++) { + if (conf.static_file_max_len < strlen (exts[i])) + conf.static_file_max_len = strlen (exts[i]); + conf.static_files[conf.static_file_idx++] = exts[i]; + } +} + +/* Clean malloc'd log/date/time escaped formats. */ +void +free_formats (void) { + free (conf.log_format); + free (conf.date_format); + free (conf.date_num_format); + free (conf.spec_date_time_format); + free (conf.spec_date_time_num_format); + free (conf.time_format); + free (conf.date_time_format); +} + +/* Clean malloc'd command line arguments. */ +void +free_cmd_args (void) { + int i; + if (nargc == 0) + return; + for (i = 0; i < nargc; i++) + free (nargv[i]); + free (nargv); + free (conf.iconfigfile); +} + +/* Append extra value to argv */ +static void +append_to_argv (int *argc, char ***argv, char *val) { + char **_argv = xrealloc (*argv, (*argc + 2) * sizeof (*_argv)); + _argv[*argc] = val; + _argv[*argc + 1] = (char *) '\0'; + (*argc)++; + *argv = _argv; +} + +/* Parses the configuration file to feed getopt_long. + * + * On error, ENOENT error code is returned. + * On success, 0 is returned and config file enabled options are appended to + * argv. */ +int +parse_conf_file (int *argc, char ***argv) { + char line[MAX_LINE_CONF + 1]; + char *path = NULL, *val, *opt, *p; + FILE *file; + int i, n = 0; + size_t idx; + + /* assumes program name is on argv[0], though, it is not guaranteed */ + append_to_argv (&nargc, &nargv, xstrdup (*argv[0] ? : PACKAGE_NAME)); + + /* determine which config file to open, default or custom */ + path = get_config_file_path (); + if (path == NULL) + return ENOENT; + + /* could not open conf file, if so prompt conf dialog */ + if ((file = fopen (path, "r")) == NULL) { + free (path); + return ENOENT; + } + + while (fgets (line, sizeof line, file) != NULL) { + while (line[0] == ' ' || line[0] == '\t') + memmove (line, line + 1, strlen (line)); + n++; + if (line[0] == '\n' || line[0] == '\r' || line[0] == '#') + continue; + + /* key */ + idx = strcspn (line, " \t"); + if (strlen (line) == idx) + FATAL ("Malformed config key at line: %d", n); + + line[idx] = '\0'; + + /* make old config options backwards compatible by + * substituting underscores with dashes */ + while ((p = strpbrk (line, "_")) != NULL) + *p = '-'; + + /* Ignore the following options when reading the config file */ + if (in_ignore_cmd_opts (line)) + continue; + + /* value */ + val = line + (idx + 1); + idx = strspn (val, " \t"); + if (strlen (line) == idx) + FATAL ("Malformed config value at line: %d", n); + val = val + idx; + val = trim_str (val); + + if (strcmp ("false", val) == 0) + continue; + + /* set it as command line options */ + opt = xmalloc (snprintf (NULL, 0, "--%s", line) + 1); + sprintf (opt, "--%s", line); + + append_to_argv (&nargc, &nargv, opt); + if (strcmp ("true", val) != 0) + append_to_argv (&nargc, &nargv, xstrdup (val)); + } + + /* give priority to command line arguments */ + for (i = 1; i < *argc; i++) + append_to_argv (&nargc, &nargv, xstrdup ((char *) (*argv)[i])); + + *argc = nargc; + *argv = (char **) nargv; + + fclose (file); + + if (conf.iconfigfile == NULL) + conf.iconfigfile = xstrdup (path); + + free (path); + return 0; +} + +/* Get the enumerated log format given its equivalent format string. + * The case in the format string does not matter. + * + * On error, -1 is returned. + * On success, the enumerated format is returned. */ +static int +get_log_format_item_enum (const char *str) { + int ret; + char *upstr; + + ret = str2enum (LOGTYPE, ARRAY_SIZE (LOGTYPE), str); + if (ret >= 0) + return ret; + + /* uppercase the input string and try again */ + upstr = strtoupper (xstrdup (str)); + ret = str2enum (LOGTYPE, ARRAY_SIZE (LOGTYPE), upstr); + free (upstr); + + return ret; +} + +/* Determine the selected log format from the config file or command line + * option. + * + * On error, -1 is returned. + * On success, the index of the matched item is returned. */ +size_t +get_selected_format_idx (void) { + if (conf.log_format == NULL) + return (size_t) -1; + if (strcmp (conf.log_format, logs.common) == 0) + return COMMON; + else if (strcmp (conf.log_format, logs.vcommon) == 0) + return VCOMMON; + else if (strcmp (conf.log_format, logs.combined) == 0) + return COMBINED; + else if (strcmp (conf.log_format, logs.vcombined) == 0) + return VCOMBINED; + else if (strcmp (conf.log_format, logs.w3c) == 0) + return W3C; + else if (strcmp (conf.log_format, logs.cloudfront) == 0) + return CLOUDFRONT; + else if (strcmp (conf.log_format, logs.cloudstorage) == 0) + return CLOUDSTORAGE; + else if (strcmp (conf.log_format, logs.awselb) == 0) + return AWSELB; + else if (strcmp (conf.log_format, logs.squid) == 0) + return SQUID; + else if (strcmp (conf.log_format, logs.awss3) == 0) + return AWSS3; + else if (strcmp (conf.log_format, logs.caddy) == 0) + return CADDY; + else if (strcmp (conf.log_format, logs.awsalb) == 0) + return AWSALB; + else if (strcmp (conf.log_format, logs.traefikclf) == 0) + return TRAEFIKCLF; + else + return (size_t) -1; +} + +/* Determine the selected log format from the config file or command line + * option. + * + * On error, NULL is returned. + * On success, an allocated string containing the log format is returned. */ +char * +get_selected_format_str (size_t idx) { + char *fmt = NULL; + switch (idx) { + case COMBINED: + fmt = alloc_string (logs.combined); + break; + case VCOMBINED: + fmt = alloc_string (logs.vcombined); + break; + case COMMON: + fmt = alloc_string (logs.common); + break; + case VCOMMON: + fmt = alloc_string (logs.vcommon); + break; + case W3C: + fmt = alloc_string (logs.w3c); + break; + case CLOUDFRONT: + fmt = alloc_string (logs.cloudfront); + break; + case CLOUDSTORAGE: + fmt = alloc_string (logs.cloudstorage); + break; + case AWSELB: + fmt = alloc_string (logs.awselb); + break; + case SQUID: + fmt = alloc_string (logs.squid); + break; + case AWSS3: + fmt = alloc_string (logs.awss3); + break; + case CADDY: + fmt = alloc_string (logs.caddy); + break; + case AWSALB: + fmt = alloc_string (logs.awsalb); + break; + case TRAEFIKCLF: + fmt = alloc_string (logs.traefikclf); + break; + } + + return fmt; +} + +/* Determine the selected date format from the config file or command line + * option. + * + * On error, NULL is returned. + * On success, an allocated string containing the date format is returned. */ +char * +get_selected_date_str (size_t idx) { + char *fmt = NULL; + switch (idx) { + case COMMON: + case VCOMMON: + case COMBINED: + case VCOMBINED: + case AWSS3: + case TRAEFIKCLF: + fmt = alloc_string (dates.apache); + break; + case AWSELB: + case AWSALB: + case CLOUDFRONT: + case W3C: + fmt = alloc_string (dates.w3c); + break; + case CLOUDSTORAGE: + fmt = alloc_string (dates.usec); + break; + case SQUID: + case CADDY: + fmt = alloc_string (dates.sec); + break; + } + + return fmt; +} + +/* Determine the selected time format from the config file or command line + * option. + * + * On error, NULL is returned. + * On success, an allocated string containing the time format is returned. */ +char * +get_selected_time_str (size_t idx) { + char *fmt = NULL; + switch (idx) { + case AWSELB: + case AWSALB: + case CLOUDFRONT: + case COMBINED: + case COMMON: + case VCOMBINED: + case VCOMMON: + case W3C: + case AWSS3: + case TRAEFIKCLF: + fmt = alloc_string (times.fmt24); + break; + case CLOUDSTORAGE: + fmt = alloc_string (times.usec); + break; + case SQUID: + case CADDY: + fmt = alloc_string (times.sec); + break; + } + + return fmt; +} + +/* Determine if the log/date/time were set, otherwise exit the program + * execution. */ +const char * +verify_formats (void) { + if (conf.time_format == NULL || *conf.time_format == '\0') + return ERR_FORMAT_NO_TIME_FMT; + + if (conf.date_format == NULL || *conf.date_format == '\0') + return ERR_FORMAT_NO_DATE_FMT; + + if (conf.log_format == NULL || *conf.log_format == '\0') + return ERR_FORMAT_NO_LOG_FMT; + + return NULL; +} + +/* A wrapper function to concat the given specificity to the date + * format. */ +static char * +append_spec_date_format (const char *date_format, const char *spec_format) { + char *s = xmalloc (snprintf (NULL, 0, "%s%s", date_format, spec_format) + 1); + sprintf (s, "%s%s", date_format, spec_format); + + return s; +} + +/* Iterate over the given format and clean unwanted chars and keep all + * date/time specifiers such as %b%Y%d%M%S. + * + * On error NULL is returned. + * On success, a clean format containing only date/time specifiers is + * returned. */ +static char * +clean_date_time_format (const char *format) { + char *fmt = NULL, *pr = NULL, *pw = NULL; + int special = 0; + + if (format == NULL || *format == '\0') + return NULL; + + fmt = xstrdup (format); + pr = fmt; + pw = fmt; + while (*pr) { + *pw = *pr++; + if (*pw == '%' || special) { + special = !special; + pw++; + } + } + *pw = '\0'; + + return fmt; +} + +/* Determine if the given specifier character is an abbreviated type + * of date. + * + * If it is, 1 is returned, otherwise, 0 is returned. */ +static int +is_date_abbreviated (const char *fdate) { + if (strpbrk (fdate, "cDF")) + return 1; + + return 0; +} + +/* A wrapper to extract time specifiers from a time format. + * + * On error NULL is returned. + * On success, a clean format containing only time specifiers is + * returned. */ +static char * +set_format_time (void) { + char *ftime = NULL; + + if (has_timestamp (conf.date_format) || !strcmp ("%T", conf.time_format)) + ftime = xstrdup ("%H%M%S"); + else + ftime = clean_date_time_format (conf.time_format); + + return ftime; +} + +/* A wrapper to extract date specifiers from a date format. + * + * On error NULL is returned. + * On success, a clean format containing only date specifiers is + * returned. */ +static char * +set_format_date (void) { + char *fdate = NULL; + + if (has_timestamp (conf.date_format)) + fdate = xstrdup ("%Y%m%d"); + else + fdate = clean_date_time_format (conf.date_format); + + return fdate; +} + +/* Once we have a numeric date format, we attempt to read the time + * format and construct a date_time numeric specificity format (if any + * specificity is given). The result may look like Ymd[HM]. + * + * On success, the numeric date time specificity format is set. */ +static void +set_spec_date_time_num_format (void) { + char *buf = NULL, *tf = set_format_time (); + const char *df = conf.date_num_format; + + if (!df || !tf) { + free (tf); + return; + } + + if (conf.date_spec_hr == 1 && strchr (tf, 'H')) + buf = append_spec_date_format (df, "%H"); + else if (conf.date_spec_hr == 2 && strchr (tf, 'M')) + buf = append_spec_date_format (df, "%H%M"); + else + buf = xstrdup (df); + + conf.spec_date_time_num_format = buf; + free (tf); +} + +/* Set a human-readable specificity date and time format. + * + * On success, the human-readable date time specificity format is set. */ +static void +set_spec_date_time_format (void) { + char *buf = NULL; + const char *fmt = conf.spec_date_time_num_format; + int buflen = 0, flen = 0; + + if (!fmt) + return; + + flen = (strlen (fmt) * 2) + 1; + buf = xcalloc (flen, sizeof (char)); + + if (strchr (fmt, 'd')) + buflen += snprintf (buf + buflen, flen - buflen, "%%d/"); + if (strchr (fmt, 'm')) + buflen += snprintf (buf + buflen, flen - buflen, "%%b/"); + if (strchr (fmt, 'Y')) + buflen += snprintf (buf + buflen, flen - buflen, "%%Y"); + if (strchr (fmt, 'H')) + buflen += snprintf (buf + buflen, flen - buflen, ":%%H"); + if (strchr (fmt, 'M')) + buflen += snprintf (buf + buflen, flen - buflen, ":%%M"); + + conf.spec_date_time_format = buf; +} + +/* Normalize the date format from the date format given by the user to + * Ymd so it can be sorted out properly afterwards. + * + * On error or unable to determine the format, 1 is returned. + * On success, the numeric date format as Ymd is set and 0 is + * returned. */ +static int +set_date_num_format (void) { + char *fdate = NULL, *buf = NULL; + int buflen = 0, flen = 0; + + fdate = set_format_date (); + if (!fdate) + return 1; + + if (is_date_abbreviated (fdate)) { + free (fdate); + conf.date_num_format = xstrdup ("%Y%m%d"); + return 0; + } + + flen = strlen (fdate) + 1; + flen = MAX (MIN_DATENUM_FMT_LEN, flen); /* at least %Y%m%d + 1 */ + buf = xcalloc (flen, sizeof (char)); + + /* always add a %Y */ + buflen += snprintf (buf + buflen, flen - buflen, "%%Y"); + if (strpbrk (fdate, "hbmBf*")) + buflen += snprintf (buf + buflen, flen - buflen, "%%m"); + if (strpbrk (fdate, "def*")) + buflen += snprintf (buf + buflen, flen - buflen, "%%d"); + + conf.date_num_format = buf; + free (fdate); + + return buflen == 0 ? 1 : 0; +} + +/* Determine if we have a valid JSON format */ +int +is_json_log_format (const char *fmt) { + enum json_type t = JSON_ERROR; + json_stream json; + + json_open_string (&json, fmt); + /* ensure we use strict JSON when determining if we're using a JSON format */ + json_set_streaming (&json, false); + do { + t = json_next (&json); + switch (t) { + case JSON_ERROR: + json_close (&json); + return 0; + default: + break; + } + } while (t != JSON_DONE && t != JSON_ERROR); + json_close (&json); + + return 1; +} + +/* Delete the given key from a nested object key or empty the key. */ +static void +dec_json_key (char *key, int has_dot) { + if (!key || has_dot < 0) + return; + + /* Designed to iterate has_dot + 1 times */ + /* if has_dot is 2, the loop will run three times (when i is 0, 1, and 2). Each + * iteration of the loop removes one dot from the end of the key string. + * Therefore, if has_dot is 2, it will remove up to three dots from the end of + * the key string. */ + for (int i = 0; i <= has_dot; i++) { + char *last_dot = strrchr (key, '.'); + if (last_dot) + *last_dot = '\0'; + else { + *key = '\0'; + return; + } + } +} + + + +/* Given a JSON string, parse it and call the given function pointer after each + * value. + * + * On error, a non-zero value is returned. + * On success, 0 is returned. */ +int +parse_json_string (void *ptr_data, const char *str, int (*cb) (void *, char *, char *)) { + char *key = NULL, *val = NULL; + enum json_type ctx = JSON_ERROR, t = JSON_ERROR; + int ret = 0, has_dot = 0; + size_t len = 0, level = 0; + json_stream json; + + json_open_string (&json, str); + do { + t = json_next (&json); + + switch (t) { + case JSON_OBJECT: + if (key == NULL) + key = xstrdup (""); + break; + case JSON_ARRAY_END: + case JSON_OBJECT_END: + dec_json_key (key, 0); + break; + case JSON_TRUE: + val = xstrdup ("true"); + if (!key || (ret = (*cb) (ptr_data, key, val))) + goto clean; + ctx = json_get_context (&json, &level); + if (ctx != JSON_ARRAY) + dec_json_key (key, 0); + free (val); + val = NULL; + break; + case JSON_FALSE: + val = xstrdup ("false"); + if (!key || (ret = (*cb) (ptr_data, key, val))) + goto clean; + ctx = json_get_context (&json, &level); + if (ctx != JSON_ARRAY) + dec_json_key (key, 0); + free (val); + val = NULL; + break; + case JSON_NULL: + val = xstrdup ("-"); + if (!key || (ret = (*cb) (ptr_data, key, val))) + goto clean; + ctx = json_get_context (&json, &level); + if (ctx != JSON_ARRAY) + dec_json_key (key, 0); + free (val); + val = NULL; + break; + case JSON_STRING: + case JSON_NUMBER: + ctx = json_get_context (&json, &level); + /* key */ + if ((level % 2) != 0 && ctx != JSON_ARRAY) { + /* check if key contains a dot, to account for it on dec_json_key */ + has_dot = count_matches (json_get_string (&json, &len), '.'); + + if (strlen (key) != 0) + append_str (&key, "."); + append_str (&key, json_get_string (&json, &len)); + } + /* val */ + else if (key && (ctx == JSON_ARRAY || ((level % 2) == 0 && ctx != JSON_ARRAY))) { + val = xstrdup (json_get_string (&json, &len)); + if (!key || (ret = (*cb) (ptr_data, key, val))) + goto clean; + if (ctx != JSON_ARRAY) + dec_json_key (key, has_dot); + + free (val); + val = NULL; + } + break; + case JSON_ERROR: + ret = -1; + goto clean; + break; + default: + break; + } + } while (t != JSON_DONE && t != JSON_ERROR); + +clean: + free (val); + free (key); + json_close (&json); + + return ret; +} + +/* If specificity is supplied, then determine which value we need to + * append to the date format. */ +void +set_spec_date_format (void) { + if (verify_formats ()) + return; + + if (conf.is_json_log_format) { + if (parse_json_string (NULL, conf.log_format, ht_insert_json_logfmt) == -1) + FATAL ("Invalid JSON log format. Verify the syntax."); + } + + if (conf.date_num_format) + free (conf.date_num_format); + if (conf.spec_date_time_format) + free (conf.spec_date_time_format); + if (conf.spec_date_time_num_format) + free (conf.spec_date_time_num_format); + + if (set_date_num_format () == 0) { + set_spec_date_time_num_format (); + set_spec_date_time_format (); + } +} + +/* Attempt to set the date format given a command line option + * argument. The supplied optarg can be either an actual format string + * or the enumerated value such as VCOMBINED */ +void +set_date_format_str (const char *oarg) { + char *fmt = NULL; + int type = get_log_format_item_enum (oarg); + + /* free date format if it was previously set by set_log_format_str() */ + if (conf.date_format) + free (conf.date_format); + + /* type not found, use whatever was given by the user then */ + if (type == -1) { + conf.date_format = unescape_str (oarg); + return; + } + + /* attempt to get the format string by the enum value */ + if ((fmt = get_selected_date_str (type)) == NULL) { + LOG_DEBUG (("Unable to set date format from enum: %s\n", oarg)); + return; + } + + conf.date_format = fmt; +} + +/* Attempt to set the time format given a command line option + * argument. The supplied optarg can be either an actual format string + * or the enumerated value such as VCOMBINED */ +void +set_time_format_str (const char *oarg) { + char *fmt = NULL; + int type = get_log_format_item_enum (oarg); + + /* free time format if it was previously set by set_log_format_str() */ + if (conf.time_format) + free (conf.time_format); + + /* type not found, use whatever was given by the user then */ + if (type == -1) { + conf.time_format = unescape_str (oarg); + return; + } + + /* attempt to get the format string by the enum value */ + if ((fmt = get_selected_time_str (type)) == NULL) { + LOG_DEBUG (("Unable to set time format from enum: %s\n", oarg)); + return; + } + + conf.time_format = fmt; +} + +/* Determine if some global flags were set through log-format. */ +static void +contains_specifier (void) { + conf.serve_usecs = conf.bandwidth = 0; /* flag */ + if (!conf.log_format) + return; + + if (strstr (conf.log_format, "%b")) + conf.bandwidth = 1; /* flag */ + if (strstr (conf.log_format, "%D")) + conf.serve_usecs = 1; /* flag */ + if (strstr (conf.log_format, "%T")) + conf.serve_usecs = 1; /* flag */ + if (strstr (conf.log_format, "%L")) + conf.serve_usecs = 1; /* flag */ +} + +/* Attempt to set the log format given a command line option argument. + * The supplied optarg can be either an actual format string or the + * enumerated value such as VCOMBINED */ +void +set_log_format_str (const char *oarg) { + char *fmt = NULL; + int type = get_log_format_item_enum (oarg); + + /* free log format if it was previously set */ + if (conf.log_format) + free (conf.log_format); + + if (type == -1 && is_json_log_format (oarg)) { + conf.is_json_log_format = 1; + conf.log_format = unescape_str (oarg); + contains_specifier (); /* set flag */ + return; + } + + /* type not found, use whatever was given by the user then */ + if (type == -1) { + conf.log_format = unescape_str (oarg); + contains_specifier (); /* set flag */ + return; + } + + /* attempt to get the format string by the enum value */ + if ((fmt = get_selected_format_str (type)) == NULL) { + LOG_DEBUG (("Unable to set log format from enum: %s\n", oarg)); + return; + } + + if (is_json_log_format (fmt)) + conf.is_json_log_format = 1; + + conf.log_format = unescape_str (fmt); + contains_specifier (); /* set flag */ + + /* assume we are using the default date/time formats */ + set_time_format_str (oarg); + set_date_format_str (oarg); + free (fmt); +} diff --git a/src/settings.h b/src/settings.h new file mode 100644 index 0000000000..0ced020fa9 --- /dev/null +++ b/src/settings.h @@ -0,0 +1,253 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef SETTINGS_H_INCLUDED +#define SETTINGS_H_INCLUDED + +#include +#include "commons.h" + +#define MAX_LINE_CONF 4096 +#define MAX_EXTENSIONS 128 +#define MAX_GEOIP_DBS 3 +#define MAX_IGNORE_IPS 1024 + 128 +#define MAX_IGNORE_REF 64 +#define MAX_CUSTOM_COLORS 64 +#define MAX_IGNORE_STATUS 64 +#define MAX_OUTFORMATS 3 +#define MAX_FILENAMES 3072 +#define MIN_DATENUM_FMT_LEN 7 +#define NO_CONFIG_FILE "No config file used" + +typedef enum LOGTYPE { + COMBINED, + VCOMBINED, + COMMON, + VCOMMON, + W3C, + CLOUDFRONT, + CLOUDSTORAGE, + AWSELB, + SQUID, + AWSS3, + CADDY, + AWSALB, + TRAEFIKCLF, +} GLogType; + +/* predefined log times */ +typedef struct GPreConfTime_ { + const char *fmt24; + const char *usec; + const char *sec; +} GPreConfTime; + +/* predefined log dates */ +typedef struct GPreConfDate_ { + const char *apache; + const char *w3c; + const char *usec; + const char *sec; +} GPreConfDate; + +/* predefined log formats */ +typedef struct GPreConfLog_ { + const char *combined; + const char *vcombined; + const char *common; + const char *vcommon; + const char *w3c; + const char *cloudfront; + const char *cloudstorage; + const char *awselb; + const char *squid; + const char *awss3; + const char *caddy; + const char *awsalb; + const char *traefikclf; +} GPreConfLog; + +/* *INDENT-OFF* */ +/* All configuration properties */ +typedef struct GConf_ +{ + /* Array options */ + const char *colors[MAX_CUSTOM_COLORS]; /* colors */ + const char *enable_panels[TOTAL_MODULES]; /* array of panels to enable */ + const char *filenames[MAX_FILENAMES]; /* log files */ + const char *hide_referers[MAX_IGNORE_REF]; /* hide referrers from report */ + const char *ignore_ips[MAX_IGNORE_IPS]; /* array of ips to ignore */ + const char *ignore_panels[TOTAL_MODULES]; /* array of panels to ignore */ + const char *ignore_referers[MAX_IGNORE_REF]; /* referrers to ignore */ + int ignore_status[MAX_IGNORE_STATUS]; /* status to ignore */ + const char *output_formats[MAX_OUTFORMATS]; /* output format, e.g. , HTML */ + const char *sort_panels[TOTAL_MODULES]; /* sorting options for each panel */ + const char *static_files[MAX_EXTENSIONS]; /* static extensions */ + const char *geoip_databases[MAX_GEOIP_DBS]; /* geoip db paths */ + + /* Log/date/time formats */ + const char *tz_name; /* Canonical TZ name, e.g., America/Chicago */ + char *date_time_format; /* date & time format */ + char *date_format; /* date format */ + char *date_num_format; /* numeric date format %Y%m%d */ + char *time_format; /* time format as given by the user */ + char *spec_date_time_format; /* date format w/ specificity */ + char *spec_date_time_num_format; /* numeric date format w/ specificity */ + char *log_format; /* log format */ + char *iconfigfile; /* config file path */ + char ***user_browsers_hash; /* custom list of browsers */ + + const char *debug_log; /* debug log path */ + const char *html_custom_css; /* custom CSS */ + const char *html_custom_js; /* custom JS */ + const char *html_prefs; /* default HTML JSON preferences */ + const char *html_report_title; /* report title */ + const char *invalid_requests_log; /* invalid lines log path */ + const char *unknowns_log; /* unknown browsers/OSs log path */ + const char *pidfile; /* daemonize pid file path */ + const char *browsers_file; /* browser's file path */ + const char *db_path; /* db path to files */ + const char *fname_as_vhost; /* filenames as vhost/server blocks */ + + /* HTML real-time */ + const char *addr; /* IP address to bind to */ + const char *fifo_in; /* path FIFO in (reader) */ + const char *fifo_out; /* path FIFO out (writer) */ + const char *origin; /* WebSocket origin */ + const char *port; /* port to use */ + const char *sslcert; /* TLS/SSL path to certificate */ + const char *sslkey; /* TLS/SSL path to private key */ + const char *ws_url; /* WebSocket URL */ + const char *ping_interval; /* WebSocket ping interval in seconds */ + const char *unix_socket; /* unix socket to bind to */ + + /* User flags */ + int all_static_files; /* parse all static files */ + int anonymize_ip; /* anonymize ip addresses */ + int anonymize_level; /* anonymization level */ + int append_method; /* append method to the req key */ + int append_protocol; /* append protocol to the req key */ + int client_err_to_unique_count; /* count 400s as visitors */ + int code444_as_404; /* 444 as 404s? */ + int color_scheme; /* color scheme */ + int chunk_size; /* chunk size for each thread */ + int crawlers_only; /* crawlers only */ + int daemonize; /* run program as a Unix daemon */ + const char *username; /* user to run program as */ + int double_decode; /* need to double decode */ + int external_assets; /* write JS/CSS assets to external files */ + int enable_html_resolver; /* html/json/csv resolver */ + int geo_db; /* legacy geoip db */ + int hl_header; /* highlight header on term */ + int ignore_crawlers; /* ignore crawlers */ + int unknowns_as_crawlers; /* unknown OS and browsers are classified as crawlers */ + int ignore_qstr; /* ignore query string */ + int ignore_statics; /* ignore static files */ + int jobs; /* multi-thread jobs count */ + int json_pretty_print; /* pretty print JSON data */ + int list_agents; /* show list of agents per host */ + int load_conf_dlg; /* load curses config dialog */ + int load_global_config; /* use global config file */ + int max_items; /* max number of items to output */ + int mouse_support; /* add curses mouse support */ + int no_color; /* no terminal colors */ + int no_strict_status; /* don't enforce 100-599 status codes */ + int no_column_names; /* don't show col names on terminal */ + int no_csv_summary; /* don't show overall metrics */ + int no_html_last_updated; /* don't show HTML last updated field */ + int no_ip_validation; /* don't validate client IP addresses */ + int no_parsing_spinner; /* disable parsing spinner */ + int no_progress; /* disable progress metrics */ + int no_tab_scroll; /* don't scroll dashboard on tab */ + int output_stdout; /* outputting to stdout */ + int persist; /* ensure to persist data on exit */ + int process_and_exit; /* parse and exit without outputting */ + int real_os; /* show real OSs */ + int real_time_html; /* enable real-time HTML output */ + int restore; /* reload data from db-path */ + int skip_term_resolver; /* no terminal resolver */ + int is_json_log_format; /* is a json log format */ + uint32_t keep_last; /* number of days to keep in storage */ + uint32_t num_tests; /* number of lines to test */ + uint64_t html_refresh; /* refresh html report every X of seconds */ + uint64_t log_size; /* log size override */ + + /* Internal flags */ + int bandwidth; /* is there bandwidth within the req line */ + int date_spec_hr; /* date specificity - hour */ + int has_geocity; + int has_geocountry; + int has_geoasn; + int hour_spec_min; /* hour specificity - min */ + int read_stdin; /* read from stdin */ + int serve_usecs; /* is there time served within req line */ + int stop_processing; /* stop all processing */ + int tailing_mode; /* in tailing-mode? */ + + /* Array indices */ + int color_idx; /* colors index */ + int enable_panel_idx; /* enable panels index */ + int filenames_idx; /* filenames index */ + int hide_referer_idx; /* hide referrers index */ + int ignore_ip_idx; /* ignored ips index */ + int ignore_panel_idx; /* ignored panels index */ + int ignore_referer_idx; /* ignored referrers index */ + int ignore_status_idx; /* ignore status index */ + int output_format_idx; /* output format index */ + int sort_panel_idx; /* sort panel index */ + int static_file_idx; /* static extensions index */ + int geoip_db_idx; /* geoip db index */ + int browsers_hash_idx; /* browsers hash index */ + + size_t static_file_max_len; + +} GConf; +/* *INDENT-ON* */ + +char *get_selected_date_str (size_t idx); +char *get_selected_format_str (size_t idx); +char *get_selected_time_str (size_t idx); +const char *verify_formats (void); +int is_json_log_format (const char *fmt); +int parse_json_string (void *userdata, const char *str, int (*cb) (void *, char *, char *)); +size_t get_selected_format_idx (void); +void set_date_format_str (const char *optarg); +void set_log_format_str (const char *optarg); +void set_spec_date_format (void); +void set_time_format_str (const char *optarg); + +extern GConf conf; + +char *get_config_file_path (void); +int parse_conf_file (int *argc, char ***argv); +void free_cmd_args (void); +void free_formats (void); +void set_default_static_files (void); + +#endif diff --git a/src/sha1.c b/src/sha1.c new file mode 100644 index 0000000000..5af8cdb3c5 --- /dev/null +++ b/src/sha1.c @@ -0,0 +1,229 @@ +/* +SHA-1 in C +By Steve Reid +100% Public Domain + +Test Vectors (from FIPS PUB 180-1) +"abc" + A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D +"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" + 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 +A million repetitions of "a" + 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F +*/ + +/* #define LITTLE_ENDIAN * This should be #define'd if true. */ +#if __LITTLE_ENDIAN__ +#define LITTLE_ENDIAN +#endif +/* #define SHA1HANDSOFF * Copies data before messing with it. */ + +#include + +#include "sha1.h" + +void SHA1Transform (uint32_t state[5], uint8_t buffer[64]); + +#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) + +/* blk0() and blk() perform the initial expand. */ +/* I got the idea of expanding during the round function from SSLeay */ +#ifdef LITTLE_ENDIAN +#define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \ + |(rol(block->l[i],8)&0x00FF00FF)) +#else +#define blk0(i) block->l[i] +#endif +#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ + ^block->l[(i+2)&15]^block->l[i&15],1)) + +/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ +#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); +#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); +#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); +#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); +#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); + + +/* Hash a single 512-bit block. This is the core of the algorithm. */ + +void +SHA1Transform (uint32_t state[5], uint8_t buffer[64]) { + uint32_t a, b, c, d, e; + typedef union { + uint8_t c[64]; + uint32_t l[16]; + } CHAR64LONG16; + CHAR64LONG16 *block; +#ifdef SHA1HANDSOFF + static uint8_t workspace[64]; + block = (CHAR64LONG16 *) (void *) workspace; + memcpy (block, buffer, 64); +#else + block = (CHAR64LONG16 *) (void *) buffer; +#endif + /* Copy context->state[] to working vars */ + a = state[0]; + b = state[1]; + c = state[2]; + d = state[3]; + e = state[4]; + /* 4 rounds of 20 operations each. Loop unrolled. */ + R0 (a, b, c, d, e, 0); + R0 (e, a, b, c, d, 1); + R0 (d, e, a, b, c, 2); + R0 (c, d, e, a, b, 3); + R0 (b, c, d, e, a, 4); + R0 (a, b, c, d, e, 5); + R0 (e, a, b, c, d, 6); + R0 (d, e, a, b, c, 7); + R0 (c, d, e, a, b, 8); + R0 (b, c, d, e, a, 9); + R0 (a, b, c, d, e, 10); + R0 (e, a, b, c, d, 11); + R0 (d, e, a, b, c, 12); + R0 (c, d, e, a, b, 13); + R0 (b, c, d, e, a, 14); + R0 (a, b, c, d, e, 15); + R1 (e, a, b, c, d, 16); + R1 (d, e, a, b, c, 17); + R1 (c, d, e, a, b, 18); + R1 (b, c, d, e, a, 19); + R2 (a, b, c, d, e, 20); + R2 (e, a, b, c, d, 21); + R2 (d, e, a, b, c, 22); + R2 (c, d, e, a, b, 23); + R2 (b, c, d, e, a, 24); + R2 (a, b, c, d, e, 25); + R2 (e, a, b, c, d, 26); + R2 (d, e, a, b, c, 27); + R2 (c, d, e, a, b, 28); + R2 (b, c, d, e, a, 29); + R2 (a, b, c, d, e, 30); + R2 (e, a, b, c, d, 31); + R2 (d, e, a, b, c, 32); + R2 (c, d, e, a, b, 33); + R2 (b, c, d, e, a, 34); + R2 (a, b, c, d, e, 35); + R2 (e, a, b, c, d, 36); + R2 (d, e, a, b, c, 37); + R2 (c, d, e, a, b, 38); + R2 (b, c, d, e, a, 39); + R3 (a, b, c, d, e, 40); + R3 (e, a, b, c, d, 41); + R3 (d, e, a, b, c, 42); + R3 (c, d, e, a, b, 43); + R3 (b, c, d, e, a, 44); + R3 (a, b, c, d, e, 45); + R3 (e, a, b, c, d, 46); + R3 (d, e, a, b, c, 47); + R3 (c, d, e, a, b, 48); + R3 (b, c, d, e, a, 49); + R3 (a, b, c, d, e, 50); + R3 (e, a, b, c, d, 51); + R3 (d, e, a, b, c, 52); + R3 (c, d, e, a, b, 53); + R3 (b, c, d, e, a, 54); + R3 (a, b, c, d, e, 55); + R3 (e, a, b, c, d, 56); + R3 (d, e, a, b, c, 57); + R3 (c, d, e, a, b, 58); + R3 (b, c, d, e, a, 59); + R4 (a, b, c, d, e, 60); + R4 (e, a, b, c, d, 61); + R4 (d, e, a, b, c, 62); + R4 (c, d, e, a, b, 63); + R4 (b, c, d, e, a, 64); + R4 (a, b, c, d, e, 65); + R4 (e, a, b, c, d, 66); + R4 (d, e, a, b, c, 67); + R4 (c, d, e, a, b, 68); + R4 (b, c, d, e, a, 69); + R4 (a, b, c, d, e, 70); + R4 (e, a, b, c, d, 71); + R4 (d, e, a, b, c, 72); + R4 (c, d, e, a, b, 73); + R4 (b, c, d, e, a, 74); + R4 (a, b, c, d, e, 75); + R4 (e, a, b, c, d, 76); + R4 (d, e, a, b, c, 77); + R4 (c, d, e, a, b, 78); + R4 (b, c, d, e, a, 79); + /* Add the working vars back into context.state[] */ + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + state[4] += e; + /* Wipe variables */ + a = b = c = d = e = 0; +} + + +/* SHA1Init - Initialize new context */ + +void +SHA1Init (SHA1_CTX *context) { + /* SHA1 initialization constants */ + context->state[0] = 0x67452301; + context->state[1] = 0xEFCDAB89; + context->state[2] = 0x98BADCFE; + context->state[3] = 0x10325476; + context->state[4] = 0xC3D2E1F0; + context->count[0] = context->count[1] = 0; +} + + +/* Run your data through this. */ + +void +SHA1Update (SHA1_CTX *context, uint8_t *data, unsigned int len) { + unsigned int i, j; + + j = (context->count[0] >> 3) & 63; + if ((context->count[0] += len << 3) < (len << 3)) + context->count[1]++; + context->count[1] += (len >> 29); + if ((j + len) > 63) { + memcpy (&context->buffer[j], data, (i = 64 - j)); + SHA1Transform (context->state, context->buffer); + for (; i + 63 < len; i += 64) { + SHA1Transform (context->state, &data[i]); + } + j = 0; + } else + i = 0; + memcpy (&context->buffer[j], &data[i], len - i); +} + + +/* Add padding and return the message digest. */ + +void +SHA1Final (uint8_t digest[20], SHA1_CTX *context) { + uint32_t i, j; + uint8_t finalcount[8]; + + for (i = 0; i < 8; i++) { + finalcount[i] = (uint8_t) ((context->count[(i >= 4 ? 0 : 1)] + >> ((3 - (i & 3)) * 8)) & 255); /* Endian independent */ + } + SHA1Update (context, (uint8_t *) "\200", 1); + while ((context->count[0] & 504) != 448) { + SHA1Update (context, (uint8_t *) "\0", 1); + } + SHA1Update (context, finalcount, 8); /* Should cause a SHA1Transform() */ + for (i = 0; i < 20; i++) { + digest[i] = (uint8_t) + ((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255); + } + /* Wipe variables */ + i = j = 0; + memset (context->buffer, 0, 64); + memset (context->state, 0, 20); + memset (context->count, 0, 8); + memset (&finalcount, 0, 8); +#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite its own static vars */ + SHA1Transform (context->state, context->buffer); +#endif +} diff --git a/src/sha1.h b/src/sha1.h new file mode 100644 index 0000000000..633d91cae8 --- /dev/null +++ b/src/sha1.h @@ -0,0 +1,19 @@ +#ifndef SHA1_H_INCLUDED +#define SHA1_H_INCLUDED + +#include +#include + +// From http://www.mirrors.wiretapped.net/security/cryptography/hashes/sha1/sha1.c + +typedef struct { + uint32_t state[5]; + uint32_t count[2]; + uint8_t buffer[64]; +} SHA1_CTX; + +extern void SHA1Init (SHA1_CTX * context); +extern void SHA1Update (SHA1_CTX * context, uint8_t * data, uint32_t len); +extern void SHA1Final (uint8_t digest[20], SHA1_CTX * context); + +#endif // for #ifndef SHA1_H diff --git a/src/sort.c b/src/sort.c new file mode 100644 index 0000000000..857f8be2b2 --- /dev/null +++ b/src/sort.c @@ -0,0 +1,565 @@ +/** + * sort.c -- functions related to sort functionality + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include "settings.h" +#include "util.h" + +#include "sort.h" + +/* *INDENT-OFF* */ +const int sort_choices[][SORT_MAX_OPTS] = { + /* VISITORS */ + {SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1}, + /* REQUESTS */ + {SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, SORT_BY_PROT, SORT_BY_MTHD, -1}, + /* REQUESTS_STATIC */ + {SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, SORT_BY_PROT, SORT_BY_MTHD, -1}, + /* NOT_FOUND */ + {SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, SORT_BY_PROT, SORT_BY_MTHD, -1}, + /* HOSTS */ + {SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1}, + /* OS */ + {SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1}, + /* BROWSERS */ + {SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1}, + /* VISIT_TIMES */ + {SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1}, + /* VIRTUAL_HOSTS */ + {SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1}, + /* REFERRERS */ + {SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1}, + /* REFERRING_SITES */ + {SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1}, + /* KEYPHRASES */ + {SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1}, + /* STATUS_CODES */ + {SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1}, + /* REMOTE_USER */ + {SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1}, + /* CACHE_STATUS */ + {SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1}, +#ifdef HAVE_GEOLOCATION + /* GEO_LOCATION */ + {SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1}, + /* ASN */ + {SORT_BY_HITS, SORT_BY_VISITORS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1}, +#endif + /* MIME_TYPE */ + {SORT_BY_HITS, SORT_BY_DATA, SORT_BY_BW, SORT_BY_AVGTS, SORT_BY_CUMTS, SORT_BY_MAXTS, -1}, + /* TLS_TYPE */ + {SORT_BY_HITS, SORT_BY_DATA, SORT_BY_VISITORS, SORT_BY_BW, -1}, +}; + +static const GEnum FIELD[] = { + {"BY_HITS" , SORT_BY_HITS } , + {"BY_VISITORS" , SORT_BY_VISITORS } , + {"BY_DATA" , SORT_BY_DATA } , + {"BY_BW" , SORT_BY_BW } , + {"BY_AVGTS" , SORT_BY_AVGTS } , + {"BY_CUMTS" , SORT_BY_CUMTS } , + {"BY_MAXTS" , SORT_BY_MAXTS } , + {"BY_PROT" , SORT_BY_PROT } , + {"BY_MTHD" , SORT_BY_MTHD } , +}; + +static const GEnum ORDER[] = { + {"ASC" , SORT_ASC } , + {"DESC" , SORT_DESC } , +}; + +GSort module_sort[TOTAL_MODULES] = { + {VISITORS , SORT_BY_DATA , SORT_DESC } , + {REQUESTS , SORT_BY_HITS , SORT_DESC } , + {REQUESTS_STATIC , SORT_BY_HITS , SORT_DESC } , + {NOT_FOUND , SORT_BY_HITS , SORT_DESC } , + {HOSTS , SORT_BY_HITS , SORT_DESC } , + {OS , SORT_BY_HITS , SORT_DESC } , + {BROWSERS , SORT_BY_HITS , SORT_DESC } , + {VISIT_TIMES , SORT_BY_DATA , SORT_ASC } , + {VIRTUAL_HOSTS , SORT_BY_HITS , SORT_DESC } , + {REFERRERS , SORT_BY_HITS , SORT_DESC } , + {REFERRING_SITES , SORT_BY_HITS , SORT_DESC } , + {KEYPHRASES , SORT_BY_HITS , SORT_DESC } , + {STATUS_CODES , SORT_BY_HITS , SORT_DESC } , + {REMOTE_USER , SORT_BY_HITS , SORT_DESC } , + {CACHE_STATUS , SORT_BY_HITS , SORT_DESC } , +#ifdef HAVE_GEOLOCATION + {GEO_LOCATION , SORT_BY_HITS , SORT_DESC } , + {ASN , SORT_BY_HITS , SORT_DESC } , +#endif + {MIME_TYPE , SORT_BY_HITS , SORT_DESC } , + {TLS_TYPE , SORT_BY_VISITORS , SORT_DESC } , +}; +/* *INDENT-ON* */ + +/* Sort an array of strings ascending */ +int +strcmp_asc (const void *a, const void *b) { + return strcmp (*((char *const *) a), *((char *const *) b)); +} + +/* Sort 'data' metric ascending */ +static int +cmp_data_asc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + return strcmp (ia->metrics->data, ib->metrics->data); +} + +/* Sort 'data' metric descending */ +static int +cmp_data_desc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + return strcmp (ib->metrics->data, ia->metrics->data); +} + +/* Sort 'hits' metric descending */ +static int +cmp_num_desc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + + uint64_t va = ia->metrics->hits; + uint64_t vb = ib->metrics->hits; + + return (va < vb) - (va > vb); +} + +/* Sort 'hits' metric ascending */ +static int +cmp_num_asc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + + uint64_t va = ia->metrics->hits; + uint64_t vb = ib->metrics->hits; + + return (va > vb) - (va < vb); +} + +/* Sort 'visitors' metric descending */ +static int +cmp_vis_desc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + + uint64_t va = ia->metrics->visitors; + uint64_t vb = ib->metrics->visitors; + + return (va < vb) - (va > vb); +} + +/* Sort 'visitors' metric ascending */ +static int +cmp_vis_asc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + + uint64_t va = ia->metrics->visitors; + uint64_t vb = ib->metrics->visitors; + + return (va > vb) - (va < vb); +} + +/* Sort GRawDataItem value descending */ +static int +cmp_raw_num_desc (const void *a, const void *b) { + const GRawDataItem *ia = a; + const GRawDataItem *ib = b; + + uint64_t va = ia->hits; + uint64_t vb = ib->hits; + + return (va < vb) - (va > vb); +} + +/* Sort GRawDataItem value descending */ +static int +cmp_raw_str_desc (const void *a, const void *b) { + const GRawDataItem *ia = a; + const GRawDataItem *ib = b; + + return strcmp (ib->data, ia->data); +} + +/* Sort 'bandwidth' metric descending */ +static int +cmp_bw_desc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + + uint64_t va = ia->metrics->bw.nbw; + uint64_t vb = ib->metrics->bw.nbw; + + return (va < vb) - (va > vb); +} + +/* Sort 'bandwidth' metric ascending */ +static int +cmp_bw_asc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + + uint64_t va = ia->metrics->bw.nbw; + uint64_t vb = ib->metrics->bw.nbw; + + return (va > vb) - (va < vb); +} + +/* Sort 'avgts' metric descending */ +static int +cmp_avgts_desc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + + uint64_t va = ia->metrics->avgts.nts; + uint64_t vb = ib->metrics->avgts.nts; + + return (va < vb) - (va > vb); +} + +/* Sort 'avgts' metric ascending */ +static int +cmp_avgts_asc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + + uint64_t va = ia->metrics->avgts.nts; + uint64_t vb = ib->metrics->avgts.nts; + + return (va > vb) - (va < vb); +} + +/* Sort 'cumts' metric descending */ +static int +cmp_cumts_desc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + + uint64_t va = ia->metrics->cumts.nts; + uint64_t vb = ib->metrics->cumts.nts; + + return (va < vb) - (va > vb); +} + +/* Sort 'cumts' metric ascending */ +static int +cmp_cumts_asc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + + uint64_t va = ia->metrics->cumts.nts; + uint64_t vb = ib->metrics->cumts.nts; + + return (va > vb) - (va < vb); +} + +/* Sort 'maxts' metric descending */ +static int +cmp_maxts_desc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + + uint64_t va = ia->metrics->maxts.nts; + uint64_t vb = ib->metrics->maxts.nts; + + return (va < vb) - (va > vb); +} + +/* Sort 'maxts' metric ascending */ +static int +cmp_maxts_asc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + + uint64_t va = ia->metrics->maxts.nts; + uint64_t vb = ib->metrics->maxts.nts; + + return (va > vb) - (va < vb); +} + +/* Sort 'protocol' metric ascending */ +static int +cmp_proto_asc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + return strcmp (ia->metrics->protocol, ib->metrics->protocol); +} + +/* Sort 'protocol' metric descending */ +static int +cmp_proto_desc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + return strcmp (ib->metrics->protocol, ia->metrics->protocol); +} + +/* Sort 'method' metric ascending */ +static int +cmp_mthd_asc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + return strcmp (ia->metrics->method, ib->metrics->method); +} + +/* Sort 'method' metric descending */ +static int +cmp_mthd_desc (const void *a, const void *b) { + const GHolderItem *ia = a; + const GHolderItem *ib = b; + return strcmp (ib->metrics->method, ia->metrics->method); +} + +/* Sort ascending */ +#if defined(__clang__) && defined(__clang_major__) && (__clang_major__ >= 4) +__attribute__((no_sanitize ("implicit-conversion", "unsigned-integer-overflow"))) +#endif +int +cmp_ui32_asc (const void *a, const void *b) { + const uint32_t *ia = (const uint32_t *) a; // casting pointer types + const uint32_t *ib = (const uint32_t *) b; + return *ia - *ib; +} + +int +cmp_ui32_desc (const void *a, const void *b) { + const uint32_t *ia = (const uint32_t *) a; // casting pointer types + const uint32_t *ib = (const uint32_t *) b; + return *ib - *ia; +} + +/* Given a string sort field, get the enum field value. + * + * On error, -1 is returned. + * On success, the enumerated field value is returned. */ +int +get_sort_field_enum (const char *str) { + return str2enum (FIELD, ARRAY_SIZE (FIELD), str); +} + +/* Given a string sort order, get the enum order value. + * + * On error, -1 is returned. + * On success, the enumerated order value is returned. */ +int +get_sort_order_enum (const char *str) { + return str2enum (ORDER, ARRAY_SIZE (ORDER), str); +} + +/* Given a GSortOrder enum value, return the corresponding string. + * + * The string corresponding to the enumerated order value is returned. */ +const char * +get_sort_order_str (GSortOrder order) { + return ORDER[order].str; +} + +/* Given a GSortField enum value, return the corresponding string. + * + * The string corresponding to the enumerated field value is returned. */ +const char * +get_sort_field_str (GSortField field) { + return FIELD[field].str; +} + +/* Given a GSortField enum value, return the corresponding key. + * + * The key corresponding to the enumerated field value is returned. */ +const char * +get_sort_field_key (GSortField field) { + static const char *const field2key[][2] = { + {"BY_HITS", "hits"}, + {"BY_VISITORS", "visitors"}, + {"BY_DATA", "data"}, + {"BY_BW", "bytes"}, + {"BY_AVGTS", "avgts"}, + {"BY_CUMTS", "cumts"}, + {"BY_MAXTS", "maxts"}, + {"BY_PROT", "protocol"}, + {"BY_MTHD", "method"}, + }; + + return field2key[field][1]; +} + +/* Set the initial metric sort per module/panel. + * + * On error, function returns. + * On success, panel metrics are sorted. */ +void +set_initial_sort (const char *smod, const char *sfield, const char *ssort) { + int module, field, order; + if ((module = get_module_enum (smod)) == -1) + return; + + if ((field = get_sort_field_enum (sfield)) == -1) + return; + if ((order = get_sort_order_enum (ssort)) == -1) + return; + if (!can_sort_module (module, field)) + return; + + module_sort[module].field = field; + module_sort[module].sort = order; +} + +/* Determine if module/panel metric can be sorted. + * + * On error or if metric can't be sorted, 0 is returned. + * On success, 1 is returned. */ +int +can_sort_module (GModule module, int field) { + int i, can_sort = 0; + for (i = 0; -1 != sort_choices[module][i]; i++) { + if (sort_choices[module][i] != field) + continue; + if (SORT_BY_AVGTS == field && !conf.serve_usecs) + continue; + if (SORT_BY_CUMTS == field && !conf.serve_usecs) + continue; + if (SORT_BY_MAXTS == field && !conf.serve_usecs) + continue; + else if (SORT_BY_BW == field && !conf.bandwidth) + continue; + else if (SORT_BY_PROT == field && !conf.append_protocol) + continue; + else if (SORT_BY_MTHD == field && !conf.append_method) + continue; + + can_sort = 1; + break; + } + + return can_sort; +} + +/* Parse all initial sort options from the config file. + * + * On error, function returns. + * On success, panel metrics are sorted. */ +void +parse_initial_sort (void) { + int i; + char module[SORT_MODULE_LEN], field[SORT_FIELD_LEN], order[SORT_ORDER_LEN]; + for (i = 0; i < conf.sort_panel_idx; ++i) { + if (sscanf (conf.sort_panels[i], "%15[^','],%11[^','],%4s", module, field, order) != 3) + continue; + set_initial_sort (module, field, order); + } +} + +/* Apply user defined sort */ +void +sort_holder_items (GHolderItem *items, int size, GSort sort) { + switch (sort.field) { + case SORT_BY_HITS: + if (sort.sort == SORT_DESC) + qsort (items, size, sizeof (GHolderItem), cmp_num_desc); + else + qsort (items, size, sizeof (GHolderItem), cmp_num_asc); + break; + case SORT_BY_VISITORS: + if (sort.sort == SORT_DESC) + qsort (items, size, sizeof (GHolderItem), cmp_vis_desc); + else + qsort (items, size, sizeof (GHolderItem), cmp_vis_asc); + break; + case SORT_BY_DATA: + if (sort.sort == SORT_DESC) + qsort (items, size, sizeof (GHolderItem), cmp_data_desc); + else + qsort (items, size, sizeof (GHolderItem), cmp_data_asc); + break; + case SORT_BY_BW: + if (sort.sort == SORT_DESC) + qsort (items, size, sizeof (GHolderItem), cmp_bw_desc); + else + qsort (items, size, sizeof (GHolderItem), cmp_bw_asc); + break; + case SORT_BY_AVGTS: + if (sort.sort == SORT_DESC) + qsort (items, size, sizeof (GHolderItem), cmp_avgts_desc); + else + qsort (items, size, sizeof (GHolderItem), cmp_avgts_asc); + break; + case SORT_BY_CUMTS: + if (sort.sort == SORT_DESC) + qsort (items, size, sizeof (GHolderItem), cmp_cumts_desc); + else + qsort (items, size, sizeof (GHolderItem), cmp_cumts_asc); + break; + case SORT_BY_MAXTS: + if (sort.sort == SORT_DESC) + qsort (items, size, sizeof (GHolderItem), cmp_maxts_desc); + else + qsort (items, size, sizeof (GHolderItem), cmp_maxts_asc); + break; + case SORT_BY_PROT: + if (sort.sort == SORT_DESC) + qsort (items, size, sizeof (GHolderItem), cmp_proto_desc); + else + qsort (items, size, sizeof (GHolderItem), cmp_proto_asc); + break; + case SORT_BY_MTHD: + if (sort.sort == SORT_DESC) + qsort (items, size, sizeof (GHolderItem), cmp_mthd_desc); + else + qsort (items, size, sizeof (GHolderItem), cmp_mthd_asc); + break; + } +} + +/* Sort raw numeric data in a descending order for the first run + * (default sort) + * + * On success, raw data sorted in a descending order. */ +GRawData * +sort_raw_num_data (GRawData *raw_data, int ht_size) { + qsort (raw_data->items, ht_size, sizeof *(raw_data->items), cmp_raw_num_desc); + return raw_data; +} + +/* Sort raw string data in a descending order for the first run. + * + * On success, raw data sorted in a descending order. */ +GRawData * +sort_raw_str_data (GRawData *raw_data, int ht_size) { + qsort (raw_data->items, ht_size, sizeof *(raw_data->items), cmp_raw_str_desc); + return raw_data; +} diff --git a/src/sort.h b/src/sort.h new file mode 100644 index 0000000000..06ed02092c --- /dev/null +++ b/src/sort.h @@ -0,0 +1,91 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#ifndef SORT_H_INCLUDED +#define SORT_H_INCLUDED + +#include "commons.h" +#include "parser.h" + +#define SORT_MAX_OPTS 11 + +/* See GEnum for mapping */ +#define SORT_FIELD_LEN 11 + 1 /* longest metric name */ +#define SORT_MODULE_LEN 15 + 1 /* longest module name */ +#define SORT_ORDER_LEN 4 + 1 /* length of ASC or DESC */ + +/* Enumerated sorting metrics */ +typedef enum GSortField_ { + SORT_BY_HITS, + SORT_BY_VISITORS, + SORT_BY_DATA, + SORT_BY_BW, + SORT_BY_AVGTS, + SORT_BY_CUMTS, + SORT_BY_MAXTS, + SORT_BY_PROT, + SORT_BY_MTHD, +} GSortField; + +/* Enumerated sorting order */ +typedef enum GSortOrder_ { + SORT_ASC, + SORT_DESC +} GSortOrder; + +/* Sorting of each panel, metric and order */ +typedef struct GSort_ { + GModule module; + GSortField field; + GSortOrder sort; +} GSort; + +extern GSort module_sort[TOTAL_MODULES]; +extern const int sort_choices[][SORT_MAX_OPTS]; + +GRawData *sort_raw_num_data (GRawData * raw_data, int ht_size); +GRawData *sort_raw_str_data (GRawData * raw_data, int ht_size); +const char *get_sort_field_key (GSortField field); +const char *get_sort_field_str (GSortField field); +const char *get_sort_order_str (GSortOrder order); +int can_sort_module (GModule module, int field); +int get_sort_field_enum (const char *str); +int get_sort_order_enum (const char *str); +int strcmp_asc (const void *a, const void *b); +int cmp_ui32_asc (const void *a, const void *b); +int cmp_ui32_desc (const void *a, const void *b); +void parse_initial_sort (void); +void set_initial_sort (const char *smod, const char *sfield, const char *ssort); +void sort_holder_items (GHolderItem * items, int size, GSort sort); + +#endif diff --git a/src/tpl.c b/src/tpl.c new file mode 100644 index 0000000000..fd6dfb5a3b --- /dev/null +++ b/src/tpl.c @@ -0,0 +1,2676 @@ +/* +Copyright (c) 2005-2013, Troy D. Hanson http://troydhanson.github.com/tpl/ +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#define TPL_VERSION 1.6 + +/*static const char id[]="$Id: tpl.c 192 2009-04-24 10:35:30Z thanson $";*/ + + +#include /* malloc */ +#include /* va_list */ +#include /* memcpy, memset, strchr */ +#include /* printf (tpl_hook.oops default function) */ + +#ifndef _WIN32 +#include /* for ftruncate */ +#else +#include +#define ftruncate(x,y) _chsize(x,y) +#endif +#include /* for 'open' */ +#include /* for 'open' */ +#include +#ifndef _WIN32 +#include /* uint32_t, uint64_t, etc */ +#else +typedef unsigned short ushort; +typedef __int16 int16_t; +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; +#endif + +#ifndef S_ISREG +#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) +#endif + +#if ( defined __CYGWIN__ || defined __MINGW32__ || defined _WIN32 ) +#include "win/mman.h" /* mmap */ +#else +#include /* mmap */ +#endif + +#include "tpl.h" + +#define TPL_GATHER_BUFLEN 8192 +#define TPL_MAGIC "tpl" + +/* macro to add a structure to a doubly-linked list */ +#define DL_ADD(head,add) \ + do { \ + if (head) { \ + (add)->prev = (head)->prev; \ + (head)->prev->next = (add); \ + (head)->prev = (add); \ + (add)->next = NULL; \ + } else { \ + (head)=(add); \ + (head)->prev = (head); \ + (head)->next = NULL; \ + } \ + } while (0); + +#define fatal_oom() tpl_hook.fatal("out of memory\n") + +/* bit flags (internal). preceded by the external flags in tpl.h */ +#define TPL_WRONLY (1 << 9) /* app has initiated tpl packing */ +#define TPL_RDONLY (1 << 10) /* tpl was loaded (for unpacking) */ +#define TPL_XENDIAN (1 << 11) /* swap endianness when unpacking */ +#define TPL_OLD_STRING_FMT (1 << 12) /* tpl has strings in 1.2 format */ + +/* values for the flags byte that appears after the magic prefix */ +#define TPL_SUPPORTED_BITFLAGS 3 +#define TPL_FL_BIGENDIAN (1 << 0) +#define TPL_FL_NULLSTRINGS (1 << 1) + +/* char values for node type */ +#define TPL_TYPE_ROOT 0 +#define TPL_TYPE_INT32 1 +#define TPL_TYPE_UINT32 2 +#define TPL_TYPE_BYTE 3 +#define TPL_TYPE_STR 4 +#define TPL_TYPE_ARY 5 +#define TPL_TYPE_BIN 6 +#define TPL_TYPE_DOUBLE 7 +#define TPL_TYPE_INT64 8 +#define TPL_TYPE_UINT64 9 +#define TPL_TYPE_INT16 10 +#define TPL_TYPE_UINT16 11 +#define TPL_TYPE_POUND 12 + +/* error codes */ +#define ERR_NOT_MINSIZE (-1) +#define ERR_MAGIC_MISMATCH (-2) +#define ERR_INCONSISTENT_SZ (-3) +#define ERR_FMT_INVALID (-4) +#define ERR_FMT_MISSING_NUL (-5) +#define ERR_FMT_MISMATCH (-6) +#define ERR_FLEN_MISMATCH (-7) +#define ERR_INCONSISTENT_SZ2 (-8) +#define ERR_INCONSISTENT_SZ3 (-9) +#define ERR_INCONSISTENT_SZ4 (-10) +#define ERR_UNSUPPORTED_FLAGS (-11) + +/* access to A(...) nodes by index */ +typedef struct tpl_pidx { + struct tpl_node *node; + struct tpl_pidx *next, *prev; +} tpl_pidx; + +/* A(...) node datum */ +typedef struct tpl_atyp { + uint32_t num; /* num elements */ + size_t sz; /* size of each backbone's datum */ + struct tpl_backbone *bb, *bbtail; + void *cur; +} tpl_atyp; + +/* backbone to extend A(...) lists dynamically */ +typedef struct tpl_backbone { + struct tpl_backbone *next; + /* when this structure is malloc'd, extra space is alloc'd at the + * end to store the backbone "datum", and data points to it. */ +#if __STDC_VERSION__ < 199901 + char *data; +#else + char data[]; +#endif +} tpl_backbone; + +/* mmap record */ +typedef struct tpl_mmap_rec { + int fd; + void *text; + size_t text_sz; +} tpl_mmap_rec; + +/* root node datum */ +typedef struct tpl_root_data { + int flags; + tpl_pidx *pidx; + tpl_mmap_rec mmap; + char *fmt; + int *fxlens, num_fxlens; +} tpl_root_data; + +/* node type to size mapping */ +struct tpl_type_t { + char c; + int sz; +}; + + +/* Internal prototypes */ +static tpl_node *tpl_node_new (tpl_node * parent); +static tpl_node *tpl_find_i (tpl_node * n, int i); +static void *tpl_cpv (void *datav, const void *data, size_t sz); +static void *tpl_extend_backbone (tpl_node * n); +static char *tpl_fmt (tpl_node * r); +static void *tpl_dump_atyp (tpl_node * n, tpl_atyp * at, void *dv); +static size_t tpl_ser_osz (tpl_node * n); +static void tpl_free_atyp (tpl_node * n, tpl_atyp * atyp); +static int tpl_dump_to_mem (tpl_node * r, void *addr, size_t sz); +static int tpl_mmap_file (char *filename, tpl_mmap_rec * map_rec); +static int tpl_mmap_output_file (char *filename, size_t sz, void **text_out); +static int tpl_cpu_bigendian (void); +static int tpl_needs_endian_swap (void *); +static void tpl_byteswap (void *word, int len); +static void tpl_fatal (const char *fmt, ...) + __attribute__((__format__ (printf, 1, 2))) __attribute__((__noreturn__)); +static int tpl_serlen (tpl_node * r, tpl_node * n, void *dv, size_t *serlen); +static int tpl_unpackA0 (tpl_node * r); +static int tpl_oops (const char *fmt, ...) + __attribute__((__format__ (printf, 1, 2))); +static int tpl_gather_mem (char *buf, size_t len, tpl_gather_t ** gs, + tpl_gather_cb * cb, void *data); +static int tpl_gather_nonblocking (int fd, tpl_gather_t ** gs, tpl_gather_cb * cb, void *data); +static int tpl_gather_blocking (int fd, void **img, size_t *sz); + +/* This is used internally to help calculate padding when a 'double' + * follows a smaller datatype in a structure. Normally under gcc + * on x86, d will be aligned at +4, however use of -malign-double + * causes d to be aligned at +8 (this is actually faster on x86). + * Also SPARC and x86_64 seem to align always on +8. + */ +struct tpl_double_alignment_detector { + char a; + double d; /* some platforms align this on +4, others on +8 */ +}; + +/* this is another case where alignment varies. mac os x/gcc was observed + * to align the int64_t at +4 under -m32 and at +8 under -m64 */ +struct tpl_int64_alignment_detector { + int i; + int64_t j; /* some platforms align this on +4, others on +8 */ +}; + +typedef struct { + size_t inter_elt_len; /* padded inter-element len; i.e. &a[1].field - &a[0].field */ + tpl_node *iter_start_node; /* node to jump back to, as we start each new iteration */ + size_t iternum; /* current iteration number (total req'd. iter's in n->num) */ +} tpl_pound_data; + +/* Hooks for customizing tpl mem alloc, error handling, etc. Set defaults. */ +tpl_hook_t tpl_hook = { + /* .oops = */ tpl_oops, + /* .malloc = */ malloc, + /* .realloc = */ realloc, + /* .free = */ free, + /* .fatal = */ tpl_fatal, + /* .gather_max = */ 0 + /* max tpl size (bytes) for tpl_gather */ +}; + +static const char tpl_fmt_chars[] = "AS($)BiucsfIUjv#"; /* valid format chars */ +/* valid within S(...) */ +/* static const char tpl_S_fmt_chars[] = "iucsfIUjv#$()"; */ +static const char tpl_datapeek_ok_chars[] = "iucsfIUjv"; /* valid in datapeek */ +static const struct tpl_type_t tpl_types[] = { + /* [TPL_TYPE_ROOT] = */ {'r', 0}, + /* [TPL_TYPE_INT32] = */ {'i', sizeof (int32_t)}, + /* [TPL_TYPE_UINT32] = */ {'u', sizeof (uint32_t)}, + /* [TPL_TYPE_BYTE] = */ {'c', sizeof (char)}, + /* [TPL_TYPE_STR] = */ {'s', sizeof (char *)}, + /* [TPL_TYPE_ARY] = */ {'A', 0}, + /* [TPL_TYPE_BIN] = */ {'B', 0}, + /* [TPL_TYPE_DOUBLE] = */ {'f', 8}, + /* not sizeof(double) as that varies */ + /* [TPL_TYPE_INT64] = */ {'I', sizeof (int64_t)}, + /* [TPL_TYPE_UINT64] = */ {'U', sizeof (uint64_t)}, + /* [TPL_TYPE_INT16] = */ {'j', sizeof (int16_t)}, + /* [TPL_TYPE_UINT16] = */ {'v', sizeof (uint16_t)}, + /* [TPL_TYPE_POUND] = */ {'#', 0}, +}; + +/* default error-reporting function. Just writes to stderr. */ +static int +tpl_oops (const char *fmt, ...) { + va_list ap; + va_start (ap, fmt); + vfprintf (stderr, fmt, ap); + va_end (ap); + return 0; +} + + +static tpl_node * +tpl_node_new (tpl_node *parent) { + tpl_node *n; + if ((n = tpl_hook.malloc (sizeof (tpl_node))) == NULL) { + fatal_oom (); + } + n->addr = NULL; + n->data = NULL; + n->num = 1; + n->ser_osz = 0; + n->children = NULL; + n->next = NULL; + n->parent = parent; + return n; +} + +/* Used in S(..) formats to pack several fields from a structure based on + * only the structure address. We need to calculate field addresses + * manually taking into account the size of the fields and intervening padding. + * The wrinkle is that double is not normally aligned on x86-32 but the + * -malign-double compiler option causes it to be. Double are aligned + * on Sparc, and apparently on 64 bit x86. We use a helper structure + * to detect whether double is aligned in this compilation environment. + */ +static char * +calc_field_addr (tpl_node *parent, int type, char *struct_addr, int ordinal) { + tpl_node *prev; + int offset; + int align_sz; + + if (ordinal == 1) + return struct_addr; /* first field starts on structure address */ + + /* generate enough padding so field addr is divisible by it's align_sz. 4, 8, etc */ + prev = parent->children->prev; + switch (type) { + case TPL_TYPE_DOUBLE: + align_sz = sizeof (struct tpl_double_alignment_detector) > 12 ? 8 : 4; + break; + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + align_sz = sizeof (struct tpl_int64_alignment_detector) > 12 ? 8 : 4; + break; + default: + align_sz = tpl_types[type].sz; + break; + } + offset = ((uintptr_t) prev->addr - (uintptr_t) struct_addr) + + (tpl_types[prev->type].sz * prev->num); + offset = (offset + align_sz - 1) / align_sz * align_sz; + return struct_addr + offset; +} + +TPL_API tpl_node * +tpl_map (char *fmt, ...) { + va_list ap; + tpl_node *tn; + + va_start (ap, fmt); + tn = tpl_map_va (fmt, ap); + va_end (ap); + return tn; +} + +TPL_API tpl_node * +tpl_map_va (char *fmt, va_list ap) { + int lparen_level = 0, expect_lparen = 0, t = 0, in_structure = 0, ordinal = 0; + int in_nested_structure = 0; + char *c, *peek, *struct_addr = NULL, *struct_next; + tpl_node *root, *parent, *n = NULL, *preceding, *iter_start_node = NULL, + *struct_widest_node = NULL, *np; + tpl_pidx *pidx; + tpl_pound_data *pd; + int *fxlens, num_fxlens, pound_num, pound_prod, applies_to_struct; + int contig_fxlens[10]; /* temp space for contiguous fxlens */ + uint32_t num_contig_fxlens; + uint32_t i; + int j; + ptrdiff_t inter_elt_len = 0; /* padded element length of contiguous structs in array */ + + + root = tpl_node_new (NULL); + root->type = TPL_TYPE_ROOT; + root->data = (tpl_root_data *) tpl_hook.malloc (sizeof (tpl_root_data)); + if (!root->data) + fatal_oom (); + memset ((tpl_root_data *) root->data, 0, sizeof (tpl_root_data)); + + /* set up root nodes special ser_osz to reflect overhead of preamble */ + root->ser_osz = sizeof (uint32_t); /* tpl leading length */ + root->ser_osz += strlen (fmt) + 1; /* fmt + NUL-terminator */ + root->ser_osz += 4; /* 'tpl' magic prefix + flags byte */ + + parent = root; + + c = fmt; + while (*c != '\0') { + switch (*c) { + case 'c': + case 'i': + case 'u': + case 'j': + case 'v': + case 'I': + case 'U': + case 'f': + if (*c == 'c') + t = TPL_TYPE_BYTE; + else if (*c == 'i') + t = TPL_TYPE_INT32; + else if (*c == 'u') + t = TPL_TYPE_UINT32; + else if (*c == 'j') + t = TPL_TYPE_INT16; + else if (*c == 'v') + t = TPL_TYPE_UINT16; + else if (*c == 'I') + t = TPL_TYPE_INT64; + else if (*c == 'U') + t = TPL_TYPE_UINT64; + else if (*c == 'f') + t = TPL_TYPE_DOUBLE; + + if (expect_lparen) + goto fail; + n = tpl_node_new (parent); + n->type = t; + if (in_structure) { + if (ordinal == 1) { + /* for S(...)# iteration. Apply any changes to case 's' too!!! */ + iter_start_node = n; + struct_widest_node = n; + } + if (tpl_types[n->type].sz > tpl_types[struct_widest_node->type].sz) { + struct_widest_node = n; + } + n->addr = calc_field_addr (parent, n->type, struct_addr, ordinal++); + } else + n->addr = (void *) va_arg (ap, void *); + n->data = tpl_hook.malloc (tpl_types[t].sz); + if (!n->data) + fatal_oom (); + if (n->parent->type == TPL_TYPE_ARY) + ((tpl_atyp *) (n->parent->data))->sz += tpl_types[t].sz; + DL_ADD (parent->children, n); + break; + case 's': + if (expect_lparen) + goto fail; + n = tpl_node_new (parent); + n->type = TPL_TYPE_STR; + if (in_structure) { + if (ordinal == 1) { + iter_start_node = n; /* for S(...)# iteration */ + struct_widest_node = n; + } + if (tpl_types[n->type].sz > tpl_types[struct_widest_node->type].sz) { + struct_widest_node = n; + } + n->addr = calc_field_addr (parent, n->type, struct_addr, ordinal++); + } else + n->addr = (void *) va_arg (ap, void *); + n->data = tpl_hook.malloc (sizeof (char *)); + if (!n->data) + fatal_oom (); + *(char **) (n->data) = NULL; + if (n->parent->type == TPL_TYPE_ARY) + ((tpl_atyp *) (n->parent->data))->sz += sizeof (void *); + DL_ADD (parent->children, n); + break; + case '#': + /* apply a 'num' to preceding atom */ + if (!parent->children) + goto fail; + preceding = parent->children->prev; /* first child's prev is 'last child' */ + t = preceding->type; + applies_to_struct = (*(c - 1) == ')') ? 1 : 0; + if (!applies_to_struct) { + if (!(t == TPL_TYPE_BYTE || t == TPL_TYPE_INT32 || + t == TPL_TYPE_UINT32 || t == TPL_TYPE_DOUBLE || + t == TPL_TYPE_UINT64 || t == TPL_TYPE_INT64 || + t == TPL_TYPE_UINT16 || t == TPL_TYPE_INT16 || t == TPL_TYPE_STR)) + goto fail; + } + /* count up how many contiguous # and form their product */ + pound_prod = 1; + num_contig_fxlens = 0; + for (peek = c; *peek == '#'; peek++) { + pound_num = va_arg (ap, int); + if (pound_num < 1) { + tpl_hook.fatal ("non-positive iteration count %d\n", pound_num); + } + if (num_contig_fxlens >= (sizeof (contig_fxlens) / sizeof (contig_fxlens[0]))) { + tpl_hook.fatal ("contiguous # exceeds hardcoded limit\n"); + } + contig_fxlens[num_contig_fxlens++] = pound_num; + pound_prod *= pound_num; + } + /* increment c to skip contiguous # so its points to last one */ + c = peek - 1; + /* differentiate atom-# from struct-# by noting preceding rparen */ + if (applies_to_struct) { /* insert # node to induce looping */ + n = tpl_node_new (parent); + n->type = TPL_TYPE_POUND; + n->num = pound_prod; + n->data = tpl_hook.malloc (sizeof (tpl_pound_data)); + if (!n->data) + fatal_oom (); + pd = (tpl_pound_data *) n->data; + pd->inter_elt_len = inter_elt_len; + pd->iter_start_node = iter_start_node; + pd->iternum = 0; + DL_ADD (parent->children, n); + /* multiply the 'num' and data space on each atom in the structure */ + for (np = iter_start_node; np != n; np = np->next) { + if (n->parent->type == TPL_TYPE_ARY) { + ((tpl_atyp *) (n->parent->data))->sz += + tpl_types[np->type].sz * (np->num * (n->num - 1)); + } + np->data = tpl_hook.realloc (np->data, tpl_types[np->type].sz * np->num * n->num); + if (!np->data) + fatal_oom (); + memset (np->data, 0, tpl_types[np->type].sz * np->num * n->num); + } + } else { /* simple atom-# form does not require a loop */ + preceding->num = pound_prod; + preceding->data = tpl_hook.realloc (preceding->data, tpl_types[t].sz * preceding->num); + if (!preceding->data) + fatal_oom (); + memset (preceding->data, 0, tpl_types[t].sz * preceding->num); + if (n->parent->type == TPL_TYPE_ARY) { + ((tpl_atyp *) (n->parent->data))->sz += tpl_types[t].sz * (preceding->num - 1); + } + } + root->ser_osz += (sizeof (uint32_t) * num_contig_fxlens); + + j = ((tpl_root_data *) root->data)->num_fxlens; /* before incrementing */ + (((tpl_root_data *) root->data)->num_fxlens) += num_contig_fxlens; + num_fxlens = ((tpl_root_data *) root->data)->num_fxlens; /* new value */ + fxlens = ((tpl_root_data *) root->data)->fxlens; + fxlens = tpl_hook.realloc (fxlens, sizeof (int) * num_fxlens); + if (!fxlens) + fatal_oom (); + ((tpl_root_data *) root->data)->fxlens = fxlens; + for (i = 0; i < num_contig_fxlens; i++) + fxlens[j++] = contig_fxlens[i]; + + break; + case 'B': + if (expect_lparen) + goto fail; + if (in_structure) + goto fail; + n = tpl_node_new (parent); + n->type = TPL_TYPE_BIN; + n->addr = (tpl_bin *) va_arg (ap, void *); + n->data = tpl_hook.malloc (sizeof (tpl_bin *)); + if (!n->data) + fatal_oom (); + *((tpl_bin **) n->data) = NULL; + if (n->parent->type == TPL_TYPE_ARY) + ((tpl_atyp *) (n->parent->data))->sz += sizeof (tpl_bin); + DL_ADD (parent->children, n); + break; + case 'A': + if (in_structure) + goto fail; + n = tpl_node_new (parent); + n->type = TPL_TYPE_ARY; + DL_ADD (parent->children, n); + parent = n; + expect_lparen = 1; + pidx = (tpl_pidx *) tpl_hook.malloc (sizeof (tpl_pidx)); + if (!pidx) + fatal_oom (); + pidx->node = n; + pidx->next = NULL; + DL_ADD (((tpl_root_data *) (root->data))->pidx, pidx); + /* set up the A's tpl_atyp */ + n->data = (tpl_atyp *) tpl_hook.malloc (sizeof (tpl_atyp)); + if (!n->data) + fatal_oom (); + ((tpl_atyp *) (n->data))->num = 0; + ((tpl_atyp *) (n->data))->sz = 0; + ((tpl_atyp *) (n->data))->bb = NULL; + ((tpl_atyp *) (n->data))->bbtail = NULL; + ((tpl_atyp *) (n->data))->cur = NULL; + if (n->parent->type == TPL_TYPE_ARY) + ((tpl_atyp *) (n->parent->data))->sz += sizeof (void *); + break; + case 'S': + if (in_structure) + goto fail; + expect_lparen = 1; + ordinal = 1; /* index upcoming atoms in S(..) */ + in_structure = 1 + lparen_level; /* so we can tell where S fmt ends */ + struct_addr = (char *) va_arg (ap, void *); + break; + case '$': /* nested structure */ + if (!in_structure) + goto fail; + expect_lparen = 1; + in_nested_structure++; + break; + case ')': + lparen_level--; + if (lparen_level < 0) + goto fail; + if (*(c - 1) == '(') + goto fail; + if (in_nested_structure) + in_nested_structure--; + else if (in_structure && (in_structure - 1 == lparen_level)) { + /* calculate delta between contiguous structures in array */ + struct_next = calc_field_addr (parent, struct_widest_node->type, struct_addr, ordinal++); + inter_elt_len = struct_next - struct_addr; + in_structure = 0; + } else + parent = parent->parent; /* rparen ends A() type, not S() type */ + break; + case '(': + if (!expect_lparen) + goto fail; + expect_lparen = 0; + lparen_level++; + break; + default: + tpl_hook.oops ("unsupported option %c\n", *c); + goto fail; + } + c++; + } + if (lparen_level != 0) + goto fail; + + /* copy the format string, save for convenience */ + ((tpl_root_data *) (root->data))->fmt = tpl_hook.malloc (strlen (fmt) + 1); + if (((tpl_root_data *) (root->data))->fmt == NULL) + fatal_oom (); + memcpy (((tpl_root_data *) (root->data))->fmt, fmt, strlen (fmt) + 1); + + return root; + +fail: + tpl_hook.oops ("failed to parse %s\n", fmt); + tpl_free (root); + return NULL; +} + +static int +tpl_unmap_file (tpl_mmap_rec *mr) { + + if (munmap (mr->text, mr->text_sz) == -1) { + tpl_hook.oops ("Failed to munmap: %s\n", strerror (errno)); + } + close (mr->fd); + mr->text = NULL; + mr->text_sz = 0; + return 0; +} + +static void +tpl_free_keep_map (tpl_node *r) { + int mmap_bits = (TPL_RDONLY | TPL_FILE); + int ufree_bits = (TPL_MEM | TPL_UFREE); + tpl_node *nxtc, *c; + int find_next_node = 0, looking, i; + size_t sz; + + /* For mmap'd files, or for 'ufree' memory images , do appropriate release */ + if ((((tpl_root_data *) (r->data))->flags & mmap_bits) == mmap_bits) { + tpl_unmap_file (&((tpl_root_data *) (r->data))->mmap); + } else if ((((tpl_root_data *) (r->data))->flags & ufree_bits) == ufree_bits) { + tpl_hook.free (((tpl_root_data *) (r->data))->mmap.text); + } + + c = r->children; + if (c) { + while (c->type != TPL_TYPE_ROOT) { /* loop until we come back to root node */ + switch (c->type) { + case TPL_TYPE_BIN: + /* free any binary buffer hanging from tpl_bin */ + if (*((tpl_bin **) (c->data))) { + if ((*((tpl_bin **) (c->data)))->addr) { + tpl_hook.free ((*((tpl_bin **) (c->data)))->addr); + } + *((tpl_bin **) c->data) = NULL; /* reset tpl_bin */ + } + find_next_node = 1; + break; + case TPL_TYPE_STR: + /* free any packed (copied) string */ + for (i = 0; i < c->num; i++) { + char *str = ((char **) c->data)[i]; + if (str) { + tpl_hook.free (str); + ((char **) c->data)[i] = NULL; + } + } + find_next_node = 1; + break; + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + case TPL_TYPE_POUND: + find_next_node = 1; + break; + case TPL_TYPE_ARY: + c->ser_osz = 0; /* zero out the serialization output size */ + + sz = ((tpl_atyp *) (c->data))->sz; /* save sz to use below */ + tpl_free_atyp (c, c->data); + + /* make new atyp */ + c->data = (tpl_atyp *) tpl_hook.malloc (sizeof (tpl_atyp)); + if (!c->data) + fatal_oom (); + ((tpl_atyp *) (c->data))->num = 0; + ((tpl_atyp *) (c->data))->sz = sz; /* restore bb datum sz */ + ((tpl_atyp *) (c->data))->bb = NULL; + ((tpl_atyp *) (c->data))->bbtail = NULL; + ((tpl_atyp *) (c->data))->cur = NULL; + + c = c->children; + break; + default: + tpl_hook.fatal ("unsupported format character\n"); + break; + } + + if (find_next_node) { + find_next_node = 0; + looking = 1; + while (looking) { + if (c->next) { + nxtc = c->next; + c = nxtc; + looking = 0; + } else { + if (c->type == TPL_TYPE_ROOT) + break; /* root node */ + else { + nxtc = c->parent; + c = nxtc; + } + } + } + } + } + } + + ((tpl_root_data *) (r->data))->flags = 0; /* reset flags */ +} + +TPL_API void +tpl_free (tpl_node *r) { + int mmap_bits = (TPL_RDONLY | TPL_FILE); + int ufree_bits = (TPL_MEM | TPL_UFREE); + tpl_node *nxtc, *c; + int find_next_node = 0, looking, num, i; + tpl_pidx *pidx, *pidx_nxt; + + /* For mmap'd files, or for 'ufree' memory images , do appropriate release */ + if ((((tpl_root_data *) (r->data))->flags & mmap_bits) == mmap_bits) { + tpl_unmap_file (&((tpl_root_data *) (r->data))->mmap); + } else if ((((tpl_root_data *) (r->data))->flags & ufree_bits) == ufree_bits) { + tpl_hook.free (((tpl_root_data *) (r->data))->mmap.text); + } + + c = r->children; + if (c) { + while (c->type != TPL_TYPE_ROOT) { /* loop until we come back to root node */ + switch (c->type) { + case TPL_TYPE_BIN: + /* free any binary buffer hanging from tpl_bin */ + if (*((tpl_bin **) (c->data))) { + if ((*((tpl_bin **) (c->data)))->sz != 0) { + tpl_hook.free ((*((tpl_bin **) (c->data)))->addr); + } + tpl_hook.free (*((tpl_bin **) c->data)); /* free tpl_bin */ + } + tpl_hook.free (c->data); /* free tpl_bin* */ + find_next_node = 1; + break; + case TPL_TYPE_STR: + /* free any packed (copied) string */ + num = 1; + nxtc = c->next; + while (nxtc) { + if (nxtc->type == TPL_TYPE_POUND) { + num = nxtc->num; + } + nxtc = nxtc->next; + } + for (i = 0; i < c->num * num; i++) { + char *str = ((char **) c->data)[i]; + if (str) { + tpl_hook.free (str); + ((char **) c->data)[i] = NULL; + } + } + tpl_hook.free (c->data); + find_next_node = 1; + break; + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + case TPL_TYPE_POUND: + tpl_hook.free (c->data); + find_next_node = 1; + break; + case TPL_TYPE_ARY: + tpl_free_atyp (c, c->data); + if (c->children) + c = c->children; /* normal case */ + else + find_next_node = 1; /* edge case, handle bad format A() */ + break; + default: + tpl_hook.fatal ("unsupported format character\n"); + break; + } + + if (find_next_node) { + find_next_node = 0; + looking = 1; + while (looking) { + if (c->next) { + nxtc = c->next; + tpl_hook.free (c); + c = nxtc; + looking = 0; + } else { + if (c->type == TPL_TYPE_ROOT) + break; /* root node */ + else { + nxtc = c->parent; + tpl_hook.free (c); + c = nxtc; + } + } + } + } + } + } + + /* free root */ + for (pidx = ((tpl_root_data *) (r->data))->pidx; pidx; pidx = pidx_nxt) { + pidx_nxt = pidx->next; + tpl_hook.free (pidx); + } + tpl_hook.free (((tpl_root_data *) (r->data))->fmt); + if (((tpl_root_data *) (r->data))->num_fxlens > 0) { + tpl_hook.free (((tpl_root_data *) (r->data))->fxlens); + } + tpl_hook.free (r->data); /* tpl_root_data */ + tpl_hook.free (r); +} + + +/* Find the i'th packable ('A' node) */ +static tpl_node * +tpl_find_i (tpl_node *n, int i) { + int j = 0; + tpl_pidx *pidx; + if (n->type != TPL_TYPE_ROOT) + return NULL; + if (i == 0) + return n; /* packable 0 is root */ + for (pidx = ((tpl_root_data *) (n->data))->pidx; pidx; pidx = pidx->next) { + if (++j == i) + return pidx->node; + } + return NULL; +} + +static void * +tpl_cpv (void *datav, const void *data, size_t sz) { + if (sz > 0) + memcpy (datav, data, sz); + return (void *) ((uintptr_t) datav + sz); +} + +static void * +tpl_extend_backbone (tpl_node *n) { + tpl_backbone *bb; + bb = (tpl_backbone *) tpl_hook.malloc (sizeof (tpl_backbone) + ((tpl_atyp *) (n->data))->sz); /* datum hangs on coattails of bb */ + if (!bb) + fatal_oom (); +#if __STDC_VERSION__ < 199901 + bb->data = (char *) ((uintptr_t) bb + sizeof (tpl_backbone)); +#endif + memset (bb->data, 0, ((tpl_atyp *) (n->data))->sz); + bb->next = NULL; + /* Add the new backbone to the tail, also setting head if necessary */ + if (((tpl_atyp *) (n->data))->bb == NULL) { + ((tpl_atyp *) (n->data))->bb = bb; + ((tpl_atyp *) (n->data))->bbtail = bb; + } else { + ((tpl_atyp *) (n->data))->bbtail->next = bb; + ((tpl_atyp *) (n->data))->bbtail = bb; + } + + ((tpl_atyp *) (n->data))->num++; + return bb->data; +} + +/* Get the format string corresponding to a given tpl (root node) */ +static char * +tpl_fmt (tpl_node *r) { + return ((tpl_root_data *) (r->data))->fmt; +} + +/* Get the fmt # lengths as a contiguous buffer of ints (length num_fxlens) */ +static int * +tpl_fxlens (tpl_node *r, int *num_fxlens) { + *num_fxlens = ((tpl_root_data *) (r->data))->num_fxlens; + return ((tpl_root_data *) (r->data))->fxlens; +} + +/* called when serializing an 'A' type node into a buffer which has + * already been set up with the proper space. The backbone is walked + * which was obtained from the tpl_atyp header passed in. + */ +static void * +tpl_dump_atyp (tpl_node *n, tpl_atyp *at, void *dv) { + tpl_backbone *bb; + tpl_node *c; + void *datav; + uint32_t slen; + tpl_bin *binp; + char *strp; + tpl_atyp *atypp; + tpl_pound_data *pd; + int i; + size_t itermax; + + /* handle 'A' nodes */ + dv = tpl_cpv (dv, &at->num, sizeof (uint32_t)); /* array len */ + for (bb = at->bb; bb; bb = bb->next) { + datav = bb->data; + c = n->children; + while (c) { + switch (c->type) { + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + dv = tpl_cpv (dv, datav, tpl_types[c->type].sz * c->num); + datav = (void *) ((uintptr_t) datav + tpl_types[c->type].sz * c->num); + break; + case TPL_TYPE_BIN: + /* dump the buffer length followed by the buffer */ + memcpy (&binp, datav, sizeof (tpl_bin *)); /* cp to aligned */ + slen = binp->sz; + dv = tpl_cpv (dv, &slen, sizeof (uint32_t)); + dv = tpl_cpv (dv, binp->addr, slen); + datav = (void *) ((uintptr_t) datav + sizeof (tpl_bin *)); + break; + case TPL_TYPE_STR: + /* dump the string length followed by the string */ + for (i = 0; i < c->num; i++) { + memcpy (&strp, datav, sizeof (char *)); /* cp to aligned */ + slen = strp ? (strlen (strp) + 1) : 0; + dv = tpl_cpv (dv, &slen, sizeof (uint32_t)); + if (slen > 1) + dv = tpl_cpv (dv, strp, slen - 1); + datav = (void *) ((uintptr_t) datav + sizeof (char *)); + } + break; + case TPL_TYPE_ARY: + memcpy (&atypp, datav, sizeof (tpl_atyp *)); /* cp to aligned */ + dv = tpl_dump_atyp (c, atypp, dv); + datav = (void *) ((uintptr_t) datav + sizeof (void *)); + break; + case TPL_TYPE_POUND: + /* iterate over the preceding nodes */ + pd = (tpl_pound_data *) c->data; + itermax = c->num; + if (++(pd->iternum) < itermax) { + c = pd->iter_start_node; + continue; + } else { /* loop complete. */ + pd->iternum = 0; + } + break; + default: + tpl_hook.fatal ("unsupported format character\n"); + break; + } + c = c->next; + } + } + return dv; +} + +/* figure the serialization output size needed for tpl whose root is n*/ +static size_t +tpl_ser_osz (tpl_node *n) { + tpl_node *c, *np; + size_t sz, itermax; + tpl_bin *binp; + char *strp; + tpl_pound_data *pd; + int i; + + /* handle the root node ONLY (subtree's ser_osz have been bubbled-up) */ + if (n->type != TPL_TYPE_ROOT) { + tpl_hook.fatal ("internal error: tpl_ser_osz on non-root node\n"); + } + + sz = n->ser_osz; /* start with fixed overhead, already stored */ + c = n->children; + while (c) { + switch (c->type) { + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + sz += tpl_types[c->type].sz * c->num; + break; + case TPL_TYPE_BIN: + sz += sizeof (uint32_t); /* binary buf len */ + memcpy (&binp, c->data, sizeof (tpl_bin *)); /* cp to aligned */ + sz += binp->sz; + break; + case TPL_TYPE_STR: + for (i = 0; i < c->num; i++) { + sz += sizeof (uint32_t); /* string len */ + memcpy (&strp, &((char **) c->data)[i], sizeof (char *)); /* cp to aligned */ + sz += strp ? strlen (strp) : 0; + } + break; + case TPL_TYPE_ARY: + sz += sizeof (uint32_t); /* array len */ + sz += c->ser_osz; /* bubbled-up child array ser_osz */ + break; + case TPL_TYPE_POUND: + /* iterate over the preceding nodes */ + itermax = c->num; + pd = (tpl_pound_data *) c->data; + if (++(pd->iternum) < itermax) { + for (np = pd->iter_start_node; np != c; np = np->next) { + np->data = (char *) (np->data) + (tpl_types[np->type].sz * np->num); + } + c = pd->iter_start_node; + continue; + } else { /* loop complete. */ + pd->iternum = 0; + for (np = pd->iter_start_node; np != c; np = np->next) { + np->data = (char *) (np->data) - ((itermax - 1) * tpl_types[np->type].sz * np->num); + } + } + break; + default: + tpl_hook.fatal ("unsupported format character\n"); + break; + } + c = c->next; + } + return sz; +} + + +TPL_API int +tpl_dump (tpl_node *r, int mode, ...) { + va_list ap; + char *filename, *bufv; + void **addr_out, *buf, *pa_addr; + int fd, rc = 0; + size_t sz, *sz_out, pa_sz; + struct stat sbuf; + + if (((tpl_root_data *) (r->data))->flags & TPL_RDONLY) { /* unusual */ + tpl_hook.oops ("error: tpl_dump called for a loaded tpl\n"); + return -1; + } + + sz = tpl_ser_osz (r); /* compute the size needed to serialize */ + + va_start (ap, mode); + if (mode & TPL_FILE) { + filename = va_arg (ap, char *); + fd = tpl_mmap_output_file (filename, sz, &buf); + if (fd == -1) + rc = -1; + else { + rc = tpl_dump_to_mem (r, buf, sz); + if (msync (buf, sz, MS_SYNC) == -1) { + tpl_hook.oops ("msync failed on fd %d: %s\n", fd, strerror (errno)); + } + if (munmap (buf, sz) == -1) { + tpl_hook.oops ("munmap failed on fd %d: %s\n", fd, strerror (errno)); + } + close (fd); + } + } else if (mode & TPL_FD) { + fd = va_arg (ap, int); + if ((buf = tpl_hook.malloc (sz)) == NULL) + fatal_oom (); + tpl_dump_to_mem (r, buf, sz); + bufv = buf; + do { + rc = write (fd, bufv, sz); + if (rc > 0) { + sz -= rc; + bufv += rc; + } else if (rc == -1) { + if (errno == EINTR || errno == EAGAIN) + continue; + tpl_hook.oops ("error writing to fd %d: %s\n", fd, strerror (errno)); + /* attempt to rewind partial write to a regular file */ + if (fstat (fd, &sbuf) == 0 && S_ISREG (sbuf.st_mode)) { + if (ftruncate (fd, sbuf.st_size - (bufv - (char *) buf)) == -1) { + tpl_hook.oops ("can't rewind: %s\n", strerror (errno)); + } + } + free (buf); + va_end (ap); + return -1; + } + } while (sz > 0); + free (buf); + rc = 0; + } else if (mode & TPL_MEM) { + if (mode & TPL_PREALLOCD) { /* caller allocated */ + pa_addr = (void *) va_arg (ap, void *); + pa_sz = va_arg (ap, size_t); + if (pa_sz < sz) { + tpl_hook.oops ("tpl_dump: buffer too small, need %zu bytes\n", sz); + va_end (ap); + return -1; + } + rc = tpl_dump_to_mem (r, pa_addr, sz); + } else { /* we allocate */ + addr_out = (void **) va_arg (ap, void *); + sz_out = va_arg (ap, size_t *); + if ((buf = tpl_hook.malloc (sz)) == NULL) + fatal_oom (); + *sz_out = sz; + *addr_out = buf; + rc = tpl_dump_to_mem (r, buf, sz); + } + } else if (mode & TPL_GETSIZE) { + sz_out = va_arg (ap, size_t *); + *sz_out = sz; + } else { + tpl_hook.oops ("unsupported tpl_dump mode %d\n", mode); + rc = -1; + } + va_end (ap); + return rc; +} + +/* This function expects the caller to have set up a memory buffer of + * adequate size to hold the serialized tpl. The sz parameter must be + * the result of tpl_ser_osz(r). + */ +static int +tpl_dump_to_mem (tpl_node *r, void *addr, size_t sz) { + uint32_t slen, sz32; + int *fxlens, num_fxlens, i; + void *dv; + char *fmt, flags; + tpl_node *c, *np; + tpl_pound_data *pd; + size_t itermax; + + fmt = tpl_fmt (r); + flags = 0; + if (tpl_cpu_bigendian ()) + flags |= TPL_FL_BIGENDIAN; + if (strchr (fmt, 's')) + flags |= TPL_FL_NULLSTRINGS; + sz32 = sz; + + dv = addr; + dv = tpl_cpv (dv, TPL_MAGIC, 3); /* copy tpl magic prefix */ + dv = tpl_cpv (dv, &flags, 1); /* copy flags byte */ + dv = tpl_cpv (dv, &sz32, sizeof (uint32_t)); /* overall length (inclusive) */ + dv = tpl_cpv (dv, fmt, strlen (fmt) + 1); /* copy format with NUL-term */ + fxlens = tpl_fxlens (r, &num_fxlens); + dv = tpl_cpv (dv, fxlens, num_fxlens * sizeof (uint32_t)); /* fmt # lengths */ + + /* serialize the tpl content, iterating over direct children of root */ + c = r->children; + while (c) { + switch (c->type) { + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + dv = tpl_cpv (dv, c->data, tpl_types[c->type].sz * c->num); + break; + case TPL_TYPE_BIN: + slen = (*(tpl_bin **) (c->data))->sz; + dv = tpl_cpv (dv, &slen, sizeof (uint32_t)); /* buffer len */ + dv = tpl_cpv (dv, (*(tpl_bin **) (c->data))->addr, slen); /* buf */ + break; + case TPL_TYPE_STR: + for (i = 0; i < c->num; i++) { + char *str = ((char **) c->data)[i]; + slen = str ? strlen (str) + 1 : 0; + dv = tpl_cpv (dv, &slen, sizeof (uint32_t)); /* string len */ + if (slen > 1) + dv = tpl_cpv (dv, str, slen - 1); /*string */ + } + break; + case TPL_TYPE_ARY: + dv = tpl_dump_atyp (c, (tpl_atyp *) c->data, dv); + break; + case TPL_TYPE_POUND: + pd = (tpl_pound_data *) c->data; + itermax = c->num; + if (++(pd->iternum) < itermax) { + + /* in start or midst of loop. advance data pointers. */ + for (np = pd->iter_start_node; np != c; np = np->next) { + np->data = (char *) (np->data) + (tpl_types[np->type].sz * np->num); + } + /* do next iteration */ + c = pd->iter_start_node; + continue; + + } else { /* loop complete. */ + + /* reset iteration index and addr/data pointers. */ + pd->iternum = 0; + for (np = pd->iter_start_node; np != c; np = np->next) { + np->data = (char *) (np->data) - ((itermax - 1) * tpl_types[np->type].sz * np->num); + } + + } + break; + default: + tpl_hook.fatal ("unsupported format character\n"); + break; + } + c = c->next; + } + + return 0; +} + +static int +tpl_cpu_bigendian (void) { + unsigned i = 1; + char *c; + c = (char *) &i; + return (c[0] == 1 ? 0 : 1); +} + + +/* + * algorithm for sanity-checking a tpl image: + * scan the tpl whilst not exceeding the buffer size (bufsz) , + * formulating a calculated (expected) size of the tpl based + * on walking its data. When calcsize has been calculated it + * should exactly match the buffer size (bufsz) and the internal + * recorded size (intlsz) + */ +static int +tpl_sanity (tpl_node *r, int excess_ok) { + uint32_t intlsz; + int found_nul = 0, rc, octothorpes = 0, num_fxlens, *fxlens, flen; + void *d, *dv; + char intlflags, *fmt, c, *mapfmt; + size_t bufsz, serlen; + + d = ((tpl_root_data *) (r->data))->mmap.text; + bufsz = ((tpl_root_data *) (r->data))->mmap.text_sz; + + dv = d; + if (bufsz < (4 + sizeof (uint32_t) + 1)) + return ERR_NOT_MINSIZE; /* min sz: magic+flags+len+nul */ + if (memcmp (dv, TPL_MAGIC, 3) != 0) + return ERR_MAGIC_MISMATCH; /* missing tpl magic prefix */ + if (tpl_needs_endian_swap (dv)) + ((tpl_root_data *) (r->data))->flags |= TPL_XENDIAN; + dv = (void *) ((uintptr_t) dv + 3); + memcpy (&intlflags, dv, sizeof (char)); /* extract flags */ + if (intlflags & ~TPL_SUPPORTED_BITFLAGS) + return ERR_UNSUPPORTED_FLAGS; + /* TPL1.3 stores strings with a "length+1" prefix to discern NULL strings from + empty strings from non-empty strings; TPL1.2 only handled the latter two. + So we need to be mindful of which string format we're reading from. */ + if (!(intlflags & TPL_FL_NULLSTRINGS)) { + ((tpl_root_data *) (r->data))->flags |= TPL_OLD_STRING_FMT; + } + dv = (void *) ((uintptr_t) dv + 1); + memcpy (&intlsz, dv, sizeof (uint32_t)); /* extract internal size */ + if (((tpl_root_data *) (r->data))->flags & TPL_XENDIAN) + tpl_byteswap (&intlsz, sizeof (uint32_t)); + if (!excess_ok && (intlsz != bufsz)) + return ERR_INCONSISTENT_SZ; /* inconsistent buffer/internal size */ + dv = (void *) ((uintptr_t) dv + sizeof (uint32_t)); + + /* dv points to the start of the format string. Look for nul w/in buf sz */ + fmt = (char *) dv; + while ((uintptr_t) dv - (uintptr_t) d < bufsz && !found_nul) { + if ((c = *(char *) dv) != '\0') { + if (strchr (tpl_fmt_chars, c) == NULL) + return ERR_FMT_INVALID; /* invalid char in format string */ + if ((c = *(char *) dv) == '#') + octothorpes++; + dv = (void *) ((uintptr_t) dv + 1); + } else + found_nul = 1; + } + if (!found_nul) + return ERR_FMT_MISSING_NUL; /* runaway format string */ + dv = (void *) ((uintptr_t) dv + 1); /* advance to octothorpe lengths buffer */ + + /* compare the map format to the format of this tpl image */ + mapfmt = tpl_fmt (r); + rc = strcmp (mapfmt, fmt); + if (rc != 0) + return ERR_FMT_MISMATCH; + + /* compare octothorpe lengths in image to the mapped values */ + if ((((uintptr_t) dv + (octothorpes * 4)) - (uintptr_t) d) > bufsz) + return ERR_INCONSISTENT_SZ4; + fxlens = tpl_fxlens (r, &num_fxlens); /* mapped fxlens */ + while (num_fxlens--) { + memcpy (&flen, dv, sizeof (uint32_t)); /* stored flen */ + if (((tpl_root_data *) (r->data))->flags & TPL_XENDIAN) + tpl_byteswap (&flen, sizeof (uint32_t)); + if (flen != *fxlens) + return ERR_FLEN_MISMATCH; + dv = (void *) ((uintptr_t) dv + sizeof (uint32_t)); + fxlens++; + } + + /* dv now points to beginning of data */ + rc = tpl_serlen (r, r, dv, &serlen); /* get computed serlen of data part */ + if (rc == -1) + return ERR_INCONSISTENT_SZ2; /* internal inconsistency in tpl image */ + serlen += ((uintptr_t) dv - (uintptr_t) d); /* add back serlen of preamble part */ + if (excess_ok && (bufsz < serlen)) + return ERR_INCONSISTENT_SZ3; + if (!excess_ok && (serlen != bufsz)) + return ERR_INCONSISTENT_SZ3; /* buffer/internal sz exceeds serlen */ + return 0; +} + +static void * +tpl_find_data_start (void *d) { + int octothorpes = 0; + d = (void *) ((uintptr_t) d + 4); /* skip TPL_MAGIC and flags byte */ + d = (void *) ((uintptr_t) d + 4); /* skip int32 overall len */ + while (*(char *) d != '\0') { + if (*(char *) d == '#') + octothorpes++; + d = (void *) ((uintptr_t) d + 1); + } + d = (void *) ((uintptr_t) d + 1); /* skip NUL */ + d = (void *) ((uintptr_t) d + (octothorpes * sizeof (uint32_t))); /* skip # array lens */ + return d; +} + +static int +tpl_needs_endian_swap (void *d) { + char *c; + int cpu_is_bigendian; + c = (char *) d; + cpu_is_bigendian = tpl_cpu_bigendian (); + return ((c[3] & TPL_FL_BIGENDIAN) == cpu_is_bigendian) ? 0 : 1; +} + +static size_t +tpl_size_for (char c) { + uint32_t i; + for (i = 0; i < sizeof (tpl_types) / sizeof (tpl_types[0]); i++) { + if (tpl_types[i].c == c) + return tpl_types[i].sz; + } + return 0; +} + +TPL_API char * +tpl_peek (int mode, ...) { + va_list ap; + int xendian = 0, found_nul = 0, old_string_format = 0; + char *filename = NULL, *datapeek_f = NULL, *datapeek_c, *datapeek_s; + void *addr = NULL, *dv, *datapeek_p = NULL; + size_t sz = 0, fmt_len, first_atom, num_fxlens = 0; + uint32_t datapeek_ssz, datapeek_csz, datapeek_flen; + tpl_mmap_rec mr = { 0, NULL, 0 }; + char *fmt, *fmt_cpy = NULL, c; + uint32_t intlsz, **fxlens = NULL, *num_fxlens_out = NULL, *fxlensv; + + va_start (ap, mode); + if ((mode & TPL_FXLENS) && (mode & TPL_DATAPEEK)) { + tpl_hook.oops ("TPL_FXLENS and TPL_DATAPEEK mutually exclusive\n"); + goto fail; + } + if (mode & TPL_FILE) + filename = va_arg (ap, char *); + else if (mode & TPL_MEM) { + addr = va_arg (ap, void *); + sz = va_arg (ap, size_t); + } else { + tpl_hook.oops ("unsupported tpl_peek mode %d\n", mode); + goto fail; + } + if (mode & TPL_DATAPEEK) { + datapeek_f = va_arg (ap, char *); + } + if (mode & TPL_FXLENS) { + num_fxlens_out = va_arg (ap, uint32_t *); + fxlens = va_arg (ap, uint32_t **); + *num_fxlens_out = 0; + *fxlens = NULL; + } + + if (mode & TPL_FILE) { + if (tpl_mmap_file (filename, &mr) != 0) { + tpl_hook.oops ("tpl_peek failed for file %s\n", filename); + goto fail; + } + addr = mr.text; + sz = mr.text_sz; + } + + dv = addr; + if (sz < (4 + sizeof (uint32_t) + 1)) + goto fail; /* min sz */ + if (memcmp (dv, TPL_MAGIC, 3) != 0) + goto fail; /* missing tpl magic prefix */ + if (tpl_needs_endian_swap (dv)) + xendian = 1; + if ((((char *) dv)[3] & TPL_FL_NULLSTRINGS) == 0) + old_string_format = 1; + dv = (void *) ((uintptr_t) dv + 4); + memcpy (&intlsz, dv, sizeof (uint32_t)); /* extract internal size */ + if (xendian) + tpl_byteswap (&intlsz, sizeof (uint32_t)); + if (intlsz != sz) + goto fail; /* inconsistent buffer/internal size */ + dv = (void *) ((uintptr_t) dv + sizeof (uint32_t)); + + /* dv points to the start of the format string. Look for nul w/in buf sz */ + fmt = (char *) dv; + while ((uintptr_t) dv - (uintptr_t) addr < sz && !found_nul) { + if ((c = *(char *) dv) == '\0') { + found_nul = 1; + } else if (c == '#') { + num_fxlens++; + } + dv = (void *) ((uintptr_t) dv + 1); + } + if (!found_nul) + goto fail; /* runaway format string */ + fmt_len = (char *) dv - fmt; /* include space for \0 */ + fmt_cpy = tpl_hook.malloc (fmt_len); + if (fmt_cpy == NULL) { + fatal_oom (); + } + memcpy (fmt_cpy, fmt, fmt_len); + + /* retrieve the octothorpic lengths if requested */ + if (num_fxlens > 0) { + if (sz < ((uintptr_t) dv + (num_fxlens * sizeof (uint32_t)) - (uintptr_t) addr)) { + goto fail; + } + } + if ((mode & TPL_FXLENS) && (num_fxlens > 0)) { + *fxlens = tpl_hook.malloc (num_fxlens * sizeof (uint32_t)); + if (*fxlens == NULL) + tpl_hook.fatal ("out of memory"); + *num_fxlens_out = num_fxlens; + fxlensv = *fxlens; + while (num_fxlens--) { + memcpy (fxlensv, dv, sizeof (uint32_t)); + if (xendian) + tpl_byteswap (fxlensv, sizeof (uint32_t)); + dv = (void *) ((uintptr_t) dv + sizeof (uint32_t)); + fxlensv++; + } + } + /* if caller requested, peek into the specified data elements */ + if (mode & TPL_DATAPEEK) { + + first_atom = strspn (fmt, "S()"); /* skip any leading S() */ + + datapeek_flen = strlen (datapeek_f); + if (strspn (datapeek_f, tpl_datapeek_ok_chars) < datapeek_flen) { + tpl_hook.oops ("invalid TPL_DATAPEEK format: %s\n", datapeek_f); + tpl_hook.free (fmt_cpy); + fmt_cpy = NULL; /* fail */ + goto fail; + } + + if (strncmp (&fmt[first_atom], datapeek_f, datapeek_flen) != 0) { + tpl_hook.oops ("TPL_DATAPEEK format mismatches tpl image\n"); + tpl_hook.free (fmt_cpy); + fmt_cpy = NULL; /* fail */ + goto fail; + } + + /* advance to data start, then copy out requested elements */ + dv = (void *) ((uintptr_t) dv + (num_fxlens * sizeof (uint32_t))); + for (datapeek_c = datapeek_f; *datapeek_c != '\0'; datapeek_c++) { + datapeek_p = va_arg (ap, void *); + if (*datapeek_c == 's') { /* special handling for strings */ + if ((uintptr_t) dv - (uintptr_t) addr + sizeof (uint32_t) > sz) { + tpl_hook.oops ("tpl_peek: tpl has insufficient length\n"); + tpl_hook.free (fmt_cpy); + fmt_cpy = NULL; /* fail */ + goto fail; + } + memcpy (&datapeek_ssz, dv, sizeof (uint32_t)); /* get slen */ + if (xendian) + tpl_byteswap (&datapeek_ssz, sizeof (uint32_t)); + if (old_string_format) + datapeek_ssz++; + dv = (void *) ((uintptr_t) dv + sizeof (uint32_t)); /* adv. to str */ + if (datapeek_ssz == 0) + datapeek_s = NULL; + else { + if ((uintptr_t) dv - (uintptr_t) addr + datapeek_ssz - 1 > sz) { + tpl_hook.oops ("tpl_peek: tpl has insufficient length\n"); + tpl_hook.free (fmt_cpy); + fmt_cpy = NULL; /* fail */ + goto fail; + } + datapeek_s = tpl_hook.malloc (datapeek_ssz); + if (datapeek_s == NULL) + fatal_oom (); + memcpy (datapeek_s, dv, datapeek_ssz - 1); + datapeek_s[datapeek_ssz - 1] = '\0'; + dv = (void *) ((uintptr_t) dv + datapeek_ssz - 1); + } + *(char **) datapeek_p = datapeek_s; + } else { + datapeek_csz = tpl_size_for (*datapeek_c); + if ((uintptr_t) dv - (uintptr_t) addr + datapeek_csz > sz) { + tpl_hook.oops ("tpl_peek: tpl has insufficient length\n"); + tpl_hook.free (fmt_cpy); + fmt_cpy = NULL; /* fail */ + goto fail; + } + memcpy (datapeek_p, dv, datapeek_csz); + if (xendian) + tpl_byteswap (datapeek_p, datapeek_csz); + dv = (void *) ((uintptr_t) dv + datapeek_csz); + } + } + } + +fail: + va_end (ap); + if ((mode & TPL_FILE) && mr.text != NULL) + tpl_unmap_file (&mr); + return fmt_cpy; +} + +/* tpl_jot(TPL_FILE, "file.tpl", "si", &s, &i); */ +/* tpl_jot(TPL_MEM, &buf, &sz, "si", &s, &i); */ +/* tpl_jot(TPL_FD, fd, "si", &s, &i); */ +TPL_API int +tpl_jot (int mode, ...) { + va_list ap; + char *filename, *fmt; + size_t *sz; + int fd, rc = 0; + void **buf; + tpl_node *tn; + + va_start (ap, mode); + if (mode & TPL_FILE) { + filename = va_arg (ap, char *); + fmt = va_arg (ap, char *); + tn = tpl_map_va (fmt, ap); + if (tn == NULL) { + rc = -1; + goto fail; + } + tpl_pack (tn, 0); + rc = tpl_dump (tn, TPL_FILE, filename); + tpl_free (tn); + } else if (mode & TPL_MEM) { + buf = va_arg (ap, void *); + sz = va_arg (ap, size_t *); + fmt = va_arg (ap, char *); + tn = tpl_map_va (fmt, ap); + if (tn == NULL) { + rc = -1; + goto fail; + } + tpl_pack (tn, 0); + rc = tpl_dump (tn, TPL_MEM, buf, sz); + tpl_free (tn); + } else if (mode & TPL_FD) { + fd = va_arg (ap, int); + fmt = va_arg (ap, char *); + tn = tpl_map_va (fmt, ap); + if (tn == NULL) { + rc = -1; + goto fail; + } + tpl_pack (tn, 0); + rc = tpl_dump (tn, TPL_FD, fd); + tpl_free (tn); + } else { + tpl_hook.fatal ("invalid tpl_jot mode\n"); + } + +fail: + va_end (ap); + return rc; +} + +TPL_API int +tpl_load (tpl_node *r, int mode, ...) { + va_list ap; + int rc = 0, fd = 0; + char *filename = NULL; + void *addr; + size_t sz; + + va_start (ap, mode); + if (mode & TPL_FILE) + filename = va_arg (ap, char *); + else if (mode & TPL_MEM) { + addr = va_arg (ap, void *); + sz = va_arg (ap, size_t); + } else if (mode & TPL_FD) { + fd = va_arg (ap, int); + } else { + tpl_hook.oops ("unsupported tpl_load mode %d\n", mode); + va_end (ap); + return -1; + } + va_end (ap); + + if (r->type != TPL_TYPE_ROOT) { + tpl_hook.oops ("error: tpl_load to non-root node\n"); + return -1; + } + if (((tpl_root_data *) (r->data))->flags & (TPL_WRONLY | TPL_RDONLY)) { + /* already packed or loaded, so reset it as if newly mapped */ + tpl_free_keep_map (r); + } + if (mode & TPL_FILE) { + if (tpl_mmap_file (filename, &((tpl_root_data *) (r->data))->mmap) != 0) { + tpl_hook.oops ("tpl_load failed for file %s\n", filename); + return -1; + } + if ((rc = tpl_sanity (r, (mode & TPL_EXCESS_OK))) != 0) { + if (rc == ERR_FMT_MISMATCH) { + tpl_hook.oops ("%s: format signature mismatch\n", filename); + } else if (rc == ERR_FLEN_MISMATCH) { + tpl_hook.oops ("%s: array lengths mismatch\n", filename); + } else { + tpl_hook.oops ("%s: not a valid tpl file\n", filename); + } + tpl_unmap_file (&((tpl_root_data *) (r->data))->mmap); + return -1; + } + ((tpl_root_data *) (r->data))->flags = (TPL_FILE | TPL_RDONLY); + } else if (mode & TPL_MEM) { + ((tpl_root_data *) (r->data))->mmap.text = addr; + ((tpl_root_data *) (r->data))->mmap.text_sz = sz; + if ((rc = tpl_sanity (r, (mode & TPL_EXCESS_OK))) != 0) { + if (rc == ERR_FMT_MISMATCH) { + tpl_hook.oops ("format signature mismatch\n"); + } else { + tpl_hook.oops ("not a valid tpl file\n"); + } + return -1; + } + ((tpl_root_data *) (r->data))->flags = (TPL_MEM | TPL_RDONLY); + if (mode & TPL_UFREE) + ((tpl_root_data *) (r->data))->flags |= TPL_UFREE; + } else if (mode & TPL_FD) { + /* if fd read succeeds, resulting mem img is used for load */ + if (tpl_gather (TPL_GATHER_BLOCKING, fd, &addr, &sz) > 0) { + return tpl_load (r, TPL_MEM | TPL_UFREE, addr, sz); + } else + return -1; + } else { + tpl_hook.oops ("invalid tpl_load mode %d\n", mode); + return -1; + } + /* this applies to TPL_MEM or TPL_FILE */ + if (tpl_needs_endian_swap (((tpl_root_data *) (r->data))->mmap.text)) + ((tpl_root_data *) (r->data))->flags |= TPL_XENDIAN; + tpl_unpackA0 (r); /* prepare root A nodes for use */ + return 0; +} + +TPL_API int +tpl_Alen (tpl_node *r, int i) { + tpl_node *n; + + n = tpl_find_i (r, i); + if (n == NULL) { + tpl_hook.oops ("invalid index %d to tpl_unpack\n", i); + return -1; + } + if (n->type != TPL_TYPE_ARY) + return -1; + return ((tpl_atyp *) (n->data))->num; +} + +static void +tpl_free_atyp (tpl_node *n, tpl_atyp *atyp) { + tpl_backbone *bb, *bbnxt; + tpl_node *c; + void *dv; + tpl_bin *binp; + tpl_atyp *atypp; + char *strp; + size_t itermax; + tpl_pound_data *pd; + int i; + + bb = atyp->bb; + while (bb) { + bbnxt = bb->next; + dv = bb->data; + c = n->children; + while (c) { + switch (c->type) { + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + dv = (void *) ((uintptr_t) dv + tpl_types[c->type].sz * c->num); + break; + case TPL_TYPE_BIN: + memcpy (&binp, dv, sizeof (tpl_bin *)); /* cp to aligned */ + if (binp->addr) + tpl_hook.free (binp->addr); /* free buf */ + tpl_hook.free (binp); /* free tpl_bin */ + dv = (void *) ((uintptr_t) dv + sizeof (tpl_bin *)); + break; + case TPL_TYPE_STR: + for (i = 0; i < c->num; i++) { + memcpy (&strp, dv, sizeof (char *)); /* cp to aligned */ + if (strp) + tpl_hook.free (strp); /* free string */ + dv = (void *) ((uintptr_t) dv + sizeof (char *)); + } + break; + case TPL_TYPE_POUND: + /* iterate over the preceding nodes */ + itermax = c->num; + pd = (tpl_pound_data *) c->data; + if (++(pd->iternum) < itermax) { + c = pd->iter_start_node; + continue; + } else { /* loop complete. */ + pd->iternum = 0; + } + break; + case TPL_TYPE_ARY: + memcpy (&atypp, dv, sizeof (tpl_atyp *)); /* cp to aligned */ + tpl_free_atyp (c, atypp); /* free atyp */ + dv = (void *) ((uintptr_t) dv + sizeof (void *)); + break; + default: + tpl_hook.fatal ("unsupported format character\n"); + break; + } + c = c->next; + } + tpl_hook.free (bb); + bb = bbnxt; + } + tpl_hook.free (atyp); +} + +/* determine (by walking) byte length of serialized r/A node at address dv + * returns 0 on success, or -1 if the tpl isn't trustworthy (fails consistency) + */ +static int +tpl_serlen (tpl_node *r, tpl_node *n, void *dv, size_t *serlen) { + uint32_t slen; + int num = 0, fidx; + tpl_node *c; + size_t len = 0, alen, buf_past, itermax; + tpl_pound_data *pd; + + buf_past = ((uintptr_t) ((tpl_root_data *) (r->data))->mmap.text + + ((tpl_root_data *) (r->data))->mmap.text_sz); + + if (n->type == TPL_TYPE_ROOT) + num = 1; + else if (n->type == TPL_TYPE_ARY) { + if ((uintptr_t) dv + sizeof (uint32_t) > buf_past) + return -1; + memcpy (&num, dv, sizeof (uint32_t)); + if (((tpl_root_data *) (r->data))->flags & TPL_XENDIAN) + tpl_byteswap (&num, sizeof (uint32_t)); + dv = (void *) ((uintptr_t) dv + sizeof (uint32_t)); + len += sizeof (uint32_t); + } else + tpl_hook.fatal ("internal error in tpl_serlen\n"); + + while (num-- > 0) { + c = n->children; + while (c) { + switch (c->type) { + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + for (fidx = 0; fidx < c->num; fidx++) { /* octothorpe support */ + if ((uintptr_t) dv + tpl_types[c->type].sz > buf_past) + return -1; + dv = (void *) ((uintptr_t) dv + tpl_types[c->type].sz); + len += tpl_types[c->type].sz; + } + break; + case TPL_TYPE_BIN: + len += sizeof (uint32_t); + if ((uintptr_t) dv + sizeof (uint32_t) > buf_past) + return -1; + memcpy (&slen, dv, sizeof (uint32_t)); + if (((tpl_root_data *) (r->data))->flags & TPL_XENDIAN) + tpl_byteswap (&slen, sizeof (uint32_t)); + len += slen; + dv = (void *) ((uintptr_t) dv + sizeof (uint32_t)); + if ((uintptr_t) dv + slen > buf_past) + return -1; + dv = (void *) ((uintptr_t) dv + slen); + break; + case TPL_TYPE_STR: + for (fidx = 0; fidx < c->num; fidx++) { /* octothorpe support */ + len += sizeof (uint32_t); + if ((uintptr_t) dv + sizeof (uint32_t) > buf_past) + return -1; + memcpy (&slen, dv, sizeof (uint32_t)); + if (((tpl_root_data *) (r->data))->flags & TPL_XENDIAN) + tpl_byteswap (&slen, sizeof (uint32_t)); + if (!(((tpl_root_data *) (r->data))->flags & TPL_OLD_STRING_FMT)) + slen = (slen > 1) ? (slen - 1) : 0; + len += slen; + dv = (void *) ((uintptr_t) dv + sizeof (uint32_t)); + if ((uintptr_t) dv + slen > buf_past) + return -1; + dv = (void *) ((uintptr_t) dv + slen); + } + break; + case TPL_TYPE_ARY: + if (tpl_serlen (r, c, dv, &alen) == -1) + return -1; + dv = (void *) ((uintptr_t) dv + alen); + len += alen; + break; + case TPL_TYPE_POUND: + /* iterate over the preceding nodes */ + itermax = c->num; + pd = (tpl_pound_data *) c->data; + if (++(pd->iternum) < itermax) { + c = pd->iter_start_node; + continue; + } else { /* loop complete. */ + pd->iternum = 0; + } + break; + default: + tpl_hook.fatal ("unsupported format character\n"); + break; + } + c = c->next; + } + } + *serlen = len; + return 0; +} + +static int +tpl_mmap_output_file (char *filename, size_t sz, void **text_out) { + void *text; + int fd, perms; + +#ifndef _WIN32 + perms = S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP | S_IROTH; /* ug+w o+r */ + fd = open (filename, O_CREAT | O_TRUNC | O_RDWR, perms); +#else + perms = _S_IWRITE; + fd = _open (filename, _O_CREAT | _O_TRUNC | _O_RDWR, perms); +#endif + + if (fd == -1) { + tpl_hook.oops ("Couldn't open file %s: %s\n", filename, strerror (errno)); + return -1; + } + + text = mmap (0, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (text == MAP_FAILED) { + tpl_hook.oops ("Failed to mmap %s: %s\n", filename, strerror (errno)); + close (fd); + return -1; + } + if (ftruncate (fd, sz) == -1) { + tpl_hook.oops ("ftruncate failed: %s\n", strerror (errno)); + munmap (text, sz); + close (fd); + return -1; + } + *text_out = text; + return fd; +} + +static int +tpl_mmap_file (char *filename, tpl_mmap_rec *mr) { + struct stat stat_buf; + + if ((mr->fd = open (filename, O_RDONLY)) == -1) { + tpl_hook.oops ("Couldn't open file %s: %s\n", filename, strerror (errno)); + return -1; + } + + if (fstat (mr->fd, &stat_buf) == -1) { + close (mr->fd); + tpl_hook.oops ("Couldn't stat file %s: %s\n", filename, strerror (errno)); + return -1; + } + + mr->text_sz = (size_t) stat_buf.st_size; + mr->text = mmap (0, stat_buf.st_size, PROT_READ, MAP_PRIVATE, mr->fd, 0); + if (mr->text == MAP_FAILED) { + close (mr->fd); + tpl_hook.oops ("Failed to mmap %s: %s\n", filename, strerror (errno)); + return -1; + } + + return 0; +} + +TPL_API int +tpl_pack (tpl_node *r, int i) { + tpl_node *n, *child, *np; + void *datav = NULL; + size_t sz, itermax; + uint32_t slen; + char *str; + tpl_bin *bin; + tpl_pound_data *pd; + int fidx; + + n = tpl_find_i (r, i); + if (n == NULL) { + tpl_hook.oops ("invalid index %d to tpl_pack\n", i); + return -1; + } + + if (((tpl_root_data *) (r->data))->flags & TPL_RDONLY) { + /* convert to an writeable tpl, initially empty */ + tpl_free_keep_map (r); + } + + ((tpl_root_data *) (r->data))->flags |= TPL_WRONLY; + + if (n->type == TPL_TYPE_ARY) + datav = tpl_extend_backbone (n); + child = n->children; + while (child) { + switch (child->type) { + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + /* no need to use fidx iteration here; we can copy multiple values in one memcpy */ + memcpy (child->data, child->addr, tpl_types[child->type].sz * child->num); + if (datav) + datav = tpl_cpv (datav, child->data, tpl_types[child->type].sz * child->num); + if (n->type == TPL_TYPE_ARY) + n->ser_osz += tpl_types[child->type].sz * child->num; + break; + case TPL_TYPE_BIN: + /* copy the buffer to be packed */ + slen = ((tpl_bin *) child->addr)->sz; + if (slen > 0) { + str = tpl_hook.malloc (slen); + if (!str) + fatal_oom (); + memcpy (str, ((tpl_bin *) child->addr)->addr, slen); + } else + str = NULL; + /* and make a tpl_bin to point to it */ + bin = tpl_hook.malloc (sizeof (tpl_bin)); + if (!bin) + fatal_oom (); + bin->addr = str; + bin->sz = slen; + /* now pack its pointer, first deep freeing any pre-existing bin */ + if (*(tpl_bin **) (child->data) != NULL) { + if ((*(tpl_bin **) (child->data))->sz != 0) { + tpl_hook.free ((*(tpl_bin **) (child->data))->addr); + } + tpl_hook.free (*(tpl_bin **) (child->data)); + } + memcpy (child->data, &bin, sizeof (tpl_bin *)); + if (datav) { + datav = tpl_cpv (datav, &bin, sizeof (tpl_bin *)); + *(tpl_bin **) (child->data) = NULL; + } + if (n->type == TPL_TYPE_ARY) { + n->ser_osz += sizeof (uint32_t); /* binary buf len word */ + n->ser_osz += bin->sz; /* binary buf */ + } + break; + case TPL_TYPE_STR: + for (fidx = 0; fidx < child->num; fidx++) { + /* copy the string to be packed. slen includes \0. this + block also works if the string pointer is NULL. */ + char *caddr = ((char **) child->addr)[fidx]; + char **cdata = &((char **) child->data)[fidx]; + slen = caddr ? (strlen (caddr) + 1) : 0; + if (slen) { + str = tpl_hook.malloc (slen); + if (!str) + fatal_oom (); + memcpy (str, caddr, slen); /* include \0 */ + } else { + str = NULL; + } + /* now pack its pointer, first freeing any pre-existing string */ + if (*cdata != NULL) { + tpl_hook.free (*cdata); + } + memcpy (cdata, &str, sizeof (char *)); + if (datav) { + datav = tpl_cpv (datav, &str, sizeof (char *)); + *cdata = NULL; + } + if (n->type == TPL_TYPE_ARY) { + n->ser_osz += sizeof (uint32_t); /* string len word */ + if (slen > 1) + n->ser_osz += slen - 1; /* string (without nul) */ + } + } + break; + case TPL_TYPE_ARY: + /* copy the child's tpl_atype* and reset it to empty */ + if (datav) { + sz = ((tpl_atyp *) (child->data))->sz; + datav = tpl_cpv (datav, &child->data, sizeof (void *)); + child->data = tpl_hook.malloc (sizeof (tpl_atyp)); + if (!child->data) + fatal_oom (); + ((tpl_atyp *) (child->data))->num = 0; + ((tpl_atyp *) (child->data))->sz = sz; + ((tpl_atyp *) (child->data))->bb = NULL; + ((tpl_atyp *) (child->data))->bbtail = NULL; + } + /* parent is array? then bubble up child array's ser_osz */ + if (n->type == TPL_TYPE_ARY) { + n->ser_osz += sizeof (uint32_t); /* array len word */ + n->ser_osz += child->ser_osz; /* child array ser_osz */ + child->ser_osz = 0; /* reset child array ser_osz */ + } + break; + + case TPL_TYPE_POUND: + /* we need to iterate n times over preceding nodes in S(...). + * we may be in the midst of an iteration each time or starting. */ + pd = (tpl_pound_data *) child->data; + itermax = child->num; + + /* itermax is total num of iterations needed */ + /* pd->iternum is current iteration index */ + /* pd->inter_elt_len is element-to-element len of contiguous structs */ + /* pd->iter_start_node is where we jump to at each iteration. */ + + if (++(pd->iternum) < itermax) { + + /* in start or midst of loop. advance addr/data pointers. */ + for (np = pd->iter_start_node; np != child; np = np->next) { + np->data = (char *) (np->data) + (tpl_types[np->type].sz * np->num); + np->addr = (char *) (np->addr) + pd->inter_elt_len; + } + /* do next iteration */ + child = pd->iter_start_node; + continue; + + } else { /* loop complete. */ + + /* reset iteration index and addr/data pointers. */ + pd->iternum = 0; + for (np = pd->iter_start_node; np != child; np = np->next) { + np->data = (char *) (np->data) - ((itermax - 1) * tpl_types[np->type].sz * np->num); + np->addr = (char *) (np->addr) - ((itermax - 1) * pd->inter_elt_len); + } + + } + break; + default: + tpl_hook.fatal ("unsupported format character\n"); + break; + } + child = child->next; + } + return 0; +} + +TPL_API int +tpl_unpack (tpl_node *r, int i) { + tpl_node *n, *c, *np; + uint32_t slen; + int rc = 1, fidx; + char *str; + void *dv = NULL, *caddr; + size_t A_bytes, itermax; + tpl_pound_data *pd; + void *img; + size_t sz; + + + /* handle unusual case of tpl_pack,tpl_unpack without an + * intervening tpl_dump. do a dump/load implicitly. */ + if (((tpl_root_data *) (r->data))->flags & TPL_WRONLY) { + if (tpl_dump (r, TPL_MEM, &img, &sz) != 0) + return -1; + if (tpl_load (r, TPL_MEM | TPL_UFREE, img, sz) != 0) { + tpl_hook.free (img); + return -1; + }; + } + + n = tpl_find_i (r, i); + if (n == NULL) { + tpl_hook.oops ("invalid index %d to tpl_unpack\n", i); + return -1; + } + + /* either root node or an A node */ + if (n->type == TPL_TYPE_ROOT) { + dv = tpl_find_data_start (((tpl_root_data *) (n->data))->mmap.text); + } else if (n->type == TPL_TYPE_ARY) { + if (((tpl_atyp *) (n->data))->num <= 0) + return 0; /* array consumed */ + else + rc = ((tpl_atyp *) (n->data))->num--; + dv = ((tpl_atyp *) (n->data))->cur; + if (!dv) + tpl_hook.fatal ("must unpack parent of node before node itself\n"); + } + + c = n->children; + while (c) { + switch (c->type) { + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + /* unpack elements of cross-endian octothorpic array individually */ + if (((tpl_root_data *) (r->data))->flags & TPL_XENDIAN) { + for (fidx = 0; fidx < c->num; fidx++) { + caddr = (void *) ((uintptr_t) c->addr + (fidx * tpl_types[c->type].sz)); + memcpy (caddr, dv, tpl_types[c->type].sz); + tpl_byteswap (caddr, tpl_types[c->type].sz); + dv = (void *) ((uintptr_t) dv + tpl_types[c->type].sz); + } + } else { + /* bulk unpack ok if not cross-endian */ + memcpy (c->addr, dv, tpl_types[c->type].sz * c->num); + dv = (void *) ((uintptr_t) dv + tpl_types[c->type].sz * c->num); + } + break; + case TPL_TYPE_BIN: + memcpy (&slen, dv, sizeof (uint32_t)); + if (((tpl_root_data *) (r->data))->flags & TPL_XENDIAN) + tpl_byteswap (&slen, sizeof (uint32_t)); + if (slen > 0) { + str = (char *) tpl_hook.malloc (slen); + if (!str) + fatal_oom (); + } else + str = NULL; + dv = (void *) ((uintptr_t) dv + sizeof (uint32_t)); + if (slen > 0) + memcpy (str, dv, slen); + memcpy (&(((tpl_bin *) c->addr)->addr), &str, sizeof (void *)); + memcpy (&(((tpl_bin *) c->addr)->sz), &slen, sizeof (uint32_t)); + dv = (void *) ((uintptr_t) dv + slen); + break; + case TPL_TYPE_STR: + for (fidx = 0; fidx < c->num; fidx++) { + memcpy (&slen, dv, sizeof (uint32_t)); + if (((tpl_root_data *) (r->data))->flags & TPL_XENDIAN) + tpl_byteswap (&slen, sizeof (uint32_t)); + if (((tpl_root_data *) (r->data))->flags & TPL_OLD_STRING_FMT) + slen += 1; + dv = (void *) ((uintptr_t) dv + sizeof (uint32_t)); + if (slen) { /* slen includes \0 */ + str = (char *) tpl_hook.malloc (slen); + if (!str) + fatal_oom (); + if (slen > 1) + memcpy (str, dv, slen - 1); + str[slen - 1] = '\0'; /* nul terminate */ + dv = (void *) ((uintptr_t) dv + slen - 1); + } else + str = NULL; + memcpy (&((char **) c->addr)[fidx], &str, sizeof (char *)); + } + break; + case TPL_TYPE_POUND: + /* iterate over preceding nodes */ + pd = (tpl_pound_data *) c->data; + itermax = c->num; + if (++(pd->iternum) < itermax) { + /* in start or midst of loop. advance addr/data pointers. */ + for (np = pd->iter_start_node; np != c; np = np->next) { + np->addr = (char *) (np->addr) + pd->inter_elt_len; + } + /* do next iteration */ + c = pd->iter_start_node; + continue; + + } else { /* loop complete. */ + + /* reset iteration index and addr/data pointers. */ + pd->iternum = 0; + for (np = pd->iter_start_node; np != c; np = np->next) { + np->addr = (char *) (np->addr) - ((itermax - 1) * pd->inter_elt_len); + } + + } + break; + case TPL_TYPE_ARY: + if (tpl_serlen (r, c, dv, &A_bytes) == -1) + tpl_hook.fatal ("internal error in unpack\n"); + memcpy (&((tpl_atyp *) (c->data))->num, dv, sizeof (uint32_t)); + if (((tpl_root_data *) (r->data))->flags & TPL_XENDIAN) + tpl_byteswap (&((tpl_atyp *) (c->data))->num, sizeof (uint32_t)); + ((tpl_atyp *) (c->data))->cur = (void *) ((uintptr_t) dv + sizeof (uint32_t)); + dv = (void *) ((uintptr_t) dv + A_bytes); + break; + default: + tpl_hook.fatal ("unsupported format character\n"); + break; + } + + c = c->next; + } + if (n->type == TPL_TYPE_ARY) + ((tpl_atyp *) (n->data))->cur = dv; /* next element */ + return rc; +} + +/* Specialized function that unpacks only the root's A nodes, after tpl_load */ +static int +tpl_unpackA0 (tpl_node *r) { + tpl_node *n, *c; + uint32_t slen; + int rc = 1, fidx, i; + void *dv; + size_t A_bytes, itermax; + tpl_pound_data *pd; + + n = r; + dv = tpl_find_data_start (((tpl_root_data *) (r->data))->mmap.text); + + c = n->children; + while (c) { + switch (c->type) { + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + for (fidx = 0; fidx < c->num; fidx++) { + dv = (void *) ((uintptr_t) dv + tpl_types[c->type].sz); + } + break; + case TPL_TYPE_BIN: + memcpy (&slen, dv, sizeof (uint32_t)); + if (((tpl_root_data *) (r->data))->flags & TPL_XENDIAN) + tpl_byteswap (&slen, sizeof (uint32_t)); + dv = (void *) ((uintptr_t) dv + sizeof (uint32_t)); + dv = (void *) ((uintptr_t) dv + slen); + break; + case TPL_TYPE_STR: + for (i = 0; i < c->num; i++) { + memcpy (&slen, dv, sizeof (uint32_t)); + if (((tpl_root_data *) (r->data))->flags & TPL_XENDIAN) + tpl_byteswap (&slen, sizeof (uint32_t)); + if (((tpl_root_data *) (r->data))->flags & TPL_OLD_STRING_FMT) + slen += 1; + dv = (void *) ((uintptr_t) dv + sizeof (uint32_t)); + if (slen > 1) + dv = (void *) ((uintptr_t) dv + slen - 1); + } + break; + case TPL_TYPE_POUND: + /* iterate over the preceding nodes */ + itermax = c->num; + pd = (tpl_pound_data *) c->data; + if (++(pd->iternum) < itermax) { + c = pd->iter_start_node; + continue; + } else { /* loop complete. */ + pd->iternum = 0; + } + break; + case TPL_TYPE_ARY: + if (tpl_serlen (r, c, dv, &A_bytes) == -1) + tpl_hook.fatal ("internal error in unpackA0\n"); + memcpy (&((tpl_atyp *) (c->data))->num, dv, sizeof (uint32_t)); + if (((tpl_root_data *) (r->data))->flags & TPL_XENDIAN) + tpl_byteswap (&((tpl_atyp *) (c->data))->num, sizeof (uint32_t)); + ((tpl_atyp *) (c->data))->cur = (void *) ((uintptr_t) dv + sizeof (uint32_t)); + dv = (void *) ((uintptr_t) dv + A_bytes); + break; + default: + tpl_hook.fatal ("unsupported format character\n"); + break; + } + c = c->next; + } + return rc; +} + +/* In-place byte order swapping of a word of length "len" bytes */ +static void +tpl_byteswap (void *word, int len) { + int i; + char c, *w; + w = (char *) word; + for (i = 0; i < len / 2; i++) { + c = w[i]; + w[i] = w[len - 1 - i]; + w[len - 1 - i] = c; + } +} + +static void +tpl_fatal (const char *fmt, ...) { + va_list ap; + char exit_msg[100]; + + va_start (ap, fmt); + vsnprintf (exit_msg, 100, fmt, ap); + va_end (ap); + + tpl_hook.oops ("%s", exit_msg); + exit (-1); +} + +TPL_API int +tpl_gather (int mode, ...) { + va_list ap; + int fd, rc = 0; + size_t *szp, sz; + void **img, *addr, *data; + tpl_gather_t **gs; + tpl_gather_cb *cb; + + va_start (ap, mode); + switch (mode) { + case TPL_GATHER_BLOCKING: + fd = va_arg (ap, int); + img = va_arg (ap, void *); + szp = va_arg (ap, size_t *); + rc = tpl_gather_blocking (fd, img, szp); + break; + case TPL_GATHER_NONBLOCKING: + fd = va_arg (ap, int); + gs = (tpl_gather_t **) va_arg (ap, void *); + cb = (tpl_gather_cb *) va_arg (ap, tpl_gather_cb *); + data = va_arg (ap, void *); + rc = tpl_gather_nonblocking (fd, gs, cb, data); + break; + case TPL_GATHER_MEM: + addr = va_arg (ap, void *); + sz = va_arg (ap, size_t); + gs = (tpl_gather_t **) va_arg (ap, void *); + cb = (tpl_gather_cb *) va_arg (ap, tpl_gather_cb *); + data = va_arg (ap, void *); + rc = tpl_gather_mem (addr, sz, gs, cb, data); + break; + default: + tpl_hook.fatal ("unsupported tpl_gather mode %d\n", mode); + break; + } + va_end (ap); + return rc; +} + +/* dequeue a tpl by reading until one full tpl image is obtained. + * We take care not to read past the end of the tpl. + * This is intended as a blocking call i.e. for use with a blocking fd. + * It can be given a non-blocking fd, but the read spins if we have to wait. + */ +static int +tpl_gather_blocking (int fd, void **img, size_t *sz) { + char preamble[8]; + int rc; + uint32_t i = 0, tpllen; + + do { + rc = read (fd, &preamble[i], 8 - i); + i += (rc > 0) ? rc : 0; + } while ((rc == -1 && (errno == EINTR || errno == EAGAIN)) || (rc > 0 && i < 8)); + + if (rc < 0) { + tpl_hook.oops ("tpl_gather_fd_blocking failed: %s\n", strerror (errno)); + return -1; + } else if (rc == 0) { + /* tpl_hook.oops("tpl_gather_fd_blocking: eof\n"); */ + return 0; + } else if (i != 8) { + tpl_hook.oops ("internal error\n"); + return -1; + } + + if (preamble[0] == 't' && preamble[1] == 'p' && preamble[2] == 'l') { + memcpy (&tpllen, &preamble[4], 4); + if (tpl_needs_endian_swap (preamble)) + tpl_byteswap (&tpllen, 4); + } else { + tpl_hook.oops ("tpl_gather_fd_blocking: non-tpl input\n"); + return -1; + } + + /* malloc space for remainder of tpl image (overall length tpllen) + * and read it in + */ + if (tpl_hook.gather_max > 0 && tpllen > tpl_hook.gather_max) { + tpl_hook.oops ("tpl exceeds max length %zu\n", tpl_hook.gather_max); + return -2; + } + *sz = tpllen; + if ((*img = tpl_hook.malloc (tpllen)) == NULL) { + fatal_oom (); + } + + memcpy (*img, preamble, 8); /* copy preamble to output buffer */ + i = 8; + do { + rc = read (fd, &((*(char **) img)[i]), tpllen - i); + i += (rc > 0) ? rc : 0; + } while ((rc == -1 && (errno == EINTR || errno == EAGAIN)) || (rc > 0 && i < tpllen)); + + if (rc < 0) { + tpl_hook.oops ("tpl_gather_fd_blocking failed: %s\n", strerror (errno)); + tpl_hook.free (*img); + return -1; + } else if (rc == 0) { + /* tpl_hook.oops("tpl_gather_fd_blocking: eof\n"); */ + tpl_hook.free (*img); + return 0; + } else if (i != tpllen) { + tpl_hook.oops ("internal error\n"); + tpl_hook.free (*img); + return -1; + } + + return 1; +} + +/* Used by select()-driven apps which want to gather tpl images piecemeal */ +/* the file descriptor must be non-blocking for this function to work. */ +static int +tpl_gather_nonblocking (int fd, tpl_gather_t **gs, tpl_gather_cb *cb, void *data) { + char buf[TPL_GATHER_BUFLEN], *img, *tpl; + int rc, keep_looping, cbrc = 0; + size_t catlen; + uint32_t tpllen; + + while (1) { + rc = read (fd, buf, TPL_GATHER_BUFLEN); + if (rc == -1) { + if (errno == EINTR) + continue; /* got signal during read, ignore */ + if (errno == EAGAIN) + return 1; /* nothing to read right now */ + else { + tpl_hook.oops ("tpl_gather failed: %s\n", strerror (errno)); + if (*gs) { + tpl_hook.free ((*gs)->img); + tpl_hook.free (*gs); + *gs = NULL; + } + return -1; /* error, caller should close fd */ + } + } else if (rc == 0) { + if (*gs) { + tpl_hook.oops ("tpl_gather: partial tpl image precedes EOF\n"); + tpl_hook.free ((*gs)->img); + tpl_hook.free (*gs); + *gs = NULL; + } + return 0; /* EOF, caller should close fd */ + } else { + /* concatenate any partial tpl from last read with new buffer */ + if (*gs) { + catlen = (*gs)->len + rc; + if (tpl_hook.gather_max > 0 && catlen > tpl_hook.gather_max) { + tpl_hook.free ((*gs)->img); + tpl_hook.free ((*gs)); + *gs = NULL; + tpl_hook.oops ("tpl exceeds max length %zu\n", tpl_hook.gather_max); + return -2; /* error, caller should close fd */ + } + if ((img = tpl_hook.realloc ((*gs)->img, catlen)) == NULL) { + fatal_oom (); + } + memcpy (img + (*gs)->len, buf, rc); + tpl_hook.free (*gs); + *gs = NULL; + } else { + img = buf; + catlen = rc; + } + /* isolate any full tpl(s) in img and invoke cb for each */ + tpl = img; + keep_looping = (tpl + 8 < img + catlen) ? 1 : 0; + while (keep_looping) { + if (strncmp ("tpl", tpl, 3) != 0) { + tpl_hook.oops ("tpl prefix invalid\n"); + if (img != buf) + tpl_hook.free (img); + tpl_hook.free (*gs); + *gs = NULL; + return -3; /* error, caller should close fd */ + } + memcpy (&tpllen, &tpl[4], 4); + if (tpl_needs_endian_swap (tpl)) + tpl_byteswap (&tpllen, 4); + if (tpl + tpllen <= img + catlen) { + cbrc = (cb) (tpl, tpllen, data); /* invoke cb for tpl image */ + tpl += tpllen; /* point to next tpl image */ + if (cbrc < 0) + keep_looping = 0; + else + keep_looping = (tpl + 8 < img + catlen) ? 1 : 0; + } else + keep_looping = 0; + } + /* check if app callback requested closure of tpl source */ + if (cbrc < 0) { + tpl_hook.oops ("tpl_fd_gather aborted by app callback\n"); + if (img != buf) + tpl_hook.free (img); + if (*gs) + tpl_hook.free (*gs); + *gs = NULL; + return -4; + } + /* store any leftover, partial tpl fragment for next read */ + if (tpl == img && img != buf) { + /* consumed nothing from img!=buf */ + if ((*gs = tpl_hook.malloc (sizeof (tpl_gather_t))) == NULL) { + fatal_oom (); + } + (*gs)->img = tpl; + (*gs)->len = catlen; + } else if (tpl < img + catlen) { + /* consumed 1+ tpl(s) from img!=buf or 0 from img==buf */ + if ((*gs = tpl_hook.malloc (sizeof (tpl_gather_t))) == NULL) { + fatal_oom (); + } + if (((*gs)->img = tpl_hook.malloc (img + catlen - tpl)) == NULL) { + fatal_oom (); + } + (*gs)->len = img + catlen - tpl; + memcpy ((*gs)->img, tpl, img + catlen - tpl); + /* free partially consumed concat buffer if used */ + if (img != buf) + tpl_hook.free (img); + } else { /* tpl(s) fully consumed */ + /* free consumed concat buffer if used */ + if (img != buf) + tpl_hook.free (img); + } + } + } +} + +/* gather tpl piecemeal from memory buffer (not fd) e.g., from a lower-level api */ +static int +tpl_gather_mem (char *buf, size_t len, tpl_gather_t **gs, tpl_gather_cb *cb, void *data) { + char *img, *tpl; + int keep_looping, cbrc = 0; + size_t catlen; + uint32_t tpllen; + + /* concatenate any partial tpl from last read with new buffer */ + if (*gs) { + catlen = (*gs)->len + len; + if (tpl_hook.gather_max > 0 && catlen > tpl_hook.gather_max) { + tpl_hook.free ((*gs)->img); + tpl_hook.free ((*gs)); + *gs = NULL; + tpl_hook.oops ("tpl exceeds max length %zu\n", tpl_hook.gather_max); + return -2; /* error, caller should stop accepting input from source */ + } + if ((img = tpl_hook.realloc ((*gs)->img, catlen)) == NULL) { + fatal_oom (); + } + memcpy (img + (*gs)->len, buf, len); + tpl_hook.free (*gs); + *gs = NULL; + } else { + img = buf; + catlen = len; + } + /* isolate any full tpl(s) in img and invoke cb for each */ + tpl = img; + keep_looping = (tpl + 8 < img + catlen) ? 1 : 0; + while (keep_looping) { + if (strncmp ("tpl", tpl, 3) != 0) { + tpl_hook.oops ("tpl prefix invalid\n"); + if (img != buf) + tpl_hook.free (img); + tpl_hook.free (*gs); + *gs = NULL; + return -3; /* error, caller should stop accepting input from source */ + } + memcpy (&tpllen, &tpl[4], 4); + if (tpl_needs_endian_swap (tpl)) + tpl_byteswap (&tpllen, 4); + if (tpl + tpllen <= img + catlen) { + cbrc = (cb) (tpl, tpllen, data); /* invoke cb for tpl image */ + tpl += tpllen; /* point to next tpl image */ + if (cbrc < 0) + keep_looping = 0; + else + keep_looping = (tpl + 8 < img + catlen) ? 1 : 0; + } else + keep_looping = 0; + } + /* check if app callback requested closure of tpl source */ + if (cbrc < 0) { + tpl_hook.oops ("tpl_mem_gather aborted by app callback\n"); + if (img != buf) + tpl_hook.free (img); + if (*gs) + tpl_hook.free (*gs); + *gs = NULL; + return -4; + } + /* store any leftover, partial tpl fragment for next read */ + if (tpl == img && img != buf) { + /* consumed nothing from img!=buf */ + if ((*gs = tpl_hook.malloc (sizeof (tpl_gather_t))) == NULL) { + fatal_oom (); + } + (*gs)->img = tpl; + (*gs)->len = catlen; + } else if (tpl < img + catlen) { + /* consumed 1+ tpl(s) from img!=buf or 0 from img==buf */ + if ((*gs = tpl_hook.malloc (sizeof (tpl_gather_t))) == NULL) { + fatal_oom (); + } + if (((*gs)->img = tpl_hook.malloc (img + catlen - tpl)) == NULL) { + fatal_oom (); + } + (*gs)->len = img + catlen - tpl; + memcpy ((*gs)->img, tpl, img + catlen - tpl); + /* free partially consumed concat buffer if used */ + if (img != buf) + tpl_hook.free (img); + } else { /* tpl(s) fully consumed */ + /* free consumed concat buffer if used */ + if (img != buf) + tpl_hook.free (img); + } + return 1; +} diff --git a/src/tpl.h b/src/tpl.h new file mode 100644 index 0000000000..cdf7264dbc --- /dev/null +++ b/src/tpl.h @@ -0,0 +1,136 @@ +/* +Copyright (c) 2005-2013, Troy D. Hanson http://troydhanson.github.com/tpl/ +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef TPL_H +#define TPL_H + +#include /* size_t */ + +#include /* va_list */ + +#ifdef __INTEL_COMPILER +#include +#endif /* Intel Compiler efficient memcpy etc */ + +#ifdef _MSC_VER +typedef unsigned int uint32_t; +#else +#include /* uint32_t */ +#endif + +#if defined __cplusplus +extern "C" { +#endif + +#ifdef _WIN32 +#ifdef TPL_EXPORTS +#define TPL_API __declspec(dllexport) +#else /* */ +#ifdef TPL_NOLIB +#define TPL_API +#else +#define TPL_API __declspec(dllimport) +#endif /* TPL_NOLIB */ +#endif /* TPL_EXPORTS */ +#else +#define TPL_API +#endif + +/* bit flags (external) */ +#define TPL_FILE (1 << 0) +#define TPL_MEM (1 << 1) +#define TPL_PREALLOCD (1 << 2) +#define TPL_EXCESS_OK (1 << 3) +#define TPL_FD (1 << 4) +#define TPL_UFREE (1 << 5) +#define TPL_DATAPEEK (1 << 6) +#define TPL_FXLENS (1 << 7) +#define TPL_GETSIZE (1 << 8) +/* do not add flags here without renumbering the internal flags! */ + +/* flags for tpl_gather mode */ +#define TPL_GATHER_BLOCKING 1 +#define TPL_GATHER_NONBLOCKING 2 +#define TPL_GATHER_MEM 3 + +/* Hooks for error logging, memory allocation functions and fatal */ + typedef int (tpl_print_fcn) (const char *fmt, ...); + typedef void *(tpl_malloc_fcn) (size_t sz); + typedef void *(tpl_realloc_fcn) (void *ptr, size_t sz); + typedef void (tpl_free_fcn) (void *ptr); + typedef void (tpl_fatal_fcn) (const char *fmt, ...); + + typedef struct tpl_hook_t { + tpl_print_fcn *oops __attribute__((__format__ (printf, 1, 2))); + tpl_malloc_fcn *malloc; + tpl_realloc_fcn *realloc; + tpl_free_fcn *free; + tpl_fatal_fcn *fatal __attribute__((__format__ (printf, 1, 2))) + __attribute__((__noreturn__)); + size_t gather_max; + } tpl_hook_t; + + typedef struct tpl_node { + int type; + void *addr; + void *data; /* r:tpl_root_data*. A:tpl_atyp*. ow:szof type */ + int num; /* length of type if it's a C array */ + size_t ser_osz; /* serialization output size for subtree */ + struct tpl_node *children; /* my children; linked-list */ + struct tpl_node *next, *prev; /* my siblings (next child of my parent) */ + struct tpl_node *parent; /* my parent */ + } tpl_node; + +/* used when un/packing 'B' type (binary buffers) */ + typedef struct tpl_bin { + void *addr; + uint32_t sz; + } tpl_bin; + +/* for async/piecemeal reading of tpl images */ + typedef struct tpl_gather_t { + char *img; + int len; + } tpl_gather_t; + +/* Callback used when tpl_gather has read a full tpl image */ + typedef int (tpl_gather_cb) (void *img, size_t sz, void *data); + +/* Prototypes */ + TPL_API tpl_node *tpl_map (char *fmt, ...); /* define tpl using format */ + TPL_API void tpl_free (tpl_node * r); /* free a tpl map */ + TPL_API int tpl_pack (tpl_node * r, int i); /* pack the n'th packable */ + TPL_API int tpl_unpack (tpl_node * r, int i); /* unpack the n'th packable */ + TPL_API int tpl_dump (tpl_node * r, int mode, ...); /* serialize to mem/file */ + TPL_API int tpl_load (tpl_node * r, int mode, ...); /* set mem/file to unpack */ + TPL_API int tpl_Alen (tpl_node * r, int i); /* array len of packable i */ + TPL_API char *tpl_peek (int mode, ...); /* sneak peek at format string */ + TPL_API int tpl_gather (int mode, ...); /* non-blocking image gather */ + TPL_API int tpl_jot (int mode, ...); /* quick write a simple tpl */ + + TPL_API tpl_node *tpl_map_va (char *fmt, va_list ap); + +#if defined __cplusplus +} +#endif +#endif /* TPL_H */ diff --git a/src/ui.c b/src/ui.c new file mode 100644 index 0000000000..9343f8ec7e --- /dev/null +++ b/src/ui.c @@ -0,0 +1,1931 @@ +/** + * ui.c -- various curses interfaces + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE +#define _FILE_OFFSET_BITS 64 + +#define STDIN_FILENO 0 +#ifndef _BSD_SOURCE +#define _BSD_SOURCE /* include stuff from 4.3 BSD */ +#endif +#ifndef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE +#endif + +#if HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ui.h" + +#include "color.h" +#include "error.h" +#include "gkhash.h" +#include "gmenu.h" +#include "goaccess.h" +#include "util.h" +#include "xmalloc.h" + +/* *INDENT-OFF* */ +/* Determine which metrics should be displayed per module/panel */ +static const GOutput outputting[] = { + {VISITORS , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 1 , 1} , + {REQUESTS , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0} , + {REQUESTS_STATIC , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0} , + {NOT_FOUND , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0} , + {HOSTS , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 1 , 0} , + {OS , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 1 , 1} , + {BROWSERS , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 1 , 1} , + {VISIT_TIMES , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 1 , 1} , + {VIRTUAL_HOSTS , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0} , + {REFERRERS , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0} , + {REFERRING_SITES , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0} , + {KEYPHRASES , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0} , + {STATUS_CODES , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0} , + {REMOTE_USER , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0} , + {CACHE_STATUS , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0} , +#ifdef HAVE_GEOLOCATION + {GEO_LOCATION , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0} , + {ASN , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0} , +#endif + {MIME_TYPE , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0} , + {TLS_TYPE , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0} , +}; +/* *INDENT-ON* */ + +/* Structure to display overall statistics */ +typedef struct Field_ { + const char *field; + /* char due to log, bw, log_file */ + char *value; + GColors *(*colorlbl) (void); + GColors *(*colorval) (void); + short oneliner; +} Field; + +/* Determine which metrics to output given a module + * + * On error, or if not found, NULL is returned. + * On success, the panel value is returned. */ +const GOutput * +output_lookup (GModule module) { + int i, num_panels = ARRAY_SIZE (outputting); + + for (i = 0; i < num_panels; i++) { + if (outputting[i].module == module) + return &outputting[i]; + } + return NULL; +} + +/* Initialize curses colors */ +void +init_colors (int force) { + /* use default foreground/background colors */ + use_default_colors (); + /* first set a default normal color */ + set_normal_color (); + /* then parse custom colors and initialize them */ + set_colors (force); +} + +/* Ncurses' window handling */ +void +set_input_opts (void) { + initscr (); + clear (); + noecho (); + halfdelay (10); + nonl (); + intrflush (stdscr, FALSE); + keypad (stdscr, TRUE); + if (curs_set (0) == ERR) + LOG_DEBUG (("Unable to change cursor: %s\n", strerror (errno))); + + if (conf.mouse_support) + mousemask (BUTTON1_CLICKED, NULL); +} + +/* Deletes the given window, freeing all memory associated with it. */ +void +close_win (WINDOW *w) { + if (w == NULL) + return; + wclear (w); + wrefresh (w); + delwin (w); +} + +/* Get the current calendar time as a value of type time_t and convert + * time_t to tm as local time */ +void +generate_time (void) { + if (conf.tz_name) + set_tz (); + timestamp = time (NULL); + localtime_r (×tamp, &now_tm); +} + +/* Set the loading spinner as ended and manage the mutex locking. */ +void +end_spinner (void) { + if (conf.no_parsing_spinner) + return; + + pthread_mutex_lock (&parsing_spinner->mutex); + parsing_spinner->state = SPN_END; + pthread_mutex_unlock (&parsing_spinner->mutex); + if (!parsing_spinner->curses) { + /* wait for the ui_spinner thread to finish */ + struct timespec ts = {.tv_sec = 0,.tv_nsec = SPIN_UPDATE_INTERVAL }; + if (nanosleep (&ts, NULL) == -1 && errno != EINTR) + FATAL ("nanosleep: %s", strerror (errno)); + } +} + +/* Set background colors to all windows. */ +void +set_wbkgd (WINDOW *main_win, WINDOW *header_win) { + GColors *color = get_color (COLOR_BG); + + /* background colors */ + wbkgd (main_win, COLOR_PAIR (color->pair->idx)); + wbkgd (header_win, COLOR_PAIR (color->pair->idx)); + wbkgd (stdscr, COLOR_PAIR (color->pair->idx)); + wrefresh (main_win); +} + +/* Creates and the new terminal windows and set basic properties to + * each of them. e.g., background color, enable the reading of + * function keys. */ +void +init_windows (WINDOW **header_win, WINDOW **main_win) { + int row = 0, col = 0; + + /* init standard screen */ + getmaxyx (stdscr, row, col); + if (row < MIN_HEIGHT || col < MIN_WIDTH) + FATAL ("Minimum screen size - 0 columns by 7 lines"); + + /* init header screen */ + *header_win = newwin (6, col, 0, 0); + if (*header_win == NULL) + FATAL ("Unable to allocate memory for header_win."); + keypad (*header_win, TRUE); + + /* init main screen */ + *main_win = newwin (row - 8, col, 7, 0); + if (*main_win == NULL) + FATAL ("Unable to allocate memory for main_win."); + keypad (*main_win, TRUE); + set_wbkgd (*main_win, *header_win); +} + +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +/* Draw a generic header with the ability to set a custom text to it. */ +void +draw_header (WINDOW *win, const char *s, const char *fmt, int y, int x, int w, + GColors *(*func) (void)) { + GColors *color = (*func) (); + char *buf; + + buf = xmalloc (snprintf (NULL, 0, fmt, s) + 1); + sprintf (buf, fmt, s); + + wattron (win, color->attr | COLOR_PAIR (color->pair->idx)); + mvwhline (win, y, x, ' ', w); + mvwaddnstr (win, y, x, buf, w); + wattroff (win, color->attr | COLOR_PAIR (color->pair->idx)); + + free (buf); +} + +#pragma GCC diagnostic warning "-Wformat-nonliteral" + +/* Determine the actual size of the main window. */ +void +term_size (WINDOW *main_win, int *main_win_height) { + int term_h = 0, term_w = 0; + + getmaxyx (stdscr, term_h, term_w); + + *main_win_height = term_h - (MAX_HEIGHT_HEADER + MAX_HEIGHT_FOOTER); + wresize (main_win, *main_win_height, term_w); + wmove (main_win, *main_win_height, 0); +} + +/* Get the module/panel label name for the given module enum value. + * + * On success, a string containing the label name is returned. */ +const char * +module_to_label (GModule module) { + static const char *const modules[] = { + VISITORS_LABEL, + REQUESTS_LABEL, + REQUESTS_STATIC_LABEL, + NOT_FOUND_LABEL, + HOSTS_LABEL, + OS_LABEL, + BROWSERS_LABEL, + VISIT_TIMES_LABEL, + VIRTUAL_HOSTS_LABEL, + REFERRERS_LABEL, + REFERRING_SITES_LABEL, + KEYPHRASES_LABEL, + STATUS_CODES_LABEL, + REMOTE_USER_LABEL, + CACHE_STATUS_LABEL, +#ifdef HAVE_GEOLOCATION + GEO_LOCATION_LABEL, + ASN_LABEL, +#endif + MIME_TYPE_LABEL, + TLS_TYPE_LABEL, + }; + + return _(modules[module]); +} + +/* Get the module/panel label id for the given module enum value. + * + * On success, a string containing the label id is returned. */ +const char * +module_to_id (GModule module) { + static const char *const modules[] = { + VISITORS_ID, + REQUESTS_ID, + REQUESTS_STATIC_ID, + NOT_FOUND_ID, + HOSTS_ID, + OS_ID, + BROWSERS_ID, + VISIT_TIMES_ID, + VIRTUAL_HOSTS_ID, + REFERRERS_ID, + REFERRING_SITES_ID, + KEYPHRASES_ID, + STATUS_CODES_ID, + REMOTE_USER_ID, + CACHE_STATUS_ID, +#ifdef HAVE_GEOLOCATION + GEO_LOCATION_ID, + ASN_ID, +#endif + MIME_TYPE_ID, + TLS_TYPE_ID, + }; + + return _(modules[module]); +} + +/* Get the module/panel label header for the given module enum value. + * + * On success, a string containing the label header is returned. */ +const char * +module_to_head (GModule module) { + static const char *modules[] = { + VISITORS_HEAD, + REQUESTS_HEAD, + REQUESTS_STATIC_HEAD, + NOT_FOUND_HEAD, + HOSTS_HEAD, + OS_HEAD, + BROWSERS_HEAD, + VISIT_TIMES_HEAD, + VIRTUAL_HOSTS_HEAD, + REFERRERS_HEAD, + REFERRING_SITES_HEAD, + KEYPHRASES_HEAD, + STATUS_CODES_HEAD, + REMOTE_USER_HEAD, + CACHE_STATUS_HEAD, +#ifdef HAVE_GEOLOCATION + GEO_LOCATION_HEAD, + ASN_HEAD, +#endif + MIME_TYPE_HEAD, + TLS_TYPE_HEAD, + }; + + if (!conf.ignore_crawlers) + modules[VISITORS] = VISITORS_HEAD_BOTS; + + return _(modules[module]); +} + +/* Get the module/panel label description for the given module enum + * value. + * + * On success, a string containing the label description is returned. */ +const char * +module_to_desc (GModule module) { + static const char *const modules[] = { + VISITORS_DESC, + REQUESTS_DESC, + REQUESTS_STATIC_DESC, + NOT_FOUND_DESC, + HOSTS_DESC, + OS_DESC, + BROWSERS_DESC, + VISIT_TIMES_DESC, + VIRTUAL_HOSTS_DESC, + REFERRERS_DESC, + REFERRING_SITES_DESC, + KEYPHRASES_DESC, + STATUS_CODES_DESC, + REMOTE_USER_DESC, + CACHE_STATUS_DESC, +#ifdef HAVE_GEOLOCATION + GEO_LOCATION_DESC, + ASN_DESC, +#endif + MIME_TYPE_DESC, + TLS_TYPE_DESC, + }; + + return _(modules[module]); +} + +/* Rerender the header window to reflect active module. */ +void +update_active_module (WINDOW *header_win, GModule current) { + GColors *color = get_color (COLOR_ACTIVE_LABEL); + const char *module = module_to_label (current); + int col = getmaxx (stdscr); + + char *lbl = xmalloc (snprintf (NULL, 0, T_ACTIVE_PANEL, module) + 1); + sprintf (lbl, T_ACTIVE_PANEL, module); + + wmove (header_win, 0, 30); + + wattron (header_win, color->attr | COLOR_PAIR (color->pair->idx)); + mvwprintw (header_win, 0, col - strlen (lbl) - 1, "%s", lbl); + wattroff (header_win, color->attr | COLOR_PAIR (color->pair->idx)); + + wrefresh (header_win); + + free (lbl); +} + +/* Print out (terminal) an overall field label. e.g., 'Processed Time' */ +static void +render_overall_field (WINDOW *win, const char *s, int y, int x, GColors *color) { + wattron (win, color->attr | COLOR_PAIR (color->pair->idx)); + mvwprintw (win, y, x, "%s", s); + wattroff (win, color->attr | COLOR_PAIR (color->pair->idx)); +} + +/* Print out (terminal) an overall field value. e.g., '120 secs' */ +static void +render_overall_value (WINDOW *win, const char *s, int y, int x, GColors *color) { + wattron (win, color->attr | COLOR_PAIR (color->pair->idx)); + mvwprintw (win, y, x, "%s", s); + wattroff (win, color->attr | COLOR_PAIR (color->pair->idx)); +} + +/* Convert the number of excluded ips to a string. + * + * On success, the number of excluded ips as a string is returned. */ +static char * +get_str_excluded_ips (void) { + return u642str (ht_get_excluded_ips (), 0); +} + +/* Convert the number of failed requests to a string. + * + * On success, the number of failed requests as a string is returned. */ +static char * +get_str_failed_reqs (void) { + return u642str (ht_get_invalid (), 0); +} + +/* Convert the number of processed requests to a string. + * + * On success, the number of processed requests as a string is returned. */ +static char * +get_str_processed_reqs (void) { + return u642str (ht_get_processed (), 0); +} + +/* Convert the number of valid requests to a string. + * + * On success, the number of valid requests as a string is returned. */ +static char * +get_str_valid_reqs (void) { + return u642str (ht_sum_valid (), 0); +} + +/* Convert the number of not found requests to a string. + * + * On success, the number of not found requests as a string is + * returned. */ +static char * +get_str_notfound_reqs (void) { + return u642str (ht_get_size_datamap (NOT_FOUND), 0); +} + +/* Convert the number of referrers to a string. + * + * On success, the number of referrers as a string is returned. */ +static char * +get_str_ref_reqs (void) { + return u642str (ht_get_size_datamap (REFERRERS), 0); +} + +/* Convert the number of requests to a string. + * + * On success, the number of requests as a string is returned. */ +static char * +get_str_reqs (void) { + return u642str (ht_get_size_datamap (REQUESTS), 0); +} + +/* Convert the number of static requests to a string. + * + * On success, the number of static requests as a string is returned. */ +static char * +get_str_static_reqs (void) { + return u642str (ht_get_size_datamap (REQUESTS_STATIC), 0); +} + +/* Convert the number of unique visitors to a string. + * + * On success, the number of unique visitors as a string is returned. */ +static char * +get_str_visitors (void) { + return u642str (ht_get_size_uniqmap (VISITORS), 0); +} + +/* Convert the time taken to process the log to a string. + * + * On success, the time taken to process the log as a string is + * returned. */ +static char * +get_str_proctime (void) { + char *s = NULL; + uint32_t secs = ht_get_processing_time (); + + s = xmalloc (snprintf (NULL, 0, "%us", secs) + 1); + sprintf (s, "%us", secs); + + return s; +} + +/* Get the log file size in a human-readable format. + * + * On success, the log file size as a string is returned. */ +static char * +get_str_filesize (void) { + return filesize_str (get_log_sizes ()); +} + +/* Get the log file path. + * + * On success, the log file path as a string is returned. */ +static char * +get_str_logfile (void) { + int col = getmaxx (stdscr), left_padding = 20; + return get_log_source_str (col - left_padding); +} + +/* Get the bandwidth in a human-readable format. + * + * On success, the bandwidth as a string is returned. */ +static char * +get_str_bandwidth (void) { + return filesize_str (ht_sum_bw ()); +} + +/* Get the overall statistics start and end dates. + * + * On failure, 1 is returned + * On success, 0 is returned and an string containing the overall + * header is returned. */ +int +get_start_end_parsing_dates (char **start, char **end, const char *f) { + uint32_t *dates = NULL; + uint32_t len = 0; + const char *sndfmt = "%Y%m%d"; + char s[DATE_LEN]; + char e[DATE_LEN]; + + dates = get_sorted_dates (&len); + sprintf (s, "%u", dates[0]); + sprintf (e, "%u", dates[len - 1]); + + /* just display the actual dates - no specificity */ + *start = get_visitors_date (s, sndfmt, f); + *end = get_visitors_date (e, sndfmt, f); + + free (dates); + + return 0; +} + +/* Get the overall statistics header (label). + * + * On success, an string containing the overall header is returned. */ +char * +get_overall_header (GHolder *h) { + const char *head = T_DASH_HEAD; + char *hd = NULL, *start = NULL, *end = NULL; + + if (h->idx == 0 || get_start_end_parsing_dates (&start, &end, "%d/%b/%Y")) + return xstrdup (head); + + hd = xmalloc (snprintf (NULL, 0, "%s (%s - %s)", head, start, end) + 1); + sprintf (hd, "%s (%s - %s)", head, start, end); + + free (end); + free (start); + + return hd; +} + +/* Print out (terminal dashboard) the overall statistics header. */ +static void +render_overall_header (WINDOW *win, GHolder *h) { + char *hd = get_overall_header (h); + int col = getmaxx (stdscr); + + draw_header (win, hd, " %s", 0, 0, col, color_panel_header); + free (hd); +} + +/* Render the overall statistics. This will attempt to determine the + * right X and Y position given the current values. */ +static void +render_overall_statistics (WINDOW *win, Field fields[], size_t n) { + GColors *color = NULL; + int x_field = 2, x_value; + size_t i, j, k, max_field = 0, max_value, mod_val, y; + + for (i = 0, k = 0, y = 2; i < n; i++) { + /* new line every OVERALL_NUM_COLS */ + mod_val = k % OVERALL_NUM_COLS; + + /* reset position & length and increment row */ + if (k > 0 && mod_val == 0) { + max_field = 0; + x_field = 2; + y++; + } + + /* x pos = max length of field */ + x_field += max_field; + + color = (*fields[i].colorlbl) (); + render_overall_field (win, fields[i].field, y, x_field, color); + + /* get max length of field in the same column */ + max_field = 0; + for (j = 0; j < n; j++) { + size_t len = strlen (fields[j].field); + if (j % OVERALL_NUM_COLS == mod_val && len > max_field && !fields[j].oneliner) + max_field = len; + } + /* get max length of value in the same column */ + max_value = 0; + for (j = 0; j < n; j++) { + size_t len = strlen (fields[j].value); + if (j % OVERALL_NUM_COLS == mod_val && len > max_value && !fields[j].oneliner) + max_value = len; + } + + /* spacers */ + x_value = max_field + x_field + 1; + max_field += max_value + 2; + + color = (*fields[i].colorval) (); + render_overall_value (win, fields[i].value, y, x_value, color); + k += fields[i].oneliner ? OVERALL_NUM_COLS : 1; + } +} + +/* The entry point to render the overall statistics and free its data. */ +void +display_general (WINDOW *win, GHolder *h) { + GColors *(*colorlbl) (void) = color_overall_lbls; + GColors *(*colorpth) (void) = color_overall_path; + GColors *(*colorval) (void) = color_overall_vals; + + size_t n, i; + + /* *INDENT-OFF* */ + Field fields[] = { + {T_REQUESTS , get_str_processed_reqs () , colorlbl , colorval , 0} , + {T_UNIQUE_VISITORS , get_str_visitors () , colorlbl , colorval , 0} , + {T_UNIQUE_FILES , get_str_reqs () , colorlbl , colorval , 0} , + {T_REFERRER , get_str_ref_reqs () , colorlbl , colorval , 0} , + {T_VALID , get_str_valid_reqs () , colorlbl , colorval , 0} , + {T_GEN_TIME , get_str_proctime () , colorlbl , colorval , 0} , + {T_STATIC_FILES , get_str_static_reqs () , colorlbl , colorval , 0} , + {T_LOG , get_str_filesize () , colorlbl , colorval , 0} , + {T_FAILED , get_str_failed_reqs () , colorlbl , colorval , 0} , + {T_EXCLUDE_IP , get_str_excluded_ips () , colorlbl , colorval , 0} , + {T_UNIQUE404 , get_str_notfound_reqs () , colorlbl , colorval , 0} , + {T_BW , get_str_bandwidth () , colorlbl , colorval , 0} , + {T_LOG_PATH , get_str_logfile () , colorlbl , colorpth , 1} + }; + /* *INDENT-ON* */ + + werase (win); + render_overall_header (win, h); + + n = ARRAY_SIZE (fields); + render_overall_statistics (win, fields, n); + + for (i = 0; i < n; i++) { + free (fields[i].value); + } +} + +static char * +set_default_string (WINDOW *win, int pos_y, int pos_x, size_t max_width, const char *str) { + char *s = xmalloc (max_width + 1), *tmp; + size_t len = 0; + size_t size_x = 0, size_y = 0; + getmaxyx (win, size_y, size_x); + (void) size_y; + size_x -= 4; + + /* are we setting a default string */ + if (!str) { + s[0] = '\0'; + return s; + } + + len = MIN (max_width, strlen (str)); + memcpy (s, str, len); + s[len] = '\0'; + + /* is the default str length greater than input field? */ + if (strlen (s) > size_x) { + tmp = xstrdup (&s[0]); + tmp[size_x] = '\0'; + mvwprintw (win, pos_y, pos_x, "%s", tmp); + free (tmp); + } else { + mvwprintw (win, pos_y, pos_x, "%s", s); + } + + return s; +} + +/* Implement a basic framework to build a field input. + * + * On success, the inputted string is returned. */ +char * +input_string (WINDOW *win, int pos_y, int pos_x, size_t max_width, const char *str, + int enable_case, int *toggle_case) { + char *s = NULL, *tmp; + size_t i, c, pos = 0, x = 0, quit = 1, size_x = 0, size_y = 0; + + getmaxyx (win, size_y, size_x); + size_x -= 4; + + s = set_default_string (win, pos_y, pos_x, max_width, str); + if (str) + x = pos = 0; + + if (enable_case) + mvwprintw (win, size_y - 2, 1, " %s", CSENSITIVE); + + wmove (win, pos_y, pos_x + x); + wrefresh (win); + + curs_set (1); + while (quit) { + c = wgetch (stdscr); + switch (c) { + case 1: /* ^a */ + case 262: /* HOME */ + pos = x = 0; + break; + case 5: + case 360: /* END of line */ + if (strlen (s) > size_x) { + x = size_x; + pos = strlen (s) - size_x; + } else { + pos = 0; + x = strlen (s); + } + break; + case 7: /* ^g */ + case 27: /* ESC */ + pos = x = 0; + if (str && *str == '\0') + s[0] = '\0'; + quit = 0; + break; + case 9: /* TAB */ + if (!enable_case) + break; + *toggle_case = *toggle_case == 0 ? 1 : 0; + if (*toggle_case) + mvwprintw (win, size_y - 2, 1, " %s", CISENSITIVE); + else if (!*toggle_case) + mvwprintw (win, size_y - 2, 1, " %s", CSENSITIVE); + break; + case 21: /* ^u */ + s[0] = '\0'; + pos = x = 0; + break; + case 8: /* xterm-256color */ + case 127: + case KEY_BACKSPACE: + if (pos + x > 0) { + memmove (&s[(pos + x) - 1], &s[pos + x], (max_width - (pos + x)) + 1); + if (pos <= 0) + x--; + else + pos--; + } + break; + case KEY_LEFT: + if (x > 0) + x--; + else if (pos > 0) + pos--; + break; + case KEY_RIGHT: + if ((x + pos) < strlen (s)) { + if (x < size_x) + x++; + else + pos++; + } + break; + case 0x0a: + case 0x0d: + case KEY_ENTER: + quit = 0; + break; + default: + if (strlen (s) == max_width) + break; + if (!isprint ((unsigned char) c)) + break; + + if (strlen (s) == pos) { + s[pos + x] = c; + s[pos + x + 1] = '\0'; + waddch (win, c); + } else { + memmove (&s[pos + x + 1], &s[pos + x], strlen (&s[pos + x]) + 1); + s[pos + x] = c; + } + if ((x + pos) < max_width) { + if (x < size_x) + x++; + else + pos++; + } + } + tmp = xstrdup (&s[pos > 0 ? pos : 0]); + tmp[MIN (strlen (tmp), size_x)] = '\0'; + for (i = strlen (tmp); i < size_x; i++) + mvwprintw (win, pos_y, pos_x + i, "%s", " "); + mvwprintw (win, pos_y, pos_x, "%s", tmp); + free (tmp); + + wmove (win, pos_y, pos_x + x); + wrefresh (win); + } + curs_set (0); + + return s; +} + +/* Add the given user agent value into our array of GAgents. + * + * On error, 1 is returned. + * On success, the user agent is added to the array and 0 is returned. */ +static int +set_agents (void *val, void *user_data) { + GAgents *agents = user_data; + GAgentItem *tmp = NULL; + char *agent = NULL; + int newlen = 0, i; + + if (!(agent = ht_get_host_agent_val (*(uint32_t *) val))) + return 1; + + if (agents->size - 1 == agents->idx) { + newlen = agents->size + 4; + if (!(tmp = realloc (agents->items, newlen * sizeof (GAgentItem)))) + FATAL ("Unable to realloc agents"); + + agents->items = tmp; + agents->size = newlen; + } + + for (i = 0; i < agents->idx; ++i) { + if (strcmp (agent, agents->items[i].agent) == 0) { + free (agent); + return 0; + } + } + agents->items[agents->idx++].agent = agent; + + return 0; +} + +/* Iterate over the list of agents */ +GAgents * +load_host_agents (const char *addr) { + GAgents *agents = NULL; + GSLList *keys = NULL, *list = NULL; + void *data = NULL; + uint32_t items = 4, key = djb2 ((const unsigned char *) addr); + + keys = ht_get_keymap_list_from_key (HOSTS, key); + if (!keys) + return NULL; + + agents = new_gagents (items); + + /* *INDENT-OFF* */ + GSLIST_FOREACH (keys, data, { + if ((list = ht_get_host_agent_list (HOSTS, (*(uint32_t *) data)))) { + list_foreach (list, set_agents, agents); + list_remove_nodes (list); + } + }); + /* *INDENT-ON* */ + list_remove_nodes (keys); + + return agents; +} + +/* Fill the given terminal dashboard menu with user agent data. + * + * On error, the 1 is returned. + * On success, 0 is returned. */ +static int +fill_host_agents_gmenu (GMenu *menu, GAgents *agents) { + int i; + + if (agents == NULL) + return 1; + + menu->items = xcalloc (agents->idx, sizeof (GItem)); + for (i = 0; i < agents->idx; ++i) { + menu->items[i].name = xstrdup (agents->items[i].agent); + menu->items[i].checked = 0; + menu->size++; + } + + return 0; +} + +/* Render a list of agents if available for the selected host/IP. */ +void +load_agent_list (WINDOW *main_win, char *addr) { + GMenu *menu; + GAgents *agents = NULL; + WINDOW *win; + + char buf[256]; + int c, quit = 1, i; + int y, x, list_h, list_w, menu_w, menu_h; + + if (!conf.list_agents) + return; + + getmaxyx (stdscr, y, x); + list_h = y / 2; /* list window - height */ + list_w = x - 4; /* list window - width */ + menu_h = list_h - AGENTS_MENU_Y - 1; /* menu window - height */ + menu_w = list_w - AGENTS_MENU_X - AGENTS_MENU_X; /* menu window - width */ + + win = newwin (list_h, list_w, (y - list_h) / 2, (x - list_w) / 2); + keypad (win, TRUE); + wborder (win, '|', '|', '-', '-', '+', '+', '+', '+'); + + /* create a new instance of GMenu and make it selectable */ + menu = new_gmenu (win, menu_h, menu_w, AGENTS_MENU_Y, AGENTS_MENU_X); + if (!(agents = load_host_agents (addr))) + goto out; + if (fill_host_agents_gmenu (menu, agents) != 0) + goto out; + + post_gmenu (menu); + snprintf (buf, sizeof buf, AGENTSDLG_HEAD, addr); + draw_header (win, buf, " %s", 1, 1, list_w - 2, color_panel_header); + mvwprintw (win, 2, 2, AGENTSDLG_DESC); + wrefresh (win); + + while (quit) { + c = wgetch (stdscr); + switch (c) { + case KEY_DOWN: + gmenu_driver (menu, REQ_DOWN); + break; + case KEY_UP: + gmenu_driver (menu, REQ_UP); + break; + case KEY_RESIZE: + case 'q': + quit = 0; + break; + } + wrefresh (win); + } + + touchwin (main_win); + close_win (win); + win = NULL; + wrefresh (main_win); + +out: + + /* clean stuff up */ + for (i = 0; i < menu->size; ++i) + free (menu->items[i].name); + if (menu->items) + free (menu->items); + free (menu); + free_agents_array (agents); + close_win (win); +} + +/* Render the processing spinner. This runs within its own thread. */ +static void +ui_spinner (void *ptr_data) { + GSpinner *sp = (GSpinner *) ptr_data; + GColors *color = NULL; + + static char const spin_chars[] = "/-\\|"; + char buf[SPIN_LBL]; + const char *fn = NULL; + int i = 0; + long long tdiff = 0, psec = 0; + time_t begin; + struct timespec ts = {.tv_sec = 0,.tv_nsec = SPIN_UPDATE_INTERVAL }; + + if (sp->curses) + color = (*sp->color) (); + + time (&begin); + while (1) { + pthread_mutex_lock (&sp->mutex); + if (sp->state == SPN_END) { + if (!sp->curses && !conf.no_progress) + fprintf (stderr, "\n"); + + pthread_mutex_unlock (&sp->mutex); + return; + } + + setlocale (LC_NUMERIC, ""); + if (conf.no_progress) { + snprintf (buf, sizeof buf, SPIN_FMT, sp->label); + } else { + fn = *sp->filename ? *sp->filename : "restoring"; + tdiff = (long long) (time (NULL) - begin); + psec = tdiff >= 1 ? **(sp->processed) / tdiff : 0; + snprintf (buf, sizeof buf, SPIN_FMTM, sp->label, fn, **(sp->processed), psec); + } + setlocale (LC_NUMERIC, "POSIX"); + + if (sp->curses) { + /* CURSES */ + draw_header (sp->win, buf, " %s", sp->y, sp->x, sp->w, sp->color); + /* caret */ + wattron (sp->win, COLOR_PAIR (color->pair->idx)); + mvwaddch (sp->win, sp->y, sp->spin_x, spin_chars[i++ & 3]); + wattroff (sp->win, COLOR_PAIR (color->pair->idx)); + wrefresh (sp->win); + } else if (!conf.no_progress) { + /* STDOUT */ + fprintf (stderr, " \033[K%s\r", buf); + } + + pthread_mutex_unlock (&sp->mutex); + if (nanosleep (&ts, NULL) == -1 && errno != EINTR) + FATAL ("nanosleep: %s", strerror (errno)); + } +} + +/* Create the processing spinner's thread */ +void +ui_spinner_create (GSpinner *spinner) { + if (conf.no_parsing_spinner) + return; + + pthread_create (&(spinner->thread), NULL, (void *) &ui_spinner, spinner); + pthread_detach (spinner->thread); +} + +/* Initialize processing spinner data. */ +void +set_curses_spinner (GSpinner *spinner) { + int y, x; + if (spinner == NULL) + return; + + getmaxyx (stdscr, y, x); + + spinner->color = color_progress; + spinner->curses = 1; + spinner->win = stdscr; + spinner->x = 0; + spinner->w = x; + spinner->spin_x = x - 2; + spinner->y = y - 1; +} + +/* Determine if we need to lock the mutex. */ +void +lock_spinner (void) { + if (parsing_spinner != NULL && parsing_spinner->state == SPN_RUN) + pthread_mutex_lock (&parsing_spinner->mutex); +} + +/* Determine if we need to unlock the mutex. */ +void +unlock_spinner (void) { + if (parsing_spinner != NULL && parsing_spinner->state == SPN_RUN) + pthread_mutex_unlock (&parsing_spinner->mutex); +} + +/* Allocate memory for a spinner instance and initialize its data. + * + * On success, the newly allocated GSpinner is returned. */ +GSpinner * +new_gspinner (void) { + GSpinner *spinner; + + spinner = xcalloc (1, sizeof (GSpinner)); + spinner->label = "Parsing..."; + spinner->state = SPN_RUN; + spinner->curses = 0; + //if (conf.load_from_disk) + // conf.no_progress = 1; + + if (pthread_mutex_init (&(spinner->mutex), NULL)) + FATAL ("Failed init thread mutex"); + + return spinner; +} + +/* A wrapper call to clear the status bar on the config dialog + * (terminal output). */ +static void +clear_confdlg_status_bar (WINDOW *win, int y, int x, int w) { + draw_header (win, "", "%s", y, x, w + 1, color_default); +} + +/* Escape a date format string. + * + * If no conf.date_format is given, NULL is returned. + * On success, the newly escaped allocated string is returned. */ +static char * +get_input_date_format (void) { + char *date_format = NULL; + + if (conf.date_format) + date_format = escape_str (conf.date_format); + return date_format; +} + +/* Escape a time format string. + * + * If no conf.time_format is given, NULL is returned. + * On success, the newly escaped allocated string is returned. */ +static char * +get_input_time_format (void) { + char *time_format = NULL; + + if (conf.time_format) + time_format = escape_str (conf.time_format); + return time_format; +} + +/* Escape a log format string. + * + * If no conf.log_format is given, NULL is returned. + * On success, the newly escaped allocated string is returned. */ +static char * +get_input_log_format (void) { + char *log_format = NULL; + + if (conf.log_format) + log_format = escape_str (conf.log_format); + return log_format; +} + +static void +draw_formats (WINDOW *win, int w2) { + char *date_format = NULL, *log_format = NULL, *time_format = NULL; + + draw_header (win, CONFDLG_HEAD, " %s", 1, 1, w2, color_panel_header); + mvwprintw (win, 2, 2, CONFDLG_KEY_HINTS); + + /* set log format from config file if available */ + draw_header (win, CONFDLG_LOG_FORMAT, " %s", 11, 1, w2, color_panel_header); + if ((log_format = get_input_log_format ())) { + mvwprintw (win, 12, 2, "%.*s", CONF_MENU_W, log_format); + + free (log_format); + } + + /* set log format from config file if available */ + draw_header (win, CONFDLG_DATE_FORMAT, " %s", 14, 1, w2, color_panel_header); + if ((date_format = get_input_date_format ())) { + mvwprintw (win, 15, 2, "%.*s", CONF_MENU_W, date_format); + + free (date_format); + } + + /* set log format from config file if available */ + draw_header (win, CONFDLG_TIME_FORMAT, " %s", 17, 1, w2, color_panel_header); + if ((time_format = get_input_time_format ())) { + mvwprintw (win, 18, 2, "%.*s", CONF_MENU_W, time_format); + + free (time_format); + } +} + +static const char * +set_formats (char *date_format, char *log_format, char *time_format) { + /* display status bar error messages */ + if (!time_format && !conf.time_format) + return ERR_FORMAT_NO_TIME_FMT_DLG; + if (!date_format && !conf.date_format) + return ERR_FORMAT_NO_DATE_FMT_DLG; + if (!log_format && !conf.log_format) + return ERR_FORMAT_NO_LOG_FMT_DLG; + + if (time_format) { + free (conf.time_format); + conf.time_format = unescape_str (time_format); + } + + if (date_format) { + free (conf.date_format); + conf.date_format = unescape_str (date_format); + } + + if (log_format) { + free (conf.log_format); + conf.log_format = unescape_str (log_format); + } + + if (is_json_log_format (conf.log_format)) + conf.is_json_log_format = 1; + + set_spec_date_format (); + + return NULL; +} + +/* Render the help dialog. */ +static void +load_confdlg_error (WINDOW *parent_win, char **errors, int nerrors) { + int c, quit = 1, i = 0; + int y, x, h = ERR_WIN_HEIGHT, w = ERR_WIN_WIDTH; + WINDOW *win; + GMenu *menu; + + getmaxyx (stdscr, y, x); + + win = newwin (h, w, (y - h) / 2, (x - w) / 2); + keypad (win, TRUE); + wborder (win, '|', '|', '-', '-', '+', '+', '+', '+'); + + /* create a new instance of GMenu and make it selectable */ + menu = new_gmenu (win, ERR_MENU_HEIGHT, ERR_MENU_WIDTH, ERR_MENU_Y, ERR_MENU_X); + menu->size = nerrors; + + /* add items to GMenu */ + menu->items = (GItem *) xcalloc (nerrors, sizeof (GItem)); + for (i = 0; i < nerrors; ++i) { + menu->items[i].name = alloc_string (errors[i]); + menu->items[i].checked = 0; + free (errors[i]); + } + free (errors); + post_gmenu (menu); + + draw_header (win, ERR_FORMAT_HEADER, " %s", 1, 1, w - 2, color_error); + mvwprintw (win, 2, 2, CONFDLG_DESC); + + wrefresh (win); + while (quit) { + c = wgetch (stdscr); + switch (c) { + case KEY_DOWN: + gmenu_driver (menu, REQ_DOWN); + break; + case KEY_UP: + gmenu_driver (menu, REQ_UP); + break; + case KEY_RESIZE: + case 'q': + quit = 0; + break; + } + wrefresh (win); + } + /* clean stuff up */ + for (i = 0; i < nerrors; ++i) + free (menu->items[i].name); + free (menu->items); + free (menu); + + touchwin (parent_win); + close_win (win); + wrefresh (parent_win); +} + +/* Render the config log date/format dialog. + * + * On error, or if the selected format is invalid, 1 is returned. + * On success, 0 is returned. */ +int +render_confdlg (Logs *logs, GSpinner *spinner) { + GMenu *menu; + WINDOW *win; + + const char *log_err = NULL; + char *date_format = NULL, *log_format = NULL, *time_format = NULL; + char *cstm_log, *cstm_date, *cstm_time; + int c, quit = 1, invalid = 1, y, x, h = CONF_WIN_H, w = CONF_WIN_W; + int w2 = w - 2; + size_t i, n, sel; + + /* conf dialog menu options */ + static const char *const choices[] = { + "NCSA Combined Log Format", + "NCSA Combined Log Format with Virtual Host", + "Common Log Format (CLF)", + "Common Log Format (CLF) with Virtual Host", + "W3C", + "CloudFront (Download Distribution)", + "Google Cloud Storage", + "AWS Elastic Load Balancing (HTTP/S)", + "Squid Native Format", + "AWS Simple Storage Service (S3)", + "CADDY JSON Structured", + "AWS Application Load Balancer", + "Traefik CLF flavor" + }; + n = ARRAY_SIZE (choices); + getmaxyx (stdscr, y, x); + + win = newwin (h, w, (y - h) / 2, (x - w) / 2); + keypad (win, TRUE); + wborder (win, '|', '|', '-', '-', '+', '+', '+', '+'); + + /* create a new instance of GMenu and make it selectable */ + menu = new_gmenu (win, CONF_MENU_H, CONF_MENU_W, CONF_MENU_Y, CONF_MENU_X); + menu->size = n; + menu->selectable = 1; + + /* add items to GMenu */ + menu->items = (GItem *) xcalloc (n, sizeof (GItem)); + for (i = 0; i < n; ++i) { + menu->items[i].name = alloc_string (choices[i]); + sel = get_selected_format_idx (); + menu->items[i].checked = sel == i ? 1 : 0; + } + post_gmenu (menu); + draw_formats (win, w2); + + wrefresh (win); + while (quit) { + c = wgetch (stdscr); + switch (c) { + case KEY_DOWN: + gmenu_driver (menu, REQ_DOWN); + clear_confdlg_status_bar (win, 3, 2, CONF_MENU_W); + break; + case KEY_UP: + gmenu_driver (menu, REQ_UP); + clear_confdlg_status_bar (win, 3, 2, CONF_MENU_W); + break; + case 32: /* space */ + gmenu_driver (menu, REQ_SEL); + clear_confdlg_status_bar (win, 12, 1, CONF_MENU_W); + clear_confdlg_status_bar (win, 15, 1, CONF_MENU_W); + clear_confdlg_status_bar (win, 18, 1, CONF_MENU_W); + + if (time_format) + free (time_format); + if (date_format) + free (date_format); + if (log_format) + free (log_format); + + for (i = 0; i < n; ++i) { + if (menu->items[i].checked != 1) + continue; + + date_format = get_selected_date_str (i); + log_format = get_selected_format_str (i); + time_format = get_selected_time_str (i); + + free (set_default_string (win, 12, 2, CONF_MENU_W, log_format)); + free (set_default_string (win, 15, 2, CONF_MENU_W, date_format)); + free (set_default_string (win, 18, 2, CONF_MENU_W, time_format)); + break; + } + break; + case 99: /* c */ + /* clear top status bar */ + clear_confdlg_status_bar (win, 3, 2, CONF_MENU_W); + wmove (win, 12, 2); + + /* get input string */ + if (!log_format) + log_format = get_input_log_format (); + + cstm_log = input_string (win, 12, 2, CONF_MAX_LEN_DLG, log_format, 0, 0); + if (cstm_log != NULL && *cstm_log != '\0') { + if (log_format) + free (log_format); + + log_format = alloc_string (cstm_log); + free (cstm_log); + } + /* did not set an input string */ + else { + if (cstm_log) + free (cstm_log); + if (log_format) { + free (log_format); + log_format = NULL; + } + } + break; + case 100: /* d */ + /* clear top status bar */ + clear_confdlg_status_bar (win, 3, 2, CONF_MENU_W); + wmove (win, 15, 0); + + /* get input string */ + if (!date_format) + date_format = get_input_date_format (); + + cstm_date = input_string (win, 15, 2, 14, date_format, 0, 0); + if (cstm_date != NULL && *cstm_date != '\0') { + if (date_format) + free (date_format); + + date_format = alloc_string (cstm_date); + free (cstm_date); + } + /* did not set an input string */ + else { + if (cstm_date) + free (cstm_date); + if (date_format) { + free (date_format); + date_format = NULL; + } + } + break; + case 116: /* t */ + /* clear top status bar */ + clear_confdlg_status_bar (win, 3, 2, CONF_MENU_W); + wmove (win, 15, 0); + + /* get input string */ + if (!time_format) + time_format = get_input_time_format (); + + cstm_time = input_string (win, 18, 2, 14, time_format, 0, 0); + if (cstm_time != NULL && *cstm_time != '\0') { + if (time_format) + free (time_format); + + time_format = alloc_string (cstm_time); + free (cstm_time); + } + /* did not set an input string */ + else { + if (cstm_time) + free (cstm_time); + if (time_format) { + free (time_format); + time_format = NULL; + } + } + break; + case 274: /* F10 */ + case 0x0a: + case 0x0d: + case KEY_ENTER: + if ((log_err = set_formats (date_format, log_format, time_format))) + draw_header (win, log_err, " %s", 3, 2, CONF_MENU_W, color_error); + + if (!log_err) { + char **errors = NULL; + int nerrors = 0; + + /* test log against selected settings */ + if ((errors = test_format (logs, &nerrors))) { + invalid = 1; + load_confdlg_error (win, errors, nerrors); + } + /* valid data, reset glog & start parsing */ + else { + reset_struct (logs); + /* start spinner thread */ + spinner->win = win; + spinner->y = 3; + spinner->x = 2; + spinner->spin_x = CONF_MENU_W; + spinner->w = CONF_MENU_W; + spinner->color = color_progress; + ui_spinner_create (spinner); + + invalid = 0; + quit = 0; + } + } + break; + case KEY_RESIZE: + case 'q': + quit = 0; + break; + } + + pthread_mutex_lock (&spinner->mutex); + wrefresh (win); + pthread_mutex_unlock (&spinner->mutex); + } + + free (time_format); + free (date_format); + free (log_format); + + /* clean stuff up */ + for (i = 0; i < n; ++i) + free (menu->items[i].name); + free (menu->items); + free (menu); + + return invalid ? 1 : 0; +} + +/* Given the name of the selected scheme, set it under our config + * options. */ +static void +scheme_chosen (const char *name) { + int force = 0; + + free_color_lists (); + if (strcmp ("Green", name) == 0) { + conf.color_scheme = STD_GREEN; + force = 1; + } else if (strcmp ("Monochrome", name) == 0) { + conf.color_scheme = MONOCHROME; + force = 1; + } else if (strcmp ("Monokai", name) == 0) { + conf.color_scheme = MONOKAI; + force = 1; + } else if (strcmp ("Custom Scheme", name) == 0) { + force = 0; + } + init_colors (force); +} + +static const char ** +get_color_schemes (size_t *size) { + const char *choices[] = { + "Monokai", + "Monochrome", + "Green", + "Custom Scheme" + }; + int i, j, n = ARRAY_SIZE (choices); + const char **opts = xmalloc (sizeof (char *) * n); + + for (i = 0, j = 0; i < n; ++i) { + if (!conf.color_idx && !strcmp ("Custom Scheme", choices[i])) + continue; + if (COLORS < 256 && !strcmp ("Monokai", choices[i])) + continue; + opts[j++] = choices[i]; + } + *size = j; + + return opts; +} + +/* Render the schemes dialog. */ +void +load_schemes_win (WINDOW *main_win) { + GMenu *menu; + WINDOW *win; + int c, quit = 1; + size_t i, n = 0; + int y, x, h = SCHEME_WIN_H, w = SCHEME_WIN_W; + int w2 = w - 2; + const char **choices = get_color_schemes (&n); + + getmaxyx (stdscr, y, x); + + win = newwin (h, w, (y - h) / 2, (x - w) / 2); + keypad (win, TRUE); + wborder (win, '|', '|', '-', '-', '+', '+', '+', '+'); + + /* create a new instance of GMenu and make it selectable */ + menu = new_gmenu (win, SCHEME_MENU_H, SCHEME_MENU_W, SCHEME_MENU_Y, SCHEME_MENU_X); + /* remove custom color option if no custom scheme used */ + menu->size = n; + + /* add items to GMenu */ + menu->items = (GItem *) xcalloc (n, sizeof (GItem)); + for (i = 0; i < n; ++i) { + menu->items[i].name = alloc_string (choices[i]); + menu->items[i].checked = 0; + } + post_gmenu (menu); + + draw_header (win, SCHEMEDLG_HEAD, " %s", 1, 1, w2, color_panel_header); + mvwprintw (win, 2, 2, SCHEMEDLG_DESC); + + wrefresh (win); + while (quit) { + c = wgetch (stdscr); + switch (c) { + case KEY_DOWN: + gmenu_driver (menu, REQ_DOWN); + break; + case KEY_UP: + gmenu_driver (menu, REQ_UP); + break; + case 32: + case 0x0a: + case 0x0d: + case KEY_ENTER: + gmenu_driver (menu, REQ_SEL); + for (i = 0; i < n; ++i) { + if (menu->items[i].checked != 1) + continue; + scheme_chosen (choices[i]); + break; + } + quit = 0; + break; + case KEY_RESIZE: + case 'q': + quit = 0; + break; + } + wrefresh (win); + } + /* clean stuff up */ + for (i = 0; i < n; ++i) + free (menu->items[i].name); + free (menu->items); + free (menu); + free (choices); + + touchwin (main_win); + close_win (win); + wrefresh (main_win); +} + +/* Render the sort dialog. */ +void +load_sort_win (WINDOW *main_win, GModule module, GSort *sort) { + GMenu *menu; + WINDOW *win; + GSortField opts[SORT_MAX_OPTS]; + + int c, quit = 1; + int i = 0, k, n = 0; + int y, x, h = SORT_WIN_H, w = SORT_WIN_W; + int w2 = w - 2; + + getmaxyx (stdscr, y, x); + + /* determine amount of sort choices */ + for (i = 0, k = 0; -1 != sort_choices[module][i]; i++) { + GSortField field = sort_choices[module][i]; + if (SORT_BY_CUMTS == field && !conf.serve_usecs) + continue; + else if (SORT_BY_MAXTS == field && !conf.serve_usecs) + continue; + else if (SORT_BY_AVGTS == field && !conf.serve_usecs) + continue; + else if (SORT_BY_BW == field && !conf.bandwidth) + continue; + else if (SORT_BY_PROT == field && !conf.append_protocol) + continue; + else if (SORT_BY_MTHD == field && !conf.append_method) + continue; + opts[k++] = field; + n++; + } + + win = newwin (h, w, (y - h) / 2, (x - w) / 2); + keypad (win, TRUE); + wborder (win, '|', '|', '-', '-', '+', '+', '+', '+'); + + /* create a new instance of GMenu and make it selectable */ + menu = new_gmenu (win, SORT_MENU_H, SORT_MENU_W, SORT_MENU_Y, SORT_MENU_X); + menu->size = n; + menu->selectable = 1; + + /* add items to GMenu */ + menu->items = (GItem *) xcalloc (n, sizeof (GItem)); + + /* set choices, checked option and index */ + for (i = 0; i < n; ++i) { + GSortField field = sort_choices[module][opts[i]]; + if (SORT_BY_HITS == field) { + menu->items[i].name = alloc_string (MTRC_HITS_LBL); + if (sort->field == SORT_BY_HITS) { + menu->items[i].checked = 1; + menu->idx = i; + } + } else if (SORT_BY_VISITORS == field) { + menu->items[i].name = alloc_string (MTRC_VISITORS_LBL); + if (sort->field == SORT_BY_VISITORS) { + menu->items[i].checked = 1; + menu->idx = i; + } + } else if (SORT_BY_DATA == field) { + menu->items[i].name = alloc_string (MTRC_DATA_LBL); + if (sort->field == SORT_BY_DATA) { + menu->items[i].checked = 1; + menu->idx = i; + } + } else if (SORT_BY_BW == field) { + menu->items[i].name = alloc_string (MTRC_BW_LBL); + if (sort->field == SORT_BY_BW) { + menu->items[i].checked = 1; + menu->idx = i; + } + } else if (SORT_BY_AVGTS == field) { + menu->items[i].name = alloc_string (MTRC_AVGTS_LBL); + if (sort->field == SORT_BY_AVGTS) { + menu->items[i].checked = 1; + menu->idx = i; + } + } else if (SORT_BY_CUMTS == field) { + menu->items[i].name = alloc_string (MTRC_CUMTS_LBL); + if (sort->field == SORT_BY_CUMTS) { + menu->items[i].checked = 1; + menu->idx = i; + } + } else if (SORT_BY_MAXTS == field) { + menu->items[i].name = alloc_string (MTRC_MAXTS_LBL); + if (sort->field == SORT_BY_MAXTS) { + menu->items[i].checked = 1; + menu->idx = i; + } + } else if (SORT_BY_PROT == field) { + menu->items[i].name = alloc_string (MTRC_PROTOCOLS_LBL); + if (sort->field == SORT_BY_PROT) { + menu->items[i].checked = 1; + menu->idx = i; + } + } else if (SORT_BY_MTHD == field) { + menu->items[i].name = alloc_string (MTRC_METHODS_LBL); + if (sort->field == SORT_BY_MTHD) { + menu->items[i].checked = 1; + menu->idx = i; + } + } + } + post_gmenu (menu); + + draw_header (win, SORTDLG_HEAD, " %s", 1, 1, w2, color_panel_header); + mvwprintw (win, 2, 2, SORTDLG_DESC); + + if (sort->sort == SORT_ASC) + mvwprintw (win, SORT_WIN_H - 2, 1, " %s", SORT_ASC_SEL); + else + mvwprintw (win, SORT_WIN_H - 2, 1, " %s", SORT_DESC_SEL); + + wrefresh (win); + while (quit) { + c = wgetch (stdscr); + switch (c) { + case KEY_DOWN: + gmenu_driver (menu, REQ_DOWN); + break; + case KEY_UP: + gmenu_driver (menu, REQ_UP); + break; + case 9: /* TAB */ + if (sort->sort == SORT_ASC) { + /* ascending */ + sort->sort = SORT_DESC; + mvwprintw (win, SORT_WIN_H - 2, 1, " %s", SORT_DESC_SEL); + } else { + /* descending */ + sort->sort = SORT_ASC; + mvwprintw (win, SORT_WIN_H - 2, 1, " %s", SORT_ASC_SEL); + } + break; + case 32: + case 0x0a: + case 0x0d: + case KEY_ENTER: + gmenu_driver (menu, REQ_SEL); + for (i = 0; i < n; ++i) { + if (menu->items[i].checked != 1) + continue; + if (strcmp ("Hits", menu->items[i].name) == 0) + sort->field = SORT_BY_HITS; + else if (strcmp ("Visitors", menu->items[i].name) == 0) + sort->field = SORT_BY_VISITORS; + else if (strcmp ("Data", menu->items[i].name) == 0) + sort->field = SORT_BY_DATA; + else if (strcmp ("Tx. Amount", menu->items[i].name) == 0) + sort->field = SORT_BY_BW; + else if (strcmp ("Avg. T.S.", menu->items[i].name) == 0) + sort->field = SORT_BY_AVGTS; + else if (strcmp ("Cum. T.S.", menu->items[i].name) == 0) + sort->field = SORT_BY_CUMTS; + else if (strcmp ("Max. T.S.", menu->items[i].name) == 0) + sort->field = SORT_BY_MAXTS; + else if (strcmp ("Protocol", menu->items[i].name) == 0) + sort->field = SORT_BY_PROT; + else if (strcmp ("Method", menu->items[i].name) == 0) + sort->field = SORT_BY_MTHD; + quit = 0; + break; + } + break; + case KEY_RESIZE: + case 'q': + quit = 0; + break; + } + wrefresh (win); + } + + /* clean stuff up */ + for (i = 0; i < n; ++i) + free (menu->items[i].name); + free (menu->items); + free (menu); + + touchwin (main_win); + close_win (win); + wrefresh (main_win); +} + +/* Help menu data (F1/h). */ +static const char *const help_main[] = { + "Copyright (C) 2009-2024 by Gerardo Orellana", + "https://goaccess.io - ", + "Released under the MIT License.", + "", + "See `man` page for more details", + "", + "GoAccess is an open source real-time web log analyzer and", + "interactive viewer that runs in a terminal in *nix systems.", + "It provides fast and valuable HTTP statistics for system", + "administrators that require a visual server report on the", + "fly.", + "", + "The data collected based on the parsing of the log is", + "divided into different modules. Modules are automatically", + "generated and presented to the user.", + "", + "The main dashboard displays general statistics, top", + "visitors, requests, browsers, operating systems,", + "hosts, etc.", + "", + "The user can make use of the following keys:", + " ^F1^ or ^h^ Main help", + " ^F5^ Redraw [main window]", + " ^q^ Quit the program, current window or module", + " ^o^ or ^ENTER^ Expand selected module", + " ^[Shift]0-9^ Set selected module to active", + " ^Up^ arrow Scroll up main dashboard", + " ^Down^ arrow Scroll down main dashboard", + " ^j^ Scroll down within expanded module", + " ^k^ Scroll up within expanded module", + " ^c^ Set or change scheme color", + " ^CTRL^ + ^f^ Scroll forward one screen within", + " active module", + " ^CTRL^ + ^b^ Scroll backward one screen within", + " active module", + " ^TAB^ Iterate modules (forward)", + " ^SHIFT^ + ^TAB^ Iterate modules (backward)", + " ^s^ Sort options for current module", + " ^/^ Search across all modules", + " ^n^ Find position of the next occurrence", + " ^g^ Move to the first item or top of screen", + " ^G^ Move to the last item or bottom of screen", + "", + "Examples can be found by running `man goaccess`.", + "", + "If you believe you have found a bug, please drop me", + "an email with details.", + "", + "Feedback? Just shoot me an email to:", + "hello@goaccess.io", +}; + +/* Render the help dialog. */ +void +load_help_popup (WINDOW *main_win) { + int c, quit = 1; + size_t i, n; + int y, x, h = HELP_WIN_HEIGHT, w = HELP_WIN_WIDTH; + int w2 = w - 2; + WINDOW *win; + GMenu *menu; + + n = ARRAY_SIZE (help_main); + getmaxyx (stdscr, y, x); + + win = newwin (h, w, (y - h) / 2, (x - w) / 2); + keypad (win, TRUE); + wborder (win, '|', '|', '-', '-', '+', '+', '+', '+'); + + /* create a new instance of GMenu and make it selectable */ + menu = new_gmenu (win, HELP_MENU_HEIGHT, HELP_MENU_WIDTH, HELP_MENU_Y, HELP_MENU_X); + menu->size = n; + + /* add items to GMenu */ + menu->items = (GItem *) xcalloc (n, sizeof (GItem)); + for (i = 0; i < n; ++i) { + menu->items[i].name = alloc_string (help_main[i]); + menu->items[i].checked = 0; + } + post_gmenu (menu); + + draw_header (win, HELPDLG_HEAD, " %s", 1, 1, w2, color_panel_header); + mvwprintw (win, 2, 2, HELPDLG_DESC); + + wrefresh (win); + while (quit) { + c = wgetch (stdscr); + switch (c) { + case KEY_DOWN: + gmenu_driver (menu, REQ_DOWN); + break; + case KEY_UP: + gmenu_driver (menu, REQ_UP); + break; + case KEY_RESIZE: + case 'q': + quit = 0; + break; + } + wrefresh (win); + } + /* clean stuff up */ + for (i = 0; i < n; ++i) + free (menu->items[i].name); + free (menu->items); + free (menu); + + touchwin (main_win); + close_win (win); + wrefresh (main_win); +} diff --git a/src/ui.h b/src/ui.h new file mode 100644 index 0000000000..0215913a89 --- /dev/null +++ b/src/ui.h @@ -0,0 +1,260 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef UI_H_INCLUDED +#define UI_H_INCLUDED + +#ifdef HAVE_NCURSESW_NCURSES_H +#include +#elif HAVE_NCURSES_NCURSES_H +#include +#elif HAVE_NCURSES_H +#include +#elif HAVE_CURSES_H +#include +#endif + +#ifdef HAVE_LIBPTHREAD +#include +#endif + +/* string literals and translations */ +#include "labels.h" +#include "commons.h" + +/* Global UI defaults */ +#define MIN_HEIGHT 8 /* minimum window height */ +#define MIN_WIDTH 0 /* minimum window width */ +#define MAX_HEIGHT_FOOTER 1 /* height of the footer window */ +#define MAX_HEIGHT_HEADER 7 /* height of the header window */ +#define OVERALL_NUM_COLS 4 /* number of columns on the overall stats win */ + +/* Spinner Label Format */ +#define SPIN_FMT "%s" +#define SPIN_FMTM "[%s %s] {%'"PRIu64"} @ {%'lld/s}" +#define SPIN_LBL 256 /* max length of the progress spinner */ + +#define SPIN_UPDATE_INTERVAL 100000000 /* in nanoseconds */ + +/* Module JSON keys */ +#define VISITORS_ID "visitors" +#define REQUESTS_ID "requests" +#define REQUESTS_STATIC_ID "static_requests" +#define VISIT_TIMES_ID "visit_time" +#define VIRTUAL_HOSTS_ID "vhosts" +#define REMOTE_USER_ID "remote_user" +#define CACHE_STATUS_ID "cache_status" +#define NOT_FOUND_ID "not_found" +#define HOSTS_ID "hosts" +#define OS_ID "os" +#define BROWSERS_ID "browsers" +#define REFERRERS_ID "referrers" +#define REFERRING_SITES_ID "referring_sites" +#define KEYPHRASES_ID "keyphrases" +#define GEO_LOCATION_ID "geolocation" +#define ASN_ID "asn" +#define STATUS_CODES_ID "status_codes" +#define GENER_ID "general" + +#define MIME_TYPE_ID "mime_type" +#define TLS_TYPE_ID "tls_type" + +/* Overall Statistics CSV/JSON Keys */ +#define OVERALL_STARTDATE "start_date" +#define OVERALL_ENDDATE "end_date" +#define OVERALL_DATETIME "date_time" +#define OVERALL_REQ "total_requests" +#define OVERALL_VALID "valid_requests" +#define OVERALL_GENTIME "generation_time" +#define OVERALL_FAILED "failed_requests" +#define OVERALL_VISITORS "unique_visitors" +#define OVERALL_FILES "unique_files" +#define OVERALL_EXCL_HITS "excluded_hits" +#define OVERALL_REF "unique_referrers" +#define OVERALL_NOTFOUND "unique_not_found" +#define OVERALL_STATIC "unique_static_files" +#define OVERALL_LOGSIZE "log_size" +#define OVERALL_BANDWIDTH "bandwidth" +#define OVERALL_LOG "log_path" + +/* CONFIG DIALOG */ +#define CONF_MENU_H 6 +#define CONF_MENU_W 67 +#define CONF_MENU_X 2 +#define CONF_MENU_Y 4 +#define CONF_WIN_H 20 +#define CONF_WIN_W 71 +#define CONF_MAX_LEN_DLG 512 + +/* FIND DIALOG */ +#define FIND_DLG_HEIGHT 8 +#define FIND_DLG_WIDTH 50 +#define FIND_MAX_MATCHES 1 + +/* COLOR SCHEME DIALOG */ +#define SCHEME_MENU_H 4 +#define SCHEME_MENU_W 38 +#define SCHEME_MENU_X 2 +#define SCHEME_MENU_Y 4 +#define SCHEME_WIN_H 10 +#define SCHEME_WIN_W 42 + +/* SORT DIALOG */ +#define SORT_MENU_H 6 +#define SORT_MENU_W 38 +#define SORT_MENU_X 2 +#define SORT_MENU_Y 4 +#define SORT_WIN_H 13 +#define SORT_WIN_W 42 + +/* AGENTS DIALOG */ +#define AGENTS_MENU_X 2 +#define AGENTS_MENU_Y 4 + +/* HELP DIALOG */ +#define HELP_MENU_HEIGHT 12 +#define HELP_MENU_WIDTH 60 +#define HELP_MENU_X 2 +#define HELP_MENU_Y 4 +#define HELP_WIN_HEIGHT 17 +#define HELP_WIN_WIDTH 64 + +/* CONF ERROR DIALOG */ +#define ERR_MENU_HEIGHT 10 +#define ERR_MENU_WIDTH 67 +#define ERR_MENU_X 2 +#define ERR_MENU_Y 4 +#define ERR_WIN_HEIGHT 15 +#define ERR_WIN_WIDTH 71 + +#include "color.h" +#include "commons.h" +#include "sort.h" + +/* Curses dashboard find */ +typedef struct GFind_ { + GModule module; + char *pattern; + int next_idx; + int next_parent_idx; + int next_sub_idx; + int look_in_sub; + int done; + int icase; +} GFind; + +/* Each panel contains its own scrolling and offset */ +typedef struct GScrollModule_ { + int scroll; + int offset; +} GScrollModule; + +/* Curses Scrolling */ +typedef struct GScroll_ { + GScrollModule module[TOTAL_MODULES]; + GModule current; + int dash; + int expanded; +} GScroll; + +/* Spinner or Progress Indicator */ +typedef struct GSpinner_ { + const char *label; + GColors *(*color) (void); + int curses; + int spin_x; + int w; + int x; + int y; + pthread_mutex_t mutex; + pthread_t thread; + uint64_t **processed; + char **filename; + WINDOW *win; + enum { + SPN_RUN, + SPN_END + } state; +} GSpinner; + +/* Controls metric output. + * i.e., which metrics it should display */ +typedef struct GOutput_ { + GModule module; + int8_t visitors; + int8_t hits; + int8_t percent; + int8_t bw; + int8_t avgts; + int8_t cumts; + int8_t maxts; + int8_t protocol; + int8_t method; + int8_t data; + int8_t graph; /* display bars when collapsed */ + int8_t sub_graph; /* display bars upon expanding it */ +} GOutput; + +/* *INDENT-OFF* */ +const GOutput *output_lookup (GModule module); +GSpinner *new_gspinner (void); + +char *get_browser_type (char *line); +char *get_overall_header (GHolder *h); +char *input_string (WINDOW * win, int pos_y, int pos_x, size_t max_width, const char *str, int enable_case, int *toggle_case); +const char *module_to_desc (GModule module); +const char *module_to_head (GModule module); +const char *module_to_id (GModule module); +const char *module_to_label (GModule module); +GAgents *load_host_agents (const char *addr); +int get_start_end_parsing_dates (char **start, char **end, const char *f); +int render_confdlg (Logs * logs, GSpinner * spinner); +void close_win (WINDOW * w); +void display_general (WINDOW * win, GHolder *h); +void draw_header (WINDOW * win, const char *s, const char *fmt, int y, int x, int w, GColors * (*func) (void)); +void end_spinner (void); +void generate_time (void); +void init_colors (int force); +void init_windows (WINDOW ** header_win, WINDOW ** main_win); +void load_agent_list (WINDOW * main_win, char *addr); +void load_help_popup (WINDOW * main_win); +void load_schemes_win (WINDOW * main_win); +void load_sort_win (WINDOW * main_win, GModule module, GSort * sort); +void lock_spinner (void); +void set_curses_spinner (GSpinner *spinner); +void set_input_opts (void); +void set_wbkgd (WINDOW *main_win, WINDOW *header_win); +void term_size (WINDOW * main_win, int *main_win_height); +void ui_spinner_create (GSpinner * spinner); +void unlock_spinner (void); +void update_active_module (WINDOW * header_win, GModule current); +void update_header (WINDOW * header_win, int current); +/* *INDENT-ON* */ + +#endif diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000000..b26ca74bbb --- /dev/null +++ b/src/util.c @@ -0,0 +1,1223 @@ +/** + * util.c -- a set of handy functions to help parsing + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#define _LARGEFILE_SOURCE +#define _LARGEFILE64_SOURCE +#define _FILE_OFFSET_BITS 64 + +#define _GNU_SOURCE +#define _DEFAULT_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "util.h" + +#include "error.h" +#include "labels.h" +#include "xmalloc.h" + +pthread_mutex_t tz_mutex = PTHREAD_MUTEX_INITIALIZER; + +/* HTTP status codes categories */ +static const char *const code_type[] = { + STATUS_CODE_0XX, + STATUS_CODE_1XX, + STATUS_CODE_2XX, + STATUS_CODE_3XX, + STATUS_CODE_4XX, + STATUS_CODE_5XX, +}; + +/* HTTP status codes */ +static const char *const codes[600] = { + [0] = STATUS_CODE_0, + [100] = STATUS_CODE_100, STATUS_CODE_101, + [200] = STATUS_CODE_200, STATUS_CODE_201, STATUS_CODE_202, STATUS_CODE_203, STATUS_CODE_204, + [205] = STATUS_CODE_205, STATUS_CODE_206, STATUS_CODE_207, STATUS_CODE_208, + [218] = STATUS_CODE_218, + [300] = STATUS_CODE_300, STATUS_CODE_301, STATUS_CODE_302, STATUS_CODE_303, STATUS_CODE_304, + [305] = STATUS_CODE_305, NULL, STATUS_CODE_307, STATUS_CODE_308, + [400] = STATUS_CODE_400, STATUS_CODE_401, STATUS_CODE_402, STATUS_CODE_403, STATUS_CODE_404, + [405] = STATUS_CODE_405, STATUS_CODE_406, STATUS_CODE_407, STATUS_CODE_408, STATUS_CODE_409, + [410] = STATUS_CODE_410, STATUS_CODE_411, STATUS_CODE_412, STATUS_CODE_413, STATUS_CODE_414, + [415] = STATUS_CODE_415, STATUS_CODE_416, STATUS_CODE_417, STATUS_CODE_418, STATUS_CODE_419, + [420] = STATUS_CODE_420, STATUS_CODE_421, STATUS_CODE_422, STATUS_CODE_423, STATUS_CODE_424, + [425] = NULL, STATUS_CODE_426, NULL, STATUS_CODE_428, STATUS_CODE_429, STATUS_CODE_430, + [431] = STATUS_CODE_431, + [440] = STATUS_CODE_440, + [444] = STATUS_CODE_444, + [449] = STATUS_CODE_449, + [450] = STATUS_CODE_450, + [451] = STATUS_CODE_451, + [460] = STATUS_CODE_460, STATUS_CODE_463, STATUS_CODE_464, + [494] = STATUS_CODE_494, + [495] = STATUS_CODE_495, STATUS_CODE_496, STATUS_CODE_497, STATUS_CODE_498, STATUS_CODE_499, + [500] = STATUS_CODE_500, STATUS_CODE_501, STATUS_CODE_502, STATUS_CODE_503, STATUS_CODE_504, + [505] = STATUS_CODE_505, + [509] = STATUS_CODE_509, + [520] = STATUS_CODE_520, STATUS_CODE_521, STATUS_CODE_522, STATUS_CODE_523, STATUS_CODE_524, + STATUS_CODE_525, STATUS_CODE_526, STATUS_CODE_527, STATUS_CODE_529, + [530] = STATUS_CODE_530, + [540] = STATUS_CODE_540, + [561] = STATUS_CODE_561, + [598] = STATUS_CODE_598, STATUS_CODE_599, +}; + +/* Return part of a string + * + * On error NULL is returned. + * On success the extracted part of string is returned */ +char * +substring (const char *str, int begin, int len) { + char *buffer; + if (str == NULL) + return NULL; + if (begin < 0) + begin = strlen (str) + begin; + if (begin < 0) + begin = 0; + if (len < 0) + len = 0; + if (((size_t) begin) > strlen (str)) + begin = strlen (str); + if (((size_t) len) > strlen (&str[begin])) + len = strlen (&str[begin]); + if ((buffer = xmalloc (len + 1)) == NULL) + return NULL; + memcpy (buffer, &(str[begin]), len); + buffer[len] = '\0'; + + return buffer; +} + +/* A pointer to the allocated memory of the new string + * + * On success, a pointer to a new string is returned */ +char * +alloc_string (const char *str) { + char *new = xmalloc (strlen (str) + 1); + strcpy (new, str); + return new; +} + +/* A wrapper function to copy the first num characters of source to + * destination. */ +void +xstrncpy (char *dest, const char *source, const size_t dest_size) { + strncpy (dest, source, dest_size); + if (dest_size > 0) { + dest[dest_size - 1] = '\0'; + } else { + dest[0] = '\0'; + } +} + +/* A random string generator. */ +void +genstr (char *dest, size_t len) { + char set[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + for (; len > 0; --len) + *dest++ = set[rand () % (sizeof (set) - 1)]; + *dest = '\0'; +} + +/* Count the number of matches on the string `s1` given a character `c` + * + * If the character is not found, 0 is returned + * On success, the number of characters found */ +int +count_matches (const char *s1, char c) { + const char *ptr = s1; + int n = 0; + do { + if (*ptr == c) + n++; + } while (*(ptr++)); + return n; +} + +/* Simple but efficient uint32_t hashing. */ +#if defined(__clang__) && defined(__clang_major__) && (__clang_major__ >= 4) +__attribute__((no_sanitize ("unsigned-integer-overflow"))) +#if (__clang_major__ >= 12) + __attribute__((no_sanitize ("unsigned-shift-base"))) +#endif +#endif + uint32_t +djb2 (const unsigned char *str) { + uint32_t hash = 5381; + int c; + + while ((c = *str++)) + hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ + + return hash; +} + +/* String matching where one string contains wildcard characters. + * + * If no match found, 1 is returned. + * If match found, 0 is returned. */ +static int +wc_match (const char *wc, char *str) { + while (*wc && *str) { + if (*wc == '*') { + while (*wc && *wc == '*') + wc++; + if (!*wc) + return 1; + + while (*str && *str != *wc) + str++; + } else if (*wc == '?' || *wc == *str) { + wc++; + str++; + } else { + break; + } + } + if (!*wc && !*str) + return 1; + return 0; +} + +/** + * Extracts the hostname part from a given URL. + * + * On error, NULL is returned. + * On success, a dynamically allocated string containing the hostname is returned. + */ +static char * +extract_hostname (const char *url) { + const char *start, *end; + char *hostname = NULL; + + start = strstr (url, "://"); + if (start != NULL) { + start += 3; + } else { + start = url; + } + + end = strchr (start, '/'); + if (end == NULL) { + /* no path, use the entire string */ + end = start + strlen (start); + } + + hostname = xmalloc (end - start + 1); + strncpy (hostname, start, end - start); + hostname[end - start] = '\0'; + + return hostname; +} + +/* Generic routine to extract all groups from a string given a POSIX regex. + * + * If no match found or error, NULL is returned. + * If match found, a string is returned. */ +char * +regex_extract_string (const char *str, const char *regex, int max_groups, char const **err) { + char *copy = NULL, *dest = NULL; + int i, ret = 0; + regex_t re; + regmatch_t groups[max_groups]; + + if (str == NULL || *str == '\0') { + *err = "Invalid string."; + return NULL; + } + + if (regcomp (&re, regex, REG_EXTENDED)) { + *err = "Unable to compile regular expression upon extraction"; + return NULL; + } + + ret = regexec (&re, str, max_groups, groups, 0); + if (ret == REG_NOMATCH) { + *err = "Unable to match regular expression extraction."; + goto out; + } + + if (ret != 0) { + *err = "Error while matching regular expression extraction."; + goto out; + } + + dest = xstrdup (""); + for (i = 0; i < max_groups; ++i) { + if (groups[i].rm_so == -1) + break; + + copy = xstrdup (str); + copy[groups[i].rm_eo] = 0; + + append_str (&dest, copy + groups[i].rm_so); + free (copy); + } + +out: + regfree (&re); + + return ret == 0 ? dest : NULL; +} + +static int +handle_referer (const char *host, const char **referers, int referer_idx) { + char *needle = NULL, *hostname = NULL; + int i, ignore = 0; + + if (referer_idx == 0) + return 0; + + if (host == NULL || *host == '\0') + return 0; + + needle = xstrdup (host); + for (i = 0; i < referer_idx; ++i) { + if (referers[i] == NULL || *referers[i] == '\0') + continue; + + if (strchr (referers[i], '*') != NULL || strchr (referers[i], '?') != NULL) { + if (wc_match (referers[i], needle)) { + ignore = 1; + goto out; + } + } else { + hostname = extract_hostname (host); + if (strcmp (referers[i], hostname) == 0) { + ignore = 1; + free (hostname); + goto out; + } + free (hostname); + } + } + +out: + free (needle); + return ignore; +} + +/* Determine if the given host needs to be ignored given the list of + * referrers to ignore. + * + * On error, or the referrer is not found, 0 is returned + * On success, or if the host needs to be ignored, 1 is returned */ +int +ignore_referer (const char *host) { + return handle_referer (host, conf.ignore_referers, conf.ignore_referer_idx); +} + +/* Determine if the given host needs to be hidden given the list of + * referrers to hide. + * + * On error, or the referrer is not found, 0 is returned + * On success, or if the host needs to be ignored, 1 is returned */ +int +hide_referer (const char *host) { + return handle_referer (host, conf.hide_referers, conf.hide_referer_idx); +} + +/* Determine if the given ip is within a range of IPs. + * + * On error, or not within the range, 0 is returned + * On success, or if within the range, 1 is returned */ +static int +within_range (const char *ip, const char *start, const char *end) { + struct in6_addr addr6, start6, end6; + struct in_addr addr4, start4, end4; + + if (start == NULL || *start == '\0') + return 0; + if (end == NULL || *end == '\0') + return 0; + if (ip == NULL || *ip == '\0') + return 0; + + /* IPv4 */ + if (1 == inet_pton (AF_INET, ip, &addr4)) { + if (1 != inet_pton (AF_INET, start, &start4)) + return 0; + if (1 != inet_pton (AF_INET, end, &end4)) + return 0; + if (memcmp (&addr4, &start4, sizeof (addr4)) >= 0 && + memcmp (&addr4, &end4, sizeof (addr4)) <= 0) + return 1; + } + /* IPv6 */ + else if (1 == inet_pton (AF_INET6, ip, &addr6)) { + if (1 != inet_pton (AF_INET6, start, &start6)) + return 0; + if (1 != inet_pton (AF_INET6, end, &end6)) + return 0; + if (memcmp (&addr6, &start6, sizeof (addr6)) >= 0 && + memcmp (&addr6, &end6, sizeof (addr6)) <= 0) + return 1; + } + + return 0; +} + +/* Determine if the given IP needs to be ignored given the list of IPs + * to ignore. + * + * On error, or not within the range, 0 is returned + * On success, or if within the range, 1 is returned */ +int +ip_in_range (const char *ip) { + char *start, *end, *dash; + int i; + + for (i = 0; i < conf.ignore_ip_idx; ++i) { + end = NULL; + if (conf.ignore_ips[i] == NULL || *conf.ignore_ips[i] == '\0') + continue; + + start = xstrdup (conf.ignore_ips[i]); + /* split range */ + if ((dash = strchr (start, '-')) != NULL) { + *dash = '\0'; + end = dash + 1; + } + + /* matches single IP */ + if (end == NULL) { + if (strcmp (ip, start) == 0) { + free (start); + return 1; + } + } + /* within range */ + else { + if (within_range (ip, start, end)) { + free (start); + return 1; + } + } + free (start); + } + + return 0; +} + +/* Searches the array of output formats for the given extension value. + * + * If not found, 1 is returned. + * On success, the given filename is malloc'd and assigned and 0 is + * returned. */ +int +find_output_type (char **filename, const char *ext, int alloc) { + int i; + const char *dot = NULL; + + for (i = 0; i < conf.output_format_idx; ++i) { + /* for backwards compatibility. i.e., -o json */ + if (strcmp (conf.output_formats[i], ext) == 0) + return 0; + + if ((dot = strrchr (conf.output_formats[i], '.')) != NULL && strcmp (dot + 1, ext) == 0) { + if (alloc) + *filename = xstrdup (conf.output_formats[i]); + return 0; + } + } + + return 1; +} + +/* Validates the '-o' filename extension for any of: + * 1) .csv + * 2) .json + * 3) .html + * + * Return Value + * 1: valid + * 0: invalid + * -1: non-existent extension + */ +int +valid_output_type (const char *filename) { + const char *ext = NULL; + size_t sl; + + if ((ext = strrchr (filename, '.')) == NULL) + return -1; + + ext++; + /* Is extension 3<=len<=4? */ + sl = strlen (ext); + if (sl < 3 || sl > 4) + return 0; + + if (strcmp ("html", ext) == 0) + return 1; + + if (strcmp ("json", ext) == 0) + return 1; + + if (strcmp ("csv", ext) == 0) + return 1; + + return 0; +} + +/* Get the path to the user config file (ie. HOME/.goaccessrc). + * + * On error, it returns NULL. + * On success, the path of the user config file is returned. */ +char * +get_user_config (void) { + char *user_home = NULL, *path = NULL; + size_t len; + + user_home = getenv ("HOME"); + if (user_home == NULL) + return NULL; + + len = snprintf (NULL, 0, "%s/.goaccessrc", user_home) + 1; + path = xmalloc (len); + snprintf (path, len, "%s/.goaccessrc", user_home); + + return path; +} + +/* Get the path to the global config file. + * + * On success, the path of the global config file is returned. */ +char * +get_global_config (void) { + char *path = NULL; + size_t len; + + len = snprintf (NULL, 0, "%s/goaccess/goaccess.conf", SYSCONFDIR) + 1; + path = xmalloc (len); + snprintf (path, len, "%s/goaccess/goaccess.conf", SYSCONFDIR); + + return path; +} + +/* A self-checking wrapper to convert_date(). + * + * On error, a newly malloc'd '---' string is returned. + * On success, a malloc'd 'Ymd' date is returned. */ +char * +get_visitors_date (const char *odate, const char *from, const char *to) { + char date[DATE_TIME] = ""; /* Ymd */ + + memset (date, 0, sizeof *date); + /* verify we have a valid date conversion */ + if (convert_date (date, odate, from, to, DATE_TIME) == 0) + return xstrdup (date); + + LOG_DEBUG (("invalid date: %s", odate)); + return xstrdup ("---"); +} + +static time_t +tm2time (const struct tm *src) { + struct tm tmp; + + tmp = *src; + return timegm (&tmp) - src->tm_gmtoff; +} + +void +set_tz (void) { + /* this will persist for the duration of the program but also assumes that all + * threads have the same conf.tz_name values */ + static char tz[TZ_NAME_LEN] = { 0 }; + + if (!conf.tz_name) + return; + + if (pthread_mutex_lock (&tz_mutex) != 0) { + LOG_DEBUG (("Failed to acquire tz_mutex")); + return; + } + + snprintf (tz, TZ_NAME_LEN, "TZ=%s", conf.tz_name); + if ((putenv (tz)) != 0) { + int old_errno = errno; + LOG_DEBUG (("Can't set TZ env variable %s: %s: %d\n", tz, strerror (old_errno), old_errno)); + goto release; + } + + tzset (); + +release: + + if (pthread_mutex_unlock (&tz_mutex) != 0) { + LOG_DEBUG (("Failed to release tz_mutex")); + } + + return; +} + +#if defined(__linux__) && !defined(__GLIBC__) +static int +parse_tz_specifier (const char *str, const char *fmt, struct tm *tm) { + char *fmt_notz = NULL, *p = NULL, *end = NULL, *ptr = NULL; + int tz_offset_hours = 0, tz_offset_minutes = 0, neg = 0; + + /* new format string that excludes %z */ + fmt_notz = xstrdup (fmt); + + p = strstr (fmt_notz, "%z"); + if (p != NULL) + *p = '\0'; + + /* parse date/time without timezone offset */ + end = strptime (str, fmt_notz, tm); + free (fmt_notz); + if (end == NULL) + return 1; + + /* bail early if no timezone offset is expected */ + if (*end == '\0') { + tm->tm_gmtoff = 0; + return 0; + } + + /* try to parse timezone offset else bail early, +/-0500 */ + if ((*end != '+' && *end != '-') || strlen (end) < 4) + return 1; + + /* divide by 100 to extract the hours part (e.g., 400 / 100 = 4) */ + tz_offset_hours = labs (strtol (end, &ptr, 10)) / 100; + if (*ptr != '\0') + return 1; + + if (strlen (end) >= 5) { + /* minutes part of the offset is present */ + tz_offset_minutes = strtol (end + 3, &ptr, 10); + if (*ptr != '\0') + return 1; + } + + neg = (*end == '-'); + tm->tm_gmtoff = (tz_offset_hours * 3600 + tz_offset_minutes * 60) * (neg ? -1 : 1); + + return 0; +} +#endif + +/* Format the given date/time according the given format. + * + * On error, 1 is returned. + * On success, 0 is returned. */ +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +int +str_to_time (const char *str, const char *fmt, struct tm *tm, int tz) { + time_t t; + char *end = NULL, *sEnd = NULL; + unsigned long long ts = 0; + int us, ms; +#if !defined(__GLIBC__) + int se; +#endif + + time_t seconds = 0; + + if (str == NULL || *str == '\0' || fmt == NULL || *fmt == '\0') + return 1; + + us = strcmp ("%f", fmt) == 0; + ms = strcmp ("%*", fmt) == 0; +#if !defined(__GLIBC__) + se = strcmp ("%s", fmt) == 0; +#endif + + /* check if char string needs to be converted from milli/micro seconds */ + /* note that MUSL doesn't have %s under strptime(3) */ +#if !defined(__GLIBC__) + if (se || us || ms) { +#else + if (us || ms) { +#endif + errno = 0; + + ts = strtoull (str, &sEnd, 10); + if (str == sEnd || *sEnd != '\0' || errno == ERANGE) + return 1; + + seconds = (us) ? ts / SECS : ((ms) ? ts / MILS : ts); + + if (conf.tz_name && tz) + set_tz (); + + /* if GMT needed, gmtime_r instead of localtime_r. */ + localtime_r (&seconds, tm); + + return 0; + } +#if defined(__linux__) && !defined(__GLIBC__) + if (parse_tz_specifier (str, fmt, tm)) + return -1; +#else + end = strptime (str, fmt, tm); + if (end == NULL || *end != '\0') + return 1; +#endif + + if (!tz || !conf.tz_name) + return 0; + + if ((t = tm2time (tm)) == -1) { + LOG_DEBUG (("Can't set time via tm2time() %s: %s\n", str, strerror (errno))); + return 0; + } + + set_tz (); + localtime_r (&t, tm); + + return 0; +} + +/* Convert a date from one format to another and store in the given buffer. + * + * On error, 1 is returned. + * On success, 0 is returned. */ +int +convert_date (char *res, const char *data, const char *from, const char *to, int size) { + struct tm tm; + + memset (&tm, 0, sizeof (tm)); + timestamp = time (NULL); + localtime_r (×tamp, &now_tm); + + /* This assumes that the given date is already in the correct timezone. */ + if (str_to_time (data, from, &tm, 0) != 0) + return 1; + + /* if not a timestamp, use current year if not passed */ + if (!has_timestamp (from) && strpbrk (from, "Yy") == NULL) + tm.tm_year = now_tm.tm_year; + + if (strftime (res, size, to, &tm) <= 0) + return 1; + + return 0; +} + +#pragma GCC diagnostic warning "-Wformat-nonliteral" + +/* Determine if the given IP is a valid IPv4/IPv6 address. + * + * On error, 1 is returned. + * On success, 0 is returned. */ +int +invalid_ipaddr (const char *str, int *ipvx) { + union { + struct sockaddr addr; + struct sockaddr_in6 addr6; + struct sockaddr_in addr4; + } a; + + (*ipvx) = TYPE_IPINV; + if (str == NULL || *str == '\0') + return 1; + + memset (&a, 0, sizeof (a)); + if (1 == inet_pton (AF_INET, str, &a.addr4.sin_addr)) { + (*ipvx) = TYPE_IPV4; + return 0; + } else if (1 == inet_pton (AF_INET6, str, &a.addr6.sin6_addr)) { + (*ipvx) = TYPE_IPV6; + return 0; + } + + return 1; +} + +/* Encode a data key and a unique visitor's key to a new uint64_t key + * + * ###NOTE: THIS LIMITS THE MAX VALUE OF A DATA TABLE TO uint32_t + * WILL NEED TO CHANGE THIS IF WE GO OVER uint32_t + */ +uint64_t +u64encode (uint32_t x, uint32_t y) { + return x > y ? (uint32_t) y | ((uint64_t) x << 32) : (uint32_t) x | ((uint64_t) y << 32); +} + +/* Decode a uint64_t number into the original two uint32_t */ +void +u64decode (uint64_t n, uint32_t *x, uint32_t *y) { + *x = (uint64_t) n >> 32; + *y = (uint64_t) n & 0xFFFFFFFF; +} + +/* Get information about the filename. + * + * On error, -1 is returned. + * On success, the file size of the given filename. */ +off_t +file_size (const char *filename) { + struct stat st; + + if (stat (filename, &st) == 0) + return st.st_size; + + LOG_DEBUG (("Can't determine size of %s: %s\n", filename, strerror (errno))); + + return -1; +} + +/* Determine if the given status code is within the list of status + * codes and find out the status type/category. + * + * If not found, "Unknown" is returned. + * On success, the status code type/category is returned. */ +const char * +verify_status_code_type (int code) { + if (code < 0 || code > 599 || code_type[code / 100] == NULL) + return "Unknown"; + + return code_type[code / 100]; +} + +/* Determine if the given status code is within the list of status + * codes. + * + * If not found, "Unknown" is returned. + * On success, the status code is returned. */ +const char * +verify_status_code (int code) { + if (code < 0 || code > 599 || code_type[code / 100] == NULL || codes[code] == NULL) + return "Unknown"; + + return codes[code]; +} + +int +is_valid_http_status (int code) { + return code >= 0 && code <= 599 && code_type[code / 100] != NULL && codes[code] != NULL; +} + +/* Checks if the given string is within the given array. + * + * If not found, -1 is returned. + * If found, the key for needle in the array is returned. */ +int +str_inarray (const char *s, const char *arr[], int size) { + int i; + for (i = 0; i < size; i++) { + if (strcmp (arr[i], s) == 0) + return i; + } + return -1; +} + +/* Strip whitespace from the beginning of a string. + * + * On success, a string with whitespace stripped from the beginning of + * the string is returned. */ +char * +ltrim (char *s) { + char *begin = s; + + while (isspace ((unsigned char) *begin)) + ++begin; + memmove (s, begin, strlen (begin) + 1); + + return s; +} + +/* Strip whitespace from the end of a string. + * + * On success, a string with whitespace stripped from the end of the + * string is returned. */ +char * +rtrim (char *s) { + char *end = s + strlen (s); + + while ((end != s) && isspace ((unsigned char) *(end - 1))) + --end; + *end = '\0'; + + return s; +} + +/* Strip whitespace from the beginning and end of the string. + * + * On success, the trimmed string is returned. */ +char * +trim_str (char *str) { + return rtrim (ltrim (str)); +} + +/* Convert the file size in bytes to a human-readable format. + * + * On error, the original size of the string in bytes is returned. + * On success, the file size in a human-readable format is returned. */ +char * +filesize_str (unsigned long long log_size) { + char *size = xmalloc (sizeof (char) * 12); + if (log_size >= (1ULL << 50)) + snprintf (size, 12, "%.2f PiB", (double) (log_size) / PIB (1ULL)); + else if (log_size >= (1ULL << 40)) + snprintf (size, 12, "%.2f TiB", (double) (log_size) / TIB (1ULL)); + else if (log_size >= (1ULL << 30)) + snprintf (size, 12, "%.2f GiB", (double) (log_size) / GIB (1ULL)); + else if (log_size >= (1ULL << 20)) + snprintf (size, 12, "%.2f MiB", (double) (log_size) / MIB (1ULL)); + else if (log_size >= (1ULL << 10)) + snprintf (size, 12, "%.2f KiB", (double) (log_size) / KIB (1ULL)); + else + snprintf (size, 12, "%.1f B", (double) (log_size)); + + return size; +} + +/* Convert microseconds to a human-readable format. + * + * On error, a malloc'd string in microseconds is returned. + * On success, the time in a human-readable format is returned. */ +char * +usecs_to_str (unsigned long long usec) { + char *size = xmalloc (sizeof (char) * 11); + if (usec >= DAY) + snprintf (size, 11, "%.2f d", (double) (usec) / DAY); + else if (usec >= HOUR) + snprintf (size, 11, "%.2f hr", (double) (usec) / HOUR); + else if (usec >= MINS) + snprintf (size, 11, "%.2f mn", (double) (usec) / MINS); + else if (usec >= SECS) + snprintf (size, 11, "%.2f s", (double) (usec) / SECS); + else if (usec >= MILS) + snprintf (size, 11, "%.2f ms", (double) (usec) / MILS); + else + snprintf (size, 11, "%.2f us", (double) (usec)); + + return size; +} + +/* Convert the given int to a string with the ability to add some + * padding. + * + * On success, the given number as a string is returned. */ +char * +int2str (int d, int width) { + char *s = xmalloc (snprintf (NULL, 0, "%*d", width, d) + 1); + sprintf (s, "%*d", width, d); + + return s; +} + +/* Convert the given uint32_t to a string with the ability to add some + * padding. + * + * On success, the given number as a string is returned. */ +char * +u322str (uint32_t d, int width) { + char *s = xmalloc (snprintf (NULL, 0, "%*u", width, d) + 1); + sprintf (s, "%*u", width, d); + + return s; +} + +/* Convert the given uint64_t to a string with the ability to add some + * padding. + * + * On success, the given number as a string is returned. */ +char * +u642str (uint64_t d, int width) { + char *s = xmalloc (snprintf (NULL, 0, "%*" PRIu64, width, d) + 1); + sprintf (s, "%*" PRIu64, width, d); + + return s; +} + +/* Convert the given float to a string with the ability to add some + * padding. + * + * On success, the given number as a string is returned. */ +char * +float2str (float d, int width) { + char *s = xmalloc (snprintf (NULL, 0, "%*.2f", width, d) + 1); + sprintf (s, "%*.2f", width, d); + + return s; +} + +int +ptr2int (char *ptr) { + char *sEnd = NULL; + int value = -1; + + value = strtol (ptr, &sEnd, 10); + if (ptr == sEnd || *sEnd != '\0' || errno == ERANGE) { + LOG_DEBUG (("Invalid parse of integer value from pointer. \n")); + return -1; + } + + return value; +} + +int +str2int (const char *date) { + char *sEnd = NULL; + int d = strtol (date, &sEnd, 10); + if (date == sEnd || *sEnd != '\0' || errno == ERANGE) + return -1; + return d; +} + +/* Determine the length of an integer (number of digits). + * + * On success, the length of the number is returned. */ +int +intlen (uint64_t num) { + int l = 1; + while (num > 9) { + l++; + num /= 10; + } + + return l; +} + +/* Allocate a new string and fill it with the given character. + * + * On success, the newly allocated string is returned. */ +char * +char_repeat (int n, char c) { + char *dest = xmalloc (n + 1); + memset (dest, c, n); + dest[n] = '\0'; + + return dest; +} + +/* Replace all occurrences of the given char with the replacement + * char. + * + * On error the original string is returned. + * On success, a string with the replaced values is returned. */ +char * +char_replace (char *str, char o, char n) { + char *p = str; + + if (str == NULL || *str == '\0') + return str; + + while ((p = strchr (p, o)) != NULL) + *p++ = n; + + return str; +} + +/* Remove all occurrences of a new line. + * + * On success, a string with the replaced new lines is returned. */ +void +strip_newlines (char *str) { + char *src, *dst; + for (src = dst = str; *src != '\0'; src++) { + *dst = *src; + if (*dst != '\r' && *dst != '\n') + dst++; + } + *dst = '\0'; +} + +/* Strip blanks from a string. + * + * On success, a string without whitespace is returned. */ +char * +deblank (char *str) { + char *out = str, *put = str; + + for (; *str != '\0'; ++str) { + if (*str != ' ') + *put++ = *str; + } + *put = '\0'; + + return out; +} + +/* Make a string uppercase. + * + * On error the original string is returned. + * On success, the uppercased string is returned. */ +char * +strtoupper (char *str) { + char *p = str; + if (str == NULL || *str == '\0') + return str; + + while (*p != '\0') { + *p = toupper ((unsigned char) *p); + p++; + } + + return str; +} + +/* Left-pad a string with n amount of spaces. + * + * On success, a left-padded string is returned. */ +char * +left_pad_str (const char *s, int indent) { + char *buf = NULL; + + indent = strlen (s) + indent; + buf = xmalloc (snprintf (NULL, 0, "%*s", indent, s) + 1); + sprintf (buf, "%*s", indent, s); + + return buf; +} + +/* Append the source string to destination and reallocates and + * updating the destination buffer appropriately. */ +size_t +append_str (char **dest, const char *src) { + size_t curlen = strlen (*dest); + size_t srclen = strlen (src); + size_t newlen = curlen + srclen; + + char *str = xrealloc (*dest, newlen + 1); + memcpy (str + curlen, src, srclen + 1); + *dest = str; + + return newlen; +} + +/* Escapes the special characters, e.g., '\n', '\r', '\t', '\' + * in the string source by inserting a '\' before them. + * + * On error NULL is returned. + * On success the escaped string is returned */ +char * +escape_str (const char *src) { + char *dest, *q; + const unsigned char *p; + + if (src == NULL || *src == '\0') + return NULL; + + p = (const unsigned char *) src; + q = dest = xmalloc (strlen (src) * 4 + 1); + + while (*p) { + switch (*p) { + case '\\': + *q++ = '\\'; + *q++ = '\\'; + break; + case '\n': + *q++ = '\\'; + *q++ = 'n'; + break; + case '\r': + *q++ = '\\'; + *q++ = 'r'; + break; + case '\t': + *q++ = '\\'; + *q++ = 't'; + break; + default: + /* not ASCII */ + if ((*p < ' ') || (*p >= 0177)) { + *q++ = '\\'; + *q++ = '0' + (((*p) >> 6) & 07); + *q++ = '0' + (((*p) >> 3) & 07); + *q++ = '0' + ((*p) & 07); + } else + *q++ = *p; + break; + } + p++; + } + *q = 0; + return dest; +} + +/* Get an unescaped malloc'd string + * + * On error NULL is returned. + * On success the unescaped string is returned */ +char * +unescape_str (const char *src) { + char *dest, *q; + const char *p = src; + + if (src == NULL || *src == '\0') + return NULL; + + dest = xmalloc (strlen (src) + 1); + q = dest; + + while (*p) { + if (*p == '\\') { + p++; + switch (*p) { + case '\0': + /* warning... */ + goto out; + case 'n': + *q++ = '\n'; + break; + case 'r': + *q++ = '\r'; + break; + case 't': + *q++ = '\t'; + break; + default: + *q++ = *p; + break; + } + } else + *q++ = *p; + p++; + } +out: + *q = 0; + + return dest; +} diff --git a/src/util.h b/src/util.h new file mode 100644 index 0000000000..140e7e3942 --- /dev/null +++ b/src/util.h @@ -0,0 +1,115 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef UTIL_H_INCLUDED +#define UTIL_H_INCLUDED + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) + +#define REGEX_ERROR 100 + +#define KIB(n) (n << 10) +#define MIB(n) (n << 20) +#define GIB(n) (n << 30) +#define TIB(n) (n << 40) +#define PIB(n) (n << 50) + +#define MILS 1000ULL +#define SECS 1000000ULL +#define MINS 60000000ULL +#define HOUR 3600000000ULL +#define DAY 86400000000ULL +#define TZ_NAME_LEN 48 + +#define RAND_FN 7 + 1 + +/* Convenient macros */ +#define MIN(a,b) \ + ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + _a < _b ? _a : _b; }) + +#define MAX(a,b) (((a)>(b))?(a):(b)) + +/* *INDENT-OFF* */ +#include +#include +#include + +char *alloc_string (const char *str); +char *char_repeat (int n, char c); +char *char_replace (char *str, char o, char n); +char *deblank (char *str); +char *escape_str (const char *src); +char *filesize_str (unsigned long long log_size); +char *float2str (float d, int width); +char *get_global_config (void); +char *get_user_config (void); +char *get_visitors_date (const char *odate, const char *from, const char *to); +char *int2str (int d, int width); +char *left_pad_str (const char *s, int indent); +char *ltrim (char *s); +char *regex_extract_string (const char *str, const char *regex, int max_groups, char const **err); +char *rtrim (char *s); +char *strtoupper (char *str); +char *substring (const char *str, int begin, int len); +char *trim_str (char *str); +char *u322str (uint32_t d, int width); +char *u642str (uint64_t d, int width); +char *unescape_str (const char *src); +char *usecs_to_str (unsigned long long usec); +const char *verify_status_code (int code); +const char *verify_status_code_type (int code); +int convert_date (char *res, const char *data, const char *from, const char *to, int size); +int count_matches (const char *s1, char c); +int find_output_type (char **filename, const char *ext, int alloc); +int hide_referer (const char *host); +int ignore_referer (const char *host); +int intlen (uint64_t num); +int invalid_ipaddr (const char *str, int *ipvx); +int ip_in_range (const char *ip); +int is_valid_http_status (int code); +int ptr2int (char *ptr); +int str2int (const char *date); +int str_inarray (const char *s, const char *arr[], int size); +int str_to_time (const char *str, const char *fmt, struct tm *tm, int tz); +int valid_output_type (const char *filename); +off_t file_size (const char *filename); +size_t append_str (char **dest, const char *src); +uint32_t djb2 (const unsigned char *str); +uint64_t u64encode (uint32_t x, uint32_t y); +void genstr (char *dest, size_t len); +void set_tz (void); +void strip_newlines (char *str); +void u64decode (uint64_t n, uint32_t * x, uint32_t * y); +void xstrncpy (char *dest, const char *source, const size_t dest_size); + +/* *INDENT-ON* */ + +#endif diff --git a/src/websocket.c b/src/websocket.c new file mode 100644 index 0000000000..80889217ef --- /dev/null +++ b/src/websocket.c @@ -0,0 +1,2989 @@ +/** + * websocket.c -- An rfc6455-complaint Web Socket Server + * _______ _______ __ __ + * / ____/ | / / ___/____ _____/ /_____ / /_ + * / / __ | | /| / /\__ \/ __ \/ ___/ //_/ _ \/ __/ + * / /_/ / | |/ |/ /___/ / /_/ / /__/ ,< / __/ /_ + * \____/ |__/|__//____/\____/\___/_/|_|\___/\__/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if HAVE_CONFIG_H +#include +#endif + +#include "websocket.h" + +#include "base64.h" +#include "error.h" +#include "gslist.h" +#include "sha1.h" +#include "util.h" +#include "xmalloc.h" + +/* *INDENT-OFF* */ + +/* UTF-8 Decoder */ +/* Copyright (c) 2008-2009 Bjoern Hoehrmann + * See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details. */ +#define UTF8_VALID 0 +#define UTF8_INVAL 1 +static const uint8_t utf8d[] = { + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 00..1f */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 20..3f */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 40..5f */ + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 60..7f */ + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, /* 80..9f */ + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, /* a0..bf */ + 8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, /* c0..df */ + 0xa,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x4,0x3,0x3, /* e0..ef */ + 0xb,0x6,0x6,0x6,0x5,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8, /* f0..ff */ + 0x0,0x1,0x2,0x3,0x5,0x8,0x7,0x1,0x1,0x1,0x4,0x6,0x1,0x1,0x1,0x1, /* s0..s0 */ + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,1, /* s1..s2 */ + 1,2,1,1,1,1,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1, /* s3..s4 */ + 1,2,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,3,1,1,1,1,1,1, /* s5..s6 */ + 1,3,1,1,1,1,1,3,1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* s7..s8 */ +}; +/* *INDENT-ON* */ + +static struct pollfd *fdstate = NULL; +static nfds_t nfdstate = 0; +static WSConfig wsconfig = { 0 }; + +static void handle_read_close (int *conn, WSClient * client, WSServer * server); +static void handle_reads (int *conn, WSServer * server); +static void handle_writes (int *conn, WSServer * server); +#ifdef HAVE_LIBSSL +static int shutdown_ssl (WSClient * client); +#endif + +/* Determine if the given string is valid UTF-8. + * + * The state after the by has been processed is returned. */ +static uint32_t +verify_utf8 (uint32_t *state, const char *str, int len) { + int i; + uint32_t type; + + for (i = 0; i < len; ++i) { + type = utf8d[(uint8_t) str[i]]; + *state = utf8d[256 + (*state) * 16 + type]; + + if (*state == UTF8_INVAL) + break; + } + + return *state; +} + +/* Decode a character maintaining state and a byte, and returns the + * state achieved after processing the byte. + * + * The state after the by has been processed is returned. */ +static uint32_t +utf8_decode (uint32_t *state, uint32_t *p, uint32_t b) { + uint32_t type = utf8d[(uint8_t) b]; + + *p = (*state != UTF8_VALID) ? (b & 0x3fu) | (*p << 6) : (0xff >> type) & (b); + *state = utf8d[256 + *state * 16 + type]; + + return *state; +} + +/* Replace malformed sequences with a substitute character. + * + * On success, it replaces the whole sequence and return a malloc'd buffer. */ +static char * +sanitize_utf8 (const char *str, int len) { + char *buf = NULL; + uint32_t state = UTF8_VALID, prev = UTF8_VALID, cp = 0; + int i = 0, j = 0, k = 0, l = 0; + + buf = xcalloc (len + 1, sizeof (char)); + for (; i < len; prev = state, ++i) { + switch (utf8_decode (&state, &cp, (unsigned char) str[i])) { + case UTF8_INVAL: + /* replace the whole sequence */ + if (k) { + for (l = i - k; l < i; ++l) + buf[j++] = '?'; + } else { + buf[j++] = '?'; + } + state = UTF8_VALID; + if (prev != UTF8_VALID) + i--; + k = 0; + break; + case UTF8_VALID: + /* fill i - k valid continuation bytes */ + if (k) + for (l = i - k; l < i; ++l) + buf[j++] = str[l]; + buf[j++] = str[i]; + k = 0; + break; + default: + /* UTF8_VALID + continuation bytes */ + k++; + break; + } + } + + return buf; +} + +/* find a pollfd structure based on fd + * this should only be called by set_pollfd and unset_pollfd + * because the position in memory may change */ +static struct pollfd * +get_pollfd (int fd) { + struct pollfd *pfd, *efd = fdstate + nfdstate; + + for (pfd = fdstate; pfd < efd; pfd++) { + if (pfd->fd == fd) + return pfd; + } + + return NULL; +} + +/* set flags for an existing pollfd structure based on fd, + * otherwise malloc a new one */ +static void +set_pollfd (int fd, short flags) { + struct pollfd *pfd; + + if (fd == -1) + FATAL ("Cannot poll an invalid fd"); + + pfd = get_pollfd (fd); + if (pfd == NULL) { + struct pollfd *newstate = xrealloc (fdstate, sizeof (*pfd) * (nfdstate + 1)); + + fdstate = newstate; + pfd = fdstate + nfdstate++; + pfd->fd = fd; + } + pfd->events = flags; + pfd->revents = 0; +} + +/* free a pollfd structure based on fd */ +static void +unset_pollfd (int fd) { + struct pollfd *pfd = get_pollfd (fd), *efd; + struct pollfd *newstate; + + if (pfd == NULL) + return; + + nfdstate--; + + /* avoid undefined behaviour with realloc with a size of zero */ + if (nfdstate == 0) { + free (fdstate); + fdstate = NULL; + return; + } + + efd = fdstate + nfdstate; + if (pfd != efd) + memmove (pfd, pfd + 1, (char *) efd - (char *) pfd); + + /* realloc could fail, but that's ok, we don't mind. */ + newstate = realloc (fdstate, sizeof (*pfd) * nfdstate); + if (newstate != NULL) + fdstate = newstate; +} + +/* Allocate memory for a websocket server */ +static WSServer * +new_wsserver (void) { + WSServer *server = xcalloc (1, sizeof (WSServer)); + + return server; +} + +/* Allocate memory for a websocket client */ +static WSClient * +new_wsclient (void) { + WSClient *client = xcalloc (1, sizeof (WSClient)); + client->status = WS_OK; + + return client; +} + +/* Allocate memory for a websocket header */ +static WSHeaders * +new_wsheader (void) { + WSHeaders *headers = xcalloc (1, sizeof (WSHeaders)); + memset (headers->buf, 0, sizeof (headers->buf)); + headers->reading = 1; + + return headers; +} + +/* Allocate memory for a websocket frame */ +static WSFrame * +new_wsframe (void) { + WSFrame *frame = xcalloc (1, sizeof (WSFrame)); + memset (frame->buf, 0, sizeof (frame->buf)); + frame->reading = 1; + + return frame; +} + +/* Allocate memory for a websocket message */ +static WSMessage * +new_wsmessage (void) { + WSMessage *msg = xcalloc (1, sizeof (WSMessage)); + + return msg; +} + +/* Allocate memory for a websocket pipeout */ +static WSPipeOut * +new_wspipeout (void) { + WSPipeOut *pipeout = xcalloc (1, sizeof (WSPipeOut)); + pipeout->fd = -1; + + return pipeout; +} + +/* Allocate memory for a websocket pipein */ +static WSPipeIn * +new_wspipein (void) { + WSPipeIn *pipein = xcalloc (1, sizeof (WSPipeIn)); + pipein->fd = -1; + + return pipein; +} + +/* Escapes the special characters, e.g., '\n', '\r', '\t', '\' + * in the string source by inserting a '\' before them. + * + * On error NULL is returned. + * On success the escaped string is returned */ +static char * +escape_http_request (const char *src) { + char *dest, *q; + const unsigned char *p; + + if (src == NULL || *src == '\0') + return NULL; + + p = (const unsigned char *) src; + q = dest = xmalloc (strlen (src) * 4 + 1); + + while (*p) { + switch (*p) { + case '\\': + *q++ = '\\'; + *q++ = '\\'; + break; + case '\n': + *q++ = '\\'; + *q++ = 'n'; + break; + case '\r': + *q++ = '\\'; + *q++ = 'r'; + break; + case '\t': + *q++ = '\\'; + *q++ = 't'; + break; + case '"': + *q++ = '\\'; + *q++ = '"'; + break; + default: + if ((*p < ' ') || (*p >= 0177)) { + /* not ASCII */ + } else { + *q++ = *p; + } + break; + } + p++; + } + *q = 0; + return dest; +} + +/* Chop n characters from the beginning of the supplied buffer. + * + * The new length of the string is returned. */ +static size_t +chop_nchars (char *str, size_t n, size_t len) { + if (n == 0 || str == 0) + return 0; + + if (n > len) + n = len; + memmove (str, str + n, len - n); + + return (len - n); +} + +/* Match a client given a socket id and an item from the list. + * + * On match, 1 is returned, else 0. */ +static int +ws_find_client_sock_in_list (void *data, void *needle) { + WSClient *client = data; + + return client->listener == (*(int *) needle); +} + +/* Find a client given a socket id. + * + * On success, an instance of a GSLList node is returned, else NULL. */ +static GSLList * +ws_get_list_node_from_list (int listener, GSLList **colist) { + GSLList *match = NULL; + + /* Find the client data for the socket in use */ + if (!(match = list_find (*colist, ws_find_client_sock_in_list, &listener))) + return NULL; + return match; +} + +/* Find a client given a socket id. + * + * On success, an instance of a WSClient is returned, else NULL. */ +static WSClient * +ws_get_client_from_list (int listener, GSLList **colist) { + GSLList *match = NULL; + + /* Find the client data for the socket in use */ + if (!(match = list_find (*colist, ws_find_client_sock_in_list, &listener))) + return NULL; + return (WSClient *) match->data; +} + +/* Free a frame structure and its data for the given client. */ +static void +ws_free_frame (WSClient *client) { + if (client->frame) + free (client->frame); + client->frame = NULL; +} + +/* Free a message structure and its data for the given client. */ +static void +ws_free_message (WSClient *client) { + if (client->message && client->message->payload) + free (client->message->payload); + if (client->message) + free (client->message); + client->message = NULL; +} + +/* Free all HTTP handshake headers data for the given client. */ +static void +ws_free_header_fields (WSHeaders *headers) { + if (headers->connection) + free (headers->connection); + if (headers->host) + free (headers->host); + if (headers->agent) + free (headers->agent); + if (headers->method) + free (headers->method); + if (headers->origin) + free (headers->origin); + if (headers->path) + free (headers->path); + if (headers->protocol) + free (headers->protocol); + if (headers->upgrade) + free (headers->upgrade); + if (headers->ws_accept) + free (headers->ws_accept); + if (headers->ws_key) + free (headers->ws_key); + if (headers->ws_protocol) + free (headers->ws_protocol); + if (headers->ws_resp) + free (headers->ws_resp); + if (headers->ws_sock_ver) + free (headers->ws_sock_ver); + if (headers->referer) + free (headers->referer); +} + +/* A wrapper to close a socket. */ +static void +ws_close (int listener) { + unset_pollfd (listener); + close (listener); +} + +/* Clear the client's sent queue and its data. */ +static void +ws_clear_queue (WSClient *client) { + WSQueue **queue = &client->sockqueue; + if (!(*queue)) + return; + + if ((*queue)->queued) + free ((*queue)->queued); + (*queue)->queued = NULL; + (*queue)->qlen = 0; + + free ((*queue)); + (*queue) = NULL; + + /* done sending the whole queue, stop throttling */ + client->status &= ~WS_THROTTLING; + /* done sending, close connection if set to close */ + if ((client->status & WS_CLOSE) && (client->status & WS_SENDING)) + client->status = WS_CLOSE; +} + +/* Free all HTTP handshake headers and structure. */ +static void +ws_clear_handshake_headers (WSHeaders *headers) { + ws_free_header_fields (headers); + free (headers); +} + +/* Remove the given client from the list. */ +static void +ws_remove_client_from_list (WSClient *client, WSServer *server) { + GSLList *node = NULL; + + if (!(node = ws_get_list_node_from_list (client->listener, &server->colist))) + return; + + if (client->headers) + ws_clear_handshake_headers (client->headers); + list_remove_node (&server->colist, node); +} + +#if HAVE_LIBSSL +/* Attempt to send the TLS/SSL "close notify" shutdown and and removes + * the SSL structure pointed to by ssl and frees up the allocated + * memory. */ +static void +ws_shutdown_dangling_clients (WSClient *client) { + shutdown_ssl (client); + SSL_free (client->ssl); + client->ssl = NULL; +} + +/* Attempt to remove the SSL_CTX object pointed to by ctx and frees up + * the allocated memory and cleans some more generally used TLS/SSL + * memory. */ +static void +ws_ssl_cleanup (WSServer *server) { + if (!wsconfig.use_ssl) + return; + + if (server->ctx) + SSL_CTX_free (server->ctx); + + CRYPTO_cleanup_all_ex_data (); + CRYPTO_set_id_callback (NULL); + CRYPTO_set_locking_callback (NULL); + ERR_free_strings (); +#if OPENSSL_VERSION_NUMBER < 0x10100000L + ERR_remove_state (0); +#endif + EVP_cleanup (); +} +#endif + +/* Remove all clients that are still hanging out. */ +static int +ws_remove_dangling_clients (void *value, void *user_data) { + WSClient *client = value; + (void) (user_data); + + if (client == NULL) + return 1; + + if (client->headers) + ws_clear_handshake_headers (client->headers); + if (client->sockqueue) + ws_clear_queue (client); +#ifdef HAVE_LIBSSL + if (client->ssl) + ws_shutdown_dangling_clients (client); +#endif + + return 0; +} + +/* Do some housekeeping on the named pipe data packet. */ +static void +ws_clear_fifo_packet (WSPacket *packet) { + if (!packet) + return; + + if (packet->data) + free (packet->data); + free (packet); +} + +/* Do some housekeeping on the named pipe. */ +static void +ws_clear_pipein (WSPipeIn *pipein) { + WSPacket **packet = &pipein->packet; + if (!pipein) + return; + + if (pipein->fd != -1) + ws_close (pipein->fd); + + ws_clear_fifo_packet (*packet); + free (pipein); + + if (wsconfig.pipein && access (wsconfig.pipein, F_OK) != -1) + unlink (wsconfig.pipein); +} + +/* Do some housekeeping on the named pipe. */ +static void +ws_clear_pipeout (WSPipeOut *pipeout) { + if (!pipeout) + return; + + if (pipeout->fd != -1) + ws_close (pipeout->fd); + + free (pipeout); + + if (wsconfig.pipeout && access (wsconfig.pipeout, F_OK) != -1) + unlink (wsconfig.pipeout); +} + +/* Stop the server and do some cleaning. */ +void +ws_stop (WSServer *server) { + WSPipeIn **pipein = &server->pipein; + WSPipeOut **pipeout = &server->pipeout; + + ws_clear_pipein (*pipein); + ws_clear_pipeout (*pipeout); + + /* close access log (if any) */ + if (wsconfig.accesslog) + access_log_close (); + + /* remove dangling clients */ + if (list_count (server->colist) > 0) + list_foreach (server->colist, ws_remove_dangling_clients, NULL); + + if (server->colist) + list_remove_nodes (server->colist); + +#ifdef HAVE_LIBSSL + ws_ssl_cleanup (server); +#endif + + free (server); + free (fdstate); + fdstate = NULL; +} + +/* Set the connection status for the given client and return the given + * bytes. + * + * The given number of bytes are returned. */ +static int +ws_set_status (WSClient *client, WSStatus status, int bytes) { + client->status = status; + return bytes; +} + +/* Append the source string to destination and reallocates and + * updating the destination buffer appropriately. */ +static void +ws_append_str (char **dest, const char *src) { + size_t curlen = strlen (*dest); + size_t srclen = strlen (src); + size_t newlen = curlen + srclen; + + char *str = xrealloc (*dest, newlen + 1); + memcpy (str + curlen, src, srclen + 1); + *dest = str; +} + +#if HAVE_LIBSSL +/* Create a new SSL_CTX object as framework to establish TLS/SSL + * enabled connections. + * + * On error 1 is returned. + * On success, SSL_CTX object is malloc'd and 0 is returned. + */ +static int +initialize_ssl_ctx (WSServer *server) { + int ret = 1; + SSL_CTX *ctx = NULL; + +#if OPENSSL_VERSION_NUMBER < 0x10100000L + SSL_library_init (); + SSL_load_error_strings (); +#endif + + /* Ciphers and message digests */ + OpenSSL_add_ssl_algorithms (); + + /* ssl context */ +#if OPENSSL_VERSION_NUMBER < 0x10100000L + if (!(ctx = SSL_CTX_new (SSLv23_server_method ()))) +#else + if (!(ctx = SSL_CTX_new (TLS_server_method ()))) +#endif + goto out; + /* set certificate */ + if (!SSL_CTX_use_certificate_file (ctx, wsconfig.sslcert, SSL_FILETYPE_PEM)) + goto out; + /* ssl private key */ + if (!SSL_CTX_use_PrivateKey_file (ctx, wsconfig.sslkey, SSL_FILETYPE_PEM)) + goto out; + if (!SSL_CTX_check_private_key (ctx)) + goto out; + + /* since we queued up the send data, a retry won't be the same buffer, + * thus we need the following flags */ + SSL_CTX_set_mode (ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER | SSL_MODE_ENABLE_PARTIAL_WRITE); + + server->ctx = ctx; + ret = 0; +out: + if (ret) { + SSL_CTX_free (ctx); + LOG (("Error: %s\n", ERR_error_string (ERR_get_error (), NULL))); + } + + return ret; +} + +/* Log result code for TLS/SSL I/O operation */ +static void +log_return_message (int ret, int err, const char *fn) { + unsigned long e; + + switch (err) { + case SSL_ERROR_NONE: + LOG (("SSL: %s -> SSL_ERROR_NONE\n", fn)); + LOG (("SSL: TLS/SSL I/O operation completed\n")); + break; + case SSL_ERROR_WANT_READ: + LOG (("SSL: %s -> SSL_ERROR_WANT_READ\n", fn)); + LOG (("SSL: incomplete, data available for reading\n")); + break; + case SSL_ERROR_WANT_WRITE: + LOG (("SSL: %s -> SSL_ERROR_WANT_WRITE\n", fn)); + LOG (("SSL: incomplete, data available for writing\n")); + break; + case SSL_ERROR_ZERO_RETURN: + LOG (("SSL: %s -> SSL_ERROR_ZERO_RETURN\n", fn)); + LOG (("SSL: TLS/SSL connection has been closed\n")); + break; + case SSL_ERROR_WANT_X509_LOOKUP: + LOG (("SSL: %s -> SSL_ERROR_WANT_X509_LOOKUP\n", fn)); + break; + case SSL_ERROR_SYSCALL: + LOG (("SSL: %s -> SSL_ERROR_SYSCALL\n", fn)); + + e = ERR_get_error (); + if (e > 0) + LOG (("SSL: %s -> %s\n", fn, ERR_error_string (e, NULL))); + + /* call was not successful because a fatal error occurred either at the + * protocol level or a connection failure occurred. */ + if (ret != 0) { + LOG (("SSL bogus handshake interrupt: %s\n", strerror (errno))); + break; + } + /* call not yet finished. */ + LOG (("SSL: handshake interrupted, got EOF\n")); + if (errno == EINTR || errno == EWOULDBLOCK || errno == EAGAIN) + LOG (("SSL: %s -> not yet finished %s\n", fn, strerror (errno))); + break; + default: + LOG (("SSL: %s -> failed fatal error code: %d\n", fn, err)); + LOG (("SSL: %s\n", ERR_error_string (ERR_get_error (), NULL))); + break; + } +} + +/* Shut down the client's TLS/SSL connection + * + * On fatal error, 1 is returned. + * If data still needs to be read/written, -1 is returned. + * On success, the TLS/SSL connection is closed and 0 is returned */ +static int +shutdown_ssl (WSClient *client) { + int ret = -1, err = 0; + + /* all good */ + if ((ret = SSL_shutdown (client->ssl)) > 0) + return ws_set_status (client, WS_CLOSE, 0); + + err = SSL_get_error (client->ssl, ret); + log_return_message (ret, err, "SSL_shutdown"); + + switch (err) { + case SSL_ERROR_WANT_READ: + case SSL_ERROR_WANT_WRITE: + client->sslstatus = WS_TLS_SHUTTING; + break; + case SSL_ERROR_SYSCALL: + if (ret == 0) { + LOG (("SSL: SSL_shutdown, connection unexpectedly closed by peer.\n")); + /* The shutdown is not yet finished. */ + if (errno == EINTR || errno == EWOULDBLOCK || errno == EAGAIN) + client->sslstatus = WS_TLS_SHUTTING; + break; + } + LOG (("SSL: SSL_shutdown, probably unrecoverable, forcing close.\n")); + /* FALLTHRU */ + case SSL_ERROR_ZERO_RETURN: + case SSL_ERROR_WANT_X509_LOOKUP: + default: + return ws_set_status (client, WS_ERR | WS_CLOSE, 1); + } + + return ret; +} + +/* Wait for a TLS/SSL client to initiate a TLS/SSL handshake + * + * On fatal error, the connection is shut down. + * If data still needs to be read/written, -1 is returned. + * On success, the TLS/SSL connection is completed and 0 is returned */ +static int +accept_ssl (WSClient *client) { + int ret = -1, err = 0; + + /* all good on TLS handshake */ + if ((ret = SSL_accept (client->ssl)) > 0) { + client->sslstatus &= ~WS_TLS_ACCEPTING; + return 0; + } + + err = SSL_get_error (client->ssl, ret); + log_return_message (ret, err, "SSL_accept"); + + switch (err) { + case SSL_ERROR_WANT_READ: + case SSL_ERROR_WANT_WRITE: + client->sslstatus = WS_TLS_ACCEPTING; + break; + case SSL_ERROR_SYSCALL: + /* Wait for more activity else bail out, for instance if the socket is closed + * during the handshake. */ + if (ret < 0 && (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)) { + client->sslstatus = WS_TLS_ACCEPTING; + break; + } + /* The peer notified that it is shutting down through a SSL "close_notify" so + * we shutdown too */ + /* FALLTHRU */ + case SSL_ERROR_ZERO_RETURN: + case SSL_ERROR_WANT_X509_LOOKUP: + default: + client->sslstatus &= ~WS_TLS_ACCEPTING; + return ws_set_status (client, WS_ERR | WS_CLOSE, 1); + } + + return ret; +} + +/* Create a new SSL structure for a connection and perform handshake */ +static void +handle_accept_ssl (WSClient *client, WSServer *server) { + /* attempt to create SSL connection if we don't have one yet */ + if (!client->ssl) { + if (!(client->ssl = SSL_new (server->ctx))) { + LOG (("SSL: SSL_new, new SSL structure failed.\n")); + return; + } + if (!SSL_set_fd (client->ssl, client->listener)) { + LOG (("SSL: unable to set file descriptor\n")); + return; + } + } + + /* attempt to initiate the TLS/SSL handshake */ + if (accept_ssl (client) == 0) { + LOG (("SSL Accepted: %d %s\n", client->listener, client->remote_ip)); + } +} + +/* Given the current status of the SSL buffer, perform that action. + * + * On error or if no SSL pending status, 1 is returned. + * On success, the TLS/SSL pending action is called and 0 is returned */ +static int +handle_ssl_pending_rw (int *conn, WSServer *server, WSClient *client) { + if (!wsconfig.use_ssl) + return 1; + + /* trying to write but still waiting for a successful SSL_accept */ + if (client->sslstatus & WS_TLS_ACCEPTING) { + handle_accept_ssl (client, server); + return 0; + } + /* trying to read but still waiting for a successful SSL_read */ + if (client->sslstatus & WS_TLS_READING) { + handle_reads (conn, server); + return 0; + } + /* trying to write but still waiting for a successful SSL_write */ + if (client->sslstatus & WS_TLS_WRITING) { + handle_writes (conn, server); + return 0; + } + /* trying to write but still waiting for a successful SSL_shutdown */ + if (client->sslstatus & WS_TLS_SHUTTING) { + if (shutdown_ssl (client) == 0) + handle_read_close (conn, client, server); + return 0; + } + + return 1; +} + +/* Write bytes to a TLS/SSL connection for a given client. + * + * On error or if no write is performed <=0 is returned. + * On success, the number of bytes actually written to the TLS/SSL + * connection are returned */ +static int +send_ssl_buffer (WSClient *client, const char *buffer, int len) { + int bytes = 0, err = 0; + +#if OPENSSL_VERSION_NUMBER < 0x10100000L + ERR_clear_error (); +#endif + if ((bytes = SSL_write (client->ssl, buffer, len)) > 0) + return bytes; + + err = SSL_get_error (client->ssl, bytes); + log_return_message (bytes, err, "SSL_write"); + + switch (err) { + case SSL_ERROR_WANT_WRITE: + break; + case SSL_ERROR_WANT_READ: + client->sslstatus = WS_TLS_WRITING; + break; + case SSL_ERROR_SYSCALL: + if ((bytes < 0 && (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR))) + break; + /* The connection was shut down cleanly */ + /* FALLTHRU */ + case SSL_ERROR_ZERO_RETURN: + case SSL_ERROR_WANT_X509_LOOKUP: + default: + return ws_set_status (client, WS_ERR | WS_CLOSE, -1); + } + + return bytes; +} + +/* Read data from the given client's socket and set a connection + * status given the output of recv(). + * + * On error, -1 is returned and the connection status is set. + * On success, the number of bytes read is returned. */ +static int +read_ssl_socket (WSClient *client, char *buffer, int size) { + int bytes = 0, done = 0, err = 0; + do { +#if OPENSSL_VERSION_NUMBER < 0x10100000L + ERR_clear_error (); +#endif + + done = 0; + if ((bytes = SSL_read (client->ssl, buffer, size)) > 0) + break; + + err = SSL_get_error (client->ssl, bytes); + log_return_message (bytes, err, "SSL_read"); + + switch (err) { + case SSL_ERROR_WANT_WRITE: + client->sslstatus = WS_TLS_READING; + done = 1; + break; + case SSL_ERROR_WANT_READ: + done = 1; + break; + case SSL_ERROR_SYSCALL: + if ((bytes < 0 && (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR))) + break; + /* FALLTHRU */ + case SSL_ERROR_ZERO_RETURN: + case SSL_ERROR_WANT_X509_LOOKUP: + default: + return ws_set_status (client, WS_ERR | WS_CLOSE, -1); + } + } while (SSL_pending (client->ssl) && !done); + + return bytes; +} +#endif + +/* Get sockaddr, either IPv4 or IPv6 */ +static void * +ws_get_raddr (struct sockaddr *sa) { + if (sa->sa_family == AF_INET) + return &(((struct sockaddr_in *) (void *) sa)->sin_addr); + + return &(((struct sockaddr_in6 *) (void *) sa)->sin6_addr); +} + +/* Set the given file descriptor as NON BLOCKING. */ +void +set_nonblocking (int sock) { + if (fcntl (sock, F_SETFL, fcntl (sock, F_GETFL, 0) | O_NONBLOCK) == -1) + FATAL ("Unable to set socket as non-blocking: %s.", strerror (errno)); +} + +/* Accept a new connection on a socket and add it to the list of + * current connected clients. + * + * The newly assigned socket is returned. */ +static int +accept_client (int listener, GSLList **colist) { + WSClient *client; + struct sockaddr_storage raddr; + int newfd; + const void *src = NULL; + socklen_t alen; + + alen = sizeof (raddr); + if ((newfd = accept (listener, (struct sockaddr *) &raddr, &alen)) == -1) + FATAL ("Unable to set accept: %s.", strerror (errno)); + + if (newfd == -1) { + LOG (("Unable to accept: %s.", strerror (errno))); + return newfd; + } + src = ws_get_raddr ((struct sockaddr *) &raddr); + + /* malloc a new client */ + client = new_wsclient (); + client->listener = newfd; + inet_ntop (raddr.ss_family, src, client->remote_ip, INET6_ADDRSTRLEN); + + /* add up our new client to keep track of */ + if (*colist == NULL) + *colist = list_create (client); + else + *colist = list_insert_prepend (*colist, client); + + /* make the socket non-blocking */ + set_nonblocking (client->listener); + + /* poll for the socket */ + set_pollfd (client->listener, POLLIN); + + return newfd; +} + +/* Extract the HTTP method. + * + * On error, or if not found, NULL is returned. + * On success, the HTTP method is returned. */ +static const char * +ws_get_method (const char *token) { + const char *lookfor = NULL; + + if ((lookfor = "GET", !memcmp (token, "GET ", 4)) || + (lookfor = "get", !memcmp (token, "get ", 4))) + return lookfor; + return NULL; +} + +/* Parse a request containing the method and protocol. + * + * On error, or unable to parse, NULL is returned. + * On success, the HTTP request is returned and the method and + * protocol are assigned to the corresponding buffers. */ +static char * +ws_parse_request (char *line, char **method, char **protocol) { + const char *meth; + char *req = NULL, *request = NULL, *proto = NULL; + ptrdiff_t rlen; + + if ((meth = ws_get_method (line)) == NULL) { + return NULL; + } else { + req = line + strlen (meth); + if ((proto = strstr (line, " HTTP/1.0")) == NULL && + (proto = strstr (line, " HTTP/1.1")) == NULL) + return NULL; + + req++; + if ((rlen = proto - req) <= 0) + return NULL; + + request = xmalloc (rlen + 1); + strncpy (request, req, rlen); + request[rlen] = 0; + + (*method) = strtoupper (xstrdup (meth)); + (*protocol) = strtoupper (xstrdup (++proto)); + } + + return request; +} + +/* Given a pair of key/values, assign it to our HTTP headers + * structure. */ +static void +ws_set_header_key_value (WSHeaders *headers, char *key, char *value) { + if (strcasecmp ("Host", key) == 0) + headers->host = xstrdup (value); + else if (strcasecmp ("Origin", key) == 0) + headers->origin = xstrdup (value); + else if (strcasecmp ("Upgrade", key) == 0) + headers->upgrade = xstrdup (value); + else if (strcasecmp ("Connection", key) == 0) + headers->connection = xstrdup (value); + else if (strcasecmp ("Sec-WebSocket-Protocol", key) == 0) + headers->ws_protocol = xstrdup (value); + else if (strcasecmp ("Sec-WebSocket-Key", key) == 0) + headers->ws_key = xstrdup (value); + else if (strcasecmp ("Sec-WebSocket-Version", key) == 0) + headers->ws_sock_ver = xstrdup (value); + else if (strcasecmp ("User-Agent", key) == 0) + headers->agent = xstrdup (value); + else if (strcasecmp ("Referer", key) == 0) + headers->referer = xstrdup (value); +} + +/* Verify that the given HTTP headers were passed upon doing the + * websocket handshake. + * + * On error, or header missing, 1 is returned. + * On success, 0 is returned. */ +static int +ws_verify_req_headers (WSHeaders *headers) { + if (!headers->host) + return 1; + if (!headers->method) + return 1; + if (!headers->protocol) + return 1; + if (!headers->path) + return 1; + if (wsconfig.origin && !headers->origin) + return 1; + if (wsconfig.origin && strcasecmp (wsconfig.origin, headers->origin) != 0) + return 1; + if (!headers->connection) + return 1; + if (!headers->ws_key) + return 1; + if (!headers->ws_sock_ver) + return 1; + return 0; +} + +/* From RFC2616, each header field consists of a name followed by a + * colon (":") and the field value. Field names are case-insensitive. + * The field value MAY be preceded by any amount of LWS, though a + * single SP is preferred */ +static int +ws_set_header_fields (char *line, WSHeaders *headers) { + char *path = NULL, *method = NULL, *proto = NULL, *p, *value; + + if (line[0] == '\n' || line[0] == '\r') + return 1; + + if ((strstr (line, "GET ")) || (strstr (line, "get "))) { + if ((path = ws_parse_request (line, &method, &proto)) == NULL) + return 1; + headers->path = path; + headers->method = method; + headers->protocol = proto; + + return 0; + } + + if ((p = strchr (line, ':')) == NULL) + return 1; + + value = p + 1; + while (p != line && isspace ((unsigned char) *(p - 1))) + p--; + + if (p == line) + return 1; + + *p = '\0'; + if (strpbrk (line, " \t") != NULL) { + *p = ' '; + return 1; + } + while (isspace ((unsigned char) *value)) + value++; + + ws_set_header_key_value (headers, line, value); + + return 0; +} + +/* Parse the given HTTP headers and set the expected websocket + * handshake. + * + * On error, or 1 is returned. + * On success, 0 is returned. */ +static int +parse_headers (WSHeaders *headers) { + char *tmp = NULL; + const char *buffer = headers->buf; + const char *line = buffer, *next = NULL; + int len = 0; + + while (line) { + if ((next = strstr (line, "\r\n")) != NULL) + len = (next - line); + else + len = strlen (line); + + if (len <= 0) + return 1; + + tmp = xmalloc (len + 1); + memcpy (tmp, line, len); + tmp[len] = '\0'; + + if (ws_set_header_fields (tmp, headers) == 1) { + free (tmp); + return 1; + } + + free (tmp); + line = next ? (next + 2) : NULL; + + if (next && strcmp (next, "\r\n\r\n") == 0) + break; + } + + return 0; +} + +/* Set into a queue the data that couldn't be sent. */ +static void +ws_queue_sockbuf (WSClient *client, const char *buffer, int len, int bytes) { + WSQueue *queue = xcalloc (1, sizeof (WSQueue)); + + if (bytes < 1) + bytes = 0; + + queue->queued = xcalloc (len - bytes, sizeof (char)); + memcpy (queue->queued, buffer + bytes, len - bytes); + queue->qlen = len - bytes; + client->sockqueue = queue; + + client->status |= WS_SENDING; + set_pollfd (client->listener, POLLIN | POLLOUT); +} + +/* Read data from the given client's socket and set a connection + * status given the output of recv(). + * + * On error, -1 is returned and the connection status is set. + * On success, the number of bytes read is returned. */ +static int +read_plain_socket (WSClient *client, char *buffer, int size) { + int bytes = 0; + + bytes = recv (client->listener, buffer, size, 0); + + if (bytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) + return ws_set_status (client, WS_READING, bytes); + else if (bytes == -1 || bytes == 0) + return ws_set_status (client, WS_ERR | WS_CLOSE, bytes); + + return bytes; +} + +/* Read data from the given client's socket and set a connection + * status given the output of recv(). + * + * On error, -1 is returned and the connection status is set. + * On success, the number of bytes read is returned. */ +static int +read_socket (WSClient *client, char *buffer, int size) { +#ifdef HAVE_LIBSSL + if (wsconfig.use_ssl) + return read_ssl_socket (client, buffer, size); + else + return read_plain_socket (client, buffer, size); +#else + return read_plain_socket (client, buffer, size); +#endif +} + +static int +send_plain_buffer (WSClient *client, const char *buffer, int len) { + return send (client->listener, buffer, len, 0); +} + +static int +send_buffer (WSClient *client, const char *buffer, int len) { +#ifdef HAVE_LIBSSL + if (wsconfig.use_ssl) + return send_ssl_buffer (client, buffer, len); + else + return send_plain_buffer (client, buffer, len); +#else + return send_plain_buffer (client, buffer, len); +#endif +} + +/* Attempt to send the given buffer to the given socket. + * + * On error, -1 is returned and the connection status is set. + * On success, the number of bytes sent is returned. */ +static int +ws_respond_data (WSClient *client, const char *buffer, int len) { + int bytes = 0; + + bytes = send_buffer (client, buffer, len); + if (bytes == -1 && errno == EPIPE) + return ws_set_status (client, WS_ERR | WS_CLOSE, bytes); + + /* did not send all of it... buffer it for a later attempt */ + if (bytes < len || (bytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))) + ws_queue_sockbuf (client, buffer, len, bytes); + + return bytes; +} + +/* Attempt to send the queued up client's data to the given socket. + * + * On error, -1 is returned and the connection status is set. + * On success, the number of bytes sent is returned. */ +static int +ws_respond_cache (WSClient *client) { + WSQueue *queue = client->sockqueue; + int bytes = 0; + + bytes = send_buffer (client, queue->queued, queue->qlen); + if (bytes == -1 && errno == EPIPE) + return ws_set_status (client, WS_ERR | WS_CLOSE, bytes); + + if (bytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) + return bytes; + + if (chop_nchars (queue->queued, bytes, queue->qlen) == 0) + ws_clear_queue (client); + else + queue->qlen -= bytes; + + return bytes; +} + +/* Attempt to realloc the current sent queue. + * + * On error, 1 is returned and the connection status is set. + * On success, 0 is returned. */ +static int +ws_realloc_send_buf (WSClient *client, const char *buf, int len) { + WSQueue *queue = client->sockqueue; + char *tmp = NULL; + int newlen = 0; + + newlen = queue->qlen + len; + tmp = realloc (queue->queued, newlen); + if (tmp == NULL && newlen > 0) { + ws_clear_queue (client); + return ws_set_status (client, WS_ERR | WS_CLOSE, 1); + } + queue->queued = tmp; + memcpy (queue->queued + queue->qlen, buf, len); + queue->qlen += len; + + /* client probably too slow, so stop queueing until everything is + * sent */ + if (queue->qlen >= WS_THROTTLE_THLD) + client->status |= WS_THROTTLING; + + return 0; +} + +/* An entry point to attempt to send the client's data. + * + * On error, 1 is returned and the connection status is set. + * On success, the number of bytes sent is returned. */ +static int +ws_respond (WSClient *client, const char *buffer, int len) { + int bytes = 0; + + /* attempt to send the whole buffer */ + if (client->sockqueue == NULL) + bytes = ws_respond_data (client, buffer, len); + /* buffer not empty, just append new data iff we're not throttling the + * client */ + else if (client->sockqueue != NULL && buffer != NULL && !(client->status & WS_THROTTLING)) { + if (ws_realloc_send_buf (client, buffer, len) == 1) + return bytes; + } + /* send from cache buffer */ + else { + bytes = ws_respond_cache (client); + } + + return bytes; +} + +/* Encode a websocket frame (header/message) and attempt to send it + * through the client's socket. + * + * On success, 0 is returned. */ +static int +ws_send_frame (WSClient *client, WSOpcode opcode, const char *p, int sz) { + unsigned char buf[32] = { 0 }; + char *frm = NULL; + uint64_t payloadlen = 0, u64; + int hsize = 2; + + if (sz < 126) { + payloadlen = sz; + } else if (sz < (1 << 16)) { + payloadlen = WS_PAYLOAD_EXT16; + hsize += 2; + } else { + payloadlen = WS_PAYLOAD_EXT64; + hsize += 8; + } + + buf[0] = 0x80 | ((uint8_t) opcode); + switch (payloadlen) { + case WS_PAYLOAD_EXT16: + buf[1] = WS_PAYLOAD_EXT16; + buf[2] = (sz & 0xff00) >> 8; + buf[3] = (sz & 0x00ff) >> 0; + break; + case WS_PAYLOAD_EXT64: + buf[1] = WS_PAYLOAD_EXT64; + u64 = htobe64 (sz); + memcpy (buf + 2, &u64, sizeof (uint64_t)); + break; + default: + buf[1] = (sz & 0xff); + } + frm = xcalloc (hsize + sz, sizeof (unsigned char)); + memcpy (frm, buf, hsize); + if (p != NULL && sz > 0) + memcpy (frm + hsize, p, sz); + + ws_respond (client, frm, hsize + sz); + free (frm); + + return 0; +} + +/* Send an error message to the given client. + * + * On success, the number of sent bytes is returned. */ +static int +ws_error (WSClient *client, unsigned short code, const char *err) { + unsigned int len; + unsigned short code_be; + char buf[128] = { 0 }; + + len = 2; + code_be = htobe16 (code); + memcpy (buf, &code_be, 2); + if (err) + len += snprintf (buf + 2, sizeof buf - 4, "%s", err); + + return ws_send_frame (client, WS_OPCODE_CLOSE, buf, len); +} + +/* Log hit to the access log. + * + * On success, the hit/entry is logged. */ +static void +access_log (WSClient *client, int status_code) { + WSHeaders *hdrs = client->headers; + char buf[64] = { 0 }; + uint32_t elapsed = 0; + struct timeval tv; + struct tm time; + char *req = NULL, *ref = NULL, *ua = NULL; + + gettimeofday (&tv, NULL); + strftime (buf, sizeof (buf) - 1, "[%d/%b/%Y:%H:%M:%S %z]", localtime_r (&tv.tv_sec, &time)); + + elapsed = (client->end_proc.tv_sec - client->start_proc.tv_sec) * 1000.0; + elapsed += (client->end_proc.tv_usec - client->start_proc.tv_usec) / 1000.0; + + req = escape_http_request (hdrs->path); + ref = escape_http_request (hdrs->referer); + ua = escape_http_request (hdrs->agent); + + ACCESS_LOG (("%s ", client->remote_ip)); + ACCESS_LOG (("- - ")); + ACCESS_LOG (("%s ", buf)); + ACCESS_LOG (("\"%s ", hdrs->method)); + ACCESS_LOG (("%s ", req ? req : "-")); + ACCESS_LOG (("%s\" ", hdrs->protocol)); + ACCESS_LOG (("%d ", status_code)); + ACCESS_LOG (("%d ", hdrs->buflen)); + ACCESS_LOG (("\"%s\" ", ref ? ref : "-")); + ACCESS_LOG (("\"%s\" ", ua ? ua : "-")); + ACCESS_LOG (("%u\n", elapsed)); + + if (req) + free (req); + if (ref) + free (ref); + if (ua) + free (ua); +} + +/* Send an HTTP error status to the given client. + * + * On success, the number of sent bytes is returned. */ +static int +http_error (WSClient *client, const char *buffer) { + /* do access logging */ + gettimeofday (&client->end_proc, NULL); + if (wsconfig.accesslog) + access_log (client, 400); + + return ws_respond (client, buffer, strlen (buffer)); +} + +/* Compute the SHA1 for the handshake. */ +static void +ws_sha1_digest (char *s, int len, unsigned char *digest) { + SHA1_CTX sha; + + SHA1Init (&sha); + SHA1Update (&sha, (uint8_t *) s, len); + SHA1Final (digest, &sha); +} + +/* Set the parsed websocket handshake headers. */ +static void +ws_set_handshake_headers (WSHeaders *headers) { + size_t klen = strlen (headers->ws_key); + size_t mlen = strlen (WS_MAGIC_STR); + size_t len = klen + mlen; + char *s = xmalloc (klen + mlen + 1); + uint8_t digest[SHA_DIGEST_LENGTH]; + + memset (digest, 0, sizeof *digest); + + memcpy (s, headers->ws_key, klen); + memcpy (s + klen, WS_MAGIC_STR, mlen + 1); + + ws_sha1_digest (s, len, digest); + + /* set response headers */ + headers->ws_accept = base64_encode ((unsigned char *) digest, sizeof (digest)); + headers->ws_resp = xstrdup (WS_SWITCH_PROTO_STR); + + if (!headers->upgrade) + headers->upgrade = xstrdup ("websocket"); + if (!headers->connection) + headers->connection = xstrdup ("Upgrade"); + + free (s); +} + +/* Send the websocket handshake headers to the given client. + * + * On success, the number of sent bytes is returned. */ +static int +ws_send_handshake_headers (WSClient *client, WSHeaders *headers) { + int bytes = 0; + char *str = xstrdup (""); + + ws_append_str (&str, headers->ws_resp); + ws_append_str (&str, CRLF); + + ws_append_str (&str, "Upgrade: "); + ws_append_str (&str, headers->upgrade); + ws_append_str (&str, CRLF); + + ws_append_str (&str, "Connection: "); + ws_append_str (&str, headers->connection); + ws_append_str (&str, CRLF); + + ws_append_str (&str, "Sec-WebSocket-Accept: "); + ws_append_str (&str, headers->ws_accept); + ws_append_str (&str, CRLF CRLF); + + bytes = ws_respond (client, str, strlen (str)); + free (str); + + return bytes; +} + +/* Given the HTTP connection headers, attempt to parse the web socket + * handshake headers. + * + * On success, the number of sent bytes is returned. */ +static int +ws_get_handshake (WSClient *client, WSServer *server) { + int bytes = 0, readh = 0; + char *buf = NULL; + + if (client->headers == NULL) + client->headers = new_wsheader (); + + buf = client->headers->buf; + readh = client->headers->buflen; + /* Probably the connection was closed before finishing handshake */ + if ((bytes = read_socket (client, buf + readh, WS_MAX_HEAD_SZ - readh)) < 1) { + if (client->status & WS_CLOSE) { + LOG (("Connection aborted %d [%s]...\n", client->listener, client->remote_ip)); + http_error (client, WS_BAD_REQUEST_STR); + } + LOG (("Can't establish handshake %d [%s]...\n", client->listener, client->remote_ip)); + return ws_set_status (client, WS_CLOSE, bytes); + } + client->headers->buflen += bytes; + + buf[client->headers->buflen] = '\0'; /* null-terminate */ + + /* Must have a \r\n\r\n */ + if (strstr (buf, "\r\n\r\n") == NULL) { + if (strlen (buf) < WS_MAX_HEAD_SZ) { + LOG (("Headers too long %d [%s]...\n", client->listener, client->remote_ip)); + return ws_set_status (client, WS_READING, bytes); + } + + LOG (("Invalid newlines for handshake %d [%s]...\n", client->listener, client->remote_ip)); + http_error (client, WS_BAD_REQUEST_STR); + return ws_set_status (client, WS_CLOSE, bytes); + } + + /* Ensure we have valid HTTP headers for the handshake */ + if (parse_headers (client->headers) != 0) { + LOG (("Invalid headers for handshake %d [%s]...\n", client->listener, client->remote_ip)); + http_error (client, WS_BAD_REQUEST_STR); + return ws_set_status (client, WS_CLOSE, bytes); + } + + /* Ensure we have the required headers */ + if (ws_verify_req_headers (client->headers) != 0) { + LOG (("Missing headers for handshake %d [%s]...\n", client->listener, client->remote_ip)); + http_error (client, WS_BAD_REQUEST_STR); + return ws_set_status (client, WS_CLOSE, bytes); + } + + ws_set_handshake_headers (client->headers); + + /* handshake response */ + ws_send_handshake_headers (client, client->headers); + + /* upon success, call onopen() callback */ + if (server->onopen && wsconfig.strict && !wsconfig.echomode) + server->onopen (server->pipeout, client); + client->headers->reading = 0; + + /* do access logging */ + gettimeofday (&client->end_proc, NULL); + if (wsconfig.accesslog) + access_log (client, 101); + LOG (("Active: %d\n", list_count (server->colist))); + + return ws_set_status (client, WS_OK, bytes); +} + +/* Send a data message to the given client. + * + * On success, 0 is returned. */ +int +ws_send_data (WSClient *client, WSOpcode opcode, const char *p, int sz) { + char *buf = NULL; + + buf = sanitize_utf8 (p, sz); + ws_send_frame (client, opcode, buf, sz); + free (buf); + + return 0; +} + +/* Read a websocket frame's header. + * + * On success, the number of bytes read is returned. */ +static int +ws_read_header (WSClient *client, WSFrame *frm, int pos, int need) { + char *buf = frm->buf; + int bytes = 0; + + /* read the first 2 bytes for basic frame info */ + if ((bytes = read_socket (client, buf + pos, need)) < 1) { + if (client->status & WS_CLOSE) + ws_error (client, WS_CLOSE_UNEXPECTED, "Unable to read header"); + return bytes; + } + frm->buflen += bytes; + frm->buf[frm->buflen] = '\0'; /* null-terminate */ + + return bytes; +} + +/* Read a websocket frame's payload. + * + * On success, the number of bytes read is returned. */ +static int +ws_read_payload (WSClient *client, WSMessage *msg, int pos, int need) { + char *buf = msg->payload; + int bytes = 0; + + /* read the first 2 bytes for basic frame info */ + if ((bytes = read_socket (client, buf + pos, need)) < 1) { + if (client->status & WS_CLOSE) + ws_error (client, WS_CLOSE_UNEXPECTED, "Unable to read payload"); + return bytes; + } + msg->buflen += bytes; + msg->payloadsz += bytes; + + return bytes; +} + +/* Set the basic frame headers on a frame structure. + * + * On success, 0 is returned. */ +static int +ws_set_front_header_fields (WSClient *client) { + WSFrame **frm = &client->frame; + char *buf = (*frm)->buf; + + (*frm)->fin = WS_FRM_FIN (*(buf)); + (*frm)->masking = WS_FRM_MASK (*(buf + 1)); + (*frm)->opcode = WS_FRM_OPCODE (*(buf)); + (*frm)->res = WS_FRM_R1 (*(buf)) || WS_FRM_R2 (*(buf)) || WS_FRM_R3 (*(buf)); + + /* should be masked and can't be using RESVd bits */ + if (!(*frm)->masking || (*frm)->res) + return ws_set_status (client, WS_ERR | WS_CLOSE, 1); + + return 0; +} + +/* Unmask the payload given the current frame's masking key. */ +static void +ws_unmask_payload (char *buf, int len, int offset, unsigned char mask[]) { + int i, j = 0; + + /* unmask data */ + for (i = offset; i < len; ++i, ++j) { + buf[i] ^= mask[j % 4]; + } +} + +/* Close a websocket connection. */ +static int +ws_handle_close (WSClient *client) { + client->status = WS_ERR | WS_CLOSE; + return ws_send_frame (client, WS_OPCODE_CLOSE, NULL, 0); +} + +/* Handle a websocket error. + * + * On success, the number of bytes sent is returned. */ +static int +ws_handle_err (WSClient *client, unsigned short code, WSStatus status, const char *m) { + client->status = status; + return ws_error (client, code, m); +} + +/* Handle a websocket pong. */ +static void +ws_handle_pong (WSClient *client) { + WSFrame **frm = &client->frame; + + if (!(*frm)->fin) { + ws_handle_err (client, WS_CLOSE_PROTO_ERR, WS_ERR | WS_CLOSE, NULL); + return; + } + ws_free_message (client); +} + +/* Handle a websocket ping from the client and it attempts to send + * back a pong as soon as possible. */ +static void +ws_handle_ping (WSClient *client) { + WSFrame **frm = &client->frame; + WSMessage **msg = &client->message; + char *buf = NULL, *tmp = NULL; + int pos = 0, len = (*frm)->payloadlen, newlen = 0; + + /* RFC states that Control frames themselves MUST NOT be + * fragmented. */ + if (!(*frm)->fin) { + ws_handle_err (client, WS_CLOSE_PROTO_ERR, WS_ERR | WS_CLOSE, NULL); + return; + } + + /* Control frames are only allowed to have payload up to and + * including 125 octets */ + if ((*frm)->payloadlen > 125) { + ws_handle_err (client, WS_CLOSE_PROTO_ERR, WS_ERR | WS_CLOSE, NULL); + return; + } + + /* No payload from ping */ + if (len == 0) { + ws_send_frame (client, WS_OPCODE_PONG, NULL, 0); + return; + } + + /* Copy the ping payload */ + pos = (*msg)->payloadsz - len; + buf = xcalloc (len, sizeof (char)); + memcpy (buf, (*msg)->payload + pos, len); + + /* Unmask it */ + ws_unmask_payload (buf, len, 0, (*frm)->mask); + + /* Resize the current payload (keep an eye on this realloc) */ + newlen = (*msg)->payloadsz - len; + tmp = realloc ((*msg)->payload, newlen); + if (tmp == NULL && newlen > 0) { + free ((*msg)->payload); + free (buf); + + (*msg)->payload = NULL; + client->status = WS_ERR | WS_CLOSE; + return; + } + + (*msg)->payload = tmp; + (*msg)->payloadsz -= len; + + ws_send_frame (client, WS_OPCODE_PONG, buf, len); + + (*msg)->buflen = 0; /* done with the current frame's payload */ + /* Control frame injected in the middle of a fragmented message. */ + if (!(*msg)->fragmented) { + ws_free_message (client); + } + free (buf); +} + +/* Ensure we have valid UTF-8 text payload. + * + * On error, or if the message is invalid, 1 is returned. + * On success, or if the message is valid, 0 is returned. */ +int +ws_validate_string (const char *str, int len) { + uint32_t state = UTF8_VALID; + + if (verify_utf8 (&state, str, len) == UTF8_INVAL) { + LOG (("Invalid UTF8 data!\n")); + return 1; + } + if (state != UTF8_VALID) { + LOG (("Invalid UTF8 data!\n")); + return 1; + } + + return 0; +} + +/* It handles a text or binary message frame from the client. */ +static void +ws_handle_text_bin (WSClient *client, WSServer *server) { + WSFrame **frm = &client->frame; + WSMessage **msg = &client->message; + int offset = (*msg)->mask_offset; + + /* All data frames after the initial data frame must have opcode 0 */ + if ((*msg)->fragmented && (*frm)->opcode != WS_OPCODE_CONTINUATION) { + client->status = WS_ERR | WS_CLOSE; + return; + } + + /* RFC states that there is a new masking key per frame, therefore, + * time to unmask... */ + ws_unmask_payload ((*msg)->payload, (*msg)->payloadsz, offset, (*frm)->mask); + /* Done with the current frame's payload */ + (*msg)->buflen = 0; + /* Reading a fragmented frame */ + (*msg)->fragmented = 1; + + if (!(*frm)->fin) + return; + + /* validate text data encoded as UTF-8 */ + if ((*msg)->opcode == WS_OPCODE_TEXT) { + if (ws_validate_string ((*msg)->payload, (*msg)->payloadsz) != 0) { + ws_handle_err (client, WS_CLOSE_INVALID_UTF8, WS_ERR | WS_CLOSE, NULL); + return; + } + } + + if ((*msg)->opcode != WS_OPCODE_CONTINUATION && server->onmessage) { + /* just echo the message to the client */ + if (wsconfig.echomode) + ws_send_data (client, (*msg)->opcode, (*msg)->payload, (*msg)->payloadsz); + /* just pipe out the message */ + else if (!wsconfig.strict) + ws_write_fifo (server->pipeout, (*msg)->payload, (*msg)->payloadsz); + else + server->onmessage (server->pipeout, client); + } + ws_free_message (client); +} + +/* Depending on the frame opcode, then we take certain decisions. */ +static void +ws_manage_payload_opcode (WSClient *client, WSServer *server) { + WSFrame **frm = &client->frame; + WSMessage **msg = &client->message; + + switch ((*frm)->opcode) { + case WS_OPCODE_CONTINUATION: + LOG (("CONTINUATION\n")); + /* first frame can't be a continuation frame */ + if (!(*msg)->fragmented) { + client->status = WS_ERR | WS_CLOSE; + break; + } + ws_handle_text_bin (client, server); + break; + case WS_OPCODE_TEXT: + case WS_OPCODE_BIN: + LOG (("TEXT\n")); + client->message->opcode = (*frm)->opcode; + ws_handle_text_bin (client, server); + break; + case WS_OPCODE_PONG: + LOG (("PONG\n")); + ws_handle_pong (client); + break; + case WS_OPCODE_PING: + LOG (("PING\n")); + ws_handle_ping (client); + break; + default: + LOG (("CLOSE\n")); + ws_handle_close (client); + } +} + +/* Set the extended payload length into the given pointer. */ +static void +ws_set_extended_header_size (const char *buf, int *extended) { + uint64_t payloadlen = 0; + /* determine the payload length, else read more data */ + payloadlen = WS_FRM_PAYLOAD (*(buf + 1)); + switch (payloadlen) { + case WS_PAYLOAD_EXT16: + *extended = 2; + break; + case WS_PAYLOAD_EXT64: + *extended = 8; + break; + } +} + +/* Set the extended payload length into our frame structure. */ +static void +ws_set_payloadlen (WSFrame *frm, const char *buf) { + uint64_t payloadlen = 0, len64; + uint16_t len16; + + /* determine the payload length, else read more data */ + payloadlen = WS_FRM_PAYLOAD (*(buf + 1)); + switch (payloadlen) { + case WS_PAYLOAD_EXT16: + memcpy (&len16, (buf + 2), sizeof (uint16_t)); + frm->payloadlen = ntohs (len16); + break; + case WS_PAYLOAD_EXT64: + memcpy (&len64, (buf + 2), sizeof (uint64_t)); + frm->payloadlen = be64toh (len64); + break; + default: + frm->payloadlen = payloadlen; + } +} + +/* Set the masking key into our frame structure. */ +static void +ws_set_masking_key (WSFrame *frm, const char *buf) { + uint64_t payloadlen = 0; + + /* determine the payload length, else read more data */ + payloadlen = WS_FRM_PAYLOAD (*(buf + 1)); + switch (payloadlen) { + case WS_PAYLOAD_EXT16: + memcpy (&frm->mask, buf + 4, sizeof (frm->mask)); + break; + case WS_PAYLOAD_EXT64: + memcpy (&frm->mask, buf + 10, sizeof (frm->mask)); + break; + default: + memcpy (&frm->mask, buf + 2, sizeof (frm->mask)); + } +} + +/* Attempt to read the frame's header and set the relevant data into + * our frame structure. + * + * On error, or if no data available to read, the number of bytes is + * returned and the appropriate connection status is set. + * On success, the number of bytes is returned. */ +static int +ws_get_frm_header (WSClient *client) { + WSFrame **frm = NULL; + int bytes = 0, readh = 0, need = 0, offset = 0, extended = 0; + + if (client->frame == NULL) + client->frame = new_wsframe (); + + frm = &client->frame; + + /* Read the first 2 bytes for basic frame info */ + readh = (*frm)->buflen; /* read from header so far */ + need = 2 - readh; /* need to read */ + if (need > 0) { + if ((bytes = ws_read_header (client, (*frm), readh, need)) < 1) + return bytes; + if (bytes != need) + return ws_set_status (client, WS_READING, bytes); + } + offset += 2; + + if (ws_set_front_header_fields (client) != 0) + return bytes; + + ws_set_extended_header_size ((*frm)->buf, &extended); + /* read the extended header */ + readh = (*frm)->buflen; /* read from header so far */ + need = (extended + offset) - readh; /* read from header field so far */ + if (need > 0) { + if ((bytes = ws_read_header (client, (*frm), readh, need)) < 1) + return bytes; + if (bytes != need) + return ws_set_status (client, WS_READING, bytes); + } + offset += extended; + + /* read the masking key */ + readh = (*frm)->buflen; /* read from header so far */ + need = (4 + offset) - readh; + if (need > 0) { + if ((bytes = ws_read_header (client, (*frm), readh, need)) < 1) + return bytes; + if (bytes != need) + return ws_set_status (client, WS_READING, bytes); + } + offset += 4; + + ws_set_payloadlen ((*frm), (*frm)->buf); + ws_set_masking_key ((*frm), (*frm)->buf); + + if ((*frm)->payloadlen > wsconfig.max_frm_size) { + ws_error (client, WS_CLOSE_TOO_LARGE, "Frame is too big"); + return ws_set_status (client, WS_ERR | WS_CLOSE, bytes); + } + + (*frm)->buflen = 0; + (*frm)->reading = 0; + (*frm)->payload_offset = offset; + + return ws_set_status (client, WS_OK, bytes); +} + +/* Attempt to realloc the message payload. + * + * On error, 1 is returned. + * On success, 0 is returned. */ +static int +ws_realloc_frm_payload (WSFrame *frm, WSMessage *msg) { + char *tmp = NULL; + uint64_t newlen = 0; + + newlen = msg->payloadsz + frm->payloadlen; + tmp = realloc (msg->payload, newlen); + if (tmp == NULL && newlen > 0) { + free (msg->payload); + msg->payload = NULL; + return 1; + } + msg->payload = tmp; + + return 0; +} + +/* Attempt to read the frame's payload and set the relevant data into + * our message structure. + * + * On error, or if no data available to read, the number of bytes is + * returned and the appropriate connection status is set. + * On success, the number of bytes is returned. */ +static int +ws_get_frm_payload (WSClient *client, WSServer *server) { + WSFrame **frm = NULL; + WSMessage **msg = NULL; + int bytes = 0, readh = 0, need = 0; + + if (client->message == NULL) + client->message = new_wsmessage (); + + frm = &client->frame; + msg = &client->message; + + /* message within the same frame */ + if ((*msg)->payload == NULL && (*frm)->payloadlen) + (*msg)->payload = xcalloc ((*frm)->payloadlen, sizeof (char)); + /* handle a new frame */ + else if ((*msg)->buflen == 0 && (*frm)->payloadlen) { + if (ws_realloc_frm_payload ((*frm), (*msg)) == 1) + return ws_set_status (client, WS_ERR | WS_CLOSE, 0); + } + + readh = (*msg)->buflen; /* read from so far */ + need = (*frm)->payloadlen - readh; /* need to read */ + if (need > 0) { + if ((bytes = ws_read_payload (client, (*msg), (*msg)->payloadsz, need)) < 0) + return bytes; + if (bytes != need) + return ws_set_status (client, WS_READING, bytes); + } + + (*msg)->mask_offset = (*msg)->payloadsz - (*msg)->buflen; + + ws_manage_payload_opcode (client, server); + ws_free_frame (client); + + return bytes; +} + +/* Determine if we need to read a frame's header or its payload. + * + * On success, the number of bytes is returned. */ +static int +ws_get_message (WSClient *client, WSServer *server) { + int bytes = 0; + if ((client->frame == NULL) || (client->frame->reading)) + if ((bytes = ws_get_frm_header (client)) < 1 || client->frame->reading) + return bytes; + return ws_get_frm_payload (client, server); +} + +/* Determine if we need to read an HTTP request or a websocket frame. + * + * On success, the number of bytes is returned. */ +static int +read_client_data (WSClient *client, WSServer *server) { + int bytes = 0; + + /* Handshake */ + if ((!(client->headers) || (client->headers->reading))) + bytes = ws_get_handshake (client, server); + /* Message */ + else + bytes = ws_get_message (client, server); + + return bytes; +} + +/* Handle a tcp close connection. */ +static void +handle_tcp_close (int conn, WSClient *client, WSServer *server) { + LOG (("Closing TCP %d [%s]\n", client->listener, client->remote_ip)); + +#ifdef HAVE_LIBSSL + if (client->ssl) + shutdown_ssl (client); +#endif + + shutdown (conn, SHUT_RDWR); + /* upon close, call onclose() callback */ + if (server->onclose && wsconfig.strict && !wsconfig.echomode) + (*server->onclose) (server->pipeout, client); + + /* do access logging */ + gettimeofday (&client->end_proc, NULL); + if (wsconfig.accesslog) + access_log (client, 200); + + /* errored out while parsing a frame or a message */ + if (client->status & WS_ERR) { + ws_clear_queue (client); + ws_free_frame (client); + ws_free_message (client); + } + + server->closing = 0; + ws_close (conn); + +#ifdef HAVE_LIBSSL + if (client->ssl) + SSL_free (client->ssl); + client->ssl = NULL; +#endif + + /* remove client from our list */ + ws_remove_client_from_list (client, server); + LOG (("Connection Closed.\nActive: %d\n", list_count (server->colist))); +} + +/* Handle a tcp read close connection. */ +static void +handle_read_close (int *conn, WSClient *client, WSServer *server) { + /* We can still try to send a message to the client if not forcing close, (nice + * goodbye), else proceed to close it */ + if (!(client->status & WS_CLOSE) && client->status & WS_SENDING) { + server->closing = 1; + set_pollfd (client->listener, POLLOUT); + return; + } + handle_tcp_close (*conn, client, server); +} + +/* Handle a new socket connection. */ +static void +handle_accept (int listener, WSServer *server) { + WSClient *client = NULL; + int newfd; + + newfd = accept_client (listener, &server->colist); + if (newfd == -1) + return; + + if (!(client = ws_get_client_from_list (newfd, &server->colist))) + return; + +#ifdef HAVE_LIBSSL + /* set flag to do TLS handshake */ + if (wsconfig.use_ssl) + client->sslstatus |= WS_TLS_ACCEPTING; +#endif + + LOG (("Accepted: %d [%s]\n", newfd, client->remote_ip)); +} + +/* Handle a tcp read. */ +static void +handle_reads (int *conn, WSServer *server) { + WSClient *client = NULL; + + if (!(client = ws_get_client_from_list (*conn, &server->colist))) + return; + + LOG (("Handling read %d [%s]...\n", client->listener, client->remote_ip)); + +#ifdef HAVE_LIBSSL + if (handle_ssl_pending_rw (conn, server, client) == 0) + return; +#endif + + /* *INDENT-OFF* */ + client->start_proc = client->end_proc = (struct timeval) {0}; + /* *INDENT-ON* */ + gettimeofday (&client->start_proc, NULL); + read_client_data (client, server); + /* An error occurred while reading data or connection closed */ + if ((client->status & WS_CLOSE)) { + handle_read_close (conn, client, server); + *conn = -1; + } +} + +/* Handle a tcp write close connection. */ +static void +handle_write_close (int conn, WSClient *client, WSServer *server) { + handle_tcp_close (conn, client, server); +} + +/* Handle a tcp write. */ +static void +handle_writes (int *conn, WSServer *server) { + WSClient *client = NULL; + + if (!(client = ws_get_client_from_list (*conn, &server->colist))) + return; + +#ifdef HAVE_LIBSSL + if (handle_ssl_pending_rw (conn, server, client) == 0) + return; +#endif + + ws_respond (client, NULL, 0); /* buffered data */ + /* done sending data */ + if (client->sockqueue == NULL) { + client->status &= ~WS_SENDING; + set_pollfd (client->listener, server->closing ? 0 : POLLIN); + } + + /* An error occurred while sending data or while reading data but still + * waiting from the last send() from the server to the client. e.g., + * sending status code */ + if ((client->status & WS_CLOSE) && !(client->status & WS_SENDING)) + handle_write_close (*conn, client, server); +} + +/* Create named pipe (FIFO) with the given pipe name. + * + * On error, 1 is returned. + * On success, 0 is returned. */ +int +ws_setfifo (const char *pipename) { + struct stat fistat; + const char *f = pipename; + + if (access (f, F_OK) == 0) + return 0; + + if (mkfifo (f, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) < 0) + FATAL ("Unable to set fifo: %s.", strerror (errno)); + if (stat (f, &fistat) < 0) + FATAL ("Unable to stat fifo: %s.", strerror (errno)); + if (!S_ISFIFO (fistat.st_mode)) + FATAL ("pipe is not a fifo: %s.", strerror (errno)); + + return 0; +} + +/* Open a named pipe (FIFO) for input to the server (reader). */ +static void +ws_openfifo_in (WSPipeIn *pipein) { + ws_setfifo (wsconfig.pipein); + /* we should be able to open it at as reader */ + if ((pipein->fd = open (wsconfig.pipein, O_RDWR | O_NONBLOCK)) < 0) + FATAL ("Unable to open fifo in: %s.", strerror (errno)); +} + + +/* Open a named pipe (FIFO) for output from the server (writer). */ +static int +ws_openfifo_out (WSPipeOut *pipeout) { + int status = 0; + + ws_setfifo (wsconfig.pipeout); + status = open (wsconfig.pipeout, O_WRONLY | O_NONBLOCK); + /* will attempt on the next write */ + if (status == -1 && errno == ENXIO) + LOG (("Unable to open fifo out: %s.\n", strerror (errno))); + else if (status < 0) + FATAL ("Unable to open fifo out: %s.", strerror (errno)); + pipeout->fd = status; + + return status; +} + +/* Set a new named pipe for incoming messages and one for outgoing + * messages from the client. */ +static void +ws_fifo (WSServer *server) { + ws_openfifo_in (server->pipein); + set_pollfd (server->pipein->fd, POLLIN); + ws_openfifo_out (server->pipeout); + set_pollfd (server->pipeout->fd, POLLOUT); +} + +/* Clear the queue for an outgoing named pipe. */ +static void +clear_fifo_queue (WSPipeOut *pipeout) { + WSQueue **queue = &pipeout->fifoqueue; + if (!(*queue)) + return; + + if ((*queue)->queued) + free ((*queue)->queued); + (*queue)->queued = NULL; + (*queue)->qlen = 0; + + free ((*queue)); + (*queue) = NULL; +} + +/* Attempt to realloc the current sent queue for an outgoing named pip + * (FIFO). + * + * On error, 1 is returned and the connection status is closed and + * reopened. + * On success, 0 is returned. */ +static int +ws_realloc_fifobuf (WSPipeOut *pipeout, const char *buf, int len) { + WSQueue *queue = pipeout->fifoqueue; + char *tmp = NULL; + int newlen = 0; + + newlen = queue->qlen + len; + tmp = realloc (queue->queued, newlen); + if (tmp == NULL && newlen > 0) { + ws_close (pipeout->fd); + clear_fifo_queue (pipeout); + ws_openfifo_out (pipeout); + return 1; + } + + queue->queued = tmp; + memcpy (queue->queued + queue->qlen, buf, len); + queue->qlen += len; + + return 0; +} + +/* Set into a queue the data that couldn't be sent in the outgoing + * FIFO. */ +static void +ws_queue_fifobuf (WSPipeOut *pipeout, const char *buffer, int len, int bytes) { + WSQueue **queue = &pipeout->fifoqueue; + + if (bytes < 1) + bytes = 0; + + (*queue) = xcalloc (1, sizeof (WSQueue)); + (*queue)->queued = xcalloc (len - bytes, sizeof (char)); + memcpy ((*queue)->queued, buffer + bytes, len - bytes); + (*queue)->qlen = len - bytes; + + pipeout->status |= WS_SENDING; + set_pollfd (pipeout->fd, POLLOUT); +} + +/* Attempt to send the given buffer to the given outgoing FIFO. + * + * On error, the data is queued up. + * On success, the number of bytes sent is returned. */ +static int +ws_write_fifo_data (WSPipeOut *pipeout, char *buffer, int len) { + int bytes = 0; + + bytes = write (pipeout->fd, buffer, len); + + /* At this point, the reader probably closed the pipe, so a cheap *hack* for + * this is to close the pipe on our end and attempt to reopen it. If unable to + * do so, then let it be -1 and try on the next attempt to write. */ + if (bytes == -1 && errno == EPIPE) { + ws_close (pipeout->fd); + ws_openfifo_out (pipeout); + return bytes; + } + if (bytes < len || (bytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))) + ws_queue_fifobuf (pipeout, buffer, len, bytes); + + return bytes; +} + +/* Attempt to send the queued up client's data through the outgoing + * named pipe (FIFO) . + * + * On error, 1 is returned and the connection status is set. + * On success, the number of bytes sent is returned. */ +static int +ws_write_fifo_cache (WSPipeOut *pipeout) { + WSQueue *queue = pipeout->fifoqueue; + int bytes = 0; + + bytes = write (pipeout->fd, queue->queued, queue->qlen); + + /* At this point, the reader probably closed the pipe, so a cheap *hack* for + * this is to close the pipe on our end and attempt to reopen it. If unable to + * do so, then let it be -1 and try on the next attempt to write. */ + if (bytes == -1 && errno == EPIPE) { + ws_close (pipeout->fd); + ws_openfifo_out (pipeout); + return bytes; + } + + if (chop_nchars (queue->queued, bytes, queue->qlen) == 0) + clear_fifo_queue (pipeout); + else + queue->qlen -= bytes; + + return bytes; +} + +/* An entry point to attempt to send the client's data into an + * outgoing named pipe (FIFO). + * + * On success, the number of bytes sent is returned. */ +int +ws_write_fifo (WSPipeOut *pipeout, char *buffer, int len) { + int bytes = 0; + + if (pipeout->fd == -1 && ws_openfifo_out (pipeout) == -1) + return bytes; + + /* attempt to send the whole buffer */ + if (pipeout->fifoqueue == NULL) + bytes = ws_write_fifo_data (pipeout, buffer, len); + /* buffer not empty, just append new data */ + else if (pipeout->fifoqueue != NULL && buffer != NULL) { + if (ws_realloc_fifobuf (pipeout, buffer, len) == 1) + return bytes; + } + /* send from cache buffer */ + else { + bytes = ws_write_fifo_cache (pipeout); + } + + if (pipeout->fifoqueue == NULL) { + pipeout->status &= ~WS_SENDING; + set_pollfd (pipeout->fd, 0); + } + + return bytes; +} + +/* Clear an incoming FIFO packet and header data. */ +static void +clear_fifo_packet (WSPipeIn *pipein) { + memset (pipein->hdr, 0, sizeof (pipein->hdr)); + pipein->hlen = 0; + + if (pipein->packet == NULL) + return; + + if (pipein->packet->data) + free (pipein->packet->data); + free (pipein->packet); + pipein->packet = NULL; +} + +/* Broadcast to all connected clients the given message. */ +static int +ws_broadcast_fifo (WSClient *client, WSServer *server) { + WSPacket *packet = server->pipein->packet; + + LOG (("Broadcasting to %d [%s] ", client->listener, client->remote_ip)); + if (client == NULL) + return 1; + + if (client->headers == NULL || client->headers->ws_accept == NULL) { + /* no handshake for this client */ + LOG (("No headers. Closing %d [%s]\n", client->listener, client->remote_ip)); + return -1; + } + + LOG ((" - Sending...\n")); + ws_send_data (client, packet->type, packet->data, packet->size); + + return 0; +} + +static void +ws_broadcast_fifo_to_clients (WSServer *server) { + WSClient *client = NULL; + void *data = NULL; + uint32_t *close_list = NULL; + int n = 0, idx = 0, i = 0, listener = 0; + + if ((n = list_count (server->colist)) == 0) + return; + + close_list = xcalloc (n, sizeof (uint32_t)); + /* *INDENT-OFF* */ + GSLIST_FOREACH (server->colist, data, { + client = data; + if (ws_broadcast_fifo(client, server) == -1) + close_list[idx++] = client->listener; + }); + /* *INDENT-ON* */ + + client = NULL; + for (i = 0; i < idx; ++i) { + listener = close_list[i]; + if ((client = ws_get_client_from_list (listener, &server->colist))) + handle_tcp_close (listener, client, server); + } + + free (close_list); +} + +/* Send a message from the incoming named pipe to specific client + * given the socket id. */ +static void +ws_send_strict_fifo_to_client (WSServer *server, int listener, WSPacket *pa) { + WSClient *client = NULL; + + if (!(client = ws_get_client_from_list (listener, &server->colist))) + return; + /* no handshake for this client */ + if (client->headers == NULL || client->headers->ws_accept == NULL) { + LOG (("No headers. Closing %d [%s]\n", client->listener, client->remote_ip)); + + handle_tcp_close (client->listener, client, server); + return; + } + ws_send_data (client, pa->type, pa->data, pa->len); +} + +/* Attempt to read message from a named pipe (FIFO). + * + * On error, -1 is returned. + * On success, the number of bytes read is returned. */ +int +ws_read_fifo (int fd, char *buf, int *buflen, int pos, int need) { + int bytes = 0; + + bytes = read (fd, buf + pos, need); + if (bytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) + return bytes; + else if (bytes == -1) + return bytes; + *buflen += bytes; + + return bytes; +} + +/* Pack the given value into a network byte order. + * + * On success, the number size of uint32_t is returned. */ +size_t +pack_uint32 (void *buf, uint32_t val) { + uint32_t v32 = htonl (val); + memcpy (buf, &v32, sizeof (uint32_t)); + + return sizeof (uint32_t); +} + +/* Unpack the given value into a host byte order. + * + * On success, the number size of uint32_t is returned. */ +size_t +unpack_uint32 (const void *buf, uint32_t *val) { + uint32_t v32 = 0; + memcpy (&v32, buf, sizeof (uint32_t)); + *val = ntohl (v32); + + return sizeof (uint32_t); +} + +/* Ensure the fields coming from the named pipe are valid. + * + * On error, 1 is returned. + * On success, 0 is returned. */ +static int +validate_fifo_packet (uint32_t type, int size) { + if (type != WS_OPCODE_TEXT && type != WS_OPCODE_BIN) { + LOG (("Invalid fifo packet type\n")); + return 1; + } + + if (size > wsconfig.max_frm_size) { + LOG (("Invalid fifo packet size\n")); + return 1; + } + + return 0; +} + +/* Handle reading and sending the incoming data from the named pipe on + * strict mode. */ +static void +handle_strict_fifo (WSServer *server) { + WSPipeIn *pi = server->pipein; + WSPacket **pa = &pi->packet; + int bytes = 0, readh = 0, need = 0; + + char *ptr = NULL; + uint32_t listener = 0, type = 0, size = 0; + + readh = pi->hlen; /* read from header so far */ + need = HDR_SIZE - readh; /* need to read */ + if (need > 0) { + if ((bytes = ws_read_fifo (pi->fd, pi->hdr, &pi->hlen, readh, need)) < 0) + return; + if (bytes != need) + return; + } + + /* unpack size, and type */ + ptr = pi->hdr; + ptr += unpack_uint32 (ptr, &listener); + ptr += unpack_uint32 (ptr, &type); + ptr += unpack_uint32 (ptr, &size); + + if (validate_fifo_packet (type, size) == 1) { + ws_close (pi->fd); + clear_fifo_packet (pi); + ws_openfifo_in (pi); + return; + } + + if ((*pa) == NULL) { + (*pa) = xcalloc (1, sizeof (WSPacket)); + (*pa)->type = type; + (*pa)->size = size; + (*pa)->data = xcalloc (size, sizeof (char)); + } + + readh = (*pa)->len; /* read from payload so far */ + need = (*pa)->size - readh; /* need to read */ + if (need > 0) { + if ((bytes = ws_read_fifo (pi->fd, (*pa)->data, &(*pa)->len, readh, need)) < 0) + return; + if (bytes != need) + return; + } + + /* no clients to send data to */ + if (list_count (server->colist) == 0) { + clear_fifo_packet (pi); + return; + } + + /* Either send it to a specific client or broadcast message to all + * clients */ + if (listener != 0) + ws_send_strict_fifo_to_client (server, listener, *pa); + else + ws_broadcast_fifo_to_clients (server); + clear_fifo_packet (pi); +} + +/* Handle reading and sending the incoming data from the named pipe on + * a fixed buffer mode. */ +static void +handle_fixed_fifo (WSServer *server) { + WSPipeIn *pi = server->pipein; + WSPacket **pa = &pi->packet; + + int bytes = 0; + char buf[PIPE_BUF] = { 0 }; + + if ((bytes = read (pi->fd, buf, PIPE_BUF - 1)) < 0) + return; + + buf[bytes] = '\0'; /* null-terminate */ + if (ws_validate_string (buf, bytes) != 0) + return; + + (*pa) = xcalloc (1, sizeof (WSPacket)); + (*pa)->type = WS_OPCODE_TEXT; + (*pa)->size = bytes; + (*pa)->data = xstrdup (buf); + + /* no clients to send data to */ + if (list_count (server->colist) == 0) { + clear_fifo_packet (pi); + return; + } + + /* broadcast message to all clients */ + ws_broadcast_fifo_to_clients (server); + clear_fifo_packet (pi); +} + +/* Determine which mode should use the incoming message from the FIFO. */ +static void +handle_fifo (WSServer *server) { + if (wsconfig.strict) + handle_strict_fifo (server); + else + handle_fixed_fifo (server); +} + +/* Creates an endpoint for communication and start listening for + * connections on a socket */ +static void +ws_socket (int *listener) { + if (wsconfig.unix_socket) { + struct sockaddr_un servaddr; + + /* Create a TCP socket. */ + if ((*listener = socket (AF_UNIX, SOCK_STREAM, 0)) == -1) + FATAL ("Unable to open socket: %s.", strerror (errno)); + + memset (&servaddr, 0, sizeof (servaddr)); + servaddr.sun_family = AF_UNIX; + strncpy (servaddr.sun_path, wsconfig.unix_socket, sizeof (servaddr.sun_path) - 1); + + /* Bind the socket to the address. */ + if (bind (*listener, (struct sockaddr *) &servaddr, sizeof (servaddr)) != 0) + FATAL ("Unable to set bind: %s.", strerror (errno)); + } else { + int ov = 1, bind_result = 0; + struct addrinfo hints, *ai, *p; + + memset (&hints, 0, sizeof (hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + + if (getaddrinfo (wsconfig.host, wsconfig.port, &hints, &ai) != 0) + FATAL ("Unable to set server: %s.", gai_strerror (errno)); + + for (p = ai; p != NULL; p = p->ai_next) { + *listener = socket (p->ai_family, p->ai_socktype, p->ai_protocol); + if (*listener == -1) + continue; + + if (setsockopt (*listener, SOL_SOCKET, SO_REUSEADDR, &ov, sizeof (ov)) == -1) { + close (*listener); + continue; + } + + if (bind (*listener, p->ai_addr, p->ai_addrlen) == 0) { + bind_result = 1; + break; + } + + close (*listener); + } + + freeaddrinfo (ai); + + if (bind_result == 0) + FATAL ("Unable to set bind: %s.", strerror (errno)); + } + + if (listen (*listener, SOMAXCONN) == -1) + FATAL ("Unable to listen: %s.", strerror (errno)); +} + +/* Start the websocket server and start to monitor multiple file + * descriptors until we have something to read or write. */ +void +ws_start (WSServer *server) { + int listener = -1, ret = 0; + struct pollfd *cfdstate = NULL, *pfd, *efd; + nfds_t ncfdstate = 0; + bool run = true; + + if (server->self_pipe[0] != -1) + set_pollfd (server->self_pipe[0], POLLIN); + +#ifdef HAVE_LIBSSL + if (wsconfig.sslcert && wsconfig.sslkey) { + LOG (("==Using TLS/SSL==\n")); + wsconfig.use_ssl = 1; + if (initialize_ssl_ctx (server)) { + LOG (("Unable to initialize_ssl_ctx\n")); + return; + } + } +#endif + + ws_socket (&listener); + set_pollfd (listener, POLLIN); + + while (run) { + /* take a copy of the fdstate and give that to poll to allow + * any dispatch to modify the real fdstate for the next pass */ + if (ncfdstate != nfdstate) { + free (cfdstate); + cfdstate = xmalloc (nfdstate * sizeof (*cfdstate)); + memset (cfdstate, 0, sizeof (*cfdstate) * nfdstate); + ncfdstate = nfdstate; + } + memcpy (cfdstate, fdstate, ncfdstate * sizeof (*cfdstate)); + + /* yep, wait patiently */ + if ((ret = poll (cfdstate, nfdstate, -1)) == -1) { + switch (errno) { + case EINTR: + LOG (("A signal was caught on poll(2)\n")); + break; + default: + FATAL ("Unable to poll: %s.", strerror (errno)); + } + } + + /* iterate over existing connections */ + efd = cfdstate + nfdstate; + for (pfd = cfdstate; pfd < efd; pfd++) { + if (pfd->revents & POLLHUP) + LOG (("Got POLLHUP %d\n", pfd->fd)); + if (pfd->revents & POLLNVAL) + LOG (("Got POLLNVAL %d\n", pfd->fd)); + if (pfd->revents & POLLERR) + LOG (("Got POLLERR %d\n", pfd->fd)); + + /* handle self-pipe trick */ + if (pfd->fd == server->self_pipe[0]) { + if (pfd->revents & POLLIN) { + LOG (("Handled self-pipe to close event loop.\n")); + run = false; + break; + } + } else if (pfd->fd == server->pipein->fd) { + /* handle pipein */ + if (pfd->revents & POLLIN) + handle_fifo (server); + } else if (pfd->fd == server->pipeout->fd) { + /* handle pipeout */ + if (pfd->revents & POLLOUT) + ws_write_fifo (server->pipeout, NULL, 0); + } else if (pfd->fd == listener) { + /* handle new connections */ + if (pfd->revents & POLLIN) + handle_accept (listener, server); + } else { + /* handle data from a client */ + if (pfd->revents & POLLIN) { + if (server->closing) { + struct pollfd *ffd = get_pollfd (pfd->fd); + if (ffd != NULL) + ffd->events &= ~POLLIN; + } else + handle_reads (&pfd->fd, server); + } + /* handle sending data to a client */ + if (pfd->revents & POLLOUT) + handle_writes (&pfd->fd, server); + } + } + } + + free (cfdstate); + ws_close (listener); + if (server->self_pipe[0] != -1) + unset_pollfd (server->self_pipe[0]); + + if (wsconfig.unix_socket) { + unlink (wsconfig.unix_socket); + } +} + +/* Set the origin so the server can force connections to have the + * given HTTP origin. */ +void +ws_set_config_origin (const char *origin) { + wsconfig.origin = origin; +} + +/* Set the maximum websocket frame size. */ +void +ws_set_config_frame_size (int max_frm_size) { + wsconfig.max_frm_size = max_frm_size; +} + +/* Set specific name for the reader named pipe. */ +void +ws_set_config_pipein (const char *pipein) { + wsconfig.pipein = pipein; +} + +/* Set specific name for the writer named pipe. */ +void +ws_set_config_pipeout (const char *pipeout) { + wsconfig.pipeout = pipeout; +} + +/* Set a path and a file for the access log. */ +void +ws_set_config_accesslog (const char *accesslog) { + wsconfig.accesslog = accesslog; + + if (access_log_open (wsconfig.accesslog) == 1) + FATAL ("Unable to open access log: %s.", strerror (errno)); +} + +/* Set if the server should handle strict named pipe handling. */ +void +ws_set_config_strict (int strict) { + wsconfig.strict = strict; +} + +/* Set the server into echo mode. */ +void +ws_set_config_echomode (int echomode) { + wsconfig.echomode = echomode; +} + +/* Set the server host bind address. */ +void +ws_set_config_host (const char *host) { + wsconfig.host = host; +} + +/* Set the server unix socket bind address. */ +void +ws_set_config_unix_socket (const char *unix_socket) { + wsconfig.unix_socket = unix_socket; +} + +/* Set the server port bind address. */ +void +ws_set_config_port (const char *port) { + wsconfig.port = port; +} + +/* Set specific name for the SSL certificate. */ +void +ws_set_config_sslcert (const char *sslcert) { + wsconfig.sslcert = sslcert; +} + +/* Set specific name for the SSL key. */ +void +ws_set_config_sslkey (const char *sslkey) { + wsconfig.sslkey = sslkey; +} + +/* Create a new websocket server context. */ +WSServer * +ws_init (const char *host, const char *port, void (*initopts) (void)) { + WSServer *server = new_wsserver (); + server->pipein = new_wspipein (); + server->pipeout = new_wspipeout (); + server->self_pipe[0] = server->self_pipe[1] = -1; + + wsconfig.accesslog = NULL; + wsconfig.host = host; + wsconfig.unix_socket = NULL; + wsconfig.max_frm_size = WS_MAX_FRM_SZ; + wsconfig.origin = NULL; + wsconfig.pipein = NULL; + wsconfig.pipeout = NULL; + wsconfig.sslcert = NULL; + wsconfig.sslkey = NULL; + wsconfig.port = port; + wsconfig.strict = 0; + wsconfig.use_ssl = 0; + + initopts (); + ws_fifo (server); + + return server; +} diff --git a/src/websocket.h b/src/websocket.h new file mode 100644 index 0000000000..2846d6b527 --- /dev/null +++ b/src/websocket.h @@ -0,0 +1,323 @@ +/** + * _______ _______ __ __ + * / ____/ | / / ___/____ _____/ /_____ / /_ + * / / __ | | /| / /\__ \/ __ \/ ___/ //_/ _ \/ __/ + * / /_/ / | |/ |/ /___/ / /_/ / /__/ ,< / __/ /_ + * \____/ |__/|__//____/\____/\___/_/|_|\___/\__/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2024 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#if HAVE_CONFIG_H +#include +#endif + +#ifndef WEBSOCKET_H_INCLUDED +#define WEBSOCKET_H_INCLUDED + +#include +#include +#include +#include + +#if HAVE_LIBSSL +#include +#include +#include +#endif + +#if defined(__linux__) || defined(__CYGWIN__) +# include +#if ((__GLIBC__ == 2) && (__GLIBC_MINOR__ < 9)) +#if defined(__BYTE_ORDER) && (__BYTE_ORDER == __LITTLE_ENDIAN) +# include +# define htobe16(x) htons(x) +# define htobe64(x) (((uint64_t)htonl(((uint32_t)(((uint64_t)(x)) >> 32)))) | \ + (((uint64_t)htonl(((uint32_t)(x)))) << 32)) +# define be16toh(x) ntohs(x) +# define be32toh(x) ntohl(x) +# define be64toh(x) (((uint64_t)ntohl(((uint32_t)(((uint64_t)(x)) >> 32)))) | \ + (((uint64_t)ntohl(((uint32_t)(x)))) << 32)) +#else +# error Byte Order not supported! +#endif +#endif +#elif defined(__sun__) +# include +# define htobe16(x) BE_16(x) +# define htobe64(x) BE_64(x) +# define be16toh(x) BE_IN16(x) +# define be32toh(x) BE_IN32(x) +# define be64toh(x) BE_IN64(x) +#elif defined(__FreeBSD__) || defined(__NetBSD__) +# include +#elif defined(__OpenBSD__) +# include +# if !defined(be16toh) +# define be16toh(x) betoh16(x) +# endif +# if !defined(be32toh) +# define be32toh(x) betoh32(x) +# endif +# if !defined(be64toh) +# define be64toh(x) betoh64(x) +# endif +#elif defined(__APPLE__) +# include +# define htobe16(x) OSSwapHostToBigInt16(x) +# define htobe64(x) OSSwapHostToBigInt64(x) +# define be16toh(x) OSSwapBigToHostInt16(x) +# define be32toh(x) OSSwapBigToHostInt32(x) +# define be64toh(x) OSSwapBigToHostInt64(x) +#else +# error Platform not supported! +#endif + +#define MAX(a,b) (((a)>(b))?(a):(b)) +#include "gslist.h" + +#define WS_BAD_REQUEST_STR "HTTP/1.1 400 Invalid Request\r\n\r\n" +#define WS_SWITCH_PROTO_STR "HTTP/1.1 101 Switching Protocols" +#define WS_TOO_BUSY_STR "HTTP/1.1 503 Service Unavailable\r\n\r\n" + +#define CRLF "\r\n" +#define SHA_DIGEST_LENGTH 20 + +/* packet header is 3 unit32_t : type, size, listener */ +#define HDR_SIZE 3 * 4 +#define WS_MAX_FRM_SZ 1048576 /* 1 MiB max frame size */ +#define WS_THROTTLE_THLD 2097152 /* 2 MiB throttle threshold */ +#define WS_MAX_HEAD_SZ 8192 /* a reasonable size for request headers */ + +#define WS_MAGIC_STR "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" +#define WS_PAYLOAD_EXT16 126 +#define WS_PAYLOAD_EXT64 127 +#define WS_PAYLOAD_FULL 125 +#define WS_FRM_HEAD_SZ 16 /* frame header size */ + +#define WS_FRM_FIN(x) (((x) >> 7) & 0x01) +#define WS_FRM_MASK(x) (((x) >> 7) & 0x01) +#define WS_FRM_R1(x) (((x) >> 6) & 0x01) +#define WS_FRM_R2(x) (((x) >> 5) & 0x01) +#define WS_FRM_R3(x) (((x) >> 4) & 0x01) +#define WS_FRM_OPCODE(x) ((x) & 0x0F) +#define WS_FRM_PAYLOAD(x) ((x) & 0x7F) + +#define WS_CLOSE_NORMAL 1000 +#define WS_CLOSE_GOING_AWAY 1001 +#define WS_CLOSE_PROTO_ERR 1002 +#define WS_CLOSE_INVALID_UTF8 1007 +#define WS_CLOSE_TOO_LARGE 1009 +#define WS_CLOSE_UNEXPECTED 1011 + +typedef enum WSSTATUS { + WS_OK = 0, + WS_ERR = (1 << 0), + WS_CLOSE = (1 << 1), + WS_READING = (1 << 2), + WS_SENDING = (1 << 3), + WS_THROTTLING = (1 << 4), + WS_TLS_ACCEPTING = (1 << 5), + WS_TLS_READING = (1 << 6), + WS_TLS_WRITING = (1 << 7), + WS_TLS_SHUTTING = (1 << 8), +} WSStatus; + +typedef enum WSOPCODE { + WS_OPCODE_CONTINUATION = 0x00, + WS_OPCODE_TEXT = 0x01, + WS_OPCODE_BIN = 0x02, + WS_OPCODE_END = 0x03, + WS_OPCODE_CLOSE = 0x08, + WS_OPCODE_PING = 0x09, + WS_OPCODE_PONG = 0x0A, +} WSOpcode; + +typedef struct WSQueue_ { + char *queued; /* queue data */ + int qlen; /* queue length */ +} WSQueue; + +typedef struct WSPacket_ { + uint32_t type; /* packet type (fixed-size) */ + uint32_t size; /* payload size in bytes (fixed-size) */ + char *data; /* payload */ + int len; /* payload buffer len */ +} WSPacket; + +/* WS HTTP Headers */ +typedef struct WSHeaders_ { + int reading; + int buflen; + char buf[WS_MAX_HEAD_SZ + 1]; + + char *agent; + char *path; + char *method; + char *protocol; + char *host; + char *origin; + char *upgrade; + char *referer; + char *connection; + char *ws_protocol; + char *ws_key; + char *ws_sock_ver; + + char *ws_accept; + char *ws_resp; +} WSHeaders; + +/* A WebSocket Message */ +typedef struct WSFrame_ { + /* frame format */ + WSOpcode opcode; /* frame opcode */ + unsigned char fin; /* frame fin flag */ + unsigned char mask[4]; /* mask key */ + uint8_t res; /* extensions */ + int payload_offset; /* end of header/start of payload */ + int payloadlen; /* payload length (for each frame) */ + + /* status flags */ + int reading; /* still reading frame's header part? */ + int masking; /* are we masking the frame? */ + + char buf[WS_FRM_HEAD_SZ + 1]; /* frame's header */ + int buflen; /* recv'd buf length so far (for each frame) */ +} WSFrame; + +/* A WebSocket Message */ +typedef struct WSMessage_ { + WSOpcode opcode; /* frame opcode */ + int fragmented; /* reading a fragmented frame */ + int mask_offset; /* for fragmented frames */ + + char *payload; /* payload message */ + int payloadsz; /* total payload size (whole message) */ + int buflen; /* recv'd buf length so far (for each frame) */ +} WSMessage; + +/* A WebSocket Client */ +typedef struct WSClient_ { + /* socket data */ + int listener; /* socket */ + char remote_ip[INET6_ADDRSTRLEN]; /* client IP */ + + WSQueue *sockqueue; /* sending buffer */ + WSHeaders *headers; /* HTTP headers */ + WSFrame *frame; /* frame headers */ + WSMessage *message; /* message */ + WSStatus status; /* connection status */ + + struct timeval start_proc; + struct timeval end_proc; + +#ifdef HAVE_LIBSSL + SSL *ssl; + WSStatus sslstatus; /* ssl connection status */ +#endif +} WSClient; + +/* Config OOptions */ +typedef struct WSPipeIn_ { + int fd; /* named pipe FD */ + + WSPacket *packet; /* FIFO data's buffer */ + + char hdr[HDR_SIZE]; /* FIFO header's buffer */ + int hlen; +} WSPipeIn; + +/* Pipe Out */ +typedef struct WSPipeOut_ { + int fd; /* named pipe FD */ + WSQueue *fifoqueue; /* FIFO out queue */ + WSStatus status; /* connection status */ +} WSPipeOut; + +/* Config OOptions */ +typedef struct WSConfig_ { + /* Config Options */ + const char *accesslog; + const char *host; + const char *origin; + const char *pipein; + const char *pipeout; + const char *port; + const char *sslcert; + const char *sslkey; + const char *unix_socket; + int echomode; + int strict; + int max_frm_size; + int use_ssl; +} WSConfig; + +/* A WebSocket Instance */ +typedef struct WSServer_ { + /* Server Status */ + int closing; + + /* Callbacks */ + int (*onclose) (WSPipeOut * pipeout, WSClient * client); + int (*onmessage) (WSPipeOut * pipeout, WSClient * client); + int (*onopen) (WSPipeOut * pipeout, WSClient * client); + + /* self-pipe */ + int self_pipe[2]; + /* FIFO reader */ + WSPipeIn *pipein; + /* FIFO writer */ + WSPipeOut *pipeout; + /* Connected Clients */ + GSLList *colist; + +#ifdef HAVE_LIBSSL + SSL_CTX *ctx; +#endif +} WSServer; + +int ws_read_fifo (int fd, char *buf, int *buflen, int pos, int need); +int ws_send_data (WSClient * client, WSOpcode opcode, const char *p, int sz); +int ws_setfifo (const char *pipename); +int ws_validate_string (const char *str, int len); +int ws_write_fifo (WSPipeOut * pipeout, char *buffer, int len); +size_t pack_uint32 (void *buf, uint32_t val); +size_t unpack_uint32 (const void *buf, uint32_t * val); +void set_nonblocking (int listener); +void ws_set_config_accesslog (const char *accesslog); +void ws_set_config_echomode (int echomode); +void ws_set_config_frame_size (int max_frm_size); +void ws_set_config_host (const char *host); +void ws_set_config_unix_socket (const char *unix_socket); +void ws_set_config_origin (const char *origin); +void ws_set_config_pipein (const char *pipein); +void ws_set_config_pipeout (const char *pipeout); +void ws_set_config_port (const char *port); +void ws_set_config_sslcert (const char *sslcert); +void ws_set_config_sslkey (const char *sslkey); +void ws_set_config_strict (int strict); +void ws_start (WSServer * server); +void ws_stop (WSServer * server); +WSServer *ws_init (const char *host, const char *port, void (*initopts) (void)); + +#endif // for #ifndef WEBSOCKET_H diff --git a/src/win/mman.h b/src/win/mman.h new file mode 100644 index 0000000000..b238b7f538 --- /dev/null +++ b/src/win/mman.h @@ -0,0 +1,52 @@ +#ifndef _MMAN_H_ +#define _MMAN_H_ + +/* Protections */ +#define PROT_NONE 0x00 /* no permissions */ +#define PROT_READ 0x01 /* pages can be read */ +#define PROT_WRITE 0x02 /* pages can be written */ +#define PROT_EXEC 0x04 /* pages can be executed */ + +/* Sharing type and options */ +#define MAP_SHARED 0x0001 /* share changes */ +#define MAP_PRIVATE 0x0002 /* changes are private */ +#define MAP_COPY MAP_PRIVATE /* Obsolete */ +#define MAP_FIXED 0x0010 /* map addr must be exactly as requested */ +#define MAP_RENAME 0x0020 /* Sun: rename private pages to file */ +#define MAP_NORESERVE 0x0040 /* Sun: don't reserve needed swap area */ +#define MAP_INHERIT 0x0080 /* region is retained after exec */ +#define MAP_NOEXTEND 0x0100 /* for MAP_FILE, don't change file size */ +#define MAP_HASSEMAPHORE 0x0200 /* region may contain semaphores */ +#define MAP_STACK 0x0400 /* region grows down, like a stack */ + +/* Error returned from mmap() */ +#define MAP_FAILED ((void *)-1) + +/* Flags to msync */ +#define MS_ASYNC 0x01 /* perform asynchronous writes */ +#define MS_SYNC 0x02 /* perform synchronous writes */ +#define MS_INVALIDATE 0x04 /* invalidate cached data */ + +/* File modes for 'open' not defined in MinGW32 (not used by mmap) */ +#ifndef S_IWGRP +#define S_IWGRP 0 +#define S_IRGRP 0 +#define S_IROTH 0 +#endif + +/** + * Map a file to a memory region + */ +void *mmap (void *addr, unsigned int len, int prot, int flags, int fd, unsigned int offset); + +/** + * Unmap a memory region + */ +int munmap (void *addr, int len); + +/** + * Synchronize a mapped region + */ +int msync (char *addr, int len, int flags); + +#endif /* _MMAN_H_ */ diff --git a/src/win/mmap.c b/src/win/mmap.c new file mode 100644 index 0000000000..5f3c1ccdd8 --- /dev/null +++ b/src/win/mmap.c @@ -0,0 +1,170 @@ +#include +#include +#ifdef _WIN32 +#include +#endif +#include +#include "mman.h" + +static const char id[] = "$Id: tpl.c 107 2007-04-20 17:11:29Z thanson $"; + +/** + * @brief Map a file to a memory region + * + * This function emulates the POSIX mmap() using CreateFileMapping() and + * MapViewOfFile() + * + * @param addr the suggested start address (if != 0) + * @param len length of the region + * @param prot region accessibility, bitwise OR of PROT_READ, PROT_WRITE, PROT_EXEC + * @param flags mapping type and options (ignored) + * @param fd object to be mapped into memory + * @param offset offset into mapped object + * @return pointer to the memory region, or NULL in case of error + */ +void * +mmap (void *addr, unsigned int len, int prot, int flags, int fd, unsigned int offset) { + DWORD wprot; + DWORD waccess; + HANDLE h; + void *region; + + /* Translate read/write/exec flags into WIN32 constants */ + switch (prot) { + case PROT_READ: + wprot = PAGE_READONLY; + break; + case PROT_EXEC: + wprot = PAGE_EXECUTE_READ; + break; + case PROT_READ | PROT_EXEC: + wprot = PAGE_EXECUTE_READ; + break; + case PROT_WRITE: + wprot = PAGE_READWRITE; + break; + case PROT_READ | PROT_WRITE: + wprot = PAGE_READWRITE; + break; + case PROT_READ | PROT_WRITE | PROT_EXEC: + wprot = PAGE_EXECUTE_READWRITE; + break; + case PROT_WRITE | PROT_EXEC: + wprot = PAGE_EXECUTE_READWRITE; + break; + } + + /* Obtaing handle to map region */ + h = CreateFileMapping ((HANDLE) _get_osfhandle (fd), 0, wprot, 0, len, 0); + if (h == NULL) { + DWORD error = GetLastError (); + + /* Try and translate some error codes */ + switch (error) { + case ERROR_ACCESS_DENIED: + case ERROR_INVALID_ACCESS: + errno = EACCES; + break; + case ERROR_OUTOFMEMORY: + case ERROR_NOT_ENOUGH_MEMORY: + errno = ENOMEM; + break; + default: + errno = EINVAL; + break; + } + return MAP_FAILED; + } + + + /* Translate sharing options into WIN32 constants */ + switch (wprot) { + case PAGE_READONLY: + waccess = FILE_MAP_READ; + break; + case PAGE_READWRITE: + waccess = FILE_MAP_WRITE; + break; + } + + /* Map file and return pointer */ + region = MapViewOfFile (h, waccess, 0, 0, 0); + if (region == NULL) { + DWORD error = GetLastError (); + + /* Try and translate some error codes */ + switch (error) { + case ERROR_ACCESS_DENIED: + case ERROR_INVALID_ACCESS: + errno = EACCES; + break; + case ERROR_INVALID_HANDLE: + errno = EBADF; + break; + default: + errno = EINVAL; + break; + } + CloseHandle (h); + return MAP_FAILED; + } + CloseHandle (h); /* ok to call UnmapViewOfFile after this */ + + /* All fine */ + return region; +} + + +/** + * @brief Unmap a memory region + * + * This is a wrapper around UnmapViewOfFile in the win32 API + * + * @param addr start address + * @param len length of the region + * @return 0 for success, -1 for error + */ +int +munmap (void *addr, int len) { + if (UnmapViewOfFile (addr)) { + return 0; + } else { + errno = EINVAL; + return -1; + } +} + + +/** + * Synchronize a mapped region + * + * This is a wrapper around FlushViewOfFile + * + * @param addr start address + * @param len number of bytes to flush + * @param flags sync options -- currently ignored + * @return 0 for success, -1 for error + */ +int +msync (char *addr, int len, int flags) { + if (FlushViewOfFile (addr, len) == 0) { + DWORD error = GetLastError (); + + /* Try and translate some error codes */ + switch (error) { + case ERROR_INVALID_PARAMETER: + errno = EINVAL; + break; + case ERROR_WRITE_FAULT: + errno = EIO; + break; + default: + errno = EINVAL; + break; + } + return -1; + } + + /* Success */ + return 0; +} diff --git a/src/xmalloc.c b/src/xmalloc.c new file mode 100644 index 0000000000..bac7b98d9d --- /dev/null +++ b/src/xmalloc.c @@ -0,0 +1,84 @@ +/** + * xmalloc.c -- *alloc functions with error handling + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2022 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#if !defined __SUNPRO_C +#include +#endif +#include +#include + +#include "error.h" +#include "xmalloc.h" + +/* Self-checking wrapper to malloc() */ +void * +xmalloc (size_t size) { + void *ptr; + + if ((ptr = malloc (size)) == NULL) + FATAL ("Unable to allocate memory - failed."); + + return (ptr); +} + +char * +xstrdup (const char *s) { + char *ptr; + size_t len; + + len = strlen (s) + 1; + ptr = xmalloc (len); + + strncpy (ptr, s, len); + return (ptr); +} + +/* Self-checking wrapper to calloc() */ +void * +xcalloc (size_t nmemb, size_t size) { + void *ptr; + + if ((ptr = calloc (nmemb, size)) == NULL) + FATAL ("Unable to calloc memory - failed."); + + return (ptr); +} + +/* Self-checking wrapper to realloc() */ +void * +xrealloc (void *oldptr, size_t size) { + void *newptr; + + if ((newptr = realloc (oldptr, size)) == NULL) + FATAL ("Unable to reallocate memory - failed"); + + return (newptr); +} diff --git a/src/xmalloc.h b/src/xmalloc.h new file mode 100644 index 0000000000..861b5c8be3 --- /dev/null +++ b/src/xmalloc.h @@ -0,0 +1,38 @@ +/** + * ______ ___ + * / ____/___ / | _____________ __________ + * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ + * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) + * \____/\____/_/ |_\___/\___/\___/____/____/ + * + * The MIT License (MIT) + * Copyright (c) 2009-2022 Gerardo Orellana + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef XMALLOC_H_INCLUDED +#define XMALLOC_H_INCLUDED + +char *xstrdup (const char *s); +void *xcalloc (size_t nmemb, size_t size); +void *xmalloc (size_t size); +void *xrealloc (void *oldptr, size_t size); + +#endif diff --git a/tcabinet.c b/tcabinet.c deleted file mode 100644 index 004d623ed1..0000000000 --- a/tcabinet.c +++ /dev/null @@ -1,894 +0,0 @@ -/** - * tcabinet.c -- Tokyo Cabinet database functions - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "tcabinet.h" - -#ifdef HAVE_LIBGEOIP -#include "geolocation.h" -#endif - -#include "commons.h" -#include "error.h" -#include "parser.h" -#include "settings.h" -#include "util.h" -#include "xmalloc.h" - -#ifdef TCB_BTREE - -TCBDB *ht_browsers = NULL; -TCBDB *ht_countries = NULL; -TCBDB *ht_date_bw = NULL; -TCBDB *ht_file_bw = NULL; -TCBDB *ht_file_serve_usecs = NULL; -TCBDB *ht_general_stats = NULL; -TCBDB *ht_host_bw = NULL; -TCBDB *ht_hostnames = NULL; -TCBDB *ht_hosts_agents = NULL; -TCBDB *ht_host_serve_usecs = NULL; -TCBDB *ht_hosts = NULL; -TCBDB *ht_keyphrases = NULL; -TCBDB *ht_not_found_requests = NULL; -TCBDB *ht_os = NULL; -TCBDB *ht_referrers = NULL; -TCBDB *ht_referring_sites = NULL; -TCBDB *ht_request_keys = NULL; -TCBDB *ht_request_methods = NULL; -TCBDB *ht_request_protocols = NULL; -TCBDB *ht_requests = NULL; -TCBDB *ht_requests_static = NULL; -TCBDB *ht_status_code = NULL; -TCBDB *ht_unique_visitors = NULL; -TCBDB *ht_unique_vis = NULL; - -#else - -TCMDB *ht_browsers = NULL; -TCMDB *ht_countries = NULL; -TCMDB *ht_date_bw = NULL; -TCMDB *ht_file_bw = NULL; -TCMDB *ht_file_serve_usecs = NULL; -TCMDB *ht_host_bw = NULL; -TCMDB *ht_hostnames = NULL; -TCMDB *ht_hosts = NULL; -TCMDB *ht_host_serve_usecs = NULL; -TCMDB *ht_keyphrases = NULL; -TCMDB *ht_not_found_requests = NULL; -TCMDB *ht_os = NULL; -TCMDB *ht_hosts_agents = NULL; -TCMDB *ht_referrers = NULL; -TCMDB *ht_referring_sites = NULL; -TCMDB *ht_request_methods = NULL; -TCMDB *ht_requests = NULL; -TCMDB *ht_request_keys = NULL; -TCMDB *ht_request_protocols = NULL; -TCMDB *ht_requests_static = NULL; -TCMDB *ht_status_code = NULL; -TCMDB *ht_unique_vis = NULL; -TCMDB *ht_unique_visitors = NULL; - -#endif - -#ifdef TCB_BTREE -static char * -tc_db_set_path (const char *dbname) -{ - char *path; - - if (conf.db_path != NULL) { - path = xmalloc (snprintf (NULL, 0, "%s%s", conf.db_path, dbname) + 1); - sprintf (path, "%s%s", conf.db_path, dbname); - } else { - path = xmalloc (snprintf (NULL, 0, "%s%s", TC_DBPATH, dbname) + 1); - sprintf (path, "%s%s", TC_DBPATH, dbname); - } - return path; -} -#endif - -/* Open the database handle */ -#ifdef TCB_BTREE -static TCBDB * -tc_db_create (const char *dbname) -{ - TCBDB *bdb; - char *path = NULL; - int ecode; - uint32_t lcnum, ncnum, lmemb, nmemb, bnum, flags; - - path = tc_db_set_path (dbname); - - bdb = tcbdbnew (); - - lcnum = conf.cache_lcnum > 0 ? conf.cache_lcnum : TC_LCNUM; - ncnum = conf.cache_ncnum > 0 ? conf.cache_ncnum : TC_NCNUM; - - LOG_DEBUG (("%s\n", path)); - LOG_DEBUG (("lcnum, ncnum: %d, %d\n", lcnum, ncnum)); - - /* set the caching parameters of a B+ tree database object */ - if (!tcbdbsetcache (bdb, lcnum, ncnum)) { - free (path); - LOG_DEBUG (("Unable to set TCB cache.\n\n")); - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Unable to set TCB cache"); - } - - LOG_DEBUG (("xmmap: %d\n", conf.xmmap)); - /* set the size of the extra mapped memory */ - if (conf.xmmap > 0 && !tcbdbsetxmsiz (bdb, conf.xmmap)) { - free (path); - LOG_DEBUG (("Unable to set TCB xmmap.\n\n")); - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Unable to set TCB xmmap"); - } - - lmemb = conf.tune_lmemb > 0 ? conf.tune_lmemb : TC_LMEMB; - nmemb = conf.tune_nmemb > 0 ? conf.tune_nmemb : TC_NMEMB; - bnum = conf.tune_bnum > 0 ? conf.tune_bnum : TC_BNUM; - - /* compression */ - flags = BDBTLARGE; - LOG_DEBUG (("flags: BDBTLARGE")); - if (conf.compression == TC_BZ2) { - flags |= BDBTBZIP; - LOG_DEBUG ((" | BDBTBZIP")); - } else if (conf.compression == TC_ZLIB) { - flags |= BDBTDEFLATE; - LOG_DEBUG ((" | BDBTDEFLATE")); - } - - LOG_DEBUG (("\nlmemb, nmemb, bnum: %d, %d, %d\n\n", lmemb, nmemb, bnum)); - /* set the tuning parameters */ - tcbdbtune (bdb, lmemb, nmemb, bnum, 8, 10, flags); - - /* open flags */ - flags = BDBOWRITER | BDBOCREAT; - if (!conf.load_from_disk) - flags |= BDBOTRUNC; - - /* attempt to open the database */ - if (!tcbdbopen (bdb, path, flags)) { - free (path); - ecode = tcbdbecode (bdb); - - LOG_DEBUG (("%s\n\n", tcbdberrmsg (ecode))); - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - tcbdberrmsg (ecode)); - } - free (path); - - return bdb; -} -#endif - -#ifdef TCB_MEMHASH -static TCMDB * -tc_ht_create (void) -{ - TCMDB *mdb = tcmdbnew (); - return mdb; -} -#endif - -/* Initialize TokyoCabinet storage */ -void -init_storage (void) -{ -/* *INDENT-OFF* */ -#ifdef TCB_BTREE - ht_browsers = tc_db_create (DB_BROWSERS); - ht_countries = tc_db_create (DB_COUNTRIES); - ht_date_bw = tc_db_create (DB_DATE_BW); - ht_file_bw = tc_db_create (DB_FILE_BW); - ht_file_serve_usecs = tc_db_create (DB_FILE_SERVE_USECS); - ht_general_stats = tc_db_create (DB_GENERAL_STATS); - ht_host_bw = tc_db_create (DB_HOST_BW); - ht_hostnames = tc_db_create (DB_HOSTNAMES); - ht_hosts_agents = tc_db_create (DB_HOST_AGENTS); - ht_host_serve_usecs = tc_db_create (DB_HOST_SERVE_USECS); - ht_hosts = tc_db_create (DB_HOSTS); - ht_keyphrases = tc_db_create (DB_KEYPHRASES); - ht_not_found_requests = tc_db_create (DB_NOT_FOUND_REQUESTS); - ht_os = tc_db_create (DB_OS); - ht_referrers = tc_db_create (DB_REFERRERS); - ht_referring_sites = tc_db_create (DB_REFERRING_SITES); - ht_request_keys = tc_db_create (DB_REQUEST_KEYS); - ht_request_methods = tc_db_create (DB_REQUEST_METHODS); - ht_request_protocols = tc_db_create (DB_REQUEST_PROTOCOLS); - ht_requests_static = tc_db_create (DB_REQUESTS_STATIC); - ht_requests = tc_db_create (DB_REQUESTS); - ht_status_code = tc_db_create (DB_STATUS_CODE); - ht_unique_visitors = tc_db_create (DB_UNIQUE_VISITORS); - ht_unique_vis = tc_db_create (DB_UNIQUE_VIS); -#else - ht_browsers = tc_ht_create (); - ht_countries = tc_ht_create (); - ht_date_bw = tc_ht_create (); - ht_file_bw = tc_ht_create (); - ht_file_serve_usecs = tc_ht_create (); - ht_host_bw = tc_ht_create (); - ht_hostnames = tc_ht_create (); - ht_hosts_agents = tc_ht_create (); - ht_host_serve_usecs = tc_ht_create (); - ht_hosts = tc_ht_create (); - ht_keyphrases = tc_ht_create (); - ht_not_found_requests = tc_ht_create (); - ht_os = tc_ht_create (); - ht_referrers = tc_ht_create (); - ht_referring_sites = tc_ht_create (); - ht_request_methods = tc_ht_create (); - ht_request_protocols = tc_ht_create (); - ht_requests_static = tc_ht_create (); - ht_requests = tc_ht_create (); - ht_request_keys = tc_ht_create (); - ht_status_code = tc_ht_create (); - ht_unique_visitors = tc_ht_create (); - ht_unique_vis = tc_ht_create (); -#endif -/* *INDENT-ON* */ -} - -/* Close the database handle */ -#ifdef TCB_BTREE -int -tc_db_close (void *db, const char *dbname) -{ - TCBDB *bdb = db; - char *path = NULL; - int ecode; - - if (bdb == NULL) - return 1; - - /* close the database */ - if (!tcbdbclose (bdb)) { - ecode = tcbdbecode (bdb); - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - tcbdberrmsg (ecode)); - } - /* delete the object */ - tcbdbdel (bdb); - - if (conf.keep_db_files || conf.load_from_disk) - return 0; - - /* remove database file */ - path = tc_db_set_path (dbname); - if (!tcremovelink (path)) - LOG_DEBUG (("Unable to remove DB: %s\n", path)); - free (path); - - return 0; -} -#endif - -#ifdef TCB_MEMHASH -int -tc_db_close (void *db, GO_UNUSED const char *dbname) -{ - TCMDB *mdb = db; - if (mdb == NULL) - return 1; - tcmdbdel (mdb); - return 0; -} -#endif - -#ifdef TCB_BTREE -/* Calls the given function for each of the key/value pairs */ -void -tc_db_foreach (void *db, void (*fp) (BDBCUR * cur, char *k, int s, void *u), - void *user_data) -{ - TCBDB *bdb = db; - BDBCUR *cur; - int ksize; - char *key = NULL; - - cur = tcbdbcurnew (bdb); - tcbdbcurfirst (cur); - while ((key = tcbdbcurkey (cur, &ksize)) != NULL) - (*fp) (cur, key, ksize, user_data); - - tcbdbcurdel (cur); -} -#endif - -#ifdef TCB_MEMHASH -/* Calls the given function for each of the key/value pairs */ -void -tc_db_foreach (void *db, void (*fp) (TCMDB * m, char *k, int s, void *u), - void *user_data) -{ - TCMDB *mdb = db; - int ksize; - char *key = NULL; - - tcmdbiterinit (mdb); - while ((key = tcmdbiternext (mdb, &ksize)) != NULL) - (*fp) (mdb, key, ksize, user_data); -} -#endif - -/* Return number of records of a hash database */ -unsigned int -get_ht_size (void *db) -{ -#ifdef TCB_BTREE - TCBDB *bdb = db; - if (bdb == NULL) - return 0; - return tcbdbrnum (bdb); -#else - TCMDB *mdb = db; - if (mdb == NULL) - return 0; - return tcmdbrnum (mdb); -#endif -} - -/* Add an integer to a record */ -static int -tc_db_add_int (void *db, const char *k, int n) -{ -#ifdef TCB_BTREE - TCBDB *bdb = db; - return tcbdbaddint (bdb, k, strlen (k), n) == 1 ? KEY_NOT_FOUND : KEY_FOUND; -#else - TCMDB *mdb = db; - return tcmdbaddint (mdb, k, strlen (k), n) == 1 ? KEY_NOT_FOUND : KEY_FOUND; -#endif -} - -/* Store generic data into the given hash table */ -int -process_generic_data (void *db, const char *k) -{ - return tc_db_add_int (db, k, 1); -} - -static void * -tc_db_get (void *db, const char *k) -{ - int sp = 0; -#ifdef TCB_BTREE - TCBDB *bdb = db; - return tcbdbget (bdb, k, strlen (k), &sp); -#else - TCMDB *mdb = db; - return tcmdbget (mdb, k, strlen (k), &sp); -#endif -} - -static void -tc_db_put (void *db, const char *k, void *v, uint32_t v_size) -{ -#ifdef TCB_BTREE - int ecode; - TCBDB *bdb = db; - if (!tcbdbput (bdb, k, strlen (k), v, v_size)) { - ecode = tcbdbecode (bdb); - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - tcbdberrmsg (ecode)); - } -#else - TCMDB *mdb = db; - tcmdbput (mdb, k, strlen (k), v, v_size); -#endif -} - -void * -tc_db_get_str (void *db, const char *k) -{ -#ifdef TCB_BTREE - TCBDB *bdb = db; - return tcbdbget2 (bdb, k); -#else - TCMDB *mdb = db; - return tcmdbget2 (mdb, k); -#endif -} - -void -tc_db_put_str (void *db, const char *k, const char *v) -{ -#ifdef TCB_BTREE - int ecode; - TCBDB *bdb = db; - if (!tcbdbput2 (bdb, k, v)) { - ecode = tcbdbecode (bdb); - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - tcbdberrmsg (ecode)); - } -#else - TCMDB *mdb = db; - tcmdbput2 (mdb, k, v); -#endif -} - -int -tc_db_get_int (void *db, const char *k) -{ - void *value; - int num = 0; - - if ((db == NULL) || (k == NULL)) - return (EINVAL); - - if ((value = tc_db_get (db, k)) != NULL) { - num = (*(int *) value); - free (value); - } - - return num; -} - -uint64_t -tc_db_get_uint64 (void *db, const char *k) -{ - uint64_t num = 0; - void *value; - - if ((db == NULL) || (k == NULL)) - return (EINVAL); - - if ((value = tc_db_get (db, k)) != NULL) { - num = (*(uint64_t *) value); - free (value); - } - - return num; -} - -int -process_request (void *db, const char *k, const GLogItem * glog) -{ - if ((db == NULL) || (k == NULL)) - return (EINVAL); - - process_generic_data (db, k); - if (conf.append_protocol && glog->protocol) - tc_db_put_str (ht_request_protocols, k, glog->protocol); - if (conf.append_method && glog->method) - tc_db_put_str (ht_request_methods, k, glog->method); - tc_db_put_str (ht_request_keys, k, glog->req); - - return 0; -} - -int -process_request_meta (void *db, const char *k, uint64_t size) -{ - void *value; - uint64_t add_value; - - if ((db == NULL) || (k == NULL)) - return (EINVAL); - - if ((value = tc_db_get (db, k)) != NULL) { - add_value = (*(uint64_t *) value) + size; - } else { - add_value = 0 + size; - } - tc_db_put (db, k, &add_value, sizeof (uint64_t)); - free (value); - - return 0; -} - -int -process_opesys (void *db, const char *k, const char *os_type) -{ - GOpeSys *opesys; - - if ((db == NULL) || (k == NULL)) - return (EINVAL); - - if ((opesys = tc_db_get (db, k)) != NULL) { - opesys->hits++; - } else { - opesys = xcalloc (1, sizeof (GOpeSys)); - xstrncpy (opesys->os_type, os_type, OPESYS_TYPE_LEN); - opesys->hits = 1; - } - tc_db_put (db, k, opesys, sizeof (GOpeSys)); - if (opesys) - free (opesys); - - return 0; -} - -int -process_browser (void *db, const char *k, const char *browser_type) -{ - GBrowser *browser; - - if ((db == NULL) || (k == NULL)) - return (EINVAL); - - if ((browser = tc_db_get (db, k)) != NULL) { - browser->hits++; - } else { - browser = xcalloc (1, sizeof (GOpeSys)); - xstrncpy (browser->browser_type, browser_type, BROWSER_TYPE_LEN); - browser->hits = 1; - } - tc_db_put (db, k, browser, sizeof (GBrowser)); - if (browser) - free (browser); - - return 0; -} - -#ifdef HAVE_LIBGEOIP -int -process_geolocation (void *db, const char *ctry, const char *cont, - const char *city) -{ - GLocation *location; - - if ((db == NULL) || (ctry == NULL)) - return (EINVAL); - - if ((location = tc_db_get (db, ctry)) != NULL) { - location->hits++; - } else { - location = xcalloc (1, sizeof (GLocation)); - xstrncpy (location->continent, cont, CONTINENT_LEN); - if (city[0] != '\0') - xstrncpy (location->city, city, CITY_LEN); - location->hits = 1; - } - tc_db_put (db, ctry, location, sizeof (GLocation)); - if (location) - free (location); - - return 0; -} -#endif - -/* process host agent strings */ -int -process_host_agents (char *host, char *agent) -{ -#ifdef TCB_BTREE - TCBDB *db = ht_hosts_agents; -#else - TCMDB *db = ht_hosts_agents; -#endif - - char *ptr_value = NULL, *tmp = NULL, *a = NULL; - void *value_ptr; - size_t len1, len2; - - if ((db == NULL) || (host == NULL) || (agent == NULL)) - return (EINVAL); - - a = xstrdup (agent); - - if ((value_ptr = tc_db_get_str (db, host)) != NULL) { - ptr_value = (char *) value_ptr; - if (strstr (ptr_value, a)) { - if (a != NULL) - goto out; - } - - len1 = strlen (ptr_value); - len2 = strlen (a); - - tmp = xmalloc (len1 + len2 + 2); - memcpy (tmp, ptr_value, len1); - tmp[len1] = '|'; - /* NUL-terminated */ - memcpy (tmp + len1 + 1, a, len2 + 1); - } else - tmp = alloc_string (a); - - tc_db_put_str (db, host, tmp); - -out: - if (a != NULL) - free (a); - if (tmp != NULL) - free (tmp); - if (value_ptr != NULL) - free (value_ptr); - - return 0; -} - -uint64_t -get_serve_time (const char *k, GModule module) -{ -#ifdef TCB_BTREE - TCBDB *db = NULL; -#else - TCMDB *db = NULL; -#endif - - uint64_t serve_time = 0; - void *value; - - /* serve time modules */ - switch (module) { - case HOSTS: - db = ht_host_serve_usecs; - break; - case REQUESTS: - case REQUESTS_STATIC: - case NOT_FOUND: - db = ht_file_serve_usecs; - break; - default: - db = NULL; - } - - if (db == NULL) - return 0; - - if ((value = tc_db_get (db, k)) != NULL) { - serve_time = (*(uint64_t *) value); - free (value); - } - - return serve_time; -} - -uint64_t -get_bandwidth (char *k, GModule module) -{ -#ifdef TCB_BTREE - TCBDB *db = NULL; -#else - TCMDB *db = NULL; -#endif - uint64_t bw = 0; - void *value; - - /* bandwidth modules */ - switch (module) { - case VISITORS: - db = ht_date_bw; - break; - case REQUESTS: - case REQUESTS_STATIC: - case NOT_FOUND: - db = ht_file_bw; - break; - case HOSTS: - db = ht_host_bw; - break; - default: - db = NULL; - } - - if (db == NULL) - return 0; - - if ((value = tc_db_get (db, k)) != NULL) { - bw = (*(uint64_t *) value); - free (value); - } - - return bw; -} - -char * -get_request_meta (const char *k, GReqMeta meta) -{ -#ifdef TCB_BTREE - TCBDB *db = NULL; -#else - TCMDB *db = NULL; -#endif - void *value; - - switch (meta) { - case REQUEST: - db = ht_request_keys; - break; - case REQUEST_METHOD: - db = ht_request_methods; - break; - case REQUEST_PROTOCOL: - db = ht_request_protocols; - break; - default: - db = NULL; - } - - if (db == NULL) - return 0; - - if ((value = tc_db_get_str (db, k)) != NULL) - return (char *) value; - - return alloc_string ("---"); -} - -#ifdef TCB_BTREE -TCBDB * -get_ht_by_module (GModule module) -{ - TCBDB *bdb; - - switch (module) { - case VISITORS: - bdb = ht_unique_vis; - break; - case REQUESTS: - bdb = ht_requests; - break; - case REQUESTS_STATIC: - bdb = ht_requests_static; - break; - case NOT_FOUND: - bdb = ht_not_found_requests; - break; - case HOSTS: - bdb = ht_hosts; - break; - case OS: - bdb = ht_os; - break; - case BROWSERS: - bdb = ht_browsers; - break; - case REFERRERS: - bdb = ht_referrers; - break; - case REFERRING_SITES: - bdb = ht_referring_sites; - break; - case KEYPHRASES: - bdb = ht_keyphrases; - break; -#ifdef HAVE_LIBGEOIP - case GEO_LOCATION: - bdb = ht_countries; - break; -#endif - case STATUS_CODES: - bdb = ht_status_code; - break; - default: - return NULL; - } - - return bdb; -} -#endif - -#ifdef TCB_MEMHASH -TCMDB * -get_ht_by_module (GModule module) -{ - TCMDB *mdb; - - switch (module) { - case VISITORS: - mdb = ht_unique_vis; - break; - case REQUESTS: - mdb = ht_requests; - break; - case REQUESTS_STATIC: - mdb = ht_requests_static; - break; - case NOT_FOUND: - mdb = ht_not_found_requests; - break; - case HOSTS: - mdb = ht_hosts; - break; - case OS: - mdb = ht_os; - break; - case BROWSERS: - mdb = ht_browsers; - break; - case REFERRERS: - mdb = ht_referrers; - break; - case REFERRING_SITES: - mdb = ht_referring_sites; - break; - case KEYPHRASES: - mdb = ht_keyphrases; - break; -#ifdef HAVE_LIBGEOIP - case GEO_LOCATION: - mdb = ht_countries; - break; -#endif - case STATUS_CODES: - mdb = ht_status_code; - break; - default: - return NULL; - } - - return mdb; -} -#endif - -static void -set_raw_data (char *key, void *value, GRawData * raw_data) -{ - raw_data->items[raw_data->idx].key = key; - raw_data->items[raw_data->idx].value = value; - raw_data->idx++; -} - -#ifdef TCB_BTREE -static void -data_iter_generic (BDBCUR * cur, char *key, GO_UNUSED int ksize, - void *user_data) -{ - GRawData *raw_data = user_data; - void *value; - int vsize = 0; - - value = tcbdbcurval (cur, &vsize); - if (value) - set_raw_data (key, value, raw_data); - tcbdbcurnext (cur); -} -#endif - -#ifdef TCB_MEMHASH -static void -data_iter_generic (TCMDB * mdb, char *key, GO_UNUSED int ksize, void *user_data) -{ - GRawData *raw_data = user_data; - void *value; - - value = tc_db_get (mdb, key); - if (value) - set_raw_data (key, value, raw_data); -} -#endif - -GRawData * -parse_raw_data (void *db, int ht_size, GModule module) -{ - GRawData *raw_data; - - raw_data = new_grawdata (); - raw_data->size = ht_size; - raw_data->module = module; - raw_data->idx = 0; - raw_data->items = new_grawdata_item (ht_size); - - tc_db_foreach (db, data_iter_generic, raw_data); - sort_raw_data (raw_data, module, ht_size); - - return raw_data; -} diff --git a/tcabinet.h b/tcabinet.h deleted file mode 100644 index 2012cab975..0000000000 --- a/tcabinet.h +++ /dev/null @@ -1,166 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#if HAVE_CONFIG_H -#include -#endif - -#ifndef TCABINET_H_INCLUDED -#define TCABINET_H_INCLUDED - -#include - -#include "commons.h" -#include "parser.h" - -#define TC_MMAP 0 -#define TC_LCNUM 1024 -#define TC_NCNUM 512 -#define TC_LMEMB 128 -#define TC_NMEMB 256 -#define TC_BNUM 32749 -#define TC_DBPATH "/tmp/" -#define TC_ZLIB 1 -#define TC_BZ2 2 - -/* B+ Tree - on-disk databases */ -#define DB_BROWSERS "db_browsers.tcb" -#define DB_COUNTRIES "db_countries.tcb" -#define DB_DATE_BW "db_date_bw.tcb" -#define DB_FILE_BW "db_file_bw.tcb" -#define DB_FILE_SERVE_USECS "db_file_serve_usecs.tcb" -#define DB_GENERAL_STATS "db_general_stats.tcb" -#define DB_HOST_AGENTS "db_host_agents.tcb" -#define DB_HOST_BW "db_host_bw.tcb" -#define DB_HOSTNAMES "db_hostnames.tcb" -#define DB_HOSTS "db_hosts.tcb" -#define DB_HOST_SERVE_USECS "db_host_serve_usecs.tcb" -#define DB_KEYPHRASES "db_keyphrases.tcb" -#define DB_NOT_FOUND_REQUESTS "db_not_found_requests.tcb" -#define DB_OS "db_os.tcb" -#define DB_REFERRERS "db_referrers.tcb" -#define DB_REFERRING_SITES "db_referring_sites.tcb" -#define DB_REQUEST_KEYS "db_request_keys.tcb" -#define DB_REQUEST_METHODS "db_request_methods.tcb" -#define DB_REQUEST_PROTOCOLS "db_request_protocols.tcb" -#define DB_REQUESTS "db_requests.tcb" -#define DB_REQUESTS_STATIC "db_requests_static.tcb" -#define DB_STATUS_CODE "db_status_code.tcb" -#define DB_UNIQUE_VIS "db_unique_vis.tcb" -#define DB_UNIQUE_VISITORS "db_unique_visitors.tcb" - -#ifdef TCB_BTREE - -extern TCBDB *ht_browsers; -extern TCBDB *ht_countries; -extern TCBDB *ht_date_bw; -extern TCBDB *ht_file_bw; -extern TCBDB *ht_file_serve_usecs; -extern TCBDB *ht_general_stats; -extern TCBDB *ht_host_bw; -extern TCBDB *ht_hostnames; -extern TCBDB *ht_hosts; -extern TCBDB *ht_hosts_agents; -extern TCBDB *ht_host_serve_usecs; -extern TCBDB *ht_keyphrases; -extern TCBDB *ht_not_found_requests; -extern TCBDB *ht_os; -extern TCBDB *ht_referrers; -extern TCBDB *ht_referring_sites; -extern TCBDB *ht_request_keys; -extern TCBDB *ht_request_methods; -extern TCBDB *ht_request_protocols; -extern TCBDB *ht_requests; -extern TCBDB *ht_requests_static; -extern TCBDB *ht_status_code; -extern TCBDB *ht_unique_vis; -extern TCBDB *ht_unique_visitors; - -#else - -extern TCMDB *ht_browsers; -extern TCMDB *ht_countries; -extern TCMDB *ht_date_bw; -extern TCMDB *ht_file_bw; -extern TCMDB *ht_file_serve_usecs; -extern TCMDB *ht_host_bw; -extern TCMDB *ht_hostnames; -extern TCMDB *ht_hosts; -extern TCMDB *ht_hosts_agents; -extern TCMDB *ht_host_serve_usecs; -extern TCMDB *ht_keyphrases; -extern TCMDB *ht_not_found_requests; -extern TCMDB *ht_os; -extern TCMDB *ht_referrers; -extern TCMDB *ht_referring_sites; -extern TCMDB *ht_request_keys; -extern TCMDB *ht_requests; -extern TCMDB *ht_request_methods; -extern TCMDB *ht_request_protocols; -extern TCMDB *ht_requests_static; -extern TCMDB *ht_status_code; -extern TCMDB *ht_unique_vis; -extern TCMDB *ht_unique_visitors; - -#endif - -#define INT_TO_POINTER(i) ((void *) (long) (i)) - -#ifdef TCB_BTREE -int tc_db_close (void *db, const char *dbname); -TCBDB *get_ht_by_module (GModule module); -void free_requests (BDBCUR * cur, char *key, GO_UNUSED int ksize, - GO_UNUSED void *user_data); -void tc_db_foreach (void *db, - void (*fp) (BDBCUR * cur, char *k, int s, void *u), - void *user_data); -#endif - -#ifdef TCB_MEMHASH -int tc_db_close (void *db, GO_UNUSED const char *dbname); -TCMDB *get_ht_by_module (GModule module); -void free_requests (TCMDB * mdb, char *key, GO_UNUSED int ksize, - GO_UNUSED void *user_data); -void tc_db_foreach (void *db, void (*fp) (TCMDB * m, char *k, int s, void *u), - void *user_data); -#endif - -char *get_request_meta (const char *k, GReqMeta meta); -GRawData *parse_raw_data (void *db, int ht_size, GModule module); -int process_browser (void *db, const char *k, const char *browser_type); -int process_generic_data (void *db, const char *k); -int process_geolocation (void *db, const char *ctry, const char *cont, - const char *city); -int process_host_agents (char *host, char *agent); -int process_opesys (void *db, const char *k, const char *os_type); -int process_request_meta (void *db, const char *k, uint64_t size); -int process_request (void *db, const char *k, const GLogItem * glog); -int tc_db_get_int (void *db, const char *k); -uint64_t get_bandwidth (char *k, GModule module); -uint64_t get_serve_time (const char *k, GModule module); -uint64_t tc_db_get_uint64 (void *db, const char *k); -unsigned int get_ht_size (void *db); -void free_key (BDBCUR * cur, char *key, GO_UNUSED int ksize, - GO_UNUSED void *user_data); -void init_storage (void); -void *tc_db_get_str (void *db, const char *k); -void tc_db_put_str (void *db, const char *k, const char *v); - -#endif diff --git a/ui.c b/ui.c deleted file mode 100644 index b3b4c8e2b5..0000000000 --- a/ui.c +++ /dev/null @@ -1,1345 +0,0 @@ -/** - * ui.c -- various curses interfaces - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -/* - * "_XOPEN_SOURCE" is required for the GNU libc to export "strptime(3)" - * correctly. - */ -#define _LARGEFILE_SOURCE -#define _LARGEFILE64_SOURCE -#define _FILE_OFFSET_BITS 64 - -#define _XOPEN_SOURCE 700 -#define STDIN_FILENO 0 -#define _BSD_SOURCE - -#if HAVE_CONFIG_H -#include -#endif - -#include -#include - -#include -#include -#include -#include -#include - -#include "ui.h" - -#ifdef HAVE_LIBTOKYOCABINET -#include "tcabinet.h" -#else -#include "glibht.h" -#endif - -#include "commons.h" -#include "error.h" -#include "gmenu.h" -#include "goaccess.h" -#include "parser.h" -#include "settings.h" -#include "util.h" -#include "xmalloc.h" - -static char *log_format = NULL; -static char *date_format = NULL; - -/* *INDENT-OFF* */ -static const char *sort_choices[][SORT_MAX_OPTS] = { - {"Hits", "Data", "Bandwidth", NULL}, - {"Hits", "Data", "Bandwidth", "Time Served", "Protocol", "Method", NULL}, - {"Hits", "Data", "Bandwidth", "Time Served", "Protocol", "Method", NULL}, - {"Hits", "Data", "Bandwidth", "Time Served", "Protocol", "Method", NULL}, - {"Hits", "Data", "Bandwidth", "Time Served", NULL}, - {"Hits", "Data", NULL}, - {"Hits", "Data", NULL}, - {"Hits", "Data", NULL}, - {"Hits", "Data", NULL}, - {"Hits", "Data", NULL}, -#ifdef HAVE_LIBGEOIP - {"Hits", "Data", NULL}, -#endif - {"Hits", "Data", NULL}, -}; -/* *INDENT-ON* */ - -/* creation - ncurses' window handling */ -WINDOW * -create_win (int h, int w, int y, int x) -{ - WINDOW *win = newwin (h, w, y, x); - if (win == NULL) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Unable to allocate memory for new WINDOW."); - return win; -} - -/* initialize curses colors */ -void -init_colors (void) -{ - /* use default foreground/background colors */ - use_default_colors (); - - init_pair (COL_BLUE, COLOR_BLUE, -1); - if (conf.color_scheme == STD_GREEN) - init_pair (COL_GREEN, COLOR_GREEN, -1); - else - init_pair (COL_GREEN, COLOR_WHITE, -1); - - init_pair (COL_RED, COLOR_RED, -1); - init_pair (COL_BLACK, COLOR_BLACK, -1); - init_pair (COL_CYAN, COLOR_CYAN, -1); - init_pair (COL_YELLOW, COLOR_YELLOW, -1); - - if (conf.color_scheme == STD_GREEN) - init_pair (BLUE_GREEN, COLOR_BLUE, COLOR_GREEN); - else - init_pair (BLUE_GREEN, COLOR_BLUE, COLOR_WHITE); - - init_pair (BLACK_GREEN, COLOR_BLACK, COLOR_GREEN); - init_pair (BLACK_CYAN, COLOR_BLACK, COLOR_CYAN); - init_pair (WHITE_RED, COLOR_WHITE, COLOR_RED); -} - -/* creation - ncurses' window handling */ -void -set_input_opts (void) -{ - initscr (); - clear (); - noecho (); - halfdelay (10); - nonl (); - intrflush (stdscr, FALSE); - keypad (stdscr, TRUE); - curs_set (0); - - if (conf.mouse_support) - mousemask (BUTTON1_CLICKED, NULL); -} - -/* delete ncurses window handling */ -void -close_win (WINDOW * w) -{ - if (w == NULL) - return; - wclear (w); - wrefresh (w); - delwin (w); -} - -void -generate_time (void) -{ - timestamp = time (NULL); - now_tm = localtime (×tamp); -} - -void -end_spinner (void) -{ - pthread_mutex_lock (&parsing_spinner->mutex); - parsing_spinner->state = SPN_END; - pthread_mutex_unlock (&parsing_spinner->mutex); -} - -void -init_windows (WINDOW ** header_win, WINDOW ** main_win) -{ - int row = 0, col = 0; - - /* init standard screen */ - attron (COLOR_PAIR (COL_WHITE)); - getmaxyx (stdscr, row, col); - if (row < MIN_HEIGHT || col < MIN_WIDTH) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Minimum screen size - 0 columns by 7 lines"); - - /* init header screen */ - *header_win = newwin (5, col, 0, 0); - keypad (*header_win, TRUE); - if (*header_win == NULL) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Unable to allocate memory for header_win."); - - /* init main screen */ - *main_win = newwin (row - 7, col, 6, 0); - keypad (*main_win, TRUE); - if (*main_win == NULL) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Unable to allocate memory for main_win."); -} - -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -/* draw a generic header */ -void -draw_header (WINDOW * win, const char *s, const char *fmt, int y, int x, - int w, int color) -{ - char *buf = xmalloc (snprintf (NULL, 0, fmt, s) + 1); - sprintf (buf, fmt, s); - - if (conf.color_scheme == STD_GREEN) { - init_pair (1, COLOR_BLACK, COLOR_GREEN); - init_pair (2, COLOR_BLACK, COLOR_CYAN); - wattron (win, COLOR_PAIR (color)); - } else if (conf.color_scheme == MONOCHROME) { - init_pair (1, COLOR_BLACK, COLOR_WHITE); - init_pair (2, COLOR_WHITE, -1); - wattron (win, COLOR_PAIR (color)); - } else { - if (color == 1) - wattron (win, A_REVERSE); - else if (color == 2) - wattron (win, A_NORMAL); - } - - mvwhline (win, y, x, ' ', w); - mvwaddnstr (win, y, x, buf, w); - - if (conf.color_scheme == STD_GREEN) - wattroff (win, COLOR_PAIR (color)); - else if (conf.color_scheme == MONOCHROME) - wattroff (win, COLOR_PAIR (color)); - else { - if (color == 1) - wattroff (win, A_REVERSE); - else if (color == 2) - wattroff (win, A_NORMAL); - } - free (buf); -} - -#pragma GCC diagnostic warning "-Wformat-nonliteral" - -/* determine the actual size of the main window */ -void -term_size (WINDOW * main_win) -{ - getmaxyx (stdscr, term_h, term_w); - - real_size_y = term_h - (MAX_HEIGHT_HEADER + MAX_HEIGHT_FOOTER); - wresize (main_win, real_size_y, term_w); - wmove (main_win, real_size_y, 0); -} - -static const char * -module_to_label (GModule module) -{ - static const char *modules[] = { - "Visitors", - "Requests", - "Static Requests", - "Not Found", - "Hosts", - "OS", - "Browsers", - "Referrers", - "Referring Sites", - "Keyphrases", -#ifdef HAVE_LIBGEOIP - "Geo Location", -#endif - "Status Codes" - }; - - return modules[module]; -} - -/* rerender header window to reflect active module */ -void -update_active_module (WINDOW * header_win, GModule current) -{ - const char *module = module_to_label (current); - int col = getmaxx (stdscr); - - char *lbl = xmalloc (snprintf (NULL, 0, "[Active Module: %s]", module) + 1); - sprintf (lbl, "[Active Module: %s]", module); - - if (conf.color_scheme == NO_COLOR) - wattron (header_win, A_REVERSE); - else - wattron (header_win, COLOR_PAIR (BLUE_GREEN)); - - wmove (header_win, 0, 30); - mvwprintw (header_win, 0, col - strlen (lbl) - 1, "%s", lbl); - - if (conf.color_scheme == NO_COLOR) - wattroff (header_win, A_REVERSE); - else - wattroff (header_win, COLOR_PAIR (BLUE_GREEN)); - wrefresh (header_win); - - free (lbl); -} - -/* render general statistics */ -void -display_general (WINDOW * win, char *ifile, int piping, int processed, - int invalid, unsigned long long bandwidth) -{ - char *bw, *size, *log_file; - char *failed, *not_found, *process, *ref, *req; - char *static_files, *now, *visitors; - - int x_field = 2, x_value = 0; - size_t n, i, j, max_field = 0, max_value = 0, mod_val, y; - - typedef struct Field_ - { - const char *field; - char *value; /* char due to log, bw, log_file */ - int color; - } Field; - - Field fields[] = { - {T_REQUESTS, NULL, COL_CYAN}, - {T_UNIQUE_VIS, NULL, COL_CYAN}, - {T_REFERRER, NULL, COL_CYAN}, - {T_LOG, NULL, COL_CYAN}, - {T_F_REQUESTS, NULL, COL_CYAN}, - {T_UNIQUE_FIL, NULL, COL_CYAN}, - {T_UNIQUE404, NULL, COL_CYAN}, - {T_BW, NULL, COL_CYAN}, - {T_GEN_TIME, NULL, COL_CYAN}, - {T_STATIC_FIL, NULL, COL_CYAN}, - {"", alloc_string (""), COL_CYAN}, - {T_LOG_PATH, NULL, COL_YELLOW} - }; - - werase (win); - draw_header (win, T_HEAD, " %s", 0, 0, getmaxx (stdscr), 1); - - if (!piping && ifile != NULL) { - size = filesize_str (file_size (ifile)); - log_file = alloc_string (ifile); - } else { - size = alloc_string ("N/A"); - log_file = alloc_string ("STDIN"); - } - bw = filesize_str ((float) bandwidth); - - /* *INDENT-OFF* */ - failed = int_to_str (invalid); - not_found = int_to_str (get_ht_size (ht_not_found_requests)); - process = int_to_str (processed); - ref = int_to_str (get_ht_size (ht_referrers)); - req = int_to_str (get_ht_size(ht_requests)); - static_files = int_to_str (get_ht_size(ht_requests_static)); - now = int_to_str (((long long) end_proc - start_proc)); - visitors = int_to_str (get_ht_size(ht_unique_visitors)); - - fields[0].value = process; - fields[1].value = visitors; - fields[2].value = ref; - fields[3].value = size; - fields[4].value = failed; - fields[5].value = req; - fields[6].value = not_found; - fields[7].value = bw; - fields[8].value = now; - fields[9].value = static_files; - fields[11].value = log_file; - - n = ARRAY_SIZE (fields); - - /* *INDENT-ON* */ - for (i = 0, y = 2; i < n; i++) { - mod_val = i % 4; - if (i > 0 && mod_val == 0) { - max_field = 0; - max_value = 0; - x_field = 2; - x_value = 2; - y++; - } - - x_field += max_field; - mvwprintw (win, y, x_field, "%s", fields[i].field); - - max_field = 0; - for (j = 0; j < n; j++) { - size_t len = strlen (fields[j].field); - if (j % 4 == mod_val && len > max_field) - max_field = len; - } - - max_value = 0; - for (j = 0; j < n; j++) { - size_t len = strlen (fields[j].value); - if (j % 4 == mod_val && len > max_value) - max_value = len; - } - x_value = max_field + x_field + 1; - max_field += max_value + 2; - - wattron (win, A_BOLD | COLOR_PAIR (fields[i].color)); - mvwprintw (win, y, x_value, "%s", fields[i].value); - wattroff (win, A_BOLD | COLOR_PAIR (fields[i].color)); - } - for (i = 0; i < n; i++) { - free (fields[i].value); - } -} - -/* implement basic frame work to build a field input */ -char * -input_string (WINDOW * win, int pos_y, int pos_x, size_t max_width, - const char *str, int enable_case, int *toggle_case) -{ - char *s = xmalloc (max_width + 1), *tmp; - size_t pos = 0, x = 0, quit = 1, c; - - /* window dimensions */ - size_t size_x = 0, size_y = 0, i; - getmaxyx (win, size_y, size_x); - size_x -= 4; - - /* are we setting a default string */ - if (str) { - size_t len = MIN (max_width, strlen (str)); - memcpy (s, str, len); - s[len] = '\0'; - - x = pos = 0; - /* is the default str length greater than input field? */ - if (strlen (s) > size_x) { - tmp = xstrdup (&s[0]); - tmp[size_x] = '\0'; - mvwprintw (win, pos_y, pos_x, "%s", tmp); - free (tmp); - } else - mvwprintw (win, pos_y, pos_x, "%s", s); - } else - s[0] = '\0'; - - if (enable_case) - draw_header (win, "[x] case sensitive", " %s", size_y - 2, 1, size_x - 2, - 2); - - wmove (win, pos_y, pos_x + x); - wrefresh (win); - - curs_set (1); - while (quit) { - c = wgetch (stdscr); - switch (c) { - case 1: /* ^a */ - case 262: /* HOME */ - pos = x = 0; - break; - case 5: - case 360: /* END of line */ - if (strlen (s) > size_x) { - x = size_x; - pos = strlen (s) - size_x; - } else { - pos = 0; - x = strlen (s); - } - break; - case 7: /* ^g */ - case 27: /* ESC */ - pos = x = 0; - if (str && *str == '\0') - s[0] = '\0'; - quit = 0; - break; - case 9: /* TAB */ - if (!enable_case) - break; - *toggle_case = *toggle_case == 0 ? 1 : 0; - if (*toggle_case) - draw_header (win, "[ ] case sensitive", " %s", size_y - 2, 1, - size_x - 2, 2); - else if (!*toggle_case) - draw_header (win, "[x] case sensitive", " %s", size_y - 2, 1, - size_x - 2, 2); - break; - case 21: /* ^u */ - s[0] = '\0'; - pos = x = 0; - break; - case 8: /* xterm-256color */ - case 127: - case KEY_BACKSPACE: - if (pos + x > 0) { - memmove (&s[(pos + x) - 1], &s[pos + x], (max_width - (pos + x)) + 1); - if (pos <= 0) - x--; - else - pos--; - } - break; - case KEY_LEFT: - if (x > 0) - x--; - else if (pos > 0) - pos--; - break; - case KEY_RIGHT: - if ((x + pos) < strlen (s)) { - if (x < size_x) - x++; - else - pos++; - } - break; - case 0x0a: - case 0x0d: - case KEY_ENTER: - quit = 0; - break; - default: - if (strlen (s) == max_width) - break; - if (!isprint (c)) - break; - - if (strlen (s) == pos) { - s[pos + x] = c; - s[pos + x + 1] = '\0'; - waddch (win, c); - } else { - memmove (&s[pos + x + 1], &s[pos + x], strlen (&s[pos + x]) + 1); - s[pos + x] = c; - } - if ((x + pos) < max_width) { - if (x < size_x) - x++; - else - pos++; - } - } - tmp = xstrdup (&s[pos > 0 ? pos : 0]); - tmp[MIN (strlen (tmp), size_x)] = '\0'; - for (i = strlen (tmp); i < size_x; i++) - mvwprintw (win, pos_y, pos_x + i, "%s", " "); - mvwprintw (win, pos_y, pos_x, "%s", tmp); - free (tmp); - - wmove (win, pos_y, pos_x + x); - wrefresh (win); - } - curs_set (0); - return s; -} - -/* allocate memory for a new instace of GAgents */ -static GAgents * -new_gagents (unsigned int n) -{ - GAgents *agents = xcalloc (n, sizeof (GAgents)); - return agents; -} - -/* split agent str if length > max or if '|' is found */ -int -split_agent_str (char *ptr_value, GAgents * agents, int max) -{ - char *holder; - char *p = ptr_value; - int i = 0, offset = 0; - - agents[i].agents = xmalloc (max + 1); - holder = agents[i].agents; - - while (*p != '\0') { - /* add char to holder */ - if (offset < max && *p != '|') { - *(holder++) = *(p++); - offset++; - continue; - } - /* split agent string since a delim was found */ - else if (*p == '|') - (void) *p++; - offset = 0; - *holder = '\0'; - agents[++i].agents = xmalloc (max + 1); - holder = agents[i].agents; - } - *holder = '\0'; - return i + 1; -} - -/* render a list of agents if available */ -void -load_agent_list (WINDOW * main_win, char *addr) -{ - char buf[256]; - char *ptr_value; - GAgents *agents = NULL; - GMenu *menu; - int c, quit = 1, delims = 0; - int i, n = 0, alloc = 0; - int y, x, list_h, list_w, menu_w, menu_h; - void *value_ptr = NULL; - WINDOW *win; - - if (!conf.list_agents) - return; - - getmaxyx (stdscr, y, x); - list_h = y / 2; /* list window - height */ - list_w = x - 4; /* list window - width */ - menu_h = list_h - AGENTS_MENU_Y - 1; /* menu window - height */ - menu_w = list_w - AGENTS_MENU_X - AGENTS_MENU_X; /* menu window - width */ - -#ifdef HAVE_LIBTOKYOCABINET - value_ptr = tc_db_get_str (ht_hosts_agents, addr); -#else - value_ptr = g_hash_table_lookup (ht_hosts_agents, addr); -#endif - - if (value_ptr != NULL) { - ptr_value = (char *) value_ptr; - delims = count_occurrences (ptr_value, '|'); - - n = ((strlen (ptr_value) + menu_w - 1) / menu_w) + delims + 1; - agents = new_gagents (n); - alloc = split_agent_str (ptr_value, agents, menu_w); -#ifdef HAVE_LIBTOKYOCABINET - free (value_ptr); -#endif - } - - win = newwin (list_h, list_w, (y - list_h) / 2, (x - list_w) / 2); - keypad (win, TRUE); - wborder (win, '|', '|', '-', '-', '+', '+', '+', '+'); - - /* create a new instance of GMenu and make it selectable */ - menu = new_gmenu (win, menu_h, menu_w, AGENTS_MENU_Y, AGENTS_MENU_X); - - /* add items to GMenu */ - menu->items = (GItem *) xcalloc (alloc, sizeof (GItem)); - for (i = 0; i < alloc; ++i) { - menu->items[i].name = alloc_string (agents[i].agents); - menu->items[i].checked = 0; - menu->size++; - } - post_gmenu (menu); - - snprintf (buf, sizeof buf, "User Agents for %s", addr); - draw_header (win, buf, " %s", 1, 1, list_w - 2, 1); - mvwprintw (win, 2, 2, "[UP/DOWN] to scroll - [q] to close window"); - - wrefresh (win); - while (quit) { - c = wgetch (stdscr); - switch (c) { - case KEY_DOWN: - gmenu_driver (menu, REQ_DOWN); - draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0); - break; - case KEY_UP: - gmenu_driver (menu, REQ_UP); - draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0); - break; - case KEY_RESIZE: - case 'q': - quit = 0; - break; - } - wrefresh (win); - } - /* clean stuff up */ - for (i = 0; i < alloc; ++i) - free (menu->items[i].name); - free (menu->items); - free (menu); - - for (i = 0; i < alloc; ++i) - free (agents[i].agents); - if (agents) - free (agents); - - touchwin (main_win); - close_win (win); - wrefresh (main_win); -} - -/* render processing spinner */ -static void -ui_spinner (void *ptr_data) -{ - GSpinner *sp = (GSpinner *) ptr_data; - - static char const spin_chars[] = "/-\\|"; - char buf[SPIN_LBL]; - long long tdiff = 0, psec = 0; - int i = 0; - time_t begin; - - time (&begin); - while (1) { - pthread_mutex_lock (&sp->mutex); - if (sp->state == SPN_END) - break; - - if (conf.no_progress) { - snprintf (buf, sizeof buf, SPIN_FMT, sp->label); - } else { - tdiff = (long long) (time (NULL) - begin); - psec = tdiff >= 1 ? *(sp->process) / tdiff : 0; - snprintf (buf, sizeof buf, SPIN_FMTM, sp->label, *(sp->process), psec); - } - - /* CURSES */ - if (sp->curses) { - /* label + metrics */ - draw_header (sp->win, buf, " %s", sp->y, sp->x, sp->w, sp->color); - - /* caret */ - wattron (sp->win, COLOR_PAIR (sp->color)); - mvwaddch (sp->win, sp->y, sp->spin_x, spin_chars[i++ & 3]); - wattroff (sp->win, COLOR_PAIR (sp->color)); - wrefresh (sp->win); - } - /* STDOUT */ - else if (!conf.no_progress) { - fprintf (stderr, "%s\r", buf); - } - - pthread_mutex_unlock (&sp->mutex); - usleep (100000); - } - sp = NULL; - free (sp); -} - -/* create spinner's thread */ -void -ui_spinner_create (GSpinner * spinner) -{ - pthread_create (&(spinner->thread), NULL, (void *) &ui_spinner, spinner); - pthread_detach (spinner->thread); -} - -/* allocate memory and initialize data */ -void -set_curses_spinner (GSpinner * spinner) -{ - int y, x; - if (spinner == NULL) - return; - - getmaxyx (stdscr, y, x); - - spinner->color = HIGHLIGHT; - spinner->curses = 1; - spinner->win = stdscr; - spinner->x = 0; - spinner->w = x; - spinner->spin_x = x - 2; - spinner->y = y - 1; -} - -/* allocate memory and initialize data */ -GSpinner * -new_gspinner (void) -{ - GSpinner *spinner; - - spinner = xcalloc (1, sizeof (GSpinner)); - spinner->label = "Parsing..."; - spinner->state = SPN_RUN; - spinner->curses = 0; - if (conf.load_from_disk) - conf.no_progress = 1; - - if (pthread_mutex_init (&(spinner->mutex), NULL)) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Failed thread mutex"); - - return spinner; -} - -/* render config log date/format dialog */ -int -verify_format (GLog * logger, GSpinner * spinner) -{ - GMenu *menu; - WINDOW *win; - - char *cstm_log, *cstm_date; - int c, quit = 1; - int invalid = 1; - int y, x, h = CONF_WIN_H, w = CONF_WIN_W; - int w2 = w - 2; - size_t i, n, sel; - - /* conf dialog menu options */ - const char *choices[] = { - "Common Log Format (CLF)", - "Common Log Format (CLF) with Virtual Host", - "NCSA Combined Log Format", - "NCSA Combined Log Format with Virtual Host", - "W3C", - "CloudFront (Download Distribution)" - }; - n = ARRAY_SIZE (choices); - getmaxyx (stdscr, y, x); - - win = newwin (h, w, (y - h) / 2, (x - w) / 2); - keypad (win, TRUE); - wborder (win, '|', '|', '-', '-', '+', '+', '+', '+'); - - /* create a new instance of GMenu and make it selectable */ - menu = new_gmenu (win, CONF_MENU_H, CONF_MENU_W, CONF_MENU_Y, CONF_MENU_X); - menu->size = n; - menu->selectable = 1; - - /* add items to GMenu */ - menu->items = (GItem *) xcalloc (n, sizeof (GItem)); - for (i = 0; i < n; ++i) { - menu->items[i].name = alloc_string (choices[i]); - sel = get_selected_format_idx (); - menu->items[i].checked = sel == i ? 1 : 0; - } - post_gmenu (menu); - - draw_header (win, "Log Format Configuration", " %s", 1, 1, w2, 1); - mvwprintw (win, 2, 2, "[SPACE] to toggle - [ENTER] to proceed"); - - /* set log format from goaccessrc if available */ - draw_header (win, "Log Format - [c] to add/edit format", " %s", 11, 1, w2, 1); - if (conf.log_format) { - log_format = escape_str (conf.log_format); - mvwprintw (win, 12, 2, "%.*s", CONF_MENU_W, log_format); - if (conf.log_format) - free (conf.log_format); - } - - /* set date format from goaccessrc if available */ - draw_header (win, "Date Format - [d] to add/edit format", " %s", 14, 1, w2, - 1); - if (conf.date_format) { - date_format = escape_str (conf.date_format); - mvwprintw (win, 15, 2, "%.*s", CONF_MENU_W, date_format); - if (conf.date_format) - free (conf.date_format); - } - - wrefresh (win); - while (quit) { - c = wgetch (stdscr); - switch (c) { - case KEY_DOWN: - gmenu_driver (menu, REQ_DOWN); - draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0); - break; - case KEY_UP: - gmenu_driver (menu, REQ_UP); - draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0); - break; - case 32: /* space */ - gmenu_driver (menu, REQ_SEL); - - if (date_format) - free (date_format); - if (log_format) - free (log_format); - - for (i = 0; i < n; ++i) { - if (menu->items[i].checked != 1) - continue; - - date_format = get_selected_date_str (i); - log_format = get_selected_format_str (i); - draw_header (win, date_format, " %s", 15, 1, CONF_MENU_W, 0); - draw_header (win, log_format, " %s", 12, 1, CONF_MENU_W, 0); - break; - } - break; - case 99: /* c */ - /* clear top status bar */ - draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0); - wmove (win, 12, 2); - - /* get input string */ - cstm_log = input_string (win, 12, 2, 70, log_format, 0, 0); - if (cstm_log != NULL && *cstm_log != '\0') { - if (log_format) - free (log_format); - - log_format = alloc_string (cstm_log); - free (cstm_log); - } - /* did not set an input string */ - else { - if (cstm_log) - free (cstm_log); - if (log_format) { - free (log_format); - log_format = NULL; - } - } - break; - case 100: /* d */ - /* clear top status bar */ - draw_header (win, "", "%s", 3, 2, CONF_MENU_W, 0); - wmove (win, 15, 0); - - /* get input string */ - cstm_date = input_string (win, 15, 2, 14, date_format, 0, 0); - if (cstm_date != NULL && *cstm_date != '\0') { - if (date_format) - free (date_format); - - date_format = alloc_string (cstm_date); - free (cstm_date); - } - /* did not set an input string */ - else { - if (cstm_date) - free (cstm_date); - if (date_format) { - free (date_format); - date_format = NULL; - } - } - break; - case 274: /* F10 */ - case 0x0a: - case 0x0d: - case KEY_ENTER: - /* display status bar error messages */ - if (date_format == NULL) - draw_header (win, "Select a date format.", "%s", 3, 2, CONF_MENU_W, - WHITE_RED); - if (log_format == NULL) - draw_header (win, "Select a log format.", "%s", 3, 2, CONF_MENU_W, - WHITE_RED); - - if (date_format && log_format) { - conf.date_format = unescape_str (date_format); - conf.log_format = unescape_str (log_format); - - /* test log against selected settings */ - if (test_format (logger)) { - invalid = 1; - draw_header (win, "No valid hits.", "%s", 3, 2, CONF_MENU_W, - WHITE_RED); - - free (conf.log_format); - free (conf.date_format); - } - /* valid data, reset logger & start parsing */ - else { - reset_struct (logger); - /* start spinner thread */ - spinner->win = win; - spinner->y = 3; - spinner->x = 2; - spinner->spin_x = CONF_MENU_W; - spinner->w = CONF_MENU_W; - spinner->color = BLACK_CYAN; - ui_spinner_create (spinner); - - invalid = 0; - quit = 0; - } - } - break; - case KEY_RESIZE: - case 'q': - quit = 0; - break; - } - pthread_mutex_lock (&spinner->mutex); - wrefresh (win); - pthread_mutex_unlock (&spinner->mutex); - } - /* clean stuff up */ - for (i = 0; i < n; ++i) - free (menu->items[i].name); - free (menu->items); - free (menu); - - return invalid ? 1 : 0; -} - -/* get selected scheme */ -static void -scheme_chosen (const char *name) -{ - if (strcmp ("Green/Original", name) == 0) - conf.color_scheme = STD_GREEN; - else if (strcmp ("Monochrome/Default", name) == 0) - conf.color_scheme = MONOCHROME; - init_colors (); -} - -/* render schemes dialog */ -void -load_schemes_win (WINDOW * main_win) -{ - GMenu *menu; - WINDOW *win; - int c, quit = 1; - size_t i, n; - int y, x, h = SCHEME_WIN_H, w = SCHEME_WIN_W; - int w2 = w - 2; - - const char *choices[] = { - "Monochrome/Default", - "Green/Original" - }; - - n = ARRAY_SIZE (choices); - getmaxyx (stdscr, y, x); - - win = newwin (h, w, (y - h) / 2, (x - w) / 2); - keypad (win, TRUE); - wborder (win, '|', '|', '-', '-', '+', '+', '+', '+'); - - /* create a new instance of GMenu and make it selectable */ - menu = - new_gmenu (win, SCHEME_MENU_H, SCHEME_MENU_W, SCHEME_MENU_Y, SCHEME_MENU_X); - menu->size = n; - - /* add items to GMenu */ - menu->items = (GItem *) xcalloc (n, sizeof (GItem)); - for (i = 0; i < n; ++i) { - menu->items[i].name = alloc_string (choices[i]); - menu->items[i].checked = 0; - } - post_gmenu (menu); - - draw_header (win, "Scheme Configuration", " %s", 1, 1, w2, 1); - mvwprintw (win, 2, 2, "[ENTER] to switch scheme"); - - wrefresh (win); - while (quit) { - c = wgetch (stdscr); - switch (c) { - case KEY_DOWN: - gmenu_driver (menu, REQ_DOWN); - draw_header (win, "", "%s", 3, 2, SCHEME_MENU_W, 0); - break; - case KEY_UP: - gmenu_driver (menu, REQ_UP); - draw_header (win, "", "%s", 3, 2, SCHEME_MENU_W, 0); - break; - case 32: - case 0x0a: - case 0x0d: - case KEY_ENTER: - gmenu_driver (menu, REQ_SEL); - for (i = 0; i < n; ++i) { - if (menu->items[i].checked != 1) - continue; - scheme_chosen (choices[i]); - break; - } - quit = 0; - break; - case KEY_RESIZE: - case 'q': - quit = 0; - break; - } - wrefresh (win); - } - /* clean stuff up */ - for (i = 0; i < n; ++i) - free (menu->items[i].name); - free (menu->items); - free (menu); - - touchwin (main_win); - close_win (win); - wrefresh (main_win); -} - -/* render sort dialog */ -void -load_sort_win (WINDOW * main_win, GModule module, GSort * sort) -{ - GMenu *menu; - int c, quit = 1; - int i = 0, k, n = 0; - int opts[SORT_MAX_OPTS]; - int y, x, h = SORT_WIN_H, w = SORT_WIN_W; - int w2 = w - 2; - WINDOW *win; - - getmaxyx (stdscr, y, x); - - /* determine amount of sort choices */ - for (i = 0, k = 0; NULL != sort_choices[module][i]; i++) { - const char *name = sort_choices[module][i]; - if (strcmp ("Time Served", name) == 0 && !conf.serve_usecs) - continue; - else if (strcmp ("Bandwidth", name) == 0 && !conf.bandwidth) - continue; - else if (strcmp ("Protocol", name) == 0 && !conf.append_protocol) - continue; - else if (strcmp ("Method", name) == 0 && !conf.append_method) - continue; - opts[k++] = i; - n++; - } - - win = newwin (h, w, (y - h) / 2, (x - w) / 2); - keypad (win, TRUE); - wborder (win, '|', '|', '-', '-', '+', '+', '+', '+'); - - /* create a new instance of GMenu and make it selectable */ - menu = new_gmenu (win, SORT_MENU_H, SORT_MENU_W, SORT_MENU_Y, SORT_MENU_X); - menu->size = n; - menu->selectable = 1; - - /* add items to GMenu */ - menu->items = (GItem *) xcalloc (n, sizeof (GItem)); - - /* set checked option and set index */ - for (i = 0; i < n; ++i) { - menu->items[i].name = alloc_string (sort_choices[module][opts[i]]); - if (sort->field == SORT_BY_HITS && - strcmp ("Hits", menu->items[i].name) == 0) { - menu->items[i].checked = 1; - menu->idx = i; - } else if (sort->field == SORT_BY_DATA && - strcmp ("Data", menu->items[i].name) == 0) { - menu->items[i].checked = 1; - menu->idx = i; - } else if (sort->field == SORT_BY_BW && - strcmp ("Bandwidth", menu->items[i].name) == 0) { - menu->items[i].checked = 1; - menu->idx = i; - } else if (sort->field == SORT_BY_USEC && - strcmp ("Time Served", menu->items[i].name) == 0) { - menu->items[i].checked = 1; - menu->idx = i; - } else if (sort->field == SORT_BY_PROT && - strcmp ("Protocol", menu->items[i].name) == 0) { - menu->items[i].checked = 1; - menu->idx = i; - } else if (sort->field == SORT_BY_MTHD && - strcmp ("Method", menu->items[i].name) == 0) { - menu->items[i].checked = 1; - menu->idx = i; - } - } - post_gmenu (menu); - - draw_header (win, "Sort active module by", " %s", 1, 1, w2, 1); - mvwprintw (win, 2, 2, "[ENTER] to select field - [TAB] sort"); - if (sort->sort == SORT_ASC) - draw_header (win, "[x] ASC [ ] DESC", " %s", SORT_WIN_H - 2, 1, - SORT_WIN_W - 2, 2); - else - draw_header (win, "[ ] ASC [x] DESC", " %s", SORT_WIN_H - 2, 1, - SORT_WIN_W - 2, 2); - - wrefresh (win); - while (quit) { - c = wgetch (stdscr); - switch (c) { - case KEY_DOWN: - gmenu_driver (menu, REQ_DOWN); - draw_header (win, "", "%s", 3, 2, SORT_MENU_W, 0); - break; - case KEY_UP: - gmenu_driver (menu, REQ_UP); - draw_header (win, "", "%s", 3, 2, SORT_MENU_W, 0); - break; - case 9: /* TAB */ - /* ascending */ - if (sort->sort == SORT_ASC) { - sort->sort = SORT_DESC; - draw_header (win, "[ ] ASC [x] DESC", " %s", SORT_WIN_H - 2, 1, - SORT_WIN_W - 2, 2); - } - /* descending */ - else { - sort->sort = SORT_ASC; - draw_header (win, "[x] ASC [ ] DESC", " %s", SORT_WIN_H - 2, 1, - SORT_WIN_W - 2, 2); - } - break; - case 32: - case 0x0a: - case 0x0d: - case KEY_ENTER: - gmenu_driver (menu, REQ_SEL); - for (i = 0; i < n; ++i) { - if (menu->items[i].checked != 1) - continue; - if (strcmp ("Hits", menu->items[i].name) == 0) - sort->field = SORT_BY_HITS; - else if (strcmp ("Data", menu->items[i].name) == 0) - sort->field = SORT_BY_DATA; - else if (strcmp ("Bandwidth", menu->items[i].name) == 0) - sort->field = SORT_BY_BW; - else if (strcmp ("Time Served", menu->items[i].name) == 0) - sort->field = SORT_BY_USEC; - else if (strcmp ("Protocol", menu->items[i].name) == 0) - sort->field = SORT_BY_PROT; - else if (strcmp ("Method", menu->items[i].name) == 0) - sort->field = SORT_BY_MTHD; - quit = 0; - break; - } - break; - case KEY_RESIZE: - case 'q': - quit = 0; - break; - } - wrefresh (win); - } - - /* clean stuff up */ - for (i = 0; i < n; ++i) - free (menu->items[i].name); - free (menu->items); - free (menu); - - touchwin (main_win); - close_win (win); - wrefresh (main_win); -} - -static const char *help_main[] = { - "Copyright (C) 2009-2014", - "by Gerardo Orellana ", - "http://goaccess.prosoftcorp.com", - "Released under the GNU GPL. See `man` page for more details", - "", - "GoAccess is an open source real-time web log analyzer and", - "interactive viewer that runs in a terminal in *nix systems.", - "It provides fast and valuable HTTP statistics for system", - "administrators that require a visual server report on the", - "fly.", - "", - "The data collected based on the parsing of the log is", - "divided into different modules. Modules are automatically", - "generated and presented to the user.", - "", - "The main dashboard displays general statistics, top", - "visitors, requests, browsers, operating systems,", - "hosts, etc.", - "", - "The user can make use of the following keys:", - " ^F1^ or ^h^ Main help", - " ^F5^ Redraw [main window]", - " ^q^ Quit the program, current window or module", - " ^o^ or ^ENTER^ Expand selected module", - " ^[Shift]0-9^ Set selected module to active", - " ^j^ Scroll down within expanded module", - " ^k^ Scroll up within expanded module", - " ^c^ Set or change scheme color", - " ^CTRL^ + ^f^ Scroll forward one screen within", - " active module", - " ^CTRL^ + ^b^ Scroll backward one screen within", - " active module", - " ^TAB^ Iterate modules (forward)", - " ^SHIFT^ + ^TAB^ Iterate modules (backward)", - " ^s^ Sort options for current module", - " ^/^ Search across all modules", - " ^n^ Find position of the next occurrence", - " ^g^ Move to the first item or top of screen", - " ^G^ Move to the last item or bottom of screen", - "", - "Examples can be found by running `man goaccess`.", - "", - "If you believe you have found a bug, please drop me", - "an email with details.", - "", - "If you have a medium or high traffic website, it", - "would be interesting to hear your experience with", - "GoAccess, such as generating time, visitors or hits.", - "", - "Feedback? Just shoot me an email to:", - "goaccess@prosoftcorp.com", -}; - -/* render help dialog */ -void -load_help_popup (WINDOW * main_win) -{ - int c, quit = 1; - size_t i, n; - int y, x, h = HELP_WIN_HEIGHT, w = HELP_WIN_WIDTH; - int w2 = w - 2; - WINDOW *win; - GMenu *menu; - - n = ARRAY_SIZE (help_main); - getmaxyx (stdscr, y, x); - - win = newwin (h, w, (y - h) / 2, (x - w) / 2); - keypad (win, TRUE); - wborder (win, '|', '|', '-', '-', '+', '+', '+', '+'); - - /* create a new instance of GMenu and make it selectable */ - menu = - new_gmenu (win, HELP_MENU_HEIGHT, HELP_MENU_WIDTH, HELP_MENU_Y, - HELP_MENU_X); - menu->size = n; - - /* add items to GMenu */ - menu->items = (GItem *) xcalloc (n, sizeof (GItem)); - for (i = 0; i < n; ++i) { - menu->items[i].name = alloc_string (help_main[i]); - menu->items[i].checked = 0; - } - post_gmenu (menu); - - draw_header (win, "GoAccess Quick Help", " %s", 1, 1, w2, 1); - mvwprintw (win, 2, 2, "[UP/DOWN] to scroll - [q] to quit"); - - wrefresh (win); - while (quit) { - c = wgetch (stdscr); - switch (c) { - case KEY_DOWN: - gmenu_driver (menu, REQ_DOWN); - draw_header (win, "", "%s", 3, 2, HELP_MENU_WIDTH, 0); - break; - case KEY_UP: - gmenu_driver (menu, REQ_UP); - draw_header (win, "", "%s", 3, 2, HELP_MENU_WIDTH, 0); - break; - case KEY_RESIZE: - case 'q': - quit = 0; - break; - } - wrefresh (win); - } - /* clean stuff up */ - for (i = 0; i < n; ++i) - free (menu->items[i].name); - free (menu->items); - free (menu); - - touchwin (main_win); - close_win (win); - wrefresh (main_win); -} diff --git a/ui.h b/ui.h deleted file mode 100644 index 872a94ddd3..0000000000 --- a/ui.h +++ /dev/null @@ -1,265 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#ifndef UI_H_INCLUDED -#define UI_H_INCLUDED - -#ifdef HAVE_NCURSESW_NCURSES_H -#include -#elif HAVE_NCURSES_NCURSES_H -#include -#elif HAVE_NCURSES_H -#include -#elif HAVE_CURSES_H -#include -#endif - -#ifdef HAVE_LIBPTHREAD -#include -#endif - -/* overall stats */ -#define T_BW "Bandwidth" -#define T_F_REQUESTS "Failed Requests" -#define T_GEN_TIME "Generation Time" -#define T_HEAD "General Dashboard - Overall Analyzed Requests" -#define T_LOG "Log Size" -#define T_REFERRER "Referrers" -#define T_REQUESTS "Total Requests" -#define T_STATIC_FIL "Static Files" -#define T_UNIQUE404 "Unique 404" -#define T_UNIQUE_FIL "Unique Files" -#define T_LOG_PATH "Log File" -#define T_UNIQUE_VIS "Unique Visitors" - -/* spinner label format */ -#define SPIN_FMT "%s" -#define SPIN_FMTM "%s [%'d] [%'lld/s]" -#define SPIN_LBL 50 - -/* modules */ -#define VISIT_HEAD "Unique visitors per day - Including spiders" -#define VISIT_DESC "Hits having the same IP, date and agent are a unique visit." -#define VISIT_ID "visitors" -#define REQUE_HEAD "Requested files (Pages-URL)" -#define REQUE_DESC "Top Requested Files sorted by hits - [time served] [protocol] [method]" -#define REQUE_ID "requests" -#define STATI_HEAD "Requested static files (e.g., png, js, css, etc.)" -#define STATI_DESC "Top Static Files sorted by hits - [time served] [protocol] [method]" -#define STATI_ID "static_requests" -#define FOUND_HEAD "HTTP 404 Not Found URLs" -#define FOUND_DESC "Top 404 Not Found URLs sorted by hits - [time served] [protocol] [method]" -#define FOUND_ID "not_found" -#define HOSTS_HEAD "Hosts" -#define HOSTS_DESC "Top Hosts sorted by hits - [bandwidth] [time served]" -#define HOSTS_ID "hosts" -#define OPERA_HEAD "Operating Systems" -#define OPERA_DESC "Top Operating Systems sorted by unique visitors" -#define OPERA_ID "os" -#define BROWS_HEAD "Browsers" -#define BROWS_DESC "Top Browsers sorted by unique visitors" -#define BROWS_ID "browsers" -#define REFER_HEAD "Referrers URLs" -#define REFER_DESC "Top Requested Referrers sorted by hits" -#define REFER_ID "referrers" -#define SITES_HEAD "Referring Sites" -#define SITES_DESC "Top Referring Sites sorted by hits" -#define SITES_ID "referring_sites" -#define KEYPH_HEAD "Keyphrases from Google's search engine" -#define KEYPH_DESC "Top Keyphrases sorted by hits" -#define KEYPH_ID "keyphrases" -#define GEOLO_HEAD "Geo Location" -#define GEOLO_DESC "Continent > Country sorted by unique visitors" -#define GEOLO_ID "geolocation" -#define CODES_HEAD "HTTP Status Codes" -#define CODES_DESC "Top HTTP Status Codes sorted by hits" -#define CODES_ID "status_codes" -#define GENER_ID "general" - -/* dialogs */ -#define FIND_HEAD "Find pattern in all modules" -#define FIND_DESC "Regex allowed - ^g to cancel - TAB switch case" - -#define MAX_CHOICES 300 -#define MIN_HEIGHT 7 -#define MIN_WIDTH 0 -#define MAX_HEIGHT_FOOTER 1 -#define MAX_HEIGHT_HEADER 6 - -#define CONF_MENU_H 6 -#define CONF_MENU_W 48 -#define CONF_MENU_X 2 -#define CONF_MENU_Y 4 -#define CONF_WIN_H 17 -#define CONF_WIN_W 52 - -#define FIND_DLG_HEIGHT 8 -#define FIND_DLG_WIDTH 50 -#define FIND_MAX_MATCHES 1 - -#define SCHEME_MENU_H 2 -#define SCHEME_MENU_W 38 -#define SCHEME_MENU_X 2 -#define SCHEME_MENU_Y 4 -#define SCHEME_WIN_H 8 -#define SCHEME_WIN_W 42 - -#define SORT_MAX_OPTS 7 -#define SORT_MENU_H 6 -#define SORT_MENU_W 38 -#define SORT_MENU_X 2 -#define SORT_MENU_Y 4 -#define SORT_WIN_H 13 -#define SORT_WIN_W 42 - -#define AGENTS_MENU_X 2 -#define AGENTS_MENU_Y 4 - -#define HELP_MENU_HEIGHT 12 -#define HELP_MENU_WIDTH 60 -#define HELP_MENU_X 2 -#define HELP_MENU_Y 4 -#define HELP_WIN_HEIGHT 17 -#define HELP_WIN_WIDTH 64 - -#define BLACK_CYAN 9 -#define BLACK_GREEN 8 -#define BLUE_GREEN 7 -#define COL_BLACK 4 -#define COL_BLUE 1 -#define COL_CYAN 5 -#define COL_GREEN 11 -#define COL_RED 3 -#define COL_WHITE 0 -#define COL_YELLOW 6 -#define WHITE_RED 10 - -#define HIGHLIGHT 1 - -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) - -#include "commons.h" -#include "parser.h" - -typedef enum SCHEMES -{ - NO_COLOR, - MONOCHROME, - STD_GREEN -} GShemes; - -typedef struct GFind_ -{ - GModule module; - char *pattern; - int next_idx; - int next_parent_idx; - int next_sub_idx; - int look_in_sub; - int done; - int icase; -} GFind; - -typedef struct GSort_ -{ - GModule module; - enum - { - SORT_BY_HITS, - SORT_BY_DATA, - SORT_BY_BW, - SORT_BY_USEC, - SORT_BY_PROT, - SORT_BY_MTHD, - } field; - enum - { - SORT_ASC, - SORT_DESC - } sort; -} GSort; - -typedef struct GScrollModule_ -{ - int scroll; - int offset; -} GScrollModule; - -typedef struct GScrolling_ -{ - GScrollModule module[TOTAL_MODULES]; - GModule current; - int dash; - int expanded; -} GScrolling; - -typedef struct GAgents_ -{ - char *agents; - int size; -} GAgents; - -typedef struct GSpinner_ -{ - const char *label; - int color; - int curses; - int spin_x; - int w; - int x; - int y; - pthread_mutex_t mutex; - pthread_t thread; - unsigned int *process; - WINDOW *win; - enum - { - SPN_RUN, - SPN_END - } state; -} GSpinner; - -/* *INDENT-OFF* */ -char *get_browser_type (char *line); -char *input_string (WINDOW * win, int pos_y, int pos_x, size_t max_width, const char *str, int enable_case, int *toggle_case); -GSpinner *new_gspinner (void); -int split_agent_str (char *ptr_value, GAgents * agents, int max); -int verify_format (GLog * logger, GSpinner * spinner); -void close_win (WINDOW * w); -void display_general (WINDOW * header_win, char *ifile, int piping, int process, int invalid, unsigned long long bandwidth); -void draw_header (WINDOW * win, const char *s, const char *fmt, int y, int x, int w, int color); -void end_spinner (void); -void generate_time (void); -void init_colors (void); -void init_windows (WINDOW ** header_win, WINDOW ** main_win); -void load_agent_list (WINDOW * main_win, char *addr); -void load_help_popup (WINDOW * main_win); -void load_schemes_win (WINDOW * main_win); -void load_sort_win (WINDOW * main_win, GModule module, GSort * sort); -void set_curses_spinner (GSpinner *spinner); -void set_input_opts (void); -void term_size (WINDOW * main_win); -void ui_spinner_create (GSpinner * spinner); -void update_active_module (WINDOW * header_win, GModule current); -void update_header (WINDOW * header_win, int current); -WINDOW *create_win (int h, int w, int y, int x); -/* *INDENT-ON* */ - -#endif diff --git a/util.c b/util.c deleted file mode 100644 index 7c57130a24..0000000000 --- a/util.c +++ /dev/null @@ -1,545 +0,0 @@ -/** - * util.c -- a set of handy functions to help parsing - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#define _LARGEFILE_SOURCE -#define _LARGEFILE64_SOURCE -#define _FILE_OFFSET_BITS 64 - -#define _XOPEN_SOURCE 700 - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "util.h" - -#include "error.h" -#include "parser.h" -#include "settings.h" -#include "xmalloc.h" - -static const char *code_type[][2] = { - {"1", "1xx Informational"}, - {"2", "2xx Success"}, - {"3", "3xx Redirection"}, - {"4", "4xx Client Error"}, - {"5", "5xx Server Error"}, -}; - -static const char *codes[][2] = { - {"100", "100 - Continue: Server has received the request headers"}, - {"101", "101 - Switching Protocols: Client asked to switch protocols"}, - {"200", "200 - OK: The request sent by the client was successful"}, - {"201", "201 - Created: The request has been fulfilled and created"}, - {"202", "202 - Accepted: The request has been accepted for processing"}, - {"203", "203 - Non-Authoritative Information"}, - {"204", "204 - No Content: Request is not returning any content"}, - {"205", "205 - Reset Content: User-Agent should reset the document"}, - {"206", "206 - Partial Content: The partial GET has been successful"}, - {"300", "300 - Multiple Choices: Multiple options for the resource"}, - {"301", "301 - Moved Permanently: Resource has permanently moved"}, - {"302", "302 - Moved Temporarily (redirect)"}, - {"303", "303 - See Other Document: The response is at a different URI"}, - {"304", "304 - Not Modified: Resource has not been modified"}, - {"305", "305 - Use Proxy: Can only be accessed through the proxy"}, - {"307", "307 - Temporary Redirect: Resource temporarily moved"}, - {"400", "400 - Bad Request: The syntax of the request is invalid"}, - {"401", "401 - Unauthorized: Request needs user authentication"}, - {"402", "402 - Payment Required"}, - {"403", "403 - Forbidden: Server is refusing to respond to it"}, - {"404", "404 - Document Not Found: Requested resource could not be found"}, - {"405", "405 - Method Not Allowed: Request method not supported"}, - {"406", "406 - Not Acceptable"}, - {"407", "407 - Proxy Authentication Required"}, - {"408", - "408 - Request Timeout: The server timed out waiting for the request"}, - {"409", "409 - Conflict: Conflict in the request"}, - {"410", "410 - Gone: Resource requested is no longer available"}, - {"411", "411 - Length Required: Invalid Content-Length"}, - {"412", "412 - Precondition Failed: Server does not meet preconditions"}, - {"413", "413 - Requested Entity Too Long"}, - {"414", "414 - Requested Filename Too Long"}, - {"415", "415 - Unsupported Media Type: Media type is not supported"}, - {"416", - "416 - Requested Range Not Satisfiable: Cannot supply that portion"}, - {"417", "417 - Expectation Failed"}, - {"500", "500 - Internal Server Error"}, - {"501", "501 - Not Implemented"}, - {"502", - "502 - Bad Gateway: Received an invalid response from the upstream"}, - {"503", "503 - Service Unavailable: The server is currently unavailable"}, - {"504", - "504 - Gateway Timeout: The upstream server failed to send request"}, - {"505", "505 - HTTP Version Not Supported"} -}; - -/* helper functions */ -char * -substring (const char *str, int begin, int len) -{ - char *buffer; - if (str == NULL) - return NULL; - if (begin < 0) - begin = strlen (str) + begin; - if (begin < 0) - begin = 0; - if (len < 0) - len = 0; - if (((size_t) begin) > strlen (str)) - begin = strlen (str); - if (((size_t) len) > strlen (&str[begin])) - len = strlen (&str[begin]); - if ((buffer = xmalloc (len + 1)) == NULL) - return NULL; - memcpy (buffer, &(str[begin]), len); - buffer[len] = '\0'; - - return buffer; -} - -char * -alloc_string (const char *str) -{ - char *new = xmalloc (strlen (str) + 1); - strcpy (new, str); - return new; -} - -void -xstrncpy (char *dest, const char *source, const size_t dest_size) -{ - strncpy (dest, source, dest_size); - if (dest_size > 0) { - dest[dest_size - 1] = '\0'; - } else { - dest[0] = '\0'; - } -} - -int -count_occurrences (const char *s1, char c) -{ - const char *ptr = s1; - int n = 0; - do { - if (*ptr == c) - n++; - } while (*(ptr++)); - return n; -} - -char * -get_home (void) -{ - char *user_home = NULL, *path = NULL; - - user_home = getenv ("HOME"); - if (user_home == NULL) - return NULL; - - path = xmalloc (snprintf (NULL, 0, "%s/.goaccessrc", user_home) + 1); - sprintf (path, "%s/.goaccessrc", user_home); - - return path; -} - -char * -get_global_config (void) -{ - char *path = NULL; - - path = xmalloc (snprintf (NULL, 0, "%s/goaccess.conf", SYSCONFDIR) + 1); - sprintf (path, "%s/goaccess.conf", SYSCONFDIR); - - return path; -} - -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -char * -convert_date (char *result, char *data, const char *from, const char *to, - int size) -{ - struct tm tm; - char *end; - - memset (&tm, 0, sizeof (tm)); - - end = strptime (data, from, &tm); - if (end == NULL || *end != '\0') - return NULL; - if (strftime (result, size, to, &tm) <= 0) - return NULL; - - return result; -} - -#pragma GCC diagnostic warning "-Wformat-nonliteral" - -int -invalid_ipaddr (char *str) -{ - union - { - struct sockaddr addr; - struct sockaddr_in6 addr6; - struct sockaddr_in addr4; - } a; - - if (str == NULL || *str == '\0') - return 1; - - memset (&a, 0, sizeof (a)); - if (1 == inet_pton (AF_INET, str, &a.addr4.sin_addr)) - return 0; - else if (1 == inet_pton (AF_INET6, str, &a.addr6.sin6_addr)) - return 0; - return 1; -} - -/* off_t becomes 64 bit aware */ -off_t -file_size (const char *filename) -{ - struct stat st; - - if (stat (filename, &st) == 0) - return st.st_size; - - LOG_DEBUG (("Can't determine size of %s: %s\n", filename, strerror (errno))); - - return -1; -} - -const char * -verify_status_code_type (const char *str) -{ - size_t i; - for (i = 0; i < ARRAY_SIZE (code_type); i++) - if (strchr (code_type[i][0], str[0]) != NULL) - return code_type[i][1]; - - return "Unknown"; -} - -const char * -verify_status_code (char *str) -{ - size_t i; - for (i = 0; i < ARRAY_SIZE (codes); i++) - if (strstr (str, codes[i][0]) != NULL) - return codes[i][1]; - - return "Unknown"; -} - -char * -ltrim (char *s) -{ - char *begin = s; - - while (isspace (*begin)) - ++begin; - memmove (s, begin, strlen (begin) + 1); - - return s; -} - -char * -rtrim (char *s) -{ - char *end = s + strlen (s); - - while ((end != s) && isspace (*(end - 1))) - --end; - *end = '\0'; - - return s; -} - -char * -trim_str (char *str) -{ - return rtrim (ltrim (str)); -} - -char * -filesize_str (unsigned long long log_size) -{ - char *size = (char *) xmalloc (sizeof (char) * 12); - if (log_size >= GB) - snprintf (size, 12, "%.2f GiB", (double) (log_size) / GB); - else if (log_size >= MB) - snprintf (size, 12, "%.2f MiB", (double) (log_size) / MB); - else if (log_size >= KB) - snprintf (size, 12, "%.2f KiB", (double) (log_size) / KB); - else - snprintf (size, 12, "%.1f B", (double) (log_size)); - - return size; -} - -char * -usecs_to_str (unsigned long long usec) -{ - char *size = (char *) xmalloc (sizeof (char) * 11); - if (usec >= HOUR) - snprintf (size, 11, "%.2f hr", (double) (usec) / HOUR); - else if (usec >= MINS) - snprintf (size, 11, "%.2f mn", (double) (usec) / MINS); - else if (usec >= SECS) - snprintf (size, 11, "%.2f s", (double) (usec) / SECS); - else if (usec >= MILS) - snprintf (size, 11, "%.2f ms", (double) (usec) / MILS); - else - snprintf (size, 11, "%.2f us", (double) (usec)); - - return size; -} - -char * -clean_date (char *s) -{ - char *buffer; - if ((s == NULL) || (*s == '\0')) - return NULL; - - buffer = xmalloc (strlen (s) + 1); - if (sscanf (s, "%11[^|]", buffer) != 1) { - free (buffer); - return NULL; - } - - return buffer; -} - -char * -clean_month (char *s) -{ - char *buffer; - if ((s == NULL) || (*s == '\0')) - return NULL; - - buffer = xmalloc (strlen (s) + 1); - if (sscanf (s, "%6[^|]", buffer) != 1) { - free (buffer); - return NULL; - } - - return buffer; -} - -char * -int_to_str (int d) -{ - char *s = xmalloc (snprintf (NULL, 0, "%d", d) + 1); - sprintf (s, "%d", d); - - return s; -} - -char * -float_to_str (float d) -{ - char *s = xmalloc (snprintf (NULL, 0, "%.2f", d) + 1); - sprintf (s, "%.2f", d); - - return s; -} - -int -intlen (int num) -{ - int l = 1; - while (num > 9) { - l++; - num /= 10; - } - - return l; -} - -char * -char_repeat (int n, char c) -{ - char *dest = xmalloc (n + 1); - memset (dest, c, n); - dest[n] = '\0'; - - return dest; -} - -/* replace old with new char */ -char * -char_replace (char *str, char o, char n) -{ - char *p = str; - - if (str == NULL || *str == '\0') - return str; - - while ((p = strchr (p, o)) != NULL) - *p++ = n; - - return str; -} - -/* strip blanks from a string */ -char * -deblank (char *str) -{ - char *out = str, *put = str; - - for (; *str != '\0'; ++str) { - if (*str != ' ') - *put++ = *str; - } - *put = '\0'; - - return out; -} - -void -str_to_upper (char *str) -{ - if (str == NULL || *str == '\0') - return; - - while (*str != '\0') { - *str = toupper (*str); - str++; - } -} - -char * -left_pad_str (const char *s, int indent) -{ - char *buf = NULL; - - indent = strlen (s) + indent; - buf = xmalloc (snprintf (NULL, 0, "%*s", indent, s) + 1); - sprintf (buf, "%*s", indent, s); - - return buf; -} - -/* returns unescaped malloc'd string */ -char * -unescape_str (const char *src) -{ - char *dest, *q; - const char *p = src; - - if (src == NULL || *src == '\0') - return NULL; - - dest = xmalloc (strlen (src) + 1); - q = dest; - - while (*p) { - if (*p == '\\') { - p++; - switch (*p) { - case '\0': - /* warning... */ - goto out; - case 'n': - *q++ = '\n'; - break; - case 'r': - *q++ = '\r'; - break; - case 't': - *q++ = '\t'; - break; - default: - *q++ = *p; - break; - } - } else - *q++ = *p; - p++; - } -out: - *q = 0; - - return dest; -} - -/* returns escaped malloc'd string */ -char * -escape_str (const char *src) -{ - char *dest, *q; - const unsigned char *p; - - if (src == NULL || *src == '\0') - return NULL; - - p = (unsigned char *) src; - q = dest = xmalloc (strlen (src) * 4 + 1); - - while (*p) { - switch (*p) { - case '\\': - *q++ = '\\'; - *q++ = '\\'; - break; - case '\n': - *q++ = '\\'; - *q++ = 'n'; - break; - case '\r': - *q++ = '\\'; - *q++ = 'r'; - break; - case '\t': - *q++ = '\\'; - *q++ = 't'; - break; - default: - /* not ASCII */ - if ((*p < ' ') || (*p >= 0177)) { - *q++ = '\\'; - *q++ = '0' + (((*p) >> 6) & 07); - *q++ = '0' + (((*p) >> 3) & 07); - *q++ = '0' + ((*p) & 07); - } else - *q++ = *p; - break; - } - p++; - } - *q = 0; - return dest; -} diff --git a/util.h b/util.h deleted file mode 100644 index a717ca8dd4..0000000000 --- a/util.h +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#ifndef UTIL_H_INCLUDED -#define UTIL_H_INCLUDED - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) - -#define REGEX_ERROR 100 -#define DATE_LEN 12 /* date length */ -#define KB 1024 -#define MB (KB * 1024) -#define GB (MB * 1024) - -#define MILS 1000ULL -#define SECS 1000000ULL -#define MINS 60000000ULL -#define HOUR 3600000000ULL - -char *alloc_string (const char *str); -char *char_repeat (int n, char c); -char *char_replace (char *str, char o, char n); -char *clean_date (char *s); -char *clean_month (char *s); -char *convert_date (char *result, char *data, const char *from, const char *to, - int size); -char *deblank (char *str); -char *escape_str (const char *src); -char *filesize_str (unsigned long long log_size); -char *float_to_str (float num); -char *get_global_config (void); -char *get_home (void); -char *int_to_str (int d); -char *left_pad_str (const char *s, int indent); -char *ltrim (char *s); -char *replace_str (const char *str, const char *old, const char *new); -char *rtrim (char *s); -char *secs_to_str (int secs); -char *substring (const char *str, int begin, int len); -char *trim_str (char *str); -char *unescape_str (const char *src); -char *usecs_to_str (unsigned long long usec); -const char *verify_status_code (char *str); -const char *verify_status_code_type (const char *str); -int count_occurrences (const char *s1, char c); -int intlen (int num); -int invalid_ipaddr (char *str); -off_t file_size (const char *filename); -void str_to_upper (char *s); -void xstrncpy (char *dest, const char *source, const size_t dest_size); - -#endif diff --git a/xmalloc.c b/xmalloc.c deleted file mode 100644 index b31276639f..0000000000 --- a/xmalloc.c +++ /dev/null @@ -1,82 +0,0 @@ -/** - * xmalloc.c -- *alloc functions with error handling - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#include -#if !defined __SUNPRO_C -#include -#endif -#include -#include - -#include "error.h" -#include "xmalloc.h" - -/* self-checking wrapper to malloc() */ -void * -xmalloc (size_t size) -{ - void *ptr; - - if ((ptr = malloc (size)) == NULL) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Unable to allocate memory - failed."); - - return (ptr); -} - -char * -xstrdup (const char *s) -{ - char *ptr; - size_t len; - - len = strlen (s) + 1; - ptr = xmalloc (len); - - strncpy (ptr, s, len); - return (ptr); -} - -/* self-checking wrapper to calloc() */ -void * -xcalloc (size_t nmemb, size_t size) -{ - void *ptr; - - if ((ptr = calloc (nmemb, size)) == NULL) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Unable to calloc memory - failed."); - - return (ptr); -} - -/* self-checking wrapper to realloc() */ -void * -xrealloc (void *oldptr, size_t size) -{ - void *newptr; - - if ((newptr = realloc (oldptr, size)) == NULL) - error_handler (__PRETTY_FUNCTION__, __FILE__, __LINE__, - "Unable to reallocate memory - failed"); - - return (newptr); -} diff --git a/xmalloc.h b/xmalloc.h deleted file mode 100644 index 58bd469c66..0000000000 --- a/xmalloc.h +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (C) 2009-2014 by Gerardo Orellana - * GoAccess - An Ncurses apache weblog analyzer & interactive viewer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * A copy of the GNU General Public License is attached to this - * source distribution for its full text. - * - * Visit http://goaccess.prosoftcorp.com for new releases. - */ - -#ifndef XMALLOC_H_INCLUDED -#define XMALLOC_H_INCLUDED - -char *xstrdup (const char *s); -void *xcalloc (size_t nmemb, size_t size); -void *xmalloc (size_t size); -void *xrealloc (void *oldptr, size_t size); - -#endif