{{ ┌──────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ Autor: Jörg Deckert │ │ Copyright (c) 2014 Jörg Deckert │ │ See end of file for terms of use. │ │ Die Nutzungsbedingungen befinden sich am Ende der Datei │ └──────────────────────────────────────────────────────────────────────────────────────────────────────┘ Informationen : hive-project.de Kontakt : joergd@bitquell.de System : TriOS Name : flash Chip : Regnatix Typ : Programm Version : Subversion : Funktion : Webserver Komponenten : - COG's : - Logbuch : 23.06.2014-joergd - erste Version - Parameter für Benutzer und Paßwort Kommandoliste : Notizen : }} OBJ ios: "reg-ios" gc : "glob-con" str: "glob-string" num: "glob-numbers" CON _CLKMODE = XTAL1 + PLL16X _XINFREQ = 5_000_000 CON 'NVRAM Konstanten -------------------------------------------------------------------------- #4, NVRAM_IPADDR #24, NVRAM_HIVE ' 4 Bytes DAT strNVRAMFile byte "nvram.sav",0 'contains the 56 bytes of NVRAM, if RTC is not available VAR byte handleidx 'Handle web connection byte reqstr[32] ' request string byte webbuff[128] ' incoming header buffer byte rtcAvailable long hiveid long cog, random_value PUB main rr_start ios.start ifnot (ios.admgetspec & gc#A_LAN) ios.sddmset(ios#DM_USER) 'u-marker setzen ios.sddmact(ios#DM_SYSTEM) 's-marker aktivieren ios.admload(string("admnet.adm")) 'versuche, admnet zu laden ios.sddmact(ios#DM_USER) 'u-marker aktivieren ifnot (ios.admgetspec & gc#A_LAN) 'wenn Laden fehlgeschlagen ios.print(@strNoNetwork) ios.stop 'Ende ios.printnl ios.lanstart 'LAN-Treiber initialisieren (eigene IP-Adresse usw. setzen) handleidx := $FF getcfg ios.print(@strMsgEnd) repeat if ios.keystat > 0 ios.key quit if (handleidx := ios.lan_listen(handleidx,80)) <> $FF 'Empfangs-Socket auf Port 80 öffnen if ios.lan_isconnected(handleidx) 'bei bestehender Verbindung... if webThread == 0 ios.lan_txflush(handleidx) ios.lan_close(handleidx) handleidx := $FF ios.stop PRI webThread | i, j, uri, args if webReadLine == 0 ' read the first header, quit if it is empty return 0 bytemove(@reqstr, @webbuff, 32) ' copy the header to a temporary request string for later processing ' obtain get arguments if (i := indexOf(@reqstr, string(".cgi?"))) <> -1 ' was the request for a *.cgi script with arguments? args := @reqstr[i + 5] ' extract the argument if (j := indexOf(args, string("="))) <> -1 ' find the end of the argument byte[args][j] := 0 ' string termination ' read the rest of the headers repeat until webReadLine == 0 ' read the rest of the headers, throwing them away sendStr(string("HTTP/1.0 200 OK",13,10,13,10)) ' print the HTTP header if indexOf(@reqstr, string("ajax.js")) <> -1 ' ajax.js sendStr(@ajaxjs) elseif indexOf(@reqstr, string("rand.cgi")) <> -1 ' rand.cgi sendStr(str.trimCharacters(num.ToStr(long[rr_random_ptr], num#DEC))) elseif indexOf(@reqstr, string("id.cgi")) <> -1 ' id.cgi sendStr(str.trimCharacters(num.ToStr(hiveid, num#DEC))) elseif indexOf(@reqstr, string("img.bin")) <> -1 ' img.bin ios.lan_txdata(handleidx, 0, 32768) else ' default page sendStr(@strDefPage1) sendStr(str.trimCharacters(num.ToStr(hiveid, num#DEC))) sendStr(@strDefPage2) return 0 PRI webReadLine | i, ch repeat i from 0 to 126 ch := ios.lan_rxtime(handleidx, 500) if ch == 13 ch := ios.lan_rxtime(handleidx, 500) if ch == -1 or ch == 10 quit webbuff[i] := ch webbuff[i] := 0 return i PRI sendStr (strSend) : error #ifdef __DEBUG ios.print(string(" > ")) ios.print(strSend) ios.printnl #endif error := ios.lan_txdata(handleidx, strSend, strsize(strSend)) PRI indexOf(haystack, needle) | i, j '' Searches for a 'needle' inside a 'haystack' '' Returns starting index of 'needle' inside 'haystack' repeat i from 0 to strsize(haystack) - strsize(needle) repeat j from 0 to strsize(needle) - 1 if byte[haystack][i + j] <> byte[needle][j] quit if j == strsize(needle) return i return -1 PRI getcfg 'nvram: IP-Konfiguration anzeigen if ios.rtcTest 'RTC chip available? rtcAvailable := TRUE else 'use configfile rtcAvailable := FALSE ios.sddmset(ios#DM_USER) 'u-marker setzen ios.sddmact(ios#DM_SYSTEM) 's-marker aktivieren if ios.sdopen("R",@strNVRAMFile) ios.print(@strErrorOpen) ios.sddmact(ios#DM_USER) 'u-marker aktivieren return ios.print(@strAddr) listaddr(NVRAM_IPADDR) ios.printnl if rtcAvailable hiveid := ios.getNVSRAM(NVRAM_HIVE) hiveid += ios.getNVSRAM(NVRAM_HIVE+1) << 8 hiveid += ios.getNVSRAM(NVRAM_HIVE+2) << 16 hiveid += ios.getNVSRAM(NVRAM_HIVE+3) << 24 else ios.sdseek(NVRAM_HIVE) hiveid := ios.sdgetc hiveid += ios.sdgetc << 8 hiveid += ios.sdgetc << 16 hiveid += ios.sdgetc << 24 ifnot rtcAvailable ios.sdclose ios.sddmact(ios#DM_USER) 'u-marker aktivieren PRI listaddr (nvidx) | count 'IP-Adresse anzeigen ifnot rtcAvailable ios.sdseek(nvidx) repeat count from 0 to 3 if(count) ios.print(string(".")) if rtcAvailable ios.print(str.trimCharacters(num.ToStr(ios.getNVSRAM(nvidx+count), num#DEC))) else ios.print(str.trimCharacters(num.ToStr(ios.sdgetc, num#DEC))) DAT ' Locale #ifdef __LANG_EN 'locale: english strNoNetwork byte 13,"Administra doesn't provide network functions!",13,"Please load admnet.",13,0 strWaitConnection byte "Waiting for client connection...",13,0 strErrorNoSock byte "No free socket.",13,0 strErrorOpen byte "Can't open configuration file",13,0 strAddr byte 13,"Webserver startet, please use this URL to connect:",13," http://",0 strDefPage1 byte "
It Works!