Commands in pfSsh.php don't work (manual php scripts do)
-
Trying to automate some things. Looking at the PHP developer shell:
https://pfsense-docs.readthedocs.io/en/latest/development/using-the-php-pfsense-shell.html
If I log in as any user and, from the menu, either run
12
or run8
and then executepfSsh.php
, I can't get anything to run except thehelp
command.In other words, while I can run the
help
command, I can't run anythinghelp
suggests and get any results.Example:
Starting the pfSense developer shell.... Welcome to the pfSense developer shell Type "help" to show common usage scenarios. Available playback commands: changepassword disablecarp disablecarpmaint disabledhcpd disablereferercheck enableallowallwan enablecarp enablecarpmaint enablesshd externalconfiglocator gatewaystatus generateguicert gitsync installpkg listpkg pfanchordrill pftabledrill removepkgconfig removeshaper resetwebgui restartdhcpd restartipsec svc uninstallpkg pfSense shell: help Enter a series of commands and then execute the set with "exec". For example: echo "foo"; // php command echo "foo2"; // php command ! echo "heh" # shell command exec Example commands: record <recordingfilename> stoprecording showrecordings parse_config(true); # reloads the $config array $temp = print_r($config, true); more($temp); /* to output a configuration array */ print_r($config); (snip) pfSense shell: parse_config(true); pfSense shell: print_r($config); pfSense shell:
The output is nothing.
However, if I do it manually through the php interactive shell, it seems to work:
php -a -d display_errors=true require_once("globals.inc"); require_once("functions.inc"); require_once("config.inc"); require_once("util.inc"); parse_config(true); print_r($config);
(The config tree prints).
Am I wrong to expect the php developer shell
pfSsh.php
to work the same asphp -a
?I'm fine with writing my own php if that's the preferred method, but I was thinking it would be better to run it through the provided shell script. Am I maybe overlooking something about how to do that?
Thanks very much.
-
I seem to be seeing the same behavior on my pfSense Plus 24.11 box.
-
@opoplawski are you running
exec
after entering commands? -
Works fine here when I try. You do need
exec
as the last manual command to execute from the PHP shell prompt:Netgate pfSense Plus shell: print(config_get_path('system/hostname') . "\n"); Netgate pfSense Plus shell: exec river Netgate pfSense Plus shell:
-
The
exec
step is what I had been overlooking, at least. It's stated explicitly, and it's even right there in the very transcript I posted, but I wasn't processing the second half of that sentence for some reason. -
Some things are working, but others are not:
Netgate pfSense Plus shell: print(config_get_path('system/hostname') . "\n"); Netgate pfSense Plus shell: exec inferno Netgate pfSense Plus shell: parse_config(true); Netgate pfSense Plus shell: print_r($config); Netgate pfSense Plus shell: exec Netgate pfSense Plus shell:
The print_r works on my other pfSense box:
pfSense shell: parse_config(true); # reloads the $config array pfSense shell: print_r($config); pfSense shell: exec Array ( [version] => 23.3 ...
-
That example is outdated. Things are not accessed directly using
$config
these days. And there shouldn't be a need to re-parse it that way.It should work if you declare it global first, try:
global $config; print_r($config); exec
How best to do whatever you are trying to do is probably a better subject for a fresh thread with a specific subject, though.
-
@jimp gotcha - thanks, will do.
-