Page 2 of 2

Re: Telegram Notification IF LAN IP CHANGED

Posted: Sunday 25 December 2016 23:35
by ropske
i have made a php file called version.php

Code: Select all

<?php

phpinfo();

?>
and this works, so php is working

Re: Telegram Notification IF LAN IP CHANGED

Posted: Monday 26 December 2016 0:26
by ropske
my token is correctly and userid also, because when i enter this
https://api.telegram.org/123456789/send ... 9&text=wie ben jij

then i'm receiving this on my telegram bot

can someone show me maybe how to use this telegram.php ?

thanks

Re: Telegram Notification IF LAN IP CHANGED

Posted: Monday 26 December 2016 1:49
by sincze
ropske wrote:will it also work with:
PHP Version
5.5.22

?
i have this one installed in my nas and if i want to run the telegram.php
i'm getting this error:

HTTP 500-fout
Dat is vreemd... deze pagina kan niet worden weergegeven door de website
seems something is wrong with your .php file, you might want to check the source vice php checker??
to see if you might have a typo.
http://phpcodechecker.com/

Re: Telegram Notification IF LAN IP CHANGED

Posted: Monday 26 December 2016 10:38
by ropske
i just copied the code from you:

Code: Select all

#!/usr/bin/php
<?php error_reporting(E_ALL);ini_set("display_errors","on");
$silent=true;$type=NULL;$to=NULL;
if(isset($_REQUEST['silent']))$silent=$_REQUEST['silent'];
if(isset($_REQUEST['text'])){$type='text';$content=$_REQUEST['text'];}
if(isset($_REQUEST['photo'])){$type='photo';$content=$_REQUEST['photo'];}
if(isset($_REQUEST['video'])){$type='video';$content=$_REQUEST['video'];$silent=true;}
if(isset($_REQUEST['to']))$to=$_REQUEST['to'];
if($to=='Wife')$telegramchatid=12345678;
elseif($to=='channel')$telegramchatid=-1234567890123;
else $telegramchatid=87654321;
if(!empty($argv[1])&&!empty($argv[2])){$type=$argv[1];$content=$argv[2];}
if(!empty($argv[1])&&$argv[1]=="snapshot") {$type='photo';$content = "/run/pikrellcam/mjpeg.jpg";$silent=true;}
if(isset($type)&&isset($content)){
    $bot_url="https://api.telegram.org/bot123592115:A2EZ-xCRhO-RBf2qICiJs8q2A_2YIr1irxI/";
    if($type=="text"){$url=$bot_url."sendMessage?chat_id=".$telegramchatid;$post_fields=array('chat_id'=>$telegramchatid,'text'=>$content,'disable_notification'=>$silent);}
    elseif($type=="photo"){$url=$bot_url."sendPhoto?chat_id=".$telegramchatid;$post_fields=array('chat_id'=>$telegramchatid,'photo'=>new CURLFile(realpath($content)),'disable_notification'=>true);}
    elseif($type=="video"){$url=$bot_url."sendVideo?chat_id=".$telegramchatid;$post_fields=array('chat_id'=>$telegramchatid,'video'=>new CURLFile(realpath($content)),'disable_notification'=>true);}
    $ch=curl_init();curl_setopt($ch,CURLOPT_HTTPHEADER,array("Content-Type:multipart/form-data"));curl_setopt($ch,CURLOPT_URL,$url);curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch,CURLOPT_POSTFIELDS,$post_fields);
    for($x=1;$x<=100;$x++){
        $result=json_decode(curl_exec($ch),true);
        if($result['ok']===true)break;
        sleep($x*3);
    }
}
 
but when i enter this in http://phpcodechecker.com/ i'm getting indeed some errors.

PHP Syntax Check: Parse error: syntax error, unexpected '$telegramchatid' (T_VARIABLE) in your code on line 10
else $telegramchatid=123456789;
PHP Syntax Check: Errors parsing your code

when i change to this:
else ($telegramchatid=123456789);
it's ok, but then the next error comes...

Re: Telegram Notification IF LAN IP CHANGED

Posted: Monday 26 December 2016 11:05
by sincze
ropske wrote:i just copied the code from you:

but when i enter this in http://phpcodechecker.com/ i'm getting indeed some errors.

PHP Syntax Check: Parse error: syntax error, unexpected '$telegramchatid' (T_VARIABLE) in your code on line 10
else $telegramchatid=123456789;
PHP Syntax Check: Errors parsing your code

