vps for proxmox init...
This commit is contained in:
parent
5903700260
commit
2329206f94
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,3 +1,6 @@
|
|||||||
|
.env
|
||||||
|
package-lock.json
|
||||||
|
|
||||||
# ---> CodeIgniter
|
# ---> CodeIgniter
|
||||||
*/config/development
|
*/config/development
|
||||||
*/logs/log-*.php
|
*/logs/log-*.php
|
||||||
@ -18,3 +21,5 @@ application/logs/*
|
|||||||
!application/logs/.htaccess
|
!application/logs/.htaccess
|
||||||
/vendor/
|
/vendor/
|
||||||
|
|
||||||
|
#node_modules
|
||||||
|
/node_modules
|
||||||
@ -1,2 +1,7 @@
|
|||||||
# vps
|
# vps
|
||||||
|
|
||||||
|
#실행 전 설치사항
|
||||||
|
npm install express ejs body-parser express-session passport mysql2 uuid bcrypt path express-ejs-layouts
|
||||||
|
|
||||||
|
#실행
|
||||||
|
npm run app.js
|
||||||
38
app.js
Normal file
38
app.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
const path = require('path'); // path 모듈 불러오기
|
||||||
|
const dotenv = require('dotenv');
|
||||||
|
const passport = require('passport');
|
||||||
|
const express = require('express');
|
||||||
|
const session = require('express-session');
|
||||||
|
const bodyParser = require('body-parser');
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
const app = express();
|
||||||
|
// 기본페이지
|
||||||
|
app.set(path.join(__dirname, 'public'));
|
||||||
|
app.set('layout', 'common/layout');
|
||||||
|
app.set('layout extractScripts', true);
|
||||||
|
app.set('view engine', 'ejs');
|
||||||
|
app.set('views', path.join(__dirname, 'views'));
|
||||||
|
|
||||||
|
//Layout 설정
|
||||||
|
app.use(require('express-ejs-layouts'));
|
||||||
|
// ... Passport 설정 및 기타 설정
|
||||||
|
app.use(session({ secret: process.env.SESSION_SECRET, resave: false, saveUninitialized: false }))
|
||||||
|
.use(passport.initialize())
|
||||||
|
.use(passport.session());
|
||||||
|
// Body Parser 미들웨어 설정
|
||||||
|
app.use(bodyParser.urlencoded({ extended: false }))
|
||||||
|
.use(bodyParser.json());
|
||||||
|
// 정적 파일 미들웨어 설정
|
||||||
|
app.use(express.static(path.join(__dirname, 'public')));
|
||||||
|
// 라우팅 설정
|
||||||
|
app.use('/', require('./routes/index'))
|
||||||
|
.use('/user', require('./routes/users'))
|
||||||
|
.use('/auth', require('./routes/auths'))
|
||||||
|
.use('/proxmox/node', require('./routes/proxmox/nodes'));
|
||||||
|
|
||||||
|
// 서버 실행
|
||||||
|
const PORT = process.env.PORT || 3000;
|
||||||
|
app.listen(PORT, () => {
|
||||||
|
console.log(`Server is running on port ${PORT}`);
|
||||||
|
});
|
||||||
31
config/db.js
Normal file
31
config/db.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// config/db.js
|
||||||
|
const mysql = require('mysql2/promise');
|
||||||
|
require('dotenv').config();
|
||||||
|
|
||||||
|
class Database {
|
||||||
|
constructor() {
|
||||||
|
this.pool = mysql.createPool({
|
||||||
|
host: process.env.DB_HOST,
|
||||||
|
user: process.env.DB_USER,
|
||||||
|
password: process.env.DB_PASSWORD,
|
||||||
|
database: process.env.DB_DATABASE,
|
||||||
|
waitForConnections: true,
|
||||||
|
connectionLimit: 10,
|
||||||
|
queueLimit: 0,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async execute(query, values) {
|
||||||
|
const connection = await this.pool.getConnection();
|
||||||
|
try {
|
||||||
|
const [rows] = await connection.execute(query, values);
|
||||||
|
return rows;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
connection.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Database;
|
||||||
21
controllers/authController.js
Normal file
21
controllers/authController.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// controllers/authController.js
|
||||||
|
const express = require('express');
|
||||||
|
const AuthModel = require('../models/authModel');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
class AuthController {
|
||||||
|
async register(req, res) {
|
||||||
|
const { username, password } = req.body;
|
||||||
|
await AuthModel.addAuth(username, password);
|
||||||
|
res.send('사용자 등록 완료');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 로그인 및 로그아웃 등 다른 인증 관련 로직 추가 가능
|
||||||
|
}
|
||||||
|
|
||||||
|
const authController = new AuthController();
|
||||||
|
|
||||||
|
router.post('/register', authController.register.bind(authController));
|
||||||
|
// 다른 인증 관련 라우팅 추가 가능
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
21
controllers/proxmoxController.js
Normal file
21
controllers/proxmoxController.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// controllers/proxmoxController.js
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
class ProxmoxController {
|
||||||
|
constructor() {
|
||||||
|
// Constructor logic if needed
|
||||||
|
}
|
||||||
|
|
||||||
|
getProxmoxData(req, res) {
|
||||||
|
// Proxmox 관련 컨트롤러 로직
|
||||||
|
}
|
||||||
|
|
||||||
|
// 다른 Proxmox API 관련 라우팅 및 로직 추가 가능
|
||||||
|
}
|
||||||
|
|
||||||
|
const proxmoxController = new ProxmoxController();
|
||||||
|
|
||||||
|
router.get('/', proxmoxController.getProxmoxData.bind(proxmoxController));
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
16
controllers/userController.js
Normal file
16
controllers/userController.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// controllers/userController.js
|
||||||
|
const Model = require('../models/userModel');
|
||||||
|
|
||||||
|
class UserController {
|
||||||
|
async getUsers() {
|
||||||
|
var users = [];
|
||||||
|
try {
|
||||||
|
users = await Model.getUsers();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 다른 CURD 기능에 대한 컨트롤러 메소드 구현
|
||||||
|
}
|
||||||
12
entities/authEntity.js
Normal file
12
entities/authEntity.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
// entities/Auth.js
|
||||||
|
class AuthEntity {
|
||||||
|
constructor(uid, id, password, role, status) {
|
||||||
|
this.uid = uid;
|
||||||
|
this.id = id;
|
||||||
|
this.password = password;
|
||||||
|
this.role = role;
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = AuthEntity;
|
||||||
13
entities/userEntity.js
Normal file
13
entities/userEntity.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// entities/User.js
|
||||||
|
class UserEntity {
|
||||||
|
constructor(uid,auth_uid, name, email, address, phone) {
|
||||||
|
this.uid = uid;
|
||||||
|
this.auth_uid = auth_uid;
|
||||||
|
this.name = name;
|
||||||
|
this.email = email;
|
||||||
|
this.address = address;
|
||||||
|
this.phone = phone;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = UserEntity;
|
||||||
30
models/authModel.js
Normal file
30
models/authModel.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// models/authModel.js
|
||||||
|
const Database = require('../config/db');
|
||||||
|
const AuthEntity = require('../entities/authEntity');
|
||||||
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
const bcrypt = require('bcrypt');
|
||||||
|
|
||||||
|
class AuthModel {
|
||||||
|
constructor() {
|
||||||
|
this.db = new Database();
|
||||||
|
}
|
||||||
|
|
||||||
|
async addAuth(id, password, role, status) {
|
||||||
|
const uid = uuidv4();
|
||||||
|
const hashedPassword = await bcrypt.hash(password, 10);
|
||||||
|
const auth = new AuthEntity(uid, id, hashedPassword, role, status);
|
||||||
|
const query = 'INSERT INTO auth (uid, id, password, role, status) VALUES (?, ?, ?, ?, ?)';
|
||||||
|
return await this.db.execute(query, [auth.uid, auth.id, auth.password, auth.role, auth.status]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getAuthById(id, password) {
|
||||||
|
const hashedPassword = await bcrypt.hash(password, 10);
|
||||||
|
const query = 'SELECT * FROM auth WHERE id = ? AND password = ? AND statu = ? ';
|
||||||
|
const auths = await this.db.execute(query, [id,hashedPassword,'use']);
|
||||||
|
return auths[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 다른 인증 관련 메소드 추가 가능
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = new AuthModel();
|
||||||
37
models/userModel.js
Normal file
37
models/userModel.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// models/userModel.js
|
||||||
|
const Database = require('../config/db');
|
||||||
|
const UserEntity = require('../entities/userEntity');
|
||||||
|
|
||||||
|
class UserModel {
|
||||||
|
constructor() {
|
||||||
|
this.db = new Database();
|
||||||
|
}
|
||||||
|
|
||||||
|
async getUsers() {
|
||||||
|
const query = 'SELECT * FROM users';
|
||||||
|
return await this.db.execute(query);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getUserById(uid) {
|
||||||
|
const query = 'SELECT * FROM users WHERE uid = ?';
|
||||||
|
const users = await this.db.execute(query, [uid]);
|
||||||
|
return users[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
async addUser(name, email) {
|
||||||
|
const query = 'INSERT INTO users (name, email) VALUES (?, ?)';
|
||||||
|
return await this.db.execute(query, [name, email]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateUser(uid, name, email) {
|
||||||
|
const query = 'UPDATE users SET name = ?, email = ? WHERE id = ?';
|
||||||
|
return await this.db.execute(query, [name, email, uid]);
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteUser(uid) {
|
||||||
|
const query = 'DELETE FROM users WHERE id = ?';
|
||||||
|
return await this.db.execute(query, [uid]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = new UserModel();
|
||||||
15
package.json
Normal file
15
package.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"bcrypt": "^5.1.1",
|
||||||
|
"body-parser": "^1.20.2",
|
||||||
|
"dotenv": "^16.3.1",
|
||||||
|
"ejs": "^3.1.9",
|
||||||
|
"express": "^4.18.2",
|
||||||
|
"express-ejs-layouts": "^2.5.1",
|
||||||
|
"express-session": "^1.17.3",
|
||||||
|
"mysql2": "^3.6.5",
|
||||||
|
"passport": "^0.7.0",
|
||||||
|
"path": "^0.12.7",
|
||||||
|
"uuid": "^9.0.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
12
public/css/user.css
Normal file
12
public/css/user.css
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-margin {
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
20
routes/auths.js
Normal file
20
routes/auths.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// routes/Auths.js
|
||||||
|
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
router.get('/', (req, res) => {
|
||||||
|
res.render('index', { title: 'Auth List', body: '...' }); // 유저 리스트 페이지
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get('/add', (req, res) => {
|
||||||
|
res.render('addAuth', { title: 'Add Auth', body: '...' }); // 사용자 추가 페이지
|
||||||
|
});
|
||||||
|
|
||||||
|
router.get('/edit/:id', (req, res) => {
|
||||||
|
res.render('editAuth', { title: 'Edit Auth', body: '...', Auth: { id: req.params.id } }); // 사용자 수정 페이지
|
||||||
|
});
|
||||||
|
|
||||||
|
// 나머지 CRUD 라우팅...
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
10
routes/index.js
Normal file
10
routes/index.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// routes/index.js
|
||||||
|
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
router.get('/', (req, res) => {
|
||||||
|
res.render('index',{title: "HOME"});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
13
routes/proxmox/nodes.js
Normal file
13
routes/proxmox/nodes.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// routes/Nodes.js
|
||||||
|
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
router.get('/proxmox/node', (req, res) => {
|
||||||
|
res.render('index', { title: 'Node List', body: '...' }); // 유저 리스트 페이지
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// 나머지 CRUD 라우팅...
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
27
routes/users.js
Normal file
27
routes/users.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// routes/users.js
|
||||||
|
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
// 컨트롤러를 받아오는 부분
|
||||||
|
const Control = require("../controllers/userController");
|
||||||
|
|
||||||
|
// 유저 리스트 페이지
|
||||||
|
router.get('/', (req, res, next) => {
|
||||||
|
res.render('user/index', { title: 'User List', users: Control.getUsers});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 사용자 추가 페이지
|
||||||
|
router.get('/add', (req, res, next) => {
|
||||||
|
res.render('addUser', { title: 'Add User', user: '...' });
|
||||||
|
});
|
||||||
|
router.post('/add', (req, res, next) => {
|
||||||
|
res.render('addUser', { title: 'Add User', user: '...' });
|
||||||
|
});
|
||||||
|
|
||||||
|
// 사용자 수정 페이지
|
||||||
|
router.get('/edit/:id', (req, res, next) => {
|
||||||
|
res.render('editUser', { title: 'Edit User', user: { id: req.params.id } });
|
||||||
|
});
|
||||||
|
|
||||||
|
// 나머지 CRUD 라우팅...
|
||||||
|
module.exports = router;
|
||||||
18
views/common/layout.ejs
Normal file
18
views/common/layout.ejs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<!-- views/common/layout.ejs -->
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="ko">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>VPS Site</title>
|
||||||
|
<link href="/css/user.css" rel="stylesheet">
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="container mt-5">
|
||||||
|
<%- body %>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
5
views/index.ejs
Normal file
5
views/index.ejs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<!-- views/index.ejs -->
|
||||||
|
<h1>Action List</h1>
|
||||||
|
<a href="/auth" class="btn btn-success">Auth List</a>
|
||||||
|
<a href="/user" class="btn btn-success">User List</a>
|
||||||
|
<a href="/proxmox/node" class="btn btn-success">Node List</a>
|
||||||
21
views/user/add.ejs
Normal file
21
views/user/add.ejs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!-- views/addUser.ejs -->
|
||||||
|
<h1>Add User</h1>
|
||||||
|
<form action="/add" method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="fullName" class="form-label">Full Name</label>
|
||||||
|
<input type="text" class="form-control" id="fullName" name="fullName">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="email" class="form-label">Email</label>
|
||||||
|
<input type="email" class="form-control" id="email" name="email">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="address" class="form-label">Address</label>
|
||||||
|
<input type="text" class="form-control" id="address" name="address">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="phone" class="form-label">Phone</label>
|
||||||
|
<input type="text" class="form-control" id="phone" name="phone">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Submit</button>
|
||||||
|
</form>
|
||||||
21
views/user/edit.ejs
Normal file
21
views/user/edit.ejs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<!-- views/editUser.ejs -->
|
||||||
|
<h1>Edit User</h1>
|
||||||
|
<form action="/edit/<%= user.id %>" method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="fullName" class="form-label">Full Name</label>
|
||||||
|
<input type="text" class="form-control" id="fullName" name="fullName" value="<%= user.fullName %>">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="email" class="form-label">Email</label>
|
||||||
|
<input type="email" class="form-control" id="email" name="email" value="<%= user.email %>">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="address" class="form-label">Address</label>
|
||||||
|
<input type="text" class="form-control" id="address" name="address" value="<%= user.address %>">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="phone" class="form-label">Phone</label>
|
||||||
|
<input type="text" class="form-control" id="phone" name="phone" value="<%= user.phone %>">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Update</button>
|
||||||
|
</form>
|
||||||
32
views/user/index.ejs
Normal file
32
views/user/index.ejs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<!-- views/index.ejs -->
|
||||||
|
<h1>User List</h1>
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>UID</th>
|
||||||
|
<th>Auth</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Email</th>
|
||||||
|
<th>Address</th>
|
||||||
|
<th>Phone</th>
|
||||||
|
<th>Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% users.forEach(user => { %>
|
||||||
|
<tr>
|
||||||
|
<td><%= user.uid %></td>
|
||||||
|
<td><%= user.auth_uid %></td>
|
||||||
|
<td><%= user.name %></td>
|
||||||
|
<td><%= user.email %></td>
|
||||||
|
<td><%= user.address %></td>
|
||||||
|
<td><%= user.phone %></td>
|
||||||
|
<td>
|
||||||
|
<a href="/edit/<%= user.id %>" class="btn btn-primary btn-sm">Edit</a>
|
||||||
|
<a href="/delete/<%= user.id %>" class="btn btn-danger btn-sm">Delete</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% }); %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<a href="/add" class="btn btn-success">Add User</a>
|
||||||
Loading…
Reference in New Issue
Block a user