/** @BeforeFeature */ public static function prepareForTheFeature() { @http_delete(ELASTICSEARCH . '/cncflora_test0', []); @http_delete(ELASTICSEARCH . '/cncflora_test1', []); @http_delete(COUCHDB . '/cncflora_test0', []); @http_delete(COUCHDB . '/cncflora_test1', []); @http_put(ELASTICSEARCH . '/cncflora_test0', []); @http_put(ELASTICSEARCH . '/cncflora_test1', []); @http_put(COUCHDB . '/cncflora_test0', []); @http_put(COUCHDB . '/cncflora_test1', []); $file = file_get_contents(__DIR__ . "/load.json"); $json = json_decode($file); $r = http_post(COUCHDB . "/cncflora_test0/_bulk_docs", array('docs' => $json)); foreach ($json as $doc) { $doc->id = $doc->_id; foreach ($r as $revs) { if ($revs->id == $doc->_id) { $doc->rev = $revs->rev; $doc->_rev = $revs->rev; } } http_put(ELASTICSEARCH . '/cncflora_test0/' . $doc->metadata->type . '/' . $doc->_id, $doc); } sleep(1); }
/** * Removes all selectedSubmissions of a user regarding * a particular sheet. * * @param $uid The id of the user * @param $sid The id of the sheet */ function removeSelectedSubmission($uid, $sid) { global $databaseURI; $URI = $databaseURI . "/selectedsubmission/user/{$uid}/exercisesheet/{$sid}"; http_delete($URI, true, $message); if ($message == "201") { return true; } else { return false; } }
* @author Ralf Busch */ include_once dirname(__FILE__) . '/include/Boilerplate.php'; include_once dirname(__FILE__) . '/../Assistants/Structures.php'; include_once dirname(__FILE__) . '/../Assistants/LArraySorter.php'; global $globalUserData; Authentication::checkRights(PRIVILEGE_LEVEL::ADMIN, $cid, $uid, $globalUserData); $langTemplate = 'Admin_Controller'; Language::loadLanguageFile('de', $langTemplate, 'json', dirname(__FILE__) . '/'); $sheetNotifications = array(); if (isset($_POST['action'])) { if ($_POST['action'] == "ExerciseSheetLecturer" && isset($_POST['deleteSheetWarning'])) { $sheetNotifications[$_POST['deleteSheetWarning']][] = MakeNotification("warning", Language::Get('main', 'askDeleteSubmission', $langTemplate)); } elseif ($_POST['action'] == "ExerciseSheetLecturer" && isset($_POST['deleteSheet'])) { $URL = $logicURI . "/exercisesheet/exercisesheet/{$_POST['deleteSheet']}"; $result = http_delete($URL, true, $message); if ($message == 201) { $sheetNotifications[$_POST['deleteSheet']][] = MakeNotification('success', Language::Get('main', 'successDeleteSubmission', $langTemplate)); } else { $sheetNotifications[$_POST['deleteSheet']][] = MakeNotification('error', Language::Get('main', 'errorDeleteSubmission', $langTemplate)); } } } // load GetSite data for Admin.php $URL = $getSiteURI . "/admin/user/{$uid}/course/{$cid}"; $admin_data = http_get($URL, true); $admin_data = json_decode($admin_data, true); $admin_data['filesystemURI'] = $filesystemURI; $admin_data['cid'] = $cid; $user_course_data = $admin_data['user']; $menu = MakeNavigationElement($user_course_data, PRIVILEGE_LEVEL::ADMIN);
set_error("409"); exit; } } else { $grantRightsNotifications[] = MakeNotification("error", Language::Get('main', 'noSelectedUser', $langTemplate)); } } elseif ($_POST['action'] == "RevokeRights") { // check if POST data is send if (isset($_POST['userID'])) { // clean Input $userID = cleanInput($_POST['userID']); // validate POST data if (is_numeric($userID) == true) { // delete coursestatus $url = $databaseURI . "/coursestatus/course/{$cid}/user/{$userID}"; http_delete($url, true, $message); // show notification if ($message == "201") { $revokeRightsNotifications[] = MakeNotification("success", Language::Get('main', 'successRemoveUser', $langTemplate)); } } else { // otherwise show conflict page set_error("409"); exit; } } else { $revokeRightsNotifications[] = MakeNotification("error", Language::Get('main', 'noSelectedUser', $langTemplate)); } } elseif ($_POST['action'] == "AddUser") { $f = new FormEvaluator($_POST); $f->checkStringForKey('userName', FormEvaluator::REQUIRED, 'warning', Language::Get('main', 'invalidUserName', $langTemplate), array('min' => 1));
function http_multi(&$requests) { $handles = array(); $responses = array(); foreach ($requests as $req) { $url = $req['url']; $method = isset($req['method']) ? strtoupper($req['method']) : 'GET'; $body = is_array($req['body']) ? $req['body'] : null; $headers = is_array($req['headers']) ? $req['headers'] : array(); $more = is_array($req['more']) ? $req['more'] : array(); $more['return_curl_handle'] = 1; if ($method == 'HEAD') { $ch = http_head($url, $headers, $more); } else { if ($method == 'GET') { $ch = http_get($url, $headers, $more); } else { if ($method == 'POST') { $ch = http_post($url, $body, $headers, $more); } else { if ($method == 'DELETE') { $ch = http_delete($url, $body, $headers, $more); } else { if ($method == 'PUT') { $ch = http_put($url, $body, $headers, $more); } else { log_warning("http", "unsupported HTTP method : {$method}"); continue; } } } } } $handles[] = $ch; } # http://us.php.net/manual/en/function.curl-multi-init.php $mh = curl_multi_init(); foreach ($handles as $ch) { curl_multi_add_handle($mh, $ch); } $active = null; $start = microtime_ms(); # this syntax makes my eyes bleed but whatever... # (20110822/straup) do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); while ($active && $mrc == CURLM_OK) { if (curl_multi_select($mh) != -1) { do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); } } $end = microtime_ms(); $GLOBALS['timings']['http_count'] += count($handlers); $GLOBALS['timings']['http_time'] += $end - $start; foreach ($handles as $ch) { $raw = curl_multi_getcontent($ch); $info = curl_getinfo($ch); curl_multi_remove_handle($mh, $ch); $rsp = _http_parse_response($raw, $info); $responses[] = $rsp; } curl_multi_close($mh); return $responses; }
/** * Logs out a user. * * @param bool $noback Set it manually to true, if no back-redirection-url is wanted. */ public static function logoutUser($noback = false) { global $databaseURI; // delete session in DB if (isset($_SESSION['SESSION'])) { $session = $_SESSION['SESSION']; http_delete("{$databaseURI}/session/{$session}", true, $message, true); } // delete session in UI session_destroy(); if ($noback == true || isset($_GET['action']) && $_GET['action'] == "logout") { // redirect to Loginpage header('Location: Login.php'); } else { // get current relative url $backurl = basename(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); // if someone opens a page with /UI (without index.php) or a existing page without .php suffix if (!strpos($backurl, '.php') && !file_exists($backurl . ".php")) { $backurl = "index.php"; } elseif (!strpos($backurl, '.php') && file_exists($backurl . ".php")) { $backurl = $backurl . ".php"; } // Url GET parameters $urlparameters = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY); if ($urlparameters != "") { $urlparameters = "?" . rawurlencode($urlparameters); } // redirect to Loginpage and save current page in GET param header('Location: Login.php?back=' . $backurl . $urlparameters); } exit; }
<?php session_start(); include "../conn/ws-conn.php"; include "../page-util.php"; $id = $_GET[id]; if ($id != "") { http_delete("user/" . $id); } page_redirect("../index.php?action=user");
/** * Logs in a user. * * @param string $username * @param string $password * @return true if login is successful */ public function loginUser($username, $password) { global $databaseURI; global $logicURI; // check if logged in in studip $studip = $this->checkUserInStudip($this->uid, $this->sid); $studipStatus = null; if ($studip == true) { ///Logger::Log("inStudip", LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log'); $url = "{$databaseURI}/user/user/{$username}"; $message = null; $this->userData = http_get($url, false, $message); ///Logger::Log("ostepuUser_url: ".$url, LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log'); ///Logger::Log("ostepuUser_message: ".$message, LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log'); ///Logger::Log("ostepuUser_data: ".$this->userData, LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log'); $this->userData = json_decode($this->userData, true); // check if user exists in our system if ($message != "404" && empty($this->userData) == false) { // save logged in uid $_SESSION['UID'] = $this->userData['id']; // refresh Session in UI and DB $refresh = $this->refreshSession(); if (isset($_GET['vid']) && (!isset($_GET['cid']) || $this->cid === null)) { // convert vid to cid // create course if does not exist $this->cid = $this->convertVidToCid($_GET['vid']); ///Logger::Log("cid: ".$this->cid , LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log'); if ($this->cid === null) { // create course $studipStatus = $this->getUserStatusInStudip($this->uid, $this->vid); if ($studipStatus === CourseStatus::getStatusDefinition(true)['administrator']) { ///Logger::Log("createCourse>>".$_GET['vid'] , LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log'); $courseObject = $this->getCourseInStudip($this->vid); if ($courseObject !== null) { $url = "{$logicURI}/course"; $courseObject = http_post_data($url, Course::encodeCourse($courseObject), false, $message); if ($message === 201) { // new course was created $courseObject = Course::decodeCourse($courseObject); if ($courseObject !== null) { $this->cid = $courseObject->getId(); $url = "{$databaseURI}/externalid"; $externalId = ExternalId::createExternalId('S_' . $_GET['vid'], $this->cid); $externalId = http_post_data($url, ExternalId::encodeExternalId($externalId), false, $message); if ($message !== 201) { // create externalId fails, remove course $url = "{$logicURI}/course/course/" . $this->cid; http_delete($url, false, $message); $this->cid = null; } if ($this->cid !== null && $studipStatus === CourseStatus::getStatusDefinition(true)['administrator']) { // redirect user to course settings /// ??? } } } } } } } if (!isset($this->cid) || $this->cid === null) { set_error("unbekannte Veranstaltung!!!"); exit; } // get the courseStatus for given course $this->courseStatus = $this->findCourseStatus(); ///Logger::Log("courseStatus: ".$this->courseStatus , LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log'); // if user has no status in course create it if (!isset($this->courseStatus)) { if ($studipStatus === null) { $studipStatus = $this->getUserStatusInStudip($this->uid, $this->vid); } if ($studipStatus !== null) { ///Logger::Log("createCourseStatus" , LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log'); // check whether an registration is allowed $courseData = $this->getCourseData($this->cid); if ($courseData === null) { // no course data set_error("Keine Veranstaltung gefunden!"); exit; } if ($courseData->getSettings() !== null) { $end = Course::containsSetting($courseData, 'RegistrationPeriodEnd'); if ($end !== null && $end != 0 && $end < time()) { // no registration allowed set_error("Eine Anmeldung ist nicht möglich!!! Ablaufdatum: " . date('d.m.Y - H:i', $end)); exit; } } $CourseStatusResponse = $this->createCourseStatus($this->userData['id'], $this->cid, $studipStatus); // set courseStatus to studipStatus only if status is created in DB successfully if ($CourseStatusResponse == true) { $this->courseStatus = $studipStatus; } } } return $refresh; } else { // get new user from studIP $newUser = $this->getUserInStudip($username); // if user is a valid user if ($newUser != "not found") { ///Logger::Log("creatUser: "******""); } } } } return false; }
foreach ($markingList as $markingId => $subs) { $subs = $subs[0]; $sub = new Submission(); $sub->setId($subs); if ($owner == -1) { // from unassigned to tutor (creates new marking) $marking = new Marking(); $marking->setSubmission($sub); $marking->setStatus(1); $marking->setTutorId($selectedTutorID); $markings[] = $marking; } else { if ($selectedTutorID == -1) { // remove assignment from tutor (removes the specified marking) $URI = $serverURI . "/logic/LMarking/marking/marking/" . $markingId; http_delete($URI, true, $message); } else { // move assignment from tutor to tutor $marking = new Marking(); $marking->setId($markingId); $marking->setTutorId($selectedTutorID); $markings[] = $marking; } } } } // "unassigned" can't obtain proposals (-1 -> "unassiged") if ($selectedTutorID != -1) { foreach ($proposals as $props) { // assign to selected tutor $sub = new Submission();
if ($_POST['action'] == 'edit') { $errormsg = Language::Get('main', 'successEditSheet', $langTemplate); } else { $errormsg = Language::Get('main', 'successCreateSheet', $langTemplate); } array_push($notifications, MakeNotification('success', $errormsg)); } else { if ($_POST['action'] == 'edit') { $errormsg = Language::Get('main', 'errorEditSheet', $langTemplate); } else { $errormsg = Language::Get('main', 'errorCreateSheet', $langTemplate); } array_push($notifications, MakeNotification('error', $errormsg)); // delete exercisesheet if exercises are going wrong if ($_POST['action'] == 'new') { http_delete($logicURI . '/DB/exercisesheet/exercisesheet/' . $output['id'], true, $message); } } } else { if ($_POST['action'] == 'edit') { $errormsg = Language::Get('main', 'errorEditSheet', $langTemplate); } else { $errormsg = Language::Get('main', 'errorCreateSheet', $langTemplate); } array_push($notifications, MakeNotification('error', $errormsg)); } } else { $notifications = array_merge($notifications, $f->notifications); } } if (isset($sid)) {