mirror of
				https://github.com/ShaYmez/FreeSTAR-Status-Engine.git
				synced 2025-11-04 04:30:22 -05:00 
			
		
		
		
	login and logout with telegram
This commit is contained in:
		
							parent
							
								
									65f6de7289
								
							
						
					
					
						commit
						c96cc6e1c5
					
				
							
								
								
									
										12
									
								
								check.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								check.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					require_once("config.php");
 | 
				
			||||||
 | 
					require_once("telegram.php");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					try {
 | 
				
			||||||
 | 
						$auth_data = checkTelegramAuthorization($_GET);
 | 
				
			||||||
 | 
						saveTelegramUserData($auth_data);
 | 
				
			||||||
 | 
					  } catch (Exception $e) {
 | 
				
			||||||
 | 
						die ($e->getMessage());
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  header('Location: index.php');
 | 
				
			||||||
 | 
					  ?>
 | 
				
			||||||
@ -21,6 +21,12 @@ if (isset($_GET['ajax']))
 | 
				
			|||||||
  $offset = $_GET['offset'];
 | 
					  $offset = $_GET['offset'];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if (isset($_GET['subscriber_logout'])){
 | 
				
			||||||
 | 
					  setcookie('tg_user', '');
 | 
				
			||||||
 | 
						setcookie('referer', '', time() - 3600);
 | 
				
			||||||
 | 
					  header('Location: index.php');
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Template::render_header("Status");
 | 
					Template::render_header("Status");
 | 
				
			||||||
?>
 | 
					?>
 | 
				
			||||||
    <div class="text-center">
 | 
					    <div class="text-center">
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										44
									
								
								telegram.php
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								telegram.php
									
									
									
									
									
								
							@ -18,4 +18,46 @@ function getTelegramUserData() {
 | 
				
			|||||||
		return $auth_data;
 | 
							return $auth_data;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return false;
 | 
						return false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					/** 
 | 
				
			||||||
 | 
					 * Check if data is from telegram
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * This checks if the data provides is from telegram. It includes a Fix for firefox
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * @param mixed $auth_data The Authentication Data
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * @return $auth_data
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					function checkTelegramAuthorization($auth_data) {
 | 
				
			||||||
 | 
						$check_hash = $auth_data['hash'];
 | 
				
			||||||
 | 
						unset($auth_data['hash']);
 | 
				
			||||||
 | 
						$data_check_arr = [];
 | 
				
			||||||
 | 
						foreach ($auth_data as $key => $value) {
 | 
				
			||||||
 | 
						 // $data_check_arr[] = $key . '=' . $value;
 | 
				
			||||||
 | 
						  $data_check_arr[] = $key . '=' . str_replace('https:/t', 'https://t', $value);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						sort($data_check_arr);
 | 
				
			||||||
 | 
						$data_check_string = implode("\n", $data_check_arr);
 | 
				
			||||||
 | 
						$secret_key = hash('sha256', TG_BOT_API_TOKEN, true);
 | 
				
			||||||
 | 
						$hash = hash_hmac('sha256', $data_check_string, $secret_key);
 | 
				
			||||||
 | 
						if (strcmp($hash, $check_hash) !== 0) {
 | 
				
			||||||
 | 
						  throw new Exception('Data is NOT from Telegram');
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if ((time() - $auth_data['auth_date']) > 86400) {
 | 
				
			||||||
 | 
						  throw new Exception('Data is outdated');
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return $auth_data;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Save telegram userdata
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * Save the telegram user data in a cookie
 | 
				
			||||||
 | 
					 *  @return void
 | 
				
			||||||
 | 
					 */  
 | 
				
			||||||
 | 
					function saveTelegramUserData($auth_data) {
 | 
				
			||||||
 | 
						$auth_data_json = json_encode($auth_data);
 | 
				
			||||||
 | 
						setcookie('tg_user', $auth_data_json);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
							
								
								
									
										12
									
								
								template.php
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								template.php
									
									
									
									
									
								
							@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					<<<<<<< HEAD
 | 
				
			||||||
<?php 
 | 
					<?php 
 | 
				
			||||||
//This should later be translatable, maybe find a better solution?
 | 
					//This should later be translatable, maybe find a better solution?
 | 
				
			||||||
//This is here for better generation of POT files :)
 | 
					//This is here for better generation of POT files :)
 | 
				
			||||||
@ -8,6 +9,8 @@ $some = array(_("Some systems are experiencing major outages"), _("Some systems
 | 
				
			|||||||
$all = array(_("Our systems are experiencing major outages."), _("Our systems are experiencing minor outages"), _("Our systems are under maintenance"), _("All systems operational"));
 | 
					$all = array(_("Our systems are experiencing major outages."), _("Our systems are experiencing minor outages"), _("Our systems are under maintenance"), _("All systems operational"));
 | 
				
			||||||
$permissions = array(_("Super admin"), _("Admin"), _("Editor"));
 | 
					$permissions = array(_("Super admin"), _("Admin"), _("Editor"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					require_once("telegram.php"); 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
* Class that encapsulates methods to render header and footer
 | 
					* Class that encapsulates methods to render header and footer
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
@ -64,7 +67,14 @@ class Template{
 | 
				
			|||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <div class="navbar-collapse collapse navbar-right navbar-admin">
 | 
					            <div class="navbar-collapse collapse navbar-right navbar-admin">
 | 
				
			||||||
              <ul class="nav navbar-nav">
 | 
					              <ul class="nav navbar-nav">
 | 
				
			||||||
                <li><a href="#"><script async src="https://telegram.org/js/telegram-widget.js?4" data-telegram-login="jhuesserstatusbot" data-size="small" data-userpic="false" data-auth-url="https://status.jhuesser.ch/check.php" data-request-access="write"></script></a></li>
 | 
					              <?php
 | 
				
			||||||
 | 
					              $tg_user = getTelegramUserData();
 | 
				
			||||||
 | 
					              if($tg_user !== false){
 | 
				
			||||||
 | 
					                  echo '<li><a href="https://status.jhuesser.ch/index.php?subscriber_logout=1">Logout</a></li>';
 | 
				
			||||||
 | 
					              } else {
 | 
				
			||||||
 | 
					                echo '<li><a href="#"><script async src="https://telegram.org/js/telegram-widget.js?4" data-telegram-login="jhuesserstatusbot" data-size="small" data-userpic="false" data-auth-url="https://status.jhuesser.ch/check.php" data-request-access="write"></script></a></li>';
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					              ?>
 | 
				
			||||||
              </ul>
 | 
					              </ul>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <!--/.nav-collapse -->
 | 
					            <!--/.nav-collapse -->
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user