Auslesen von Netzwerkinformationen

This commit is contained in:
2023-05-02 22:03:09 +02:00
parent f2938cf701
commit ec8a954b0b
3 changed files with 63 additions and 79 deletions

View File

@@ -5,20 +5,15 @@ if (!defined('PICONTROL')) exit();
(include_once LIBRARY_PATH . 'network/network.function.php') or die('Error: 0x0011');
$tpl->setHeaderTitle(_t('Netzwerk'));
if (isset($_GET['hostname']))
{
if (isset($_POST['submit']) && $_POST['submit'] != '')
{
if (isset($_POST['hostname']) && trim($pHostname = trim($_POST['hostname'])) != '')
{
if (preg_match('/^([a-z][a-z0-9\-\.]*[^\-]){1,24}$/im', $pHostname))
{
if (isset($_GET['hostname'])) {
if (isset($_POST['submit']) && $_POST['submit'] != '') {
if (isset($_POST['hostname']) && trim($pHostname = trim($_POST['hostname'])) != '') {
if (preg_match('/^([a-z][a-z0-9\-\.]*[^\-]){1,24}$/im', $pHostname)) {
if (($status = editHostname($pHostname)) === true)
$tpl->msg('success', _t('Hostname gespeichert'), _t('Damit die &Auml;nderung wirksam wird, muss dein Raspberry Pi neu gestartet werden. <a href="%s">Jetzt neu starten.</a>', '?s=shutdown&restart'));
else
$tpl->msg('error', _t('Fehler'), _t('Fehler beim &Auml;ndern des Hostname! Fehlercode: %s', $status));
}
else
} else
$tpl->msg('error', _t('Fehler'), _t('Der Hostname ist ung&uuml;ltig! Er muss aus mindestens 1 bis 24 Zeichen bestehen und darf nur folgende Zeichen enthalten: A-Z a-z 0-9 -<br />Der Hostname darf nicht mit einem Bindestrich Anfangen oder Enden.'));
}
}
@@ -26,16 +21,13 @@ if (isset($_GET['hostname']))
$tpl->assign('hostname', rpi_getHostname());
$tpl->draw('network_hostname');
}
else
{
} else {
$networkConnections = getAllNetworkConnections();
$networkCounts = unserialize(htmlspecialchars_decode(getConfig('main:network.overflowCount', 'a:0:{}')));
$counter = 0;
foreach ($networkConnections as $network)
{
foreach ($networkConnections as $network) {
$countSent = 0;
$countReceive = 0;
@@ -57,4 +49,3 @@ else
$tpl->draw('network');
}
?>

View File

@@ -38,7 +38,7 @@ $tpl->assign('configHelpFilesFolders', $config['url']['help'].'?s=view&amp;i=1'.
$tpl->assign('configHelpCron', $config['url']['help'].'?s=view&amp;i=10'.getURLLangParam());
$tpl->assign('cronEntry', $cronEntry);
$tpl->assign('cronMatch', $cronMatch);
$tpl->assign('cronPHPCLI', ($cronPHPCLI = (trim(exec('dpkg -s php7.0-cli | grep Status: ')) != '' || trim(exec('dpkg -s php7.3-cli | grep Status: ')) != '') ? true : false));
$tpl->assign('cronPHPCLI', ($cronPHPCLI = (trim(exec('dpkg -s php-cli | grep Status: ')) != '' || trim(exec('dpkg -s php7.3-cli | grep Status: ')) != '') ? true : false));
$tpl->assign('cronLastExecution', formatTime(getConfig('cron:execution.cron', 0)));
$tpl->assign('cronLastExecutionBool', ($cronLastExecutionBool = (getConfig('cron:execution.cron', 0) > time()-150) ? true : false));
$tpl->assign('cronLastExecutionLog', formatTime($lastExecutionLog[0]));

View File

@@ -393,32 +393,24 @@ function getImageFromSignal($signal)
function getAllNetworkConnections()
{
$shell_string = '';
$output = array();
$networkInterfaces = json_decode(shell_exec('ip -j addr'));
exec('/sbin/ifconfig | grep -E -o "^[[:alnum:][:punct:]]*" | grep -E -v "(lo)" | sed "s/:$//"', $networkInterfaces);
foreach ($networkInterfaces as $interface) {
if ($interface->ifname != 'lo') {
$wirelessOption = [];
foreach ($networkInterfaces as $interface)
$shell_string .= '/sbin/ifconfig ' . $interface . (($networkInterfaces[count($networkInterfaces) - 1] != $interface) ? ' && echo "-#-" && ' : '');
foreach ($interface->addr_info as $addr) {
if ($addr->family == "inet")
$ipAddress = $addr->local;
}
$macAddress = $interface->address;
$bytesReceived = 0;
$bytesSent = 0;
$packetsReceived = 0;
$packetsSent = 0;
$streamInterfaces = explode('-#-', shell_exec($shell_string));
foreach ($streamInterfaces as $index => $streamInterface) {
$wirelessOption = '';
$interface = $networkInterfaces[$index];
preg_match('#inet(?:[ ]+(?:addr\:)?)([\w\.]+)#', $streamInterface, $ipAddress);
preg_match('#(?:HWaddr|ether) ([\w\:]+)#', $streamInterface, $macAddress);
preg_match('#RX(?:.*?)bytes[:| ]([\d]+)#', $streamInterface, $bytesReceived);
preg_match('#TX(?:.*?)bytes[:| ]([\d]+)#', $streamInterface, $bytesSent);
preg_match('#RX(?:.*?)packets[:| ]([\d]+)#', $streamInterface, $packetsReceived);
preg_match('#TX(?:.*?)packets[:| ]([\d]+)#', $streamInterface, $packetsSent);
$output0 = $interface;
if (substr($output0, 0, 4) == 'wlan') {
$streamWirelessInterface = shell_exec('/sbin/iwconfig ' . $output0);
if (substr($interface->ifname, 0, 4) == 'wlan') {
$streamWirelessInterface = shell_exec('/sbin/iwconfig ' . $interface->ifname);
if (0 == substr_count($streamWirelessInterface, 'Not-Associated')) {
$posConfig_start = @strpos($streamWirelessInterface, 'ESSID:"', 0) + 7;
@@ -446,7 +438,8 @@ function getAllNetworkConnections()
}
}
$output[] = array('interface' => $interface, 'mac' => strtoupper($macAddress[1]), 'ip' => (isset($ipAddress[1])) ? $ipAddress[1] : NULL, 'sent' => $bytesSent[1], 'receive' => $bytesReceived[1], 'option' => $wirelessOption, 'packets' => array('sent' => $packetsSent[1], 'received' => $packetsReceived[1]));
$output[] = array('interface' => $interface->ifname, 'mac' => strtoupper($macAddress), 'ip' => (isset($ipAddress)) ? $ipAddress : NULL, 'sent' => $bytesSent, 'receive' => $bytesReceived, 'option' => $wirelessOption, 'packets' => array('sent' => $packetsSent, 'received' => $packetsReceived));
}
}
return $output;