'noaccess']; } include 'general/noaccess.php'; return; } // Required files. ui_require_css_file('credential_store'); require_once $config['homedir'].'/include/functions_credential_store.php'; require_once $config['homedir'].'/include/functions_io.php'; if (is_ajax()) { $draw = get_parameter('draw', 0); $filter = get_parameter('filter', []); $get_key = get_parameter('get_key', 0); $new_form = get_parameter('new_form', 0); $new_key = get_parameter('new_key', 0); $update_key = get_parameter('update_key', 0); $delete_key = get_parameter('delete_key', 0); if ($new_form) { echo print_inputs(); exit; } if ($delete_key) { $identifier = get_parameter('identifier', null); if (empty($identifier)) { ajax_msg('error', __('identifier cannot be empty')); } if (db_process_sql_delete( 'tcredential_store', ['identifier' => $identifier] ) === false ) { ajax_msg('error', $config['dbconnection']->error, true); } else { ajax_msg('result', $identifier, true); } } if ($update_key) { $data = get_parameter('values', null); if ($data === null || !is_array($data)) { echo json_encode(['error' => __('Invalid parameters, please retry')]); exit; } $values = []; foreach ($data as $key => $value) { if ($key == 'identifier') { $identifier = base64_decode($value); } else if ($key == 'product') { $product = base64_decode($value); } else { $values[$key] = base64_decode($value); } } if (empty($identifier)) { ajax_msg('error', __('identifier cannot be empty')); } if (empty($product)) { ajax_msg('error', __('product cannot be empty')); } if (db_process_sql_update( 'tcredential_store', $values, ['identifier' => $identifier] ) === false ) { ajax_msg('error', $config['dbconnection']->error); } else { ajax_msg('result', $identifier); } exit; } if ($new_key) { $data = get_parameter('values', null); if ($data === null || !is_array($data)) { echo json_encode(['error' => __('Invalid parameters, please retry')]); exit; } $values = []; foreach ($data as $key => $value) { $values[$key] = base64_decode($value); if ($key == 'identifier') { $values[$key] = preg_replace('/\s+/', '-', trim($values[$key])); } } $identifier = $values['identifier']; if (empty($identifier)) { ajax_msg('error', __('identifier cannot be empty')); } if (empty($values['product'])) { ajax_msg('error', __('product cannot be empty')); } if (db_process_sql_insert('tcredential_store', $values) === false) { ajax_msg('error', $config['dbconnection']->error); } else { ajax_msg('result', $identifier); } exit; } if ($get_key) { $identifier = get_parameter('identifier', null); $key = get_key($identifier); echo print_inputs($key); exit; } if ($draw) { // Datatables offset, limit and order. $start = get_parameter('start', 0); $length = get_parameter('length', $config['block_size']); $order = get_datatable_order(true); try { ob_start(); $fields = [ 'cs.*', 'tg.nombre as `group`', ]; // Retrieve data. $data = credentials_get_all( // Fields. $fields, // Filter. $filter, // Offset. $start, // Limit. $length, // Order. $order['direction'], // Sort field. $order['field'] ); // Retrieve counter. $count = credentials_get_all( 'count', $filter ); if ($data) { $data = array_reduce( $data, function ($carry, $item) { // Transforms array of arrays $data into an array // of objects, making a post-process of certain fields. $tmp = (object) $item; $tmp->username = io_safe_output($tmp->username); if (empty($tmp->group)) { $tmp->group = __('All'); } else { $tmp->group = io_safe_output($tmp->group); } $carry[] = $tmp; return $carry; } ); } // Datatables format: RecordsTotal && recordsfiltered. echo json_encode( [ 'data' => $data, 'recordsTotal' => $count, 'recordsFiltered' => $count, ] ); // Capture output. $response = ob_get_clean(); } catch (Exception $e) { return json_encode(['error' => $e->getMessage()]); } // If not valid, show error with issue. json_decode($response); if (json_last_error() == JSON_ERROR_NONE) { // If valid dump. echo $response; } else { echo json_encode( ['error' => $response] ); } exit; } exit; } // Datatables list. try { $columns = [ 'group', 'identifier', 'product', 'username', 'options', ]; $column_names = [ __('Group'), __('Identifier'), __('Product'), __('User'), [ 'text' => __('Options'), 'class' => 'action_buttons', ], ]; $table_id = 'keystore'; // Load datatables user interface. ui_print_datatable( [ 'id' => $table_id, 'class' => 'info_table', 'style' => 'width: 100%', 'columns' => $columns, 'column_names' => $column_names, 'ajax_url' => 'godmode/groups/credential_store', 'ajax_postprocess' => 'process_datatables_item(item)', 'no_sortable_columns' => [-1], 'order' => [ 'field' => 'identifier', 'direction' => 'asc', ], 'search_button_class' => 'sub filter float-right', 'form' => [ 'inputs' => [ [ 'label' => __('Group'), 'type' => 'select', 'id' => 'filter_id_group', 'name' => 'filter_id_group', 'options' => users_get_groups_for_select( $config['id_user'], 'AR', true, true, false ), ], [ 'label' => __('Free search'), 'type' => 'text', 'class' => 'mw250px', 'id' => 'free_search', 'name' => 'free_search', ], ], ], ] ); } catch (Exception $e) { echo $e->getMessage(); } // Auxiliar div. $new = ''; $details = ''; $aux = ''; echo $new.$details.$aux; // Create button. echo '
'; html_print_submit_button( __('Add key'), 'create', false, 'class="sub next"' ); echo '
'; ?>