when i change to this:
else ($telegramchatid=123456789);
it's ok, but then the next error comes...
A well I had to modify that code a bit as well to have it work without any problems on my setup. This is my telegram.php. Credits ofcourse go to the original writer :D

Code: Select all

#!/usr/bin/php
<?php
error_reporting(E_ALL);ini_set("display_errors", "on");
$silent=false;$type='';
if(isset($_REQUEST['silent'])) $silent = $_REQUEST['silent'];
if(isset($_REQUEST['text'])) {$type='text';$content = $_REQUEST['text'];}
if(isset($_REQUEST['photo'])) {$type='photo';$content = $_REQUEST['photo'];}
if(isset($_REQUEST['video'])) {$type='video';$content = $_REQUEST['video'];$silent=true;}
if(!empty($argv[1])&&!empty($argv[2])) {$type=$argv[1];$content = $argv[2];}
//if(!empty($argv[1])&&$argv[1]=="snapshot") {$type='photo';$content = "/var/tmp/snapshot1.jpg";$silent=true;}
echo '<pre>REQUEST=';print_r($_REQUEST);echo '</pre>';

if(isset($type)&&isset($content)) {

	echo 'Type = '.$type.'<br/>Content = '.$content.'<br/>';
	
	$telegrambot='123456789:AA_______________________________poQ';
	$telegramchatid=-1111222233334;
	
	$bot_url    = "https://api.telegram.org/bot$telegrambot/";
	
	if($type=="text") {
		$url        = $bot_url . "sendMessage?chat_id=" . $telegramchatid ;
		$post_fields = array('chat_id'   => $telegramchatid,
			'text'     => $content,
			'disable_notification' => $silent
		);
	}
	else if($type=="photo") {
		$url        = $bot_url . "sendPhoto?chat_id=" . $telegramchatid ;
		$post_fields = array('chat_id'   => $telegramchatid,
			'photo'     => new CURLFile(realpath($content)),
			'disable_notification' => true
		);
	}
	else if($type=="video") {
		$url        = $bot_url . "sendVideo?chat_id=" . $telegramchatid ;
		$post_fields = array('chat_id'   => $telegramchatid,
			'video'     => new CURLFile(realpath($content)),
			'disable_notification' => true
		);
	}
	//echo 'URL = '.$url.'<br/>';
	//echo '<pre>post_fields=';print_r($post_fields);echo '</pre>';
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_HTTPHEADER, array(
			"Content-Type:multipart/form-data"
		));
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
		$output = json_decode(curl_exec($ch),true);
		
	//echo '<pre>Output=';print_r($output);echo '</pre>';



}
The problem I had was with line

Code: Select all

//if(!empty($argv[1])&&$argv[1]=="snapshot") {$type='photo';$content = "/var/tmp/snapshot1.jpg";$silent=true;}
Had to comment that out of the way. This code will compile without errors on PHP Code Checker.

Re: Telegram Notification IF LAN IP CHANGED

Posted: Monday 26 December 2016 11:13
by ropske

Re: Telegram Notification IF LAN IP CHANGED

Posted: Monday 26 December 2016 11:25
by ropske
because it's still not working :(

Re: Telegram Notification IF LAN IP CHANGED

Posted: Monday 26 December 2016 12:09
by sincze
ropske wrote:because it's still not working :(
assuming you configured your webserver correctly (mine is running on default port 80 not 5000) the command would be:

Code: Select all

http://192.168.2.10/php/telegram.php?text=Reboot_MQX
as you can see my telegram.php is not located in the root of the www directory of the webserver, but in sub directory called php.
good luck. you now have all the pieces :D

Re: Telegram Notification IF LAN IP CHANGED

Posted: Monday 26 December 2016 12:27
by ropske
i cannot change my port :(
i have a zyxell nas 540
maybe it is something at my nas-server i need to setup.
i better bought a synology it seems

Re: Telegram Notification IF LAN IP CHANGED

Posted: Monday 26 December 2016 12:31
by sincze
ropske wrote:i cannot change my port :(
i have a zyxell nas 540
maybe it is something at my nas-server i need to setup.
i better bought a synology it seems
I don't use synology for this.
Any webserver will do. APACHE / NGINX.

Re: Telegram Notification IF LAN IP CHANGED

Posted: Monday 26 December 2016 18:14
by ropske
lol, seems this 'section' on my nas is not supporting php
need to check how to activate it on published sites