Koozali.org: home of the SME Server
Obsolete Releases => SME Server 8.x => Topic started by: apmuthu on May 08, 2013, 03:06:12 PM
-
Writing PHP code to parse the SME db files possibly for use outside of SME can be assisted by the use of the following script to get the shared folders array list:
<?php
$reqkeylist = Array('share');
$a=file_get_contents("/home/e-smith/db/accounts");
$b = explode(chr(10), $a);
$c = array();
$e = array();
// Remove Comment Lines and blank lines
for ($i = 0; $i < count($b); $i++) {
$firstchar = substr(trim($b[$i]), 0,1);
if ((strlen($firstchar) <> 0) && ($firstchar <> '#')) $c[] = $b[$i];
}
for ($i=0; $i < count($c); $i++) {
$b = array();
$b[$i] = explode('|', $c[$i]);
$x = array();
$x = explode('=', $b[$i][0]);
$x[1] = trim($x[1]);
if (in_array($x[1], $reqkeylist)) {
$e[$x[0]]['InfoType'] = $x[1];
for ($j=1; $j < count($b[$i]); $j = $j+2) {
$e[$x[0]][$b[$i][$j]] = trim($b[$i][$j+1]);
}
}
}
echo print_r($e, true);
?>
-
apmuthu
this kind of post should be done in wiki and reported here as link to the wiki page, thank you
I would add that this topic is OT in this forum and that should be moved in another place
-
On SME server, PHP only runs as the user 'www', who does not have permission to read the configuration database files.
I don't know how OP intends to use this.
My suggestion is to create a specific templated file which contains only the information of interest to whatever script you have. That file can be created to be publicly readable, and PHP files can parse that file (or it could be a .php file).
-
On SME server, PHP only runs as the user 'www', who does not have permission to read the configuration database files.
indeed, you are right and I forgot to mention
-
Thankyou @CB & @Stefano. It is precisely this kind of feedback I was looking for. Possibly a symlink of the db files into an I-bay that is private may suffice. Where in the server-manager would php files be executable? Would we have to wrap them into a cli script and execute it within perl?
This method became necessary for generating bitkinex config files for use by clients based on current "shared folders" set in the extension of that name.
-
Possibly a symlink of the db files into an I-bay that is private may suffice.
No, you cannot defeat file system permission protection by using a symlink.
Where in the server-manager would php files be executable? Would we have to wrap them into a cli script and execute it within perl?
PHP files can't be executed in the server-manager. I don't know why you are determined to use PHP, but I already gave you a suggestion how you could do what you want.
-
@CB: Thanks for the info. If the usage of PHP in the server-manager was eschewed on grounds of security, then compromising it would be pointless, especially for a trivial end such as to generate config files for BitKinex.
The workaround here I am currently using is to download the /home/e-smith/db/accounts file from the the SME and the upload it on the fly into a php script on a private I-bay and obtaining the config files for BitKinex. Insisting on using php is just a matter of proficiency over perl. Will possibly use the native perl libraries for manipulating the said file when time permits.
-
Further refinement of the PHP parsing of the accounts file for SME Shared Folders info for use in generating config files for WebDAV clients like Bitkinex:
<?php
function getsfdata($dbfile, $reqkeylist) {
$a=file_get_contents("accounts");
$b = explode(chr(10), $a);
$c = array();
$e = array();
// Remove Comment Lines and blank lines
for ($i = 0; $i < count($b); $i++) {
$firstchar = substr(trim($b[$i]), 0,1);
if ((strlen($firstchar) <> 0) && ($firstchar <> '#')) $c[] = $b[$i];
}
for ($i=0; $i < count($c); $i++) {
$b = array();
$b[$i] = explode('|', $c[$i]);
$x = array();
$x = explode('=', $b[$i][0]);
$x[1] = trim($x[1]);
if (in_array($x[1], $reqkeylist)) {
$e[$x[0]]['InfoType'] = $x[1];
for ($j=1; $j < count($b[$i]); $j = $j+2) {
$e[$x[0]][$b[$i][$j]] = trim($b[$i][$j+1]);
}
}
}
// echo print_r($e, true);
return $e;
}
function getsfusergrouplist() {
$dbfile = 'accounts';
$reqkeylist = Array('group');
$groups = getsfdata($dbfile, $reqkeylist);
$a = Array();
foreach ($groups as $key => $value) {
$members = Array();
$members = explode(',', $value['Members']);
foreach ($members as $member) {
$a[] = Array('member' => $member, 'group' => $key);
}
}
return $a;
}
function getsfusers() {
$a = getsfusergrouplist();
$users = Array();
foreach ($a as $groupuser) {
$users[$groupuser['member']]['group'][] = $groupuser['group'];
}
ksort($users);
return $users;
}
function getsfgroupsharelist() {
$dbfile = 'accounts';
$reqkeylist = Array('share');
$shares = getsfdata($dbfile, $reqkeylist);
$a = Array();
foreach ($shares as $key => $value) {
$sharedesc = $value['Name'];
$groupsR = Array();
$groupsR = explode(',', $value['ReadGroups']);
if ((count($groupsR) > 0) && (strlen($value['ReadGroups'][0]) > 0)){
foreach ($groupsR as $group) {
$a[] = Array('group' => $group, 'share' => $key, 'sharedesc' => $sharedesc, 'RW' => 'R');
}
}
$groupsW = Array();
$groupsW = explode(',', $value['WriteGroups']);
if ((count($groupsW) > 0) && (strlen($value['WriteGroups'][0]) > 0)){
foreach ($groupsW as $group) {
$a[] = Array('group' => $group, 'share' => $key, 'sharedesc' => $sharedesc, 'RW' => 'W');
}
}
}
array_unique($a);
asort($a);
$b = Array();
foreach ($a as $shareset) {
$b[$shareset['group']][$shareset['share']] = Array('sharedesc' => $shareset['sharedesc'], 'RW' => $shareset['RW']);
}
return $b;
}
function getsfusershares() {
$shares = getsfgroupsharelist();
$users = getsfusers();
$a = Array();
foreach ($users as $user => $details) {
$group = $details['group'];
foreach ($group as $groupname) {
$shareset = $shares[$groupname];
foreach ($shareset as $sharename => $sharedetails) {
$shareRW = $sharedetails['RW'];
if ( (!array_key_exists($sharename, $a[$user])) ||
(($shareRW == 'W') && ($a[$user][$sharename] == 'R')) ) {
$a[$user][$sharename] = $sharedetails;
}
}
}
}
return $a;
}
?>