Need help about Mikrotik PHP API - php

Currently I am working on a web application developed for ISPs. I am using Mikrotik PHP API to create firewall connections logs. I am adding all entries into the MySql database. Everything is OK when I use this script on my Windows-based XAMPP server on my laptop but when I upload this script of Ubuntu then it says
"This page isn’t working"... HTTP ERROR 500...
Other commands with $API->write(); working well but this command is not working:
$API->comm("/ip/firewall/connection/print");
I am using Ubuntu 16.4 on my server machine. Above mentioned command is working in XAMPP (Windows) but not working LAMP (Ubuntu 16.4).
Complete code is here:
<?php
include_once('key.php');
$mikrotik_ip = $ip;
$mikrotik_username = $user;
$mikrotik_password = $pass;
if ($API->connect($mikrotik_ip, $mikrotik_username,$mikrotik_password)) {
$log = $API->comm("/ip/firewall/connection/print");
$clog = count($log);
for($a=0;$a<=$clog;$a++){
$state = isset($log[$a]['tcp-state']) ? $log[$a]['tcp-state'] : '';
$src = $log[$a]['src-address'];
$src_rep = $log[$a]['reply-src-address'];
$dst = $log[$a]['dst-address'];
$dst_rep = $log[$a]['reply-dst-address'];
$prot = $log[$a]['protocol'];
mysqli_query($connect,"insert into cts(cts_id,src_address,reply_src_address,dst_address,reply_dst_address,protocol,tcp_state,date) values('','$src','$src_rep','$dst','$dst_rep','$prot','$state','".date("Y-m-d H:i:s")."')") or die(mysqli_error());
}
mysqli_close($connect);
}else{
echo 'Not Connected';
}
?>

Related

PHP Scraping images from bing with panther library show chrome port 9515 already in use

I am trying to to scrape images from a rss feed by passing the first 3 words i am searching on bing for images and trying to scrape the images. My code is working but i always get the error that port 9515 is already in use. I have already added code to kill the port but its not working please help me out. I took reference from this url to build my code https://www.thoughtfulcode.com/php-web-scraping/./ Please help me out.
Code
include ('vendor/autoload.php');
error_reporting(E_ERROR | E_PARSE);
$url="https://timesofindia.indiatimes.com/rssfeedstopstories.cms";
$xml = simplexml_load_file($url);
$array = json_decode(json_encode($xml), true);
$description=array();
$i_size=sizeof($array['channel']['item'])-1;
for($i=0;$i<sizeof($array['channel']['item']);$i++){
$title=$array['channel']['item'][$i]['title'];
$keyword_array=explode(" ",$title);
$keyword=$keyword_array[0].' '.$keyword_array[1].' '.$keyword_array[2];
download_feed_image($keyword);
if($i_size==$i){
echo "done";
}
}
function download_feed_image($keyword){
try {
$client = \Symfony\Component\Panther\Client::createChromeClient();
$crawler = $client->request('GET', 'https://www.bing.com/images/search?q='.$keyword.'&form=HDRSC2&first=1&cw=1349&ch=657');
$fullPageHtml = $crawler->html();
$pageH1 = $crawler->filter('.iusc')->attr('href');
$img_tag=null;
parse_str($pageH1,$img_tag);
$file_name = basename($img_tag['mediaurl']);
file_put_contents( $file_name,file_get_contents($img_tag['mediaurl']));
} catch (Exception $e) {
echo $e->getMessage();
} finally {
$client->quit();
}
exec("kill -9 $(lsof -t -i:9515)");
}
Just restart computer help to kill Chrome browser instance or
if you use Ubuntu type in terminal pkill chrome
$client->quit();
Not works when Browser is busy and not answered :(
Before you quit from Chrome browser you need to delete temporary data
$client->close();
$client->quit();
P.s. You can see Chrome browser status here
http://127.0.0.1:9515/status

PHP - How would i scan a specific UDP Port to see if my game server is online or not

i recently got back into php! I have been trying to get this to work but i just can't seem to get it :(
So, i am trying to check to see if a UDP port (the port i am using for my game server is running or not) it says "Online" but it stays online even when i turn the server off :( can someone explain to me what is going and correct me? thanks!
<?php
$host = '47.39.46.24';
$port = 14242;
$waitTimeoutInSeconds = 7;
if($fp = fsockopen("udp://".$host,$port,$errCode,$errStr))
{
$write = fwrite($fp,"x00");
if (!$write)
{
echo 'offline';
}
else
{
echo 'online';
}
}
else
{
echo 'offline';
}
fclose($fp);
?>
And before you say i shouldn't be giving my ip don't worry it isn't real :D

Request does not work on live host, but does work locally

I'm trying to get records from a server using PHP. When I run the code below using XAMPP, it works without any issue. However, when I upload the code to my web host (infinityfree), the request no longer works. The error I receive is Server is offline.
Please see my code below:
try
{
$rQuery = new QueryServer( $serverIP, $serverPort );
$aInformation = $rQuery->GetInfo( );
$aServerRules = $rQuery->GetRules( );
$aBasicPlayer = $rQuery->GetPlayers( );
$aTotalPlayers = $rQuery->GetDetailedPlayers( );
$rQuery->Close( );
}
catch (QueryServerException $pError)
{
echo 'Server is offline';
}
Any help is appreciated.

Query Remote Windows Service through PHP

The following PHP win32_query_service_status works for querying the local machine, however we are attempting to perform this query on a remote machine within the same domain. We receive no errors however nothing is returned ideas?
$name = "spooler"
$machine = "remotemachine"
$status=win32_query_service_status($name, $machine);
echo "$name service is ";
if ($status["CurrentState"]==1) {echo "Stopped";}
else
if ($status["CurrentState"]==2) {echo "Starting";}
else
if ($status["CurrentState"]==3) {echo "Stopping";}
else
if ($status["CurrentState"]==4) {echo "Running";}

Create google GCM testing app in emulator and get registration id using PHP

I'm trying to create a testing app which will run at emulator and the GCM server will use PHP.
I'm looking the code how it pushes the message to target device, the following code I downloaded somewhere:
<?php
$json = array();
$regId = $_GET["regID"];
$msg = $_GET["msg"];
if (isset($regId) && isset($msg)) {
require_once("GCM.php");
$message = array("message" => $msg);
$regId = explode(",", $regId);
$result = gcm_push_notification($regId, $message);
$success_code = json_decode($result,true)["success"];
if($success_code > 0){
//echo $result; //
echo $success_code."/".count($regId); //
}else{
echo "error";
}
} else {
echo "error";
}
?>
The code every time will need "registration id"s to send a message:
I am wondering how can I get all registration ids every time before
sending a message?
And if I create a simple app which will run at emulator only, will it generate a registration id? How do I get that?
You could create a database and store all the registration id's in the server. And emulators can generate GCM ID. Make sure you set your emulator target to Google API.
If your emulator is running Android 4.0 and below, add an Google account to your emulator.

Categories