Skip to content

Commit

Permalink
added notifications via telegram bot
Browse files Browse the repository at this point in the history
  • Loading branch information
damianofalcioni committed Sep 25, 2024
1 parent dd13b87 commit 9c836c9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 26 deletions.
51 changes: 27 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ who visualize the image or open the links.
- Possibility to stop and start the tracking at any time
- Possibility to hide the Dashboard and protect its access with a password
- Live tracking reports from the Dashboard
- Tracking reports live delivered to a configurable mail address
- Tracking reports live delivered to a configurable mail address and telegram chat
- Different IP analysis services
- User-Agent analysis service
- Integrate URL shortening service
Expand All @@ -32,39 +32,42 @@ Give it a try!

## Getting Started
#### Deploy IP-Biter
0) Copy ipb.php in your PHP server and optionally create a .htaccess file as described in the next security notes
- Some configurable parameters are available in the firsts uncommented PHP lines of the ipb.php file, identified by the comment "START CONFIGURATION SECTION"
0) Copy ipb.php in your PHP server and optionally create a .htaccess file as described in the next security notes.
- Some configurable parameters are available in the firsts uncommented PHP lines of the ipb.php file, identified by the comment "START CONFIGURATION SECTION".
#### Access the Dashboard
1) Access the dashboard through ipb.php?op=$dashboardPage (replacing $dashboardPage with its effective value)
- $dashboardPage is the PHP variable defined in the "START CONFIGURATION SECTION" of the ipb.php file. The default value is "dashboard" so the default URL is `ipb.php?op=dashboard`
- If the PHP variable $dashboardPage is empty you can access the dashboard through the URL `ipb.php`
- If the PHP variable $dashboardPageSecret is not empty then a login page will appear, asking for the $dashboardPageSecret value
1) Access the dashboard through ipb.php?op=$dashboardPage (replacing $dashboardPage with its effective value).
- $dashboardPage is the PHP variable defined in the "START CONFIGURATION SECTION" of the ipb.php file. The default value is "dashboard" so the default URL is `ipb.php?op=dashboard`.
- If the PHP variable $dashboardPage is empty you can access the dashboard through the URL `ipb.php`.
- If the PHP variable $dashboardPageSecret is not empty then a login page will appear, asking for the $dashboardPageSecret value.
#### Create a new configuration
2) When the dashboard is opened without parameters, a new configuration is created
- Another empty new configuration can be generate clicking the "New" button
3) Configure the tracking image and the advanced setting if needed
2) When the dashboard is opened without parameters, a new configuration is created.
- Another empty new configuration can be generate clicking the "New" button.
3) Optionally provide mails and Telegram Bot token and chat id where you want to be notified.
- Telegram Note: To obtain a token, create a Telegram Bot following the instructions under [https://core.telegram.org/bots/features#botfather](https://core.telegram.org/bots/features#botfather).
- Telegram Note: To obtain a chat id, start a new chat with your bot, then open `https://api.telegram.org/bot<token>/getUpdates` replacing `<token>` with your bot token, then you will find your chat id under result/message/chat/id of the returned JSON.
4) Configure the tracking image and the advanced setting if needed.
- It is possible to left the original image url empty. In this case an empty image will be used.
4) Add tracking links if needed
5) Add tracking links if needed.
- It is possible to left the original link empty. In this case the link will generate a 404 page.
5) **Save the configuration**
6) Distribute the generated image or the links to start the tracking
- You can click the copy button and paste in a html rich email editor like gmail
- NOTE: If you try to open the generated image or links but have in the same browser the dashboard page opened and loaded, your request will not be tracked (self-tracking prevention feature)
6) **Save the configuration**
7) Distribute the generated image or the links to start the tracking.
- You can click the copy button and paste in a html rich email editor like gmail.
- NOTE: If you try to open the generated image or links but have in the same browser the dashboard page opened and loaded, your request will not be tracked (self-tracking prevention feature).

#### Load an existing configuration
7) When the dashboard is opened with the parameter "uuid", the associated configuration is loaded
- Another configuration can be loaded pasting the "Track UUID" in the dashboard relative field and clicking the "Load" button
8) The reports will be automatically visualized in the "Tracking Reports" section of the dashboard
8) When the dashboard is opened with the parameter "uuid", the associated configuration is loaded.
- Another configuration can be loaded pasting the "Track UUID" in the dashboard relative field and clicking the "Load" button,
9) The reports will be automatically visualized in the "Tracking Reports" section of the dashboard.

## Admin Overview Page
1) Access the Admin page through ipb.php?op=$adminPage (replacing $adminPage with its effective value)
- $adminPage is the PHP variable defined in the "START CONFIGURATION SECTION" of the ipb.php file. The default value is "admin" so the default URL is `ipb.php?op=admin`
- If the PHP variable $adminPage is empty the admin page will be not available
- If the PHP variable $adminPageSecret is not empty then a login page will appear, asking for the $adminPageSecret value
1) Access the Admin page through ipb.php?op=$adminPage (replacing $adminPage with its effective value).
- $adminPage is the PHP variable defined in the "START CONFIGURATION SECTION" of the ipb.php file. The default value is "admin" so the default URL is `ipb.php?op=admin`.
- If the PHP variable $adminPage is empty the admin page will be not available.
- If the PHP variable $adminPageSecret is not empty then a login page will appear, asking for the $adminPageSecret value.
2) All the defined configuration will be visualized in a table.

