12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988 |
- <?php
- /**
- * PON devices management and monitoring implementation
- */
- class PONizer {
- /**
- * All available ONU devices as id=>onudata
- *
- * @var array
- */
- protected $allOnu = array();
- /**
- * List for mac = id
- *
- * @var array
- */
- protected $onuMacIdList = array();
- /**
- * List for serial = id
- *
- * @var type
- */
- protected $onuSerialIdList = array();
- /**
- * List for mac = oltid
- *
- * @var array
- */
- protected $onuMacOltidList = array();
- /**
- * List for serial = oltid
- *
- * @var array
- */
- protected $onuSerialOltidList = array();
- /**
- * Contains array of additional ONU users as id=>binddata
- *
- * @var array
- */
- protected $allOnuExtUsers = array();
- /**
- * OLT models data as id=>model data array
- *
- * @var array
- */
- protected $allModelsData = array();
- /**
- * All available OLT devices as id=>ip - location
- *
- * @var array
- */
- protected $allOltDevices = array();
- /**
- * All available OLT devices locations as id=>location
- *
- * @var array
- */
- protected $allOltNames = array();
- /**
- * Contains all OLT devices id=>modelId mappings
- *
- * @var array
- */
- protected $allOltModelIds = array();
- /**
- * OLT devices snmp data as id=>snmp data array
- *
- * @var array
- */
- protected $allOltSnmp = array();
- /**
- * OLT devices IPs as id=>ip
- *
- * @var array
- */
- protected $allOltIps = array();
- /**
- * Available OLT models as id=>modelname + snmptemplate + ports
- *
- * @var array
- */
- protected $allOltModels = array();
- /**
- * Contains available SNMP templates for OLT modelids as modelId=>snmpTemplateData
- *
- * @var array
- */
- protected $snmpTemplates = array();
- /**
- * Contains current ONU signal cache data as mac=>signal
- *
- * @var array
- */
- protected $signalCache = array();
- /**
- * Contains current ONU signal cache data as mac=>distance
- *
- * @var array
- */
- protected $distanceCache = array();
- /**
- * Contains current ONU last dereg reasons cache data as mac=>last dereg reason
- *
- * @var array
- */
- protected $lastDeregCache = array();
- /**
- * Contains ONU indexes cache as mac=>oltid
- *
- * @var array
- */
- protected $onuIndexCache = array();
- /**
- * Contains ONU indexes cache as mac=>interface
- *
- * @var array
- */
- protected $interfaceCache = array();
- /**
- * Contains FDB indexes cache as id=>mac
- *
- * @var array
- */
- protected $FDBCache = array();
- /**
- * Contains ONU devices indexes cache as mac => devID
- *
- * @var array
- */
- protected $onuMACDevIDCache = array();
- /**
- * Contains ONU UNI ports cache as MAC/Serial => (EtherPort => Status)
- *
- * @var array
- */
- protected $uniOperStatsCache = array();
- /**
- * System alter.ini config stored as key=>value
- *
- * @var array
- */
- protected $altCfg = array();
- /**
- * SNMPHelper object instance
- *
- * @var array
- */
- protected $snmp = '';
- /**
- * Prepared HTML for asterisk determining mandatory form field
- *
- * @var string
- */
- protected $sup = '';
- /**
- * Are QuickOLTLinks enabled?
- *
- * @var bool
- */
- protected $EnableQuickOLTLinks = false;
- /**
- * Are OLTs polled individually via AJAX?
- *
- * @var bool
- */
- protected $OLTIndividualRepollAJAX = false;
- /**
- * Is PON signal history charts spoiler initially closed?
- *
- * @var bool
- */
- protected $ONUChartsSpoilerClosed = false;
- /**
- * Is user search by MAC for unknown ONU registering form enabled?
- *
- * @var bool
- */
- protected $onuUknownUserByMACSearchShow = false;
- /**
- * Increment for user search by MAC telepathy for unknown ONU registering form
- *
- * @var string
- */
- protected $onuUknownUserByMACSearchIncrement = 0;
- /**
- * Is user search by MAC for unknown ONU registering form enabled mandatory?
- *
- * @var bool
- */
- protected $onuUknownUserByMACSearchShowAlways = false;
- /**
- * Is user search by MAC telepathy for unknown ONU registering form enabled?
- *
- * @var bool
- */
- protected $onuUknownUserByMACSearchTelepathy = false;
- /**
- * Is tab UI for ponizer active?
- *
- * @var bool
- */
- protected $ponizerUseTabUI = false;
- /**
- * Placeholder for onu MAC validation regex
- *
- * @var string
- */
- protected $onuMACValidateRegex = '/^([[:xdigit:]]{2}[\s:.-]?){5}[[:xdigit:]]{2}$/';
- /**
- * Perform ONU MAC validation against $onuMACValidateRegex?
- *
- * @var bool
- */
- protected $validateONUMACEnabled = false;
- /**
- * Replace ONU's MAC if invalid with a random one?
- *
- * @var string
- */
- protected $replaceInvalidONUMACWithRandom = false;
- /**
- * Show PON interfaces descriptions in main ONU list tab if present?
- *
- * @var bool
- */
- protected $showPONIfaceDescrMainTab = false;
- /**
- * Show PON interfaces descriptions in OLT stats tab if present?
- *
- * @var bool
- */
- protected $showPONIfaceDescrStatsTab = false;
- /**
- * Contains OLT PON interfaces description as $oltID => array($cleanIfaceName => $ifaceDescr)
- *
- * @var array
- */
- protected $ponIfaceDescrCache = array();
- /**
- * Placeholder for UbillingConfig object
- *
- * @var null
- */
- protected $ubConfig = null;
- /**
- * Array of MAC address of ONU devices which will be hidden from unknown ONU list
- *
- * @var array
- */
- protected $hideOnuMac = array();
- /**
- * OLT intefaces manual descriptions flag
- *
- * @var bool
- */
- protected $ponIfDescribe = false;
- /**
- * Deferred loading flag
- *
- * @var boolt
- */
- protected $deferredLoadingFlag = false;
- /**
- * Placeholder for PON_ONU_OFFLINE_SIGNAL alter.ini option
- *
- * @var string
- */
- protected $onuOfflineSignalLevel = '-9000';
- /**
- * PON interfaces object placeholder
- *
- * @var object
- */
- public $ponInterfaces = '';
- /**
- * IP column rendering flag
- *
- * @var bool
- */
- protected $ipColumnVisible = true;
- /**
- * Placeholder for PON_UKNKOWN_ONU_LLID_SHOW alter.ini option
- *
- * @var bool
- */
- protected $llidColVisibleUnknownONU = false;
- /**
- * Placeholder for PON_ONU_UNI_STATUS_ENABLED alter.ini option
- *
- * @var bool
- */
- protected $onuUniStatusEnabled = false;
- /**
- * Placeholder for PON_ONU_SERIAL_CASE_MODE alter.ini option
- * 0 - no case convert
- * 1 - lowercase
- * 2 - uppercase
- *
- * @var bool
- */
- protected $onuSerialCaseMode = 0;
- /**
- * Contains all busy ONU MAC/serials as lowercase onuIdent=>onuId
- *
- * @var array
- */
- protected $existingOnuIdents = array();
- /**
- * System message helper object placeholder
- *
- * @var object
- */
- protected $messages = '';
- /**
- * System caching object placeholder
- *
- * @var object
- */
- protected $cache = '';
- /**
- * Onu data caching timeout
- *
- * @var int
- */
- protected $onuCacheTimeout = 0;
- /**
- * Contains instance of OltAttractor
- *
- * @var object
- */
- protected $oltData = '';
- /**
- * Quiet mode flag
- *
- * @var bool
- */
- protected $supressOutput = false;
- /**
- * ONUs database abstraction layer
- *
- * @var object
- */
- protected $onuDb = '';
- /**
- * ONUs database abstraction layer
- *
- * @var object
- */
- protected $onuExtUsersDb = '';
- /**
- * Contains process manager instance
- *
- * @var object
- */
- protected $stardust = '';
- /**
- * Some predefined paths, marks etc.
- * This is here for legacy purpoces for external modules.
- */
- const SIGCACHE_PATH = OLTAttractor::SIGCACHE_PATH;
- const SIGCACHE_EXT = OLTAttractor::SIGCACHE_EXT;
- const DISTCACHE_PATH = OLTAttractor::DISTCACHE_PATH;
- const DISTCACHE_EXT = OLTAttractor::DISTCACHE_EXT;
- const ONUCACHE_PATH = OLTAttractor::ONUCACHE_PATH;
- const ONUCACHE_EXT = OLTAttractor::ONUCACHE_EXT;
- const INTCACHE_PATH = OLTAttractor::INTCACHE_PATH;
- const INTCACHE_EXT = OLTAttractor::INTCACHE_EXT;
- const INTDESCRCACHE_EXT = OLTAttractor::INTDESCRCACHE_EXT;
- const FDBCACHE_PATH = OLTAttractor::FDBCACHE_PATH;
- const FDBCACHE_EXT = OLTAttractor::FDBCACHE_EXT;
- const DEREGCACHE_PATH = OLTAttractor::DEREGCACHE_PATH;
- const DEREGCACHE_EXT = OLTAttractor::DEREGCACHE_EXT;
- const UPTIME_PATH = OLTAttractor::UPTIME_PATH;
- const UPTIME_EXT = OLTAttractor::UPTIME_EXT;
- const TEMPERATURE_PATH = OLTAttractor::TEMPERATURE_PATH;
- const TEMPERATURE_EXT = OLTAttractor::TEMPERATURE_EXT;
- const MACDEVIDCACHE_PATH = OLTAttractor::MACDEVIDCACHE_PATH;
- const MACDEVIDCACHE_EXT = OLTAttractor::MACDEVIDCACHE_EXT;
- const ONUSIG_PATH = OLTAttractor::ONUSIG_PATH;
- const POLL_PID = 'OLTPOLL_';
- const POLL_STATS = 'exports/pondata/races/PONYRUN_';
- const POLL_LOG = 'exports/oltpoll.log';
- /**
- * Other predefined constants
- */
- const SNMPCACHE = false;
- const SNMPPORT = 161;
- const TABLE_ONUS = 'pononu';
- const TABLE_SWITCHES = 'switches';
- const TABLE_ONUEXTUSERS = 'pononuextusers';
- const KEY_ALLONU = 'ALLONU';
- const KEY_ONUOLT = 'ONUOLTID_';
- const KEY_ONULISTAJ = 'ONULISTAJ_';
- const SNMP_TEMPLATES_PATH = 'config/snmptemplates/';
- const SNMP_PRIVATE_TEMPLATES_PATH = 'documents/mysnmptemplates/';
- /**
- * Some URLs here
- */
- const URL_ME = '?module=ponizer';
- const URL_ONULIST = '?module=ponizer&onulist=true';
- const URL_USERPROFILE = '?module=userprofile&username=';
- const URL_ONU = '?module=ponizer&editonu=';
- /**
- * Views/stats coloring
- */
- const COLOR_OK = '#005502';
- const COLOR_AVG = '#FF5500';
- const COLOR_BAD = '#AB0000';
- const COLOR_NOSIG = '#000000';
- const NO_SIGNAL = 'Offline';
- const POLL_RUNNING = '🏁';
- /**
- * Creates new PONizer object instance
- *
- * @param int $oltId load ONU data only for selected OLT. Loads all if empty.
- *
- * @return void
- */
- public function __construct($oltId = '') {
- global $ubillingConfig;
- $this->ubConfig = $ubillingConfig;
- $this->loadAlter();
- $this->initMessages();
- $this->initStarDust();
- $this->initOltAttractor();
- $this->initOnuDb();
- $this->initOnuExtUsersDb();
- $this->initCache();
- $this->loadOltDevices();
- $this->loadOltModels();
- $this->loadSnmpTemplates();
- $this->initSNMP();
- $this->loadOnu($oltId);
- $this->loadOnuExtUsers();
- $this->loadModels();
- $this->sup = wf_tag('sup') . '*' . wf_tag('sup', true);
- $this->EnableQuickOLTLinks = $this->ubConfig->getAlterParam('PON_QUICK_OLT_LINKS');
- $this->OLTIndividualRepollAJAX = $this->ubConfig->getAlterParam('PON_OLT_INDIVIDUAL_REPOLL_AJAX');
- $this->ONUChartsSpoilerClosed = $this->ubConfig->getAlterParam('PON_ONU_CHARTS_SPOILER_CLOSED');
- $this->onuUknownUserByMACSearchShow = $this->ubConfig->getAlterParam('PON_UONU_USER_BY_MAC_SEARCH_SHOW');
- $this->onuUknownUserByMACSearchIncrement = ($this->ubConfig->getAlterParam('PON_UONU_USER_BY_MAC_SEARCH_INCREMENT')) ? $this->ubConfig->getAlterParam('PON_UONU_USER_BY_MAC_SEARCH_INCREMENT') : 0;
- $this->onuUknownUserByMACSearchShowAlways = $this->ubConfig->getAlterParam('PON_UONU_USER_BY_MAC_SEARCH_SHOW_ALWAYS');
- $this->onuUknownUserByMACSearchTelepathy = $this->ubConfig->getAlterParam('PON_UONU_USER_BY_MAC_SEARCH_TELEPATHY');
- $this->ponizerUseTabUI = $this->ubConfig->getAlterParam('PON_UI_USE_TABS');
- $this->validateONUMACEnabled = $this->ubConfig->getAlterParam('PON_ONU_MAC_VALIDATE');
- $this->replaceInvalidONUMACWithRandom = $this->ubConfig->getAlterParam('PON_ONU_MAC_MAKE_RANDOM_IF_INVALID');
- $this->showPONIfaceDescrMainTab = $this->ubConfig->getAlterParam('PON_IFACE_DESCRIPTION_IN_MAINTAB');
- $this->showPONIfaceDescrStatsTab = $this->ubConfig->getAlterParam('PON_IFACE_DESCRIPTION_IN_STATSTAB');
- $this->ponIfDescribe = $this->ubConfig->getAlterParam('PON_IFDESC');
- $this->onuOfflineSignalLevel = $this->ubConfig->getAlterParam('PON_ONU_OFFLINE_SIGNAL', $this->onuOfflineSignalLevel);
- $this->deferredLoadingFlag = $this->ubConfig->getAlterParam('PON_DEFERRED_LOADING', false);
- $this->ipColumnVisible = ($this->ubConfig->getAlterParam('PONIZER_NO_IP_COLUMN')) ? false : true;
- $this->llidColVisibleUnknownONU = $this->ubConfig->getAlterParam('PON_UKNKOWN_ONU_LLID_SHOW', false);
- $this->onuUniStatusEnabled = $this->ubConfig->getAlterParam('PON_ONU_UNI_STATUS_ENABLED', false);
- $this->onuSerialCaseMode = $this->ubConfig->getAlterParam('PON_ONU_SERIAL_CASE_MODE', 0);
- if ($this->ponIfDescribe) {
- $this->ponInterfaces = new PONIfDesc();
- }
- //optional ONU MAC hiding
- if (@$this->altCfg['PON_ONU_HIDE']) {
- $tmpHideOnuList = explode(',', $this->altCfg['PON_ONU_HIDE']);
- $tmpHideOnuList = array_flip($tmpHideOnuList);
- $this->hideOnuMac = $tmpHideOnuList;
- }
- }
- /**
- * Loads system alter.ini config into private data property
- *
- * @return void
- */
- protected function loadAlter() {
- $this->altCfg = $this->ubConfig->getAlter();
- }
- /**
- * Inits system messages helper for further usage
- *
- * @return void
- */
- protected function initMessages() {
- $this->messages = new UbillingMessageHelper();
- }
- /**
- * Inits anonymous OLT attractor instance for further usage
- *
- * @return void
- */
- protected function initOltAttractor() {
- $this->oltData = new OLTAttractor();
- }
- /**
- * Inits ONUs database abstraction layer
- *
- * @return void
- */
- protected function initOnuDb() {
- $this->onuDb = new NyanORM(self::TABLE_ONUS);
- }
- /**
- * Inits ONUs additional users database abstraction layer
- *
- * @return void
- */
- protected function initOnuExtUsersDb() {
- $this->onuExtUsersDb = new NyanORM(self::TABLE_ONUEXTUSERS);
- }
- /**
- * Inits process manager
- *
- * @return void
- */
- protected function initStarDust() {
- $this->stardust = new StarDust();
- }
- /**
- * Loads all available devices set as OLT
- *
- * @return void
- */
- protected function loadOltDevices() {
- $switchesDb = new NyanORM(self::TABLE_SWITCHES);
- $requiredFields = array('`id`', '`ip`', '`location`', '`snmp`', '`modelid`', '`desc`');
- $switchesDb->selectable($requiredFields);
- $switchesDb->where('desc', 'LIKE', '%OLT%');
- //custom field sorting?
- $oltLoadOrderField = $this->ubConfig->getAlterParam('PON_OLT_ORDER');
- if (!empty($oltLoadOrderField)) {
- //is fileld valid?
- if (array_search('`' . $oltLoadOrderField . '`', $requiredFields) !== false) {
- $switchesDb->orderBy($oltLoadOrderField, 'ASC');
- } else {
- show_error(__('Wrong value') . ' PON_OLT_ORDER: ' . '"' . $oltLoadOrderField . '"');
- }
- }
- $raw = $switchesDb->getAll();
- if (!empty($raw)) {
- foreach ($raw as $io => $each) {
- //OLT must have non empty community
- if (!empty($each['snmp'])) {
- $this->allOltDevices[$each['id']] = $each['ip'] . ' - ' . $each['location'];
- $this->allOltNames[$each['id']] = $each['location'];
- $this->allOltModelIds[$each['id']] = $each['modelid'];
- $this->allOltIps[$each['id']] = $each['ip'];
- $this->allOltSnmp[$each['id']]['community'] = $each['snmp'];
- $this->allOltSnmp[$each['id']]['modelid'] = $each['modelid'];
- $this->allOltSnmp[$each['id']]['ip'] = $each['ip'];
- $this->allOltSnmp[$each['id']]['nofdbquery'] = ispos($each['desc'], 'NOFDBQUERY');
- }
- }
- }
- }
- /**
- * Getter for allOltDevices array
- *
- * @return array
- */
- public function getAllOltDevices() {
- return $this->allOltDevices;
- }
- /**
- * Loads all available snmp models data into private data property
- *
- * @return void
- */
- protected function loadOltModels() {
- $rawModels = zb_SwitchModelsGetAll();
- if (!empty($rawModels)) {
- foreach ($rawModels as $io => $each) {
- $this->allOltModels[$each['id']]['modelname'] = $each['modelname'];
- $this->allOltModels[$each['id']]['snmptemplate'] = $each['snmptemplate'];
- $this->allOltModels[$each['id']]['ports'] = $each['ports'];
- }
- }
- }
- /**
- * Performs SNMP templates preprocessing for OLT devices
- *
- * @return void
- */
- protected function loadSnmpTemplates() {
- if (!empty($this->allOltDevices)) {
- foreach ($this->allOltDevices as $oltId => $eachOltData) {
- if (isset($this->allOltSnmp[$oltId])) {
- $oltModelid = $this->allOltSnmp[$oltId]['modelid'];
- if ($oltModelid) {
- if (isset($this->allOltModels[$oltModelid])) {
- $templateFileName = $this->allOltModels[$oltModelid]['snmptemplate'];
- if (!empty($templateFileName)) {
- $basicTemplateFile = self::SNMP_TEMPLATES_PATH . $templateFileName;
- $privateTemplateFile = DATA_PATH . self::SNMP_PRIVATE_TEMPLATES_PATH . $templateFileName;
- //loading basic SNMP template
- if (file_exists($basicTemplateFile)) {
- $this->snmpTemplates[$oltModelid] = rcms_parse_ini_file($basicTemplateFile, true);
- }
- //custom SNMP templates is separated and overrides original templates
- if (file_exists($privateTemplateFile)) {
- $this->snmpTemplates[$oltModelid] = rcms_parse_ini_file($privateTemplateFile, true);
- }
- }
- }
- }
- }
- }
- }
- }
- /**
- * Creates single instance of SNMPHelper object
- *
- * @return void
- */
- protected function initSNMP() {
- $this->snmp = new SNMPHelper();
- }
- /**
- * Inits system caching engine
- *
- * @return void
- */
- protected function initCache() {
- $this->cache = new UbillingCache();
- $this->onuCacheTimeout = $this->ubConfig->getAlterParam('PON_ONU_CACHING', 0);
- if ($this->onuCacheTimeout) {
- $this->onuCacheTimeout = $this->onuCacheTimeout * 60; //in minutes
- }
- }
- /**
- * Try to detect ONU id by assigned users login
- *
- * @param string $login
- * @return int/bool
- */
- public function getOnuIdByUser($login) {
- $result = 0;
- if (!empty($this->allOnu)) {
- foreach ($this->allOnu as $io => $each) {
- if ($each['login'] == $login) {
- $result = $each['id'];
- break;
- }
- }
- if (!empty($this->allOnuExtUsers)) {
- foreach ($this->allOnuExtUsers as $io => $each) {
- if ($each['login'] == $login) {
- $result = $each['onuid'];
- break;
- }
- }
- }
- }
- return ($result);
- }
- /**
- * Trys to detect all ONU IDs by assigned users login as idx=>onuId
- *
- * @param string $login
- *
- * @return array
- */
- public function getOnuIdByUserAll($login) {
- $result = array();
- if (!empty($this->allOnu)) {
- foreach ($this->allOnu as $io => $each) {
- if ($each['login'] == $login) {
- $result[] = $each['id'];
- }
- }
- if (!empty($this->allOnuExtUsers)) {
- foreach ($this->allOnuExtUsers as $io => $each) {
- if ($each['login'] == $login) {
- $result[] = $each['onuid'];
- }
- }
- }
- }
- return ($result);
- }
- /**
- * Returns array of ONUs assigned on some OLT
- *
- * @param string $OltId
- * @return array
- */
- protected function getOnuArrayByOltID($OltId = '') {
- $result = array();
- if (!empty($this->allOnu) and !empty($OltId)) {
- foreach ($this->allOnu as $io => $each) {
- if ($each['oltid'] == $OltId) {
- $result[$io] = $each;
- }
- }
- }
- return ($result);
- }
- /**
- * Performs OLT device polling via PON HAL instance
- *
- * @param int $oltid Existing OLT id to perform polling
- * @param bool $quiet dont output debug info to viewport
- *
- * @return void
- */
- public function pollOltSignal($oltid, $quiet = false) {
- $oltid = ubRouting::filters($oltid, 'int');
- $this->supressOutput = $quiet;
- $this->logPoll($oltid, 'STARTING: polling');
- if (isset($this->allOltDevices[$oltid])) {
- if (isset($this->allOltSnmp[$oltid])) {
- $this->flushOnuAjListCache($oltid);
- $oltCommunity = $this->allOltSnmp[$oltid]['community'];
- $oltModelId = $this->allOltSnmp[$oltid]['modelid'];
- $oltIp = $this->allOltSnmp[$oltid]['ip'];
- $oltNoFDBQ = $this->allOltSnmp[$oltid]['nofdbquery'];
- if (isset($this->snmpTemplates[$oltModelId])) {
- $this->logPoll($oltid, 'Using device SNMP template "' . $this->snmpTemplates[$oltModelId]['define']['DEVICE'] . '"');
- if (isset($this->snmpTemplates[$oltModelId]['signal'])) {
- //logging collector signalmode and collector
- $logTemplate = 'Template mode:"' . $this->snmpTemplates[$oltModelId]['signal']['SIGNALMODE'] . '" ';
- $logTemplate .= 'collector name:"' . @$this->snmpTemplates[$oltModelId]['signal']['COLLECTORNAME'] . '"';
- $this->logPoll($oltid, $logTemplate);
- //preventing simultaneously device polling within different processes
- if (!$this->isPollingLocked($oltid)) {
- //prefilling polling stats
- $pollingStartTime = time();
- $this->pollingStatsUpdate($oltid, $pollingStartTime, 0, false);
- $collector = '';
- $collectorName = '';
- $collectorMethod = 'collect';
- $oltParameters = array(
- 'MODELID' => $oltModelId,
- 'ID' => $oltid,
- 'IP' => $oltIp,
- 'COMMUNITY' => $oltCommunity,
- 'NOFDB' => $oltNoFDBQ,
- 'TYPE' => 'PON'
- );
- switch ($this->snmpTemplates[$oltModelId]['signal']['SIGNALMODE']) {
- /**
- * Switchable OLT devices polling abstraction layer
- */
- case 'HAL':
- //setting collector class name
- $collectorName = $this->snmpTemplates[$oltModelId]['signal']['COLLECTORNAME'];
- //setting optional primary collector method name to call
- if (isset($this->snmpTemplates[$oltModelId]['signal']['COLLECTORMETHOD'])) {
- $collectorMethod = $this->snmpTemplates[$oltModelId]['signal']['COLLECTORMETHOD'];
- }
- break;
- /**
- * Following cases is legacy for old or custom device templates
- * without collector hardware abstraction layer specified explictly
- */
- case 'BDCOM':
- /**
- * BDCOM/Eltex/Extralink devices polling
- */
- $collectorName = 'PONBdcom';
- break;
- case 'GPBDCOM':
- /**
- * BDCOM GP3600
- */
- $collectorName = 'PONBdcomGP';
- break;
- case 'STELS12':
- /**
- * Stels FD12XX devices polling
- */
- $collectorName = 'PONStels12';
- break;
- case 'STELSFD':
- /**
- * Stels FD11XX devices polling
- */
- $collectorName = 'PONStels11';
- break;
- case 'VSOL':
- /**
- * V-Solution 1600D devices polling
- */
- $collectorName = 'PONVsol';
- break;
- /**
- * ZTE-like EPON OLTs polling
- */
- case 'ZTE':
- $collectorName = 'PonZte';
- $collectorMethod = 'pollEpon';
- $oltParameters['TYPE'] = 'EPON';
- break;
- /**
- * ZTE GPON OLTs polling
- */
- case 'ZTE_GPON':
- $collectorName = 'PonZte';
- $collectorMethod = 'pollGpon';
- $oltParameters['TYPE'] = 'GPON';
- break;
- /**
- * Huawei EPON OLTs polling
- */
- case 'HUAWEI_GPON':
- $collectorName = 'PonZte';
- $collectorMethod = 'huaweiPollGpon';
- $oltParameters['TYPE'] = 'GPON';
- break;
- }
- //Run OLT HAL instance for device polling
- if (!empty($collectorName)) {
- if (class_exists($collectorName)) {
- $collector = new $collectorName($oltParameters, $this->snmpTemplates);
- $logCollector = 'Polling prepare using PON HAL collector:"' . $collectorName . '" ';
- $logCollector .= 'with parameters OLT ID: ' . $oltParameters['ID'] . ' IP:' . $oltParameters['IP'];
- $this->logPoll($oltid, $logCollector);
- if (method_exists($collector, 'setOfflineSignal')) {
- $collector->setOfflineSignal($this->onuOfflineSignalLevel);
- }
- if (method_exists($collector, $collectorMethod)) {
- $this->logPoll($oltid, 'RUNNING: PON HAL collector method:' . $collectorName . '->' . $collectorMethod);
- $collector->$collectorMethod();
- $this->logPoll($oltid, 'COMPLETED: PON HAL collector method:' . $collectorName . '->' . $collectorMethod);
- } else {
- $this->logPoll($oltid, 'FAILED run PON HAL collector:' . $collectorName . '->' . $collectorMethod . ' METHOD_NOT_EXISTS');
- }
- } else {
- $this->logPoll($oltid, 'FATAL run PON HAL collector:' . $collectorName . ' EX_HAL_COLLECTOR_NOT_EXISTS');
- }
- } else {
- $this->logPoll($oltid, 'Failed: collector name not defined');
- }
- //finishing OLT polling stats
- $pollingEndTime = time();
- $this->pollingStatsUpdate($oltid, $pollingStartTime, $pollingEndTime, true);
- $this->logPoll($oltid, 'FINISHED: polled successfully');
- } else {
- $this->logPoll($oltid, 'FINISHED: skipped, polling already in progress');
- }
- } else {
- $this->logPoll($oltid, 'Failed polling due signal section is not exists');
- }
- } else {
- $this->logPoll($oltid, 'SKIPPING MODELID:' . $oltModelId . ' NO_SNMP_TEMPLATE_BODY');
- }
- } else {
- $this->logPoll($oltid, 'SKIPPING No snmp data for this OLT');
- }
- } else {
- $this->logPoll($oltid, 'SKIPPING Not in OLT devices list');
- }
- }
- /**
- * Performs available OLT devices polling. Use only in remote API.
- *
- * @param bool $quiet dont output debug data into viewport
- *
- * @return void
- */
- public function oltDevicesPolling($quiet = false) {
- if (!empty($this->allOltDevices)) {
- foreach ($this->allOltDevices as $oltid => $each) {
- if (!$quiet) {
- print('POLLING:' . $oltid . ' ' . $each . PHP_EOL);
- }
- if (@!$this->altCfg['HERD_OF_PONIES']) {
- $this->pollOltSignal($oltid, $quiet);
- } else {
- //starting herd of apocalypse pony here!
- $herdTimeout = 0;
- if ($this->altCfg['HERD_OF_PONIES'] > 1) {
- $herdTimeout = ubRouting::filters($this->altCfg['HERD_OF_PONIES'], 'int');
- }
- $this->stardust->runBackgroundProcess('/bin/ubapi "herd&oltid=' . $oltid . '"', $herdTimeout);
- }
- }
- }
- }
- /**
- * Fast check some OLT for running collector process.
- *
- * @param int $oltId Existing OLT device ID
- *
- * @return bool
- */
- protected function isPollingNow($oltId) {
- $result = false;
- //Не плач, моє серце, не плач,
- //Не муч душу свою картонну!
- $pollingStats = $this->pollingStatsRead($oltId);
- if (!empty($pollingStats)) {
- $result = $pollingStats['finished'] ? false : true;
- }
- return ($result);
- }
- /**
- * Returns polling stats for some OLT
- *
- * @param int $oltId
- *
- * @return array
- */
- protected function pollingStatsRead($oltId) {
- $result = array();
- $statsPath = self::POLL_STATS . $oltId;
- if (file_exists($statsPath)) {
- $resultRaw = file_get_contents($statsPath);
- $result = json_decode($resultRaw, true);
- }
- return ($result);
- }
- /**
- * Updates some OLT polling stats
- *
- * @param int $oltId Existing OLT ID
- * @param int $pollingStartTime polling start timestame
- * @param int $pollingEndTime polling end timestamp
- * @param bool $finished polling finished or not flag
- *
- * @return void
- */
- protected function pollingStatsUpdate($oltId, $pollingStartTime = 0, $pollingEndTime = 0, $finished = false) {
- $oltId = ubRouting::filters($oltId, 'int');
- $statsPath = self::POLL_STATS . $oltId;
- $finishedData = ($finished) ? 1 : 0;
- $dataToSave['start'] = $pollingStartTime;
- $dataToSave['end'] = $pollingEndTime;
- $dataToSave['finished'] = $finishedData;
- $dataToSave = json_encode($dataToSave);
- file_put_contents($statsPath, $dataToSave);
- //collector process locking and releasing of locks here
- if ($finished) {
- //release lock
- $this->stardust->setProcess(self::POLL_PID . $oltId);
- $this->stardust->stop();
- } else {
- //set lock for polling of some OLT
- $this->stardust->setProcess(self::POLL_PID . $oltId);
- $this->stardust->start();
- }
- }
- /**
- * Performs logging of OLT polling
- *
- * @param int $oltId
- * @param string $logData
- *
- * @return void
- */
- public function logPoll($oltId, $logData) {
- $curdate = curdatetime();
- $logData = $curdate . ' | OLT[' . $oltId . '] | ' . $logData . PHP_EOL;
- if (!$this->supressOutput) {
- print($logData); // for manual debug of oltpoll and herd remoteapi calls
- }
- file_put_contents(self::POLL_LOG, $logData, FILE_APPEND);
- }
- /**
- * Performs check of OLT polling lock via DB.
- * Using this only for checks of possibility real collector runs.
- *
- * @param int $oltId
- *
- * @return bool
- */
- protected function isPollingLocked($oltId) {
- $oltId = ubRouting::filters($oltId, 'int');
- $this->stardust->setProcess(self::POLL_PID . $oltId);
- $result = $this->stardust->isRunning();
- return ($result);
- }
- /**
- * Returns some polllog viewer controls
- *
- * @return string
- */
- public function renderLogControls() {
- $result = '';
- $result .= wf_BackLink(self::URL_ME . '&oltstats=true') . ' ';
- $result .= wf_Link(self::URL_ME . '&polllogs=true', wf_img('skins/log_icon_small.png') . ' ' . __('Log'), false, 'ubButton') . '';
- $result .= wf_Link(self::URL_ME . '&polllogs=true&zenlog=true', wf_img('skins/zen.png') . ' ' . __('Zen'), false, 'ubButton') . '';
- return ($result);
- }
- /**
- * Renders last lines from OLT polling log
- *
- * @return string
- */
- public function renderPollingLog() {
- $result = '';
- $renderLimit = 100;
- //$result .= wf_BackLink(self::URL_ME . '&oltstats=true');
- if (file_exists(self::POLL_LOG)) {
- $rawLog = zb_ReadLastLines(self::POLL_LOG, $renderLimit);
- if (!empty($rawLog)) {
- $rawLog = explodeRows($rawLog);
- $rawLog = array_reverse($rawLog);
- if (!empty($rawLog)) {
- $cells = wf_TableCell(__('Date'));
- $cells .= wf_TableCell(__('OLT'));
- $cells .= wf_TableCell(__('Event'));
- $rows = wf_TableRow($cells, 'row1');
- foreach ($rawLog as $io => $eachLine) {
- if (!empty($eachLine)) {
- $eachLine = explode('|', $eachLine);
- //normal format: time|OLT|event
- if (sizeof($eachLine) == 3) {
- $oltId = ubRouting::filters($eachLine[1], 'int');
- $cells = wf_TableCell($eachLine[0]);
- $cells .= wf_TableCell('[' . $oltId . '] ' . @$this->allOltDevices[$oltId]);
- $cells .= wf_TableCell($eachLine[2]);
- $rows .= wf_TableRow($cells, 'row5');
- }
- }
- }
- $result .= wf_TableBody($rows, '100%', 0, 'sortable');
- }
- } else {
- $result .= $this->messages->getStyledMessage(__('Nothing to show') . ': ' . __('Logs') . ' ' . __('is empty'), 'warning');
- }
- } else {
- $result .= $this->messages->getStyledMessage(__('Nothing to show') . ': ' . __('OLT polling log') . ' ' . __('does not exist'), 'warning');
- }
- return ($result);
- }
- /**
- * Renders some ONUs navigation list
- *
- * @param array $onuArr
- * @param string $customOnuUrl
- *
- * @return string
- */
- public function renderOnuNavBar($onuArr, $customOnuUrl = '') {
- $result = '';
- if (!empty($onuArr)) {
- $result .= wf_tag('div');
- foreach ($onuArr as $io => $eachOnuId) {
- if (isset($this->allOnu[$eachOnuId])) {
- $onuData = $this->allOnu[$eachOnuId];
- if ($customOnuUrl) {
- $onuUrl = $customOnuUrl . $eachOnuId;
- } else {
- $onuUrl = self::URL_ONU . $eachOnuId;
- }
- $onuLabel = '';
- if (!empty($onuData['mac'])) {
- $onuLabel .= ' ' . $onuData['mac'];
- }
- if (!empty($onuData['serial'])) {
- $onuLabel .= ' ' . $onuData['serial'];
- }
- $result .= wf_tag('div', false, 'dashtask');
- $result .= wf_Link($onuUrl, wf_img('skins/onudev.png'));
- $result .= wf_delimiter(0);
- $result .= __('ONU') . ' ' . $onuLabel;
- $result .= wf_tag('div', true);
- }
- }
- $result .= wf_tag('div', true);
- $result .= wf_CleanDiv();
- } else {
- $this->messages->getStyledMessage(__('Nothing to show'), 'warning');
- }
- return ($result);
- }
- /**
- * Loads avaliable ONUs from database into private data property
- *
- * @param int $oltId load ONU only for selected OLT
- *
- * @return void
- */
- protected function loadOnu($oltId = '') {
- $oltId = ubRouting::filters($oltId, 'int');
- $fromCache = false;
- if ($this->onuCacheTimeout) {
- //specific OLT ONU data
- if ($oltId) {
- $cachedOnus = $this->cache->get(self::KEY_ONUOLT . $oltId, $this->onuCacheTimeout);
- if (!empty($cachedOnus)) {
- $all = $cachedOnus;
- $fromCache = true;
- }
- } else {
- //all OLTs ONU data
- $cachedOnus = $this->cache->get(self::KEY_ALLONU, $this->onuCacheTimeout);
- if (!empty($cachedOnus)) {
- $all = $cachedOnus;
- $fromCache = true;
- }
- }
- }
- //perform database query if no cached data available
- if (!$fromCache) {
- //optional OLT ID filter
- if ($oltId) {
- $this->onuDb->where('oltid', '=', $oltId);
- }
- $all = $this->onuDb->getAll();
- }
- if (!empty($all)) {
- foreach ($all as $io => $each) {
- $this->allOnu[$each['id']] = $each;
- $this->onuMacIdList[$each['mac']] = $each['id'];
- $this->onuSerialIdList[$each['serial']] = $each['id'];
- $this->onuMacOltidList[$each['mac']] = $each['oltid'];
- $this->onuSerialOltidList[$each['serial']] = $each['oltid'];
- //filling used onuIdents array
- $this->existingOnuIdents[strtolower($each['mac'])] = $each['id'];
- $this->existingOnuIdents[strtolower($each['serial'])] = $each['id'];
- }
- }
- //cache requires update
- if ($this->onuCacheTimeout and !$fromCache) {
- if ($oltId) {
- $this->cache->set(self::KEY_ONUOLT . $oltId, $all, $this->onuCacheTimeout);
- } else {
- //all OLTs ONU data
- $this->cache->set(self::KEY_ALLONU, $all, $this->onuCacheTimeout);
- }
- }
- }
- /**
- * Loads avaliable ONUs additional users bindings from database into private data property
- *
- * @return void
- */
- protected function loadOnuExtUsers() {
- $this->allOnuExtUsers = $this->onuExtUsersDb->getAll('id');
- }
- /**
- * Returns Available OLT devices ONU counts
- *
- * @return string
- */
- public function getOltOnuCounts() {
- $result = array();
- if (!empty($this->allOnu)) {
- foreach ($this->allOnu as $io => $each) {
- if (isset($result[$each['oltid']])) {
- $result[$each['oltid']]++;
- } else {
- $result[$each['oltid']] = 1;
- }
- }
- }
- return ($result);
- }
- /**
- * Returns int for ONU has or has not some of subscribers login assignment
- * May return array with status, login and OLT location and IP
- *
- * 0 - has no assignment
- * 1 - has assignment, but login does not exist
- * 2 - has assignment
- *
- * @param int $onuid
- * @param bool $getLogin
- * @param bool $getOLTData
- *
- * @return int|array
- */
- public function checkONUAssignment($onuid, $getLogin = false, $getOLTData = false) {
- $result = 0;
- $tLogin = '';
- $oltData = '';
- $tArray = array();
- if (isset($this->allOnu[$onuid])) {
- $onuRec = $this->allOnu[$onuid];
- if (!empty($onuRec)) {
- $tLogin = $onuRec['login'];
- if (empty($tLogin)) {
- $result = 1;
- } else {
- $query = "SELECT * from `users` WHERE `login`='" . $tLogin . "'";
- $loginRec = simple_query($query);
- (empty($loginRec)) ? $result = 1 : $result = 2;
- }
- if ($getOLTData and isset($this->allOltDevices[$onuRec['oltid']])) {
- $oltData = $this->allOltDevices[$onuRec['oltid']];
- }
- }
- }
- if ($getLogin or $getOLTData) {
- $tArray['status'] = $result;
- $tArray['login'] = $tLogin;
- $tArray['oltdata'] = $oltData;
- $result = $tArray;
- }
- return ($result);
- }
- /**
- * Getter for loaded ONU devices as id=>onuData
- *
- * @return array
- */
- public function getAllOnu() {
- return ($this->allOnu);
- }
- /**
- * Returns ONU ID by ONU MAC or serial
- *
- * @param string $onuIdent existing ONU MAC or serial
- *
- * @return int/0 - on not found
- */
- public function getOnuIDbyIdent($onuIdent) {
- $result = 0;
- $onuIdent = strtolower($onuIdent);
- $sn = strtoupper($onuIdent);
- if (!empty($this->onuMacIdList)) {
- if (isset($this->onuMacIdList[$onuIdent])) {
- $result = $this->onuMacIdList[$onuIdent];
- }
- }
- if (!empty($this->onuSerialIdList)) {
- if (isset($this->onuSerialIdList[$sn])) {
- $result = $this->onuSerialIdList[$sn];
- }
- }
- return ($result);
- }
- /**
- * Performs search in nethosts for a MAC and a login linked to it
- *
- * @param string $mac
- * @param int $macIncrementWith
- *
- * @return array
- */
- public function getUserByONUMAC($mac, $macIncrementWith = 0, $doSerialize = false) {
- if (!empty($macIncrementWith)) {
- $macAsHex = str_replace(':', '', $mac);
- $macAsHex = dechex(hexdec($macAsHex) + $macIncrementWith);
- $macAsHex = (strlen($macAsHex) < 12) ? str_pad($macAsHex, 12, '0', STR_PAD_LEFT) : $macAsHex;
- $mac = implode(":", str_split($macAsHex, 2));
- }
- $query = "SELECT `users`.`login`, `users`.`ip`, `nethosts`.`mac` FROM `users` RIGHT JOIN `nethosts` USING(ip) WHERE mac = '" . $mac . "'";
- $queryResult = simple_queryall($query);
- if (empty($queryResult)) {
- //$result = array('login' => '', 'ip' => '');
- $result = array();
- } else {
- $result = $queryResult[0];
- }
- $result = ($doSerialize) ? json_encode($result) : $result;
- return ($result);
- }
- /**
- * Loads available device models from database
- *
- * @return void
- */
- protected function loadModels() {
- $tmpModels = zb_SwitchModelsGetAll();
- if (!empty($tmpModels)) {
- foreach ($tmpModels as $io => $each) {
- $this->allModelsData[$each['id']] = $each;
- }
- }
- }
- /**
- * Getter for allModelsData array
- *
- * @return array
- */
- public function getAllModelsData() {
- return $this->allModelsData;
- }
- /**
- * Returns model name by its id
- *
- * @param int $id
- * @return string
- */
- protected function getModelName($id) {
- $result = '';
- if (isset($this->allModelsData[$id])) {
- $result = $this->allModelsData[$id]['modelname'];
- }
- return ($result);
- }
- /**
- * Returns model ports count by its id
- *
- * @param int $id
- *
- * @return string
- */
- protected function getModelPorts($id) {
- $result = '';
- if (isset($this->allModelsData[$id])) {
- $result = $this->allModelsData[$id]['ports'];
- }
- return ($result);
- }
- /**
- * Check ONU MAC address unique or not?
- *
- * @param string $mac
- * @return bool
- */
- public function checkMacUnique($mac) {
- $mac = strtolower($mac);
- $result = true;
- if (!empty($this->allOnu)) {
- foreach ($this->allOnu as $io => $each) {
- if ($each['mac'] == $mac) {
- $result = false;
- break;
- }
- }
- }
- return ($result);
- }
- /**
- * Check ONU MAC address or Serial unique or not?
- *
- * @param string $onuIdent
- *
- * @return bool
- */
- public function checkOnuUnique($onuIdent) {
- $result = true;
- if (!empty($onuIdent)) {
- $onuIdent = strtolower($onuIdent);
- // We are heroes
- // Heroes of the night
- // We are ready to live forevermore
- // Our gods lead us through this fight
- if (isset($this->existingOnuIdents[$onuIdent])) {
- $result = false;
- }
- }
- return ($result);
- }
- /**
- * Flushes all ONU related cache keys
- *
- * @return void
- */
- public function flushOnuCache() {
- if ($this->onuCacheTimeout) {
- $this->cache->delete(self::KEY_ALLONU);
- $allCacheKeys = $this->cache->getAllcache();
- if (!empty($allCacheKeys)) {
- foreach ($allCacheKeys as $io => $eachKey) {
- if (ispos($eachKey, self::KEY_ONULISTAJ) or ispos($eachKey, self::KEY_ONUOLT)) {
- $cleanKey = str_replace(UbillingCache::CACHE_PREFIX, '', $eachKey);
- $this->cache->delete($cleanKey);
- }
- }
- }
- }
- }
- /**
- * Flushes some OLT precached list
- *
- * @param int $oltId
- *
- * @return void
- */
- public function flushOnuAjListCache($oltId) {
- if ($this->onuCacheTimeout) {
- if (!empty($oltId)) {
- $allCacheKeys = $this->cache->getAllcache();
- if (!empty($allCacheKeys)) {
- foreach ($allCacheKeys as $io => $eachKey) {
- if ((UbillingCache::CACHE_PREFIX . self::KEY_ONULISTAJ . $oltId) == $eachKey) {
- $cleanKey = str_replace(UbillingCache::CACHE_PREFIX, '', $eachKey);
- $this->cache->delete($cleanKey);
- }
- }
- }
- }
- }
- }
- /**
- * Creates new ONU in database and returns it Id or 0 if action fails
- *
- * @param int $onumodelid
- * @param int $oltid
- * @param string $ip
- * @param string $mac
- * @param string $serial
- * @param string $login
- *
- * @return int/0 - if something went wrong
- */
- public function onuCreate($onumodelid, $oltid, $ip, $mac, $serial, $login) {
- $macF = strtolower($mac);
- $macF = trim($macF);
- $macF = ubRouting::filters($macF, 'mres');
- $onumodelid = ubRouting::filters($onumodelid, 'int');
- $oltid = ubRouting::filters($oltid, 'int');
- $ip = ubRouting::filters($ip, 'mres');
- $serial = ubRouting::filters($serial, 'mres');
- if ($this->onuSerialCaseMode == 1) {
- $serial = strtolower($serial);
- } elseif ($this->onuSerialCaseMode == 2) {
- $serial = strtoupper($serial);
- }
- $login = trim($login);
- $login = ubRouting::filters($login, 'mres');
- $newId = 0;
- $modelid = @$this->allOltSnmp[$oltid]['modelid'];
- //empty MAC workaround for GPON devices
- if (empty($macF) and !empty($serial)) {
- $macF = zb_MacGetRandom();
- log_register('PON CREATE ONU MAC EMPTY TRY REPLACED WITH `' . $macF . '`');
- }
- if (!empty($macF)) {
- if ($this->checkOnuUnique($macF) and $this->checkOnuUnique($serial)) {
- if (check_mac_format($macF)) {
- $this->onuDb->data('onumodelid', $onumodelid);
- $this->onuDb->data('oltid', $oltid);
- $this->onuDb->data('ip', $ip);
- $this->onuDb->data('mac', $macF);
- $this->onuDb->data('serial', $serial);
- $this->onuDb->data('login', $login);
- $this->onuDb->create();
- $newId = $this->onuDb->getLastId();
- log_register('PON CREATE ONU [' . $newId . '] MAC `' . $macF . '` SERIAL `' . $serial . '`');
- } else {
- log_register('PON CREATE ONU MACINVALID TRY `' . $mac . '`');
- }
- } else {
- log_register('PON CREATE ONU DUPLICATE TRY `' . $macF . '` SERIAL `' . $serial . '`');
- }
- } else {
- log_register('PON CREATE ONU MAC EMPTY TRY');
- }
- $this->flushOnuCache();
- return ($newId);
- }
- /**
- * Saves ONU changes into database
- *
- * @param int $onuId
- * @param int $onumodelid
- * @param int $oltid
- * @param string $ip
- * @param string $mac
- * @param string $serial
- * @param string $login
- *
- * @return void
- */
- public function onuSave($onuId, $onumodelid, $oltid, $ip, $mac, $serial, $login) {
- $macF = strtolower($mac);
- $macF = trim($macF);
- $macF = ubRouting::filters($macF, 'mres');
- $onuId = ubRouting::filters($onuId, 'int');
- $onumodelid = ubRouting::filters($onumodelid, 'int');
- $oltid = ubRouting::filters($oltid, 'int');
- $ip = ubRouting::filters($ip, 'mres');
- $onuId = ubRouting::filters($onuId, 'int');
- $serial = ubRouting::filters($serial, 'mres');
- $login = ubRouting::filters($login, 'mres');
- $login = trim($login);
- $currentMac = $this->allOnu[$onuId]['mac'];
- $currentSerial = $this->allOnu[$onuId]['serial'];
- $currentLogin = $this->allOnu[$onuId]['login'];
- $this->onuDb->where('id', '=', $onuId);
- $this->onuDb->data('onumodelid', $onumodelid);
- $this->onuDb->data('oltid', $oltid);
- $this->onuDb->data('ip', $ip);
- if (!empty($macF)) {
- if (check_mac_format($macF)) {
- if ($currentMac != $macF) {
- if ($this->checkOnuUnique($macF)) {
- $this->onuDb->data('mac', $macF);
- } else {
- log_register('PON MACDUPLICATE TRY `' . $mac . '`');
- }
- }
- } else {
- log_register('PON MACINVALID TRY `' . $mac . '`');
- }
- } else {
- log_register('PON MACEMPTY TRY `' . $mac . '`');
- }
- if ($currentSerial != $serial) {
- if ($this->checkOnuUnique($serial)) {
- $this->onuDb->data('serial', $serial);
- if (!empty($serial)) {
- if (empty($currentSerial)) {
- log_register('PON EDIT ONU [' . $onuId . '] SET SERIAL `' . $serial . '`');
- } else {
- log_register('PON EDIT ONU [' . $onuId . '] SET SERIAL `' . $serial . '` INSTEAD `' . $currentSerial . '`');
- }
- } else {
- if (empty($currentSerial)) {
- log_register('PON EDIT ONU [' . $onuId . '] SET SERIAL EMPTY');
- } else {
- log_register('PON EDIT ONU [' . $onuId . '] SET SERIAL EMPTY INSTEAD `' . $currentSerial . '`');
- }
- }
- } else {
- log_register('PON SERIALDUPLICATE TRY `' . $serial . '`');
- }
- }
- if ($currentLogin != $login) {
- $this->onuDb->data('login', $login);
- if (!empty($login)) {
- if (empty($currentLogin)) {
- log_register('PON EDIT ONU [' . $onuId . '] SET LOGIN (' . $login . ')');
- } else {
- log_register('PON EDIT ONU [' . $onuId . '] SET LOGIN (' . $login . ') INSTEAD (' . $currentLogin . ')');
- }
- } else {
- if (empty($currentLogin)) {
- log_register('PON EDIT ONU [' . $onuId . '] SET LOGIN EMPTY');
- } else {
- log_register('PON EDIT ONU [' . $onuId . '] SET LOGIN EMPTY INSTEAD (' . $currentLogin . ')');
- }
- }
- }
- $this->onuDb->save();
- log_register('PON EDIT ONU [' . $onuId . '] MAC `' . $mac . '`');
- $this->flushOnuCache();
- }
- /**
- * Assigns exinsting ONU with some login
- *
- * @param int $onuid
- * @param string $login
- *
- * @return void
- */
- public function onuAssign($onuid, $login) {
- $onuid = ubRouting::filters($onuid, 'int');
- if (isset($this->allOnu[$onuid])) {
- $this->onuDb->where('id', '=', $onuid);
- $this->onuDb->data('login', $login);
- $this->onuDb->save();
- log_register('PON ASSIGN ONU [' . $onuid . '] WITH (' . $login . ')');
- $this->flushOnuCache();
- } else {
- log_register('PON ASSIGN ONU [' . $onuid . '] FAILED');
- }
- }
- /**
- * Deletes onu from database by its ID
- *
- * @param int $onuId
- */
- public function onuDelete($onuId) {
- $onuId = ubRouting::filters($onuId, 'int');
- $this->onuDb->where('id', '=', $onuId);
- $this->onuDb->delete();
- log_register('PON DELETE ONU [' . $onuId . ']');
- $this->flushOnuCache();
- }
- /**
- * Returns ONU creation form
- *
- * @return string
- */
- protected function onuCreateForm() {
- $models = array();
- $result = '';
- if (!empty($this->allModelsData)) {
- foreach ($this->allModelsData as $io => $each) {
- if (@$this->altCfg['ONUMODELS_FILTER']) {
- if (ispos($each['modelname'], 'ONU')) {
- $models[$each['id']] = $each['modelname'];
- }
- } else {
- $models[$each['id']] = $each['modelname'];
- }
- }
- }
- if (!empty($this->allOltDevices)) {
- if (!empty($models)) {
- $inputs = wf_HiddenInput('createnewonu', 'true');
- $inputs .= wf_Selector('newoltid', $this->allOltDevices, __('OLT device') . $this->sup, '', true);
- $inputs .= wf_Selector('newonumodelid', $models, __('ONU model') . $this->sup, '', true);
- if (@$this->altCfg['PON_ONUIPASIF']) {
- $ipFieldLabel = __('Interface');
- } else {
- $ipFieldLabel = __('IP');
- }
- $inputs .= wf_TextInput('newip', $ipFieldLabel, '', true, 20);
- $inputs .= wf_TextInput('newmac', __('MAC') . $this->sup, '', true, 20, 'mac');
- $inputs .= wf_TextInput('newserial', __('Serial number'), '', true, 20);
- $inputs .= wf_TextInput('newlogin', __('Login'), '', true, 20);
- $inputs .= wf_Submit(__('Create'));
- $result .= wf_Form('', 'POST', $inputs, 'glamour');
- } else {
- $messages = new UbillingMessageHelper();
- $result .= $messages->getStyledMessage(__('Any available ONU models exist'), 'error');
- }
- } else {
- $messages = new UbillingMessageHelper();
- $result .= $messages->getStyledMessage(__('Any available OLT devices exist'), 'error');
- }
- return ($result);
- }
- /**
- * Returns ONU fast registration form
- *
- * @param int $oltId
- * @param string $onuMac
- *
- * @return string
- */
- public function onuRegisterForm($oltId, $onuMac, $UserLogin = '', $UserIP = '', $RenderedOutside = false, $PageReloadAfterDone = false, $CtrlIDToReplaceAfterDone = '', $ModalWindowID = '') {
- $models = array();
- $telepathyArray = array();
- $result = '';
- $onuSerial = '';
- if (!empty($onuMac)) {
- if (!check_mac_format($onuMac)) {
- $onuSerial = $onuMac; //this is something like not mac
- $onuMac = zb_MacGetRandom(); //replacing MAC with random one
- }
- }
- if (!empty($this->allModelsData)) {
- foreach ($this->allModelsData as $io => $each) {
- if (@$this->altCfg['ONUMODELS_FILTER']) {
- if (ispos($each['modelname'], 'ONU')) {
- $models[$each['id']] = $each['modelname'];
- }
- } else {
- $models[$each['id']] = $each['modelname'];
- }
- }
- }
- if ($this->onuUknownUserByMACSearchTelepathy and (empty($UserLogin) or empty($UserIP))) {
- $telepathyArray = $this->getUserByONUMAC($onuMac, $this->onuUknownUserByMACSearchIncrement);
- if (!empty($telepathyArray)) {
- $UserLogin = $telepathyArray['login'];
- $UserIP = $telepathyArray['ip'];
- }
- }
- if (!empty($this->allOltDevices)) {
- if (!empty($models)) {
- $inputs = wf_HiddenInput('createnewonu', 'true');
- $inputs .= wf_Selector('newoltid', $this->allOltDevices, __('OLT device') . $this->sup, $oltId, true);
- $inputs .= wf_Selector('newonumodelid', $models, __('ONU model') . $this->sup, '', true);
- $inputs .= wf_TextInput('newip', __('IP'), $UserIP, true, 20, '', '__NewONUIP');
- $inputs .= wf_TextInput('newmac', __('MAC') . $this->sup, $onuMac, true, 20, 'mac', '__NewONUMAC');
- $inputs .= wf_TextInput('newserial', __('Serial number'), $onuSerial, true, 20);
- $inputs .= wf_TextInput('newlogin', __('Login'), $UserLogin, true, 20, '', '__NewONULogin');
- $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;"');
- $inputs .= wf_tag('span', false, '', 'id="onuassignment2" style="font-weight: 600; color: #000"');
- $inputs .= wf_tag('span', true);
- if (($this->onuUknownUserByMACSearchShow and (empty($UserLogin) or empty($UserIP))) or $this->onuUknownUserByMACSearchShowAlways) {
- $inputs .= wf_delimiter(0) . wf_tag('div', false, '', 'style="padding: 2px 8px;"');
- $inputs .= __('Try to find user by MAC') . ':';
- $inputs .= wf_tag('div', false, '', 'style="margin-top: 5px;"');
- $inputs .= wf_nbsp(2) . wf_tag('span', false, '', 'style="width: 444px;display: inline-block;float: left;"') .
- __('increase/decrease searched MAC address on (use negative value to decrease MAC)') . wf_tag('span', true) .
- wf_tag('span', false, '', 'style="display: inline-block;padding: 5px 0;"') .
- wf_TextInput('macincrementwith', '', $this->onuUknownUserByMACSearchIncrement, true, '4', '', '__MACIncrementWith') .
- wf_tag('span', true);
- $inputs .= wf_tag('div', true);
- $inputs .= wf_Link('#', __('Search'), true, 'ubButton __UserByMACSearchBtn', 'style="width: 100%; text-align: center; padding: 6px 0; margin-top: 5px;"');
- $inputs .= wf_tag('div', true);
- }
- $NoRedirChkID = 'NoRedirChk_' . wf_InputId();
- $ReloadChkID = 'ReloadChk_' . wf_InputId();
- $SubmitID = 'Submit_' . wf_InputId();
- $FormID = 'Form_' . wf_InputId();
- $HiddenReplID = 'ReplaceCtrlID_' . wf_InputId();
- $HiddenModalID = 'ModalWindowID_' . wf_InputId();
- $inputs .= wf_tag('br');
- $inputs .= (($RenderedOutside) ? wf_CheckInput('NoRedirect', __('Do not redirect anywhere: just add & close'), true, true, $NoRedirChkID, '__ONUAACFormNoRedirChck') : '');
- $inputs .= (($PageReloadAfterDone) ? wf_CheckInput('', __('Reload page after action'), true, true, $ReloadChkID, '__ONUAACFormPageReloadChck') : '');
- $inputs .= wf_tag('br');
- $inputs .= wf_Submit(__('Create'), $SubmitID);
- $result = wf_Form(self::URL_ME, 'POST', $inputs, 'glamour __ONUAssignAndCreateForm', '', $FormID);
- $result .= wf_HiddenInput('', $CtrlIDToReplaceAfterDone, $HiddenReplID, '__ONUAACFormReplaceCtrlID');
- $result .= wf_HiddenInput('', $ModalWindowID, $HiddenModalID, '__ONUAACFormModalWindowID');
- $result .= wf_tag('script', false, '', 'type="text/javascript"');
- $result .= '
- $(\'#' . $FormID . '\').submit(function(evt) {
- if ( $(\'#' . $NoRedirChkID . '\').is(\':checked\') ) {
- evt.preventDefault();
-
- $.ajax({
- type: "POST",
- url: "' . self::URL_ME . '",
- data: $(\'#' . $FormID . '\').serialize(),
- success: function() {
- if ( $(\'#' . $ReloadChkID . '\').is(\':checked\') ) { location.reload();}
- $( \'#\'+$(\'#' . $HiddenReplID . '\').val() ).replaceWith(\'' . web_ok_icon() . '\');
- $( \'#\'+$(\'#' . $HiddenModalID . '\').val() ).dialog("close");
- }
- });
- }
- });
- ';
- $result .= wf_tag('script', true);
- } else {
- $messages = new UbillingMessageHelper();
- $result .= $messages->getStyledMessage(__('Any available ONU models exist'), 'error');
- }
- } else {
- $messages = new UbillingMessageHelper();
- $result .= $messages->getStyledMessage(__('Any available OLT devices exist'), 'error');
- }
- return ($result);
- }
- /**
- * returns vendor by MAC search control if this enabled in config
- *
- * @return string
- */
- protected function getSearchmacControl($mac) {
- $result = '';
- if ($this->altCfg['MACVEN_ENABLED']) {
- if (cfr('MACVEN')) {
- if (!empty($mac)) {
- $optionState = $this->altCfg['MACVEN_ENABLED'];
- switch ($optionState) {
- case 1:
- $lookupUrl = '?module=macvendor&modalpopup=true&mac=' . $mac;
- $result .= wf_AjaxLink($lookupUrl, wf_img('skins/macven.gif', __('Device vendor')), 'macvendorcontainer', false);
- $result .= wf_AjaxContainerSpan('macvendorcontainer', '', '');
- break;
- case 2:
- $vendorframe = wf_tag('iframe', false, '', 'src="?module=macvendor&mac=' . $mac . '" width="360" height="160" frameborder="0"');
- $vendorframe .= wf_tag('iframe', true);
- $result = wf_modalAuto(wf_img('skins/macven.gif', __('Device vendor')), __('Device vendor'), $vendorframe, '');
- break;
- case 3:
- $lookupUrl = '?module=macvendor&raw=true&mac=' . $mac;
- $result .= wf_AjaxLink($lookupUrl, wf_img('skins/macven.gif', __('Device vendor')), 'macvendorcontainer', false);
- $result .= wf_AjaxContainerSpan('macvendorcontainer', '', '');
- break;
- }
- }
- }
- }
- return ($result);
- }
- /**
- * Renders ONU assigning form
- *
- * @param string $login
- * @return string
- */
- public function onuAssignForm($login) {
- $result = '';
- $params = array();
- $allRealnames = zb_UserGetAllRealnames();
- $allAddress = zb_AddressGetFulladdresslistCached();
- @$userAddress = $allAddress[$login];
- @$userRealname = $allRealnames[$login];
- if (!empty($this->allOnu)) {
- foreach ($this->allOnu as $io => $each) {
- if (empty($each['login'])) {
- $onuLabel = (empty($each['ip'])) ? $each['mac'] : $each['mac'] . ' - ' . $each['ip'];
- $params[$each['id']] = $onuLabel;
- }
- }
- }
- //user data
- $cells = wf_TableCell(__('Real Name'), '30%', 'row2');
- $cells .= wf_TableCell($userRealname);
- $rows = wf_TableRow($cells, 'row3');
- $cells = wf_TableCell(__('Full address'), '30%', 'row2');
- $cells .= wf_TableCell($userAddress);
- $rows .= wf_TableRow($cells, 'row3');
- $result .= wf_TableBody($rows, '100%', 0, '');
- $result .= wf_delimiter();
- if (!empty($params)) {
- $inputs = wf_HiddenInput('assignonulogin', $login);
- $inputs .= wf_Selector('assignonuid', $params, __('ONU'), '', false);
- $inputs .= wf_Submit(__('Save'));
- $result .= wf_Form('', 'POST', $inputs, 'glamour');
- } else {
- $result .= $this->messages->getStyledMessage(__('No ONUs not assigned to users were found'), 'success');
- }
- $result .= wf_CleanDiv();
- $result .= wf_delimiter();
- $result .= web_UserControls($login);
- return ($result);
- }
- /**
- * Returns array of additional ONU assigned users
- *
- * @param int $onuId
- *
- * @return array
- */
- protected function getOnuExtUsers($onuId) {
- $result = array();
- if (!empty($this->allOnuExtUsers)) {
- foreach ($this->allOnuExtUsers as $io => $each) {
- if ($each['onuid'] == $onuId) {
- $result[$each['id']] = $each;
- }
- }
- }
- return ($result);
- }
- /**
- * Deletes existing user binding to ONU by user Id
- *
- * @param int $extUserId
- *
- * @return void
- */
- public function deleteOnuExtUser($extUserId) {
- $extUserId = ubRouting::filters($extUserId, 'int');
- if (isset($this->allOnuExtUsers[$extUserId])) {
- $oldData = $this->allOnuExtUsers[$extUserId];
- $this->onuExtUsersDb->where('id', '=', $extUserId);
- $this->onuExtUsersDb->delete();
- log_register('PON EDIT ONU [' . $oldData['onuid'] . '] DELETE EXTUSER (' . $oldData['login'] . ')');
- }
- }
- /**
- * Renders additional user creation form
- *
- * @param int $onuId
- *
- * @return string
- */
- protected function renderOnuExtUserForm($onuId) {
- $result = '';
- $onuId = vf($onuId, 3);
- if (isset($this->allOnu[$onuId])) {
- $inputs = wf_HiddenInput('newpononuextid', $onuId);
- $inputs .= wf_TextInput('newpononuextlogin', __('Login'), '', false, 20) . ' ';
- $inputs .= wf_Submit(__('Create'));
- $result .= wf_Form('', 'POST', $inputs, 'glamour');
- }
- return ($result);
- }
- /**
- * Creates new ONU additional user binding
- *
- * @param int $onuId
- * @param string $login
- *
- * @return void
- */
- public function createOnuExtUser($onuId, $login) {
- $onuId = ubRouting::filters($onuId, 'int');
- if (isset($this->allOnu[$onuId])) {
- $loginF = ubRouting::filters($login, 'mres');
- $this->onuExtUsersDb->data('onuid', $onuId);
- $this->onuExtUsersDb->data('login', $loginF);
- $this->onuExtUsersDb->create();
- log_register('PON EDIT ONU [' . $onuId . '] ASSIGN EXTUSER (' . $login . ')');
- }
- }
- /**
- * Returns existing ONU data or empty array if it not exists
- *
- * @param int $onuId
- *
- * @return array
- */
- public function getOnuData($onuId) {
- $result = array();
- if (isset($this->allOnu[$onuId])) {
- $result = $this->allOnu[$onuId];
- }
- return ($result);
- }
- /**
- * Returns some ONU signal level as array with following keys: raw/color/type/styled/isoffline
- *
- * @param int $onuId
- *
- * @return array
- */
- public function getOnuSignalLevelData($onuId) {
- $result = array();
- if (isset($this->allOnu[$onuId])) {
- $onuData = $this->allOnu[$onuId];
- $oltId = $onuData['oltid'];
- $oltPollingStats = $this->pollingStatsRead($oltId);
- //load cache once
- if (empty($this->signalCache)) {
- if ($this->oltData->isSignalsAvailable()) {
- $this->loadSignalsCache();
- }
- }
- $offlineFlag = false;
- if (isset($this->signalCache[$onuData['mac']])) {
- $signal = $this->signalCache[$onuData['mac']];
- if (($signal > 0) or ($signal < -27)) {
- $sigColor = self::COLOR_BAD;
- $sigLabel = 'Bad signal';
- } elseif ($signal > -27 and $signal < -25) {
- $sigColor = self::COLOR_AVG;
- $sigLabel = 'Mediocre signal';
- } else {
- $sigColor = self::COLOR_OK;
- $sigLabel = 'Normal';
- }
- if ($signal == self::NO_SIGNAL) {
- $ONUIsOffline = true;
- $signal = __('No');
- $sigColor = self::COLOR_NOSIG;
- $sigLabel = 'No signal';
- $offlineFlag = true;
- }
- } elseif (isset($this->signalCache[$onuData['serial']])) {
- $signal = $this->signalCache[$onuData['serial']];
- if (($signal > 0) or ($signal < -27)) {
- $sigColor = self::COLOR_BAD;
- $sigLabel = 'Bad signal';
- } elseif ($signal > -27 and $signal < -25) {
- $sigColor = self::COLOR_AVG;
- $sigLabel = 'Mediocre signal';
- } else {
- $sigColor = self::COLOR_OK;
- $sigLabel = 'Normal';
- }
- if ($signal == self::NO_SIGNAL) {
- $ONUIsOffline = true;
- $signal = __('No');
- $sigColor = self::COLOR_NOSIG;
- $sigLabel = 'No signal';
- $offlineFlag = true;
- }
- } else {
- $ONUIsOffline = true;
- $signal = __('No');
- $sigColor = self::COLOR_NOSIG;
- $sigLabel = 'No signal';
- $offlineFlag = true;
- }
- $result['raw'] = $signal;
- $result['color'] = $sigColor;
- $result['type'] = $sigLabel;
- $result['styled'] = wf_tag('font', false, '', 'color="' . $sigColor . '"') . $signal . wf_tag('font', true);
- $result['isoffline'] = $offlineFlag;
- $result['polltime'] = '';
- $result['pollnow'] = 0;
- if (!empty($oltPollingStats)) {
- if (!$oltPollingStats['finished']) {
- $result['pollnow'] = 1;
- }
- if ($oltPollingStats['end']) {
- $result['polltime'] = $oltPollingStats['end'];
- }
- }
- }
- return ($result);
- }
- /**
- * Returns styled current ONU signal
- *
- * @param int $onuId
- *
- * @return string
- */
- protected function renderOnuSignalBig($onuId) {
- $result = '';
- if (isset($this->allOnu[$onuId])) {
- $allDeadSwitches = zb_SwitchesGetAllDead();
- $oltId = $this->allOnu[$onuId]['oltid'];
- $oltIp = $this->allOltIps[$oltId];
- $deadOltFlag = (isset($allDeadSwitches[$oltIp])) ? true : false;
- $onuSignal = $this->getOnuSignalLevelData($onuId);
- if (!empty($onuSignal)) {
- $sigTypeLabel=($deadOltFlag) ? __('Latest') : __('Current');
- $result .= wf_tag('div', false, 'onusignalbig');
- $result .= $sigTypeLabel . ' ' . __('Signal') . ' ' . __('ONU');
- $result .= wf_delimiter();
- $result .= wf_tag('font', false, '', 'color="' . $onuSignal['color'] . '" size="16pt"') . $onuSignal['raw'] . wf_tag('font', true);
- $result .= wf_delimiter();
- if ($deadOltFlag) {
- $result .= wf_img('skins/skull.png') . ' ' . __('OLT is dead now');
- } else {
- $result .= __($onuSignal['type']);
- }
- $result .= $this->renderOnuMiscStats($onuId, $onuSignal);
- $result .= ($this->onuUniStatusEnabled) ? $this->renderONUUniStats($onuId, $onuSignal) : '';
- $result .= wf_tag('div', true);
- }
- }
- return ($result);
- }
- /**
- * Renders ONU interface, distance and last dereg reason if available
- *
- * @param int $onuId
- * @param array $signalStatsData
- *
- * @return string
- */
- protected function renderOnuMiscStats($onuId, $signalStatsData) {
- $result = '';
- $offlineFlag = ($signalStatsData['isoffline']) ? true : false;
- if (isset($this->allOnu[$onuId])) {
- $this->loadInterfaceCache();
- $this->loadDistanceCache();
- $this->loadLastDeregCache();
- $onuData = $this->allOnu[$onuId];
- $onuMiscStats = '';
- // interface
- $interfaceIcon = wf_img_sized('skins/pon_icon.gif', __('Interface'), '12');
- if (isset($this->interfaceCache[$onuData['mac']])) {
- $onuMiscStats .= $interfaceIcon . ' ' . $this->interfaceCache[$onuData['mac']] . ' ';
- } else {
- if (isset($this->interfaceCache[$onuData['serial']])) {
- $onuMiscStats .= $interfaceIcon . ' ' . $this->interfaceCache[$onuData['serial']] . ' ';
- }
- }
- //distance
- if (!$offlineFlag) {
- $distanceIcon = wf_img_sized('skins/distance_icon.png', __('Distance'), '12');
- if (isset($this->distanceCache[$onuData['mac']])) {
- $onuMiscStats .= $distanceIcon . ' ' . $this->distanceCache[$onuData['mac']] . __('m') . ' ';
- } else {
- if (isset($this->distanceCache[$onuData['serial']])) {
- $onuMiscStats .= $distanceIcon . ' ' . $this->distanceCache[$onuData['serial']] . __('m') . ' ';
- }
- }
- }
- //last dereg reason
- if ($offlineFlag) {
- $offlineIcon = wf_img_sized('skins/offline_icon.png', __('Last dereg reason'), '12');
- if (isset($this->lastDeregCache[$onuData['mac']])) {
- $onuMiscStats .= $offlineIcon . ' ' . $this->lastDeregCache[$onuData['mac']] . ' ';
- } else {
- if (isset($this->lastDeregCache[$onuData['serial']])) {
- $onuMiscStats .= $offlineIcon . ' ' . $this->lastDeregCache[$onuData['serial']] . ' ';
- }
- }
- }
- //polling time here
- $fullTime = '';
- $shortTime = '';
- if (!empty($signalStatsData['polltime'])) {
- $fullTime = __('Time') . ': ' . date("Y-m-d H:i:s", $signalStatsData['polltime']);
- $shortTime = date("H:i:s", $signalStatsData['polltime']);
- } else {
- $shortTime .= __('In progress now');
- }
- $pollTimeIcon = ($signalStatsData['pollnow']) ? self::POLL_RUNNING : wf_img_sized('skins/icon_time_small.png', $fullTime, '12');
- $onuMiscStats .= $pollTimeIcon . ' ' . $shortTime;
- $containerStyle = 'style="font-size:10pt; padding:10px;"';
- $result .= wf_tag('div', false, '', $containerStyle);
- $result .= $onuMiscStats;
- $result .= wf_tag('div', true);
- }
- return ($result);
- }
- /**
- * Renders ONU UNI port operational status if available
- *
- * @param $onuId
- * @param $signalStatsData
- *
- * @return string
- */
- protected function renderONUUniStats($onuId, $signalStatsData) {
- $result = '';
- $onuMAC = '';
- $onuSerial = '';
- $uniStatsData = '';
- $onuUniOperStats = '';
- $offlineFlag = ($signalStatsData['isoffline']) ? true : false;
- if (isset($this->allOnu[$onuId]) and !$offlineFlag) {
- $this->loadUniOperStatsCache();
- if (!empty($this->allOnu[$onuId]['mac'])) {
- $onuMAC = $this->allOnu[$onuId]['mac'];
- }
- if (!empty($this->allOnu[$onuId]['serial'])) {
- $onuSerial = $this->allOnu[$onuId]['serial'];
- }
- if (!empty($this->uniOperStatsCache[$onuMAC])) {
- $uniStatsData = $this->uniOperStatsCache[$onuMAC];
- } elseif (!empty($this->uniOperStatsCache[$onuSerial])) {
- $uniStatsData = $this->uniOperStatsCache[$onuSerial];
- }
- if (!empty($uniStatsData)) {
- foreach ($uniStatsData as $eachPort => $eachStatus) {
- if ($eachStatus) {
- $interfaceIcon = wf_img_sized('skins/icon_ether.gif', __('Interface')) . wf_nbsp()
- . wf_img_sized('skins/rise_icon.png', __('Up'), '8', '10');
- } else {
- $interfaceIcon = wf_img_sized('skins/icon_ether_down.png', __('Interface')) . wf_nbsp()
- . wf_img_sized('skins/drain_icon.png', __('Down'), '8', '10');
- }
- $onuUniOperStats .= $eachPort . ': ' . $interfaceIcon . wf_nbsp(4);
- }
- $containerStyle = 'style="font-size:10pt; padding:10px;"';
- $result .= wf_tag('div', false, '', $containerStyle);
- $result .= $onuUniOperStats;
- $result .= wf_tag('div', true);
- }
- }
- return ($result);
- }
- /**
- * Performs burial of some ONU
- *
- * @param int $onuId
- *
- * @return void
- */
- public function onuBurial($onuId) {
- $onuid = ubRouting::filters($onuId, 'int');
- if (isset($this->allOnu[$onuId])) {
- $this->onuDb->where('id', '=', $onuId);
- $this->onuDb->data('login', 'dead');
- $this->onuDb->save();
- log_register('PON BURIAL ONU [' . $onuId . ']');
- $this->flushOnuCache();
- } else {
- log_register('PON BURIAL ONU [' . $onuId . '] FAILED');
- }
- }
- /**
- * Performs resurrection of some buried ONU
- *
- * @param int $onuId
- *
- * @return void
- */
- public function onuResurrect($onuId) {
- $onuid = ubRouting::filters($onuId, 'int');
- if (isset($this->allOnu[$onuId])) {
- $this->onuDb->where('id', '=', $onuId);
- $this->onuDb->data('login', '');
- $this->onuDb->save();
- log_register('PON RESURRECT ONU [' . $onuId . ']');
- } else {
- log_register('PON RESURRECT ONU [' . $onuId . '] FAILED');
- }
- }
- /**
- * Returns ONU edit form
- *
- * @param int $onuId
- * @param bool $limitedControls
- *
- * @return string
- */
- public function onuEditForm($onuId, $limitedControls = false) {
- $onuId = ubRouting::filters($onuId, 'int');
- $result = '';
- if (isset($this->allOnu[$onuId])) {
- $messages = new UbillingMessageHelper();
- $models = array();
- if (!empty($this->allModelsData)) {
- foreach ($this->allModelsData as $io => $each) {
- if (@$this->altCfg['ONUMODELS_FILTER']) {
- if (ispos($each['modelname'], 'ONU')) {
- $models[$each['id']] = $each['modelname'];
- }
- } else {
- $models[$each['id']] = $each['modelname'];
- }
- }
- }
- $onuPortsCount = $this->allModelsData[$this->allOnu[$onuId]['onumodelid']]['ports'];
- $onuMaxUsers = $onuPortsCount - 1;
- $onuExtUsers = $this->getOnuExtUsers($onuId);
- $onuCurrentExtUsers = sizeof($onuExtUsers);
- $inputs = wf_HiddenInput('editonu', $onuId);
- if ($this->altCfg['OLTSEL_SEARCHBL']) {
- $inputs .= wf_SelectorSearchable('editoltid', $this->allOltDevices, __('OLT device') . $this->sup, $this->allOnu[$onuId]['oltid'], true, false);
- } else {
- $inputs .= wf_Selector('editoltid', $this->allOltDevices, __('OLT device') . $this->sup, $this->allOnu[$onuId]['oltid'], true, false);
- }
- $inputs .= wf_Selector('editonumodelid', $models, __('ONU model') . $this->sup, $this->allOnu[$onuId]['onumodelid'], true);
- if (@$this->altCfg['PON_ONUIPASIF']) {
- $ipFieldLabel = __('Interface');
- } else {
- $ipFieldLabel = __('IP');
- }
- $inputs .= wf_TextInput('editip', $ipFieldLabel, $this->allOnu[$onuId]['ip'], true, 20);
- $inputs .= wf_TextInput('editmac', __('MAC') . $this->sup . ' ' . $this->getSearchmacControl($this->allOnu[$onuId]['mac']), $this->allOnu[$onuId]['mac'], true, 20);
- $inputs .= wf_TextInput('editserial', __('Serial number'), $this->allOnu[$onuId]['serial'], true, 20);
- $burialLabel = ($this->allOnu[$onuId]['login'] == 'dead') ? ' ' . wf_img('skins/skull.png', __('Buried')) : '';
- $inputs .= wf_TextInput('editlogin', __('Login') . $burialLabel, $this->allOnu[$onuId]['login'], true, 20);
- if (!empty($onuExtUsers)) {
- foreach ($onuExtUsers as $io => $each) {
- //Editing feature: 100$ donate or do it yourself. Im to lazy right now.
- $inputs .= wf_tag('input', false, '', 'name="onuextlogin_' . $each['id'] . '" type="text" value="' . $each['login'] . '" size="20" DISABLED') . ' ';
- if (cfr('PONEDIT')) {
- $controllerUrl = self::URL_ME;
- if ($limitedControls) {
- $controllerUrl = '?module=pl_branchesonuview';
- }
- $inputs .= wf_JSAlert($controllerUrl . '&editonu=' . $onuId . '&deleteextuser=' . $each['id'], wf_img_sized('skins/icon_del.gif', __('Delete'), '13'), $messages->getDeleteAlert()) . ' ';
- }
- $inputs .= wf_Link(self::URL_USERPROFILE . $each['login'], web_profile_icon());
- $inputs .= wf_tag('br');
- }
- }
- if (cfr('PONEDIT')) {
- $inputs .= wf_tag('br');
- $inputs .= wf_Submit(__('Save'));
- }
- $onuEditForm = wf_Form('', 'POST', $inputs, 'glamour');
- $gridCells = wf_TableCell($onuEditForm . wf_CleanDiv(), '50%', '');
- $gridCells .= wf_TableCell($this->renderOnuSignalBig($onuId));
- $gridRows = wf_TableRow($gridCells);
- $result = wf_TableBody($gridRows, '100%', 0, '');
- $result .= wf_CleanDiv();
- ///ponboxes here. We hope.
- if (@$this->altCfg['PONBOXES_ENABLED']) {
- $ponBoxes = new PONBoxes(true);
- //linking if required
- if (ubRouting::checkPost(array($ponBoxes::PROUTE_NEWLINKBOX, $ponBoxes::PROUTE_NEWLINKONU, $ponBoxes::PROUTE_NEWLINKTYPE))) {
- $newLinkBoxId = ubRouting::post($ponBoxes::PROUTE_NEWLINKBOX);
- $newLinkType = ubRouting::post($ponBoxes::PROUTE_NEWLINKTYPE);
- $newLinkOnuId = ubRouting::post($ponBoxes::PROUTE_NEWLINKONU);
- $ponBoxLinkResult = $ponBoxes->createLinkONU($newLinkBoxId, $newLinkOnuId, $newLinkType);
- if (empty($ponBoxLinkResult)) {
- ubRouting::nav(self::URL_ME . '&editonu=' . $newLinkOnuId);
- } else {
- show_error($ponBoxLinkResult);
- }
- }
- //interface render
- $result .= wf_delimiter();
- $result .= $ponBoxes->renderBoxAssignForm($this->allOnu[$onuId]);
- //rendering associated boxes
- $linkedBoxes = $ponBoxes->getLinkedBoxes($this->allOnu[$onuId]);
- if (count($linkedBoxes) > 1) {
- $result .= $ponBoxes->renderCrossLinkWarning();
- }
- $result .= $ponBoxes->renderLinkedBoxes($linkedBoxes);
- }
- $result .= wf_delimiter();
- if (!$limitedControls) {
- $result .= wf_BackLink(self::URL_ONULIST);
- }
- //back to primary user profile control
- if (!empty($this->allOnu[$onuId]['login'])) {
- if ($this->allOnu[$onuId]['login'] != 'dead') {
- $result .= wf_Link(self::URL_USERPROFILE . $this->allOnu[$onuId]['login'], wf_img('skins/icon_user.gif') . ' ' . __('User profile'), false, 'ubButton');
- }
- }
- //ONU burial or resurrection controls
- if (!empty($this->allOnu[$onuId]['login'])) {
- if (cfr('PONEDIT') and !$limitedControls) {
- if (@$this->altCfg['ONU_BURIAL_ENABLED']) {
- if ($this->allOnu[$onuId]['login'] != 'dead') {
- //this ONU is owned by some user. Burial controls here.
- $burCancelUrl = self::URL_ME . '&editonu=' . $onuId;
- $burConfirmUrl = self::URL_ME . '&onuburial=' . $onuId;
- $burAlertLabel = __('Bury this ONU') . '? ' . $messages->getEditAlert();
- $result .= wf_ConfirmDialog($burConfirmUrl, wf_img('skins/skull.png') . __('Bury this ONU'), $burAlertLabel, 'ubButton', $burCancelUrl);
- } else {
- //this ONU is already buried. Ressurection controls here.
- $resCancelUrl = self::URL_ME . '&editonu=' . $onuId;
- $resConfirmUrl = self::URL_ME . '&onuresurrect=' . $onuId;
- $resAlertLabel = __('Resurrect this ONU') . '? ' . $messages->getEditAlert() . ' ';
- $resAlertLabel .= __('After resurrection device will be marked as not belonging to anyone') . '.';
- $result .= wf_ConfirmDialog($resConfirmUrl, wf_img('skins/pigeon_icon.png') . ' ' . __('Resurrect this ONU'), $resAlertLabel, 'ubButton', $resCancelUrl);
- }
- }
- }
- }
- //additional login append forms
- if (cfr('PONEDIT')) {
- if (sizeof($onuExtUsers) < $onuMaxUsers) {
- $extCreationLabel = wf_img_sized('skins/add_icon.png', '', '13') . ' ' . __('Assign additional login');
- $result .= wf_modalAuto($extCreationLabel, __('Additional login') . ' (' . ($onuMaxUsers - $onuCurrentExtUsers) . ' ' . __('remains') . ')', $this->renderOnuExtUserForm($onuId), 'ubButton');
- }
- }
- //ONU deletion control
- if (cfr('PONDEL') and !$limitedControls) {
- $delCancelUrl = self::URL_ME . '&editonu=' . $onuId;
- $delConfirmUrl = self::URL_ME . '&deleteonu=' . $onuId;
- $result .= wf_ConfirmDialog($delConfirmUrl, web_delete_icon() . ' ' . __('Delete') . ' ' . __('ONU'), $messages->getDeleteAlert(), 'ubButton', $delCancelUrl);
- }
- } else {
- $result = wf_tag('div', false, 'alert_error') . __('Strange exeption') . ': ONUID_NOT_EXISTS' . wf_tag('div', true);
- }
- //additional comments handling
- if ($this->altCfg['ADCOMMENTS_ENABLED']) {
- $adcomments = new ADcomments('PONONU');
- $result .= wf_delimiter();
- $result .= wf_tag('h3') . __('Additional comments') . wf_tag('h3', true);
- $result .= $adcomments->renderComments($onuId);
- }
- return ($result);
- }
- /**
- * Renders ONU signal history chart
- *
- * @param int $onuId
- * @return string
- */
- protected function onuSignalHistory($onuId, $ShowTitle = false, $ShowXLabel = false, $ShowYLabel = false, $ShowRangeSelector = false) {
- $billCfg = $this->ubConfig->getBilling();
- $onuId = vf($onuId, 3);
- $result = '';
- if (isset($this->allOnu[$onuId])) {
- //not empty MAC
- if ($this->allOnu[$onuId]['mac']) {
- if (file_exists(self::ONUSIG_PATH . md5($this->allOnu[$onuId]['mac']))) {
- $historyKey = self::ONUSIG_PATH . md5($this->allOnu[$onuId]['mac']);
- $historyKeyMonth = self::ONUSIG_PATH . md5($this->allOnu[$onuId]['mac']) . '_month';
- } elseif (file_exists(self::ONUSIG_PATH . md5($this->allOnu[$onuId]['serial']))) {
- $historyKey = self::ONUSIG_PATH . md5($this->allOnu[$onuId]['serial']);
- $historyKeyMonth = self::ONUSIG_PATH . md5($this->allOnu[$onuId]['serial']) . '_month';
- } else {
- $historyKey = '';
- $historyKeyMonth = '';
- }
- if (!empty($historyKey)) {
- $curdate = curdate();
- $curmonth = curmonth() . '-';
- $getMonthDataCmd = $billCfg['CAT'] . ' ' . $historyKey . ' | ' . $billCfg['GREP'] . ' ' . $curmonth;
- $rawData = shell_exec($getMonthDataCmd);
- $result .= wf_delimiter();
- //current day signal levels
- $todaySignal = '';
- if (!empty($rawData)) {
- $todayTmp = explodeRows($rawData);
- if (!empty($todayTmp)) {
- foreach ($todayTmp as $io => $each) {
- if (ispos($each, $curdate)) {
- $todaySignal .= $each . "\n";
- }
- }
- }
- }
- $GraphTitle = ($ShowTitle) ? __('Today') : '';
- $GraphXLabel = ($ShowXLabel) ? __('Time') : '';
- $GraphYLabel = ($ShowYLabel) ? __('Signal') : '';
- $result .= wf_Graph($todaySignal, '800', '300', false, $GraphTitle, $GraphXLabel, $GraphYLabel, $ShowRangeSelector);
- $result .= wf_delimiter(2);
- //current month signal levels
- $monthSignal = '';
- $curmonth = curmonth();
- if (!empty($rawData)) {
- $monthTmp = explodeRows($rawData);
- if (!empty($monthTmp)) {
- foreach ($monthTmp as $io => $each) {
- if (ispos($each, $curmonth)) {
- $monthSignal .= $each . "\n";
- }
- }
- }
- }
- $GraphTitle = ($ShowTitle) ? __('Monthly graph') : '';
- $GraphXLabel = ($ShowXLabel) ? __('Date') : '';
- file_put_contents($historyKeyMonth, $monthSignal);
- $result .= wf_GraphCSV($historyKeyMonth, '800', '300', false, $GraphTitle, $GraphXLabel, $GraphYLabel, $ShowRangeSelector);
- $result .= wf_delimiter(2);
- //all time signal history
- $GraphTitle = ($ShowTitle) ? __('All time graph') : '';
- $result .= wf_GraphCSV($historyKey, '800', '300', false, $GraphTitle, $GraphXLabel, $GraphYLabel, $ShowRangeSelector);
- $result .= wf_delimiter();
- }
- }
- }
- return ($result);
- }
- /**
- * Returns default list controls
- *
- * @return string
- */
- public function controls() {
- $result = '';
- if (!ubRouting::checkGet('unknownonulist')) {
- if (cfr('PONEDIT')) {
- $result .= wf_modalAuto(wf_img_sized('skins/add_icon.png', '', '16', '16') . ' ' . __('Create') . ' ' . __('ONU'), __('Register new ONU'), $this->onuCreateForm(), 'ubButton') . ' ';
- }
- $availOnuCache = $this->oltData->isOnusAvailable();
- $result .= wf_Link(self::URL_ME . '&forcepoll=true', wf_img_sized('skins/refresh.gif', '', '16', '16') . ' ' . __('Force query'), false, 'ubButton');
- if (!empty($availOnuCache)) {
- if (cfr('PONEDIT')) {
- $result .= wf_Link(self::URL_ME . '&unknownonulist=true', wf_img_sized('skins/question.png', '', '16', '16') . ' ' . __('Unknown ONU'), false, 'ubButton');
- }
- }
- $availOnuFdbCache = $this->oltData->isFdbAvailable();
- if (!empty($availOnuFdbCache)) {
- $result .= wf_Link(self::URL_ME . '&fdbcachelist=true', wf_img_sized('skins/icon_fdb.png', '', '16', '16') . ' ' . __('Current FDB cache'), false, 'ubButton');
- }
- if (@$this->altCfg['PON_ONU_PORT_MAX']) {
- $result .= wf_Link(self::URL_ME . '&oltstats=true', wf_img_sized('skins/icon_stats.gif', '', '16', '16') . ' ' . __('Stats'), false, 'ubButton');
- }
- if (@$this->altCfg['PONMAP_ENABLED']) {
- if (cfr('ONUMAP')) {
- $result .= wf_Link('?module=ponmap&bl=ponizer', wf_img_sized('skins/ponmap_icon.png', '', '16', '16') . ' ' . __('ONU Map'), false, 'ubButton');
- }
- }
- if (@$this->altCfg['PON_ONU_SEARCH_ENABLED']) {
- $result .= wf_modalAuto(web_icon_search() . ' ' . __('Search'), __('Search') . ' ' . __('ONU'), $this->renderOnuSearchForm(), 'ubButton');
- }
- if ($this->altCfg['ONUREG_ZTE']) {
- $zteControls = '';
- if (cfr(OnuRegister::REG_MODULE_RIGHTS)) {
- $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();
- $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();
- $zteControls .= wf_link(OnuRegister::UNREG_MASS_FIX_PREVIEW_URL, wf_img_sized('skins/brain.png', '', '16', '16') . ' ' . __('Mass fix'), false, 'ubButton') . wf_delimiter();
- }
- if (cfr(OnuRegister::VLAN_MODULE_RIGHTS)) {
- $zteControls .= wf_link(OnuRegister::VLAN_MODULE_URL, wf_img_sized('skins/register.png', '', '16', '16') . ' ' . __('Edit OLT Cards'), false, 'ubButton') . wf_delimiter();
- }
- $result .= wf_modalAuto(web_icon_extended() . ' ' . __('ZTE'), __('ZTE'), $zteControls, 'ubButton');
- }
- } else {
- $result .= wf_BackLink(self::URL_ONULIST);
- $result .= wf_Link(self::URL_ME . '&forcepoll=true&uol=true', wf_img_sized('skins/refresh.gif', '', '16', '16') . ' ' . __('Force query'), false, 'ubButton');
- if (cfr('ROOT')) {
- //ONU batch registration accessible only for ROOT users now
- $massRegUrl = self::URL_ME . '&onumassreg=true';
- $massRegCancelUrl = '?module=ponizer&unknownonulist=true';
- $alertLabel = __('Register all unknown ONUs') . '? ' . __('Are you serious');
- $dialogLink = wf_img('skins/icon_addrow.png') . ' ' . __('Register all unknown ONUs');
- $result .= wf_ConfirmDialog($massRegUrl, $dialogLink, $alertLabel, 'ubButton', $massRegCancelUrl, __('Are you serious'));
- }
- }
- $result .= wf_tag('script', false, '', 'type="text/javascript"');
- $result .= wf_JSEmptyFunc();
- $result .= wf_JSElemInsertedCatcherFunc();
- $result .= '
- function checkONUAssignment() {
- if ( typeof( $(\'input[name=newmac]\').val() ) === "string" && $(\'input[name=newmac]\').val().length > 0 ) {
- $.ajax({
- type: "GET",
- url: "?module=ponizer",
- data: {action:\'checkONUAssignment\', onumac:$(\'input[name=newmac]\').val()},
- success: function(result) {
- $(\'#onuassignment2\').text(result);
- }
- });
- } else {$(\'#onuassignment2\').text(\'\');}
- }
-
- function dynamicBindClick(ctrlClassName) {
- $(document).on("click", ctrlClassName, function(evt) {
- evt.preventDefault();
- checkONUAssignment($(ctrlClassName).val());
- return false;
- });
- }
-
- onElementInserted(\'body\', \'.__CheckONUAssignmentBtn\', function(element) {
- dynamicBindClick(\'.__CheckONUAssignmentBtn\');
- });
-
- function OLTIndividualRefresh(OLTID, JQAjaxTab, RefreshButtonSelector) {
- $.ajax({
- type: "GET",
- url: "' . self::URL_ME . '",
- data: {IndividualRefresh:true, forceoltidpoll:OLTID},
- success: function(result) {
- if ($.type(JQAjaxTab) === \'string\') {
- $("#"+JQAjaxTab).DataTable().ajax.reload();
- } else {
- $(JQAjaxTab).DataTable().ajax.reload();
- }
-
- if ($.type(RefreshButtonSelector) === \'string\') {
- $("#"+RefreshButtonSelector).find(\'img\').toggleClass("image_rotate");
- } else {
- $(RefreshButtonSelector).find(\'img\').toggleClass("image_rotate");
- }
- }
- });
- };
- function getOLTInfo(OLTID, InfoBlckSelector, ReturnHTML = false, InSpoiler = false) {
- $.ajax({
- type: "GET",
- url: "' . self::URL_ME . '",
- data: { IndividualRefresh:true,
- GetOLTInfo:true,
- apid:OLTID,
- returnAsHTML:ReturnHTML,
- returnInSpoiler:InSpoiler
- },
- success: function(result) {
- var InfoBlck = $(InfoBlckSelector);
- if ( !InfoBlck.length || !(InfoBlck instanceof jQuery)) {return false;}
-
- $(InfoBlck).html(result);
- }
- });
- }
- ';
- // making an event binding for "DelUserAssignment" button("red cross" near user's login) on "ONU create&assign form"
- // 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
- // creating of "ONU create&assign form" dynamically reduces the amount of text and page weight dramatically
- $result .= '$(document).on("click", ".__UsrDelAssignButton", function(evt) {
- $("[name=assignoncreate]").val("");
- $(\'.__UsrAssignBlock\').html("' . __('Do not assign WiFi equipment to any user') . '");
- evt.preventDefault();
- return false;
- });
-
- ';
- // making an event binding for "ONU create&assign form" 'Submit' action to be able to create "ONU create&assign form" dynamically
- $result .= '$(document).on("submit", ".__ONUAssignAndCreateForm", function(evt) {
- if ($(document.activeElement).attr("class") == \'__MACIncrementWith\') {
- evt.preventDefault();
- $(".__UserByMACSearchBtn").click();
- return false;
- }
-
- //var FrmAction = \'"\' + $(".__ONUAssignAndCreateForm").attr("action") + \'"\';
- var FrmAction = $(".__ONUAssignAndCreateForm").attr("action");
-
- if ( $(".__ONUAACFormNoRedirChck").is(\':checked\') ) {
- evt.preventDefault();
-
- $.ajax({
- type: "POST",
- url: FrmAction,
- data: $(".__ONUAssignAndCreateForm").serialize(),
- success: function() {
- if ( $(".__ONUAACFormPageReloadChck").is(\':checked\') ) { location.reload();}
-
- $( \'#\'+$(".__ONUAACFormReplaceCtrlID").val() ).replaceWith(\'' . web_ok_icon() . '\');
- $( \'#\'+$(".__ONUAACFormModalWindowID").val() ).dialog("close");
- }
- });
- }
- });
-
- ';
- $result .= '$(document).on("click", ".__UserByMACSearchBtn", function(evt) {
- //__NewONULogin, __NewONUIP, __NewONUMAC, __MACIncrementWith
-
- $.ajax({
- type: "GET",
- url: "' . self::URL_ME . '",
- data: {
- searchunknownonu:true,
- searchunknownmac:$(".__NewONUMAC").val(),
- searchunknownincrement:$(".__MACIncrementWith").val(),
- searchunknownserialize:true
- },
- success: function(result) {
- var tObj = JSON.parse(result);
-
- if ( empty(tObj.login) && empty(tObj.ip) ) {
- alert(\'' . __('User is not found') . '\');
- } else {
- $(".__NewONULogin").val(tObj.login);
- $(".__NewONUIP").val(tObj.ip);
- }
- }
- });
-
- evt.preventDefault();
- return false;
- });
- ';
- $result .= wf_tag('script', true);
- $result .= wf_delimiter();
- return ($result);
- }
- /**
- * Returns ONU signal history chart
- *
- * @param int $onuId
- * @return string
- */
- public function loadonuSignalHistory($onuId, $ReturnInSpoiler) {
- $result = $this->onuSignalHistory($onuId, true, true, true, true);
- if ($ReturnInSpoiler) {
- $result = wf_Spoiler($result, __('Signal levels history graphs'), $this->ONUChartsSpoilerClosed, '', '', '', '', 'style="margin: 10px auto;display: table;"');
- }
- $result = show_window(__('ONU signal history'), $result);
- return ($result);
- }
- /**
- * Renders available ONU JQDT list container
- *
- * @return string
- */
- public function renderOnuList() {
- $distCacheAvail = $this->oltData->isDistancesAvailable();
- $intCacheAvail = $this->oltData->isInterfacesAvailable();
- $lastDeregCacheAvail = $this->oltData->isDeregsAvailable();
- $oltOnuCounters = $this->getOltOnuCounts();
- $opts = '"order": [[ 0, "desc" ]]';
- if ($this->deferredLoadingFlag) {
- $opts .= ', "deferLoading": 100';
- }
- $result = '';
- $tabClickScript = '';
- $tabsList = array();
- $tabsData = array();
- // to prevent changing the keys order of $this->allOLTDevices we are using "+" opreator and not all those "array_merge" and so on
- $QickOLTsArray = array(-9999 => '') + $this->allOltDevices;
- foreach ($this->allOltDevices as $oltId => $eachOltData) {
- $AjaxURLStr = '' . self::URL_ME . '&ajaxonu=true&oltid=' . $oltId . '';
- $JQDTId = 'jqdt_' . md5($AjaxURLStr);
- $OLTIDStr = 'OLTID_' . $oltId;
- $InfoButtonID = 'InfID_' . $oltId;
- $InfoBlockID = 'InfBlck_' . $oltId;
- $QuickOLTLinkID = 'QuickOLTLinkID_' . $oltId;
- $QuickOLTDDLName = 'QuickOLTDDL_' . wf_InputId();
- $QuickOLTLink = wf_tag('span', false, '', 'id="' . $QuickOLTLinkID . '"') .
- wf_img('skins/menuicons/switches.png') . wf_tag('span', true);
- $oltRenderMode = $this->getOltOnuRenderMode($oltId);
- $columns = array('ID');
- if ($intCacheAvail) {
- $columns[] = __('Interface');
- }
- $columns[] = 'Model';
- if ($this->ipColumnVisible) {
- if (@$this->altCfg['PON_ONUIPASIF']) {
- $columns[] = 'Interface';
- } else {
- $columns[] = 'IP';
- }
- }
- $onuIdentColumn = '';
- if ($oltRenderMode == 'mac') {
- $onuIdentColumn = __('MAC');
- } else {
- $onuIdentColumn = __('Serial');
- }
- $columns[] = $onuIdentColumn;
- $columns[] = 'Signal';
- if ($distCacheAvail) {
- $columns[] = __('Distance') . ' (' . __('m') . ')';
- }
- if ($lastDeregCacheAvail) {
- $columns[] = __('Last dereg reason');
- }
- $columns[] = 'Address';
- $columns[] = 'Real Name';
- $columns[] = 'Tariff';
- $columns[] = 'Actions';
- if ($this->EnableQuickOLTLinks) {
- if ($this->ponizerUseTabUI) {
- $QuickOLTDDLName = 'QuickOLTDDL_100500';
- $tabClickScript = wf_tag('script', false, '', 'type="text/javascript"');
- $tabClickScript .= '$(\'a[href="#' . $QuickOLTLinkID . '"]\').click(function(evt) {
- var tmpID = $(this).attr("href").replace("#QuickOLTLinkID_", "");
- if ($(\'[name="' . $QuickOLTDDLName . '"]\').val() != tmpID) {
- $(\'[name="' . $QuickOLTDDLName . '"]\').val(tmpID);
- }
- });
- ';
- $tabClickScript .= wf_tag('script', true);
- } else {
- $QuickOLTLinkInput = wf_tag('div', false, '', 'style="width: 100%;text-align: right;margin-top: 15px;margin-bottom: 20px"') .
- wf_tag('font', false, '', 'style="font-weight: 600"') . __('Go to OLT') . wf_tag('font', true) .
- wf_nbsp(2) . wf_Selector($QuickOLTDDLName, $QickOLTsArray, '', '', true) .
- wf_tag('script', false, '', 'type="text/javascript"') .
- '$(\'[name="' . $QuickOLTDDLName . '"]\').change(function(evt) {
- var LinkIDObjFromVal = $(\'#QuickOLTLinkID_\'+$(this).val());
- $(\'body,html\').scrollTop( $(LinkIDObjFromVal).offset().top - 25 );
- });' .
- wf_tag('script', true) .
- wf_tag('div', true);
- }
- } else {
- $QuickOLTLinkInput = '';
- }
- if ($this->OLTIndividualRepollAJAX) {
- if ($this->ponizerUseTabUI) {
- if ($this->isPollingNow($oltId)) {
- $refresh_button = wf_tag('span', false, '', 'title="' . __('In progress now') . '"') . self::POLL_RUNNING . wf_tag('span', true);
- } else {
- $refresh_button = wf_tag('span', false, '', 'href="#" id="' . $OLTIDStr . '" title="' . __('Refresh data for this OLT') . '" style="cursor: pointer;"');
- $refresh_button .= wf_img('skins/refresh.gif');
- $refresh_button .= wf_tag('span', true);
- }
- } else {
- $refresh_button = wf_tag('a', false, '', 'href="#" id="' . $OLTIDStr . '" title="' . __('Refresh data for this OLT') . '"');
- $refresh_button .= wf_img('skins/refresh.gif');
- $refresh_button .= wf_tag('a', true);
- }
- $refresh_button .= wf_tag('script', false, '', 'type="text/javascript"');
- $refresh_button .= '$(\'#' . $OLTIDStr . '\').click(function(evt) {
- $(\'img\', this).addClass("image_rotate");
- OLTIndividualRefresh(' . $oltId . ', ' . $JQDTId . ', ' . $OLTIDStr . ');
- evt.preventDefault();
- return false;
- });';
- $refresh_button .= wf_tag('script', true);
- } else {
- $refresh_button = wf_Link(self::URL_ME . '&forceoltidpoll=' . $oltId, wf_img('skins/refresh.gif', __('Refresh data for this OLT')));
- }
- if ($this->ponizerUseTabUI) {
- $tabsList[$QuickOLTLinkID] = array(
- 'options' => '',
- 'caption' => $refresh_button . wf_nbsp(4) . wf_img('skins/menuicons/switches.png') . wf_nbsp(2) . @$eachOltData,
- 'additional_data' => $tabClickScript
- );
- $tabsData[$QuickOLTLinkID] = array(
- 'options' => 'style="padding: 0 0 0 2px;"',
- 'body' => wf_JqDtLoader($columns, $AjaxURLStr, false, 'ONU', 100, $opts),
- 'additional_data' => ''
- );
- } else {
- $result .= show_window($refresh_button . wf_nbsp(4) . $QuickOLTLink . wf_nbsp(2) . @$eachOltData, wf_JqDtLoader($columns, $AjaxURLStr, false, 'ONU', 100, $opts) . $QuickOLTLinkInput);
- }
- }
- if ($this->ponizerUseTabUI) {
- $tabsDivOpts = 'style="border: none;padding: 0;"';
- $tabsLstOpts = 'style="border: none;background: #fff;"';
- if ($this->EnableQuickOLTLinks and !empty($this->allOltDevices)) {
- $QuickOLTDDLName = 'QuickOLTDDL_100500';
- $QickOLTsArray = $this->allOltDevices;
- $oltSelectorBody = wf_Selector($QuickOLTDDLName, $QickOLTsArray, '', '', true, false, 'someid');
- $QuickOLTLinkInput = wf_tag('div', false, '', 'style="margin-top: 15px;text-align: right;"') .
- wf_tag('font', false, '', 'style="font-weight: 600"') . __('Go to OLT') . wf_tag('font', true) .
- wf_nbsp(2) . $oltSelectorBody .
- wf_tag('script', false, '', 'type="text/javascript"') .
- '$(\'[name="' . $QuickOLTDDLName . '"]\').change(function(evt) {
- $(\'a[href="#QuickOLTLinkID_\'+$(this).val()+\'"]\').click();
- });' .
- wf_tag('script', true) .
- wf_tag('div', true);
- } else {
- $QuickOLTLinkInput = '';
- }
- //interface grid construction
- $ponizerGrid = '';
- $ponizerGrid .= $QuickOLTLinkInput . wf_delimiter(0);
- $ponizerGrid .= wf_TabsCarouselInitLinking();
- $ponizerGrid .= wf_TabsGen('ui-tabs', $tabsList, $tabsData, $tabsDivOpts, $tabsLstOpts, true);
- $ponizerGrid .= $QuickOLTLinkInput;
- //rendering it
- show_window('', $ponizerGrid);
- } else {
- return ($result);
- }
- }
- /**
- * Renders OLT stats
- *
- * @return string
- */
- public function renderOltStats() {
- $oltOnuCounters = $this->getOltOnuCounts();
- $onuMaxCountConf = @$this->altCfg['PON_ONU_PORT_MAX'];
- $herdEnabledFlag = (@$this->altCfg['HERD_OF_PONIES']) ? true : false;
- $oltOnuFilled = array();
- $oltOnuPonPortMax = array();
- $oltInterfacesFilled = array();
- $oltInterfaceDescrs = array();
- $signals = array();
- $badSignals = array();
- $avgSignals = array();
- $oltsTemps = array(); //oltId=>temperature
- $oltData = new OLTAttractor();
- $statsControls = wf_BackLink(self::URL_ONULIST);
- $statsControls .= wf_Link(self::URL_ME . '&oltstats=true', wf_img('skins/icon_stats_16.gif') . ' ' . __('Stats') . ' ' . __('OLT'), false, 'ubButton') . ' ';
- if (!ubRouting::checkGet('temperature')) {
- $statsControls .= wf_Link(self::URL_ME . '&oltstats=true&temperature=true', wf_img('skins/temperature.png') . ' ' . __('Temperature'), false, 'ubButton') . ' ';
- } else {
- $statsControls .= wf_Link(self::URL_ME . '&oltstats=true', wf_img('skins/notemperature.png') . ' ' . __('Temperature'), false, 'ubButton') . ' ';
- }
- $statsControls .= wf_Link(self::URL_ME . '&oltstats=true&pollstats=true', wf_img('skins/icon_time_small.png') . ' ' . __('Devices polling stats'), false, 'ubButton') . ' ';
- $statsControls .= wf_Link(self::URL_ME . '&polllogs=true', wf_img('skins/log_icon_small.png') . ' ' . __('OLT polling log'), false, 'ubButton') . ' ';
- if (cfr('ROOT')) {
- $cleanupUrl = self::URL_ME . '&oltstats=true&pondatacleanup=true';
- $cleanupCancel = self::URL_ME . '&oltstats=true';
- $cleanupLabel = wf_img('skins/icon_cleanup.png') . ' ' . __('Cache cleanup');
- $cleanupAlert = __('Clear all cache') . '?';
- $statsControls .= wf_ConfirmDialog($cleanupUrl, $cleanupLabel, $cleanupAlert, 'ubButton', $cleanupCancel, __('Cleanup') . '?');
- }
- $result = '';
- $result .= $statsControls;
- $result .= wf_tag('br');
- foreach ($this->allOltDevices as $oltId => $eachOltData) {
- if (isset($oltOnuCounters[$oltId])) {
- $onuCount = $oltOnuCounters[$oltId];
- $oltModelId = @$this->allOltSnmp[$oltId]['modelid'];
- $oltPorts = @$this->allOltModels[$oltModelId]['ports'];
- $snmpTemplatesMaxPort = @$this->snmpTemplates[$oltModelId]['define']['PON_ONU_PORT_MAX'];
- $onuMaxCount = (!empty($snmpTemplatesMaxPort)) ? $snmpTemplatesMaxPort : $onuMaxCountConf;
- if ((!empty($oltModelId)) and (!empty($oltPorts)) and (!empty($onuMaxCount))) {
- $oltData->setOltId($oltId); //switching attractor scope
- $maxOnuPerOlt = $oltPorts * $onuMaxCount;
- $oltOnuFilled[$oltId] = zb_PercentValue($maxOnuPerOlt, $onuCount);
- $oltOnuPonPortMax[$oltId] = $onuMaxCount;
- $interfaces = $oltData->readInterfaces();
- //is any ONU interfaces here?
- if (!empty($interfaces)) {
- $signals = $oltData->readSignals();
- $ifaceDescrs = $oltData->readInterfacesDescriptions();
- foreach ($interfaces as $eachMac => $eachInterface) {
- $cleanInterface = strstr($eachInterface, ':', true);
- if (isset($oltInterfacesFilled[$oltId][$cleanInterface])) {
- $oltInterfacesFilled[$oltId][$cleanInterface]++;
- } else {
- $oltInterfacesFilled[$oltId][$cleanInterface] = 1;
- }
- if (isset($signals[$eachMac])) {
- $macSignal = $signals[$eachMac];
- if ((($macSignal > -27) and ($macSignal < -25))) {
- if (isset($avgSignals[$oltId][$cleanInterface])) {
- $avgSignals[$oltId][$cleanInterface]++;
- } else {
- $avgSignals[$oltId][$cleanInterface] = 1;
- }
- }
- if ((($macSignal > 0) or ($macSignal < -27))) {
- if (isset($badSignals[$oltId][$cleanInterface])) {
- $badSignals[$oltId][$cleanInterface]++;
- } else {
- $badSignals[$oltId][$cleanInterface] = 1;
- }
- }
- }
- //storing PON ifaces descriptions, if not stored yet
- if (
- !isset($oltInterfaceDescrs[$oltId][$cleanInterface])
- and !empty($ifaceDescrs) and !empty($ifaceDescrs[$cleanInterface])
- ) {
- $oltInterfaceDescrs[$oltId][$cleanInterface] = ' | ' . $ifaceDescrs[$cleanInterface];
- }
- }
- }
- }
- }
- }
- if ((!empty($oltInterfacesFilled)) and (!empty($oltOnuFilled))) {
- foreach ($oltOnuFilled as $oltId => $oltFilledPercent) {
- $oltData->setOltId($oltId);
- $oltControls = '';
- $result .= wf_tag('h3');
- $result .= $this->allOltDevices[$oltId] . ' ' . __('filled on') . ' ' . $oltFilledPercent . '%';
- $result .= ' (' . $oltOnuCounters[$oltId] . ' ' . __('ONU') . ' ' . __('Registered') . ')';
- if (@$this->altCfg['PONMAP_ENABLED']) {
- $oltControls .= ' ' . wf_Link(PONONUMap::URL_ME . '&' . PONONUMap::ROUTE_FILTER_OLT . '=' . $oltId, wf_img('skins/ponmap_icon.png', __('ONU Map')), false);
- }
- $result .= $oltControls;
- $result .= wf_tag('h3', true);
- if (isset($oltInterfacesFilled[$oltId])) {
- $cells = wf_TableCell(__('Interface'));
- $cells .= wf_TableCell(__('Count'));
- $cells .= wf_TableCell(__('Mediocre signal'));
- $cells .= wf_TableCell(__('Mediocre signal') . ' %');
- $cells .= wf_TableCell(__('Bad signal'));
- $cells .= wf_TableCell(__('Bad signal') . ' %');
- $cells .= wf_TableCell(__('Visual'));
- $rows = wf_TableRow($cells, 'row1');
- foreach ($oltInterfacesFilled[$oltId] as $eachInterface => $eachInterfaceCount) {
- $eachInterfacePercent = zb_PercentValue($oltOnuPonPortMax[$oltId], $eachInterfaceCount);
- $oltIfaceDescr = ($this->showPONIfaceDescrStatsTab and !empty($oltInterfaceDescrs[$oltId][$eachInterface])) ? $oltInterfaceDescrs[$oltId][$eachInterface] : '';
- $avgSignalCount = @$avgSignals[$oltId][$eachInterface];
- $badSignalCount = @$badSignals[$oltId][$eachInterface];
- $avgSignalColor = '';
- $avgSignalColorEnd = '';
- $avgSignalPercent = '';
- $badSignalColor = '';
- $badSignalColorEnd = '';
- $badSignalPercent = '';
- $interfaceFillColor = '';
- $interfaceFillColorEnd = '';
- if ($eachInterfacePercent > 80) {
- $interfaceFillColor = wf_tag('font', false, '', 'color="' . self::COLOR_AVG . '"') . wf_tag('b', false);
- $interfaceFillColorEnd = wf_tag('b', true) . wf_tag('font', true);
- }
- if ($eachInterfacePercent > 90) {
- $interfaceFillColor = wf_tag('font', false, '', 'color="' . self::COLOR_BAD . '"') . wf_tag('b', false);
- $interfaceFillColorEnd = wf_tag('b', true) . wf_tag('font', true);
- }
- $interfaceFillLabel = $interfaceFillColor . $eachInterfaceCount . ' (' . $eachInterfacePercent . '%)' . $interfaceFillColorEnd;
- if (!empty($avgSignalCount)) {
- if ($avgSignalCount >= 3) {
- $avgSignalColor = wf_tag('font', false, '', 'color="' . self::COLOR_AVG . '"') . wf_tag('b', false);
- $avgSignalColorEnd = wf_tag('b', true) . wf_tag('font', true);
- } else {
- $avgSignalColor = '';
- $avgSignalColorEnd = '';
- }
- $avgSignalPercent = zb_PercentValue($eachInterfaceCount, $avgSignalCount) . '%';
- } else {
- $avgSignalCount = '';
- }
- if (!empty($badSignalCount)) {
- if ($badSignalCount >= 3) {
- $badSignalColor = wf_tag('font', false, '', 'color="' . self::COLOR_BAD . '"') . wf_tag('b', false);
- $badSignalColorEnd = wf_tag('b', true) . wf_tag('font', true);
- } else {
- $badSignalColor = '';
- $badSignalColorEnd = '';
- }
- $badSignalPercent = zb_PercentValue($eachInterfaceCount, $badSignalCount) . '%';
- } else {
- $badSignalCount = '';
- }
- $eachInterfaceLabel = $eachInterface;
- if ($this->ponIfDescribe) {
- $controllerUrl = self::URL_ME . '&oltid=' . $oltId . '&if=' . $eachInterface;
- $ponIfDescr = $this->ponInterfaces->getDescription($oltId, $eachInterface);
- if (!empty($ponIfDescr)) {
- $ponIfDescr = ' ' . $ponIfDescr;
- }
- if (cfr('PONEDIT')) {
- $eachInterfaceLabel = wf_Link($controllerUrl, $eachInterface) . $ponIfDescr;
- } else {
- $eachInterfaceLabel = $eachInterface . ' ' . $ponIfDescr;
- }
- }
- $cells = wf_TableCell($eachInterfaceLabel . $oltIfaceDescr);
- $cells .= wf_TableCell($interfaceFillLabel, '', '', 'sorttable_customkey="' . $eachInterfaceCount . '"');
- $cells .= wf_TableCell($avgSignalColor . $avgSignalCount . $avgSignalColorEnd);
- $cells .= wf_TableCell($avgSignalPercent);
- $cells .= wf_TableCell($badSignalColor . $badSignalCount . $badSignalColorEnd);
- $cells .= wf_TableCell($badSignalPercent);
- $cells .= wf_TableCell(web_bar($eachInterfaceCount, $oltOnuPonPortMax[$oltId]), '', '', 'sorttable_customkey="' . $eachInterfaceCount . '"');
- $rows .= wf_TableRow($cells, 'row5');
- }
- $result .= wf_TableBody($rows, '100%', 0, 'sortable');
- //gettin uptime
- $oltUptime = $oltData->readUptime();
- if (!empty($oltUptime)) {
- $result .= __('Uptime') . ': ' . $oltUptime;
- }
- //getting temperature
- $oltTemperature = $oltData->readTemperature();
- if (!empty($oltTemperature)) {
- $oltsTemps[$oltId] = $oltTemperature; //filling temp array
- $result .= ' / ' . __('Temperature') . ': ' . $oltTemperature . ' °C';
- }
- $result .= wf_delimiter(0);
- }
- }
- //temperature gauges here
- if (ubRouting::checkGet('temperature')) {
- $result = $statsControls . wf_tag('br');
- if (!empty($oltsTemps)) {
- foreach ($oltsTemps as $oltTempId => $oltTempValue) {
- $result .= wf_renderTemperature($oltTempValue, $this->allOltDevices[$oltTempId]);
- }
- $result .= wf_CleanDiv();
- } else {
- $messages = new UbillingMessageHelper();
- $result .= $messages->getStyledMessage(__('Nothing to show'), 'warning');
- }
- }
- //or OLT polling timing stats
- if (ubRouting::checkGet('pollstats')) {
- if (!empty($this->allOltDevices)) {
- $totalTime = 0;
- $devicesPolled = 0;
- $pollTimings = array();
- $cells = wf_TableCell(__('ID'));
- $cells .= wf_TableCell(__('OLT'));
- $cells .= wf_TableCell(__('Model'));
- $cells .= wf_TableCell('⏳ ' . __('from'));
- $cells .= wf_TableCell('⌛ ' . __('to'));
- $cells .= wf_TableCell('⏱️ ' . __('time'));
- $cells .= wf_TableCell('📊 ' . __('Visual'));
- $rows = wf_TableRow($cells, 'row1');
- //poll timing preprocessing
- foreach ($this->allOltDevices as $oltId => $eachDevice) {
- $pollStats = $this->pollingStatsRead($oltId);
- if (!empty($pollStats)) {
- $devPollTime = 0;
- if (!empty($pollStats['start']) and !empty($pollStats['end'])) {
- $devPollTime = $pollStats['end'] - $pollStats['start'];
- if ($herdEnabledFlag) {
- if ($devPollTime > $totalTime) {
- $totalTime = $devPollTime;
- }
- } else {
- $totalTime += $devPollTime;
- }
- }
- $pollTimings[$oltId]['start'] = $pollStats['start'];
- $pollTimings[$oltId]['end'] = $pollStats['end'];
- $pollTimings[$oltId]['finished'] = $pollStats['finished'];
- $pollTimings[$oltId]['time'] = $devPollTime;
- }
- }
- //rendering stats
- if (!empty($pollTimings)) {
- foreach ($pollTimings as $oltId => $pollStats) {
- $pollingFinished = $pollStats['finished'];
- if (!empty($pollStats['start'])) {
- $pollingStartLabel = date("Y-m-d H:i:s", $pollStats['start']);
- } else {
- $pollingStartLabel = '-';
- }
- if (($pollingFinished) and (!empty($pollStats['start'])) and (!empty($pollStats['end']))) {
- $pollingTimeLabel = zb_formatTime($pollStats['time']);
- $pollingEndLabel = date("Y-m-d H:i:s", $pollStats['end']);
- $visualLabel = web_bar($pollStats['time'], $totalTime);
- } else {
- $pollingTimeLabel = wf_tag('span', false, '', 'title="' . __('In progress now') . '"') . self::POLL_RUNNING . wf_tag('span', true);
- $pollingTimeLabel .= ' ' . __('In progress now');
- $pollingEndLabel = '-';
- $visualLabel = '∞';
- }
- $oltModelLabel = '';
- $oltModelId = (isset($this->allOltModelIds[$oltId])) ? $this->allOltModelIds[$oltId] : 0;
- if ($oltModelId) {
- if (isset($this->allOltModels[$oltModelId])) {
- $oltModelLabel = $this->allOltModels[$oltModelId]['modelname'];
- }
- }
- $cells = wf_TableCell($oltId);
- $cells .= wf_TableCell($this->allOltDevices[$oltId]);
- $cells .= wf_TableCell($oltModelLabel);
- $cells .= wf_TableCell($pollingStartLabel);
- $cells .= wf_TableCell($pollingEndLabel);
- $cells .= wf_TableCell($pollingTimeLabel, '', '', 'sorttable_customkey="' . $pollStats['time'] . '"');
- $cells .= wf_TableCell($visualLabel, '20%', '', 'sorttable_customkey="' . $pollStats['time'] . '"');
- $rows .= wf_TableRow($cells, 'row5');
- $devicesPolled++;
- }
- }
- $result = $statsControls;
- $result .= wf_tag('h3') . __('SNMP query') . wf_tag('h3', true);
- $result .= wf_TableBody($rows, '100%', 0, 'sortable');
- $result .= wf_delimiter(0);
- $result .= wf_tag('b') . __('Total') . ' ' . __('time') . ': ' . wf_tag('b', true) . zb_formatTime($totalTime) . wf_tag('br');
- $result .= wf_tag('b') . __('Total') . ' ' . __('OLT') . ': ' . wf_tag('b', true) . $devicesPolled . wf_tag('br');
- } else {
- $messages = new UbillingMessageHelper();
- $result .= $messages->getStyledMessage(__('Nothing to show'), 'warning');
- }
- }
- } else {
- $messages = new UbillingMessageHelper();
- $result .= $messages->getStyledMessage(__('Nothing to show'), 'warning');
- }
- return ($result);
- }
- /**
- * Renders unknown ONU list container
- *
- * @return string
- */
- public function renderUnknownOnuList() {
- $result = '';
- if ($this->llidColVisibleUnknownONU) {
- $columns = array('OLT', 'Login', 'Address', 'Real Name', 'Tariff', 'IP', 'Interface', __('MAC') . ' ' . __('or') . ' ' . __('Serial'), 'Actions');
- } else {
- $columns = array('OLT', 'Login', 'Address', 'Real Name', 'Tariff', 'IP', __('MAC') . ' ' . __('or') . ' ' . __('Serial'), 'Actions');
- }
- $opts = '"order": [[ 0, "desc" ]]';
- $result = wf_JqDtLoader($columns, self::URL_ME . '&ajaxunknownonu=true', false, 'ONU', 100, $opts);
- $result .= wf_delimiter(0);
- return ($result);
- }
- /**
- * Returns current FDB cache list container with controls
- *
- * @return string
- */
- public function renderOnuFdbCache() {
- $result = wf_BackLink(self::URL_ONULIST);
- if (cfr('ROOT')) {
- //auto OLT associtation fixing interface
- $fixCancelUrl = self::URL_ME . '&fdbcachelist=true';
- $fixConfirmUrl = self::URL_ME . '&fdbcachelist=true&fixonuoltassings=true';
- $fixDialogLabel = wf_img('skins/icon_repair.gif') . ' ' . __('Fix OLT inconsistencies');
- $fixDialogNotice = __('This operation automatically remaps ONU assigns whith OLT devices from where last data was received for this ONUs');
- $result .= wf_ConfirmDialog($fixConfirmUrl, $fixDialogLabel, $fixDialogNotice, 'ubButton', $fixCancelUrl);
- }
- $result .= wf_delimiter();
- $columns = array('OLT', 'ONU', 'ID', 'Vlan', 'MAC', 'Address', 'Login', 'Real Name', 'Tariff');
- $opts = '"order": [[ 0, "desc" ]]';
- $result .= wf_JqDtLoader($columns, self::URL_ME . '&fdbcachelist=true&ajaxfdblist=true', false, 'ONU', 100, $opts);
- return ($result);
- }
- /**
- * Renders OLT FDB list container
- *
- * @param int $onuid
- * @param string $customDataSource
- *
- * @return string
- */
- public function renderOltFdbList($onuid = '', $customDataSource = '') {
- $result = '';
- $columns = array('ID', 'Vlan', 'MAC', 'Address', 'Real Name', 'Tariff');
- $opts = '"order": [[ 0, "desc" ]]';
- if ($customDataSource) {
- $dataSource = $customDataSource . $onuid;
- } else {
- $dataSource = self::URL_ME . '&ajaxoltfdb=true&onuid=' . $onuid;
- }
- $result = wf_JqDtLoader($columns, $dataSource, false, 'ONU', 100, $opts);
- return ($result);
- }
- /**
- * Loads existing signal cache from FS
- *
- * @return void
- */
- protected function loadSignalsCache() {
- $this->signalCache = $this->reviewDataSet($this->oltData->getSignalsAll());
- }
- /**
- * Loads ONU distance cache
- *
- * @return void
- */
- protected function loadDistanceCache() {
- $this->distanceCache = $this->reviewDataSet($this->oltData->getDistancesAll());
- }
- /**
- * Loads ONU last dereg reasons cache
- *
- * @return void
- */
- protected function loadLastDeregCache() {
- $this->lastDeregCache = $this->reviewDataSet($this->oltData->getDeregsAll());
- }
- /**
- * Loads ONU interface cache
- *
- * @return void
- */
- protected function loadInterfaceCache() {
- $this->interfaceCache = $this->reviewDataSet($this->oltData->getInterfacesAll());
- }
- /**
- * Loads available OLTs PON interfaces descriptions
- *
- * @return void
- */
- protected function loadPONIfaceDescrCache() {
- $this->ponIfaceDescrCache = $this->oltData->getInterfacesDescriptions();
- }
- /**
- * Loads OLT FDB cache
- *
- * @return void
- */
- protected function loadFDBCache() {
- $this->FDBCache = $this->reviewDataSet($this->oltData->getFdbAll());
- }
- protected function loadUniOperStatsCache() {
- $this->uniOperStatsCache = $this->reviewDataSet($this->oltData->getUniOperStatsAll());
- }
- /**
- * Fills onuIndexCache array
- *
- * NOTICE: not similar with previous all - in readOnuCache() is [onuIdx]=>onuMac
- * REQUIRED: onuMac=>oltId
- *
- * @return void
- */
- protected function fillONUIndexCache() {
- $this->onuIndexCache = $this->reviewDataSet($this->oltData->getONUonOLTAll());
- }
- /**
- * Returns array of unknown ONUs MACs which can be filtered by OLT ID and returned just like simple array
- * or formed HTML selector ready to use on web page
- *
- * @param int $FilterByOLTID
- * @param bool $ReturnAsHTMLSelector
- * @param bool $AddEmptyFirsSelectorItem
- * @param string $HTMLSelectorID
- * @param string $HTMLSelectorName
- * @param string $HTMLSelectorLabel
- * @param string $HTMLSelectorSelectedItem
- * @param bool $HTMLSelectorBR
- * @param bool $HTMLSelectorSort
- *
- * @return array|string
- */
- public function getUnknownONUMACList($FilterByOLTID = 0, $ReturnAsHTMLSelector = false, $AddEmptyFirsSelectorItem = false, $HTMLSelectorID = 'nonameselectorid', $HTMLSelectorName = 'nonameselector', $HTMLSelectorLabel = '', $HTMLSelectorSelectedItem = '', $HTMLSelectorBR = false, $HTMLSelectorSort = false) {
- $UnknownONUList = ($ReturnAsHTMLSelector and $AddEmptyFirsSelectorItem) ? array('' => '-') : array();
- $this->fillONUIndexCache();
- if (!empty($this->onuIndexCache)) {
- foreach ($this->onuIndexCache as $onuMac => $oltId) {
- if (!empty($FilterByOLTID) and $oltId != $FilterByOLTID) {
- continue;
- }
- //not registered?
- if ($this->checkOnuUnique($onuMac)) {
- $UnknownONUList[$onuMac] = $onuMac;
- }
- }
- }
- return (($ReturnAsHTMLSelector) ? wf_Selector($HTMLSelectorName, $UnknownONUList, $HTMLSelectorLabel, $HTMLSelectorSelectedItem, $HTMLSelectorBR, $HTMLSelectorSort, $HTMLSelectorID) : $UnknownONUList);
- }
- /**
- * Renders json formatted data about unregistered ONU
- *
- * @return void
- */
- public function ajaxOnuUnknownData() {
- $json = new wf_JqDtHelper();
- $this->fillONUIndexCache();
- if (!empty($this->onuIndexCache)) {
- $allUsermacs = zb_UserGetAllMACs();
- $allUserData = zb_UserGetAllDataCache();
- if ($this->llidColVisibleUnknownONU) {
- $this->loadInterfaceCache();
- }
- foreach ($this->onuIndexCache as $onuMac => $oltId) {
- //not registered?
- if ($this->checkOnuUnique($onuMac)) {
- $login = in_array($onuMac, array_map('strtolower', $allUsermacs)) ? array_search($onuMac, array_map('strtolower', $allUsermacs)) : '';
- $userLink = $login ? wf_Link('?module=userprofile&username=' . $login, web_profile_icon() . ' ' . @$allUserData[$login]['login'] . '', false) : '';
- $userLogin = $login ? @$allUserData[$login]['login'] : '';
- $userRealnames = $login ? @$allUserData[$login]['realname'] : '';
- $userTariff = $login ? @$allUserData[$login]['Tariff'] : '';
- $userIP = $login ? @$allUserData[$login]['ip'] : '';
- $LnkID = wf_InputId();
- if ($this->llidColVisibleUnknownONU) {
- $onuLLID = (empty($this->interfaceCache[$onuMac]) ? '' : $this->interfaceCache[$onuMac]);
- }
- $actControls = wf_tag('a', false, '', 'id="' . $LnkID . '" href="#" title="' . __('Register new ONU') . '"');
- $actControls .= web_icon_create();
- $actControls .= wf_tag('a', true);
- $actControls .= wf_tag('script', false, '', 'type="text/javascript"');
- $actControls .= '
- $(\'#' . $LnkID . '\').click(function(evt) {
- $.ajax({
- type: "GET",
- url: "' . self::URL_ME . '",
- data: {
- renderCreateForm:true,
- renderDynamically:true,
- renderedOutside:true,
- reloadPageAfterDone:false,
- userLogin:"' . $userLogin . '",
- userIP:"' . $userIP . '",
- onumac:"' . $onuMac . '",
- oltid:"' . $oltId . '",
- ModalWID:"pon_dialog-modal_' . $LnkID . '",
- ModalWBID:"body_pon_dialog-modal_' . $LnkID . '",
- ActionCtrlID:"' . $LnkID . '"
- },
- success: function(result) {
- $(document.body).append(result);
- $(\'#pon_dialog-modal_' . $LnkID . '\').dialog("open");
- }
- });
-
- evt.preventDefault();
- return false;
- });
- ';
- $actControls .= wf_tag('script', true);
- $oltData = @$this->allOltDevices[$oltId];
- if (!isset($this->hideOnuMac[$onuMac])) {
- //brand new BDCOM issue temorary workaround. Broken serials too.
- if (!ispos($onuMac, 'no:such') and !ispos($onuMac, PHP_EOL)) {
- $data[] = $oltData;
- $data[] = $userLink;
- $data[] = @$allUserData[$login]['fulladress'];
- $data[] = $userRealnames;
- $data[] = $userTariff;
- $data[] = $userIP;
- if ($this->llidColVisibleUnknownONU) {
- $data[] = $onuLLID;
- }
- $data[] = $onuMac;
- $data[] = $actControls;
- $json->addRow($data);
- unset($data);
- }
- }
- }
- }
- }
- $json->getJson();
- }
- /**
- * Returns state of ONU_RENDER_MODE misc section option for some olt, if it exists.
- *
- * @param int $oltId
- *
- * @return string mac/serial
- */
- protected function getOltOnuRenderMode($oltId) {
- $result = 'mac';
- if (isset($this->allOltSnmp[$oltId])) {
- $oltModelId = $this->allOltSnmp[$oltId]['modelid'];
- if (isset($this->snmpTemplates[$oltModelId])) {
- $oltTemplate = $this->snmpTemplates[$oltModelId];
- if (isset($oltTemplate['misc'])) {
- if (isset($oltTemplate['misc']['ONU_RENDER_MODE'])) {
- $result = $oltTemplate['misc']['ONU_RENDER_MODE'];
- }
- }
- }
- }
- return ($result);
- }
- /**
- * Renders json formatted data for jquery data tables list with ONU signals list
- *
- * @param string $OltId
- * @return void
- */
- public function ajaxOnuData($OltId) {
- $OnuByOLT = $this->getOnuArrayByOltID($OltId);
- $json = new wf_JqDtHelper();
- $allRealnames = zb_UserGetAllRealnames();
- $allAddress = zb_AddressGetFulladdresslistCached();
- $allTariffs = zb_TariffsGetAllUsers();
- $burialEnabled = @$this->altCfg['ONU_BURIAL_ENABLED'];
- $noSignalLabel = __('No');
- $fromCache = false;
- $oltOnuRenderMode = $this->getOltOnuRenderMode($OltId);
- //try to get all data from cache
- if ($this->onuCacheTimeout) {
- $ajData = $this->cache->get(self::KEY_ONULISTAJ . $OltId, $this->onuCacheTimeout);
- if (!empty($ajData)) {
- $fromCache = true;
- }
- }
- if (!$fromCache) {
- if ($this->altCfg['ADCOMMENTS_ENABLED']) {
- $adcomments = new ADcomments('PONONU');
- $adc = true;
- } else {
- $adc = false;
- }
- $this->loadSignalsCache();
- $distCacheAvail = $this->oltData->isDistancesAvailable();
- if ($distCacheAvail) {
- $this->loadDistanceCache();
- }
- $intCacheAvail = $this->oltData->isInterfacesAvailable();
- if ($intCacheAvail) {
- $this->loadInterfaceCache();
- }
- $intDescrCacheAvail = $this->oltData->isInterfacesDescriptionsAvailable();
- $curOLTIfaceDescrs = array();
- if ($intDescrCacheAvail) {
- $this->loadPONIfaceDescrCache();
- if (!empty($this->ponIfaceDescrCache[$OltId])) {
- $intDescrCacheAvail = true;
- $curOLTIfaceDescrs = $this->ponIfaceDescrCache[$OltId];
- } else {
- $intDescrCacheAvail = false;
- }
- }
- $lastDeregCacheAvail = $this->oltData->isDeregsAvailable();
- if ($lastDeregCacheAvail) {
- $this->loadLastDeregCache();
- }
- if (!empty($OnuByOLT)) {
- foreach ($OnuByOLT as $io => $each) {
- $renderThisOnu = true;
- //not show buried ONUs
- if ($burialEnabled) {
- if ($each['login'] == 'dead') {
- $renderThisOnu = false;
- }
- }
- if ($renderThisOnu) {
- $userTariff = '';
- $ONUIsOffline = false;
- if (!empty($each['login'])) {
- $userLogin = trim($each['login']);
- if (isset($allAddress[$userLogin])) {
- $userLink = wf_Link('?module=userprofile&username=' . $userLogin, web_profile_icon() . ' ' . $allAddress[$userLogin], false);
- } else {
- $userLink = wf_Link('?module=userprofile&username=' . $userLogin, web_profile_icon(), false) . ' ' . $userLogin;
- }
- @$userRealName = $allRealnames[$userLogin];
- //tariff data
- if (isset($allTariffs[$userLogin])) {
- $userTariff = $allTariffs[$userLogin];
- }
- } else {
- $userLink = '';
- $userRealName = '';
- }
- //checking adcomments availability
- if ($adc) {
- $indicatorIcon = $adcomments->getCommentsIndicator($each['id']);
- } else {
- $indicatorIcon = '';
- }
- $actLinks = wf_Link('?module=ponizer&editonu=' . $each['id'], web_edit_icon(), false);
- $actLinks .= ' ' . $indicatorIcon;
- //coloring signal
- if (isset($this->signalCache[$each['mac']])) {
- $signal = $this->signalCache[$each['mac']];
- if (($signal > 0) or ($signal < -27)) {
- $sigColor = self::COLOR_BAD;
- } elseif ($signal > -27 and $signal < -25) {
- $sigColor = self::COLOR_AVG;
- } else {
- $sigColor = self::COLOR_OK;
- }
- if ($signal == self::NO_SIGNAL) {
- $ONUIsOffline = true;
- $signal = $noSignalLabel;
- $sigColor = self::COLOR_NOSIG;
- }
- } elseif (isset($this->signalCache[$each['serial']])) {
- $signal = $this->signalCache[$each['serial']];
- if (($signal > 0) or ($signal < -27)) {
- $sigColor = self::COLOR_BAD;
- } elseif ($signal > -27 and $signal < -25) {
- $sigColor = self::COLOR_AVG;
- } else {
- $sigColor = self::COLOR_OK;
- }
- if ($signal == self::NO_SIGNAL) {
- $ONUIsOffline = true;
- $signal = $noSignalLabel;
- $sigColor = self::COLOR_NOSIG;
- }
- } else {
- $ONUIsOffline = true;
- $signal = $noSignalLabel;
- $sigColor = self::COLOR_NOSIG;
- }
- $data[] = $each['id'];
- if ($intCacheAvail) {
- if (isset($this->interfaceCache[$each['mac']])) {
- $ponInterface = $this->interfaceCache[$each['mac']];
- } else {
- if (isset($this->interfaceCache[$each['serial']])) {
- $ponInterface = $this->interfaceCache[$each['serial']];
- } else {
- $ponInterface = '';
- }
- }
- $cleanInterface = strstr($ponInterface, ':', true);
- $oltIfaceDescr = ($this->showPONIfaceDescrMainTab and $intDescrCacheAvail and !empty($curOLTIfaceDescrs[$cleanInterface])) ? $curOLTIfaceDescrs[$cleanInterface] . ' | ' : '';
- $data[] = $oltIfaceDescr . $ponInterface;
- }
- $data[] = $this->getModelName($each['onumodelid']);
- if ($this->ipColumnVisible) {
- $data[] = $each['ip'];
- }
- //MAC/Serial column here
- if ($oltOnuRenderMode == 'mac') {
- $onuIdent = $each['mac'];
- } else {
- $onuIdent = $each['serial'];
- }
- $data[] = $onuIdent;
- $data[] = wf_tag('font', false, '', 'color=' . $sigColor . '') . $signal . wf_tag('font', true);
- if ($distCacheAvail) {
- if (isset($this->distanceCache[$each['mac']])) {
- $data[] = $this->distanceCache[$each['mac']];
- } else {
- if (isset($this->distanceCache[$each['serial']])) {
- $data[] = $this->distanceCache[$each['serial']];
- } else {
- $data[] = '';
- }
- }
- }
- if ($lastDeregCacheAvail) {
- if ($ONUIsOffline) {
- $data[] = @$this->lastDeregCache[$each['mac']];
- } else {
- $data[] = '';
- }
- }
- $data[] = $userLink;
- $data[] = $userRealName;
- $data[] = $userTariff;
- $data[] = $actLinks;
- $json->addRow($data);
- unset($data);
- }
- }
- }
- //extract json data
- $ajData = $json->extractJson();
- //update cache if required
- if ($this->onuCacheTimeout and !$fromCache) {
- $this->cache->set(self::KEY_ONULISTAJ . $OltId, $ajData, $this->onuCacheTimeout);
- }
- }
- die($ajData);
- }
- /**
- * Renders json formatted data for jquery data tables list
- *
- * @param string $OnuId
- * @return void
- */
- public function ajaxOltFdbData($OnuId) {
- $json = new wf_JqDtHelper();
- $fdbPointer = '';
- if (!empty($OnuId)) {
- $allUserTariffs = zb_TariffsGetAllUsers();
- $onuMacId = @$this->allOnu[$OnuId]['mac'];
- $onuSerialId = @$this->allOnu[$OnuId]['serial'];
- $fdbCacheAvail = $this->oltData->isFdbAvailable();
- if ($fdbCacheAvail) {
- $this->loadFDBCache();
- } else {
- $fdbCacheAvail = false;
- }
- if (isset($this->FDBCache[$onuMacId])) {
- $fdbPointer = $this->FDBCache[$onuMacId];
- }
- if (isset($this->FDBCache[$onuSerialId])) {
- $fdbPointer = $this->FDBCache[$onuSerialId];
- }
- if ($fdbCacheAvail and $fdbPointer) {
- $GetLoginMac = zb_UserGetAllMACs();
- $allAddress = zb_AddressGetFulladdresslistCached();
- $allRealnames = zb_UserGetAllRealnames();
- foreach ($fdbPointer as $id => $FDBdata) {
- $login = in_array($FDBdata['mac'], array_map('strtolower', $GetLoginMac)) ? array_search($FDBdata['mac'], array_map('strtolower', $GetLoginMac)) : '';
- $userLink = $login ? wf_Link('?module=userprofile&username=' . $login, web_profile_icon() . ' ' . @$allAddress[$login], false) : '';
- $userRealnames = $login ? @$allRealnames[$login] : '';
- $userTariff = (isset($allUserTariffs[$login])) ? $allUserTariffs[$login] : '';
- $data[] = $id;
- $data[] = $FDBdata['vlan'];
- $data[] = $FDBdata['mac'];
- $data[] = @$userLink;
- $data[] = @$userRealnames;
- $data[] = $userTariff;
- $json->addRow($data);
- unset($data);
- }
- }
- }
- $json->getJson();
- }
- /**
- * Checks is ONU really associated with some OLT
- *
- * @param string $onuMac
- * @param int $oltId
- * @return bool
- */
- protected function checkOnuOLTid($onuMac, $oltId) {
- $result = true;
- $sn = strtoupper($onuMac);
- if (!empty($this->onuMacOltidList)) {
- if (isset($this->onuMacOltidList[$onuMac])) {
- if ($this->onuMacOltidList[$onuMac] != $oltId) {
- $result = false;
- }
- }
- }
- if (!empty($this->onuSerialOltidList)) {
- if (isset($this->onuSerialOltidList[$sn])) {
- if ($this->onuSerialOltidList[$sn] != $oltId) {
- $result = false;
- }
- }
- }
- return ($result);
- }
- /**
- * Checks is ONU associated with some login or not
- *
- * @param int $onuId
- * @param string $userLogin
- *
- * @return bool
- */
- protected function checkOnuUserAssign($onuId, $userLogin) {
- $result = true;
- if (@$this->altCfg['PON_USERLINK_CHECK']) {
- //ONU is registered
- if ($onuId != 0) {
- @$associatedUserLogin = $this->allOnu[$onuId]['login'];
- } else {
- $associatedUserLogin = '';
- }
- if (!empty($associatedUserLogin)) {
- if ($userLogin != $associatedUserLogin) {
- $result = false;
- } else {
- $result = true;
- }
- }
- //something strange
- if ($result == false) {
- $onuExtUsers = $this->getOnuExtUsers($onuId);
- if (!empty($onuExtUsers)) {
- foreach ($onuExtUsers as $io => $each) {
- if ($each['login'] == $userLogin) {
- $result = true;
- }
- }
- }
- }
- }
- return ($result);
- }
- /**
- * Renders json for current all OLT FDB list
- *
- * @return void
- */
- public function ajaxFdbCacheList() {
- $json = new wf_JqDtHelper();
- $availOnuFdbCache = $this->oltData->isFdbAvailable();
- if (!empty($availOnuFdbCache)) {
- $availOnuFdbCache = $this->oltData->getFdbOLTAll();
- $allAddress = zb_AddressGetFulladdresslistCached();
- $allRealnames = zb_UserGetAllRealnames();
- $allUserMac = zb_UserGetAllMACs();
- $allUserMac = array_map('strtolower', $allUserMac);
- $allUserMac = array_flip($allUserMac);
- $allUserTariffs = zb_TariffsGetAllUsers();
- foreach ($availOnuFdbCache as $oltId => $eachOltFdb) {
- $oltDesc = @$this->allOltDevices[$oltId];
- if (!empty($eachOltFdb)) {
- foreach ($eachOltFdb as $onuMac => $onuTmp) {
- if (!empty($onuTmp)) {
- foreach ($onuTmp as $id => $onuData) {
- $onuRealId = $this->getOnuIDbyIdent($onuMac);
- if ($onuRealId) {
- $associatedUserLogin = $this->allOnu[$onuRealId]['login'];
- } else {
- $associatedUserLogin = '';
- }
- $userLogin = (isset($allUserMac[$onuData['mac']])) ? $allUserMac[$onuData['mac']] : '';
- $onuLink = ($onuRealId) ? wf_Link(self::URL_ME . '&editonu=' . $onuRealId, $id) : $id;
- @$userAddress = $allAddress[$userLogin];
- @$userRealName = $allRealnames[$userLogin];
- @$userTariff = $allUserTariffs[$userLogin];
- $userLink = (!empty($userLogin)) ? wf_Link('?module=userprofile&username=' . $userLogin, web_profile_icon() . ' ' . $userAddress) : '';
- $oltCheck = (!$this->checkOnuOLTid($onuMac, $oltId)) ? ' ' . wf_img('skins/createtask.gif', __('Wrong OLT')) . ' ' . __('Oh no') : '';
- $userCheck = (!$this->checkOnuUserAssign($onuRealId, $userLogin)) ? ' ' . wf_img('skins/createtask.gif', __('Wrong associated user')) . ' ' . __('Oh no') : '';
- $data[] = $oltDesc . $oltCheck;
- $data[] = $onuMac;
- $data[] = $onuLink;
- $data[] = $onuData['vlan'];
- $data[] = $onuData['mac'] . $userCheck;
- $data[] = $userLink;
- $data[] = $associatedUserLogin;
- $data[] = $userRealName;
- $data[] = $userTariff;
- $json->addRow($data);
- unset($data);
- }
- }
- }
- }
- }
- }
- $json->getJson();
- }
- /**
- * Automatically fixes ONU to OLT associations due the actual FDB cache data
- *
- * @return void
- */
- public function fixOnuOltAssigns() {
- $result = '';
- $result = wf_BackLink(self::URL_ME . '&fdbcachelist=true');
- $failedOnuFound = false;
- $repairConfirmed = (ubRouting::checkGet('autorepairconfirmed')) ? true : false;
- $totalCount = 0;
- $availOnuSigCache = $this->oltData->getSignalsOLTAll();
- if (!empty($availOnuSigCache)) {
- foreach ($availOnuSigCache as $oltId => $eachOltSignals) {
- $oltDesc = @$this->allOltDevices[$oltId];
- if (!empty($eachOltSignals)) {
- foreach ($eachOltSignals as $onuMac => $onuSignal) {
- $onuRealId = $this->getOnuIDbyIdent($onuMac);
- $onuLink = ($onuRealId) ? wf_Link(self::URL_ME . '&editonu=' . $onuRealId, $onuRealId) : '';
- if ($onuRealId) {
- $wrongOltFlag = (!$this->checkOnuOLTid($onuMac, $oltId)) ? true : false;
- if ($wrongOltFlag) {
- $totalCount++;
- $failedOnuFound = true; //set once
- $onuData = $this->allOnu[$onuRealId];
- $wrongOltId = $onuData['oltid'];
- $wrongOltDesc = @$this->allOltDevices[$wrongOltId];
- if (empty($wrongOltDesc)) {
- $wrongOltDesc = '[' . $wrongOltId . '] ' . __('Unknown');
- }
- $missmatchLabel = __('ONU') . ' [ ' . $onuLink . '] ' . __('wrong') . ' ' . __('OLT') . ' ' . $wrongOltDesc . ', ';
- $missmatchLabel .= __('must be') . ' ' . $oltDesc;
- $result .= $this->messages->getStyledMessage($missmatchLabel, 'warning');
- if ($repairConfirmed) {
- if (isset($this->allOltDevices[$oltId])) {
- if (isset($this->allOnu[$onuRealId])) {
- $this->onuDb->where('id', '=', $onuRealId);
- $this->onuDb->data('oltid', $oltId);
- $this->onuDb->save();
- log_register('PON REMAP ONU [' . $onuRealId . '] MAC `' . $onuData['mac'] . '` OLT [' . $wrongOltId . '] TO [' . $oltId . ']');
- $repairLabel = __('ONU') . ' [ ' . $onuLink . '] ' . __('assigned') . ' ' . __('OLT') . ' ' . $oltDesc . '!';
- $result .= $this->messages->getStyledMessage($repairLabel, 'success');
- } else {
- $result .= $this->messages->getStyledMessage(__('ONU') . ' [' . $onuRealId . '] ' . __('Not exists'), 'error');
- }
- } else {
- $result .= $this->messages->getStyledMessage(__('OLT') . ' [' . $oltId . '] ' . __('Not exists'), 'error');
- }
- }
- }
- }
- }
- }
- }
- } else {
- $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'warning');
- }
- if ($failedOnuFound) {
- //totals rendering
- $result .= $this->messages->getStyledMessage(__('Total') . ' ' . __('ONU') . ' ' . __('wrong') . ': ' . $totalCount, 'info');
- $result .= wf_delimiter();
- $repairConfirmUrl = self::URL_ME . '&fdbcachelist=true&fixonuoltassings=true&autorepairconfirmed=true';
- $result .= wf_JSAlert($repairConfirmUrl, wf_img('skins/icon_repair.gif') . ' ' . __('Fix') . '?', $this->messages->getEditAlert(), '', 'ubButton');
- } else {
- $result .= $this->messages->getStyledMessage(__('Everything is Ok'), 'success');
- }
- return ($result);
- }
- /**
- * Returns ONU create and assign form for user profile module
- *
- * @param $userLogin
- * @param $allUserData
- *
- * @return string
- */
- public function renderCpeUserControls($userLogin, $allUserData) {
- $result = '';
- $userHasCPE = false;
- // if there is no assigned ONU with $userLogin yet
- $userHasCPE = $this->getOnuIdByUser($userLogin);
- if (empty($userHasCPE)) {
- $LnkID = wf_InputId();
- $userIP = $allUserData[$userLogin]['ip'];
- $userMAC = $allUserData[$userLogin]['mac'];
- $result .= wf_tag('br') . wf_tag('b') . __('Users PON equipment') . wf_tag('b', true) . wf_tag('br');
- $result .= wf_Link(self::URL_ME . '&unknownonulist=true', wf_img('skins/icon_link.gif') . ' ' . __('Assign PON equipment to user'), false, 'ubButton') . ' ';
- $result .= wf_modalAutoForm(__('Create new CPE'), '', 'dialog-modal_' . $LnkID, 'body_dialog-modal_' . $LnkID);
- $result .= wf_tag('a', false, 'ubButton', 'id="' . $LnkID . '" href="#"');
- $result .= web_icon_create() . ' ' . __('Create new CPE');
- $result .= wf_tag('a', true);
- $result .= wf_tag('script', false, '', 'type="text/javascript"');
- $result .= wf_JSElemInsertedCatcherFunc();
- $result .= wf_JSEmptyFunc();
- $result .= '
- function checkONUAssignment() {
- if ( typeof( $(\'input[name=newmac]\').val() ) === "string" && $(\'input[name=newmac]\').val().length > 0 ) {
- $.ajax({
- type: "GET",
- url: "?module=ponizer",
- data: {action:\'checkONUAssignment\', onumac:$(\'input[name=newmac]\').val()},
- success: function(result) {
- $(\'#onuassignment2\').text(result);
- }
- });
- } else {$(\'#onuassignment2\').text(\'\');}
- }
-
- function dynamicBindClick(ctrlClassName) {
- $(document).on("click", ctrlClassName, function(evt) {
- evt.preventDefault();
- checkONUAssignment($(ctrlClassName).val());
- return false;
- });
- }
-
- onElementInserted(\'body\', \'.__CheckONUAssignmentBtn\', function(element) {
- dynamicBindClick(\'.__CheckONUAssignmentBtn\');
- });
-
- $(\'#' . $LnkID . '\').click(function(evt) {
- $.ajax({
- type: "GET",
- url: "' . self::URL_ME . '",
- data: {
- renderCreateForm:true,
- renderedOutside:true,
- reloadPageAfterDone:true,
- userLogin:"' . $userLogin . '",
- onumac:"' . $userMAC . '",
- userIP:"' . $userIP . '",
- oltid:"",
- ActionCtrlID:"' . $LnkID . '",
- ModalWID:"dialog-modal_' . $LnkID . '"
- },
- success: function(result) {
- $(\'#body_dialog-modal_' . $LnkID . '\').html(result);
- $(\'#dialog-modal_' . $LnkID . '\').dialog("open");
- }
- });
-
- evt.preventDefault();
- return false;
- });
- ';
- $result .= wf_tag('script', true);
- $result .= wf_delimiter();
- }
- return ($result);
- }
- /**
- * Returns array like: $userLogin => $onuSignal
- *
- * @return array
- */
- public static function getAllONUSignals() {
- global $ubillingConfig;
- $result = array();
- $oltData = new OLTAttractor();
- $signalCache = $oltData->getSignalsAll();
- $onuMACValidateRegex = '/^([[:xdigit:]]{2}[\s:.-]?){5}[[:xdigit:]]{2}$/';
- $validateONUMACEnabled = $ubillingConfig->getAlterParam('PON_ONU_MAC_VALIDATE');
- //not using $this->onuDb here, because static method call possible
- $onuDb = new NyanORM(self::TABLE_ONUS);
- $onuDb->whereRaw("`login` != '' and NOT ISNULL(`login`)");
- $allOnuRecs = $onuDb->getAll();
- if (!empty($allOnuRecs) and !empty($signalCache)) {
- //Preprocess MACs if enabled.
- //Not using reviewDataSet here, because static method call possible
- if ($validateONUMACEnabled) {
- foreach ($signalCache as $mac => $signal) {
- if ($validateONUMACEnabled) {
- $matches = array();
- preg_match($onuMACValidateRegex, $mac, $matches);
- if (empty($matches[0])) {
- unset($signalCache[$mac]);
- }
- }
- }
- }
- foreach ($allOnuRecs as $io => $each) {
- if (isset($signalCache[$each['mac']])) {
- $result[$each['login']] = $signalCache[$each['mac']];
- }
- if (isset($signalCache[$each['serial']])) {
- $result[$each['login']] = $signalCache[$each['serial']];
- }
- }
- }
- return ($result);
- }
- /**
- * Return all of last dereg reasons as userLogin=>deregReason[raw/styled]
- *
- * @return array
- */
- public function getAllONUDeregReasons() {
- global $ubillingConfig;
- $result = array();
- $onuMACValidateRegex = '/^([[:xdigit:]]{2}[\s:.-]?){5}[[:xdigit:]]{2}$/';
- $validateONUMACEnabled = $ubillingConfig->getAlterParam('PON_ONU_MAC_VALIDATE');
- $oltData = new OLTAttractor();
- $deregsCache = $oltData->getDeregsAll();
- $onuDb = new NyanORM(self::TABLE_ONUS);
- $onuDb->whereRaw("`login` != '' and NOT ISNULL(`login`)");
- $allOnuRecs = $onuDb->getAll();
- if (!empty($allOnuRecs) and !empty($deregsCache)) {
- //Preprocess MACs if enabled.
- if ($validateONUMACEnabled) {
- foreach ($deregsCache as $mac => $dereg) {
- if ($validateONUMACEnabled) {
- $matches = array();
- preg_match($onuMACValidateRegex, $mac, $matches);
- if (empty($matches[0])) {
- unset($deregsCache[$mac]);
- }
- }
- }
- }
- foreach ($allOnuRecs as $io => $each) {
- if (isset($deregsCache[$each['mac']])) {
- $result[$each['login']]['raw'] = strip_tags($deregsCache[$each['mac']]);
- $result[$each['login']]['styled'] = $deregsCache[$each['mac']];
- }
- if (isset($deregsCache[$each['serial']])) {
- $result[$each['login']]['raw'] = strip_tags($deregsCache[$each['serial']]);
- $result[$each['login']]['styled'] = $deregsCache[$each['serial']];
- }
- }
- }
- return ($result);
- }
- /**
- * Just generates random MAC address to replace invalid ONU MAC
- *
- * @return string
- */
- protected function getRandomMac() {
- $result = $result = 'ff:' . '00' . ':' . rand(10, 99) . ':' . rand(10, 99) . ':' . rand(10, 99) . ':' . '00';
- return ($result);
- }
- /**
- * Validate ONUs MAC against regex and return bool value
- *
- * @param $onuMAC
- *
- * @return bool
- */
- public function validateONUMAC($onuMAC) {
- $matches = array();
- preg_match($this->onuMACValidateRegex, $onuMAC, $matches);
- return (!empty($matches[0]));
- }
- /**
- * Returns validated MAC or replaces it with random one
- *
- * @param string $mac
- *
- * @return string
- */
- protected function validatedMac($mac) {
- if ($this->validateONUMACEnabled and !$this->validateONUMAC($mac)) {
- if ($this->replaceInvalidONUMACWithRandom) {
- $mac = $this->getRandomMac();
- }
- }
- return ($mac);
- }
- /**
- * Performs validation of some data set if required as onuMac=>someValue
- *
- * @param array $dataSet
- *
- * @return array
- */
- protected function reviewDataSet($dataSet) {
- $result = array();
- if ($this->validateONUMACEnabled) {
- if (!empty($dataSet)) {
- foreach ($dataSet as $onuIdent => $someValue) {
- $result[$this->validatedMac($onuIdent)] = $someValue;
- }
- }
- } else {
- return ($dataSet);
- }
- return ($result);
- }
- /**
- * Renders ONU search form
- *
- * @return string
- */
- public function renderOnuSearchForm() {
- $result = '';
- if (!empty($this->allOnu)) {
- $inputs = '';
- $searchQueryPreset = (ubRouting::checkPost('onusearchquery')) ? ubRouting::post('onusearchquery', 'mres') : '';
- $inputs .= wf_TextInput('onusearchquery', '', $searchQueryPreset, true, 40) . ' ';
- $inputs .= __('Search by') . ':' . wf_delimiter(0);
- if (ubRouting::checkPost('onusearchquery')) {
- //saving checkbox state between queries
- $macChecked = (ubRouting::checkPost('searchmac')) ? true : false;
- $loginChecked = (ubRouting::checkPost('searchlogin')) ? true : false;
- $serialChecked = (ubRouting::checkPost('searchserial')) ? true : false;
- $ipChecked = (ubRouting::checkPost('searchip')) ? true : false;
- $idChecked = (ubRouting::checkPost('searchonuid')) ? true : false;
- } else {
- //default checkbox state
- $macChecked = true;
- $loginChecked = true;
- $serialChecked = true;
- $ipChecked = true;
- $idChecked = true;
- }
- $inputs .= wf_CheckInput('searchmac', __('MAC'), true, $macChecked);
- $inputs .= wf_CheckInput('searchlogin', __('Login'), true, $loginChecked);
- $inputs .= wf_CheckInput('searchserial', __('Serial number'), true, $serialChecked);
- $inputs .= wf_CheckInput('searchip', __('IP'), true, $ipChecked);
- $inputs .= wf_CheckInput('searchonuid', __('ONU') . ' ' . __('ID'), true, $idChecked);
- $inputs .= wf_delimiter(0);
- $inputs .= wf_Submit(__('Search'));
- $result .= wf_Form(self::URL_ME . '&onusearch=true', 'POST', $inputs, 'glamour');
- } else {
- $result .= $this->messages->getStyledMessage(__('Nothing found'), 'warning', 'style="width:300px;"');
- }
- return ($result);
- }
- /**
- * Catches ONU search request and renders some result
- *
- * @return string
- */
- public function renderOnuSearchResult() {
- $result = '';
- $resultTmp = array();
- $messages = new UbillingMessageHelper();
- if (!empty($this->allOnu)) {
- $searchQuery = ubRouting::post('onusearchquery', 'mres');
- if (!empty($searchQuery)) {
- //search fields flags
- $macChecked = (ubRouting::checkPost('searchmac')) ? true : false;
- $loginChecked = (ubRouting::checkPost('searchlogin')) ? true : false;
- $serialChecked = (ubRouting::checkPost('searchserial')) ? true : false;
- $ipChecked = (ubRouting::checkPost('searchip')) ? true : false;
- $idChecked = (ubRouting::checkPost('searchonuid')) ? true : false;
- //processing some search
- foreach ($this->allOnu as $eachOnuId => $eachOnuData) {
- if ($macChecked) {
- $rawMac = str_replace(array(':', '.', '-'), '', $eachOnuData['mac']);
- $macSearchQuery = str_replace(array(':', '.', '-'), '', $searchQuery);
- if (ispos($eachOnuData['mac'], $searchQuery) or ispos($rawMac, $macSearchQuery)) {
- $resultTmp[$eachOnuId] = $eachOnuData;
- }
- }
- if ($loginChecked) {
- if (ispos($eachOnuData['login'], $searchQuery)) {
- $resultTmp[$eachOnuId] = $eachOnuData;
- }
- }
- if ($serialChecked) {
- if (ispos($eachOnuData['serial'], $searchQuery)) {
- $resultTmp[$eachOnuId] = $eachOnuData;
- }
- }
- if ($ipChecked) {
- if (ispos($eachOnuData['ip'], $searchQuery)) {
- $resultTmp[$eachOnuId] = $eachOnuData;
- }
- }
- if ($idChecked) {
- if ($eachOnuData['id'] === $searchQuery) {
- $resultTmp[$eachOnuId] = $eachOnuData;
- }
- }
- }
- //something found
- if (!empty($resultTmp)) {
- $result .= $this->renderOnuArray($resultTmp);
- } else {
- $result .= $messages->getStyledMessage(__('Nothing found'), 'warning');
- }
- }
- } else {
- $result .= $messages->getStyledMessage(__('Nothing to show'), 'error');
- }
- return ($result);
- }
- /**
- * Renders ONU Array just as table list with some controls
- *
- * @param array $onuArray
- *
- * @return string
- */
- protected function renderOnuArray($onuArray) {
- $result = '';
- if (!empty($onuArray)) {
- $count = 0;
- $cells = wf_TableCell(__('ID'));
- $cells .= wf_TableCell(__('OLT'));
- $cells .= wf_TableCell(__('Model'));
- if ($this->ipColumnVisible) {
- $cells .= wf_TableCell(__('IP'));
- }
- $cells .= wf_TableCell(__('Serial number'));
- $cells .= wf_TableCell(__('MAC'));
- $cells .= wf_TableCell(__('User'));
- $cells .= wf_TableCell(__('Actions'));
- $rows = wf_TableRow($cells, 'row1');
- foreach ($onuArray as $eachOnuId => $eachOnuData) {
- $cells = wf_TableCell($eachOnuId);
- $cells .= wf_TableCell(@$this->allOltNames[$eachOnuData['oltid']]);
- $cells .= wf_TableCell(@$this->allModelsData[$eachOnuData['onumodelid']]['modelname']);
- if ($this->ipColumnVisible) {
- $cells .= wf_TableCell($eachOnuData['ip']);
- }
- $cells .= wf_TableCell($eachOnuData['serial']);
- $cells .= wf_TableCell($eachOnuData['mac']);
- if (!empty($eachOnuData['login'])) {
- $userLink = wf_Link(self::URL_USERPROFILE . $eachOnuData['login'], web_profile_icon() . ' ' . $eachOnuData['login']);
- } else {
- $userLink = '';
- }
- $cells .= wf_TableCell($userLink);
- $actControls = wf_Link(self::URL_ME . '&editonu=' . $eachOnuId, web_edit_icon(__('Edit') . ' ' . __('ONU')));
- $cells .= wf_TableCell($actControls);
- $rows .= wf_TableRow($cells, 'row5');
- $count++;
- }
- $result .= wf_TableBody($rows, '100%', 0, 'sortable');
- $result .= wf_tag('b') . __('Total') . ': ' . $count . wf_tag('b', true);
- }
- return ($result);
- }
- /**
- * Tries to return the current "realtime" ONU signal value
- *
- * @param $oltID
- * @param $onumac
- *
- * @return float|int|string
- */
- public function getONURealtimeSignal($oltID, $onumac, $getTxSgnal = false) {
- $signal = '';
- $oltID = vf($oltID, 3);
- if (isset($this->allOltDevices[$oltID]) and isset($this->allOltSnmp[$oltID])) {
- $oltCommunity = $this->allOltSnmp[$oltID]['community'];
- $oltModelId = $this->allOltSnmp[$oltID]['modelid'];
- $oltIp = $this->allOltSnmp[$oltID]['ip'];
- $cacheMACDevID = array();
- if (
- isset($this->snmpTemplates[$oltModelId])
- and isset($this->snmpTemplates[$oltModelId]['signal'])
- and isset($this->snmpTemplates[$oltModelId]['misc'])
- and file_exists(self::MACDEVIDCACHE_PATH . $oltID . '_' . self::MACDEVIDCACHE_EXT)
- ) {
- $cacheMACDevID = file_get_contents(self::MACDEVIDCACHE_PATH . $oltID . '_' . self::MACDEVIDCACHE_EXT);
- $cacheMACDevID = unserialize($cacheMACDevID);
- if (!empty($cacheMACDevID[$onumac])) {
- $snmpSignalOIDs = $this->snmpTemplates[$oltModelId]['signal'];
- $snmpMiscOIDs = $this->snmpTemplates[$oltModelId]['misc'];
- $onuDevID = $cacheMACDevID[$onumac];
- if ($snmpSignalOIDs['SIGNALMODE'] == 'VSOL') {
- $sigOIDPart = ($getTxSgnal) ? '.6.' : '.7.';
- $sigIndexOID = $snmpSignalOIDs['SIGINDEX'] . $sigOIDPart . $onuDevID;
- $sigIndexVal = $snmpSignalOIDs['SIGVALUE'];
- } else {
- if (
- $getTxSgnal
- and isset($snmpMiscOIDs['ONUTXSIGNAL'])
- and isset($snmpMiscOIDs['ONUTXSIGNALVAL'])
- ) {
- $sigIndexOID = $snmpMiscOIDs['ONUTXSIGNAL'] . '.' . $onuDevID;
- $sigIndexVal = $snmpMiscOIDs['ONUTXSIGNALVAL'];
- } else {
- $sigIndexOID = $snmpSignalOIDs['SIGINDEX'] . '.' . $onuDevID;
- $sigIndexVal = $snmpSignalOIDs['SIGVALUE'];
- }
- }
- $sigIndex = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $sigIndexOID, self::SNMPCACHE);
- $sigIndex = str_replace($sigIndexOID . '.', '', $sigIndex);
- $sigIndex = str_replace($sigIndexVal, '', $sigIndex);
- if (!empty($sigIndex)) {
- if ($snmpSignalOIDs['SIGNALMODE'] == 'BDCOM') {
- $line = explode('=', $sigIndex);
- //signal is present
- if (isset($line[1])) {
- $signal = trim($line[1]); // signal level
- if (empty($signal) or !is_numeric($signal) or $signal == $snmpSignalOIDs['DOWNVALUE']) {
- $signal = 'Offline';
- } else {
- if ($snmpSignalOIDs['OFFSETMODE'] == 'div') {
- if ($snmpSignalOIDs['OFFSET']) {
- $signal = $signal / $snmpSignalOIDs['OFFSET'];
- }
- }
- }
- }
- }
- if ($snmpSignalOIDs['SIGNALMODE'] == 'STELSFD') {
- $line = explode('=', $sigIndex);
- //signal is present
- if (isset($line[1])) {
- $signal = trim($line[1]); // signal level
- if (empty($signal) or !is_numeric($signal) or $signal == $snmpSignalOIDs['DOWNVALUE']) {
- $signal = 'Offline';
- } else {
- if ($snmpSignalOIDs['OFFSETMODE'] == 'logm') {
- if ($snmpSignalOIDs['OFFSET']) {
- $signal = round(10 * log10($signal) - $snmpSignalOIDs['OFFSET'], 2);
- }
- }
- }
- }
- }
- if ($snmpSignalOIDs['SIGNALMODE'] == 'VSOL') {
- $signal = trim(substr(stristr(stristr(stristr($sigIndex, '('), ')', true), 'dBm', true), 1));
- }
- }
- }
- }
- }
- return ($signal);
- }
- /**
- * Tries to return some of the extended "realtime" ONU info, like Tx signal, last reg/dereg time, alive time
- *
- * @param $oltID
- * @param $onumac
- *
- * @return array
- */
- public function getONUExtenInfo($oltID, $onumac) {
- $result = array();
- $oltID = vf($oltID, 3);
- if (isset($this->allOltDevices[$oltID]) and isset($this->allOltSnmp[$oltID])) {
- $oltCommunity = $this->allOltSnmp[$oltID]['community'];
- $oltModelId = $this->allOltSnmp[$oltID]['modelid'];
- $oltIp = $this->allOltSnmp[$oltID]['ip'];
- $cacheMACDevID = array();
- if (
- isset($this->snmpTemplates[$oltModelId])
- and isset($this->snmpTemplates[$oltModelId]['signal'])
- and isset($this->snmpTemplates[$oltModelId]['misc'])
- and file_exists(self::MACDEVIDCACHE_PATH . $oltID . '_' . self::MACDEVIDCACHE_EXT)
- ) {
- if ($this->snmpTemplates[$oltModelId]['signal']['SIGNALMODE'] == 'STELSFD') {
- return ($result);
- }
- $cacheMACDevID = file_get_contents(self::MACDEVIDCACHE_PATH . $oltID . '_' . self::MACDEVIDCACHE_EXT);
- $cacheMACDevID = unserialize($cacheMACDevID);
- if (!empty($cacheMACDevID[$onumac])) {
- $snmpDevice = $this->snmpTemplates[$oltModelId]['define']['DEVICE'];
- $snmpSignalOIDs = $this->snmpTemplates[$oltModelId]['signal'];
- $snmpMiscOIDs = $this->snmpTemplates[$oltModelId]['misc'];
- $onuDevID = $cacheMACDevID[$onumac];
- $onuIdxDevID = '';
- $lastRegTime = '';
- $lastDeregTime = '';
- $lastAliveTime = '';
- if (ispos($snmpDevice, 'OLT P36')) {
- $onuIdx = file_get_contents(self::ONUCACHE_PATH . $oltID . '_' . self::ONUCACHE_EXT);
- if (!empty($onuIdx)) {
- $onuIdx = array_flip(unserialize($onuIdx));
- if (!empty($onuIdx[$onumac])) {
- $onuIdxDevID = $onuIdx[$onumac];
- }
- }
- }
- if (!empty($snmpMiscOIDs['LASTREGTIME'])) {
- if (ispos($snmpDevice, 'OLT P36')) {
- $lastRegTimeOID = $snmpMiscOIDs['LASTREGTIME'] . '.' . $onuIdxDevID;
- } else {
- $lastRegTimeOID = $snmpMiscOIDs['LASTREGTIME'] . '.' . $onuDevID;
- }
- $lastRegTimeVal = $snmpMiscOIDs['LASTREGTIMEVAL'];
- $lastRegTime = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $lastRegTimeOID, self::SNMPCACHE);
- $lastRegTime = trimSNMPOutput($lastRegTime, $lastRegTimeOID);
- $lastRegTime = (empty($lastRegTime[1]) ? '' : $lastRegTime[1]);
- }
- if (!empty($snmpMiscOIDs['LASTDEREGTIME'])) {
- if (ispos($snmpDevice, 'OLT P36')) {
- $lastDeregTimeOID = $snmpMiscOIDs['LASTDEREGTIME'] . '.' . $onuIdxDevID;
- } else {
- $lastDeregTimeOID = $snmpMiscOIDs['LASTDEREGTIME'] . '.' . $onuDevID;
- }
- $lastDeregTimeVal = $snmpMiscOIDs['LASTDEREGTIMEVAL'];
- $lastDeregTime = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $lastDeregTimeOID, self::SNMPCACHE);
- $lastDeregTime = trimSNMPOutput($lastDeregTime, $lastDeregTimeOID);
- $lastDeregTime = empty($lastDeregTime[1]) ? '' : $lastDeregTime[1];
- }
- if (!empty($snmpMiscOIDs['LASTALIVETIME'])) {
- $lastAliveTimeOID = $snmpMiscOIDs['LASTALIVETIME'] . '.' . $onuDevID;
- $lastAliveTimeVal = $snmpMiscOIDs['LASTALIVETIMEVAL'];
- $lastAliveTime = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $lastAliveTimeOID, self::SNMPCACHE);
- $lastAliveTime = trimSNMPOutput($lastAliveTime, $lastAliveTimeOID);
- $lastAliveTime = empty($lastAliveTime[1]) ? '' : $lastAliveTime[1];
- }
- if (!empty($lastRegTime) or !empty($lastDeregTime) or !empty($lastAliveTime)) {
- if ($snmpSignalOIDs['SIGNALMODE'] == 'BDCOM' or ispos($snmpDevice, 'FD12XXS') or ispos($snmpDevice, 'FD16XXS')) {
- $lastAliveTime = (empty($lastAliveTime) or !is_numeric($lastAliveTime)) ? 0 : $lastAliveTime;
- $lastAliveTime = zb_formatTime($lastAliveTime);
- $lastRegTime = $this->convertBDCOMTime($lastRegTime);
- $lastDeregTime = $this->convertBDCOMTime($lastDeregTime);
- }
- $result['lastreg'] = trim(trim($lastRegTime), '"');
- $result['lastdereg'] = trim(trim($lastDeregTime), '"');
- $result['lastalive'] = trim(trim($lastAliveTime), '"');
- }
- }
- }
- }
- return ($result);
- }
- /**
- * Tries to return the current "realtime" OLT uptime value
- *
- * @param $oltID
- * @param bool $fromCache
- *
- * @return bool|string
- */
- public function getOLTUptime($oltID, $fromCache = true) {
- $oltUptime = '';
- if ($fromCache and file_exists(self::UPTIME_PATH . $oltID . '_' . self::UPTIME_EXT)) {
- $oltUptime = file_get_contents(self::UPTIME_PATH . $oltID . '_' . self::UPTIME_EXT);
- } else {
- $oltID = vf($oltID, 3);
- if (isset($this->allOltDevices[$oltID]) and isset($this->allOltSnmp[$oltID])) {
- $oltCommunity = $this->allOltSnmp[$oltID]['community'];
- $oltModelId = $this->allOltSnmp[$oltID]['modelid'];
- $oltIp = $this->allOltSnmp[$oltID]['ip'];
- if (isset($this->snmpTemplates[$oltModelId]['system'])) {
- //OLT uptime
- if (isset($this->snmpTemplates[$oltModelId]['system']['UPTIME'])) {
- $uptimeIndexOid = $this->snmpTemplates[$oltModelId]['system']['UPTIME'];
- $oltUptime = $this->snmp->walk($oltIp . ':' . self::SNMPPORT, $oltCommunity, $uptimeIndexOid, self::SNMPCACHE);
- if (!empty($oltUptime)) {
- $oltUptime = explode(')', $oltUptime);
- $oltUptime = $oltUptime[1];
- $oltUptime = trim($oltUptime);
- }
- }
- }
- }
- }
- return ($oltUptime);
- }
- /**
- * Tries to make BDCOM Reg/Dereg dates human readable
- *
- * @param $hexOIDVal
- *
- * @return string
- */
- public function convertBDCOMTime($hexOIDVal) {
- $result = '';
- if (!empty($hexOIDVal)) {
- $hexOIDVal = substr(str_replace(' ', '', $hexOIDVal), 0, 14);
- $bdcomYear = hexdec(substr($hexOIDVal, 0, 4));
- $bdcomMonth = hexdec(substr($hexOIDVal, 4, 2));
- $bdcomMonth = (strlen($bdcomMonth) < 2) ? '0' . $bdcomMonth : $bdcomMonth;
- $bdcomDay = hexdec(substr($hexOIDVal, 6, 2));
- $bdcomDay = (strlen($bdcomDay) < 2) ? '0' . $bdcomDay : $bdcomDay;
- $bdcomHour = hexdec(substr($hexOIDVal, 8, 2));
- $bdcomHour = (strlen($bdcomHour) < 2) ? '0' . $bdcomHour : $bdcomHour;
- $bdcomMin = hexdec(substr($hexOIDVal, 10, 2));
- $bdcomMin = (strlen($bdcomMin) < 2) ? '0' . $bdcomMin : $bdcomMin;
- $bdcomSec = hexdec(substr($hexOIDVal, 12, 2));
- $bdcomSec = (strlen($bdcomSec) < 2) ? '0' . $bdcomSec : $bdcomSec;
- $result = $bdcomYear . '.' . $bdcomMonth . '.' . $bdcomDay . ' ' . $bdcomHour . ':' . $bdcomMin . ':' . $bdcomSec;
- }
- return ($result);
- }
- /**
- * Performs reply on ONU assigment check
- */
- public function checkONUAssignmentReply() {
- $tString = '';
- $tStatus = 0;
- $tLogin = '';
- $oltData = '';
- $onuMAC = ubRouting::get('onumac');
- $ONUAssignment = $this->checkONUAssignment($this->getOnuIDbyIdent($onuMAC), true, true);
- $tStatus = $ONUAssignment['status'];
- $tLogin = $ONUAssignment['login'];
- $oltData = $ONUAssignment['oltdata'];
- switch ($tStatus) {
- case 0:
- $tString = __('ONU is not assigned');
- break;
- case 1:
- $tString = __('ONU is already assigned, but such login is not exists anymore') . '. ' . __('Login') . ': ' . $tLogin . '. OLT: ' . $oltData;
- break;
- case 2:
- $tString = __('ONU is already assigned') . '. ' . __('Login') . ': ' . $tLogin . '. OLT: ' . $oltData;
- break;
- }
- die($tString);
- }
- /**
- * Returns filtered array of unknown ONUs as mac/serial=>oltId
- *
- * @return array
- */
- protected function getOnuUnknownAll() {
- $result = array();
- $this->fillONUIndexCache();
- if (!empty($this->onuIndexCache)) {
- foreach ($this->onuIndexCache as $onuMac => $oltId) {
- //ONU not registered yet?
- if ($this->checkOnuUnique($onuMac)) {
- if (!isset($this->hideOnuMac[$onuMac])) {
- if (!ispos($onuMac, 'no:such')) {
- $result[$onuMac] = $oltId;
- }
- }
- }
- }
- }
- return ($result);
- }
- /**
- * Renders batch unknown ONU registration list
- *
- * @return string
- */
- public function renderBatchOnuRegList() {
- $result = '';
- $allUnknownOnus = $this->getOnuUnknownAll();
- if (!empty($allUnknownOnus)) {
- $onuLabel = __('Oh you are a lazy ass') . '... ' . sizeof($allUnknownOnus) . ' ' . __('Unknown ONU') . '!';
- $result .= $this->messages->getStyledMessage($onuLabel, 'info');
- foreach ($allUnknownOnus as $eachOnuIdent => $eachOnuOltId) {
- if (check_mac_format($eachOnuIdent)) {
- //valid MAC?
- $identLabel = __('ONU') . ' ' . __('MAC');
- } else {
- //looks like serial
- $identLabel = __('ONU') . ' ' . __('Serial');
- }
- $onuLabel = $identLabel . ' ' . $eachOnuIdent . ' ' . __('on') . ' ' . __('OLT') . ' ' . @$this->allOltDevices[$eachOnuOltId];
- $result .= $this->messages->getStyledMessage($onuLabel, 'warning');
- }
- } else {
- $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'success');
- }
- return ($result);
- }
- /**
- * Renders batch unknown ONU registration form
- *
- * @return string
- */
- public function renderBatchOnuRegForm() {
- $result = '';
- $models = array();
- $allUnknownOnus = $this->getOnuUnknownAll();
- if (!empty($allUnknownOnus)) {
- if (!empty($this->allModelsData)) {
- foreach ($this->allModelsData as $io => $each) {
- if (@$this->altCfg['ONUMODELS_FILTER']) {
- if (ispos($each['modelname'], 'ONU')) {
- $models[$each['id']] = $each['modelname'];
- }
- } else {
- $models[$each['id']] = $each['modelname'];
- }
- }
- }
- if (!empty($models)) {
- $inputs = wf_HiddenInput('runmassonureg', 'true');
- $inputs .= wf_Selector('massonuregonumodelid', $models, __('ONU model') . $this->sup, '', true);
- $inputs .= wf_delimiter(0);
- $confirmLabel = __('I also understand well that no one will correct my mistakes for me and only I bear full financial responsibility for my mistakes');
- $inputs .= wf_CheckInput('massonuregconfirmation', $confirmLabel, true, false);
- $inputs .= wf_delimiter(0);
- $inputs .= wf_Submit(__('Register all unknown ONUs'));
- $result .= wf_Form('', 'POST', $inputs, 'glamour');
- } else {
- $result .= $this->messages->getStyledMessage(__('Any available ONU models exist'), 'error');
- }
- } else {
- $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'success');
- }
- return ($result);
- }
- /**
- * Performs batch unknown ONUs registration
- *
- * @param string $customBackLink
- *
- * @return string
- */
- public function runBatchOnuRegister($customBackLink = '') {
- set_time_limit(0);
- $result = '';
- $onuList = '';
- if ($customBackLink) {
- $result .= wf_BackLink($customBackLink);
- } else {
- $result .= wf_BackLink('?module=ponizer&onumassreg=true');
- }
- $result .= wf_delimiter(0);
- $errorCount = 0;
- $succCount = 0;
- if (ubRouting::checkPost('massonuregconfirmation')) {
- if (ubRouting::checkPost('massonuregonumodelid')) {
- $newOnusModelId = ubRouting::post('massonuregonumodelid', 'int');
- if (!empty($newOnusModelId) and isset($this->allModelsData)) {
- $allUnknownOnus = $this->getOnuUnknownAll();
- if (!empty($allUnknownOnus)) {
- $onuLabel = __('Oh you are a lazy ass') . '... ' . sizeof($allUnknownOnus) . ' ' . __('Unknown ONU') . '!';
- $onuList .= $this->messages->getStyledMessage($onuLabel, 'warning');
- foreach ($allUnknownOnus as $eachOnuIdent => $eachOnuOltId) {
- $oltLabel = ' [' . $eachOnuOltId . '] ' . $this->allOltDevices[$eachOnuOltId];
- $onuLabel = __('Registering') . ' ' . __('MAC') . '/' . __('Serial') . ' ' . $eachOnuIdent . ' ' . __('on') . ' ' . __('OLT') . ' ' . $oltLabel;
- $onuList .= $this->messages->getStyledMessage($onuLabel, 'info');
- if (isset($this->allOltDevices[$eachOnuOltId])) {
- if ($this->checkOnuUnique($eachOnuIdent)) {
- if (check_mac_format($eachOnuIdent)) {
- //looks like normal MAC
- $newOnuMac = $eachOnuIdent;
- $newOnuSerial = '';
- } else {
- //seems its GPON device serial
- $newOnuMac = zb_MacGetRandom();
- $newOnuSerial = $eachOnuIdent;
- }
- $newOnuId = $this->onuCreate($newOnusModelId, $eachOnuOltId, '', $newOnuMac, $newOnuSerial, '');
- if ($newOnuId) {
- $oltLabel = ' [' . $eachOnuOltId . '] ' . $this->allOltDevices[$eachOnuOltId] . '. ';
- $onuLabel = __('Registered') . ' ' . __('MAC') . ' ' . __('or') . ' ' . __('Serial') . ' ' . $eachOnuIdent . ' ' . __('ONU') . ' [' . $newOnuId . '] ' . __('on') . ' ' . __('OLT') . ' ' . $oltLabel;
- $onuLabel .= __('Success') . '!';
- $onuList .= $this->messages->getStyledMessage($onuLabel, 'success');
- $succCount++;
- } else {
- $errorCount++;
- $onuList .= $this->messages->getStyledMessage(__('Registering') . ' ' . __('Failed') . ' "' . $eachOnuIdent . '" ', 'error');
- }
- } else {
- $errorCount++;
- $onuList .= $this->messages->getStyledMessage(__('MAC duplicate') . ' ' . $eachOnuIdent . ' ', 'error');
- }
- } else {
- $errorCount++;
- $result .= $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('OLT') . ' [' . $eachOnuOltId . '] ' . __('Not exists'), 'error');
- }
- }
- } else {
- $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'success');
- }
- } else {
- $result .= $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('ONU model') . ' ' . __('Not exists'), 'error');
- }
- } else {
- $result .= $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('No') . ' ' . __('ONU model'), 'error');
- }
- } else {
- $result .= $this->messages->getStyledMessage(__('You are not mentally prepared for this'), 'error');
- }
- //some summary here
- if ($succCount > 0) {
- $result .= $this->messages->getStyledMessage(__('Registered') . ': ' . $succCount, 'success');
- }
- if ($errorCount > 0) {
- $result .= $this->messages->getStyledMessage(__('Error') . ': ' . $errorCount, 'error');
- }
- $result .= $onuList;
- return ($result);
- }
- }
|