Skip to content

Instantly share code, notes, and snippets.

@muhajirinlpu
Created September 27, 2023 05:13
Show Gist options
  • Save muhajirinlpu/f122cd9d04b5ce5023c3b649e6e33105 to your computer and use it in GitHub Desktop.
Save muhajirinlpu/f122cd9d04b5ce5023c3b649e6e33105 to your computer and use it in GitHub Desktop.
pens autologin

PENS Portal Autologin

This tutorial is assume you're using latest LTS Ubuntu

Preparation

1. Account

Prepare your email and password, and make sure your account is active by manually login into PENS CAS portal. In this tutorial I will use this account below as an example

Email    : is123@is.student.pens.ac.id
Password : w@nderful

Before further proceed, your account need to be encoded into url. You can encode your email and password respectively using this site URL Encode

Email    : is123%40is.student.pens.ac.id
Password : w%40nderful

2. Prepare file

Download file login.sh and change

auth_user=changeme%40is.student.pens.ac.id&auth_pass=changeme

into your own account

auth_user=is123%40is.student.pens.ac.id&auth_pass=w%40nderful

Save login.sh in your home directory ~/.pens/login.sh then add execution permission into login.sh file For example if you want to use command one by one

mkdir -p ~/.pens/login.sh
mv login.sh ~/.pens/login.sh
chmod +x  ~/.pens/login.sh

Testing

  1. Logout your current session account by accessing this link. and click button Disconnect.
  2. Run your script in your terminal bash ~/.pens/login.sh, it should print text Internet not accessible. Logging into CAS...
  3. Check your internet connection, and make sure it's works

Finishing

1. Check Cron

Run sudo systemctl status cron.service and make sure the result is active and enabled

● cron.service - Regular background program processing daemon
     Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-09-20 12:27:35 UTC; 6 days ago
       Docs: man:cron(8)
   Main PID: 3868188 (cron)
      Tasks: 1 (limit: 2220)
     Memory: 7.2M
        CPU: 57.421s
     CGroup: /system.slice/cron.service
             └─3868188 /usr/sbin/cron -f -P

if not, run sudo systemctl enable --now cron.service

2. Add file to cron file

Run crontab -e (if there is an interactive choice, just choose anything you want). Add this line in the bottom of text

* * * * * /home/<your username>/.pens/login.sh

If you're confuse what <your username> is, just run whoami

#!/bin/bash
curl -s https://iac4.pens.ac.id:8009/index.php?zone=misc | grep "value=\"Disconnect\"" 1> /dev/null 2> /dev/null
if [ $? -ne 0 ] ; then
echo `date` "Internet not accessible. Logging into CAS..."
curl -s 'https://iac4.pens.ac.id:8009/index.php?zone=misc' -H 'Content-Type: application/x-www-form-urlencoded' -H 'DNT: 1' -H 'Origin: https://iac4.pens.ac.id:8009' -H 'Referer: https://iac4.pens.ac.id:8009/index.php?zone=misc' -H 'Upgrade-Insecure-Requests: 1' --data-raw 'auth_user=changeme%40is.student.pens.ac.id&auth_pass=changeme&redirurl=&accept=Login' --compressed > /dev/null
else
echo `date` "Internet accessible"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment