1.0.53 • Published 5 months ago

mayohr-auto-punch v1.0.53

Weekly downloads
-
License
-
Repository
-
Last release
5 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

5 months ago

1.0.52

6 months ago

1.0.51

6 months ago

1.0.50

7 months ago

1.0.49

7 months ago

1.0.47

7 months ago

1.0.46

7 months ago

1.0.45

7 months ago

1.0.44

7 months ago

1.0.43

7 months ago

1.0.42

7 months ago

1.0.41

7 months ago

1.0.40

7 months ago

1.0.39

7 months ago

1.0.38

7 months ago

1.0.37

7 months ago

1.0.36

7 months ago

1.0.35

7 months ago

1.0.34

7 months ago

1.0.33

7 months ago

1.0.32

7 months ago

1.0.31

7 months ago

1.0.30

7 months ago

1.0.29

7 months ago

1.0.28

7 months ago

1.0.27

7 months ago

1.0.26

7 months ago

1.0.25

7 months ago

1.0.24

7 months ago

1.0.23

7 months ago

1.0.22

7 months ago

1.0.21

7 months ago

1.0.20

7 months ago

1.0.19

7 months ago

1.0.18

7 months ago

1.0.17

7 months ago

1.0.15

7 months ago

1.0.13

7 months ago

1.0.11

7 months ago

1.0.10

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago