Пример #1
0
 /**
  * Check is a given user exists - send json error msg if not
  * @param string $user
  */
 public static function checkUserExists($user)
 {
     if (!OCP\User::userExists($user)) {
         $l = OC_L10N::get('lib');
         OCP\JSON::error(array('data' => array('message' => $l->t('Unknown user'))));
         exit;
     }
 }
Пример #2
0
 /**
  * Check is a given user exists - send json error msg if not
  * @param string $user
  * @deprecated Use a AppFramework JSONResponse instead
  */
 public static function checkUserExists($user)
 {
     if (!OCP\User::userExists($user)) {
         $l = \OC::$server->getL10N('lib');
         OCP\JSON::error(array('data' => array('message' => $l->t('Unknown user'), 'error' => 'unknown_user')));
         exit;
     }
 }
Пример #3
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function exportContacts()
 {
     $bookid = $this->params('bookid');
     $bookid = isset($bookid) ? $bookid : null;
     $contactid = $this->params('contactid');
     $contactid = isset($contactid) ? $contactid : null;
     $selectedids = $this->params('selectedids');
     $selectedids = isset($selectedids) ? $selectedids : null;
     $nl = "\n";
     if (!is_null($bookid)) {
         try {
             $addressbook = Addressbook::find($bookid);
         } catch (Exception $e) {
             OCP\JSON::error(array('data' => array('message' => $e->getMessage())));
             exit;
         }
         $start = 0;
         $ContactsOutput = '';
         $batchsize = $this->configInfo->getUserValue($this->userId, $this->appName, 'export_batch_size', 20);
         while ($cardobjects = VCard::all($bookid, $start, $batchsize, array('carddata'))) {
             foreach ($cardobjects as $card) {
                 $ContactsOutput .= $card['carddata'] . $nl;
             }
             $start += $batchsize;
         }
         $name = str_replace(' ', '_', $addressbook['displayname']) . '.vcf';
         $response = new DataDownloadResponse($ContactsOutput, $name, 'text/directory');
         return $response;
     } elseif (!is_null($contactid)) {
         try {
             $data = VCard::find($contactid);
         } catch (Exception $e) {
             OCP\JSON::error(array('data' => array('message' => $e->getMessage())));
             exit;
         }
         $name = str_replace(' ', '_', $data['fullname']) . '.vcf';
         $response = new DataDownloadResponse($data['carddata'], $name, 'text/vcard');
         return $response;
     } elseif (!is_null($selectedids)) {
         $selectedids = explode(',', $selectedids);
         $name = (string) $this->l10n->t('%d_selected_contacts', array(count($selectedids))) . '.vcf';
         $ContactsOutput = '';
         foreach ($selectedids as $id) {
             try {
                 $data = VCard::find($id);
                 $ContactsOutput .= $data['carddata'] . $nl;
             } catch (Exception $e) {
                 continue;
             }
         }
         $response = new DataDownloadResponse($ContactsOutput, $name, 'text/directory');
         return $response;
     }
 }
Пример #4
0
 public static function getContactObject($id)
 {
     $card = OC_Contacts_VCard::find($id);
     if ($card === false) {
         OCP\Util::writeLog('contacts', 'Contact could not be found: ' . $id, OCP\Util::ERROR);
         OCP\JSON::error(array('data' => array('message' => self::$l10n->t('Contact could not be found.') . ' ' . $id)));
         exit;
     }
     self::getAddressbook($card['addressbookid']);
     //access check
     return $card;
 }
 public function checkPassword($uid, $assertion)
 {
     if ($this->_isPersonaRequest) {
         $email = OCA\User_persona\Validator::Validate($assertion);
         if ($email) {
             return OCA\User_persona\Policy::apply($email, $uid);
         }
         //we've got incorrect assertion
         OCP\Util::writeLog('OC_USER_PERSONA', 'Validation failed. Incorrect Assertion.', OCP\Util::DEBUG);
         OCP\JSON::error(array('msg' => 'Incorrect Assertion'));
         exit;
     }
     return false;
 }
