Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Advanced Settings Template #1210

Open
fodhelper opened this issue Aug 1, 2024 · 0 comments
Open

More Advanced Settings Template #1210

fodhelper opened this issue Aug 1, 2024 · 0 comments
Labels
Backend Feature New feature or request

Comments

@fodhelper
Copy link
Contributor

fodhelper commented Aug 1, 2024

Currently we have Settings/Headers template for each Transport of different Client Cores (Thanks to M03ED)

  1. We can have multiple Settings for each transport in the Settings Template, and from GUI, user can select one for each Host or let it get selected randomly (I guess select random for all Hosts is enough)

If we don't need to specify a different Settings for each Host then this can do the job

import json, random

def random_from_array(data):
    if isinstance(data, list):
        return data[ random.randint(0, len(data)) - 1 ]
    else:
        return None

jsonFile = '''
{
  "grpcSettings": [
    {
      "data": "first"
    },
    {
      "data": "second"
    }
  ]
}
'''

jsonTemplate = json.loads(jsonFile)

# Print a random item
print( random_from_array(jsonTemplate["grpcSettings"]) )

# Check if Array is valid
if random_from_array(jsonTemplate):
    print("valid")
else:
    print("in-valid")

# Check if Array is valid
if random_from_array(jsonTemplate["grpcSettings"]):
    print("valid")
else:
    print("in-valid")
  1. We can add multiple v2rayNG sockopt template and let user select one for each Host (Here the ability to select random must not exist i guess)
    https://xtls.github.io/config/transport.html#sockoptobject
    sing-box have dial settings instead of sockopt :
    https://sing-box.sagernet.org/configuration/shared/dial/
    and Clash.Meta have common proxy settings :
    https://wiki.metacubex.one/en/config/proxies/

Here is a function but it needs GUI changes that i can't do them myself

import json, random

def get_item(data, by_name=None):
  if by_name != None:
    if by_name in data:
      return data[by_name]
    else:
      return None
  else:
    keys = list(data.keys())
    random_key = random.choice(keys)
    return data[random_key]

jsonFile = '''
{
  "tree": {
    "0": {
      "data": "aaa0",
      "data": "aaa1",
      "data": "aaa2",
      "data": "aaa3"
    },
    "1": {
      "data": "bbb12"
    },
    "2": {
      "data": "ccc34"
    },
    "3": {
      "data": "ddd56"
    }
  }
}
'''

jsonTemplate = json.loads(jsonFile)

# Print a random item
print( get_item(jsonTemplate["tree"]) )

# Print a random item
print( get_item(jsonTemplate["tree"]["0"]) )

# Print item with name "0"
print( get_item(jsonTemplate["tree"], by_name="1") )

# Check if item with name "2" exist or not
if get_item(jsonTemplate["tree"], by_name="2"):
    print("exist")
else:
    print("not exist")

# Check if item with name "5" exist or not
if get_item(jsonTemplate["tree"], by_name="5"):
    print("exist")
else:
    print("not exist")

This and #1190 will be so good for pro users

@fodhelper fodhelper added the Feature New feature or request label Aug 1, 2024
@erfjab erfjab added the Backend label Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend Feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants