0

I have a monitoring application (nagiosxi) that is deployed on a Linux box and some final settings are carried out via the web browser. For example, if the application is deployed on say, 192.168.2.10 and if I point the browser to http://192.168.2.10, it automatically redirects to http://192.168.2.10/nagiosxi/install.php. There are some basic settings like verifying the URL and click next, followed by setting up a password and finally hitting finished set-up.

Now, I trying to see if I can do the same using the php CLI

So, in a terminal I tried,

php -f /usr/local/nagiosxi/html/install.php

but this gives a big stdout and I cannot interactively set anything.

Is there a way to do this? Please note I have zero background in PHP.

2
  • Why are you trying to install via cli if it's supposed to be done in browser? The script is likely only intended to be installed via browser. Commented Jun 29, 2020 at 2:34
  • @Spudly The idea is to automate the entire deployment. Commented Jun 29, 2020 at 3:34

1 Answer 1

1

The PHP manual may help you solve your problem.

I hope the reference code and source link below will help you.

source : https://www.php.net/manual/en/function.fopen.php

I was working on a console script for win32 and noticed a few things about it. On win32 it appears that you can't re-open the input stream for reading, but rather you have to open it once, and read from there on. Also, i don't know if this is a bug or what but it appears that fgets() reads until the new line anyway. The number of characters returned is ok, but it will not halt reading and return to the script. I don't know of a work around for this right now, but i'll keep working on it.

This is some code to work around the close and re-open of stdin.

<?php
function read($length='255'){
    if (!isset($GLOBALS['StdinPointer'])){
        $GLOBALS['StdinPointer']=fopen("php://stdin","r");
    }
    $line=fgets($GLOBALS['StdinPointer'],$length);
    return trim($line);
}
echo "Enter your name: ";
$name=read();
echo "Enter your age: ";
$age=read();
echo "Hi $name, Isn't it Great to be $age years old?";
@fclose($StdinPointer);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.