if ($ModelType != 'DES-3526' && $skipcablediaginitfor3526 == 'false' || $ModelType != 'DES-3026' || $ModelType != 'DGS-3100-24TG') { for ($pi = 1; $pi < 25; $pi++) { if (@snmpset($ip, $wcomm, ".1.3.6.1.4.1.171.12.58.1.1.1.12." . $pi, "i", "1", $writetimeout, $retries) == false) { $noerror = false; } } // Для 3200-28 делаем паузу в опросе, иначе часто получаем статус пары 'other'. Может исправят в новых прошивках if ($ModelType == 'DES-3200-28') { usleep($timeout); } } //Диагностика кабеля for ($pi = 1; $pi < 25; $pi++) { //без этой конструкции у меня не работал скрипт на 3026, с ней на 3028 if ($ModelType == 'DES-3026') { if (@snmpset($ip, $wcomm, ".1.3.6.1.4.1.171.12.58.1.1.1.12." . $pi, "i", "1", $writetimeout, $retries) == false) { $noerror = false; } } // Статус линка $cableDiagLinkStatus[$pi - 1] = @snmpget($ip, $rcomm, ".1.3.6.1.4.1.171.12.58.1.1.1.3." . $pi, $timeout, $retries); // Статус 1-й пары $cableDiagPair1Status[$pi - 1] = @snmpget($ip, $rcomm, ".1.3.6.1.4.1.171.12.58.1.1.1.4." . $pi, $timeout, $retries); // Статус 2-й пары $cableDiagPair2Status[$pi - 1] = @snmpget($ip, $rcomm, ".1.3.6.1.4.1.171.12.58.1.1.1.5." . $pi, $timeout, $retries); // Длина 1-й пары $cableDiagPair1Length[$pi - 1] = @snmpget($ip, $rcomm, ".1.3.6.1.4.1.171.12.58.1.1.1.8." . $pi, $timeout, $retries); // Длина 2-й пары $cableDiagPair2Length[$pi - 1] = @snmpget($ip, $rcomm, ".1.3.6.1.4.1.171.12.58.1.1.1.9." . $pi, $timeout, $retries); } // Список названий vlan
function Set($ip, $ver, $cm, $oid, $f, $v, $t = 1000000, $r = 2) { global $debug, $comms; if ($ver == 3 and $comms[$cm]['pprot']) { if ($debug) { echo "<div class=\"textpad noti \">snmpset -v3 -c{$cm} " . $comms[$cm]['aprot'] . "/" . $comms[$cm]['pprot'] . " {$ip} {$oid} {$f} {$v} ({$t} usec * {$r})</div>"; } return snmp3_set($ip, $cm, 'authPriv', $comms[$cm]['aprot'], $comms[$cm]['apass'], $comms[$cm]['pprot'], $comms[$cm]['ppass'], ".{$oid}", $f, $v, $t); } elseif ($ver == 3 and $comms[$cm]['aprot']) { if ($debug) { echo "<div class=\"textpad noti \">snmpset -v3 -c{$cm} " . $comms[$cm]['aprot'] . " {$ip} {$oid} {$f} {$v} ({$t} usec * {$r})</div>"; } return snmp3_set($ip, $cm, 'authNoPriv', $comms[$cm]['aprot'], $comms[$cm]['apass'], 'DES', '', ".{$oid}", $f, $v, $t); } elseif ($ver == 2) { if ($debug) { echo "<div class=\"textpad noti \">snmpset -v2c -c{$cm} {$ip} {$oid} {$f} {$v} ({$t} usec * {$r})</div>"; } return snmp2_set($ip, $cm, ".{$oid}", $f, $v, $t); } elseif ($ver == 0) { if ($debug) { echo "<div class=\"textpad noti \">Skipping Non-SNMP Device</div>"; } return 0; } else { if ($debug) { echo "<div class=\"textpad noti \">snmpset -v1 -c{$cm} {$ip} {$oid} {$f} {$v} ({$t} usec * {$r})</div>"; } return snmpset($ip, $cm, ".{$oid}", $f, $v, $t); } }
<?php // copyright license/LICENSE //SEND MODIFYING STATE COMMAND include "outlet_values.php"; //DYNAMIC VALUES //$num = 1; //outlet port # (1-8) $num = $_REQUEST['outletnum']; //echo $num; //echo vs return seem to change whether it returns once or twice, also return fails to pass anything but "" //if ($num) { echo 1; } else { echo 0;} //$num = 8; $op = "." . $num; //outlet port # (1-8) //$cmd = 3; //state change: 1 immediateon, 2 immediateoff, 3 reboot $cmd = $_REQUEST['commandnum']; $oid = $pre . $det . $op; //FUNCTIONS //READ STATUS $status = snmp3_real_walk($ip, $sec_name, $sec_level, $auth_protocol, $auth_passphrase, $priv_protocol, $priv_passphrase, $oid); //CHANGE STATE $result = snmpset($ip, $comm, $oid, 'i', $cmd); //true/false or 1/0? //RETURN VALUES //echo "Outlet: ".$num." was ".$result." turned ".$cmd; //return $result; echo $result;
function snmpset($oid, $type, $value) { return snmpset($this->hostname, $this->snmpsetup['community'], $oid, $type, $value); }
die; } else { if (isset($_GET['portoff'])) { snmpset("{$row['0']}", "private", "ifAdminStatus.{$port}", "i", "2"); $sqldown = "UPDATE ports SET state_id=2 WHERE port='{$port}' AND device_id='{$id}'"; $resdown = mysql_query($sqldown, $dbconnect); header("location:port.php?id={$id}&port={$port}"); die; } else { if (isset($_GET['iptvon'])) { snmpset("{$row['0']}", "private", "{$row['5']}.{$row['3']}", "i", "2"); header("location:port.php?id={$id}&port={$port}"); die; } else { if (isset($_GET['iptvoff'])) { snmpset("{$row['0']}", "private", "{$row['5']}.{$row['3']}", "i", "0"); header("location:port.php?id={$id}&port={$port}"); die; } else { if (isset($_GET['graf'])) { /* Преобразование в UNIXTIMESTAMP */ $start = mktime($shr, $smin, 00, $smon, $sday, $syear); $end = mktime($ehr, $emin, 00, $emon, $eday, $eyear); $rrd = array("--start={$start}", "--end={$end}", "DEF:in={$homedir}/rrd/" . $id . "_" . $port . ".rrd:in:AVERAGE", "DEF:out={$homedir}/rrd/" . $id . "_" . $port . ".rrd:out:AVERAGE", "CDEF:inbits=in,8,*", "CDEF:outbits=out,8,*", "AREA:inbits#00CF00FF:In", "GPRINT:inbits:LAST: Current\\:%8.2lf %s", "GPRINT:inbits:AVERAGE:Average\\:%8.2lf %s", "GPRINT:inbits:MAX:Max\\:%8.2lf %s\\n", "LINE1:outbits#002A97FF:Out", "GPRINT:outbits:LAST:Current\\:%8.2lf %s", "GPRINT:outbits:AVERAGE:Average\\:%8.2lf %s", "GPRINT:outbits:MAX:Max\\:%8.2lf %s"); $res = rrd_graph("{$homedir}/tmp/" . $id . "_" . $port . ".png", $rrd, count($rrd)); header("location:port.php?id={$id}&port={$port}"); die; } } } }
var_dump(snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2); echo "Multiple OID, single type in array, multiple value\n"; $z = snmpset($hostname, $communityWrite, array($oid1, $oid2), array('s'), array($newvalue1, $newvalue2), $timeout, $retries); var_dump($z); var_dump(snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1); var_dump(snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2); echo "Multiple OID & type, singe value in array\n"; $z = snmpset($hostname, $communityWrite, array($oid1, $oid2), array('s', 's'), array($newvalue1), $timeout, $retries); var_dump($z); var_dump(snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1); var_dump(snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2); echo "Multiple OID, 1st bogus, single type, multiple value\n"; $z = snmpset($hostname, $communityWrite, array($oid1 . '44.55.66.77', $oid2), 's', array($newvalue1, $newvalue2), $timeout, $retries); var_dump($z); var_dump(snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1); var_dump(snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2); echo "Multiple OID, 2nd bogus, single type, multiple value\n"; $z = snmpset($hostname, $communityWrite, array($oid1, $oid2 . '44.55.66.77'), 's', array($newvalue1, $newvalue2), $timeout, $retries); var_dump($z); var_dump(snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1); var_dump(snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2); echo "Multiple OID, single multiple type (1st bogus), multiple value\n"; $z = snmpset($hostname, $communityWrite, array($oid1, $oid2), array('q', 's'), array($newvalue1, $newvalue2), $timeout, $retries); var_dump($z); var_dump(snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1); var_dump(snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2); echo "Multiple OID, single multiple type (2nd bogus), multiple value\n"; $z = snmpset($hostname, $communityWrite, array($oid1, $oid2), array('s', 'w'), array($newvalue1, $newvalue2), $timeout, $retries); var_dump($z); var_dump(snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1); var_dump(snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2);
function setProperty($p_id, $value) { $prec = SQLSelectOne("SELECT * FROM snmpproperties WHERE ID='" . $p_id . "'"); if (!$prec['ID']) { return 0; } $drec = SQLSelectOne("SELECT * FROM snmpdevices WHERE ID='" . $prec['DEVICE_ID'] . "'"); if (!$drec['ID']) { return 0; } $snmp_oid = $prec['OID']; $snmp_host = $drec['HOST']; $snmp_community = $drec['READ_COMMUNITY']; $type = 'i'; //int string counter oid ip if ($prec['TYPE'] == 'int') { $type = 'i'; } elseif ($prec['TYPE'] == 'uint') { $type = 'u'; } elseif ($prec['TYPE'] == 'string') { $type = 's'; } elseif ($prec['TYPE'] == 'counter') { $type = 't'; } elseif ($prec['TYPE'] == 'oid') { $type = 'o'; } elseif ($prec['TYPE'] == 'ip') { $type = 'a'; } @($res = snmpset($snmp_host, $snmp_community, $snmp_oid, $type, $value)); if ($res) { $this->readProperty($p_id); } return $res; }
sleep(3); header("location:mac.php?id={$id}&port={$port}"); die; } else { if (isset($_GET['portoff'])) { snmpset("{$row['0']}", "private", "ifAdminStatus.{$port}", "i", "2"); header("location:mac.php?id={$id}&port={$port}"); die; } else { if (isset($_GET['iptvon'])) { snmpset("{$row['0']}", "private", "{$row['7']}.{$port}", "i", "2"); header("location:mac.php?id={$id}&port={$port}"); die; } else { if (isset($_GET['iptvoff'])) { snmpset("{$row['0']}", "private", "{$row['7']}.{$port}", "i", "0"); header("location:mac.php?id={$id}&port={$port}"); die; } } } } } } } } } } } } }
if (snmpset($apcs[$edit_name]['host'], $edit_community, $edit_statusoid, $statustype, $onvalue)) { $status = trim(snmpget($apcs[$edit_name]['host'], $edit_community, $edit_statusoid)); $status = preg_replace("/INTEGER:|STRING:|\"/", "", $status); if ($status == $onvalue) { $status = "On"; } if ($status == $offvalue) { $status = "Off"; } echo $status; } else { echo trim($_POST['value']) . "*"; } } if ($_POST['value'] == 'Off') { if (snmpset($apcs[$edit_name]['host'], $edit_community, $edit_statusoid, $statustype, $offvalue)) { $status = trim(snmpget($apcs[$edit_name]['host'], $edit_community, $edit_statusoid)); $status = preg_replace("/INTEGER:|STRING:|\"/", "", $status); if ($status == $onvalue) { $status = "On"; } if ($status == $offvalue) { $status = "Off"; } echo $status; } else { echo trim($_POST['value']) . "*"; } } if ($_POST['value'] == 'GET') { $status = trim(snmpget($apcs[$edit_name]['host'], $edit_community, $edit_statusoid));
} else { $portactres[$pdport] = 'Fail'; } } } // Сохранение результатов подписи портов для DES-3028, 3028, 3026, 3200-28 if ($ModelType == 'DES-3028' || $ModelType == 'DES-3028G' || $ModelType == 'DES-3026' || $ModelType == 'DES-3028P' || $ModelType == 'DES-3200-28') { if (@snmpset($ip, $wcomm, ".1.3.6.1.4.1.171.12.1.2.6.0", "i", "5", $timeout * 100, 0) != false) { $saveres = "<font color=#00ff00>Конфигурация успешно сохранена!</font>"; } else { $saveres = "<font color=#ff0000>Ошибка сохранения конфигурации!</font>"; } } // Сохранение результатов подписи портов для DES-3526 if ($ModelType == 'DES-3526') { @snmpset($ip, $wcomm, ".1.3.6.1.4.1.171.12.1.2.6.0", "i", "3", $timeout, 0); $saveres = "<font color=#0000ff>Запрос на сохранении конфигурации отправлен!</font>"; } // Сообщение в случае использования DGS-3100-24TG if ($ModelType == 'DGS-3100-24TG') { $saveres = "<font color=#0000ff>Сохранение конфигурации для DGS-3100-24TG данным модулем не поддерживается!</font>"; } } // Создаем шапку FDB таблицы $swtable = "\n<form method='post'>"; $swtable .= "\n<table border=1 width='100%'>"; $swtable .= "\n\t<tr class='head'>\n\t\t<td class='tablehead' colspan=3>Таблица описаний портов<br>"; // Отображать или нет кнопку 'Подписать' $savestr = ''; if ($enablesavecontrol == 'true') { $savestr = "<input type='submit' name='doit' value='Подписать' class='pdesc'>";
break; case "set": $oid = $buffer; $mode = "set2"; break; case "set2": if (strpos($buffer, ' ') === false) { $type = $buffer; $mode = "set3"; break; } else { list($type, $buffer) = explode(' ', $buffer, 2); // fall through voluntarily } case "set3": $response = snmpset($oid, $type, $buffer, $server) . "\n"; echo $response === true ? "DONE\n" : $response . "\n"; $mode = "command"; break; default: // assert false... eZDebugSetting::writeDebug('snmp-access', 'NONE', 'response'); echo "NONE\n"; $mode = "command"; break; } } while (!$quit); } function snmpset($oid, $type, $value, $server) { eZDebugSetting::writeDebug('snmp-access', "set {$oid} {$type} {$value}", 'command');
private function SetCopyUserPassword($UserPassword) { $Host = $this->Host; $Community = $this->Community; if ($this->debug) { printf("\nSetting Login Password:\n"); printf("CISCO-CONFIG-COPY-MIB::ccCopyUserPassword.%d to %s ...\n", $this->RandomNumber, $UserPassword); } // Set Login Password $oid = $this->ConfigCopyOID['ccCopyUserPassword'] . '.' . $this->RandomNumber; if (snmpset($Host, $Community, $oid, 's', $UserPassword)) { if ($this->debug) { printf('CISCO-CONFIG-COPY-MIB::'); printf("ccCopyUserPassword.%d ... Response OK\n", $this->RandomNumber); } return true; } else { $this->Error = 'CISCO-CONFIG-COPY-MIB::ccCopyUserPassword No Response or Response Error'; return false; } }
/** * Change SNMP value * The "type" parameter must be one of the following, depending on the type of variable to set on the SNMP host: * i INTEGER * u unsigned INTEGER * t TIMETICKS * a IPADDRESS * o OBJID * s STRING * x HEX STRING * d DECIMAL STRING * n NULLOBJ * b BITS * @param Host $host * @param string $object_id * @param string $type * @param mixed $value * @return bool * @throws Exception */ public static function set($host, $object_id, $type, $value) { snmp_set_oid_output_format(self::$oid_format); $snmp = $host->snmpTemplate; if (is_null($type)) { throw new Exception('type not set'); } if ($snmp instanceof SnmpTemplate) { switch ($snmp->version) { case "1": $result = snmpset($host->ip, $snmp->community, $object_id, $type, $value, $snmp->timeout, $snmp->retries); break; case "2": case "2c": $result = snmp2_set($host->ip, $snmp->community, $object_id, $type, $value, $snmp->timeout, $snmp->retries); break; case "3": $result = snmp3_set($host->ip, $snmp->security_name, $snmp->security_level, $snmp->auth_protocol, $snmp->auth_passphrase, $snmp->priv_protocol, $snmp->priv_passphrase, $object_id, $type, $value, $snmp->timeout, $snmp->retries); break; default: throw new Exception('SNMP Template not implemented yet'); } } return $result; }
function setSNMPValue($Device, $WriteCommunity, $OID, $Type, $Value) { $setvalue = @snmpset($Device, $WriteCommunity, $OID, $Type, $Value); return $setvalue; }
protected function snmpset($oid, $value, $type = null, $version = null, $community = null) { if (!$version) { $version = $this->getAgentVersion(); } if (!$community) { $community = $this->writeCommunity; } if (!$type) { list($oldValue, $oid, $type) = reset($this->getParsed($oid)); } if (!($typeCode = $this->getTypeCode($type))) { $this->setError(self::ERROR_UNKNOWN_TYPE); return false; } switch ($version) { case 1: return @snmpset($this->host, $community, $oid, $typeCode, $value, $this->timeout * 1000000, $this->retries); case 2: return @snmp2_set($this->host, $community, $oid, $typeCode, $value, $this->timeout * 1000000, $this->retries); case 3: extract($this->version3); return @snmp3_set($this->host, $secName, $secLevel, $authProtocol, $authPassphrase, $privProtocol, $privPassphrase, $oid, $typeCode, $value, $this->timeout * 1000000, $this->retries); default: return false; } }