Skip to content

Commit 60ed43d

Browse files
committed
Patch so phpMoAdmin continues to work when magic quotes is enabled
1 parent d21f418 commit 60ed43d

File tree

1 file changed

+48
-19
lines changed

1 file changed

+48
-19
lines changed

moadmin.php

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* www.Vork.us
77
* www.MongoDB.org
88
*
9-
* @version 1.0.4
9+
* @version 1.0.5
1010
* @author Eric David Benari, Chief Architect, phpMoAdmin
1111
*/
1212

@@ -286,7 +286,7 @@ public function getStats() {
286286
. ' minutes';
287287
$unshift['mongo'] = $return['version'];
288288
$unshift['mongoPhpDriver'] = Mongo::VERSION;
289-
$unshift['phpMoAdmin'] = '1.0.4';
289+
$unshift['phpMoAdmin'] = '1.0.5';
290290
$unshift['gitVersion'] = $return['gitVersion'];
291291
unset($return['ok'], $return['version'], $return['gitVersion']);
292292
$return = array_merge(array('version' => $unshift), $return);
@@ -459,7 +459,7 @@ public function editObject($collection, $_id, $idtype) {
459459
* @return array
460460
*/
461461
public function saveObject($collection, $obj) {
462-
eval('$obj='.$obj.';'); //cast from string to array
462+
eval('$obj=' . $obj . ';'); //cast from string to array
463463
return $this->mongo->selectCollection($collection)->save($obj);
464464
}
465465
}
@@ -1573,26 +1573,22 @@ public function getCheckboxes(array $args) {
15731573
}
15741574

15751575
/**
1576-
* phpMoAdmin bootstrap
1576+
* phpMoAdmin specific functionality
15771577
*/
1578-
if (!isset($_GET['db'])) {
1579-
$_GET['db'] = 'admin';
1580-
} else if (strpos($_GET['db'], '.') !== false) {
1581-
$_GET['db'] = $_GET['newdb'];
1582-
}
1583-
try {
1584-
moadminComponent::$model = new moadminModel($_GET['db']);
1585-
} catch(Exception $e) {
1586-
echo $e;
1587-
exit(0);
1588-
}
1589-
$html = get::helper('html');
1590-
$form = new formHelper;
1591-
$mo = new moadminComponent;
1592-
15931578
class phpMoAdmin {
1579+
/**
1580+
* Sets the depth limit for phpMoAdmin::getArrayKeys (and prevents an endless loop with self-referencing objects)
1581+
*/
15941582
const DRILL_DOWN_DEPTH_LIMIT = 8;
15951583

1584+
/**
1585+
* Retrieves all the keys & subkeys of an array recursively drilling down
1586+
*
1587+
* @param array $array
1588+
* @param string $path
1589+
* @param int $drillDownDepthCount
1590+
* @return array
1591+
*/
15961592
public static function getArrayKeys(array $array, $path = '', $drillDownDepthCount = 0) {
15971593
$return = array();
15981594
if ($drillDownDepthCount) {
@@ -1608,7 +1604,40 @@ public static function getArrayKeys(array $array, $path = '', $drillDownDepthCou
16081604
}
16091605
return $return;
16101606
}
1607+
1608+
/**
1609+
* Strip slashes recursively - used only when magic quotes is enabled (this reverses magic quotes)
1610+
*
1611+
* @param mixed $val
1612+
* @return mixed
1613+
*/
1614+
public static function stripslashes($val) {
1615+
return (is_array($val) ? array_map(array('self', 'stripslashes'), $val) : stripslashes($val));
1616+
}
1617+
}
1618+
1619+
/**
1620+
* phpMoAdmin bootstrap
1621+
*/
1622+
if (get_magic_quotes_gpc()) {
1623+
$_GET = phpMoAdmin::stripslashes($_GET);
1624+
$_POST = phpMoAdmin::stripslashes($_POST);
1625+
}
1626+
1627+
if (!isset($_GET['db'])) {
1628+
$_GET['db'] = 'admin';
1629+
} else if (strpos($_GET['db'], '.') !== false) {
1630+
$_GET['db'] = $_GET['newdb'];
1631+
}
1632+
try {
1633+
moadminComponent::$model = new moadminModel($_GET['db']);
1634+
} catch(Exception $e) {
1635+
echo $e;
1636+
exit(0);
16111637
}
1638+
$html = get::helper('html');
1639+
$form = new formHelper;
1640+
$mo = new moadminComponent;
16121641

16131642
/**
16141643
* phpMoAdmin front-end view-element

0 commit comments

Comments
 (0)