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

Quesiton: How to create a user with fauxapi #26

Closed
Jgerardopine opened this issue Jul 12, 2018 · 2 comments
Closed

Quesiton: How to create a user with fauxapi #26

Jgerardopine opened this issue Jul 12, 2018 · 2 comments

Comments

@Jgerardopine
Copy link

HI,

I was trying to create a user with fauxapi. From dev shell you can create a new user by running the following command:

$config['system']['user'][] = <name>

The only .inc file that makes sense of creatin a user is auth.inc line 480.
I have tried with several functions with the method function_call() from fauxapi, but it doesn't create the user.
Have you been able to generate a user via fauxapi? I have been trying all day, eventhough the function is passing the arguments properly, and in the debugging is showing but the 200 ok, the user is not being created. Fo you have any clue on how to do this?

Best regards,

Jose Gerardo Pineda

@ndejong
Copy link
Owner

ndejong commented Aug 16, 2018

This sounded like a common enough use-case that I created some example code that implements the following:-

  • get_users - returns a dict of users on the system
  • add_user - adds a new user to the system
  • manage_user - manages users attributes such as password, sshkey, description and privileges
  • remove_user - removes a user by username
  • get_groups - returns a dict of groups on the system
  • add_group - creates a new local user group
  • manage_group - manages the description, privileges and users in a group
  • remove_group - removes a group by group name

You can review the code here:-
https://github.com/ndejong/pfsense_fauxapi_client_python/blob/master/examples/usergroup-management.py

The thing to remember is that FauxAPI is a tool for interacting with the pfSense configuration file and as such you sometimes need to do a bit of extra work here and there - in this case we need to increment the nextuid and nextguid fields after adding users and groups - works just fine though

@ndejong ndejong closed this as completed Aug 16, 2018
@Dev-Romar
Copy link

How to add nat and rules? Im using PHP.

Here is my code for NAT:

$data = [
    "nat" => [
        "rule" => [
            "source"=>[
                "any"=>""
            ],
            "destination"=>[
                "network"=>"wanip",
                "port"=>"8080"
            ],
            "protocol"=>"tcp",
            "target"=>"192.168.10.300",
            "local-port"=>"5050",
            "interface"=>"wan"
        ]
    ]
];

$response = $client->config_patch($data);
var_dump($response);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants