DIR : /home/kozerus/safer/ko_startup.php

/home/kozerus/safer

<?php
# ../safer/ko_startup.php	20211208_1930 disable db3 loging
# ../safer/db2cfg		20211127_2000 kolog db2_drop,create,insert
# ../safer/db2cfg		20211127_2000
# return();

	$http_host="ko2.us";
	$dbname="";
	if( isset( $_SERVER['HTTP_HOST'] )) { $http_host=$_SERVER['HTTP_HOST']; }


function startup_db2($http_host) {
	$http_host="ko2.us";
	$dbname="";
	if( isset( $_SERVER['HTTP_HOST'] )) { $http_host=$_SERVER['HTTP_HOST']; }

	$dbname=""; $tbl=""; $sql=""; $user=""; $pass="";
	if( isset( $_REQUEST['dbname'] )) { $dbname=$_REQUEST['dbname']; }
	if( isset( $_REQUEST['tbl'] )) { $tbl=$_REQUEST['']; }
	else { 
		$dbname=kocfg($http_host,'dbname'); 
		$tbl=kocfg($http_host,'tbl'); 
		$sql=kocfg($http_host,'sql'); 
		}

	$server=kocfg($http_host,'server');
	$user=kocfg($http_host,'user');
	$pass=kocfg($http_host,'pass');

# 	$server="localhost"; $dbname="dgs"; $user="dgsmstr"; $pass=""; $sql="select tables;";
# 	$server="localhost"; $dbname="kotwous_ko"; $user="komstr"; $pass="=komstr="; $sql="select tables;";

	$query_string="";
#	print( "<h1>BUGS_10 safer/db2cfg.php  host=$host query_string=$query_string</h1><hr color=goldenrod>" );


	$progid="ko_startup";
	$dttm=date('Ymd_His');
	$user="dgsmstr";
	$addr="127.0.0.1";
	$port="80";
	$agent="";
	$referer="referer";
	$describ="describ_$dttm";
	$cnt=0;

	if( isset($_SERVER['host'] )) { $host=$_SERVER['host']; }
	if( isset( $_SERVER['REMOTE_ADDR'])) {
		$remote_addr=$_SERVER['REMOTE_ADDR'];
		$remote_addr=str_replace(".","-",$remote_addr);
		$addr=$remote_addr;
		}

	if( isset($_SERVER['HTTP_USER_AGENT'] )) {
		$http_user_agent=$_SERVER['HTTP_USER_AGENT'];
		$http_user_agent=str_replace(" ","",$http_user_agent );
		$http_user_agent=str_replace(".","",$http_user_agent );
		$http_user_agent=str_replace(";","",$http_user_agent );
		$http_user_agent=str_replace(":","",$http_user_agent );
		$http_user_agent=str_replace("/","",$http_user_agent );
		$http_user_agent=str_replace("\n","",$http_user_agent );
		$http_user_agent=str_replace("(","",$http_user_agent );
		$http_user_agent=str_replace(")","",$http_user_agent );
		$http_user_agent=str_replace(" ","",$http_user_agent );
		$http_user_agent=str_replace(" ","",$http_user_agent );
		$agent=$http_user_agent;
		}
	if( isset( $_SERVER['REMOTE_PORT'])) { 
		$remote_port=$_SERVER['REMOTE_PORT']; 
		$port=$remote_port;
		}
	if( isset( $_SERVER['REFERER'])) { $referer=$_SERVER['REFERER']; }
	if( isset( $_SERVER['QUERY_STRING'])) {
		$query_string=$_SERVER['QUERY_STRING'];
		$query_string=str_replace("%27","",$query_string);
		}

	$tbllog = "kolog";
	$db2_sql_create = "";
	$db2_sql_create .= "create table if not exists $tbllog (";
	$db2_sql_create .= "	progid text,";
	$db2_sql_create .= "	dttm text,";
	$db2_sql_create .= "	host text,";
	$db2_sql_create .= "	user text,";
	$db2_sql_create .= "	addr text,";
	$db2_sql_create .= "	port text,";
	$db2_sql_create .= "	agent text,";
	$db2_sql_create .= "	referer text,";
	$db2_sql_create .= "	query_string text,";
	$db2_sql_create .= "	cnt text, ";
	$db2_sql_create .= "	describ text ";
	$db2_sql_create .= "	);";

	$db2_sql_drop = "";
	$db2_sql_drop .= "drop table if exists $tbllog";

	$db2_sql_insert ="insert into $tbllog ";
	$db2_sql_insert .= "(progid,dttm,host,user,addr,port,agent,referer,query_string,cnt,describ)";
	$db2_sql_insert  .= " values ";
	$db2_sql_insert  .= "('$progid','$dttm','$host','$user','$addr','$port','$agent','$referer','$query_string','$cnt','$describ')";
	$db2_sql_select = "select * from kolog";



#	print("<h3>MSG_11 db2_sql=$db2_sql_create</h3>" );
#	print("<h3>MSG_12 db2_sql=$db2_sql_drop</h3>" );
#	print("<h3>MSG_13 db2_sql=$db2_sql_insert</h3>" );

$hostid="ko2";
# $hostid="ka1";
# $hostids="ko2 ko1 ka1";
# $user="root"; $pass="..root";
# $dbname="ko"; $user="komstr"; $pass="=komstr=";
# $dbname="kozerus_ko"; $user="komstr"; $pass="=komstr=";
# $dbname="kotwous_ko"; $user="komstr"; $pass="=komstr=";
# $dbname="kozerus_ko"; $user="komstr"; $pass="=komstr=";

	if( isset( $_REQUEST['hostids'] )) { $hostids=$_REQUEST['hostids']; }
	if( isset( $_REQUEST['hostid'] )) { $hostids=$hostid; }
	if( isset( $_REQUEST['sql'] )) { $sql=$_REQUEST['sql']; }
	if( isset( $_REQUEST['tbl'] )) { $sql=$_REQUEST['tbl']; }

	if( isset( $_SERVER['HOME'])) { $home=$_SERVER['HOME']; }
	if( isset( $_SERVER['SERVER_NAME'])) { $server_name=$_SERVER['SERVER_NAME']; }
	if( isset( $_SERVER['HTTP_HOST'])) { $http_host=$_SERVER['HTTP_HOST']; }


	print( "<h1>BUGS_140 $progid $dttm http_host=$http_host home=$home server_name=$server_name </h1>" );

	print( "<h3>MSG_141 $progid $progid $dttm DB2_CONNECT hostid=$hostid server=$server dbname=$dbname user=$user pass=pass</h3>" );

#	print( "<h3>MSG_142 $progid hostid=$hostid server=$server dbname=$dbname user=$user sql=$sql</h3>" );

	$db2="";
#	$server="localhost"; $dbname="dgs"; $user="dgsmstr"; $pass="=dgsmstr=";
#	print( "<h3>MSG_141 DB2_CONNECT dbname=$dbname user=$user</h3>" );

	$db2=db2conn($server,$dbname,$user,$pass);
#	print( "<h3>BUGS_151 DB2_CONN_DONE db2=\$db2 server=$server dbname=$dbname user=$user" );


	if( $db2 ) {
#		print( "<h3>MSG_142 DB2_DROP dbname=$dbname db2_sql_drop=$db2_sql_drop</h3>" );
		$db2->exec($db2_sql_drop);

#		print( "<h3>MSG_143 DB2_CREATE dbname=$dbname db2_sql_create=$db2_sql_create</h3>" );
		$db2->exec($db2_sql_create);

#		print( "<h3>MSG_144 DB2_INSERT dbname=$dbname db2_sql_insert=$db2_sql_insert</h3>" );
		$db2->exec($db2_sql_insert);
#		print( "<h3>MSG_145 DB2_CLOSE dbname=$dbname</h3>" );
#		$db2->close();
		$db2 = null;
#		print( "<h3>MSG_149 DB2_DONE dbname=$dbname db2_sql_insert=$db2_sql_insert</h3>" );
		}
	else {
##		print( "<h3>ERR_159 DB2_FAIL dbname=$dbname db2_sql_insert=$db2_sql_insert</h3>" );

		}

#	$sql = "select * from $tbllog";
#	$htmout = db2_select( $db2,$sql);

	$db3fil="/db3fil.db3";
	$db3fil="ko_startup.db3";
	$db3fil="../safer/ko_startup.db3";
	$db3_sql_drop=$db2_sql_drop;
	$db3_sql_create=$db2_sql_create;
	$db3_sql_insert=$db2_sql_insert;
	$db3_sql_select=$db2_sql_select;
#	print( "<h3>MSG_200 SQL3_CONNECT ko_startup db3fil=$db3fil</h3>" );
#	$db3 = new PDO($db3fil);
#	$db3 = newpdo($db3fil);
#	$db3 = new SQLite3($db3fil);

#	if( $db3 ) {
#		print( "<h3>MSG_201 ko_startup SQL3_DROP db3fil=$db3file sql3_sql_drop=$db3_sql_drop</h3>" );
#		$db3->exec($db3_sql_drop);
#		print( "<h3>MSG_202 ko_startup SQL3_CREATE db3fil=$db3fil db3_sql_create=$db3_sql_create</h3>" );
#		$db3->exec($db3_sql_create);
#		print( "<h3>MSG_203 ko_startup SQL3_INSERT db3fil=$db3fil db3_sql_insert=$db3_sql_insert</h3>" );
#		$db3->exec($db3_sql_insert);
#		$db3 = null;
#		print( "<h3>MSG_204 ko_startup SQL3_DONE db3fil=$db3fil</h3>" );
#		}
#	else {
#		print( "<h3>MSG_205 ko_startup SQL3_FAIL db3fil=$db3fil </h3>" );
#		}

	$htmout="";
	print( $htmout );
	return( $htmout );
	}
	




function db2conn($server,$dbname,$user,$pass) {
	$htmout = ""; $db2="";
#	$htmout .= "<h1>MSG_181 DB2CONN server=$server $dbname=$dbname user=$user</h1>";
	try {
		$db2 = new PDO("mysql:host=$server;dbname=$dbname",$user, $pass);

#		print( "<h2>MSG_182 db2=\$db2 host=$server dbname=$dbname user=$user</h2>");
// set the PDO error mode to exception
		$db2->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
#		$htmout .= "<h1>MSG_183 server=$server dbname=$dbname user=$user </h1>";
		}
	
	catch(PDOException $e) {
//		echo "<h1>ERR_34003 FAIL_CONNECT server=$server dbname=$dbname user=$user err=" . $e->getMessage();
//		$htmout .=  "<h1>ERR_13 FAIL DB2_CONNECT: server=$server dbname=$dbname user=$user server=$server errmsg=" . $e->getMessage();
		}
	return($db2);
	}

function db2_select($db2,$sql) {
#	print( "<h3>MSG_170 DB2_SELECT sql=$sql</h3>" );
	if( $db2 == "" ) { return(""); }
#	$db3->query($sql);
	$stm = $db2->query($sql);
	$j=0; 
	$htmout = "";
	$rowcnt=$db2->rowCount;
	$colcnt=$db2->columnCount;
	while( $row = $stmt->fetch(PDO::FETCH_BOTH)) {
		$j=$j+1;
		$row0=$row[0];
		$htmout .= $row0."<br>\n";
		}

#	print( "<h3>MSG_180 DB2_SELECT rowcnt=$rowcnt colcnt=$colcnt sql=$sql</h3>" );

	}




