Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MetaGer Keymanager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
MetaGer Keymanager
Commits
06b52c97
Commit
06b52c97
authored
2 years ago
by
Dominik Hebeler
Browse files
Options
Downloads
Patches
Plain Diff
key is now stored with correct expiration
parent
2e6fb121
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pass/routes/key.js
+55
-57
55 additions, 57 deletions
pass/routes/key.js
with
55 additions
and
57 deletions
pass/routes/key.js
+
55
−
57
View file @
06b52c97
var
express
=
require
(
"
express
"
);
var
router
=
express
.
Router
();
var
multer
=
require
(
"
multer
"
);
const
{
param
,
validationResult
,
}
=
require
(
"
express-validator
"
);
const
{
param
,
validationResult
}
=
require
(
"
express-validator
"
);
const
config
=
require
(
"
config
"
);
var
orderRouter
=
require
(
"
./orders/orders
"
);
...
...
@@ -30,7 +27,7 @@ router.get("/remove", (req, res) => {
router
.
get
(
"
/enter
"
,
function
(
req
,
res
,
next
)
{
if
(
req
.
cookies
.
key
)
{
Key
.
GET_KEY
(
req
.
cookies
.
key
,
false
).
then
(
key
=>
{
Key
.
GET_KEY
(
req
.
cookies
.
key
,
false
).
then
(
(
key
)
=>
{
res
.
redirect
(
`
${
res
.
locals
.
baseDir
}
/key/`
+
encodeURIComponent
(
key
.
get_key
())
);
...
...
@@ -49,56 +46,50 @@ const upload = multer({
fields
:
1
,
},
});
router
.
post
(
"
/enter
"
,
upload
.
single
(
"
file
"
),
async
(
req
,
res
,
next
)
=>
{
/** @type {Key} */
let
key
=
null
;
if
(
typeof
req
.
body
.
key
===
"
string
"
&&
req
.
body
.
key
.
length
>
0
)
{
key
=
await
Key
.
GET_KEY
(
req
.
body
.
key
.
trim
()).
then
((
key
)
=>
key
.
get_key
())
}
if
(
key
!==
null
)
{
res
.
redirect
(
`
${
res
.
locals
.
baseDir
}
/key/`
+
key
);
}
else
if
(
typeof
req
.
file
===
"
undefined
"
)
{
res
.
render
(
"
login/key
"
,
{
errors
:
"
File not provided or invalid
"
});
}
else
{
const
jimp
=
require
(
"
jimp
"
);
router
.
post
(
"
/enter
"
,
upload
.
single
(
"
file
"
),
async
(
req
,
res
,
next
)
=>
{
/** @type {Key} */
let
key
=
null
;
if
(
typeof
req
.
body
.
key
===
"
string
"
&&
req
.
body
.
key
.
length
>
0
)
{
key
=
await
Key
.
GET_KEY
(
req
.
body
.
key
.
trim
()).
then
((
key
)
=>
key
.
get_key
());
}
jimp
.
read
(
req
.
file
.
buffer
,
(
err
,
image
)
=>
{
if
(
key
!==
null
)
{
res
.
redirect
(
`
${
res
.
locals
.
baseDir
}
/key/`
+
key
);
}
else
if
(
typeof
req
.
file
===
"
undefined
"
)
{
res
.
render
(
"
login/key
"
,
{
errors
:
"
File not provided or invalid
"
});
}
else
{
const
jimp
=
require
(
"
jimp
"
);
jimp
.
read
(
req
.
file
.
buffer
,
(
err
,
image
)
=>
{
if
(
err
)
{
res
.
render
(
"
login/key
"
,
{
errors
:
[
"
Error reading image data
"
]
});
return
;
}
const
QrCode
=
require
(
"
qrcode-reader
"
);
let
qr
=
new
QrCode
();
qr
.
callback
=
(
err
,
value
)
=>
{
if
(
err
)
{
res
.
render
(
"
login/key
"
,
{
errors
:
[
"
Error
rea
ding
image data
"
]
});
res
.
render
(
"
login/key
"
,
{
errors
:
[
"
Error
deco
ding
QR
"
]
});
return
;
}
const
QrCode
=
require
(
"
qrcode-reader
"
);
let
qr
=
new
QrCode
();
qr
.
callback
=
(
err
,
value
)
=>
{
if
(
err
)
{
res
.
render
(
"
login/key
"
,
{
errors
:
[
"
Error decoding QR
"
]
});
return
;
}
let
url
;
try
{
url
=
new
URL
(
value
.
result
);
}
catch
(
err
)
{
res
.
render
(
"
login/key
"
,
{
errors
:
[
"
Error parsing URL
"
]
});
return
;
}
let
key
=
url
.
searchParams
.
get
(
"
key
"
);
if
(
key
!==
null
)
{
res
.
redirect
(
`
${
res
.
locals
.
baseDir
}
/key/`
+
encodeURIComponent
(
key
)
);
}
else
{
res
.
render
(
"
login/key
"
,
{
errors
:
[
"
Error parsing URL
"
]
});
}
};
qr
.
decode
(
image
.
bitmap
);
});
}
let
url
;
try
{
url
=
new
URL
(
value
.
result
);
}
catch
(
err
)
{
res
.
render
(
"
login/key
"
,
{
errors
:
[
"
Error parsing URL
"
]
});
return
;
}
let
key
=
url
.
searchParams
.
get
(
"
key
"
);
if
(
key
!==
null
)
{
res
.
redirect
(
`
${
res
.
locals
.
baseDir
}
/key/`
+
encodeURIComponent
(
key
));
}
else
{
res
.
render
(
"
login/key
"
,
{
errors
:
[
"
Error parsing URL
"
]
});
}
};
qr
.
decode
(
image
.
bitmap
);
});
}
);
}
);
router
.
use
(
"
/:key
"
,
param
(
"
key
"
).
isUUID
(
4
),
async
(
req
,
res
,
next
)
=>
{
// Input Validation
...
...
@@ -107,20 +98,23 @@ router.use("/:key", param("key").isUUID(4), async (req, res, next) => {
return
res
.
status
(
400
).
json
({
errors
:
errors
.
array
()
});
}
let
metager_url
=
"
https://metager.de/meta/settings/load-settings?
"
;
let
metager_url
=
"
https://metager.de/meta/settings/load-settings?
"
;
let
params
=
{
key
:
req
.
params
.
key
}
key
:
req
.
params
.
key
,
}
;
for
(
let
cookie
in
req
.
cookies
)
{
if
(
cookie
.
match
(
/^
(
dark_mode$|new_tab$|zitate$|web_|bilder_|produkte_|nachrichten_|science_
)
/
))
{
if
(
cookie
.
match
(
/^
(
dark_mode$|new_tab$|zitate$|web_|bilder_|produkte_|nachrichten_|science_
)
/
)
)
{
params
[
cookie
]
=
req
.
cookies
[
cookie
];
}
}
metager_url
+=
(
new
URLSearchParams
(
params
)
)
.
toString
();
metager_url
+=
new
URLSearchParams
(
params
).
toString
();
let
QRCode
=
require
(
"
qrcode
"
);
...
...
@@ -162,6 +156,7 @@ router.get("/:key", async (req, res) => {
)
{
res
.
cookie
(
"
key
"
,
req
.
data
.
key
.
key
.
get_key
(),
{
sameSite
:
"
lax
"
,
maxAge
:
5
*
365
*
24
*
60
*
60
*
1000
,
// Store for 5 years
});
}
res
.
render
(
"
key
"
,
req
.
data
);
...
...
@@ -228,7 +223,10 @@ router.use("/:key/checkout/:amount?/:payment_source", (req, res, next) => {
router
.
use
(
"
/:key/checkout/:amount?/paypal
"
,
checkout_router_paypal
);
router
.
use
(
"
/:key/checkout/:amount?/manual
"
,
checkout_router_manual
);
router
.
use
(
"
/:key/checkout/:amount?/micropayment
"
,
checkout_router_micropayment
);
router
.
use
(
"
/:key/checkout/:amount?/micropayment
"
,
checkout_router_micropayment
);
router
.
use
(
"
/:key/checkout/:amount?/cash
"
,
checkout_router_cash
);
module
.
exports
=
router
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment