123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- package main
- import (
- "./color"
- "./settings"
- "fmt"
- "html/template"
- "net/http"
- "os"
- "time"
- )
- func indexPage(w http.ResponseWriter, r *http.Request) {
- http.Redirect(w, r, "/plan/", 302)
- }
- func planPage(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path != "/" && r.URL.Path != "/plan/" {
- http.Redirect(w, r, "/404Err", 404)
- return
- }
- t, err := template.ParseFiles(
- HTMLPATH+"index.html",
- NAVPATH,
- HEADPATH,
- )
- if err != nil {
- panic("can't load hmtl files")
- }
- showRequest(r)
- t.Execute(w, nil)
- }
- func loginPage(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path != "/" && r.URL.Path != "/auth/" {
- http.Redirect(w, r, "/404Err", 404)
- return
- }
- t, err := template.ParseFiles(
- HTMLPATH+"login.html",
- HEADPATH,
- )
- if err != nil {
- panic("can't load hmtl files")
- }
- showRequest(r)
- t.Execute(w, nil)
- }
- func specialtyPage(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path != "/" && r.URL.Path != "/specialty/" {
- http.Redirect(w, r, "/404Err", 404)
- return
- }
- t, err := template.ParseFiles(
- HTMLPATH+"specialty.html",
- NAVPATH,
- HEADPATH,
- )
- if err != nil {
- panic("can't load hmtl files")
- }
- showRequest(r)
- t.Execute(w, nil)
- }
- func bellPage(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path != "/" && r.URL.Path != "/bellschedule/" {
- http.Redirect(w, r, "/404Err", 404)
- return
- }
- t, err := template.ParseFiles(
- HTMLPATH+"bellschedule.html",
- NAVPATH,
- HEADPATH,
- )
- if err != nil {
- panic("can't load hmtl files")
- }
- showRequest(r)
- t.Execute(w, nil)
- }
- func schedulePage(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path != "/" && r.URL.Path != "/schedule/" {
- http.Redirect(w, r, "/404Err", 404)
- return
- }
- t, err := template.ParseFiles(
- HTMLPATH+"schedule.html",
- NAVPATH,
- HEADPATH,
- )
- if err != nil {
- panic("can't load hmtl files")
- }
- showRequest(r)
- t.Execute(w, nil)
- }
- func apiPage(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path != "/" && r.URL.Path != "/api/" {
- http.Redirect(w, r, "/404Err", 404)
- return
- }
- t, err := template.ParseFiles(
- HTMLPATH + "api.html",
- )
- if err != nil {
- panic("can't load hmtl files")
- }
- showRequest(r)
- t.Execute(w, nil)
- }
- func subjectPage(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path != "/" && r.URL.Path != "/subject/" {
- http.Redirect(w, r, "/404Err", 404)
- return
- }
- t, err := template.ParseFiles(
- HTMLPATH+"subject.html",
- NAVPATH,
- HEADPATH,
- )
- if err != nil {
- panic("can't load hmtl files")
- }
- showRequest(r)
- t.Execute(w, nil)
- }
- func groupPage(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path != "/group/" {
- http.Redirect(w, r, "/404Err", 404)
- return
- }
- t, err := template.ParseFiles(
- HTMLPATH+"group.html",
- NAVPATH,
- HEADPATH,
- )
- if err != nil {
- panic("can't load hmtl files")
- }
- showRequest(r)
- t.Execute(w, nil)
- }
- func groupCardPage(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path != "/groupcard/" {
- http.Redirect(w, r, "/404Err", 404)
- return
- }
- t, err := template.ParseFiles(
- HTMLPATH+"groupcard.html",
- NAVPATH,
- HEADPATH,
- )
- if err != nil {
- panic("can't load hmtl files")
- }
- showRequest(r)
- t.Execute(w, nil)
- }
- func teacherCardPage(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path != "/teachercard/" {
- http.Redirect(w, r, "/404Err", 404)
- return
- }
- t, err := template.ParseFiles(
- HTMLPATH+"teacherscard.html",
- NAVPATH,
- HEADPATH,
- )
- if err != nil {
- panic("can't load hmtl files")
- }
- showRequest(r)
- t.Execute(w, nil)
- }
- func teacherPage(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path != "/teacher/" {
- return
- }
- t, err := template.ParseFiles(
- HTMLPATH+"teacher.html",
- NAVPATH,
- HEADPATH,
- )
- if err != nil {
- panic("can't load hmtl files")
- }
- showRequest(r)
- t.Execute(w, nil)
- }
- func classroomPage(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path != "/classroom/" {
- return
- }
- t, err := template.ParseFiles(
- HTMLPATH+"classroom.html",
- NAVPATH,
- HEADPATH,
- )
- if err != nil {
- panic("can't load hmtl files")
- }
- showRequest(r)
- t.Execute(w, nil)
- }
- func cyclePage(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path != "/cycle/" {
- http.Redirect(w, r, "/404Err", 404)
- return
- }
- t, err := template.ParseFiles(
- HTMLPATH+"cycle.html",
- NAVPATH,
- HEADPATH,
- )
- if err != nil {
- panic("can't load hmtl files")
- }
- showRequest(r)
- t.Execute(w, nil)
- }
- func showRequest(r *http.Request) {
- t := time.Now()
- fmt.Println("[", t.Format(settings.TimeLayout), "]", color.Blue, "Request", color.Reset, "from", r.RemoteAddr, " to ", r.URL.Path)
- urllog, err := os.OpenFile("log/Requests_URL.log", os.O_APPEND|os.O_WRONLY, 0644)
- if err != nil {
- fmt.Println("[", t.Format(settings.TimeLayout), "]", "Error writing to URL log file")
- }
- s := "[" + t.Format(settings.TimeLayout) + "] " + "Request from " + r.RemoteAddr + " to " + r.URL.Path + "\n"
- _, err = urllog.WriteString(s)
- if err != nil {
- fmt.Println("[", t.Format(settings.TimeLayout), "]", "Error writing to log file")
- }
- }
|