Пример #6
0
function index()
{
    if (isset($_GET['fileid'])) {
        $fileIds = array($_GET['fileid']);
    } else {
        $fileIds = OCA\Search_Lucene\Indexer::getUnindexed();
    }
    $eventSource = new OC_EventSource();
    $eventSource->send('count', count($fileIds));
    $skippedDirs = explode(';', OCP\Config::getUserValue(OCP\User::getUser(), 'search_lucene', 'skipped_dirs', '.git;.svn;.CVS;.bzr'));
    foreach ($fileIds as $id) {
        $skipped = false;
        $fileStatus = OCA\Search_Lucene\Status::fromFileId($id);
        try {
            //before we start mark the file as error so we know there was a problem when the php execution dies
            $fileStatus->markError();
            $path = OC\Files\Filesystem::getPath($id);
            $eventSource->send('indexing', $path);
            foreach ($skippedDirs as $skippedDir) {
                if (strpos($path, '/' . $skippedDir . '/') !== false || strrpos($path, '/' . $skippedDir) === strlen($path) - (strlen($skippedDir) + 1)) {
                    $result = $fileStatus->markSkipped();
                    $skipped = true;
                    break;
                }
            }
            if (!$skipped) {
                if (OCA\Search_Lucene\Indexer::indexFile($path, OCP\User::getUser())) {
                    $result = $fileStatus->markIndexed();
                }
            }
            if (!$result) {
                OCP\JSON::error(array('message' => 'Could not index file.'));
                $eventSource->send('error', $path);
            }
        } catch (Exception $e) {
            //sqlite might report database locked errors when stock filescan is in progress
            //this also catches db locked exception that might come up when using sqlite
            \OCP\Util::writeLog('search_lucene', $e->getMessage() . ' Trace:\\n' . $e->getTraceAsString(), \OCP\Util::ERROR);
            OCP\JSON::error(array('message' => 'Could not index file.'));
            $eventSource->send('error', $e->getMessage());
            //try to mark the file as new to let it reindex
            $fileStatus->markNew();
            // Add UI to trigger rescan of files with status 'E'rror?
        }
    }
    $eventSource->send('done', '');
    $eventSource->close();
}
Пример #7
0
 public static function av_scan($path)
 {
     $path = $path[\OC\Files\Filesystem::signal_param_path];
     if ($path != '') {
         $files_view = \OCP\Files::getStorage("files");
         if ($files_view->file_exists($path)) {
             $root = OC_User::getHome(OC_User::getUser()) . '/files';
             $file = $root . $path;
             $result = self::clamav_scan($file);
             switch ($result) {
                 case CLAMAV_SCANRESULT_UNCHECKED:
                     //TODO: Show warning to the user: The file can not be checked
                     break;
                 case CLAMAV_SCANRESULT_INFECTED:
                     //remove file
                     $files_view->unlink($path);
                     OCP\JSON::error(array("data" => array("message" => "Virus detected! Can't upload the file.")));
                     $email = OC_Preferences::getValue(OC_User::getUser(), 'settings', 'email', '');
                     \OCP\Util::writeLog('files_antivirus', 'Email: ' . $email, \OCP\Util::DEBUG);
                     if (!empty($email)) {
                         $tmpl = new OC_Template('files_antivirus', 'notification');
                         $tmpl->assign('file', $path);
                         $tmpl->assign('host', OCP\Util::getServerHost());
                         $tmpl->assign('user', OC_User::getUser());
                         $msg = $tmpl->fetchPage();
                         $from = OCP\Util::getDefaultEmailAddress('security-noreply');
                         OCP\Util::sendMail($email, OC_User::getUser(), 'Malware detected', $msg, $from, 'ownCloud', 1);
                     }
                     exit;
                     break;
                 case CLAMAV_SCANRESULT_CLEAN:
                     //do nothing
                     break;
             }
         }
     }
 }
