Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 48f78ec

Browse files
author
Jamie Snape
committed
Migrate remoteprocessing module settings to database
1 parent 05f5d6e commit 48f78ec

File tree

18 files changed

+301
-340
lines changed

18 files changed

+301
-340
lines changed

modules/remoteprocessing/Notification.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Remoteprocessing_Notification extends ApiEnabled_Notification
2626
public $moduleName = 'remoteprocessing';
2727
public $_moduleComponents = array('Api');
2828
public $_moduleModels = array('Job');
29-
public $_models = array('Item');
29+
public $_models = array('Item', 'Setting');
3030
public $_moduleDaos = array('Job');
3131

3232
/** init notification process */
@@ -63,8 +63,7 @@ public function getFooter()
6363
/** add a process button */
6464
public function getButton($params)
6565
{
66-
$modulesConfig = Zend_Registry::get('configsModules');
67-
if ($modulesConfig[$this->moduleName]->showbutton) {
66+
if ($this->Setting->getValueByName(MIDAS_REMOTEPROCESSING_SHOW_BUTTON_KEY, $this->moduleName) == 1) {
6867
$html = "<li class='processButton' style='margin-left:5px;' title='Process' rel='".Zend_Registry::get(
6968
'webroot'
7069
)."/remoteprocessing/index/selectaction'>

modules/remoteprocessing/configs/module.ini

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,4 @@ description = "Run remote processes"
66
category = "Processing"
77
dependencies = api,scheduler
88
uuid = "e341ea40-5fff-4906-ac05-94f6bc890f91"
9-
version = "1.0.2"
10-
11-
securitykey = ""
12-
showbutton = "1"
9+
version = "1.1.0"

modules/remoteprocessing/constant/module.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
limitations under the License.
1919
=========================================================================*/
2020

21+
define('MIDAS_REMOTEPROCESSING_SECURITY_KEY_KEY', 'security_key');
22+
define('MIDAS_REMOTEPROCESSING_SHOW_BUTTON_KEY', 'show_button');
23+
define('MIDAS_REMOTEPROCESSING_SHOW_BUTTON_DEFAULT_VALUE', 1);
24+
2125
define('MIDAS_REMOTEPROCESSING_OS_WINDOWS', 'windows');
2226
define('MIDAS_REMOTEPROCESSING_OS_LINUX', 'linux');
2327

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** Admin controller for the remoteprocessing module. */
22+
class Remoteprocessing_AdminController extends Remoteprocessing_AppController
23+
{
24+
/** @var array */
25+
public $_models = array('Setting');
26+
27+
/** Index action */
28+
public function indexAction()
29+
{
30+
$this->requireAdminPrivileges();
31+
32+
$this->view->pageTitle = 'Remote Processing Module Configuration';
33+
$form = new Remoteprocessing_Form_Admin();
34+
35+
if ($this->getRequest()->isPost()) {
36+
$data = $this->getRequest()->getPost();
37+
38+
if ($form->isValid($data)) {
39+
$values = $form->getValues();
40+
41+
foreach ($values as $key => $value) {
42+
$this->Setting->setConfig($key, $value, $this->moduleName);
43+
}
44+
}
45+
46+
$form->populate($data);
47+
} else {
48+
$elements = $form->getElements();
49+
50+
foreach ($elements as $element) {
51+
$name = $element->getName();
52+
53+
if ($name !== 'csrf' && $name !== 'submit') {
54+
$value = $this->Setting->getValueByName($name, $this->moduleName);
55+
56+
if (!is_null($value)) {
57+
$form->setDefault($name, $value);
58+
}
59+
}
60+
}
61+
}
62+
63+
$this->view->form = $form;
64+
session_start();
65+
}
66+
67+
/** Download remote script action. */
68+
public function downloadAction()
69+
{
70+
while (ob_get_level() > 0) {
71+
ob_end_clean();
72+
}
73+
74+
$this->requireAdminPrivileges();
75+
$this->disableLayout();
76+
$this->disableView();
77+
78+
ob_start();
79+
$zip = new ZipStream('RemoteScript.zip');
80+
$file = BASE_PATH.'/modules/remoteprocessing/remotescript/main.py';
81+
$zip->add_file_from_path(basename($file), $file);
82+
$file = BASE_PATH.'/modules/remoteprocessing/remotescript/config.cfg';
83+
$zip->add_file_from_path(basename($file), $file);
84+
$dirname = BASE_PATH.'/modules/remoteprocessing/remotescript/pydas/';
85+
$dir = opendir($dirname);
86+
87+
while ($file = readdir($dir)) {
88+
if ($file != '.' && $file != '..' && !is_dir($dirname.$file)) {
89+
$zip->add_file_from_path('pydas/'.basename($dirname.$file), $dirname.$file);
90+
}
91+
}
92+
93+
$zip->finish();
94+
exit();
95+
}
96+
}

modules/remoteprocessing/controllers/ConfigController.php

Lines changed: 0 additions & 113 deletions
This file was deleted.

modules/remoteprocessing/controllers/components/ApiComponent.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
/** Component for api methods */
2424
class Remoteprocessing_ApiComponent extends AppComponent
2525
{
26+
public $moduleName = 'remoteprocessing';
27+
2628
/**
2729
* Register a server
2830
*
@@ -35,32 +37,35 @@ class Remoteprocessing_ApiComponent extends AppComponent
3537
public function registerserver($args)
3638
{
3739
$os = '';
38-
$apikey = '';
40+
$apiKey = '';
3941
$email = '';
40-
$securitykey = '';
42+
$securityKey = '';
4143
if (isset($args['os'])) {
4244
$os = $args['os'];
4345
}
4446
if (isset($args['apikey'])) {
45-
$apikey = $args['apikey'];
47+
$apiKey = $args['apikey'];
4648
}
4749
if (isset($args['email'])) {
4850
$email = $args['email'];
4951
}
5052
if (isset($args['securitykey'])) {
51-
$securitykey = $args['securitykey'];
53+
$securityKey = $args['securitykey'];
5254
}
5355

54-
$modulesConfig = Zend_Registry::get('configsModules');
55-
$checkSecuritykey = $modulesConfig['remoteprocessing']->securitykey;
56-
if (empty($securitykey) || $securitykey != $checkSecuritykey) {
57-
throw new Exception('Error security key.', MIDAS_INVALID_PARAMETER);
56+
/** @var SettingModel $settingModel */
57+
$settingModel = MidasLoader::loadModel('Setting');
58+
$checkSecurityKey = $settingModel->getValueByName(MIDAS_REMOTEPROCESSING_SECURITY_KEY_KEY, $this->moduleName);
59+
60+
if (empty($securityKey) || $securityKey != $checkSecurityKey) {
61+
throw new Exception('Error security key. '.$securityKey.' '.$checkSecurityKey, MIDAS_INVALID_PARAMETER);
5862
}
5963

6064
$userModel = MidasLoader::loadModel('User');
6165
$groupModel = MidasLoader::loadModel('Group');
62-
$UserapiModel = MidasLoader::loadModel('Userapi');
63-
if (empty($apikey)) {
66+
$userApiModel = MidasLoader::loadModel('Userapi');
67+
68+
if (empty($apiKey)) {
6469
if (empty($os)) {
6570
throw new Exception('Error os parameter.', MIDAS_INVALID_PARAMETER);
6671
}
@@ -75,24 +80,24 @@ public function registerserver($args)
7580
$serverGroup = $groupModel->load(MIDAS_GROUP_SERVER_KEY);
7681
$groupModel->addUser($serverGroup, $userDao);
7782

78-
$userapiDao = $UserapiModel->getByAppAndUser('remoteprocessing', $userDao);
83+
$userapiDao = $userApiModel->getByAppAndUser('remoteprocessing', $userDao);
7984
if ($userapiDao == false) {
80-
$userapiDao = $UserapiModel->createKey($userDao, 'remoteprocessing', '100');
85+
$userapiDao = $userApiModel->createKey($userDao, 'remoteprocessing', '100');
8186
}
8287

83-
$apikey = $userapiDao->getApikey();
88+
$apiKey = $userapiDao->getApikey();
8489

8590
Zend_Registry::get('notifier')->callback('CALLBACK_REMOTEPROCESSING_CREATESERVER', $userDao->toArray());
8691
}
8792

88-
$tokenDao = $UserapiModel->getToken($email, $apikey, 'remoteprocessing');
93+
$tokenDao = $userApiModel->getToken($email, $apiKey, 'remoteprocessing');
8994
if (empty($tokenDao)) {
9095
throw new Exception('Unable to authenticate. Please check credentials.', MIDAS_INVALID_PARAMETER);
9196
}
9297

9398
$data['token'] = $tokenDao->getToken();
9499
$data['email'] = $email;
95-
$data['apikey'] = $apikey;
100+
$data['apikey'] = $apiKey;
96101

97102
return $data;
98103
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
require_once BASE_PATH.'/modules/remoteprocessing/constant/module.php';
22+
23+
/** Install the remoteprocessing module. */
24+
class Remoteprocessing_InstallScript extends MIDASModuleInstallScript
25+
{
26+
/** @var string */
27+
public $moduleName = 'remoteprocessing';
28+
29+
/** Post database install. */
30+
public function postInstall()
31+
{
32+
/** @var RandomComponent $randomComponent */
33+
$randomComponent = MidasLoader::loadComponent('Random');
34+
$securityKey = $randomComponent->generateString(32);
35+
36+
/** @var SettingModel $settingModel */
37+
$settingModel = MidasLoader::loadModel('Setting');
38+
$settingModel->setConfig(MIDAS_REMOTEPROCESSING_SECURITY_KEY_KEY, $securityKey, $this->moduleName);
39+
$settingModel->setConfig(MIDAS_REMOTEPROCESSING_SHOW_BUTTON_KEY, MIDAS_REMOTEPROCESSING_SHOW_BUTTON_DEFAULT_VALUE, $this->moduleName);
40+
}
41+
}

modules/remoteprocessing/database/mysql/1.0.2.sql renamed to modules/remoteprocessing/database/mysql/1.1.0.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0.
22

3-
-- MySQL database for the remoteprocessing module, version 1.0.2
3+
-- MySQL database for the remoteprocessing module, version 1.1.0
44

55
CREATE TABLE IF NOT EXISTS `remoteprocessing_job` (
66
`job_id` bigint(20) NOT NULL AUTO_INCREMENT,

modules/remoteprocessing/database/pgsql/1.0.2.sql renamed to modules/remoteprocessing/database/pgsql/1.1.0.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0.
22

3-
-- PostgreSQL database for the remoteprocessing module, version 1.0.2
3+
-- PostgreSQL database for the remoteprocessing module, version 1.1.0
44

55
SET client_encoding = 'UTF8';
66
SET default_with_oids = FALSE;

0 commit comments

Comments
 (0)