wgcf Documentation

repository·master·Indexed 27 days ago

https://github.com/virb3/wgcf

An unofficial, cross-platform CLI tool for managing Cloudflare Warp accounts. wgcf allows users to register accounts, generate WireGuard profiles, and bind Warp+ subscriptions to use Cloudflare services via the WireGuard protocol. It includes a Go API client for interacting with the Cloudflare WARP API, featuring endpoints for account registration, license management, and device updates.

Tokens
26.8K
Snippets
35
Records
201
Agent score
90%

What's inside wgcf

  1. Check device and Warp status

    master

    Use the following commands to inspect your account and connection status:

    • wgcf status: Checks the current device/account status.
    • wgcf trace: Prints trace information to debug the connection. After connecting to your generated WireGuard profile, check the last line of the output. It should indicate warp=on or warp=plus.
    wgcf status
    wgcf trace
  2. Regenerate the OpenAPI API client

    master

    The API client code is auto-generated from openapi-spec.yml and resides in the openapi/ package. To update the client, do not edit the openapi/ directory directly. Instead, modify openapi-spec.yml and run the generator.

    Prerequisites: Install openapi-generator.

    Command:

    go generate
  3. Add a Warp+ license key to an account

    master

    If you have an existing Warp+ subscription (purchased directly via the official 1.1.1.1 app), you can bind it to your wgcf account. Note that there is a limit of 5 linked devices.

    Important Bug Workaround: If you have previously connected to Warp VPN, a known Cloudflare bug may prevent Warp+ from activating even after binding a key. If this happens, you must register a completely new account and immediately apply the license key without running other commands.

    Steps to apply a license key:

    1. Obtain your license key from the 1.1.1.1 app (Account > Key).
    2. Run the following commands:
    wgcf update --license-key "YOUR_LICENSE_KEY_GOES_HERE"
    wgcf generate
  4. Install the Go API client

    master

    To use this API client, install the required dependencies and import the package into your project. To use a proxy, set the HTTP_PROXY environment variable.

    go get github.com/stretchr/testify/assert
    go get golang.org/x/net/context
    import openapi "github.com/GIT_USER_ID/GIT_REPO_ID"
    os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")
  5. Generate a WireGuard profile

    master

    To generate a WireGuard configuration file, run the generate command. The resulting profile will be saved as wgcf-profile.conf.

    Note on MTU: The generated profile uses an MTU of 1280 for maximum compatibility (matching the official Android app). If you encounter performance issues, you may attempt to increase this value.

    wgcf generate
  6. Configure the Server URL

    master

    The client uses a default server configuration. You can override the server index or provide templated variables using Go context values.

    ### Select a different server index
    ```go
    ctx := context.WithValue(context.Background(), openapi.ContextServerIndex, 1)

    Use templated server variables

    ctx := context.WithValue(context.Background(), openapi.ContextServerVariables, map[string]string{
    	"basePath": "v2",
    })
  7. Configure URLs per Operation

    master

    You can override the server URL for specific operations using the OperationServers map in the Configuration. Operations are identified by the string format "{classname}Service.{nickname}". Use openapi.ContextOperationServerIndices and openapi.ContextOperationServerVariables to pass these overrides via context.

    ctx := context.WithValue(context.Background(), openapi.ContextOperationServerIndices, map[string]int{
    	"{classname}Service.{nickname}": 2,
    })
    ctx = context.WithValue(context.Background(), openapi.ContextOperationServerVariables, map[string]map[string]string{
    	"{classname}Service.{nickname}": {
    		"port": "8443",
    	},
    })
  8. Initialize the Cloudflare WARP API Client

    master
    To interact with the Cloudflare WARP API, create a new APIClient using the NewAPIClient function. This requires a *Configuration object. You can optionally provide a custom http.Client within the configuration to enable advanced features like caching. It is recommended to share a single APIClient instance across your application.
  9. Instantiate Register200Response in Go

    master

    You can create a Register200Response object using two different constructor methods depending on whether you need to satisfy API requirements or just assign default values.

    • NewRegister200Response(...): Instantiates a new object and assigns default values to properties. It ensures properties required by the API are set, but the argument list may change if API requirements change.
    • NewRegister200ResponseWithDefaults(): Instantiates a new object and only assigns default values. It does not guarantee that all API-required properties are set.
  10. Access and set Networks in GetClientConfig200ResponseCaptivePortalInner

    master

    The Networks field can be managed using the following methods:

    • GetNetworks() []GetClientConfig200ResponseCaptivePortalInnerNetworksInner: Returns the Networks field if non-nil, otherwise returns the zero value.
    • GetNetworksOk() (*[]GetClientConfig200ResponseCaptivePortalInnerNetworksInner, bool): Returns a tuple containing the Networks field (if non-nil) and a boolean indicating if the value has been set.
    • SetNetworks(v []GetClientConfig200ResponseCaptivePortalInnerNetworksInner): Sets the Networks field to the provided slice of networks.