@ivrפון בזמנו בניתי לך כזה דבר אבל היה תקלה בקוד אנה הקוד המעודקן שתסים בשרת
<?php
define('INI_FILE', 'DID_Storage.ini');
define('TEMP_INI_FILE_SUFFIX', '_himut.ini');
define('API_URL', 'https://www.call2all.co.il/ym/api/');
$did = $_GET['did'] ?? null;
$pass = $_GET['pass'] ?? null;
$ApiExtension = $_GET['ApiExtension'] ?? null;
$sug_himut = $_GET['sug_himut'] ?? null;
$kod_himut = $_GET['kod_himut'] ?? null;
$condition = $_GET['condition'] ?? null;
$hangup = $_GET['hangup'] ?? null;
$path = $_GET['path'] ?? null;
$text = $_GET['text'] ?? null;
$did1 = $_GET['did1'] ?? '';
$did2 = $_GET['did2'] ?? '';
$did3 = $_GET['did3'] ?? '';
$token = "token=$did:$pass";
$temp_ini_file_name = $did . TEMP_INI_FILE_SUFFIX;
if ($hangup === "yes" && $did !== null) {
if (file_exists($temp_ini_file_name)) {
unlink($temp_ini_file_name);
}
exit;
}
if ($did === null) {
echo "read=m-2571=did,yes,10,9,10,Digits,yes&";
exit;
}
if ($pass === null) {
echo "read=m-1800=pass,yes,10,1,10,Digits,yes&";
exit;
}
$ini_OK = [];
if (file_exists($temp_ini_file_name)) {
$ini_OK = parse_ini_file($temp_ini_file_name, true, INI_SCANNER_RAW) ?? [];
}
$himut_ok = ($ini_OK[$did] ?? null) === "ok" ? true : false;
function save_ini_file(array $data) {
$content = "";
foreach ($data as $did_key => $details) {
if (is_array($details) && isset($details['expiry_date'])) {
$content .= "[$did_key]\nexpiry_date = \"" . $details['expiry_date'] . "\"\n\n";
}
}
return file_put_contents(INI_FILE, $content, LOCK_EX) !== false;
}
function set_did_in_ini(string $did_value, int $condition_value) {
$ini_data = file_exists(INI_FILE) ? parse_ini_file(INI_FILE, true) : [];
if ($condition_value === 3) {
if (isset($ini_data[$did_value])) {
unset($ini_data[$did_value]);
save_ini_file($ini_data);
}
return true;
}
$expiry_datetime = new DateTime();
if ($condition_value === 1) $expiry_datetime->modify('+30 days');
elseif ($condition_value === 2) $expiry_datetime->modify('+10 years');
else return null;
$ini_data[$did_value] = ['expiry_date' => $expiry_datetime->format('Y-m-d H:i:s')];
return save_ini_file($ini_data);
}
function check_did_validity(string $did): bool {
if (!file_exists(INI_FILE)) return false;
$ini_data = parse_ini_file(INI_FILE, true);
if (!isset($ini_data[$did]['expiry_date'])) return false;
try {
$expiry = new DateTime($ini_data[$did]['expiry_date']);
if ($expiry > new DateTime()) return true;
unset($ini_data[$did]);
save_ini_file($ini_data);
} catch (Exception $e) {}
return false;
}
function processConfigurationText($text, $vars) {
$repl = [
'?' => '=',
'!' => '&',
'+-' => '#',
'%2A' => '*',
'?1' => $vars['did1'],
'?2' => $vars['did2'],
'?3' => $vars['did3'],
'?did' => $vars['did'],
'?pass' => $vars['pass']
];
return strtr($text, $repl);
}
function translatePath($path) {
if ($path == "**1") return "Star";
if ($path == "**2") return "Hash";
if ($path == "*") return "";
return $path;
}
if (!$himut_ok) {
if (check_did_validity($did)) {
$check_ym = @json_decode(file_get_contents(API_URL . "MFASession?$token&action=try"), true);
if (($check_ym['isPass'] ?? false) === true) {
file_put_contents($temp_ini_file_name, "[$did]\n$did=ok", FILE_APPEND);
$himut_ok = true;
}
}
}
if (!$himut_ok) {
if ($condition === null) {
echo "read=t-נא לבחור משך שמירה. 1 ל-30 יום. 2 לצמיתות. 3 ללא שמירה=condition,yes,1,1,1,Digits,yes&";
exit;
}
if ($kod_himut !== null) {
$res = @json_decode(file_get_contents(API_URL . "MFASession?$token&action=validMFA&mfaCode=$kod_himut"), true);
if (($res["mfa_valid_status"] ?? "") === "valid") {
file_put_contents($temp_ini_file_name, "[$did]\n$did=ok", FILE_APPEND);
set_did_in_ini($did, (int)$condition);
$himut_ok = true;
} else {
echo "id_list_message=t-קוד שגוי&go_to_folder=hangup&";
exit;
}
} elseif ($sug_himut !== null) {
@file_get_contents(API_URL . "MFASession?$token&action=sendMFA&mfaId=$sug_himut&mfaSendType=CALL");
echo "read=t-נא להקיש את הקוד שקיבלתם=kod_himut,yes,6,4,10,Digits,yes&";
exit;
} else {
$res = @json_decode(file_get_contents(API_URL . "MFASession?$token&action=getMFAMethods"), true);
if (($res['responseStatus'] ?? '') !== 'OK') {
echo "id_list_message=t-שגיאה בקבלת נתונים&go_to_folder=hangup&";
exit;
}
$methods = "";
foreach ($res["mfaMethods"] as $m) {
if ($m["STATUS"] == "ACTIVE") {
$methods .= "לספרות " . substr($m["VALUE"], -2) . " הקישו " . $m["ID"] . ". ";
}
}
echo "read=t-בחרו שיטת אימות. $methods=sug_himut,yes,2,1,2,Digits,yes&";
exit;
}
}
if ($path === null) {
echo "read=t-אנא הקישו את מספר השלוחה. לשלוחה ראשית הקישו כוכבית וסולמית=path,yes,10,1,10,Digits,yes&";
exit;
}
if ($text === null) {
echo "read=t-הקישו את ההגדרות. סימן שאלה עבור שווה וסימן קריאה להפרדה=text,no,500,1,500,EnglishKeyboard,yes&";
exit;
}
$cleanPath = translatePath($path);
$vars = ['did1' => $did1, 'did2' => $did2, 'did3' => $did3, 'did' => $did, 'pass' => $pass];
$additionalParams = processConfigurationText($text, $vars);
$updateUrl = API_URL . "UpdateExtension?$token&path=ivr2:$cleanPath&$additionalParams";
$response = @json_decode(file_get_contents($updateUrl), true);
if (($response['responseStatus'] ?? '') === "OK") {
echo "id_list_message=t-הפעולה בוצעה בהצלחה&go_to_folder=/&";
} else {
echo "id_list_message=t-שגיאה בעדכון&go_to_folder=hangup&";
}
exit;