/** * Show info template * * @param string error message * @param array screen info */ private function show_template_info($error = null, $screen = null) { onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__); onapp_permission('roles'); $params = array('title' => onapp_string('SCREENS_'), 'screen' => $screen, 'screen_id' => onapp_get_arg('screen_id'), 'info_title' => onapp_string('SCREEN_INFO'), 'info_body' => onapp_string('SCREEN_INFO_INFO')); onapp_show_template('screen_info', $params); }
public function run() { onapp_debug(__METHOD__); global $_ALIASES, $_SCREEN_IDS; $route = onapp_get_arg('route'); onapp_debug('route => ' . $route); if (array_key_exists($route, $_SCREEN_IDS)) { $method_name = $_SCREEN_IDS[$route]['method']; $class_name = $_SCREEN_IDS[$route]['class']; } else { if (is_null($route)) { onapp_debug('$route is null!, Redirecting :' . ONAPP_BASE_URL . '/' . $_ALIASES[ONAPP_DEFAULT_ALIAS]); onapp_redirect(ONAPP_BASE_URL . '/' . $_ALIASES[ONAPP_DEFAULT_ALIAS]); } else { onapp_debug('There is no such page, Redirecting Base Url'); trigger_error('There is no such page => ' . ONAPP_BASE_URL . $route); $_SESSION['message'] = 'THERE_IS_NO_SUCH_PAGE'; onapp_redirect(ONAPP_BASE_URL); } } $file_path = ONAPP_PATH . ONAPP_DS . 'controllers' . ONAPP_DS . ONAPP_CONTROLLERS . ONAPP_DS . strtolower('c_' . $class_name . '') . '.php'; if (file_exists($file_path)) { require_once "{$file_path}"; } else { onapp_die("Could not find file {$file_path}"); } onapp_debug("ONAPP_Controller->run: args => " . print_r(array('route' => $route, 'file' => $file_path, 'class' => $class_name, 'method' => $method_name), true)); $new_class = new $class_name(); $new_class->{$method_name}(); }
/** * Main controller function * * @return void */ public function view() { $action = onapp_get_arg('action'); switch ($action) { default: $this->show_template_view(); break; } }
/** * Displays log details page * * @param object $onapp OnApp object * @return void */ public function show_template_details($onapp) { onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__); $id = onapp_get_arg('id'); onapp_debug('$id => ' . $id); $logs = $onapp->factory('Transaction', ONAPP_WRAPPER_LOG_REPORT_ENABLE); $params = array('logs_obj' => $logs->load($id), 'title' => onapp_string('TRANSACTION_DETAILS'), 'info_title' => onapp_string('TRANSACTION_DETAILS'), 'info_body' => onapp_string('TRANSACTION_DETAILS_INFO')); onapp_show_template('logs_details', $params); }
/** * Displays error log details page * * @param string error log identifier * @return void */ public function show_template_details($id) { onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__); $contents = $this->get_debug($id); $params = array('id' => onapp_get_arg('id'), 'contents' => $contents, 'title' => onapp_string('DEBUG_LOGS_DETAILS'), 'info_title' => onapp_string('DEBUG_LOGS_DETAILS'), 'info_body' => onapp_string('DEBUG_LOGS_DETAILS_INFO')); if (!$contents) { $error = 'SESSION_IDENTIFIER_NOT_FOUND_IN_LOG_FILE'; trigger_error(onapp_string($error)); $this->show_template_view($error); } else { onapp_show_template('debugLogs_details', $params); } }
/** * Displays frontend logs list * * @return void */ private function show_template_view() { onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__); $page = onapp_get_arg('page'); if (!$page) { $page = 1; } if (count(scandir(ONAPP_PATH . ONAPP_DS . ONAPP_LOG_DIRECTORY)) < 4) { $files_list = NULL; $pages_quantity = NULL; } else { $list = onapp_scan_dir(ONAPP_PATH . ONAPP_DS . ONAPP_LOG_DIRECTORY); foreach ($list as $file) { if (!preg_match("/^" . ONAPP_DEBUG_FILE_NAME . "|^index/", $file)) { $files_list[substr($file, 6, -4)]['date'] = date('Y-m-d H:i:s', filemtime(ONAPP_PATH . ONAPP_DS . ONAPP_LOG_DIRECTORY . ONAPP_DS . $file)); $files_list[substr($file, 6, -4)]['size'] = filesize(ONAPP_PATH . ONAPP_DS . ONAPP_LOG_DIRECTORY . ONAPP_DS . $file); } } if (isset($files_list) && count($files_list) > 1) { arsort($files_list); } $items_per_page = 15; $j = 0; $i = 1; if (isset($files_list) && is_array($files_list)) { foreach ($files_list as $key => $value) { $files_list_array[$i][$key] = $value; $j++; if ($j > $items_per_page) { $j = 0; $i++; } } $pages_quantity = count($files_list_array); $files_list = $files_list_array[$page]; } else { $pages_quantity = NULL; $files_list = NULL; } } $params = array('alias' => 'error_logs', 'page' => $page, 'pages_quantity' => $pages_quantity, 'files_list' => $files_list, 'title' => onapp_string('ERROR_LOGS'), 'info_title' => onapp_string('ERROR_LOGS'), 'info_body' => onapp_string('ERROR_LOGS_INFO')); onapp_show_template('errorLogs_view', $params); }
/** * Saves log settings frontend configurations * * @return void * */ private function save() { onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__); $settings = onapp_get_arg('settings'); onapp_debug('save: $settings => ' . print_r($settings, true)); if (file_exists(ONAPP_PATH . ONAPP_DS . 'config.ini')) { $conf = parse_ini_file(ONAPP_PATH . ONAPP_DS . 'config.ini'); onapp_debug('$conf => ' . print_r($conf, true)); // get constant string names instead of numeric values $frontend_error_levels = onapp_get_frontend_errors(); $php_error_levels = onapp_get_php_errors(); foreach ($conf as $key => $value) { if ($key == 'log_level_php') { $conf[$key] = $php_error_levels[$value]; } else { if ($key == 'log_level_frontend') { $conf[$key] = $frontend_error_levels[$value]; } } } $result = array_merge($conf, $settings); if (!$result) { $error = 'COULD_NOT_UPDATE_CONFIG_FILE'; } else { onapp_debug('$conf and $settings arrays merge => ' . print_r($result, true)); $updated = $this->write_config($result, ONAPP_PATH . ONAPP_DS . 'config.ini'); if (!is_null($updated)) { $error = $updated; } } if (!isset($error)) { onapp_debug('Update Success'); } } else { $error = 'CONFIG_FILE_DOES_NOT_EXISTS'; } if (!isset($error)) { $this->show_template_view('CONFIGURATIONS_HAVE_BEEN_UPDATED'); } else { trigger_error(onapp_string($error)); $this->show_template_edit($error); } }
/** * Creates a new mail template * * @global array $_ALIASES menu page aliases * @return void */ private function create() { global $_ALIASES; onapp_debug(__METHOD__); $template = onapp_get_arg('template'); if (is_null($template)) { $this->show_template_create(); } else { $content = ":template_name: " . $template['_template_name'] . "\n" . ":from: " . $template['_from'] . "\n" . ":from_name:" . $template['_from_name'] . "\n" . ":to:" . $template['_to'] . "\n" . ":copy: " . $template['_copy'] . "\n" . ":subject: " . $template['_subject'] . "\n" . "" . "\n" . $template['_message'] . "\n "; $path = ONAPP_PATH . ONAPP_DS . 'events' . ONAPP_DS . $template['_new_event'] . ONAPP_DS . 'mail' . ONAPP_DS . 'mail'; $k = 1; while (file_exists($path . $k)) { $k++; } $written = onapp_file_write($content, NULL, $path . $k); if ($written) { $_SESSION['message'] = 'TEMPLATE_HAS_BEEN_CREATED_SUCCESSFULLY'; onapp_redirect(ONAPP_BASE_URL . '/' . $_ALIASES['email_templates'] . '?action=view'); } else { $error = onapp_string('TEMPLATE_HAS_NOT_BEEN_CREATED_CHECK_EVENTS_FOLDER_PERMISSIONS'); trigger_error($error); $this->show_template_view($error); } } }
/** * Creates new cron job in cron file * * @global array $_ALIASES url aliases * @return void */ private function create() { onapp_debug(__METHOD__); global $_ALIASES; $cron = onapp_get_arg('cron'); if (!$cron) { $this->show_template_create(); } else { if ($cron['command'] == '') { $error = onapp_string('COMMAND_FIELD_COULD_NOT_BE_EMPTY'); trigger_error($error); $this->show_template_create($error); exit; } $this->ssh_connect(); $this->append_cronjob($cron['minute'] . ' ' . $cron['hour'] . ' ' . $cron['day'] . ' ' . $cron['month'] . ' ' . $cron['weekday'] . ' ' . $cron['command']); $_SESSION['message'] = 'CRON_JOB_HAS_BEEN_CREATED_SUCCESSFULLY'; onapp_redirect(ONAPP_BASE_URL . '/' . $_ALIASES['cron_manager']); } }
/** * Displays particular load balancer details page * * @param integer load balancer id * @param string error message * @return void */ public function show_template_details($id, $error = NULL) { onapp_debug(__METHOD__); onapp_debug('id => ' . $id . ' error => ' . $error); $load_balancer_obj = $this->load('LoadBalancer', array($id)); $load_balancing_cluster = $this->load('LoadBalancingCluster', array(onapp_get_arg('cluster'))); foreach ($load_balancing_cluster->_nodes as $node) { $nodes[] = $this->load('VirtualMachine', array($node->_virtual_machine_id)); } $vm_backup_obj = $this->getList('VirtualMachine_Backup', array($id)); $size_and_quantity = $this->calculateBackups($vm_backup_obj); $params = array('virtual_machine_id' => $id, 'user_obj' => $this->load('User', array($load_balancer_obj->_user_id)), 'profile_obj' => $_SESSION['profile_obj'], 'hypervisor_obj' => $this->load('Hypervisor', array($load_balancer_obj->_hypervisor_id)), 'load_balancer_obj' => $load_balancer_obj, 'backups_quantity' => $size_and_quantity['quantity'], 'backups_total_size' => $size_and_quantity['size'], 'nodes' => $nodes, 'title' => onapp_string('LOAD_BALANCER_DETAILS'), 'info_title' => onapp_string('LOAD_BALANCER_DETAILS'), 'info_body' => onapp_string('LOAD_BALANCER_DETAILS_INFO'), 'error' => $error); onapp_show_template('loadBalancers_details', $params); }
/** * Edits user group * * @global array $_ALIASES menu page aliases * @param integer user group id * @return void */ private function group_edit($id) { global $_ALIASES; onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__); onapp_debug('id => ' . $id); onapp_permission(array('groups', 'groups.update')); $group = onapp_get_arg('group'); if (is_null($group)) { $this->show_template_group_edit($id); } else { $onapp = $this->get_factory(); $group_obj = $onapp->factory('UserGroup', ONAPP_WRAPPER_LOG_REPORT_ENABLE); foreach ($group as $key => $value) { $group_obj->{$key} = $value; } $group_obj->_id = $id; //TODO delete this when fixed Ticket #2511 $group_obj->_tagRoot = 'pack'; //***************************** $group_obj->save(); onapp_debug('group_obj =>' . print_r($group_obj, true)); if (is_null($group_obj->error)) { onapp_event_exec('group_edit', array($group_obj->_obj)); $_SESSION['message'] = 'GROUP_HAS_BEEN_UPDATED_SUCCESSFULLY'; onapp_redirect(ONAPP_BASE_URL . '/' . $_ALIASES['users_and_groups'] . '?action=groups'); } else { onapp_event_exec('group_edit_failed', array($group_obj->_obj)); trigger_error(print_r($group_obj->error, true)); $this->show_template_groups($group_obj->error); } } }
private function _start_session() { onapp_debug(__METHOD__); $_SESSION['id'] = session_id(); $_SESSION['host'] = onapp_get_arg('host'); $_SESSION['lang'] = onapp_get_arg('lang'); $_SESSION['login'] = onapp_get_arg('login'); $_SESSION['password'] = onapp_cryptData(onapp_get_arg('password'), 'encrypt'); }
/** * Migrate VM to other Hypervisor * * @global array $_ALIASES menu page aliases * @param interger virtual machine id * @return void */ private function migrate($id) { global $_ALIASES; onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__); onapp_debug('id => ' . $id); onapp_permission(array('virtual_machines', 'virtual_machines.migrate', 'virtual_machines.migrate.own')); $virtual_machine = onapp_get_arg('virtual_machine'); if (!$virtual_machine) { $this->show_template_migrate($id); } else { $onapp = $this->get_factory(); $vm = $onapp->factory('VirtualMachine', ONAPP_WRAPPER_LOG_REPORT_ENABLE); $vm->migrate($id, $virtual_machine['_destination_id']); // print('<pre>');print_r($vm);die(); onapp_debug('vm => ' . print_r($vm, true)); if (is_null($vm->error)) { onapp_event_exec('vm_migrate', array($vm->_obj)); $_SESSION['message'] = 'VIRTUAL_MACHINE_MIGRATE_HAS_BEEN_QUEUED'; onapp_redirect(ONAPP_BASE_URL . '/' . $_ALIASES['virtual_machines'] . '?action=details&id=' . $id); } else { onapp_event_exec('vm_migrate_failed', array($vm->_obj)); trigger_error(print_r($vm->error, true)); $this->show_template_details($id, $vm->error); } } }
/** * Edits hypervisor's params * * @global array $_ALIASES menu page aliases * @param integer hypervisor id * @return void */ private function edit($id) { global $_ALIASES; onapp_debug(__METHOD__); onapp_debug('id => ' . $id); $hypervisor = onapp_get_arg('hypervisor'); onapp_permission(array('hypervisors.update', 'hypervisors')); if (is_null($hypervisor)) { $this->show_template_edit($id); } else { $onapp = $this->get_factory(); $id = onapp_get_arg('id'); $hypervisor_obj = $onapp->factory('Hypervisor', ONAPP_WRAPPER_LOG_REPORT_ENABLE); foreach ($hypervisor as $key => $value) { $hypervisor_obj->{$key} = $value; } $hypervisor_obj->_id = $id; $hypervisor_obj->save(); onapp_debug('hypervisor_obj =>' . print_r($hypervisor_obj, true)); if (is_null($hypervisor_obj->error)) { onapp_event_exec('hypervisor_edit', array($hypervisor_obj->_obj)); $_SESSION['message'] = 'HYPERVISOR_HAS_BEEN_UPDATED_SUCCESSFULLY'; onapp_redirect(ONAPP_BASE_URL . '/' . $_ALIASES['hypervisors']); } else { onapp_event_exec('hypervisor_edit_failed', array($hypervisor_obj->_obj)); trigger_error(print_r($hypervisor_obj->error, true)); $this->show_template_view($hypervisor_obj->error); } } }