Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 209557 | Differences between
and this patch

Collapse All | Expand All

(-)eclipse.org-common/system/app.class.php (+39 lines)
Lines 329-334 Link Here
329
	
329
	
330
	function generatePage($theme, $Menu, $Nav, $pageAuthor, $pageKeywords, $pageTitle, $html) {
330
	function generatePage($theme, $Menu, $Nav, $pageAuthor, $pageKeywords, $pageTitle, $html) {
331
		
331
		
332
		# OPT1: ob_start();
333
		
332
		# All web page parameters passed for variable scope
334
		# All web page parameters passed for variable scope
333
		
335
		
334
		if($theme == "") {
336
		if($theme == "") {
Lines 359-364 Link Here
359
		
361
		
360
		echo $html;
362
		echo $html;
361
		include($this->getFooterPath($theme));
363
		include($this->getFooterPath($theme));
364
		
365
		# OPT1:$starttime = microtime();
366
		# OPT1:$html = ob_get_contents();
367
		# OPT1:ob_end_clean();
368
		
369
		# OPT1:$stripped_html = $html;
370
		# OPT1:$stripped_html = preg_replace("/^\s*/", "", $stripped_html);
371
		# OPT1:$stripped_html = preg_replace("/\s{2,}/", " ", $stripped_html);
372
		# OPT1:$stripped_html = preg_replace("/^\t*/", "", $stripped_html);
373
		# OPT1:$stripped_html = preg_replace("/\n/", "", $stripped_html);
374
		# OPT1:$stripped_html = preg_replace("/>\s</", "><", $stripped_html);
375
		# $stripped_html = preg_replace("/<!--.*-->/", "", $stripped_html);
376
		# OPT1:$endtime = microtime();
377
		
378
		# OPT1:echo "<!-- unstripped: " . strlen($html) . " bytes/ stripped: " . strlen($stripped_html) . "bytes - " . sprintf("%.2f", strlen($stripped_html) / strlen($html)) . " Bytes saved: " . (strlen($html) - strlen($stripped_html)) . " Time: " . ($endtime - $starttime) . " -->";
379
		# echo $stripped_html;
362
	}
380
	}
363
	
381
	
364
	function AddExtraHtmlHeader( $string ) {
382
	function AddExtraHtmlHeader( $string ) {
Lines 703-708 Link Here
703
			}
721
			}
704
			return $fileSize;
722
			return $fileSize;
705
		}
723
		}
724
725
		function useSession() {
726
			require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/session.class.php");
727
        	$ssn = new Session();
728
        	$ssn->validate();
729
        	return $ssn;
730
		}
731
		
732
		function isValidCaller($_pathArray) {
733
			$a = debug_backtrace();
734
			$caller = $a[1]['file'];  # Caller 0 is the class that called App();
735
			$validCaller = false;
736
			for($i = 0; $i < count($_pathArray); $i++) {
737
				# TODO: use regexp's to match the leftmost portion for better security 
738
				if(strstr($caller, $_pathArray[$i])) {
739
					$validCaller = true;
740
					break;
741
				}
742
			}
743
			return $validCaller;			
744
		}
706
}
745
}
707
746
708
?>
747
?>
(-)eclipse.org-common/system/session.class.php (+233 lines)
Added Link Here
1
<?php
2
/*******************************************************************************
3
 * Copyright (c) 2007 Eclipse Foundation and others.
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Denis Roy (Eclipse Foundation)- initial API and implementation
11
 *******************************************************************************/
12
13
define('ECLIPSE_SESSION', 'ECLIPSESESSION');
14
15
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/classes/friends/friend.class.php");
16
require_once("/home/data/httpd/eclipse-php-classes/system/dbconnection_rw.class.php");
17
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/app.class.php");
18
require_once($_SERVER['DOCUMENT_ROOT'] . "/eclipse.org-common/system/evt_log.class.php");
19
20
class Session {
21
22
	private $gid		= "";
23
	private $bugzilla_id= 0;
24
	private $subnet		= "";
25
	private $updated_at	= "";
26
	private $is_persistent	= 0;
27
	private $Friend		= null;
28
	private $data		= "";
29
	
30
	/**
31
	 * Default constructor
32
	 *
33
	 * @return null
34
	 */
35
	function Session($persistent=null) {
36
		$this->is_persistent = $persistent;
37
		$this->validate();			
38
	}
39
	
40
41
	
42
	function getGID() {
43
		return $this->gid;
44
	}
45
	function getBugzillaID() {
46
		return $this->bugzilla_id;
47
	}
48
	function getSubnet() {
49
		return $this->subnet;
50
	}
51
	function getUpdatedAt() {
52
		return $this->updated_at;
53
	}
54
	function getFriend() {
55
		return $this->Friend;
56
	}
57
	function getData() {
58
		return unserialize($this->data);
59
	}
60
	function getIsPersistent() {
61
		return $this->is_persistent == null ? 0 : $this->is_persistent;
62
	}
63
	
64
	function setGID($_gid) {
65
		$this->gid = $_gid;
66
	}
67
	function setBugzillaID($_bugzilla_id) {
68
		$this->bugzilla_id = $_bugzilla_id;
69
	}
70
	function setSubnet($_subnet) {
71
		$this->subnet = $_subnet;
72
	}
73
	function setUpdatedAt($_updated_at) {
74
		$this->updated_at = $_updated_at;
75
	}
76
	function setFriend($_friend) {
77
		$this->Friend = $_friend;
78
	}
79
	function setData($_data) {
80
		$this->data = serialize($_data);
81
	}
82
	function setIsPersistent($_is_persistent) {
83
		$this->is_persistent = $_is_persistent;
84
	}
85
86
	
87
	/**
88
	 * Validate session based on browser cookie
89
	 *
90
	 * @return boolean
91
	 */
92
	function validate() {
93
		$cookie = (isset($_COOKIE[ECLIPSE_SESSION]) ? $_COOKIE[ECLIPSE_SESSION] : "");
94
		$rValue = false;
95
		if ( (!$this->load($cookie))) {
96
        	# Failed - no such session, or session no match.  Need to relogin
97
        	setcookie(ECLIPSE_SESSION, "", -36000, "/", "eclipse.org");
98
        	$rValue = false;
99
        }
100
        else {
101
			# TODO: update session?
102
			$rValue = true;
103
        	$this->maintenance();
104
        	$this->setFriend($this->getData());
105
        }
106
        return $rValue;
107
	}
108
109
110
	function destroy() {
111
		if($this->getBugzillaID() != 0) {
112
        	$sql = "DELETE FROM sessions WHERE bugzilla_id = " . $this->getBugzillaID();
113
        	$dbc = new DBConnectionRW();
114
			$dbh = $dbc->connect();
115
			mysql_query($sql, $dbh);
116
			$dbc->disconnect();
117
			setcookie(ECLIPSE_SESSION, "", -36000, "/", "eclipse.org");
118
			
119
			# Log this event
120
			$EvtLog = new EvtLog();
121
			$EvtLog->setLogTable("sessions");
122
			$EvtLog->setPK1($this->getBugzillaID());
123
			$EvtLog->setPK2($_SERVER['REMOTE_ADDR']);
124
			$EvtLog->setLogAction("DELETE");
125
			$EvtLog->insertModLog("apache");
126
		}
127
	}
128
	
129
	function create() {
130
		# create session on the database
131
		$Friend = $this->getFriend();
132
		$this->setData($Friend);
133
		
134
		# need to have a bugzilla ID to log in
135
		if($Friend->getBugzillaID() > 0) {
136
			$App = new App();
137
			$this->setGID(md5(uniqid(rand(),true)));
138
			$this->setSubnet($this->getClientSubnet());
139
			$this->setUpdatedAt($App->getCURDATE());
140
			
141
			$dbc = new DBConnectionRW();
142
			$dbh = $dbc->connect();
143
			
144
			$sql = "INSERT INTO sessions (
145
						gid,
146
						bugzilla_id,
147
						subnet,
148
						updated_at,
149
						data,
150
						is_persistent)
151
						VALUES (
152
							" . $App->returnQuotedString($this->getGID()) . ",
153
							" . $Friend->getBugzillaID() . ",
154
							" . $App->returnQuotedString($this->getSubnet()) . ",
155
							NOW(),
156
							'" . $App->returnJSSAfeString($this->data) . "',
157
							'" . $this->getIsPersistent() . "')";
158
159
			mysql_query($sql, $dbh);
160
			$dbc->disconnect();
161
			
162
			
163
			# Log this event
164
			$EvtLog = new EvtLog();
165
			$EvtLog->setLogTable("sessions");
166
			$EvtLog->setPK1($this->getBugzillaID());
167
			$EvtLog->setPK2($_SERVER['REMOTE_ADDR']);
168
			$EvtLog->setLogAction("INSERT");
169
			$EvtLog->insertModLog("apache");
170
171
			
172
			$cookie_time = 0;
173
			if($this->persistent) {
174
				$cookie_time = time()+3600*24*365;
175
			}
176
			setcookie(ECLIPSE_SESSION, $this->getGID(), $cookie_time, "/", "eclipse.org");			
177
		}
178
	}
179
	
180
	function load($_gid) {
181
		# need to have a bugzilla ID to log in
182
		
183
		$rValue = false;
184
		if($_gid != "") {
185
			$App = new App();
186
			$sql = "SELECT	gid,
187
							bugzilla_id,
188
							subnet,
189
							updated_at,
190
							data,
191
							is_persistent
192
					FROM sessions
193
					WHERE gid = " . $App->returnQuotedString($_gid) . "
194
						AND subnet = " . $App->returnQuotedString($this->getClientSubnet());
195
			
196
			$dbc = new DBConnectionRW();
197
			$dbh = $dbc->connect();
198
			$result = mysql_query($sql, $dbh);
199
			if($result && mysql_num_rows($result) > 0) {
200
				$rValue = true;
201
				$myrow = mysql_fetch_assoc($result);
202
				$this->setGID($_gid);
203
				$this->setBugzillaID($myrow['bugzilla_id']);
204
				$this->setSubnet($myrow['subnet']);
205
				$this->setUpdatedAt($myrow['updated_at']);
206
				$this->data = $myrow['data'];
207
				$this->setIsPersistent($myrow['is_persistent']);
208
			}
209
			$dbc->disconnect();
210
		}		
211
		return $rValue;
212
	}
213
	
214
	
215
	function maintenance() {
216
		$dbc = new DBConnectionRW();
217
		$dbh = $dbc->connect();
218
			
219
		$sql = "DELETE FROM sessions 
220
				WHERE (updated_at < DATE_SUB(NOW(), INTERVAL 1 DAY) AND is_persistent = 0) 
221
				OR (subnet = '" . $this->getClientSubnet() . "' AND gid <> '" . $this->getGID() . "')"; 
222
223
		mysql_query($sql, $dbh);
224
225
		$dbc->disconnect();
226
	}
227
		
228
	function getClientSubnet() {
229
		# return class-c subnet
230
		return substr($_SERVER['REMOTE_ADDR'], 0, strrpos($_SERVER['REMOTE_ADDR'], ".")) . ".0";
231
	}	
232
}    
233
?>
(-)eclipse.org-common/system/evt_log.class.php (+141 lines)
Added Link Here
1
<?php
2
/*******************************************************************************
3
 * Copyright (c) 2007 Eclipse Foundation and others.
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Denis Roy (Eclipse Foundation)- initial API and implementation
11
 *******************************************************************************/
12
13
define('MAX_LOG_DAYS', 365);
14
15
require_once("/home/data/httpd/eclipse-php-classes/system/dbconnection_rw.class.php");
16
17
class EvtLog {
18
19
	#*****************************************************************************
20
	#
21
	# evt_log.class.php
22
	#
23
	# Author: 		Denis Roy
24
	# Date:			2004-08-05
25
	#
26
	# Description: Functions and modules related to a modification log entry
27
	#
28
	# HISTORY:
29
	#
30
	#*****************************************************************************
31
32
33
	
34
	var $LogID 		= 0;
35
	var $LogTable		= "";
36
	var $PK1		= "";
37
	var $PK2		= "";
38
	var $LogAction		= "";
39
	var $uid		= "";
40
	var $EvtDateTime	= "";
41
	
42
	function getLogID() {
43
		return $this->LogID;
44
	}
45
	function getLogTable() {
46
		return $this->LogTable;
47
	}
48
	function getPK1() {
49
		return $this->PK1;
50
	}
51
	function getPK2() {
52
		return $this->PK2;
53
	}
54
	function getLogAction() {
55
		return $this->LogAction;
56
	}
57
	function getuid() {
58
		return $this->PersonID;
59
	}
60
	function getEvtDateTime() {
61
		return $this->EvtDateTime;
62
	}
63
64
65
	function setLogID($_LogID) {
66
		$this->LogID = $_LogID;
67
	}
68
	function setLogTable($_LogTable) {
69
		$this->LogTable = $_LogTable;
70
	}
71
	function setPK1($_PK1) {
72
		$this->PK1 = $_PK1;
73
	}
74
	function setPK2($_PK2) {
75
		$this->PK2 = $_PK2;
76
	}
77
	function setLogAction($_LogAction) {
78
		$this->LogAction = $_LogAction;
79
	}
80
	function setuid($_uid) {
81
		$this->uid = $_uid;
82
	}
83
	function setEvtDateTime($_EvtDateTime) {
84
		$this->EvtDateTime = $_EvtDateTime;
85
	}
86
87
	function insertModLog ($_uid) {
88
		$uid = $_uid;
89
		if($this->getLogTable() != "" && $this->getPK1() != "" && $this->getLogAction() != "" && $uid != "") {
90
			$App = new App();
91
			$dbc = new DBConnectionRW();
92
			$dbh = $dbc->connect();
93
			
94
			$sql = "INSERT INTO SYS_EvtLog (
95
						LogID,
96
						LogTable,
97
						PK1,
98
						PK2,
99
						LogAction,
100
						uid,
101
						EvtDateTime)
102
					VALUES (
103
						NULL,
104
						" . $App->returnQuotedString($this->getLogTable()) . ",
105
						" . $App->returnQuotedString($this->getPK1()) . ",
106
						" . $App->returnQuotedString($this->getPK2()) . ",
107
						" . $App->returnQuotedString($this->getLogAction()) . ",
108
						" . $App->returnQuotedString($uid) . ",
109
						NOW()
110
					)";
111
					
112
			mysql_query($sql, $dbh);
113
			if(mysql_error() != "") {
114
				echo "An unknown database error has occurred while logging information.  Please contact the System Administrator.";
115
				echo mysql_error();
116
				exit;
117
			}
118
			
119
			$dbc->disconnect();
120
			
121
			# 1% of each hits will perform clean up	
122
			if(rand(0, 100) < 1) {
123
				$this->cleanup();
124
			}
125
		}
126
		else {
127
			echo "An unknown system error has occurred while logging information.  Please contact the System Administrator.";
128
			exit;
129
		}
130
	}
131
	
132
	function cleanup() {
133
		 $sql = "DELETE FROM SYS_EvtLog WHERE EvtDateTime < " . MAX_LOG_DAYS;
134
					
135
		$dbc = new DBConnectionRW();
136
		$dbh = $dbc->connect();
137
		mysql_query($sql, $dbh);
138
		$dbc->disconnect();
139
	}
140
}
141
?>

Return to bug 209557