public function actionShellRun() { $repeat_cmd_name = Yii::$app->request->post()['repeat_cmd_name']; $repeat_cmd = DcmdOprCmdRepeatExec::findOne(['repeat_cmd_name' => $repeat_cmd_name]); $ips = array(); if ($repeat_cmd->ip_mutable) { $t = Yii::$app->request->post()['ips']; $ips = explode(";", $t); } $args = array(); if ($repeat_cmd->arg_mutable) { $temp = explode(";", Yii::$app->request->post()['args']); foreach ($temp as $ag) { $i = explode("=", $ag); if (sizeof($i) != 2) { continue; } $args[$i[0]] = $i[1]; } } $retcontent = array(); $query = DcmdCenter::findOne(['master' => 1]); if ($query) { list($ip, $port) = explode(':', $query["host"]); $reply = execRepeatOprCmd($ip, $port, $repeat_cmd_name, $args, $ips); if ($reply->getState() == 0) { $ret_msg = "State:success<br>Detail:<br>"; foreach ($reply->getResult() as $agent) { $ret_msg .= "-------------------------------------------------------<br>"; $ret_msg .= "Ip:" . $agent->getIp() . "<br>"; if ($agent->getState() == 0) { $ret_msg .= "State:success<br>"; $ret_msg .= "Status:" . $agent->getStatus() . "<br>"; $ret_msg .= "Result:<br>" . str_replace("\n", "<br/>", $agent->getResult()) . "<br>"; } else { $ret_msg .= "State:error<br>"; $ret_msg .= "Detail:<br>" . str_replace("\n", "<br/>", $agent->getErr()) . "<br>"; } $retContent["result"] = $ret_msg; } } else { $retContent["result"] = "State:error<br>detail:" . str_replace("\n", "<br/>", $reply->getErr()) . "<br>"; } } else { $retContent["result"] = "无法获取Center."; } echo json_encode($retContent); exit; }
public function actionOsInfo($ip) { $query = DcmdCenter::findOne(['master' => 1]); $ret_msg = ""; if ($query) { list($host, $port) = explode(':', $query["host"]); $reply = execRepeatOprCmd($host, $port, "os_info", array(), array($ip)); if ($reply->getState() == 0) { foreach ($reply->getResult() as $agent) { if ($agent->getState() == 0) { $result = explode("\n", $agent->getResult()); $os = array(); foreach ($result as $k => $v) { $pos = strpos($v, ":"); if ($pos == false) { continue; } $col = substr($v, 0, $pos); $param = substr($v, $pos + 1, strlen($v) - $pos); $pos = strpos($param, "="); $p1 = substr($param, 0, $pos); $p2 = substr($param, $pos + 1, strlen($param) - $pos); if (array_key_exists($col, $os) == false) { $os[$col] = array(); } $os[$col][$p1] = $p2; } foreach ($os as $k => $v) { $ret_msg .= "<p><strong>" . $k . "信息:</strong></p>"; $ret_msg .= '<table class="table table-striped table-bordered"><tbody>'; $ret_msg .= "<tr><td width=40%>参数</td><td>值</td></tr>"; foreach ($v as $a => $b) { $ret_msg .= "<tr><td>" . $a . "</td><td>" . $b . "</td></tr>"; } $ret_msg .= "</tbody></table>"; } } else { $ret_msg .= "<p><font color=red>获取OS失败:"; $ret_msg .= str_replace("\n", "<br/>", $agent->getErr()) . "</font></p>"; } } } else { $ret_msg .= "<p><font color=red>获取失败:" . str_replace("\n", "<br/>", $reply->getErr()) . "</font></p>"; } } else { $ret_msg .= "<p><font color=red>无法获取Center!</font></p>"; } echo $ret_msg; exit; }