Пример #8
0
function bailOut($msg)
{
    OCP\JSON::error(array('data' => array('message' => $msg)));
    OCP\Util::writeLog('contacts', 'ajax/categories/delete.php: ' . $msg, OCP\Util::DEBUG);
    exit;
}
Пример #9
0
    }
    header('Content-Type: text/directory');
    header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $addressbook['displayname']) . '.vcf');
    $start = 0;
    $batchsize = OCP\Config::getUserValue(OCP\User::getUser(), 'contacts', 'export_batch_size', 20);
    while ($cardobjects = OCA\Contacts\VCard::all($bookid, $start, $batchsize, array('carddata'))) {
        foreach ($cardobjects as $card) {
            echo $card['carddata'] . $nl;
        }
        $start += $batchsize;
    }
} elseif (!is_null($contactid)) {
    try {
        $data = OCA\Contacts\VCard::find($contactid);
    } catch (Exception $e) {
        OCP\JSON::error(array('data' => array('message' => $e->getMessage())));
        exit;
    }
    header('Content-Type: text/vcard');
    header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $data['fullname']) . '.vcf');
    echo $data['carddata'];
} elseif (!is_null($selectedids)) {
    $selectedids = explode(',', $selectedids);
    $l10n = \OC_L10N::get('contacts');
    header('Content-Type: text/directory');
    header('Content-Disposition: inline; filename=' . $l10n->t('%d_selected_contacts', array(count($selectedids))) . '.vcf');
    foreach ($selectedids as $id) {
        try {
            $data = OCA\Contacts\VCard::find($id);
            echo $data['carddata'] . $nl;
        } catch (Exception $e) {
                $parentname = dirname($curdir);
                $dirs[$curdir] = $selectdir;
                $selectdir = $curdir;
            }
            if ($safeguard === 0) {
                //some funny directory loop
                OCP\JSON::error(array('data' => array('message' => 'An error occured while exploring the path: ' . $_POST['path'])));
            } else {
                foreach ($dirs as $dir => $subdir) {
                    if (strpos($dir, $localroot) !== 0) {
                        unset($dirs[$dir]);
                    }
                }
                OCP\JSON::success(array('data' => $dirs));
            }
        } else {
            //normal directory listing, return an array
            //where key is a sibdir name and value is it's full path
            $dirs = array();
            foreach (glob($path . '/*', GLOB_ONLYDIR) as $subdir) {
                $dirs[basename($subdir)] = $subdir;
            }
            OCP\JSON::success(array('data' => $dirs));
        }
    } else {
        OCP\JSON::success(array('message' => 'outside of starting dir'));
    }
} else {
    //no path provided
    OCP\JSON::error(array('data' => array('message' => 'Please provide the path for directory listing')));
}
Пример #11
0
<?php

