Improve server management
This commit is contained in:
@@ -234,6 +234,29 @@ $config['parameters/create'] = array(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rules for creating servers.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
$config['servers/edit'] = array(
|
||||||
|
array(
|
||||||
|
'field' => 'description',
|
||||||
|
'label' => _('Description'),
|
||||||
|
'rules' => 'required|trim',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'field' => 'location',
|
||||||
|
'label' => _('Location'),
|
||||||
|
'rules' => 'required|max_length[255]|trim',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'field' => 'owner',
|
||||||
|
'label' => _('Owner'),
|
||||||
|
'rules' => 'required|alpha_numeric|trim',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rules for creating projects.
|
* Rules for creating projects.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -30,33 +30,88 @@ require_once APPPATH . 'core/Admin_Controller.php';
|
|||||||
class Servers extends Admin_Controller {
|
class Servers extends Admin_Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Calls the parent constructor.
|
||||||
*/
|
*/
|
||||||
function __construct() {
|
function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->load->model('server');
|
$this->load->model('server');
|
||||||
|
$this->load->library('form_validation');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all servers.
|
* Lists all servers.
|
||||||
*/
|
*/
|
||||||
function index() {
|
function index() {
|
||||||
$tpl->servers = $this->server->getAll();
|
$this->load->view('admin/servers/list', array('servers' => $this->server->getAll()));
|
||||||
|
|
||||||
$this->load->view('admin/server/list', $tpl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve details of a server.
|
* Shows details of a server.
|
||||||
*
|
*
|
||||||
* @param type $server_id
|
* @param string $serverId
|
||||||
*/
|
*/
|
||||||
function detail($server_id) {
|
function detail($serverId) {
|
||||||
$tpl->server = $this->server->getById($server_id);
|
$this->load->helper('typography');
|
||||||
|
|
||||||
$this->load->view('admin/server/detail', $tpl);
|
$data['server'] = $this->server->getById($serverId);
|
||||||
|
$data['owner'] = $this->user->getUserByID($data['server']->owner);
|
||||||
|
|
||||||
|
$this->load->view('admin/servers/detail', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows admins to edit a server.
|
||||||
|
*
|
||||||
|
* @param string $serverId
|
||||||
|
*/
|
||||||
|
public function edit($serverId) {
|
||||||
|
$server = $this->server->getById($serverId);
|
||||||
|
|
||||||
|
if (!isset($server) || !is_object($server)) {
|
||||||
|
show_404();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->form_validation->run('servers/edit') === true) {
|
||||||
|
$data = array(
|
||||||
|
'description' => $this->input->post('description'),
|
||||||
|
'location' => $this->input->post('location'),
|
||||||
|
'owner' => $this->input->post('owner'),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($this->server->update($serverId, $data)) {
|
||||||
|
$this->messages->add(sprintf(_("The server "%s" has been updated successfully."), $server->id), 'success');
|
||||||
|
}
|
||||||
|
redirect('admin/servers', 303);
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = array(); // empty data array
|
||||||
|
$data['server'] = $server;
|
||||||
|
|
||||||
|
$data['users'] = array();
|
||||||
|
|
||||||
|
$users = $this->user->getAll();
|
||||||
|
foreach ($users as $user) {
|
||||||
|
$data['users'][$user['id']] = $user['firstname'] . ' ' . $user['lastname'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->load->view('admin/servers/edit', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows admins to delete a server.
|
||||||
|
*
|
||||||
|
* @param string $serverId
|
||||||
|
*/
|
||||||
|
public function delete($serverId) {
|
||||||
|
$server = $this->server->getById($serverId);
|
||||||
|
|
||||||
|
if (!isset($server) || !is_object($server)) {
|
||||||
|
show_404();
|
||||||
|
} else {
|
||||||
|
$this->server->delete($server->id);
|
||||||
|
redirect('admin/servers', 303);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End of file servers.php */
|
/* End of file servers.php */
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php defined('BASEPATH') || exit('No direct script access allowed');
|
<?php defined('BASEPATH') || exit('No direct script access allowed');
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011 Karsten Heiken <karsten@disposed.de>
|
* Copyright (c) 2011 Karsten Heiken, Eike Foken
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -22,34 +22,36 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @author Karsten Heiken <karsten@disposed.de>
|
* @author Karsten Heiken <karsten@disposed.de>
|
||||||
*/
|
*/
|
||||||
class Server extends CI_Model {
|
class Server extends CI_Model {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new server.
|
* Creates a new server.
|
||||||
*
|
*
|
||||||
* @param array $data the server informations
|
* @param array $data The server informations
|
||||||
* @return bool was the insert successful
|
* @return boolean Returns TRUE if the insert was successful.
|
||||||
*/
|
*/
|
||||||
public function create($data) {
|
public function create($data) {
|
||||||
return $this->db->insert('servers', $data);
|
return $this->db->insert('servers', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a server.
|
* Deletes a server.
|
||||||
*
|
*
|
||||||
* @param string $server_id
|
* @param string $serverId
|
||||||
* @return bool was the deletion successful
|
* @return boolean Returns TRUE if the deletion was successful.
|
||||||
*/
|
*/
|
||||||
public function delete($server_id) {
|
public function delete($serverId) {
|
||||||
return $this->db->delete('servers', array('id' => $server_id));
|
$this->db->delete('servers', array('id' => $serverId));
|
||||||
|
return $this->db->affected_rows() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of all available servers.
|
* Gets a list of all available servers.
|
||||||
*
|
*
|
||||||
* @return array List of all available servers.
|
* @return array The list of all available servers
|
||||||
*/
|
*/
|
||||||
public function getAll() {
|
public function getAll() {
|
||||||
$servers = $this->db->get('servers')->result_array();
|
$servers = $this->db->get('servers')->result_array();
|
||||||
@@ -60,22 +62,24 @@ class Server extends CI_Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of servers that could handle another job.
|
* Gets a list of servers that could handle another job.
|
||||||
*
|
*
|
||||||
* @return array List of servers that could handle another job.
|
* @return array The list of servers that could handle another job
|
||||||
*/
|
*/
|
||||||
public function getIdle() {
|
public function getIdle() {
|
||||||
return $this->db->get_where('servers', 'workload <= 2')->result_array();
|
return $this->db->get_where('servers', 'workload <= 2')->result_array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a server.
|
* Updates a server.
|
||||||
* *
|
*
|
||||||
* @param type $secret The server's secret for basic authentication.
|
* @param type $secret The server's secret for basic authentication
|
||||||
* @param type $workload The server's workload.
|
* @param type $workload The server's workload
|
||||||
|
* @return boolean Returns TRUE if the update was successful.
|
||||||
*/
|
*/
|
||||||
public function update($server_id, $data) {
|
public function update($serverId, $data) {
|
||||||
return $this->db->where('id', $server_id)->update('servers', $data);
|
$this->db->where('id', $serverId)->update('servers', $data);
|
||||||
|
return $this->db->affected_rows() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -101,10 +105,11 @@ class Server extends CI_Model {
|
|||||||
* @param string $serverId
|
* @param string $serverId
|
||||||
*/
|
*/
|
||||||
public function getById($serverId) {
|
public function getById($serverId) {
|
||||||
$this->load->helper('date');
|
|
||||||
$server = $this->db->get_where('servers', array('id' => $serverId))->row();
|
$server = $this->db->get_where('servers', array('id' => $serverId))->row();
|
||||||
|
if (is_object($server)) {
|
||||||
$server->uptimestring = prettyTime($server->uptime);
|
$server->uptimestring = prettyTime($server->uptime);
|
||||||
$server->lastheartbeat = prettyTime(time_diff($server->last_update, mysql_now()));
|
$server->lastheartbeat = prettyTime(time_diff($server->last_update, mysql_now()));
|
||||||
|
}
|
||||||
return $server;
|
return $server;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
<?php $this->load->view('header'); ?>
|
|
||||||
|
|
||||||
<div id="content">
|
|
||||||
|
|
||||||
<div class="title">
|
|
||||||
<h2>Serververwaltung: <?=$server->id?></h2>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="box">
|
|
||||||
<h3>Miscellaneous</h3>
|
|
||||||
<h4>Location</h4>
|
|
||||||
<p><?=nl2br($server->location)?></p>
|
|
||||||
|
|
||||||
<h4>Owner</h4>
|
|
||||||
<p><a href="#" title="Profil von Jörg Thomaschewski anzeigen">Jörg Thomaschewski</a></p>
|
|
||||||
|
|
||||||
<h3>Technical information</h3>
|
|
||||||
<h4>Hardware & OS</h4>
|
|
||||||
<p>
|
|
||||||
CPU: <?=$server->hardware;?><br />
|
|
||||||
Uptime: <?=$server->uptimestring;?><br />
|
|
||||||
OS: <?=$server->os;?><br />
|
|
||||||
Workload: <?=sprintf('%.02f', $server->workload);?><br />
|
|
||||||
Last heartbeat: <?=$server->lastheartbeat;?>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<h4>ScattPort-Statistics</h4>
|
|
||||||
<p>
|
|
||||||
Completed jobs: 47<br />
|
|
||||||
Available programs: PYTHA, ABC, DEF
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php $this->load->view('footer'); ?>
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
<?php $this->load->view('header'); ?>
|
|
||||||
|
|
||||||
<div id="content">
|
|
||||||
|
|
||||||
<div class="title">
|
|
||||||
<h2>Server management</h2>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="box">
|
|
||||||
<h3>List of all available servers</h3>
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th scope="col">ID</th>
|
|
||||||
<th scope="col">Location</th>
|
|
||||||
<th scope="col">Status</th>
|
|
||||||
<th scope="col">Actions</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody class="tableList">
|
|
||||||
<?
|
|
||||||
foreach ($servers as $server):
|
|
||||||
if ($server['available']) {
|
|
||||||
if ($server['workload'] > 0.8) {
|
|
||||||
$server['class'] = "pending";
|
|
||||||
$server['status'] = 'busy';
|
|
||||||
} else {
|
|
||||||
$server['class'] = "active";
|
|
||||||
$server['status'] = 'available';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$server['class'] = "closed";
|
|
||||||
$server['status'] = "offline";
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<tr>
|
|
||||||
<td><a href="<?= site_url('admin/servers/detail/' . $server['id']) ?>"><?= $server['id'] ?></a></td>
|
|
||||||
<td><abbr title="Technikum, Raum E10"><?= $server['location'] ?></abbr></td>
|
|
||||||
<td>
|
|
||||||
<?
|
|
||||||
?>
|
|
||||||
<span class="<?= $server['class'] ?>"><?= $server['status'] ?></span></td>
|
|
||||||
<td><a href="#">Edit</a> | <a href="#">Delete</a></td>
|
|
||||||
</tr>
|
|
||||||
<?
|
|
||||||
endforeach;
|
|
||||||
?>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php $this->load->view('footer'); ?>
|
|
||||||
41
application/views/admin/servers/detail.php
Normal file
41
application/views/admin/servers/detail.php
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php $this->load->view('header');?>
|
||||||
|
|
||||||
|
<div id="content">
|
||||||
|
|
||||||
|
<div class="title">
|
||||||
|
<h2><?=anchor('admin/servers', _('Servers'));?> » <?=$server->id;?></h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box">
|
||||||
|
<h3><?=_('Miscellaneous');?></h3>
|
||||||
|
<h4><?=_('Location');?></h4>
|
||||||
|
<?=auto_typography($server->location);?>
|
||||||
|
|
||||||
|
<h4><?=_('Owner');?></h4>
|
||||||
|
<p>
|
||||||
|
<a href="<?=site_url('users/profile/' . urlencode($owner['username']));?>" title="<?=sprintf(_("Show %s's profile"), $owner['firstname'] . ' ' . $owner['lastname']);?>"><?=$owner['firstname'] . ' ' . $owner['lastname'];?></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h4><?=_('Description');?></h4>
|
||||||
|
<?=auto_typography($server->description);?>
|
||||||
|
|
||||||
|
<h3><?=_('Technical information');?></h3>
|
||||||
|
<h4><?=_('Hardware & OS');?></h4>
|
||||||
|
<p>
|
||||||
|
<?=_('CPU');?>: <?=$server->hardware;?><br />
|
||||||
|
<?=_('Uptime');?>: <?=$server->uptimestring;?><br />
|
||||||
|
<?=_('OS');?>: <?=$server->os;?><br />
|
||||||
|
<?=_('Workload');?>: <?=sprintf('%.02f', $server->workload);?><br />
|
||||||
|
<?=_('Last heartbeat');?>: <?=$server->lastheartbeat;?>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h4>ScattPort-<?=_('Statistics');?></h4>
|
||||||
|
<p>
|
||||||
|
<?=_('Completed jobs');?>: 47<br />
|
||||||
|
<?=_('Available programs');?>: ScaTT
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php $this->load->view('footer');?>
|
||||||
42
application/views/admin/servers/edit.php
Normal file
42
application/views/admin/servers/edit.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php $this->load->view('header');?>
|
||||||
|
|
||||||
|
<div id="content">
|
||||||
|
|
||||||
|
<div class="title">
|
||||||
|
<h2><?=anchor('admin/servers', _('Servers'));?> » <?=sprintf(_('Edit server "%s"'), $server->id);?></h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box">
|
||||||
|
<form name="editServer" method="post" action="<?=site_url('admin/servers/edit/' . $server->id)?>">
|
||||||
|
<h3><?=_('Required information');?></h3>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Location'), 'location');?> <span class="req">*</span>
|
||||||
|
<div>
|
||||||
|
<input type="text" name="location" id="location" class="medium text" value="<?=set_value('location', $server->location);?>" />
|
||||||
|
<?=form_error('location');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Owner'), 'owner');?> <span class="req">*</span>
|
||||||
|
<div>
|
||||||
|
<?=form_dropdown('owner', $users, $server->owner, 'id="owner" class="drop"');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Description'), 'description');?> <span class="req">*</span>
|
||||||
|
<div>
|
||||||
|
<textarea name="description" id="description" rows="6" cols="60" class="textarea"><?=set_value('description', $server->description);?></textarea>
|
||||||
|
<?=form_error('description');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<p>
|
||||||
|
<a href="javascript:void(0);" onclick="$('form[name=editServer]').submit();" class="button save"><?=_('Save');?></a>
|
||||||
|
<a href="<?=site_url('admin/servers');?>" class="button cancel"><?=_('Cancel');?></a>
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php $this->load->view('footer');?>
|
||||||
54
application/views/admin/servers/list.php
Normal file
54
application/views/admin/servers/list.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?php $this->load->view('header');?>
|
||||||
|
|
||||||
|
<div id="content">
|
||||||
|
|
||||||
|
<div class="title">
|
||||||
|
<h2><?=_('Servers');?></h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="box">
|
||||||
|
<h3><?=_('Available servers');?></h3>
|
||||||
|
<table class="tableList paginated">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col"><?=_('ID');?></th>
|
||||||
|
<th scope="col"><?=_('Location');?></th>
|
||||||
|
<th scope="col"><?=_('Status');?></th>
|
||||||
|
<th scope="col"><?=_('Actions');?></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php
|
||||||
|
foreach ($servers as $server):
|
||||||
|
if ($server['available'] != 0) {
|
||||||
|
if ($server['workload'] > 0.8) {
|
||||||
|
$server['class'] = 'pending';
|
||||||
|
$server['status'] = 'busy';
|
||||||
|
} else {
|
||||||
|
$server['class'] = 'active';
|
||||||
|
$server['status'] = 'available';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$server['class'] = 'closed';
|
||||||
|
$server['status'] = 'offline';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td><a href="<?= site_url('admin/servers/detail/' . $server['id']) ?>"><?= $server['id'] ?></a></td>
|
||||||
|
<td><abbr title="Technikum, Raum E10"><?= $server['location'] ?></abbr></td>
|
||||||
|
<td><span class="<?= $server['class'] ?>"><?= $server['status'] ?></span></td>
|
||||||
|
<td>
|
||||||
|
<a href="<?=site_url('admin/servers/detail/' . $server['id']);?>" title="<?=_('Show details');?>"><?=_('Show');?></a> |
|
||||||
|
<a href="<?=site_url('admin/servers/edit/' . $server['id']);?>" title="<?=_('Edit this server');?>"><?=_('Edit');?></a> |
|
||||||
|
<a href="javascript:deleteConfirm('<?=site_url('admin/servers/delete/' . $server['id']);?>');" title="<?=_('Delete this server');?>"><?=_('Delete');?></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php
|
||||||
|
endforeach;
|
||||||
|
?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php $this->load->view('footer');?>
|
||||||
Reference in New Issue
Block a user