Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions agent/modals/credential/credential_import.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
<?php } ?>
<div class="modal-body">
<p><strong>Format csv file with headings & data:</strong><br>Name, Description, Username, Password, TOTP, URI</p>
<p><strong>Format csv file with headings & data:</strong><br>Name, Description, Username, Password, TOTP, URL, URL2, Note, Important;</p>
<hr>
<div class="form-group my-4">
<input type="file" class="form-control-file" name="file" accept=".csv" required>
Expand All @@ -27,4 +27,4 @@
</form>
</div>
</div>
</div>
</div>
30 changes: 17 additions & 13 deletions agent/post/credential.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@

//get records from database
$sql = mysqli_query($mysqli,"SELECT * FROM credentials LEFT JOIN clients ON client_id = credential_client_id WHERE credential_archived_at IS NULL $client_query ORDER BY credential_name ASC");

$num_rows = mysqli_num_rows($sql);

if ($num_rows > 0) {
Expand All @@ -329,14 +330,14 @@
$f = fopen('php://memory', 'w');

//set column headers
$fields = array('Name', 'Description', 'Username', 'Password', 'TOTP', 'URI');
$fields = array('Name', 'Description', 'Username', 'Password', 'TOTP', 'URI', 'URI_2', 'Note', 'Important');
fputcsv($f, $fields, $delimiter, $enclosure, $escape);

//output each row of the data, format line as csv and write to file pointer
while($row = mysqli_fetch_assoc($sql)){
$credential_username = decryptCredentialEntry($row['credential_username']);
$credential_password = decryptCredentialEntry($row['credential_password']);
$lineData = array($row['credential_name'], $row['credential_description'], $credential_username, $credential_password, $row['credential_otp_secret'], $row['credential_uri']);
$lineData = array($row['credential_name'], $row['credential_description'], $credential_username, $credential_password, $row['credential_otp_secret'], $row['credential_uri'], $row['credential_uri_2'], $row['credential_note'], $row['credential_important']);
fputcsv($f, $lineData, $delimiter, $enclosure, $escape);
}

Expand Down Expand Up @@ -388,7 +389,7 @@
//(Else)Check column count
$f = fopen($file_name, "r");
$f_columns = fgetcsv($f, 1000, ",");
if (!$error & count($f_columns) != 6) {
if (!$error & count($f_columns) != 9) {
$error = true;
flash_alert("Bad column count.", 'error');
}
Expand All @@ -401,38 +402,41 @@
$duplicate_count = 0;
while(($column = fgetcsv($file, 1000, ",")) !== false){
$duplicate_detect = 0;
// Name
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't remove these comments, they're useful!!

if (isset($column[0])) {
$name = sanitizeInput($column[0]);
if (mysqli_num_rows(mysqli_query($mysqli,"SELECT * FROM credentials WHERE credential_name = '$name' AND credential_client_id = $client_id")) > 0){
$duplicate_detect = 1;
}
}
// Desc
if (isset($column[1])) {
$description = sanitizeInput($column[1]);
}
// User
if (isset($column[2])) {
$username = sanitizeInput(encryptCredentialEntry($column[2]));
}
// Pass
if (isset($column[3])) {
$password = sanitizeInput(encryptCredentialEntry($column[3]));
}
// OTP
if (isset($column[4])) {
$totp = sanitizeInput($column[4]);
$otp_secret = sanitizeInput($column[4]);
}
// URL
if (isset($column[4])) {
if (isset($column[5])) {
$uri = sanitizeInput($column[5]);
}
if (isset($column[6])) {
$uri_2 = sanitizeInput($column[6]);
}
if (isset($column[7])) {
$note = sanitizeInput($column[7]);
}
if (isset($column[8])) {
$important = sanitizeInput($column[8]);
}

// Check if duplicate was detected
if ($duplicate_detect == 0){
//Add
mysqli_query($mysqli,"INSERT INTO credentials SET credential_name = '$name', credential_description = '$description', credential_uri = '$uri', credential_username = '$username', credential_password = '$password', credential_otp_secret = '$totp', credential_client_id = $client_id");
mysqli_query($mysqli,"INSERT INTO credentials SET credential_name = '$name', credential_description = '$description', credential_uri = '$uri', credential_uri_2 = '$uri_2', credential_username = '$username', credential_password = '$password', credential_otp_secret = '$otp_secret', credential_note = '$note', credential_important = $important, credential_client_id = $client_id");
$row_count = $row_count + 1;
} else {
$duplicate_count = $duplicate_count + 1;
Expand Down Expand Up @@ -462,7 +466,7 @@
$f = fopen('php://memory', 'w');

//set column headers
$fields = array('Name', 'Description', 'Username', 'Password', 'TOTP', 'URI');
$fields = array('Name', 'Description', 'Username', 'Password', 'TOTP', 'URI', 'URI_2', 'Note', 'Important');
fputcsv($f, $fields, $delimiter);

//move back to beginning of file
Expand Down