/**
 * Copyright (c) 2012 Thomas Tanghus <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
$id = isset($_GET['id']) ? $_GET['id'] : null;
if (is_null($id)) {
    OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('No ID provided'))));
    exit;
}
$vcard = OC_Contacts_App::getContactVCard($id);
foreach ($vcard->children as $property) {
    if ($property->name == 'CATEGORIES') {
        $checksum = md5($property->serialize());
        OCP\JSON::success(array('data' => array('value' => $property->value, 'checksum' => $checksum)));
        exit;
    }
}
OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error setting checksum.'))));
Пример #12
0
 * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
OCP\JSON::checkAdminUser();
OCP\JSON::callCheck();
if (!array_key_exists('appid', $_POST)) {
    OCP\JSON::error(array('message' => 'No AppId given!'));
    return;
}
$appId = (string) $_POST['appid'];
if (!is_numeric($appId)) {
    $appId = \OC::$server->getAppConfig()->getValue($appId, 'ocsid', null);
    if ($appId === null) {
        OCP\JSON::error(array('message' => 'No OCS-ID found for app!'));
        exit;
    }
}
$appId = OC_App::cleanAppId($appId);
$config = \OC::$server->getConfig();
$config->setSystemValue('maintenance', true);
try {
    $result = OC_Installer::updateAppByOCSId($appId);
    $config->setSystemValue('maintenance', false);
} catch (Exception $ex) {
    $config->setSystemValue('maintenance', false);
    OC_JSON::error(array("data" => array("message" => $ex->getMessage())));
    return;
}
if ($result !== false) {
Пример #13
0
 * @author Robin Appelman <*****@*****.**>
 * @author Thomas Müller <*****@*****.**>
 *
 * @copyright Copyright (c) 2015, ownCloud, Inc.
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * 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, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */
// Check user and app status
OCP\JSON::checkAdminUser();
OCP\JSON::checkAppEnabled('user_ldap');
OCP\JSON::callCheck();
$prefix = (string) $_POST['ldap_serverconfig_chooser'];
$helper = new \OCA\user_ldap\lib\Helper();
if ($helper->deleteServerConfiguration($prefix)) {
    OCP\JSON::success();
} else {
    $l = \OC::$server->getL10N('user_ldap');
    OCP\JSON::error(array('message' => $l->t('Failed to delete the server configuration')));
}
Пример #14
0
    if (isset($_POST['step'])) {
        switch ($_POST['step']) {
            case 1:
                try {
                    if (isset($_POST['callback'])) {
                        $callback = $_POST['callback'];
                    } else {
                        $callback = null;
                    }
                    $token = $oauth->getRequestToken();
                    OCP\JSON::success(array('data' => array('url' => $oauth->getAuthorizeUrl($callback), 'request_token' => $token['token'], 'request_token_secret' => $token['token_secret'])));
                } catch (Exception $exception) {
                    OCP\JSON::error(array('data' => array('message' => 'Fetching request tokens failed. Verify that your Dropbox app key and secret are correct.')));
                }
                break;
            case 2:
                if (isset($_POST['request_token']) && isset($_POST['request_token_secret'])) {
                    try {
                        $oauth->setToken($_POST['request_token'], $_POST['request_token_secret']);
                        $token = $oauth->getAccessToken();
                        OCP\JSON::success(array('access_token' => $token['token'], 'access_token_secret' => $token['token_secret']));
                    } catch (Exception $exception) {
                        OCP\JSON::error(array('data' => array('message' => 'Fetching access tokens failed. Verify that your Dropbox app key and secret are correct.')));
                    }
                }
                break;
        }
    }
} else {
    OCP\JSON::error(array('data' => array('message' => 'Please provide a valid Dropbox app key and secret.')));
}
Пример #15
0
<?php

