[go: up one dir, main page]

Menu

[r61]: / inc / functions.php  Maximize  Restore  History

Download this file

123 lines (113 with data), 3.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
require_once 'MDB2.php';
function getListOfProtocols($select_name, $selected){
$out="<select name='service[".$select_name."][protocol]'>\n";
$options[]='http';
$options[]='sip';
foreach($options as $option) {
if($option==$selected){
$add_select="selected='selected'";
}
else {
$add_select="";
}
$out .= "<option value='$option' $add_select >$option</option>\n";
}
return $out;
}
function addMachine($vals_array){
$mdb2 =& MDB2::singleton();
if($vals_array['host']==""){
return;
}
$query="INSERT INTO machine VALUES(NULL, ";
$query .= "'".$vals_array['host']."',";
$query .= "'".$vals_array['display']."',";
$query .= "'".$vals_array['user']."',";
$query .= "'".$vals_array['password']."',";
$query .= "'".$vals_array['port']."'";
$query .=")";
$mdb2->query($query);
}
function delMachine($mid){
$mdb2 =& MDB2::singleton();
$query="DELETE FROM machine WHERE `id`='".$mid."'";
$mdb2->query($query);
}
function updateService($vals_array){
$mdb2 =& MDB2::singleton();
if (PEAR::isError($mdb2)) {
die($mdb2->getMessage());
} if(!isset($vals_array['id'])){
if($vals_array['port']==""){
return;
}
$query="INSERT INTO service VALUES(NULL, ";
$query .= "'".$vals_array['mid']."',";
$query .= "'".$vals_array['protocol']."',";
$query .= "'".$vals_array['port']."',";
$query .= "'".$vals_array['interval']."',";
$query .= "'".$vals_array['count']."',";
$query .= "'',";
$query .= "'".$vals_array['service_name']."'";
$query .=")";
$mdb2->query($query);
return;
}
if(isset($vals_array['del'])){
$query="DELETE FROM service WHERE `id`='".$vals_array['id']."'";
$mdb2->query($query);
return;
}
$query="UPDATE service SET ";
$query .= "`protocol`='".$vals_array['protocol']."',";
$query .= "`port`='".$vals_array['port']."',";
$query .= "`interval`='".$vals_array['interval']."',";
$query .= "`count`='".$vals_array['count']."',";
$query .= "`service_name`='".$vals_array['service_name']."' ";
$query .= "WHERE id='".$vals_array['id']."'";
$mdb2->query($query);
}
function execute_ssh_command($host, $port, $user, $pass_or_key, $cmd){
$connection=null;
if(is_readable($pass_or_key)){
$connection = ssh2_connect($host, $port,array('hostkey'=>'ssh-rsa'));
if (!ssh2_auth_pubkey_file($connection,$user,"$pass_or_key.pub",$pass_or_key)){
return false;
}
}
else {
$connection = ssh2_connect($host, $port);
if (ssh2_auth_password($connection, $user, $pass_or_key)===FALSE) {
return false;
}
}
$stream = ssh2_exec($connection, $cmd);
stream_set_blocking($stream, true);
return stream_get_contents($stream);
}
function get_machines_from_db(){
$mdb2 =& MDB2::singleton();
if (PEAR::isError($mdb2)) {
die($mdb2->getMessage());
} $query = "SELECT * FROM machine";
$result=&$mdb2->query($query);
$machines=array();
while($machine=$result->fetchRow(MDB2_FETCHMODE_OBJECT)){
$id=$machine->id;
$machines[$id]=$machine;
}
return $machines;
}
function getServicesOfMachine($mid){
$mdb2 =& MDB2::singleton();
if (PEAR::isError($mdb2)) {
die($mdb2->getMessage());
} $res =& $mdb2->query("SELECT * FROM service WHERE machine_id=$mid");
$services=array();
while ($row = $res->fetchRow(MDB2_FETCHMODE_OBJECT)) {
$services[]=$row;
}
return $services;
}
?>