Revize 1025
Přidáno uživatelem Michal Kliment před více než 13 roky(ů)
freenetis/branches/testing/media/css/style.css | ||
---|---|---|
|
||
.ui-autocomplete-loading {
|
||
background: white url('../images/ui-anim_basic_16x16.gif') right center no-repeat;
|
||
}
|
||
|
||
.ssh-key {
|
||
width: 347px;
|
||
word-wrap: break-word;
|
||
}
|
||
|
||
.ssh-key-link {
|
||
float:right;
|
||
margin-right: 5px;
|
||
}
|
freenetis/branches/testing/application/i18n/cs_CZ/texts.php | ||
---|---|---|
'add new ip address' => 'Přidat novou IP adresu',
|
||
'add new ip address to device' => 'Přidat novou IP adresu k zařízení',
|
||
'add new items' => 'Přidat nové položky',
|
||
'add new key' => 'Přidat nový klíč',
|
||
'add new member' => 'Přidat nového člena',
|
||
'add new message' => 'Přidat novou zprávu',
|
||
'add new port' => 'Přidat nový port',
|
||
'add new project account' => 'Přidat nový projektový účet',
|
||
'add new redirection message' => 'Přidat novou zprávu přesměrování',
|
||
'add new segment' => 'Přidat nový segment',
|
||
'add new ssh key' => 'Přidat nový SSH klíč',
|
||
'add new ssh key to user' => 'Přidat nový SSH klíč uživateli',
|
||
'add new street' => 'Přidat novou ulici',
|
||
'add new subnet' => 'Přidat novou podsíť',
|
||
'add new template' => 'Přidat novou šablonu',
|
||
... | ... | |
'edit invoice item' => 'Upravit položku faktury',
|
||
'edit ip address' => 'Upravit IP adresu',
|
||
'edit ip address redirection' => 'Upravit přesměrování IP adresy',
|
||
'edit key' => 'Upravit klíč',
|
||
'edit maximum count' => 'Upravit maximální počet',
|
||
'edit maximum count of allowed subnets of member' => 'Upravit maximální počet povolených podsítí člena',
|
||
'edit member' => 'Upravit člena',
|
||
... | ... | |
'edit segment' => 'Úprava segmentu',
|
||
'edit smokeping record' => 'Upravit záznam smokepingu',
|
||
'edit the work' => 'Upravit práci',
|
||
'edit ssh key' => 'Upravit SSH klíč',
|
||
'edit ssh key of user' => 'Upravit SSH klíč uživatele',
|
||
'edit street' => 'Upravit ulici',
|
||
'edit subnet' => 'Upravit podsíť',
|
||
'edit tariff of member' => 'Upravit tarif člena',
|
||
... | ... | |
'january' => 'Leden',
|
||
'june' => 'Červen',
|
||
'july' => 'Červenec',
|
||
'key' => 'Klíč',
|
||
'key has been successfully added' => 'Klíč byl úspěšně přidán.',
|
||
'key has been successfully deleted' => 'Klíč byl úspěšně smazán.',
|
||
'key has been successfully updated' => 'Klíč byl úspěšně aktualizován.',
|
||
'language' => 'Jazyk',
|
||
'last changed author' => 'Autor poslední úpravy',
|
||
'last changed date' => 'Datum poslední úpravy',
|
||
... | ... | |
'some phones wasn\'t founded' => 'Některé telefony nebyly nalezeny',
|
||
'someone from the ip address %s, probably you, requested to change your password' => 'někdo, patrně Vy, žádal z IP %s o změnu vašeho hesla',
|
||
'specific symbol' => 'Specifický symbol',
|
||
'ssh key' => 'SSH klíč',
|
||
'ssh keys' => 'SSH klíče',
|
||
'start amount' => 'Počáteční částka',
|
||
'static ip' => 'Statická IP',
|
||
'statistics' => 'Statistiky',
|
freenetis/branches/testing/application/models/users_key.php | ||
---|---|---|
<?php
|
||
/**
|
||
*
|
||
* @author Michal Kliment
|
||
* @copyright (c) 2011 Kliment Michal
|
||
* @license GNU GPLv3
|
||
* @license http://www.gnu.org/licenses/gpl.txt
|
||
*/
|
||
|
||
class Users_key_Model extends ORM
|
||
{
|
||
protected $belongs_to = array ('user');
|
||
|
||
/**
|
||
* Returns all keys belongs to device
|
||
*
|
||
* @author Michal Kliment
|
||
* @param integer $device_id
|
||
* @return array
|
||
*/
|
||
public function get_keys_by_device ($device_id)
|
||
{
|
||
return arr::from_objects(
|
||
$this->db->query("
|
||
SELECT k.id, k.key FROM
|
||
(
|
||
(
|
||
SELECT u.id from device_admins a
|
||
JOIN users u ON a.user_id = u.id
|
||
WHERE a.device_id = ?
|
||
)
|
||
UNION
|
||
(
|
||
SELECT 1 AS id
|
||
)
|
||
) AS u
|
||
JOIN users_keys k ON u.id = k.user_id
|
||
",
|
||
array($device_id))->as_array(),
|
||
'key');
|
||
}
|
||
}
|
||
|
||
?>
|
freenetis/branches/testing/application/models/user.php | ||
---|---|---|
public static $user = 2;
|
||
|
||
protected $belongs_to = array('member');
|
||
protected $has_many = array('jobs', 'devices', 'logs', 'phone_invoices_users', 'users' => 'private_phone_contacts');
|
||
protected $has_many = array('jobs', 'devices', 'logs', 'phone_invoices_users', 'users' => 'private_phone_contacts', 'users_keys');
|
||
protected $has_and_belongs_to_many = array('users_contacts' => 'contacts');
|
||
|
||
public $arr_sql = array('id' => 'u.id', 'name' => 'u.name', 'surname' => 'u.surname', 'login' => 'u.login', 'member_name' => 'm.name', 'email' => 'c.value');
|
freenetis/branches/testing/application/controllers/web_interface.php | ||
---|---|---|
}
|
||
}
|
||
|
||
/**
|
||
* Generates authorized keys to device
|
||
*
|
||
* @author Michal Kliment
|
||
* @param integer $device_id
|
||
* @return mixed
|
||
*/
|
||
public function authorized_keys ($device_id = NULL)
|
||
{
|
||
// bad parameter
|
||
if (!$device_id || !is_numeric($device_id))
|
||
return;
|
||
|
||
// finds all keys by device
|
||
$keys = ORM::factory('users_key')->get_keys_by_device ($device_id);
|
||
|
||
foreach ($keys as $key)
|
||
{
|
||
echo "$key\n";
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Prints all user's keys
|
||
*
|
||
* @author Michal Kliment
|
||
* @param integer $user_id
|
||
* @return mixed
|
||
*/
|
||
public function key ($user_id = NULL)
|
||
{
|
||
// bad parameter
|
||
if (!$user_id || !is_numeric($user_id))
|
||
return;
|
||
|
||
// finds all keys by user
|
||
$keys = ORM::factory('users_key')->where('user_id', $user_id)->find_all();
|
||
|
||
foreach ($keys as $key)
|
||
{
|
||
echo "$key->key\n";
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
?>
|
freenetis/branches/testing/application/controllers/users_keys.php | ||
---|---|---|
<?php
|
||
/**
|
||
*
|
||
* @author Michal Kliment
|
||
* @copyright (c) 2011 Kliment Michal
|
||
* @license GNU GPLv3
|
||
* @license http://www.gnu.org/licenses/gpl.txt
|
||
*/
|
||
|
||
class Users_keys_Controller extends Controller
|
||
{
|
||
/**
|
||
* Adds new SSH key to user
|
||
*
|
||
* @author Michal Kliment
|
||
* @param integer $user_id
|
||
*/
|
||
public function add ($user_id = NULL)
|
||
{
|
||
// bad parameter
|
||
if (!$user_id || !is_numeric($user_id))
|
||
Controller::warning(PARAMETER);
|
||
|
||
$user = new User_Model($user_id);
|
||
|
||
// user doesn't exist
|
||
if (!$user->id)
|
||
Controller::error(RECORD);
|
||
|
||
// access control
|
||
if (!$this->acl_check_new('Users_Controller', 'keys', $user->member_id))
|
||
Controller::error(ACCESS);
|
||
|
||
$user_name = $user->name.' '.$user->surname;
|
||
|
||
// creates form
|
||
$form = new Forge(url::base(TRUE).url::current(TRUE), '', 'POST', array('id' => 'article_form'));
|
||
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
$form->dropdown('user_id')->label(url_lang::lang('texts.User').':')->options(array($user->id => $user_name))->rules('required');
|
||
$form->textarea('key')->label(url_lang::lang('texts.Key').':')->rules('required');
|
||
|
||
$form->submit('submit')->value(url_lang::lang('texts.Add'));
|
||
special::required_forge_style($form, ' *', 'required');
|
||
|
||
// form is validate
|
||
if ($form->validate())
|
||
{
|
||
$form_data = $form->as_array();
|
||
|
||
$users_key = new Users_key_Model();
|
||
$users_key->user_id = $user->id;
|
||
$users_key->key = html::specialchars ($form_data['key']);
|
||
|
||
// success
|
||
if ($users_key->save())
|
||
$this->session->set_flash('message', url_lang::lang('texts.Key has been successfully added.'));
|
||
|
||
url::redirect (url_lang::base().'users/show/'.$user->id);
|
||
}
|
||
|
||
// creates breadcrumbs
|
||
$breadcrumbs = array();
|
||
$breadcrumbs[] = ($this->acl_check_view('Members_Controller','members')) ? html::anchor (url_lang::base().'members/show_all', url_lang::lang('texts.Members')) : url_lang::lang('texts.Members');
|
||
$breadcrumbs[] = ($this->acl_check_view('Members_Controller','members', $user->member->id)) ? html::anchor(url_lang::base().'members/show/'.$user->member->id, "ID ".$user->member->id." - ".$user->member->name) : "ID ".$user->member->id." - ".$user->member->name;
|
||
$breadcrumbs[] = ($this->acl_check_view('Users_Controller','users',$user->member_id)) ? html::anchor (url_lang::base().'users/show_by_member/'.$user->member_id, url_lang::lang('texts.Users')) : url_lang::lang('texts.Users');
|
||
$breadcrumbs[] = ($this->acl_check_view('Users_Controller','users',$user->member_id)) ? html::anchor (url_lang::base().'users/show/'.$user->id, "$user_name ($user->login)") : "$user_name ($user->login)";
|
||
$breadcrumbs[] = url_lang::lang('texts.Add new SSH key');
|
||
|
||
$title = url_lang::lang('texts.Add new SSH key to user').' '.$user_name;
|
||
|
||
$view = new View('main');
|
||
$view->breadcrumbs = implode(' » ', $breadcrumbs);
|
||
$view->title = $title;
|
||
$view->content = new View('form');
|
||
$view->content->headline = $title;
|
||
$view->content->form = $form;
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
/**
|
||
* Edits SSH key of user
|
||
*
|
||
* @author Michal Kliment
|
||
* @param integer $users_key_id
|
||
*/
|
||
public function edit ($users_key_id = NULL)
|
||
{
|
||
// bad parameter
|
||
if (!$users_key_id || !is_numeric($users_key_id))
|
||
Controller::warning(PARAMETER);
|
||
|
||
$users_key = new Users_key_Model($users_key_id);
|
||
|
||
// key doesn't exist
|
||
if (!$users_key->id)
|
||
Controller::error(RECORD);
|
||
|
||
// access control
|
||
if (!$this->acl_check_edit('Users_Controller', 'keys', $users_key->user->member_id))
|
||
Controller::error(ACCESS);
|
||
|
||
$user_name = $users_key->user->name.' '.$users_key->user->surname;
|
||
|
||
// creates form
|
||
$form = new Forge(url::base(TRUE).url::current(TRUE), '', 'POST', array('id' => 'article_form'));
|
||
$form->set_attr('class', 'form_class')->set_attr('method', 'post');
|
||
|
||
$form->dropdown('user_id')->label(url_lang::lang('texts.User').':')->options(array($users_key->user->id => $user_name))->rules('required');
|
||
$form->textarea('key')->label(url_lang::lang('texts.Key').':')->rules('required')->value($users_key->key);
|
||
|
||
$form->submit('submit')->value(url_lang::lang('texts.Add'));
|
||
special::required_forge_style($form, ' *', 'required');
|
||
|
||
// form is validate
|
||
if ($form->validate())
|
||
{
|
||
$form_data = $form->as_array();
|
||
|
||
$users_key = new Users_key_Model($users_key->id);
|
||
$users_key->key = html::specialchars ($form_data['key']);
|
||
|
||
// success
|
||
if ($users_key->save())
|
||
$this->session->set_flash('message', url_lang::lang('texts.Key has been successfully updated.'));
|
||
|
||
url::redirect (url_lang::base().'users/show/'.$users_key->user->id);
|
||
}
|
||
|
||
// creates breadcrumbs
|
||
$breadcrumbs = array();
|
||
$breadcrumbs[] = ($this->acl_check_view('Members_Controller','members')) ? html::anchor (url_lang::base().'members/show_all', url_lang::lang('texts.Members')) : url_lang::lang('texts.Members');
|
||
$breadcrumbs[] = ($this->acl_check_view('Members_Controller','members', $users_key->user->member->id)) ? html::anchor(url_lang::base().'members/show/'.$users_key->user->member->id, "ID ".$users_key->user->member->id." - ".$users_key->user->member->name) : "ID ".$users_key->user->member->id." - ".$users_key->user->member->name;
|
||
$breadcrumbs[] = ($this->acl_check_view('Users_Controller','users',$users_key->user->member_id)) ? html::anchor (url_lang::base().'users/show_by_member/'.$users_key->user->member_id, url_lang::lang('texts.Users')) : url_lang::lang('texts.Users');
|
||
$breadcrumbs[] = ($this->acl_check_view('Users_Controller','users',$users_key->user->member_id)) ? html::anchor (url_lang::base().'users/show/'.$users_key->user->id, "$user_name (".$users_key->user->login.")") : "$user_name (".$users_key->user->login.")";
|
||
$breadcrumbs[] = url_lang::lang('texts.Edit SSH key');
|
||
|
||
$title = url_lang::lang('texts.Edit SSH key of user').' '.$user_name;
|
||
|
||
$view = new View('main');
|
||
$view->breadcrumbs = implode(' » ', $breadcrumbs);
|
||
$view->title = $title;
|
||
$view->content = new View('form');
|
||
$view->content->headline = $title;
|
||
$view->content->form = $form;
|
||
$view->render(TRUE);
|
||
}
|
||
|
||
/**
|
||
* Deletes SSH key
|
||
*
|
||
* @author Michal Kliment
|
||
* @param integer $users_key_id
|
||
*/
|
||
public function delete ($users_key_id = NULL)
|
||
{
|
||
// bad parameter
|
||
if (!$users_key_id || !is_numeric($users_key_id))
|
||
Controller::warning(PARAMETER);
|
||
|
||
$users_key = new Users_key_Model($users_key_id);
|
||
|
||
// key doesn't exist
|
||
if (!$users_key->id)
|
||
Controller::error(RECORD);
|
||
|
||
// access control
|
||
if (!$this->acl_check_new('Users_Controller', 'keys', $users_key->user->member_id))
|
||
Controller::error(ACCESS);
|
||
|
||
$user_id = $users_key->user_id;
|
||
|
||
// success
|
||
if ($users_key->delete())
|
||
$this->session->set_flash('message', url_lang::lang('texts.Key has been successfully deleted.'));
|
||
|
||
url::redirect(url_lang::base().'users/show/'.$user_id);
|
||
}
|
||
}
|
||
|
||
?>
|
freenetis/branches/testing/application/upgrade_sql/upgrade_sql.php | ||
---|---|---|
// array of sql queries that upgrade database
|
||
$upgrade_sql[get_SVN_rev()] = array(
|
||
|
||
"CREATE TABLE IF NOT EXISTS `members_domiciles` (
|
||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||
`member_id` int(11) NOT NULL,
|
||
`address_point_id` int(11) NOT NULL,
|
||
PRIMARY KEY (`id`),
|
||
KEY `member_id` (`member_id`,`address_point_id`)
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;",
|
||
"CREATE TABLE `users_keys` (
|
||
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
|
||
`user_id` INT( 11 ) NOT NULL ,
|
||
`key` TEXT NOT NULL ,
|
||
INDEX ( `user_id` )
|
||
) ENGINE = INNODB;",
|
||
|
||
"INSERT INTO `axo` (`id`, `section_value`, `value`, `order_value`, `name`, `hidden`) VALUES ('176', 'Users_Controller', 'keys', '0', 'Keys (SSH)', '0');",
|
||
|
||
"INSERT INTO `axo_map` (`acl_id`, `section_value`, `value`) VALUES ('38', 'Users_Controller', 'keys');",
|
||
|
||
"INSERT INTO `axo_map` (`acl_id`, `section_value`, `value`) VALUES ('64', 'Users_Controller', 'keys');",
|
||
|
||
);
|
||
?>
|
freenetis/branches/testing/application/upgrade_sql/upgrade_sql_969.php | ||
---|---|---|
<?php
|
||
|
||
// array of sql queries that upgrade database
|
||
$upgrade_sql[969] = array(
|
||
|
||
"CREATE TABLE IF NOT EXISTS `members_domiciles` (
|
||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||
`member_id` int(11) NOT NULL,
|
||
`address_point_id` int(11) NOT NULL,
|
||
PRIMARY KEY (`id`),
|
||
KEY `member_id` (`member_id`,`address_point_id`)
|
||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;",
|
||
|
||
);
|
||
?>
|
freenetis/branches/testing/application/libraries/Forge.php | ||
---|---|---|
$form->inputs = $this->inputs;
|
||
}
|
||
|
||
return $form;
|
||
return $form->render();
|
||
}
|
||
|
||
/**
|
freenetis/branches/testing/application/views/users_show.php | ||
---|---|---|
<td><?php echo url_lang::lang('texts.'.$aro_group->name) ?></td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
<tr>
|
||
<th colspan="2"><?php echo url_lang::lang('texts.SSH keys') ?></th>
|
||
</tr>
|
||
<?php foreach ($user_data->users_keys as $key): ?>
|
||
<tr>
|
||
<td colspan="2">
|
||
<div class="ssh-key">
|
||
<?php echo $key->key ?><br />
|
||
<?php echo html::anchor (url_lang::base().'users_keys/delete/'.$key->id, url_lang::lang('texts.Delete'), array('class' => 'delete_link ssh-key-link')) ?>
|
||
<?php echo html::anchor (url_lang::base().'users_keys/edit/'.$key->id, url_lang::lang('texts.Edit'), array('class' => 'ssh-key-link')) ?>
|
||
<div class="clear"></div>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
<?php endforeach ?>
|
||
<tr>
|
||
<td colspan="2"><?php echo html::anchor(url_lang::base().'users_keys/add/'.$user_data->id, url_lang::lang('texts.Add new key')) ?></td>
|
||
</tr>
|
||
</table>
|
Také k dispozici: Unified diff
Implementace SSH klicu do Freenetisu - kazdy uzivatel si muze pridat do systemu N klicu. Pomoci metody authorized_keys v kontroleru web_interface se pak generuje soubor authorized_keys pro zarizeni podle jeho spravcu.