



Estude fácil! Tem muito documento disponível na Docsity
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
Esta página não é visível na pré-visualização
Não perca as partes importantes!




148 TEM Journal – Volume 3 / Number 2 / 2014.
1
1
(^1) Plovdiv University “Paisii Hilendarski“, 236 Bulgaria Blvd., 4003 Plovdiv, Bulgaria
Abstract – The purpose of this publication is to present the implementation of API interface for RouterOS of the company MikroTik, which allows using PHP scripts for obtaining data for configuration and management of the routing devices that use this OS.
Keywords – API interface for RouterOS, MikroTik.
TEM Journal – Volume 3 / Number 2 / 2014. 149
RouterOS log
Failed to connect toRouterOS.
Time Topic Message
sendSync( newRouterOS\Request('/log print'))- >getAllOfType(RouterOS\Response::TYPE_DATA);** foreach ($logEntries as $entry ) {?>
sendSync($pingRequest- >setArgument('address', $_GET['address']));** } }?>
Ping
IP address:
Results:'; foreach ( $results as $result ) { echo 'Time:', $result->getArgument('time') , ''; } echo ''; }?>
TEM Journal – Volume 3 / Number 2 / 2014. 151
query( "SELECT time, rx-bits-per-second, tx-bits-per- second FROM stats WHERE time >= '" .date('Y-m-d H:i:s', $startTime = (time() - 121)). "'" ); while ($row = $result->fetch_assoc()) { $currentTime = 0 - ($startTime - DateTime::createFromFormat('Y-m-d H:i:s', $row['time'])- >getTimestamp() + 120); if (0 === $currentTime % 10) { $time[] = $currentTime; } else { $time[] = VOID; } $rx_bits_per_second[] = $row['rx-bits-per-second']; $tx_bits_per_second[] = $row['tx-bits-per-second']; } //Appointment of retrieved data $stats = new pData(); $stats->addPoints($time, 'Time'); $stats->addPoints($rx_bits_per_second, 'rx-bits-per- second'); $stats->addPoints($tx_bits_per_second, 'tx-bits-per- second'); //Settings of the appearance of the time axis $stats->setSerieTicks('Time', 10); $stats->setAbscissa('Time'); $stats->setXAxisName('Time'); $stats->setXAxisUnit('s'); $stats->setXAxisDisplay(AXIS_FORMAT_DEFAULT); //Settings for the vertical axis $stats->setAxisName(0, 'RX/TX'); $stats->setAxisUnit(0, 'bps'); $stats->setAxisDisplay(0, AXIS_FORMAT_METRIC); $stats->setSerieTicks('RX/TX', 1024);
//Upload speed settings $stats->setSerieOnAxis('rx-bits-per-second', 0); $stats->setSerieDescription('rx-bits-per-second', 'Upload');
$stats->setPalette('rx-bits-per-second',array('R'=>50, 'G'=>50,'B'=>127));
//Download speed settings $stats->setSerieOnAxis('tx-bits-per-second', 0); $stats->setSerieDescription('tx-bits-per-second', 'Download'); $stats->setPalette('tx-bits-per-second',array('R'=>255, 'G'=>50,'B'=>1)); //Preparing the graphic $chart = new pImage(700, 250, $stats, true); $chart->FontName = 'pChart/fonts/GeosansLight.ttf'; $chart->setGraphArea(160, 40, 640, 180); $chart->drawScale(); $chart->drawLegend( 570, 210, array('Style' =>LEGEND_NOBORDER,'Mode' => LEGEND_VERTICAL)); $chart->drawAreaChart(array('ForceTransparency' => 60)); //Sending the result $chart->Stroke(); ?>
Statistics
update everyseconds
152 TEM Journal – Volume 3 / Number 2 / 2014.
varrefreshRate = 3;
varrefreshRateElement =
document.getElementById('refreshRate');
refreshRateElement.onkeyup = function(e) {
varnewRefreshRate = new
Number(refreshRateElement.value);
if (!isNaN(newRefreshRate) &&newRefreshRate> 0) {
refreshRate = newRefreshRate;
} };
var refresher = function() {
loadingImage.style.display = 'inline';
varnewImage = new Image();
newImage.id = 'stat';
newImage.onload = function() {
statImage.parentNode.replaceChild(newImage, statImage);
statImage = newImage;
loadingImage.style.display = 'none';
setTimeout(refresher, refreshRate * 1000);
};
newImage.src = "img.php?"+new Date();
};
setTimeout(refresher, refreshRate * 1000);
//]]>
References
[1]. Adam Mohammed Saliu, Mohammed Idris Kolo, Mohammed Kudu Muhammad, Lukman Abiodun Nafiu, (2013).Internet Authentication and Billing (Hotspot) System Using MikroTik Router Operating System, International Journal of Wireless Communications and Mobile Computing,1(1),51-57. [2]. API ActionScript 3 class, http://wiki.mikrotik.com/wiki/API_ActionScript _3_class , (last visited on 17.03.2014). [3]. API Delphi, http://wiki.mikrotik.com/wiki/API_Delphi (last visited on 17.03.2014). [4]. API in CPP, http://wiki.mikrotik.com/wiki/API_In_CPP [5]. (last visited on 17.03.2014). [6]. Burgess, D. (2009). Learn RouterOS, ISBN 978-
[7]. Discher, St. (2011). RouterOS by Example, ISBN: 978-0615547046. [8]. Manual:API, http://wiki.mikrotik.com/wiki/Manual:A PI (last visited on 21.02.2014). [9]. MikroTikRouterOS, http://wiki.mikrotik.com/wiki/M anual:TOC (last visited on 21.02.2014). [10]. Net_RouterOS Releases, https://github.com/pear2/Net_RouterOS/rele ases (last visited on 21.02.2014). [11]. PEAR, http://pear2.php.net/ (last visited on 21.02.2014). [12]. Stoitsov, G. (2010). Types of addresses and levels of use in the TCP/IP protocol stack, REMIA 2010, Plovdiv. [13]. The implementation of the API Manual, https://github.com/pear2/Net_RouterOS/wiki (last visited on 21.02.2014). [14]. Util extras, https://github.com/pear2/Net_RouterOS/wiki/Util- extras , (last visited on 17.03.2014).
Corresponding author: Gencho Stoitsov Institution: Plovdiv University “Paisii Hilendarski“, Bulgaria E-mail: [email protected]