$action, "args" => $args)); $descriptorspec = array( 0 => array("pipe", "r"), // stdin 1 => array("pipe", "w"), // stdout 2 => array("pipe", "w"), // stderr ); $cmd = 'sudo /opt/backups/bin/cwp_user'; $process = proc_open($cmd, $descriptorspec, $pipes); $return_data = null; $error = null; if (is_resource($process)) { fwrite($pipes[0], $send_data); fclose($pipes[0]); $cmd_stdout = stream_get_contents($pipes[1]); fclose($pipes[1]); $cmd_stderr = stream_get_contents($pipes[2]); fclose($pipes[2]); // It is important that you close any pipes before calling // proc_close in order to avoid a deadlock $exit_code = proc_close($process); if ($exit_code == 0){ $return_data = json_decode($cmd_stdout, true, 512); $json_errno = json_last_error(); if ($json_errno != JSON_ERROR_NONE){ $error = $lang['JSON_ERRNO'] . " $json_errno"; } } else { $error = $lang['CWP_USER_ERR'] . " - $cmd_stderr $cmd_stdout"; } } else { $error = $lang['CWP_USER_ERR']; } return array("err" => $error, "bakmgr" => $return_data); } if(isset($_GET['action'])){ $action = $_GET['action']; $args = $_POST['args']; $bakmgr = cwp_user($action, $args, $lang); if (is_null($bakmgr['bakmgr'])){ $err = array("data" => $bakmgr['err'], "status" => -1); echo json_encode($err); } else { echo json_encode($bakmgr['bakmgr']); } die; } // Initial page load $mod['ip_user'] = $_SESSION['ip_user']; $mod['tokengui'] = $_SESSION['tokengui']; $bakmgr = cwp_user("get_settings", array(), $lang); if (!is_null($bakmgr['err'])){ $mod['err'] = $bakmgr['err']; } elseif ($bakmgr['status'] != 0){ $mod['err'] = $bakmgr['data']; } elseif (!is_null($bakmgr['bakmgr'])){ $mod['bakmgr'] = $bakmgr['bakmgr']['data']; }