## Security Notes
- Change the folders name and the dashboard page in the configuration section in order to improve the security
- Change the folders name and the dashboard page in the configuration section in order to improve the security.
- Add the following lines to the .htaccess file in order to deny the access to the "configs" and "reports" folders:
```
DirectoryIndex ipb.php
Expand All @@ -82,7 +85,7 @@ From this url you are not able to access the relative dashboard.
Did not trust me?
Try to hack it as a challange and report me your success; you will be rewarded with a coffee <3
-->
Have a look at the [DEMO](https://damianofalcioni.alwaysdata.net/ipb.php?op=l&tid=4a33afe3-2a49-455f-b1a1-19e28aa12faf&lid=f2d41e3b-da57-4efb-8490-e0678d5090d2)
Have a look at the [DEMO](https://damianofalcioni.alwaysdata.net/ipb.php?op=l&tid=4a33afe3-2a49-455f-b1a1-19e28aa12faf&lid=f2d41e3b-da57-4efb-8490-e0678d5090d2).

## Support Me <3
<!--
Expand Down
31 changes: 29 additions & 2 deletions ipb.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
- Possibility to stop and start the tracking at any time
- Possibility to hide the Dashboard and protect its access with a password
- Live tracking reports from the Dashboard
- Tracking reports live delivered to a configurable mail address
- Tracking reports live delivered to a configurable mail address and telegram chat
- Different IP analysis services
- User-Agent analysis service
- Integrate URL shortening service
Expand All @@ -77,7 +77,9 @@
#### Create a new configuration
2) When the dashboard is opened without parameters, a new configuration is created.
- Another empty new configuration can be generate clicking the "New" button.
3) Optionally provide mails where you want to be notified.
3) Optionally provide mails and Telegram Bot token and chat id where you want to be notified.
- Telegram Note: To obtain a token, create a Telegram Bot following the instructions under [https://core.telegram.org/bots/features#botfather](https://core.telegram.org/bots/features#botfather).
- Telegram Note: To obtain a chat id, start a new chat with your bot, then open `https://api.telegram.org/bot<token>/getUpdates` replacing `<token>` with your bot token, then you will find your chat id under result/message/chat/id of the returned JSON.
4) Configure the tracking image and the advanced setting if needed.
- It is possible to left the original image url empty. In this case an empty image will be used.
5) Add tracking links if needed.
Expand Down Expand Up @@ -258,6 +260,16 @@ function sendNotifications($config, $track){
} catch(Throwable $ex) {
logError('Failed to send notification for config UUID '.$config->uuid.' : '.$ex->getMessage());
}
try {
if(isset($config->telegramToken) && $config->telegramToken!='' && isset($config->telegramChatId) && $config->telegramChatId!=''){
$notificationText = str_replace('localhost', '127.0.0.1', $notificationText); //Telegram bug: localhost not parsed
$telegramSent = req('https://api.telegram.org/bot'.$config->telegramToken.'/sendMessage', json_encode(array('chat_id'=>$config->telegramChatId, 'parse_mode'=>'html', 'text'=>'[Tracking Live Report] '.$config->mailId."\n".$notificationText)), 'application/json');
if(json_decode($telegramSent)->ok === false)
throw new Exception('Failed to send telegram message to chat '.$config->telegramChatId.': '.$telegramSent);
}
} catch(Throwable $ex) {
logError('Failed to send notification for config UUID '.$config->uuid.' : '.$ex->getMessage());
}
}

function validateUUID($uuid) {
Expand Down Expand Up @@ -344,6 +356,8 @@ function validateUUID($uuid) {
$('#trackingEnabledChk').prop('checked', configJson.trackingEnabled);
$('#mailIdTxt').val(configJson.mailId);
$('#notificationMailTxt').val(configJson.notificationAddress);
$('#notificationTelegramTokenTxt').val(configJson.telegramToken);
$('#notificationTelegramChatIdTxt').val(configJson.telegramChatId);
$('#trackingImageOriginalUrlTxt').val(configJson.trackingImage).trigger('change');
$('#trackingImageHTTPStatusTxt').val(configJson.trackingImageStatusCode);
configJson.trackingImageCustomHeaderList.forEach(function(item){
Expand Down Expand Up @@ -677,6 +691,8 @@ function validateUUID($uuid) {
trackingEnabled : $('#trackingEnabledChk').is(':checked'),
mailId : $('#mailIdTxt').val(),
notificationAddress : $('#notificationMailTxt').val(),
telegramToken: $('#notificationTelegramTokenTxt').val(),
telegramChatId: $('#notificationTelegramChatIdTxt').val(),
trackingImage : $('#trackingImageOriginalUrlTxt').val(),
trackingImageStatusCode : parseInt($('#trackingImageHTTPStatusTxt').val()),
trackingImageCustomHeaderList : function(){
Expand Down Expand Up @@ -1079,6 +1095,17 @@ function validateUUID($uuid) {
</div>
</div>

<div class="row form-group">
<div class="col-lg-12">
<div class="input-group">
<span class="input-group-addon">Telegram notification bot token</span>
<input id="notificationTelegramTokenTxt" type="text" class="form-control" placeholder="Telegram Bot token that will send notifications on new tracks">
<span class="input-group-addon">Chat ID</span>
<input id="notificationTelegramChatIdTxt" type="text" class="form-control" placeholder="Telegram Chat ID to use">
</div>
</div>
</div>

<div class="panel panel-default">
<div class="panel-heading"><h4 class="panel-title">Tracking Image</h4></div>
<div class="panel-body" id="trackingImageConfigDiv">
Expand Down

0 comments on commit 9c836c9

Please sign in to comment.