#	echo get_cfg_var("mysqli.default_pw")
#	my_raldfklg_random_key_pw=top-secret-password
#	echo get_cfg_var("my_raldfklg_random_key_pw")
#	

#	php.ini's standard section. like: mongodb_dflkjadkfl_username=... and mongodb_dflkjadkfl_password=..., then get the value via get_cfg_var("mongodb_dflkjadkfl_username") and get_cfg_var("mongodb_dflkjadkfl_password") , where dflkjadkfl is some random text 


function kocfg($http_host,$fld) {

# $hostids="ko2.us ko1.us ko0.us ka12";
#	foreach( explode(" ", $hostids) as $hostid ) {
#		}


	if( $http_host=="ko2.us" ) {
#		$server="ko2.us";
		$server="localhost";
		if( $dbname == "" ) { $dbname="kotwous_ko"; }
		$sql="show tables;";
		if( $dbname=="kotwous_ko") { 
			$tbl="kolog"; 
			$sql="select * from $tbl";
			$user="komstr"; $pass="=komstr=";
			} 
		if( $dbname=="kotwous_dgs") { 
			$tbl="Games"; 
			$sql="select * from $tbl";
			$user="dgsmstr"; $pass="=dgsmstr=";
			} 
		if( $dbname=="kotwous_zc") { $tbl="ko_temp"; 
			$tbl="Categories";
			$sql="select * from $tbl";
			$user="adam"; $pass="yumcart2";
			} 
		}
	
	if( $http_host == "ko0.us" ) {
#		$server="ko0.us"; 
		$server="localhost";
		if( $dbname == "" ) { $dbname="kozerus_ko"; }
		$user="kozerus_komstr"; $pass="=komstr="; $tbl="kolog"; 
		$sql="show tables;";
		if( $dbname=="kozerus_ko") { 
			$tbl="kolog";
			$sql="select * from $tbl";
			$user="kozerus_komstr"; $pass="=komstr=";
			} 
		if( $dbname=="kozerus_dgs") { 
			$tbl="Players";
			$sql="select * from $tbl";
			$user="dgsmstr"; $pass="=dgsmstr=";
			} 
		if( $dbname=="kozerus_zc") { 
			$tbl="Categories";
			$sql="select * from $tbl";
			$user="adam"; $pass="yumcart0";
			} 
		}

	if( $http_host=="ka12" ) {
		$server="localhost"; 
		$dbname="ko";
		$user="komstr"; $pass="=komstr="; $tlb="ko";
		$sql="show tables;";
		if( $dbname=="ko") { 
			$tbl="kolog"; 
			$sql="select * from $tbl";
			$user="komstr"; $pass="=komstr=";
			} 
		if( $dbname=="dgs") { $tbl="ko_temp"; 
			$tbl="Games";
			$sql="select * from $tbl";
			$user="dgsmstr"; $pass="=dgsmstr=";
			} 
		if( $dbname=="zc") { 
			$tbl="Categories"; 
			$sql="select * from $tbl";
			$user="adam"; $pass="yumcart1";
			} 
		}

	if( $fld == "server" ) { return($server); }
	if( $fld == "dbname" ) { return($dbname); }
	if( $fld == "tbl" ) { return($tbl); }
	if( $fld == "sql" ) { return($sql); }
	if( $fld == "user" ) { return($user); }
	if( $fld == "pass" ) { return($pass); }
	print( "<h1>MSG_200 $progid http_host=$http_host hostid=$hostid dbname=$dbname user=$user</h1>\n" );
	return("");
	}

//


koh5_pano



Your browser does not support the HTML5 canvas element.


Drag mouse to navigate.

Navigation





17.Aug.2010, Martin Wengenmayer