01_FHEMWEB.pm 150 KB

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