diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..ba113c3 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,72 @@ +name: Publish + +on: + push: + tags: + - "v*" # Push events to matching v*, i.e. v1.0, v20.15.10 + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 5.0.x + - name: Build + run: | + dotnet publish -r osx-x64 -c Release -p:PublishReadyToRun=true -p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained true -o build/macos-x64 src/UFiber.Configurator + dotnet publish -r linux-x64 -c Release -p:PublishReadyToRun=true -p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained true -o build/linux-x64 src/UFiber.Configurator + dotnet publish -r win-x64 -c Release -p:PublishReadyToRun=true -p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained true -o build/win-x64 src/UFiber.Configurator + - name: Pack + working-directory: build + run: | + tar -czvf UFiber.Configurator-MacOS.tar.gz macos-x64 + tar -czvf UFiber.Configurator-Linux.tar.gz linux-x64 + zip -r UFiber.Configurator-Windows.zip win-x64 + release: + runs-on: ubuntu-latest + needs: [build] + steps: + - uses: actions/checkout@v1 + - name: Create Release + id: create_release + uses: actions/create-release@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + - name: Upload MacOS + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: build/UFiber.Configurator-MacOS.tar.gz + asset_name: UFiber.Configurator-MacOS.tar.gz + asset_content_type: application/gzip + - name: Upload Linux + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: build/UFiber.Configurator-Linux.tar.gz + asset_name: UFiber.Configurator-Linux.tar.gz + asset_content_type: application/gzip + - name: Upload Windows + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: build/UFiber.Configurator-Windows.zip + asset_name: UFiber.Configurator-Windows.zip + asset_content_type: application/zip + + diff --git a/.gitignore b/.gitignore index 9c06b60..12c9add 100644 --- a/.gitignore +++ b/.gitignore @@ -350,4 +350,5 @@ MigrationBackup/ .ionide/ dumps -patched \ No newline at end of file +patched +build \ No newline at end of file diff --git a/README.md b/README.md index 35cf77b..1f32366 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,72 @@ # UFiber.Configurator -UFiber Configuration Tool + +> **Disclaimer**: This **NOT** an official tool nor it was endorsed in any way by Ubiquiti. This is a community driven tool. Even though we will do our best to help the community there are no implicity or explicity warranties whatsoever. Use at your own risk. + +FTTx became a quite popular technology to deliver high speed connectivity specially at homes (FTTH) on which on a single fiber optics terminal you can provision and deliver internet access, IPTV and VoIP. + +[Ubiquiti](https://www.ui.com) has a line of fiber optics networking products that target usually ISPs. Among those products, some of them in particular are used on the customer premises as a CPE, which receives the fiber optics line and transform it on ethernet which is usually called GPON CPE or ONT. + +The Ubiquiti products that fall on this category are: [UFiber Loco (UF-Loco)](https://www.ui.com/ufiber/ufiber-loco/), [UFiber Nano G (UF-Nano-G)](https://www.ui.com/ufiber/ufiber-nano-g/), [UFiber Instant (UF-Instant)](https://store.ui.com/collections/operator-ufiber/products/uf-instant). + +Even thought Ubiquiti advertive UF-Loco and UF-Nano-G as to support third party OLT devices on your ISP, the most "clean" usage requires a full UFiber networking deployment on your ISP to be as much as "plug and play" as possible. The UF-Instant is even worse, where Ubiquiti says that it *only* works if you are connected to a fiber optics line which is provided by an UFiber OLT. + +On UF-Loco and UF-Nano-G, the 3rd party support allow you to select a profile and set a very limited number of options to make it work with them which not always is enough to make it work on ISPs that have custom or more complex fiber networks. + +This tool allow you to overcome those limitations by patching UF-Loco and UF-Nano-G file system to allow those customizations and make it work properly with most of the ISPs. + +## Why are you doing that and not using the UFiber admin pages? + +After frustrating attempts to provide feedback and ask Ubiquiti for the ability to change some of those configuration using the embedded admin web pages natively, and seeing many users having the same problem, we decided to create this small tool to make it a simple one shot patch for the problem. + +Most of us use FTTH and usually the clunky ISP ONT/Modems are pretty bad or provide a lot of limitations then we usually replace this modem with an custom GPON ONT device (like the ones mentioned here) and use our own routers to provide networking for our environments. + +## How does it work? + +Essentially this is the flow: +1. Connects to your UFiber device using SSH and SCP; +2. Generate a dump of one of its partitions; +3. Pull the dump file to your host computer; +4. Apply the patch with the settings you passed to the tool as parameters (i.e. SLID, Vendor Id, Serial Number, MAC); +5. Push the file to the UFiber device; +6. Write the patched file to the original partition from which the dump was taken at first place. + +## Supported UFiber devices + +- UF-Loco +- UF-Nano-G +- UF-Instant *(still under test)* + +## Usage + +You can find release packages for each OS on the [Releases section](https://github.com/Unifi-Tools/UFiber.Configurator/releases) of this repository. + +By running the `UFiber.Configurator --help` you will get all the parameters used by this tool: + +``` +UFiber.Configurator + Apply configuration changes to UFiber devices + +Usage: + UFiber.Configurator [options] + +Options: + --host IP or hostname of the target UFiber device. + --user SSH user name. [default: ubnt] + --pw SSH password. [default: ubnt] + --port SSH port of the target UFiber device. [default: 22] + --dry-run Don't apply the patched file to the target UFiber device. (i.e. dry-run) + --slid The SLID (or PLOAM Password). + --vendor 4-digit Vendor Id (e.g. HWTC, MTSC, etc.). Combined with --serial, a GPON Serial Number is + built. + --serial 8-digit serial number (e.g. 01234567). Combined with --vendor, a GPON Serial Number is + built. + --mac The desired MAC address to clone. + --version Show version information + -?, -h, --help Show help and usage information +``` + +## Contributions and feedback + +Please feel free to open issues and contribute back. + +A huge thanks and kudos to @jakesays for all the help while creating this tool. \ No newline at end of file diff --git a/src/UFiber.Configurator/Program.cs b/src/UFiber.Configurator/Program.cs index 04db22a..568c977 100644 --- a/src/UFiber.Configurator/Program.cs +++ b/src/UFiber.Configurator/Program.cs @@ -4,14 +4,13 @@ using Renci.SshNet; using UFiber.Configurator; using System.CommandLine; using System.CommandLine.Invocation; -using System.Text; -using System.Linq; var rootCommand = new RootCommand("Apply configuration changes to UFiber devices") { new Option( "--host", - "IP or hostname of the target UFiber device.", ArgumentArity.ExactlyOne), + getDefaultValue: () => "192.168.1.1", + "IP or hostname of the target UFiber device."), new Option( "--user", getDefaultValue: () => "ubnt", @@ -171,13 +170,13 @@ rootCommand.Handler = CommandHandler } Console.WriteLine("Uploaded!"); Console.WriteLine("### Applying patched file on the target UFiber device..."); - // cmd = ssh.RunCommand($"dd if=/tmp/{patchedFileName} of=/dev/mtdblock3 && rm /tmp/{patchedFileName}"); - // if (cmd.ExitStatus != 0) - // { - // Console.Error.WriteLine($"Failure to apply patched image file. Error: {cmd.Error}"); - // Environment.ExitCode = cmd.ExitStatus; - // return; - // } + cmd = ssh.RunCommand($"dd if=/tmp/{patchedFileName} of=/dev/mtdblock3 && rm /tmp/{patchedFileName}"); + if (cmd.ExitStatus != 0) + { + Console.Error.WriteLine($"Failure to apply patched image file. Error: {cmd.Error}"); + Environment.ExitCode = cmd.ExitStatus; + return; + } Console.WriteLine("### Applied patch! Please reboot your UFiber device to load the new image."); } else