Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions nightly_db_backup/db_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:file: db_backup.py
:language: python3
:author: Peter Bailie (Systems Programmer, Dept. of Computer Science, RPI)
:date: May 22 2018
:date: August 22 2018

This script will take backup dumps of each individual Submitty course
database. This should be set up by a sysadmin to be run on the Submitty
Expand All @@ -31,16 +31,17 @@

import argparse
import datetime
import json
import os
import re
import subprocess
import sys

# CONFIGURATION
DB_HOST = 'submitty.cs.myuniversity.edu'
DB_USER = 'hsdbu'
DB_PASS = 'DB.p4ssw0rd' # CHANGE THIS! DO NOT USE 'DB.p4ssw0rd'
DUMP_PATH = '/var/local/submitty-dumps'
# DATABASE CONFIGURATION PATH
DB_CONFIG_PATH = '/usr/local/submitty/config/database.json'

# WHERE DUMP FILES ARE WRITTEN
DUMP_PATH = '/var/local/submitty/submitty-dumps'

def delete_obsolete_dumps(working_path, expiration_stamp):
"""
Expand Down Expand Up @@ -111,6 +112,14 @@ def main():
else:
semester = args.t

# GET DATABASE CONFIG FROM SUBMITTY
fh = open(DB_CONFIG_PATH, "r")
db_config = json.load(fh)
fh.close()
DB_HOST = db_config['database_host']
DB_USER = db_config['database_user']
DB_PASS = db_config['database_password']

# GET ACTIVE COURSES FROM 'MASTER' DB
try:
sql = "select course from courses where semester='{}'".format(semester)
Expand Down
22 changes: 14 additions & 8 deletions pam_accounts/accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@
error_reporting(null);
ini_set('display_errors', '0');

//Database access
define('DB_LOGIN', 'submitty_dbuser');
define('DB_PASSWD', 'submitty_dbuser_pa55W0rd');
define('DB_HOST', 'localhost');
//Database access configuration from Submitty
define('DB_CONFIG_PATH', '/usr/local/submitty/config/database.json');

//Location of accounts creation error log file
define('ERROR_LOG_FILE', 'accounts_script_error.log');
Expand Down Expand Up @@ -88,6 +86,11 @@ public function __construct() {
exit("This script must be run as root." . PHP_EOL);
}

//This is run from the command line, not a webpage.
if (PHP_SAPI !== 'cli') {
exit("This script must be run from the command line." . PHP_EOL);
}

//Init class properties, quit on error.
if ($this->init() === false) {
exit(1);
Expand Down Expand Up @@ -211,10 +214,13 @@ private function process() {
* @return boolean TRUE on success, FALSE when there is a problem.
*/
private function db_connect() {
$db_user = DB_LOGIN;
$db_pass = DB_PASSWD;
$db_host = DB_HOST;
self::$db_conn = pg_connect("host={$db_host} dbname=submitty user={$db_user} password={$db_pass} sslmode=prefer");
$json_str = file_get_contents(DB_CONFIG_PATH);
$db_config = json_decode($json_str, true);
$db_host = $db_config['database_host'];
$db_user = $db_config['database_user'];
$db_pass = $db_config['database_password'];

self::$db_conn = pg_connect("dbname=submitty host={$db_host} user={$db_user} password={$db_pass} sslmode=prefer");
if (pg_connection_status(self::$db_conn) !== PGSQL_CONNECTION_OK) {
$this->log_it(pg_last_error(self::$db_conn));
return false;
Expand Down
2 changes: 1 addition & 1 deletion sample_bin/map_course.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
$db_config = json_decode($json_str, true);

//Connect to master DB.
$db_conn = pg_connect("dbname=submitty host={$db_config['database_host']} user={$db_config['database_user']} password={$db_config['database_password']}");
$db_conn = pg_connect("dbname=submitty host={$db_config['database_host']} user={$db_config['database_user']} password={$db_config['database_password']} sslmode=prefer");
if (pg_connection_status($db_conn) !== PGSQL_CONNECTION_OK) {
exit(sprintf("ERROR: Could not establish connection to Submitty Master DB%sCheck configuration at %s%s", PHP_EOL, DB_CONFIG_PATH, PHP_EOL));
}
Expand Down