function onConstruct() { global $args, $Logger, $User; if (!$this->ID) { $d = new dbIO('Filesystem'); $d->UserID = $User->ID; $d->Name = reset(explode(':', $args->path ? $args->path : $args->args->path)); if ($d->Load()) { foreach ($d as $k => $v) { $this->{$k} = $v; } } } $this->sysinfo = json_decode(file_get_contents('devices/DOSDrivers/DropboxDrive/sysinfo.json'), true); if (!is_array($this->sysinfo) || !$this->sysinfo['api-key']['key'] || !$this->sysinfo['api-key']['secret']) { $Logger->log('Unable to load sysinfo'); die('fail'); } if ($this->Config == '') { $this->state = self::UNAUTHORIZED; } else { //nothing to do here.... } $this->fileInfo = isset($args->fileInfo) ? $args->fileInfo : new stdClass(); }
<?php /******************************************************************************* * * * This file is part of FRIEND UNIFYING PLATFORM. * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU Affero General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Affero General Public License for more details. * * * * You should have received a copy of the GNU Affero General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * *******************************************************************************/ $o = new dbIO('FSetting'); $o->UserID = $User->ID; $o->Type = 'system'; $o->Key = $args->args->setting; $o->Load(); $o->Data = json_encode($args->args->data); $o->Save(); die('ok');
/******************************************************************************* * * * This file is part of FRIEND UNIFYING PLATFORM. * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU Affero General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Affero General Public License for more details. * * * * You should have received a copy of the GNU Affero General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * *******************************************************************************/ // 2. Setup standard dock items $dockItems = array(array('Dock', 'A simple dock desklet'), array('Dingo', 'A command line interface'), array('Artisan', 'A programmers editor'), array('Author', 'A word processor'), array('Wallpaper', 'Select a wallpaper')); $i = 0; foreach ($dockItems as $r) { $d = new dbIO('DockItem'); $d->Application = $r[0]; $d->ShortDescription = $r[1]; $d->UserID = $User->ID; $d->SortOrder = $i++; $d->Parent = 0; $d->Save(); }
require 'modules/system/include/themes.php'; break; case 'settheme': $o = new dbIO('FSetting'); $o->UserID = $User->ID; $o->Type = 'system'; $o->Key = 'theme'; $o->Load(); $o->Data = $args->args->theme; $o->Save(); if ($o->ID > 0) { die('ok'); } die('fail'); case 'userdelete': $u = new dbIO('FUser'); if ($u->Load($args->args->id)) { $SqlDatabase->query('DELETE FROM `FSetting` WHERE UserID=\'' . $u->ID . '\''); $SqlDatabase->query('DELETE FROM `DockItem` WHERE UserID=\'' . $u->ID . '\''); $u->Delete(); die('ok'); } die('fail'); case 'usersettings': // Settings object $s = new stdClass(); // The first login test! include 'modules/system/include/firstlogin.php'; // Theme information $o = new dbIO('FSetting'); $o->UserID = $User->ID;
* * * You should have received a copy of the GNU Affero General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * *******************************************************************************/ function findBaseHref($app) { $ar = array('../resources/webclient/apps/', 'resources/webclient/apps/'); foreach ($ar as $apath) { if (file_exists($apath . $app) && is_dir($apath . $app)) { return str_replace(array('../resources', 'resources'), '', $apath) . $app . '/'; } } return false; } $app = new dbIO('FApplication'); $app->UserID = $User->ID; $app->Name = $args->app; if ($app->Load()) { $path = findBaseHref($app->Name); $conf = json_decode($app->Config); friendHeader('Content-Type: text/html'); $scrp = file_get_contents('resources/' . $path . $conf->Init); $scrp = preg_replace('/progdir\\:/i', $path, $scrp); // TODO: Permissions? $str = '<!DOCTYPE html> <html> <head> <title>' . $conf->Name . '</title> <base href="' . $path . '"/> <script src="/webclient/js/apps/api.js"></script>
function copyFile($pathFrom, $pathTo) { global $User, $Logger; // 1. Get the filesystem objects $from = reset(explode(':', $pathFrom)); $to = reset(explode(':', $pathTo)); $fsFrom = new dbIO('Filesystem'); $fsFrom->UserID = $User->ID; $fsFrom->Name = $from; $fsFrom->Load(); $fsTo = new dbIO('Filesystem'); $fsTo->UserID = $User->ID; $fsTo->Name = $to; $fsTo->Load(); // We got two filesystems, good! if ($fsTo->ID > 0 && $fsFrom->ID > 0) { // Make sure we support both filesystems // TODO: Deprecate old version $testFrom = 'modules/files/include/door_' . $fsFrom->Type . '.php'; $testTo = 'modules/files/include/door_' . $fsTo->Type . '.php'; // New version: if (!file_exists($testFrom)) { $testFrom = 'devices/DOSDrivers/' . $fsFrom->Type . '/door.php'; } if (!file_exists($testTo)) { $testTo = 'devices/DOSDrivers/' . $fsTo->Type . '/door.php'; } // Final test if (!file_exists($testFrom)) { die('error'); } if (!file_exists($testTo)) { die('error'); } // Get a filesystem object for the two file systems $path = $pathFrom; include $testFrom; $doorFrom = $door; $path = $pathTo; include $testTo; $doorTo = $door; unset($door, $path); // Do a file move! // It's a folder! if (substr($pathFrom, -1, 1) == '/') { $fpath = substr($pathFrom, 0, strlen($pathFrom) - 1); if (strstr($fpath, '/')) { $folderName = end(explode('/', $fpath)); } else { $folderName = end(explode(':', $fpath)); } if (trim($folderName)) { $tpath = $pathTo; if (substr($tpath, -1, 1) != ':' && substr($tpath, -1, 1) != '/') { $tpath .= '/'; } // Create the path $doorTo->createFolder($folderName, $tpath); return true; } } else { if ($file = $doorFrom->getFile($pathFrom)) { if ($doorTo->putFile($pathTo, $file)) { return true; } } } return false; } }
* but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Affero General Public License for more details. * * * * You should have received a copy of the GNU Affero General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * *******************************************************************************/ if ($row = $SqlDatabase->FetchObject(' SELECT * FROM FApplication WHERE `Name` = "' . $args->args->application . '" AND UserID=\'' . $User->ID . '\' ')) { if (isset($args->args->permissions) && is_array($args->args->permissions)) { $perms = []; foreach ($args->args->permissions as $p) { $rw = []; for ($a = 1; $a < count($p); $a++) { $rw[$a - 1] = $p[$a]; } $perms[] = $rw; } // Collect permissions in a string $app = new dbIO('FUserApplication'); $app->ApplicationID = $row->ID; $app->UserID = $User->ID; $app->AuthID = md5(rand(0, 9999) . rand(0, 9999) . rand(0, 9999) . $row->ID); $app->Permissions = json_encode($perms); $app->Save(); die('ok<!--separate-->'); } } die('fail');
function deleteFile($path, $recursive = false) { global $Config, $User, $Logger; // If it's a folder if (substr($path, -1, 1) == '/') { return $this->deleteFolder($path, $recursive); } // Remove file from path $subPath = explode('/', end(explode(':', $path))); array_pop($subPath); $subPath = implode('/', $subPath) . '/'; $fo = $this->getSubFolder($subPath); $Logger->log('Trying to delete a file in folder: ' . ($fo ? $fo->Name : '(don\'t know, but in subfolder ' . $subPath . ')')); $fi = new dbIO('FSFile'); $fi->UserID = $User->ID; $fi->FilesystemID = $this->ID; $fi->FolderID = $fo ? $fo->ID : '0'; if (strstr($path, '/')) { $fi->Filename = end(explode('/', $path)); } else { $fi->Filename = end(explode(':', $path)); } if ($fi->Load()) { if (file_exists($Config->FCUpload . $fi->DiskFilename)) { $Logger->log('Deleting file in folder ' . ($fo ? $fo->Name : '') . '/ (' . $fi->FolderID . ')'); unlink($Config->FCUpload . $fi->DiskFilename); $fi->Delete(); return true; } else { $Logger->log('Deleting db only (corrupt) file in folder ' . $fi->Name . '/ (' . $fi->FolderID . ')'); $fi->Delete(); } } return false; }
FMail WHERE UserID=\'' . $User->ID . '\' AND `Address`=\'' . mysql_real_escape_string($args->args->account) . '\' ')) { $fld = end(explode('}', $args->args->folder)); if ($imap = imap_open('{' . $row->Server . ':' . $row->Port . '/imap/ssl}' . $fld, $row->Username, $row->Password)) { $info = imap_headerinfo($imap, $args->args->id); $output = new stdClass(); $output->subject = $info->subject; $output->to = $info->toaddress; $output->date = $info->date; $output->from = $info->fromaddress; $output->replyto = $info->reply_toaddress; $output->messageId = $args->args->id; $output->account = $args->args->account; // Put in store $f = new dbIO('FMailHeader'); $f->UserID = $User->ID; $f->ExternalMessageID = $args->args->id; $f->Folder = $args->args->folder; $f->Address = $args->args->account; if (!$f->Load()) { $f->To = $info->toaddress; $f->From = $info->fromaddress; $f->Subject = iconv_mime_decode(utf8_encode($info->subject)); $f->Date = date('Y-m-d H:i:s', strtotime($info->date)); $f->ReplyTo = $info->reply_toaddress; $f->Save(); } imap_close($imap); die('ok<!--separate-->' . json_encode($output)); }
$UserApplication = false; // Get user information $User = new dbIO('FUser'); if (isset($GLOBALS['args']->sessionid)) { $User->SessionID = $GLOBALS['args']->sessionid; $User = $User->FindSingle(); //$logger->log( 'User logged in with sessionid:' . ( $User ? ( $User->ID . ' ' . print_r( $args, 1 ) ) : ( 'No user id!' . print_r( $args, 1 ) ) ) ); } if (isset($User->SessionID) && trim($User->SessionID) && $User->Load()) { //$logger->log( 'fop' ); $GLOBALS['User'] =& $User; } else { //$logger->log( 'lop' ); // Ok, did we have auth id? if (isset($GLOBALS['args']->authid)) { $UserApplication = new dbIO('FUserApplication'); $UserApplication->AuthID = $GLOBALS['args']->authid; $UserApplication->Load(); if ($UserApplication->ID > 0) { $User->Load($UserApplication->UserID); if ($User->ID > 0) { $GLOBALS['User'] =& $User; } } } //$logger->log( 'ok: ' . ( isset( $User ) ? ' has user' : ' no user' ) ); // Failed to authenticate if (isset($User->ID) && $User->ID <= 0) { die('404'); } }
die('ok<!--separate-->' . json_encode($types)); } else { // Try to generate for user! if ($rows = $SqlDatabase->FetchObjects(' SELECT ua.ID, n.Name, ua.Permissions, ua.Data FROM FUserApplication ua, FApplication n WHERE n.ID = ua.ApplicationID AND ua.UserID=\'' . $User->ID . '\' ORDER BY n.Name ASC ')) { foreach ($rows as $row) { if (file_exists($f = 'resources/webclient/apps/' . $row->Name . '/Config.conf')) { $obj = json_decode(file_get_contents($f)); if ($obj) { if ($obj->MimeTypes) { foreach ($obj->MimeTypes as $k => $v) { $s = new dbIO('FSetting'); $s->UserID = $User->ID; $s->Type = 'mimetypes'; $s->Key = '.' . strtolower($k); $s->Data = $row->Name; $s->Save(); } } } } } $types = _get_mimetypes(); if (count($types)) { die('ok<!--separate-->' . json_encode($types)); } }
$r[] = $m->Name; } die('ok<!--separate-->' . json_encode($r)); } die('fail'); break; case 'addaccount': // Make sure we have everything $required = ['email', 'inserver', 'inport', 'inuser', 'inpass', 'outserver', 'outport', 'outuser', 'outpass']; foreach ($required as $req) { if (!isset($args->args->{$req})) { die('fail<!--separate-->Missing data'); } } // Save the account $o = new dbIO('FMail'); $o->UserID = $User->ID; $o->Address = $args->args->email; $o->Server = $args->args->inserver; $o->Port = $args->args->inport; $o->Username = $args->args->inuser; $o->Password = $args->args->inpass; $o->OutServer = $args->args->outserver; $o->OutPort = $args->args->outport; $o->OutUser = $args->args->outuser; $o->OutPass = $args->args->outpass; $o->Save(); if ($o->ID) { die('ok'); } break;
* This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU Affero General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Affero General Public License for more details. * * * * You should have received a copy of the GNU Affero General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * *******************************************************************************/ if ($row = $SqlDatabase->FetchObject(' SELECT * FROM FApplication WHERE `Name` = "' . $args->args->application . '" AND UserID=\'' . $User->ID . '\' ')) { if (isset($args->args->permissions)) { // Collect permissions in a string $app = new dbIO('FUserApplication'); $app->ApplicationID = $row->ID; $app->UserID = $User->ID; $app->Load(); if ($app->ID > 0) { $app->Permissions = $args->args->permissions; $app->Save(); die('ok<!--separate-->'); } } } die('fail');
*******************************************************************************/ function findInSearchPaths($app) { $ar = array('resources/webclient/apps/'); foreach ($ar as $apath) { if (file_exists($apath . $app) && is_dir($apath . $app)) { return $apath . $app; } } return false; } if ($path = findInSearchPaths($args->args->application)) { if (file_exists($path . '/Config.conf')) { $f = file_get_contents($path . '/Config.conf'); // Path is dynamic! $f = preg_replace('/\\"Path[^,]*?\\,/i', '"Path": "' . $path . '/",', $f); // Store application! $a = new dbIO('FApplication'); $a->Config = $f; $a->UserID = $User->ID; $a->Name = $args->args->application; $a->Permissions = 'UGO'; $a->DateInstalled = date('Y-m-d H:i:s'); $a->DateModified = $a->DateInstalled; $a->Save(); if ($a->ID > 0) { die('ok<!--separate-->' . $a->ID); } } } die('failed');
} // Get the groups for authentication $r = AuthenticateApplication($args->args->application, $User->ID); if ($r && substr($r, 0, 4) == 'fail') { die($r); } list($retCode, $retData) = explode('<!--separate-->', $r); $retObject = false; if ($retData) { $retObject = json_decode($retData); } // Some settings $sets = array('language'); $opts = new stdClass(); foreach ($sets as $set) { $s = new dbIO('FSetting'); $s->Type = 'system'; $s->Key = $set; $s->UserID = $User->ID; if ($s->Load()) { $json = false; if (substr($s->Data, 0, 1) == '"' && substr($s->Data, -1, 1) == '"') { $json = substr($s->Data, 1, strlen($s->Data) - 2); } if ($json && ($d = json_decode($json))) { $opts->{$set} = $d; } else { if ($d = json_decode($s->Data)) { $opts->{$set} = $d; } else { $opts->{$set} = $s->Data;
$fl->FolderID = $f2->ID; $fl->FilesystemID = $o->ID; $fl->Filesize = filesize($prefix . $file . '.jpg'); $fl->DateCreated = date('Y-m-d H:i:s'); $fl->DateModified = $fl->DateCreated; $fl->UserID = $User->ID; $fl->Save(); } // 7. Copy some other files $prefix = "resources/webclient/examples/"; $files = array("ExampleWindow.jsx", "Template.html"); foreach ($files as $filen) { list($file, $ext) = explode('.', $filen); $newname = $file; while (file_exists('storage/' . $newname . '.' . $ext)) { $newname = $file . rand(0, 999999); } copy($prefix . $file . '.' . $ext, 'storage/' . $newname . '.' . $ext); $fl = new dbIO('FSFile'); $fl->DiskFilename = $newname . '.' . $ext; $fl->Filename = $file . '.' . $ext; $fl->FolderID = $f1->ID; $fl->FilesystemID = $o->ID; $fl->Filesize = filesize($prefix . $file . '.' . $ext); $fl->DateCreated = date('Y-m-d H:i:s'); $fl->DateModified = $fl->DateCreated; $fl->UserID = $User->ID; $fl->Save(); } } }
function GetByIds($tableName, $keyAr) { $o = new dbIO($tableName); if (count($keyAr) < count($o->_primarykeys)) { return false; } $i = 0; foreach ($o->_primarykeys as $p) { $o->{$p} = $keyAr[$i++]; } if ($o->Load()) { return $o; } return false; }