اصلاحات هنگام تست نهایی نصب
This commit is contained in:
parent
65af65c9b2
commit
5d50aef5fd
|
|
@ -1,4 +1,4 @@
|
||||||
import { ArchiveRestore, BookOpen, CircleDollarSign, FileSpreadsheet, Gauge, LayoutDashboard, Lightbulb, ListTodo, LogOut, Network, Settings2, ShieldCheck, Users } from "lucide-react";
|
import { ArchiveRestore, BookOpen, CircleDollarSign, Gauge, LayoutDashboard, Lightbulb, ListTodo, LogOut, Network, Settings2, ShieldCheck, Users } from "lucide-react";
|
||||||
import { Link, NavLink, Outlet } from "react-router";
|
import { Link, NavLink, Outlet } from "react-router";
|
||||||
import { useAuth } from "../auth/AuthContext";
|
import { useAuth } from "../auth/AuthContext";
|
||||||
import { useDeploymentProfile } from "../deployment/DeploymentProfileContext";
|
import { useDeploymentProfile } from "../deployment/DeploymentProfileContext";
|
||||||
|
|
@ -13,7 +13,6 @@ export const sections = [
|
||||||
{ id: "ecosystem", to: "/admin/ecosystem", label: "زیستبوم", icon: Network },
|
{ id: "ecosystem", to: "/admin/ecosystem", label: "زیستبوم", icon: Network },
|
||||||
{ id: "financial", to: "/admin/financial", label: "اطلاعات مالی", icon: CircleDollarSign },
|
{ id: "financial", to: "/admin/financial", label: "اطلاعات مالی", icon: CircleDollarSign },
|
||||||
{ id: "content", to: "/admin/content", label: "انتشارات و رویدادها", icon: BookOpen },
|
{ id: "content", to: "/admin/content", label: "انتشارات و رویدادها", icon: BookOpen },
|
||||||
{ id: "imports", to: "/admin/imports", label: "ورود اکسل", icon: FileSpreadsheet },
|
|
||||||
{ id: "users", to: "/admin/users", label: "کاربران و دسترسیها", icon: Users },
|
{ id: "users", to: "/admin/users", label: "کاربران و دسترسیها", icon: Users },
|
||||||
{ id: "account", to: "/admin/account", label: "امنیت حساب", icon: ShieldCheck },
|
{ id: "account", to: "/admin/account", label: "امنیت حساب", icon: ShieldCheck },
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ export interface DeploymentActivation {
|
||||||
|
|
||||||
export interface DeploymentProfile {
|
export interface DeploymentProfile {
|
||||||
activation: DeploymentActivation;
|
activation: DeploymentActivation;
|
||||||
|
isConfigured: boolean;
|
||||||
profileVersion: string;
|
profileVersion: string;
|
||||||
company: { displayName: string; shortName: string; englishName?: string };
|
company: { displayName: string; shortName: string; englishName?: string };
|
||||||
branding: { dashboardLoginLogoAssetKey:string; adminLoginLogoAssetKey:string; ecosystemCenterLogoSource:"dashboard"|"admin"; applicationTitle: string; adminTitle: string; loginTitle: string; loginSubtitle: string; loginDescription?: string; footerText?: string };
|
branding: { dashboardLoginLogoAssetKey:string; adminLoginLogoAssetKey:string; ecosystemCenterLogoSource:"dashboard"|"admin"; applicationTitle: string; adminTitle: string; loginTitle: string; loginSubtitle: string; loginDescription?: string; footerText?: string };
|
||||||
|
|
@ -51,7 +52,7 @@ export function DeploymentProfileProvider({ children }: { children: ReactNode })
|
||||||
.then(setProfile)
|
.then(setProfile)
|
||||||
.catch(reason => {
|
.catch(reason => {
|
||||||
if (reason instanceof DOMException && reason.name === "AbortError") return;
|
if (reason instanceof DOMException && reason.name === "AbortError") return;
|
||||||
console.error("Deployment profile could not be loaded.", reason);
|
console.error("Deployment profile could not be loaded.");
|
||||||
setFailed(true);
|
setFailed(true);
|
||||||
});
|
});
|
||||||
return () => controller.abort();
|
return () => controller.abort();
|
||||||
|
|
@ -89,4 +90,3 @@ export function useDeploymentProfile() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,19 @@
|
||||||
import type { ApiProblem } from "../types";
|
import type { ApiProblem } from "../types";
|
||||||
import { API_ORIGIN } from "../../lib/runtime-config";
|
import { API_ORIGIN } from "../../lib/runtime-config";
|
||||||
|
import { AUTH_CLEARED_EVENT, AUTH_INVALIDATED_EVENT, safeApiMessage } from "../../lib/api";
|
||||||
|
|
||||||
export const apiOrigin = API_ORIGIN;
|
export const apiOrigin = API_ORIGIN;
|
||||||
let csrfToken: string | null = null;
|
let csrfToken: string | null = null;
|
||||||
const getCache = new Map<string, { expires: number; value: Promise<unknown> }>();
|
const getCache = new Map<string, { expires: number; value: Promise<unknown> }>();
|
||||||
const getCacheTtlMs = 30_000;
|
const getCacheTtlMs = 30_000;
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
for (const event of [AUTH_CLEARED_EVENT, AUTH_INVALIDATED_EVENT])
|
||||||
|
window.addEventListener(event, () => { csrfToken = null; getCache.clear(); });
|
||||||
|
}
|
||||||
|
|
||||||
export class ApiError extends Error {
|
export class ApiError extends Error {
|
||||||
constructor(public status: number, public problem: ApiProblem) {
|
constructor(public status: number, public problem: ApiProblem) {
|
||||||
super(problem.title ?? "خطا در ارتباط با سرور");
|
super(safeApiMessage(status, problem.code, problem.traceId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,7 +48,10 @@ async function request<T>(path: string, init: RequestInit, method: string): Prom
|
||||||
const response = await fetch(`${apiOrigin}${path}`, { ...init, headers, credentials: "include" });
|
const response = await fetch(`${apiOrigin}${path}`, { ...init, headers, credentials: "include" });
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
csrfToken = null; getCache.clear();
|
csrfToken = null; getCache.clear();
|
||||||
if (!path.endsWith("/login")) window.location.assign("/admin/login");
|
if (!path.endsWith("/login")) {
|
||||||
|
window.dispatchEvent(new Event(AUTH_INVALIDATED_EVENT));
|
||||||
|
if (window.location.pathname !== "/admin/login") window.location.assign("/admin/login");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
let problem: ApiProblem = { title: `خطای ${response.status}` };
|
let problem: ApiProblem = { title: `خطای ${response.status}` };
|
||||||
|
|
@ -54,4 +62,3 @@ async function request<T>(path: string, init: RequestInit, method: string): Prom
|
||||||
if (response.status === 204) return undefined as T;
|
if (response.status === 204) return undefined as T;
|
||||||
return response.json() as Promise<T>;
|
return response.json() as Promise<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ export function DeploymentSettingsPage() {
|
||||||
<Field label="عنوان سری کاهش هزینه"><Input value={settings.dashboard.costSeriesLabel} onChange={e=>setDashboard("costSeriesLabel",e.target.value)}/></Field>
|
<Field label="عنوان سری کاهش هزینه"><Input value={settings.dashboard.costSeriesLabel} onChange={e=>setDashboard("costSeriesLabel",e.target.value)}/></Field>
|
||||||
<div className="unit-metric-options"><strong>اطلاعات نمایشی برای همه واحدها</strong>{unitMetricOptions.map(metric=><label className="checkbox-row" key={metric.key}><input type="checkbox" checked={visibleMetrics.includes(metric.key)} onChange={e=>toggleMetric(metric.key,e.target.checked)}/><span>{metric.label}</span></label>)}</div>
|
<div className="unit-metric-options"><strong>اطلاعات نمایشی برای همه واحدها</strong>{unitMetricOptions.map(metric=><label className="checkbox-row" key={metric.key}><input type="checkbox" checked={visibleMetrics.includes(metric.key)} onChange={e=>toggleMetric(metric.key,e.target.checked)}/><span>{metric.label}</span></label>)}</div>
|
||||||
<label className="checkbox-row"><input type="checkbox" checked={settings.dashboard.showRevenueSeries} onChange={e=>setSettings({...settings,dashboard:{...settings.dashboard,showRevenueSeries:e.target.checked}})}/><span>نمایش سری درآمد در نمودار مقایسهای</span></label>
|
<label className="checkbox-row"><input type="checkbox" checked={settings.dashboard.showRevenueSeries} onChange={e=>setSettings({...settings,dashboard:{...settings.dashboard,showRevenueSeries:e.target.checked}})}/><span>نمایش سری درآمد در نمودار مقایسهای</span></label>
|
||||||
{layout&&<div className="unit-visual-editor">{settings.dashboard.units.map((unit,index)=>{const slot=layout.slots[index];return <article key={`${unit.dataKey}-${index}`} className="unit-visual-card" style={{gridColumn:slot.column,gridRow:slot.row}} draggable onDragStart={()=>setDraggedUnit(index)} onDragEnd={()=>setDraggedUnit(null)} onDragOver={event=>event.preventDefault()} onDrop={()=>{if(draggedUnit!==null)moveUnit(draggedUnit,index);setDraggedUnit(null)}}>
|
{layout&&<div className="unit-visual-editor">{settings.dashboard.units.map((unit,index)=>{const slot=layout.slots[index];return <article key={index} className="unit-visual-card" style={{gridColumn:slot.column,gridRow:slot.row}} draggable onDragStart={()=>setDraggedUnit(index)} onDragEnd={()=>setDraggedUnit(null)} onDragOver={event=>event.preventDefault()} onDrop={()=>{if(draggedUnit!==null)moveUnit(draggedUnit,index);setDraggedUnit(null)}}>
|
||||||
<div className="unit-visual-head"><span><GripVertical size={15}/>جایگاه {index+1}</span><button type="button" onClick={()=>removeUnit(index)} disabled={settings.dashboard.units.length===1} title="حذف واحد"><Trash2 size={15}/></button></div>
|
<div className="unit-visual-head"><span><GripVertical size={15}/>جایگاه {index+1}</span><button type="button" onClick={()=>removeUnit(index)} disabled={settings.dashboard.units.length===1} title="حذف واحد"><Trash2 size={15}/></button></div>
|
||||||
<img src={`${assetUrl(unit.imageAssetKey)}?v=${assetRevision}`} alt=""/>
|
<img src={`${assetUrl(unit.imageAssetKey)}?v=${assetRevision}`} alt=""/>
|
||||||
<Field label="نام واحد / شرکت مرتبط"><Input value={unit.title} onChange={e=>setUnitName(index,e.target.value)}/></Field>
|
<Field label="نام واحد / شرکت مرتبط"><Input value={unit.title} onChange={e=>setUnitName(index,e.target.value)}/></Field>
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ export function LoginPage() {
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
if (user) return <Navigate to="/admin" replace/>;
|
if (user) return <Navigate to={profile.isConfigured ? "/admin" : "/admin/deployment-settings"} replace/>;
|
||||||
|
|
||||||
async function submit(event: FormEvent) {
|
async function submit(event: FormEvent) {
|
||||||
event.preventDefault(); setBusy(true); setError("");
|
event.preventDefault(); setBusy(true); setError("");
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import React, { createContext, useContext, useEffect, useState } from "react";
|
import React, { createContext, useContext, useEffect, useState } from "react";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import apiService, { type CurrentUser } from "~/lib/api";
|
import apiService, { AUTH_CLEARED_EVENT, AUTH_INVALIDATED_EVENT, type CurrentUser } from "~/lib/api";
|
||||||
|
|
||||||
interface User {
|
interface User {
|
||||||
id: string;
|
id: string;
|
||||||
|
|
@ -56,6 +56,16 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||||
localStorage.removeItem("auth_token");
|
localStorage.removeItem("auth_token");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const clear = () => clearAuthData();
|
||||||
|
window.addEventListener(AUTH_INVALIDATED_EVENT, clear);
|
||||||
|
window.addEventListener(AUTH_CLEARED_EVENT, clear);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener(AUTH_INVALIDATED_EVENT, clear);
|
||||||
|
window.removeEventListener(AUTH_CLEARED_EVENT, clear);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
const applySession = (current: CurrentUser) => {
|
const applySession = (current: CurrentUser) => {
|
||||||
setUser(toUser(current));
|
setUser(toUser(current));
|
||||||
setToken(marker);
|
setToken(marker);
|
||||||
|
|
@ -107,13 +117,14 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||||
const logout = async () => {
|
const logout = async () => {
|
||||||
try {
|
try {
|
||||||
await apiService.logout();
|
await apiService.logout();
|
||||||
} catch (error) {
|
} catch {
|
||||||
console.error("Logout API call failed:", error);
|
// The local session is cleared even if the network request fails.
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
sessionStorage.setItem("justLoggedOut", "1");
|
sessionStorage.setItem("justLoggedOut", "1");
|
||||||
} catch {}
|
} catch {}
|
||||||
clearAuthData();
|
clearAuthData();
|
||||||
|
window.location.assign(window.location.pathname.startsWith("/admin") ? "/admin/login" : "/login");
|
||||||
toast.success("با موفقیت خارج شدید", { id: "logout-success" });
|
toast.success("با موفقیت خارج شدید", { id: "logout-success" });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import React, { createContext, useContext, useEffect, useMemo, useState } from "react";
|
import React, { createContext, useContext, useEffect, useMemo, useState } from "react";
|
||||||
|
import { Navigate, useLocation } from "react-router";
|
||||||
import { API_BASE_URL } from "~/lib/api";
|
import { API_BASE_URL } from "~/lib/api";
|
||||||
import { resolveDeploymentAsset } from "~/lib/deployment-assets";
|
import { resolveDeploymentAsset } from "~/lib/deployment-assets";
|
||||||
|
|
||||||
|
|
@ -14,6 +15,7 @@ export interface DeploymentUnit {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DeploymentProfile {
|
export interface DeploymentProfile {
|
||||||
|
isConfigured: boolean;
|
||||||
profileVersion: string;
|
profileVersion: string;
|
||||||
company: { displayName: string; shortName: string; englishName?: string };
|
company: { displayName: string; shortName: string; englishName?: string };
|
||||||
branding: {
|
branding: {
|
||||||
|
|
@ -54,6 +56,7 @@ interface DeploymentContextValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
const safeDefault: DeploymentProfile = {
|
const safeDefault: DeploymentProfile = {
|
||||||
|
isConfigured: false,
|
||||||
profileVersion: "unavailable",
|
profileVersion: "unavailable",
|
||||||
company: { displayName: "سازمان", shortName: "سازمان" },
|
company: { displayName: "سازمان", shortName: "سازمان" },
|
||||||
branding: {
|
branding: {
|
||||||
|
|
@ -80,6 +83,7 @@ const safeDefault: DeploymentProfile = {
|
||||||
const DeploymentContext = createContext<DeploymentContextValue | null>(null);
|
const DeploymentContext = createContext<DeploymentContextValue | null>(null);
|
||||||
|
|
||||||
export function DeploymentProfileProvider({ children }: { children: React.ReactNode }) {
|
export function DeploymentProfileProvider({ children }: { children: React.ReactNode }) {
|
||||||
|
const location = useLocation();
|
||||||
const [profile, setProfile] = useState<DeploymentProfile>(safeDefault);
|
const [profile, setProfile] = useState<DeploymentProfile>(safeDefault);
|
||||||
const [state, setState] = useState<"loading" | "ready" | "error">("loading");
|
const [state, setState] = useState<"loading" | "ready" | "error">("loading");
|
||||||
|
|
||||||
|
|
@ -100,7 +104,7 @@ export function DeploymentProfileProvider({ children }: { children: React.ReactN
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
if (error instanceof DOMException && error.name === "AbortError") return;
|
if (error instanceof DOMException && error.name === "AbortError") return;
|
||||||
console.error("Deployment profile could not be loaded.", error);
|
console.error("Deployment profile could not be loaded.");
|
||||||
setState("error");
|
setState("error");
|
||||||
});
|
});
|
||||||
return () => controller.abort();
|
return () => controller.abort();
|
||||||
|
|
@ -145,6 +149,8 @@ export function DeploymentProfileProvider({ children }: { children: React.ReactN
|
||||||
<div><h1 className="text-lg font-bold mb-2">تنظیمات استقرار در دسترس نیست</h1><p>اتصال API را بررسی و صفحه را دوباره بارگذاری کنید.</p></div>
|
<div><h1 className="text-lg font-bold mb-2">تنظیمات استقرار در دسترس نیست</h1><p>اتصال API را بررسی و صفحه را دوباره بارگذاری کنید.</p></div>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
if (!profile.isConfigured && !location.pathname.startsWith("/admin"))
|
||||||
|
return <Navigate to="/admin/deployment-settings" replace/>;
|
||||||
return <DeploymentContext.Provider value={{ profile, assetUrl }}>{children}</DeploymentContext.Provider>;
|
return <DeploymentContext.Provider value={{ profile, assetUrl }}>{children}</DeploymentContext.Provider>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@ const DATE_PATTERN = /^\d{4}\/\d{2}\/\d{2}$/;
|
||||||
|
|
||||||
export function defaultCalendarDate(): CalendarDate {
|
export function defaultCalendarDate(): CalendarDate {
|
||||||
return {
|
return {
|
||||||
start: `${jy}/01/01`,
|
start: "1400/01/01",
|
||||||
end: `${jy}/12/30`,
|
end: `${jy}/01/01`,
|
||||||
sinceMonth: "بهار",
|
sinceMonth: "بهار",
|
||||||
untilMonth: "زمستان",
|
untilMonth: "بهار",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -23,6 +23,11 @@ export function readStoredDate(): CalendarDate {
|
||||||
// Accept and normalize the naming used by older builds.
|
// Accept and normalize the naming used by older builds.
|
||||||
const start = parsed?.start ?? parsed?.startDate;
|
const start = parsed?.start ?? parsed?.startDate;
|
||||||
const end = parsed?.end ?? parsed?.endDate;
|
const end = parsed?.end ?? parsed?.endDate;
|
||||||
|
// Replace the previous automatic current-year range without changing a custom selection.
|
||||||
|
if (start === `${jy}/01/01` && end === `${jy}/12/30`) {
|
||||||
|
localStorage.setItem("dateSelected", JSON.stringify(fallback));
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
typeof start === "string" &&
|
typeof start === "string" &&
|
||||||
typeof end === "string" &&
|
typeof end === "string" &&
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,24 @@ export interface ApiProblem {
|
||||||
status?: number;
|
status?: number;
|
||||||
errors?: Record<string, string[]>;
|
errors?: Record<string, string[]>;
|
||||||
code?: string;
|
code?: string;
|
||||||
|
traceId?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AUTH_INVALIDATED_EVENT = "inogen:auth-invalidated";
|
||||||
|
export const AUTH_CLEARED_EVENT = "inogen:auth-cleared";
|
||||||
|
|
||||||
|
export function safeApiMessage(status: number, code?: string, traceId?: string): string {
|
||||||
|
const known: Record<string, string> = {
|
||||||
|
invalid_csrf: "نشست امنیتی معتبر نیست. صفحه را تازهسازی کنید.",
|
||||||
|
concurrency_conflict: "داده تغییر کرده است. دوباره تلاش کنید.",
|
||||||
|
not_found: "مورد درخواستی پیدا نشد.",
|
||||||
|
};
|
||||||
|
const message = known[code ?? ""] ?? ({ 400: "درخواست معتبر نیست.", 401: "نشست شما پایان یافته است.",
|
||||||
|
403: "دسترسی به این عملیات مجاز نیست.", 409: "داده تغییر کرده است.", 422: "دادههای واردشده معتبر نیست.",
|
||||||
|
423: "سامانه در حال حاضر آماده نیست.", 500: "خطای پیشبینینشدهای رخ داد." } as Record<number, string>)[status]
|
||||||
|
?? "درخواست انجام نشد.";
|
||||||
|
return status >= 500 && traceId && /^[\w.-]{1,120}$/.test(traceId)
|
||||||
|
? `${message} کد پیگیری: ${traceId}` : message;
|
||||||
}
|
}
|
||||||
|
|
||||||
type RequestOptions = RequestInit & {
|
type RequestOptions = RequestInit & {
|
||||||
|
|
@ -41,11 +59,14 @@ class ApiService {
|
||||||
private csrfToken: string | null = null;
|
private csrfToken: string | null = null;
|
||||||
|
|
||||||
private handleSessionExpired(message?: string) {
|
private handleSessionExpired(message?: string) {
|
||||||
|
this.csrfToken = null;
|
||||||
|
window.dispatchEvent(new Event(AUTH_INVALIDATED_EVENT));
|
||||||
try {
|
try {
|
||||||
sessionStorage.setItem("sessionExpired", "1");
|
sessionStorage.setItem("sessionExpired", "1");
|
||||||
} catch {}
|
} catch {}
|
||||||
if (message) toast.error(message);
|
if (message) toast.error(message);
|
||||||
if (window.location.pathname !== "/login") window.location.assign("/login");
|
if (window.location.pathname !== "/login" && window.location.pathname !== "/admin/login")
|
||||||
|
window.location.assign(window.location.pathname.startsWith("/admin") ? "/admin/login" : "/login");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async ensureCsrfToken(): Promise<string> {
|
private async ensureCsrfToken(): Promise<string> {
|
||||||
|
|
@ -64,12 +85,9 @@ class ApiService {
|
||||||
private async readError(response: Response): Promise<string> {
|
private async readError(response: Response): Promise<string> {
|
||||||
try {
|
try {
|
||||||
const problem = (await response.json()) as ApiProblem;
|
const problem = (await response.json()) as ApiProblem;
|
||||||
const validation = problem.errors
|
return safeApiMessage(response.status, problem.code, problem.traceId);
|
||||||
? Object.values(problem.errors).flat().filter(Boolean).join(" ")
|
|
||||||
: "";
|
|
||||||
return validation || problem.detail || problem.title || `خطای HTTP ${response.status}`;
|
|
||||||
} catch {
|
} catch {
|
||||||
return `خطای HTTP ${response.status}`;
|
return safeApiMessage(response.status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,8 +113,10 @@ class ApiService {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.status === 401 && options.redirectOnUnauthorized !== false) {
|
if (response.status === 401 && endpoint !== "/auth/login") {
|
||||||
this.handleSessionExpired("نشست شما منقضی شده است. لطفاً دوباره وارد شوید.");
|
if (options.redirectOnUnauthorized !== false)
|
||||||
|
this.handleSessionExpired("نشست شما منقضی شده است. لطفاً دوباره وارد شوید.");
|
||||||
|
else window.dispatchEvent(new Event(AUTH_INVALIDATED_EVENT));
|
||||||
}
|
}
|
||||||
if (!response.ok) throw new Error(await this.readError(response));
|
if (!response.ok) throw new Error(await this.readError(response));
|
||||||
if (response.status === 204) return undefined as T;
|
if (response.status === 204) return undefined as T;
|
||||||
|
|
@ -132,8 +152,8 @@ class ApiService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async logout(): Promise<void> {
|
async logout(): Promise<void> {
|
||||||
await this.post<void>("/auth/logout");
|
try { await this.post<void>("/auth/logout", undefined, { redirectOnUnauthorized: false }); }
|
||||||
this.csrfToken = null;
|
finally { this.csrfToken = null; window.dispatchEvent(new Event(AUTH_CLEARED_EVENT)); }
|
||||||
}
|
}
|
||||||
|
|
||||||
currentUser(): Promise<CurrentUser> {
|
currentUser(): Promise<CurrentUser> {
|
||||||
|
|
|
||||||
|
|
@ -15,5 +15,8 @@ const configuredApiUrl = import.meta.env.DEV
|
||||||
// The runtime value is loaded before the application bundle, so a deployment can
|
// The runtime value is loaded before the application bundle, so a deployment can
|
||||||
// change the API endpoint without rebuilding the frontend. During development,
|
// change the API endpoint without rebuilding the frontend. During development,
|
||||||
// VITE_API_URL remains authoritative so the API can run on its own local port.
|
// VITE_API_URL remains authoritative so the API can run on its own local port.
|
||||||
export const API_BASE_URL = (configuredApiUrl || "/api/v1").replace(/\/$/, "");
|
const configuredBase = (configuredApiUrl || "/api/v1").replace(/\/$/, "");
|
||||||
|
export const API_BASE_URL = /\/api\/v1$/i.test(configuredBase)
|
||||||
|
? configuredBase
|
||||||
|
: `${configuredBase}/api/v1`;
|
||||||
export const API_ORIGIN = API_BASE_URL.replace(/\/api\/v1\/?$/, "").replace(/\/$/, "");
|
export const API_ORIGIN = API_BASE_URL.replace(/\/api\/v1\/?$/, "").replace(/\/$/, "");
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { lazy, Suspense, type ComponentType } from "react";
|
import { lazy, Suspense, type ComponentType } from "react";
|
||||||
import { Navigate, Route, Routes } from "react-router";
|
import { Navigate, Outlet, Route, Routes } from "react-router";
|
||||||
import type { Route as RouteTypes } from "./+types/admin";
|
import type { Route as RouteTypes } from "./+types/admin";
|
||||||
import { AuthProvider, useAuth } from "~/admin/auth/AuthContext";
|
import { AuthProvider, useAuth } from "~/admin/auth/AuthContext";
|
||||||
import { AppShell } from "~/admin/components/AppShell";
|
import { AppShell } from "~/admin/components/AppShell";
|
||||||
|
|
@ -48,9 +48,24 @@ function ProtectedAdminLayout() {
|
||||||
return user.roles.includes("Admin") ? <AppShell/> : <div className="access-denied"><h2>دسترسی به پنل راهبر مجاز نیست</h2><p>این حساب فقط برای مشاهده گزارشها تعریف شده است.</p></div>;
|
return user.roles.includes("Admin") ? <AppShell/> : <div className="access-denied"><h2>دسترسی به پنل راهبر مجاز نیست</h2><p>این حساب فقط برای مشاهده گزارشها تعریف شده است.</p></div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function InitialSetupLayout() {
|
||||||
|
const { user, loading } = useAuth();
|
||||||
|
if (loading) return <div className="screen-loader">در حال آمادهسازی پنل…</div>;
|
||||||
|
if (!user) return <Navigate to="/admin/login" replace/>;
|
||||||
|
if (!user.roles.includes("Admin")) return <div className="access-denied">دسترسی مجاز نیست.</div>;
|
||||||
|
return <main className="main-area"><div className="page-container"><Outlet/></div></main>;
|
||||||
|
}
|
||||||
|
|
||||||
function AdminRoutes() {
|
function AdminRoutes() {
|
||||||
const { profile } = useDeploymentProfile();
|
const { profile } = useDeploymentProfile();
|
||||||
if (!profile.activation.isActivated) return <ActivationPage/>;
|
if (!profile.activation.isActivated) return <ActivationPage/>;
|
||||||
|
if (!profile.isConfigured) return <Suspense fallback={<div className="screen-loader">در حال دریافت تنظیمات…</div>}><Routes>
|
||||||
|
<Route path="login" element={<LoginPage/>}/>
|
||||||
|
<Route element={<InitialSetupLayout/>}>
|
||||||
|
<Route path="deployment-settings" element={<DeploymentSettingsPage/>}/>
|
||||||
|
</Route>
|
||||||
|
<Route path="*" element={<Navigate to="/admin/deployment-settings" replace/>}/>
|
||||||
|
</Routes></Suspense>;
|
||||||
return <Suspense fallback={<div className="screen-loader">در حال دریافت بخش موردنظر…</div>}><Routes>
|
return <Suspense fallback={<div className="screen-loader">در حال دریافت بخش موردنظر…</div>}><Routes>
|
||||||
<Route path="login" element={<LoginPage/>}/>
|
<Route path="login" element={<LoginPage/>}/>
|
||||||
<Route element={<ProtectedAdminLayout/>}>
|
<Route element={<ProtectedAdminLayout/>}>
|
||||||
|
|
|
||||||
58
deployment/INSTALL-INTERNAL.md
Normal file
58
deployment/INSTALL-INTERNAL.md
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
# راهنمای نصب دستی و انتقال داده برای تست داخلی Inogen
|
||||||
|
|
||||||
|
این راهنما مخصوص بستهٔ داخلی است. بستهٔ مشتری ابزار انتقال داده ندارد. برای هر شرکت، یک دیتابیس مقصد جداگانه انتخاب کنید؛ ساختار دیتابیسهای قدیمی یکسان است، اما نام دیتابیس منبع را برای هر انتقال دقیق وارد کنید.
|
||||||
|
|
||||||
|
## ۱. بستهٔ داخلی را بسازید و نصب پایه را انجام دهید
|
||||||
|
|
||||||
|
1. در محیط ساخت، کلید امضای موجود را به نشست PowerShell معرفی کنید و بستهٔ داخلی را بسازید. کلید خصوصی را به سرور تست منتقل نکنید:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
cd 'D:\Work\Inogen\inogen'; $env:INOGEN_RELEASE_SIGNING_KEY = 'D:\Work\Inogen-release-signing-private.pem'; .\deployment\build-package.ps1 -SkipNpmInstall -IncludeInternalTransfer
|
||||||
|
```
|
||||||
|
|
||||||
|
گزینهٔ `-SkipNpmInstall` را فقط وقتی بگذارید که وابستگیهای فرانت از قبل نصب شدهاند.
|
||||||
|
|
||||||
|
2. بستهٔ ZIP داخلی را روی سرور استخراج کنید و گامهای ۱ تا ۴ راهنمای `INSTALL.pdf` را برای دیتابیس مقصد جدید انجام دهید. برای نمونه، مقصد را `SQL-SERVER-01/Inogen_CompanyA` بگذارید. ساختار مقصد را با `migrate-target.ps1` ایجاد کنید؛ دادهٔ قدیمی هنوز منتقل نشده است.
|
||||||
|
3. اگر گواهی SQL در محیط تست مورد اعتماد نیست، ابتدا گواهی را درست نصب کنید. برای عبور موقت در تست، به فرمان `migrate-target.ps1` گزینهٔ `-TrustServerCertificate` را اضافه کنید و در رشتههای اتصال منبع و مقصد نیز مقدار `TrustServerCertificate=True` بگذارید. این استثنا را به محیط مشتری منتقل نکنید.
|
||||||
|
|
||||||
|
## ۲. منبع و مقصد انتقال را مشخص کنید
|
||||||
|
|
||||||
|
1. از دیتابیس قدیمی و مقصد نسخهٔ پشتیبان بگیرید. نام دقیق سرور و دیتابیس قدیمی را از SQL Server بخوانید؛ برای نمونه `OLD-SQL-01/Legacy_CompanyA`. نام منبع نباید با مقصد یکسان باشد.
|
||||||
|
2. روی دیتابیس قدیمی یک حساب فقطخواندنی بسازید. حساب مقصد نیز باید مجوز نوشتن در schema `inogen` داشته باشد. از ریشهٔ بسته، فرمان زیر را اجرا کنید؛ اسکریپت نام مقصد را از `backend\appsettings.Production.json` میخواند و هر دو رمز را جداگانه میپرسد:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
.\prepare-transfer-connections.ps1 -SourceServer 'OLD-SQL-01' -SourceDatabase 'Legacy_CompanyA' -SourceUser 'legacy_reader' -TargetUser 'inogen_runtime'
|
||||||
|
```
|
||||||
|
|
||||||
|
3. اگر گواهی SQL منبع یا مقصد فقط در محیط تست مورد اعتماد نیست، به فرمان بالا بهترتیب `-TrustSourceCertificate` یا `-TrustTargetCertificate` اضافه کنید. همین پنجرهٔ PowerShell را تا پایان انتقال باز نگه دارید.
|
||||||
|
|
||||||
|
## ۳. انتقال را بررسی و اجرا کنید
|
||||||
|
|
||||||
|
1. از ریشهٔ بستهٔ داخلی، ابتدا فرمان بررسی منبع و سپس فرمان پیشنمایش را **جداگانه** اجرا کنید. نام منبع در هر دو باید یکسان باشد:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
.\select-internal-transfer.ps1 -Command verify-source -SourceServer 'OLD-SQL-01' -SourceDatabase 'Legacy_CompanyA'
|
||||||
|
```
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
.\select-internal-transfer.ps1 -Command preview-source -SourceServer 'OLD-SQL-01' -SourceDatabase 'Legacy_CompanyA'
|
||||||
|
```
|
||||||
|
|
||||||
|
2. شمار رکوردها و شناسهٔ snapshot پیشنمایش را با دیتابیس همان شرکت تطبیق دهید. سپس یک شناسهٔ یکتا برای این نوبت انتقال انتخاب کنید و فرمان زیر را اجرا کنید. ابزار برای تأیید، نام دیتابیس قدیمی را دوباره میپرسد:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
.\select-internal-transfer.ps1 -Command import-source -SourceServer 'OLD-SQL-01' -SourceDatabase 'Legacy_CompanyA' -IdempotencyKey 'company-a-20261103-01'
|
||||||
|
```
|
||||||
|
|
||||||
|
3. شمار رکوردهای منتقلشده و موارد quarantine را بررسی کنید. اگر شرکت دیگری را منتقل میکنید، دیتابیس مقصد، تنظیمات و هر دو رشتهٔ اتصال را برای آن شرکت تغییر دهید و از ابتدا بررسی کنید. دادهٔ دو شرکت را در یک مقصد وارد نکنید.
|
||||||
|
|
||||||
|
## ۴. نصب را تکمیل کنید
|
||||||
|
|
||||||
|
1. گامهای فعالسازی و ساخت مدیر در `INSTALL.pdf` را برای همین مقصد انجام دهید. اگر رمز یا نشست PowerShell تغییر کرده است، اتصال migration را دوباره مطابق راهنمای پایه تنظیم کنید.
|
||||||
|
2. پس از آزمون، متغیرهای موقت انتقال را پاک کنید:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Remove-Item Env:INOGEN_SOURCE_READONLY_CONNECTION,Env:ConnectionStrings__TargetDatabase -ErrorAction SilentlyContinue
|
||||||
|
```
|
||||||
|
|
||||||
|
انتقال تصویرهای قدیمی، اگر لازم باشد، مرحلهای جداگانه در ابزار `Inogen.DataTransfer` است؛ ابتدا انتقال رکوردها را کامل و سپس طبق runbook انتقال تصویر اجرا کنید.
|
||||||
77
deployment/INSTALL-INTERNAL.pdf
Normal file
77
deployment/INSTALL-INTERNAL.pdf
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
راهنمای نصب دستی و انتقال داده برای تست داخلی
|
||||||
|
Inogen
|
||||||
|
|
||||||
|
این راهنما مخصوص بستٔه داخلی است .بستٔه مشتری ابزار انتقال داده ندارد .برای هر شرکت ،یک دیتابیس مقصد
|
||||||
|
جداگانه انتخاب کنید؛ ساختار دیتابی سهای قدیمی یکسان است ،اما نام دیتابیس منبع را برای هر انتقال دقیق وارد
|
||||||
|
|
||||||
|
کنید.
|
||||||
|
|
||||||
|
.۱بستٔه داخلی را بسازید و نصب پایه را انجام دهید
|
||||||
|
|
||||||
|
.1در محیط ساخت ،کلید امضای موجود را به نشست PowerShellمعرفی کنید و بستٔه داخلی را بسازید .کلید
|
||||||
|
خصوصی را به سرور تست منتقل نکنید:
|
||||||
|
|
||||||
|
cd 'D:\Work\Inogen\inogen'; $env:INOGEN_RELEASE_SIGNING_KEY = 'D:\Work\Inogen-release-signing-
|
||||||
|
private.pem'; .\deployment\build-package.ps1 -SkipNpmInstall -IncludeInternalTransfer
|
||||||
|
|
||||||
|
گزینٔه -SkipNpmInstallرا فقط وقتی بگذارید که وابستگ یهای فرانت از قبل نصب شدهاند.
|
||||||
|
|
||||||
|
.1بستٔه ZIPداخلی را روی سرور استخراج کنید و گامهای ۱تا ۴راهنمای INSTALL.pdfرا برای دیتابیس مقصد
|
||||||
|
جدید انجام دهید .برای نمونه ،مقصد را SQL-SERVER-01/Inogen_CompanyAبگذارید .ساختار مقصد را با
|
||||||
|
migrate-target.ps1ایجاد کنید؛ دادٔه قدیمی هنوز منتقل نشده است.
|
||||||
|
|
||||||
|
.2اگر گواهی SQLدر محیط تست مورد اعتماد نیست ،ابتدا گواهی را درست نصب کنید .برای عبور موقت در
|
||||||
|
تست ،به فرمان migrate-target.ps1گزینٔه -TrustServerCertificateرا اضافه کنید و در رشت ههای اتصال
|
||||||
|
منبع و مقصد نیز مقدار TrustServerCertificate=Trueبگذارید .این استثنا را به محیط مشتری منتقل نکنید.
|
||||||
|
|
||||||
|
.۲منبع و مقصد انتقال را مشخص کنید
|
||||||
|
|
||||||
|
.1از دیتابیس قدیمی و مقصد نسخٔه پشتیبان بگیرید .نام دقیق سرور و دیتابیس قدیمی را از SQL Server
|
||||||
|
بخوانید؛ برای نمونه .OLD-SQL-01/Legacy_CompanyAنام منبع نباید با مقصد یکسان باشد.
|
||||||
|
|
||||||
|
.2روی دیتابیس قدیمی یک حساب فقطخواندنی بسازید .حساب مقصد نیز باید مجوز نوشتن در schema
|
||||||
|
inogenداشته باشد .از ریشٔه بسته ،فرمان زیر را اجرا کنید؛ اسکریپت نام مقصد را از
|
||||||
|
backend\appsettings.Production.jsonمیخواند و هر دو رمز را جداگانه م یپرسد:
|
||||||
|
|
||||||
|
.\prepare-transfer-connections.ps1 -SourceServer 'OLD-SQL-01' -SourceDatabase 'Legacy_CompanyA' -
|
||||||
|
'SourceUser 'legacy_reader' -TargetUser 'inogen_runtime
|
||||||
|
|
||||||
|
.1اگر گواهی SQLمنبع یا مقصد فقط در محیط تست مورد اعتماد نیست ،به فرمان بالا ب هترتیب -
|
||||||
|
TrustSourceCertificateیا -TrustTargetCertificateاضافه کنید .همین پنجرٔه PowerShellرا تا پایان
|
||||||
|
|
||||||
|
انتقال باز نگه دارید.
|
||||||
|
.۳انتقال را بررسی و اجرا کنید
|
||||||
|
|
||||||
|
.1از ریشٔه بستٔه داخلی ،ابتدا فرمان بررسی منبع و سپس فرمان پی شنمایش را جداگانه اجرا کنید .نام منبع
|
||||||
|
در هر دو باید یکسان باشد:
|
||||||
|
|
||||||
|
.\select-internal-transfer.ps1 -Command verify-source -SourceServer 'OLD-SQL-01' -SourceDatabase
|
||||||
|
''Legacy_CompanyA
|
||||||
|
|
||||||
|
.\select-internal-transfer.ps1 -Command preview-source -SourceServer 'OLD-SQL-01' -SourceDatabase
|
||||||
|
''Legacy_CompanyA
|
||||||
|
|
||||||
|
.1شمار رکوردها و شناسٔه snapshotپی شنمایش را با دیتابیس همان شرکت تطبیق دهید .سپس یک شناسٔه
|
||||||
|
یکتا برای این نوبت انتقال انتخاب کنید و فرمان زیر را اجرا کنید .ابزار برای تأیید ،نام دیتابیس قدیمی را دوباره
|
||||||
|
م یپرسد:
|
||||||
|
|
||||||
|
.\select-internal-transfer.ps1 -Command import-source -SourceServer 'OLD-SQL-01' -SourceDatabase
|
||||||
|
''Legacy_CompanyA' -IdempotencyKey 'company-a-20261103-01
|
||||||
|
|
||||||
|
.1شمار رکوردهای منتق لشده و موارد quarantineرا بررسی کنید .اگر شرکت دیگری را منتقل میکنید،
|
||||||
|
دیتابیس مقصد ،تنظیمات و هر دو رشتٔه اتصال را برای آن شرکت تغییر دهید و از ابتدا بررسی کنید .دادٔه دو
|
||||||
|
|
||||||
|
شرکت را در یک مقصد وارد نکنید.
|
||||||
|
|
||||||
|
.۴نصب را تکمیل کنید
|
||||||
|
|
||||||
|
.1گامهای فعا لسازی و ساخت مدیر در INSTALL.pdfرا برای همین مقصد انجام دهید .اگر رمز یا نشست
|
||||||
|
PowerShellتغییر کرده است ،اتصال migrationرا دوباره مطابق راهنمای پایه تنظیم کنید.
|
||||||
|
.2پس از آزمون ،متغیرهای موقت انتقال را پاک کنید:
|
||||||
|
|
||||||
|
Remove-Item Env:INOGEN_SOURCE_READONLY_CONNECTION,Env:ConnectionStrings__TargetDatabase -ErrorAction
|
||||||
|
SilentlyContinue
|
||||||
|
|
||||||
|
انتقال تصویرهای قدیمی ،اگر لازم باشد ،مرحل های جداگانه در ابزار Inogen.DataTransferاست؛ ابتدا انتقال رکوردها
|
||||||
|
را کامل و سپس طبق runbookانتقال تصویر اجرا کنید.
|
||||||
|
|
||||||
|
|
@ -1,89 +1,101 @@
|
||||||
# راهاندازی نهایی سامانه Inogen روی Windows Server
|
# راهنمای نصب دستی Inogen برای مشتری
|
||||||
|
|
||||||
این بسته شامل سه پوشه `frontend`، `backend` و `tools` است. اطلاعات آزمایشی یا اطلاعات سامانه قبلی در این فرایند منتقل نمیشود. دیتابیس تازه در اولین اجرای موفق بکاند بهصورت خودکار ایجاد و به آخرین نسخه ارتقا داده میشود.
|
در نمونههای زیر، سرور SQL برابر `SQL-SERVER-01`، دیتابیس جدید برابر `Inogen_CompanyA`، دامنهٔ فرانت برابر `app.example.com` و دامنهٔ API برابر `api.example.com` است. این مقدارها را با مقدار واقعی خود جایگزین کنید. فرمانها را از ریشهٔ بستهٔ استخراجشده اجرا کنید.
|
||||||
|
|
||||||
## ۱. پیشنیازهای سرور
|
## ۱. سرور و فایلها را آماده کنید
|
||||||
|
|
||||||
روی Windows Server موارد زیر نصب شوند:
|
1. روی Windows Server، IIS با قابلیتهای Static Content و Default Document، افزونه URL Rewrite و .NET Hosting Bundle سازگار با API را نصب کنید.
|
||||||
|
2. برای دامنههای فرانت و API رکورد DNS تنظیم کنید. گواهی HTTPS معتبر هر دامنه را روی سرور IIS نصب کنید؛ گواهی CDN بهتنهایی گواهی IIS نیست.
|
||||||
|
3. ZIP را در پوشهای مانند `C:\Inogen` استخراج کنید. پوشههای `frontend` و `backend` را کنار هم نگه دارید؛ فرمانهای نصب را از ریشهٔ بسته اجرا کنید.
|
||||||
|
|
||||||
- SQL Server در دسترس بکاند، یا دسترسی شبکهای به یک SQL Server موجود؛
|
## ۲. دیتابیس و حسابها را آماده کنید
|
||||||
- IIS با قابلیتهای Static Content، Default Document، HTTP Errors، Request Filtering، Static Content Compression و IIS Management Console؛
|
|
||||||
- بسته .NET 9 Hosting Bundle؛ پس از نصب آن، IIS را با `iisreset` بازنشانی کنید؛
|
|
||||||
- افزونه Microsoft IIS URL Rewrite Module 2. قانون لازم از قبل در `frontend\web.config` قرار دارد و تنظیم دستی Rewrite لازم نیست؛
|
|
||||||
- گواهی TLS معتبر برای حالت پیشنهادی HTTPS.
|
|
||||||
|
|
||||||
حساب اجرای Application Pool بکاند باید دسترسی Modify به پوشه `backend\data` داشته باشد. حساب SQL استفادهشده در اولین اجرا باید مجوز ایجاد دیتابیس داشته باشد؛ پس از ایجاد دیتابیس میتوان سطح دسترسی آن را به مجوزهای لازم روی همان دیتابیس محدود کرد.
|
1. در SQL Server یک دیتابیس خالی با نام واقعی استقرار، مانند `Inogen_CompanyA`، ایجاد کنید.
|
||||||
|
2. در SSMS به همان نمونهٔ SQL Server که دیتابیس را در آن ساختهاید، با حساب مدیر وصل شوید. از بخش `Security > Logins` حساب SQL به نام `inogen_migrator` را بسازید یا وجود آن را بررسی کنید. در یک پنجرهٔ Query همان اتصال، نام دیتابیس را در فرمان زیر جایگزین و آن را اجرا کنید تا کاربر دیتابیس ساخته شود و مجوز اجرای migration بگیرد:
|
||||||
|
|
||||||
## ۲. کپی بسته
|
```sql
|
||||||
|
USE [Inogen_CompanyA]; IF USER_ID(N'inogen_migrator') IS NULL CREATE USER [inogen_migrator] FOR LOGIN [inogen_migrator]; IF IS_ROLEMEMBER(N'db_owner', N'inogen_migrator') <> 1 ALTER ROLE [db_owner] ADD MEMBER [inogen_migrator];
|
||||||
|
```
|
||||||
|
|
||||||
محتوای بسته را برای نمونه در مسیر `C:\Sites\Inogen` استخراج کنید. پوشههای داده و فایلهای آپلودی در `C:\Sites\Inogen\backend\data` نگهداری میشوند؛ از این پوشه پشتیبانگیری منظم انجام دهید.
|
حساب جداگانهٔ `inogen_runtime` را برای API بسازید؛ پس از اجرای migration به آن مجوزهای `SELECT`، `INSERT`، `UPDATE` و `DELETE` روی schema `inogen` بدهید. به حساب runtime مجوز تغییر ساختار ندهید.
|
||||||
|
3. پیش از اجرای migration، یک اتصال جدید در SSMS با SQL Authentication و حساب `inogen_migrator` به همان نمونهٔ SQL باز کنید. فرمان زیر را با نام دیتابیس واقعی اجرا کنید. مقدارهای `IsDbOwner` و `CanCreateTable` باید هر دو `1` باشند. اگر اتصال برقرار نشد یا یکی از مقدارها `1` نبود، نگاشت کاربر، نقش و نام نمونهٔ SQL را با مدیر سرور اصلاح کنید و سپس این بررسی را تکرار کنید:
|
||||||
|
|
||||||
## ۳. تنظیم اتصال دیتابیس و نشانی فرانتاند
|
```sql
|
||||||
|
USE [Inogen_CompanyA]; SELECT @@SERVERNAME AS SqlServer, DB_NAME() AS DatabaseName, ORIGINAL_LOGIN() AS LoginName, USER_NAME() AS DatabaseUser, IS_MEMBER(N'db_owner') AS IsDbOwner, HAS_PERMS_BY_NAME(DB_NAME(), N'DATABASE', N'CREATE TABLE') AS CanCreateTable;
|
||||||
|
```
|
||||||
|
4. گواهی TLS سرور SQL را روی سرور برنامه مورد اعتماد قرار دهید. رشتههای اتصال را با `Encrypt=True;TrustServerCertificate=False` تنظیم کنید.
|
||||||
|
|
||||||
فایل `backend\appsettings.Production.json` را ویرایش کنید:
|
## ۳. تنظیمات را ثبت و migration را اجرا کنید
|
||||||
|
|
||||||
- مقدار `ConnectionStrings.TargetDatabase` اتصال SQL Server مقصد است؛
|
1. در `backend\appsettings.Production.json`، مقدارهای نمونهٔ `AllowedServers`، `AllowedDatabases` و `FrontendOrigins` را با سرور SQL، دیتابیس مقصد و نشانی فرانت واقعی جایگزین کنید. مقدار `ApplyMigrationsOnStartup` را `false` نگه دارید. مقدار `TargetDatabase` فقط نمونه است؛ رمز `CHANGE_ME` را در فایل به رمز واقعی تبدیل نکنید. رشتهٔ اتصال واقعی را در گام IIS، برای App Pool API ثبت کنید.
|
||||||
- مقدار دقیق نام/نشانی سرور در `TargetDatabaseGuard.AllowedServers` و نام دیتابیس در `TargetDatabaseGuard.AllowedDatabases` نیز تکرار شود؛
|
|
||||||
- نشانی فرانتاند در `FrontendOrigins` نوشته شود، مانند `https://inogen.company.local` یا `http://192.168.1.20`؛
|
|
||||||
- رمز نمونه `CHANGE_ME` حتماً عوض شود. بهتر است رمز اتصال با متغیر محیطی IIS به نام `ConnectionStrings__TargetDatabase` تأمین شود و در فایل باقی نماند.
|
|
||||||
|
|
||||||
در شروع نخست، migrationهای EF اجرا و دیتابیس مشخصشده ایجاد میشود. این رفتار با `DatabaseInitialization.ApplyMigrationsOnStartup=true` فعال است.
|
2. در `frontend\config\runtime-config.js` نشانی API را ثبت کنید:
|
||||||
|
|
||||||
## ۴. ساخت سایت بکاند در IIS
|
|
||||||
|
|
||||||
یک Application Pool بدون Managed Runtime بسازید و یک IIS Site با Physical Path برابر پوشه `backend` ایجاد کنید. برای آن یک Binding مستقل تعریف کنید؛ برای نمونه:
|
|
||||||
|
|
||||||
- HTTPS: `https://inogen-api.company.local`
|
|
||||||
- شبکه داخلی با IP و پورت مستقل: `http://192.168.1.20:5082`
|
|
||||||
|
|
||||||
حالت HTTPS توصیه میشود. فقط اگر شبکه داخلی واقعاً بدون TLS راهاندازی میشود، در `appsettings.Production.json` مقدار `Security.AllowInsecureHttp` را `true` کنید. در این حالت نشانی `FrontendOrigins` و آدرس API نیز باید با `http` یکسان باشند.
|
|
||||||
|
|
||||||
پس از راهاندازی، پاسخ `backend-address/health` باید وضعیت `ok` برگرداند. اجرای اول ممکن است به دلیل ایجاد دیتابیس کمی بیشتر طول بکشد.
|
|
||||||
|
|
||||||
## ۵. اتصال فرانتاند به بکاند و ساخت سایت فرانتاند
|
|
||||||
|
|
||||||
فایل `frontend\config\runtime-config.js` را بدون نیاز به Build مجدد ویرایش کنید. نمونه دامنهای:
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
window.INOGEN_CONFIG = { apiBaseUrl: "https://inogen-api.company.local/api/v1" };
|
window.INOGEN_CONFIG = { apiBaseUrl: "https://api.example.com/api/v1" };
|
||||||
```
|
```
|
||||||
|
|
||||||
نمونه شبکه داخلی مبتنی بر IP:
|
فایل را در پوشهٔ `frontend` **نسخهٔ نصبشده روی سرور** نیز بررسی کنید؛ مقدار `/api/v1` فقط زمانی درست است که API و فرانت روی یک دامنه و از همان مسیر منتشر شده باشند. برای دو دامنهٔ جدا، نشانی کامل HTTPS دامنهٔ API را مانند نمونهٔ بالا بگذارید. در `backend\appsettings.Production.json` نیز نشانی واقعی دامنهٔ فرانت را در `FrontendOrigins` ثبت کنید.
|
||||||
|
|
||||||
```javascript
|
3. در PowerShell، پس از اصلاح `AllowedServers` و `AllowedDatabases` در فایل تنظیمات، فرمان زیر را از ریشهٔ بسته اجرا کنید. نام حساب SQL را جایگزین کنید؛ اسکریپت نام سرور و دیتابیس را از همان فایل میخواند و رمز را جداگانه درخواست میکند:
|
||||||
window.INOGEN_CONFIG = { apiBaseUrl: "http://192.168.1.20:5082/api/v1" };
|
|
||||||
```
|
|
||||||
|
|
||||||
سپس یک IIS Site با Physical Path برابر پوشه `frontend` و Binding موردنظر، مانند `https://inogen.company.local` یا `http://192.168.1.20` بسازید. فایل `web.config` همراه بسته، مسیرهای React مانند `/admin` را به `index.html` هدایت میکند.
|
|
||||||
|
|
||||||
## ۶. فعالسازی سامانه
|
|
||||||
|
|
||||||
صفحه ورود را باز کنید و شناسه سرور نمایشدادهشده در فرایند فعالسازی را برای شرکت تولیدکننده ارسال کنید. کد فعالسازی متناظر را از شرکت تولیدکننده دریافت و در صفحه فعالسازی وارد کنید. کد به همان سرور و نسخه پروفایل وابسته است.
|
|
||||||
|
|
||||||
## ۷. ایجاد مدیر اولیه
|
|
||||||
|
|
||||||
سامانه رمز پیشفرض یا ثابت ندارد. پس از ایجاد دیتابیس، در PowerShell سرور مقادیر زیر را با اطلاعات واقعی تنظیم و ابزار را اجرا کنید:
|
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
$env:INOGEN_TARGET_CONNECTION = "Server=SQL-SERVER;Database=Inogen;User Id=INOGEN_USER;Password=STRONG_PASSWORD;Encrypt=True;TrustServerCertificate=True"
|
.\migrate-target.ps1 -SqlUser 'inogen_migrator'
|
||||||
$env:INOGEN_TARGET_ALLOWED_SERVER = "SQL-SERVER"
|
|
||||||
$env:INOGEN_TARGET_ALLOWED_DATABASE = "Inogen"
|
|
||||||
$env:INOGEN_BOOTSTRAP_ADMIN_USER = "admin"
|
|
||||||
$env:INOGEN_BOOTSTRAP_ADMIN_PASSWORD = "A-Long-Unique-Password"
|
|
||||||
$env:INOGEN_BOOTSTRAP_ADMIN_DISPLAY_NAME = "مدیر سامانه"
|
|
||||||
& ".\tools\Inogen.DataTransfer\Inogen.DataTransfer.exe" provision-admin
|
|
||||||
```
|
```
|
||||||
|
|
||||||
پس از اجرا، متغیرهای حاوی رمز را از همان نشست پاک کنید یا پنجره PowerShell را ببندید. رمز در خروجی ثبت نمیشود.
|
فقط پس از دیدن `Target migrations applied.` ادامه دهید و همین پنجرهٔ PowerShell را برای ساخت حساب مدیر باز نگه دارید. migration ساختار دیتابیس را ایجاد میکند و دادهٔ قدیمی را منتقل نمیکند. اگر گواهی SQL فقط در محیط تست مورد اعتماد نیست، میتوانید موقتاً `-TrustServerCertificate` را به انتهای همین فرمان اضافه کنید.
|
||||||
|
|
||||||
## ۸. بازنشانی رمز فراموششده مدیر
|
اگر خطای `SQL error 262: CREATE TABLE permission denied` دیدید، migration را متوقف کنید؛ گام ۲ و ۳ بخش «دیتابیس و حسابها» را روی همان نمونهٔ SQL و همان دیتابیس تکرار کنید. پیام `Target guard passed` فقط نام مقصد را بررسی میکند و تأیید مجوز SQL نیست. پس از اینکه هر دو مقدار بررسی مجوز `1` شدند، فرمان migration را دوباره اجرا کنید. اگر خطای گواهی نامعتبر دیدید، گواهی SQL را روی سرور برنامه مورد اعتماد قرار دهید؛ گزینهٔ `-TrustServerCertificate` فقط برای تست داخلی است.
|
||||||
|
|
||||||
با همان سه متغیر اتصال مرحله قبل، متغیرهای زیر را تنظیم و فرمان بازنشانی را اجرا کنید. این فرمان فقط برای حساب فعال دارای نقش Admin عمل میکند:
|
4. پس از migration، در SSMS مجوز حساب runtime را روی دیتابیس مقصد ثبت کنید:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
USE [Inogen_CompanyA]; IF USER_ID(N'inogen_runtime') IS NULL CREATE USER [inogen_runtime] FOR LOGIN [inogen_runtime]; GRANT SELECT, INSERT, UPDATE, DELETE ON SCHEMA::[inogen] TO [inogen_runtime];
|
||||||
|
```
|
||||||
|
|
||||||
|
## ۴. سایتهای IIS را دستی ایجاد کنید
|
||||||
|
|
||||||
|
1. در IIS Manager دو Application Pool به نام `Inogen-Frontend` و `Inogen-Api` بسازید و `.NET CLR Version` را برای هر دو روی `No Managed Code` بگذارید.
|
||||||
|
2. سایت فرانت را به مسیر فیزیکی `C:\Inogen\frontend` و Pool اول وصل کنید. سایت API را به `C:\Inogen\backend` و Pool دوم وصل کنید. اگر مسیر استخراج متفاوت است، همان مسیر واقعی را وارد کنید.
|
||||||
|
3. برای هر سایت binding از نوع `https` روی پورت `443` و Host name همان دامنه با SNI بسازید و گواهی همان دامنه را انتخاب کنید. اگر از ابر آروان استفاده میکنید، HTTPS از آروان تا سرور مبدأ را نیز تنظیم کنید.
|
||||||
|
4. به `IIS AppPool\Inogen-Api` روی `backend\data` و زیرپوشههای آن مجوز Modify بدهید.
|
||||||
|
5. رشتهٔ اتصال حساب runtime را با نام `ConnectionStrings__TargetDatabase` در **متغیرهای محیطی App Pool API** ثبت کنید. نمونهٔ مقدار در `appsettings.Production.json` آمده است؛ رمز واقعی را در آن فایل ننویسید. پس از ساخت Pool، در PowerShell مدیر فرمان زیر را اجرا کنید. اسکریپت نام سرور و دیتابیس را از فایل تنظیمات میخواند و رمز را جداگانه میپرسد:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
$env:INOGEN_RESET_ADMIN_USER = "admin"
|
.\set-iis-runtime-connection.ps1 -SqlUser 'inogen_runtime' -AppPoolName 'Inogen-Api'
|
||||||
$env:INOGEN_RESET_ADMIN_PASSWORD = "A-New-Long-Unique-Password"
|
|
||||||
& ".\tools\Inogen.DataTransfer\Inogen.DataTransfer.exe" reset-admin-password
|
|
||||||
```
|
```
|
||||||
|
|
||||||
در پایان سایت فرانتاند و بکاند را یکبار Restart کنید و ورود به `/admin` و داشبورد را بررسی کنید.
|
این مقدار در تنظیمات IIS ذخیره میشود؛ دسترسی مدیران سرور به آن را محدود کنید. اگر نام Pool را تغییر دادهاید، مقدار `-AppPoolName` را عوض کنید. در محیط تست، اگر گواهی SQL هنوز مورد اعتماد نیست، گزینهٔ `-TrustServerCertificate` را فقط موقتاً به فرمان اضافه کنید.
|
||||||
|
|
||||||
|
6. از خود سرور، `https://api.example.com/health` و سپس `https://api.example.com/api/v1/deployment/profile` را باز کنید. پاسخ اول باید کد `200` و پاسخ دوم باید یک شیء JSON شامل `company`، `branding` و `activation` باشد. سپس نشانی فرانت را باز کنید. اگر فرانت پیام «تنظیمات استقرار در دسترس نیست» نشان داد، ابتدا `frontend\config\runtime-config.js` را بررسی کنید و سپس در ابزار Developer Tools مرورگر، وضعیت درخواست `/api/v1/deployment/profile` را ببینید. اگر درخواست به دامنهٔ اشتباه میرود، نشانی API را در همان فایل اصلاح و صفحه را با بارگذاری کامل دوباره باز کنید؛ اگر درخواست از دامنهٔ درست خطای شبکه یا CORS دارد، HTTPS دامنهٔ API و مقدار `FrontendOrigins` را بررسی کنید.
|
||||||
|
|
||||||
|
## ۵. سامانه را فعال و مدیر را ایجاد کنید
|
||||||
|
|
||||||
|
1. نشانی فرانت را مانند `https://app.example.com/admin` باز کنید. اگر صفحهٔ فعالسازی نمایش داده شد، شناسهٔ ۶۴ کاراکتری سرور را کپی و برای صادرکنندهٔ کد ارسال کنید. کد دریافتی را در همان صفحه ثبت کنید.
|
||||||
|
2. در همان نشست PowerShell گام ۳، حساب مدیر را روی همان دیتابیس بسازید. اگر PowerShell را بستهاید، ابتدا اتصال را در نشست جدید با فرمان زیر دوباره آماده کنید؛ `-ConfigureOnly` migration را تکرار نمیکند:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
.\migrate-target.ps1 -SqlUser 'inogen_migrator' -ConfigureOnly
|
||||||
|
```
|
||||||
|
|
||||||
|
اگر فقط در محیط تست گواهی SQL هنوز مورد اعتماد نیست، به همین فرمان `-TrustServerCertificate` را هم اضافه کنید. سپس در همان پنجره حساب مدیر را بسازید:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
.\initialize-admin.ps1 -DisplayName 'مدیر سامانه'
|
||||||
|
```
|
||||||
|
|
||||||
|
رمز مدیر باید حداقل ۱۲ نویسه، حرف بزرگ، حرف کوچک، رقم و نویسهٔ ویژه داشته باشد. نام کاربری خروجی را ثبت کنید و رمز را جداگانه و امن تحویل دهید. حساب مدیر با رمز پیشفرض وجود ندارد.
|
||||||
|
|
||||||
|
پس از فعالسازی و ورود مدیر، صفحهٔ تنظیمات استقرار را مستقیم با نشانی مانند `https://app.example.com/admin/deployment-settings` باز کنید. این صفحه در منوی پنل نمایش داده نمیشود. در بخش `واحدهای داشبورد` نام واحدها و چیدمان را ثبت کنید و دکمهٔ `ذخیره تنظیمات` را بزنید. صفحهٔ ورود کد فعالسازی فقط کد را دریافت میکند؛ تنظیمات واحدها در صفحهٔ جداگانه انجام میشود.
|
||||||
|
|
||||||
|
اگر ساخت مدیر ناموفق بود، مرحلهٔ اعلامشده در خطای ابزار را بخوانید. برای خطای `Identity validation failed`، کد خطای سیاست رمز یا نام کاربری را اصلاح و فرمان را دوباره اجرا کنید. اگر نشست PowerShell عوض شده است، ابتدا فرمان `migrate-target.ps1` را با `-ConfigureOnly` در همان نشست اجرا کنید و سپس ساخت مدیر را تکرار کنید. اگر خطا در مرحلهٔ `create roles` یا `assign administrator role` رخ داد، مجوز حساب migration را روی دیتابیس مقصد بررسی کنید؛ حساب API را برای این فرمان به کار نبرید.
|
||||||
|
|
||||||
|
## ۶. نصب را بررسی کنید
|
||||||
|
|
||||||
|
1. نشانی پنل مدیر را با دامنهٔ واقعی فرانت، مانند `https://app.example.com/admin`، باز کنید و با حساب مدیری که در گام ۵ ساختهاید وارد شوید. نشانی دامنهٔ API صفحهٔ ورود مدیر ندارد. پاسخ فرانت و API را بررسی کنید.
|
||||||
|
2. روی نقطهٔ پایان HTTPS، TLS 1.0 و 1.1 و cipherهای CBC را غیرفعال کنید. برای Windows Server میتوانید `configure-windows-tls.ps1` را ابتدا برای پیشنمایش و سپس در بازهٔ نگهداری با `-Apply` اجرا کنید. تنظیمات ابر آروان را در پنل آن انجام دهید.
|
||||||
|
3. متغیرهای موقت نشست نصب را پاک کنید:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Remove-Item Env:INOGEN_TARGET_CONNECTION,Env:INOGEN_TARGET_ALLOWED_SERVER,Env:INOGEN_TARGET_ALLOWED_DATABASE -ErrorAction SilentlyContinue
|
||||||
|
```
|
||||||
|
|
|
||||||
175
deployment/INSTALL.pdf
Normal file
175
deployment/INSTALL.pdf
Normal file
|
|
@ -0,0 +1,175 @@
|
||||||
|
راهنمای نصب دستی Inogenبرای مشتری
|
||||||
|
|
||||||
|
در نمون ههای زیر ،سرور SQLبرابر ،SQL-SERVER-01دیتابیس جدید برابر ،Inogen_CompanyAدامنٔه فرانت برابر
|
||||||
|
app.example.comو دامنٔه APIبرابر api.example.comاست .این مقدارها را با مقدار واقعی خود جایگزین کنید.
|
||||||
|
|
||||||
|
فرما نها را از ریشٔه بستٔه استخرا جشده اجرا کنید.
|
||||||
|
|
||||||
|
.۱سرور و فای لها را آماده کنید
|
||||||
|
|
||||||
|
.1روی Windows Server، IISبا قابلیتهای Static Contentو ،Default Documentافزونه URL Rewriteو
|
||||||
|
NET Hosting Bundle.سازگار با APIرا نصب کنید.
|
||||||
|
|
||||||
|
.2برای دامنههای فرانت و APIرکورد DNSتنظیم کنید .گواهی HTTPSمعتبر هر دامنه را روی سرور IISنصب
|
||||||
|
کنید؛ گواهی CDNب هتنهایی گواهی IISنیست.
|
||||||
|
|
||||||
|
ZIP .3را در پوشهای مانند C:\Inogenاستخراج کنید .پوشههای frontendو backendرا کنار هم نگه دارید؛
|
||||||
|
فرما نهای نصب را از ریشٔه بسته اجرا کنید.
|
||||||
|
|
||||||
|
.۲دیتابیس و حسا بها را آماده کنید
|
||||||
|
|
||||||
|
.1در SQL Serverیک دیتابیس خالی با نام واقعی استقرار ،مانند ،Inogen_CompanyAایجاد کنید.
|
||||||
|
.2در SSMSبه همان نمونٔه SQL Serverکه دیتابیس را در آن ساختهاید ،با حساب مدیر وصل شوید .از بخش
|
||||||
|
Security > Loginsحساب SQLبه نام inogen_migratorرا بسازید یا وجود آن را بررسی کنید .در یک پنجرٔه
|
||||||
|
Queryهمان اتصال ،نام دیتابیس را در فرمان زیر جایگزین و آن را اجرا کنید تا کاربر دیتابیس ساخته شود و
|
||||||
|
|
||||||
|
مجوز اجرای migrationبگیرد:
|
||||||
|
|
||||||
|
USE [Inogen_CompanyA]; IF USER_ID(N'inogen_migrator') IS NULL CREATE USER [inogen_migrator] FOR LOGIN
|
||||||
|
[inogen_migrator]; IF IS_ROLEMEMBER(N'db_owner', N'inogen_migrator') <> 1 ALTER ROLE [db_owner] ADD
|
||||||
|
;]MEMBER [inogen_migrator
|
||||||
|
|
||||||
|
حساب جداگانٔه inogen_runtimeرا برای APIبسازید؛ پس از اجرای migrationبه آن مجوزهای ،INSERT ،SELECT
|
||||||
|
UPDATEو DELETEروی inogen schemaبدهید .به حساب runtimeمجوز تغییر ساختار ندهید .3 .پیش از اجرای
|
||||||
|
|
||||||
|
،migrationیک اتصال جدید در SSMSبا SQL Authenticationو حساب inogen_migratorبه همان نمونٔه SQLباز
|
||||||
|
کنید .فرمان زیر را با نام دیتابیس واقعی اجرا کنید .مقدارهای IsDbOwnerو CanCreateTableباید هر دو 1باشند .اگر
|
||||||
|
|
||||||
|
اتصال برقرار نشد یا یکی از مقدارها 1نبود ،نگاشت کاربر ،نقش و نام نمونٔه SQLرا با مدیر سرور اصلاح کنید و
|
||||||
|
سپس این بررسی را تکرار کنید:
|
||||||
|
|
||||||
|
)(USE [Inogen_CompanyA]; SELECT @@SERVERNAME AS SqlServer, DB_NAME() AS DatabaseName, ORIGINAL_LOGIN
|
||||||
|
AS LoginName, USER_NAME() AS DatabaseUser, IS_MEMBER(N'db_owner') AS IsDbOwner,
|
||||||
|
;HAS_PERMS_BY_NAME(DB_NAME(), N'DATABASE', N'CREATE TABLE') AS CanCreateTable
|
||||||
|
|
||||||
|
.1گواهی TLSسرور SQLرا روی سرور برنامه مورد اعتماد قرار دهید .رشت ههای اتصال را با
|
||||||
|
Encrypt=True;TrustServerCertificate=Falseتنظیم کنید.
|
||||||
|
.۳تنظیمات را ثبت و migrationرا اجرا کنید
|
||||||
|
|
||||||
|
.1در ،backend\appsettings.Production.jsonمقدارهای نمونٔه AllowedDatabases ،AllowedServersو
|
||||||
|
FrontendOriginsرا با سرور ،SQLدیتابیس مقصد و نشانی فرانت واقعی جایگزین کنید .مقدار
|
||||||
|
|
||||||
|
ApplyMigrationsOnStartupرا falseنگه دارید .مقدار TargetDatabaseفقط نمونه است؛ رمز CHANGE_MEرا در
|
||||||
|
فایل به رمز واقعی تبدیل نکنید .رشتٔه اتصال واقعی را در گام ،IISبرای App Pool APIثبت کنید.
|
||||||
|
|
||||||
|
.2در frontend\config\runtime-config.jsنشانی APIرا ثبت کنید:
|
||||||
|
|
||||||
|
;} "window.INOGEN_CONFIG = { apiBaseUrl: "https://api.example.com/api/v1
|
||||||
|
|
||||||
|
فایل را در پوشٔه frontendنسخٔه نصبشده روی سرور نیز بررسی کنید؛ مقدار /api/v1فقط زمانی درست
|
||||||
|
است که APIو فرانت روی یک دامنه و از همان مسیر منتشر شده باشند .برای دو دامنٔه جدا ،نشانی کامل HTTPS
|
||||||
|
|
||||||
|
دامنٔه APIرا مانند نمونٔه بالا بگذارید .در backend\appsettings.Production.jsonنیز نشانی واقعی دامنٔه فرانت را
|
||||||
|
در FrontendOriginsثبت کنید.
|
||||||
|
|
||||||
|
.1در ،PowerShellپس از اصلاح AllowedServersو AllowedDatabasesدر فایل تنظیمات ،فرمان زیر را از ریشٔه
|
||||||
|
بسته اجرا کنید .نام حساب SQLرا جایگزین کنید؛ اسکریپت نام سرور و دیتابیس را از همان فایل م یخواند و
|
||||||
|
|
||||||
|
رمز را جداگانه درخواست میکند:
|
||||||
|
|
||||||
|
'.\migrate-target.ps1 -SqlUser 'inogen_migrator
|
||||||
|
|
||||||
|
فقط پس از دیدن Target migrations applied.ادامه دهید و همین پنجرٔه PowerShellرا برای ساخت حساب مدیر
|
||||||
|
باز نگه دارید migration .ساختار دیتابیس را ایجاد م یکند و دادٔه قدیمی را منتقل نمیکند .اگر گواهی SQLفقط در
|
||||||
|
محیط تست مورد اعتماد نیست ،میتوانید موقتًا -TrustServerCertificateرا به انتهای همین فرمان اضافه کنید.
|
||||||
|
|
||||||
|
اگر خطای SQL error 262: CREATE TABLE permission deniedدیدید migration ،را متوقف کنید؛ گام ۲و ۳بخش
|
||||||
|
«دیتابیس و حسا بها» را روی همان نمونٔه SQLو همان دیتابیس تکرار کنید .پیام Target guard passedفقط نام
|
||||||
|
|
||||||
|
مقصد را بررسی م یکند و تأیید مجوز SQLنیست .پس از اینکه هر دو مقدار بررسی مجوز 1شدند ،فرمان migration
|
||||||
|
را دوباره اجرا کنید .اگر خطای گواهی نامعتبر دیدید ،گواهی SQLرا روی سرور برنامه مورد اعتماد قرار دهید؛ گزینٔه -
|
||||||
|
|
||||||
|
TrustServerCertificateفقط برای تست داخلی است.
|
||||||
|
|
||||||
|
.1پس از ،migrationدر SSMSمجوز حساب runtimeرا روی دیتابیس مقصد ثبت کنید:
|
||||||
|
|
||||||
|
USE [Inogen_CompanyA]; IF USER_ID(N'inogen_runtime') IS NULL CREATE USER [inogen_runtime] FOR LOGIN
|
||||||
|
;][inogen_runtime]; GRANT SELECT, INSERT, UPDATE, DELETE ON SCHEMA::[inogen] TO [inogen_runtime
|
||||||
|
|
||||||
|
.۴سایتهای IISرا دستی ایجاد کنید
|
||||||
|
|
||||||
|
.1در IIS Managerدو Application Poolبه نام Inogen-Frontendو Inogen-Apiبسازید و .NET CLR Versionرا
|
||||||
|
برای هر دو روی No Managed Codeبگذارید.
|
||||||
|
.2سایت فرانت را به مسیر فیزیکی C:\Inogen\frontendو Poolاول وصل کنید .سایت APIرا به
|
||||||
|
C:\Inogen\backendو Poolدوم وصل کنید .اگر مسیر استخراج متفاوت است ،همان مسیر واقعی را وارد
|
||||||
|
|
||||||
|
کنید.
|
||||||
|
.3برای هر سایت bindingاز نوع httpsروی پورت 443و Host nameهمان دامنه با SNIبسازید و گواهی همان
|
||||||
|
|
||||||
|
دامنه را انتخاب کنید .اگر از ابر آروان استفاده میکنید HTTPS ،از آروان تا سرور مبدأ را نیز تنظیم کنید.
|
||||||
|
.4به IIS AppPool\Inogen-Apiروی backend\dataو زیرپوش ههای آن مجوز Modifyبدهید.
|
||||||
|
|
||||||
|
.5رشتٔه اتصال حساب runtimeرا با نام ConnectionStrings__TargetDatabaseدر متغیرهای محیطی App
|
||||||
|
Pool APIثبت کنید .نمونٔه مقدار در appsettings.Production.jsonآمده است؛ رمز واقعی را در آن فایل
|
||||||
|
|
||||||
|
ننویسید .پس از ساخت ،Poolدر PowerShellمدیر فرمان زیر را اجرا کنید .اسکریپت نام سرور و دیتابیس را از
|
||||||
|
فایل تنظیمات م یخواند و رمز را جداگانه م یپرسد:
|
||||||
|
|
||||||
|
'.\set-iis-runtime-connection.ps1 -SqlUser 'inogen_runtime' -AppPoolName 'Inogen-Api
|
||||||
|
|
||||||
|
این مقدار در تنظیمات IISذخیره م یشود؛ دسترسی مدیران سرور به آن را محدود کنید .اگر نام Poolرا تغییر
|
||||||
|
داد هاید ،مقدار -AppPoolNameرا عوض کنید .در محیط تست ،اگر گواهی SQLهنوز مورد اعتماد نیست ،گزینٔه -
|
||||||
|
|
||||||
|
TrustServerCertificateرا فقط موقتًا به فرمان اضافه کنید.
|
||||||
|
|
||||||
|
.1از خود سرور https://api.example.com/health ،و سپس
|
||||||
|
https://api.example.com/api/v1/deployment/profileرا باز کنید .پاسخ اول باید کد 200و پاسخ دوم باید
|
||||||
|
یک شیء JSONشامل branding ،companyو activationباشد .سپس نشانی فرانت را باز کنید .اگر فرانت
|
||||||
|
|
||||||
|
پیام «تنظیمات استقرار در دسترس نیست» نشان داد ،ابتدا frontend\config\runtime-config.jsرا
|
||||||
|
بررسی کنید و سپس در ابزار Developer Toolsمرورگر ،وضعیت درخواست /api/v1/deployment/profileرا
|
||||||
|
|
||||||
|
ببینید .اگر درخواست به دامنٔه اشتباه م یرود ،نشانی APIرا در همان فایل اصلاح و صفحه را با بارگذاری
|
||||||
|
کامل دوباره باز کنید؛ اگر درخواست از دامنٔه درست خطای شبکه یا CORSدارد HTTPS ،دامنٔه APIو مقدار
|
||||||
|
|
||||||
|
FrontendOriginsرا بررسی کنید.
|
||||||
|
|
||||||
|
.۵سامانه را فعال و مدیر را ایجاد کنید
|
||||||
|
|
||||||
|
.1نشانی فرانت را مانند https://app.example.com/adminباز کنید .اگر صفحٔه فعا لسازی نمایش داده شد،
|
||||||
|
شناسٔه ۶۴کاراکتری سرور را کپی و برای صادرکنندٔه کد ارسال کنید .کد دریافتی را در همان صفحه ثبت
|
||||||
|
کنید.
|
||||||
|
.2در همان نشست PowerShellگام ،۳حساب مدیر را روی همان دیتابیس بسازید .اگر PowerShellرا
|
||||||
|
|
||||||
|
بست هاید ،ابتدا اتصال را در نشست جدید با فرمان زیر دوباره آماده کنید؛ migration -ConfigureOnlyرا تکرار
|
||||||
|
نمیکند:
|
||||||
|
|
||||||
|
.\migrate-target.ps1 -SqlUser 'inogen_migrator' -ConfigureOnly
|
||||||
|
|
||||||
|
اگر فقط در محیط تست گواهی SQLهنوز مورد اعتماد نیست ،به همین فرمان -TrustServerCertificateرا هم
|
||||||
|
اضافه کنید .سپس در همان پنجره حساب مدیر را بسازید:
|
||||||
|
'مدیر سامانه' .\initialize-admin.ps1 -DisplayName
|
||||||
|
|
||||||
|
رمز مدیر باید حداقل ۱۲نویسه ،حرف بزرگ ،حرف کوچک ،رقم و نویسٔه ویژه داشته باشد .نام کاربری خروجی را ثبت
|
||||||
|
کنید و رمز را جداگانه و امن تحویل دهید .حساب مدیر با رمز پی شفرض وجود ندارد.
|
||||||
|
|
||||||
|
پس از فعا لسازی و ورود مدیر ،صفحٔه تنظیمات استقرار را مستقیم با نشانی مانند
|
||||||
|
https://app.example.com/admin/deployment-settingsباز کنید .این صفحه در منوی پنل نمایش داده نم یشود.
|
||||||
|
|
||||||
|
در بخش واحدهای داشبورد نام واحدها و چیدمان را ثبت کنید و دکمٔه ذخیره تنظیمات را بزنید .صفحٔه ورود کد
|
||||||
|
فعا لسازی فقط کد را دریافت م یکند؛ تنظیمات واحدها در صفحٔه جداگانه انجام م یشود.
|
||||||
|
|
||||||
|
اگر ساخت مدیر ناموفق بود ،مرحلٔه اعلامشده در خطای ابزار را بخوانید .برای خطای ،Identity validation failed
|
||||||
|
کد خطای سیاست رمز یا نام کاربری را اصلاح و فرمان را دوباره اجرا کنید .اگر نشست PowerShellعوض شده
|
||||||
|
|
||||||
|
است ،ابتدا فرمان migrate-target.ps1را با -ConfigureOnlyدر همان نشست اجرا کنید و سپس ساخت مدیر را
|
||||||
|
تکرار کنید .اگر خطا در مرحلٔه create rolesیا assign administrator roleرخ داد ،مجوز حساب migrationرا روی
|
||||||
|
|
||||||
|
دیتابیس مقصد بررسی کنید؛ حساب APIرا برای این فرمان به کار نبرید.
|
||||||
|
|
||||||
|
.۶نصب را بررسی کنید
|
||||||
|
|
||||||
|
.1نشانی پنل مدیر را با دامنٔه واقعی فرانت ،مانند ،https://app.example.com/adminباز کنید و با حساب
|
||||||
|
مدیری که در گام ۵ساخت هاید وارد شوید .نشانی دامنٔه APIصفحٔه ورود مدیر ندارد .پاسخ فرانت و APIرا
|
||||||
|
|
||||||
|
بررسی کنید.
|
||||||
|
.2روی نقطٔه پایان HTTPS، TLS 1.0و 1.1و cipherهای CBCرا غیرفعال کنید .برای Windows Serverم یتوانید
|
||||||
|
configure-windows-tls.ps1را ابتدا برای پی شنمایش و سپس در بازٔه نگهداری با -Applyاجرا کنید .تنظیمات
|
||||||
|
|
||||||
|
ابر آروان را در پنل آن انجام دهید.
|
||||||
|
.3متغیرهای موقت نشست نصب را پاک کنید:
|
||||||
|
|
||||||
|
Remove-Item
|
||||||
|
Env:INOGEN_TARGET_CONNECTION,Env:INOGEN_TARGET_ALLOWED_SERVER,Env:INOGEN_TARGET_ALLOWED_DATABASE -
|
||||||
|
ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
|
@ -1,17 +1,18 @@
|
||||||
{
|
{
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"TargetDatabase": "Server=SQL-SERVER;Database=Inogen;User Id=INOGEN_USER;Password=CHANGE_ME;Encrypt=True;TrustServerCertificate=True"
|
"TargetDatabase": "Server=SQL-SERVER-01;Database=Inogen_CompanyA;User Id=inogen_runtime;Password=CHANGE_ME;Encrypt=True;TrustServerCertificate=False;"
|
||||||
},
|
},
|
||||||
"TargetDatabaseGuard": {
|
"TargetDatabaseGuard": {
|
||||||
"AllowedServers": ["SQL-SERVER"],
|
"AllowedServers": ["SQL-SERVER-01"],
|
||||||
"AllowedDatabases": ["Inogen"]
|
"AllowedDatabases": ["Inogen_CompanyA"]
|
||||||
},
|
},
|
||||||
"FrontendOrigins": ["https://INOGEN-SERVER"],
|
"FrontendOrigins": ["https://app.example.com"],
|
||||||
"Security": {
|
"Security": {
|
||||||
"AllowInsecureHttp": false,
|
"AllowInsecureHttp": false,
|
||||||
"IntegrityPublicKeyPath": "integrity-public.pem"
|
"IntegrityPublicKeyPath": "integrity-public.pem",
|
||||||
|
"KnownProxies": []
|
||||||
},
|
},
|
||||||
"DatabaseInitialization": {
|
"DatabaseInitialization": {
|
||||||
"ApplyMigrationsOnStartup": true
|
"ApplyMigrationsOnStartup": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param(
|
param(
|
||||||
[string]$BackendSource = "D:\Work\Inogen_new\backend",
|
[string]$BackendSource = "D:\Work\Inogen_new\Inogen backend",
|
||||||
[string]$OutputRoot = (Join-Path $PSScriptRoot "..\artifacts"),
|
[string]$OutputRoot = (Join-Path $PSScriptRoot "..\artifacts"),
|
||||||
[string]$SigningPrivateKey = $env:INOGEN_RELEASE_SIGNING_KEY,
|
[string]$SigningPrivateKey = $env:INOGEN_RELEASE_SIGNING_KEY,
|
||||||
[switch]$SkipNpmInstall
|
[string]$ApiBaseUrl,
|
||||||
|
[switch]$SkipNpmInstall,
|
||||||
|
[switch]$IncludeInternalTransfer
|
||||||
)
|
)
|
||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
|
|
@ -11,17 +13,36 @@ $frontendSource = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
|
||||||
$backendSourcePath = (Resolve-Path -LiteralPath $BackendSource).Path
|
$backendSourcePath = (Resolve-Path -LiteralPath $BackendSource).Path
|
||||||
$outputRootPath = [IO.Path]::GetFullPath($OutputRoot)
|
$outputRootPath = [IO.Path]::GetFullPath($OutputRoot)
|
||||||
$releaseName = "Inogen-{0}" -f (Get-Date -Format "yyyyMMdd-HHmmss")
|
$releaseName = "Inogen-{0}" -f (Get-Date -Format "yyyyMMdd-HHmmss")
|
||||||
|
if ($IncludeInternalTransfer) { $releaseName += "-Internal" }
|
||||||
$releasePath = Join-Path $outputRootPath $releaseName
|
$releasePath = Join-Path $outputRootPath $releaseName
|
||||||
$backendOutput = Join-Path $releasePath "backend"
|
$backendOutput = Join-Path $releasePath "backend"
|
||||||
$frontendOutput = Join-Path $releasePath "frontend"
|
$frontendOutput = Join-Path $releasePath "frontend"
|
||||||
$toolOutput = Join-Path $releasePath "tools\Inogen.DataTransfer"
|
$transferOutput = Join-Path $releasePath "tools\Inogen.DataTransfer"
|
||||||
|
|
||||||
if ([string]::IsNullOrWhiteSpace($SigningPrivateKey)) {
|
if ([string]::IsNullOrWhiteSpace($SigningPrivateKey)) {
|
||||||
throw "Set INOGEN_RELEASE_SIGNING_KEY to the absolute path of the RSA private PEM used for release signing."
|
throw "Release signing key is not configured. Generate one once with: dotnet run --project '<backend>\tools\Inogen.ReleaseProtector' -- generate-key '<secure-directory>\inogen-release-private.pem'. Then set INOGEN_RELEASE_SIGNING_KEY to that absolute file path. Keep the private key outside the package and source tree."
|
||||||
|
}
|
||||||
|
if (-not [IO.Path]::IsPathRooted($SigningPrivateKey) -or
|
||||||
|
-not (Test-Path -LiteralPath $SigningPrivateKey -PathType Leaf)) {
|
||||||
|
throw "SigningPrivateKey must be the absolute path of an existing private PEM file."
|
||||||
}
|
}
|
||||||
$signingKeyPath = (Resolve-Path -LiteralPath $SigningPrivateKey).Path
|
$signingKeyPath = (Resolve-Path -LiteralPath $SigningPrivateKey).Path
|
||||||
|
|
||||||
New-Item -ItemType Directory -Force -Path $backendOutput, $frontendOutput, $toolOutput | Out-Null
|
if ([string]::IsNullOrWhiteSpace($ApiBaseUrl)) {
|
||||||
|
throw "Set -ApiBaseUrl to the HTTPS API address ending in /api/v1 for this deployment."
|
||||||
|
}
|
||||||
|
$apiUri = $null
|
||||||
|
if (-not [Uri]::TryCreate($ApiBaseUrl.Trim(), [UriKind]::Absolute, [ref]$apiUri) -or
|
||||||
|
$apiUri.Scheme -ne [Uri]::UriSchemeHttps -or
|
||||||
|
$apiUri.AbsolutePath.TrimEnd('/') -ne '/api/v1' -or
|
||||||
|
-not [string]::IsNullOrEmpty($apiUri.Query) -or
|
||||||
|
-not [string]::IsNullOrEmpty($apiUri.Fragment) -or
|
||||||
|
-not [string]::IsNullOrEmpty($apiUri.UserInfo)) {
|
||||||
|
throw "ApiBaseUrl must be an absolute HTTPS URL ending in /api/v1 without query, fragment, or credentials."
|
||||||
|
}
|
||||||
|
|
||||||
|
New-Item -ItemType Directory -Force -Path $backendOutput, $frontendOutput | Out-Null
|
||||||
|
if ($IncludeInternalTransfer) { New-Item -ItemType Directory -Force -Path $transferOutput | Out-Null }
|
||||||
|
|
||||||
function Assert-NativeCommandSucceeded([string]$operation) {
|
function Assert-NativeCommandSucceeded([string]$operation) {
|
||||||
if ($LASTEXITCODE -ne 0) { throw "$operation failed with exit code $LASTEXITCODE." }
|
if ($LASTEXITCODE -ne 0) { throw "$operation failed with exit code $LASTEXITCODE." }
|
||||||
|
|
@ -86,6 +107,11 @@ try {
|
||||||
npm run build
|
npm run build
|
||||||
Assert-NativeCommandSucceeded "Frontend build"
|
Assert-NativeCommandSucceeded "Frontend build"
|
||||||
Copy-Item -Path (Join-Path $frontendSource "build\client\*") -Destination $frontendOutput -Recurse -Force
|
Copy-Item -Path (Join-Path $frontendSource "build\client\*") -Destination $frontendOutput -Recurse -Force
|
||||||
|
$runtimeConfigPath = Join-Path $frontendOutput "config\runtime-config.js"
|
||||||
|
$apiBaseUrlJson = ConvertTo-Json -InputObject $apiUri.AbsoluteUri.TrimEnd('/') -Compress
|
||||||
|
[IO.File]::WriteAllText($runtimeConfigPath,
|
||||||
|
"window.INOGEN_CONFIG = { apiBaseUrl: $apiBaseUrlJson };`n",
|
||||||
|
[Text.UTF8Encoding]::new($false))
|
||||||
}
|
}
|
||||||
finally { Pop-Location }
|
finally { Pop-Location }
|
||||||
|
|
||||||
|
|
@ -94,28 +120,40 @@ dotnet publish (Join-Path $backendSourcePath "src\Inogen.Api\Inogen.Api.csproj")
|
||||||
Assert-NativeCommandSucceeded "Backend publish"
|
Assert-NativeCommandSucceeded "Backend publish"
|
||||||
$developmentSettings = Join-Path $backendOutput "appsettings.Development.json"
|
$developmentSettings = Join-Path $backendOutput "appsettings.Development.json"
|
||||||
if (Test-Path -LiteralPath $developmentSettings) { Remove-Item -LiteralPath $developmentSettings -Force }
|
if (Test-Path -LiteralPath $developmentSettings) { Remove-Item -LiteralPath $developmentSettings -Force }
|
||||||
dotnet publish (Join-Path $backendSourcePath "tools\Inogen.DataTransfer\Inogen.DataTransfer.csproj") `
|
if ($IncludeInternalTransfer) {
|
||||||
--configuration Release --output $toolOutput --no-self-contained
|
dotnet publish (Join-Path $backendSourcePath "tools\Inogen.DataTransfer\Inogen.DataTransfer.csproj") `
|
||||||
Assert-NativeCommandSucceeded "Administration tool publish"
|
--configuration Release --output $transferOutput --no-self-contained
|
||||||
|
Assert-NativeCommandSucceeded "Internal transfer tool publish"
|
||||||
|
}
|
||||||
Push-Location $backendSourcePath
|
Push-Location $backendSourcePath
|
||||||
try {
|
try {
|
||||||
dotnet tool restore
|
dotnet tool restore
|
||||||
Assert-NativeCommandSucceeded "Obfuscator restore"
|
Assert-NativeCommandSucceeded "Obfuscator restore"
|
||||||
}
|
}
|
||||||
finally { Pop-Location }
|
finally { Pop-Location }
|
||||||
$backendModules = @("Inogen.Api.dll", "Inogen.Application.dll")
|
$backendModules = @()
|
||||||
$toolModules = @("Inogen.DataTransfer.dll", "Inogen.Application.dll")
|
|
||||||
$integrityModules = @("Inogen.Api.dll", "Inogen.Application.dll", "Inogen.Domain.dll", "Inogen.Infrastructure.dll")
|
$integrityModules = @("Inogen.Api.dll", "Inogen.Application.dll", "Inogen.Domain.dll", "Inogen.Infrastructure.dll")
|
||||||
Protect-Assemblies $backendOutput $backendModules
|
if ($backendModules.Count -gt 0) { Protect-Assemblies $backendOutput $backendModules }
|
||||||
Protect-Assemblies $toolOutput $toolModules
|
$publishedPaths = @($backendOutput)
|
||||||
Get-ChildItem -LiteralPath $backendOutput, $toolOutput -Filter "*.pdb" -File | Remove-Item -Force
|
if ($IncludeInternalTransfer) { $publishedPaths += $transferOutput }
|
||||||
Get-ChildItem -LiteralPath $backendOutput, $toolOutput -Filter "Mapping.txt" -File | Remove-Item -Force
|
Get-ChildItem -LiteralPath $publishedPaths -Filter "*.pdb" -File | Remove-Item -Force
|
||||||
|
Get-ChildItem -LiteralPath $publishedPaths -Filter "Mapping.txt" -File | Remove-Item -Force
|
||||||
Write-SignedIntegrityManifest $backendOutput $integrityModules
|
Write-SignedIntegrityManifest $backendOutput $integrityModules
|
||||||
|
|
||||||
Copy-Item -LiteralPath (Join-Path $PSScriptRoot "appsettings.Production.template.json") `
|
Copy-Item -LiteralPath (Join-Path $PSScriptRoot "appsettings.Production.template.json") `
|
||||||
-Destination (Join-Path $backendOutput "appsettings.Production.json") -Force
|
-Destination (Join-Path $backendOutput "appsettings.Production.json") -Force
|
||||||
Copy-Item -LiteralPath (Join-Path $PSScriptRoot "INSTALL.md") -Destination $releasePath -Force
|
Copy-Item -LiteralPath (Join-Path $PSScriptRoot "INSTALL.pdf") -Destination $releasePath -Force
|
||||||
|
Copy-Item -LiteralPath (Join-Path $PSScriptRoot "initialize-admin.ps1") -Destination $releasePath -Force
|
||||||
|
Copy-Item -LiteralPath (Join-Path $PSScriptRoot "migrate-target.ps1") -Destination $releasePath -Force
|
||||||
|
Copy-Item -LiteralPath (Join-Path $PSScriptRoot "set-iis-runtime-connection.ps1") -Destination $releasePath -Force
|
||||||
|
if ($IncludeInternalTransfer) {
|
||||||
|
Copy-Item -LiteralPath (Join-Path $PSScriptRoot "INSTALL-INTERNAL.pdf") -Destination $releasePath -Force
|
||||||
|
Copy-Item -LiteralPath (Join-Path $PSScriptRoot "select-internal-transfer.ps1") -Destination $releasePath -Force
|
||||||
|
Copy-Item -LiteralPath (Join-Path $PSScriptRoot "prepare-transfer-connections.ps1") -Destination $releasePath -Force
|
||||||
|
}
|
||||||
|
Copy-Item -LiteralPath (Join-Path $PSScriptRoot "configure-windows-tls.ps1") -Destination $releasePath -Force
|
||||||
|
Copy-Item -LiteralPath (Join-Path $PSScriptRoot "verify-public-security.ps1") -Destination $releasePath -Force
|
||||||
|
Copy-Item -LiteralPath (Join-Path $PSScriptRoot "verify-runtime-sql-permissions.ps1") -Destination $releasePath -Force
|
||||||
|
|
||||||
$assetPath = Join-Path $backendOutput "data\deployment\assets"
|
$assetPath = Join-Path $backendOutput "data\deployment\assets"
|
||||||
New-Item -ItemType Directory -Force -Path $assetPath, (Join-Path $backendOutput "data\files"), `
|
New-Item -ItemType Directory -Force -Path $assetPath, (Join-Path $backendOutput "data\files"), `
|
||||||
|
|
|
||||||
43
deployment/configure-windows-tls.ps1
Normal file
43
deployment/configure-windows-tls.ps1
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
[CmdletBinding(SupportsShouldProcess = $true)]
|
||||||
|
param([switch]$Apply)
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
if (-not $IsWindows -and $PSVersionTable.PSEdition -eq 'Core') {
|
||||||
|
throw 'This script must run on the Windows TLS termination server.'
|
||||||
|
}
|
||||||
|
if (-not (Get-Command Get-TlsCipherSuite -ErrorAction SilentlyContinue) -or
|
||||||
|
-not (Get-Command Disable-TlsCipherSuite -ErrorAction SilentlyContinue)) {
|
||||||
|
throw 'Windows TLS cipher suite cmdlets are unavailable on this server.'
|
||||||
|
}
|
||||||
|
|
||||||
|
$availableSuites = Get-TlsCipherSuite
|
||||||
|
$cbcSuites = @($availableSuites | Where-Object { $_.Name -match '_CBC_' } | ForEach-Object { $_.Name })
|
||||||
|
$modernSuites = @($availableSuites | Where-Object { $_.Name -match '_GCM_|_CHACHA20_' })
|
||||||
|
if ($modernSuites.Count -eq 0) { throw 'No modern TLS cipher suite was found; no changes were made.' }
|
||||||
|
|
||||||
|
Write-Host "CBC suites to disable: $($cbcSuites.Count)"
|
||||||
|
Write-Host 'TLS 1.0 and TLS 1.1 server protocols to disable.'
|
||||||
|
if (-not $Apply) {
|
||||||
|
Write-Host 'Preview only. Run with -Apply on the Windows TLS termination server after a maintenance window is approved.'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
$principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
|
||||||
|
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
||||||
|
throw 'Administrator privileges are required.'
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($version in @('TLS 1.0', 'TLS 1.1')) {
|
||||||
|
$path = "HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\$version\Server"
|
||||||
|
if ($PSCmdlet.ShouldProcess($path, 'Disable server protocol')) {
|
||||||
|
New-Item -Path $path -Force | Out-Null
|
||||||
|
New-ItemProperty -Path $path -Name Enabled -PropertyType DWord -Value 0 -Force | Out-Null
|
||||||
|
New-ItemProperty -Path $path -Name DisabledByDefault -PropertyType DWord -Value 1 -Force | Out-Null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($suite in $cbcSuites) {
|
||||||
|
if ($PSCmdlet.ShouldProcess($suite, 'Disable TLS cipher suite')) {
|
||||||
|
Disable-TlsCipherSuite -Name $suite
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Host 'TLS changes were applied. Restart the TLS termination service or server as appropriate, then run an external scan.'
|
||||||
49
deployment/generate-install-pdfs.py
Normal file
49
deployment/generate-install-pdfs.py
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
"""Render the installation handbooks from their Markdown sources using Chrome."""
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
from html import escape
|
||||||
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
import markdown
|
||||||
|
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parent
|
||||||
|
CHROME = Path(r"C:\Program Files\Google\Chrome\Application\chrome.exe")
|
||||||
|
if not CHROME.exists():
|
||||||
|
CHROME = Path(r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe")
|
||||||
|
|
||||||
|
|
||||||
|
def render(source: str, destination: str) -> None:
|
||||||
|
body = (ROOT / source).read_text(encoding="utf-8")
|
||||||
|
content = markdown.markdown(body, extensions=["fenced_code", "tables"])
|
||||||
|
html = f"""<!doctype html><html lang="fa" dir="rtl"><head><meta charset="utf-8">
|
||||||
|
<title>{escape(destination)}</title><style>
|
||||||
|
@page {{ size: A4; margin: 16mm 16mm 18mm; }}
|
||||||
|
body {{ font-family: Tahoma, Arial, sans-serif; font-size: 10.5pt; line-height: 1.8; color: #20242a; }}
|
||||||
|
h1 {{ font-size: 18pt; margin: 0 0 14pt; }}
|
||||||
|
h2 {{ font-size: 13pt; margin: 16pt 0 6pt; break-after: avoid; }}
|
||||||
|
p, li {{ text-align: right; }}
|
||||||
|
ul {{ padding-right: 22pt; }}
|
||||||
|
pre {{ direction: ltr; text-align: left; background: #f3f5f7; border: 1px solid #dce0e3;
|
||||||
|
padding: 8pt; white-space: pre-wrap; overflow-wrap: anywhere; font: 8.5pt Consolas, monospace; }}
|
||||||
|
code {{ direction: ltr; unicode-bidi: isolate; font-family: Consolas, monospace; font-size: 9pt; }}
|
||||||
|
pre code {{ font-size: inherit; }}
|
||||||
|
h1, h2, pre {{ break-inside: avoid; }}
|
||||||
|
</style></head><body>{content}</body></html>"""
|
||||||
|
with tempfile.TemporaryDirectory() as temp:
|
||||||
|
page = Path(temp) / "guide.html"
|
||||||
|
page.write_text(html, encoding="utf-8")
|
||||||
|
output = ROOT / destination
|
||||||
|
command = [str(CHROME), "--headless", "--disable-gpu", "--no-first-run",
|
||||||
|
"--no-default-browser-check", "--disable-extensions", "--no-pdf-header-footer",
|
||||||
|
f"--user-data-dir={Path(temp) / 'profile'}", f"--print-to-pdf={output}", page.as_uri()]
|
||||||
|
subprocess.run(command, check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
if not output.is_file() or output.stat().st_size < 1000:
|
||||||
|
raise RuntimeError(f"PDF was not created: {output}")
|
||||||
|
print(output)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
render("INSTALL.md", "INSTALL.pdf")
|
||||||
|
render("INSTALL-INTERNAL.md", "INSTALL-INTERNAL.pdf")
|
||||||
52
deployment/initialize-admin.ps1
Normal file
52
deployment/initialize-admin.ps1
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[string]$UserName,
|
||||||
|
[string]$DisplayName = 'مدیر سامانه'
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
$setup = Join-Path $PSScriptRoot 'tools\Inogen.Setup\Inogen.Setup.exe'
|
||||||
|
if (-not (Test-Path -LiteralPath $setup)) { throw 'The customer setup tool is missing.' }
|
||||||
|
if ([string]::IsNullOrWhiteSpace($UserName)) {
|
||||||
|
$bytes = New-Object byte[] 4
|
||||||
|
$random = [Security.Cryptography.RandomNumberGenerator]::Create()
|
||||||
|
try { $random.GetBytes($bytes) } finally { $random.Dispose() }
|
||||||
|
$UserName = 'admin-' + [BitConverter]::ToString($bytes).Replace('-', '').ToLowerInvariant()
|
||||||
|
}
|
||||||
|
if ($UserName -notmatch '^[A-Za-z0-9._-]{5,64}$') {
|
||||||
|
throw 'User name must contain 5-64 Latin letters, digits, dots, underscores or hyphens.'
|
||||||
|
}
|
||||||
|
if ([string]::IsNullOrWhiteSpace($env:INOGEN_TARGET_CONNECTION)) {
|
||||||
|
throw 'Set the private target connection and target allowlist before creating the administrator.'
|
||||||
|
}
|
||||||
|
|
||||||
|
function To-PlainText([Security.SecureString]$secret) {
|
||||||
|
$pointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secret)
|
||||||
|
try { [Runtime.InteropServices.Marshal]::PtrToStringBSTR($pointer) }
|
||||||
|
finally { [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($pointer) }
|
||||||
|
}
|
||||||
|
|
||||||
|
$password = To-PlainText (Read-Host 'Administrator password' -AsSecureString)
|
||||||
|
$confirmation = To-PlainText (Read-Host 'Confirm administrator password' -AsSecureString)
|
||||||
|
if ($password -cne $confirmation) {
|
||||||
|
$password = $null
|
||||||
|
$confirmation = $null
|
||||||
|
throw 'Passwords do not match.'
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$env:INOGEN_BOOTSTRAP_ADMIN_USER = $UserName
|
||||||
|
$env:INOGEN_BOOTSTRAP_ADMIN_DISPLAY_NAME = $DisplayName
|
||||||
|
$env:INOGEN_BOOTSTRAP_ADMIN_PASSWORD = $password
|
||||||
|
& $setup provision-admin
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw 'Administrator creation failed.' }
|
||||||
|
Write-Host "Administrator user name for handover: $UserName"
|
||||||
|
Write-Host 'Deliver the password through a separate secure channel; it is not stored in the package.'
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Remove-Item Env:INOGEN_BOOTSTRAP_ADMIN_USER -ErrorAction SilentlyContinue
|
||||||
|
Remove-Item Env:INOGEN_BOOTSTRAP_ADMIN_DISPLAY_NAME -ErrorAction SilentlyContinue
|
||||||
|
Remove-Item Env:INOGEN_BOOTSTRAP_ADMIN_PASSWORD -ErrorAction SilentlyContinue
|
||||||
|
$password = $null
|
||||||
|
$confirmation = $null
|
||||||
|
}
|
||||||
58
deployment/migrate-target.ps1
Normal file
58
deployment/migrate-target.ps1
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$SqlUser,
|
||||||
|
[switch]$TrustServerCertificate,
|
||||||
|
[switch]$ConfigureOnly
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
$settingsPath = Join-Path $PSScriptRoot 'backend\appsettings.Production.json'
|
||||||
|
$setupPath = Join-Path $PSScriptRoot 'tools\Inogen.Setup\Inogen.Setup.exe'
|
||||||
|
if (-not (Test-Path -LiteralPath $settingsPath -PathType Leaf) -or
|
||||||
|
-not (Test-Path -LiteralPath $setupPath -PathType Leaf)) {
|
||||||
|
throw 'Run this script from the extracted package that contains backend and tools/Inogen.Setup.'
|
||||||
|
}
|
||||||
|
|
||||||
|
$settings = Get-Content -LiteralPath $settingsPath -Raw | ConvertFrom-Json
|
||||||
|
$servers = @($settings.TargetDatabaseGuard.AllowedServers)
|
||||||
|
$databases = @($settings.TargetDatabaseGuard.AllowedDatabases)
|
||||||
|
if ($servers.Count -ne 1 -or $databases.Count -ne 1 -or
|
||||||
|
[string]::IsNullOrWhiteSpace($servers[0]) -or [string]::IsNullOrWhiteSpace($databases[0])) {
|
||||||
|
throw 'Set exactly one target server and database in backend/appsettings.Production.json.'
|
||||||
|
}
|
||||||
|
|
||||||
|
$secret = Read-Host 'SQL migration password' -AsSecureString
|
||||||
|
$pointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secret)
|
||||||
|
try { $plainPassword = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($pointer) }
|
||||||
|
finally { [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($pointer) }
|
||||||
|
|
||||||
|
try {
|
||||||
|
$builder = New-Object System.Data.SqlClient.SqlConnectionStringBuilder
|
||||||
|
$builder['Data Source'] = [string]$servers[0]
|
||||||
|
$builder['Initial Catalog'] = [string]$databases[0]
|
||||||
|
$builder['User ID'] = $SqlUser
|
||||||
|
$builder['Password'] = $plainPassword
|
||||||
|
$builder['Encrypt'] = $true
|
||||||
|
$builder['TrustServerCertificate'] = [bool]$TrustServerCertificate
|
||||||
|
$env:INOGEN_TARGET_CONNECTION = $builder.ConnectionString
|
||||||
|
$env:INOGEN_TARGET_ALLOWED_SERVER = [string]$servers[0]
|
||||||
|
$env:INOGEN_TARGET_ALLOWED_DATABASE = [string]$databases[0]
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
$plainPassword = $null
|
||||||
|
$secret = $null
|
||||||
|
$builder = $null
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Target: $($servers[0])/$($databases[0])"
|
||||||
|
& $setupPath verify-target
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw 'Target verification failed; migration was not started.' }
|
||||||
|
if ($ConfigureOnly) {
|
||||||
|
Write-Host 'Target connection is ready in this PowerShell session; migration was not run.'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
& $setupPath list-migrations
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw 'No database migrations were discovered; migration was not started.' }
|
||||||
|
& $setupPath migrate-target
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw 'Target migration failed.' }
|
||||||
|
Write-Host 'Keep this PowerShell session open until the administrator account is created.'
|
||||||
62
deployment/prepare-transfer-connections.ps1
Normal file
62
deployment/prepare-transfer-connections.ps1
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$SourceServer,
|
||||||
|
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$SourceDatabase,
|
||||||
|
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$SourceUser,
|
||||||
|
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$TargetUser,
|
||||||
|
[switch]$TrustSourceCertificate,
|
||||||
|
[switch]$TrustTargetCertificate
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
$settings = Get-Content -LiteralPath (Join-Path $PSScriptRoot 'backend\appsettings.Production.json') -Raw | ConvertFrom-Json
|
||||||
|
$servers = @($settings.TargetDatabaseGuard.AllowedServers)
|
||||||
|
$databases = @($settings.TargetDatabaseGuard.AllowedDatabases)
|
||||||
|
if ($servers.Count -ne 1 -or $databases.Count -ne 1 -or
|
||||||
|
[string]::IsNullOrWhiteSpace($servers[0]) -or [string]::IsNullOrWhiteSpace($databases[0])) {
|
||||||
|
throw 'Set exactly one target server and database in backend/appsettings.Production.json.'
|
||||||
|
}
|
||||||
|
if ($SourceServer -ieq $servers[0] -and $SourceDatabase -ieq $databases[0]) {
|
||||||
|
throw 'Source and destination must be different databases.'
|
||||||
|
}
|
||||||
|
|
||||||
|
function Read-SqlPassword([string]$prompt) {
|
||||||
|
$secret = Read-Host $prompt -AsSecureString
|
||||||
|
$pointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secret)
|
||||||
|
try { [Runtime.InteropServices.Marshal]::PtrToStringBSTR($pointer) }
|
||||||
|
finally {
|
||||||
|
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($pointer)
|
||||||
|
$secret = $null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sourcePassword = Read-SqlPassword 'Old database password'
|
||||||
|
try {
|
||||||
|
$source = New-Object System.Data.SqlClient.SqlConnectionStringBuilder
|
||||||
|
$source['Data Source'] = $SourceServer
|
||||||
|
$source['Initial Catalog'] = $SourceDatabase
|
||||||
|
$source['User ID'] = $SourceUser
|
||||||
|
$source['Password'] = $sourcePassword
|
||||||
|
$source['ApplicationIntent'] = 'ReadOnly'
|
||||||
|
$source['Encrypt'] = $true
|
||||||
|
$source['TrustServerCertificate'] = [bool]$TrustSourceCertificate
|
||||||
|
$env:INOGEN_SOURCE_READONLY_CONNECTION = $source.ConnectionString
|
||||||
|
}
|
||||||
|
finally { $sourcePassword = $null; $source = $null }
|
||||||
|
|
||||||
|
$targetPassword = Read-SqlPassword 'New database password'
|
||||||
|
try {
|
||||||
|
$target = New-Object System.Data.SqlClient.SqlConnectionStringBuilder
|
||||||
|
$target['Data Source'] = [string]$servers[0]
|
||||||
|
$target['Initial Catalog'] = [string]$databases[0]
|
||||||
|
$target['User ID'] = $TargetUser
|
||||||
|
$target['Password'] = $targetPassword
|
||||||
|
$target['Encrypt'] = $true
|
||||||
|
$target['TrustServerCertificate'] = [bool]$TrustTargetCertificate
|
||||||
|
$env:ConnectionStrings__TargetDatabase = $target.ConnectionString
|
||||||
|
}
|
||||||
|
finally { $targetPassword = $null; $target = $null }
|
||||||
|
|
||||||
|
Write-Host "Source: $SourceServer/$SourceDatabase"
|
||||||
|
Write-Host "Target: $($servers[0])/$($databases[0])"
|
||||||
|
Write-Host 'Both connections are ready in this PowerShell session.'
|
||||||
80
deployment/select-internal-transfer.ps1
Normal file
80
deployment/select-internal-transfer.ps1
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)][ValidateSet('verify-source', 'preview-source', 'import-source')][string]$Command,
|
||||||
|
[string]$SourceDatabase,
|
||||||
|
[string]$SourceServer,
|
||||||
|
[string]$IdempotencyKey
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
$settingsPath = Join-Path $PSScriptRoot 'backend\appsettings.Production.json'
|
||||||
|
$transfer = Join-Path $PSScriptRoot 'tools\Inogen.DataTransfer\Inogen.DataTransfer.exe'
|
||||||
|
if (-not (Test-Path -LiteralPath $settingsPath) -or -not (Test-Path -LiteralPath $transfer)) {
|
||||||
|
throw 'This command requires the internal package and its Production configuration.'
|
||||||
|
}
|
||||||
|
|
||||||
|
$settings = Get-Content -LiteralPath $settingsPath -Raw | ConvertFrom-Json
|
||||||
|
$targetServer = @($settings.TargetDatabaseGuard.AllowedServers)
|
||||||
|
$targetDatabase = @($settings.TargetDatabaseGuard.AllowedDatabases)
|
||||||
|
if ($targetServer.Count -ne 1 -or $targetDatabase.Count -ne 1 -or
|
||||||
|
[string]::IsNullOrWhiteSpace($targetServer[0]) -or [string]::IsNullOrWhiteSpace($targetDatabase[0])) {
|
||||||
|
throw 'Configure exactly one target server and database in backend/appsettings.Production.json.'
|
||||||
|
}
|
||||||
|
|
||||||
|
# The private runtime connection is the same destination selected for customer installation.
|
||||||
|
$targetConnection = $env:ConnectionStrings__TargetDatabase
|
||||||
|
if ([string]::IsNullOrWhiteSpace($targetConnection)) {
|
||||||
|
throw 'Set the private ConnectionStrings__TargetDatabase environment variable for this installation.'
|
||||||
|
}
|
||||||
|
$target = New-Object System.Data.SqlClient.SqlConnectionStringBuilder($targetConnection)
|
||||||
|
if ($target.DataSource -ine $targetServer[0] -or $target.InitialCatalog -ine $targetDatabase[0]) {
|
||||||
|
throw 'The configured runtime connection and target allowlist refer to different databases.'
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([string]::IsNullOrWhiteSpace($SourceServer)) { $SourceServer = Read-Host 'Exact old SQL Server name' }
|
||||||
|
if ([string]::IsNullOrWhiteSpace($SourceDatabase)) { $SourceDatabase = Read-Host 'Exact old database name' }
|
||||||
|
if ([string]::IsNullOrWhiteSpace($SourceServer) -or [string]::IsNullOrWhiteSpace($SourceDatabase)) {
|
||||||
|
throw 'Source server and database names are required.'
|
||||||
|
}
|
||||||
|
if ($SourceServer -ieq $targetServer[0] -and $SourceDatabase -ieq $targetDatabase[0]) {
|
||||||
|
throw 'Source and destination must be different databases.'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Credentials are supplied privately; only the exact operator-selected source is accepted.
|
||||||
|
$sourceConnection = $env:INOGEN_SOURCE_READONLY_CONNECTION
|
||||||
|
if ([string]::IsNullOrWhiteSpace($sourceConnection)) {
|
||||||
|
throw 'Set INOGEN_SOURCE_READONLY_CONNECTION with ApplicationIntent=ReadOnly before running.'
|
||||||
|
}
|
||||||
|
$source = New-Object System.Data.SqlClient.SqlConnectionStringBuilder($sourceConnection)
|
||||||
|
if ($source.DataSource -ine $SourceServer -or $source.InitialCatalog -ine $SourceDatabase -or
|
||||||
|
$source.ApplicationIntent -ne [System.Data.SqlClient.ApplicationIntent]::ReadOnly) {
|
||||||
|
throw 'Source connection must match the entered server/database and use ApplicationIntent=ReadOnly.'
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($Command -eq 'import-source') {
|
||||||
|
if ([string]::IsNullOrWhiteSpace($IdempotencyKey)) {
|
||||||
|
throw 'Supply an IdempotencyKey after reviewing the source preview.'
|
||||||
|
}
|
||||||
|
$selection = Read-Host "Import from '$SourceServer/$SourceDatabase' to '$($targetServer[0])/$($targetDatabase[0])'? Type the source database name"
|
||||||
|
if ($selection -cne $SourceDatabase) { throw 'Source confirmation did not match; import stopped.' }
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$env:INOGEN_TARGET_CONNECTION = $targetConnection
|
||||||
|
$env:INOGEN_TARGET_ALLOWED_SERVER = $targetServer[0]
|
||||||
|
$env:INOGEN_TARGET_ALLOWED_DATABASE = $targetDatabase[0]
|
||||||
|
$env:INOGEN_SOURCE_ALLOWED_SERVER = $SourceServer
|
||||||
|
$env:INOGEN_SOURCE_ALLOWED_DATABASE = $SourceDatabase
|
||||||
|
if ($Command -eq 'import-source') { $env:INOGEN_MIGRATION_IDEMPOTENCY_KEY = $IdempotencyKey }
|
||||||
|
Write-Host "Source: $SourceServer/$SourceDatabase"
|
||||||
|
Write-Host "Target: $($targetServer[0])/$($targetDatabase[0])"
|
||||||
|
& $transfer $Command
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw "$Command failed; no other source was selected." }
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
foreach ($name in @('INOGEN_TARGET_CONNECTION', 'INOGEN_TARGET_ALLOWED_SERVER',
|
||||||
|
'INOGEN_TARGET_ALLOWED_DATABASE', 'INOGEN_SOURCE_ALLOWED_SERVER',
|
||||||
|
'INOGEN_SOURCE_ALLOWED_DATABASE', 'INOGEN_MIGRATION_IDEMPOTENCY_KEY')) {
|
||||||
|
Remove-Item "Env:$name" -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
}
|
||||||
54
deployment/set-iis-runtime-connection.ps1
Normal file
54
deployment/set-iis-runtime-connection.ps1
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]$SqlUser,
|
||||||
|
[ValidatePattern('^[A-Za-z0-9._-]{3,80}$')][string]$AppPoolName = 'Inogen-Api',
|
||||||
|
[switch]$TrustServerCertificate
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
Import-Module WebAdministration -ErrorAction Stop
|
||||||
|
if (-not (Test-Path "IIS:\AppPools\$AppPoolName")) { throw "IIS App Pool not found: $AppPoolName" }
|
||||||
|
$settingsPath = Join-Path $PSScriptRoot 'backend\appsettings.Production.json'
|
||||||
|
$settings = Get-Content -LiteralPath $settingsPath -Raw | ConvertFrom-Json
|
||||||
|
$servers = @($settings.TargetDatabaseGuard.AllowedServers)
|
||||||
|
$databases = @($settings.TargetDatabaseGuard.AllowedDatabases)
|
||||||
|
if ($servers.Count -ne 1 -or $databases.Count -ne 1 -or
|
||||||
|
[string]::IsNullOrWhiteSpace($servers[0]) -or [string]::IsNullOrWhiteSpace($databases[0])) {
|
||||||
|
throw 'Set exactly one target server and database in backend/appsettings.Production.json.'
|
||||||
|
}
|
||||||
|
|
||||||
|
$secret = Read-Host 'SQL runtime password' -AsSecureString
|
||||||
|
$pointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secret)
|
||||||
|
try { $plainPassword = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($pointer) }
|
||||||
|
finally { [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($pointer) }
|
||||||
|
try {
|
||||||
|
$builder = New-Object System.Data.SqlClient.SqlConnectionStringBuilder
|
||||||
|
$builder['Data Source'] = [string]$servers[0]
|
||||||
|
$builder['Initial Catalog'] = [string]$databases[0]
|
||||||
|
$builder['User ID'] = $SqlUser
|
||||||
|
$builder['Password'] = $plainPassword
|
||||||
|
$builder['Encrypt'] = $true
|
||||||
|
$builder['TrustServerCertificate'] = [bool]$TrustServerCertificate
|
||||||
|
$connection = $builder.ConnectionString
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
$plainPassword = $null
|
||||||
|
$secret = $null
|
||||||
|
$builder = $null
|
||||||
|
}
|
||||||
|
|
||||||
|
$baseFilter = "system.applicationHost/applicationPools/add[@name='$AppPoolName']/environmentVariables"
|
||||||
|
$itemFilter = "$baseFilter/add[@name='ConnectionStrings__TargetDatabase']"
|
||||||
|
$existing = Get-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter $itemFilter `
|
||||||
|
-Name 'value' -ErrorAction SilentlyContinue
|
||||||
|
if ($null -eq $existing) {
|
||||||
|
Add-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter $baseFilter `
|
||||||
|
-Name '.' -Value @{ name = 'ConnectionStrings__TargetDatabase'; value = $connection }
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Set-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter $itemFilter `
|
||||||
|
-Name 'value' -Value $connection
|
||||||
|
}
|
||||||
|
$connection = $null
|
||||||
|
Restart-WebAppPool -Name $AppPoolName
|
||||||
|
Write-Host "Runtime SQL connection was saved for IIS App Pool $AppPoolName."
|
||||||
17
deployment/verify-public-security.ps1
Normal file
17
deployment/verify-public-security.ps1
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory = $true)][uri]$FrontendUrl,
|
||||||
|
[Parameter(Mandatory = $true)][uri]$ApiUrl
|
||||||
|
)
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
foreach ($url in @($FrontendUrl, $ApiUrl)) {
|
||||||
|
if ($url.Scheme -ne 'https') { throw "HTTPS URL required: $url" }
|
||||||
|
$response = Invoke-WebRequest -Uri $url -Method Get -MaximumRedirection 0 -UseBasicParsing
|
||||||
|
$hsts = $response.Headers['Strict-Transport-Security']
|
||||||
|
if ([string]::IsNullOrWhiteSpace($hsts) -or $hsts -notmatch 'max-age=\d+') {
|
||||||
|
throw "HSTS missing or invalid: $url"
|
||||||
|
}
|
||||||
|
Write-Host "HSTS verified: $($url.Host)"
|
||||||
|
}
|
||||||
|
Write-Host 'HSTS checks passed. TLS protocol and cipher suite checks require an external TLS scanner against both public hosts.'
|
||||||
46
deployment/verify-runtime-sql-permissions.ps1
Normal file
46
deployment/verify-runtime-sql-permissions.ps1
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
[CmdletBinding()]
|
||||||
|
param()
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
$connectionString = $env:INOGEN_RUNTIME_CONNECTION
|
||||||
|
$allowedServer = $env:INOGEN_TARGET_ALLOWED_SERVER
|
||||||
|
$allowedDatabase = $env:INOGEN_TARGET_ALLOWED_DATABASE
|
||||||
|
if ([string]::IsNullOrWhiteSpace($connectionString) -or
|
||||||
|
[string]::IsNullOrWhiteSpace($allowedServer) -or
|
||||||
|
[string]::IsNullOrWhiteSpace($allowedDatabase)) {
|
||||||
|
throw 'Set INOGEN_RUNTIME_CONNECTION and the explicit target server/database allowlist.'
|
||||||
|
}
|
||||||
|
$builder = New-Object System.Data.SqlClient.SqlConnectionStringBuilder($connectionString)
|
||||||
|
if ($builder.DataSource -ne $allowedServer -or $builder.InitialCatalog -ne $allowedDatabase -or
|
||||||
|
$builder.InitialCatalog -match 'APADANA-IATM|NOPC') {
|
||||||
|
throw 'Runtime connection does not match the approved target.'
|
||||||
|
}
|
||||||
|
|
||||||
|
$connection = New-Object System.Data.SqlClient.SqlConnection($connectionString)
|
||||||
|
try {
|
||||||
|
$connection.Open()
|
||||||
|
$command = $connection.CreateCommand()
|
||||||
|
$command.CommandText = @'
|
||||||
|
SELECT
|
||||||
|
ISNULL(IS_SRVROLEMEMBER('sysadmin'), 0),
|
||||||
|
ISNULL(IS_MEMBER('db_owner'), 0),
|
||||||
|
ISNULL(HAS_PERMS_BY_NAME('inogen', 'SCHEMA', 'ALTER'), 0),
|
||||||
|
ISNULL(HAS_PERMS_BY_NAME('inogen', 'SCHEMA', 'SELECT'), 0),
|
||||||
|
ISNULL(HAS_PERMS_BY_NAME('inogen', 'SCHEMA', 'INSERT'), 0),
|
||||||
|
ISNULL(HAS_PERMS_BY_NAME('inogen', 'SCHEMA', 'UPDATE'), 0),
|
||||||
|
ISNULL(HAS_PERMS_BY_NAME('inogen', 'SCHEMA', 'DELETE'), 0)
|
||||||
|
'@
|
||||||
|
$reader = $command.ExecuteReader()
|
||||||
|
try {
|
||||||
|
if (-not $reader.Read()) { throw 'SQL permission probe returned no data.' }
|
||||||
|
if ($reader.GetInt32(0) -ne 0 -or $reader.GetInt32(1) -ne 0 -or $reader.GetInt32(2) -ne 0) {
|
||||||
|
throw 'Runtime SQL principal has an excessive privilege.'
|
||||||
|
}
|
||||||
|
foreach ($index in 3..6) {
|
||||||
|
if ($reader.GetInt32($index) -ne 1) { throw 'Runtime SQL principal lacks a required data permission.' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally { $reader.Dispose() }
|
||||||
|
Write-Host 'Runtime SQL principal has the expected data permissions without sysadmin, db_owner or schema ALTER.'
|
||||||
|
}
|
||||||
|
finally { $connection.Dispose() }
|
||||||
|
|
@ -45,6 +45,7 @@
|
||||||
<add name="Referrer-Policy" value="strict-origin-when-cross-origin" />
|
<add name="Referrer-Policy" value="strict-origin-when-cross-origin" />
|
||||||
<add name="Permissions-Policy" value="camera=(), microphone=(), geolocation=()" />
|
<add name="Permissions-Policy" value="camera=(), microphone=(), geolocation=()" />
|
||||||
<add name="X-Frame-Options" value="SAMEORIGIN" />
|
<add name="X-Frame-Options" value="SAMEORIGIN" />
|
||||||
|
<add name="Strict-Transport-Security" value="max-age=2592000" />
|
||||||
</customHeaders>
|
</customHeaders>
|
||||||
</httpProtocol>
|
</httpProtocol>
|
||||||
<staticContent>
|
<staticContent>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user