api.ponizer.php 204 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988
  1. <?php
  2. /**
  3. * PON devices management and monitoring implementation
  4. */
  5. class PONizer {
  6. /**
  7. * All available ONU devices as id=>onudata
  8. *
  9. * @var array
  10. */
  11. protected $allOnu = array();
  12. /**
  13. * List for mac = id
  14. *
  15. * @var array
  16. */
  17. protected $onuMacIdList = array();
  18. /**
  19. * List for serial = id
  20. *
  21. * @var type
  22. */
  23. protected $onuSerialIdList = array();
  24. /**
  25. * List for mac = oltid
  26. *
  27. * @var array
  28. */
  29. protected $onuMacOltidList = array();
  30. /**
  31. * List for serial = oltid
  32. *
  33. * @var array
  34. */
  35. protected $onuSerialOltidList = array();
  36. /**
  37. * Contains array of additional ONU users as id=>binddata
  38. *
  39. * @var array
  40. */
  41. protected $allOnuExtUsers = array();
  42. /**
  43. * OLT models data as id=>model data array
  44. *
  45. * @var array
  46. */
  47. protected $allModelsData = array();
  48. /**
  49. * All available OLT devices as id=>ip - location
  50. *
  51. * @var array
  52. */
  53. protected $allOltDevices = array();
  54. /**
  55. * All available OLT devices locations as id=>location
  56. *
  57. * @var array
  58. */
  59. protected $allOltNames = array();
  60. /**
  61. * Contains all OLT devices id=>modelId mappings
  62. *
  63. * @var array
  64. */
  65. protected $allOltModelIds = array();
  66. /**
  67. * OLT devices snmp data as id=>snmp data array
  68. *
  69. * @var array
  70. */
  71. protected $allOltSnmp = array();
  72. /**
  73. * OLT devices IPs as id=>ip
  74. *
  75. * @var array
  76. */
  77. protected $allOltIps = array();
  78. /**
  79. * Available OLT models as id=>modelname + snmptemplate + ports
  80. *
  81. * @var array
  82. */
  83. protected $allOltModels = array();
  84. /**
  85. * Contains available SNMP templates for OLT modelids as modelId=>snmpTemplateData
  86. *
  87. * @var array
  88. */
  89. protected $snmpTemplates = array();
  90. /**
  91. * Contains current ONU signal cache data as mac=>signal
  92. *
  93. * @var array
  94. */
  95. protected $signalCache = array();
  96. /**
  97. * Contains current ONU signal cache data as mac=>distance
  98. *
  99. * @var array
  100. */
  101. protected $distanceCache = array();
  102. /**
  103. * Contains current ONU last dereg reasons cache data as mac=>last dereg reason
  104. *
  105. * @var array
  106. */
  107. protected $lastDeregCache = array();
  108. /**
  109. * Contains ONU indexes cache as mac=>oltid
  110. *
  111. * @var array
  112. */
  113. protected $onuIndexCache = array();
  114. /**
  115. * Contains ONU indexes cache as mac=>interface
  116. *
  117. * @var array
  118. */
  119. protected $interfaceCache = array();
  120. /**
  121. * Contains FDB indexes cache as id=>mac
  122. *
  123. * @var array
  124. */
  125. protected $FDBCache = array();
  126. /**
  127. * Contains ONU devices indexes cache as mac => devID
  128. *
  129. * @var array
  130. */
  131. protected $onuMACDevIDCache = array();
  132. /**
  133. * Contains ONU UNI ports cache as MAC/Serial => (EtherPort => Status)
  134. *
  135. * @var array
  136. */
  137. protected $uniOperStatsCache = array();
  138. /**
  139. * System alter.ini config stored as key=>value
  140. *
  141. * @var array
  142. */
  143. protected $altCfg = array();
  144. /**
  145. * SNMPHelper object instance
  146. *
  147. * @var array
  148. */
  149. protected $snmp = '';
  150. /**
  151. * Prepared HTML for asterisk determining mandatory form field
  152. *
  153. * @var string
  154. */
  155. protected $sup = '';
  156. /**
  157. * Are QuickOLTLinks enabled?
  158. *
  159. * @var bool
  160. */
  161. protected $EnableQuickOLTLinks = false;
  162. /**
  163. * Are OLTs polled individually via AJAX?
  164. *
  165. * @var bool
  166. */
  167. protected $OLTIndividualRepollAJAX = false;
  168. /**
  169. * Is PON signal history charts spoiler initially closed?
  170. *
  171. * @var bool
  172. */
  173. protected $ONUChartsSpoilerClosed = false;
  174. /**
  175. * Is user search by MAC for unknown ONU registering form enabled?
  176. *
  177. * @var bool
  178. */
  179. protected $onuUknownUserByMACSearchShow = false;
  180. /**
  181. * Increment for user search by MAC telepathy for unknown ONU registering form
  182. *
  183. * @var string
  184. */
  185. protected $onuUknownUserByMACSearchIncrement = 0;
  186. /**
  187. * Is user search by MAC for unknown ONU registering form enabled mandatory?
  188. *
  189. * @var bool
  190. */
  191. protected $onuUknownUserByMACSearchShowAlways = false;
  192. /**
  193. * Is user search by MAC telepathy for unknown ONU registering form enabled?
  194. *
  195. * @var bool
  196. */
  197. protected $onuUknownUserByMACSearchTelepathy = false;
  198. /**
  199. * Is tab UI for ponizer active?
  200. *
  201. * @var bool
  202. */
  203. protected $ponizerUseTabUI = false;
  204. /**
  205. * Placeholder for onu MAC validation regex
  206. *
  207. * @var string
  208. */
  209. protected $onuMACValidateRegex = '/^([[:xdigit:]]{2}[\s:.-]?){5}[[:xdigit:]]{2}$/';
  210. /**
  211. * Perform ONU MAC validation against $onuMACValidateRegex?
  212. *
  213. * @var bool
  214. */
  215. protected $validateONUMACEnabled = false;
  216. /**
  217. * Replace ONU's MAC if invalid with a random one?
  218. *
  219. * @var string
  220. */
  221. protected $replaceInvalidONUMACWithRandom = false;
  222. /**
  223. * Show PON interfaces descriptions in main ONU list tab if present?
  224. *
  225. * @var bool
  226. */
  227. protected $showPONIfaceDescrMainTab = false;
  228. /**
  229. * Show PON interfaces descriptions in OLT stats tab if present?
  230. *
  231. * @var bool
  232. */
  233. protected $showPONIfaceDescrStatsTab = false;
  234. /**
  235. * Contains OLT PON interfaces description as $oltID => array($cleanIfaceName => $ifaceDescr)
  236. *
  237. * @var array
  238. */
  239. protected $ponIfaceDescrCache = array();
  240. /**
  241. * Placeholder for UbillingConfig object
  242. *
  243. * @var null
  244. */
  245. protected $ubConfig = null;
  246. /**
  247. * Array of MAC address of ONU devices which will be hidden from unknown ONU list
  248. *
  249. * @var array
  250. */
  251. protected $hideOnuMac = array();
  252. /**
  253. * OLT intefaces manual descriptions flag
  254. *
  255. * @var bool
  256. */
  257. protected $ponIfDescribe = false;
  258. /**
  259. * Deferred loading flag
  260. *
  261. * @var boolt
  262. */
  263. protected $deferredLoadingFlag = false;
  264. /**
  265. * Placeholder for PON_ONU_OFFLINE_SIGNAL alter.ini option
  266. *
  267. * @var string
  268. */
  269. protected $onuOfflineSignalLevel = '-9000';
  270. /**
  271. * PON interfaces object placeholder
  272. *
  273. * @var object
  274. */
  275. public $ponInterfaces = '';
  276. /**
  277. * IP column rendering flag
  278. *
  279. * @var bool
  280. */
  281. protected $ipColumnVisible = true;
  282. /**
  283. * Placeholder for PON_UKNKOWN_ONU_LLID_SHOW alter.ini option
  284. *
  285. * @var bool
  286. */
  287. protected $llidColVisibleUnknownONU = false;
  288. /**
  289. * Placeholder for PON_ONU_UNI_STATUS_ENABLED alter.ini option
  290. *
  291. * @var bool
  292. */
  293. protected $onuUniStatusEnabled = false;
  294. /**
  295. * Placeholder for PON_ONU_SERIAL_CASE_MODE alter.ini option
  296. * 0 - no case convert
  297. * 1 - lowercase
  298. * 2 - uppercase
  299. *
  300. * @var bool
  301. */
  302. protected $onuSerialCaseMode = 0;
  303. /**
  304. * Contains all busy ONU MAC/serials as lowercase onuIdent=>onuId
  305. *
  306. * @var array
  307. */
  308. protected $existingOnuIdents = array();
  309. /**
  310. * System message helper object placeholder
  311. *
  312. * @var object
  313. */
  314. protected $messages = '';
  315. /**
  316. * System caching object placeholder
  317. *
  318. * @var object
  319. */
  320. protected $cache = '';
  321. /**
  322. * Onu data caching timeout
  323. *
  324. * @var int
  325. */
  326. protected $onuCacheTimeout = 0;
  327. /**
  328. * Contains instance of OltAttractor
  329. *
  330. * @var object
  331. */
  332. protected $oltData = '';
  333. /**
  334. * Quiet mode flag
  335. *
  336. * @var bool
  337. */
  338. protected $supressOutput = false;
  339. /**
  340. * ONUs database abstraction layer
  341. *
  342. * @var object
  343. */
  344. protected $onuDb = '';
  345. /**
  346. * ONUs database abstraction layer
  347. *
  348. * @var object
  349. */
  350. protected $onuExtUsersDb = '';
  351. /**
  352. * Contains process manager instance
  353. *
  354. * @var object
  355. */
  356. protected $stardust = '';
  357. /**
  358. * Some predefined paths, marks etc.
  359. * This is here for legacy purpoces for external modules.
  360. */
  361. const SIGCACHE_PATH = OLTAttractor::SIGCACHE_PATH;
  362. const SIGCACHE_EXT = OLTAttractor::SIGCACHE_EXT;
  363. const DISTCACHE_PATH = OLTAttractor::DISTCACHE_PATH;
  364. const DISTCACHE_EXT = OLTAttractor::DISTCACHE_EXT;
  365. const ONUCACHE_PATH = OLTAttractor::ONUCACHE_PATH;
  366. const ONUCACHE_EXT = OLTAttractor::ONUCACHE_EXT;
  367. const INTCACHE_PATH = OLTAttractor::INTCACHE_PATH;
  368. const INTCACHE_EXT = OLTAttractor::INTCACHE_EXT;
  369. const INTDESCRCACHE_EXT = OLTAttractor::INTDESCRCACHE_EXT;
  370. const FDBCACHE_PATH = OLTAttractor::FDBCACHE_PATH;
  371. const FDBCACHE_EXT = OLTAttractor::FDBCACHE_EXT;
  372. const DEREGCACHE_PATH = OLTAttractor::DEREGCACHE_PATH;
  373. const DEREGCACHE_EXT = OLTAttractor::DEREGCACHE_EXT;
  374. const UPTIME_PATH = OLTAttractor::UPTIME_PATH;
  375. const UPTIME_EXT = OLTAttractor::UPTIME_EXT;
  376. const TEMPERATURE_PATH = OLTAttractor::TEMPERATURE_PATH;
  377. const TEMPERATURE_EXT = OLTAttractor::TEMPERATURE_EXT;
  378. const MACDEVIDCACHE_PATH = OLTAttractor::MACDEVIDCACHE_PATH;
  379. const MACDEVIDCACHE_EXT = OLTAttractor::MACDEVIDCACHE_EXT;
  380. const ONUSIG_PATH = OLTAttractor::ONUSIG_PATH;
  381. const POLL_PID = 'OLTPOLL_';
  382. const POLL_STATS = 'exports/pondata/races/PONYRUN_';
  383. const POLL_LOG = 'exports/oltpoll.log';
  384. /**
  385. * Other predefined constants
  386. */
  387. const SNMPCACHE = false;
  388. const SNMPPORT = 161;
  389. const TABLE_ONUS = 'pononu';
  390. const TABLE_SWITCHES = 'switches';
  391. const TABLE_ONUEXTUSERS = 'pononuextusers';
  392. const KEY_ALLONU = 'ALLONU';
  393. const KEY_ONUOLT = 'ONUOLTID_';
  394. const KEY_ONULISTAJ = 'ONULISTAJ_';
  395. const SNMP_TEMPLATES_PATH = 'config/snmptemplates/';
  396. const SNMP_PRIVATE_TEMPLATES_PATH = 'documents/mysnmptemplates/';
  397. /**
  398. * Some URLs here
  399. */
  400. const URL_ME = '?module=ponizer';
  401. const URL_ONULIST = '?module=ponizer&onulist=true';
  402. const URL_USERPROFILE = '?module=userprofile&username=';
  403. const URL_ONU = '?module=ponizer&editonu=';
  404. /**
  405. * Views/stats coloring
  406. */
  407. const COLOR_OK = '#005502';
  408. const COLOR_AVG = '#FF5500';
  409. const COLOR_BAD = '#AB0000';
  410. const COLOR_NOSIG = '#000000';
  411. const NO_SIGNAL = 'Offline';
  412. const POLL_RUNNING = '🏁';
  413. /**
  414. * Creates new PONizer object instance
  415. *
  416. * @param int $oltId load ONU data only for selected OLT. Loads all if empty.
  417. *
  418. * @return void
  419. */
  420. public function __construct($oltId = '') {
  421. global $ubillingConfig;
  422. $this->ubConfig = $ubillingConfig;
  423. $this->loadAlter();
  424. $this->initMessages();
  425. $this->initStarDust();
  426. $this->initOltAttractor();
  427. $this->initOnuDb();
  428. $this->initOnuExtUsersDb();
  429. $this->initCache();
  430. $this->loadOltDevices();
  431. $this->loadOltModels();
  432. $this->loadSnmpTemplates();
  433. $this->initSNMP();
  434. $this->loadOnu($oltId);
  435. $this->loadOnuExtUsers();
  436. $this->loadModels();
  437. $this->sup = wf_tag('sup') . '*' . wf_tag('sup', true);
  438. $this->EnableQuickOLTLinks = $this->ubConfig->getAlterParam('PON_QUICK_OLT_LINKS');
  439. $this->OLTIndividualRepollAJAX = $this->ubConfig->getAlterParam('PON_OLT_INDIVIDUAL_REPOLL_AJAX');
  440. $this->ONUChartsSpoilerClosed = $this->ubConfig->getAlterParam('PON_ONU_CHARTS_SPOILER_CLOSED');
  441. $this->onuUknownUserByMACSearchShow = $this->ubConfig->getAlterParam('PON_UONU_USER_BY_MAC_SEARCH_SHOW');
  442. $this->onuUknownUserByMACSearchIncrement = ($this->ubConfig->getAlterParam('PON_UONU_USER_BY_MAC_SEARCH_INCREMENT')) ? $this->ubConfig->getAlterParam('PON_UONU_USER_BY_MAC_SEARCH_INCREMENT') : 0;
  443. $this->onuUknownUserByMACSearchShowAlways = $this->ubConfig->getAlterParam('PON_UONU_USER_BY_MAC_SEARCH_SHOW_ALWAYS');
  444. $this->onuUknownUserByMACSearchTelepathy = $this->ubConfig->getAlterParam('PON_UONU_USER_BY_MAC_SEARCH_TELEPATHY');
  445. $this->ponizerUseTabUI = $this->ubConfig->getAlterParam('PON_UI_USE_TABS');
  446. $this->validateONUMACEnabled = $this->ubConfig->getAlterParam('PON_ONU_MAC_VALIDATE');
  447. $this->replaceInvalidONUMACWithRandom = $this->ubConfig->getAlterParam('PON_ONU_MAC_MAKE_RANDOM_IF_INVALID');
  448. $this->showPONIfaceDescrMainTab = $this->ubConfig->getAlterParam('PON_IFACE_DESCRIPTION_IN_MAINTAB');
  449. $this->showPONIfaceDescrStatsTab = $this->ubConfig->getAlterParam('PON_IFACE_DESCRIPTION_IN_STATSTAB');
  450. $this->ponIfDescribe = $this->ubConfig->getAlterParam('PON_IFDESC');
  451. $this->onuOfflineSignalLevel = $this->ubConfig->getAlterParam('PON_ONU_OFFLINE_SIGNAL', $this->onuOfflineSignalLevel);
  452. $this->deferredLoadingFlag = $this->ubConfig->getAlterParam('PON_DEFERRED_LOADING', false);
  453. $this->ipColumnVisible = ($this->ubConfig->getAlterParam('PONIZER_NO_IP_COLUMN')) ? false : true;
  454. $this->llidColVisibleUnknownONU = $this->ubConfig->getAlterParam('PON_UKNKOWN_ONU_LLID_SHOW', false);
  455. $this->onuUniStatusEnabled = $this->ubConfig->getAlterParam('PON_ONU_UNI_STATUS_ENABLED', false);
  456. $this->onuSerialCaseMode = $this->ubConfig->getAlterParam('PON_ONU_SERIAL_CASE_MODE', 0);
  457. if ($this->ponIfDescribe) {
  458. $this->ponInterfaces = new PONIfDesc();
  459. }
  460. //optional ONU MAC hiding
  461. if (@$this->altCfg['PON_ONU_HIDE']) {
  462. $tmpHideOnuList = explode(',', $this->altCfg['PON_ONU_HIDE']);
  463. $tmpHideOnuList = array_flip($tmpHideOnuList);
  464. $this->hideOnuMac = $tmpHideOnuList;
  465. }
  466. }
  467. /**
  468. * Loads system alter.ini config into private data property
  469. *
  470. * @return void
  471. */
  472. protected function loadAlter() {
  473. $this->altCfg = $this->ubConfig->getAlter();
  474. }
  475. /**
  476. * Inits system messages helper for further usage
  477. *
  478. * @return void
  479. */
  480. protected function initMessages() {
  481. $this->messages = new UbillingMessageHelper();
  482. }
  483. /**
  484. * Inits anonymous OLT attractor instance for further usage
  485. *
  486. * @return void
  487. */
  488. protected function initOltAttractor() {
  489. $this->oltData = new OLTAttractor();
  490. }
  491. /**
  492. * Inits ONUs database abstraction layer
  493. *
  494. * @return void
  495. */
  496. protected function initOnuDb() {
  497. $this->onuDb = new NyanORM(self::TABLE_ONUS);
  498. }
  499. /**
  500. * Inits ONUs additional users database abstraction layer
  501. *
  502. * @return void
  503. */
  504. protected function initOnuExtUsersDb() {
  505. $this->onuExtUsersDb = new NyanORM(self::TABLE_ONUEXTUSERS);
  506. }
  507. /**
  508. * Inits process manager
  509. *
  510. * @return void
  511. */
  512. protected function initStarDust() {
  513. $this->stardust = new StarDust();
  514. }
  515. /**
  516. * Loads all available devices set as OLT
  517. *
  518. * @return void
  519. */
  520. protected function loadOltDevices() {
  521. $switchesDb = new NyanORM(self::TABLE_SWITCHES);
  522. $requiredFields = array('`id`', '`ip`', '`location`', '`snmp`', '`modelid`', '`desc`');
  523. $switchesDb->selectable($requiredFields);
  524. $switchesDb->where('desc', 'LIKE', '%OLT%');
  525. //custom field sorting?
  526. $oltLoadOrderField = $this->ubConfig->getAlterParam('PON_OLT_ORDER');
  527. if (!empty($oltLoadOrderField)) {
  528. //is fileld valid?
  529. if (array_search('`' . $oltLoadOrderField . '`', $requiredFields) !== false) {
  530. $switchesDb->orderBy($oltLoadOrderField, 'ASC');
  531. } else {
  532. show_error(__('Wrong value') . ' PON_OLT_ORDER: ' . '"' . $oltLoadOrderField . '"');
  533. }
  534. }
  535. $raw = $switchesDb->getAll();
  536. if (!empty($raw)) {
  537. foreach ($raw as $io => $each) {
  538. //OLT must have non empty community
  539. if (!empty($each['snmp'])) {
  540. $this->allOltDevices[$each['id']] = $each['ip'] . ' - ' . $each['location'];
  541. $this->allOltNames[$each['id']] = $each['location'];
  542. $this->allOltModelIds[$each['id']] = $each['modelid'];
  543. $this->allOltIps[$each['id']] = $each['ip'];
  544. $this->allOltSnmp[$each['id']]['community'] = $each['snmp'];
  545. $this->allOltSnmp[$each['id']]['modelid'] = $each['modelid'];
  546. $this->allOltSnmp[$each['id']]['ip'] = $each['ip'];
  547. $this->allOltSnmp[$each['id']]['nofdbquery'] = ispos($each['desc'], 'NOFDBQUERY');
  548. }
  549. }
  550. }
  551. }
  552. /**
  553. * Getter for allOltDevices array
  554. *
  555. * @return array
  556. */
  557. public function getAllOltDevices() {
  558. return $this->allOltDevices;
  559. }
  560. /**
  561. * Loads all available snmp models data into private data property
  562. *
  563. * @return void
  564. */
  565. protected function loadOltModels() {
  566. $rawModels = zb_SwitchModelsGetAll();
  567. if (!empty($rawModels)) {
  568. foreach ($rawModels as $io => $each) {
  569. $this->allOltModels[$each['id']]['modelname'] = $each['modelname'];
  570. $this->allOltModels[$each['id']]['snmptemplate'] = $each['snmptemplate'];
  571. $this->allOltModels[$each['id']]['ports'] = $each['ports'];
  572. }
  573. }
  574. }
  575. /**
  576. * Performs SNMP templates preprocessing for OLT devices
  577. *
  578. * @return void
  579. */
  580. protected function loadSnmpTemplates() {
  581. if (!empty($this->allOltDevices)) {
  582. foreach ($this->allOltDevices as $oltId => $eachOltData) {
  583. if (isset($this->allOltSnmp[$oltId])) {
  584. $oltModelid = $this->allOltSnmp[$oltId]['modelid'];
  585. if ($oltModelid) {
  586. if (isset($this->allOltModels[$oltModelid])) {
  587. $templateFileName = $this->allOltModels[$oltModelid]['snmptemplate'];
  588. if (!empty($templateFileName)) {
  589. $basicTemplateFile = self::SNMP_TEMPLATES_PATH . $templateFileName;
  590. $privateTemplateFile = DATA_PATH . self::SNMP_PRIVATE_TEMPLATES_PATH . $templateFileName;
  591. //loading basic SNMP template
  592. if (file_exists($basicTemplateFile)) {
  593. $this->snmpTemplates[$oltModelid] = rcms_parse_ini_file($basicTemplateFile, true);
  594. }
  595. //custom SNMP templates is separated and overrides original templates
  596. if (file_exists($privateTemplateFile)) {
  597. $this->snmpTemplates[$oltModelid] = rcms_parse_ini_file($privateTemplateFile, true);
  598. }
  599. }
  600. }
  601. }
  602. }
  603. }
  604. }
  605. }
  606. /**
  607. * Creates single instance of SNMPHelper object
  608. *
  609. * @return void
  610. */
  611. protected function initSNMP() {
  612. $this->snmp = new SNMPHelper();
  613. }
  614. /**
  615. * Inits system caching engine
  616. *
  617. * @return void
  618. */
  619. protected function initCache() {
  620. $this->cache = new UbillingCache();
  621. $this->onuCacheTimeout = $this->ubConfig->getAlterParam('PON_ONU_CACHING', 0);
  622. if ($this->onuCacheTimeout) {
  623. $this->onuCacheTimeout = $this->onuCacheTimeout * 60; //in minutes
  624. }
  625. }
  626. /**
  627. * Try to detect ONU id by assigned users login
  628. *
  629. * @param string $login
  630. * @return int/bool
  631. */
  632. public function getOnuIdByUser($login) {
  633. $result = 0;
  634. if (!empty($this->allOnu)) {
  635. foreach ($this->allOnu as $io => $each) {
  636. if ($each['login'] == $login) {
  637. $result = $each['id'];
  638. break;
  639. }
  640. }
  641. if (!empty($this->allOnuExtUsers)) {
  642. foreach ($this->allOnuExtUsers as $io => $each) {
  643. if ($each['login'] == $login) {
  644. $result = $each['onuid'];
  645. break;
  646. }
  647. }
  648. }
  649. }
  650. return ($result);
  651. }
  652. /**
  653. * Trys to detect all ONU IDs by assigned users login as idx=>onuId
  654. *
  655. * @param string $login
  656. *
  657. * @return array
  658. */
  659. public function getOnuIdByUserAll($login) {
  660. $result = array();
  661. if (!empty($this->allOnu)) {
  662. foreach ($this->allOnu as $io => $each) {
  663. if ($each['login'] == $login) {
  664. $result[] = $each['id'];
  665. }
  666. }
  667. if (!empty($this->allOnuExtUsers)) {
  668. foreach ($this->allOnuExtUsers as $io => $each) {
  669. if ($each['login'] == $login) {
  670. $result[] = $each['onuid'];
  671. }
  672. }
  673. }
  674. }
  675. return ($result);
  676. }
  677. /**
  678. * Returns array of ONUs assigned on some OLT
  679. *
  680. * @param string $OltId
  681. * @return array
  682. */
  683. protected function getOnuArrayByOltID($OltId = '') {
  684. $result = array();
  685. if (!empty($this->allOnu) and !empty($OltId)) {
  686. foreach ($this->allOnu as $io => $each) {
  687. if ($each['oltid'] == $OltId) {
  688. $result[$io] = $each;
  689. }
  690. }
  691. }
  692. return ($result);
  693. }
  694. /**
  695. * Performs OLT device polling via PON HAL instance
  696. *
  697. * @param int $oltid Existing OLT id to perform polling
  698. * @param bool $quiet dont output debug info to viewport
  699. *
  700. * @return void
  701. */
  702. public function pollOltSignal($oltid, $quiet = false) {
  703. $oltid = ubRouting::filters($oltid, 'int');
  704. $this->supressOutput = $quiet;
  705. $this->logPoll($oltid, 'STARTING: polling');
  706. if (isset($this->allOltDevices[$oltid])) {
  707. if (isset($this->allOltSnmp[$oltid])) {
  708. $this->flushOnuAjListCache($oltid);
  709. $oltCommunity = $this->allOltSnmp[$oltid]['community'];
  710. $oltModelId = $this->allOltSnmp[$oltid]['modelid'];
  711. $oltIp = $this->allOltSnmp[$oltid]['ip'];
  712. $oltNoFDBQ = $this->allOltSnmp[$oltid]['nofdbquery'];
  713. if (isset($this->snmpTemplates[$oltModelId])) {
  714. $this->logPoll($oltid, 'Using device SNMP template "' . $this->snmpTemplates[$oltModelId]['define']['DEVICE'] . '"');
  715. if (isset($this->snmpTemplates[$oltModelId]['signal'])) {
  716. //logging collector signalmode and collector
  717. $logTemplate = 'Template mode:"' . $this->snmpTemplates[$oltModelId]['signal']['SIGNALMODE'] . '" ';
  718. $logTemplate .= 'collector name:"' . @$this->snmpTemplates[$oltModelId]['signal']['COLLECTORNAME'] . '"';
  719. $this->logPoll($oltid, $logTemplate);
  720. //preventing simultaneously device polling within different processes
  721. if (!$this->isPollingLocked($oltid)) {
  722. //prefilling polling stats
  723. $pollingStartTime = time();
  724. $this->pollingStatsUpdate($oltid, $pollingStartTime, 0, false);
  725. $collector = '';
  726. $collectorName = '';
  727. $collectorMethod = 'collect';
  728. $oltParameters = array(
  729. 'MODELID' => $oltModelId,
  730. 'ID' => $oltid,
  731. 'IP' => $oltIp,
  732. 'COMMUNITY' => $oltCommunity,
  733. 'NOFDB' => $oltNoFDBQ,
  734. 'TYPE' => 'PON'
  735. );
  736. switch ($this->snmpTemplates[$oltModelId]['signal']['SIGNALMODE']) {
  737. /**
  738. * Switchable OLT devices polling abstraction layer
  739. */
  740. case 'HAL':
  741. //setting collector class name
  742. $collectorName = $this->snmpTemplates[$oltModelId]['signal']['COLLECTORNAME'];
  743. //setting optional primary collector method name to call
  744. if (isset($this->snmpTemplates[$oltModelId]['signal']['COLLECTORMETHOD'])) {
  745. $collectorMethod = $this->snmpTemplates[$oltModelId]['signal']['COLLECTORMETHOD'];
  746. }
  747. break;
  748. /**
  749. * Following cases is legacy for old or custom device templates
  750. * without collector hardware abstraction layer specified explictly
  751. */
  752. case 'BDCOM':
  753. /**
  754. * BDCOM/Eltex/Extralink devices polling
  755. */
  756. $collectorName = 'PONBdcom';
  757. break;
  758. case 'GPBDCOM':
  759. /**
  760. * BDCOM GP3600
  761. */
  762. $collectorName = 'PONBdcomGP';
  763. break;
  764. case 'STELS12':
  765. /**
  766. * Stels FD12XX devices polling
  767. */
  768. $collectorName = 'PONStels12';
  769. break;
  770. case 'STELSFD':
  771. /**
  772. * Stels FD11XX devices polling
  773. */
  774. $collectorName = 'PONStels11';
  775. break;
  776. case 'VSOL':
  777. /**
  778. * V-Solution 1600D devices polling
  779. */
  780. $collectorName = 'PONVsol';
  781. break;
  782. /**
  783. * ZTE-like EPON OLTs polling
  784. */
  785. case 'ZTE':
  786. $collectorName = 'PonZte';
  787. $collectorMethod = 'pollEpon';
  788. $oltParameters['TYPE'] = 'EPON';
  789. break;
  790. /**
  791. * ZTE GPON OLTs polling
  792. */
  793. case 'ZTE_GPON':
  794. $collectorName = 'PonZte';
  795. $collectorMethod = 'pollGpon';
  796. $oltParameters['TYPE'] = 'GPON';
  797. break;
  798. /**
  799. * Huawei EPON OLTs polling
  800. */
  801. case 'HUAWEI_GPON':
  802. $collectorName = 'PonZte';
  803. $collectorMethod = 'huaweiPollGpon';
  804. $oltParameters['TYPE'] = 'GPON';
  805. break;
  806. }
  807. //Run OLT HAL instance for device polling
  808. if (!empty($collectorName)) {
  809. if (class_exists($collectorName)) {
  810. $collector = new $collectorName($oltParameters, $this->snmpTemplates);
  811. $logCollector = 'Polling prepare using PON HAL collector:"' . $collectorName . '" ';
  812. $logCollector .= 'with parameters OLT ID: ' . $oltParameters['ID'] . ' IP:' . $oltParameters['IP'];
  813. $this->logPoll($oltid, $logCollector);
  814. if (method_exists($collector, 'setOfflineSignal')) {
  815. $collector->setOfflineSignal($this->onuOfflineSignalLevel);
  816. }
  817. if (method_exists($collector, $collectorMethod)) {
  818. $this->logPoll($oltid, 'RUNNING: PON HAL collector method:' . $collectorName . '->' . $collectorMethod);
  819. $collector->$collectorMethod();
  820. $this->logPoll($oltid, 'COMPLETED: PON HAL collector method:' . $collectorName . '->' . $collectorMethod);
  821. } else {
  822. $this->logPoll($oltid, 'FAILED run PON HAL collector:' . $collectorName . '->' . $collectorMethod . ' METHOD_NOT_EXISTS');
  823. }
  824. } else {
  825. $this->logPoll($oltid, 'FATAL run PON HAL collector:' . $collectorName . ' EX_HAL_COLLECTOR_NOT_EXISTS');
  826. }
  827. } else {
  828. $this->logPoll($oltid, 'Failed: collector name not defined');
  829. }
  830. //finishing OLT polling stats
  831. $pollingEndTime = time();
  832. $this->pollingStatsUpdate($oltid, $pollingStartTime, $pollingEndTime, true);
  833. $this->logPoll($oltid, 'FINISHED: polled successfully');
  834. } else {
  835. $this->logPoll($oltid, 'FINISHED: skipped, polling already in progress');
  836. }
  837. } else {
  838. $this->logPoll($oltid, 'Failed polling due signal section is not exists');
  839. }
  840. } else {
  841. $this->logPoll($oltid, 'SKIPPING MODELID:' . $oltModelId . ' NO_SNMP_TEMPLATE_BODY');
  842. }
  843. } else {
  844. $this->logPoll($oltid, 'SKIPPING No snmp data for this OLT');
  845. }
  846. } else {
  847. $this->logPoll($oltid, 'SKIPPING Not in OLT devices list');
  848. }
  849. }
  850. /**
  851. * Performs available OLT devices polling. Use only in remote API.
  852. *
  853. * @param bool $quiet dont output debug data into viewport
  854. *
  855. * @return void
  856. */
  857. public function oltDevicesPolling($quiet = false) {
  858. if (!empty($this->allOltDevices)) {
  859. foreach ($this->allOltDevices as $oltid => $each) {
  860. if (!$quiet) {
  861. print('POLLING:' . $oltid . ' ' . $each . PHP_EOL);
  862. }
  863. if (@!$this->altCfg['HERD_OF_PONIES']) {
  864. $this->pollOltSignal($oltid, $quiet);
  865. } else {
  866. //starting herd of apocalypse pony here!
  867. $herdTimeout = 0;
  868. if ($this->altCfg['HERD_OF_PONIES'] > 1) {
  869. $herdTimeout = ubRouting::filters($this->altCfg['HERD_OF_PONIES'], 'int');
  870. }
  871. $this->stardust->runBackgroundProcess('/bin/ubapi "herd&oltid=' . $oltid . '"', $herdTimeout);
  872. }
  873. }
  874. }
  875. }
  876. /**
  877. * Fast check some OLT for running collector process.
  878. *
  879. * @param int $oltId Existing OLT device ID
  880. *
  881. * @return bool
  882. */
  883. protected function isPollingNow($oltId) {
  884. $result = false;
  885. //Не плач, моє серце, не плач,
  886. //Не муч душу свою картонну!
  887. $pollingStats = $this->pollingStatsRead($oltId);
  888. if (!empty($pollingStats)) {
  889. $result = $pollingStats['finished'] ? false : true;
  890. }
  891. return ($result);
  892. }
  893. /**
  894. * Returns polling stats for some OLT
  895. *
  896. * @param int $oltId
  897. *
  898. * @return array
  899. */
  900. protected function pollingStatsRead($oltId) {
  901. $result = array();
  902. $statsPath = self::POLL_STATS . $oltId;
  903. if (file_exists($statsPath)) {
  904. $resultRaw = file_get_contents($statsPath);
  905. $result = json_decode($resultRaw, true);
  906. }
  907. return ($result);
  908. }
  909. /**
  910. * Updates some OLT polling stats
  911. *
  912. * @param int $oltId Existing OLT ID
  913. * @param int $pollingStartTime polling start timestame
  914. * @param int $pollingEndTime polling end timestamp
  915. * @param bool $finished polling finished or not flag
  916. *
  917. * @return void
  918. */
  919. protected function pollingStatsUpdate($oltId, $pollingStartTime = 0, $pollingEndTime = 0, $finished = false) {
  920. $oltId = ubRouting::filters($oltId, 'int');
  921. $statsPath = self::POLL_STATS . $oltId;
  922. $finishedData = ($finished) ? 1 : 0;
  923. $dataToSave['start'] = $pollingStartTime;
  924. $dataToSave['end'] = $pollingEndTime;
  925. $dataToSave['finished'] = $finishedData;
  926. $dataToSave = json_encode($dataToSave);
  927. file_put_contents($statsPath, $dataToSave);
  928. //collector process locking and releasing of locks here
  929. if ($finished) {
  930. //release lock
  931. $this->stardust->setProcess(self::POLL_PID . $oltId);
  932. $this->stardust->stop();
  933. } else {
  934. //set lock for polling of some OLT
  935. $this->stardust->setProcess(self::POLL_PID . $oltId);
  936. $this->stardust->start();
  937. }
  938. }
  939. /**
  940. * Performs logging of OLT polling
  941. *
  942. * @param int $oltId
  943. * @param string $logData
  944. *
  945. * @return void
  946. */
  947. public function logPoll($oltId, $logData) {
  948. $curdate = curdatetime();
  949. $logData = $curdate . ' | OLT[' . $oltId . '] | ' . $logData . PHP_EOL;
  950. if (!$this->supressOutput) {
  951. print($logData); // for manual debug of oltpoll and herd remoteapi calls
  952. }
  953. file_put_contents(self::POLL_LOG, $logData, FILE_APPEND);
  954. }
  955. /**
  956. * Performs check of OLT polling lock via DB.
  957. * Using this only for checks of possibility real collector runs.
  958. *
  959. * @param int $oltId
  960. *
  961. * @return bool
  962. */
  963. protected function isPollingLocked($oltId) {
  964. $oltId = ubRouting::filters($oltId, 'int');
  965. $this->stardust->setProcess(self::POLL_PID . $oltId);
  966. $result = $this->stardust->isRunning();
  967. return ($result);
  968. }
  969. /**
  970. * Returns some polllog viewer controls
  971. *
  972. * @return string
  973. */
  974. public function renderLogControls() {
  975. $result = '';
  976. $result .= wf_BackLink(self::URL_ME . '&oltstats=true') . ' ';
  977. $result .= wf_Link(self::URL_ME . '&polllogs=true', wf_img('skins/log_icon_small.png') . ' ' . __('Log'), false, 'ubButton') . '';
  978. $result .= wf_Link(self::URL_ME . '&polllogs=true&zenlog=true', wf_img('skins/zen.png') . ' ' . __('Zen'), false, 'ubButton') . '';
  979. return ($result);
  980. }
  981. /**
  982. * Renders last lines from OLT polling log
  983. *
  984. * @return string
  985. */
  986. public function renderPollingLog() {
  987. $result = '';
  988. $renderLimit = 100;
  989. //$result .= wf_BackLink(self::URL_ME . '&oltstats=true');
  990. if (file_exists(self::POLL_LOG)) {
  991. $rawLog = zb_ReadLastLines(self::POLL_LOG, $renderLimit);
  992. if (!empty($rawLog)) {
  993. $rawLog = explodeRows($rawLog);
  994. $rawLog = array_reverse($rawLog);
  995. if (!empty($rawLog)) {
  996. $cells = wf_TableCell(__('Date'));
  997. $cells .= wf_TableCell(__('OLT'));
  998. $cells .= wf_TableCell(__('Event'));
  999. $rows = wf_TableRow($cells, 'row1');
  1000. foreach ($rawLog as $io => $eachLine) {
  1001. if (!empty($eachLine)) {
  1002. $eachLine = explode('|', $eachLine);
  1003. //normal format: time|OLT|event
  1004. if (sizeof($eachLine) == 3) {
  1005. $oltId = ubRouting::filters($eachLine[1], 'int');
  1006. $cells = wf_TableCell($eachLine[0]);
  1007. $cells .= wf_TableCell('[' . $oltId . '] ' . @$this->allOltDevices[$oltId]);
  1008. $cells .= wf_TableCell($eachLine[2]);
  1009. $rows .= wf_TableRow($cells, 'row5');
  1010. }
  1011. }
  1012. }
  1013. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  1014. }
  1015. } else {
  1016. $result .= $this->messages->getStyledMessage(__('Nothing to show') . ': ' . __('Logs') . ' ' . __('is empty'), 'warning');
  1017. }
  1018. } else {
  1019. $result .= $this->messages->getStyledMessage(__('Nothing to show') . ': ' . __('OLT polling log') . ' ' . __('does not exist'), 'warning');
  1020. }
  1021. return ($result);
  1022. }
  1023. /**
  1024. * Renders some ONUs navigation list
  1025. *
  1026. * @param array $onuArr
  1027. * @param string $customOnuUrl
  1028. *
  1029. * @return string
  1030. */
  1031. public function renderOnuNavBar($onuArr, $customOnuUrl = '') {
  1032. $result = '';
  1033. if (!empty($onuArr)) {
  1034. $result .= wf_tag('div');
  1035. foreach ($onuArr as $io => $eachOnuId) {
  1036. if (isset($this->allOnu[$eachOnuId])) {
  1037. $onuData = $this->allOnu[$eachOnuId];
  1038. if ($customOnuUrl) {
  1039. $onuUrl = $customOnuUrl . $eachOnuId;
  1040. } else {
  1041. $onuUrl = self::URL_ONU . $eachOnuId;
  1042. }
  1043. $onuLabel = '';
  1044. if (!empty($onuData['mac'])) {
  1045. $onuLabel .= ' ' . $onuData['mac'];
  1046. }
  1047. if (!empty($onuData['serial'])) {
  1048. $onuLabel .= ' ' . $onuData['serial'];
  1049. }
  1050. $result .= wf_tag('div', false, 'dashtask');
  1051. $result .= wf_Link($onuUrl, wf_img('skins/onudev.png'));
  1052. $result .= wf_delimiter(0);
  1053. $result .= __('ONU') . ' ' . $onuLabel;
  1054. $result .= wf_tag('div', true);
  1055. }
  1056. }
  1057. $result .= wf_tag('div', true);
  1058. $result .= wf_CleanDiv();
  1059. } else {
  1060. $this->messages->getStyledMessage(__('Nothing to show'), 'warning');
  1061. }
  1062. return ($result);
  1063. }
  1064. /**
  1065. * Loads avaliable ONUs from database into private data property
  1066. *
  1067. * @param int $oltId load ONU only for selected OLT
  1068. *
  1069. * @return void
  1070. */
  1071. protected function loadOnu($oltId = '') {
  1072. $oltId = ubRouting::filters($oltId, 'int');
  1073. $fromCache = false;
  1074. if ($this->onuCacheTimeout) {
  1075. //specific OLT ONU data
  1076. if ($oltId) {
  1077. $cachedOnus = $this->cache->get(self::KEY_ONUOLT . $oltId, $this->onuCacheTimeout);
  1078. if (!empty($cachedOnus)) {
  1079. $all = $cachedOnus;
  1080. $fromCache = true;
  1081. }
  1082. } else {
  1083. //all OLTs ONU data
  1084. $cachedOnus = $this->cache->get(self::KEY_ALLONU, $this->onuCacheTimeout);
  1085. if (!empty($cachedOnus)) {
  1086. $all = $cachedOnus;
  1087. $fromCache = true;
  1088. }
  1089. }
  1090. }
  1091. //perform database query if no cached data available
  1092. if (!$fromCache) {
  1093. //optional OLT ID filter
  1094. if ($oltId) {
  1095. $this->onuDb->where('oltid', '=', $oltId);
  1096. }
  1097. $all = $this->onuDb->getAll();
  1098. }
  1099. if (!empty($all)) {
  1100. foreach ($all as $io => $each) {
  1101. $this->allOnu[$each['id']] = $each;
  1102. $this->onuMacIdList[$each['mac']] = $each['id'];
  1103. $this->onuSerialIdList[$each['serial']] = $each['id'];
  1104. $this->onuMacOltidList[$each['mac']] = $each['oltid'];
  1105. $this->onuSerialOltidList[$each['serial']] = $each['oltid'];
  1106. //filling used onuIdents array
  1107. $this->existingOnuIdents[strtolower($each['mac'])] = $each['id'];
  1108. $this->existingOnuIdents[strtolower($each['serial'])] = $each['id'];
  1109. }
  1110. }
  1111. //cache requires update
  1112. if ($this->onuCacheTimeout and !$fromCache) {
  1113. if ($oltId) {
  1114. $this->cache->set(self::KEY_ONUOLT . $oltId, $all, $this->onuCacheTimeout);
  1115. } else {
  1116. //all OLTs ONU data
  1117. $this->cache->set(self::KEY_ALLONU, $all, $this->onuCacheTimeout);
  1118. }
  1119. }
  1120. }
  1121. /**
  1122. * Loads avaliable ONUs additional users bindings from database into private data property
  1123. *
  1124. * @return void
  1125. */
  1126. protected function loadOnuExtUsers() {
  1127. $this->allOnuExtUsers = $this->onuExtUsersDb->getAll('id');
  1128. }
  1129. /**
  1130. * Returns Available OLT devices ONU counts
  1131. *
  1132. * @return string
  1133. */
  1134. public function getOltOnuCounts() {
  1135. $result = array();
  1136. if (!empty($this->allOnu)) {
  1137. foreach ($this->allOnu as $io => $each) {
  1138. if (isset($result[$each['oltid']])) {
  1139. $result[$each['oltid']]++;
  1140. } else {
  1141. $result[$each['oltid']] = 1;
  1142. }
  1143. }
  1144. }
  1145. return ($result);
  1146. }
  1147. /**
  1148. * Returns int for ONU has or has not some of subscribers login assignment
  1149. * May return array with status, login and OLT location and IP
  1150. *
  1151. * 0 - has no assignment
  1152. * 1 - has assignment, but login does not exist
  1153. * 2 - has assignment
  1154. *
  1155. * @param int $onuid
  1156. * @param bool $getLogin
  1157. * @param bool $getOLTData
  1158. *
  1159. * @return int|array
  1160. */
  1161. public function checkONUAssignment($onuid, $getLogin = false, $getOLTData = false) {
  1162. $result = 0;
  1163. $tLogin = '';
  1164. $oltData = '';
  1165. $tArray = array();
  1166. if (isset($this->allOnu[$onuid])) {
  1167. $onuRec = $this->allOnu[$onuid];
  1168. if (!empty($onuRec)) {
  1169. $tLogin = $onuRec['login'];
  1170. if (empty($tLogin)) {
  1171. $result = 1;
  1172. } else {
  1173. $query = "SELECT * from `users` WHERE `login`='" . $tLogin . "'";
  1174. $loginRec = simple_query($query);
  1175. (empty($loginRec)) ? $result = 1 : $result = 2;
  1176. }
  1177. if ($getOLTData and isset($this->allOltDevices[$onuRec['oltid']])) {
  1178. $oltData = $this->allOltDevices[$onuRec['oltid']];
  1179. }
  1180. }
  1181. }
  1182. if ($getLogin or $getOLTData) {
  1183. $tArray['status'] = $result;
  1184. $tArray['login'] = $tLogin;
  1185. $tArray['oltdata'] = $oltData;
  1186. $result = $tArray;
  1187. }
  1188. return ($result);
  1189. }
  1190. /**
  1191. * Getter for loaded ONU devices as id=>onuData
  1192. *
  1193. * @return array
  1194. */
  1195. public function getAllOnu() {
  1196. return ($this->allOnu);
  1197. }
  1198. /**
  1199. * Returns ONU ID by ONU MAC or serial
  1200. *
  1201. * @param string $onuIdent existing ONU MAC or serial
  1202. *
  1203. * @return int/0 - on not found
  1204. */
  1205. public function getOnuIDbyIdent($onuIdent) {
  1206. $result = 0;
  1207. $onuIdent = strtolower($onuIdent);
  1208. $sn = strtoupper($onuIdent);
  1209. if (!empty($this->onuMacIdList)) {
  1210. if (isset($this->onuMacIdList[$onuIdent])) {
  1211. $result = $this->onuMacIdList[$onuIdent];
  1212. }
  1213. }
  1214. if (!empty($this->onuSerialIdList)) {
  1215. if (isset($this->onuSerialIdList[$sn])) {
  1216. $result = $this->onuSerialIdList[$sn];
  1217. }
  1218. }
  1219. return ($result);
  1220. }
  1221. /**
  1222. * Performs search in nethosts for a MAC and a login linked to it
  1223. *
  1224. * @param string $mac
  1225. * @param int $macIncrementWith
  1226. *
  1227. * @return array
  1228. */
  1229. public function getUserByONUMAC($mac, $macIncrementWith = 0, $doSerialize = false) {
  1230. if (!empty($macIncrementWith)) {
  1231. $macAsHex = str_replace(':', '', $mac);
  1232. $macAsHex = dechex(hexdec($macAsHex) + $macIncrementWith);
  1233. $macAsHex = (strlen($macAsHex) < 12) ? str_pad($macAsHex, 12, '0', STR_PAD_LEFT) : $macAsHex;
  1234. $mac = implode(":", str_split($macAsHex, 2));
  1235. }
  1236. $query = "SELECT `users`.`login`, `users`.`ip`, `nethosts`.`mac` FROM `users` RIGHT JOIN `nethosts` USING(ip) WHERE mac = '" . $mac . "'";
  1237. $queryResult = simple_queryall($query);
  1238. if (empty($queryResult)) {
  1239. //$result = array('login' => '', 'ip' => '');
  1240. $result = array();
  1241. } else {
  1242. $result = $queryResult[0];
  1243. }
  1244. $result = ($doSerialize) ? json_encode($result) : $result;
  1245. return ($result);
  1246. }
  1247. /**
  1248. * Loads available device models from database
  1249. *
  1250. * @return void
  1251. */
  1252. protected function loadModels() {
  1253. $tmpModels = zb_SwitchModelsGetAll();
  1254. if (!empty($tmpModels)) {
  1255. foreach ($tmpModels as $io => $each) {
  1256. $this->allModelsData[$each['id']] = $each;
  1257. }
  1258. }
  1259. }
  1260. /**
  1261. * Getter for allModelsData array
  1262. *
  1263. * @return array
  1264. */
  1265. public function getAllModelsData() {
  1266. return $this->allModelsData;
  1267. }
  1268. /**
  1269. * Returns model name by its id
  1270. *
  1271. * @param int $id
  1272. * @return string
  1273. */
  1274. protected function getModelName($id) {
  1275. $result = '';
  1276. if (isset($this->allModelsData[$id])) {
  1277. $result = $this->allModelsData[$id]['modelname'];
  1278. }
  1279. return ($result);
  1280. }
  1281. /**
  1282. * Returns model ports count by its id
  1283. *
  1284. * @param int $id
  1285. *
  1286. * @return string
  1287. */
  1288. protected function getModelPorts($id) {
  1289. $result = '';
  1290. if (isset($this->allModelsData[$id])) {
  1291. $result = $this->allModelsData[$id]['ports'];
  1292. }
  1293. return ($result);
  1294. }
  1295. /**
  1296. * Check ONU MAC address unique or not?
  1297. *
  1298. * @param string $mac
  1299. * @return bool
  1300. */
  1301. public function checkMacUnique($mac) {
  1302. $mac = strtolower($mac);
  1303. $result = true;
  1304. if (!empty($this->allOnu)) {
  1305. foreach ($this->allOnu as $io => $each) {
  1306. if ($each['mac'] == $mac) {
  1307. $result = false;
  1308. break;
  1309. }
  1310. }
  1311. }
  1312. return ($result);
  1313. }
  1314. /**
  1315. * Check ONU MAC address or Serial unique or not?
  1316. *
  1317. * @param string $onuIdent
  1318. *
  1319. * @return bool
  1320. */
  1321. public function checkOnuUnique($onuIdent) {
  1322. $result = true;
  1323. if (!empty($onuIdent)) {
  1324. $onuIdent = strtolower($onuIdent);
  1325. // We are heroes
  1326. // Heroes of the night
  1327. // We are ready to live forevermore
  1328. // Our gods lead us through this fight
  1329. if (isset($this->existingOnuIdents[$onuIdent])) {
  1330. $result = false;
  1331. }
  1332. }
  1333. return ($result);
  1334. }
  1335. /**
  1336. * Flushes all ONU related cache keys
  1337. *
  1338. * @return void
  1339. */
  1340. public function flushOnuCache() {
  1341. if ($this->onuCacheTimeout) {
  1342. $this->cache->delete(self::KEY_ALLONU);
  1343. $allCacheKeys = $this->cache->getAllcache();
  1344. if (!empty($allCacheKeys)) {
  1345. foreach ($allCacheKeys as $io => $eachKey) {
  1346. if (ispos($eachKey, self::KEY_ONULISTAJ) or ispos($eachKey, self::KEY_ONUOLT)) {
  1347. $cleanKey = str_replace(UbillingCache::CACHE_PREFIX, '', $eachKey);
  1348. $this->cache->delete($cleanKey);
  1349. }
  1350. }
  1351. }
  1352. }
  1353. }
  1354. /**
  1355. * Flushes some OLT precached list
  1356. *
  1357. * @param int $oltId
  1358. *
  1359. * @return void
  1360. */
  1361. public function flushOnuAjListCache($oltId) {
  1362. if ($this->onuCacheTimeout) {
  1363. if (!empty($oltId)) {
  1364. $allCacheKeys = $this->cache->getAllcache();
  1365. if (!empty($allCacheKeys)) {
  1366. foreach ($allCacheKeys as $io => $eachKey) {
  1367. if ((UbillingCache::CACHE_PREFIX . self::KEY_ONULISTAJ . $oltId) == $eachKey) {
  1368. $cleanKey = str_replace(UbillingCache::CACHE_PREFIX, '', $eachKey);
  1369. $this->cache->delete($cleanKey);
  1370. }
  1371. }
  1372. }
  1373. }
  1374. }
  1375. }
  1376. /**
  1377. * Creates new ONU in database and returns it Id or 0 if action fails
  1378. *
  1379. * @param int $onumodelid
  1380. * @param int $oltid
  1381. * @param string $ip
  1382. * @param string $mac
  1383. * @param string $serial
  1384. * @param string $login
  1385. *
  1386. * @return int/0 - if something went wrong
  1387. */
  1388. public function onuCreate($onumodelid, $oltid, $ip, $mac, $serial, $login) {
  1389. $macF = strtolower($mac);
  1390. $macF = trim($macF);
  1391. $macF = ubRouting::filters($macF, 'mres');
  1392. $onumodelid = ubRouting::filters($onumodelid, 'int');
  1393. $oltid = ubRouting::filters($oltid, 'int');
  1394. $ip = ubRouting::filters($ip, 'mres');
  1395. $serial = ubRouting::filters($serial, 'mres');
  1396. if ($this->onuSerialCaseMode == 1) {
  1397. $serial = strtolower($serial);
  1398. } elseif ($this->onuSerialCaseMode == 2) {
  1399. $serial = strtoupper($serial);
  1400. }
  1401. $login = trim($login);
  1402. $login = ubRouting::filters($login, 'mres');
  1403. $newId = 0;
  1404. $modelid = @$this->allOltSnmp[$oltid]['modelid'];
  1405. //empty MAC workaround for GPON devices
  1406. if (empty($macF) and !empty($serial)) {
  1407. $macF = zb_MacGetRandom();
  1408. log_register('PON CREATE ONU MAC EMPTY TRY REPLACED WITH `' . $macF . '`');
  1409. }
  1410. if (!empty($macF)) {
  1411. if ($this->checkOnuUnique($macF) and $this->checkOnuUnique($serial)) {
  1412. if (check_mac_format($macF)) {
  1413. $this->onuDb->data('onumodelid', $onumodelid);
  1414. $this->onuDb->data('oltid', $oltid);
  1415. $this->onuDb->data('ip', $ip);
  1416. $this->onuDb->data('mac', $macF);
  1417. $this->onuDb->data('serial', $serial);
  1418. $this->onuDb->data('login', $login);
  1419. $this->onuDb->create();
  1420. $newId = $this->onuDb->getLastId();
  1421. log_register('PON CREATE ONU [' . $newId . '] MAC `' . $macF . '` SERIAL `' . $serial . '`');
  1422. } else {
  1423. log_register('PON CREATE ONU MACINVALID TRY `' . $mac . '`');
  1424. }
  1425. } else {
  1426. log_register('PON CREATE ONU DUPLICATE TRY `' . $macF . '` SERIAL `' . $serial . '`');
  1427. }
  1428. } else {
  1429. log_register('PON CREATE ONU MAC EMPTY TRY');
  1430. }
  1431. $this->flushOnuCache();
  1432. return ($newId);
  1433. }
  1434. /**
  1435. * Saves ONU changes into database
  1436. *
  1437. * @param int $onuId
  1438. * @param int $onumodelid
  1439. * @param int $oltid
  1440. * @param string $ip
  1441. * @param string $mac
  1442. * @param string $serial
  1443. * @param string $login
  1444. *
  1445. * @return void
  1446. */
  1447. public function onuSave($onuId, $onumodelid, $oltid, $ip, $mac, $serial, $login) {
  1448. $macF = strtolower($mac);
  1449. $macF = trim($macF);
  1450. $macF = ubRouting::filters($macF, 'mres');
  1451. $onuId = ubRouting::filters($onuId, 'int');
  1452. $onumodelid = ubRouting::filters($onumodelid, 'int');
  1453. $oltid = ubRouting::filters($oltid, 'int');
  1454. $ip = ubRouting::filters($ip, 'mres');
  1455. $onuId = ubRouting::filters($onuId, 'int');
  1456. $serial = ubRouting::filters($serial, 'mres');
  1457. $login = ubRouting::filters($login, 'mres');
  1458. $login = trim($login);
  1459. $currentMac = $this->allOnu[$onuId]['mac'];
  1460. $currentSerial = $this->allOnu[$onuId]['serial'];
  1461. $currentLogin = $this->allOnu[$onuId]['login'];
  1462. $this->onuDb->where('id', '=', $onuId);
  1463. $this->onuDb->data('onumodelid', $onumodelid);
  1464. $this->onuDb->data('oltid', $oltid);
  1465. $this->onuDb->data('ip', $ip);
  1466. if (!empty($macF)) {
  1467. if (check_mac_format($macF)) {
  1468. if ($currentMac != $macF) {
  1469. if ($this->checkOnuUnique($macF)) {
  1470. $this->onuDb->data('mac', $macF);
  1471. } else {
  1472. log_register('PON MACDUPLICATE TRY `' . $mac . '`');
  1473. }
  1474. }
  1475. } else {
  1476. log_register('PON MACINVALID TRY `' . $mac . '`');
  1477. }
  1478. } else {
  1479. log_register('PON MACEMPTY TRY `' . $mac . '`');
  1480. }
  1481. if ($currentSerial != $serial) {
  1482. if ($this->checkOnuUnique($serial)) {
  1483. $this->onuDb->data('serial', $serial);
  1484. if (!empty($serial)) {
  1485. if (empty($currentSerial)) {
  1486. log_register('PON EDIT ONU [' . $onuId . '] SET SERIAL `' . $serial . '`');
  1487. } else {
  1488. log_register('PON EDIT ONU [' . $onuId . '] SET SERIAL `' . $serial . '` INSTEAD `' . $currentSerial . '`');
  1489. }
  1490. } else {
  1491. if (empty($currentSerial)) {
  1492. log_register('PON EDIT ONU [' . $onuId . '] SET SERIAL EMPTY');
  1493. } else {
  1494. log_register('PON EDIT ONU [' . $onuId . '] SET SERIAL EMPTY INSTEAD `' . $currentSerial . '`');
  1495. }
  1496. }
  1497. } else {
  1498. log_register('PON SERIALDUPLICATE TRY `' . $serial . '`');
  1499. }
  1500. }
  1501. if ($currentLogin != $login) {
  1502. $this->onuDb->data('login', $login);
  1503. if (!empty($login)) {
  1504. if (empty($currentLogin)) {
  1505. log_register('PON EDIT ONU [' . $onuId . '] SET LOGIN (' . $login . ')');
  1506. } else {
  1507. log_register('PON EDIT ONU [' . $onuId . '] SET LOGIN (' . $login . ') INSTEAD (' . $currentLogin . ')');
  1508. }
  1509. } else {
  1510. if (empty($currentLogin)) {
  1511. log_register('PON EDIT ONU [' . $onuId . '] SET LOGIN EMPTY');
  1512. } else {
  1513. log_register('PON EDIT ONU [' . $onuId . '] SET LOGIN EMPTY INSTEAD (' . $currentLogin . ')');
  1514. }
  1515. }
  1516. }
  1517. $this->onuDb->save();
  1518. log_register('PON EDIT ONU [' . $onuId . '] MAC `' . $mac . '`');
  1519. $this->flushOnuCache();
  1520. }
  1521. /**
  1522. * Assigns exinsting ONU with some login
  1523. *
  1524. * @param int $onuid
  1525. * @param string $login
  1526. *
  1527. * @return void
  1528. */
  1529. public function onuAssign($onuid, $login) {
  1530. $onuid = ubRouting::filters($onuid, 'int');
  1531. if (isset($this->allOnu[$onuid])) {
  1532. $this->onuDb->where('id', '=', $onuid);
  1533. $this->onuDb->data('login', $login);
  1534. $this->onuDb->save();
  1535. log_register('PON ASSIGN ONU [' . $onuid . '] WITH (' . $login . ')');
  1536. $this->flushOnuCache();
  1537. } else {
  1538. log_register('PON ASSIGN ONU [' . $onuid . '] FAILED');
  1539. }
  1540. }
  1541. /**
  1542. * Deletes onu from database by its ID
  1543. *
  1544. * @param int $onuId
  1545. */
  1546. public function onuDelete($onuId) {
  1547. $onuId = ubRouting::filters($onuId, 'int');
  1548. $this->onuDb->where('id', '=', $onuId);
  1549. $this->onuDb->delete();
  1550. log_register('PON DELETE ONU [' . $onuId . ']');
  1551. $this->flushOnuCache();
  1552. }
  1553. /**
  1554. * Returns ONU creation form
  1555. *
  1556. * @return string
  1557. */
  1558. protected function onuCreateForm() {
  1559. $models = array();
  1560. $result = '';
  1561. if (!empty($this->allModelsData)) {
  1562. foreach ($this->allModelsData as $io => $each) {
  1563. if (@$this->altCfg['ONUMODELS_FILTER']) {
  1564. if (ispos($each['modelname'], 'ONU')) {
  1565. $models[$each['id']] = $each['modelname'];
  1566. }
  1567. } else {
  1568. $models[$each['id']] = $each['modelname'];
  1569. }
  1570. }
  1571. }
  1572. if (!empty($this->allOltDevices)) {
  1573. if (!empty($models)) {
  1574. $inputs = wf_HiddenInput('createnewonu', 'true');
  1575. $inputs .= wf_Selector('newoltid', $this->allOltDevices, __('OLT device') . $this->sup, '', true);
  1576. $inputs .= wf_Selector('newonumodelid', $models, __('ONU model') . $this->sup, '', true);
  1577. if (@$this->altCfg['PON_ONUIPASIF']) {
  1578. $ipFieldLabel = __('Interface');
  1579. } else {
  1580. $ipFieldLabel = __('IP');
  1581. }
  1582. $inputs .= wf_TextInput('newip', $ipFieldLabel, '', true, 20);
  1583. $inputs .= wf_TextInput('newmac', __('MAC') . $this->sup, '', true, 20, 'mac');
  1584. $inputs .= wf_TextInput('newserial', __('Serial number'), '', true, 20);
  1585. $inputs .= wf_TextInput('newlogin', __('Login'), '', true, 20);
  1586. $inputs .= wf_Submit(__('Create'));
  1587. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  1588. } else {
  1589. $messages = new UbillingMessageHelper();
  1590. $result .= $messages->getStyledMessage(__('Any available ONU models exist'), 'error');
  1591. }
  1592. } else {
  1593. $messages = new UbillingMessageHelper();
  1594. $result .= $messages->getStyledMessage(__('Any available OLT devices exist'), 'error');
  1595. }
  1596. return ($result);
  1597. }
  1598. /**
  1599. * Returns ONU fast registration form
  1600. *
  1601. * @param int $oltId
  1602. * @param string $onuMac
  1603. *
  1604. * @return string
  1605. */
  1606. public function onuRegisterForm($oltId, $onuMac, $UserLogin = '', $UserIP = '', $RenderedOutside = false, $PageReloadAfterDone = false, $CtrlIDToReplaceAfterDone = '', $ModalWindowID = '') {
  1607. $models = array();
  1608. $telepathyArray = array();
  1609. $result = '';
  1610. $onuSerial = '';
  1611. if (!empty($onuMac)) {
  1612. if (!check_mac_format($onuMac)) {
  1613. $onuSerial = $onuMac; //this is something like not mac
  1614. $onuMac = zb_MacGetRandom(); //replacing MAC with random one
  1615. }
  1616. }
  1617. if (!empty($this->allModelsData)) {
  1618. foreach ($this->allModelsData as $io => $each) {
  1619. if (@$this->altCfg['ONUMODELS_FILTER']) {
  1620. if (ispos($each['modelname'], 'ONU')) {
  1621. $models[$each['id']] = $each['modelname'];
  1622. }
  1623. } else {
  1624. $models[$each['id']] = $each['modelname'];
  1625. }
  1626. }
  1627. }
  1628. if ($this->onuUknownUserByMACSearchTelepathy and (empty($UserLogin) or empty($UserIP))) {
  1629. $telepathyArray = $this->getUserByONUMAC($onuMac, $this->onuUknownUserByMACSearchIncrement);
  1630. if (!empty($telepathyArray)) {
  1631. $UserLogin = $telepathyArray['login'];
  1632. $UserIP = $telepathyArray['ip'];
  1633. }
  1634. }
  1635. if (!empty($this->allOltDevices)) {
  1636. if (!empty($models)) {
  1637. $inputs = wf_HiddenInput('createnewonu', 'true');
  1638. $inputs .= wf_Selector('newoltid', $this->allOltDevices, __('OLT device') . $this->sup, $oltId, true);
  1639. $inputs .= wf_Selector('newonumodelid', $models, __('ONU model') . $this->sup, '', true);
  1640. $inputs .= wf_TextInput('newip', __('IP'), $UserIP, true, 20, '', '__NewONUIP');
  1641. $inputs .= wf_TextInput('newmac', __('MAC') . $this->sup, $onuMac, true, 20, 'mac', '__NewONUMAC');
  1642. $inputs .= wf_TextInput('newserial', __('Serial number'), $onuSerial, true, 20);
  1643. $inputs .= wf_TextInput('newlogin', __('Login'), $UserLogin, true, 20, '', '__NewONULogin');
  1644. $inputs .= wf_Link('#', __('Check if ONU is assigned to any login already'), true, 'ubButton __CheckONUAssignmentBtn', 'style="width: 100%; text-align: center;padding: 6px 0; margin-top: 5px;"');
  1645. $inputs .= wf_tag('span', false, '', 'id="onuassignment2" style="font-weight: 600; color: #000"');
  1646. $inputs .= wf_tag('span', true);
  1647. if (($this->onuUknownUserByMACSearchShow and (empty($UserLogin) or empty($UserIP))) or $this->onuUknownUserByMACSearchShowAlways) {
  1648. $inputs .= wf_delimiter(0) . wf_tag('div', false, '', 'style="padding: 2px 8px;"');
  1649. $inputs .= __('Try to find user by MAC') . ':';
  1650. $inputs .= wf_tag('div', false, '', 'style="margin-top: 5px;"');
  1651. $inputs .= wf_nbsp(2) . wf_tag('span', false, '', 'style="width: 444px;display: inline-block;float: left;"') .
  1652. __('increase/decrease searched MAC address on (use negative value to decrease MAC)') . wf_tag('span', true) .
  1653. wf_tag('span', false, '', 'style="display: inline-block;padding: 5px 0;"') .
  1654. wf_TextInput('macincrementwith', '', $this->onuUknownUserByMACSearchIncrement, true, '4', '', '__MACIncrementWith') .
  1655. wf_tag('span', true);
  1656. $inputs .= wf_tag('div', true);
  1657. $inputs .= wf_Link('#', __('Search'), true, 'ubButton __UserByMACSearchBtn', 'style="width: 100%; text-align: center; padding: 6px 0; margin-top: 5px;"');
  1658. $inputs .= wf_tag('div', true);
  1659. }
  1660. $NoRedirChkID = 'NoRedirChk_' . wf_InputId();
  1661. $ReloadChkID = 'ReloadChk_' . wf_InputId();
  1662. $SubmitID = 'Submit_' . wf_InputId();
  1663. $FormID = 'Form_' . wf_InputId();
  1664. $HiddenReplID = 'ReplaceCtrlID_' . wf_InputId();
  1665. $HiddenModalID = 'ModalWindowID_' . wf_InputId();
  1666. $inputs .= wf_tag('br');
  1667. $inputs .= (($RenderedOutside) ? wf_CheckInput('NoRedirect', __('Do not redirect anywhere: just add & close'), true, true, $NoRedirChkID, '__ONUAACFormNoRedirChck') : '');
  1668. $inputs .= (($PageReloadAfterDone) ? wf_CheckInput('', __('Reload page after action'), true, true, $ReloadChkID, '__ONUAACFormPageReloadChck') : '');
  1669. $inputs .= wf_tag('br');
  1670. $inputs .= wf_Submit(__('Create'), $SubmitID);
  1671. $result = wf_Form(self::URL_ME, 'POST', $inputs, 'glamour __ONUAssignAndCreateForm', '', $FormID);
  1672. $result .= wf_HiddenInput('', $CtrlIDToReplaceAfterDone, $HiddenReplID, '__ONUAACFormReplaceCtrlID');
  1673. $result .= wf_HiddenInput('', $ModalWindowID, $HiddenModalID, '__ONUAACFormModalWindowID');
  1674. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  1675. $result .= '
  1676. $(\'#' . $FormID . '\').submit(function(evt) {
  1677. if ( $(\'#' . $NoRedirChkID . '\').is(\':checked\') ) {
  1678. evt.preventDefault();
  1679. $.ajax({
  1680. type: "POST",
  1681. url: "' . self::URL_ME . '",
  1682. data: $(\'#' . $FormID . '\').serialize(),
  1683. success: function() {
  1684. if ( $(\'#' . $ReloadChkID . '\').is(\':checked\') ) { location.reload();}
  1685. $( \'#\'+$(\'#' . $HiddenReplID . '\').val() ).replaceWith(\'' . web_ok_icon() . '\');
  1686. $( \'#\'+$(\'#' . $HiddenModalID . '\').val() ).dialog("close");
  1687. }
  1688. });
  1689. }
  1690. });
  1691. ';
  1692. $result .= wf_tag('script', true);
  1693. } else {
  1694. $messages = new UbillingMessageHelper();
  1695. $result .= $messages->getStyledMessage(__('Any available ONU models exist'), 'error');
  1696. }
  1697. } else {
  1698. $messages = new UbillingMessageHelper();
  1699. $result .= $messages->getStyledMessage(__('Any available OLT devices exist'), 'error');
  1700. }
  1701. return ($result);
  1702. }
  1703. /**
  1704. * returns vendor by MAC search control if this enabled in config
  1705. *
  1706. * @return string
  1707. */
  1708. protected function getSearchmacControl($mac) {
  1709. $result = '';
  1710. if ($this->altCfg['MACVEN_ENABLED']) {
  1711. if (cfr('MACVEN')) {
  1712. if (!empty($mac)) {
  1713. $optionState = $this->altCfg['MACVEN_ENABLED'];
  1714. switch ($optionState) {
  1715. case 1:
  1716. $lookupUrl = '?module=macvendor&modalpopup=true&mac=' . $mac;
  1717. $result .= wf_AjaxLink($lookupUrl, wf_img('skins/macven.gif', __('Device vendor')), 'macvendorcontainer', false);
  1718. $result .= wf_AjaxContainerSpan('macvendorcontainer', '', '');
  1719. break;
  1720. case 2:
  1721. $vendorframe = wf_tag('iframe', false, '', 'src="?module=macvendor&mac=' . $mac . '" width="360" height="160" frameborder="0"');
  1722. $vendorframe .= wf_tag('iframe', true);
  1723. $result = wf_modalAuto(wf_img('skins/macven.gif', __('Device vendor')), __('Device vendor'), $vendorframe, '');
  1724. break;
  1725. case 3:
  1726. $lookupUrl = '?module=macvendor&raw=true&mac=' . $mac;
  1727. $result .= wf_AjaxLink($lookupUrl, wf_img('skins/macven.gif', __('Device vendor')), 'macvendorcontainer', false);
  1728. $result .= wf_AjaxContainerSpan('macvendorcontainer', '', '');
  1729. break;
  1730. }
  1731. }
  1732. }
  1733. }
  1734. return ($result);
  1735. }
  1736. /**
  1737. * Renders ONU assigning form
  1738. *
  1739. * @param string $login
  1740. * @return string
  1741. */
  1742. public function onuAssignForm($login) {
  1743. $result = '';
  1744. $params = array();
  1745. $allRealnames = zb_UserGetAllRealnames();
  1746. $allAddress = zb_AddressGetFulladdresslistCached();
  1747. @$userAddress = $allAddress[$login];
  1748. @$userRealname = $allRealnames[$login];
  1749. if (!empty($this->allOnu)) {
  1750. foreach ($this->allOnu as $io => $each) {
  1751. if (empty($each['login'])) {
  1752. $onuLabel = (empty($each['ip'])) ? $each['mac'] : $each['mac'] . ' - ' . $each['ip'];
  1753. $params[$each['id']] = $onuLabel;
  1754. }
  1755. }
  1756. }
  1757. //user data
  1758. $cells = wf_TableCell(__('Real Name'), '30%', 'row2');
  1759. $cells .= wf_TableCell($userRealname);
  1760. $rows = wf_TableRow($cells, 'row3');
  1761. $cells = wf_TableCell(__('Full address'), '30%', 'row2');
  1762. $cells .= wf_TableCell($userAddress);
  1763. $rows .= wf_TableRow($cells, 'row3');
  1764. $result .= wf_TableBody($rows, '100%', 0, '');
  1765. $result .= wf_delimiter();
  1766. if (!empty($params)) {
  1767. $inputs = wf_HiddenInput('assignonulogin', $login);
  1768. $inputs .= wf_Selector('assignonuid', $params, __('ONU'), '', false);
  1769. $inputs .= wf_Submit(__('Save'));
  1770. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  1771. } else {
  1772. $result .= $this->messages->getStyledMessage(__('No ONUs not assigned to users were found'), 'success');
  1773. }
  1774. $result .= wf_CleanDiv();
  1775. $result .= wf_delimiter();
  1776. $result .= web_UserControls($login);
  1777. return ($result);
  1778. }
  1779. /**
  1780. * Returns array of additional ONU assigned users
  1781. *
  1782. * @param int $onuId
  1783. *
  1784. * @return array
  1785. */
  1786. protected function getOnuExtUsers($onuId) {
  1787. $result = array();
  1788. if (!empty($this->allOnuExtUsers)) {
  1789. foreach ($this->allOnuExtUsers as $io => $each) {
  1790. if ($each['onuid'] == $onuId) {
  1791. $result[$each['id']] = $each;
  1792. }
  1793. }
  1794. }
  1795. return ($result);
  1796. }
  1797. /**
  1798. * Deletes existing user binding to ONU by user Id
  1799. *
  1800. * @param int $extUserId
  1801. *
  1802. * @return void
  1803. */
  1804. public function deleteOnuExtUser($extUserId) {
  1805. $extUserId = ubRouting::filters($extUserId, 'int');
  1806. if (isset($this->allOnuExtUsers[$extUserId])) {
  1807. $oldData = $this->allOnuExtUsers[$extUserId];
  1808. $this->onuExtUsersDb->where('id', '=', $extUserId);
  1809. $this->onuExtUsersDb->delete();
  1810. log_register('PON EDIT ONU [' . $oldData['onuid'] . '] DELETE EXTUSER (' . $oldData['login'] . ')');
  1811. }
  1812. }
  1813. /**
  1814. * Renders additional user creation form
  1815. *
  1816. * @param int $onuId
  1817. *
  1818. * @return string
  1819. */
  1820. protected function renderOnuExtUserForm($onuId) {
  1821. $result = '';
  1822. $onuId = vf($onuId, 3);
  1823. if (isset($this->allOnu[$onuId])) {
  1824. $inputs = wf_HiddenInput('newpononuextid', $onuId);
  1825. $inputs .= wf_TextInput('newpononuextlogin', __('Login'), '', false, 20) . ' ';
  1826. $inputs .= wf_Submit(__('Create'));
  1827. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  1828. }
  1829. return ($result);
  1830. }
  1831. /**
  1832. * Creates new ONU additional user binding
  1833. *
  1834. * @param int $onuId
  1835. * @param string $login
  1836. *
  1837. * @return void
  1838. */
  1839. public function createOnuExtUser($onuId, $login) {
  1840. $onuId = ubRouting::filters($onuId, 'int');
  1841. if (isset($this->allOnu[$onuId])) {
  1842. $loginF = ubRouting::filters($login, 'mres');
  1843. $this->onuExtUsersDb->data('onuid', $onuId);
  1844. $this->onuExtUsersDb->data('login', $loginF);
  1845. $this->onuExtUsersDb->create();
  1846. log_register('PON EDIT ONU [' . $onuId . '] ASSIGN EXTUSER (' . $login . ')');
  1847. }
  1848. }
  1849. /**
  1850. * Returns existing ONU data or empty array if it not exists
  1851. *
  1852. * @param int $onuId
  1853. *
  1854. * @return array
  1855. */
  1856. public function getOnuData($onuId) {
  1857. $result = array();
  1858. if (isset($this->allOnu[$onuId])) {
  1859. $result = $this->allOnu[$onuId];
  1860. }
  1861. return ($result);
  1862. }
  1863. /**
  1864. * Returns some ONU signal level as array with following keys: raw/color/type/styled/isoffline
  1865. *
  1866. * @param int $onuId
  1867. *
  1868. * @return array
  1869. */
  1870. public function getOnuSignalLevelData($onuId) {
  1871. $result = array();
  1872. if (isset($this->allOnu[$onuId])) {
  1873. $onuData = $this->allOnu[$onuId];
  1874. $oltId = $onuData['oltid'];
  1875. $oltPollingStats = $this->pollingStatsRead($oltId);
  1876. //load cache once
  1877. if (empty($this->signalCache)) {
  1878. if ($this->oltData->isSignalsAvailable()) {
  1879. $this->loadSignalsCache();
  1880. }
  1881. }
  1882. $offlineFlag = false;
  1883. if (isset($this->signalCache[$onuData['mac']])) {
  1884. $signal = $this->signalCache[$onuData['mac']];
  1885. if (($signal > 0) or ($signal < -27)) {
  1886. $sigColor = self::COLOR_BAD;
  1887. $sigLabel = 'Bad signal';
  1888. } elseif ($signal > -27 and $signal < -25) {
  1889. $sigColor = self::COLOR_AVG;
  1890. $sigLabel = 'Mediocre signal';
  1891. } else {
  1892. $sigColor = self::COLOR_OK;
  1893. $sigLabel = 'Normal';
  1894. }
  1895. if ($signal == self::NO_SIGNAL) {
  1896. $ONUIsOffline = true;
  1897. $signal = __('No');
  1898. $sigColor = self::COLOR_NOSIG;
  1899. $sigLabel = 'No signal';
  1900. $offlineFlag = true;
  1901. }
  1902. } elseif (isset($this->signalCache[$onuData['serial']])) {
  1903. $signal = $this->signalCache[$onuData['serial']];
  1904. if (($signal > 0) or ($signal < -27)) {
  1905. $sigColor = self::COLOR_BAD;
  1906. $sigLabel = 'Bad signal';
  1907. } elseif ($signal > -27 and $signal < -25) {
  1908. $sigColor = self::COLOR_AVG;
  1909. $sigLabel = 'Mediocre signal';
  1910. } else {
  1911. $sigColor = self::COLOR_OK;
  1912. $sigLabel = 'Normal';
  1913. }
  1914. if ($signal == self::NO_SIGNAL) {
  1915. $ONUIsOffline = true;
  1916. $signal = __('No');
  1917. $sigColor = self::COLOR_NOSIG;
  1918. $sigLabel = 'No signal';
  1919. $offlineFlag = true;
  1920. }
  1921. } else {
  1922. $ONUIsOffline = true;
  1923. $signal = __('No');
  1924. $sigColor = self::COLOR_NOSIG;
  1925. $sigLabel = 'No signal';
  1926. $offlineFlag = true;
  1927. }
  1928. $result['raw'] = $signal;
  1929. $result['color'] = $sigColor;
  1930. $result['type'] = $sigLabel;
  1931. $result['styled'] = wf_tag('font', false, '', 'color="' . $sigColor . '"') . $signal . wf_tag('font', true);
  1932. $result['isoffline'] = $offlineFlag;
  1933. $result['polltime'] = '';
  1934. $result['pollnow'] = 0;
  1935. if (!empty($oltPollingStats)) {
  1936. if (!$oltPollingStats['finished']) {
  1937. $result['pollnow'] = 1;
  1938. }
  1939. if ($oltPollingStats['end']) {
  1940. $result['polltime'] = $oltPollingStats['end'];
  1941. }
  1942. }
  1943. }
  1944. return ($result);
  1945. }
  1946. /**
  1947. * Returns styled current ONU signal
  1948. *
  1949. * @param int $onuId
  1950. *
  1951. * @return string
  1952. */
  1953. protected function renderOnuSignalBig($onuId) {
  1954. $result = '';
  1955. if (isset($this->allOnu[$onuId])) {
  1956. $allDeadSwitches = zb_SwitchesGetAllDead();
  1957. $oltId = $this->allOnu[$onuId]['oltid'];
  1958. $oltIp = $this->allOltIps[$oltId];
  1959. $deadOltFlag = (isset($allDeadSwitches[$oltIp])) ? true : false;
  1960. $onuSignal = $this->getOnuSignalLevelData($onuId);
  1961. if (!empty($onuSignal)) {
  1962. $sigTypeLabel=($deadOltFlag) ? __('Latest') : __('Current');
  1963. $result .= wf_tag('div', false, 'onusignalbig');
  1964. $result .= $sigTypeLabel . ' ' . __('Signal') . ' ' . __('ONU');
  1965. $result .= wf_delimiter();
  1966. $result .= wf_tag('font', false, '', 'color="' . $onuSignal['color'] . '" size="16pt"') . $onuSignal['raw'] . wf_tag('font', true);
  1967. $result .= wf_delimiter();
  1968. if ($deadOltFlag) {
  1969. $result .= wf_img('skins/skull.png') . ' ' . __('OLT is dead now');
  1970. } else {
  1971. $result .= __($onuSignal['type']);
  1972. }
  1973. $result .= $this->renderOnuMiscStats($onuId, $onuSignal);
  1974. $result .= ($this->onuUniStatusEnabled) ? $this->renderONUUniStats($onuId, $onuSignal) : '';
  1975. $result .= wf_tag('div', true);
  1976. }
  1977. }
  1978. return ($result);
  1979. }
  1980. /**
  1981. * Renders ONU interface, distance and last dereg reason if available
  1982. *
  1983. * @param int $onuId
  1984. * @param array $signalStatsData
  1985. *
  1986. * @return string
  1987. */
  1988. protected function renderOnuMiscStats($onuId, $signalStatsData) {
  1989. $result = '';
  1990. $offlineFlag = ($signalStatsData['isoffline']) ? true : false;
  1991. if (isset($this->allOnu[$onuId])) {
  1992. $this->loadInterfaceCache();
  1993. $this->loadDistanceCache();
  1994. $this->loadLastDeregCache();
  1995. $onuData = $this->allOnu[$onuId];
  1996. $onuMiscStats = '';
  1997. // interface
  1998. $interfaceIcon = wf_img_sized('skins/pon_icon.gif', __('Interface'), '12');
  1999. if (isset($this->interfaceCache[$onuData['mac']])) {
  2000. $onuMiscStats .= $interfaceIcon . ' ' . $this->interfaceCache[$onuData['mac']] . ' ';
  2001. } else {
  2002. if (isset($this->interfaceCache[$onuData['serial']])) {
  2003. $onuMiscStats .= $interfaceIcon . ' ' . $this->interfaceCache[$onuData['serial']] . ' ';
  2004. }
  2005. }
  2006. //distance
  2007. if (!$offlineFlag) {
  2008. $distanceIcon = wf_img_sized('skins/distance_icon.png', __('Distance'), '12');
  2009. if (isset($this->distanceCache[$onuData['mac']])) {
  2010. $onuMiscStats .= $distanceIcon . ' ' . $this->distanceCache[$onuData['mac']] . __('m') . ' ';
  2011. } else {
  2012. if (isset($this->distanceCache[$onuData['serial']])) {
  2013. $onuMiscStats .= $distanceIcon . ' ' . $this->distanceCache[$onuData['serial']] . __('m') . ' ';
  2014. }
  2015. }
  2016. }
  2017. //last dereg reason
  2018. if ($offlineFlag) {
  2019. $offlineIcon = wf_img_sized('skins/offline_icon.png', __('Last dereg reason'), '12');
  2020. if (isset($this->lastDeregCache[$onuData['mac']])) {
  2021. $onuMiscStats .= $offlineIcon . ' ' . $this->lastDeregCache[$onuData['mac']] . ' ';
  2022. } else {
  2023. if (isset($this->lastDeregCache[$onuData['serial']])) {
  2024. $onuMiscStats .= $offlineIcon . ' ' . $this->lastDeregCache[$onuData['serial']] . ' ';
  2025. }
  2026. }
  2027. }
  2028. //polling time here
  2029. $fullTime = '';
  2030. $shortTime = '';
  2031. if (!empty($signalStatsData['polltime'])) {
  2032. $fullTime = __('Time') . ': ' . date("Y-m-d H:i:s", $signalStatsData['polltime']);
  2033. $shortTime = date("H:i:s", $signalStatsData['polltime']);
  2034. } else {
  2035. $shortTime .= __('In progress now');
  2036. }
  2037. $pollTimeIcon = ($signalStatsData['pollnow']) ? self::POLL_RUNNING : wf_img_sized('skins/icon_time_small.png', $fullTime, '12');
  2038. $onuMiscStats .= $pollTimeIcon . ' ' . $shortTime;
  2039. $containerStyle = 'style="font-size:10pt; padding:10px;"';
  2040. $result .= wf_tag('div', false, '', $containerStyle);
  2041. $result .= $onuMiscStats;
  2042. $result .= wf_tag('div', true);
  2043. }
  2044. return ($result);
  2045. }
  2046. /**
  2047. * Renders ONU UNI port operational status if available
  2048. *
  2049. * @param $onuId
  2050. * @param $signalStatsData
  2051. *
  2052. * @return string
  2053. */
  2054. protected function renderONUUniStats($onuId, $signalStatsData) {
  2055. $result = '';
  2056. $onuMAC = '';
  2057. $onuSerial = '';
  2058. $uniStatsData = '';
  2059. $onuUniOperStats = '';
  2060. $offlineFlag = ($signalStatsData['isoffline']) ? true : false;
  2061. if (isset($this->allOnu[$onuId]) and !$offlineFlag) {
  2062. $this->loadUniOperStatsCache();
  2063. if (!empty($this->allOnu[$onuId]['mac'])) {
  2064. $onuMAC = $this->allOnu[$onuId]['mac'];
  2065. }
  2066. if (!empty($this->allOnu[$onuId]['serial'])) {
  2067. $onuSerial = $this->allOnu[$onuId]['serial'];
  2068. }
  2069. if (!empty($this->uniOperStatsCache[$onuMAC])) {
  2070. $uniStatsData = $this->uniOperStatsCache[$onuMAC];
  2071. } elseif (!empty($this->uniOperStatsCache[$onuSerial])) {
  2072. $uniStatsData = $this->uniOperStatsCache[$onuSerial];
  2073. }
  2074. if (!empty($uniStatsData)) {
  2075. foreach ($uniStatsData as $eachPort => $eachStatus) {
  2076. if ($eachStatus) {
  2077. $interfaceIcon = wf_img_sized('skins/icon_ether.gif', __('Interface')) . wf_nbsp()
  2078. . wf_img_sized('skins/rise_icon.png', __('Up'), '8', '10');
  2079. } else {
  2080. $interfaceIcon = wf_img_sized('skins/icon_ether_down.png', __('Interface')) . wf_nbsp()
  2081. . wf_img_sized('skins/drain_icon.png', __('Down'), '8', '10');
  2082. }
  2083. $onuUniOperStats .= $eachPort . ': ' . $interfaceIcon . wf_nbsp(4);
  2084. }
  2085. $containerStyle = 'style="font-size:10pt; padding:10px;"';
  2086. $result .= wf_tag('div', false, '', $containerStyle);
  2087. $result .= $onuUniOperStats;
  2088. $result .= wf_tag('div', true);
  2089. }
  2090. }
  2091. return ($result);
  2092. }
  2093. /**
  2094. * Performs burial of some ONU
  2095. *
  2096. * @param int $onuId
  2097. *
  2098. * @return void
  2099. */
  2100. public function onuBurial($onuId) {
  2101. $onuid = ubRouting::filters($onuId, 'int');
  2102. if (isset($this->allOnu[$onuId])) {
  2103. $this->onuDb->where('id', '=', $onuId);
  2104. $this->onuDb->data('login', 'dead');
  2105. $this->onuDb->save();
  2106. log_register('PON BURIAL ONU [' . $onuId . ']');
  2107. $this->flushOnuCache();
  2108. } else {
  2109. log_register('PON BURIAL ONU [' . $onuId . '] FAILED');
  2110. }
  2111. }
  2112. /**
  2113. * Performs resurrection of some buried ONU
  2114. *
  2115. * @param int $onuId
  2116. *
  2117. * @return void
  2118. */
  2119. public function onuResurrect($onuId) {
  2120. $onuid = ubRouting::filters($onuId, 'int');
  2121. if (isset($this->allOnu[$onuId])) {
  2122. $this->onuDb->where('id', '=', $onuId);
  2123. $this->onuDb->data('login', '');
  2124. $this->onuDb->save();
  2125. log_register('PON RESURRECT ONU [' . $onuId . ']');
  2126. } else {
  2127. log_register('PON RESURRECT ONU [' . $onuId . '] FAILED');
  2128. }
  2129. }
  2130. /**
  2131. * Returns ONU edit form
  2132. *
  2133. * @param int $onuId
  2134. * @param bool $limitedControls
  2135. *
  2136. * @return string
  2137. */
  2138. public function onuEditForm($onuId, $limitedControls = false) {
  2139. $onuId = ubRouting::filters($onuId, 'int');
  2140. $result = '';
  2141. if (isset($this->allOnu[$onuId])) {
  2142. $messages = new UbillingMessageHelper();
  2143. $models = array();
  2144. if (!empty($this->allModelsData)) {
  2145. foreach ($this->allModelsData as $io => $each) {
  2146. if (@$this->altCfg['ONUMODELS_FILTER']) {
  2147. if (ispos($each['modelname'], 'ONU')) {
  2148. $models[$each['id']] = $each['modelname'];
  2149. }
  2150. } else {
  2151. $models[$each['id']] = $each['modelname'];
  2152. }
  2153. }
  2154. }
  2155. $onuPortsCount = $this->allModelsData[$this->allOnu[$onuId]['onumodelid']]['ports'];
  2156. $onuMaxUsers = $onuPortsCount - 1;
  2157. $onuExtUsers = $this->getOnuExtUsers($onuId);
  2158. $onuCurrentExtUsers = sizeof($onuExtUsers);
  2159. $inputs = wf_HiddenInput('editonu', $onuId);
  2160. if ($this->altCfg['OLTSEL_SEARCHBL']) {
  2161. $inputs .= wf_SelectorSearchable('editoltid', $this->allOltDevices, __('OLT device') . $this->sup, $this->allOnu[$onuId]['oltid'], true, false);
  2162. } else {
  2163. $inputs .= wf_Selector('editoltid', $this->allOltDevices, __('OLT device') . $this->sup, $this->allOnu[$onuId]['oltid'], true, false);
  2164. }
  2165. $inputs .= wf_Selector('editonumodelid', $models, __('ONU model') . $this->sup, $this->allOnu[$onuId]['onumodelid'], true);
  2166. if (@$this->altCfg['PON_ONUIPASIF']) {
  2167. $ipFieldLabel = __('Interface');
  2168. } else {
  2169. $ipFieldLabel = __('IP');
  2170. }
  2171. $inputs .= wf_TextInput('editip', $ipFieldLabel, $this->allOnu[$onuId]['ip'], true, 20);
  2172. $inputs .= wf_TextInput('editmac', __('MAC') . $this->sup . ' ' . $this->getSearchmacControl($this->allOnu[$onuId]['mac']), $this->allOnu[$onuId]['mac'], true, 20);
  2173. $inputs .= wf_TextInput('editserial', __('Serial number'), $this->allOnu[$onuId]['serial'], true, 20);
  2174. $burialLabel = ($this->allOnu[$onuId]['login'] == 'dead') ? ' ' . wf_img('skins/skull.png', __('Buried')) : '';
  2175. $inputs .= wf_TextInput('editlogin', __('Login') . $burialLabel, $this->allOnu[$onuId]['login'], true, 20);
  2176. if (!empty($onuExtUsers)) {
  2177. foreach ($onuExtUsers as $io => $each) {
  2178. //Editing feature: 100$ donate or do it yourself. Im to lazy right now.
  2179. $inputs .= wf_tag('input', false, '', 'name="onuextlogin_' . $each['id'] . '" type="text" value="' . $each['login'] . '" size="20" DISABLED') . ' ';
  2180. if (cfr('PONEDIT')) {
  2181. $controllerUrl = self::URL_ME;
  2182. if ($limitedControls) {
  2183. $controllerUrl = '?module=pl_branchesonuview';
  2184. }
  2185. $inputs .= wf_JSAlert($controllerUrl . '&editonu=' . $onuId . '&deleteextuser=' . $each['id'], wf_img_sized('skins/icon_del.gif', __('Delete'), '13'), $messages->getDeleteAlert()) . ' ';
  2186. }
  2187. $inputs .= wf_Link(self::URL_USERPROFILE . $each['login'], web_profile_icon());
  2188. $inputs .= wf_tag('br');
  2189. }
  2190. }
  2191. if (cfr('PONEDIT')) {
  2192. $inputs .= wf_tag('br');
  2193. $inputs .= wf_Submit(__('Save'));
  2194. }
  2195. $onuEditForm = wf_Form('', 'POST', $inputs, 'glamour');
  2196. $gridCells = wf_TableCell($onuEditForm . wf_CleanDiv(), '50%', '');
  2197. $gridCells .= wf_TableCell($this->renderOnuSignalBig($onuId));
  2198. $gridRows = wf_TableRow($gridCells);
  2199. $result = wf_TableBody($gridRows, '100%', 0, '');
  2200. $result .= wf_CleanDiv();
  2201. ///ponboxes here. We hope.
  2202. if (@$this->altCfg['PONBOXES_ENABLED']) {
  2203. $ponBoxes = new PONBoxes(true);
  2204. //linking if required
  2205. if (ubRouting::checkPost(array($ponBoxes::PROUTE_NEWLINKBOX, $ponBoxes::PROUTE_NEWLINKONU, $ponBoxes::PROUTE_NEWLINKTYPE))) {
  2206. $newLinkBoxId = ubRouting::post($ponBoxes::PROUTE_NEWLINKBOX);
  2207. $newLinkType = ubRouting::post($ponBoxes::PROUTE_NEWLINKTYPE);
  2208. $newLinkOnuId = ubRouting::post($ponBoxes::PROUTE_NEWLINKONU);
  2209. $ponBoxLinkResult = $ponBoxes->createLinkONU($newLinkBoxId, $newLinkOnuId, $newLinkType);
  2210. if (empty($ponBoxLinkResult)) {
  2211. ubRouting::nav(self::URL_ME . '&editonu=' . $newLinkOnuId);
  2212. } else {
  2213. show_error($ponBoxLinkResult);
  2214. }
  2215. }
  2216. //interface render
  2217. $result .= wf_delimiter();
  2218. $result .= $ponBoxes->renderBoxAssignForm($this->allOnu[$onuId]);
  2219. //rendering associated boxes
  2220. $linkedBoxes = $ponBoxes->getLinkedBoxes($this->allOnu[$onuId]);
  2221. if (count($linkedBoxes) > 1) {
  2222. $result .= $ponBoxes->renderCrossLinkWarning();
  2223. }
  2224. $result .= $ponBoxes->renderLinkedBoxes($linkedBoxes);
  2225. }
  2226. $result .= wf_delimiter();
  2227. if (!$limitedControls) {
  2228. $result .= wf_BackLink(self::URL_ONULIST);
  2229. }
  2230. //back to primary user profile control
  2231. if (!empty($this->allOnu[$onuId]['login'])) {
  2232. if ($this->allOnu[$onuId]['login'] != 'dead') {
  2233. $result .= wf_Link(self::URL_USERPROFILE . $this->allOnu[$onuId]['login'], wf_img('skins/icon_user.gif') . ' ' . __('User profile'), false, 'ubButton');
  2234. }
  2235. }
  2236. //ONU burial or resurrection controls
  2237. if (!empty($this->allOnu[$onuId]['login'])) {
  2238. if (cfr('PONEDIT') and !$limitedControls) {
  2239. if (@$this->altCfg['ONU_BURIAL_ENABLED']) {
  2240. if ($this->allOnu[$onuId]['login'] != 'dead') {
  2241. //this ONU is owned by some user. Burial controls here.
  2242. $burCancelUrl = self::URL_ME . '&editonu=' . $onuId;
  2243. $burConfirmUrl = self::URL_ME . '&onuburial=' . $onuId;
  2244. $burAlertLabel = __('Bury this ONU') . '? ' . $messages->getEditAlert();
  2245. $result .= wf_ConfirmDialog($burConfirmUrl, wf_img('skins/skull.png') . __('Bury this ONU'), $burAlertLabel, 'ubButton', $burCancelUrl);
  2246. } else {
  2247. //this ONU is already buried. Ressurection controls here.
  2248. $resCancelUrl = self::URL_ME . '&editonu=' . $onuId;
  2249. $resConfirmUrl = self::URL_ME . '&onuresurrect=' . $onuId;
  2250. $resAlertLabel = __('Resurrect this ONU') . '? ' . $messages->getEditAlert() . ' ';
  2251. $resAlertLabel .= __('After resurrection device will be marked as not belonging to anyone') . '.';
  2252. $result .= wf_ConfirmDialog($resConfirmUrl, wf_img('skins/pigeon_icon.png') . ' ' . __('Resurrect this ONU'), $resAlertLabel, 'ubButton', $resCancelUrl);
  2253. }
  2254. }
  2255. }
  2256. }
  2257. //additional login append forms
  2258. if (cfr('PONEDIT')) {
  2259. if (sizeof($onuExtUsers) < $onuMaxUsers) {
  2260. $extCreationLabel = wf_img_sized('skins/add_icon.png', '', '13') . ' ' . __('Assign additional login');
  2261. $result .= wf_modalAuto($extCreationLabel, __('Additional login') . ' (' . ($onuMaxUsers - $onuCurrentExtUsers) . ' ' . __('remains') . ')', $this->renderOnuExtUserForm($onuId), 'ubButton');
  2262. }
  2263. }
  2264. //ONU deletion control
  2265. if (cfr('PONDEL') and !$limitedControls) {
  2266. $delCancelUrl = self::URL_ME . '&editonu=' . $onuId;
  2267. $delConfirmUrl = self::URL_ME . '&deleteonu=' . $onuId;
  2268. $result .= wf_ConfirmDialog($delConfirmUrl, web_delete_icon() . ' ' . __('Delete') . ' ' . __('ONU'), $messages->getDeleteAlert(), 'ubButton', $delCancelUrl);
  2269. }
  2270. } else {
  2271. $result = wf_tag('div', false, 'alert_error') . __('Strange exeption') . ': ONUID_NOT_EXISTS' . wf_tag('div', true);
  2272. }
  2273. //additional comments handling
  2274. if ($this->altCfg['ADCOMMENTS_ENABLED']) {
  2275. $adcomments = new ADcomments('PONONU');
  2276. $result .= wf_delimiter();
  2277. $result .= wf_tag('h3') . __('Additional comments') . wf_tag('h3', true);
  2278. $result .= $adcomments->renderComments($onuId);
  2279. }
  2280. return ($result);
  2281. }
  2282. /**
  2283. * Renders ONU signal history chart
  2284. *
  2285. * @param int $onuId
  2286. * @return string
  2287. */
  2288. protected function onuSignalHistory($onuId, $ShowTitle = false, $ShowXLabel = false, $ShowYLabel = false, $ShowRangeSelector = false) {
  2289. $billCfg = $this->ubConfig->getBilling();
  2290. $onuId = vf($onuId, 3);
  2291. $result = '';
  2292. if (isset($this->allOnu[$onuId])) {
  2293. //not empty MAC
  2294. if ($this->allOnu[$onuId]['mac']) {
  2295. if (file_exists(self::ONUSIG_PATH . md5($this->allOnu[$onuId]['mac']))) {
  2296. $historyKey = self::ONUSIG_PATH . md5($this->allOnu[$onuId]['mac']);
  2297. $historyKeyMonth = self::ONUSIG_PATH . md5($this->allOnu[$onuId]['mac']) . '_month';
  2298. } elseif (file_exists(self::ONUSIG_PATH . md5($this->allOnu[$onuId]['serial']))) {
  2299. $historyKey = self::ONUSIG_PATH . md5($this->allOnu[$onuId]['serial']);
  2300. $historyKeyMonth = self::ONUSIG_PATH . md5($this->allOnu[$onuId]['serial']) . '_month';
  2301. } else {
  2302. $historyKey = '';
  2303. $historyKeyMonth = '';
  2304. }
  2305. if (!empty($historyKey)) {
  2306. $curdate = curdate();
  2307. $curmonth = curmonth() . '-';
  2308. $getMonthDataCmd = $billCfg['CAT'] . ' ' . $historyKey . ' | ' . $billCfg['GREP'] . ' ' . $curmonth;
  2309. $rawData = shell_exec($getMonthDataCmd);
  2310. $result .= wf_delimiter();
  2311. //current day signal levels
  2312. $todaySignal = '';
  2313. if (!empty($rawData)) {
  2314. $todayTmp = explodeRows($rawData);
  2315. if (!empty($todayTmp)) {
  2316. foreach ($todayTmp as $io => $each) {
  2317. if (ispos($each, $curdate)) {
  2318. $todaySignal .= $each . "\n";
  2319. }
  2320. }
  2321. }
  2322. }
  2323. $GraphTitle = ($ShowTitle) ? __('Today') : '';
  2324. $GraphXLabel = ($ShowXLabel) ? __('Time') : '';
  2325. $GraphYLabel = ($ShowYLabel) ? __('Signal') : '';
  2326. $result .= wf_Graph($todaySignal, '800', '300', false, $GraphTitle, $GraphXLabel, $GraphYLabel, $ShowRangeSelector);
  2327. $result .= wf_delimiter(2);
  2328. //current month signal levels
  2329. $monthSignal = '';
  2330. $curmonth = curmonth();
  2331. if (!empty($rawData)) {
  2332. $monthTmp = explodeRows($rawData);
  2333. if (!empty($monthTmp)) {
  2334. foreach ($monthTmp as $io => $each) {
  2335. if (ispos($each, $curmonth)) {
  2336. $monthSignal .= $each . "\n";
  2337. }
  2338. }
  2339. }
  2340. }
  2341. $GraphTitle = ($ShowTitle) ? __('Monthly graph') : '';
  2342. $GraphXLabel = ($ShowXLabel) ? __('Date') : '';
  2343. file_put_contents($historyKeyMonth, $monthSignal);
  2344. $result .= wf_GraphCSV($historyKeyMonth, '800', '300', false, $GraphTitle, $GraphXLabel, $GraphYLabel, $ShowRangeSelector);
  2345. $result .= wf_delimiter(2);
  2346. //all time signal history
  2347. $GraphTitle = ($ShowTitle) ? __('All time graph') : '';
  2348. $result .= wf_GraphCSV($historyKey, '800', '300', false, $GraphTitle, $GraphXLabel, $GraphYLabel, $ShowRangeSelector);
  2349. $result .= wf_delimiter();
  2350. }
  2351. }
  2352. }
  2353. return ($result);
  2354. }
  2355. /**
  2356. * Returns default list controls
  2357. *
  2358. * @return string
  2359. */
  2360. public function controls() {
  2361. $result = '';
  2362. if (!ubRouting::checkGet('unknownonulist')) {
  2363. if (cfr('PONEDIT')) {
  2364. $result .= wf_modalAuto(wf_img_sized('skins/add_icon.png', '', '16', '16') . ' ' . __('Create') . ' ' . __('ONU'), __('Register new ONU'), $this->onuCreateForm(), 'ubButton') . ' ';
  2365. }
  2366. $availOnuCache = $this->oltData->isOnusAvailable();
  2367. $result .= wf_Link(self::URL_ME . '&forcepoll=true', wf_img_sized('skins/refresh.gif', '', '16', '16') . ' ' . __('Force query'), false, 'ubButton');
  2368. if (!empty($availOnuCache)) {
  2369. if (cfr('PONEDIT')) {
  2370. $result .= wf_Link(self::URL_ME . '&unknownonulist=true', wf_img_sized('skins/question.png', '', '16', '16') . ' ' . __('Unknown ONU'), false, 'ubButton');
  2371. }
  2372. }
  2373. $availOnuFdbCache = $this->oltData->isFdbAvailable();
  2374. if (!empty($availOnuFdbCache)) {
  2375. $result .= wf_Link(self::URL_ME . '&fdbcachelist=true', wf_img_sized('skins/icon_fdb.png', '', '16', '16') . ' ' . __('Current FDB cache'), false, 'ubButton');
  2376. }
  2377. if (@$this->altCfg['PON_ONU_PORT_MAX']) {
  2378. $result .= wf_Link(self::URL_ME . '&oltstats=true', wf_img_sized('skins/icon_stats.gif', '', '16', '16') . ' ' . __('Stats'), false, 'ubButton');
  2379. }
  2380. if (@$this->altCfg['PONMAP_ENABLED']) {
  2381. if (cfr('ONUMAP')) {
  2382. $result .= wf_Link('?module=ponmap&bl=ponizer', wf_img_sized('skins/ponmap_icon.png', '', '16', '16') . ' ' . __('ONU Map'), false, 'ubButton');
  2383. }
  2384. }
  2385. if (@$this->altCfg['PON_ONU_SEARCH_ENABLED']) {
  2386. $result .= wf_modalAuto(web_icon_search() . ' ' . __('Search'), __('Search') . ' ' . __('ONU'), $this->renderOnuSearchForm(), 'ubButton');
  2387. }
  2388. if ($this->altCfg['ONUREG_ZTE']) {
  2389. $zteControls = '';
  2390. if (cfr(OnuRegister::REG_MODULE_RIGHTS)) {
  2391. $zteControls .= wf_link(OnuRegister::UNREG_URL, wf_img_sized('skins/check.png', '', '16', '16') . ' ' . __('Check for unauthenticated ONU/ONT') . ' (' . __('All') . ' OLT)', false, 'ubButton') . wf_delimiter();
  2392. $zteControls .= wf_link(OnuRegister::UNREG_OLTLIST_URL, wf_img_sized('skins/pon_icon.gif', '', '16', '16') . ' ' . __('Check for unauthenticated ONU/ONT') . ' OLT', false, 'ubButton') . wf_delimiter();
  2393. $zteControls .= wf_link(OnuRegister::UNREG_MASS_FIX_PREVIEW_URL, wf_img_sized('skins/brain.png', '', '16', '16') . ' ' . __('Mass fix'), false, 'ubButton') . wf_delimiter();
  2394. }
  2395. if (cfr(OnuRegister::VLAN_MODULE_RIGHTS)) {
  2396. $zteControls .= wf_link(OnuRegister::VLAN_MODULE_URL, wf_img_sized('skins/register.png', '', '16', '16') . ' ' . __('Edit OLT Cards'), false, 'ubButton') . wf_delimiter();
  2397. }
  2398. $result .= wf_modalAuto(web_icon_extended() . ' ' . __('ZTE'), __('ZTE'), $zteControls, 'ubButton');
  2399. }
  2400. } else {
  2401. $result .= wf_BackLink(self::URL_ONULIST);
  2402. $result .= wf_Link(self::URL_ME . '&forcepoll=true&uol=true', wf_img_sized('skins/refresh.gif', '', '16', '16') . ' ' . __('Force query'), false, 'ubButton');
  2403. if (cfr('ROOT')) {
  2404. //ONU batch registration accessible only for ROOT users now
  2405. $massRegUrl = self::URL_ME . '&onumassreg=true';
  2406. $massRegCancelUrl = '?module=ponizer&unknownonulist=true';
  2407. $alertLabel = __('Register all unknown ONUs') . '? ' . __('Are you serious');
  2408. $dialogLink = wf_img('skins/icon_addrow.png') . ' ' . __('Register all unknown ONUs');
  2409. $result .= wf_ConfirmDialog($massRegUrl, $dialogLink, $alertLabel, 'ubButton', $massRegCancelUrl, __('Are you serious'));
  2410. }
  2411. }
  2412. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  2413. $result .= wf_JSEmptyFunc();
  2414. $result .= wf_JSElemInsertedCatcherFunc();
  2415. $result .= '
  2416. function checkONUAssignment() {
  2417. if ( typeof( $(\'input[name=newmac]\').val() ) === "string" && $(\'input[name=newmac]\').val().length > 0 ) {
  2418. $.ajax({
  2419. type: "GET",
  2420. url: "?module=ponizer",
  2421. data: {action:\'checkONUAssignment\', onumac:$(\'input[name=newmac]\').val()},
  2422. success: function(result) {
  2423. $(\'#onuassignment2\').text(result);
  2424. }
  2425. });
  2426. } else {$(\'#onuassignment2\').text(\'\');}
  2427. }
  2428. function dynamicBindClick(ctrlClassName) {
  2429. $(document).on("click", ctrlClassName, function(evt) {
  2430. evt.preventDefault();
  2431. checkONUAssignment($(ctrlClassName).val());
  2432. return false;
  2433. });
  2434. }
  2435. onElementInserted(\'body\', \'.__CheckONUAssignmentBtn\', function(element) {
  2436. dynamicBindClick(\'.__CheckONUAssignmentBtn\');
  2437. });
  2438. function OLTIndividualRefresh(OLTID, JQAjaxTab, RefreshButtonSelector) {
  2439. $.ajax({
  2440. type: "GET",
  2441. url: "' . self::URL_ME . '",
  2442. data: {IndividualRefresh:true, forceoltidpoll:OLTID},
  2443. success: function(result) {
  2444. if ($.type(JQAjaxTab) === \'string\') {
  2445. $("#"+JQAjaxTab).DataTable().ajax.reload();
  2446. } else {
  2447. $(JQAjaxTab).DataTable().ajax.reload();
  2448. }
  2449. if ($.type(RefreshButtonSelector) === \'string\') {
  2450. $("#"+RefreshButtonSelector).find(\'img\').toggleClass("image_rotate");
  2451. } else {
  2452. $(RefreshButtonSelector).find(\'img\').toggleClass("image_rotate");
  2453. }
  2454. }
  2455. });
  2456. };
  2457. function getOLTInfo(OLTID, InfoBlckSelector, ReturnHTML = false, InSpoiler = false) {
  2458. $.ajax({
  2459. type: "GET",
  2460. url: "' . self::URL_ME . '",
  2461. data: { IndividualRefresh:true,
  2462. GetOLTInfo:true,
  2463. apid:OLTID,
  2464. returnAsHTML:ReturnHTML,
  2465. returnInSpoiler:InSpoiler
  2466. },
  2467. success: function(result) {
  2468. var InfoBlck = $(InfoBlckSelector);
  2469. if ( !InfoBlck.length || !(InfoBlck instanceof jQuery)) {return false;}
  2470. $(InfoBlck).html(result);
  2471. }
  2472. });
  2473. }
  2474. ';
  2475. // making an event binding for "DelUserAssignment" button("red cross" near user's login) on "ONU create&assign form"
  2476. // to be able to create "ONU create&assign form" dynamically and not to put it's content to every "Create ONU" button in JqDt tables
  2477. // creating of "ONU create&assign form" dynamically reduces the amount of text and page weight dramatically
  2478. $result .= '$(document).on("click", ".__UsrDelAssignButton", function(evt) {
  2479. $("[name=assignoncreate]").val("");
  2480. $(\'.__UsrAssignBlock\').html("' . __('Do not assign WiFi equipment to any user') . '");
  2481. evt.preventDefault();
  2482. return false;
  2483. });
  2484. ';
  2485. // making an event binding for "ONU create&assign form" 'Submit' action to be able to create "ONU create&assign form" dynamically
  2486. $result .= '$(document).on("submit", ".__ONUAssignAndCreateForm", function(evt) {
  2487. if ($(document.activeElement).attr("class") == \'__MACIncrementWith\') {
  2488. evt.preventDefault();
  2489. $(".__UserByMACSearchBtn").click();
  2490. return false;
  2491. }
  2492. //var FrmAction = \'"\' + $(".__ONUAssignAndCreateForm").attr("action") + \'"\';
  2493. var FrmAction = $(".__ONUAssignAndCreateForm").attr("action");
  2494. if ( $(".__ONUAACFormNoRedirChck").is(\':checked\') ) {
  2495. evt.preventDefault();
  2496. $.ajax({
  2497. type: "POST",
  2498. url: FrmAction,
  2499. data: $(".__ONUAssignAndCreateForm").serialize(),
  2500. success: function() {
  2501. if ( $(".__ONUAACFormPageReloadChck").is(\':checked\') ) { location.reload();}
  2502. $( \'#\'+$(".__ONUAACFormReplaceCtrlID").val() ).replaceWith(\'' . web_ok_icon() . '\');
  2503. $( \'#\'+$(".__ONUAACFormModalWindowID").val() ).dialog("close");
  2504. }
  2505. });
  2506. }
  2507. });
  2508. ';
  2509. $result .= '$(document).on("click", ".__UserByMACSearchBtn", function(evt) {
  2510. //__NewONULogin, __NewONUIP, __NewONUMAC, __MACIncrementWith
  2511. $.ajax({
  2512. type: "GET",
  2513. url: "' . self::URL_ME . '",
  2514. data: {
  2515. searchunknownonu:true,
  2516. searchunknownmac:$(".__NewONUMAC").val(),
  2517. searchunknownincrement:$(".__MACIncrementWith").val(),
  2518. searchunknownserialize:true
  2519. },
  2520. success: function(result) {
  2521. var tObj = JSON.parse(result);
  2522. if ( empty(tObj.login) && empty(tObj.ip) ) {
  2523. alert(\'' . __('User is not found') . '\');
  2524. } else {
  2525. $(".__NewONULogin").val(tObj.login);
  2526. $(".__NewONUIP").val(tObj.ip);
  2527. }
  2528. }
  2529. });
  2530. evt.preventDefault();
  2531. return false;
  2532. });
  2533. ';
  2534. $result .= wf_tag('script', true);
  2535. $result .= wf_delimiter();
  2536. return ($result);
  2537. }
  2538. /**
  2539. * Returns ONU signal history chart
  2540. *
  2541. * @param int $onuId
  2542. * @return string
  2543. */
  2544. public function loadonuSignalHistory($onuId, $ReturnInSpoiler) {
  2545. $result = $this->onuSignalHistory($onuId, true, true, true, true);
  2546. if ($ReturnInSpoiler) {
  2547. $result = wf_Spoiler($result, __('Signal levels history graphs'), $this->ONUChartsSpoilerClosed, '', '', '', '', 'style="margin: 10px auto;display: table;"');
  2548. }
  2549. $result = show_window(__('ONU signal history'), $result);
  2550. return ($result);
  2551. }
  2552. /**
  2553. * Renders available ONU JQDT list container
  2554. *
  2555. * @return string
  2556. */
  2557. public function renderOnuList() {
  2558. $distCacheAvail = $this->oltData->isDistancesAvailable();
  2559. $intCacheAvail = $this->oltData->isInterfacesAvailable();
  2560. $lastDeregCacheAvail = $this->oltData->isDeregsAvailable();
  2561. $oltOnuCounters = $this->getOltOnuCounts();
  2562. $opts = '"order": [[ 0, "desc" ]]';
  2563. if ($this->deferredLoadingFlag) {
  2564. $opts .= ', "deferLoading": 100';
  2565. }
  2566. $result = '';
  2567. $tabClickScript = '';
  2568. $tabsList = array();
  2569. $tabsData = array();
  2570. // to prevent changing the keys order of $this->allOLTDevices we are using "+" opreator and not all those "array_merge" and so on
  2571. $QickOLTsArray = array(-9999 => '') + $this->allOltDevices;
  2572. foreach ($this->allOltDevices as $oltId => $eachOltData) {
  2573. $AjaxURLStr = '' . self::URL_ME . '&ajaxonu=true&oltid=' . $oltId . '';
  2574. $JQDTId = 'jqdt_' . md5($AjaxURLStr);
  2575. $OLTIDStr = 'OLTID_' . $oltId;
  2576. $InfoButtonID = 'InfID_' . $oltId;
  2577. $InfoBlockID = 'InfBlck_' . $oltId;
  2578. $QuickOLTLinkID = 'QuickOLTLinkID_' . $oltId;
  2579. $QuickOLTDDLName = 'QuickOLTDDL_' . wf_InputId();
  2580. $QuickOLTLink = wf_tag('span', false, '', 'id="' . $QuickOLTLinkID . '"') .
  2581. wf_img('skins/menuicons/switches.png') . wf_tag('span', true);
  2582. $oltRenderMode = $this->getOltOnuRenderMode($oltId);
  2583. $columns = array('ID');
  2584. if ($intCacheAvail) {
  2585. $columns[] = __('Interface');
  2586. }
  2587. $columns[] = 'Model';
  2588. if ($this->ipColumnVisible) {
  2589. if (@$this->altCfg['PON_ONUIPASIF']) {
  2590. $columns[] = 'Interface';
  2591. } else {
  2592. $columns[] = 'IP';
  2593. }
  2594. }
  2595. $onuIdentColumn = '';
  2596. if ($oltRenderMode == 'mac') {
  2597. $onuIdentColumn = __('MAC');
  2598. } else {
  2599. $onuIdentColumn = __('Serial');
  2600. }
  2601. $columns[] = $onuIdentColumn;
  2602. $columns[] = 'Signal';
  2603. if ($distCacheAvail) {
  2604. $columns[] = __('Distance') . ' (' . __('m') . ')';
  2605. }
  2606. if ($lastDeregCacheAvail) {
  2607. $columns[] = __('Last dereg reason');
  2608. }
  2609. $columns[] = 'Address';
  2610. $columns[] = 'Real Name';
  2611. $columns[] = 'Tariff';
  2612. $columns[] = 'Actions';
  2613. if ($this->EnableQuickOLTLinks) {
  2614. if ($this->ponizerUseTabUI) {
  2615. $QuickOLTDDLName = 'QuickOLTDDL_100500';
  2616. $tabClickScript = wf_tag('script', false, '', 'type="text/javascript"');
  2617. $tabClickScript .= '$(\'a[href="#' . $QuickOLTLinkID . '"]\').click(function(evt) {
  2618. var tmpID = $(this).attr("href").replace("#QuickOLTLinkID_", "");
  2619. if ($(\'[name="' . $QuickOLTDDLName . '"]\').val() != tmpID) {
  2620. $(\'[name="' . $QuickOLTDDLName . '"]\').val(tmpID);
  2621. }
  2622. });
  2623. ';
  2624. $tabClickScript .= wf_tag('script', true);
  2625. } else {
  2626. $QuickOLTLinkInput = wf_tag('div', false, '', 'style="width: 100%;text-align: right;margin-top: 15px;margin-bottom: 20px"') .
  2627. wf_tag('font', false, '', 'style="font-weight: 600"') . __('Go to OLT') . wf_tag('font', true) .
  2628. wf_nbsp(2) . wf_Selector($QuickOLTDDLName, $QickOLTsArray, '', '', true) .
  2629. wf_tag('script', false, '', 'type="text/javascript"') .
  2630. '$(\'[name="' . $QuickOLTDDLName . '"]\').change(function(evt) {
  2631. var LinkIDObjFromVal = $(\'#QuickOLTLinkID_\'+$(this).val());
  2632. $(\'body,html\').scrollTop( $(LinkIDObjFromVal).offset().top - 25 );
  2633. });' .
  2634. wf_tag('script', true) .
  2635. wf_tag('div', true);
  2636. }
  2637. } else {
  2638. $QuickOLTLinkInput = '';
  2639. }
  2640. if ($this->OLTIndividualRepollAJAX) {
  2641. if ($this->ponizerUseTabUI) {
  2642. if ($this->isPollingNow($oltId)) {
  2643. $refresh_button = wf_tag('span', false, '', 'title="' . __('In progress now') . '"') . self::POLL_RUNNING . wf_tag('span', true);
  2644. } else {
  2645. $refresh_button = wf_tag('span', false, '', 'href="#" id="' . $OLTIDStr . '" title="' . __('Refresh data for this OLT') . '" style="cursor: pointer;"');
  2646. $refresh_button .= wf_img('skins/refresh.gif');
  2647. $refresh_button .= wf_tag('span', true);
  2648. }
  2649. } else {
  2650. $refresh_button = wf_tag('a', false, '', 'href="#" id="' . $OLTIDStr . '" title="' . __('Refresh data for this OLT') . '"');
  2651. $refresh_button .= wf_img('skins/refresh.gif');
  2652. $refresh_button .= wf_tag('a', true);
  2653. }
  2654. $refresh_button .= wf_tag('script', false, '', 'type="text/javascript"');
  2655. $refresh_button .= '$(\'#' . $OLTIDStr . '\').click(function(evt) {
  2656. $(\'img\', this).addClass("image_rotate");
  2657. OLTIndividualRefresh(' . $oltId . ', ' . $JQDTId . ', ' . $OLTIDStr . ');
  2658. evt.preventDefault();
  2659. return false;
  2660. });';
  2661. $refresh_button .= wf_tag('script', true);
  2662. } else {
  2663. $refresh_button = wf_Link(self::URL_ME . '&forceoltidpoll=' . $oltId, wf_img('skins/refresh.gif', __('Refresh data for this OLT')));
  2664. }
  2665. if ($this->ponizerUseTabUI) {
  2666. $tabsList[$QuickOLTLinkID] = array(
  2667. 'options' => '',
  2668. 'caption' => $refresh_button . wf_nbsp(4) . wf_img('skins/menuicons/switches.png') . wf_nbsp(2) . @$eachOltData,
  2669. 'additional_data' => $tabClickScript
  2670. );
  2671. $tabsData[$QuickOLTLinkID] = array(
  2672. 'options' => 'style="padding: 0 0 0 2px;"',
  2673. 'body' => wf_JqDtLoader($columns, $AjaxURLStr, false, 'ONU', 100, $opts),
  2674. 'additional_data' => ''
  2675. );
  2676. } else {
  2677. $result .= show_window($refresh_button . wf_nbsp(4) . $QuickOLTLink . wf_nbsp(2) . @$eachOltData, wf_JqDtLoader($columns, $AjaxURLStr, false, 'ONU', 100, $opts) . $QuickOLTLinkInput);
  2678. }
  2679. }
  2680. if ($this->ponizerUseTabUI) {
  2681. $tabsDivOpts = 'style="border: none;padding: 0;"';
  2682. $tabsLstOpts = 'style="border: none;background: #fff;"';
  2683. if ($this->EnableQuickOLTLinks and !empty($this->allOltDevices)) {
  2684. $QuickOLTDDLName = 'QuickOLTDDL_100500';
  2685. $QickOLTsArray = $this->allOltDevices;
  2686. $oltSelectorBody = wf_Selector($QuickOLTDDLName, $QickOLTsArray, '', '', true, false, 'someid');
  2687. $QuickOLTLinkInput = wf_tag('div', false, '', 'style="margin-top: 15px;text-align: right;"') .
  2688. wf_tag('font', false, '', 'style="font-weight: 600"') . __('Go to OLT') . wf_tag('font', true) .
  2689. wf_nbsp(2) . $oltSelectorBody .
  2690. wf_tag('script', false, '', 'type="text/javascript"') .
  2691. '$(\'[name="' . $QuickOLTDDLName . '"]\').change(function(evt) {
  2692. $(\'a[href="#QuickOLTLinkID_\'+$(this).val()+\'"]\').click();
  2693. });' .
  2694. wf_tag('script', true) .
  2695. wf_tag('div', true);
  2696. } else {
  2697. $QuickOLTLinkInput = '';
  2698. }
  2699. //interface grid construction
  2700. $ponizerGrid = '';
  2701. $ponizerGrid .= $QuickOLTLinkInput . wf_delimiter(0);
  2702. $ponizerGrid .= wf_TabsCarouselInitLinking();
  2703. $ponizerGrid .= wf_TabsGen('ui-tabs', $tabsList, $tabsData, $tabsDivOpts, $tabsLstOpts, true);
  2704. $ponizerGrid .= $QuickOLTLinkInput;
  2705. //rendering it
  2706. show_window('', $ponizerGrid);
  2707. } else {
  2708. return ($result);
  2709. }
  2710. }
  2711. /**
  2712. * Renders OLT stats
  2713. *
  2714. * @return string
  2715. */
  2716. public function renderOltStats() {
  2717. $oltOnuCounters = $this->getOltOnuCounts();
  2718. $onuMaxCountConf = @$this->altCfg['PON_ONU_PORT_MAX'];
  2719. $herdEnabledFlag = (@$this->altCfg['HERD_OF_PONIES']) ? true : false;
  2720. $oltOnuFilled = array();
  2721. $oltOnuPonPortMax = array();
  2722. $oltInterfacesFilled = array();
  2723. $oltInterfaceDescrs = array();
  2724. $signals = array();
  2725. $badSignals = array();
  2726. $avgSignals = array();
  2727. $oltsTemps = array(); //oltId=>temperature
  2728. $oltData = new OLTAttractor();
  2729. $statsControls = wf_BackLink(self::URL_ONULIST);
  2730. $statsControls .= wf_Link(self::URL_ME . '&oltstats=true', wf_img('skins/icon_stats_16.gif') . ' ' . __('Stats') . ' ' . __('OLT'), false, 'ubButton') . ' ';
  2731. if (!ubRouting::checkGet('temperature')) {
  2732. $statsControls .= wf_Link(self::URL_ME . '&oltstats=true&temperature=true', wf_img('skins/temperature.png') . ' ' . __('Temperature'), false, 'ubButton') . ' ';
  2733. } else {
  2734. $statsControls .= wf_Link(self::URL_ME . '&oltstats=true', wf_img('skins/notemperature.png') . ' ' . __('Temperature'), false, 'ubButton') . ' ';
  2735. }
  2736. $statsControls .= wf_Link(self::URL_ME . '&oltstats=true&pollstats=true', wf_img('skins/icon_time_small.png') . ' ' . __('Devices polling stats'), false, 'ubButton') . ' ';
  2737. $statsControls .= wf_Link(self::URL_ME . '&polllogs=true', wf_img('skins/log_icon_small.png') . ' ' . __('OLT polling log'), false, 'ubButton') . ' ';
  2738. if (cfr('ROOT')) {
  2739. $cleanupUrl = self::URL_ME . '&oltstats=true&pondatacleanup=true';
  2740. $cleanupCancel = self::URL_ME . '&oltstats=true';
  2741. $cleanupLabel = wf_img('skins/icon_cleanup.png') . ' ' . __('Cache cleanup');
  2742. $cleanupAlert = __('Clear all cache') . '?';
  2743. $statsControls .= wf_ConfirmDialog($cleanupUrl, $cleanupLabel, $cleanupAlert, 'ubButton', $cleanupCancel, __('Cleanup') . '?');
  2744. }
  2745. $result = '';
  2746. $result .= $statsControls;
  2747. $result .= wf_tag('br');
  2748. foreach ($this->allOltDevices as $oltId => $eachOltData) {
  2749. if (isset($oltOnuCounters[$oltId])) {
  2750. $onuCount = $oltOnuCounters[$oltId];
  2751. $oltModelId = @$this->allOltSnmp[$oltId]['modelid'];
  2752. $oltPorts = @$this->allOltModels[$oltModelId]['ports'];
  2753. $snmpTemplatesMaxPort = @$this->snmpTemplates[$oltModelId]['define']['PON_ONU_PORT_MAX'];
  2754. $onuMaxCount = (!empty($snmpTemplatesMaxPort)) ? $snmpTemplatesMaxPort : $onuMaxCountConf;
  2755. if ((!empty($oltModelId)) and (!empty($oltPorts)) and (!empty($onuMaxCount))) {
  2756. $oltData->setOltId($oltId); //switching attractor scope
  2757. $maxOnuPerOlt = $oltPorts * $onuMaxCount;
  2758. $oltOnuFilled[$oltId] = zb_PercentValue($maxOnuPerOlt, $onuCount);
  2759. $oltOnuPonPortMax[$oltId] = $onuMaxCount;
  2760. $interfaces = $oltData->readInterfaces();
  2761. //is any ONU interfaces here?
  2762. if (!empty($interfaces)) {
  2763. $signals = $oltData->readSignals();
  2764. $ifaceDescrs = $oltData->readInterfacesDescriptions();
  2765. foreach ($interfaces as $eachMac => $eachInterface) {
  2766. $cleanInterface = strstr($eachInterface, ':', true);
  2767. if (isset($oltInterfacesFilled[$oltId][$cleanInterface])) {
  2768. $oltInterfacesFilled[$oltId][$cleanInterface]++;
  2769. } else {
  2770. $oltInterfacesFilled[$oltId][$cleanInterface] = 1;
  2771. }
  2772. if (isset($signals[$eachMac])) {
  2773. $macSignal = $signals[$eachMac];
  2774. if ((($macSignal > -27) and ($macSignal < -25))) {
  2775. if (isset($avgSignals[$oltId][$cleanInterface])) {
  2776. $avgSignals[$oltId][$cleanInterface]++;
  2777. } else {
  2778. $avgSignals[$oltId][$cleanInterface] = 1;
  2779. }
  2780. }
  2781. if ((($macSignal > 0) or ($macSignal < -27))) {
  2782. if (isset($badSignals[$oltId][$cleanInterface])) {
  2783. $badSignals[$oltId][$cleanInterface]++;
  2784. } else {
  2785. $badSignals[$oltId][$cleanInterface] = 1;
  2786. }
  2787. }
  2788. }
  2789. //storing PON ifaces descriptions, if not stored yet
  2790. if (
  2791. !isset($oltInterfaceDescrs[$oltId][$cleanInterface])
  2792. and !empty($ifaceDescrs) and !empty($ifaceDescrs[$cleanInterface])
  2793. ) {
  2794. $oltInterfaceDescrs[$oltId][$cleanInterface] = ' | ' . $ifaceDescrs[$cleanInterface];
  2795. }
  2796. }
  2797. }
  2798. }
  2799. }
  2800. }
  2801. if ((!empty($oltInterfacesFilled)) and (!empty($oltOnuFilled))) {
  2802. foreach ($oltOnuFilled as $oltId => $oltFilledPercent) {
  2803. $oltData->setOltId($oltId);
  2804. $oltControls = '';
  2805. $result .= wf_tag('h3');
  2806. $result .= $this->allOltDevices[$oltId] . ' ' . __('filled on') . ' ' . $oltFilledPercent . '%';
  2807. $result .= ' (' . $oltOnuCounters[$oltId] . ' ' . __('ONU') . ' ' . __('Registered') . ')';
  2808. if (@$this->altCfg['PONMAP_ENABLED']) {
  2809. $oltControls .= ' ' . wf_Link(PONONUMap::URL_ME . '&' . PONONUMap::ROUTE_FILTER_OLT . '=' . $oltId, wf_img('skins/ponmap_icon.png', __('ONU Map')), false);
  2810. }
  2811. $result .= $oltControls;
  2812. $result .= wf_tag('h3', true);
  2813. if (isset($oltInterfacesFilled[$oltId])) {
  2814. $cells = wf_TableCell(__('Interface'));
  2815. $cells .= wf_TableCell(__('Count'));
  2816. $cells .= wf_TableCell(__('Mediocre signal'));
  2817. $cells .= wf_TableCell(__('Mediocre signal') . ' %');
  2818. $cells .= wf_TableCell(__('Bad signal'));
  2819. $cells .= wf_TableCell(__('Bad signal') . ' %');
  2820. $cells .= wf_TableCell(__('Visual'));
  2821. $rows = wf_TableRow($cells, 'row1');
  2822. foreach ($oltInterfacesFilled[$oltId] as $eachInterface => $eachInterfaceCount) {
  2823. $eachInterfacePercent = zb_PercentValue($oltOnuPonPortMax[$oltId], $eachInterfaceCount);
  2824. $oltIfaceDescr = ($this->showPONIfaceDescrStatsTab and !empty($oltInterfaceDescrs[$oltId][$eachInterface])) ? $oltInterfaceDescrs[$oltId][$eachInterface] : '';
  2825. $avgSignalCount = @$avgSignals[$oltId][$eachInterface];
  2826. $badSignalCount = @$badSignals[$oltId][$eachInterface];
  2827. $avgSignalColor = '';
  2828. $avgSignalColorEnd = '';
  2829. $avgSignalPercent = '';
  2830. $badSignalColor = '';
  2831. $badSignalColorEnd = '';
  2832. $badSignalPercent = '';
  2833. $interfaceFillColor = '';
  2834. $interfaceFillColorEnd = '';
  2835. if ($eachInterfacePercent > 80) {
  2836. $interfaceFillColor = wf_tag('font', false, '', 'color="' . self::COLOR_AVG . '"') . wf_tag('b', false);
  2837. $interfaceFillColorEnd = wf_tag('b', true) . wf_tag('font', true);
  2838. }
  2839. if ($eachInterfacePercent > 90) {
  2840. $interfaceFillColor = wf_tag('font', false, '', 'color="' . self::COLOR_BAD . '"') . wf_tag('b', false);
  2841. $interfaceFillColorEnd = wf_tag('b', true) . wf_tag('font', true);
  2842. }
  2843. $interfaceFillLabel = $interfaceFillColor . $eachInterfaceCount . ' (' . $eachInterfacePercent . '%)' . $interfaceFillColorEnd;
  2844. if (!empty($avgSignalCount)) {
  2845. if ($avgSignalCount >= 3) {
  2846. $avgSignalColor = wf_tag('font', false, '', 'color="' . self::COLOR_AVG . '"') . wf_tag('b', false);
  2847. $avgSignalColorEnd = wf_tag('b', true) . wf_tag('font', true);
  2848. } else {
  2849. $avgSignalColor = '';
  2850. $avgSignalColorEnd = '';
  2851. }
  2852. $avgSignalPercent = zb_PercentValue($eachInterfaceCount, $avgSignalCount) . '%';
  2853. } else {
  2854. $avgSignalCount = '';
  2855. }
  2856. if (!empty($badSignalCount)) {
  2857. if ($badSignalCount >= 3) {
  2858. $badSignalColor = wf_tag('font', false, '', 'color="' . self::COLOR_BAD . '"') . wf_tag('b', false);
  2859. $badSignalColorEnd = wf_tag('b', true) . wf_tag('font', true);
  2860. } else {
  2861. $badSignalColor = '';
  2862. $badSignalColorEnd = '';
  2863. }
  2864. $badSignalPercent = zb_PercentValue($eachInterfaceCount, $badSignalCount) . '%';
  2865. } else {
  2866. $badSignalCount = '';
  2867. }
  2868. $eachInterfaceLabel = $eachInterface;
  2869. if ($this->ponIfDescribe) {
  2870. $controllerUrl = self::URL_ME . '&oltid=' . $oltId . '&if=' . $eachInterface;
  2871. $ponIfDescr = $this->ponInterfaces->getDescription($oltId, $eachInterface);
  2872. if (!empty($ponIfDescr)) {
  2873. $ponIfDescr = ' ' . $ponIfDescr;
  2874. }
  2875. if (cfr('PONEDIT')) {
  2876. $eachInterfaceLabel = wf_Link($controllerUrl, $eachInterface) . $ponIfDescr;
  2877. } else {
  2878. $eachInterfaceLabel = $eachInterface . ' ' . $ponIfDescr;
  2879. }
  2880. }
  2881. $cells = wf_TableCell($eachInterfaceLabel . $oltIfaceDescr);
  2882. $cells .= wf_TableCell($interfaceFillLabel, '', '', 'sorttable_customkey="' . $eachInterfaceCount . '"');
  2883. $cells .= wf_TableCell($avgSignalColor . $avgSignalCount . $avgSignalColorEnd);
  2884. $cells .= wf_TableCell($avgSignalPercent);
  2885. $cells .= wf_TableCell($badSignalColor . $badSignalCount . $badSignalColorEnd);
  2886. $cells .= wf_TableCell($badSignalPercent);
  2887. $cells .= wf_TableCell(web_bar($eachInterfaceCount, $oltOnuPonPortMax[$oltId]), '', '', 'sorttable_customkey="' . $eachInterfaceCount . '"');
  2888. $rows .= wf_TableRow($cells, 'row5');
  2889. }
  2890. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  2891. //gettin uptime
  2892. $oltUptime = $oltData->readUptime();
  2893. if (!empty($oltUptime)) {
  2894. $result .= __('Uptime') . ': ' . $oltUptime;
  2895. }
  2896. //getting temperature
  2897. $oltTemperature = $oltData->readTemperature();
  2898. if (!empty($oltTemperature)) {
  2899. $oltsTemps[$oltId] = $oltTemperature; //filling temp array
  2900. $result .= ' / ' . __('Temperature') . ': ' . $oltTemperature . ' °C';
  2901. }
  2902. $result .= wf_delimiter(0);
  2903. }
  2904. }
  2905. //temperature gauges here
  2906. if (ubRouting::checkGet('temperature')) {
  2907. $result = $statsControls . wf_tag('br');
  2908. if (!empty($oltsTemps)) {
  2909. foreach ($oltsTemps as $oltTempId => $oltTempValue) {
  2910. $result .= wf_renderTemperature($oltTempValue, $this->allOltDevices[$oltTempId]);
  2911. }
  2912. $result .= wf_CleanDiv();
  2913. } else {
  2914. $messages = new UbillingMessageHelper();
  2915. $result .= $messages->getStyledMessage(__('Nothing to show'), 'warning');
  2916. }
  2917. }
  2918. //or OLT polling timing stats
  2919. if (ubRouting::checkGet('pollstats')) {
  2920. if (!empty($this->allOltDevices)) {
  2921. $totalTime = 0;
  2922. $devicesPolled = 0;
  2923. $pollTimings = array();
  2924. $cells = wf_TableCell(__('ID'));
  2925. $cells .= wf_TableCell(__('OLT'));
  2926. $cells .= wf_TableCell(__('Model'));
  2927. $cells .= wf_TableCell('⏳ ' . __('from'));
  2928. $cells .= wf_TableCell('⌛ ' . __('to'));
  2929. $cells .= wf_TableCell('⏱️ ' . __('time'));
  2930. $cells .= wf_TableCell('📊 ' . __('Visual'));
  2931. $rows = wf_TableRow($cells, 'row1');
  2932. //poll timing preprocessing
  2933. foreach ($this->allOltDevices as $oltId => $eachDevice) {
  2934. $pollStats = $this->pollingStatsRead($oltId);
  2935. if (!empty($pollStats)) {
  2936. $devPollTime = 0;
  2937. if (!empty($pollStats['start']) and !empty($pollStats['end'])) {
  2938. $devPollTime = $pollStats['end'] - $pollStats['start'];
  2939. if ($herdEnabledFlag) {
  2940. if ($devPollTime > $totalTime) {
  2941. $totalTime = $devPollTime;
  2942. }
  2943. } else {
  2944. $totalTime += $devPollTime;
  2945. }
  2946. }
  2947. $pollTimings[$oltId]['start'] = $pollStats['start'];
  2948. $pollTimings[$oltId]['end'] = $pollStats['end'];
  2949. $pollTimings[$oltId]['finished'] = $pollStats['finished'];
  2950. $pollTimings[$oltId]['time'] = $devPollTime;
  2951. }
  2952. }
  2953. //rendering stats
  2954. if (!empty($pollTimings)) {
  2955. foreach ($pollTimings as $oltId => $pollStats) {
  2956. $pollingFinished = $pollStats['finished'];
  2957. if (!empty($pollStats['start'])) {
  2958. $pollingStartLabel = date("Y-m-d H:i:s", $pollStats['start']);
  2959. } else {
  2960. $pollingStartLabel = '-';
  2961. }
  2962. if (($pollingFinished) and (!empty($pollStats['start'])) and (!empty($pollStats['end']))) {
  2963. $pollingTimeLabel = zb_formatTime($pollStats['time']);
  2964. $pollingEndLabel = date("Y-m-d H:i:s", $pollStats['end']);
  2965. $visualLabel = web_bar($pollStats['time'], $totalTime);
  2966. } else {
  2967. $pollingTimeLabel = wf_tag('span', false, '', 'title="' . __('In progress now') . '"') . self::POLL_RUNNING . wf_tag('span', true);
  2968. $pollingTimeLabel .= ' ' . __('In progress now');
  2969. $pollingEndLabel = '-';
  2970. $visualLabel = '∞';
  2971. }
  2972. $oltModelLabel = '';
  2973. $oltModelId = (isset($this->allOltModelIds[$oltId])) ? $this->allOltModelIds[$oltId] : 0;
  2974. if ($oltModelId) {
  2975. if (isset($this->allOltModels[$oltModelId])) {
  2976. $oltModelLabel = $this->allOltModels[$oltModelId]['modelname'];
  2977. }
  2978. }
  2979. $cells = wf_TableCell($oltId);
  2980. $cells .= wf_TableCell($this->allOltDevices[$oltId]);
  2981. $cells .= wf_TableCell($oltModelLabel);
  2982. $cells .= wf_TableCell($pollingStartLabel);
  2983. $cells .= wf_TableCell($pollingEndLabel);
  2984. $cells .= wf_TableCell($pollingTimeLabel, '', '', 'sorttable_customkey="' . $pollStats['time'] . '"');
  2985. $cells .= wf_TableCell($visualLabel, '20%', '', 'sorttable_customkey="' . $pollStats['time'] . '"');
  2986. $rows .= wf_TableRow($cells, 'row5');
  2987. $devicesPolled++;
  2988. }
  2989. }
  2990. $result = $statsControls;
  2991. $result .= wf_tag('h3') . __('SNMP query') . wf_tag('h3', true);
  2992. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  2993. $result .= wf_delimiter(0);
  2994. $result .= wf_tag('b') . __('Total') . ' ' . __('time') . ': ' . wf_tag('b', true) . zb_formatTime($totalTime) . wf_tag('br');
  2995. $result .= wf_tag('b') . __('Total') . ' ' . __('OLT') . ': ' . wf_tag('b', true) . $devicesPolled . wf_tag('br');
  2996. } else {
  2997. $messages = new UbillingMessageHelper();
  2998. $result .= $messages->getStyledMessage(__('Nothing to show'), 'warning');
  2999. }
  3000. }
  3001. } else {
  3002. $messages = new UbillingMessageHelper();
  3003. $result .= $messages->getStyledMessage(__('Nothing to show'), 'warning');
  3004. }
  3005. return ($result);
  3006. }
  3007. /**
  3008. * Renders unknown ONU list container
  3009. *
  3010. * @return string
  3011. */
  3012. public function renderUnknownOnuList() {
  3013. $result = '';
  3014. if ($this->llidColVisibleUnknownONU) {
  3015. $columns = array('OLT', 'Login', 'Address', 'Real Name', 'Tariff', 'IP', 'Interface', __('MAC') . ' ' . __('or') . ' ' . __('Serial'), 'Actions');
  3016. } else {
  3017. $columns = array('OLT', 'Login', 'Address', 'Real Name', 'Tariff', 'IP', __('MAC') . ' ' . __('or') . ' ' . __('Serial'), 'Actions');
  3018. }
  3019. $opts = '"order": [[ 0, "desc" ]]';
  3020. $result = wf_JqDtLoader($columns, self::URL_ME . '&ajaxunknownonu=true', false, 'ONU', 100, $opts);
  3021. $result .= wf_delimiter(0);
  3022. return ($result);
  3023. }
  3024. /**
  3025. * Returns current FDB cache list container with controls
  3026. *
  3027. * @return string
  3028. */
  3029. public function renderOnuFdbCache() {
  3030. $result = wf_BackLink(self::URL_ONULIST);
  3031. if (cfr('ROOT')) {
  3032. //auto OLT associtation fixing interface
  3033. $fixCancelUrl = self::URL_ME . '&fdbcachelist=true';
  3034. $fixConfirmUrl = self::URL_ME . '&fdbcachelist=true&fixonuoltassings=true';
  3035. $fixDialogLabel = wf_img('skins/icon_repair.gif') . ' ' . __('Fix OLT inconsistencies');
  3036. $fixDialogNotice = __('This operation automatically remaps ONU assigns whith OLT devices from where last data was received for this ONUs');
  3037. $result .= wf_ConfirmDialog($fixConfirmUrl, $fixDialogLabel, $fixDialogNotice, 'ubButton', $fixCancelUrl);
  3038. }
  3039. $result .= wf_delimiter();
  3040. $columns = array('OLT', 'ONU', 'ID', 'Vlan', 'MAC', 'Address', 'Login', 'Real Name', 'Tariff');
  3041. $opts = '"order": [[ 0, "desc" ]]';
  3042. $result .= wf_JqDtLoader($columns, self::URL_ME . '&fdbcachelist=true&ajaxfdblist=true', false, 'ONU', 100, $opts);
  3043. return ($result);
  3044. }
  3045. /**
  3046. * Renders OLT FDB list container
  3047. *
  3048. * @param int $onuid
  3049. * @param string $customDataSource
  3050. *
  3051. * @return string
  3052. */
  3053. public function renderOltFdbList($onuid = '', $customDataSource = '') {
  3054. $result = '';
  3055. $columns = array('ID', 'Vlan', 'MAC', 'Address', 'Real Name', 'Tariff');
  3056. $opts = '"order": [[ 0, "desc" ]]';
  3057. if ($customDataSource) {
  3058. $dataSource = $customDataSource . $onuid;
  3059. } else {
  3060. $dataSource = self::URL_ME . '&ajaxoltfdb=true&onuid=' . $onuid;
  3061. }
  3062. $result = wf_JqDtLoader($columns, $dataSource, false, 'ONU', 100, $opts);
  3063. return ($result);
  3064. }
  3065. /**
  3066. * Loads existing signal cache from FS
  3067. *
  3068. * @return void
  3069. */
  3070. protected function loadSignalsCache() {
  3071. $this->signalCache = $this->reviewDataSet($this->oltData->getSignalsAll());
  3072. }
  3073. /**
  3074. * Loads ONU distance cache
  3075. *
  3076. * @return void
  3077. */
  3078. protected function loadDistanceCache() {
  3079. $this->distanceCache = $this->reviewDataSet($this->oltData->getDistancesAll());
  3080. }
  3081. /**
  3082. * Loads ONU last dereg reasons cache
  3083. *
  3084. * @return void
  3085. */
  3086. protected function loadLastDeregCache() {
  3087. $this->lastDeregCache = $this->reviewDataSet($this->oltData->getDeregsAll());
  3088. }
  3089. /**
  3090. * Loads ONU interface cache
  3091. *
  3092. * @return void
  3093. */
  3094. protected function loadInterfaceCache() {
  3095. $this->interfaceCache = $this->reviewDataSet($this->oltData->getInterfacesAll());
  3096. }
  3097. /**
  3098. * Loads available OLTs PON interfaces descriptions
  3099. *
  3100. * @return void
  3101. */
  3102. protected function loadPONIfaceDescrCache() {
  3103. $this->ponIfaceDescrCache = $this->oltData->getInterfacesDescriptions();
  3104. }
  3105. /**
  3106. * Loads OLT FDB cache
  3107. *
  3108. * @return void
  3109. */
  3110. protected function loadFDBCache() {
  3111. $this->FDBCache = $this->reviewDataSet($this->oltData->getFdbAll());
  3112. }
  3113. protected function loadUniOperStatsCache() {
  3114. $this->uniOperStatsCache = $this->reviewDataSet($this->oltData->getUniOperStatsAll());
  3115. }
  3116. /**
  3117. * Fills onuIndexCache array
  3118. *
  3119. * NOTICE: not similar with previous all - in readOnuCache() is [onuIdx]=>onuMac
  3120. * REQUIRED: onuMac=>oltId
  3121. *
  3122. * @return void
  3123. */
  3124. protected function fillONUIndexCache() {
  3125. $this->onuIndexCache = $this->reviewDataSet($this->oltData->getONUonOLTAll());
  3126. }
  3127. /**
  3128. * Returns array of unknown ONUs MACs which can be filtered by OLT ID and returned just like simple array
  3129. * or formed HTML selector ready to use on web page
  3130. *
  3131. * @param int $FilterByOLTID
  3132. * @param bool $ReturnAsHTMLSelector
  3133. * @param bool $AddEmptyFirsSelectorItem
  3134. * @param string $HTMLSelectorID
  3135. * @param string $HTMLSelectorName
  3136. * @param string $HTMLSelectorLabel
  3137. * @param string $HTMLSelectorSelectedItem
  3138. * @param bool $HTMLSelectorBR
  3139. * @param bool $HTMLSelectorSort
  3140. *
  3141. * @return array|string
  3142. */
  3143. public function getUnknownONUMACList($FilterByOLTID = 0, $ReturnAsHTMLSelector = false, $AddEmptyFirsSelectorItem = false, $HTMLSelectorID = 'nonameselectorid', $HTMLSelectorName = 'nonameselector', $HTMLSelectorLabel = '', $HTMLSelectorSelectedItem = '', $HTMLSelectorBR = false, $HTMLSelectorSort = false) {
  3144. $UnknownONUList = ($ReturnAsHTMLSelector and $AddEmptyFirsSelectorItem) ? array('' => '-') : array();
  3145. $this->fillONUIndexCache();
  3146. if (!empty($this->onuIndexCache)) {
  3147. foreach ($this->onuIndexCache as $onuMac => $oltId) {
  3148. if (!empty($FilterByOLTID) and $oltId != $FilterByOLTID) {
  3149. continue;
  3150. }
  3151. //not registered?
  3152. if ($this->checkOnuUnique($onuMac)) {
  3153. $UnknownONUList[$onuMac] = $onuMac;
  3154. }
  3155. }
  3156. }
  3157. return (($ReturnAsHTMLSelector) ? wf_Selector($HTMLSelectorName, $UnknownONUList, $HTMLSelectorLabel, $HTMLSelectorSelectedItem, $HTMLSelectorBR, $HTMLSelectorSort, $HTMLSelectorID) : $UnknownONUList);
  3158. }
  3159. /**
  3160. * Renders json formatted data about unregistered ONU
  3161. *
  3162. * @return void
  3163. */
  3164. public function ajaxOnuUnknownData() {
  3165. $json = new wf_JqDtHelper();
  3166. $this->fillONUIndexCache();
  3167. if (!empty($this->onuIndexCache)) {
  3168. $allUsermacs = zb_UserGetAllMACs();
  3169. $allUserData = zb_UserGetAllDataCache();
  3170. if ($this->llidColVisibleUnknownONU) {
  3171. $this->loadInterfaceCache();
  3172. }
  3173. foreach ($this->onuIndexCache as $onuMac => $oltId) {
  3174. //not registered?
  3175. if ($this->checkOnuUnique($onuMac)) {
  3176. $login = in_array($onuMac, array_map('strtolower', $allUsermacs)) ? array_search($onuMac, array_map('strtolower', $allUsermacs)) : '';
  3177. $userLink = $login ? wf_Link('?module=userprofile&username=' . $login, web_profile_icon() . ' ' . @$allUserData[$login]['login'] . '', false) : '';
  3178. $userLogin = $login ? @$allUserData[$login]['login'] : '';
  3179. $userRealnames = $login ? @$allUserData[$login]['realname'] : '';
  3180. $userTariff = $login ? @$allUserData[$login]['Tariff'] : '';
  3181. $userIP = $login ? @$allUserData[$login]['ip'] : '';
  3182. $LnkID = wf_InputId();
  3183. if ($this->llidColVisibleUnknownONU) {
  3184. $onuLLID = (empty($this->interfaceCache[$onuMac]) ? '' : $this->interfaceCache[$onuMac]);
  3185. }
  3186. $actControls = wf_tag('a', false, '', 'id="' . $LnkID . '" href="#" title="' . __('Register new ONU') . '"');
  3187. $actControls .= web_icon_create();
  3188. $actControls .= wf_tag('a', true);
  3189. $actControls .= wf_tag('script', false, '', 'type="text/javascript"');
  3190. $actControls .= '
  3191. $(\'#' . $LnkID . '\').click(function(evt) {
  3192. $.ajax({
  3193. type: "GET",
  3194. url: "' . self::URL_ME . '",
  3195. data: {
  3196. renderCreateForm:true,
  3197. renderDynamically:true,
  3198. renderedOutside:true,
  3199. reloadPageAfterDone:false,
  3200. userLogin:"' . $userLogin . '",
  3201. userIP:"' . $userIP . '",
  3202. onumac:"' . $onuMac . '",
  3203. oltid:"' . $oltId . '",
  3204. ModalWID:"pon_dialog-modal_' . $LnkID . '",
  3205. ModalWBID:"body_pon_dialog-modal_' . $LnkID . '",
  3206. ActionCtrlID:"' . $LnkID . '"
  3207. },
  3208. success: function(result) {
  3209. $(document.body).append(result);
  3210. $(\'#pon_dialog-modal_' . $LnkID . '\').dialog("open");
  3211. }
  3212. });
  3213. evt.preventDefault();
  3214. return false;
  3215. });
  3216. ';
  3217. $actControls .= wf_tag('script', true);
  3218. $oltData = @$this->allOltDevices[$oltId];
  3219. if (!isset($this->hideOnuMac[$onuMac])) {
  3220. //brand new BDCOM issue temorary workaround. Broken serials too.
  3221. if (!ispos($onuMac, 'no:such') and !ispos($onuMac, PHP_EOL)) {
  3222. $data[] = $oltData;
  3223. $data[] = $userLink;
  3224. $data[] = @$allUserData[$login]['fulladress'];
  3225. $data[] = $userRealnames;
  3226. $data[] = $userTariff;
  3227. $data[] = $userIP;
  3228. if ($this->llidColVisibleUnknownONU) {
  3229. $data[] = $onuLLID;
  3230. }
  3231. $data[] = $onuMac;
  3232. $data[] = $actControls;
  3233. $json->addRow($data);
  3234. unset($data);
  3235. }
  3236. }
  3237. }
  3238. }
  3239. }
  3240. $json->getJson();
  3241. }
  3242. /**
  3243. * Returns state of ONU_RENDER_MODE misc section option for some olt, if it exists.
  3244. *
  3245. * @param int $oltId
  3246. *
  3247. * @return string mac/serial
  3248. */
  3249. protected function getOltOnuRenderMode($oltId) {
  3250. $result = 'mac';
  3251. if (isset($this->allOltSnmp[$oltId])) {
  3252. $oltModelId = $this->allOltSnmp[$oltId]['modelid'];
  3253. if (isset($this->snmpTemplates[$oltModelId])) {
  3254. $oltTemplate = $this->snmpTemplates[$oltModelId];
  3255. if (isset($oltTemplate['misc'])) {
  3256. if (isset($oltTemplate['misc']['ONU_RENDER_MODE'])) {
  3257. $result = $oltTemplate['misc']['ONU_RENDER_MODE'];
  3258. }
  3259. }
  3260. }
  3261. }
  3262. return ($result);
  3263. }
  3264. /**
  3265. * Renders json formatted data for jquery data tables list with ONU signals list
  3266. *
  3267. * @param string $OltId
  3268. * @return void
  3269. */
  3270. public function ajaxOnuData($OltId) {
  3271. $OnuByOLT = $this->getOnuArrayByOltID($OltId);
  3272. $json = new wf_JqDtHelper();
  3273. $allRealnames = zb_UserGetAllRealnames();
  3274. $allAddress = zb_AddressGetFulladdresslistCached();
  3275. $allTariffs = zb_TariffsGetAllUsers();
  3276. $burialEnabled = @$this->altCfg['ONU_BURIAL_ENABLED'];
  3277. $noSignalLabel = __('No');
  3278. $fromCache = false;
  3279. $oltOnuRenderMode = $this->getOltOnuRenderMode($OltId);
  3280. //try to get all data from cache
  3281. if ($this->onuCacheTimeout) {
  3282. $ajData = $this->cache->get(self::KEY_ONULISTAJ . $OltId, $this->onuCacheTimeout);
  3283. if (!empty($ajData)) {
  3284. $fromCache = true;
  3285. }
  3286. }
  3287. if (!$fromCache) {
  3288. if ($this->altCfg['ADCOMMENTS_ENABLED']) {
  3289. $adcomments = new ADcomments('PONONU');
  3290. $adc = true;
  3291. } else {
  3292. $adc = false;
  3293. }
  3294. $this->loadSignalsCache();
  3295. $distCacheAvail = $this->oltData->isDistancesAvailable();
  3296. if ($distCacheAvail) {
  3297. $this->loadDistanceCache();
  3298. }
  3299. $intCacheAvail = $this->oltData->isInterfacesAvailable();
  3300. if ($intCacheAvail) {
  3301. $this->loadInterfaceCache();
  3302. }
  3303. $intDescrCacheAvail = $this->oltData->isInterfacesDescriptionsAvailable();
  3304. $curOLTIfaceDescrs = array();
  3305. if ($intDescrCacheAvail) {
  3306. $this->loadPONIfaceDescrCache();
  3307. if (!empty($this->ponIfaceDescrCache[$OltId])) {
  3308. $intDescrCacheAvail = true;
  3309. $curOLTIfaceDescrs = $this->ponIfaceDescrCache[$OltId];
  3310. } else {
  3311. $intDescrCacheAvail = false;
  3312. }
  3313. }
  3314. $lastDeregCacheAvail = $this->oltData->isDeregsAvailable();
  3315. if ($lastDeregCacheAvail) {
  3316. $this->loadLastDeregCache();
  3317. }
  3318. if (!empty($OnuByOLT)) {
  3319. foreach ($OnuByOLT as $io => $each) {
  3320. $renderThisOnu = true;
  3321. //not show buried ONUs
  3322. if ($burialEnabled) {
  3323. if ($each['login'] == 'dead') {
  3324. $renderThisOnu = false;
  3325. }
  3326. }
  3327. if ($renderThisOnu) {
  3328. $userTariff = '';
  3329. $ONUIsOffline = false;
  3330. if (!empty($each['login'])) {
  3331. $userLogin = trim($each['login']);
  3332. if (isset($allAddress[$userLogin])) {
  3333. $userLink = wf_Link('?module=userprofile&username=' . $userLogin, web_profile_icon() . ' ' . $allAddress[$userLogin], false);
  3334. } else {
  3335. $userLink = wf_Link('?module=userprofile&username=' . $userLogin, web_profile_icon(), false) . ' ' . $userLogin;
  3336. }
  3337. @$userRealName = $allRealnames[$userLogin];
  3338. //tariff data
  3339. if (isset($allTariffs[$userLogin])) {
  3340. $userTariff = $allTariffs[$userLogin];
  3341. }
  3342. } else {
  3343. $userLink = '';
  3344. $userRealName = '';
  3345. }
  3346. //checking adcomments availability
  3347. if ($adc) {
  3348. $indicatorIcon = $adcomments->getCommentsIndicator($each['id']);
  3349. } else {
  3350. $indicatorIcon = '';
  3351. }
  3352. $actLinks = wf_Link('?module=ponizer&editonu=' . $each['id'], web_edit_icon(), false);
  3353. $actLinks .= ' ' . $indicatorIcon;
  3354. //coloring signal
  3355. if (isset($this->signalCache[$each['mac']])) {
  3356. $signal = $this->signalCache[$each['mac']];
  3357. if (($signal > 0) or ($signal < -27)) {
  3358. $sigColor = self::COLOR_BAD;
  3359. } elseif ($signal > -27 and $signal < -25) {
  3360. $sigColor = self::COLOR_AVG;
  3361. } else {
  3362. $sigColor = self::COLOR_OK;
  3363. }
  3364. if ($signal == self::NO_SIGNAL) {
  3365. $ONUIsOffline = true;
  3366. $signal = $noSignalLabel;
  3367. $sigColor = self::COLOR_NOSIG;
  3368. }
  3369. } elseif (isset($this->signalCache[$each['serial']])) {
  3370. $signal = $this->signalCache[$each['serial']];
  3371. if (($signal > 0) or ($signal < -27)) {
  3372. $sigColor = self::COLOR_BAD;
  3373. } elseif ($signal > -27 and $signal < -25) {
  3374. $sigColor = self::COLOR_AVG;
  3375. } else {
  3376. $sigColor = self::COLOR_OK;
  3377. }
  3378. if ($signal == self::NO_SIGNAL) {
  3379. $ONUIsOffline = true;
  3380. $signal = $noSignalLabel;
  3381. $sigColor = self::COLOR_NOSIG;
  3382. }
  3383. } else {
  3384. $ONUIsOffline = true;
  3385. $signal = $noSignalLabel;
  3386. $sigColor = self::COLOR_NOSIG;
  3387. }
  3388. $data[] = $each['id'];
  3389. if ($intCacheAvail) {
  3390. if (isset($this->interfaceCache[$each['mac']])) {
  3391. $ponInterface = $this->interfaceCache[$each['mac']];
  3392. } else {
  3393. if (isset($this->interfaceCache[$each['serial']])) {
  3394. $ponInterface = $this->interfaceCache[$each['serial']];
  3395. } else {
  3396. $ponInterface = '';
  3397. }
  3398. }
  3399. $cleanInterface = strstr($ponInterface, ':', true);
  3400. $oltIfaceDescr = ($this->showPONIfaceDescrMainTab and $intDescrCacheAvail and !empty($curOLTIfaceDescrs[$cleanInterface])) ? $curOLTIfaceDescrs[$cleanInterface] . ' | ' : '';
  3401. $data[] = $oltIfaceDescr . $ponInterface;
  3402. }
  3403. $data[] = $this->getModelName($each['onumodelid']);
  3404. if ($this->ipColumnVisible) {
  3405. $data[] = $each['ip'];
  3406. }
  3407. //MAC/Serial column here
  3408. if ($oltOnuRenderMode == 'mac') {
  3409. $onuIdent = $each['mac'];
  3410. } else {
  3411. $onuIdent = $each['serial'];
  3412. }
  3413. $data[] = $onuIdent;
  3414. $data[] = wf_tag('font', false, '', 'color=' . $sigColor . '') . $signal . wf_tag('font', true);
  3415. if ($distCacheAvail) {
  3416. if (isset($this->distanceCache[$each['mac']])) {
  3417. $data[] = $this->distanceCache[$each['mac']];
  3418. } else {
  3419. if (isset($this->distanceCache[$each['serial']])) {
  3420. $data[] = $this->distanceCache[$each['serial']];
  3421. } else {
  3422. $data[] = '';
  3423. }
  3424. }
  3425. }
  3426. if ($lastDeregCacheAvail) {
  3427. if ($ONUIsOffline) {
  3428. $data[] = @$this->lastDeregCache[$each['mac']];
  3429. } else {
  3430. $data[] = '';
  3431. }
  3432. }
  3433. $data[] = $userLink;
  3434. $data[] = $userRealName;
  3435. $data[] = $userTariff;
  3436. $data[] = $actLinks;
  3437. $json->addRow($data);
  3438. unset($data);
  3439. }
  3440. }
  3441. }
  3442. //extract json data
  3443. $ajData = $json->extractJson();
  3444. //update cache if required
  3445. if ($this->onuCacheTimeout and !$fromCache) {
  3446. $this->cache->set(self::KEY_ONULISTAJ . $OltId, $ajData, $this->onuCacheTimeout);
  3447. }
  3448. }
  3449. die($ajData);
  3450. }
  3451. /**
  3452. * Renders json formatted data for jquery data tables list
  3453. *
  3454. * @param string $OnuId
  3455. * @return void
  3456. */
  3457. public function ajaxOltFdbData($OnuId) {
  3458. $json = new wf_JqDtHelper();
  3459. $fdbPointer = '';
  3460. if (!empty($OnuId)) {
  3461. $allUserTariffs = zb_TariffsGetAllUsers();
  3462. $onuMacId = @$this->allOnu[$OnuId]['mac'];
  3463. $onuSerialId = @$this->allOnu[$OnuId]['serial'];
  3464. $fdbCacheAvail = $this->oltData->isFdbAvailable();
  3465. if ($fdbCacheAvail) {
  3466. $this->loadFDBCache();
  3467. } else {
  3468. $fdbCacheAvail = false;
  3469. }
  3470. if (isset($this->FDBCache[$onuMacId])) {
  3471. $fdbPointer = $this->FDBCache[$onuMacId];
  3472. }
  3473. if (isset($this->FDBCache[$onuSerialId])) {
  3474. $fdbPointer = $this->FDBCache[$onuSerialId];
  3475. }
  3476. if ($fdbCacheAvail and $fdbPointer) {
  3477. $GetLoginMac = zb_UserGetAllMACs();
  3478. $allAddress = zb_AddressGetFulladdresslistCached();
  3479. $allRealnames = zb_UserGetAllRealnames();
  3480. foreach ($fdbPointer as $id => $FDBdata) {
  3481. $login = in_array($FDBdata['mac'], array_map('strtolower', $GetLoginMac)) ? array_search($FDBdata['mac'], array_map('strtolower', $GetLoginMac)) : '';
  3482. $userLink = $login ? wf_Link('?module=userprofile&username=' . $login, web_profile_icon() . ' ' . @$allAddress[$login], false) : '';
  3483. $userRealnames = $login ? @$allRealnames[$login] : '';
  3484. $userTariff = (isset($allUserTariffs[$login])) ? $allUserTariffs[$login] : '';
  3485. $data[] = $id;
  3486. $data[] = $FDBdata['vlan'];
  3487. $data[] = $FDBdata['mac'];
  3488. $data[] = @$userLink;
  3489. $data[] = @$userRealnames;
  3490. $data[] = $userTariff;
  3491. $json->addRow($data);
  3492. unset($data);
  3493. }
  3494. }
  3495. }
  3496. $json->getJson();
  3497. }
  3498. /**
  3499. * Checks is ONU really associated with some OLT
  3500. *
  3501. * @param string $onuMac
  3502. * @param int $oltId
  3503. * @return bool
  3504. */
  3505. protected function checkOnuOLTid($onuMac, $oltId) {
  3506. $result = true;
  3507. $sn = strtoupper($onuMac);
  3508. if (!empty($this->onuMacOltidList)) {
  3509. if (isset($this->onuMacOltidList[$onuMac])) {
  3510. if ($this->onuMacOltidList[$onuMac] != $oltId) {
  3511. $result = false;
  3512. }
  3513. }
  3514. }
  3515. if (!empty($this->onuSerialOltidList)) {
  3516. if (isset($this->onuSerialOltidList[$sn])) {
  3517. if ($this->onuSerialOltidList[$sn] != $oltId) {
  3518. $result = false;
  3519. }
  3520. }
  3521. }
  3522. return ($result);
  3523. }
  3524. /**
  3525. * Checks is ONU associated with some login or not
  3526. *
  3527. * @param int $onuId
  3528. * @param string $userLogin
  3529. *
  3530. * @return bool
  3531. */
  3532. protected function checkOnuUserAssign($onuId, $userLogin) {
  3533. $result = true;
  3534. if (@$this->altCfg['PON_USERLINK_CHECK']) {
  3535. //ONU is registered
  3536. if ($onuId != 0) {
  3537. @$associatedUserLogin = $this->allOnu[$onuId]['login'];
  3538. } else {
  3539. $associatedUserLogin = '';
  3540. }
  3541. if (!empty($associatedUserLogin)) {
  3542. if ($userLogin != $associatedUserLogin) {
  3543. $result = false;
  3544. } else {
  3545. $result = true;
  3546. }
  3547. }
  3548. //something strange
  3549. if ($result == false) {
  3550. $onuExtUsers = $this->getOnuExtUsers($onuId);
  3551. if (!empty($onuExtUsers)) {
  3552. foreach ($onuExtUsers as $io => $each) {
  3553. if ($each['login'] == $userLogin) {
  3554. $result = true;
  3555. }
  3556. }
  3557. }
  3558. }
  3559. }
  3560. return ($result);
  3561. }
  3562. /**
  3563. * Renders json for current all OLT FDB list
  3564. *
  3565. * @return void
  3566. */
  3567. public function ajaxFdbCacheList() {
  3568. $json = new wf_JqDtHelper();
  3569. $availOnuFdbCache = $this->oltData->isFdbAvailable();
  3570. if (!empty($availOnuFdbCache)) {
  3571. $availOnuFdbCache = $this->oltData->getFdbOLTAll();
  3572. $allAddress = zb_AddressGetFulladdresslistCached();
  3573. $allRealnames = zb_UserGetAllRealnames();
  3574. $allUserMac = zb_UserGetAllMACs();
  3575. $allUserMac = array_map('strtolower', $allUserMac);
  3576. $allUserMac = array_flip($allUserMac);
  3577. $allUserTariffs = zb_TariffsGetAllUsers();
  3578. foreach ($availOnuFdbCache as $oltId => $eachOltFdb) {
  3579. $oltDesc = @$this->allOltDevices[$oltId];
  3580. if (!empty($eachOltFdb)) {
  3581. foreach ($eachOltFdb as $onuMac => $onuTmp) {
  3582. if (!empty($onuTmp)) {
  3583. foreach ($onuTmp as $id => $onuData) {
  3584. $onuRealId = $this->getOnuIDbyIdent($onuMac);
  3585. if ($onuRealId) {
  3586. $associatedUserLogin = $this->allOnu[$onuRealId]['login'];
  3587. } else {
  3588. $associatedUserLogin = '';
  3589. }
  3590. $userLogin = (isset($allUserMac[$onuData['mac']])) ? $allUserMac[$onuData['mac']] : '';
  3591. $onuLink = ($onuRealId) ? wf_Link(self::URL_ME . '&editonu=' . $onuRealId, $id) : $id;
  3592. @$userAddress = $allAddress[$userLogin];
  3593. @$userRealName = $allRealnames[$userLogin];
  3594. @$userTariff = $allUserTariffs[$userLogin];
  3595. $userLink = (!empty($userLogin)) ? wf_Link('?module=userprofile&username=' . $userLogin, web_profile_icon() . ' ' . $userAddress) : '';
  3596. $oltCheck = (!$this->checkOnuOLTid($onuMac, $oltId)) ? ' ' . wf_img('skins/createtask.gif', __('Wrong OLT')) . ' ' . __('Oh no') : '';
  3597. $userCheck = (!$this->checkOnuUserAssign($onuRealId, $userLogin)) ? ' ' . wf_img('skins/createtask.gif', __('Wrong associated user')) . ' ' . __('Oh no') : '';
  3598. $data[] = $oltDesc . $oltCheck;
  3599. $data[] = $onuMac;
  3600. $data[] = $onuLink;
  3601. $data[] = $onuData['vlan'];
  3602. $data[] = $onuData['mac'] . $userCheck;
  3603. $data[] = $userLink;
  3604. $data[] = $associatedUserLogin;
  3605. $data[] = $userRealName;
  3606. $data[] = $userTariff;
  3607. $json->addRow($data);
  3608. unset($data);
  3609. }
  3610. }
  3611. }
  3612. }
  3613. }
  3614. }
  3615. $json->getJson();
  3616. }
  3617. /**
  3618. * Automatically fixes ONU to OLT associations due the actual FDB cache data
  3619. *
  3620. * @return void
  3621. */
  3622. public function fixOnuOltAssigns() {
  3623. $result = '';
  3624. $result = wf_BackLink(self::URL_ME . '&fdbcachelist=true');
  3625. $failedOnuFound = false;
  3626. $repairConfirmed = (ubRouting::checkGet('autorepairconfirmed')) ? true : false;
  3627. $totalCount = 0;
  3628. $availOnuSigCache = $this->oltData->getSignalsOLTAll();
  3629. if (!empty($availOnuSigCache)) {
  3630. foreach ($availOnuSigCache as $oltId => $eachOltSignals) {
  3631. $oltDesc = @$this->allOltDevices[$oltId];
  3632. if (!empty($eachOltSignals)) {
  3633. foreach ($eachOltSignals as $onuMac => $onuSignal) {
  3634. $onuRealId = $this->getOnuIDbyIdent($onuMac);
  3635. $onuLink = ($onuRealId) ? wf_Link(self::URL_ME . '&editonu=' . $onuRealId, $onuRealId) : '';
  3636. if ($onuRealId) {
  3637. $wrongOltFlag = (!$this->checkOnuOLTid($onuMac, $oltId)) ? true : false;
  3638. if ($wrongOltFlag) {
  3639. $totalCount++;
  3640. $failedOnuFound = true; //set once
  3641. $onuData = $this->allOnu[$onuRealId];
  3642. $wrongOltId = $onuData['oltid'];
  3643. $wrongOltDesc = @$this->allOltDevices[$wrongOltId];
  3644. if (empty($wrongOltDesc)) {
  3645. $wrongOltDesc = '[' . $wrongOltId . '] ' . __('Unknown');
  3646. }
  3647. $missmatchLabel = __('ONU') . ' [ ' . $onuLink . '] ' . __('wrong') . ' ' . __('OLT') . ' ' . $wrongOltDesc . ', ';
  3648. $missmatchLabel .= __('must be') . ' ' . $oltDesc;
  3649. $result .= $this->messages->getStyledMessage($missmatchLabel, 'warning');
  3650. if ($repairConfirmed) {
  3651. if (isset($this->allOltDevices[$oltId])) {
  3652. if (isset($this->allOnu[$onuRealId])) {
  3653. $this->onuDb->where('id', '=', $onuRealId);
  3654. $this->onuDb->data('oltid', $oltId);
  3655. $this->onuDb->save();
  3656. log_register('PON REMAP ONU [' . $onuRealId . '] MAC `' . $onuData['mac'] . '` OLT [' . $wrongOltId . '] TO [' . $oltId . ']');
  3657. $repairLabel = __('ONU') . ' [ ' . $onuLink . '] ' . __('assigned') . ' ' . __('OLT') . ' ' . $oltDesc . '!';
  3658. $result .= $this->messages->getStyledMessage($repairLabel, 'success');
  3659. } else {
  3660. $result .= $this->messages->getStyledMessage(__('ONU') . ' [' . $onuRealId . '] ' . __('Not exists'), 'error');
  3661. }
  3662. } else {
  3663. $result .= $this->messages->getStyledMessage(__('OLT') . ' [' . $oltId . '] ' . __('Not exists'), 'error');
  3664. }
  3665. }
  3666. }
  3667. }
  3668. }
  3669. }
  3670. }
  3671. } else {
  3672. $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'warning');
  3673. }
  3674. if ($failedOnuFound) {
  3675. //totals rendering
  3676. $result .= $this->messages->getStyledMessage(__('Total') . ' ' . __('ONU') . ' ' . __('wrong') . ': ' . $totalCount, 'info');
  3677. $result .= wf_delimiter();
  3678. $repairConfirmUrl = self::URL_ME . '&fdbcachelist=true&fixonuoltassings=true&autorepairconfirmed=true';
  3679. $result .= wf_JSAlert($repairConfirmUrl, wf_img('skins/icon_repair.gif') . ' ' . __('Fix') . '?', $this->messages->getEditAlert(), '', 'ubButton');
  3680. } else {
  3681. $result .= $this->messages->getStyledMessage(__('Everything is Ok'), 'success');
  3682. }
  3683. return ($result);
  3684. }
  3685. /**
  3686. * Returns ONU create and assign form for user profile module
  3687. *
  3688. * @param $userLogin
  3689. * @param $allUserData
  3690. *
  3691. * @return string
  3692. */
  3693. public function renderCpeUserControls($userLogin, $allUserData) {
  3694. $result = '';
  3695. $userHasCPE = false;
  3696. // if there is no assigned ONU with $userLogin yet
  3697. $userHasCPE = $this->getOnuIdByUser($userLogin);
  3698. if (empty($userHasCPE)) {
  3699. $LnkID = wf_InputId();
  3700. $userIP = $allUserData[$userLogin]['ip'];
  3701. $userMAC = $allUserData[$userLogin]['mac'];
  3702. $result .= wf_tag('br') . wf_tag('b') . __('Users PON equipment') . wf_tag('b', true) . wf_tag('br');
  3703. $result .= wf_Link(self::URL_ME . '&unknownonulist=true', wf_img('skins/icon_link.gif') . ' ' . __('Assign PON equipment to user'), false, 'ubButton') . '&nbsp';
  3704. $result .= wf_modalAutoForm(__('Create new CPE'), '', 'dialog-modal_' . $LnkID, 'body_dialog-modal_' . $LnkID);
  3705. $result .= wf_tag('a', false, 'ubButton', 'id="' . $LnkID . '" href="#"');
  3706. $result .= web_icon_create() . ' ' . __('Create new CPE');
  3707. $result .= wf_tag('a', true);
  3708. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  3709. $result .= wf_JSElemInsertedCatcherFunc();
  3710. $result .= wf_JSEmptyFunc();
  3711. $result .= '
  3712. function checkONUAssignment() {
  3713. if ( typeof( $(\'input[name=newmac]\').val() ) === "string" && $(\'input[name=newmac]\').val().length > 0 ) {
  3714. $.ajax({
  3715. type: "GET",
  3716. url: "?module=ponizer",
  3717. data: {action:\'checkONUAssignment\', onumac:$(\'input[name=newmac]\').val()},
  3718. success: function(result) {
  3719. $(\'#onuassignment2\').text(result);
  3720. }
  3721. });
  3722. } else {$(\'#onuassignment2\').text(\'\');}
  3723. }
  3724. function dynamicBindClick(ctrlClassName) {
  3725. $(document).on("click", ctrlClassName, function(evt) {
  3726. evt.preventDefault();
  3727. checkONUAssignment($(ctrlClassName).val());
  3728. return false;
  3729. });
  3730. }
  3731. onElementInserted(\'body\', \'.__CheckONUAssignmentBtn\', function(element) {
  3732. dynamicBindClick(\'.__CheckONUAssignmentBtn\');
  3733. });
  3734. $(\'#' . $LnkID . '\').click(function(evt) {
  3735. $.ajax({
  3736. type: "GET",
  3737. url: "' . self::URL_ME . '",
  3738. data: {
  3739. renderCreateForm:true,
  3740. renderedOutside:true,
  3741. reloadPageAfterDone:true,
  3742. userLogin:"' . $userLogin . '",
  3743. onumac:"' . $userMAC . '",
  3744. userIP:"' . $userIP . '",
  3745. oltid:"",
  3746. ActionCtrlID:"' . $LnkID . '",
  3747. ModalWID:"dialog-modal_' . $LnkID . '"
  3748. },
  3749. success: function(result) {
  3750. $(\'#body_dialog-modal_' . $LnkID . '\').html(result);
  3751. $(\'#dialog-modal_' . $LnkID . '\').dialog("open");
  3752. }
  3753. });
  3754. evt.preventDefault();
  3755. return false;
  3756. });
  3757. ';
  3758. $result .= wf_tag('script', true);
  3759. $result .= wf_delimiter();
  3760. }
  3761. return ($result);
  3762. }
  3763. /**
  3764. * Returns array like: $userLogin => $onuSignal
  3765. *
  3766. * @return array
  3767. */
  3768. public static function getAllONUSignals() {
  3769. global $ubillingConfig;
  3770. $result = array();
  3771. $oltData = new OLTAttractor();
  3772. $signalCache = $oltData->getSignalsAll();
  3773. $onuMACValidateRegex = '/^([[:xdigit:]]{2}[\s:.-]?){5}[[:xdigit:]]{2}$/';
  3774. $validateONUMACEnabled = $ubillingConfig->getAlterParam('PON_ONU_MAC_VALIDATE');
  3775. //not using $this->onuDb here, because static method call possible
  3776. $onuDb = new NyanORM(self::TABLE_ONUS);
  3777. $onuDb->whereRaw("`login` != '' and NOT ISNULL(`login`)");
  3778. $allOnuRecs = $onuDb->getAll();
  3779. if (!empty($allOnuRecs) and !empty($signalCache)) {
  3780. //Preprocess MACs if enabled.
  3781. //Not using reviewDataSet here, because static method call possible
  3782. if ($validateONUMACEnabled) {
  3783. foreach ($signalCache as $mac => $signal) {
  3784. if ($validateONUMACEnabled) {
  3785. $matches = array();
  3786. preg_match($onuMACValidateRegex, $mac, $matches);
  3787. if (empty($matches[0])) {
  3788. unset($signalCache[$mac]);
  3789. }
  3790. }
  3791. }
  3792. }
  3793. foreach ($allOnuRecs as $io => $each) {
  3794. if (isset($signalCache[$each['mac']])) {
  3795. $result[$each['login']] = $signalCache[$each['mac']];
  3796. }
  3797. if (isset($signalCache[$each['serial']])) {
  3798. $result[$each['login']] = $signalCache[$each['serial']];
  3799. }
  3800. }
  3801. }
  3802. return ($result);
  3803. }
  3804. /**
  3805. * Return all of last dereg reasons as userLogin=>deregReason[raw/styled]
  3806. *
  3807. * @return array
  3808. */
  3809. public function getAllONUDeregReasons() {
  3810. global $ubillingConfig;
  3811. $result = array();
  3812. $onuMACValidateRegex = '/^([[:xdigit:]]{2}[\s:.-]?){5}[[:xdigit:]]{2}$/';
  3813. $validateONUMACEnabled = $ubillingConfig->getAlterParam('PON_ONU_MAC_VALIDATE');
  3814. $oltData = new OLTAttractor();
  3815. $deregsCache = $oltData->getDeregsAll();
  3816. $onuDb = new NyanORM(self::TABLE_ONUS);
  3817. $onuDb->whereRaw("`login` != '' and NOT ISNULL(`login`)");
  3818. $allOnuRecs = $onuDb->getAll();
  3819. if (!empty($allOnuRecs) and !empty($deregsCache)) {
  3820. //Preprocess MACs if enabled.
  3821. if ($validateONUMACEnabled) {
  3822. foreach ($deregsCache as $mac => $dereg) {
  3823. if ($validateONUMACEnabled) {
  3824. $matches = array();
  3825. preg_match($onuMACValidateRegex, $mac, $matches);
  3826. if (empty($matches[0])) {
  3827. unset($deregsCache[$mac]);
  3828. }
  3829. }
  3830. }
  3831. }
  3832. foreach ($allOnuRecs as $io => $each) {
  3833. if (isset($deregsCache[$each['mac']])) {
  3834. $result[$each['login']]['raw'] = strip_tags($deregsCache[$each['mac']]);
  3835. $result[$each['login']]['styled'] = $deregsCache[$each['mac']];
  3836. }
  3837. if (isset($deregsCache[$each['serial']])) {
  3838. $result[$each['login']]['raw'] = strip_tags($deregsCache[$each['serial']]);
  3839. $result[$each['login']]['styled'] = $deregsCache[$each['serial']];
  3840. }
  3841. }
  3842. }
  3843. return ($result);
  3844. }
  3845. /**
  3846. * Just generates random MAC address to replace invalid ONU MAC
  3847. *
  3848. * @return string
  3849. */
  3850. protected function getRandomMac() {
  3851. $result = $result = 'ff:' . '00' . ':' . rand(10, 99) . ':' . rand(10, 99) . ':' . rand(10, 99) . ':' . '00';
  3852. return ($result);
  3853. }
  3854. /**
  3855. * Validate ONUs MAC against regex and return bool value
  3856. *
  3857. * @param $onuMAC
  3858. *
  3859. * @return bool
  3860. */
  3861. public function validateONUMAC($onuMAC) {
  3862. $matches = array();
  3863. preg_match($this->onuMACValidateRegex, $onuMAC, $matches);
  3864. return (!empty($matches[0]));
  3865. }
  3866. /**
  3867. * Returns validated MAC or replaces it with random one
  3868. *
  3869. * @param string $mac
  3870. *
  3871. * @return string
  3872. */
  3873. protected function validatedMac($mac) {
  3874. if ($this->validateONUMACEnabled and !$this->validateONUMAC($mac)) {
  3875. if ($this->replaceInvalidONUMACWithRandom) {
  3876. $mac = $this->getRandomMac();
  3877. }
  3878. }
  3879. return ($mac);
  3880. }
  3881. /**
  3882. * Performs validation of some data set if required as onuMac=>someValue
  3883. *
  3884. * @param array $dataSet
  3885. *
  3886. * @return array
  3887. */
  3888. protected function reviewDataSet($dataSet) {
  3889. $result = array();
  3890. if ($this->validateONUMACEnabled) {
  3891. if (!empty($dataSet)) {
  3892. foreach ($dataSet as $onuIdent => $someValue) {
  3893. $result[$this->validatedMac($onuIdent)] = $someValue;
  3894. }
  3895. }
  3896. } else {
  3897. return ($dataSet);
  3898. }
  3899. return ($result);
  3900. }
  3901. /**
  3902. * Renders ONU search form
  3903. *
  3904. * @return string
  3905. */
  3906. public function renderOnuSearchForm() {
  3907. $result = '';
  3908. if (!empty($this->allOnu)) {
  3909. $inputs = '';
  3910. $searchQueryPreset = (ubRouting::checkPost('onusearchquery')) ? ubRouting::post('onusearchquery', 'mres') : '';
  3911. $inputs .= wf_TextInput('onusearchquery', '', $searchQueryPreset, true, 40) . ' ';
  3912. $inputs .= __('Search by') . ':' . wf_delimiter(0);
  3913. if (ubRouting::checkPost('onusearchquery')) {
  3914. //saving checkbox state between queries
  3915. $macChecked = (ubRouting::checkPost('searchmac')) ? true : false;
  3916. $loginChecked = (ubRouting::checkPost('searchlogin')) ? true : false;
  3917. $serialChecked = (ubRouting::checkPost('searchserial')) ? true : false;
  3918. $ipChecked = (ubRouting::checkPost('searchip')) ? true : false;
  3919. $idChecked = (ubRouting::checkPost('searchonuid')) ? true : false;
  3920. } else {
  3921. //default checkbox state
  3922. $macChecked = true;
  3923. $loginChecked = true;
  3924. $serialChecked = true;
  3925. $ipChecked = true;
  3926. $idChecked = true;
  3927. }
  3928. $inputs .= wf_CheckInput('searchmac', __('MAC'), true, $macChecked);
  3929. $inputs .= wf_CheckInput('searchlogin', __('Login'), true, $loginChecked);
  3930. $inputs .= wf_CheckInput('searchserial', __('Serial number'), true, $serialChecked);
  3931. $inputs .= wf_CheckInput('searchip', __('IP'), true, $ipChecked);
  3932. $inputs .= wf_CheckInput('searchonuid', __('ONU') . ' ' . __('ID'), true, $idChecked);
  3933. $inputs .= wf_delimiter(0);
  3934. $inputs .= wf_Submit(__('Search'));
  3935. $result .= wf_Form(self::URL_ME . '&onusearch=true', 'POST', $inputs, 'glamour');
  3936. } else {
  3937. $result .= $this->messages->getStyledMessage(__('Nothing found'), 'warning', 'style="width:300px;"');
  3938. }
  3939. return ($result);
  3940. }
  3941. /**
  3942. * Catches ONU search request and renders some result
  3943. *
  3944. * @return string
  3945. */
  3946. public function renderOnuSearchResult() {
  3947. $result = '';
  3948. $resultTmp = array();
  3949. $messages = new UbillingMessageHelper();
  3950. if (!empty($this->allOnu)) {
  3951. $searchQuery = ubRouting::post('onusearchquery', 'mres');
  3952. if (!empty($searchQuery)) {
  3953. //search fields flags
  3954. $macChecked = (ubRouting::checkPost('searchmac')) ? true : false;
  3955. $loginChecked = (ubRouting::checkPost('searchlogin')) ? true : false;
  3956. $serialChecked = (ubRouting::checkPost('searchserial')) ? true : false;
  3957. $ipChecked = (ubRouting::checkPost('searchip')) ? true : false;
  3958. $idChecked = (ubRouting::checkPost('searchonuid')) ? true : false;
  3959. //processing some search
  3960. foreach ($this->allOnu as $eachOnuId => $eachOnuData) {
  3961. if ($macChecked) {
  3962. $rawMac = str_replace(array(':', '.', '-'), '', $eachOnuData['mac']);
  3963. $macSearchQuery = str_replace(array(':', '.', '-'), '', $searchQuery);
  3964. if (ispos($eachOnuData['mac'], $searchQuery) or ispos($rawMac, $macSearchQuery)) {
  3965. $resultTmp[$eachOnuId] = $eachOnuData;
  3966. }
  3967. }
  3968. if ($loginChecked) {
  3969. if (ispos($eachOnuData['login'], $searchQuery)) {
  3970. $resultTmp[$eachOnuId] = $eachOnuData;
  3971. }
  3972. }
  3973. if ($serialChecked) {
  3974. if (ispos($eachOnuData['serial'], $searchQuery)) {
  3975. $resultTmp[$eachOnuId] = $eachOnuData;
  3976. }
  3977. }
  3978. if ($ipChecked) {
  3979. if (ispos($eachOnuData['ip'], $searchQuery)) {
  3980. $resultTmp[$eachOnuId] = $eachOnuData;
  3981. }
  3982. }
  3983. if ($idChecked) {
  3984. if ($eachOnuData['id'] === $searchQuery) {
  3985. $resultTmp[$eachOnuId] = $eachOnuData;
  3986. }
  3987. }
  3988. }
  3989. //something found
  3990. if (!empty($resultTmp)) {
  3991. $result .= $this->renderOnuArray($resultTmp);
  3992. } else {
  3993. $result .= $messages->getStyledMessage(__('Nothing found'), 'warning');
  3994. }
  3995. }
  3996. } else {
  3997. $result .= $messages->getStyledMessage(__('Nothing to show'), 'error');
  3998. }
  3999. return ($result);
  4000. }
  4001. /**
  4002. * Renders ONU Array just as table list with some controls
  4003. *
  4004. * @param array $onuArray
  4005. *
  4006. * @return string
  4007. */
  4008. protected function renderOnuArray($onuArray) {
  4009. $result = '';
  4010. if (!empty($onuArray)) {
  4011. $count = 0;
  4012. $cells = wf_TableCell(__('ID'));
  4013. $cells .= wf_TableCell(__('OLT'));
  4014. $cells .= wf_TableCell(__('Model'));
  4015. if ($this->ipColumnVisible) {
  4016. $cells .= wf_TableCell(__('IP'));
  4017. }
  4018. $cells .= wf_TableCell(__('Serial number'));
  4019. $cells .= wf_TableCell(__('MAC'));
  4020. $cells .= wf_TableCell(__('User'));
  4021. $cells .= wf_TableCell(__('Actions'));
  4022. $rows = wf_TableRow($cells, 'row1');
  4023. foreach ($onuArray as $eachOnuId => $eachOnuData) {
  4024. $cells = wf_TableCell($eachOnuId);
  4025. $cells .= wf_TableCell(@$this->allOltNames[$eachOnuData['oltid']]);
  4026. $cells .= wf_TableCell(@$this->allModelsData[$eachOnuData['onumodelid']]['modelname']);
  4027. if ($this->ipColumnVisible) {
  4028. $cells .= wf_TableCell($eachOnuData['ip']);
  4029. }
  4030. $cells .= wf_TableCell($eachOnuData['serial']);
  4031. $cells .= wf_TableCell($eachOnuData['mac']);
  4032. if (!empty($eachOnuData['login'])) {
  4033. $userLink = wf_Link(self::URL_USERPROFILE . $eachOnuData['login'], web_profile_icon() . ' ' . $eachOnuData['login']);
  4034. } else {
  4035. $userLink = '';
  4036. }
  4037. $cells .= wf_TableCell($userLink);
  4038. $actControls = wf_Link(self::URL_ME . '&editonu=' . $eachOnuId, web_edit_icon(__('Edit') . ' ' . __('ONU')));
  4039. $cells .= wf_TableCell($actControls);
  4040. $rows .= wf_TableRow($cells, 'row5');
  4041. $count++;
  4042. }
  4043. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  4044. $result .= wf_tag('b') . __('Total') . ': ' . $count . wf_tag('b', true);
  4045. }
  4046. return ($result);
  4047. }
  4048. /**
  4049. * Tries to return the current "realtime" ONU signal value
  4050. *
  4051. * @param $oltID
  4052. * @param $onumac
  4053. *
  4054. * @return float|int|string
  4055. */
  4056. public function getONURealtimeSignal($oltID, $onumac, $getTxSgnal = false) {
  4057. $signal = '';
  4058. $oltID = vf($oltID, 3);
  4059. if (isset($this->allOltDevices[$oltID]) and isset($this->allOltSnmp[$oltID])) {
  4060. $oltCommunity = $this->allOltSnmp[$oltID]['community'];
  4061. $oltModelId = $this->allOltSnmp[$oltID]['modelid'];
  4062. $oltIp = $this->allOltSnmp[$oltID]['ip'];
  4063. $cacheMACDevID = array();
  4064. if (
  4065. isset($this->snmpTemplates[$oltModelId])
  4066. and isset($this->snmpTemplates[$oltModelId]['signal'])
  4067. and isset($this->snmpTemplates[$oltModelId]['misc'])
  4068. and file_exists(self::MACDEVIDCACHE_PATH . $oltID . '_' . self::MACDEVIDCACHE_EXT)
  4069. ) {
  4070. $cacheMACDevID = file_get_contents(self::MACDEVIDCACHE_PATH . $oltID . '_' . self::MACDEVIDCACHE_EXT);
  4071. $cacheMACDevID = unserialize($cacheMACDevID);
  4072. if (!empty($cacheMACDevID[$onumac])) {
  4073. $snmpSignalOIDs = $this->snmpTemplates[$oltModelId]['signal'];
  4074. $snmpMiscOIDs = $this->snmpTemplates[$oltModelId]['misc'];
  4075. $onuDevID = $cacheMACDevID[$onumac];
  4076. if ($snmpSignalOIDs['SIGNALMODE'] == 'VSOL') {
  4077. $sigOIDPart = ($getTxSgnal) ? '.6.' : '.7.';
  4078. $sigIndexOID = $snmpSignalOIDs['SIGINDEX'] . $sigOIDPart . $onuDevID;
  4079. $sigIndexVal = $snmpSignalOIDs['SIGVALUE'];
  4080. } else {
  4081. if (
  4082. $getTxSgnal
  4083. and isset($snmpMiscOIDs['ONUTXSIGNAL'])
  4084. and isset($snmpMiscOIDs['ONUTXSIGNALVAL'])
  4085. ) {
  4086. $sigIndexOID = $snmpMiscOIDs['ONUTXSIGNAL'] . '.' . $onuDevID;
  4087. $sigIndexVal = $snmpMiscOIDs['ONUTXSIGNALVAL'];
  4088. } else {
  4089. $sigIndexOID = $snmpSignalOIDs['SIGINDEX'] . '.' . $onuDevID;
  4090. $sigIndexVal = $snmpSignalOIDs['SIGVALUE'];
  4091. }
  4092. }
  4093. $sigIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $sigIndexOID, self::SNMPCACHE);
  4094. $sigIndex = str_replace($sigIndexOID . '.', '', $sigIndex);
  4095. $sigIndex = str_replace($sigIndexVal, '', $sigIndex);
  4096. if (!empty($sigIndex)) {
  4097. if ($snmpSignalOIDs['SIGNALMODE'] == 'BDCOM') {
  4098. $line = explode('=', $sigIndex);
  4099. //signal is present
  4100. if (isset($line[1])) {
  4101. $signal = trim($line[1]); // signal level
  4102. if (empty($signal) or !is_numeric($signal) or $signal == $snmpSignalOIDs['DOWNVALUE']) {
  4103. $signal = 'Offline';
  4104. } else {
  4105. if ($snmpSignalOIDs['OFFSETMODE'] == 'div') {
  4106. if ($snmpSignalOIDs['OFFSET']) {
  4107. $signal = $signal / $snmpSignalOIDs['OFFSET'];
  4108. }
  4109. }
  4110. }
  4111. }
  4112. }
  4113. if ($snmpSignalOIDs['SIGNALMODE'] == 'STELSFD') {
  4114. $line = explode('=', $sigIndex);
  4115. //signal is present
  4116. if (isset($line[1])) {
  4117. $signal = trim($line[1]); // signal level
  4118. if (empty($signal) or !is_numeric($signal) or $signal == $snmpSignalOIDs['DOWNVALUE']) {
  4119. $signal = 'Offline';
  4120. } else {
  4121. if ($snmpSignalOIDs['OFFSETMODE'] == 'logm') {
  4122. if ($snmpSignalOIDs['OFFSET']) {
  4123. $signal = round(10 * log10($signal) - $snmpSignalOIDs['OFFSET'], 2);
  4124. }
  4125. }
  4126. }
  4127. }
  4128. }
  4129. if ($snmpSignalOIDs['SIGNALMODE'] == 'VSOL') {
  4130. $signal = trim(substr(stristr(stristr(stristr($sigIndex, '('), ')', true), 'dBm', true), 1));
  4131. }
  4132. }
  4133. }
  4134. }
  4135. }
  4136. return ($signal);
  4137. }
  4138. /**
  4139. * Tries to return some of the extended "realtime" ONU info, like Tx signal, last reg/dereg time, alive time
  4140. *
  4141. * @param $oltID
  4142. * @param $onumac
  4143. *
  4144. * @return array
  4145. */
  4146. public function getONUExtenInfo($oltID, $onumac) {
  4147. $result = array();
  4148. $oltID = vf($oltID, 3);
  4149. if (isset($this->allOltDevices[$oltID]) and isset($this->allOltSnmp[$oltID])) {
  4150. $oltCommunity = $this->allOltSnmp[$oltID]['community'];
  4151. $oltModelId = $this->allOltSnmp[$oltID]['modelid'];
  4152. $oltIp = $this->allOltSnmp[$oltID]['ip'];
  4153. $cacheMACDevID = array();
  4154. if (
  4155. isset($this->snmpTemplates[$oltModelId])
  4156. and isset($this->snmpTemplates[$oltModelId]['signal'])
  4157. and isset($this->snmpTemplates[$oltModelId]['misc'])
  4158. and file_exists(self::MACDEVIDCACHE_PATH . $oltID . '_' . self::MACDEVIDCACHE_EXT)
  4159. ) {
  4160. if ($this->snmpTemplates[$oltModelId]['signal']['SIGNALMODE'] == 'STELSFD') {
  4161. return ($result);
  4162. }
  4163. $cacheMACDevID = file_get_contents(self::MACDEVIDCACHE_PATH . $oltID . '_' . self::MACDEVIDCACHE_EXT);
  4164. $cacheMACDevID = unserialize($cacheMACDevID);
  4165. if (!empty($cacheMACDevID[$onumac])) {
  4166. $snmpDevice = $this->snmpTemplates[$oltModelId]['define']['DEVICE'];
  4167. $snmpSignalOIDs = $this->snmpTemplates[$oltModelId]['signal'];
  4168. $snmpMiscOIDs = $this->snmpTemplates[$oltModelId]['misc'];
  4169. $onuDevID = $cacheMACDevID[$onumac];
  4170. $onuIdxDevID = '';
  4171. $lastRegTime = '';
  4172. $lastDeregTime = '';
  4173. $lastAliveTime = '';
  4174. if (ispos($snmpDevice, 'OLT P36')) {
  4175. $onuIdx = file_get_contents(self::ONUCACHE_PATH . $oltID . '_' . self::ONUCACHE_EXT);
  4176. if (!empty($onuIdx)) {
  4177. $onuIdx = array_flip(unserialize($onuIdx));
  4178. if (!empty($onuIdx[$onumac])) {
  4179. $onuIdxDevID = $onuIdx[$onumac];
  4180. }
  4181. }
  4182. }
  4183. if (!empty($snmpMiscOIDs['LASTREGTIME'])) {
  4184. if (ispos($snmpDevice, 'OLT P36')) {
  4185. $lastRegTimeOID = $snmpMiscOIDs['LASTREGTIME'] . '.' . $onuIdxDevID;
  4186. } else {
  4187. $lastRegTimeOID = $snmpMiscOIDs['LASTREGTIME'] . '.' . $onuDevID;
  4188. }
  4189. $lastRegTimeVal = $snmpMiscOIDs['LASTREGTIMEVAL'];
  4190. $lastRegTime = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $lastRegTimeOID, self::SNMPCACHE);
  4191. $lastRegTime = trimSNMPOutput($lastRegTime, $lastRegTimeOID);
  4192. $lastRegTime = (empty($lastRegTime[1]) ? '' : $lastRegTime[1]);
  4193. }
  4194. if (!empty($snmpMiscOIDs['LASTDEREGTIME'])) {
  4195. if (ispos($snmpDevice, 'OLT P36')) {
  4196. $lastDeregTimeOID = $snmpMiscOIDs['LASTDEREGTIME'] . '.' . $onuIdxDevID;
  4197. } else {
  4198. $lastDeregTimeOID = $snmpMiscOIDs['LASTDEREGTIME'] . '.' . $onuDevID;
  4199. }
  4200. $lastDeregTimeVal = $snmpMiscOIDs['LASTDEREGTIMEVAL'];
  4201. $lastDeregTime = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $lastDeregTimeOID, self::SNMPCACHE);
  4202. $lastDeregTime = trimSNMPOutput($lastDeregTime, $lastDeregTimeOID);
  4203. $lastDeregTime = empty($lastDeregTime[1]) ? '' : $lastDeregTime[1];
  4204. }
  4205. if (!empty($snmpMiscOIDs['LASTALIVETIME'])) {
  4206. $lastAliveTimeOID = $snmpMiscOIDs['LASTALIVETIME'] . '.' . $onuDevID;
  4207. $lastAliveTimeVal = $snmpMiscOIDs['LASTALIVETIMEVAL'];
  4208. $lastAliveTime = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $lastAliveTimeOID, self::SNMPCACHE);
  4209. $lastAliveTime = trimSNMPOutput($lastAliveTime, $lastAliveTimeOID);
  4210. $lastAliveTime = empty($lastAliveTime[1]) ? '' : $lastAliveTime[1];
  4211. }
  4212. if (!empty($lastRegTime) or !empty($lastDeregTime) or !empty($lastAliveTime)) {
  4213. if ($snmpSignalOIDs['SIGNALMODE'] == 'BDCOM' or ispos($snmpDevice, 'FD12XXS') or ispos($snmpDevice, 'FD16XXS')) {
  4214. $lastAliveTime = (empty($lastAliveTime) or !is_numeric($lastAliveTime)) ? 0 : $lastAliveTime;
  4215. $lastAliveTime = zb_formatTime($lastAliveTime);
  4216. $lastRegTime = $this->convertBDCOMTime($lastRegTime);
  4217. $lastDeregTime = $this->convertBDCOMTime($lastDeregTime);
  4218. }
  4219. $result['lastreg'] = trim(trim($lastRegTime), '"');
  4220. $result['lastdereg'] = trim(trim($lastDeregTime), '"');
  4221. $result['lastalive'] = trim(trim($lastAliveTime), '"');
  4222. }
  4223. }
  4224. }
  4225. }
  4226. return ($result);
  4227. }
  4228. /**
  4229. * Tries to return the current "realtime" OLT uptime value
  4230. *
  4231. * @param $oltID
  4232. * @param bool $fromCache
  4233. *
  4234. * @return bool|string
  4235. */
  4236. public function getOLTUptime($oltID, $fromCache = true) {
  4237. $oltUptime = '';
  4238. if ($fromCache and file_exists(self::UPTIME_PATH . $oltID . '_' . self::UPTIME_EXT)) {
  4239. $oltUptime = file_get_contents(self::UPTIME_PATH . $oltID . '_' . self::UPTIME_EXT);
  4240. } else {
  4241. $oltID = vf($oltID, 3);
  4242. if (isset($this->allOltDevices[$oltID]) and isset($this->allOltSnmp[$oltID])) {
  4243. $oltCommunity = $this->allOltSnmp[$oltID]['community'];
  4244. $oltModelId = $this->allOltSnmp[$oltID]['modelid'];
  4245. $oltIp = $this->allOltSnmp[$oltID]['ip'];
  4246. if (isset($this->snmpTemplates[$oltModelId]['system'])) {
  4247. //OLT uptime
  4248. if (isset($this->snmpTemplates[$oltModelId]['system']['UPTIME'])) {
  4249. $uptimeIndexOid = $this->snmpTemplates[$oltModelId]['system']['UPTIME'];
  4250. $oltUptime = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $uptimeIndexOid, self::SNMPCACHE);
  4251. if (!empty($oltUptime)) {
  4252. $oltUptime = explode(')', $oltUptime);
  4253. $oltUptime = $oltUptime[1];
  4254. $oltUptime = trim($oltUptime);
  4255. }
  4256. }
  4257. }
  4258. }
  4259. }
  4260. return ($oltUptime);
  4261. }
  4262. /**
  4263. * Tries to make BDCOM Reg/Dereg dates human readable
  4264. *
  4265. * @param $hexOIDVal
  4266. *
  4267. * @return string
  4268. */
  4269. public function convertBDCOMTime($hexOIDVal) {
  4270. $result = '';
  4271. if (!empty($hexOIDVal)) {
  4272. $hexOIDVal = substr(str_replace(' ', '', $hexOIDVal), 0, 14);
  4273. $bdcomYear = hexdec(substr($hexOIDVal, 0, 4));
  4274. $bdcomMonth = hexdec(substr($hexOIDVal, 4, 2));
  4275. $bdcomMonth = (strlen($bdcomMonth) < 2) ? '0' . $bdcomMonth : $bdcomMonth;
  4276. $bdcomDay = hexdec(substr($hexOIDVal, 6, 2));
  4277. $bdcomDay = (strlen($bdcomDay) < 2) ? '0' . $bdcomDay : $bdcomDay;
  4278. $bdcomHour = hexdec(substr($hexOIDVal, 8, 2));
  4279. $bdcomHour = (strlen($bdcomHour) < 2) ? '0' . $bdcomHour : $bdcomHour;
  4280. $bdcomMin = hexdec(substr($hexOIDVal, 10, 2));
  4281. $bdcomMin = (strlen($bdcomMin) < 2) ? '0' . $bdcomMin : $bdcomMin;
  4282. $bdcomSec = hexdec(substr($hexOIDVal, 12, 2));
  4283. $bdcomSec = (strlen($bdcomSec) < 2) ? '0' . $bdcomSec : $bdcomSec;
  4284. $result = $bdcomYear . '.' . $bdcomMonth . '.' . $bdcomDay . ' ' . $bdcomHour . ':' . $bdcomMin . ':' . $bdcomSec;
  4285. }
  4286. return ($result);
  4287. }
  4288. /**
  4289. * Performs reply on ONU assigment check
  4290. */
  4291. public function checkONUAssignmentReply() {
  4292. $tString = '';
  4293. $tStatus = 0;
  4294. $tLogin = '';
  4295. $oltData = '';
  4296. $onuMAC = ubRouting::get('onumac');
  4297. $ONUAssignment = $this->checkONUAssignment($this->getOnuIDbyIdent($onuMAC), true, true);
  4298. $tStatus = $ONUAssignment['status'];
  4299. $tLogin = $ONUAssignment['login'];
  4300. $oltData = $ONUAssignment['oltdata'];
  4301. switch ($tStatus) {
  4302. case 0:
  4303. $tString = __('ONU is not assigned');
  4304. break;
  4305. case 1:
  4306. $tString = __('ONU is already assigned, but such login is not exists anymore') . '. ' . __('Login') . ': ' . $tLogin . '. OLT: ' . $oltData;
  4307. break;
  4308. case 2:
  4309. $tString = __('ONU is already assigned') . '. ' . __('Login') . ': ' . $tLogin . '. OLT: ' . $oltData;
  4310. break;
  4311. }
  4312. die($tString);
  4313. }
  4314. /**
  4315. * Returns filtered array of unknown ONUs as mac/serial=>oltId
  4316. *
  4317. * @return array
  4318. */
  4319. protected function getOnuUnknownAll() {
  4320. $result = array();
  4321. $this->fillONUIndexCache();
  4322. if (!empty($this->onuIndexCache)) {
  4323. foreach ($this->onuIndexCache as $onuMac => $oltId) {
  4324. //ONU not registered yet?
  4325. if ($this->checkOnuUnique($onuMac)) {
  4326. if (!isset($this->hideOnuMac[$onuMac])) {
  4327. if (!ispos($onuMac, 'no:such')) {
  4328. $result[$onuMac] = $oltId;
  4329. }
  4330. }
  4331. }
  4332. }
  4333. }
  4334. return ($result);
  4335. }
  4336. /**
  4337. * Renders batch unknown ONU registration list
  4338. *
  4339. * @return string
  4340. */
  4341. public function renderBatchOnuRegList() {
  4342. $result = '';
  4343. $allUnknownOnus = $this->getOnuUnknownAll();
  4344. if (!empty($allUnknownOnus)) {
  4345. $onuLabel = __('Oh you are a lazy ass') . '... ' . sizeof($allUnknownOnus) . ' ' . __('Unknown ONU') . '!';
  4346. $result .= $this->messages->getStyledMessage($onuLabel, 'info');
  4347. foreach ($allUnknownOnus as $eachOnuIdent => $eachOnuOltId) {
  4348. if (check_mac_format($eachOnuIdent)) {
  4349. //valid MAC?
  4350. $identLabel = __('ONU') . ' ' . __('MAC');
  4351. } else {
  4352. //looks like serial
  4353. $identLabel = __('ONU') . ' ' . __('Serial');
  4354. }
  4355. $onuLabel = $identLabel . ' ' . $eachOnuIdent . ' ' . __('on') . ' ' . __('OLT') . ' ' . @$this->allOltDevices[$eachOnuOltId];
  4356. $result .= $this->messages->getStyledMessage($onuLabel, 'warning');
  4357. }
  4358. } else {
  4359. $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'success');
  4360. }
  4361. return ($result);
  4362. }
  4363. /**
  4364. * Renders batch unknown ONU registration form
  4365. *
  4366. * @return string
  4367. */
  4368. public function renderBatchOnuRegForm() {
  4369. $result = '';
  4370. $models = array();
  4371. $allUnknownOnus = $this->getOnuUnknownAll();
  4372. if (!empty($allUnknownOnus)) {
  4373. if (!empty($this->allModelsData)) {
  4374. foreach ($this->allModelsData as $io => $each) {
  4375. if (@$this->altCfg['ONUMODELS_FILTER']) {
  4376. if (ispos($each['modelname'], 'ONU')) {
  4377. $models[$each['id']] = $each['modelname'];
  4378. }
  4379. } else {
  4380. $models[$each['id']] = $each['modelname'];
  4381. }
  4382. }
  4383. }
  4384. if (!empty($models)) {
  4385. $inputs = wf_HiddenInput('runmassonureg', 'true');
  4386. $inputs .= wf_Selector('massonuregonumodelid', $models, __('ONU model') . $this->sup, '', true);
  4387. $inputs .= wf_delimiter(0);
  4388. $confirmLabel = __('I also understand well that no one will correct my mistakes for me and only I bear full financial responsibility for my mistakes');
  4389. $inputs .= wf_CheckInput('massonuregconfirmation', $confirmLabel, true, false);
  4390. $inputs .= wf_delimiter(0);
  4391. $inputs .= wf_Submit(__('Register all unknown ONUs'));
  4392. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  4393. } else {
  4394. $result .= $this->messages->getStyledMessage(__('Any available ONU models exist'), 'error');
  4395. }
  4396. } else {
  4397. $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'success');
  4398. }
  4399. return ($result);
  4400. }
  4401. /**
  4402. * Performs batch unknown ONUs registration
  4403. *
  4404. * @param string $customBackLink
  4405. *
  4406. * @return string
  4407. */
  4408. public function runBatchOnuRegister($customBackLink = '') {
  4409. set_time_limit(0);
  4410. $result = '';
  4411. $onuList = '';
  4412. if ($customBackLink) {
  4413. $result .= wf_BackLink($customBackLink);
  4414. } else {
  4415. $result .= wf_BackLink('?module=ponizer&onumassreg=true');
  4416. }
  4417. $result .= wf_delimiter(0);
  4418. $errorCount = 0;
  4419. $succCount = 0;
  4420. if (ubRouting::checkPost('massonuregconfirmation')) {
  4421. if (ubRouting::checkPost('massonuregonumodelid')) {
  4422. $newOnusModelId = ubRouting::post('massonuregonumodelid', 'int');
  4423. if (!empty($newOnusModelId) and isset($this->allModelsData)) {
  4424. $allUnknownOnus = $this->getOnuUnknownAll();
  4425. if (!empty($allUnknownOnus)) {
  4426. $onuLabel = __('Oh you are a lazy ass') . '... ' . sizeof($allUnknownOnus) . ' ' . __('Unknown ONU') . '!';
  4427. $onuList .= $this->messages->getStyledMessage($onuLabel, 'warning');
  4428. foreach ($allUnknownOnus as $eachOnuIdent => $eachOnuOltId) {
  4429. $oltLabel = ' [' . $eachOnuOltId . '] ' . $this->allOltDevices[$eachOnuOltId];
  4430. $onuLabel = __('Registering') . ' ' . __('MAC') . '/' . __('Serial') . ' ' . $eachOnuIdent . ' ' . __('on') . ' ' . __('OLT') . ' ' . $oltLabel;
  4431. $onuList .= $this->messages->getStyledMessage($onuLabel, 'info');
  4432. if (isset($this->allOltDevices[$eachOnuOltId])) {
  4433. if ($this->checkOnuUnique($eachOnuIdent)) {
  4434. if (check_mac_format($eachOnuIdent)) {
  4435. //looks like normal MAC
  4436. $newOnuMac = $eachOnuIdent;
  4437. $newOnuSerial = '';
  4438. } else {
  4439. //seems its GPON device serial
  4440. $newOnuMac = zb_MacGetRandom();
  4441. $newOnuSerial = $eachOnuIdent;
  4442. }
  4443. $newOnuId = $this->onuCreate($newOnusModelId, $eachOnuOltId, '', $newOnuMac, $newOnuSerial, '');
  4444. if ($newOnuId) {
  4445. $oltLabel = ' [' . $eachOnuOltId . '] ' . $this->allOltDevices[$eachOnuOltId] . '. ';
  4446. $onuLabel = __('Registered') . ' ' . __('MAC') . ' ' . __('or') . ' ' . __('Serial') . ' ' . $eachOnuIdent . ' ' . __('ONU') . ' [' . $newOnuId . '] ' . __('on') . ' ' . __('OLT') . ' ' . $oltLabel;
  4447. $onuLabel .= __('Success') . '!';
  4448. $onuList .= $this->messages->getStyledMessage($onuLabel, 'success');
  4449. $succCount++;
  4450. } else {
  4451. $errorCount++;
  4452. $onuList .= $this->messages->getStyledMessage(__('Registering') . ' ' . __('Failed') . ' "' . $eachOnuIdent . '" ', 'error');
  4453. }
  4454. } else {
  4455. $errorCount++;
  4456. $onuList .= $this->messages->getStyledMessage(__('MAC duplicate') . ' ' . $eachOnuIdent . ' ', 'error');
  4457. }
  4458. } else {
  4459. $errorCount++;
  4460. $result .= $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('OLT') . ' [' . $eachOnuOltId . '] ' . __('Not exists'), 'error');
  4461. }
  4462. }
  4463. } else {
  4464. $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'success');
  4465. }
  4466. } else {
  4467. $result .= $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('ONU model') . ' ' . __('Not exists'), 'error');
  4468. }
  4469. } else {
  4470. $result .= $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('No') . ' ' . __('ONU model'), 'error');
  4471. }
  4472. } else {
  4473. $result .= $this->messages->getStyledMessage(__('You are not mentally prepared for this'), 'error');
  4474. }
  4475. //some summary here
  4476. if ($succCount > 0) {
  4477. $result .= $this->messages->getStyledMessage(__('Registered') . ': ' . $succCount, 'success');
  4478. }
  4479. if ($errorCount > 0) {
  4480. $result .= $this->messages->getStyledMessage(__('Error') . ': ' . $errorCount, 'error');
  4481. }
  4482. $result .= $onuList;
  4483. return ($result);
  4484. }
  4485. }