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_support/modules/config/model/ |
Upload File : |
<?php
class settings_model extends Model {
// test settings
// save if ok, otherwise give error
public function __construct() {
parent::__construct();
$settings = $this->SettingGet('config.module_info', NULL);
$this->salt = isset($settings['key']) ? $settings['secret'] : LOCK_FILE;
}
public function SaveSettings($post) {
$title = trim($post['title']); // company/trading name
$db_host = trim($post['db_host']);
$db_name = trim($post['db_name']);
$db_user = trim($post['db_user']);
$db_pass = base64_encode(trim($post['db_pass']));
$this->SettingSet('title', $title);
// try to log in.
if ($db_host != '' && $db_name != '' && $db_user != '') {
$engine = hook_execute('db.load', NULL, 'mysql', "mysql://{$db_user}:{$db_pass}@{$db_host}/{$db_name}");
$this->SettingSet('db_host', $db_host);
$this->SettingSet('db_name', $db_name);
$this->SettingSet('db_user', $db_user);
$this->SettingSet('db_pass', $db_pass);
$ok = $engine->open();
if ($ok) {
$this->SettingSet('db_ok', 1);
$this->SettingSet('db_message', '');
} else {
$this->SettingSet('db_ok', 0);
$this->SettingSet('db_message', $engine->errmsg . " [{$engine->errnum}]");
}
if ($ok) {
$output = hook_execute('db.migrate', '', $this->controller); // Create Tables
}
return $ok;
}
}
function _getModuleHash($module_name) {
return md5("{$this->salt}:$module_name");
}
// Generate data needed for html. include current value
private function _generateFieldData($field_defs, $module_name) {
$output = [];
$active_settings = $GLOBALS['loader']->LoadModuleSettings($module_name);
foreach($field_defs as $index => $field_def) {
$field_name = $field_def['name'];
$field_def['name'] = $module_name . '[' . $field_name . ']';
$field_def['id'] = $module_name . '_' . $field_name;
$value = $active_settings !== NULL && isset($active_settings[$field_name]) ? $active_settings[$field_name] : NULL;
if ($value === NULL) {
$value = isset($field_def['default'])? $field_def['default'] : '';
}
$type = strtolower($field_def['type']);
/*if (isset($field_def['callback'])) {
$x = call_user_func($field_def['callback']);
if ($type == 'select') {
$field_def['v'] = $x;
}
unset($field_def['callback']);
}*/
$field_def['value'] = $value;
$field_def['type'] = $type;
$field_def['key'] = $field_name;
$output[] = $field_def;
}
return $output;
}
public function GetPackageSettings(&$result, $specific_module = '', $asFieldSet = FALSE) {
$data = [];
$info = [];
$modules = $GLOBALS['loader']->getModuleList();
foreach($modules as $module_name => $module_info) {
if ($specific_module == '' || $specific_module == $module_name) {
if (isset($module_info['.info']) && isset($module_info['.info']['settings'])) {
$help = empty($module_info['.info']['helplink']) ? FALSE : $module_info['.info']['helplink'];
$param = &$module_info['.info'];
$order = isset($param['display_order']) ? $param['display_order'] : 50;
$info[] = ['info' => $param, 'order' => $order, 'helplink' => $help, 'module' => $module_name];
}
}
}
// sort by display order
usort($info, function($a, $b) {
return $a['order'] - $b['order'];
});
foreach($info as $info_item) {
$module_name = $info_item['module'];
$title = isset($info_item['info']['name']) ? $info_item['info']['name'] : $module_name;
$fielddata = $this->_generateFieldData($info_item['info']['settings'], $module_name);
if (count($fielddata)) {
foreach($fielddata as &$fielddata_item) {
$name = $fielddata_item['name'];
$result[$name] = $fielddata_item['value'];
unset($fielddata_item['value']);
}
if ($info_item['helplink']) { // put in module path
$info_item['helplink'] = '/~/' . strtolower($module_name) . '/' . $info_item['helplink'];
}
$data[] = ['name' => $title, 'fieldlist' => $fielddata, 'helplink' => $info_item['helplink']];
}
}
if ($specific_module != '' && !$asFieldSet) {
$result['fieldlist'] = $data[0]['fieldlist'];
if (isset($data[0]['helplink'])) $result['helplink'] = $data[0]['helplink'];
} else {
$result['fieldset'] = $data;
}
}
public function SetPackageSettings($post, $specific_module = '') {
$modules = $GLOBALS['loader']->getModuleList();
foreach($modules as $module_name => $module_info) {
if ($specific_module == '' || $specific_module == $module_name) {
if (isset($module_info['.info']) && isset($module_info['.info']['settings'])) {
$this->_saveClassSettings($module_name, $module_info['.info']['settings'], $post[$module_name]);
}
}
}
}
private function _saveClassSettings($module_name, $settings /* field definitions */, $values /* new values */) {
// move to settings
$result = [];
foreach($settings as $fieldname => $field_info) {
if (is_numeric($fieldname)) {
$fieldname = $field_info['name']; // needed for `config` module
}
$type = strtolower($field_info['type']);
// if ($type == 'select') { // must be a valid option
// } else
if ($type == 'checkbox') {
$result[$fieldname] = !empty($values[$fieldname]);
} else {
$result[$fieldname] = trim($values[$fieldname]);
}
}
return $this->_saveClass($module_name, $result);
}
private function _saveClass($module_name, $result) {
// apply module-specific callback
$result = hook_execute('settings.filter', $result, $module_name);
// update loaded copy of settings
$loader = $GLOBALS['loader'];
$loader->DATA[$module_name]['current'] = $result;
// save settings (in filesystem or database, depending on module)
$data = Hook_Execute('config.set', $result, $module_name);
return $data;
}
/* public function GenerateProviderList($providers) {
$output = [];
foreach($providers as $name => $provider_info) {
$tag = $provider_info['info']['authentication'];
$html = hook_execute("auth.{$tag}.button", '');
if ($html != '') {
$output[] = ['link' => '?tag=' . $tag, 'value' => $html];
}
}
return $output;
} */
public function GetProvider($providers, $the_tag) {
foreach($providers as $key => $provider_info) {
$tag = $provider_info['.info']['authentication'];
if ($tag == $the_tag) {
$provider_info['key'] = explode(':', $key);
return $provider_info;
}
}
return NULL;
}
public function EditAuthenticationSettings(&$res, $info, $tag) {
$module = $info['key'][0];
hook_execute('module.enable', $module, 1); // enable the module
if (!isset($info['.info']['settings'])) {
return FALSE;
}
$this->GetPackageSettings($res, $info['key'][0], TRUE);
return TRUE;
}
public function SaveModuleSettings($post, $info) {
$this->SetPackageSettings($post, $info['key'][0]);
}
public function CheckFileSystem() {
$filename = $GLOBALS['loader']->filename();
$s = $this->_verify($filename);
if ($s->isError()) return $s;
$filename = $this->__CONFIG->filename();
return $this->_verify($filename);
}
private function _verify($filename) {
$s = new http_status(200);
if (file_exists($filename)) {
if (!is_writable($filename)) {
$note = <<<BLOCK
<p>The file "{$filename}" exists, but the webserver cannot write to it. Please change the file permissions.<p>
<p>When the setup procedure is complete, you may change the permissions back to read-only</p>
BLOCK;
$s->Status(461)
->Message('Unable to write to file')
->Note($note);
return $s;
}
}
// try to create a temp file in the folder
$base = pathinfo($filename, PATHINFO_DIRNAME);
$file = pathinfo($filename, PATHINFO_BASENAME);
$tempname = md5(uniqid('', TRUE));
$fp = @fopen("$base/$tempname", 'w');
if (is_resource($fp)) {
fclose($fp);
unlink("$base/$tempname");
} else {
$note = <<<BLOCK
<p>Please change the permissions on the folder "$base" to allow the webserver to create a new file, or create an empty writable file called "$file" within that folder.<p>
<p>When the setup procedure is complete, you may change the permissions back to read-only</p>
BLOCK;
$s->Status(462)
->Message('Unable to create file')
->Note($note);
}
return $s;
}
private function _GetLockFilename() {
return sys_get_temp_dir() . '/' . LOCK_FILE;
}
// Are we going to be automatically promoted to the Setup user?
public function PromoteToSetupUser($auth) {
// is session variable present>
if (isset($_SESSION['setup-user'])) return TRUE;
$filename = $this->_GetLockFilename();
if (file_exists($filename)) {
$x = file_get_contents($filename);
if ($x == $auth) {
$_SESSION['setup-user'] = 1;
return TRUE;
}
return FALSE;
}
$_SESSION['setup-user'] = 1;
$auth = md5(time() . ':' . session_id());
file_put_contents($filename, $auth);
return TRUE;
}
public function SetupUserDetails(&$res) {
if (isset($_SESSION['setup-user'])) {
$filename = $this->_GetLockFilename();
$x = file_get_contents($filename);
$res['single'] = "/admin/setup?auth=$x";
}
$db_ok = $this->SettingGet('db_ok', 0);
$message = $this->SettingGet('db_message', '');
if (!$db_ok && !empty($message)) $res['message'] = $message;
}
public function ResetSingleUserMode($level) {
if (isset($_SESSION['setup-user']) && $level >= 10) {
unset($_SESSION['setup-user']);
$filename = $this->_GetLockFilename();
if (file_exists($filename)) {
unlink($filename);
}
}
}
protected function file_exists($filename) {
if (version_compare(PHP_VERSION, '7.4.0') >= 0 && version_compare(PHP_VERSION, '7.5.0') < 0) {
// this has bug - and will return true, even when file does not exists
// `service apache2 restart` will clear the file
}
// 7.3 is fine
return file_exists($filename);
}
// if the lock file exists, and we are not the session that locked the file
// then we are in maintenance mode, and cannot continue
public function isLocked() {
$filename = $this->_GetLockFilename();
return $this->file_exists($filename) && !isset($_SESSION['setup-user']);
}
private function _generateAuth($key, $category) {
$auth = hook_execute('nonce.create', FALSE, $category, $key);
return $auth;
}
function _getSupportedTimeZones(&$info) {
$timezone_identifiers = DateTimeZone::listIdentifiers();
foreach($timezone_identifiers as $name) {
$info[] = ['key' => $name, 'value' => $name];
}
}
function _asInput($module_name, $current_settings, $setting_name, $setting_definition) {
$hash = $this->_getModuleHash($module_name);
$auth = $this->_generateAuth("{$hash}-{$setting_name}", 'modedit');
$value = isset($current_settings[$setting_name]) ? $current_settings[$setting_name] : '';
if (isset($setting_definition['default']) && $value == '') $value = $setting_definition['default'];
$type = $setting_definition['type'];
$class = 'bind-editable';
$selectdata = '';
switch($type) {
case 'select': // a select list
if (!empty($setting_definition['filter'])) {
$info = hook_execute($setting_definition['filter'], []);
} elseif (!empty($setting_definition['options'])) {
$info = [];
if (is_string($setting_definition['options'])) {
switch($setting_definition['options']) {
case '{timezone}':
$this->_getSupportedTimeZones($info);
$param = [];
break;
}
} else {
$param = $setting_definition['options'];
}
foreach($param as $xkey => $xvalue) {
$info[] = ['key' => $xkey, 'value' => $xvalue];
}
} else {
$info = [];
}
$data = []; $dvalue = '';
foreach($info as $info_item) {
$k = $info_item['key'];
$data[$k] = $info_item['value'];
if ($k == $value) $dvalue = $info_item['value'];
}
$data['selected'] = $value;
$value = $dvalue;
$selectdata = json_encode($data);
$selectdata = 'data-select="' . htmlspecialchars($selectdata) . '" ';
break;
case 'checkbox':
$chk = empty($value) ? '' : ' checked';
return "<input type=\"checkbox\" class=\"checkbox-input\" href=\"/admin/settings/edit/{$hash}-{$setting_name}/$auth\" value=\"1\"$chk>";
case 'password': //•
$dvalue = htmlspecialchars($value);
$selectdata = "data-value=\"$dvalue\" ";
$xvalue = '';
for($i = 0; $i<strlen($value); $i++) {
$xvalue .= '●'; // 25CF
}
return "<b class=\"$class\" data-category=\"config\" data-module=\"{$hash}\" data-field=\"{$setting_name}\" data-type=\"{$type}\" {$selectdata}href=\"/admin/settings/edit/{$hash}-{$setting_name}/$auth\">" . $xvalue . "</b>";
case 'text':
$class .= ' format-pre';
break;
}
// have a context menu for this item? attach it to the read-only part of this field:
// to do: some indication that a context menu is present
if (isset($setting_definition['context'])) {
$class .= ' contextMenu';
$selectdata .= " id=\"{$hash}-{$setting_name}\" src=\"/~/config/context/{$auth}\"";
}
// show placeholder text for an input[type="text"] field?
if (!empty($setting_definition['placeholder'])) {
$x = htmlspecialchars($setting_definition['placeholder']);
$selectdata .= "placeholder=\"$x\"";
}
// data-module and data-field are used to update the internal copy of this field. No auth required since it's not going into the database via that route
$xvalue = $value == '' ? '(no value)' : $value;
$xvalue = $value;
return "<b class=\"$class\" data-category=\"config\" data-module=\"{$hash}\" data-field=\"{$setting_name}\" data-type=\"{$type}\" {$selectdata}href=\"/admin/settings/edit/{$hash}-{$setting_name}/$auth\">" . htmlspecialchars($xvalue) . "</b>";
}
// get all modules, their status, and configuration parameters
public function ModuleList() {
// $this->LoadActiveModules();
$data = [];
$errors = [];
$modules = $GLOBALS['loader']->getModuleList();
foreach($modules as $module => $module_data) {
if ($module == 'config') continue; // System Settings is elsewhere
$auth = $this->_generateAuth($module, 'enable');
if (isset($module_data['.info'])) {
$required = !empty($module_data['.info']['required']);
// $enabled = !empty($module_data['settings']['enabled']) || $required;
$enabled = !empty($module_data['enabled']) || $required;
$missing = isset($module_data['.info']['missing']) ? count($module_data['.info']['missing']) : 0;
$sel = $enabled ? ' checked' : '';
$dis = $required ? ' disabled' : '';
$edt = $required ? '' : ' class="checkbox-edit"';
if ($missing) {
$denable = '<img src="/static/warning.png" width="20" height="20" border="0" alt="missing dependencies" title="This module has missing dependencies">';
} else {
$denable = "<input type=\"checkbox\"$edt name=\"cb|{$module}|$auth\" value=\"1\"$dis$sel>";
}
$node = [ 'enabled' => array('disp' => $denable, 'val' => $enabled ? 1 : 0),
'name' => $module,
'desc' => $module_data['.info']['name'],
'data' => array(),
'module' => $module,
];
if ($enabled && isset($module_data['main'])) { // check for errors
$obj = $module_data['main'];
if (method_exists($obj, 'Validate')) {
$obj->Validate($errors);
}
}
// add note of missing dependencies
if ($missing) {
$node['data'][] = [0 => 'Missing dependencies:', 1 => '<strong>' . join('</strong>, <strong>', $module_data['.info']['missing']) . '</strong>'];
}
// add settings
if (isset($module_data['.info']['settings'])) {
// load settings for inactive modules
foreach($module_data['.info']['settings'] as $setting_definition) {
$setting_name = $setting_definition['name'];
$caption = $setting_definition['caption'];
if (isset($setting_definition['link'])) {
$caption .= '<a href="' . htmlspecialchars($setting_definition['link']) . '" target="_blank">*</a>';
}
if (isset($setting_definition['hint'])) {
$caption = '<span title="' . htmlspecialchars($setting_definition['hint']) . '">' . $caption . '</span>';
}
if (!isset($module_data['current'])) { // should not happen - indicates a parser error?
var_dump($module_data);
// $module_data['current'] = [];
}
$node['data'][] = array(0 => $caption, 1 => $this->_asInput($module, $module_data['current'], $setting_name, $setting_definition));
}
}
if (!count($node['data'])) $node['DT_RowClass'] = 'nochild';
$data[] = $node;
}
}
return array('data' => $data, 'errors' => $errors);
}
public function ModuleDatatable() {
// $auth = $this->_generateAuth(0, 'active');
$result = array(
'columns' => array(
array('class' => 'details-control', 'orderable' => false, 'data' => '_', 'defaultContent' => '', 'width' => '20px'),
array('data' => 'enabled', 'width' => '40px', 'render' => array('_' => 'disp', 'sort' => 'val'), 'sClass' => 'dt-center'),
array('data' => 'name', 'width' => '110px'),
array('data' => 'desc'),
),
'order' => array( array( 2, 'asc' )),
'pageLength' => 25,
'bPaginate' => TRUE,
'bFilter' => TRUE,
'bInfo' => TRUE, // Showing x to y of z entries
);
return $result;
}
private function _getModuleFromHash($class_hash) {
$modules = $GLOBALS['loader']->getModuleList();
foreach($modules as $module => $module_data) {
if ($module == 'config') continue; // System Settings is elsewhere
$hash = $this->_getModuleHash($module);
if ($hash == $class_hash) return $module;
}
return NULL;
}
private function _locateFieldDefinition($settings, $fieldname) {
$definitions = $settings['.info']['settings'];
foreach($definitions as $item) {
if ($item['name'] == $fieldname) return $item;
}
return NULL;
}
//to do: if the module is disabled, then load it.. this will install the onSave hook (aka 'config.set')
protected function ModuleEditSetting($class_hash, $fieldname, $new_value) {
// select section based on class_hash:
$module_name = $this->_getModuleFromHash($class_hash);
if ($module_name === NULL) return; /// not found
list($x, $settings) = $GLOBALS['loader']->locateModule($module_name);
if ($settings === FALSE) return; // not found
if (!isset($settings['main'])) { // module is not active, so load it
$GLOBALS['loader']->loadModule($settings_class_module);
}
$result = $settings['current'];
if ($result === NULL) $result = [];
$field_info = $this->_locateFieldDefinition($settings, $fieldname);
$type = $field_info === NULL ? 'string' : strtolower($field_info['type']);
if ($type == 'checkbox') {
$result[$fieldname] = !empty($new_value);
} else {
$result[$fieldname] = trim($new_value);
}
return $this->_saveClass($module_name, $result); // the returned text is ignored by jeditable
}
private function ModuleEnable($module_name, $enabled) {
$loader = $GLOBALS['loader'];
list($modname, $info) = $loader->locateModule($module_name);
if ($info === FALSE) return ['result' => -3, 'message' => 'unknown module' ]; /// not found
if ($enabled) { // and if Validate function present
$res = $loader->VerifyModuleSettings($modname);
if ($res !== TRUE) return $res; // verification failed - display noty
$res = hook_execute('module.verify', NULL, $module_name);
if (is_array($res)) return $res; // a check [by another module] is preventing this module from being enabled.
// Activate the module so the module.enable hook can be run (do database migrations)
$loader->ActivateModule($modname);
}
hook_execute('module.enable', $modname, $enabled);
$status = $enabled ? 'enabled' : 'disabled';
return ['result' => 0, 'message' => "module $module_name {$status}."];
}
public function ModuleEdit($key, $requested_auth, $value) {
$auth_cb = hook_execute('nonce.verify', FALSE, 'enable', $key, $requested_auth);
$auth_me = hook_execute('nonce.verify', FALSE, 'modedit', $key, $requested_auth);
if ($auth_cb) { // enable checkbox
return $this->ModuleEnable($key, $value);
} elseif ($auth_me) { // a setting within the module
list($class_hash, $field) = explode('-', $key, 2);
return $this->ModuleEditSetting($class_hash, $field, $value);
}
return ['result' => -2, 'cb' => $requested_auth, 'key' => $key, 'value' => $value];
}
public function contextMenu($key, $auth) {
list($class_hash, $field) = explode('-', $key, 2);
$module_name = $this->_getModuleFromHash($class_hash);
if ($module_name === NULL) return; /// not found
list($x, $settings) = $GLOBALS['loader']->locateModule($module_name);
if ($settings === FALSE) return; // not found
$item = $this->_locateFieldDefinition($settings, $field);
if ($item === NULL) return;
$hasContextCallback = isset($item['context.enabled']);
if ($hasContextCallback) { // activate the module, if not already active
if (!isset($settings['main'])) return FALSE; // module is not active - no context menu
}
$result = [];
foreach($item['context'] as $index => $contextitem) { // 'class' => $item['class']
$href = str_replace('{auth}', $auth, $contextitem['href']);
$node = ['name' => $contextitem['caption'], 'icon' => 'fas fa-key', 'href' => $href ];
if ($hasContextCallback) {
$enabled = hook_execute($item['context.enabled'], FALSE, $contextitem, $item);
if (!$enabled) $node['disabled'] = TRUE;
}
$result['item' . $index] = $node;
}
return $result;
/*
["href"]=>
string(24) "/~/agentRemote/createkey"
["class"]=>
string(4) "ajax"
["caption"]=>
string(14) "Create New Key"
subItems = {
"edit": { name: "Edit", icon: "edit" },
"cut": { name: "Cut", icon: "cut" },
"status": {
name: "Status",
icon: "delete",
items: {
"sub1": { name: "Submenu1", icon: "edit" },
"sub2": { name: "Submenu2", icon: "cut" },
},
},
"normalSub": {
name: "Normal Sub",
items: {
"normalsub1": { name: "normal Sub 1"},
"normalsub2": { name: "normal Sub 2"},
"normalsub3": { name: "normal Sub 3"},
}
}
}
*/
}
}
/*
private function GetModuleData($module, &$count) {
$count = $this->LoadModuleSettings($module);
if (!$count) {
$node = array();
} else {
$node = $this->MODULES[$module]['settings'];
}
return $node;
}
private function SetModuleData($module, $node, $count) {
global $DATABASE;
$payload = serialize($node);
if ($count) {
$sql = "update config set cfg_data=%s where cfg_key=%s";
$this->Execute($sql, array($payload, $module));
} else {
$sql = "insert into config set cfg_data=%s, cfg_key=%s";
$this->Execute($sql, array($payload, $module));
}
return array('result' => $DATABASE->errnum, 'message' => $DATABASE->error);
}
protected function ModuleEnable($module, $new_value) {
$node = $this->GetModuleData($module, $count);
$old = empty($node['enabled']) ? 0 : $node['enabled'];
$node['enabled'] = intval($new_value);
$data = $this->SetModuleData($module, $node, $count);
$this->errors = [];
if ($node['enabled'] && !$old) {
$this->Execute_onEnabled($module); // module has just been enabled - call the onEnable function
} elseif (!$node['enabled'] && $old) {
$this->Execute_onDisabled($module); // module has just been disabled
}
if (count($this->errors)) $data['errors'] = $this->errors;
return $data;
}
protected function ModuleEditSetting($module, $field, $new_value) {
$node = $this->GetModuleData($module, $count);
$node[$field] = $new_value;
return $this->SetModuleData($module, $node, $count);
}
*/