Jump to content

Fabian Näf

Members
  • Posts

    205
  • Joined

  • Last visited

  • Days Won

    11

Posts posted by Fabian Näf

  1. Hi Habskilla

     

    To create the REST JSON Body I always go for the following approach: First create a PowerShell object and convert it then to a JSON-String. The big advantage of that is, that you don't have to care about any special characters, escaping and stuff like that.

    $Body = @{
         FolderName = $Name
         Description = $Description
    	 NestUnderFolderID = $ParentFolderID
    	 APIKey = $global:PasswordStateSystemWideAPIKey
    }
    $jsonBody = $Body | ConvertTo-Json
    $PasswordstateURLFull = "$($global:PasswordstateURL)/api/folders"
    $result = Invoke-Restmethod -Method POST -Uri $PasswordstateURLFull -ContentType "application/json; charset=utf-8" -Body $jsonBody

    The response I get is then stored in $result and can be accessed directly:

    $output = $result.FolderID

    If you have the answer as a string you also could use for the following approach:

    $responseObject = $responseJsonString | ConvertFrom-Json

    If you take a look the KeePassImport-Script you'll find some more examples.

     

    All the best,

     

    Fabian

  2. 22 hours ago, Folke said:

    And by the way: I've added a few functions to Fabians Import-KeePass-XML.ps1 which now supports configurable mapping of keepass' addidional fields to Passwordstate generic Fields, adding not handled fields to the description, UTF8 Ümläüte fixed, and support for files/attachments. Works very smooth now. If anyone is interested i can provide it her

     

    Ohh, I just realized, that I've overseen your "by the way"!

    Sounds very very interesting to me!! I know, that other people already asked for a funktion to upload the attachments as well.

    Could you post your updated version in this thread?

     

    Grüsse zurück nach München :-)

     

    Fabian

  3. +1

    Reason: Sometimes the extension fills other fields which are not my logon fields. E.g. I work with a ServiceNow which is running in the browser. There are loads of fields and if a field accidentaly matches the id, it get filled, which can lead to problems when I submit the form then (data get changed unintended). My current workaround: specify in the URL field in Passwordstate the path to the logon form of ServiceNow (/logon.do). The extension is then only running on the logon form.

  4. Hi Folke

     

    My final solution (workaround) in this case was to update the guide directly in the database, below some snippets from my Powershell script.

    I have to say, that this is very dangerous and can lead to a corrupt database if you're doing something wrong! So be very careful with this!!

     

    $global:PasswordstateSystemWideAPIKey = '';
    
    Import-Module SQLPS -DisableNameChecking
    
    Push-Location
    cd SQLSERVER:\SQL\localhost\DEFAULT\Databases\passwordstate
    
    Function UpdateGuideOfPasswordstatePasswordlistOrFolder() {
        Param ( 
                [Parameter(Mandatory=$True,ValueFromPipeline=$False,ValueFromPipelinebyPropertyName=$False)]
                [String]$Id,     
                [Parameter(Mandatory=$False,ValueFromPipeline=$False,ValueFromPipelinebyPropertyName=$False)]
                [String]$Guide
        ) 
        Begin { 
            $Guide = ConvertTextToHtml -text $Guide
        }  
        Process { 
            $Header = @{
    	        APIKey = $global:PasswordstateSystemWideAPIKey
            }
    
            try {
                $query = $("UPDATE PasswordLists SET Guide = '" + $Guide + "' WHERE PasswordListID = " + $ID)
                Invoke-Sqlcmd -Query $query
            } catch {
                Write-Host $_ -ForegroundColor Red
                Write-Host $_.GetType() -ForegroundColor Red
                Write-Host $_.Exception -ForegroundColor Red
                throw $_.Exception
            }          
        }
        End {
            Write-Output ($result | Where-Object { $_.TreePath -eq $Tree }).PasswordListID
        }
    
    }
    
    Function ConvertTextToHtml() {
        Param ( 
                [Parameter(Mandatory=$True,ValueFromPipeline=$False,ValueFromPipelinebyPropertyName=$False)]
                [String]$text          
        ) 
     
        Begin {  } 
     
        Process { 
            $html = $($text -replace "\n", "<br>")
        }
    
        End {
            Write-Output $html
        }
    }
    
    
    $dummyGuide = @"
    This
    Is
    A
    Test
    Guide
    Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. 
    "@
    UpdateGuideOfPasswordstatePasswordlistOrFolder -Id 123456789 -Guide $dummyGuide
    
    Pop-Location

    Best regards,

     

    Fabian

  5. Hi All

     

    Our company just went live with Passwordstate a week a go. We migrated loads of credentials and a big tree structur from our previous password manager solution to Passwordstate. After we went live, we realized, that we forgot to migrate some certain fields from the old password manager solution from the tree (which should be migrated to folder and passwordliste in Passwordstate).

    Currently Passwordstate has no REST method to modify (or delete) folders or passwordlists. So the only option which left was to inject the missing date directly into the database, which is kind of ugly, even though it went well.

     

    Therefore I'd like to raise this feature request for modify and delete REST methods for the win and anonymous REST API.

     

    Best regards,

     

    Fabian

×
×
  • Create New...