backup: live-stand vor erstem git-deployment
This commit is contained in:
4
module/api/.htaccess
Normal file
4
module/api/.htaccess
Normal file
@@ -0,0 +1,4 @@
|
||||
<Files "notifications-c5c54-a9705bfea23c.json">
|
||||
Order allow,deny
|
||||
Deny from all
|
||||
</Files>
|
||||
3
module/api/app_api_domain.php
Normal file
3
module/api/app_api_domain.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
echo "true";
|
||||
?>
|
||||
0
module/api/cronjob_send_custom_notif.inc.php
Normal file
0
module/api/cronjob_send_custom_notif.inc.php
Normal file
242
module/api/cronjob_send_custom_notif.php
Normal file
242
module/api/cronjob_send_custom_notif.php
Normal file
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
function getAccessToken($jsonKeyPath)
|
||||
{
|
||||
try {
|
||||
|
||||
$jwt = generateJWT($jsonKeyPath);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, 'https://oauth2.googleapis.com/token');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
|
||||
'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
||||
'assertion' => $jwt,
|
||||
]));
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type: application/x-www-form-urlencoded',
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$jsonResponse = json_decode($response, true);
|
||||
} catch (\Throwable $th) {
|
||||
echo $th;
|
||||
}
|
||||
return $jsonResponse['access_token'];
|
||||
}
|
||||
|
||||
function generateJWT($jsonKeyPath)
|
||||
{
|
||||
$jsonKey = json_decode(file_get_contents($jsonKeyPath), true);
|
||||
|
||||
$header = base64_encode(json_encode([
|
||||
'alg' => 'RS256',
|
||||
'typ' => 'JWT',
|
||||
]));
|
||||
|
||||
$iat = time();
|
||||
$exp = $iat + 3600; // 1 час
|
||||
$claimSet = base64_encode(json_encode([
|
||||
'iss' => $jsonKey['client_email'],
|
||||
'scope' => 'https://www.googleapis.com/auth/firebase.messaging',
|
||||
'aud' => 'https://oauth2.googleapis.com/token',
|
||||
'exp' => $exp,
|
||||
'iat' => $iat,
|
||||
]));
|
||||
|
||||
$signatureInput = $header . '.' . $claimSet;
|
||||
|
||||
openssl_sign($signatureInput, $signature, openssl_pkey_get_private($jsonKey['private_key']), 'sha256');
|
||||
$signature = base64_encode($signature);
|
||||
|
||||
return $signatureInput . '.' . $signature;
|
||||
}
|
||||
|
||||
function send($token, $username, $message)
|
||||
{
|
||||
// $jsonKeyPath = '../../notifications-c5c54-a9705bfea23c.json';
|
||||
$jsonKeyPath = 'secrets/notifications-c5c54-a9705bfea23c.json';
|
||||
$accessToken = getAccessToken($jsonKeyPath);
|
||||
|
||||
$json = json_encode([
|
||||
"message" => [
|
||||
"token" => $token,
|
||||
"notification" => [
|
||||
"title" => $username,
|
||||
"body" => $message
|
||||
],
|
||||
"data" => [
|
||||
"story_id" => "story_12345",
|
||||
"badgeIncrement" => "1"
|
||||
],
|
||||
"apns" => [
|
||||
"payload" => [
|
||||
"aps" => [
|
||||
"content-available" => 1
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$url = "https://fcm.googleapis.com/v1/projects/notifications-c5c54/messages:send";
|
||||
|
||||
$ch = curl_init($url);
|
||||
|
||||
|
||||
$headers = [
|
||||
'Authorization: Bearer ' . $accessToken,
|
||||
'Content-Type: application/json; charset=UTF-8',
|
||||
];
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
$env = parse_ini_file('/var/www/web10/htdocs/intranet/config/.env');
|
||||
|
||||
$db_host = $env['MAIN_MYSQL_DB_HOST'];
|
||||
$db_port = $env['MAIN_MYSQL_DB_PORT'];
|
||||
$db_user = $env['MAIN_MYSQL_DB_USER'];
|
||||
$db_pass = $env['MAIN_MYSQL_DB_PASS'];
|
||||
$db_schema = $env['MAIN_MYSQL_DB_SCHEMA'];
|
||||
|
||||
$conn = new mysqli($db_host, $db_user, $db_pass, $db_schema, $db_port);
|
||||
|
||||
|
||||
|
||||
// Format current date to match the validity_from format (YYYY-MM-DD)
|
||||
$currDate = date('Y-m-d');
|
||||
|
||||
// Query to get all collections where validity_from matches today's date
|
||||
$query_get_all_current_collections = "SELECT * FROM main_collection WHERE delayed_notification = 1 AND validity_from = '$currDate'";
|
||||
$result_collections = $conn->query($query_get_all_current_collections);
|
||||
|
||||
if ($result_collections->num_rows > 0) {
|
||||
// Loop through each collection
|
||||
while ($row = $result_collections->fetch_assoc()) {
|
||||
|
||||
print_r($row["description"]);
|
||||
print_r($row["id"]);
|
||||
$article_name = $row["description"];
|
||||
|
||||
|
||||
echo "<br>--------------------<br>";
|
||||
|
||||
$department_ids = [];
|
||||
$role_ids = [];
|
||||
|
||||
$query_get_department = "SELECT * FROM intranet_teil_link WHERE content_type = 'collection' AND content_id = " . $row['id'];
|
||||
$result_department = $conn->query($query_get_department);
|
||||
|
||||
while ($row_department = $result_department->fetch_assoc()) {
|
||||
$department_ids[] = $row_department['main_department_id'];
|
||||
var_dump($row_department);
|
||||
}
|
||||
|
||||
echo "<br>--------------------<br>";
|
||||
|
||||
$query_get_role = "SELECT * FROM intranet_role_link WHERE content_type = 'collection' AND content_id = " . $row['id'];
|
||||
$result_role = $conn->query($query_get_role);
|
||||
|
||||
while ($row_role = $result_role->fetch_assoc()) {
|
||||
$role_ids[] = $row_role['main_role_id'];
|
||||
var_dump($row_role);
|
||||
}
|
||||
|
||||
// Create comma-separated strings
|
||||
$abteilung = implode(',', $department_ids);
|
||||
$role = implode(',', $role_ids);
|
||||
|
||||
$abteilungArray = explode(',', $abteilung);
|
||||
$roleArray = explode(',', $role);
|
||||
|
||||
$mergedArray = [];
|
||||
|
||||
foreach ($abteilungArray as $abteilung) {
|
||||
foreach ($roleArray as $role) {
|
||||
$mergedArray[] = [
|
||||
'abteilung' => $abteilung,
|
||||
'role' => $role
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$tokenArray = [];
|
||||
// print_r($mergedArray);
|
||||
// print_r($abteilungArray);
|
||||
// print_r($roleArray);
|
||||
var_dump($mergedArray);
|
||||
foreach ($mergedArray as $element) {
|
||||
|
||||
if ($element['abteilung'] == "" && $element['role'] == "") {
|
||||
|
||||
$sql = "SELECT DISTINCT main_contact_id FROM main_contact_department WHERE main_mandant_id = 1 AND active = 1";
|
||||
} else if ($element['abteilung'] == "") {
|
||||
$sql = "SELECT DISTINCT main_contact_id FROM main_contact_department WHERE main_mandant_id = 1 AND active = 1 and main_role_id = " . $element['role'];
|
||||
} else if ($element['role'] == "") {
|
||||
$sql = "SELECT DISTINCT main_contact_id FROM main_contact_department WHERE main_mandant_id = 1 AND active = 1 and main_department_id = " . $element['abteilung'];
|
||||
} else {
|
||||
$sql = "SELECT DISTINCT main_contact_id FROM main_contact_department WHERE main_mandant_id = 1 AND active = 1 and main_department_id = " . $element['abteilung'] . " and main_role_id = " . $element['role'];
|
||||
}
|
||||
// var_dump($sql);
|
||||
var_dump($sql);
|
||||
$result = $conn->query($sql);
|
||||
if ($result->num_rows > 0) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$query = "SELECT DISTINCT main_contact.id, main_contact.name, token_contact.token as 'token' FROM main_contact LEFT JOIN token_contact ON token_contact.contact_id = main_contact.id WHERE main_contact.id = '" . $row['main_contact_id'] . "'";
|
||||
// var_dump($query);
|
||||
$user_result = $conn->query($query);
|
||||
if ($user_result->num_rows > 0) {
|
||||
while ($contact = $user_result->fetch_assoc()) {
|
||||
if ($contact['token'] != null && $contact['token'] != "") {
|
||||
// send($contact['token'], "Intranet", "Neuer Beitrag im Intranet");
|
||||
$contact_info = [
|
||||
'id' => $contact['id'],
|
||||
'name' => $contact['name'],
|
||||
'token' => $contact['token']
|
||||
];
|
||||
if (!in_array($contact_info, $tokenArray, true)) {
|
||||
$tokenArray[] = $contact_info;
|
||||
|
||||
} else {
|
||||
// echo "Already in array";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// var_dump($tokenArray);
|
||||
// foreach ($tokenArray as $token) {
|
||||
// // print("würde gesendet: <br>");
|
||||
// send($token['token'], "Neuer Beitrag im Intranet", $article_name);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
} else {
|
||||
echo "No collections found for today.";
|
||||
}
|
||||
|
||||
$query = "INSERT INTO cron_jobs (name) VALUES ('send_custom_notif')";
|
||||
$result = $conn->query($query);
|
||||
|
||||
|
||||
25
module/api/getUser.php
Normal file
25
module/api/getUser.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
$userLogin = $_POST['login_api_phone'];
|
||||
$userPassword = $_POST['password_api_phone'];
|
||||
$password = md5($userPassword);
|
||||
|
||||
// echo $userLogin." ".$password;
|
||||
|
||||
$pdo = new PDO('mysql:host=localhost;dbname=web4_intranet;charset=utf8', "web4_intranet", "WewJedjuAbEynk3");
|
||||
$GLOBALS["pdo_conn"] = $pdo;
|
||||
|
||||
$noPublish = "SELECT main_contact_id AS contact_id FROM main_contact_department INNER JOIN main_contact ON main_contact_department.main_contact_id=main_contact.id WHERE main_contact.shortcut='$userLogin' AND main_contact.password='$password'";
|
||||
|
||||
|
||||
$stmt = $pdo->prepare($noPublish);
|
||||
$stmt->execute();
|
||||
|
||||
// $pp = md5($userPassword);
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($row) {
|
||||
echo $row["contact_id"];
|
||||
}else {
|
||||
echo "null";
|
||||
}
|
||||
?>
|
||||
3
module/api/isShowEvent.php
Normal file
3
module/api/isShowEvent.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
?>
|
||||
14
module/api/out_system.inc.php
Normal file
14
module/api/out_system.inc.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
$user = $_POST['user'];
|
||||
|
||||
$pdo = new PDO('mysql:host=localhost;dbname=web4_intranet;charset=utf8', "web4_intranet", "WewJedjuAbEynk3");
|
||||
$GLOBALS["pdo_conn"] = $pdo;
|
||||
|
||||
$noPublish = "UPDATE token_contact SET token_contact.in_system=0 WHERE token_contact.contact_id=$user";
|
||||
|
||||
$stmt = $pdo->prepare($noPublish);
|
||||
$stmt->execute();
|
||||
|
||||
$count = $stmt->fetchColumn();
|
||||
|
||||
?>
|
||||
16
module/api/sendTokenToDB.php
Normal file
16
module/api/sendTokenToDB.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
$token = $_POST['token'];
|
||||
$user = $_POST['user'];
|
||||
$domain = $_POST['domain'];
|
||||
|
||||
$pdo = new PDO('mysql:host=localhost;dbname=web4_intranet;charset=utf8', "web4_intranet", "WewJedjuAbEynk3");
|
||||
$GLOBALS["pdo_conn"] = $pdo;
|
||||
|
||||
$noPublish = "CALL insertToken('$token', '$user')";
|
||||
|
||||
$stmt = $pdo->prepare($noPublish);
|
||||
$stmt->execute();
|
||||
|
||||
$count = $stmt->fetchColumn();
|
||||
|
||||
?>
|
||||
228
module/api/send_custom_notif.inc.php
Normal file
228
module/api/send_custom_notif.inc.php
Normal file
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
$user = $_POST['user'];
|
||||
$title = $_POST['title'];
|
||||
$body = $_POST['body'];
|
||||
$abteilung = $_POST['abteilung'];
|
||||
$role = $_POST['role'];
|
||||
$domain = $_POST['domain'];
|
||||
$input_collection_id = $_POST['input_collection_id'];
|
||||
|
||||
|
||||
function getAccessToken($jsonKeyPath)
|
||||
{
|
||||
try {
|
||||
|
||||
$jwt = generateJWT($jsonKeyPath);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, 'https://oauth2.googleapis.com/token');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
|
||||
'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
||||
'assertion' => $jwt,
|
||||
]));
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type: application/x-www-form-urlencoded',
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$jsonResponse = json_decode($response, true);
|
||||
} catch (\Throwable $th) {
|
||||
echo $th;
|
||||
}
|
||||
return $jsonResponse['access_token'];
|
||||
}
|
||||
|
||||
function generateJWT($jsonKeyPath)
|
||||
{
|
||||
$jsonKey = json_decode(file_get_contents($jsonKeyPath), true);
|
||||
|
||||
$header = base64_encode(json_encode([
|
||||
'alg' => 'RS256',
|
||||
'typ' => 'JWT',
|
||||
]));
|
||||
|
||||
$iat = time();
|
||||
$exp = $iat + 3600; // 1 час
|
||||
$claimSet = base64_encode(json_encode([
|
||||
'iss' => $jsonKey['client_email'],
|
||||
'scope' => 'https://www.googleapis.com/auth/firebase.messaging',
|
||||
'aud' => 'https://oauth2.googleapis.com/token',
|
||||
'exp' => $exp,
|
||||
'iat' => $iat,
|
||||
]));
|
||||
|
||||
$signatureInput = $header . '.' . $claimSet;
|
||||
|
||||
openssl_sign($signatureInput, $signature, openssl_pkey_get_private($jsonKey['private_key']), 'sha256');
|
||||
$signature = base64_encode($signature);
|
||||
|
||||
return $signatureInput . '.' . $signature;
|
||||
}
|
||||
|
||||
function send($token, $username, $message)
|
||||
{
|
||||
// $jsonKeyPath = '../../notifications-c5c54-a9705bfea23c.json';
|
||||
$jsonKeyPath = 'secrets/notifications-c5c54-a9705bfea23c.json';
|
||||
$accessToken = getAccessToken($jsonKeyPath);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
{
|
||||
"message": {
|
||||
"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJzaG9ydGN1dCI6ImVhIn0.mcO9WT0VV_lXJp48mu3XF9E9bKEdCitoKogAk067LwQ",
|
||||
"notification": {
|
||||
"title": "Breaking News",
|
||||
"body": "New news story available."
|
||||
},
|
||||
"data": {
|
||||
"story_id": "story_12345"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
$json = json_encode([
|
||||
"message" => [
|
||||
"token" => $token,
|
||||
"notification" => [
|
||||
"title" => $username,
|
||||
"body" => $message
|
||||
],
|
||||
"data" => [
|
||||
"story_id" => "story_12345",
|
||||
"badgeIncrement" => "1"
|
||||
],
|
||||
"apns" => [
|
||||
"payload" => [
|
||||
"aps" => [
|
||||
"content-available" => 1
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
|
||||
|
||||
$url = "https://fcm.googleapis.com/v1/projects/notifications-c5c54/messages:send";
|
||||
|
||||
|
||||
$ch = curl_init($url);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$headers = [
|
||||
'Authorization: Bearer ' . $accessToken,
|
||||
'Content-Type: application/json; charset=UTF-8',
|
||||
];
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
$env = parse_ini_file('../../config/.env');
|
||||
|
||||
$db_host = $env['MAIN_MYSQL_DB_HOST'];
|
||||
$db_port = $env['MAIN_MYSQL_DB_PORT'];
|
||||
$db_user = $env['MAIN_MYSQL_DB_USER'];
|
||||
$db_pass = $env['MAIN_MYSQL_DB_PASS'];
|
||||
$db_schema = $env['MAIN_MYSQL_DB_SCHEMA'];
|
||||
|
||||
$conn = new mysqli($db_host, $db_user, $db_pass, $db_schema, $db_port);
|
||||
|
||||
$abteilungArray = explode(',', $abteilung);
|
||||
$roleArray = explode(',', $role);
|
||||
|
||||
$mergedArray = [];
|
||||
|
||||
foreach ($abteilungArray as $abteilung) {
|
||||
foreach ($roleArray as $role) {
|
||||
$mergedArray[] = [
|
||||
'abteilung' => $abteilung,
|
||||
'role' => $role
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$query_collection_name = "SELECT * FROM main_collection WHERE id = " . $input_collection_id;
|
||||
$result = $conn->query($query_collection_name);
|
||||
if ($result->num_rows > 0) {
|
||||
$row = $result->fetch_assoc();
|
||||
$collection_name = $row['description'];
|
||||
} else {
|
||||
echo "collection not found";
|
||||
die();
|
||||
}
|
||||
|
||||
$tokenArray = [];
|
||||
// print_r($mergedArray);
|
||||
// print_r($abteilungArray);
|
||||
// print_r($roleArray);
|
||||
foreach ($mergedArray as $element) {
|
||||
// $sql = "SELECT DISTINCT main_contact_id FROM main_contact_department WHERE main_mandant_id = 1 AND active = 1 and main_department_id = " . $element['abteilung'] . " and main_role_id = " . $element['role'];
|
||||
// var_dump($sql);
|
||||
if ($element['abteilung'] == "" && $element['role'] == "") {
|
||||
|
||||
$sql = "SELECT DISTINCT main_contact_id FROM main_contact_department WHERE main_mandant_id = 1 AND active = 1";
|
||||
} else if ($element['abteilung'] == "") {
|
||||
$sql = "SELECT DISTINCT main_contact_id FROM main_contact_department WHERE main_mandant_id = 1 AND active = 1 and main_role_id = " . $element['role'];
|
||||
} else if ($element['role'] == "") {
|
||||
$sql = "SELECT DISTINCT main_contact_id FROM main_contact_department WHERE main_mandant_id = 1 AND active = 1 and main_department_id = " . $element['abteilung'];
|
||||
} else {
|
||||
$sql = "SELECT DISTINCT main_contact_id FROM main_contact_department WHERE main_mandant_id = 1 AND active = 1 and main_department_id = " . $element['abteilung'] . " and main_role_id = " . $element['role'];
|
||||
}
|
||||
$result = $conn->query($sql);
|
||||
if ($result->num_rows > 0) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$query = "SELECT DISTINCT main_contact.id, main_contact.name, token_contact.token as 'token' FROM main_contact LEFT JOIN token_contact ON token_contact.contact_id = main_contact.id WHERE main_contact.id = '" . $row['main_contact_id'] . "'";
|
||||
// var_dump($query);
|
||||
$user_result = $conn->query($query);
|
||||
if ($user_result->num_rows > 0) {
|
||||
while ($contact = $user_result->fetch_assoc()) {
|
||||
if ($contact['token'] != null && $contact['token'] != "") {
|
||||
// send($contact['token'], "Intranet", "Neuer Beitrag im Intranet");
|
||||
$contact_info = [
|
||||
'id' => $contact['id'],
|
||||
'name' => $contact['name'],
|
||||
'token' => $contact['token']
|
||||
];
|
||||
if (!in_array($contact_info, $tokenArray, true)) {
|
||||
$tokenArray[] = $contact_info;
|
||||
} else {
|
||||
// echo "Already in array";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($tokenArray as $token) {
|
||||
send($token['token'], "Neuer Beitrag im Intranet", $collection_name);
|
||||
}
|
||||
|
||||
// send("cyO6CxjDS5S7fz5DX1vA95:APA91bGxyA0ai9h1oCt4vrEmfYu0Ics1uX8kxfWNztYgQF1oQgLD-Nql7dM88LfudccwCA3vKM7cQldqOfffbRv-9v_79B7bmnhlFOZUsEsaZVpqWoHaOEyTw7bYo6VY8aC00GGwv_M1", "Test breadcrumb", "Test message");
|
||||
215
module/api/send_notif.inc.php
Normal file
215
module/api/send_notif.inc.php
Normal file
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
$user = $_POST['user'];
|
||||
$title = $_POST['title'];
|
||||
$body = $_POST['body'];
|
||||
$domain = $_POST['domain'];
|
||||
|
||||
|
||||
$news_id = $_POST["news_id"];
|
||||
|
||||
|
||||
function getAccessToken($jsonKeyPath)
|
||||
{
|
||||
try {
|
||||
|
||||
$jwt = generateJWT($jsonKeyPath);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, 'https://oauth2.googleapis.com/token');
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
|
||||
'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
|
||||
'assertion' => $jwt,
|
||||
]));
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type: application/x-www-form-urlencoded',
|
||||
]);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
$jsonResponse = json_decode($response, true);
|
||||
} catch (\Throwable $th) {
|
||||
echo $th;
|
||||
}
|
||||
return $jsonResponse['access_token'];
|
||||
}
|
||||
|
||||
function generateJWT($jsonKeyPath)
|
||||
{
|
||||
$jsonKey = json_decode(file_get_contents($jsonKeyPath), true);
|
||||
|
||||
$header = base64_encode(json_encode([
|
||||
'alg' => 'RS256',
|
||||
'typ' => 'JWT',
|
||||
]));
|
||||
|
||||
$iat = time();
|
||||
$exp = $iat + 3600; // 1 час
|
||||
$claimSet = base64_encode(json_encode([
|
||||
'iss' => $jsonKey['client_email'],
|
||||
'scope' => 'https://www.googleapis.com/auth/firebase.messaging',
|
||||
'aud' => 'https://oauth2.googleapis.com/token',
|
||||
'exp' => $exp,
|
||||
'iat' => $iat,
|
||||
]));
|
||||
|
||||
$signatureInput = $header . '.' . $claimSet;
|
||||
|
||||
openssl_sign($signatureInput, $signature, openssl_pkey_get_private($jsonKey['private_key']), 'sha256');
|
||||
$signature = base64_encode($signature);
|
||||
|
||||
return $signatureInput . '.' . $signature;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// $jsonKeyPath = '../../notifications-c5c54-a9705bfea23c.json';
|
||||
$jsonKeyPath = 'secrets/notifications-c5c54-a9705bfea23c.json';
|
||||
|
||||
|
||||
$accessToken = getAccessToken($jsonKeyPath);
|
||||
|
||||
|
||||
|
||||
$url = 'https://fcm.googleapis.com/v1/projects/notifications-c5c54/messages:send';
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
|
||||
|
||||
|
||||
|
||||
// HERE NEW LOGIC
|
||||
// GET ALl MANDANTS FROM NEWS ID
|
||||
$mysql_con = new mysqli("localhost", "web4_intranet", "WewJedjuAbEynk3", "web4_intranet");
|
||||
|
||||
$allowed_contact_ids = [];
|
||||
|
||||
$all_mandants_query = "SELECT main_mandant_id FROM `main_collection_mandant_link` WHERE main_collection_id = " . (int) $news_id;
|
||||
$sql_all_mandants = @mysqli_query($mysql_con, $all_mandants_query);
|
||||
while ($row = @mysqli_fetch_assoc($sql_all_mandants)) {
|
||||
$all_mandants[] = $row["main_mandant_id"];
|
||||
}
|
||||
|
||||
$all_departments_query = "SELECT main_department_id FROM `main_collection_department_link` WHERE main_collection_id = " . (int) $news_id;
|
||||
$sql_all_departments = @mysqli_query($mysql_con, $all_departments_query);
|
||||
while ($row = @mysqli_fetch_assoc($sql_all_departments)) {
|
||||
$all_departments[] = $row["main_department_id"];
|
||||
}
|
||||
|
||||
$all_fachbereich_query = "SELECT main_fachbereich_id FROM `main_collection_fachbereich_link` WHERE main_collection_id = " . (int) $news_id;
|
||||
$sql_all_fachbereichs = @mysqli_query($mysql_con, $all_fachbereich_query);
|
||||
while ($row = @mysqli_fetch_assoc($sql_all_fachbereichs)) {
|
||||
$all_fachbereichs[] = $row["main_fachbereich_id"];
|
||||
}
|
||||
|
||||
$all_einrichtungen_query = "SELECT main_einricht_id FROM `main_collection_einricht_link` WHERE main_collection_id = " . (int) $news_id;
|
||||
$sql_all_einrichtungen = @mysqli_query($mysql_con, $all_einrichtungen_query);
|
||||
while ($row = @mysqli_fetch_assoc($sql_all_einrichtungen)) {
|
||||
$all_einrichtungen[] = $row["main_einricht_id"];
|
||||
}
|
||||
|
||||
$all_role_query = "SELECT main_role_id FROM `main_collection_role_link` WHERE main_collection_id = " . (int) $news_id;
|
||||
$sql_all_rolles = @mysqli_query($mysql_con, $all_role_query);
|
||||
while ($row = @mysqli_fetch_assoc($sql_all_rolles)) {
|
||||
$all_rolles[] = $row["main_role_id"];
|
||||
}
|
||||
|
||||
|
||||
|
||||
$query_get_all_contacts = "SELECT * FROM main_contact_department";
|
||||
$sql_get_all_contacts = @mysqli_query($mysql_con, $query_get_all_contacts);
|
||||
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql_get_all_contacts)) {
|
||||
|
||||
$count++;
|
||||
// 1. Mandant
|
||||
if (!empty($all_mandants) && !in_array($row["main_mandant_id"], $all_mandants)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 2. Department
|
||||
if (!empty($all_departments) && !in_array($row["main_department_id"], $all_departments)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($all_fachbereichs) && !in_array($row["main_bereich_id"], $all_fachbereichs)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($all_einrichtungen) && !in_array($row["main_einricht_id"], $all_einrichtungen)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($all_rolles) && !in_array($row["main_role_id"], $all_rolles)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$allowed_contact_ids[] = $row["main_contact_id"];
|
||||
}
|
||||
|
||||
$allowed_contact_ids = array_unique($allowed_contact_ids);
|
||||
|
||||
foreach ($allowed_contact_ids as $cid) {
|
||||
$query_contact_token = "SELECT * FROM token_contact WHERE contact_id = " . (int) $cid . " AND in_system = 1 ORDER BY id DESC LIMIT 1";
|
||||
$sql_contactn_token = @mysqli_query($mysql_con, $query_contact_token);
|
||||
|
||||
|
||||
while ($row_token = @mysqli_fetch_assoc($sql_contactn_token)) {
|
||||
|
||||
|
||||
$contactId = trim($row_token['contact_id'] ?? '');
|
||||
$token = trim($row_token['token'] ?? '');
|
||||
|
||||
if (
|
||||
$contactId === '' || $contactId === 'undefined' ||
|
||||
$token === '' || $token === 'undefined'
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$data = [
|
||||
'message' => [
|
||||
'token' => $row_token["token"],
|
||||
'notification' => [
|
||||
'title' => $title,
|
||||
'body' => $body,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
|
||||
|
||||
$jsonData = json_encode($data);
|
||||
|
||||
$ch = curl_init($url);
|
||||
|
||||
|
||||
$headers = [
|
||||
'Authorization: Bearer ' . $accessToken,
|
||||
'Content-Type: application/json; charset=UTF-8',
|
||||
];
|
||||
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
|
||||
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
85
module/api/testGraph.php
Normal file
85
module/api/testGraph.php
Normal file
@@ -0,0 +1,85 @@
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
$parts = parse_url("https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."");
|
||||
parse_str($parts['query'], $query);
|
||||
$code = $query['code'];
|
||||
// var_dump(getToken($code));
|
||||
$token = getToken($code);
|
||||
// $refresh_token = getToken($code)[1];
|
||||
// var_dump($token);
|
||||
$headers = [
|
||||
'Authorization: Bearer '.$token[0],
|
||||
'Content-Type: application/json'
|
||||
];
|
||||
|
||||
|
||||
$fcmUrl = 'https://graph.microsoft.com/v1.0/me';
|
||||
$cRequest = curl_init();
|
||||
curl_setopt($cRequest, CURLOPT_URL, $fcmUrl);
|
||||
curl_setopt($cRequest, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($cRequest, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($cRequest, CURLOPT_SSL_VERIFYPEER, false);
|
||||
$result = curl_exec($cRequest);
|
||||
$obj = json_decode($result);
|
||||
$email = $obj->mail;
|
||||
curl_close($cRequest);
|
||||
|
||||
$pdo = new PDO('mysql:host=localhost;dbname=dev-intranet;charset=utf8', "dev-user", "AcdinemGeor5qua");
|
||||
$GLOBALS["pdo_conn"] = $pdo;
|
||||
// echo $token."</br>".$email."</br>".$refresh_token;
|
||||
|
||||
$noPublish = "CALL insertTokenMicrosoftKey('$token[0]', '$email', '$token[1]')";
|
||||
|
||||
$stmt = $pdo->prepare($noPublish);
|
||||
$stmt->execute();
|
||||
|
||||
$count = $stmt->fetchColumn();
|
||||
|
||||
?>
|
||||
<script>
|
||||
setTimeout(() => {
|
||||
window.close();
|
||||
}, 1000);
|
||||
|
||||
</script>'
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
function getToken($code){
|
||||
$array = array();
|
||||
$headers = [
|
||||
'Content-Type: application/x-www-form-urlencoded'
|
||||
];
|
||||
$fcmUrl = 'https://login.microsoftonline.com/organizations/oauth2/v2.0/token';
|
||||
$cRequest = curl_init();
|
||||
curl_setopt($cRequest, CURLOPT_URL, $fcmUrl);
|
||||
curl_setopt($cRequest, CURLOPT_POST, true);
|
||||
curl_setopt($cRequest, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($cRequest, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($cRequest, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($cRequest, CURLOPT_POSTFIELDS, http_build_query(array(
|
||||
'client_id' => '998f5db8-f544-4dda-a10a-79eda88a5437',
|
||||
'scope' => 'openid User.ReadWrite Calendars.ReadWrite Presence.ReadWrite',
|
||||
'code' => $code,
|
||||
'redirect_uri' => 'https://dev-intranet.breadcrumb-online.de/module/api/testGraph.php',
|
||||
'grant_type' => 'authorization_code',
|
||||
'client_secret' => 'S6Z8Q~zae4D8k0mpbCtgAQrAUV5we.FxcR6LHav-'
|
||||
|
||||
)));
|
||||
$result = curl_exec($cRequest);
|
||||
$obj_token = json_decode($result);
|
||||
$token_get = $obj_token->access_token;
|
||||
echo $result;
|
||||
$refresh_token = $obj_token->refresh_token;
|
||||
array_push($array, $token_get);
|
||||
array_push($array, $refresh_token);
|
||||
curl_close($cRequest);
|
||||
return $array;
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
22
module/api/tgw.php
Normal file
22
module/api/tgw.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
|
||||
$fcmUrl = 'https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize?client_id=998f5db8-f544-4dda-a10a-79eda88a5437&response_type=code&redirect_uri=https://dev-intranet.breadcrumb-online.de/module/api/testGraph.php&response_mode=query&scope=offline_access%20User.ReadWrite%20Presence.ReadWrite%20Calendars.ReadWrite&state=12345';
|
||||
$cRequest = curl_init();
|
||||
curl_setopt($cRequest, CURLOPT_URL, $fcmUrl);
|
||||
curl_setopt($cRequest, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($cRequest, CURLOPT_SSL_VERIFYPEER, false);
|
||||
$result = curl_exec($cRequest);
|
||||
echo $result;
|
||||
curl_close($cRequest);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user