/** * 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); }
/** * Performs Login actions * * @global array $_ALIASES menu page aliases * @return void */ function login() { global $_ALIASES; $login = onapp_get_arg('login'); $password = onapp_get_arg('password'); $host = onapp_get_arg('host'); $submit = onapp_get_arg('submit'); if (preg_match('/,/', $host)) { $host = explode(',', $host); foreach ($host as $hst) { $logedin = $this->login_action($login, $password, trim($hst)); if ($logedin) { $_SESSION['host'] = trim($hst); $this->after_logedin_action(); exit; } } onapp_debug('login failed couldn\'t get APIVersion'); $params = array('error_message' => onapp_string('ERORR_WRONG_LOGIN_DATA')); onapp_show_template('login', $params); exit; } if (is_null($submit)) { } elseif (!is_null($submit) && $this->login_action($login, $password, $host)) { onapp_debug('Login successfull!'); $this->after_logedin_action(); } else { onapp_debug('login failed couldn\'t get APIVersion'); $params = array('error_message' => onapp_string('ERORR_WRONG_LOGIN_DATA')); } if (!isset($params)) { $params = NULL; } onapp_show_template('login', $params); }
/** * 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); }
/** * Shows template view * * @return void */ public function show_template_view($error = NULL) { $postfields = array('clientid' => 1); $response = onapp_send_whmcs_api_request(ONAPP_WHMCS_LOGIN, ONAPP_WHMCS_PASSWORD, ONAPP_WHMCS_API_FILE_URL, 'getclientsdetails', $postfields); print '<pre>'; print_r($response); die; onapp_show_template('test_view', array('title' => onapp_string('TEST_'), 'info_title' => onapp_string('TEST_'), 'info_body' => onapp_string('TEST_INFO'), 'error' => onapp_string($error))); }
/** * 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); } }
/** * 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); } } }
/** * Displays error log details page * * @param string error log identifier * @return void */ public function show_template_details($id) { onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__); $filename = ONAPP_PATH . ONAPP_DS . ONAPP_LOG_DIRECTORY . ONAPP_DS . 'error_' . $id . '.log'; // echo $filename; die(); $handle = fopen($filename, "rb"); $contents = fread($handle, filesize($filename)); fclose($handle); $params = array('contents' => $contents, 'title' => onapp_string('ERROR_LOGS_DETAILS'), 'info_title' => onapp_string('ERROR_LOGS_DETAILS'), 'info_body' => onapp_string('ERROR_LOGS_DETAILS_INFO')); onapp_show_template('errorLogs_details', $params); }
/** * Shows template view * * @return void */ public function show_template_view($error = NULL) { onapp_show_template('profile_view', array('title' => onapp_string('PROFILE_'), 'info_title' => onapp_string('PROFILE_'), 'info_body' => onapp_string('PROFILE_INFO'), 'error' => onapp_string($error))); }
/** * Removes cron job string from the cron file * * @param string $cron_jobs cron job string * @return Cron */ public function remove_cronjob($cron_jobs = NULL) { onapp_debug(__METHOD__); if (is_null($cron_jobs)) { $this->error_message("Nothing to remove! Please specify a cron job or an array of cron jobs."); } $this->write_to_file(); $cron_array = file($this->cron_file, FILE_IGNORE_NEW_LINES); //print('<pre>'); print_r($cron_array); die(); $count_before = count($cron_array); if (empty($cron_array)) { $this->remove_file()->error_message("Nothing to remove! The cronTab is already empty."); } if (is_array($cron_jobs)) { foreach ($cron_jobs as $cron_regex) { $cron_array = preg_grep($cron_regex, $cron_array, PREG_GREP_INVERT); } } else { foreach ($cron_array as $key => $cron_job) { if ($cron_job == $cron_jobs) { unset($cron_array[$key]); } } } $count_after = count($cron_array); // print('<pre>'); print_r($cron_array); die(); if ($count_after == $count_before) { $this->remove_file(); $error = onapp_string('CRON_JOB_HAS_NOT_BEEN_DELETED'); trigger_error($error); $this->show_template_view($error); exit; } $this->remove_file(); $this->remove_crontab(); if (!empty($cron_array)) { $this->append_cronjob($cron_array); } return $this; }
/** * 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); }
/** * Shows user payments page * * @global array $_ALIASES menu page aliases * @param string error message * @return void */ private function show_template_white_list($id, $error = NULL) { onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__); onapp_debug('error => ' . print_r($error, true) . ', id =>' . $id); onapp_permission(array('user_white_lists', 'user_white_lists.read.own', 'user_white_lists.read')); $params = array('user_id' => $id, 'white_list_obj' => $this->getList('User_WhiteList', array($id)), 'title' => onapp_string('WHITE_LIST_IPS_FOR_THIS_USER'), 'info_title' => onapp_string('WHITE_LIST_IPS_FOR_THIS_USER'), 'info_body' => onapp_string('WHITE_LIST_IPS_FOR_THIS_USER_INFO'), 'error' => $error); onapp_show_template('usersAndGroups_whiteList', $params); }
/** * Shows virtual machine resource allocation page * * @param integer virtual machine id * @return void */ private function show_template_edit($id) { onapp_debug(__CLASS__ . ' :: ' . __FUNCTION__); onapp_debug('id => ' . $id); onapp_permission(array('virtual_machines', 'virtual_machines.update.own', 'virtual_machines.update')); $params = array('vm_obj' => $this->load('VirtualMachine', array($id)), 'title' => onapp_string('ADJUST_RESOURCE_ALLOCATIONS'), 'info_title' => onapp_string('ADJUST_RESOURCE_ALLOCATIONS'), 'info_body' => onapp_string('ADJUST_RESOURCE_ALLOCATIONS_INFO')); onapp_show_template('vm_edit', $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); } }
/** * Shows hypervisor's params edit page * * @param integer user id * @return void */ private function show_template_edit($id) { onapp_debug(__METHOD__); onapp_debug('id =>' . $id); onapp_permission(array('hypervisors', 'hypervisors.update')); $onapp = $this->get_factory(); $hypervisor = $onapp->factory('Hypervisor', ONAPP_WRAPPER_LOG_REPORT_ENABLE); $params = array('hypervisor_id' => $id, 'hypervisor_obj' => $hypervisor->load($id), 'hypervisor_types' => array('kvm', 'xen'), 'title' => onapp_string('EDIT_HYPERVISOR'), 'info_title' => onapp_string('EDIT_HYPERVISOR'), 'info_body' => onapp_string('EDIT_HYPERVISOR_INFO')); onapp_show_template('hypervisor_edit', $params); }