feat: Add configuration form and secure credential handling
This commit is contained in:
parent
90efce488f
commit
77e4db0d78
24
ConfigForm.ps1
Normal file
24
ConfigForm.ps1
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
Add-Type -AssemblyName System.Windows.Forms
|
||||||
|
|
||||||
|
$configForm = New-Object System.Windows.Forms.Form
|
||||||
|
$configForm.Text = "SharePoint Configuration"
|
||||||
|
$configForm.Size = New-Object System.Drawing.Size(400,300)
|
||||||
|
|
||||||
|
# Add controls for all configuration fields
|
||||||
|
$lblSiteUrl = New-Object System.Windows.Forms.Label
|
||||||
|
$lblSiteUrl.Text = "Site URL:"
|
||||||
|
$lblSiteUrl.Location = New-Object System.Drawing.Point(20,20)
|
||||||
|
|
||||||
|
$txtSiteUrl = New-Object System.Windows.Forms.TextBox
|
||||||
|
$txtSiteUrl.Location = New-Object System.Drawing.Point(20,40)
|
||||||
|
$txtSiteUrl.Size = New-Object System.Drawing.Size(340,20)
|
||||||
|
|
||||||
|
$btnSave = New-Object System.Windows.Forms.Button
|
||||||
|
$btnSave.Text = "Save"
|
||||||
|
$btnSave.Add_Click({
|
||||||
|
Save-Config -SiteUrl $txtSiteUrl.Text -ProductionLibrary "Documents" -TempLibrary "Documents/Temp" -ClientId "" -ClientSecret ""
|
||||||
|
$configForm.Close()
|
||||||
|
})
|
||||||
|
|
||||||
|
$configForm.Controls.AddRange(@($lblSiteUrl, $txtSiteUrl, $btnSave))
|
||||||
|
$configForm.ShowDialog()
|
||||||
16
MainForm.ps1
16
MainForm.ps1
@ -11,6 +11,15 @@ $form.Text = "SharePoint XLS Converter"
|
|||||||
$form.Size = New-Object System.Drawing.Size(600,400)
|
$form.Size = New-Object System.Drawing.Size(600,400)
|
||||||
|
|
||||||
# Add controls
|
# Add controls
|
||||||
|
$txtSiteUrl = New-Object System.Windows.Forms.TextBox
|
||||||
|
$txtSiteUrl.Location = New-Object System.Drawing.Point(20,120)
|
||||||
|
$txtSiteUrl.Size = New-Object System.Drawing.Size(200,20)
|
||||||
|
|
||||||
|
$btnSaveConfig = New-Object System.Windows.Forms.Button
|
||||||
|
$btnSaveConfig.Location = New-Object System.Drawing.Point(230,120)
|
||||||
|
$btnSaveConfig.Size = New-Object System.Drawing.Size(80,20)
|
||||||
|
$btnSaveConfig.Text = "Save Config"
|
||||||
|
|
||||||
$btnList = New-Object System.Windows.Forms.Button
|
$btnList = New-Object System.Windows.Forms.Button
|
||||||
$btnList.Location = New-Object System.Drawing.Point(20,20)
|
$btnList.Location = New-Object System.Drawing.Point(20,20)
|
||||||
$btnList.Size = New-Object System.Drawing.Size(120,30)
|
$btnList.Size = New-Object System.Drawing.Size(120,30)
|
||||||
@ -35,6 +44,13 @@ $txtStatus.Size = New-Object System.Drawing.Size(540,280)
|
|||||||
$txtStatus.Multiline = $true
|
$txtStatus.Multiline = $true
|
||||||
$txtStatus.ScrollBars = "Vertical"
|
$txtStatus.ScrollBars = "Vertical"
|
||||||
$form.Controls.Add($txtStatus)
|
$form.Controls.Add($txtStatus)
|
||||||
|
$form.Controls.Add($txtSiteUrl)
|
||||||
|
$form.Controls.Add($btnSaveConfig)
|
||||||
|
|
||||||
|
# Load configuration
|
||||||
|
if (-not (Load-Config)) {
|
||||||
|
[System.Windows.Forms.MessageBox]::Show("Configuration missing! Please enter settings.")
|
||||||
|
}
|
||||||
|
|
||||||
# Attach event handlers
|
# Attach event handlers
|
||||||
$btnList.Add_Click({ List-XlsFiles })
|
$btnList.Add_Click({ List-XlsFiles })
|
||||||
|
|||||||
@ -1,7 +1,43 @@
|
|||||||
|
$configPath = Join-Path $PSScriptRoot "config.json"
|
||||||
|
|
||||||
|
function Load-Config {
|
||||||
|
if (Test-Path $configPath) {
|
||||||
|
try {
|
||||||
|
$script:config = Get-Content $configPath | ConvertFrom-Json
|
||||||
|
$script:txtSiteUrl.Text = $config.SiteUrl
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Error "Invalid config file: $_"
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
|
||||||
|
function Save-Config {
|
||||||
|
param(
|
||||||
|
[string]$SiteUrl,
|
||||||
|
[string]$ProductionLibrary,
|
||||||
|
[string]$TempLibrary,
|
||||||
|
[string]$ClientId,
|
||||||
|
[string]$ClientSecret
|
||||||
|
)
|
||||||
|
|
||||||
|
$config = @{
|
||||||
|
SiteUrl = $SiteUrl
|
||||||
|
ProductionLibrary = $ProductionLibrary
|
||||||
|
TempLibrary = $TempLibrary
|
||||||
|
ClientId = $ClientId
|
||||||
|
ClientSecret = $ClientSecret
|
||||||
|
}
|
||||||
|
|
||||||
|
$config | ConvertTo-Json | Set-Content $configPath
|
||||||
|
}
|
||||||
|
|
||||||
function Connect-SharePoint {
|
function Connect-SharePoint {
|
||||||
param($SiteUrl)
|
|
||||||
try {
|
try {
|
||||||
Connect-PnPOnline -Url $SiteUrl -UseWebLogin
|
Connect-PnPOnline -Url $config.SiteUrl -ClientId $config.ClientId -ClientSecret $config.ClientSecret
|
||||||
return $true
|
return $true
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
@ -11,14 +47,14 @@ function Connect-SharePoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function List-XlsFiles {
|
function List-XlsFiles {
|
||||||
if (-not (Connect-SharePoint -SiteUrl "https://yoursite.sharepoint.com")) {
|
if (-not (Connect-SharePoint)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
$tempLibrary = "Documents/Temp"
|
$tempLibrary = $config.TempLibrary
|
||||||
$fileList = @()
|
$fileList = @()
|
||||||
|
|
||||||
$items = Get-PnPListItem -List "Documents" -PageSize 2000 | Where {
|
$items = Get-PnPListItem -List $config.ProductionLibrary -PageSize 2000 | Where {
|
||||||
($_.FieldValues.FileRef -like "*.xls") -and (-not $_.FieldValues.FileRef.Contains(".xlsx"))
|
($_.FieldValues.FileRef -like "*.xls") -and (-not $_.FieldValues.FileRef.Contains(".xlsx"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
7
config.json
Normal file
7
config.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"SiteUrl": "https://yoursite.sharepoint.com/sites/yoursite",
|
||||||
|
"ProductionLibrary": "Documents",
|
||||||
|
"TempLibrary": "Documents/Temp",
|
||||||
|
"ClientId": "your-client-id",
|
||||||
|
"ClientSecret": "your-client-secret"
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user