Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/patientapps_beta/api/.api/ |
Upload File : |
<?php
// https://patientapps.net/api/provision.json?product=pai-lgb&email=&phone=&duration=60
// https://patientapps.net/api/provision.json?product=pai-rcl&email=Phil%27s+Clinic&phone=1.844.99.YOUNG&duration=60
// https://patientapps.net/api/provision.json?product=pai-ull&email=&phone=&duration=60&test=1
$param = [
'product' => str_replace(['/', '..', '<', '>', '&', '|'], '', strtolower(trim($_REQUEST['product']))),
'email' => trim($_REQUEST['email']),
'phone' => trim($_REQUEST['phone']),
'duration' => (int)$_REQUEST['duration'],
'test' => isset($_REQUEST['test']) ? (int)$_REQUEST['test'] > 0 : FALSE,
'utm' => isset($_REQUEST['utm']) ? trim($_REQUEST['utm']) : '',
'desc' => empty($_REQUEST['desc']) ? '' : trim($_REQUEST['desc']),
'previous' => empty($_REQUEST['previous']) ? '' : trim($_REQUEST['previous']),
];
// load original data
$docroot = realpath(__DIR__ . '/../..');
$source = $docroot . '/.download/' . $param['product'];
if (!file_exists($source . '.json')) {
ReturnJson(['status' => 'err', 'message' => 'unable to locate source product', 'file' => $source]);
}
$json = json_decode(file_get_contents($source . '.json'), TRUE);
if (!isset($json['data.json'])) {
ReturnJson(['status' => 'err', 'message' => 'error loading source product', 'file' => 'data.json']);
}
$definition = base64_decode($json['data.json']);
$definition = json_decode($definition, TRUE);
$definition = _modifyProductDefinition($definition, $param);
if ($param['desc'] == '') $param['desc'] = '%P - %D-day Trial';
// allocate number and save it
$description = str_replace(['%P', '%D' ],
[$param['product'], $param['duration'] ],
$param['desc']);
$subdomain = _allocateProductNumber($db, $description, $definition['expiry'], $param);
$queryparam = ['id' => $subdomain];
$utm = $param['utm'];
if ($utm != '') {
$queryparam['utm'] = $utm;
}
$output = '';
foreach($queryparam as $key => $value) {
$output .= ($output == '') ? '?' : '&';
$output .= rawurlencode($key) . '=' . rawurlencode($value);
}
$definition['infolink'] = 'https://patientapps.com/home/info' . $output;
$jsontext = base64_encode(unEscapeSlash(json_encode($definition)));
$json['data.json'] = $jsontext;
_saveJson($docroot . '/.download/' . $subdomain, $json);
_saveSql3($source . '.sql3', $docroot . '/.download/' . $subdomain . '.sql3', $definition);
// no need to save a pointer to audio, since the new json points to the original files
// return allocated number
$content = [
'status' => 'ok',
'identifier' => $subdomain,
];
ReturnJson($content);
function unEscapeSlash($jsontext) {
// this is not part of a html document, so does not need escaping
return str_replace('\\/', '/', $jsontext);
}
function _saveJson($target, $jsondata) {
$jsontext = json_encode($jsondata);
$jsontext = unEscapeSlash($jsontext);
file_put_contents($target . '.json', $jsontext);
}
function _UpdateBlob($db, $name, $node) {
$stmt = $db->prepare("UPDATE blobs set wd = :wd, ht = :ht, mimetype = :mime, data = :data where name = :name");
$stmt->bindValue(':name', $name, SQLITE3_TEXT);
$stmt->bindValue(':wd', $node['wd'], SQLITE3_INTEGER);
$stmt->bindValue(':ht', $node['ht'], SQLITE3_INTEGER);
$stmt->bindValue(':mime', $node['mime'], SQLITE3_TEXT);
$stmt->bindValue(':data', $node['data'], SQLITE3_BLOB);
$stmt->execute();
$stmt->reset();
}
function _saveSql3($source, $target, $jsondata) {
copy($source, $target);
$db = new SQLite3($target);
$jsontext = json_encode($jsondata);
$jsontext = str_replace("\r\n", "\n", $jsontext);
$node = ['.data', 'wd' => 0, 'ht' => 0, 'mime' => '', 'data' => $jsontext];
_UpdateBlob($db, '.data', $node);
$db->close();
}
// modify json
// add expiry
// remove contact us
// change phone/email/country
// remove careteam
function _modifyProductDefinition($definition, $param) {
unset($definition['careteam'], $definition['care_team']);
$definition['expiry'] = time() + 86400 * $param['duration'];
$email = empty($param['email']) ? '' : 'mailto:' . $param['email'];
$phone = empty($param['phone']) ? '' : 'tel:' . $param['email'];
$definition['macro']['email'] = $email;
$definition['macro']['phone_office'] = $phone;
$definition['macro']['phone_oncall'] = '#'; // no oncall
// remove contact info, if not specified
if ($email == '') {
_replaceEmpty($definition['content'], '~<a href="\{\{email\}\}">(.*?)</a>~');
}
if ($phone == '') {
_replaceEmpty($definition['content'], '~<icon name="telephone" />\s*<a href=\"\{\{.*?\}\}\">(.*?)</a>~');
}
return $definition;
}
function _replaceEmpty(&$definition, $pattern) {
foreach($definition as &$item) {
if (is_array($item)) {
_replaceEmpty($item, $pattern);
} elseif (strpos($item, '{{') !== FALSE) {
_replaceEmpty_string($item, $pattern);
}
}
}
function _replaceEmpty_string(&$entry, $pattern) {
$entry = preg_replace($pattern . 'ism', '[Contact your Provider]', $entry);
}
function _GenerateRandomNumeric($length) {
$syms = '0123456789';
$result = '';
$j = strlen($syms);
for($i = 0; $i < $length; $i++) {
$result .= $syms[mt_rand(0, $j - 1)];
}
return $result;
}
# generate a random unused number
function generateRandomNumeric($db) {
$count = 0;
$len = 6;
do {
$shortcode = _GenerateRandomNumeric($len);
$data = $db->lookup('select * from `shortlink` where sl_short=%s', $shortcode, 'shortlink');
$found = $data['__existing'];
if ($found && $count > 25) {
$count = 0;
$len++;
}
} while ($found);
$data['sl_short'] = $shortcode;
return $data;
}
function _allocateProductNumber($db, $description, $expiry = NULL, $param) {
$test = empty($param['test']) ? 0 : $param['test'];
if (!empty($param['previous'])) {
$shortcode = $param['previous'];
$data = $db->lookup('select * from `shortlink` where sl_short=%s', $shortcode, 'shortlink');
} else {
$data = generateRandomNumeric($db);
$shortcode = $data['sl_short'];
}
if (!$test) {
$utm = isset($param['utm']) ? $param['utm'] : NULL;
$data['sl_full'] = 'https://' . $shortcode . '.myapp.care/';
$data['sl_desc'] = $description;
$data['sl_expiry'] = gmdate('Y-m-d H:i:s', $expiry);
$data['sl_date'] = gmdate('Y-m-d H:i:s');
//$data['sl_short'] = $shortcode;
$data['sl_count'] = 0;
if (empty($data['sl_tracking'])) {
$data['sl_tracking'] = $utm;
}
$db->SaveRecord($data);
}
return $shortcode;
}