1.0.53 • Published 7 months ago

mayohr-auto-punch v1.0.53

Weekly downloads
-
License
-
Repository
-
Last release
7 months ago

mayohr-auto-punch

Automatic punch in/out system for mayohr

Requirements

  • Node.js 16+

Usage

Create a .env file

Create a .env file with your credentials:

# Download the .env.example file:
mkdir -p ~/.mayohr-auto-punch \
  && wget -O ~/.mayohr-auto-punch/.env \
  https://raw.githubusercontent.com/awesome-oa-tools/mayohr-auto-punch/main/.env.example

# Update the .env file with your credentials:
vi ~/.mayohr-auto-punch/.env

Run the script

npx --yes --quite mayohr-auto-punch@latest

Run the script with Crontab

# Download the crontab config
mkdir -p ~/.mayohr-auto-punch/crontab && \
  wget -O ~/.mayohr-auto-punch/crontab/mayohr-auto-punch.sh \
    https://raw.githubusercontent.com/awesome-oa-tools/mayohr-auto-punch/main/examples/crontab/mayohr-auto-punch.sh && \
  chmod +x ~/.mayohr-auto-punch/crontab/mayohr-auto-punch.sh && \
  wget -O ~/.mayohr-auto-punch/crontab/mayohr \
    https://raw.githubusercontent.com/awesome-oa-tools/mayohr-auto-punch/main/examples/crontab/mayohr

# Add to existing crontab (this will merge with your existing crontab entries)
crontab -l | cat - ~/.mayohr-auto-punch/crontab/mayohr | crontab -

# Verify the crontab settings
crontab -l

# To remove crontab, run crontab -e

Run the script with PM2

# Install PM2
npm i -g pm2

# Download the pm2 configs:
wget -O ~/.mayohr-auto-punch/ecosystem.config.js \
  https://raw.githubusercontent.com/awesome-oa-tools/mayohr-auto-punch/main/examples/pm2/ecosystem.config.js

# Start the script with PM2:
pm2 start ~/.mayohr-auto-punch/ecosystem.config.js \
  && pm2 stop mayohr-morning-punch mayohr-evening-punch

Run the script with Docker

docker run --rm -it \
  -v $HOME/.mayohr-auto-punch:/home/pptruser/.mayohr-auto-punch \
  justintw/mayohr-auto-punch:latest

Run the script with AWS Lambda

# Download the AWS template
mkdir -p ~/.mayohr-auto-punch/aws \
  && wget -O ~/.mayohr-auto-punch/aws/ecr-template.yaml \
  https://raw.githubusercontent.com/awesome-oa-tools/mayohr-auto-punch/main/examples/aws/ecr-template.yaml \
  && wget -O ~/.mayohr-auto-punch/aws/lambda-template.yaml \
  https://raw.githubusercontent.com/awesome-oa-tools/mayohr-auto-punch/main/examples/aws/lambda-template.yaml

source ~/.mayohr-auto-punch/.env

# Create SSM parameters for sensitive data
aws ssm put-parameter \
  --no-cli-pager \
  --region ap-northeast-1 \
  --name "/mayohr-auto-punch/ms-password" \
  --value "${MS_PASSWORD}" \
  --type "SecureString" \
  --overwrite

aws ssm put-parameter \
  --no-cli-pager \
  --region ap-northeast-1 \
  --name "/mayohr-auto-punch/ms-totp-secret" \
  --value "${MS_TOPT_SECRET}" \
  --type "SecureString" \
  --overwrite

aws ssm put-parameter \
  --no-cli-pager \
  --region ap-northeast-1 \
  --name "/mayohr-auto-punch/telegram-bot-token" \
  --value "${TELEGRAM_BOT_TOKEN}" \
  --type "SecureString" \
  --overwrite

# Create the ecr stack
aws cloudformation create-stack \
  --no-cli-pager \
  --region ap-northeast-1 \
  --stack-name mayohr-auto-punch-ecr \
  --template-body file://~/.mayohr-auto-punch/aws/ecr-template.yaml

# Get ECR URI
ECR_URI=$(aws cloudformation describe-stacks \
  --no-cli-pager \
  --region ap-northeast-1 \
  --stack-name mayohr-auto-punch-ecr \
  --query "Stacks[0].Outputs[?OutputKey=='RepositoryUri'].OutputValue" \
  --output text)

# Login to ECR
aws ecr get-login-password \
  --no-cli-pager \
  --region ap-northeast-1 \
  | docker login \
    --username AWS \
    --password-stdin \
    ${ECR_URI}

# Push the image to ECR
docker pull --platform linux/amd64 justintw/mayohr-auto-punch:latest \
  && docker tag justintw/mayohr-auto-punch:latest ${ECR_URI}:latest \
  && docker push ${ECR_URI}:latest

# Create the stack
aws cloudformation create-stack \
  --no-cli-pager \
  --region ap-northeast-1 \
  --stack-name mayohr-auto-punch-lambda \
  --template-body file://~/.mayohr-auto-punch/aws/lambda-template.yaml \
  --parameters \
    ParameterKey=ImageUri,ParameterValue=${ECR_URI}:latest \
    ParameterKey=MsDomain,ParameterValue=${MS_DOMAIN} \
    ParameterKey=MsUsername,ParameterValue=${MS_USERNAME} \
    ParameterKey=TelegramEnabled,ParameterValue=${TELEGRAM_ENABLED} \
    ParameterKey=TelegramChatId,ParameterValue=${TELEGRAM_CHAT_ID} \
  --capabilities CAPABILITY_IAM

Telegram Notification (Optional)

To enable Telegram notifications:

  1. Create a Telegram bot through @BotFather
  2. Create a Telegram Channel and add the bot to it as an admin
  3. Get Channel ID from https://api.telegram.org/bot<bot_token>/getUpdates
  4. Add the following to your ~/.mayohr-auto-punch/.env file:
TELEGRAM_ENABLED="true"
TELEGRAM_BOT_TOKEN="your_bot_token"
TELEGRAM_CHAT_ID="your_chat_id"
1.0.53

7 months ago

1.0.52

8 months ago

1.0.51

8 months ago

1.0.50

9 months ago

1.0.49

9 months ago

1.0.47

9 months ago

1.0.46

9 months ago

1.0.45

9 months ago

1.0.44

9 months ago

1.0.43

9 months ago

1.0.42

9 months ago

1.0.41

9 months ago

1.0.40

9 months ago

1.0.39

9 months ago

1.0.38

9 months ago

1.0.37

9 months ago

1.0.36

9 months ago

1.0.35

9 months ago

1.0.34

9 months ago

1.0.33

9 months ago

1.0.32

9 months ago

1.0.31

9 months ago

1.0.30

9 months ago

1.0.29

9 months ago

1.0.28

9 months ago

1.0.27

9 months ago

1.0.26

9 months ago

1.0.25

9 months ago

1.0.24

9 months ago

1.0.23

10 months ago

1.0.22

10 months ago

1.0.21

10 months ago

1.0.20

10 months ago

1.0.19

10 months ago

1.0.18

10 months ago

1.0.17

10 months ago

1.0.15

10 months ago

1.0.13

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago