Info Security Memo
  • Blog
  • Sitemap
    • Categories
  • Contact
  • About
  • Resources
  • Tools
  • 51sec.org

Build Confidence

Focusing on Information Security 

Info Security Notes

Deploy OneManager to Heroku and Bypass Free Tier's Restrictions

4/22/2021

0 Comments

 
Deploy OneManager to Heroku and Bypass Free Tier's Restrictions

 I have been introduced a couple ways to display OneDrive's content, either using Cloudflare workers or using Heroku. You can find them from my previous posts:

  • OneManager - Deploy a free OneDrive List App using Heroku and Cloudflare
  • Fast OneDrive Index - A Serverless OneDrive Index Setup

Also I recorded videos to show the whole process:


Deploying OneManager to Heroku is simple and easy but there are two issues which will cause the OneManager will be down. 

  1. New accounts receive 550 free dyno hours and you can verify your identity with a credit card for an additional 450 hours.
  2. The app will be put into idle mode automatically, after 30 minutes of inactivity. It will take 1-2 minutes to wake it up when it receives access activity. 


To resolve those two issues, I developed following three steps to bypass them.

Demo site: https://myod.51sec.eu.org

Deploy Two OneManager into Two Different Heroku Accounts

Lets say, you created two Heroku accounts, and deployed two OneManager apps into them one by one with the process described in my previous post:

  • OneManager - Deploy a free OneDrive List App using Heroku and Cloudflare

You got following two OneManager apps:

  1. https://ift.tt/3sHs0tB
  2. https://ift.tt/2RSZJ6B

They are exactly same except the app name and app url is different. Both apps have added same OneDrive disk in it. 

The logic behind it to use two OneManager apps which not get us exceeding the 550 hours / month limits if we only activate one app every day and keep another one in idle. 


Create a Cloudflare Workers to Rotate Access to Those Two Apps

Now we need to tell CloudFlare Workers to only point to one app at one day and point to anther app at another day. 
Github project: https://github.com/51sec/CF-Herokus/
Basically, this workers code will get Cloudflare route the traffic to myod1 on odd number days and to myod2 on even number days. 

// odd days const SingleDay =
'myod1.herokuapp.com' // plural days const DoubleDay = 'myod2.herokuapp.com' // Using CF to do porxy? true/false const CFproxy = true // Heroku only has 550 hours/month for free plan by default. // This CloudFlare Workers code can let use different Heroku app based on odd or even number's day. // Please change above code for your Heroku's app in either SingleDay or Doubleday parameter. addEventListener('fetch', event => { let nd = new Date(); if (nd.getDate()%2) { host = SingleDay } else { host = DoubleDay } if (!CFproxy) { let url=new URL(event.request.url); if (url.protocol == 'http:') { url.protocol = 'https:' response = Response.redirect(url.href); event.respondWith( response ); } else { url.hostname=host; let request=new Request(url,event.request); event.respondWith( fetch(request) ) } } else { event.respondWith( fetchAndApply(event.request) ); } }) async function fetchAndApply(request) { let response = null; let url = new URL(request.url); if (url.protocol == 'http:') { url.protocol = 'https:' response = Response.redirect(url.href); return response; } url.host = host; let method = request.method; let body = request.body; let request_headers = request.headers; let new_request_headers = new Headers(request_headers); new_request_headers.set('Host', url.host); new_request_headers.set('Referer', request.url); let original_response = await fetch(url.href, { method: method, body: body, headers: new_request_headers }); response = new Response(original_response.body, { status: original_response.status, headers: original_response.headers }) return response; }

Of course, do not forget to set up a DNS A record (myod.51sec.eu.org) and workers route to it.



Create two CRON Job from www.easycron.com

Since Heroku will put your APP in idle mode once there is no activity for 30 minutes, we will just need to create a CRON job to get the site every 30 minutes at www.easycron.com site.  We will need to create two CRON jobs, one for odd number days to get myod1.herokuapp.com, and second one for even number days to get my od2.herokuapp.com.





Done, that is all you will need to set up a OneManager at Heroku, which will make your site up all the time to end user when they using your Cloudflare dns to access your site. 





References

  • Onedrive+OneManager+Heroku+CFWorkers 羊毛衫新织法





via Blogger https://ift.tt/3eiq0mg
April 22, 2021 at 08:39PM Cloud
0 Comments



Leave a Reply.

    Categories

    All
    Architecture
    Blog
    Checkpoint
    Cisco
    Cloud
    CyberArk
    F5
    Fortigate
    Guardium
    Juniper
    Linux
    Network
    Others
    Palo Alto
    Qualys
    Raspberry Pi
    Security
    SIEM
    Software
    Vmware
    VPN
    Wireless

    Archives

    March 2024
    February 2024
    January 2024
    December 2023
    November 2023
    October 2023
    September 2023
    August 2023
    July 2023
    June 2023
    May 2023
    April 2023
    March 2023
    February 2023
    January 2023
    December 2022
    November 2022
    October 2022
    September 2022
    August 2022
    July 2022
    June 2022
    May 2022
    April 2022
    March 2022
    February 2022
    January 2022
    December 2021
    November 2021
    October 2021
    September 2021
    August 2021
    July 2021
    June 2021
    May 2021
    April 2021
    March 2021
    February 2021
    January 2021
    December 2020
    November 2020
    October 2020
    September 2020
    August 2020
    July 2020
    October 2019
    September 2019
    June 2019
    July 2018
    May 2018
    December 2017
    August 2017
    April 2017
    March 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015
    September 2015
    August 2015
    July 2015
    June 2015
    May 2015
    April 2015
    March 2015

    Print Page:

    RSS Feed

    Email Subscribe
Powered by Create your own unique website with customizable templates.
  • Blog
  • Sitemap
    • Categories
  • Contact
  • About
  • Resources
  • Tools
  • 51sec.org