Commit 7745ecf7 authored by Lakr Aream's avatar Lakr Aream 👼🏽

存档

parent 02a708b4
......@@ -155,14 +155,15 @@ echo $signStr;
- User type: root(unique), admin, developer, user
```
SQL TABLE CONTENT
----------users----------
id: int(11), not null, auto_increment,
name: string 255 char long
icon: string, 20000 char long base64encoded
-------------------------
TABLE `Candiay`.`users` (
`name` varchar(255) NOT NULL,
`pass` varchar(255) NULL,
`token` varchar(255) NULL,
`guard` date NULL,
`actived` int(1) NULL DEFAULT 1,
`info` json NULL,
PRIMARY KEY (`name`)
);
```
<details>
......
......@@ -14,7 +14,7 @@ export class ConfigManager {
public portToBind: number
public rootTicket: string | null
public accpetAddr: string[]
public requireSign: boolean
public noSign: boolean
constructor() {
console.log("ConfigManager constructor")
......@@ -26,7 +26,7 @@ export class ConfigManager {
this.rootTicket = null
}
this.accpetAddr = this.object.app.accpet
this.requireSign = this.object.app.use_development_ticket
this.noSign = this.object.app.use_development_ticket
}
healthCheck() {
......
import express from "express"
import { ConfigManager } from "./config"
import { DataBase } from "./database"
import { DataBase } from "./mysql"
import { StatusManager } from "./status"
import { RequestManager } from "./request"
ConfigManager.shared.healthCheck()
DataBase.shared.healthCheck()
......@@ -13,13 +14,23 @@ const port = ConfigManager.shared.portToBind
coreApp.get("/", (req, res) => {
if (!StatusManager.shared.configSuccessed) {
res.send("Application in configuration")
res.status(502).send("Application in configuration")
return
}
res.send("Candiay Core Bootstrap Succeed")
})
coreApp.get("/users/c", (req, res) => {
if (!StatusManager.shared.configSuccessed) {
res.status(502).send("Application in configuration")
return
}
RequestManager.shared.performSelectorUserManagementRequest(req, res, (code, context) => {
res.status(code).send(context)
})
})
// Start servers
coreApp.listen(port, err => {
if (err) {
......
......@@ -118,4 +118,39 @@ export class DataBase {
})
}
public queryWithCommand(cmd: string, callback: (err: any, result: any) => void) {
this.connection.query(cmd, (err: { message: any }, result: any) => {
if (err) {
console.log('[SQL ERROR] - ',err.message)
}
console.log('--------------------------SQL----------------------------')
console.log(cmd)
console.log(result)
console.log('---------------------------------------------------------')
if (err) {
callback(err, undefined)
} else {
callback(err, result)
}
})
}
public readObjectsFromTable(table: string, callback: (err: any, result: any) => void) {
const cmd = "SELECT * FROM `" + this.base + "`.`" + table + "`"
this.connection.query(cmd, (err: { message: any }, result: any) => {
if (err) {
console.log('[SQL ERROR] - ',err.message)
}
console.log('--------------------------SQL----------------------------')
console.log(cmd)
console.log(result)
console.log('---------------------------------------------------------')
if (err) {
callback(err, undefined)
} else {
callback(err, result)
}
})
}
}
\ No newline at end of file
import { ConfigManager } from "./config"
import { UserManager } from "./users"
export class RequestManager {
static shared = new RequestManager()
public vaildateRequest(headers: object, params: object, from: string, callback: (isVaildated: boolean) => void) {
// if (ConfigManager.shared.noSign) {
// return true
// }
const clientSignResult = headers["x-candiay-sign"]
if (clientSignResult === "" || clientSignResult === undefined || clientSignResult === null) {
callback(false)
}
let signString = ""
Object.keys(params).sort().forEach((key) => {
signString += key
signString += "="
signString += params[key]
signString += "&"
})
// tslint:disable-next-line: no-string-literal
let fromUserSName = params["from"]
if (fromUserSName === "" || fromUserSName === undefined || fromUserSName === null) {
fromUserSName = "root"
}
UserManager.shared.readTokenFromUser(fromUserSName, (token) => {
if (token === "" || token === null || token === undefined) {
callback(false)
} else {
}
})
}
public performSelectorUserManagementRequest(req: any, res: any, recall: (code: number, context: any) => void ) {
const headers: object = req.headers
const params: object = req.query
const from: string = req.host
this.vaildateRequest(headers, params, from, (vaildated) => {
console.log("-------------------REQUEST-------------------");
console.log((new Date()))
console.log(req.url);
if (vaildated) {
console.log("vaildate success");
} else {
console.log("vaildate failed");
}
console.log("---------------------------------------------");
if (!vaildated) {
recall(401, "Signing Invailed!")
return
}
// Doing ~~Steave~~ Jobs
})
}
}
import { DataBase } from "./mysql"
import { ConfigManager } from "./config"
export interface User {
name: string
pass: string
token: string
guard: Date
actived: boolean
info: { [key: string] : string }
}
export class UserManager {
static shared = new UserManager()
private userListCache: User[] | undefined
private userListCacheLastUpdate: number
public readUserList(callback: (users: User[]) => void = null) {
if (this.userListCache === undefined || this.userListCache.length < 1) {
// reload from database
this.userListCacheLastUpdate = -10000
this.reloadUserListFromDataBaseIfNeeded((users) => {
if (callback !== null) {
callback(users)
}
})
}
if (callback !== null) {
callback(this.userListCache)
}
this.reloadUserListFromDataBaseIfNeeded()
}
private async reloadUserListFromDataBaseIfNeeded(callback: ((users: User[]) => void) = null ) {
const gap = (new Date()).getTime() - this.userListCacheLastUpdate
if (gap > 60) {
DataBase.shared.readObjectsFromTable("users", (err: any, ret: any) => {
const obj = Object(ret)
if (err) {
return
}
const ulist: User[] = []
// tslint:disable-next-line: prefer-for-of
for (let index = 0; index < obj.length; index++) {
const element = obj[index];
const u: User = {
name: element.name,
pass: element.pass,
token: element.token,
guard: element.guard,
actived: element.actived,
info: element.info
}
ulist.push(u)
}
this.userListCache = ulist
this.userListCacheLastUpdate = (new Date()).getTime()
if (callback != null) {
callback(ulist)
}
})
}
}
public readTokenFromUser(withName: string, callback: (token: string) => void) {
if (withName === "root") {
callback(ConfigManager.shared.rootTicket)
return
}
this.readUserList((users) => {
// Look for user
// tslint:disable-next-line: prefer-for-of
for (let index = 0; index < this.userListCache.length; index++) {
const element = this.userListCache[index];
if (element.name.toLowerCase() === withName.toLowerCase()) {
// there is a user
callback(element.token)
}
}
// User not exists, do nothing
})
}
}
\ No newline at end of file
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objects = {
/* Begin PBXBuildFile section */
F72F29B4243D750200144AB9 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72F29B3243D750200144AB9 /* main.swift */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
F72F29AE243D750200144AB9 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 1;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
F72F29B0243D750200144AB9 /* test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = test; sourceTree = BUILT_PRODUCTS_DIR; };
F72F29B3243D750200144AB9 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
F72F29AD243D750200144AB9 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
F72F29A7243D750200144AB9 = {
isa = PBXGroup;
children = (
F72F29B2243D750200144AB9 /* test */,
F72F29B1243D750200144AB9 /* Products */,
);
sourceTree = "<group>";
};
F72F29B1243D750200144AB9 /* Products */ = {
isa = PBXGroup;
children = (
F72F29B0243D750200144AB9 /* test */,
);
name = Products;
sourceTree = "<group>";
};
F72F29B2243D750200144AB9 /* test */ = {
isa = PBXGroup;
children = (
F72F29B3243D750200144AB9 /* main.swift */,
);
path = test;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
F72F29AF243D750200144AB9 /* test */ = {
isa = PBXNativeTarget;
buildConfigurationList = F72F29B7243D750200144AB9 /* Build configuration list for PBXNativeTarget "test" */;
buildPhases = (
F72F29AC243D750200144AB9 /* Sources */,
F72F29AD243D750200144AB9 /* Frameworks */,
F72F29AE243D750200144AB9 /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = test;
productName = test;
productReference = F72F29B0243D750200144AB9 /* test */;
productType = "com.apple.product-type.tool";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
F72F29A8243D750200144AB9 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1130;
LastUpgradeCheck = 1130;
ORGANIZATIONNAME = "Lakr Aream";
TargetAttributes = {
F72F29AF243D750200144AB9 = {
CreatedOnToolsVersion = 11.3;
};
};
};
buildConfigurationList = F72F29AB243D750200144AB9 /* Build configuration list for PBXProject "test" */;
compatibilityVersion = "Xcode 9.3";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = F72F29A7243D750200144AB9;
productRefGroup = F72F29B1243D750200144AB9 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
F72F29AF243D750200144AB9 /* test */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
F72F29AC243D750200144AB9 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F72F29B4243D750200144AB9 /* main.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
F72F29B5243D750200144AB9 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
F72F29B6243D750200144AB9 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
};
name = Release;
};
F72F29B8243D750200144AB9 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
F72F29B9243D750200144AB9 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
F72F29AB243D750200144AB9 /* Build configuration list for PBXProject "test" */ = {
isa = XCConfigurationList;
buildConfigurations = (
F72F29B5243D750200144AB9 /* Debug */,
F72F29B6243D750200144AB9 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
F72F29B7243D750200144AB9 /* Build configuration list for PBXNativeTarget "test" */ = {
isa = XCConfigurationList;
buildConfigurations = (
F72F29B8243D750200144AB9 /* Debug */,
F72F29B9243D750200144AB9 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = F72F29A8243D750200144AB9 /* Project object */;
}
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:test.xcodeproj">
</FileRef>
</Workspace>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
//
// main.swift
// test
//
// Created by Lakr Aream on 2020/4/8.
// Copyright © 2020 Lakr Aream. All rights reserved.
//
import Foundation
let url = "127.0.0.1"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment