Commit 18e875c9 authored by Reto Da Forno's avatar Reto Da Forno
Browse files

merge test_start/end_planned/_act as they are the same, and some cleanup

parent 741d63c2
......@@ -247,10 +247,8 @@ CREATE TABLE `tbl_serv_tests` (
`description` text COLLATE utf8_bin,
`owner_fk` int(10) unsigned NOT NULL,
`testconfig_xml` longtext COLLATE utf8_bin NOT NULL,
`time_start_wish` datetime NOT NULL,
`time_start_act` datetime DEFAULT NULL,
`time_end_wish` datetime NOT NULL,
`time_end_act` datetime DEFAULT NULL,
`time_start` datetime NOT NULL,
`time_end` datetime NOT NULL,
`setuptime` int(11) DEFAULT NULL COMMENT 'Time needed to setup the test',
`cleanuptime` int(11) DEFAULT NULL COMMENT 'Time needed to cleanup the test',
`test_status` enum('not schedulable','planned','preparing','running','cleaning up','syncing','synced','finished','aborting','failed','todelete','deleted','retention expiring') COLLATE utf8_bin NOT NULL DEFAULT 'not schedulable',
......
......@@ -112,8 +112,8 @@ def main(argv):
else:
try:
# Check for tests to delete ---
sql = """SELECT `serv_tests_key`, `time_start_wish`
FROM `tbl_serv_tests`
sql = """SELECT `serv_tests_key`, `time_start`
FROM `tbl_serv_tests`
WHERE (`test_status` = 'todelete')
"""
if ( cur.execute(sql) <= 0 ):
......@@ -190,7 +190,7 @@ def main(argv):
# Check for tests that are stuck ---
sql = """SELECT `serv_tests_key` FROM `tbl_serv_tests`
WHERE ((`test_status` IN ('preparing', 'aborting', 'cleaning up', 'syncing', 'synced')) OR (`test_status` = 'running' AND `dispatched` = 1))
AND (TIMESTAMPDIFF(MINUTE, `time_end_wish`, '%s') > %d)
AND (TIMESTAMPDIFF(MINUTE, `time_end`, '%s') > %d)
"""
if cur.execute(sql % (now, maxtestcleanuptime)) <= 0:
logger.debug("No stuck tests found.")
......@@ -211,7 +211,7 @@ def main(argv):
# Check for tests that are still running, but should have been stopped (NOTE: needs to be AFTER the checking for stuck tests!) ---
sql = """SELECT `serv_tests_key`, `test_status` FROM `tbl_serv_tests`
WHERE (`test_status` = 'running') AND (`time_end_wish` <= '%s') AND (`dispatched` = 0)
WHERE (`test_status` = 'running') AND (`time_end` <= '%s') AND (`dispatched` = 0)
"""
cur.execute(sql % (now))
rs = cur.fetchall()
......@@ -245,7 +245,7 @@ def main(argv):
testid = int(command.split('testid=', 1)[1].split()[0])
# check stop time of this test
sql = """SELECT `serv_tests_key` FROM `tbl_serv_tests`
WHERE `serv_tests_key`=%d AND TIMESTAMPDIFF(MINUTE, `time_end_wish`, '%s') > %d
WHERE `serv_tests_key`=%d AND TIMESTAMPDIFF(MINUTE, `time_end`, '%s') > %d
"""
if cur.execute(sql % (testid, now, maxtestcleanuptime)) > 0:
# thread is stuck -> add to list and kill
......
......@@ -313,7 +313,7 @@ def start_test(testid, cur, cn, obsdict_key, obsdict_id):
flocklab.set_test_status(cur, cn, testid, 'preparing')
# Get start/stop time ---
cur.execute("SELECT `time_start_wish`, `time_end_wish`, `owner_fk` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" %testid)
cur.execute("SELECT `time_start`, `time_end`, `owner_fk` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" %testid)
# Times are going to be of datetime type:
ret = cur.fetchone()
starttime = ret[0]
......@@ -788,7 +788,7 @@ def start_test(testid, cur, cn, obsdict_key, obsdict_id):
# check if we're still in time ---
if len(errors) == 0:
now = time.strftime(flocklab.config.get("database", "timeformat"), time.gmtime(time.time() - 10)) # allow 10s tolerance
cur.execute("SELECT `serv_tests_key` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d AND `time_start_wish` <= '%s'" % (testid, now))
cur.execute("SELECT `serv_tests_key` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d AND `time_start` <= '%s'" % (testid, now))
if cur.fetchone() is not None:
msg = "Setup for test ID %d took too much time." % (testid)
errors.append(msg)
......@@ -798,12 +798,10 @@ def start_test(testid, cur, cn, obsdict_key, obsdict_id):
if len(errors) == 0:
logger.debug("Setting test status in DB to running...")
flocklab.set_test_status(cur, cn, testid, 'running')
cur.execute("UPDATE `tbl_serv_tests` SET `time_start_act` = `time_start_wish` WHERE `serv_tests_key` = %d" %testid)
cn.commit()
else:
logger.debug("Setting test status in DB to aborting...")
flocklab.set_test_status(cur, cn, testid, 'aborting')
cur.execute("UPDATE `tbl_serv_tests` SET `time_start_act` = `time_start_wish`, `time_end_act` = UTC_TIMESTAMP() WHERE `serv_tests_key` = %d" %testid)
cur.execute("UPDATE `tbl_serv_tests` SET `time_end` = UTC_TIMESTAMP() WHERE `serv_tests_key` = %d" % testid)
cn.commit()
logger.debug("At end of start_test(). Returning...")
......@@ -926,10 +924,6 @@ def stop_test(testid, cur, cn, obsdict_key, obsdict_id, abort=False):
for err in errs[1]:
#logger.error("Error from test stop thread: %s" %(str(err[0])))
warnings.append(err[0])
# Set stop time in DB ---
cur.execute("UPDATE `tbl_serv_tests` SET `time_end_act` = UTC_TIMESTAMP() WHERE `serv_tests_key` = %d" %testid)
cn.commit()
except Exception:
msg = "Unexpected error: %s: %s\n%s" % (str(sys.exc_info()[0]), str(sys.exc_info()[1]), traceback.format_exc())
......@@ -1051,7 +1045,7 @@ def evaluate_linkmeasurement(testid, cur):
logger = flocklab.get_logger()
errors = []
# if link measurement, evaluate data
cur.execute("SELECT `username`, `time_start_act` FROM `tbl_serv_tests` LEFT JOIN `tbl_serv_users` ON (`serv_users_key`=`owner_fk`) WHERE (`serv_tests_key` = %s)" % testid)
cur.execute("SELECT `username`, `time_start` FROM `tbl_serv_tests` LEFT JOIN `tbl_serv_users` ON (`serv_users_key`=`owner_fk`) WHERE (`serv_tests_key` = %s)" % testid)
ret = cur.fetchone()
if ret and ret[0] == flocklab.config.get('linktests', 'user'):
teststarttime = ret[1]
......@@ -1415,7 +1409,7 @@ def main(argv):
flocklab.send_mail_to_admin(msg)
# Get the stop time from the database
cur.execute("SELECT `time_end_wish` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" % testid)
cur.execute("SELECT `time_end` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" % testid)
ret = cur.fetchone()
stoptimestamp = datetime.datetime.timestamp(ret[0]) + 1 # postpone by 1s to give services on observers time to shut down
if not stoptimestamp or stoptimestamp < time.time():
......@@ -1488,7 +1482,7 @@ def main(argv):
logger.debug("Fetcher has set test status to '%s'." % status)
# Check the actual runtime: if < 0, test failed
cur.execute("SELECT TIME_TO_SEC(TIMEDIFF(`time_end_act`, `time_start_act`)) FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" % testid)
cur.execute("SELECT TIME_TO_SEC(TIMEDIFF(`time_end`, `time_start`)) FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" % testid)
test_runtime = cur.fetchone()[0]
if not test_runtime or int(test_runtime) < 0:
logger.info("Negative runtime detected, marking test as 'failed'.")
......
......@@ -1068,7 +1068,7 @@ def main(argv):
serialdict = {0: 'r', 1: 'w'}
#find out the start and stoptime of the test
cur.execute("SELECT `time_start_wish`, `time_end_wish` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" %testid)
cur.execute("SELECT `time_start`, `time_end` FROM `tbl_serv_tests` WHERE `serv_tests_key` = %d" % testid)
# Times are going to be of datetime type:
ret = cur.fetchone()
teststarttime = ret[0]
......@@ -1078,7 +1078,7 @@ def main(argv):
# Find out which services are used to allocate working threads later on ---
# Get the XML config from the database and check which services are used in the test.
servicesUsed_dict = {'gpiotracing': 'gpioTracingConf', 'powerprofiling': 'powerProfilingConf', 'serial': 'serialConf', 'datatrace': 'dataTraceConf'}
cur.execute("SELECT `testconfig_xml` FROM `tbl_serv_tests` WHERE (`serv_tests_key` = %s)" %testid)
cur.execute("SELECT `testconfig_xml` FROM `tbl_serv_tests` WHERE (`serv_tests_key` = %s)" % testid)
ret = cur.fetchone()
if not ret:
msg = "No XML found in database for testid %d." %testid
......
......@@ -113,20 +113,22 @@ def main(argv):
logger.debug("Expiration lead time is %s days" % expiration_leadtime)
try:
# Get all users that have ran tests:
sql = """ SELECT DISTINCT `owner_fk`
FROM `tbl_serv_tests`
WHERE (`test_status` IN ('not schedulable','finished','failed', 'retention expiring'))
"""
sql = """
SELECT DISTINCT `owner_fk`
FROM `tbl_serv_tests`
WHERE (`test_status` IN ('not schedulable','finished','failed', 'retention expiring'))
"""
if ( cur.execute(sql) <= 0 ):
logger.info("No users found which ran tests.")
else:
rs = cur.fetchall()
ownerids = [str(i[0]) for i in rs]
for ownerid in ownerids:
sql = """ SELECT `retention_time`, `email`, `username`, `is_active`
FROM `tbl_serv_users`
WHERE (`serv_users_key` = %s)
""" % (ownerid)
sql = """
SELECT `retention_time`, `email`, `username`, `is_active`
FROM `tbl_serv_users`
WHERE (`serv_users_key` = %s)
""" % (ownerid)
cur.execute(sql)
rs = cur.fetchone()
retention_time_user = rs[0]
......@@ -136,11 +138,12 @@ def main(argv):
logger.debug("Checking tests of user %s (users retention time is %d days)." % (ownerusername, retention_time_user))
# Check for each user (taking into account her individual retention time [-1 means saving data forever]) if there are tests to be cleaned soon and inform the user about these tests.
if retention_time_user != -1:
sql = """ SELECT `serv_tests_key`, `title`, DATE(`time_end_act`), `test_status`
FROM `tbl_serv_tests`
WHERE ((`owner_fk` = %s) AND (`time_end_act` < ADDDATE(NOW(), -(%s + %s))) AND (`test_status` IN ('not schedulable','finished','failed')))
ORDER BY `time_end_act` DESC
""" % (ownerid, retention_time_user, expiration_leadtime)
sql = """
SELECT `serv_tests_key`, `title`, DATE(`time_end`), `test_status`
FROM `tbl_serv_tests`
WHERE ((`owner_fk` = %s) AND (`time_end` < ADDDATE(NOW(), -(%s + %s))) AND (`test_status` IN ('not schedulable','finished','failed')))
ORDER BY `time_end` DESC
""" % (ownerid, retention_time_user, expiration_leadtime)
if(cur.execute(sql) > 0):
rs = cur.fetchall()
msg_expiring = """Dear FlockLab user,\n\n\
......@@ -170,10 +173,11 @@ Yours faithfully,\nthe FlockLab server"""
continue
else:
# Mark the tests in the database:
sql = """ UPDATE `tbl_serv_tests`
SET `test_status` = 'retention expiring', `retention_expiration_warned` = NOW()
WHERE `serv_tests_key` IN (%s)
"""
sql = """
UPDATE `tbl_serv_tests`
SET `test_status` = 'retention expiring', `retention_expiration_warned` = NOW()
WHERE `serv_tests_key` IN (%s)
"""
cur.execute(sql%(testids))
cn.commit()
logger.debug("Set test status to 'retention expiring' for tests.")
......@@ -181,11 +185,12 @@ Yours faithfully,\nthe FlockLab server"""
logger.debug("Found no tests whose retention time expires soon.")
# Check for each user if there are tests which are to be marked for deletion as their retention time expired:
sql = """ SELECT `serv_tests_key`, `title`, DATE(`time_end_act`)
FROM `tbl_serv_tests`
WHERE ((`owner_fk` = %s) AND (`time_end_act` < ADDDATE(NOW(), -(%s))) AND (`test_status` = 'retention expiring') AND (`retention_expiration_warned` < ADDDATE(NOW(), -(%s+1))))
ORDER BY `time_end_act` DESC
"""
sql = """
SELECT `serv_tests_key`, `title`, DATE(`time_end`)
FROM `tbl_serv_tests`
WHERE ((`owner_fk` = %s) AND (`time_end` < ADDDATE(NOW(), -(%s))) AND (`test_status` = 'retention expiring') AND (`retention_expiration_warned` < ADDDATE(NOW(), -(%s+1))))
ORDER BY `time_end` DESC
"""
if(cur.execute(sql % (ownerid, retention_time_user, expiration_leadtime)) > 0):
rs = cur.fetchall()
msg_deleted = """Dear FlockLab user,\n\n\
......@@ -214,10 +219,11 @@ Yours faithfully,\nthe FlockLab server"""
continue
else:
# Mark the tests in the database:
sql = """ UPDATE `tbl_serv_tests`
SET `test_status` = 'todelete'
WHERE `serv_tests_key` IN (%s)
"""
sql = """
UPDATE `tbl_serv_tests`
SET `test_status` = 'todelete'
WHERE `serv_tests_key` IN (%s)
"""
cur.execute(sql%(testids))
cn.commit()
logger.debug("Set test status to 'todelete' for tests.")
......
......@@ -183,10 +183,10 @@ def main(argv):
earlieststart = (datetime.datetime.now() + datetime.timedelta(seconds=setuptime) - datetime.timedelta(seconds=schedinterval)).strftime(flocklab.config.get("database", "timeformat"))
lateststart = (datetime.datetime.now() + datetime.timedelta(seconds=setuptime) + datetime.timedelta(seconds=schedinterval)).strftime(flocklab.config.get("database", "timeformat"))
# Check if a test is going to start soon:
sql = """SELECT `serv_tests_key`,`time_start_wish`
FROM `tbl_serv_tests`
WHERE (`time_start_wish` >= '%s')
AND (`time_start_wish` <= '%s')
sql = """SELECT `serv_tests_key`,`time_start`
FROM `tbl_serv_tests`
WHERE (`time_start` >= '%s')
AND (`time_start` <= '%s')
AND (`test_status` = 'planned')
AND (`dispatched` = 0)
""" % (earlieststart, lateststart)
......@@ -208,12 +208,12 @@ def main(argv):
# Check for test which have been missed ---
sql1 = """SELECT `serv_tests_key`
FROM `tbl_serv_tests`
WHERE (`time_start_wish` < '%s')
WHERE (`time_start` < '%s')
AND (`test_status` = 'planned')
""" % earlieststart
sql2 = """UPDATE `tbl_serv_tests`
SET `test_status` = 'failed'
WHERE (`time_start_wish` < '%s')
WHERE (`time_start` < '%s')
AND (`test_status` = 'planned')
""" % earlieststart
nmissed = cur.execute(sql1)
......
......@@ -152,7 +152,7 @@ def update_configuration_from_db():
flocklab.error_logandexit(msg, errno.EAGAIN)
try:
# Get the XML config from the database:
cur.execute("SELECT `testconfig_xml`, `serv_tests_key` FROM `tbl_serv_tests` WHERE (`test_status` IN ('preparing', 'running') AND `time_end_wish` >= NOW())")
cur.execute("SELECT `testconfig_xml`, `serv_tests_key` FROM `tbl_serv_tests` WHERE (`test_status` IN ('preparing', 'running') AND `time_end` >= NOW())")
ret = cur.fetchall()
for testconfig in ret:
logger.debug("Create proxy config for test %d" % testconfig[1])
......
......@@ -625,9 +625,9 @@ def get_obs_from_id(cursor=None, obsid=0):
return FAILED
try:
sql = " SELECT `ethernet_address`, `status` \
FROM `tbl_serv_observer` \
WHERE `observer_id`=%d;"
sql = "SELECT `ethernet_address`, `status` \
FROM `tbl_serv_observer` \
WHERE `observer_id`=%d;"
cursor.execute(sql %obsid)
rs = cursor.fetchone()
......@@ -1014,7 +1014,7 @@ def is_test_running(cursor=None):
cursor.execute("""
SELECT COUNT(serv_tests_key) FROM tbl_serv_tests
WHERE test_status IN('preparing', 'running', 'aborting', 'cleaning up')
AND TIMESTAMPDIFF(MINUTE, time_end_wish, '%s') <= %d
AND TIMESTAMPDIFF(MINUTE, time_end, '%s') <= %d
""" % (now, maxcleanuptime))
rs = cursor.fetchone()
if rs[0] != 0:
......
......@@ -110,7 +110,7 @@
exit();
}
$db = db_connect();
$sql = "SELECT title, description, test_status as status, UNIX_TIMESTAMP(time_start_wish) AS start_planned, UNIX_TIMESTAMP(time_start_act) AS start_act, UNIX_TIMESTAMP(time_end_wish) AS end_planned, UNIX_TIMESTAMP(time_end_act) AS end_act
$sql = "SELECT title, description, test_status as status, UNIX_TIMESTAMP(time_start) AS start, UNIX_TIMESTAMP(time_end) AS end
FROM `flocklab`.`tbl_serv_tests`
WHERE serv_tests_key=".intval($_POST['id']);
if ($userrole != 'admin' && $userrole != 'internal') {
......@@ -123,7 +123,7 @@
else {
$row = mysqli_fetch_assoc($res);
if ($row) {
echo json_encode(array('status' => 'ok', 'output' => array('title' => $row['title'], 'description' => $row['description'], 'status' => $row['status'], 'start_planned' => $row['start_planned'], 'start' => $row['start_act'], 'end_planned' => $row['end_planned'], 'end' => $row['end_act'])));
echo json_encode(array('status' => 'ok', 'output' => array('title' => $row['title'], 'description' => $row['description'], 'status' => $row['status'], 'start' => $row['start'], 'end' => $row['end'], 'start_planned' => $row['start'], 'end_planned' => $row['end']))); // keep start_planned / end_planned for backwards compatibility (flocklab tools)
} else {
echo json_encode(array('status' => 'error', 'output' => 'test ID '.intval($_POST['id']).' not found'));
}
......
......@@ -40,23 +40,23 @@
$mysqlstart = date( 'Y-m-d H:i:s T', $_GET['start']);
$mysqlend = date('Y-m-d H:i:s T', $_GET['end']);
$mini = isset($_GET['mini']) && $_GET['mini']==TRUE;
// Connect to database and get the corresponding events:
$guard_setup_sec = $CONFIG['tests']['setuptime'];
$guard_cleanup_sec = $CONFIG['tests']['cleanuptime'];
$db = db_connect();
// planned tests
$sql = "SELECT `a`.serv_tests_key, `a`.title, `a`.description, `a`.time_start_wish, `a`.time_end_wish, `a`.owner_fk,
`b`.username, `b`.firstname, `b`.lastname, `a`.time_start_act, `a`.time_end_act, `a`.test_status,
DATE_ADD(`a`.time_start_wish, INTERVAL -".$guard_setup_sec." SECOND) as time_start_offset,
DATE_ADD(`a`.time_end_wish, INTERVAL ".$guard_cleanup_sec." SECOND) as time_end_offset
$sql = "SELECT `a`.serv_tests_key, `a`.title, `a`.description, `a`.time_start, `a`.time_end, `a`.owner_fk,
`b`.username, `b`.firstname, `b`.lastname, `a`.test_status,
DATE_ADD(`a`.time_start, INTERVAL -".$guard_setup_sec." SECOND) as time_start_offset,
DATE_ADD(`a`.time_end, INTERVAL ".$guard_cleanup_sec." SECOND) as time_end_offset
FROM `tbl_serv_tests` AS `a`
LEFT JOIN `tbl_serv_users` AS `b` ON `a`.owner_fk = `b`.serv_users_key
WHERE (`a`.test_status NOT IN ('not schedulable') OR (`a`.test_status_preserved IS NOT NULL AND `a`.test_status_preserved IN ('finished','failed')))
AND ( (`a`.time_start_wish BETWEEN '" . $mysqlstart . "' AND '" . $mysqlend . "') OR (`a`.time_end_wish BETWEEN '" . $mysqlstart . "' AND '" . $mysqlend . "') )
ORDER BY `a`.time_start_wish";
AND ( (`a`.time_start BETWEEN '" . $mysqlstart . "' AND '" . $mysqlend . "') OR (`a`.time_end BETWEEN '" . $mysqlstart . "' AND '" . $mysqlend . "') )
ORDER BY `a`.time_start";
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get calendar data from database because: ' . mysqli_error($db));
// Build the array of events:
$events = array();
while ($row = mysqli_fetch_array($rs)) {
......@@ -66,9 +66,9 @@
$events[] = array(
'id' => $row['serv_tests_key'],
'title' => 'Test ' . $row['serv_tests_key'] . ': ' . $row['title'],
'description' => $mini?'':'Test-ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start_act'])).' - '.date("H:i", strtotime($row['time_end_act'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'].'<br />Status: '.$row['test_status'],
'start' => $row['time_start_act'],
'end' => $row['time_end_act'],
'description' => $mini?'':'Test-ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start'])).' - '.date("H:i", strtotime($row['time_end'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'].'<br />Status: '.$row['test_status'],
'start' => $row['time_start'],
'end' => $row['time_end'],
'allDay' => false,
'color' => '#eca427',
);
......@@ -80,7 +80,7 @@
'title' => 'Test setup',
'description' => $mini?'':'Time needed by FlockLab to setup your test.',
'start' => $row['time_start_offset'],
'end' => $row['time_start_wish'],
'end' => $row['time_start'],
'allDay' => false,
'color' => 'orange',
);
......@@ -88,9 +88,9 @@
$events[] = array(
'id' => $row['serv_tests_key'],
'title' => 'Test ' . $row['serv_tests_key'] . ': ' . $row['title'],
'description' => $mini?'':'Test-ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start_wish'])).' - '.date("H:i", strtotime($row['time_end_wish'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'].'<br />Status: '.$row['test_status'],
'start' => $row['time_start_wish'],
'end' => $row['time_end_wish'],
'description' => $mini?'':'Test-ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start'])).' - '.date("H:i", strtotime($row['time_end'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'].'<br />Status: '.$row['test_status'],
'start' => $row['time_start'],
'end' => $row['time_end'],
'allDay' => false,
'color' => '#eca427',
);
......@@ -99,7 +99,7 @@
'id' => 'service',
'title' => 'Test cleanup',
'description' => $mini?'':'Time needed by FlockLab to cleanup your test.',
'start' => $row['time_end_wish'],
'start' => $row['time_end'],
'end' => $row['time_end_offset'],
'allDay' => false,
'color' => 'orange',
......@@ -110,47 +110,47 @@
$event = array(
'id' => $row['serv_tests_key'],
'title' => $row['username'] . ' (' . $row['firstname'] . ' ' . $row['lastname'] . ')',
'description' => $mini?'':'ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start_wish'])).' - '.date("H:i", strtotime($row['time_end_wish'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'] . '<br/> User: ' . $row['username'] . ' (' . $row['firstname'] . ' ' . $row['lastname'] . ')' . '<br/>Status: ' . $row['test_status'],
'description' => $mini?'':'ID: ' . $row['serv_tests_key'] . '<br/>Duration: '.date("H:i", strtotime($row['time_start'])).' - '.date("H:i", strtotime($row['time_end'])).' (UTC)<br/>Title: ' . $row['title'] . '<br/> Description: ' . $row['description'] . '<br/> User: ' . $row['username'] . ' (' . $row['firstname'] . ' ' . $row['lastname'] . ')' . '<br/>Status: ' . $row['test_status'],
'allDay' => false,
);
if (isset($row['time_start_act']))
$event['start'] = $row['time_start_act'];
if (isset($row['time_start']))
$event['start'] = $row['time_start'];
else
$event['start'] = $row['time_start_offset'];
if (isset($row['time_end_act']))
$event['end'] = $row['time_end_act'];
if (isset($row['time_end']))
$event['end'] = $row['time_end'];
else
$event['end'] = $row['time_end_offset'];
array_push($events, $event);
} else {
// The event is not owned by the logged-in user, thus just show one event without details and add the offsets directly to the event:
// The event is not owned by the logged-in user, thus just show one event without details and add the offsets directly to the event:
$event = array(
'id' => $row['serv_tests_key'],
'title' => 'Occupied',
'description' => $mini?'':'Another user is running a test.',
'allDay' => false,
);
if (isset($row['time_start_act']))
$event['start'] = $row['time_start_act'];
if (isset($row['time_start']))
$event['start'] = $row['time_start'];
else
$event['start'] = $row['time_start_offset'];
if (isset($row['time_end_act']))
$event['end'] = $row['time_end_act'];
if (isset($row['time_end']))
$event['end'] = $row['time_end'];
else
$event['end'] = $row['time_end_offset'];
array_push($events, $event);
}
}
// add reservation slots that affect this user (i.e., blocks time)
$sql = 'SELECT max(`user_fk` = '.$_SESSION['serv_users_key'].') as `reservation_match`, `time_start`, `time_end`, `serv_reservation_key`, `group_id_fk`
FROM `tbl_serv_reservations` LEFT JOIN `tbl_serv_user_groups` ON `group_fk`=`group_id_fk`
WHERE `time_end` > NOW() AND
(`time_start` BETWEEN "' . $mysqlstart . '" AND "' . $mysqlend . '" OR
`time_end` BETWEEN "' . $mysqlstart . '" AND "' . $mysqlend . '")
GROUP BY serv_reservation_key
'. (($_SESSION['is_admin'] == true || $_SESSION['is_internal'] == true) ? '' : 'HAVING `reservation_match` is NULL OR `reservation_match` <> 1');
FROM `tbl_serv_reservations` LEFT JOIN `tbl_serv_user_groups` ON `group_fk`=`group_id_fk`
WHERE `time_end` > NOW() AND
(`time_start` BETWEEN "' . $mysqlstart . '" AND "' . $mysqlend . '" OR
`time_end` BETWEEN "' . $mysqlstart . '" AND "' . $mysqlend . '")
GROUP BY serv_reservation_key
'. (($_SESSION['is_admin'] == true || $_SESSION['is_internal'] == true) ? '' : 'HAVING `reservation_match` is NULL OR `reservation_match` <> 1');
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get calendar data from database because: ' . mysqli_error($db));
while ($row = mysqli_fetch_array($rs)) {
$event = array(
......
......@@ -53,12 +53,12 @@
// Connect to database and get the corresponding events:
$db = db_connect();
// Only get data for the last 30 days:
$sql = "SELECT serv_tests_key, title, left(description, 100) as description, ADDTIME(`a`.time_start_wish, '-00:05:00') AS time_start_w_offset, ADDTIME(`a`.time_end_wish, '00:05:00') AS time_end_w_offset,
$sql = "SELECT serv_tests_key, title, left(description, 100) as description, ADDTIME(`a`.time_start, '-00:05:00') AS time_start_w_offset, ADDTIME(`a`.time_end, '00:05:00') AS time_end_w_offset,
`b`.username
FROM `tbl_serv_tests` AS `a`
LEFT JOIN `tbl_serv_users` AS `b` ON `a`.owner_fk = `b`.serv_users_key
WHERE `a`.test_status <> 'not schedulable' AND `a`.test_status <> 'deleted' AND `a`.test_status <> 'todelete' AND (`a`.time_end_wish >= ADDTIME(NOW(), '-30 0:0:0.0'))
ORDER by `a`.time_start_wish ASC LIMIT 1000";
WHERE `a`.test_status <> 'not schedulable' AND `a`.test_status <> 'deleted' AND `a`.test_status <> 'todelete' AND (`a`.time_end >= ADDTIME(NOW(), '-30 0:0:0.0'))
ORDER by `a`.time_start ASC LIMIT 1000";
$rs = mysqli_query($db, $sql) or die("Unknown error occurred.");
mysqli_close($db);
......
......@@ -100,7 +100,7 @@ function rrm($dir) {
##############################################################################
#
# do_login
#
#
# check name and password and create session.
#
# @param username
......@@ -111,7 +111,7 @@ function rrm($dir) {
*/
function do_login($username, $password) {
global $CONFIG;
// Check username and password:
if (strlen($username)>0 && strlen($password) > 0) {
$db = db_connect();
......@@ -124,8 +124,8 @@ function do_login($username, $password) {
if ($rows['role'] != 'admin') {
// check for global UI lock
$sql = "SELECT message, time_start, time_end
FROM tbl_serv_web_status
WHERE time_start < UTC_TIMESTAMP() and time_end > UTC_TIMESTAMP() AND ui_lock='true'";
FROM tbl_serv_web_status
WHERE time_start < UTC_TIMESTAMP() and time_end > UTC_TIMESTAMP() AND ui_lock='true'";
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot authenticate because: ' . mysqli_error($db));
if (mysqli_num_rows($rs) > 0) {
$rows = mysqli_fetch_array($rs);
......@@ -187,8 +187,8 @@ function destroy_session() {
##############################################################################
*/
function check_testid($testid, $userid) {
$db = db_connect();
$sql = "SELECT owner_fk
$db = db_connect();
$sql = "SELECT owner_fk
FROM tbl_serv_tests
WHERE serv_tests_key = " . $testid;
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get test owner from database because: ' . mysqli_error($db));
......@@ -210,8 +210,8 @@ function check_testid($testid, $userid) {
##############################################################################
*/
function check_imageid($imageid, $userid) {
$db = db_connect();
$sql = "SELECT owner_fk
$db = db_connect();
$sql = "SELECT owner_fk
FROM tbl_serv_targetimages
WHERE serv_targetimages_key = " . $imageid;
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get test owner from database because: ' . mysqli_error($db));
......@@ -238,7 +238,7 @@ function get_admin_emails() {
if (isset($CONFIG['email']['admin_email'])) {
array_push($admins, trim($CONFIG['email']['admin_email']));
} else {
$db = db_connect();
$db = db_connect();
$sql = "SELECT `email`
FROM tbl_serv_users
WHERE `role` = 'admin'";
......@@ -317,13 +317,13 @@ function get_user_role($username=null) {
##############################################################################
*/
function get_available_platforms() {
$db = db_connect();
$db = db_connect();
$sql = 'SELECT `serv_platforms_key`, `name`, `core`, `tbl_serv_architectures`.`description` `core_desc`
FROM `tbl_serv_platforms`
LEFT JOIN `tbl_serv_architectures`
ON `tbl_serv_architectures`.`platforms_fk` = `tbl_serv_platforms`.`serv_platforms_key`
WHERE `active` = 1
ORDER BY `name`, `core` ASC';
FROM `tbl_serv_platforms`
LEFT JOIN `tbl_serv_architectures`
ON `tbl_serv_architectures`.`platforms_fk` = `tbl_serv_platforms`.`serv_platforms_key`
WHERE `active` = 1
ORDER BY `name`, `core` ASC';
$res = mysqli_query($db, $sql) or flocklab_die('Cannot fetch available platforms because: ' . mysqli_error($db));
$num = mysqli_num_rows($res);
$available_platforms = Array();
......@@ -341,10 +341,10 @@ function get_available_platforms() {
}
function get_testconfig($testid) {
$db = db_connect();
$sql = "SELECT `testconfig_xml`
FROM tbl_serv_tests
WHERE ".($_SESSION['is_admin']?"":("owner_fk = " . $_SESSION['serv_users_key'] . " AND "))."`serv_tests_key`=".mysqli_real_escape_string($db, $testid);
$db = db_connect();
$sql = "SELECT `testconfig_xml`
FROM tbl_serv_tests
WHERE ".($_SESSION['is_admin']?"":("owner_fk = " . $_SESSION['serv_users_key'] . " AND "))."`serv_tests_key`=".mysqli_real_escape_string($db, $testid);
$res = mysqli_query($db, $sql);
if ($res !== false) {
$row = mysqli_fetch_assoc($res);
......@@ -354,10 +354,10 @@ function get_testconfig($testid) {
}
function get_teststatus($testid) {
$db = db_connect();
$sql = "SELECT `test_status`
FROM tbl_serv_tests
WHERE owner_fk = " . $_SESSION['serv_users_key'] . " AND `serv_tests_key`=".mysqli_real_escape_string($db, $testid);
$db = db_connect();
$sql = "SELECT `test_status`
FROM tbl_serv_tests
WHERE owner_fk = " . $_SESSION['serv_users_key'] . " AND `serv_tests_key`=".mysqli_real_escape_string($db, $testid);
$res = mysqli_query($db, $sql);
if ($res !== false) {
$row = mysqli_fetch_assoc($res);
......@@ -434,12 +434,12 @@ function check_image_duplicate($image) {
$db = db_connect();
$hash = hash('sha1', $image['data']);
$sql = 'SELECT `serv_targetimages_key`, `binary`
FROM `tbl_serv_targetimages`
WHERE `owner_fk`='.$_SESSION['serv_users_key'].'
AND `binary` IS NOT NULL
AND `binary_hash_sha1`="'.$hash.'"
AND `platforms_fk`='.mysqli_real_escape_string