To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 90e66ed8 authored by Reto Da Forno's avatar Reto Da Forno

webserver files updated, now compatible with PHP7

parent 1dbf731d
......@@ -197,6 +197,8 @@ def main(argv):
keeptime = config.getint('cleaner', 'keeptime_viz')
earliest_keeptime = time.time() - (keeptime*86400)
imgdir_path = config.get('viz','imgdir')
if not os.path.isdir(imgdir_path):
os.mkdir(imgdir_path)
for f in os.listdir(imgdir_path):
path = os.path.join(imgdir_path, f)
if os.stat(path).st_mtime < earliest_keeptime:
......
......@@ -15,15 +15,15 @@
exit(1);
if (isset($_POST['resid'])) {
$db = db_connect();
$sql = "DELETE FROM tbl_serv_reservations where serv_reservation_key=".mysql_real_escape_string($_POST['resid']);
$rs = mysql_query($sql) or flocklab_die('Cannot delete reservation in database because: ' . mysql_error());
mysql_close($db);
$sql = "DELETE FROM tbl_serv_reservations where serv_reservation_key=".mysqli_real_escape_string($db, $_POST['resid']);
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot delete reservation in database because: ' . mysqli_error($db));
mysqli_close($db);
}
if (isset($_POST['add_group'])) {
$db = db_connect();
$sql = 'INSERT INTO tbl_serv_reservations (group_id_fk, time_start, time_end) values ('.mysql_real_escape_string($_POST['add_group']).',FROM_UNIXTIME('.strtotime(mysql_real_escape_string($_POST['add_start_time'])).'),FROM_UNIXTIME('.strtotime(mysql_real_escape_string($_POST['add_end_time'])).'))';
$rs = mysql_query($sql) or flocklab_die('Cannot add reservation in database because: ' . mysql_error());
mysql_close($db);
$sql = 'INSERT INTO tbl_serv_reservations (group_id_fk, time_start, time_end) values ('.mysqli_real_escape_string($db, $_POST['add_group']).',FROM_UNIXTIME('.strtotime(mysqli_real_escape_string($db, $_POST['add_start_time'])).'),FROM_UNIXTIME('.strtotime(mysqli_real_escape_string($db, $_POST['add_end_time'])).'))';
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot add reservation in database because: ' . mysqli_error($db));
mysqli_close($db);
}
?>
<script type="text/javascript" src="scripts/jquery.cookie.js"></script>
......@@ -64,18 +64,18 @@ echo '<h1>Admin Group Reservations</h1>';
/* Get all reservations from the database and display them in the table. */
$db = db_connect();
$sql = "SELECT serv_groups_key, groupname, GROUP_CONCAT(username SEPARATOR ', ') as group_list FROM (tbl_serv_groups left join tbl_serv_user_groups on (group_fk=serv_groups_key)) left join tbl_serv_users on (user_fk=tbl_serv_users.serv_users_key) GROUP BY group_fk";
$rs = mysql_query($sql) or flocklab_die('Cannot get reservations from database because: ' . mysql_error());
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get reservations from database because: ' . mysqli_error($db));
$groups = array();
while ($row = mysql_fetch_array($rs)) {
while ($row = mysqli_fetch_array($rs)) {
$groups[$row['serv_groups_key']]=Array('name' => $row['groupname'], 'users' => $row['group_list']);
}
$sql = "SELECT serv_reservation_key, group_id_fk, time_start, time_end, groupname, group_list
FROM tbl_serv_reservations LEFT JOIN (
SELECT serv_groups_key, groupname, GROUP_CONCAT(username SEPARATOR ', ') as group_list FROM (tbl_serv_groups left join tbl_serv_user_groups on (group_fk=serv_groups_key)) left join tbl_serv_users on (user_fk=tbl_serv_users.serv_users_key) GROUP BY serv_groups_key) as groups on (groups.serv_groups_key = group_id_fk)
ORDER BY time_start DESC";
$rs = mysql_query($sql) or flocklab_die('Cannot get reservations from database because: ' . mysql_error());
$nrows = mysql_num_rows($rs);
mysql_close($db);
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get reservations from database because: ' . mysqli_error($db));
$nrows = mysqli_num_rows($rs);
mysqli_close($db);
?>
<form name="resadd" method="post" action="admin_group_reservation.php">
......@@ -92,7 +92,7 @@ ORDER BY time_start DESC";
<?php
$i = 0;
$max_len = 30; // maximum length of text before being cut
while ($row = mysql_fetch_array($rs)) {
while ($row = mysqli_fetch_array($rs)) {
$i++;
if ($i%2 == 1) {
echo "<tr class='even'>";
......
......@@ -16,20 +16,20 @@
if (isset($_POST['inlist']) && isset($_POST['group'])) {
$db = db_connect();
foreach ($_POST['inlist'] as $user) {
$sql = "DELETE FROM tbl_serv_user_groups where group_fk=".mysql_real_escape_string($_POST['group'])." and user_fk=".mysql_real_escape_string($user);
$rs = mysql_query($sql) or flocklab_die('Cannot remove user from group because: ' . mysql_error());
$sql = "DELETE FROM tbl_serv_user_groups where group_fk=".mysqli_real_escape_string($db, $_POST['group'])." and user_fk=".mysqli_real_escape_string($db, $user);
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot remove user from group because: ' . mysqli_error($db));
echo "remove user ".$user." from group ".$_POST['group'];
}
mysql_close($db);
mysqli_close($db);
}
if (isset($_POST['notinlist']) && isset($_POST['group'])) {
$db = db_connect();
foreach ($_POST['notinlist'] as $user) {
$sql = "insert into tbl_serv_user_groups (group_fk, user_fk) values (".mysql_real_escape_string($_POST['group']).",".mysql_real_escape_string($user).")";
$rs = mysql_query($sql) or flocklab_die('Cannot add user to group because: ' . mysql_error());
$sql = "insert into tbl_serv_user_groups (group_fk, user_fk) values (".mysqli_real_escape_string($db, $_POST['group']).",".mysqli_real_escape_string($db, $user).")";
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot add user to group because: ' . mysqli_error($db));
echo "add user ".$user." to group ".$_POST['group'];
}
mysql_close($db);
mysqli_close($db);
}
?>
<script type="text/javascript" src="scripts/jquery.cookie.js"></script>
......@@ -46,9 +46,9 @@ echo '<h1>Admin Groups</h1>';
/* Get groups */
$db = db_connect();
$sql = "SELECT serv_groups_key, groupname FROM tbl_serv_groups";
$rs = mysql_query($sql) or flocklab_die('Cannot get reservations from database because: ' . mysql_error());
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get reservations from database because: ' . mysqli_error($db));
$groups = array();
while ($row = mysql_fetch_array($rs)) {
while ($row = mysqli_fetch_array($rs)) {
$groups[$row['serv_groups_key']]=$row['groupname'];
}
if (empty($_POST['group'])) {
......@@ -59,18 +59,18 @@ echo '<h1>Admin Groups</h1>';
$selgroup = $_POST['group'];
}
$sql = "SELECT group_fk, serv_users_key, username FROM tbl_serv_user_groups left join tbl_serv_users on (user_fk=tbl_serv_users.serv_users_key) where group_fk=".$selgroup." order by username";
$rs = mysql_query($sql) or flocklab_die('Cannot get reservations from database because: ' . mysql_error());
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get reservations from database because: ' . mysqli_error($db));
$isuser = array();
while ($row = mysql_fetch_array($rs)) {
while ($row = mysqli_fetch_array($rs)) {
$isuser[$row['serv_users_key']]=$row['username'];
}
$sql = "SELECT sum(group_fk=".$selgroup.") as isgroup, serv_users_key, username FROM tbl_serv_users left join tbl_serv_user_groups on (user_fk=tbl_serv_users.serv_users_key) group by serv_users_key having isgroup is null or isgroup=0 order by username";
$rs = mysql_query($sql) or flocklab_die('Cannot get reservations from database because: ' . mysql_error());
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get reservations from database because: ' . mysqli_error($db));
$notuser = array();
while ($row = mysql_fetch_array($rs)) {
while ($row = mysqli_fetch_array($rs)) {
$notuser[$row['serv_users_key']]=$row['username'];
}
mysql_close($db);
mysqli_close($db);
$max_len = 50;
?>
<form name="resadd" method="post" action="admin_groups.php">
......
......@@ -21,41 +21,41 @@ echo '<h1>Admin Statistics</h1><table>';
$testoverhead = 2*3*60; // time needed to setup and clean up a test in seconds
$db = db_connect();
$sql = "select count(*) as num from tbl_serv_users";
$rs = mysql_query($sql) or flocklab_die('Cannot get statistics from database because: ' . mysql_error());
$row = mysql_fetch_array($rs);
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get statistics from database because: ' . mysqli_error($db));
$row = mysqli_fetch_array($rs);
echo '<tr><td><b>Number of users</b></td><td>'.$row['num'].'</td></tr>';
echo '<tr><td><b>Users by institution</b></td><td></td></tr>';
$sql = 'select institution, count(institution) as num from tbl_serv_users group by institution';
$rs = mysql_query($sql) or flocklab_die('Cannot get statistics from database because: ' . mysql_error());
while ($row = mysql_fetch_array($rs)) {
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get statistics from database because: ' . mysqli_error($db));
while ($row = mysqli_fetch_array($rs)) {
echo '<tr><td>&nbsp;&nbsp;'.$row['institution'].'</td><td>'.$row['num'].'</td></tr>';
}
echo '<tr><td><b>Users by country</b></td><td></td></tr>';
$sql = 'select country, count(country) as num from tbl_serv_users group by country';
$rs = mysql_query($sql) or flocklab_die('Cannot get statistics from database because: ' . mysql_error());
while ($row = mysql_fetch_array($rs)) {
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get statistics from database because: ' . mysqli_error($db));
while ($row = mysqli_fetch_array($rs)) {
echo '<tr><td>&nbsp;&nbsp;'.$row['country'].'</td><td>'.$row['num'].'</td></tr>';
}
// Tests, by nodes, with setup and cleanup
$sql = 'select year(time_start_act) as y, count(*) as num from tbl_serv_tests where test_status_preserved in ("finished", "retention expiring", "synced") or test_status_preserved is null group by year(time_start_act) having y is not null';
$rs = mysql_query($sql) or flocklab_die('Cannot get statistics from database because: ' . mysql_error());
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get statistics from database because: ' . mysqli_error($db));
$testcount=Array();
while ($row = mysql_fetch_array($rs)) {
while ($row = mysqli_fetch_array($rs)) {
$year = $row['y'];
echo '<tr><td><b>Number of tests '.$year.' (avg [max] setup / cleanup time)</td><td>'.$row['num'].'</td></tr>';
$testcount[$year] = $row['num'];
$sql = 'select year(time_start_act), pname, count(*) as c, time_start_act, b.test_status_preserved, avg(setuptime) as tsetup, avg(cleanuptime) as tcleanup, max(setuptime) as tsetupmax, max(cleanuptime) as tcleanupmax from (select distinct test_fk, tbl_serv_platforms.name as pname from tbl_serv_map_test_observer_targetimages left join tbl_serv_targetimages on (targetimage_fk = serv_targetimages_key) left join tbl_serv_platforms on (platforms_fk = serv_platforms_key)) as a left join tbl_serv_tests as b on (a.test_fk = b.serv_tests_key) where year(time_start_act) = '.$year.' and (b.test_status_preserved in ("finished", "retention expiring", "synced") or b.test_status_preserved is null) and time_start_act is not null and pname is not null group by pname order by time_start_act, pname';
$rs2 = mysql_query($sql) or flocklab_die('Cannot get statistics from database because: ' . mysql_error());
while ($row = mysql_fetch_array($rs2)) {
$rs2 = mysqli_query($db, $sql) or flocklab_die('Cannot get statistics from database because: ' . mysqli_error($db));
while ($row = mysqli_fetch_array($rs2)) {
echo '<tr><td>&nbsp;&nbsp;'.$row['pname'].'</td><td>'.$row['c'].' ('.round($row['tsetup']).' ['.round($row['tsetupmax']).'] / '.round($row['tcleanup']).' ['.round($row['tcleanupmax']).'] s)</td></tr>';
}
// Tests by service
$sql = 'select year(time_start_act) as y, sum(1) as num_all, sum(ExtractValue(testconfig_xml, "count(/testConf/serialConf|/testConf/serialReaderConf)") > 0) as num_serial, sum(ExtractValue(testconfig_xml, "count(/testConf/gpioTracingConf|/testConf/gpioMonitorConf)") > 0) as num_tracing, sum(ExtractValue(testconfig_xml, "count(/testConf/gpioActuationConf|/testConf/gpioSettingConf)") > 0) as num_actuation, sum(ExtractValue(testconfig_xml, "count(/testConf/powerProfilingConf|/testConf/powerprofConf)") > 0) as num_power from tbl_serv_tests where year(time_start_act) = '.$year.' and (test_status_preserved in ("finished", "retention expiring", "synced") or test_status_preserved is null)';
$rs3 = mysql_query($sql) or flocklab_die('Cannot get statistics from database because: ' . mysql_error());
$row = mysql_fetch_array($rs3);
$rs3 = mysqli_query($db, $sql) or flocklab_die('Cannot get statistics from database because: ' . mysqli_error($db));
$row = mysqli_fetch_array($rs3);
foreach (array('Serial'=>'num_serial','GPIO tracing'=>'num_tracing','GPIO actuation'=>'num_actuation','Power profiling'=>'num_power') as $service=>$field) {
echo '<tr><td>&nbsp;&nbsp;'.$service.'</td><td>'.$row[$field].' ('.(round($row[$field] / $row['num_all'] * 100 )).'%)</td></tr>';
}
......@@ -63,20 +63,20 @@ echo '<h1>Admin Statistics</h1><table>';
// Users by service and node type
$sql = 'select year(time_start_act) as y, count(distinct owner_fk) as num from tbl_serv_tests where test_status_preserved in ("finished", "retention expiring", "synced") or test_status_preserved is null group by year(time_start_act) having y is not null';
$rs = mysql_query($sql) or flocklab_die('Cannot get statistics from database because: ' . mysql_error());
while ($row = mysql_fetch_array($rs)) {
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get statistics from database because: ' . mysqli_error($db));
while ($row = mysqli_fetch_array($rs)) {
$year = $row['y'];
$num_users = $row['num'];
echo '<tr><td><b>Number of active users in '.$year.'</td><td>'.$row['num'].'</td></tr>';
$sql = 'select year(time_start_act), pname, count(distinct owner_fk) as c, time_start_act, b.test_status_preserved from (select distinct test_fk, tbl_serv_platforms.name as pname from tbl_serv_map_test_observer_targetimages left join tbl_serv_targetimages on (targetimage_fk = serv_targetimages_key) left join tbl_serv_platforms on (platforms_fk = serv_platforms_key)) as a left join tbl_serv_tests as b on (a.test_fk = b.serv_tests_key) where year(time_start_act) = '.$year.' and (b.test_status_preserved in ("finished", "retention expiring", "synced") or b.test_status_preserved is null) and time_start_act is not null and pname is not null group by pname order by time_start_act, pname';
$rs2 = mysql_query($sql) or flocklab_die('Cannot get statistics from database because: ' . mysql_error());
while ($row = mysql_fetch_array($rs2)) {
$rs2 = mysqli_query($db, $sql) or flocklab_die('Cannot get statistics from database because: ' . mysqli_error($db));
while ($row = mysqli_fetch_array($rs2)) {
echo '<tr><td>&nbsp;&nbsp;'.$row['pname'].'</td><td>'.$row['c'].' ('.(round($row['c']/$num_users * 100)).'%)</td></tr>';
}
$sql = 'select sum(num_all > 0) as user_all, sum(num_serial > 0) as user_serial, sum(num_tracing > 0) as user_tracing, sum(num_actuation > 0) as user_actuation, sum(num_power > 0) as user_power from (select year(time_start_act) as y, sum(1) as num_all, sum(ExtractValue(testconfig_xml, "count(/testConf/serialConf|/testConf/serialReaderConf)") > 0) as num_serial, sum(ExtractValue(testconfig_xml, "count(/testConf/gpioTracingConf|/testConf/gpioMonitorConf)") > 0) as num_tracing, sum(ExtractValue(testconfig_xml, "count(/testConf/gpioActuationConf|/testConf/gpioSettingConf)") > 0) as num_actuation, sum(ExtractValue(testconfig_xml, "count(/testConf/powerProfilingConf|/testConf/powerprofConf)") > 0) as num_power from tbl_serv_tests where year(time_start_act) = '.$year.' and (test_status_preserved in ("finished", "retention expiring", "synced") or test_status_preserved is null) group by owner_fk) as stats;';
$rs3 = mysql_query($sql) or flocklab_die('Cannot get statistics from database because: ' . mysql_error());
$row = mysql_fetch_array($rs3);
$rs3 = mysqli_query($db, $sql) or flocklab_die('Cannot get statistics from database because: ' . mysqli_error($db));
$row = mysqli_fetch_array($rs3);
foreach (array('Serial'=>'user_serial','GPIO tracing'=>'user_tracing','GPIO actuation'=>'user_actuation','Power profiling'=>'user_power') as $service=>$field) {
echo '<tr><td>&nbsp;&nbsp;'.$service.'</td><td>'.$row[$field].' ('.(round($row[$field] / $row['user_all'] * 100 )).'%)</td></tr>';
}
......@@ -84,8 +84,8 @@ echo '<h1>Admin Statistics</h1><table>';
// Occupied per year
$sql = 'select year(time_start_act) as y, min(time_start_act) as minp, max(time_end_act) as maxp, max(time_end_act - time_start_act), sum(timestampdiff(SECOND,time_start_act,time_end_act)) as duration from tbl_serv_tests where (test_status_preserved in ("finished", "retention expiring", "synced") or test_status_preserved is null) and (time_end_act is not null and time_start_act is not null and time_start_act < time_end_act and timestampdiff(SECOND,time_start_act,time_end_act) < 72 * 3600) group by year(time_start_act)';
$rs = mysql_query($sql) or flocklab_die('Cannot get statistics from database because: ' . mysql_error());
while ($row = mysql_fetch_array($rs)) {
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get statistics from database because: ' . mysqli_error($db));
while ($row = mysqli_fetch_array($rs)) {
echo '<tr><td><b>Time occupied '.$row['y'].'</b></td><td>'.round((($row['duration'] + $testcount[$row['y']] * $testoverhead) / 3600)).' hours ('.round((($row['duration'] + $testcount[$row['y']] * $testoverhead) / (strtotime($row['maxp'])-strtotime($row['minp'])) * 100)).'%)</td></tr>';
}
......@@ -94,9 +94,9 @@ echo '<h1>Admin Statistics</h1><table>';
datediff(DATE_SUB(DATE_SUB(CURDATE(),INTERVAL (DAY(CURDATE())-1) DAY),INTERVAL 12 MONTH),time_start_act) <=0 AND
(test_status_preserved in ("finished", "retention expiring", "synced") or test_status_preserved is null)
group by year(time_start_act), week(time_start_act) having y is not null';
$rs = mysql_query($sql) or flocklab_die('Cannot get statistics from database because: ' . mysql_error());
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get statistics from database because: ' . mysqli_error($db));
$testcount = Array();
while ($row = mysql_fetch_array($rs)) {
while ($row = mysqli_fetch_array($rs)) {
$testcount[$row['y'].'-'.$row['w']] = $row['num'];
}
$sql = 'select year(time_start_act) as y, week(time_start_act) as w, min(time_start_act) as minp, max(time_end_act) as maxp, max(timestampdiff(SECOND,time_start_act,time_end_act)), sum(timestampdiff(SECOND,time_start_act,time_end_act)) as duration from tbl_serv_tests
......@@ -105,9 +105,9 @@ echo '<h1>Admin Statistics</h1><table>';
(test_status_preserved in ("finished", "retention expiring", "synced") or test_status_preserved is null) and
(time_end_act is not null and time_start_act is not null and time_start_act < time_end_act and timestampdiff(SECOND,time_start_act,time_end_act) < 72 * 3600)
group by year(time_start_act), week(time_start_act) having y is not null';
$rs = mysql_query($sql) or flocklab_die('Cannot get statistics from database because: ' . mysql_error());
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get statistics from database because: ' . mysqli_error($db));
$uval=Array();$uweek=Array();
while ($row = mysql_fetch_array($rs)) {
while ($row = mysqli_fetch_array($rs)) {
// echo '<tr><td>&nbsp;&nbsp;Time occupied '.$row['y'].' week '.$row['w'].'</td><td>'.round((($row['duration'] + $testcount[$row['y'].'-'.$row['w']] * $testoverhead) / 3600)).' hours ('.round((($row['duration'] + $testcount[$row['y'].'-'.$row['w']] * $testoverhead) / (7*24*3600) * 100)).'%)</td></tr>';
array_push($uval, round((($row['duration'] + $testcount[$row['y'].'-'.$row['w']] * $testoverhead) / (7*24*3600) * 100)));
array_push($uweek, $row['w']);
......@@ -149,7 +149,7 @@ vis.render();
});
</script>
';
mysql_close($db);
mysqli_close($db);
?>
<tr><td colspan="2"><b>Weekly utilization during the most recent 12 months</b><div id="usagebars"></div></td></tr>
</table>
......
......@@ -15,26 +15,26 @@
exit(1);
if (isset($_POST['use_daq']) && isset($_POST['user_id'])) {
$db = db_connect();
$sql = "UPDATE tbl_serv_users SET use_daq=".mysql_real_escape_string($_POST['use_daq'])." WHERE serv_users_key=".mysql_real_escape_string($_POST['user_id']);
$rs = mysql_query($sql) or flocklab_die('Cannot update user propery in database because: ' . mysql_error());
mysql_close($db);
$sql = "UPDATE tbl_serv_users SET use_daq=".mysqli_real_escape_string($db, $_POST['use_daq'])." WHERE serv_users_key=".mysqli_real_escape_string($db, $_POST['user_id']);
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot update user propery in database because: ' . mysqli_error($db));
mysqli_close($db);
}
if (isset($_POST['is_active']) && isset($_POST['user_id'])) {
$db = db_connect();
$sql = "UPDATE tbl_serv_users SET is_active=".mysql_real_escape_string($_POST['is_active'])." WHERE serv_users_key=".mysql_real_escape_string($_POST['user_id']);
$rs = mysql_query($sql) or flocklab_die('Cannot update user propery in database because: ' . mysql_error());
$sql = "UPDATE tbl_serv_users SET is_active=".mysqli_real_escape_string($db, $_POST['is_active'])." WHERE serv_users_key=".mysqli_real_escape_string($db, $_POST['user_id']);
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot update user propery in database because: ' . mysqli_error($db));
// send email to the user
if ($_POST['is_active']) {
// fetch the user email
$sql = "SELECT email, last_login from tbl_serv_users where serv_users_key=".mysql_real_escape_string($_POST['user_id']);
$rs = mysql_query($sql) or flocklab_die('Cannot get user email from database because: ' . mysql_error());
$row = mysql_fetch_array($rs);
$sql = "SELECT email, last_login from tbl_serv_users where serv_users_key=".mysqli_real_escape_string($db, $_POST['user_id']);
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get user email from database because: ' . mysqli_error($db));
$row = mysqli_fetch_array($rs);
if (file_exists("template/newuser_emailtemplate.txt") && $row['last_login'] === NULL) { // only send mail to new users (who have not yet logged in)
$msg = file_get_contents("template/newuser_emailtemplate.txt");
mail($row['email'], "Re: Request for FlockLab user account", $msg, "From: flocklab@tik.ee.ethz.ch\r\nReply-To: flocklab-admin@tik.ee.ethz.ch");
}
}
mysql_close($db);
mysqli_close($db);
}
?>
<script type="text/javascript" src="scripts/jquery.cookie.js"></script>
......@@ -78,9 +78,9 @@ echo '<h1>Admin User Management</h1>';
/* Get all users from the database and display them in the table. */
$db = db_connect();
$sql = "SELECT serv_users_key, lastname, firstname, username, email, is_active, use_daq, quota_runtime, quota_tests, role, UNIX_TIMESTAMP(create_time) as create_time_ts, DATE_FORMAT(create_time,'%d.%m.%Y') as create_date, last_login from tbl_serv_users";
$rs = mysql_query($sql) or flocklab_die('Cannot get users from database because: ' . mysql_error());
$nrows = mysql_num_rows($rs);
mysql_close($db);
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get users from database because: ' . mysqli_error($db));
$nrows = mysqli_num_rows($rs);
mysqli_close($db);
?>
<form name="resadd" method="post" action="#">
<table id="res_overview" class="tablesorter" style="display:none">
......@@ -100,7 +100,7 @@ echo '<h1>Admin User Management</h1>';
<tbody>
<?php
$i = 0;
while ($row = mysql_fetch_array($rs)) {
while ($row = mysqli_fetch_array($rs)) {
$i++;
if ($i%2 == 1) {
echo "<tr class='even'>";
......
......@@ -37,11 +37,11 @@
)
) ORDER BY `a`.time_start_wish
";
$rs = mysql_query($sql) or flocklab_die('Cannot get calendar data from database because: ' . mysql_error());
$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 = mysql_fetch_array($rs)) {
while ($row = mysqli_fetch_array($rs)) {
// Create the event depending on the owner: if it is an event which belongs to the logged-in user, show more info and color it differently.
if ($row['owner_fk'] == $_SESSION['serv_users_key']) {
if ($row['test_status'] == 'failed' || $row['test_status'] == 'finished' || $row['test_status'] == 'retention expiring' || $row['test_status'] == 'deleted' || $row['test_status'] == 'todelete' ) {
......@@ -133,8 +133,8 @@
`time_end` BETWEEN "' . $mysqlstart . '" AND "' . $mysqlend . '")
GROUP BY serv_reservation_key
'. ($_SESSION['is_admin'] == true?'':'HAVING `reservation_match` is NULL OR `reservation_match` <> 1');
$rs = mysql_query($sql) or flocklab_die('Cannot get calendar data from database because: ' . mysql_error());
while ($row = mysql_fetch_array($rs)) {
$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(
'id' => $row['serv_reservation_key'],
'title' => ($_SESSION['is_admin'] == true?'Reservation for group '.$row['group_id_fk']:'Occupied'),
......@@ -145,7 +145,7 @@
$event['end'] = $row['time_end'];
array_push($events, $event);
}
mysql_close($db);
mysqli_close($db);
// JSON-encode the array and return it to the calendar:
echo json_encode($events);
......
......@@ -36,14 +36,14 @@
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";
$rs = mysql_query($sql) or die("Unknown error occurred.");
mysql_close($db);
$rs = mysqli_query($db, $sql) or die("Unknown error occurred.");
mysqli_close($db);
$config = array( "unique_id" => "flocklab.ethz.ch" );
$vcalendar = new vcalendar( $config );
// Build the events:
while ($row = mysql_fetch_array($rs)) {
while ($row = mysqli_fetch_array($rs)) {
$start = date_parse($row['time_start_w_offset']);
$end = date_parse($row['time_end_w_offset']);
$vevent = & $vcalendar->newComponent( "vevent" );
......
......@@ -19,8 +19,8 @@
$sql = 'UPDATE `tbl_serv_targetimages`
SET `binary` = NULL, `binary_hash_sha1` = NULL
WHERE `owner_fk` = '.$_SESSION['serv_users_key'].'
AND `serv_targetimages_key` = ' .mysql_real_escape_string($_POST['imageid']);
mysql_query($sql) or flocklab_die('Cannot remove image: ' . mysql_error());
AND `serv_targetimages_key` = ' .mysqli_real_escape_string($db, $_POST['imageid']);
mysqli_query($db, $sql) or flocklab_die('Cannot remove image: ' . mysqli_error($db));
}
?>
<?php
......@@ -48,9 +48,9 @@
$sql = 'SELECT `serv_targetimages_key`, `tbl_serv_targetimages`.`name` as `name`, `tbl_serv_targetimages`.`description` as `description`, `tbl_serv_operatingsystems`.`name` as `os_name`, `tbl_serv_platforms`.`name` as `platform_name`, `tbl_serv_targetimages`.`last_changed`
FROM `tbl_serv_targetimages`
LEFT JOIN (`tbl_serv_platforms`, `tbl_serv_operatingsystems`) ON (`operatingsystems_fk`=`tbl_serv_operatingsystems`.`serv_operatingsystems_key` AND `platforms_fk` = `tbl_serv_platforms`.`serv_platforms_key`)
WHERE `owner_fk` = '.$_SESSION['serv_users_key'].' AND `serv_targetimages_key` = ' .mysql_real_escape_string($_POST['imageid']);
$res = mysql_query($sql) or flocklab_die('Cannot fetch image information: ' . mysql_error());
$row = mysql_fetch_assoc($res);
WHERE `owner_fk` = '.$_SESSION['serv_users_key'].' AND `serv_targetimages_key` = ' .mysqli_real_escape_string($db, $_POST['imageid']);
$res = mysqli_query($db, $sql) or flocklab_die('Cannot fetch image information: ' . mysqli_error($db));
$row = mysqli_fetch_assoc($res);
echo '
<form method="post" action="image_delete.php" enctype="multipart/form-data">
<fieldset>
......
......@@ -17,10 +17,10 @@ if (isset($_POST['imageid']) && is_numeric($_POST['imageid']) && check_imageid($
FROM tbl_serv_targetimages i
left join tbl_serv_platforms p on (i.platforms_fk = p.serv_platforms_key)
left join tbl_serv_operatingsystems o on (i.operatingsystems_fk = o.serv_operatingsystems_key)
WHERE ".($_SESSION['is_admin']?"":("owner_fk = " . $_SESSION['serv_users_key'] . " AND "))."`serv_targetimages_key`=".mysql_real_escape_string($_POST['imageid']);
$res = mysql_query($sql);
WHERE ".($_SESSION['is_admin']?"":("owner_fk = " . $_SESSION['serv_users_key'] . " AND "))."`serv_targetimages_key`=".mysqli_real_escape_string($db, $_POST['imageid']);
$res = mysqli_query($db, $sql);
if ($res !== false) {
$row = mysql_fetch_assoc($res);
$row = mysqli_fetch_assoc($res);
// Send the file to the user's browser:
header("Content-Type: binary/octet-stream");
header("Content-Disposition: attachment; filename=\"". $_POST['imageid'] .".".$row['platform'].".".$row['operatingsystem'].".exe\"");
......
......@@ -44,10 +44,10 @@
/* Platforms with more than one core. */
$db = db_connect();
$sql = "select count(core) as corenum, name from tbl_serv_architectures left join tbl_serv_platforms on serv_platforms_key = platforms_fk group by platforms_fk having corenum > 1";
$rs = mysql_query($sql) or flocklab_die('Cannot get test images from database because: ' . mysql_error());
$nrows = mysql_num_rows($rs);
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get test images from database because: ' . mysqli_error($db));
$nrows = mysqli_num_rows($rs);
$multicore = Array();
while ($row = mysql_fetch_assoc($rs))
while ($row = mysqli_fetch_assoc($rs))
array_push($multicore, $row['name']);
/* Get all test images of the current user from the database and display them in the table. */
$sql = "SELECT `serv_targetimages_key`, `tbl_serv_targetimages`.`name` as `name`, `tbl_serv_targetimages`.`description` as `description`, `tbl_serv_architectures`.`description` as `core_desc`, `tbl_serv_operatingsystems`.`name` as `os_name`, `tbl_serv_platforms`.`name` as `platform_name`, `tbl_serv_targetimages`.`last_changed`, `test_fk`, `tbl_serv_tests`.`test_status`
......@@ -64,9 +64,9 @@
AND (`tbl_serv_targetimages`.`binary_hash_sha1` is not NULL)
GROUP BY `serv_targetimages_key`
ORDER BY `serv_targetimages_key` DESC";
$rs = mysql_query($sql) or flocklab_die('Cannot get test images from database because: ' . mysql_error());
$nrows = mysql_num_rows($rs);
mysql_close($db);
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get test images from database because: ' . mysqli_error($db));
$nrows = mysqli_num_rows($rs);
mysqli_close($db);
// If there are no tests for this user, display a message instead of the table:
if ($nrows == 0) {
......@@ -91,7 +91,7 @@
<?php
$i = 0;
$max_len = 16; // maximum length of text before beeing cut
while ($row = mysql_fetch_assoc($rs)) {
while ($row = mysqli_fetch_assoc($rs)) {
$i++;
if ($i%2 == 1) {
echo "<tr class='even'>";
......
......@@ -24,16 +24,16 @@ function db_connect()
{
global $CONFIG;
$dbh = mysql_connect($CONFIG['database']['host'], $CONFIG['database']['user'], $CONFIG['database']['password']) or flocklab_die ('Cannot connect to the database because: ' . mysql_error());
mysql_select_db($CONFIG['database']['database'], $dbh) or flocklab_die ('Cannot select database because: ' . mysql_error());
$dbh = mysqli_connect($CONFIG['database']['host'], $CONFIG['database']['user'], $CONFIG['database']['password'], $CONFIG['database']['database']) or flocklab_die ('Cannot connect to the database because: ' . mysqli_error($dbh));
$sql='SET time_zone="+0:00"';
mysql_query($sql) or flocklab_die('Cannot init timezone for database connection because: ' . mysql_error());
mysqli_query($dbh, $sql) or flocklab_die('Cannot init timezone for database connection because: ' . mysqli_error($dbh));
$sql='SET sql_mode=""';
mysql_query($sql) or flocklab_die('Cannot set sql mode for database connection because: ' . mysql_error());
mysqli_query($dbh, $sql) or flocklab_die('Cannot set sql mode for database connection because: ' . mysqli_error($dbh));
return($dbh);
}
/*
##############################################################################
#
......@@ -92,18 +92,18 @@ function do_login($username, $password) {
$db = db_connect();
$sql = "SELECT serv_users_key, username, firstname, lastname, email, role
FROM tbl_serv_users
WHERE username = '" . mysql_real_escape_string($username) . "' AND password = '" . mysql_real_escape_string(sha1($password)) . "' AND is_active=1";
$rs = mysql_query($sql) or flocklab_die('Cannot authenticate because: ' . mysql_error());
$rows = mysql_fetch_array($rs);
WHERE username = '" . mysqli_real_escape_string($db, $username) . "' AND password = '" . mysqli_real_escape_string($db, sha1($password)) . "' AND is_active=1";
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot authenticate because: ' . mysqli_error($db));
$rows = mysqli_fetch_array($rs);
if ($rows) {
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'";
$rs = mysql_query($sql) or flocklab_die('Cannot authenticate because: ' . mysql_error());
if (mysql_num_rows($rs) > 0) {
$rows = mysql_fetch_array($rs);
$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);
$d = new DateTime($row['time_end']);
return $rows['message'].'<br>Access should again be possible after <span class="time">'.$d->format("U").'</span>';
}
......@@ -111,8 +111,8 @@ function do_login($username, $password) {
// update user stats
$sql = "UPDATE tbl_serv_users set last_login=NOW(), login_count=login_count+1
WHERE serv_users_key = " . $rows['serv_users_key'];
mysql_query($sql);
mysql_close($db);
mysqli_query($db, $sql);
mysqli_close($db);
// Set session variables for this user:
$_SESSION['logged_in'] = true;
$_SESSION['serv_users_key'] = $rows['serv_users_key'];
......@@ -125,7 +125,7 @@ function do_login($username, $password) {
return true;
}
else {
mysql_close($db);
mysqli_close($db);
}
}
return false;
......@@ -165,9 +165,9 @@ function check_testid($testid, $userid) {
$sql = "SELECT owner_fk
FROM tbl_serv_tests
WHERE serv_tests_key = " . $testid;
$rs = mysql_query($sql) or flocklab_die('Cannot get test owner from database because: ' . mysql_error());
$owner = mysql_fetch_array($rs);
mysql_close($db);
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get test owner from database because: ' . mysqli_error($db));
$owner = mysqli_fetch_array($rs);
mysqli_close($db);
if ($owner['owner_fk'] == $userid)
return true;
else
......@@ -188,9 +188,9 @@ function check_imageid($imageid, $userid) {
$sql = "SELECT owner_fk
FROM tbl_serv_targetimages
WHERE serv_targetimages_key = " . $imageid;
$rs = mysql_query($sql) or flocklab_die('Cannot get test owner from database because: ' . mysql_error());
$owner = mysql_fetch_array($rs);
mysql_close($db);
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get test owner from database because: ' . mysqli_error($db));
$owner = mysqli_fetch_array($rs);
mysqli_close($db);
if ($owner['owner_fk'] == $userid)
return true;
else
......@@ -211,12 +211,12 @@ function get_admin_emails() {
$sql = "SELECT `email`
FROM tbl_serv_users
WHERE `role` = 'admin'";
$rs = mysql_query($sql) or flocklab_die('Cannot get admin emails from database because: ' . mysql_error());
$rs = mysqli_query($db, $sql) or flocklab_die('Cannot get admin emails from database because: ' . mysqli_error($db));
$admins = Array();
while ($row=mysql_fetch_array($rs)) {
while ($row=mysqli_fetch_array($rs)) {
array_push($admins, $row['email']);
}
mysql_close($db);
mysqli_close($db);
return $admins;
}
......@@ -237,19 +237,19 @@ function get_available_platforms() {
LEFT JOIN `tbl_serv_architectures`
ON `tbl_serv_architectures`.`platforms_fk` = `tbl_serv_platforms`.`serv_platforms_key`
ORDER BY `name`, `core` ASC';
$res = mysql_query($sql) or flocklab_die('Cannot fetch available platforms because: ' . mysql_error());
$num = mysql_num_rows($res);
$res = mysqli_query($db, $sql) or flocklab_die('Cannot fetch available platforms because: ' . mysqli_error($db));
$num = mysqli_num_rows($res);
$available_platforms = Array();
$pkey = -1;
while ($num-- > 0) {
$row = mysql_fetch_assoc($res);
$row = mysqli_fetch_assoc($res);
if ($pkey != $row['serv_platforms_key']) {
$pkey = $row['serv_platforms_key'];
$available_platforms[$row['serv_platforms_key']] = Array();
}
$available_platforms[$row['serv_platforms_key']][]=Array('name'=>$row['name'], 'core'=>$row['core'], 'core_desc'=>$row['core_desc']);
}
mysql_close($db);
mysqli_close($db);
return $available_platforms;
}
......@@ -267,14 +267,14 @@ function get_available_os() {
$sql = 'SELECT `serv_operatingsystems_key`, `name`
FROM `tbl_serv_operatingsystems`
ORDER BY `name` ASC';
$res = mysql_query($sql) or flocklab_die('Cannot fetch available os because: ' . mysql_error());
$num = mysql_num_rows($res);
$res = mysqli_query($db, $sql) or flocklab_die('Cannot fetch available os because: ' . mysqli_error($db));
$num = mysqli_num_rows($res);
$available_os = Array();
while ($num-- > 0) {
$row = mysql_fetch_assoc($res);
$row = mysqli_fetch_assoc($res);
$available_os[$row['serv_operatingsystems_key']]=$row['name'];
}
mysql_close($db);
mysqli_close($db);
return $available_os;
}
......@@ -282,10 +282,10 @@ 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`=".mysql_real_escape_string($testid);
$res = mysql_query($sql);
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 = mysql_fetch_assoc($res);
$row = mysqli_fetch_assoc($res);
return $row['testconfig_xml'];
}
return false;
......@@ -295,10 +295,10 @@ 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`=".mysql_real_escape_string($testid);
$res = mysql_query($sql);
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 = mysql_fetch_assoc($res);
$row = mysqli_fetch_assoc($res);
return $row['test_status'];
}
return false;
......@@ -357,19 +357,19 @@ function check_image_duplicate($image) {
WHERE `owner_fk`='.$_SESSION['serv_users_key'].'
AND `binary` IS NOT NULL
AND `binary_hash_sha1`="'.$hash.'"
AND `operatingsystems_fk`='.mysql_real_escape_string($image['os']).'
AND `platforms_fk`='.mysql_real_escape_string($image['platform']).'
AND `core`='.mysql_real_escape_string($image['core']);
$res = mysql_query($sql) or flocklab_die('Cannot compare to other images because: ' . mysql_error());
$num = mysql_num_rows($res);
AND `operatingsystems_fk`='.mysqli_real_escape_string($db, $image['os']).'
AND `platforms_fk`='.mysqli_real_escape_string($db, $image['platform']).'
AND `core`='.mysqli_real_escape_string($db, $image['core']);
$res = mysqli_query($db, $sql) or flocklab_die('Cannot compare to other images because: ' . mysqli_error($db));
$num = mysqli_num_rows($res);
while ($num-- > 0) {
$row = mysql_fetch_assoc($res);
$row = mysqli_fetch_assoc($res);
if (strcmp($row['binary'], $image['data'])==0) {
$duplicate = $row['serv_targetimages_key'];
break;
}
}
mysql_close($db);
mysqli_close($db);
return $duplicate;
}
......@@ -390,17 +390,17 @@ function store_image($image) {
$db = db_connect();
$sql = 'INSERT INTO `tbl_serv_targetimages` (`name`,`description`,`owner_fk`,`operatingsystems_fk`,`platforms_fk`,`core`,`binary`,`binary_hash_sha1`)