Skip to content

Commit

Permalink
🎉 Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kdevo committed Feb 18, 2020
1 parent 3ad7e65 commit 028c1a3
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 276 deletions.
Binary file added .github/copy-curl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
280 changes: 4 additions & 276 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,276 +1,4 @@
## Core latex/pdflatex auxiliary files:
*.aux
*.lof
*.log
*.lot
*.fls
*.out
*.toc
*.fmt
*.fot
*.cb
*.cb2
.*.lb

## Intermediate documents:
*.dvi
*.xdv
*-converted-to.*
# these rules might exclude image files for figures etc.
# *.ps
# *.eps
# *.pdf

## Generated if empty string is given at "Please type another file name for output:"
.pdf

## Bibliography auxiliary files (bibtex/biblatex/biber):
*.bbl
*.bcf
*.blg
*-blx.aux
*-blx.bib
*.run.xml

## Build tool auxiliary files:
*.fdb_latexmk
*.synctex
*.synctex(busy)
*.synctex.gz
*.synctex.gz(busy)
*.pdfsync

## Build tool directories for auxiliary files
# latexrun
latex.out/

## Auxiliary and intermediate files from other packages:
# algorithms
*.alg
*.loa

# achemso
acs-*.bib

# amsthm
*.thm

# beamer
*.nav
*.pre
*.snm
*.vrb

# changes
*.soc

# comment
*.cut

# cprotect
*.cpt

# elsarticle (documentclass of Elsevier journals)
*.spl

# endnotes
*.ent

# fixme
*.lox

# feynmf/feynmp
*.mf
*.mp
*.t[1-9]
*.t[1-9][0-9]
*.tfm

#(r)(e)ledmac/(r)(e)ledpar
*.end
*.?end
*.[1-9]
*.[1-9][0-9]
*.[1-9][0-9][0-9]
*.[1-9]R
*.[1-9][0-9]R
*.[1-9][0-9][0-9]R
*.eledsec[1-9]
*.eledsec[1-9]R
*.eledsec[1-9][0-9]
*.eledsec[1-9][0-9]R
*.eledsec[1-9][0-9][0-9]
*.eledsec[1-9][0-9][0-9]R

# glossaries
*.acn
*.acr
*.glg
*.glo
*.gls
*.glsdefs
*.lzo
*.lzs

# uncomment this for glossaries-extra (will ignore makeindex's style files!)
# *.ist

# gnuplottex
*-gnuplottex-*

# gregoriotex
*.gaux
*.gtex

# htlatex
*.4ct
*.4tc
*.idv
*.lg
*.trc
*.xref

# hyperref
*.brf

# knitr
*-concordance.tex
# TODO Comment the next line if you want to keep your tikz graphics files
*.tikz
*-tikzDictionary

# listings
*.lol

# luatexja-ruby
*.ltjruby

# makeidx
*.idx
*.ilg
*.ind

# minitoc
*.maf
*.mlf
*.mlt
*.mtc[0-9]*
*.slf[0-9]*
*.slt[0-9]*
*.stc[0-9]*

# minted
_minted*
*.pyg

# morewrites
*.mw

# nomencl
*.nlg
*.nlo
*.nls

# pax
*.pax

# pdfpcnotes
*.pdfpc

# sagetex
*.sagetex.sage
*.sagetex.py
*.sagetex.scmd

# scrwfile
*.wrt

# sympy
*.sout
*.sympy
sympy-plots-for-*.tex/

# pdfcomment
*.upa
*.upb

# pythontex
*.pytxcode
pythontex-files-*/

# tcolorbox
*.listing

# thmtools
*.loe

# TikZ & PGF
*.dpth
*.md5
*.auxlock

# todonotes
*.tdo

# vhistory
*.hst
*.ver

# easy-todo
*.lod

# xcolor
*.xcp

# xmpincl
*.xmpi

# xindy
*.xdy

# xypic precompiled matrices and outlines
*.xyc
*.xyd

# endfloat
*.ttt
*.fff

# Latexian
TSWLatexianTemp*

## Editors:
# WinEdt
*.bak
*.sav

# Texpad
.texpadtmp

# LyX
*.lyx~

# Kile
*.backup

# gummi
.*.swp

# KBibTeX
*~[0-9]*

# TeXnicCenter
*.tps

# auto folder when using emacs and auctex
./auto/*
*.el

# expex forward references with \gathertags
*-tags.tex

# standalone packages
*.sta

# Makeindex log files
*.lpz
github-project/
overleaf-project/
overleaf-project.zip
my-copied-curl.sh
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Overleaf Synchronizer

This is extremely minimalistic one-hour PoC bash script that fetches your project's ZIP from Overleaf and pushes it to your GitHub repository.

## *The *Why* and the *How*

I wanted to learn something about *replaying logins* and *CSRF* in the real world, so I checked if and how my favorite LaTeX IDE Overleaf is using it (properly).
And yes, it is. During the login process itself, a `_csrf` field is submitted in the JSON request payload.

For other actions, a valid session cookie is required.
We can replay this cookie (as long as it's session is active) and utilize this to fetch the ZIP without requiring Overleaf to offer a public API for it. I do not think that this is reliable, but wanted to share my result anyway.

## Instructions

Currently, this project only supports the (more difficult to set-up and maintain) private projects.

### Private Project

#### 1. Retrieve valid session cookie

1. Open up Chrome (or similar Chromium-based browser such as Brave)
2. Login and go to the Overleaf project that you want to synchronize
3. Copy URL and append a `/download/zip` to your project URL, e.g. `https://www.overleaf.com/project/1234567890abcdefdeadb33f/download/zip`
4. Open a new tab, press F12 and go to "Network" dev tools tab
5. Enter URL constructed in step #3
6. Under "Network" dev tools tab and then "Copy as cURL (bash)" as shown in the screenshot below

![.github/copy-curl.png](.github/copy-curl.png)

#### 2. Configure this project

1. Clone this project
2. Put your copied cURL from the step before inside `your-copied-curl.sh`
3. Edit `sync.sh` and configure your `GIT_URL` at the top of the script
4. Call `./sync.sh`
5. Optional: Set-up cron job or similar that calls this script regularly (e.g. hourly)

### Public Project

Maybe coming soon, maybe not.
29 changes: 29 additions & 0 deletions sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

GIT_URL="CONFIGURE ME"

set -e

if [[ "${GIT_URL}" =~ ^.+git$ ]]; then
echo "GIT_URL: ${GIT_URL}"
else
echo "Please enter a valid GIT_URL (ending with .git)"
exit 1
fi

./your-copied-curl.sh > overleaf-project.zip

unzip -o overleaf-project.zip -d overleaf-project/
if [[ -d github-project/ ]]; then
echo "No need to clone: Directory github-project already exists."
echo "If you want to change your GitHub repo, call './wipe.sh' before executing this script."
else
git clone "${GIT_URL}" github-project/
fi

cd github-project
git pull
cp -rf ../overleaf-project/* .
git add .
git commit -m ":twisted_rightwards_arrows: Sync with overleaf project"
git push
4 changes: 4 additions & 0 deletions wipe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

rm -rf overleaf-project/
rm -rf github-project/
2 changes: 2 additions & 0 deletions your-copied-curl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Put the copied cURL string in bash format as described in README and replace the line below with it:
echo -e "ATTENTION: Please configure as described in the README and remove this line">&2 && exit 1

0 comments on commit 028c1a3

Please sign in to comment.