Skip to content
AnivicePublic

About

C++ Clash Dashboard

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

872 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CCDB

CI
CI
CI
CI
CI
CI

Warning

CCDB HAS POOR CHINESE LANGUAGE SUPPORT

The translation is incomplete and existing translations are a mess. Texts lacking Chinese corresponding translations are shown in English. Missing texts will be shown in ~/.cache/ccdb/MISSING-TRANSLATIONS.json for Release Candidates.

A lightweight terminal dashboard for Clash/Mihomo, written in C++.

Nload

Overview

CCDB targets low-resource environments (for example, embedded devices) and users who want a low-overhead dashboard.

CCDB depends on the following open-source libraries:

ALL SOURCES ARE VENDORED WITH NO ADDITIONAL DOWNLOAD AT COMPILE TIME.

Direct Downloads:

Linux

1. Define get function.
# Bash:
ccdb_get() {
    local prefix="$1" asset="$2" output="${3:-$2}"
    local page json line tag sha

    for ((page=1; ;page++)); do
        json=$(curl -fsSL \
          "https://api.github.com/repos/Anivice/ccdb/releases?per_page=100&page=$page") || return 1

        [[ "$json" == "[]" ]] && break

        while IFS= read -r line; do
            [[ $line =~ \"tag_name\"[[:space:]]*:[[:space:]]*\"([^\"]+)\" ]] || continue

            tag="${BASH_REMATCH[1]}"
            [[ "$tag" == "$prefix".* ]] || continue

            sha="${tag#"$prefix".}"
            [[ "$sha" =~ ^[0-9a-f]{8}$ ]] || continue

            if curl -fLSs --retry 3 \
                -o "$output" \
                "https://github.com/Anivice/ccdb/releases/download/$tag/$asset"; then
                printf 'Downloaded %s (%s)\n' "$output" "$tag"
                return 0
            fi
        done <<< "$json"
    done

    printf 'No matching release asset: %s / %s\n' "$prefix" "$asset" >&2
    return 1
}
2. Get assets.
  • Linux x86_64, musl-static:

    ccdb_get ccdb.NightlyBuild_x86_64_static ccdb
  • Linux i586, musl-static:

    ccdb_get ccdb.NightlyBuild_i586_static ccdb
  • Linux ARMv7 hard-float, musl-static:

    ccdb_get ccdb.NightlyBuild_armv7hf_static ccdb
  • Linux AArch64, musl-static:

    ccdb_get ccdb.NightlyBuild_aarch64_static ccdb
  • Linux x86_64, dynamically linked:

    ccdb_get ccdb.NightlyBuild ccdb && ccdb_get ccdb.NightlyBuild libccdb.so
  • Linux AArch64, dynamically linked:

    ccdb_get ccdb.NightlyBuild.aarch64 ccdb && ccdb_get ccdb.NightlyBuild.aarch64 libccdb.so
  • Linux x86_64, AppImage:

    ccdb_get ccdb.NightlyBuild.AppImage ccdb ccdb.AppImage
  • Linux AArch64, AppImage:

    ccdb_get ccdb.NightlyBuild.AppImage.aarch64 ccdb ccdb.AppImage

Windows

function Get-CCDB {
    param(
        [string]$Prefix,
        [string]$Asset = "ccdb.exe",
        [string]$Output = $Asset
    )

    $pattern = '^' + [regex]::Escape($Prefix) + '\.[0-9a-f]{8}$'

    for ($page = 1; ; $page++) {
        $uri = "https://api.github.com/repos/Anivice/ccdb/releases?per_page=100&page=$page"

        $json = (& curl.exe -fsSL $uri) -join "`n"
        if ($LASTEXITCODE -ne 0) {
            throw "GitHub API request failed."
        }

        if ($json.Trim() -eq '[]') { break }

        foreach ($release in ($json | ConvertFrom-Json)) {
            if ($release.draft -or -not $release.prerelease) {
                continue
            }

            if ($release.tag_name -cnotmatch $pattern) {
                continue
            }

            $item = $release.assets |
                Where-Object {
                    $_.name -ceq $Asset -and
                    $_.state -eq "uploaded"
                } |
                Select-Object -First 1

            if ($null -eq $item) { continue }

            & curl.exe -fL --retry 3 `
                -o $Output `
                $item.browser_download_url

            if ($LASTEXITCODE -eq 0) {
                Write-Host "Downloaded $Output ($($release.tag_name))"
                return
            }
        }
    }

    throw "No matching release asset: $Prefix / $Asset"
}
2. Get assets.
Get-CCDB ccdb.NightlyBuild.windows.x64 ccdb.exe

Usage

Use help command to see usage details.

Press Tab twice to list candidates in a command, this will list all the available candidates like proxy endpoints or groups, with additional information like latency (if tested) and vector index.

To run a shell command, prefix it with "$ " (dollar sign + space/$[WITH A SPACE]).

NOTE 1:

Double tab will show the helper details of each and every candidate:

img img

NOTE 2:

ccdb/ccdbrc.example

Lines 56 to 57 in c5b70b0

dashboard = get connections # clash dashboard
logs = get log # show logs

Comments for the aliases will be noted and printed in the double tab helper as well:

e.g.:

~/.ccdbrc definition: ~/.ccdbrc definition

Helper output: Helper output

Example 1: Switch Proxy in a Proxy Group

Step 1

Select the group you want to switch by the following command:

set vgroup [DOUBLE TAB TO LIST GROUPS YOU WANT TO SWITCH]

You should see the vector results similar to this image (groups and endpoints are redacted):

Image

Step 2

Say, I want to change group 44. Use the following command to list the proxy I can set for this group:

set vgroup 44 [DOUBLE TAB TO LIST WHICH PROXY ENDPOINT YOU WANT TO SWITCH TO]

Image

As is shown in the above image, currently selected proxy is marked with a prefix " * " and is highlighted in the candidate selection prompt. The selected endpoint for the above proxy group 44 is 3.

Additional Note

If you tested latency before using get latency, the latency results will be shown in the parentheses, i.e., ([\d]+), as is shown in the following image.

Image

Example 2: Map the Entire Proxy Chain

Image

Example 3: Shell Parsing of get config

CCDB supports shell parsing of its own command outputs. This can be useful for commands like get config to parse JSON on external utilities like jq. For example, you can select dns-hijack from the JSON reply from backend using get config | jq -r '.tun["dns-hijack"]':

Image

Or, you can even pipe a POSIX script into the pipeline:

Image

As you can see, when executing a piped script, you can invoke ccdb with environment variable $CCDB, which is a duplicate of the parent ccdb arguments.

Example 4: Dump backend debug info

   ccdb> get memory pprof heap > /tmp/heap

Here we dumped backend heap file to /tmp/heap.

How to Build

Linux

Requirements

You need

  • a complete C++ toolchain of either GCC or Clang that can process at least C++ 17 (GCC >= 13 would be fine)
  • cmake and your build system of choice (either Unix Makefile [make] or Ninja [ninja]).
  • tar, sed, and grep, the standard POSIX tools that should exist on all Linux systems by default.
  • GNU's automake, required by tar package for ccdb

to build CCDB.

All dependencies are embedded inside the source code. No additional installation required.

CMake Settings

  • OPENSSL_TARGET: Supported openssl target, if you are cross-compiling you need to specify a platform.
  • OPENSSL_LIBP: Depending on the target, openssl can have its lib in .../lib or .../lib64, you can tell CMake this info by setting it to lib or lib64.

Build

Linux

On x86_64, you can use the command

  git clone https://github.com/Anivice/ccdb --depth=1 && \
  cd ccdb && mkdir build && cd build && \
  cmake ../src/ -DPERL_MAKE_ADDITIONAL_FLAGS=-j$(nproc) -DOPENSSL_MAKE_ADDITIONAL_FLAGS=-j$(nproc) -DREADLINE_MAKE_ADDITIONAL_FLAGS=-j$(nproc) -DNCURSES_MAKE_ADDITIONAL_FLAGS=-j$(nproc) \
      -DCC_ADDITIONAL_OPTIONS="-O3 -fomit-frame-pointer -ffast-math -fstrict-aliasing -fdata-sections -ffunction-sections -D_FORTIFY_SOURCE=2 -fno-stack-protector -s" \
      -DLD_ADDITIONAL_OPTIONS="-O3 -fomit-frame-pointer -ffast-math -fstrict-aliasing -fdata-sections -ffunction-sections -D_FORTIFY_SOURCE=2 -fno-stack-protector -s" \
      -DOPENSSL_TARGET=linux-x86_64 -DOPENSSL_LIBP=lib64 && \
  make -j$(nproc)

to build locally.

Windows
git clone https://github.com/Anivice/ccdb --depth=1
cd ccdb
New-Item -ItemType Directory -Force -Path build | Out-Null
cd build

# Set this to the CMake on your own machine
$cmake = "C:\Program Files\Microsoft Visual Studio\18\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe"

& $cmake ../src/
& $cmake --build . --config Release --parallel 32

Disclaimers

THIS PROJECT INCORPORATES THE USE OF ARTIFICIAL INTELLIGENCE.

This is free software; There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This project is provided "as is." DO NOT use it in production.

The author is not responsible for any data losses, credential leaks, or other possible damages done to your work or machine due to even the correct and simple use of the tool.

YOU HAVE BEEN WARNED


CCDB is GPLv3-licensed to comply with its statically linked GPL dependencies.

See LICENSE for details.

About

C++ Clash Dashboard

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages