• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login
Netgate Discussion Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login

Commands in pfSsh.php don't work (manual php scripts do)

Scheduled Pinned Locked Moved webGUI
phpshellpfssh.php
9 Posts 4 Posters 2.5k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D
    deet
    last edited by Feb 13, 2021, 8:03 PM

    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 run 8 and then execute pfSsh.php, I can't get anything to run except the help command.

    In other words, while I can run the help command, I can't run anything help 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 as php -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.

    1 Reply Last reply Reply Quote 1
    • O
      opoplawski
      last edited by Jan 27, 2025, 7:13 PM

      I seem to be seeing the same behavior on my pfSense Plus 24.11 box.

      D 1 Reply Last reply Jan 27, 2025, 7:42 PM Reply Quote 0
      • D
        deet @opoplawski
        last edited by Jan 27, 2025, 7:42 PM

        @opoplawski are you running exec after entering commands?

        1 Reply Last reply Reply Quote 1
        • J
          jimp Rebel Alliance Developer Netgate
          last edited by Jan 27, 2025, 7:51 PM

          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: 
          

          Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

          Need help fast? Netgate Global Support!

          Do not Chat/PM for help!

          D 1 Reply Last reply Jan 27, 2025, 7:56 PM Reply Quote 0
          • D
            deet @jimp
            last edited by Jan 27, 2025, 7:56 PM

            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.

            1 Reply Last reply Reply Quote 1
            • O
              opoplawski
              last edited by opoplawski Jan 27, 2025, 8:00 PM Jan 27, 2025, 7:58 PM

              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
              ...
              
              1 Reply Last reply Reply Quote 0
              • J
                jimp Rebel Alliance Developer Netgate
                last edited by Jan 27, 2025, 8:03 PM

                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.

                Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

                Need help fast? Netgate Global Support!

                Do not Chat/PM for help!

                O 1 Reply Last reply Jan 27, 2025, 8:28 PM Reply Quote 1
                • O
                  opoplawski @jimp
                  last edited by Jan 27, 2025, 8:28 PM

                  @jimp gotcha - thanks, will do.

                  G 1 Reply Last reply Jan 31, 2025, 2:25 PM Reply Quote 0
                  • G
                    Gertjan @opoplawski
                    last edited by Jan 31, 2025, 2:25 PM

                    @opoplawski

                    The one liner method works also :

                    $config = parse_config(true); print_r($config);
                    exec
                    

                    No "help me" PM's please. Use the forum, the community will thank you.
                    Edit : and where are the logs ??

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post
                    Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
                      This community forum collects and processes your personal information.
                      consent.not_received