01_FHEMWEB.pm 149 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684
  1. ##############################################
  2. # $Id: 01_FHEMWEB.pm 16350 2018-03-07 21:30:37Z rudolfkoenig $
  3. package main;
  4. use strict;
  5. use warnings;
  6. use TcpServerUtils;
  7. use HttpUtils;
  8. use Time::HiRes qw(gettimeofday);
  9. #########################
  10. # Forward declaration
  11. sub FW_IconURL($);
  12. sub FW_addContent(;$);
  13. sub FW_addToWritebuffer($$@);
  14. sub FW_answerCall($);
  15. sub FW_dev2image($;$);
  16. sub FW_devState($$@);
  17. sub FW_digestCgi($);
  18. sub FW_directNotify($@);
  19. sub FW_doDetail($);
  20. sub FW_fatal($);
  21. sub FW_fileList($;$);
  22. sub FW_htmlEscape($);
  23. sub FW_iconName($);
  24. sub FW_iconPath($);
  25. sub FW_logWrapper($);
  26. sub FW_makeEdit($$$);
  27. sub FW_makeImage(@);
  28. sub FW_makeTable($$$@);
  29. sub FW_makeTableFromArray($$@);
  30. sub FW_pF($@);
  31. sub FW_pH(@);
  32. sub FW_pHPlain(@);
  33. sub FW_pO(@);
  34. sub FW_parseColumns($);
  35. sub FW_readIcons($);
  36. sub FW_readIconsFrom($$);
  37. sub FW_returnFileAsStream($$$$$);
  38. sub FW_roomOverview($);
  39. #sub FW_roomStatesForInform($$); # Forum 30515
  40. sub FW_select($$$$$@);
  41. sub FW_serveSpecial($$$$);
  42. sub FW_showRoom();
  43. sub FW_style($$);
  44. sub FW_submit($$@);
  45. sub FW_textfield($$$);
  46. sub FW_textfieldv($$$$);
  47. sub FW_updateHashes();
  48. sub FW_visibleDevices(;$);
  49. sub FW_widgetOverride($$);
  50. sub FW_Read($$);
  51. use vars qw($FW_dir); # base directory for web server
  52. use vars qw($FW_icondir); # icon base directory
  53. use vars qw($FW_cssdir); # css directory
  54. use vars qw($FW_gplotdir);# gplot directory
  55. use vars qw($MW_dir); # moddir (./FHEM), needed by edit Files in new
  56. # structure
  57. use vars qw($FW_ME); # webname (default is fhem), used by 97_GROUP/weblink
  58. use vars qw($FW_CSRF); # CSRF Token or empty
  59. use vars qw($FW_ss); # is smallscreen, needed by 97_GROUP/95_VIEW
  60. use vars qw($FW_tp); # is touchpad (iPad / etc)
  61. use vars qw($FW_sp); # stylesheetPrefix
  62. # global variables, also used by 97_GROUP/95_VIEW/95_FLOORPLAN
  63. use vars qw(%FW_types); # device types,
  64. use vars qw($FW_RET); # Returned data (html)
  65. use vars qw($FW_RETTYPE); # image/png or the like
  66. use vars qw($FW_wname); # Web instance
  67. use vars qw($FW_subdir); # Sub-path in URL, used by FLOORPLAN/weblink
  68. use vars qw(%FW_pos); # scroll position
  69. use vars qw($FW_cname); # Current connection name
  70. use vars qw(%FW_hiddenroom); # hash of hidden rooms, used by weblink
  71. use vars qw($FW_plotmode);# Global plot mode (WEB attribute), used by SVG
  72. use vars qw($FW_plotsize);# Global plot size (WEB attribute), used by SVG
  73. use vars qw(%FW_webArgs); # all arguments specified in the GET
  74. use vars qw(@FW_fhemwebjs);# List of fhemweb*js scripts to load
  75. use vars qw($FW_fhemwebjs);# List of fhemweb*js scripts to load
  76. use vars qw($FW_detail); # currently selected device for detail view
  77. use vars qw($FW_cmdret); # Returned data by the fhem call
  78. use vars qw($FW_room); # currently selected room
  79. use vars qw($FW_formmethod);
  80. use vars qw(%FW_visibleDeviceHash);
  81. use vars qw(@FW_httpheader); # HTTP header, line by line
  82. use vars qw(%FW_httpheader); # HTTP header, as hash
  83. use vars qw($FW_userAgent); # user agent string
  84. $FW_formmethod = "post";
  85. my $FW_zlib_checked;
  86. my $FW_use_zlib = 1;
  87. my $FW_use_sha = 0;
  88. my $FW_activateInform = 0;
  89. my $FW_lastWebName = ""; # Name of last FHEMWEB instance, for caching
  90. my $FW_lastHashUpdate = 0;
  91. my $FW_httpRetCode = "";
  92. my %FW_csrfTokenCache;
  93. my %FW_id2inform;
  94. #########################
  95. # As we are _not_ multithreaded, it is safe to use global variables.
  96. # Note: for delivering SVG plots we fork
  97. my $FW_data; # Filecontent from browser when editing a file
  98. my %FW_icons; # List of icons
  99. my @FW_iconDirs; # Directory search order for icons
  100. my $FW_RETTYPE; # image/png or the like
  101. my %FW_rooms; # hash of all rooms
  102. my @FW_roomsArr; # ordered list of rooms
  103. my %FW_groups; # hash of all groups
  104. my %FW_types; # device types, for sorting
  105. my %FW_hiddengroup;# hash of hidden groups
  106. my $FW_inform;
  107. my $FW_XHR; # Data only answer, no HTML
  108. my $FW_id=""; # id of current page
  109. my $FW_jsonp; # jasonp answer (sending function calls to the client)
  110. my $FW_headerlines; #
  111. my $FW_chash; # client fhem hash
  112. my $FW_encoding="UTF-8";
  113. my $FW_styleStamp=time();
  114. #####################################
  115. sub
  116. FHEMWEB_Initialize($)
  117. {
  118. my ($hash) = @_;
  119. $hash->{ReadFn} = "FW_Read";
  120. $hash->{GetFn} = "FW_Get";
  121. $hash->{SetFn} = "FW_Set";
  122. $hash->{AttrFn} = "FW_Attr";
  123. $hash->{DefFn} = "FW_Define";
  124. $hash->{UndefFn} = "FW_Undef";
  125. $hash->{NotifyFn}= "FW_Notify";
  126. $hash->{AsyncOutputFn} = "FW_AsyncOutput";
  127. $hash->{ActivateInformFn} = "FW_ActivateInform";
  128. no warnings 'qw';
  129. my @attrList = qw(
  130. CORS:0,1
  131. HTTPS:1,0
  132. CssFiles
  133. Css:textField-long
  134. JavaScripts
  135. SVGcache:1,0
  136. addHtmlTitle:1,0
  137. addStateEvent
  138. csrfToken
  139. csrfTokenHTTPHeader:0,1
  140. alarmTimeout
  141. allowedHttpMethods
  142. allowedCommands
  143. allowfrom
  144. basicAuth
  145. basicAuthMsg
  146. closeConn:1,0
  147. column
  148. confirmDelete:0,1
  149. confirmJSError:0,1
  150. defaultRoom
  151. deviceOverview:always,iconOnly,onClick,never
  152. editConfig:1,0
  153. editFileList:textField-long
  154. endPlotNow:1,0
  155. endPlotToday:1,0
  156. fwcompress:0,1
  157. hiddengroup
  158. hiddengroupRegexp
  159. hiddenroom
  160. hiddenroomRegexp
  161. iconPath
  162. longpoll:0,1,websocket
  163. longpollSVG:1,0
  164. menuEntries
  165. mainInputLength
  166. nameDisplay
  167. ploteditor:always,onClick,never
  168. plotfork:1,0
  169. plotmode:gnuplot-scroll,gnuplot-scroll-svg,SVG
  170. plotEmbed:0,1
  171. plotsize
  172. plotWeekStartDay:0,1,2,3,4,5,6
  173. nrAxis
  174. redirectCmds:0,1
  175. refresh
  176. reverseLogs:0,1
  177. roomIcons
  178. sortRooms
  179. showUsedFiles:0,1
  180. sslVersion
  181. smallscreen:unused
  182. smallscreenCommands:0,1
  183. stylesheetPrefix
  184. styleData:textField-long
  185. title
  186. touchpad:unused
  187. viewport
  188. webname
  189. );
  190. use warnings 'qw';
  191. $hash->{AttrList} = join(" ", @attrList);
  192. ###############
  193. # Initialize internal structures
  194. map { addToAttrList($_) } ( "webCmd", "webCmdLabel:textField-long", "icon",
  195. "cmdIcon", "devStateIcon", "widgetOverride", "sortby", "devStateStyle");
  196. InternalTimer(time()+60, "FW_closeInactiveClients", 0, 0);
  197. $FW_dir = "$attr{global}{modpath}/www";
  198. $FW_icondir = "$FW_dir/images";
  199. $FW_cssdir = "$FW_dir/pgm2";
  200. $FW_gplotdir = "$FW_dir/gplot";
  201. if(opendir(DH, "$FW_dir/pgm2")) {
  202. $FW_fhemwebjs = join(",", map { $_ = ~m/^fhemweb_(.*).js$/; $1 }
  203. grep { /fhemweb_(.*).js$/ }
  204. readdir(DH));
  205. closedir(DH);
  206. }
  207. $data{webCmdFn}{"~"} = "FW_widgetFallbackFn"; # Should be the last
  208. if($init_done) { # reload workaround
  209. foreach my $pe ("fhemSVG", "openautomation", "default") {
  210. FW_readIcons($pe);
  211. }
  212. }
  213. eval { require Digest::SHA; };
  214. if($@) {
  215. Log 4, $@;
  216. Log 3, "FHEMWEB: Can't load Digest::SHA, ".
  217. "longpoll via websocket is not available";
  218. }
  219. $FW_use_sha = 1;
  220. }
  221. #####################################
  222. sub
  223. FW_Define($$)
  224. {
  225. my ($hash, $def) = @_;
  226. my ($name, $type, $port, $global) = split("[ \t]+", $def);
  227. return "Usage: define <name> FHEMWEB [IPV6:]<tcp-portnr> [global]"
  228. if($port !~ m/^(IPV6:)?\d+$/);
  229. FW_Undef($hash, undef) if($hash->{OLDDEF}); # modify
  230. foreach my $pe ("fhemSVG", "openautomation", "default") {
  231. FW_readIcons($pe);
  232. }
  233. my $ret = TcpServer_Open($hash, $port, $global);
  234. # Make sure that fhem only runs once
  235. if($ret && !$init_done) {
  236. Log3 $hash, 1, "$ret. Exiting.";
  237. exit(1);
  238. }
  239. $hash->{CSRFTOKEN} = $FW_csrfTokenCache{$name};
  240. if(!defined($hash->{CSRFTOKEN})) { # preserve over rereadcfg
  241. InternalTimer(1, sub(){
  242. if($featurelevel >= 5.8 && !AttrVal($name, "csrfToken", undef)) {
  243. my ($x,$y) = gettimeofday();
  244. ($defs{$name}{CSRFTOKEN}="csrf_".(rand($y)*rand($x))) =~s/[^a-z_0-9]//g;
  245. $FW_csrfTokenCache{$name} = $hash->{CSRFTOKEN};
  246. }
  247. }, $hash, 0);
  248. }
  249. return $ret;
  250. }
  251. #####################################
  252. sub
  253. FW_Undef($$)
  254. {
  255. my ($hash, $arg) = @_;
  256. my $ret = TcpServer_Close($hash);
  257. if($hash->{inform}) {
  258. delete $FW_id2inform{$hash->{FW_ID}} if($hash->{FW_ID});
  259. %FW_visibleDeviceHash = FW_visibleDevices();
  260. delete($logInform{$hash->{NAME}});
  261. }
  262. return $ret;
  263. }
  264. #####################################
  265. sub
  266. FW_Read($$)
  267. {
  268. my ($hash, $reread) = @_;
  269. my $name = $hash->{NAME};
  270. if($hash->{SERVERSOCKET}) { # Accept and create a child
  271. my $nhash = TcpServer_Accept($hash, "FHEMWEB");
  272. return if(!$nhash);
  273. my $wt = AttrVal($name, "alarmTimeout", undef);
  274. $nhash->{ALARMTIMEOUT} = $wt if($wt);
  275. $nhash->{CD}->blocking(0);
  276. return;
  277. }
  278. $FW_chash = $hash;
  279. $FW_wname = $hash->{SNAME};
  280. $FW_cname = $name;
  281. $FW_subdir = "";
  282. my $c = $hash->{CD};
  283. if(!$FW_zlib_checked) {
  284. $FW_zlib_checked = 1;
  285. $FW_use_zlib = AttrVal($FW_wname, "fwcompress", 1);
  286. if($FW_use_zlib) {
  287. eval { require Compress::Zlib; };
  288. if($@) {
  289. $FW_use_zlib = 0;
  290. Log3 $FW_wname, 1, $@;
  291. Log3 $FW_wname, 1,
  292. "$FW_wname: Can't load Compress::Zlib, deactivating compression";
  293. $attr{$FW_wname}{fwcompress} = 0;
  294. }
  295. }
  296. }
  297. if(!$reread) {
  298. # Data from HTTP Client
  299. my $buf;
  300. my $ret = sysread($c, $buf, 1024);
  301. if(!defined($ret) && $! == EWOULDBLOCK ){
  302. $hash->{wantWrite} = 1
  303. if(TcpServer_WantWrite($hash));
  304. return;
  305. } elsif(!$ret) { # 0==EOF, undef=error
  306. CommandDelete(undef, $name);
  307. Log3 $FW_wname, 4, "Connection closed for $name: ".
  308. (defined($ret) ? 'EOF' : $!);
  309. return;
  310. }
  311. $hash->{BUF} .= $buf;
  312. if($hash->{SSL} && $c->can('pending')) {
  313. while($c->pending()) {
  314. sysread($c, $buf, 1024);
  315. $hash->{BUF} .= $buf;
  316. }
  317. }
  318. }
  319. if($hash->{websocket}) { # 59713
  320. my $fin = (ord(substr($hash->{BUF},0,1)) & 0x80)?1:0;
  321. my $op = (ord(substr($hash->{BUF},0,1)) & 0x0F);
  322. my $mask = (ord(substr($hash->{BUF},1,1)) & 0x80)?1:0;
  323. my $len = (ord(substr($hash->{BUF},1,1)) & 0x7F);
  324. my $i = 2;
  325. if( $len == 126 ) {
  326. $len = unpack( 'n', substr($hash->{BUF},$i,2) );
  327. $i += 2;
  328. } elsif( $len == 127 ) {
  329. $len = unpack( 'q', substr($hash->{BUF},$i,8) );
  330. $i += 8;
  331. }
  332. if( $mask ) {
  333. $mask = substr($hash->{BUF},$i,4);
  334. $i += 4;
  335. }
  336. my $data = substr($hash->{BUF}, $i, $len);
  337. #for( my $i = 0; $i < $len; $i++ ) {
  338. # substr( $data, $i, 1, substr( $data, $i, 1, ) ^ substr($mask, $i% , 1) );
  339. #}
  340. #Log 1, "Received via websocket: ".unpack("H*",$data);
  341. $hash->{BUF} = "";
  342. return;
  343. }
  344. if(!$hash->{HDR}) {
  345. return if($hash->{BUF} !~ m/^(.*?)(\n\n|\r\n\r\n)(.*)$/s);
  346. $hash->{HDR} = $1;
  347. $hash->{BUF} = $3;
  348. if($hash->{HDR} =~ m/Content-Length:\s*([^\r\n]*)/si) {
  349. $hash->{CONTENT_LENGTH} = $1;
  350. }
  351. }
  352. my $POSTdata = "";
  353. if($hash->{CONTENT_LENGTH}) {
  354. return if(length($hash->{BUF})<$hash->{CONTENT_LENGTH});
  355. $POSTdata = substr($hash->{BUF}, 0, $hash->{CONTENT_LENGTH});
  356. $hash->{BUF} = substr($hash->{BUF}, $hash->{CONTENT_LENGTH});
  357. }
  358. @FW_httpheader = split(/[\r\n]+/, $hash->{HDR});
  359. %FW_httpheader = map {
  360. my ($k,$v) = split(/: */, $_, 2);
  361. $k =~ s/(\w+)/\u$1/g; # Forum #39203
  362. $k=>(defined($v) ? $v : 1);
  363. } @FW_httpheader;
  364. delete($hash->{HDR});
  365. my @origin = grep /Origin/i, @FW_httpheader;
  366. $FW_headerlines = (AttrVal($FW_wname, "CORS", 0) ?
  367. (($#origin<0) ? "": "Access-Control-Allow-".$origin[0]."\r\n").
  368. "Access-Control-Allow-Methods: GET POST OPTIONS\r\n".
  369. "Access-Control-Allow-Headers: Origin, Authorization, Accept\r\n".
  370. "Access-Control-Allow-Credentials: true\r\n".
  371. "Access-Control-Max-Age:86400\r\n".
  372. "Access-Control-Expose-Headers: X-FHEM-csrfToken\r\n": "");
  373. $FW_headerlines .= "X-FHEM-csrfToken: $defs{$FW_wname}{CSRFTOKEN}\r\n"
  374. if(defined($defs{$FW_wname}{CSRFTOKEN}) &&
  375. AttrVal($FW_wname, "csrfTokenHTTPHeader", 1));
  376. #########################
  377. # Return 200 for OPTIONS or 405 for unsupported method
  378. my ($method, $arg, $httpvers) = split(" ", $FW_httpheader[0], 3)
  379. if($FW_httpheader[0]);
  380. $method = "" if(!$method);
  381. my $ahm = AttrVal($FW_wname, "allowedHttpMethods", "GET|POST");
  382. if($method !~ m/^($ahm)$/i){
  383. my $retCode = ($method eq "OPTIONS") ? "200 OK" : "405 Method Not Allowed";
  384. TcpServer_WriteBlocking($FW_chash,
  385. "HTTP/1.1 $retCode\r\n" .
  386. $FW_headerlines.
  387. "Content-Length: 0\r\n\r\n");
  388. delete $hash->{CONTENT_LENGTH};
  389. FW_Read($hash, 1) if($hash->{BUF});
  390. Log 3, "$FW_cname: unsupported HTTP method $method, rejecting it."
  391. if($retCode ne "200 OK");
  392. FW_closeConn($hash);
  393. return;
  394. }
  395. #############################
  396. # AUTH
  397. if(!defined($FW_chash->{Authenticated})) {
  398. my $ret = Authenticate($FW_chash, \%FW_httpheader);
  399. if($ret == 0) {
  400. $FW_chash->{Authenticated} = 0; # not needed
  401. } elsif($ret == 1) {
  402. $FW_chash->{Authenticated} = 1; # ok
  403. # Need to send set-cookie (if set) after succesful authentication
  404. my $ah = $FW_chash->{".httpAuthHeader"};
  405. $FW_headerlines .= $ah if($ah);
  406. delete $FW_chash->{".httpAuthHeader"};
  407. } else {
  408. my $ah = $FW_chash->{".httpAuthHeader"};
  409. TcpServer_WriteBlocking($hash,
  410. ($ah ? $ah : "").
  411. $FW_headerlines.
  412. "Content-Length: 0\r\n\r\n");
  413. delete $hash->{CONTENT_LENGTH};
  414. FW_Read($hash, 1) if($hash->{BUF});
  415. return;
  416. }
  417. } else {
  418. my $ah = $FW_chash->{".httpAuthHeader"};
  419. $FW_headerlines .= $ah if($ah);
  420. }
  421. #############################
  422. my $now = time();
  423. $arg .= "&".$POSTdata if($POSTdata);
  424. delete $hash->{CONTENT_LENGTH};
  425. $hash->{LASTACCESS} = $now;
  426. $FW_userAgent = $FW_httpheader{"User-Agent"};
  427. $FW_userAgent = "" if(!defined($FW_userAgent));
  428. $FW_ME = "/" . AttrVal($FW_wname, "webname", "fhem");
  429. $FW_CSRF = (defined($defs{$FW_wname}{CSRFTOKEN}) ?
  430. "&fwcsrf=".$defs{$FW_wname}{CSRFTOKEN} : "");
  431. if($FW_use_sha && $method eq 'GET' &&
  432. $FW_httpheader{Connection} && $FW_httpheader{Connection} =~ /Upgrade/i) {
  433. my $shastr = Digest::SHA::sha1_base64($FW_httpheader{'Sec-WebSocket-Key'}.
  434. "258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
  435. TcpServer_WriteBlocking($FW_chash,
  436. "HTTP/1.1 101 Switching Protocols\r\n" .
  437. "Upgrade: websocket\r\n" .
  438. "Connection: Upgrade\r\n" .
  439. "Sec-WebSocket-Accept:$shastr=\r\n".
  440. "\r\n" );
  441. $FW_chash->{websocket} = 1;
  442. my $me = $FW_chash;
  443. my ($cmd, $cmddev) = FW_digestCgi($arg);
  444. if($FW_id) {
  445. $me->{FW_ID} = $FW_id;
  446. $me->{canAsyncOutput} = 1;
  447. }
  448. FW_initInform($me, 0) if($FW_inform);
  449. return -1;
  450. }
  451. $arg = "" if(!defined($arg));
  452. Log3 $FW_wname, 4, "$name $method $arg; BUFLEN:".length($hash->{BUF});
  453. my $pf = AttrVal($FW_wname, "plotfork", undef);
  454. if($pf) { # 0 disables
  455. # Process SVG rendering as a parallel process
  456. my $p = $data{FWEXT};
  457. if(grep { $p->{$_}{FORKABLE} && $arg =~ m+^$FW_ME$_+ } keys %{$p}) {
  458. my $pid = fhemFork();
  459. if($pid) { # success, parent
  460. use constant PRIO_PROCESS => 0;
  461. setpriority(PRIO_PROCESS, $pid, getpriority(PRIO_PROCESS,$pid) + $pf)
  462. if($^O !~ m/Win/);
  463. # a) while child writes a new request might arrive if client uses
  464. # pipelining or
  465. # b) parent doesn't know about ssl-session changes due to child writing
  466. # to socket
  467. # -> have to close socket in parent... so that its only used in this
  468. # child.
  469. TcpServer_Disown( $hash );
  470. delete($defs{$name});
  471. delete($attr{$name});
  472. FW_Read($hash, 1) if($hash->{BUF});
  473. return;
  474. } elsif(defined($pid)){ # child
  475. delete $hash->{BUF};
  476. $hash->{isChild} = 1;
  477. } # fork failed and continue in parent
  478. }
  479. }
  480. $FW_httpRetCode = "200 OK";
  481. my $cacheable = FW_answerCall($arg);
  482. if($cacheable == -1) {
  483. FW_closeConn($hash);
  484. return;
  485. }
  486. my $compressed = "";
  487. if($FW_RETTYPE =~ m/(text|xml|json|svg|script)/i &&
  488. ($FW_httpheader{"Accept-Encoding"} &&
  489. $FW_httpheader{"Accept-Encoding"} =~ m/gzip/) &&
  490. $FW_use_zlib) {
  491. utf8::encode($FW_RET)
  492. if(utf8::is_utf8($FW_RET) && $FW_RET =~ m/[^\x00-\xFF]/ );
  493. eval { $FW_RET = Compress::Zlib::memGzip($FW_RET); };
  494. if($@) {
  495. Log 1, "memGzip: $@"; $FW_RET=""; #Forum #29939
  496. } else {
  497. $compressed = "Content-Encoding: gzip\r\n";
  498. }
  499. }
  500. my $length = length($FW_RET);
  501. my $expires = ($cacheable?
  502. ("Expires: ".FmtDateTimeRFC1123($now+900)."\r\n") : "");
  503. Log3 $FW_wname, 4,
  504. "$FW_wname: $arg / RL:$length / $FW_RETTYPE / $compressed / $expires";
  505. if( ! FW_addToWritebuffer($hash,
  506. "HTTP/1.1 $FW_httpRetCode\r\n" .
  507. "Content-Length: $length\r\n" .
  508. $expires . $compressed . $FW_headerlines .
  509. "Content-Type: $FW_RETTYPE\r\n\r\n" .
  510. $FW_RET, "FW_closeConn", 1) ){
  511. Log3 $name, 4, "Closing connection $name due to full buffer in FW_Read"
  512. if(!$hash->{isChild});
  513. FW_closeConn($hash);
  514. TcpServer_Close($hash, 1);
  515. }
  516. }
  517. sub
  518. FW_initInform($$)
  519. {
  520. my ($me, $longpoll) = @_;
  521. if($FW_inform =~ /type=/) {
  522. foreach my $kv (split(";", $FW_inform)) {
  523. my ($key,$value) = split("=", $kv, 2);
  524. $me->{inform}{$key} = $value;
  525. }
  526. } else { # Compatibility mode
  527. $me->{inform}{type} = ($FW_room ? "status" : "raw");
  528. $me->{inform}{filter} = ($FW_room ? $FW_room : ".*");
  529. }
  530. $FW_id2inform{$FW_id} = $me if($FW_id);
  531. my $filter = $me->{inform}{filter};
  532. $filter =~ s/([[\]().+?])/\\$1/g if($filter =~ m/room=/); # Forum #80390
  533. $filter = "NAME=.*" if($filter eq "room=all");
  534. $filter = "room!=.+" if($filter eq "room=Unsorted");
  535. my %h = map { $_ => 1 } devspec2array($filter);
  536. $h{global} = 1 if( $me->{inform}{addglobal} );
  537. $h{"#FHEMWEB:$FW_wname"} = 1;
  538. $me->{inform}{devices} = \%h;
  539. %FW_visibleDeviceHash = FW_visibleDevices();
  540. # NTFY_ORDER is larger than the normal order (50-)
  541. $me->{NTFY_ORDER} = $FW_cname; # else notifyfn won't be called
  542. %ntfyHash = ();
  543. $me->{inform}{since} = time()-5
  544. if(!defined($me->{inform}{since}) || $me->{inform}{since} !~ m/^\d+$/);
  545. my $sinceTimestamp = FmtDateTime($me->{inform}{since});
  546. if($longpoll) {
  547. TcpServer_WriteBlocking($me,
  548. "HTTP/1.1 200 OK\r\n".
  549. $FW_headerlines.
  550. "Content-Type: application/octet-stream; charset=$FW_encoding\r\n\r\n".
  551. FW_roomStatesForInform($me, $sinceTimestamp));
  552. } else { # websocket
  553. FW_addToWritebuffer($me,
  554. FW_roomStatesForInform($me, $sinceTimestamp));
  555. }
  556. if($FW_id && $defs{$FW_wname}{asyncOutput}) {
  557. my $data = $defs{$FW_wname}{asyncOutput}{$FW_id};
  558. if($data) {
  559. FW_addToWritebuffer($me, $data."\n");
  560. delete $defs{$FW_wname}{asyncOutput}{$FW_id};
  561. }
  562. }
  563. if($me->{inform}{withLog}) {
  564. $logInform{$me->{NAME}} = "FW_logInform";
  565. } else {
  566. delete($logInform{$me->{NAME}});
  567. }
  568. }
  569. sub
  570. FW_addToWritebuffer($$@)
  571. {
  572. my ($hash, $txt, $callback, $nolimit) = @_;
  573. if( $hash->{websocket} ) {
  574. my $len = length($txt);
  575. if( $len < 126 ) {
  576. $txt = chr(0x81) . chr($len) . $txt;
  577. } else {
  578. if ( $len < 65536 ) {
  579. $txt = chr(0x81) . chr(0x7E) . pack('n', $len) . $txt;
  580. } else {
  581. $txt = chr(0x81) . chr(0x7F) . chr(0x00) . chr(0x00) .
  582. chr(0x00) . chr(0x00) . pack('N', $len) . $txt;
  583. }
  584. }
  585. }
  586. return addToWritebuffer($hash, $txt, $callback, $nolimit);
  587. }
  588. sub
  589. FW_AsyncOutput($$)
  590. {
  591. my ($hash, $ret) = @_;
  592. return if(!$hash || !$hash->{FW_ID});
  593. if( $ret =~ m/^<html>(.*)<\/html>$/s ) {
  594. $ret = $1;
  595. } else {
  596. $ret = FW_htmlEscape($ret);
  597. $ret = "<pre>$ret</pre>" if($ret =~ m/\n/ );
  598. $ret =~ s/\n/<br>/g;
  599. }
  600. my $data = FW_longpollInfo('JSON',
  601. "#FHEMWEB:$FW_wname","FW_okDialog('$ret')","");
  602. # find the longpoll connection with the same fw_id as the page that was the
  603. # origin of the get command
  604. my $fwid = $hash->{FW_ID};
  605. if(!$fwid) {
  606. Log3 $hash->{SNAME}, 4, "AsyncOutput from $hash->{NAME} without FW_ID";
  607. return;
  608. }
  609. Log3 $hash->{SNAME}, 4, "AsyncOutput from $hash->{NAME}";
  610. $hash = $FW_id2inform{$fwid};
  611. if($hash) {
  612. FW_addToWritebuffer($hash, $data."\n");
  613. } else {
  614. $defs{$FW_wname}{asyncOutput}{$fwid} = $data;
  615. }
  616. return undef;
  617. }
  618. sub
  619. FW_closeConn($)
  620. {
  621. my ($hash) = @_;
  622. if(!$hash->{inform} && !$hash->{BUF}) { # Forum #41125
  623. my $cc = AttrVal($hash->{SNAME}, "closeConn",
  624. $FW_userAgent =~ m/(iPhone|iPad|iPod)/);
  625. if(!$FW_httpheader{Connection} || $cc) {
  626. TcpServer_Close($hash, 1);
  627. }
  628. }
  629. POSIX::exit(0) if($hash->{isChild});
  630. FW_Read($hash, 1) if($hash->{BUF});
  631. }
  632. ###########################
  633. sub
  634. FW_serveSpecial($$$$)
  635. {
  636. my ($file,$ext,$dir,$cacheable)= @_;
  637. $file =~ s,\.\./,,g; # little bit of security
  638. $file = "$FW_sp$file" if($ext eq "css" && -f "$dir/$FW_sp$file.$ext");
  639. $FW_RETTYPE = ext2MIMEType($ext);
  640. my $fname = ($ext ? "$file.$ext" : $file);
  641. return FW_returnFileAsStream("$dir/$fname", "", $FW_RETTYPE, 0, $cacheable);
  642. }
  643. sub
  644. FW_answerCall($)
  645. {
  646. my ($arg) = @_;
  647. my $me=$defs{$FW_cname}; # cache, else rereadcfg will delete us
  648. $FW_RET = "";
  649. $FW_RETTYPE = "text/html; charset=$FW_encoding";
  650. $MW_dir = "$attr{global}{modpath}/FHEM";
  651. $FW_sp = AttrVal($FW_wname, "stylesheetPrefix", "");
  652. $FW_ss = ($FW_sp =~ m/smallscreen/);
  653. $FW_tp = ($FW_sp =~ m/smallscreen|touchpad/);
  654. @FW_iconDirs = grep { $_ } split(":", AttrVal($FW_wname, "iconPath",
  655. "$FW_sp:default:fhemSVG:openautomation"));
  656. @FW_fhemwebjs = ("fhemweb.js");
  657. push(@FW_fhemwebjs, "$FW_sp.js") if(-r "$FW_dir/pgm2/$FW_sp.js");
  658. if($arg =~ m,$FW_ME/floorplan/([a-z0-9.:_]+),i) { # FLOORPLAN: special icondir
  659. unshift @FW_iconDirs, $1;
  660. FW_readIcons($1);
  661. }
  662. # /icons/... => current state of ...
  663. # also used for static images: unintended, but too late to change
  664. my ($dir1, $dirN, $ofile) = ($1, $2, $3)
  665. if($arg =~ m,^$FW_ME/([^/]*)(.*/)([^/]*)$,);
  666. if($arg =~ m,\brobots.txt$,) {
  667. Log3 $FW_wname, 1, "NOTE: $FW_wname is probed by a search engine";
  668. $FW_RETTYPE = "text/plain; charset=$FW_encoding";
  669. FW_pO "User-agent: *\r";
  670. FW_pO "Disallow: *\r";
  671. return 0;
  672. } elsif($arg =~ m,^$FW_ME/icons/(.*)$,) {
  673. my ($icon,$cacheable) = (urlDecode($1), 1);
  674. my $iconPath = FW_iconPath($icon);
  675. # if we do not have the icon, we convert the device state to the icon name
  676. if(!$iconPath) {
  677. my ($img, $link, $isHtml) = FW_dev2image($icon);
  678. $cacheable = 0;
  679. return 0 if(!$img);
  680. $iconPath = FW_iconPath($img);
  681. if($iconPath =~ m/\.svg$/i) {
  682. $FW_RETTYPE = ext2MIMEType("svg");
  683. FW_pO FW_makeImage($img, $img);
  684. return 0;
  685. }
  686. } elsif($iconPath =~ m/\.svg$/i && $icon=~ m/@/) {
  687. $FW_RETTYPE = ext2MIMEType("svg");
  688. FW_pO FW_makeImage($icon, $icon);
  689. return 0;
  690. }
  691. $iconPath =~ m/(.*)\.([^.]*)/;
  692. return FW_serveSpecial($1, $2, $FW_icondir, $cacheable);
  693. } elsif($dir1 && !$data{FWEXT}{"/$dir1"}) {
  694. my $dir = "$dir1$dirN";
  695. my $ext = "";
  696. $dir =~ s,/$,,;
  697. $dir =~ s/\.\.//g;
  698. $dir =~ s,www/,,g; # Want commandref.html to work from file://...
  699. my $file = urlDecode($ofile); # 69164
  700. $file =~ s/\?.*//; # Remove timestamp of CSS reloader
  701. if($file =~ m/^(.*)\.([^.]*)$/) {
  702. $file = $1; $ext = $2;
  703. }
  704. my $ldir = "$FW_dir/$dir";
  705. $ldir = "$FW_dir/pgm2" if($dir eq "css" || $dir eq "js"); # FLOORPLAN compat
  706. $ldir = "$attr{global}{modpath}/docs" if($dir eq "docs");
  707. # pgm2 check is for jquery-ui images
  708. my $static = ($ext =~ m/(css|js|png|jpg)/i || $dir =~ m/^pgm2/);
  709. my $fname = ($ext ? "$file.$ext" : $file);
  710. return FW_serveSpecial($file, $ext, $ldir, ($arg =~ m/nocache/) ? 0 : 1)
  711. if(-r "$ldir/$fname" || $static); # no return for FLOORPLAN
  712. $arg = "/$dir/$ofile";
  713. } elsif($arg =~ m/^$FW_ME(.*)/s) {
  714. $arg = $1; # The stuff behind FW_ME, continue to check for commands/FWEXT
  715. } else {
  716. Log3 $FW_wname, 4, "$FW_wname: redirecting $arg to $FW_ME";
  717. TcpServer_WriteBlocking($me,
  718. "HTTP/1.1 302 Found\r\n".
  719. "Content-Length: 0\r\n".
  720. $FW_headerlines.
  721. "Location: $FW_ME\r\n\r\n");
  722. FW_closeConn($FW_chash);
  723. return -1;
  724. }
  725. $FW_plotmode = AttrVal($FW_wname, "plotmode", "SVG");
  726. $FW_plotsize = AttrVal($FW_wname, "plotsize", $FW_ss ? "480,160" :
  727. $FW_tp ? "640,160" : "800,160");
  728. my ($cmd, $cmddev) = FW_digestCgi($arg);
  729. if($cmd && $FW_CSRF && $cmd !~ m/style (list|select|eventMonitor)/) {
  730. my $supplied = defined($FW_webArgs{fwcsrf}) ? $FW_webArgs{fwcsrf} : "";
  731. my $want = $defs{$FW_wname}{CSRFTOKEN};
  732. if($supplied ne $want) {
  733. Log3 $FW_wname, 3, "FHEMWEB $FW_wname CSRF error: $supplied ne $want ".
  734. "for client $FW_chash->{NAME} / command $cmd. ".
  735. "For details see the csrfToken FHEMWEB attribute.";
  736. $FW_httpRetCode = "400 Bad Request";
  737. return 0;
  738. }
  739. }
  740. if( $FW_id ) {
  741. $me->{FW_ID} = $FW_id;
  742. $me->{canAsyncOutput} = 1;
  743. }
  744. if($FW_inform) { # Longpoll header
  745. FW_initInform($me, 1);
  746. return -1;
  747. }
  748. my $docmd = 0;
  749. $docmd = 1 if($cmd &&
  750. $cmd !~ /^showlog/ &&
  751. $cmd !~ /^style / &&
  752. $cmd !~ /^edit/);
  753. #If we are in XHR or json mode, execute the command directly
  754. if($FW_XHR || $FW_jsonp) {
  755. $FW_cmdret = $docmd ? FW_fC($cmd, $cmddev) : undef;
  756. $FW_RETTYPE = $FW_chash->{contenttype} ?
  757. $FW_chash->{contenttype} : "text/plain; charset=$FW_encoding";
  758. delete($FW_chash->{contenttype});
  759. if($FW_jsonp) {
  760. $FW_cmdret =~ s/'/\\'/g;
  761. # Escape newlines in JavaScript string
  762. $FW_cmdret =~ s/\n/\\\n/g;
  763. FW_pO "$FW_jsonp('$FW_cmdret');";
  764. } else {
  765. $FW_cmdret = FW_addLinks($FW_cmdret) if($FW_webArgs{addLinks});
  766. FW_pO $FW_cmdret;
  767. }
  768. return 0;
  769. }
  770. ##############################
  771. # FHEMWEB extensions (FLOORPLOAN, SVG_WriteGplot, etc)
  772. my $FW_contentFunc;
  773. if(defined($data{FWEXT})) {
  774. foreach my $k (sort keys %{$data{FWEXT}}) {
  775. my $h = $data{FWEXT}{$k};
  776. next if($arg !~ m/^$k/);
  777. $FW_contentFunc = $h->{CONTENTFUNC};
  778. next if($h !~ m/HASH/ || !$h->{FUNC});
  779. #Returns undef as FW_RETTYPE if it already sent a HTTP header
  780. no strict "refs";
  781. ($FW_RETTYPE, $FW_RET) = &{$h->{FUNC}}($arg);
  782. if(defined($FW_RETTYPE) && $FW_RETTYPE =~ m,text/html,) {
  783. my $dataAttr = FW_dataAttr();
  784. $FW_RET =~ s/<body/<body $dataAttr/;
  785. }
  786. use strict "refs";
  787. return defined($FW_RETTYPE) ? 0 : -1;
  788. }
  789. }
  790. #Now execute the command
  791. $FW_cmdret = undef;
  792. if($docmd) {
  793. $FW_cmdret = FW_fC($cmd, $cmddev);
  794. if($cmd =~ m/^define +([^ ]+) /) { # "redirect" after define to details
  795. $FW_detail = $1;
  796. }
  797. elsif($cmd =~ m/^copy +([^ ]+) +([^ ]+)/) { # redirect define to details
  798. $FW_detail = $2;
  799. }
  800. }
  801. # Redirect after a command, to clean the browser URL window
  802. if($docmd && !defined($FW_cmdret) && AttrVal($FW_wname, "redirectCmds", 1)) {
  803. my $tgt = $FW_ME;
  804. if($FW_detail) { $tgt .= "?detail=$FW_detail&fw_id=$FW_id" }
  805. elsif($FW_room) { $tgt .= "?room=".urlEncode($FW_room)."&fw_id=$FW_id" }
  806. else { $tgt .= "?fw_id=$FW_id" }
  807. TcpServer_WriteBlocking($me,
  808. "HTTP/1.1 302 Found\r\n".
  809. "Content-Length: 0\r\n". $FW_headerlines.
  810. "Location: $tgt\r\n".
  811. "\r\n");
  812. return -1;
  813. }
  814. if($FW_lastWebName ne $FW_wname || $FW_lastHashUpdate != $lastDefChange) {
  815. FW_updateHashes();
  816. $FW_lastWebName = $FW_wname;
  817. $FW_lastHashUpdate = $lastDefChange;
  818. }
  819. my $hsh = "Home, Sweet Home";
  820. my $t = AttrVal($FW_wname, "title", AttrVal("global", "title", $hsh));
  821. $t = eval $t if($t =~ m/^{.*}$/s); # Forum #48668
  822. $t = $hsh if(!defined($t));
  823. FW_pO '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '.
  824. '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
  825. FW_pO '<html xmlns="http://www.w3.org/1999/xhtml">';
  826. FW_pO "<head root=\"$FW_ME\">\n<title>$t</title>";
  827. FW_pO '<link rel="shortcut icon" href="'.FW_IconURL("favicon").'" />';
  828. FW_pO "<meta charset=\"$FW_encoding\">"; # Forum 28666
  829. FW_pO "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">";#Forum 18316
  830. # Enable WebApps
  831. if($FW_tp || $FW_ss) {
  832. my $icon = FW_iconPath("fhemicon_ios.png");
  833. $icon = $FW_ME."/images/".($icon ? $icon : "default/fhemicon_ios.png");
  834. my $viewport = '';
  835. if($FW_ss) {
  836. my $stf = $FW_userAgent =~ m/iPad|iPhone|iPod/ ? ",shrink-to-fit=no" :"";
  837. $viewport = "initial-scale=1.0,user-scalable=1$stf";
  838. } elsif($FW_tp) {
  839. $viewport = "width=768";
  840. }
  841. $viewport = AttrVal($FW_wname, "viewport", $viewport);
  842. FW_pO '<meta name="viewport" content="'.$viewport.'"/>' if ($viewport);
  843. FW_pO '<meta name="apple-mobile-web-app-capable" content="yes"/>';
  844. FW_pO '<meta name="mobile-web-app-capable" content="yes"/>'; # Forum #36183
  845. FW_pO '<link rel="apple-touch-icon" href="'.$icon.'"/>';
  846. FW_pO '<link rel="shortcut-icon" href="'.$icon.'"/>';
  847. }
  848. if(!$FW_detail) {
  849. my $rf = AttrVal($FW_wname, "refresh", "");
  850. FW_pO "<meta http-equiv=\"refresh\" content=\"$rf\">" if($rf);
  851. }
  852. ########################
  853. # CSS
  854. my $cssTemplate = "<link href=\"$FW_ME/%s\" rel=\"stylesheet\"/>";
  855. FW_pO sprintf($cssTemplate, "pgm2/style.css?v=$FW_styleStamp");
  856. FW_pO sprintf($cssTemplate, "pgm2/jquery-ui.min.css");
  857. map { FW_pO sprintf($cssTemplate, $_); }
  858. split(" ", AttrVal($FW_wname, "CssFiles", ""));
  859. my $sd = AttrVal($FW_wname, "styleData", ""); # Avoid flicker in f18
  860. if($sd && $sd =~ m/"$FW_sp":/s) {
  861. my $bg;
  862. $bg = $1 if($FW_room && $sd =~ m/"Room\.$FW_room\.cols.bg": "([^"]*)"/s);
  863. $bg = $1 if(!defined($bg) && $sd =~ m/"cols.bg": "([^"]*)"/s);
  864. my $bgImg;
  865. $bgImg = $1 if($FW_room && $sd =~ m/"Room\.$FW_room\.bgImg": "([^"]*)"/s);
  866. $bgImg = $1 if(!defined($bgImg) && $sd =~ m/"bgImg": "([^"]*)"/s);
  867. FW_pO "<style id='style_css'>";
  868. FW_pO "body { background-color:#$bg; }" if($bg);
  869. FW_pO "body { background-image:url($FW_ME/images/background/$bgImg); }"
  870. if($bgImg);
  871. FW_pO "</style>";
  872. }
  873. my $css = AttrVal($FW_wname, "Css", "");
  874. FW_pO "<style id='fhemweb_css'>$css</style>\n" if($css);
  875. ########################
  876. # JavaScripts
  877. my $jsTemplate =
  878. '<script attr=\'%s\' type="text/javascript" src="%s"></script>';
  879. FW_pO sprintf($jsTemplate, "", "$FW_ME/pgm2/jquery.min.js");
  880. FW_pO sprintf($jsTemplate, "", "$FW_ME/pgm2/jquery-ui.min.js");
  881. my (%jsNeg, @jsList); # jsNeg was used to exclude automatically loaded files
  882. map { $_ =~ m/^-(.*)$/ ? $jsNeg{$1} = 1 : push(@jsList, $_); }
  883. split(" ", AttrVal($FW_wname, "JavaScripts", ""));
  884. map { FW_pO sprintf($jsTemplate, "", "$FW_ME/pgm2/$_") if(!$jsNeg{$_}); }
  885. @FW_fhemwebjs;
  886. #######################
  887. # "Own" JavaScripts + their Attributes
  888. map {
  889. my $n = $_; $n =~ s+.*/++; $n =~ s/.js$//; $n =~ s/fhem_//; $n .= "Param";
  890. FW_pO sprintf($jsTemplate, AttrVal($FW_wname, $n, ""), "$FW_ME/$_");
  891. } @jsList;
  892. ########################
  893. # FW Extensions
  894. if(defined($data{FWEXT})) {
  895. foreach my $k (sort keys %{$data{FWEXT}}) {
  896. my $h = $data{FWEXT}{$k};
  897. next if($h !~ m/HASH/ || !$h->{SCRIPT} || $h->{SCRIPT} =~ m+pgm2/jquery+);
  898. my $script = $h->{SCRIPT};
  899. $script = ($script =~ m,^/,) ? "$FW_ME$script" : "$FW_ME/pgm2/$script";
  900. FW_pO sprintf($jsTemplate, "", $script);
  901. }
  902. }
  903. my $csrf= ($FW_CSRF ? "fwcsrf='$defs{$FW_wname}{CSRFTOKEN}'" : "");
  904. my $gen = 'generated="'.(time()-1).'"';
  905. my $lp = 'longpoll="'.AttrVal($FW_wname,"longpoll",
  906. $FW_use_sha && $FW_userAgent=~m/Chrome/ ? "websocket": 1).'"';
  907. $FW_id = $FW_chash->{NR} if( !$FW_id );
  908. my $dataAttr = FW_dataAttr();
  909. FW_pO "</head>\n<body name='$t' fw_id='$FW_id' $gen $lp $csrf $dataAttr>";
  910. if($FW_activateInform) {
  911. $cmd = "style eventMonitor $FW_activateInform";
  912. $FW_cmdret = undef;
  913. $FW_activateInform = "";
  914. }
  915. FW_roomOverview($cmd);
  916. if(defined($FW_cmdret)) {
  917. $FW_detail = "";
  918. $FW_room = "";
  919. if( $FW_cmdret =~ m/^<html>(.*)<\/html>$/s ) {
  920. $FW_cmdret = $1;
  921. } else { # "linkify" output (e.g. for list)
  922. $FW_cmdret = FW_addLinks(FW_htmlEscape($FW_cmdret));
  923. $FW_cmdret =~ s/:\S+//g if($FW_cmdret =~ m/unknown.*choose one of/i);
  924. $FW_cmdret = "<pre>$FW_cmdret</pre>" if($FW_cmdret =~ m/\n/);
  925. }
  926. FW_addContent();
  927. if($FW_ss) {
  928. FW_pO "<div class=\"tiny\">$FW_cmdret</div>";
  929. } else {
  930. FW_pO $FW_cmdret;
  931. }
  932. FW_pO "</div>";
  933. }
  934. if($FW_contentFunc) {
  935. no strict "refs";
  936. my $ret = &{$FW_contentFunc}($arg);
  937. use strict "refs";
  938. return $ret if($ret);
  939. }
  940. if($cmd =~ m/^style /) { FW_style($cmd,undef); }
  941. elsif($FW_detail) { FW_doDetail($FW_detail); }
  942. elsif($FW_room) { FW_showRoom(); }
  943. elsif(!defined($FW_cmdret) &&
  944. !$FW_contentFunc) {
  945. $FW_room = AttrVal($FW_wname, "defaultRoom", '');
  946. if($FW_room ne '') {
  947. FW_showRoom();
  948. } else {
  949. my $motd = AttrVal("global","motd","none");
  950. if($motd ne "none") {
  951. FW_addContent("><pre class='motd'>$motd</pre></div");
  952. }
  953. }
  954. }
  955. FW_pO "</body></html>";
  956. return 0;
  957. }
  958. sub
  959. FW_dataAttr()
  960. {
  961. sub
  962. addParam($$)
  963. {
  964. my ($p, $default) = @_;
  965. my $val = AttrVal($FW_wname,$p, $default);
  966. $val =~ s/&/&amp;/g;
  967. $val =~ s/'/&quot;/g;
  968. return "data-$p='$val' ";
  969. }
  970. return
  971. addParam("confirmDelete", 1).
  972. addParam("confirmJSError", 1).
  973. addParam("addHtmlTitle", 1).
  974. addParam("styleData", "").
  975. "data-availableJs='$FW_fhemwebjs' ".
  976. "data-webName='$FW_wname '";
  977. }
  978. sub
  979. FW_addContent(;$)
  980. {
  981. my $add = ($_[0] ? " $_[0]" : "");
  982. FW_pO "<div id='content' $add>";
  983. }
  984. sub
  985. FW_addLinks($)
  986. {
  987. my ($txt) = @_;
  988. return undef if(!defined($txt));
  989. $txt =~ s,\b([a-z0-9._]+)\b,
  990. $defs{$1} ? "<a href='$FW_ME$FW_subdir?detail=$1'>$1</a>" : $1,gei;
  991. return $txt;
  992. }
  993. ###########################
  994. # Digest CGI parameters
  995. sub
  996. FW_digestCgi($)
  997. {
  998. my ($arg) = @_;
  999. my (%arg, %val, %dev);
  1000. my ($cmd, $c) = ("","","");
  1001. %FW_pos = ();
  1002. $FW_room = "";
  1003. $FW_detail = "";
  1004. $FW_XHR = undef;
  1005. $FW_id = "";
  1006. $FW_jsonp = undef;
  1007. $FW_inform = undef;
  1008. %FW_webArgs = ();
  1009. #Remove (nongreedy) everything including the first '?'
  1010. $arg =~ s,^.*?[?],,;
  1011. foreach my $pv (split("&", $arg)) {
  1012. next if($pv eq ""); # happens when post forgot to set FW_ME
  1013. $pv =~ s/\+/ /g;
  1014. $pv =~ s/%([\dA-F][\dA-F])/chr(hex($1))/ige;
  1015. my ($p,$v) = split("=",$pv, 2);
  1016. $v = "" if(!defined($v));
  1017. # Multiline: escape the NL for fhem
  1018. $v =~ s/[\r]//g if($v && $p && $p ne "data");
  1019. $FW_webArgs{$p} = $v;
  1020. if($p eq "detail") { $FW_detail = $v; }
  1021. if($p eq "room") { $FW_room = $v; }
  1022. if($p eq "cmd") { $cmd = $v; }
  1023. if($p =~ m/^arg\.(.*)$/) { $arg{$1} = $v; }
  1024. if($p =~ m/^val\.(.*)$/) { $val{$1} = ($val{$1} ? $val{$1}.",$v" : $v) }
  1025. if($p =~ m/^dev\.(.*)$/) { $dev{$1} = $v; }
  1026. if($p =~ m/^cmd\.(.*)$/) { $cmd = $v; $c = $1; }
  1027. if($p eq "pos") { %FW_pos = split(/[=;]/, $v); }
  1028. if($p eq "data") { $FW_data = $v; }
  1029. if($p eq "XHR") { $FW_XHR = 1; }
  1030. if($p eq "fw_id") { $FW_id = $v; }
  1031. if($p eq "jsonp") { $FW_jsonp = $v; }
  1032. if($p eq "inform") { $FW_inform = $v; }
  1033. }
  1034. $cmd.=" $dev{$c}" if(defined($dev{$c}));
  1035. $cmd.=" $arg{$c}" if(defined($arg{$c}) &&
  1036. ($arg{$c} ne "state" || $cmd !~ m/^set/));
  1037. $cmd.=" $val{$c}" if(defined($val{$c}));
  1038. #replace unicode newline symbol \u2424 with real newline
  1039. my $nl = chr(226) . chr(144) . chr(164);
  1040. $cmd =~ s/$nl/\n/g;
  1041. return ($cmd, $c);
  1042. }
  1043. #####################
  1044. # create FW_rooms && FW_types
  1045. sub
  1046. FW_updateHashes()
  1047. {
  1048. %FW_rooms = (); # Make a room hash
  1049. %FW_groups = (); # Make a group hash
  1050. %FW_types = (); # Needed for type sorting
  1051. my $hre = AttrVal($FW_wname, "hiddenroomRegexp", "");
  1052. foreach my $d (keys %defs ) {
  1053. next if(IsIgnored($d));
  1054. foreach my $r (split(",", AttrVal($d, "room", "Unsorted"))) {
  1055. next if($hre && $r =~ m/$hre/);
  1056. $FW_rooms{$r}{$d} = 1;
  1057. }
  1058. foreach my $r (split(",", AttrVal($d, "group", ""))) {
  1059. $FW_groups{$r}{$d} = 1;
  1060. }
  1061. my $t = AttrVal($d, "subType", $defs{$d}{TYPE});
  1062. $t = AttrVal($d, "model", $t) if($t && $t eq "unknown"); # RKO: ???
  1063. $FW_types{$d} = $t;
  1064. }
  1065. $FW_room = AttrVal($FW_detail, "room", "Unsorted") if($FW_detail);
  1066. if(AttrVal($FW_wname, "sortRooms", "")) { # Slow!
  1067. my @sortBy = split( " ", AttrVal( $FW_wname, "sortRooms", "" ) );
  1068. my %sHash;
  1069. map { $sHash{$_} = FW_roomIdx(\@sortBy,$_) } keys %FW_rooms;
  1070. @FW_roomsArr = sort { $sHash{$a} cmp $sHash{$b} } keys %FW_rooms;
  1071. } else {
  1072. @FW_roomsArr = sort keys %FW_rooms;
  1073. }
  1074. }
  1075. ##############################
  1076. sub
  1077. FW_makeTable($$$@)
  1078. {
  1079. my($title, $name, $hash, $cmd) = (@_);
  1080. return if(!$hash || !int(keys %{$hash}));
  1081. my $class = lc($title);
  1082. $class =~ s/[^A-Za-z]/_/g;
  1083. FW_pO "<div class='makeTable wide ".lc($title)."'>";
  1084. FW_pO "<span class='mkTitle'>$title</span>";
  1085. FW_pO "<table class=\"block wide $class\">";
  1086. my $si = AttrVal("global", "showInternalValues", 0);
  1087. my $row = 1;
  1088. my $prefix = ($title eq "Attributes" ? "a-" : "");
  1089. foreach my $n (sort keys %{$hash}) {
  1090. next if(!$si && $n =~ m/^\./); # Skip "hidden" Values
  1091. my $val = $hash->{$n};
  1092. $val = "" if(!defined($val));
  1093. $val = $hash->{$n}{NAME} # Exception
  1094. if($n eq "IODev" && ref($val) eq "HASH" && defined($hash->{$n}{NAME}));
  1095. my $r = ref($val);
  1096. next if($r && ($r ne "HASH" || !defined($hash->{$n}{VAL})));
  1097. FW_pF "<tr class=\"%s\">", ($row&1)?"odd":"even";
  1098. $row++;
  1099. if($n eq "DEF" && !$FW_hiddenroom{input}) {
  1100. FW_makeEdit($name, $n, $val);
  1101. } else {
  1102. FW_pO "<td><div class=\"dname\" data-name=\"$name\">$n</div></td>";
  1103. if(ref($val)) { #handle readings
  1104. my ($v, $t) = ($val->{VAL}, $val->{TIME});
  1105. if($v =~ m,^<html>(.*)</html>$,) {
  1106. $v = $1;
  1107. } else {
  1108. $v = FW_htmlEscape($v);
  1109. }
  1110. if($FW_ss) {
  1111. $t = ($t ? "<br><div class=\"tiny\">$t</div>" : "");
  1112. FW_pO "<td><div class=\"dval\">$v$t</div></td>";
  1113. } else {
  1114. $t = "" if(!$t);
  1115. FW_pO "<td><div class=\"dval\" informId=\"$name-$prefix$n\">$v</div></td>";
  1116. FW_pO "<td><div informId=\"$name-$prefix$n-ts\">$t</div></td>";
  1117. }
  1118. } else {
  1119. $val = FW_htmlEscape($val);
  1120. my $tattr = "informId=\"$name-$prefix$n\" class=\"dval\"";
  1121. # if possible provide some links
  1122. if ($n eq "room"){
  1123. FW_pO "<td><div $tattr>".
  1124. join(",", map { FW_pH("room=$_",$_,0,"",1,1) } split(",",$val)).
  1125. "</div></td>";
  1126. } elsif ($n =~ m/^fp_(.*)/ && $defs{$1}){ #special for Floorplan
  1127. FW_pH "detail=$1", $val,1;
  1128. } elsif ($modules{$val} ) {
  1129. FW_pH "cmd=list%20TYPE=$val", $val,1;
  1130. } else {
  1131. $val = "<pre>$val</pre>" if($val =~ m/\n/ && $title eq "Attributes");
  1132. FW_pO "<td><div $tattr>".
  1133. join(",", map { ($_ ne $name && $defs{$_}) ?
  1134. FW_pH( "detail=$_", $_ ,0,"",1,1) : $_ } split(",",$val)).
  1135. "</div></td>";
  1136. }
  1137. }
  1138. }
  1139. FW_pH "cmd.$name=$cmd $name $n&amp;detail=$name", $cmd, 1
  1140. if($cmd && !$FW_ss);
  1141. FW_pO "</tr>";
  1142. }
  1143. FW_pO "</table>";
  1144. FW_pO "</div>";
  1145. }
  1146. ##############################
  1147. # Used only for set or attr lists.
  1148. sub
  1149. FW_detailSelect(@)
  1150. {
  1151. my ($d, $cmd, $list, $param) = @_;
  1152. return "" if(!$list || $FW_hiddenroom{input});
  1153. my %al = map { s/:.*//;$_ => 1 } split(" ", $list);
  1154. my @al = sort keys %al; # remove duplicate items in list
  1155. my $selEl = (defined($al[0]) ? $al[0] : " ");
  1156. $selEl = $1 if($list =~ m/([^ ]*):slider,/); # promote a slider if available
  1157. $selEl = "room" if($list =~ m/room:/);
  1158. $list =~ s/"/&quot;/g;
  1159. my $ret ="";
  1160. my $psc = AttrVal("global", "perlSyntaxCheck", ($featurelevel>5.7) ? 1 : 0);
  1161. $ret .= "<div class='makeSelect' dev=\"$d\" cmd=\"$cmd\" list=\"$list\">";
  1162. $ret .= "<form method=\"$FW_formmethod\" ".
  1163. "action=\"$FW_ME$FW_subdir\" autocomplete=\"off\">";
  1164. $ret .= FW_hidden("detail", $d);
  1165. $ret .= FW_hidden("dev.$cmd$d", $d.($param ? " $param":""));
  1166. $ret .= FW_submit("cmd.$cmd$d", $cmd, $cmd.($psc?" psc":""));
  1167. $ret .= "<div class=\"$cmd downText\">&nbsp;$d&nbsp;".
  1168. ($param ? "&nbsp;$param":"")."</div>";
  1169. $ret .= FW_select("sel_$cmd$d","arg.$cmd$d",\@al, $selEl, $cmd);
  1170. $ret .= FW_textfield("val.$cmd$d", 30, $cmd);
  1171. $ret .= "</form></div>";
  1172. return $ret;
  1173. }
  1174. ##############################
  1175. sub
  1176. FW_doDetail($)
  1177. {
  1178. my ($d) = @_;
  1179. return if($FW_hiddenroom{detail});
  1180. return if(!defined($defs{$d}));
  1181. my $h = $defs{$d};
  1182. my $t = $h->{TYPE};
  1183. $t = "MISSING" if(!defined($t));
  1184. FW_addContent();
  1185. if($FW_ss) {
  1186. my $webCmd = AttrVal($d, "webCmd", undef);
  1187. if($webCmd) {
  1188. FW_pO "<table class=\"webcmd\">";
  1189. foreach my $cmd (split(":", $webCmd)) {
  1190. FW_pO "<tr>";
  1191. FW_pH "cmd.$d=set $d $cmd&detail=$d", $cmd, 1, "col1";
  1192. FW_pO "</tr>";
  1193. }
  1194. FW_pO "</table>";
  1195. }
  1196. }
  1197. FW_pO "<table><tr><td>";
  1198. if(!$modules{$t}{FW_detailFn} || $modules{$t}{FW_deviceOverview}) {
  1199. my $show = AttrVal($FW_wname, "deviceOverview", "always");
  1200. if( $show ne 'never' ) {
  1201. my %extPage = ();
  1202. if( $show eq 'iconOnly' ) {
  1203. my ($allSets, $cmdlist, $txt) = FW_devState($d, $FW_room, \%extPage);
  1204. FW_pO "<div informId='$d'".
  1205. ($FW_tp?"":" style='float:right'").">$txt</div>";
  1206. } else {
  1207. my $nameDisplay = AttrVal($FW_wname,"nameDisplay",undef);
  1208. my %usuallyAtEnd = ();
  1209. my $style = "";
  1210. if( $show eq 'onClick' ) {
  1211. my $pgm = "Javascript:" .
  1212. "s=document.getElementById('ddtable').style;".
  1213. "s.display = s.display=='none' ? 'block' : 'none';".
  1214. "s=document.getElementById('ddisp').style;".
  1215. "s.display = s.display=='none' ? 'block' : 'none';";
  1216. FW_pO "<div id=\"ddisp\"><br><a style=\"cursor:pointer\" ".
  1217. "onClick=\"$pgm\">Show DeviceOverview</a><br><br></div>";
  1218. $style = 'style="display:none"';
  1219. }
  1220. FW_pO "<div $style id=\"ddtable\" class='makeTable wide'>";
  1221. FW_pO "<span class='mkTitle'>DeviceOverview</span>";
  1222. FW_pO "<table class=\"block wide\">";
  1223. FW_makeDeviceLine($d,1,\%extPage,$nameDisplay,\%usuallyAtEnd);
  1224. FW_pO "</table></div>";
  1225. }
  1226. }
  1227. }
  1228. if($modules{$t}{FW_detailFn}) {
  1229. no strict "refs";
  1230. my $txt = &{$modules{$t}{FW_detailFn}}($FW_wname, $d, $FW_room);
  1231. FW_pO "</td></tr><tr><td>$txt<br>" if(defined($txt));
  1232. use strict "refs";
  1233. }
  1234. FW_pO FW_detailSelect($d, "set",
  1235. FW_widgetOverride($d, getAllSets($d, $FW_chash)));
  1236. FW_pO FW_detailSelect($d, "get",
  1237. FW_widgetOverride($d, getAllGets($d, $FW_chash)));
  1238. FW_makeTable("Internals", $d, $h);
  1239. FW_makeTable("Readings", $d, $h->{READINGS});
  1240. my $attrList = getAllAttr($d);
  1241. my $roomList = "multiple,".join(",",
  1242. sort map { $_ =~ s/ /#/g ;$_} keys %FW_rooms);
  1243. my $groupList = "multiple,".join(",",
  1244. sort map { $_ =~ s/ /#/g ;$_} keys %FW_groups);
  1245. $attrList =~ s/room /room:$roomList /;
  1246. $attrList =~ s/group /group:$groupList /;
  1247. $attrList = FW_widgetOverride($d, $attrList);
  1248. $attrList =~ s/\\/\\\\/g;
  1249. $attrList =~ s/'/\\'/g;
  1250. FW_pO FW_detailSelect($d, "attr", $attrList);
  1251. FW_makeTable("Attributes", $d, $attr{$d}, "deleteattr");
  1252. FW_makeTableFromArray("Probably associated with", "assoc", getPawList($d));
  1253. FW_pO "</td></tr></table>";
  1254. my ($link, $txt, $td, $class, $doRet,$nonl) = @_;
  1255. FW_pH "cmd=style iconFor $d", "Select icon", undef, "detLink iconFor";
  1256. FW_pH "cmd=style showDSI $d", "Extend devStateIcon", undef, "detLink showDSI";
  1257. FW_pH "cmd=rawDef $d", "Raw definition", undef, "detLink rawDef";
  1258. FW_pH "cmd=delete $d", "Delete this device ($d)", undef, "detLink delDev"
  1259. if($d ne "global");
  1260. my $sfx = AttrVal("global", "language", "EN");
  1261. $sfx = ($sfx eq "EN" ? "" : "_$sfx");
  1262. FW_pH "$FW_ME/docs/commandref${sfx}.html#${t}", "Device specific help",
  1263. undef, "detLink devSpecHelp";
  1264. FW_pO "<br><br>";
  1265. FW_pO "</div>";
  1266. }
  1267. ##############################
  1268. sub
  1269. FW_makeTableFromArray($$@) {
  1270. my ($txt,$class,@obj) = @_;
  1271. if (@obj>0) {
  1272. my $row=1;
  1273. FW_pO "<div class='makeTable wide'>";
  1274. FW_pO "<span class='mkTitle'>$txt</span>";
  1275. FW_pO "<table class=\"block wide $class\">";
  1276. foreach (sort @obj) {
  1277. FW_pF "<tr class=\"%s\"><td>", (($row++)&1)?"odd":"even";
  1278. FW_pH "detail=$_", $_;
  1279. FW_pO "</td><td>";
  1280. FW_pO $defs{$_}{STATE} if(defined($defs{$_}{STATE}));
  1281. FW_pO "</td><td>";
  1282. FW_pH "cmd=list TYPE=$defs{$_}{TYPE}", $defs{$_}{TYPE};
  1283. FW_pO "</td>";
  1284. FW_pO "</tr>";
  1285. }
  1286. FW_pO "</table></div>";
  1287. }
  1288. }
  1289. sub
  1290. FW_roomIdx($$)
  1291. {
  1292. my ($arr,$v) = @_;
  1293. my ($index) = grep { $v =~ /^$arr->[$_]$/ } 0..$#$arr;
  1294. if( !defined($index) ) {
  1295. $index = 9999;
  1296. } else {
  1297. $index = sprintf( "%03i", $index );
  1298. }
  1299. return "$index-$v";
  1300. }
  1301. ##############
  1302. # Header, Zoom-Icons & list of rooms at the left.
  1303. sub
  1304. FW_roomOverview($)
  1305. {
  1306. my ($cmd) = @_;
  1307. %FW_hiddenroom = ();
  1308. foreach my $r (split(",",AttrVal($FW_wname, "hiddenroom", ""))) {
  1309. $FW_hiddenroom{$r} = 1;
  1310. }
  1311. ##############
  1312. # LOGO
  1313. my $hasMenuScroll;
  1314. if($FW_detail && $FW_ss) {
  1315. $FW_room = AttrVal($FW_detail, "room", undef);
  1316. $FW_room = $1 if($FW_room && $FW_room =~ m/^([^,]*),/);
  1317. $FW_room = "" if(!$FW_room);
  1318. FW_pO(FW_pHPlain("room=$FW_room",
  1319. "<div id=\"back\">" . FW_makeImage("back") . "</div>"));
  1320. FW_pO "<div id=\"menu\">$FW_detail details</div>";
  1321. return;
  1322. } else {
  1323. $hasMenuScroll = 1;
  1324. FW_pO '<div id="menuScrollArea">';
  1325. FW_pH "", '<div id="logo"></div>';
  1326. }
  1327. ##############
  1328. # MENU
  1329. my (@list1, @list2);
  1330. push(@list1, ""); push(@list2, "");
  1331. if(!$FW_hiddenroom{save} && !$FW_hiddenroom{"Save config"}) {
  1332. push(@list1, "Save config");
  1333. push(@list2, "$FW_ME?cmd=save");
  1334. push(@list1, ""); push(@list2, "");
  1335. }
  1336. ########################
  1337. # Show FW Extensions in the menu
  1338. if(defined($data{FWEXT})) {
  1339. my $cnt = 0;
  1340. foreach my $k (sort keys %{$data{FWEXT}}) {
  1341. my $h = $data{FWEXT}{$k};
  1342. next if($h !~ m/HASH/ || !$h->{LINK} || !$h->{NAME});
  1343. next if($FW_hiddenroom{$h->{NAME}});
  1344. push(@list1, $h->{NAME});
  1345. push(@list2, $FW_ME ."/".$h->{LINK});
  1346. $cnt++;
  1347. }
  1348. if($cnt > 0) {
  1349. push(@list1, ""); push(@list2, "");
  1350. }
  1351. }
  1352. $FW_room = "" if(!$FW_room);
  1353. ##########################
  1354. # Rooms and other links
  1355. foreach my $r (@FW_roomsArr) {
  1356. next if($r eq "hidden" || $FW_hiddenroom{$r});
  1357. $FW_room = AttrVal($FW_wname, "defaultRoom", $r)
  1358. if(!$FW_room && $FW_ss);
  1359. push @list1, FW_htmlEscape($r);
  1360. push @list2, "$FW_ME?room=".urlEncode($r);
  1361. }
  1362. my $sfx = AttrVal("global", "language", "EN");
  1363. $sfx = ($sfx eq "EN" ? "" : "_$sfx");
  1364. my @list = (
  1365. "Everything", "$FW_ME?room=all",
  1366. "", "",
  1367. "Commandref", "$FW_ME/docs/commandref${sfx}.html",
  1368. "Remote doc", "http://fhem.de/fhem.html#Documentation",
  1369. "Edit files", "$FW_ME?cmd=style%20list",
  1370. "Select style", "$FW_ME?cmd=style%20select",
  1371. "Event monitor", "$FW_ME?cmd=style%20eventMonitor",
  1372. "", "");
  1373. my $lastname = ","; # Avoid double "".
  1374. my $lfn = "Logfile";
  1375. if($defs{$lfn}) { # Add the current Logfile to the list if defined
  1376. my @l = FW_fileList($defs{$lfn}{logfile},1);
  1377. my $fn = pop @l;
  1378. splice @list, 4,0, ("Logfile",
  1379. "$FW_ME/FileLog_logWrapper?dev=$lfn&type=text&file=$fn");
  1380. }
  1381. my @me = split(",", AttrVal($FW_wname, "menuEntries", ""));
  1382. push @list, @me, "", "" if(@me);
  1383. for(my $idx = 0; $idx < @list; $idx+= 2) {
  1384. next if($FW_hiddenroom{$list[$idx]} || $list[$idx] eq $lastname);
  1385. push @list1, $list[$idx];
  1386. push @list2, $list[$idx+1];
  1387. $lastname = $list[$idx];
  1388. }
  1389. FW_pO "<div id=\"menu\">";
  1390. FW_pO "<table>";
  1391. if($FW_ss) { # Make a selection sensitive dropdown list
  1392. FW_pO "<tr><td><select OnChange=\"location.href=" .
  1393. "this.options[this.selectedIndex].value\">";
  1394. foreach(my $idx = 0; $idx < @list1; $idx++) {
  1395. next if(!$list1[$idx]);
  1396. my $sel = ($list1[$idx] eq $FW_room ? " selected=\"selected\"" : "");
  1397. FW_pO "<option value='$list2[$idx]'$sel>$list1[$idx]</option>";
  1398. }
  1399. FW_pO "</select></td>";
  1400. FW_pO "</tr>";
  1401. } else {
  1402. my $tblnr = 1;
  1403. my $roomEscaped = FW_htmlEscape($FW_room);
  1404. foreach(my $idx = 0; $idx < @list1; $idx++) {
  1405. my ($l1, $l2) = ($list1[$idx], $list2[$idx]);
  1406. if(!$l1) {
  1407. FW_pO "</table></td></tr>" if($idx);
  1408. if($idx<int(@list1)-1) {
  1409. FW_pO "<tr><td><table class=\"room roomBlock$tblnr\">";
  1410. $tblnr++;
  1411. }
  1412. } else {
  1413. FW_pF "<tr%s>", $l1 eq $roomEscaped ? " class=\"sel\"" : "";
  1414. my $class = "menu_$l1";
  1415. $class =~ s/[^A-Z0-9]/_/gi;
  1416. # image tag if we have an icon, else empty
  1417. my $icoName = "ico$l1";
  1418. map { my ($n,$v) = split(":",$_); $icoName=$v if($l1 =~ m/^$n$/); }
  1419. split(" ", AttrVal($FW_wname, "roomIcons", ""));
  1420. my $icon = FW_iconName($icoName) ?
  1421. FW_makeImage($icoName,$icoName,"icon")."&nbsp;" : "";
  1422. if($l1 eq "Save config") {
  1423. $l1 .= '</a> <a id="saveCheck" class="changed" style="visibility:'.
  1424. (int(@structChangeHist) ? 'visible' : 'hidden').'">?';
  1425. }
  1426. # Force external browser if FHEMWEB is installed as an offline app.
  1427. my $target = ''; # Forum 33066, 39854
  1428. $target = 'target="_blank"' if($l2 =~ s/^$FW_ME\/\+/$FW_ME\//);
  1429. $target = 'target="_blank"' if($l2 =~ m/commandref|fhem.de.fhem.html/);
  1430. if($l2 =~ m/.html$/ || $l2 =~ m/^(http|javascript)/ || length($target)){
  1431. FW_pO "<td><div><a href='$l2' $target>$icon<span>$l1</span></a>".
  1432. "</div></td>";
  1433. } else {
  1434. FW_pH $l2, "$icon<span>$l1</span>", 1, $class;
  1435. }
  1436. FW_pO "</tr>";
  1437. }
  1438. }
  1439. }
  1440. FW_pO "</table>";
  1441. FW_pO "</div>";
  1442. FW_pO "</div>" if($hasMenuScroll);
  1443. ##############
  1444. # HEADER
  1445. FW_pO "<div id=\"hdr\">";
  1446. FW_pO '<table border="0" class="header"><tr><td style="padding:0">';
  1447. FW_pO "<form method=\"$FW_formmethod\" action=\"$FW_ME\">";
  1448. FW_pO FW_hidden("fw_id", $FW_id) if($FW_id);
  1449. FW_pO FW_hidden("room", $FW_room) if($FW_room);
  1450. FW_pO FW_hidden("fwcsrf", $defs{$FW_wname}{CSRFTOKEN}) if($FW_CSRF);
  1451. FW_pO FW_textfield("cmd",
  1452. AttrVal($FW_wname, "mainInputLength", $FW_ss ? 25 : 40), "maininput");
  1453. FW_pO "</form>";
  1454. FW_pO "</td></tr></table>";
  1455. FW_pO "</div>";
  1456. }
  1457. sub
  1458. FW_alias($)
  1459. {
  1460. my ($d) = @_;
  1461. if($FW_room) {
  1462. return AttrVal($d, "alias_$FW_room", AttrVal($d, "alias", $d));
  1463. } else {
  1464. return AttrVal($d, "alias", $d);
  1465. }
  1466. }
  1467. sub
  1468. FW_makeDeviceLine($$$$$)
  1469. {
  1470. my ($d,$row,$extPage,$nameDisplay,$usuallyAtEnd) = @_;
  1471. my $rf = ($FW_room ? "&amp;room=$FW_room" : ""); # stay in the room
  1472. FW_pF "\n<tr class=\"%s\">", ($row&1)?"odd":"even";
  1473. my $devName = FW_alias($d);
  1474. if(defined($nameDisplay)) {
  1475. my ($DEVICE, $ALIAS) = ($d, $devName);
  1476. $devName = eval $nameDisplay;
  1477. }
  1478. my $icon = AttrVal($d, "icon", "");
  1479. $icon = FW_makeImage($icon,$icon,"icon") . "&nbsp;" if($icon);
  1480. if($FW_hiddenroom{detail}) {
  1481. FW_pO "<td><div class=\"col1\">$icon$devName</div></td>"
  1482. if(!$usuallyAtEnd->{$d});
  1483. } else {
  1484. FW_pH "detail=$d", "$icon$devName", 1, "col1" if(!$usuallyAtEnd->{$d});
  1485. }
  1486. my ($allSets, $cmdlist, $txt) = FW_devState($d, $rf, $extPage);
  1487. if($cmdlist) {
  1488. my $cl2 = $cmdlist; $cl2 =~ s/ [^:]*//g; $cl2 =~ s/:/ /g; # Forum #74053
  1489. $allSets = "$allSets $cl2";
  1490. }
  1491. $allSets = FW_widgetOverride($d, $allSets);
  1492. my $colSpan = ($usuallyAtEnd->{$d} ? ' colspan="2"' : '');
  1493. FW_pO "<td informId=\"$d\"$colSpan>$txt</td>";
  1494. ######
  1495. # Commands, slider, dropdown
  1496. my $smallscreenCommands = AttrVal($FW_wname, "smallscreenCommands", "");
  1497. if((!$FW_ss || $smallscreenCommands) && $cmdlist) {
  1498. my @a = split("[: ]", AttrVal($d, "cmdIcon", ""));
  1499. Log 1, "ERROR: bad cmdIcon definition for $d" if(@a % 2);
  1500. my %cmdIcon = @a;
  1501. my @cl = split(":", $cmdlist);
  1502. my @wcl = split(":", AttrVal($d, "webCmdLabel", ""));
  1503. my $nRows;
  1504. $nRows = split("\n", AttrVal($d, "webCmdLabel", "")) if(@wcl);
  1505. @wcl = () if(@wcl != @cl); # some safety
  1506. for(my $i1=0; $i1<@cl; $i1++) {
  1507. my $cmd = $cl[$i1];
  1508. my $htmlTxt;
  1509. my @c = split(' ', $cmd); # @c==0 if $cmd==" ";
  1510. if(int(@c) && $allSets && $allSets =~ m/\b$c[0]:([^ ]*)/) {
  1511. my $values = $1;
  1512. foreach my $fn (sort keys %{$data{webCmdFn}}) {
  1513. no strict "refs";
  1514. $htmlTxt = &{$data{webCmdFn}{$fn}}($FW_wname,
  1515. $d, $FW_room, $cmd, $values);
  1516. use strict "refs";
  1517. last if(defined($htmlTxt));
  1518. }
  1519. }
  1520. if($htmlTxt) {
  1521. $htmlTxt =~ s,^<td[^>]*>(.*)</td>$,$1,;
  1522. } else {
  1523. my $nCmd = $cmdIcon{$cmd} ?
  1524. FW_makeImage($cmdIcon{$cmd},$cmd,"webCmd") : $cmd;
  1525. $htmlTxt = FW_pH "cmd.$d=set $d $cmd$rf", $nCmd, 0, "", 1, 1;
  1526. }
  1527. if(@wcl > $i1) {
  1528. if($nRows > 1) {
  1529. FW_pO "<td><table class='wide'><tr>" if($i1 == 0);
  1530. FW_pO "<td>$wcl[$i1]</td><td>$htmlTxt</td>";
  1531. FW_pO "</tr><tr>" if($wcl[$i1] =~ m/\n/);
  1532. FW_pO "</tr></table></td>" if($i1 == @cl-1);
  1533. } else {
  1534. FW_pO "<td><div class='col3'>$wcl[$i1]$ htmlTxt</div></td>";
  1535. }
  1536. } else {
  1537. FW_pO "<td><div class='col3'>$htmlTxt</div></td>";
  1538. }
  1539. }
  1540. }
  1541. FW_pO "</tr>";
  1542. }
  1543. sub
  1544. FW_sortIndex($)
  1545. {
  1546. my ($d) = @_;
  1547. return $d if(!$attr{$d});
  1548. my $val = $attr{$d}{sortby};
  1549. if($val) {
  1550. if($val =~ m/^{.*}/) {
  1551. my %specials=("%NAME" => $d);
  1552. my $exec = EvalSpecials($val, %specials);
  1553. return AnalyzePerlCommand($FW_chash, $exec);
  1554. }
  1555. return lc($val);
  1556. }
  1557. if($FW_room) {
  1558. $val = $attr{$d}{"alias_$FW_room"};
  1559. return $val if($val);
  1560. }
  1561. $val = $attr{$d}{"alias"};
  1562. return $val if($val);
  1563. return $d;
  1564. }
  1565. ########################
  1566. # Show the overview of devices in one room
  1567. # room can be a room, all or Unsorted
  1568. sub
  1569. FW_showRoom()
  1570. {
  1571. return if(!$FW_room);
  1572. %FW_hiddengroup = ();
  1573. foreach my $r (split(",",AttrVal($FW_wname, "hiddengroup", ""))) {
  1574. $FW_hiddengroup{$r} = 1;
  1575. }
  1576. my $hge = AttrVal($FW_wname, "hiddengroupRegexp", undef);
  1577. FW_pO "<form method=\"$FW_formmethod\" ". # Why do we need a form here?
  1578. "action=\"$FW_ME\" autocomplete=\"off\">";
  1579. FW_addContent("room='$FW_room'");
  1580. FW_pO "<table class=\"roomoverview\">"; # Need for equal width of subtables
  1581. # array of all device names in the room (exception weblinks without group
  1582. # attribute)
  1583. my @devs= grep { (($FW_rooms{$FW_room} && $FW_rooms{$FW_room}{$_}) ||
  1584. $FW_room eq "all") && !IsIgnored($_) } keys %defs;
  1585. my (%group, @atEnds, %usuallyAtEnd, %sortIndex);
  1586. foreach my $dev (@devs) {
  1587. if($modules{$defs{$dev}{TYPE}}{FW_atPageEnd}) {
  1588. $usuallyAtEnd{$dev} = 1;
  1589. if(!AttrVal($dev, "group", undef)) {
  1590. $sortIndex{$dev} = FW_sortIndex($dev);
  1591. push @atEnds, $dev;
  1592. next;
  1593. }
  1594. }
  1595. next if(!$FW_types{$dev}); # FHEMWEB connection, missed due to caching
  1596. foreach my $grp (split(",", AttrVal($dev, "group", $FW_types{$dev}))) {
  1597. next if($FW_hiddengroup{$grp});
  1598. next if($hge && $grp =~ m/$hge/);
  1599. $sortIndex{$dev} = FW_sortIndex($dev);
  1600. $group{$grp}{$dev} = 1;
  1601. }
  1602. }
  1603. # row counter
  1604. my $row=1;
  1605. my %extPage = ();
  1606. my $nameDisplay = AttrVal($FW_wname,"nameDisplay",undef);
  1607. my ($columns, $maxc) = FW_parseColumns(\%group);
  1608. FW_pO "<tr class=\"column\">" if($maxc != -1);
  1609. for(my $col=1; $col < ($maxc==-1 ? 2 : $maxc); $col++) {
  1610. FW_pO "<td><table class=\"column tblcol_$col\">" if($maxc != -1);
  1611. # iterate over the distinct groups
  1612. foreach my $g (sort { $maxc==-1 ?
  1613. $a cmp $b :
  1614. ($columns->{$a} ? $columns->{$a}->[0] : 99) <=>
  1615. ($columns->{$b} ? $columns->{$b}->[0] : 99) } keys %group) {
  1616. next if($maxc != -1 && (!$columns->{$g} || $columns->{$g}->[1] != $col));
  1617. #################
  1618. # Check if there is a device of this type in the room
  1619. FW_pO "<tr class='devTypeTr'><td><div class='devType'>$g</div></td></tr>";
  1620. FW_pO "<tr><td>";
  1621. FW_pO "<table class=\"block wide\" id=\"TYPE_$g\">";
  1622. foreach my $d (sort { $sortIndex{$a} cmp $sortIndex{$b} }
  1623. keys %{$group{$g}}) {
  1624. my $type = $defs{$d}{TYPE};
  1625. $extPage{group} = $g;
  1626. FW_makeDeviceLine($d,$row,\%extPage,$nameDisplay,\%usuallyAtEnd);
  1627. if($modules{$type}{FW_addDetailToSummary}) {
  1628. no strict "refs";
  1629. my $txt = &{$modules{$type}{FW_detailFn}}($FW_wname, $d, $FW_room);
  1630. use strict "refs";
  1631. if(defined($txt)) {
  1632. FW_pO "<tr class='".($row&1?"odd":"even").
  1633. "'><td colspan='50'>$txt</td></tr>";
  1634. }
  1635. }
  1636. $row++;
  1637. }
  1638. FW_pO "</table>";
  1639. FW_pO "</td></tr>";
  1640. }
  1641. FW_pO "</table></td>" if($maxc != -1); # Column
  1642. }
  1643. FW_pO "</tr>" if($maxc != -1);
  1644. FW_pO "</table><br>";
  1645. # Now the "atEnds"
  1646. foreach my $d (sort { $sortIndex{$a} cmp $sortIndex{$b} } @atEnds) {
  1647. no strict "refs";
  1648. $extPage{group} = "atEnd";
  1649. FW_pO &{$modules{$defs{$d}{TYPE}}{FW_summaryFn}}($FW_wname, $d,
  1650. $FW_room, \%extPage);
  1651. use strict "refs";
  1652. }
  1653. FW_pO "</div>";
  1654. FW_pO "</form>";
  1655. }
  1656. # Room1:col1group1,col1group2|col2group1,col2group2 Room2:...
  1657. sub
  1658. FW_parseColumns($)
  1659. {
  1660. my ($aGroup) = @_;
  1661. my %columns;
  1662. my $colNo = -1;
  1663. foreach my $roomgroup (split("[ \t\r\n]+", AttrVal($FW_wname,"column",""))) {
  1664. my ($room, $groupcolumn)=split(":",$roomgroup,2);
  1665. $room =~ s/%20/ /g; # Space
  1666. next if(!defined($groupcolumn) || $FW_room !~ m/^$room$/);
  1667. $colNo = 1;
  1668. my @grouplist = keys %$aGroup;
  1669. my %handled;
  1670. foreach my $groups (split(/\|/,$groupcolumn)) {
  1671. my $lineNo = 1;
  1672. foreach my $group (split(",",$groups)) {
  1673. $group =~ s/%20/ /g; # Forum #33612
  1674. $group = "^$group\$"; #71381
  1675. foreach my $g (grep /$group/ ,@grouplist) {
  1676. next if($handled{$g});
  1677. $handled{$g} = 1;
  1678. $columns{$g} = [$lineNo++, $colNo]; #23212
  1679. }
  1680. }
  1681. $colNo++;
  1682. }
  1683. last;
  1684. }
  1685. return (\%columns, $colNo);
  1686. }
  1687. #################
  1688. # return a sorted list of actual files for a given regexp
  1689. sub
  1690. FW_fileList($;$)
  1691. {
  1692. my ($fname,$mtime) = @_;
  1693. $fname =~ m,^(.*)/([^/]*)$,; # Split into dir and file
  1694. my ($dir,$re) = ($1, $2);
  1695. return $fname if(!$re);
  1696. $dir =~ s/%L/$attr{global}{logdir}/g # %L present and log directory defined
  1697. if($dir =~ m/%/ && $attr{global}{logdir});
  1698. $re =~ s/%./[A-Za-z0-9]*/g; # logfile magic (%Y, etc)
  1699. my @ret;
  1700. return @ret if(!opendir(DH, $dir));
  1701. while(my $f = readdir(DH)) {
  1702. next if($f !~ m,^$re$, || $f eq "99_Utils.pm");
  1703. push(@ret, $f);
  1704. }
  1705. closedir(DH);
  1706. return sort { (CORE::stat("$dir/$a"))[9] <=> (CORE::stat("$dir/$b"))[9] }
  1707. @ret if($mtime);
  1708. @ret = cfgDB_FW_fileList($dir,$re,@ret) if (configDBUsed());
  1709. return sort @ret;
  1710. }
  1711. ###################################
  1712. # Stream big files in chunks, to avoid bloating ourselves.
  1713. # This is a "terminal" function, no data can be appended after it is called.
  1714. sub
  1715. FW_outputChunk($$$)
  1716. {
  1717. my ($hash, $buf, $d) = @_;
  1718. $buf = $d->deflate($buf) if($d);
  1719. if( length($buf) ){
  1720. TcpServer_WriteBlocking($hash, sprintf("%x\r\n",length($buf)) .$buf."\r\n");
  1721. }
  1722. }
  1723. sub
  1724. FW_returnFileAsStream($$$$$)
  1725. {
  1726. my ($path, $suffix, $type, $doEsc, $cacheable) = @_;
  1727. my $etag;
  1728. if($cacheable) {
  1729. #Check for If-None-Match header (ETag)
  1730. my $if_none_match = $FW_httpheader{"If-None-Match"};
  1731. $if_none_match =~ s/"(.*)"/$1/ if($if_none_match);
  1732. $etag = (stat($path))[9]; #mtime
  1733. if(defined($etag) && defined($if_none_match) && $etag eq $if_none_match) {
  1734. my $now = time();
  1735. my $rsp = "Date: ".FmtDateTimeRFC1123($now)."\r\n".
  1736. "ETag: $etag\r\n".
  1737. "Expires: ".FmtDateTimeRFC1123($now+900)."\r\n";
  1738. Log3 $FW_wname, 4, "$FW_chash->{NAME} => 304 Not Modified";
  1739. TcpServer_WriteBlocking($FW_chash,"HTTP/1.1 304 Not Modified\r\n".
  1740. $rsp . $FW_headerlines . "\r\n");
  1741. return -1;
  1742. }
  1743. }
  1744. if(!open(FH, $path)) {
  1745. Log3 $FW_wname, 4, "FHEMWEB $FW_wname $path: $!";
  1746. TcpServer_WriteBlocking($FW_chash,
  1747. "HTTP/1.1 404 Not Found\r\n".
  1748. "Content-Length:0\r\n\r\n");
  1749. FW_closeConn($FW_chash);
  1750. return -1;
  1751. }
  1752. binmode(FH) if($type !~ m/text/); # necessary for Windows
  1753. my $sz = -s $path;
  1754. $etag = defined($etag) ? "ETag: \"$etag\"\r\n" : "";
  1755. my $expires = $cacheable ? ("Expires: ".gmtime(time()+900)." GMT\r\n"): "";
  1756. my $compr = ($FW_httpheader{"Accept-Encoding"} &&
  1757. $FW_httpheader{"Accept-Encoding"} =~ m/gzip/ && $FW_use_zlib) ?
  1758. "Content-Encoding: gzip\r\n" : "";
  1759. TcpServer_WriteBlocking($FW_chash, "HTTP/1.1 200 OK\r\n".
  1760. $compr . $expires . $FW_headerlines . $etag .
  1761. "Transfer-Encoding: chunked\r\n" .
  1762. "Content-Type: $type; charset=$FW_encoding\r\n\r\n");
  1763. my $d = Compress::Zlib::deflateInit(-WindowBits=>31) if($compr);
  1764. FW_outputChunk($FW_chash, $FW_RET, $d);
  1765. FW_outputChunk($FW_chash,
  1766. "<a href='#end_of_file'>jump to the end</a><br><br>", $d)
  1767. if($doEsc && $sz > 2048);
  1768. my $buf;
  1769. while(sysread(FH, $buf, 2048)) {
  1770. if($doEsc) { # FileLog special
  1771. $buf =~ s/</&lt;/g;
  1772. $buf =~ s/>/&gt;/g;
  1773. }
  1774. FW_outputChunk($FW_chash, $buf, $d);
  1775. }
  1776. close(FH);
  1777. FW_outputChunk($FW_chash, "<br/><a name='end_of_file'></a>".
  1778. "<a href='#top'>jump to the top</a><br/><br/>", $d)
  1779. if($doEsc && $sz > 2048);
  1780. FW_outputChunk($FW_chash, $suffix, $d);
  1781. if($compr) {
  1782. $buf = $d->flush();
  1783. if($buf){
  1784. TcpServer_WriteBlocking($FW_chash,
  1785. sprintf("%x\r\n",length($buf)) .$buf."\r\n");
  1786. }
  1787. }
  1788. TcpServer_WriteBlocking($FW_chash, "0\r\n\r\n");
  1789. FW_closeConn($FW_chash);
  1790. return -1;
  1791. }
  1792. ##################
  1793. sub
  1794. FW_fatal($)
  1795. {
  1796. my ($msg) = @_;
  1797. FW_pO "<html><body>$msg</body></html>";
  1798. }
  1799. ##################
  1800. sub
  1801. FW_hidden($$)
  1802. {
  1803. my ($n, $v) = @_;
  1804. return "<input type=\"hidden\" name=\"$n\" value=\"$v\"/>";
  1805. }
  1806. ##################
  1807. # Generate a select field with option list
  1808. sub
  1809. FW_select($$$$$@)
  1810. {
  1811. my ($id, $name, $valueArray, $selected, $class, $jSelFn) = @_;
  1812. $jSelFn = ($jSelFn ? "onchange=\"$jSelFn\"" : "");
  1813. $id =~ s/\./_/g if($id); # to avoid problems in JS DOM Search
  1814. $id = ($id ? "id=\"$id\" informId=\"$id\"" : "");
  1815. my $s = "<select $jSelFn $id name=\"$name\" class=\"$class\">";
  1816. foreach my $v (@{$valueArray}) {
  1817. if(defined($selected) && $v eq $selected) {
  1818. $s .= "<option selected=\"selected\" value='$v'>$v</option>\n";
  1819. } else {
  1820. $s .= "<option value='$v'>$v</option>\n";
  1821. }
  1822. }
  1823. $s .= "</select>";
  1824. return $s;
  1825. }
  1826. ##################
  1827. sub
  1828. FW_textfieldv($$$$)
  1829. {
  1830. my ($n, $z, $class, $value) = @_;
  1831. my $v;
  1832. $v=" value='$value'" if(defined($value));
  1833. return if($FW_hiddenroom{input});
  1834. my $s = "<input type='text' name='$n' class='$class' size='$z'$v ".
  1835. "autocorrect='off' autocapitalize='off'/>";
  1836. return $s;
  1837. }
  1838. sub
  1839. FW_textfield($$$)
  1840. {
  1841. return FW_textfieldv($_[0], $_[1], $_[2], "");
  1842. }
  1843. ##################
  1844. sub
  1845. FW_submit($$@)
  1846. {
  1847. my ($n, $v, $class) = @_;
  1848. $class = ($class ? "class=\"$class\"" : "");
  1849. my $s ="<input type=\"submit\" name=\"$n\" value=\"$v\" $class/>";
  1850. $s = FW_hidden("fwcsrf", $defs{$FW_wname}{CSRFTOKEN}).$s if($FW_CSRF);
  1851. return $s;
  1852. }
  1853. ##################
  1854. sub
  1855. FW_displayFileList($@)
  1856. {
  1857. my ($heading,@files)= @_;
  1858. my $hid = lc($heading);
  1859. $hid =~ s/[^A-Za-z]/_/g;
  1860. FW_pO "<div class=\"fileList $hid\">$heading</div>";
  1861. FW_pO "<table class=\"block wide fileList\">";
  1862. my $cfgDB = "";
  1863. my $row = 0;
  1864. foreach my $f (@files) {
  1865. $cfgDB = ($f =~ s,\.configDB$,,);
  1866. $cfgDB = ($cfgDB) ? "configDB" : "";
  1867. FW_pO "<tr class=\"" . ($row?"odd":"even") . "\">";
  1868. FW_pH "cmd=style edit $f $cfgDB", $f, 1;
  1869. FW_pO "</tr>";
  1870. $row = ($row+1)%2;
  1871. }
  1872. FW_pO "</table>";
  1873. FW_pO "<br>";
  1874. }
  1875. ##################
  1876. sub
  1877. FW_fileNameToPath($)
  1878. {
  1879. my $name = shift;
  1880. $attr{global}{configfile} =~ m,([^/]*)$,;
  1881. my $cfgFileName = $1;
  1882. if($name eq $cfgFileName) {
  1883. return $attr{global}{configfile};
  1884. } elsif($name =~ m/.*(js|css|_defs.svg)$/) {
  1885. return "$FW_cssdir/$name";
  1886. } elsif($name =~ m/.*(png|svg)$/) {
  1887. my $d="";
  1888. map { $d = $_ if(!$d && -d "$FW_icondir/$_") } @FW_iconDirs;
  1889. return "$FW_icondir/$d/$name";
  1890. } elsif($name =~ m/.*gplot$/) {
  1891. return "$FW_gplotdir/$name";
  1892. } else {
  1893. return "$MW_dir/$name";
  1894. }
  1895. }
  1896. ##################
  1897. # List/Edit/Save css and gnuplot files
  1898. sub
  1899. FW_style($$)
  1900. {
  1901. my ($cmd, $msg) = @_;
  1902. my @a = split(" ", $cmd);
  1903. return if(!Authorized($FW_chash, "cmd", $a[0]));
  1904. my $start = '><table><tr><td';
  1905. my $end = "</td></tr></table></div>";
  1906. if($a[1] eq "list") {
  1907. FW_addContent($start);
  1908. FW_pO "$msg<br><br>" if($msg);
  1909. $attr{global}{configfile} =~ m,([^/]*)$,;
  1910. my $cfgFileName = $1;
  1911. FW_displayFileList("config file", $cfgFileName)
  1912. if(!configDBUsed());
  1913. my $efl = AttrVal($FW_wname, 'editFileList',
  1914. "Own modules and helper files:\$MW_dir:^(.*sh|[0-9][0-9].*Util.*pm|".
  1915. ".*cfg|.*\.holiday|myUtilsTemplate.pm|.*layout)\$\n".
  1916. "Gplot files:\$FW_gplotdir:^.*gplot\$\n".
  1917. "Style files:\$FW_cssdir:^.*(css|svg)\$");
  1918. foreach my $l (split(/[\r\n]/, $efl)) {
  1919. my ($t, $v, $re) = split(":", $l, 3);
  1920. $v = eval $v;
  1921. my @fList;
  1922. if($v eq $FW_gplotdir && AttrVal($FW_wname,'showUsedFiles',0)) {
  1923. @fList = defInfo('TYPE=SVG','GPLOTFILE');
  1924. @fList = map { "$_.gplot" } @fList;
  1925. @fList = map { "$_.configDB" } @fList if configDBUsed();
  1926. my %fListUnique = map { $_, 1 } @fList;
  1927. @fList = sort keys %fListUnique;
  1928. } else {
  1929. @fList = FW_fileList("$v/$re");
  1930. }
  1931. FW_displayFileList($t, @fList);
  1932. }
  1933. FW_pO $end;
  1934. } elsif($a[1] eq "select") {
  1935. my @fl = grep { $_ !~ m/(floorplan|dashboard)/ }
  1936. FW_fileList("$FW_cssdir/.*style.css");
  1937. FW_addContent($start);
  1938. FW_pO "<div class='fileList styles'>Styles</div>";
  1939. FW_pO "<table class='block wide fileList'>";
  1940. my $row = 0;
  1941. foreach my $file (@fl) {
  1942. next if($file =~ m/svg_/);
  1943. $file =~ s/style.css//;
  1944. $file = "default" if($file eq "");
  1945. FW_pO "<tr class=\"" . ($row?"odd":"even") . "\">";
  1946. FW_pH "cmd=style set $file", "$file", 1;
  1947. FW_pO "</tr>";
  1948. $row = ($row+1)%2;
  1949. }
  1950. FW_pO "</table>$end";
  1951. } elsif($a[1] eq "set") {
  1952. if($a[2] eq "default") {
  1953. CommandDeleteAttr(undef, "$FW_wname stylesheetPrefix");
  1954. } else {
  1955. CommandAttr(undef, "$FW_wname stylesheetPrefix $a[2]");
  1956. }
  1957. $FW_styleStamp = time();
  1958. $FW_RET =~ s,/style.css\?v=\d+,/style.css?v=$FW_styleStamp,;
  1959. FW_addContent($start);
  1960. FW_pO "Reload the page in the browser.$end";
  1961. } elsif($a[1] eq "edit") {
  1962. my $fileName = $a[2];
  1963. my $data = "";
  1964. my $cfgDB = defined($a[3]) ? $a[3] : "";
  1965. my $forceType = ($cfgDB eq 'configDB') ? $cfgDB : "file";
  1966. $fileName =~ s,.*/,,g; # Little bit of security
  1967. my $filePath = FW_fileNameToPath($fileName);
  1968. my($err, @content) = FileRead({FileName=>$filePath, ForceType=>$forceType});
  1969. if($err) {
  1970. FW_addContent(">$err</div");
  1971. return;
  1972. }
  1973. $data = join("\n", @content);
  1974. $data =~ s/&/&amp;/g;
  1975. $attr{global}{configfile} =~ m,([^/]*)$,;
  1976. my $readOnly = (AttrVal($FW_wname, "editConfig", ($1 ne $fileName)) ?
  1977. "" : "readonly");
  1978. my $ncols = $FW_ss ? 40 : 80;
  1979. FW_addContent();
  1980. FW_pO "<form method=\"$FW_formmethod\">";
  1981. if($readOnly) {
  1982. FW_pO "You can enable saving this file by setting the editConfig ";
  1983. FW_pO "attribute, but read the documentation first for the side effects.";
  1984. FW_pO "<br><br>";
  1985. } else {
  1986. FW_pO FW_submit("save", "Save $fileName");
  1987. FW_pO "&nbsp;&nbsp;";
  1988. FW_pO FW_submit("saveAs", "Save as");
  1989. FW_pO FW_textfieldv("saveName", 30, "saveName", $fileName);
  1990. FW_pO "<br><br>";
  1991. }
  1992. FW_pO FW_hidden("cmd", "style save $fileName $cfgDB");
  1993. FW_pO "<textarea $readOnly name=\"data\" cols=\"$ncols\" rows=\"30\">" .
  1994. "$data</textarea>";
  1995. FW_pO "</form>";
  1996. FW_pO "</div>";
  1997. } elsif($a[1] eq "save") {
  1998. my $fileName = $a[2];
  1999. my $cfgDB = defined($a[3]) ? $a[3] : "";
  2000. $fileName = $FW_webArgs{saveName}
  2001. if($FW_webArgs{saveAs} && $FW_webArgs{saveName});
  2002. $fileName =~ s,.*/,,g; # Little bit of security
  2003. my $filePath = FW_fileNameToPath($fileName);
  2004. my $isImg = ($fileName =~ m,\.(svg|png)$,i);
  2005. my $forceType = ($cfgDB eq 'configDB' && !$isImg) ? $cfgDB : "file";
  2006. $FW_data =~ s/\r//g if(!$isImg);
  2007. my $err;
  2008. if($fileName =~ m,\.png$,) {
  2009. $err = FileWrite({FileName=>$filePath,ForceType=>$forceType,NoNL=>1},
  2010. $FW_data);
  2011. } else {
  2012. $err = FileWrite({ FileName=>$filePath, ForceType=>$forceType },
  2013. split("\n", $FW_data));
  2014. }
  2015. if($err) {
  2016. FW_addContent(">$filePath: $!</div");
  2017. return;
  2018. }
  2019. my $ret = FW_fC("rereadcfg") if($filePath eq $attr{global}{configfile});
  2020. $ret = FW_fC("reload $fileName") if($fileName =~ m,\.pm$,);
  2021. $ret = FW_Set("","","rereadicons") if($isImg);
  2022. DoTrigger("global", "FILEWRITE $filePath", 1) if(!$ret); # Forum #32592
  2023. $ret = ($ret ? "<h3>ERROR:</h3><b>$ret</b>" : "Saved $fileName");
  2024. FW_style("style list", $ret);
  2025. $ret = "";
  2026. } elsif($a[1] eq "iconFor") {
  2027. FW_iconTable("iconFor", "icon", "style setIF $a[2] %s", undef);
  2028. } elsif($a[1] eq "setIF") {
  2029. FW_fC("attr $a[2] icon $a[3]");
  2030. FW_doDetail($a[2]);
  2031. } elsif($a[1] eq "showDSI") {
  2032. FW_iconTable("devStateIcon", "",
  2033. "style addDSI $a[2] %s", "Enter value/regexp for STATE");
  2034. } elsif($a[1] eq "addDSI") {
  2035. my $dsi = AttrVal($a[2], "devStateIcon", "");
  2036. $dsi .= " " if($dsi);
  2037. FW_fC("attr $a[2] devStateIcon $dsi$FW_data:$a[3]");
  2038. FW_doDetail($a[2]);
  2039. } elsif($a[1] eq "eventMonitor") {
  2040. FW_pO "<script type=\"text/javascript\" src=\"$FW_ME/pgm2/console.js\">".
  2041. "</script>";
  2042. FW_addContent();
  2043. my $filter = $a[2] ? ($a[2] eq "log" ? "global" : $a[2]) : ".*";
  2044. FW_pO "Events (Filter: <a href=\"#\" id=\"eventFilter\">$filter</a>) ".
  2045. "&nbsp;&nbsp;<span class='fhemlog'>FHEM log ".
  2046. "<input id='eventWithLog' type='checkbox'".
  2047. ($a[2] && $a[2] eq "log" ? " checked":"")."></span>".
  2048. "&nbsp;&nbsp;<button id='eventReset'>Reset</button><br><br>\n";
  2049. FW_pO "<div id=\"console\"></div>";
  2050. FW_pO "</div>";
  2051. }
  2052. }
  2053. sub
  2054. FW_iconTable($$$$)
  2055. {
  2056. my ($name, $class, $cmdFmt, $textfield) = @_;
  2057. my %icoList = ();
  2058. foreach my $style (@FW_iconDirs) {
  2059. foreach my $imgName (sort keys %{$FW_icons{$style}}) {
  2060. $imgName =~ s/\.[^.]*$//; # Cut extension
  2061. next if(!$FW_icons{$style}{$imgName}); # Dont cut it twice: FS20.on.png
  2062. next if($FW_icons{$style}{$imgName} !~ m/$imgName/); # Skip alias
  2063. next if($imgName=~m+^(weather/|shutter.*big|fhemicon|favicon|ws_.*_kl)+);
  2064. next if($imgName=~m+^(dashboardicons)+);
  2065. $icoList{$imgName} = 1;
  2066. }
  2067. }
  2068. FW_addContent();
  2069. FW_pO "<form method=\"$FW_formmethod\">";
  2070. FW_pO "Filter:&nbsp;".FW_textfieldv("icon-filter",20,"iconTable","")."<br>";
  2071. if($textfield) {
  2072. FW_pO "$textfield:&nbsp;".FW_textfieldv("data",20,"iconTable",".*")."<br>";
  2073. }
  2074. foreach my $i (sort keys %icoList) {
  2075. FW_pF "<button title='%s' type='submit' class='dist' name='cmd' ".
  2076. "value='$cmdFmt'>%s</button>", $i, $i, FW_makeImage($i,$i,$class);
  2077. }
  2078. FW_pO "</form>";
  2079. FW_pO "</div>";
  2080. }
  2081. ##################
  2082. # print (append) to output
  2083. sub
  2084. FW_pO(@)
  2085. {
  2086. my $arg = shift;
  2087. return if(!defined($arg));
  2088. $FW_RET .= $arg;
  2089. $FW_RET .= "\n";
  2090. }
  2091. #################
  2092. # add href
  2093. sub
  2094. FW_pH(@)
  2095. {
  2096. my ($link, $txt, $td, $class, $doRet,$nonl) = @_;
  2097. my $ret;
  2098. $link .= $FW_CSRF if($link =~ m/cmd/ &&
  2099. $link !~m/cmd=style%20(list|select|eventMonitor)/);
  2100. $link = ($link =~ m,^/,) ? $link : "$FW_ME$FW_subdir?$link";
  2101. # Using onclick, as href starts safari in a webapp.
  2102. # Known issue: the pointer won't change
  2103. if($FW_ss || $FW_tp) {
  2104. $ret = "<a onClick=\"location.href='$link'\">$txt</a>";
  2105. } else {
  2106. $ret = "<a href=\"$link\">$txt</a>";
  2107. }
  2108. #actually 'div' should be removed if no class is defined
  2109. # as I can't check all code for consistancy I add nonl instead
  2110. $class = ($class)?" class=\"$class\"":"";
  2111. $ret = "<div$class>$ret</div>" if (!$nonl);
  2112. $ret = "<td>$ret</td>" if($td);
  2113. return $ret if($doRet);
  2114. FW_pO $ret;
  2115. }
  2116. #################
  2117. # href without class/div, returned as a string
  2118. sub
  2119. FW_pHPlain(@)
  2120. {
  2121. my ($link, $txt, $td) = @_;
  2122. $link = "?$link" if($link !~ m+^/+);
  2123. my $ret = "";
  2124. $ret .= "<td>" if($td);
  2125. $link .= $FW_CSRF;
  2126. if($FW_ss || $FW_tp) {
  2127. $ret .= "<a onClick=\"location.href='$FW_ME$FW_subdir$link'\">$txt</a>";
  2128. } else {
  2129. $ret .= "<a href=\"$FW_ME$FW_subdir$link\">$txt</a>";
  2130. }
  2131. $ret .= "</td>" if($td);
  2132. return $ret;
  2133. }
  2134. ##############################
  2135. sub
  2136. FW_makeImage(@)
  2137. {
  2138. my ($name, $txt, $class)= @_;
  2139. $txt = $name if(!defined($txt));
  2140. $class = "" if(!$class);
  2141. $class = "$class $name";
  2142. $class =~ s/\./_/g;
  2143. $class =~ s/@/ /g;
  2144. my $p = FW_iconPath($name);
  2145. return $name if(!$p);
  2146. if($p =~ m/\.svg$/i) {
  2147. if(open(FH, "$FW_icondir/$p")) {
  2148. my $data;
  2149. do {
  2150. $data = <FH>;
  2151. if(!defined($data)) {
  2152. Log 1, "$FW_icondir/$p is not useable";
  2153. return "";
  2154. }
  2155. } until( $data =~ m/^<svg/ );
  2156. $data .= join("", <FH>);
  2157. close(FH);
  2158. $data =~ s/[\r\n]/ /g;
  2159. $data =~ s/ *$//g;
  2160. $data =~ s/<svg/<svg class="$class" data-txt="$txt"/; #52967
  2161. $name =~ m/(@.*)$/;
  2162. my $col = $1 if($1);
  2163. if($col) {
  2164. $col =~ s/@//;
  2165. $col = "#$col" if($col =~ m/^([A-F0-9]{6})$/);
  2166. $data =~ s/fill="#000000"/fill="$col"/g;
  2167. $data =~ s/fill:#000000/fill:$col/g;
  2168. } else {
  2169. $data =~ s/fill="#000000"//g;
  2170. $data =~ s/fill:#000000//g;
  2171. }
  2172. return $data;
  2173. } else {
  2174. return $name;
  2175. }
  2176. } else {
  2177. $class = "class='$class'" if($class);
  2178. $p = urlEncodePath($p);
  2179. return "<img $class src=\"$FW_ME/images/$p\" alt=\"$txt\" title=\"$txt\">";
  2180. }
  2181. }
  2182. ####
  2183. sub
  2184. FW_IconURL($)
  2185. {
  2186. my ($name)= @_;
  2187. return "$FW_ME/icons/$name";
  2188. }
  2189. ##################
  2190. # print formatted
  2191. sub
  2192. FW_pF($@)
  2193. {
  2194. my $fmt = shift;
  2195. $FW_RET .= sprintf $fmt, @_;
  2196. }
  2197. ##################
  2198. # fhem command
  2199. sub
  2200. FW_fC($@)
  2201. {
  2202. my ($cmd, $unique) = @_;
  2203. my $ret;
  2204. if($unique) {
  2205. $ret = AnalyzeCommand($FW_chash, $cmd);
  2206. } else {
  2207. $ret = AnalyzeCommandChain($FW_chash, $cmd);
  2208. }
  2209. return $ret;
  2210. }
  2211. sub
  2212. FW_Attr(@)
  2213. {
  2214. my ($type, $devName, $attrName, @param) = @_;
  2215. my $hash = $defs{$devName};
  2216. my $sP = "stylesheetPrefix";
  2217. my $retMsg;
  2218. if($type eq "set" && $attrName eq "HTTPS") {
  2219. TcpServer_SetSSL($hash);
  2220. }
  2221. if($type eq "set") { # Converting styles
  2222. if($attrName eq "smallscreen" || $attrName eq "touchpad") {
  2223. $attr{$devName}{$sP} = $attrName;
  2224. $retMsg="$devName: attribute $attrName deprecated, converted to $sP";
  2225. $param[0] = $attrName; $attrName = $sP;
  2226. }
  2227. }
  2228. if($attrName eq $sP) {
  2229. # AttrFn is called too early, we have to set/del the attr here
  2230. if($type eq "set") {
  2231. $attr{$devName}{$sP} = (defined($param[0]) ? $param[0] : "default");
  2232. FW_readIcons($attr{$devName}{$sP});
  2233. } else {
  2234. delete $attr{$devName}{$sP};
  2235. }
  2236. }
  2237. if(($attrName eq "allowedCommands" ||
  2238. $attrName eq "basicAuth" ||
  2239. $attrName eq "basicAuthMsg")
  2240. && $type eq "set") {
  2241. my $aName = "allowed_$devName";
  2242. my $exists = ($defs{$aName} ? 1 : 0);
  2243. AnalyzeCommand(undef, "defmod $aName allowed");
  2244. AnalyzeCommand(undef, "attr $aName validFor $devName");
  2245. AnalyzeCommand(undef, "attr $aName $attrName ".join(" ",@param));
  2246. return "$devName: ".($exists ? "modifying":"creating").
  2247. " device $aName for attribute $attrName";
  2248. }
  2249. if($attrName eq "iconPath" && $type eq "set") {
  2250. foreach my $pe (split(":", $param[0])) {
  2251. $pe =~ s+\.\.++g;
  2252. FW_readIcons($pe);
  2253. }
  2254. }
  2255. if($attrName eq "JavaScripts" && $type eq "set") { # create some attributes
  2256. my (%a, @add);
  2257. map { $a{$_} = 1 } split(" ", $modules{FHEMWEB}{AttrList});
  2258. map {
  2259. $_ =~ s+.*/++; $_ =~ s/.js$//; $_ =~ s/fhem_//; $_ .= "Param";
  2260. push @add, $_ if(!$a{$_} && $_ !~ m/^-/);
  2261. } split(" ", $param[0]);
  2262. $modules{FHEMWEB}{AttrList} .= " ".join(" ",@add) if(@add);
  2263. }
  2264. if($attrName eq "csrfToken") {
  2265. return undef if($FW_csrfTokenCache{$devName} && !$init_done);
  2266. my $csrf = $param[0];
  2267. if($type eq "del" || $csrf eq "random") {
  2268. my ($x,$y) = gettimeofday();
  2269. ($csrf = "csrf_".(rand($y)*rand($x))) =~ s/[^a-z_0-9]//g;
  2270. }
  2271. if($csrf eq "none") {
  2272. delete($hash->{CSRFTOKEN});
  2273. delete($FW_csrfTokenCache{$devName});
  2274. } else {
  2275. $hash->{CSRFTOKEN} = $csrf;
  2276. $FW_csrfTokenCache{$devName} = $hash->{CSRFTOKEN};
  2277. }
  2278. }
  2279. if($attrName eq "longpoll" && $type eq "set" && $param[0] eq "websocket") {
  2280. return "$devName: Could not load Digest::SHA on startup, no websocket"
  2281. if(!$FW_use_sha);
  2282. }
  2283. return $retMsg;
  2284. }
  2285. # recursion starts at $FW_icondir/$dir
  2286. # filenames are relative to $FW_icondir
  2287. sub
  2288. FW_readIconsFrom($$)
  2289. {
  2290. my ($dir,$subdir)= @_;
  2291. my $ldir = ($subdir ? "$dir/$subdir" : $dir);
  2292. my @entries;
  2293. if(opendir(DH, "$FW_icondir/$ldir")) {
  2294. @entries= sort readdir(DH); # assures order: .gif .ico .jpg .png .svg
  2295. closedir(DH);
  2296. }
  2297. foreach my $entry (@entries) {
  2298. if( -d "$FW_icondir/$ldir/$entry" ) { # directory -> recurse
  2299. FW_readIconsFrom($dir, $subdir ? "$subdir/$entry" : $entry)
  2300. unless($entry eq "." || $entry eq ".." || $entry eq ".svn");
  2301. } else {
  2302. if($entry =~ m/^iconalias.txt$/i && open(FH, "$FW_icondir/$ldir/$entry")){
  2303. while(my $l = <FH>) {
  2304. chomp($l);
  2305. my @a = split(" ", $l);
  2306. next if($l =~ m/^#/ || @a < 2);
  2307. $FW_icons{$dir}{$a[0]} = $a[1];
  2308. }
  2309. close(FH);
  2310. } elsif($entry =~ m/(gif|ico|jpg|png|jpeg|svg)$/i) {
  2311. my $filename = $subdir ? "$subdir/$entry" : $entry;
  2312. $FW_icons{$dir}{$filename} = $filename;
  2313. my $tag = $filename; # Add it without extension too
  2314. $tag =~ s/\.[^.]*$//;
  2315. $FW_icons{$dir}{$tag} = $filename;
  2316. }
  2317. }
  2318. }
  2319. $FW_icons{$dir}{""} = 1; # Do not check empty directories again.
  2320. }
  2321. sub
  2322. FW_readIcons($)
  2323. {
  2324. my ($dir)= @_;
  2325. return if($FW_icons{$dir});
  2326. FW_readIconsFrom($dir, "");
  2327. }
  2328. # check if the icon exists, and if yes, returns its "logical" name;
  2329. sub
  2330. FW_iconName($)
  2331. {
  2332. my ($oname)= @_;
  2333. return undef if(!defined($oname));
  2334. my $name = $oname;
  2335. $name =~ s/@.*//;
  2336. foreach my $pe (@FW_iconDirs) {
  2337. return $oname if($pe && $FW_icons{$pe} && $FW_icons{$pe}{$name});
  2338. }
  2339. return undef;
  2340. }
  2341. # returns the physical absolute path relative for the logical path
  2342. # examples:
  2343. # FS20.on -> dark/FS20.on.png
  2344. # weather/sunny -> default/weather/sunny.gif
  2345. sub
  2346. FW_iconPath($)
  2347. {
  2348. my ($name) = @_;
  2349. $name =~ s/@.*//;
  2350. foreach my $pe (@FW_iconDirs) {
  2351. return "$pe/$FW_icons{$pe}{$name}"
  2352. if($pe && $FW_icons{$pe} && $FW_icons{$pe}{$name});
  2353. }
  2354. return undef;
  2355. }
  2356. sub
  2357. FW_dev2image($;$)
  2358. {
  2359. my ($name, $state) = @_;
  2360. my $d = $defs{$name};
  2361. return "" if(!$name || !$d);
  2362. my $type = $d->{TYPE};
  2363. $state = $d->{STATE} if(!defined($state));
  2364. return "" if(!$type || !defined($state));
  2365. my $model = AttrVal($name, "model", "");
  2366. my (undef, $rstate) = ReplaceEventMap($name, [undef, $state], 0);
  2367. my ($icon, $rlink);
  2368. my $devStateIcon = AttrVal($name, "devStateIcon", undef);
  2369. if(defined($devStateIcon) && $devStateIcon =~ m/^{.*}$/) {
  2370. my ($html, $link) = eval $devStateIcon;
  2371. Log3 $FW_wname, 1, "devStateIcon $name: $@" if($@);
  2372. return ($html, $link, 1) if(defined($html) && $html =~ m/^<.*>$/s);
  2373. $devStateIcon = $html;
  2374. }
  2375. if(defined($devStateIcon)) {
  2376. my @list = split(" ", $devStateIcon);
  2377. foreach my $l (@list) {
  2378. my ($re, $iconName, $link) = split(":", $l, 3);
  2379. if(defined($re) && $state =~ m/^$re$/) {
  2380. if(defined($iconName) && $iconName eq "") {
  2381. $rlink = $link;
  2382. last;
  2383. }
  2384. if(defined($iconName) && defined(FW_iconName($iconName))) {
  2385. return ($iconName, $link, 0);
  2386. } else {
  2387. return ($state, $link, 1);
  2388. }
  2389. }
  2390. }
  2391. }
  2392. $state =~ s/ .*//; # Want to be able to have icons for "on-for-timer xxx"
  2393. $icon = FW_iconName("$name.$state") if(!$icon); # lamp.Aus.png
  2394. $icon = FW_iconName("$name.$rstate") if(!$icon); # lamp.on.png
  2395. $icon = FW_iconName($name) if(!$icon); # lamp.png
  2396. $icon = FW_iconName("$model.$state") if(!$icon && $model); # fs20st.off.png
  2397. $icon = FW_iconName($model) if(!$icon && $model); # fs20st.png
  2398. $icon = FW_iconName("$type.$state") if(!$icon); # FS20.Aus.png
  2399. $icon = FW_iconName("$type.$rstate") if(!$icon); # FS20.on.png
  2400. $icon = FW_iconName($type) if(!$icon); # FS20.png
  2401. $icon = FW_iconName($state) if(!$icon); # Aus.png
  2402. $icon = FW_iconName($rstate) if(!$icon); # on.png
  2403. return ($icon, $rlink, 0);
  2404. }
  2405. sub
  2406. FW_makeEdit($$$)
  2407. {
  2408. my ($name, $n, $val) = @_;
  2409. # Toggle Edit-Window visibility script.
  2410. my $psc = AttrVal("global", "perlSyntaxCheck", ($featurelevel>5.7) ? 1 : 0);
  2411. FW_pO "<td>";
  2412. FW_pO "<a id=\"DEFa\" style=\"cursor:pointer\">$n</a>";
  2413. FW_pO "</td>";
  2414. $val =~ s,\\\n,\n,g;
  2415. $val = FW_htmlEscape($val);
  2416. my $eval = $val;
  2417. $eval = "<pre>$eval</pre>" if($eval =~ m/\n/);
  2418. FW_pO "<td>";
  2419. FW_pO "<div class=\"dval\" id=\"disp\">$eval</div>";
  2420. FW_pO "</td>";
  2421. FW_pO "</tr><tr><td colspan=\"2\">";
  2422. FW_pO "<div id=\"edit\" style=\"display:none\">";
  2423. FW_pO "<form method=\"$FW_formmethod\">";
  2424. FW_pO FW_hidden("detail", $name);
  2425. my $cmd = "modify";
  2426. my $ncols = $FW_ss ? 30 : 60;
  2427. FW_pO "<textarea name=\"val.${cmd}$name\" ".
  2428. "cols=\"$ncols\" rows=\"10\">$val</textarea>";
  2429. FW_pO "<br>" . FW_submit("cmd.${cmd}$name", "$cmd $name",($psc?"psc":""));
  2430. FW_pO "</form></div>";
  2431. FW_pO "</td>";
  2432. }
  2433. sub
  2434. FW_longpollInfo($@)
  2435. {
  2436. my $fmt = shift;
  2437. if($fmt && $fmt eq "JSON") {
  2438. my @a;
  2439. map { my $x = $_; #Forum 57377, ASCII 0-19 \ "
  2440. $x=~ s/([\x00-\x1f\x22\x5c\x7f])/sprintf '\u%04x', ord($1)/ge;
  2441. push @a,$x; } @_;
  2442. return '["'.join('","', @a).'"]';
  2443. } else {
  2444. return join('<<', @_);
  2445. }
  2446. }
  2447. sub
  2448. FW_roomStatesForInform($$)
  2449. {
  2450. my ($me, $sinceTimestamp ) = @_;
  2451. return "" if($me->{inform}{type} !~ m/status/);
  2452. my %extPage = ();
  2453. my @data;
  2454. foreach my $dn (keys %{$me->{inform}{devices}}) {
  2455. next if(!defined($defs{$dn}));
  2456. my $t = $defs{$dn}{TYPE};
  2457. next if(!$t || $modules{$t}{FW_atPageEnd});
  2458. my $lastChanged = OldTimestamp( $dn );
  2459. next if(!defined($lastChanged) || $lastChanged lt $sinceTimestamp);
  2460. my ($allSet, $cmdlist, $txt) = FW_devState($dn, "", \%extPage);
  2461. if($defs{$dn} && $defs{$dn}{STATE} && $defs{$dn}{TYPE} ne "weblink") {
  2462. push @data,
  2463. FW_longpollInfo($me->{inform}{fmt}, $dn, $defs{$dn}{STATE}, $txt);
  2464. }
  2465. }
  2466. my $data = join("\n", map { s/\n/ /gm; $_ } @data)."\n";
  2467. return $data;
  2468. }
  2469. sub
  2470. FW_logInform($$)
  2471. {
  2472. my ($me, $msg) = @_; # _NO_ Log3 here!
  2473. my $ntfy = $defs{$me};
  2474. if(!$ntfy) {
  2475. delete $logInform{$me};
  2476. return;
  2477. }
  2478. $msg = FW_htmlEscape($msg);
  2479. if(!FW_addToWritebuffer($ntfy, "<div class='fhemlog'>$msg</div>") ){
  2480. TcpServer_Close($ntfy, 1);
  2481. delete $logInform{$me};
  2482. }
  2483. }
  2484. sub
  2485. FW_Notify($$)
  2486. {
  2487. my ($ntfy, $dev) = @_;
  2488. my $h = $ntfy->{inform};
  2489. return undef if(!$h);
  2490. my $isStatus = ($h->{type} =~ m/status/);
  2491. my $events;
  2492. my $dn = $dev->{NAME};
  2493. if($dn eq "global" && $isStatus) {
  2494. my $vs = int(@structChangeHist) ? 'visible' : 'hidden';
  2495. my $data = FW_longpollInfo($h->{fmt},
  2496. "#FHEMWEB:$ntfy->{NAME}","\$('#saveCheck').css('visibility','$vs')","");
  2497. FW_addToWritebuffer($ntfy, $data."\n");
  2498. if($dev->{CHANGED}) {
  2499. $dn = $1 if($dev->{CHANGED}->[0] =~ m/^MODIFIED (.*)$/);
  2500. if($dev->{CHANGED}->[0] =~ m/^ATTR ([^ ]+) ([^ ]+) (.*)$/s) {
  2501. $dn = $1;
  2502. my @a = ("a-$2: $3");
  2503. $events = \@a;
  2504. }
  2505. }
  2506. }
  2507. if($dn eq $ntfy->{SNAME} &&
  2508. $dev->{CHANGED} &&
  2509. $dev->{CHANGED}->[0] =~ m/^JS(#([^:]*))?:(.*)$/) {
  2510. my $data = $3;
  2511. return if( $2 && $ntfy->{PEER} !~ m/$2/ );
  2512. $data = FW_longpollInfo($h->{fmt}, "#FHEMWEB:$ntfy->{NAME}",$data,"");
  2513. FW_addToWritebuffer($ntfy, $data."\n");
  2514. return;
  2515. }
  2516. return undef if($isStatus && !$h->{devices}{$dn});
  2517. my @data;
  2518. my %extPage;
  2519. my $isRaw = ($h->{type} =~ m/raw/);
  2520. $events = deviceEvents($dev, AttrVal($FW_wname, "addStateEvent",!$isRaw))
  2521. if(!$events);
  2522. if($isStatus) {
  2523. # Why is saving this stuff needed? FLOORPLAN?
  2524. my @old = ($FW_wname, $FW_ME, $FW_ss, $FW_tp, $FW_subdir);
  2525. $FW_wname = $ntfy->{SNAME};
  2526. $FW_ME = "/" . AttrVal($FW_wname, "webname", "fhem");
  2527. $FW_subdir = ($h->{iconPath} ? "/floorplan/$h->{iconPath}" : ""); # 47864
  2528. $FW_sp = AttrVal($FW_wname, "stylesheetPrefix", 0);
  2529. $FW_ss = ($FW_sp =~ m/smallscreen/);
  2530. $FW_tp = ($FW_sp =~ m/smallscreen|touchpad/);
  2531. @FW_iconDirs = grep { $_ } split(":", AttrVal($FW_wname, "iconPath",
  2532. "$FW_sp:default:fhemSVG:openautomation"));
  2533. if($h->{iconPath}) {
  2534. unshift @FW_iconDirs, $h->{iconPath};
  2535. FW_readIcons($h->{iconPath});
  2536. }
  2537. if( !$modules{$defs{$dn}{TYPE}}{FW_atPageEnd} ) {
  2538. my ($allSet, $cmdlist, $txt) = FW_devState($dn, "", \%extPage);
  2539. ($FW_wname, $FW_ME, $FW_ss, $FW_tp, $FW_subdir) = @old;
  2540. push @data, FW_longpollInfo($h->{fmt}, $dn, $dev->{STATE}, $txt);
  2541. }
  2542. #Add READINGS
  2543. if($events) { # It gets deleted sometimes (?)
  2544. my $tn = TimeNow();
  2545. my $max = int(@{$events});
  2546. for(my $i = 0; $i < $max; $i++) {
  2547. if($events->[$i] !~ /: /) {
  2548. if($dev->{NAME} eq 'global') { # Forum #47634
  2549. my($type,$args) = split(' ', $events->[$i], 2);
  2550. $args = "" if(!defined($args)); # global SAVE
  2551. push @data, FW_longpollInfo($h->{fmt}, "$dn-$type", $args, $args);
  2552. }
  2553. next; #ignore 'set' commands
  2554. }
  2555. my ($readingName,$readingVal) = split(": ",$events->[$i],2);
  2556. next if($readingName !~ m/^[A-Za-z\d_\.\-\/:]+$/); # Forum #70608,70844
  2557. push @data, FW_longpollInfo($h->{fmt},
  2558. "$dn-$readingName", $readingVal,$readingVal);
  2559. push @data, FW_longpollInfo($h->{fmt}, "$dn-$readingName-ts", $tn, $tn);
  2560. }
  2561. }
  2562. }
  2563. if($isRaw) {
  2564. if($events) { # It gets deleted sometimes (?)
  2565. my $tn = TimeNow();
  2566. if($attr{global}{mseclog}) {
  2567. my ($seconds, $microseconds) = gettimeofday();
  2568. $tn .= sprintf(".%03d", $microseconds/1000);
  2569. }
  2570. my $max = int(@{$events});
  2571. my $dt = $dev->{TYPE};
  2572. for(my $i = 0; $i < $max; $i++) {
  2573. my $line = "$tn $dt $dn ".$events->[$i]."<br>";
  2574. eval {
  2575. my $ok;
  2576. if($h->{filterType} && $h->{filterType} eq "notify") {
  2577. $ok = ($dn =~ m/^$h->{filter}$/ ||
  2578. "$dn:$events->[$i]" =~ m/^$h->{filter}$/) ;
  2579. } else {
  2580. $ok = ($line =~ m/$h->{filter}/) ;
  2581. }
  2582. push @data,$line if($ok);
  2583. }
  2584. }
  2585. }
  2586. }
  2587. if(@data){
  2588. if(!FW_addToWritebuffer($ntfy,
  2589. join("\n", map { s/\n/ /gm; $_ } @data)."\n") ){
  2590. my $name = $ntfy->{NAME};
  2591. Log3 $name, 4, "Closing connection $name due to full buffer in FW_Notify";
  2592. TcpServer_Close($ntfy, 1);
  2593. }
  2594. }
  2595. return undef;
  2596. }
  2597. sub
  2598. FW_directNotify($@) # Notify without the event overhead (Forum #31293)
  2599. {
  2600. my $filter;
  2601. if($_[0] =~ m/^FILTER=(.*)/) {
  2602. $filter = "^$1\$";
  2603. shift;
  2604. }
  2605. my $dev = $_[0];
  2606. foreach my $ntfy (values(%defs)) {
  2607. next if(!$ntfy->{TYPE} ||
  2608. $ntfy->{TYPE} ne "FHEMWEB" ||
  2609. !$ntfy->{inform} ||
  2610. !$ntfy->{inform}{devices}{$dev} ||
  2611. $ntfy->{inform}{type} ne "status");
  2612. next if($filter && $ntfy->{inform}{filter} !~ m/$filter/);
  2613. if(!FW_addToWritebuffer($ntfy,
  2614. FW_longpollInfo($ntfy->{inform}{fmt}, @_)."\n")) {
  2615. my $name = $ntfy->{NAME};
  2616. Log3 $name, 4, "Closing connection $name due to full buffer in FW_Notify";
  2617. TcpServer_Close($ntfy, 1);
  2618. }
  2619. }
  2620. }
  2621. ###################
  2622. # Compute the state (==second) column
  2623. sub
  2624. FW_devState($$@)
  2625. {
  2626. my ($d, $rf, $extPage) = @_;
  2627. my ($hasOnOff, $link);
  2628. my $cmdList = AttrVal($d, "webCmd", "");
  2629. my $allSets = FW_widgetOverride($d, getAllSets($d, $FW_chash));
  2630. my $state = $defs{$d}{STATE};
  2631. $state = "" if(!defined($state));
  2632. $hasOnOff = ($allSets =~ m/(^| )on(:[^ ]*)?( |$)/ &&
  2633. $allSets =~ m/(^| )off(:[^ ]*)?( |$)/);
  2634. my $txt = $state;
  2635. my $dsi = ($attr{$d} && ($attr{$d}{stateFormat} || $attr{$d}{devStateIcon}));
  2636. if(AttrVal($d, "showtime", undef)) {
  2637. my $v = $defs{$d}{READINGS}{state}{TIME};
  2638. $txt = $v if(defined($v));
  2639. } elsif(!$dsi && $allSets =~ m/\bdesired-temp:/) {
  2640. $txt = "$1 &deg;C" if($txt =~ m/^measured-temp: (.*)/); # FHT fix
  2641. $cmdList = "desired-temp" if(!$cmdList);
  2642. } elsif(!$dsi && $allSets =~ m/\bdesiredTemperature:/) {
  2643. $txt = ReadingsVal($d, "temperature", ""); # ignores stateFormat!!!
  2644. $txt =~ s/ .*//;
  2645. $txt .= "&deg;C";
  2646. $cmdList = "desiredTemperature" if(!$cmdList);
  2647. } else {
  2648. my ($icon, $isHtml);
  2649. ($icon, $link, $isHtml) = FW_dev2image($d);
  2650. $txt = ($isHtml ? $icon : FW_makeImage($icon, $state)) if($icon);
  2651. my $cmdlist = (defined($link) ? $link : "");
  2652. my $h = "";
  2653. foreach my $cmd (split(":", $cmdlist)) {
  2654. my $htmlTxt;
  2655. my @c = split(' ', $cmd); # @c==0 if $cmd==" ";
  2656. if(int(@c) && $allSets && $allSets =~ m/\b$c[0]:([^ ]*)/) {
  2657. my $values = $1;
  2658. foreach my $fn (sort keys %{$data{webCmdFn}}) {
  2659. no strict "refs";
  2660. $htmlTxt = &{$data{webCmdFn}{$fn}}($FW_wname,
  2661. $d, $FW_room, $cmd, $values);
  2662. use strict "refs";
  2663. last if(defined($htmlTxt));
  2664. }
  2665. }
  2666. if( $htmlTxt ) {
  2667. $h .= "<p>$htmlTxt</p>";
  2668. }
  2669. }
  2670. if( $h ) {
  2671. $link = undef;
  2672. $h =~ s/'/\\"/g;
  2673. $txt = "<a onClick='FW_okDialog(\"$h\",this)'\>$txt</a>";
  2674. } else {
  2675. $link = "cmd.$d=set $d $link" if(defined($link));
  2676. }
  2677. }
  2678. if($hasOnOff) {
  2679. # Have to cover: "on:An off:Aus", "A0:Aus AI:An Aus:off An:on"
  2680. my $on = ReplaceEventMap($d, "on", 1);
  2681. my $off = ReplaceEventMap($d, "off", 1);
  2682. $link = "cmd.$d=set $d " . ($state eq $on ? $off : $on) if(!defined($link));
  2683. $cmdList = "$on:$off" if(!$cmdList);
  2684. }
  2685. if(defined($link)) { # Have command to execute
  2686. my $room = AttrVal($d, "room", undef);
  2687. if($room) {
  2688. if($FW_room && $room =~ m/\b$FW_room\b/) {
  2689. $room = $FW_room;
  2690. } else {
  2691. $room =~ s/,.*//;
  2692. }
  2693. $link .= "&room=".urlEncode($room);
  2694. }
  2695. $txt = "<a href=\"$FW_ME$FW_subdir?$link$rf$FW_CSRF\">$txt</a>"
  2696. if($link !~ m/ noFhemwebLink\b/);
  2697. }
  2698. my $style = AttrVal($d, "devStateStyle", "");
  2699. $state =~ s/"//g;
  2700. $txt = "<div id=\"$d\" $style title=\"$state\" class=\"col2\">$txt</div>";
  2701. my $type = $defs{$d}{TYPE};
  2702. my $sfn = $modules{$type}{FW_summaryFn};
  2703. if($sfn) {
  2704. if(!defined($extPage)) {
  2705. my %hash;
  2706. $extPage = \%hash;
  2707. }
  2708. no strict "refs";
  2709. my $newtxt = &{$sfn}($FW_wname, $d, $FW_room, $extPage);
  2710. use strict "refs";
  2711. $txt = $newtxt if(defined($newtxt)); # As specified
  2712. }
  2713. return ($allSets, $cmdList, $txt);
  2714. }
  2715. sub
  2716. FW_Get($@)
  2717. {
  2718. my ($hash, @a) = @_;
  2719. my $arg = (defined($a[1]) ? $a[1] : "");
  2720. if($arg eq "icon") {
  2721. return "need one icon as argument" if(int(@a) != 3);
  2722. my $ofn = $FW_wname;
  2723. $FW_wname = $hash->{NAME};
  2724. my $icon = FW_iconPath($a[2]);
  2725. $FW_wname = $ofn;
  2726. return defined($icon) ? "$FW_icondir/$icon" : "no such icon";
  2727. } elsif($arg eq "pathlist") {
  2728. return "web server root: $FW_dir\n".
  2729. "icon directory: $FW_icondir\n".
  2730. "css directory: $FW_cssdir\n".
  2731. "gplot directory: $FW_gplotdir";
  2732. } else {
  2733. return "Unknown argument $arg choose one of icon pathlist:noArg";
  2734. }
  2735. }
  2736. #####################################
  2737. sub
  2738. FW_Set($@)
  2739. {
  2740. my ($hash, @a) = @_;
  2741. my %cmd = ("rereadicons" => 1, "clearSvgCache" => 1);
  2742. return "no set value specified" if(@a < 2);
  2743. return ("Unknown argument $a[1], choose one of ".
  2744. join(" ", map { "$_:noArg" } sort keys %cmd))
  2745. if(!$cmd{$a[1]});
  2746. if($a[1] eq "rereadicons") {
  2747. my @dirs = keys %FW_icons;
  2748. %FW_icons = ();
  2749. foreach my $d (@dirs) {
  2750. FW_readIcons($d);
  2751. }
  2752. }
  2753. if($a[1] eq "clearSvgCache") {
  2754. my $cDir = "$FW_dir/SVGcache";
  2755. if(opendir(DH, $cDir)) {
  2756. map { my $n="$cDir/$_"; unlink($n) if(-f $n); } readdir(DH);
  2757. closedir(DH);
  2758. } else {
  2759. return "Can't open $cDir: $!";
  2760. }
  2761. }
  2762. return undef;
  2763. }
  2764. #####################################
  2765. sub
  2766. FW_closeInactiveClients()
  2767. {
  2768. my $now = time();
  2769. foreach my $dev (keys %defs) {
  2770. next if(!$defs{$dev}{TYPE} || $defs{$dev}{TYPE} ne "FHEMWEB" ||
  2771. !$defs{$dev}{LASTACCESS} || $defs{$dev}{inform} ||
  2772. ($now - $defs{$dev}{LASTACCESS}) < 60);
  2773. Log3 $FW_wname, 4, "Closing inactive connection $dev";
  2774. FW_Undef($defs{$dev}, undef);
  2775. delete $defs{$dev};
  2776. delete $attr{$dev};
  2777. }
  2778. InternalTimer($now+60, "FW_closeInactiveClients", 0, 0);
  2779. }
  2780. sub
  2781. FW_htmlEscape($)
  2782. {
  2783. my ($txt) = @_;
  2784. $txt =~ s/&/&amp;/g;
  2785. $txt =~ s/</&lt;/g;
  2786. $txt =~ s/>/&gt;/g;
  2787. $txt =~ s/'/&apos;/g;
  2788. # $txt =~ s/\n/<br>/g;
  2789. return $txt;
  2790. }
  2791. ###########################
  2792. # Widgets START
  2793. sub
  2794. FW_widgetFallbackFn()
  2795. {
  2796. my ($FW_wname, $d, $FW_room, $cmd, $values) = @_;
  2797. # webCmd "temp 30" should remain text
  2798. # noArg is needed for fhem.cfg.demo / Cinema
  2799. return "" if(!$values || $values eq "noArg");
  2800. my($reading) = split( ' ', $cmd, 2 );
  2801. my $current;
  2802. if($cmd eq "desired-temp" || $cmd eq "desiredTemperature") {
  2803. $current = ReadingsVal($d, $cmd, 20);
  2804. $current =~ s/ .*//; # Cut off Celsius
  2805. $current = sprintf("%2.1f", int(2*$current)/2) if($current =~ m/[0-9.-]/);
  2806. } else {
  2807. $current = ReadingsVal($d, $reading, undef);
  2808. if( !defined($current) ) {
  2809. $reading = 'state';
  2810. $current = Value($d);
  2811. }
  2812. $current =~ s/$cmd //;
  2813. $current = ReplaceEventMap($d, $current, 1);
  2814. }
  2815. return "<td><div class='fhemWidget' cmd='$cmd' reading='$reading' ".
  2816. "dev='$d' arg='$values' current='$current'></div></td>";
  2817. }
  2818. # Widgets END
  2819. ###########################
  2820. sub
  2821. FW_visibleDevices(;$)
  2822. {
  2823. my($FW_wname) = @_;
  2824. my %devices = ();
  2825. foreach my $d (sort keys %defs) {
  2826. next if(!defined($defs{$d}));
  2827. my $h = $defs{$d};
  2828. next if(!$h->{TEMPORARY});
  2829. next if($h->{TYPE} ne "FHEMWEB");
  2830. next if(defined($FW_wname) && $h->{SNAME} ne $FW_wname);
  2831. next if(!defined($h->{inform}));
  2832. @devices{ keys %{$h->{inform}->{devices}} } =
  2833. values %{$h->{inform}->{devices}};
  2834. }
  2835. return %devices;
  2836. }
  2837. sub
  2838. FW_ActivateInform($;$)
  2839. {
  2840. my ($cl, $arg) = @_;
  2841. $FW_activateInform = ($arg ? $arg : 1);
  2842. }
  2843. sub
  2844. FW_widgetOverride($$)
  2845. {
  2846. my ($d, $str) = @_;
  2847. return $str if(!$str);
  2848. my $da = AttrVal($d, "widgetOverride", "");
  2849. my $fa = AttrVal($FW_wname, "widgetOverride", "");
  2850. return $str if(!$da && !$fa);
  2851. my @list;
  2852. push @list, split(" ", $fa) if($fa);
  2853. push @list, split(" ", $da) if($da);
  2854. foreach my $na (@list) {
  2855. my ($n,$a) = split(":", $na, 2);
  2856. $str =~ s/\b($n)\b(:[^ ]*)?/$1:$a/g;
  2857. }
  2858. return $str;
  2859. }
  2860. 1;
  2861. =pod
  2862. =item helper
  2863. =item summary HTTP Server and FHEM Frontend
  2864. =item summary_DE HTTP Server und FHEM Frontend
  2865. =begin html
  2866. <a name="FHEMWEB"></a>
  2867. <h3>FHEMWEB</h3>
  2868. <ul>
  2869. FHEMWEB is the builtin web-frontend, it also implements a simple web
  2870. server (optionally with Basic-Auth and HTTPS).
  2871. <br> <br>
  2872. <a name="FHEMWEBdefine"></a>
  2873. <b>Define</b>
  2874. <ul>
  2875. <code>define &lt;name&gt; FHEMWEB &lt;tcp-portnr&gt; [global|IP]</code>
  2876. <br><br>
  2877. Enable the webfrontend on port &lt;tcp-portnr&gt;. If global is specified,
  2878. then requests from all interfaces (not only localhost / 127.0.0.1) are
  2879. serviced. If IP is specified, then FHEMWEB will only listen on this IP.<br>
  2880. To enable listening on IPV6 see the comments <a href="#telnet">here</a>.
  2881. <br>
  2882. </ul>
  2883. <br>
  2884. <a name="FHEMWEBset"></a>
  2885. <b>Set</b>
  2886. <ul>
  2887. <li>rereadicons<br>
  2888. reads the names of the icons from the icon path. Use after adding or
  2889. deleting icons.
  2890. </li>
  2891. <li>clearSvgCache<br>
  2892. delete all files found in the www/SVGcache directory, which is used to
  2893. cache SVG data, if the SVGcache attribute is set.
  2894. </li>
  2895. </ul>
  2896. <br>
  2897. <a name="FHEMWEBget"></a>
  2898. <b>Get</b>
  2899. <ul>
  2900. <li>icon &lt;logical icon&gt;<br>
  2901. returns the absolute path to the logical icon. Example:
  2902. <ul>
  2903. <code>get myFHEMWEB icon FS20.on<br>
  2904. /data/Homeautomation/fhem/FHEM/FS20.on.png
  2905. </code>
  2906. </ul>
  2907. </li>
  2908. <li>pathlist<br>
  2909. return FHEMWEB specific directories, where files for given types are
  2910. located
  2911. <br><br>
  2912. </ul>
  2913. <a name="FHEMWEBattr"></a>
  2914. <b>Attributes</b>
  2915. <ul>
  2916. <a name="addHtmlTitle"></a>
  2917. <li>addHtmlTitle<br>
  2918. If set to 0, do not add a title Attribute to the set/get/attr detail
  2919. widgets. This might be necessary for some screenreaders. Default is 1.
  2920. </li><br>
  2921. <li><a href="#addStateEvent">addStateEvent</a></li><br>
  2922. <li>alias_&lt;RoomName&gt;<br>
  2923. If you define a userattr alias_&lt;RoomName&gt; and set this attribute
  2924. for a device assgined to &lt;RoomName&gt;, then this value will be used
  2925. when displaying &lt;RoomName&gt;.<br>
  2926. Note: you can use the userattr alias_.* to allow all rooms, but in this
  2927. case the attribute dropdown in the device detail view won't work for the
  2928. alias_.* attributes.
  2929. </li><br>
  2930. <li><a href="#allowfrom">allowfrom</a></li>
  2931. </li><br>
  2932. <li>allowedCommands, basicAuth, basicAuthMsg<br>
  2933. Please create these attributes for the corresponding <a
  2934. href="#allowed">allowed</a> device, they are deprecated for the FHEMWEB
  2935. instance from now on.
  2936. </li><br>
  2937. <li>allowedHttpMethods<br>
  2938. FHEMWEB implements the GET, POST and OPTIONS HTTP methods. Some external
  2939. devices require the HEAD method, which is not implemented correctly in
  2940. FHEMWEB, as FHEMWEB always returns a body, which, according to the spec,
  2941. is wrong. As in some cases this not a problem, enabling GET may work.
  2942. To do this, set this attribute to GET|POST|HEAD, default ist GET|POST.
  2943. OPTIONS is always enabled.
  2944. </li><br>
  2945. <a name="closeConn"></a>
  2946. <li>closeConn<br>
  2947. If set, a TCP Connection will only serve one HTTP request. Seems to
  2948. solve problems on iOS9 for WebApp startup.
  2949. </li><br>
  2950. <a name="column"></a>
  2951. <li>column<br>
  2952. Allows to display more than one column per room overview, by specifying
  2953. the groups for the columns. Example:<br>
  2954. <ul><code>
  2955. attr WEB column LivingRoom:FS20,notify|FHZ,notify DiningRoom:FS20|FHZ
  2956. </code></ul>
  2957. In this example in the LivingRoom the FS20 and the notify group is in
  2958. the first column, the FHZ and the notify in the second.<br>
  2959. Notes: some elements like SVG plots and readingsGroup can only be part of
  2960. a column if they are part of a <a href="#group">group</a>.
  2961. This attribute can be used to sort the groups in a room, just specify
  2962. the groups in one column.
  2963. Space in the room and group name has to be written as %20 for this
  2964. attribute. Both the room name and the groups are regular expressions.
  2965. </li>
  2966. <br>
  2967. <a name="confirmDelete"></a>
  2968. <li>confirmDelete<br>
  2969. confirm delete actions with a dialog. Default is 1, set it to 0 to
  2970. disable the feature.
  2971. </li>
  2972. <br>
  2973. <a name="confirmJSError"></a>
  2974. <li>confirmJSError<br>
  2975. JavaScript errors are reported in a dialog as default.
  2976. Set this attribute to 0 to disable the reporting.
  2977. </li>
  2978. <br>
  2979. <a name="CORS"></a>
  2980. <li>CORS<br>
  2981. If set to 1, FHEMWEB will supply a "Cross origin resource sharing"
  2982. header, see the wikipedia for details.
  2983. </li>
  2984. <br>
  2985. <a name="csrfToken"></a>
  2986. <li>csrfToken<br>
  2987. If set, FHEMWEB requires the value of this attribute as fwcsrf Parameter
  2988. for each command. It is used as countermeasure for Cross Site Resource
  2989. Forgery attacks. If the value is random, then a random number will be
  2990. generated on each FHEMWEB start. If it is set to the literal string
  2991. none, no token is expected. Default is random for featurelevel 5.8 and
  2992. greater, and none for featurelevel below 5.8 </li><br>
  2993. <a name="csrfTokenHTTPHeader"></a>
  2994. <li>csrfTokenHTTPHeader<br>
  2995. If set (default), FHEMWEB sends the token with the X-FHEM-csrfToken HTTP
  2996. header, which is used by some clients. Set it to 0 to switch it off, as
  2997. a measurre against shodan.io like FHEM-detection.</li><br>
  2998. <a name="CssFiles"></a>
  2999. <li>CssFiles<br>
  3000. Space separated list of .css files to be included. The filenames
  3001. are relative to the www directory. Example:
  3002. <ul><code>
  3003. attr WEB CssFiles pgm2/mystyle.css
  3004. </code></ul>
  3005. </li><br>
  3006. <a name="Css"></a>
  3007. <li>Css<br>
  3008. CSS included in the header after the CssFiles section.
  3009. </li><br>
  3010. <a name="cmdIcon"></a>
  3011. <li>cmdIcon<br>
  3012. Space separated list of cmd:iconName pairs. If set, the webCmd text is
  3013. replaced with the icon. An easy method to set this value is to use
  3014. "Extend devStateIcon" in the detail-view, and copy its value.<br>
  3015. Example:<ul>
  3016. attr lamp cmdIcon on:control_centr_arrow_up off:control_centr_arrow_down
  3017. </ul>
  3018. </li><br>
  3019. <a name="defaultRoom"></a>
  3020. <li>defaultRoom<br>
  3021. show the specified room if no room selected, e.g. on execution of some
  3022. commands. If set hides the <a href="#motd">motd</a>. Example:<br>
  3023. attr WEB defaultRoom Zentrale
  3024. </li>
  3025. <br>
  3026. <a name="devStateIcon"></a>
  3027. <li>devStateIcon<br>
  3028. First form:<br>
  3029. <ul>
  3030. Space separated list of regexp:icon-name:cmd triples, icon-name and cmd
  3031. may be empty.<br>
  3032. If the state of the device matches regexp, then icon-name will be
  3033. displayed as the status icon in the room, and (if specified) clicking
  3034. on the icon executes cmd. If fhem cannot find icon-name, then the
  3035. status text will be displayed.
  3036. Example:<br>
  3037. <ul>
  3038. attr lamp devStateIcon on:closed off:open<br>
  3039. attr lamp devStateIcon on::A0 off::AI<br>
  3040. attr lamp devStateIcon .*:noIcon<br>
  3041. </ul>
  3042. Note: if the image is referencing an SVG icon, then you can use the
  3043. @colorname suffix to color the image. E.g.:<br>
  3044. <ul>
  3045. attr Fax devStateIcon on:control_building_empty@red
  3046. off:control_building_filled:278727
  3047. </ul>
  3048. If the cmd is noFhemwebLink, then no HTML-link will be generated, i.e.
  3049. nothing will happen when clicking on the icon or text.
  3050. </ul>
  3051. Second form:<br>
  3052. <ul>
  3053. Perl code enclosed in {}. If the code returns undef, then the default
  3054. icon is used, if it retuns a string enclosed in <>, then it is
  3055. interpreted as an html string. Else the string is interpreted as a
  3056. devStateIcon of the first fom, see above.
  3057. Example:<br>
  3058. {'&lt;div
  3059. style="width:32px;height:32px;background-color:green"&gt;&lt;/div&gt;'}
  3060. </ul>
  3061. </li>
  3062. <br>
  3063. <a name="devStateStyle"></a>
  3064. <li>devStateStyle<br>
  3065. Specify an HTML style for the given device, e.g.:<br>
  3066. <ul>
  3067. attr sensor devStateStyle style="text-align:left;;font-weight:bold;;"<br>
  3068. </ul>
  3069. </li>
  3070. <br>
  3071. <li>deviceOverview<br>
  3072. Configures if the device line from the room view (device icon, state
  3073. icon and webCmds/cmdIcons) should also be shown in the device detail
  3074. view. Can be set to always, onClick, iconOnly or never. Default is
  3075. always.
  3076. </li><br>
  3077. <a name="editConfig"></a>
  3078. <li>editConfig<br>
  3079. If this FHEMWEB attribute is set to 1, then you will be able to edit
  3080. the FHEM configuration file (fhem.cfg) in the "Edit files" section.
  3081. After saving this file a rereadcfg is executed automatically, which has
  3082. a lot of side effects.<br>
  3083. </li><br>
  3084. <a name="editFileList"></a>
  3085. <li>editFileList<br>
  3086. Specify the list of Files shown in "Edit Files" section. It is a
  3087. newline separated list of triples, the first is the Title, the next is
  3088. the directory to search for, the third the regular expression. Default
  3089. is:
  3090. <ul>
  3091. <code>
  3092. Own modules and helper files:$MW_dir:^(.*sh|[0-9][0-9].*Util.*pm|.*cfg|.*holiday|myUtilsTemplate.pm|.*layout)$<br>
  3093. Gplot files:$FW_gplotdir:^.*gplot$<br>
  3094. Styles:$FW_cssdir:^.*(css|svg)$<br>
  3095. </code>
  3096. </ul>
  3097. NOTE: The directory spec is not flexible: all .js/.css/_defs.svg files
  3098. come from www/pgm2 ($FW_cssdir), .gplot files from $FW_gplotdir
  3099. (www/gplot), everything else from $MW_dir (FHEM).
  3100. </li><br>
  3101. <a name="endPlotNow"></a>
  3102. <li>endPlotNow<br>
  3103. If this FHEMWEB attribute is set to 1, then day and hour plots will
  3104. end at current time. Else the whole day, the 6 hour period starting at
  3105. 0, 6, 12 or 18 hour or the whole hour will be shown. This attribute
  3106. is not used if the SVG has the attribute startDate defined.<br>
  3107. </li><br>
  3108. <a name="endPlotToday"></a>
  3109. <li>endPlotToday<br>
  3110. If this FHEMWEB attribute is set to 1, then week and month plots will
  3111. end today. Else the current week or the current month will be shown.
  3112. <br>
  3113. </li><br>
  3114. <a name="fwcompress"></a>
  3115. <li>fwcompress<br>
  3116. Enable compressing the HTML data (default is 1, i.e. yes, use 0 to switch it off).
  3117. </li>
  3118. <br>
  3119. <a name="hiddengroup"></a>
  3120. <li>hiddengroup<br>
  3121. Comma separated list of groups to "hide", i.e. not to show in any room
  3122. of this FHEMWEB instance.<br>
  3123. Example: attr WEBtablet hiddengroup FileLog,dummy,at,notify
  3124. </li>
  3125. <br>
  3126. <a name="hiddengroupRegexp"></a>
  3127. <li>hiddengroupRegexp<br>
  3128. One regexp for the same purpose as hiddengroup.
  3129. </li>
  3130. <br>
  3131. <a name="hiddenroom"></a>
  3132. <li>hiddenroom<br>
  3133. Comma separated list of rooms to "hide", i.e. not to show. Special
  3134. values are input, detail and save, in which case the input areas, link
  3135. to the detailed views or save button is hidden (although each aspect
  3136. still can be addressed through URL manipulation).<br>
  3137. The list can also contain values from the additional "Howto/Wiki/FAQ"
  3138. block.
  3139. </li>
  3140. <br>
  3141. <a name="hiddenroomRegexp"></a>
  3142. <li>hiddenroomRegexp<br>
  3143. One regexp for the same purpose as hiddenroom. Example:
  3144. <ul>
  3145. attr WEB hiddenroomRegexp .*config
  3146. </ul>
  3147. Note: the special values input, detail and save cannot be specified
  3148. with hiddenroomRegexp.
  3149. </li>
  3150. <br>
  3151. <a name="HTTPS"></a>
  3152. <li>HTTPS<br>
  3153. Enable HTTPS connections. This feature requires the perl module
  3154. IO::Socket::SSL, to be installed with cpan -i IO::Socket::SSL or
  3155. apt-get install libio-socket-ssl-perl; OSX and the FritzBox-7390
  3156. already have this module.<br>
  3157. A local certificate has to be generated into a directory called certs,
  3158. this directory <b>must</b> be in the <a href="#modpath">modpath</a>
  3159. directory, at the same level as the FHEM directory.
  3160. <ul>
  3161. mkdir certs<br>
  3162. cd certs<br>
  3163. openssl req -new -x509 -nodes -out server-cert.pem -days 3650 -keyout server-key.pem
  3164. </ul>
  3165. <br>
  3166. </li>
  3167. <a name="icon"></a>
  3168. <li>icon<br>
  3169. Set the icon for a device in the room overview. There is an
  3170. icon-chooser in FHEMWEB to ease this task. Setting icons for the room
  3171. itself is indirect: there must exist an icon with the name
  3172. ico&lt;ROOMNAME&gt;.png in the iconPath.
  3173. </li>
  3174. <br>
  3175. <a name="iconPath"></a>
  3176. <li>iconPath<br>
  3177. colon separated list of directories where the icons are read from.
  3178. The directories start in the fhem/www/images directory. The default is
  3179. $styleSheetPrefix:default:fhemSVG:openautomation<br>
  3180. Set it to fhemSVG:openautomation to get only SVG images.
  3181. </li>
  3182. <br>
  3183. <a name="JavaScripts"></a>
  3184. <li>JavaScripts<br>
  3185. Space separated list of JavaScript files to be included. The filenames
  3186. are relative to the www directory. For each file an additional
  3187. user-settable FHEMWEB attribute will be created, to pass parameters to
  3188. the script. The name of this additional attribute gets the Param
  3189. suffix, directory and the fhem_ prefix will be deleted. Example:
  3190. <ul><code>
  3191. attr WEB JavaScripts codemirror/fhem_codemirror.js<br>
  3192. attr WEB codemirrorParam { "theme":"blackboard", "lineNumbers":true }
  3193. </code></ul>
  3194. </li><br>
  3195. <a name="longpoll"></a>
  3196. <li>longpoll [0|1|websocket]<br>
  3197. If activated, the browser is notifed when device states, readings or
  3198. attributes are changed, a reload of the page is not necessary.
  3199. Default is 1 (on), use 0 to deactivate it.<br>
  3200. If websocket is specified, then this API is used to notify the browser,
  3201. else HTTP longpoll. Note: some older browser do not implement websocket.
  3202. </li>
  3203. <br>
  3204. <a name="longpollSVG"></a>
  3205. <li>longpollSVG<br>
  3206. Reloads an SVG weblink, if an event should modify its content. Since
  3207. an exact determination of the affected events is too complicated, we
  3208. need some help from the definition in the .gplot file: the filter used
  3209. there (second parameter if the source is FileLog) must either contain
  3210. only the deviceName or have the form deviceName.event or deviceName.*.
  3211. This is always the case when using the <a href="#plotEditor">Plot
  3212. editor</a>. The SVG will be reloaded for <b>any</b> event triggered by
  3213. this deviceName. Default is off.
  3214. </li>
  3215. <br>
  3216. <a name="mainInputLength"></a>
  3217. <li>mainInputLength<br>
  3218. length of the maininput text widget in characters (decimal number).
  3219. </li>
  3220. <br>
  3221. <a name="menuEntries"></a>
  3222. <li>menuEntries<br>
  3223. Comma separated list of name,html-link pairs to display in the
  3224. left-side list. Example:<br>
  3225. attr WEB menuEntries fhem.de,http://fhem.de,culfw.de,http://culfw.de<br>
  3226. attr WEB menuEntries
  3227. AlarmOn,http://fhemhost:8083/fhem?cmd=set%20alarm%20on<br>
  3228. </li>
  3229. <br>
  3230. <a name="nameDisplay"></a>
  3231. <li>nameDisplay<br>
  3232. The argument is perl code, which is executed for each single device in
  3233. the room to determine the name displayed. $DEVICE is the name of the
  3234. current device, and $ALIAS is the value of the alias attribute or the
  3235. name of the device, if no alias is set. E.g. you can add a a global
  3236. userattr named alias_hu for the Hungarian translation, and specify
  3237. nameDisplay for the hungarian FHEMWEB instance as
  3238. <ul>
  3239. AttrVal($DEVICE, "alias_hu", $ALIAS)
  3240. </ul>
  3241. </li>
  3242. <br>
  3243. <a name="nrAxis"></a>
  3244. <li>nrAxis<br>
  3245. the number of axis for which space should be reserved on the left and
  3246. right sides of a plot and optionaly how many axes should realy be used
  3247. on each side, separated by comma: left,right[,useLeft,useRight]. You
  3248. can set individual numbers by setting the nrAxis of the SVG. Default is
  3249. 1,1.
  3250. </li><br>
  3251. <a name="ploteditor"></a>
  3252. <li>ploteditor<br>
  3253. Configures if the <a href="#plotEditor">Plot editor</a> should be shown
  3254. in the SVG detail view.
  3255. Can be set to always, onClick or never. Default is always.
  3256. </li><br>
  3257. <a name="plotEmbed"></a>
  3258. <li>plotEmbed 0<br>
  3259. SVG plots are rendered as part of &lt;embed&gt; tags, as in the past
  3260. this was the only way to display SVG, and it allows to render them in
  3261. parallel, see plotfork.
  3262. Setting plotEmbed to 0 will render SVG in-place, but as a side-effect
  3263. makes the plotfork attribute meaningless.<br>
  3264. </li><br>
  3265. <a name="plotfork"></a>
  3266. <li>plotfork [&lt;&Delta;p&gt;]<br>
  3267. If set to a nonzero value, run part of the processing (e.g. <a
  3268. href="#SVG">SVG</a> plot generation or <a href="#RSS">RSS</a> feeds) in
  3269. parallel processes. Actually, child processes are forked whose
  3270. priorities are the FHEM process' priority plus &Delta;p.
  3271. Higher values mean lower priority. e.g. use &Delta;p= 10 to renice the
  3272. child processes and provide more CPU power to the main FHEM process.
  3273. &Delta;p is optional and defaults to 0.<br>
  3274. Note: do not use it
  3275. on Windows and on systems with small memory footprint.
  3276. </li><br>
  3277. <a name="plotmode"></a>
  3278. <li>plotmode<br>
  3279. Specifies how to generate the plots:
  3280. <ul>
  3281. <li>SVG<br>
  3282. The plots are created with the <a href="#SVG">SVG</a> module.
  3283. This is the default.</li>
  3284. <li>gnuplot-scroll<br>
  3285. The plots are created with the gnuplot program. The gnuplot
  3286. output terminal PNG is assumed. Scrolling to historical values
  3287. is also possible, just like with SVG.</li>
  3288. <li>gnuplot-scroll-svg<br>
  3289. Like gnuplot-scroll, but the output terminal SVG is assumed.</li>
  3290. </ul>
  3291. </li><br>
  3292. <a name="plotsize"></a>
  3293. <li>plotsize<br>
  3294. the default size of the plot, in pixels, separated by comma:
  3295. width,height. You can set individual sizes by setting the plotsize of
  3296. the SVG. Default is 800,160 for desktop, and 480,160 for
  3297. smallscreen.
  3298. </li><br>
  3299. <a name="plotWeekStartDay"></a>
  3300. <li>plotWeekStartDay<br>
  3301. Start the week-zoom of the SVG plots with this day.
  3302. 0 is Sunday, 1 is Monday, etc.<br>
  3303. </li><br>
  3304. <a name="redirectCmds"></a>
  3305. <li>redirectCmds<br>
  3306. Clear the browser URL window after issuing the command by redirecting
  3307. the browser, as a reload for the same site might have unintended
  3308. side-effects. Default is 1 (enabled). Disable it by setting this
  3309. attribute to 0 if you want to study the command syntax, in order to
  3310. communicate with FHEMWEB.
  3311. </li>
  3312. <br>
  3313. <a name="refresh"></a>
  3314. <li>refresh<br>
  3315. If set, a http-equiv="refresh" entry will be genererated with the given
  3316. argument (i.e. the browser will reload the page after the given
  3317. seconds).
  3318. </li><br>
  3319. <a name="reverseLogs"></a>
  3320. <li>reverseLogs<br>
  3321. Display the lines from the logfile in a reversed order, newest on the
  3322. top, so that you dont have to scroll down to look at the latest entries.
  3323. Note: enabling this attribute will prevent FHEMWEB from streaming
  3324. logfiles, resulting in a considerably increased memory consumption
  3325. (about 6 times the size of the file on the disk).
  3326. </li>
  3327. <br>
  3328. <a name="roomIcons"></a>
  3329. <li>roomIcons<br>
  3330. Space separated list of room:icon pairs, to override the default
  3331. behaviour of showing an icon, if there is one with the name of
  3332. "icoRoomName". This is the correct way to remove the icon for the room
  3333. Everything, or to set one for rooms with / in the name (e.g.
  3334. Anlagen/EDV). The first part is treated as regexp, so space is
  3335. represented by a dot. Example:<br>
  3336. attr WEB roomIcons Anlagen.EDV:icoEverything
  3337. </li>
  3338. <br>
  3339. <a name="smallscreenCommands"></a>
  3340. <li>smallscreenCommands<br>
  3341. If set to 1, commands, slider and dropdown menues will appear in
  3342. smallscreen landscape mode.
  3343. </li><br>
  3344. <a name="sortby"></a>
  3345. <li>sortby<br>
  3346. Take the value of this attribute when sorting the devices in the room
  3347. overview instead of the alias, or if that is missing the devicename
  3348. itself. If the sortby value is enclosed in {} than it is evaluated as a
  3349. perl expression. $NAME is set to the device name.
  3350. </li>
  3351. <br>
  3352. <a name="showUsedFiles"></a>
  3353. <li>showUsedFiles<br>
  3354. In the Edit files section, show only the used files.
  3355. Note: currently this is only working for the "Gplot files" section.
  3356. </li>
  3357. <br>
  3358. <a name="sortRooms"></a>
  3359. <li>sortRooms<br>
  3360. Space separated list of rooms to override the default sort order of the
  3361. room links. As the rooms in this attribute are actually regexps, space
  3362. in the roomname has to be specified as dot (.).
  3363. Example:<br>
  3364. attr WEB sortRooms DG OG EG Keller
  3365. </li>
  3366. <br>
  3367. <li>sslVersion<br>
  3368. See the global attribute sslVersion.
  3369. </li><br>
  3370. <a name="styleData"></a>
  3371. <li>styleData<br>
  3372. data-storage used by dynamic styles like f18
  3373. </li><br>
  3374. <a name="stylesheetPrefix"></a>
  3375. <li>stylesheetPrefix<br>
  3376. prefix for the files style.css, svg_style.css and svg_defs.svg. If the
  3377. file with the prefix is missing, the default file (without prefix) will
  3378. be used. These files have to be placed into the FHEM directory, and can
  3379. be selected directly from the "Select style" FHEMWEB menu entry. Example:
  3380. <ul>
  3381. attr WEB stylesheetPrefix dark<br>
  3382. <br>
  3383. Referenced files:<br>
  3384. <ul>
  3385. darksvg_defs.svg<br>
  3386. darksvg_style.css<br>
  3387. darkstyle.css<br>
  3388. </ul>
  3389. <br>
  3390. </ul>
  3391. <b>Note:</b>if the argument contains the string smallscreen or touchpad,
  3392. then FHEMWEB will optimize the layout/access for small screen size (i.e.
  3393. smartphones) or touchpad devices (i.e. tablets)<br>
  3394. The default configuration installs 3 FHEMWEB instances: port 8083 for
  3395. desktop browsers, port 8084 for smallscreen, and 8085 for touchpad.<br>
  3396. If touchpad or smallscreen is specified, then WebApp support is
  3397. activated: After viewing the site on the iPhone or iPad in Safari, you
  3398. can add a link to the home-screen to get full-screen support. Links are
  3399. rendered differently in this mode to avoid switching back to the "normal"
  3400. browser.
  3401. </li>
  3402. <br>
  3403. <a name="SVGcache"></a>
  3404. <li>SVGcache<br>
  3405. if set, cache plots which won't change any more (the end-date is prior
  3406. to the current timestamp). The files are written to the www/SVGcache
  3407. directory. Default is off.<br>
  3408. See also the clearSvgCache command for clearing the cache.
  3409. </li><br>
  3410. <a name="title"></a>
  3411. <li>title<br>
  3412. Sets the title of the page. If enclosed in {} the content is evaluated.
  3413. </li><br>
  3414. <a name="viewport"></a>
  3415. <li>viewport<br>
  3416. Sets the &quot;viewport&quot; attribute in the HTML header. This can for
  3417. example be used to force the width of the page or disable zooming.<br>
  3418. Example: attr WEB viewport
  3419. width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no
  3420. </li><br>
  3421. <a name="webCmd"></a>
  3422. <li>webCmd<br>
  3423. Colon separated list of commands to be shown in the room overview for a
  3424. certain device. Has no effect on smallscreen devices, see the
  3425. devStateIcon command for an alternative.<br>
  3426. Example:
  3427. <ul>
  3428. attr lamp webCmd on:off:on-for-timer 10<br>
  3429. </ul>
  3430. <br>
  3431. The first specified command is looked up in the "set device ?" list
  3432. (see the <a href="#setList">setList</a> attribute for dummy devices).
  3433. If <b>there</b> it contains some known modifiers (colon, followed
  3434. by a comma separated list), then a different widget will be displayed.
  3435. See also the widgetOverride attribute below. Examples:
  3436. <ul>
  3437. define d1 dummy<br>
  3438. attr d1 webCmd state<br>
  3439. attr d1 readingList state<br>
  3440. attr d1 setList state:on,off<br><br>
  3441. define d2 dummy<br>
  3442. attr d2 webCmd state<br>
  3443. attr d2 readingList state<br>
  3444. attr d2 setList state:slider,0,1,10<br><br>
  3445. define d3 dummy<br>
  3446. attr d3 webCmd state<br>
  3447. attr d3 readingList state<br>
  3448. attr d3 setList state:time<br>
  3449. </ul>
  3450. If the command is state, then the value will be used as a command.<br>
  3451. Note: this is an attribute for the displayed device, not for the FHEMWEB
  3452. instance.
  3453. </li>
  3454. <br>
  3455. <a name="webCmdLabel"></a>
  3456. <li>webCmdLabel<br>
  3457. Colon separated list of labels, used to prefix each webCmd. The number
  3458. of labels must exactly match the number of webCmds. To implement
  3459. multiple rows, insert a return character after the text and before the
  3460. colon.</li></br>
  3461. <a name="webname"></a>
  3462. <li>webname<br>
  3463. Path after the http://hostname:port/ specification. Defaults to fhem,
  3464. i.e the default http address is http://localhost:8083/fhem
  3465. </li><br>
  3466. <a name="widgetOverride"></a>
  3467. <li>widgetOverride<br>
  3468. Space separated list of name:modifier pairs, to override the widget
  3469. for a set/get/attribute specified by the module author.
  3470. Following is the list of known modifiers:
  3471. <ul>
  3472. <!-- INSERT_DOC_FROM: www/pgm2/fhemweb.*.js -->
  3473. </ul>
  3474. </li>
  3475. <br>
  3476. </ul>
  3477. </ul>
  3478. =end html
  3479. =begin html_DE
  3480. <a name="FHEMWEB"></a>
  3481. <h3>FHEMWEB</h3>
  3482. <ul>
  3483. FHEMWEB ist das default WEB-Frontend, es implementiert auch einen einfachen
  3484. Webserver (optional mit Basic-Auth und HTTPS).
  3485. <br> <br>
  3486. <a name="FHEMWEBdefine"></a>
  3487. <b>Define</b>
  3488. <ul>
  3489. <code>define &lt;name&gt; FHEMWEB &lt;tcp-portnr&gt; [global|IP]</code>
  3490. <br><br>
  3491. Aktiviert das Webfrontend auf dem Port &lt;tcp-portnr&gt;. Mit dem
  3492. Parameter global werden Anfragen von allen Netzwerkschnittstellen
  3493. akzeptiert (nicht nur vom localhost / 127.0.0.1). Falls IP angegeben wurde,
  3494. dann werden nur Anfragen an diese IP Adresse akzeptiert. <br>
  3495. Informationen f&uuml;r den Betrieb mit IPv6 finden Sie <a
  3496. href="#telnet">hier</a>.<br>
  3497. </ul>
  3498. <br>
  3499. <a name="FHEMWEBset"></a>
  3500. <b>Set</b>
  3501. <ul>
  3502. <li>rereadicons<br>
  3503. Damit wird die Liste der Icons neu eingelesen, f&uuml;r den Fall, dass
  3504. Sie Icons l&ouml;schen oder hinzuf&uuml;gen.
  3505. </li>
  3506. <li>clearSvgCache<br>
  3507. Im Verzeichnis www/SVGcache werden SVG Daten zwischengespeichert, wenn
  3508. das Attribut SVGcache gesetzt ist. Mit diesem Befehl leeren Sie diesen
  3509. Zwischenspeicher.
  3510. </li>
  3511. </ul>
  3512. <br>
  3513. <a name="FHEMWEBget"></a>
  3514. <b>Get</b>
  3515. <ul>
  3516. <li>icon &lt;logical icon&gt;<br>
  3517. Liefert den absoluten Pfad des (logischen) Icons zur&uuml;ck. Beispiel:
  3518. <ul>
  3519. <code>get myFHEMWEB icon FS20.on<br>
  3520. /data/Homeautomation/fhem/FHEM/FS20.on.png
  3521. </code>
  3522. </ul></li>
  3523. <li>pathlist<br>
  3524. Zeigt diejenigen Verzeichnisse an, in welchen die verschiedenen Dateien
  3525. f&uuml;r FHEMWEB liegen.
  3526. </li>
  3527. <br><br>
  3528. </ul>
  3529. <a name="FHEMWEBattr"></a>
  3530. <b>Attribute</b>
  3531. <ul>
  3532. <a name="addHtmlTitle"></a>
  3533. <li>addHtmlTitle<br>
  3534. Falls der Wert 0 ist, wird bei den set/get/attr Parametern in der
  3535. DetailAnsicht der Ger&auml;te kein title Attribut gesetzt. Das is bei
  3536. manchen Screenreadern erforderlich. Die Voreinstellung ist 1.
  3537. </li><br>
  3538. <li><a href="#addStateEvent">addStateEvent</a></li><br>
  3539. <li>alias_&lt;RoomName&gt;<br>
  3540. Falls man das Attribut alias_&lt;RoomName&gt; definiert, und dieses
  3541. Attribut f&uuml;r ein Ger&auml;t setzt, dann wird dieser Wert bei
  3542. Anzeige von &lt;RoomName&gt; verwendet.<br>
  3543. Achtung: man kann im userattr auch alias_.* verwenden um alle
  3544. m&ouml;glichen R&auml;ume abzudecken, in diesem Fall wird aber die
  3545. Attributauswahl in der Detailansicht f&uuml;r alias_.* nicht
  3546. funktionieren.
  3547. </li><br>
  3548. <li><a href="#allowfrom">allowfrom</a>
  3549. </li><br>
  3550. <li>allowedCommands, basicAuth, basicAuthMsg<br>
  3551. Diese Attribute m&uuml;ssen ab sofort bei dem passenden <a
  3552. href="#allowed">allowed</a> Ger&auml;t angelegt werden, und sind
  3553. f&uuml;r eine FHEMWEB Instanz unerw&uuml;nscht.
  3554. </li><br>
  3555. <li>allowedHttpMethods</br>
  3556. FHEMWEB implementiert die HTTP Methoden GET, POST und OPTIONS. Manche
  3557. externe Ger&auml;te ben&ouml;tigen HEAD, das ist aber in FHEMWEB nicht
  3558. korrekt implementiert, da FHEMWEB immer ein body zur&uuml;ckliefert, was
  3559. laut Spec falsch ist. Da ein body in manchen F&auml;llen kein Problem
  3560. ist, kann man HEAD durch setzen dieses Attributes auf GET|POST|HEAD
  3561. aktivieren, die Voreinstellung ist GET|POST. OPTIONS ist immer
  3562. aktiviert.
  3563. </li><br>
  3564. <a name="closeConn"></a>
  3565. <li>closeConn<br>
  3566. Falls gesetzt, wird pro TCP Verbindung nur ein HTTP Request
  3567. durchgef&uuml;hrt. F&uuml;r iOS9 WebApp startups scheint es zu helfen.
  3568. </li><br>
  3569. <a name="cmdIcon"></a>
  3570. <li>cmdIcon<br>
  3571. Leerzeichen getrennte Auflistung von cmd:iconName Paaren.
  3572. Falls gesetzt, wird das webCmd text durch den icon gesetzt.
  3573. Am einfachsten setzt man cmdIcon indem man "Extend devStateIcon" im
  3574. Detail-Ansicht verwendet, und den Wert nach cmdIcon kopiert.<br>
  3575. Beispiel:<ul>
  3576. attr lamp cmdIcon on:control_centr_arrow_up off:control_centr_arrow_down
  3577. </ul>
  3578. </li><br>
  3579. <a name="column"></a>
  3580. <li>column<br>
  3581. Damit werden mehrere Spalten f&uuml;r einen Raum angezeigt, indem
  3582. sie verschiedene Gruppen Spalten zuordnen. Beispiel:<br>
  3583. <ul><code>
  3584. attr WEB column LivingRoom:FS20,notify|FHZ,notify DiningRoom:FS20|FHZ
  3585. </code></ul>
  3586. In diesem Beispiel werden im Raum LivingRoom die FS20 sowie die notify
  3587. Gruppe in der ersten Spalte, die FHZ und das notify in der zweiten
  3588. Spalte angezeigt.<br>
  3589. Anmerkungen: einige Elemente, wie SVG Plots und readingsGroup
  3590. k&ouml;nnen nur dann Teil einer Spalte sein wenn sie in <a
  3591. href="#group">group</a> stehen. Dieses Attribut kann man zum sortieren
  3592. der Gruppen auch dann verwenden, wenn man nur eine Spalte hat.
  3593. Leerzeichen im Raum- und Gruppennamen sind f&uuml;r dieses Attribut als
  3594. %20 zu schreiben. Raum- und Gruppenspezifikation ist jeweils ein
  3595. %regul&auml;rer Ausdruck.
  3596. </li><br>
  3597. <a name="confirmDelete"></a>
  3598. <li>confirmDelete<br>
  3599. L&ouml;schaktionen weden mit einem Dialog best&auml;tigt.
  3600. Falls dieses Attribut auf 0 gesetzt ist, entf&auml;llt das.
  3601. </li>
  3602. <br>
  3603. <a name="confirmJSError"></a>
  3604. <li>confirmJSError<br>
  3605. JavaScript Fehler werden per Voreinstellung in einem Dialog gemeldet.
  3606. Durch setzen dieses Attributes auf 0 werden solche Fehler nicht
  3607. gemeldet.
  3608. </li>
  3609. <br>
  3610. <a name="CORS"></a>
  3611. <li>CORS<br>
  3612. Wenn auf 1 gestellt, wird FHEMWEB einen "Cross origin resource sharing"
  3613. Header bereitstellen, n&auml;heres siehe Wikipedia.
  3614. </li><br>
  3615. <a name="csrfToken"></a>
  3616. <li>csrfToken<br>
  3617. Falls gesetzt, wird der Wert des Attributes als fwcsrf Parameter bei
  3618. jedem &uuml;ber FHEMWEB abgesetzten Kommando verlangt, es dient zum
  3619. Schutz von Cross Site Resource Forgery Angriffen.
  3620. Falls der Wert random ist, dann wird ein Zufallswert beim jeden FHEMWEB
  3621. Start neu generiert, falls er none ist, dann wird kein Parameter
  3622. verlangt. Default ist random f&uuml;r featurelevel 5.8 und
  3623. gr&ouml;&szlig;er, und none f&uuml;r featurelevel kleiner 5.8
  3624. </li><br>
  3625. <a name="csrfTokenHTTPHeader"></a>
  3626. <li>csrfTokenHTTPHeader<br>
  3627. Falls gesetzt (Voreinstellung), FHEMWEB sendet im HTTP Header den
  3628. csrfToken als X-FHEM-csrfToken, das wird von manchen FHEM-Clients
  3629. benutzt. Mit 0 kann man das abstellen, um Sites wie shodan.io die
  3630. Erkennung von FHEM zu erschweren.</li><br>
  3631. <a name="CssFiles"></a>
  3632. <li>CssFiles<br>
  3633. Leerzeichen getrennte Liste von .css Dateien, die geladen werden.
  3634. Die Dateinamen sind relativ zum www Verzeichnis anzugeben. Beispiel:
  3635. <ul><code>
  3636. attr WEB CssFiles pgm2/mystyle.css
  3637. </code></ul>
  3638. </li><br>
  3639. <a name="Css"></a>
  3640. <li>Css<br>
  3641. CSS, was nach dem CssFiles Abschnitt im Header eingefuegt wird.
  3642. </li><br>
  3643. <a name="defaultRoom"></a>
  3644. <li>defaultRoom<br>
  3645. Zeigt den angegebenen Raum an falls kein Raum explizit ausgew&auml;hlt
  3646. wurde. Achtung: falls gesetzt, wird motd nicht mehr angezeigt.
  3647. Beispiel:<br>
  3648. attr WEB defaultRoom Zentrale
  3649. </li><br>
  3650. <a name="devStateIcon"></a>
  3651. <li>devStateIcon<br>
  3652. Erste Variante:<br>
  3653. <ul>
  3654. Leerzeichen getrennte Auflistung von regexp:icon-name:cmd
  3655. Dreierp&auml;rchen, icon-name und cmd d&uuml;rfen leer sein.<br>
  3656. Wenn der Zustand des Ger&auml;tes mit der regexp &uuml;bereinstimmt,
  3657. wird als icon-name das entsprechende Status Icon angezeigt, und (falls
  3658. definiert), l&ouml;st ein Klick auf das Icon das entsprechende cmd aus.
  3659. Wenn fhem icon-name nicht finden kann, wird der Status als Text
  3660. angezeigt.
  3661. Beispiel:<br>
  3662. <ul>
  3663. attr lamp devStateIcon on:closed off:open<br>
  3664. attr lamp devStateIcon on::A0 off::AI<br>
  3665. attr lamp devStateIcon .*:noIcon<br>
  3666. </ul>
  3667. Anmerkung: Wenn das Icon ein SVG Bild ist, kann das @colorname Suffix
  3668. verwendet werden um das Icon einzuf&auml;rben. Z.B.:<br>
  3669. <ul>
  3670. attr Fax devStateIcon on:control_building_empty@red
  3671. off:control_building_filled:278727
  3672. </ul>
  3673. Falls cmd noFhemwebLink ist, dann wird kein HTML-Link generiert, d.h.
  3674. es passiert nichts, wenn man auf das Icon/Text klickt.
  3675. </ul>
  3676. Zweite Variante:<br>
  3677. <ul>
  3678. Perl regexp eingeschlossen in {}. Wenn der Code undef
  3679. zur&uuml;ckliefert, wird das Standard Icon verwendet; wird ein String
  3680. in <> zur&uuml;ck geliefert, wird dieser als HTML String interpretiert.
  3681. Andernfalls wird der String als devStateIcon gem&auml;&szlig; der
  3682. ersten Variante interpretiert, siehe oben. Beispiel:<br>
  3683. {'&lt;div style="width:32px;height:32px;background-color:green"&gt;&lt;/div&gt;'}
  3684. </ul>
  3685. </li><br>
  3686. <a name="devStateStyle"></a>
  3687. <li>devStateStyle<br>
  3688. F&uuml;r ein best. Ger&auml;t einen best. HTML-Style benutzen.
  3689. Beispiel:<br>
  3690. <ul>
  3691. attr sensor devStateStyle style="text-align:left;;font-weight:bold;;"<br>
  3692. </ul>
  3693. </li><br>
  3694. <li>deviceOverview<br>
  3695. Gibt an ob die Darstellung aus der Raum-Ansicht (Zeile mit
  3696. Ger&uuml;teicon, Stateicon und webCmds/cmdIcons) auch in der
  3697. Detail-Ansicht angezeigt werden soll. Kann auf always, onClick,
  3698. iconOnly oder never gesetzt werden. Der Default ist always.
  3699. </li><br>
  3700. <a name="editConfig"></a>
  3701. <li>editConfig<br>
  3702. Falls dieses FHEMWEB Attribut (auf 1) gesetzt ist, dann kann man die
  3703. FHEM Konfigurationsdatei in dem "Edit files" Abschnitt bearbeiten. Beim
  3704. Speichern dieser Datei wird automatisch rereadcfg ausgefuehrt, was
  3705. diverse Nebeneffekte hat.<br>
  3706. </li><br>
  3707. <a name="editFileList"></a>
  3708. <li>editFileList<br>
  3709. Definiert die Liste der angezeigten Dateien in der "Edit Files" Abschnitt.
  3710. Es ist eine Newline getrennte Liste von Tripeln bestehend aus Titel,
  3711. Verzeichnis f&uuml;r die Suche, und Regexp. Die Voreinstellung ist:
  3712. <ul>
  3713. <code>
  3714. Own modules and helper files:$MW_dir:^(.*sh|[0-9][0-9].*Util.*pm|.*cfg|.*holiday|myUtilsTemplate.pm|.*layout)$<br>
  3715. Gplot files:$FW_gplotdir:^.*gplot$<br>
  3716. Styles:$FW_cssdir:^.*(css|svg)$<br>
  3717. </code>
  3718. </ul>
  3719. Achtung: die Verzeichnis Angabe ist nicht flexibel: alle
  3720. .js/.css/_defs.svg Dateien sind in www/pgm2 ($FW_cssdir), .gplot
  3721. Dateien in $FW_gplotdir (www/gplot), alles andere in $MW_dir (FHEM).
  3722. </li><br>
  3723. <a name="endPlotNow"></a>
  3724. <li>endPlotNow<br>
  3725. Wenn Sie dieses FHEMWEB Attribut auf 1 setzen, werden Tages und
  3726. Stunden-Plots zur aktuellen Zeit beendet. (&Auml;hnlich wie
  3727. endPlotToday, nur eben min&uuml;tlich).
  3728. Ansonsten wird der gesamte Tag oder eine 6 Stunden Periode (0, 6, 12,
  3729. 18 Stunde) gezeigt. Dieses Attribut wird nicht verwendet, wenn das SVG
  3730. Attribut startDate benutzt wird.<br>
  3731. </li><br>
  3732. <a name="endPlotToday"></a>
  3733. <li>endPlotToday<br>
  3734. Wird dieses FHEMWEB Attribut gesetzt, so enden Wochen- bzw. Monatsplots
  3735. am aktuellen Tag, sonst wird die aktuelle Woche/Monat angezeigt.
  3736. </li><br>
  3737. <a name="fwcompress"></a>
  3738. <li>fwcompress<br>
  3739. Aktiviert die HTML Datenkompression (Standard ist 1, also ja, 0 stellt
  3740. die Kompression aus).
  3741. </li><br>
  3742. <a name="hiddengroup"></a>
  3743. <li>hiddengroup<br>
  3744. Wie hiddenroom (siehe unten), jedoch auf Ger&auml;tegruppen bezogen.
  3745. <br>
  3746. Beispiel: attr WEBtablet hiddengroup FileLog,dummy,at,notify
  3747. </li><br>
  3748. <a name="hiddengroupRegexp"></a>
  3749. <li>hiddengroupRegexp<br>
  3750. Ein regul&auml;rer Ausdruck, um Gruppen zu verstecken.
  3751. </li>
  3752. <br>
  3753. <a name="hiddenroom"></a>
  3754. <li>hiddenroom<br>
  3755. Eine Komma getrennte Liste, um R&auml;ume zu verstecken, d.h. nicht
  3756. anzuzeigen. Besondere Werte sind input, detail und save. In diesem
  3757. Fall werden diverse Eingabefelder ausgeblendent. Durch direktes Aufrufen
  3758. der URL sind diese R&auml;ume weiterhin erreichbar!<br>
  3759. Ebenso k&ouml;nnen Eintr&auml;ge in den Logfile/Commandref/etc Block
  3760. versteckt werden. </li><br>
  3761. <a name="hiddenroomRegexp"></a>
  3762. <li>hiddenroomRegexp<br>
  3763. Ein regul&auml;rer Ausdruck, um R&auml;ume zu verstecken. Beispiel:
  3764. <ul>
  3765. attr WEB hiddenroomRegexp .*config
  3766. </ul>
  3767. Achtung: die besonderen Werte input, detail und save m&uuml;ssen mit
  3768. hiddenroom spezifiziert werden.
  3769. </li>
  3770. <br>
  3771. <a name="HTTPS"></a>
  3772. <li>HTTPS<br>
  3773. Erm&ouml;glicht HTTPS Verbindungen. Es werden die Perl Module
  3774. IO::Socket::SSL ben&ouml;tigt, installierbar mit cpan -i
  3775. IO::Socket::SSL oder apt-get install libio-socket-ssl-perl; (OSX und
  3776. die FritzBox-7390 haben dieses Modul schon installiert.)<br>
  3777. Ein lokales Zertifikat muss im Verzeichis certs erzeugt werden.
  3778. Dieses Verzeichnis <b>muss</b> im <a href="#modpath">modpath</a>
  3779. angegeben werden, also auf der gleichen Ebene wie das FHEM Verzeichnis.
  3780. Beispiel:
  3781. <ul>
  3782. mkdir certs<br>
  3783. cd certs<br>
  3784. openssl req -new -x509 -nodes -out server-cert.pem -days 3650 -keyout
  3785. server-key.pem
  3786. </ul>
  3787. <br>
  3788. </li>
  3789. <a name="icon"></a>
  3790. <li>icon<br>
  3791. Damit definiert man ein Icon f&uuml;r die einzelnen Ger&auml;te in der
  3792. Raum&uuml;bersicht. Es gibt einen passenden Link in der Detailansicht
  3793. um das zu vereinfachen. Um ein Bild f&uuml;r die R&auml;ume selbst zu
  3794. definieren muss ein Icon mit dem Namen ico&lt;Raumname&gt;.png im
  3795. iconPath existieren (oder man verwendet roomIcons, s.u.)
  3796. </li><br>
  3797. <a name="iconPath"></a>
  3798. <li>iconPath<br>
  3799. Durch Doppelpunkt getrennte Aufz&auml;hlung der Verzeichnisse, in
  3800. welchen nach Icons gesucht wird. Die Verzeichnisse m&uuml;ssen unter
  3801. fhem/www/images angelegt sein. Standardeinstellung ist:
  3802. $styleSheetPrefix:default:fhemSVG:openautomation<br>
  3803. Setzen Sie den Wert auf fhemSVG:openautomation um nur SVG Bilder zu
  3804. benutzen.
  3805. </li><br>
  3806. <a name="JavaScripts"></a>
  3807. <li>JavaScripts<br>
  3808. Leerzeichen getrennte Liste von JavaScript Dateien, die geladen werden.
  3809. Die Dateinamen sind relativ zum www Verzeichnis anzugeben. F&uuml;r
  3810. jede Datei wird ein zus&auml;tzliches Attribut angelegt, damit der
  3811. Benutzer dem Skript Parameter weiterreichen kann. Bei diesem
  3812. Attributnamen werden Verzeichnisname und fhem_ Pr&auml;fix entfernt
  3813. und Param als Suffix hinzugef&uuml;gt. Beispiel:
  3814. <ul><code>
  3815. attr WEB JavaScripts codemirror/fhem_codemirror.js<br>
  3816. attr WEB codemirrorParam { "theme":"blackboard", "lineNumbers":true }
  3817. </code></ul>
  3818. </li><br>
  3819. <a name="longpoll"></a>
  3820. <li>longpoll [0|1|websocket]<br>
  3821. Falls gesetzt, FHEMWEB benachrichtigt den Browser, wenn
  3822. Ger&auml;testatuus, Readings or Attribute sich &auml;ndern, ein
  3823. Neuladen der Seite ist nicht notwendig. Zum deaktivieren 0 verwenden.
  3824. <br>
  3825. Falls websocket spezifiziert ist, l&auml;uft die Benachrichtigung des
  3826. Browsers &uuml;ber dieses Verfahren sonst &uuml;ber HTTP longpoll.
  3827. Achtung: &auml;ltere Browser haben keine websocket Implementierung.
  3828. </li><br>
  3829. <a name="longpollSVG"></a>
  3830. <li>longpollSVG<br>
  3831. L&auml;dt SVG Instanzen erneut, falls ein Ereignis dessen Inhalt
  3832. &auml;ndert. Funktioniert nur, falls die dazugeh&ouml;rige Definition
  3833. der Quelle in der .gplot Datei folgenden Form hat: deviceName.Event
  3834. bzw. deviceName.*. Wenn man den <a href="#plotEditor">Plot Editor</a>
  3835. benutzt, ist das &uuml;brigens immer der Fall. Die SVG Datei wird bei
  3836. <b>jedem</b> ausl&ouml;senden Event dieses Ger&auml;tes neu geladen.
  3837. Die Voreinstellung ist aus.
  3838. </li><br>
  3839. <a name="mainInputLength"></a>
  3840. <li>mainInputLength<br>
  3841. L&auml;nge des maininput Eingabefeldes (Anzahl der Buchstaben,
  3842. Ganzzahl).
  3843. </li> <br>
  3844. <a name="menuEntries"></a>
  3845. <li>menuEntries<br>
  3846. Komma getrennte Liste; diese Links werden im linken Men&uuml; angezeigt.
  3847. Beispiel:<br>
  3848. attr WEB menuEntries fhem.de,http://fhem.de,culfw.de,http://culfw.de<br>
  3849. attr WEB menuEntries
  3850. AlarmOn,http://fhemhost:8083/fhem?cmd=set%20alarm%20on<br>
  3851. </li><br>
  3852. <a name="nameDisplay"></a>
  3853. <li>nameDisplay<br>
  3854. Das Argument ist Perl-Code, was f&uuml;r jedes Ger&auml;t in der
  3855. Raum-&Uuml;bersicht ausgef&uuml;hrt wird, um den angezeigten Namen zu
  3856. berechnen. Dabei kann man die Variable $DEVICE f&uuml;r den aktuellen
  3857. Ger&auml;tenamen, und $ALIAS f&uuml;r den aktuellen alias bzw. Name,
  3858. falls alias nicht gesetzt ist, verwenden. Z.Bsp. f&uuml;r eine FHEMWEB
  3859. Instanz mit ungarischer Anzeige f&uuml;gt man ein global userattr
  3860. alias_hu hinzu, und man setzt nameDisplay f&uuml;r diese FHEMWEB
  3861. Instanz auf dem Wert:
  3862. <ul>
  3863. AttrVal($DEVICE, "alias_hu", $ALIAS)
  3864. </ul>
  3865. </li>
  3866. <br>
  3867. <a name="nrAxis"></a>
  3868. <li>nrAxis<br>
  3869. (bei mehrfach-Y-Achsen im SVG-Plot) Die Darstellung der Y Achsen
  3870. ben&ouml;tigt Platz. Hierdurch geben Sie an wie viele Achsen Sie
  3871. links,rechts [useLeft,useRight] ben&ouml;tigen. Default ist 1,1 (also 1
  3872. Achse links, 1 Achse rechts).
  3873. </li><br>
  3874. <a name="ploteditor"></a>
  3875. <li>ploteditor<br>
  3876. Gibt an ob der <a href="#plotEditor">Plot Editor</a> in der SVG detail
  3877. ansicht angezeigt werden soll. Kann auf always, onClick oder never
  3878. gesetzt werden. Der Default ist always.
  3879. </li><br>
  3880. <a name="plotEmbed"></a>
  3881. <li>plotEmbed 0<br>
  3882. SVG Grafiken werden als Teil der &lt;embed&gt; Tags dargestellt, da
  3883. fr&uuml;her das der einzige Weg war SVG darzustellen, weiterhin
  3884. erlaubt es das parallele Berechnen via plotfork (s.o.)
  3885. Falls plotEmbed auf 0 gesetzt wird, dann werden die SVG Grafiken als
  3886. Teil der HTML-Seite generiert, was leider das plotfork Attribut
  3887. wirkungslos macht.
  3888. </li><br>
  3889. <a name="plotfork"></a>
  3890. <li>plotfork<br>
  3891. Normalerweise wird die Ploterstellung im Hauptprozess ausgef&uuml;hrt,
  3892. FHEM wird w&auml;rend dieser Zeit nicht auf andere Ereignisse
  3893. reagieren.
  3894. Falls dieses Attribut auf einen nicht 0 Wert gesetzt ist, dann wird die
  3895. Berechnung in weitere Prozesse ausgelagert. Das kann die Berechnung auf
  3896. Rechnern mit mehreren Prozessoren beschleunigen, allerdings kann es auf
  3897. Rechnern mit wenig Speicher (z.Bsp. FRITZ!Box 7390) zum automatischen
  3898. Abschuss des FHEM Prozesses durch das OS f&uuml;hren.
  3899. </li><br>
  3900. <a name="plotmode"></a>
  3901. <li>plotmode<br>
  3902. Spezifiziert, wie Plots erzeugt werden sollen:
  3903. <ul>
  3904. <li>SVG<br>
  3905. Die Plots werden mit Hilfe des <a href="#SVG">SVG</a> Moduls als SVG
  3906. Grafik gerendert. Das ist die Standardeinstellung.</li>
  3907. <li>gnuplot-scroll<br>
  3908. Die plots werden mit dem Programm gnuplot erstellt. Das output
  3909. terminal ist PNG. Der einfache Zugriff auf historische Daten
  3910. ist m&ouml;glich (analog SVG).
  3911. </li>
  3912. <li>gnuplot-scroll-svg<br>
  3913. Wie gnuplot-scroll, aber als output terminal wird SVG angenommen.
  3914. </li>
  3915. </ul>
  3916. </li><br>
  3917. <a name="plotsize"></a>
  3918. <li>plotsize<br>
  3919. gibt die Standardbildgr&ouml;&szlig;e aller erzeugten Plots an als
  3920. Breite,H&ouml;he an. Um einem individuellen Plot die Gr&ouml;&szlig;e zu
  3921. &auml;ndern muss dieses Attribut bei der entsprechenden SVG Instanz
  3922. gesetzt werden. Default sind 800,160 f&uuml;r Desktop und 480,160
  3923. f&uuml;r Smallscreen
  3924. </li><br>
  3925. <a name="plotWeekStartDay"></a>
  3926. <li>plotWeekStartDay<br>
  3927. Starte das Plot in der Wochen-Ansicht mit diesem Tag.
  3928. 0 ist Sonntag, 1 ist Montag, usw.
  3929. </li><br>
  3930. <a name="redirectCmds"></a>
  3931. <li>redirectCmds<br>
  3932. Damit wird das URL Eingabefeld des Browser nach einem Befehl geleert.
  3933. Standard ist eingeschaltet (1), ausschalten kann man es durch
  3934. setzen des Attributs auf 0, z.Bsp. um den Syntax der Kommunikation mit
  3935. FHEMWEB zu untersuchen.
  3936. </li><br>
  3937. <a name="refresh"></a>
  3938. <li>refresh<br>
  3939. Damit erzeugen Sie auf den ausgegebenen Webseiten einen automatischen
  3940. Refresh, z.B. nach 5 Sekunden.
  3941. </li><br>
  3942. <a name="reverseLogs"></a>
  3943. <li>reverseLogs<br>
  3944. Damit wird das Logfile umsortiert, die neuesten Eintr&auml;ge stehen
  3945. oben. Der Vorteil ist, dass man nicht runterscrollen muss um den
  3946. neuesten Eintrag zu sehen, der Nachteil dass FHEM damit deutlich mehr
  3947. Hauptspeicher ben&ouml;tigt, etwa 6 mal so viel, wie das Logfile auf
  3948. dem Datentr&auml;ger gro&szlig; ist. Das kann auf Systemen mit wenig
  3949. Speicher (FRITZ!Box) zum Terminieren des FHEM Prozesses durch das
  3950. Betriebssystem f&uuml;hren.
  3951. </li><br>
  3952. <a name="roomIcons"></a>
  3953. <li>roomIcons<br>
  3954. Leerzeichen getrennte Liste von room:icon Zuordnungen
  3955. Der erste Teil wird als regexp interpretiert, daher muss ein
  3956. Leerzeichen als Punkt geschrieben werden. Beispiel:<br>
  3957. attr WEB roomIcons Anlagen.EDV:icoEverything
  3958. </li><br>
  3959. <a name="sortby"></a>
  3960. <li>sortby<br>
  3961. Der Wert dieses Attributs wird zum sortieren von Ger&auml;ten in
  3962. R&auml;umen verwendet, sonst w&auml;re es der Alias oder, wenn keiner
  3963. da ist, der Ger&auml;tename selbst. Falls der Wert des sortby
  3964. Attributes in {} eingeschlossen ist, dann wird er als ein perl Ausdruck
  3965. evaluiert. $NAME wird auf dem Ger&auml;tenamen gesetzt.
  3966. </li><br>
  3967. <a name="showUsedFiles"></a>
  3968. <li>showUsedFiles<br>
  3969. Zeige nur die verwendeten Dateien in der "Edit files" Abschnitt.
  3970. Achtung: aktuell ist das nur f&uuml;r den "Gplot files" Abschnitt
  3971. implementiert.
  3972. </li>
  3973. <br>
  3974. <a name="sortRooms"></a>
  3975. <li>sortRooms<br>
  3976. Durch Leerzeichen getrennte Liste von R&auml;umen, um deren Reihenfolge
  3977. zu definieren.
  3978. Da die R&auml;ume in diesem Attribut als Regexp interpretiert werden,
  3979. sind Leerzeichen im Raumnamen als Punkt (.) zu hinterlegen.
  3980. Beispiel:<br>
  3981. attr WEB sortRooms DG OG EG Keller
  3982. </li><br>
  3983. <a name="smallscreenCommands"></a>
  3984. <li>smallscreenCommands<br>
  3985. Falls auf 1 gesetzt werden Kommandos, Slider und Dropdown Men&uuml;s im
  3986. Smallscreen Landscape Modus angezeigt.
  3987. </li><br>
  3988. <li>sslVersion<br>
  3989. Siehe das global Attribut sslVersion.
  3990. </li><br>
  3991. <a name="styleData"></a>
  3992. <li>styleData<br>
  3993. wird von dynamischen styles wie f18 werwendet
  3994. </li><br>
  3995. <a name="stylesheetPrefix"></a>
  3996. <li>stylesheetPrefix<br>
  3997. Pr&auml;fix f&uuml;r die Dateien style.css, svg_style.css und
  3998. svg_defs.svg. Wenn die Datei mit dem Pr&auml;fix fehlt, wird die Default
  3999. Datei (ohne Pr&auml;fix) verwendet. Diese Dateien m&uuml;ssen im FHEM
  4000. Ordner liegen und k&ouml;nnen direkt mit "Select style" im FHEMWEB
  4001. Men&uuml;eintrag ausgew&auml;hlt werden. Beispiel:
  4002. <ul>
  4003. attr WEB stylesheetPrefix dark<br>
  4004. <br>
  4005. Referenzdateien:<br>
  4006. <ul>
  4007. darksvg_defs.svg<br>
  4008. darksvg_style.css<br>
  4009. darkstyle.css<br>
  4010. </ul>
  4011. <br>
  4012. </ul>
  4013. <b>Anmerkung:</b>Wenn der Parametername smallscreen oder touchpad
  4014. enth&auml;lt, wird FHEMWEB das Layout/den Zugriff f&uuml;r entsprechende
  4015. Ger&auml;te (Smartphones oder Touchpads) optimieren<br>
  4016. Standardm&auml;&szlig;ig werden 3 FHEMWEB Instanzen aktiviert: Port 8083
  4017. f&uuml;r Desktop Browser, Port 8084 f&uuml;r Smallscreen, und 8085
  4018. f&uuml;r Touchpad.<br>
  4019. Wenn touchpad oder smallscreen benutzt werden, wird WebApp support
  4020. aktiviert: Nachdem Sie eine Seite am iPhone oder iPad mit Safari
  4021. angesehen haben, k&ouml;nnen Sie einen Link auf den Homescreen anlegen um
  4022. die Seite im Fullscreen Modus zu sehen. Links werden in diesem Modus
  4023. anders gerendert, um ein "Zur&uuml;ckfallen" in den "normalen" Browser zu
  4024. verhindern.
  4025. </li><br>
  4026. <a name="SVGcache"></a>
  4027. <li>SVGcache<br>
  4028. Plots die sich nicht mehr &auml;ndern, werden im SVGCache Verzeichnis
  4029. (www/SVGcache) gespeichert, um die erneute, rechenintensive
  4030. Berechnung der Grafiken zu vermeiden. Default ist 0, d.h. aus.<br>
  4031. Siehe den clearSvgCache Befehl um diese Daten zu l&ouml;schen.
  4032. </li><br>
  4033. <a name="title"></a>
  4034. <li>title<br>
  4035. Setzt den Titel der Seite. Falls in {} eingeschlossen, dann wird es
  4036. als Perl Ausdruck evaluiert.
  4037. </li><br>
  4038. <a name="viewport"></a>
  4039. <li>viewport<br>
  4040. Setzt das &quot;viewport&quot; Attribut im HTML Header. Das kann benutzt
  4041. werden um z.B. die Breite fest vorzugeben oder Zoomen zu verhindern.<br>
  4042. Beispiel: attr WEB viewport
  4043. width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no
  4044. </li><br>
  4045. <a name="webCmd"></a>
  4046. <li>webCmd<br>
  4047. Durch Doppelpunkte getrennte Auflistung von Befehlen, die f&uuml;r ein
  4048. bestimmtes Ger&auml;t gelten sollen. Funktioniert nicht mit
  4049. smallscreen, ein Ersatz daf&uuml;r ist der devStateIcon Befehl.<br>
  4050. Beispiel:
  4051. <ul>
  4052. attr lamp webCmd on:off:on-for-timer 10<br>
  4053. </ul>
  4054. <br>
  4055. Der erste angegebene Befehl wird in der "set device ?" list
  4056. nachgeschlagen (Siehe das <a href="#setList">setList</a> Attrib
  4057. f&uuml;r Dummy Ger&auml;te). Wenn <b>dort</b> bekannte Modifier sind,
  4058. wird ein anderes Widget angezeigt. Siehe auch widgetOverride.<br>
  4059. Wenn der Befehl state ist, wird der Wert als Kommando interpretiert.<br>
  4060. Beispiele:
  4061. <ul>
  4062. define d1 dummy<br>
  4063. attr d1 webCmd state<br>
  4064. attr d1 setList state:on,off<br>
  4065. define d2 dummy<br>
  4066. attr d2 webCmd state<br>
  4067. attr d2 setList state:slider,0,1,10<br>
  4068. define d3 dummy<br>
  4069. attr d3 webCmd state<br>
  4070. attr d3 setList state:time<br>
  4071. </ul>
  4072. Anmerkung: dies ist ein Attribut f&uuml;r das anzuzeigende Ger&auml;t,
  4073. nicht f&uuml;r die FHEMWEBInstanz.
  4074. </li><br>
  4075. <a name="webCmdLabel"></a>
  4076. <li>webCmdLabel<br>
  4077. Durch Doppelpunkte getrennte Auflistung von Texten, die vor dem
  4078. jeweiligen webCmd angezeigt werden. Der Anzahl der Texte muss exakt den
  4079. Anzahl der webCmds entsprechen. Um mehrzeilige Anzeige zu realisieren,
  4080. kann ein Return nach dem Text und vor dem Doppelpunkt eingefuehrt
  4081. werden.</li><br>
  4082. <a name="webname"></a>
  4083. <li>webname<br>
  4084. Der Pfad nach http://hostname:port/ . Standard ist fhem,
  4085. so ist die Standard HTTP Adresse http://localhost:8083/fhem
  4086. </li><br>
  4087. <a name="widgetOverride"></a>
  4088. <li>widgetOverride<br>
  4089. Leerzeichen separierte Liste von Name/Modifier Paaren, mit dem man den
  4090. vom Modulautor f&uuml;r einen bestimmten Parameter (Set/Get/Attribut)
  4091. vorgesehene Widgets &auml;ndern kann. Folgendes ist die Liste der
  4092. bekannten Modifier:
  4093. <ul>
  4094. <!-- INSERT_DOC_FROM: www/pgm2/fhemweb.*.js -->
  4095. </ul></li>
  4096. </ul>
  4097. </ul>
  4098. =end html_DE
  4099. =cut