OCP\JSON::checkAppEnabled('files_versions');
OCP\JSON::callCheck();
$userDirectory = "/" . OCP\USER::getUser() . "/files";
$file = $_GET['file'];
$revision = (int) $_GET['revision'];
if (OCA_Versions\Storage::isversioned($file)) {
    if (OCA_Versions\Storage::rollback($file, $revision)) {
        OCP\JSON::success(array("data" => array("revision" => $revision, "file" => $file)));
    } else {
        OCP\JSON::error(array("data" => array("message" => "Could not revert:" . $file)));
    }
}
Пример #16
0
                $GA_VALID_CHAR = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
                $UserTokenSeed = generateRandomString(8, 64, 8, $GA_VALID_CHAR);
                //}
            } else {
                $UserTokenSeed = $_POST["UserTokenSeed"];
            }
            //$UserTokenSeed="234567234567AZAZ";
            //$UserTokenSeed="Hello!";
            //~ if (OCP\Config::getAppValue('user_otp','TokenBase32Encode',true)){
            //~ $UserTokenSeed=bin2hex(base32_decode($UserTokenSeed));
            //~ }//else{
            //$UserTokenSeed=bin2hex($UserTokenSeed);
            $UserTokenSeed = bin2hex(base32_decode($UserTokenSeed));
            //$UserTokenSeed=bin2hex(base32_decode($UserTokenSeed));
            //echo $UserTokenSeed." / ".base32_encode($UserTokenSeed);exit;
            //echo $UserTokenSeed." / ".hex2bin($UserTokenSeed);exit;
            //}
            //echo "toto";
            $result = $mOtp->CreateUser($uid, OCP\Config::getAppValue('user_otp', 'UserPrefixPin', '0') ? 1 : 0, OCP\Config::getAppValue('user_otp', 'UserAlgorithm', 'TOTP'), $UserTokenSeed, $_POST["UserPin"], OCP\Config::getAppValue('user_otp', 'UserTokenNumberOfDigits', '6'), OCP\Config::getAppValue('user_otp', 'UserTokenTimeIntervalOrLastEvent', '30'));
            //var_dump($result);
            //exit;
            if ($result) {
                OCP\JSON::success(array("data" => array("message" => $l->t("OTP Changed"))));
            } else {
                OCP\JSON::error(array("data" => array("message" => $l->t("check apps folder rights"))));
            }
        } else {
            OCP\JSON::error(array("data" => array("message" => $l->t("Invalid request"))));
        }
    }
}
Пример #17
0
    OCP\JSON::error($result);
    exit;
}
$target = $dir . '/' . $fileName;
if (\OC\Files\Filesystem::file_exists($target)) {
    $result['data'] = array('message' => (string) $l10n->t('The name %s is already used in the folder %s. Please choose a different name.', array($fileName, $dir)));
    OCP\JSON::error($result);
    exit;
}
$success = false;
$templateManager = OC_Helper::getFileTemplateManager();
$mimeType = OC_Helper::getMimetypeDetector()->detectPath($target);
$content = $templateManager->getTemplate($mimeType);
try {
    if ($content) {
        $success = \OC\Files\Filesystem::file_put_contents($target, $content);
    } else {
        $success = \OC\Files\Filesystem::touch($target);
    }
} catch (\Exception $e) {
    $result = ['success' => false, 'data' => ['message' => $e->getMessage()]];
    OCP\JSON::error($result);
    exit;
}
if ($success) {
    $meta = \OC\Files\Filesystem::getFileInfo($target);
    OCP\JSON::success(array('data' => \OCA\Files\Helper::formatFileInfo($meta)));
    return;
}
OCP\JSON::error(array('data' => array('message' => $l10n->t('Error when creating the file'))));
Пример #18
0
\OC::$server->getSession()->close();
// Get data
$dir = stripslashes($_POST["dir"]);
$allFiles = isset($_POST["allfiles"]) ? $_POST["allfiles"] : false;
// delete all files in dir ?
if ($allFiles === 'true') {
    $files = array();
    $fileList = \OC\Files\Filesystem::getDirectoryContent($dir);
    foreach ($fileList as $fileInfo) {
        $files[] = $fileInfo['name'];
    }
} else {
    $files = isset($_POST["file"]) ? $_POST["file"] : $_POST["files"];
    $files = json_decode($files);
}
$filesWithError = '';
$success = true;
//Now delete
foreach ($files as $file) {
    if (\OC\Files\Filesystem::file_exists($dir . '/' . $file) && !\OC\Files\Filesystem::unlink($dir . '/' . $file)) {
        $filesWithError .= $file . "\n";
        $success = false;
    }
}
// get array with updated storage stats (e.g. max file size) after upload
$storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
if ($success) {
    OCP\JSON::success(array("data" => array_merge(array("dir" => $dir, "files" => $files), $storageStats)));
} else {
    OCP\JSON::error(array("data" => array_merge(array("message" => "Could not delete:\n" . $filesWithError), $storageStats)));
}
Пример #19
0
 * @copyright 2012 Jakob Sack <*****@*****.**>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library 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 library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('mail');
$accounts = OCA_Mail\App::getFolders(OCP\User::getUser());
//
// TODO: error is listed within the accounts
//
if ($accounts['error']) {
    OCP\JSON::error(array('data' => array('message' => $accounts['error'])));
    exit;
}
$tmpl = new OCP\Template('mail', 'part.folders');
$tmpl->assign('accounts', $accounts);
$page = $tmpl->fetchPage();
OCP\JSON::success(array('data' => $page));
Пример #20
0
                    $error = $l->t('Upload failed. Could not find uploaded file');
                }
            } catch (Exception $ex) {
                $error = $ex->getMessage();
            }
        } else {
            // file already exists
            $meta = \OC\Files\Filesystem::getFileInfo($target);
            if ($meta === false) {
                $error = $l->t('Upload failed. Could not get file info.');
            } else {
                $data = \OCA\Files\Helper::formatFileInfo($meta);
                $data['permissions'] = $data['permissions'] & $allowedPermissions;
                $data['status'] = 'existserror';
                $data['originalname'] = $files['tmp_name'][$i];
                $data['uploadMaxFilesize'] = $maxUploadFileSize;
                $data['maxHumanFilesize'] = $maxHumanFileSize;
                $data['permissions'] = $meta['permissions'] & $allowedPermissions;
                $data['directory'] = $returnedDir;
                $result[] = $data;
            }
        }
    }
} else {
    $error = $l->t('Invalid directory.');
}
if ($error === false) {
    OCP\JSON::encodedPrint($result);
} else {
    OCP\JSON::error(array(array('data' => array_merge(array('message' => $error, 'code' => $errorCode), $storageStats))));
}
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library 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 library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
// Check user and app status
OCP\JSON::checkAdminUser();
OCP\JSON::checkAppEnabled('user_ldap');
OCP\JSON::callCheck();
$l = OC_L10N::get('user_ldap');
$ldapWrapper = new OCA\user_ldap\lib\LDAP();
$connection = new \OCA\user_ldap\lib\Connection($ldapWrapper, '', null);
//needs to be true, otherwise it will also fail with an irritating message
$_POST['ldap_configuration_active'] = 1;
if ($connection->setConfiguration($_POST)) {
    //Configuration is okay
    if ($connection->bind()) {
        OCP\JSON::success(array('message' => $l->t('The configuration is valid and the connection could be established!')));
    } else {
        OCP\JSON::error(array('message' => $l->t('The configuration is valid, but the Bind failed. Please check the server settings and credentials.')));
    }
} else {
    OCP\JSON::error(array('message' => $l->t('The configuration is invalid. Please have a look at the logs for further details.')));
}
Пример #22
0
            $params = array('scope' => $scope, 'oauth_callback' => $callback);
            $request = OAuthRequest::from_consumer_and_token($consumer, null, 'GET', $url, $params);
            $request->sign_request($sigMethod, $consumer, null);
            $response = send_signed_request('GET', $url, array($request->to_header()), null, false);
            $token = array();
            parse_str($response, $token);
            if (isset($token['oauth_token']) && isset($token['oauth_token_secret'])) {
                $authUrl = 'https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=' . $token['oauth_token'];
                OCP\JSON::success(array('data' => array('url' => $authUrl, 'request_token' => $token['oauth_token'], 'request_token_secret' => $token['oauth_token_secret'])));
            } else {
                OCP\JSON::error(array('data' => array('message' => 'Fetching request tokens failed. Error: ' . $response)));
            }
            break;
        case 2:
            if (isset($_POST['oauth_verifier']) && isset($_POST['request_token']) && isset($_POST['request_token_secret'])) {
                $token = new OAuthToken($_POST['request_token'], $_POST['request_token_secret']);
                $url = 'https://www.google.com/accounts/OAuthGetAccessToken';
                $request = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $url, array('oauth_verifier' => $_POST['oauth_verifier']));
                $request->sign_request($sigMethod, $consumer, $token);
                $response = send_signed_request('GET', $url, array($request->to_header()), null, false);
                $token = array();
                parse_str($response, $token);
                if (isset($token['oauth_token']) && isset($token['oauth_token_secret'])) {
                    OCP\JSON::success(array('access_token' => $token['oauth_token'], 'access_token_secret' => $token['oauth_token_secret']));
                } else {
                    OCP\JSON::error(array('data' => array('message' => 'Fetching access tokens failed. Error: ' . $response)));
                }
            }
            break;
    }
}
Пример #23
0
    $path = $dir . '/' . $file;
    if ($dir === '/') {
        $file = ltrim($file, '/');
        $delimiter = strrpos($file, '.d');
        $filename = substr($file, 0, $delimiter);
        $timestamp = substr($file, $delimiter + 2);
    } else {
        $path_parts = pathinfo($file);
        $filename = $path_parts['basename'];
        $timestamp = null;
    }
    if (!OCA\Files_Trashbin\Trashbin::restore($path, $filename, $timestamp)) {
        $error[] = $filename;
        \OCP\Util::writeLog('trashbin', 'can\'t restore ' . $filename, \OCP\Util::ERROR);
    } else {
        $success[$i]['filename'] = $file;
        $success[$i]['timestamp'] = $timestamp;
        $i++;
    }
}
if ($error) {
    $filelist = '';
    foreach ($error as $e) {
        $filelist .= $e . ', ';
    }
    $l = OC::$server->getL10N('files_trashbin');
    $message = $l->t("Couldn't restore %s", array(rtrim($filelist, ', ')));
    OCP\JSON::error(array("data" => array("message" => $message, "success" => $success, "error" => $error)));
} else {
    OCP\JSON::success(array("data" => array("success" => $success)));
}
Пример #24
0
/**
 * Copyright (c) 2012 Georg Ehrke <*****@*****.**>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */
$data = $_POST['data'];
$data = explode(',', $data);
$data = end($data);
$data = base64_decode($data);
OCP\JSON::checkLoggedIn();
OCP\App::checkAppEnabled('calendar');
$import = new OC_Calendar_Import($data);
$import->setUserID(OCP\User::getUser());
$import->setTimeZone(OC_Calendar_App::$tz);
$import->disableProgressCache();
if (!$import->isValid()) {
    OCP\JSON::error();
    exit;
}
$newcalendarname = strip_tags($import->createCalendarName());
$newid = OC_Calendar_Calendar::addCalendar(OCP\User::getUser(), $newcalendarname, 'VEVENT,VTODO,VJOURNAL', null, 0, $import->createCalendarColor());
$import->setCalendarID($newid);
$import->import();
$count = $import->getCount();
if ($count == 0) {
    OC_Calendar_Calendar::deleteCalendar($newid);
    OCP\JSON::error(array('message' => OC_Calendar_App::$l10n->t('The file contained either no events or all events are already saved in your calendar.')));
} else {
    OCP\JSON::success(array('message' => $count . ' ' . OC_Calendar_App::$l10n->t('events has been saved in the new calendar') . ' ' . $newcalendarname, 'eventSource' => OC_Calendar_Calendar::getEventSourceInfo(OC_Calendar_Calendar::find($newid))));
}
Пример #25
0
$userDirectory = '/' . OCP\USER::getUser() . '/files';
$sources = explode(';', $_POST['sources']);
$uid_shared_with = $_POST['uid_shared_with'];
$permissions = $_POST['permissions'];
foreach ($sources as $source) {
    $file = OC_FileCache::get($source);
    $path = ltrim($source, '/');
    $source = $userDirectory . $source;
    // Check if the file exists or if the file is being reshared
    if ($source && $file['encrypted'] == false && (OC_FILESYSTEM::file_exists($path) && OC_FILESYSTEM::is_readable($path) || OC_Share::getSource($source))) {
        try {
            $shared = new OC_Share($source, $uid_shared_with, $permissions);
            // If this is a private link, return the token
            if ($uid_shared_with == OC_Share::PUBLICLINK) {
                OCP\JSON::success(array('data' => $shared->getToken()));
            } else {
                OCP\JSON::success();
            }
        } catch (Exception $exception) {
            OCP\Util::writeLog('files_sharing', 'Unexpected Error : ' . $exception->getMessage(), OCP\Util::ERROR);
            OCP\JSON::error(array('data' => array('message' => $exception->getMessage())));
        }
    } else {
        if ($file['encrypted'] == true) {
            OCP\JSON::error(array('data' => array('message' => 'Encrypted files cannot be shared')));
        } else {
            OCP\Util::writeLog('files_sharing', 'File does not exist or is not readable :' . $source, OCP\Util::ERROR);
            OCP\JSON::error(array('data' => array('message' => 'File does not exist or is not readable')));
        }
    }
}
Пример #26
0
 /**
  * @brief checks if an event was edited and dies if it was
  * @param (object) $vevent - vevent object of the event
  * @param (int) $lastmodified - time of last modification as unix timestamp
  * @return (bool)
  */
 public static function isNotModified($vevent, $lastmodified)
 {
     $last_modified = $vevent->__get('LAST-MODIFIED');
     if ($last_modified && $lastmodified != $last_modified->getDateTime()->format('U')) {
         OCP\JSON::error(array('modified' => true));
         exit;
     }
     return true;
 }
Пример #27
0
            $mailNotification = new \OC\Share\MailNotifications();
            $expiration = null;
            if (isset($_POST['expiration']) && $_POST['expiration'] !== '') {
                try {
                    $date = new DateTime((string) $_POST['expiration']);
                    $expiration = $date->getTimestamp();
                } catch (Exception $e) {
                    \OCP\Util::writeLog('sharing', "Couldn't read date: " . $e->getMessage(), \OCP\Util::ERROR);
                }
            }
            $result = $mailNotification->sendLinkShareMail($to_address, $file, $link, $expiration);
            if (empty($result)) {
                \OCP\JSON::success();
            } else {
                $l = \OC::$server->getL10N('core');
                OCP\JSON::error(array('data' => array('message' => $l->t("Couldn't send mail to following users: %s ", implode(', ', $result)))));
            }
            break;
    }
} else {
    if (isset($_GET['fetch'])) {
        switch ($_GET['fetch']) {
            case 'getItemsSharedStatuses':
                if (isset($_GET['itemType'])) {
                    $return = OCP\Share::getItemsShared((string) $_GET['itemType'], OCP\Share::FORMAT_STATUSES);
                    is_array($return) ? OC_JSON::success(array('data' => $return)) : OC_JSON::error();
                }
                break;
            case 'getItem':
                if (isset($_GET['itemType']) && isset($_GET['itemSource']) && isset($_GET['checkReshare']) && isset($_GET['checkShares'])) {
                    if ($_GET['checkReshare'] == 'true') {
Пример #28
0
<?php

// Init owncloud
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
// Get the params
$dir = isset($_POST['dir']) ? stripslashes($_POST['dir']) : '';
$foldername = isset($_POST['foldername']) ? stripslashes($_POST['foldername']) : '';
if (trim($foldername) == '') {
    OCP\JSON::error(array("data" => array("message" => "Empty Foldername")));
    exit;
}
if (strpos($foldername, '/') !== false) {
    OCP\JSON::error(array("data" => array("message" => "Invalid Foldername")));
    exit;
}
if (OC_Files::newFile($dir, stripslashes($foldername), 'dir')) {
    OCP\JSON::success(array("data" => array()));
    exit;
}
OCP\JSON::error(array("data" => array("message" => "Error when creating the folder")));
Пример #29
0
OCP\JSON::checkAppEnabled('files_external');
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();
$l = \OC::$server->getL10N('files_external');
if (isset($_POST['client_id']) && isset($_POST['client_secret']) && isset($_POST['redirect'])) {
    $client = new Google_Client();
    $client->setClientId($_POST['client_id']);
    $client->setClientSecret($_POST['client_secret']);
    $client->setRedirectUri($_POST['redirect']);
    $client->setScopes(array('https://www.googleapis.com/auth/drive'));
    if (isset($_POST['step'])) {
        $step = $_POST['step'];
        if ($step == 1) {
            try {
                $authUrl = $client->createAuthUrl();
                OCP\JSON::success(array('data' => array('url' => $authUrl)));
            } catch (Exception $exception) {
                OCP\JSON::error(array('data' => array('message' => $l->t('Step 1 failed. Exception: %s', array($exception->getMessage())))));
            }
        } else {
            if ($step == 2 && isset($_POST['code'])) {
                try {
                    $token = $client->authenticate($_POST['code']);
                    OCP\JSON::success(array('data' => array('token' => $token)));
                } catch (Exception $exception) {
                    OCP\JSON::error(array('data' => array('message' => $l->t('Step 2 failed. Exception: %s', array($exception->getMessage())))));
                }
            }
        }
    }
}
Пример #30
0
 * @copyright 2012 Arthur Schiwon blizzz@owncloud.com
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or any later version.
 *
 * This library 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 library.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
// Check user and app status
OCP\JSON::checkAdminUser();
OCP\JSON::checkAppEnabled('user_ldap');
OCP\JSON::callCheck();
$connection = new \OCA\user_ldap\lib\Connection(null);
if ($connection->setConfiguration($_POST)) {
    //Configuration is okay
    if ($connection->bind()) {
        OCP\JSON::success(array('message' => 'The configuration is valid and the connection could be established!'));
    } else {
        OCP\JSON::error(array('message' => 'The configuration is valid, but the Bind failed. Please check the server settings and credentials.'));
    }
} else {
    OCP\JSON::error(array('message' => 'The configuration is invalid. Please look in the ownCloud log for further details.'));
}