403Webshell
Server IP : 217.160.0.244  /  Your IP : 216.73.216.25
Web Server : Apache
System : Linux infong-eu155 4.4.400-icpu-108 #2 SMP Wed Feb 11 11:51:01 UTC 2026 x86_64
User : u100174116 ( 6746176)
PHP Version : 8.5.10
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /homepages/13/d818981593/htdocs/GutTrechowNeu/assets/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /homepages/13/d818981593/htdocs/GutTrechowNeu/assets/js/api.js
/**
 * Gut Trechow – Frontend API
 * Nutzt api.php wenn vorhanden, sonst localStorage als Fallback
 */
;(function(w){'use strict';

  /* ── API-URL berechnen ── */
  function apiURL(){
    var tags=document.querySelectorAll('script[src]');
    for(var i=0;i<tags.length;i++){
      var s=tags[i].getAttribute('src')||'';
      if(s.indexOf('assets/js/api.js')!==-1)
        return s.replace('assets/js/api.js','api.php');
    }
    return '/api.php';
  }

  /* ── Session (nur sessionStorage, kein Cookie) ── */
  var SK='gt_sess';
  function tok(){return sessionStorage.getItem(SK)||'';}
  function setTok(t){if(t)sessionStorage.setItem(SK,t);else sessionStorage.removeItem(SK);}

  /* ── HTTP-Request ── */
  function req(action,method,body,auth,extra){
    var url=apiURL()+'?action='+action+(extra||'');
    var h={'Content-Type':'application/json'};
    if(auth)h['X-GT-Session']=tok();
    var o={method:method||'GET',headers:h};
    if(body!==undefined&&method!=='GET')o.body=JSON.stringify(body);
    return fetch(url,o).then(function(r){
      return r.json().then(function(d){
        if(!d.ok){var e=new Error(d.error||'HTTP '+r.status);e.status=r.status;throw e;}
        return d.data;
      });
    });
  }


  function canUseLocalFallback(err){
    return !err || typeof err.status === 'undefined';
  }

  /* ── localStorage-Fallback-Helpers ── */
  function lsGet(k,def){try{var v=JSON.parse(localStorage.getItem('gt_'+k));return v!==null?v:def;}catch(e){return def;}}
  function lsSet(k,v){try{localStorage.setItem('gt_'+k,JSON.stringify(v));}catch(e){}}

  /* ── Verfügbarkeit testen (cached) ── */
  var _avail=null; // null=ungetestet, true/false
  function checkAvail(){
    if(_avail!==null)return Promise.resolve(_avail);
    return fetch(apiURL()+'?action=check',{method:'GET',headers:{'Content-Type':'application/json'}})
      .then(function(r){return r.json();})
      .then(function(d){_avail=!!(d&&d.ok!==undefined);return _avail;})
      .catch(function(){_avail=false;return false;});
  }

  /* ── Upload ── */
  function upload(file){
    var fd=new FormData();fd.append('file',file);
    return fetch(apiURL()+'?action=upload',{method:'POST',headers:{'X-GT-Session':tok()},body:fd})
      .then(function(r){return r.json();})
      .then(function(d){if(!d.ok)throw new Error(d.error||'Upload fehlgeschlagen');return d.data;});
  }

  w.GT={
    SEED_ENTRIES:[],
    isConfigured:function(){return true;},

    /* ── Auth ── */
    login:function(u,p){
      return req('login','POST',{user:u,pass:p})
        .then(function(d){setTok(d.token);_avail=true;return d;})
        .catch(function(e){
          /* Fallback: lokales Login wenn api.php nicht erreichbar */
          if(e.status===401)throw e; // Echtes falsches Passwort
          var lu=lsGet('admin_user','admin'),lp=lsGet('admin_pass','trechow2024');
          if(u===lu&&p===lp){setTok('local_session');_avail=false;return{token:'local_session',user:u};}
          throw new Error('Benutzername oder Passwort falsch.');
        });
    },
    logout:function(){setTok(null);return req('logout','POST',{},false).catch(function(){});},
    checkAuth:function(){
      var t=tok();
      if(!t)return Promise.resolve({ok:false});
      if(t==='local_session')return Promise.resolve({ok:true,user:lsGet('admin_user','admin')});
      return req('check','GET',undefined,true).catch(function(){setTok(null);return{ok:false};});
    },
    changePassword:function(np){
      if(tok()==='local_session'){
        var c=lsGet('admin_user','admin');
        lsSet('admin_pass',np);
        return Promise.resolve();
      }
      return req('change_password','POST',{new_pass:np},true);
    },

    /* ── Wartungsmodus ── */
    getMaintenance:function(){
      return req('maintenance','GET')
        .then(function(d){return!!(d&&d.active);})
        .catch(function(){return lsGet('maintenance',false);});
    },
    setMaintenance:function(a){
      lsSet('maintenance',!!a); // immer lokal merken als Fallback
      return req('maintenance','POST',{active:!!a},true)
        .then(function(d){return!!(d&&d.active);})
        .catch(function(){return!!a;});
    },

    /* ── Gästebuch öffentlich ── */
    getPublicEntries:function(){
      var lsApproved = lsGet('gb_approved',[]);
      return req('guestbook','GET')
        .then(function(e){
          if(!Array.isArray(e)) e=[];
          // Merge server entries with localStorage entries (avoid duplicates by id)
          var serverIds={};
          e.forEach(function(x){serverIds[x.id]=true;});
          lsApproved.forEach(function(x){if(!serverIds[x.id])e.push(x);});
          e.sort(function(a,b){return new Date(b.date)-new Date(a.date);}); 
          return e;
        })
        .catch(function(){
          // Fallback: only localStorage
          lsApproved.sort(function(a,b){return new Date(b.date)-new Date(a.date);});
          return lsApproved;
        });
    },
    submitEntry:function(entry){
      entry.name=String(entry.name||'').trim();
      entry.context=String(entry.context||'').trim();
      entry.message=String(entry.message||'').trim();
      if(entry.name.length<2) return Promise.reject(new Error('Name zu kurz.'));
      if(entry.message.length<5) return Promise.reject(new Error('Nachricht zu kurz.'));
      entry.date=new Date().toISOString();
      entry.id='gb-'+Date.now();
      entry.approved=false;
      var pending=lsGet('gb_pending',[]);
      pending.unshift(entry);lsSet('gb_pending',pending);
      return req('guestbook','POST',entry)
        .catch(function(err){ if(!canUseLocalFallback(err)) throw err; return{id:entry.id}; });
    },
    getAllEntries:function(){
      var lsPending  = lsGet('gb_pending',[]);
      var lsApproved = lsGet('gb_approved',[]);
      return req('guestbook_admin','GET',undefined,true)
        .then(function(d){
          var serverPnd = d.pending||[];
          var serverApr = d.approved||[];
          // Merge localStorage entries not yet on server
          var serverIds={};
          serverPnd.concat(serverApr).forEach(function(x){serverIds[x.id]=true;});
          lsPending.forEach(function(x){if(!serverIds[x.id])serverPnd.push(x);});
          lsApproved.forEach(function(x){if(!serverIds[x.id])serverApr.push(x);});
          return{pending:serverPnd,approved:serverApr};
        })
        .catch(function(){
          return{pending:lsPending,approved:lsApproved};
        });
    },
    approveEntry:function(id){
      var pending=lsGet('gb_pending',[]);
      var approved=lsGet('gb_approved',[]);
      for(var i=0;i<pending.length;i++) if(pending[i].id===id){var e=pending.splice(i,1)[0];e.approved=true;approved.unshift(e);break;}
      lsSet('gb_pending',pending);lsSet('gb_approved',approved);
      return req('approve','POST',{},true,'&id='+encodeURIComponent(id))
        .catch(function(){return null;});
    },
    deleteEntry:function(id){
      lsSet('gb_pending',(lsGet('gb_pending',[])).filter(function(e){return e.id!==id;}));
      lsSet('gb_approved',(lsGet('gb_approved',[])).filter(function(e){return e.id!==id;}));
      return req('delete_entry','DELETE',undefined,true,'&id='+encodeURIComponent(id))
        .catch(function(){return null;});
    },
    getPage:function(slug){
      return req('get_page','GET',undefined,false,'&slug='+encodeURIComponent(slug))
        .catch(function(e){if(!canUseLocalFallback(e)) throw e; return lsGet('page_'+slug.replace(/\//g,'_'),null);});
    },
    savePage:function(slug,title,content,meta,hero,blocks){
      lsSet('page_'+slug.replace(/\//g,'_'),{title:title,content:content,meta:meta||{},hero:hero||{},blocks:blocks||[],updated:new Date().toISOString()});
      return req('save_page','POST',{slug:slug,title:title,content:content,meta:meta||{},hero:hero||{},blocks:blocks||[]},true)
        .catch(function(e){if(!canUseLocalFallback(e)) throw e; return null;}); // localStorage already saved
    },
    getAllPages:function(){
      return req('get_all_pages','GET',undefined,true)
        .catch(function(e){if(!canUseLocalFallback(e)) throw e; return{};});
    },

    /* ── Veranstaltungen ── */
    getEvents:function(){
      var lsEvs = lsGet('events',[]);
      return req('get_events','GET')
        .then(function(e){
          if(!Array.isArray(e)) e=[];
          // Merge: localStorage events that aren't on server yet
          var serverIds={};
          e.forEach(function(x){serverIds[x.id]=true;});
          lsEvs.forEach(function(x){if(!serverIds[x.id])e.push(x);});
          e.sort(function(a,b){return (a.date||'').localeCompare(b.date||'');});
          return e;
        })
        .catch(function(){
          lsEvs.sort(function(a,b){return (a.date||'').localeCompare(b.date||'');});
          return lsEvs;
        });
    },
    saveEvent:function(ev){
      if(!ev.id) ev.id='ev-'+Date.now();
      var evs=lsGet('events',[]);
      var found=false;
      for(var i=0;i<evs.length;i++) if(evs[i].id===ev.id){evs[i]=ev;found=true;break;}
      if(!found) evs.push(ev);
      lsSet('events',evs);
      return req('save_event','POST',ev,true)
        .catch(function(err){ if(!canUseLocalFallback(err)) throw err; return ev; });
    },
    deleteEvent:function(id){
      lsSet('events',(lsGet('events',[])).filter(function(e){return e.id!==id;}));
      return req('delete_event','DELETE',undefined,true,'&id='+encodeURIComponent(id))
        .catch(function(err){ if(!canUseLocalFallback(err)) throw err; return null; });
    },

Youez - 2016 - github.com/yon3zu
LinuXploit