function add_first_user() { global $input; // Add the first user in database $first_user = file_get_contents("../first_user"); $first_user = explode(" , ", $first_user); $user_ID = $first_user[0]; $surname = $first_user[3]; $forename = $first_user[2]; $passwd = $first_user[1]; $permissions = 1; // try { if (!db_ready()) { db_prepare(); } db_user_create($user_ID, $surname, $forename, $passwd, $permissions); add_admin_to_file($user_ID); push_users_to_ezmanager(); db_log(db_gettable('users'), 'Created user ' . $user_ID, $_SESSION['user_login']); db_close(); // } catch (PDOException $e) { // $errors['db_error'] = $e->getMessage(); // require template_getpath('install.php'); // die; // } session_destroy(); unlink("../first_user"); require template_getpath('install_success.php'); }
/** * Pushes users (htpasswd) and associations between users and courses (courselist.php) */ function push_users_courses_to_recorder() { global $recorder_user; global $recorder_basedir; global $recorder_subdir; global $recorder_password_storage_enabled; if (!db_ready()) { db_prepare(statements_get()); } $users = db_users_in_recorder_get(); $classrooms = db_classrooms_list_enabled(); //htpasswd $htpasswd = ''; $previous_user = ""; foreach ($users as $u) { if ($previous_user != $u['user_ID']) { $htpasswd .= $u['user_ID'] . ':' . $u['recorder_passwd'] . PHP_EOL; $previous_user = $u['user_ID']; } } file_put_contents('var/htpasswd', $htpasswd); //courselist.php $courselist = '<?php' . PHP_EOL; foreach ($users as $u) { $title = isset($u['shortname']) && !empty($u['shortname']) ? $u['shortname'] : $u['course_name']; $courselist .= '$course[\'' . $u['user_ID'] . '\'][\'' . $u['course_code'] . '\'] = "' . $title . '";' . PHP_EOL; $courselist .= '$users[\'' . $u['user_ID'] . '\'][\'full_name\']="' . $u['forename'] . ' ' . $u['surname'] . '";' . PHP_EOL; $courselist .= '$users[\'' . $u['user_ID'] . '\'][\'email\']="";' . PHP_EOL; } $courselist .= '?>'; file_put_contents('var/courselist.php', $courselist); // Upload all this on server foreach ($classrooms as $c) { exec('ping ' . $c['IP'] . ' 10', $output, $return_val); if ($return_val == 0) { $cmd = 'scp -o ConnectTimeout=10 ./var/htpasswd ' . $recorder_user . '@' . $c['IP'] . ':' . $recorder_basedir . $recorder_subdir; exec($cmd, $output, $return_var); $cmd = 'scp -o ConnectTimeout=10 ./var/courselist.php ' . $recorder_user . '@' . $c['IP'] . ':' . $recorder_basedir . $recorder_subdir; exec($cmd, $output, $return_var); } } return true; }